[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v7 6/8] i2c: Match parameters of i2c_start_transfer and i2c_send_
From: |
BALATON Zoltan |
Subject: |
[PATCH v7 6/8] i2c: Match parameters of i2c_start_transfer and i2c_send_recv |
Date: |
Mon, 29 Jun 2020 20:55:26 +0200 |
These functions have a parameter that decides the direction of
transfer but totally confusingly they don't match but inverted sense.
To avoid frequent mistakes when using these functions change
i2c_send_recv to match i2c_start_transfer. Also use bool in
i2c_start_transfer instead of int to match i2c_send_recv.
Signed-off-by: BALATON Zoltan <balaton@eik.bme.hu>
---
This probably won't be the solution accepted as Philippe has an
alternative series fixing this problem here:
https://lists.nongnu.org/archive/html/qemu-devel/2020-06/msg07022.html
but until that or something else is merged this will do for the next
patch. When this gets sorted out I'll send a rebased version.
hw/display/sm501.c | 2 +-
hw/i2c/core.c | 34 +++++++++++++++++-----------------
hw/i2c/ppc4xx_i2c.c | 2 +-
include/hw/i2c/i2c.h | 4 ++--
4 files changed, 21 insertions(+), 21 deletions(-)
diff --git a/hw/display/sm501.c b/hw/display/sm501.c
index a7fc08c52b..e714674681 100644
--- a/hw/display/sm501.c
+++ b/hw/display/sm501.c
@@ -1041,7 +1041,7 @@ static void sm501_i2c_write(void *opaque, hwaddr addr,
uint64_t value,
s->i2c_byte_count + 1, s->i2c_addr >> 1);
for (i = 0; i <= s->i2c_byte_count; i++) {
res = i2c_send_recv(s->i2c_bus, &s->i2c_data[i],
- !(s->i2c_addr & 1));
+ s->i2c_addr & 1);
if (res) {
SM501_DPRINTF("sm501 i2c : transfer failed"
" i=%d, res=%d\n", i, res);
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index acf34a12d6..0303fefeaf 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -91,7 +91,7 @@ int i2c_bus_busy(I2CBus *bus)
* without releasing the bus. If that fails, the bus is still
* in a transaction.
*/
-int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv)
+int i2c_start_transfer(I2CBus *bus, uint8_t address, bool recv)
{
BusChild *kid;
I2CSlaveClass *sc;
@@ -175,26 +175,14 @@ void i2c_end_transfer(I2CBus *bus)
bus->broadcast = false;
}
-int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
+int i2c_send_recv(I2CBus *bus, uint8_t *data, bool recv)
{
I2CSlaveClass *sc;
I2CSlave *s;
I2CNode *node;
int ret = 0;
- if (send) {
- QLIST_FOREACH(node, &bus->current_devs, next) {
- s = node->elt;
- sc = I2C_SLAVE_GET_CLASS(s);
- if (sc->send) {
- trace_i2c_send(s->address, *data);
- ret = ret || sc->send(s, *data);
- } else {
- ret = -1;
- }
- }
- return ret ? -1 : 0;
- } else {
+ if (recv) {
ret = 0xff;
if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) {
sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
@@ -206,19 +194,31 @@ int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
}
*data = ret;
return 0;
+ } else {
+ QLIST_FOREACH(node, &bus->current_devs, next) {
+ s = node->elt;
+ sc = I2C_SLAVE_GET_CLASS(s);
+ if (sc->send) {
+ trace_i2c_send(s->address, *data);
+ ret = ret || sc->send(s, *data);
+ } else {
+ ret = -1;
+ }
+ }
+ return ret ? -1 : 0;
}
}
int i2c_send(I2CBus *bus, uint8_t data)
{
- return i2c_send_recv(bus, &data, true);
+ return i2c_send_recv(bus, &data, false);
}
uint8_t i2c_recv(I2CBus *bus)
{
uint8_t data = 0xff;
- i2c_send_recv(bus, &data, false);
+ i2c_send_recv(bus, &data, true);
return data;
}
diff --git a/hw/i2c/ppc4xx_i2c.c b/hw/i2c/ppc4xx_i2c.c
index c0a8e04567..d3899203a4 100644
--- a/hw/i2c/ppc4xx_i2c.c
+++ b/hw/i2c/ppc4xx_i2c.c
@@ -239,7 +239,7 @@ static void ppc4xx_i2c_writeb(void *opaque, hwaddr addr,
uint64_t value,
}
}
if (!(i2c->sts & IIC_STS_ERR) &&
- i2c_send_recv(i2c->bus, &i2c->mdata[i], !recv)) {
+ i2c_send_recv(i2c->bus, &i2c->mdata[i], recv)) {
i2c->sts |= IIC_STS_ERR;
i2c->extsts |= IIC_EXTSTS_XFRA;
break;
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index d6e3d85faf..ad2475d6a2 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -72,10 +72,10 @@ struct I2CBus {
I2CBus *i2c_init_bus(DeviceState *parent, const char *name);
void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
int i2c_bus_busy(I2CBus *bus);
-int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv);
+int i2c_start_transfer(I2CBus *bus, uint8_t address, bool recv);
void i2c_end_transfer(I2CBus *bus);
void i2c_nack(I2CBus *bus);
-int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send);
+int i2c_send_recv(I2CBus *bus, uint8_t *data, bool recv);
int i2c_send(I2CBus *bus, uint8_t data);
uint8_t i2c_recv(I2CBus *bus);
--
2.21.3
- [PATCH v7 0/8] Mac Old World ROM experiment, BALATON Zoltan, 2020/06/29
- [PATCH v7 4/8] mac_oldworld: Drop some variables, BALATON Zoltan, 2020/06/29
- [PATCH v7 3/8] mac_oldworld: Drop a variable, use get_system_memory() directly, BALATON Zoltan, 2020/06/29
- [PATCH v7 2/8] mac_newworld: Allow loading binary ROM image, BALATON Zoltan, 2020/06/29
- [PATCH v7 1/8] mac_oldworld: Allow loading binary ROM image, BALATON Zoltan, 2020/06/29
- [PATCH v7 5/8] mac_oldworld: Change PCI address of macio to match real hardware, BALATON Zoltan, 2020/06/29
- [PATCH v7 8/8] mac_oldworld: Add SPD data to cover RAM, BALATON Zoltan, 2020/06/29
- [PATCH v7 6/8] i2c: Match parameters of i2c_start_transfer and i2c_send_recv,
BALATON Zoltan <=
- [RFC PATCH v7 7/8] WIP macio/cuda: Attempt to add i2c support, BALATON Zoltan, 2020/06/29
- Re: [PATCH v7 0/8] Mac Old World ROM experiment, Mark Cave-Ayland, 2020/06/30