174ba9207SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */ 29d2ecfb7SGuenter Roeck /* 39d2ecfb7SGuenter Roeck * pmbus.h - Common defines and structures for PMBus devices 49d2ecfb7SGuenter Roeck * 59d2ecfb7SGuenter Roeck * Copyright (c) 2010, 2011 Ericsson AB. 6aebcbbfcSGuenter Roeck * Copyright (c) 2012 Guenter Roeck 79d2ecfb7SGuenter Roeck */ 89d2ecfb7SGuenter Roeck 99d2ecfb7SGuenter Roeck #ifndef PMBUS_H 109d2ecfb7SGuenter Roeck #define PMBUS_H 119d2ecfb7SGuenter Roeck 122c052d42SGuenter Roeck #include <linux/bitops.h> 132c052d42SGuenter Roeck #include <linux/regulator/driver.h> 142c052d42SGuenter Roeck 159d2ecfb7SGuenter Roeck /* 169d2ecfb7SGuenter Roeck * Registers 179d2ecfb7SGuenter Roeck */ 182238835cSGuenter Roeck enum pmbus_regs { 192238835cSGuenter Roeck PMBUS_PAGE = 0x00, 202238835cSGuenter Roeck PMBUS_OPERATION = 0x01, 212238835cSGuenter Roeck PMBUS_ON_OFF_CONFIG = 0x02, 222238835cSGuenter Roeck PMBUS_CLEAR_FAULTS = 0x03, 232238835cSGuenter Roeck PMBUS_PHASE = 0x04, 249d2ecfb7SGuenter Roeck 259e347728SGuenter Roeck PMBUS_WRITE_PROTECT = 0x10, 269e347728SGuenter Roeck 272238835cSGuenter Roeck PMBUS_CAPABILITY = 0x19, 282238835cSGuenter Roeck PMBUS_QUERY = 0x1A, 29221819caSPatrick Rudolph PMBUS_SMBALERT_MASK = 0x1B, 302238835cSGuenter Roeck PMBUS_VOUT_MODE = 0x20, 312238835cSGuenter Roeck PMBUS_VOUT_COMMAND = 0x21, 322238835cSGuenter Roeck PMBUS_VOUT_TRIM = 0x22, 332238835cSGuenter Roeck PMBUS_VOUT_CAL_OFFSET = 0x23, 342238835cSGuenter Roeck PMBUS_VOUT_MAX = 0x24, 352238835cSGuenter Roeck PMBUS_VOUT_MARGIN_HIGH = 0x25, 362238835cSGuenter Roeck PMBUS_VOUT_MARGIN_LOW = 0x26, 372238835cSGuenter Roeck PMBUS_VOUT_TRANSITION_RATE = 0x27, 382238835cSGuenter Roeck PMBUS_VOUT_DROOP = 0x28, 392238835cSGuenter Roeck PMBUS_VOUT_SCALE_LOOP = 0x29, 402238835cSGuenter Roeck PMBUS_VOUT_SCALE_MONITOR = 0x2A, 419d2ecfb7SGuenter Roeck 422238835cSGuenter Roeck PMBUS_COEFFICIENTS = 0x30, 432238835cSGuenter Roeck PMBUS_POUT_MAX = 0x31, 449d2ecfb7SGuenter Roeck 452238835cSGuenter Roeck PMBUS_FAN_CONFIG_12 = 0x3A, 462238835cSGuenter Roeck PMBUS_FAN_COMMAND_1 = 0x3B, 472238835cSGuenter Roeck PMBUS_FAN_COMMAND_2 = 0x3C, 482238835cSGuenter Roeck PMBUS_FAN_CONFIG_34 = 0x3D, 492238835cSGuenter Roeck PMBUS_FAN_COMMAND_3 = 0x3E, 502238835cSGuenter Roeck PMBUS_FAN_COMMAND_4 = 0x3F, 519d2ecfb7SGuenter Roeck 522238835cSGuenter Roeck PMBUS_VOUT_OV_FAULT_LIMIT = 0x40, 532238835cSGuenter Roeck PMBUS_VOUT_OV_FAULT_RESPONSE = 0x41, 542238835cSGuenter Roeck PMBUS_VOUT_OV_WARN_LIMIT = 0x42, 552238835cSGuenter Roeck PMBUS_VOUT_UV_WARN_LIMIT = 0x43, 562238835cSGuenter Roeck PMBUS_VOUT_UV_FAULT_LIMIT = 0x44, 572238835cSGuenter Roeck PMBUS_VOUT_UV_FAULT_RESPONSE = 0x45, 582238835cSGuenter Roeck PMBUS_IOUT_OC_FAULT_LIMIT = 0x46, 592238835cSGuenter Roeck PMBUS_IOUT_OC_FAULT_RESPONSE = 0x47, 602238835cSGuenter Roeck PMBUS_IOUT_OC_LV_FAULT_LIMIT = 0x48, 612238835cSGuenter Roeck PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49, 622238835cSGuenter Roeck PMBUS_IOUT_OC_WARN_LIMIT = 0x4A, 632238835cSGuenter Roeck PMBUS_IOUT_UC_FAULT_LIMIT = 0x4B, 642238835cSGuenter Roeck PMBUS_IOUT_UC_FAULT_RESPONSE = 0x4C, 659d2ecfb7SGuenter Roeck 662238835cSGuenter Roeck PMBUS_OT_FAULT_LIMIT = 0x4F, 672238835cSGuenter Roeck PMBUS_OT_FAULT_RESPONSE = 0x50, 682238835cSGuenter Roeck PMBUS_OT_WARN_LIMIT = 0x51, 692238835cSGuenter Roeck PMBUS_UT_WARN_LIMIT = 0x52, 702238835cSGuenter Roeck PMBUS_UT_FAULT_LIMIT = 0x53, 712238835cSGuenter Roeck PMBUS_UT_FAULT_RESPONSE = 0x54, 722238835cSGuenter Roeck PMBUS_VIN_OV_FAULT_LIMIT = 0x55, 732238835cSGuenter Roeck PMBUS_VIN_OV_FAULT_RESPONSE = 0x56, 742238835cSGuenter Roeck PMBUS_VIN_OV_WARN_LIMIT = 0x57, 752238835cSGuenter Roeck PMBUS_VIN_UV_WARN_LIMIT = 0x58, 762238835cSGuenter Roeck PMBUS_VIN_UV_FAULT_LIMIT = 0x59, 779d2ecfb7SGuenter Roeck 782238835cSGuenter Roeck PMBUS_IIN_OC_FAULT_LIMIT = 0x5B, 792238835cSGuenter Roeck PMBUS_IIN_OC_WARN_LIMIT = 0x5D, 809d2ecfb7SGuenter Roeck 812238835cSGuenter Roeck PMBUS_POUT_OP_FAULT_LIMIT = 0x68, 822238835cSGuenter Roeck PMBUS_POUT_OP_WARN_LIMIT = 0x6A, 832238835cSGuenter Roeck PMBUS_PIN_OP_WARN_LIMIT = 0x6B, 849d2ecfb7SGuenter Roeck 852238835cSGuenter Roeck PMBUS_STATUS_BYTE = 0x78, 862238835cSGuenter Roeck PMBUS_STATUS_WORD = 0x79, 872238835cSGuenter Roeck PMBUS_STATUS_VOUT = 0x7A, 882238835cSGuenter Roeck PMBUS_STATUS_IOUT = 0x7B, 892238835cSGuenter Roeck PMBUS_STATUS_INPUT = 0x7C, 902238835cSGuenter Roeck PMBUS_STATUS_TEMPERATURE = 0x7D, 912238835cSGuenter Roeck PMBUS_STATUS_CML = 0x7E, 922238835cSGuenter Roeck PMBUS_STATUS_OTHER = 0x7F, 932238835cSGuenter Roeck PMBUS_STATUS_MFR_SPECIFIC = 0x80, 942238835cSGuenter Roeck PMBUS_STATUS_FAN_12 = 0x81, 952238835cSGuenter Roeck PMBUS_STATUS_FAN_34 = 0x82, 969d2ecfb7SGuenter Roeck 972238835cSGuenter Roeck PMBUS_READ_VIN = 0x88, 982238835cSGuenter Roeck PMBUS_READ_IIN = 0x89, 992238835cSGuenter Roeck PMBUS_READ_VCAP = 0x8A, 1002238835cSGuenter Roeck PMBUS_READ_VOUT = 0x8B, 1012238835cSGuenter Roeck PMBUS_READ_IOUT = 0x8C, 1022238835cSGuenter Roeck PMBUS_READ_TEMPERATURE_1 = 0x8D, 1032238835cSGuenter Roeck PMBUS_READ_TEMPERATURE_2 = 0x8E, 1042238835cSGuenter Roeck PMBUS_READ_TEMPERATURE_3 = 0x8F, 1052238835cSGuenter Roeck PMBUS_READ_FAN_SPEED_1 = 0x90, 1062238835cSGuenter Roeck PMBUS_READ_FAN_SPEED_2 = 0x91, 1072238835cSGuenter Roeck PMBUS_READ_FAN_SPEED_3 = 0x92, 1082238835cSGuenter Roeck PMBUS_READ_FAN_SPEED_4 = 0x93, 1092238835cSGuenter Roeck PMBUS_READ_DUTY_CYCLE = 0x94, 1102238835cSGuenter Roeck PMBUS_READ_FREQUENCY = 0x95, 1112238835cSGuenter Roeck PMBUS_READ_POUT = 0x96, 1122238835cSGuenter Roeck PMBUS_READ_PIN = 0x97, 1139d2ecfb7SGuenter Roeck 1142238835cSGuenter Roeck PMBUS_REVISION = 0x98, 1152238835cSGuenter Roeck PMBUS_MFR_ID = 0x99, 1162238835cSGuenter Roeck PMBUS_MFR_MODEL = 0x9A, 1172238835cSGuenter Roeck PMBUS_MFR_REVISION = 0x9B, 1182238835cSGuenter Roeck PMBUS_MFR_LOCATION = 0x9C, 1192238835cSGuenter Roeck PMBUS_MFR_DATE = 0x9D, 1202238835cSGuenter Roeck PMBUS_MFR_SERIAL = 0x9E, 1219d2ecfb7SGuenter Roeck 122787c095eSZbigniew Lukwinski PMBUS_MFR_VIN_MIN = 0xA0, 123787c095eSZbigniew Lukwinski PMBUS_MFR_VIN_MAX = 0xA1, 124787c095eSZbigniew Lukwinski PMBUS_MFR_IIN_MAX = 0xA2, 125787c095eSZbigniew Lukwinski PMBUS_MFR_PIN_MAX = 0xA3, 126787c095eSZbigniew Lukwinski PMBUS_MFR_VOUT_MIN = 0xA4, 127787c095eSZbigniew Lukwinski PMBUS_MFR_VOUT_MAX = 0xA5, 128787c095eSZbigniew Lukwinski PMBUS_MFR_IOUT_MAX = 0xA6, 129787c095eSZbigniew Lukwinski PMBUS_MFR_POUT_MAX = 0xA7, 130787c095eSZbigniew Lukwinski 131a1dd176cSGuenter Roeck PMBUS_IC_DEVICE_ID = 0xAD, 132a1dd176cSGuenter Roeck PMBUS_IC_DEVICE_REV = 0xAE, 133a1dd176cSGuenter Roeck 134787c095eSZbigniew Lukwinski PMBUS_MFR_MAX_TEMP_1 = 0xC0, 135787c095eSZbigniew Lukwinski PMBUS_MFR_MAX_TEMP_2 = 0xC1, 136787c095eSZbigniew Lukwinski PMBUS_MFR_MAX_TEMP_3 = 0xC2, 137787c095eSZbigniew Lukwinski 1389d2ecfb7SGuenter Roeck /* 1396f183d33SGuenter Roeck * Virtual registers. 1406f183d33SGuenter Roeck * Useful to support attributes which are not supported by standard PMBus 1416f183d33SGuenter Roeck * registers but exist as manufacturer specific registers on individual chips. 1426f183d33SGuenter Roeck * Must be mapped to real registers in device specific code. 1436f183d33SGuenter Roeck * 1446f183d33SGuenter Roeck * Semantics: 1456f183d33SGuenter Roeck * Virtual registers are all word size. 1466f183d33SGuenter Roeck * READ registers are read-only; writes are either ignored or return an error. 14720fcfe17SGuenter Roeck * RESET registers are read/write. Reading reset registers returns zero 14820fcfe17SGuenter Roeck * (used for detection), writing any value causes the associated history to be 14920fcfe17SGuenter Roeck * reset. 15020fcfe17SGuenter Roeck * Virtual registers have to be handled in device specific driver code. Chip 15120fcfe17SGuenter Roeck * driver code returns non-negative register values if a virtual register is 15220fcfe17SGuenter Roeck * supported, or a negative error code if not. The chip driver may return 15320fcfe17SGuenter Roeck * -ENODATA or any other error code in this case, though an error code other 15420fcfe17SGuenter Roeck * than -ENODATA is handled more efficiently and thus preferred. Either case, 15520fcfe17SGuenter Roeck * the calling PMBus core code will abort if the chip driver returns an error 15620fcfe17SGuenter Roeck * code when reading or writing virtual registers. 1576f183d33SGuenter Roeck */ 1582238835cSGuenter Roeck PMBUS_VIRT_BASE = 0x100, 1592238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP_AVG, 1602238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP_MIN, 1612238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP_MAX, 1622238835cSGuenter Roeck PMBUS_VIRT_RESET_TEMP_HISTORY, 1632238835cSGuenter Roeck PMBUS_VIRT_READ_VIN_AVG, 1642238835cSGuenter Roeck PMBUS_VIRT_READ_VIN_MIN, 1652238835cSGuenter Roeck PMBUS_VIRT_READ_VIN_MAX, 1662238835cSGuenter Roeck PMBUS_VIRT_RESET_VIN_HISTORY, 1672238835cSGuenter Roeck PMBUS_VIRT_READ_IIN_AVG, 1682238835cSGuenter Roeck PMBUS_VIRT_READ_IIN_MIN, 1692238835cSGuenter Roeck PMBUS_VIRT_READ_IIN_MAX, 1702238835cSGuenter Roeck PMBUS_VIRT_RESET_IIN_HISTORY, 1712238835cSGuenter Roeck PMBUS_VIRT_READ_PIN_AVG, 1722238835cSGuenter Roeck PMBUS_VIRT_READ_PIN_MIN, 1732238835cSGuenter Roeck PMBUS_VIRT_READ_PIN_MAX, 1742238835cSGuenter Roeck PMBUS_VIRT_RESET_PIN_HISTORY, 1752238835cSGuenter Roeck PMBUS_VIRT_READ_POUT_AVG, 1762238835cSGuenter Roeck PMBUS_VIRT_READ_POUT_MIN, 1772238835cSGuenter Roeck PMBUS_VIRT_READ_POUT_MAX, 1782238835cSGuenter Roeck PMBUS_VIRT_RESET_POUT_HISTORY, 1792238835cSGuenter Roeck PMBUS_VIRT_READ_VOUT_AVG, 1802238835cSGuenter Roeck PMBUS_VIRT_READ_VOUT_MIN, 1812238835cSGuenter Roeck PMBUS_VIRT_READ_VOUT_MAX, 1822238835cSGuenter Roeck PMBUS_VIRT_RESET_VOUT_HISTORY, 1832238835cSGuenter Roeck PMBUS_VIRT_READ_IOUT_AVG, 1842238835cSGuenter Roeck PMBUS_VIRT_READ_IOUT_MIN, 1852238835cSGuenter Roeck PMBUS_VIRT_READ_IOUT_MAX, 1862238835cSGuenter Roeck PMBUS_VIRT_RESET_IOUT_HISTORY, 1872238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP2_AVG, 1882238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP2_MIN, 1892238835cSGuenter Roeck PMBUS_VIRT_READ_TEMP2_MAX, 1902238835cSGuenter Roeck PMBUS_VIRT_RESET_TEMP2_HISTORY, 1916f183d33SGuenter Roeck 1922238835cSGuenter Roeck PMBUS_VIRT_READ_VMON, 1932238835cSGuenter Roeck PMBUS_VIRT_VMON_UV_WARN_LIMIT, 1942238835cSGuenter Roeck PMBUS_VIRT_VMON_OV_WARN_LIMIT, 1952238835cSGuenter Roeck PMBUS_VIRT_VMON_UV_FAULT_LIMIT, 1962238835cSGuenter Roeck PMBUS_VIRT_VMON_OV_FAULT_LIMIT, 1972238835cSGuenter Roeck PMBUS_VIRT_STATUS_VMON, 198d206636eSAndrew Jeffery 199d206636eSAndrew Jeffery /* 200d206636eSAndrew Jeffery * RPM and PWM Fan control 201d206636eSAndrew Jeffery * 202d206636eSAndrew Jeffery * Drivers wanting to expose PWM control must define the behaviour of 203d206636eSAndrew Jeffery * PMBUS_VIRT_PWM_[1-4] and PMBUS_VIRT_PWM_ENABLE_[1-4] in the 204d206636eSAndrew Jeffery * {read,write}_word_data callback. 205d206636eSAndrew Jeffery * 206d206636eSAndrew Jeffery * pmbus core provides a default implementation for 207d206636eSAndrew Jeffery * PMBUS_VIRT_FAN_TARGET_[1-4]. 208d206636eSAndrew Jeffery * 209d206636eSAndrew Jeffery * TARGET, PWM and PWM_ENABLE members must be defined sequentially; 210d206636eSAndrew Jeffery * pmbus core uses the difference between the provided register and 211d206636eSAndrew Jeffery * it's _1 counterpart to calculate the FAN/PWM ID. 212d206636eSAndrew Jeffery */ 213d206636eSAndrew Jeffery PMBUS_VIRT_FAN_TARGET_1, 214d206636eSAndrew Jeffery PMBUS_VIRT_FAN_TARGET_2, 215d206636eSAndrew Jeffery PMBUS_VIRT_FAN_TARGET_3, 216d206636eSAndrew Jeffery PMBUS_VIRT_FAN_TARGET_4, 217d206636eSAndrew Jeffery PMBUS_VIRT_PWM_1, 218d206636eSAndrew Jeffery PMBUS_VIRT_PWM_2, 219d206636eSAndrew Jeffery PMBUS_VIRT_PWM_3, 220d206636eSAndrew Jeffery PMBUS_VIRT_PWM_4, 221d206636eSAndrew Jeffery PMBUS_VIRT_PWM_ENABLE_1, 222d206636eSAndrew Jeffery PMBUS_VIRT_PWM_ENABLE_2, 223d206636eSAndrew Jeffery PMBUS_VIRT_PWM_ENABLE_3, 224d206636eSAndrew Jeffery PMBUS_VIRT_PWM_ENABLE_4, 22549c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 22649c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) /* Samples for average 22749c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * 22849c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * Drivers wanting to expose functionality for changing the number of 22949c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * samples used for average values should implement support in 23049c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * {read,write}_word_data callback for either PMBUS_VIRT_SAMPLES if it 23149c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * applies to all types of measurements, or any number of specific 23249c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) * PMBUS_VIRT_*_SAMPLES registers to allow for individual control. 23349c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) */ 23449c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) PMBUS_VIRT_SAMPLES, 23549c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) PMBUS_VIRT_IN_SAMPLES, 23649c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) PMBUS_VIRT_CURR_SAMPLES, 23749c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) PMBUS_VIRT_POWER_SAMPLES, 23849c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) PMBUS_VIRT_TEMP_SAMPLES, 2392238835cSGuenter Roeck }; 240aebcbbfcSGuenter Roeck 2416f183d33SGuenter Roeck /* 242ddbb4db4SAlan Tull * OPERATION 243ddbb4db4SAlan Tull */ 2442c052d42SGuenter Roeck #define PB_OPERATION_CONTROL_ON BIT(7) 245ddbb4db4SAlan Tull 246ddbb4db4SAlan Tull /* 24705010fcfSPatrick Rudolph * ON_OFF_CONFIG 24805010fcfSPatrick Rudolph */ 24905010fcfSPatrick Rudolph #define PB_ON_OFF_CONFIG_POWERUP_CONTROL BIT(4) 25005010fcfSPatrick Rudolph #define PB_ON_OFF_CONFIG_OPERATION_REQ BIT(3) 25105010fcfSPatrick Rudolph #define PB_ON_OFF_CONFIG_EN_PIN_REQ BIT(2) 25205010fcfSPatrick Rudolph #define PB_ON_OFF_CONFIG_POLARITY_HIGH BIT(1) 25305010fcfSPatrick Rudolph #define PB_ON_OFF_CONFIG_TURN_OFF_FAST BIT(0) 25405010fcfSPatrick Rudolph 25505010fcfSPatrick Rudolph /* 2569e347728SGuenter Roeck * WRITE_PROTECT 2579e347728SGuenter Roeck */ 2589e347728SGuenter Roeck #define PB_WP_ALL BIT(7) /* all but WRITE_PROTECT */ 2599e347728SGuenter Roeck #define PB_WP_OP BIT(6) /* all but WP, OPERATION, PAGE */ 2609e347728SGuenter Roeck #define PB_WP_VOUT BIT(5) /* all but WP, OPERATION, PAGE, VOUT, ON_OFF */ 2619e347728SGuenter Roeck 2629e347728SGuenter Roeck #define PB_WP_ANY (PB_WP_ALL | PB_WP_OP | PB_WP_VOUT) 2639e347728SGuenter Roeck 2649e347728SGuenter Roeck /* 2659d2ecfb7SGuenter Roeck * CAPABILITY 2669d2ecfb7SGuenter Roeck */ 2672c052d42SGuenter Roeck #define PB_CAPABILITY_SMBALERT BIT(4) 2682c052d42SGuenter Roeck #define PB_CAPABILITY_ERROR_CHECK BIT(7) 2699d2ecfb7SGuenter Roeck 2709d2ecfb7SGuenter Roeck /* 2719d2ecfb7SGuenter Roeck * VOUT_MODE 2729d2ecfb7SGuenter Roeck */ 2739d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_MODE_MASK 0xe0 2749d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_PARAM_MASK 0x1f 2759d2ecfb7SGuenter Roeck 2769d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_LINEAR 0x00 2779d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_VID 0x20 2789d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_DIRECT 0x40 2799d2ecfb7SGuenter Roeck 2809d2ecfb7SGuenter Roeck /* 2819d2ecfb7SGuenter Roeck * Fan configuration 2829d2ecfb7SGuenter Roeck */ 2832c052d42SGuenter Roeck #define PB_FAN_2_PULSE_MASK (BIT(0) | BIT(1)) 2842c052d42SGuenter Roeck #define PB_FAN_2_RPM BIT(2) 2852c052d42SGuenter Roeck #define PB_FAN_2_INSTALLED BIT(3) 2862c052d42SGuenter Roeck #define PB_FAN_1_PULSE_MASK (BIT(4) | BIT(5)) 2872c052d42SGuenter Roeck #define PB_FAN_1_RPM BIT(6) 2882c052d42SGuenter Roeck #define PB_FAN_1_INSTALLED BIT(7) 2899d2ecfb7SGuenter Roeck 290d206636eSAndrew Jeffery enum pmbus_fan_mode { percent = 0, rpm }; 291d206636eSAndrew Jeffery 2929d2ecfb7SGuenter Roeck /* 2939d2ecfb7SGuenter Roeck * STATUS_BYTE, STATUS_WORD (lower) 2949d2ecfb7SGuenter Roeck */ 2952c052d42SGuenter Roeck #define PB_STATUS_NONE_ABOVE BIT(0) 2962c052d42SGuenter Roeck #define PB_STATUS_CML BIT(1) 2972c052d42SGuenter Roeck #define PB_STATUS_TEMPERATURE BIT(2) 2982c052d42SGuenter Roeck #define PB_STATUS_VIN_UV BIT(3) 2992c052d42SGuenter Roeck #define PB_STATUS_IOUT_OC BIT(4) 3002c052d42SGuenter Roeck #define PB_STATUS_VOUT_OV BIT(5) 3012c052d42SGuenter Roeck #define PB_STATUS_OFF BIT(6) 3022c052d42SGuenter Roeck #define PB_STATUS_BUSY BIT(7) 3039d2ecfb7SGuenter Roeck 3049d2ecfb7SGuenter Roeck /* 3059d2ecfb7SGuenter Roeck * STATUS_WORD (upper) 3069d2ecfb7SGuenter Roeck */ 3072c052d42SGuenter Roeck #define PB_STATUS_UNKNOWN BIT(8) 3082c052d42SGuenter Roeck #define PB_STATUS_OTHER BIT(9) 3092c052d42SGuenter Roeck #define PB_STATUS_FANS BIT(10) 3102c052d42SGuenter Roeck #define PB_STATUS_POWER_GOOD_N BIT(11) 3112c052d42SGuenter Roeck #define PB_STATUS_WORD_MFR BIT(12) 3122c052d42SGuenter Roeck #define PB_STATUS_INPUT BIT(13) 3132c052d42SGuenter Roeck #define PB_STATUS_IOUT_POUT BIT(14) 3142c052d42SGuenter Roeck #define PB_STATUS_VOUT BIT(15) 3159d2ecfb7SGuenter Roeck 3169d2ecfb7SGuenter Roeck /* 3179d2ecfb7SGuenter Roeck * STATUS_IOUT 3189d2ecfb7SGuenter Roeck */ 3192c052d42SGuenter Roeck #define PB_POUT_OP_WARNING BIT(0) 3202c052d42SGuenter Roeck #define PB_POUT_OP_FAULT BIT(1) 3212c052d42SGuenter Roeck #define PB_POWER_LIMITING BIT(2) 3222c052d42SGuenter Roeck #define PB_CURRENT_SHARE_FAULT BIT(3) 3232c052d42SGuenter Roeck #define PB_IOUT_UC_FAULT BIT(4) 3242c052d42SGuenter Roeck #define PB_IOUT_OC_WARNING BIT(5) 3252c052d42SGuenter Roeck #define PB_IOUT_OC_LV_FAULT BIT(6) 3262c052d42SGuenter Roeck #define PB_IOUT_OC_FAULT BIT(7) 3279d2ecfb7SGuenter Roeck 3289d2ecfb7SGuenter Roeck /* 3299d2ecfb7SGuenter Roeck * STATUS_VOUT, STATUS_INPUT 3309d2ecfb7SGuenter Roeck */ 331a5436af5SBrandon Wyman #define PB_VOLTAGE_VIN_OFF BIT(3) 3322c052d42SGuenter Roeck #define PB_VOLTAGE_UV_FAULT BIT(4) 3332c052d42SGuenter Roeck #define PB_VOLTAGE_UV_WARNING BIT(5) 3342c052d42SGuenter Roeck #define PB_VOLTAGE_OV_WARNING BIT(6) 3352c052d42SGuenter Roeck #define PB_VOLTAGE_OV_FAULT BIT(7) 3369d2ecfb7SGuenter Roeck 3379d2ecfb7SGuenter Roeck /* 3389d2ecfb7SGuenter Roeck * STATUS_INPUT 3399d2ecfb7SGuenter Roeck */ 3402c052d42SGuenter Roeck #define PB_PIN_OP_WARNING BIT(0) 3412c052d42SGuenter Roeck #define PB_IIN_OC_WARNING BIT(1) 3422c052d42SGuenter Roeck #define PB_IIN_OC_FAULT BIT(2) 3439d2ecfb7SGuenter Roeck 3449d2ecfb7SGuenter Roeck /* 3459d2ecfb7SGuenter Roeck * STATUS_TEMPERATURE 3469d2ecfb7SGuenter Roeck */ 3472c052d42SGuenter Roeck #define PB_TEMP_UT_FAULT BIT(4) 3482c052d42SGuenter Roeck #define PB_TEMP_UT_WARNING BIT(5) 3492c052d42SGuenter Roeck #define PB_TEMP_OT_WARNING BIT(6) 3502c052d42SGuenter Roeck #define PB_TEMP_OT_FAULT BIT(7) 3519d2ecfb7SGuenter Roeck 3529d2ecfb7SGuenter Roeck /* 3539d2ecfb7SGuenter Roeck * STATUS_FAN 3549d2ecfb7SGuenter Roeck */ 3552c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_WARNING BIT(0) 3562c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_FAULT BIT(1) 3572c052d42SGuenter Roeck #define PB_FAN_FAN2_SPEED_OVERRIDE BIT(2) 3582c052d42SGuenter Roeck #define PB_FAN_FAN1_SPEED_OVERRIDE BIT(3) 3592c052d42SGuenter Roeck #define PB_FAN_FAN2_WARNING BIT(4) 3602c052d42SGuenter Roeck #define PB_FAN_FAN1_WARNING BIT(5) 3612c052d42SGuenter Roeck #define PB_FAN_FAN2_FAULT BIT(6) 3622c052d42SGuenter Roeck #define PB_FAN_FAN1_FAULT BIT(7) 3639d2ecfb7SGuenter Roeck 3649d2ecfb7SGuenter Roeck /* 3659d2ecfb7SGuenter Roeck * CML_FAULT_STATUS 3669d2ecfb7SGuenter Roeck */ 3672c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_MEM_LOGIC BIT(0) 3682c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_COMM BIT(1) 3692c052d42SGuenter Roeck #define PB_CML_FAULT_PROCESSOR BIT(3) 3702c052d42SGuenter Roeck #define PB_CML_FAULT_MEMORY BIT(4) 3712c052d42SGuenter Roeck #define PB_CML_FAULT_PACKET_ERROR BIT(5) 3722c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_DATA BIT(6) 3732c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_COMMAND BIT(7) 3749d2ecfb7SGuenter Roeck 3759d2ecfb7SGuenter Roeck enum pmbus_sensor_classes { 3769d2ecfb7SGuenter Roeck PSC_VOLTAGE_IN = 0, 3779d2ecfb7SGuenter Roeck PSC_VOLTAGE_OUT, 3789d2ecfb7SGuenter Roeck PSC_CURRENT_IN, 3799d2ecfb7SGuenter Roeck PSC_CURRENT_OUT, 3809d2ecfb7SGuenter Roeck PSC_POWER, 3819d2ecfb7SGuenter Roeck PSC_TEMPERATURE, 3829d2ecfb7SGuenter Roeck PSC_FAN, 383d206636eSAndrew Jeffery PSC_PWM, 3849d2ecfb7SGuenter Roeck PSC_NUM_CLASSES /* Number of power sensor classes */ 3859d2ecfb7SGuenter Roeck }; 3869d2ecfb7SGuenter Roeck 3879d2ecfb7SGuenter Roeck #define PMBUS_PAGES 32 /* Per PMBus specification */ 3880c1acde1SVadim Pasternak #define PMBUS_PHASES 10 /* Maximum number of phases per page */ 3899d2ecfb7SGuenter Roeck 3909d2ecfb7SGuenter Roeck /* Functionality bit mask */ 3912c052d42SGuenter Roeck #define PMBUS_HAVE_VIN BIT(0) 3922c052d42SGuenter Roeck #define PMBUS_HAVE_VCAP BIT(1) 3932c052d42SGuenter Roeck #define PMBUS_HAVE_VOUT BIT(2) 3942c052d42SGuenter Roeck #define PMBUS_HAVE_IIN BIT(3) 3952c052d42SGuenter Roeck #define PMBUS_HAVE_IOUT BIT(4) 3962c052d42SGuenter Roeck #define PMBUS_HAVE_PIN BIT(5) 3972c052d42SGuenter Roeck #define PMBUS_HAVE_POUT BIT(6) 3982c052d42SGuenter Roeck #define PMBUS_HAVE_FAN12 BIT(7) 3992c052d42SGuenter Roeck #define PMBUS_HAVE_FAN34 BIT(8) 4002c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP BIT(9) 4012c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP2 BIT(10) 4022c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP3 BIT(11) 4032c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VOUT BIT(12) 4042c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_IOUT BIT(13) 4052c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_INPUT BIT(14) 4062c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_TEMP BIT(15) 4072c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN12 BIT(16) 4082c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN34 BIT(17) 4092c052d42SGuenter Roeck #define PMBUS_HAVE_VMON BIT(18) 4102c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VMON BIT(19) 411d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM12 BIT(20) 412d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM34 BIT(21) 41349c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) #define PMBUS_HAVE_SAMPLES BIT(22) 4149d2ecfb7SGuenter Roeck 41516358542SGuenter Roeck #define PMBUS_PHASE_VIRTUAL BIT(30) /* Phases on this page are virtual */ 41616358542SGuenter Roeck #define PMBUS_PAGE_VIRTUAL BIT(31) /* Page is virtual */ 417464df6faSAndrew Jeffery 4184036a48eSGuenter Roeck enum pmbus_data_format { linear = 0, ieee754, direct, vid }; 4199d72340bSVadim Pasternak enum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv }; 4201061d851SGuenter Roeck 4219d2ecfb7SGuenter Roeck struct pmbus_driver_info { 4229d2ecfb7SGuenter Roeck int pages; /* Total number of pages */ 42316358542SGuenter Roeck u8 phases[PMBUS_PAGES]; /* Number of phases per page */ 4241061d851SGuenter Roeck enum pmbus_data_format format[PSC_NUM_CLASSES]; 425b9fa0a3aSVadim Pasternak enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */ 4269d2ecfb7SGuenter Roeck /* 4279d2ecfb7SGuenter Roeck * Support one set of coefficients for each sensor type 4289d2ecfb7SGuenter Roeck * Used for chips providing data in direct mode. 4299d2ecfb7SGuenter Roeck */ 4309d2ecfb7SGuenter Roeck int m[PSC_NUM_CLASSES]; /* mantissa for direct data format */ 4319d2ecfb7SGuenter Roeck int b[PSC_NUM_CLASSES]; /* offset */ 4329d2ecfb7SGuenter Roeck int R[PSC_NUM_CLASSES]; /* exponent */ 4339d2ecfb7SGuenter Roeck 4349d2ecfb7SGuenter Roeck u32 func[PMBUS_PAGES]; /* Functionality, per page */ 43516358542SGuenter Roeck u32 pfunc[PMBUS_PHASES];/* Functionality, per phase */ 4369d2ecfb7SGuenter Roeck /* 4379d2ecfb7SGuenter Roeck * The following functions map manufacturing specific register values 4389d2ecfb7SGuenter Roeck * to PMBus standard register values. Specify only if mapping is 4399d2ecfb7SGuenter Roeck * necessary. 44020fcfe17SGuenter Roeck * Functions return the register value (read) or zero (write) if 44120fcfe17SGuenter Roeck * successful. A return value of -ENODATA indicates that there is no 44220fcfe17SGuenter Roeck * manufacturer specific register, but that a standard PMBus register 44320fcfe17SGuenter Roeck * may exist. Any other negative return value indicates that the 44420fcfe17SGuenter Roeck * register does not exist, and that no attempt should be made to read 44520fcfe17SGuenter Roeck * the standard register. 4469d2ecfb7SGuenter Roeck */ 4479d2ecfb7SGuenter Roeck int (*read_byte_data)(struct i2c_client *client, int page, int reg); 44843f33b6eSGuenter Roeck int (*read_word_data)(struct i2c_client *client, int page, int phase, 44943f33b6eSGuenter Roeck int reg); 4505de3e13fSMårten Lindahl int (*write_byte_data)(struct i2c_client *client, int page, int reg, 4515de3e13fSMårten Lindahl u8 byte); 45246243f3aSGuenter Roeck int (*write_word_data)(struct i2c_client *client, int page, int reg, 45346243f3aSGuenter Roeck u16 word); 454044cd3a5SGuenter Roeck int (*write_byte)(struct i2c_client *client, int page, u8 value); 4559d2ecfb7SGuenter Roeck /* 4569d2ecfb7SGuenter Roeck * The identify function determines supported PMBus functionality. 4579d2ecfb7SGuenter Roeck * This function is only necessary if a chip driver supports multiple 4589d2ecfb7SGuenter Roeck * chips, and the chip functionality is not pre-determined. 4599d2ecfb7SGuenter Roeck */ 4609d2ecfb7SGuenter Roeck int (*identify)(struct i2c_client *client, 4619d2ecfb7SGuenter Roeck struct pmbus_driver_info *info); 462ddbb4db4SAlan Tull 463ddbb4db4SAlan Tull /* Regulator functionality, if supported by this chip driver. */ 464ddbb4db4SAlan Tull int num_regulators; 465ddbb4db4SAlan Tull const struct regulator_desc *reg_desc; 466991d6799Skrzysztof.adamski@nokia.com 467991d6799Skrzysztof.adamski@nokia.com /* custom attributes */ 468991d6799Skrzysztof.adamski@nokia.com const struct attribute_group **groups; 4699d2ecfb7SGuenter Roeck }; 4709d2ecfb7SGuenter Roeck 471ddbb4db4SAlan Tull /* Regulator ops */ 472ddbb4db4SAlan Tull 473a07d7311SAxel Lin extern const struct regulator_ops pmbus_regulator_ops; 474ddbb4db4SAlan Tull 4754a235369SMårten Lindahl /* Macros for filling in array of struct regulator_desc */ 476b52acefcSSaravanan Sekar #define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step, _min_uV) \ 477ddbb4db4SAlan Tull [_id] = { \ 478ddbb4db4SAlan Tull .name = (_name # _id), \ 479ddbb4db4SAlan Tull .id = (_id), \ 480ddbb4db4SAlan Tull .of_match = of_match_ptr(_name # _id), \ 481ddbb4db4SAlan Tull .regulators_node = of_match_ptr("regulators"), \ 482ddbb4db4SAlan Tull .ops = &pmbus_regulator_ops, \ 4837b7a8b42SAxel Lin .type = REGULATOR_VOLTAGE, \ 484ddbb4db4SAlan Tull .owner = THIS_MODULE, \ 4854a235369SMårten Lindahl .n_voltages = _voltages, \ 4864a235369SMårten Lindahl .uV_step = _step, \ 487b52acefcSSaravanan Sekar .min_uV = _min_uV, \ 488ddbb4db4SAlan Tull } 489ddbb4db4SAlan Tull 490b52acefcSSaravanan Sekar #define PMBUS_REGULATOR(_name, _id) PMBUS_REGULATOR_STEP(_name, _id, 0, 0, 0) 4914a235369SMårten Lindahl 492*88b5970eSSaravanan Sekar #define PMBUS_REGULATOR_STEP_ONE(_name, _voltages, _step, _min_uV) \ 493*88b5970eSSaravanan Sekar { \ 494*88b5970eSSaravanan Sekar .name = (_name), \ 495*88b5970eSSaravanan Sekar .of_match = of_match_ptr(_name), \ 496*88b5970eSSaravanan Sekar .regulators_node = of_match_ptr("regulators"), \ 497*88b5970eSSaravanan Sekar .ops = &pmbus_regulator_ops, \ 498*88b5970eSSaravanan Sekar .type = REGULATOR_VOLTAGE, \ 499*88b5970eSSaravanan Sekar .owner = THIS_MODULE, \ 500*88b5970eSSaravanan Sekar .n_voltages = _voltages, \ 501*88b5970eSSaravanan Sekar .uV_step = _step, \ 502*88b5970eSSaravanan Sekar .min_uV = _min_uV, \ 503*88b5970eSSaravanan Sekar } 504*88b5970eSSaravanan Sekar 505*88b5970eSSaravanan Sekar #define PMBUS_REGULATOR_ONE(_name) PMBUS_REGULATOR_STEP_ONE(_name, 0, 0, 0) 506*88b5970eSSaravanan Sekar 5079d2ecfb7SGuenter Roeck /* Function declarations */ 5089d2ecfb7SGuenter Roeck 509ce603b18SGuenter Roeck void pmbus_clear_cache(struct i2c_client *client); 510d3e33067SErik Rosen void pmbus_set_update(struct i2c_client *client, u8 reg, bool update); 51143f33b6eSGuenter Roeck int pmbus_set_page(struct i2c_client *client, int page, int phase); 51243f33b6eSGuenter Roeck int pmbus_read_word_data(struct i2c_client *client, int page, int phase, 51343f33b6eSGuenter Roeck u8 reg); 51443f33b6eSGuenter Roeck int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, 51543f33b6eSGuenter Roeck u16 word); 5169c1ed894SGuenter Roeck int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg); 51703e9bd8dSGuenter Roeck int pmbus_write_byte(struct i2c_client *client, int page, u8 value); 51811c11998SAlan Tull int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg, 51911c11998SAlan Tull u8 value); 52011c11998SAlan Tull int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg, 52111c11998SAlan Tull u8 mask, u8 value); 5229d2ecfb7SGuenter Roeck void pmbus_clear_faults(struct i2c_client *client); 5239d2ecfb7SGuenter Roeck bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg); 5249d2ecfb7SGuenter Roeck bool pmbus_check_word_register(struct i2c_client *client, int page, int reg); 525dd431939SStephen Kitt int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info); 5269d2ecfb7SGuenter Roeck const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client 5279d2ecfb7SGuenter Roeck *client); 528d206636eSAndrew Jeffery int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id, 529d206636eSAndrew Jeffery enum pmbus_fan_mode mode); 530d206636eSAndrew Jeffery int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id, 531d206636eSAndrew Jeffery enum pmbus_fan_mode mode); 532a7ac3718SEddie James int pmbus_lock_interruptible(struct i2c_client *client); 533a7ac3718SEddie James void pmbus_unlock(struct i2c_client *client); 534d206636eSAndrew Jeffery int pmbus_update_fan(struct i2c_client *client, int page, int id, 535d206636eSAndrew Jeffery u8 config, u8 mask, u16 command); 536eb6489b6SEdward A. James struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client); 537eb6489b6SEdward A. James 5389d2ecfb7SGuenter Roeck #endif /* PMBUS_H */ 539