QE/FHCI: fixed the CONTROL bug
[zen-stable.git] / drivers / mtd / onenand / generic.c
blob2d70d354d846b6d36efb334434533445c0e21270
1 /*
2 * linux/drivers/mtd/onenand/generic.c
4 * Copyright (c) 2005 Samsung Electronics
5 * Kyungmin Park <kyungmin.park@samsung.com>
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.
11 * Overview:
12 * This is a device driver for the OneNAND flash for generic boards.
15 #include <linux/module.h>
16 #include <linux/init.h>
17 #include <linux/slab.h>
18 #include <linux/platform_device.h>
19 #include <linux/mtd/mtd.h>
20 #include <linux/mtd/onenand.h>
21 #include <linux/mtd/partitions.h>
22 #include <asm/io.h>
25 * Note: Driver name and platform data format have been updated!
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.
31 #define DRIVER_NAME "onenand-flash"
33 static const char *part_probes[] = { "cmdlinepart", NULL, };
35 struct onenand_info {
36 struct mtd_info mtd;
37 struct mtd_partition *parts;
38 struct onenand_chip onenand;
41 static int __devinit generic_onenand_probe(struct platform_device *pdev)
43 struct onenand_info *info;
44 struct onenand_platform_data *pdata = pdev->dev.platform_data;
45 struct resource *res = pdev->resource;
46 unsigned long size = resource_size(res);
47 int err;
49 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
50 if (!info)
51 return -ENOMEM;
53 if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
54 err = -EBUSY;
55 goto out_free_info;
58 info->onenand.base = ioremap(res->start, size);
59 if (!info->onenand.base) {
60 err = -ENOMEM;
61 goto out_release_mem_region;
64 info->onenand.mmcontrol = pdata ? pdata->mmcontrol : 0;
65 info->onenand.irq = platform_get_irq(pdev, 0);
67 info->mtd.name = dev_name(&pdev->dev);
68 info->mtd.priv = &info->onenand;
69 info->mtd.owner = THIS_MODULE;
71 if (onenand_scan(&info->mtd, 1)) {
72 err = -ENXIO;
73 goto out_iounmap;
76 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
77 if (err > 0)
78 mtd_device_register(&info->mtd, info->parts, err);
79 else if (err <= 0 && pdata && pdata->parts)
80 mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts);
81 else
82 err = mtd_device_register(&info->mtd, NULL, 0);
84 platform_set_drvdata(pdev, info);
86 return 0;
88 out_iounmap:
89 iounmap(info->onenand.base);
90 out_release_mem_region:
91 release_mem_region(res->start, size);
92 out_free_info:
93 kfree(info);
95 return err;
98 static int __devexit generic_onenand_remove(struct platform_device *pdev)
100 struct onenand_info *info = platform_get_drvdata(pdev);
101 struct resource *res = pdev->resource;
102 unsigned long size = resource_size(res);
104 platform_set_drvdata(pdev, NULL);
106 if (info) {
107 mtd_device_unregister(&info->mtd);
108 onenand_release(&info->mtd);
109 release_mem_region(res->start, size);
110 iounmap(info->onenand.base);
111 kfree(info);
114 return 0;
117 static struct platform_driver generic_onenand_driver = {
118 .driver = {
119 .name = DRIVER_NAME,
120 .owner = THIS_MODULE,
122 .probe = generic_onenand_probe,
123 .remove = __devexit_p(generic_onenand_remove),
126 MODULE_ALIAS("platform:" DRIVER_NAME);
128 static int __init generic_onenand_init(void)
130 return platform_driver_register(&generic_onenand_driver);
133 static void __exit generic_onenand_exit(void)
135 platform_driver_unregister(&generic_onenand_driver);
138 module_init(generic_onenand_init);
139 module_exit(generic_onenand_exit);
141 MODULE_LICENSE("GPL");
142 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
143 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");