Skip to content

Commit 61367d0

Browse files
dillon-minbroonie
authored andcommitted
spi: stm32: Add 'SPI_SIMPLEX_RX', 'SPI_3WIRE_RX' support for stm32f4
in l3gd20 driver startup, there is a setup failed error return from stm32 spi driver " [ 2.687630] st-gyro-spi spi0.0: supply vdd not found, using dummy regulator [ 2.696869] st-gyro-spi spi0.0: supply vddio not found, using dummy regulator [ 2.706707] spi_stm32 40015000.spi: SPI transfer setup failed [ 2.713741] st-gyro-spi spi0.0: SPI transfer failed: -22 [ 2.721096] spi_master spi0: failed to transfer one message from queue [ 2.729268] iio iio:device0: failed to read Who-Am-I register. [ 2.737504] st-gyro-spi: probe of spi0.0 failed with error -22 " after debug into spi-stm32 driver, st-gyro-spi split two steps to read l3gd20 id first: send command to l3gd20 with read id command in tx_buf, rx_buf is null. second: read id with tx_buf is null, rx_buf not null. so, for second step, stm32 driver recongise this process as 'SPI_SIMPLE_RX' from stm32_spi_communication_type(), but there is no related process for this type in stm32f4_spi_set_mode(), then we get error from stm32_spi_transfer_one_setup(). we can use two method to fix this bug. 1, use stm32 spi's "In unidirectional receive-only mode (BIDIMODE=0 and RXONLY=1)". but as our code running in sdram, the read latency is too large to get so many receive overrun error in interrupts handler. 2, use stm32 spi's "In full-duplex (BIDIMODE=0 and RXONLY=0)", as tx_buf is null, so add flag 'SPI_MASTER_MUST_TX' to spi master. Change since V4: 1 remove dummy data sent out by stm32 spi driver 2 add flag 'SPI_MASTER_MUST_TX' to spi master Signed-off-by: dillon min <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent 8fede89 commit 61367d0

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

drivers/spi/spi-stm32.c

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,9 @@ static irqreturn_t stm32f4_spi_irq_event(int irq, void *dev_id)
811811
mask |= STM32F4_SPI_SR_TXE;
812812
}
813813

814-
if (!spi->cur_usedma && spi->cur_comm == SPI_FULL_DUPLEX) {
814+
if (!spi->cur_usedma && (spi->cur_comm == SPI_FULL_DUPLEX ||
815+
spi->cur_comm == SPI_SIMPLEX_RX ||
816+
spi->cur_comm == SPI_3WIRE_RX)) {
815817
/* TXE flag is set and is handled when RXNE flag occurs */
816818
sr &= ~STM32F4_SPI_SR_TXE;
817819
mask |= STM32F4_SPI_SR_RXNE | STM32F4_SPI_SR_OVR;
@@ -850,7 +852,7 @@ static irqreturn_t stm32f4_spi_irq_event(int irq, void *dev_id)
850852
stm32f4_spi_read_rx(spi);
851853
if (spi->rx_len == 0)
852854
end = true;
853-
else /* Load data for discontinuous mode */
855+
else if (spi->tx_buf)/* Load data for discontinuous mode */
854856
stm32f4_spi_write_tx(spi);
855857
}
856858

@@ -1151,7 +1153,9 @@ static int stm32f4_spi_transfer_one_irq(struct stm32_spi *spi)
11511153
/* Enable the interrupts relative to the current communication mode */
11521154
if (spi->cur_comm == SPI_SIMPLEX_TX || spi->cur_comm == SPI_3WIRE_TX) {
11531155
cr2 |= STM32F4_SPI_CR2_TXEIE;
1154-
} else if (spi->cur_comm == SPI_FULL_DUPLEX) {
1156+
} else if (spi->cur_comm == SPI_FULL_DUPLEX ||
1157+
spi->cur_comm == SPI_SIMPLEX_RX ||
1158+
spi->cur_comm == SPI_3WIRE_RX) {
11551159
/* In transmit-only mode, the OVR flag is set in the SR register
11561160
* since the received data are never read. Therefore set OVR
11571161
* interrupt only when rx buffer is available.
@@ -1462,10 +1466,16 @@ static int stm32f4_spi_set_mode(struct stm32_spi *spi, unsigned int comm_type)
14621466
stm32_spi_set_bits(spi, STM32F4_SPI_CR1,
14631467
STM32F4_SPI_CR1_BIDIMODE |
14641468
STM32F4_SPI_CR1_BIDIOE);
1465-
} else if (comm_type == SPI_FULL_DUPLEX) {
1469+
} else if (comm_type == SPI_FULL_DUPLEX ||
1470+
comm_type == SPI_SIMPLEX_RX) {
14661471
stm32_spi_clr_bits(spi, STM32F4_SPI_CR1,
14671472
STM32F4_SPI_CR1_BIDIMODE |
14681473
STM32F4_SPI_CR1_BIDIOE);
1474+
} else if (comm_type == SPI_3WIRE_RX) {
1475+
stm32_spi_set_bits(spi, STM32F4_SPI_CR1,
1476+
STM32F4_SPI_CR1_BIDIMODE);
1477+
stm32_spi_clr_bits(spi, STM32F4_SPI_CR1,
1478+
STM32F4_SPI_CR1_BIDIOE);
14691479
} else {
14701480
return -EINVAL;
14711481
}
@@ -1906,6 +1916,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
19061916
master->prepare_message = stm32_spi_prepare_msg;
19071917
master->transfer_one = stm32_spi_transfer_one;
19081918
master->unprepare_message = stm32_spi_unprepare_msg;
1919+
master->flags = SPI_MASTER_MUST_TX;
19091920

19101921
spi->dma_tx = dma_request_chan(spi->dev, "tx");
19111922
if (IS_ERR(spi->dma_tx)) {

0 commit comments

Comments
 (0)