2 * Handle mapping of the flash memory access routines on the SBC8240 board.
4 * Carolyn Smith, Tektronix, Inc.
8 * $Id: sbc8240.c,v 1.5 2005/11/07 11:14:28 gleixner Exp $
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.
21 #include <linux/config.h>
22 #include <linux/module.h>
23 #include <linux/types.h>
24 #include <linux/kernel.h>
27 #include <linux/mtd/mtd.h>
28 #include <linux/mtd/map.h>
29 #include <linux/mtd/cfi.h>
31 #ifdef CONFIG_MTD_PARTITIONS
32 #include <linux/mtd/partitions.h>
38 # define debugk(fmt,args...) printk(fmt ,##args)
40 # define debugk(fmt,args...)
44 #define WINDOW_ADDR0 0xFFF00000 /* 512 KiB */
45 #define WINDOW_SIZE0 0x00080000
48 #define WINDOW_ADDR1 0xFF000000 /* 4 MiB */
49 #define WINDOW_SIZE1 0x00400000
52 #define MSG_PREFIX "sbc8240:" /* prefix for our printk()'s */
53 #define MTDID "sbc8240-%d" /* for mtdparts= partitioning */
56 static struct map_info sbc8240_map[2] = {
58 .name = "sbc8240 Flash Bank #0",
60 .bankwidth = BUSWIDTH0,
63 .name = "sbc8240 Flash Bank #1",
65 .bankwidth = BUSWIDTH1,
69 #define NUM_FLASH_BANKS (sizeof(sbc8240_map) / sizeof(struct map_info))
72 * The following defines the partition layout of SBC8240 boards.
74 * See include/linux/mtd/partitions.h for definition of the
75 * mtd_partition structure.
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.
83 #ifdef CONFIG_MTD_PARTITIONS
85 static struct mtd_partition sbc8240_uboot_partitions [] = {
88 .name = "U-boot", /* U-Boot Firmware */
90 .size = 0x00070000, /* 7 x 64 KiB sectors */
91 .mask_flags = MTD_WRITEABLE, /* force read-only */
94 .name = "environment", /* U-Boot environment */
96 .size = 0x00010000, /* 1 x 64 KiB sector */
100 static struct mtd_partition sbc8240_fs_partitions [] = {
102 .name = "jffs", /* JFFS filesystem */
104 .size = 0x003C0000, /* 4 * 15 * 64KiB */
108 .offset = 0x003C0000,
109 .size = 0x00020000, /* 4 * 32KiB */
113 .offset = 0x003E0000,
114 .size = 0x00008000, /* 4 * 8KiB */
118 .offset = 0x003E8000,
119 .size = 0x00008000, /* 4 * 8KiB */
123 .offset = 0x003F0000,
124 .size = 0x00010000, /* 4 * 16KiB */
128 #define NB_OF(x) (sizeof (x) / sizeof (x[0]))
130 /* trivial struct to describe partition information */
135 struct mtd_partition* mtd_part;
138 static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
139 static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
142 #endif /* CONFIG_MTD_PARTITIONS */
145 int __init init_sbc8240_mtd (void)
150 } pt[NUM_FLASH_BANKS] = {
152 .addr = WINDOW_ADDR0,
156 .addr = WINDOW_ADDR1,
161 int devicesfound = 0;
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);
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");
174 simple_map_init(&sbc8240_mtd[i]);
176 sbc8240_mtd[i] = do_map_probe("jedec_probe", &sbc8240_map[i]);
178 if (sbc8240_mtd[i]) {
179 sbc8240_mtd[i]->module = THIS_MODULE;
185 printk(KERN_NOTICE MSG_PREFIX
186 "No suppported flash chips found!\n");
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);
198 for (i = 0; i < NUM_FLASH_BANKS; i++) {
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]);
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);
214 printk(KERN_NOTICE MSG_PREFIX
215 "Registering %d flash banks at once\n", devicesfound);
217 for (i = 0; i < devicesfound; i++) {
218 add_mtd_device(sbc8240_mtd[i]);
220 #endif /* CONFIG_MTD_PARTITIONS */
222 return devicesfound == 0 ? -ENXIO : 0;
225 static void __exit cleanup_sbc8240_mtd (void)
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]);
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;
241 module_init (init_sbc8240_mtd);
242 module_exit (cleanup_sbc8240_mtd);
244 MODULE_LICENSE ("GPL");
245 MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
246 MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");