[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 05/26] hw/i2c/bitbang_i2c: Change state calling bitbang_i2c_set_st
From: |
Peter Maydell |
Subject: |
[PULL 05/26] hw/i2c/bitbang_i2c: Change state calling bitbang_i2c_set_state() helper |
Date: |
Mon, 23 Jan 2023 13:35:32 +0000 |
From: Philippe Mathieu-Daudé <philmd@linaro.org>
Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Acked-by: Corey Minyard <cminyard@mvista.com>
Message-id: 20230111085016.44551-4-philmd@linaro.org
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
hw/i2c/bitbang_i2c.c | 23 +++++++++++++++--------
1 file changed, 15 insertions(+), 8 deletions(-)
diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c
index e41cb63daa7..bf4b781393d 100644
--- a/hw/i2c/bitbang_i2c.c
+++ b/hw/i2c/bitbang_i2c.c
@@ -26,13 +26,19 @@ do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while
(0)
#define DPRINTF(fmt, ...) do {} while(0)
#endif
+static void bitbang_i2c_set_state(bitbang_i2c_interface *i2c,
+ bitbang_i2c_state state)
+{
+ i2c->state = state;
+}
+
static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c)
{
DPRINTF("STOP\n");
if (i2c->current_addr >= 0)
i2c_end_transfer(i2c->bus);
i2c->current_addr = -1;
- i2c->state = STOPPED;
+ bitbang_i2c_set_state(i2c, STOPPED);
}
/* Set device data pin. */
@@ -69,7 +75,7 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int
level)
if (level == 0) {
DPRINTF("START\n");
/* START condition. */
- i2c->state = SENDING_BIT7;
+ bitbang_i2c_set_state(i2c, SENDING_BIT7);
i2c->current_addr = -1;
} else {
/* STOP condition. */
@@ -96,7 +102,7 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
case SENDING_BIT7 ... SENDING_BIT0:
i2c->buffer = (i2c->buffer << 1) | data;
/* will end up in WAITING_FOR_ACK */
- i2c->state++;
+ bitbang_i2c_set_state(i2c, i2c->state + 1);
return bitbang_i2c_ret(i2c, 1);
case WAITING_FOR_ACK:
@@ -117,13 +123,14 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
* device we were sending to decided to NACK us).
*/
DPRINTF("Got NACK\n");
+ bitbang_i2c_set_state(i2c, SENT_NACK);
bitbang_i2c_enter_stop(i2c);
return bitbang_i2c_ret(i2c, 1);
}
if (i2c->current_addr & 1) {
- i2c->state = RECEIVING_BIT7;
+ bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
} else {
- i2c->state = SENDING_BIT7;
+ bitbang_i2c_set_state(i2c, SENDING_BIT7);
}
return bitbang_i2c_ret(i2c, 0);
}
@@ -134,18 +141,18 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line,
int level)
case RECEIVING_BIT6 ... RECEIVING_BIT0:
data = i2c->buffer >> 7;
/* will end up in SENDING_ACK */
- i2c->state++;
+ bitbang_i2c_set_state(i2c, i2c->state + 1);
i2c->buffer <<= 1;
return bitbang_i2c_ret(i2c, data);
case SENDING_ACK:
- i2c->state = RECEIVING_BIT7;
if (data != 0) {
DPRINTF("NACKED\n");
- i2c->state = SENT_NACK;
+ bitbang_i2c_set_state(i2c, SENT_NACK);
i2c_nack(i2c->bus);
} else {
DPRINTF("ACKED\n");
+ bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
}
return bitbang_i2c_ret(i2c, 1);
}
--
2.34.1
- [PULL 22/26] target/arm: Don't set EXC_RETURN.ES if Security Extension not present, (continued)
- [PULL 22/26] target/arm: Don't set EXC_RETURN.ES if Security Extension not present, Peter Maydell, 2023/01/23
- [PULL 16/26] target/arm/sme: Reset SVE state in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 21/26] target/arm: Fix in_debug path in S1_ptw_translate, Peter Maydell, 2023/01/23
- [PULL 18/26] target/arm/sme: Rebuild hflags in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 02/26] target/arm: Unify checking for M Main Extension in MRS/MSR, Peter Maydell, 2023/01/23
- [PULL 03/26] hw/i2c/bitbang_i2c: Define TYPE_GPIO_I2C in public header, Peter Maydell, 2023/01/23
- [PULL 04/26] hw/i2c/bitbang_i2c: Remove unused dummy MemoryRegion, Peter Maydell, 2023/01/23
- [PULL 08/26] hw/i2c/versatile_i2c: Drop useless casts from void * to pointer, Peter Maydell, 2023/01/23
- [PULL 06/26] hw/i2c/bitbang_i2c: Trace state changes, Peter Maydell, 2023/01/23
- [PULL 10/26] hw/i2c/versatile_i2c: Replace TYPE_VERSATILE_I2C -> TYPE_ARM_SBCON_I2C, Peter Maydell, 2023/01/23
- [PULL 05/26] hw/i2c/bitbang_i2c: Change state calling bitbang_i2c_set_state() helper,
Peter Maydell <=
- [PULL 12/26] hw/i2c/versatile_i2c: Rename versatile_i2c -> arm_sbcon_i2c, Peter Maydell, 2023/01/23
- [PULL 17/26] target/arm/sme: Reset ZA state in aarch64_set_svcr(), Peter Maydell, 2023/01/23
- [PULL 23/26] target/arm: implement DBGCLAIM registers, Peter Maydell, 2023/01/23
- [PULL 20/26] target/arm: Fix physical address resolution for MTE, Peter Maydell, 2023/01/23
- [PULL 25/26] target/arm: Reorg do_coproc_insn, Peter Maydell, 2023/01/23
- [PULL 14/26] target/arm/sme: Rebuild hflags in set_pstate() helpers, Peter Maydell, 2023/01/23
- [PULL 13/26] target/arm/sme: Reorg SME access handling in handle_msr_i(), Peter Maydell, 2023/01/23
- [PULL 24/26] target/arm: provide stubs for more external debug registers, Peter Maydell, 2023/01/23
- [PULL 26/26] target/arm: Look up ARMCPRegInfo at runtime, Peter Maydell, 2023/01/23
- Re: [PULL 00/26] target-arm queue, Peter Maydell, 2023/01/23