aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd/maps/physmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/mtd/maps/physmap.c')
-rw-r--r--drivers/mtd/maps/physmap.c255
1 files changed, 186 insertions, 69 deletions
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index f49ebc3c4606..433c3cac3ca9 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -14,112 +14,229 @@
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <asm/io.h> 17#include <linux/device.h>
18#include <linux/platform_device.h>
18#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
19#include <linux/mtd/map.h> 20#include <linux/mtd/map.h>
20#include <linux/config.h> 21#include <linux/config.h>
21#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
22#include <linux/mtd/physmap.h> 23#include <linux/mtd/physmap.h>
24#include <asm/io.h>
23 25
24static struct mtd_info *mymtd; 26struct physmap_flash_info {
25 27 struct mtd_info *mtd;
26struct map_info physmap_map = { 28 struct map_info map;
27 .name = "phys_mapped_flash", 29 struct resource *res;
28 .phys = CONFIG_MTD_PHYSMAP_START, 30#ifdef CONFIG_MTD_PARTITIONS
29 .size = CONFIG_MTD_PHYSMAP_LEN, 31 int nr_parts;
30 .bankwidth = CONFIG_MTD_PHYSMAP_BANKWIDTH, 32 struct mtd_partition *parts;
33#endif
31}; 34};
32 35
36
37static int physmap_flash_remove(struct platform_device *dev)
38{
39 struct physmap_flash_info *info;
40 struct physmap_flash_data *physmap_data;
41
42 info = platform_get_drvdata(dev);
43 if (info == NULL)
44 return 0;
45 platform_set_drvdata(dev, NULL);
46
47 physmap_data = dev->dev.platform_data;
48
49 if (info->mtd != NULL) {
33#ifdef CONFIG_MTD_PARTITIONS 50#ifdef CONFIG_MTD_PARTITIONS
34static struct mtd_partition *mtd_parts; 51 if (info->nr_parts) {
35static int mtd_parts_nb; 52 del_mtd_partitions(info->mtd);
53 kfree(info->parts);
54 } else if (physmap_data->nr_parts) {
55 del_mtd_partitions(info->mtd);
56 } else {
57 del_mtd_device(info->mtd);
58 }
59#else
60 del_mtd_device(info->mtd);
61#endif
62 map_destroy(info->mtd);
63 }
36 64
37static int num_physmap_partitions; 65 if (info->map.virt != NULL)
38static struct mtd_partition *physmap_partitions; 66 iounmap((void *)info->map.virt);
39 67
40static const char *part_probes[] __initdata = {"cmdlinepart", "RedBoot", NULL}; 68 if (info->res != NULL) {
69 release_resource(info->res);
70 kfree(info->res);
71 }
41 72
42void physmap_set_partitions(struct mtd_partition *parts, int num_parts) 73 return 0;
43{
44 physmap_partitions=parts;
45 num_physmap_partitions=num_parts;
46} 74}
47#endif /* CONFIG_MTD_PARTITIONS */
48 75
49static int __init init_physmap(void) 76static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL };
77#ifdef CONFIG_MTD_PARTITIONS
78static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
79#endif
80
81static int physmap_flash_probe(struct platform_device *dev)
50{ 82{
51 static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", "map_rom", NULL }; 83 struct physmap_flash_data *physmap_data;
52 const char **type; 84 struct physmap_flash_info *info;
85 const char **probe_type;
86 int err;
87
88 physmap_data = dev->dev.platform_data;
89 if (physmap_data == NULL)
90 return -ENODEV;
91
92 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
93 (unsigned long long)dev->resource->end - dev->resource->start + 1,
94 (unsigned long long)dev->resource->start);
95
96 info = kmalloc(sizeof(struct physmap_flash_info), GFP_KERNEL);
97 if (info == NULL) {
98 err = -ENOMEM;
99 goto err_out;
100 }
101 memset(info, 0, sizeof(*info));
53 102
54 printk(KERN_NOTICE "physmap flash device: %lx at %lx\n", physmap_map.size, physmap_map.phys); 103 platform_set_drvdata(dev, info);
55 physmap_map.virt = ioremap(physmap_map.phys, physmap_map.size);
56 104
57 if (!physmap_map.virt) { 105 info->res = request_mem_region(dev->resource->start,
58 printk("Failed to ioremap\n"); 106 dev->resource->end - dev->resource->start + 1,
59 return -EIO; 107 dev->dev.bus_id);
108 if (info->res == NULL) {
109 dev_err(&dev->dev, "Could not reserve memory region\n");
110 err = -ENOMEM;
111 goto err_out;
60 } 112 }
61 113
62 simple_map_init(&physmap_map); 114 info->map.name = dev->dev.bus_id;
115 info->map.phys = dev->resource->start;
116 info->map.size = dev->resource->end - dev->resource->start + 1;
117 info->map.bankwidth = physmap_data->width;
118 info->map.set_vpp = physmap_data->set_vpp;
119
120 info->map.virt = ioremap(info->map.phys, info->map.size);
121 if (info->map.virt == NULL) {
122 dev_err(&dev->dev, "Failed to ioremap flash region\n");
123 err = EIO;
124 goto err_out;
125 }
63 126
64 mymtd = NULL; 127 simple_map_init(&info->map);
65 type = rom_probe_types; 128
66 for(; !mymtd && *type; type++) { 129 probe_type = rom_probe_types;
67 mymtd = do_map_probe(*type, &physmap_map); 130 for (; info->mtd == NULL && *probe_type != NULL; probe_type++)
131 info->mtd = do_map_probe(*probe_type, &info->map);
132 if (info->mtd == NULL) {
133 dev_err(&dev->dev, "map_probe failed\n");
134 err = -ENXIO;
135 goto err_out;
68 } 136 }
69 if (mymtd) { 137 info->mtd->owner = THIS_MODULE;
70 mymtd->owner = THIS_MODULE;
71 138
72#ifdef CONFIG_MTD_PARTITIONS 139#ifdef CONFIG_MTD_PARTITIONS
73 mtd_parts_nb = parse_mtd_partitions(mymtd, part_probes, 140 err = parse_mtd_partitions(info->mtd, part_probe_types, &info->parts, 0);
74 &mtd_parts, 0); 141 if (err > 0) {
142 add_mtd_partitions(info->mtd, info->parts, err);
143 return 0;
144 }
75 145
76 if (mtd_parts_nb > 0) 146 if (physmap_data->nr_parts) {
77 { 147 printk(KERN_NOTICE "Using physmap partition information\n");
78 add_mtd_partitions (mymtd, mtd_parts, mtd_parts_nb); 148 add_mtd_partitions(info->mtd, physmap_data->parts,
79 return 0; 149 physmap_data->nr_parts);
80 } 150 return 0;
151 }
152#endif
153
154 add_mtd_device(info->mtd);
155 return 0;
156
157err_out:
158 physmap_flash_remove(dev);
159 return err;
160}
161
162static struct platform_driver physmap_flash_driver = {
163 .probe = physmap_flash_probe,
164 .remove = physmap_flash_remove,
165 .driver = {
166 .name = "physmap-flash",
167 },
168};
81 169
82 if (num_physmap_partitions != 0)
83 {
84 printk(KERN_NOTICE
85 "Using physmap partition definition\n");
86 add_mtd_partitions (mymtd, physmap_partitions, num_physmap_partitions);
87 return 0;
88 }
89 170
171#ifdef CONFIG_MTD_PHYSMAP_LEN
172#if CONFIG_MTD_PHYSMAP_LEN != 0
173#warning using PHYSMAP compat code
174#define PHYSMAP_COMPAT
175#endif
90#endif 176#endif
91 add_mtd_device(mymtd);
92 177
93 return 0; 178#ifdef PHYSMAP_COMPAT
94 } 179static struct physmap_flash_data physmap_flash_data = {
180 .width = CONFIG_MTD_PHYSMAP_BANKWIDTH,
181};
95 182
96 iounmap(physmap_map.virt); 183static struct resource physmap_flash_resource = {
97 return -ENXIO; 184 .start = CONFIG_MTD_PHYSMAP_START,
98} 185 .end = CONFIG_MTD_PHYSMAP_START + CONFIG_MTD_PHYSMAP_LEN,
186 .flags = IORESOURCE_MEM,
187};
99 188
100static void __exit cleanup_physmap(void) 189static struct platform_device physmap_flash = {
190 .name = "physmap-flash",
191 .id = 0,
192 .dev = {
193 .platform_data = &physmap_flash_data,
194 },
195 .num_resources = 1,
196 .resource = &physmap_flash_resource,
197};
198
199void physmap_configure(unsigned long addr, unsigned long size,
200 int bankwidth, void (*set_vpp)(struct map_info *, int))
101{ 201{
202 physmap_flash_resource.start = addr;
203 physmap_flash_resource.end = addr + size - 1;
204 physmap_flash_data.width = bankwidth;
205 physmap_flash_data.set_vpp = set_vpp;
206}
207
102#ifdef CONFIG_MTD_PARTITIONS 208#ifdef CONFIG_MTD_PARTITIONS
103 if (mtd_parts_nb) { 209void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
104 del_mtd_partitions(mymtd); 210{
105 kfree(mtd_parts); 211 physmap_flash_data.nr_parts = num_parts;
106 } else if (num_physmap_partitions) { 212 physmap_flash_data.parts = parts;
107 del_mtd_partitions(mymtd); 213}
108 } else { 214#endif
109 del_mtd_device(mymtd);
110 }
111#else
112 del_mtd_device(mymtd);
113#endif 215#endif
114 map_destroy(mymtd);
115 216
116 iounmap(physmap_map.virt); 217static int __init physmap_init(void)
117 physmap_map.virt = NULL; 218{
219 int err;
220
221 err = platform_driver_register(&physmap_flash_driver);
222#ifdef PHYSMAP_COMPAT
223 if (err == 0)
224 platform_device_register(&physmap_flash);
225#endif
226
227 return err;
118} 228}
119 229
120module_init(init_physmap); 230static void __exit physmap_exit(void)
121module_exit(cleanup_physmap); 231{
232#ifdef PHYSMAP_COMPAT
233 platform_device_unregister(&physmap_flash);
234#endif
235 platform_driver_unregister(&physmap_flash_driver);
236}
122 237
238module_init(physmap_init);
239module_exit(physmap_exit);
123 240
124MODULE_LICENSE("GPL"); 241MODULE_LICENSE("GPL");
125MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 242MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");