Skip to content

Commit c2bcfe7

Browse files
dlechbroonie
authored andcommitted
spi: stm32: move splitting transfers to optimize_message
Since splitting transfers was moved to spi_optimize_message() in the core SPI code, we now need to use the optimize_message callback in the STM32 SPI driver to ensure that the operation is only performed once when spi_optimize_message() is used by peripheral drivers explicitly. Signed-off-by: David Lechner <[email protected]> Link: https://msgid.link/r/20240219-mainline-spi-precook-message-v2-3-4a762c6701b9@baylibre.com Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Mark Brown <[email protected]>
1 parent fab53fe commit c2bcfe7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

drivers/spi/spi-stm32.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1118,6 +1118,21 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
11181118
return IRQ_HANDLED;
11191119
}
11201120

1121+
static int stm32_spi_optimize_message(struct spi_message *msg)
1122+
{
1123+
struct spi_controller *ctrl = msg->spi->controller;
1124+
struct stm32_spi *spi = spi_controller_get_devdata(ctrl);
1125+
1126+
/* On STM32H7, messages should not exceed a maximum size set
1127+
* later via the set_number_of_data function. In order to
1128+
* ensure that, split large messages into several messages
1129+
*/
1130+
if (spi->cfg->set_number_of_data)
1131+
return spi_split_transfers_maxwords(ctrl, msg, spi->t_size_max);
1132+
1133+
return 0;
1134+
}
1135+
11211136
/**
11221137
* stm32_spi_prepare_msg - set up the controller to transfer a single message
11231138
* @ctrl: controller interface
@@ -1163,18 +1178,6 @@ static int stm32_spi_prepare_msg(struct spi_controller *ctrl,
11631178
!!(spi_dev->mode & SPI_LSB_FIRST),
11641179
!!(spi_dev->mode & SPI_CS_HIGH));
11651180

1166-
/* On STM32H7, messages should not exceed a maximum size setted
1167-
* afterward via the set_number_of_data function. In order to
1168-
* ensure that, split large messages into several messages
1169-
*/
1170-
if (spi->cfg->set_number_of_data) {
1171-
int ret;
1172-
1173-
ret = spi_split_transfers_maxwords(ctrl, msg, spi->t_size_max);
1174-
if (ret)
1175-
return ret;
1176-
}
1177-
11781181
spin_lock_irqsave(&spi->lock, flags);
11791182

11801183
/* CPOL, CPHA and LSB FIRST bits have common register */
@@ -2180,6 +2183,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
21802183
ctrl->max_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_min;
21812184
ctrl->min_speed_hz = spi->clk_rate / spi->cfg->baud_rate_div_max;
21822185
ctrl->use_gpio_descriptors = true;
2186+
ctrl->optimize_message = stm32_spi_optimize_message;
21832187
ctrl->prepare_message = stm32_spi_prepare_msg;
21842188
ctrl->transfer_one = stm32_spi_transfer_one;
21852189
ctrl->unprepare_message = stm32_spi_unprepare_msg;

0 commit comments

Comments
 (0)