SPI: drain MXC SPI transfer buffer when probing device
Subsystems (2)
PATCH 1/1 SPI: drain MXC SPI transfer buffer when probing device
On the MX31litekit, the bootloader seems to communicate with the MC13783 PMIC chip before booting Linux. However, it does not flush all the buffers properly after that, which makes the imx-spi driver read bogus data when probing the MC13783.
Fix that by draining the SPI buffer on startup.
--- drivers/spi/spi_imx.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/spi/spi_imx.c +7 -0
@@ -42,8 +42,11 @@#define MXC_CSPITXDATA 0x04#define MXC_CSPICTRL 0x08#define MXC_CSPIINT 0x0c +#define MXC_CSPISTAT 0x14#define MXC_RESET 0x1c +#define MXC_CSPISTAT_RR (1 << 3) +/* generic defines to abstract from the different register layouts */ #define MXC_INT_RR (1 << 0)/* Receive data ready interrupt */ #define MXC_INT_TE (1 << 1)/* Transmit FIFO empty interrupt */
@@ -593,6 +596,10 @@ static int __init spi_imx_probe(struct platform_device *pdev)if (!cpu_is_mx31 () || !cpu_is_mx35 ())writel (1 , spi_imx->base +MXC_RESET ); +/* drain the buffer */ +while (readl (spi_imx->base +MXC_CSPISTAT ) &MXC_CSPISTAT_RR ) +readl (spi_imx->base +MXC_CSPIRXDATA ); + spi_imx->intctrl (spi_imx,0 ); ret =spi_bitbang_start (&spi_imx->bitbang);
Signature · 1 line
1.6.5.2
PATCH 1/1 SPI: drain MXC SPI transfer buffer when probing device
Hello Daniel,
Quoted 22 lines · Daniel Mack
On the MX31litekit, the bootloader seems to communicate with the MC13783 PMIC chip before booting Linux. However, it does not flush all the buffers properly after that, which makes the imx-spi driver read bogus data when probing the MC13783.
Fix that by draining the SPI buffer on startup.
Signed-off-by Daniel Mack <[email protected]>Cc David Brownell <[email protected]>Cc Andrew Morton <[email protected]>Cc Sascha Hauer <[email protected]>Cc Uwe Kleine-K?nig <[email protected]>Cc spi-devel-general at lists.sourceforge.net--- drivers/spi/spi_imx.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)drivers/spi/spi_imx.c +0
-0
drivers/spi/spi_imx.c line 45
Quoted 4 lines
drivers/spi/spi_imx.c +1
-0@@ -42,8 +42,11 @@#define MXC_CSPITXDATA 0x04#define MXC_CSPICTRL 0x08#define MXC_CSPIINT 0x0c +#define MXC_CSPISTAT 0x14
On imx27 the register at offset 0x14 is called PERIODREG ...
drivers/spi/spi_imx.c line 48
Quoted 3 lines
drivers/spi/spi_imx.c +1
-0#define MXC_RESET 0x1c +#define MXC_CSPISTAT_RR (1 << 3)
... and bits 0..14 are called WAIT.
drivers/spi/spi_imx.c static int __init spi_imx_probe(struct platform_device *pdev) · line 602
Quoted 12 lines
drivers/spi/spi_imx.c +5
-0+/* generic defines to abstract from the different register layouts */ #define MXC_INT_RR (1 << 0)/* Receive data ready interrupt */ #define MXC_INT_TE (1 << 1)/* Transmit FIFO empty interrupt */ @@ -593,6 +596,10 @@ static int __init spi_imx_probe(struct platform_device *pdev)if (!cpu_is_mx31 () || !cpu_is_mx35 ())writel (1 , spi_imx->base +MXC_RESET ); +/* drain the buffer */ +while (readl (spi_imx->base +MXC_CSPISTAT ) &MXC_CSPISTAT_RR ) +readl (spi_imx->base +MXC_CSPIRXDATA ); +
So this needs protection by
if (cpu_is_mx31() || cpu_is_mx35())
(note, I didn't check the mx35 reference!).
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |
PATCH 1/1 SPI: drain MXC SPI transfer buffer when probing device
Hi Uwe,
Quoted 43 lines · Uwe Kleine-K?nig
Quoted 22 lines · Daniel Mack
On the MX31litekit, the bootloader seems to communicate with the MC13783 PMIC chip before booting Linux. However, it does not flush all the buffers properly after that, which makes the imx-spi driver read bogus data when probing the MC13783.
Fix that by draining the SPI buffer on startup.
Signed-off-by Daniel Mack <[email protected]>Cc David Brownell <[email protected]>Cc Andrew Morton <[email protected]>Cc Sascha Hauer <[email protected]>Cc Uwe Kleine-K?nig <[email protected]>Cc spi-devel-general at lists.sourceforge.net--- drivers/spi/spi_imx.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)drivers/spi/spi_imx.c +0
-0drivers/spi/spi_imx.c line 45
Quoted 4 lines
drivers/spi/spi_imx.c +1
-0@@ -42,8 +42,11 @@#define MXC_CSPITXDATA 0x04#define MXC_CSPICTRL 0x08#define MXC_CSPIINT 0x0c +#define MXC_CSPISTAT 0x14On imx27 the register at offset
0x14is called PERIODREG ...drivers/spi/spi_imx.c line 48
Quoted 3 lines
drivers/spi/spi_imx.c +1
-0#define MXC_RESET 0x1c +#define MXC_CSPISTAT_RR (1 << 3)... and bits 0..14 are called WAIT.
Quoted 8 lines
drivers/spi/spi_imx.c +1
-0+/* generic defines to abstract from the different register layouts */ #define MXC_INT_RR (1 << 0)/* Receive data ready interrupt */ #define MXC_INT_TE (1 << 1)/* Transmit FIFO empty interrupt */ @@ -593,6 +596,10 @@ static int __init spi_imx_probe(struct platform_device *pdev)if (!cpu_is_mx31 () || !cpu_is_mx35 ())writel (1 , spi_imx->base +MXC_RESET );
Quoted 7 lines
drivers/spi/spi_imx.c static int __init spi_imx_probe(struct platform_device *pdev) · line 602
Quoted 4 lines
drivers/spi/spi_imx.c +4
-0+/* drain the buffer */ +while (readl (spi_imx->base +MXC_CSPISTAT ) &MXC_CSPISTAT_RR ) +readl (spi_imx->base +MXC_CSPIRXDATA ); +So this needs protection by
if (cpu_is_mx31() || cpu_is_mx35())
Oh, I wasn't aware of such differences, thanks for checking!
Quoted 1 line
(note, I didn't check the mx35 reference!).
But I did now, and mx35 seems to be compatible. I also changed the register define names to avoid confusion.
New patch below.
Thanks,
Daniel
PATCH 1/1 SPI: drain MXC SPI transfer buffer when probing device
Hello,
Quoted 52 lines · Daniel Mack
Hi Uwe,
Quoted 49 lines · Uwe Kleine-K?nig
Quoted 22 lines · Daniel Mack
On the MX31litekit, the bootloader seems to communicate with the MC13783 PMIC chip before booting Linux. However, it does not flush all the buffers properly after that, which makes the imx-spi driver read bogus data when probing the MC13783.
Fix that by draining the SPI buffer on startup.
Signed-off-by Daniel Mack <[email protected]>Cc David Brownell <[email protected]>Cc Andrew Morton <[email protected]>Cc Sascha Hauer <[email protected]>Cc Uwe Kleine-K?nig <[email protected]>Cc spi-devel-general at lists.sourceforge.net--- drivers/spi/spi_imx.c | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-)drivers/spi/spi_imx.c +0
-0drivers/spi/spi_imx.c line 45
Quoted 4 lines
drivers/spi/spi_imx.c +1
-0@@ -42,8 +42,11 @@#define MXC_CSPITXDATA 0x04#define MXC_CSPICTRL 0x08#define MXC_CSPIINT 0x0c +#define MXC_CSPISTAT 0x14On imx27 the register at offset
0x14is called PERIODREG ...drivers/spi/spi_imx.c line 48
Quoted 3 lines
drivers/spi/spi_imx.c +1
-0#define MXC_RESET 0x1c +#define MXC_CSPISTAT_RR (1 << 3)... and bits 0..14 are called WAIT.
drivers/spi/spi_imx.c static int __init spi_imx_probe(struct platform_device *pdev) · line 602
Quoted 12 lines
drivers/spi/spi_imx.c +5
-0+/* generic defines to abstract from the different register layouts */ #define MXC_INT_RR (1 << 0)/* Receive data ready interrupt */ #define MXC_INT_TE (1 << 1)/* Transmit FIFO empty interrupt */ @@ -593,6 +596,10 @@ static int __init spi_imx_probe(struct platform_device *pdev)if (!cpu_is_mx31 () || !cpu_is_mx35 ())writel (1 , spi_imx->base +MXC_RESET ); +/* drain the buffer */ +while (readl (spi_imx->base +MXC_CSPISTAT ) &MXC_CSPISTAT_RR ) +readl (spi_imx->base +MXC_CSPIRXDATA ); +So this needs protection by
Quoted 8 lines
Quoted 1 line
if (cpu_is_mx31() || cpu_is_mx35())Oh, I wasn't aware of such differences, thanks for checking!
Quoted 1 line
(note, I didn't check the mx35 reference!).
But I did now, and mx35 seems to be compatible. I also changed the register define names to avoid confusion.
hmm, I'm not really happy with the naming, but as I don't have a better idea now, it's OK for me.
You can take it as an ack.
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |