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.11 2004/09/16 23:27:12 gleixner 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>
22 #include <linux/init.h>
23 #include <linux/slab.h>
25 #include <linux/mtd/mtd.h>
26 #include <linux/mtd/map.h>
27 #include <linux/mtd/partitions.h>
28 #include <linux/mtd/concat.h>
30 #include <asm/hardware.h>
31 #include <asm/mach-types.h>
33 #include <asm/sizes.h>
36 * This isn't complete yet, so...
38 #define CONFIG_MTD_CEIVA_STATICMAP
40 #ifdef CONFIG_MTD_CEIVA_STATICMAP
42 * See include/linux/mtd/partitions.h for definition of the mtd_partition
46 * 1. The flash size given should be the largest flash size that can
49 * 2. The bus width must defined in clps_setup_flash.
51 * The MTD layer will detect flash chip aliasing and reduce the size of
52 * the map accordingly.
56 #ifdef CONFIG_ARCH_CEIVA
57 /* Flash / Partition sizing */
58 /* For the 28F8003, we use the block mapping to calcuate the sizes */
59 #define MAX_SIZE_KiB (16 + 8 + 8 + 96 + (7*128))
60 #define BOOT_PARTITION_SIZE_KiB (16)
61 #define PARAMS_PARTITION_SIZE_KiB (8)
62 #define KERNEL_PARTITION_SIZE_KiB (4*128)
63 /* Use both remaing portion of first flash, and all of second flash */
64 #define ROOT_PARTITION_SIZE_KiB (3*128) + (8*128)
66 static struct mtd_partition ceiva_partitions
[] = {
68 .name
= "Ceiva BOOT partition",
69 .size
= BOOT_PARTITION_SIZE_KiB
*1024,
73 .name
= "Ceiva parameters partition",
74 .size
= PARAMS_PARTITION_SIZE_KiB
*1024,
75 .offset
= (16 + 8) * 1024,
77 .name
= "Ceiva kernel partition",
78 .size
= (KERNEL_PARTITION_SIZE_KiB
)*1024,
82 .name
= "Ceiva root filesystem partition",
83 .offset
= MTDPART_OFS_APPEND
,
84 .size
= (ROOT_PARTITION_SIZE_KiB
)*1024,
89 static int __init
clps_static_partitions(struct mtd_partition
**parts
)
93 #ifdef CONFIG_ARCH_CEIVA
94 if (machine_is_ceiva()) {
95 *parts
= ceiva_partitions
;
96 nb_parts
= ARRAY_SIZE(ceiva_partitions
);
108 struct map_info
*map
;
109 struct mtd_info
*mtd
;
110 struct resource
*res
;
115 static struct clps_info info
[NR_SUBMTD
];
117 static int __init
clps_setup_mtd(struct clps_info
*clps
, int nr
, struct mtd_info
**rmtd
)
119 struct mtd_info
*subdev
[nr
];
120 struct map_info
*maps
;
121 int i
, found
= 0, ret
= 0;
124 * Allocate the map_info structs in one go.
126 maps
= kmalloc(sizeof(struct map_info
) * nr
, GFP_KERNEL
);
129 memset(maps
, 0, sizeof(struct map_info
) * nr
);
131 * Claim and then map the memory regions.
133 for (i
= 0; i
< nr
; i
++) {
134 if (clps
[i
].base
== (unsigned long)-1)
137 clps
[i
].res
= request_mem_region(clps
[i
].base
, clps
[i
].size
, "clps flash");
143 clps
[i
].map
= maps
+ i
;
145 clps
[i
].map
->name
= "clps flash";
146 clps
[i
].map
->phys
= clps
[i
].base
;
148 clps
[i
].vbase
= ioremap(clps
[i
].base
, clps
[i
].size
);
149 if (!clps
[i
].vbase
) {
154 clps
[i
].map
->virt
= (void __iomem
*)clps
[i
].vbase
;
155 clps
[i
].map
->bankwidth
= clps
[i
].width
;
156 clps
[i
].map
->size
= clps
[i
].size
;
158 simple_map_init(&clps
[i
].map
);
160 clps
[i
].mtd
= do_map_probe("jedec_probe", clps
[i
].map
);
161 if (clps
[i
].mtd
== NULL
) {
165 clps
[i
].mtd
->owner
= THIS_MODULE
;
166 subdev
[i
] = clps
[i
].mtd
;
168 printk(KERN_INFO
"clps flash: JEDEC device at 0x%08lx, %dMiB, "
169 "%d-bit\n", clps
[i
].base
, clps
[i
].mtd
->size
>> 20,
175 * ENXIO is special. It means we didn't find a chip when
176 * we probed. We need to tear down the mapping, free the
177 * resource and mark it as such.
180 iounmap(clps
[i
].vbase
);
181 clps
[i
].vbase
= NULL
;
182 release_resource(clps
[i
].res
);
187 * If we found one device, don't bother with concat support.
188 * If we found multiple devices, use concat if we have it
189 * available, otherwise fail.
191 if (ret
== 0 || ret
== -ENXIO
) {
195 } else if (found
> 1) {
197 * We detected multiple devices. Concatenate
200 #ifdef CONFIG_MTD_CONCAT
201 *rmtd
= mtd_concat_create(subdev
, found
,
206 printk(KERN_ERR
"clps flash: multiple devices "
207 "found but MTD concat support disabled.\n");
214 * If we failed, clean up.
219 map_destroy(clps
[i
].mtd
);
221 iounmap(clps
[i
].vbase
);
223 release_resource(clps
[i
].res
);
232 static void __exit
clps_destroy_mtd(struct clps_info
*clps
, struct mtd_info
*mtd
)
236 del_mtd_partitions(mtd
);
238 if (mtd
!= clps
[0].mtd
)
239 mtd_concat_destroy(mtd
);
241 for (i
= NR_SUBMTD
; i
>= 0; i
--) {
243 map_destroy(clps
[i
].mtd
);
245 iounmap(clps
[i
].vbase
);
247 release_resource(clps
[i
].res
);
253 * We define the memory space, size, and width for the flash memory
257 static int __init
clps_setup_flash(void)
261 #ifdef CONFIG_ARCH_CEIVA
262 if (machine_is_ceiva()) {
263 info
[0].base
= CS0_PHYS_BASE
;
264 info
[0].size
= SZ_32M
;
265 info
[0].width
= CEIVA_FLASH_WIDTH
;
266 info
[1].base
= CS1_PHYS_BASE
;
267 info
[1].size
= SZ_32M
;
268 info
[1].width
= CEIVA_FLASH_WIDTH
;
275 static struct mtd_partition
*parsed_parts
;
276 static const char *probes
[] = { "cmdlinepart", "RedBoot", NULL
};
278 static void __init
clps_locate_partitions(struct mtd_info
*mtd
)
280 const char *part_type
= NULL
;
284 * Partition selection stuff.
286 nr_parts
= parse_mtd_partitions(mtd
, probes
, &parsed_parts
, 0);
288 part_type
= "command line";
291 #ifdef CONFIG_MTD_CEIVA_STATICMAP
292 nr_parts
= clps_static_partitions(&parsed_parts
);
294 part_type
= "static";
297 printk("found: %d partitions\n", nr_parts
);
302 printk(KERN_NOTICE
"clps flash: no partition info "
303 "available, registering whole flash\n");
306 printk(KERN_NOTICE
"clps flash: using %s partition "
307 "definition\n", part_type
);
308 add_mtd_partitions(mtd
, parsed_parts
, nr_parts
);
311 /* Always succeeds. */
314 static void __exit
clps_destroy_partitions(void)
319 static struct mtd_info
*mymtd
;
321 static int __init
clps_mtd_init(void)
326 nr
= clps_setup_flash();
330 ret
= clps_setup_mtd(info
, nr
, &mymtd
);
334 clps_locate_partitions(mymtd
);
339 static void __exit
clps_mtd_cleanup(void)
341 clps_destroy_mtd(info
, mymtd
);
342 clps_destroy_partitions();
345 module_init(clps_mtd_init
);
346 module_exit(clps_mtd_cleanup
);
348 MODULE_AUTHOR("Rob Scott");
349 MODULE_DESCRIPTION("Cirrus Logic JEDEC map driver");
350 MODULE_LICENSE("GPL");