ramips: specify eeprom file name on RT305X
[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/rt2x00_platform.h>
18
19 #include <asm/addrspace.h>
20
21 #include <asm/mach-ralink/rt305x.h>
22 #include <asm/mach-ralink/rt305x_regs.h>
23 #include "devices.h"
24
25 #include <ramips_eth_platform.h>
26
27 static struct resource rt305x_flash0_resources[] = {
28 {
29 .flags = IORESOURCE_MEM,
30 .start = KSEG1ADDR(RT305X_FLASH0_BASE),
31 .end = KSEG1ADDR(RT305X_FLASH0_BASE) +
32 RT305X_FLASH0_SIZE - 1,
33 },
34 };
35
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),
40 };
41
42 static struct resource rt305x_flash1_resources[] = {
43 {
44 .flags = IORESOURCE_MEM,
45 .start = KSEG1ADDR(RT305X_FLASH1_BASE),
46 .end = KSEG1ADDR(RT305X_FLASH1_BASE) +
47 RT305X_FLASH1_SIZE - 1,
48 },
49 };
50
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),
55 };
56
57 static int rt305x_flash_instance __initdata;
58 void __init rt305x_register_flash(unsigned int id,
59 struct physmap_flash_data *pdata)
60 {
61 struct platform_device *pdev;
62 u32 t;
63 int reg;
64
65 switch (id) {
66 case 0:
67 pdev = &rt305x_flash0_device;
68 reg = MEMC_REG_FLASH_CFG0;
69 break;
70 case 1:
71 pdev = &rt305x_flash1_device;
72 reg = MEMC_REG_FLASH_CFG1;
73 break;
74 default:
75 return;
76 }
77
78 t = rt305x_memc_rr(reg);
79 t = (t >> FLASH_CFG_WIDTH_SHIFT) & FLASH_CFG_WIDTH_MASK;
80
81 switch (t) {
82 case FLASH_CFG_WIDTH_8BIT:
83 pdata->width = 1;
84 break;
85 case FLASH_CFG_WIDTH_16BIT:
86 pdata->width = 2;
87 break;
88 case FLASH_CFG_WIDTH_32BIT:
89 pdata->width = 4;
90 break;
91 default:
92 printk(KERN_ERR "RT305x: flash bank%u witdh is invalid\n", id);
93 return;
94 }
95
96 pdev->dev.platform_data = pdata;
97 pdev->id = rt305x_flash_instance;
98
99 platform_device_register(pdev);
100 rt305x_flash_instance++;
101 }
102
103 static void rt305x_fe_reset(void)
104 {
105 rt305x_sysc_wr(RT305X_RESET_FE, SYSC_REG_RESET_CTRL);
106 rt305x_sysc_wr(0, SYSC_REG_RESET_CTRL);
107 }
108
109 static struct resource rt305x_eth_resources[] = {
110 {
111 .start = RT305X_FE_BASE,
112 .end = RT305X_FE_BASE + PAGE_SIZE - 1,
113 .flags = IORESOURCE_MEM,
114 }, {
115 .start = RT305X_CPU_IRQ_FE,
116 .end = RT305X_CPU_IRQ_FE,
117 .flags = IORESOURCE_IRQ,
118 },
119 };
120
121 static struct ramips_eth_platform_data ramips_eth_data = {
122 .mac = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 },
123 .reset_fe = rt305x_fe_reset,
124 .min_pkt_len = 64,
125 };
126
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),
131 .dev = {
132 .platform_data = &ramips_eth_data,
133 }
134 };
135
136 static struct resource rt305x_esw_resources[] = {
137 {
138 .start = RT305X_SWITCH_BASE,
139 .end = RT305X_SWITCH_BASE + PAGE_SIZE - 1,
140 .flags = IORESOURCE_MEM,
141 },
142 };
143
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),
149 .dev = {
150 .platform_data = &rt305x_esw_data,
151 }
152 };
153
154 void __init rt305x_register_ethernet(void)
155 {
156 struct clk *clk;
157
158 clk = clk_get(NULL, "sys");
159 if (IS_ERR(clk))
160 panic("unable to get SYS clock, err=%ld", PTR_ERR(clk));
161
162 ramips_eth_data.sys_freq = clk_get_rate(clk);
163
164 platform_device_register(&rt305x_esw_device);
165 platform_device_register(&rt305x_eth_device);
166 }
167
168 static struct resource rt305x_wifi_resources[] = {
169 {
170 .start = RT305X_WMAC_BASE,
171 .end = RT305X_WMAC_BASE + 0x3FFFF,
172 .flags = IORESOURCE_MEM,
173 }, {
174 .start = RT305X_CPU_IRQ_WNIC,
175 .end = RT305X_CPU_IRQ_WNIC,
176 .flags = IORESOURCE_IRQ,
177 },
178 };
179
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),
185 .dev = {
186 .platform_data = &rt305x_wifi_data,
187 }
188 };
189
190 void __init rt305x_register_wifi(void)
191 {
192 rt305x_wifi_data.eeprom_file_name = "RT305X.eeprom";
193 platform_device_register(&rt305x_wifi_device);
194 }
195
196 static struct resource rt305x_wdt_resources[] = {
197 {
198 .start = RT305X_TIMER_BASE,
199 .end = RT305X_TIMER_BASE + RT305X_TIMER_SIZE - 1,
200 .flags = IORESOURCE_MEM,
201 },
202 };
203
204 static struct platform_device rt305x_wdt_device = {
205 .name = "ramips-wdt",
206 .id = -1,
207 .resource = rt305x_wdt_resources,
208 .num_resources = ARRAY_SIZE(rt305x_wdt_resources),
209 };
210
211 void __init rt305x_register_wdt(void)
212 {
213 u32 t;
214
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);
220
221 platform_device_register(&rt305x_wdt_device);
222 }