spi: dw: Add deferred DMA-channels setup support
PATCH 1/1 spi: dw: Add deferred DMA-channels setup support
Currently if the source DMA device isn't ready to provide the channels capable of the SPI DMA transfers, the DW SSI controller will be registered with no DMA support. It isn't right since all what the driver needs to do is to postpone the probe procedure until the DMA device is ready. Let's fix that in the framework of the DWC SSI generic DMA implementation. First we need to use the dma_request_chan() method instead of the dma_request_slave_channel() function, because the later one is deprecated and most importantly doesn't return the failure cause but the NULL-pointer. Second we need to stop the DW SSI controller probe procedure if the -EPROBE_DEFER error is returned on the DMA initialization. The procedure will resume later when the channels are ready to be requested.
--- drivers/spi/spi-dw-core.c | 5 ++++- drivers/spi/spi-dw-dma.c | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-)
drivers/spi/spi-dw-core.c +4 -1
@@ -942,7 +942,9 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_init) { ret = dws->dma_ops->dma_init (dev, dws); -if (ret) { +if (ret == -EPROBE_DEFER ) { + goto err_free_irq; + }else if (ret) {dev_warn (dev,"DMA init failed\n" ); }else { master->can_dma = dws->dma_ops->can_dma;
@@ -963,6 +965,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_exit) dws->dma_ops->dma_exit (dws);dw_spi_enable_chip (dws,0 ); +err_free_irq:free_irq (dws->irq, master); err_free_master:spi_controller_put (master);
drivers/spi/spi-dw-dma.c +18 -7
@@ -139,15 +139,20 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)static int dw_spi_dma_init_generic (struct device *dev,struct dw_spi *dws) { - dws->rxchan =dma_request_slave_channel (dev,"rx" ); -if (!dws->rxchan) -return -ENODEV ; +int ret; - dws->txchan =dma_request_slave_channel (dev,"tx" ); -if (!dws->txchan) { -dma_release_channel (dws->rxchan); + dws->rxchan =dma_request_chan (dev,"rx" ); +if (IS_ERR (dws->rxchan)) { + ret =PTR_ERR (dws->rxchan); dws->rxchan =NULL ; -return -ENODEV ; + goto err_exit; + } + + dws->txchan =dma_request_chan (dev,"tx" ); +if (IS_ERR (dws->txchan)) { + ret =PTR_ERR (dws->txchan); + dws->txchan =NULL ; + goto free_rxchan; } dws->master->dma_rx = dws->rxchan;
@@ -160,6 +165,12 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws)dw_spi_dma_sg_burst_init (dws);return 0 ; + +free_rxchan: +dma_release_channel (dws->rxchan); + dws->rxchan =NULL ; +err_exit: +return ret; }static void dw_spi_dma_exit (struct dw_spi *dws)
Signature · 1 line
2.35.1
Quoted 11 lines · Serge Semin
Currently if the source DMA device isn't ready to provide the channels capable of the SPI DMA transfers, the DW SSI controller will be registered with no DMA support. It isn't right since all what the driver needs to do is to postpone the probe procedure until the DMA device is ready. Let's fix that in the framework of the DWC SSI generic DMA implementation. First we need to use the
dma_request_chan()method instead of thedma_request_slave_channel()function, because the later one is deprecated and most importantly doesn't return the failure cause but the NULL-pointer. Second we need to stop the DW SSI controller probe procedure if the -EPROBE_DEFER error is returned on the DMA initialization. The procedure will resume later when the channels are ready to be requested.
One nit-pick below
Quoted 42 lines
Signed-off-by Serge Semin <[email protected]>--- drivers/spi/spi-dw-core.c | 5 ++++- drivers/spi/spi-dw-dma.c | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-)drivers/spi/spi-dw-core.c +4
-1@@ -942,7 +942,9 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_init) { ret = dws->dma_ops->dma_init (dev, dws); -if (ret) { +if (ret == -EPROBE_DEFER ) { + goto err_free_irq; + }else if (ret) {dev_warn (dev,"DMA init failed\n" ); }else { master->can_dma = dws->dma_ops->can_dma;@@ -963,6 +965,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_exit) dws->dma_ops->dma_exit (dws);dw_spi_enable_chip (dws,0 ); +err_free_irq:free_irq (dws->irq, master); err_free_master:spi_controller_put (master);drivers/spi/spi-dw-dma.c +1
-3@@ -139,15 +139,20 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)static int dw_spi_dma_init_generic (struct device *dev,struct dw_spi *dws) { - dws->rxchan =dma_request_slave_channel (dev,"rx" ); -if (!dws->rxchan) -return -ENODEV ; +int ret;
drivers/spi/spi-dw-dma.c static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) · line 149
Quoted 10 lines
drivers/spi/spi-dw-dma.c +4
-4- dws->txchan =dma_request_slave_channel (dev,"tx" ); -if (!dws->txchan) { -dma_release_channel (dws->rxchan); + dws->rxchan =dma_request_chan (dev,"rx" ); +if (IS_ERR (dws->rxchan)) { + ret =PTR_ERR (dws->rxchan); dws->rxchan =NULL ; -return -ENODEV ; + goto err_exit;
This change doesn't bring anything...
Quoted 11 lines
drivers/spi/spi-dw-dma.c +7
-0+ } + + dws->txchan =dma_request_chan (dev,"tx" ); +if (IS_ERR (dws->txchan)) { + ret =PTR_ERR (dws->txchan); + dws->txchan =NULL ; + goto free_rxchan; }drivers/spi/spi-dw-dma.c +0
-0dws->master->dma_rx = dws->rxchan;
drivers/spi/spi-dw-dma.c static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) · line 173
Quoted 9 lines
drivers/spi/spi-dw-dma.c +5
-0@@ -160,6 +165,12 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws)dw_spi_dma_sg_burst_init (dws);return 0 ; + +free_rxchan: +dma_release_channel (dws->rxchan); + dws->rxchan =NULL ; +err_exit:
...and this too.
Quoted 7 lines
drivers/spi/spi-dw-dma.c +1
-0+return ret; }static void
dw_spi_dma_exit(struct dw_spi *dws)Signature · 1 line
2.35.1
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 14 lines · Andy Shevchenko
Quoted 11 lines · Serge Semin
Currently if the source DMA device isn't ready to provide the channels capable of the SPI DMA transfers, the DW SSI controller will be registered with no DMA support. It isn't right since all what the driver needs to do is to postpone the probe procedure until the DMA device is ready. Let's fix that in the framework of the DWC SSI generic DMA implementation. First we need to use the
dma_request_chan()method instead of thedma_request_slave_channel()function, because the later one is deprecated and most importantly doesn't return the failure cause but the NULL-pointer. Second we need to stop the DW SSI controller probe procedure if the -EPROBE_DEFER error is returned on the DMA initialization. The procedure will resume later when the channels are ready to be requested.
Quoted 2 lines
One nit-pick below
Reviewed-by Andy Shevchenko <[email protected]>
Thanks.
Quoted 51 lines
Quoted 50 lines
Signed-off-by Serge Semin <[email protected]>--- drivers/spi/spi-dw-core.c | 5 ++++- drivers/spi/spi-dw-dma.c | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-)drivers/spi/spi-dw-core.c +4
-1@@ -942,7 +942,9 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_init) { ret = dws->dma_ops->dma_init (dev, dws); -if (ret) { +if (ret == -EPROBE_DEFER ) { + goto err_free_irq; + }else if (ret) {dev_warn (dev,"DMA init failed\n" ); }else { master->can_dma = dws->dma_ops->can_dma;@@ -963,6 +965,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_exit) dws->dma_ops->dma_exit (dws);dw_spi_enable_chip (dws,0 ); +err_free_irq:free_irq (dws->irq, master); err_free_master:spi_controller_put (master);drivers/spi/spi-dw-dma.c +4
-6@@ -139,15 +139,20 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)static int dw_spi_dma_init_generic (struct device *dev,struct dw_spi *dws) { - dws->rxchan =dma_request_slave_channel (dev,"rx" ); -if (!dws->rxchan) -return -ENODEV ; +int ret; - dws->txchan =dma_request_slave_channel (dev,"tx" ); -if (!dws->txchan) { -dma_release_channel (dws->rxchan); + dws->rxchan =dma_request_chan (dev,"rx" ); +if (IS_ERR (dws->rxchan)) { + ret =PTR_ERR (dws->rxchan); dws->rxchan =NULL ;
Quoted 5 lines
drivers/spi/spi-dw-dma.c static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws) · line 148
Quoted 2 lines
drivers/spi/spi-dw-dma.c +1
-1-return -ENODEV ; + goto err_exit;This change doesn't bring anything...
Right, but it makes this method looking alike dw_spi_dma_init_mfld(). I even used the same label names. It makes the code a little bit easier to read.
Quoted 20 lines
Quoted 19 lines
drivers/spi/spi-dw-dma.c +11
-0+ } + + dws->txchan =dma_request_chan (dev,"tx" ); +if (IS_ERR (dws->txchan)) { + ret =PTR_ERR (dws->txchan); + dws->txchan =NULL ; + goto free_rxchan; } dws->master->dma_rx = dws->rxchan;@@ -160,6 +165,12 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws)dw_spi_dma_sg_burst_init (dws);return 0 ; + +free_rxchan: +dma_release_channel (dws->rxchan); + dws->rxchan =NULL ;
Quoted 4 lines
drivers/spi/spi-dw-dma.c static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws) · line 172
Quoted 1 line
drivers/spi/spi-dw-dma.c +1
-0+err_exit:...and this too.
ditto
-Sergey
Quoted 14 lines
Quoted 8 lines
drivers/spi/spi-dw-dma.c +1
-0+return ret; }static void dw_spi_dma_exit (struct dw_spi *dws)Signature · 1 line
2.35.1Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH RESEND v2 1/1 spi: dw: Add deferred DMA-channels setup support
In reply to Serge SeminCurrently if the source DMA device isn't ready to provide the channels capable of the SPI DMA transfers, the DW SSI controller will be registered with no DMA support. It isn't right since all what the driver needs to do is to postpone the probe procedure until the DMA device is ready. Let's fix that in the framework of the DWC SSI generic DMA implementation. First we need to use the dma_request_chan() method instead of the dma_request_slave_channel() function, because the later one is deprecated and most importantly doesn't return the failure cause but the NULL-pointer. Second we need to stop the DW SSI controller probe procedure if the -EPROBE_DEFER error is returned on the DMA initialization. The procedure will resume later when the channels are ready to be requested.
---
Changelog v2:
- Just resend.
- Rebase onto the kernel v5.19-rcX.
--- drivers/spi/spi-dw-core.c | 5 ++++- drivers/spi/spi-dw-dma.c | 25 ++++++++++++++++++------- 2 files changed, 22 insertions(+), 8 deletions(-)
drivers/spi/spi-dw-core.c +4 -1
@@ -942,7 +942,9 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_init) { ret = dws->dma_ops->dma_init (dev, dws); -if (ret) { +if (ret == -EPROBE_DEFER ) { + goto err_free_irq; + }else if (ret) {dev_warn (dev,"DMA init failed\n" ); }else { master->can_dma = dws->dma_ops->can_dma;
@@ -963,6 +965,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)if (dws->dma_ops && dws->dma_ops->dma_exit) dws->dma_ops->dma_exit (dws);dw_spi_enable_chip (dws,0 ); +err_free_irq:free_irq (dws->irq, master); err_free_master:spi_controller_put (master);
drivers/spi/spi-dw-dma.c +18 -7
@@ -139,15 +139,20 @@ static int dw_spi_dma_init_mfld(struct device *dev, struct dw_spi *dws)static int dw_spi_dma_init_generic (struct device *dev,struct dw_spi *dws) { - dws->rxchan =dma_request_slave_channel (dev,"rx" ); -if (!dws->rxchan) -return -ENODEV ; +int ret; - dws->txchan =dma_request_slave_channel (dev,"tx" ); -if (!dws->txchan) { -dma_release_channel (dws->rxchan); + dws->rxchan =dma_request_chan (dev,"rx" ); +if (IS_ERR (dws->rxchan)) { + ret =PTR_ERR (dws->rxchan); dws->rxchan =NULL ; -return -ENODEV ; + goto err_exit; + } + + dws->txchan =dma_request_chan (dev,"tx" ); +if (IS_ERR (dws->txchan)) { + ret =PTR_ERR (dws->txchan); + dws->txchan =NULL ; + goto free_rxchan; } dws->master->dma_rx = dws->rxchan;
@@ -160,6 +165,12 @@ static int dw_spi_dma_init_generic(struct device *dev, struct dw_spi *dws)dw_spi_dma_sg_burst_init (dws);return 0 ; + +free_rxchan: +dma_release_channel (dws->rxchan); + dws->rxchan =NULL ; +err_exit: +return ret; }static void dw_spi_dma_exit (struct dw_spi *dws)
Signature · 1 line
2.35.1
Mark Brown
maintainerQuoted 12 lines · Serge Semin
Currently if the source DMA device isn't ready to provide the channels capable of the SPI DMA transfers, the DW SSI controller will be registered with no DMA support. It isn't right since all what the driver needs to do is to postpone the probe procedure until the DMA device is ready. Let's fix that in the framework of the DWC SSI generic DMA implementation. First we need to use the
dma_request_chan()method instead of thedma_request_slave_channel()function, because the later one is deprecated and most importantly doesn't return the failure cause but the NULL-pointer. Second we need to stop the DW SSI controller probe procedure if the -EPROBE_DEFER error is returned on the DMA initialization. The procedure will resume later when the channels are ready to be requested.
Quoted 1 line
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next
Thanks!
[1/1] spi: dw: Add deferred DMA-channels setup support
commit: e95a1cd2cfe722dc8434db6de33958035853aa05
All 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