Patchwork [U-Boot,2/3] spi: fsl_espi: Use DIV_ROUND_UP instead of open-coded

login
register
mail settings
Submitter Axel Lin
Date July 12, 2013, 9:41 a.m.
Message ID <1373622068.24016.4.camel@phoenix>
Download mbox | patch
Permalink /patch/258731/
State Accepted
Delegated to: Jagannadha Sutradharudu Teki
Headers show

Comments

Axel Lin - July 12, 2013, 9:41 a.m.
Use DIV_ROUND_UP to simplify the code.

Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
 drivers/spi/fsl_espi.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
Jagannadha Sutradharudu Teki - Aug. 6, 2013, 6:49 p.m.
On 12-07-2013 15:11, Axel Lin wrote:
> Use DIV_ROUND_UP to simplify the code.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
>   drivers/spi/fsl_espi.c | 6 ++----
>   1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c
> index 28609ee..e20ab9f 100644
> --- a/drivers/spi/fsl_espi.c
> +++ b/drivers/spi/fsl_espi.c
> @@ -234,15 +234,13 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
>   	      slave->bus, slave->cs, *(uint *) dout,
>   	      dout, *(uint *) din, din, len);
>
> -	num_chunks = data_len / max_tran_len +
> -		(data_len % max_tran_len ? 1 : 0);
> +	num_chunks = DIV_ROUND_UP(data_len, max_tran_len);
>   	while (num_chunks--) {
>   		if (data_in)
>   			din = buffer + rx_offset;
>   		dout = buffer;
>   		tran_len = min(data_len , max_tran_len);
> -		num_blks = (tran_len + cmd_len) / 4 +
> -			((tran_len + cmd_len) % 4 ? 1 : 0);
> +		num_blks = DIV_ROUND_UP(tran_len + cmd_len, 4);
>   		num_bytes = (tran_len + cmd_len) % 4;
>   		fsl->data_len = tran_len + cmd_len;
>   		spi_cs_activate(slave);
>

Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>

--
Thanks,
Jagan.
Jagannadha Sutradharudu Teki - Aug. 6, 2013, 6:56 p.m.
On 07-08-2013 00:19, Jagan Teki wrote:
> On 12-07-2013 15:11, Axel Lin wrote:
>> Use DIV_ROUND_UP to simplify the code.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>> ---
>>   drivers/spi/fsl_espi.c | 6 ++----
>>   1 file changed, 2 insertions(+), 4 deletions(-)
>>
>> diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c
>> index 28609ee..e20ab9f 100644
>> --- a/drivers/spi/fsl_espi.c
>> +++ b/drivers/spi/fsl_espi.c
>> @@ -234,15 +234,13 @@ int spi_xfer(struct spi_slave *slave, unsigned
>> int bitlen, const void *data_out,
>>             slave->bus, slave->cs, *(uint *) dout,
>>             dout, *(uint *) din, din, len);
>>
>> -    num_chunks = data_len / max_tran_len +
>> -        (data_len % max_tran_len ? 1 : 0);
>> +    num_chunks = DIV_ROUND_UP(data_len, max_tran_len);
>>       while (num_chunks--) {
>>           if (data_in)
>>               din = buffer + rx_offset;
>>           dout = buffer;
>>           tran_len = min(data_len , max_tran_len);
>> -        num_blks = (tran_len + cmd_len) / 4 +
>> -            ((tran_len + cmd_len) % 4 ? 1 : 0);
>> +        num_blks = DIV_ROUND_UP(tran_len + cmd_len, 4);
>>           num_bytes = (tran_len + cmd_len) % 4;
>>           fsl->data_len = tran_len + cmd_len;
>>           spi_cs_activate(slave);
>>
>
> Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
>
> --
> Thanks,
> Jagan.

Applied to u-boot-spi/master

--
Thanks,
Jagan.

Patch

diff --git a/drivers/spi/fsl_espi.c b/drivers/spi/fsl_espi.c
index 28609ee..e20ab9f 100644
--- a/drivers/spi/fsl_espi.c
+++ b/drivers/spi/fsl_espi.c
@@ -234,15 +234,13 @@  int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *data_out,
 	      slave->bus, slave->cs, *(uint *) dout,
 	      dout, *(uint *) din, din, len);
 
-	num_chunks = data_len / max_tran_len +
-		(data_len % max_tran_len ? 1 : 0);
+	num_chunks = DIV_ROUND_UP(data_len, max_tran_len);
 	while (num_chunks--) {
 		if (data_in)
 			din = buffer + rx_offset;
 		dout = buffer;
 		tran_len = min(data_len , max_tran_len);
-		num_blks = (tran_len + cmd_len) / 4 +
-			((tran_len + cmd_len) % 4 ? 1 : 0);
+		num_blks = DIV_ROUND_UP(tran_len + cmd_len, 4);
 		num_bytes = (tran_len + cmd_len) % 4;
 		fsl->data_len = tran_len + cmd_len;
 		spi_cs_activate(slave);