spi: sh_qspi: Replace data types with short ones
PATCH 1/4 spi: sh_qspi: Replace data types with short ones
Just replace unsigned {char,short,long} with u{8,16,32}, no functional change.
--- drivers/spi/sh_qspi.c | 62 +++++++++++++++++++++++++-------------------------- 1 file changed, 31 insertions(+), 31 deletions(-)
drivers/spi/sh_qspi.c +31 -31
@@ -38,30 +38,30 @@/* SH QSPI register set */ struct sh_qspi_regs { -unsigned char spcr; -unsigned char sslp; -unsigned char sppcr; -unsigned char spsr; -unsigned long spdr; -unsigned char spscr; -unsigned char spssr; -unsigned char spbr; -unsigned char spdcr; -unsigned char spckd; -unsigned char sslnd; -unsigned char spnd; -unsigned char dummy0; -unsigned short spcmd0; -unsigned short spcmd1; -unsigned short spcmd2; -unsigned short spcmd3; -unsigned char spbfcr; -unsigned char dummy1; -unsigned short spbdcr; -unsigned long spbmul0; -unsigned long spbmul1; -unsigned long spbmul2; -unsigned long spbmul3; +u8 spcr; +u8 sslp; +u8 sppcr; +u8 spsr; +u32 spdr; +u8 spscr; +u8 spssr; +u8 spbr; +u8 spdcr; +u8 spckd; +u8 sslnd; +u8 spnd; +u8 dummy0; +u16 spcmd0; +u16 spcmd1; +u16 spcmd2; +u16 spcmd3; +u8 spbfcr; +u8 dummy1; +u16 spbdcr; +u32 spbmul0; +u32 spbmul1; +u32 spbmul2; +u32 spbmul3; };struct sh_qspi_slave {
@@ -200,11 +200,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, void *din, unsigned long flags) {struct sh_qspi_slave *ss =to_sh_qspi (slave); -unsigned long nbyte; +u32 nbyte;int ret =0 ; -unsigned char dtdata =0 , drdata; -unsigned char *tdata = &dtdata, *rdata = &drdata; -unsigned long *spbmul0 = &ss->regs->spbmul0; +u8 dtdata =0 , drdata; +u8 *tdata = &dtdata, *rdata = &drdata; +u32 *spbmul0 = &ss->regs->spbmul0;if (dout ==NULL && din ==NULL ) {if (flags &SPI_XFER_END )
@@ -230,7 +230,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,writel (nbyte, spbmul0);if (dout !=NULL ) - tdata = (unsigned char *)dout; + tdata = (u8 *)dout;if (din !=NULL ) rdata = din;
@@ -244,7 +244,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,udelay (10 ); } -writeb (*tdata, (unsigned char *)(&ss->regs->spdr)); +writeb (*tdata, (u8 *)(&ss->regs->spdr));while ((readw (&ss->regs->spbdcr) !=SPBDCR_RXBC0 )) {if (ctrlc ()) {
@@ -262,7 +262,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,udelay (10 ); } - *rdata =readb ((unsigned char *)(&ss->regs->spdr)); + *rdata =readb ((u8 *)(&ss->regs->spdr));if (dout !=NULL ) tdata++;
Signature · 1 line
2.16.2
PATCH 2/4 spi: sh_qspi: Drop SPBDCR wait
Waiting for SPBDCR == 1 is not required and is covered by the subsequent wait for SPSR_SPRFF, so drop this.
--- drivers/spi/sh_qspi.c | 8 -------- 1 file changed, 8 deletions(-)
drivers/spi/sh_qspi.c +0 -8
@@ -246,14 +246,6 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,writeb (*tdata, (u8 *)(&ss->regs->spdr)); -while ((readw (&ss->regs->spbdcr) !=SPBDCR_RXBC0 )) { -if (ctrlc ()) { -puts ("abort\n" ); -return 1 ; - } -udelay (1 ); - } -while (!(readb (&ss->regs->spsr) &SPSR_SPRFF )) {if (ctrlc ()) {puts ("abort\n" );
Signature · 1 line
2.16.2
PATCH 3/4 spi: sh_qspi: Replace ad hoc waiting with wait_for_bit
In reply to Marek VasutReplace the ad-hoc endless loops with wait_for_bit() with reasonable timeout. Note that the loops had internal 10uS delays, although there is no reason for those on this HW, so they are dropped.
--- drivers/spi/sh_qspi.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-)
drivers/spi/sh_qspi.c +9 -14
@@ -11,6 +11,7 @@#include <console.h> #include <malloc.h> #include <spi.h> +#include <wait_bit.h> #include <asm/arch/rmobile.h> #include <asm/io.h>
@@ -236,23 +237,17 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, rdata = din;while (nbyte >0 ) { -while (!(readb (&ss->regs->spsr) &SPSR_SPTEF )) { -if (ctrlc ()) { -puts ("abort\n" ); -return 1 ; - } -udelay (10 ); - } + ret =wait_for_bit_8 (&ss->regs->spsr,SPSR_SPTEF , + true,1000 , true); +if (ret) +return ret;writeb (*tdata, (u8 *)(&ss->regs->spdr)); -while (!(readb (&ss->regs->spsr) &SPSR_SPRFF )) { -if (ctrlc ()) { -puts ("abort\n" ); -return 1 ; - } -udelay (10 ); - } + ret =wait_for_bit_8 (&ss->regs->spsr,SPSR_SPRFF , + true,1000 , true); +if (ret) +return ret; *rdata =readb ((u8 *)(&ss->regs->spdr));
Signature · 1 line
2.16.2
PATCH 4/4 spi: sh_qspi: Make use of the 32byte FIFO
In reply to Marek VasutThe QSPI controller on RCar Gen2 has 32byte FIFO. Instead of doing the SPI transmission 1 byte at time, if there is a 32byte chunk of data to be transferred, fill the FIFO completely and then transfer the data to/from the FIFO. This increases the SPI NOR access speed significantly.
--- drivers/spi/sh_qspi.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-)
drivers/spi/sh_qspi.c +24 -10
@@ -36,6 +36,8 @@ SPCMD_BRDV0#define SPBFCR_TXRST BIT(7)#define SPBFCR_RXRST BIT(6) +#define SPBFCR_TXTRG 0x30 +#define SPBFCR_RXTRG 0x07/* SH QSPI register set */ struct sh_qspi_regs {
@@ -201,8 +203,8 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, void *din, unsigned long flags) {struct sh_qspi_slave *ss =to_sh_qspi (slave); -u32 nbyte; -int ret =0 ; +u32 nbyte, chunk; +int i, ret =0 ;u8 dtdata =0 , drdata;u8 *tdata = &dtdata, *rdata = &drdata;u32 *spbmul0 = &ss->regs->spbmul0;
@@ -237,26 +239,38 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, rdata = din;while (nbyte >0 ) { +/* +* Check if there is 32 Byte chunk and if there is, transfer +* it in one burst, otherwise transfer on byte-by-byte basis. +*/ + chunk = (nbyte >=32 ) ?32 :1 ; + +clrsetbits_8 (&ss->regs->spbfcr,SPBFCR_TXTRG |SPBFCR_RXTRG , + chunk ==32 ?SPBFCR_TXTRG |SPBFCR_RXTRG :0 ); + ret =wait_for_bit_8 (&ss->regs->spsr,SPSR_SPTEF , true,1000 , true);if (ret)return ret; -writeb (*tdata, (u8 *)(&ss->regs->spdr)); +for (i =0 ; i < chunk; i++) { +writeb (*tdata, &ss->regs->spdr); +if (dout !=NULL ) + tdata++; + } ret =wait_for_bit_8 (&ss->regs->spsr,SPSR_SPRFF , true,1000 , true);if (ret)return ret; - *rdata =readb ((u8 *)(&ss->regs->spdr)); - -if (dout !=NULL ) - tdata++; -if (din !=NULL ) - rdata++; +for (i =0 ; i < chunk; i++) { + *rdata =readb (&ss->regs->spdr); +if (din !=NULL ) + rdata++; + } - nbyte--; + nbyte -= chunk; }if (flags &SPI_XFER_END )
Signature · 1 line
2.16.2