Removed CHECK_NACK macro from Davinci I2C driver for code cleanup.

Signed-off-by: Sergey Kubushyn <k...@koi8.net>
---
 cpu/arm926ejs/davinci/i2c.c |   62 +++++++++++++++++++++++++---------
 1 files changed, 45 insertions(+), 17 deletions(-)

diff --git a/cpu/arm926ejs/davinci/i2c.c b/cpu/arm926ejs/davinci/i2c.c
index 3ba20ef..f48aae2 100644
--- a/cpu/arm926ejs/davinci/i2c.c
+++ b/cpu/arm926ejs/davinci/i2c.c
@@ -32,14 +32,6 @@
 #include <asm/arch/hardware.h>
 #include <asm/arch/i2c_defs.h>
 
-#define CHECK_NACK() \
-       do {\
-               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {\
-                       REG(I2C_CON) = 0;\
-                       return(1);\
-               }\
-       } while (0)
-
 
 static int wait_for_bus(void)
 {
@@ -179,7 +171,11 @@ int i2c_read(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
 
                tmp = poll_i2c_irq(I2C_STAT_XRDY | I2C_STAT_NACK);
 
-               CHECK_NACK();
+               /* Check for NACK */
+               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                       REG(I2C_CON) = 0;
+                       return(1);
+               }
 
                switch (alen) {
                        case 2:
@@ -193,7 +189,11 @@ int i2c_read(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
 
                                tmp = poll_i2c_irq(I2C_STAT_XRDY | 
I2C_STAT_NACK);
 
-                               CHECK_NACK();
+                               /* Check for NACK */
+                               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                                       REG(I2C_CON) = 0;
+                                       return(1);
+                               }
                                /* No break, fall through */
                        case 1:
                                /* Send address LSByte */
@@ -206,7 +206,11 @@ int i2c_read(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
 
                                tmp = poll_i2c_irq(I2C_STAT_XRDY | 
I2C_STAT_NACK | I2C_STAT_ARDY);
 
-                               CHECK_NACK();
+                               /* Check for NACK */
+                               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                                       REG(I2C_CON) = 0;
+                                       return(1);
+                               }
 
                                if (!(tmp & I2C_STAT_ARDY)) {
                                        REG(I2C_CON) = 0;
@@ -224,7 +228,11 @@ int i2c_read(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
        for (i = 0; i < len; i++) {
                tmp = poll_i2c_irq(I2C_STAT_RRDY | I2C_STAT_NACK | 
I2C_STAT_ROVR);
 
-               CHECK_NACK();
+               /* Check for NACK */
+               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                       REG(I2C_CON) = 0;
+                       return(1);
+               }
 
                if (tmp & I2C_STAT_RRDY) {
                        buf[i] = REG(I2C_DRR);
@@ -236,7 +244,11 @@ int i2c_read(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
 
        tmp = poll_i2c_irq(I2C_STAT_SCD | I2C_STAT_NACK);
 
-       CHECK_NACK();
+       /* Check for NACK */
+       if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+               REG(I2C_CON) = 0;
+               return(1);
+       }
 
        if (!(tmp & I2C_STAT_SCD)) {
                REG(I2C_CON) = 0;
@@ -279,7 +291,11 @@ int i2c_write(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
                        /* Send address MSByte */
                        tmp = poll_i2c_irq(I2C_STAT_XRDY | I2C_STAT_NACK);
 
-                       CHECK_NACK();
+                       /* Check for NACK */
+                       if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                               REG(I2C_CON) = 0;
+                               return(1);
+                       }
 
                        if (tmp & I2C_STAT_XRDY) {
                                REG(I2C_DXR) = (addr >> 8) & 0xff;
@@ -292,7 +308,11 @@ int i2c_write(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
                        /* Send address LSByte */
                        tmp = poll_i2c_irq(I2C_STAT_XRDY | I2C_STAT_NACK);
 
-                       CHECK_NACK();
+                       /* Check for NACK */
+                       if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                               REG(I2C_CON) = 0;
+                               return(1);
+                       }
 
                        if (tmp & I2C_STAT_XRDY) {
                                REG(I2C_DXR) = addr & 0xff;
@@ -305,7 +325,11 @@ int i2c_write(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
        for (i = 0; i < len; i++) {
                tmp = poll_i2c_irq(I2C_STAT_XRDY | I2C_STAT_NACK);
 
-               CHECK_NACK();
+               /* Check for NACK */
+               if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+                       REG(I2C_CON) = 0;
+                       return(1);
+               }
 
                if (tmp & I2C_STAT_XRDY) {
                        REG(I2C_DXR) = buf[i];
@@ -316,7 +340,11 @@ int i2c_write(u_int8_t chip, u_int32_t addr, int alen, 
u_int8_t *buf, int len)
 
        tmp = poll_i2c_irq(I2C_STAT_SCD | I2C_STAT_NACK);
 
-       CHECK_NACK();
+       /* Check for NACK */
+       if (tmp & (I2C_TIMEOUT | I2C_STAT_NACK)) {
+               REG(I2C_CON) = 0;
+               return(1);
+       }
 
        if (!(tmp & I2C_STAT_SCD)) {
                REG(I2C_CON) = 0;
_______________________________________________
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

Reply via email to