This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / mtd / maps / db1x00-flash.c
1 /*
2  * Flash memory access on Alchemy Db1xxx boards
3  * 
4  * $Id: db1x00-flash.c,v 1.3 2004/07/14 17:45:40 dwmw2 Exp $
5  *
6  * (C) 2003 Pete Popov <ppopov@pacbell.net>
7  * 
8  */
9
10 #include <linux/config.h>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/init.h>
14 #include <linux/kernel.h>
15
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/map.h>
18 #include <linux/mtd/partitions.h>
19
20 #include <asm/io.h>
21 #include <asm/au1000.h>
22 #include <asm/db1x00.h>
23
24 #ifdef  DEBUG_RW
25 #define DBG(x...)       printk(x)
26 #else
27 #define DBG(x...)       
28 #endif
29
30 static unsigned long window_addr;
31 static unsigned long window_size;
32 static unsigned long flash_size;
33
34 static BCSR * const bcsr = (BCSR *)0xAE000000;
35 static unsigned char flash_bankwidth = 4;
36
37 /* 
38  * The Db1x boards support different flash densities. We setup
39  * the mtd_partition structures below for default of 64Mbit 
40  * flash densities, and override the partitions sizes, if
41  * necessary, after we check the board status register.
42  */
43
44 #ifdef DB1X00_BOTH_BANKS
45 /* both banks will be used. Combine the first bank and the first 
46  * part of the second bank together into a single jffs/jffs2
47  * partition.
48  */
49 static struct mtd_partition db1x00_partitions[] = {
50         {
51                 .name         =  "User FS",
52                 .size         =  0x1c00000,
53                 .offset       =  0x0000000
54         },{
55                 .name         =  "yamon",
56                 .size         =  0x0100000,
57                 .offset       =  MTDPART_OFS_APPEND,
58                 .mask_flags   =  MTD_WRITEABLE
59         },{
60                 .name         =  "raw kernel",
61                 .size         =  (0x300000-0x40000), /* last 256KB is env */
62                 .offset       =  MTDPART_OFS_APPEND,
63         }
64 };
65 #elif defined(DB1X00_BOOT_ONLY)
66 static struct mtd_partition db1x00_partitions[] = {
67         {
68                 .name         =  "User FS",
69                 .size         =  0x00c00000,
70                 .offset       =  0x0000000
71         },{
72                 .name         =  "yamon",
73                 .size         =  0x0100000,
74                 .offset       =  MTDPART_OFS_APPEND,
75                 .mask_flags   =  MTD_WRITEABLE
76         },{
77                 .name         =  "raw kernel",
78                 .size         =  (0x300000-0x40000), /* last 256KB is env */
79                 .offset       =  MTDPART_OFS_APPEND,
80         }
81 };
82 #elif defined(DB1X00_USER_ONLY)
83 static struct mtd_partition db1x00_partitions[] = {
84         {
85                 .name         =  "User FS",
86                 .size         =  0x0e00000,
87                 .offset       =  0x0000000
88         },{
89                 .name         =  "raw kernel",
90                 .size         =  MTDPART_SIZ_FULL,
91                 .offset       =  MTDPART_OFS_APPEND,
92         }
93 };
94 #else
95 #error MTD_DB1X00 define combo error /* should never happen */
96 #endif
97 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
98
99 #define NAME            "Db1x00 Linux Flash"
100
101 static struct map_info db1xxx_mtd_map = {
102         .name           = NAME,
103 };
104
105 static struct mtd_partition *parsed_parts;
106 static struct mtd_info *db1xxx_mtd;
107
108 /*
109  * Probe the flash density and setup window address and size
110  * based on user CONFIG options. There are times when we don't
111  * want the MTD driver to be probing the boot or user flash,
112  * so having the option to enable only one bank is important.
113  */
114 int setup_flash_params(void)
115 {
116         switch ((bcsr->status >> 14) & 0x3) {
117                 case 0: /* 64Mbit devices */
118                         flash_size = 0x800000; /* 8MB per part */
119 #if defined(DB1X00_BOTH_BANKS)
120                         window_addr = 0x1E000000;
121                         window_size = 0x2000000; 
122 #elif defined(DB1X00_BOOT_ONLY)
123                         window_addr = 0x1F000000;
124                         window_size = 0x1000000; 
125 #else /* USER ONLY */
126                         window_addr = 0x1E000000;
127                         window_size = 0x1000000; 
128 #endif
129                         break;
130                 case 1:
131                         /* 128 Mbit devices */
132                         flash_size = 0x1000000; /* 16MB per part */
133 #if defined(DB1X00_BOTH_BANKS)
134                         window_addr = 0x1C000000;
135                         window_size = 0x4000000;
136                         /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */
137                         db1x00_partitions[0].size = 0x3C00000;
138 #elif defined(DB1X00_BOOT_ONLY)
139                         window_addr = 0x1E000000;
140                         window_size = 0x2000000;
141                         /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */
142                         db1x00_partitions[0].size = 0x1C00000;
143 #else /* USER ONLY */
144                         window_addr = 0x1C000000;
145                         window_size = 0x2000000;
146                         /* USERFS from 0x1C00 0000 to 0x1DE00000 */
147                         db1x00_partitions[0].size = 0x1DE0000;
148 #endif
149                         break;
150                 case 2:
151                         /* 256 Mbit devices */
152                         flash_size = 0x4000000; /* 64MB per part */
153 #if defined(DB1X00_BOTH_BANKS)
154                         return 1;
155 #elif defined(DB1X00_BOOT_ONLY)
156                         /* Boot ROM flash bank only; no user bank */
157                         window_addr = 0x1C000000;
158                         window_size = 0x4000000;
159                         /* USERFS from 0x1C00 0000 to 0x1FC00000 */
160                         db1x00_partitions[0].size = 0x3C00000;
161 #else /* USER ONLY */
162                         return 1;
163 #endif
164                         break;
165                 default:
166                         return 1;
167         }
168         db1xxx_mtd_map.size = window_size;
169         db1xxx_mtd_map.bankwidth = flash_bankwidth;
170         db1xxx_mtd_map.phys = window_addr;
171         db1xxx_mtd_map.bankwidth = flash_bankwidth;
172         return 0;
173 }
174
175 int __init db1x00_mtd_init(void)
176 {
177         struct mtd_partition *parts;
178         int nb_parts = 0;
179         
180         if (setup_flash_params()) 
181                 return -ENXIO;
182
183         /*
184          * Static partition definition selection
185          */
186         parts = db1x00_partitions;
187         nb_parts = NB_OF(db1x00_partitions);
188
189         /*
190          * Now let's probe for the actual flash.  Do it here since
191          * specific machine settings might have been set above.
192          */
193         printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n", 
194                         db1xxx_mtd_map.bankwidth*8);
195         db1xxx_mtd_map.virt = (unsigned long)ioremap(window_addr, window_size);
196         db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map);
197         if (!db1xxx_mtd) return -ENXIO;
198         db1xxx_mtd->owner = THIS_MODULE;
199
200         add_mtd_partitions(db1xxx_mtd, parts, nb_parts);
201         return 0;
202 }
203
204 static void __exit db1x00_mtd_cleanup(void)
205 {
206         if (db1xxx_mtd) {
207                 del_mtd_partitions(db1xxx_mtd);
208                 map_destroy(db1xxx_mtd);
209                 if (parsed_parts)
210                         kfree(parsed_parts);
211         }
212 }
213
214 module_init(db1x00_mtd_init);
215 module_exit(db1x00_mtd_cleanup);
216
217 MODULE_AUTHOR("Pete Popov");
218 MODULE_DESCRIPTION("Db1x00 mtd map driver");
219 MODULE_LICENSE("GPL");