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
6 based on f3bc64d6d1f21c1b92d75f233a37b75d77af6963
8 Signed-off-by: John Crispin <blogic@openwrt.org>
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(-)
16 --- a/arch/mips/ralink/Kconfig
17 +++ b/arch/mips/ralink/Kconfig
18 @@ -27,6 +27,8 @@ choice
22 + select USB_ARCH_HAS_OHCI
23 + select USB_ARCH_HAS_EHCI
27 --- a/drivers/usb/Makefile
28 +++ b/drivers/usb/Makefile
29 @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/
31 obj-$(CONFIG_USB_MON) += mon/
33 +obj-$(CONFIG_USB_OTG_UTILS) += phy/
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/
41 obj-$(CONFIG_USB) += misc/
42 -obj-$(CONFIG_USB_OTG_UTILS) += phy/
43 obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
45 obj-$(CONFIG_USB_ATM) += atm/
46 --- a/drivers/usb/host/ehci-platform.c
47 +++ b/drivers/usb/host/ehci-platform.c
50 * Licensed under the GNU/GPL. See COPYING for details.
52 +#include <linux/dma-mapping.h>
53 #include <linux/err.h>
54 #include <linux/kernel.h>
55 #include <linux/hrtimer.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>
67 @@ -63,22 +67,32 @@ static const struct ehci_driver_override
68 .reset = ehci_platform_reset,
71 +static struct usb_ehci_pdata ehci_platform_defaults;
73 static int ehci_platform_probe(struct platform_device *dev)
76 struct resource *res_mem;
77 - struct usb_ehci_pdata *pdata = dev->dev.platform_data;
78 + struct usb_ehci_pdata *pdata;
91 + * use reasonable defaults so platforms don't have to provide these.
92 + * with DT probing on ARM, none of these are set.
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);
101 + pdata = dev->dev.platform_data;
103 irq = platform_get_irq(dev, 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);
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,
115 + usb_phy_init(hcd->phy);
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);
126 + if (pdata == &ehci_platform_defaults)
127 + dev->dev.platform_data = NULL;
132 @@ -184,6 +210,11 @@ static int ehci_platform_resume(struct d
133 #define ehci_platform_resume NULL
134 #endif /* CONFIG_PM */
136 +static const struct of_device_id ralink_ehci_ids[] = {
137 + { .compatible = "ralink,rt3xxx-ehci", },
141 static const struct platform_device_id ehci_platform_table[] = {
142 { "ehci-platform", 0 },
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),
152 --- a/drivers/usb/host/ohci-platform.c
153 +++ b/drivers/usb/host/ohci-platform.c
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>
161 +static struct usb_ohci_pdata ohci_platform_defaults;
163 static int ohci_platform_reset(struct usb_hcd *hcd)
165 @@ -88,14 +92,22 @@ static int ohci_platform_probe(struct pl
168 struct resource *res_mem;
169 - struct usb_ohci_pdata *pdata = dev->dev.platform_data;
170 + struct usb_ohci_pdata *pdata;
179 + * use reasonable defaults so platforms don't have to provide these.
180 + * with DT probing on ARM, none of these are set.
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);
189 + pdata = dev->dev.platform_data;
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);
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);
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);
210 + if (pdata == &ohci_platform_defaults)
211 + dev->dev.platform_data = NULL;
216 @@ -201,6 +222,11 @@ static int ohci_platform_resume(struct d
217 #define ohci_platform_resume NULL
218 #endif /* CONFIG_PM */
220 +static const struct of_device_id ralink_ohci_ids[] = {
221 + { .compatible = "ralink,rt3xxx-ohci", },
225 static const struct platform_device_id ohci_platform_table[] = {
226 { "ohci-platform", 0 },
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),