ramips: initial support for Sitecom WL-351 v1 002
[openwrt/openwrt.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 static struct platform_device rt305x_flash0_device = {
39 .name = "physmap-flash",
40 .resource = rt305x_flash0_resources,
41 .num_resources = ARRAY_SIZE(rt305x_flash0_resources),
42 };
43
44 static struct resource rt305x_flash1_resources[] = {
45 {
46 .flags = IORESOURCE_MEM,
47 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
48 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
49 RT305X_FLASH1_SIZE - 1,
50 },
51 };
52
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),
57 };
58
59 static int rt305x_flash_instance __initdata;
60 void __init rt305x_register_flash(unsigned int id,
61 struct physmap_flash_data *pdata)
62 {
63 struct platform_device *pdev;
64 u32 t;
65 int reg;
66
67 switch (id) {
68 case 0:
69 pdev = &rt305x_flash0_device;
70 reg = MEMC_REG_FLASH_CFG0;
71 break;
72 case 1:
73 pdev = &rt305x_flash1_device;
74 reg = MEMC_REG_FLASH_CFG1;
75 break;
76 default:
77 return;
78 }
79
80 t = rt305x_memc_rr(reg);
81 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
82
83 switch (t) {
84 case FLASH_CFG_WIDTH_8BIT:
85 pdata->width = 1;
86 break;
87 case FLASH_CFG_WIDTH_16BIT:
88 pdata->width = 2;
89 break;
90 case FLASH_CFG_WIDTH_32BIT:
91 pdata->width = 4;
92 break;
93 default:
94 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
95 return;
96 }
97
98 pdev->dev.platform_data = pdata;
99 pdev->id = rt305x_flash_instance;
100
101 platform_device_register(pdev);
102 rt305x_flash_instance++;
103 }
104
105 static void rt305x_fe_reset(void)
106 {
107 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
108 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
109 }
110
111 static struct resource rt305x_eth_resources[] = {
112 {
113 .start = RT305X_FE_BASE,
114 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
115 .flags = IORESOURCE_MEM,
116 }, {
117 .start = RT305X_CPU_IRQ_FE,
118 .end = RT305X_CPU_IRQ_FE,
119 .flags = IORESOURCE_IRQ,
120 },
121 };
122
123 static struct ramips_eth_platform_data ramips_eth_data = {
124 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
125 .reset_fe = rt305x_fe_reset,
126 .min_pkt_len = 64,
127 };
128
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),
133 .dev = {
134 .platform_data = &ramips_eth_data,
135 }
136 };
137
138 static struct resource rt305x_esw_resources[] = {
139 {
140 .start = RT305X_SWITCH_BASE,
141 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
142 .flags = IORESOURCE_MEM,
143 },
144 };
145
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,
150 };
151
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),
156 .dev = {
157 .platform_data = &rt305x_esw_data,
158 }
159 };
160
161 void __init rt305x_register_ethernet(void)
162 {
163 struct clk *clk;
164
165 clk = clk_get(NULL, "sys");
166 if (IS_ERR(clk))
167 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
168
169 ramips_eth_data.sys_freq = clk_get_rate(clk);
170
171 platform_device_register(&rt305x_esw_device);
172 platform_device_register(&rt305x_eth_device);
173 }
174
175 static struct resource rt305x_wifi_resources[] = {
176 {
177 .start = RT305X_WMAC_BASE,
178 .end = RT305X_WMAC_BASE + 0x3FFFF,
179 .flags = IORESOURCE_MEM,
180 }, {
181 .start = RT305X_CPU_IRQ_WNIC,
182 .end = RT305X_CPU_IRQ_WNIC,
183 .flags = IORESOURCE_IRQ,
184 },
185 };
186
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),
192 .dev = {
193 .platform_data = &rt305x_wifi_data,
194 }
195 };
196
197 void __init rt305x_register_wifi(void)
198 {
199 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
200 platform_device_register(&rt305x_wifi_device);
201 }
202
203 static struct resource rt305x_wdt_resources[] = {
204 {
205 .start = RT305X_TIMER_BASE,
206 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
207 .flags = IORESOURCE_MEM,
208 },
209 };
210
211 static struct platform_device rt305x_wdt_device = {
212 .name = "ramips-wdt",
213 .id = -1,
214 .resource = rt305x_wdt_resources,
215 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
216 };
217
218 void __init rt305x_register_wdt(void)
219 {
220 u32 t;
221
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);
227
228 platform_device_register(&rt305x_wdt_device);
229 }
230
231 static struct resource rt305x_spi_resources[] = {
232 {
233 .flags = IORESOURCE_MEM,
234 .start = RT305X_SPI_BASE,
235 .end = RT305X_SPI_BASE + RT305X_SPI_SIZE - 1,
236 },
237 };
238
239 static struct platform_device rt305x_spi_device = {
240 .name = "ramips-spi",
241 .id = 0,
242 .resource = rt305x_spi_resources,
243 .num_resources = ARRAY_SIZE(rt305x_spi_resources),
244 };
245
246 void __init rt305x_register_spi(struct spi_board_info *info, int n)
247 {
248 spi_register_board_info(info, n);
249 platform_device_register(&rt305x_spi_device);
250 }
251
252 static struct resource rt305x_usb_resources[] = {
253 {
254 .start = RT305X_OTG_BASE,
255 .end = RT305X_OTG_BASE + 0x3FFFF,
256 .flags = IORESOURCE_MEM,
257 }, {
258 .start = RT305X_INTC_IRQ_OTG,
259 .end = RT305X_INTC_IRQ_OTG,
260 .flags = IORESOURCE_IRQ,
261 },
262 };
263
264 static struct platform_device rt305x_usb_device = {
265 .name = "dwc_otg",
266 .resource = rt305x_usb_resources,
267 .num_resources = ARRAY_SIZE(rt305x_usb_resources),
268 .dev = {
269 .platform_data = NULL,
270 }
271 };
272
273 void __init rt305x_register_usb(void)
274 {
275 platform_device_register(&rt305x_usb_device);
276 }