diff mbox

[U-Boot,V2,08/11] SPI: mxc_spi: fix swapping bug and add missing swapping in unaligned rx case

Message ID 1295513194-16158-9-git-send-email-sbabic@denx.de
State Superseded
Delegated to: Stefano Babic
Headers show

Commit Message

Stefano Babic Jan. 20, 2011, 8:46 a.m. UTC
From: Anatolij Gustschin <agust@denx.de>

We need to shift only one time in each cycle in the swapping loop
for unaligned tx case. Currently two byte shift operations are
performed in each loop cycle causing zero gaps in the transmited
data, so not all data scheduled for transmition is actually
transmited.

The proper swapping in unaligned rx case is missing, so add it
as we need to put the received data into the rx buffer in the
correct byte order.

Signed-off-by: Anatolij Gustschin <agust@denx.de>
Tested-by: Stefano Babic <sbabic@denx.de>
---
 drivers/spi/mxc_spi.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

Comments

Wolfgang Denk Jan. 20, 2011, 9:32 a.m. UTC | #1
Dear Stefano Babic,

In message <1295513194-16158-9-git-send-email-sbabic@denx.de> you wrote:
> From: Anatolij Gustschin <agust@denx.de>
> 
> We need to shift only one time in each cycle in the swapping loop
> for unaligned tx case. Currently two byte shift operations are
> performed in each loop cycle causing zero gaps in the transmited
> data, so not all data scheduled for transmition is actually
> transmited.
> 
> The proper swapping in unaligned rx case is missing, so add it
> as we need to put the received data into the rx buffer in the
> correct byte order.
> 
> Signed-off-by: Anatolij Gustschin <agust@denx.de>
> Tested-by: Stefano Babic <sbabic@denx.de>

Checkpatch says:

	[U-Boot] [PATCH V2 08/11] SPI: mxc_spi: fix swapping bug and add
	total: 0 errors, 1 warnings, 22 lines checked

Please have a look.


Best regards,

Wolfgang Denk
Stefano Babic Jan. 20, 2011, 10:29 a.m. UTC | #2
On 01/20/2011 10:32 AM, Wolfgang Denk wrote:
> Dear Stefano Babic,
> 
> In message <1295513194-16158-9-git-send-email-sbabic@denx.de> you wrote:
>> From: Anatolij Gustschin <agust@denx.de>
>>
>> We need to shift only one time in each cycle in the swapping loop
>> for unaligned tx case. Currently two byte shift operations are
>> performed in each loop cycle causing zero gaps in the transmited
>> data, so not all data scheduled for transmition is actually
>> transmited.
>>
>> The proper swapping in unaligned rx case is missing, so add it
>> as we need to put the received data into the rx buffer in the
>> correct byte order.
>>
>> Signed-off-by: Anatolij Gustschin <agust@denx.de>
>> Tested-by: Stefano Babic <sbabic@denx.de>
> 
> Checkpatch says:
> 
> 	[U-Boot] [PATCH V2 08/11] SPI: mxc_spi: fix swapping bug and add
> 	total: 0 errors, 1 warnings, 22 lines checked

WARNING: braces {} are not necessary for single statement blocks
#31: FILE: drivers/spi/mxc_spi.c:375:
+				for (i = 0; i < 4; i++) {
 					data = (data << 8) | (*dout++ & 0xFF);
 				}

total: 0 errors, 1 warnings, 22 lines checked

This is exactly what you prefer, but checkpatch complains. IMHO I prefer
to fix in this patch removing braces, and do not change in previous
patches where you suggest to add braces (and then checkpatch will
complain about it).

Best regards,
Stefano Babic
Wolfgang Denk Jan. 20, 2011, 11:59 a.m. UTC | #3
Dear Stefano Babic,

In message <4D380E7F.60506@denx.de> you wrote:
>
> > 	[U-Boot] [PATCH V2 08/11] SPI: mxc_spi: fix swapping bug and add
> > 	total: 0 errors, 1 warnings, 22 lines checked
> 
> WARNING: braces {} are not necessary for single statement blocks
> #31: FILE: drivers/spi/mxc_spi.c:375:
> +				for (i = 0; i < 4; i++) {
>  					data = (data << 8) | (*dout++ & 0xFF);
>  				}
> 
> total: 0 errors, 1 warnings, 22 lines checked
> 
> This is exactly what you prefer, but checkpatch complains. IMHO I prefer
> to fix in this patch removing braces, and do not change in previous
> patches where you suggest to add braces (and then checkpatch will
> complain about it).

These are two _different_ situations.

Here we have a single statement on a single line.  This needs no
braces.


In the other case, we had a single stament split over multiple lines,
and with multiple lines I want to see braces.  And checkpatch appears
to be happy with braces then, too (and without as well).

Best regards,

Wolfgang Denk
diff mbox

Patch

diff --git a/drivers/spi/mxc_spi.c b/drivers/spi/mxc_spi.c
index 5670714..3e99afd 100644
--- a/drivers/spi/mxc_spi.c
+++ b/drivers/spi/mxc_spi.c
@@ -372,7 +372,7 @@  int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
 			/* Buffer is not 32-bit aligned */
 			if ((unsigned long)dout & 0x03) {
 				data = 0;
-				for (i = 0; i < 4; i++, data <<= 8) {
+				for (i = 0; i < 4; i++) {
 					data = (data << 8) | (*dout++ & 0xFF);
 				}
 			} else {
@@ -405,11 +405,11 @@  int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
 	if (bitlen % 32) {
 		data = reg_read(mxcs->base + MXC_CSPIRXDATA);
 		cnt = (bitlen % 32) / 8;
+		data = cpu_to_be32(data) >> ((sizeof(data) - cnt) * 8);
 		debug("SPI Rx unaligned: 0x%x\n", data);
 		if (din) {
-			for (i = 0; i < cnt; i++, data >>= 8) {
-				*din++ = data & 0xFF;
-			}
+			memcpy(din, &data, cnt);
+			din += cnt;
 		}
 		nbytes -= cnt;
 	}