Linux 4.19.133
[linux/fpc-iii.git] / drivers / mtd / nand / onenand / generic.c
blobacad17ec6581a247f3377b27024cdb839a75a0a1
1 /*
2 * Copyright (c) 2005 Samsung Electronics
3 * Kyungmin Park <kyungmin.park@samsung.com>
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.
9 * Overview:
10 * This is a device driver for the OneNAND flash for generic boards.
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>
22 * Note: Driver name and platform data format have been updated!
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.
28 #define DRIVER_NAME "onenand-flash"
30 struct onenand_info {
31 struct mtd_info mtd;
32 struct onenand_chip onenand;
35 static int generic_onenand_probe(struct platform_device *pdev)
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;
43 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
44 if (!info)
45 return -ENOMEM;
47 if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
48 err = -EBUSY;
49 goto out_free_info;
52 info->onenand.base = ioremap(res->start, size);
53 if (!info->onenand.base) {
54 err = -ENOMEM;
55 goto out_release_mem_region;
58 info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
59 info->onenand.irq = platform_get_irq(pdev, 0);
61 info->mtd.dev.parent = &pdev->dev;
62 info->mtd.priv = &info->onenand;
64 if (onenand_scan(&info->mtd, 1)) {
65 err = -ENXIO;
66 goto out_iounmap;
69 err = mtd_device_register(&info->mtd, pdata ? pdata->parts : NULL,
70 pdata ? pdata->nr_parts : 0);
72 platform_set_drvdata(pdev, info);
74 return 0;
76 out_iounmap:
77 iounmap(info->onenand.base);
78 out_release_mem_region:
79 release_mem_region(res->start, size);
80 out_free_info:
81 kfree(info);
83 return err;
86 static int generic_onenand_remove(struct platform_device *pdev)
88 struct onenand_info *info = platform_get_drvdata(pdev);
89 struct resource *res = pdev->resource;
90 unsigned long size = resource_size(res);
92 if (info) {
93 onenand_release(&info->mtd);
94 release_mem_region(res->start, size);
95 iounmap(info->onenand.base);
96 kfree(info);
99 return 0;
102 static struct platform_driver generic_onenand_driver = {
103 .driver = {
104 .name = DRIVER_NAME,
106 .probe = generic_onenand_probe,
107 .remove = generic_onenand_remove,
110 module_platform_driver(generic_onenand_driver);
112 MODULE_LICENSE("GPL");
113 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
114 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
115 MODULE_ALIAS("platform:" DRIVER_NAME);