hw/sensor: MAX31790 support
PATCH 1/1 hw/sensor: MAX31790 support
Product: [1]
Datasheet: [2]
MAX31790 Support:
- fan inputs are reading
- tach reading propertional to pwm setting from linux driver
- fans do not show any fault
- 6 PWM registers influence 6 TACH registers
There is intentional stub behavior in some places and various functions of the device are currently unsupported.
MAX31790 currently unsupported:
- slave address restriction
- fan dynamics
- spin-up configuration
- fault state / failure possibility
- rate-of-change control
- tach mode
- mixed layouts where number of fans != number of tachs
- see Figure 5.9 in [2] for example of mixed layout
Anyone could expand it in the future for more accurate emulation.
Tested: on yosemite 4 qemu
``` root@yosemite4:~# ls /sys/class/hwmon/hwmon2/ device fan2_fault fan3_target fan5_fault fan6_target pwm2 pwm5 fan1_enable fan2_input fan4_enable fan5_input name pwm2_enable pwm5_enable fan1_fault fan2_target fan4_fault fan5_target of_node pwm3 pwm6 fan1_input fan3_enable fan4_input fan6_enable power pwm3_enable pwm6_enable fan1_target fan3_fault fan4_target fan6_fault pwm1 pwm4 subsystem fan2_enable fan3_input fan5_enable fan6_input pwm1_enable pwm4_enable uevent root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_input 4551 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_enable 1 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_fault 0 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_target 2048 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/pwm1 178 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/name max31790 ```
Trace output:
``` max31790_realize i2c_addr: 0x20 max31790_realize i2c_addr: 0x2f max31790_realize i2c_addr: 0x20 max31790_realize i2c_addr: 0x2f max31790_event i2c_addr: 0x20, event: 0x01 max31790_send i2c_addr: 0x20, data: 0x02 max31790_event i2c_addr: 0x20, event: 0x00 max31790_recv i2c_addr: 0x20, reg_addr: 0x02 max31790_recv_return i2c_addr: 0x20, returns: 0x08 ... ```
References:
[1] https://www.analog.com/en/products/MAX31790.html
[2] https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31790.pdf
--- hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/max31790.c | 499 +++++++++++++++++++++++++++++++++++ hw/sensor/meson.build | 1 + hw/sensor/trace-events | 8 + include/hw/sensor/max31790.h | 7 + 6 files changed, 520 insertions(+) create mode 100644 hw/sensor/max31790.c create mode 100644 include/hw/sensor/max31790.h
hw/arm/Kconfig +1 -0
@@ -552,6 +552,7 @@ config ASPEED_SOC select LED select PMBUS select MAX31785 + select MAX31790 select FSI_APB2OPB_ASPEED select AT24C select PCI_EXPRESS
hw/sensor/Kconfig +4 -0
@@ -43,3 +43,7 @@ config ISL_PMBUS_VR config MAX31785 bool depends on PMBUS + +config MAX31790 + bool + depends on PMBUS
hw/sensor/max31790.c new file +499 -0
499 lines not on this page · raw message
hw/sensor/meson.build +1 -0
@@ -8,3 +8,4 @@ system_ss.add(when: 'CONFIG_MAX34451', if_true: files('max34451.c')) system_ss.add(when: 'CONFIG_LSM303DLHC_MAG', if_true: files('lsm303dlhc_mag.c')) system_ss.add(when: 'CONFIG_ISL_PMBUS_VR', if_true: files('isl_pmbus_vr.c')) system_ss.add(when: 'CONFIG_MAX31785', if_true: files('max31785.c')) +system_ss.add(when: 'CONFIG_MAX31790', if_true: files('max31790.c'))
hw/sensor/trace-events +8 -0
@@ -4,3 +4,11 @@ tmp105_read(uint8_t dev, uint8_t addr) "device: 0x%02x, addr: 0x%02x" tmp105_write(uint8_t dev, uint8_t addr) "device: 0x%02x, addr 0x%02x" tmp105_write_shutdown(uint8_t dev) "device: 0x%02x" + +# max31790.c +max31790_send(uint8_t i2c_addr, uint8_t send) "i2c_addr: 0x%02x, data: 0x%02x" +max31790_recv(uint8_t i2c_addr, uint8_t reg_addr) "i2c_addr: 0x%02x, reg_addr: 0x%02x" +max31790_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, returns: 0x%02x" +max31790_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x, event: 0x%02x" +max31790_realize(uint8_t i2c_addr) "i2c_addr: 0x%02x" +max31790_pwm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x"
include/hw/sensor/max31790.h new file +7 -0
@@ -0,0 +1,7 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef QEMU_MAX31790_H +#define QEMU_MAX31790_H + +#define TYPE_MAX31790 "max31790" + +#endif
Signature · 1 line
2.53.0
Quoted 4 lines · Alexander Hansen
Product: [1]
Datasheet: [2]
Quoted 8 lines
MAX31790 Support:
- fan inputs are reading
- tach reading propertional to pwm setting from linux driver
- fans do not show any fault
- 6 PWM registers influence 6 TACH registersThere is intentional stub behavior in some places and various functions of the device are currently unsupported.
Hi; thanks for this patch.
From our conversation on IRC: you say you want this as part of modelling the aspeed yosemite4 board. (I've cc'd Cedric as aspeed maintainer). For upstream QEMU we generally prefer new device models to be sent as part of the patch series that adds the board they're part of, so that they have a use upstream.
The code itself looks mostly in good shape; I have a few first-pass comments below.
Quoted 10 lines
MAX31790 currently unsupported:
- slave address restriction
- fan dynamics
- spin-up configuration
- fault state / failure possibility
- rate-of-change control
- tach mode
- mixed layouts where number of fans != number of tachs
- see Figure 5.9 in [2] for example of mixed layout
Quoted 6 lines
Anyone could expand it in the future for more accurate emulation.
Tested: on yosemite 4 qemu
```
Commit messages aren't markdown, they're plain text.
The commit message also ideally ought to give the rationale for implementing the device (though this is a bit less necessary when it's part of a larger series adding board support).
Quoted 49 lines
root@yosemite4:~# ls /sys/class/hwmon/hwmon2/ device fan2_fault fan3_target fan5_fault fan6_target pwm2 pwm5 fan1_enable fan2_input fan4_enable fan5_input name pwm2_enable pwm5_enable fan1_fault fan2_target fan4_fault fan5_target of_node pwm3 pwm6 fan1_input fan3_enable fan4_input fan6_enable power pwm3_enable pwm6_enable fan1_target fan3_fault fan4_target fan6_fault pwm1 pwm4 subsystem fan2_enable fan3_input fan5_enable fan6_input pwm1_enable pwm4_enable uevent root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_input 4551 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_enable 1 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_fault 0 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/fan1_target 2048 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/pwm1 178 root@yosemite4:~# cat /sys/class/hwmon/hwmon2/name max31790 ```Trace output:
``` max31790_realize i2c_addr: 0x20 max31790_realize i2c_addr: 0x2f max31790_realize i2c_addr: 0x20 max31790_realize i2c_addr: 0x2f max31790_event i2c_addr: 0x20, event: 0x01 max31790_send i2c_addr: 0x20, data: 0x02 max31790_event i2c_addr: 0x20, event: 0x00 max31790_recv i2c_addr: 0x20, reg_addr: 0x02 max31790_recv_return i2c_addr: 0x20, returns: 0x08 ... ```References:
[1] https://www.analog.com/en/products/MAX31790.html
[2] https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31790.pdfCC Paolo Bonzini <[email protected]>CC Peter Maydell <[email protected]>CC "Philippe Mathieu-Daudé" <[email protected]>Signed-off-by Alexander Hansen <[email protected]>---
+++
b/hw/sensor/max31790.c
hw/sensor/max31790.c line 8
Quoted 8 lines
hw/sensor/max31790.c new file +8
-0@@ -0,0 +1,499 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* +* Maxim MAX31790 PMBus 6-Channel Fan Controller +* +* Datasheet: +* https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31790.pdf +* +* Copyright(c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
Copyright doesn't seem to match your email address, and the date is very old: is this code that's been in a downstream fork that you've picked up?
Quoted 10 lines
hw/sensor/max31790.c new file +8
-0+*/ +static void max31790_realize (DeviceState *dev,Error **errp) +{ +MAX31790State *s =MAX31790 (dev); + +trace_max31790_realize (s->i2c.address); + +for (int i =0 ; i <MAX31790_NUM_FANS ; i++) {
hw/sensor/max31790.c line 464
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+/* POR-State 0b 0XX0 0000 */ + s->fan_config[i] =0b00000000 ; + +/* same as POR-State */ + s->tach_target[i] =0b0011110000000000 ; + +/* same as POR-State */ + s->fan_dynamics[i] =0b01001100 ; + + s->pwm[i] =0 ;
Reset should be in a reset method, not realize.
hw/sensor/max31790.c line 470
Quoted 6 lines
hw/sensor/max31790.c new file +6
-0+ } + +for (int i =0 ; i <MAX31790_NUM_TACHS ; i++) { +max31790_set_rpm (s, i,0x4444 ); + } +}
thanks
-- PMM