[backfire] iwinfo: merge r29417
[openwrt-10.03/.git] / target / linux / rdc / files-2.6.30 / arch / x86 / mach-rdc321x / boards / sitecom.c
1 /*
2  *  Sitecom 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/mtd/physmap.h>
27 #include <linux/input.h>
28
29 #include <asm/rdc_boards.h>
30
31 struct image_header {
32         char    magic[4];
33         u32     kernel_length;
34         u32     ramdisk_length;
35         char    magic2[4];
36         u32     kernel_length2;
37 };
38
39 static struct gpio_led sitecom_leds[] = {
40         { .name = "rdc321x:power", .gpio = 15, .active_low = 1},
41         { .name = "rdc321x:usb0", .gpio = 0, .active_low = 1},
42         { .name = "rdc321x:usb1", .gpio = 1, .active_low = 1},
43 };
44
45 static struct gpio_button sitecom_btns[] = {
46         {
47                 .gpio = 6,
48                 .code = BTN_0,
49                 .desc = "Reset",
50                 .active_low = 1,
51         }
52 };
53
54 static int __init parse_sitecom_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long plat_data)
55 {
56         struct image_header header;
57         int res;
58         size_t len;
59         struct mtd_partition *rdc_flash_parts;
60         struct rdc_platform_data *pdata = (struct rdc_platform_data *) plat_data;
61         
62         if (master->size != 0x400000) //4MB
63                 return -ENOSYS;
64
65         res =  master->read(master, 0x8000, sizeof(header), &len, (char *)&header);
66         if (res)
67                 return res;
68
69         if (strncmp(header.magic, "CSYS", 4) || strncmp(header.magic2, "WRRM", 4))
70                 return -ENOSYS;
71         
72         rdc_flash_parts = kzalloc(sizeof(struct mtd_partition) * 5, GFP_KERNEL);
73         
74         rdc_flash_parts[0].name = "firmware";
75         rdc_flash_parts[0].offset = 0x8000;
76         rdc_flash_parts[0].size = 0x3F0000;
77         rdc_flash_parts[1].name = "config";
78         rdc_flash_parts[1].offset = 0;
79         rdc_flash_parts[1].size = 0x8000;
80         rdc_flash_parts[2].name = "kernel";
81         rdc_flash_parts[2].offset = 0x8014;
82         rdc_flash_parts[2].size = header.kernel_length;
83         rdc_flash_parts[3].name = "rootfs";
84         rdc_flash_parts[3].offset = 0x8014 + header.kernel_length;
85         rdc_flash_parts[3].size = 0x3F0000 - rdc_flash_parts[3].offset;
86         rdc_flash_parts[4].name = "bootloader";
87         rdc_flash_parts[4].offset = 0x3F0000;
88         rdc_flash_parts[4].size = 0x10000;
89
90         *pparts = rdc_flash_parts;
91         
92         pdata->led_data.num_leds = ARRAY_SIZE(sitecom_leds);
93         pdata->led_data.leds = sitecom_leds;
94         pdata->button_data.nbuttons = ARRAY_SIZE(sitecom_btns);
95         pdata->button_data.buttons = sitecom_btns;
96         
97         return 5;
98 }
99
100 struct mtd_part_parser __initdata sitecom_parser = {
101         .owner = THIS_MODULE,
102         .parse_fn = parse_sitecom_partitions,
103         .name = "Sitecom",
104 };
105
106 static int __init sitecom_setup(void)
107 {
108         return register_mtd_parser(&sitecom_parser);
109 }
110
111 arch_initcall(sitecom_setup);