mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-25 20:14:25 +08:00
d4092d76a4
We are planning to share more code between different NAND based devices (SPI NAND, OneNAND and raw NANDs), but before doing that we need to move the existing include/linux/mtd/nand.h file into include/linux/mtd/rawnand.h so we can later create a nand.h header containing all common structure and function prototypes. Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com> Signed-off-by: Peter Pan <peterpandong@micron.com> Acked-by: Vladimir Zapolskiy <vz@mleia.com> Acked-by: Alexander Sverdlin <alexander.sverdlin@gmail.com> Acked-by: Wenyou Yang <wenyou.yang@microchip.com> Acked-by: Krzysztof Kozlowski <krzk@kernel.org> Acked-by: Han Xu <han.xu@nxp.com> Acked-by: H Hartley Sweeten <hsweeten@visionengravers.com> Acked-by: Shawn Guo <shawnguo@kernel.org> Acked-by: Gregory CLEMENT <gregory.clement@free-electrons.com> Acked-by: Neil Armstrong <narmstrong@baylibre.com> Acked-by: Masahiro Yamada <yamada.masahiro@socionext.com> Acked-By: Harvey Hunt <harveyhuntnexus@gmail.com> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Krzysztof Halasa <khalasa@piap.pl>
145 lines
3.5 KiB
C
145 lines
3.5 KiB
C
/*
|
|
* Generic NAND driver
|
|
*
|
|
* Author: Vitaly Wool <vitalywool@gmail.com>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
*/
|
|
|
|
#include <linux/err.h>
|
|
#include <linux/io.h>
|
|
#include <linux/module.h>
|
|
#include <linux/platform_device.h>
|
|
#include <linux/slab.h>
|
|
#include <linux/mtd/mtd.h>
|
|
#include <linux/mtd/rawnand.h>
|
|
#include <linux/mtd/partitions.h>
|
|
|
|
struct plat_nand_data {
|
|
struct nand_chip chip;
|
|
void __iomem *io_base;
|
|
};
|
|
|
|
/*
|
|
* Probe for the NAND device.
|
|
*/
|
|
static int plat_nand_probe(struct platform_device *pdev)
|
|
{
|
|
struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
|
|
struct plat_nand_data *data;
|
|
struct mtd_info *mtd;
|
|
struct resource *res;
|
|
const char **part_types;
|
|
int err = 0;
|
|
|
|
if (!pdata) {
|
|
dev_err(&pdev->dev, "platform_nand_data is missing\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
if (pdata->chip.nr_chips < 1) {
|
|
dev_err(&pdev->dev, "invalid number of chips specified\n");
|
|
return -EINVAL;
|
|
}
|
|
|
|
/* Allocate memory for the device structure (and zero it) */
|
|
data = devm_kzalloc(&pdev->dev, sizeof(struct plat_nand_data),
|
|
GFP_KERNEL);
|
|
if (!data)
|
|
return -ENOMEM;
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
data->io_base = devm_ioremap_resource(&pdev->dev, res);
|
|
if (IS_ERR(data->io_base))
|
|
return PTR_ERR(data->io_base);
|
|
|
|
nand_set_flash_node(&data->chip, pdev->dev.of_node);
|
|
mtd = nand_to_mtd(&data->chip);
|
|
mtd->dev.parent = &pdev->dev;
|
|
|
|
data->chip.IO_ADDR_R = data->io_base;
|
|
data->chip.IO_ADDR_W = data->io_base;
|
|
data->chip.cmd_ctrl = pdata->ctrl.cmd_ctrl;
|
|
data->chip.dev_ready = pdata->ctrl.dev_ready;
|
|
data->chip.select_chip = pdata->ctrl.select_chip;
|
|
data->chip.write_buf = pdata->ctrl.write_buf;
|
|
data->chip.read_buf = pdata->ctrl.read_buf;
|
|
data->chip.read_byte = pdata->ctrl.read_byte;
|
|
data->chip.chip_delay = pdata->chip.chip_delay;
|
|
data->chip.options |= pdata->chip.options;
|
|
data->chip.bbt_options |= pdata->chip.bbt_options;
|
|
|
|
data->chip.ecc.hwctl = pdata->ctrl.hwcontrol;
|
|
data->chip.ecc.mode = NAND_ECC_SOFT;
|
|
data->chip.ecc.algo = NAND_ECC_HAMMING;
|
|
|
|
platform_set_drvdata(pdev, data);
|
|
|
|
/* Handle any platform specific setup */
|
|
if (pdata->ctrl.probe) {
|
|
err = pdata->ctrl.probe(pdev);
|
|
if (err)
|
|
goto out;
|
|
}
|
|
|
|
/* Scan to find existence of the device */
|
|
err = nand_scan(mtd, pdata->chip.nr_chips);
|
|
if (err)
|
|
goto out;
|
|
|
|
part_types = pdata->chip.part_probe_types;
|
|
|
|
err = mtd_device_parse_register(mtd, part_types, NULL,
|
|
pdata->chip.partitions,
|
|
pdata->chip.nr_partitions);
|
|
|
|
if (!err)
|
|
return err;
|
|
|
|
nand_release(mtd);
|
|
out:
|
|
if (pdata->ctrl.remove)
|
|
pdata->ctrl.remove(pdev);
|
|
return err;
|
|
}
|
|
|
|
/*
|
|
* Remove a NAND device.
|
|
*/
|
|
static int plat_nand_remove(struct platform_device *pdev)
|
|
{
|
|
struct plat_nand_data *data = platform_get_drvdata(pdev);
|
|
struct platform_nand_data *pdata = dev_get_platdata(&pdev->dev);
|
|
|
|
nand_release(nand_to_mtd(&data->chip));
|
|
if (pdata->ctrl.remove)
|
|
pdata->ctrl.remove(pdev);
|
|
|
|
return 0;
|
|
}
|
|
|
|
static const struct of_device_id plat_nand_match[] = {
|
|
{ .compatible = "gen_nand" },
|
|
{},
|
|
};
|
|
MODULE_DEVICE_TABLE(of, plat_nand_match);
|
|
|
|
static struct platform_driver plat_nand_driver = {
|
|
.probe = plat_nand_probe,
|
|
.remove = plat_nand_remove,
|
|
.driver = {
|
|
.name = "gen_nand",
|
|
.of_match_table = plat_nand_match,
|
|
},
|
|
};
|
|
|
|
module_platform_driver(plat_nand_driver);
|
|
|
|
MODULE_LICENSE("GPL");
|
|
MODULE_AUTHOR("Vitaly Wool");
|
|
MODULE_DESCRIPTION("Simple generic NAND driver");
|
|
MODULE_ALIAS("platform:gen_nand");
|