spi/dw_spi: clean the cs_control code
PATCH 1/1 spi/dw_spi: clean the cs_control code
commit 052dc7c45 introduced cs_control code, which has a bug in setting transfer mode, also it forces devices who don't need cs_control to re-configured the control registers. This patch will fix them
--- drivers/spi/dw_spi.c | 17 +++++------------ include/linux/spi/dw_spi.h | 3 +++ 2 files changed, 8 insertions(+), 12 deletions(-)
drivers/spi/dw_spi.c +5 -12
@@ -181,10 +181,6 @@ static void flush(struct dw_spi *dws)wait_till_not_busy (dws); } -static void null_cs_control (u32 command) -{ -} -static int null_writer (struct dw_spi *dws) {u8 n_bytes = dws->n_bytes;
@@ -322,7 +318,7 @@ static void giveback(struct dw_spi *dws) struct spi_transfer, transfer_list); -if (!last_transfer->cs_change) +if (!last_transfer->cs_change && dws->cs_control) dws->cs_control (MRST_SPI_DEASSERT ); msg->state =NULL ;
@@ -544,13 +540,13 @@ static void pump_transfers(unsigned long data)*/ if (dws->cs_control) {if (dws->rx && dws->tx) - chip->tmode =0x00 ; + chip->tmode =SPI_TMOD_TR ;else if (dws->rx) - chip->tmode =0x02 ; + chip->tmode =SPI_TMOD_RO ;else - chip->tmode =0x01 ; + chip->tmode =SPI_TMOD_TO ; - cr0 &= ~(0x3 <<SPI_MODE_OFFSET ); + cr0 &= ~SPI_TMOD_MASK ; cr0 |= (chip->tmode <<SPI_TMOD_OFFSET ); }
@@ -699,9 +695,6 @@ static int dw_spi_setup(struct spi_device *spi) chip =kzalloc (sizeof (struct chip_data ),GFP_KERNEL );if (!chip)return -ENOMEM ; - - chip->cs_control = null_cs_control; - chip->enable_dma =0 ; }/*
include/linux/spi/dw_spi.h +3 -0
@@ -12,9 +12,12 @@#define SPI_FRF_RESV 0x3#define SPI_MODE_OFFSET 6 +#define SPI_MODE_MASK (0x3 << SPI_MODE_OFFSET)#define SPI_SCPH_OFFSET 6#define SPI_SCOL_OFFSET 7 +#define SPI_TMOD_OFFSET 8 +#define SPI_TMOD_MASK (0x3 << SPI_TMOD_OFFSET)#define SPI_TMOD_TR 0x0/* xmit & recv */ #define SPI_TMOD_TO 0x1/* xmit only */ #define SPI_TMOD_RO 0x2/* recv only */
Signature · 9 lines
1.7.0.4 ------------------------------------------------------------------------------ This SF.net Dev2Dev email is sponsored by: Show off your parallel programming skills. Enter the Intel(R) Threading Challenge 2010. http://p.sf.net/sfu/intel-thread-sfd
A message that is not in the archive (sent off-list or not yet received): 1283319359-16297-1-git-send-email-feng.tang-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org
Hi Feng,
Quoted 1 line · Feng Tang
commit
052dc7c45introducedcs_controlcode,
Be friendly to mere-mortals. You should quote the patch title "spi/dw_spi:
conditional transfer mode changes" in addition to the sha1 id.
Quoted 2 lines
which has a bug in setting
transfer mode,
It would be helpful if you explained what the bug is.
Quoted 42 lines
also it forces devices who don't need
cs_controlto re-configured the control registers. This patch will fix themSigned-off-by Feng Tang <[email protected]>Cc David Brownell <[email protected]>Cc Grant Likely <grant.likely-s3s/[email protected]>Cc George Shore <[email protected]>--- drivers/spi/dw_spi.c | 17 +++++------------ include/linux/spi/dw_spi.h | 3 +++ 2 files changed, 8 insertions(+), 12 deletions(-)drivers/spi/dw_spi.c +2
-6@@ -181,10 +181,6 @@ static void flush(struct dw_spi *dws)wait_till_not_busy (dws); } -static void null_cs_control (u32 command) -{ -} -static int null_writer (struct dw_spi *dws) {u8 n_bytes = dws->n_bytes;@@ -322,7 +318,7 @@ static void giveback(struct dw_spi *dws) struct spi_transfer, transfer_list); -if (!last_transfer->cs_change) +if (!last_transfer->cs_change && dws->cs_control) dws->cs_control (MRST_SPI_DEASSERT ); msg->state =NULL ;@@ -544,13 +540,13 @@ static void pump_transfers(unsigned long data)*/ if (dws->cs_control) {if (dws->rx && dws->tx) - chip->tmode =0x00 ; + chip->tmode =SPI_TMOD_TR ;
drivers/spi/dw_spi.c static void pump_transfers(unsigned long data) · line 550
Quoted 10 lines
drivers/spi/dw_spi.c +3
-3else if (dws->rx) - chip->tmode =0x02 ; + chip->tmode =SPI_TMOD_RO ;else - chip->tmode =0x01 ; + chip->tmode =SPI_TMOD_TO ; - cr0 &= ~(0x3 <<SPI_MODE_OFFSET ); + cr0 &= ~SPI_TMOD_MASK ; cr0 |= (chip->tmode <<SPI_TMOD_OFFSET );
Changing these values isn't mentioned in the patch description. I assume this is not the bug fix because the #defines are the same values.
Quoted 17 lines
drivers/spi/dw_spi.c +0
-3}@@ -699,9 +695,6 @@ static int dw_spi_setup(struct spi_device *spi) chip =kzalloc (sizeof (struct chip_data ),GFP_KERNEL );if (!chip)return -ENOMEM ; - - chip->cs_control = null_cs_control; - chip->enable_dma =0 ; }/* include/linux/spi/dw_spi.h +0
-0
include/linux/spi/dw_spi.h line 15
Quoted 4 lines
include/linux/spi/dw_spi.h +1
-0@@ -12,9 +12,12 @@#define SPI_FRF_RESV 0x3#define SPI_MODE_OFFSET 6 +#define SPI_MODE_MASK (0x3 << SPI_MODE_OFFSET)
SPI_MODE_MASK is unused.
Quoted 11 lines
include/linux/spi/dw_spi.h +2
-0#define SPI_SCPH_OFFSET 6#define SPI_SCOL_OFFSET 7 +#define SPI_TMOD_OFFSET 8 +#define SPI_TMOD_MASK (0x3 << SPI_TMOD_OFFSET)#define SPI_TMOD_TR 0x0/* xmit & recv */ #define SPI_TMOD_TO 0x1/* xmit only */ #define SPI_TMOD_RO 0x2/* recv only */ Signature · 1 line
1.7.0.4
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd
A message that is not in the archive (sent off-list or not yet received): 20100901150757.GA13421-MrY2KI0G/OVr83L8+7iqerDks+cytr/[email protected]
Quoted 8 lines · On Wed, 1 Sep 2010 23:07:57 +0800 Grant Likely…
Hi Feng,
Quoted 1 line · Feng Tang
commit
052dc7c45introducedcs_controlcode,Be friendly to mere-mortals. You should quote the patch title "spi/dw_spi: conditional transfer mode changes" in addition to the sha1 id.
Got it, thanks, will add it in V2
Quoted 13 lines
Quoted 13 lines
drivers/spi/dw_spi.c +3
-3@@ -544,13 +540,13 @@ static void pump_transfers(unsigned long data)*/ if (dws->cs_control) {if (dws->rx && dws->tx) - chip->tmode =0x00 ; + chip->tmode =SPI_TMOD_TR ;else if (dws->rx) - chip->tmode =0x02 ; + chip->tmode =SPI_TMOD_RO ;else - chip->tmode =0x01 ; + chip->tmode =SPI_TMOD_TO ;
Quoted 7 lines
drivers/spi/dw_spi.c static void pump_transfers(unsigned long data) · line 550
Quoted 3 lines
drivers/spi/dw_spi.c +1
-1- cr0 &= ~(0x3 <<SPI_MODE_OFFSET ); + cr0 &= ~SPI_TMOD_MASK ; cr0 |= (chip->tmode <<SPI_TMOD_OFFSET );Changing these values isn't mentioned in the patch description. I assume this is not the bug fix because the #defines are the same values.
OK, it's a little confusing, there are 2 OFFSET here:
SPI_MODE_OFFSET (for spi mode 0/1/2 etc setting) SPI_TMOD_OFFSET (for tx only/rx only/duplex)
So simple fix should be
- cr0 &= ~(0x3 << SPI_MODE_OFFSET);
+ cr0 &= ~(0x3 << SPI_TMOD_OFFSET);
while my new introduced SPI_TMOD_MASK make things complex :)
Thanks,
Feng
------------------------------------------------------------------------------
This SF.net Dev2Dev email is sponsored by:
Show off your parallel programming skills.
Enter the Intel(R) Threading Challenge 2010.
http://p.sf.net/sfu/intel-thread-sfd