]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/mtd/maps/physmap.c
ARM: 6906/1: MTD: Remove integrator-flash
[mirror_ubuntu-artful-kernel.git] / drivers / mtd / maps / physmap.c
CommitLineData
1da177e4 1/*
1da177e4
LT
2 * Normal mappings of chips in physical memory
3 *
4 * Copyright (C) 2003 MontaVista Software Inc.
5 * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
6 *
7 * 031022 - [jsun] add run-time configure and partition setup
8 */
9
10#include <linux/module.h>
11#include <linux/types.h>
12#include <linux/kernel.h>
13#include <linux/init.h>
14#include <linux/slab.h>
73566edf
LB
15#include <linux/device.h>
16#include <linux/platform_device.h>
1da177e4
LT
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/map.h>
1da177e4 19#include <linux/mtd/partitions.h>
2b9175c1 20#include <linux/mtd/physmap.h>
df66e716 21#include <linux/mtd/concat.h>
3136e903 22#include <linux/io.h>
1da177e4 23
df66e716
SR
24#define MAX_RESOURCES 4
25
73566edf 26struct physmap_flash_info {
df66e716
SR
27 struct mtd_info *mtd[MAX_RESOURCES];
28 struct mtd_info *cmtd;
29 struct map_info map[MAX_RESOURCES];
73566edf
LB
30#ifdef CONFIG_MTD_PARTITIONS
31 int nr_parts;
e480814f 32 struct mtd_partition *parts;
73566edf 33#endif
1da177e4
LT
34};
35
73566edf
LB
36static int physmap_flash_remove(struct platform_device *dev)
37{
38 struct physmap_flash_info *info;
39 struct physmap_flash_data *physmap_data;
df66e716 40 int i;
73566edf
LB
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
8ce110ac
HS
49 if (info->cmtd) {
50#ifdef CONFIG_MTD_PARTITIONS
4b56ffca 51 if (info->nr_parts || physmap_data->nr_parts) {
d58ab5cf 52 del_mtd_partitions(info->cmtd);
4b56ffca
HS
53
54 if (info->nr_parts)
55 kfree(info->parts);
56 } else {
d58ab5cf 57 del_mtd_device(info->cmtd);
4b56ffca 58 }
8ce110ac 59#else
d58ab5cf 60 del_mtd_device(info->cmtd);
8ce110ac 61#endif
8ce110ac
HS
62 if (info->cmtd != info->mtd[0])
63 mtd_concat_destroy(info->cmtd);
8ce110ac 64 }
df66e716
SR
65
66 for (i = 0; i < MAX_RESOURCES; i++) {
e480814f 67 if (info->mtd[i] != NULL)
df66e716 68 map_destroy(info->mtd[i]);
73566edf 69 }
b7281ca2
MZ
70
71 if (physmap_data->exit)
72 physmap_data->exit(dev);
73
73566edf 74 return 0;
1da177e4 75}
1da177e4 76
d8140830
AK
77static const char *rom_probe_types[] = {
78 "cfi_probe",
79 "jedec_probe",
80 "qinfo_probe",
81 "map_rom",
82 NULL };
73566edf 83#ifdef CONFIG_MTD_PARTITIONS
b7281ca2
MZ
84static const char *part_probe_types[] = { "cmdlinepart", "RedBoot",
85#ifdef CONFIG_MTD_AFS_PARTS
86 "afs",
87#endif
88 NULL };
73566edf
LB
89#endif
90
91static int physmap_flash_probe(struct platform_device *dev)
1da177e4 92{
73566edf
LB
93 struct physmap_flash_data *physmap_data;
94 struct physmap_flash_info *info;
95 const char **probe_type;
df66e716
SR
96 int err = 0;
97 int i;
98 int devices_found = 0;
73566edf
LB
99
100 physmap_data = dev->dev.platform_data;
101 if (physmap_data == NULL)
102 return -ENODEV;
103
3136e903
AN
104 info = devm_kzalloc(&dev->dev, sizeof(struct physmap_flash_info),
105 GFP_KERNEL);
73566edf
LB
106 if (info == NULL) {
107 err = -ENOMEM;
108 goto err_out;
109 }
1da177e4 110
b7281ca2
MZ
111 if (physmap_data->init) {
112 err = physmap_data->init(dev);
113 if (err)
114 goto err_out;
115 }
116
73566edf 117 platform_set_drvdata(dev, info);
1da177e4 118
df66e716
SR
119 for (i = 0; i < dev->num_resources; i++) {
120 printk(KERN_NOTICE "physmap platform flash device: %.8llx at %.8llx\n",
1d90d2c3 121 (unsigned long long)resource_size(&dev->resource[i]),
df66e716
SR
122 (unsigned long long)dev->resource[i].start);
123
3136e903
AN
124 if (!devm_request_mem_region(&dev->dev,
125 dev->resource[i].start,
1d90d2c3 126 resource_size(&dev->resource[i]),
160bbab3 127 dev_name(&dev->dev))) {
df66e716
SR
128 dev_err(&dev->dev, "Could not reserve memory region\n");
129 err = -ENOMEM;
130 goto err_out;
131 }
1da177e4 132
160bbab3 133 info->map[i].name = dev_name(&dev->dev);
df66e716 134 info->map[i].phys = dev->resource[i].start;
1d90d2c3 135 info->map[i].size = resource_size(&dev->resource[i]);
df66e716
SR
136 info->map[i].bankwidth = physmap_data->width;
137 info->map[i].set_vpp = physmap_data->set_vpp;
d8140830 138 info->map[i].pfow_base = physmap_data->pfow_base;
df66e716 139
3136e903
AN
140 info->map[i].virt = devm_ioremap(&dev->dev, info->map[i].phys,
141 info->map[i].size);
df66e716
SR
142 if (info->map[i].virt == NULL) {
143 dev_err(&dev->dev, "Failed to ioremap flash region\n");
895fb494 144 err = -EIO;
df66e716
SR
145 goto err_out;
146 }
73566edf 147
df66e716 148 simple_map_init(&info->map[i]);
1da177e4 149
df66e716 150 probe_type = rom_probe_types;
78ef7fab
BS
151 if (physmap_data->probe_type == NULL) {
152 for (; info->mtd[i] == NULL && *probe_type != NULL; probe_type++)
153 info->mtd[i] = do_map_probe(*probe_type, &info->map[i]);
154 } else
155 info->mtd[i] = do_map_probe(physmap_data->probe_type, &info->map[i]);
156
df66e716
SR
157 if (info->mtd[i] == NULL) {
158 dev_err(&dev->dev, "map_probe failed\n");
159 err = -ENXIO;
160 goto err_out;
161 } else {
162 devices_found++;
163 }
164 info->mtd[i]->owner = THIS_MODULE;
87f39f04 165 info->mtd[i]->dev.parent = &dev->dev;
df66e716 166 }
73566edf 167
df66e716
SR
168 if (devices_found == 1) {
169 info->cmtd = info->mtd[0];
170 } else if (devices_found > 1) {
171 /*
172 * We detected multiple devices. Concatenate them together.
173 */
160bbab3 174 info->cmtd = mtd_concat_create(info->mtd, devices_found, dev_name(&dev->dev));
df66e716
SR
175 if (info->cmtd == NULL)
176 err = -ENXIO;
1da177e4 177 }
df66e716
SR
178 if (err)
179 goto err_out;
1da177e4 180
8ce110ac
HS
181#ifdef CONFIG_MTD_PARTITIONS
182 err = parse_mtd_partitions(info->cmtd, part_probe_types,
183 &info->parts, 0);
184 if (err > 0) {
185 add_mtd_partitions(info->cmtd, info->parts, err);
186 info->nr_parts = err;
187 return 0;
188 }
1da177e4 189
8ce110ac
HS
190 if (physmap_data->nr_parts) {
191 printk(KERN_NOTICE "Using physmap partition information\n");
192 add_mtd_partitions(info->cmtd, physmap_data->parts,
193 physmap_data->nr_parts);
194 return 0;
73566edf 195 }
8ce110ac 196#endif
73566edf 197
df66e716 198 add_mtd_device(info->cmtd);
73566edf
LB
199 return 0;
200
201err_out:
202 physmap_flash_remove(dev);
203 return err;
204}
205
17c2dae3 206#ifdef CONFIG_PM
17c2dae3
LB
207static void physmap_flash_shutdown(struct platform_device *dev)
208{
209 struct physmap_flash_info *info = platform_get_drvdata(dev);
df66e716
SR
210 int i;
211
4a5691c0 212 for (i = 0; i < MAX_RESOURCES && info->mtd[i]; i++)
7b249191
RJ
213 if (info->mtd[i]->suspend && info->mtd[i]->resume)
214 if (info->mtd[i]->suspend(info->mtd[i]) == 0)
215 info->mtd[i]->resume(info->mtd[i]);
17c2dae3 216}
d5476689 217#else
d5476689 218#define physmap_flash_shutdown NULL
17c2dae3
LB
219#endif
220
73566edf
LB
221static struct platform_driver physmap_flash_driver = {
222 .probe = physmap_flash_probe,
223 .remove = physmap_flash_remove,
17c2dae3 224 .shutdown = physmap_flash_shutdown,
73566edf
LB
225 .driver = {
226 .name = "physmap-flash",
41d867c9 227 .owner = THIS_MODULE,
73566edf
LB
228 },
229};
1da177e4 230
1da177e4 231
dcb3e137 232#ifdef CONFIG_MTD_PHYSMAP_COMPAT
73566edf
LB
233static struct physmap_flash_data physmap_flash_data = {
234 .width = CONFIG_MTD_PHYSMAP_BANKWIDTH,
235};
1da177e4 236
73566edf
LB
237static struct resource physmap_flash_resource = {
238 .start = CONFIG_MTD_PHYSMAP_START,
6d4f8224 239 .end = CONFIG_MTD_PHYSMAP_START + CONFIG_MTD_PHYSMAP_LEN - 1,
73566edf
LB
240 .flags = IORESOURCE_MEM,
241};
1da177e4 242
73566edf
LB
243static struct platform_device physmap_flash = {
244 .name = "physmap-flash",
245 .id = 0,
246 .dev = {
247 .platform_data = &physmap_flash_data,
248 },
249 .num_resources = 1,
250 .resource = &physmap_flash_resource,
251};
252
253void physmap_configure(unsigned long addr, unsigned long size,
254 int bankwidth, void (*set_vpp)(struct map_info *, int))
1da177e4 255{
73566edf
LB
256 physmap_flash_resource.start = addr;
257 physmap_flash_resource.end = addr + size - 1;
258 physmap_flash_data.width = bankwidth;
259 physmap_flash_data.set_vpp = set_vpp;
260}
261
1da177e4 262#ifdef CONFIG_MTD_PARTITIONS
73566edf
LB
263void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
264{
265 physmap_flash_data.nr_parts = num_parts;
266 physmap_flash_data.parts = parts;
267}
268#endif
1da177e4 269#endif
1da177e4 270
73566edf
LB
271static int __init physmap_init(void)
272{
273 int err;
274
275 err = platform_driver_register(&physmap_flash_driver);
dcb3e137 276#ifdef CONFIG_MTD_PHYSMAP_COMPAT
1ca5d2f0
HS
277 if (err == 0) {
278 err = platform_device_register(&physmap_flash);
279 if (err)
280 platform_driver_unregister(&physmap_flash_driver);
281 }
73566edf
LB
282#endif
283
284 return err;
1da177e4
LT
285}
286
73566edf
LB
287static void __exit physmap_exit(void)
288{
dcb3e137 289#ifdef CONFIG_MTD_PHYSMAP_COMPAT
73566edf
LB
290 platform_device_unregister(&physmap_flash);
291#endif
292 platform_driver_unregister(&physmap_flash_driver);
293}
1da177e4 294
73566edf
LB
295module_init(physmap_init);
296module_exit(physmap_exit);
1da177e4
LT
297
298MODULE_LICENSE("GPL");
299MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
300MODULE_DESCRIPTION("Generic configurable MTD map driver");
41d867c9
KS
301
302/* legacy platform drivers can't hotplug or coldplg */
dcb3e137 303#ifndef CONFIG_MTD_PHYSMAP_COMPAT
41d867c9
KS
304/* work with hotplug and coldplug */
305MODULE_ALIAS("platform:physmap-flash");
306#endif