From ee8e9a7bea33f240184b45efced1e523fbbc6767 Mon Sep 17 00:00:00 2001 From: Yureka Lilian Date: Sat, 26 Sep 2026 16:51:46 +0200 Subject: [PATCH] pinctrl: apple: Add t8140-pinctrl support Ensure the regmap does not attempt to read REG_GPIOx of any of the pins marked with gpio-reserved-ranges. For this purpose, move the regmap_init just before the first regmap_read, at which point the valid_mask has been populated from the gpio-reserved-ranges device tree property. With this, make the driver accept the new t8140 base compatible as with this modifications the driver can now be loaded on this SoC without crashing. Signed-off-by: Yureka Lilian Signed-off-by: Linus Walleij --- drivers/pinctrl/pinctrl-apple-gpio.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 6305b96aaa73..6b26a23d283c 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -66,6 +66,13 @@ struct apple_gpio_pinctrl { #define REG_GPIOx_DRIVE_STRENGTH1 GENMASK(23, 22) #define REG_IRQ(g, x) (0x800 + 0x40 * (g) + 4 * ((x) >> 5)) +static bool apple_gpio_readable_register(struct device *dev, unsigned int reg) +{ + struct apple_gpio_pinctrl *pctl = dev_get_drvdata(dev); + + return gpiochip_line_is_valid(&pctl->gpio_chip, reg / 4); +} + static const struct regmap_config regmap_config = { .reg_bits = 32, .val_bits = 32, @@ -75,6 +82,7 @@ static const struct regmap_config regmap_config = { .num_reg_defaults_raw = 512, .use_relaxed_mmio = true, .use_raw_spinlock = true, + .readable_reg = apple_gpio_readable_register, }; /* No locking needed to mask/unmask IRQs as the interrupt mode is per pin-register. */ @@ -90,6 +98,13 @@ static u32 apple_gpio_get_reg(struct apple_gpio_pinctrl *pctl, int ret; u32 val; + if (!pctl->map) { + pctl->map = devm_regmap_init_mmio(pctl->dev, pctl->base, ®map_config); + if (IS_ERR(pctl->map)) + return dev_err_probe(pctl->dev, PTR_ERR(pctl->map), + "Failed to create regmap\n"); + } + ret = regmap_read(pctl->map, REG_GPIO(pin), &val); if (ret) return 0; @@ -475,11 +490,6 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) if (IS_ERR(pctl->base)) return PTR_ERR(pctl->base); - pctl->map = devm_regmap_init_mmio(&pdev->dev, pctl->base, ®map_config); - if (IS_ERR(pctl->map)) - return dev_err_probe(&pdev->dev, PTR_ERR(pctl->map), - "Failed to create regmap\n"); - for (i = 0; i < npins; i++) { pins[i].number = i; pins[i].name = devm_kasprintf(&pdev->dev, GFP_KERNEL, "PIN%u", i); @@ -522,6 +532,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", }, { .compatible = "apple,t8103-pinctrl", }, { .compatible = "apple,pinctrl", }, { }