diff options
author | Troy Kisky <troy.kisky@boundarydevices.com> | 2012-07-19 08:18:06 +0000 |
---|---|---|
committer | Heiko Schocher <hs@denx.de> | 2012-07-31 07:42:58 +0200 |
commit | b230ddc267be2b9166421869549882d15b92e2ff (patch) | |
tree | 26324175039988766e605e42375679931b451fdc | |
parent | ea572d853eb03c6ac2021c21aae60891b5f92655 (diff) | |
download | u-boot-imx-b230ddc267be2b9166421869549882d15b92e2ff.zip u-boot-imx-b230ddc267be2b9166421869549882d15b92e2ff.tar.gz u-boot-imx-b230ddc267be2b9166421869549882d15b92e2ff.tar.bz2 |
mxc_i2c: create i2c_init_transfer
Initial code of i2c_read and i2c_write
is identical, move to subroutine.
Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
Acked-by: Marek Vasut <marex@denx.de>
Acked-by: Stefano Babic <sbabic@denx.de>
-rw-r--r-- | drivers/i2c/mxc_i2c.c | 44 |
1 files changed, 18 insertions, 26 deletions
diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c index 57027ad..4ce695a 100644 --- a/drivers/i2c/mxc_i2c.c +++ b/drivers/i2c/mxc_i2c.c @@ -275,19 +275,29 @@ void i2c_imx_stop(void) } /* - * Write register address + * Send start signal, chip address and + * write register address */ -int i2c_imx_set_reg_addr(uint addr, int alen) +static int i2c_init_transfer(struct mxc_i2c_regs *i2c_regs, + uchar chip, uint addr, int alen) { - struct mxc_i2c_regs *i2c_regs = (struct mxc_i2c_regs *)I2C_BASE; - int ret = 0; + int ret = i2c_imx_start(); + if (ret) + goto exit; + + /* write slave address */ + ret = tx_byte(i2c_regs, chip << 1); + if (ret < 0) + goto exit; while (alen--) { ret = tx_byte(i2c_regs, (addr >> (alen * 8)) & 0xff); if (ret < 0) - break; + goto exit; } - + return 0; +exit: + i2c_imx_stop(); return ret; } @@ -318,19 +328,10 @@ int i2c_read(uchar chip, uint addr, int alen, uchar *buf, int len) unsigned int temp; int i; - ret = i2c_imx_start(); - if (ret) - return ret; - - /* write slave address */ - ret = tx_byte(i2c_regs, chip << 1); + ret = i2c_init_transfer(i2c_regs, chip, addr, alen); if (ret < 0) return ret; - ret = i2c_imx_set_reg_addr(addr, alen); - if (ret) - return ret; - temp = readb(&i2c_regs->i2cr); temp |= I2CR_RSTA; writeb(temp, &i2c_regs->i2cr); @@ -387,19 +388,10 @@ int i2c_write(uchar chip, uint addr, int alen, uchar *buf, int len) int ret; int i; - ret = i2c_imx_start(); - if (ret) - return ret; - - /* write slave address */ - ret = tx_byte(i2c_regs, chip << 1); + ret = i2c_init_transfer(i2c_regs, chip, addr, alen); if (ret < 0) return ret; - ret = i2c_imx_set_reg_addr(addr, alen); - if (ret) - return ret; - for (i = 0; i < len; i++) { ret = tx_byte(i2c_regs, buf[i]); if (ret < 0) |