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/rt2x00_platform.h>
19 #include <asm/addrspace.h>
21 #include <asm/mach-ralink/rt305x.h>
22 #include <asm/mach-ralink/rt305x_regs.h>
25 #include <ramips_eth_platform.h>
27 static struct resource rt305x_flash0_resources
[] = {
29 .flags
= IORESOURCE_MEM
,
30 .start
= KSEG1ADDR(RT305X_FLASH0_BASE
),
31 .end
= KSEG1ADDR(RT305X_FLASH0_BASE
) +
32 RT305X_FLASH0_SIZE
- 1,
36 static struct platform_device rt305x_flash0_device
= {
37 .name
= "physmap-flash",
38 .resource
= rt305x_flash0_resources
,
39 .num_resources
= ARRAY_SIZE(rt305x_flash0_resources
),
42 static struct resource rt305x_flash1_resources
[] = {
44 .flags
= IORESOURCE_MEM
,
45 .start
= KSEG1ADDR(RT305X_FLASH1_BASE
),
46 .end
= KSEG1ADDR(RT305X_FLASH1_BASE
) +
47 RT305X_FLASH1_SIZE
- 1,
51 static struct platform_device rt305x_flash1_device
= {
52 .name
= "physmap-flash",
53 .resource
= rt305x_flash1_resources
,
54 .num_resources
= ARRAY_SIZE(rt305x_flash1_resources
),
57 static int rt305x_flash_instance __initdata
;
58 void __init
rt305x_register_flash(unsigned int id
,
59 struct physmap_flash_data
*pdata
)
61 struct platform_device
*pdev
;
67 pdev
= &rt305x_flash0_device
;
68 reg
= MEMC_REG_FLASH_CFG0
;
71 pdev
= &rt305x_flash1_device
;
72 reg
= MEMC_REG_FLASH_CFG1
;
78 t
= rt305x_memc_rr(reg
);
79 t
= (t
>> FLASH_CFG_WIDTH_SHIFT
) & FLASH_CFG_WIDTH_MASK
;
82 case FLASH_CFG_WIDTH_8BIT
:
85 case FLASH_CFG_WIDTH_16BIT
:
88 case FLASH_CFG_WIDTH_32BIT
:
92 printk(KERN_ERR
"RT305x: flash bank%u witdh is invalid\n", id
);
96 pdev
->dev
.platform_data
= pdata
;
97 pdev
->id
= rt305x_flash_instance
;
99 platform_device_register(pdev
);
100 rt305x_flash_instance
++;
103 static void rt305x_fe_reset(void)
105 rt305x_sysc_wr(RT305X_RESET_FE
, SYSC_REG_RESET_CTRL
);
106 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL
);
109 static struct resource rt305x_eth_resources
[] = {
111 .start
= RT305X_FE_BASE
,
112 .end
= RT305X_FE_BASE
+ PAGE_SIZE
- 1,
113 .flags
= IORESOURCE_MEM
,
115 .start
= RT305X_CPU_IRQ_FE
,
116 .end
= RT305X_CPU_IRQ_FE
,
117 .flags
= IORESOURCE_IRQ
,
121 static struct ramips_eth_platform_data ramips_eth_data
= {
122 .mac
= { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
123 .reset_fe
= rt305x_fe_reset
,
127 static struct platform_device rt305x_eth_device
= {
128 .name
= "ramips_eth",
129 .resource
= rt305x_eth_resources
,
130 .num_resources
= ARRAY_SIZE(rt305x_eth_resources
),
132 .platform_data
= &ramips_eth_data
,
136 static struct resource rt305x_esw_resources
[] = {
138 .start
= RT305X_SWITCH_BASE
,
139 .end
= RT305X_SWITCH_BASE
+ PAGE_SIZE
- 1,
140 .flags
= IORESOURCE_MEM
,
144 struct rt305x_esw_platform_data rt305x_esw_data
;
145 static struct platform_device rt305x_esw_device
= {
146 .name
= "rt305x-esw",
147 .resource
= rt305x_esw_resources
,
148 .num_resources
= ARRAY_SIZE(rt305x_esw_resources
),
150 .platform_data
= &rt305x_esw_data
,
154 void __init
rt305x_register_ethernet(void)
158 clk
= clk_get(NULL
, "sys");
160 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk
));
162 ramips_eth_data
.sys_freq
= clk_get_rate(clk
);
164 platform_device_register(&rt305x_esw_device
);
165 platform_device_register(&rt305x_eth_device
);
168 static struct resource rt305x_wifi_resources
[] = {
170 .start
= RT305X_WMAC_BASE
,
171 .end
= RT305X_WMAC_BASE
+ 0x3FFFF,
172 .flags
= IORESOURCE_MEM
,
174 .start
= RT305X_CPU_IRQ_WNIC
,
175 .end
= RT305X_CPU_IRQ_WNIC
,
176 .flags
= IORESOURCE_IRQ
,
180 static struct rt2x00_platform_data rt305x_wifi_data
;
181 static struct platform_device rt305x_wifi_device
= {
182 .name
= "rt2800_wmac",
183 .resource
= rt305x_wifi_resources
,
184 .num_resources
= ARRAY_SIZE(rt305x_wifi_resources
),
186 .platform_data
= &rt305x_wifi_data
,
190 void __init
rt305x_register_wifi(void)
192 rt305x_wifi_data
.eeprom_file_name
= "RT305X.eeprom";
193 platform_device_register(&rt305x_wifi_device
);
196 static struct resource rt305x_wdt_resources
[] = {
198 .start
= RT305X_TIMER_BASE
,
199 .end
= RT305X_TIMER_BASE
+ RT305X_TIMER_SIZE
- 1,
200 .flags
= IORESOURCE_MEM
,
204 static struct platform_device rt305x_wdt_device
= {
205 .name
= "ramips-wdt",
207 .resource
= rt305x_wdt_resources
,
208 .num_resources
= ARRAY_SIZE(rt305x_wdt_resources
),
211 void __init
rt305x_register_wdt(void)
215 /* enable WDT reset output on pin SRAM_CS_N */
216 t
= rt305x_sysc_rr(SYSC_REG_SYSTEM_CONFIG
);
217 t
|= SYSTEM_CONFIG_SRAM_CS0_MODE_WDT
<<
218 SYSTEM_CONFIG_SRAM_CS0_MODE_SHIFT
;
219 rt305x_sysc_wr(t
, SYSC_REG_SYSTEM_CONFIG
);
221 platform_device_register(&rt305x_wdt_device
);