mobile-nixos icon indicating copy to clipboard operation
mobile-nixos copied to clipboard

pinephone/pinephone-keyboard: init at 1.2

Open zhaofengli opened this issue 2 years ago • 23 comments

Old description

fetchurl needs to be used since it's a bundle of multiple commits and fetchpatch's normalization will ruin the ordering. For PinePhone Pro, this DT patch is required but it doesn't work well at the moment (keypresses are inconsistent) and more investigation is needed.

zhaofengli avatar Jan 13 '22 21:01 zhaofengli

Great to see this support, I'm eagerly awaiting delivery of the keyboard.

It looks like the original source of these patches is https://github.com/smaeul/linux/commits/wip/pp-keyboard .

Do we know why these aren't included in either upstream, or Megi's kernel? Per https://xnux.eu/log/#044, Megi worked on the keyboard firmware. Is there any driver in his tree?

tomfitzhenry avatar Jan 14 '22 19:01 tomfitzhenry

Megi has a userspace driver that can be used with uinput. Even if you don't want to use the userspace driver, it's still valuable to build the tools because of the firmware flasher and debugger. I should add a package for that, and in the meantime you can build them manually in nix-shell -p php -p sdcc -p python3.

zhaofengli avatar Jan 14 '22 20:01 zhaofengli

I have tested @zhaofengli's branch on my pinephone+keyboard and it does indeed work. Would love to see this merged since compiling the kernel took like 3-5 hours on my x86 machine.

tgharib avatar Jan 16 '22 17:01 tgharib

https://megous.com/git/linux/log/?h=orange-pi-5.16 now contains the kb151 driver.

https://xnux.eu/log/#058

I will bump https://github.com/NixOS/mobile-nixos/pull/449 to 5.16

tomfitzhenry avatar Jan 29 '22 21:01 tomfitzhenry

Great, I'll draft this and rebase with only the userspace utilities once it's merged.

zhaofengli avatar Jan 29 '22 21:01 zhaofengli

I will bump #449 to 5.16

Done. https://github.com/NixOS/mobile-nixos/pull/449#issuecomment-1026808220

tomfitzhenry avatar Feb 01 '22 12:02 tomfitzhenry

Why are we integrating the kernel driver over the more capable userspace driver?

NoahAndrews avatar Feb 01 '22 17:02 NoahAndrews

Why are we integrating the kernel driver over the more capable userspace driver?

The kb151 keyboard driver is part of our upstream (Megi's kernel). Having to patch that to remove the kernel's driver is a maintenance burden. Users who want to use the userspace driver could blacklist the kb151 driver.

What capabilities does the userspace driver have the kernel driver does not?

tomfitzhenry avatar Feb 02 '22 07:02 tomfitzhenry

@tomfitzhenry the kerneland driver is still a bit buggy, namely some of the keys are mapped wrong for some reason, and I am still getting issues with charging from the keyboard. I have heard the userland driver fixes this issue, and there is the bonus that one can still use something like say the Zen kernel.

I don't particularly care about which driver, but I would like to know if this PR is ready enough for me to test?

FedX-sudo avatar Mar 03 '22 20:03 FedX-sudo

@zhaofengli What is the current status of this PR?

collinarnett avatar Nov 14 '22 20:11 collinarnett

Rebased and removed everything besides the userspace bits. The userspace keyboard driver can be started via ppkb-i2c-inputd. Should I add a systemd service gated by an option? If the keyboard is not present, ppkb-i2c-inputd will crash in a loop which isn't ideal.

zhaofengli avatar Dec 01 '22 08:12 zhaofengli

Rebased and removed everything besides the userspace bits. The userspace keyboard driver can be started via ppkb-i2c-inputd. Should I add a systemd service gated by an option? If the keyboard is not present, ppkb-i2c-inputd will crash in a loop which isn't ideal.

A service, disabled by default, would be helpful. A PinePhone with the keyboard may not have a virtual keyboard configured.

The service crashing without the keyboard should not be an issue. If a user does not have the keyboard, they should not enable the service.

justinlovinger avatar Jan 30 '23 18:01 justinlovinger

Is this ready for review?

Anyone with the hardware (I don't have it), it would help if this is tested, especially on both Pinephones (A64, Pro) if applicable.

samueldr avatar Jan 30 '23 19:01 samueldr

With

{
  environment.systemPackages = with pkgs; [
    pine64-pinephone.pinephone-keyboard
  ];
}

and cherry-picking d6cac047802ec97590901fe399436e4cc6933384 on top of NixOS/mobile-nixos?rev=7478a9ffad737486951186b66f6c5535dc5802e2 I can start ppkb-i2c-inputd. Then the keyboard is working with a PinePhone Braveheart.

0x4A6F avatar Jan 31 '23 19:01 0x4A6F

With ppkb-i2c-inputd, the keyboard worked in a TTY but not in Sway. As far as I can tell, the issue is not NixOS-specific, and the userspace driver may need additional configuration for some environments. I am still investigating.

A user on the PinePhone Discord indicated most distros use the kernel driver, not the userspace driver. Issues like this may be why.

justinlovinger avatar Jan 31 '23 20:01 justinlovinger

With ppkb-i2c-inputd, the keyboard worked in a TTY but not in Sway. As far as I can tell, the issue is not NixOS-specific, and the userspace driver may need additional configuration for some environments. I am still investigating.

Hmm, I'm using Sway as well and the keyboard works fine. What does swaymsg -t get_inputs say?

zhaofengli avatar Jan 31 '23 20:01 zhaofengli

With ppkb-i2c-inputd, the keyboard worked in a TTY but not in Sway. As far as I can tell, the issue is not NixOS-specific, and the userspace driver may need additional configuration for some environments. I am still investigating.

Hmm, I'm using Sway as well and the keyboard works fine. What does swaymsg -t get_inputs say?

swaymsg -t get_inputs shows what appears to be the PinePhone keyboard:

{
  "identifier": "4660:22136:ppkbd",
  "name": "ppkbd",
  "vendor": 4660,
  "product": 22136,
  "type": "keyboard",
  "xkb_layout_names": [
    "English (US)"
  ],
  "xkb_active_layout_index": 0,
  "xkb_active_layout_name": "English (US)",
  "libinput": {
    "send_events": "enabled"
  }
}

Edit: I figured it out, the driver works. The issue for me was the userspace driver changed the pine cone key, which my Sway configuration used as the modifier key for opening applications and the like. Without being able to open anything, I was unable to test the keyboard further.

justinlovinger avatar Jan 31 '23 20:01 justinlovinger

Also, I just heard mainline kernel 6.1 added a PinePhone keyboard driver, https://github.com/torvalds/linux/commit/17406967ec0ff8e14737ee7a073c7a45fc8210f1.

justinlovinger avatar Jan 31 '23 21:01 justinlovinger

Also, I just heard mainline kernel 6.1 added a PinePhone keyboard driver, torvalds/linux@1740696.

The kernel space driver is also in recent megous kernels. Setting KEYBOARD_PINEPHONE = yes; in mobile.kernel.structuredConfig, normalizing the kernel config, rebuilding and reflashing config.mobile.outputs.u-boot.boot-partition works for me.

chuangzhu avatar May 06 '23 07:05 chuangzhu

Also, I just heard mainline kernel 6.1 added a PinePhone keyboard driver, torvalds/linux@1740696.

The kernel space driver is also in recent megous kernels. Setting KEYBOARD_PINEPHONE = yes; in mobile.kernel.structuredConfig, normalizing the kernel config, rebuilding and reflashing config.mobile.outputs.u-boot.boot-partition works for me.

@chuangzhu I am interested in trying your solution on my own PinePhone, do you have any documents online you could share on how I can do this? Thanks!

boozedog avatar May 08 '23 14:05 boozedog

@chuangzhu I am interested in trying your solution on my own PinePhone, do you have any documents online you could share on how I can do this? Thanks!

Add the following to mobile-nixos/devices/pine64-pinephone/default.nix:

mobile.kernel.structuredConfig =
  [ (helpers: with helpers; { KEYBOARD_PINEPHONE = yes; }) ];

then run ./bin/kernel-normalize-config pine64-pinephone to update mobile-nixos/devices/pine64-pinephone/kernel/config.aarch64. For rebuilding and reflashing the boot partition check https://mobile.nixos.org/devices/pine64-pinephone.html#_updating_the_boot_image.

If you don't want to maintain a fork of mobile-nixos you can copy mobile-nixos/devices/pine64-pinephone/kernel/ to your config repo and add

mobile.kernel.structuredConfig =
  [ (helpers: with helpers; { KEYBOARD_PINEPHONE = yes; }) ];
mobile.boot.stage-1.kernel.package = lib.mkForce (pkgs.callPackage ./kernel { });

to your configuration. I don't know if there is a better approach.

At first I thought that I had to overlay the hardware.deviceTree to use the keyboard, but it turns out that sun50i-a64-pinephone-1.2.dtb already includes a pine64,pinephone-keyboard node (even when CONFIG_KEYBOARD_PINEPHONE is not set).

chuangzhu avatar May 08 '23 15:05 chuangzhu

but it turns out that [the device tree] already includes a pine64,pinephone-keyboard node (even when CONFIG_KEYBOARD_PINEPHONE is not set).

AFAIK all device trees are "static", and not influenced by the kernel config. In theory they should be static facts describing the exact details of the hardware.

In practice it's a bit more subtle because it may be that some hardware isn't actually present, but that shouldn't be a configuration at build-time, but something handled in the firmware, with some additional knowledge or configuration (think a bios option to tell the system has a keyboard or not).

samueldr avatar May 08 '23 21:05 samueldr

Does including KEYBOARD_PINEPHONE = yes cause issues if the keyboard is not attached? Meaning, can we set KEYBOARD_PINEPHONE = yes in Mobile NixOS for PinePhone and call it a day? If not, we can include a configuration setting that that passes KEYBOARD_PINEPHONE = yes through to the kernel configuration.

justinlovinger avatar May 23 '23 12:05 justinlovinger