ACPI: make acpi_pci_bind() static
[linux-2.6/linux-acpi-2.6.git] / drivers / mtd / maps / sbc8240.c
blobd5374cdcb163bc82b3bbaa94a87062431be9cf8e
1 /*
2 * Handle mapping of the flash memory access routines on the SBC8240 board.
4 * Carolyn Smith, Tektronix, Inc.
6 * This code is GPLed
7 */
9 /*
10 * The SBC8240 has 2 flash banks.
11 * Bank 0 is a 512 KiB AMD AM29F040B; 8 x 64 KiB sectors.
12 * It contains the U-Boot code (7 sectors) and the environment (1 sector).
13 * Bank 1 is 4 x 1 MiB AMD AM29LV800BT; 15 x 64 KiB sectors, 1 x 32 KiB sector,
14 * 2 x 8 KiB sectors, 1 x 16 KiB sectors.
15 * Both parts are JEDEC compatible.
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/kernel.h>
21 #include <asm/io.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/cfi.h>
27 #ifdef CONFIG_MTD_PARTITIONS
28 #include <linux/mtd/partitions.h>
29 #endif
31 #define DEBUG
33 #ifdef DEBUG
34 # define debugk(fmt,args...) printk(fmt ,##args)
35 #else
36 # define debugk(fmt,args...)
37 #endif
40 #define WINDOW_ADDR0 0xFFF00000 /* 512 KiB */
41 #define WINDOW_SIZE0 0x00080000
42 #define BUSWIDTH0 1
44 #define WINDOW_ADDR1 0xFF000000 /* 4 MiB */
45 #define WINDOW_SIZE1 0x00400000
46 #define BUSWIDTH1 8
48 #define MSG_PREFIX "sbc8240:" /* prefix for our printk()'s */
49 #define MTDID "sbc8240-%d" /* for mtdparts= partitioning */
52 static struct map_info sbc8240_map[2] = {
54 .name = "sbc8240 Flash Bank #0",
55 .size = WINDOW_SIZE0,
56 .bankwidth = BUSWIDTH0,
59 .name = "sbc8240 Flash Bank #1",
60 .size = WINDOW_SIZE1,
61 .bankwidth = BUSWIDTH1,
65 #define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
68 * The following defines the partition layout of SBC8240 boards.
70 * See include/linux/mtd/partitions.h for definition of the
71 * mtd_partition structure.
73 * The *_max_flash_size is the maximum possible mapped flash size
74 * which is not necessarily the actual flash size. It must correspond
75 * to the value specified in the mapping definition defined by the
76 * "struct map_desc *_io_desc" for the corresponding machine.
79 #ifdef CONFIG_MTD_PARTITIONS
81 static struct mtd_partition sbc8240_uboot_partitions [] = {
82 /* Bank 0 */
84 .name = "U-boot", /* U-Boot Firmware */
85 .offset = 0,
86 .size = 0x00070000, /* 7 x 64 KiB sectors */
87 .mask_flags = MTD_WRITEABLE, /* force read-only */
90 .name = "environment", /* U-Boot environment */
91 .offset = 0x00070000,
92 .size = 0x00010000, /* 1 x 64 KiB sector */
96 static struct mtd_partition sbc8240_fs_partitions [] = {
98 .name = "jffs", /* JFFS filesystem */
99 .offset = 0,
100 .size = 0x003C0000, /* 4 * 15 * 64KiB */
103 .name = "tmp32",
104 .offset = 0x003C0000,
105 .size = 0x00020000, /* 4 * 32KiB */
108 .name = "tmp8a",
109 .offset = 0x003E0000,
110 .size = 0x00008000, /* 4 * 8KiB */
113 .name = "tmp8b",
114 .offset = 0x003E8000,
115 .size = 0x00008000, /* 4 * 8KiB */
118 .name = "tmp16",
119 .offset = 0x003F0000,
120 .size = 0x00010000, /* 4 * 16KiB */
124 /* trivial struct to describe partition information */
125 struct mtd_part_def
127 int nums;
128 unsigned char *type;
129 struct mtd_partition* mtd_part;
132 static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
133 static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
136 #endif /* CONFIG_MTD_PARTITIONS */
139 static int __init init_sbc8240_mtd (void)
141 static struct _cjs {
142 u_long addr;
143 u_long size;
144 } pt[NUM_FLASH_BANKS] = {
146 .addr = WINDOW_ADDR0,
147 .size = WINDOW_SIZE0
150 .addr = WINDOW_ADDR1,
151 .size = WINDOW_SIZE1
155 int devicesfound = 0;
156 int i,j;
158 for (i = 0; i < NUM_FLASH_BANKS; i++) {
159 printk (KERN_NOTICE MSG_PREFIX
160 "Probing 0x%08lx at 0x%08lx\n", pt[i].size, pt[i].addr);
162 sbc8240_map[i].map_priv_1 =
163 (unsigned long) ioremap (pt[i].addr, pt[i].size);
164 if (!sbc8240_map[i].map_priv_1) {
165 printk (MSG_PREFIX "failed to ioremap\n");
166 for (j = 0; j < i; j++) {
167 iounmap((void *) sbc8240_map[j].map_priv_1);
168 sbc8240_map[j].map_priv_1 = 0;
170 return -EIO;
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;
178 devicesfound++;
179 } else {
180 if (sbc8240_map[i].map_priv_1) {
181 iounmap((void *) sbc8240_map[i].map_priv_1);
182 sbc8240_map[i].map_priv_1 = 0;
187 if (!devicesfound) {
188 printk(KERN_NOTICE MSG_PREFIX
189 "No suppported flash chips found!\n");
190 return -ENXIO;
193 #ifdef CONFIG_MTD_PARTITIONS
194 sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
195 sbc8240_part_banks[0].type = "static image";
196 sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
197 sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
198 sbc8240_part_banks[1].type = "static file system";
199 sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);
201 for (i = 0; i < NUM_FLASH_BANKS; i++) {
203 if (!sbc8240_mtd[i]) continue;
204 if (sbc8240_part_banks[i].nums == 0) {
205 printk (KERN_NOTICE MSG_PREFIX
206 "No partition info available, registering whole device\n");
207 add_mtd_device(sbc8240_mtd[i]);
208 } else {
209 printk (KERN_NOTICE MSG_PREFIX
210 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name);
211 add_mtd_partitions (sbc8240_mtd[i],
212 sbc8240_part_banks[i].mtd_part,
213 sbc8240_part_banks[i].nums);
216 #else
217 printk(KERN_NOTICE MSG_PREFIX
218 "Registering %d flash banks at once\n", devicesfound);
220 for (i = 0; i < devicesfound; i++) {
221 add_mtd_device(sbc8240_mtd[i]);
223 #endif /* CONFIG_MTD_PARTITIONS */
225 return devicesfound == 0 ? -ENXIO : 0;
228 static void __exit cleanup_sbc8240_mtd (void)
230 int i;
232 for (i = 0; i < NUM_FLASH_BANKS; i++) {
233 if (sbc8240_mtd[i]) {
234 del_mtd_device (sbc8240_mtd[i]);
235 map_destroy (sbc8240_mtd[i]);
237 if (sbc8240_map[i].map_priv_1) {
238 iounmap ((void *) sbc8240_map[i].map_priv_1);
239 sbc8240_map[i].map_priv_1 = 0;
244 module_init (init_sbc8240_mtd);
245 module_exit (cleanup_sbc8240_mtd);
247 MODULE_LICENSE ("GPL");
248 MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
249 MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");