[U-Boot] Best way to use UCLASS_GPIO board id

Simon Glass sjg at chromium.org
Mon Nov 18 16:39:20 UTC 2019


Hi Michael,

On Sun, 10 Nov 2019 at 02:08, Michael Nazzareno Trimarchi
<michael at amarulasolutions.com> wrote:
>
> Hi Simon
>
> +       project_id: project-id {
> +               pid0: bid0 {
> +                       rockchip,pins = <2 RK_PA1 RK_FUNC_GPIO &pcfg_pull_up>;
> +               };
> +
> +               pid1: pid1 {
> +                       rockchip,pins = <2 RK_PA2 RK_FUNC_GPIO &pcfg_pull_up>;
> +               };
> +
> +               pid2: pid2 {
> +                       rockchip,pins = <2 RK_PA3 RK_FUNC_GPIO &pcfg_pull_up>;
> +               };
> +       };
> +
> +       pcb_id: pcb-id {
> +               pcbid0: pcbid0 {
> +                       rockchip,pins = <2 RK_PB0 RK_FUNC_GPIO &pcfg_pull_none>;
> +               };
> +
> +               pcbid1: pcbid1 {
> +                       rockchip,pins = <2 RK_PB1 RK_FUNC_GPIO &pcfg_pull_none>;
> +               };
> +
> +               pcbid2: pcbid2 {
> +                       rockchip,pins = <2 RK_PB2 RK_FUNC_GPIO &pcfg_pull_none>;
> +               };
> +       };
>
>
> I have defined the pins needed for tinker board and understand what
> board revision is. Now I would like to use them from spl_board_init
> and I have
> them in dtb
>
> +&pcbid0 {
> +       u-boot,dm-spl;
> +};
> +
> +&pcbid1 {
> +       u-boot,dm-spl;
> +};
> +
> +&pcbid2 {
> +       u-boot,dm-spl;
> +};
> +
> +&pid1 {
> +       u-boot,dm-spl;
> +};
> +
> +&pid2 {
> +       u-boot,dm-spl;
> +};
> +
> +&pid0 {
> +       u-boot,dm-spl;
> +};
> +
> +&pid1 {
> +       u-boot,dm-spl;
> +};
> +
> +&pid2 {
> +       u-boot,dm-spl;
> +};
>
> Now is there a way to reference them easily after probe the UCLASS_GPIO?
>
> +int spl_board_init(void)
> +{
> +       int ret;
> +       struct udevice *gpio_dev2 = NULL;
> +       struct udevice *gpio_dev6 = NULL;
> +
> +       if (uclass_get_device_by_name(UCLASS_GPIO, "gpio2 at ff790000",
> &gpio_dev2) ||
> +           uclass_get_device_by_name(UCLASS_GPIO, "gpio6 at ff7d0000",
> &gpio_dev6)) {
> +               printf("Could not get GPIO device.\n");
> +               return -EINVAL;
> +       }
> +
> +       ret = device_probe(gpio_dev2);
> +       if (ret)
> +               pr_err("%s - probe failed: %d\n", gpio_dev2->name, ret);
> +
> +       ret = device_probe(gpio_dev6);
> +       if (ret)
> +               pr_err("%s - probe failed: %d\n", gpio_dev6->name, ret);
>
>
> Michael

This seems pretty painful and doesn't really use pinctrl to best advantage.

My suggestion would be to create a driver in UCLASS_BOARD and put the
GPIOs into property, like:

your-board {
   compatible = "...";
   board-id-gpios = <&gpio0 5 GPIO_ACTIVE_HIGH
       &gpio2 3 GPIO_ACTIVE_HIGH
      ...>;
   pinctrl=0 = <&board_id>;

Then you can use gpio_request_list_by_name() to get the GPIOs and
dm_gpio_get_values_as_int() to convert them to an int.

For pinctrl, put it all in one node in pinctrl, like the others, e.g.
ids {
   board_id: board-id {
       rockchip,pins = <0 5 RK_FUNC_GPIO &pcfg_pull_up
           2 3 RK_FUNC_GPIO &pcfg_pull_up
             ...>;
    };
};

Good luck!

Regards,
Simon


More information about the U-Boot mailing list