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