On 10 Jun 2026, at 14:21, Alexander Hansen wrote:
diff --git a/hw/sensor/max31790.c b/hw/sensor/max31790.c
new file mode 100644
index 0000000000..f0aaff84b5
--- /dev/null
+++ b/hw/sensor/max31790.c
+#define TYPE_MAX31790 "max31790"
Might be nice to define it in a .h so machines can use the constant?
+
+#define MAX31790_NUM_FANS 6
+#define MAX31790_NUM_TACHS 12
+
+#define MAX31790_REG_GLOBAL_CONFIG 0x00
+#define MAX31790_REG_PWM_FREQ 0x01
+
+/* 0x02 to 0x07: N = 0 .. 5 */
+#define MAX31790_REG_FAN_CONFIG(N) (0x02 + N)
Maybe use (0x02 + (N))?
+ switch (s->pointer) {
+ case MAX31790_REG_FAN_CONFIG(0):
+ case MAX31790_REG_FAN_CONFIG(1):
+ case MAX31790_REG_FAN_CONFIG(2):
+ case MAX31790_REG_FAN_CONFIG(3):
+ case MAX31790_REG_FAN_CONFIG(4):
+ case MAX31790_REG_FAN_CONFIG(5):
Maybe use case ranges?
+ /* simplified, assuming NP = 2 */
+ uint64_t tach_count = (245760ULL * sr) / (uint64_t)rpm;
Maybe use (some) explicit constants?
+static void max31790_realize(DeviceState *dev, Error **errp)
+{
+ MAX31790State *s = MAX31790(dev);
+
+ trace_max31790_realize(s->i2c.address);
+
+ max31790_reset_enter(s);
Initial reset is usually called from the SoC reset sequence (through
bus_reset_child_foreach), is this explicit reset required?
+static void max31790_class_init(ObjectClass *klass, const void *data)
+{
+ DeviceClass *dc = DEVICE_CLASS(klass);
+ I2CSlaveClass *k = I2C_SLAVE_CLASS(klass);
+
+ dc->realize = max31790_realize;
+ dc->desc = "Maxim MAX31790 6-Channel Fan Controller";
+ dc->vmsd = &vmstate_max31790;
+ dc->legacy_reset = max31790_reset;
Maybe favor the “new” Resettable API, rather than the legacy reset
API?