qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] hw/sensor: enable setting adm1272 temperature with qmp


From: Patrick Venture
Subject: Re: [PATCH] hw/sensor: enable setting adm1272 temperature with qmp
Date: Fri, 7 Jan 2022 10:17:12 -0800



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. 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]