diff mbox series

[U-Boot,v1,1/2] dm: pinctrl: Avoid race condition on probe for UCLASS_PINCTRL

Message ID 1550241059-4544-2-git-send-email-patrice.chotard@st.com
State Superseded
Delegated to: Tom Rini
Headers show
Series Update pinctrl-uclass | expand

Commit Message

Patrice CHOTARD Feb. 15, 2019, 2:30 p.m. UTC
In case of system with several pin-controller device, probe the first
UCLASS_PINCTRL by seq number (defined by alias) to avoid race condition
with I2C PINCONTROL driver for GPIO expander (GPIO expander need I2C bus,
I2C driver need PINCONFIG).

Signed-off-by: Patrick DELAUNAY <patrick.delaunay@st.com>
Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
---

 drivers/pinctrl/pinctrl-uclass.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

Comments

Simon Glass Feb. 15, 2019, 5:11 p.m. UTC | #1
On Fri, 15 Feb 2019 at 15:31, Patrice Chotard <patrice.chotard@st.com> wrote:
>
> In case of system with several pin-controller device, probe the first
> UCLASS_PINCTRL by seq number (defined by alias) to avoid race condition
> with I2C PINCONTROL driver for GPIO expander (GPIO expander need I2C bus,
> I2C driver need PINCONFIG).
>
> Signed-off-by: Patrick DELAUNAY <patrick.delaunay@st.com>
> Signed-off-by: Patrice Chotard <patrice.chotard@st.com>
> ---
>
>  drivers/pinctrl/pinctrl-uclass.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/drivers/pinctrl/pinctrl-uclass.c b/drivers/pinctrl/pinctrl-uclass.c
index 0e3260afd1ee..abb622cfe79e 100644
--- a/drivers/pinctrl/pinctrl-uclass.c
+++ b/drivers/pinctrl/pinctrl-uclass.c
@@ -201,11 +201,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;