diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-23 13:07:49 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2009-09-23 13:07:49 -0400 |
commit | a7c367b95a9d8e65e0f0e7da31f700a556794efb (patch) | |
tree | 5b1bb202801e29e3237381aa7aad5aa288378d5b /drivers/mtd/maps | |
parent | 15f964bed054821d6d940d3752508c5f96a9ffd3 (diff) | |
parent | e1070211f7327a1f197d535aa886f721a241c32f (diff) |
Merge git://git.infradead.org/mtd-2.6
* git://git.infradead.org/mtd-2.6: (58 commits)
mtd: jedec_probe: add PSD4256G6V id
mtd: OneNand support for Nomadik 8815 SoC (on NHK8815 board)
mtd: nand: driver for Nomadik 8815 SoC (on NHK8815 board)
m25p80: Add Spansion S25FL129P serial flashes
jffs2: Use SLAB_HWCACHE_ALIGN for jffs2_raw_{dirent,inode} slabs
mtd: sh_flctl: register sh_flctl using platform_driver_probe()
mtd: nand: txx9ndfmc: transfer 512 byte at a time if possible
mtd: nand: fix tmio_nand ecc correction
mtd: nand: add __nand_correct_data helper function
mtd: cfi_cmdset_0002: add 0xFF intolerance for M29W128G
mtd: inftl: fix fold chain block number
mtd: jedec: fix compilation problem with I28F640C3B definition
mtd: nand: fix ECC Correction bug for SMC ordering for NDFC driver
mtd: ofpart: Check availability of reg property instead of name property
driver/Makefile: Initialize "mtd" and "spi" before "net"
mtd: omap: adding DMA mode support in nand prefetch/post-write
mtd: omap: add support for nand prefetch-read and post-write
mtd: add nand support for w90p910 (v2)
mtd: maps: add mtd-ram support to physmap_of
mtd: pxa3xx_nand: add single-bit error corrections reporting
...
Diffstat (limited to 'drivers/mtd/maps')
-rw-r--r-- | drivers/mtd/maps/Kconfig | 12 | ||||
-rw-r--r-- | drivers/mtd/maps/Makefile | 3 | ||||
-rw-r--r-- | drivers/mtd/maps/gpio-addr-flash.c | 311 | ||||
-rw-r--r-- | drivers/mtd/maps/physmap_of.c | 24 | ||||
-rw-r--r-- | drivers/mtd/maps/plat-ram.c | 2 | ||||
-rw-r--r-- | drivers/mtd/maps/pmcmsp-flash.c | 76 | ||||
-rw-r--r-- | drivers/mtd/maps/uclinux.c | 8 |
7 files changed, 406 insertions, 30 deletions
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 7a58bd5522fd..3a9a960644b6 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -484,9 +484,19 @@ config MTD_BFIN_ASYNC | |||
484 | 484 | ||
485 | If compiled as a module, it will be called bfin-async-flash. | 485 | If compiled as a module, it will be called bfin-async-flash. |
486 | 486 | ||
487 | config MTD_GPIO_ADDR | ||
488 | tristate "GPIO-assisted Flash Chip Support" | ||
489 | depends on MTD_COMPLEX_MAPPINGS | ||
490 | select MTD_PARTITIONS | ||
491 | help | ||
492 | Map driver which allows flashes to be partially physically addressed | ||
493 | and assisted by GPIOs. | ||
494 | |||
495 | If compiled as a module, it will be called gpio-addr-flash. | ||
496 | |||
487 | config MTD_UCLINUX | 497 | config MTD_UCLINUX |
488 | bool "Generic uClinux RAM/ROM filesystem support" | 498 | bool "Generic uClinux RAM/ROM filesystem support" |
489 | depends on MTD_PARTITIONS && MTD_RAM && !MMU | 499 | depends on MTD_PARTITIONS && MTD_RAM=y && !MMU |
490 | help | 500 | help |
491 | Map driver to support image based filesystems for uClinux. | 501 | Map driver to support image based filesystems for uClinux. |
492 | 502 | ||
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 5beb0662d724..1d5cf8636723 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile | |||
@@ -58,5 +58,4 @@ obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o | |||
58 | obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o | 58 | obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o |
59 | obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o | 59 | obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o |
60 | obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o | 60 | obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o |
61 | obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o | 61 | obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o |
62 | obj-$(CONFIG_MTD_VMU) += vmu-flash.o | ||
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c new file mode 100644 index 000000000000..44ef9a49a860 --- /dev/null +++ b/drivers/mtd/maps/gpio-addr-flash.c | |||
@@ -0,0 +1,311 @@ | |||
1 | /* | ||
2 | * drivers/mtd/maps/gpio-addr-flash.c | ||
3 | * | ||
4 | * Handle the case where a flash device is mostly addressed using physical | ||
5 | * line and supplemented by GPIOs. This way you can hook up say a 8MiB flash | ||
6 | * to a 2MiB memory range and use the GPIOs to select a particular range. | ||
7 | * | ||
8 | * Copyright © 2000 Nicolas Pitre <nico@cam.org> | ||
9 | * Copyright © 2005-2009 Analog Devices Inc. | ||
10 | * | ||
11 | * Enter bugs at http://blackfin.uclinux.org/ | ||
12 | * | ||
13 | * Licensed under the GPL-2 or later. | ||
14 | */ | ||
15 | |||
16 | #include <linux/init.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/mtd/mtd.h> | ||
20 | #include <linux/mtd/map.h> | ||
21 | #include <linux/mtd/partitions.h> | ||
22 | #include <linux/mtd/physmap.h> | ||
23 | #include <linux/platform_device.h> | ||
24 | #include <linux/types.h> | ||
25 | |||
26 | #include <asm/gpio.h> | ||
27 | #include <asm/io.h> | ||
28 | |||
29 | #define pr_devinit(fmt, args...) ({ static const __devinitconst char __fmt[] = fmt; printk(__fmt, ## args); }) | ||
30 | |||
31 | #define DRIVER_NAME "gpio-addr-flash" | ||
32 | #define PFX DRIVER_NAME ": " | ||
33 | |||
34 | /** | ||
35 | * struct async_state - keep GPIO flash state | ||
36 | * @mtd: MTD state for this mapping | ||
37 | * @map: MTD map state for this flash | ||
38 | * @gpio_count: number of GPIOs used to address | ||
39 | * @gpio_addrs: array of GPIOs to twiddle | ||
40 | * @gpio_values: cached GPIO values | ||
41 | * @win_size: dedicated memory size (if no GPIOs) | ||
42 | */ | ||
43 | struct async_state { | ||
44 | struct mtd_info *mtd; | ||
45 | struct map_info map; | ||
46 | size_t gpio_count; | ||
47 | unsigned *gpio_addrs; | ||
48 | int *gpio_values; | ||
49 | unsigned long win_size; | ||
50 | }; | ||
51 | #define gf_map_info_to_state(mi) ((struct async_state *)(mi)->map_priv_1) | ||
52 | |||
53 | /** | ||
54 | * gf_set_gpios() - set GPIO address lines to access specified flash offset | ||
55 | * @state: GPIO flash state | ||
56 | * @ofs: desired offset to access | ||
57 | * | ||
58 | * Rather than call the GPIO framework every time, cache the last-programmed | ||
59 | * value. This speeds up sequential accesses (which are by far the most common | ||
60 | * type). We rely on the GPIO framework to treat non-zero value as high so | ||
61 | * that we don't have to normalize the bits. | ||
62 | */ | ||
63 | static void gf_set_gpios(struct async_state *state, unsigned long ofs) | ||
64 | { | ||
65 | size_t i = 0; | ||
66 | int value; | ||
67 | ofs /= state->win_size; | ||
68 | do { | ||
69 | value = ofs & (1 << i); | ||
70 | if (state->gpio_values[i] != value) { | ||
71 | gpio_set_value(state->gpio_addrs[i], value); | ||
72 | state->gpio_values[i] = value; | ||
73 | } | ||
74 | } while (++i < state->gpio_count); | ||
75 | } | ||
76 | |||
77 | /** | ||
78 | * gf_read() - read a word at the specified offset | ||
79 | * @map: MTD map state | ||
80 | * @ofs: desired offset to read | ||
81 | */ | ||
82 | static map_word gf_read(struct map_info *map, unsigned long ofs) | ||
83 | { | ||
84 | struct async_state *state = gf_map_info_to_state(map); | ||
85 | uint16_t word; | ||
86 | map_word test; | ||
87 | |||
88 | gf_set_gpios(state, ofs); | ||
89 | |||
90 | word = readw(map->virt + (ofs % state->win_size)); | ||
91 | test.x[0] = word; | ||
92 | return test; | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * gf_copy_from() - copy a chunk of data from the flash | ||
97 | * @map: MTD map state | ||
98 | * @to: memory to copy to | ||
99 | * @from: flash offset to copy from | ||
100 | * @len: how much to copy | ||
101 | * | ||
102 | * We rely on the MTD layer to chunk up copies such that a single request here | ||
103 | * will not cross a window size. This allows us to only wiggle the GPIOs once | ||
104 | * before falling back to a normal memcpy. Reading the higher layer code shows | ||
105 | * that this is indeed the case, but add a BUG_ON() to future proof. | ||
106 | */ | ||
107 | static void gf_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) | ||
108 | { | ||
109 | struct async_state *state = gf_map_info_to_state(map); | ||
110 | |||
111 | gf_set_gpios(state, from); | ||
112 | |||
113 | /* BUG if operation crosses the win_size */ | ||
114 | BUG_ON(!((from + len) % state->win_size <= (from + len))); | ||
115 | |||
116 | /* operation does not cross the win_size, so one shot it */ | ||
117 | memcpy_fromio(to, map->virt + (from % state->win_size), len); | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * gf_write() - write a word at the specified offset | ||
122 | * @map: MTD map state | ||
123 | * @ofs: desired offset to write | ||
124 | */ | ||
125 | static void gf_write(struct map_info *map, map_word d1, unsigned long ofs) | ||
126 | { | ||
127 | struct async_state *state = gf_map_info_to_state(map); | ||
128 | uint16_t d; | ||
129 | |||
130 | gf_set_gpios(state, ofs); | ||
131 | |||
132 | d = d1.x[0]; | ||
133 | writew(d, map->virt + (ofs % state->win_size)); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * gf_copy_to() - copy a chunk of data to the flash | ||
138 | * @map: MTD map state | ||
139 | * @to: flash offset to copy to | ||
140 | * @from: memory to copy from | ||
141 | * @len: how much to copy | ||
142 | * | ||
143 | * See gf_copy_from() caveat. | ||
144 | */ | ||
145 | static void gf_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) | ||
146 | { | ||
147 | struct async_state *state = gf_map_info_to_state(map); | ||
148 | |||
149 | gf_set_gpios(state, to); | ||
150 | |||
151 | /* BUG if operation crosses the win_size */ | ||
152 | BUG_ON(!((to + len) % state->win_size <= (to + len))); | ||
153 | |||
154 | /* operation does not cross the win_size, so one shot it */ | ||
155 | memcpy_toio(map->virt + (to % state->win_size), from, len); | ||
156 | } | ||
157 | |||
158 | #ifdef CONFIG_MTD_PARTITIONS | ||
159 | static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL }; | ||
160 | #endif | ||
161 | |||
162 | /** | ||
163 | * gpio_flash_probe() - setup a mapping for a GPIO assisted flash | ||
164 | * @pdev: platform device | ||
165 | * | ||
166 | * The platform resource layout expected looks something like: | ||
167 | * struct mtd_partition partitions[] = { ... }; | ||
168 | * struct physmap_flash_data flash_data = { ... }; | ||
169 | * unsigned flash_gpios[] = { GPIO_XX, GPIO_XX, ... }; | ||
170 | * struct resource flash_resource[] = { | ||
171 | * { | ||
172 | * .name = "cfi_probe", | ||
173 | * .start = 0x20000000, | ||
174 | * .end = 0x201fffff, | ||
175 | * .flags = IORESOURCE_MEM, | ||
176 | * }, { | ||
177 | * .start = (unsigned long)flash_gpios, | ||
178 | * .end = ARRAY_SIZE(flash_gpios), | ||
179 | * .flags = IORESOURCE_IRQ, | ||
180 | * } | ||
181 | * }; | ||
182 | * struct platform_device flash_device = { | ||
183 | * .name = "gpio-addr-flash", | ||
184 | * .dev = { .platform_data = &flash_data, }, | ||
185 | * .num_resources = ARRAY_SIZE(flash_resource), | ||
186 | * .resource = flash_resource, | ||
187 | * ... | ||
188 | * }; | ||
189 | */ | ||
190 | static int __devinit gpio_flash_probe(struct platform_device *pdev) | ||
191 | { | ||
192 | int ret; | ||
193 | size_t i, arr_size; | ||
194 | struct physmap_flash_data *pdata; | ||
195 | struct resource *memory; | ||
196 | struct resource *gpios; | ||
197 | struct async_state *state; | ||
198 | |||
199 | pdata = pdev->dev.platform_data; | ||
200 | memory = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
201 | gpios = platform_get_resource(pdev, IORESOURCE_IRQ, 0); | ||
202 | |||
203 | if (!memory || !gpios || !gpios->end) | ||
204 | return -EINVAL; | ||
205 | |||
206 | arr_size = sizeof(int) * gpios->end; | ||
207 | state = kzalloc(sizeof(*state) + arr_size, GFP_KERNEL); | ||
208 | if (!state) | ||
209 | return -ENOMEM; | ||
210 | |||
211 | state->gpio_count = gpios->end; | ||
212 | state->gpio_addrs = (void *)gpios->start; | ||
213 | state->gpio_values = (void *)(state + 1); | ||
214 | state->win_size = memory->end - memory->start + 1; | ||
215 | memset(state->gpio_values, 0xff, arr_size); | ||
216 | |||
217 | state->map.name = DRIVER_NAME; | ||
218 | state->map.read = gf_read; | ||
219 | state->map.copy_from = gf_copy_from; | ||
220 | state->map.write = gf_write; | ||
221 | state->map.copy_to = gf_copy_to; | ||
222 | state->map.bankwidth = pdata->width; | ||
223 | state->map.size = state->win_size * (1 << state->gpio_count); | ||
224 | state->map.virt = (void __iomem *)memory->start; | ||
225 | state->map.phys = NO_XIP; | ||
226 | state->map.map_priv_1 = (unsigned long)state; | ||
227 | |||
228 | platform_set_drvdata(pdev, state); | ||
229 | |||
230 | i = 0; | ||
231 | do { | ||
232 | if (gpio_request(state->gpio_addrs[i], DRIVER_NAME)) { | ||
233 | pr_devinit(KERN_ERR PFX "failed to request gpio %d\n", | ||
234 | state->gpio_addrs[i]); | ||
235 | while (i--) | ||
236 | gpio_free(state->gpio_addrs[i]); | ||
237 | kfree(state); | ||
238 | return -EBUSY; | ||
239 | } | ||
240 | gpio_direction_output(state->gpio_addrs[i], 0); | ||
241 | } while (++i < state->gpio_count); | ||
242 | |||
243 | pr_devinit(KERN_NOTICE PFX "probing %d-bit flash bus\n", | ||
244 | state->map.bankwidth * 8); | ||
245 | state->mtd = do_map_probe(memory->name, &state->map); | ||
246 | if (!state->mtd) { | ||
247 | for (i = 0; i < state->gpio_count; ++i) | ||
248 | gpio_free(state->gpio_addrs[i]); | ||
249 | kfree(state); | ||
250 | return -ENXIO; | ||
251 | } | ||
252 | |||
253 | #ifdef CONFIG_MTD_PARTITIONS | ||
254 | ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0); | ||
255 | if (ret > 0) { | ||
256 | pr_devinit(KERN_NOTICE PFX "Using commandline partition definition\n"); | ||
257 | add_mtd_partitions(state->mtd, pdata->parts, ret); | ||
258 | kfree(pdata->parts); | ||
259 | |||
260 | } else if (pdata->nr_parts) { | ||
261 | pr_devinit(KERN_NOTICE PFX "Using board partition definition\n"); | ||
262 | add_mtd_partitions(state->mtd, pdata->parts, pdata->nr_parts); | ||
263 | |||
264 | } else | ||
265 | #endif | ||
266 | { | ||
267 | pr_devinit(KERN_NOTICE PFX "no partition info available, registering whole flash at once\n"); | ||
268 | add_mtd_device(state->mtd); | ||
269 | } | ||
270 | |||
271 | return 0; | ||
272 | } | ||
273 | |||
274 | static int __devexit gpio_flash_remove(struct platform_device *pdev) | ||
275 | { | ||
276 | struct async_state *state = platform_get_drvdata(pdev); | ||
277 | size_t i = 0; | ||
278 | do { | ||
279 | gpio_free(state->gpio_addrs[i]); | ||
280 | } while (++i < state->gpio_count); | ||
281 | #ifdef CONFIG_MTD_PARTITIONS | ||
282 | del_mtd_partitions(state->mtd); | ||
283 | #endif | ||
284 | map_destroy(state->mtd); | ||
285 | kfree(state); | ||
286 | return 0; | ||
287 | } | ||
288 | |||
289 | static struct platform_driver gpio_flash_driver = { | ||
290 | .probe = gpio_flash_probe, | ||
291 | .remove = __devexit_p(gpio_flash_remove), | ||
292 | .driver = { | ||
293 | .name = DRIVER_NAME, | ||
294 | }, | ||
295 | }; | ||
296 | |||
297 | static int __init gpio_flash_init(void) | ||
298 | { | ||
299 | return platform_driver_register(&gpio_flash_driver); | ||
300 | } | ||
301 | module_init(gpio_flash_init); | ||
302 | |||
303 | static void __exit gpio_flash_exit(void) | ||
304 | { | ||
305 | platform_driver_unregister(&gpio_flash_driver); | ||
306 | } | ||
307 | module_exit(gpio_flash_exit); | ||
308 | |||
309 | MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>"); | ||
310 | MODULE_DESCRIPTION("MTD map driver for flashes addressed physically and with gpios"); | ||
311 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 39d357b2eb47..61e4eb48bb2d 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c | |||
@@ -190,6 +190,7 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
190 | const u32 *p; | 190 | const u32 *p; |
191 | int reg_tuple_size; | 191 | int reg_tuple_size; |
192 | struct mtd_info **mtd_list = NULL; | 192 | struct mtd_info **mtd_list = NULL; |
193 | resource_size_t res_size; | ||
193 | 194 | ||
194 | reg_tuple_size = (of_n_addr_cells(dp) + of_n_size_cells(dp)) * sizeof(u32); | 195 | reg_tuple_size = (of_n_addr_cells(dp) + of_n_size_cells(dp)) * sizeof(u32); |
195 | 196 | ||
@@ -204,7 +205,7 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
204 | dev_err(&dev->dev, "Malformed reg property on %s\n", | 205 | dev_err(&dev->dev, "Malformed reg property on %s\n", |
205 | dev->node->full_name); | 206 | dev->node->full_name); |
206 | err = -EINVAL; | 207 | err = -EINVAL; |
207 | goto err_out; | 208 | goto err_flash_remove; |
208 | } | 209 | } |
209 | count /= reg_tuple_size; | 210 | count /= reg_tuple_size; |
210 | 211 | ||
@@ -212,14 +213,14 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
212 | info = kzalloc(sizeof(struct of_flash) + | 213 | info = kzalloc(sizeof(struct of_flash) + |
213 | sizeof(struct of_flash_list) * count, GFP_KERNEL); | 214 | sizeof(struct of_flash_list) * count, GFP_KERNEL); |
214 | if (!info) | 215 | if (!info) |
215 | goto err_out; | 216 | goto err_flash_remove; |
216 | |||
217 | mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL); | ||
218 | if (!info) | ||
219 | goto err_out; | ||
220 | 217 | ||
221 | dev_set_drvdata(&dev->dev, info); | 218 | dev_set_drvdata(&dev->dev, info); |
222 | 219 | ||
220 | mtd_list = kzalloc(sizeof(struct mtd_info) * count, GFP_KERNEL); | ||
221 | if (!mtd_list) | ||
222 | goto err_flash_remove; | ||
223 | |||
223 | for (i = 0; i < count; i++) { | 224 | for (i = 0; i < count; i++) { |
224 | err = -ENXIO; | 225 | err = -ENXIO; |
225 | if (of_address_to_resource(dp, i, &res)) { | 226 | if (of_address_to_resource(dp, i, &res)) { |
@@ -233,8 +234,8 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
233 | (unsigned long long)res.end); | 234 | (unsigned long long)res.end); |
234 | 235 | ||
235 | err = -EBUSY; | 236 | err = -EBUSY; |
236 | info->list[i].res = request_mem_region(res.start, res.end - | 237 | res_size = resource_size(&res); |
237 | res.start + 1, | 238 | info->list[i].res = request_mem_region(res.start, res_size, |
238 | dev_name(&dev->dev)); | 239 | dev_name(&dev->dev)); |
239 | if (!info->list[i].res) | 240 | if (!info->list[i].res) |
240 | goto err_out; | 241 | goto err_out; |
@@ -249,7 +250,7 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
249 | 250 | ||
250 | info->list[i].map.name = dev_name(&dev->dev); | 251 | info->list[i].map.name = dev_name(&dev->dev); |
251 | info->list[i].map.phys = res.start; | 252 | info->list[i].map.phys = res.start; |
252 | info->list[i].map.size = res.end - res.start + 1; | 253 | info->list[i].map.size = res_size; |
253 | info->list[i].map.bankwidth = *width; | 254 | info->list[i].map.bankwidth = *width; |
254 | 255 | ||
255 | err = -ENOMEM; | 256 | err = -ENOMEM; |
@@ -338,6 +339,7 @@ static int __devinit of_flash_probe(struct of_device *dev, | |||
338 | 339 | ||
339 | err_out: | 340 | err_out: |
340 | kfree(mtd_list); | 341 | kfree(mtd_list); |
342 | err_flash_remove: | ||
341 | of_flash_remove(dev); | 343 | of_flash_remove(dev); |
342 | 344 | ||
343 | return err; | 345 | return err; |
@@ -360,6 +362,10 @@ static struct of_device_id of_flash_match[] = { | |||
360 | .data = (void *)"jedec_probe", | 362 | .data = (void *)"jedec_probe", |
361 | }, | 363 | }, |
362 | { | 364 | { |
365 | .compatible = "mtd-ram", | ||
366 | .data = (void *)"map_ram", | ||
367 | }, | ||
368 | { | ||
363 | .type = "rom", | 369 | .type = "rom", |
364 | .compatible = "direct-mapped" | 370 | .compatible = "direct-mapped" |
365 | }, | 371 | }, |
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c index 49c9ece76477..dafb91944e70 100644 --- a/drivers/mtd/maps/plat-ram.c +++ b/drivers/mtd/maps/plat-ram.c | |||
@@ -175,7 +175,7 @@ static int platram_probe(struct platform_device *pdev) | |||
175 | /* setup map parameters */ | 175 | /* setup map parameters */ |
176 | 176 | ||
177 | info->map.phys = res->start; | 177 | info->map.phys = res->start; |
178 | info->map.size = (res->end - res->start) + 1; | 178 | info->map.size = resource_size(res); |
179 | info->map.name = pdata->mapname != NULL ? | 179 | info->map.name = pdata->mapname != NULL ? |
180 | (char *)pdata->mapname : (char *)pdev->name; | 180 | (char *)pdata->mapname : (char *)pdev->name; |
181 | info->map.bankwidth = pdata->bankwidth; | 181 | info->map.bankwidth = pdata->bankwidth; |
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c index 4768bd5459d6..c8fd8da4bc87 100644 --- a/drivers/mtd/maps/pmcmsp-flash.c +++ b/drivers/mtd/maps/pmcmsp-flash.c | |||
@@ -50,7 +50,7 @@ static int fcnt; | |||
50 | 50 | ||
51 | static int __init init_msp_flash(void) | 51 | static int __init init_msp_flash(void) |
52 | { | 52 | { |
53 | int i, j; | 53 | int i, j, ret = -ENOMEM; |
54 | int offset, coff; | 54 | int offset, coff; |
55 | char *env; | 55 | char *env; |
56 | int pcnt; | 56 | int pcnt; |
@@ -75,14 +75,16 @@ static int __init init_msp_flash(void) | |||
75 | printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt); | 75 | printk(KERN_NOTICE "Found %d PMC flash devices\n", fcnt); |
76 | 76 | ||
77 | msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL); | 77 | msp_flash = kmalloc(fcnt * sizeof(struct map_info *), GFP_KERNEL); |
78 | if (!msp_flash) | ||
79 | return -ENOMEM; | ||
80 | |||
78 | msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL); | 81 | msp_parts = kmalloc(fcnt * sizeof(struct mtd_partition *), GFP_KERNEL); |
82 | if (!msp_parts) | ||
83 | goto free_msp_flash; | ||
84 | |||
79 | msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL); | 85 | msp_maps = kcalloc(fcnt, sizeof(struct mtd_info), GFP_KERNEL); |
80 | if (!msp_flash || !msp_parts || !msp_maps) { | 86 | if (!msp_maps) |
81 | kfree(msp_maps); | 87 | goto free_msp_parts; |
82 | kfree(msp_parts); | ||
83 | kfree(msp_flash); | ||
84 | return -ENOMEM; | ||
85 | } | ||
86 | 88 | ||
87 | /* loop over the flash devices, initializing each */ | 89 | /* loop over the flash devices, initializing each */ |
88 | for (i = 0; i < fcnt; i++) { | 90 | for (i = 0; i < fcnt; i++) { |
@@ -100,13 +102,18 @@ static int __init init_msp_flash(void) | |||
100 | 102 | ||
101 | msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), | 103 | msp_parts[i] = kcalloc(pcnt, sizeof(struct mtd_partition), |
102 | GFP_KERNEL); | 104 | GFP_KERNEL); |
105 | if (!msp_parts[i]) | ||
106 | goto cleanup_loop; | ||
103 | 107 | ||
104 | /* now initialize the devices proper */ | 108 | /* now initialize the devices proper */ |
105 | flash_name[5] = '0' + i; | 109 | flash_name[5] = '0' + i; |
106 | env = prom_getenv(flash_name); | 110 | env = prom_getenv(flash_name); |
107 | 111 | ||
108 | if (sscanf(env, "%x:%x", &addr, &size) < 2) | 112 | if (sscanf(env, "%x:%x", &addr, &size) < 2) { |
109 | return -ENXIO; | 113 | ret = -ENXIO; |
114 | kfree(msp_parts[i]); | ||
115 | goto cleanup_loop; | ||
116 | } | ||
110 | addr = CPHYSADDR(addr); | 117 | addr = CPHYSADDR(addr); |
111 | 118 | ||
112 | printk(KERN_NOTICE | 119 | printk(KERN_NOTICE |
@@ -122,13 +129,23 @@ static int __init init_msp_flash(void) | |||
122 | */ | 129 | */ |
123 | if (size > CONFIG_MSP_FLASH_MAP_LIMIT) | 130 | if (size > CONFIG_MSP_FLASH_MAP_LIMIT) |
124 | size = CONFIG_MSP_FLASH_MAP_LIMIT; | 131 | size = CONFIG_MSP_FLASH_MAP_LIMIT; |
132 | |||
125 | msp_maps[i].virt = ioremap(addr, size); | 133 | msp_maps[i].virt = ioremap(addr, size); |
134 | if (msp_maps[i].virt == NULL) { | ||
135 | ret = -ENXIO; | ||
136 | kfree(msp_parts[i]); | ||
137 | goto cleanup_loop; | ||
138 | } | ||
139 | |||
126 | msp_maps[i].bankwidth = 1; | 140 | msp_maps[i].bankwidth = 1; |
127 | msp_maps[i].name = strncpy(kmalloc(7, GFP_KERNEL), | 141 | msp_maps[i].name = kmalloc(7, GFP_KERNEL); |
128 | flash_name, 7); | 142 | if (!msp_maps[i].name) { |
143 | iounmap(msp_maps[i].virt); | ||
144 | kfree(msp_parts[i]); | ||
145 | goto cleanup_loop; | ||
146 | } | ||
129 | 147 | ||
130 | if (msp_maps[i].virt == NULL) | 148 | msp_maps[i].name = strncpy(msp_maps[i].name, flash_name, 7); |
131 | return -ENXIO; | ||
132 | 149 | ||
133 | for (j = 0; j < pcnt; j++) { | 150 | for (j = 0; j < pcnt; j++) { |
134 | part_name[5] = '0' + i; | 151 | part_name[5] = '0' + i; |
@@ -136,8 +153,14 @@ static int __init init_msp_flash(void) | |||
136 | 153 | ||
137 | env = prom_getenv(part_name); | 154 | env = prom_getenv(part_name); |
138 | 155 | ||
139 | if (sscanf(env, "%x:%x:%n", &offset, &size, &coff) < 2) | 156 | if (sscanf(env, "%x:%x:%n", &offset, &size, |
140 | return -ENXIO; | 157 | &coff) < 2) { |
158 | ret = -ENXIO; | ||
159 | kfree(msp_maps[i].name); | ||
160 | iounmap(msp_maps[i].virt); | ||
161 | kfree(msp_parts[i]); | ||
162 | goto cleanup_loop; | ||
163 | } | ||
141 | 164 | ||
142 | msp_parts[i][j].size = size; | 165 | msp_parts[i][j].size = size; |
143 | msp_parts[i][j].offset = offset; | 166 | msp_parts[i][j].offset = offset; |
@@ -152,18 +175,37 @@ static int __init init_msp_flash(void) | |||
152 | add_mtd_partitions(msp_flash[i], msp_parts[i], pcnt); | 175 | add_mtd_partitions(msp_flash[i], msp_parts[i], pcnt); |
153 | } else { | 176 | } else { |
154 | printk(KERN_ERR "map probe failed for flash\n"); | 177 | printk(KERN_ERR "map probe failed for flash\n"); |
155 | return -ENXIO; | 178 | ret = -ENXIO; |
179 | kfree(msp_maps[i].name); | ||
180 | iounmap(msp_maps[i].virt); | ||
181 | kfree(msp_parts[i]); | ||
182 | goto cleanup_loop; | ||
156 | } | 183 | } |
157 | } | 184 | } |
158 | 185 | ||
159 | return 0; | 186 | return 0; |
187 | |||
188 | cleanup_loop: | ||
189 | while (i--) { | ||
190 | del_mtd_partitions(msp_flash[i]); | ||
191 | map_destroy(msp_flash[i]); | ||
192 | kfree(msp_maps[i].name); | ||
193 | iounmap(msp_maps[i].virt); | ||
194 | kfree(msp_parts[i]); | ||
195 | } | ||
196 | kfree(msp_maps); | ||
197 | free_msp_parts: | ||
198 | kfree(msp_parts); | ||
199 | free_msp_flash: | ||
200 | kfree(msp_flash); | ||
201 | return ret; | ||
160 | } | 202 | } |
161 | 203 | ||
162 | static void __exit cleanup_msp_flash(void) | 204 | static void __exit cleanup_msp_flash(void) |
163 | { | 205 | { |
164 | int i; | 206 | int i; |
165 | 207 | ||
166 | for (i = 0; i < sizeof(msp_flash) / sizeof(struct mtd_info **); i++) { | 208 | for (i = 0; i < fcnt; i++) { |
167 | del_mtd_partitions(msp_flash[i]); | 209 | del_mtd_partitions(msp_flash[i]); |
168 | map_destroy(msp_flash[i]); | 210 | map_destroy(msp_flash[i]); |
169 | iounmap((void *)msp_maps[i].virt); | 211 | iounmap((void *)msp_maps[i].virt); |
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c index d4314fb88212..35009294b435 100644 --- a/drivers/mtd/maps/uclinux.c +++ b/drivers/mtd/maps/uclinux.c | |||
@@ -89,7 +89,11 @@ static int __init uclinux_mtd_init(void) | |||
89 | mtd->priv = mapp; | 89 | mtd->priv = mapp; |
90 | 90 | ||
91 | uclinux_ram_mtdinfo = mtd; | 91 | uclinux_ram_mtdinfo = mtd; |
92 | #ifdef CONFIG_MTD_PARTITIONS | ||
92 | add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS); | 93 | add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS); |
94 | #else | ||
95 | add_mtd_device(mtd); | ||
96 | #endif | ||
93 | 97 | ||
94 | return(0); | 98 | return(0); |
95 | } | 99 | } |
@@ -99,7 +103,11 @@ static int __init uclinux_mtd_init(void) | |||
99 | static void __exit uclinux_mtd_cleanup(void) | 103 | static void __exit uclinux_mtd_cleanup(void) |
100 | { | 104 | { |
101 | if (uclinux_ram_mtdinfo) { | 105 | if (uclinux_ram_mtdinfo) { |
106 | #ifdef CONFIG_MTD_PARTITIONS | ||
102 | del_mtd_partitions(uclinux_ram_mtdinfo); | 107 | del_mtd_partitions(uclinux_ram_mtdinfo); |
108 | #else | ||
109 | del_mtd_device(uclinux_ram_mtdinfo); | ||
110 | #endif | ||
103 | map_destroy(uclinux_ram_mtdinfo); | 111 | map_destroy(uclinux_ram_mtdinfo); |
104 | uclinux_ram_mtdinfo = NULL; | 112 | uclinux_ram_mtdinfo = NULL; |
105 | } | 113 | } |