initial support for yosemite4
Subsystems (2)
v5 cover initial support for yosemite4
Thanks to Titus, Jonathan and Cedric for reviewing
Summary of changes from v4:
machine:
- no changes
functional test:
- add missing import: from qemu_test import wait_for_console_pattern
max31790:
- add trailing newline to log messages
- fix a couple of formatting issues
- log a guest error if max31790_recv detects over-read
- fix Kconfig (depends on I2C) instead of PMBUS
- remove an unused import from functional test
- rename 'rpm' array to 'tach_count' to better reflect its actual purpose
- fix functional test with correct RPM value and additional checks to test for
pwm1 <= pwm2 => rpm(pwm1) <= rpm(pwm2)
I must have had some misconception about what's stored in tach_count and how it relates to rpm, hope that's cleared up now in the code.
max11615:
- fix comment style in header
- remove #include <stdint.h>
- max11615_write_config_byte: fix comment (MAX11615 is only 8 channels)
- fix possible out of bounds access missed by max11615_write_config_byte
- remove an empty function
- max11615_init_with_values: simplify (directly applied the suggested code snippet)
- max11615_reset: reset channel readings as well.
- init_with_values uses decimals now instead of binary notation
- support differential mode
- support unipolar / bipolar mode
- max11615_write_config_byte: log unimplemented for scan mode != 0b11
- max11615_write_setup_byte: log unimplemented for external reference set
- max11615_recv: support multichannel scans
- functional test is using stable file name (bus + address + wildcard)
adc128d818:
- fix comment style in header
- replace #include <stdint.h> with #include <qemu/osdep.h>
- adc128d818_write_advanced_config: reset channel readings and interrupt status
- adc128d818_send: check s->len before writing into s->buf[s->len]
- adc128d818_init: remove (empty function)
- adc128d818_init_with_values: simplify channel init similar to max11615
- adc128d818_reset: reset channel readings
Alexander Hansen (5):
ast2600: yosemite4 initial support
ast2600: yosemite4 functional test
hw/sensor: MAX31790 support
hw/sensor: support MAX11615
hw/sensor: support Texas Instruments ADC128D818
MAINTAINERS | 3 + include/hw/sensor/adc128d818.h | 23 + include/hw/sensor/max11615.h | 20 + hw/arm/aspeed_ast2600_fby4.c | 280 ++++++++++++ hw/sensor/adc128d818.c | 433 ++++++++++++++++++ hw/sensor/max11615.c | 312 +++++++++++++ hw/sensor/max31790.c | 537 +++++++++++++++++++++++ hw/arm/Kconfig | 3 + hw/arm/meson.build | 1 + hw/sensor/Kconfig | 12 + hw/sensor/meson.build | 3 + hw/sensor/trace-events | 26 ++ tests/functional/arm/meson.build | 2 + tests/functional/arm/test_aspeed_fby4.py | 89 ++++ 14 files changed, 1744 insertions(+) create mode 100644 include/hw/sensor/adc128d818.h create mode 100644 include/hw/sensor/max11615.h create mode 100644 hw/arm/aspeed_ast2600_fby4.c create mode 100644 hw/sensor/adc128d818.c create mode 100644 hw/sensor/max11615.c create mode 100644 hw/sensor/max31790.c create mode 100755 tests/functional/arm/test_aspeed_fby4.py
Signature · 1 line
2.54.0
PATCH v5 1/5 ast2600: yosemite4 initial support
Initial patch based on [1] to support yosemite v4 bmc emulation.
The goal of this machine support is to support OpenBMC development.
Reference linux devicetree from openbmc linux is [2].
Status:
- Enclosure FRU: showing up - Management Board FRU: showing up - Blade Board FRU: showing up - Blade Board sensors: not implemented - Blade Chassis FRU: showing up - Fan Board FRU: both showing up - Fan Board sensors: supported
Overall the emulation is incomplete but already helpful in development and testing.
The focus of this initial support is on the FRU eeproms and fanboard sensors.
Tested: booted an OpenBMC image for yosemite4 target.
References:
[1] https://github.com/9elements/qemu/commit/32139f913c2bd0ebe4bd26c46765861f6f9f2d49
[2] arch/arm/boot/dts/aspeed/aspeed-bmc-facebook-yosemite4.dts
[3] https://github.com/legoater/qemu-aspeed-boot/pull/5
--- hw/arm/aspeed_ast2600_fby4.c | 267 +++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 1 + 2 files changed, 268 insertions(+) create mode 100644 hw/arm/aspeed_ast2600_fby4.c
hw/arm/aspeed_ast2600_fby4.c new file +267 -0
@@ -0,0 +1,267 @@ +/* +* Facebook Yosemite V4 +* +* Copyright 2026 9elements. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "hw/arm/machines-qom.h" +#include "hw/arm/aspeed.h" +#include "hw/arm/aspeed_soc.h" +#include "hw/nvram/eeprom_at24c.h" +#include "hw/i2c/i2c_mux_pca954x.h" +#include "hw/gpio/pca9552.h" + +#define FBY4_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) + +/* START OF EEPROM CONTENTS */ + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Fan Board FSC-MAX ADC-TI LED-NXP EFUSE-MAX" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set product.custom="Fanboard Custom1" \ +* --set product.custom.1="Fanboard Custom2" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-fanboard.bin +*/ +/* EM Config: yosemite4_fanboard_fsc_max_adc_ti_led_nxp_ons_efuse_max.json */ +/* Yosemite4 fan board */ +static const uint8_t fru_yv4_fanboard_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x0b ,0x00 ,0x00 ,0xf3 ,0x01 ,0x0a ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xea ,0x46 ,0x61 , +0x6e ,0x20 ,0x42 ,0x6f ,0x61 ,0x72 ,0x64 ,0x20 ,0x46 ,0x53 ,0x43 ,0x2d , +0x4d ,0x41 ,0x58 ,0x20 ,0x41 ,0x44 ,0x43 ,0x2d ,0x54 ,0x49 ,0x20 ,0x4c , +0x45 ,0x44 ,0x2d ,0x4e ,0x58 ,0x50 ,0x20 ,0x45 ,0x46 ,0x55 ,0x53 ,0x45 , +0x2d ,0x4d ,0x41 ,0x58 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 , +0x52 ,0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 , +0x00 ,0x00 ,0x00 ,0xdb ,0x01 ,0x09 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 , +0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 , +0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 , +0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e , +0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xd0 ,0x46 ,0x61 ,0x6e ,0x62 , +0x6f ,0x61 ,0x72 ,0x64 ,0x20 ,0x43 ,0x75 ,0x73 ,0x74 ,0x6f ,0x6d ,0x32 , +0xc1 ,0x00 ,0x00 ,0x9d +}; +static const size_t fru_yv4_fanboard_bin_len =sizeof (fru_yv4_fanboard_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Sentinel Dome without Retimer" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set product.custom="Yosemite V4 T1" \ +* --set product.custom.1="Yosemite V4 T1" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-sentineldome-board.bin +*/ +/* product.cust maps to PRODUCT_INFO_AM2 */ +/* EM Config: yosemite4_sentineldome_t1.json */ +/* Yosemite4 Sentinel Dome without Retimer Boards */ +static const uint8_t fru_yv4_sentineldome_board_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x09 ,0x00 ,0x00 ,0xf5 ,0x01 ,0x08 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xdd ,0x53 ,0x65 , +0x6e ,0x74 ,0x69 ,0x6e ,0x65 ,0x6c ,0x20 ,0x44 ,0x6f ,0x6d ,0x65 ,0x20 , +0x77 ,0x69 ,0x74 ,0x68 ,0x6f ,0x75 ,0x74 ,0x20 ,0x52 ,0x65 ,0x74 ,0x69 , +0x6d ,0x65 ,0x72 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 ,0x52 , +0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 ,0x78 , +0x01 ,0x09 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcb ,0x59 , +0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 ,0x56 ,0x34 ,0xc6 ,0x50 , +0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 ,0x2e ,0x31 ,0x85 ,0x91 , +0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e ,0x25 ,0xfa ,0xb2 ,0x64 , +0x29 ,0x03 ,0xc0 ,0xce ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 , +0x20 ,0x56 ,0x34 ,0x20 ,0x54 ,0x31 ,0xc1 ,0x00 ,0x00 ,0x00 ,0x00 ,0xeb +}; +static const size_t fru_yv4_sentineldome_board_bin_len = +sizeof (fru_yv4_sentineldome_board_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Sentinel Dome" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-sentineldome-chassis.bin +*/ +/* EM Config: yosemite4_sentineldome_chassis.json */ +/* Yosemite 4 Sentinel Dome Chassis FRU */ +static const uint8_t fru_yv4_sentineldome_chassis_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x07 ,0x00 ,0x00 ,0xf7 ,0x01 ,0x06 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcd ,0x53 ,0x65 , +0x6e ,0x74 ,0x69 ,0x6e ,0x65 ,0x6c ,0x20 ,0x44 ,0x6f ,0x6d ,0x65 ,0x85 , +0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 ,0x52 ,0x44 ,0x2d ,0x50 ,0x4e , +0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 ,0xb6 ,0x01 ,0x07 ,0x19 ,0xc6 , +0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d , +0x69 ,0x74 ,0x65 ,0x20 ,0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 , +0x35 ,0xc4 ,0x76 ,0x31 ,0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 , +0x89 ,0x30 ,0x1b ,0x8e ,0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xc1 , +0x00 ,0x00 ,0x00 ,0x59 +}; +static const size_t fru_yv4_sentineldome_chassis_bin_len = +sizeof (fru_yv4_sentineldome_chassis_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Management Board wBMC" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-eclosure.bin +*/ +/* EM Config: yosemite4_chassis.json, yosemite4.json */ +/* Yosemite 4 Sentinel Dome Enclosure FRU */ +static const uint8_t fru_yv4_eclosure_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x08 ,0x00 ,0x00 ,0xf6 ,0x01 ,0x07 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xd5 ,0x4d ,0x61 , +0x6e ,0x61 ,0x67 ,0x65 ,0x6d ,0x65 ,0x6e ,0x74 ,0x20 ,0x42 ,0x6f ,0x61 , +0x72 ,0x64 ,0x20 ,0x77 ,0x42 ,0x4d ,0x43 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 , +0x05 ,0xca ,0x42 ,0x52 ,0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 , +0xc0 ,0xc1 ,0x00 ,0x26 ,0x01 ,0x07 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 , +0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 , +0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 , +0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e , +0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xc1 ,0x00 ,0x00 ,0x00 ,0x59 +}; +static const size_t fru_yv4_eclosure_bin_len =sizeof (fru_yv4_eclosure_bin); + +/* END OF EEPROM CONTENTS */ + +static void fby4_i2c_init_fanboard (I2CSlave *fan_mux,size_t eepromSize) +{ +/* 2 fan boards */ +for (int i =0 ; i <=1 ; i++) { +/* downstream bus */ +I2CBus *bus =pca954x_i2c_get_bus (fan_mux, i); + +/* ti,adc128d818 @ 0x1f (adc) */ +/* TODO */ + +/* maxim,max31790 @ 0x20 (pwm) */ +/* TODO */ + +/* +* ti,tca6424 @ 0x22 (gpio) +* linux handles tca6424 with PCA953X_TYPE, same as pca9535 +* { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, +* { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, +* so we _could_ be fine here unless more than 16 gpios are used +*/ +i2c_slave_create_simple (bus,TYPE_PCA9535 ,0x22 ); + +/* +* NOTE: above works and could use for gpio presence: +* $ gpioget gpiochip2 2 +* 1 +*/ + +/* maxim,max31790 @ 0x2f (pwm) */ +/* TODO */ + +/* maxim,max11615 @ 0x33 (adc) */ +/* TODO */ + +at24c_eeprom_init_rom ( + bus,0x52 , eepromSize, + fru_yv4_fanboard_bin, + fru_yv4_fanboard_bin_len); + +/* LED blink driver / gpio expander */ +/* nxp,pca9552 @ 0x61 (gpio) */ +i2c_slave_create_simple (bus,TYPE_PCA9552 ,0x61 ); + } +} + +static void fby4_i2c_init_blade_chassis (I2CBus *bus,size_t eepromSize) +{ +/* Sentinel Dome Blade EEPROMS */ + +/* Board */ +at24c_eeprom_init_rom (bus,0x54 , eepromSize, + fru_yv4_sentineldome_board_bin, fru_yv4_sentineldome_board_bin_len); + +/* Chassis */ +at24c_eeprom_init_rom (bus,0x55 , eepromSize, + fru_yv4_sentineldome_chassis_bin, fru_yv4_sentineldome_chassis_bin_len); +} + +static void fby4_i2c_init_multiple_blade_chassis (I2CBus **i2c, +size_t eepromSize) +{ +/* there is 8 blade chassis, but we only emulate 2 for performance reason */ +for (int bus =1 ; bus <= (8 /4 ); bus++) { +fby4_i2c_init_blade_chassis (i2c[bus], eepromSize); + } +} + +static void fby4_i2c_init (AspeedMachineState *bmc) +{ +AspeedSoCState *soc = bmc->soc; +I2CBus *i2c[16 ]; + +for (int i =0 ; i <16 ; i++) { + i2c[i] =aspeed_i2c_get_bus (&soc->i2c, i); + } + +/* Enclosure (EM Config: yosemite4_chassis.json, yosemite4.json) */ +at24c_eeprom_init_rom (i2c[1 ],0x51 ,128 * KiB, + fru_yv4_eclosure_bin, fru_yv4_eclosure_bin_len); + +fby4_i2c_init_multiple_blade_chassis (i2c,128 * KiB); + +/* Yv4 fanboard connection */ +I2CSlave *fan_mux =i2c_slave_create_simple (i2c[14 ],TYPE_PCA9546 ,0x74 ); + +fby4_i2c_init_fanboard (fan_mux,128 * KiB); +} + +static void aspeed_machine_fby4_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +AspeedMachineClass *amc =ASPEED_MACHINE_CLASS (oc); + + mc->desc ="Facebook fby4 BMC (Cortex-A7)" ; + amc->fmc_model ="mx66l1g45g" ; + amc->num_cs =2 ; + amc->macs_mask =ASPEED_MAC3_ON ; + amc->i2c_init = fby4_i2c_init; + mc->default_ram_size =FBY4_BMC_RAM_SIZE ; +aspeed_machine_class_init_cpus_defaults (mc); +} + +static const TypeInfo aspeed_ast2600_fby4_types[] = { + { + .name =MACHINE_TYPE_NAME ("fby4-bmc" ), + .parent =MACHINE_TYPE_NAME ("ast2600-evb" ), + .class_init = aspeed_machine_fby4_class_init, + .interfaces = arm_machine_interfaces, + } +}; + +DEFINE_TYPES (aspeed_ast2600_fby4_types)
hw/arm/meson.build +1 -0
@@ -59,6 +59,7 @@ arm_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_ast2600_catalina.c', 'aspeed_ast2600_evb.c', 'aspeed_ast2600_fby35.c', + 'aspeed_ast2600_fby4.c', 'aspeed_ast2600_fuji.c', 'aspeed_ast2600_gb200nvl.c', 'aspeed_ast2600_rainier.c',
Signature · 1 line
2.54.0
Re: [PATCH v5 1/5] ast2600: yosemite4 initial support
Quoted 41 lines · Alexander Hansen
Initial patch based on [1] to support yosemite v4 bmc emulation.
The goal of this machine support is to support OpenBMC development.
Reference linux devicetree from openbmc linux is [2].
Status:
- Enclosure FRU: showing up - Management Board FRU: showing up - Blade Board FRU: showing up - Blade Board sensors: not implemented - Blade Chassis FRU: showing up - Fan Board FRU: both showing up - Fan Board sensors: supportedOverall the emulation is incomplete but already helpful in development and testing.
The focus of this initial support is on the FRU eeproms and fanboard sensors.
Tested: booted an OpenBMC image for yosemite4 target.
References:
[1] https://github.com/9elements/qemu/commit/32139f913c2bd0ebe4bd26c46765861f6f9f2d49
[2]arch/arm/boot/dts/aspeed/aspeed-bmc-facebook-yosemite4.dts
[3] https://github.com/legoater/qemu-aspeed-boot/pull/5Cc Titus Rwantare <[email protected]>Cc "Cédric Le Goater" <[email protected]> (maintainer:ASPEED BMCs)Cc Peter Maydell <[email protected]> (maintainer:ASPEED BMCs)Cc Steven Lee <[email protected]> (reviewer:ASPEED BMCs)Cc Troy Lee <[email protected]> (reviewer:ASPEED BMCs)Cc Jamin Lin <[email protected]> (reviewer:ASPEED BMCs)Cc Kane Chen <[email protected]> (reviewer:ASPEED BMCs)Cc Andrew Jeffery <[email protected]> (reviewer:ASPEED BMCs)Cc Joel Stanley <[email protected]> (reviewer:ASPEED BMCs)Cc [email protected] (open list:ASPEED BMCs)Cc [email protected] (open list:All patches CC here)Reviewed-by Cédric Le Goater <[email protected]>Signed-off-by Alexander Hansen <[email protected]>
Quoted 3 lines
--- hw/arm/aspeed_ast2600_fby4.c | 267 +++++++++++++++++++++++++++++++++++ hw/arm/meson.build | 1 +
Please mention the new machine in docs/system/arm/aspeed.rst
Quoted 219 lines
2 files changed, 268 insertions(+)create mode 100644
hw/arm/aspeed_ast2600_fby4.chw/arm/aspeed_ast2600_fby4.c new file +210
-0@@ -0,0 +1,267 @@ +/* +* Facebook Yosemite V4 +* +* Copyright 2026 9elements. +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "hw/arm/machines-qom.h" +#include "hw/arm/aspeed.h" +#include "hw/arm/aspeed_soc.h" +#include "hw/nvram/eeprom_at24c.h" +#include "hw/i2c/i2c_mux_pca954x.h" +#include "hw/gpio/pca9552.h" + +#define FBY4_BMC_RAM_SIZE ASPEED_RAM_SIZE(2 * GiB) + +/* START OF EEPROM CONTENTS */ + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Fan Board FSC-MAX ADC-TI LED-NXP EFUSE-MAX" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set product.custom="Fanboard Custom1" \ +* --set product.custom.1="Fanboard Custom2" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-fanboard.bin +*/ +/* EM Config: yosemite4_fanboard_fsc_max_adc_ti_led_nxp_ons_efuse_max.json */ +/* Yosemite4 fan board */ +static const uint8_t fru_yv4_fanboard_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x0b ,0x00 ,0x00 ,0xf3 ,0x01 ,0x0a ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xea ,0x46 ,0x61 , +0x6e ,0x20 ,0x42 ,0x6f ,0x61 ,0x72 ,0x64 ,0x20 ,0x46 ,0x53 ,0x43 ,0x2d , +0x4d ,0x41 ,0x58 ,0x20 ,0x41 ,0x44 ,0x43 ,0x2d ,0x54 ,0x49 ,0x20 ,0x4c , +0x45 ,0x44 ,0x2d ,0x4e ,0x58 ,0x50 ,0x20 ,0x45 ,0x46 ,0x55 ,0x53 ,0x45 , +0x2d ,0x4d ,0x41 ,0x58 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 , +0x52 ,0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 , +0x00 ,0x00 ,0x00 ,0xdb ,0x01 ,0x09 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 , +0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 , +0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 , +0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e , +0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xd0 ,0x46 ,0x61 ,0x6e ,0x62 , +0x6f ,0x61 ,0x72 ,0x64 ,0x20 ,0x43 ,0x75 ,0x73 ,0x74 ,0x6f ,0x6d ,0x32 , +0xc1 ,0x00 ,0x00 ,0x9d +}; +static const size_t fru_yv4_fanboard_bin_len =sizeof (fru_yv4_fanboard_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Sentinel Dome without Retimer" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set product.custom="Yosemite V4 T1" \ +* --set product.custom.1="Yosemite V4 T1" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-sentineldome-board.bin +*/ +/* product.cust maps to PRODUCT_INFO_AM2 */ +/* EM Config: yosemite4_sentineldome_t1.json */ +/* Yosemite4 Sentinel Dome without Retimer Boards */ +static const uint8_t fru_yv4_sentineldome_board_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x09 ,0x00 ,0x00 ,0xf5 ,0x01 ,0x08 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xdd ,0x53 ,0x65 , +0x6e ,0x74 ,0x69 ,0x6e ,0x65 ,0x6c ,0x20 ,0x44 ,0x6f ,0x6d ,0x65 ,0x20 , +0x77 ,0x69 ,0x74 ,0x68 ,0x6f ,0x75 ,0x74 ,0x20 ,0x52 ,0x65 ,0x74 ,0x69 , +0x6d ,0x65 ,0x72 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 ,0x52 , +0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 ,0x78 , +0x01 ,0x09 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcb ,0x59 , +0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 ,0x56 ,0x34 ,0xc6 ,0x50 , +0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 ,0x2e ,0x31 ,0x85 ,0x91 , +0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e ,0x25 ,0xfa ,0xb2 ,0x64 , +0x29 ,0x03 ,0xc0 ,0xce ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 , +0x20 ,0x56 ,0x34 ,0x20 ,0x54 ,0x31 ,0xc1 ,0x00 ,0x00 ,0x00 ,0x00 ,0xeb +}; +static const size_t fru_yv4_sentineldome_board_bin_len = +sizeof (fru_yv4_sentineldome_board_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Sentinel Dome" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-sentineldome-chassis.bin +*/ +/* EM Config: yosemite4_sentineldome_chassis.json */ +/* Yosemite 4 Sentinel Dome Chassis FRU */ +static const uint8_t fru_yv4_sentineldome_chassis_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x07 ,0x00 ,0x00 ,0xf7 ,0x01 ,0x06 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcd ,0x53 ,0x65 , +0x6e ,0x74 ,0x69 ,0x6e ,0x65 ,0x6c ,0x20 ,0x44 ,0x6f ,0x6d ,0x65 ,0x85 , +0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0xca ,0x42 ,0x52 ,0x44 ,0x2d ,0x50 ,0x4e , +0x2d ,0x33 ,0x34 ,0x35 ,0xc0 ,0xc1 ,0x00 ,0xb6 ,0x01 ,0x07 ,0x19 ,0xc6 , +0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d , +0x69 ,0x74 ,0x65 ,0x20 ,0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 , +0x35 ,0xc4 ,0x76 ,0x31 ,0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 , +0x89 ,0x30 ,0x1b ,0x8e ,0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xc1 , +0x00 ,0x00 ,0x00 ,0x59 +}; +static const size_t fru_yv4_sentineldome_chassis_bin_len = +sizeof (fru_yv4_sentineldome_chassis_bin); + +/* +*./frugen -s board.mfg="Wiwynn" \ +* --set board.pname="Management Board wBMC" \ +* --set text:board.pn="BRD-PN-345" \ +* --board-date "10/1/2017 12:58:00" \ +* --set board.serial="123456" \ +* --set product.pname="Yosemite V4" \ +* --set product.mfg="Wiwynn" \ +* --set product.ver="v1.1" \ +* --set product.serial="123456" \ +* --set product.atag="PLACEHOLDER" \ +* --set text:product.pn="PN-345" \ +* fru-yv4-eclosure.bin +*/ +/* EM Config: yosemite4_chassis.json, yosemite4.json */ +/* Yosemite 4 Sentinel Dome Enclosure FRU */ +static const uint8_t fru_yv4_eclosure_bin[] = { +0x01 ,0x00 ,0x00 ,0x01 ,0x08 ,0x00 ,0x00 ,0xf6 ,0x01 ,0x07 ,0x19 ,0xce , +0xc2 ,0xa8 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 ,0x6e ,0x6e ,0xd5 ,0x4d ,0x61 , +0x6e ,0x61 ,0x67 ,0x65 ,0x6d ,0x65 ,0x6e ,0x74 ,0x20 ,0x42 ,0x6f ,0x61 , +0x72 ,0x64 ,0x20 ,0x77 ,0x42 ,0x4d ,0x43 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 , +0x05 ,0xca ,0x42 ,0x52 ,0x44 ,0x2d ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 , +0xc0 ,0xc1 ,0x00 ,0x26 ,0x01 ,0x07 ,0x19 ,0xc6 ,0x57 ,0x69 ,0x77 ,0x79 , +0x6e ,0x6e ,0xcb ,0x59 ,0x6f ,0x73 ,0x65 ,0x6d ,0x69 ,0x74 ,0x65 ,0x20 , +0x56 ,0x34 ,0xc6 ,0x50 ,0x4e ,0x2d ,0x33 ,0x34 ,0x35 ,0xc4 ,0x76 ,0x31 , +0x2e ,0x31 ,0x85 ,0x91 ,0x34 ,0x51 ,0x95 ,0x05 ,0x89 ,0x30 ,0x1b ,0x8e , +0x25 ,0xfa ,0xb2 ,0x64 ,0x29 ,0x03 ,0xc0 ,0xc1 ,0x00 ,0x00 ,0x00 ,0x59 +}; +static const size_t fru_yv4_eclosure_bin_len =sizeof (fru_yv4_eclosure_bin); + +/* END OF EEPROM CONTENTS */ + +static void fby4_i2c_init_fanboard (I2CSlave *fan_mux,size_t eepromSize) +{ +/* 2 fan boards */ +for (int i =0 ; i <=1 ; i++) { +/* downstream bus */ +I2CBus *bus =pca954x_i2c_get_bus (fan_mux, i); + +/* ti,adc128d818 @ 0x1f (adc) */ +/* TODO */ + +/* maxim,max31790 @ 0x20 (pwm) */ +/* TODO */ + +/* +* ti,tca6424 @ 0x22 (gpio) +* linux handles tca6424 with PCA953X_TYPE, same as pca9535 +* { "pca9535", 16 | PCA953X_TYPE | PCA_INT, }, +* { "tca6424", 24 | PCA953X_TYPE | PCA_INT, }, +* so we _could_ be fine here unless more than 16 gpios are used +*/ +i2c_slave_create_simple (bus,TYPE_PCA9535 ,0x22 ); + +/* +* NOTE: above works and could use for gpio presence: +* $ gpioget gpiochip2 2 +* 1 +*/ + +/* maxim,max31790 @ 0x2f (pwm) */ +/* TODO */ + +/* maxim,max11615 @ 0x33 (adc) */ +/* TODO */ + +at24c_eeprom_init_rom ( + bus,0x52 , eepromSize, + fru_yv4_fanboard_bin, + fru_yv4_fanboard_bin_len); + +/* LED blink driver / gpio expander */ +/* nxp,pca9552 @ 0x61 (gpio) */ +i2c_slave_create_simple (bus,TYPE_PCA9552 ,0x61 ); + } +} + +static void fby4_i2c_init_blade_chassis (I2CBus *bus,size_t eepromSize) +{ +/* Sentinel Dome Blade EEPROMS */ + +/* Board */ +at24c_eeprom_init_rom (bus,0x54 , eepromSize, + fru_yv4_sentineldome_board_bin, fru_yv4_sentineldome_board_bin_len); + +/* Chassis */ + at24c_eeprom_init_rom(bus, 0x55, eepromSize,
hw/arm/aspeed_ast2600_fby4.c line 220
Quoted 10 lines
hw/arm/aspeed_ast2600_fby4.c new file +10
-0+ fru_yv4_sentineldome_chassis_bin, fru_yv4_sentineldome_chassis_bin_len); +} + +static void fby4_i2c_init_multiple_blade_chassis (I2CBus **i2c, +size_t eepromSize) +{ +/* there is 8 blade chassis, but we only emulate 2 for performance reason */ +for (int bus =1 ; bus <= (8 /4 ); bus++) { +fby4_i2c_init_blade_chassis (i2c[bus], eepromSize); + }
I don't think this routine has much value. I would keep the comment and simply add :
fby4_i2c_init_blade_chassis(i2c[1], eepromSize);
fby4_i2c_init_blade_chassis(i2c[2], eepromSize);in fby4_i2c_init()
Quoted 59 lines
hw/arm/aspeed_ast2600_fby4.c new file +47
-0+} + +static void fby4_i2c_init (AspeedMachineState *bmc) +{ +AspeedSoCState *soc = bmc->soc; +I2CBus *i2c[16 ]; + +for (int i =0 ; i <16 ; i++) { + i2c[i] =aspeed_i2c_get_bus (&soc->i2c, i); + } + +/* Enclosure (EM Config: yosemite4_chassis.json, yosemite4.json) */ +at24c_eeprom_init_rom (i2c[1 ],0x51 ,128 * KiB, + fru_yv4_eclosure_bin, fru_yv4_eclosure_bin_len); + +fby4_i2c_init_multiple_blade_chassis (i2c,128 * KiB); + +/* Yv4 fanboard connection */ +I2CSlave *fan_mux =i2c_slave_create_simple (i2c[14 ],TYPE_PCA9546 ,0x74 ); + +fby4_i2c_init_fanboard (fan_mux,128 * KiB); +} + +static void aspeed_machine_fby4_class_init (ObjectClass *oc,const void *data) +{ +MachineClass *mc =MACHINE_CLASS (oc); +AspeedMachineClass *amc =ASPEED_MACHINE_CLASS (oc); + + mc->desc ="Facebook fby4 BMC (Cortex-A7)" ; + amc->fmc_model ="mx66l1g45g" ; + amc->num_cs =2 ; + amc->macs_mask =ASPEED_MAC3_ON ; + amc->i2c_init = fby4_i2c_init; + mc->default_ram_size =FBY4_BMC_RAM_SIZE ; +aspeed_machine_class_init_cpus_defaults (mc); +} + +static const TypeInfo aspeed_ast2600_fby4_types[] = { + { + .name =MACHINE_TYPE_NAME ("fby4-bmc" ), + .parent =MACHINE_TYPE_NAME ("ast2600-evb" ), + .class_init = aspeed_machine_fby4_class_init, + .interfaces = arm_machine_interfaces, + } +}; + +DEFINE_TYPES (aspeed_ast2600_fby4_types)hw/arm/meson.build +1
-0@@ -59,6 +59,7 @@ arm_ss.add(when: 'CONFIG_ASPEED_SOC', if_true: files( 'aspeed_ast2600_catalina.c', 'aspeed_ast2600_evb.c', 'aspeed_ast2600_fby35.c', + 'aspeed_ast2600_fby4.c', 'aspeed_ast2600_fuji.c', 'aspeed_ast2600_gb200nvl.c', 'aspeed_ast2600_rainier.c',
PATCH v5 2/5 ast2600: yosemite4 functional test
In reply to Alexander HansenAdd a functional test for the Yosemite V4 (fby4-bmc) machine that validates:
- U-Boot initialization and kernel boot sequence
The test uses an OpenBMC image built for the yosemite4 board and validates console output through the boot process.
--- tests/functional/arm/meson.build | 2 ++ tests/functional/arm/test_aspeed_fby4.py | 45 ++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 tests/functional/arm/test_aspeed_fby4.py
tests/functional/arm/meson.build +2 -0
@@ -15,6 +15,7 @@ test_arm_timeouts = { 'aspeed_anacapa' : 480, 'aspeed_bletchley' : 480, 'aspeed_catalina' : 480, + 'aspeed_fby4': 480, 'aspeed_gb200nvl_bmc' : 480, 'aspeed_rainier' : 480, 'bpim2u' : 500,
@@ -50,6 +51,7 @@ tests_arm_system_thorough = [ 'aspeed_anacapa', 'aspeed_bletchley', 'aspeed_catalina', + 'aspeed_fby4', 'aspeed_gb200nvl_bmc', 'aspeed_rainier', 'bpim2u',
tests/functional/arm/test_aspeed_fby4.py new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
2.54.0
PATCH v5 3/5 hw/sensor: MAX31790 support
In reply to Alexander HansenProduct: [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.
The reason for adding this device is to support Yosemite V4 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
--- MAINTAINERS | 1 + hw/arm/aspeed_ast2600_fby4.c | 4 +- hw/sensor/max31790.c | 537 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 11 + tests/functional/arm/test_aspeed_fby4.py | 26 ++ 8 files changed, 583 insertions(+), 2 deletions(-) create mode 100644 hw/sensor/max31790.c
MAINTAINERS +1 -0
@@ -3987,6 +3987,7 @@ S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c +F: hw/sensor/max31790.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h F: include/hw/sensor/isl_pmbus_vr.h
hw/arm/aspeed_ast2600_fby4.c +2 -2
@@ -164,7 +164,7 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)/* TODO */ /* maxim,max31790 @ 0x20 (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x20 );/* * ti,tca6424 @ 0x22 (gpio)
@@ -182,7 +182,7 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)*/ /* maxim,max31790 @ 0x2f (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x2f );/* maxim,max11615 @ 0x33 (adc) */ /* TODO */
hw/sensor/max31790.c new file +537 -0
537 lines not on this page · raw message
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 I2C
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 +11 -0
@@ -4,3 +4,14 @@ 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" +max31790_rpm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +max31790_tach_count_reg(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +
tests/functional/arm/test_aspeed_fby4.py +26 -0
@@ -8,6 +8,8 @@ from qemu_test import wait_for_console_pattern from aspeed import AspeedTest +from qemu_test import wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_pattern class YosemiteV4Machine(AspeedTest):
@@ -34,6 +36,30 @@ def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, # different from the other machines. self.wait_for_console_pattern('yosemite4 login:') + # perform login + exec_command_and_wait_for_pattern(self, + "root", "Password:"); + + exec_command_and_wait_for_pattern(self, "0penBmc", "#"); + + # MAX31790 test + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/name", "max31790"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "7447"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_enable", "1"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_fault", "0"); + exec_command_and_wait_for_pattern(self, + "echo 1 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "140"); + exec_command_and_wait_for_pattern(self, + "echo 255 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "10685"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
Signature · 1 line
2.54.0
Re: [PATCH v5 3/5] hw/sensor: MAX31790 support
Quoted 370 lines · Alexander Hansen
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 registersThere 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 layoutAnyone could expand it in the future for more accurate emulation.
The reason for adding this device is to support Yosemite V4 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 max31790Trace output:
max31790_realizei2c_addr:0x20max31790_realizei2c_addr:0x2fmax31790_realizei2c_addr:0x20max31790_realizei2c_addr:0x2fmax31790_eventi2c_addr:0x20, event:0x01max31790_sendi2c_addr:0x20, data:0x02max31790_eventi2c_addr:0x20, event:0x00max31790_recvi2c_addr:0x20,reg_addr:0x02max31790_recv_returni2c_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 Titus Rwantare <[email protected]>Cc "Cédric Le Goater" <[email protected]> (maintainer:ASPEED BMCs)Cc Jonathan Cameron <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]>Signed-off-by Alexander Hansen <[email protected]>--- MAINTAINERS | 1 + hw/arm/aspeed_ast2600_fby4.c | 4 +- hw/sensor/max31790.c | 537 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 11 + tests/functional/arm/test_aspeed_fby4.py | 26 ++ 8 files changed, 583 insertions(+), 2 deletions(-)create mode 100644
hw/sensor/max31790.cMAINTAINERS +1
-0@@ -3987,6 +3987,7 @@ S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c +F: hw/sensor/max31790.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h F: include/hw/sensor/isl_pmbus_vr.hhw/arm/aspeed_ast2600_fby4.c +2
-2@@ -164,7 +164,7 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)/* TODO */ /* maxim,max31790 @ 0x20 (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x20 );/* * ti,tca6424 @ 0x22 (gpio) @@ -182,7 +182,7 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)*/ /* maxim,max31790 @ 0x2f (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x2f );/* maxim,max11615 @ 0x33 (adc) */ /* TODO */ hw/sensor/max31790.c new file +245
-0@@ -0,0 +1,537 @@ +/* +* Maxim MAX31790 PMBus 6-Channel Fan Controller +* +* Datasheet: +* https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31790.pdf +* +* Copyright 2026 9elements +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/i2c/i2c.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "migration/vmstate.h" +#include "qemu/module.h" +#include "qom/object.h" +#include "trace.h" + +#define TYPE_MAX31790 "max31790" + +#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) + +/* 0x08 to 0x0d: N = 0 .. 5 */ +#define MAX31790_REG_FAN_DYNAMICS (N ) (0x08 + N) + +#define MAX31790_REG_FAN_FAULT_STATUS_2 0x10 +#define MAX31790_REG_FAN_FAULT_STATUS_1 0x11 +#define MAX31790_REG_FAN_FAULT_MASK_2 0x12 +#define MAX31790_REG_FAN_FAULT_MASK_1 0x13 +#define MAX31790_REG_FAILED_FAN_OPT 0x14 + +/* 0x18 to 0x2f: N = 0 .. 11 */ +#define MAX31790_REG_TACH_COUNT_MSB (N ) (0x18 + 2 * N) +#define MAX31790_REG_TACH_COUNT_LSB (N ) (0x19 + 2 * N) + +/* 0x30 to 0x3b: N = 0 .. 5 */ +#define MAX31790_REG_PWM_DUTY_CYCLE_MSB (N ) (0x30 + 2 * N) +#define MAX31790_REG_PWM_DUTY_CYCLE_LSB (N ) (0x31 + 2 * N) + +/* .. reserved registers ... */ + +/* 0x40 to 0x4b: N = 0 .. 5 */ +#define MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (N ) (0x40 + 2 * N) +#define MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (N ) (0x41 + 2 * N) + +/* ... 'User Byte' registers ... */ + +/* 0x50 to 0x5b: N = 0 .. 5 */ +#define MAX31790_REG_TACH_TARGET_COUNT_MSB (N ) (0x50 + 2 * N) +#define MAX31790_REG_TACH_TARGET_COUNT_LSB (N ) (0x51 + 2 * N) + +struct MAX31790State { +I2CSlave i2c; + +uint8_t fan_config[MAX31790_NUM_FANS ]; +uint8_t fan_dynamics[MAX31790_NUM_FANS ]; + +uint16_t pwm[MAX31790_NUM_FANS ]; +uint16_t tach_target[MAX31790_NUM_FANS ]; + +/* +* Fan speed is measured by counting the number of internal 8192Hz +* (fTOSC/4) clock cycles that take place during a select- +* able number of tachometer periods. The number of clock +* cycles counted (11-bit value) is stored in the associated +* TACH Count registers and the desired number of cycles +* is stored in the TACH Target Count registers. +*/ +uint16_t tach_count[MAX31790_NUM_TACHS ]; + +/* command buffer */ +uint8_t len; +uint8_t buf[2 ]; + +/* output buffer */ +uint8_t outlen; +uint8_t outbuf[2 ]; + +/* selected register for read/write operation */ +uint8_t pointer; +}; + +struct MAX31790Class { +I2CSlaveClass parent_class; +}; + +OBJECT_DECLARE_TYPE(MAX31790State, MAX31790Class, MAX31790) + +static void max31790_read (MAX31790State *s) +{ +size_t index =0 ; +uint8_t out0 =0 ; +uint8_t out1 =0 ; + +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 ): + out0 = s->fan_config[s->pointer -MAX31790_REG_FAN_CONFIG (0 )]; +break ; +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ): +case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): + out0 = s->fan_dynamics[s->pointer -MAX31790_REG_FAN_DYNAMICS (0 )]; +break ; +case MAX31790_REG_FAN_FAULT_STATUS_1 : +case MAX31790_REG_FAN_FAULT_STATUS_2 : +/* we do not have any fan fault */ + out0 =0x00 ; + out1 =0x00 ; +break ; +case MAX31790_REG_TACH_COUNT_MSB (0 ): +case MAX31790_REG_TACH_COUNT_MSB (1 ): +case MAX31790_REG_TACH_COUNT_MSB (2 ): +case MAX31790_REG_TACH_COUNT_MSB (3 ): +case MAX31790_REG_TACH_COUNT_MSB (4 ): +case MAX31790_REG_TACH_COUNT_MSB (5 ): +case MAX31790_REG_TACH_COUNT_MSB (6 ): +case MAX31790_REG_TACH_COUNT_MSB (7 ): +case MAX31790_REG_TACH_COUNT_MSB (8 ): +case MAX31790_REG_TACH_COUNT_MSB (9 ): +case MAX31790_REG_TACH_COUNT_MSB (10 ): +case MAX31790_REG_TACH_COUNT_MSB (11 ): + index = (s->pointer -MAX31790_REG_TACH_COUNT_MSB (0 )) /2 ; + out0 = (s->tach_count[index] >>8 ) &0xff ; + out1 = s->tach_count[index] &0xff ; +break ; + +case MAX31790_REG_TACH_COUNT_LSB (0 ): +case MAX31790_REG_TACH_COUNT_LSB (1 ): +case MAX31790_REG_TACH_COUNT_LSB (2 ): +case MAX31790_REG_TACH_COUNT_LSB (3 ): +case MAX31790_REG_TACH_COUNT_LSB (4 ): +case MAX31790_REG_TACH_COUNT_LSB (5 ): +case MAX31790_REG_TACH_COUNT_LSB (6 ): +case MAX31790_REG_TACH_COUNT_LSB (7 ): +case MAX31790_REG_TACH_COUNT_LSB (8 ): +case MAX31790_REG_TACH_COUNT_LSB (9 ): +case MAX31790_REG_TACH_COUNT_LSB (10 ): +case MAX31790_REG_TACH_COUNT_LSB (11 ): + index = (s->pointer -MAX31790_REG_TACH_COUNT_LSB (0 )) /2 ; + out0 = s->tach_count[index] &0xff ; +break ; + +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_DUTY_CYCLE_MSB (0 )) /2 ; + out0 = (s->pwm[index] >>8 ) &0xff ; + out1 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_DUTY_CYCLE_LSB (0 )) /2 ; + out0 = s->pwm[index] &0xff ; +break ; + +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 )) /2 ; + out0 = (s->pwm[index] >>8 ) &0xff ; + out1 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 )) /2 ; + out0 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer -MAX31790_REG_TACH_TARGET_COUNT_MSB (0 )) /2 ; + out0 = (s->tach_target[index] >>8 ) &0xff ; + out1 = s->tach_target[index] &0xff ; +break ; +case MAX31790_REG_TACH_TARGET_COUNT_LSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (5 ): + index = (s->pointer -MAX31790_REG_TACH_TARGET_COUNT_LSB (0 )) /2 ; + out0 = s->tach_target[index] &0xff ; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: read of register %d\n" , __func__, + s->pointer); +break ; + } + + s->outbuf[0 ] = out0; + s->outbuf[1 ] = out1; +} + +static uint8_t max31790_get_speed_range (MAX31790State *s,size_t index) +{ +const uint16_t value = (s->fan_dynamics[index] >>5 ); +return (value >5 ) ?32 :1 << value; +} + +static void max31790_set_rpm (MAX31790State *s,size_t index,uint16_t rpm) +{ +trace_max31790_rpm_write (s->i2c.address, index, rpm); + +/* +* (see page 11) NP = number of tachometer pulses per revolution. +* Most general-purpose brushless DC fans produce two tachometer +* pulses per revolution. +*/ +const uint64_t sr =max31790_get_speed_range (s, index); +
hw/sensor/max31790.c line 255
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+/* page 11: tach_count = 60 * SR * 8192 / (NP * RPM) */ + +/* prevent division by 0 */ + rpm = (rpm ==0 ) ?1 : rpm; + +/* simplified, assuming NP = 2 */ +uint64_t tach_count = (245760ULL * sr) / (uint64_t )rpm; + +/* datasheet: lowest 5 bits are 0 */ + s->tach_count[index] = tach_count <<5 ;
Hmm, this is assigning a uint16_t from a uint64_t. There could be issues.
Quoted 226 lines
hw/sensor/max31790.c new file +226
-0+ +trace_max31790_tach_count_reg (s->i2c.address, index, s->tach_count[index]); +} + +static void max31790_pwm_write (MAX31790State *s,size_t index,uint16_t value) +{ +trace_max31790_pwm_write (s->i2c.address, index, value); + + s->pwm[index] = value; + +/* last 7 bits in register are 0 , 9 bits remaining */ +const uint16_t pwm_real = s->pwm[index] >>7 ; + +/* maximum value will be 511 */ + +/* +* This formula has magic values which model the relationship +* of PWM input to a fan. Not derived from datasheet. +*/ +max31790_set_rpm (s, index,100 + pwm_real *20 ); +} + +static void max31790_write_2_byte (MAX31790State *s) +{ +size_t index =0 ; +const uint8_t value0 = s->buf[0 ]; +const uint8_t value1 = s->buf[1 ]; + +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 ): +break ;/* handled by one byte write */ +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ): +case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): +break ;/* handled by one byte write */ +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 )) /2 ; +max31790_pwm_write (s, index, value0 <<8 | value1); +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer -MAX31790_REG_TACH_TARGET_COUNT_MSB (0 )) /2 ; + s->tach_target[index] = (value0 <<8 ) | value1; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: write to register %d\n" , __func__, + s->pointer); +break ; + } +} + +static void max31790_write_1_byte (MAX31790State *s) +{ +size_t index =0 ; +uint16_t pwm =0 ; +const uint8_t value = s->buf[0 ]; + +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 ): + s->fan_config[s->pointer -MAX31790_REG_FAN_CONFIG (0 )] = value; +break ; +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ): +case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): + s->fan_dynamics[s->pointer -MAX31790_REG_FAN_DYNAMICS (0 )] = value; +break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 )) /2 ; + pwm = (value <<8 ) | (s->pwm[index] &0x00ff ); +max31790_pwm_write (s, index, pwm); +break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 )) /2 ; + pwm = (s->pwm[index] &0xff00 ) | (value &0x00ff ); +max31790_pwm_write (s, index, pwm); +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer -MAX31790_REG_TACH_TARGET_COUNT_MSB (0 )) /2 ; + s->tach_target[index] = (s->tach_target[index] &0x00ff ) | (value <<8 ); +break ; +case MAX31790_REG_TACH_TARGET_COUNT_LSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (5 ): + index = (s->pointer -MAX31790_REG_TACH_TARGET_COUNT_LSB (0 )) /2 ; + s->tach_target[index] = (s->tach_target[index] &0xff00 ) | value; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: write to register %d\n" , __func__, + s->pointer); +break ; + } +} + +static int max31790_send (I2CSlave *i2c,uint8_t data) +{ +MAX31790State *s =MAX31790 (i2c); + +trace_max31790_send (s->i2c.address, data); + +if (s->len ==0 ) { +/* first byte is the register pointer for a read / write operation */ + s->pointer = data; + s->len++; +return 0 ; + } + +if (s->len >2 ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: write too many bytes\n" , __func__); +return 1 ;/* NAK */ + } + +/* second / third byte is the data to write */ + s->buf[s->len -1 ] = data; + s->len++; + +if (s->len ==2 ) { +max31790_write_1_byte (s); + }else if (s->len ==3 ) { +max31790_write_2_byte (s); + } + +return 0 ; +} + +static uint8_t max31790_recv (I2CSlave *i2c) +{ +MAX31790State *s =MAX31790 (i2c); +trace_max31790_recv (s->i2c.address, s->pointer); + +max31790_read (s); + s->len =0 ; + +if (s->outlen >=2 ) { +/* error */ +qemu_log_mask (LOG_GUEST_ERROR ,"%s: guest over read\n" , __func__); + s->outlen =0 ; + } + +const uint8_t data = s->outbuf[s->outlen++]; + +trace_max31790_recv_return (s->i2c.address, data); +return data; +} + +static int max31790_event (I2CSlave *i2c,enum i2c_event event) +{ +MAX31790State *s =MAX31790 (i2c); + +trace_max31790_event (s->i2c.address, event); + +switch (event) { +case I2C_START_RECV : + s->outlen =0 ; +break ; +case I2C_START_SEND : + s->len =0 ; +break ; +default : +break ; + } + +return 0 ; +} + +static const VMStateDescription vmstate_max31790 = { + .name =TYPE_MAX31790 , + .version_id =0 , + .minimum_version_id =0 , + .fields = + (const VMStateField []){ +VMSTATE_UINT8 (len, MAX31790State), +VMSTATE_UINT8_ARRAY (fan_config, MAX31790State,MAX31790_NUM_FANS ), +VMSTATE_UINT8_ARRAY (fan_dynamics, MAX31790State,MAX31790_NUM_FANS ), +VMSTATE_UINT16_ARRAY (pwm, MAX31790State,MAX31790_NUM_FANS ), +VMSTATE_UINT16_ARRAY (tach_target, MAX31790State,MAX31790_NUM_FANS ), +VMSTATE_UINT16_ARRAY (tach_count, MAX31790State,MAX31790_NUM_TACHS ), +VMSTATE_UINT8_ARRAY (buf, MAX31790State,2 ), +VMSTATE_UINT8 (outlen, MAX31790State), +VMSTATE_UINT8_ARRAY (outbuf, MAX31790State,2 ), +VMSTATE_UINT8 (pointer, MAX31790State), +VMSTATE_I2C_SLAVE (i2c, MAX31790State),VMSTATE_END_OF_LIST () } +}; +
hw/sensor/max31790.c line 491
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+static void max31790_reset (DeviceState *dev) +{ +MAX31790State *s =MAX31790 (dev); + +for (int i =0 ; i <MAX31790_NUM_FANS ; i++) { +/* POR-State 0b 0XX0 0000 */ + s->fan_config[i] =0b00000000 ; + +/* same as POR-State */ + s->tach_target[i] =0b0011110000000000 ;
tach_target[] array size is MAX31790_NUM_TACHS = 12. The loop uses MAX31790_NUM_FANS = 6
hw/sensor/max31790.c line 498
Quoted 7 lines
hw/sensor/max31790.c new file +7
-0+ +/* same as POR-State */ + s->fan_dynamics[i] =0b01001100 ; + } + +/* this will set both pwm and tach count */ +for (int i =0 ; i <MAX31790_NUM_TACHS ; i++) {
pwm[] array size is MAX31790_NUM_FANS = 6. The loop uses MAX31790_NUM_TACHS = 12. this is an out-of-bounds write.
hw/sensor/max31790.c line 499
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+max31790_pwm_write (s, i,0x4444 );
How does the 0x4444 value relates to the one used in the tests ?
Quoted 95 lines
hw/sensor/max31790.c new file +38
-0+ } +} + +static void max31790_realize (DeviceState *dev,Error **errp) +{ +MAX31790State *s =MAX31790 (dev); + +trace_max31790_realize (s->i2c.address); +} + +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; + k->event = max31790_event; + k->recv = max31790_recv; + k->send = max31790_send; +} + +static const TypeInfo max31790_info = { + .name =TYPE_MAX31790 , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (MAX31790State), + .class_size =sizeof (MAX31790Class), + .class_init = max31790_class_init, +}; + +static void max31790_register_types (void ) +{ +type_register_static (&max31790_info); +} + +type_init (max31790_register_types)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_EXPRESShw/sensor/Kconfig +4
-0@@ -43,3 +43,7 @@ config ISL_PMBUS_VR config MAX31785 bool depends on PMBUS + +config MAX31790 + bool + depends on I2Chw/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 +11
-0@@ -4,3 +4,14 @@ 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" +max31790_rpm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +max31790_tach_count_reg(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +tests/functional/arm/test_aspeed_fby4.py +0
-0
tests/functional/arm/test_aspeed_fby4.py line 10
Quoted 3 lines
tests/functional/arm/test_aspeed_fby4.py +0
-0@@ -8,6 +8,8 @@ from qemu_test import wait_for_console_pattern from aspeed import AspeedTest
Drop the extra newline
tests/functional/arm/test_aspeed_fby4.py line 12
Quoted 2 lines
tests/functional/arm/test_aspeed_fby4.py +2
-0+from qemu_test import wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_pattern
redundant import.
Quoted 34 lines
tests/functional/arm/test_aspeed_fby4.py +24
-0class YosemiteV4Machine(AspeedTest):@@ -34,6 +36,30 @@ def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, # different from the other machines. self.wait_for_console_pattern('yosemite4 login:') + # perform login + exec_command_and_wait_for_pattern(self, + "root", "Password:"); + + exec_command_and_wait_for_pattern(self, "0penBmc", "#"); + + # MAX31790 test + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/name", "max31790"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "7447"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_enable", "1"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_fault", "0"); + exec_command_and_wait_for_pattern(self, + "echo 1 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "140"); + exec_command_and_wait_for_pattern(self, + "echo 255 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "10685"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
Re: [PATCH v5 3/5] hw/sensor: MAX31790 support
Hi Cedric,
Quoted 1 line
How does the
0x4444value relates to the one used in the tests ?
There is something in the image which is writing the pwm, if you look at the traces
it should be more obvious in the next patchset (v6, not yet sent)
max31790_pwm_write i2c_addr: 0x2f, index: 5, value: 0xb200 max31790_rpm_write i2c_addr: 0x2f, index: 5, value: 0x1c34 max31790_tach_count_reg i2c_addr: 0x2f, index: 5, value: 0x0440 max31790_send i2c_addr: 0x2f, data: 0x80 max31790_pwm_write i2c_addr: 0x2f, index: 5, value: 0xb280 max31790_rpm_write i2c_addr: 0x2f, index: 5, value: 0x1c48 max31790_tach_count_reg i2c_addr: 0x2f, index: 5, value: 0x0420
Looking then at the latest fan dynamics read from the driver
max31790_fan_dynamics_read i2c_addr: 0x20, channel: 0, value: 0x0000 max31790_recv_return i2c_addr: 0x20, reg_addr: 0x08, returns: 0x00
and plugging that into the equation
Quoted 1 line
Quoted 1 line
Quoted 1 line
(60 * 1 * 8192) / (
0x0420>> 4)
7447.272727272727
we get the value found in the test. The fan dynamics are wrong because the reset was not being called.
Should be fixed in the next patchset. The newly added traces should make things clearer and the functional test will also have a comment going through an example calculation.
Am Mo., 1. Juni 2026 um 11:17 Uhr schrieb Cédric Le Goater <[email protected]>:
Quoted 831 lines · Alexander Hansen
Quoted 22 lines
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 registersThere 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 layoutQuoted 8 lines
Anyone could expand it in the future for more accurate emulation.
The reason for adding this device is to support Yosemite V4 emulation.
Tested: on yosemite 4 qemu
root@yosemite4:~# ls /sys/class/hwmon/hwmon2/ device fan2_fault fan3_target fan5_fault fan6_targetpwm2 pwm5
Quoted 1 line
fan1_enablefan2_inputfan4_enablefan5_inputname
pwm2_enablepwm5_enableQuoted 1 line
fan1_faultfan2_targetfan4_faultfan5_targetof_nodepwm3pwm6
Quoted 1 line
fan1_inputfan3_enablefan4_inputfan6_enablepower
pwm3_enablepwm6_enableQuoted 1 line
fan1_targetfan3_faultfan4_targetfan6_faultpwm1 pwm4subsystem
Quoted 1 line
fan2_enablefan3_inputfan5_enablefan6_inputpwm1_enable
pwm4_enableueventQuoted 25 lines
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 max31790Trace output:
max31790_realizei2c_addr:0x20max31790_realizei2c_addr:0x2fmax31790_realizei2c_addr:0x20max31790_realizei2c_addr:0x2fmax31790_eventi2c_addr:0x20, event:0x01max31790_sendi2c_addr:0x20, data:0x02max31790_eventi2c_addr:0x20, event:0x00max31790_recvi2c_addr:0x20,reg_addr:0x02max31790_recv_returni2c_addr:0x20, returns:0x08
...Quoted 3 lines
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/aspeed_ast2600_fby4.c static void fby4_i2c_init_fanboard(I2CSlave
Quoted 39 lines
Cc Titus Rwantare <[email protected]>Cc "Cédric Le Goater" <[email protected]> (maintainer:ASPEED BMCs)Cc Jonathan Cameron <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Peter Maydell <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]>Signed-off-by Alexander Hansen <[email protected]>--- MAINTAINERS | 1 + hw/arm/aspeed_ast2600_fby4.c | 4 +- hw/sensor/max31790.c | 537 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 11 + tests/functional/arm/test_aspeed_fby4.py | 26 ++ 8 files changed, 583 insertions(+), 2 deletions(-)create mode 100644
hw/sensor/max31790.cMAINTAINERS +1
-0@@ -3987,6 +3987,7 @@ S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c +F: hw/sensor/max31790.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h F: include/hw/sensor/isl_pmbus_vr.hhw/arm/aspeed_ast2600_fby4.c +0
-0@@ -164,7 +164,7 @@ static void fby4_i2c_init_fanboard(I2CSlave
*fan_mux,size_teepromSize)hw/arm/aspeed_ast2600_fby4.c static void fby4_i2c_init_fanboard(I2CSlave
Quoted 9 lines
hw/arm/aspeed_ast2600_fby4.c +1
-1/* TODO */ /* maxim,max31790 @ 0x20 (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x20 );/* * ti,tca6424 @ 0x22 (gpio) @@ -182,7 +182,7 @@ static void fby4_i2c_init_fanboard(I2CSlave
*fan_mux,size_teepromSize)Quoted 14 lines
hw/arm/aspeed_ast2600_fby4.c +1
-1*/ /* maxim,max31790 @ 0x2f (pwm) */ -/* TODO */ +i2c_slave_create_simple (bus,"max31790" ,0x2f );/* maxim,max11615 @ 0x33 (adc) */ /* TODO */ hw/sensor/max31790.c new file +0
-0hw/sensor/max31790.c line 5
Quoted 5 lines
hw/sensor/max31790.c new file +5
-0@@ -0,0 +1,537 @@ +/* +* Maxim MAX31790 PMBus 6-Channel Fan Controller +* +* Datasheet: +* https://www.analog.com/media/en/technical-documentation/data-sheets/MAX31790.pdf
Quoted 105 lines
hw/sensor/max31790.c new file +105
-0+* +* Copyright 2026 9elements +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "hw/i2c/i2c.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "migration/vmstate.h" +#include "qemu/module.h" +#include "qom/object.h" +#include "trace.h" + +#define TYPE_MAX31790 "max31790" + +#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) + +/* 0x08 to 0x0d: N = 0 .. 5 */ +#define MAX31790_REG_FAN_DYNAMICS (N ) (0x08 + N) + +#define MAX31790_REG_FAN_FAULT_STATUS_2 0x10 +#define MAX31790_REG_FAN_FAULT_STATUS_1 0x11 +#define MAX31790_REG_FAN_FAULT_MASK_2 0x12 +#define MAX31790_REG_FAN_FAULT_MASK_1 0x13 +#define MAX31790_REG_FAILED_FAN_OPT 0x14 + +/* 0x18 to 0x2f: N = 0 .. 11 */ +#define MAX31790_REG_TACH_COUNT_MSB (N ) (0x18 + 2 * N) +#define MAX31790_REG_TACH_COUNT_LSB (N ) (0x19 + 2 * N) + +/* 0x30 to 0x3b: N = 0 .. 5 */ +#define MAX31790_REG_PWM_DUTY_CYCLE_MSB (N ) (0x30 + 2 * N) +#define MAX31790_REG_PWM_DUTY_CYCLE_LSB (N ) (0x31 + 2 * N) + +/* .. reserved registers ... */ + +/* 0x40 to 0x4b: N = 0 .. 5 */ +#define MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (N ) (0x40 + 2 * N) +#define MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (N ) (0x41 + 2 * N) + +/* ... 'User Byte' registers ... */ + +/* 0x50 to 0x5b: N = 0 .. 5 */ +#define MAX31790_REG_TACH_TARGET_COUNT_MSB (N ) (0x50 + 2 * N) +#define MAX31790_REG_TACH_TARGET_COUNT_LSB (N ) (0x51 + 2 * N) + +struct MAX31790State { +I2CSlave i2c; + +uint8_t fan_config[MAX31790_NUM_FANS ]; +uint8_t fan_dynamics[MAX31790_NUM_FANS ]; + +uint16_t pwm[MAX31790_NUM_FANS ]; +uint16_t tach_target[MAX31790_NUM_FANS ]; + +/* +* Fan speed is measured by counting the number of internal 8192Hz +* (fTOSC/4) clock cycles that take place during a select- +* able number of tachometer periods. The number of clock +* cycles counted (11-bit value) is stored in the associated +* TACH Count registers and the desired number of cycles +* is stored in the TACH Target Count registers. +*/ +uint16_t tach_count[MAX31790_NUM_TACHS ]; + +/* command buffer */ +uint8_t len; +uint8_t buf[2 ]; + +/* output buffer */ +uint8_t outlen; +uint8_t outbuf[2 ]; + +/* selected register for read/write operation */ +uint8_t pointer; +}; + +struct MAX31790Class { +I2CSlaveClass parent_class; +}; + +OBJECT_DECLARE_TYPE(MAX31790State, MAX31790Class, MAX31790) + +static void max31790_read (MAX31790State *s) +{ +size_t index =0 ; +uint8_t out0 =0 ; +uint8_t out1 =0 ; + +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 ):hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+case MAX31790_REG_FAN_CONFIG (5 ): + out0 = s->fan_config[s->pointer -MAX31790_REG_FAN_CONFIG (0 )]; +break ; +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ): +case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): + out0 = s->fan_dynamics[s->pointer -
MAX31790_REG_FAN_DYNAMICS(0)];Quoted 57 lines
hw/sensor/max31790.c new file +57
-0+break ; +case MAX31790_REG_FAN_FAULT_STATUS_1 : +case MAX31790_REG_FAN_FAULT_STATUS_2 : +/* we do not have any fan fault */ + out0 =0x00 ; + out1 =0x00 ; +break ; +case MAX31790_REG_TACH_COUNT_MSB (0 ): +case MAX31790_REG_TACH_COUNT_MSB (1 ): +case MAX31790_REG_TACH_COUNT_MSB (2 ): +case MAX31790_REG_TACH_COUNT_MSB (3 ): +case MAX31790_REG_TACH_COUNT_MSB (4 ): +case MAX31790_REG_TACH_COUNT_MSB (5 ): +case MAX31790_REG_TACH_COUNT_MSB (6 ): +case MAX31790_REG_TACH_COUNT_MSB (7 ): +case MAX31790_REG_TACH_COUNT_MSB (8 ): +case MAX31790_REG_TACH_COUNT_MSB (9 ): +case MAX31790_REG_TACH_COUNT_MSB (10 ): +case MAX31790_REG_TACH_COUNT_MSB (11 ): + index = (s->pointer -MAX31790_REG_TACH_COUNT_MSB (0 )) /2 ; + out0 = (s->tach_count[index] >>8 ) &0xff ; + out1 = s->tach_count[index] &0xff ; +break ; + +case MAX31790_REG_TACH_COUNT_LSB (0 ): +case MAX31790_REG_TACH_COUNT_LSB (1 ): +case MAX31790_REG_TACH_COUNT_LSB (2 ): +case MAX31790_REG_TACH_COUNT_LSB (3 ): +case MAX31790_REG_TACH_COUNT_LSB (4 ): +case MAX31790_REG_TACH_COUNT_LSB (5 ): +case MAX31790_REG_TACH_COUNT_LSB (6 ): +case MAX31790_REG_TACH_COUNT_LSB (7 ): +case MAX31790_REG_TACH_COUNT_LSB (8 ): +case MAX31790_REG_TACH_COUNT_LSB (9 ): +case MAX31790_REG_TACH_COUNT_LSB (10 ): +case MAX31790_REG_TACH_COUNT_LSB (11 ): + index = (s->pointer -MAX31790_REG_TACH_COUNT_LSB (0 )) /2 ; + out0 = s->tach_count[index] &0xff ; +break ; + +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_DUTY_CYCLE_MSB (0 )) /2 ; + out0 = (s->pwm[index] >>8 ) &0xff ; + out1 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -MAX31790_REG_PWM_DUTY_CYCLE_LSB (0 )) /2 ;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ out0 = s->pwm[index] &0xff ; +break ; + +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -
MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB(0)) / 2;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ out0 = (s->pwm[index] >>8 ) &0xff ; + out1 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -
MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB(0)) / 2;hw/sensor/max31790.c
Quoted 9 lines
hw/sensor/max31790.c new file +9
-0+ out0 = s->pwm[index] &0xff ; +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer - MAX31790_REG_TACH_TARGET_COUNT_MSB(0)) /2;
hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ out0 = (s->tach_target[index] >>8 ) &0xff ; + out1 = s->tach_target[index] &0xff ; +break ; +case MAX31790_REG_TACH_TARGET_COUNT_LSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (5 ): + index = (s->pointer - MAX31790_REG_TACH_TARGET_COUNT_LSB(0)) /2;
Quoted 9 lines
hw/sensor/max31790.c new file +9
-0+ out0 = s->tach_target[index] &0xff ; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: read of register %d\n" , __func__, + s->pointer); +break ; + } + + s->outbuf[0 ] = out0;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ s->outbuf[1 ] = out1; +} + +static uint8_t max31790_get_speed_range (MAX31790State *s,size_t index) +{ +const uint16_t value = (s->fan_dynamics[index] >>5 ); +return (value >5 ) ?32 :1 << value; +} + +static void max31790_set_rpm(MAX31790State *s, size_t index, uint16_trpm)
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+{ +trace_max31790_rpm_write (s->i2c.address, index, rpm); + +/* +* (see page 11) NP = number of tachometer pulses per revolution. +* Most general-purpose brushless DC fans produce two tachometer +* pulses per revolution. +*/ +const uint64_t sr =max31790_get_speed_range (s, index); +hw/sensor/max31790.c line 255
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+/* page 11: tach_count = 60 * SR * 8192 / (NP * RPM) */ + +/* prevent division by 0 */ + rpm = (rpm ==0 ) ?1 : rpm; + +/* simplified, assuming NP = 2 */ +uint64_t tach_count = (245760ULL * sr) / (uint64_t )rpm; + +/* datasheet: lowest 5 bits are 0 */ + s->tach_count[index] = tach_count <<5 ;Hmm, this is assigning a
uint16_tfrom auint64_t. There could be issues.hw/sensor/max31790.c line 257
Quoted 2 lines
hw/sensor/max31790.c new file +2
-0+ + trace_max31790_tach_count_reg(s->i2c.address, index,s->tach_count[index]);
hw/sensor/max31790.c
Quoted 3 lines
hw/sensor/max31790.c new file +3
-0+} + +static void max31790_pwm_write(MAX31790State *s, size_t index, uint16_tvalue)
Quoted 35 lines
hw/sensor/max31790.c new file +35
-0+{ +trace_max31790_pwm_write (s->i2c.address, index, value); + + s->pwm[index] = value; + +/* last 7 bits in register are 0 , 9 bits remaining */ +const uint16_t pwm_real = s->pwm[index] >>7 ; + +/* maximum value will be 511 */ + +/* +* This formula has magic values which model the relationship +* of PWM input to a fan. Not derived from datasheet. +*/ +max31790_set_rpm (s, index,100 + pwm_real *20 ); +} + +static void max31790_write_2_byte (MAX31790State *s) +{ +size_t index =0 ; +const uint8_t value0 = s->buf[0 ]; +const uint8_t value1 = s->buf[1 ]; + +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 ): +break ;/* handled by one byte write */ +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ):hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): +break ;/* handled by one byte write */ +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -
MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB(0)) / 2;hw/sensor/max31790.c
Quoted 9 lines
hw/sensor/max31790.c new file +9
-0+max31790_pwm_write (s, index, value0 <<8 | value1); +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer - MAX31790_REG_TACH_TARGET_COUNT_MSB(0)) /2;
Quoted 21 lines
hw/sensor/max31790.c new file +21
-0+ s->tach_target[index] = (value0 <<8 ) | value1; +break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: write to register %d\n" , __func__, + s->pointer); +break ; + } +} + +static void max31790_write_1_byte (MAX31790State *s) +{ +size_t index =0 ; +uint16_t pwm =0 ; +const uint8_t value = s->buf[0 ]; + +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 ):hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+case MAX31790_REG_FAN_CONFIG (5 ): + s->fan_config[s->pointer -MAX31790_REG_FAN_CONFIG (0 )] = value; +break ; +case MAX31790_REG_FAN_DYNAMICS (0 ): +case MAX31790_REG_FAN_DYNAMICS (1 ): +case MAX31790_REG_FAN_DYNAMICS (2 ): +case MAX31790_REG_FAN_DYNAMICS (3 ): +case MAX31790_REG_FAN_DYNAMICS (4 ): +case MAX31790_REG_FAN_DYNAMICS (5 ): + s->fan_dynamics[s->pointer - MAX31790_REG_FAN_DYNAMICS(0)] =value;
hw/sensor/max31790.c
Quoted 8 lines
hw/sensor/max31790.c new file +8
-0+break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB (5 ): + index = (s->pointer -
MAX31790_REG_PWM_TARGET_DUTY_CYCLE_MSB(0)) / 2;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ pwm = (value <<8 ) | (s->pwm[index] &0x00ff ); +max31790_pwm_write (s, index, pwm); +break ; +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (0 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (1 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (2 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (3 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (4 ): +case MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB (5 ): + index = (s->pointer -
MAX31790_REG_PWM_TARGET_DUTY_CYCLE_LSB(0)) / 2;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+ pwm = (s->pwm[index] &0xff00 ) | (value &0x00ff ); +max31790_pwm_write (s, index, pwm); +break ; +case MAX31790_REG_TACH_TARGET_COUNT_MSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_MSB (5 ): + index = (s->pointer - MAX31790_REG_TACH_TARGET_COUNT_MSB(0)) /2;
hw/sensor/max31790.c line 374
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+ s->tach_target[index] = (s->tach_target[index] & 0x00ff) |(value << 8);
hw/sensor/max31790.c
Quoted 8 lines
hw/sensor/max31790.c new file +8
-0+break ; +case MAX31790_REG_TACH_TARGET_COUNT_LSB (0 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (1 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (2 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (3 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (4 ): +case MAX31790_REG_TACH_TARGET_COUNT_LSB (5 ): + index = (s->pointer - MAX31790_REG_TACH_TARGET_COUNT_LSB(0)) /2;
hw/sensor/max31790.c line 383
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+ s->tach_target[index] = (s->tach_target[index] & 0xff00) |value;
Quoted 6 lines
hw/sensor/max31790.c new file +6
-0+break ; +default : +qemu_log_mask (LOG_UNIMP ,"%s: write to register %d\n" , __func__, + s->pointer); +break ; + }hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+} + +static int max31790_send (I2CSlave *i2c,uint8_t data) +{ +MAX31790State *s =MAX31790 (i2c); + +trace_max31790_send (s->i2c.address, data); + +if (s->len ==0 ) { +/* first byte is the register pointer for a read / write operation */
hw/sensor/max31790.c
Quoted 7 lines
hw/sensor/max31790.c new file +7
-0+ s->pointer = data; + s->len++; +return 0 ; + } + +if (s->len >2 ) { + qemu_log_mask(LOG_GUEST_ERROR, "%s: write too many bytes\n",
__func__);Quoted 17 lines
hw/sensor/max31790.c new file +17
-0+return 1 ;/* NAK */ + } + +/* second / third byte is the data to write */ + s->buf[s->len -1 ] = data; + s->len++; + +if (s->len ==2 ) { +max31790_write_1_byte (s); + }else if (s->len ==3 ) { +max31790_write_2_byte (s); + } + +return 0 ; +} + +static uint8_t max31790_recv (I2CSlave *i2c)hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+{ +MAX31790State *s =MAX31790 (i2c); +trace_max31790_recv (s->i2c.address, s->pointer); + +max31790_read (s); + s->len =0 ; + +if (s->outlen >=2 ) { +/* error */ + qemu_log_mask(LOG_GUEST_ERROR, "%s: guest over read\n",
__func__);Quoted 27 lines
hw/sensor/max31790.c new file +27
-0+ s->outlen =0 ; + } + +const uint8_t data = s->outbuf[s->outlen++]; + +trace_max31790_recv_return (s->i2c.address, data); +return data; +} + +static int max31790_event (I2CSlave *i2c,enum i2c_event event) +{ +MAX31790State *s =MAX31790 (i2c); + +trace_max31790_event (s->i2c.address, event); + +switch (event) { +case I2C_START_RECV : + s->outlen =0 ; +break ; +case I2C_START_SEND : + s->len =0 ; +break ; +default : +break ; + } + +return 0 ;hw/sensor/max31790.c
Quoted 10 lines
hw/sensor/max31790.c new file +10
-0+} + +static const VMStateDescription vmstate_max31790 = { + .name =TYPE_MAX31790 , + .version_id =0 , + .minimum_version_id =0 , + .fields = + (const VMStateField []){ +VMSTATE_UINT8 (len, MAX31790State), + VMSTATE_UINT8_ARRAY(fan_config, MAX31790State,
MAX31790_NUM_FANS),hw/sensor/max31790.c line 471
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+ VMSTATE_UINT8_ARRAY(fan_dynamics, MAX31790State,
MAX31790_NUM_FANS),hw/sensor/max31790.c line 473
Quoted 2 lines
hw/sensor/max31790.c new file +2
-0+VMSTATE_UINT16_ARRAY (pwm, MAX31790State,MAX31790_NUM_FANS ), + VMSTATE_UINT16_ARRAY(tach_target, MAX31790State,
MAX31790_NUM_FANS),hw/sensor/max31790.c line 474
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+ VMSTATE_UINT16_ARRAY(tach_count, MAX31790State,
MAX31790_NUM_TACHS),hw/sensor/max31790.c
Quoted 5 lines
hw/sensor/max31790.c new file +5
-0+VMSTATE_UINT8_ARRAY (buf, MAX31790State,2 ), +VMSTATE_UINT8 (outlen, MAX31790State), +VMSTATE_UINT8_ARRAY (outbuf, MAX31790State,2 ), +VMSTATE_UINT8 (pointer, MAX31790State), + VMSTATE_I2C_SLAVE(i2c, MAX31790State),
VMSTATE_END_OF_LIST()}hw/sensor/max31790.c line 491
Quoted 12 lines
hw/sensor/max31790.c new file +12
-0+}; + +static void max31790_reset (DeviceState *dev) +{ +MAX31790State *s =MAX31790 (dev); + +for (int i =0 ; i <MAX31790_NUM_FANS ; i++) { +/* POR-State 0b 0XX0 0000 */ + s->fan_config[i] =0b00000000 ; + +/* same as POR-State */ + s->tach_target[i] =0b0011110000000000 ;tach_target[] array size is
MAX31790_NUM_TACHS= 12. The loop usesMAX31790_NUM_FANS= 6hw/sensor/max31790.c line 498
Quoted 7 lines
hw/sensor/max31790.c new file +7
-0+ +/* same as POR-State */ + s->fan_dynamics[i] =0b01001100 ; + } + +/* this will set both pwm and tach count */ +for (int i =0 ; i <MAX31790_NUM_TACHS ; i++) {pwm[] array size is
MAX31790_NUM_FANS= 6. The loop usesMAX31790_NUM_TACHS= 12. this is an out-of-bounds write.hw/sensor/max31790.c line 499
Quoted 1 line
hw/sensor/max31790.c new file +1
-0+max31790_pwm_write (s, i,0x4444 );How does the
0x4444value relates to the one used in the tests ?hw/sensor/meson.build system_ss.add(when: 'CONFIG_MAX34451', if_true:
Quoted 67 lines
hw/sensor/max31790.c new file +38
-0+ } +} + +static void max31790_realize (DeviceState *dev,Error **errp) +{ +MAX31790State *s =MAX31790 (dev); + +trace_max31790_realize (s->i2c.address); +} + +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; + k->event = max31790_event; + k->recv = max31790_recv; + k->send = max31790_send; +} + +static const TypeInfo max31790_info = { + .name =TYPE_MAX31790 , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (MAX31790State), + .class_size =sizeof (MAX31790Class), + .class_init = max31790_class_init, +}; + +static void max31790_register_types (void ) +{ +type_register_static (&max31790_info); +} + +type_init (max31790_register_types)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_EXPRESShw/sensor/Kconfig +4
-0@@ -43,3 +43,7 @@ config ISL_PMBUS_VR config MAX31785 bool depends on PMBUS + +config MAX31790 + bool + depends on I2Chw/sensor/meson.build +0
-0@@ -8,3 +8,4 @@ system_ss.add(when: 'CONFIG_MAX34451', if_true:files('max34451.c'))
hw/sensor/meson.build system_ss.add(when: 'CONFIG_MAX34451', if_true: · line 8
Quoted 1 line
hw/sensor/meson.build +0
-0system_ss.add(when: 'CONFIG_LSM303DLHC_MAG', if_true:
files('lsm303dlhc_mag.c'))hw/sensor/meson.build system_ss.add(when: 'CONFIG_MAX34451', if_true: · line 9
Quoted 1 line
hw/sensor/meson.build +0
-0system_ss.add(when: 'CONFIG_ISL_PMBUS_VR', if_true:
files('isl_pmbus_vr.c'))hw/sensor/trace-events line 9
Quoted 13 lines
hw/sensor/meson.build +1
-0system_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 +3
-0@@ -4,3 +4,14 @@ 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"
hw/sensor/trace-events line 10
Quoted 1 line
hw/sensor/trace-events +1
-0+max31790_recv(uint8_t i2c_addr, uint8_t reg_addr) "i2c_addr: 0x%02x,
reg_addr: 0x%02x"hw/sensor/trace-events line 11
Quoted 1 line
hw/sensor/trace-events +1
-0+max31790_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x,returns: 0x%02x"
hw/sensor/trace-events line 12
Quoted 1 line
hw/sensor/trace-events +1
-0+max31790_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x,event: 0x%02x"
hw/sensor/trace-events line 14
Quoted 2 lines
hw/sensor/trace-events +2
-0+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"hw/sensor/trace-events line 15
Quoted 1 line
hw/sensor/trace-events +1
-0+max31790_rpm_write(uint8_t i2c_addr, size_t index, uint16_t value)"
i2c_addr: 0x%02x, index: %zu, value: 0x%04x"hw/sensor/trace-events line 16
Quoted 1 line
hw/sensor/trace-events +1
-0+max31790_tach_count_reg(uint8_t i2c_addr, size_t index, uint16_t value)"
i2c_addr: 0x%02x, index: %zu, value: 0x%04x"Review
Quoted 2 lines
hw/sensor/trace-events +1
-0+(quoted diff) +0
-0
b/tests/functional/arm/test_aspeed_fby4.pytests/functional/arm/test_aspeed_fby4.py line 10
Quoted 7 lines
index
a521834f79..dc2437a533100755tests/functional/arm/test_aspeed_fby4.py +0
-0@@ -8,6 +8,8 @@ from qemu_test import wait_for_console_pattern from aspeed import AspeedTestDrop the extra newline
tests/functional/arm/test_aspeed_fby4.py line 12
Quoted 2 lines
tests/functional/arm/test_aspeed_fby4.py +2
-0+from qemu_test import wait_for_console_pattern +from qemu_test import exec_command_and_wait_for_patternredundant import.
tests/functional/arm/test_aspeed_fby4.py def do_test_arm_aspeed_openbmc_no_network(self,
Quoted 4 lines
tests/functional/arm/test_aspeed_fby4.py +0
-0class YosemiteV4Machine(AspeedTest):@@ -34,6 +36,30 @@ def do_test_arm_aspeed_openbmc_no_network(self,machine, image, uboot,
Quoted 14 lines
tests/functional/arm/test_aspeed_fby4.py +11
-0# different from the other machines. self.wait_for_console_pattern('yosemite4 login:') + # perform login + exec_command_and_wait_for_pattern(self, + "root", "Password:"); + + exec_command_and_wait_for_pattern(self, "0penBmc", "#"); + + # MAX31790 test + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/name", "max31790"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "7447");tests/functional/arm/test_aspeed_fby4.py def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot,
Quoted 10 lines
tests/functional/arm/test_aspeed_fby4.py +10
-0+ exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_enable", "1"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_fault", "0"); + exec_command_and_wait_for_pattern(self, + "echo 1 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4"); + exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "140"); + exec_command_and_wait_for_pattern(self, + "echo 255 > /sys/class/hwmon/hwmon2/pwm1", "root@yosemite4");
Quoted 6 lines
tests/functional/arm/test_aspeed_fby4.py +3
-0+ exec_command_and_wait_for_pattern(self, + "cat /sys/class/hwmon/hwmon2/fan1_input", "10685"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
PATCH v5 4/5 hw/sensor: support MAX11615
In reply to Alexander HansenProduct: [1]
Datasheet: [2]
Sensor readings can be provided upon creation of the device. In case no readings are provided the ADC reads a pre-defined arbitrary value.
root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/name max11615 root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/in_voltage0_raw 1922 root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/in_voltage_scale 0.500000000
trace:
less /tmp/qemu-trace.log | grep -i max116 max11615_realize i2c_addr: 0x33 max11615_realize i2c_addr: 0x33 max11615_event i2c_addr: 0x33, event: 0x01 max11615_write_setup i2c_addr: 0x33, data: 0xd2 max11615_write_config i2c_addr: 0x33, data: 0x0f max11615_event i2c_addr: 0x33, event: 0x03 max11615_event i2c_addr: 0x33, event: 0x01 max11615_write_setup i2c_addr: 0x33, data: 0xd2 max11615_write_config i2c_addr: 0x33, data: 0x0f max11615_event i2c_addr: 0x33, event: 0x03 max11615_event i2c_addr: 0x33, event: 0x01 max11615_write_setup i2c_addr: 0x33, data: 0xd2 max11615_write_config i2c_addr: 0x33, data: 0x61 max11615_event i2c_addr: 0x33, event: 0x03 max11615_event i2c_addr: 0x33, event: 0x00 max11615_recv i2c_addr: 0x33, reg_addr: 0x00 max11615_recv_return i2c_addr: 0x33, returns: 0xfa max11615_recv i2c_addr: 0x33, reg_addr: 0x00 max11615_recv_return i2c_addr: 0x33, returns: 0xd2 max11615_event i2c_addr: 0x33, event: 0x04 max11615_event i2c_addr: 0x33, event: 0x03
References:
[1] https://www.analog.com/en/products/MAX11615.html
[2] https://www.analog.com/media/en/technical-documentation/data-sheets/MAX11612-MAX11617.pdf
--- MAINTAINERS | 1 + include/hw/sensor/max11615.h | 20 ++ hw/arm/aspeed_ast2600_fby4.c | 8 +- hw/sensor/max11615.c | 312 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 8 + tests/functional/arm/test_aspeed_fby4.py | 8 + 9 files changed, 362 insertions(+), 1 deletion(-) create mode 100644 include/hw/sensor/max11615.h create mode 100644 hw/sensor/max11615.c
MAINTAINERS +1 -0
@@ -3987,6 +3987,7 @@ S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c +F: hw/sensor/max11615.c F: hw/sensor/max31790.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.h
include/hw/sensor/max11615.h new file +20 -0
@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef QEMU_MAX11615_H +#define QEMU_MAX11615_H + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" + +#define TYPE_MAX11615 "max11615" + +/* +* Create and realize a MAX11615 ADC with constant caller-supplied readings +* @bus: I2C bus to put it on +* @address: I2C address +* @init_values: array of readings for each ADC channel +* @init_values_size: Size of @init_values, can be less than the number of channels +*/ +I2CSlave *max11615_init_with_values (I2CBus *bus,uint8_t address, +const uint16_t *init_values,uint32_t init_values_size); + +#endif
hw/arm/aspeed_ast2600_fby4.c +7 -1
@@ -11,6 +11,7 @@#include "hw/arm/aspeed.h" #include "hw/arm/aspeed_soc.h" #include "hw/nvram/eeprom_at24c.h" +#include "hw/sensor/max11615.h" #include "hw/i2c/i2c_mux_pca954x.h" #include "hw/gpio/pca9552.h"
@@ -185,7 +186,12 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)i2c_slave_create_simple (bus,"max31790" ,0x2f );/* maxim,max11615 @ 0x33 (adc) */ -/* TODO */ +static const uint16_t adc_values[8 ] = { +1922 ,1000 , +1922 ,1000 , +1922 ,1000 , +1922 ,1000 }; +max11615_init_with_values (bus,0x33 , adc_values,8 ); at24c_eeprom_init_rom( bus, 0x52, eepromSize,
hw/sensor/max11615.c new file +312 -0
312 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -553,6 +553,7 @@ config ASPEED_SOC select PMBUS select MAX31785 select MAX31790 + select MAX11615 select FSI_APB2OPB_ASPEED select AT24C select PCI_EXPRESS
hw/sensor/Kconfig +4 -0
@@ -47,3 +47,7 @@ config MAX31785 config MAX31790 bool depends on I2C + +config MAX11615 + bool + depends on I2C
hw/sensor/meson.build +1 -0
@@ -9,3 +9,4 @@ 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')) +system_ss.add(when: 'CONFIG_MAX11615', if_true: files('max11615.c'))
hw/sensor/trace-events +8 -0
@@ -15,3 +15,11 @@ max31790_pwm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x max31790_rpm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" max31790_tach_count_reg(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +# max11615.c +max11615_write_setup(uint8_t i2c_addr, uint8_t send) "i2c_addr: 0x%02x, data: 0x%02x" +max11615_write_config(uint8_t i2c_addr, uint8_t send) "i2c_addr: 0x%02x, data: 0x%02x" +max11615_recv(uint8_t i2c_addr, uint8_t reg_addr) "i2c_addr: 0x%02x, reg_addr: 0x%02x" +max11615_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, returns: 0x%02x" +max11615_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x, event: 0x%02x" +max11615_realize(uint8_t i2c_addr) "i2c_addr: 0x%02x" +
tests/functional/arm/test_aspeed_fby4.py +8 -0
@@ -60,6 +60,14 @@ def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, exec_command_and_wait_for_pattern(self, "cat /sys/class/hwmon/hwmon2/fan1_input", "10685"); + # MAX11615 test + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/name", "max11615"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/in_voltage0_raw", "4095"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/in_voltage_scale", "0.500000000"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
Signature · 1 line
2.54.0
Re: [PATCH v5 4/5] hw/sensor: support MAX11615
Quoted 82 lines · Alexander Hansen
Product: [1]
Datasheet: [2]Sensor readings can be provided upon creation of the device. In case no readings are provided the ADC reads a pre-defined arbitrary value.
root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/name max11615 root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/in_voltage0_raw 1922 root@yosemite4:~# cat /sys/bus/iio/devices/iio:device2/in_voltage_scale 0.500000000trace:
less/tmp/qemu-trace.log| grep -i max116max11615_realizei2c_addr:0x33max11615_realizei2c_addr:0x33max11615_eventi2c_addr:0x33, event:0x01max11615_write_setupi2c_addr:0x33, data:0xd2max11615_write_configi2c_addr:0x33, data:0x0fmax11615_eventi2c_addr:0x33, event:0x03max11615_eventi2c_addr:0x33, event:0x01max11615_write_setupi2c_addr:0x33, data:0xd2max11615_write_configi2c_addr:0x33, data:0x0fmax11615_eventi2c_addr:0x33, event:0x03max11615_eventi2c_addr:0x33, event:0x01max11615_write_setupi2c_addr:0x33, data:0xd2max11615_write_configi2c_addr:0x33, data:0x61max11615_eventi2c_addr:0x33, event:0x03max11615_eventi2c_addr:0x33, event:0x00max11615_recvi2c_addr:0x33,reg_addr:0x00max11615_recv_returni2c_addr:0x33, returns:0xfamax11615_recvi2c_addr:0x33,reg_addr:0x00max11615_recv_returni2c_addr:0x33, returns:0xd2max11615_eventi2c_addr:0x33, event:0x04max11615_eventi2c_addr:0x33, event:0x03References:
[1] https://www.analog.com/en/products/MAX11615.html
[2] https://www.analog.com/media/en/technical-documentation/data-sheets/MAX11612-MAX11617.pdfCc Titus Rwantare <[email protected]>Cc "Cédric Le Goater" <[email protected]> (maintainer:ASPEED BMCs)Cc Jonathan Cameron <[email protected]>Cc "Philippe Mathieu-Daudé" <[email protected]> (odd fixer:Overall sensors)Cc Paolo Bonzini <[email protected]> (maintainer:Kconfig)Cc Peter Maydell <[email protected]> (supporter:ARM TCG CPUs)Cc [email protected] (open list:All patches CC here)Cc [email protected] (open list:ARM TCG CPUs)Signed-off-by Alexander Hansen <[email protected]>--- MAINTAINERS | 1 + include/hw/sensor/max11615.h | 20 ++ hw/arm/aspeed_ast2600_fby4.c | 8 +- hw/sensor/max11615.c | 312 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 8 + tests/functional/arm/test_aspeed_fby4.py | 8 + 9 files changed, 362 insertions(+), 1 deletion(-)create mode 100644
include/hw/sensor/max11615.h
create mode 100644hw/sensor/max11615.cMAINTAINERS +1
-0@@ -3987,6 +3987,7 @@ S: Maintained F: hw/i2c/pmbus_device.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c +F: hw/sensor/max11615.c F: hw/sensor/max31790.c F: hw/sensor/max34451.c F: include/hw/i2c/pmbus_device.hinclude/hw/sensor/max11615.h new file +0
-0
include/hw/sensor/max11615.h line 5
Quoted 5 lines
include/hw/sensor/max11615.h new file +5
-0@@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef QEMU_MAX11615_H +#define QEMU_MAX11615_H + +#include "qemu/osdep.h"
Please remove this include.
Quoted 28 lines
include/hw/sensor/max11615.h new file +15
-0+#include "hw/i2c/i2c.h" + +#define TYPE_MAX11615 "max11615" + +/* +* Create and realize a MAX11615 ADC with constant caller-supplied readings +* @bus: I2C bus to put it on +* @address: I2C address +* @init_values: array of readings for each ADC channel +* @init_values_size: Size of @init_values, can be less than the number of channels +*/ +I2CSlave *max11615_init_with_values (I2CBus *bus,uint8_t address, +const uint16_t *init_values,uint32_t init_values_size); + +#endif hw/arm/aspeed_ast2600_fby4.c +1
-0@@ -11,6 +11,7 @@#include "hw/arm/aspeed.h" #include "hw/arm/aspeed_soc.h" #include "hw/nvram/eeprom_at24c.h" +#include "hw/sensor/max11615.h" #include "hw/i2c/i2c_mux_pca954x.h" #include "hw/gpio/pca9552.h"
hw/arm/aspeed_ast2600_fby4.c static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize) · line 194
Quoted 10 lines
hw/arm/aspeed_ast2600_fby4.c +6
-1@@ -185,7 +186,12 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)i2c_slave_create_simple (bus,"max31790" ,0x2f );/* maxim,max11615 @ 0x33 (adc) */ -/* TODO */ +static const uint16_t adc_values[8 ] = { +1922 ,1000 , +1922 ,1000 , +1922 ,1000 , +1922 ,1000 }; +max11615_init_with_values (bus,0x33 , adc_values,8 );
see below
Quoted 139 lines
hw/arm/aspeed_ast2600_fby4.c +0
-0at24c_eeprom_init_rom( bus, 0x52, eepromSize,hw/sensor/max11615.c new file +130
-0@@ -0,0 +1,312 @@ +/* +* Maxim MAX11615 Low-Power 12 bit ADC +* Models MAX11612,MAX11613,MAX11614,MAX11615,MAX11616,MAX11617 +* +* Datasheet: +* https://www.analog.com/media/en/technical-documentation/data-sheets/MAX11612-MAX11617.pdf +* +* Copyright 2026 9elements +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "hw/sensor/max11615.h" +#include "hw/i2c/i2c.h" +#include "migration/vmstate.h" +#include "qapi/error.h" +#include "qapi/visitor.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/osdep.h" +#include "trace.h" + +#define MAX11615_NUM_CHANNELS 8 + +struct MAX11615State { +I2CSlave i2c; + +/* true: single-ended mode, false: differential mode */ +bool single_ended; + +/* +* Output data coding for the MAX11612–MAX11617 is +* binary in unipolar mode and two’s complement in bipolar mode +*/ +bool bipolar; + +/* The MAX11613/MAX11615/MAX11617 feature a 2.048V internal reference */ +uint16_t vref; + +uint16_t channels[MAX11615_NUM_CHANNELS ]; + +/* output buffer */ +uint8_t outlen; +uint8_t outbuf[2 ]; + +/* selected channel for read/write operation */ +uint8_t pointer; +}; + +struct MAX11615Class { +I2CSlaveClass parent_class; +}; + +OBJECT_DECLARE_TYPE(MAX11615State, MAX11615Class, MAX11615) + +static void max11615_set_outbuf (MAX11615State *s,uint16_t value) +{ +uint8_t msb = value >>8 ; +uint8_t lsb = value &0xff ; + s->outbuf[0 ] =0b11110000 | (msb &0b00001111 ); + s->outbuf[1 ] = lsb; +} + +static void max11615_read_single_ended (MAX11615State *s) +{ +/* Table 3. Channel Selection in Single-Ended Mode */ +/* read an ADC channel, first 4 bits must be high */ +uint16_t value = s->channels[s->pointer]; +/* +* In single-ended mode, the MAX11612–MAX11617 always +* operates in unipolar mode irrespective of BIP/UNI. +*/ +if (value > s->vref) { + value =0xfff ; + } +max11615_set_outbuf (s, value); +} + +static int16_t max11615_differential_value (MAX11615State *s) +{ +/* Table 4. Channel Selection in Differential Mode */ +size_t i1 = s->pointer; +size_t i2 = (s->pointer %2 ==0 ) ? s->pointer +1 : s->pointer -1 ; + +const int16_t ch1 = s->channels[i1]; +const int16_t ch2 = s->channels[i2]; +return ch1 - ch2; +} + +static void max11615_read_differential (MAX11615State *s) +{ +const int16_t value =max11615_differential_value (s); +uint16_t vu = value; + +/* full-scale transition: Figure 12, Figure 13 */ +if (s->bipolar) { +const uint16_t fs = s->vref /2 ; +if (value < -fs) { + vu =0b100000000000 ; + } +if (value > fs) { + vu =0b011111111111 ; + } + }else { +/* +* A negative differential analog input in unipolar mode causes the +* digital output code to be zero +*/ +if (value <0 ) { + vu =0 ; + } + } + +max11615_set_outbuf (s, vu); +} + +static void max11615_read (MAX11615State *s) +{ +if (s->single_ended) { +max11615_read_single_ended (s); + }else { +max11615_read_differential (s); + } +} + +static void max11615_write_config_byte (MAX11615State *s,uint8_t data) +{ +trace_max11615_write_config (s->i2c.address, data); + +uint8_t scan_select = (data >>5 ) &0b11 ;
hw/sensor/max11615.c line 140
Quoted 10 lines
hw/sensor/max11615.c new file +10
-0+ +if (scan_select !=0b11 ) { +qemu_log_mask (LOG_UNIMP ,"%s: unimplemented scan select\n" , __func__); + } + +uint8_t channel_select = (data >>1 ) &0b1111 ; + +/* Table 3. Channel Selection */ +if (channel_select >=MAX11615_NUM_CHANNELS ) { +qemu_log_mask (LOG_GUEST_ERROR ,"%s: invalid channel select" , __func__);
missing \n
Quoted 106 lines
hw/sensor/max11615.c new file +106
-0+ channel_select =MAX11615_NUM_CHANNELS -1 ; + } + s->pointer = channel_select; + s->single_ended = data &0x1 ; +} + +static void max11615_write_setup_byte (MAX11615State *s,uint8_t data) +{ +trace_max11615_write_setup (s->i2c.address, data); +/* we ignore the setup byte, not implemented */ + +/* 1 = no action, 0 = resets the configuration register to default */ +const bool rst = ((data >>1 ) &0b1 ) ==0b0 ; + +if (rst) { + s->single_ended = true; + s->pointer =0 ; + } + + s->bipolar = ((data >>2 ) &0b1 ) ==0b1 ; + +/* Table 6. Reference Voltage */ +const uint8_t sel = (data >>4 ) &0b111 ; + +if (sel ==0b10 || sel ==0b11 ) { +qemu_log_mask (LOG_UNIMP ,"%s: unsupported: external vref\n" , __func__); + } +} + +static int max11615_send (I2CSlave *i2c,uint8_t data) +{ +MAX11615State *s =MAX11615 (i2c); +const uint8_t msb = (data >>7 ) &0b1 ; + +if (msb) { +max11615_write_setup_byte (s, data); + }else { +max11615_write_config_byte (s, data); + } + + s->outlen =0 ; +return 0 ; +} + +static uint8_t max11615_recv (I2CSlave *i2c) +{ +MAX11615State *s =MAX11615 (i2c); +trace_max11615_recv (s->i2c.address, s->pointer); + +if (s->outlen >=2 ) { +/* MAX11615 supports multichannel scan with wraparound */ +/* see datasheet page 17 */ + + s->outlen =0 ; + + s->pointer++; +if (s->pointer >=MAX11615_NUM_CHANNELS ) { + s->pointer =0 ; + } + } + +max11615_read (s); + +const uint8_t data = s->outbuf[s->outlen++]; + +trace_max11615_recv_return (s->i2c.address, data); +return data; +} + +static int max11615_event (I2CSlave *i2c,enum i2c_event event) +{ +MAX11615State *s =MAX11615 (i2c); + +trace_max11615_event (s->i2c.address, event); + +switch (event) { +case I2C_START_RECV : + s->outlen =0 ; +break ; +default : +break ; + } + +return 0 ; +} + +static const VMStateDescription vmstate_max11615 = { + .name =TYPE_MAX11615 , + .version_id =0 , + .minimum_version_id =0 , + .fields = + (const VMStateField []){VMSTATE_BOOL (single_ended, MAX11615State), +VMSTATE_BOOL (bipolar, MAX11615State), +VMSTATE_UINT16 (vref, MAX11615State), +VMSTATE_UINT16_ARRAY (channels, MAX11615State, +MAX11615_NUM_CHANNELS ), +VMSTATE_UINT8 (outlen, MAX11615State), +VMSTATE_UINT8_ARRAY (outbuf, MAX11615State,2 ), +VMSTATE_UINT8 (pointer, MAX11615State), +VMSTATE_I2C_SLAVE (i2c, MAX11615State), +VMSTATE_END_OF_LIST () } +}; + +I2CSlave *max11615_init_with_values (I2CBus *bus,uint8_t address, +const uint16_t *init_values, +uint32_t init_values_size)
hw/sensor/max11615.c line 256
Quoted 10 lines
hw/sensor/max11615.c new file +10
-0+{ +MAX11615State *s; + + s =MAX11615 (i2c_slave_new (TYPE_MAX11615 , address)); + +for (int i =0 ; i <MAX11615_NUM_CHANNELS ; i++) { +/* arbitrary value if there is no data*/ + s->channels[i] = + i < init_values_size ? init_values[i] :0b0000101011010010 ; + }
s->channels[i] is set here and then machine resets occur and ....
Quoted 8 lines
hw/sensor/max11615.c new file +8
-0+i2c_slave_realize_and_unref (I2C_SLAVE (s), bus, &error_abort); + +return I2C_SLAVE (s); +} + +static void max11615_reset (DeviceState *dev) +{ +MAX11615State *s =MAX11615 (dev);
hw/sensor/max11615.c line 275
Quoted 10 lines
hw/sensor/max11615.c new file +10
-0+ + s->single_ended = true; + s->bipolar = false; + s->vref =2048 ; + s->pointer =0 ; + s->outlen =0 ; + +for (int i =0 ; i <MAX11615_NUM_CHANNELS ; i++) { + s->channels[i] =0b0000101011010010 ; + }
s->channels[i] should be reset again, which makes me wonder if the functional test really works.
hw/sensor/max11615.c line 283
Quoted 8 lines
hw/sensor/max11615.c new file +8
-0+} + +static void max11615_realize (DeviceState *dev,Error **errp) +{ +MAX11615State *s =MAX11615 (dev); + +trace_max11615_realize (s->i2c.address); +}
realize seems useless.
Quoted 82 lines
hw/sensor/max11615.c new file +28
-0+static void max11615_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *k =I2C_SLAVE_CLASS (klass); + + dc->realize = max11615_realize; + dc->desc ="Maxim MAX11615 12-bit ADC" ; + dc->vmsd = &vmstate_max11615; + dc->legacy_reset = max11615_reset; + k->event = max11615_event; + k->recv = max11615_recv; + k->send = max11615_send; +} + +static const TypeInfo max11615_info = { + .name =TYPE_MAX11615 , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (MAX11615State), + .class_size =sizeof (MAX11615Class), + .class_init = max11615_class_init, +}; + +static void max11615_register_types (void ) +{ +type_register_static (&max11615_info); +} + +type_init (max11615_register_types)hw/arm/Kconfig +1
-0@@ -553,6 +553,7 @@ config ASPEED_SOC select PMBUS select MAX31785 select MAX31790 + select MAX11615 select FSI_APB2OPB_ASPEED select AT24C select PCI_EXPRESShw/sensor/Kconfig +4
-0@@ -47,3 +47,7 @@ config MAX31785 config MAX31790 bool depends on I2C + +config MAX11615 + bool + depends on I2Chw/sensor/meson.build +1
-0@@ -9,3 +9,4 @@ 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')) +system_ss.add(when: 'CONFIG_MAX11615', if_true: files('max11615.c'))hw/sensor/trace-events +8
-0@@ -15,3 +15,11 @@ max31790_pwm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x max31790_rpm_write(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" max31790_tach_count_reg(uint8_t i2c_addr, size_t index, uint16_t value) "i2c_addr: 0x%02x, index: %zu, value: 0x%04x" +# max11615.c +max11615_write_setup(uint8_t i2c_addr, uint8_t send) "i2c_addr: 0x%02x, data: 0x%02x" +max11615_write_config(uint8_t i2c_addr, uint8_t send) "i2c_addr: 0x%02x, data: 0x%02x" +max11615_recv(uint8_t i2c_addr, uint8_t reg_addr) "i2c_addr: 0x%02x, reg_addr: 0x%02x" +max11615_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, returns: 0x%02x" +max11615_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x, event: 0x%02x" +max11615_realize(uint8_t i2c_addr) "i2c_addr: 0x%02x" +tests/functional/arm/test_aspeed_fby4.py +0
-0
tests/functional/arm/test_aspeed_fby4.py def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, · line 67
Quoted 8 lines
tests/functional/arm/test_aspeed_fby4.py +5
-0@@ -60,6 +60,14 @@ def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, exec_command_and_wait_for_pattern(self, "cat /sys/class/hwmon/hwmon2/fan1_input", "10685"); + # MAX11615 test + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/name", "max11615"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/in_voltage0_raw", "4095");
This is 0xfff. Which value is expected ? This does not reflect well in the board. Looks like a make-it-work value for me.
Thanks,
C.
Quoted 6 lines
tests/functional/arm/test_aspeed_fby4.py +3
-0+ exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-0033/iio:device*/in_voltage_scale", "0.500000000"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
PATCH v5 5/5 hw/sensor: support Texas Instruments ADC128D818
In reply to Alexander HansenProduct: [1]
Datasheet: [2]
ADC128D818 Support:
- channel readings from pre-set values
- driver can read and write most configuration registers
ADC128D818 currently unsupported:
- slave address restriction
- startup sequence and realistic busy register emulation
- external VREF
- conversion rate
- interrupts
- deep shutdown mode
- individual channel shutdown
- selection between Mode 0,1,2,3
- pseudo-differential input
Anyone could expand it in the future for more accurate emulation.
The reason for adding this device is to support Yosemite V4 emulation.
Tested: on yosemite v4 qemu
initialize the device:
// ti,adc128d818 @ 0x1f (adc)
// the driver will throw away the last 4 bits, set them 0
uint16_t adc_values1[8] = {
0b011110000000, 0b010100010000,
0b001000110000, 0b100000100000,
0b011110000000, 0b010100010000,
0b001000110000, 0b100000100000};adc128d818_init_with_values(bus, 0x1f, adc_values1, 8);
Trace outputs directly after initialization:adc128d818_realize i2c_addr: 0x1f adc128d818_realize i2c_addr: 0x1f adc128d818_event i2c_addr: 0x1f, event: 0x01 adc128d818_send i2c_addr: 0x1f, data: 0x00 adc128d818_send i2c_addr: 0x1f, data: 0x80 adc128d818_write i2c_addr: 0x1f, reg: 0x00 data: 0x80 adc128d818_event i2c_addr: 0x1f, event: 0x03 adc128d818_event i2c_addr: 0x1f, event: 0x01
...
read the values
root@yosemite4:/sys/bus/i2c/devices/30-001f# cat hwmon/hwmon0/in0_min 0 root@yosemite4:/sys/bus/i2c/devices/30-001f# cat hwmon/hwmon0/in0_max 0 root@yosemite4:/sys/bus/i2c/devices/30-001f# cat hwmon/hwmon0/in0_input 75 root@yosemite4:/sys/bus/i2c/devices/30-001f# cat hwmon/hwmon0/name adc128d818
We initially configured 0b011110000000 for the first channel. The driver throws away the last 4 bits and does calculation similar to below:
val = DIV_ROUND_CLOSEST(data->in[index][nr] * data->vref, 4095);
We can check that the calculation is as expected given our configured value.
((0b011110000000 >> 4) * 2560) / 4095
75.01831501831502
References:
[1] https://www.ti.com/product/ADC128D818
[2] https://www.ti.com/lit/gpn/adc128d818
--- MAINTAINERS | 1 + include/hw/sensor/adc128d818.h | 23 ++ hw/arm/aspeed_ast2600_fby4.c | 9 +- hw/sensor/adc128d818.c | 433 +++++++++++++++++++++++ hw/arm/Kconfig | 1 + hw/sensor/Kconfig | 4 + hw/sensor/meson.build | 1 + hw/sensor/trace-events | 7 + tests/functional/arm/test_aspeed_fby4.py | 10 + 9 files changed, 488 insertions(+), 1 deletion(-) create mode 100644 include/hw/sensor/adc128d818.h create mode 100644 hw/sensor/adc128d818.c
MAINTAINERS +1 -0
@@ -3985,6 +3985,7 @@ PMBus M: Titus Rwantare <[email protected]> S: Maintained F: hw/i2c/pmbus_device.c +F: hw/sensor/adc128d818.c F: hw/sensor/adm1272.c F: hw/sensor/isl_pmbus_vr.c F: hw/sensor/max11615.c
include/hw/sensor/adc128d818.h new file +23 -0
@@ -0,0 +1,23 @@ +/* Copyright 2026 9elements */ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef QEMU_ADC128D818_H +#define QEMU_ADC128D818_H + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" + +#define TYPE_ADC128D818 "adc128d818" + +/* +* Create and realize a adc128d818 ADC with constant caller-supplied readings +* @bus: I2C bus to put it on +* @address: I2C address +* @init_values: array of readings for each ADC channel +* @init_values_size: Size of @init_values, can be less than the number of +* channels +*/ +I2CSlave *adc128d818_init_with_values (I2CBus *bus,uint8_t address, +const uint16_t *init_values, +uint32_t init_values_size); + +#endif
hw/arm/aspeed_ast2600_fby4.c +8 -1
@@ -12,6 +12,7 @@#include "hw/arm/aspeed_soc.h" #include "hw/nvram/eeprom_at24c.h" #include "hw/sensor/max11615.h" +#include "hw/sensor/adc128d818.h" #include "hw/i2c/i2c_mux_pca954x.h" #include "hw/gpio/pca9552.h"
@@ -162,7 +163,13 @@ static void fby4_i2c_init_fanboard(I2CSlave *fan_mux, size_t eepromSize)I2CBus *bus =pca954x_i2c_get_bus (fan_mux, i);/* ti,adc128d818 @ 0x1f (adc) */ -/* TODO */ +/* the driver will throw away the last 4 bits, set them 0 */ +static const uint16_t adc_values1[8 ] = { +0b011110000000 ,0b010100010000 , +0b001000110000 ,0b100000100000 , +0b011110000000 ,0b010100010000 , +0b001000110000 ,0b100000100000 }; +adc128d818_init_with_values (bus,0x1f , adc_values1,8 );/* maxim,max31790 @ 0x20 (pwm) */ i2c_slave_create_simple (bus,"max31790" ,0x20 );
hw/sensor/adc128d818.c new file +433 -0
433 lines not on this page · raw message
hw/arm/Kconfig +1 -0
@@ -554,6 +554,7 @@ config ASPEED_SOC select MAX31785 select MAX31790 select MAX11615 + select ADC128D818 select FSI_APB2OPB_ASPEED select AT24C select PCI_EXPRESS
hw/sensor/Kconfig +4 -0
@@ -51,3 +51,7 @@ config MAX31790 config MAX11615 bool depends on I2C + +config ADC128D818 + bool + depends on I2C
hw/sensor/meson.build +1 -0
@@ -10,3 +10,4 @@ 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')) system_ss.add(when: 'CONFIG_MAX11615', if_true: files('max11615.c')) +system_ss.add(when: 'CONFIG_ADC128D818', if_true: files('adc128d818.c'))
hw/sensor/trace-events +7 -0
@@ -23,3 +23,10 @@ max11615_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, returns: max11615_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x, event: 0x%02x" max11615_realize(uint8_t i2c_addr) "i2c_addr: 0x%02x" +# adc128d818.c +adc128d818_send(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, data: 0x%02x" +adc128d818_write(uint8_t i2c_addr, uint8_t reg, uint8_t data) "i2c_addr: 0x%02x, reg: 0x%02x data: 0x%02x" +adc128d818_recv(uint8_t i2c_addr, uint8_t reg) "i2c_addr: 0x%02x, reg: 0x%02x" +adc128d818_recv_return(uint8_t i2c_addr, uint8_t data) "i2c_addr: 0x%02x, returns: 0x%02x" +adc128d818_event(uint8_t i2c_addr, uint8_t event) "i2c_addr: 0x%02x, event: 0x%02x" +adc128d818_realize(uint8_t i2c_addr) "i2c_addr: 0x%02x"
tests/functional/arm/test_aspeed_fby4.py +10 -0
@@ -68,6 +68,16 @@ def do_test_arm_aspeed_openbmc_no_network(self, machine, image, uboot, exec_command_and_wait_for_pattern(self, "cat /sys/bus/i2c/devices/30-0033/iio:device*/in_voltage_scale", "0.500000000"); + # ADC128D818 test + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-001f/hwmon/hwmon0/name", "adc128d818"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-001f/hwmon/hwmon0/in0_input", "108"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-001f/hwmon/hwmon0/in0_min", "0"); + exec_command_and_wait_for_pattern(self, + "cat /sys/bus/i2c/devices/30-001f/hwmon/hwmon0/in0_max", "0"); + def test_arm_ast2600_yosemitev4_openbmc(self): image_path = self.uncompress(self.ASSET_YOSEMITE_V4_FLASH)
Signature · 1 line
2.54.0