blob: 32a216d31141ba91a48f3f3724d7f7659d29dd0e [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>
Tim Schmielaude259682006-01-08 01:02:05 -080016#include <linux/slab.h>
Kyungmin Park27f4e082005-12-16 11:17:29 +090017#include <linux/platform_device.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010018#include <linux/mtd/mtd.h>
19#include <linux/mtd/onenand.h>
20#include <linux/mtd/partitions.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010021#include <asm/io.h>
Kyungmin Park68ee4b12005-09-09 07:39:50 +010022
Magnus Damm778dbcc2009-09-18 12:51:44 -070023/*
24 * Note: Driver name and platform data format have been updated!
25 *
26 * This version of the driver is named "onenand-flash" and takes struct
27 * onenand_platform_data as platform data. The old ARM-specific version
28 * with the name "onenand" used to take struct flash_platform_data.
29 */
30#define DRIVER_NAME "onenand-flash"
Kyungmin Park68ee4b12005-09-09 07:39:50 +010031
Kyungmin Park68ee4b12005-09-09 07:39:50 +010032struct onenand_info {
33 struct mtd_info mtd;
Kyungmin Park68ee4b12005-09-09 07:39:50 +010034 struct onenand_chip onenand;
35};
36
Bill Pemberton06f25512012-11-19 13:23:07 -050037static int generic_onenand_probe(struct platform_device *pdev)
Kyungmin Park68ee4b12005-09-09 07:39:50 +010038{
39 struct onenand_info *info;
Jingoo Hane09f7f92013-07-30 17:18:53 +090040 struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010041 struct resource *res = pdev->resource;
Magnus Damm778dbcc2009-09-18 12:51:44 -070042 unsigned long size = resource_size(res);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010043 int err;
44
Burman Yan95b93a02006-11-15 21:10:29 +020045 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010046 if (!info)
47 return -ENOMEM;
48
Magnus Damm778dbcc2009-09-18 12:51:44 -070049 if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
Kyungmin Park68ee4b12005-09-09 07:39:50 +010050 err = -EBUSY;
51 goto out_free_info;
52 }
53
54 info->onenand.base = ioremap(res->start, size);
55 if (!info->onenand.base) {
56 err = -ENOMEM;
57 goto out_release_mem_region;
58 }
59
Brian Norris8b3ae732013-09-20 12:44:26 -070060 info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
Kyungmin Park2c221202006-11-16 11:23:48 +090061 info->onenand.irq = platform_get_irq(pdev, 0);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010062
Kay Sievers475b44c2009-01-06 10:44:38 -080063 info->mtd.name = dev_name(&pdev->dev);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010064 info->mtd.priv = &info->onenand;
65 info->mtd.owner = THIS_MODULE;
66
67 if (onenand_scan(&info->mtd, 1)) {
68 err = -ENXIO;
69 goto out_iounmap;
70 }
71
Artem Bityutskiy42d7fbe2012-03-09 19:24:26 +020072 err = mtd_device_parse_register(&info->mtd, NULL, NULL,
73 pdata ? pdata->parts : NULL,
74 pdata ? pdata->nr_parts : 0);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010075
Ming Lei7a192ec2009-02-06 23:40:12 +080076 platform_set_drvdata(pdev, info);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010077
78 return 0;
79
80out_iounmap:
81 iounmap(info->onenand.base);
82out_release_mem_region:
83 release_mem_region(res->start, size);
84out_free_info:
85 kfree(info);
86
87 return err;
88}
89
Bill Pemberton810b7e02012-11-19 13:26:04 -050090static int generic_onenand_remove(struct platform_device *pdev)
Kyungmin Park68ee4b12005-09-09 07:39:50 +010091{
Ming Lei7a192ec2009-02-06 23:40:12 +080092 struct onenand_info *info = platform_get_drvdata(pdev);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010093 struct resource *res = pdev->resource;
Magnus Damm778dbcc2009-09-18 12:51:44 -070094 unsigned long size = resource_size(res);
Kyungmin Park68ee4b12005-09-09 07:39:50 +010095
Kyungmin Park68ee4b12005-09-09 07:39:50 +010096 if (info) {
Kyungmin Park68ee4b12005-09-09 07:39:50 +010097 onenand_release(&info->mtd);
98 release_mem_region(res->start, size);
99 iounmap(info->onenand.base);
100 kfree(info);
101 }
102
103 return 0;
104}
105
Ming Lei7a192ec2009-02-06 23:40:12 +0800106static struct platform_driver generic_onenand_driver = {
107 .driver = {
108 .name = DRIVER_NAME,
Ming Lei7a192ec2009-02-06 23:40:12 +0800109 },
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100110 .probe = generic_onenand_probe,
Bill Pemberton5153b882012-11-19 13:21:24 -0500111 .remove = generic_onenand_remove,
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100112};
113
Axel Linf99640d2011-11-27 20:45:03 +0800114module_platform_driver(generic_onenand_driver);
Kyungmin Park68ee4b12005-09-09 07:39:50 +0100115
116MODULE_LICENSE("GPL");
117MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
118MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
Axel Linf99640d2011-11-27 20:45:03 +0800119MODULE_ALIAS("platform:" DRIVER_NAME);