162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 262306a36Sopenharmony_ci/* 362306a36Sopenharmony_ci * pmbus.h - Common defines and structures for PMBus devices 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (c) 2010, 2011 Ericsson AB. 662306a36Sopenharmony_ci * Copyright (c) 2012 Guenter Roeck 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci 962306a36Sopenharmony_ci#ifndef PMBUS_H 1062306a36Sopenharmony_ci#define PMBUS_H 1162306a36Sopenharmony_ci 1262306a36Sopenharmony_ci#include <linux/bitops.h> 1362306a36Sopenharmony_ci#include <linux/regulator/driver.h> 1462306a36Sopenharmony_ci 1562306a36Sopenharmony_ci/* 1662306a36Sopenharmony_ci * Registers 1762306a36Sopenharmony_ci */ 1862306a36Sopenharmony_cienum pmbus_regs { 1962306a36Sopenharmony_ci PMBUS_PAGE = 0x00, 2062306a36Sopenharmony_ci PMBUS_OPERATION = 0x01, 2162306a36Sopenharmony_ci PMBUS_ON_OFF_CONFIG = 0x02, 2262306a36Sopenharmony_ci PMBUS_CLEAR_FAULTS = 0x03, 2362306a36Sopenharmony_ci PMBUS_PHASE = 0x04, 2462306a36Sopenharmony_ci 2562306a36Sopenharmony_ci PMBUS_WRITE_PROTECT = 0x10, 2662306a36Sopenharmony_ci 2762306a36Sopenharmony_ci PMBUS_CAPABILITY = 0x19, 2862306a36Sopenharmony_ci PMBUS_QUERY = 0x1A, 2962306a36Sopenharmony_ci PMBUS_SMBALERT_MASK = 0x1B, 3062306a36Sopenharmony_ci PMBUS_VOUT_MODE = 0x20, 3162306a36Sopenharmony_ci PMBUS_VOUT_COMMAND = 0x21, 3262306a36Sopenharmony_ci PMBUS_VOUT_TRIM = 0x22, 3362306a36Sopenharmony_ci PMBUS_VOUT_CAL_OFFSET = 0x23, 3462306a36Sopenharmony_ci PMBUS_VOUT_MAX = 0x24, 3562306a36Sopenharmony_ci PMBUS_VOUT_MARGIN_HIGH = 0x25, 3662306a36Sopenharmony_ci PMBUS_VOUT_MARGIN_LOW = 0x26, 3762306a36Sopenharmony_ci PMBUS_VOUT_TRANSITION_RATE = 0x27, 3862306a36Sopenharmony_ci PMBUS_VOUT_DROOP = 0x28, 3962306a36Sopenharmony_ci PMBUS_VOUT_SCALE_LOOP = 0x29, 4062306a36Sopenharmony_ci PMBUS_VOUT_SCALE_MONITOR = 0x2A, 4162306a36Sopenharmony_ci 4262306a36Sopenharmony_ci PMBUS_COEFFICIENTS = 0x30, 4362306a36Sopenharmony_ci PMBUS_POUT_MAX = 0x31, 4462306a36Sopenharmony_ci 4562306a36Sopenharmony_ci PMBUS_FAN_CONFIG_12 = 0x3A, 4662306a36Sopenharmony_ci PMBUS_FAN_COMMAND_1 = 0x3B, 4762306a36Sopenharmony_ci PMBUS_FAN_COMMAND_2 = 0x3C, 4862306a36Sopenharmony_ci PMBUS_FAN_CONFIG_34 = 0x3D, 4962306a36Sopenharmony_ci PMBUS_FAN_COMMAND_3 = 0x3E, 5062306a36Sopenharmony_ci PMBUS_FAN_COMMAND_4 = 0x3F, 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci PMBUS_VOUT_OV_FAULT_LIMIT = 0x40, 5362306a36Sopenharmony_ci PMBUS_VOUT_OV_FAULT_RESPONSE = 0x41, 5462306a36Sopenharmony_ci PMBUS_VOUT_OV_WARN_LIMIT = 0x42, 5562306a36Sopenharmony_ci PMBUS_VOUT_UV_WARN_LIMIT = 0x43, 5662306a36Sopenharmony_ci PMBUS_VOUT_UV_FAULT_LIMIT = 0x44, 5762306a36Sopenharmony_ci PMBUS_VOUT_UV_FAULT_RESPONSE = 0x45, 5862306a36Sopenharmony_ci PMBUS_IOUT_OC_FAULT_LIMIT = 0x46, 5962306a36Sopenharmony_ci PMBUS_IOUT_OC_FAULT_RESPONSE = 0x47, 6062306a36Sopenharmony_ci PMBUS_IOUT_OC_LV_FAULT_LIMIT = 0x48, 6162306a36Sopenharmony_ci PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49, 6262306a36Sopenharmony_ci PMBUS_IOUT_OC_WARN_LIMIT = 0x4A, 6362306a36Sopenharmony_ci PMBUS_IOUT_UC_FAULT_LIMIT = 0x4B, 6462306a36Sopenharmony_ci PMBUS_IOUT_UC_FAULT_RESPONSE = 0x4C, 6562306a36Sopenharmony_ci 6662306a36Sopenharmony_ci PMBUS_OT_FAULT_LIMIT = 0x4F, 6762306a36Sopenharmony_ci PMBUS_OT_FAULT_RESPONSE = 0x50, 6862306a36Sopenharmony_ci PMBUS_OT_WARN_LIMIT = 0x51, 6962306a36Sopenharmony_ci PMBUS_UT_WARN_LIMIT = 0x52, 7062306a36Sopenharmony_ci PMBUS_UT_FAULT_LIMIT = 0x53, 7162306a36Sopenharmony_ci PMBUS_UT_FAULT_RESPONSE = 0x54, 7262306a36Sopenharmony_ci PMBUS_VIN_OV_FAULT_LIMIT = 0x55, 7362306a36Sopenharmony_ci PMBUS_VIN_OV_FAULT_RESPONSE = 0x56, 7462306a36Sopenharmony_ci PMBUS_VIN_OV_WARN_LIMIT = 0x57, 7562306a36Sopenharmony_ci PMBUS_VIN_UV_WARN_LIMIT = 0x58, 7662306a36Sopenharmony_ci PMBUS_VIN_UV_FAULT_LIMIT = 0x59, 7762306a36Sopenharmony_ci 7862306a36Sopenharmony_ci PMBUS_IIN_OC_FAULT_LIMIT = 0x5B, 7962306a36Sopenharmony_ci PMBUS_IIN_OC_WARN_LIMIT = 0x5D, 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci PMBUS_POUT_OP_FAULT_LIMIT = 0x68, 8262306a36Sopenharmony_ci PMBUS_POUT_OP_WARN_LIMIT = 0x6A, 8362306a36Sopenharmony_ci PMBUS_PIN_OP_WARN_LIMIT = 0x6B, 8462306a36Sopenharmony_ci 8562306a36Sopenharmony_ci PMBUS_STATUS_BYTE = 0x78, 8662306a36Sopenharmony_ci PMBUS_STATUS_WORD = 0x79, 8762306a36Sopenharmony_ci PMBUS_STATUS_VOUT = 0x7A, 8862306a36Sopenharmony_ci PMBUS_STATUS_IOUT = 0x7B, 8962306a36Sopenharmony_ci PMBUS_STATUS_INPUT = 0x7C, 9062306a36Sopenharmony_ci PMBUS_STATUS_TEMPERATURE = 0x7D, 9162306a36Sopenharmony_ci PMBUS_STATUS_CML = 0x7E, 9262306a36Sopenharmony_ci PMBUS_STATUS_OTHER = 0x7F, 9362306a36Sopenharmony_ci PMBUS_STATUS_MFR_SPECIFIC = 0x80, 9462306a36Sopenharmony_ci PMBUS_STATUS_FAN_12 = 0x81, 9562306a36Sopenharmony_ci PMBUS_STATUS_FAN_34 = 0x82, 9662306a36Sopenharmony_ci 9762306a36Sopenharmony_ci PMBUS_READ_VIN = 0x88, 9862306a36Sopenharmony_ci PMBUS_READ_IIN = 0x89, 9962306a36Sopenharmony_ci PMBUS_READ_VCAP = 0x8A, 10062306a36Sopenharmony_ci PMBUS_READ_VOUT = 0x8B, 10162306a36Sopenharmony_ci PMBUS_READ_IOUT = 0x8C, 10262306a36Sopenharmony_ci PMBUS_READ_TEMPERATURE_1 = 0x8D, 10362306a36Sopenharmony_ci PMBUS_READ_TEMPERATURE_2 = 0x8E, 10462306a36Sopenharmony_ci PMBUS_READ_TEMPERATURE_3 = 0x8F, 10562306a36Sopenharmony_ci PMBUS_READ_FAN_SPEED_1 = 0x90, 10662306a36Sopenharmony_ci PMBUS_READ_FAN_SPEED_2 = 0x91, 10762306a36Sopenharmony_ci PMBUS_READ_FAN_SPEED_3 = 0x92, 10862306a36Sopenharmony_ci PMBUS_READ_FAN_SPEED_4 = 0x93, 10962306a36Sopenharmony_ci PMBUS_READ_DUTY_CYCLE = 0x94, 11062306a36Sopenharmony_ci PMBUS_READ_FREQUENCY = 0x95, 11162306a36Sopenharmony_ci PMBUS_READ_POUT = 0x96, 11262306a36Sopenharmony_ci PMBUS_READ_PIN = 0x97, 11362306a36Sopenharmony_ci 11462306a36Sopenharmony_ci PMBUS_REVISION = 0x98, 11562306a36Sopenharmony_ci PMBUS_MFR_ID = 0x99, 11662306a36Sopenharmony_ci PMBUS_MFR_MODEL = 0x9A, 11762306a36Sopenharmony_ci PMBUS_MFR_REVISION = 0x9B, 11862306a36Sopenharmony_ci PMBUS_MFR_LOCATION = 0x9C, 11962306a36Sopenharmony_ci PMBUS_MFR_DATE = 0x9D, 12062306a36Sopenharmony_ci PMBUS_MFR_SERIAL = 0x9E, 12162306a36Sopenharmony_ci 12262306a36Sopenharmony_ci PMBUS_MFR_VIN_MIN = 0xA0, 12362306a36Sopenharmony_ci PMBUS_MFR_VIN_MAX = 0xA1, 12462306a36Sopenharmony_ci PMBUS_MFR_IIN_MAX = 0xA2, 12562306a36Sopenharmony_ci PMBUS_MFR_PIN_MAX = 0xA3, 12662306a36Sopenharmony_ci PMBUS_MFR_VOUT_MIN = 0xA4, 12762306a36Sopenharmony_ci PMBUS_MFR_VOUT_MAX = 0xA5, 12862306a36Sopenharmony_ci PMBUS_MFR_IOUT_MAX = 0xA6, 12962306a36Sopenharmony_ci PMBUS_MFR_POUT_MAX = 0xA7, 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci PMBUS_IC_DEVICE_ID = 0xAD, 13262306a36Sopenharmony_ci PMBUS_IC_DEVICE_REV = 0xAE, 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_ci PMBUS_MFR_MAX_TEMP_1 = 0xC0, 13562306a36Sopenharmony_ci PMBUS_MFR_MAX_TEMP_2 = 0xC1, 13662306a36Sopenharmony_ci PMBUS_MFR_MAX_TEMP_3 = 0xC2, 13762306a36Sopenharmony_ci 13862306a36Sopenharmony_ci/* 13962306a36Sopenharmony_ci * Virtual registers. 14062306a36Sopenharmony_ci * Useful to support attributes which are not supported by standard PMBus 14162306a36Sopenharmony_ci * registers but exist as manufacturer specific registers on individual chips. 14262306a36Sopenharmony_ci * Must be mapped to real registers in device specific code. 14362306a36Sopenharmony_ci * 14462306a36Sopenharmony_ci * Semantics: 14562306a36Sopenharmony_ci * Virtual registers are all word size. 14662306a36Sopenharmony_ci * READ registers are read-only; writes are either ignored or return an error. 14762306a36Sopenharmony_ci * RESET registers are read/write. Reading reset registers returns zero 14862306a36Sopenharmony_ci * (used for detection), writing any value causes the associated history to be 14962306a36Sopenharmony_ci * reset. 15062306a36Sopenharmony_ci * Virtual registers have to be handled in device specific driver code. Chip 15162306a36Sopenharmony_ci * driver code returns non-negative register values if a virtual register is 15262306a36Sopenharmony_ci * supported, or a negative error code if not. The chip driver may return 15362306a36Sopenharmony_ci * -ENODATA or any other error code in this case, though an error code other 15462306a36Sopenharmony_ci * than -ENODATA is handled more efficiently and thus preferred. Either case, 15562306a36Sopenharmony_ci * the calling PMBus core code will abort if the chip driver returns an error 15662306a36Sopenharmony_ci * code when reading or writing virtual registers. 15762306a36Sopenharmony_ci */ 15862306a36Sopenharmony_ci PMBUS_VIRT_BASE = 0x100, 15962306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP_AVG, 16062306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP_MIN, 16162306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP_MAX, 16262306a36Sopenharmony_ci PMBUS_VIRT_RESET_TEMP_HISTORY, 16362306a36Sopenharmony_ci PMBUS_VIRT_READ_VIN_AVG, 16462306a36Sopenharmony_ci PMBUS_VIRT_READ_VIN_MIN, 16562306a36Sopenharmony_ci PMBUS_VIRT_READ_VIN_MAX, 16662306a36Sopenharmony_ci PMBUS_VIRT_RESET_VIN_HISTORY, 16762306a36Sopenharmony_ci PMBUS_VIRT_READ_IIN_AVG, 16862306a36Sopenharmony_ci PMBUS_VIRT_READ_IIN_MIN, 16962306a36Sopenharmony_ci PMBUS_VIRT_READ_IIN_MAX, 17062306a36Sopenharmony_ci PMBUS_VIRT_RESET_IIN_HISTORY, 17162306a36Sopenharmony_ci PMBUS_VIRT_READ_PIN_AVG, 17262306a36Sopenharmony_ci PMBUS_VIRT_READ_PIN_MIN, 17362306a36Sopenharmony_ci PMBUS_VIRT_READ_PIN_MAX, 17462306a36Sopenharmony_ci PMBUS_VIRT_RESET_PIN_HISTORY, 17562306a36Sopenharmony_ci PMBUS_VIRT_READ_POUT_AVG, 17662306a36Sopenharmony_ci PMBUS_VIRT_READ_POUT_MIN, 17762306a36Sopenharmony_ci PMBUS_VIRT_READ_POUT_MAX, 17862306a36Sopenharmony_ci PMBUS_VIRT_RESET_POUT_HISTORY, 17962306a36Sopenharmony_ci PMBUS_VIRT_READ_VOUT_AVG, 18062306a36Sopenharmony_ci PMBUS_VIRT_READ_VOUT_MIN, 18162306a36Sopenharmony_ci PMBUS_VIRT_READ_VOUT_MAX, 18262306a36Sopenharmony_ci PMBUS_VIRT_RESET_VOUT_HISTORY, 18362306a36Sopenharmony_ci PMBUS_VIRT_READ_IOUT_AVG, 18462306a36Sopenharmony_ci PMBUS_VIRT_READ_IOUT_MIN, 18562306a36Sopenharmony_ci PMBUS_VIRT_READ_IOUT_MAX, 18662306a36Sopenharmony_ci PMBUS_VIRT_RESET_IOUT_HISTORY, 18762306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP2_AVG, 18862306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP2_MIN, 18962306a36Sopenharmony_ci PMBUS_VIRT_READ_TEMP2_MAX, 19062306a36Sopenharmony_ci PMBUS_VIRT_RESET_TEMP2_HISTORY, 19162306a36Sopenharmony_ci 19262306a36Sopenharmony_ci PMBUS_VIRT_READ_VMON, 19362306a36Sopenharmony_ci PMBUS_VIRT_VMON_UV_WARN_LIMIT, 19462306a36Sopenharmony_ci PMBUS_VIRT_VMON_OV_WARN_LIMIT, 19562306a36Sopenharmony_ci PMBUS_VIRT_VMON_UV_FAULT_LIMIT, 19662306a36Sopenharmony_ci PMBUS_VIRT_VMON_OV_FAULT_LIMIT, 19762306a36Sopenharmony_ci PMBUS_VIRT_STATUS_VMON, 19862306a36Sopenharmony_ci 19962306a36Sopenharmony_ci /* 20062306a36Sopenharmony_ci * RPM and PWM Fan control 20162306a36Sopenharmony_ci * 20262306a36Sopenharmony_ci * Drivers wanting to expose PWM control must define the behaviour of 20362306a36Sopenharmony_ci * PMBUS_VIRT_PWM_[1-4] and PMBUS_VIRT_PWM_ENABLE_[1-4] in the 20462306a36Sopenharmony_ci * {read,write}_word_data callback. 20562306a36Sopenharmony_ci * 20662306a36Sopenharmony_ci * pmbus core provides a default implementation for 20762306a36Sopenharmony_ci * PMBUS_VIRT_FAN_TARGET_[1-4]. 20862306a36Sopenharmony_ci * 20962306a36Sopenharmony_ci * TARGET, PWM and PWM_ENABLE members must be defined sequentially; 21062306a36Sopenharmony_ci * pmbus core uses the difference between the provided register and 21162306a36Sopenharmony_ci * it's _1 counterpart to calculate the FAN/PWM ID. 21262306a36Sopenharmony_ci */ 21362306a36Sopenharmony_ci PMBUS_VIRT_FAN_TARGET_1, 21462306a36Sopenharmony_ci PMBUS_VIRT_FAN_TARGET_2, 21562306a36Sopenharmony_ci PMBUS_VIRT_FAN_TARGET_3, 21662306a36Sopenharmony_ci PMBUS_VIRT_FAN_TARGET_4, 21762306a36Sopenharmony_ci PMBUS_VIRT_PWM_1, 21862306a36Sopenharmony_ci PMBUS_VIRT_PWM_2, 21962306a36Sopenharmony_ci PMBUS_VIRT_PWM_3, 22062306a36Sopenharmony_ci PMBUS_VIRT_PWM_4, 22162306a36Sopenharmony_ci PMBUS_VIRT_PWM_ENABLE_1, 22262306a36Sopenharmony_ci PMBUS_VIRT_PWM_ENABLE_2, 22362306a36Sopenharmony_ci PMBUS_VIRT_PWM_ENABLE_3, 22462306a36Sopenharmony_ci PMBUS_VIRT_PWM_ENABLE_4, 22562306a36Sopenharmony_ci 22662306a36Sopenharmony_ci /* Samples for average 22762306a36Sopenharmony_ci * 22862306a36Sopenharmony_ci * Drivers wanting to expose functionality for changing the number of 22962306a36Sopenharmony_ci * samples used for average values should implement support in 23062306a36Sopenharmony_ci * {read,write}_word_data callback for either PMBUS_VIRT_SAMPLES if it 23162306a36Sopenharmony_ci * applies to all types of measurements, or any number of specific 23262306a36Sopenharmony_ci * PMBUS_VIRT_*_SAMPLES registers to allow for individual control. 23362306a36Sopenharmony_ci */ 23462306a36Sopenharmony_ci PMBUS_VIRT_SAMPLES, 23562306a36Sopenharmony_ci PMBUS_VIRT_IN_SAMPLES, 23662306a36Sopenharmony_ci PMBUS_VIRT_CURR_SAMPLES, 23762306a36Sopenharmony_ci PMBUS_VIRT_POWER_SAMPLES, 23862306a36Sopenharmony_ci PMBUS_VIRT_TEMP_SAMPLES, 23962306a36Sopenharmony_ci}; 24062306a36Sopenharmony_ci 24162306a36Sopenharmony_ci/* 24262306a36Sopenharmony_ci * OPERATION 24362306a36Sopenharmony_ci */ 24462306a36Sopenharmony_ci#define PB_OPERATION_CONTROL_ON BIT(7) 24562306a36Sopenharmony_ci 24662306a36Sopenharmony_ci/* 24762306a36Sopenharmony_ci * WRITE_PROTECT 24862306a36Sopenharmony_ci */ 24962306a36Sopenharmony_ci#define PB_WP_ALL BIT(7) /* all but WRITE_PROTECT */ 25062306a36Sopenharmony_ci#define PB_WP_OP BIT(6) /* all but WP, OPERATION, PAGE */ 25162306a36Sopenharmony_ci#define PB_WP_VOUT BIT(5) /* all but WP, OPERATION, PAGE, VOUT, ON_OFF */ 25262306a36Sopenharmony_ci 25362306a36Sopenharmony_ci#define PB_WP_ANY (PB_WP_ALL | PB_WP_OP | PB_WP_VOUT) 25462306a36Sopenharmony_ci 25562306a36Sopenharmony_ci/* 25662306a36Sopenharmony_ci * CAPABILITY 25762306a36Sopenharmony_ci */ 25862306a36Sopenharmony_ci#define PB_CAPABILITY_SMBALERT BIT(4) 25962306a36Sopenharmony_ci#define PB_CAPABILITY_ERROR_CHECK BIT(7) 26062306a36Sopenharmony_ci 26162306a36Sopenharmony_ci/* 26262306a36Sopenharmony_ci * VOUT_MODE 26362306a36Sopenharmony_ci */ 26462306a36Sopenharmony_ci#define PB_VOUT_MODE_MODE_MASK 0xe0 26562306a36Sopenharmony_ci#define PB_VOUT_MODE_PARAM_MASK 0x1f 26662306a36Sopenharmony_ci 26762306a36Sopenharmony_ci#define PB_VOUT_MODE_LINEAR 0x00 26862306a36Sopenharmony_ci#define PB_VOUT_MODE_VID 0x20 26962306a36Sopenharmony_ci#define PB_VOUT_MODE_DIRECT 0x40 27062306a36Sopenharmony_ci 27162306a36Sopenharmony_ci/* 27262306a36Sopenharmony_ci * Fan configuration 27362306a36Sopenharmony_ci */ 27462306a36Sopenharmony_ci#define PB_FAN_2_PULSE_MASK (BIT(0) | BIT(1)) 27562306a36Sopenharmony_ci#define PB_FAN_2_RPM BIT(2) 27662306a36Sopenharmony_ci#define PB_FAN_2_INSTALLED BIT(3) 27762306a36Sopenharmony_ci#define PB_FAN_1_PULSE_MASK (BIT(4) | BIT(5)) 27862306a36Sopenharmony_ci#define PB_FAN_1_RPM BIT(6) 27962306a36Sopenharmony_ci#define PB_FAN_1_INSTALLED BIT(7) 28062306a36Sopenharmony_ci 28162306a36Sopenharmony_cienum pmbus_fan_mode { percent = 0, rpm }; 28262306a36Sopenharmony_ci 28362306a36Sopenharmony_ci/* 28462306a36Sopenharmony_ci * STATUS_BYTE, STATUS_WORD (lower) 28562306a36Sopenharmony_ci */ 28662306a36Sopenharmony_ci#define PB_STATUS_NONE_ABOVE BIT(0) 28762306a36Sopenharmony_ci#define PB_STATUS_CML BIT(1) 28862306a36Sopenharmony_ci#define PB_STATUS_TEMPERATURE BIT(2) 28962306a36Sopenharmony_ci#define PB_STATUS_VIN_UV BIT(3) 29062306a36Sopenharmony_ci#define PB_STATUS_IOUT_OC BIT(4) 29162306a36Sopenharmony_ci#define PB_STATUS_VOUT_OV BIT(5) 29262306a36Sopenharmony_ci#define PB_STATUS_OFF BIT(6) 29362306a36Sopenharmony_ci#define PB_STATUS_BUSY BIT(7) 29462306a36Sopenharmony_ci 29562306a36Sopenharmony_ci/* 29662306a36Sopenharmony_ci * STATUS_WORD (upper) 29762306a36Sopenharmony_ci */ 29862306a36Sopenharmony_ci#define PB_STATUS_UNKNOWN BIT(8) 29962306a36Sopenharmony_ci#define PB_STATUS_OTHER BIT(9) 30062306a36Sopenharmony_ci#define PB_STATUS_FANS BIT(10) 30162306a36Sopenharmony_ci#define PB_STATUS_POWER_GOOD_N BIT(11) 30262306a36Sopenharmony_ci#define PB_STATUS_WORD_MFR BIT(12) 30362306a36Sopenharmony_ci#define PB_STATUS_INPUT BIT(13) 30462306a36Sopenharmony_ci#define PB_STATUS_IOUT_POUT BIT(14) 30562306a36Sopenharmony_ci#define PB_STATUS_VOUT BIT(15) 30662306a36Sopenharmony_ci 30762306a36Sopenharmony_ci/* 30862306a36Sopenharmony_ci * STATUS_IOUT 30962306a36Sopenharmony_ci */ 31062306a36Sopenharmony_ci#define PB_POUT_OP_WARNING BIT(0) 31162306a36Sopenharmony_ci#define PB_POUT_OP_FAULT BIT(1) 31262306a36Sopenharmony_ci#define PB_POWER_LIMITING BIT(2) 31362306a36Sopenharmony_ci#define PB_CURRENT_SHARE_FAULT BIT(3) 31462306a36Sopenharmony_ci#define PB_IOUT_UC_FAULT BIT(4) 31562306a36Sopenharmony_ci#define PB_IOUT_OC_WARNING BIT(5) 31662306a36Sopenharmony_ci#define PB_IOUT_OC_LV_FAULT BIT(6) 31762306a36Sopenharmony_ci#define PB_IOUT_OC_FAULT BIT(7) 31862306a36Sopenharmony_ci 31962306a36Sopenharmony_ci/* 32062306a36Sopenharmony_ci * STATUS_VOUT, STATUS_INPUT 32162306a36Sopenharmony_ci */ 32262306a36Sopenharmony_ci#define PB_VOLTAGE_VIN_OFF BIT(3) 32362306a36Sopenharmony_ci#define PB_VOLTAGE_UV_FAULT BIT(4) 32462306a36Sopenharmony_ci#define PB_VOLTAGE_UV_WARNING BIT(5) 32562306a36Sopenharmony_ci#define PB_VOLTAGE_OV_WARNING BIT(6) 32662306a36Sopenharmony_ci#define PB_VOLTAGE_OV_FAULT BIT(7) 32762306a36Sopenharmony_ci 32862306a36Sopenharmony_ci/* 32962306a36Sopenharmony_ci * STATUS_INPUT 33062306a36Sopenharmony_ci */ 33162306a36Sopenharmony_ci#define PB_PIN_OP_WARNING BIT(0) 33262306a36Sopenharmony_ci#define PB_IIN_OC_WARNING BIT(1) 33362306a36Sopenharmony_ci#define PB_IIN_OC_FAULT BIT(2) 33462306a36Sopenharmony_ci 33562306a36Sopenharmony_ci/* 33662306a36Sopenharmony_ci * STATUS_TEMPERATURE 33762306a36Sopenharmony_ci */ 33862306a36Sopenharmony_ci#define PB_TEMP_UT_FAULT BIT(4) 33962306a36Sopenharmony_ci#define PB_TEMP_UT_WARNING BIT(5) 34062306a36Sopenharmony_ci#define PB_TEMP_OT_WARNING BIT(6) 34162306a36Sopenharmony_ci#define PB_TEMP_OT_FAULT BIT(7) 34262306a36Sopenharmony_ci 34362306a36Sopenharmony_ci/* 34462306a36Sopenharmony_ci * STATUS_FAN 34562306a36Sopenharmony_ci */ 34662306a36Sopenharmony_ci#define PB_FAN_AIRFLOW_WARNING BIT(0) 34762306a36Sopenharmony_ci#define PB_FAN_AIRFLOW_FAULT BIT(1) 34862306a36Sopenharmony_ci#define PB_FAN_FAN2_SPEED_OVERRIDE BIT(2) 34962306a36Sopenharmony_ci#define PB_FAN_FAN1_SPEED_OVERRIDE BIT(3) 35062306a36Sopenharmony_ci#define PB_FAN_FAN2_WARNING BIT(4) 35162306a36Sopenharmony_ci#define PB_FAN_FAN1_WARNING BIT(5) 35262306a36Sopenharmony_ci#define PB_FAN_FAN2_FAULT BIT(6) 35362306a36Sopenharmony_ci#define PB_FAN_FAN1_FAULT BIT(7) 35462306a36Sopenharmony_ci 35562306a36Sopenharmony_ci/* 35662306a36Sopenharmony_ci * CML_FAULT_STATUS 35762306a36Sopenharmony_ci */ 35862306a36Sopenharmony_ci#define PB_CML_FAULT_OTHER_MEM_LOGIC BIT(0) 35962306a36Sopenharmony_ci#define PB_CML_FAULT_OTHER_COMM BIT(1) 36062306a36Sopenharmony_ci#define PB_CML_FAULT_PROCESSOR BIT(3) 36162306a36Sopenharmony_ci#define PB_CML_FAULT_MEMORY BIT(4) 36262306a36Sopenharmony_ci#define PB_CML_FAULT_PACKET_ERROR BIT(5) 36362306a36Sopenharmony_ci#define PB_CML_FAULT_INVALID_DATA BIT(6) 36462306a36Sopenharmony_ci#define PB_CML_FAULT_INVALID_COMMAND BIT(7) 36562306a36Sopenharmony_ci 36662306a36Sopenharmony_cienum pmbus_sensor_classes { 36762306a36Sopenharmony_ci PSC_VOLTAGE_IN = 0, 36862306a36Sopenharmony_ci PSC_VOLTAGE_OUT, 36962306a36Sopenharmony_ci PSC_CURRENT_IN, 37062306a36Sopenharmony_ci PSC_CURRENT_OUT, 37162306a36Sopenharmony_ci PSC_POWER, 37262306a36Sopenharmony_ci PSC_TEMPERATURE, 37362306a36Sopenharmony_ci PSC_FAN, 37462306a36Sopenharmony_ci PSC_PWM, 37562306a36Sopenharmony_ci PSC_NUM_CLASSES /* Number of power sensor classes */ 37662306a36Sopenharmony_ci}; 37762306a36Sopenharmony_ci 37862306a36Sopenharmony_ci#define PMBUS_PAGES 32 /* Per PMBus specification */ 37962306a36Sopenharmony_ci#define PMBUS_PHASES 10 /* Maximum number of phases per page */ 38062306a36Sopenharmony_ci 38162306a36Sopenharmony_ci/* Functionality bit mask */ 38262306a36Sopenharmony_ci#define PMBUS_HAVE_VIN BIT(0) 38362306a36Sopenharmony_ci#define PMBUS_HAVE_VCAP BIT(1) 38462306a36Sopenharmony_ci#define PMBUS_HAVE_VOUT BIT(2) 38562306a36Sopenharmony_ci#define PMBUS_HAVE_IIN BIT(3) 38662306a36Sopenharmony_ci#define PMBUS_HAVE_IOUT BIT(4) 38762306a36Sopenharmony_ci#define PMBUS_HAVE_PIN BIT(5) 38862306a36Sopenharmony_ci#define PMBUS_HAVE_POUT BIT(6) 38962306a36Sopenharmony_ci#define PMBUS_HAVE_FAN12 BIT(7) 39062306a36Sopenharmony_ci#define PMBUS_HAVE_FAN34 BIT(8) 39162306a36Sopenharmony_ci#define PMBUS_HAVE_TEMP BIT(9) 39262306a36Sopenharmony_ci#define PMBUS_HAVE_TEMP2 BIT(10) 39362306a36Sopenharmony_ci#define PMBUS_HAVE_TEMP3 BIT(11) 39462306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_VOUT BIT(12) 39562306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_IOUT BIT(13) 39662306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_INPUT BIT(14) 39762306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_TEMP BIT(15) 39862306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_FAN12 BIT(16) 39962306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_FAN34 BIT(17) 40062306a36Sopenharmony_ci#define PMBUS_HAVE_VMON BIT(18) 40162306a36Sopenharmony_ci#define PMBUS_HAVE_STATUS_VMON BIT(19) 40262306a36Sopenharmony_ci#define PMBUS_HAVE_PWM12 BIT(20) 40362306a36Sopenharmony_ci#define PMBUS_HAVE_PWM34 BIT(21) 40462306a36Sopenharmony_ci#define PMBUS_HAVE_SAMPLES BIT(22) 40562306a36Sopenharmony_ci 40662306a36Sopenharmony_ci#define PMBUS_PHASE_VIRTUAL BIT(30) /* Phases on this page are virtual */ 40762306a36Sopenharmony_ci#define PMBUS_PAGE_VIRTUAL BIT(31) /* Page is virtual */ 40862306a36Sopenharmony_ci 40962306a36Sopenharmony_cienum pmbus_data_format { linear = 0, ieee754, direct, vid }; 41062306a36Sopenharmony_cienum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv }; 41162306a36Sopenharmony_ci 41262306a36Sopenharmony_cistruct pmbus_driver_info { 41362306a36Sopenharmony_ci int pages; /* Total number of pages */ 41462306a36Sopenharmony_ci u8 phases[PMBUS_PAGES]; /* Number of phases per page */ 41562306a36Sopenharmony_ci enum pmbus_data_format format[PSC_NUM_CLASSES]; 41662306a36Sopenharmony_ci enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */ 41762306a36Sopenharmony_ci /* 41862306a36Sopenharmony_ci * Support one set of coefficients for each sensor type 41962306a36Sopenharmony_ci * Used for chips providing data in direct mode. 42062306a36Sopenharmony_ci */ 42162306a36Sopenharmony_ci int m[PSC_NUM_CLASSES]; /* mantissa for direct data format */ 42262306a36Sopenharmony_ci int b[PSC_NUM_CLASSES]; /* offset */ 42362306a36Sopenharmony_ci int R[PSC_NUM_CLASSES]; /* exponent */ 42462306a36Sopenharmony_ci 42562306a36Sopenharmony_ci u32 func[PMBUS_PAGES]; /* Functionality, per page */ 42662306a36Sopenharmony_ci u32 pfunc[PMBUS_PHASES];/* Functionality, per phase */ 42762306a36Sopenharmony_ci /* 42862306a36Sopenharmony_ci * The following functions map manufacturing specific register values 42962306a36Sopenharmony_ci * to PMBus standard register values. Specify only if mapping is 43062306a36Sopenharmony_ci * necessary. 43162306a36Sopenharmony_ci * Functions return the register value (read) or zero (write) if 43262306a36Sopenharmony_ci * successful. A return value of -ENODATA indicates that there is no 43362306a36Sopenharmony_ci * manufacturer specific register, but that a standard PMBus register 43462306a36Sopenharmony_ci * may exist. Any other negative return value indicates that the 43562306a36Sopenharmony_ci * register does not exist, and that no attempt should be made to read 43662306a36Sopenharmony_ci * the standard register. 43762306a36Sopenharmony_ci */ 43862306a36Sopenharmony_ci int (*read_byte_data)(struct i2c_client *client, int page, int reg); 43962306a36Sopenharmony_ci int (*read_word_data)(struct i2c_client *client, int page, int phase, 44062306a36Sopenharmony_ci int reg); 44162306a36Sopenharmony_ci int (*write_byte_data)(struct i2c_client *client, int page, int reg, 44262306a36Sopenharmony_ci u8 byte); 44362306a36Sopenharmony_ci int (*write_word_data)(struct i2c_client *client, int page, int reg, 44462306a36Sopenharmony_ci u16 word); 44562306a36Sopenharmony_ci int (*write_byte)(struct i2c_client *client, int page, u8 value); 44662306a36Sopenharmony_ci /* 44762306a36Sopenharmony_ci * The identify function determines supported PMBus functionality. 44862306a36Sopenharmony_ci * This function is only necessary if a chip driver supports multiple 44962306a36Sopenharmony_ci * chips, and the chip functionality is not pre-determined. 45062306a36Sopenharmony_ci */ 45162306a36Sopenharmony_ci int (*identify)(struct i2c_client *client, 45262306a36Sopenharmony_ci struct pmbus_driver_info *info); 45362306a36Sopenharmony_ci 45462306a36Sopenharmony_ci /* Regulator functionality, if supported by this chip driver. */ 45562306a36Sopenharmony_ci int num_regulators; 45662306a36Sopenharmony_ci const struct regulator_desc *reg_desc; 45762306a36Sopenharmony_ci 45862306a36Sopenharmony_ci /* custom attributes */ 45962306a36Sopenharmony_ci const struct attribute_group **groups; 46062306a36Sopenharmony_ci}; 46162306a36Sopenharmony_ci 46262306a36Sopenharmony_ci/* Regulator ops */ 46362306a36Sopenharmony_ci 46462306a36Sopenharmony_ciextern const struct regulator_ops pmbus_regulator_ops; 46562306a36Sopenharmony_ci 46662306a36Sopenharmony_ci/* Macros for filling in array of struct regulator_desc */ 46762306a36Sopenharmony_ci#define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step, _min_uV) \ 46862306a36Sopenharmony_ci [_id] = { \ 46962306a36Sopenharmony_ci .name = (_name # _id), \ 47062306a36Sopenharmony_ci .id = (_id), \ 47162306a36Sopenharmony_ci .of_match = of_match_ptr(_name # _id), \ 47262306a36Sopenharmony_ci .regulators_node = of_match_ptr("regulators"), \ 47362306a36Sopenharmony_ci .ops = &pmbus_regulator_ops, \ 47462306a36Sopenharmony_ci .type = REGULATOR_VOLTAGE, \ 47562306a36Sopenharmony_ci .owner = THIS_MODULE, \ 47662306a36Sopenharmony_ci .n_voltages = _voltages, \ 47762306a36Sopenharmony_ci .uV_step = _step, \ 47862306a36Sopenharmony_ci .min_uV = _min_uV, \ 47962306a36Sopenharmony_ci } 48062306a36Sopenharmony_ci 48162306a36Sopenharmony_ci#define PMBUS_REGULATOR(_name, _id) PMBUS_REGULATOR_STEP(_name, _id, 0, 0, 0) 48262306a36Sopenharmony_ci 48362306a36Sopenharmony_ci/* Function declarations */ 48462306a36Sopenharmony_ci 48562306a36Sopenharmony_civoid pmbus_clear_cache(struct i2c_client *client); 48662306a36Sopenharmony_civoid pmbus_set_update(struct i2c_client *client, u8 reg, bool update); 48762306a36Sopenharmony_ciint pmbus_set_page(struct i2c_client *client, int page, int phase); 48862306a36Sopenharmony_ciint pmbus_read_word_data(struct i2c_client *client, int page, int phase, 48962306a36Sopenharmony_ci u8 reg); 49062306a36Sopenharmony_ciint pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, 49162306a36Sopenharmony_ci u16 word); 49262306a36Sopenharmony_ciint pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg); 49362306a36Sopenharmony_ciint pmbus_write_byte(struct i2c_client *client, int page, u8 value); 49462306a36Sopenharmony_ciint pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, 49562306a36Sopenharmony_ci u8 value); 49662306a36Sopenharmony_ciint pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg, 49762306a36Sopenharmony_ci u8 mask, u8 value); 49862306a36Sopenharmony_civoid pmbus_clear_faults(struct i2c_client *client); 49962306a36Sopenharmony_cibool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); 50062306a36Sopenharmony_cibool pmbus_check_word_register(struct i2c_client *client, int page, int reg); 50162306a36Sopenharmony_ciint pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info); 50262306a36Sopenharmony_ciconst struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client 50362306a36Sopenharmony_ci *client); 50462306a36Sopenharmony_ciint pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id, 50562306a36Sopenharmony_ci enum pmbus_fan_mode mode); 50662306a36Sopenharmony_ciint pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id, 50762306a36Sopenharmony_ci enum pmbus_fan_mode mode); 50862306a36Sopenharmony_ciint pmbus_lock_interruptible(struct i2c_client *client); 50962306a36Sopenharmony_civoid pmbus_unlock(struct i2c_client *client); 51062306a36Sopenharmony_ciint pmbus_update_fan(struct i2c_client *client, int page, int id, 51162306a36Sopenharmony_ci u8 config, u8 mask, u16 command); 51262306a36Sopenharmony_cistruct dentry *pmbus_get_debugfs_dir(struct i2c_client *client); 51362306a36Sopenharmony_ci 51462306a36Sopenharmony_ci#endif /* PMBUS_H */ 515