* [PATCH] mmc: omap: Use DIV_ROUND_UP instead of open coded
@ 2013-09-01 7:07 Axel Lin
0 siblings, 0 replies; 4+ messages in thread
From: Axel Lin @ 2013-09-01 7:07 UTC (permalink / raw)
To: Chris Ball; +Cc: Lokesh Vutla, linux-omap, linux-mmc
This patch makes the intention of the code more clear.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/mmc/host/omap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index b94f38e..3187af0 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -189,7 +189,7 @@ static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
unsigned long tick_ns;
if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) {
- tick_ns = (1000000000 + slot->fclk_freq - 1) / slot->fclk_freq;
+ tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
ndelay(8 * tick_ns);
}
}
@@ -444,7 +444,7 @@ static void mmc_omap_send_stop_work(struct work_struct *work)
struct mmc_data *data = host->stop_data;
unsigned long tick_ns;
- tick_ns = (1000000000 + slot->fclk_freq - 1)/slot->fclk_freq;
+ tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
ndelay(8*tick_ns);
mmc_omap_start_command(host, data->stop);
@@ -486,7 +486,7 @@ mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops)
u16 stat = 0;
/* Sending abort takes 80 clocks. Have some extra and round up */
- timeout = (120*1000000 + slot->fclk_freq - 1)/slot->fclk_freq;
+ timeout = DIV_ROUND_UP(120 * 1000000, slot->fclk_freq);
restarts = 0;
while (restarts < maxloops) {
OMAP_MMC_WRITE(host, STAT, 0xFFFF);
@@ -686,8 +686,8 @@ mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
if (n > host->buffer_bytes_left)
n = host->buffer_bytes_left;
- nwords = n / 2;
- nwords += n & 1; /* handle odd number of bytes to transfer */
+ /* Round up to handle odd number of bytes to transfer */
+ nwords = DIV_ROUND_UP(n, 2);
host->buffer_bytes_left -= n;
host->total_bytes_left -= n;
--
1.8.1.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] mmc: omap: Use DIV_ROUND_UP instead of open coded
@ 2014-04-27 10:56 Axel Lin
2014-05-02 15:39 ` Tony Lindgren
0 siblings, 1 reply; 4+ messages in thread
From: Axel Lin @ 2014-04-27 10:56 UTC (permalink / raw)
To: Chris Ball, Ulf Hansson; +Cc: Jarkko Lavinen, linux-omap, linux-mmc
This also makes the intention more clear.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
---
drivers/mmc/host/omap.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
index 5c2e58b..711981e 100644
--- a/drivers/mmc/host/omap.c
+++ b/drivers/mmc/host/omap.c
@@ -177,7 +177,7 @@ static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
unsigned long tick_ns;
if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) {
- tick_ns = (1000000000 + slot->fclk_freq - 1) / slot->fclk_freq;
+ tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
ndelay(8 * tick_ns);
}
}
@@ -435,7 +435,7 @@ static void mmc_omap_send_stop_work(struct work_struct *work)
struct mmc_data *data = host->stop_data;
unsigned long tick_ns;
- tick_ns = (1000000000 + slot->fclk_freq - 1)/slot->fclk_freq;
+ tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
ndelay(8*tick_ns);
mmc_omap_start_command(host, data->stop);
@@ -477,7 +477,7 @@ mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops)
u16 stat = 0;
/* Sending abort takes 80 clocks. Have some extra and round up */
- timeout = (120*1000000 + slot->fclk_freq - 1)/slot->fclk_freq;
+ timeout = DIV_ROUND_UP(120 * 1000000, slot->fclk_freq);
restarts = 0;
while (restarts < maxloops) {
OMAP_MMC_WRITE(host, STAT, 0xFFFF);
@@ -677,8 +677,8 @@ mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
if (n > host->buffer_bytes_left)
n = host->buffer_bytes_left;
- nwords = n / 2;
- nwords += n & 1; /* handle odd number of bytes to transfer */
+ /* Round up to handle odd number of bytes to transfer */
+ nwords = DIV_ROUND_UP(n, 2);
host->buffer_bytes_left -= n;
host->total_bytes_left -= n;
--
1.8.3.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] mmc: omap: Use DIV_ROUND_UP instead of open coded
2014-04-27 10:56 Axel Lin
@ 2014-05-02 15:39 ` Tony Lindgren
2014-05-02 20:30 ` Joachim Eastwood
0 siblings, 1 reply; 4+ messages in thread
From: Tony Lindgren @ 2014-05-02 15:39 UTC (permalink / raw)
To: Axel Lin
Cc: Chris Ball, Ulf Hansson, Jarkko Lavinen, linux-omap, linux-mmc,
Jarkko Nikula
* Axel Lin <axel.lin@ingics.com> [140427 03:58]:
> This also makes the intention more clear.
>
> Signed-off-by: Axel Lin <axel.lin@ingics.com>
Added Jarkko Nikula to cc.
Tony
> ---
> drivers/mmc/host/omap.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
> index 5c2e58b..711981e 100644
> --- a/drivers/mmc/host/omap.c
> +++ b/drivers/mmc/host/omap.c
> @@ -177,7 +177,7 @@ static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
> unsigned long tick_ns;
>
> if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) {
> - tick_ns = (1000000000 + slot->fclk_freq - 1) / slot->fclk_freq;
> + tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
> ndelay(8 * tick_ns);
> }
> }
> @@ -435,7 +435,7 @@ static void mmc_omap_send_stop_work(struct work_struct *work)
> struct mmc_data *data = host->stop_data;
> unsigned long tick_ns;
>
> - tick_ns = (1000000000 + slot->fclk_freq - 1)/slot->fclk_freq;
> + tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
> ndelay(8*tick_ns);
>
> mmc_omap_start_command(host, data->stop);
> @@ -477,7 +477,7 @@ mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops)
> u16 stat = 0;
>
> /* Sending abort takes 80 clocks. Have some extra and round up */
> - timeout = (120*1000000 + slot->fclk_freq - 1)/slot->fclk_freq;
> + timeout = DIV_ROUND_UP(120 * 1000000, slot->fclk_freq);
> restarts = 0;
> while (restarts < maxloops) {
> OMAP_MMC_WRITE(host, STAT, 0xFFFF);
> @@ -677,8 +677,8 @@ mmc_omap_xfer_data(struct mmc_omap_host *host, int write)
> if (n > host->buffer_bytes_left)
> n = host->buffer_bytes_left;
>
> - nwords = n / 2;
> - nwords += n & 1; /* handle odd number of bytes to transfer */
> + /* Round up to handle odd number of bytes to transfer */
> + nwords = DIV_ROUND_UP(n, 2);
>
> host->buffer_bytes_left -= n;
> host->total_bytes_left -= n;
> --
> 1.8.3.2
>
>
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-omap" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] mmc: omap: Use DIV_ROUND_UP instead of open coded
2014-05-02 15:39 ` Tony Lindgren
@ 2014-05-02 20:30 ` Joachim Eastwood
0 siblings, 0 replies; 4+ messages in thread
From: Joachim Eastwood @ 2014-05-02 20:30 UTC (permalink / raw)
To: Tony Lindgren
Cc: Axel Lin, Chris Ball, Ulf Hansson, Jarkko Lavinen, linux-omap,
linux-mmc, Jarkko Nikula
On 2 May 2014 17:39, Tony Lindgren <tony@atomide.com> wrote:
> * Axel Lin <axel.lin@ingics.com> [140427 03:58]:
>> This also makes the intention more clear.
While you are at it you may want to use some nice defines from time.h
>> Signed-off-by: Axel Lin <axel.lin@ingics.com>
>
> Added Jarkko Nikula to cc.
>
> Tony
>
>> ---
>> drivers/mmc/host/omap.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/mmc/host/omap.c b/drivers/mmc/host/omap.c
>> index 5c2e58b..711981e 100644
>> --- a/drivers/mmc/host/omap.c
>> +++ b/drivers/mmc/host/omap.c
>> @@ -177,7 +177,7 @@ static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
>> unsigned long tick_ns;
>>
>> if (slot != NULL && slot->host->fclk_enabled && slot->fclk_freq > 0) {
>> - tick_ns = (1000000000 + slot->fclk_freq - 1) / slot->fclk_freq;
>> + tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
Use NSEC_PER_SEC from time.h
>> ndelay(8 * tick_ns);
>> }
>> }
>> @@ -435,7 +435,7 @@ static void mmc_omap_send_stop_work(struct work_struct *work)
>> struct mmc_data *data = host->stop_data;
>> unsigned long tick_ns;
>>
>> - tick_ns = (1000000000 + slot->fclk_freq - 1)/slot->fclk_freq;
>> + tick_ns = DIV_ROUND_UP(1000000000, slot->fclk_freq);
Same here NSEC_PER_SEC.
>> ndelay(8*tick_ns);
>> mmc_omap_start_command(host, data->stop);
>> @@ -477,7 +477,7 @@ mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops)
>> u16 stat = 0;
>>
>> /* Sending abort takes 80 clocks. Have some extra and round up */
>> - timeout = (120*1000000 + slot->fclk_freq - 1)/slot->fclk_freq;
>> + timeout = DIV_ROUND_UP(120 * 1000000, slot->fclk_freq);
USEC_PER_SEC from time.h
regards
Joachim Eastwood
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-02 20:30 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-01 7:07 [PATCH] mmc: omap: Use DIV_ROUND_UP instead of open coded Axel Lin
-- strict thread matches above, loose matches on Subject: below --
2014-04-27 10:56 Axel Lin
2014-05-02 15:39 ` Tony Lindgren
2014-05-02 20:30 ` Joachim Eastwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).