diff --git a/hosts/modules/hal/pine64-pinephone-pro/default.nix b/hosts/modules/hal/pine64-pinephone-pro/default.nix index fdcef4cc9..c81b37266 100644 --- a/hosts/modules/hal/pine64-pinephone-pro/default.nix +++ b/hosts/modules/hal/pine64-pinephone-pro/default.nix @@ -36,7 +36,7 @@ in "pine64-alsa-ucm" # upstreaming: https://github.com/alsa-project/alsa-ucm-conf/pull/375 ]; - # sane.programs.nwg-panel.config.torch = "white:flash"; #< TODO: enable the flashlight/torch + sane.programs.nwg-panel.config.torch = "white:flash"; sane.programs.swaynotificationcenter.config = { backlight = "backlight"; # /sys/class/backlight/*backlight*/brightness }; @@ -44,6 +44,18 @@ in # else it'll change to something which produces no sound (like the "Voice Call" use case) # sane.programs.callaudiod.enableFor.user.colin = lib.mkForce false; + services.udev.extraRules = let + chmod = lib.getExe' pkgs.coreutils "chmod"; + chown = lib.getExe' pkgs.coreutils "chown"; + in '' + # make flashlight/torch writable by user. + # taken from postmarketOS: + SUBSYSTEM=="leds", DEVPATH=="*/*:flash", RUN+="${chmod} g+w /sys%p/brightness /sys%p/flash_strobe", RUN+="${chown} :video /sys%p/brightness /sys%p/flash_strobe" + + # make the front led (and all leds) user-writable (because why not) + SUBSYSTEM=="leds", DEVPATH=="*/*", RUN+="${chmod} g+w /sys%p/brightness /sys%p/flash_strobe", RUN+="${chown} :video /sys%p/brightness" + ''; + boot.kernelPatches = [ { # TODO: upstream into nixpkgs. @@ -68,18 +80,22 @@ in name = "rk3399-pinephone-pro-battery"; dtsFile = ./rk3399-pinephone-pro-battery.dtso; } + { + name = "rk3399-pinephone-pro-flash-led"; + dtsFile = ./rk3399-pinephone-pro-flash-led.dtso; + } { name = "rk3399-pinephone-pro-lradc-fix"; dtsFile = ./rk3399-pinephone-pro-lradc-fix.dtso; } - { - name = "rk3399-pinephone-pro-sound"; - dtsFile = ./rk3399-pinephone-pro-sound.dtso; - } { name = "rk3399-pinephone-pro-modem"; dtsFile = ./rk3399-pinephone-pro-modem.dtso; } + { + name = "rk3399-pinephone-pro-sound"; + dtsFile = ./rk3399-pinephone-pro-sound.dtso; + } ]; # this seems to not actually be necessary (unless maybe my *overlay* #include's stuff) diff --git a/hosts/modules/hal/pine64-pinephone-pro/rk3399-pinephone-pro-flash-led.dtso b/hosts/modules/hal/pine64-pinephone-pro/rk3399-pinephone-pro-flash-led.dtso new file mode 100644 index 000000000..7eb487c9d --- /dev/null +++ b/hosts/modules/hal/pine64-pinephone-pro/rk3399-pinephone-pro-flash-led.dtso @@ -0,0 +1,43 @@ +// for LED_FUNCTION_FLASH, etc +#include +// for RK_PC6, other pins +#include +// for GPIO_ACTIVE_HIGH +#include + +/dts-v1/; +/plugin/; + +/ { + /* ensure this overlay applies only to the correct board */ + compatible = "pine64,pinephone-pro"; +}; + +// taken from pine64-org/rk3399-pinephone-pro.dts, did not validate against schematic. +// subset of 41742e56f5: "arm64: dts: pinephone-pro: Add camera support" +&{/} { + sgm3140: led-controller { + compatible = "sgmicro,sgm3140"; + vin-supply = <&vcc3v3_sys>; + pinctrl-names = "default"; + pinctrl-0 = <&flash_pins>; + enable-gpios = <&gpio4 RK_PC6 GPIO_ACTIVE_HIGH>; + flash-gpios = <&gpio1 RK_PA3 GPIO_ACTIVE_HIGH>; + + sgm3140_flash: led { + function = LED_FUNCTION_FLASH; + color = ; + flash-max-timeout-us = <250000>; + }; + }; +}; + +&pinctrl { + leds { + flash_pins: flash-pins { + rockchip,pins = + <1 RK_PA3 RK_FUNC_GPIO &pcfg_pull_none>, + <4 RK_PC6 RK_FUNC_GPIO &pcfg_pull_none>; + }; + }; +};