* [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded
@ 2013-07-12 9:39 Axel Lin
2013-07-12 9:41 ` [U-Boot] [PATCH 2/3] spi: fsl_espi: " Axel Lin
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Axel Lin @ 2013-07-12 9:39 UTC (permalink / raw)
To: u-boot
Use DIV_ROUND_UP to simplify the code.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/spi/bfin_spi.c | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
index a9a4d92..f7192c2 100644
--- a/drivers/spi/bfin_spi.c
+++ b/drivers/spi/bfin_spi.c
@@ -144,10 +144,8 @@ void spi_set_speed(struct spi_slave *slave, uint hz)
u32 baud;
sclk = get_sclk();
- baud = sclk / (2 * hz);
/* baud should be rounded up */
- if (sclk % (2 * hz))
- baud += 1;
+ baud = DIV_ROUND_UP(sclk, 2 * hz);
if (baud < 2)
baud = 2;
else if (baud > (u16)-1)
--
1.8.1.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 2/3] spi: fsl_espi: Use DIV_ROUND_UP instead of open-coded
2013-07-12 9:39 [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded Axel Lin
@ 2013-07-12 9:41 ` Axel Lin
2013-08-06 18:49 ` Jagan Teki
2013-07-12 9:42 ` [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: " Axel Lin
2013-07-15 7:58 ` [U-Boot] [PATCH 1/3] spi: bfin_spi: " Sonic Zhang
2 siblings, 1 reply; 8+ messages in thread
From: Axel Lin @ 2013-07-12 9:41 UTC (permalink / raw)
To: u-boot
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);
--
1.8.1.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: Use DIV_ROUND_UP instead of open-coded
2013-07-12 9:39 [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded Axel Lin
2013-07-12 9:41 ` [U-Boot] [PATCH 2/3] spi: fsl_espi: " Axel Lin
@ 2013-07-12 9:42 ` Axel Lin
2013-08-06 18:49 ` Jagan Teki
2013-07-15 7:58 ` [U-Boot] [PATCH 1/3] spi: bfin_spi: " Sonic Zhang
2 siblings, 1 reply; 8+ messages in thread
From: Axel Lin @ 2013-07-12 9:42 UTC (permalink / raw)
To: u-boot
Use DIV_ROUND_UP to simplify the code.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/spi/mpc8xxx_spi.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
index 6b0e3b4..c90c0ce 100644
--- a/drivers/spi/mpc8xxx_spi.c
+++ b/drivers/spi/mpc8xxx_spi.c
@@ -93,7 +93,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
{
volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
unsigned int tmpdout, tmpdin, event;
- int numBlks = bitlen / 32 + (bitlen % 32 ? 1 : 0);
+ int numBlks = DIV_ROUND_UP(bitlen, 32);
int tm, isRead = 0;
unsigned char charSize = 32;
--
1.8.1.2
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded
2013-07-12 9:39 [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded Axel Lin
2013-07-12 9:41 ` [U-Boot] [PATCH 2/3] spi: fsl_espi: " Axel Lin
2013-07-12 9:42 ` [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: " Axel Lin
@ 2013-07-15 7:58 ` Sonic Zhang
2 siblings, 0 replies; 8+ messages in thread
From: Sonic Zhang @ 2013-07-15 7:58 UTC (permalink / raw)
To: u-boot
Acked-by: Sonic Zhang <sonic.zhang@analog.com>
On Fri, Jul 12, 2013 at 5:39 PM, Axel Lin <axel.lin@ingics.com> wrote:
> Use DIV_ROUND_UP to simplify the code.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> drivers/spi/bfin_spi.c | 4 +---
> 1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/drivers/spi/bfin_spi.c b/drivers/spi/bfin_spi.c
> index a9a4d92..f7192c2 100644
> --- a/drivers/spi/bfin_spi.c
> +++ b/drivers/spi/bfin_spi.c
> @@ -144,10 +144,8 @@ void spi_set_speed(struct spi_slave *slave, uint hz)
> u32 baud;
>
> sclk = get_sclk();
> - baud = sclk / (2 * hz);
> /* baud should be rounded up */
> - if (sclk % (2 * hz))
> - baud += 1;
> + baud = DIV_ROUND_UP(sclk, 2 * hz);
> if (baud < 2)
> baud = 2;
> else if (baud > (u16)-1)
> --
> 1.8.1.2
>
>
>
> _______________________________________________
> U-Boot mailing list
> U-Boot at lists.denx.de
> http://lists.denx.de/mailman/listinfo/u-boot
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 2/3] spi: fsl_espi: Use DIV_ROUND_UP instead of open-coded
2013-07-12 9:41 ` [U-Boot] [PATCH 2/3] spi: fsl_espi: " Axel Lin
@ 2013-08-06 18:49 ` Jagan Teki
2013-08-06 18:56 ` Jagan Teki
0 siblings, 1 reply; 8+ messages in thread
From: Jagan Teki @ 2013-08-06 18:49 UTC (permalink / raw)
To: u-boot
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: Use DIV_ROUND_UP instead of open-coded
2013-07-12 9:42 ` [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: " Axel Lin
@ 2013-08-06 18:49 ` Jagan Teki
2013-08-06 18:55 ` Jagan Teki
0 siblings, 1 reply; 8+ messages in thread
From: Jagan Teki @ 2013-08-06 18:49 UTC (permalink / raw)
To: u-boot
On 12-07-2013 15:12, Axel Lin wrote:
> Use DIV_ROUND_UP to simplify the code.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
> ---
> drivers/spi/mpc8xxx_spi.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
> index 6b0e3b4..c90c0ce 100644
> --- a/drivers/spi/mpc8xxx_spi.c
> +++ b/drivers/spi/mpc8xxx_spi.c
> @@ -93,7 +93,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
> {
> volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
> unsigned int tmpdout, tmpdin, event;
> - int numBlks = bitlen / 32 + (bitlen % 32 ? 1 : 0);
> + int numBlks = DIV_ROUND_UP(bitlen, 32);
> int tm, isRead = 0;
> unsigned char charSize = 32;
>
>
Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
--
Thanks,
Jagan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: Use DIV_ROUND_UP instead of open-coded
2013-08-06 18:49 ` Jagan Teki
@ 2013-08-06 18:55 ` Jagan Teki
0 siblings, 0 replies; 8+ messages in thread
From: Jagan Teki @ 2013-08-06 18:55 UTC (permalink / raw)
To: u-boot
On 07-08-2013 00:19, Jagan Teki wrote:
> On 12-07-2013 15:12, Axel Lin wrote:
>> Use DIV_ROUND_UP to simplify the code.
>>
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>> ---
>> drivers/spi/mpc8xxx_spi.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/spi/mpc8xxx_spi.c b/drivers/spi/mpc8xxx_spi.c
>> index 6b0e3b4..c90c0ce 100644
>> --- a/drivers/spi/mpc8xxx_spi.c
>> +++ b/drivers/spi/mpc8xxx_spi.c
>> @@ -93,7 +93,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int
>> bitlen, const void *dout,
>> {
>> volatile spi8xxx_t *spi = &((immap_t *) (CONFIG_SYS_IMMR))->spi;
>> unsigned int tmpdout, tmpdin, event;
>> - int numBlks = bitlen / 32 + (bitlen % 32 ? 1 : 0);
>> + int numBlks = DIV_ROUND_UP(bitlen, 32);
>> int tm, isRead = 0;
>> unsigned char charSize = 32;
>>
>>
>
> Reviewed-by: Jagannadha Sutradharudu Teki <jagannadh.teki@gmail.com>
>
> --
> Thanks,
> Jagan.
Applied to u-boot-spi/master
--
Thanks,
Jagan.
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH 2/3] spi: fsl_espi: Use DIV_ROUND_UP instead of open-coded
2013-08-06 18:49 ` Jagan Teki
@ 2013-08-06 18:56 ` Jagan Teki
0 siblings, 0 replies; 8+ messages in thread
From: Jagan Teki @ 2013-08-06 18:56 UTC (permalink / raw)
To: u-boot
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2013-08-06 18:56 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-12 9:39 [U-Boot] [PATCH 1/3] spi: bfin_spi: Use DIV_ROUND_UP instead of open-coded Axel Lin
2013-07-12 9:41 ` [U-Boot] [PATCH 2/3] spi: fsl_espi: " Axel Lin
2013-08-06 18:49 ` Jagan Teki
2013-08-06 18:56 ` Jagan Teki
2013-07-12 9:42 ` [U-Boot] [PATCH 3/3] spi: mpc8xxx_spi: " Axel Lin
2013-08-06 18:49 ` Jagan Teki
2013-08-06 18:55 ` Jagan Teki
2013-07-15 7:58 ` [U-Boot] [PATCH 1/3] spi: bfin_spi: " Sonic Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox