[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v4 11/15] hw/i2c: Remove confusing i2c_send_recv()
From: |
Philippe Mathieu-Daudé |
Subject: |
[PATCH v4 11/15] hw/i2c: Remove confusing i2c_send_recv() |
Date: |
Wed, 16 Jun 2021 23:42:50 +0200 |
We replaced all the i2c_send_recv() calls by the clearer i2c_recv()
and i2c_send(), so we can remove this confusing API.
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Signed-off-by: Philippe Mathieu-Daudé <f4bug@amsat.org>
---
include/hw/i2c/i2c.h | 1 -
hw/i2c/core.c | 50 +++++++++++++++++++-------------------------
2 files changed, 21 insertions(+), 30 deletions(-)
diff --git a/include/hw/i2c/i2c.h b/include/hw/i2c/i2c.h
index 850815e707c..99635b837a5 100644
--- a/include/hw/i2c/i2c.h
+++ b/include/hw/i2c/i2c.h
@@ -84,7 +84,6 @@ int i2c_bus_busy(I2CBus *bus);
int i2c_start_transfer(I2CBus *bus, uint8_t address, int 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(I2CBus *bus, uint8_t data);
uint8_t i2c_recv(I2CBus *bus);
bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast,
diff --git a/hw/i2c/core.c b/hw/i2c/core.c
index 3a7bae311df..27a66df7f34 100644
--- a/hw/i2c/core.c
+++ b/hw/i2c/core.c
@@ -188,50 +188,42 @@ void i2c_end_transfer(I2CBus *bus)
bus->broadcast = false;
}
-int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send)
+int i2c_send(I2CBus *bus, uint8_t data)
{
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;
- }
+ 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 {
- ret = 0xff;
- if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) {
- sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
- if (sc->recv) {
- s = QLIST_FIRST(&bus->current_devs)->elt;
- ret = sc->recv(s);
- trace_i2c_recv(s->address, ret);
- }
- }
- *data = ret;
- return 0;
}
-}
-int i2c_send(I2CBus *bus, uint8_t data)
-{
- return i2c_send_recv(bus, &data, true);
+ return ret ? -1 : 0;
}
uint8_t i2c_recv(I2CBus *bus)
{
uint8_t data = 0xff;
+ I2CSlaveClass *sc;
+ I2CSlave *s;
+
+ if (!QLIST_EMPTY(&bus->current_devs) && !bus->broadcast) {
+ sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt);
+ if (sc->recv) {
+ s = QLIST_FIRST(&bus->current_devs)->elt;
+ data = sc->recv(s);
+ trace_i2c_recv(s->address, data);
+ }
+ }
- i2c_send_recv(bus, &data, false);
return data;
}
--
2.31.1
- [PATCH v4 02/15] hw/input/lm832x: Define TYPE_LM8323 in public header, (continued)
- [PATCH v4 02/15] hw/input/lm832x: Define TYPE_LM8323 in public header, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 03/15] hw/display/sm501: Simplify sm501_i2c_write() logic, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 04/15] hw/display/sm501: Replace i2c_send_recv() by i2c_recv() & i2c_send(), Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 05/15] hw/i2c/ppc4xx_i2c: Add reference to datasheet, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 06/15] hw/i2c/ppc4xx_i2c: Replace i2c_send_recv() by i2c_recv() & i2c_send(), Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 07/15] hw/misc/auxbus: Fix MOT/classic I2C mode, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 08/15] hw/misc/auxbus: Explode READ_I2C / WRITE_I2C_MOT cases, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 09/15] hw/misc/auxbus: Replace 'is_write' boolean by its value, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 10/15] hw/misc/auxbus: Replace i2c_send_recv() by i2c_recv() & i2c_send(), Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 11/15] hw/i2c: Remove confusing i2c_send_recv(),
Philippe Mathieu-Daudé <=
- [PATCH v4 12/15] hw/i2c: Rename i2c_set_slave_address() -> i2c_slave_set_address(), Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 13/15] hw/i2c: Make i2c_start_transfer() direction argument a boolean, Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 14/15] hw/i2c: Extract i2c_do_start_transfer() from i2c_start_transfer(), Philippe Mathieu-Daudé, 2021/06/16
- [PATCH v4 15/15] hw/i2c: Introduce i2c_start_recv() and i2c_start_send(), Philippe Mathieu-Daudé, 2021/06/16