Skip to contentSkip to conversation

aspeed/i2c: QOMify AspeedI2CBus

PATCH In review Cédric Le Goater 2 participants 3 messages Sep 7, 2021 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 aspeed/i2c: QOMify AspeedI2CBus

The AST2600 SoC realize routine needs to be adapted when connecting the I2C bus IRQs because the bus IRQs have moved to the AspeedI2CBus SysBus device, one level below the Aspeed I2C controller SysBus device.

---
 include/hw/i2c/aspeed_i2c.h |   8 ++-
 hw/arm/aspeed_ast2600.c     |   7 +--
 hw/i2c/aspeed_i2c.c         | 103 +++++++++++++++++++++++++++++-------
 3 files changed, 93 insertions(+), 25 deletions(-)
include/hw/i2c/aspeed_i2c.h +6 -2
index 565f83306624..4b9be09274c7 100644
@@ -36,7 +36,11 @@ OBJECT_DECLARE_TYPE(AspeedI2CState, AspeedI2CClass, ASPEED_I2C)
 
 struct AspeedI2CState;
 
-typedef struct AspeedI2CBus {
+#define TYPE_ASPEED_I2C_BUS "aspeed.i2c.bus"
+OBJECT_DECLARE_SIMPLE_TYPE(AspeedI2CBus, ASPEED_I2C_BUS)
+struct AspeedI2CBus {
+    SysBusDevice parent_obj;
+
     struct AspeedI2CState *controller;
 
     MemoryRegion mr;
@@ -54,7 +58,7 @@ typedef struct AspeedI2CBus {
     uint32_t pool_ctrl;
     uint32_t dma_addr;
     uint32_t dma_len;
-} AspeedI2CBus;
+};
 
 struct AspeedI2CState {
     SysBusDevice parent_obj;
hw/arm/aspeed_ast2600.c +2 -5
index c69f27dff62a..a70e4c48a73c 100644
@@ -337,11 +337,8 @@ static void aspeed_soc_ast2600_realize(DeviceState *dev, Error **errp)
     for (i = 0; i < ASPEED_I2C_GET_CLASS(&s->i2c)->num_busses; i++) {
         qemu_irq irq = qdev_get_gpio_in(DEVICE(&s->a7mpcore),
                                         sc->irqmap[ASPEED_DEV_I2C] + i);
-        /*
-         * The AST2600 SoC has one IRQ per I2C bus. Skip the common
-         * IRQ (AST2400 and AST2500) and connect all bussses.
-         */
-        sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), i + 1, irq);
+        /* The AST2600 I2C controller has one IRQ per bus. */
+        sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c.busses[i]), 0, irq);
     }
 
     /* FMC, The number of CS is set at the board level */
hw/i2c/aspeed_i2c.c +85 -18

140 lines not on this page · raw message

Signature · 1 line
2.31.1
#1 lore raw
Quoted 4 lines · Cédric Le Goater

The AST2600 SoC realize routine needs to be adapted when connecting the I2C bus IRQs because the bus IRQs have moved to the AspeedI2CBus SysBus device, one level below the Aspeed I2C controller SysBus device.

When did they move?

Quoted 11 lines
---
 include/hw/i2c/aspeed_i2c.h |   8 ++-
 hw/arm/aspeed_ast2600.c     |   7 +--
 hw/i2c/aspeed_i2c.c         | 103 +++++++++++++++++++++++++++++-------
 3 files changed, 93 insertions(+), 25 deletions(-)
hw/i2c/aspeed_i2c.c +4 -0
+static void aspeed_i2c_bus_realize(DeviceState *dev, Error **errp)
+{
+    AspeedI2CBus *s = ASPEED_I2C_BUS(dev);
+    char name[32];

hw/i2c/aspeed_i2c.c static void aspeed_i2c_class_init(ObjectClass *klass, void *data) · line 881

Quoted 10 lines
hw/i2c/aspeed_i2c.c +10 -0
+    AspeedI2CClass *aic;
+
+    if (!s->controller) {
+        error_setg(errp, TYPE_ASPEED_I2C_BUS ": 'controller' link not set");
+        return;
+    }
+
+    aic = ASPEED_I2C_GET_CLASS(s->controller);
+
+    snprintf(name, sizeof(name), TYPE_ASPEED_I2C_BUS ".%d", s->id);

Even if this particular case is safe, it is better to use:

g_autofree char *name = g_strdup_printf(TYPE_ASPEED_I2C_BUS ".%d",

                                          s->id);

So future developer copying your device code will be safe if they modify the format :)

Quoted 9 lines
hw/i2c/aspeed_i2c.c +9 -0
+
+    sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
+
+    s->bus = i2c_init_bus(dev, name);
+
+    memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i2c_bus_ops,
+                          s, name, aic->reg_size);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
+}
#2 lore raw
Quoted 7 lines · Philippe Mathieu-Daudé
Quoted 4 lines · Cédric Le Goater

The AST2600 SoC realize routine needs to be adapted when connecting the I2C bus IRQs because the bus IRQs have moved to the AspeedI2CBus SysBus device, one level below the Aspeed I2C controller SysBus device.

When did they move?

With this patch. I will rephrase.

Quoted 25 lines
Quoted 12 lines
---
 include/hw/i2c/aspeed_i2c.h |   8 ++-
 hw/arm/aspeed_ast2600.c     |   7 +--
 hw/i2c/aspeed_i2c.c         | 103 +++++++++++++++++++++++++++++-------
 3 files changed, 93 insertions(+), 25 deletions(-)
hw/i2c/aspeed_i2c.c +4 -0
+static void aspeed_i2c_bus_realize(DeviceState *dev, Error **errp)
+{
+    AspeedI2CBus *s = ASPEED_I2C_BUS(dev);
+    char name[32];

hw/i2c/aspeed_i2c.c static void aspeed_i2c_class_init(ObjectClass *klass, void *data) · line 881

Quoted 10 lines
hw/i2c/aspeed_i2c.c +10 -0
+    AspeedI2CClass *aic;
+
+    if (!s->controller) {
+        error_setg(errp, TYPE_ASPEED_I2C_BUS ": 'controller' link not set");
+        return;
+    }
+
+    aic = ASPEED_I2C_GET_CLASS(s->controller);
+
+    snprintf(name, sizeof(name), TYPE_ASPEED_I2C_BUS ".%d", s->id);

Even if this particular case is safe, it is better to use:

Quoted 5 lines

g_autofree char *name = g_strdup_printf(TYPE_ASPEED_I2C_BUS ".%d",

                                          s->id);

So future developer copying your device code will be safe if they modify the format :)

Yeah. I kind of like snprintf but I agree g_strdup_printf() is as good with the g_autofree variables. I will change the patches.

Thanks,

C.

Quoted 9 lines
Quoted 9 lines
hw/i2c/aspeed_i2c.c +9 -0
+
+    sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
+
+    s->bus = i2c_init_bus(dev, name);
+
+    memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i2c_bus_ops,
+                          s, name, aic->reg_size);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
+}