Skip to contentSkip to conversation

Add Aspeed GPIO test and Support Nuvoton Serial GPIO Expansion (SGPIO) device

PATCH Superseded Coco Li 3 participants 14 messages Sep 25, 2025 – Oct 13, 2025

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Coco Li

author
#0 lore raw

cover Add Aspeed GPIO test and Support Nuvoton Serial GPIO Expansion (SGPIO) device

GPIO series:
Added 32 bits property for ASPEED GPIO with updated qtests.

SGPIO series:
Implemented SGPIO device according for npcm8xx.
Two notable implementations left undone in these patches are:

1. Reading the data from the host controlled SIOX via register IOXDATR
2. On-demand with polling reading node

The reason for this ommitance is that both features are currently unused/umimplemented by the nuvoton driver.

The changes to qobject is used in both sets of patches. The patch series implements indexing gpios with array indices on top of accessing with registers.
The reasons for this is becasue it creates another easier way to access gpio. In our internal tests, we model complex behaviors with a large number of gpios, such as in fault injection, or in networking behaviors. Indexing multiple gpios at once allows qmp/side band client no longer hardcode and populate register names and manipulate them faster.

Updates since V0: added more descriptions on qobjects change in cover letter.

Coco Li (3):
hw/arm/npcm8xx.c: Add all IRQ ENUMs
hw/gpio/npcm8xx: Implement SIOX (SPGIO) device for NPCM without input
pin logic
hw/gpio/npcm8xx: Implement npcm sgpio device input pin logic

Felix Wu (2):
hw/gpio: Add property for ASPEED GPIO in 32 bits basis tests/qtest: Add qtest for for ASPEED GPIO gpio-set property

 hw/arm/npcm8xx.c                 |  66 +++-
 hw/gpio/aspeed_gpio.c            |  57 ++++
 hw/gpio/meson.build              |   1 +
 hw/gpio/npcm8xx_sgpio.c          | 533 +++++++++++++++++++++++++++++++
 hw/gpio/trace-events             |   4 +
 include/hw/arm/npcm8xx.h         |   2 +
 include/hw/gpio/npcm8xx_sgpio.h  |  45 +++
 include/qobject/qdict.h          |   1 +
 qobject/qdict.c                  |  13 +
 tests/qtest/aspeed_gpio-test.c   | 105 +++++-
 tests/qtest/meson.build          |   3 +-
 tests/qtest/npcm8xx_sgpio-test.c | 222 +++++++++++++
 12 files changed, 1039 insertions(+), 13 deletions(-)
 create mode 100644 hw/gpio/npcm8xx_sgpio.c
 create mode 100644 include/hw/gpio/npcm8xx_sgpio.h
 create mode 100644 tests/qtest/npcm8xx_sgpio-test.c
Signature · 1 line
2.51.0.536.g15c5d4f767-goog
author
#1 lore raw

PATCH 1/5 hw/gpio: Add property for ASPEED GPIO in 32 bits basis

From: Felix Wu <[email protected]>

Added 32 bits property for ASPEED GPIO. Previously it can only be access in bitwise manner.

This change gives ASPEED similar behavior as Nuvoton.

---
 hw/gpio/aspeed_gpio.c | 57 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
hw/gpio/aspeed_gpio.c +57 -0
index 609a556908..2d78bf9515 100644
@@ -1308,6 +1308,57 @@ static void aspeed_gpio_2700_write(void *opaque, hwaddr offset,
 }
 
 /* Setup functions */
+static void aspeed_gpio_set_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (!visit_type_uint32(v, name, &set_val, errp)) {
+        return;
+    }
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    aspeed_gpio_update(s, &s->sets[set_idx], set_val,
+                       ~s->sets[set_idx].direction);
+}
+
+static void aspeed_gpio_get_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    set_val = s->sets[set_idx].data_value;
+    visit_type_uint32(v, name, &set_val, errp);
+}
+
+/****************** Setup functions ******************/
 static const GPIOSetProperties ast2400_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
     [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
     [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },
@@ -1435,6 +1486,12 @@ static void aspeed_gpio_init(Object *obj)
             g_free(name);
         }
     }
+
+    for (int i = 0; i < agc->nr_gpio_sets; i++) {
+        char *name = g_strdup_printf("gpio-set[%d]", i);
+        object_property_add(obj, name, "uint32", aspeed_gpio_get_set,
+        aspeed_gpio_set_set, NULL, NULL);
+    }
 }
 
 static const VMStateDescription vmstate_gpio_regs = {
Signature · 1 line
2.51.0.536.g15c5d4f767-goog
maintainer
#2 lore raw

Re: [PATCH v1 1/5] hw/gpio: Add property for ASPEED GPIO in 32 bits basis

Quoted 5 lines · Coco Li

From: Felix Wu <[email protected]>

Added 32 bits property for ASPEED GPIO. Previously it can only be access in bitwise manner.

This change gives ASPEED similar behavior as Nuvoton.

I don't think this has adequately addressed my request on the prior series:

https://lore.kernel.org/all/e244fdb5d2d889674a583df8f8b9bc4bf8d476f4.camel@codeconstruct.com.au/

Can you please improve the commit message?

I don't have any particular concern with the implementation, other than understanding whether it's something that's reasonable to add to begin with. The "sets" and their indexes are somewhat an implementation detail. Exposing them might preclude a different implementation design, though I'm also not sure why we'd change at this point.

Andrew

Quoted 81 lines

---
 hw/gpio/aspeed_gpio.c | 57 +++++++++++++++++++++++++++++++++++++++++++

 1 file changed, 57 insertions(+)
hw/gpio/aspeed_gpio.c +0 -0
index 609a556908..2d78bf9515 100644
@@ -1308,6 +1308,57 @@ static void aspeed_gpio_2700_write(void *opaque, hwaddr offset,
  }


 /* Setup functions */

hw/gpio/aspeed_gpio.c +51 -0
+static void aspeed_gpio_set_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (!visit_type_uint32(v, name, &set_val, errp)) {
+        return;
+    }
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    aspeed_gpio_update(s, &s->sets[set_idx], set_val,
+                       ~s->sets[set_idx].direction);
+}
+
+static void aspeed_gpio_get_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    set_val = s->sets[set_idx].data_value;
+    visit_type_uint32(v, name, &set_val, errp);
+}
+
+/****************** Setup functions ******************/

 static const GPIOSetProperties ast2400_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
     [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
     [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },

hw/gpio/aspeed_gpio.c +6 -0
@@ -1435,6 +1486,12 @@ static void aspeed_gpio_init(Object *obj)
              g_free(name);
          }
      }
+
+    for (int i = 0; i < agc->nr_gpio_sets; i++) {
+        char *name = g_strdup_printf("gpio-set[%d]", i);
+        object_property_add(obj, name, "uint32", aspeed_gpio_get_set,
+        aspeed_gpio_set_set, NULL, NULL);
+    }
  }


 static const VMStateDescription vmstate_gpio_regs = {

author
#3 lore raw

Re: [PATCH v1 1/5] hw/gpio: Add property for ASPEED GPIO in 32 bits basis

Quoted 15 lines · Andrew Jeffery
Quoted 5 lines · Coco Li

From: Felix Wu <[email protected]>

Added 32 bits property for ASPEED GPIO. Previously it can only be access in bitwise manner.

This change gives ASPEED similar behavior as Nuvoton.

I don't think this has adequately addressed my request on the prior series:

https://lore.kernel.org/all/e244fdb5d2d889674a583df8f8b9bc4bf8d476f4.camel@codeconstruct.com.au/

Can you please improve the commit message?

Quoted 8 lines

I don't have any particular concern with the implementation, other than understanding whether it's something that's reasonable to add to begin with. The "sets" and their indexes are somewhat an implementation detail. Exposing them might preclude a different implementation design, though I'm also not sure why we'd change at this point.

Andrew

Hello Andrew,

To confirm that I understand your request, I should do the following:

1) remove the reference to Nuvoton behavior in the ASPEED patches (will do in follow up)
2) you asked for discussion of complex simulations, is the addition in the cover patch sufficient? Otherwise, could you elaborate on your comment here on what I can help provide please?

Best,
Coco

Quoted 81 lines
Quoted 81 lines
---
 hw/gpio/aspeed_gpio.c | 57 +++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 57 insertions(+)
hw/gpio/aspeed_gpio.c +57 -0
index 609a556908..2d78bf9515 100644
@@ -1308,6 +1308,57 @@ static void aspeed_gpio_2700_write(void *opaque, hwaddr offset,
 }
 
 /* Setup functions */
+static void aspeed_gpio_set_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (!visit_type_uint32(v, name, &set_val, errp)) {
+        return;
+    }
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    aspeed_gpio_update(s, &s->sets[set_idx], set_val,
+                       ~s->sets[set_idx].direction);
+}
+
+static void aspeed_gpio_get_set(Object *obj, Visitor *v,
+                                        const char *name, void *opaque,
+                                        Error **errp)
+{
+    uint32_t set_val = 0;
+    AspeedGPIOState *s = ASPEED_GPIO(obj);
+    AspeedGPIOClass *agc = ASPEED_GPIO_GET_CLASS(s);
+    int set_idx = 0;
+
+    if (sscanf(name, "gpio-set[%d]", &set_idx) != 1) {
+        error_setg(errp, "%s: error reading %s", __func__, name);
+        return;
+    }
+
+    if (set_idx >= agc->nr_gpio_sets || set_idx < 0) {
+        error_setg(errp, "%s: invalid set_idx %s", __func__, name);
+        return;
+    }
+
+    set_val = s->sets[set_idx].data_value;
+    visit_type_uint32(v, name, &set_val, errp);
+}
+
+/****************** Setup functions ******************/
 static const GPIOSetProperties ast2400_set_props[ASPEED_GPIO_MAX_NR_SETS] = {
     [0] = {0xffffffff,  0xffffffff,  {"A", "B", "C", "D"} },
     [1] = {0xffffffff,  0xffffffff,  {"E", "F", "G", "H"} },
@@ -1435,6 +1486,12 @@ static void aspeed_gpio_init(Object *obj)
             g_free(name);
         }
     }
+
+    for (int i = 0; i < agc->nr_gpio_sets; i++) {
+        char *name = g_strdup_printf("gpio-set[%d]", i);
+        object_property_add(obj, name, "uint32", aspeed_gpio_get_set,
+        aspeed_gpio_set_set, NULL, NULL);
+    }
 }
 
 static const VMStateDescription vmstate_gpio_regs = {
maintainer
#4 lore raw

Re: [PATCH v1 1/5] hw/gpio: Add property for ASPEED GPIO in 32 bits basis

Quoted 28 lines · Coco Li
Quoted 15 lines · Andrew Jeffery
Quoted 5 lines · Coco Li

From: Felix Wu <[email protected]>

Added 32 bits property for ASPEED GPIO. Previously it can only be access in bitwise manner.

This change gives ASPEED similar behavior as Nuvoton.

I don't think this has adequately addressed my request on the prior series:

https://lore.kernel.org/all/e244fdb5d2d889674a583df8f8b9bc4bf8d476f4.camel@codeconstruct.com.au/

Can you please improve the commit message?

Quoted 8 lines

I don't have any particular concern with the implementation, other than understanding whether it's something that's reasonable to add to begin with. The "sets" and their indexes are somewhat an implementation detail. Exposing them might preclude a different implementation design, though I'm also not sure why we'd change at this point.

Andrew

Hello Andrew,

Quoted 7 lines

To confirm that I understand your request, I should do the following:

1) remove the reference to Nuvoton behavior in the ASPEED patches (will do in follow up)
2) you asked for discussion of complex simulations, is the addition in the cover patch sufficient? Otherwise, could you elaborate on your comment here on what I can help provide please?

Can you please integrate the description from the cover letter into the commit message? It's not always the case that the series cover letter is tracked in the git history.

Andrew

author
#5 lore raw

PATCH 2/5 tests/qtest: Add qtest for for ASPEED GPIO gpio-set property

In reply to Coco Li

From: Felix Wu <[email protected]>

- Added qtests to test gpio-set property for ASPEED.
- Added function to get uint in qdict.

---
 include/qobject/qdict.h        |   1 +
 qobject/qdict.c                |  13 ++++
 tests/qtest/aspeed_gpio-test.c | 105 ++++++++++++++++++++++++++++++---
 3 files changed, 110 insertions(+), 9 deletions(-)
include/qobject/qdict.h +1 -0
index 903e6e5462..861996f08d 100644
@@ -57,6 +57,7 @@ void qdict_put_str(QDict *qdict, const char *key, const char *value);
 
 double qdict_get_double(const QDict *qdict, const char *key);
 int64_t qdict_get_int(const QDict *qdict, const char *key);
+uint64_t qdict_get_uint(const QDict *qdict, const char *key);
 bool qdict_get_bool(const QDict *qdict, const char *key);
 QList *qdict_get_qlist(const QDict *qdict, const char *key);
 QDict *qdict_get_qdict(const QDict *qdict, const char *key);
qobject/qdict.c +13 -0
index a90ac9ae2f..0dafe6d421 100644
@@ -209,6 +209,19 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)
     return qnum_get_int(qobject_to(QNum, qdict_get(qdict, key)));
 }
 
+/**
+ * qdict_get_uint(): Get an unsigned integer mapped by 'key'
+ *
+ * This function assumes that 'key' exists and it stores a
+ * QNum representable as uint.
+ *
+ * Return unsigned integer mapped by 'key'.
+ */
+uint64_t qdict_get_uint(const QDict *qdict, const char *key)
+{
+    return qnum_get_uint(qobject_to(QNum, qdict_get(qdict, key)));
+}
+
 /**
  * qdict_get_bool(): Get a bool mapped by 'key'
  *
tests/qtest/aspeed_gpio-test.c +96 -9

124 lines not on this page · raw message

Signature · 1 line
2.51.0.536.g15c5d4f767-goog
author
#6 lore raw

PATCH 3/5 hw/arm/npcm8xx.c: Add all IRQ ENUMs

In reply to Coco Li

In the process of implementing serial gpio and adding the corresponding ENUMs, also complete the list for npcm8xx.

---
 hw/arm/npcm8xx.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
hw/arm/npcm8xx.c +42 -1
index a276fea698..10887d07fa 100644
@@ -92,8 +92,14 @@ enum NPCM8xxInterrupt {
     NPCM8XX_GMAC2_IRQ,
     NPCM8XX_GMAC3_IRQ,
     NPCM8XX_GMAC4_IRQ,
-    NPCM8XX_MMC_IRQ             = 26,
+    NPCM8XX_ESPI_IRQ,
+    NPCM8XX_SIOX0_IRQ,
+    NPCM8XX_SIOX1_IRQ,
+    NPCM8XX_MC_IRQ              = 25,
+    NPCM8XX_MMC_IRQ,
     NPCM8XX_PSPI_IRQ            = 28,
+    NPCM8XX_VDMA_IRQ,
+    NPCM8XX_MCTP_IRQ,
     NPCM8XX_TIMER0_IRQ          = 32,   /* Timer Module 0 */
     NPCM8XX_TIMER1_IRQ,
     NPCM8XX_TIMER2_IRQ,
@@ -116,6 +122,14 @@ enum NPCM8xxInterrupt {
     NPCM8XX_OHCI1_IRQ,
     NPCM8XX_EHCI2_IRQ,
     NPCM8XX_OHCI2_IRQ,
+    NPCM8XX_SPI1_IRQ            = 82,
+    NPCM8XX_RNG_IRQ             = 84,
+    NPCM8XX_SPI0_IRQ            = 85,
+    NPCM8XX_SPI3_IRQ            = 87,
+    NPCM8XX_GDMA0_IRQ           = 88,
+    NPCM8XX_GDMA1_IRQ,
+    NPCM8XX_GDMA2_IRQ,
+    NPCM8XX_OTP_IRQ             = 92,
     NPCM8XX_PWM0_IRQ            = 93,   /* PWM module 0 */
     NPCM8XX_PWM1_IRQ,                   /* PWM module 1 */
     NPCM8XX_MFT0_IRQ            = 96,   /* MFT module 0 */
@@ -128,6 +142,11 @@ enum NPCM8xxInterrupt {
     NPCM8XX_MFT7_IRQ,                   /* MFT module 7 */
     NPCM8XX_PCI_MBOX1_IRQ       = 105,
     NPCM8XX_PCI_MBOX2_IRQ,
+    NPCM8XX_GPIO231_IRQ         = 108,
+    NPCM8XX_GPIO233_IRQ,
+    NPCM8XX_GPIO234_IRQ,
+    NPCM8XX_GPIO93_IRQ,
+    NPCM8XX_GPIO94_IRQ,
     NPCM8XX_GPIO0_IRQ           = 116,
     NPCM8XX_GPIO1_IRQ,
     NPCM8XX_GPIO2_IRQ,
@@ -163,6 +182,12 @@ enum NPCM8xxInterrupt {
     NPCM8XX_SMBUS24_IRQ,
     NPCM8XX_SMBUS25_IRQ,
     NPCM8XX_SMBUS26_IRQ,
+    NPCM8XX_FLM0_IRQ            = 160,
+    NPCM8XX_FLM1_IRQ,
+    NPCM8XX_FLM2_IRQ,
+    NPCM8XX_FLM3_IRQ,
+    NPCM8XX_JMT1_IRQ            = 188,
+    NPCM8XX_JMT2_IRQ,
     NPCM8XX_UART0_IRQ           = 192,
     NPCM8XX_UART1_IRQ,
     NPCM8XX_UART2_IRQ,
@@ -170,6 +195,22 @@ enum NPCM8xxInterrupt {
     NPCM8XX_UART4_IRQ,
     NPCM8XX_UART5_IRQ,
     NPCM8XX_UART6_IRQ,
+    NPCM8XX_I3C0_IRQ            = 224,
+    NPCM8XX_I3C1_IRQ,
+    NPCM8XX_I3C2_IRQ,
+    NPCM8XX_I3C3_IRQ,
+    NPCM8XX_I3C4_IRQ,
+    NPCM8XX_I3C5_IRQ,
+    NPCM8XX_A35INTERR_IRQ       = 240,
+    NPCM8XX_A35EXTERR_IRQ,
+    NPCM8XX_PMU0_IRQ,
+    NPCM8XX_PMU1_IRQ,
+    NPCM8XX_PMU2_IRQ,
+    NPCM8XX_PMU3_IRQ,
+    NPCM8XX_CTI0_IRQ,
+    NPCM8XX_CTI1_IRQ,
+    NPCM8XX_CTI2_IRQ,
+    NPCM8XX_CTI3_IRQ,
 };
 
 /* Total number of GIC interrupts, including internal Cortex-A35 interrupts. */
Signature · 1 line
2.51.0.536.g15c5d4f767-goog
#7 lore raw

Re: [PATCH v1 3/5] hw/arm/npcm8xx.c: Add all IRQ ENUMs

Hi,

Quoted 57 lines · Coco Li

In the process of implementing serial gpio and adding the corresponding ENUMs, also complete the list for npcm8xx.

---
  hw/arm/npcm8xx.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 42 insertions(+), 1 deletion(-)
hw/arm/npcm8xx.c +20 -1
index a276fea698..10887d07fa 100644
@@ -92,8 +92,14 @@ enum NPCM8xxInterrupt {
      NPCM8XX_GMAC2_IRQ,
      NPCM8XX_GMAC3_IRQ,
      NPCM8XX_GMAC4_IRQ,
-    NPCM8XX_MMC_IRQ             = 26,
+    NPCM8XX_ESPI_IRQ,
+    NPCM8XX_SIOX0_IRQ,
+    NPCM8XX_SIOX1_IRQ,
+    NPCM8XX_MC_IRQ              = 25,
+    NPCM8XX_MMC_IRQ,
      NPCM8XX_PSPI_IRQ            = 28,
+    NPCM8XX_VDMA_IRQ,
+    NPCM8XX_MCTP_IRQ,
      NPCM8XX_TIMER0_IRQ          = 32,   /* Timer Module 0 */
      NPCM8XX_TIMER1_IRQ,
      NPCM8XX_TIMER2_IRQ,
@@ -116,6 +122,14 @@ enum NPCM8xxInterrupt {
      NPCM8XX_OHCI1_IRQ,
      NPCM8XX_EHCI2_IRQ,
      NPCM8XX_OHCI2_IRQ,
+    NPCM8XX_SPI1_IRQ            = 82,
+    NPCM8XX_RNG_IRQ             = 84,
+    NPCM8XX_SPI0_IRQ            = 85,
+    NPCM8XX_SPI3_IRQ            = 87,
+    NPCM8XX_GDMA0_IRQ           = 88,
+    NPCM8XX_GDMA1_IRQ,
+    NPCM8XX_GDMA2_IRQ,
+    NPCM8XX_OTP_IRQ             = 92,
      NPCM8XX_PWM0_IRQ            = 93,   /* PWM module 0 */
      NPCM8XX_PWM1_IRQ,                   /* PWM module 1 */
      NPCM8XX_MFT0_IRQ            = 96,   /* MFT module 0 */
@@ -128,6 +142,11 @@ enum NPCM8xxInterrupt {
      NPCM8XX_MFT7_IRQ,                   /* MFT module 7 */
      NPCM8XX_PCI_MBOX1_IRQ       = 105,
      NPCM8XX_PCI_MBOX2_IRQ,
+    NPCM8XX_GPIO231_IRQ         = 108,
+    NPCM8XX_GPIO233_IRQ,
+    NPCM8XX_GPIO234_IRQ,
+    NPCM8XX_GPIO93_IRQ,
+    NPCM8XX_GPIO94_IRQ,
      NPCM8XX_GPIO0_IRQ           = 116,
      NPCM8XX_GPIO1_IRQ,
      NPCM8XX_GPIO2_IRQ,

hw/arm/npcm8xx.c enum NPCM8xxInterrupt { · line 188

Quoted 7 lines
hw/arm/npcm8xx.c +4 -0
@@ -163,6 +182,12 @@ enum NPCM8xxInterrupt {
      NPCM8XX_SMBUS24_IRQ,
      NPCM8XX_SMBUS25_IRQ,
      NPCM8XX_SMBUS26_IRQ,
+    NPCM8XX_FLM0_IRQ            = 160,
+    NPCM8XX_FLM1_IRQ,
+    NPCM8XX_FLM2_IRQ,
+    NPCM8XX_FLM3_IRQ,

Minor style comment, maybe worth adding a new line when the following enum is not contiguous.

Regards,

Phil.

Quoted 28 lines
hw/arm/npcm8xx.c +18 -0
+    NPCM8XX_JMT1_IRQ            = 188,
+    NPCM8XX_JMT2_IRQ,
      NPCM8XX_UART0_IRQ           = 192,
      NPCM8XX_UART1_IRQ,
      NPCM8XX_UART2_IRQ,
@@ -170,6 +195,22 @@ enum NPCM8xxInterrupt {
      NPCM8XX_UART4_IRQ,
      NPCM8XX_UART5_IRQ,
      NPCM8XX_UART6_IRQ,
+    NPCM8XX_I3C0_IRQ            = 224,
+    NPCM8XX_I3C1_IRQ,
+    NPCM8XX_I3C2_IRQ,
+    NPCM8XX_I3C3_IRQ,
+    NPCM8XX_I3C4_IRQ,
+    NPCM8XX_I3C5_IRQ,
+    NPCM8XX_A35INTERR_IRQ       = 240,
+    NPCM8XX_A35EXTERR_IRQ,
+    NPCM8XX_PMU0_IRQ,
+    NPCM8XX_PMU1_IRQ,
+    NPCM8XX_PMU2_IRQ,
+    NPCM8XX_PMU3_IRQ,
+    NPCM8XX_CTI0_IRQ,
+    NPCM8XX_CTI1_IRQ,
+    NPCM8XX_CTI2_IRQ,
+    NPCM8XX_CTI3_IRQ,
  };
 
  /* Total number of GIC interrupts, including internal Cortex-A35 interrupts. */
author
#8 lore raw

Re: [PATCH v1 3/5] hw/arm/npcm8xx.c: Add all IRQ ENUMs

Hi Phil,

Thanks for the review!
It looks like IRQ mapping enums on other boards also generally do not have line breaks, is it ok if I keep it like this for consistency sake?

Best,
Coco

Quoted 106 lines · Philippe Mathieu-Daudé

Hi,

Quoted 57 lines · Coco Li

In the process of implementing serial gpio and adding the corresponding ENUMs, also complete the list for npcm8xx.

---
  hw/arm/npcm8xx.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 42 insertions(+), 1 deletion(-)
hw/arm/npcm8xx.c +20 -1
index a276fea698..10887d07fa 100644
@@ -92,8 +92,14 @@ enum NPCM8xxInterrupt {
      NPCM8XX_GMAC2_IRQ,
      NPCM8XX_GMAC3_IRQ,
      NPCM8XX_GMAC4_IRQ,
-    NPCM8XX_MMC_IRQ             = 26,
+    NPCM8XX_ESPI_IRQ,
+    NPCM8XX_SIOX0_IRQ,
+    NPCM8XX_SIOX1_IRQ,
+    NPCM8XX_MC_IRQ              = 25,
+    NPCM8XX_MMC_IRQ,
      NPCM8XX_PSPI_IRQ            = 28,
+    NPCM8XX_VDMA_IRQ,
+    NPCM8XX_MCTP_IRQ,
      NPCM8XX_TIMER0_IRQ          = 32,   /* Timer Module 0 */
      NPCM8XX_TIMER1_IRQ,
      NPCM8XX_TIMER2_IRQ,
@@ -116,6 +122,14 @@ enum NPCM8xxInterrupt {
      NPCM8XX_OHCI1_IRQ,
      NPCM8XX_EHCI2_IRQ,
      NPCM8XX_OHCI2_IRQ,
+    NPCM8XX_SPI1_IRQ            = 82,
+    NPCM8XX_RNG_IRQ             = 84,
+    NPCM8XX_SPI0_IRQ            = 85,
+    NPCM8XX_SPI3_IRQ            = 87,
+    NPCM8XX_GDMA0_IRQ           = 88,
+    NPCM8XX_GDMA1_IRQ,
+    NPCM8XX_GDMA2_IRQ,
+    NPCM8XX_OTP_IRQ             = 92,
      NPCM8XX_PWM0_IRQ            = 93,   /* PWM module 0 */
      NPCM8XX_PWM1_IRQ,                   /* PWM module 1 */
      NPCM8XX_MFT0_IRQ            = 96,   /* MFT module 0 */
@@ -128,6 +142,11 @@ enum NPCM8xxInterrupt {
      NPCM8XX_MFT7_IRQ,                   /* MFT module 7 */
      NPCM8XX_PCI_MBOX1_IRQ       = 105,
      NPCM8XX_PCI_MBOX2_IRQ,
+    NPCM8XX_GPIO231_IRQ         = 108,
+    NPCM8XX_GPIO233_IRQ,
+    NPCM8XX_GPIO234_IRQ,
+    NPCM8XX_GPIO93_IRQ,
+    NPCM8XX_GPIO94_IRQ,
      NPCM8XX_GPIO0_IRQ           = 116,
      NPCM8XX_GPIO1_IRQ,
      NPCM8XX_GPIO2_IRQ,

hw/arm/npcm8xx.c enum NPCM8xxInterrupt { · line 188

Quoted 7 lines
hw/arm/npcm8xx.c +4 -0
@@ -163,6 +182,12 @@ enum NPCM8xxInterrupt {
      NPCM8XX_SMBUS24_IRQ,
      NPCM8XX_SMBUS25_IRQ,
      NPCM8XX_SMBUS26_IRQ,
+    NPCM8XX_FLM0_IRQ            = 160,
+    NPCM8XX_FLM1_IRQ,
+    NPCM8XX_FLM2_IRQ,
+    NPCM8XX_FLM3_IRQ,

Minor style comment, maybe worth adding a new line when the following enum is not contiguous.

Regards,

Phil.

Quoted 18 lines
hw/arm/npcm8xx.c +11 -0
+    NPCM8XX_JMT1_IRQ            = 188,
+    NPCM8XX_JMT2_IRQ,
      NPCM8XX_UART0_IRQ           = 192,
      NPCM8XX_UART1_IRQ,
      NPCM8XX_UART2_IRQ,
@@ -170,6 +195,22 @@ enum NPCM8xxInterrupt {
      NPCM8XX_UART4_IRQ,
      NPCM8XX_UART5_IRQ,
      NPCM8XX_UART6_IRQ,
+    NPCM8XX_I3C0_IRQ            = 224,
+    NPCM8XX_I3C1_IRQ,
+    NPCM8XX_I3C2_IRQ,
+    NPCM8XX_I3C3_IRQ,
+    NPCM8XX_I3C4_IRQ,
+    NPCM8XX_I3C5_IRQ,
+    NPCM8XX_A35INTERR_IRQ       = 240,
+    NPCM8XX_A35EXTERR_IRQ,
+    NPCM8XX_PMU0_IRQ,

hw/arm/npcm8xx.c enum NPCM8xxInterrupt { · line 216

Quoted 10 lines
hw/arm/npcm8xx.c +7 -0
+    NPCM8XX_PMU1_IRQ,
+    NPCM8XX_PMU2_IRQ,
+    NPCM8XX_PMU3_IRQ,
+    NPCM8XX_CTI0_IRQ,
+    NPCM8XX_CTI1_IRQ,
+    NPCM8XX_CTI2_IRQ,
+    NPCM8XX_CTI3_IRQ,
  };
 
  /* Total number of GIC interrupts, including internal Cortex-A35

interrupts. */

#9 lore raw

Re: [PATCH v1 3/5] hw/arm/npcm8xx.c: Add all IRQ ENUMs

Quoted 4 lines · Coco Li

Hi Phil,

Thanks for the review!
It looks like IRQ mapping enums on other boards also generally do not have line breaks, is it ok if I keep it like this for consistency sake?

This is just a suggestion, since you are modifying these lines. I won't object if you keep the old style, and I don't mind if the other boards as not changed (also, can be done as future cleanup).

(please avoid top-posting on technical mailing lists).

Quoted 83 lines

Best,
Coco

On Wed, Sep 24, 2025 at 6:08 PM Philippe Mathieu-Daudé <[email protected] <mailto:[email protected]>> wrote:

Hi,

On 25/9/25 02:58, Coco Li wrote:
> In the process of implementing serial gpio and adding the
corresponding
> ENUMs, also complete the list for npcm8xx.
>
> Signed-off-by: Coco Li <[email protected]
<mailto:[email protected]>>
> Reviewed-by: Hao Wu <[email protected]
<mailto:[email protected]>>
> ---
>   hw/arm/npcm8xx.c | 43 ++++++++++++++++++++++++++++++++++++++++++- >   1 file changed, 42 insertions(+), 1 deletion(-)
>
> diff --git a/hw/arm/npcm8xx.c b/hw/arm/npcm8xx.c
> index a276fea698..10887d07fa 100644
> --- a/hw/arm/npcm8xx.c
> +++ b/hw/arm/npcm8xx.c
> @@ -92,8 +92,14 @@ enum NPCM8xxInterrupt {
>       NPCM8XX_GMAC2_IRQ,
>       NPCM8XX_GMAC3_IRQ,
>       NPCM8XX_GMAC4_IRQ,
> -    NPCM8XX_MMC_IRQ             = 26,
> +    NPCM8XX_ESPI_IRQ,
> +    NPCM8XX_SIOX0_IRQ,
> +    NPCM8XX_SIOX1_IRQ,
> +    NPCM8XX_MC_IRQ              = 25,
> +    NPCM8XX_MMC_IRQ,
>       NPCM8XX_PSPI_IRQ            = 28,
> +    NPCM8XX_VDMA_IRQ,
> +    NPCM8XX_MCTP_IRQ,
>       NPCM8XX_TIMER0_IRQ          = 32,   /* Timer Module 0 */ >       NPCM8XX_TIMER1_IRQ,
>       NPCM8XX_TIMER2_IRQ,
> @@ -116,6 +122,14 @@ enum NPCM8xxInterrupt {
>       NPCM8XX_OHCI1_IRQ,
>       NPCM8XX_EHCI2_IRQ,
>       NPCM8XX_OHCI2_IRQ,
> +    NPCM8XX_SPI1_IRQ            = 82,
> +    NPCM8XX_RNG_IRQ             = 84,
> +    NPCM8XX_SPI0_IRQ            = 85,
> +    NPCM8XX_SPI3_IRQ            = 87,
> +    NPCM8XX_GDMA0_IRQ           = 88,
> +    NPCM8XX_GDMA1_IRQ,
> +    NPCM8XX_GDMA2_IRQ,
> +    NPCM8XX_OTP_IRQ             = 92,
>       NPCM8XX_PWM0_IRQ            = 93,   /* PWM module 0 */ >       NPCM8XX_PWM1_IRQ,                   /* PWM module 1 */ >       NPCM8XX_MFT0_IRQ            = 96,   /* MFT module 0 */ > @@ -128,6 +142,11 @@ enum NPCM8xxInterrupt {
>       NPCM8XX_MFT7_IRQ,                   /* MFT module 7 */ >       NPCM8XX_PCI_MBOX1_IRQ       = 105,
>       NPCM8XX_PCI_MBOX2_IRQ,
> +    NPCM8XX_GPIO231_IRQ         = 108,
> +    NPCM8XX_GPIO233_IRQ,
> +    NPCM8XX_GPIO234_IRQ,
> +    NPCM8XX_GPIO93_IRQ,
> +    NPCM8XX_GPIO94_IRQ,
>       NPCM8XX_GPIO0_IRQ           = 116,
>       NPCM8XX_GPIO1_IRQ,
>       NPCM8XX_GPIO2_IRQ,
> @@ -163,6 +182,12 @@ enum NPCM8xxInterrupt {
>       NPCM8XX_SMBUS24_IRQ,
>       NPCM8XX_SMBUS25_IRQ,
>       NPCM8XX_SMBUS26_IRQ,
> +    NPCM8XX_FLM0_IRQ            = 160,
> +    NPCM8XX_FLM1_IRQ,
> +    NPCM8XX_FLM2_IRQ,
> +    NPCM8XX_FLM3_IRQ,

Minor style comment, maybe worth adding a new line when the following enum is not contiguous.

Regards,

Phil.

author
#10 lore raw

PATCH 4/5 hw/gpio/npcm8xx: Implement SIOX (SPGIO) device for NPCM without input pin logic

In reply to Coco Li
---
 hw/arm/npcm8xx.c                 |  23 +-
 hw/gpio/meson.build              |   1 +
 hw/gpio/npcm8xx_sgpio.c          | 425 +++++++++++++++++++++++++++++++
 hw/gpio/trace-events             |   4 +
 include/hw/arm/npcm8xx.h         |   2 +
 include/hw/gpio/npcm8xx_sgpio.h  |  45 ++++
 tests/qtest/meson.build          |   3 +-
 tests/qtest/npcm8xx_sgpio-test.c | 100 ++++++++
 8 files changed, 600 insertions(+), 3 deletions(-)
 create mode 100644 hw/gpio/npcm8xx_sgpio.c
 create mode 100644 include/hw/gpio/npcm8xx_sgpio.h
 create mode 100644 tests/qtest/npcm8xx_sgpio-test.c
hw/arm/npcm8xx.c +21 -2
index 10887d07fa..ae72c6d54b 100644
@@ -369,6 +369,11 @@ static const struct {
     },
 };
 
+static const hwaddr npcm8xx_sgpio_addr[] = {
+    0xf0101000,
+    0xf0102000,
+};
+
 static const struct {
     const char *name;
     hwaddr regs_addr;
@@ -474,6 +479,11 @@ static void npcm8xx_init(Object *obj)
     }
 
 
+    for (i = 0; i < ARRAY_SIZE(s->sgpio); i++) {
+        object_initialize_child(obj, "sgpio[*]",
+                                &s->sgpio[i], TYPE_NPCM8XX_SGPIO);
+    }
+
     for (i = 0; i < ARRAY_SIZE(s->smbus); i++) {
         object_initialize_child(obj, "smbus[*]", &s->smbus[i],
                                 TYPE_NPCM7XX_SMBUS);
@@ -671,6 +681,17 @@ static void npcm8xx_realize(DeviceState *dev, Error **errp)
                            npcm8xx_irq(s, NPCM8XX_GPIO0_IRQ + i));
     }
 
+    /* Serial SIOX modules. Cannot fail. */
+    QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm8xx_sgpio_addr) != ARRAY_SIZE(s->sgpio));
+    for (i = 0; i < ARRAY_SIZE(s->sgpio); i++) {
+        Object *obj = OBJECT(&s->sgpio[i]);
+
+        sysbus_realize(SYS_BUS_DEVICE(obj), &error_abort);
+        sysbus_mmio_map(SYS_BUS_DEVICE(obj), 0, npcm8xx_sgpio_addr[i]);
+        sysbus_connect_irq(SYS_BUS_DEVICE(obj), 0,
+                           npcm8xx_irq(s, NPCM8XX_SIOX0_IRQ + i));
+    }
+
     /* SMBus modules. Cannot fail. */
     QEMU_BUILD_BUG_ON(ARRAY_SIZE(npcm8xx_smbus_addr) != ARRAY_SIZE(s->smbus));
     for (i = 0; i < ARRAY_SIZE(s->smbus); i++) {
@@ -818,8 +839,6 @@ static void npcm8xx_realize(DeviceState *dev, Error **errp)
     create_unimplemented_device("npcm8xx.bt",           0xf0030000,   4 * KiB);
     create_unimplemented_device("npcm8xx.espi",         0xf009f000,   4 * KiB);
     create_unimplemented_device("npcm8xx.peci",         0xf0100000,   4 * KiB);
-    create_unimplemented_device("npcm8xx.siox[1]",      0xf0101000,   4 * KiB);
-    create_unimplemented_device("npcm8xx.siox[2]",      0xf0102000,   4 * KiB);
     create_unimplemented_device("npcm8xx.tmps",         0xf0188000,   4 * KiB);
     create_unimplemented_device("npcm8xx.viru1",        0xf0204000,   4 * KiB);
     create_unimplemented_device("npcm8xx.viru2",        0xf0205000,   4 * KiB);
hw/gpio/meson.build +1 -0
index 74840619c0..8a3879983c 100644
@@ -18,3 +18,4 @@ system_ss.add(when: 'CONFIG_STM32L4X5_SOC', if_true: files('stm32l4x5_gpio.c'))
 system_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files('aspeed_gpio.c'))
 system_ss.add(when: 'CONFIG_SIFIVE_GPIO', if_true: files('sifive_gpio.c'))
 system_ss.add(when: 'CONFIG_PCF8574', if_true: files('pcf8574.c'))
+system_ss.add(when: 'CONFIG_NPCM8XX', if_true: files('npcm8xx_sgpio.c'))
hw/gpio/npcm8xx_sgpio.c new file +425 -0

425 lines not on this page · raw message

hw/gpio/trace-events +4 -0
index cea896b28f..5a3625cabc 100644
@@ -12,6 +12,10 @@ npcm7xx_gpio_set_input(const char *id, int32_t line, int32_t level) "%s line: %"
 npcm7xx_gpio_set_output(const char *id, int32_t line, int32_t level) "%s line: %" PRIi32 " level: %" PRIi32
 npcm7xx_gpio_update_events(const char *id, uint32_t evst, uint32_t even) "%s evst: 0x%08" PRIx32 " even: 0x%08" PRIx32
 
+# npcm8xx_sgpio.c
+npcm8xx_sgpio_read(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
+npcm8xx_sgpio_write(const char *id, uint64_t offset, uint64_t value) " %s offset: 0x%04" PRIx64 " value 0x%08" PRIx64
+
 # nrf51_gpio.c
 nrf51_gpio_read(uint64_t offset, uint64_t r) "offset 0x%" PRIx64 " value 0x%" PRIx64
 nrf51_gpio_write(uint64_t offset, uint64_t value) "offset 0x%" PRIx64 " value 0x%" PRIx64
include/hw/arm/npcm8xx.h +2 -0
index a8377db490..2d177329b8 100644
@@ -21,6 +21,7 @@
 #include "hw/cpu/cluster.h"
 #include "hw/gpio/npcm7xx_gpio.h"
 #include "hw/i2c/npcm7xx_smbus.h"
+#include "hw/gpio/npcm8xx_sgpio.h"
 #include "hw/intc/arm_gic_common.h"
 #include "hw/mem/npcm7xx_mc.h"
 #include "hw/misc/npcm_clk.h"
@@ -104,6 +105,7 @@ struct NPCM8xxState {
     NPCMPCSState        pcs;
     NPCM7xxSDHCIState   mmc;
     NPCMPSPIState       pspi;
+    NPCM8xxSGPIOState   sgpio[2];
 };
 
 struct NPCM8xxClass {
include/hw/gpio/npcm8xx_sgpio.h new file +45 -0

45 lines not on this page · raw message

tests/qtest/meson.build +2 -1
index 669d07c06b..12737ad21f 100644
@@ -212,7 +212,8 @@ qtests_npcm7xx = \
    'npcm7xx_watchdog_timer-test'] + \
    (slirp.found() ? ['npcm7xx_emc-test'] : [])
 qtests_npcm8xx = \
-  ['npcm_gmac-test']
+  ['npcm_gmac-test',
+   'npcm8xx_sgpio-test',]
 qtests_aspeed = \
   ['aspeed_gpio-test',
    'aspeed_hace-test',
tests/qtest/npcm8xx_sgpio-test.c new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.51.0.536.g15c5d4f767-goog
author
#11 lore raw

PATCH 5/5 hw/gpio/npcm8xx: Implement npcm sgpio device input pin logic

In reply to Coco Li
---
 hw/gpio/npcm8xx_sgpio.c          | 134 ++++++++++++++++++++---
 include/hw/gpio/npcm8xx_sgpio.h  |   4 +-
 tests/qtest/npcm8xx_sgpio-test.c | 180 ++++++++++++++++++++++++++-----
 3 files changed, 274 insertions(+), 44 deletions(-)
hw/gpio/npcm8xx_sgpio.c +121 -13
index f7d6bbf672..3b626a44e5 100644
@@ -27,6 +27,8 @@
 #include "qemu/units.h"
 #include "trace.h"
 
+#include <limits.h>
+
 #define NPCM8XX_SGPIO_RD_MODE_MASK      0x6
 #define NPCM8XX_SGPIO_RD_MODE_PERIODIC  0x4
 #define NPCM8XX_SGPIO_RD_MODE_ON_DEMAND 0x0
@@ -126,24 +128,83 @@ static uint64_t npcm8xx_sgpio_regs_read_with_cfg(NPCM8xxSGPIOState *s,
     if (rd_word) {
         value = ((uint16_t)s->regs[reg] << 8) | s->regs[reg + 1];
     } else {
-        value = s->regs[reg];
+        value = (uint8_t) s->regs[reg];
     }
 
     return value;
 }
 
+static uint8_t get_even_bits(uint16_t n)
+{
+    n &= 0x5555;
+
+    n = (n | (n >> 1)) & 0x3333;
+    n = (n | (n >> 2)) & 0x0F0F;
+    n = (n | (n >> 4)) & 0x00FF;
+
+    return (uint8_t)n;
+}
+
+static uint8_t get_odd_bits(uint16_t n)
+{
+    return get_even_bits(n >> 1);
+}
+
+/*
+ *  For each pin, event can be generated from one of 3 conditions.
+ *
+ *  | 1 | 0 | event configuration
+ *  -----------------------------
+ *  | 0 | 0 | disabled
+ *  | 0 | 1 | 0-1 transition
+ *  | 1 | 0 | 1-0 transition
+ *  | 1 | 1 | even by any transition
+ */
+
 static void npcm8xx_sgpio_update_event(NPCM8xxSGPIOState *s, uint64_t diff)
 {
-    /* TODO in upcoming patch */
+    uint8_t *d = (uint8_t *)&(diff);
+    uint8_t *p = (uint8_t *)&s->pin_in_level;
+    uint16_t type;
+    uint8_t sts;
+    int i;
+
+    for (i = 0; i < npcm8xx_sgpio_get_in_port(s); ++i) {
+        type = ((uint16_t)s->regs[NPCM8XX_SGPIO_XEVCFG0 + 2 * i] << 8) |
+                        s->regs[NPCM8XX_SGPIO_XEVCFG0 + 2 * i + 1];
+
+        /* 0-1 transitions */
+        sts = p[i] & d[i] & get_even_bits(type);
+        /* 1-0 transitions */
+        sts |= (~p[i]) & (d[i] & get_odd_bits(type));
+
+        s->regs[NPCM8XX_SGPIO_XEVSTS0 + i] = sts;
+
+        /* Generate event if the event status register tells us so */
+        qemu_set_irq(s->irq, !!(s->regs[NPCM8XX_SGPIO_XEVSTS0 + i]));
+    }
 }
 
-static void npcm8xx_sgpio_update_pins_in(NPCM8xxSGPIOState *s, uint64_t diff)
+static void npcm8xx_sgpio_update_pins_in(NPCM8xxSGPIOState *s, uint64_t value)
 {
-    /* TODO in upcoming patch */
+    uint8_t *nv = (uint8_t *)&value;
+    uint8_t *ov = (uint8_t *)&s->pin_in_level;
+    uint64_t diff = s->pin_in_level ^ value;
+    int i;
+
+    for (i = 0; i < npcm8xx_sgpio_get_in_port(s); ++i) {
+        if (ov[i] == nv[i]) {
+            continue;
+        }
+        s->regs[NPCM8XX_SGPIO_XDIN0 + i] = nv[i];
+    }
+    s->pin_in_level = value;
+    npcm8xx_sgpio_update_event(s, diff);
 }
 
 static void npcm8xx_sgpio_update_pins_out(NPCM8xxSGPIOState *s, hwaddr reg)
 {
+    uint8_t *p = (uint8_t *)&s->pin_out_level;
     uint8_t nout, dout;
 
     if (~(s->regs[NPCM8XX_SGPIO_IOXCTS] & NPCM8XX_SGPIO_IOXCTS_IOXIF_EN)) {
@@ -159,7 +220,7 @@ static void npcm8xx_sgpio_update_pins_out(NPCM8xxSGPIOState *s, hwaddr reg)
                       "%s: Accessing XDOUT%d when NOUT is %d\n",
                       DEVICE(s)->canonical_path, dout, nout);
     }
-    s->pin_out_level[dout] = s->regs[NPCM8XX_SGPIO_XDOUT0 + dout];
+    p[dout] = s->regs[reg];
     /* unset WR_PEND */
     s->regs[NPCM8XX_SGPIO_IOXCTS] &= ~0x40;
 }
@@ -294,10 +355,8 @@ static void npcm8xx_sgpio_regs_write(void *opaque, hwaddr addr, uint64_t v,
             }
             s->regs[reg] ^= hi_val;
             s->regs[reg + 1] ^= value;
-            npcm8xx_sgpio_update_event(s, 0);
         } else {
             s->regs[reg] ^= value;
-            npcm8xx_sgpio_update_event(s, 0);
         }
         break;
 
@@ -371,19 +430,70 @@ static void npcm8xx_sgpio_hold_reset(Object *obj, ResetType type)
 {
     NPCM8xxSGPIOState *s = NPCM8XX_SGPIO(obj);
 
-    npcm8xx_sgpio_update_pins_in(s, -1);
+    npcm8xx_sgpio_update_pins_in(s, 0);
+}
+
+static void npcm8xx_sgpio_set_input_lo(void *opaque, int line, int level)
+{
+    NPCM8xxSGPIOState *s = opaque;
+
+    g_assert(line >= 0 && line < NPCM8XX_SGPIO_NR_PINS / 2);
+
+    npcm8xx_sgpio_update_pins_in(s, BIT(line) && level);
+}
+
+static void npcm8xx_sgpio_set_input_hi(void *opaque, int line, int level)
+{
+    NPCM8xxSGPIOState *s = opaque;
+    uint64_t line_ull = line;
+
+    g_assert(line >= NPCM8XX_SGPIO_NR_PINS / 2 && line < NPCM8XX_SGPIO_NR_PINS);
+
+    npcm8xx_sgpio_update_pins_in(s, BIT(line_ull << 32) && level);
+}
+
+static void npcm8xx_sgpio_get_pins_in(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    NPCM8xxSGPIOState *s = NPCM8XX_SGPIO(obj);
+
+    visit_type_uint64(v, name, &s->pin_in_level, errp);
+}
+
+static void npcm8xx_sgpio_set_pins_in(Object *obj, Visitor *v, const char *name,
+                                     void *opaque, Error **errp)
+{
+    NPCM8xxSGPIOState *s = NPCM8XX_SGPIO(obj);
+    uint64_t new_pins_in;
+
+    if (!visit_type_uint64(v, name, &new_pins_in, errp)) {
+        return;
+    }
+
+    npcm8xx_sgpio_update_pins_in(s, new_pins_in);
 }
 
 static void npcm8xx_sgpio_init(Object *obj)
 {
     NPCM8xxSGPIOState *s = NPCM8XX_SGPIO(obj);
+    DeviceState *dev = DEVICE(obj);
 
     memory_region_init_io(&s->mmio, obj, &npcm8xx_sgpio_regs_ops, s,
                           "regs", NPCM8XX_SGPIO_REGS_SIZE);
     sysbus_init_mmio(SYS_BUS_DEVICE(obj), &s->mmio);
     sysbus_init_irq(SYS_BUS_DEVICE(obj), &s->irq);
 
-    /* TODO: Add input GPIO pins */
+    /* There are total 64 input pins that can be set */
+    QEMU_BUILD_BUG_ON(NPCM8XX_SGPIO_NR_PINS >
+                      sizeof(s->pin_in_level) * CHAR_BIT);
+    qdev_init_gpio_in(dev, npcm8xx_sgpio_set_input_hi,
+                      NPCM8XX_SGPIO_NR_PINS / 2);
+    qdev_init_gpio_in(dev, npcm8xx_sgpio_set_input_lo,
+                      NPCM8XX_SGPIO_NR_PINS / 2);
+
+    object_property_add(obj, "sgpio-pins-in", "uint64",
+                        npcm8xx_sgpio_get_pins_in, npcm8xx_sgpio_set_pins_in,
+                        NULL, NULL);
 }
 
 static const VMStateDescription vmstate_npcm8xx_sgpio = {
@@ -391,10 +501,8 @@ static const VMStateDescription vmstate_npcm8xx_sgpio = {
     .version_id = 0,
     .minimum_version_id = 0,
     .fields = (const VMStateField[]) {
-        VMSTATE_UINT8_ARRAY(pin_in_level, NPCM8xxSGPIOState,
-                            NPCM8XX_SGPIO_NR_PINS / NPCM8XX_SGPIO_MAX_PORTS),
-        VMSTATE_UINT8_ARRAY(pin_out_level, NPCM8xxSGPIOState,
-                            NPCM8XX_SGPIO_NR_PINS / NPCM8XX_SGPIO_MAX_PORTS),
+        VMSTATE_UINT64(pin_in_level, NPCM8xxSGPIOState),
+        VMSTATE_UINT64(pin_out_level, NPCM8xxSGPIOState),
         VMSTATE_UINT8_ARRAY(regs, NPCM8xxSGPIOState, NPCM8XX_SGPIO_NR_REGS),
         VMSTATE_END_OF_LIST(),
     },
include/hw/gpio/npcm8xx_sgpio.h +2 -2
index cce844951e..05dfafcb5e 100644
@@ -34,8 +34,8 @@ typedef struct NPCM8xxSGPIOState {
     MemoryRegion mmio;
     qemu_irq irq;
 
-    uint8_t pin_in_level[NPCM8XX_SGPIO_MAX_PORTS];
-    uint8_t pin_out_level[NPCM8XX_SGPIO_MAX_PORTS];
+    uint64_t pin_in_level;
+    uint64_t pin_out_level;
     uint8_t regs[NPCM8XX_SGPIO_NR_REGS];
 } NPCM8xxSGPIOState;
 
tests/qtest/npcm8xx_sgpio-test.c +151 -29

216 lines not on this page · raw message

Signature · 1 line
2.51.0.536.g15c5d4f767-goog
#12 lore raw

Re: [PATCH v1 5/5] hw/gpio/npcm8xx: Implement npcm sgpio device input pin logic

Quoted 16 lines · Coco Li
---
  hw/gpio/npcm8xx_sgpio.c          | 134 ++++++++++++++++++++---
  include/hw/gpio/npcm8xx_sgpio.h  |   4 +-
  tests/qtest/npcm8xx_sgpio-test.c | 180 ++++++++++++++++++++++++++-----
  3 files changed, 274 insertions(+), 44 deletions(-)
hw/gpio/npcm8xx_sgpio.c +5 -0
 
 
+static uint8_t get_even_bits(uint16_t n)
+{
+    n &= 0x5555;
+
+    n = (n | (n >> 1)) & 0x3333;

hw/gpio/npcm8xx_sgpio.c static uint64_t npcm8xx_sgpio_regs_read_with_cfg(NPCM8xxSGPIOState *s, · line 151

Quoted 10 lines
hw/gpio/npcm8xx_sgpio.c +10 -0
+    n = (n | (n >> 2)) & 0x0F0F;
+    n = (n | (n >> 4)) & 0x00FF;
+
+    return (uint8_t)n;
+}
+
+static uint8_t get_odd_bits(uint16_t n)
+{
+    return get_even_bits(n >> 1);
+}

Candidates for "include/qemu/bitops.h"?

author
#13 lore raw

Re: [PATCH v1 5/5] hw/gpio/npcm8xx: Implement npcm sgpio device input pin logic

Good call, I can put it in the next version.

Quoted 30 lines · Philippe Mathieu-Daudé
Quoted 16 lines · Coco Li
---
  hw/gpio/npcm8xx_sgpio.c          | 134 ++++++++++++++++++++---
  include/hw/gpio/npcm8xx_sgpio.h  |   4 +-
  tests/qtest/npcm8xx_sgpio-test.c | 180 ++++++++++++++++++++++++++-----
  3 files changed, 274 insertions(+), 44 deletions(-)
hw/gpio/npcm8xx_sgpio.c +5 -0
 
 
+static uint8_t get_even_bits(uint16_t n)
+{
+    n &= 0x5555;
+
+    n = (n | (n >> 1)) & 0x3333;

hw/gpio/npcm8xx_sgpio.c static uint64_t npcm8xx_sgpio_regs_read_with_cfg(NPCM8xxSGPIOState *s, · line 151

Quoted 10 lines
hw/gpio/npcm8xx_sgpio.c +10 -0
+    n = (n | (n >> 2)) & 0x0F0F;
+    n = (n | (n >> 4)) & 0x00FF;
+
+    return (uint8_t)n;
+}
+
+static uint8_t get_odd_bits(uint16_t n)
+{
+    return get_even_bits(n >> 1);
+}

Candidates for "include/qemu/bitops.h"?