mirror of
https://github.com/Stichting-MINIX-Research-Foundation/u-boot.git
synced 2025-09-10 04:26:19 -04:00
Rewrite a series of goto statements as a sequences of
conditional expressions instead. Use consistent return code 0/-1 for good/bad indicators. Include one fewer file if the driver isn't used at all. Signed-off-by: Jon Loeliger <jdl@freescale.com>
This commit is contained in:
parent
7237c033b0
commit
4d45f69e36
@ -16,17 +16,15 @@
|
|||||||
* MA 02111-1307 USA
|
* MA 02111-1307 USA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <command.h>
|
|
||||||
|
|
||||||
#ifdef CONFIG_HARD_I2C
|
#ifdef CONFIG_HARD_I2C
|
||||||
|
|
||||||
|
#include <command.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
#include <asm/fsl_i2c.h>
|
#include <asm/fsl_i2c.h>
|
||||||
|
|
||||||
#define I2C_TIMEOUT (CFG_HZ / 4)
|
#define I2C_TIMEOUT (CFG_HZ / 4)
|
||||||
|
|
||||||
#define I2C ((struct fsl_i2c *)(CFG_IMMR + CFG_I2C_OFFSET))
|
#define I2C ((struct fsl_i2c *)(CFG_IMMR + CFG_I2C_OFFSET))
|
||||||
|
|
||||||
|
|
||||||
@ -170,24 +168,19 @@ i2c_read(u8 dev, uint addr, int alen, u8 *data, int length)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
u8 *a = (u8*)&addr;
|
u8 *a = (u8*)&addr;
|
||||||
|
|
||||||
if (i2c_wait4bus () < 0)
|
if (i2c_wait4bus() >= 0
|
||||||
goto exit;
|
&& i2c_write_addr(dev, I2C_WRITE, 0) != 0
|
||||||
|
&& __i2c_write(&a[4 - alen], alen) == alen
|
||||||
if (i2c_write_addr(dev, I2C_WRITE, 0) == 0)
|
&& i2c_write_addr(dev, I2C_READ, 1) != 0) {
|
||||||
goto exit;
|
|
||||||
|
|
||||||
if (__i2c_write(&a[4 - alen], alen) != alen)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
if (i2c_write_addr(dev, I2C_READ, 1) == 0)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
i = __i2c_read(data, length);
|
i = __i2c_read(data, length);
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
|
||||||
writeb(I2C_CR_MEN, &I2C->cr);
|
writeb(I2C_CR_MEN, &I2C->cr);
|
||||||
|
|
||||||
return !(i == length);
|
if (i == length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
@ -196,21 +189,18 @@ i2c_write(u8 dev, uint addr, int alen, u8 *data, int length)
|
|||||||
int i = 0;
|
int i = 0;
|
||||||
u8 *a = (u8*)&addr;
|
u8 *a = (u8*)&addr;
|
||||||
|
|
||||||
if (i2c_wait4bus() < 0)
|
if (i2c_wait4bus() >= 0
|
||||||
goto exit;
|
&& i2c_write_addr(dev, I2C_WRITE, 0) != 0
|
||||||
|
&& __i2c_write(&a[4 - alen], alen) == alen) {
|
||||||
if (i2c_write_addr(dev, I2C_WRITE, 0) == 0)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
if (__i2c_write(&a[4 - alen], alen) != alen)
|
|
||||||
goto exit;
|
|
||||||
|
|
||||||
i = __i2c_write(data, length);
|
i = __i2c_write(data, length);
|
||||||
|
}
|
||||||
|
|
||||||
exit:
|
|
||||||
writeb(I2C_CR_MEN, &I2C->cr);
|
writeb(I2C_CR_MEN, &I2C->cr);
|
||||||
|
|
||||||
return !(i == length);
|
if (i == length)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
Loading…
x
Reference in New Issue
Block a user