summaryrefslogtreecommitdiffstats
path: root/configs/platform-v7a/patches/barebox-2020.02.0/0001-USB-MUSB-PHY-scrap-singleton-am335x_get_usb_phy.patch
blob: 2250399200d1ccb5bac4d82f596dbf2fb8d4bfa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
Date: Tue, 25 Feb 2020 17:57:30 +0100
Subject: [PATCH] USB: MUSB: PHY: scrap singleton am335x_get_usb_phy()

am335x_get_usb_phy() retrieves the last probed USB phy. On the BeagleBone
with both PHYs enabled, this means that dependent on probe order, both
MUSB instances could end up with the same PHY.

Remove the global variable and have the MUSB driver parse the "phys"
property instead.

The cleaner way to achieve this would be to migrate phy-am335x.c
and phy-am335x-control.c to the generic phy framework and have MUSB use
of_phy_get, alas, even Linux hasn't done this so far and we need
a short patch for master anyway, thus just do it the easy way.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
Tested-by: Yegor Yefremov <yegorslists@googlemail.com>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/usb/musb/musb_dsps.c  | 16 +++++++++++-----
 drivers/usb/musb/phy-am335x.c | 11 ++---------
 drivers/usb/musb/phy-am335x.h |  6 ------
 3 files changed, 13 insertions(+), 20 deletions(-)
 delete mode 100644 drivers/usb/musb/phy-am335x.h

diff --git a/drivers/usb/musb/musb_dsps.c b/drivers/usb/musb/musb_dsps.c
index 3b76b6cc610d..f30672914830 100644
--- a/drivers/usb/musb/musb_dsps.c
+++ b/drivers/usb/musb/musb_dsps.c
@@ -39,7 +39,6 @@
 #include <linux/barebox-wrapper.h>
 
 #include "musb_core.h"
-#include "phy-am335x.h"
 
 static __maybe_unused struct of_device_id musb_dsps_dt_ids[];
 
@@ -217,10 +216,6 @@ static int dsps_musb_init(struct musb *musb)
 	const struct dsps_musb_wrapper *wrp = glue->wrp;
 	u32 rev, val, mode;
 
-	musb->xceiv = am335x_get_usb_phy();
-	if (IS_ERR(musb->xceiv))
-		return PTR_ERR(musb->xceiv);
-
 	/* Returns zero if e.g. not clocked */
 	rev = dsps_readl(musb->ctrl_base, wrp->revision);
 	if (!rev)
@@ -324,6 +319,8 @@ static int dsps_probe(struct device_d *dev)
 	struct musb_hdrc_config	*config;
 	struct device_node *dn = dev->device_node;
 	const struct dsps_musb_wrapper *wrp;
+	struct device_node *phy_node;
+	struct device_d *phy_dev;
 	struct dsps_glue *glue;
 	int ret;
 
@@ -337,6 +334,14 @@ static int dsps_probe(struct device_d *dev)
 		return -ENODEV;
 	}
 
+	phy_node = of_parse_phandle(dn, "phys", 0);
+	if (!phy_node)
+		return -ENODEV;
+
+	phy_dev = of_find_device_by_node(phy_node);
+	if (!phy_dev || !phy_dev->priv)
+		return -EPROBE_DEFER;
+
 	/* allocate glue */
 	glue = kzalloc(sizeof(*glue), GFP_KERNEL);
 	if (!glue) {
@@ -360,6 +365,7 @@ static int dsps_probe(struct device_d *dev)
 	glue->musb.ctrl_base = IOMEM(iores->start);
 
 	glue->musb.controller = dev;
+	glue->musb.xceiv = phy_dev->priv;
 
 	config = &glue->config;
 
diff --git a/drivers/usb/musb/phy-am335x.c b/drivers/usb/musb/phy-am335x.c
index df31255d891c..6991f4402d3f 100644
--- a/drivers/usb/musb/phy-am335x.c
+++ b/drivers/usb/musb/phy-am335x.c
@@ -5,7 +5,6 @@
 #include <linux/err.h>
 #include "am35x-phy-control.h"
 #include "musb_core.h"
-#include "phy-am335x.h"
 
 struct am335x_usbphy {
 	void __iomem *base;
@@ -14,13 +13,6 @@ struct am335x_usbphy {
 	struct usb_phy phy;
 };
 
-static struct am335x_usbphy *am_usbphy;
-
-struct usb_phy *am335x_get_usb_phy(void)
-{
-	return &am_usbphy->phy;
-}
-
 static int am335x_init(struct usb_phy *phy)
 {
 	struct am335x_usbphy *am_usbphy = container_of(phy, struct am335x_usbphy, phy);
@@ -31,6 +23,7 @@ static int am335x_init(struct usb_phy *phy)
 
 static int am335x_phy_probe(struct device_d *dev)
 {
+	struct am335x_usbphy *am_usbphy;
 	struct resource *iores;
 	int ret;
 
@@ -54,7 +47,7 @@ static int am335x_phy_probe(struct device_d *dev)
 	}
 
 	am_usbphy->phy.init = am335x_init;
-	dev->priv = am_usbphy;
+	dev->priv = &am_usbphy->phy;
 
 	dev_info(dev, "am_usbphy %p enabled\n", &am_usbphy->phy);
 
diff --git a/drivers/usb/musb/phy-am335x.h b/drivers/usb/musb/phy-am335x.h
deleted file mode 100644
index 27da2e3b1057..000000000000
--- a/drivers/usb/musb/phy-am335x.h
+++ /dev/null
@@ -1,6 +0,0 @@
-#ifndef _PHY_AM335x_H_
-#define _PHY_AM335x_H_
-
-struct usb_phy *am335x_get_usb_phy(void);
-
-#endif