@@ -1118,6 +1118,21 @@ static irqreturn_t stm32h7_spi_irq_thread(int irq, void *dev_id)
1118
1118
return IRQ_HANDLED ;
1119
1119
}
1120
1120
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
+
1121
1136
/**
1122
1137
* stm32_spi_prepare_msg - set up the controller to transfer a single message
1123
1138
* @ctrl: controller interface
@@ -1163,18 +1178,6 @@ static int stm32_spi_prepare_msg(struct spi_controller *ctrl,
1163
1178
!!(spi_dev -> mode & SPI_LSB_FIRST ),
1164
1179
!!(spi_dev -> mode & SPI_CS_HIGH ));
1165
1180
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
-
1178
1181
spin_lock_irqsave (& spi -> lock , flags );
1179
1182
1180
1183
/* CPOL, CPHA and LSB FIRST bits have common register */
@@ -2180,6 +2183,7 @@ static int stm32_spi_probe(struct platform_device *pdev)
2180
2183
ctrl -> max_speed_hz = spi -> clk_rate / spi -> cfg -> baud_rate_div_min ;
2181
2184
ctrl -> min_speed_hz = spi -> clk_rate / spi -> cfg -> baud_rate_div_max ;
2182
2185
ctrl -> use_gpio_descriptors = true;
2186
+ ctrl -> optimize_message = stm32_spi_optimize_message ;
2183
2187
ctrl -> prepare_message = stm32_spi_prepare_msg ;
2184
2188
ctrl -> transfer_one = stm32_spi_transfer_one ;
2185
2189
ctrl -> unprepare_message = stm32_spi_unprepare_msg ;
0 commit comments