2 * $Id: physmap.c,v 1.39 2005/11/29 14:49:36 gleixner Exp $
4 * Normal mappings of chips in physical memory
6 * Copyright (C) 2003 MontaVista Software Inc.
7 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
9 * 031022 - [jsun] add run-time configure and partition setup
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/device.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/map.h>
21 #include <linux/config.h>
22 #include <linux/mtd/partitions.h>
23 #include <linux/mtd/physmap.h>
25 #include <asm/mach/flash.h>
27 struct physmap_flash_info {
31 #ifdef CONFIG_MTD_PARTITIONS
33 struct mtd_partition *parts;
38 static int physmap_flash_remove(struct platform_device *dev)
40 struct physmap_flash_info *info;
41 struct physmap_flash_data *physmap_data;
43 info = platform_get_drvdata(dev);
46 platform_set_drvdata(dev, NULL);
48 physmap_data = dev->dev.platform_data;
50 if (info->mtd != NULL) {
51 #ifdef CONFIG_MTD_PARTITIONS
53 del_mtd_partitions(info->mtd);
55 } else if (physmap_data->nr_parts) {
56 del_mtd_partitions(info->mtd);
58 del_mtd_device(info->mtd);
61 del_mtd_device(info->mtd);
63 map_destroy(info->mtd);
66 if (info->map.virt != NULL)
67 iounmap((void *)info->map.virt);
69 if (info->res != NULL) {
70 release_resource(info->res);
77 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
78 #ifdef CONFIG_MTD_PARTITIONS
79 static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
82 static int physmap_flash_probe(struct platform_device *dev)
84 struct physmap_flash_data *physmap_data;
85 struct physmap_flash_info *info;
86 const char **probe_type;
89 physmap_data = dev->dev.platform_data;
90 if (physmap_data == NULL)
93 printk(KERN_NOTICE "physmap platform flash device: %.8lx at %.8lx\n",
94 dev->resource->end - dev->resource->start + 1,
95 dev->resource->start);
97 info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
102 memset(info, 0, sizeof(*info));
104 platform_set_drvdata(dev, info);
106 info->res = request_mem_region(dev->resource->start,
107 dev->resource->end - dev->resource->start + 1,
109 if (info->res == NULL) {
110 dev_err(&dev->dev, "Could not reserve memory region\n");
115 info->map.name = dev->dev.bus_id;
116 info->map.phys = dev->resource->start;
117 info->map.size = dev->resource->end - dev->resource->start + 1;
118 info->map.bankwidth = physmap_data->width;
119 info->map.set_vpp = physmap_data->set_vpp;
121 info->map.virt = ioremap(info->map.phys, info->map.size);
122 if (info->map.virt == NULL) {
123 dev_err(&dev->dev, "Failed to ioremap flash region\n");
128 simple_map_init(&info->map);
130 probe_type = rom_probe_types;
131 for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
132 info->mtd = do_map_probe(*probe_type, &info->map);
133 if (info->mtd == NULL) {
134 dev_err(&dev->dev, "map_probe failed\n");
138 info->mtd->owner = THIS_MODULE;
140 #ifdef CONFIG_MTD_PARTITIONS
141 err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
143 add_mtd_partitions(info->mtd, info->parts, err);
147 if (physmap_data->nr_parts) {
148 printk(KERN_NOTICE "Using physmap partition information\n");
149 add_mtd_partitions(info->mtd, physmap_data->parts,
150 physmap_data->nr_parts);
155 add_mtd_device(info->mtd);
159 physmap_flash_remove(dev);
163 static struct platform_driver physmap_flash_driver = {
164 .probe = physmap_flash_probe,
165 .remove = physmap_flash_remove,
167 .name = "physmap-flash",
172 #ifdef CONFIG_MTD_PHYSMAP_LEN
173 #if CONFIG_MTD_PHYSMAP_LEN != 0
174 #warning using PHYSMAP compat code
175 #define PHYSMAP_COMPAT
179 #ifdef PHYSMAP_COMPAT
180 static struct physmap_flash_data physmap_flash_data = {
181 .width = CONFIG_MTD_PHYSMAP_BANKWIDTH,
184 static struct resource physmap_flash_resource = {
185 .start = CONFIG_MTD_PHYSMAP_START,
186 .end = CONFIG_MTD_PHYSMAP_START + CONFIG_MTD_PHYSMAP_LEN,
187 .flags = IORESOURCE_MEM,
190 static struct platform_device physmap_flash = {
191 .name = "physmap-flash",
194 .platform_data = &physmap_flash_data,
197 .resource = &physmap_flash_resource,
200 void physmap_configure(unsigned long addr, unsigned long size,
201 int bankwidth, void (*set_vpp)(struct map_info *, int))
203 physmap_flash_resource.start = addr;
204 physmap_flash_resource.end = addr + size - 1;
205 physmap_flash_data.width = bankwidth;
206 physmap_flash_data.set_vpp = set_vpp;
209 #ifdef CONFIG_MTD_PARTITIONS
210 void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
212 physmap_flash_data.nr_parts = num_parts;
213 physmap_flash_data.parts = parts;
218 static int __init physmap_init(void)
222 err = platform_driver_register(&physmap_flash_driver);
223 #ifdef PHYSMAP_COMPAT
225 platform_device_register(&physmap_flash);
231 static void __exit physmap_exit(void)
233 #ifdef PHYSMAP_COMPAT
234 platform_device_unregister(&physmap_flash);
236 platform_driver_unregister(&physmap_flash_driver);
239 module_init(physmap_init);
240 module_exit(physmap_exit);
242 MODULE_LICENSE("GPL");
243 MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
244 MODULE_DESCRIPTION("Generic configurable MTD map driver");