Skip to contentSkip to conversation

spi: cf_qspi: Use DIV_ROUND_UP at appropriate place

PATCH New Axel Lin 3 participants 7 messages Jun 14, 2013

Subsystems (2)
lore
Share & tools
lore

Axel Lin

author
#0 lore raw

PATCH 1/2 spi: cf_qspi: Use DIV_ROUND_UP at appropriate place

This change slightly improves readability.

---
 drivers/spi/cf_qspi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/cf_qspi.c +1 -1
index a37ac4e..06bcf91 100644
@@ -171,7 +171,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 	volatile qspi_t *qspi = dev->regs;
 	u8 *txbuf = (u8 *)dout;
 	u8 *rxbuf = (u8 *)din;
-	u32 count = ((bitlen / 8) + (bitlen % 8 ? 1 : 0));
+	u32 count = DIV_ROUND_UP(bitlen, 8);
 	u32 n, i = 0;
 
 	/* Sanitize arguments */
Signature · 1 line
1.8.1.2
author
#1 lore raw

PATCH 2/2 spi: mxc_spi: Use DIV_ROUND_UP at appropriate places

This change slightly improves readability.

---
 drivers/spi/mxc_spi.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/mxc_spi.c +3 -3
index 5bed858..2ea3228 100644
@@ -224,7 +224,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
 	const u8 *dout, u8 *din, unsigned long flags)
 {
 	struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
-	int nbytes = (bitlen + 7) / 8;
+	int nbytes = DIV_ROUND_UP(bitlen, 8);
 	u32 data, cnt, i;
 	struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
 
@@ -294,7 +294,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
 	/* Transfer completed, clear any pending request */
 	reg_write(&regs->stat, MXC_CSPICTRL_TC | MXC_CSPICTRL_RXOVF);
 
-	nbytes = (bitlen + 7) / 8;
+	nbytes = DIV_ROUND_UP(bitlen, 8);
 
 	cnt = nbytes % 32;
 
@@ -330,7 +330,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
 int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
 		void *din, unsigned long flags)
 {
-	int n_bytes = (bitlen + 7) / 8;
+	int n_bytes = DIV_ROUND_UP(bitlen, 8);
 	int n_bits;
 	int ret;
 	u32 blk_size;
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH 2/2 spi: mxc_spi: Use DIV_ROUND_UP at appropriate places

Quoted 31 lines · Axel Lin

This change slightly improves readability.

---
  drivers/spi/mxc_spi.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/mxc_spi.c +2 -2
index 5bed858..2ea3228 100644
@@ -224,7 +224,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
  	const u8 *dout, u8 *din, unsigned long flags)
  {
  	struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
-	int nbytes = (bitlen + 7) / 8;
+	int nbytes = DIV_ROUND_UP(bitlen, 8);
  	u32 data, cnt, i;
  	struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
 
@@ -294,7 +294,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
  	/* Transfer completed, clear any pending request */
  	reg_write(&regs->stat, MXC_CSPICTRL_TC | MXC_CSPICTRL_RXOVF);
 
-	nbytes = (bitlen + 7) / 8;
+	nbytes = DIV_ROUND_UP(bitlen, 8);
 
  	cnt = nbytes % 32;
 

drivers/spi/mxc_spi.c int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen, · line 336

Quoted 8 lines
drivers/spi/mxc_spi.c +1 -1
@@ -330,7 +330,7 @@ int spi_xchg_single(struct spi_slave *slave, unsigned int bitlen,
  int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
  		void *din, unsigned long flags)
  {
-	int n_bytes = (bitlen + 7) / 8;
+	int n_bytes = DIV_ROUND_UP(bitlen, 8);
  	int n_bits;
  	int ret;
  	u32 blk_size;

--
Thanks,
Jagan.

#3 lore raw

PATCH 2/2 spi: mxc_spi: Use DIV_ROUND_UP at appropriate places

Quoted 32 lines · Jagan Teki
Quoted 31 lines · Axel Lin

This change slightly improves readability.

---
  drivers/spi/mxc_spi.c | 6 +++---
  1 file changed, 3 insertions(+), 3 deletions(-)
drivers/spi/mxc_spi.c +2 -2
index 5bed858..2ea3228 100644
@@ -224,7 +224,7 @@ int spi_xchg_single(struct spi_slave *slave,
 unsigned int bitlen,
      const u8 *dout, u8 *din, unsigned long flags)
  {
      struct mxc_spi_slave *mxcs = to_mxc_spi_slave(slave);
-    int nbytes = (bitlen + 7) / 8;
+    int nbytes = DIV_ROUND_UP(bitlen, 8);
      u32 data, cnt, i;
      struct cspi_regs *regs = (struct cspi_regs *)mxcs->base;
@@ -294,7 +294,7 @@ int spi_xchg_single(struct spi_slave *slave,
 unsigned int bitlen,
      /* Transfer completed, clear any pending request */
      reg_write(&regs->stat, MXC_CSPICTRL_TC | MXC_CSPICTRL_RXOVF);
 
-    nbytes = (bitlen + 7) / 8;
+    nbytes = DIV_ROUND_UP(bitlen, 8);
 
      cnt = nbytes % 32;
Quoted 14 lines
Quoted 9 lines
drivers/spi/mxc_spi.c +1 -1
@@ -330,7 +330,7 @@ int spi_xchg_single(struct spi_slave *slave,
 unsigned int bitlen,
  int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const
 void *dout,
          void *din, unsigned long flags)
  {
-    int n_bytes = (bitlen + 7) / 8;
+    int n_bytes = DIV_ROUND_UP(bitlen, 8);
      int n_bits;
Quoted 3 lines
      int ret;
      u32 blk_size;

Applied to u-boot-spi/master

--
Thanks,
Jagan.

#4 lore raw

PATCH 1/2 spi: cf_qspi: Use DIV_ROUND_UP at appropriate place

In reply to Axel Lin
Quoted 12 lines · Axel Lin

This change slightly improves readability.

---
  drivers/spi/cf_qspi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/cf_qspi.c +0 -0
index a37ac4e..06bcf91 100644

drivers/spi/cf_qspi.c int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout, · line 177

Quoted 8 lines
drivers/spi/cf_qspi.c +1 -1
@@ -171,7 +171,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen, const void *dout,
  	volatile qspi_t *qspi = dev->regs;
  	u8 *txbuf = (u8 *)dout;
  	u8 *rxbuf = (u8 *)din;
-	u32 count = ((bitlen / 8) + (bitlen % 8 ? 1 : 0));
+	u32 count = DIV_ROUND_UP(bitlen, 8);
  	u32 n, i = 0;
 
  	/* Sanitize arguments */

ACK. Thanks for the cleanup.

#5 lore raw

PATCH 1/2 spi: cf_qspi: Use DIV_ROUND_UP at appropriate place

Quoted 21 lines · Richard Retanubun
Quoted 20 lines · Axel Lin

This change slightly improves readability.

---
  drivers/spi/cf_qspi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/cf_qspi.c +1 -1
index a37ac4e..06bcf91 100644
@@ -171,7 +171,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int
 bitlen, const void *dout,
      volatile qspi_t *qspi = dev->regs;
      u8 *txbuf = (u8 *)dout;
      u8 *rxbuf = (u8 *)din;
-    u32 count = ((bitlen / 8) + (bitlen % 8 ? 1 : 0));
+    u32 count = DIV_ROUND_UP(bitlen, 8);
      u32 n, i = 0;
 
Quoted 4 lines
Quoted 1 line
      /* Sanitize arguments */

ACK. Thanks for the cleanup.

--
Thanks,
Jagan.

#6 lore raw

PATCH 1/2 spi: cf_qspi: Use DIV_ROUND_UP at appropriate place

Quoted 22 lines · Jagan Teki
Quoted 21 lines · Richard Retanubun
Quoted 20 lines · Axel Lin

This change slightly improves readability.

---
  drivers/spi/cf_qspi.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/spi/cf_qspi.c +1 -1
index a37ac4e..06bcf91 100644
@@ -171,7 +171,7 @@ int spi_xfer(struct spi_slave *slave, unsigned int
 bitlen, const void *dout,
      volatile qspi_t *qspi = dev->regs;
      u8 *txbuf = (u8 *)dout;
      u8 *rxbuf = (u8 *)din;
-    u32 count = ((bitlen / 8) + (bitlen % 8 ? 1 : 0));
+    u32 count = DIV_ROUND_UP(bitlen, 8);
      u32 n, i = 0;
 
Quoted 6 lines
Quoted 4 lines
Quoted 1 line
      /* Sanitize arguments */

ACK. Thanks for the cleanup.

Applied to u-boot-spi/master

--
Thanks,
Jagan.