[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qde
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface |
Date: |
Tue, 21 Apr 2020 14:16:18 +0200 |
The TMP421 is an I2C device with multiple temperature sensors.
Let it implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/misc/tmp421.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/hw/misc/tmp421.c b/hw/misc/tmp421.c
index 270e7d5510..31bfbecb1d 100644
--- a/hw/misc/tmp421.c
+++ b/hw/misc/tmp421.c
@@ -30,6 +30,7 @@
#include "qapi/error.h"
#include "qapi/visitor.h"
#include "qemu/module.h"
+#include "hw/misc/temp-sensor.h"
/* Manufacturer / Device ID's */
#define TMP421_MANUFACTURER_ID 0x55
@@ -138,6 +139,21 @@ static void set_temp_mC(TMP421State *s, unsigned int id,
s->temperature[id] = (int16_t) ((temp * 256 - 128) / 1000) + offset;
}
+static float tmp421_get_temp(TempSensor *obj, unsigned sensor_id)
+{
+ TMP421State *s = TMP421(obj);
+
+ return get_temp_mC(s, sensor_id) / 1000.f;
+}
+
+static void tmp421_set_temp(TempSensor *obj, unsigned sensor_id,
+ float temp_C, Error **errp)
+{
+ TMP421State *s = TMP421(obj);
+
+ set_temp_mC(s, sensor_id, temp_C * 1000.f, errp);
+}
+
static void tmp421_get_temperature(Object *obj, Visitor *v, const char *name,
void *opaque, Error **errp)
{
@@ -380,6 +396,7 @@ static void tmp421_class_init(ObjectClass *klass, void
*data)
DeviceClass *dc = DEVICE_CLASS(klass);
I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
TMP421Class *sc = TMP421_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->realize = tmp421_realize;
k->event = tmp421_event;
@@ -387,6 +404,9 @@ static void tmp421_class_init(ObjectClass *klass, void
*data)
k->send = tmp421_tx;
dc->vmsd = &vmstate_tmp421;
sc->dev = (DeviceInfo *) data;
+ tc->sensor_count = SENSORS_COUNT;
+ tc->set_temperature = tmp421_set_temp;
+ tc->get_temperature = tmp421_get_temp;
}
static const TypeInfo tmp421_info = {
@@ -396,6 +416,10 @@ static const TypeInfo tmp421_info = {
.class_size = sizeof(TMP421Class),
.instance_init = tmp421_initfn,
.abstract = true,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void tmp421_register_types(void)
--
2.21.1
- [RFC PATCH 00/17] hw/misc: Introduce a temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 06/17] hw/misc/tmp421: Add definition for SENSORS_COUNT, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 08/17] hw/misc/tmp421: Extract set_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 05/17] hw/misc/tmp105: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 09/17] hw/misc/tmp421: Implement the 'temperature-sensor' qdev interface,
Philippe Mathieu-Daudé <=
- [RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 15/17] hw/ide/qdev: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 14/17] hw/display/ads7846: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 16/17] hw/misc/imx6ul_ccm: Implement the 'temperature-sensor' qdev interface, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' interface, Philippe Mathieu-Daudé, 2020/04/21