COLO: notify net filters about checkpoint/failover event
[qemu/ar7.git] / hw / display / sii9022.c
blobeaf11a6e7bb5b9d091199a86d40980dda5aad268
1 /*
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"
20 #include "trace.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 {
40 I2CSlave parent_obj;
41 uint8_t ptr;
42 bool addr_byte;
43 bool ddc_req;
44 bool ddc_skip_finish;
45 bool ddc;
46 } sii9022_state;
48 static const VMStateDescription vmstate_sii9022 = {
49 .name = "sii9022",
50 .version_id = 1,
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),
59 VMSTATE_END_OF_LIST()
63 static int sii9022_event(I2CSlave *i2c, enum i2c_event event)
65 sii9022_state *s = SII9022(i2c);
67 switch (event) {
68 case I2C_START_SEND:
69 s->addr_byte = true;
70 break;
71 case I2C_START_RECV:
72 break;
73 case I2C_FINISH:
74 break;
75 case I2C_NACK:
76 break;
79 return 0;
82 static int sii9022_rx(I2CSlave *i2c)
84 sii9022_state *s = SII9022(i2c);
85 uint8_t res = 0x00;
87 switch (s->ptr) {
88 case SII9022_SYS_CTRL_DATA:
89 if (s->ddc_req) {
90 /* Acknowledge DDC bus request */
91 res = SII9022_SYS_CTRL_DDC_BUS_GRTD | SII9022_SYS_CTRL_DDC_BUS_REQ;
93 break;
94 case SII9022_REG_CHIPID:
95 res = 0xb0;
96 break;
97 case SII9022_INT_STATUS:
98 /* Something is cold-plugged in, no interrupts */
99 res = SII9022_INT_STATUS_PLUGGED;
100 break;
101 default:
102 break;
105 trace_sii9022_read_reg(s->ptr, res);
106 s->ptr++;
108 return res;
111 static int sii9022_tx(I2CSlave *i2c, uint8_t data)
113 sii9022_state *s = SII9022(i2c);
115 if (s->addr_byte) {
116 s->ptr = data;
117 s->addr_byte = false;
118 return 0;
121 switch (s->ptr) {
122 case SII9022_SYS_CTRL_DATA:
123 if (data & SII9022_SYS_CTRL_DDC_BUS_REQ) {
124 s->ddc_req = true;
125 if (data & SII9022_SYS_CTRL_DDC_BUS_GRTD) {
126 s->ddc = true;
127 /* Skip this finish since we just switched to DDC */
128 s->ddc_skip_finish = true;
129 trace_sii9022_switch_mode("DDC");
131 } else {
132 s->ddc_req = false;
133 s->ddc = false;
134 trace_sii9022_switch_mode("normal");
136 break;
137 default:
138 break;
141 trace_sii9022_write_reg(s->ptr, data);
142 s->ptr++;
144 return 0;
147 static void sii9022_reset(DeviceState *dev)
149 sii9022_state *s = SII9022(dev);
151 s->ptr = 0;
152 s->addr_byte = false;
153 s->ddc_req = false;
154 s->ddc_skip_finish = false;
155 s->ddc = false;
158 static void sii9022_realize(DeviceState *dev, Error **errp)
160 I2CBus *bus;
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)