From 6d69ad699718d16a166d12e8a8bc3bef00b72e24 Mon Sep 17 00:00:00 2001 From: Nate Crawford Date: Sun, 8 Nov 2026 07:03:18 +0000 Subject: [PATCH] pinctrl: samsung: Enable GPIO direction readback on Tensor G4 The Samsung GPIO chip has no get_direction() callback. gpiolib asks for the direction of a line when a shared GPIO proxy registers its chip and when a consumer requests a line through the proxy. It warns at drivers/gpio/gpiolib.c:431 each time the callback is missing. On the Pixel 9 Pro Fold, this produces three warnings at boot and one more each time a driver takes gpp10-2, the reset GPIO shared by the main camera and its lens actuator. Read the function field of the bank's CON register, which samsung_gpio_set_direction() writes. Report function 0x1 as GPIO output and input or alternate functions as GPIO input. Opt in through the zumapro pin controller data used by the Pixel 9 Pro Fold and the Pixel 9a, for the eight controllers zumapro.dtsi describes (ALIVE, CUSTOM, FAR, HSI1, HSI2, HSI2UFS, PERIC0, PERIC1). gpiolib reads each line's direction when the GPIO chip registers. The GSACORE and GSACTRL entries, which have no node yet, stay without it, as do the other SoCs, including gs101, whose secure pinctrl_gsactrl must not be read by Linux. With the callback, gpiochip_lock_as_irq() reads the pin direction and returns -EIO for a GPIO configured as a push-pull output ("tried to flag a GPIO set as output for IRQ"). exynos_irq_request_resources() calls it before switching the pin to EINT, so a pin left as an output by the bootloader can now be rejected at IRQ request time. Earlier Pixel 9 Pro Fold testing with the unconditional callback found no gpiolib.c:431 warning at boot, when the shared reset's consumers bound, or when reading /sys/kernel/debug/gpio. The line still read as an output driven low. On 2026-11-18, the Comet integration kernel 7.3.0-rc6-omamobile-comet-rc2-cand21 had the unconditional samsung_gpio_get_direction in kallsyms. Across two boots with all interrupt consumers bound, dmesg had zero "tried to flag a GPIO set as output for IRQ" lines. Assisted-by: LLM Signed-off-by: Nate Crawford --- .../pinctrl/samsung/pinctrl-exynos-arm64.c | 8 ++++ drivers/pinctrl/samsung/pinctrl-samsung.c | 43 ++++++++++++++++++- drivers/pinctrl/samsung/pinctrl-samsung.h | 2 + 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c b/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c index bab951eb0a..1c8a39a4e2 100644 --- a/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c +++ b/drivers/pinctrl/samsung/pinctrl-exynos-arm64.c @@ -2566,17 +2566,20 @@ static const struct samsung_pin_ctrl zumapro_pin_ctrl[] __initconst = { /* Controller 0: ALIVE */ .pin_banks = zumapro_pin_alive, .nr_banks = ARRAY_SIZE(zumapro_pin_alive), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, .eint_wkup_init = exynos_eint_wkup_init, }, { /* Controller 1: CUSTOM */ .pin_banks = zumapro_pin_custom, .nr_banks = ARRAY_SIZE(zumapro_pin_custom), + .has_get_direction = true, .eint_wkup_init = exynos_eint_wkup_init, }, { /* Controller 2: FAR */ .pin_banks = zumapro_pin_far, .nr_banks = ARRAY_SIZE(zumapro_pin_far), + .has_get_direction = true, .eint_wkup_init = exynos_eint_wkup_init, }, { /* Controller 3: GSACORE0 */ @@ -2607,26 +2610,31 @@ static const struct samsung_pin_ctrl zumapro_pin_ctrl[] __initconst = { /* Controller 8: HSI1 */ .pin_banks = zumapro_pin_hsi1, .nr_banks = ARRAY_SIZE(zumapro_pin_hsi1), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, }, { /* Controller 9: HSI2 */ .pin_banks = zumapro_pin_hsi2, .nr_banks = ARRAY_SIZE(zumapro_pin_hsi2), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, }, { /* Controller 10: HSI2UFS */ .pin_banks = zumapro_pin_hsi2ufs, .nr_banks = ARRAY_SIZE(zumapro_pin_hsi2ufs), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, }, { /* Controller 11: PERIC0 */ .pin_banks = zumapro_pin_peric0, .nr_banks = ARRAY_SIZE(zumapro_pin_peric0), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, }, { /* Controller 12: PERIC1 */ .pin_banks = zumapro_pin_peric1, .nr_banks = ARRAY_SIZE(zumapro_pin_peric1), + .has_get_direction = true, .eint_gpio_init = exynos_eint_gpio_init, }, }; diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.c b/drivers/pinctrl/samsung/pinctrl-samsung.c index 009eccf13b..017a74327d 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.c +++ b/drivers/pinctrl/samsung/pinctrl-samsung.c @@ -1064,6 +1064,42 @@ static int samsung_gpio_set_config(struct gpio_chip *gc, unsigned int offset, return ret; } +/* gpiolib gpio_get_direction callback function. */ +static int samsung_gpio_get_direction(struct gpio_chip *gc, unsigned int offset) +{ + struct samsung_pin_bank *bank = gpiochip_get_data(gc); + const struct samsung_pin_bank_type *type = bank->type; + struct samsung_pinctrl_drv_data *drvdata = bank->drvdata; + void __iomem *reg; + u32 data, mask, shift; + int ret; + + reg = bank->pctl_base + bank->pctl_offset + + type->reg_offset[PINCFG_TYPE_FUNC]; + mask = (1 << type->fld_width[PINCFG_TYPE_FUNC]) - 1; + shift = offset * type->fld_width[PINCFG_TYPE_FUNC]; + if (shift >= 32) { + /* Some banks have two config registers */ + shift -= 32; + reg += 4; + } + + ret = clk_enable(drvdata->pclk); + if (ret) { + dev_err(drvdata->dev, "failed to enable clock\n"); + return ret; + } + + data = (readl(reg) >> shift) & mask; + + clk_disable(drvdata->pclk); + + if (data == PIN_CON_FUNC_OUTPUT) + return GPIO_LINE_DIRECTION_OUT; + + return GPIO_LINE_DIRECTION_IN; +} + static const struct gpio_chip samsung_gpiolib_chip = { .request = gpiochip_generic_request, .free = gpiochip_generic_free, @@ -1079,7 +1115,8 @@ static const struct gpio_chip samsung_gpiolib_chip = { /* register the gpiolib interface with the gpiolib subsystem */ static int samsung_gpiolib_register(struct platform_device *pdev, - struct samsung_pinctrl_drv_data *drvdata) + struct samsung_pinctrl_drv_data *drvdata, + const struct samsung_pin_ctrl *ctrl) { struct samsung_pin_bank *bank = drvdata->pin_banks; struct gpio_chip *gc; @@ -1095,6 +1132,8 @@ static int samsung_gpiolib_register(struct platform_device *pdev, gc->parent = &pdev->dev; gc->fwnode = bank->fwnode; gc->label = bank->name; + if (ctrl->has_get_direction) + gc->get_direction = samsung_gpio_get_direction; ret = devm_gpiochip_add_data(&pdev->dev, gc, bank); if (ret) { @@ -1311,7 +1350,7 @@ static int samsung_pinctrl_probe(struct platform_device *pdev) else samsung_pud_value_init(drvdata); - ret = samsung_gpiolib_register(pdev, drvdata); + ret = samsung_gpiolib_register(pdev, drvdata, ctrl); if (ret) goto err_unregister; diff --git a/drivers/pinctrl/samsung/pinctrl-samsung.h b/drivers/pinctrl/samsung/pinctrl-samsung.h index aafe1d311f..3eb64917f1 100644 --- a/drivers/pinctrl/samsung/pinctrl-samsung.h +++ b/drivers/pinctrl/samsung/pinctrl-samsung.h @@ -267,6 +267,7 @@ struct samsung_retention_data { * @pin_banks: list of pin banks included in this controller. * @nr_banks: number of pin banks. * @nr_ext_resources: number of the extra base address for pin banks. + * @has_get_direction: enable GPIO direction readback for this controller. * @retention_data: configuration data for retention control. * @eint_gpio_init: platform specific callback to setup the external gpio * interrupts for the controller. @@ -284,6 +285,7 @@ struct samsung_pin_ctrl { const struct samsung_pin_bank_data *pin_banks; unsigned int nr_banks; unsigned int nr_ext_resources; + bool has_get_direction; const struct samsung_retention_data *retention_data; int (*eint_gpio_init)(struct samsung_pinctrl_drv_data *);