2 * Ceiva flash memory driver.
3 * Copyright (C) 2002 Rob Scott <rscott@mtrob.fdns.net>
5 * Note: this driver supports jedec compatible devices. Modification
6 * for CFI compatible devices should be straight forward: change
7 * jedec_probe to cfi_probe.
9 * Based on: sa1100-flash.c, which has the following copyright:
10 * Flash memory access on SA11x0 based devices
12 * (C) 2000 Nicolas Pitre <nico@cam.org>
14 * $Id: ceiva.c,v 1.2 2002/10/14 12:50:22 rmk Exp $
17 #include <linux/config.h>
18 #include <linux/module.h>
19 #include <linux/types.h>
20 #include <linux/ioport.h>
21 #include <linux/kernel.h>
23 #include <linux/mtd/mtd.h>
24 #include <linux/mtd/map.h>
25 #include <linux/mtd/partitions.h>
26 #include <linux/mtd/concat.h>
28 #include <asm/hardware.h>
29 #include <asm/mach-types.h>
31 #include <asm/sizes.h>
34 * This isnt complete yet, so...
36 #define CONFIG_MTD_CEIVA_STATICMAP
38 static __u8 clps_read8(struct map_info *map, unsigned long ofs)
40 return readb(map->map_priv_1 + ofs);
43 static __u16 clps_read16(struct map_info *map, unsigned long ofs)
45 return readw(map->map_priv_1 + ofs);
48 static __u32 clps_read32(struct map_info *map, unsigned long ofs)
50 return readl(map->map_priv_1 + ofs);
53 static void clps_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
55 memcpy(to, (void *)(map->map_priv_1 + from), len);
58 static void clps_write8(struct map_info *map, __u8 d, unsigned long adr)
60 writeb(d, map->map_priv_1 + adr);
63 static void clps_write16(struct map_info *map, __u16 d, unsigned long adr)
65 writew(d, map->map_priv_1 + adr);
68 static void clps_write32(struct map_info *map, __u32 d, unsigned long adr)
70 writel(d, map->map_priv_1 + adr);
73 static void clps_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
75 memcpy((void *)(map->map_priv_1 + to), from, len);
78 static struct map_info clps_map __initdata = {
83 copy_from: clps_copy_from,
85 write16: clps_write16,
86 write32: clps_write32,
87 copy_to: clps_copy_to,
90 #ifdef CONFIG_MTD_CEIVA_STATICMAP
92 * See include/linux/mtd/partitions.h for definition of the mtd_partition
96 * 1. The flash size given should be the largest flash size that can
99 * 2. The bus width must defined in clps_setup_flash.
101 * The MTD layer will detect flash chip aliasing and reduce the size of
102 * the map accordingly.
106 #ifdef CONFIG_ARCH_CEIVA
107 /* Flash / Partition sizing */
108 /* For the 28F8003, we use the block mapping to calcuate the sizes */
109 #define MAX_SIZE_KiB (16 + 8 + 8 + 96 + (7*128))
110 #define BOOT_PARTITION_SIZE_KiB (16)
111 #define PARAMS_PARTITION_SIZE_KiB (8)
112 #define KERNEL_PARTITION_SIZE_KiB (4*128)
113 /* Use both remaing portion of first flash, and all of second flash */
114 #define ROOT_PARTITION_SIZE_KiB (3*128) + (8*128)
116 static struct mtd_partition ceiva_partitions[] = {
118 name: "Ceiva BOOT partition",
119 size: BOOT_PARTITION_SIZE_KiB*1024,
123 name: "Ceiva parameters partition",
124 size: PARAMS_PARTITION_SIZE_KiB*1024,
125 offset: (16 + 8) * 1024,
127 name: "Ceiva kernel partition",
128 size: (KERNEL_PARTITION_SIZE_KiB)*1024,
132 name: "Ceiva root filesystem partition",
133 offset: MTDPART_OFS_APPEND,
134 size: (ROOT_PARTITION_SIZE_KiB)*1024,
139 static int __init clps_static_partitions(struct mtd_partition **parts)
143 #ifdef CONFIG_ARCH_CEIVA
144 if (machine_is_ceiva()) {
145 *parts = ceiva_partitions;
146 nb_parts = ARRAY_SIZE(ceiva_partitions);
158 struct map_info *map;
159 struct mtd_info *mtd;
160 struct resource *res;
165 static struct clps_info info[NR_SUBMTD];
167 static int __init clps_setup_mtd(struct clps_info *clps, int nr, struct mtd_info **rmtd)
169 struct mtd_info *subdev[nr];
170 struct map_info *maps;
171 int i, found = 0, ret = 0;
174 * Allocate the map_info structs in one go.
176 maps = kmalloc(sizeof(struct map_info) * nr, GFP_KERNEL);
181 * Claim and then map the memory regions.
183 for (i = 0; i < nr; i++) {
184 if (clps[i].base == (unsigned long)-1)
187 clps[i].res = request_mem_region(clps[i].base, clps[i].size, "clps flash");
193 clps[i].map = maps + i;
194 memcpy(clps[i].map, &clps_map, sizeof(struct map_info));
196 clps[i].vbase = ioremap(clps[i].base, clps[i].size);
197 if (!clps[i].vbase) {
202 clps[i].map->map_priv_1 = (unsigned long)clps[i].vbase;
203 clps[i].map->buswidth = clps[i].width;
204 clps[i].map->size = clps[i].size;
206 clps[i].mtd = do_map_probe("jedec_probe", clps[i].map);
207 if (clps[i].mtd == NULL) {
211 clps[i].mtd->module = THIS_MODULE;
212 subdev[i] = clps[i].mtd;
214 printk(KERN_INFO "clps flash: JEDEC device at 0x%08lx, %dMiB, "
215 "%d-bit\n", clps[i].base, clps[i].mtd->size >> 20,
221 * ENXIO is special. It means we didn't find a chip when
222 * we probed. We need to tear down the mapping, free the
223 * resource and mark it as such.
226 iounmap(clps[i].vbase);
227 clps[i].vbase = NULL;
228 release_resource(clps[i].res);
233 * If we found one device, don't bother with concat support.
234 * If we found multiple devices, use concat if we have it
235 * available, otherwise fail.
237 if (ret == 0 || ret == -ENXIO) {
241 } else if (found > 1) {
243 * We detected multiple devices. Concatenate
246 #ifdef CONFIG_MTD_CONCAT
247 *rmtd = mtd_concat_create(subdev, found,
252 printk(KERN_ERR "clps flash: multiple devices "
253 "found but MTD concat support disabled.\n");
260 * If we failed, clean up.
265 map_destroy(clps[i].mtd);
267 iounmap(clps[i].vbase);
269 release_resource(clps[i].res);
278 static void __exit clps_destroy_mtd(struct clps_info *clps, struct mtd_info *mtd)
282 del_mtd_partitions(mtd);
284 if (mtd != clps[0].mtd)
285 mtd_concat_destroy(mtd);
287 for (i = NR_SUBMTD; i >= 0; i--) {
289 map_destroy(clps[i].mtd);
291 iounmap(clps[i].vbase);
293 release_resource(clps[i].res);
299 * We define the memory space, size, and width for the flash memory
303 static int __init clps_setup_flash(void)
307 #ifdef CONFIG_ARCH_CEIVA
308 if (machine_is_ceiva()) {
309 info[0].base = CS0_PHYS_BASE;
310 info[0].size = SZ_32M;
311 info[0].width = CEIVA_FLASH_WIDTH;
312 info[1].base = CS1_PHYS_BASE;
313 info[1].size = SZ_32M;
314 info[1].width = CEIVA_FLASH_WIDTH;
321 extern int parse_redboot_partitions(struct mtd_info *master, struct mtd_partition **pparts);
322 extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, char *);
324 static struct mtd_partition *parsed_parts;
326 static void __init clps_locate_partitions(struct mtd_info *mtd)
328 const char *part_type = NULL;
332 * Partition selection stuff.
334 #ifdef CONFIG_MTD_CMDLINE_PARTS
335 nr_parts = parse_cmdline_partitions(mtd, &parsed_parts, "clps");
337 part_type = "command line";
341 #ifdef CONFIG_MTD_REDBOOT_PARTS
342 nr_parts = parse_redboot_partitions(mtd, &parsed_parts);
344 part_type = "RedBoot";
348 #ifdef CONFIG_MTD_CEIVA_STATICMAP
349 nr_parts = clps_static_partitions(&parsed_parts);
351 part_type = "static";
354 printk("found: %d partitions\n", nr_parts);
359 printk(KERN_NOTICE "clps flash: no partition info "
360 "available, registering whole flash\n");
363 printk(KERN_NOTICE "clps flash: using %s partition "
364 "definition\n", part_type);
365 add_mtd_partitions(mtd, parsed_parts, nr_parts);
368 /* Always succeeds. */
371 static void __exit clps_destroy_partitions(void)
377 static struct mtd_info *mymtd;
379 static int __init clps_mtd_init(void)
384 nr = clps_setup_flash();
388 ret = clps_setup_mtd(info, nr, &mymtd);
392 clps_locate_partitions(mymtd);
397 static void __exit clps_mtd_cleanup(void)
399 clps_destroy_mtd(info, mymtd);
400 clps_destroy_partitions();
403 module_init(clps_mtd_init);
404 module_exit(clps_mtd_cleanup);
406 MODULE_AUTHOR("Rob Scott");
407 MODULE_DESCRIPTION("Cirrus Logic JEDEC map driver");
408 MODULE_LICENSE("GPL");