Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

spi: orion: enable support for switching CS every transferred byte

Some SPI devices, require toggling the CS every transferred byte.
Enable such possibility in the spi-orion driver.

Note that in order to use it, in the driver of a secondary device
attached to this controller, the SPI bus 'mode' field must be
updated with SPI_CS_WORD flag before calling spi_setup() routine.

In addition to that include a work-around - some devices, such as
certain models of SLIC (Subscriber Line Interface Card),
may require extra delay after CS toggling, so add a minimal
timing relaxation in relevant places.

Signed-off-by: Marcin Wojtas <mw@semihalf.com>
Signed-off-by: Konstantin Porotchkin <kostap@marvell.com>
Link: https://lore.kernel.org/r/20201223103827.29721-3-kostap@marvell.com
Signed-off-by: Mark Brown <broonie@kernel.org>

authored by

Marcin Wojtas and committed by
Mark Brown
22a6d41c e2be7031

+28 -4
+28 -4
drivers/spi/spi-orion.c
··· 375 375 { 376 376 void __iomem *tx_reg, *rx_reg, *int_reg; 377 377 struct orion_spi *orion_spi; 378 + bool cs_single_byte; 379 + 380 + cs_single_byte = spi->mode & SPI_CS_WORD; 378 381 379 382 orion_spi = spi_master_get_devdata(spi->master); 383 + 384 + if (cs_single_byte) 385 + orion_spi_set_cs(spi, 0); 386 + 380 387 tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG); 381 388 rx_reg = spi_reg(orion_spi, ORION_SPI_DATA_IN_REG); 382 389 int_reg = spi_reg(orion_spi, ORION_SPI_INT_CAUSE_REG); ··· 397 390 writel(0, tx_reg); 398 391 399 392 if (orion_spi_wait_till_ready(orion_spi) < 0) { 393 + if (cs_single_byte) { 394 + orion_spi_set_cs(spi, 1); 395 + /* Satisfy some SLIC devices requirements */ 396 + udelay(4); 397 + } 400 398 dev_err(&spi->dev, "TXS timed out\n"); 401 399 return -1; 402 400 } 403 401 404 402 if (rx_buf && *rx_buf) 405 403 *(*rx_buf)++ = readl(rx_reg); 404 + 405 + if (cs_single_byte) { 406 + orion_spi_set_cs(spi, 1); 407 + /* Satisfy some SLIC devices requirements */ 408 + udelay(4); 409 + } 406 410 407 411 return 1; 408 412 } ··· 424 406 { 425 407 void __iomem *tx_reg, *rx_reg, *int_reg; 426 408 struct orion_spi *orion_spi; 409 + 410 + if (spi->mode & SPI_CS_WORD) { 411 + dev_err(&spi->dev, "SPI_CS_WORD is only supported for 8 bit words\n"); 412 + return -1; 413 + } 427 414 428 415 orion_spi = spi_master_get_devdata(spi->master); 429 416 tx_reg = spi_reg(orion_spi, ORION_SPI_DATA_OUT_REG); ··· 469 446 orion_spi = spi_master_get_devdata(spi->master); 470 447 471 448 /* 472 - * Use SPI direct write mode if base address is available. Otherwise 473 - * fall back to PIO mode for this transfer. 449 + * Use SPI direct write mode if base address is available 450 + * and SPI_CS_WORD flag is not set. 451 + * Otherwise fall back to PIO mode for this transfer. 474 452 */ 475 453 vaddr = orion_spi->child[cs].direct_access.vaddr; 476 454 477 - if (vaddr && xfer->tx_buf && word_len == 8) { 455 + if (vaddr && xfer->tx_buf && word_len == 8 && (spi->mode & SPI_CS_WORD) == 0) { 478 456 unsigned int cnt = count / 4; 479 457 unsigned int rem = count % 4; 480 458 ··· 660 636 } 661 637 662 638 /* we support all 4 SPI modes and LSB first option */ 663 - master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST; 639 + master->mode_bits = SPI_CPHA | SPI_CPOL | SPI_LSB_FIRST | SPI_CS_WORD; 664 640 master->set_cs = orion_spi_set_cs; 665 641 master->transfer_one = orion_spi_transfer_one; 666 642 master->num_chipselect = ORION_NUM_CHIPSELECTS;