|
@@ -16,6 +16,7 @@
|
|
#include "hw/sysbus.h"
|
|
#include "hw/sysbus.h"
|
|
#include "qemu/module.h"
|
|
#include "qemu/module.h"
|
|
#include "qom/object.h"
|
|
#include "qom/object.h"
|
|
|
|
+#include "trace.h"
|
|
|
|
|
|
//#define DEBUG_BITBANG_I2C
|
|
//#define DEBUG_BITBANG_I2C
|
|
|
|
|
|
@@ -26,15 +27,41 @@ do { printf("bitbang_i2c: " fmt , ## __VA_ARGS__); } while (0)
|
|
#define DPRINTF(fmt, ...) do {} while(0)
|
|
#define DPRINTF(fmt, ...) do {} while(0)
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+/* bitbang_i2c_state enum to name */
|
|
|
|
+static const char * const sname[] = {
|
|
|
|
+#define NAME(e) [e] = stringify(e)
|
|
|
|
+ NAME(STOPPED),
|
|
|
|
+ [SENDING_BIT7] = "SENDING_BIT7 (START)",
|
|
|
|
+ NAME(SENDING_BIT6),
|
|
|
|
+ NAME(SENDING_BIT5),
|
|
|
|
+ NAME(SENDING_BIT4),
|
|
|
|
+ NAME(SENDING_BIT3),
|
|
|
|
+ NAME(SENDING_BIT2),
|
|
|
|
+ NAME(SENDING_BIT1),
|
|
|
|
+ NAME(SENDING_BIT0),
|
|
|
|
+ NAME(WAITING_FOR_ACK),
|
|
|
|
+ [RECEIVING_BIT7] = "RECEIVING_BIT7 (ACK)",
|
|
|
|
+ NAME(RECEIVING_BIT6),
|
|
|
|
+ NAME(RECEIVING_BIT5),
|
|
|
|
+ NAME(RECEIVING_BIT4),
|
|
|
|
+ NAME(RECEIVING_BIT3),
|
|
|
|
+ NAME(RECEIVING_BIT2),
|
|
|
|
+ NAME(RECEIVING_BIT1),
|
|
|
|
+ NAME(RECEIVING_BIT0),
|
|
|
|
+ NAME(SENDING_ACK),
|
|
|
|
+ NAME(SENT_NACK)
|
|
|
|
+#undef NAME
|
|
|
|
+};
|
|
|
|
+
|
|
static void bitbang_i2c_set_state(bitbang_i2c_interface *i2c,
|
|
static void bitbang_i2c_set_state(bitbang_i2c_interface *i2c,
|
|
bitbang_i2c_state state)
|
|
bitbang_i2c_state state)
|
|
{
|
|
{
|
|
|
|
+ trace_bitbang_i2c_state(sname[i2c->state], sname[state]);
|
|
i2c->state = state;
|
|
i2c->state = state;
|
|
}
|
|
}
|
|
|
|
|
|
static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c)
|
|
static void bitbang_i2c_enter_stop(bitbang_i2c_interface *i2c)
|
|
{
|
|
{
|
|
- DPRINTF("STOP\n");
|
|
|
|
if (i2c->current_addr >= 0)
|
|
if (i2c->current_addr >= 0)
|
|
i2c_end_transfer(i2c->bus);
|
|
i2c_end_transfer(i2c->bus);
|
|
i2c->current_addr = -1;
|
|
i2c->current_addr = -1;
|
|
@@ -73,7 +100,6 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level)
|
|
return bitbang_i2c_nop(i2c);
|
|
return bitbang_i2c_nop(i2c);
|
|
}
|
|
}
|
|
if (level == 0) {
|
|
if (level == 0) {
|
|
- DPRINTF("START\n");
|
|
|
|
/* START condition. */
|
|
/* START condition. */
|
|
bitbang_i2c_set_state(i2c, SENDING_BIT7);
|
|
bitbang_i2c_set_state(i2c, SENDING_BIT7);
|
|
i2c->current_addr = -1;
|
|
i2c->current_addr = -1;
|
|
@@ -122,7 +148,6 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level)
|
|
/* NACK (either addressing a nonexistent device, or the
|
|
/* NACK (either addressing a nonexistent device, or the
|
|
* device we were sending to decided to NACK us).
|
|
* device we were sending to decided to NACK us).
|
|
*/
|
|
*/
|
|
- DPRINTF("Got NACK\n");
|
|
|
|
bitbang_i2c_set_state(i2c, SENT_NACK);
|
|
bitbang_i2c_set_state(i2c, SENT_NACK);
|
|
bitbang_i2c_enter_stop(i2c);
|
|
bitbang_i2c_enter_stop(i2c);
|
|
return bitbang_i2c_ret(i2c, 1);
|
|
return bitbang_i2c_ret(i2c, 1);
|
|
@@ -147,11 +172,9 @@ int bitbang_i2c_set(bitbang_i2c_interface *i2c, int line, int level)
|
|
|
|
|
|
case SENDING_ACK:
|
|
case SENDING_ACK:
|
|
if (data != 0) {
|
|
if (data != 0) {
|
|
- DPRINTF("NACKED\n");
|
|
|
|
bitbang_i2c_set_state(i2c, SENT_NACK);
|
|
bitbang_i2c_set_state(i2c, SENT_NACK);
|
|
i2c_nack(i2c->bus);
|
|
i2c_nack(i2c->bus);
|
|
} else {
|
|
} else {
|
|
- DPRINTF("ACKED\n");
|
|
|
|
bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
|
|
bitbang_i2c_set_state(i2c, RECEIVING_BIT7);
|
|
}
|
|
}
|
|
return bitbang_i2c_ret(i2c, 1);
|
|
return bitbang_i2c_ret(i2c, 1);
|