From 221e1638e02d9b614b663fce5af8511ee98e0f3d Mon Sep 17 00:00:00 2001 From: Eric Anderson Date: Thu, 18 Jun 2026 17:59:12 -0700 Subject: [PATCH] lk2nd: hw: gpio: pm8921: Add devicetree flag for GPIO polarity inversion Allow configuring PMIC GPIO interrupt/input polarity inversion dynamically via a custom devicetree flag `GPIO_PMIC_INVERTED`. On the Asus Nexus 7 (flo), the primary bootloader configures the volume keys with inversion enabled and Linux does not seem to reconfigure this. When lk2nd configured the buttons, it cleared the inversion causing Linux to believe the buttons were pressed. --- lk2nd/device/dts/msm8960/bundle.dts | 4 ++-- lk2nd/hw/gpio/pm8921.c | 1 + lk2nd/hw/gpio/supplier.h | 1 + lk2nd/include/dt-bindings/lk2nd/gpio.h | 1 + 4 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lk2nd/device/dts/msm8960/bundle.dts b/lk2nd/device/dts/msm8960/bundle.dts index cf60c34c6..d3528cc76 100644 --- a/lk2nd/device/dts/msm8960/bundle.dts +++ b/lk2nd/device/dts/msm8960/bundle.dts @@ -14,11 +14,11 @@ volume-up { lk2nd,code = ; - gpios = <&pmic 3 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + gpios = <&pmic 3 (GPIO_ACTIVE_HIGH | GPIO_PMIC_INVERTED)>; }; volume-down { lk2nd,code = ; - gpios = <&pmic 37 (GPIO_ACTIVE_LOW | GPIO_PULL_UP)>; + gpios = <&pmic 37 (GPIO_ACTIVE_HIGH | GPIO_PMIC_INVERTED)>; }; }; }; diff --git a/lk2nd/hw/gpio/pm8921.c b/lk2nd/hw/gpio/pm8921.c index 64f503b61..b495ca2e5 100644 --- a/lk2nd/hw/gpio/pm8921.c +++ b/lk2nd/hw/gpio/pm8921.c @@ -18,6 +18,7 @@ int lk2nd_gpio_pmic_config(uint32_t num, int flags) .function = !!(flags & GPIOL_FLAGS_ASSERTED), .vin_sel = PMIC_FLAGS_VIN_SEL(flags), .out_strength = clamp(GPIOL_CONF_DRVSTR(flags), 0, 3), + .inv_int_pol = !!(flags & PMIC_FLAGS_INVERTED), }; if (flags & GPIO_PULL_UP) diff --git a/lk2nd/hw/gpio/supplier.h b/lk2nd/hw/gpio/supplier.h index d2c2a879c..f14955176 100644 --- a/lk2nd/hw/gpio/supplier.h +++ b/lk2nd/hw/gpio/supplier.h @@ -14,6 +14,7 @@ #define PMIC_FLAGS_VIN_SEL(x) BITS_SHIFT(num, 26, 24) #define PMIC_NON_DEFAULT_VIN_SEL BIT(27) +#define PMIC_FLAGS_INVERTED BIT(28) /* tlmm.c */ int lk2nd_gpio_tlmm_config(uint32_t num, int flags); diff --git a/lk2nd/include/dt-bindings/lk2nd/gpio.h b/lk2nd/include/dt-bindings/lk2nd/gpio.h index 363fda8d8..e14d1127e 100644 --- a/lk2nd/include/dt-bindings/lk2nd/gpio.h +++ b/lk2nd/include/dt-bindings/lk2nd/gpio.h @@ -45,6 +45,7 @@ /* 24:31 - Device-specific config flags */ #define GPIO_PMIC_VIN_SEL(x) (((x) & 0x07) << 24 | BIT(27)) /* bits 24:27 */ +#define GPIO_PMIC_INVERTED BIT(28) /* device-specific definitions */