[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-se
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface |
Date: |
Tue, 21 Apr 2020 14:16:20 +0200 |
The BCM2835 has a block that reports its temperature.
Let it implement the 'temperature-sensor' interface.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
hw/misc/bcm2835_thermal.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
index 6ee149de20..6b85cf9705 100644
--- a/hw/misc/bcm2835_thermal.c
+++ b/hw/misc/bcm2835_thermal.c
@@ -12,6 +12,7 @@
#include "hw/misc/bcm2835_thermal.h"
#include "hw/registerfields.h"
#include "migration/vmstate.h"
+#include "hw/misc/temp-sensor.h"
REG32(CTL, 0)
FIELD(CTL, POWER_DOWN, 0, 1)
@@ -32,6 +33,21 @@ FIELD(STAT, INTERRUPT, 11, 1)
#define THERMAL_OFFSET_C 412
#define THERMAL_COEFF (-0.538f)
+static void bcm2835_set_temperature(TempSensor *obj, unsigned int sensor_id,
+ float temp, Error **errp)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ s->temp = temp;
+}
+
+static float bcm2835_get_temperature(TempSensor *obj, unsigned int sensor_id)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ return s->temp;
+}
+
static uint16_t bcm2835_thermal_temp2adc(float64 temp_C)
{
return (temp_C - THERMAL_OFFSET_C) / THERMAL_COEFF;
@@ -121,10 +137,14 @@ static const VMStateDescription bcm2835_thermal_vmstate =
{
static void bcm2835_thermal_class_init(ObjectClass *klass, void *data)
{
DeviceClass *dc = DEVICE_CLASS(klass);
+ TempSensorClass *tc = TEMPSENSOR_INTERFACE_CLASS(klass);
dc->realize = bcm2835_thermal_realize;
dc->reset = bcm2835_thermal_reset;
dc->vmsd = &bcm2835_thermal_vmstate;
+ tc->sensor_count = 1;
+ tc->set_temperature = bcm2835_set_temperature;
+ tc->get_temperature = bcm2835_get_temperature;
}
static const TypeInfo bcm2835_thermal_info = {
@@ -133,6 +153,10 @@ static const TypeInfo bcm2835_thermal_info = {
.instance_size = sizeof(Bcm2835ThermalState),
.instance_init = bcm2835_thermal_init,
.class_init = bcm2835_thermal_class_init,
+ .interfaces = (InterfaceInfo[]) {
+ { TYPE_TEMPSENSOR_INTERFACE },
+ { }
+ },
};
static void bcm2835_thermal_register_types(void)
--
2.21.1
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command, (continued)
- [RFC PATCH 03/17] hw/misc/temp-sensor: Add 'info temp' HMP command, 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 04/17] hw/misc/tmp105: Extract get_temp_mC() and set_temp_mC() helpers, 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 08/17] hw/misc/tmp421: Extract set_temp_mC() helper, 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 12/17] hw/misc/bcm2835_property: Hold the temperature in the device state, Philippe Mathieu-Daudé, 2020/04/21
- [RFC PATCH 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' interface,
Philippe Mathieu-Daudé <=
- [RFC PATCH 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' 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 16/17] hw/misc/imx6ul_ccm: Implement the 'temperature-sensor' qdev interface, 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 17/17] tests/qtest/tmp105-test: Trivial test for TempSensorClass, Philippe Mathieu-Daudé, 2020/04/21