[PATCH 2/2] mtd: make spinand driver usable without CONFIG_DM
Mikhail Kshevetskiy
mikhail.kshevetskiy at oktetlabs.ru
Mon Jun 22 17:54:31 CEST 2020
From: Mikhail Kshevetskiy <Mikhail.Kshevetskiy at oktetlabs.ru>
Here is an example of spinand driver initialization without CONFIG_DM
enabled:
void board_nand_init(void)
{
static struct spinand_device spinand;
static struct mtd_info mtd;
static struct spi_slave *slave;
int ret;
memset(&spinand, 0, sizeof(spinand));
memset(&mtd, 0, sizeof(mtd));
slave = spi_setup_slave(BUS, CS, MAX_HZ, MODE);
if (!slave) {
printf("SPI-NAND: Failed to set up SPI slave\n");
return;
}
slave->mode |= (SPI_TX_BYTE | SPI_RX_SLOW);
slave->max_read_size = SPI_MAX_READ_SIZE;
slave->max_write_size = SPI_MAX_WRITE_SIZE;
ret = spinand_probe_no_dm(&spinand, slave, &mtd);
if (!ret)
nand_register(0, &mtd);
}
Using of dual and quad wire transfer modes requires:
* dual/quad speed capable hardware (both controller and flash)
* physical presence of 4 data wires (quad mode only)
* spi controller driver MUST supports slave->mem_ops.exec_op() operations
(spi_xfer() interface will suits for single speed data transfer mode
only)
Signed-off-by: Mikhail Kshevetskiy <Mikhail.Kshevetskiy at oktetlabs.ru>
---
drivers/mtd/nand/spi/Kconfig | 2 +-
drivers/mtd/nand/spi/core.c | 46 ++++++++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/nand/spi/Kconfig b/drivers/mtd/nand/spi/Kconfig
index 0777dfdf0a..fd88e2cec9 100644
--- a/drivers/mtd/nand/spi/Kconfig
+++ b/drivers/mtd/nand/spi/Kconfig
@@ -1,6 +1,6 @@
menuconfig MTD_SPI_NAND
bool "SPI NAND device Support"
- depends on DM_MTD && DM_SPI
+ depends on (DM_MTD && DM_SPI) || (MTD && SPI)
select MTD_NAND_CORE
select SPI_MEM
help
diff --git a/drivers/mtd/nand/spi/core.c b/drivers/mtd/nand/spi/core.c
index e0ebd9c04b..a24e2e6677 100644
--- a/drivers/mtd/nand/spi/core.c
+++ b/drivers/mtd/nand/spi/core.c
@@ -170,14 +170,22 @@ int spinand_select_target(struct spinand_device *spinand, unsigned int target)
static int spinand_init_cfg_cache(struct spinand_device *spinand)
{
struct nand_device *nand = spinand_to_nand(spinand);
+#ifdef CONFIG_DM
struct udevice *dev = spinand->slave->dev;
+#endif
unsigned int target;
int ret;
+#ifdef CONFIG_DM
spinand->cfg_cache = devm_kzalloc(dev,
sizeof(*spinand->cfg_cache) *
nand->memorg.ntargets,
GFP_KERNEL);
+#else
+ spinand->cfg_cache = kzalloc(sizeof(*spinand->cfg_cache) *
+ nand->memorg.ntargets,
+ GFP_KERNEL);
+#endif
if (!spinand->cfg_cache)
return -ENOMEM;
@@ -1135,6 +1144,7 @@ static void spinand_cleanup(struct spinand_device *spinand)
kfree(spinand->scratchbuf);
}
+#ifdef CONFIG_DM
static int spinand_probe(struct udevice *dev)
{
struct spinand_device *spinand = dev_get_priv(dev);
@@ -1187,6 +1197,40 @@ err_spinand_cleanup:
return ret;
}
+#endif /* CONFIG_DM */
+
+#ifdef __UBOOT__
+int spinand_probe_no_dm(struct spinand_device *spinand,
+ struct spi_slave *slave,
+ struct mtd_info *mtd)
+{
+ struct nand_device *nand = spinand_to_nand(spinand);
+ int ret;
+
+ nand->mtd = mtd;
+ mtd->priv = nand;
+ mtd->name = malloc(20);
+ if (!mtd->name)
+ return -ENOMEM;
+ sprintf(mtd->name, "spi-nand%d", spi_nand_idx++);
+ spinand->slave = slave;
+
+ ret = spinand_init(spinand);
+ if (ret)
+ return ret;
+
+ ret = add_mtd_device(mtd);
+ if (ret)
+ goto err_spinand_cleanup;
+
+ return 0;
+
+err_spinand_cleanup:
+ spinand_cleanup(spinand);
+
+ return ret;
+}
+#endif /* __UBOOT__ */
#ifndef __UBOOT__
static int spinand_remove(struct udevice *slave)
@@ -1238,6 +1282,7 @@ MODULE_AUTHOR("Peter Pan<peterpandong at micron.com>");
MODULE_LICENSE("GPL v2");
#endif /* __UBOOT__ */
+#ifdef CONFIG_DM
static const struct udevice_id spinand_ids[] = {
{ .compatible = "spi-nand" },
{ /* sentinel */ },
@@ -1250,3 +1295,4 @@ U_BOOT_DRIVER(spinand) = {
.priv_auto_alloc_size = sizeof(struct spinand_device),
.probe = spinand_probe,
};
+#endif /* CONFIG_DM */
--
2.27.0
More information about the U-Boot
mailing list