2 * Ralink RT3662/RT3883 SoC platform device registration
4 * Copyright (C) 2011-2012 Gabor Juhos <juhosg@openwrt.org>
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.
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>
25 #include <asm/addrspace.h>
27 #include <asm/mach-ralink/rt3883.h>
28 #include <asm/mach-ralink/rt3883_regs.h>
29 #include <asm/mach-ralink/ramips_nand_platform.h>
32 #include <ramips_eth_platform.h>
34 static struct resource rt3883_flash0_resources[] = {
36 .flags = IORESOURCE_MEM,
37 .start = RT3883_BOOT_BASE,
38 .end = RT3883_BOOT_BASE + RT3883_BOOT_SIZE - 1,
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),
48 .platform_data = &rt3883_flash0_data,
52 static struct resource rt3883_flash1_resources[] = {
54 .flags = IORESOURCE_MEM,
55 .start = RT3883_SRAM_BASE,
56 .end = RT3883_SRAM_BASE + RT3883_SRAM_SIZE - 1,
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),
66 .platform_data = &rt3883_flash1_data,
70 static int rt3883_flash_instance __initdata;
71 void __init rt3883_register_pflash(unsigned int id)
73 struct platform_device *pdev;
74 struct physmap_flash_data *pdata;
75 void __iomem *fscc_base;
81 pdev = &rt3883_flash0_device;
82 reg = RT3883_FSCC_REG_FLASH_CFG0;
85 pdev = &rt3883_flash1_device;
86 reg = RT3883_FSCC_REG_FLASH_CFG1;
92 pdata = pdev->dev.platform_data;
94 fscc_base = ioremap(RT3883_FSCC_BASE, RT3883_FSCC_SIZE);
96 panic("RT3883: ioremap failed for FSCC");
98 t = __raw_readl(fscc_base + reg);
101 t = (t >> RT3883_FLASH_CFG_WIDTH_SHIFT) & RT3883_FLASH_CFG_WIDTH_MASK;
103 case RT3883_FLASH_CFG_WIDTH_8BIT:
106 case RT3883_FLASH_CFG_WIDTH_16BIT:
109 case RT3883_FLASH_CFG_WIDTH_32BIT:
116 pr_warn("RT3883: flash bank%d: invalid width detected\n", id);
120 pdev->id = rt3883_flash_instance;
122 platform_device_register(pdev);
123 rt3883_flash_instance++;
126 static atomic_t rt3883_usb_pwr_ref = ATOMIC_INIT(0);
128 static int rt3883_usb_power_on(struct platform_device *pdev)
131 if (atomic_inc_return(&rt3883_usb_pwr_ref) == 1) {
134 t = rt3883_sysc_rr(RT3883_SYSC_REG_USB_PS);
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);
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);
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);
153 t = rt3883_sysc_rr(RT3883_SYSC_REG_USB_PS);
159 static void rt3883_usb_power_off(struct platform_device *pdev)
161 if (atomic_dec_return(&rt3883_usb_pwr_ref) == 0) {
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);
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);
179 static struct usb_ehci_pdata rt3883_ehci_data = {
180 .power_on = rt3883_usb_power_on,
181 .power_off = rt3883_usb_power_off,
184 static struct resource rt3883_ehci_resources[] = {
186 .start = RT3883_EHCI_BASE,
187 .end = RT3883_EHCI_BASE + PAGE_SIZE - 1,
188 .flags = IORESOURCE_MEM,
190 .start = RT3883_INTC_IRQ_UHST,
191 .end = RT3883_INTC_IRQ_UHST,
192 .flags = IORESOURCE_IRQ,
196 static u64 rt3883_ehci_dmamask = DMA_BIT_MASK(32);
197 static struct platform_device rt3883_ehci_device = {
198 .name = "ehci-platform",
200 .resource = rt3883_ehci_resources,
201 .num_resources = ARRAY_SIZE(rt3883_ehci_resources),
203 .dma_mask = &rt3883_ehci_dmamask,
204 .coherent_dma_mask = DMA_BIT_MASK(32),
205 .platform_data = &rt3883_ehci_data,
209 static struct resource rt3883_ohci_resources[] = {
211 .start = RT3883_OHCI_BASE,
212 .end = RT3883_OHCI_BASE + PAGE_SIZE - 1,
213 .flags = IORESOURCE_MEM,
215 .start = RT3883_INTC_IRQ_UHST,
216 .end = RT3883_INTC_IRQ_UHST,
217 .flags = IORESOURCE_IRQ,
221 static struct usb_ohci_pdata rt3883_ohci_data = {
222 .power_on = rt3883_usb_power_on,
223 .power_off = rt3883_usb_power_off,
226 static u64 rt3883_ohci_dmamask = DMA_BIT_MASK(32);
227 static struct platform_device rt3883_ohci_device = {
228 .name = "ohci-platform",
230 .resource = rt3883_ohci_resources,
231 .num_resources = ARRAY_SIZE(rt3883_ohci_resources),
233 .dma_mask = &rt3883_ohci_dmamask,
234 .coherent_dma_mask = DMA_BIT_MASK(32),
235 .platform_data = &rt3883_ohci_data,
239 void __init rt3883_register_usbhost(void)
241 platform_device_register(&rt3883_ehci_device);
242 platform_device_register(&rt3883_ohci_device);
245 static void rt3883_fe_reset(void)
249 t = rt3883_sysc_rr(RT3883_SYSC_REG_RSTCTRL);
250 t |= RT3883_RSTCTRL_FE;
251 rt3883_sysc_wr(t , RT3883_SYSC_REG_RSTCTRL);
253 t &= ~RT3883_RSTCTRL_FE;
254 rt3883_sysc_wr(t, RT3883_SYSC_REG_RSTCTRL);
257 static struct resource rt3883_eth_resources[] = {
259 .start = RT3883_FE_BASE,
260 .end = RT3883_FE_BASE + PAGE_SIZE - 1,
261 .flags = IORESOURCE_MEM,
263 .start = RT3883_CPU_IRQ_FE,
264 .end = RT3883_CPU_IRQ_FE,
265 .flags = IORESOURCE_IRQ,
269 struct ramips_eth_platform_data rt3883_eth_data = {
270 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
271 .reset_fe = rt3883_fe_reset,
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),
280 .platform_data = &rt3883_eth_data,
284 void __init rt3883_register_ethernet(void)
288 clk = clk_get(NULL, "sys");
290 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
292 rt3883_eth_data.sys_freq = clk_get_rate(clk);
294 platform_device_register(&rt3883_eth_device);
297 static struct resource rt3883_wlan_resources[] = {
299 .start = RT3883_WLAN_BASE,
300 .end = RT3883_WLAN_BASE + 0x3FFFF,
301 .flags = IORESOURCE_MEM,
303 .start = RT3883_CPU_IRQ_WLAN,
304 .end = RT3883_CPU_IRQ_WLAN,
305 .flags = IORESOURCE_IRQ,
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),
315 .platform_data = &rt3883_wlan_data,
319 void __init rt3883_register_wlan(void)
321 rt3883_wlan_data.eeprom_file_name = "soc_wmac.eeprom",
322 platform_device_register(&rt3883_wlan_device);
325 static struct resource rt3883_wdt_resources[] = {
327 .start = RT3883_TIMER_BASE,
328 .end = RT3883_TIMER_BASE + RT3883_TIMER_SIZE - 1,
329 .flags = IORESOURCE_MEM,
333 static struct platform_device rt3883_wdt_device = {
334 .name = "ramips-wdt",
336 .resource = rt3883_wdt_resources,
337 .num_resources = ARRAY_SIZE(rt3883_wdt_resources),
340 void __init rt3883_register_wdt(bool enable_reset)
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);
351 platform_device_register(&rt3883_wdt_device);
354 static struct resource rt3883_nand_resources[] = {
356 .flags = IORESOURCE_MEM,
357 .start = RT3883_NANDC_BASE,
358 .end = RT3883_NANDC_BASE + RT3883_NANDC_SIZE - 1,
362 struct ramips_nand_platform_data rt3883_nand_data;
363 static struct platform_device rt3883_nand_device = {
364 .name = RAMIPS_NAND_DRIVER_NAME,
366 .resource = rt3883_nand_resources,
367 .num_resources = ARRAY_SIZE(rt3883_nand_resources),
369 .platform_data = &rt3883_nand_data,
373 void __init rt3883_register_nand(void)
375 platform_device_register(&rt3883_nand_device);
378 static struct resource rt3883_spi_resources[] = {
380 .flags = IORESOURCE_MEM,
381 .start = RT3883_SPI_BASE,
382 .end = RT3883_SPI_BASE + RT3883_SPI_SIZE - 1,
386 static struct platform_device rt3883_spi_device = {
387 .name = "ramips-spi",
389 .resource = rt3883_spi_resources,
390 .num_resources = ARRAY_SIZE(rt3883_spi_resources),
393 void __init rt3883_register_spi(struct spi_board_info *info, int n)
395 spi_register_board_info(info, n);
396 platform_device_register(&rt3883_spi_device);