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 ARRAY_SIZE(sbc8240_map)
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 /* trivial struct to describe partition information */
133 struct mtd_partition* mtd_part;
136 static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
137 static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
140 #endif /* CONFIG_MTD_PARTITIONS */
143 int __init init_sbc8240_mtd (void)
148 } pt[NUM_FLASH_BANKS] = {
150 .addr = WINDOW_ADDR0,
154 .addr = WINDOW_ADDR1,
159 int devicesfound = 0;
162 for (i = 0; i < NUM_FLASH_BANKS; i++) {
163 printk (KERN_NOTICE MSG_PREFIX
164 "Probing 0x%08lx at 0x%08lx\n", pt[i].size, pt[i].addr);
166 sbc8240_map[i].map_priv_1 =
167 (unsigned long) ioremap (pt[i].addr, pt[i].size);
168 if (!sbc8240_map[i].map_priv_1) {
169 printk (MSG_PREFIX "failed to ioremap\n");
172 simple_map_init(&sbc8240_mtd[i]);
174 sbc8240_mtd[i] = do_map_probe("jedec_probe", &sbc8240_map[i]);
176 if (sbc8240_mtd[i]) {
177 sbc8240_mtd[i]->module = THIS_MODULE;
183 printk(KERN_NOTICE MSG_PREFIX
184 "No suppported flash chips found!\n");
188 #ifdef CONFIG_MTD_PARTITIONS
189 sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
190 sbc8240_part_banks[0].type = "static image";
191 sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
192 sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
193 sbc8240_part_banks[1].type = "static file system";
194 sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);
196 for (i = 0; i < NUM_FLASH_BANKS; i++) {
198 if (!sbc8240_mtd[i]) continue;
199 if (sbc8240_part_banks[i].nums == 0) {
200 printk (KERN_NOTICE MSG_PREFIX
201 "No partition info available, registering whole device\n");
202 add_mtd_device(sbc8240_mtd[i]);
204 printk (KERN_NOTICE MSG_PREFIX
205 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name);
206 add_mtd_partitions (sbc8240_mtd[i],
207 sbc8240_part_banks[i].mtd_part,
208 sbc8240_part_banks[i].nums);
212 printk(KERN_NOTICE MSG_PREFIX
213 "Registering %d flash banks at once\n", devicesfound);
215 for (i = 0; i < devicesfound; i++) {
216 add_mtd_device(sbc8240_mtd[i]);
218 #endif /* CONFIG_MTD_PARTITIONS */
220 return devicesfound == 0 ? -ENXIO : 0;
223 static void __exit cleanup_sbc8240_mtd (void)
227 for (i = 0; i < NUM_FLASH_BANKS; i++) {
228 if (sbc8240_mtd[i]) {
229 del_mtd_device (sbc8240_mtd[i]);
230 map_destroy (sbc8240_mtd[i]);
232 if (sbc8240_map[i].map_priv_1) {
233 iounmap ((void *) sbc8240_map[i].map_priv_1);
234 sbc8240_map[i].map_priv_1 = 0;
239 module_init (init_sbc8240_mtd);
240 module_exit (cleanup_sbc8240_mtd);
242 MODULE_LICENSE ("GPL");
243 MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
244 MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");