diff options
author | Geert Uytterhoeven <geert+renesas@glider.be> | 2017-12-13 14:05:10 -0500 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2017-12-14 06:46:02 -0500 |
commit | 7ff0b53c4051145d1cf992d2f60987e6447eed4f (patch) | |
tree | 810a911241204673b058aa8832bf44c6c0708c94 | |
parent | 5d8e614f6cf8850657edbd1859391a2ae45b4488 (diff) |
spi: sh-msiof: Avoid writing to registers from spi_master.setup()
The spi_master.setup() callback must not change configuration registers,
as that could corrupt I/O that is in progress for other SPI slaves.
The only exception is the configuration of the native chip select
polarity in SPI master mode, as a wrong chip select polarity will cause
havoc during all future transfers to any other SPI slave.
Hence stop writing to registers in sh_msiof_spi_setup(), unless it is
the first call for a controller using a native chip select, or unless
native chip select polarity has changed (note that you'll loose anyway
if I/O is in progress). Even then, only do what is strictly necessary,
instead of calling sh_msiof_spi_set_pin_regs().
Signed-off-by: Geert Uytterhoeven <geert+renesas@glider.be>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/spi/spi-sh-msiof.c | 35 |
1 files changed, 24 insertions, 11 deletions
diff --git a/drivers/spi/spi-sh-msiof.c b/drivers/spi/spi-sh-msiof.c index 81a9144f5442..2704abb11ea4 100644 --- a/drivers/spi/spi-sh-msiof.c +++ b/drivers/spi/spi-sh-msiof.c | |||
@@ -55,6 +55,8 @@ struct sh_msiof_spi_priv { | |||
55 | void *rx_dma_page; | 55 | void *rx_dma_page; |
56 | dma_addr_t tx_dma_addr; | 56 | dma_addr_t tx_dma_addr; |
57 | dma_addr_t rx_dma_addr; | 57 | dma_addr_t rx_dma_addr; |
58 | bool native_cs_inited; | ||
59 | bool native_cs_high; | ||
58 | bool slave_aborted; | 60 | bool slave_aborted; |
59 | }; | 61 | }; |
60 | 62 | ||
@@ -528,8 +530,7 @@ static int sh_msiof_spi_setup(struct spi_device *spi) | |||
528 | { | 530 | { |
529 | struct device_node *np = spi->master->dev.of_node; | 531 | struct device_node *np = spi->master->dev.of_node; |
530 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); | 532 | struct sh_msiof_spi_priv *p = spi_master_get_devdata(spi->master); |
531 | 533 | u32 clr, set, tmp; | |
532 | pm_runtime_get_sync(&p->pdev->dev); | ||
533 | 534 | ||
534 | if (!np) { | 535 | if (!np) { |
535 | /* | 536 | /* |
@@ -539,19 +540,31 @@ static int sh_msiof_spi_setup(struct spi_device *spi) | |||
539 | spi->cs_gpio = (uintptr_t)spi->controller_data; | 540 | spi->cs_gpio = (uintptr_t)spi->controller_data; |
540 | } | 541 | } |
541 | 542 | ||
542 | /* Configure pins before deasserting CS */ | 543 | if (spi->cs_gpio >= 0) { |
543 | sh_msiof_spi_set_pin_regs(p, !!(spi->mode & SPI_CPOL), | ||
544 | !!(spi->mode & SPI_CPHA), | ||
545 | !!(spi->mode & SPI_3WIRE), | ||
546 | !!(spi->mode & SPI_LSB_FIRST), | ||
547 | !!(spi->mode & SPI_CS_HIGH)); | ||
548 | |||
549 | if (spi->cs_gpio >= 0) | ||
550 | gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); | 544 | gpio_set_value(spi->cs_gpio, !(spi->mode & SPI_CS_HIGH)); |
545 | return 0; | ||
546 | } | ||
551 | 547 | ||
548 | if (spi_controller_is_slave(p->master)) | ||
549 | return 0; | ||
552 | 550 | ||
553 | pm_runtime_put(&p->pdev->dev); | 551 | if (p->native_cs_inited && |
552 | (p->native_cs_high == !!(spi->mode & SPI_CS_HIGH))) | ||
553 | return 0; | ||
554 | 554 | ||
555 | /* Configure native chip select mode/polarity early */ | ||
556 | clr = MDR1_SYNCMD_MASK; | ||
557 | set = MDR1_TRMD | TMDR1_PCON | MDR1_SYNCMD_SPI; | ||
558 | if (spi->mode & SPI_CS_HIGH) | ||
559 | clr |= BIT(MDR1_SYNCAC_SHIFT); | ||
560 | else | ||
561 | set |= BIT(MDR1_SYNCAC_SHIFT); | ||
562 | pm_runtime_get_sync(&p->pdev->dev); | ||
563 | tmp = sh_msiof_read(p, TMDR1) & ~clr; | ||
564 | sh_msiof_write(p, TMDR1, tmp | set); | ||
565 | pm_runtime_put(&p->pdev->dev); | ||
566 | p->native_cs_high = spi->mode & SPI_CS_HIGH; | ||
567 | p->native_cs_inited = true; | ||
555 | return 0; | 568 | return 0; |
556 | } | 569 | } |
557 | 570 | ||