Skip to content

Commit 313bdb1

Browse files
Lee Joneslinusw
authored andcommitted
usb: musb: ux500: add device tree probing support
This patch will allow ux500-musb to be probed and configured solely from configuration found in Device Tree. Cc: Rob Herring <[email protected]> Cc: [email protected] Cc: [email protected] Acked-by: Felipe Balbi <[email protected]> Acked-by: Fabio Baltieri <[email protected]> Signed-off-by: Lee Jones <[email protected]> Signed-off-by: Linus Walleij <[email protected]>
1 parent 2968da0 commit 313bdb1

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
Ux500 MUSB
2+
3+
Required properties:
4+
- compatible : Should be "stericsson,db8500-musb"
5+
- reg : Offset and length of registers
6+
- interrupts : Interrupt; mode, number and trigger
7+
- dr_mode : Dual-role; either host mode "host", peripheral mode "peripheral"
8+
or both "otg"
9+
10+
Optional properties:
11+
- dmas : A list of dma channels;
12+
dma-controller, event-line, fixed-channel, flags
13+
- dma-names : An ordered list of channel names affiliated to the above
14+
15+
Example:
16+
17+
usb_per5@a03e0000 {
18+
compatible = "stericsson,db8500-musb", "mentor,musb";
19+
reg = <0xa03e0000 0x10000>;
20+
interrupts = <0 23 0x4>;
21+
interrupt-names = "mc";
22+
23+
dr_mode = "otg";
24+
25+
dmas = <&dma 38 0 0x2>, /* Logical - DevToMem */
26+
<&dma 38 0 0x0>, /* Logical - MemToDev */
27+
<&dma 37 0 0x2>, /* Logical - DevToMem */
28+
<&dma 37 0 0x0>, /* Logical - MemToDev */
29+
<&dma 36 0 0x2>, /* Logical - DevToMem */
30+
<&dma 36 0 0x0>, /* Logical - MemToDev */
31+
<&dma 19 0 0x2>, /* Logical - DevToMem */
32+
<&dma 19 0 0x0>, /* Logical - MemToDev */
33+
<&dma 18 0 0x2>, /* Logical - DevToMem */
34+
<&dma 18 0 0x0>, /* Logical - MemToDev */
35+
<&dma 17 0 0x2>, /* Logical - DevToMem */
36+
<&dma 17 0 0x0>, /* Logical - MemToDev */
37+
<&dma 16 0 0x2>, /* Logical - DevToMem */
38+
<&dma 16 0 0x0>, /* Logical - MemToDev */
39+
<&dma 39 0 0x2>, /* Logical - DevToMem */
40+
<&dma 39 0 0x0>; /* Logical - MemToDev */
41+
42+
dma-names = "iep_1_9", "oep_1_9",
43+
"iep_2_10", "oep_2_10",
44+
"iep_3_11", "oep_3_11",
45+
"iep_4_12", "oep_4_12",
46+
"iep_5_13", "oep_5_13",
47+
"iep_6_14", "oep_6_14",
48+
"iep_7_15", "oep_7_15",
49+
"iep_8", "oep_8";
50+
};

drivers/usb/musb/ux500.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include <linux/clk.h>
2626
#include <linux/err.h>
2727
#include <linux/io.h>
28+
#include <linux/of.h>
2829
#include <linux/platform_device.h>
2930
#include <linux/usb/musb-ux500.h>
3031

@@ -194,14 +195,57 @@ static const struct musb_platform_ops ux500_ops = {
194195
.set_vbus = ux500_musb_set_vbus,
195196
};
196197

198+
static struct musb_hdrc_platform_data *
199+
ux500_of_probe(struct platform_device *pdev, struct device_node *np)
200+
{
201+
struct musb_hdrc_platform_data *pdata;
202+
const char *mode;
203+
int strlen;
204+
205+
pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
206+
if (!pdata)
207+
return NULL;
208+
209+
mode = of_get_property(np, "dr_mode", &strlen);
210+
if (!mode) {
211+
dev_err(&pdev->dev, "No 'dr_mode' property found\n");
212+
return NULL;
213+
}
214+
215+
if (strlen > 0) {
216+
if (!strcmp(mode, "host"))
217+
pdata->mode = MUSB_HOST;
218+
if (!strcmp(mode, "otg"))
219+
pdata->mode = MUSB_OTG;
220+
if (!strcmp(mode, "peripheral"))
221+
pdata->mode = MUSB_PERIPHERAL;
222+
}
223+
224+
return pdata;
225+
}
226+
197227
static int ux500_probe(struct platform_device *pdev)
198228
{
199229
struct musb_hdrc_platform_data *pdata = pdev->dev.platform_data;
230+
struct device_node *np = pdev->dev.of_node;
200231
struct platform_device *musb;
201232
struct ux500_glue *glue;
202233
struct clk *clk;
203234
int ret = -ENOMEM;
204235

236+
if (!pdata) {
237+
if (np) {
238+
pdata = ux500_of_probe(pdev, np);
239+
if (!pdata)
240+
goto err0;
241+
242+
pdev->dev.platform_data = pdata;
243+
} else {
244+
dev_err(&pdev->dev, "no pdata or device tree found\n");
245+
goto err0;
246+
}
247+
}
248+
205249
glue = kzalloc(sizeof(*glue), GFP_KERNEL);
206250
if (!glue) {
207251
dev_err(&pdev->dev, "failed to allocate glue context\n");
@@ -230,6 +274,7 @@ static int ux500_probe(struct platform_device *pdev)
230274
musb->dev.parent = &pdev->dev;
231275
musb->dev.dma_mask = &pdev->dev.coherent_dma_mask;
232276
musb->dev.coherent_dma_mask = pdev->dev.coherent_dma_mask;
277+
musb->dev.of_node = pdev->dev.of_node;
233278

234279
glue->dev = &pdev->dev;
235280
glue->musb = musb;
@@ -328,12 +373,18 @@ static const struct dev_pm_ops ux500_pm_ops = {
328373
#define DEV_PM_OPS NULL
329374
#endif
330375

376+
static const struct of_device_id ux500_match[] = {
377+
{ .compatible = "stericsson,db8500-musb", },
378+
{}
379+
};
380+
331381
static struct platform_driver ux500_driver = {
332382
.probe = ux500_probe,
333383
.remove = ux500_remove,
334384
.driver = {
335385
.name = "musb-ux500",
336386
.pm = DEV_PM_OPS,
387+
.of_match_table = ux500_match,
337388
},
338389
};
339390

0 commit comments

Comments
 (0)