[rdc] add a new southbridge driver which registers the gpio and watchdog platform...
[openwrt/svn-archive/archive.git] / target / linux / rdc / files-2.6.30 / arch / x86 / mach-rdc321x / platform.c
1 /*
2 * Generic RDC321x platform devices
3 *
4 * Copyright (C) 2007-2009 OpenWrt.org
5 * Copyright (C) 2007 Florian Fainelli <florian@openwrt.org>
6 * Copyright (C) 2008-2009 Daniel Gimpelevich <daniel@gimpelevich.san-francisco.ca.us>
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25 #include <linux/init.h>
26 #include <linux/kernel.h>
27 #include <linux/list.h>
28 #include <linux/device.h>
29 #include <linux/platform_device.h>
30 #include <linux/version.h>
31 #include <linux/leds.h>
32 #include <linux/gpio_keys.h>
33 #include <linux/input.h>
34 #include <linux/mtd/map.h>
35 #include <linux/mtd/mtd.h>
36 #include <linux/mtd/physmap.h>
37 #include <linux/root_dev.h>
38
39 #include <asm/rdc321x_gpio.h>
40
41 /* Flash */
42 #ifdef CONFIG_MTD_R8610
43 #define CONFIG_MTD_RDC3210 1
44 #elif defined CONFIG_MTD_RDC3210
45 static struct resource rdc_flash_resource[] = {
46 [0] = {
47 .start = (u32)-CONFIG_MTD_RDC3210_SIZE,
48 .end = (u32)-1,
49 .flags = IORESOURCE_MEM,
50 },
51 };
52
53 static struct platform_device rdc_flash_device = {
54 .name = "rdc321x-flash",
55 .id = -1,
56 .num_resources = ARRAY_SIZE(rdc_flash_resource),
57 .resource = rdc_flash_resource,
58 };
59 #else
60 static struct mtd_partition rdc_flash_parts[15];
61
62 static struct resource rdc_flash_resource = {
63 .end = (u32)-1,
64 .flags = IORESOURCE_MEM,
65 };
66
67 static struct physmap_flash_data rdc_flash_data = {
68 .parts = rdc_flash_parts,
69 };
70
71 static struct platform_device rdc_flash_device = {
72 .name = "physmap-flash",
73 .id = -1,
74 .resource = &rdc_flash_resource,
75 .num_resources = 1,
76 .dev.platform_data = &rdc_flash_data,
77 };
78 #endif
79
80 /* LEDS */
81 static struct gpio_led default_leds[] = {
82 { .name = "rdc321x:dmz", .gpio = 1, .active_low = 1},
83 };
84
85 static struct gpio_led_platform_data rdc321x_led_data = {
86 .num_leds = ARRAY_SIZE(default_leds),
87 .leds = default_leds,
88 };
89
90 static struct platform_device rdc321x_leds = {
91 .name = "leds-gpio",
92 .id = -1,
93 .dev = {
94 .platform_data = &rdc321x_led_data,
95 }
96 };
97
98 /* Button */
99 static struct gpio_keys_button rdc321x_gpio_btn[] = {
100 {
101 .gpio = 0,
102 .code = BTN_0,
103 .desc = "Reset",
104 .active_low = 1,
105 }
106 };
107
108 static struct gpio_keys_platform_data rdc321x_gpio_btn_data = {
109 .buttons = rdc321x_gpio_btn,
110 .nbuttons = ARRAY_SIZE(rdc321x_gpio_btn),
111 };
112
113 static struct platform_device rdc321x_button = {
114 .name = "gpio-keys",
115 .id = -1,
116 .dev = {
117 .platform_data = &rdc321x_gpio_btn_data,
118 }
119 };
120
121 static struct platform_device *rdc321x_devs[] = {
122 &rdc_flash_device,
123 &rdc321x_leds,
124 &rdc321x_button,
125 };
126
127 static int probe_flash_start(struct map_info *the_map)
128 {
129 struct mtd_info *res;
130
131 the_map->virt = ioremap(the_map->phys, the_map->size);
132 if (the_map->virt == NULL)
133 return 1;
134 for (the_map->bankwidth = 32; the_map->bankwidth; the_map->bankwidth
135 >>= 1) {
136 res = do_map_probe("cfi_probe", the_map);
137 if (res == NULL)
138 res = do_map_probe("jedec_probe", the_map);
139 if (res != NULL)
140 break;
141 }
142 iounmap(the_map->virt);
143 if (res != NULL)
144 the_map->phys = (u32)-(s32)(the_map->size = res->size);
145 return res == NULL;
146 }
147
148 static int __init rdc_board_setup(void)
149 {
150 #ifndef CONFIG_MTD_RDC3210
151 struct map_info rdc_map_info;
152 u32 the_header[8];
153
154 ROOT_DEV = 0;
155 rdc_map_info.name = rdc_flash_device.name;
156 rdc_map_info.size = 0x800000; //8MB
157 rdc_map_info.phys = (u32) -rdc_map_info.size;
158 rdc_map_info.bankwidth = 2;
159 rdc_map_info.set_vpp = NULL;
160 simple_map_init(&rdc_map_info);
161 while (probe_flash_start(&rdc_map_info)) {
162 if (rdc_map_info.size /= 2 < 0x100000) //1MB
163 panic("Could not find start of flash!");
164 rdc_map_info.phys = (u32) -rdc_map_info.size;
165 }
166 rdc_flash_resource.start = rdc_map_info.phys;
167 rdc_flash_data.width = rdc_map_info.bankwidth;
168 rdc_map_info.virt = ioremap_nocache(rdc_map_info.phys, 0x10);
169 if (rdc_map_info.virt == NULL)
170 panic("Could not ioremap to read device magic!");
171 the_header[0] = ((u32 *)rdc_map_info.virt)[0];
172 the_header[1] = ((u32 *)rdc_map_info.virt)[1];
173 the_header[2] = ((u32 *)rdc_map_info.virt)[2];
174 the_header[3] = ((u32 *)rdc_map_info.virt)[3];
175 iounmap(rdc_map_info.virt);
176 rdc_map_info.virt = ioremap_nocache(rdc_map_info.phys + 0x8000, 0x10);
177 if (rdc_map_info.virt == NULL)
178 panic("Could not ioremap to read device magic!");
179 the_header[4] = ((u32 *)rdc_map_info.virt)[0];
180 the_header[5] = ((u32 *)rdc_map_info.virt)[1];
181 the_header[6] = ((u32 *)rdc_map_info.virt)[2];
182 the_header[7] = ((u32 *)rdc_map_info.virt)[3];
183 iounmap(rdc_map_info.virt);
184 if (!memcmp(the_header, "GMTK", 4)) { /* Gemtek */
185 /* TODO */
186 } else if (!memcmp(the_header + 4, "CSYS", 4)) { /* Sitecom */
187 rdc_flash_parts[0].name = "system";
188 rdc_flash_parts[0].offset = 0;
189 rdc_flash_parts[0].size = rdc_map_info.size - 0x10000;
190 rdc_flash_parts[1].name = "config";
191 rdc_flash_parts[1].offset = 0;
192 rdc_flash_parts[1].size = 0x8000;
193 rdc_flash_parts[2].name = "magic";
194 rdc_flash_parts[2].offset = 0x8000;
195 rdc_flash_parts[2].size = 0x14;
196 rdc_flash_parts[3].name = "kernel";
197 rdc_flash_parts[3].offset = 0x8014;
198 rdc_flash_parts[3].size = the_header[5];
199 rdc_flash_parts[4].name = "rootfs";
200 rdc_flash_parts[4].offset = 0x8014 + the_header[5];
201 rdc_flash_parts[4].size = rdc_flash_parts[0].size - rdc_flash_parts[4].offset;
202 rdc_flash_parts[5].name = "bootloader";
203 rdc_flash_parts[5].offset = rdc_flash_parts[0].size;
204 rdc_flash_parts[5].size = 0x10000;
205 rdc_flash_data.nr_parts = 6;
206 } else if (!memcmp(((u8 *)the_header) + 14, "Li", 2)) { /* AMIT */
207 rdc_flash_parts[0].name = "kernel_parthdr";
208 rdc_flash_parts[0].offset = 0;
209 rdc_flash_parts[0].size = 0x10;
210 rdc_flash_parts[1].name = "kernel";
211 rdc_flash_parts[1].offset = 0x10;
212 rdc_flash_parts[1].size = 0xffff0;
213 rdc_flash_parts[2].name = "rootfs_parthdr";
214 rdc_flash_parts[2].offset = 0x100000;
215 rdc_flash_parts[2].size = 0x10;
216 rdc_flash_parts[3].name = "rootfs";
217 rdc_flash_parts[3].offset = 0x100010;
218 rdc_flash_parts[3].size = rdc_map_info.size - 0x160010;
219 rdc_flash_parts[4].name = "config_parthdr";
220 rdc_flash_parts[4].offset = rdc_map_info.size - 0x60000;
221 rdc_flash_parts[4].size = 0x10;
222 rdc_flash_parts[5].name = "config";
223 rdc_flash_parts[5].offset = rdc_map_info.size - 0x5fff0;
224 rdc_flash_parts[5].size = 0xfff0;
225 rdc_flash_parts[6].name = "recoveryfs_parthdr";
226 rdc_flash_parts[6].offset = rdc_map_info.size - 0x50000;
227 rdc_flash_parts[6].size = 0x10;
228 rdc_flash_parts[7].name = "recoveryfs";
229 rdc_flash_parts[7].offset = rdc_map_info.size - 0x4fff0;
230 rdc_flash_parts[7].size = 0x3fff0;
231 rdc_flash_parts[8].name = "recovery_parthdr";
232 rdc_flash_parts[8].offset = rdc_map_info.size - 0x10000;
233 rdc_flash_parts[8].size = 0x10;
234 rdc_flash_parts[9].name = "recovery";
235 rdc_flash_parts[9].offset = rdc_map_info.size - 0xfff0;
236 rdc_flash_parts[9].size = 0x7ff0;
237 rdc_flash_parts[10].name = "productinfo_parthdr";
238 rdc_flash_parts[10].offset = rdc_map_info.size - 0x8000;
239 rdc_flash_parts[10].size = 0x10;
240 rdc_flash_parts[11].name = "productinfo";
241 rdc_flash_parts[11].offset = rdc_map_info.size - 0x7ff0;
242 rdc_flash_parts[11].size = 0x1ff0;
243 rdc_flash_parts[12].name = "bootloader_parthdr";
244 rdc_flash_parts[12].offset = rdc_map_info.size - 0x6000;
245 rdc_flash_parts[12].size = 0x10;
246 rdc_flash_parts[13].name = "bootloader";
247 rdc_flash_parts[13].offset = rdc_map_info.size - 0x5ff0;
248 rdc_flash_parts[13].size = 0x5ff0;
249 rdc_flash_parts[14].name = "everything";
250 rdc_flash_parts[14].offset = 0;
251 rdc_flash_parts[14].size = rdc_map_info.size;
252 rdc_flash_data.nr_parts = 15;
253 } else { /* ZyXEL */
254 rdc_flash_parts[0].name = "kernel";
255 rdc_flash_parts[0].offset = 0;
256 rdc_flash_parts[0].size = 0x100000;
257 rdc_flash_parts[1].name = "rootfs";
258 rdc_flash_parts[1].offset = 0x100000;
259 rdc_flash_parts[1].size = rdc_map_info.size - 0x140000;
260 rdc_flash_parts[2].name = "linux";
261 rdc_flash_parts[2].offset = 0;
262 rdc_flash_parts[2].size = rdc_map_info.size - 0x40000;
263 rdc_flash_parts[3].name = "config";
264 rdc_flash_parts[3].offset = rdc_map_info.size - 0x40000;
265 rdc_flash_parts[3].size = 0x10000;
266 rdc_flash_parts[4].name = "productinfo";
267 rdc_flash_parts[4].offset = rdc_map_info.size - 0x30000;
268 rdc_flash_parts[4].size = 0x10000;
269 rdc_flash_parts[5].name = "bootloader";
270 rdc_flash_parts[5].offset = rdc_map_info.size - 0x20000;
271 rdc_flash_parts[5].size = 0x20000;
272 rdc_flash_data.nr_parts = 6;
273 }
274 #endif
275 return platform_add_devices(rdc321x_devs, ARRAY_SIZE(rdc321x_devs));
276 }
277
278 #ifdef CONFIG_MTD_RDC3210
279 arch_initcall(rdc_board_setup);
280 #else
281 late_initcall(rdc_board_setup);
282 #endif