Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / mtd / maps / sbc8240.c
1 /*
2  * Handle mapping of the flash memory access routines on the SBC8240 board.
3  *
4  * Carolyn Smith, Tektronix, Inc.
5  *
6  * This code is GPLed
7  *
8  * $Id: sbc8240.c,v 1.5 2005/11/07 11:14:28 gleixner Exp $
9  *
10  */
11
12 /*
13  * The SBC8240 has 2 flash banks.
14  * Bank 0 is a 512 KiB AMD AM29F040B; 8 x 64 KiB sectors.
15  * It contains the U-Boot code (7 sectors) and the environment (1 sector).
16  * Bank 1 is 4 x 1 MiB AMD AM29LV800BT; 15 x 64 KiB sectors, 1 x 32 KiB sector,
17  * 2 x 8 KiB sectors, 1 x 16 KiB sectors.
18  * Both parts are JEDEC compatible.
19  */
20
21 #include <linux/module.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
24 #include <asm/io.h>
25
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/map.h>
28 #include <linux/mtd/cfi.h>
29
30 #ifdef CONFIG_MTD_PARTITIONS
31 #include <linux/mtd/partitions.h>
32 #endif
33
34 #define DEBUG
35
36 #ifdef  DEBUG
37 # define debugk(fmt,args...)    printk(fmt ,##args)
38 #else
39 # define debugk(fmt,args...)
40 #endif
41
42
43 #define WINDOW_ADDR0    0xFFF00000              /* 512 KiB */
44 #define WINDOW_SIZE0    0x00080000
45 #define BUSWIDTH0       1
46
47 #define WINDOW_ADDR1    0xFF000000              /* 4 MiB */
48 #define WINDOW_SIZE1    0x00400000
49 #define BUSWIDTH1       8
50
51 #define MSG_PREFIX "sbc8240:"   /* prefix for our printk()'s */
52 #define MTDID      "sbc8240-%d" /* for mtdparts= partitioning */
53
54
55 static struct map_info sbc8240_map[2] = {
56         {
57                 .name           = "sbc8240 Flash Bank #0",
58                 .size           = WINDOW_SIZE0,
59                 .bankwidth       = BUSWIDTH0,
60         },
61         {
62                 .name           = "sbc8240 Flash Bank #1",
63                 .size           = WINDOW_SIZE1,
64                 .bankwidth       = BUSWIDTH1,
65         }
66 };
67
68 #define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
69
70 /*
71  * The following defines the partition layout of SBC8240 boards.
72  *
73  * See include/linux/mtd/partitions.h for definition of the
74  * mtd_partition structure.
75  *
76  * The *_max_flash_size is the maximum possible mapped flash size
77  * which is not necessarily the actual flash size. It must correspond
78  * to the value specified in the mapping definition defined by the
79  * "struct map_desc *_io_desc" for the corresponding machine.
80  */
81
82 #ifdef CONFIG_MTD_PARTITIONS
83
84 static struct mtd_partition sbc8240_uboot_partitions [] = {
85         /* Bank 0 */
86         {
87                 .name = "U-boot",                       /* U-Boot Firmware      */
88                 .offset =       0,
89                 .size = 0x00070000,                     /*  7 x 64 KiB sectors  */
90                 .mask_flags = MTD_WRITEABLE,            /*  force read-only     */
91         },
92         {
93                 .name = "environment",                  /* U-Boot environment   */
94                 .offset =       0x00070000,
95                 .size = 0x00010000,                     /*  1 x 64 KiB sector   */
96         },
97 };
98
99 static struct mtd_partition sbc8240_fs_partitions [] = {
100         {
101                 .name = "jffs",                         /* JFFS  filesystem     */
102                 .offset =       0,
103                 .size = 0x003C0000,                     /*  4 * 15 * 64KiB      */
104         },
105         {
106                 .name = "tmp32",
107                 .offset =       0x003C0000,
108                 .size = 0x00020000,                     /*  4 * 32KiB           */
109         },
110         {
111                 .name = "tmp8a",
112                 .offset =       0x003E0000,
113                 .size = 0x00008000,                     /*  4 * 8KiB            */
114         },
115         {
116                 .name = "tmp8b",
117                 .offset =       0x003E8000,
118                 .size = 0x00008000,                     /*  4 * 8KiB            */
119         },
120         {
121                 .name = "tmp16",
122                 .offset =       0x003F0000,
123                 .size = 0x00010000,                     /*  4 * 16KiB           */
124         }
125 };
126
127 /* trivial struct to describe partition information */
128 struct mtd_part_def
129 {
130         int nums;
131         unsigned char *type;
132         struct mtd_partition* mtd_part;
133 };
134
135 static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
136 static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
137
138
139 #endif  /* CONFIG_MTD_PARTITIONS */
140
141
142 int __init init_sbc8240_mtd (void)
143 {
144         static struct _cjs {
145                 u_long addr;
146                 u_long size;
147         } pt[NUM_FLASH_BANKS] = {
148                 {
149                         .addr = WINDOW_ADDR0,
150                         .size = WINDOW_SIZE0
151                 },
152                 {
153                         .addr = WINDOW_ADDR1,
154                         .size = WINDOW_SIZE1
155                 },
156         };
157
158         int devicesfound = 0;
159         int i;
160
161         for (i = 0; i < NUM_FLASH_BANKS; i++) {
162                 printk (KERN_NOTICE MSG_PREFIX
163                         "Probing 0x%08lx at 0x%08lx\n", pt[i].size, pt[i].addr);
164
165                 sbc8240_map[i].map_priv_1 =
166                         (unsigned long) ioremap (pt[i].addr, pt[i].size);
167                 if (!sbc8240_map[i].map_priv_1) {
168                         printk (MSG_PREFIX "failed to ioremap\n");
169                         return -EIO;
170                 }
171                 simple_map_init(&sbc8240_mtd[i]);
172
173                 sbc8240_mtd[i] = do_map_probe("jedec_probe", &sbc8240_map[i]);
174
175                 if (sbc8240_mtd[i]) {
176                         sbc8240_mtd[i]->module = THIS_MODULE;
177                         devicesfound++;
178                 }
179         }
180
181         if (!devicesfound) {
182                 printk(KERN_NOTICE MSG_PREFIX
183                        "No suppported flash chips found!\n");
184                 return -ENXIO;
185         }
186
187 #ifdef CONFIG_MTD_PARTITIONS
188         sbc8240_part_banks[0].mtd_part   = sbc8240_uboot_partitions;
189         sbc8240_part_banks[0].type       = "static image";
190         sbc8240_part_banks[0].nums       = ARRAY_SIZE(sbc8240_uboot_partitions);
191         sbc8240_part_banks[1].mtd_part   = sbc8240_fs_partitions;
192         sbc8240_part_banks[1].type       = "static file system";
193         sbc8240_part_banks[1].nums       = ARRAY_SIZE(sbc8240_fs_partitions);
194
195         for (i = 0; i < NUM_FLASH_BANKS; i++) {
196
197                 if (!sbc8240_mtd[i]) continue;
198                 if (sbc8240_part_banks[i].nums == 0) {
199                         printk (KERN_NOTICE MSG_PREFIX
200                                 "No partition info available, registering whole device\n");
201                         add_mtd_device(sbc8240_mtd[i]);
202                 } else {
203                         printk (KERN_NOTICE MSG_PREFIX
204                                 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name);
205                         add_mtd_partitions (sbc8240_mtd[i],
206                                             sbc8240_part_banks[i].mtd_part,
207                                             sbc8240_part_banks[i].nums);
208                 }
209         }
210 #else
211         printk(KERN_NOTICE MSG_PREFIX
212                "Registering %d flash banks at once\n", devicesfound);
213
214         for (i = 0; i < devicesfound; i++) {
215                 add_mtd_device(sbc8240_mtd[i]);
216         }
217 #endif  /* CONFIG_MTD_PARTITIONS */
218
219         return devicesfound == 0 ? -ENXIO : 0;
220 }
221
222 static void __exit cleanup_sbc8240_mtd (void)
223 {
224         int i;
225
226         for (i = 0; i < NUM_FLASH_BANKS; i++) {
227                 if (sbc8240_mtd[i]) {
228                         del_mtd_device (sbc8240_mtd[i]);
229                         map_destroy (sbc8240_mtd[i]);
230                 }
231                 if (sbc8240_map[i].map_priv_1) {
232                         iounmap ((void *) sbc8240_map[i].map_priv_1);
233                         sbc8240_map[i].map_priv_1 = 0;
234                 }
235         }
236 }
237
238 module_init (init_sbc8240_mtd);
239 module_exit (cleanup_sbc8240_mtd);
240
241 MODULE_LICENSE ("GPL");
242 MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
243 MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");
244