Skip to content

Commit e9dd4ed

Browse files
Stephan Olbrichbroonie
authored andcommitted
spi: bcm2835aux: fix CPOL/CPHA setting
The auxiliary spi supports only CPHA=0 modes as the first bit is always output to the pin before the first clock cycle. In CPHA=1 modes the first clock edge outputs the second bit hence the slave can never read the first bit. Also the CPHA registers switch between clocking data in/out on rising/falling edge hence depend on the CPOL setting. Signed-off-by: Stephan Olbrich <stephanolbrich@gmx.de> Reviewed-by: Eric Anholt <eric@anholt.net> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent b4e2ade commit e9dd4ed

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

drivers/spi/spi-bcm2835aux.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@
6464
#define BCM2835_AUX_SPI_CNTL0_VAR_WIDTH 0x00004000
6565
#define BCM2835_AUX_SPI_CNTL0_DOUTHOLD 0x00003000
6666
#define BCM2835_AUX_SPI_CNTL0_ENABLE 0x00000800
67-
#define BCM2835_AUX_SPI_CNTL0_CPHA_IN 0x00000400
67+
#define BCM2835_AUX_SPI_CNTL0_IN_RISING 0x00000400
6868
#define BCM2835_AUX_SPI_CNTL0_CLEARFIFO 0x00000200
69-
#define BCM2835_AUX_SPI_CNTL0_CPHA_OUT 0x00000100
69+
#define BCM2835_AUX_SPI_CNTL0_OUT_RISING 0x00000100
7070
#define BCM2835_AUX_SPI_CNTL0_CPOL 0x00000080
7171
#define BCM2835_AUX_SPI_CNTL0_MSBF_OUT 0x00000040
7272
#define BCM2835_AUX_SPI_CNTL0_SHIFTLEN 0x0000003F
@@ -92,9 +92,6 @@
9292
#define BCM2835_AUX_SPI_POLLING_LIMIT_US 30
9393
#define BCM2835_AUX_SPI_POLLING_JIFFIES 2
9494

95-
#define BCM2835_AUX_SPI_MODE_BITS (SPI_CPOL | SPI_CPHA | SPI_CS_HIGH \
96-
| SPI_NO_CS)
97-
9895
struct bcm2835aux_spi {
9996
void __iomem *regs;
10097
struct clk *clk;
@@ -389,12 +386,12 @@ static int bcm2835aux_spi_prepare_message(struct spi_master *master,
389386
bs->cntl[1] = BCM2835_AUX_SPI_CNTL1_MSBF_IN;
390387

391388
/* handle all the modes */
392-
if (spi->mode & SPI_CPOL)
389+
if (spi->mode & SPI_CPOL) {
393390
bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPOL;
394-
if (spi->mode & SPI_CPHA)
395-
bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_CPHA_OUT |
396-
BCM2835_AUX_SPI_CNTL0_CPHA_IN;
397-
391+
bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_OUT_RISING;
392+
} else {
393+
bs->cntl[0] |= BCM2835_AUX_SPI_CNTL0_IN_RISING;
394+
}
398395
bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL1, bs->cntl[1]);
399396
bcm2835aux_wr(bs, BCM2835_AUX_SPI_CNTL0, bs->cntl[0]);
400397

@@ -434,7 +431,7 @@ static int bcm2835aux_spi_probe(struct platform_device *pdev)
434431
}
435432

436433
platform_set_drvdata(pdev, master);
437-
master->mode_bits = BCM2835_AUX_SPI_MODE_BITS;
434+
master->mode_bits = (SPI_CPOL | SPI_CS_HIGH | SPI_NO_CS);
438435
master->bits_per_word_mask = SPI_BPW_MASK(8);
439436
master->num_chipselect = -1;
440437
master->transfer_one = bcm2835aux_spi_transfer_one;

0 commit comments

Comments
 (0)