1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2005 Samsung Electronics
4 * Kyungmin Park <kyungmin.park@samsung.com>
7 * This is a device driver for the OneNAND flash for generic boards.
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>
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"
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
);
40 info
= kzalloc(sizeof(struct onenand_info
), GFP_KERNEL
);
44 if (!request_mem_region(res
->start
, size
, dev_name(&pdev
->dev
))) {
49 info
->onenand
.base
= ioremap(res
->start
, size
);
50 if (!info
->onenand
.base
) {
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)) {
66 err
= mtd_device_register(&info
->mtd
, pdata
? pdata
->parts
: NULL
,
67 pdata
? pdata
->nr_parts
: 0);
69 platform_set_drvdata(pdev
, info
);
74 iounmap(info
->onenand
.base
);
75 out_release_mem_region
:
76 release_mem_region(res
->start
, size
);
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
);
90 onenand_release(&info
->mtd
);
91 release_mem_region(res
->start
, size
);
92 iounmap(info
->onenand
.base
);
99 static struct platform_driver generic_onenand_driver
= {
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
);