Linux v2.6.15-rc7
[pohmelfs.git] / drivers / mtd / onenand / generic.c
blob45c077d0f0630289f9763e35beeccf11ca285cc4
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/platform_device.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/onenand.h>
20 #include <linux/mtd/partitions.h>
22 #include <asm/io.h>
23 #include <asm/mach/flash.h>
25 #define DRIVER_NAME "onenand"
28 #ifdef CONFIG_MTD_PARTITIONS
29 static const char *part_probes[] = { "cmdlinepart", NULL, };
30 #endif
32 struct onenand_info {
33 struct mtd_info mtd;
34 struct mtd_partition *parts;
35 struct onenand_chip onenand;
38 static int __devinit generic_onenand_probe(struct device *dev)
40 struct onenand_info *info;
41 struct platform_device *pdev = to_platform_device(dev);
42 struct flash_platform_data *pdata = pdev->dev.platform_data;
43 struct resource *res = pdev->resource;
44 unsigned long size = res->end - res->start + 1;
45 int err;
47 info = kmalloc(sizeof(struct onenand_info), GFP_KERNEL);
48 if (!info)
49 return -ENOMEM;
51 memset(info, 0, sizeof(struct onenand_info));
53 if (!request_mem_region(res->start, size, dev->driver->name)) {
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->mmcontrol;
66 info->mtd.name = pdev->dev.bus_id;
67 info->mtd.priv = &info->onenand;
68 info->mtd.owner = THIS_MODULE;
70 if (onenand_scan(&info->mtd, 1)) {
71 err = -ENXIO;
72 goto out_iounmap;
75 #ifdef CONFIG_MTD_PARTITIONS
76 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
77 if (err > 0)
78 add_mtd_partitions(&info->mtd, info->parts, err);
79 else if (err < 0 && pdata->parts)
80 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts);
81 else
82 #endif
83 err = add_mtd_device(&info->mtd);
85 dev_set_drvdata(&pdev->dev, info);
87 return 0;
89 out_iounmap:
90 iounmap(info->onenand.base);
91 out_release_mem_region:
92 release_mem_region(res->start, size);
93 out_free_info:
94 kfree(info);
96 return err;
99 static int __devexit generic_onenand_remove(struct device *dev)
101 struct platform_device *pdev = to_platform_device(dev);
102 struct onenand_info *info = dev_get_drvdata(&pdev->dev);
103 struct resource *res = pdev->resource;
104 unsigned long size = res->end - res->start + 1;
106 dev_set_drvdata(&pdev->dev, NULL);
108 if (info) {
109 if (info->parts)
110 del_mtd_partitions(&info->mtd);
111 else
112 del_mtd_device(&info->mtd);
114 onenand_release(&info->mtd);
115 release_mem_region(res->start, size);
116 iounmap(info->onenand.base);
117 kfree(info);
120 return 0;
123 static struct device_driver generic_onenand_driver = {
124 .name = DRIVER_NAME,
125 .bus = &platform_bus_type,
126 .probe = generic_onenand_probe,
127 .remove = __devexit_p(generic_onenand_remove),
130 MODULE_ALIAS(DRIVER_NAME);
132 static int __init generic_onenand_init(void)
134 return driver_register(&generic_onenand_driver);
137 static void __exit generic_onenand_exit(void)
139 driver_unregister(&generic_onenand_driver);
142 module_init(generic_onenand_init);
143 module_exit(generic_onenand_exit);
145 MODULE_LICENSE("GPL");
146 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
147 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");