spi: make spi-mem driver usable without CONFIG_DM_SPI, drop NODM variant
Subsystems (3)
PATCH 1/2 spi: make spi-mem driver usable without CONFIG_DM_SPI, drop NODM variant
From: Ivan Morozko <[email protected]>
There is no reason to have a separate and highly restricted version of spi-mem driver for NODM case, it's quite easily fix DM based driver version and use it for all cases.
--- drivers/spi/Makefile | 3 +- drivers/spi/spi-mem-nodm.c | 107 ------------------------------------- drivers/spi/spi-mem.c | 37 ++++++++----- include/spi.h | 1 + 4 files changed, 26 insertions(+), 122 deletions(-) delete mode 100644 drivers/spi/spi-mem-nodm.c
drivers/spi/Makefile +1 -2
@@ -8,12 +8,11 @@ ifdef CONFIG_DM_SPI obj-y += spi-uclass.o obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o obj-$(CONFIG_SOFT_SPI) += soft_spi.o -obj-$(CONFIG_SPI_MEM) += spi-mem.o obj-$(CONFIG_TI_QSPI) += ti_qspi.o else obj-y += spi.o -obj-$(CONFIG_SPI_MEM) += spi-mem-nodm.o endif +obj-$(CONFIG_SPI_MEM) += spi-mem.o obj-$(CONFIG_ALTERA_SPI) += altera_spi.o obj-$(CONFIG_ATH79_SPI) += ath79_spi.o
drivers/spi/spi-mem-nodm.c deleted +0 -107
107 lines not on this page · raw message
drivers/spi/spi-mem.c +25 -13
@@ -105,6 +105,19 @@ void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr,EXPORT_SYMBOL_GPL (spi_controller_dma_unmap_mem_op_data);#endif /* __UBOOT__ */ +static inline +struct spi_controller_mem_ops *spi_get_mem_ops (struct spi_slave *slave) +{ +#ifdef CONFIG_DM_SPI +struct udevice *bus = slave->dev->parent; +struct dm_spi_ops *ops =spi_get_ops (bus); + +return ops->mem_ops; +#else +return slave->mem_ops; +#endif +} +static int spi_check_buswidth_req (struct spi_slave *slave,u8 buswidth,bool tx) {u32 mode = slave->mode;
@@ -181,11 +193,10 @@ EXPORT_SYMBOL_GPL(spi_mem_default_supports_op);bool spi_mem_supports_op (struct spi_slave *slave,const struct spi_mem_op *op) { -struct udevice *bus = slave->dev->parent; -struct dm_spi_ops *ops =spi_get_ops (bus); +struct spi_controller_mem_ops *mem_ops =spi_get_mem_ops (slave); -if (ops->mem_ops && ops->mem_ops->supports_op) -return ops->mem_ops->supports_op (slave, op); +if (mem_ops && mem_ops->supports_op) +return mem_ops->supports_op (slave, op);return spi_mem_default_supports_op (slave, op); }
@@ -205,8 +216,7 @@ EXPORT_SYMBOL_GPL(spi_mem_supports_op);*/ int spi_mem_exec_op (struct spi_slave *slave,const struct spi_mem_op *op) { -struct udevice *bus = slave->dev->parent; -struct dm_spi_ops *ops =spi_get_ops (bus); +struct spi_controller_mem_ops *mem_ops =spi_get_mem_ops (slave);unsigned int pos =0 ;const u8 *tx_buf =NULL ;u8 *rx_buf =NULL ;
@@ -222,7 +232,7 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)if (ret <0 )return ret; -if (ops->mem_ops && ops->mem_ops->exec_op) { +if (mem_ops && mem_ops->exec_op) {#ifndef __UBOOT__/* * Flush the message queue before executing our SPI memory
@@ -243,7 +253,8 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)mutex_lock (&ctlr->bus_lock_mutex);mutex_lock (&ctlr->io_mutex);#endif - ret = ops->mem_ops->exec_op (slave, op); + + ret = mem_ops->exec_op (slave, op);#ifndef __UBOOT__mutex_unlock (&ctlr->io_mutex);
@@ -425,13 +436,12 @@ EXPORT_SYMBOL_GPL(spi_mem_exec_op);*/ int spi_mem_adjust_op_size (struct spi_slave *slave,struct spi_mem_op *op) { -struct udevice *bus = slave->dev->parent; -struct dm_spi_ops *ops =spi_get_ops (bus); +struct spi_controller_mem_ops *mem_ops =spi_get_mem_ops (slave); -if (ops->mem_ops && ops->mem_ops->adjust_op_size) -return ops->mem_ops->adjust_op_size (slave, op); +if (mem_ops && mem_ops->adjust_op_size) +return mem_ops->adjust_op_size (slave, op); -if (!ops->mem_ops || !ops->mem_ops->exec_op) { +if (!mem_ops || !mem_ops->exec_op) {unsigned int len; len = sizeof(op->cmd.opcode) + op->addr.nbytes +
@@ -450,6 +460,7 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)if (!op->data.nbytes)return -EINVAL ; + }return 0 ;
include/spi.h +1 -0
@@ -138,6 +138,7 @@ struct spi_slave {#else unsigned int bus;unsigned int cs; +struct spi_controller_mem_ops *mem_ops;#endif uint mode;unsigned int wordlen;
Signature · 1 line
2.27.0
PATCH 2/2 mtd: make spinand driver usable without CONFIG_DM
From: Mikhail Kshevetskiy <[email protected]>
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)
--- drivers/mtd/nand/spi/Kconfig | 2 +- drivers/mtd/nand/spi/core.c | 46 ++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-)
drivers/mtd/nand/spi/Kconfig +1 -1
@@ -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
drivers/mtd/nand/spi/core.c +45 -0
80 lines not on this page · raw message
Signature · 1 line
2.27.0
PATCH 2/2 mtd: make spinand driver usable without CONFIG_DM
Quoted 38 lines · Mikhail Kshevetskiy
From: Mikhail Kshevetskiy <[email protected]>
Here is an example of spinand driver initialization without
CONFIG_DMenabled: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 supportsslave->mem_ops.exec_op()operations (spi_xfer()interface will suits for single speed data transfer mode only)
Quoted 2 lines
Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Now it's time for dm only code, better not come up with nondm anymore as possible, please.
Jagan.
PATCH 2/2 mtd: make spinand driver usable without CONFIG_DM
Quoted 40 lines · On Sat, 11 Jul 2020 14:16:23 +0530 Jagan Teki <[email protected]>…
Quoted 38 lines · Mikhail Kshevetskiy
From: Mikhail Kshevetskiy <[email protected]>
Here is an example of spinand driver initialization without
CONFIG_DMenabled: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 supportsslave->mem_ops.exec_op()operations (spi_xfer()interface will suits for single speed data transfer mode only)
Quoted 7 lines
Quoted 2 lines
Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Now it's time for dm only code, better not come up with nondm anymore as possible, please.
Jagan.
I know about it. These patches were in the queue for upstreaming from the new year :-(
We are using 2010 and 2016 year based u-boot in our projects and due to some reasons it's not easy to switch it to DM build. This two patches helps us with backporting of spinand driver from upsteam u-boot. I think we are not an only users of old u-boot in the world, so it maybe helpful for other people as well.
Just ignore these two patches if you think that NODM era is completely over.
Mikhail.
PATCH 2/2 mtd: make spinand driver usable without CONFIG_DM
Quoted 52 lines · Mikhail Kshevetskiy
Quoted 40 lines · On Sat, 11 Jul 2020 14:16:23 +0530 Jagan Teki <[email protected]>…
Quoted 38 lines · Mikhail Kshevetskiy
From: Mikhail Kshevetskiy <[email protected]>
Here is an example of spinand driver initialization without
CONFIG_DMenabled: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 supportsslave->mem_ops.exec_op()operations (spi_xfer()interface will suits for single speed data transfer mode only)Quoted 7 lines
Quoted 2 lines
Signed-off-by Mikhail Kshevetskiy <[email protected]>---
Now it's time for dm only code, better not come up with nondm anymore as possible, please.
Jagan.
Quoted 7 lines
I know about it. These patches were in the queue for upstreaming from the new year :-(
We are using 2010 and 2016 year based u-boot in our projects and due to some reasons it's not easy to switch it to DM build. This two patches helps us with backporting of spinand driver from upsteam u-boot. I think we are not an only users of old u-boot in the world, so it maybe helpful for other people as well.
Yes, I agree with this point in terms of MTD code is a concern. However, supporting nondm at this point look traversing in the reverse direction as per as U-Boot development is a concern. I can guarantee that the community is always helping to improve code if you wish to use/migrate the mainline at any point.
Quoted 2 lines
Just ignore these two patches if you think that NODM era is completely over.
Thanks.
Jagan.