1 From d7e679017ec92824145b275572f6ef83d461f076 Mon Sep 17 00:00:00 2001
2 From: John Crispin <blogic@openwrt.org>
3 Date: Tue, 19 Mar 2013 09:26:22 +0100
4 Subject: [PATCH 204/208] owrt: MIPS: ralink: add usb platform support
6 Add code to load the platform ehci/ohci driver on Ralink SoC. For the usb core
7 to work we need to populate the platform_data during boot, prior to the usb
10 Signed-off-by: John Crispin <blogic@openwrt.org>
12 arch/mips/ralink/Makefile | 4 +-
13 arch/mips/ralink/common.h | 1 +
14 arch/mips/ralink/mt7620.c | 5 ++
15 arch/mips/ralink/of.c | 1 +
16 arch/mips/ralink/rt305x-usb.c | 120 +++++++++++++++++++++++++++++++++++++++++
17 arch/mips/ralink/rt3883-usb.c | 118 ++++++++++++++++++++++++++++++++++++++++
18 6 files changed, 247 insertions(+), 2 deletions(-)
19 create mode 100644 arch/mips/ralink/rt305x-usb.c
20 create mode 100644 arch/mips/ralink/rt3883-usb.c
22 diff --git a/arch/mips/ralink/Makefile b/arch/mips/ralink/Makefile
23 index cae7d88..8572538 100644
24 --- a/arch/mips/ralink/Makefile
25 +++ b/arch/mips/ralink/Makefile
27 obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
29 obj-$(CONFIG_SOC_RT288X) += rt288x.o
30 -obj-$(CONFIG_SOC_RT305X) += rt305x.o
31 -obj-$(CONFIG_SOC_RT3883) += rt3883.o
32 +obj-$(CONFIG_SOC_RT305X) += rt305x.o rt305x-usb.o
33 +obj-$(CONFIG_SOC_RT3883) += rt3883.o rt3883-usb.o
34 obj-$(CONFIG_SOC_MT7620) += mt7620.o
36 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
37 diff --git a/arch/mips/ralink/common.h b/arch/mips/ralink/common.h
38 index ed99f23..14a101c 100644
39 --- a/arch/mips/ralink/common.h
40 +++ b/arch/mips/ralink/common.h
41 @@ -43,5 +43,6 @@ extern void prom_soc_init(struct ralink_soc_info *soc_info);
42 __iomem void *plat_of_remap_node(const char *node);
44 void ralink_pinmux(void);
45 +void ralink_usb_platform(void);
47 #endif /* _RALINK_COMMON_H__ */
48 diff --git a/arch/mips/ralink/mt7620.c b/arch/mips/ralink/mt7620.c
49 index 9d0dc8b..19b28c5 100644
50 --- a/arch/mips/ralink/mt7620.c
51 +++ b/arch/mips/ralink/mt7620.c
52 @@ -146,6 +146,11 @@ struct ralink_pinmux rt_pinmux = {
53 // .wdt_reset = rt305x_wdt_reset,
56 +void ralink_usb_platform(void)
61 void __init ralink_clk_init(void)
63 unsigned long cpu_rate, sys_rate;
64 diff --git a/arch/mips/ralink/of.c b/arch/mips/ralink/of.c
65 index ecf1482..f438145 100644
66 --- a/arch/mips/ralink/of.c
67 +++ b/arch/mips/ralink/of.c
68 @@ -102,6 +102,7 @@ static int __init plat_of_setup(void)
69 panic("failed to populate DT\n");
72 + ralink_usb_platform();
76 diff --git a/arch/mips/ralink/rt305x-usb.c b/arch/mips/ralink/rt305x-usb.c
78 index 0000000..793fc82
80 +++ b/arch/mips/ralink/rt305x-usb.c
83 + * This program is free software; you can redistribute it and/or modify it
84 + * under the terms of the GNU General Public License version 2 as published
85 + * by the Free Software Foundation.
87 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
88 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
91 +#include <linux/kernel.h>
92 +#include <linux/init.h>
93 +#include <linux/module.h>
95 +#include <linux/delay.h>
96 +#include <linux/of_platform.h>
97 +#include <linux/dma-mapping.h>
98 +#include <linux/usb/ehci_pdriver.h>
99 +#include <linux/usb/ohci_pdriver.h>
101 +#include <asm/mach-ralink/ralink_regs.h>
102 +#include <asm/mach-ralink/rt305x.h>
104 +static atomic_t rt3352_usb_pwr_ref = ATOMIC_INIT(0);
106 +static int rt3352_usb_power_on(struct platform_device *pdev)
109 + if (atomic_inc_return(&rt3352_usb_pwr_ref) == 1) {
112 + t = rt_sysc_r32(RT3352_SYSC_REG_USB_PS);
114 + /* enable clock for port0's and port1's phys */
115 + t = rt_sysc_r32(RT3352_SYSC_REG_CLKCFG1);
116 + t |= RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN;
117 + rt_sysc_w32(t, RT3352_SYSC_REG_CLKCFG1);
120 + /* pull USBHOST and USBDEV out from reset */
121 + t = rt_sysc_r32(RT3352_SYSC_REG_RSTCTRL);
122 + t &= ~(RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV);
123 + rt_sysc_w32(t, RT3352_SYSC_REG_RSTCTRL);
126 + /* enable host mode */
127 + t = rt_sysc_r32(RT3352_SYSC_REG_SYSCFG1);
128 + t |= RT3352_SYSCFG1_USB0_HOST_MODE;
129 + rt_sysc_w32(t, RT3352_SYSC_REG_SYSCFG1);
131 + t = rt_sysc_r32(RT3352_SYSC_REG_USB_PS);
137 +static void rt3352_usb_power_off(struct platform_device *pdev)
139 + if (atomic_dec_return(&rt3352_usb_pwr_ref) == 0) {
142 + /* put USBHOST and USBDEV into reset */
143 + t = rt_sysc_r32(RT3352_SYSC_REG_RSTCTRL);
144 + t |= RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV;
145 + rt_sysc_w32(t, RT3352_SYSC_REG_RSTCTRL);
148 + /* disable clock for port0's and port1's phys*/
149 + t = rt_sysc_r32(RT3352_SYSC_REG_CLKCFG1);
150 + t &= ~(RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN);
151 + rt_sysc_w32(t, RT3352_SYSC_REG_CLKCFG1);
156 +static struct usb_ehci_pdata rt3352_ehci_data = {
157 + .power_on = rt3352_usb_power_on,
158 + .power_off = rt3352_usb_power_off,
161 +static struct usb_ohci_pdata rt3352_ohci_data = {
162 + .power_on = rt3352_usb_power_on,
163 + .power_off = rt3352_usb_power_off,
166 +static void ralink_add_usb(char *name, void *pdata, u64 *mask)
168 + struct device_node *node;
169 + struct platform_device *pdev;
171 + node = of_find_compatible_node(NULL, NULL, name);
175 + pdev = of_find_device_by_node(node);
180 + pdev->dev.platform_data = pdata;
182 + pdev->dev.dma_mask = mask;
183 + pdev->dev.coherent_dma_mask = *mask;
190 +static u64 rt3352_ohci_dmamask = DMA_BIT_MASK(32);
191 +static u64 rt3352_ehci_dmamask = DMA_BIT_MASK(32);
193 +void ralink_usb_platform(void)
195 + if (soc_is_rt3352() || soc_is_rt5350()) {
196 + ralink_add_usb("ohci-platform",
197 + &rt3352_ohci_data, &rt3352_ohci_dmamask);
198 + ralink_add_usb("ehci-platform",
199 + &rt3352_ehci_data, &rt3352_ehci_dmamask);
202 diff --git a/arch/mips/ralink/rt3883-usb.c b/arch/mips/ralink/rt3883-usb.c
204 index 0000000..1d948a9
206 +++ b/arch/mips/ralink/rt3883-usb.c
209 + * This program is free software; you can redistribute it and/or modify it
210 + * under the terms of the GNU General Public License version 2 as published
211 + * by the Free Software Foundation.
213 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
214 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
217 +#include <linux/kernel.h>
218 +#include <linux/init.h>
219 +#include <linux/module.h>
221 +#include <linux/delay.h>
222 +#include <linux/of_platform.h>
223 +#include <linux/dma-mapping.h>
224 +#include <linux/usb/ehci_pdriver.h>
225 +#include <linux/usb/ohci_pdriver.h>
227 +#include <asm/mach-ralink/ralink_regs.h>
228 +#include <asm/mach-ralink/rt3883.h>
230 +static atomic_t rt3883_usb_pwr_ref = ATOMIC_INIT(0);
232 +static int rt3883_usb_power_on(struct platform_device *pdev)
234 + if (atomic_inc_return(&rt3883_usb_pwr_ref) == 1) {
237 + t = rt_sysc_r32(RT3883_SYSC_REG_USB_PS);
239 + /* enable clock for port0's and port1's phys */
240 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
241 + t |= RT3883_CLKCFG1_UPHY0_CLK_EN | RT3883_CLKCFG1_UPHY1_CLK_EN;
242 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
245 + /* pull USBHOST and USBDEV out from reset */
246 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
247 + t &= ~(RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV);
248 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
251 + /* enable host mode */
252 + t = rt_sysc_r32(RT3883_SYSC_REG_SYSCFG1);
253 + t |= RT3883_SYSCFG1_USB0_HOST_MODE;
254 + rt_sysc_w32(t, RT3883_SYSC_REG_SYSCFG1);
256 + t = rt_sysc_r32(RT3883_SYSC_REG_USB_PS);
262 +static void rt3883_usb_power_off(struct platform_device *pdev)
264 + if (atomic_dec_return(&rt3883_usb_pwr_ref) == 0) {
267 + /* put USBHOST and USBDEV into reset */
268 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
269 + t |= RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV;
270 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
273 + /* disable clock for port0's and port1's phys*/
274 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
275 + t &= ~(RT3883_CLKCFG1_UPHY0_CLK_EN |
276 + RT3883_CLKCFG1_UPHY1_CLK_EN);
277 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
282 +static struct usb_ohci_pdata rt3883_ohci_data = {
283 + .power_on = rt3883_usb_power_on,
284 + .power_off = rt3883_usb_power_off,
287 +static struct usb_ehci_pdata rt3883_ehci_data = {
288 + .power_on = rt3883_usb_power_on,
289 + .power_off = rt3883_usb_power_off,
292 +static void ralink_add_usb(char *name, void *pdata, u64 *mask)
294 + struct device_node *node;
295 + struct platform_device *pdev;
297 + node = of_find_compatible_node(NULL, NULL, name);
301 + pdev = of_find_device_by_node(node);
306 + pdev->dev.platform_data = pdata;
308 + pdev->dev.dma_mask = mask;
309 + pdev->dev.coherent_dma_mask = *mask;
316 +static u64 rt3883_ohci_dmamask = DMA_BIT_MASK(32);
317 +static u64 rt3883_ehci_dmamask = DMA_BIT_MASK(32);
319 +void ralink_usb_platform(void)
321 + ralink_add_usb("ohci-platform",
322 + &rt3883_ohci_data, &rt3883_ohci_dmamask);
323 + ralink_add_usb("ehci-platform",
324 + &rt3883_ehci_data, &rt3883_ehci_dmamask);