From: Sergiu Moga Date: Thu, 1 Sep 2022 14:22:41 +0000 (+0300) Subject: pinctrl: at91-pio4: Bind GPIO driver to the pinctrl DT node X-Git-Tag: v2023.07~312^2~9^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2ed96a87d2c7f22fe2649f6e041cc3884a0dbea7;p=platform%2Fkernel%2Fu-boot.git pinctrl: at91-pio4: Bind GPIO driver to the pinctrl DT node This has been done in order to align the DT of U-Boot with the DT of Linux. In Linux, a phandle from a '-gpio' DT property is linked to the pinctrl driver, a single driver that handles both pinctrl settings and offers GPIO API to callers. On the other hand, U-Boot redirects such phandle to a corresponding UCLASS_GPIO driver, because U-Boot offers two different types of drivers in this case: UCLASS_PINCTRL which handles pin functions and UCLASS_GPIO which handles gpio requests as a gpio provider. Due to this, we have two drivers in Uboot, but the Devicetree has a single node. Thus, just one of the drivers can be probed for the DT node during platform initialization, before relocation. Our previous solution in U-Boot was to have a different devicetree: the gpio node has a subnode for the pinctrl driver, which is not compliant with Linux ABI. Furthermore, our documentation for this type of nodes mentions no such gpio compatible. After this patch, we can no longer add nodes with a gpio compatible in the DT. Thus, in order to link the pinctrl driver to the gpio one, a hook to the bind method of the former in U-Boot has been added and the GPIO related compatibles have been removed to avoid conflict when compatibles are enumerated and bound to drivers during platform start before relocation. The bind method will attach the GPIO driver to the pinctrl DT node so that every phandle coming from '-gpio' DT properties will be redirected to a valid driver attached to the pinctrl DT node. Signed-off-by: Sergiu Moga --- diff --git a/drivers/gpio/atmel_pio4.c b/drivers/gpio/atmel_pio4.c index 77a76c1..47ed297 100644 --- a/drivers/gpio/atmel_pio4.c +++ b/drivers/gpio/atmel_pio4.c @@ -350,10 +350,8 @@ static const struct atmel_pioctrl_data microchip_sama7g5_pioctrl_data = { static const struct udevice_id atmel_pio4_ids[] = { { - .compatible = "atmel,sama5d2-gpio", .data = (ulong)&atmel_sama5d2_pioctrl_data, }, { - .compatible = "microchip,sama7g5-gpio", .data = (ulong)µchip_sama7g5_pioctrl_data, }, {} diff --git a/drivers/pinctrl/pinctrl-at91-pio4.c b/drivers/pinctrl/pinctrl-at91-pio4.c index 26fb5d6..e434a38 100644 --- a/drivers/pinctrl/pinctrl-at91-pio4.c +++ b/drivers/pinctrl/pinctrl-at91-pio4.c @@ -9,6 +9,8 @@ #include #include #include +#include +#include #include #include #include @@ -28,6 +30,25 @@ struct atmel_pio4_plat { unsigned int slew_rate_support; }; +/* + * Table keeping track of the pinctrl driver's slew rate support and the + * corresponding index into the struct udevice_id of the gpio_atmel_pio4 GPIO + * driver. This has been done in order to align the DT of U-Boot with the DT of + * Linux. In Linux, a phandle from a '-gpio' DT property is linked to the + * pinctrl driver, unlike U-Boot which redirects this phandle to a corresponding + * UCLASS_GPIO driver. Thus, in order to link the two, a hook to the bind method + * of the pinctrl driver in U-Boot has been added. This bind method will attach + * the GPIO driver to the pinctrl DT node using this table. + * @slew_rate_support pinctrl driver's slew rate support + * @gdidx index into the GPIO driver's struct udevide_id + * (needed in order to properly bind with driver_data) + */ + +struct atmel_pinctrl_data { + unsigned int slew_rate_support; + int gdidx; +}; + static const struct pinconf_param conf_params[] = { { "bias-disable", PIN_CONFIG_BIAS_DISABLE, 0 }, { "bias-pull-up", PIN_CONFIG_BIAS_PULL_UP, 1 }, @@ -181,24 +202,57 @@ const struct pinctrl_ops atmel_pinctrl_ops = { static int atmel_pinctrl_probe(struct udevice *dev) { struct atmel_pio4_plat *plat = dev_get_plat(dev); - ulong priv = dev_get_driver_data(dev); + struct atmel_pinctrl_data *priv = (struct atmel_pinctrl_data *)dev_get_driver_data(dev); fdt_addr_t addr_base; - dev = dev_get_parent(dev); addr_base = dev_read_addr(dev); if (addr_base == FDT_ADDR_T_NONE) return -EINVAL; plat->reg_base = (struct atmel_pio4_port *)addr_base; - plat->slew_rate_support = priv; + plat->slew_rate_support = priv->slew_rate_support; return 0; } +static int atmel_pinctrl_bind(struct udevice *dev) +{ + struct udevice *g; + struct driver *drv; + ofnode node = dev_ofnode(dev); + struct atmel_pinctrl_data *priv = (struct atmel_pinctrl_data *)dev_get_driver_data(dev); + + if (!CONFIG_IS_ENABLED(ATMEL_PIO4)) + return 0; + + /* Obtain a handle to the GPIO driver */ + drv = lists_driver_lookup_name("gpio_atmel_pio4"); + if (!drv) + return -ENOENT; + + /* + * Bind the GPIO driver to the pinctrl DT node, together + * with its corresponding driver_data. + */ + return device_bind_with_driver_data(dev, drv, drv->name, + drv->of_match[priv->gdidx].data, + node, &g); +} + +static const struct atmel_pinctrl_data atmel_sama5d2_pinctrl_data = { + .gdidx = 0, +}; + +static const struct atmel_pinctrl_data microchip_sama7g5_pinctrl_data = { + .slew_rate_support = 1, + .gdidx = 1, +}; + static const struct udevice_id atmel_pinctrl_match[] = { - { .compatible = "atmel,sama5d2-pinctrl" }, + { .compatible = "atmel,sama5d2-pinctrl", + .data = (ulong)&atmel_sama5d2_pinctrl_data, }, { .compatible = "microchip,sama7g5-pinctrl", - .data = (ulong)1, }, + .data = (ulong)µchip_sama7g5_pinctrl_data, }, {} }; @@ -206,6 +260,7 @@ U_BOOT_DRIVER(atmel_pinctrl) = { .name = "pinctrl_atmel_pio4", .id = UCLASS_PINCTRL, .of_match = atmel_pinctrl_match, + .bind = atmel_pinctrl_bind, .probe = atmel_pinctrl_probe, .plat_auto = sizeof(struct atmel_pio4_plat), .ops = &atmel_pinctrl_ops,