[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the d
From: |
Philippe Mathieu-Daudé |
Subject: |
[RFC PATCH 10/17] hw/misc/bcm2835_thermal: Hold the temperature in the device state |
Date: |
Tue, 21 Apr 2020 14:16:19 +0200 |
We are going to modify this variable, move it to the device state.
Signed-off-by: Philippe Mathieu-Daudé <address@hidden>
---
include/hw/misc/bcm2835_thermal.h | 1 +
hw/misc/bcm2835_thermal.c | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 5 deletions(-)
diff --git a/include/hw/misc/bcm2835_thermal.h
b/include/hw/misc/bcm2835_thermal.h
index c3651b27ec..df6a7b86c3 100644
--- a/include/hw/misc/bcm2835_thermal.h
+++ b/include/hw/misc/bcm2835_thermal.h
@@ -22,6 +22,7 @@ typedef struct {
/*< public >*/
MemoryRegion iomem;
uint32_t ctl;
+ float64 temp;
} Bcm2835ThermalState;
#endif
diff --git a/hw/misc/bcm2835_thermal.c b/hw/misc/bcm2835_thermal.c
index c6f3b1ad60..6ee149de20 100644
--- a/hw/misc/bcm2835_thermal.c
+++ b/hw/misc/bcm2835_thermal.c
@@ -32,7 +32,7 @@ FIELD(STAT, INTERRUPT, 11, 1)
#define THERMAL_OFFSET_C 412
#define THERMAL_COEFF (-0.538f)
-static uint16_t bcm2835_thermal_temp2adc(int temp_C)
+static uint16_t bcm2835_thermal_temp2adc(float64 temp_C)
{
return (temp_C - THERMAL_OFFSET_C) / THERMAL_COEFF;
}
@@ -47,8 +47,7 @@ static uint64_t bcm2835_thermal_read(void *opaque, hwaddr
addr, unsigned size)
val = s->ctl;
break;
case A_STAT:
- /* Temperature is constantly 25°C. */
- val = FIELD_DP32(bcm2835_thermal_temp2adc(25), STAT, VALID, true);
+ val = FIELD_DP32(bcm2835_thermal_temp2adc(s->temp), STAT, VALID, true);
break;
default:
/* MemoryRegionOps are aligned, so this can not happen. */
@@ -85,6 +84,13 @@ static const MemoryRegionOps bcm2835_thermal_ops = {
.endianness = DEVICE_NATIVE_ENDIAN,
};
+static void bcm2835_thermal_init(Object *obj)
+{
+ Bcm2835ThermalState *s = BCM2835_THERMAL(obj);
+
+ s->temp = 25.0;
+}
+
static void bcm2835_thermal_reset(DeviceState *dev)
{
Bcm2835ThermalState *s = BCM2835_THERMAL(dev);
@@ -103,10 +109,11 @@ static void bcm2835_thermal_realize(DeviceState *dev,
Error **errp)
static const VMStateDescription bcm2835_thermal_vmstate = {
.name = "bcm2835_thermal",
- .version_id = 1,
- .minimum_version_id = 1,
+ .version_id = 2,
+ .minimum_version_id = 2,
.fields = (VMStateField[]) {
VMSTATE_UINT32(ctl, Bcm2835ThermalState),
+ VMSTATE_FLOAT64(temp, Bcm2835ThermalState),
VMSTATE_END_OF_LIST()
}
};
@@ -124,6 +131,7 @@ static const TypeInfo bcm2835_thermal_info = {
.name = TYPE_BCM2835_THERMAL,
.parent = TYPE_SYS_BUS_DEVICE,
.instance_size = sizeof(Bcm2835ThermalState),
+ .instance_init = bcm2835_thermal_init,
.class_init = bcm2835_thermal_class_init,
};
--
2.21.1
- Re: [RFC PATCH 02/17] hw/misc/temp-sensor: Add 'query-temperature-sensors' QMP command, (continued)
- [RFC PATCH 01/17] hw/misc: Introduce the temperature sensor interface, 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 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 11/17] hw/misc/bcm2835_thermal: Implement the 'temperature-sensor' 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é <=
- [RFC PATCH 07/17] hw/misc/tmp421: Extract get_temp_mC() helper, 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 13/17] hw/misc/bcm2835_property: Implement the 'temperature-sensor' 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