[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface |
Date: |
Tue, 21 Apr 2020 14:16:10 +0200 |
Introduce an interface to set and get temperature from devices.
A device can have multiple temperature sensors.
Each sensor might have a custom name.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/misc/temp-sensor.h | 69 +++++++++++++++++++++++++++++++++++
hw/misc/temp-sensor.c | 25 +++++++++++++
MAINTAINERS | 6 +++
hw/misc/Makefile.objs | 1 +
4 files changed, 101 insertions(+)
create mode 100644 include/hw/misc/temp-sensor.h
create mode 100644 hw/misc/temp-sensor.c
diff --git a/include/hw/misc/temp-sensor.h b/include/hw/misc/temp-sensor.h
new file mode 100644
index 0000000000..3067b1dd2e
--- /dev/null
+++ b/include/hw/misc/temp-sensor.h
@@ -0,0 +1,69 @@
+/*
+ * Generic interface for temperature sensors
+ *
+ * Copyright (c) 2020 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef HW_MISC_TEMP_SENSOR_H
+#define HW_MISC_TEMP_SENSOR_H
+
+#include "qom/object.h"
+
+#define TYPE_TEMPSENSOR_INTERFACE "temp-sensor-interface"
+#define TEMPSENSOR_INTERFACE(obj) \
+ INTERFACE_CHECK(TempSensor, (obj), TYPE_TEMPSENSOR_INTERFACE)
+#define TEMPSENSOR_INTERFACE_CLASS(class) \
+ OBJECT_CLASS_CHECK(TempSensorClass, (class), TYPE_TEMPSENSOR_INTERFACE)
+#define TEMPSENSOR_INTERFACE_GET_CLASS(class) \
+ OBJECT_GET_CLASS(TempSensorClass, (class), TYPE_TEMPSENSOR_INTERFACE)
+
+typedef struct TempSensor TempSensor;
+
+typedef struct TempSensorClass {
+ /* <private> */
+ InterfaceClass parent;
+ /* <public> */
+
+ /** Number of temperature sensors */
+ size_t sensor_count;
+
+ /**
+ * get_name:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ *
+ * Returns: name of a temperature sensor.
+ */
+ const char *(*get_name)(TempSensor *obj, unsigned sensor_id);
+
+ /**
+ * set_temperature:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ * @temp_C: sensor temperature, in degree Celsius
+ * @errp: pointer to a NULL-initialized error object
+ *
+ * Set a sensor temperature.
+ *
+ * If an error occurs @errp will contain the details
+ * (likely temperature out of range).
+ */
+ void (*set_temperature)(TempSensor *obj,
+ unsigned sensor_id, float temp_C, Error **errp);
+
+ /**
+ * get_temperature:
+ * @obj: opaque pointer to Object
+ * @sensor_id: sensor index
+ *
+ * Get a sensor temperature.
+ *
+ * Returns: sensor temperature in °C.
+ */
+ float (*get_temperature)(TempSensor *obj, unsigned sensor_id);
+} TempSensorClass;
+
+#endif /* HW_MISC_TEMP_SENSOR_H */
diff --git a/hw/misc/temp-sensor.c b/hw/misc/temp-sensor.c
new file mode 100644
index 0000000000..b7c1eb2d87
--- /dev/null
+++ b/hw/misc/temp-sensor.c
@@ -0,0 +1,25 @@
+/*
+ * Generic interface for temperature sensors
+ *
+ * Copyright (c) 2020 Philippe Mathieu-Daudé
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#include "qemu/osdep.h"
+#include "hw/misc/temp-sensor.h"
+
+static TypeInfo tempsensor_interface_type_info = {
+ .name = TYPE_TEMPSENSOR_INTERFACE,
+ .parent = TYPE_INTERFACE,
+ .class_size = sizeof(TempSensorClass),
+};
+
+static void tempsensor_register_types(void)
+{
+ type_register_static(&tempsensor_interface_type_info);
+}
+
+type_init(tempsensor_register_types)
diff --git a/MAINTAINERS b/MAINTAINERS
index 8cbc1fac2b..5559110c56 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -1575,6 +1575,12 @@ F: hw/sd/sd*
F: hw/sd/ssi-sd.c
F: tests/qtest/sd*
+Temperature Sensors
+M: Philippe Mathieu-Daudé <address@hidden>
+S: Odd Fixes
+F: hw/misc/temp-sensor.c
+F: include/hw/misc/temp-sensor.h
+
USB
M: Gerd Hoffmann <address@hidden>
S: Maintained
diff --git a/hw/misc/Makefile.objs b/hw/misc/Makefile.objs
index 68aae2eabb..4f90efb06d 100644
--- a/hw/misc/Makefile.objs
+++ b/hw/misc/Makefile.objs
@@ -90,3 +90,4 @@ common-obj-$(CONFIG_NRF51_SOC) += nrf51_rng.o
obj-$(CONFIG_MAC_VIA) += mac_via.o
common-obj-$(CONFIG_GRLIB) += grlib_ahb_apb_pnp.o
+common-obj-y += temp-sensor.o
--
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é <=
- [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é, 2020/04/21
- [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