qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PULL 0/2] Pull request for some I2C changes
@ 2023-12-07  1:41 minyard
  2023-12-07  1:41 ` [PULL 1/2] hw/sensor: enable setting adm1272 temperature with qmp minyard
  2023-12-07  1:41 ` [PULL 2/2] hw/i2c: add pca9543 i2c-mux switch minyard
  0 siblings, 2 replies; 3+ messages in thread
From: minyard @ 2023-12-07  1:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Potin Lai, Patrick Venture, Hao Wu, Titus Rwantare, Corey Minyard

From: Corey Minyard <minyard@acm.org>

Some minor I2C changes.  One has been sitting in my queue forgotten for
a while, but still needs to go in.  The other is fairly recent.  Both
are for BMC related stuff.

These are available at:
   https://github.com/cminyard/qemu.git i2c-for-release-2023-12-06
and signed by me.

Potin Lai (1):
  hw/i2c: add pca9543 i2c-mux switch

Titus Rwantare (1):
  hw/sensor: enable setting adm1272 temperature with qmp

 hw/i2c/i2c_mux_pca954x.c         | 12 ++++++++++++
 hw/sensor/adm1272.c              | 27 ++++++++++++++++++++++++++-
 include/hw/i2c/i2c_mux_pca954x.h |  1 +
 tests/qtest/adm1272-test.c       | 28 +++++++++++++++++++++++++++-
 4 files changed, 66 insertions(+), 2 deletions(-)

-- 
2.34.1



^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PULL 1/2] hw/sensor: enable setting adm1272 temperature with qmp
  2023-12-07  1:41 [PULL 0/2] Pull request for some I2C changes minyard
@ 2023-12-07  1:41 ` minyard
  2023-12-07  1:41 ` [PULL 2/2] hw/i2c: add pca9543 i2c-mux switch minyard
  1 sibling, 0 replies; 3+ messages in thread
From: minyard @ 2023-12-07  1:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Potin Lai, Patrick Venture, Hao Wu, Titus Rwantare, Chris Rauer,
	Corey Minyard

From: Titus Rwantare <titusr@google.com>

Reviewed-by: Patrick Venture <venture@google.com>
Reviewed-by: Chris Rauer <crauer@google.com>
Reviewed-by: Hao Wu <wuhaotsh@google.com>
Signed-off-by: Titus Rwantare <titusr@google.com>
Message-Id: <20220106173814.3580141-1-venture@google.com>
Signed-off-by: Corey Minyard <cminyard@mvista.com>
---
 hw/sensor/adm1272.c        | 27 ++++++++++++++++++++++++++-
 tests/qtest/adm1272-test.c | 28 +++++++++++++++++++++++++++-
 2 files changed, 53 insertions(+), 2 deletions(-)

diff --git a/hw/sensor/adm1272.c b/hw/sensor/adm1272.c
index 8f4a1c2cd4..6e5ae6e63b 100644
--- a/hw/sensor/adm1272.c
+++ b/hw/sensor/adm1272.c
@@ -65,6 +65,7 @@
 #define ADM1272_VOLTAGE_COEFF_DEFAULT   1
 #define ADM1272_CURRENT_COEFF_DEFAULT   3
 #define ADM1272_PWR_COEFF_DEFAULT       7
+#define ADM1272_TEMP_COEFF_DEFAULT      8
 #define ADM1272_IOUT_OFFSET             0x5000
 #define ADM1272_IOUT_OFFSET             0x5000
 
@@ -185,6 +186,22 @@ static uint32_t adm1272_direct_to_watts(uint16_t value)
     return pmbus_direct_mode2data(c, value);
 }
 
+static uint16_t adm1272_millidegrees_to_direct(uint32_t value)
+{
+    PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT];
+    c.b = c.b * 1000;
+    c.R = c.R - 3;
+    return pmbus_data2direct_mode(c, value);
+}
+
+static uint32_t adm1272_direct_to_millidegrees(uint16_t value)
+{
+    PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT];
+    c.b = c.b * 1000;
+    c.R = c.R - 3;
+    return pmbus_direct_mode2data(c, value);
+}
+
 static void adm1272_exit_reset(Object *obj)
 {
     ADM1272State *s = ADM1272(obj);
@@ -219,7 +236,7 @@ static void adm1272_exit_reset(Object *obj)
         = adm1272_millivolts_to_direct(ADM1272_VOLT_DEFAULT);
     pmdev->pages[0].read_iout
         = adm1272_milliamps_to_direct(ADM1272_IOUT_DEFAULT);
-    pmdev->pages[0].read_temperature_1 = 0;
+    pmdev->pages[0].read_temperature_1 = adm1272_millidegrees_to_direct(30000);
     pmdev->pages[0].read_pin = adm1272_watts_to_direct(ADM1272_PWR_DEFAULT);
     pmdev->pages[0].revision = ADM1272_PMBUS_REVISION_DEFAULT;
     pmdev->pages[0].mfr_id = ADM1272_MFR_ID_DEFAULT;
@@ -422,6 +439,8 @@ static void adm1272_get(Object *obj, Visitor *v, const char *name, void *opaque,
         value = adm1272_direct_to_milliamps(*(uint16_t *)opaque);
     } else if (strcmp(name, "pin") == 0) {
         value = adm1272_direct_to_watts(*(uint16_t *)opaque);
+    } else if (strcmp(name, "temperature") == 0) {
+        value = adm1272_direct_to_millidegrees(*(uint16_t *)opaque);
     } else {
         value = *(uint16_t *)opaque;
     }
@@ -446,6 +465,8 @@ static void adm1272_set(Object *obj, Visitor *v, const char *name, void *opaque,
         *internal = adm1272_milliamps_to_direct(value);
     } else if (strcmp(name, "pin") == 0) {
         *internal = adm1272_watts_to_direct(value);
+    } else if (strcmp(name, "temperature") == 0) {
+        *internal = adm1272_millidegrees_to_direct(value);
     } else {
         *internal = value;
     }
@@ -509,6 +530,10 @@ static void adm1272_init(Object *obj)
                         adm1272_get,
                         adm1272_set, NULL, &pmdev->pages[0].read_pin);
 
+    object_property_add(obj, "temperature", "uint16",
+                        adm1272_get,
+                        adm1272_set, NULL, &pmdev->pages[0].read_temperature_1);
+
 }
 
 static void adm1272_class_init(ObjectClass *klass, void *data)
diff --git a/tests/qtest/adm1272-test.c b/tests/qtest/adm1272-test.c
index 63f8514801..98134aabd2 100644
--- a/tests/qtest/adm1272-test.c
+++ b/tests/qtest/adm1272-test.c
@@ -65,6 +65,7 @@
 #define ADM1272_VOLTAGE_COEFF_DEFAULT   1
 #define ADM1272_CURRENT_COEFF_DEFAULT   3
 #define ADM1272_PWR_COEFF_DEFAULT       7
+#define ADM1272_TEMP_COEFF_DEFAULT      8
 #define ADM1272_IOUT_OFFSET             0x5000
 #define ADM1272_IOUT_OFFSET             0x5000
 
@@ -144,6 +145,22 @@ static uint32_t adm1272_direct_to_watts(uint16_t value)
     return pmbus_direct_mode2data(c, value);
 }
 
+static uint16_t adm1272_millidegrees_to_direct(uint32_t value)
+{
+    PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT];
+    c.b = c.b * 1000;
+    c.R = c.R - 3;
+    return pmbus_data2direct_mode(c, value);
+}
+
+static uint32_t adm1272_direct_to_millidegrees(uint16_t value)
+{
+    PMBusCoefficients c = adm1272_coefficients[ADM1272_TEMP_COEFF_DEFAULT];
+    c.b = c.b * 1000;
+    c.R = c.R - 3;
+    return pmbus_direct_mode2data(c, value);
+}
+
 static uint16_t qmp_adm1272_get(const char *id, const char *property)
 {
     QDict *response;
@@ -248,7 +265,7 @@ static void test_defaults(void *obj, void *data, QGuestAllocator *alloc)
 /* test qmp access */
 static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc)
 {
-    uint16_t i2c_value, value, i2c_voltage, i2c_pwr, lossy_value;
+    uint16_t i2c_value, value, i2c_voltage, i2c_pwr, i2c_temp, lossy_value;
     QI2CDevice *i2cdev = (QI2CDevice *)obj;
 
     /* converting to direct mode is lossy - we generate the same loss here */
@@ -287,6 +304,15 @@ static void test_tx_rx(void *obj, void *data, QGuestAllocator *alloc)
     i2c_pwr = adm1272_direct_to_watts(i2c_value);
     g_assert_cmphex(value, ==, i2c_pwr);
     g_assert_cmphex(i2c_pwr, ==, lossy_value);
+
+    lossy_value =
+        adm1272_direct_to_millidegrees(adm1272_millidegrees_to_direct(25000));
+    qmp_adm1272_set(TEST_ID, "temperature", 25000);
+    value = qmp_adm1272_get(TEST_ID, "temperature");
+    i2c_value = adm1272_i2c_get16(i2cdev, PMBUS_READ_TEMPERATURE_1);
+    i2c_temp = adm1272_direct_to_millidegrees(i2c_value);
+    g_assert_cmphex(value, ==, i2c_temp);
+    g_assert_cmphex(i2c_temp, ==, lossy_value);
 }
 
 /* test r/w registers */
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PULL 2/2] hw/i2c: add pca9543 i2c-mux switch
  2023-12-07  1:41 [PULL 0/2] Pull request for some I2C changes minyard
  2023-12-07  1:41 ` [PULL 1/2] hw/sensor: enable setting adm1272 temperature with qmp minyard
@ 2023-12-07  1:41 ` minyard
  1 sibling, 0 replies; 3+ messages in thread
From: minyard @ 2023-12-07  1:41 UTC (permalink / raw)
  To: qemu-devel
  Cc: Potin Lai, Patrick Venture, Hao Wu, Titus Rwantare, Corey Minyard

From: Potin Lai <potin.lai.pt@gmail.com>

Add pca9543 2-channel i2c-mux switch support.

Signed-off-by: Potin Lai <potin.lai.pt@gmail.com>
Reviewed-by: Patrick Venture <venture@google.com>
Message-Id: <20231113063156.2264941-1-potin.lai.pt@gmail.com>
Signed-off-by: Corey Minyard <minyard@acm.org>
---
 hw/i2c/i2c_mux_pca954x.c         | 12 ++++++++++++
 include/hw/i2c/i2c_mux_pca954x.h |  1 +
 2 files changed, 13 insertions(+)

diff --git a/hw/i2c/i2c_mux_pca954x.c b/hw/i2c/i2c_mux_pca954x.c
index db5db956a6..6aace0fc47 100644
--- a/hw/i2c/i2c_mux_pca954x.c
+++ b/hw/i2c/i2c_mux_pca954x.c
@@ -30,6 +30,7 @@
 
 #define PCA9548_CHANNEL_COUNT 8
 #define PCA9546_CHANNEL_COUNT 4
+#define PCA9543_CHANNEL_COUNT 2
 
 /*
  * struct Pca954xState - The pca954x state object.
@@ -172,6 +173,12 @@ I2CBus *pca954x_i2c_get_bus(I2CSlave *mux, uint8_t channel)
     return pca954x->bus[channel];
 }
 
+static void pca9543_class_init(ObjectClass *klass, void *data)
+{
+    Pca954xClass *s = PCA954X_CLASS(klass);
+    s->nchans = PCA9543_CHANNEL_COUNT;
+}
+
 static void pca9546_class_init(ObjectClass *klass, void *data)
 {
     Pca954xClass *s = PCA954X_CLASS(klass);
@@ -246,6 +253,11 @@ static const TypeInfo pca954x_info[] = {
         .class_init    = pca954x_class_init,
         .abstract      = true,
     },
+    {
+        .name          = TYPE_PCA9543,
+        .parent        = TYPE_PCA954X,
+        .class_init    = pca9543_class_init,
+    },
     {
         .name          = TYPE_PCA9546,
         .parent        = TYPE_PCA954X,
diff --git a/include/hw/i2c/i2c_mux_pca954x.h b/include/hw/i2c/i2c_mux_pca954x.h
index 3dd25ec983..1da5508ed5 100644
--- a/include/hw/i2c/i2c_mux_pca954x.h
+++ b/include/hw/i2c/i2c_mux_pca954x.h
@@ -3,6 +3,7 @@
 
 #include "hw/i2c/i2c.h"
 
+#define TYPE_PCA9543 "pca9543"
 #define TYPE_PCA9546 "pca9546"
 #define TYPE_PCA9548 "pca9548"
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-12-07  1:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-07  1:41 [PULL 0/2] Pull request for some I2C changes minyard
2023-12-07  1:41 ` [PULL 1/2] hw/sensor: enable setting adm1272 temperature with qmp minyard
2023-12-07  1:41 ` [PULL 2/2] hw/i2c: add pca9543 i2c-mux switch minyard

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).