diff options
author | Martin Sperl <kernel@martin.sperl.org> | 2015-07-28 10:03:12 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2015-08-14 14:09:09 -0400 |
commit | ca861dd0c5e36c4a2cf454049a45a961c855290a (patch) | |
tree | 7d104d1dda6ecc317fac583e5491b7360530caca | |
parent | bc0195aad0daa2ad5b0d76cce22b167bc3435590 (diff) |
spi: bcm2835: set up spi-mode before asserting cs-gpio
When using reverse polarity for clock (spi-cpol) on a device
the clock line gets altered after chip-select has been asserted
resulting in an additional clock beat, which confuses hardware.
This did not show when using native-CS, as the same register
is used to control cs as well as polarity, so the changes came
into effect at the same time. Unfortunately this is not true
with gpio-cs.
To avoid this situation this patch moves the setup of polarity
(spi-cpol and spi-cpha) outside of the chip-select into
prepare_message, which is run prior to asserting chip-select.
Also fixes resetting 3-wire mode after use of rx-mode, so that
a 3-Wire sequence TX, RX, TX works as well (right now it runs
TX, RX, RX instead)
Reported-by: Noralf Tronnes <noralf@tronnes.org>
Signed-off-by: Martin Sperl <kernel@martin.sperl.org>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/spi/spi-bcm2835.c | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/drivers/spi/spi-bcm2835.c b/drivers/spi/spi-bcm2835.c index 59705ab23577..c9357bb393d3 100644 --- a/drivers/spi/spi-bcm2835.c +++ b/drivers/spi/spi-bcm2835.c | |||
@@ -553,13 +553,11 @@ static int bcm2835_spi_transfer_one(struct spi_master *master, | |||
553 | spi_used_hz = cdiv ? (clk_hz / cdiv) : (clk_hz / 65536); | 553 | spi_used_hz = cdiv ? (clk_hz / cdiv) : (clk_hz / 65536); |
554 | bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv); | 554 | bcm2835_wr(bs, BCM2835_SPI_CLK, cdiv); |
555 | 555 | ||
556 | /* handle all the modes */ | 556 | /* handle all the 3-wire mode */ |
557 | if ((spi->mode & SPI_3WIRE) && (tfr->rx_buf)) | 557 | if ((spi->mode & SPI_3WIRE) && (tfr->rx_buf)) |
558 | cs |= BCM2835_SPI_CS_REN; | 558 | cs |= BCM2835_SPI_CS_REN; |
559 | if (spi->mode & SPI_CPOL) | 559 | else |
560 | cs |= BCM2835_SPI_CS_CPOL; | 560 | cs &= ~BCM2835_SPI_CS_REN; |
561 | if (spi->mode & SPI_CPHA) | ||
562 | cs |= BCM2835_SPI_CS_CPHA; | ||
563 | 561 | ||
564 | /* for gpio_cs set dummy CS so that no HW-CS get changed | 562 | /* for gpio_cs set dummy CS so that no HW-CS get changed |
565 | * we can not run this in bcm2835_spi_set_cs, as it does | 563 | * we can not run this in bcm2835_spi_set_cs, as it does |
@@ -592,6 +590,25 @@ static int bcm2835_spi_transfer_one(struct spi_master *master, | |||
592 | return bcm2835_spi_transfer_one_irq(master, spi, tfr, cs); | 590 | return bcm2835_spi_transfer_one_irq(master, spi, tfr, cs); |
593 | } | 591 | } |
594 | 592 | ||
593 | static int bcm2835_spi_prepare_message(struct spi_master *master, | ||
594 | struct spi_message *msg) | ||
595 | { | ||
596 | struct spi_device *spi = msg->spi; | ||
597 | struct bcm2835_spi *bs = spi_master_get_devdata(master); | ||
598 | u32 cs = bcm2835_rd(bs, BCM2835_SPI_CS); | ||
599 | |||
600 | cs &= ~(BCM2835_SPI_CS_CPOL | BCM2835_SPI_CS_CPHA); | ||
601 | |||
602 | if (spi->mode & SPI_CPOL) | ||
603 | cs |= BCM2835_SPI_CS_CPOL; | ||
604 | if (spi->mode & SPI_CPHA) | ||
605 | cs |= BCM2835_SPI_CS_CPHA; | ||
606 | |||
607 | bcm2835_wr(bs, BCM2835_SPI_CS, cs); | ||
608 | |||
609 | return 0; | ||
610 | } | ||
611 | |||
595 | static void bcm2835_spi_handle_err(struct spi_master *master, | 612 | static void bcm2835_spi_handle_err(struct spi_master *master, |
596 | struct spi_message *msg) | 613 | struct spi_message *msg) |
597 | { | 614 | { |
@@ -739,6 +756,7 @@ static int bcm2835_spi_probe(struct platform_device *pdev) | |||
739 | master->set_cs = bcm2835_spi_set_cs; | 756 | master->set_cs = bcm2835_spi_set_cs; |
740 | master->transfer_one = bcm2835_spi_transfer_one; | 757 | master->transfer_one = bcm2835_spi_transfer_one; |
741 | master->handle_err = bcm2835_spi_handle_err; | 758 | master->handle_err = bcm2835_spi_handle_err; |
759 | master->prepare_message = bcm2835_spi_prepare_message; | ||
742 | master->dev.of_node = pdev->dev.of_node; | 760 | master->dev.of_node = pdev->dev.of_node; |
743 | 761 | ||
744 | bs = spi_master_get_devdata(master); | 762 | bs = spi_master_get_devdata(master); |