Re: [PATCH] mtd: nand: Add support for M5441x NFC

Geert Uytterhoeven
2024-06-27T15:01:32Z

On Thu, Jun 20, 2024 at 6:25 PM Jean-Michel Hautbois
<jeanmichel.hautbois@yoseli.org> wrote:
> The vf610_nfc driver is also the one which should be used for the
> coldfire series. Sadly, these device don't support device-tree and so we
> need to do a few modifications:
> - Adapt the probe to use pdata if available
> - Add a new variant as there is a small part to adapt in
> vf610_nfc_select_target()
> - Add the corresponding missing register definitions
>
> Tested successfully on a 54418 custom board with a raw NAND:
> [ 2.640000] nand: device found, Manufacturer ID: 0x2c, Chip ID: 0xdc
> [ 2.650000] nand: Micron MT29F4G08ABADAWP
> [ 2.650000] nand: 512 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64
>
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@yoseli.org>

Thanks for your patch!

> --- a/drivers/mtd/nand/raw/vf610_nfc.c
> +++ b/drivers/mtd/nand/raw/vf610_nfc.c
> @@ -810,6 +840,7 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> struct vf610_nfc *nfc;
> struct mtd_info *mtd;
> struct nand_chip *chip;
> + struct nand_chip *pdata;
> struct device_node *child;

As reported by the robot, this is now unused.

> int err;
> int irq;
> @@ -820,30 +851,53 @@ static int vf610_nfc_probe(struct platform_device *pdev)
>
> nfc->dev = &pdev->dev;
> chip = &nfc->chip;
> + pdata = dev_get_platdata(&pdev->dev);
> + if (pdata)
> + *chip = *pdata;
> +
> mtd = nand_to_mtd(chip);
>
> mtd->owner = THIS_MODULE;
> mtd->dev.parent = nfc->dev;
> - mtd->name = DRV_NAME;
> +
> + /*
> + * We keep the MTD name unchanged to avoid breaking platforms
> + * where the MTD cmdline parser is used and the bootloader
> + * has not been updated to use the new naming scheme.
> + */
> + if (!nfc->dev->of_node)
> + mtd->name = "NAND";
> + else
> + mtd->name = DRV_NAME;
>
> irq = platform_get_irq(pdev, 0);
> if (irq < 0)
> return irq;
>
> nfc->regs = devm_platform_ioremap_resource(pdev, 0);
> - if (IS_ERR(nfc->regs))
> + if (IS_ERR(nfc->regs)) {
> + dev_err(nfc->dev, "Unable to map registers!\n");
> return PTR_ERR(nfc->regs);
> + }
>
> +#ifdef CONFIG_OF

Do you need all the #ifdeffery?

> nfc->clk = devm_clk_get_enabled(&pdev->dev, NULL);

Perhaps replace by devm_clk_get_optional_enabled() instead?

> if (IS_ERR(nfc->clk)) {
> dev_err(nfc->dev, "Unable to get and enable clock!\n");
> return PTR_ERR(nfc->clk);
> }
>
> - nfc->variant = (enum vf610_nfc_variant)device_get_match_data(&pdev->dev);
> - if (!nfc->variant)
> - return -ENODEV;
> + const void *data = device_get_match_data(&pdev->dev);
>
> + nfc->variant = (enum vf610_nfc_variant)data;
> + if (!nfc->variant) {
> + dev_err(nfc->dev, "No variant data found!\n");
> + return -ENODEV;
> + }
> +#else
> + nfc->variant = (enum vf610_nfc_variant)platform_get_device_id(pdev)->driver_data;
> +#endif
> +#ifdef CONFIG_OF
> for_each_available_child_of_node(nfc->dev->of_node, child) {

for_each_available_child_of_node_scoped(...), so the child variable
no longer needs to be declared at the top.

> if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) {
>
> @@ -862,6 +916,10 @@ static int vf610_nfc_probe(struct platform_device *pdev)
> dev_err(nfc->dev, "NAND chip sub-node missing!\n");
> return -ENODEV;
> }
> +#else
> + nfc->clk = NULL;
> + mtd->dev.parent = &pdev->dev;
> +#endif
>
> chip->options |= NAND_NO_SUBPAGE_WRITE;
>

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds