Merge tag 'io_uring-5.11-2021-01-16' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / mtd / nand / onenand / generic.c
blob8b6f4da5d72011b878732242d0041dc6b6c0b2aa
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright (c) 2005 Samsung Electronics
4 * Kyungmin Park <kyungmin.park@samsung.com>
6 * Overview:
7 * This is a device driver for the OneNAND flash for generic boards.
8 */
10 #include <linux/module.h>
11 #include <linux/slab.h>
12 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/onenand.h>
15 #include <linux/mtd/partitions.h>
16 #include <linux/io.h>
19 * Note: Driver name and platform data format have been updated!
21 * This version of the driver is named "onenand-flash" and takes struct
22 * onenand_platform_data as platform data. The old ARM-specific version
23 * with the name "onenand" used to take struct flash_platform_data.
25 #define DRIVER_NAME "onenand-flash"
27 struct onenand_info {
28 struct mtd_info mtd;
29 struct onenand_chip onenand;
32 static int generic_onenand_probe(struct platform_device *pdev)
34 struct onenand_info *info;
35 struct onenand_platform_data *pdata = dev_get_platdata(&pdev->dev);
36 struct resource *res = pdev->resource;
37 unsigned long size = resource_size(res);
38 int err;
40 info = kzalloc(sizeof(struct onenand_info), GFP_KERNEL);
41 if (!info)
42 return -ENOMEM;
44 if (!request_mem_region(res->start, size, dev_name(&pdev->dev))) {
45 err = -EBUSY;
46 goto out_free_info;
49 info->onenand.base = ioremap(res->start, size);
50 if (!info->onenand.base) {
51 err = -ENOMEM;
52 goto out_release_mem_region;
55 info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
56 info->onenand.irq = platform_get_irq(pdev, 0);
58 info->mtd.dev.parent = &pdev->dev;
59 info->mtd.priv = &info->onenand;
61 if (onenand_scan(&info->mtd, 1)) {
62 err = -ENXIO;
63 goto out_iounmap;
66 err = mtd_device_register(&info->mtd, pdata ? pdata->parts : NULL,
67 pdata ? pdata->nr_parts : 0);
69 platform_set_drvdata(pdev, info);
71 return 0;
73 out_iounmap:
74 iounmap(info->onenand.base);
75 out_release_mem_region:
76 release_mem_region(res->start, size);
77 out_free_info:
78 kfree(info);
80 return err;
83 static int generic_onenand_remove(struct platform_device *pdev)
85 struct onenand_info *info = platform_get_drvdata(pdev);
86 struct resource *res = pdev->resource;
87 unsigned long size = resource_size(res);
89 if (info) {
90 onenand_release(&info->mtd);
91 release_mem_region(res->start, size);
92 iounmap(info->onenand.base);
93 kfree(info);
96 return 0;
99 static struct platform_driver generic_onenand_driver = {
100 .driver = {
101 .name = DRIVER_NAME,
103 .probe = generic_onenand_probe,
104 .remove = generic_onenand_remove,
107 module_platform_driver(generic_onenand_driver);
109 MODULE_LICENSE("GPL");
110 MODULE_AUTHOR("Kyungmin Park <kyungmin.park@samsung.com>");
111 MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards");
112 MODULE_ALIAS("platform:" DRIVER_NAME);