e442f2f2a2f0900be0ca318c7ad4a2503bb6678f
[openwrt.git] / target / linux / ramips / patches-3.10 / 0019-USB-add-OHCI-EHCI-OF-binding.patch
1 From 40b9d3026ed0b3bcd59f90391195df5b2adabad2 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Sun, 14 Jul 2013 23:34:53 +0200
4 Subject: [PATCH 19/33] 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 |   19 +++++++++++++++----
13  drivers/usb/host/ohci-platform.c |   37 ++++++++++++++++++++++++++++++++-----
14  4 files changed, 51 insertions(+), 10 deletions(-)
15
16 Index: linux-3.10.1/arch/mips/ralink/Kconfig
17 ===================================================================
18 --- linux-3.10.1.orig/arch/mips/ralink/Kconfig  2013-07-15 17:35:28.021178556 +0200
19 +++ linux-3.10.1/arch/mips/ralink/Kconfig       2013-07-15 20:00:19.501385660 +0200
20 @@ -24,6 +24,8 @@
21  
22         config SOC_MT7620
23                 bool "MT7620"
24 +               select USB_ARCH_HAS_OHCI
25 +               select USB_ARCH_HAS_EHCI
26                 select HW_HAS_PCI
27  
28  endchoice
29 Index: linux-3.10.1/drivers/usb/Makefile
30 ===================================================================
31 --- linux-3.10.1.orig/drivers/usb/Makefile      2013-07-13 20:42:41.000000000 +0200
32 +++ linux-3.10.1/drivers/usb/Makefile   2013-07-15 19:47:26.725367249 +0200
33 @@ -10,6 +10,8 @@
34  
35  obj-$(CONFIG_USB_MON)          += mon/
36  
37 +obj-$(CONFIG_USB_PHY)          += phy/
38 +
39  obj-$(CONFIG_PCI)              += host/
40  obj-$(CONFIG_USB_EHCI_HCD)     += host/
41  obj-$(CONFIG_USB_ISP116X_HCD)  += host/
42 @@ -44,7 +46,6 @@
43  obj-$(CONFIG_USB_SERIAL)       += serial/
44  
45  obj-$(CONFIG_USB)              += misc/
46 -obj-$(CONFIG_USB_PHY)          += phy/
47  obj-$(CONFIG_EARLY_PRINTK_DBGP)        += early/
48  
49  obj-$(CONFIG_USB_ATM)          += atm/
50 Index: linux-3.10.1/drivers/usb/host/ehci-platform.c
51 ===================================================================
52 --- linux-3.10.1.orig/drivers/usb/host/ehci-platform.c  2013-07-15 17:35:22.761178428 +0200
53 +++ linux-3.10.1/drivers/usb/host/ehci-platform.c       2013-07-15 19:47:14.525366961 +0200
54 @@ -29,6 +29,8 @@
55  #include <linux/usb.h>
56  #include <linux/usb/hcd.h>
57  #include <linux/usb/ehci_pdriver.h>
58 +#include <linux/usb/phy.h>
59 +#include <linux/usb/otg.h>
60  
61  #include "ehci.h"
62  
63 @@ -118,6 +120,15 @@
64         hcd->rsrc_start = res_mem->start;
65         hcd->rsrc_len = resource_size(res_mem);
66  
67 +#ifdef CONFIG_USB_PHY
68 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
69 +       if (!IS_ERR_OR_NULL(hcd->phy)) {
70 +               otg_set_host(hcd->phy->otg,
71 +                               &hcd->self);
72 +               usb_phy_init(hcd->phy);
73 +       }
74 +#endif
75 +
76         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
77         if (IS_ERR(hcd->regs)) {
78                 err = PTR_ERR(hcd->regs);
79 @@ -155,6 +166,9 @@
80         if (pdata == &ehci_platform_defaults)
81                 dev->dev.platform_data = NULL;
82  
83 +       if (pdata == &ehci_platform_defaults)
84 +               dev->dev.platform_data = NULL;
85 +
86         return 0;
87  }
88  
89 @@ -199,9 +213,8 @@
90  #define ehci_platform_resume   NULL
91  #endif /* CONFIG_PM */
92  
93 -static const struct of_device_id vt8500_ehci_ids[] = {
94 -       { .compatible = "via,vt8500-ehci", },
95 -       { .compatible = "wm,prizm-ehci", },
96 +static const struct of_device_id ralink_ehci_ids[] = {
97 +       { .compatible = "ralink,rt3xxx-ehci", },
98         {}
99  };
100  
101 @@ -225,7 +238,7 @@
102                 .owner  = THIS_MODULE,
103                 .name   = "ehci-platform",
104                 .pm     = &ehci_platform_pm_ops,
105 -               .of_match_table = of_match_ptr(vt8500_ehci_ids),
106 +               .of_match_table = of_match_ptr(ralink_ehci_ids),
107         }
108  };
109  
110 Index: linux-3.10.1/drivers/usb/host/ohci-platform.c
111 ===================================================================
112 --- linux-3.10.1.orig/drivers/usb/host/ohci-platform.c  2013-07-13 20:42:41.000000000 +0200
113 +++ linux-3.10.1/drivers/usb/host/ohci-platform.c       2013-07-15 19:55:15.913378428 +0200
114 @@ -16,6 +16,10 @@
115  #include <linux/err.h>
116  #include <linux/platform_device.h>
117  #include <linux/usb/ohci_pdriver.h>
118 +#include <linux/dma-mapping.h>
119 +#include <linux/of.h>
120 +
121 +static struct usb_ohci_pdata ohci_platform_defaults;
122  
123  static int ohci_platform_reset(struct usb_hcd *hcd)
124  {
125 @@ -88,14 +92,22 @@
126  {
127         struct usb_hcd *hcd;
128         struct resource *res_mem;
129 -       struct usb_ohci_pdata *pdata = dev->dev.platform_data;
130 +       struct usb_ohci_pdata *pdata;
131         int irq;
132         int err = -ENOMEM;
133  
134 -       if (!pdata) {
135 -               WARN_ON(1);
136 -               return -ENODEV;
137 -       }
138 +       /*
139 +        * use reasonable defaults so platforms don't have to provide these.
140 +        * with DT probing on ARM, none of these are set.
141 +        */
142 +       if (!dev->dev.platform_data)
143 +               dev->dev.platform_data = &ohci_platform_defaults;
144 +       if (!dev->dev.dma_mask)
145 +               dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
146 +       if (!dev->dev.coherent_dma_mask)
147 +               dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
148 +
149 +       pdata = dev->dev.platform_data;
150  
151         if (usb_disabled())
152                 return -ENODEV;
153 @@ -128,6 +140,12 @@
154         hcd->rsrc_start = res_mem->start;
155         hcd->rsrc_len = resource_size(res_mem);
156  
157 +#ifdef CONFIG_USB_PHY
158 +       hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
159 +       if (!IS_ERR_OR_NULL(hcd->phy))
160 +               usb_phy_init(hcd->phy);
161 +#endif
162 +
163         hcd->regs = devm_ioremap_resource(&dev->dev, res_mem);
164         if (IS_ERR(hcd->regs)) {
165                 err = PTR_ERR(hcd->regs);
166 @@ -162,6 +180,9 @@
167         if (pdata->power_off)
168                 pdata->power_off(dev);
169  
170 +       if (pdata == &ohci_platform_defaults)
171 +               dev->dev.platform_data = NULL;
172 +
173         return 0;
174  }
175  
176 @@ -201,6 +222,11 @@
177  #define ohci_platform_resume   NULL
178  #endif /* CONFIG_PM */
179  
180 +static const struct of_device_id ralink_ohci_ids[] = {
181 +       { .compatible = "ralink,rt3xxx-ohci", },
182 +       {}
183 +};
184 +
185  static const struct platform_device_id ohci_platform_table[] = {
186         { "ohci-platform", 0 },
187         { }
188 @@ -221,5 +247,6 @@
189                 .owner  = THIS_MODULE,
190                 .name   = "ohci-platform",
191                 .pm     = &ohci_platform_pm_ops,
192 +               .of_match_table = of_match_ptr(ralink_ohci_ids),
193         }
194  };