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