Skip to contentSkip to conversation

mmc: omap: Use DIV_ROUND_UP instead of open coded

PATCH Superseded Axel Lin 3 participants 3 messages Apr 27, 2014 – May 2, 2014

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/1 mmc: omap: Use DIV_ROUND_UP instead of open coded

This also makes the intention more clear.

---
 drivers/mmc/host/omap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mmc/host/omap.c +5 -5
index 5c2e58b..711981e 100644
@@ -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;
Signature · 1 line
1.8.3.2
#1 lore raw
Quoted 3 lines · Axel Lin

This also makes the intention more clear.

Added Jarkko Nikula to cc.

Tony

Quoted 55 lines
---
 drivers/mmc/host/omap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mmc/host/omap.c +5 -5
index 5c2e58b..711981e 100644
@@ -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;
Signature · 8 lines
1.8.3.2



--
To unsubscribe from this list: send the line "unsubscribe linux-omap" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#2 lore raw
Quoted 2 lines · Tony Lindgren
Quoted 1 line · Axel Lin

This also makes the intention more clear.

While you are at it you may want to use some nice defines from time.h

Quoted 17 lines
Quoted 1 line

Added Jarkko Nikula to cc.

Tony

Quoted 11 lines
---
 drivers/mmc/host/omap.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/mmc/host/omap.c +0 -0
index 5c2e58b..711981e 100644
@@ -177,7 +177,7 @@ static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot)
      unsigned long tick_ns;
 
Quoted 3 lines

drivers/mmc/host/omap.c static void mmc_omap_fclk_offdelay(struct mmc_omap_slot *slot) · line 180

Quoted 3 lines
drivers/mmc/host/omap.c +1 -1
      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

Quoted 9 lines

drivers/mmc/host/omap.c static void mmc_omap_send_stop_work(struct work_struct *work) · line 438

Quoted 9 lines
drivers/mmc/host/omap.c +1 -1
              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.

Quoted 8 lines

drivers/mmc/host/omap.c mmc_omap_send_abort(struct mmc_omap_host *host, int maxloops) · line 480

Quoted 8 lines
drivers/mmc/host/omap.c +1 -1
      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