Skip to content

Commit

Permalink
hw/misc/auxbus: Replace 'is_write' boolean by its value
Browse files Browse the repository at this point in the history
Remove the 'is_write' boolean by directly using its value in place.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
  • Loading branch information
philmd authored and cminyard committed Jun 17, 2021
1 parent ab9f59f commit b557df1
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions hw/misc/auxbus.c
Expand Up @@ -106,7 +106,6 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
AUXReply ret = AUX_NACK;
I2CBus *i2c_bus = aux_get_i2c_bus(bus);
size_t i;
bool is_write = false;

DPRINTF("request at address 0x%" PRIX32 ", command %u, len %u\n", address,
cmd, len);
Expand All @@ -117,11 +116,10 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
*/
case WRITE_AUX:
case READ_AUX:
is_write = cmd == READ_AUX ? false : true;
for (i = 0; i < len; i++) {
if (!address_space_rw(&bus->aux_addr_space, address++,
MEMTXATTRS_UNSPECIFIED, data++, 1,
is_write)) {
cmd == WRITE_AUX)) {
ret = AUX_I2C_ACK;
} else {
ret = AUX_NACK;
Expand All @@ -133,19 +131,18 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
* Classic I2C transactions..
*/
case READ_I2C:
is_write = cmd == READ_I2C ? false : true;
if (i2c_bus_busy(i2c_bus)) {
i2c_end_transfer(i2c_bus);
}

if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, true)) {
ret = AUX_I2C_NACK;
break;
}

ret = AUX_I2C_ACK;
while (len > 0) {
if (i2c_send_recv(i2c_bus, data++, is_write) < 0) {
if (i2c_send_recv(i2c_bus, data++, false) < 0) {
ret = AUX_I2C_NACK;
break;
}
Expand All @@ -154,19 +151,18 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
i2c_end_transfer(i2c_bus);
break;
case WRITE_I2C:
is_write = cmd == READ_I2C ? false : true;
if (i2c_bus_busy(i2c_bus)) {
i2c_end_transfer(i2c_bus);
}

if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, false)) {
ret = AUX_I2C_NACK;
break;
}

ret = AUX_I2C_ACK;
while (len > 0) {
if (i2c_send_recv(i2c_bus, data++, is_write) < 0) {
if (i2c_send_recv(i2c_bus, data++, true) < 0) {
ret = AUX_I2C_NACK;
break;
}
Expand All @@ -183,13 +179,12 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
* - We changed the address.
*/
case WRITE_I2C_MOT:
is_write = cmd == READ_I2C_MOT ? false : true;
ret = AUX_I2C_NACK;
if (!i2c_bus_busy(i2c_bus)) {
/*
* No transactions started..
*/
if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, false)) {
break;
}
} else if ((address != bus->last_i2c_address) ||
Expand All @@ -198,15 +193,15 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
* Transaction started but we need to restart..
*/
i2c_end_transfer(i2c_bus);
if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, false)) {
break;
}
}

bus->last_transaction = cmd;
bus->last_i2c_address = address;
while (len > 0) {
if (i2c_send_recv(i2c_bus, data++, is_write) < 0) {
if (i2c_send_recv(i2c_bus, data++, true) < 0) {
i2c_end_transfer(i2c_bus);
break;
}
Expand All @@ -217,13 +212,12 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
}
break;
case READ_I2C_MOT:
is_write = cmd == READ_I2C_MOT ? false : true;
ret = AUX_I2C_NACK;
if (!i2c_bus_busy(i2c_bus)) {
/*
* No transactions started..
*/
if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, true)) {
break;
}
} else if ((address != bus->last_i2c_address) ||
Expand All @@ -232,15 +226,15 @@ AUXReply aux_request(AUXBus *bus, AUXCommand cmd, uint32_t address,
* Transaction started but we need to restart..
*/
i2c_end_transfer(i2c_bus);
if (i2c_start_transfer(i2c_bus, address, !is_write)) {
if (i2c_start_transfer(i2c_bus, address, true)) {
break;
}
}

bus->last_transaction = cmd;
bus->last_i2c_address = address;
while (len > 0) {
if (i2c_send_recv(i2c_bus, data++, is_write) < 0) {
if (i2c_send_recv(i2c_bus, data++, false) < 0) {
i2c_end_transfer(i2c_bus);
break;
}
Expand Down

0 comments on commit b557df1

Please sign in to comment.