VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[linux-2.6.git] / drivers / mtd / maps / lubbock-flash.c
1 /*
2  * $Id: lubbock-flash.c,v 1.15 2004/07/12 21:59:44 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 void lubbock_map_inval_cache(struct map_info *map, unsigned long from, ssize_t len)
32 {
33         consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE);
34 }
35
36 static struct map_info lubbock_maps[2] = { {
37         .size =         WINDOW_SIZE,
38         .phys =         0x00000000,
39         .inval_cache =  lubbock_map_inval_cache,
40 }, {
41         .size =         WINDOW_SIZE,
42         .phys =         0x04000000,
43         .inval_cache =  lubbock_map_inval_cache,
44 } };
45
46 static struct mtd_partition lubbock_partitions[] = {
47         {
48                 .name =         "Bootloader",
49                 .size =         0x00040000,
50                 .offset =       0,
51                 .mask_flags =   MTD_WRITEABLE  /* force read-only */
52         },{
53                 .name =         "Kernel",
54                 .size =         0x00100000,
55                 .offset =       0x00040000,
56         },{
57                 .name =         "Filesystem",
58                 .size =         MTDPART_SIZ_FULL,
59                 .offset =       0x00140000
60         }
61 };
62
63 static struct mtd_info *mymtds[2];
64 static struct mtd_partition *parsed_parts[2];
65 static int nr_parsed_parts[2];
66
67 static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
68
69 static int __init init_lubbock(void)
70 {
71         int flashboot = (LUB_CONF_SWITCHES & 1);
72         int ret = 0, i;
73
74         lubbock_maps[0].bankwidth = lubbock_maps[1].bankwidth = 
75                 (BOOT_DEF & 1) ? 2 : 4;
76
77         /* Compensate for the nROMBT switch which swaps the flash banks */
78         printk(KERN_NOTICE "Lubbock configured to boot from %s (bank %d)\n",
79                flashboot?"Flash":"ROM", flashboot);
80
81         lubbock_maps[flashboot^1].name = "Lubbock Application Flash";
82         lubbock_maps[flashboot].name = "Lubbock Boot ROM";
83
84         for (i = 0; i < 2; i++) {
85                 lubbock_maps[i].virt = (unsigned long)ioremap(lubbock_maps[i].phys, WINDOW_SIZE);
86                 if (!lubbock_maps[i].virt) {
87                         printk(KERN_WARNING "Failed to ioremap %s\n", lubbock_maps[i].name);
88                         if (!ret)
89                                 ret = -ENOMEM;
90                         continue;
91                 }
92                 lubbock_maps[i].cached = __ioremap(lubbock_maps[i].phys,
93                                                    WINDOW_SIZE,
94                                                    L_PTE_CACHEABLE, 1);
95                 if (!lubbock_maps[i].cached)
96                         printk(KERN_WARNING "Failed to ioremap cached %s\n", lubbock_maps[i].name);
97                 simple_map_init(&lubbock_maps[i]);
98
99                 printk(KERN_NOTICE "Probing %s at physical address 0x%08lx (%d-bit bankwidth)\n",
100                        lubbock_maps[i].name, lubbock_maps[i].phys, 
101                        lubbock_maps[i].bankwidth * 8);
102
103                 mymtds[i] = do_map_probe("cfi_probe", &lubbock_maps[i]);
104                 
105                 if (!mymtds[i]) {
106                         iounmap((void *)lubbock_maps[i].virt);
107                         if (lubbock_maps[i].cached)
108                                 iounmap(lubbock_maps[i].cached);
109                         if (!ret)
110                                 ret = -EIO;
111                         continue;
112                 }
113                 mymtds[i]->owner = THIS_MODULE;
114
115                 ret = parse_mtd_partitions(mymtds[i], probes,
116                                            &parsed_parts[i], 0);
117
118                 if (ret > 0)
119                         nr_parsed_parts[i] = ret;
120         }
121
122         if (!mymtds[0] && !mymtds[1])
123                 return ret;
124         
125         for (i = 0; i < 2; i++) {
126                 if (!mymtds[i]) {
127                         printk(KERN_WARNING "%s is absent. Skipping\n", lubbock_maps[i].name);
128                 } else if (nr_parsed_parts[i]) {
129                         add_mtd_partitions(mymtds[i], parsed_parts[i], nr_parsed_parts[i]);
130                 } else if (!i) {
131                         printk("Using static partitions on %s\n", lubbock_maps[i].name);
132                         add_mtd_partitions(mymtds[i], lubbock_partitions, ARRAY_SIZE(lubbock_partitions));
133                 } else {
134                         printk("Registering %s as whole device\n", lubbock_maps[i].name);
135                         add_mtd_device(mymtds[i]);
136                 }
137         }
138         return 0;
139 }
140
141 static void __exit cleanup_lubbock(void)
142 {
143         int i;
144         for (i = 0; i < 2; i++) {
145                 if (!mymtds[i])
146                         continue;
147
148                 if (nr_parsed_parts[i] || !i)
149                         del_mtd_partitions(mymtds[i]);
150                 else
151                         del_mtd_device(mymtds[i]);                      
152
153                 map_destroy(mymtds[i]);
154                 iounmap((void *)lubbock_maps[i].virt);
155                 if (lubbock_maps[i].cached)
156                         iounmap(lubbock_maps[i].cached);
157
158                 if (parsed_parts[i])
159                         kfree(parsed_parts[i]);
160         }
161 }
162
163 module_init(init_lubbock);
164 module_exit(cleanup_lubbock);
165
166 MODULE_LICENSE("GPL");
167 MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>");
168 MODULE_DESCRIPTION("MTD map driver for Intel Lubbock");