Skip to contentSkip to conversation

hw/i2c-ddc: Do not fail writes

PATCH In review Linus Walleij 5 participants 25 messages Feb 17, 2018 – Feb 27, 2018 Arm/versatile express platform

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 hw/i2c-ddc: Do not fail writes

The tx function of the DDC I2C slave emulation was returning 1 on all writes resulting in NACK in the I2C bus. Changing it to 0 makes the DDC I2C work fine with bit-banged I2C such as the versatile I2C.

I guess it was not affecting whatever I2C controller this was used with until now, but with the Versatile I2C it surely does not work.

---
 hw/i2c/i2c-ddc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i2c/i2c-ddc.c +2 -2
index 199dac9e41c1..bec0c91e2dd0 100644
@@ -259,12 +259,12 @@ static int i2c_ddc_tx(I2CSlave *i2c, uint8_t data)
         s->reg = data;
         s->firstbyte = false;
         DPRINTF("[EDID] Written new pointer: %u\n", data);
-        return 1;
+        return 0;
     }
 
     /* Ignore all writes */
     s->reg++;
-    return 1;
+    return 0;
 }
 
 static void i2c_ddc_init(Object *obj)
Signature · 1 line
2.14.3
#1 lore raw

PATCH 2/3 hw/sii9022: Add support for Silicon Image SII9022

This adds support for emulating the Silicon Image SII9022 DVI/HDMI bridge. It's not very clever right now, it just acknowledges the switch into DDC I2C mode and back. Combining this with the existing DDC I2C emulation gives the right behavior on the Versatile Express emulation passing through the QEMU EDID to the emulated platform.

---
 hw/display/Makefile.objs |   1 +
 hw/display/sii9022.c     | 185 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
 create mode 100644 hw/display/sii9022.c
hw/display/Makefile.objs +1 -0
index d3a4cb396eb9..3c7c75b94da5 100644
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
 common-obj-$(CONFIG_G364FB) += g364fb.o
 common-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 common-obj-$(CONFIG_PL110) += pl110.o
+common-obj-$(CONFIG_SII9022) += sii9022.o
 common-obj-$(CONFIG_SSD0303) += ssd0303.o
 common-obj-$(CONFIG_SSD0323) += ssd0323.o
 common-obj-$(CONFIG_XEN) += xenfb.o
hw/display/sii9022.c new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.14.3
#2 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Hi Linus,

Quoted 50 lines · Linus Walleij

This adds support for emulating the Silicon Image SII9022 DVI/HDMI bridge. It's not very clever right now, it just acknowledges the switch into DDC I2C mode and back. Combining this with the existing DDC I2C emulation gives the right behavior on the Versatile Express emulation passing through the QEMU EDID to the emulated platform.

---
 hw/display/Makefile.objs |   1 +
 hw/display/sii9022.c     | 185 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
 create mode 100644 hw/display/sii9022.c
hw/display/Makefile.objs +1 -0
index d3a4cb396eb9..3c7c75b94da5 100644
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
 common-obj-$(CONFIG_G364FB) += g364fb.o
 common-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 common-obj-$(CONFIG_PL110) += pl110.o
+common-obj-$(CONFIG_SII9022) += sii9022.o
 common-obj-$(CONFIG_SSD0303) += ssd0303.o
 common-obj-$(CONFIG_SSD0323) += ssd0323.o
 common-obj-$(CONFIG_XEN) += xenfb.o
hw/display/sii9022.c new file +18 -0
new file mode 100644
index 000000000000..d6f3cdc04293
@@ -0,0 +1,185 @@
+/*
+ * Silicon Image SiI9022
+ *
+ * This is a pretty hollow emulation: all we do is acknowledge that we
+ * exist (chip ID) and confirm that we get switched over into DDC mode
+ * so the emulated host can proceed to read out EDID data. All subsequent
+ * set-up of connectors etc will be acknowledged and ignored.
+ *
+ * Copyright (c) 2018 Linus Walleij
+ *
+ * This code is licensed under the GNU GPL v2.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.
+ */
+
+#include "qemu/osdep.h"
+#include "qemu-common.h"

hw/display/sii9022.c line 28

Quoted 10 lines
hw/display/sii9022.c new file +10 -0
+#include "hw/i2c/i2c.h"
+
+#define DEBUG_SII9022 0
+
+#define DPRINTF(fmt, ...) \
+    do { \
+        if (DEBUG_SII9022) { \
+            printf("sii9022: " fmt, ## __VA_ARGS__); \
+        } \
+    } while (0)

Can you replace DPRINTF() by trace events?

Except that, patch looks fine.

Regards,

Phil.

Quoted 158 lines
hw/display/sii9022.c new file +157 -0
+
+#define SII9022_SYS_CTRL_DATA 0x1a
+#define SII9022_SYS_CTRL_PWR_DWN 0x10
+#define SII9022_SYS_CTRL_AV_MUTE 0x08
+#define SII9022_SYS_CTRL_DDC_BUS_REQ 0x04
+#define SII9022_SYS_CTRL_DDC_BUS_GRTD 0x02
+#define SII9022_SYS_CTRL_OUTPUT_MODE 0x01
+#define SII9022_SYS_CTRL_OUTPUT_HDMI 1
+#define SII9022_SYS_CTRL_OUTPUT_DVI 0
+#define SII9022_REG_CHIPID 0x1b
+#define SII9022_INT_ENABLE 0x3c
+#define SII9022_INT_STATUS 0x3d
+#define SII9022_INT_STATUS_HOTPLUG 0x01;
+#define SII9022_INT_STATUS_PLUGGED 0x04;
+
+#define TYPE_SII9022 "sii9022"
+#define SII9022(obj) OBJECT_CHECK(sii9022_state, (obj), TYPE_SII9022)
+
+typedef struct sii9022_state {
+    I2CSlave parent_obj;
+    uint8_t ptr;
+    bool addr_byte;
+    bool ddc_req;
+    bool ddc_skip_finish;
+    bool ddc;
+} sii9022_state;
+
+static const VMStateDescription vmstate_sii9022 = {
+    .name = "sii9022",
+    .version_id = 1,
+    .minimum_version_id = 1,
+    .fields = (VMStateField[]) {
+        VMSTATE_I2C_SLAVE(parent_obj, sii9022_state),
+        VMSTATE_UINT8(ptr, sii9022_state),
+        VMSTATE_BOOL(addr_byte, sii9022_state),
+        VMSTATE_BOOL(ddc_req, sii9022_state),
+        VMSTATE_BOOL(ddc_skip_finish, sii9022_state),
+        VMSTATE_BOOL(ddc, sii9022_state),
+        VMSTATE_END_OF_LIST()
+    }
+};
+
+static int sii9022_event(I2CSlave *i2c, enum i2c_event event)
+{
+    sii9022_state *s = SII9022(i2c);
+
+    switch (event) {
+    case I2C_START_SEND:
+        s->addr_byte = true;
+        break;
+    case I2C_START_RECV:
+        break;
+    case I2C_FINISH:
+        break;
+    case I2C_NACK:
+        break;
+    }
+
+    return 0;
+}
+
+static int sii9022_rx(I2CSlave *i2c)
+{
+    sii9022_state *s = SII9022(i2c);
+    uint8_t res = 0x00;
+
+    switch (s->ptr) {
+    case SII9022_SYS_CTRL_DATA:
+        if (s->ddc_req) {
+            /* Acknowledge DDC bus request */
+            res = SII9022_SYS_CTRL_DDC_BUS_GRTD | SII9022_SYS_CTRL_DDC_BUS_REQ;
+        }
+        break;
+    case SII9022_REG_CHIPID:
+        res = 0xb0;
+        break;
+    case SII9022_INT_STATUS:
+        /* Something is cold-plugged in, no interrupts */
+        res = SII9022_INT_STATUS_PLUGGED;
+        break;
+    default:
+        break;
+    }
+    DPRINTF("%02x read from %02x\n", res, s->ptr);
+    s->ptr++;
+
+    return res;
+}
+
+static int sii9022_tx(I2CSlave *i2c, uint8_t data)
+{
+    sii9022_state *s = SII9022(i2c);
+
+    if (s->addr_byte) {
+        s->ptr = data;
+        s->addr_byte = false;
+        return 0;
+    }
+
+    switch (s->ptr) {
+    case SII9022_SYS_CTRL_DATA:
+        if (data & SII9022_SYS_CTRL_DDC_BUS_REQ) {
+            s->ddc_req = true;
+            if (data & SII9022_SYS_CTRL_DDC_BUS_GRTD) {
+                s->ddc = true;
+                /* Skip this finish since we just switched to DDC */
+                s->ddc_skip_finish = true;
+                DPRINTF("switched to DDC mode\n");
+            }
+        } else {
+            s->ddc_req = false;
+            s->ddc = false;
+        }
+        break;
+    default:
+        break;
+    }
+
+    DPRINTF("%02x written to %02x\n", data, s->ptr);
+    s->ptr++;
+
+    return 0;
+}
+
+static void sii9022_reset(DeviceState *dev)
+{
+    sii9022_state *s = SII9022(dev);
+
+    s->ptr = 0;
+    s->addr_byte = false;
+}
+
+static void sii9022_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+    k->event = sii9022_event;
+    k->recv = sii9022_rx;
+    k->send = sii9022_tx;
+    dc->reset = sii9022_reset;
+    dc->vmsd = &vmstate_sii9022;
+}
+
+static const TypeInfo sii9022_info = {
+    .name          = TYPE_SII9022,
+    .parent        = TYPE_I2C_SLAVE,
+    .instance_size = sizeof(sii9022_state),
+    .class_init    = sii9022_class_init,
+};
+
+static void sii9022_register_types(void)
+{
+    type_register_static(&sii9022_info);
+}
+
+type_init(sii9022_register_types)
#3 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Quoted 11 lines · Philippe Mathieu-Daudé

[Me]

hw/display/sii9022.c line 28

Quoted 8 lines
hw/display/sii9022.c new file +8 -0
+#define DEBUG_SII9022 0
+
+#define DPRINTF(fmt, ...) \
+    do { \
+        if (DEBUG_SII9022) { \
+            printf("sii9022: " fmt, ## __VA_ARGS__); \
+        } \
+    } while (0)

Can you replace DPRINTF() by trace events?

Absolutely but which ones?

I do not feel senior enough to also invent new trace events for displays or I2C devices...

Yours,
Linus Walleij

#4 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Quoted 14 lines · Linus Walleij
Quoted 11 lines · Philippe Mathieu-Daudé

[Me]

hw/display/sii9022.c line 28

Quoted 8 lines
hw/display/sii9022.c new file +8 -0
+#define DEBUG_SII9022 0
+
+#define DPRINTF(fmt, ...) \
+    do { \
+        if (DEBUG_SII9022) { \
+            printf("sii9022: " fmt, ## __VA_ARGS__); \
+        } \
+    } while (0)

Can you replace DPRINTF() by trace events?

Quoted 4 lines

Absolutely but which ones?

I do not feel senior enough to also invent new trace events for displays or I2C devices...

Just put a trace event where you've put DPRINTF debug statements.

thanks
-- PMM

#5 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Quoted 15 lines · Peter Maydell
Quoted 14 lines · Linus Walleij
Quoted 11 lines · Philippe Mathieu-Daudé

[Me]

hw/display/sii9022.c line 28

Quoted 8 lines
hw/display/sii9022.c new file +8 -0
+#define DEBUG_SII9022 0
+
+#define DPRINTF(fmt, ...) \
+    do { \
+        if (DEBUG_SII9022) { \
+            printf("sii9022: " fmt, ## __VA_ARGS__); \
+        } \
+    } while (0)

Can you replace DPRINTF() by trace events?

Quoted 6 lines
Quoted 4 lines

Absolutely but which ones?

I do not feel senior enough to also invent new trace events for displays or I2C devices...

Just put a trace event where you've put DPRINTF debug statements.

Yeah, hm the question might be silly or something but I don't know how to do that.

I guess I should include "trace.h".

#include "trace.h" says it is autogenerated from tracetool.

Is there some documentation I should be reading or a good example commit I can study to get the hang of it?

Yours,
Linus Walleij

#6 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Quoted 19 lines · Linus Walleij
Quoted 17 lines · Peter Maydell
Quoted 16 lines · Linus Walleij
Quoted 11 lines · Philippe Mathieu-Daudé

[Me]

hw/display/sii9022.c line 28

Quoted 8 lines
hw/display/sii9022.c new file +8 -0
+#define DEBUG_SII9022 0
+
+#define DPRINTF(fmt, ...) \
+    do { \
+        if (DEBUG_SII9022) { \
+            printf("sii9022: " fmt, ## __VA_ARGS__); \
+        } \
+    } while (0)

Can you replace DPRINTF() by trace events?

Absolutely but which ones?

Quoted 7 lines
Quoted 4 lines
Quoted 2 lines

I do not feel senior enough to also invent new trace events for displays or I2C devices...

Just put a trace event where you've put DPRINTF debug statements.

Yeah, hm the question might be silly or something but I don't know how to do that.

docs/devel/tracing.txt describes them, but basically:
* include "trace.h"
* define trace events with a line for each in the trace-events file for the subdirectory (basically a function prototype-ish thing followed by a printf-style format string)
* call them like normal function calls with a trace_ prefix

commit 1b640aa9292bc00beb441e97d862ba322a7ba18d is a recent one which converted some DRINTFs in hw/sd/sd.c to trace events.

thanks
-- PMM

#7 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

Quoted 9 lines · Peter Maydell

docs/devel/tracing.txt describes them, but basically:
* include "trace.h"
* define trace events with a line for each in the trace-events file for the subdirectory (basically a function prototype-ish thing followed by a printf-style format string)
* call them like normal function calls with a trace_ prefix

commit 1b640aa9292bc00beb441e97d862ba322a7ba18d is a recent one which converted some DRINTFs in hw/sd/sd.c to trace events.

...and you can test them most conveniently with the QEMU -d argument: "-d trace:sii9022*" will enable tracing to stderr of all trace events with names that begin 'sii9022'.

thanks
-- PMM

#8 lore raw

Re: [Qemu-arm] [PATCH 2/3] hw/sii9022: Add support for Silicon Image SII9022

In reply to Linus Walleij
Quoted 32 lines · Linus Walleij

This adds support for emulating the Silicon Image SII9022 DVI/HDMI bridge. It's not very clever right now, it just acknowledges the switch into DDC I2C mode and back. Combining this with the existing DDC I2C emulation gives the right behavior on the Versatile Express emulation passing through the QEMU EDID to the emulated platform.

---
 hw/display/Makefile.objs |   1 +
 hw/display/sii9022.c     | 185 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 186 insertions(+)
 create mode 100644 hw/display/sii9022.c
hw/display/Makefile.objs +1 -0
index d3a4cb396eb9..3c7c75b94da5 100644
@@ -3,6 +3,7 @@ common-obj-$(CONFIG_VGA_CIRRUS) += cirrus_vga.o
 common-obj-$(CONFIG_G364FB) += g364fb.o
 common-obj-$(CONFIG_JAZZ_LED) += jazz_led.o
 common-obj-$(CONFIG_PL110) += pl110.o
+common-obj-$(CONFIG_SII9022) += sii9022.o
 common-obj-$(CONFIG_SSD0303) += ssd0303.o
 common-obj-$(CONFIG_SSD0323) += ssd0323.o
 common-obj-$(CONFIG_XEN) += xenfb.o
hw/display/sii9022.c new file +0 -0
new file mode 100644
index 000000000000..d6f3cdc04293

hw/display/sii9022.c line 9

Quoted 9 lines
hw/display/sii9022.c new file +9 -0
@@ -0,0 +1,185 @@
+/*
+ * Silicon Image SiI9022
+ *
+ * This is a pretty hollow emulation: all we do is acknowledge that we
+ * exist (chip ID) and confirm that we get switched over into DDC mode
+ * so the emulated host can proceed to read out EDID data. All subsequent
+ * set-up of connectors etc will be acknowledged and ignored.
+ *
+ * Copyright (c) 2018 Linus Walleij

Sanity check: really copyright you and not Linaro ?

hw/display/sii9022.c line 14

Quoted 5 lines
hw/display/sii9022.c new file +5 -0
+ *
+ * This code is licensed under the GNU GPL v2.
+ *
+ * Contributions after 2012-01-13 are licensed under the terms of the
+ * GNU GPL, version 2 or (at your option) any later version.

If this is copyright 2018 then what parts of it are not covered by the "contributions after 2012-01-13" condition? Could we just have this be GPL-v2-or-later, which is what most new code is ?

hw/display/sii9022.c line 158

Quoted 6 lines
hw/display/sii9022.c new file +6 -0
+static void sii9022_reset(DeviceState *dev)
+{
+    sii9022_state *s = SII9022(dev);
+
+    s->ptr = 0;
+    s->addr_byte = false;

I think we should reset ddc/ddc_skip_finish/ddc_req here too. I suspect the state machine logic means we can't get to a place where their values are used once we reset ptr and addr_byte, but it's easier to reason about if we just reset all the device's state.

I agree with Philippe that we should use trace events here rather than the DPRINTF macro. Otherwise the code looks fine.

thanks
-- PMM

#9 lore raw

PATCH 3/3 arm/vexpress: Add proper display connector emulation

In reply to Linus Walleij

This adds the SiI9022 and EDID I2C devices to the ARM Versatile Express machine, and selects the two I2C devices necessary in the arm-softmmy.mak configuration so everything will build smoothly.

I am implementing proper handling of the graphics in the Linux kernel and adding proper emulation of SiI9022 and EDID makes the driver probe as nicely as before, retrieveing the resolutions supported by the "QEMU monitor" and overall just working nice.

The assignment of the SiI9022 at address 0x39 and the EDID DDC I2C at address 0x50 is not strictly correct: the DDC I2C is there all the time but in the actual component it only appears once activated inside the SiI9022, so ideally it should be added and removed to the bus by the SiI9022. However for this purpose it works fine to just have it around.

---
 default-configs/arm-softmmu.mak | 2 ++
 hw/arm/vexpress.c               | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
default-configs/arm-softmmu.mak +2 -0
index ca34cf446242..54f855d07206 100644
@@ -21,6 +21,8 @@ CONFIG_STELLARIS_INPUT=y
 CONFIG_STELLARIS_ENET=y
 CONFIG_SSD0303=y
 CONFIG_SSD0323=y
+CONFIG_DDC=y
+CONFIG_SII9022=y
 CONFIG_ADS7846=y
 CONFIG_MAX111X=y
 CONFIG_SSI=y
hw/arm/vexpress.c +6 -1
index dc5928ae1ab5..d6c912c97684 100644
@@ -29,6 +29,7 @@
 #include "hw/arm/arm.h"
 #include "hw/arm/primecell.h"
 #include "hw/devices.h"
+#include "hw/i2c/i2c.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
@@ -537,6 +538,7 @@ static void vexpress_common_init(MachineState *machine)
     uint32_t sys_id;
     DriveInfo *dinfo;
     pflash_t *pflash0;
+    I2CBus *i2c;
     ram_addr_t vram_size, sram_size;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *vram = g_new(MemoryRegion, 1);
@@ -628,7 +630,10 @@ static void vexpress_common_init(MachineState *machine)
     sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
     sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);
 
-    /* VE_SERIALDVI: not modelled */
+    dev = sysbus_create_simple("versatile_i2c", map[VE_SERIALDVI], NULL);
+    i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
+    i2c_create_slave(i2c, "sii9022", 0x39);
+    i2c_create_slave(i2c, "i2c-ddc", 0x50);
 
     sysbus_create_simple("pl031", map[VE_RTC], pic[4]); /* RTC */
 
Signature · 1 line
2.14.3
#10 lore raw

Re: [Qemu-devel] [PATCH 3/3] arm/vexpress: Add proper display connector emulation

Hi Linus,

Quoted 9 lines · Linus Walleij

This adds the SiI9022 and EDID I2C devices to the ARM Versatile Express machine, and selects the two I2C devices necessary in the arm-softmmy.mak configuration so everything will build smoothly.

I am implementing proper handling of the graphics in the Linux kernel and adding proper emulation of SiI9022 and EDID makes the driver probe as nicely as before, retrieveing the resolutions supported by the "QEMU monitor" and overall just working nice.

Quoted 6 lines

The assignment of the SiI9022 at address 0x39 and the EDID DDC I2C at address 0x50 is not strictly correct: the DDC I2C is there all the time but in the actual component it only appears once activated inside the SiI9022, so ideally it should be added and removed to the bus by the SiI9022. However for this purpose it works fine to just have it around.

This seems easier to just do it now rather than postpone :)

In your patch #2:

static void sii9022_realize(DeviceState *dev, Error **errp)

{
    I2CBus *bus;

    bus = I2C_BUS(qdev_get_parent_bus(dev));
    i2c_create_slave(bus, TYPE_I2CDDC, 0x50);
}

static void sii9022_class_init(ObjectClass *klass, void *data)

{
    DeviceClass *dc = DEVICE_CLASS(klass);

...

    dc->realize = sii9022_realize;
}
Quoted 53 lines
---
 default-configs/arm-softmmu.mak | 2 ++
 hw/arm/vexpress.c               | 7 ++++++-
 2 files changed, 8 insertions(+), 1 deletion(-)
default-configs/arm-softmmu.mak +2 -0
index ca34cf446242..54f855d07206 100644
@@ -21,6 +21,8 @@ CONFIG_STELLARIS_INPUT=y
 CONFIG_STELLARIS_ENET=y
 CONFIG_SSD0303=y
 CONFIG_SSD0323=y
+CONFIG_DDC=y
+CONFIG_SII9022=y
 CONFIG_ADS7846=y
 CONFIG_MAX111X=y
 CONFIG_SSI=y
hw/arm/vexpress.c +6 -1
index dc5928ae1ab5..d6c912c97684 100644
@@ -29,6 +29,7 @@
 #include "hw/arm/arm.h"
 #include "hw/arm/primecell.h"
 #include "hw/devices.h"
+#include "hw/i2c/i2c.h"
 #include "net/net.h"
 #include "sysemu/sysemu.h"
 #include "hw/boards.h"
@@ -537,6 +538,7 @@ static void vexpress_common_init(MachineState *machine)
     uint32_t sys_id;
     DriveInfo *dinfo;
     pflash_t *pflash0;
+    I2CBus *i2c;
     ram_addr_t vram_size, sram_size;
     MemoryRegion *sysmem = get_system_memory();
     MemoryRegion *vram = g_new(MemoryRegion, 1);
@@ -628,7 +630,10 @@ static void vexpress_common_init(MachineState *machine)
     sysbus_create_simple("sp804", map[VE_TIMER01], pic[2]);
     sysbus_create_simple("sp804", map[VE_TIMER23], pic[3]);
 
-    /* VE_SERIALDVI: not modelled */
+    dev = sysbus_create_simple("versatile_i2c", map[VE_SERIALDVI], NULL);
+    i2c = (I2CBus *)qdev_get_child_bus(dev, "i2c");
+    i2c_create_slave(i2c, "sii9022", 0x39);
+    i2c_create_slave(i2c, "i2c-ddc", 0x50);
 
     sysbus_create_simple("pl031", map[VE_RTC], pic[4]); /* RTC */
 
#11 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH 3/3] arm/vexpress: Add proper display connector emulation

Quoted 13 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Linus Walleij

The assignment of the SiI9022 at address 0x39 and the EDID DDC I2C at address 0x50 is not strictly correct: the DDC I2C is there all the time but in the actual component it only appears once activated inside the SiI9022, so ideally it should be added and removed to the bus by the SiI9022. However for this purpose it works fine to just have it around.

This seems easier to just do it now rather than postpone :)

In your patch #2:

Quoted 7 lines

static void sii9022_realize(DeviceState *dev, Error **errp)

{
    I2CBus *bus;

    bus = I2C_BUS(qdev_get_parent_bus(dev));
    i2c_create_slave(bus, TYPE_I2CDDC, 0x50);
}

I tried an approach like this but the I2C_BUS() macro was not publicly visible in any header file and trying to pry it out just brought along a lot of refactoring in the i2c core.c file that scared me away...

Has someone else fixed it already?

Yours,
Linus Walleij

#12 lore raw

Re: [Qemu-devel] [PATCH 3/3] arm/vexpress: Add proper display connector emulation

Quoted 19 lines · Linus Walleij
Quoted 11 lines · Philippe Mathieu-Daudé
Quoted 6 lines · Linus Walleij

The assignment of the SiI9022 at address 0x39 and the EDID DDC I2C at address 0x50 is not strictly correct: the DDC I2C is there all the time but in the actual component it only appears once activated inside the SiI9022, so ideally it should be added and removed to the bus by the SiI9022. However for this purpose it works fine to just have it around.

This seems easier to just do it now rather than postpone :)

In your patch #2:

Quoted 7 lines

static void sii9022_realize(DeviceState *dev, Error **errp)

{
     I2CBus *bus;

     bus = I2C_BUS(qdev_get_parent_bus(dev));
     i2c_create_slave(bus, TYPE_I2CDDC, 0x50);
}
Quoted 6 lines

I tried an approach like this but the I2C_BUS() macro was not publicly visible in any header file and trying to pry it out just brought along a lot of refactoring in the i2c core.c file that scared me away...

Has someone else fixed it already?

I have a patch that does this.  Well, it's a small cleanup patch and another patch, but it's really no that bad.  I'll send it.

-corey

Quoted 4 lines

Yours,
Linus Walleij

#13 lore raw

cover Move the bus class to i2c.h

In reply to Linus Walleij

This is a couple of changes I have because I have a bus mux emulator and a multi-master bus mux emulator. Others need this change, too, so get it out there.

-corey

#14 lore raw

PATCH 1/2 i2c: Fix some brace style issues

From: Corey Minyard <[email protected]>

---
 hw/i2c/core.c        | 3 +--
 include/hw/i2c/i2c.h | 6 ++----
 2 files changed, 3 insertions(+), 6 deletions(-)
hw/i2c/core.c +1 -2
index 59068f1..9a54b61 100644
@@ -19,8 +19,7 @@ struct I2CNode {
 
 #define I2C_BROADCAST 0x00
 
-struct I2CBus
-{
+struct I2CBus {
     BusState qbus;
     QLIST_HEAD(, I2CNode) current_devs;
     uint8_t saved_address;
include/hw/i2c/i2c.h +2 -4
index 24e95d0..8fd449f 100644
@@ -25,8 +25,7 @@ typedef struct I2CSlave I2CSlave;
 #define I2C_SLAVE_GET_CLASS(obj) \
      OBJECT_GET_CLASS(I2CSlaveClass, (obj), TYPE_I2C_SLAVE)
 
-typedef struct I2CSlaveClass
-{
+typedef struct I2CSlaveClass {
     DeviceClass parent_class;
 
     /* Callbacks provided by the device.  */
@@ -50,8 +49,7 @@ typedef struct I2CSlaveClass
     int (*event)(I2CSlave *s, enum i2c_event event);
 } I2CSlaveClass;
 
-struct I2CSlave
-{
+struct I2CSlave {
     DeviceState qdev;
 
     /* Remaining fields for internal use by the I2C code.  */
Signature · 1 line
2.7.4
#17 lore raw

PATCH 2/2 i2c: Move the bus class to i2c.h

In reply to [email protected]

From: Corey Minyard <[email protected]>

Some devices need access to it.

---
 hw/i2c/core.c        | 17 -----------------
 include/hw/i2c/i2c.h | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 17 deletions(-)
hw/i2c/core.c +0 -17
index 9a54b61..cfccefc 100644
@@ -10,30 +10,13 @@
 #include "qemu/osdep.h"
 #include "hw/i2c/i2c.h"
 
-typedef struct I2CNode I2CNode;
-
-struct I2CNode {
-    I2CSlave *elt;
-    QLIST_ENTRY(I2CNode) next;
-};
-
 #define I2C_BROADCAST 0x00
 
-struct I2CBus {
-    BusState qbus;
-    QLIST_HEAD(, I2CNode) current_devs;
-    uint8_t saved_address;
-    bool broadcast;
-};
-
 static Property i2c_props[] = {
     DEFINE_PROP_UINT8("address", struct I2CSlave, address, 0),
     DEFINE_PROP_END_OF_LIST(),
 };
 
-#define TYPE_I2C_BUS "i2c-bus"
-#define I2C_BUS(obj) OBJECT_CHECK(I2CBus, (obj), TYPE_I2C_BUS)
-
 static const TypeInfo i2c_bus_info = {
     .name = TYPE_I2C_BUS,
     .parent = TYPE_BUS,
include/hw/i2c/i2c.h +17 -0
index 8fd449f..d727379 100644
@@ -56,6 +56,23 @@ struct I2CSlave {
     uint8_t address;
 };
 
+#define TYPE_I2C_BUS "i2c-bus"
+#define I2C_BUS(obj) OBJECT_CHECK(I2CBus, (obj), TYPE_I2C_BUS)
+
+typedef struct I2CNode I2CNode;
+
+struct I2CNode {
+    I2CSlave *elt;
+    QLIST_ENTRY(I2CNode) next;
+};
+
+struct I2CBus {
+    BusState qbus;
+    QLIST_HEAD(, I2CNode) current_devs;
+    uint8_t saved_address;
+    bool broadcast;
+};
+
 I2CBus *i2c_init_bus(DeviceState *parent, const char *name);
 void i2c_set_slave_address(I2CSlave *dev, uint8_t address);
 int i2c_bus_busy(I2CBus *bus);
Signature · 1 line
2.7.4
Reviewed-by on v1 2/2
#18 lore raw

Re: [Qemu-devel] [PATCH 2/2] i2c: Move the bus class to i2c.h

Quoted 9 lines · On 19 February 2018 at 15:20, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

Some devices need access to it.

---
 hw/i2c/core.c        | 17 -----------------
 include/hw/i2c/i2c.h | 17 +++++++++++++++++
 2 files changed, 17 insertions(+), 17 deletions(-)

thanks
-- PMM

#19 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH 2/2] i2c: Move the bus class to i2c.h

Quoted 11 lines · Peter Maydell
Quoted 9 lines · On 19 February 2018 at 15:20, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

Some devices need access to it.

---
  hw/i2c/core.c        | 17 -----------------
  include/hw/i2c/i2c.h | 17 +++++++++++++++++
  2 files changed, 17 insertions(+), 17 deletions(-)

Linus, Philippe, do you want me to submit this, or do you want to take it?  You can pull it from:

https://github.com/cminyard/qemu.git tags/i2c-bus-move

-corey

Quoted 2 lines

thanks
-- PMM

#20 lore raw

Re: [Qemu-devel] [PATCH 2/2] i2c: Move the bus class to i2c.h

Quoted 14 lines · Corey Minyard
Quoted 13 lines · Peter Maydell
Quoted 10 lines · On 19 February 2018 at 15:20, <[email protected]> wrote:

From: Corey Minyard <[email protected]>

Some devices need access to it.

---
  hw/i2c/core.c        | 17 -----------------
  include/hw/i2c/i2c.h | 17 +++++++++++++++++
  2 files changed, 17 insertions(+), 17 deletions(-)
Quoted 7 lines
Quoted 1 line

Linus, Philippe, do you want me to submit this, or do you want to take it? You can pull it from:

https://github.com/cminyard/qemu.git tags/i2c-bus-move

I don't have any commit rights, if you can push this to the QEMU master I will happily rebase my stuff and resubmit :)

Yours,
Linus Walleij

#21 lore raw

Re: [Qemu-arm] [Qemu-devel] [PATCH 2/2] i2c: Move the bus class to i2c.h

Quoted 8 lines · Linus Walleij
Quoted 4 lines · Corey Minyard

Linus, Philippe, do you want me to submit this, or do you want to take it? You can pull it from:

https://github.com/cminyard/qemu.git tags/i2c-bus-move

I don't have any commit rights, if you can push this to the QEMU master I will happily rebase my stuff and resubmit :)

I suggest you take Corey's 2 patches, add them to the front of your patchset and add your signed-off-by line to them. That way you don't have to wait for them to go into git master.

thanks
-- PMM

#22 lore raw

Re: [Qemu-devel] [PATCH 2/2] i2c: Move the bus class to i2c.h

Quoted 5 lines · Peter Maydell
Quoted 4 lines · Linus Walleij
Quoted 3 lines · Corey Minyard

Linus, Philippe, do you want me to submit this, or do you want to take it? You can pull it from:

Quoted 8 lines
Quoted 4 lines
Quoted 1 line

https://github.com/cminyard/qemu.git tags/i2c-bus-move

I don't have any commit rights, if you can push this to the QEMU master I will happily rebase my stuff and resubmit :)

I suggest you take Corey's 2 patches, add them to the front of your patchset and add your signed-off-by line to them. That way you don't have to wait for them to go into git master.

OK no problem!

Yours,
Linus Walleij

Reviewed-by on v1 1/3
#24 lore raw
In reply to Linus Walleij
Quoted 34 lines · Linus Walleij

The tx function of the DDC I2C slave emulation was returning 1 on all writes resulting in NACK in the I2C bus. Changing it to 0 makes the DDC I2C work fine with bit-banged I2C such as the versatile I2C.

I guess it was not affecting whatever I2C controller this was used with until now, but with the Versatile I2C it surely does not work.

---
 hw/i2c/i2c-ddc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/i2c/i2c-ddc.c +2 -3
index 199dac9e41c1..bec0c91e2dd0 100644
@@ -259,12 +259,12 @@ static int i2c_ddc_tx(I2CSlave *i2c, uint8_t data)
         s->reg = data;
         s->firstbyte = false;
         DPRINTF("[EDID] Written new pointer: %u\n", data);
-        return 1;
+        return 0;
     }
 
     /* Ignore all writes */
     s->reg++;
-    return 1;
+    return 0;
 }
 
 static void i2c_ddc_init(Object *obj)
--
Quoted 1 line

2.14.3

Does the guest attempting writes mean that we're missing functionality that the hardware has? Is it interesting?

PS: I didn't see a cover letter email with this patchset -- if you can send a cover letter with multi-email patchsets that makes our automated tooling much happier.

thanks
-- PMM