Skip to content

Commit f25723d

Browse files
vwaxbroonie
authored andcommitted
spi: Save current RX and TX DMA devices
Save the current RX and TX DMA devices to avoid having to duplicate the logic to pick them, since we'll need access to them in some more functions to fix a bug in the cache handling. Signed-off-by: Vincent Whitchurch <vincent.whitchurch@axis.com> Link: https://lore.kernel.org/r/20220927112117.77599-2-vincent.whitchurch@axis.com Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 309e985 commit f25723d

File tree

2 files changed

+8
-15
lines changed

2 files changed

+8
-15
lines changed

drivers/spi/spi.c

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,33 +1147,22 @@ static int __spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
11471147
}
11481148
}
11491149

1150+
ctlr->cur_rx_dma_dev = rx_dev;
1151+
ctlr->cur_tx_dma_dev = tx_dev;
11501152
ctlr->cur_msg_mapped = true;
11511153

11521154
return 0;
11531155
}
11541156

11551157
static int __spi_unmap_msg(struct spi_controller *ctlr, struct spi_message *msg)
11561158
{
1159+
struct device *rx_dev = ctlr->cur_rx_dma_dev;
1160+
struct device *tx_dev = ctlr->cur_tx_dma_dev;
11571161
struct spi_transfer *xfer;
1158-
struct device *tx_dev, *rx_dev;
11591162

11601163
if (!ctlr->cur_msg_mapped || !ctlr->can_dma)
11611164
return 0;
11621165

1163-
if (ctlr->dma_tx)
1164-
tx_dev = ctlr->dma_tx->device->dev;
1165-
else if (ctlr->dma_map_dev)
1166-
tx_dev = ctlr->dma_map_dev;
1167-
else
1168-
tx_dev = ctlr->dev.parent;
1169-
1170-
if (ctlr->dma_rx)
1171-
rx_dev = ctlr->dma_rx->device->dev;
1172-
else if (ctlr->dma_map_dev)
1173-
rx_dev = ctlr->dma_map_dev;
1174-
else
1175-
rx_dev = ctlr->dev.parent;
1176-
11771166
list_for_each_entry(xfer, &msg->transfers, transfer_list) {
11781167
if (!ctlr->can_dma(ctlr, msg->spi, xfer))
11791168
continue;

include/linux/spi/spi.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ extern struct spi_device *spi_new_ancillary_device(struct spi_device *spi, u8 ch
378378
* @cleanup: frees controller-specific state
379379
* @can_dma: determine whether this controller supports DMA
380380
* @dma_map_dev: device which can be used for DMA mapping
381+
* @cur_rx_dma_dev: device which is currently used for RX DMA mapping
382+
* @cur_tx_dma_dev: device which is currently used for TX DMA mapping
381383
* @queued: whether this controller is providing an internal message queue
382384
* @kworker: pointer to thread struct for message pump
383385
* @pump_messages: work struct for scheduling work to the message pump
@@ -609,6 +611,8 @@ struct spi_controller {
609611
struct spi_device *spi,
610612
struct spi_transfer *xfer);
611613
struct device *dma_map_dev;
614+
struct device *cur_rx_dma_dev;
615+
struct device *cur_tx_dma_dev;
612616

613617
/*
614618
* These hooks are for drivers that want to use the generic

0 commit comments

Comments
 (0)