From 059fce9f61fd81ab67555b9ba87e12cc4b8db8f6 Mon Sep 17 00:00:00 2001 From: "mario.six@gdsys.cc" Date: Thu, 21 Jul 2016 11:57:05 +0200 Subject: i2c: mvtwsi: Get rid of status parameter The twsi_stop function contains a parameter "status," which is used to pass in the current exit status of the function calling twsi_stop, and either return this status unchanged if it indicates an error, or return twsi_stop's exit status if it does not indicate an error. While not massively complicated, this adds another purpose to the twsi_stop function, which should have the sole purpose of asserting a STOP condition on the bus (and not manage the exit status of its caller). Therefore, we move the exit status management into the caller functions by introducing a "stop_status" variable and returning either the status before the twsi_stop call (kept in the "status" variable), or the status from the twsi_stop call, depending on which indicates an error. Signed-off-by: Mario Six Reviewed-by: Stefan Roese --- drivers/i2c/mvtwsi.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'drivers/i2c') diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c index 4a34eab..d0e3c3f 100644 --- a/drivers/i2c/mvtwsi.c +++ b/drivers/i2c/mvtwsi.c @@ -290,10 +290,11 @@ static int twsi_recv(struct i2c_adapter *adap, u8 *byte, int ack_flag) * Assert the STOP condition. * This is also used to force the bus back to idle (SDA = SCL = 1). */ -static int twsi_stop(struct i2c_adapter *adap, int status) +static int twsi_stop(struct i2c_adapter *adap) { struct mvtwsi_registers *twsi = twsi_get_base(adap); int control, stop_status; + int status = 0; int timeout = 1000; /* Assert STOP */ @@ -308,10 +309,8 @@ static int twsi_stop(struct i2c_adapter *adap, int status) } while (timeout--); control = readl(&twsi->control); if (stop_status != MVTWSI_STATUS_IDLE) - if (status == 0) - status = mvtwsi_error( - MVTWSI_ERROR_TIMEOUT, - control, status, MVTWSI_STATUS_IDLE); + status = mvtwsi_error(MVTWSI_ERROR_TIMEOUT, + control, status, MVTWSI_STATUS_IDLE); return status; } @@ -379,7 +378,7 @@ static void twsi_i2c_init(struct i2c_adapter *adap, int speed, int slaveadd) writel(slaveadd, &twsi->slave_address); writel(0, &twsi->xtnd_slave_addr); /* Assert STOP, but don't care for the result */ - (void) twsi_stop(adap, 0); + (void) twsi_stop(adap); } /* @@ -420,7 +419,7 @@ static int twsi_i2c_probe(struct i2c_adapter *adap, uchar chip) if (status == 0) status = twsi_recv(adap, &dummy_byte, MVTWSI_READ_NAK); /* Stop transaction */ - twsi_stop(adap, 0); + twsi_stop(adap); /* Return 0, or the status of the first failure */ return status; } @@ -436,7 +435,8 @@ static int twsi_i2c_probe(struct i2c_adapter *adap, uchar chip) static int twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *data, int length) { - int status; + int status = 0; + int stop_status; /* Begin i2c write to send the address bytes */ status = i2c_begin(adap, MVTWSI_STATUS_START, (chip << 1)); @@ -455,9 +455,9 @@ static int twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, length > 0 ? MVTWSI_READ_ACK : MVTWSI_READ_NAK); /* Stop transaction */ - status = twsi_stop(adap, status); + stop_status = twsi_stop(adap); /* Return 0, or the status of the first failure */ - return status; + return status != 0 ? status : stop_status; } /* @@ -466,7 +466,7 @@ static int twsi_i2c_read(struct i2c_adapter *adap, uchar chip, uint addr, static int twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, int alen, uchar *data, int length) { - int status; + int status, stop_status; /* Begin i2c write to send first the address bytes, then the * data bytes */ @@ -479,9 +479,9 @@ static int twsi_i2c_write(struct i2c_adapter *adap, uchar chip, uint addr, while ((status == 0) && (length-- > 0)) status = twsi_send(adap, *(data++), MVTWSI_STATUS_DATA_W_ACK); /* Stop transaction */ - status = twsi_stop(adap, status); + stop_status = twsi_stop(adap); /* Return 0, or the status of the first failure */ - return status; + return status != 0 ? status : stop_status; } #ifdef CONFIG_I2C_MVTWSI_BASE0 -- cgit v1.1