2 * Ralink RT305x SoC platform device registration
4 * Copyright (C) 2009-2010 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/err.h>
14 #include <linux/clk.h>
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/physmap.h>
17 #include <linux/spi/spi.h>
18 #include <linux/rt2x00_platform.h>
20 #include <asm/addrspace.h>
22 #include <asm/mach-ralink/rt305x.h>
23 #include <asm/mach-ralink/rt305x_regs.h>
26 #include <ramips_eth_platform.h>
27 #include <rt305x_esw_platform.h>
29 static struct resource rt305x_flash0_resources[] = {
31 .flags = IORESOURCE_MEM,
32 .start = KSEG1ADDR(RT305X_FLASH0_BASE),
33 .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
34 RT305X_FLASH0_SIZE - 1,
38 struct physmap_flash_data rt305x_flash0_data;
39 static struct platform_device rt305x_flash0_device = {
40 .name = "physmap-flash",
41 .resource = rt305x_flash0_resources,
42 .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
44 .platform_data = &rt305x_flash0_data,
48 static struct resource rt305x_flash1_resources[] = {
50 .flags = IORESOURCE_MEM,
51 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
52 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
53 RT305X_FLASH1_SIZE - 1,
57 struct physmap_flash_data rt305x_flash1_data;
58 static struct platform_device rt305x_flash1_device = {
59 .name = "physmap-flash",
60 .resource = rt305x_flash1_resources,
61 .num_resources = ARRAY_SIZE(rt305x_flash1_resources),
63 .platform_data = &rt305x_flash1_data,
67 static int rt305x_flash_instance __initdata;
68 void __init rt305x_register_flash(unsigned int id)
70 struct platform_device *pdev;
71 struct physmap_flash_data *pdata;
77 pdev = &rt305x_flash0_device;
78 reg = MEMC_REG_FLASH_CFG0;
81 pdev = &rt305x_flash1_device;
82 reg = MEMC_REG_FLASH_CFG1;
88 t = rt305x_memc_rr(reg);
89 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
91 pdata = pdev->dev.platform_data;
93 case FLASH_CFG_WIDTH_8BIT:
96 case FLASH_CFG_WIDTH_16BIT:
99 case FLASH_CFG_WIDTH_32BIT:
103 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
107 pdev->id = rt305x_flash_instance;
109 platform_device_register(pdev);
110 rt305x_flash_instance++;
113 static void rt305x_fe_reset(void)
115 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
116 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
119 static struct resource rt305x_eth_resources[] = {
121 .start = RT305X_FE_BASE,
122 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
123 .flags = IORESOURCE_MEM,
125 .start = RT305X_CPU_IRQ_FE,
126 .end = RT305X_CPU_IRQ_FE,
127 .flags = IORESOURCE_IRQ,
131 static struct ramips_eth_platform_data ramips_eth_data = {
132 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
133 .reset_fe = rt305x_fe_reset,
137 static struct platform_device rt305x_eth_device = {
138 .name = "ramips_eth",
139 .resource = rt305x_eth_resources,
140 .num_resources = ARRAY_SIZE(rt305x_eth_resources),
142 .platform_data = &ramips_eth_data,
146 static struct resource rt305x_esw_resources[] = {
148 .start = RT305X_SWITCH_BASE,
149 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
150 .flags = IORESOURCE_MEM,
154 struct rt305x_esw_platform_data rt305x_esw_data = {
155 .vlan_config = RT305X_ESW_VLAN_CONFIG_NONE,
156 .reg_initval_fct2 = 0x00d6500c,
157 .reg_initval_fpa2 = 0x3f502b28,
160 static struct platform_device rt305x_esw_device = {
161 .name = "rt305x-esw",
162 .resource = rt305x_esw_resources,
163 .num_resources = ARRAY_SIZE(rt305x_esw_resources),
165 .platform_data = &rt305x_esw_data,
169 void __init rt305x_register_ethernet(void)
173 clk = clk_get(NULL, "sys");
175 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
177 ramips_eth_data.sys_freq = clk_get_rate(clk);
179 platform_device_register(&rt305x_esw_device);
180 platform_device_register(&rt305x_eth_device);
183 static struct resource rt305x_wifi_resources[] = {
185 .start = RT305X_WMAC_BASE,
186 .end = RT305X_WMAC_BASE + 0x3FFFF,
187 .flags = IORESOURCE_MEM,
189 .start = RT305X_CPU_IRQ_WNIC,
190 .end = RT305X_CPU_IRQ_WNIC,
191 .flags = IORESOURCE_IRQ,
195 static struct rt2x00_platform_data rt305x_wifi_data;
196 static struct platform_device rt305x_wifi_device = {
197 .name = "rt2800_wmac",
198 .resource = rt305x_wifi_resources,
199 .num_resources = ARRAY_SIZE(rt305x_wifi_resources),
201 .platform_data = &rt305x_wifi_data,
205 void __init rt305x_register_wifi(void)
207 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
208 platform_device_register(&rt305x_wifi_device);
211 static struct resource rt305x_wdt_resources[] = {
213 .start = RT305X_TIMER_BASE,
214 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
215 .flags = IORESOURCE_MEM,
219 static struct platform_device rt305x_wdt_device = {
220 .name = "ramips-wdt",
222 .resource = rt305x_wdt_resources,
223 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
226 void __init rt305x_register_wdt(void)
230 /* enable WDT reset output on pin SRAM_CS_N */
231 t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
232 t |= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT <<
233 SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT;
234 rt305x_sysc_wr(t, SYSC_REG_SYSTEM_CONFIG);
236 platform_device_register(&rt305x_wdt_device);
239 static struct resource rt305x_spi_resources[] = {
241 .flags = IORESOURCE_MEM,
242 .start = RT305X_SPI_BASE,
243 .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
247 static struct platform_device rt305x_spi_device = {
248 .name = "ramips-spi",
250 .resource = rt305x_spi_resources,
251 .num_resources = ARRAY_SIZE(rt305x_spi_resources),
254 void __init rt305x_register_spi(struct spi_board_info *info, int n)
256 spi_register_board_info(info, n);
257 platform_device_register(&rt305x_spi_device);
260 static struct resource rt305x_usb_resources[] = {
262 .start = RT305X_OTG_BASE,
263 .end = RT305X_OTG_BASE + 0x3FFFF,
264 .flags = IORESOURCE_MEM,
266 .start = RT305X_INTC_IRQ_OTG,
267 .end = RT305X_INTC_IRQ_OTG,
268 .flags = IORESOURCE_IRQ,
272 static struct platform_device rt305x_usb_device = {
274 .resource = rt305x_usb_resources,
275 .num_resources = ARRAY_SIZE(rt305x_usb_resources),
277 .platform_data = NULL,
281 void __init rt305x_register_usb(void)
283 platform_device_register(&rt305x_usb_device);