summaryrefslogtreecommitdiff
path: root/drivers/i2c/mvtwsi.c
diff options
context:
space:
mode:
authormario.six@gdsys.cc <mario.six@gdsys.cc>2016-07-21 11:57:09 +0200
committerHeiko Schocher <hs@denx.de>2016-07-26 10:20:05 +0200
commitf8a10ed1fd9986362a39f2b18d89429dfdb078cb (patch)
tree2366d6687fe4ac992040b668ce8a4fccd1222ace /drivers/i2c/mvtwsi.c
parent3c4db636ac918a35c4c6671e8d060e3a72ba7c94 (diff)
i2c: mvtwsi: Make address length variable
The length of the address parameter of the __twsi_i2c_read and __twsi_i2c_write functions is fixed to four bytes. As a final step in the preparation of the DM conversion, we make the length of this parameter variable by turning it into an array of bytes, and convert the 32 bit value that's passed to the legacy functions into a four-byte-array on the fly. Signed-off-by: Mario Six <mario.six@gdsys.cc> Reviewed-by: Stefan Roese <sr@denx.de>
Diffstat (limited to 'drivers/i2c/mvtwsi.c')
-rw-r--r--drivers/i2c/mvtwsi.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c
index 688efc2a23..3325c4bd46 100644
--- a/drivers/i2c/mvtwsi.c
+++ b/drivers/i2c/mvtwsi.c
@@ -423,7 +423,7 @@ static int __twsi_i2c_probe_chip(struct mvtwsi_registers *twsi, uchar chip)
* will be a repeated start without a preceding stop.
*/
static int __twsi_i2c_read(struct mvtwsi_registers *twsi, uchar chip,
- uint addr, int alen, uchar *data, int length)
+ u8 *addr, int alen, uchar *data, int length)
{
int status = 0;
int stop_status;
@@ -432,8 +432,7 @@ static int __twsi_i2c_read(struct mvtwsi_registers *twsi, uchar chip,
status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1));
/* Send address bytes */
while ((status == 0) && alen--)
- status = twsi_send(twsi, addr >> (8*alen),
- MVTWSI_STATUS_DATA_W_ACK);
+ status = twsi_send(twsi, *(addr++), MVTWSI_STATUS_DATA_W_ACK);
/* Begin i2c read to receive data bytes */
if (status == 0)
status = i2c_begin(twsi, MVTWSI_STATUS_REPEATED_START,
@@ -454,7 +453,7 @@ static int __twsi_i2c_read(struct mvtwsi_registers *twsi, uchar chip,
* Begin write, send address byte(s), send data bytes, end.
*/
static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip,
- uint addr, int alen, uchar *data, int length)
+ u8 *addr, int alen, uchar *data, int length)
{
int status, stop_status;
@@ -462,9 +461,8 @@ static int __twsi_i2c_write(struct mvtwsi_registers *twsi, uchar chip,
* data bytes */
status = i2c_begin(twsi, MVTWSI_STATUS_START, (chip << 1));
/* Send address bytes */
- while ((status == 0) && alen--)
- status = twsi_send(twsi, addr >> (8*alen),
- MVTWSI_STATUS_DATA_W_ACK);
+ while ((status == 0) && (alen-- > 0))
+ status = twsi_send(twsi, *(addr++), MVTWSI_STATUS_DATA_W_ACK);
/* Send data bytes */
while ((status == 0) && (length-- > 0))
status = twsi_send(twsi, *(data++), MVTWSI_STATUS_DATA_W_ACK);
@@ -498,14 +496,28 @@ static int twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr,
int alen, uchar *data, int length)
{
struct mvtwsi_registers *twsi = twsi_get_base(adap);
- return __twsi_i2c_read(twsi, chip, addr, alen, data, length);
+ u8 addr_bytes[4];
+
+ addr_bytes[0] = (addr >> 0) & 0xFF;
+ addr_bytes[1] = (addr >> 8) & 0xFF;
+ addr_bytes[2] = (addr >> 16) & 0xFF;
+ addr_bytes[3] = (addr >> 24) & 0xFF;
+
+ return __twsi_i2c_read(twsi, chip, addr_bytes, alen, data, length);
}
static int twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr,
int alen, uchar *data, int length)
{
struct mvtwsi_registers *twsi = twsi_get_base(adap);
- return __twsi_i2c_write(twsi, chip, addr, alen, data, length);
+ u8 addr_bytes[4];
+
+ addr_bytes[0] = (addr >> 0) & 0xFF;
+ addr_bytes[1] = (addr >> 8) & 0xFF;
+ addr_bytes[2] = (addr >> 16) & 0xFF;
+ addr_bytes[3] = (addr >> 24) & 0xFF;
+
+ return __twsi_i2c_write(twsi, chip, addr_bytes, alen, data, length);
}
#ifdef CONFIG_I2C_MVTWSI_BASE0