Skip to content

Commit e89e6b2

Browse files
committed
[ot] hw/opentitan: ot_i2c: implement I2CSlaveClass send
Needed for `ot_i2c_transport` to be able to communicate with `ot_i2c` in target mode. Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent 5039ad0 commit e89e6b2

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

hw/opentitan/ot_i2c.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1165,10 +1165,11 @@ static int ot_i2c_target_event(I2CSlave *target, enum i2c_event event)
11651165
}
11661166

11671167
switch (event) {
1168+
case I2C_START_SEND:
11681169
case I2C_START_SEND_ASYNC:
11691170
/* Set the first byte to the target address + RW bit as 0. */
11701171
ot_i2c_target_set_acqdata(s, target->address << 1u, SIGNAL_START);
1171-
i2c_ack(s->bus);
1172+
if (event == I2C_START_SEND_ASYNC) i2c_ack(s->bus);
11721173
break;
11731174
case I2C_START_RECV:
11741175
/* Set the first byte to the target address + RW bit as 1. */
@@ -1226,6 +1227,18 @@ static uint8_t ot_i2c_target_recv(I2CSlave *target)
12261227
return data;
12271228
}
12281229

1230+
static int ot_i2c_target_send(I2CSlave *target, uint8_t data)
1231+
{
1232+
BusState *abus = qdev_get_parent_bus(DEVICE(target));
1233+
OtI2CState *s = OT_I2C(abus->parent);
1234+
if (!ot_i2c_target_enabled(s)) {
1235+
return -1;
1236+
}
1237+
1238+
ot_i2c_target_set_acqdata(s, data, SIGNAL_NONE);
1239+
return 0;
1240+
}
1241+
12291242
static void ot_i2c_target_send_async(I2CSlave *target, uint8_t data)
12301243
{
12311244
BusState *abus = qdev_get_parent_bus(DEVICE(target));
@@ -1246,6 +1259,7 @@ static void ot_i2c_target_class_init(ObjectClass *klass, void *data)
12461259

12471260
dc->desc = "OpenTitan I2C Target";
12481261
sc->event = &ot_i2c_target_event;
1262+
sc->send = &ot_i2c_target_send;
12491263
sc->send_async = &ot_i2c_target_send_async;
12501264
sc->recv = &ot_i2c_target_recv;
12511265
}

0 commit comments

Comments
 (0)