blob: 350286dc1d2eeaa0d8eedf39f3a095b51f38f231 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 *
Thomas Gleixner69f34c92005-11-07 11:15:40 +00008 * $Id: sbc8240.c,v 1.5 2005/11/07 11:14:28 gleixner Exp $
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 *
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
56static 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
Tobias Klauser87d10f32006-03-31 02:29:45 -080069#define NUM_FLASH_BANKS ARRAY_SIZE(sbc8240_map)
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
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
85static 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
100static 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128/* trivial struct to describe partition information */
129struct mtd_part_def
130{
131 int nums;
132 unsigned char *type;
133 struct mtd_partition* mtd_part;
134};
135
136static struct mtd_info *sbc8240_mtd[NUM_FLASH_BANKS];
137static struct mtd_part_def sbc8240_part_banks[NUM_FLASH_BANKS];
138
139
140#endif /* CONFIG_MTD_PARTITIONS */
141
142
143int __init init_sbc8240_mtd (void)
144{
145 static struct _cjs {
146 u_long addr;
147 u_long size;
148 } pt[NUM_FLASH_BANKS] = {
149 {
150 .addr = WINDOW_ADDR0,
151 .size = WINDOW_SIZE0
152 },
153 {
154 .addr = WINDOW_ADDR1,
155 .size = WINDOW_SIZE1
156 },
157 };
158
159 int devicesfound = 0;
160 int i;
161
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);
165
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");
170 return -EIO;
171 }
172 simple_map_init(&sbc8240_mtd[i]);
173
174 sbc8240_mtd[i] = do_map_probe("jedec_probe", &sbc8240_map[i]);
175
176 if (sbc8240_mtd[i]) {
177 sbc8240_mtd[i]->module = THIS_MODULE;
178 devicesfound++;
179 }
180 }
181
182 if (!devicesfound) {
183 printk(KERN_NOTICE MSG_PREFIX
184 "No suppported flash chips found!\n");
185 return -ENXIO;
186 }
187
188#ifdef CONFIG_MTD_PARTITIONS
189 sbc8240_part_banks[0].mtd_part = sbc8240_uboot_partitions;
190 sbc8240_part_banks[0].type = "static image";
Tobias Klauser87d10f32006-03-31 02:29:45 -0800191 sbc8240_part_banks[0].nums = ARRAY_SIZE(sbc8240_uboot_partitions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 sbc8240_part_banks[1].mtd_part = sbc8240_fs_partitions;
193 sbc8240_part_banks[1].type = "static file system";
Tobias Klauser87d10f32006-03-31 02:29:45 -0800194 sbc8240_part_banks[1].nums = ARRAY_SIZE(sbc8240_fs_partitions);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195
196 for (i = 0; i < NUM_FLASH_BANKS; i++) {
197
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]);
203 } else {
204 printk (KERN_NOTICE MSG_PREFIX
205 "Using %s partition definition\n", sbc8240_part_banks[i].mtd_part->name);
Thomas Gleixner69f34c92005-11-07 11:15:40 +0000206 add_mtd_partitions (sbc8240_mtd[i],
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 sbc8240_part_banks[i].mtd_part,
208 sbc8240_part_banks[i].nums);
209 }
210 }
211#else
212 printk(KERN_NOTICE MSG_PREFIX
213 "Registering %d flash banks at once\n", devicesfound);
214
215 for (i = 0; i < devicesfound; i++) {
216 add_mtd_device(sbc8240_mtd[i]);
217 }
218#endif /* CONFIG_MTD_PARTITIONS */
219
220 return devicesfound == 0 ? -ENXIO : 0;
221}
222
223static void __exit cleanup_sbc8240_mtd (void)
224{
225 int i;
226
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]);
231 }
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;
235 }
236 }
237}
238
239module_init (init_sbc8240_mtd);
240module_exit (cleanup_sbc8240_mtd);
241
242MODULE_LICENSE ("GPL");
243MODULE_AUTHOR ("Carolyn Smith <carolyn.smith@tektronix.com>");
244MODULE_DESCRIPTION ("MTD map driver for SBC8240 boards");
245