Skip to content

Commit

Permalink
[MTD] sharpsl_nand: switch to driver model usage.
Browse files Browse the repository at this point in the history
Start cleanup of sharpsl_nand driver. Convert it to platform driver.
Corresponding device is temprorary registered in sharpsl.c but will be
later moved to corresponding board files.

Signed-off-by: Dmitry Baryshkov <dbaryshkov@gmail.com>
  • Loading branch information
Dmitry Baryshkov committed Oct 29, 2008
1 parent 0173a32 commit 2661524
Showing 1 changed file with 56 additions and 7 deletions.
63 changes: 56 additions & 7 deletions drivers/mtd/nand/sharpsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@
#include <linux/mtd/nand_ecc.h>
#include <linux/mtd/partitions.h>
#include <linux/interrupt.h>
#include <linux/platform_device.h>

#include <asm/io.h>
#include <mach/hardware.h>
#include <asm/mach-types.h>

static void __iomem *sharpsl_io_base;
static int sharpsl_phys_base = 0x0C000000;

/* register offset */
#define ECCLPLB sharpsl_io_base+0x00 /* line parity 7 - 0 bit */
Expand Down Expand Up @@ -150,10 +151,11 @@ const char *part_probes[] = { "cmdlinepart", NULL };
/*
* Main initialization routine
*/
static int __init sharpsl_nand_init(void)
static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
{
struct nand_chip *this;
struct mtd_partition *sharpsl_partition_info;
struct resource *r;
int err = 0;

/* Allocate memory for MTD device structure and private data */
Expand All @@ -163,8 +165,15 @@ static int __init sharpsl_nand_init(void)
return -ENOMEM;
}

r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!r) {
dev_err(&pdev->dev, "no io memory resource defined!\n");
err = -ENODEV;
goto err_get_res;
}

/* map physical address */
sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000);
sharpsl_io_base = ioremap(r->start, resource_size(r));
if (!sharpsl_io_base) {
printk("ioremap to access Sharp SL NAND chip failed\n");
kfree(sharpsl_mtd);
Expand Down Expand Up @@ -242,14 +251,16 @@ static int __init sharpsl_nand_init(void)

/* Return happy */
return 0;
}

module_init(sharpsl_nand_init);
err_get_res:
kfree(sharpsl_mtd);
return err;
}

/*
* Clean up routine
*/
static void __exit sharpsl_nand_cleanup(void)
static int __devexit sharpsl_nand_remove(struct platform_device *pdev)
{
/* Release resources, unregister device */
nand_release(sharpsl_mtd);
Expand All @@ -258,9 +269,47 @@ static void __exit sharpsl_nand_cleanup(void)

/* Free the MTD device structure */
kfree(sharpsl_mtd);

return 0;
}

static struct platform_driver sharpsl_nand_driver = {
.driver = {
.name = "sharpsl-nand",
.owner = THIS_MODULE,
},
.probe = sharpsl_nand_probe,
.remove = __devexit_p(sharpsl_nand_remove),
};

static struct resource sharpsl_nand_resources[] = {
{
.start = 0x0C000000,
.end = 0x0C000FFF,
.flags = IORESOURCE_MEM,
},
};

static struct platform_device sharpsl_nand_device = {
.name = "sharpsl-nand",
.id = -1,
.resource = sharpsl_nand_resources,
.num_resources = ARRAY_SIZE(sharpsl_nand_resources),
};

static int __init sharpsl_nand_init(void)
{
platform_device_register(&sharpsl_nand_device);
return platform_driver_register(&sharpsl_nand_driver);
}
module_init(sharpsl_nand_init);

module_exit(sharpsl_nand_cleanup);
static void __exit sharpsl_nand_exit(void)
{
platform_driver_unregister(&sharpsl_nand_driver);
platform_device_unregister(&sharpsl_nand_device);
}
module_exit(sharpsl_nand_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>");
Expand Down

0 comments on commit 2661524

Please sign in to comment.