xref: /linux/drivers/mtd/nand/onenand/generic.c (revision fa84cf094ef9667e2b91c104b0a788fd1896f482)
1 /*
2  *  Copyright (c) 2005 Samsung Electronics
3  *  Kyungmin Park <kyungmin.park@samsung.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  *
9  *  Overview:
10  *   This is a device driver for the OneNAND flash for generic boards.
11  */
12 
13 #include <linux/module.h>
14 #include <linux/slab.h>
15 #include <linux/platform_device.h>
16 #include <linux/mtd/mtd.h>
17 #include <linux/mtd/onenand.h>
18 #include <linux/mtd/partitions.h>
19 #include <linux/io.h>
20 
21 /*
22  * Note: Driver name and platform data format have been updated!
23  *
24  * This version of the driver is named "onenand-flash" and takes struct
25  * onenand_platform_data as platform data. The old ARM-specific version
26  * with the name "onenand" used to take struct flash_platform_data.
27  */
28 #define DRIVER_NAME	"onenand-flash"
29 
30 struct onenand_info {
31 	struct mtd_info		mtd;
32 	struct onenand_chip	onenand;
33 };
34 
35 static int generic_onenand_probe(struct platform_device *pdev)
36 {
37 	struct onenand_info *info;
38 	struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev);
39 	struct resource *res = pdev->resource;
40 	unsigned long size = resource_size(res);
41 	int err;
42 
43 	info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
44 	if (!info)
45 		return -ENOMEM;
46 
47 	if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
48 		err = -EBUSY;
49 		goto out_free_info;
50 	}
51 
52 	info->onenand.base = ioremap(res->start, size);
53 	if (!info->onenand.base) {
54 		err = -ENOMEM;
55 		goto out_release_mem_region;
56 	}
57 
58 	info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
59 	info->onenand.irq = platform_get_irq(pdev, 0);
60 
61 	info->mtd.dev.parent = &pdev->dev;
62 	info->mtd.priv = &info->onenand;
63 
64 	if (onenand_scan(&info->mtd, 1)) {
65 		err = -ENXIO;
66 		goto out_iounmap;
67 	}
68 
69 	err = mtd_device_parse_register(&info->mtd, NULL, NULL,
70 					pdata ? pdata->parts : NULL,
71 					pdata ? pdata->nr_parts : 0);
72 
73 	platform_set_drvdata(pdev, info);
74 
75 	return 0;
76 
77 out_iounmap:
78 	iounmap(info->onenand.base);
79 out_release_mem_region:
80 	release_mem_region(res->start, size);
81 out_free_info:
82 	kfree(info);
83 
84 	return err;
85 }
86 
87 static int generic_onenand_remove(struct platform_device *pdev)
88 {
89 	struct onenand_info *info = platform_get_drvdata(pdev);
90 	struct resource *res = pdev->resource;
91 	unsigned long size = resource_size(res);
92 
93 	if (info) {
94 		onenand_release(&info->mtd);
95 		release_mem_region(res->start, size);
96 		iounmap(info->onenand.base);
97 		kfree(info);
98 	}
99 
100 	return 0;
101 }
102 
103 static struct platform_driver generic_onenand_driver = {
104 	.driver = {
105 		.name		= DRIVER_NAME,
106 	},
107 	.probe		= generic_onenand_probe,
108 	.remove		= generic_onenand_remove,
109 };
110 
111 module_platform_driver(generic_onenand_driver);
112 
113 MODULE_LICENSE("GPL");
114 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
115 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
116 MODULE_ALIAS("platform:" DRIVER_NAME);
117