spi: dw: Zero DMA Tx and Rx configurations on stack
PATCH 1/8 spi: dw: Zero DMA Tx and Rx configurations on stack
Some DMA controller drivers do not tolerate non-zero values in the DMA configuration structures. Zero them to avoid issues with such DMA controller drivers. Even despite above this is a good practice per se.
--- drivers/spi/spi-dw-mid.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/spi/spi-dw-mid.c +2 -0
@@ -147,6 +147,7 @@ static struct dma_async_tx_descriptor *dw_spi_dma_prepare_tx(struct dw_spi *dws,if (!xfer->tx_buf)return NULL ; +memset (&txconf,0 ,sizeof (txconf)); txconf.direction =DMA_MEM_TO_DEV ; txconf.dst_addr = dws->dma_addr; txconf.dst_maxburst =16 ;
@@ -193,6 +194,7 @@ static struct dma_async_tx_descriptor *dw_spi_dma_prepare_rx(struct dw_spi *dws,if (!xfer->rx_buf)return NULL ; +memset (&rxconf,0 ,sizeof (rxconf)); rxconf.direction =DMA_DEV_TO_MEM ; rxconf.src_addr = dws->dma_addr; rxconf.src_maxburst =16 ;
Signature · 1 line
2.26.2
PATCH 2/8 spi: dw: Remove unused variable in CR0 configuring hooks
After enabling new IP support in the driver couple of variables were left unused compiler is not happy about:
.../spi-dw.c: In function ‘dw_spi_update_cr0’:.../spi-dw.c:264:17: warning: unused variable ‘dws’ [-Wunused-variable]
264 | struct dw_spi *dws = spi_controller_get_devdata(master);
| ^~~.../spi-dw.c: In function ‘dw_spi_update_cr0_v1_01a’:.../spi-dw.c:285:17: warning: unused variable ‘dws’ [-Wunused-variable]
285 | struct dw_spi *dws = spi_controller_get_devdata(master);
| ^~~
Drop them for good.
--- drivers/spi/spi-dw.c | 2 -- 1 file changed, 2 deletions(-)
drivers/spi/spi-dw.c +0 -2
@@ -261,7 +261,6 @@ static irqreturn_t dw_spi_irq(int irq, void *dev_id)u32 dw_spi_update_cr0 (struct spi_controller *master,struct spi_device *spi,struct spi_transfer *transfer) { -struct dw_spi *dws =spi_controller_get_devdata (master);struct chip_data *chip =spi_get_ctldata (spi);u32 cr0;
@@ -282,7 +281,6 @@ u32 dw_spi_update_cr0_v1_01a(struct spi_controller *master,struct spi_device *spi, struct spi_transfer *transfer) { - struct dw_spi *dws = spi_controller_get_devdata(master); struct chip_data *chip = spi_get_ctldata(spi);u32 cr0;
Signature · 1 line
2.26.2
PATCH 3/8 spi: dw: Move interrupt.h to spi-dw.h who is user of it
In reply to Andy ShevchenkoThe actual user of interrupt.h is spi-dw.h and not bus drivers. Move header there.
--- drivers/spi/spi-dw-mmio.c | 1 - drivers/spi/spi-dw-pci.c | 1 - drivers/spi/spi-dw.h | 1 + 3 files changed, 1 insertion(+), 2 deletions(-)
drivers/spi/spi-dw-mmio.c +0 -1
@@ -7,7 +7,6 @@#include <linux/clk.h> #include <linux/err.h> -#include <linux/interrupt.h> #include <linux/platform_device.h> #include <linux/pm_runtime.h> #include <linux/slab.h>
drivers/spi/spi-dw-pci.c +0 -1
@@ -5,7 +5,6 @@* Copyright (c) 2009, 2014 Intel Corporation. */ -#include <linux/interrupt.h> #include <linux/pci.h> #include <linux/pm_runtime.h> #include <linux/slab.h>
drivers/spi/spi-dw.h +1 -0
@@ -2,6 +2,7 @@#ifndef DW_SPI_HEADER_H #define DW_SPI_HEADER_H +#include <linux/interrupt.h> #include <linux/io.h> #include <linux/scatterlist.h>
Signature · 1 line
2.26.2
PATCH 4/8 spi: dw: Downgrade interrupt.h to irqreturn.h where appropriate
In reply to Andy Shevchenkospi-dw-mid.c along with spi-dw.h are direct users of irqreturn.h and nothing else is being used from interrupt.h. So, switch them to use the former instead of latter one.
While here, move the header under #ifdef CONFIG_SPI_DW_MID_DMA in spi-dw-mid.c.
--- drivers/spi/spi-dw-mid.c | 2 +- drivers/spi/spi-dw.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-dw-mid.c +1 -1
@@ -7,7 +7,6 @@#include <linux/dma-mapping.h> #include <linux/dmaengine.h> -#include <linux/interrupt.h> #include <linux/slab.h> #include <linux/spi/spi.h> #include <linux/types.h>
@@ -15,6 +14,7 @@#include "spi-dw.h" #ifdef CONFIG_SPI_DW_MID_DMA +#include <linux/irqreturn.h> #include <linux/pci.h> #include <linux/platform_data/dma-dw.h>
drivers/spi/spi-dw.h +1 -1
@@ -2,7 +2,7 @@#ifndef DW_SPI_HEADER_H #define DW_SPI_HEADER_H -#include <linux/interrupt.h> +#include <linux/irqreturn.h> #include <linux/io.h> #include <linux/scatterlist.h>
Signature · 1 line
2.26.2
PATCH 5/8 spi: dw: Move few headers under #ifdef CONFIG_SPI_DW_MID_DMA
In reply to Andy ShevchenkoThere is no user of few headers without CONFIG_SPI_DW_MID_DMA being set. Move them under condition.
While at it, remove unused slab.h there.
--- drivers/spi/spi-dw-mid.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/spi/spi-dw-mid.c +2 -3
@@ -5,15 +5,14 @@* Copyright (c) 2009, 2014 Intel Corporation. */ -#include <linux/dma-mapping.h> -#include <linux/dmaengine.h> -#include <linux/slab.h> #include <linux/spi/spi.h> #include <linux/types.h> #include "spi-dw.h" #ifdef CONFIG_SPI_DW_MID_DMA +#include <linux/dma-mapping.h> +#include <linux/dmaengine.h> #include <linux/irqreturn.h> #include <linux/pci.h> #include <linux/platform_data/dma-dw.h>
Signature · 1 line
2.26.2
PATCH 6/8 spi: dw: Add 'mfld' suffix to Intel Medfield related routines
In reply to Andy ShevchenkoIn order to prepare driver for the extension to support newer hardware, add 'mfld' suffix to some related functions.
While here, move DMA parameters assignment under existing #ifdef CONFIG_SPI_DW_MID_DMA.
There is no functional change intended.
--- drivers/spi/spi-dw-mid.c | 24 ++++++++++++++---------- drivers/spi/spi-dw-pci.c | 4 ++-- drivers/spi/spi-dw.h | 3 ++- 3 files changed, 18 insertions(+), 13 deletions(-)
drivers/spi/spi-dw-mid.c +14 -10
@@ -34,7 +34,7 @@ static bool mid_spi_dma_chan_filter(struct dma_chan *chan, void *param)return true; } -static int mid_spi_dma_init (struct dw_spi *dws) +static int mid_spi_dma_init_mfld (struct dw_spi *dws) {struct pci_dev *dma_dev;struct dw_dma_slave *tx = dws->dma_tx;
@@ -276,14 +276,23 @@ static void mid_spi_dma_stop(struct dw_spi *dws) } } -static const struct dw_spi_dma_ops mid_dma_ops = { - .dma_init = mid_spi_dma_init, +static const struct dw_spi_dma_ops mfld_dma_ops = { + .dma_init = mid_spi_dma_init_mfld, .dma_exit = mid_spi_dma_exit, .dma_setup = mid_spi_dma_setup, .can_dma = mid_spi_can_dma, .dma_transfer = mid_spi_dma_transfer, .dma_stop = mid_spi_dma_stop, }; + +static void dw_spi_mid_setup_dma_mfld (struct dw_spi *dws) +{ + dws->dma_tx = &mid_dma_tx; + dws->dma_rx = &mid_dma_rx; + dws->dma_ops = &mfld_dma_ops; +} +#else /* CONFIG_SPI_DW_MID_DMA */ +static inline void dw_spi_mid_setup_dma_mfld (struct dw_spi *dws) {}#endif /* Some specific info for SPI0 controller on Intel MID */
@@ -297,7 +306,7 @@ static const struct dw_spi_dma_ops mid_dma_ops = {#define CLK_SPI_CDIV_MASK 0x00000e00#define CLK_SPI_DISABLE_OFFSET 8 -int dw_spi_mid_init (struct dw_spi *dws) +int dw_spi_mid_init_mfld (struct dw_spi *dws) {void __iomem *clk_reg;u32 clk_cdiv;
@@ -314,14 +323,9 @@ int dw_spi_mid_init(struct dw_spi *dws)iounmap (clk_reg); -#ifdef CONFIG_SPI_DW_MID_DMA - dws->dma_tx = &mid_dma_tx; - dws->dma_rx = &mid_dma_rx; - dws->dma_ops = &mid_dma_ops; -#endif -/* Register hook to configure CTRLR0 */ dws->update_cr0 = dw_spi_update_cr0; +dw_spi_mid_setup_dma_mfld (dws);return 0 ; }
drivers/spi/spi-dw-pci.c +2 -2
@@ -23,13 +23,13 @@ struct spi_pci_desc { };static struct spi_pci_desc spi_pci_mid_desc_1 = { - .setup = dw_spi_mid_init, + .setup = dw_spi_mid_init_mfld, .num_cs =5 , .bus_num =0 , };static struct spi_pci_desc spi_pci_mid_desc_2 = { - .setup = dw_spi_mid_init, + .setup = dw_spi_mid_init_mfld, .num_cs =2 , .bus_num =1 , };
drivers/spi/spi-dw.h +2 -1
@@ -260,5 +260,6 @@ extern u32 dw_spi_update_cr0_v1_01a(struct spi_controller *master, struct spi_transfer *transfer);/* platform related setup */ -extern int dw_spi_mid_init (struct dw_spi *dws);/* Intel MID platforms */ +extern int dw_spi_mid_init_mfld (struct dw_spi *dws); +#endif /* DW_SPI_HEADER_H */
Signature · 1 line
2.26.2
PATCH 7/8 spi: dw: Propagate struct device pointer to ->dma_init() callback
In reply to Andy ShevchenkoIn some cases, one of which is coming soon, we would like to have a struct device pointer to request DMA channel. For this purpose propagate it to ->dma_init() callback in DMA ops.
--- drivers/spi/spi-dw-mid.c | 2 +- drivers/spi/spi-dw.c | 2 +- drivers/spi/spi-dw.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
drivers/spi/spi-dw-mid.c +1 -1
@@ -34,7 +34,7 @@ static bool mid_spi_dma_chan_filter(struct dma_chan *chan, void *param)return true; } -static int mid_spi_dma_init_mfld (struct dw_spi *dws) +static int mid_spi_dma_init_mfld (struct device *dev,struct dw_spi *dws) {struct pci_dev *dma_dev;struct dw_dma_slave *tx = dws->dma_tx;
drivers/spi/spi-dw.c +1 -1
@@ -506,7 +506,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)spi_hw_init (dev, dws);if (dws->dma_ops && dws->dma_ops->dma_init) { - ret = dws->dma_ops->dma_init (dws); + ret = dws->dma_ops->dma_init (dev, dws);if (ret) {dev_warn (dev,"DMA init failed\n" ); dws->dma_inited =0 ;
drivers/spi/spi-dw.h +1 -1
@@ -100,7 +100,7 @@ enum dw_ssi_type {struct dw_spi ;struct dw_spi_dma_ops { -int (*dma_init)(struct dw_spi *dws); +int (*dma_init)(struct device *dev,struct dw_spi *dws);void (*dma_exit)(struct dw_spi *dws);int (*dma_setup)(struct dw_spi *dws,struct spi_transfer *xfer); bool (*can_dma)(struct spi_controller *master, struct spi_device *spi,
Signature · 1 line
2.26.2
PATCH 8/8 spi: dw: Add Elkhart Lake PSE DMA support
In reply to Andy ShevchenkoFrom: Jarkko Nikula <[email protected]>
Elkhart Lake PSE SPI is capable to utilize PSE DMA engine which is described in ACPI. With help of acpi-dma module the support becomes a generic one.
Thus, add Elkhart Lake PSE DMA support and generic DMA hooks in SPI DesignWare driver.
--- drivers/spi/spi-dw-mid.c | 44 ++++++++++++++++++++++++++++++++++++++++ drivers/spi/spi-dw-pci.c | 1 + drivers/spi/spi-dw.h | 1 + 3 files changed, 46 insertions(+)
drivers/spi/spi-dw-mid.c +44 -0
@@ -75,6 +75,24 @@ static int mid_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)return -EBUSY ; } +static int mid_spi_dma_init_generic (struct device *dev,struct dw_spi *dws) +{ + dws->rxchan =dma_request_slave_channel (dev,"rx" ); +if (!dws->rxchan) +return -ENODEV ; + dws->master->dma_rx = dws->rxchan; + + dws->txchan =dma_request_slave_channel (dev,"tx" ); +if (!dws->txchan) { +dma_release_channel (dws->rxchan); +return -ENODEV ; + } + dws->master->dma_tx = dws->txchan; + + dws->dma_inited =1 ; +return 0 ; +} +static void mid_spi_dma_exit (struct dw_spi *dws) {if (!dws->dma_inited)
@@ -291,8 +309,25 @@ static void dw_spi_mid_setup_dma_mfld(struct dw_spi *dws) dws->dma_rx = &mid_dma_rx; dws->dma_ops = &mfld_dma_ops; } + +static const struct dw_spi_dma_ops generic_dma_ops = { + .dma_init = mid_spi_dma_init_generic, + .dma_exit = mid_spi_dma_exit, + .dma_setup = mid_spi_dma_setup, + .can_dma = mid_spi_can_dma, + .dma_transfer = mid_spi_dma_transfer, + .dma_stop = mid_spi_dma_stop, +}; + +static void dw_spi_mid_setup_dma_generic (struct dw_spi *dws) +{ + dws->dma_tx = &mid_dma_tx; + dws->dma_rx = &mid_dma_rx; + dws->dma_ops = &generic_dma_ops; +}#else /* CONFIG_SPI_DW_MID_DMA */ static inline void dw_spi_mid_setup_dma_mfld (struct dw_spi *dws) {} +static inline void dw_spi_mid_setup_dma_generic (struct dw_spi *dws) {}#endif /* Some specific info for SPI0 controller on Intel MID */
@@ -329,3 +364,12 @@ int dw_spi_mid_init_mfld(struct dw_spi *dws)dw_spi_mid_setup_dma_mfld (dws);return 0 ; } + +int dw_spi_mid_init_generic (struct dw_spi *dws) +{ +/* Register hook to configure CTRLR0 */ + dws->update_cr0 = dw_spi_update_cr0; + +dw_spi_mid_setup_dma_generic (dws); +return 0 ; +}
drivers/spi/spi-dw-pci.c +1 -0
@@ -35,6 +35,7 @@ static struct spi_pci_desc spi_pci_mid_desc_2 = { };static struct spi_pci_desc spi_pci_ehl_desc = { + .setup = dw_spi_mid_init_generic, .num_cs =2 , .bus_num =-1 , .max_freq =100000000 ,
drivers/spi/spi-dw.h +1 -0
@@ -261,5 +261,6 @@ extern u32 dw_spi_update_cr0_v1_01a(struct spi_controller *master,/* platform related setup */ extern int dw_spi_mid_init_mfld (struct dw_spi *dws); +extern int dw_spi_mid_init_generic (struct dw_spi *dws);#endif /* DW_SPI_HEADER_H */
Signature · 1 line
2.26.2
Quoted 8 lines · Andy Shevchenko
Some DMA controller drivers do not tolerate non-zero values in the DMA configuration structures. Zero them to avoid issues with such DMA controller drivers. Even despite above this is a good practice per se.
Fixes 7063c0d942a1 ("spi/dw_spi: add DMA support")Cc Feng Tang <[email protected]>Signed-off-by Andy Shevchenko <[email protected]>
Thanks,
Feng
Quoted 26 lines
--- drivers/spi/spi-dw-mid.c | 2 ++ 1 file changed, 2 insertions(+)drivers/spi/spi-dw-mid.c +2
-0@@ -147,6 +147,7 @@ static struct dma_async_tx_descriptor *dw_spi_dma_prepare_tx(struct dw_spi *dws,if (!xfer->tx_buf)return NULL ; +memset (&txconf,0 ,sizeof (txconf)); txconf.direction =DMA_MEM_TO_DEV ; txconf.dst_addr = dws->dma_addr; txconf.dst_maxburst =16 ;@@ -193,6 +194,7 @@ static struct dma_async_tx_descriptor *dw_spi_dma_prepare_rx(struct dw_spi *dws,if (!xfer->rx_buf)return NULL ; +memset (&rxconf,0 ,sizeof (rxconf)); rxconf.direction =DMA_DEV_TO_MEM ; rxconf.src_addr = dws->dma_addr; rxconf.src_maxburst =16 ;Signature · 1 line
2.26.2
Mark Brown
maintainerQuoted 11 lines · Andy Shevchenko
Some DMA controller drivers do not tolerate non-zero values in the DMA configuration structures. Zero them to avoid issues with such DMA controller drivers. Even despite above this is a good practice per se.
Fixes 7063c0d942a1 ("spi/dw_spi: add DMA support")Signed-off-by Andy Shevchenko <[email protected]>Acked-by Feng Tang <[email protected]>Cc Feng Tang <[email protected]>[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-5.8
Thanks!
[1/8] spi: dw: Zero DMA Tx and Rx configurations on stack
commit: 3cb97e223d277f84171cc4ccecab31e08b2ee7b5
[2/8] spi: dw: Remove unused variable in CR0 configuring hooks
commit: d4dd6c0a404a2ed3843b4b685d6990c4438a64c0
[3/8] spi: dw: Move interrupt.h to spi-dw.h who is user of it
commit: 0c2ce3fe4dd0b8f8dda07ea029f51ddf4c5190c2
[4/8] spi: dw: Downgrade interrupt.h to irqreturn.h where appropriate
commit: e62a15d97b0adede829ba5b4f1c8e28f230bd8e8
[5/8] spi: dw: Move few headers under #ifdef CONFIG_SPI_DW_MID_DMA
commit: e7940952644558e680033ae0450978445e53b423
[6/8] spi: dw: Add 'mfld' suffix to Intel Medfield related routines
commit: 37aa8aa68492deb56f9e4c8b2d00aa5d9dae7da2
[7/8] spi: dw: Propagate struct device pointer to ->dma_init() callback
commit: 6370ababce81911576d7c96663ae64fb84820c7b
[8/8] spi: dw: Add Elkhart Lake PSE DMA support
commit: 22d48ad7bfacda05900c3f7b43510fc4d40d5d53All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark