Skip to contentSkip to conversation

i2c: add aspeed i2c controller

PATCH Applied Cédric Le Goater 2 participants 4 messages May 31, 2016 – Jun 6, 2016 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 i2c: add aspeed i2c controller

The Aspeed AST2400 integrates a set of 14 I2C/SMBus bus controllers directly connected to the APB bus. They can be programmed as master or slave but the propopsed model only supports the master mode.

On the TODO list, we also have :

- improve and harden the state machine.
- bus recovery support (used by the Linux driver).
- transfer mode state machine bits. this is not strictly necessary as it is mostly used for debug. The bus busy bit is deducted from the I2C core engine of qemu.
- support of the pool buffer: 2048 bytes of internal SRAM (not used by the Linux driver).

---

Changes since v1 :

- rebased on mainline qemu
- added include "qemu/log.h" to fix compile breakage

 hw/arm/ast2400.c            |   16 +
 hw/i2c/Makefile.objs        |    1 
 hw/i2c/aspeed_i2c.c         |  450 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/ast2400.h    |    2 
 include/hw/i2c/aspeed_i2c.h |   62 ++++++
 5 files changed, 531 insertions(+)
hw/arm/ast2400.c +16 -0
Index: qemu-ast2400-mainline.git/hw/arm/ast2400.c
===================================================================
@@ -18,12 +18,14 @@
 #include "hw/arm/ast2400.h"
 #include "hw/char/serial.h"
 #include "qemu/log.h"
+#include "hw/i2c/aspeed_i2c.h"
 
 #define AST2400_UART_5_BASE      0x00184000
 #define AST2400_IOMEM_SIZE       0x00200000
 #define AST2400_IOMEM_BASE       0x1E600000
 #define AST2400_VIC_BASE         0x1E6C0000
 #define AST2400_TIMER_BASE       0x1E782000
+#define AST2400_I2C_BASE         0x1E78A000
 
 static const int uart_irqs[] = { 9, 32, 33, 34, 10 };
 static const int timer_irqs[] = { 16, 17, 18, 35, 36, 37, 38, 39, };
@@ -66,6 +68,10 @@ static void ast2400_init(Object *obj)
     object_initialize(&s->timerctrl, sizeof(s->timerctrl), TYPE_ASPEED_TIMER);
     object_property_add_child(obj, "timerctrl", OBJECT(&s->timerctrl), NULL);
     qdev_set_parent_bus(DEVICE(&s->timerctrl), sysbus_get_default());
+
+    object_initialize(&s->i2c, sizeof(s->i2c), TYPE_ASPEED_I2C);
+    object_property_add_child(obj, "i2c", OBJECT(&s->i2c), NULL);
+    qdev_set_parent_bus(DEVICE(&s->i2c), sysbus_get_default());
 }
 
 static void ast2400_realize(DeviceState *dev, Error **errp)
@@ -110,6 +116,16 @@ static void ast2400_realize(DeviceState
         serial_mm_init(&s->iomem, AST2400_UART_5_BASE, 2,
                        uart5, 38400, serial_hds[0], DEVICE_LITTLE_ENDIAN);
     }
+
+    /* I2C */
+    object_property_set_bool(OBJECT(&s->i2c), true, "realized", &err);
+    if (err) {
+        error_propagate(errp, err);
+        return;
+    }
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->i2c), 0, AST2400_I2C_BASE);
+    sysbus_connect_irq(SYS_BUS_DEVICE(&s->i2c), 0,
+                       qdev_get_gpio_in(DEVICE(&s->vic), 12));
 }
 
 static void ast2400_class_init(ObjectClass *oc, void *data)
hw/i2c/Makefile.objs +1 -0
Index: qemu-ast2400-mainline.git/hw/i2c/Makefile.objs
===================================================================
@@ -5,4 +5,5 @@ common-obj-$(CONFIG_APM) += pm_smbus.o
 common-obj-$(CONFIG_BITBANG_I2C) += bitbang_i2c.o
 common-obj-$(CONFIG_EXYNOS4) += exynos4210_i2c.o
 common-obj-$(CONFIG_IMX_I2C) += imx_i2c.o
+common-obj-$(CONFIG_ASPEED_SOC) += aspeed_i2c.o
 obj-$(CONFIG_OMAP) += omap_i2c.o
hw/i2c/aspeed_i2c.c new file +450 -0

450 lines not on this page · raw message

include/hw/i2c/aspeed_i2c.h new file +62 -0

62 lines not on this page · raw message

include/hw/arm/ast2400.h +2 -0
Index: qemu-ast2400-mainline.git/include/hw/arm/ast2400.h
===================================================================
@@ -15,6 +15,7 @@
 #include "hw/arm/arm.h"
 #include "hw/intc/aspeed_vic.h"
 #include "hw/timer/aspeed_timer.h"
+#include "hw/i2c/aspeed_i2c.h"
 
 typedef struct AST2400State {
     /*< private >*/
@@ -25,6 +26,7 @@ typedef struct AST2400State {
     MemoryRegion iomem;
     AspeedVICState vic;
     AspeedTimerCtrlState timerctrl;
+    AspeedI2CState i2c;
 } AST2400State;
 
 #define TYPE_AST2400 "ast2400"
#1 lore raw
Quoted 14 lines · Cédric Le Goater

The Aspeed AST2400 integrates a set of 14 I2C/SMBus bus controllers directly connected to the APB bus. They can be programmed as master or slave but the propopsed model only supports the master mode.

On the TODO list, we also have :

- improve and harden the state machine.
- bus recovery support (used by the Linux driver).
- transfer mode state machine bits. this is not strictly necessary as it is mostly used for debug. The bus busy bit is deducted from the I2C core engine of qemu.
- support of the pool buffer: 2048 bytes of internal SRAM (not used by the Linux driver).

Quoted 3 lines

---

Applied to target-arm.next, thanks.

-- PMM

#2 lore raw
In reply to Cédric Le Goater
Quoted 17 lines · Cédric Le Goater

The Aspeed AST2400 integrates a set of 14 I2C/SMBus bus controllers directly connected to the APB bus. They can be programmed as master or slave but the propopsed model only supports the master mode.

On the TODO list, we also have :

- improve and harden the state machine.
- bus recovery support (used by the Linux driver).
- transfer mode state machine bits. this is not strictly necessary as it is mostly used for debug. The bus busy bit is deducted from the I2C core engine of qemu.
- support of the pool buffer: 2048 bytes of internal SRAM (not used by the Linux driver).

hw/i2c/aspeed_i2c.c line 180

Quoted 9 lines
hw/i2c/aspeed_i2c.c new file +9 -0
+static inline uint64_t aspeed_i2c_bus_get_state(AspeedI2CBus *bus)
+{
+    return bus->cmd >> 19 & 0xF;
+}
+
+static inline void aspeed_i2c_bus_set_state(AspeedI2CBus *bus, uint64_t value)
+{
+    bus->cmd |= (value & 0xF) << 19;
+}

These two functions are unused, which means this doesn't compile with clang:

/Users/pm215/src/qemu-for-merges/hw/i2c/aspeed_i2c.c:172:24: warning:
unused function 'aspeed_i2c_bus_get_state' [-Wunused-function] static inline uint64_t aspeed_i2c_bus_get_state(AspeedI2CBus *bus)

                       ^
/Users/pm215/src/qemu-for-merges/hw/i2c/aspeed_i2c.c:177:20: warning:
unused function 'aspeed_i2c_bus_set_state' [-Wunused-function]
static inline void aspeed_i2c_bus_set_state(AspeedI2CBus *bus, uint64_t value)
                   ^

I have removed them in the version of the patch I put into target-arm.next.

thanks
-- PMM

#3 lore raw
Quoted 33 lines · Peter Maydell
Quoted 17 lines · Cédric Le Goater

The Aspeed AST2400 integrates a set of 14 I2C/SMBus bus controllers directly connected to the APB bus. They can be programmed as master or slave but the propopsed model only supports the master mode.

On the TODO list, we also have :

- improve and harden the state machine.
- bus recovery support (used by the Linux driver).
- transfer mode state machine bits. this is not strictly necessary as it is mostly used for debug. The bus busy bit is deducted from the I2C core engine of qemu.
- support of the pool buffer: 2048 bytes of internal SRAM (not used by the Linux driver).

hw/i2c/aspeed_i2c.c line 180

Quoted 9 lines
hw/i2c/aspeed_i2c.c new file +9 -0
+static inline uint64_t aspeed_i2c_bus_get_state(AspeedI2CBus *bus)
+{
+    return bus->cmd >> 19 & 0xF;
+}
+
+static inline void aspeed_i2c_bus_set_state(AspeedI2CBus *bus, uint64_t value)
+{
+    bus->cmd |= (value & 0xF) << 19;
+}

These two functions are unused, which means this doesn't compile with clang:

/Users/pm215/src/qemu-for-merges/hw/i2c/aspeed_i2c.c:172:24: warning:
unused function 'aspeed_i2c_bus_get_state' [-Wunused-function] static inline uint64_t aspeed_i2c_bus_get_state(AspeedI2CBus *bus)

Quoted 7 lines
                       ^
/Users/pm215/src/qemu-for-merges/hw/i2c/aspeed_i2c.c:177:20: warning:
unused function 'aspeed_i2c_bus_set_state' [-Wunused-function]
static inline void aspeed_i2c_bus_set_state(AspeedI2CBus *bus, uint64_t value)
                   ^

I have removed them in the version of the patch I put into target-arm.next.

OK. That was for the state machine I did not do finally.

Thanks,

C.

Quoted 3 lines

thanks
-- PMM