2 * Silicon Image SiI9022
4 * This is a pretty hollow emulation: all we do is acknowledge that we
5 * exist (chip ID) and confirm that we get switched over into DDC mode
6 * so the emulated host can proceed to read out EDID data. All subsequent
7 * set-up of connectors etc will be acknowledged and ignored.
9 * Copyright (C) 2018 Linus Walleij
11 * This work is licensed under the terms of the GNU GPL, version 2 or later.
12 * See the COPYING file in the top-level directory.
13 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include "qemu/osdep.h"
17 #include "qemu-common.h"
18 #include "hw/i2c/i2c.h"
19 #include "hw/i2c/i2c-ddc.h"
22 #define SII9022_SYS_CTRL_DATA 0x1a
23 #define SII9022_SYS_CTRL_PWR_DWN 0x10
24 #define SII9022_SYS_CTRL_AV_MUTE 0x08
25 #define SII9022_SYS_CTRL_DDC_BUS_REQ 0x04
26 #define SII9022_SYS_CTRL_DDC_BUS_GRTD 0x02
27 #define SII9022_SYS_CTRL_OUTPUT_MODE 0x01
28 #define SII9022_SYS_CTRL_OUTPUT_HDMI 1
29 #define SII9022_SYS_CTRL_OUTPUT_DVI 0
30 #define SII9022_REG_CHIPID 0x1b
31 #define SII9022_INT_ENABLE 0x3c
32 #define SII9022_INT_STATUS 0x3d
33 #define SII9022_INT_STATUS_HOTPLUG 0x01;
34 #define SII9022_INT_STATUS_PLUGGED 0x04;
36 #define TYPE_SII9022 "sii9022"
37 #define SII9022(obj) OBJECT_CHECK(sii9022_state, (obj), TYPE_SII9022)
39 typedef struct sii9022_state {
48 static const VMStateDescription vmstate_sii9022 = {
51 .minimum_version_id = 1,
52 .fields = (VMStateField[]) {
53 VMSTATE_I2C_SLAVE(parent_obj, sii9022_state),
54 VMSTATE_UINT8(ptr, sii9022_state),
55 VMSTATE_BOOL(addr_byte, sii9022_state),
56 VMSTATE_BOOL(ddc_req, sii9022_state),
57 VMSTATE_BOOL(ddc_skip_finish, sii9022_state),
58 VMSTATE_BOOL(ddc, sii9022_state),
63 static int sii9022_event(I2CSlave *i2c, enum i2c_event event)
65 sii9022_state *s = SII9022(i2c);
82 static int sii9022_rx(I2CSlave *i2c)
84 sii9022_state *s = SII9022(i2c);
88 case SII9022_SYS_CTRL_DATA:
90 /* Acknowledge DDC bus request */
91 res = SII9022_SYS_CTRL_DDC_BUS_GRTD | SII9022_SYS_CTRL_DDC_BUS_REQ;
94 case SII9022_REG_CHIPID:
97 case SII9022_INT_STATUS:
98 /* Something is cold-plugged in, no interrupts */
99 res = SII9022_INT_STATUS_PLUGGED;
105 trace_sii9022_read_reg(s->ptr, res);
111 static int sii9022_tx(I2CSlave *i2c, uint8_t data)
113 sii9022_state *s = SII9022(i2c);
117 s->addr_byte = false;
122 case SII9022_SYS_CTRL_DATA:
123 if (data & SII9022_SYS_CTRL_DDC_BUS_REQ) {
125 if (data & SII9022_SYS_CTRL_DDC_BUS_GRTD) {
127 /* Skip this finish since we just switched to DDC */
128 s->ddc_skip_finish = true;
129 trace_sii9022_switch_mode("DDC");
134 trace_sii9022_switch_mode("normal");
141 trace_sii9022_write_reg(s->ptr, data);
147 static void sii9022_reset(DeviceState *dev)
149 sii9022_state *s = SII9022(dev);
152 s->addr_byte = false;
154 s->ddc_skip_finish = false;
158 static void sii9022_realize(DeviceState *dev, Error **errp)
162 bus = I2C_BUS(qdev_get_parent_bus(dev));
163 i2c_create_slave(bus, TYPE_I2CDDC, 0x50);
166 static void sii9022_class_init(ObjectClass *klass, void *data)
168 DeviceClass *dc = DEVICE_CLASS(klass);
169 I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
171 k->event = sii9022_event;
172 k->recv = sii9022_rx;
173 k->send = sii9022_tx;
174 dc->reset = sii9022_reset;
175 dc->realize = sii9022_realize;
176 dc->vmsd = &vmstate_sii9022;
179 static const TypeInfo sii9022_info = {
180 .name = TYPE_SII9022,
181 .parent = TYPE_I2C_SLAVE,
182 .instance_size = sizeof(sii9022_state),
183 .class_init = sii9022_class_init,
186 static void sii9022_register_types(void)
188 type_register_static(&sii9022_info);
191 type_init(sii9022_register_types)