ramips: rt305x: remove per-board physmap_flash_data instances
[openwrt/svn-archive/archive.git] / target / linux / ramips / files / arch / mips / ralink / rt305x / devices.c
1 /*
2 * Ralink RT305x SoC platform device registration
3 *
4 * Copyright (C) 2009-2010 Gabor Juhos <juhosg@openwrt.org>
5 *
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.
9 */
10
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>
19
20 #include <asm/addrspace.h>
21
22 #include <asm/mach-ralink/rt305x.h>
23 #include <asm/mach-ralink/rt305x_regs.h>
24 #include "devices.h"
25
26 #include <ramips_eth_platform.h>
27 #include <rt305x_esw_platform.h>
28
29 static struct resource rt305x_flash0_resources[] = {
30 {
31 .flags = IORESOURCE_MEM,
32 .start = KSEG1ADDR(RT305X_FLASH0_BASE),
33 .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
34 RT305X_FLASH0_SIZE - 1,
35 },
36 };
37
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),
43 .dev = {
44 .platform_data = &rt305x_flash0_data,
45 },
46 };
47
48 static struct resource rt305x_flash1_resources[] = {
49 {
50 .flags = IORESOURCE_MEM,
51 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
52 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
53 RT305X_FLASH1_SIZE - 1,
54 },
55 };
56
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),
62 .dev = {
63 .platform_data = &rt305x_flash1_data,
64 },
65 };
66
67 static int rt305x_flash_instance __initdata;
68 void __init rt305x_register_flash(unsigned int id)
69 {
70 struct platform_device *pdev;
71 struct physmap_flash_data *pdata;
72 u32 t;
73 int reg;
74
75 switch (id) {
76 case 0:
77 pdev = &rt305x_flash0_device;
78 reg = MEMC_REG_FLASH_CFG0;
79 break;
80 case 1:
81 pdev = &rt305x_flash1_device;
82 reg = MEMC_REG_FLASH_CFG1;
83 break;
84 default:
85 return;
86 }
87
88 t = rt305x_memc_rr(reg);
89 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
90
91 pdata = pdev->dev.platform_data;
92 switch (t) {
93 case FLASH_CFG_WIDTH_8BIT:
94 pdata->width = 1;
95 break;
96 case FLASH_CFG_WIDTH_16BIT:
97 pdata->width = 2;
98 break;
99 case FLASH_CFG_WIDTH_32BIT:
100 pdata->width = 4;
101 break;
102 default:
103 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
104 return;
105 }
106
107 pdev->id = rt305x_flash_instance;
108
109 platform_device_register(pdev);
110 rt305x_flash_instance++;
111 }
112
113 static void rt305x_fe_reset(void)
114 {
115 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
116 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
117 }
118
119 static struct resource rt305x_eth_resources[] = {
120 {
121 .start = RT305X_FE_BASE,
122 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
123 .flags = IORESOURCE_MEM,
124 }, {
125 .start = RT305X_CPU_IRQ_FE,
126 .end = RT305X_CPU_IRQ_FE,
127 .flags = IORESOURCE_IRQ,
128 },
129 };
130
131 static struct ramips_eth_platform_data ramips_eth_data = {
132 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
133 .reset_fe = rt305x_fe_reset,
134 .min_pkt_len = 64,
135 };
136
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),
141 .dev = {
142 .platform_data = &ramips_eth_data,
143 }
144 };
145
146 static struct resource rt305x_esw_resources[] = {
147 {
148 .start = RT305X_SWITCH_BASE,
149 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
150 .flags = IORESOURCE_MEM,
151 },
152 };
153
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,
158 };
159
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),
164 .dev = {
165 .platform_data = &rt305x_esw_data,
166 }
167 };
168
169 void __init rt305x_register_ethernet(void)
170 {
171 struct clk *clk;
172
173 clk = clk_get(NULL, "sys");
174 if (IS_ERR(clk))
175 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
176
177 ramips_eth_data.sys_freq = clk_get_rate(clk);
178
179 platform_device_register(&rt305x_esw_device);
180 platform_device_register(&rt305x_eth_device);
181 }
182
183 static struct resource rt305x_wifi_resources[] = {
184 {
185 .start = RT305X_WMAC_BASE,
186 .end = RT305X_WMAC_BASE + 0x3FFFF,
187 .flags = IORESOURCE_MEM,
188 }, {
189 .start = RT305X_CPU_IRQ_WNIC,
190 .end = RT305X_CPU_IRQ_WNIC,
191 .flags = IORESOURCE_IRQ,
192 },
193 };
194
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),
200 .dev = {
201 .platform_data = &rt305x_wifi_data,
202 }
203 };
204
205 void __init rt305x_register_wifi(void)
206 {
207 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
208 platform_device_register(&rt305x_wifi_device);
209 }
210
211 static struct resource rt305x_wdt_resources[] = {
212 {
213 .start = RT305X_TIMER_BASE,
214 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
215 .flags = IORESOURCE_MEM,
216 },
217 };
218
219 static struct platform_device rt305x_wdt_device = {
220 .name = "ramips-wdt",
221 .id = -1,
222 .resource = rt305x_wdt_resources,
223 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
224 };
225
226 void __init rt305x_register_wdt(void)
227 {
228 u32 t;
229
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);
235
236 platform_device_register(&rt305x_wdt_device);
237 }
238
239 static struct resource rt305x_spi_resources[] = {
240 {
241 .flags = IORESOURCE_MEM,
242 .start = RT305X_SPI_BASE,
243 .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
244 },
245 };
246
247 static struct platform_device rt305x_spi_device = {
248 .name = "ramips-spi",
249 .id = 0,
250 .resource = rt305x_spi_resources,
251 .num_resources = ARRAY_SIZE(rt305x_spi_resources),
252 };
253
254 void __init rt305x_register_spi(struct spi_board_info *info, int n)
255 {
256 spi_register_board_info(info, n);
257 platform_device_register(&rt305x_spi_device);
258 }
259
260 static struct resource rt305x_usb_resources[] = {
261 {
262 .start = RT305X_OTG_BASE,
263 .end = RT305X_OTG_BASE + 0x3FFFF,
264 .flags = IORESOURCE_MEM,
265 }, {
266 .start = RT305X_INTC_IRQ_OTG,
267 .end = RT305X_INTC_IRQ_OTG,
268 .flags = IORESOURCE_IRQ,
269 },
270 };
271
272 static struct platform_device rt305x_usb_device = {
273 .name = "dwc_otg",
274 .resource = rt305x_usb_resources,
275 .num_resources = ARRAY_SIZE(rt305x_usb_resources),
276 .dev = {
277 .platform_data = NULL,
278 }
279 };
280
281 void __init rt305x_register_usb(void)
282 {
283 platform_device_register(&rt305x_usb_device);
284 }