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 static struct platform_device rt305x_flash0_device = {
39 .name = "physmap-flash",
40 .resource = rt305x_flash0_resources,
41 .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
44 static struct resource rt305x_flash1_resources[] = {
46 .flags = IORESOURCE_MEM,
47 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
48 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
49 RT305X_FLASH1_SIZE - 1,
53 static struct platform_device rt305x_flash1_device = {
54 .name = "physmap-flash",
55 .resource = rt305x_flash1_resources,
56 .num_resources = ARRAY_SIZE(rt305x_flash1_resources),
59 static int rt305x_flash_instance __initdata;
60 void __init rt305x_register_flash(unsigned int id,
61 struct physmap_flash_data *pdata)
63 struct platform_device *pdev;
69 pdev = &rt305x_flash0_device;
70 reg = MEMC_REG_FLASH_CFG0;
73 pdev = &rt305x_flash1_device;
74 reg = MEMC_REG_FLASH_CFG1;
80 t = rt305x_memc_rr(reg);
81 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
84 case FLASH_CFG_WIDTH_8BIT:
87 case FLASH_CFG_WIDTH_16BIT:
90 case FLASH_CFG_WIDTH_32BIT:
94 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
98 pdev->dev.platform_data = pdata;
99 pdev->id = rt305x_flash_instance;
101 platform_device_register(pdev);
102 rt305x_flash_instance++;
105 static void rt305x_fe_reset(void)
107 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
108 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
111 static struct resource rt305x_eth_resources[] = {
113 .start = RT305X_FE_BASE,
114 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
115 .flags = IORESOURCE_MEM,
117 .start = RT305X_CPU_IRQ_FE,
118 .end = RT305X_CPU_IRQ_FE,
119 .flags = IORESOURCE_IRQ,
123 static struct ramips_eth_platform_data ramips_eth_data = {
124 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
125 .reset_fe = rt305x_fe_reset,
129 static struct platform_device rt305x_eth_device = {
130 .name = "ramips_eth",
131 .resource = rt305x_eth_resources,
132 .num_resources = ARRAY_SIZE(rt305x_eth_resources),
134 .platform_data = &ramips_eth_data,
138 static struct resource rt305x_esw_resources[] = {
140 .start = RT305X_SWITCH_BASE,
141 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
142 .flags = IORESOURCE_MEM,
146 struct rt305x_esw_platform_data rt305x_esw_data = {
147 .vlan_config = RT305X_ESW_VLAN_CONFIG_NONE,
148 .reg_initval_fct2 = 0x00d6500c,
149 .reg_initval_fpa2 = 0x3f502b28,
152 static struct platform_device rt305x_esw_device = {
153 .name = "rt305x-esw",
154 .resource = rt305x_esw_resources,
155 .num_resources = ARRAY_SIZE(rt305x_esw_resources),
157 .platform_data = &rt305x_esw_data,
161 void __init rt305x_register_ethernet(void)
165 clk = clk_get(NULL, "sys");
167 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
169 ramips_eth_data.sys_freq = clk_get_rate(clk);
171 platform_device_register(&rt305x_esw_device);
172 platform_device_register(&rt305x_eth_device);
175 static struct resource rt305x_wifi_resources[] = {
177 .start = RT305X_WMAC_BASE,
178 .end = RT305X_WMAC_BASE + 0x3FFFF,
179 .flags = IORESOURCE_MEM,
181 .start = RT305X_CPU_IRQ_WNIC,
182 .end = RT305X_CPU_IRQ_WNIC,
183 .flags = IORESOURCE_IRQ,
187 static struct rt2x00_platform_data rt305x_wifi_data;
188 static struct platform_device rt305x_wifi_device = {
189 .name = "rt2800_wmac",
190 .resource = rt305x_wifi_resources,
191 .num_resources = ARRAY_SIZE(rt305x_wifi_resources),
193 .platform_data = &rt305x_wifi_data,
197 void __init rt305x_register_wifi(void)
199 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
200 platform_device_register(&rt305x_wifi_device);
203 static struct resource rt305x_wdt_resources[] = {
205 .start = RT305X_TIMER_BASE,
206 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
207 .flags = IORESOURCE_MEM,
211 static struct platform_device rt305x_wdt_device = {
212 .name = "ramips-wdt",
214 .resource = rt305x_wdt_resources,
215 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
218 void __init rt305x_register_wdt(void)
222 /* enable WDT reset output on pin SRAM_CS_N */
223 t = rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG);
224 t |= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT <<
225 SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT;
226 rt305x_sysc_wr(t, SYSC_REG_SYSTEM_CONFIG);
228 platform_device_register(&rt305x_wdt_device);
231 static struct resource rt305x_spi_resources[] = {
233 .flags = IORESOURCE_MEM,
234 .start = RT305X_SPI_BASE,
235 .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
239 static struct platform_device rt305x_spi_device = {
240 .name = "ramips-spi",
242 .resource = rt305x_spi_resources,
243 .num_resources = ARRAY_SIZE(rt305x_spi_resources),
246 void __init rt305x_register_spi(struct spi_board_info *info, int n)
248 spi_register_board_info(info, n);
249 platform_device_register(&rt305x_spi_device);
252 static struct resource rt305x_usb_resources[] = {
254 .start = RT305X_OTG_BASE,
255 .end = RT305X_OTG_BASE + 0x3FFFF,
256 .flags = IORESOURCE_MEM,
258 .start = RT305X_INTC_IRQ_OTG,
259 .end = RT305X_INTC_IRQ_OTG,
260 .flags = IORESOURCE_IRQ,
264 static struct platform_device rt305x_usb_device = {
266 .resource = rt305x_usb_resources,
267 .num_resources = ARRAY_SIZE(rt305x_usb_resources),
269 .platform_data = NULL,
273 void __init rt305x_register_usb(void)
275 platform_device_register(&rt305x_usb_device);