From: Patrick Venture <venture@google.com>
To: thuth@redhat.com, lvivier@redhat.com, pbonzini@redhat.com,
cminyard@mvista.com
Cc: qemu-devel@nongnu.org, Titus Rwantare <titusr@google.com>,
Patrick Venture <venture@google.com>,
Chris Rauer <crauer@google.com>, Hao Wu <wuhaotsh@google.com>
Subject: [PATCH] hw/sensor: enable setting adm1272 temperature with qmp
Date: Thu, 6 Jan 2022 09:38:14 -0800 [thread overview]
Message-ID: <20220106173814.3580141-1-venture@google.com> (raw)
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>
---
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 7310c769be..77a3d8eccf 100644
--- a/hw/sensor/adm1272.c
+++ b/hw/sensor/adm1272.c
@@ -66,6 +66,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
@@ -186,6 +187,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);
@@ -220,7 +237,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;
@@ -423,6 +440,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;
}
@@ -447,6 +466,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;
}
@@ -510,6 +531,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.448.ga2b2bfdf31-goog
next reply other threads:[~2022-01-06 17:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-06 17:38 Patrick Venture [this message]
[not found] ` <07207168-0940-a3de-c188-d676658603e8@redhat.com>
2022-01-07 18:17 ` [PATCH] hw/sensor: enable setting adm1272 temperature with qmp Patrick Venture
2022-03-15 11:07 ` Philippe Mathieu-Daudé
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=20220106173814.3580141-1-venture@google.com \
--to=venture@google.com \
--cc=cminyard@mvista.com \
--cc=crauer@google.com \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=titusr@google.com \
--cc=wuhaotsh@google.com \
/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).