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/module.h>
22 #include <linux/types.h>
23 #include <linux/kernel.h>
26 #include <linux/mtd/mtd.h>
27 #include <linux/mtd/map.h>
28 #include <linux/mtd/cfi.h>
30 #ifdef CONFIG_MTD_PARTITIONS
31 #include <linux/mtd/partitions.h>
37 # define debugk(fmt,args...) printk(fmt ,##args)
39 # define debugk(fmt,args...)
43 #define WINDOW_ADDR0 0xFFF00000 /* 512 KiB */
44 #define WINDOW_SIZE0 0x00080000
47 #define WINDOW_ADDR1 0xFF000000 /* 4 MiB */
48 #define WINDOW_SIZE1 0x00400000
51 #define MSG_PREFIX "sbc8240:" /* prefix for our printk()'s */
52 #define MTDID "sbc8240-%d" /* for mtdparts= partitioning */
55 static struct map_info sbc8240_map[2] = {
57 .name = "sbc8240 Flash Bank #0",
59 .bankwidth = BUSWIDTH0,
62 .name = "sbc8240 Flash Bank #1",
64 .bankwidth = BUSWIDTH1,
68 #define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
71 * The following defines the partition layout of SBC8240 boards.
73 * See include/linux/mtd/partitions.h for definition of the
74 * mtd_partition structure.
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.
82 #ifdef CONFIG_MTD_PARTITIONS
84 static struct mtd_partition sbc8240_uboot_partitions [] = {
87 .name = "U-boot", /* U-Boot Firmware */
89 .size = 0x00070000, /* 7 x 64 KiB sectors */
90 .mask_flags = MTD_WRITEABLE, /* force read-only */
93 .name = "environment", /* U-Boot environment */
95 .size = 0x00010000, /* 1 x 64 KiB sector */
99 static struct mtd_partition sbc8240_fs_partitions [] = {
101 .name = "jffs", /* JFFS filesystem */
103 .size = 0x003C0000, /* 4 * 15 * 64KiB */
107 .offset = 0x003C0000,
108 .size = 0x00020000, /* 4 * 32KiB */
112 .offset = 0x003E0000,
113 .size = 0x00008000, /* 4 * 8KiB */
117 .offset = 0x003E8000,
118 .size = 0x00008000, /* 4 * 8KiB */
122 .offset = 0x003F0000,
123 .size = 0x00010000, /* 4 * 16KiB */
127 /* trivial struct to describe partition information */
132 struct mtd_partition* mtd_part;
135 static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
136 static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
139 #endif /* CONFIG_MTD_PARTITIONS */
142 int __init init_sbc8240_mtd (void)
147 } pt[NUM_FLASH_BANKS] = {
149 .addr = WINDOW_ADDR0,
153 .addr = WINDOW_ADDR1,
158 int devicesfound = 0;
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);
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");
171 simple_map_init(&sbc8240_mtd[i]);
173 sbc8240_mtd[i] = do_map_probe("jedec_probe", &sbc8240_map[i]);
175 if (sbc8240_mtd[i]) {
176 sbc8240_mtd[i]->module = THIS_MODULE;
182 printk(KERN_NOTICE MSG_PREFIX
183 "No suppported flash chips found!\n");
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);
195 for (i = 0; i < NUM_FLASH_BANKS; i++) {
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]);
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);
211 printk(KERN_NOTICE MSG_PREFIX
212 "Registering %d flash banks at once\n", devicesfound);
214 for (i = 0; i < devicesfound; i++) {
215 add_mtd_device(sbc8240_mtd[i]);
217 #endif /* CONFIG_MTD_PARTITIONS */
219 return devicesfound == 0 ? -ENXIO : 0;
222 static void __exit cleanup_sbc8240_mtd (void)
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]);
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;
238 module_init (init_sbc8240_mtd);
239 module_exit (cleanup_sbc8240_mtd);
241 MODULE_LICENSE ("GPL");
242 MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
243 MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");