[PATCH v2] nand: Add NAND driver for Mikrotik RB4xx series boards

Frans Klaver fransklaver at gmail.com
Fri May 8 03:14:40 PDT 2015


On Thu, May 7, 2015 at 2:31 PM, Bert Vermeulen <bert at biot.com> wrote:

> +static int rb4xx_nand_probe(struct platform_device *pdev)
> +{
> +       struct device *spi_dev;
> +       struct rb4xx_nand_info  *info;
> +       struct rb4xx_cpld_platform_data *pdata;
> +       int ret;
> +
> +       /*
> +        * NAND chip is behind the CPLD on SPI bus 0 CS 1. Allow this
> +        * to silently fail the second time around.
> +        */
> +       spi_register_driver(&rb4xx_cpld_driver);
> +
> +       /*
> +        * Getting a handle on the SPI device above will fail the first time,
> +        * but should succeed whenever that driver gets probed.
> +        */
> +       spi_dev = bus_find_device_by_name(&spi_bus_type, NULL, "spi0.1");
> +       if (!spi_dev)
> +               return -EPROBE_DEFER;
> +
> +       pdata = dev_get_platdata(spi_dev);
> +       if (!pdata)
> +               return -ENODATA;
> +
> +       info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL);
> +       if (!info)
> +               return -ENOMEM;
> +
> +       info->gpio_ale = devm_gpiod_get(&pdev->dev, "NAND ALE", GPIOD_OUT_LOW);
> +       if (IS_ERR(info->gpio_ale)) {
> +               dev_err(&pdev->dev, "unable to request gpio NAND ALE: %ld\n",
> +                       PTR_ERR(info->gpio_ale));
> +               return -ENOENT;
> +       }
> +
> +       info->gpio_cle = devm_gpiod_get(&pdev->dev, "NAND CLE", GPIOD_OUT_LOW);
> +       if (IS_ERR(info->gpio_cle)) {
> +               dev_err(&pdev->dev, "unable to request gpio NAND CLE: %ld\n",
> +                       PTR_ERR(info->gpio_cle));
> +               return -ENOENT;
> +       }
> +
> +       info->gpio_nce = devm_gpiod_get(&pdev->dev, "NAND NCE", GPIOD_OUT_LOW);
> +       if (IS_ERR(info->gpio_nce)) {
> +               dev_err(&pdev->dev, "unable to request gpio NAND NCE: %ld\n",
> +                       PTR_ERR(info->gpio_nce));
> +               return -ENOENT;
> +       }
> +
> +       /* Platform GPIO, has no device to manage it. */
> +       info->gpio_rdy = gpiod_get(NULL, "NAND RDY", GPIOD_IN);
> +       if (IS_ERR(info->gpio_rdy)) {
> +               dev_err(&pdev->dev, "unable to request gpio RDY: %ld\n",
> +                       PTR_ERR(info->gpio_rdy));
> +               return -ENOENT;
> +       }
> +
> +       info->spi_dev = container_of(spi_dev, struct spi_device, dev);
> +
> +       info->chip.priv = info;
> +       info->mtd.priv  = &info->chip;
> +       info->mtd.owner = THIS_MODULE;

If you should respin, could you add

info->mtd.dev.parent = &pdev->dev;

This will have a symlink to the parent device show up in sysfs. Seems
some people feel rather strongly about that.

Thanks,
Frans



More information about the linux-mtd mailing list