b53795a120dd14460d61db5d2baae4e5521b6a27
[linux-flexiantxendom0-3.2.10.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.8 2003/05/21 12:45:19 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
135 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
136
137 static struct mtd_partition *parsed_parts;
138 static struct mtd_info *mymtd;
139
140 int __init pb1xxx_mtd_init(void)
141 {
142         struct mtd_partition *parts;
143         int nb_parts = 0;
144         char *part_type;
145         
146         /* Default flash buswidth */
147         pb1xxx_map.buswidth = flash_buswidth;
148
149         /*
150          * Static partition definition selection
151          */
152         part_type = "static";
153         parts = pb1xxx_partitions;
154         nb_parts = NB_OF(pb1xxx_partitions);
155         pb1xxx_map.size = flash_size;
156
157         /*
158          * Now let's probe for the actual flash.  Do it here since
159          * specific machine settings might have been set above.
160          */
161         printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n", 
162                         pb1xxx_map.buswidth*8);
163         pb1xxx_map.phys = WINDOW_ADDR;
164         pb1xxx_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
165
166         simple_map_init(&pb1xxx_map);
167
168         mymtd = do_map_probe("cfi_probe", &pb1xxx_map);
169         if (!mymtd) {
170                 iounmap(pb1xxx_map.virt);
171                 return -ENXIO;
172         }
173         mymtd->owner = THIS_MODULE;
174
175         add_mtd_partitions(mymtd, parts, nb_parts);
176         return 0;
177 }
178
179 static void __exit pb1xxx_mtd_cleanup(void)
180 {
181         if (mymtd) {
182                 del_mtd_partitions(mymtd);
183                 map_destroy(mymtd);
184                 if (parsed_parts)
185                         kfree(parsed_parts);
186         }
187         if (pb1xxx_map.virt)
188                 iounmap(pb1xxx_map.virt);
189 }
190
191 module_init(pb1xxx_mtd_init);
192 module_exit(pb1xxx_mtd_cleanup);
193
194 MODULE_AUTHOR("Pete Popov");
195 MODULE_DESCRIPTION("Pb1xxx CFI map driver");
196 MODULE_LICENSE("GPL");