qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Cédric Le Goater" <clg@kaod.org>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: "Andrew Jeffery" <andrew@aj.id.au>,
	"Cédric Le Goater" <clg@kaod.org>,
	qemu-arm@nongnu.org, qemu-devel@nongnu.org,
	"Joel Stanley" <joel@jms.id.au>
Subject: [Qemu-devel] [PATCH 15/21] aspeed/i2c: Add AST2600 support
Date: Thu, 19 Sep 2019 07:49:56 +0200	[thread overview]
Message-ID: <20190919055002.6729-16-clg@kaod.org> (raw)
In-Reply-To: <20190919055002.6729-1-clg@kaod.org>

The I2C controller of the AST2400 and AST2500 SoCs have one IRQ shared
by all I2C busses. The AST2600 SoC I2C controller has one IRQ per bus
and 16 busses.

Signed-off-by: Cédric Le Goater <clg@kaod.org>
---
 include/hw/i2c/aspeed_i2c.h |  5 +++-
 hw/i2c/aspeed_i2c.c         | 46 +++++++++++++++++++++++++++++++++++--
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/include/hw/i2c/aspeed_i2c.h b/include/hw/i2c/aspeed_i2c.h
index 6e2dae7db818..13e01059189f 100644
--- a/include/hw/i2c/aspeed_i2c.h
+++ b/include/hw/i2c/aspeed_i2c.h
@@ -27,10 +27,11 @@
 #define TYPE_ASPEED_I2C "aspeed.i2c"
 #define TYPE_ASPEED_2400_I2C TYPE_ASPEED_I2C "-ast2400"
 #define TYPE_ASPEED_2500_I2C TYPE_ASPEED_I2C "-ast2500"
+#define TYPE_ASPEED_2600_I2C TYPE_ASPEED_I2C "-ast2600"
 #define ASPEED_I2C(obj) \
     OBJECT_CHECK(AspeedI2CState, (obj), TYPE_ASPEED_I2C)
 
-#define ASPEED_I2C_NR_BUSSES 14
+#define ASPEED_I2C_NR_BUSSES 16
 
 struct AspeedI2CState;
 
@@ -41,6 +42,7 @@ typedef struct AspeedI2CBus {
 
     I2CBus *bus;
     uint8_t id;
+    qemu_irq irq;
 
     uint32_t ctrl;
     uint32_t timing[2];
@@ -72,6 +74,7 @@ typedef struct AspeedI2CClass {
     uint8_t num_busses;
     uint8_t reg_size;
     uint8_t gap;
+    qemu_irq (*bus_get_irq)(AspeedI2CBus *);
 } AspeedI2CClass;
 
 I2CBus *aspeed_i2c_get_bus(DeviceState *dev, int busnr);
diff --git a/hw/i2c/aspeed_i2c.c b/hw/i2c/aspeed_i2c.c
index fabdb01e9747..06c119f385b8 100644
--- a/hw/i2c/aspeed_i2c.c
+++ b/hw/i2c/aspeed_i2c.c
@@ -145,10 +145,12 @@ static inline bool aspeed_i2c_bus_is_enabled(AspeedI2CBus *bus)
 
 static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus)
 {
+    AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
+
     bus->intr_status &= bus->intr_ctrl;
     if (bus->intr_status) {
         bus->controller->intr_status |= 1 << bus->id;
-        qemu_irq_raise(bus->controller->irq);
+        qemu_irq_raise(aic->bus_get_irq(bus));
     }
 }
 
@@ -273,6 +275,7 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,
                                  uint64_t value, unsigned size)
 {
     AspeedI2CBus *bus = opaque;
+    AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
     bool handle_rx;
 
     switch (offset) {
@@ -299,7 +302,7 @@ static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,
         bus->intr_status &= ~(value & 0x7FFF);
         if (!bus->intr_status) {
             bus->controller->intr_status &= ~(1 << bus->id);
-            qemu_irq_lower(bus->controller->irq);
+            qemu_irq_lower(aic->bus_get_irq(bus));
         }
         if (handle_rx && (bus->cmd & (I2CD_M_RX_CMD | I2CD_M_S_RX_CMD_LAST))) {
             aspeed_i2c_handle_rx_cmd(bus);
@@ -457,6 +460,8 @@ static void aspeed_i2c_realize(DeviceState *dev, Error **errp)
     for (i = 0; i < aic->num_busses; i++) {
         char name[32];
         int offset = i < aic->gap ? 1 : 5;
+
+        sysbus_init_irq(sbd, &s->busses[i].irq);
         snprintf(name, sizeof(name), "aspeed.i2c.%d", i);
         s->busses[i].controller = s;
         s->busses[i].id = i;
@@ -488,6 +493,11 @@ static const TypeInfo aspeed_i2c_info = {
     .abstract   = true,
 };
 
+static qemu_irq aspeed_2400_i2c_bus_get_irq(AspeedI2CBus *bus)
+{
+    return bus->controller->irq;
+}
+
 static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -498,6 +508,7 @@ static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
     aic->num_busses = 14;
     aic->reg_size = 0x40;
     aic->gap = 7;
+    aic->bus_get_irq = aspeed_2400_i2c_bus_get_irq;
 }
 
 static const TypeInfo aspeed_2400_i2c_info = {
@@ -506,6 +517,11 @@ static const TypeInfo aspeed_2400_i2c_info = {
     .class_init = aspeed_2400_i2c_class_init,
 };
 
+static qemu_irq aspeed_2500_i2c_bus_get_irq(AspeedI2CBus *bus)
+{
+    return bus->controller->irq;
+}
+
 static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -516,6 +532,7 @@ static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
     aic->num_busses = 14;
     aic->reg_size = 0x40;
     aic->gap = 7;
+    aic->bus_get_irq = aspeed_2500_i2c_bus_get_irq;
 }
 
 static const TypeInfo aspeed_2500_i2c_info = {
@@ -524,11 +541,36 @@ static const TypeInfo aspeed_2500_i2c_info = {
     .class_init = aspeed_2500_i2c_class_init,
 };
 
+static qemu_irq aspeed_2600_i2c_bus_get_irq(AspeedI2CBus *bus)
+{
+    return bus->irq;
+}
+
+static void aspeed_2600_i2c_class_init(ObjectClass *klass, void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+    AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
+
+    dc->desc = "ASPEED 2600 I2C Controller";
+
+    aic->num_busses = 16;
+    aic->reg_size = 0x80;
+    aic->gap = -1; /* no gap */
+    aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq;
+}
+
+static const TypeInfo aspeed_2600_i2c_info = {
+    .name = TYPE_ASPEED_2600_I2C,
+    .parent = TYPE_ASPEED_I2C,
+    .class_init = aspeed_2600_i2c_class_init,
+};
+
 static void aspeed_i2c_register_types(void)
 {
     type_register_static(&aspeed_i2c_info);
     type_register_static(&aspeed_2400_i2c_info);
     type_register_static(&aspeed_2500_i2c_info);
+    type_register_static(&aspeed_2600_i2c_info);
 }
 
 type_init(aspeed_i2c_register_types)
-- 
2.21.0



  parent reply	other threads:[~2019-09-19  6:10 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-19  5:49 [Qemu-devel] [PATCH 00/21] aspeed: Add support for the AST2600 SoC Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 01/21] aspeed/wdt: Check correct register for clock source Cédric Le Goater
2019-09-20  4:41   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 02/21] hw/sd/aspeed_sdhci: New device Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 03/21] hw: aspeed_scu: Add AST2600 support Cédric Le Goater
2019-09-20  4:10   ` Andrew Jeffery
2019-09-20 15:15     ` Cédric Le Goater
2019-09-21  4:37       ` Joel Stanley
2019-09-23  5:44         ` Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 04/21] aspeed/timer: Introduce an object class per SoC Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 05/21] aspeed/timer: Add support for control register 3 Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 06/21] aspeed/timer: Add AST2600 support Cédric Le Goater
2019-09-20  4:42   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 07/21] aspeed/timer: Add support for IRQ status register on the AST2600 Cédric Le Goater
2019-09-20  4:43   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 08/21] aspeed/sdmc: Introduce an object class per SoC Cédric Le Goater
2019-09-20  4:51   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 09/21] aspeed/sdmc: Add AST2600 support Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 10/21] watchdog/aspeed: Introduce an object class per SoC Cédric Le Goater
2019-09-20  4:44   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 11/21] hw: wdt_aspeed: Add AST2600 support Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 12/21] aspeed/smc: " Cédric Le Goater
2019-09-20  4:46   ` Joel Stanley
2019-09-20 15:24     ` Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 13/21] hw/gpio: Add in AST2600 specific implementation Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 14/21] aspeed/i2c: Introduce an object class per SoC Cédric Le Goater
2019-09-20  4:47   ` Joel Stanley
2019-09-19  5:49 ` Cédric Le Goater [this message]
2019-09-20  4:48   ` [PATCH 15/21] aspeed/i2c: Add AST2600 support Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 16/21] aspeed: Introduce an object class per SoC Cédric Le Goater
2019-09-20  4:49   ` Joel Stanley
2019-09-19  5:49 ` [Qemu-devel] [PATCH 17/21] aspeed/soc: Add AST2600 support Cédric Le Goater
2019-09-20  4:35   ` Joel Stanley
2019-09-20 15:17     ` Cédric Le Goater
2019-09-19  5:49 ` [Qemu-devel] [PATCH 18/21] aspeed: Add an AST2600 eval board Cédric Le Goater
2019-09-20  4:40   ` Joel Stanley
2019-09-19  5:50 ` [Qemu-devel] [PATCH 19/21] aspeed: Parameterise number of MACs Cédric Le Goater
2019-09-19  5:50 ` [Qemu-devel] [PATCH 20/21] aspeed: add support for the Aspeed MII controller of the AST2600 Cédric Le Goater
2019-09-20  4:50   ` Joel Stanley
2019-09-19  5:50 ` [Qemu-devel] [PATCH 21/21] aspeed/soc: Add ASPEED Video stub Cédric Le Goater
2019-09-19 20:56 ` [Qemu-devel] [PATCH 00/21] aspeed: Add support for the AST2600 SoC no-reply
2019-09-20  3:34   ` Andrew Jeffery
2019-09-20  6:19     ` Cédric Le Goater

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190919055002.6729-16-clg@kaod.org \
    --to=clg@kaod.org \
    --cc=andrew@aj.id.au \
    --cc=joel@jms.id.au \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).