Merge tag 'u-boot-stm32-mcu-20190423' of https://github.com/pchotard/u-boot
[oweals/u-boot.git] / drivers / pinctrl / pinctrl-uclass.c
index 6db0445067079dcb2bdc986d7a1b6cd49710da98..0e6c559d5efb21ed66325338ca86aadda70daed3 100644 (file)
@@ -127,6 +127,9 @@ static int pinconfig_post_bind(struct udevice *dev)
                ofnode_get_property(node, "compatible", &ret);
                if (ret >= 0)
                        continue;
+               /* If this node has "gpio-controller" property, skip */
+               if (ofnode_read_bool(node, "gpio-controller"))
+                       continue;
 
                if (ret != -FDT_ERR_NOTFOUND)
                        return ret;
@@ -179,11 +182,14 @@ static int pinctrl_select_state_simple(struct udevice *dev)
        int ret;
 
        /*
-        * For simplicity, assume the first device of PINCTRL uclass
-        * is the correct one.  This is most likely OK as there is
-        * usually only one pinctrl device on the system.
+        * For most system, there is only one pincontroller device. But in
+        * case of multiple pincontroller devices, probe the one with sequence
+        * number 0 (defined by alias) to avoid race condition.
         */
-       ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev);
+       ret = uclass_get_device_by_seq(UCLASS_PINCTRL, 0, &pctldev);
+       if (ret)
+               /* if not found, get the first one */
+               ret = uclass_get_device(UCLASS_PINCTRL, 0, &pctldev);
        if (ret)
                return ret;