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>
28 static struct resource rt305x_flash0_resources
[] = {
30 .flags
= IORESOURCE_MEM
,
31 .start
= KSEG1ADDR(RT305X_FLASH0_BASE
),
32 .end
= KSEG1ADDR(RT305X_FLASH0_BASE
) +
33 RT305X_FLASH0_SIZE
- 1,
37 static struct platform_device rt305x_flash0_device
= {
38 .name
= "physmap-flash",
39 .resource
= rt305x_flash0_resources
,
40 .num_resources
= ARRAY_SIZE(rt305x_flash0_resources
),
43 static struct resource rt305x_flash1_resources
[] = {
45 .flags
= IORESOURCE_MEM
,
46 .start
= KSEG1ADDR(RT305X_FLASH1_BASE
),
47 .end
= KSEG1ADDR(RT305X_FLASH1_BASE
) +
48 RT305X_FLASH1_SIZE
- 1,
52 static struct platform_device rt305x_flash1_device
= {
53 .name
= "physmap-flash",
54 .resource
= rt305x_flash1_resources
,
55 .num_resources
= ARRAY_SIZE(rt305x_flash1_resources
),
58 static int rt305x_flash_instance __initdata
;
59 void __init
rt305x_register_flash(unsigned int id
,
60 struct physmap_flash_data
*pdata
)
62 struct platform_device
*pdev
;
68 pdev
= &rt305x_flash0_device
;
69 reg
= MEMC_REG_FLASH_CFG0
;
72 pdev
= &rt305x_flash1_device
;
73 reg
= MEMC_REG_FLASH_CFG1
;
79 t
= rt305x_memc_rr(reg
);
80 t
= (t
>> FLASH_CFG_WIDTH_SHIFT
) & FLASH_CFG_WIDTH_MASK
;
83 case FLASH_CFG_WIDTH_8BIT
:
86 case FLASH_CFG_WIDTH_16BIT
:
89 case FLASH_CFG_WIDTH_32BIT
:
93 printk(KERN_ERR
"RT305x: flash bank%u witdh is invalid\n", id
);
97 pdev
->dev
.platform_data
= pdata
;
98 pdev
->id
= rt305x_flash_instance
;
100 platform_device_register(pdev
);
101 rt305x_flash_instance
++;
104 static void rt305x_fe_reset(void)
106 rt305x_sysc_wr(RT305X_RESET_FE
, SYSC_REG_RESET_CTRL
);
107 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL
);
110 static struct resource rt305x_eth_resources
[] = {
112 .start
= RT305X_FE_BASE
,
113 .end
= RT305X_FE_BASE
+ PAGE_SIZE
- 1,
114 .flags
= IORESOURCE_MEM
,
116 .start
= RT305X_CPU_IRQ_FE
,
117 .end
= RT305X_CPU_IRQ_FE
,
118 .flags
= IORESOURCE_IRQ
,
122 static struct ramips_eth_platform_data ramips_eth_data
= {
123 .mac
= { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
124 .reset_fe
= rt305x_fe_reset
,
128 static struct platform_device rt305x_eth_device
= {
129 .name
= "ramips_eth",
130 .resource
= rt305x_eth_resources
,
131 .num_resources
= ARRAY_SIZE(rt305x_eth_resources
),
133 .platform_data
= &ramips_eth_data
,
137 static struct resource rt305x_esw_resources
[] = {
139 .start
= RT305X_SWITCH_BASE
,
140 .end
= RT305X_SWITCH_BASE
+ PAGE_SIZE
- 1,
141 .flags
= IORESOURCE_MEM
,
145 struct rt305x_esw_platform_data rt305x_esw_data
;
146 static struct platform_device rt305x_esw_device
= {
147 .name
= "rt305x-esw",
148 .resource
= rt305x_esw_resources
,
149 .num_resources
= ARRAY_SIZE(rt305x_esw_resources
),
151 .platform_data
= &rt305x_esw_data
,
155 void __init
rt305x_register_ethernet(void)
159 clk
= clk_get(NULL
, "sys");
161 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk
));
163 ramips_eth_data
.sys_freq
= clk_get_rate(clk
);
165 platform_device_register(&rt305x_esw_device
);
166 platform_device_register(&rt305x_eth_device
);
169 static struct resource rt305x_wifi_resources
[] = {
171 .start
= RT305X_WMAC_BASE
,
172 .end
= RT305X_WMAC_BASE
+ 0x3FFFF,
173 .flags
= IORESOURCE_MEM
,
175 .start
= RT305X_CPU_IRQ_WNIC
,
176 .end
= RT305X_CPU_IRQ_WNIC
,
177 .flags
= IORESOURCE_IRQ
,
181 static struct rt2x00_platform_data rt305x_wifi_data
;
182 static struct platform_device rt305x_wifi_device
= {
183 .name
= "rt2800_wmac",
184 .resource
= rt305x_wifi_resources
,
185 .num_resources
= ARRAY_SIZE(rt305x_wifi_resources
),
187 .platform_data
= &rt305x_wifi_data
,
191 void __init
rt305x_register_wifi(void)
193 rt305x_wifi_data
.eeprom_file_name
= "RT305X.eeprom";
194 platform_device_register(&rt305x_wifi_device
);
197 static struct resource rt305x_wdt_resources
[] = {
199 .start
= RT305X_TIMER_BASE
,
200 .end
= RT305X_TIMER_BASE
+ RT305X_TIMER_SIZE
- 1,
201 .flags
= IORESOURCE_MEM
,
205 static struct platform_device rt305x_wdt_device
= {
206 .name
= "ramips-wdt",
208 .resource
= rt305x_wdt_resources
,
209 .num_resources
= ARRAY_SIZE(rt305x_wdt_resources
),
212 void __init
rt305x_register_wdt(void)
216 /* enable WDT reset output on pin SRAM_CS_N */
217 t
= rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG
);
218 t
|= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT
<<
219 SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT
;
220 rt305x_sysc_wr(t
, SYSC_REG_SYSTEM_CONFIG
);
222 platform_device_register(&rt305x_wdt_device
);
225 static struct resource rt305x_spi_resources
[] = {
227 .flags
= IORESOURCE_MEM
,
228 .start
= RT305X_SPI_BASE
,
229 .end
= RT305X_SPI_BASE
+ RT305X_SPI_SIZE
- 1,
233 static struct platform_device rt305x_spi_device
= {
234 .name
= "ramips-spi",
236 .resource
= rt305x_spi_resources
,
237 .num_resources
= ARRAY_SIZE(rt305x_spi_resources
),
240 void __init
rt305x_register_spi(struct spi_board_info
*info
, int n
)
242 spi_register_board_info(info
, n
);
243 platform_device_register(&rt305x_spi_device
);
246 static struct resource rt305x_usb_resources
[] = {
248 .start
= RT305X_OTG_BASE
,
249 .end
= RT305X_OTG_BASE
+ 0x3FFFF,
250 .flags
= IORESOURCE_MEM
,
252 .start
= RT305X_INTC_IRQ_OTG
,
253 .end
= RT305X_INTC_IRQ_OTG
,
254 .flags
= IORESOURCE_IRQ
,
258 static struct platform_device rt305x_usb_device
= {
260 .resource
= rt305x_usb_resources
,
261 .num_resources
= ARRAY_SIZE(rt305x_usb_resources
),
263 .platform_data
= NULL
,
267 void __init
rt305x_register_usb(void)
269 platform_device_register(&rt305x_usb_device
);