ralink: update patches
[openwrt.git] / target / linux / ramips / patches-3.9 / 0161-USB-add-OHCI-EHCI-OF-binding.patch
1 From 9a15efea2e55327cf7c813da64589509f9c40786 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 16 May 2013 23:11:45 +0200
4 Subject: [PATCH 161/164] USB: add OHCI/EHCI OF binding
5
6 based on f3bc64d6d1f21c1b92d75f233a37b75d77af6963
7
8 Signed-off-by: John Crispin <blogic@openwrt.org>
9 ---
10  arch/mips/ralink/Kconfig         |    2 ++
11  drivers/usb/Makefile             |    3 ++-
12  drivers/usb/host/ehci-platform.c |   44 ++++++++++++++++++++++++++++++++------
13  drivers/usb/host/ohci-platform.c |   37 +++++++++++++++++++++++++++-----
14  4 files changed, 74 insertions(+), 12 deletions(-)
15
16 diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
17 index c8d5b6c..7cd1188 100644
18 --- a/arch/mips/ralink/Kconfig
19 +++ b/arch/mips/ralink/Kconfig
20 @@ -27,6 +27,8 @@ choice
21                 bool "MT7620"
22                 select CLKEVT_RT3352
23                 select HW_HAS_PCI
24 +               select USB_ARCH_HAS_OHCI
25 +               select USB_ARCH_HAS_EHCI
26  
27  endchoice
28  
29 diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
30 index 8f5ebce..b766256 100644
31 --- a/drivers/usb/Makefile
32 +++ b/drivers/usb/Makefile
33 @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3)                += dwc3/
34  
35  obj-$(CONFIG_USB_MON)          += mon/
36  
37 +obj-$(CONFIG_USB_OTG_UTILS)    += phy/
38 +
39  obj-$(CONFIG_PCI)              += host/
40  obj-$(CONFIG_USB_EHCI_HCD)     += host/
41  obj-$(CONFIG_USB_ISP116X_HCD)  += host/
42 @@ -46,7 +48,6 @@ obj-$(CONFIG_USB_MICROTEK)    += image/
43  obj-$(CONFIG_USB_SERIAL)       += serial/
44  
45  obj-$(CONFIG_USB)              += misc/
46 -obj-$(CONFIG_USB_OTG_UTILS)    += phy/
47  obj-$(CONFIG_EARLY_PRINTK_DBGP)        += early/
48  
49  obj-$(CONFIG_USB_ATM)          += atm/
50 diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
51 index ca75063..ae32410 100644
52 --- a/drivers/usb/host/ehci-platform.c
53 +++ b/drivers/usb/host/ehci-platform.c
54 @@ -18,14 +18,18 @@
55   *
56   * Licensed under the GNU/GPL. See COPYING for details.
57   */
58 +#include <linux/dma-mapping.h>
59  #include <linux/err.h>
60  #include <linux/kernel.h>
61  #include <linux/hrtimer.h>
62  #include <linux/io.h>
63  #include <linux/module.h>
64 +#include <linux/of.h>
65  #include <linux/platform_device.h>
66  #include <linux/usb.h>
67  #include <linux/usb/hcd.h>
68 +#include <linux/usb/otg.h>
69 +#include <linux/usb/phy.h>
70  #include <linux/usb/ehci_pdriver.h>
71  
72  #include "ehci.h"
73 @@ -62,22 +66,32 @@ static const struct ehci_driver_overrides platform_overrides __initdata = {
74         .reset =        ehci_platform_reset,
75  };
76  
77 +static struct usb_ehci_pdata ehci_platform_defaults;
78 +
79  static int ehci_platform_probe(struct platform_device *dev)
80  {
81         struct usb_hcd *hcd;
82         struct resource *res_mem;
83 -       struct usb_ehci_pdata *pdata = dev->dev.platform_data;
84 +       struct usb_ehci_pdata *pdata;
85         int irq;
86         int err = -ENOMEM;
87  
88 -       if (!pdata) {
89 -               WARN_ON(1);
90 -               return -ENODEV;
91 -       }
92 -
93         if (usb_disabled())
94                 return -ENODEV;
95  
96 +       /*
97 +        * use reasonable defaults so platforms don't have to provide these.
98 +        * with DT probing on ARM, none of these are set.
99 +        */
100 +       if (!dev->dev.platform_data)
101 +               dev->dev.platform_data = &ehci_platform_defaults;
102 +       if (!dev->dev.dma_mask)
103 +               dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
104 +       if (!dev->dev.coherent_dma_mask)
105 +               dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
106 +
107 +       pdata = dev->dev.platform_data;
108 +
109         irq = platform_get_irq(dev, 0);
110         if (irq < 0) {
111                 dev_err(&dev->dev, "no irq provided");
112 @@ -105,6 +119,15 @@ static int ehci_platform_probe(struct platform_device *dev)
113         hcd->rsrc_start = res_mem->start;
114         hcd->rsrc_len = resource_size(res_mem);
115  
116 +#ifdef CONFIG_USB_OTG_UTILS
117 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
118 +       if (!IS_ERR_OR_NULL(hcd->phy)) {
119 +               otg_set_host(hcd->phy->otg,
120 +                               &hcd->self);
121 +               usb_phy_init(hcd->phy);
122 +       }
123 +#endif
124 +
125         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
126         if (IS_ERR(hcd->regs)) {
127                 err = PTR_ERR(hcd->regs);
128 @@ -139,6 +162,9 @@ static int ehci_platform_remove(struct platform_device *dev)
129         if (pdata->power_off)
130                 pdata->power_off(dev);
131  
132 +       if (pdata == &ehci_platform_defaults)
133 +               dev->dev.platform_data = NULL;
134 +
135         return 0;
136  }
137  
138 @@ -183,6 +209,11 @@ static int ehci_platform_resume(struct device *dev)
139  #define ehci_platform_resume   NULL
140  #endif /* CONFIG_PM */
141  
142 +static const struct of_device_id ralink_ehci_ids[] = {
143 +       { .compatible = "ralink,rt3xxx-ehci", },
144 +       {}
145 +};
146 +
147  static const struct platform_device_id ehci_platform_table[] = {
148         { "ehci-platform", 0 },
149         { }
150 @@ -203,6 +234,7 @@ static struct platform_driver ehci_platform_driver = {
151                 .owner  = THIS_MODULE,
152                 .name   = "ehci-platform",
153                 .pm     = &ehci_platform_pm_ops,
154 +               .of_match_table = of_match_ptr(ralink_ehci_ids),
155         }
156  };
157  
158 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
159 index c3e7287..dd9bac6 100644
160 --- a/drivers/usb/host/ohci-platform.c
161 +++ b/drivers/usb/host/ohci-platform.c
162 @@ -16,6 +16,10 @@
163  #include <linux/err.h>
164  #include <linux/platform_device.h>
165  #include <linux/usb/ohci_pdriver.h>
166 +#include <linux/dma-mapping.h>
167 +#include <linux/of.h>
168 +
169 +static struct usb_ohci_pdata ohci_platform_defaults;
170  
171  static int ohci_platform_reset(struct usb_hcd *hcd)
172  {
173 @@ -88,14 +92,22 @@ static int ohci_platform_probe(struct platform_device *dev)
174  {
175         struct usb_hcd *hcd;
176         struct resource *res_mem;
177 -       struct usb_ohci_pdata *pdata = dev->dev.platform_data;
178 +       struct usb_ohci_pdata *pdata;
179         int irq;
180         int err = -ENOMEM;
181  
182 -       if (!pdata) {
183 -               WARN_ON(1);
184 -               return -ENODEV;
185 -       }
186 +       /*
187 +        * use reasonable defaults so platforms don't have to provide these.
188 +        * with DT probing on ARM, none of these are set.
189 +        */
190 +       if (!dev->dev.platform_data)
191 +               dev->dev.platform_data = &ohci_platform_defaults;
192 +       if (!dev->dev.dma_mask)
193 +               dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
194 +       if (!dev->dev.coherent_dma_mask)
195 +               dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
196 +
197 +       pdata = dev->dev.platform_data;
198  
199         if (usb_disabled())
200                 return -ENODEV;
201 @@ -128,6 +140,12 @@ static int ohci_platform_probe(struct platform_device *dev)
202         hcd->rsrc_start = res_mem->start;
203         hcd->rsrc_len = resource_size(res_mem);
204  
205 +#ifdef CONFIG_USB_OTG_UTILS
206 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
207 +       if (!IS_ERR_OR_NULL(hcd->phy))
208 +               usb_phy_init(hcd->phy);
209 +#endif
210 +
211         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
212         if (IS_ERR(hcd->regs)) {
213                 err = PTR_ERR(hcd->regs);
214 @@ -162,6 +180,9 @@ static int ohci_platform_remove(struct platform_device *dev)
215         if (pdata->power_off)
216                 pdata->power_off(dev);
217  
218 +       if (pdata == &ohci_platform_defaults)
219 +               dev->dev.platform_data = NULL;
220 +
221         return 0;
222  }
223  
224 @@ -201,6 +222,11 @@ static int ohci_platform_resume(struct device *dev)
225  #define ohci_platform_resume   NULL
226  #endif /* CONFIG_PM */
227  
228 +static const struct of_device_id ralink_ohci_ids[] = {
229 +       { .compatible = "ralink,rt3xxx-ohci", },
230 +       {}
231 +};
232 +
233  static const struct platform_device_id ohci_platform_table[] = {
234         { "ohci-platform", 0 },
235         { }
236 @@ -221,5 +247,6 @@ static struct platform_driver ohci_platform_driver = {
237                 .owner  = THIS_MODULE,
238                 .name   = "ohci-platform",
239                 .pm     = &ohci_platform_pm_ops,
240 +               .of_match_table = of_match_ptr(ralink_ohci_ids),
241         }
242  };
243 -- 
244 1.7.10.4
245