Code cleanup
[openwrt.git] / target / linux / rdc-2.6 / files / drivers / mtd / maps / rdc3210.c
1 /*
2 * $Id$
3 * Copyright (C) 2005 Gemtek Corporation, Dante Su (dante_su@gemtek.com.tw)
4 * Copyright (C) 2006 Florian Fainelli <florian@openwrt.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 #include <asm/io.h>
22 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/partitions.h>
27 #include <linux/vmalloc.h>
28
29 #define WINDOW_ADDR 0xFFC00000
30 #define WINDOW_SIZE 0x00400000
31 #define BUSWIDTH 2
32
33 extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts, unsigned long fis_origin);
34
35 static struct mtd_partition *parsed_parts;
36 static struct mtd_info *rdc3210_mtd_info;
37
38 static struct map_info rdc3210_map = {
39 .name = "rdc3210",
40 .size = WINDOW_SIZE,
41 .bankwidth = BUSWIDTH,
42 .phys = WINDOW_ADDR,
43 };
44
45 static struct mtd_partition rdc3210_parts[] = {
46 { name: "linux", offset: 0, size: 0x003C0000 }, /* 3840 KB = (Kernel + ROMFS) = (768 KB + 3072 KB) */
47 { name: "romfs", offset: 0x000C0000, size: 0x00300000 }, /* 3072 KB */
48 { name: "nvram", offset: 0x003C0000, size: 0x00010000 }, /* 64 KB */
49 { name: "factory", offset: 0x003D0000, size: 0x00010000 }, /* 64 KB */
50 { name: "bootldr", offset: 0x003E0000, size: 0x00020000, mask_flags: MTD_WRITEABLE },/* 128 KB */
51 };
52
53 static int __init rdc3210_mtd_init(void)
54 {
55 printk(KERN_INFO "rdc3210: 0x%08x at 0x%08x\n", WINDOW_SIZE, WINDOW_ADDR);
56 rdc3210_map.virt = ioremap_nocache(WINDOW_ADDR, WINDOW_SIZE);
57
58 if (!rdc3210_map.virt) {
59 printk(KERN_ERR "rdc3210: failed to ioremap\n");
60 return -EIO;
61 }
62
63 simple_map_init(&rdc3210_map);
64
65 rdc3210_mtd_info = do_map_probe("cfi_probe", &rdc3210_map);
66
67 if (rdc3210_mtd_info)
68 {
69 rdc3210_mtd_info->owner = THIS_MODULE;
70 int parsed_nr_parts = 0;
71 char * part_type;
72
73 #ifdef CONFIG_MTD_REDBOOT_PARTS
74 if (parsed_nr_parts == 0)
75 {
76 int ret = parse_redboot_partitions(rdc3210_mtd_info, &parsed_parts, 0);
77 if (ret > 0)
78 {
79 part_type = "RedBoot";
80 parsed_nr_parts = ret;
81 } else {
82 printk(KERN_ERR "rdc3210: failed to parse RedBoot partitions, using static mapping\n");
83 add_mtd_partitions(rdc3210_mtd_info, rdc3210_parts, sizeof(rdc3210_parts)/sizeof(rdc3210_parts[0]));
84 return -ENXIO;
85 }
86 }
87
88 add_mtd_partitions(rdc3210_mtd_info, parsed_parts, parsed_nr_parts);
89 return 0;
90 }
91 #endif
92 iounmap(rdc3210_map.virt);
93 return -ENXIO;
94 }
95
96 static void __exit rdc3210_mtd_cleanup(void)
97 {
98 if (rdc3210_mtd_info)
99 {
100 del_mtd_partitions(rdc3210_mtd_info);
101 map_destroy(rdc3210_mtd_info);
102 }
103
104 if (rdc3210_map.virt) {
105 iounmap(rdc3210_map.virt);
106 rdc3210_map.virt = 0;
107 }
108 }
109
110 module_init(rdc3210_mtd_init);
111 module_exit(rdc3210_mtd_cleanup);
112
113 MODULE_LICENSE("GPL");
114 MODULE_DESCRIPTION("RDC3210 flash map driver");
115 MODULE_AUTHOR("Florian Fainelli <florian@openwrt.org>");
This page took 0.043728 seconds and 5 git commands to generate.