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 --- a/arch/mips/ralink/Makefile
23 +++ b/arch/mips/ralink/Makefile
25 obj-y := prom.o of.o reset.o clk.o irq.o pinmux.o timer.o
27 obj-$(CONFIG_SOC_RT288X) += rt288x.o
28 -obj-$(CONFIG_SOC_RT305X) += rt305x.o
29 -obj-$(CONFIG_SOC_RT3883) += rt3883.o
30 +obj-$(CONFIG_SOC_RT305X) += rt305x.o rt305x-usb.o
31 +obj-$(CONFIG_SOC_RT3883) += rt3883.o rt3883-usb.o
32 obj-$(CONFIG_SOC_MT7620) += mt7620.o
34 obj-$(CONFIG_EARLY_PRINTK) += early_printk.o
35 --- a/arch/mips/ralink/common.h
36 +++ b/arch/mips/ralink/common.h
37 @@ -51,5 +51,6 @@ extern void prom_soc_init(struct ralink_
38 __iomem void *plat_of_remap_node(const char *node);
40 void ralink_pinmux(void);
41 +void ralink_usb_platform(void);
43 #endif /* _RALINK_COMMON_H__ */
44 --- a/arch/mips/ralink/mt7620.c
45 +++ b/arch/mips/ralink/mt7620.c
46 @@ -140,6 +140,11 @@ struct ralink_pinmux rt_gpio_pinmux = {
47 .uart_mask = MT7620_GPIO_MODE_GPIO,
50 +void ralink_usb_platform(void)
55 void __init ralink_clk_init(void)
57 unsigned long cpu_rate, sys_rate;
58 --- a/arch/mips/ralink/of.c
59 +++ b/arch/mips/ralink/of.c
60 @@ -111,6 +111,7 @@ static int __init plat_of_setup(void)
61 panic("failed to populate DT\n");
64 + ralink_usb_platform();
69 +++ b/arch/mips/ralink/rt305x-usb.c
72 + * This program is free software; you can redistribute it and/or modify it
73 + * under the terms of the GNU General Public License version 2 as published
74 + * by the Free Software Foundation.
76 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
77 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
80 +#include <linux/kernel.h>
81 +#include <linux/init.h>
82 +#include <linux/module.h>
84 +#include <linux/delay.h>
85 +#include <linux/of_platform.h>
86 +#include <linux/dma-mapping.h>
87 +#include <linux/usb/ehci_pdriver.h>
88 +#include <linux/usb/ohci_pdriver.h>
90 +#include <asm/mach-ralink/ralink_regs.h>
91 +#include <asm/mach-ralink/rt305x.h>
93 +static atomic_t rt3352_usb_pwr_ref = ATOMIC_INIT(0);
95 +static int rt3352_usb_power_on(struct platform_device *pdev)
98 + if (atomic_inc_return(&rt3352_usb_pwr_ref) == 1) {
101 + t = rt_sysc_r32(RT3352_SYSC_REG_USB_PS);
103 + /* enable clock for port0's and port1's phys */
104 + t = rt_sysc_r32(RT3352_SYSC_REG_CLKCFG1);
105 + t |= RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN;
106 + rt_sysc_w32(t, RT3352_SYSC_REG_CLKCFG1);
109 + /* pull USBHOST and USBDEV out from reset */
110 + t = rt_sysc_r32(RT3352_SYSC_REG_RSTCTRL);
111 + t &= ~(RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV);
112 + rt_sysc_w32(t, RT3352_SYSC_REG_RSTCTRL);
115 + /* enable host mode */
116 + t = rt_sysc_r32(RT3352_SYSC_REG_SYSCFG1);
117 + t |= RT3352_SYSCFG1_USB0_HOST_MODE;
118 + rt_sysc_w32(t, RT3352_SYSC_REG_SYSCFG1);
120 + t = rt_sysc_r32(RT3352_SYSC_REG_USB_PS);
126 +static void rt3352_usb_power_off(struct platform_device *pdev)
128 + if (atomic_dec_return(&rt3352_usb_pwr_ref) == 0) {
131 + /* put USBHOST and USBDEV into reset */
132 + t = rt_sysc_r32(RT3352_SYSC_REG_RSTCTRL);
133 + t |= RT3352_RSTCTRL_UHST | RT3352_RSTCTRL_UDEV;
134 + rt_sysc_w32(t, RT3352_SYSC_REG_RSTCTRL);
137 + /* disable clock for port0's and port1's phys*/
138 + t = rt_sysc_r32(RT3352_SYSC_REG_CLKCFG1);
139 + t &= ~(RT3352_CLKCFG1_UPHY0_CLK_EN | RT3352_CLKCFG1_UPHY1_CLK_EN);
140 + rt_sysc_w32(t, RT3352_SYSC_REG_CLKCFG1);
145 +static struct usb_ehci_pdata rt3352_ehci_data = {
146 + .power_on = rt3352_usb_power_on,
147 + .power_off = rt3352_usb_power_off,
150 +static struct usb_ohci_pdata rt3352_ohci_data = {
151 + .power_on = rt3352_usb_power_on,
152 + .power_off = rt3352_usb_power_off,
155 +static void ralink_add_usb(char *name, void *pdata, u64 *mask)
157 + struct device_node *node;
158 + struct platform_device *pdev;
160 + node = of_find_compatible_node(NULL, NULL, name);
164 + pdev = of_find_device_by_node(node);
169 + pdev->dev.platform_data = pdata;
171 + pdev->dev.dma_mask = mask;
172 + pdev->dev.coherent_dma_mask = *mask;
179 +static u64 rt3352_ohci_dmamask = DMA_BIT_MASK(32);
180 +static u64 rt3352_ehci_dmamask = DMA_BIT_MASK(32);
182 +void ralink_usb_platform(void)
184 + if (soc_is_rt3352() || soc_is_rt5350()) {
185 + ralink_add_usb("ohci-platform",
186 + &rt3352_ohci_data, &rt3352_ohci_dmamask);
187 + ralink_add_usb("ehci-platform",
188 + &rt3352_ehci_data, &rt3352_ehci_dmamask);
192 +++ b/arch/mips/ralink/rt3883-usb.c
195 + * This program is free software; you can redistribute it and/or modify it
196 + * under the terms of the GNU General Public License version 2 as published
197 + * by the Free Software Foundation.
199 + * Copyright (C) 2008-2011 Gabor Juhos <juhosg@openwrt.org>
200 + * Copyright (C) 2013 John Crispin <blogic@openwrt.org>
203 +#include <linux/kernel.h>
204 +#include <linux/init.h>
205 +#include <linux/module.h>
207 +#include <linux/delay.h>
208 +#include <linux/of_platform.h>
209 +#include <linux/dma-mapping.h>
210 +#include <linux/usb/ehci_pdriver.h>
211 +#include <linux/usb/ohci_pdriver.h>
213 +#include <asm/mach-ralink/ralink_regs.h>
214 +#include <asm/mach-ralink/rt3883.h>
216 +static atomic_t rt3883_usb_pwr_ref = ATOMIC_INIT(0);
218 +static int rt3883_usb_power_on(struct platform_device *pdev)
220 + if (atomic_inc_return(&rt3883_usb_pwr_ref) == 1) {
223 + t = rt_sysc_r32(RT3883_SYSC_REG_USB_PS);
225 + /* enable clock for port0's and port1's phys */
226 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
227 + t |= RT3883_CLKCFG1_UPHY0_CLK_EN | RT3883_CLKCFG1_UPHY1_CLK_EN;
228 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
231 + /* pull USBHOST and USBDEV out from reset */
232 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
233 + t &= ~(RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV);
234 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
237 + /* enable host mode */
238 + t = rt_sysc_r32(RT3883_SYSC_REG_SYSCFG1);
239 + t |= RT3883_SYSCFG1_USB0_HOST_MODE;
240 + rt_sysc_w32(t, RT3883_SYSC_REG_SYSCFG1);
242 + t = rt_sysc_r32(RT3883_SYSC_REG_USB_PS);
248 +static void rt3883_usb_power_off(struct platform_device *pdev)
250 + if (atomic_dec_return(&rt3883_usb_pwr_ref) == 0) {
253 + /* put USBHOST and USBDEV into reset */
254 + t = rt_sysc_r32(RT3883_SYSC_REG_RSTCTRL);
255 + t |= RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV;
256 + rt_sysc_w32(t, RT3883_SYSC_REG_RSTCTRL);
259 + /* disable clock for port0's and port1's phys*/
260 + t = rt_sysc_r32(RT3883_SYSC_REG_CLKCFG1);
261 + t &= ~(RT3883_CLKCFG1_UPHY0_CLK_EN |
262 + RT3883_CLKCFG1_UPHY1_CLK_EN);
263 + rt_sysc_w32(t, RT3883_SYSC_REG_CLKCFG1);
268 +static struct usb_ohci_pdata rt3883_ohci_data = {
269 + .power_on = rt3883_usb_power_on,
270 + .power_off = rt3883_usb_power_off,
273 +static struct usb_ehci_pdata rt3883_ehci_data = {
274 + .power_on = rt3883_usb_power_on,
275 + .power_off = rt3883_usb_power_off,
278 +static void ralink_add_usb(char *name, void *pdata, u64 *mask)
280 + struct device_node *node;
281 + struct platform_device *pdev;
283 + node = of_find_compatible_node(NULL, NULL, name);
287 + pdev = of_find_device_by_node(node);
292 + pdev->dev.platform_data = pdata;
294 + pdev->dev.dma_mask = mask;
295 + pdev->dev.coherent_dma_mask = *mask;
302 +static u64 rt3883_ohci_dmamask = DMA_BIT_MASK(32);
303 +static u64 rt3883_ehci_dmamask = DMA_BIT_MASK(32);
305 +void ralink_usb_platform(void)
307 + ralink_add_usb("ohci-platform",
308 + &rt3883_ohci_data, &rt3883_ohci_dmamask);
309 + ralink_add_usb("ehci-platform",
310 + &rt3883_ehci_data, &rt3883_ehci_dmamask);