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

Michael Nazzareno Trimarchi michael at amarulasolutions.com
Sun Nov 10 10:08:23 UTC 2019


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


-- 
| Michael Nazzareno Trimarchi                     Amarula Solutions BV |
| COO  -  Founder                                      Cruquiuskade 47 |
| +31(0)851119172                                 Amsterdam 1018 AM NL |
|                  [`as] http://www.amarulasolutions.com               |


More information about the U-Boot mailing list