* [PATCH] hw/sensor: enable setting adm1272 temperature with qmp
@ 2022-01-06 17:38 Patrick Venture
[not found] ` <07207168-0940-a3de-c188-d676658603e8@redhat.com>
2022-03-15 11:07 ` Philippe Mathieu-Daudé
0 siblings, 2 replies; 3+ messages in thread
From: Patrick Venture @ 2022-01-06 17:38 UTC (permalink / raw)
To: thuth, lvivier, pbonzini, cminyard
Cc: qemu-devel, Titus Rwantare, Patrick Venture, Chris Rauer, Hao Wu
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/sensor: enable setting adm1272 temperature with qmp
[not found] ` <07207168-0940-a3de-c188-d676658603e8@redhat.com>
@ 2022-01-07 18:17 ` Patrick Venture
0 siblings, 0 replies; 3+ messages in thread
From: Patrick Venture @ 2022-01-07 18:17 UTC (permalink / raw)
To: Thomas Huth; +Cc: QEMU Developers
[-- Attachment #1: Type: text/plain, Size: 6531 bytes --]
On Fri, Jan 7, 2022 at 5:24 AM Thomas Huth <thuth@redhat.com> wrote:
> On 06/01/2022 18.38, Patrick Venture wrote:
> > 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 */
>
> qtest part:
> Acked-by: Thomas Huth <thuth@redhat.com>
>
Adding your Ack to the mailing list version.
[-- Attachment #2: Type: text/html, Size: 8584 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] hw/sensor: enable setting adm1272 temperature with qmp
2022-01-06 17:38 [PATCH] hw/sensor: enable setting adm1272 temperature with qmp Patrick Venture
[not found] ` <07207168-0940-a3de-c188-d676658603e8@redhat.com>
@ 2022-03-15 11:07 ` Philippe Mathieu-Daudé
1 sibling, 0 replies; 3+ messages in thread
From: Philippe Mathieu-Daudé @ 2022-03-15 11:07 UTC (permalink / raw)
To: Patrick Venture, thuth, lvivier, pbonzini, cminyard
Cc: Titus Rwantare, Hao Wu, qemu-devel, Chris Rauer
On 6/1/22 18:38, Patrick Venture wrote:
> 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(-)
Queued to i2c-next.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-03-15 11:09 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-06 17:38 [PATCH] hw/sensor: enable setting adm1272 temperature with qmp Patrick Venture
[not found] ` <07207168-0940-a3de-c188-d676658603e8@redhat.com>
2022-01-07 18:17 ` Patrick Venture
2022-03-15 11:07 ` Philippe Mathieu-Daudé
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.