154
154
/* STM32H7_SPI_I2SCFGR bit fields */
155
155
#define STM32H7_SPI_I2SCFGR_I2SMOD BIT(0)
156
156
157
+ /* STM32MP25 SPI registers bit fields */
158
+ #define STM32MP25_SPI_HWCFGR1 0x3F0
159
+
160
+ /* STM32MP25_SPI_CR2 bit fields */
161
+ #define STM32MP25_SPI_TSIZE_MAX_LIMITED GENMASK(9, 0)
162
+
163
+ /* STM32MP25_SPI_HWCFGR1 */
164
+ #define STM32MP25_SPI_HWCFGR1_FULLCFG GENMASK(27, 24)
165
+ #define STM32MP25_SPI_HWCFGR1_FULLCFG_LIMITED 0x0
166
+ #define STM32MP25_SPI_HWCFGR1_FULLCFG_FULL 0x1
167
+ #define STM32MP25_SPI_HWCFGR1_DSCFG GENMASK(19, 16)
168
+ #define STM32MP25_SPI_HWCFGR1_DSCFG_16_B 0x0
169
+ #define STM32MP25_SPI_HWCFGR1_DSCFG_32_B 0x1
170
+
157
171
/* STM32H7 SPI Master Baud Rate min/max divisor */
158
172
#define STM32H7_SPI_MBR_DIV_MIN (2 << STM32H7_SPI_CFG1_MBR_MIN)
159
173
#define STM32H7_SPI_MBR_DIV_MAX (2 << STM32H7_SPI_CFG1_MBR_MAX)
@@ -207,6 +221,7 @@ struct stm32_spi_reg {
207
221
* @br: baud rate register and bitfields
208
222
* @rx: SPI RX data register
209
223
* @tx: SPI TX data register
224
+ * @fullcfg: SPI full or limited feature set register
210
225
*/
211
226
struct stm32_spi_regspec {
212
227
const struct stm32_spi_reg en ;
@@ -219,6 +234,7 @@ struct stm32_spi_regspec {
219
234
const struct stm32_spi_reg br ;
220
235
const struct stm32_spi_reg rx ;
221
236
const struct stm32_spi_reg tx ;
237
+ const struct stm32_spi_reg fullcfg ;
222
238
};
223
239
224
240
struct stm32_spi ;
@@ -250,6 +266,7 @@ struct stm32_spi;
250
266
* @has_fifo: boolean to know if fifo is used for driver
251
267
* @has_device_mode: is this compatible capable to switch on device mode
252
268
* @flags: compatible specific SPI controller flags used at registration time
269
+ * @prevent_dma_burst: boolean to indicate to prevent DMA burst
253
270
*/
254
271
struct stm32_spi_cfg {
255
272
const struct stm32_spi_regspec * regs ;
@@ -274,6 +291,7 @@ struct stm32_spi_cfg {
274
291
bool has_fifo ;
275
292
bool has_device_mode ;
276
293
u16 flags ;
294
+ bool prevent_dma_burst ;
277
295
};
278
296
279
297
/**
@@ -287,6 +305,8 @@ struct stm32_spi_cfg {
287
305
* @lock: prevent I/O concurrent access
288
306
* @irq: SPI controller interrupt line
289
307
* @fifo_size: size of the embedded fifo in bytes
308
+ * @t_size_max: maximum number of data of one transfer
309
+ * @feature_set: SPI full or limited feature set
290
310
* @cur_midi: host inter-data idleness in ns
291
311
* @cur_speed: speed configured in Hz
292
312
* @cur_half_period: time of a half bit in us
@@ -314,6 +334,10 @@ struct stm32_spi {
314
334
spinlock_t lock ; /* prevent I/O concurrent access */
315
335
int irq ;
316
336
unsigned int fifo_size ;
337
+ unsigned int t_size_max ;
338
+ unsigned int feature_set ;
339
+ #define STM32_SPI_FEATURE_LIMITED STM32MP25_SPI_HWCFGR1_FULLCFG_LIMITED /* 0x0 */
340
+ #define STM32_SPI_FEATURE_FULL STM32MP25_SPI_HWCFGR1_FULLCFG_FULL /* 0x1 */
317
341
318
342
unsigned int cur_midi ;
319
343
unsigned int cur_speed ;
@@ -371,6 +395,28 @@ static const struct stm32_spi_regspec stm32h7_spi_regspec = {
371
395
.tx = { STM32H7_SPI_TXDR },
372
396
};
373
397
398
+ static const struct stm32_spi_regspec stm32mp25_spi_regspec = {
399
+ /* SPI data transfer is enabled but spi_ker_ck is idle.
400
+ * CFG1 and CFG2 registers are write protected when SPE is enabled.
401
+ */
402
+ .en = { STM32H7_SPI_CR1 , STM32H7_SPI_CR1_SPE },
403
+
404
+ .dma_rx_en = { STM32H7_SPI_CFG1 , STM32H7_SPI_CFG1_RXDMAEN },
405
+ .dma_tx_en = { STM32H7_SPI_CFG1 , STM32H7_SPI_CFG1_TXDMAEN },
406
+
407
+ .cpol = { STM32H7_SPI_CFG2 , STM32H7_SPI_CFG2_CPOL },
408
+ .cpha = { STM32H7_SPI_CFG2 , STM32H7_SPI_CFG2_CPHA },
409
+ .lsb_first = { STM32H7_SPI_CFG2 , STM32H7_SPI_CFG2_LSBFRST },
410
+ .cs_high = { STM32H7_SPI_CFG2 , STM32H7_SPI_CFG2_SSIOP },
411
+ .br = { STM32H7_SPI_CFG1 , STM32H7_SPI_CFG1_MBR ,
412
+ STM32H7_SPI_CFG1_MBR_SHIFT },
413
+
414
+ .rx = { STM32H7_SPI_RXDR },
415
+ .tx = { STM32H7_SPI_TXDR },
416
+
417
+ .fullcfg = { STM32MP25_SPI_HWCFGR1 , STM32MP25_SPI_HWCFGR1_FULLCFG },
418
+ };
419
+
374
420
static inline void stm32_spi_set_bits (struct stm32_spi * spi ,
375
421
u32 offset , u32 bits )
376
422
{
@@ -457,6 +503,28 @@ static int stm32h7_spi_get_bpw_mask(struct stm32_spi *spi)
457
503
return SPI_BPW_RANGE_MASK (4 , max_bpw );
458
504
}
459
505
506
+ /**
507
+ * stm32mp25_spi_get_bpw_mask - Return bits per word mask
508
+ * @spi: pointer to the spi controller data structure
509
+ */
510
+ static int stm32mp25_spi_get_bpw_mask (struct stm32_spi * spi )
511
+ {
512
+ u32 dscfg , max_bpw ;
513
+
514
+ if (spi -> feature_set == STM32_SPI_FEATURE_LIMITED ) {
515
+ dev_dbg (spi -> dev , "8-bit or 16-bit data frame supported\n" );
516
+ return SPI_BPW_MASK (8 ) | SPI_BPW_MASK (16 );
517
+ }
518
+
519
+ dscfg = FIELD_GET (STM32MP25_SPI_HWCFGR1_DSCFG ,
520
+ readl_relaxed (spi -> base + STM32MP25_SPI_HWCFGR1 ));
521
+ max_bpw = 16 ;
522
+ if (dscfg == STM32MP25_SPI_HWCFGR1_DSCFG_32_B )
523
+ max_bpw = 32 ;
524
+ dev_dbg (spi -> dev , "%d-bit maximum data frame\n" , max_bpw );
525
+ return SPI_BPW_RANGE_MASK (4 , max_bpw );
526
+ }
527
+
460
528
/**
461
529
* stm32_spi_prepare_mbr - Determine baud rate divisor value
462
530
* @spi: pointer to the spi controller data structure
@@ -1103,7 +1171,7 @@ static int stm32_spi_prepare_msg(struct spi_controller *ctrl,
1103
1171
int ret ;
1104
1172
1105
1173
ret = spi_split_transfers_maxwords (ctrl , msg ,
1106
- STM32H7_SPI_TSIZE_MAX ,
1174
+ spi -> t_size_max ,
1107
1175
GFP_KERNEL | GFP_DMA );
1108
1176
if (ret )
1109
1177
return ret ;
@@ -1168,7 +1236,7 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
1168
1236
{
1169
1237
enum dma_slave_buswidth buswidth ;
1170
1238
struct dma_slave_caps caps ;
1171
- u32 maxburst ;
1239
+ u32 maxburst = 1 ;
1172
1240
int ret ;
1173
1241
1174
1242
if (spi -> cur_bpw <= 8 )
@@ -1178,15 +1246,9 @@ static void stm32_spi_dma_config(struct stm32_spi *spi,
1178
1246
else
1179
1247
buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES ;
1180
1248
1181
- if (spi -> cfg -> has_fifo ) {
1182
- /* Valid for DMA Half or Full Fifo threshold */
1183
- if (spi -> cur_fthlv == 2 )
1184
- maxburst = 1 ;
1185
- else
1186
- maxburst = spi -> cur_fthlv ;
1187
- } else {
1188
- maxburst = 1 ;
1189
- }
1249
+ /* Valid for DMA Half or Full Fifo threshold */
1250
+ if (!spi -> cfg -> prevent_dma_burst && spi -> cfg -> has_fifo && spi -> cur_fthlv != 2 )
1251
+ maxburst = spi -> cur_fthlv ;
1190
1252
1191
1253
/* Get the DMA channel caps, and adjust maxburst if possible */
1192
1254
ret = dma_get_slave_caps (dma_chan , & caps );
@@ -1671,7 +1733,7 @@ static void stm32h7_spi_data_idleness(struct stm32_spi *spi, u32 len)
1671
1733
*/
1672
1734
static int stm32h7_spi_number_of_data (struct stm32_spi * spi , u32 nb_words )
1673
1735
{
1674
- if (nb_words <= STM32H7_SPI_TSIZE_MAX ) {
1736
+ if (nb_words <= spi -> t_size_max ) {
1675
1737
writel_relaxed (FIELD_PREP (STM32H7_SPI_CR2_TSIZE , nb_words ),
1676
1738
spi -> base + STM32H7_SPI_CR2 );
1677
1739
} else {
@@ -1954,7 +2016,37 @@ static const struct stm32_spi_cfg stm32h7_spi_cfg = {
1954
2016
.has_device_mode = true,
1955
2017
};
1956
2018
2019
+ /*
2020
+ * STM32MP2 is compatible with the STM32H7 except:
2021
+ * - enforce the DMA maxburst value to 1
2022
+ * - spi8 have limited feature set (TSIZE_MAX = 1024, BPW of 8 OR 16)
2023
+ */
2024
+ static const struct stm32_spi_cfg stm32mp25_spi_cfg = {
2025
+ .regs = & stm32mp25_spi_regspec ,
2026
+ .get_fifo_size = stm32h7_spi_get_fifo_size ,
2027
+ .get_bpw_mask = stm32mp25_spi_get_bpw_mask ,
2028
+ .disable = stm32h7_spi_disable ,
2029
+ .config = stm32h7_spi_config ,
2030
+ .set_bpw = stm32h7_spi_set_bpw ,
2031
+ .set_mode = stm32h7_spi_set_mode ,
2032
+ .set_data_idleness = stm32h7_spi_data_idleness ,
2033
+ .set_number_of_data = stm32h7_spi_number_of_data ,
2034
+ .transfer_one_dma_start = stm32h7_spi_transfer_one_dma_start ,
2035
+ .dma_rx_cb = stm32_spi_dma_rx_cb ,
2036
+ /*
2037
+ * dma_tx_cb is not necessary since in case of TX, dma is followed by
2038
+ * SPI access hence handling is performed within the SPI interrupt
2039
+ */
2040
+ .transfer_one_irq = stm32h7_spi_transfer_one_irq ,
2041
+ .irq_handler_thread = stm32h7_spi_irq_thread ,
2042
+ .baud_rate_div_min = STM32H7_SPI_MBR_DIV_MIN ,
2043
+ .baud_rate_div_max = STM32H7_SPI_MBR_DIV_MAX ,
2044
+ .has_fifo = true,
2045
+ .prevent_dma_burst = true,
2046
+ };
2047
+
1957
2048
static const struct of_device_id stm32_spi_of_match [] = {
2049
+ { .compatible = "st,stm32mp25-spi" , .data = (void * )& stm32mp25_spi_cfg },
1958
2050
{ .compatible = "st,stm32h7-spi" , .data = (void * )& stm32h7_spi_cfg },
1959
2051
{ .compatible = "st,stm32f4-spi" , .data = (void * )& stm32f4_spi_cfg },
1960
2052
{ .compatible = "st,stm32f7-spi" , .data = (void * )& stm32f7_spi_cfg },
@@ -2058,6 +2150,22 @@ static int stm32_spi_probe(struct platform_device *pdev)
2058
2150
if (spi -> cfg -> has_fifo )
2059
2151
spi -> fifo_size = spi -> cfg -> get_fifo_size (spi );
2060
2152
2153
+ spi -> feature_set = STM32_SPI_FEATURE_FULL ;
2154
+ if (spi -> cfg -> regs -> fullcfg .reg ) {
2155
+ spi -> feature_set =
2156
+ FIELD_GET (STM32MP25_SPI_HWCFGR1_FULLCFG ,
2157
+ readl_relaxed (spi -> base + spi -> cfg -> regs -> fullcfg .reg ));
2158
+
2159
+ dev_dbg (spi -> dev , "%s feature set\n" ,
2160
+ spi -> feature_set == STM32_SPI_FEATURE_FULL ? "full" : "limited" );
2161
+ }
2162
+
2163
+ /* Only for STM32H7 and after */
2164
+ spi -> t_size_max = spi -> feature_set == STM32_SPI_FEATURE_FULL ?
2165
+ STM32H7_SPI_TSIZE_MAX :
2166
+ STM32MP25_SPI_TSIZE_MAX_LIMITED ;
2167
+ dev_dbg (spi -> dev , "one message max size %d\n" , spi -> t_size_max );
2168
+
2061
2169
ret = spi -> cfg -> config (spi );
2062
2170
if (ret ) {
2063
2171
dev_err (& pdev -> dev , "controller configuration failed: %d\n" ,
0 commit comments