VServer 1.9.2 (patch-2.6.8.1-vs1.9.2.diff)
[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.11 2004/07/12 21:59:44 dwmw2 Exp $
7  */
8
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/init.h>
13 #include <linux/kernel.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
30 #define WINDOW_ADDR 0x1F800000
31 #define WINDOW_SIZE 0x800000
32
33 static struct mtd_partition pb1xxx_partitions[] = {
34         {
35                 .name         =  "yamon env",
36                 .size         =   0x00020000,
37                 .offset       =   0,
38                 .mask_flags   =   MTD_WRITEABLE},
39         {
40                 .name         =   "User FS",
41                 .size         =   0x003e0000,
42                 .offset       =   0x20000,},
43         {
44                 .name         =   "boot code",
45                 .size         =   0x100000,
46                 .offset       =   0x400000,
47                 .mask_flags   =   MTD_WRITEABLE},
48         {
49                 .name         =   "raw/kernel",
50                 .size         =   0x300000,
51                 .offset       =   0x500000}
52 };
53
54 #elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100)
55
56 #if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
57 /* both 32MB banks will be used. Combine the first 32MB bank and the
58  * first 28MB of the second bank together into a single jffs/jffs2
59  * partition.
60  */
61 #define WINDOW_ADDR 0x1C000000
62 #define WINDOW_SIZE 0x4000000
63 static struct mtd_partition pb1xxx_partitions[] = {
64         {
65                 .name         =   "User FS",
66                 .size         =   0x3c00000,
67                 .offset       =   0x0000000
68         },{
69                 .name         =   "yamon",
70                 .size         =   0x0100000,
71                 .offset       =   0x3c00000,
72                 .mask_flags   =   MTD_WRITEABLE
73         },{
74                 .name         =   "raw kernel",
75                 .size         =   0x02c0000,
76                 .offset       =   0x3d00000
77         }
78 };
79 #elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER)
80 #define WINDOW_ADDR 0x1E000000
81 #define WINDOW_SIZE 0x2000000
82 static struct mtd_partition pb1xxx_partitions[] = {
83         {
84                 .name         =   "User FS",
85                 .size         =   0x1c00000,
86                 .offset       =   0x0000000
87         },{
88                 .name         =   "yamon",
89                 .size         =   0x0100000,
90                 .offset       =   0x1c00000,
91                 .mask_flags   =   MTD_WRITEABLE
92         },{
93                 .name         =   "raw kernel",
94                 .size         =   0x02c0000,
95                 .offset       =   0x1d00000
96         }
97 };
98 #elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER)
99 #define WINDOW_ADDR 0x1C000000
100 #define WINDOW_SIZE 0x2000000
101 static struct mtd_partition pb1xxx_partitions[] = {
102         {
103                 .name         =   "User FS",
104                 .size         =    0x1e00000,
105                 .offset       =    0x0000000
106         },{
107                 .name         =    "raw kernel",
108                 .size         =    0x0200000,
109                 .offset       =    0x1e00000,
110         }
111 };
112 #else
113 #error MTD_PB1500 define combo error /* should never happen */
114 #endif
115 #else
116 #error Unsupported board
117 #endif
118
119 #define NAME            "Pb1x00 Linux Flash"
120 #define PADDR           WINDOW_ADDR
121 #define BUSWIDTH        4
122 #define SIZE            WINDOW_SIZE
123 #define PARTITIONS      4
124
125 static struct map_info pb1xxx_mtd_map = {
126         .name           = NAME,
127         .size           = SIZE,
128         .bankwidth      = BUSWIDTH,
129         .phys           = PADDR,
130 };
131
132 static struct mtd_info *pb1xxx_mtd;
133
134 int __init pb1xxx_mtd_init(void)
135 {
136         struct mtd_partition *parts;
137         int nb_parts = 0;
138         char *part_type;
139         
140         /*
141          * Static partition definition selection
142          */
143         part_type = "static";
144         parts = pb1xxx_partitions;
145         nb_parts = ARRAY_SIZE(pb1xxx_partitions);
146
147         /*
148          * Now let's probe for the actual flash.  Do it here since
149          * specific machine settings might have been set above.
150          */
151         printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n", 
152                         BUSWIDTH*8);
153         pb1xxx_mtd_map.virt = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
154
155         simple_map_init(&pb1xxx_mtd_map);
156
157         pb1xxx_mtd = do_map_probe("cfi_probe", &pb1xxx_mtd_map);
158         if (!pb1xxx_mtd) return -ENXIO;
159         pb1xxx_mtd->owner = THIS_MODULE;
160
161         add_mtd_partitions(pb1xxx_mtd, parts, nb_parts);
162         return 0;
163 }
164
165 static void __exit pb1xxx_mtd_cleanup(void)
166 {
167         if (pb1xxx_mtd) {
168                 del_mtd_partitions(pb1xxx_mtd);
169                 map_destroy(pb1xxx_mtd);
170                 iounmap((void *) pb1xxx_mtd_map.virt);
171         }
172 }
173
174 module_init(pb1xxx_mtd_init);
175 module_exit(pb1xxx_mtd_cleanup);
176
177 MODULE_AUTHOR("Pete Popov");
178 MODULE_DESCRIPTION("Pb1xxx CFI map driver");
179 MODULE_LICENSE("GPL");