mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-19 10:44:14 +08:00
7a192ec334
This patch fixes the bug reported in http://bugzilla.kernel.org/show_bug.cgi?id=11681. "Lots of device drivers register a 'struct device_driver' with the '.bus' member set to '&platform_bus_type'. This is wrong, since the platform_bus functions expect the 'struct device_driver' to be wrapped up in a 'struct platform_driver' which provides some additional callbacks (like suspend_late, resume_early). The effect may be that platform_suspend_late() uses bogus data outside the device_driver struct as a pointer pointer to the device driver's suspend_late() function or other hard to reproduce failures."(Lothar Wassmann) Signed-off-by: Ming Lei <tom.leiming@gmail.com> Acked-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Acked-by: David Brownell <dbrownell@users.sourceforge.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
148 lines
3.4 KiB
C
148 lines
3.4 KiB
C
/*
|
|
* linux/drivers/mtd/onenand/generic.c
|
|
*
|
|
* Copyright (c) 2005 Samsung Electronics
|
|
* Kyungmin Park <kyungmin.park@samsung.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* Overview:
|
|
* This is a device driver for the OneNAND flash for generic boards.
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
#include <linux/init.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mtd/onenand.h>
|
|
#include <linux/mtd/partitions.h>
|
|
|
|
#include <asm/io.h>
|
|
#include <asm/mach/flash.h>
|
|
|
|
#define DRIVER_NAME "onenand"
|
|
|
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
|
static const char *part_probes[] = { "cmdlinepart", NULL, };
|
|
#endif
|
|
|
|
struct onenand_info {
|
|
struct mtd_info mtd;
|
|
struct mtd_partition *parts;
|
|
struct onenand_chip onenand;
|
|
};
|
|
|
|
static int __devinit generic_onenand_probe(struct platform_device *pdev)
|
|
{
|
|
struct onenand_info *info;
|
|
struct flash_platform_data *pdata = pdev->dev.platform_data;
|
|
struct resource *res = pdev->resource;
|
|
unsigned long size = res->end - res->start + 1;
|
|
int err;
|
|
|
|
info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
|
|
if (!info)
|
|
return -ENOMEM;
|
|
|
|
if (!request_mem_region(res->start, size, pdev->dev.driver->name)) {
|
|
err = -EBUSY;
|
|
goto out_free_info;
|
|
}
|
|
|
|
info->onenand.base = ioremap(res->start, size);
|
|
if (!info->onenand.base) {
|
|
err = -ENOMEM;
|
|
goto out_release_mem_region;
|
|
}
|
|
|
|
info->onenand.mmcontrol = pdata->mmcontrol;
|
|
info->onenand.irq = platform_get_irq(pdev, 0);
|
|
|
|
info->mtd.name = dev_name(&pdev->dev);
|
|
info->mtd.priv = &info->onenand;
|
|
info->mtd.owner = THIS_MODULE;
|
|
|
|
if (onenand_scan(&info->mtd, 1)) {
|
|
err = -ENXIO;
|
|
goto out_iounmap;
|
|
}
|
|
|
|
#ifdef CONFIG_MTD_PARTITIONS
|
|
err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
|
|
if (err > 0)
|
|
add_mtd_partitions(&info->mtd, info->parts, err);
|
|
else if (err <= 0 && pdata->parts)
|
|
add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
|
|
else
|
|
#endif
|
|
err = add_mtd_device(&info->mtd);
|
|
|
|
platform_set_drvdata(pdev, info);
|
|
|
|
return 0;
|
|
|
|
out_iounmap:
|
|
iounmap(info->onenand.base);
|
|
out_release_mem_region:
|
|
release_mem_region(res->start, size);
|
|
out_free_info:
|
|
kfree(info);
|
|
|
|
return err;
|
|
}
|
|
|
|
static int __devexit generic_onenand_remove(struct platform_device *pdev)
|
|
{
|
|
struct onenand_info *info = platform_get_drvdata(pdev);
|
|
struct resource *res = pdev->resource;
|
|
unsigned long size = res->end - res->start + 1;
|
|
|
|
platform_set_drvdata(pdev, NULL);
|
|
|
|
if (info) {
|
|
if (info->parts)
|
|
del_mtd_partitions(&info->mtd);
|
|
else
|
|
del_mtd_device(&info->mtd);
|
|
|
|
onenand_release(&info->mtd);
|
|
release_mem_region(res->start, size);
|
|
iounmap(info->onenand.base);
|
|
kfree(info);
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct platform_driver generic_onenand_driver = {
|
|
.driver = {
|
|
.name = DRIVER_NAME,
|
|
.owner = THIS_MODULE,
|
|
},
|
|
.probe = generic_onenand_probe,
|
|
.remove = __devexit_p(generic_onenand_remove),
|
|
};
|
|
|
|
MODULE_ALIAS(DRIVER_NAME);
|
|
|
|
static int __init generic_onenand_init(void)
|
|
{
|
|
return platform_driver_register(&generic_onenand_driver);
|
|
}
|
|
|
|
static void __exit generic_onenand_exit(void)
|
|
{
|
|
platform_driver_unregister(&generic_onenand_driver);
|
|
}
|
|
|
|
module_init(generic_onenand_init);
|
|
module_exit(generic_onenand_exit);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
|
|
MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
|