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 = {
181 .power_on = rt3883_usb_power_on,
182 .power_off = rt3883_usb_power_off,
185 static struct resource rt3883_ehci_resources[] = {
187 .start = RT3883_EHCI_BASE,
188 .end = RT3883_EHCI_BASE + PAGE_SIZE - 1,
189 .flags = IORESOURCE_MEM,
191 .start = RT3883_INTC_IRQ_UHST,
192 .end = RT3883_INTC_IRQ_UHST,
193 .flags = IORESOURCE_IRQ,
197 static u64 rt3883_ehci_dmamask = DMA_BIT_MASK(32);
198 static struct platform_device rt3883_ehci_device = {
199 .name = "ehci-platform",
201 .resource = rt3883_ehci_resources,
202 .num_resources = ARRAY_SIZE(rt3883_ehci_resources),
204 .dma_mask = &rt3883_ehci_dmamask,
205 .coherent_dma_mask = DMA_BIT_MASK(32),
206 .platform_data = &rt3883_ehci_data,
210 static struct resource rt3883_ohci_resources[] = {
212 .start = RT3883_OHCI_BASE,
213 .end = RT3883_OHCI_BASE + PAGE_SIZE - 1,
214 .flags = IORESOURCE_MEM,
216 .start = RT3883_INTC_IRQ_UHST,
217 .end = RT3883_INTC_IRQ_UHST,
218 .flags = IORESOURCE_IRQ,
222 static struct usb_ohci_pdata rt3883_ohci_data = {
223 .power_on = rt3883_usb_power_on,
224 .power_off = rt3883_usb_power_off,
227 static u64 rt3883_ohci_dmamask = DMA_BIT_MASK(32);
228 static struct platform_device rt3883_ohci_device = {
229 .name = "ohci-platform",
231 .resource = rt3883_ohci_resources,
232 .num_resources = ARRAY_SIZE(rt3883_ohci_resources),
234 .dma_mask = &rt3883_ohci_dmamask,
235 .coherent_dma_mask = DMA_BIT_MASK(32),
236 .platform_data = &rt3883_ohci_data,
240 void __init rt3883_register_usbhost(void)
242 platform_device_register(&rt3883_ehci_device);
243 platform_device_register(&rt3883_ohci_device);
246 static void rt3883_fe_reset(void)
250 t = rt3883_sysc_rr(RT3883_SYSC_REG_RSTCTRL);
251 t |= RT3883_RSTCTRL_FE;
252 rt3883_sysc_wr(t , RT3883_SYSC_REG_RSTCTRL);
254 t &= ~RT3883_RSTCTRL_FE;
255 rt3883_sysc_wr(t, RT3883_SYSC_REG_RSTCTRL);
258 static struct resource rt3883_eth_resources[] = {
260 .start = RT3883_FE_BASE,
261 .end = RT3883_FE_BASE + PAGE_SIZE - 1,
262 .flags = IORESOURCE_MEM,
264 .start = RT3883_CPU_IRQ_FE,
265 .end = RT3883_CPU_IRQ_FE,
266 .flags = IORESOURCE_IRQ,
270 struct ramips_eth_platform_data rt3883_eth_data = {
271 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
272 .reset_fe = rt3883_fe_reset,
276 static struct platform_device rt3883_eth_device = {
277 .name = "ramips_eth",
278 .resource = rt3883_eth_resources,
279 .num_resources = ARRAY_SIZE(rt3883_eth_resources),
281 .platform_data = &rt3883_eth_data,
285 void __init rt3883_register_ethernet(void)
289 clk = clk_get(NULL, "sys");
291 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
293 rt3883_eth_data.sys_freq = clk_get_rate(clk);
295 platform_device_register(&rt3883_eth_device);
298 static struct resource rt3883_wlan_resources[] = {
300 .start = RT3883_WLAN_BASE,
301 .end = RT3883_WLAN_BASE + 0x3FFFF,
302 .flags = IORESOURCE_MEM,
304 .start = RT3883_CPU_IRQ_WLAN,
305 .end = RT3883_CPU_IRQ_WLAN,
306 .flags = IORESOURCE_IRQ,
310 struct rt2x00_platform_data rt3883_wlan_data;
311 static struct platform_device rt3883_wlan_device = {
312 .name = "rt2800_wmac",
313 .resource = rt3883_wlan_resources,
314 .num_resources = ARRAY_SIZE(rt3883_wlan_resources),
316 .platform_data = &rt3883_wlan_data,
320 void __init rt3883_register_wlan(void)
322 rt3883_wlan_data.eeprom_file_name = "soc_wmac.eeprom",
323 platform_device_register(&rt3883_wlan_device);
326 static struct resource rt3883_wdt_resources[] = {
328 .start = RT3883_TIMER_BASE,
329 .end = RT3883_TIMER_BASE + RT3883_TIMER_SIZE - 1,
330 .flags = IORESOURCE_MEM,
334 static struct platform_device rt3883_wdt_device = {
335 .name = "ramips-wdt",
337 .resource = rt3883_wdt_resources,
338 .num_resources = ARRAY_SIZE(rt3883_wdt_resources),
341 void __init rt3883_register_wdt(bool enable_reset)
346 /* enable WDT reset output on GPIO 2 */
347 t = rt3883_sysc_rr(RT3883_SYSC_REG_SYSCFG1);
348 t |= RT3883_SYSCFG1_GPIO2_AS_WDT_OUT;
349 rt3883_sysc_wr(t, RT3883_SYSC_REG_SYSCFG1);
352 platform_device_register(&rt3883_wdt_device);
355 static struct resource rt3883_nand_resources[] = {
357 .flags = IORESOURCE_MEM,
358 .start = RT3883_NANDC_BASE,
359 .end = RT3883_NANDC_BASE + RT3883_NANDC_SIZE - 1,
363 struct ramips_nand_platform_data rt3883_nand_data;
364 static struct platform_device rt3883_nand_device = {
365 .name = RAMIPS_NAND_DRIVER_NAME,
367 .resource = rt3883_nand_resources,
368 .num_resources = ARRAY_SIZE(rt3883_nand_resources),
370 .platform_data = &rt3883_nand_data,
374 void __init rt3883_register_nand(void)
376 platform_device_register(&rt3883_nand_device);
379 static struct resource rt3883_spi_resources[] = {
381 .flags = IORESOURCE_MEM,
382 .start = RT3883_SPI_BASE,
383 .end = RT3883_SPI_BASE + RT3883_SPI_SIZE - 1,
387 static struct platform_device rt3883_spi_device = {
388 .name = "ramips-spi",
390 .resource = rt3883_spi_resources,
391 .num_resources = ARRAY_SIZE(rt3883_spi_resources),
394 void __init rt3883_register_spi(struct spi_board_info *info, int n)
396 spi_register_board_info(info, n);
397 platform_device_register(&rt3883_spi_device);