mtd: onenand: make onenand/generic.c more generic

Remove the ARM dependency from the generic "onenand" platform device
driver.  This change makes the driver useful for other architectures as
well.  Needed for the SuperH kfr2r09 board.

Apart from the obvious Kconfig bits, the most important change is the move
away from ARM specific includes and platform data.  Together with this
change the only in-tree board code gets an update, and the driver name is
also changed gracefully break potential out of tree drivers.

The driver is also updated to allow NULL as platform data together with a
few changes to make use of resource_size() and dev_name().

Signed-off-by: Magnus Damm <damm@igel.co.jp>
Cc: Paul Mundt <lethal@linux-sh.org>
Cc: Tony Lindgren <tony@atomide.com>
Cc: Kyungmin Park <kmpark@infradead.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
This commit is contained in:
Magnus Damm 2009-09-18 12:51:44 -07:00 committed by David Woodhouse
parent f33dabbe79
commit 778dbcc1eb
4 changed files with 24 additions and 13 deletions

View file

@ -87,7 +87,7 @@ static struct mtd_partition apollon_partitions[] = {
}, },
}; };
static struct flash_platform_data apollon_flash_data = { static struct onenand_platform_data apollon_flash_data = {
.parts = apollon_partitions, .parts = apollon_partitions,
.nr_parts = ARRAY_SIZE(apollon_partitions), .nr_parts = ARRAY_SIZE(apollon_partitions),
}; };
@ -99,7 +99,7 @@ static struct resource apollon_flash_resource[] = {
}; };
static struct platform_device apollon_onenand_device = { static struct platform_device apollon_onenand_device = {
.name = "onenand", .name = "onenand-flash",
.id = -1, .id = -1,
.dev = { .dev = {
.platform_data = &apollon_flash_data, .platform_data = &apollon_flash_data,

View file

@ -24,7 +24,6 @@ config MTD_ONENAND_VERIFY_WRITE
config MTD_ONENAND_GENERIC config MTD_ONENAND_GENERIC
tristate "OneNAND Flash device via platform device driver" tristate "OneNAND Flash device via platform device driver"
depends on ARM
help help
Support for OneNAND flash via platform device driver. Support for OneNAND flash via platform device driver.

View file

@ -19,12 +19,16 @@
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/onenand.h> #include <linux/mtd/onenand.h>
#include <linux/mtd/partitions.h> #include <linux/mtd/partitions.h>
#include <asm/io.h> #include <asm/io.h>
#include <asm/mach/flash.h>
#define DRIVER_NAME "onenand"
/*
* Note: Driver name and platform data format have been updated!
*
* This version of the driver is named "onenand-flash" and takes struct
* onenand_platform_data as platform data. The old ARM-specific version
* with the name "onenand" used to take struct flash_platform_data.
*/
#define DRIVER_NAME "onenand-flash"
#ifdef CONFIG_MTD_PARTITIONS #ifdef CONFIG_MTD_PARTITIONS
static const char *part_probes[] = { "cmdlinepart", NULL, }; static const char *part_probes[] = { "cmdlinepart", NULL, };
@ -39,16 +43,16 @@ struct onenand_info {
static int __devinit generic_onenand_probe(struct platform_device *pdev) static int __devinit generic_onenand_probe(struct platform_device *pdev)
{ {
struct onenand_info *info; struct onenand_info *info;
struct flash_platform_data *pdata = pdev->dev.platform_data; struct onenand_platform_data *pdata = pdev->dev.platform_data;
struct resource *res = pdev->resource; struct resource *res = pdev->resource;
unsigned long size = res->end - res->start + 1; unsigned long size = resource_size(res);
int err; int err;
info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL); info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
if (!info) if (!info)
return -ENOMEM; return -ENOMEM;
if (!request_mem_region(res->start, size, pdev->dev.driver->name)) { if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
err = -EBUSY; err = -EBUSY;
goto out_free_info; goto out_free_info;
} }
@ -59,7 +63,7 @@ static int __devinit generic_onenand_probe(struct platform_device *pdev)
goto out_release_mem_region; goto out_release_mem_region;
} }
info->onenand.mmcontrol = pdata->mmcontrol; info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0;
info->onenand.irq = platform_get_irq(pdev, 0); info->onenand.irq = platform_get_irq(pdev, 0);
info->mtd.name = dev_name(&pdev->dev); info->mtd.name = dev_name(&pdev->dev);
@ -75,7 +79,7 @@ static int __devinit generic_onenand_probe(struct platform_device *pdev)
err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
if (err > 0) if (err > 0)
add_mtd_partitions(&info->mtd, info->parts, err); add_mtd_partitions(&info->mtd, info->parts, err);
else if (err <= 0 && pdata->parts) else if (err <= 0 && pdata && pdata->parts)
add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts); add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
else else
#endif #endif
@ -99,7 +103,7 @@ static int __devexit generic_onenand_remove(struct platform_device *pdev)
{ {
struct onenand_info *info = platform_get_drvdata(pdev); struct onenand_info *info = platform_get_drvdata(pdev);
struct resource *res = pdev->resource; struct resource *res = pdev->resource;
unsigned long size = res->end - res->start + 1; unsigned long size = resource_size(res);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);

View file

@ -214,4 +214,12 @@ unsigned onenand_block(struct onenand_chip *this, loff_t addr);
loff_t onenand_addr(struct onenand_chip *this, int block); loff_t onenand_addr(struct onenand_chip *this, int block);
int flexonenand_region(struct mtd_info *mtd, loff_t addr); int flexonenand_region(struct mtd_info *mtd, loff_t addr);
struct mtd_partition;
struct onenand_platform_data {
void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
struct mtd_partition *parts;
unsigned int nr_parts;
};
#endif /* __LINUX_MTD_ONENAND_H */ #endif /* __LINUX_MTD_ONENAND_H */