ramips: remove port_power_off field from ehci_platform_data
[openwrt/openwrt.git] / target / linux / ramips / files / arch / mips / ralink / rt3883 / devices.c
1 /*
2 * Ralink RT3662/RT3883 SoC platform device registration
3 *
4 * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published
8 * by the Free Software Foundation.
9 */
10
11 #include <linux/kernel.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/physmap.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/dma-mapping.h>
17 #include <linux/spi/spi.h>
18 #include <linux/delay.h>
19 #include <linux/err.h>
20 #include <linux/clk.h>
21 #include <linux/rt2x00_platform.h>
22 #include <linux/usb/ehci_pdriver.h>
23 #include <linux/usb/ohci_pdriver.h>
24
25 #include <asm/addrspace.h>
26
27 #include <asm/mach-ralink/rt3883.h>
28 #include <asm/mach-ralink/rt3883_regs.h>
29 #include <asm/mach-ralink/ramips_nand_platform.h>
30 #include "devices.h"
31
32 #include <ramips_eth_platform.h>
33
34 static struct resource rt3883_flash0_resources[] = {
35 {
36 .flags = IORESOURCE_MEM,
37 .start = RT3883_BOOT_BASE,
38 .end = RT3883_BOOT_BASE + RT3883_BOOT_SIZE - 1,
39 },
40 };
41
42 struct physmap_flash_data rt3883_flash0_data;
43 static struct platform_device rt3883_flash0_device = {
44 .name = "physmap-flash",
45 .resource = rt3883_flash0_resources,
46 .num_resources = ARRAY_SIZE(rt3883_flash0_resources),
47 .dev = {
48 .platform_data = &rt3883_flash0_data,
49 },
50 };
51
52 static struct resource rt3883_flash1_resources[] = {
53 {
54 .flags = IORESOURCE_MEM,
55 .start = RT3883_SRAM_BASE,
56 .end = RT3883_SRAM_BASE + RT3883_SRAM_SIZE - 1,
57 },
58 };
59
60 struct physmap_flash_data rt3883_flash1_data;
61 static struct platform_device rt3883_flash1_device = {
62 .name = "physmap-flash",
63 .resource = rt3883_flash1_resources,
64 .num_resources = ARRAY_SIZE(rt3883_flash1_resources),
65 .dev = {
66 .platform_data = &rt3883_flash1_data,
67 },
68 };
69
70 static int rt3883_flash_instance __initdata;
71 void __init rt3883_register_pflash(unsigned int id)
72 {
73 struct platform_device *pdev;
74 struct physmap_flash_data *pdata;
75 void __iomem *fscc_base;
76 u32 t;
77 int reg;
78
79 switch (id) {
80 case 0:
81 pdev = &rt3883_flash0_device;
82 reg = RT3883_FSCC_REG_FLASH_CFG0;
83 break;
84 case 1:
85 pdev = &rt3883_flash1_device;
86 reg = RT3883_FSCC_REG_FLASH_CFG1;
87 break;
88 default:
89 return;
90 }
91
92 pdata = pdev->dev.platform_data;
93
94 fscc_base = ioremap(RT3883_FSCC_BASE, RT3883_FSCC_SIZE);
95 if (!fscc_base)
96 panic("RT3883: ioremap failed for FSCC");
97
98 t = __raw_readl(fscc_base + reg);
99 iounmap(fscc_base);
100
101 t = (t >> RT3883_FLASH_CFG_WIDTH_SHIFT) & RT3883_FLASH_CFG_WIDTH_MASK;
102 switch (t) {
103 case RT3883_FLASH_CFG_WIDTH_8BIT:
104 pdata->width = 1;
105 break;
106 case RT3883_FLASH_CFG_WIDTH_16BIT:
107 pdata->width = 2;
108 break;
109 case RT3883_FLASH_CFG_WIDTH_32BIT:
110 if (id == 1) {
111 pdata->width = 4;
112 break;
113 }
114 /* fallthrough */
115 default:
116 pr_warn("RT3883: flash bank%d: invalid width detected\n", id);
117 return;
118 }
119
120 pdev->id = rt3883_flash_instance;
121
122 platform_device_register(pdev);
123 rt3883_flash_instance++;
124 }
125
126 static atomic_t rt3883_usb_pwr_ref = ATOMIC_INIT(0);
127
128 static int rt3883_usb_power_on(struct platform_device *pdev)
129 {
130
131 if (atomic_inc_return(&rt3883_usb_pwr_ref) == 1) {
132 u32 t;
133
134 t = rt3883_sysc_rr(RT3883_SYSC_REG_USB_PS);
135
136 /* enable clock for port0's and port1's phys */
137 t = rt3883_sysc_rr(RT3883_SYSC_REG_CLKCFG1);
138 t |= RT3883_CLKCFG1_UPHY0_CLK_EN | RT3883_CLKCFG1_UPHY1_CLK_EN;
139 rt3883_sysc_wr(t, RT3883_SYSC_REG_CLKCFG1);
140 mdelay(500);
141
142 /* pull USBHOST and USBDEV out from reset */
143 t = rt3883_sysc_rr(RT3883_SYSC_REG_RSTCTRL);
144 t &= ~(RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV);
145 rt3883_sysc_wr(t, RT3883_SYSC_REG_RSTCTRL);
146 mdelay(500);
147
148 /* enable host mode */
149 t = rt3883_sysc_rr(RT3883_SYSC_REG_SYSCFG1);
150 t |= RT3883_SYSCFG1_USB0_HOST_MODE;
151 rt3883_sysc_wr(t, RT3883_SYSC_REG_SYSCFG1);
152
153 t = rt3883_sysc_rr(RT3883_SYSC_REG_USB_PS);
154 }
155
156 return 0;
157 }
158
159 static void rt3883_usb_power_off(struct platform_device *pdev)
160 {
161 if (atomic_dec_return(&rt3883_usb_pwr_ref) == 0) {
162 u32 t;
163
164 /* put USBHOST and USBDEV into reset */
165 t = rt3883_sysc_rr(RT3883_SYSC_REG_RSTCTRL);
166 t |= RT3883_RSTCTRL_UHST | RT3883_RSTCTRL_UDEV;
167 rt3883_sysc_wr(t, RT3883_SYSC_REG_RSTCTRL);
168 udelay(10000);
169
170 /* disable clock for port0's and port1's phys*/
171 t = rt3883_sysc_rr(RT3883_SYSC_REG_CLKCFG1);
172 t &= ~(RT3883_CLKCFG1_UPHY0_CLK_EN |
173 RT3883_CLKCFG1_UPHY1_CLK_EN);
174 rt3883_sysc_wr(t, RT3883_SYSC_REG_CLKCFG1);
175 udelay(10000);
176 }
177 }
178
179 static struct usb_ehci_pdata rt3883_ehci_data = {
180 .power_on = rt3883_usb_power_on,
181 .power_off = rt3883_usb_power_off,
182 };
183
184 static struct resource rt3883_ehci_resources[] = {
185 {
186 .start = RT3883_EHCI_BASE,
187 .end = RT3883_EHCI_BASE + PAGE_SIZE - 1,
188 .flags = IORESOURCE_MEM,
189 }, {
190 .start = RT3883_INTC_IRQ_UHST,
191 .end = RT3883_INTC_IRQ_UHST,
192 .flags = IORESOURCE_IRQ,
193 },
194 };
195
196 static u64 rt3883_ehci_dmamask = DMA_BIT_MASK(32);
197 static struct platform_device rt3883_ehci_device = {
198 .name = "ehci-platform",
199 .id = -1,
200 .resource = rt3883_ehci_resources,
201 .num_resources = ARRAY_SIZE(rt3883_ehci_resources),
202 .dev = {
203 .dma_mask = &rt3883_ehci_dmamask,
204 .coherent_dma_mask = DMA_BIT_MASK(32),
205 .platform_data = &rt3883_ehci_data,
206 },
207 };
208
209 static struct resource rt3883_ohci_resources[] = {
210 {
211 .start = RT3883_OHCI_BASE,
212 .end = RT3883_OHCI_BASE + PAGE_SIZE - 1,
213 .flags = IORESOURCE_MEM,
214 }, {
215 .start = RT3883_INTC_IRQ_UHST,
216 .end = RT3883_INTC_IRQ_UHST,
217 .flags = IORESOURCE_IRQ,
218 },
219 };
220
221 static struct usb_ohci_pdata rt3883_ohci_data = {
222 .power_on = rt3883_usb_power_on,
223 .power_off = rt3883_usb_power_off,
224 };
225
226 static u64 rt3883_ohci_dmamask = DMA_BIT_MASK(32);
227 static struct platform_device rt3883_ohci_device = {
228 .name = "ohci-platform",
229 .id = -1,
230 .resource = rt3883_ohci_resources,
231 .num_resources = ARRAY_SIZE(rt3883_ohci_resources),
232 .dev = {
233 .dma_mask = &rt3883_ohci_dmamask,
234 .coherent_dma_mask = DMA_BIT_MASK(32),
235 .platform_data = &rt3883_ohci_data,
236 },
237 };
238
239 void __init rt3883_register_usbhost(void)
240 {
241 platform_device_register(&rt3883_ehci_device);
242 platform_device_register(&rt3883_ohci_device);
243 }
244
245 static void rt3883_fe_reset(void)
246 {
247 u32 t;
248
249 t = rt3883_sysc_rr(RT3883_SYSC_REG_RSTCTRL);
250 t |= RT3883_RSTCTRL_FE;
251 rt3883_sysc_wr(t , RT3883_SYSC_REG_RSTCTRL);
252
253 t &= ~RT3883_RSTCTRL_FE;
254 rt3883_sysc_wr(t, RT3883_SYSC_REG_RSTCTRL);
255 }
256
257 static struct resource rt3883_eth_resources[] = {
258 {
259 .start = RT3883_FE_BASE,
260 .end = RT3883_FE_BASE + PAGE_SIZE - 1,
261 .flags = IORESOURCE_MEM,
262 }, {
263 .start = RT3883_CPU_IRQ_FE,
264 .end = RT3883_CPU_IRQ_FE,
265 .flags = IORESOURCE_IRQ,
266 },
267 };
268
269 struct ramips_eth_platform_data rt3883_eth_data = {
270 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
271 .reset_fe = rt3883_fe_reset,
272 .min_pkt_len = 64,
273 };
274
275 static struct platform_device rt3883_eth_device = {
276 .name = "ramips_eth",
277 .resource = rt3883_eth_resources,
278 .num_resources = ARRAY_SIZE(rt3883_eth_resources),
279 .dev = {
280 .platform_data = &rt3883_eth_data,
281 }
282 };
283
284 void __init rt3883_register_ethernet(void)
285 {
286 struct clk *clk;
287
288 clk = clk_get(NULL, "sys");
289 if (IS_ERR(clk))
290 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
291
292 rt3883_eth_data.sys_freq = clk_get_rate(clk);
293
294 platform_device_register(&rt3883_eth_device);
295 }
296
297 static struct resource rt3883_wlan_resources[] = {
298 {
299 .start = RT3883_WLAN_BASE,
300 .end = RT3883_WLAN_BASE + 0x3FFFF,
301 .flags = IORESOURCE_MEM,
302 }, {
303 .start = RT3883_CPU_IRQ_WLAN,
304 .end = RT3883_CPU_IRQ_WLAN,
305 .flags = IORESOURCE_IRQ,
306 },
307 };
308
309 struct rt2x00_platform_data rt3883_wlan_data;
310 static struct platform_device rt3883_wlan_device = {
311 .name = "rt2800_wmac",
312 .resource = rt3883_wlan_resources,
313 .num_resources = ARRAY_SIZE(rt3883_wlan_resources),
314 .dev = {
315 .platform_data = &rt3883_wlan_data,
316 }
317 };
318
319 void __init rt3883_register_wlan(void)
320 {
321 rt3883_wlan_data.eeprom_file_name = "soc_wmac.eeprom",
322 platform_device_register(&rt3883_wlan_device);
323 }
324
325 static struct resource rt3883_wdt_resources[] = {
326 {
327 .start = RT3883_TIMER_BASE,
328 .end = RT3883_TIMER_BASE + RT3883_TIMER_SIZE - 1,
329 .flags = IORESOURCE_MEM,
330 },
331 };
332
333 static struct platform_device rt3883_wdt_device = {
334 .name = "ramips-wdt",
335 .id = -1,
336 .resource = rt3883_wdt_resources,
337 .num_resources = ARRAY_SIZE(rt3883_wdt_resources),
338 };
339
340 void __init rt3883_register_wdt(bool enable_reset)
341 {
342 if (enable_reset) {
343 u32 t;
344
345 /* enable WDT reset output on GPIO 2 */
346 t = rt3883_sysc_rr(RT3883_SYSC_REG_SYSCFG1);
347 t |= RT3883_SYSCFG1_GPIO2_AS_WDT_OUT;
348 rt3883_sysc_wr(t, RT3883_SYSC_REG_SYSCFG1);
349 }
350
351 platform_device_register(&rt3883_wdt_device);
352 }
353
354 static struct resource rt3883_nand_resources[] = {
355 {
356 .flags = IORESOURCE_MEM,
357 .start = RT3883_NANDC_BASE,
358 .end = RT3883_NANDC_BASE + RT3883_NANDC_SIZE - 1,
359 },
360 };
361
362 struct ramips_nand_platform_data rt3883_nand_data;
363 static struct platform_device rt3883_nand_device = {
364 .name = RAMIPS_NAND_DRIVER_NAME,
365 .id = -1,
366 .resource = rt3883_nand_resources,
367 .num_resources = ARRAY_SIZE(rt3883_nand_resources),
368 .dev = {
369 .platform_data = &rt3883_nand_data,
370 },
371 };
372
373 void __init rt3883_register_nand(void)
374 {
375 platform_device_register(&rt3883_nand_device);
376 }
377
378 static struct resource rt3883_spi_resources[] = {
379 {
380 .flags = IORESOURCE_MEM,
381 .start = RT3883_SPI_BASE,
382 .end = RT3883_SPI_BASE + RT3883_SPI_SIZE - 1,
383 },
384 };
385
386 static struct platform_device rt3883_spi_device = {
387 .name = "ramips-spi",
388 .id = 0,
389 .resource = rt3883_spi_resources,
390 .num_resources = ARRAY_SIZE(rt3883_spi_resources),
391 };
392
393 void __init rt3883_register_spi(struct spi_board_info *info, int n)
394 {
395 spi_register_board_info(info, n);
396 platform_device_register(&rt3883_spi_device);
397 }
398