diff options
author | Florian Fainelli <florian@openwrt.org> | 2012-06-18 06:07:51 -0400 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2012-08-17 04:57:28 -0400 |
commit | 5a6704454a68ab6e27e4fc5b82818a8c5733bf29 (patch) | |
tree | 4b27c7f37bfe26985ff08ad09368e375cfe6dc89 | |
parent | c54de490a2e4e74164f747925ff05c00dfa153cd (diff) |
MIPS: BCM63xx: Fix SPI message control register handling for BCM6338/6348.
BCM6338 and BCM6348 have a message control register width of 8 bits, instead
of 16-bits like what the SPI driver assumes right now. Also the SPI message
type shift value of 14 is actually 6 for these SoCs.
This resulted in transmit FIFO corruption because we were writing 16-bits
to an 8-bits wide register, thus spanning on the first byte of the transmit
FIFO, which had already been filed in bcm63xx_spi_fill_txrx_fifo().
Fix this by passing the message control register width and message type
shift through platform data back to the SPI driver so that it can use
it properly.
Signed-off-by: Florian Fainelli <florian@openwrt.org>
Cc: linux-mips@linux-mips.org
Cc: grant.likely@secretlab.ca
Cc: spi-devel-general@lists.sourceforge.net
Cc: jonas.gorski@gmail.com
Patchwork: https://patchwork.linux-mips.org/patch/3983/
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/bcm63xx/dev-spi.c | 4 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h | 2 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h | 13 | ||||
-rw-r--r-- | drivers/spi/spi-bcm63xx.c | 31 |
4 files changed, 42 insertions, 8 deletions
diff --git a/arch/mips/bcm63xx/dev-spi.c b/arch/mips/bcm63xx/dev-spi.c index e39f73048d4f..f1c9c3e2f678 100644 --- a/arch/mips/bcm63xx/dev-spi.c +++ b/arch/mips/bcm63xx/dev-spi.c | |||
@@ -106,11 +106,15 @@ int __init bcm63xx_spi_register(void) | |||
106 | if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) { | 106 | if (BCMCPU_IS_6338() || BCMCPU_IS_6348()) { |
107 | spi_resources[0].end += BCM_6338_RSET_SPI_SIZE - 1; | 107 | spi_resources[0].end += BCM_6338_RSET_SPI_SIZE - 1; |
108 | spi_pdata.fifo_size = SPI_6338_MSG_DATA_SIZE; | 108 | spi_pdata.fifo_size = SPI_6338_MSG_DATA_SIZE; |
109 | spi_pdata.msg_type_shift = SPI_6338_MSG_TYPE_SHIFT; | ||
110 | spi_pdata.msg_ctl_width = SPI_6338_MSG_CTL_WIDTH; | ||
109 | } | 111 | } |
110 | 112 | ||
111 | if (BCMCPU_IS_6358() || BCMCPU_IS_6368()) { | 113 | if (BCMCPU_IS_6358() || BCMCPU_IS_6368()) { |
112 | spi_resources[0].end += BCM_6358_RSET_SPI_SIZE - 1; | 114 | spi_resources[0].end += BCM_6358_RSET_SPI_SIZE - 1; |
113 | spi_pdata.fifo_size = SPI_6358_MSG_DATA_SIZE; | 115 | spi_pdata.fifo_size = SPI_6358_MSG_DATA_SIZE; |
116 | spi_pdata.msg_type_shift = SPI_6358_MSG_TYPE_SHIFT; | ||
117 | spi_pdata.msg_ctl_width = SPI_6358_MSG_CTL_WIDTH; | ||
114 | } | 118 | } |
115 | 119 | ||
116 | bcm63xx_spi_regs_init(); | 120 | bcm63xx_spi_regs_init(); |
diff --git a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h index 7d98dbe5d4b5..c9bae1362606 100644 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_dev_spi.h | |||
@@ -9,6 +9,8 @@ int __init bcm63xx_spi_register(void); | |||
9 | 9 | ||
10 | struct bcm63xx_spi_pdata { | 10 | struct bcm63xx_spi_pdata { |
11 | unsigned int fifo_size; | 11 | unsigned int fifo_size; |
12 | unsigned int msg_type_shift; | ||
13 | unsigned int msg_ctl_width; | ||
12 | int bus_num; | 14 | int bus_num; |
13 | int num_chipselect; | 15 | int num_chipselect; |
14 | u32 speed_hz; | 16 | u32 speed_hz; |
diff --git a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h index 4ccc2a748aff..61f2a2a5099d 100644 --- a/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h +++ b/arch/mips/include/asm/mach-bcm63xx/bcm63xx_regs.h | |||
@@ -1054,7 +1054,8 @@ | |||
1054 | #define SPI_6338_FILL_BYTE 0x07 | 1054 | #define SPI_6338_FILL_BYTE 0x07 |
1055 | #define SPI_6338_MSG_TAIL 0x09 | 1055 | #define SPI_6338_MSG_TAIL 0x09 |
1056 | #define SPI_6338_RX_TAIL 0x0b | 1056 | #define SPI_6338_RX_TAIL 0x0b |
1057 | #define SPI_6338_MSG_CTL 0x40 | 1057 | #define SPI_6338_MSG_CTL 0x40 /* 8-bits register */ |
1058 | #define SPI_6338_MSG_CTL_WIDTH 8 | ||
1058 | #define SPI_6338_MSG_DATA 0x41 | 1059 | #define SPI_6338_MSG_DATA 0x41 |
1059 | #define SPI_6338_MSG_DATA_SIZE 0x3f | 1060 | #define SPI_6338_MSG_DATA_SIZE 0x3f |
1060 | #define SPI_6338_RX_DATA 0x80 | 1061 | #define SPI_6338_RX_DATA 0x80 |
@@ -1070,7 +1071,8 @@ | |||
1070 | #define SPI_6348_FILL_BYTE 0x07 | 1071 | #define SPI_6348_FILL_BYTE 0x07 |
1071 | #define SPI_6348_MSG_TAIL 0x09 | 1072 | #define SPI_6348_MSG_TAIL 0x09 |
1072 | #define SPI_6348_RX_TAIL 0x0b | 1073 | #define SPI_6348_RX_TAIL 0x0b |
1073 | #define SPI_6348_MSG_CTL 0x40 | 1074 | #define SPI_6348_MSG_CTL 0x40 /* 8-bits register */ |
1075 | #define SPI_6348_MSG_CTL_WIDTH 8 | ||
1074 | #define SPI_6348_MSG_DATA 0x41 | 1076 | #define SPI_6348_MSG_DATA 0x41 |
1075 | #define SPI_6348_MSG_DATA_SIZE 0x3f | 1077 | #define SPI_6348_MSG_DATA_SIZE 0x3f |
1076 | #define SPI_6348_RX_DATA 0x80 | 1078 | #define SPI_6348_RX_DATA 0x80 |
@@ -1078,6 +1080,7 @@ | |||
1078 | 1080 | ||
1079 | /* BCM 6358 SPI core */ | 1081 | /* BCM 6358 SPI core */ |
1080 | #define SPI_6358_MSG_CTL 0x00 /* 16-bits register */ | 1082 | #define SPI_6358_MSG_CTL 0x00 /* 16-bits register */ |
1083 | #define SPI_6358_MSG_CTL_WIDTH 16 | ||
1081 | #define SPI_6358_MSG_DATA 0x02 | 1084 | #define SPI_6358_MSG_DATA 0x02 |
1082 | #define SPI_6358_MSG_DATA_SIZE 0x21e | 1085 | #define SPI_6358_MSG_DATA_SIZE 0x21e |
1083 | #define SPI_6358_RX_DATA 0x400 | 1086 | #define SPI_6358_RX_DATA 0x400 |
@@ -1094,6 +1097,7 @@ | |||
1094 | 1097 | ||
1095 | /* BCM 6358 SPI core */ | 1098 | /* BCM 6358 SPI core */ |
1096 | #define SPI_6368_MSG_CTL 0x00 /* 16-bits register */ | 1099 | #define SPI_6368_MSG_CTL 0x00 /* 16-bits register */ |
1100 | #define SPI_6368_MSG_CTL_WIDTH 16 | ||
1097 | #define SPI_6368_MSG_DATA 0x02 | 1101 | #define SPI_6368_MSG_DATA 0x02 |
1098 | #define SPI_6368_MSG_DATA_SIZE 0x21e | 1102 | #define SPI_6368_MSG_DATA_SIZE 0x21e |
1099 | #define SPI_6368_RX_DATA 0x400 | 1103 | #define SPI_6368_RX_DATA 0x400 |
@@ -1115,7 +1119,10 @@ | |||
1115 | #define SPI_HD_W 0x01 | 1119 | #define SPI_HD_W 0x01 |
1116 | #define SPI_HD_R 0x02 | 1120 | #define SPI_HD_R 0x02 |
1117 | #define SPI_BYTE_CNT_SHIFT 0 | 1121 | #define SPI_BYTE_CNT_SHIFT 0 |
1118 | #define SPI_MSG_TYPE_SHIFT 14 | 1122 | #define SPI_6338_MSG_TYPE_SHIFT 6 |
1123 | #define SPI_6348_MSG_TYPE_SHIFT 6 | ||
1124 | #define SPI_6358_MSG_TYPE_SHIFT 14 | ||
1125 | #define SPI_6368_MSG_TYPE_SHIFT 14 | ||
1119 | 1126 | ||
1120 | /* Command */ | 1127 | /* Command */ |
1121 | #define SPI_CMD_NOOP 0x00 | 1128 | #define SPI_CMD_NOOP 0x00 |
diff --git a/drivers/spi/spi-bcm63xx.c b/drivers/spi/spi-bcm63xx.c index 6e25ef1bce91..b7d61e7b8737 100644 --- a/drivers/spi/spi-bcm63xx.c +++ b/drivers/spi/spi-bcm63xx.c | |||
@@ -47,6 +47,8 @@ struct bcm63xx_spi { | |||
47 | /* Platform data */ | 47 | /* Platform data */ |
48 | u32 speed_hz; | 48 | u32 speed_hz; |
49 | unsigned fifo_size; | 49 | unsigned fifo_size; |
50 | unsigned int msg_type_shift; | ||
51 | unsigned int msg_ctl_width; | ||
50 | 52 | ||
51 | /* Data buffers */ | 53 | /* Data buffers */ |
52 | const unsigned char *tx_ptr; | 54 | const unsigned char *tx_ptr; |
@@ -221,13 +223,20 @@ static unsigned int bcm63xx_txrx_bufs(struct spi_device *spi, | |||
221 | msg_ctl = (t->len << SPI_BYTE_CNT_SHIFT); | 223 | msg_ctl = (t->len << SPI_BYTE_CNT_SHIFT); |
222 | 224 | ||
223 | if (t->rx_buf && t->tx_buf) | 225 | if (t->rx_buf && t->tx_buf) |
224 | msg_ctl |= (SPI_FD_RW << SPI_MSG_TYPE_SHIFT); | 226 | msg_ctl |= (SPI_FD_RW << bs->msg_type_shift); |
225 | else if (t->rx_buf) | 227 | else if (t->rx_buf) |
226 | msg_ctl |= (SPI_HD_R << SPI_MSG_TYPE_SHIFT); | 228 | msg_ctl |= (SPI_HD_R << bs->msg_type_shift); |
227 | else if (t->tx_buf) | 229 | else if (t->tx_buf) |
228 | msg_ctl |= (SPI_HD_W << SPI_MSG_TYPE_SHIFT); | 230 | msg_ctl |= (SPI_HD_W << bs->msg_type_shift); |
229 | 231 | ||
230 | bcm_spi_writew(bs, msg_ctl, SPI_MSG_CTL); | 232 | switch (bs->msg_ctl_width) { |
233 | case 8: | ||
234 | bcm_spi_writeb(bs, msg_ctl, SPI_MSG_CTL); | ||
235 | break; | ||
236 | case 16: | ||
237 | bcm_spi_writew(bs, msg_ctl, SPI_MSG_CTL); | ||
238 | break; | ||
239 | } | ||
231 | 240 | ||
232 | /* Issue the transfer */ | 241 | /* Issue the transfer */ |
233 | cmd = SPI_CMD_START_IMMEDIATE; | 242 | cmd = SPI_CMD_START_IMMEDIATE; |
@@ -406,9 +415,21 @@ static int __devinit bcm63xx_spi_probe(struct platform_device *pdev) | |||
406 | master->transfer_one_message = bcm63xx_spi_transfer_one; | 415 | master->transfer_one_message = bcm63xx_spi_transfer_one; |
407 | master->mode_bits = MODEBITS; | 416 | master->mode_bits = MODEBITS; |
408 | bs->speed_hz = pdata->speed_hz; | 417 | bs->speed_hz = pdata->speed_hz; |
418 | bs->msg_type_shift = pdata->msg_type_shift; | ||
419 | bs->msg_ctl_width = pdata->msg_ctl_width; | ||
409 | bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA)); | 420 | bs->tx_io = (u8 *)(bs->regs + bcm63xx_spireg(SPI_MSG_DATA)); |
410 | bs->rx_io = (const u8 *)(bs->regs + bcm63xx_spireg(SPI_RX_DATA)); | 421 | bs->rx_io = (const u8 *)(bs->regs + bcm63xx_spireg(SPI_RX_DATA)); |
411 | 422 | ||
423 | switch (bs->msg_ctl_width) { | ||
424 | case 8: | ||
425 | case 16: | ||
426 | break; | ||
427 | default: | ||
428 | dev_err(dev, "unsupported MSG_CTL width: %d\n", | ||
429 | bs->msg_ctl_width); | ||
430 | goto out_clk_disable; | ||
431 | } | ||
432 | |||
412 | /* Initialize hardware */ | 433 | /* Initialize hardware */ |
413 | clk_enable(bs->clk); | 434 | clk_enable(bs->clk); |
414 | bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); | 435 | bcm_spi_writeb(bs, SPI_INTR_CLEAR_ALL, SPI_INT_STATUS); |