From a0609dcd5e4eea9f23a8a3d3adaa9011edca3433 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 15 Nov 2026 15:37:26 +0000 Subject: [PATCH] pinctrl: apple: clear bit 4 of the GPIO mode on the T6050 On the K114c the NUB GPIO block comes out of iBoot with bit 4 of the touch-screen reset and power pins set (0x474210, 0x474212 as read through /dev/mem). With that bit set, the DATA bit does not latch in output mode: writing 0x474213 reads back 0x474212, writing 0x474203 reads back 0x474203. direction_output wrote only bits 1-3 of the mode, so the pin stayed in a state where the driver's output value never took effect. Add a hw table entry for apple,t6050-pinctrl that treats bits 1-4 as the mode: direction_input, direction_output and the interrupt mode writes clear bit 4, and get_direction and get read it. Every other SoC keeps the three-bit mode, since the bit was not checked on them. Modes 0-7 are unchanged, and a working output (the PERST# pin of the K114c, register 0x00076a03) has the bit clear. Tested: drivers/pinctrl/pinctrl-apple-gpio.o builds with gcc 16.1.1 and W=1, no warnings, with and without the change, on a depth-1 checkout of integration/aurora (580e9119) on a 13-inch M1 MacBook. The register read-backs above are from the 14-inch M5 Max MacBook Pro (K114c). An earlier form of this change (all SoCs, mode bits 1-4) was booted there in the touch screen stack; this T6050-only form was not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/pinctrl/pinctrl-apple-gpio.c | 35 +++++++++++++++++++++------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 2f0c25e38c67f..b00ee85fc7c0d 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -56,12 +56,15 @@ struct apple_gpio_pinctrl { unsigned long *saved_valid; /* Pins this driver has written. Others belong to someone else. */ unsigned long *touched; + /* Bit 4 of the mode field, on SoCs where iBoot leaves it set */ + u32 mode_hi; struct apple_gpio_irq_group irqgrps[]; }; #define REG_GPIO(x) (4 * (x)) #define REG_GPIOx_DATA BIT(0) #define REG_GPIOx_MODE GENMASK(3, 1) +#define REG_GPIOx_MODE_HI BIT(4) #define REG_GPIOx_OUT 1 #define REG_GPIOx_IN_IRQ_HI 2 #define REG_GPIOx_IN_IRQ_LO 3 @@ -217,6 +220,12 @@ static const struct pinmux_ops apple_gpio_pinmux_ops = { .strict = true, }; +/* The mode bits to read and to clear: bits 1-3, and bit 4 where the hw table says so */ +static u32 apple_gpio_mode_mask(const struct apple_gpio_pinctrl *pctl) +{ + return REG_GPIOx_MODE | pctl->mode_hi; +} + /* GPIO chip functions */ static int apple_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) @@ -224,7 +233,7 @@ static int apple_gpio_get_direction(struct gpio_chip *chip, unsigned int offset) struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); unsigned int reg = apple_gpio_get_reg(pctl, offset); - if (FIELD_GET(REG_GPIOx_MODE, reg) == REG_GPIOx_OUT) + if ((reg & apple_gpio_mode_mask(pctl)) == FIELD_PREP(REG_GPIOx_MODE, REG_GPIOx_OUT)) return GPIO_LINE_DIRECTION_OUT; return GPIO_LINE_DIRECTION_IN; } @@ -238,7 +247,7 @@ static int apple_gpio_get(struct gpio_chip *chip, unsigned int offset) * If this is an input GPIO, read the actual value (not the * cached regmap value) */ - if (FIELD_GET(REG_GPIOx_MODE, reg) != REG_GPIOx_OUT) + if ((reg & apple_gpio_mode_mask(pctl)) != FIELD_PREP(REG_GPIOx_MODE, REG_GPIOx_OUT)) reg = readl_relaxed(pctl->base + REG_GPIO(offset)); return !!(reg & REG_GPIOx_DATA); @@ -258,7 +267,7 @@ static int apple_gpio_direction_input(struct gpio_chip *chip, unsigned int offse struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); apple_gpio_set_reg(pctl, offset, - REG_GPIOx_PERIPH | REG_GPIOx_MODE | REG_GPIOx_DATA | + REG_GPIOx_PERIPH | apple_gpio_mode_mask(pctl) | REG_GPIOx_DATA | REG_GPIOx_INPUT_ENABLE, FIELD_PREP(REG_GPIOx_MODE, REG_GPIOx_IN_IRQ_OFF) | REG_GPIOx_INPUT_ENABLE); @@ -271,7 +280,7 @@ static int apple_gpio_direction_output(struct gpio_chip *chip, struct apple_gpio_pinctrl *pctl = gpiochip_get_data(chip); apple_gpio_set_reg(pctl, offset, - REG_GPIOx_PERIPH | REG_GPIOx_MODE | REG_GPIOx_DATA, + REG_GPIOx_PERIPH | apple_gpio_mode_mask(pctl) | REG_GPIOx_DATA, FIELD_PREP(REG_GPIOx_MODE, REG_GPIOx_OUT) | (value ? REG_GPIOx_DATA : 0)); return 0; @@ -310,7 +319,7 @@ static void apple_gpio_irq_mask(struct irq_data *data) struct gpio_chip *gc = irq_data_get_irq_chip_data(data); struct apple_gpio_pinctrl *pctl = gpiochip_get_data(gc); - apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, + apple_gpio_set_reg(pctl, data->hwirq, apple_gpio_mode_mask(pctl), FIELD_PREP(REG_GPIOx_MODE, REG_GPIOx_IN_IRQ_OFF)); gpiochip_disable_irq(gc, data->hwirq); } @@ -329,7 +338,7 @@ static void apple_gpio_irq_unmask(struct irq_data *data) unsigned int irqtype = apple_gpio_irq_type(irqd_get_trigger_type(data)); gpiochip_enable_irq(gc, data->hwirq); - apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, + apple_gpio_set_reg(pctl, data->hwirq, apple_gpio_mode_mask(pctl), FIELD_PREP(REG_GPIOx_MODE, irqtype)); } @@ -355,7 +364,7 @@ static int apple_gpio_irq_set_type(struct irq_data *data, unsigned int type) if (irqtype == REG_GPIOx_IN_IRQ_OFF) return -EINVAL; - apple_gpio_set_reg(pctl, data->hwirq, REG_GPIOx_MODE, + apple_gpio_set_reg(pctl, data->hwirq, apple_gpio_mode_mask(pctl), FIELD_PREP(REG_GPIOx_MODE, irqtype)); if (type & IRQ_TYPE_LEVEL_MASK) @@ -411,6 +420,8 @@ struct apple_gpio_hw { * only within the valid GPIO registers minus gpio-reserved-ranges. */ bool no_regcache; + /* iBoot leaves bit 4 of the mode field set on some pins (T6050 touch screen) */ + bool mode_hi; }; /* T8140 (A18 Pro) and T8132 (M4) both have faulting slots in this block. */ @@ -418,6 +429,12 @@ static const struct apple_gpio_hw apple_gpio_uncached_hw = { .no_regcache = true, }; +/* T6050 (M5 Max) has the same faulting slots, and iBoot leaves mode bit 4 set on some pins. */ +static const struct apple_gpio_hw apple_gpio_t6050_hw = { + .no_regcache = true, + .mode_hi = true, +}; + static int apple_gpio_regmap_access(struct device *dev, unsigned int npins, struct regmap_config *config) { @@ -562,6 +579,8 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) if (!pctl) return -ENOMEM; pctl->dev = &pdev->dev; + if (hw && hw->mode_hi) + pctl->mode_hi = REG_GPIOx_MODE_HI; pctl->irq_group_base = irq_group_base; pctl->gpio_chip.irq.num_parents = nirqs; dev_set_drvdata(&pdev->dev, pctl); @@ -664,7 +683,7 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) static const struct of_device_id apple_gpio_pinctrl_of_match[] = { { .compatible = "apple,t8140-pinctrl", .data = &apple_gpio_uncached_hw }, { .compatible = "apple,t8132-pinctrl", .data = &apple_gpio_uncached_hw }, - { .compatible = "apple,t6050-pinctrl", .data = &apple_gpio_uncached_hw }, + { .compatible = "apple,t6050-pinctrl", .data = &apple_gpio_t6050_hw }, { .compatible = "apple,t8103-pinctrl", }, { .compatible = "apple,pinctrl", }, { }