From adfa06e0a9c39a0e4894335d38aa265252d21a86 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sun, 6 Jun 2021 18:28:46 +0200 Subject: [PATCH 1/3] onenetbook/4: init, fix stylus --- README.md | 2 + onenetbook/4/default.nix | 21 ++++++++ onenetbook/4/goodix-stylus-mastykin/Makefile | 7 +++ .../4/goodix-stylus-mastykin/default.nix | 49 +++++++++++++++++++ 4 files changed, 79 insertions(+) create mode 100644 onenetbook/4/default.nix create mode 100644 onenetbook/4/goodix-stylus-mastykin/Makefile create mode 100644 onenetbook/4/goodix-stylus-mastykin/default.nix diff --git a/README.md b/README.md index d346b73..f70a705 100644 --- a/README.md +++ b/README.md @@ -137,6 +137,7 @@ See code for all available configurations. | [Lenovo ThinkPad X1 (7th Gen)][] | `` | | Lenovo ThinkPad X1 Extreme Gen 2 | `` | | [Lenovo ThinkPad X13][] | `` | | [Microsoft Surface Pro 3][] | `` | | [MSI GS60 2QE][] | `` | @@ -181,6 +182,7 @@ See code for all available configurations. [Lenovo ThinkPad X260]: lenovo/thinkpad/x260 [Microsoft Surface Pro 3]: microsoft/surface-pro/3 [MSI GS60 2QE]: msi/gs60 +[One-Netbook OneNetbook 4]: onenetbook/4 [Raspberry Pi 2]: raspberry-pi/2 [Samsung Series 9 NP900X3C]: samsung/np900x3c [System76 (generic)]: system76 diff --git a/onenetbook/4/default.nix b/onenetbook/4/default.nix new file mode 100644 index 0000000..c02ba8a --- /dev/null +++ b/onenetbook/4/default.nix @@ -0,0 +1,21 @@ +{ pkgs, config, ... }: + +{ + imports = [ + ../../common/cpu/intel + ../../common/pc/laptop + ../../common/pc/laptop/ssd + ]; + + # OneNetbook 4 has `GXTP7386:00 27C6:011A Stylus` exporting no buttons in 5.12 + # and libinput does't consider it a tablet without them, but a touchscreen. + # This leads to real weird effects, + # starting from clicking as soon as the pen gets tracked. + # A kernel patch exists to resolve that, compiled as an out-of-tree module here + # to avoid recompiling the kernel for such a small change. + # `hid-multitouch-onenetbook4` is the fixed one, don't use `hid-multitouch`. + boot.blacklistedKernelModules = [ "hid-multitouch" ]; + boot.extraModulePackages = [ + (config.boot.kernelPackages.callPackage ./goodix-stylus-mastykin {}) + ]; +} diff --git a/onenetbook/4/goodix-stylus-mastykin/Makefile b/onenetbook/4/goodix-stylus-mastykin/Makefile new file mode 100644 index 0000000..7896ce0 --- /dev/null +++ b/onenetbook/4/goodix-stylus-mastykin/Makefile @@ -0,0 +1,7 @@ +obj-m += hid-multitouch-onenetbook4.o + +all: + make -C $(KERNEL_DIR) M=$(PWD) modules + +install: + make -C $(KERNEL_DIR) M=$(PWD) modules_install diff --git a/onenetbook/4/goodix-stylus-mastykin/default.nix b/onenetbook/4/goodix-stylus-mastykin/default.nix new file mode 100644 index 0000000..2f534a9 --- /dev/null +++ b/onenetbook/4/goodix-stylus-mastykin/default.nix @@ -0,0 +1,49 @@ +{ stdenv, lib, kernel, fetchpatch }: + +stdenv.mkDerivation rec { + name = "hid-multitouch-onenetbook4-${version}"; + version = kernel.version; + + hardeningDisable = [ "pic" "format" ]; + nativeBuildInputs = kernel.moduleBuildDependencies; + + src = ./.; + patches = [ + (fetchpatch { + url = "https://marc.info/?l=linux-input&m=161847127221531&q=p3"; + name = "goodix-stylus-mastykin-1-pen-support.patch"; + sha256 = "sha256-1oc8OvfhScYvtsMeV9A4hU+09i59tEJ6HZS6jspsJR8="; + }) + (fetchpatch { + url = "https://marc.info/?l=linux-input&m=161847127221531&q=p4"; + name = "goodix-stylus-mastykin-2-buttons.patch"; + sha256 = "sha256-HxmR8iEgoj4PJopGWJdWsjFxbfISwTMzz+HyG81mRG4="; + }) + ]; + + postUnpack = '' + tar -C goodix-stylus-mastykin \ + --strip-components=3 -xf ${kernel.src} --wildcards \ + '*/drivers/hid/hid-ids.h' '*/drivers/hid/hid-multitouch.c' + ''; + patchFlags = "-p3"; + postPatch = '' + mv hid-multitouch.c hid-multitouch-onenetbook4.c + substituteInPlace hid-multitouch-onenetbook4.c --replace \ + '.name = "hid-multitouch",' \ + '.name = "hid-multitouch-onenetbook4",' + substituteInPlace hid-multitouch-onenetbook4.c --replace \ + I2C_DEVICE_ID_GOODIX_0113 \ + 0x011A + ''; + + makeFlags = [ + "KERNEL_DIR=${kernel.dev}/lib/modules/${kernel.modDirVersion}/build" + "INSTALL_MOD_PATH=$(out)" + ]; + + meta = with lib; { + description = "hid-multitouch module patched for OneNetbook 4"; + platforms = platforms.linux; + }; +} From 9a4e7bdd2a7b256b6103a5adbf10175a59365664 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sun, 6 Jun 2021 20:13:16 +0200 Subject: [PATCH 2/3] onenetbook/4: fix accelerometer --- onenetbook/4/default.nix | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/onenetbook/4/default.nix b/onenetbook/4/default.nix index c02ba8a..374b69a 100644 --- a/onenetbook/4/default.nix +++ b/onenetbook/4/default.nix @@ -1,5 +1,9 @@ -{ pkgs, config, ... }: +{ pkgs, config, lib, ... }: +let + iio-sensor-proxy-supports-rotation = + lib.versionAtLeast pkgs.iio-sensor-proxy.version "3.0"; +in { imports = [ ../../common/cpu/intel @@ -18,4 +22,31 @@ boot.extraModulePackages = [ (config.boot.kernelPackages.callPackage ./goodix-stylus-mastykin {}) ]; + + # OneNetbook 4 has an accelerometer, + hardware.sensor.iio.enable = lib.mkDefault iio-sensor-proxy-supports-rotation; + # said accelerometer needs rotation, rotation needs iio-sensor-proxy >= 3.0 + services.udev.extraHwdb = lib.mkIf iio-sensor-proxy-supports-rotation '' + acpi:BOSC0200:BOSC0200:* + ACCEL_MOUNT_MATRIX=0, 1, 0; 0, 0, 1; 1, 0, 0 + ''; + # (this at least gets normal/left-up/right-up/bottom-up right) + # Until https://github.com/NixOS/nixpkgs/pull/125989 reaches you, you can use + #nixpkgs.overlays = [ + # (self: super: { + # iio-sensor-proxy = + # if (lib.versionOlder super.iio-sensor-proxy.version "3.0") then + # (super.iio-sensor-proxy.overrideAttrs (oa: rec { + # version = "3.0"; + # src = pkgs.fetchFromGitLab { + # domain = "gitlab.freedesktop.org"; + # owner = "hadess"; + # repo = "iio-sensor-proxy"; + # rev = version; + # sha256 = "0ngbz1vkbjci3ml6p47jh6c6caipvbkm8mxrc8ayr6vc2p9l1g49"; + # }; + # })) + # else super.iio-sensor-proxy; + # }) + #]; } From 4f74b8b63af6d896369b3c6bcd87eafa665e8b64 Mon Sep 17 00:00:00 2001 From: Alexander Sosedkin Date: Sat, 26 Jun 2021 12:05:54 +0200 Subject: [PATCH 3/3] onenetbook/4: update stylus patch for 5.12.12 --- .../5.12.12.patch.patch | 17 +++++++++ .../4/goodix-stylus-mastykin/default.nix | 35 ++++++++++++------- 2 files changed, 39 insertions(+), 13 deletions(-) create mode 100644 onenetbook/4/goodix-stylus-mastykin/5.12.12.patch.patch diff --git a/onenetbook/4/goodix-stylus-mastykin/5.12.12.patch.patch b/onenetbook/4/goodix-stylus-mastykin/5.12.12.patch.patch new file mode 100644 index 0000000..8cd8f31 --- /dev/null +++ b/onenetbook/4/goodix-stylus-mastykin/5.12.12.patch.patch @@ -0,0 +1,17 @@ +--- orig/patch1 ++++ updated/patch1 +@@ -10,11 +10,11 @@ + /* quirks to control the device */ + #define MT_QUIRK_NOT_SEEN_MEANS_UP BIT(0) + #define MT_QUIRK_SLOT_IS_CONTACTID BIT(1) +-@@ -70,6 +73,7 @@ +- #define MT_QUIRK_WIN8_PTP_BUTTONS BIT(18) ++@@ -71,6 +74,7 @@ + #define MT_QUIRK_SEPARATE_APP_REPORT BIT(19) + #define MT_QUIRK_FORCE_MULTI_INPUT BIT(20) +-+#define MT_QUIRK_NON_MT_PEN BIT(21) ++ #define MT_QUIRK_DISABLE_WAKEUP BIT(21) +++#define MT_QUIRK_NON_MT_PEN BIT(22) + + #define MT_INPUTMODE_TOUCHSCREEN 0x02 + #define MT_INPUTMODE_TOUCHPAD 0x03 diff --git a/onenetbook/4/goodix-stylus-mastykin/default.nix b/onenetbook/4/goodix-stylus-mastykin/default.nix index 2f534a9..d80749c 100644 --- a/onenetbook/4/goodix-stylus-mastykin/default.nix +++ b/onenetbook/4/goodix-stylus-mastykin/default.nix @@ -1,5 +1,25 @@ -{ stdenv, lib, kernel, fetchpatch }: +{ stdenv, lib, kernel, fetchpatch, runCommandNoCC, patch }: +let + patch1_original = fetchpatch { + url = "https://marc.info/?l=linux-input&m=161847127221531&q=p3"; + name = "goodix-stylus-mastykin-1-pen-support.patch"; + sha256 = "sha256-1oc8OvfhScYvtsMeV9A4hU+09i59tEJ6HZS6jspsJR8="; + }; + patch1_updated_5_12_12 = runCommandNoCC + "goodix-stylus-mastykin-1-pen-support-5.12.12.patch" {} + '' + cat ${patch1_original} > $out + ${patch}/bin/patch $out < ${./5.12.12.patch.patch} + ''; + patch1 = if (lib.versionAtLeast kernel.version "5.12.12") then + patch1_updated_5_12_12 else patch1_original; + patch2 = fetchpatch { + url = "https://marc.info/?l=linux-input&m=161847127221531&q=p4"; + name = "goodix-stylus-mastykin-2-buttons.patch"; + sha256 = "sha256-HxmR8iEgoj4PJopGWJdWsjFxbfISwTMzz+HyG81mRG4="; + }; +in stdenv.mkDerivation rec { name = "hid-multitouch-onenetbook4-${version}"; version = kernel.version; @@ -8,18 +28,7 @@ stdenv.mkDerivation rec { nativeBuildInputs = kernel.moduleBuildDependencies; src = ./.; - patches = [ - (fetchpatch { - url = "https://marc.info/?l=linux-input&m=161847127221531&q=p3"; - name = "goodix-stylus-mastykin-1-pen-support.patch"; - sha256 = "sha256-1oc8OvfhScYvtsMeV9A4hU+09i59tEJ6HZS6jspsJR8="; - }) - (fetchpatch { - url = "https://marc.info/?l=linux-input&m=161847127221531&q=p4"; - name = "goodix-stylus-mastykin-2-buttons.patch"; - sha256 = "sha256-HxmR8iEgoj4PJopGWJdWsjFxbfISwTMzz+HyG81mRG4="; - }) - ]; + patches = [ patch1 patch2 ]; postUnpack = '' tar -C goodix-stylus-mastykin \