From: Boris Brezillon <boris.brezillon@free-electrons.com>
To: Hauke Mehrtens <hauke@hauke-m.de>
Cc: richard@nod.at, dwmw2@infradead.org, computersforpeace@gmail.com,
linux-mtd@lists.infradead.org, john@phrozen.org
Subject: Re: [PATCH v2 1/8] MTD: xway: convert to normal platform driver
Date: Sun, 19 Jun 2016 13:32:11 +0200 [thread overview]
Message-ID: <20160619133211.04d4bd79@bbrezillon> (raw)
In-Reply-To: <1466277252-13867-2-git-send-email-hauke@hauke-m.de>
Hi Hauke,
On Sat, 18 Jun 2016 21:14:05 +0200
Hauke Mehrtens <hauke@hauke-m.de> wrote:
> Instead of hacking this into the plat_nand driver just make this a
> normal nand driver.
Thanks for taking care of that.
>
> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
> ---
> drivers/mtd/nand/Kconfig | 1 -
> drivers/mtd/nand/xway_nand.c | 119 ++++++++++++++++++++++++++++++-------------
> 2 files changed, 84 insertions(+), 36 deletions(-)
>
> diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
> index f05e0e9..d7de2c97 100644
> --- a/drivers/mtd/nand/Kconfig
> +++ b/drivers/mtd/nand/Kconfig
> @@ -539,7 +539,6 @@ config MTD_NAND_FSMC
> config MTD_NAND_XWAY
> tristate "Support for NAND on Lantiq XWAY SoC"
> depends on LANTIQ && SOC_TYPE_XWAY
> - select MTD_NAND_PLATFORM
> help
> Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached
> to the External Bus Unit (EBU).
> diff --git a/drivers/mtd/nand/xway_nand.c b/drivers/mtd/nand/xway_nand.c
> index 0cf0ac0..867a636 100644
> --- a/drivers/mtd/nand/xway_nand.c
> +++ b/drivers/mtd/nand/xway_nand.c
> @@ -4,6 +4,7 @@
> * by the Free Software Foundation.
> *
> * Copyright © 2012 John Crispin <blogic@openwrt.org>
> + * Copyright © 2016 Hauke Mehrtens <hauke@hauke-m.de>
> */
>
> #include <linux/mtd/nand.h>
> @@ -54,6 +55,10 @@
> #define NAND_CON_CSMUX (1 << 1)
> #define NAND_CON_NANDM 1
>
> +struct xway_nand_data {
> + struct nand_chip chip;
> +};
> +
> static void xway_reset_chip(struct nand_chip *chip)
> {
> unsigned long nandaddr = (unsigned long) chip->IO_ADDR_W;
> @@ -130,14 +135,50 @@ static unsigned char xway_read_byte(struct mtd_info *mtd)
> return ret;
> }
>
> +/*
> + * Probe for the NAND device.
> + */
> static int xway_nand_probe(struct platform_device *pdev)
> {
> - struct nand_chip *this = platform_get_drvdata(pdev);
> - unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
> - const __be32 *cs = of_get_property(pdev->dev.of_node,
> - "lantiq,cs", NULL);
> + struct xway_nand_data *data;
> + struct mtd_info *mtd;
> + struct resource *res;
> + int err = 0;
> + void __iomem *nandaddr;
> + const __be32 *cs;
> u32 cs_flag = 0;
>
> + /* Allocate memory for the device structure (and zero it) */
> + data = devm_kzalloc(&pdev->dev, sizeof(struct xway_nand_data),
> + GFP_KERNEL);
> + if (!data)
> + return -ENOMEM;
> +
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + nandaddr = devm_ioremap_resource(&pdev->dev, res);
> + if (IS_ERR(nandaddr))
> + return PTR_ERR(nandaddr);
> +
> + 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 = nandaddr;
> + data->chip.IO_ADDR_W = nandaddr;
> + data->chip.cmd_ctrl = xway_cmd_ctrl;
> + data->chip.dev_ready = xway_dev_ready;
> + data->chip.select_chip = xway_select_chip;
> + data->chip.read_byte = xway_read_byte;
> + data->chip.chip_delay = 30;
> +
> + data->chip.ecc.mode = NAND_ECC_SOFT;
> + data->chip.ecc.algo = NAND_ECC_HAMMING;
> +
> + platform_set_drvdata(pdev, data);
> + nand_set_controller_data(&data->chip, data);
> +
> + cs = of_get_property(pdev->dev.of_node, "lantiq,cs", NULL);
It may be a good time to switch to of_property_read_u32() (here or in a
separate patch).
> +
> /* load our CS from the DT. Either we find a valid 1 or default to 0 */
> if (cs && (*cs == 1))
> cs_flag = NAND_CON_IN_CS1 | NAND_CON_OUT_CS1;
> @@ -155,43 +196,51 @@ static int xway_nand_probe(struct platform_device *pdev)
> | cs_flag, EBU_NAND_CON);
>
> /* finish with a reset */
> - xway_reset_chip(this);
> -
> - return 0;
> -}
> + xway_reset_chip(&data->chip);
>
> -static struct platform_nand_data xway_nand_data = {
> - .chip = {
> - .nr_chips = 1,
> - .chip_delay = 30,
> - },
> - .ctrl = {
> - .probe = xway_nand_probe,
> - .cmd_ctrl = xway_cmd_ctrl,
> - .dev_ready = xway_dev_ready,
> - .select_chip = xway_select_chip,
> - .read_byte = xway_read_byte,
> + /* Scan to find existence of the device */
> + if (nand_scan(mtd, 1)) {
How about returning nand_scan() ret code if it's negative.
> + err = -ENXIO;
> + goto out;
This out label seems useless here, just return the err code directly.
> }
> -};
> +
> + err = mtd_device_register(mtd, NULL, 0);
> +
> + if (!err)
> + return 0;
> +
> + nand_release(mtd);
I'd prefer
if (err)
nand_release(mtd);
return err;
> +out:
> + return err;
> +}
>
> /*
> - * Try to find the node inside the DT. If it is available attach out
> - * platform_nand_data
> + * Remove a NAND device.
> */
> -static int __init xway_register_nand(void)
> +static int xway_nand_remove(struct platform_device *pdev)
> {
> - struct device_node *node;
> - struct platform_device *pdev;
> -
> - node = of_find_compatible_node(NULL, NULL, "lantiq,nand-xway");
> - if (!node)
> - return -ENOENT;
> - pdev = of_find_device_by_node(node);
> - if (!pdev)
> - return -EINVAL;
> - pdev->dev.platform_data = &xway_nand_data;
> - of_node_put(node);
> + struct xway_nand_data *data = platform_get_drvdata(pdev);
> +
> + nand_release(nand_to_mtd(&data->chip));
> +
> return 0;
> }
>
> -subsys_initcall(xway_register_nand);
> +static const struct of_device_id xway_nand_match[] = {
> + { .compatible = "lantiq,nand-xway" },
> + {},
> +};
> +MODULE_DEVICE_TABLE(of, xway_nand_match);
> +
> +static struct platform_driver xway_nand_driver = {
> + .probe = xway_nand_probe,
> + .remove = xway_nand_remove,
> + .driver = {
> + .name = "lantiq,nand-xway",
> + .of_match_table = xway_nand_match,
> + },
> +};
> +
> +module_platform_driver(xway_nand_driver);
> +
> +MODULE_LICENSE("GPL");
next prev parent reply other threads:[~2016-06-19 11:32 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-18 19:14 [PATCH v2 0/8] MTD: xway: fix driver Hauke Mehrtens
2016-06-18 19:14 ` [PATCH v2 1/8] MTD: xway: convert to normal platform driver Hauke Mehrtens
2016-06-19 11:32 ` Boris Brezillon [this message]
2016-06-19 11:58 ` Hauke Mehrtens
2016-06-18 19:14 ` [PATCH v2 2/8] MTD: xway: add some more documentation Hauke Mehrtens
2016-06-19 11:39 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 3/8] MTD: xway: the latched command should be persistent Hauke Mehrtens
2016-06-19 11:52 ` Boris Brezillon
2016-06-19 12:04 ` Hauke Mehrtens
2016-06-19 12:09 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 4/8] MTD: xway: remove endless loop Hauke Mehrtens
2016-06-19 12:14 ` Boris Brezillon
2016-06-19 12:32 ` Hauke Mehrtens
2016-06-19 12:57 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 5/8] MTD: xway: add missing write_buf and read_buf to nand driver Hauke Mehrtens
2016-06-19 12:38 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 6/8] MTD: xway: fix nand locking Hauke Mehrtens
2016-06-19 12:41 ` Boris Brezillon
2016-06-19 12:53 ` Richard Weinberger
2016-06-19 12:56 ` Hauke Mehrtens
2016-06-19 13:04 ` Boris Brezillon
2016-06-19 12:58 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 7/8] MTD: xway: extract read and write function Hauke Mehrtens
2016-06-19 12:42 ` Boris Brezillon
2016-06-18 19:14 ` [PATCH v2 8/8] MTD: xway: use global NAND_CMD_RESET define Hauke Mehrtens
2016-06-19 13:06 ` Boris Brezillon
2016-06-19 12:50 ` [PATCH v2 0/8] MTD: xway: fix driver Boris Brezillon
2016-06-19 13:13 ` Hauke Mehrtens
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160619133211.04d4bd79@bbrezillon \
--to=boris.brezillon@free-electrons.com \
--cc=computersforpeace@gmail.com \
--cc=dwmw2@infradead.org \
--cc=hauke@hauke-m.de \
--cc=john@phrozen.org \
--cc=linux-mtd@lists.infradead.org \
--cc=richard@nod.at \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.