[PATCH v2 0/4] Misc fixes/cleanup

These are some miscelleneous fixes which can be applied separately from each other. I have grouped them in the same series, but they do not depend on one another.
Changes in v2: - Don't remove in-use headers - Split removal of EXPORT_SYMBOL_GPL into another patch
Sean Anderson (4): doc: Fix typo in FIT documentation spi: Remove uses of #ifndef __U_BOOT__ from spi-mem.c spi: Remove some instances of EXPORT_SYMBOL_GPL spi: Fix typo in header
doc/uImage.FIT/source_file_format.txt | 2 +- drivers/spi/spi-mem.c | 279 +------------------------- include/spi.h | 2 +- 3 files changed, 3 insertions(+), 280 deletions(-)

u_boot should be u-boot
Signed-off-by: Sean Anderson seanga2@gmail.com Reviewed-by: Bin Meng bmeng.cn@gmail.com ---
(no changes since v1)
doc/uImage.FIT/source_file_format.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/doc/uImage.FIT/source_file_format.txt b/doc/uImage.FIT/source_file_format.txt index 884a58456f..633f227c59 100644 --- a/doc/uImage.FIT/source_file_format.txt +++ b/doc/uImage.FIT/source_file_format.txt @@ -172,7 +172,7 @@ the '/images' node should have the following layout: - os : OS name, mandatory for types "kernel" and "ramdisk". Valid OS names are: "openbsd", "netbsd", "freebsd", "4_4bsd", "linux", "svr4", "esix", "solaris", "irix", "sco", "dell", "ncr", "lynxos", "vxworks", "psos", "qnx", - "u_boot", "rtems", "unity", "integrity". + "u-boot", "rtems", "unity", "integrity". - arch : Architecture name, mandatory for types: "standalone", "kernel", "firmware", "ramdisk" and "fdt". Valid architecture names are: "alpha", "arm", "i386", "ia64", "mips", "mips64", "ppc", "s390", "sh", "sparc",

Preprocessing out large sections of the file is confusing and makes it difficult to follow the control flow. Presumably these were initially added to make porting easier, but this code has not been synced with Linux since it was introduced two years ago.
Signed-off-by: Sean Anderson seanga2@gmail.com ---
Changes in v2: - Don't remove in-use headers - Split removal of EXPORT_SYMBOL_GPL into another patch
drivers/spi/spi-mem.c | 273 ------------------------------------------ 1 file changed, 273 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index c095ae9505..d7209837d0 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -6,13 +6,6 @@ * Author: Boris Brezillon boris.brezillon@bootlin.com */
-#ifndef __UBOOT__ -#include <log.h> -#include <dm/devres.h> -#include <linux/dmaengine.h> -#include <linux/pm_runtime.h> -#include "internals.h" -#else #include <common.h> #include <dm.h> #include <errno.h> @@ -21,94 +14,6 @@ #include <spi.h> #include <spi-mem.h> #include <dm/device_compat.h> -#endif - -#ifndef __UBOOT__ -/** - * spi_controller_dma_map_mem_op_data() - DMA-map the buffer attached to a - * memory operation - * @ctlr: the SPI controller requesting this dma_map() - * @op: the memory operation containing the buffer to map - * @sgt: a pointer to a non-initialized sg_table that will be filled by this - * function - * - * Some controllers might want to do DMA on the data buffer embedded in @op. - * This helper prepares everything for you and provides a ready-to-use - * sg_table. This function is not intended to be called from spi drivers. - * Only SPI controller drivers should use it. - * Note that the caller must ensure the memory region pointed by - * op->data.buf.{in,out} is DMA-able before calling this function. - * - * Return: 0 in case of success, a negative error code otherwise. - */ -int spi_controller_dma_map_mem_op_data(struct spi_controller *ctlr, - const struct spi_mem_op *op, - struct sg_table *sgt) -{ - struct device *dmadev; - - if (!op->data.nbytes) - return -EINVAL; - - if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx) - dmadev = ctlr->dma_tx->device->dev; - else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx) - dmadev = ctlr->dma_rx->device->dev; - else - dmadev = ctlr->dev.parent; - - if (!dmadev) - return -EINVAL; - - return spi_map_buf(ctlr, dmadev, sgt, op->data.buf.in, op->data.nbytes, - op->data.dir == SPI_MEM_DATA_IN ? - DMA_FROM_DEVICE : DMA_TO_DEVICE); -} -EXPORT_SYMBOL_GPL(spi_controller_dma_map_mem_op_data); - -/** - * spi_controller_dma_unmap_mem_op_data() - DMA-unmap the buffer attached to a - * memory operation - * @ctlr: the SPI controller requesting this dma_unmap() - * @op: the memory operation containing the buffer to unmap - * @sgt: a pointer to an sg_table previously initialized by - * spi_controller_dma_map_mem_op_data() - * - * Some controllers might want to do DMA on the data buffer embedded in @op. - * This helper prepares things so that the CPU can access the - * op->data.buf.{in,out} buffer again. - * - * This function is not intended to be called from SPI drivers. Only SPI - * controller drivers should use it. - * - * This function should be called after the DMA operation has finished and is - * only valid if the previous spi_controller_dma_map_mem_op_data() call - * returned 0. - * - * Return: 0 in case of success, a negative error code otherwise. - */ -void spi_controller_dma_unmap_mem_op_data(struct spi_controller *ctlr, - const struct spi_mem_op *op, - struct sg_table *sgt) -{ - struct device *dmadev; - - if (!op->data.nbytes) - return; - - if (op->data.dir == SPI_MEM_DATA_OUT && ctlr->dma_tx) - dmadev = ctlr->dma_tx->device->dev; - else if (op->data.dir == SPI_MEM_DATA_IN && ctlr->dma_rx) - dmadev = ctlr->dma_rx->device->dev; - else - dmadev = ctlr->dev.parent; - - spi_unmap_buf(ctlr, dmadev, sgt, - op->data.dir == SPI_MEM_DATA_IN ? - DMA_FROM_DEVICE : DMA_TO_DEVICE); -} -EXPORT_SYMBOL_GPL(spi_controller_dma_unmap_mem_op_data); -#endif /* __UBOOT__ */
static int spi_check_buswidth_req(struct spi_slave *slave, u8 buswidth, bool tx) { @@ -228,36 +133,8 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) return ret;
if (ops->mem_ops && ops->mem_ops->exec_op) { -#ifndef __UBOOT__ - /* - * Flush the message queue before executing our SPI memory - * operation to prevent preemption of regular SPI transfers. - */ - spi_flush_queue(ctlr); - - if (ctlr->auto_runtime_pm) { - ret = pm_runtime_get_sync(ctlr->dev.parent); - if (ret < 0) { - dev_err(&ctlr->dev, - "Failed to power device: %d\n", - ret); - return ret; - } - } - - mutex_lock(&ctlr->bus_lock_mutex); - mutex_lock(&ctlr->io_mutex); -#endif ret = ops->mem_ops->exec_op(slave, op);
-#ifndef __UBOOT__ - mutex_unlock(&ctlr->io_mutex); - mutex_unlock(&ctlr->bus_lock_mutex); - - if (ctlr->auto_runtime_pm) - pm_runtime_put(ctlr->dev.parent); -#endif - /* * Some controllers only optimize specific paths (typically the * read path) and expect the core to use the regular SPI @@ -269,80 +146,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op) } }
-#ifndef __UBOOT__ - tmpbufsize = sizeof(op->cmd.opcode) + op->addr.nbytes + - op->dummy.nbytes; - - /* - * Allocate a buffer to transmit the CMD, ADDR cycles with kmalloc() so - * we're guaranteed that this buffer is DMA-able, as required by the - * SPI layer. - */ - tmpbuf = kzalloc(tmpbufsize, GFP_KERNEL | GFP_DMA); - if (!tmpbuf) - return -ENOMEM; - - spi_message_init(&msg); - - tmpbuf[0] = op->cmd.opcode; - xfers[xferpos].tx_buf = tmpbuf; - xfers[xferpos].len = sizeof(op->cmd.opcode); - xfers[xferpos].tx_nbits = op->cmd.buswidth; - spi_message_add_tail(&xfers[xferpos], &msg); - xferpos++; - totalxferlen++; - - if (op->addr.nbytes) { - int i; - - for (i = 0; i < op->addr.nbytes; i++) - tmpbuf[i + 1] = op->addr.val >> - (8 * (op->addr.nbytes - i - 1)); - - xfers[xferpos].tx_buf = tmpbuf + 1; - xfers[xferpos].len = op->addr.nbytes; - xfers[xferpos].tx_nbits = op->addr.buswidth; - spi_message_add_tail(&xfers[xferpos], &msg); - xferpos++; - totalxferlen += op->addr.nbytes; - } - - if (op->dummy.nbytes) { - memset(tmpbuf + op->addr.nbytes + 1, 0xff, op->dummy.nbytes); - xfers[xferpos].tx_buf = tmpbuf + op->addr.nbytes + 1; - xfers[xferpos].len = op->dummy.nbytes; - xfers[xferpos].tx_nbits = op->dummy.buswidth; - spi_message_add_tail(&xfers[xferpos], &msg); - xferpos++; - totalxferlen += op->dummy.nbytes; - } - - if (op->data.nbytes) { - if (op->data.dir == SPI_MEM_DATA_IN) { - xfers[xferpos].rx_buf = op->data.buf.in; - xfers[xferpos].rx_nbits = op->data.buswidth; - } else { - xfers[xferpos].tx_buf = op->data.buf.out; - xfers[xferpos].tx_nbits = op->data.buswidth; - } - - xfers[xferpos].len = op->data.nbytes; - spi_message_add_tail(&xfers[xferpos], &msg); - xferpos++; - totalxferlen += op->data.nbytes; - } - - ret = spi_sync(slave, &msg); - - kfree(tmpbuf); - - if (ret) - return ret; - - if (msg.actual_length != totalxferlen) - return -EIO; -#else - if (op->data.nbytes) { if (op->data.dir == SPI_MEM_DATA_IN) rx_buf = op->data.buf.in; @@ -407,7 +210,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
if (ret < 0) return ret; -#endif /* __UBOOT__ */
return 0; } @@ -460,78 +262,3 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op) return 0; } EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size); - -#ifndef __UBOOT__ -static inline struct spi_mem_driver *to_spi_mem_drv(struct device_driver *drv) -{ - return container_of(drv, struct spi_mem_driver, spidrv.driver); -} - -static int spi_mem_probe(struct spi_device *spi) -{ - struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); - struct spi_mem *mem; - - mem = devm_kzalloc(&spi->dev, sizeof(*mem), GFP_KERNEL); - if (!mem) - return -ENOMEM; - - mem->spi = spi; - spi_set_drvdata(spi, mem); - - return memdrv->probe(mem); -} - -static int spi_mem_remove(struct spi_device *spi) -{ - struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); - struct spi_mem *mem = spi_get_drvdata(spi); - - if (memdrv->remove) - return memdrv->remove(mem); - - return 0; -} - -static void spi_mem_shutdown(struct spi_device *spi) -{ - struct spi_mem_driver *memdrv = to_spi_mem_drv(spi->dev.driver); - struct spi_mem *mem = spi_get_drvdata(spi); - - if (memdrv->shutdown) - memdrv->shutdown(mem); -} - -/** - * spi_mem_driver_register_with_owner() - Register a SPI memory driver - * @memdrv: the SPI memory driver to register - * @owner: the owner of this driver - * - * Registers a SPI memory driver. - * - * Return: 0 in case of success, a negative error core otherwise. - */ - -int spi_mem_driver_register_with_owner(struct spi_mem_driver *memdrv, - struct module *owner) -{ - memdrv->spidrv.probe = spi_mem_probe; - memdrv->spidrv.remove = spi_mem_remove; - memdrv->spidrv.shutdown = spi_mem_shutdown; - - return __spi_register_driver(owner, &memdrv->spidrv); -} -EXPORT_SYMBOL_GPL(spi_mem_driver_register_with_owner); - -/** - * spi_mem_driver_unregister_with_owner() - Unregister a SPI memory driver - * @memdrv: the SPI memory driver to unregister - * - * Unregisters a SPI memory driver. - */ -void spi_mem_driver_unregister(struct spi_mem_driver *memdrv) -{ - spi_unregister_driver(&memdrv->spidrv); -} -EXPORT_SYMBOL_GPL(spi_mem_driver_unregister); -#endif /* __UBOOT__ */

On Fri, Aug 7, 2020 at 10:43 PM Sean Anderson seanga2@gmail.com wrote:
Preprocessing out large sections of the file is confusing and makes it difficult to follow the control flow. Presumably these were initially added to make porting easier, but this code has not been synced with Linux since it was introduced two years ago.
Signed-off-by: Sean Anderson seanga2@gmail.com
Changes in v2:
- Don't remove in-use headers
- Split removal of EXPORT_SYMBOL_GPL into another patch
drivers/spi/spi-mem.c | 273 ------------------------------------------ 1 file changed, 273 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index c095ae9505..d7209837d0 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -6,13 +6,6 @@
- Author: Boris Brezillon boris.brezillon@bootlin.com
*/
-#ifndef __UBOOT__
I think these ifdef to track Linux change. Of course, I'm not fond of these changes, if Vignesh is fine I'll push.
Jagan.

On 10/23/20 2:26 PM, Jagan Teki wrote:
On Fri, Aug 7, 2020 at 10:43 PM Sean Anderson seanga2@gmail.com wrote:
Preprocessing out large sections of the file is confusing and makes it difficult to follow the control flow. Presumably these were initially added to make porting easier, but this code has not been synced with Linux since it was introduced two years ago.
Signed-off-by: Sean Anderson seanga2@gmail.com
Changes in v2:
- Don't remove in-use headers
- Split removal of EXPORT_SYMBOL_GPL into another patch
drivers/spi/spi-mem.c | 273 ------------------------------------------ 1 file changed, 273 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index c095ae9505..d7209837d0 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -6,13 +6,6 @@
- Author: Boris Brezillon boris.brezillon@bootlin.com
*/
-#ifndef __UBOOT__
I think these ifdef to track Linux change. Of course, I'm not fond of these changes, if Vignesh is fine I'll push.
I'm not particularly attached to this patch. However, it can be quite difficult to read this file because of how much code is ifdef'd out. Entire functions (spi_controller_dma_(un)map_mem_op_data, spi_mem_{probe,shutdown,remove}, etc.) are included but ifdef'd out. When reading this code, I often found myself reading some code only to realize that it wouldn't be compiled.
--Sean

Dear Sean,
In message 0897a97a-1630-b0ec-9e27-06d1aa940d47@gmail.com you wrote:
I think these ifdef to track Linux change. Of course, I'm not fond of these changes, if Vignesh is fine I'll push.
Indeed the #ifdef's have probably been used to keep the difference to the original Linux kernel source minimal.
Before they are removed, one should test how difficult it is to update code as is against current Linux mainline, maybe by rebasing against or cherry-pickin from there. I have no idea how much code has checnged in both driver versions since, and how difficult any such upgrade might be, but we should check it.
I'm not particularly attached to this patch. However, it can be quite difficult to read this file because of how much code is ifdef'd out. Entire functions (spi_controller_dma_(un)map_mem_op_data, spi_mem_{probe,shutdown,remove}, etc.) are included but ifdef'd out. When reading this code, I often found myself reading some code only to realize that it wouldn't be compiled.
If its just for reading / understanding the code, you can always run it through the unifdef tool ...
Best regards,
Wolfgang Denk

This evaluates to nothing in U-Boot, and this file is not synced with Linux.
Signed-off-by: Sean Anderson seanga2@gmail.com ---
Changes in v2: - New
drivers/spi/spi-mem.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-)
diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c index d7209837d0..29be9645eb 100644 --- a/drivers/spi/spi-mem.c +++ b/drivers/spi/spi-mem.c @@ -9,11 +9,11 @@ #include <common.h> #include <dm.h> #include <errno.h> +#include <log.h> #include <malloc.h> #include <spi.h> #include <spi.h> #include <spi-mem.h> -#include <dm/device_compat.h>
static int spi_check_buswidth_req(struct spi_slave *slave, u8 buswidth, bool tx) { @@ -71,7 +71,6 @@ bool spi_mem_default_supports_op(struct spi_slave *slave,
return true; } -EXPORT_SYMBOL_GPL(spi_mem_default_supports_op);
/** * spi_mem_supports_op() - Check if a memory device and the controller it is @@ -99,7 +98,6 @@ bool spi_mem_supports_op(struct spi_slave *slave,
return spi_mem_default_supports_op(slave, op); } -EXPORT_SYMBOL_GPL(spi_mem_supports_op);
/** * spi_mem_exec_op() - Execute a memory operation @@ -213,7 +211,6 @@ int spi_mem_exec_op(struct spi_slave *slave, const struct spi_mem_op *op)
return 0; } -EXPORT_SYMBOL_GPL(spi_mem_exec_op);
/** * spi_mem_adjust_op_size() - Adjust the data size of a SPI mem operation to @@ -261,4 +258,3 @@ int spi_mem_adjust_op_size(struct spi_slave *slave, struct spi_mem_op *op)
return 0; } -EXPORT_SYMBOL_GPL(spi_mem_adjust_op_size);

Spelling.
Signed-off-by: Sean Anderson seanga2@gmail.com ---
(no changes since v1)
include/spi.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/include/spi.h b/include/spi.h index ef8c1f6692..2d34e4af11 100644 --- a/include/spi.h +++ b/include/spi.h @@ -51,7 +51,7 @@ struct dm_spi_bus { * struct from a spi_slave, use dev_get_parent_platdata(dev) or * dev_get_parent_platdata(slave->dev). * - * This data is immuatable. Each time the device is probed, @max_hz and @mode + * This data is immutable. Each time the device is probed, @max_hz and @mode * will be copied to struct spi_slave. * * @cs: Chip select number (0..n-1)
participants (3)
-
Jagan Teki
-
Sean Anderson
-
Wolfgang Denk