1 /*======================================================================
3 drivers/mtd/maps/integrator-flash.c: ARM Integrator flash map driver
5 Copyright (C) 2000 ARM Limited
6 Copyright (C) 2003 Deep Blue Solutions Ltd.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 This is access code for flashes using ARM's flash partitioning
25 ======================================================================*/
27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/kernel.h>
30 #include <linux/slab.h>
31 #include <linux/ioport.h>
32 #include <linux/platform_device.h>
33 #include <linux/init.h>
36 #include <linux/mtd/mtd.h>
37 #include <linux/mtd/map.h>
38 #include <linux/mtd/partitions.h>
39 #include <linux/mtd/concat.h>
41 #include <asm/mach/flash.h>
42 #include <mach/hardware.h>
43 #include <asm/system.h>
45 #define SUBDEV_NAME_SIZE (BUS_ID_SIZE + 2)
47 struct armflash_subdev_info {
48 char name[SUBDEV_NAME_SIZE];
51 struct flash_platform_data *plat;
54 struct armflash_info {
56 struct mtd_partition *parts;
59 struct armflash_subdev_info subdev[0];
62 static void armflash_set_vpp(struct map_info *map, int on)
64 struct armflash_subdev_info *info =
65 container_of(map, struct armflash_subdev_info, map);
67 if (info->plat && info->plat->set_vpp)
68 info->plat->set_vpp(on);
71 static const char *probes[] = { "cmdlinepart", "RedBoot", "afs", NULL };
73 static int armflash_subdev_probe(struct armflash_subdev_info *subdev,
76 struct flash_platform_data *plat = subdev->plat;
77 resource_size_t size = res->end - res->start + 1;
81 if (!request_mem_region(res->start, size, subdev->name)) {
86 base = ioremap(res->start, size);
93 * look for CFI based flash parts fitted to this board
95 subdev->map.size = size;
96 subdev->map.bankwidth = plat->width;
97 subdev->map.phys = res->start;
98 subdev->map.virt = base;
99 subdev->map.name = subdev->name;
100 subdev->map.set_vpp = armflash_set_vpp;
102 simple_map_init(&subdev->map);
105 * Also, the CFI layer automatically works out what size
106 * of chips we have, and does the necessary identification
107 * for us automatically.
109 subdev->mtd = do_map_probe(plat->map_name, &subdev->map);
115 subdev->mtd->owner = THIS_MODULE;
122 map_destroy(subdev->mtd);
126 release_mem_region(res->start, size);
131 static void armflash_subdev_remove(struct armflash_subdev_info *subdev)
134 map_destroy(subdev->mtd);
135 if (subdev->map.virt)
136 iounmap(subdev->map.virt);
137 release_mem_region(subdev->map.phys, subdev->map.size);
140 static int armflash_probe(struct platform_device *dev)
142 struct flash_platform_data *plat = dev->dev.platform_data;
144 struct armflash_info *info;
147 /* Count the number of devices */
149 if (!platform_get_resource(dev, IORESOURCE_MEM, nr))
156 size = sizeof(struct armflash_info) +
157 sizeof(struct armflash_subdev_info) * nr;
158 info = kzalloc(size, GFP_KERNEL);
164 if (plat && plat->init) {
170 for (i = 0; i < nr; i++) {
171 struct armflash_subdev_info *subdev = &info->subdev[i];
172 struct resource *res;
174 res = platform_get_resource(dev, IORESOURCE_MEM, i);
179 /* No MTD concatenation, just use the default name */
180 snprintf(subdev->name, SUBDEV_NAME_SIZE, "%s",
181 dev_name(&dev->dev));
183 snprintf(subdev->name, SUBDEV_NAME_SIZE, "%s-%d",
184 dev_name(&dev->dev), i);
187 err = armflash_subdev_probe(subdev, res);
196 if (info->nr_subdev == 1)
197 info->mtd = info->subdev[0].mtd;
198 else if (info->nr_subdev > 1) {
199 #ifdef CONFIG_MTD_CONCAT
200 struct mtd_info *cdev[info->nr_subdev];
203 * We detected multiple devices. Concatenate them together.
205 for (i = 0; i < info->nr_subdev; i++)
206 cdev[i] = info->subdev[i].mtd;
208 info->mtd = mtd_concat_create(cdev, info->nr_subdev,
209 dev_name(&dev->dev));
210 if (info->mtd == NULL)
213 printk(KERN_ERR "armflash: multiple devices found but "
214 "MTD concat support disabled.\n");
222 err = parse_mtd_partitions(info->mtd, probes, &info->parts, 0);
224 err = add_mtd_partitions(info->mtd, info->parts, err);
227 "mtd partition registration failed: %d\n", err);
231 platform_set_drvdata(dev, info);
236 * We got an error, free all resources.
240 del_mtd_partitions(info->mtd);
241 #ifdef CONFIG_MTD_CONCAT
242 if (info->mtd != info->subdev[0].mtd)
243 mtd_concat_destroy(info->mtd);
248 for (i = info->nr_subdev - 1; i >= 0; i--)
249 armflash_subdev_remove(&info->subdev[i]);
251 if (plat && plat->exit)
258 static int armflash_remove(struct platform_device *dev)
260 struct armflash_info *info = platform_get_drvdata(dev);
261 struct flash_platform_data *plat = dev->dev.platform_data;
264 platform_set_drvdata(dev, NULL);
268 del_mtd_partitions(info->mtd);
269 #ifdef CONFIG_MTD_CONCAT
270 if (info->mtd != info->subdev[0].mtd)
271 mtd_concat_destroy(info->mtd);
276 for (i = info->nr_subdev - 1; i >= 0; i--)
277 armflash_subdev_remove(&info->subdev[i]);
279 if (plat && plat->exit)
288 static struct platform_driver armflash_driver = {
289 .probe = armflash_probe,
290 .remove = armflash_remove,
293 .owner = THIS_MODULE,
297 static int __init armflash_init(void)
299 return platform_driver_register(&armflash_driver);
302 static void __exit armflash_exit(void)
304 platform_driver_unregister(&armflash_driver);
307 module_init(armflash_init);
308 module_exit(armflash_exit);
310 MODULE_AUTHOR("ARM Ltd");
311 MODULE_DESCRIPTION("ARM Integrator CFI map driver");
312 MODULE_LICENSE("GPL");
313 MODULE_ALIAS("platform:armflash");