Skip to content

Commit a4156ae

Browse files
committed
[ot] hw/opentitan: ot_i2c_transport: add reset & be change handlers
Signed-off-by: Alice Ziuziakowska <[email protected]>
1 parent adb240e commit a4156ae

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed

hw/opentitan/ot_i2c_transport.c

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ struct OtI2CTransportState {
6060
CharBackend chr;
6161
};
6262

63+
struct OtI2CTransportClass {
64+
SysBusDeviceClass parent_class;
65+
ResettablePhases parent_phases;
66+
};
67+
6368
static void ot_i2c_transport_put_send_failure(OtI2CTransportState *s)
6469
{
6570
uint8_t fmt_byte[2] = { '!', '!' };
@@ -207,15 +212,42 @@ static void ot_i2c_transport_receive(void *opaque, const uint8_t *buf, int size)
207212
}
208213
}
209214

215+
static int ot_i2c_transport_be_change(void *opaque)
216+
{
217+
OtI2CTransportState *s = OT_I2C_TRANSPORT(opaque);
218+
219+
qemu_chr_fe_set_handlers(&s->chr, ot_i2c_transport_can_receive,
220+
ot_i2c_transport_receive, NULL,
221+
ot_i2c_transport_be_change, s, NULL, true);
222+
223+
return 0;
224+
}
225+
226+
static void ot_i2c_transport_reset_enter(Object *obj, ResetType type)
227+
{
228+
OtI2CTransportClass *c = OT_I2C_TRANSPORT_GET_CLASS(obj);
229+
OtI2CTransportState *s = OT_I2C_TRANSPORT(obj);
230+
231+
if (c->parent_phases.enter) {
232+
c->parent_phases.enter(obj, type);
233+
}
234+
235+
i2c_end_transfer(s->bus);
236+
fifo8_reset(&s->cmd_bytes_fifo);
237+
s->parser_state = OT_I2C_CMD_INIT;
238+
s->is_read_command = false;
239+
s->byte = 0u;
240+
}
241+
210242
static void ot_i2c_transport_realize(DeviceState *dev, Error **errp)
211243
{
212244
(void)errp;
213245
OtI2CTransportState *state = OT_I2C_TRANSPORT(dev);
214246
BusState *bus = qdev_get_parent_bus(dev);
215247
state->bus = I2C_BUS(bus);
216248
qemu_chr_fe_set_handlers(&state->chr, ot_i2c_transport_can_receive,
217-
ot_i2c_transport_receive, NULL, NULL, state, NULL,
218-
true);
249+
ot_i2c_transport_receive, NULL,
250+
ot_i2c_transport_be_change, state, NULL, true);
219251
}
220252

221253
static void ot_i2c_transport_init(Object *obj)
@@ -241,6 +273,11 @@ static void ot_i2c_transport_class_init(ObjectClass *klass, void *data)
241273
device_class_set_props(dc, ot_i2c_transport_properties);
242274
dc->realize = ot_i2c_transport_realize;
243275
set_bit(DEVICE_CATEGORY_MISC, dc->categories);
276+
277+
ResettableClass *rc = RESETTABLE_CLASS(klass);
278+
OtI2CTransportClass *ic = OT_I2C_TRANSPORT_CLASS(klass);
279+
resettable_class_set_parent_phases(rc, &ot_i2c_transport_reset_enter, NULL,
280+
NULL, &ic->parent_phases);
244281
}
245282

246283
static const TypeInfo ot_i2c_transport = {

include/hw/opentitan/ot_i2c_transport.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@
3131
#include "qom/object.h"
3232

3333
#define TYPE_OT_I2C_TRANSPORT "ot-i2c-transport"
34-
OBJECT_DECLARE_SIMPLE_TYPE(OtI2CTransportState, OT_I2C_TRANSPORT)
34+
OBJECT_DECLARE_TYPE(OtI2CTransportState, OtI2CTransportClass, OT_I2C_TRANSPORT)
3535

3636
#endif /* HW_OPENTITAN_OT_I2C_TRANSPORT_H */

0 commit comments

Comments
 (0)