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>
18 #include <asm/addrspace.h>
20 #include <asm/mach-ralink/rt305x.h>
21 #include <asm/mach-ralink/rt305x_regs.h>
24 #include <ramips_eth_platform.h>
26 static struct resource rt305x_flash0_resources
[] = {
28 .flags
= IORESOURCE_MEM
,
29 .start
= KSEG1ADDR(RT305X_FLASH0_BASE
),
30 .end
= KSEG1ADDR(RT305X_FLASH0_BASE
) +
31 RT305X_FLASH0_SIZE
- 1,
35 static struct platform_device rt305x_flash0_device
= {
36 .name
= "physmap-flash",
37 .resource
= rt305x_flash0_resources
,
38 .num_resources
= ARRAY_SIZE(rt305x_flash0_resources
),
41 static struct resource rt305x_flash1_resources
[] = {
43 .flags
= IORESOURCE_MEM
,
44 .start
= KSEG1ADDR(RT305X_FLASH1_BASE
),
45 .end
= KSEG1ADDR(RT305X_FLASH1_BASE
) +
46 RT305X_FLASH1_SIZE
- 1,
50 static struct platform_device rt305x_flash1_device
= {
51 .name
= "physmap-flash",
52 .resource
= rt305x_flash1_resources
,
53 .num_resources
= ARRAY_SIZE(rt305x_flash1_resources
),
56 static int rt305x_flash_instance __initdata
;
57 void __init
rt305x_register_flash(unsigned int id
,
58 struct physmap_flash_data
*pdata
)
60 struct platform_device
*pdev
;
66 pdev
= &rt305x_flash0_device
;
67 reg
= MEMC_REG_FLASH_CFG0
;
70 pdev
= &rt305x_flash1_device
;
71 reg
= MEMC_REG_FLASH_CFG1
;
77 t
= rt305x_memc_rr(reg
);
78 t
= (t
>> FLASH_CFG_WIDTH_SHIFT
) & FLASH_CFG_WIDTH_MASK
;
81 case FLASH_CFG_WIDTH_8BIT
:
84 case FLASH_CFG_WIDTH_16BIT
:
87 case FLASH_CFG_WIDTH_32BIT
:
91 printk(KERN_ERR
"RT305x: flash bank%u witdh is invalid\n", id
);
95 pdev
->dev
.platform_data
= pdata
;
96 pdev
->id
= rt305x_flash_instance
;
98 platform_device_register(pdev
);
99 rt305x_flash_instance
++;
102 static void rt305x_fe_reset(void)
104 rt305x_sysc_wr(RT305X_RESET_FE
, SYSC_REG_RESET_CTRL
);
105 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL
);
108 static struct resource rt305x_eth_resources
[] = {
110 .start
= RT305X_FE_BASE
,
111 .end
= RT305X_FE_BASE
+ PAGE_SIZE
- 1,
112 .flags
= IORESOURCE_MEM
,
114 .start
= RT305X_CPU_IRQ_FE
,
115 .end
= RT305X_CPU_IRQ_FE
,
116 .flags
= IORESOURCE_IRQ
,
120 static struct ramips_eth_platform_data ramips_eth_data
= {
121 .mac
= { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
122 .reset_fe
= rt305x_fe_reset
,
126 static struct platform_device rt305x_eth_device
= {
127 .name
= "ramips_eth",
128 .resource
= rt305x_eth_resources
,
129 .num_resources
= ARRAY_SIZE(rt305x_eth_resources
),
131 .platform_data
= &ramips_eth_data
,
135 static struct resource rt305x_esw_resources
[] = {
137 .start
= RT305X_SWITCH_BASE
,
138 .end
= RT305X_SWITCH_BASE
+ PAGE_SIZE
- 1,
139 .flags
= IORESOURCE_MEM
,
143 struct rt305x_esw_platform_data rt305x_esw_data
;
144 static struct platform_device rt305x_esw_device
= {
145 .name
= "rt305x-esw",
146 .resource
= rt305x_esw_resources
,
147 .num_resources
= ARRAY_SIZE(rt305x_esw_resources
),
149 .platform_data
= &rt305x_esw_data
,
153 void __init
rt305x_register_ethernet(void)
157 clk
= clk_get(NULL
, "sys");
159 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk
));
161 ramips_eth_data
.sys_freq
= clk_get_rate(clk
);
163 platform_device_register(&rt305x_esw_device
);
164 platform_device_register(&rt305x_eth_device
);
167 static struct resource rt305x_wifi_resources
[] = {
169 .start
= RT305X_WMAC_BASE
,
170 .end
= RT305X_WMAC_BASE
+ 0x3FFFF,
171 .flags
= IORESOURCE_MEM
,
173 .start
= RT305X_CPU_IRQ_WNIC
,
174 .end
= RT305X_CPU_IRQ_WNIC
,
175 .flags
= IORESOURCE_IRQ
,
179 static struct platform_device rt305x_wifi_device
= {
180 .name
= "rt2800_wmac",
181 .resource
= rt305x_wifi_resources
,
182 .num_resources
= ARRAY_SIZE(rt305x_wifi_resources
),
184 .platform_data
= NULL
,
188 void __init
rt305x_register_wifi(void)
190 platform_device_register(&rt305x_wifi_device
);