2019-06-04 11:11:33 +03:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-05-06 19:31:18 +04:00
|
|
|
/*
|
|
|
|
* Generic NAND driver
|
|
|
|
*
|
|
|
|
* Author: Vitaly Wool <vitalywool@gmail.com>
|
|
|
|
*/
|
|
|
|
|
2014-01-03 06:16:28 +04:00
|
|
|
#include <linux/err.h>
|
2007-05-06 19:31:18 +04:00
|
|
|
#include <linux/io.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/mtd/mtd.h>
|
2018-09-07 01:38:46 +03:00
|
|
|
#include <linux/mtd/platnand.h>
|
2007-05-06 19:31:18 +04:00
|
|
|
|
|
|
|
struct plat_nand_data {
|
|
|
|
struct nand_chip chip;
|
|
|
|
void __iomem *io_base;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe for the NAND device.
|
|
|
|
*/
|
2012-11-19 22:23:07 +04:00
|
|
|
static int plat_nand_probe(struct platform_device *pdev)
|
2007-05-06 19:31:18 +04:00
|
|
|
{
|
2013-07-30 12:18:33 +04:00
|
|
|
struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
|
2007-05-06 19:31:18 +04:00
|
|
|
struct plat_nand_data *data;
|
2015-12-10 11:00:19 +03:00
|
|
|
struct mtd_info *mtd;
|
2009-10-20 03:45:29 +04:00
|
|
|
struct resource *res;
|
2012-03-28 22:13:05 +04:00
|
|
|
const char **part_types;
|
2009-10-20 03:45:29 +04:00
|
|
|
int err = 0;
|
|
|
|
|
2012-07-22 10:59:57 +04:00
|
|
|
if (!pdata) {
|
|
|
|
dev_err(&pdev->dev, "platform_nand_data is missing\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2010-08-12 06:53:55 +04:00
|
|
|
if (pdata->chip.nr_chips < 1) {
|
|
|
|
dev_err(&pdev->dev, "invalid number of chips specified\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2007-05-06 19:31:18 +04:00
|
|
|
/* Allocate memory for the device structure (and zero it) */
|
2014-01-03 06:16:28 +04:00
|
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data),
|
|
|
|
GFP_KERNEL);
|
2014-01-03 06:17:29 +04:00
|
|
|
if (!data)
|
2007-05-06 19:31:18 +04:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-01-07 17:38:12 +04:00
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-01-03 06:16:28 +04:00
|
|
|
data->io_base = devm_ioremap_resource(&pdev->dev, res);
|
|
|
|
if (IS_ERR(data->io_base))
|
|
|
|
return PTR_ERR(data->io_base);
|
2007-05-06 19:31:18 +04:00
|
|
|
|
2015-10-31 06:33:25 +03:00
|
|
|
nand_set_flash_node(&data->chip, pdev->dev.of_node);
|
2015-12-10 11:00:19 +03:00
|
|
|
mtd = nand_to_mtd(&data->chip);
|
|
|
|
mtd->dev.parent = &pdev->dev;
|
2007-05-06 19:31:18 +04:00
|
|
|
|
2018-09-07 01:38:34 +03:00
|
|
|
data->chip.legacy.IO_ADDR_R = data->io_base;
|
|
|
|
data->chip.legacy.IO_ADDR_W = data->io_base;
|
2018-09-07 01:38:36 +03:00
|
|
|
data->chip.legacy.cmd_ctrl = pdata->ctrl.cmd_ctrl;
|
2018-09-07 01:38:37 +03:00
|
|
|
data->chip.legacy.dev_ready = pdata->ctrl.dev_ready;
|
2018-11-11 10:55:22 +03:00
|
|
|
data->chip.legacy.select_chip = pdata->ctrl.select_chip;
|
2018-09-07 01:38:35 +03:00
|
|
|
data->chip.legacy.write_buf = pdata->ctrl.write_buf;
|
|
|
|
data->chip.legacy.read_buf = pdata->ctrl.read_buf;
|
2018-09-07 01:38:41 +03:00
|
|
|
data->chip.legacy.chip_delay = pdata->chip.chip_delay;
|
2007-05-06 19:31:18 +04:00
|
|
|
data->chip.options |= pdata->chip.options;
|
2011-06-01 03:31:22 +04:00
|
|
|
data->chip.bbt_options |= pdata->chip.bbt_options;
|
2007-05-06 19:31:18 +04:00
|
|
|
|
|
|
|
data->chip.ecc.mode = NAND_ECC_SOFT;
|
2016-04-08 13:23:50 +03:00
|
|
|
data->chip.ecc.algo = NAND_ECC_HAMMING;
|
2007-05-06 19:31:18 +04:00
|
|
|
|
|
|
|
platform_set_drvdata(pdev, data);
|
|
|
|
|
2009-05-13 00:46:58 +04:00
|
|
|
/* Handle any platform specific setup */
|
|
|
|
if (pdata->ctrl.probe) {
|
2009-10-20 03:45:29 +04:00
|
|
|
err = pdata->ctrl.probe(pdev);
|
|
|
|
if (err)
|
2009-05-13 00:46:58 +04:00
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-03-31 05:57:33 +04:00
|
|
|
/* Scan to find existence of the device */
|
2018-09-06 15:05:14 +03:00
|
|
|
err = nand_scan(&data->chip, pdata->chip.nr_chips);
|
2016-11-04 13:42:57 +03:00
|
|
|
if (err)
|
2007-05-06 19:31:18 +04:00
|
|
|
goto out;
|
|
|
|
|
2015-05-19 02:15:24 +03:00
|
|
|
part_types = pdata->chip.part_probe_types;
|
2012-03-28 22:13:05 +04:00
|
|
|
|
2015-12-10 11:00:19 +03:00
|
|
|
err = mtd_device_parse_register(mtd, part_types, NULL,
|
mtd: do not use plain 0 as NULL
The first 3 arguments of 'mtd_device_parse_register()' are pointers,
but many callers pass '0' instead of 'NULL'. Fix this globally. Thanks
to coccinelle for making it easy to do with the following semantic patch:
@@
expression mtd, types, parser_data, parts, nr_parts;
@@
(
-mtd_device_parse_register(mtd, 0, parser_data, parts, nr_parts)
+mtd_device_parse_register(mtd, NULL, parser_data, parts, nr_parts)
|
-mtd_device_parse_register(mtd, types, 0, parts, nr_parts)
+mtd_device_parse_register(mtd, types, NULL, parts, nr_parts)
|
-mtd_device_parse_register(mtd, types, parser_data, 0, nr_parts)
+mtd_device_parse_register(mtd, types, parser_data, NULL, nr_parts)
)
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com>
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
2012-03-09 21:24:26 +04:00
|
|
|
pdata->chip.partitions,
|
|
|
|
pdata->chip.nr_partitions);
|
2007-05-06 19:31:18 +04:00
|
|
|
|
2009-10-20 03:45:29 +04:00
|
|
|
if (!err)
|
|
|
|
return err;
|
2007-05-06 19:31:18 +04:00
|
|
|
|
2018-09-06 15:05:15 +03:00
|
|
|
nand_release(&data->chip);
|
2007-05-06 19:31:18 +04:00
|
|
|
out:
|
2009-05-13 00:46:58 +04:00
|
|
|
if (pdata->ctrl.remove)
|
|
|
|
pdata->ctrl.remove(pdev);
|
2009-10-20 03:45:29 +04:00
|
|
|
return err;
|
2007-05-06 19:31:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove a NAND device.
|
|
|
|
*/
|
2012-11-19 22:26:04 +04:00
|
|
|
static int plat_nand_remove(struct platform_device *pdev)
|
2007-05-06 19:31:18 +04:00
|
|
|
{
|
|
|
|
struct plat_nand_data *data = platform_get_drvdata(pdev);
|
2013-07-30 12:18:33 +04:00
|
|
|
struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
|
2007-05-06 19:31:18 +04:00
|
|
|
|
2018-09-06 15:05:15 +03:00
|
|
|
nand_release(&data->chip);
|
2009-05-13 00:46:58 +04:00
|
|
|
if (pdata->ctrl.remove)
|
|
|
|
pdata->ctrl.remove(pdev);
|
2007-05-06 19:31:18 +04:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-04-30 21:30:46 +04:00
|
|
|
static const struct of_device_id plat_nand_match[] = {
|
|
|
|
{ .compatible = "gen_nand" },
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, plat_nand_match);
|
|
|
|
|
2007-05-06 19:31:18 +04:00
|
|
|
static struct platform_driver plat_nand_driver = {
|
2012-04-30 21:30:46 +04:00
|
|
|
.probe = plat_nand_probe,
|
2012-11-19 22:21:24 +04:00
|
|
|
.remove = plat_nand_remove,
|
2012-04-30 21:30:46 +04:00
|
|
|
.driver = {
|
|
|
|
.name = "gen_nand",
|
|
|
|
.of_match_table = plat_nand_match,
|
2007-05-06 19:31:18 +04:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2011-11-27 16:45:03 +04:00
|
|
|
module_platform_driver(plat_nand_driver);
|
2007-05-06 19:31:18 +04:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_AUTHOR("Vitaly Wool");
|
|
|
|
MODULE_DESCRIPTION("Simple generic NAND driver");
|
2008-04-19 00:44:27 +04:00
|
|
|
MODULE_ALIAS("platform:gen_nand");
|