hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/spi/spi-fsl-spi.c
....@@ -203,24 +203,6 @@
203203 return bits_per_word;
204204 }
205205
206
-static int mspi_apply_qe_mode_quirks(struct spi_mpc8xxx_cs *cs,
207
- struct spi_device *spi,
208
- int bits_per_word)
209
-{
210
- /* QE uses Little Endian for words > 8
211
- * so transform all words > 8 into 8 bits
212
- * Unfortnatly that doesn't work for LSB so
213
- * reject these for now */
214
- /* Note: 32 bits word, LSB works iff
215
- * tfcr/rfcr is set to CPMFCR_GBL */
216
- if (spi->mode & SPI_LSB_FIRST &&
217
- bits_per_word > 8)
218
- return -EINVAL;
219
- if (bits_per_word > 8)
220
- return 8; /* pretend its 8 bits */
221
- return bits_per_word;
222
-}
223
-
224206 static int fsl_spi_setup_transfer(struct spi_device *spi,
225207 struct spi_transfer *t)
226208 {
....@@ -248,9 +230,6 @@
248230 bits_per_word = mspi_apply_cpu_mode_quirks(cs, spi,
249231 mpc8xxx_spi,
250232 bits_per_word);
251
- else if (mpc8xxx_spi->flags & SPI_QE)
252
- bits_per_word = mspi_apply_qe_mode_quirks(cs, spi,
253
- bits_per_word);
254233
255234 if (bits_per_word < 0)
256235 return bits_per_word;
....@@ -368,13 +347,29 @@
368347 * In CPU mode, optimize large byte transfers to use larger
369348 * bits_per_word values to reduce number of interrupts taken.
370349 */
371
- if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) {
372
- list_for_each_entry(t, &m->transfers, transfer_list) {
350
+ list_for_each_entry(t, &m->transfers, transfer_list) {
351
+ if (!(mpc8xxx_spi->flags & SPI_CPM_MODE)) {
373352 if (t->len < 256 || t->bits_per_word != 8)
374353 continue;
375354 if ((t->len & 3) == 0)
376355 t->bits_per_word = 32;
377356 else if ((t->len & 1) == 0)
357
+ t->bits_per_word = 16;
358
+ } else {
359
+ /*
360
+ * CPM/QE uses Little Endian for words > 8
361
+ * so transform 16 and 32 bits words into 8 bits
362
+ * Unfortnatly that doesn't work for LSB so
363
+ * reject these for now
364
+ * Note: 32 bits word, LSB works iff
365
+ * tfcr/rfcr is set to CPMFCR_GBL
366
+ */
367
+ if (m->spi->mode & SPI_LSB_FIRST && t->bits_per_word > 8)
368
+ return -EINVAL;
369
+ if (t->bits_per_word == 16 || t->bits_per_word == 32)
370
+ t->bits_per_word = 8; /* pretend its 8 bits */
371
+ if (t->bits_per_word == 8 && t->len >= 256 &&
372
+ (mpc8xxx_spi->flags & SPI_CPM1))
378373 t->bits_per_word = 16;
379374 }
380375 }
....@@ -633,8 +628,14 @@
633628 if (mpc8xxx_spi->type == TYPE_GRLIB)
634629 fsl_spi_grlib_probe(dev);
635630
636
- master->bits_per_word_mask =
637
- (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32)) &
631
+ if (mpc8xxx_spi->flags & SPI_CPM_MODE)
632
+ master->bits_per_word_mask =
633
+ (SPI_BPW_RANGE_MASK(4, 8) | SPI_BPW_MASK(16) | SPI_BPW_MASK(32));
634
+ else
635
+ master->bits_per_word_mask =
636
+ (SPI_BPW_RANGE_MASK(4, 16) | SPI_BPW_MASK(32));
637
+
638
+ master->bits_per_word_mask &=
638639 SPI_BPW_RANGE_MASK(1, mpc8xxx_spi->max_bits_per_word);
639640
640641 if (mpc8xxx_spi->flags & SPI_QE_CPU_MODE)