2006-12-06 18:17:49 +08:00
|
|
|
/*
|
2007-09-20 09:22:25 +08:00
|
|
|
* Flash mappings described by the OF (or flattened) device tree
|
2006-12-06 18:17:49 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 MontaVista Software Inc.
|
|
|
|
* Author: Vitaly Wool <vwool@ru.mvista.com>
|
|
|
|
*
|
2007-09-07 11:23:53 +08:00
|
|
|
* Revised to handle newer style flash binding by:
|
|
|
|
* Copyright (C) 2007 David Gibson, IBM Corporation.
|
|
|
|
*
|
2006-12-06 18:17:49 +08:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
|
|
|
#include <linux/mtd/map.h>
|
|
|
|
#include <linux/mtd/partitions.h>
|
2009-04-16 20:10:45 +08:00
|
|
|
#include <linux/mtd/concat.h>
|
2007-09-20 09:22:25 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_platform.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
struct of_flash_list {
|
|
|
|
struct mtd_info *mtd;
|
|
|
|
struct map_info map;
|
|
|
|
struct resource *res;
|
|
|
|
};
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
struct of_flash {
|
2009-04-16 20:10:45 +08:00
|
|
|
struct mtd_info *cmtd;
|
2006-12-06 18:17:49 +08:00
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
|
|
|
struct mtd_partition *parts;
|
|
|
|
#endif
|
2009-04-16 20:10:45 +08:00
|
|
|
int list_size; /* number of elements in of_flash_list */
|
|
|
|
struct of_flash_list list[0];
|
2006-12-06 18:17:49 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
2007-09-20 09:22:25 +08:00
|
|
|
#define OF_FLASH_PARTS(info) ((info)->parts)
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
static int parse_obsolete_partitions(struct of_device *dev,
|
2007-09-20 09:22:25 +08:00
|
|
|
struct of_flash *info,
|
2007-09-07 11:23:53 +08:00
|
|
|
struct device_node *dp)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
2007-09-07 11:23:53 +08:00
|
|
|
int i, plen, nr_parts;
|
|
|
|
const struct {
|
|
|
|
u32 offset, len;
|
|
|
|
} *part;
|
|
|
|
const char *names;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
part = of_get_property(dp, "partitions", &plen);
|
|
|
|
if (!part)
|
2007-09-20 09:22:25 +08:00
|
|
|
return 0; /* No partitions found */
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
dev_warn(&dev->dev, "Device tree uses obsolete partition map binding\n");
|
|
|
|
|
|
|
|
nr_parts = plen / sizeof(part[0]);
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
info->parts = kzalloc(nr_parts * sizeof(*info->parts), GFP_KERNEL);
|
|
|
|
if (!info->parts)
|
2007-09-07 11:23:53 +08:00
|
|
|
return -ENOMEM;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
names = of_get_property(dp, "partition-names", &plen);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
for (i = 0; i < nr_parts; i++) {
|
|
|
|
info->parts[i].offset = part->offset;
|
|
|
|
info->parts[i].size = part->len & ~1;
|
|
|
|
if (part->len & 1) /* bit 0 set signifies read only partition */
|
|
|
|
info->parts[i].mask_flags = MTD_WRITEABLE;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
if (names && (plen > 0)) {
|
|
|
|
int len = strlen(names) + 1;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
info->parts[i].name = (char *)names;
|
2006-12-06 18:17:49 +08:00
|
|
|
plen -= len;
|
2007-09-07 11:23:53 +08:00
|
|
|
names += len;
|
|
|
|
} else {
|
|
|
|
info->parts[i].name = "unnamed";
|
|
|
|
}
|
|
|
|
|
|
|
|
part++;
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
2007-09-07 11:23:53 +08:00
|
|
|
|
|
|
|
return nr_parts;
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
2007-09-07 11:23:53 +08:00
|
|
|
#else /* MTD_PARTITIONS */
|
2007-09-20 09:22:25 +08:00
|
|
|
#define OF_FLASH_PARTS(info) (0)
|
|
|
|
#define parse_partitions(info, dev) (0)
|
2007-09-07 11:23:53 +08:00
|
|
|
#endif /* MTD_PARTITIONS */
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static int of_flash_remove(struct of_device *dev)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
2007-09-20 09:22:25 +08:00
|
|
|
struct of_flash *info;
|
2009-04-16 20:10:45 +08:00
|
|
|
int i;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
|
|
|
info = dev_get_drvdata(&dev->dev);
|
2007-09-20 09:22:25 +08:00
|
|
|
if (!info)
|
2006-12-06 18:17:49 +08:00
|
|
|
return 0;
|
|
|
|
dev_set_drvdata(&dev->dev, NULL);
|
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
#ifdef CONFIG_MTD_CONCAT
|
|
|
|
if (info->cmtd != info->list[0].mtd) {
|
|
|
|
del_mtd_device(info->cmtd);
|
|
|
|
mtd_concat_destroy(info->cmtd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (info->cmtd) {
|
2007-09-20 09:22:25 +08:00
|
|
|
if (OF_FLASH_PARTS(info)) {
|
2009-04-16 20:10:45 +08:00
|
|
|
del_mtd_partitions(info->cmtd);
|
2007-09-20 09:22:25 +08:00
|
|
|
kfree(OF_FLASH_PARTS(info));
|
2006-12-06 18:17:49 +08:00
|
|
|
} else {
|
2009-04-16 20:10:45 +08:00
|
|
|
del_mtd_device(info->cmtd);
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
for (i = 0; i < info->list_size; i++) {
|
|
|
|
if (info->list[i].mtd)
|
|
|
|
map_destroy(info->list[i].mtd);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
if (info->list[i].map.virt)
|
|
|
|
iounmap(info->list[i].map.virt);
|
|
|
|
|
|
|
|
if (info->list[i].res) {
|
|
|
|
release_resource(info->list[i].res);
|
|
|
|
kfree(info->list[i].res);
|
|
|
|
}
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
kfree(info);
|
|
|
|
|
2006-12-06 18:17:49 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-09-07 11:23:53 +08:00
|
|
|
/* Helper function to handle probing of the obsolete "direct-mapped"
|
|
|
|
* compatible binding, which has an extra "probe-type" property
|
|
|
|
* describing the type of flash probe necessary. */
|
|
|
|
static struct mtd_info * __devinit obsolete_probe(struct of_device *dev,
|
|
|
|
struct map_info *map)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
|
|
|
struct device_node *dp = dev->node;
|
|
|
|
const char *of_probe;
|
2007-09-07 11:23:53 +08:00
|
|
|
struct mtd_info *mtd;
|
|
|
|
static const char *rom_probe_types[]
|
|
|
|
= { "cfi_probe", "jedec_probe", "map_rom"};
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dev_warn(&dev->dev, "Device tree uses obsolete \"direct-mapped\" "
|
|
|
|
"flash binding\n");
|
|
|
|
|
|
|
|
of_probe = of_get_property(dp, "probe-type", NULL);
|
|
|
|
if (!of_probe) {
|
|
|
|
for (i = 0; i < ARRAY_SIZE(rom_probe_types); i++) {
|
|
|
|
mtd = do_map_probe(rom_probe_types[i], map);
|
|
|
|
if (mtd)
|
|
|
|
return mtd;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
} else if (strcmp(of_probe, "CFI") == 0) {
|
|
|
|
return do_map_probe("cfi_probe", map);
|
|
|
|
} else if (strcmp(of_probe, "JEDEC") == 0) {
|
|
|
|
return do_map_probe("jedec_probe", map);
|
|
|
|
} else {
|
|
|
|
if (strcmp(of_probe, "ROM") != 0)
|
2007-09-20 09:22:25 +08:00
|
|
|
dev_warn(&dev->dev, "obsolete_probe: don't know probe "
|
|
|
|
"type '%s', mapping as rom\n", of_probe);
|
2007-09-07 11:23:53 +08:00
|
|
|
return do_map_probe("mtd_rom", map);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-10 03:27:56 +08:00
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
|
|
|
/* When partitions are set we look for a linux,part-probe property which
|
|
|
|
specifies the list of partition probers to use. If none is given then the
|
|
|
|
default is use. These take precedence over other device tree
|
|
|
|
information. */
|
|
|
|
static const char *part_probe_types_def[] = { "cmdlinepart", "RedBoot", NULL };
|
|
|
|
static const char ** __devinit of_get_probes(struct device_node *dp)
|
|
|
|
{
|
|
|
|
const char *cp;
|
|
|
|
int cplen;
|
|
|
|
unsigned int l;
|
|
|
|
unsigned int count;
|
|
|
|
const char **res;
|
|
|
|
|
|
|
|
cp = of_get_property(dp, "linux,part-probe", &cplen);
|
|
|
|
if (cp == NULL)
|
|
|
|
return part_probe_types_def;
|
|
|
|
|
|
|
|
count = 0;
|
|
|
|
for (l = 0; l != cplen; l++)
|
|
|
|
if (cp[l] == 0)
|
|
|
|
count++;
|
|
|
|
|
|
|
|
res = kzalloc((count + 1)*sizeof(*res), GFP_KERNEL);
|
|
|
|
count = 0;
|
|
|
|
while (cplen > 0) {
|
|
|
|
res[count] = cp;
|
|
|
|
l = strlen(cp) + 1;
|
|
|
|
cp += l;
|
|
|
|
cplen -= l;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __devinit of_free_probes(const char **probes)
|
|
|
|
{
|
|
|
|
if (probes != part_probe_types_def)
|
|
|
|
kfree(probes);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static int __devinit of_flash_probe(struct of_device *dev,
|
|
|
|
const struct of_device_id *match)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
2008-01-16 07:54:43 +08:00
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
2010-03-10 03:27:56 +08:00
|
|
|
const char **part_probe_types;
|
2008-01-16 07:54:43 +08:00
|
|
|
#endif
|
2006-12-06 18:17:49 +08:00
|
|
|
struct device_node *dp = dev->node;
|
|
|
|
struct resource res;
|
2007-09-20 09:22:25 +08:00
|
|
|
struct of_flash *info;
|
|
|
|
const char *probe_type = match->data;
|
2006-12-06 18:17:49 +08:00
|
|
|
const u32 *width;
|
|
|
|
int err;
|
2009-04-16 20:10:45 +08:00
|
|
|
int i;
|
|
|
|
int count;
|
|
|
|
const u32 *p;
|
|
|
|
int reg_tuple_size;
|
|
|
|
struct mtd_info **mtd_list = NULL;
|
2009-07-17 23:54:14 +08:00
|
|
|
resource_size_t res_size;
|
2009-04-16 20:10:45 +08:00
|
|
|
|
|
|
|
reg_tuple_size = (of_n_addr_cells(dp) + of_n_size_cells(dp)) * sizeof(u32);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get number of "reg" tuples. Scan for MTD devices on area's
|
|
|
|
* described by each "reg" region. This makes it possible (including
|
|
|
|
* the concat support) to support the Intel P30 48F4400 chips which
|
|
|
|
* consists internally of 2 non-identical NOR chips on one die.
|
|
|
|
*/
|
|
|
|
p = of_get_property(dp, "reg", &count);
|
|
|
|
if (count % reg_tuple_size != 0) {
|
|
|
|
dev_err(&dev->dev, "Malformed reg property on %s\n",
|
|
|
|
dev->node->full_name);
|
|
|
|
err = -EINVAL;
|
2009-07-30 23:24:27 +08:00
|
|
|
goto err_flash_remove;
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
2009-04-16 20:10:45 +08:00
|
|
|
count /= reg_tuple_size;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
err = -ENOMEM;
|
2009-04-16 20:10:45 +08:00
|
|
|
info = kzalloc(sizeof(struct of_flash) +
|
|
|
|
sizeof(struct of_flash_list) * count, GFP_KERNEL);
|
|
|
|
if (!info)
|
2009-07-30 23:24:27 +08:00
|
|
|
goto err_flash_remove;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
|
|
|
dev_set_drvdata(&dev->dev, info);
|
|
|
|
|
2009-12-30 03:15:23 +08:00
|
|
|
mtd_list = kzalloc(sizeof(*mtd_list) * count, GFP_KERNEL);
|
2009-07-30 23:24:27 +08:00
|
|
|
if (!mtd_list)
|
|
|
|
goto err_flash_remove;
|
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
err = -ENXIO;
|
|
|
|
if (of_address_to_resource(dp, i, &res)) {
|
|
|
|
dev_err(&dev->dev, "Can't get IO address from device"
|
|
|
|
" tree\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
dev_dbg(&dev->dev, "of_flash device: %.8llx-%.8llx\n",
|
|
|
|
(unsigned long long)res.start,
|
|
|
|
(unsigned long long)res.end);
|
|
|
|
|
|
|
|
err = -EBUSY;
|
2009-07-17 23:54:14 +08:00
|
|
|
res_size = resource_size(&res);
|
|
|
|
info->list[i].res = request_mem_region(res.start, res_size,
|
2009-04-16 20:10:45 +08:00
|
|
|
dev_name(&dev->dev));
|
|
|
|
if (!info->list[i].res)
|
|
|
|
goto err_out;
|
|
|
|
|
|
|
|
err = -ENXIO;
|
|
|
|
width = of_get_property(dp, "bank-width", NULL);
|
|
|
|
if (!width) {
|
|
|
|
dev_err(&dev->dev, "Can't get bank width from device"
|
|
|
|
" tree\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
info->list[i].map.name = dev_name(&dev->dev);
|
|
|
|
info->list[i].map.phys = res.start;
|
2009-07-17 23:54:14 +08:00
|
|
|
info->list[i].map.size = res_size;
|
2009-04-16 20:10:45 +08:00
|
|
|
info->list[i].map.bankwidth = *width;
|
|
|
|
|
|
|
|
err = -ENOMEM;
|
|
|
|
info->list[i].map.virt = ioremap(info->list[i].map.phys,
|
|
|
|
info->list[i].map.size);
|
|
|
|
if (!info->list[i].map.virt) {
|
|
|
|
dev_err(&dev->dev, "Failed to ioremap() flash"
|
|
|
|
" region\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
simple_map_init(&info->list[i].map);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
if (probe_type) {
|
|
|
|
info->list[i].mtd = do_map_probe(probe_type,
|
|
|
|
&info->list[i].map);
|
|
|
|
} else {
|
|
|
|
info->list[i].mtd = obsolete_probe(dev,
|
|
|
|
&info->list[i].map);
|
|
|
|
}
|
|
|
|
mtd_list[i] = info->list[i].mtd;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
err = -ENXIO;
|
|
|
|
if (!info->list[i].mtd) {
|
|
|
|
dev_err(&dev->dev, "do_map_probe() failed\n");
|
|
|
|
goto err_out;
|
|
|
|
} else {
|
|
|
|
info->list_size++;
|
|
|
|
}
|
|
|
|
info->list[i].mtd->owner = THIS_MODULE;
|
|
|
|
info->list[i].mtd->dev.parent = &dev->dev;
|
|
|
|
}
|
2007-09-07 11:23:53 +08:00
|
|
|
|
2009-04-16 20:10:45 +08:00
|
|
|
err = 0;
|
|
|
|
if (info->list_size == 1) {
|
|
|
|
info->cmtd = info->list[0].mtd;
|
|
|
|
} else if (info->list_size > 1) {
|
|
|
|
/*
|
|
|
|
* We detected multiple devices. Concatenate them together.
|
|
|
|
*/
|
|
|
|
#ifdef CONFIG_MTD_CONCAT
|
|
|
|
info->cmtd = mtd_concat_create(mtd_list, info->list_size,
|
|
|
|
dev_name(&dev->dev));
|
|
|
|
if (info->cmtd == NULL)
|
|
|
|
err = -ENXIO;
|
|
|
|
#else
|
|
|
|
printk(KERN_ERR "physmap_of: multiple devices "
|
|
|
|
"found but MTD concat support disabled.\n");
|
|
|
|
err = -ENXIO;
|
|
|
|
#endif
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
2009-04-16 20:10:45 +08:00
|
|
|
if (err)
|
|
|
|
goto err_out;
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2008-01-16 07:54:43 +08:00
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
2010-03-10 03:27:56 +08:00
|
|
|
part_probe_types = of_get_probes(dp);
|
2009-04-16 20:10:45 +08:00
|
|
|
err = parse_mtd_partitions(info->cmtd, part_probe_types,
|
|
|
|
&info->parts, 0);
|
2010-03-10 03:27:56 +08:00
|
|
|
if (err < 0) {
|
|
|
|
of_free_probes(part_probe_types);
|
2008-01-16 07:54:43 +08:00
|
|
|
return err;
|
2010-03-10 03:27:56 +08:00
|
|
|
}
|
|
|
|
of_free_probes(part_probe_types);
|
2008-01-16 07:54:43 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_MTD_OF_PARTS
|
|
|
|
if (err == 0) {
|
2008-10-12 22:18:36 +08:00
|
|
|
err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts);
|
2008-01-16 07:54:43 +08:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (err == 0) {
|
|
|
|
err = parse_obsolete_partitions(dev, info, dp);
|
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
}
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
if (err > 0)
|
2009-04-16 20:10:45 +08:00
|
|
|
add_mtd_partitions(info->cmtd, info->parts, err);
|
2007-09-20 09:22:25 +08:00
|
|
|
else
|
2008-01-16 07:54:43 +08:00
|
|
|
#endif
|
2009-04-16 20:10:45 +08:00
|
|
|
add_mtd_device(info->cmtd);
|
|
|
|
|
|
|
|
kfree(mtd_list);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_out:
|
2009-04-16 20:10:45 +08:00
|
|
|
kfree(mtd_list);
|
2009-07-30 23:24:27 +08:00
|
|
|
err_flash_remove:
|
2007-09-20 09:22:25 +08:00
|
|
|
of_flash_remove(dev);
|
2009-04-16 20:10:45 +08:00
|
|
|
|
2006-12-06 18:17:49 +08:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static struct of_device_id of_flash_match[] = {
|
2007-09-07 11:23:53 +08:00
|
|
|
{
|
|
|
|
.compatible = "cfi-flash",
|
|
|
|
.data = (void *)"cfi_probe",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
/* FIXME: JEDEC chips can't be safely and reliably
|
|
|
|
* probed, although the mtd code gets it right in
|
|
|
|
* practice most of the time. We should use the
|
|
|
|
* vendor and device ids specified by the binding to
|
|
|
|
* bypass the heuristic probe code, but the mtd layer
|
|
|
|
* provides, at present, no interface for doing so
|
|
|
|
* :(. */
|
|
|
|
.compatible = "jedec-flash",
|
|
|
|
.data = (void *)"jedec_probe",
|
|
|
|
},
|
2009-07-17 20:39:23 +08:00
|
|
|
{
|
|
|
|
.compatible = "mtd-ram",
|
|
|
|
.data = (void *)"map_ram",
|
|
|
|
},
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
|
|
|
.type = "rom",
|
|
|
|
.compatible = "direct-mapped"
|
|
|
|
},
|
|
|
|
{ },
|
|
|
|
};
|
2007-09-20 09:22:25 +08:00
|
|
|
MODULE_DEVICE_TABLE(of, of_flash_match);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static struct of_platform_driver of_flash_driver = {
|
|
|
|
.name = "of-flash",
|
|
|
|
.match_table = of_flash_match,
|
|
|
|
.probe = of_flash_probe,
|
|
|
|
.remove = of_flash_remove,
|
2006-12-06 18:17:49 +08:00
|
|
|
};
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static int __init of_flash_init(void)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
2007-09-20 09:22:25 +08:00
|
|
|
return of_register_platform_driver(&of_flash_driver);
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
static void __exit of_flash_exit(void)
|
2006-12-06 18:17:49 +08:00
|
|
|
{
|
2007-09-20 09:22:25 +08:00
|
|
|
of_unregister_platform_driver(&of_flash_driver);
|
2006-12-06 18:17:49 +08:00
|
|
|
}
|
|
|
|
|
2007-09-20 09:22:25 +08:00
|
|
|
module_init(of_flash_init);
|
|
|
|
module_exit(of_flash_exit);
|
2006-12-06 18:17:49 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Vitaly Wool <vwool@ru.mvista.com>");
|
2007-09-20 09:22:25 +08:00
|
|
|
MODULE_DESCRIPTION("Device tree based MTD map driver");
|