blob: 1c4f97c63e623e518367be0a178beec800e0ceb5 [file] [log] [blame]
Kyungmin Park68ee4b12005-09-09 07:39:50 +01001/*
2 * linux/drivers/mtd/onenand/generic.c
3 *
4 * Copyright (c) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * Overview:
12 * This is a device driver for the OneNAND flash for generic boards.
13 */
14
Kyungmin Park68ee4b12005-09-09 07:39:50 +010015#include <linux/module.h>
16#include <linux/init.h>
Tim Schmielaude259682006-01-08 01:02:05 -080017#include <linux/slab.h>
Kyungmin Park27f4e082005-12-16 11:17:29 +090018#include <linux/platform_device.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010019#include <linux/mtd/mtd.h>
20#include <linux/mtd/onenand.h>
21#include <linux/mtd/partitions.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010022#include <asm/io.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010023
Magnus Damm778dbcc2009-09-18 12:51:44 -070024/*
25 * Note: Driver name and platform data format have been updated!
26 *
27 * This version of the driver is named "onenand-flash" and takes struct
28 * onenand_platform_data as platform data. The old ARM-specific version
29 * with the name "onenand" used to take struct flash_platform_data.
30 */
31#define DRIVER_NAME "onenand-flash"
Kyungmin Park68ee4b12005-09-09 07:39:50 +010032
Kyungmin Park68ee4b12005-09-09 07:39:50 +010033struct onenand_info {
34 struct mtd_info mtd;
Kyungmin Park68ee4b12005-09-09 07:39:50 +010035 struct onenand_chip onenand;
36};
37
Ming Lei7a192ec2009-02-06 23:40:12 +080038static int __devinit generic_onenand_probe(struct platform_device *pdev)
Kyungmin Park68ee4b12005-09-09 07:39:50 +010039{
40 struct onenand_info *info;
Magnus Damm778dbcc2009-09-18 12:51:44 -070041 struct onenand_platform_data *pdata = pdev->dev.platform_data;
Kyungmin Park68ee4b12005-09-09 07:39:50 +010042 struct resource *res = pdev->resource;
Magnus Damm778dbcc2009-09-18 12:51:44 -070043 unsigned long size = resource_size(res);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010044 int err;
45
Burman Yan95b93a02006-11-15 21:10:29 +020046 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010047 if (!info)
48 return -ENOMEM;
49
Magnus Damm778dbcc2009-09-18 12:51:44 -070050 if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
Kyungmin Park68ee4b12005-09-09 07:39:50 +010051 err = -EBUSY;
52 goto out_free_info;
53 }
54
55 info->onenand.base = ioremap(res->start, size);
56 if (!info->onenand.base) {
57 err = -ENOMEM;
58 goto out_release_mem_region;
59 }
60
Magnus Damm778dbcc2009-09-18 12:51:44 -070061 info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0;
Kyungmin Park2c221202006-11-16 11:23:48 +090062 info->onenand.irq = platform_get_irq(pdev, 0);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010063
Kay Sievers475b44c2009-01-06 10:44:38 -080064 info->mtd.name = dev_name(&pdev->dev);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010065 info->mtd.priv = &info->onenand;
66 info->mtd.owner = THIS_MODULE;
67
68 if (onenand_scan(&info->mtd, 1)) {
69 err = -ENXIO;
70 goto out_iounmap;
71 }
72
Artem Bityutskiy42d7fbe2012-03-09 19:24:26 +020073 err = mtd_device_parse_register(&info->mtd, NULL, NULL,
74 pdata ? pdata->parts : NULL,
75 pdata ? pdata->nr_parts : 0);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010076
Ming Lei7a192ec2009-02-06 23:40:12 +080077 platform_set_drvdata(pdev, info);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010078
79 return 0;
80
81out_iounmap:
82 iounmap(info->onenand.base);
83out_release_mem_region:
84 release_mem_region(res->start, size);
85out_free_info:
86 kfree(info);
87
88 return err;
89}
90
Ming Lei7a192ec2009-02-06 23:40:12 +080091static int __devexit generic_onenand_remove(struct platform_device *pdev)
Kyungmin Park68ee4b12005-09-09 07:39:50 +010092{
Ming Lei7a192ec2009-02-06 23:40:12 +080093 struct onenand_info *info = platform_get_drvdata(pdev);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010094 struct resource *res = pdev->resource;
Magnus Damm778dbcc2009-09-18 12:51:44 -070095 unsigned long size = resource_size(res);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010096
Ming Lei7a192ec2009-02-06 23:40:12 +080097 platform_set_drvdata(pdev, NULL);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010098
99 if (info) {
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100100 onenand_release(&info->mtd);
101 release_mem_region(res->start, size);
102 iounmap(info->onenand.base);
103 kfree(info);
104 }
105
106 return 0;
107}
108
Ming Lei7a192ec2009-02-06 23:40:12 +0800109static struct platform_driver generic_onenand_driver = {
110 .driver = {
111 .name = DRIVER_NAME,
112 .owner = THIS_MODULE,
113 },
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100114 .probe = generic_onenand_probe,
115 .remove = __devexit_p(generic_onenand_remove),
116};
117
Axel Linf99640d2011-11-27 20:45:03 +0800118module_platform_driver(generic_onenand_driver);
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100119
120MODULE_LICENSE("GPL");
121MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
122MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
Axel Linf99640d2011-11-27 20:45:03 +0800123MODULE_ALIAS("platform:" DRIVER_NAME);