1 From ec6f3aa022ef6e61f6ca80c6e30610d879654466 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Thu, 20 Jun 2013 23:33:05 +0200
4 Subject: [PATCH] MIPS: add ohci/ehci support
6 Signed-off-by: John Crsipin <blogic@openwrt.org>
8 arch/mips/ralink/Kconfig | 2 ++
9 drivers/usb/Makefile | 3 ++-
10 drivers/usb/host/ehci-platform.c | 43 ++++++++++++++++++++++++++++++++------
11 drivers/usb/host/ohci-platform.c | 37 +++++++++++++++++++++++++++-----
12 4 files changed, 73 insertions(+), 12 deletions(-)
14 diff --git a/arch/mips/ralink/Kconfig b/arch/mips/ralink/Kconfig
15 index c8d5b6c..7cd1188 100644
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 diff --git a/drivers/usb/Makefile b/drivers/usb/Makefile
28 index f5ed3d7..41a4741 100644
29 --- a/drivers/usb/Makefile
30 +++ b/drivers/usb/Makefile
31 @@ -12,6 +12,8 @@ obj-$(CONFIG_USB_DWC3) += dwc3/
33 obj-$(CONFIG_USB_MON) += mon/
35 +obj-$(CONFIG_USB_COMMON) += phy/
37 obj-$(CONFIG_PCI) += host/
38 obj-$(CONFIG_USB_EHCI_HCD) += host/
39 obj-$(CONFIG_USB_ISP116X_HCD) += host/
40 @@ -46,7 +48,6 @@ obj-$(CONFIG_USB_MICROTEK) += image/
41 obj-$(CONFIG_USB_SERIAL) += serial/
43 obj-$(CONFIG_USB) += misc/
44 -obj-$(CONFIG_USB_COMMON) += phy/
45 obj-$(CONFIG_EARLY_PRINTK_DBGP) += early/
47 obj-$(CONFIG_USB_ATM) += atm/
48 diff --git a/drivers/usb/host/ehci-platform.c b/drivers/usb/host/ehci-platform.c
49 index 58fa0c9..0050df7 100644
50 --- a/drivers/usb/host/ehci-platform.c
51 +++ b/drivers/usb/host/ehci-platform.c
54 #include <linux/module.h>
55 #include <linux/platform_device.h>
56 +#include <linux/dma-mapping.h>
57 +#include <linux/of.h>
58 +#include <linux/usb/otg.h>
59 +#include <linux/usb/phy.h>
60 #include <linux/usb.h>
61 #include <linux/usb/hcd.h>
62 #include <linux/usb/ehci_pdriver.h>
63 @@ -61,22 +65,40 @@ static const struct ehci_driver_overrides platform_overrides __initdata = {
64 .reset = ehci_platform_reset,
67 +static struct usb_ehci_pdata ehci_platform_defaults;
69 static int ehci_platform_probe(struct platform_device *dev)
72 struct resource *res_mem;
73 - struct usb_ehci_pdata *pdata = dev->dev.platform_data;
74 + struct usb_ehci_pdata *pdata;
87 + * use reasonable defaults so platforms don't have to provide these.
88 + * with DT probing on ARM, none of these are set.
90 + if (!dev->dev.platform_data)
91 + dev->dev.platform_data = &ehci_platform_defaults;
92 + if (!dev->dev.dma_mask)
93 + dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
94 + if (!dev->dev.coherent_dma_mask)
95 + dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
97 + pdata = dev->dev.platform_data;
99 +#ifdef CONFIG_USB_COMMON
100 + hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
101 + if (!IS_ERR_OR_NULL(hcd->phy)) {
102 + otg_set_host(hcd->phy->otg,
104 + usb_phy_init(hcd->phy);
107 irq = platform_get_irq(dev, 0);
109 dev_err(&dev->dev, "no irq provided");
110 @@ -138,6 +160,9 @@ static int ehci_platform_remove(struct platform_device *dev)
111 if (pdata->power_off)
112 pdata->power_off(dev);
114 + if (pdata == &ehci_platform_defaults)
115 + dev->dev.platform_data = NULL;
120 @@ -182,6 +207,11 @@ static int ehci_platform_resume(struct device *dev)
121 #define ehci_platform_resume NULL
122 #endif /* CONFIG_PM */
124 +static const struct of_device_id ralink_ehci_ids[] = {
125 + { .compatible = "ralink,rt3xxx-ehci", },
129 static const struct platform_device_id ehci_platform_table[] = {
130 { "ehci-platform", 0 },
132 @@ -202,6 +232,7 @@ static struct platform_driver ehci_platform_driver = {
133 .owner = THIS_MODULE,
134 .name = "ehci-platform",
135 .pm = &ehci_platform_pm_ops,
136 + .of_match_table = of_match_ptr(ralink_ehci_ids),
140 diff --git a/drivers/usb/host/ohci-platform.c b/drivers/usb/host/ohci-platform.c
141 index 084503b..3a60f96 100644
142 --- a/drivers/usb/host/ohci-platform.c
143 +++ b/drivers/usb/host/ohci-platform.c
146 #include <linux/platform_device.h>
147 #include <linux/usb/ohci_pdriver.h>
148 +#include <linux/dma-mapping.h>
149 +#include <linux/of.h>
151 +static struct usb_ohci_pdata ohci_platform_defaults;
153 static int ohci_platform_reset(struct usb_hcd *hcd)
155 @@ -87,14 +91,22 @@ static int ohci_platform_probe(struct platform_device *dev)
158 struct resource *res_mem;
159 - struct usb_ohci_pdata *pdata = dev->dev.platform_data;
160 + struct usb_ohci_pdata *pdata;
169 + * use reasonable defaults so platforms don't have to provide these.
170 + * with DT probing on ARM, none of these are set.
172 + if (!dev->dev.platform_data)
173 + dev->dev.platform_data = &ohci_platform_defaults;
174 + if (!dev->dev.dma_mask)
175 + dev->dev.dma_mask = &dev->dev.coherent_dma_mask;
176 + if (!dev->dev.coherent_dma_mask)
177 + dev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
179 + pdata = dev->dev.platform_data;
183 @@ -124,6 +136,12 @@ static int ohci_platform_probe(struct platform_device *dev)
187 +#ifdef CONFIG_USB_COMMON
188 + hcd->phy = devm_usb_get_phy(&dev->dev, USB_PHY_TYPE_USB2);
189 + if (!IS_ERR_OR_NULL(hcd->phy))
190 + usb_phy_init(hcd->phy);
193 hcd->rsrc_start = res_mem->start;
194 hcd->rsrc_len = resource_size(res_mem);
196 @@ -161,6 +179,9 @@ static int ohci_platform_remove(struct platform_device *dev)
197 if (pdata->power_off)
198 pdata->power_off(dev);
200 + if (pdata == &ohci_platform_defaults)
201 + dev->dev.platform_data = NULL;
206 @@ -200,6 +221,11 @@ static int ohci_platform_resume(struct device *dev)
207 #define ohci_platform_resume NULL
208 #endif /* CONFIG_PM */
210 +static const struct of_device_id ralink_ohci_ids[] = {
211 + { .compatible = "ralink,rt3xxx-ohci", },
215 static const struct platform_device_id ohci_platform_table[] = {
216 { "ohci-platform", 0 },
218 @@ -220,5 +246,6 @@ static struct platform_driver ohci_platform_driver = {
219 .owner = THIS_MODULE,
220 .name = "ohci-platform",
221 .pm = &ohci_platform_pm_ops,
222 + .of_match_table = of_match_ptr(ralink_ohci_ids),