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