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