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