patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / mtd / maps / lubbock-flash.c
1 /*
2  * $Id: lubbock-flash.c,v 1.9 2003/06/23 11:48:18 dwmw2 Exp $
3  *
4  * Map driver for the Lubbock developer platform.
5  *
6  * Author:      Nicolas Pitre
7  * Copyright:   (C) 2001 MontaVista Software Inc.
8  * 
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13
14 #include <linux/module.h>
15 #include <linux/types.h>
16 #include <linux/kernel.h>
17 #include <linux/init.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/mtd/partitions.h>
21 #include <asm/io.h>
22 #include <asm/hardware.h>
23 #include <asm/arch/lubbock.h>
24
25
26 #define ROM_ADDR        0x00000000
27 #define FLASH_ADDR      0x04000000
28
29 #define WINDOW_SIZE     64*1024*1024
30
31 static struct map_info lubbock_maps[2] = { {
32         .size =         WINDOW_SIZE,
33         .phys =         0x00000000,
34 }, {
35         .size =         WINDOW_SIZE,
36         .phys =         0x04000000,
37 } };
38
39 static struct mtd_partition lubbock_partitions[] = {
40         {
41                 .name =         "Bootloader",
42                 .size =         0x00040000,
43                 .offset =       0,
44                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
45         },{
46                 .name =         "Kernel",
47                 .size =         0x00100000,
48                 .offset =       0x00040000,
49         },{
50                 .name =         "Filesystem",
51                 .size =         MTDPART_SIZ_FULL,
52                 .offset =       0x00140000
53         }
54 };
55
56 static struct mtd_info *mymtds[2];
57 static struct mtd_partition *parsed_parts[2];
58 static int nr_parsed_parts[2];
59
60 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
61
62 static int __init init_lubbock(void)
63 {
64         int flashboot = (LUB_CONF_SWITCHES & 1);
65         int ret = 0, i;
66
67         lubbock_maps[0].buswidth = lubbock_maps[1].buswidth = 
68                 (BOOT_DEF & 1) ? 2 : 4;
69
70         /* Compensate for the nROMBT switch which swaps the flash banks */
71         printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
72                flashboot?"Flash":"ROM", flashboot);
73
74         lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
75         lubbock_maps[flashboot].name = "Lubbock Boot ROM";
76
77         for (i = 0; i < 2; i++) {
78                 lubbock_maps[i].virt = (unsigned long)ioremap(lubbock_maps[i].phys, WINDOW_SIZE);
79                 if (!lubbock_maps[i].virt) {
80                         printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
81                         if (!ret)
82                                 ret = -ENOMEM;
83                         continue;
84                 }
85                 simple_map_init(&lubbock_maps[i]);
86
87                 printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit buswidth)\n",
88                        lubbock_maps[i].name, lubbock_maps[i].phys, 
89                        lubbock_maps[i].buswidth * 8);
90
91                 mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
92                 
93                 if (!mymtds[i]) {
94                         iounmap((void *)lubbock_maps[i].virt);
95                         if (!ret)
96                                 ret = -EIO;
97                         continue;
98                 }
99                 mymtds[i]->owner = THIS_MODULE;
100
101                 ret = parse_mtd_partitions(mymtds[i], probes,
102                                            &parsed_parts[i], 0);
103
104                 if (ret > 0)
105                         nr_parsed_parts[i] = ret;
106         }
107
108         if (!mymtds[0] && !mymtds[1])
109                 return ret;
110         
111         for (i = 0; i < 2; i++) {
112                 if (!mymtds[i]) {
113                         printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
114                 } else if (nr_parsed_parts[i]) {
115                         add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
116                 } else if (!i) {
117                         printk("Using static partitions on %s\n", lubbock_maps[i].name);
118                         add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions));
119                 } else {
120                         printk("Registering %s as whole device\n", lubbock_maps[i].name);
121                         add_mtd_device(mymtds[i]);
122                 }
123         }
124         return 0;
125 }
126
127 static void __exit cleanup_lubbock(void)
128 {
129         int i;
130         for (i = 0; i < 2; i++) {
131                 if (!mymtds[i])
132                         continue;
133
134                 if (nr_parsed_parts[i] || !i)
135                         del_mtd_partitions(mymtds[i]);
136                 else
137                         del_mtd_device(mymtds[i]);                      
138
139                 map_destroy(mymtds[i]);
140                 iounmap((void *)lubbock_maps[i].virt);
141
142                 if (parsed_parts[i])
143                         kfree(parsed_parts[i]);
144         }
145 }
146
147 module_init(init_lubbock);
148 module_exit(cleanup_lubbock);
149
150 MODULE_LICENSE("GPL");
151 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
152 MODULE_DESCRIPTION("MTD map driver for Intel Lubbock");