[PATCH v1 3/4] spinand: bind mtdblock
Heinrich Schuchardt
xypron.glpk at gmx.de
Tue Feb 27 14:23:20 CET 2024
On 27.02.24 11:04, Alexey Romanov wrote:
> Bind SPI-NAND driver to MTD block driver.
>
> Signed-off-by: Alexey Romanov <avromanov at salutedevices.com>
> ---
> drivers/mtd/nand/spi/core.c | 20 ++++++++++++++++++++
> 1 file changed, 20 insertions(+)
>
> diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
> index 2a3dbcfcb4..1d9cf66e4a 100644
> --- a/drivers/mtd/nand/spi/core.c
> +++ b/drivers/mtd/nand/spi/core.c
> @@ -36,6 +36,10 @@
> #include <linux/printk.h>
> #endif
>
> +struct spinand_plat {
> + struct mtd_info *mtd;
> +};
> +
> /* SPI NAND index visible in MTD names */
> static int spi_nand_idx;
>
> @@ -1174,12 +1178,22 @@ static void spinand_cleanup(struct spinand_device *spinand)
> kfree(spinand->scratchbuf);
> }
>
> +#if CONFIG_IS_ENABLED(BLK)
> +static int spinand_bind(struct udevice *dev)
> +{
> + struct spinand_plat *plat = dev_get_plat(dev);
> +
> + return mtd_bind(dev, &plat->mtd);
> +}
> +#endif
> +
> static int spinand_probe(struct udevice *dev)
> {
> struct spinand_device *spinand = dev_get_priv(dev);
> struct spi_slave *slave = dev_get_parent_priv(dev);
> struct mtd_info *mtd = dev_get_uclass_priv(dev);
> struct nand_device *nand = spinand_to_nand(spinand);
> + struct spinand_plat *plat = dev_get_plat(dev);
> int ret;
>
> #ifndef __UBOOT__
> @@ -1219,6 +1233,8 @@ static int spinand_probe(struct udevice *dev)
> if (ret)
> goto err_spinand_cleanup;
>
> + plat->mtd = mtd;
> +
> return 0;
>
> err_spinand_cleanup:
> @@ -1288,6 +1304,10 @@ U_BOOT_DRIVER(spinand) = {
> .of_match = spinand_ids,
> .priv_auto = sizeof(struct spinand_device),
> .probe = spinand_probe,
> +#if CONFIG_IS_ENABLED(BLK)
Please, have a look at doc/develop/designprinciples.rst:168:
* Avoid ``#ifdefs`` where possible
Please, use 'if CONFIG_IS_ENABLED(BLK)' in the bind function.
Best regards
Heinrich
> + .bind = spinand_bind,
> +#endif
> + .plat_auto = sizeof(struct spinand_plat),
> };
>
> void board_nand_init(void)
More information about the U-Boot
mailing list