diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2016-06-14 16:04:25 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2016-06-14 16:04:25 +0100 |
commit | 1be08a0946b1a189ac72822182c37367e8cd3d87 (patch) | |
tree | 2c41b2e3abf67957ea1b75e7d5330ab2b1dff4fe /hw/i2c | |
parent | 7474f1be701f136b224af5e1abe55e97dc3f29a5 (diff) | |
parent | fe8fcf3d642b4de1369841bf6acac13e0ec8770d (diff) | |
download | qemu-1be08a0946b1a189ac72822182c37367e8cd3d87.zip qemu-1be08a0946b1a189ac72822182c37367e8cd3d87.tar.gz qemu-1be08a0946b1a189ac72822182c37367e8cd3d87.tar.bz2 |
Merge remote-tracking branch 'remotes/pmaydell/tags/pull-target-arm-20160614-2' into staging
target-arm queue:
* add PMU support for virt machine under KVM
* fix reset and migration of TTBCR(S)
* add virt-2.7 machine type
* QOMify various ARM devices
* implement xilinx DisplayPort device
* don't permit ARMv8-only Neon insns to work on ARMv7
# gpg: Signature made Tue 14 Jun 2016 16:01:45 BST
# gpg: using RSA key 0x3C2525ED14360CDE
# gpg: Good signature from "Peter Maydell <peter.maydell@linaro.org>"
# gpg: aka "Peter Maydell <pmaydell@gmail.com>"
# gpg: aka "Peter Maydell <pmaydell@chiark.greenend.org.uk>"
# Primary key fingerprint: E1A5 C593 CD41 9DE2 8E83 15CF 3C25 25ED 1436 0CDE
* remotes/pmaydell/tags/pull-target-arm-20160614-2: (30 commits)
target-arm: Don't permit ARMv8-only Neon insns on ARMv7
arm: xlnx-zynqmp: Add xlnx-dp and xlnx-dpdma
introduce xlnx-dp
introduce xlnx-dpdma
hw/i2c-ddc.c: Implement DDC I2C slave
introduce dpcd module
introduce aux-bus
i2c: Factor our send() and recv() common logic
i2c: implement broadcast write
i2cbus: remove unused dev field
hw/sd: QOM'ify pl181.c
hw/dma: QOM'ify pxa2xx_dma.c
hw/misc: QOM'ify mst_fpga.c
hw/misc: QOM'ify exynos4210_pmu.c
hw/misc: QOM'ify arm_l2x0.c
hw/gpio: QOM'ify zaurus.c
hw/gpio: QOM'ify pl061.c
hw/gpio: QOM'ify omap_gpio.c
hw/i2c: QOM'ify versatile_i2c.c
hw/i2c: QOM'ify omap_i2c.c
...
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/i2c')
-rw-r--r-- | hw/i2c/Makefile.objs | 1 | ||||
-rw-r--r-- | hw/i2c/bitbang_i2c.c | 14 | ||||
-rw-r--r-- | hw/i2c/core.c | 161 | ||||
-rw-r--r-- | hw/i2c/exynos4210_i2c.c | 13 | ||||
-rw-r--r-- | hw/i2c/i2c-ddc.c | 308 | ||||
-rw-r--r-- | hw/i2c/omap_i2c.c | 42 | ||||
-rw-r--r-- | hw/i2c/versatile_i2c.c | 19 |
7 files changed, 452 insertions, 106 deletions
diff --git a/hw/i2c/Makefile.objs b/hw/i2c/Makefile.objs index 1fd54ed..a081b8e 100644 --- a/hw/i2c/Makefile.objs +++ b/hw/i2c/Makefile.objs @@ -1,4 +1,5 @@ common-obj-y += core.o smbus.o smbus_eeprom.o +common-obj-$(CONFIG_DDC) += i2c-ddc.o common-obj-$(CONFIG_VERSATILE_I2C) += versatile_i2c.o common-obj-$(CONFIG_ACPI_X86) += smbus_ich9.o common-obj-$(CONFIG_APM) += pm_smbus.o diff --git a/hw/i2c/bitbang_i2c.c b/hw/i2c/bitbang_i2c.c index 6ed2060..d3a2989 100644 --- a/hw/i2c/bitbang_i2c.c +++ b/hw/i2c/bitbang_i2c.c @@ -210,13 +210,14 @@ static void bitbang_i2c_gpio_set(void *opaque, int irq, int level) } } -static int gpio_i2c_init(SysBusDevice *sbd) +static void gpio_i2c_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - GPIOI2CState *s = GPIO_I2C(dev); + DeviceState *dev = DEVICE(obj); + GPIOI2CState *s = GPIO_I2C(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); I2CBus *bus; - memory_region_init(&s->dummy_iomem, OBJECT(s), "gpio_i2c", 0); + memory_region_init(&s->dummy_iomem, obj, "gpio_i2c", 0); sysbus_init_mmio(sbd, &s->dummy_iomem); bus = i2c_init_bus(dev, "i2c"); @@ -224,16 +225,12 @@ static int gpio_i2c_init(SysBusDevice *sbd) qdev_init_gpio_in(dev, bitbang_i2c_gpio_set, 2); qdev_init_gpio_out(dev, &s->out, 1); - - return 0; } static void gpio_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = gpio_i2c_init; set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); dc->desc = "Virtual GPIO to I2C bridge"; } @@ -242,6 +239,7 @@ static const TypeInfo gpio_i2c_info = { .name = TYPE_GPIO_I2C, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(GPIOI2CState), + .instance_init = gpio_i2c_init, .class_init = gpio_i2c_class_init, }; diff --git a/hw/i2c/core.c b/hw/i2c/core.c index ba22104..abb3efb 100644 --- a/hw/i2c/core.c +++ b/hw/i2c/core.c @@ -10,12 +10,19 @@ #include "qemu/osdep.h" #include "hw/i2c/i2c.h" +typedef struct I2CNode I2CNode; + +struct I2CNode { + I2CSlave *elt; + QLIST_ENTRY(I2CNode) next; +}; + struct I2CBus { BusState qbus; - I2CSlave *current_dev; - I2CSlave *dev; + QLIST_HEAD(, I2CNode) current_devs; uint8_t saved_address; + bool broadcast; }; static Property i2c_props[] = { @@ -36,17 +43,12 @@ static void i2c_bus_pre_save(void *opaque) { I2CBus *bus = opaque; - bus->saved_address = bus->current_dev ? bus->current_dev->address : -1; -} - -static int i2c_bus_post_load(void *opaque, int version_id) -{ - I2CBus *bus = opaque; - - /* The bus is loaded before attached devices, so load and save the - current device id. Devices will check themselves as loaded. */ - bus->current_dev = NULL; - return 0; + bus->saved_address = -1; + if (!QLIST_EMPTY(&bus->current_devs)) { + if (!bus->broadcast) { + bus->saved_address = QLIST_FIRST(&bus->current_devs)->elt->address; + } + } } static const VMStateDescription vmstate_i2c_bus = { @@ -54,9 +56,9 @@ static const VMStateDescription vmstate_i2c_bus = { .version_id = 1, .minimum_version_id = 1, .pre_save = i2c_bus_pre_save, - .post_load = i2c_bus_post_load, .fields = (VMStateField[]) { VMSTATE_UINT8(saved_address, I2CBus), + VMSTATE_BOOL(broadcast, I2CBus), VMSTATE_END_OF_LIST() } }; @@ -67,6 +69,7 @@ I2CBus *i2c_init_bus(DeviceState *parent, const char *name) I2CBus *bus; bus = I2C_BUS(qbus_create(TYPE_I2C_BUS, parent, name)); + QLIST_INIT(&bus->current_devs); vmstate_register(NULL, -1, &vmstate_i2c_bus, bus); return bus; } @@ -79,7 +82,7 @@ void i2c_set_slave_address(I2CSlave *dev, uint8_t address) /* Return nonzero if bus is busy. */ int i2c_bus_busy(I2CBus *bus) { - return bus->current_dev != NULL; + return !QLIST_EMPTY(&bus->current_devs); } /* Returns non-zero if the address is not valid. */ @@ -87,95 +90,127 @@ int i2c_bus_busy(I2CBus *bus) int i2c_start_transfer(I2CBus *bus, uint8_t address, int recv) { BusChild *kid; - I2CSlave *slave = NULL; I2CSlaveClass *sc; + I2CNode *node; + + if (address == 0x00) { + /* + * This is a broadcast, the current_devs will be all the devices of the + * bus. + */ + bus->broadcast = true; + } QTAILQ_FOREACH(kid, &bus->qbus.children, sibling) { DeviceState *qdev = kid->child; I2CSlave *candidate = I2C_SLAVE(qdev); - if (candidate->address == address) { - slave = candidate; - break; + if ((candidate->address == address) || (bus->broadcast)) { + node = g_malloc(sizeof(struct I2CNode)); + node->elt = candidate; + QLIST_INSERT_HEAD(&bus->current_devs, node, next); + if (!bus->broadcast) { + break; + } } } - if (!slave) { + if (QLIST_EMPTY(&bus->current_devs)) { return 1; } - sc = I2C_SLAVE_GET_CLASS(slave); - /* If the bus is already busy, assume this is a repeated - start condition. */ - bus->current_dev = slave; - if (sc->event) { - sc->event(slave, recv ? I2C_START_RECV : I2C_START_SEND); + QLIST_FOREACH(node, &bus->current_devs, next) { + sc = I2C_SLAVE_GET_CLASS(node->elt); + /* If the bus is already busy, assume this is a repeated + start condition. */ + if (sc->event) { + sc->event(node->elt, recv ? I2C_START_RECV : I2C_START_SEND); + } } return 0; } void i2c_end_transfer(I2CBus *bus) { - I2CSlave *dev = bus->current_dev; I2CSlaveClass *sc; + I2CNode *node, *next; - if (!dev) { + if (QLIST_EMPTY(&bus->current_devs)) { return; } - sc = I2C_SLAVE_GET_CLASS(dev); - if (sc->event) { - sc->event(dev, I2C_FINISH); + QLIST_FOREACH_SAFE(node, &bus->current_devs, next, next) { + sc = I2C_SLAVE_GET_CLASS(node->elt); + if (sc->event) { + sc->event(node->elt, I2C_FINISH); + } + QLIST_REMOVE(node, next); + g_free(node); } - - bus->current_dev = NULL; + bus->broadcast = false; } -int i2c_send(I2CBus *bus, uint8_t data) +int i2c_send_recv(I2CBus *bus, uint8_t *data, bool send) { - I2CSlave *dev = bus->current_dev; I2CSlaveClass *sc; + I2CNode *node; + int ret = 0; + + if (send) { + QLIST_FOREACH(node, &bus->current_devs, next) { + sc = I2C_SLAVE_GET_CLASS(node->elt); + if (sc->send) { + ret = ret || sc->send(node->elt, *data); + } else { + ret = -1; + } + } + return ret ? -1 : 0; + } else { + if ((QLIST_EMPTY(&bus->current_devs)) || (bus->broadcast)) { + return -1; + } - if (!dev) { + sc = I2C_SLAVE_GET_CLASS(QLIST_FIRST(&bus->current_devs)->elt); + if (sc->recv) { + ret = sc->recv(QLIST_FIRST(&bus->current_devs)->elt); + if (ret < 0) { + return ret; + } else { + *data = ret; + return 0; + } + } return -1; } +} - sc = I2C_SLAVE_GET_CLASS(dev); - if (sc->send) { - return sc->send(dev, data); - } - - return -1; +int i2c_send(I2CBus *bus, uint8_t data) +{ + return i2c_send_recv(bus, &data, true); } int i2c_recv(I2CBus *bus) { - I2CSlave *dev = bus->current_dev; - I2CSlaveClass *sc; - - if (!dev) { - return -1; - } + uint8_t data; + int ret = i2c_send_recv(bus, &data, false); - sc = I2C_SLAVE_GET_CLASS(dev); - if (sc->recv) { - return sc->recv(dev); - } - - return -1; + return ret < 0 ? ret : data; } void i2c_nack(I2CBus *bus) { - I2CSlave *dev = bus->current_dev; I2CSlaveClass *sc; + I2CNode *node; - if (!dev) { + if (QLIST_EMPTY(&bus->current_devs)) { return; } - sc = I2C_SLAVE_GET_CLASS(dev); - if (sc->event) { - sc->event(dev, I2C_NACK); + QLIST_FOREACH(node, &bus->current_devs, next) { + sc = I2C_SLAVE_GET_CLASS(node->elt); + if (sc->event) { + sc->event(node->elt, I2C_NACK); + } } } @@ -183,9 +218,13 @@ static int i2c_slave_post_load(void *opaque, int version_id) { I2CSlave *dev = opaque; I2CBus *bus; + I2CNode *node; + bus = I2C_BUS(qdev_get_parent_bus(DEVICE(dev))); - if (bus->saved_address == dev->address) { - bus->current_dev = dev; + if ((bus->saved_address == dev->address) || (bus->broadcast)) { + node = g_malloc(sizeof(struct I2CNode)); + node->elt = dev; + QLIST_INSERT_HEAD(&bus->current_devs, node, next); } return 0; } diff --git a/hw/i2c/exynos4210_i2c.c b/hw/i2c/exynos4210_i2c.c index 8c2a2c1..c96fa7d 100644 --- a/hw/i2c/exynos4210_i2c.c +++ b/hw/i2c/exynos4210_i2c.c @@ -299,33 +299,32 @@ static void exynos4210_i2c_reset(DeviceState *d) s->scl_free = true; } -static int exynos4210_i2c_realize(SysBusDevice *sbd) +static void exynos4210_i2c_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - Exynos4210I2CState *s = EXYNOS4_I2C(dev); + DeviceState *dev = DEVICE(obj); + Exynos4210I2CState *s = EXYNOS4_I2C(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); - memory_region_init_io(&s->iomem, OBJECT(s), &exynos4210_i2c_ops, s, + memory_region_init_io(&s->iomem, obj, &exynos4210_i2c_ops, s, TYPE_EXYNOS4_I2C, EXYNOS4_I2C_MEM_SIZE); sysbus_init_mmio(sbd, &s->iomem); sysbus_init_irq(sbd, &s->irq); s->bus = i2c_init_bus(dev, "i2c"); - return 0; } static void exynos4210_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *sbdc = SYS_BUS_DEVICE_CLASS(klass); dc->vmsd = &exynos4210_i2c_vmstate; dc->reset = exynos4210_i2c_reset; - sbdc->init = exynos4210_i2c_realize; } static const TypeInfo exynos4210_i2c_type_info = { .name = TYPE_EXYNOS4_I2C, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(Exynos4210I2CState), + .instance_init = exynos4210_i2c_init, .class_init = exynos4210_i2c_class_init, }; diff --git a/hw/i2c/i2c-ddc.c b/hw/i2c/i2c-ddc.c new file mode 100644 index 0000000..1227212 --- /dev/null +++ b/hw/i2c/i2c-ddc.c @@ -0,0 +1,308 @@ +/* A simple I2C slave for returning monitor EDID data via DDC. + * + * Copyright (c) 2011 Linaro Limited + * Written by Peter Maydell + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, see <http://www.gnu.org/licenses/>. + */ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/i2c/i2c.h" +#include "hw/i2c/i2c-ddc.h" + +#ifndef DEBUG_I2CDDC +#define DEBUG_I2CDDC 0 +#endif + +#define DPRINTF(fmt, ...) do { \ + if (DEBUG_I2CDDC) { \ + qemu_log("i2c-ddc: " fmt , ## __VA_ARGS__); \ + } \ +} while (0); + +/* Structure defining a monitor's characteristics in a + * readable format: this should be passed to build_edid_blob() + * to convert it into the 128 byte binary EDID blob. + * Not all bits of the EDID are customisable here. + */ +struct EDIDData { + char manuf_id[3]; /* three upper case letters */ + uint16_t product_id; + uint32_t serial_no; + uint8_t manuf_week; + int manuf_year; + uint8_t h_cm; + uint8_t v_cm; + uint8_t gamma; + char monitor_name[14]; + char serial_no_string[14]; + /* Range limits */ + uint8_t vmin; /* Hz */ + uint8_t vmax; /* Hz */ + uint8_t hmin; /* kHz */ + uint8_t hmax; /* kHz */ + uint8_t pixclock; /* MHz / 10 */ + uint8_t timing_data[18]; +}; + +typedef struct EDIDData EDIDData; + +/* EDID data for a simple LCD monitor */ +static const EDIDData lcd_edid = { + /* The manuf_id ought really to be an assigned EISA ID */ + .manuf_id = "QMU", + .product_id = 0, + .serial_no = 1, + .manuf_week = 1, + .manuf_year = 2011, + .h_cm = 40, + .v_cm = 30, + .gamma = 0x78, + .monitor_name = "QEMU monitor", + .serial_no_string = "1", + .vmin = 40, + .vmax = 120, + .hmin = 30, + .hmax = 100, + .pixclock = 18, + .timing_data = { + /* Borrowed from a 21" LCD */ + 0x48, 0x3f, 0x40, 0x30, 0x62, 0xb0, 0x32, 0x40, 0x40, + 0xc0, 0x13, 0x00, 0x98, 0x32, 0x11, 0x00, 0x00, 0x1e + } +}; + +static uint8_t manuf_char_to_int(char c) +{ + return (c - 'A') & 0x1f; +} + +static void write_ascii_descriptor_block(uint8_t *descblob, uint8_t blocktype, + const char *string) +{ + /* Write an EDID Descriptor Block of the "ascii string" type */ + int i; + descblob[0] = descblob[1] = descblob[2] = descblob[4] = 0; + descblob[3] = blocktype; + /* The rest is 13 bytes of ASCII; if less then the rest must + * be filled with newline then spaces + */ + for (i = 5; i < 19; i++) { + descblob[i] = string[i - 5]; + if (!descblob[i]) { + break; + } + } + if (i < 19) { + descblob[i++] = '\n'; + } + for ( ; i < 19; i++) { + descblob[i] = ' '; + } +} + +static void write_range_limits_descriptor(const EDIDData *edid, + uint8_t *descblob) +{ + int i; + descblob[0] = descblob[1] = descblob[2] = descblob[4] = 0; + descblob[3] = 0xfd; + descblob[5] = edid->vmin; + descblob[6] = edid->vmax; + descblob[7] = edid->hmin; + descblob[8] = edid->hmax; + descblob[9] = edid->pixclock; + descblob[10] = 0; + descblob[11] = 0xa; + for (i = 12; i < 19; i++) { + descblob[i] = 0x20; + } +} + +static void build_edid_blob(const EDIDData *edid, uint8_t *blob) +{ + /* Write an EDID 1.3 format blob (128 bytes) based + * on the EDIDData structure. + */ + int i; + uint8_t cksum; + + /* 00-07 : header */ + blob[0] = blob[7] = 0; + for (i = 1 ; i < 7; i++) { + blob[i] = 0xff; + } + /* 08-09 : manufacturer ID */ + blob[8] = (manuf_char_to_int(edid->manuf_id[0]) << 2) + | (manuf_char_to_int(edid->manuf_id[1]) >> 3); + blob[9] = (manuf_char_to_int(edid->manuf_id[1]) << 5) + | manuf_char_to_int(edid->manuf_id[2]); + /* 10-11 : product ID code */ + blob[10] = edid->product_id; + blob[11] = edid->product_id >> 8; + blob[12] = edid->serial_no; + blob[13] = edid->serial_no >> 8; + blob[14] = edid->serial_no >> 16; + blob[15] = edid->serial_no >> 24; + /* 16 : week of manufacture */ + blob[16] = edid->manuf_week; + /* 17 : year of manufacture - 1990 */ + blob[17] = edid->manuf_year - 1990; + /* 18, 19 : EDID version and revision */ + blob[18] = 1; + blob[19] = 3; + /* 20 - 24 : basic display parameters */ + /* We are always a digital display */ + blob[20] = 0x80; + /* 21, 22 : max h/v size in cm */ + blob[21] = edid->h_cm; + blob[22] = edid->v_cm; + /* 23 : gamma (divide by 100 then add 1 for actual value) */ + blob[23] = edid->gamma; + /* 24 feature support: no power management, RGB, preferred timing mode, + * standard colour space + */ + blob[24] = 0x0e; + /* 25 - 34 : chromaticity coordinates. These are the + * standard sRGB chromaticity values + */ + blob[25] = 0xee; + blob[26] = 0x91; + blob[27] = 0xa3; + blob[28] = 0x54; + blob[29] = 0x4c; + blob[30] = 0x99; + blob[31] = 0x26; + blob[32] = 0x0f; + blob[33] = 0x50; + blob[34] = 0x54; + /* 35, 36 : Established timings: claim to support everything */ + blob[35] = blob[36] = 0xff; + /* 37 : manufacturer's reserved timing: none */ + blob[37] = 0; + /* 38 - 53 : standard timing identification + * don't claim anything beyond what the 'established timings' + * already provide. Unused slots must be (0x1, 0x1) + */ + for (i = 38; i < 54; i++) { + blob[i] = 0x1; + } + /* 54 - 71 : descriptor block 1 : must be preferred timing data */ + memcpy(blob + 54, edid->timing_data, 18); + /* 72 - 89, 90 - 107, 108 - 125 : descriptor block 2, 3, 4 + * Order not important, but we must have a monitor name and a + * range limits descriptor. + */ + write_range_limits_descriptor(edid, blob + 72); + write_ascii_descriptor_block(blob + 90, 0xfc, edid->monitor_name); + write_ascii_descriptor_block(blob + 108, 0xff, edid->serial_no_string); + + /* 126 : extension flag */ + blob[126] = 0; + + cksum = 0; + for (i = 0; i < 127; i++) { + cksum += blob[i]; + } + /* 127 : checksum */ + blob[127] = -cksum; + if (DEBUG_I2CDDC) { + qemu_hexdump((char *)blob, stdout, "", 128); + } +} + +static void i2c_ddc_reset(DeviceState *ds) +{ + I2CDDCState *s = I2CDDC(ds); + + s->firstbyte = false; + s->reg = 0; +} + +static void i2c_ddc_event(I2CSlave *i2c, enum i2c_event event) +{ + I2CDDCState *s = I2CDDC(i2c); + + if (event == I2C_START_SEND) { + s->firstbyte = true; + } +} + +static int i2c_ddc_rx(I2CSlave *i2c) +{ + I2CDDCState *s = I2CDDC(i2c); + + int value; + value = s->edid_blob[s->reg]; + s->reg++; + return value; +} + +static int i2c_ddc_tx(I2CSlave *i2c, uint8_t data) +{ + I2CDDCState *s = I2CDDC(i2c); + if (s->firstbyte) { + s->reg = data; + s->firstbyte = false; + DPRINTF("[EDID] Written new pointer: %u\n", data); + return 1; + } + + /* Ignore all writes */ + s->reg++; + return 1; +} + +static void i2c_ddc_init(Object *obj) +{ + I2CDDCState *s = I2CDDC(obj); + build_edid_blob(&lcd_edid, s->edid_blob); +} + +static const VMStateDescription vmstate_i2c_ddc = { + .name = TYPE_I2CDDC, + .version_id = 1, + .fields = (VMStateField[]) { + VMSTATE_BOOL(firstbyte, I2CDDCState), + VMSTATE_UINT8(reg, I2CDDCState), + VMSTATE_END_OF_LIST() + } +}; + +static void i2c_ddc_class_init(ObjectClass *oc, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(oc); + I2CSlaveClass *isc = I2C_SLAVE_CLASS(oc); + + dc->reset = i2c_ddc_reset; + dc->vmsd = &vmstate_i2c_ddc; + isc->event = i2c_ddc_event; + isc->recv = i2c_ddc_rx; + isc->send = i2c_ddc_tx; +} + +static TypeInfo i2c_ddc_info = { + .name = TYPE_I2CDDC, + .parent = TYPE_I2C_SLAVE, + .instance_size = sizeof(I2CDDCState), + .instance_init = i2c_ddc_init, + .class_init = i2c_ddc_class_init +}; + +static void ddc_register_devices(void) +{ + type_register_static(&i2c_ddc_info); +} + +type_init(ddc_register_devices); diff --git a/hw/i2c/omap_i2c.c b/hw/i2c/omap_i2c.c index 67fbbff..f7c92ea 100644 --- a/hw/i2c/omap_i2c.c +++ b/hw/i2c/omap_i2c.c @@ -22,6 +22,7 @@ #include "hw/arm/omap.h" #include "hw/sysbus.h" #include "qemu/error-report.h" +#include "qapi/error.h" #define TYPE_OMAP_I2C "omap_i2c" #define OMAP_I2C(obj) OBJECT_CHECK(OMAPI2CState, (obj), TYPE_OMAP_I2C) @@ -445,29 +446,35 @@ static const MemoryRegionOps omap_i2c_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int omap_i2c_init(SysBusDevice *sbd) +static void omap_i2c_init(Object *obj) +{ + DeviceState *dev = DEVICE(obj); + OMAPI2CState *s = OMAP_I2C(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); + + sysbus_init_irq(sbd, &s->irq); + sysbus_init_irq(sbd, &s->drq[0]); + sysbus_init_irq(sbd, &s->drq[1]); + sysbus_init_mmio(sbd, &s->iomem); + s->bus = i2c_init_bus(dev, NULL); +} + +static void omap_i2c_realize(DeviceState *dev, Error **errp) { - DeviceState *dev = DEVICE(sbd); OMAPI2CState *s = OMAP_I2C(dev); + memory_region_init_io(&s->iomem, OBJECT(dev), &omap_i2c_ops, s, "omap.i2c", + (s->revision < OMAP2_INTR_REV) ? 0x800 : 0x1000); + if (!s->fclk) { - error_report("omap_i2c: fclk not connected"); - return -1; + error_setg(errp, "omap_i2c: fclk not connected"); + return; } if (s->revision >= OMAP2_INTR_REV && !s->iclk) { /* Note that OMAP1 doesn't have a separate interface clock */ - error_report("omap_i2c: iclk not connected"); - return -1; + error_setg(errp, "omap_i2c: iclk not connected"); + return; } - - sysbus_init_irq(sbd, &s->irq); - sysbus_init_irq(sbd, &s->drq[0]); - sysbus_init_irq(sbd, &s->drq[1]); - memory_region_init_io(&s->iomem, OBJECT(s), &omap_i2c_ops, s, "omap.i2c", - (s->revision < OMAP2_INTR_REV) ? 0x800 : 0x1000); - sysbus_init_mmio(sbd, &s->iomem); - s->bus = i2c_init_bus(dev, NULL); - return 0; } static Property omap_i2c_properties[] = { @@ -480,18 +487,19 @@ static Property omap_i2c_properties[] = { static void omap_i2c_class_init(ObjectClass *klass, void *data) { DeviceClass *dc = DEVICE_CLASS(klass); - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - k->init = omap_i2c_init; + dc->props = omap_i2c_properties; dc->reset = omap_i2c_reset; /* Reason: pointer properties "iclk", "fclk" */ dc->cannot_instantiate_with_device_add_yet = true; + dc->realize = omap_i2c_realize; } static const TypeInfo omap_i2c_info = { .name = TYPE_OMAP_I2C, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(OMAPI2CState), + .instance_init = omap_i2c_init, .class_init = omap_i2c_class_init, }; diff --git a/hw/i2c/versatile_i2c.c b/hw/i2c/versatile_i2c.c index 0bce524..da9f298 100644 --- a/hw/i2c/versatile_i2c.c +++ b/hw/i2c/versatile_i2c.c @@ -79,32 +79,25 @@ static const MemoryRegionOps versatile_i2c_ops = { .endianness = DEVICE_NATIVE_ENDIAN, }; -static int versatile_i2c_init(SysBusDevice *sbd) +static void versatile_i2c_init(Object *obj) { - DeviceState *dev = DEVICE(sbd); - VersatileI2CState *s = VERSATILE_I2C(dev); + DeviceState *dev = DEVICE(obj); + VersatileI2CState *s = VERSATILE_I2C(obj); + SysBusDevice *sbd = SYS_BUS_DEVICE(obj); I2CBus *bus; bus = i2c_init_bus(dev, "i2c"); s->bitbang = bitbang_i2c_init(bus); - memory_region_init_io(&s->iomem, OBJECT(s), &versatile_i2c_ops, s, + memory_region_init_io(&s->iomem, obj, &versatile_i2c_ops, s, "versatile_i2c", 0x1000); sysbus_init_mmio(sbd, &s->iomem); - return 0; -} - -static void versatile_i2c_class_init(ObjectClass *klass, void *data) -{ - SysBusDeviceClass *k = SYS_BUS_DEVICE_CLASS(klass); - - k->init = versatile_i2c_init; } static const TypeInfo versatile_i2c_info = { .name = TYPE_VERSATILE_I2C, .parent = TYPE_SYS_BUS_DEVICE, .instance_size = sizeof(VersatileI2CState), - .class_init = versatile_i2c_class_init, + .instance_init = versatile_i2c_init, }; static void versatile_i2c_register_types(void) |