This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / drivers / mtd / maps / db1550-flash.c
1 /*
2  * Flash memory access on Alchemy Db1550 board
3  * 
4  * $Id: db1550-flash.c,v 1.3 2004/07/14 17:45:40 dwmw2 Exp $
5  *
6  * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c:
7  * (C) 2003 Pete Popov <pete_popov@yahoo.com>
8  * 
9  */
10
11 #include <linux/config.h>
12 #include <linux/init.h>
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/kernel.h>
16
17 #include <linux/mtd/mtd.h>
18 #include <linux/mtd/map.h>
19 #include <linux/mtd/partitions.h>
20
21 #include <asm/io.h>
22 #include <asm/au1000.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
33
34 static struct map_info db1550_map = {
35         .name = "Db1550 flash",
36 };
37
38 static unsigned char flash_bankwidth = 4;
39
40 /* 
41  * Support only 64MB NOR Flash parts
42  */
43
44 #if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
45 #define DB1550_BOTH_BANKS
46 #elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER)
47 #define DB1550_BOOT_ONLY
48 #elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER)
49 #define DB1550_USER_ONLY
50 #endif
51
52 #ifdef DB1550_BOTH_BANKS
53 /* both banks will be used. Combine the first bank and the first 
54  * part of the second bank together into a single jffs/jffs2
55  * partition.
56  */
57 static struct mtd_partition db1550_partitions[] = {
58         /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
59          * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
60          * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
61          */
62         {
63                 .name = "User FS",
64                 .size =   (0x1FC00000 - 0x18000000),
65                 .offset = 0x0000000
66         },{
67                 .name = "yamon",
68                 .size = 0x0100000,
69                 .offset = MTDPART_OFS_APPEND,
70                 .mask_flags = MTD_WRITEABLE
71         },{
72                 .name = "raw kernel",
73                 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
74                 .offset = MTDPART_OFS_APPEND,
75         }
76 };
77 #elif defined(DB1550_BOOT_ONLY)
78 static struct mtd_partition db1550_partitions[] = {
79         /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
80          * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash
81          */
82         {
83                 .name = "User FS",
84                 .size =   0x03c00000,
85                 .offset = 0x0000000
86         },{
87                 .name = "yamon",
88                 .size = 0x0100000,
89                 .offset = MTDPART_OFS_APPEND,
90                 .mask_flags = MTD_WRITEABLE
91         },{
92                 .name = "raw kernel",
93                 .size = (0x300000-0x40000), /* last 256KB is yamon env */
94                 .offset = MTDPART_OFS_APPEND,
95         }
96 };
97 #elif defined(DB1550_USER_ONLY)
98 static struct mtd_partition db1550_partitions[] = {
99         /* assume boot[2:0]:swap is '0000' or '1000', which translates to:
100          * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash
101          */
102         {
103                 .name = "User FS",
104                 .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */
105                 .offset = 0x0000000
106         },{
107                 .name = "raw kernel",
108                 .size = MTDPART_SIZ_FULL,
109                 .offset = MTDPART_OFS_APPEND,
110         }
111 };
112 #else
113 #error MTD_DB1550 define combo error /* should never happen */
114 #endif
115
116 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
117
118 static struct mtd_info *mymtd;
119
120 /*
121  * Probe the flash density and setup window address and size
122  * based on user CONFIG options. There are times when we don't
123  * want the MTD driver to be probing the boot or user flash,
124  * so having the option to enable only one bank is important.
125  */
126 int setup_flash_params(void)
127 {
128 #if defined(DB1550_BOTH_BANKS)
129                         window_addr = 0x18000000;
130                         window_size = 0x8000000; 
131 #elif defined(DB1550_BOOT_ONLY)
132                         window_addr = 0x1C000000;
133                         window_size = 0x4000000; 
134 #else /* USER ONLY */
135                         window_addr = 0x1E000000;
136                         window_size = 0x4000000; 
137 #endif
138         return 0;
139 }
140
141 int __init db1550_mtd_init(void)
142 {
143         struct mtd_partition *parts;
144         int nb_parts = 0;
145         
146         /* Default flash bankwidth */
147         db1550_map.bankwidth = flash_bankwidth;
148
149         if (setup_flash_params()) 
150                 return -ENXIO;
151
152         /*
153          * Static partition definition selection
154          */
155         parts = db1550_partitions;
156         nb_parts = NB_OF(db1550_partitions);
157         db1550_map.size = window_size;
158
159         /*
160          * Now let's probe for the actual flash.  Do it here since
161          * specific machine settings might have been set above.
162          */
163         printk(KERN_NOTICE "Pb1550 flash: probing %d-bit flash bus\n", 
164                         db1550_map.bankwidth*8);
165         db1550_map.virt = 
166                 (unsigned long)ioremap(window_addr, window_size);
167         mymtd = do_map_probe("cfi_probe", &db1550_map);
168         if (!mymtd) return -ENXIO;
169         mymtd->owner = THIS_MODULE;
170
171         add_mtd_partitions(mymtd, parts, nb_parts);
172         return 0;
173 }
174
175 static void __exit db1550_mtd_cleanup(void)
176 {
177         if (mymtd) {
178                 del_mtd_partitions(mymtd);
179                 map_destroy(mymtd);
180         }
181 }
182
183 module_init(db1550_mtd_init);
184 module_exit(db1550_mtd_cleanup);
185
186 MODULE_AUTHOR("Embedded Edge, LLC");
187 MODULE_DESCRIPTION("Db1550 mtd map driver");
188 MODULE_LICENSE("GPL");