f2971528733df963a3c0c6a09a998253adcc7b1a
[openwrt.git] / target / linux / ramips / patches-3.14 / 0038-USB-add-OHCI-EHCI-OF-binding.patch
1 From ffb27de4760595c356ef619c97f25722c8db28e7 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 27 Jul 2014 09:49:07 +0100
4 Subject: [PATCH 38/57] USB: add OHCI/EHCI OF binding
5
6 based on f3bc64d6d1f21c1b92d75f233a37b75d77af6963
7
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 ---
10  drivers/usb/Makefile             |    3 ++-
11  drivers/usb/host/ehci-platform.c |   21 +++++++++++++++++----
12  drivers/usb/host/ohci-platform.c |   37 +++++++++++++++++++++++++++++++------
13  3 files changed, 50 insertions(+), 11 deletions(-)
14
15 --- a/drivers/usb/Makefile
16 +++ b/drivers/usb/Makefile
17 @@ -11,6 +11,8 @@ obj-$(CONFIG_USB_DWC2)                += dwc2/
18  
19  obj-$(CONFIG_USB_MON)          += mon/
20  
21 +obj-$(CONFIG_USB_PHY)          += phy/
22 +
23  obj-$(CONFIG_PCI)              += host/
24  obj-$(CONFIG_USB_EHCI_HCD)     += host/
25  obj-$(CONFIG_USB_ISP116X_HCD)  += host/
26 @@ -41,7 +43,6 @@ obj-$(CONFIG_USB_TMC)         += class/
27  obj-$(CONFIG_USB_STORAGE)      += storage/
28  obj-$(CONFIG_USB)              += storage/
29  
30 -obj-$(CONFIG_USB_MDC800)       += image/
31  obj-$(CONFIG_USB_MICROTEK)     += image/
32  
33  obj-$(CONFIG_USB_SERIAL)       += serial/
34 --- a/drivers/usb/host/ehci-platform.c
35 +++ b/drivers/usb/host/ehci-platform.c
36 @@ -29,6 +29,8 @@
37  #include <linux/usb.h>
38  #include <linux/usb/hcd.h>
39  #include <linux/usb/ehci_pdriver.h>
40 +#include <linux/usb/phy.h>
41 +#include <linux/usb/otg.h>
42  
43  #include "ehci.h"
44  
45 @@ -124,6 +126,15 @@ static int ehci_platform_probe(struct pl
46         hcd->rsrc_start = res_mem->start;
47         hcd->rsrc_len = resource_size(res_mem);
48  
49 +#ifdef CONFIG_USB_PHY
50 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
51 +       if (!IS_ERR_OR_NULL(hcd->phy)) {
52 +               otg_set_host(hcd->phy->otg,
53 +                               &hcd->self);
54 +               usb_phy_init(hcd->phy);
55 +       }
56 +#endif
57 +
58         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
59         if (IS_ERR(hcd->regs)) {
60                 err = PTR_ERR(hcd->regs);
61 @@ -161,6 +172,9 @@ static int ehci_platform_remove(struct p
62         if (pdata == &ehci_platform_defaults)
63                 dev->dev.platform_data = NULL;
64  
65 +       if (pdata == &ehci_platform_defaults)
66 +               dev->dev.platform_data = NULL;
67 +
68         return 0;
69  }
70  
71 @@ -205,9 +219,8 @@ static int ehci_platform_resume(struct d
72  #define ehci_platform_resume   NULL
73  #endif /* CONFIG_PM */
74  
75 -static const struct of_device_id vt8500_ehci_ids[] = {
76 -       { .compatible = "via,vt8500-ehci", },
77 -       { .compatible = "wm,prizm-ehci", },
78 +static const struct of_device_id ralink_ehci_ids[] = {
79 +       { .compatible = "ralink,rt3xxx-ehci", },
80         {}
81  };
82  
83 @@ -231,7 +244,7 @@ static struct platform_driver ehci_platf
84                 .owner  = THIS_MODULE,
85                 .name   = "ehci-platform",
86                 .pm     = &ehci_platform_pm_ops,
87 -               .of_match_table = vt8500_ehci_ids,
88 +               .of_match_table = ralink_ehci_ids,
89         }
90  };
91  
92 --- a/drivers/usb/host/ohci-platform.c
93 +++ b/drivers/usb/host/ohci-platform.c
94 @@ -22,18 +22,22 @@
95  #include <linux/platform_device.h>
96  #include <linux/usb/ohci_pdriver.h>
97  #include <linux/usb.h>
98 +#include <linux/usb/phy.h>
99  #include <linux/usb/hcd.h>
100 +#include <linux/dma-mapping.h>
101 +#include <linux/of.h>
102  
103  #include "ohci.h"
104  
105  #define DRIVER_DESC "OHCI generic platform driver"
106  
107 +static struct usb_ohci_pdata ohci_platform_defaults;
108  static const char hcd_name[] = "ohci-platform";
109  
110  static int ohci_platform_reset(struct usb_hcd *hcd)
111  {
112         struct platform_device *pdev = to_platform_device(hcd->self.controller);
113 -       struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);
114 +       struct usb_ohci_pdata *pdata = dev_get_platdata(&pdev->dev);;
115         struct ohci_hcd *ohci = hcd_to_ohci(hcd);
116  
117         if (pdata->big_endian_desc)
118 @@ -63,11 +67,18 @@ static int ohci_platform_probe(struct pl
119         int irq;
120         int err = -ENOMEM;
121  
122 -       if (!pdata) {
123 -               WARN_ON(1);
124 -               return -ENODEV;
125 -       }
126 +       /*
127 +        * use reasonable defaults so platforms don't have to provide these.
128 +        * with DT probing on ARM, none of these are set.
129 +        */
130 +       if (!dev->dev.platform_data)
131 +               dev->dev.platform_data = &ohci_platform_defaults;
132 +       if (!dev->dev.dma_mask)
133 +               dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
134 +       if (!dev->dev.coherent_dma_mask)
135 +               dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
136  
137 +       pdata = dev->dev.platform_data;
138         if (usb_disabled())
139                 return -ENODEV;
140  
141 @@ -99,6 +110,12 @@ static int ohci_platform_probe(struct pl
142         hcd->rsrc_start = res_mem->start;
143         hcd->rsrc_len = resource_size(res_mem);
144  
145 +#ifdef CONFIG_USB_PHY
146 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
147 +       if (!IS_ERR_OR_NULL(hcd->phy))
148 +               usb_phy_init(hcd->phy);
149 +#endif
150 +
151         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
152         if (IS_ERR(hcd->regs)) {
153                 err = PTR_ERR(hcd->regs);
154 @@ -134,6 +151,9 @@ static int ohci_platform_remove(struct p
155         if (pdata->power_off)
156                 pdata->power_off(dev);
157  
158 +       if (pdata == &ohci_platform_defaults)
159 +               dev->dev.platform_data = NULL;
160 +
161         return 0;
162  }
163  
164 @@ -180,6 +200,11 @@ static int ohci_platform_resume(struct d
165  #define ohci_platform_resume   NULL
166  #endif /* CONFIG_PM */
167  
168 +static const struct of_device_id ralink_ohci_ids[] = {
169 +       { .compatible = "ralink,rt3xxx-ohci", },
170 +       {}
171 +};
172 +
173  static const struct platform_device_id ohci_platform_table[] = {
174         { "ohci-platform", 0 },
175         { }
176 @@ -200,6 +225,7 @@ static struct platform_driver ohci_platf
177                 .owner  = THIS_MODULE,
178                 .name   = "ohci-platform",
179                 .pm     = &ohci_platform_pm_ops,
180 +               .of_match_table = of_match_ptr(ralink_ohci_ids),
181         }
182  };
183