Skip to contentSkip to conversation

Misc NPCM7XX patches

PATCH Superseded Hao Wu 3 participants 12 messages Aug 13, 2021 – Aug 20, 2021

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Hao Wu

author
#0 lore raw

cover Misc NPCM7XX patches

This patch set contains a few bug fixes and I2C devices for some NPCM7XX boards.

Patch 1~2 fix a problem that causes the SMBus module to behave incorrectly when it's in FIFO mode and trying to receive more than 16 bytes at a time.

Patch 3 fixes a error in a register for ADC module.

Patch 4 makes the ADC input to be R/W instead of write only. It allows a test system to read these via QMP and has no negative effect.

Patch 5 adds a new aux function for at24c EEPROM. It allows us to attach a drive to an at24c EEPROM device that is used as the initialized content of that device.

Patch 6 uses the function defined in patch 5 to add the EEPROM and other I2C devices for Quanta GBS board.

Patch 7 modifies the Quanta GSJ board to use the new function defined in patch 5.

Hao Wu (6):
hw/i2c: Clear ACK bit in NPCM7xx SMBus module hw/i2c: Read FIFO during RXF_CTL change in NPCM7XX SMBus hw/adc: Fix CONV bit in NPCM7XX ADC CON register hw/adc: Make adci[*] R/W in NPCM7XX ADC
hw/nvram: Add a new auxiliary function to init at24c eeprom hw/arm: Use unit number in quanta-gsj eeprom files

Patrick Venture (1):
hw/arm: quanta-gbs-bmc add i2c devices

 hw/adc/npcm7xx_adc.c            |  4 +-
 hw/arm/npcm7xx_boards.c         | 94 ++++++++++++++++-----------------
 hw/i2c/npcm7xx_smbus.c          |  8 +--
 hw/nvram/eeprom_at24c.c         | 18 +++++++
 include/hw/nvram/eeprom_at24c.h | 13 +++++
 tests/qtest/npcm7xx_adc-test.c  |  2 +-
 6 files changed, 85 insertions(+), 54 deletions(-)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
author
#1 lore raw

PATCH 1/7 hw/i2c: Clear ACK bit in NPCM7xx SMBus module

The ACK bit in NPCM7XX SMBus module should be cleared each time it sends out a NACK signal. This patch fixes the bug that it fails to do so.

---
 hw/i2c/npcm7xx_smbus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/i2c/npcm7xx_smbus.c +1 -1
index e7e0ba66fe..f18e311556 100644
@@ -270,7 +270,7 @@ static void npcm7xx_smbus_recv_byte(NPCM7xxSMBusState *s)
     if (s->st & NPCM7XX_SMBCTL1_ACK) {
         trace_npcm7xx_smbus_nack(DEVICE(s)->canonical_path);
         i2c_nack(s->bus);
-        s->st &= NPCM7XX_SMBCTL1_ACK;
+        s->st &= ~NPCM7XX_SMBCTL1_ACK;
     }
     trace_npcm7xx_smbus_recv_byte((DEVICE(s)->canonical_path), s->sda);
     npcm7xx_smbus_update_irq(s);
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
author
#2 lore raw

PATCH 2/7 hw/i2c: Read FIFO during RXF_CTL change in NPCM7XX SMBus

In reply to Hao Wu

Originally we read in from SMBus when RXF_STS is cleared. However, the driver clears RXF_STS before setting RXF_CTL, causing the SM bus module to read incorrect amount of bytes in FIFO mode when the number of bytes read changed. This patch fixes this issue.

---
 hw/i2c/npcm7xx_smbus.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
hw/i2c/npcm7xx_smbus.c +3 -3
index f18e311556..1435daea94 100644
@@ -637,9 +637,6 @@ static void npcm7xx_smbus_write_rxf_sts(NPCM7xxSMBusState *s, uint8_t value)
 {
     if (value & NPCM7XX_SMBRXF_STS_RX_THST) {
         s->rxf_sts &= ~NPCM7XX_SMBRXF_STS_RX_THST;
-        if (s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
-            npcm7xx_smbus_recv_fifo(s);
-        }
     }
 }
 
@@ -651,6 +648,9 @@ static void npcm7xx_smbus_write_rxf_ctl(NPCM7xxSMBusState *s, uint8_t value)
         new_ctl = KEEP_OLD_BIT(s->rxf_ctl, new_ctl, NPCM7XX_SMBRXF_CTL_LAST);
     }
     s->rxf_ctl = new_ctl;
+    if (s->status == NPCM7XX_SMBUS_STATUS_RECEIVING) {
+        npcm7xx_smbus_recv_fifo(s);
+    }
 }
 
 static uint64_t npcm7xx_smbus_read(void *opaque, hwaddr offset, unsigned size)
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
author
#3 lore raw

PATCH 3/7 hw/adc: Fix CONV bit in NPCM7XX ADC CON register

In reply to Hao Wu

The correct bit for the CONV bit in NPCM7XX ADC is bit 13. This patch fixes that in the module, and also lower the IRQ when the guest is done handling an interrupt event from the ADC module.

---
 hw/adc/npcm7xx_adc.c           | 2 +-
 tests/qtest/npcm7xx_adc-test.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
hw/adc/npcm7xx_adc.c +1 -1
index 0f0a9f63e2..47fb9e5f74 100644
@@ -36,7 +36,7 @@ REG32(NPCM7XX_ADC_DATA, 0x4)
 #define NPCM7XX_ADC_CON_INT     BIT(18)
 #define NPCM7XX_ADC_CON_EN      BIT(17)
 #define NPCM7XX_ADC_CON_RST     BIT(16)
-#define NPCM7XX_ADC_CON_CONV    BIT(14)
+#define NPCM7XX_ADC_CON_CONV    BIT(13)
 #define NPCM7XX_ADC_CON_DIV(rv) extract32(rv, 1, 8)
 
 #define NPCM7XX_ADC_MAX_RESULT      1023
tests/qtest/npcm7xx_adc-test.c +1 -1
index 5ce8ce13b3..aaf127dd42 100644
@@ -50,7 +50,7 @@
 #define CON_INT     BIT(18)
 #define CON_EN      BIT(17)
 #define CON_RST     BIT(16)
-#define CON_CONV    BIT(14)
+#define CON_CONV    BIT(13)
 #define CON_DIV(rv) extract32(rv, 1, 8)
 
 #define FST_RDST    BIT(1)
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
author
#4 lore raw

PATCH 4/7 hw/adc: Make adci[*] R/W in NPCM7XX ADC

In reply to Hao Wu

Our sensor test requires both reading and writing from a sensor's QOM property. So we need to make the input of ADC module R/W instead of read only for that to work.

---
 hw/adc/npcm7xx_adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/adc/npcm7xx_adc.c +1 -1
index 47fb9e5f74..bc6f3f55e6 100644
@@ -242,7 +242,7 @@ static void npcm7xx_adc_init(Object *obj)
 
     for (i = 0; i < NPCM7XX_ADC_NUM_INPUTS; ++i) {
         object_property_add_uint32_ptr(obj, "adci[*]",
-                &s->adci[i], OBJ_PROP_FLAG_WRITE);
+                &s->adci[i], OBJ_PROP_FLAG_READWRITE);
     }
     object_property_add_uint32_ptr(obj, "vref",
             &s->vref, OBJ_PROP_FLAG_WRITE);
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#5 lore raw

Re: [PATCH 4/7] hw/adc: Make adci[*] R/W in NPCM7XX ADC

Quoted 15 lines · Hao Wu

Our sensor test requires both reading and writing from a sensor's QOM property. So we need to make the input of ADC module R/W instead of read only for that to work.

---
 hw/adc/npcm7xx_adc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/adc/npcm7xx_adc.c +0 -0
index 47fb9e5f74..bc6f3f55e6 100644

hw/adc/npcm7xx_adc.c static void npcm7xx_adc_init(Object *obj) · line 245

Quoted 5 lines
hw/adc/npcm7xx_adc.c +1 -1
@@ -242,7 +242,7 @@ static void npcm7xx_adc_init(Object *obj)
 
     for (i = 0; i < NPCM7XX_ADC_NUM_INPUTS; ++i) {
         object_property_add_uint32_ptr(obj, "adci[*]",
-                &s->adci[i], OBJ_PROP_FLAG_WRITE);
+                &s->adci[i], OBJ_PROP_FLAG_READWRITE);

What about:

qtest_enabled() ? OBJ_PROP_FLAG_READWRITE : OBJ_PROP_FLAG_WRITE

Quoted 4 lines
hw/adc/npcm7xx_adc.c +0 -0
     }
     object_property_add_uint32_ptr(obj, "vref",
             &s->vref, OBJ_PROP_FLAG_WRITE);
author
#6 lore raw

PATCH 5/7 hw/nvram: Add a new auxiliary function to init at24c eeprom

In reply to Hao Wu

In NPCM7xx boards, at24c eeproms are backed by drives. However, these drives use unit number as unique identifier. So if we specify two drives with the same unit number, error will occured:
Device with id 'none85' exists.

Instead of using i2c address as unit number, we now assign unique unit numbers for each eeproms in each board. This avoids conflict in providing multiple eeprom contents with the same address.

We add an auxiliary function in the at24c eeprom module for this. This allows it to easily add at24c eeprom to non-nuvoton boards like aspeed as well.

---
 hw/nvram/eeprom_at24c.c         | 18 ++++++++++++++++++
 include/hw/nvram/eeprom_at24c.h | 13 +++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
hw/nvram/eeprom_at24c.c +18 -0
index af6f5dbb99..a9e3702b00 100644
@@ -12,9 +12,11 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "hw/i2c/i2c.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/blockdev.h"
 #include "qom/object.h"
 
 /* #define DEBUG_AT24C */
@@ -205,3 +207,19 @@ static void at24c_eeprom_register(void)
 }
 
 type_init(at24c_eeprom_register)
+
+void at24c_eeprom_init_one(I2CBus *i2c_bus, int bus, uint8_t addr,
+                           uint32_t rsize, int unit_number)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
+    DeviceState *dev = DEVICE(i2c_dev);
+    BlockInterfaceType type = IF_NONE;
+    DriveInfo *dinfo;
+
+    dinfo = drive_get(type, bus, unit_number);
+    if (dinfo) {
+        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
+    }
+    qdev_prop_set_uint32(dev, "rom-size", rsize);
+    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
+}
include/hw/nvram/eeprom_at24c.h new file +13 -0
new file mode 100644
index 0000000000..b649557a07
@@ -0,0 +1,13 @@
+/*
+ * *AT24C* series I2C EEPROM
+ *
+ * Copyright (c) 2015 Michael Davidsaver
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2.  See
+ * the LICENSE file in the top-level directory.
+ */
+
+/* Init one at24c eeprom device */
+void at24c_eeprom_init_one(I2CBus *i2c_bus, int bus, uint8_t addr,
+                           uint32_t rsize, int unit_number);
+
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#7 lore raw

Re: [PATCH 5/7] hw/nvram: Add a new auxiliary function to init at24c eeprom

Quoted 48 lines · Hao Wu

In NPCM7xx boards, at24c eeproms are backed by drives. However, these drives use unit number as unique identifier. So if we specify two drives with the same unit number, error will occured:
Device with id 'none85' exists.

Instead of using i2c address as unit number, we now assign unique unit numbers for each eeproms in each board. This avoids conflict in providing multiple eeprom contents with the same address.

We add an auxiliary function in the at24c eeprom module for this. This allows it to easily add at24c eeprom to non-nuvoton boards like aspeed as well.

---
 hw/nvram/eeprom_at24c.c         | 18 ++++++++++++++++++
 include/hw/nvram/eeprom_at24c.h | 13 +++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 include/hw/nvram/eeprom_at24c.h
hw/nvram/eeprom_at24c.c +8 -0
index af6f5dbb99..a9e3702b00 100644
@@ -12,9 +12,11 @@
 #include "qapi/error.h"
 #include "qemu/module.h"
 #include "hw/i2c/i2c.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/qdev-properties.h"
 #include "hw/qdev-properties-system.h"
 #include "sysemu/block-backend.h"
+#include "sysemu/blockdev.h"
 #include "qom/object.h"
 
 /* #define DEBUG_AT24C */
@@ -205,3 +207,19 @@ static void at24c_eeprom_register(void)
 }
 
 type_init(at24c_eeprom_register)
+
+void at24c_eeprom_init_one(I2CBus *i2c_bus, int bus, uint8_t addr,
+                           uint32_t rsize, int unit_number)
+{
+    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
+    DeviceState *dev = DEVICE(i2c_dev);

hw/nvram/eeprom_at24c.c static void at24c_eeprom_register(void) · line 225

Quoted 10 lines
hw/nvram/eeprom_at24c.c +10 -0
+    BlockInterfaceType type = IF_NONE;
+    DriveInfo *dinfo;
+
+    dinfo = drive_get(type, bus, unit_number);
+    if (dinfo) {
+        qdev_prop_set_drive(dev, "drive", blk_by_legacy_dinfo(dinfo));
+    }
+    qdev_prop_set_uint32(dev, "rom-size", rsize);
+    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
+}

This is just creating a device and configuring it, right? We tend to prefer that this is just done directly in the board or SoC code these days, rather than providing helper functions for it.

If you don't like what hw/arm/npcm7xx_boards.c:at24c_eeprom_init() is currently doing, you should just patch it to do something different.

thanks
-- PMM

author
#8 lore raw

PATCH 6/7 hw/arm: quanta-gbs-bmc add i2c devices

In reply to Hao Wu

From: Patrick Venture <[email protected]>

Adds supported i2c devices to the quanta-gbc-bmc board.

---
 hw/arm/npcm7xx_boards.c | 79 +++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 34 deletions(-)
hw/arm/npcm7xx_boards.c +45 -34
index e5a3243995..54cf9785ec 100644
@@ -21,6 +21,7 @@
 #include "hw/i2c/i2c_mux_pca954x.h"
 #include "hw/i2c/smbus_eeprom.h"
 #include "hw/loader.h"
+#include "hw/nvram/eeprom_at24c.h"
 #include "hw/qdev-core.h"
 #include "hw/qdev-properties.h"
 #include "qapi/error.h"
@@ -252,11 +253,12 @@ static void quanta_gsj_fan_init(NPCM7xxMachine *machine, NPCM7xxState *soc)
 
 static void quanta_gbs_i2c_init(NPCM7xxState *soc)
 {
-    /*
-     * i2c-0:
-     *     pca9546@71
-     *
-     * i2c-1:
+    I2CSlave *i2c_mux;
+
+    /* i2c-0: */
+    i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), TYPE_PCA9546, 0x71);
+
+    /* i2c-1:
      *     pca9535@24
      *     pca9535@20
      *     pca9535@21
@@ -264,47 +266,56 @@ static void quanta_gbs_i2c_init(NPCM7xxState *soc)
      *     pca9535@23
      *     pca9535@25
      *     pca9535@26
-     *
-     * i2c-2:
-     *     sbtsi@4c
-     *
-     * i2c-5:
-     *     atmel,24c64@50 mb_fru
-     *     pca9546@71
-     *         - channel 0: max31725@54
-     *         - channel 1: max31725@55
-     *         - channel 2: max31725@5d
-     *                      atmel,24c64@51 fan_fru
-     *         - channel 3: atmel,24c64@52 hsbp_fru
-     *
-     * i2c-6:
+     */
+
+    /* i2c-2: sbtsi@4c */
+
+    /* i2c-5: */
+    /* mb_fru */
+    at24c_eeprom_init_one(npcm7xx_i2c_get_bus(soc, 5), 5, 0x50, 8192, 0);
+    i2c_mux = i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 5),
+                                      TYPE_PCA9546, 0x71);
+    /* max31725 is tmp105 compatible. */
+    i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 0), "tmp105", 0x54);
+    i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 1), "tmp105", 0x55);
+    i2c_slave_create_simple(pca954x_i2c_get_bus(i2c_mux, 2), "tmp105", 0x5d);
+    /* fan_fru */
+    at24c_eeprom_init_one(pca954x_i2c_get_bus(i2c_mux, 2), 5, 0x51, 8192, 1);
+    /* hsbp_fru */
+    at24c_eeprom_init_one(pca954x_i2c_get_bus(i2c_mux, 3), 5, 0x52, 8192, 2);
+
+    /* i2c-6:
      *     pca9545@73
      *
      * i2c-7:
      *     pca9545@72
-     *
-     * i2c-8:
-     *     adi,adm1272@10
-     *
-     * i2c-9:
-     *     pca9546@71
-     *         - channel 0: isil,isl68137@60
+     */
+
+    /* i2c-8: */
+    i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 8), "adm1272", 0x10);
+
+    /* i2c-9: */
+    i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 9), TYPE_PCA9546, 0x71);
+    /*         - channel 0: isil,isl68137@60
      *         - channel 1: isil,isl68137@61
      *         - channel 2: isil,isl68137@63
      *         - channel 3: isil,isl68137@45
-     *
-     * i2c-10:
+     */
+
+    /* i2c-10:
      *     pca9545@71
      *
      * i2c-11:
      *     pca9545@76
-     *
-     * i2c-12:
-     *     maxim,max34451@4e
-     *     isil,isl68137@5d
+     */
+
+    /* i2c-12: */
+    i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 12), "max34451", 0x4e);
+    /*     isil,isl68137@5d
      *     isil,isl68137@5e
-     *
-     * i2c-14:
+     */
+
+    /* i2c-14:
      *     pca9545@70
      */
 }
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#9 lore raw

Re: [PATCH 6/7] hw/arm: quanta-gbs-bmc add i2c devices

Quoted 11 lines · Hao Wu

From: Patrick Venture <[email protected]>

Adds supported i2c devices to the quanta-gbc-bmc board.

---
 hw/arm/npcm7xx_boards.c | 79 +++++++++++++++++++++++------------------
 1 file changed, 45 insertions(+), 34 deletions(-)

Does the documentation need updating to mention these newly supported devices ?

Quoted 6 lines

static void quanta_gbs_i2c_init(NPCM7xxState *soc) {

hw/arm/npcm7xx_boards.c +0 -4
-    /*
-     * i2c-0:
-     *     pca9546@71
-     *

hw/arm/npcm7xx_boards.c static void quanta_gsj_fan_init(NPCM7xxMachine *machine, NPCM7xxState *soc) · line 264

Quoted 10 lines
hw/arm/npcm7xx_boards.c +6 -1
-     * i2c-1:
+    I2CSlave *i2c_mux;
+
+    /* i2c-0: */
+    i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 0), TYPE_PCA9546, 0x71);
+
+    /* i2c-1:
      *     pca9535@24
      *     pca9535@20
      *     pca9535@21

This leaves this multiline block comment with the wrong format: QEMU's coding style wants the leading "/*" on a line of its own. Similarly for some others in this patch.

thanks
-- PMM

author
#10 lore raw

PATCH 7/7 hw/arm: Use unit number in quanta-gsj eeprom files

In reply to Hao Wu

Use unique unit numbers in quanta-gsj eeprom files.

---
 hw/arm/npcm7xx_boards.c | 15 ++-------------
 1 file changed, 2 insertions(+), 13 deletions(-)
hw/arm/npcm7xx_boards.c +2 -13
index 54cf9785ec..be6c81b29d 100644
@@ -107,17 +107,6 @@ static I2CBus *npcm7xx_i2c_get_bus(NPCM7xxState *soc, uint32_t num)
     return I2C_BUS(qdev_get_child_bus(DEVICE(&soc->smbus[num]), "i2c-bus"));
 }
 
-static void at24c_eeprom_init(NPCM7xxState *soc, int bus, uint8_t addr,
-                              uint32_t rsize)
-{
-    I2CBus *i2c_bus = npcm7xx_i2c_get_bus(soc, bus);
-    I2CSlave *i2c_dev = i2c_slave_new("at24c-eeprom", addr);
-    DeviceState *dev = DEVICE(i2c_dev);
-
-    qdev_prop_set_uint32(dev, "rom-size", rsize);
-    i2c_slave_realize_and_unref(i2c_dev, i2c_bus, &error_abort);
-}
-
 static void npcm7xx_init_pwm_splitter(NPCM7xxMachine *machine,
                                       NPCM7xxState *soc, const int *fan_counts)
 {
@@ -220,8 +209,8 @@ static void quanta_gsj_i2c_init(NPCM7xxState *soc)
     i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 3), "tmp105", 0x5c);
     i2c_slave_create_simple(npcm7xx_i2c_get_bus(soc, 4), "tmp105", 0x5c);
 
-    at24c_eeprom_init(soc, 9, 0x55, 8192);
-    at24c_eeprom_init(soc, 10, 0x55, 8192);
+    at24c_eeprom_init_one(npcm7xx_i2c_get_bus(soc, 9), 9, 0x55, 8192, 0);
+    at24c_eeprom_init_one(npcm7xx_i2c_get_bus(soc, 10), 10, 0x55, 8192, 1);
 
     /*
      * i2c-11:
Signature · 1 line
2.33.0.rc1.237.g0d66db33f3-goog
#11 lore raw
In reply to Hao Wu
Quoted 17 lines · Hao Wu

This patch set contains a few bug fixes and I2C devices for some NPCM7XX boards.

Patch 1~2 fix a problem that causes the SMBus module to behave incorrectly when it's in FIFO mode and trying to receive more than 16 bytes at a time.

Patch 3 fixes a error in a register for ADC module.

Patch 4 makes the ADC input to be R/W instead of write only. It allows a test system to read these via QMP and has no negative effect.

Patch 5 adds a new aux function for at24c EEPROM. It allows us to attach a drive to an at24c EEPROM device that is used as the initialized content of that device.

Quoted 5 lines

Patch 6 uses the function defined in patch 5 to add the EEPROM and other I2C devices for Quanta GBS board.

Patch 7 modifies the Quanta GSJ board to use the new function defined in patch 5.

I've left review comments on a few of the patches. The first 4 look fine; I just haven't left r-by tags because I didn't go and look up the specs for the hardware.

thanks
-- PMM