ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / mtd / maps / pb1xxx-flash.c
1 /*
2  * Flash memory access on Alchemy Pb1xxx boards
3  * 
4  * (C) 2001 Pete Popov <ppopov@mvista.com>
5  * 
6  * $Id: pb1xxx-flash.c,v 1.9 2003/06/23 11:48:18 dwmw2 Exp $
7  */
8
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/init.h>
14
15 #include <linux/mtd/mtd.h>
16 #include <linux/mtd/map.h>
17 #include <linux/mtd/partitions.h>
18
19 #include <asm/io.h>
20 #include <asm/au1000.h>
21
22 #ifdef  DEBUG_RW
23 #define DBG(x...)       printk(x)
24 #else
25 #define DBG(x...)       
26 #endif
27
28 #ifdef CONFIG_MIPS_PB1000
29 #define WINDOW_ADDR 0x1F800000
30 #define WINDOW_SIZE 0x800000
31 #endif
32
33
34 static struct map_info pb1xxx_map = {
35         .name = "Pb1xxx flash",
36 };
37
38
39 #ifdef CONFIG_MIPS_PB1000
40
41 static unsigned long flash_size = 0x00800000;
42 static unsigned char flash_buswidth = 4;
43 static struct mtd_partition pb1xxx_partitions[] = {
44         {
45                 .name = "yamon env",
46                 .size = 0x00020000,
47                 .offset = 0,
48                 .mask_flags = MTD_WRITEABLE
49         },{
50                 .name = "User FS",
51                 .size = 0x003e0000,
52                 .offset = 0x20000,
53         },{
54                 .name = "boot code",
55                 .size = 0x100000,
56                 .offset = 0x400000,
57                 .mask_flags = MTD_WRITEABLE
58         },{
59                 .name = "raw/kernel",
60                 .size = 0x300000,
61                 .offset = 0x500000
62         }
63 };
64
65 #elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100)
66
67 static unsigned char flash_buswidth = 4;
68 #if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
69 /* both 32MiB banks will be used. Combine the first 32MiB bank and the
70  * first 28MiB of the second bank together into a single jffs/jffs2
71  * partition.
72  */
73 static unsigned long flash_size = 0x04000000;
74 #define WINDOW_ADDR 0x1C000000
75 #define WINDOW_SIZE 0x4000000
76 static struct mtd_partition pb1xxx_partitions[] = {
77         {
78                 .name = "User FS",
79                 .size =   0x3c00000,
80                 .offset = 0x0000000
81         },{
82                 .name = "yamon",
83                 .size = 0x0100000,
84                 .offset = 0x3c00000,
85                 .mask_flags = MTD_WRITEABLE
86         },{
87                 .name = "raw kernel",
88                 .size = 0x02c0000,
89                 .offset = 0x3d00000
90         }
91 };
92 #elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER)
93 static unsigned long flash_size = 0x02000000;
94 #define WINDOW_ADDR 0x1E000000
95 #define WINDOW_SIZE 0x2000000
96 static struct mtd_partition pb1xxx_partitions[] = {
97         {
98                 .name = "User FS",
99                 .size =   0x1c00000,
100                 .offset = 0x0000000
101         },{
102                 .name = "yamon",
103                 .size = 0x0100000,
104                 .offset = 0x1c00000,
105                 .mask_flags = MTD_WRITEABLE
106         },{
107                 .name = "raw kernel",
108                 .size = 0x02c0000,
109                 .offset = 0x1d00000
110         }
111 };
112 #elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
113 static unsigned long flash_size = 0x02000000;
114 #define WINDOW_ADDR 0x1C000000
115 #define WINDOW_SIZE 0x2000000
116 static struct mtd_partition pb1xxx_partitions[] = {
117         {
118                 .name = "User FS",
119                 .size =   0x1e00000,
120                 .offset = 0x0000000
121         },{
122                 .name = "raw kernel",
123                 .size = 0x0200000,
124                 .offset = 0x1e00000,
125         }
126 };
127 #else
128 #error MTD_PB1500 define combo error /* should never happen */
129 #endif
130 #else
131 #error Unsupported board
132 #endif
133
134 static struct mtd_partition *parsed_parts;
135 static struct mtd_info *mymtd;
136
137 int __init pb1xxx_mtd_init(void)
138 {
139         struct mtd_partition *parts;
140         int nb_parts = 0;
141         char *part_type;
142         
143         /* Default flash buswidth */
144         pb1xxx_map.buswidth = flash_buswidth;
145
146         /*
147          * Static partition definition selection
148          */
149         part_type = "static";
150         parts = pb1xxx_partitions;
151         nb_parts = ARRAY_SIZE(pb1xxx_partitions);
152         pb1xxx_map.size = flash_size;
153
154         /*
155          * Now let's probe for the actual flash.  Do it here since
156          * specific machine settings might have been set above.
157          */
158         printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n", 
159                         pb1xxx_map.buswidth*8);
160         pb1xxx_map.phys = WINDOW_ADDR;
161         pb1xxx_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
162
163         simple_map_init(&pb1xxx_map);
164
165         mymtd = do_map_probe("cfi_probe", &pb1xxx_map);
166         if (!mymtd) {
167                 iounmap(pb1xxx_map.virt);
168                 return -ENXIO;
169         }
170         mymtd->owner = THIS_MODULE;
171
172         add_mtd_partitions(mymtd, parts, nb_parts);
173         return 0;
174 }
175
176 static void __exit pb1xxx_mtd_cleanup(void)
177 {
178         if (mymtd) {
179                 del_mtd_partitions(mymtd);
180                 map_destroy(mymtd);
181                 if (parsed_parts)
182                         kfree(parsed_parts);
183         }
184         if (pb1xxx_map.virt)
185                 iounmap(pb1xxx_map.virt);
186 }
187
188 module_init(pb1xxx_mtd_init);
189 module_exit(pb1xxx_mtd_cleanup);
190
191 MODULE_AUTHOR("Pete Popov");
192 MODULE_DESCRIPTION("Pb1xxx CFI map driver");
193 MODULE_LICENSE("GPL");