[RFC 4/6] gpio: add scmi driver based on pinctrl

Simon Glass sjg at chromium.org
Thu Sep 7 14:23:05 CEST 2023


Hi AKASHI,

On Tue, 5 Sept 2023 at 20:41, AKASHI Takahiro
<takahiro.akashi at linaro.org> wrote:
>
> This DM-compliant driver deals with SCMI pinctrl protocol and presents
> gpio devices exposed by SCMI firmware (server).
>
> Signed-off-by: AKASHI Takahiro <takahiro.akashi at linaro.org>
> ---
>  drivers/pinctrl/pinctrl-scmi.c | 544 ++++++++++++++++++++++++++++++++-
>  1 file changed, 539 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/pinctrl/pinctrl-scmi.c b/drivers/pinctrl/pinctrl-scmi.c
> index 3ebdad57b86c..73d385bdbfcc 100644
> --- a/drivers/pinctrl/pinctrl-scmi.c
> +++ b/drivers/pinctrl/pinctrl-scmi.c
> @@ -11,21 +11,20 @@
>  #include <malloc.h>
>  #include <scmi_agent.h>
>  #include <scmi_protocols.h>
> +#include <asm-generic/gpio.h>
>  #include <dm/device_compat.h>
> +#include <dm/device-internal.h>
> +#include <dm/lists.h>
>  #include <dm/pinctrl.h>
>
[..]

> +
> +U_BOOT_DRIVER(scmi_gpio) = {
> +       .name = "scmi_gpio",
> +       .id = UCLASS_GPIO,
> +       .of_match = scmi_gpio_ids,
> +       .of_to_plat = scmi_gpio_probe,
> +       .ops = &scmi_gpio_ops,
> +       .plat_auto = sizeof(struct scmi_pinctrl_gpio_plat),
> +};
> +
> +/**
> + * scmi_gpiochip_register - Create a pinctrl-controlled gpio device
> + * @parent:    SCMI pinctrl device
> + *
> + * Create a pinctrl-controlled gpio device
> + *
> + * Return:     0 on success, error code on failure
> + */
> +static int scmi_gpiochip_register(struct udevice *parent)
> +{
> +       ofnode node;
> +       struct driver *drv;
> +       struct udevice *gpio_dev;
> +       int ret;
> +
> +       /* TODO: recovery if failed */
> +       dev_for_each_subnode(node, parent) {
> +               if (!ofnode_is_enabled(node))
> +                       continue;

Can we not rely on the normal driver model binding to bind these
devices? Why does it need to be done manually here?
> +
> +               if (!ofnode_read_prop(node, "gpio-controller", NULL))
> +                       /* not a GPIO node */
> +                       continue;
> +
> +               drv = DM_DRIVER_GET(scmi_gpio);
> +               if (!drv) {
> +                       dev_err(parent, "No gpio driver?\n");
> +                       return -ENODEV;
> +               }
> +
> +               ret = device_bind(parent, drv, ofnode_get_name(node), NULL,
> +                                 node, &gpio_dev);
> +               if (ret) {
> +                       dev_err(parent, "failed to bind %s to gpio (%d)\n",
> +                               ofnode_get_name(node), ret);
> +                       return -ENODEV;
> +               }
> +
> +               return 0;
> +       }
> +
> +       return -ENODEV;
> +}
> +

Regards,
Simon


More information about the U-Boot mailing list