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", }, { }