xref: /qemu/include/hw/i2c/pmbus_device.h (revision 3401b1dd)
13746d5c1STitus Rwantare /*
23746d5c1STitus Rwantare  * QEMU PMBus device emulation
33746d5c1STitus Rwantare  *
43746d5c1STitus Rwantare  * Copyright 2021 Google LLC
53746d5c1STitus Rwantare  *
63746d5c1STitus Rwantare  * SPDX-License-Identifier: GPL-2.0-or-later
73746d5c1STitus Rwantare  */
83746d5c1STitus Rwantare 
93746d5c1STitus Rwantare #ifndef HW_PMBUS_DEVICE_H
103746d5c1STitus Rwantare #define HW_PMBUS_DEVICE_H
113746d5c1STitus Rwantare 
123746d5c1STitus Rwantare #include "qemu/bitops.h"
133746d5c1STitus Rwantare #include "hw/i2c/smbus_slave.h"
143746d5c1STitus Rwantare 
153746d5c1STitus Rwantare enum pmbus_registers {
163746d5c1STitus Rwantare     PMBUS_PAGE                      = 0x00, /* R/W byte */
173746d5c1STitus Rwantare     PMBUS_OPERATION                 = 0x01, /* R/W byte */
183746d5c1STitus Rwantare     PMBUS_ON_OFF_CONFIG             = 0x02, /* R/W byte */
193746d5c1STitus Rwantare     PMBUS_CLEAR_FAULTS              = 0x03, /* Send Byte */
203746d5c1STitus Rwantare     PMBUS_PHASE                     = 0x04, /* R/W byte */
213746d5c1STitus Rwantare     PMBUS_PAGE_PLUS_WRITE           = 0x05, /* Block Write-only */
223746d5c1STitus Rwantare     PMBUS_PAGE_PLUS_READ            = 0x06, /* Block Read-only */
233746d5c1STitus Rwantare     PMBUS_WRITE_PROTECT             = 0x10, /* R/W byte */
243746d5c1STitus Rwantare     PMBUS_STORE_DEFAULT_ALL         = 0x11, /* Send Byte */
253746d5c1STitus Rwantare     PMBUS_RESTORE_DEFAULT_ALL       = 0x12, /* Send Byte */
263746d5c1STitus Rwantare     PMBUS_STORE_DEFAULT_CODE        = 0x13, /* Write-only Byte */
273746d5c1STitus Rwantare     PMBUS_RESTORE_DEFAULT_CODE      = 0x14, /* Write-only Byte */
283746d5c1STitus Rwantare     PMBUS_STORE_USER_ALL            = 0x15, /* Send Byte */
293746d5c1STitus Rwantare     PMBUS_RESTORE_USER_ALL          = 0x16, /* Send Byte */
303746d5c1STitus Rwantare     PMBUS_STORE_USER_CODE           = 0x17, /* Write-only Byte */
313746d5c1STitus Rwantare     PMBUS_RESTORE_USER_CODE         = 0x18, /* Write-only Byte */
323746d5c1STitus Rwantare     PMBUS_CAPABILITY                = 0x19, /* Read-Only byte */
333746d5c1STitus Rwantare     PMBUS_QUERY                     = 0x1A, /* Write-Only */
343746d5c1STitus Rwantare     PMBUS_SMBALERT_MASK             = 0x1B, /* Block read, Word write */
353746d5c1STitus Rwantare     PMBUS_VOUT_MODE                 = 0x20, /* R/W byte */
363746d5c1STitus Rwantare     PMBUS_VOUT_COMMAND              = 0x21, /* R/W word */
373746d5c1STitus Rwantare     PMBUS_VOUT_TRIM                 = 0x22, /* R/W word */
383746d5c1STitus Rwantare     PMBUS_VOUT_CAL_OFFSET           = 0x23, /* R/W word */
393746d5c1STitus Rwantare     PMBUS_VOUT_MAX                  = 0x24, /* R/W word */
403746d5c1STitus Rwantare     PMBUS_VOUT_MARGIN_HIGH          = 0x25, /* R/W word */
413746d5c1STitus Rwantare     PMBUS_VOUT_MARGIN_LOW           = 0x26, /* R/W word */
423746d5c1STitus Rwantare     PMBUS_VOUT_TRANSITION_RATE      = 0x27, /* R/W word */
433746d5c1STitus Rwantare     PMBUS_VOUT_DROOP                = 0x28, /* R/W word */
443746d5c1STitus Rwantare     PMBUS_VOUT_SCALE_LOOP           = 0x29, /* R/W word */
453746d5c1STitus Rwantare     PMBUS_VOUT_SCALE_MONITOR        = 0x2A, /* R/W word */
4632480293STitus Rwantare     PMBUS_VOUT_MIN                  = 0x2B, /* R/W word */
473746d5c1STitus Rwantare     PMBUS_COEFFICIENTS              = 0x30, /* Read-only block 5 bytes */
483746d5c1STitus Rwantare     PMBUS_POUT_MAX                  = 0x31, /* R/W word */
493746d5c1STitus Rwantare     PMBUS_MAX_DUTY                  = 0x32, /* R/W word */
503746d5c1STitus Rwantare     PMBUS_FREQUENCY_SWITCH          = 0x33, /* R/W word */
513746d5c1STitus Rwantare     PMBUS_VIN_ON                    = 0x35, /* R/W word */
523746d5c1STitus Rwantare     PMBUS_VIN_OFF                   = 0x36, /* R/W word */
533746d5c1STitus Rwantare     PMBUS_INTERLEAVE                = 0x37, /* R/W word */
543746d5c1STitus Rwantare     PMBUS_IOUT_CAL_GAIN             = 0x38, /* R/W word */
553746d5c1STitus Rwantare     PMBUS_IOUT_CAL_OFFSET           = 0x39, /* R/W word */
563746d5c1STitus Rwantare     PMBUS_FAN_CONFIG_1_2            = 0x3A, /* R/W byte */
573746d5c1STitus Rwantare     PMBUS_FAN_COMMAND_1             = 0x3B, /* R/W word */
583746d5c1STitus Rwantare     PMBUS_FAN_COMMAND_2             = 0x3C, /* R/W word */
593746d5c1STitus Rwantare     PMBUS_FAN_CONFIG_3_4            = 0x3D, /* R/W byte */
603746d5c1STitus Rwantare     PMBUS_FAN_COMMAND_3             = 0x3E, /* R/W word */
613746d5c1STitus Rwantare     PMBUS_FAN_COMMAND_4             = 0x3F, /* R/W word */
623746d5c1STitus Rwantare     PMBUS_VOUT_OV_FAULT_LIMIT       = 0x40, /* R/W word */
633746d5c1STitus Rwantare     PMBUS_VOUT_OV_FAULT_RESPONSE    = 0x41, /* R/W byte */
643746d5c1STitus Rwantare     PMBUS_VOUT_OV_WARN_LIMIT        = 0x42, /* R/W word */
653746d5c1STitus Rwantare     PMBUS_VOUT_UV_WARN_LIMIT        = 0x43, /* R/W word */
663746d5c1STitus Rwantare     PMBUS_VOUT_UV_FAULT_LIMIT       = 0x44, /* R/W word */
673746d5c1STitus Rwantare     PMBUS_VOUT_UV_FAULT_RESPONSE    = 0x45, /* R/W byte */
683746d5c1STitus Rwantare     PMBUS_IOUT_OC_FAULT_LIMIT       = 0x46, /* R/W word */
693746d5c1STitus Rwantare     PMBUS_IOUT_OC_FAULT_RESPONSE    = 0x47, /* R/W byte */
703746d5c1STitus Rwantare     PMBUS_IOUT_OC_LV_FAULT_LIMIT    = 0x48, /* R/W word */
713746d5c1STitus Rwantare     PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49, /* R/W byte */
723746d5c1STitus Rwantare     PMBUS_IOUT_OC_WARN_LIMIT        = 0x4A, /* R/W word */
733746d5c1STitus Rwantare     PMBUS_IOUT_UC_FAULT_LIMIT       = 0x4B, /* R/W word */
743746d5c1STitus Rwantare     PMBUS_IOUT_UC_FAULT_RESPONSE    = 0x4C, /* R/W byte */
753746d5c1STitus Rwantare     PMBUS_OT_FAULT_LIMIT            = 0x4F, /* R/W word */
763746d5c1STitus Rwantare     PMBUS_OT_FAULT_RESPONSE         = 0x50, /* R/W byte */
773746d5c1STitus Rwantare     PMBUS_OT_WARN_LIMIT             = 0x51, /* R/W word */
783746d5c1STitus Rwantare     PMBUS_UT_WARN_LIMIT             = 0x52, /* R/W word */
793746d5c1STitus Rwantare     PMBUS_UT_FAULT_LIMIT            = 0x53, /* R/W word */
803746d5c1STitus Rwantare     PMBUS_UT_FAULT_RESPONSE         = 0x54, /* R/W byte */
813746d5c1STitus Rwantare     PMBUS_VIN_OV_FAULT_LIMIT        = 0x55, /* R/W word */
823746d5c1STitus Rwantare     PMBUS_VIN_OV_FAULT_RESPONSE     = 0x56, /* R/W byte */
833746d5c1STitus Rwantare     PMBUS_VIN_OV_WARN_LIMIT         = 0x57, /* R/W word */
843746d5c1STitus Rwantare     PMBUS_VIN_UV_WARN_LIMIT         = 0x58, /* R/W word */
853746d5c1STitus Rwantare     PMBUS_VIN_UV_FAULT_LIMIT        = 0x59, /* R/W word */
863746d5c1STitus Rwantare     PMBUS_VIN_UV_FAULT_RESPONSE     = 0x5A, /* R/W byte */
873746d5c1STitus Rwantare     PMBUS_IIN_OC_FAULT_LIMIT        = 0x5B, /* R/W word */
883746d5c1STitus Rwantare     PMBUS_IIN_OC_FAULT_RESPONSE     = 0x5C, /* R/W byte */
893746d5c1STitus Rwantare     PMBUS_IIN_OC_WARN_LIMIT         = 0x5D, /* R/W word */
903746d5c1STitus Rwantare     PMBUS_POWER_GOOD_ON             = 0x5E, /* R/W word */
913746d5c1STitus Rwantare     PMBUS_POWER_GOOD_OFF            = 0x5F, /* R/W word */
923746d5c1STitus Rwantare     PMBUS_TON_DELAY                 = 0x60, /* R/W word */
933746d5c1STitus Rwantare     PMBUS_TON_RISE                  = 0x61, /* R/W word */
943746d5c1STitus Rwantare     PMBUS_TON_MAX_FAULT_LIMIT       = 0x62, /* R/W word */
953746d5c1STitus Rwantare     PMBUS_TON_MAX_FAULT_RESPONSE    = 0x63, /* R/W byte */
963746d5c1STitus Rwantare     PMBUS_TOFF_DELAY                = 0x64, /* R/W word */
973746d5c1STitus Rwantare     PMBUS_TOFF_FALL                 = 0x65, /* R/W word */
983746d5c1STitus Rwantare     PMBUS_TOFF_MAX_WARN_LIMIT       = 0x66, /* R/W word */
993746d5c1STitus Rwantare     PMBUS_POUT_OP_FAULT_LIMIT       = 0x68, /* R/W word */
1003746d5c1STitus Rwantare     PMBUS_POUT_OP_FAULT_RESPONSE    = 0x69, /* R/W byte */
1013746d5c1STitus Rwantare     PMBUS_POUT_OP_WARN_LIMIT        = 0x6A, /* R/W word */
1023746d5c1STitus Rwantare     PMBUS_PIN_OP_WARN_LIMIT         = 0x6B, /* R/W word */
1033746d5c1STitus Rwantare     PMBUS_STATUS_BYTE               = 0x78, /* R/W byte */
1043746d5c1STitus Rwantare     PMBUS_STATUS_WORD               = 0x79, /* R/W word */
1053746d5c1STitus Rwantare     PMBUS_STATUS_VOUT               = 0x7A, /* R/W byte */
1063746d5c1STitus Rwantare     PMBUS_STATUS_IOUT               = 0x7B, /* R/W byte */
1073746d5c1STitus Rwantare     PMBUS_STATUS_INPUT              = 0x7C, /* R/W byte */
1083746d5c1STitus Rwantare     PMBUS_STATUS_TEMPERATURE        = 0x7D, /* R/W byte */
1093746d5c1STitus Rwantare     PMBUS_STATUS_CML                = 0x7E, /* R/W byte */
1103746d5c1STitus Rwantare     PMBUS_STATUS_OTHER              = 0x7F, /* R/W byte */
1113746d5c1STitus Rwantare     PMBUS_STATUS_MFR_SPECIFIC       = 0x80, /* R/W byte */
1123746d5c1STitus Rwantare     PMBUS_STATUS_FANS_1_2           = 0x81, /* R/W byte */
1133746d5c1STitus Rwantare     PMBUS_STATUS_FANS_3_4           = 0x82, /* R/W byte */
1143746d5c1STitus Rwantare     PMBUS_READ_EIN                  = 0x86, /* Read-Only block 5 bytes */
1153746d5c1STitus Rwantare     PMBUS_READ_EOUT                 = 0x87, /* Read-Only block 5 bytes */
1163746d5c1STitus Rwantare     PMBUS_READ_VIN                  = 0x88, /* Read-Only word */
1173746d5c1STitus Rwantare     PMBUS_READ_IIN                  = 0x89, /* Read-Only word */
1183746d5c1STitus Rwantare     PMBUS_READ_VCAP                 = 0x8A, /* Read-Only word */
1193746d5c1STitus Rwantare     PMBUS_READ_VOUT                 = 0x8B, /* Read-Only word */
1203746d5c1STitus Rwantare     PMBUS_READ_IOUT                 = 0x8C, /* Read-Only word */
1213746d5c1STitus Rwantare     PMBUS_READ_TEMPERATURE_1        = 0x8D, /* Read-Only word */
1223746d5c1STitus Rwantare     PMBUS_READ_TEMPERATURE_2        = 0x8E, /* Read-Only word */
1233746d5c1STitus Rwantare     PMBUS_READ_TEMPERATURE_3        = 0x8F, /* Read-Only word */
1243746d5c1STitus Rwantare     PMBUS_READ_FAN_SPEED_1          = 0x90, /* Read-Only word */
1253746d5c1STitus Rwantare     PMBUS_READ_FAN_SPEED_2          = 0x91, /* Read-Only word */
1263746d5c1STitus Rwantare     PMBUS_READ_FAN_SPEED_3          = 0x92, /* Read-Only word */
1273746d5c1STitus Rwantare     PMBUS_READ_FAN_SPEED_4          = 0x93, /* Read-Only word */
1283746d5c1STitus Rwantare     PMBUS_READ_DUTY_CYCLE           = 0x94, /* Read-Only word */
1293746d5c1STitus Rwantare     PMBUS_READ_FREQUENCY            = 0x95, /* Read-Only word */
1303746d5c1STitus Rwantare     PMBUS_READ_POUT                 = 0x96, /* Read-Only word */
1313746d5c1STitus Rwantare     PMBUS_READ_PIN                  = 0x97, /* Read-Only word */
1323746d5c1STitus Rwantare     PMBUS_REVISION                  = 0x98, /* Read-Only byte */
1333746d5c1STitus Rwantare     PMBUS_MFR_ID                    = 0x99, /* R/W block */
1343746d5c1STitus Rwantare     PMBUS_MFR_MODEL                 = 0x9A, /* R/W block */
1353746d5c1STitus Rwantare     PMBUS_MFR_REVISION              = 0x9B, /* R/W block */
1363746d5c1STitus Rwantare     PMBUS_MFR_LOCATION              = 0x9C, /* R/W block */
1373746d5c1STitus Rwantare     PMBUS_MFR_DATE                  = 0x9D, /* R/W block */
1383746d5c1STitus Rwantare     PMBUS_MFR_SERIAL                = 0x9E, /* R/W block */
1393746d5c1STitus Rwantare     PMBUS_APP_PROFILE_SUPPORT       = 0x9F, /* Read-Only block-read */
1403746d5c1STitus Rwantare     PMBUS_MFR_VIN_MIN               = 0xA0, /* Read-Only word */
1413746d5c1STitus Rwantare     PMBUS_MFR_VIN_MAX               = 0xA1, /* Read-Only word */
1423746d5c1STitus Rwantare     PMBUS_MFR_IIN_MAX               = 0xA2, /* Read-Only word */
1433746d5c1STitus Rwantare     PMBUS_MFR_PIN_MAX               = 0xA3, /* Read-Only word */
1443746d5c1STitus Rwantare     PMBUS_MFR_VOUT_MIN              = 0xA4, /* Read-Only word */
1453746d5c1STitus Rwantare     PMBUS_MFR_VOUT_MAX              = 0xA5, /* Read-Only word */
1463746d5c1STitus Rwantare     PMBUS_MFR_IOUT_MAX              = 0xA6, /* Read-Only word */
1473746d5c1STitus Rwantare     PMBUS_MFR_POUT_MAX              = 0xA7, /* Read-Only word */
1483746d5c1STitus Rwantare     PMBUS_MFR_TAMBIENT_MAX          = 0xA8, /* Read-Only word */
1493746d5c1STitus Rwantare     PMBUS_MFR_TAMBIENT_MIN          = 0xA9, /* Read-Only word */
1503746d5c1STitus Rwantare     PMBUS_MFR_EFFICIENCY_LL         = 0xAA, /* Read-Only block 14 bytes */
1513746d5c1STitus Rwantare     PMBUS_MFR_EFFICIENCY_HL         = 0xAB, /* Read-Only block 14 bytes */
1523746d5c1STitus Rwantare     PMBUS_MFR_PIN_ACCURACY          = 0xAC, /* Read-Only byte */
1533746d5c1STitus Rwantare     PMBUS_IC_DEVICE_ID              = 0xAD, /* Read-Only block-read */
1543746d5c1STitus Rwantare     PMBUS_IC_DEVICE_REV             = 0xAE, /* Read-Only block-read */
1553746d5c1STitus Rwantare     PMBUS_MFR_MAX_TEMP_1            = 0xC0, /* R/W word */
1563746d5c1STitus Rwantare     PMBUS_MFR_MAX_TEMP_2            = 0xC1, /* R/W word */
1573746d5c1STitus Rwantare     PMBUS_MFR_MAX_TEMP_3            = 0xC2, /* R/W word */
158d272d141SPeter Delevoryas     PMBUS_IDLE_STATE                = 0xFF,
1593746d5c1STitus Rwantare };
1603746d5c1STitus Rwantare 
1613746d5c1STitus Rwantare /* STATUS_WORD */
1623746d5c1STitus Rwantare #define PB_STATUS_VOUT           BIT(15)
1633746d5c1STitus Rwantare #define PB_STATUS_IOUT_POUT      BIT(14)
1643746d5c1STitus Rwantare #define PB_STATUS_INPUT          BIT(13)
1653746d5c1STitus Rwantare #define PB_STATUS_WORD_MFR       BIT(12)
1663746d5c1STitus Rwantare #define PB_STATUS_POWER_GOOD_N   BIT(11)
1673746d5c1STitus Rwantare #define PB_STATUS_FAN            BIT(10)
1683746d5c1STitus Rwantare #define PB_STATUS_OTHER          BIT(9)
1693746d5c1STitus Rwantare #define PB_STATUS_UNKNOWN        BIT(8)
1703746d5c1STitus Rwantare /* STATUS_BYTE */
1713746d5c1STitus Rwantare #define PB_STATUS_BUSY           BIT(7)
1723746d5c1STitus Rwantare #define PB_STATUS_OFF            BIT(6)
1733746d5c1STitus Rwantare #define PB_STATUS_VOUT_OV        BIT(5)
1743746d5c1STitus Rwantare #define PB_STATUS_IOUT_OC        BIT(4)
1753746d5c1STitus Rwantare #define PB_STATUS_VIN_UV         BIT(3)
1763746d5c1STitus Rwantare #define PB_STATUS_TEMPERATURE    BIT(2)
1773746d5c1STitus Rwantare #define PB_STATUS_CML            BIT(1)
1783746d5c1STitus Rwantare #define PB_STATUS_NONE_ABOVE     BIT(0)
1793746d5c1STitus Rwantare 
1803746d5c1STitus Rwantare /* STATUS_VOUT */
1813746d5c1STitus Rwantare #define PB_STATUS_VOUT_OV_FAULT         BIT(7) /* Output Overvoltage Fault */
1823746d5c1STitus Rwantare #define PB_STATUS_VOUT_OV_WARN          BIT(6) /* Output Overvoltage Warning */
1833746d5c1STitus Rwantare #define PB_STATUS_VOUT_UV_WARN          BIT(5) /* Output Undervoltage Warning */
1843746d5c1STitus Rwantare #define PB_STATUS_VOUT_UV_FAULT         BIT(4) /* Output Undervoltage Fault */
1853746d5c1STitus Rwantare #define PB_STATUS_VOUT_MAX              BIT(3)
1863746d5c1STitus Rwantare #define PB_STATUS_VOUT_TON_MAX_FAULT    BIT(2)
1873746d5c1STitus Rwantare #define PB_STATUS_VOUT_TOFF_MAX_WARN    BIT(1)
1883746d5c1STitus Rwantare 
1893746d5c1STitus Rwantare /* STATUS_IOUT */
1903746d5c1STitus Rwantare #define PB_STATUS_IOUT_OC_FAULT    BIT(7) /* Output Overcurrent Fault */
1913746d5c1STitus Rwantare #define PB_STATUS_IOUT_OC_LV_FAULT BIT(6) /* Output OC And Low Voltage Fault */
1923746d5c1STitus Rwantare #define PB_STATUS_IOUT_OC_WARN     BIT(5) /* Output Overcurrent Warning */
1933746d5c1STitus Rwantare #define PB_STATUS_IOUT_UC_FAULT    BIT(4) /* Output Undercurrent Fault */
1943746d5c1STitus Rwantare #define PB_STATUS_CURR_SHARE       BIT(3) /* Current Share Fault */
1953746d5c1STitus Rwantare #define PB_STATUS_PWR_LIM_MODE     BIT(2) /* In Power Limiting Mode */
1963746d5c1STitus Rwantare #define PB_STATUS_POUT_OP_FAULT    BIT(1) /* Output Overpower Fault */
1973746d5c1STitus Rwantare #define PB_STATUS_POUT_OP_WARN     BIT(0) /* Output Overpower Warning */
1983746d5c1STitus Rwantare 
1993746d5c1STitus Rwantare /* STATUS_INPUT */
2003746d5c1STitus Rwantare #define PB_STATUS_INPUT_VIN_OV_FAULT    BIT(7) /* Input Overvoltage Fault */
2013746d5c1STitus Rwantare #define PB_STATUS_INPUT_VIN_OV_WARN     BIT(6) /* Input Overvoltage Warning */
2023746d5c1STitus Rwantare #define PB_STATUS_INPUT_VIN_UV_WARN     BIT(5) /* Input Undervoltage Warning */
2033746d5c1STitus Rwantare #define PB_STATUS_INPUT_VIN_UV_FAULT    BIT(4) /* Input Undervoltage Fault */
2043746d5c1STitus Rwantare #define PB_STATUS_INPUT_IIN_OC_FAULT    BIT(2) /* Input Overcurrent Fault */
2053746d5c1STitus Rwantare #define PB_STATUS_INPUT_IIN_OC_WARN     BIT(1) /* Input Overcurrent Warning */
2063746d5c1STitus Rwantare #define PB_STATUS_INPUT_PIN_OP_WARN     BIT(0) /* Input Overpower Warning */
2073746d5c1STitus Rwantare 
2083746d5c1STitus Rwantare /* STATUS_TEMPERATURE */
2093746d5c1STitus Rwantare #define PB_STATUS_OT_FAULT              BIT(7) /* Overtemperature Fault */
2103746d5c1STitus Rwantare #define PB_STATUS_OT_WARN               BIT(6) /* Overtemperature Warning */
2113746d5c1STitus Rwantare #define PB_STATUS_UT_WARN               BIT(5) /* Undertemperature Warning */
2123746d5c1STitus Rwantare #define PB_STATUS_UT_FAULT              BIT(4) /* Undertemperature Fault */
2133746d5c1STitus Rwantare 
2143746d5c1STitus Rwantare /* STATUS_CML */
2153746d5c1STitus Rwantare #define PB_CML_FAULT_INVALID_CMD     BIT(7) /* Invalid/Unsupported Command */
2163746d5c1STitus Rwantare #define PB_CML_FAULT_INVALID_DATA    BIT(6) /* Invalid/Unsupported Data  */
2173746d5c1STitus Rwantare #define PB_CML_FAULT_PEC             BIT(5) /* Packet Error Check Failed */
2183746d5c1STitus Rwantare #define PB_CML_FAULT_MEMORY          BIT(4) /* Memory Fault Detected */
2193746d5c1STitus Rwantare #define PB_CML_FAULT_PROCESSOR       BIT(3) /* Processor Fault Detected */
2203746d5c1STitus Rwantare #define PB_CML_FAULT_OTHER_COMM      BIT(1) /* Other communication fault */
2213746d5c1STitus Rwantare #define PB_CML_FAULT_OTHER_MEM_LOGIC BIT(0) /* Other Memory Or Logic Fault */
2223746d5c1STitus Rwantare 
2233746d5c1STitus Rwantare /* OPERATION*/
2243746d5c1STitus Rwantare #define PB_OP_ON                BIT(7) /* PSU is switched on */
2253746d5c1STitus Rwantare #define PB_OP_MARGIN_HIGH       BIT(5) /* PSU vout is set to margin high */
2263746d5c1STitus Rwantare #define PB_OP_MARGIN_LOW        BIT(4) /* PSU vout is set to margin low */
2273746d5c1STitus Rwantare 
2283746d5c1STitus Rwantare /* PAGES */
2293746d5c1STitus Rwantare #define PB_MAX_PAGES            0x1F
2303746d5c1STitus Rwantare #define PB_ALL_PAGES            0xFF
2313746d5c1STitus Rwantare 
23238870253STitus Rwantare #define PMBUS_ERR_BYTE          0xFF
23338870253STitus Rwantare 
2343746d5c1STitus Rwantare #define TYPE_PMBUS_DEVICE "pmbus-device"
2353746d5c1STitus Rwantare OBJECT_DECLARE_TYPE(PMBusDevice, PMBusDeviceClass,
2363746d5c1STitus Rwantare                     PMBUS_DEVICE)
2373746d5c1STitus Rwantare 
2383746d5c1STitus Rwantare /* flags */
2393746d5c1STitus Rwantare #define PB_HAS_COEFFICIENTS        BIT_ULL(9)
2403746d5c1STitus Rwantare #define PB_HAS_VIN                 BIT_ULL(10)
2413746d5c1STitus Rwantare #define PB_HAS_VOUT                BIT_ULL(11)
2423746d5c1STitus Rwantare #define PB_HAS_VOUT_MARGIN         BIT_ULL(12)
2433746d5c1STitus Rwantare #define PB_HAS_VIN_RATING          BIT_ULL(13)
2443746d5c1STitus Rwantare #define PB_HAS_VOUT_RATING         BIT_ULL(14)
2453746d5c1STitus Rwantare #define PB_HAS_VOUT_MODE           BIT_ULL(15)
2463401b1ddSTitus Rwantare #define PB_HAS_VCAP                BIT_ULL(16)
2473746d5c1STitus Rwantare #define PB_HAS_IOUT                BIT_ULL(21)
2483746d5c1STitus Rwantare #define PB_HAS_IIN                 BIT_ULL(22)
2493746d5c1STitus Rwantare #define PB_HAS_IOUT_RATING         BIT_ULL(23)
2503746d5c1STitus Rwantare #define PB_HAS_IIN_RATING          BIT_ULL(24)
2513746d5c1STitus Rwantare #define PB_HAS_IOUT_GAIN           BIT_ULL(25)
2523746d5c1STitus Rwantare #define PB_HAS_POUT                BIT_ULL(30)
2533746d5c1STitus Rwantare #define PB_HAS_PIN                 BIT_ULL(31)
2543746d5c1STitus Rwantare #define PB_HAS_EIN                 BIT_ULL(32)
2553746d5c1STitus Rwantare #define PB_HAS_EOUT                BIT_ULL(33)
2563746d5c1STitus Rwantare #define PB_HAS_POUT_RATING         BIT_ULL(34)
2573746d5c1STitus Rwantare #define PB_HAS_PIN_RATING          BIT_ULL(35)
2583746d5c1STitus Rwantare #define PB_HAS_TEMPERATURE         BIT_ULL(40)
2593746d5c1STitus Rwantare #define PB_HAS_TEMP2               BIT_ULL(41)
2603746d5c1STitus Rwantare #define PB_HAS_TEMP3               BIT_ULL(42)
2613746d5c1STitus Rwantare #define PB_HAS_TEMP_RATING         BIT_ULL(43)
262b7fba25eSTitus Rwantare #define PB_HAS_FAN                 BIT_ULL(44)
2633746d5c1STitus Rwantare #define PB_HAS_MFR_INFO            BIT_ULL(50)
26432480293STitus Rwantare #define PB_HAS_STATUS_MFR_SPECIFIC BIT_ULL(51)
2653746d5c1STitus Rwantare 
2663746d5c1STitus Rwantare struct PMBusDeviceClass {
2673746d5c1STitus Rwantare     SMBusDeviceClass parent_class;
2683746d5c1STitus Rwantare     uint8_t device_num_pages;
2693746d5c1STitus Rwantare 
2703746d5c1STitus Rwantare     /**
2713746d5c1STitus Rwantare      * Implement quick_cmd, receive byte, and write_data to support non-standard
2723746d5c1STitus Rwantare      * PMBus functionality
2733746d5c1STitus Rwantare      */
2743746d5c1STitus Rwantare     void (*quick_cmd)(PMBusDevice *dev, uint8_t read);
2753746d5c1STitus Rwantare     int (*write_data)(PMBusDevice *dev, const uint8_t *buf, uint8_t len);
2763746d5c1STitus Rwantare     uint8_t (*receive_byte)(PMBusDevice *dev);
2773746d5c1STitus Rwantare };
2783746d5c1STitus Rwantare 
2793746d5c1STitus Rwantare /*
2803746d5c1STitus Rwantare  * According to the spec, each page may offer the full range of PMBus commands
2813746d5c1STitus Rwantare  * available for each output or non-PMBus device.
2823746d5c1STitus Rwantare  * Therefore, we can't assume that any registers will always be the same across
2833746d5c1STitus Rwantare  * all pages.
2843746d5c1STitus Rwantare  * The page 0xFF is intended for writes to all pages
2853746d5c1STitus Rwantare  */
2863746d5c1STitus Rwantare typedef struct PMBusPage {
2873746d5c1STitus Rwantare     uint64_t page_flags;
2883746d5c1STitus Rwantare 
2893746d5c1STitus Rwantare     uint8_t page;                      /* R/W byte */
2903746d5c1STitus Rwantare     uint8_t operation;                 /* R/W byte */
2913746d5c1STitus Rwantare     uint8_t on_off_config;             /* R/W byte */
2923746d5c1STitus Rwantare     uint8_t write_protect;             /* R/W byte */
2933746d5c1STitus Rwantare     uint8_t phase;                     /* R/W byte */
2943746d5c1STitus Rwantare     uint8_t vout_mode;                 /* R/W byte */
2953746d5c1STitus Rwantare     uint16_t vout_command;             /* R/W word */
2963746d5c1STitus Rwantare     uint16_t vout_trim;                /* R/W word */
2973746d5c1STitus Rwantare     uint16_t vout_cal_offset;          /* R/W word */
2983746d5c1STitus Rwantare     uint16_t vout_max;                 /* R/W word */
2993746d5c1STitus Rwantare     uint16_t vout_margin_high;         /* R/W word */
3003746d5c1STitus Rwantare     uint16_t vout_margin_low;          /* R/W word */
3013746d5c1STitus Rwantare     uint16_t vout_transition_rate;     /* R/W word */
3023746d5c1STitus Rwantare     uint16_t vout_droop;               /* R/W word */
3033746d5c1STitus Rwantare     uint16_t vout_scale_loop;          /* R/W word */
3043746d5c1STitus Rwantare     uint16_t vout_scale_monitor;       /* R/W word */
30532480293STitus Rwantare     uint16_t vout_min;                 /* R/W word */
3063746d5c1STitus Rwantare     uint8_t coefficients[5];           /* Read-only block 5 bytes */
3073746d5c1STitus Rwantare     uint16_t pout_max;                 /* R/W word */
3083746d5c1STitus Rwantare     uint16_t max_duty;                 /* R/W word */
3093746d5c1STitus Rwantare     uint16_t frequency_switch;         /* R/W word */
3103746d5c1STitus Rwantare     uint16_t vin_on;                   /* R/W word */
3113746d5c1STitus Rwantare     uint16_t vin_off;                  /* R/W word */
3123746d5c1STitus Rwantare     uint16_t iout_cal_gain;            /* R/W word */
3133746d5c1STitus Rwantare     uint16_t iout_cal_offset;          /* R/W word */
3143746d5c1STitus Rwantare     uint8_t fan_config_1_2;            /* R/W byte */
3153746d5c1STitus Rwantare     uint16_t fan_command_1;            /* R/W word */
3163746d5c1STitus Rwantare     uint16_t fan_command_2;            /* R/W word */
3173746d5c1STitus Rwantare     uint8_t fan_config_3_4;            /* R/W byte */
3183746d5c1STitus Rwantare     uint16_t fan_command_3;            /* R/W word */
3193746d5c1STitus Rwantare     uint16_t fan_command_4;            /* R/W word */
3203746d5c1STitus Rwantare     uint16_t vout_ov_fault_limit;      /* R/W word */
3213746d5c1STitus Rwantare     uint8_t vout_ov_fault_response;    /* R/W byte */
3223746d5c1STitus Rwantare     uint16_t vout_ov_warn_limit;       /* R/W word */
3233746d5c1STitus Rwantare     uint16_t vout_uv_warn_limit;       /* R/W word */
3243746d5c1STitus Rwantare     uint16_t vout_uv_fault_limit;      /* R/W word */
3253746d5c1STitus Rwantare     uint8_t vout_uv_fault_response;    /* R/W byte */
3263746d5c1STitus Rwantare     uint16_t iout_oc_fault_limit;      /* R/W word */
3273746d5c1STitus Rwantare     uint8_t iout_oc_fault_response;    /* R/W byte */
3283746d5c1STitus Rwantare     uint16_t iout_oc_lv_fault_limit;   /* R/W word */
3293746d5c1STitus Rwantare     uint8_t iout_oc_lv_fault_response; /* R/W byte */
3303746d5c1STitus Rwantare     uint16_t iout_oc_warn_limit;       /* R/W word */
3313746d5c1STitus Rwantare     uint16_t iout_uc_fault_limit;      /* R/W word */
3323746d5c1STitus Rwantare     uint8_t iout_uc_fault_response;    /* R/W byte */
3333746d5c1STitus Rwantare     uint16_t ot_fault_limit;           /* R/W word */
3343746d5c1STitus Rwantare     uint8_t ot_fault_response;         /* R/W byte */
3353746d5c1STitus Rwantare     uint16_t ot_warn_limit;            /* R/W word */
3363746d5c1STitus Rwantare     uint16_t ut_warn_limit;            /* R/W word */
3373746d5c1STitus Rwantare     uint16_t ut_fault_limit;           /* R/W word */
3383746d5c1STitus Rwantare     uint8_t ut_fault_response;         /* R/W byte */
3393746d5c1STitus Rwantare     uint16_t vin_ov_fault_limit;       /* R/W word */
3403746d5c1STitus Rwantare     uint8_t vin_ov_fault_response;     /* R/W byte */
3413746d5c1STitus Rwantare     uint16_t vin_ov_warn_limit;        /* R/W word */
3423746d5c1STitus Rwantare     uint16_t vin_uv_warn_limit;        /* R/W word */
3433746d5c1STitus Rwantare     uint16_t vin_uv_fault_limit;       /* R/W word */
3443746d5c1STitus Rwantare     uint8_t vin_uv_fault_response;     /* R/W byte */
3453746d5c1STitus Rwantare     uint16_t iin_oc_fault_limit;       /* R/W word */
3463746d5c1STitus Rwantare     uint8_t iin_oc_fault_response;     /* R/W byte */
3473746d5c1STitus Rwantare     uint16_t iin_oc_warn_limit;        /* R/W word */
3483746d5c1STitus Rwantare     uint16_t power_good_on;            /* R/W word */
3493746d5c1STitus Rwantare     uint16_t power_good_off;           /* R/W word */
3503746d5c1STitus Rwantare     uint16_t ton_delay;                /* R/W word */
3513746d5c1STitus Rwantare     uint16_t ton_rise;                 /* R/W word */
3523746d5c1STitus Rwantare     uint16_t ton_max_fault_limit;      /* R/W word */
3533746d5c1STitus Rwantare     uint8_t ton_max_fault_response;    /* R/W byte */
3543746d5c1STitus Rwantare     uint16_t toff_delay;               /* R/W word */
3553746d5c1STitus Rwantare     uint16_t toff_fall;                /* R/W word */
3563746d5c1STitus Rwantare     uint16_t toff_max_warn_limit;      /* R/W word */
3573746d5c1STitus Rwantare     uint16_t pout_op_fault_limit;      /* R/W word */
3583746d5c1STitus Rwantare     uint8_t pout_op_fault_response;    /* R/W byte */
3593746d5c1STitus Rwantare     uint16_t pout_op_warn_limit;       /* R/W word */
3603746d5c1STitus Rwantare     uint16_t pin_op_warn_limit;        /* R/W word */
3613746d5c1STitus Rwantare     uint16_t status_word;              /* R/W word */
3623746d5c1STitus Rwantare     uint8_t status_vout;               /* R/W byte */
3633746d5c1STitus Rwantare     uint8_t status_iout;               /* R/W byte */
3643746d5c1STitus Rwantare     uint8_t status_input;              /* R/W byte */
3653746d5c1STitus Rwantare     uint8_t status_temperature;        /* R/W byte */
3663746d5c1STitus Rwantare     uint8_t status_cml;                /* R/W byte */
3673746d5c1STitus Rwantare     uint8_t status_other;              /* R/W byte */
3683746d5c1STitus Rwantare     uint8_t status_mfr_specific;       /* R/W byte */
3693746d5c1STitus Rwantare     uint8_t status_fans_1_2;           /* R/W byte */
3703746d5c1STitus Rwantare     uint8_t status_fans_3_4;           /* R/W byte */
3713746d5c1STitus Rwantare     uint8_t read_ein[5];               /* Read-Only block 5 bytes */
3723746d5c1STitus Rwantare     uint8_t read_eout[5];              /* Read-Only block 5 bytes */
3733746d5c1STitus Rwantare     uint16_t read_vin;                 /* Read-Only word */
3743746d5c1STitus Rwantare     uint16_t read_iin;                 /* Read-Only word */
3753746d5c1STitus Rwantare     uint16_t read_vcap;                /* Read-Only word */
3763746d5c1STitus Rwantare     uint16_t read_vout;                /* Read-Only word */
3773746d5c1STitus Rwantare     uint16_t read_iout;                /* Read-Only word */
3783746d5c1STitus Rwantare     uint16_t read_temperature_1;       /* Read-Only word */
3793746d5c1STitus Rwantare     uint16_t read_temperature_2;       /* Read-Only word */
3803746d5c1STitus Rwantare     uint16_t read_temperature_3;       /* Read-Only word */
3813746d5c1STitus Rwantare     uint16_t read_fan_speed_1;         /* Read-Only word */
3823746d5c1STitus Rwantare     uint16_t read_fan_speed_2;         /* Read-Only word */
3833746d5c1STitus Rwantare     uint16_t read_fan_speed_3;         /* Read-Only word */
3843746d5c1STitus Rwantare     uint16_t read_fan_speed_4;         /* Read-Only word */
3853746d5c1STitus Rwantare     uint16_t read_duty_cycle;          /* Read-Only word */
3863746d5c1STitus Rwantare     uint16_t read_frequency;           /* Read-Only word */
3873746d5c1STitus Rwantare     uint16_t read_pout;                /* Read-Only word */
3883746d5c1STitus Rwantare     uint16_t read_pin;                 /* Read-Only word */
3893746d5c1STitus Rwantare     uint8_t revision;                  /* Read-Only byte */
3903746d5c1STitus Rwantare     const char *mfr_id;                /* R/W block */
3913746d5c1STitus Rwantare     const char *mfr_model;             /* R/W block */
3923746d5c1STitus Rwantare     const char *mfr_revision;          /* R/W block */
3933746d5c1STitus Rwantare     const char *mfr_location;          /* R/W block */
3943746d5c1STitus Rwantare     const char *mfr_date;              /* R/W block */
3953746d5c1STitus Rwantare     const char *mfr_serial;            /* R/W block */
3963746d5c1STitus Rwantare     const char *app_profile_support;   /* Read-Only block-read */
3973746d5c1STitus Rwantare     uint16_t mfr_vin_min;              /* Read-Only word */
3983746d5c1STitus Rwantare     uint16_t mfr_vin_max;              /* Read-Only word */
3993746d5c1STitus Rwantare     uint16_t mfr_iin_max;              /* Read-Only word */
4003746d5c1STitus Rwantare     uint16_t mfr_pin_max;              /* Read-Only word */
4013746d5c1STitus Rwantare     uint16_t mfr_vout_min;             /* Read-Only word */
4023746d5c1STitus Rwantare     uint16_t mfr_vout_max;             /* Read-Only word */
4033746d5c1STitus Rwantare     uint16_t mfr_iout_max;             /* Read-Only word */
4043746d5c1STitus Rwantare     uint16_t mfr_pout_max;             /* Read-Only word */
4053746d5c1STitus Rwantare     uint16_t mfr_tambient_max;         /* Read-Only word */
4063746d5c1STitus Rwantare     uint16_t mfr_tambient_min;         /* Read-Only word */
4073746d5c1STitus Rwantare     uint8_t mfr_efficiency_ll[14];     /* Read-Only block 14 bytes */
4083746d5c1STitus Rwantare     uint8_t mfr_efficiency_hl[14];     /* Read-Only block 14 bytes */
4093746d5c1STitus Rwantare     uint8_t mfr_pin_accuracy;          /* Read-Only byte */
4103746d5c1STitus Rwantare     uint16_t mfr_max_temp_1;           /* R/W word */
4113746d5c1STitus Rwantare     uint16_t mfr_max_temp_2;           /* R/W word */
4123746d5c1STitus Rwantare     uint16_t mfr_max_temp_3;           /* R/W word */
4133746d5c1STitus Rwantare } PMBusPage;
4143746d5c1STitus Rwantare 
4153746d5c1STitus Rwantare /* State */
4163746d5c1STitus Rwantare struct PMBusDevice {
4173746d5c1STitus Rwantare     SMBusDevice smb;
4183746d5c1STitus Rwantare 
4193746d5c1STitus Rwantare     uint8_t num_pages;
4203746d5c1STitus Rwantare     uint8_t code;
4213746d5c1STitus Rwantare     uint8_t page;
4223746d5c1STitus Rwantare 
4233746d5c1STitus Rwantare     /*
4243746d5c1STitus Rwantare      * PMBus registers are stored in a PMBusPage structure allocated by
4253746d5c1STitus Rwantare      * calling pmbus_pages_alloc()
4263746d5c1STitus Rwantare      */
4273746d5c1STitus Rwantare     PMBusPage *pages;
4283746d5c1STitus Rwantare     uint8_t capability;
4293746d5c1STitus Rwantare 
4303746d5c1STitus Rwantare 
4313746d5c1STitus Rwantare     int32_t in_buf_len;
4323746d5c1STitus Rwantare     uint8_t *in_buf;
4333746d5c1STitus Rwantare     int32_t out_buf_len;
4343746d5c1STitus Rwantare     uint8_t out_buf[SMBUS_DATA_MAX_LEN];
4353746d5c1STitus Rwantare };
4363746d5c1STitus Rwantare 
4373746d5c1STitus Rwantare /**
4383746d5c1STitus Rwantare  * Direct mode coefficients
4393746d5c1STitus Rwantare  * @var m - mantissa
4403746d5c1STitus Rwantare  * @var b - offset
4413746d5c1STitus Rwantare  * @var R - exponent
4423746d5c1STitus Rwantare  */
4433746d5c1STitus Rwantare typedef struct PMBusCoefficients {
4443746d5c1STitus Rwantare     int32_t m;     /* mantissa */
4453746d5c1STitus Rwantare     int64_t b;     /* offset */
4463746d5c1STitus Rwantare     int32_t R;     /* exponent */
4473746d5c1STitus Rwantare } PMBusCoefficients;
4483746d5c1STitus Rwantare 
4493746d5c1STitus Rwantare /**
450144729b9STitus Rwantare  * VOUT_Mode bit fields
451144729b9STitus Rwantare  */
452144729b9STitus Rwantare typedef struct PMBusVoutMode {
453144729b9STitus Rwantare     uint8_t  mode:3;
454144729b9STitus Rwantare     int8_t   exp:5;
455144729b9STitus Rwantare } PMBusVoutMode;
456144729b9STitus Rwantare 
457144729b9STitus Rwantare /**
4583746d5c1STitus Rwantare  * Convert sensor values to direct mode format
4593746d5c1STitus Rwantare  *
4603746d5c1STitus Rwantare  * Y = (m * x - b) * 10^R
4613746d5c1STitus Rwantare  *
462648a4882SShengtan Mao  * @return uint16_t
4633746d5c1STitus Rwantare  */
4643746d5c1STitus Rwantare uint16_t pmbus_data2direct_mode(PMBusCoefficients c, uint32_t value);
4653746d5c1STitus Rwantare 
4663746d5c1STitus Rwantare /**
4673746d5c1STitus Rwantare  * Convert direct mode formatted data into sensor reading
4683746d5c1STitus Rwantare  *
4693746d5c1STitus Rwantare  * X = (Y * 10^-R - b) / m
4703746d5c1STitus Rwantare  *
4713746d5c1STitus Rwantare  * @return uint32_t
4723746d5c1STitus Rwantare  */
4733746d5c1STitus Rwantare uint32_t pmbus_direct_mode2data(PMBusCoefficients c, uint16_t value);
4743746d5c1STitus Rwantare 
4753746d5c1STitus Rwantare /**
476648a4882SShengtan Mao  * Convert sensor values to linear mode format
477648a4882SShengtan Mao  *
478648a4882SShengtan Mao  * L = D * 2^(-e)
479648a4882SShengtan Mao  *
480648a4882SShengtan Mao  * @return uint16
481648a4882SShengtan Mao  */
482648a4882SShengtan Mao uint16_t pmbus_data2linear_mode(uint16_t value, int exp);
483648a4882SShengtan Mao 
484648a4882SShengtan Mao /**
485648a4882SShengtan Mao  * Convert linear mode formatted data into sensor reading
486648a4882SShengtan Mao  *
487648a4882SShengtan Mao  * D = L * 2^e
488648a4882SShengtan Mao  *
489648a4882SShengtan Mao  * @return uint16
490648a4882SShengtan Mao  */
491648a4882SShengtan Mao uint16_t pmbus_linear_mode2data(uint16_t value, int exp);
492648a4882SShengtan Mao 
493648a4882SShengtan Mao /**
4943746d5c1STitus Rwantare  * @brief Send a block of data over PMBus
4953746d5c1STitus Rwantare  * Assumes that the bytes in the block are already ordered correctly,
4963746d5c1STitus Rwantare  * also assumes the length has been prepended to the block if necessary
4973746d5c1STitus Rwantare  *     | low_byte | ... | high_byte |
4983746d5c1STitus Rwantare  * @param state - maintains state of the PMBus device
4993746d5c1STitus Rwantare  * @param data - byte array to be sent by device
5003746d5c1STitus Rwantare  * @param len - number
5013746d5c1STitus Rwantare  */
5023746d5c1STitus Rwantare void pmbus_send(PMBusDevice *state, const uint8_t *data, uint16_t len);
5033746d5c1STitus Rwantare void pmbus_send8(PMBusDevice *state, uint8_t data);
5043746d5c1STitus Rwantare void pmbus_send16(PMBusDevice *state, uint16_t data);
5053746d5c1STitus Rwantare void pmbus_send32(PMBusDevice *state, uint32_t data);
5063746d5c1STitus Rwantare void pmbus_send64(PMBusDevice *state, uint64_t data);
5073746d5c1STitus Rwantare 
5083746d5c1STitus Rwantare /**
5093746d5c1STitus Rwantare  * @brief Send a string over PMBus with length prepended.
5103746d5c1STitus Rwantare  * Length is calculated using str_len()
5113746d5c1STitus Rwantare  */
5123746d5c1STitus Rwantare void pmbus_send_string(PMBusDevice *state, const char *data);
5133746d5c1STitus Rwantare 
5143746d5c1STitus Rwantare /**
515cfb0884cSTitus Rwantare  * @brief Receive data sent with Block Write.
516cfb0884cSTitus Rwantare  * @param dest - memory with enough capacity to receive the write
517cfb0884cSTitus Rwantare  * @param len - the capacity of dest
518cfb0884cSTitus Rwantare  */
519cfb0884cSTitus Rwantare uint8_t pmbus_receive_block(PMBusDevice *pmdev, uint8_t *dest, size_t len);
520cfb0884cSTitus Rwantare 
521cfb0884cSTitus Rwantare /**
5223746d5c1STitus Rwantare  * @brief Receive data over PMBus
5233746d5c1STitus Rwantare  * These methods help track how much data is being received over PMBus
5243746d5c1STitus Rwantare  * Log to GUEST_ERROR if too much or too little is sent.
5253746d5c1STitus Rwantare  */
5263746d5c1STitus Rwantare uint8_t pmbus_receive8(PMBusDevice *pmdev);
5273746d5c1STitus Rwantare uint16_t pmbus_receive16(PMBusDevice *pmdev);
5283746d5c1STitus Rwantare uint32_t pmbus_receive32(PMBusDevice *pmdev);
5293746d5c1STitus Rwantare uint64_t pmbus_receive64(PMBusDevice *pmdev);
5303746d5c1STitus Rwantare 
5313746d5c1STitus Rwantare /**
5323746d5c1STitus Rwantare  * PMBus page config must be called before any page is first used.
5333746d5c1STitus Rwantare  * It will allocate memory for all the pages if needed.
5343746d5c1STitus Rwantare  * Passed in flags overwrite existing flags if any.
5353746d5c1STitus Rwantare  * @param page_index the page to which the flags are applied, setting page_index
5363746d5c1STitus Rwantare  * to 0xFF applies the passed in flags to all pages.
5373746d5c1STitus Rwantare  * @param flags
5383746d5c1STitus Rwantare  */
5393746d5c1STitus Rwantare int pmbus_page_config(PMBusDevice *pmdev, uint8_t page_index, uint64_t flags);
5403746d5c1STitus Rwantare 
5413746d5c1STitus Rwantare /**
5423746d5c1STitus Rwantare  * Update the status registers when sensor values change.
5433746d5c1STitus Rwantare  * Useful if modifying sensors through qmp, this way status registers get
5443746d5c1STitus Rwantare  * updated
5453746d5c1STitus Rwantare  */
5463746d5c1STitus Rwantare void pmbus_check_limits(PMBusDevice *pmdev);
5473746d5c1STitus Rwantare 
548d272d141SPeter Delevoryas /**
549d272d141SPeter Delevoryas  * Enter an idle state where only the PMBUS_ERR_BYTE will be returned
550d272d141SPeter Delevoryas  * indefinitely until a new command is issued.
551d272d141SPeter Delevoryas  */
552d272d141SPeter Delevoryas void pmbus_idle(PMBusDevice *pmdev);
553d272d141SPeter Delevoryas 
5543746d5c1STitus Rwantare extern const VMStateDescription vmstate_pmbus_device;
5553746d5c1STitus Rwantare 
5563746d5c1STitus Rwantare #define VMSTATE_PMBUS_DEVICE(_field, _state) {                       \
5573746d5c1STitus Rwantare     .name       = (stringify(_field)),                               \
5583746d5c1STitus Rwantare     .size       = sizeof(PMBusDevice),                               \
5593746d5c1STitus Rwantare     .vmsd       = &vmstate_pmbus_device,                             \
5603746d5c1STitus Rwantare     .flags      = VMS_STRUCT,                                        \
5613746d5c1STitus Rwantare     .offset     = vmstate_offset_value(_state, _field, PMBusDevice), \
5623746d5c1STitus Rwantare }
5633746d5c1STitus Rwantare 
5643746d5c1STitus Rwantare #endif
565