xref: /linux/drivers/hwmon/pmbus/pmbus.h (revision 74ba9207e1adf1966c57450340534ae9742d00af)
1*74ba9207SThomas 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 
252238835cSGuenter Roeck 	PMBUS_CAPABILITY		= 0x19,
262238835cSGuenter Roeck 	PMBUS_QUERY			= 0x1A,
279d2ecfb7SGuenter Roeck 
282238835cSGuenter Roeck 	PMBUS_VOUT_MODE			= 0x20,
292238835cSGuenter Roeck 	PMBUS_VOUT_COMMAND		= 0x21,
302238835cSGuenter Roeck 	PMBUS_VOUT_TRIM			= 0x22,
312238835cSGuenter Roeck 	PMBUS_VOUT_CAL_OFFSET		= 0x23,
322238835cSGuenter Roeck 	PMBUS_VOUT_MAX			= 0x24,
332238835cSGuenter Roeck 	PMBUS_VOUT_MARGIN_HIGH		= 0x25,
342238835cSGuenter Roeck 	PMBUS_VOUT_MARGIN_LOW		= 0x26,
352238835cSGuenter Roeck 	PMBUS_VOUT_TRANSITION_RATE	= 0x27,
362238835cSGuenter Roeck 	PMBUS_VOUT_DROOP		= 0x28,
372238835cSGuenter Roeck 	PMBUS_VOUT_SCALE_LOOP		= 0x29,
382238835cSGuenter Roeck 	PMBUS_VOUT_SCALE_MONITOR	= 0x2A,
399d2ecfb7SGuenter Roeck 
402238835cSGuenter Roeck 	PMBUS_COEFFICIENTS		= 0x30,
412238835cSGuenter Roeck 	PMBUS_POUT_MAX			= 0x31,
429d2ecfb7SGuenter Roeck 
432238835cSGuenter Roeck 	PMBUS_FAN_CONFIG_12		= 0x3A,
442238835cSGuenter Roeck 	PMBUS_FAN_COMMAND_1		= 0x3B,
452238835cSGuenter Roeck 	PMBUS_FAN_COMMAND_2		= 0x3C,
462238835cSGuenter Roeck 	PMBUS_FAN_CONFIG_34		= 0x3D,
472238835cSGuenter Roeck 	PMBUS_FAN_COMMAND_3		= 0x3E,
482238835cSGuenter Roeck 	PMBUS_FAN_COMMAND_4		= 0x3F,
499d2ecfb7SGuenter Roeck 
502238835cSGuenter Roeck 	PMBUS_VOUT_OV_FAULT_LIMIT	= 0x40,
512238835cSGuenter Roeck 	PMBUS_VOUT_OV_FAULT_RESPONSE	= 0x41,
522238835cSGuenter Roeck 	PMBUS_VOUT_OV_WARN_LIMIT	= 0x42,
532238835cSGuenter Roeck 	PMBUS_VOUT_UV_WARN_LIMIT	= 0x43,
542238835cSGuenter Roeck 	PMBUS_VOUT_UV_FAULT_LIMIT	= 0x44,
552238835cSGuenter Roeck 	PMBUS_VOUT_UV_FAULT_RESPONSE	= 0x45,
562238835cSGuenter Roeck 	PMBUS_IOUT_OC_FAULT_LIMIT	= 0x46,
572238835cSGuenter Roeck 	PMBUS_IOUT_OC_FAULT_RESPONSE	= 0x47,
582238835cSGuenter Roeck 	PMBUS_IOUT_OC_LV_FAULT_LIMIT	= 0x48,
592238835cSGuenter Roeck 	PMBUS_IOUT_OC_LV_FAULT_RESPONSE	= 0x49,
602238835cSGuenter Roeck 	PMBUS_IOUT_OC_WARN_LIMIT	= 0x4A,
612238835cSGuenter Roeck 	PMBUS_IOUT_UC_FAULT_LIMIT	= 0x4B,
622238835cSGuenter Roeck 	PMBUS_IOUT_UC_FAULT_RESPONSE	= 0x4C,
639d2ecfb7SGuenter Roeck 
642238835cSGuenter Roeck 	PMBUS_OT_FAULT_LIMIT		= 0x4F,
652238835cSGuenter Roeck 	PMBUS_OT_FAULT_RESPONSE		= 0x50,
662238835cSGuenter Roeck 	PMBUS_OT_WARN_LIMIT		= 0x51,
672238835cSGuenter Roeck 	PMBUS_UT_WARN_LIMIT		= 0x52,
682238835cSGuenter Roeck 	PMBUS_UT_FAULT_LIMIT		= 0x53,
692238835cSGuenter Roeck 	PMBUS_UT_FAULT_RESPONSE		= 0x54,
702238835cSGuenter Roeck 	PMBUS_VIN_OV_FAULT_LIMIT	= 0x55,
712238835cSGuenter Roeck 	PMBUS_VIN_OV_FAULT_RESPONSE	= 0x56,
722238835cSGuenter Roeck 	PMBUS_VIN_OV_WARN_LIMIT		= 0x57,
732238835cSGuenter Roeck 	PMBUS_VIN_UV_WARN_LIMIT		= 0x58,
742238835cSGuenter Roeck 	PMBUS_VIN_UV_FAULT_LIMIT	= 0x59,
759d2ecfb7SGuenter Roeck 
762238835cSGuenter Roeck 	PMBUS_IIN_OC_FAULT_LIMIT	= 0x5B,
772238835cSGuenter Roeck 	PMBUS_IIN_OC_WARN_LIMIT		= 0x5D,
789d2ecfb7SGuenter Roeck 
792238835cSGuenter Roeck 	PMBUS_POUT_OP_FAULT_LIMIT	= 0x68,
802238835cSGuenter Roeck 	PMBUS_POUT_OP_WARN_LIMIT	= 0x6A,
812238835cSGuenter Roeck 	PMBUS_PIN_OP_WARN_LIMIT		= 0x6B,
829d2ecfb7SGuenter Roeck 
832238835cSGuenter Roeck 	PMBUS_STATUS_BYTE		= 0x78,
842238835cSGuenter Roeck 	PMBUS_STATUS_WORD		= 0x79,
852238835cSGuenter Roeck 	PMBUS_STATUS_VOUT		= 0x7A,
862238835cSGuenter Roeck 	PMBUS_STATUS_IOUT		= 0x7B,
872238835cSGuenter Roeck 	PMBUS_STATUS_INPUT		= 0x7C,
882238835cSGuenter Roeck 	PMBUS_STATUS_TEMPERATURE	= 0x7D,
892238835cSGuenter Roeck 	PMBUS_STATUS_CML		= 0x7E,
902238835cSGuenter Roeck 	PMBUS_STATUS_OTHER		= 0x7F,
912238835cSGuenter Roeck 	PMBUS_STATUS_MFR_SPECIFIC	= 0x80,
922238835cSGuenter Roeck 	PMBUS_STATUS_FAN_12		= 0x81,
932238835cSGuenter Roeck 	PMBUS_STATUS_FAN_34		= 0x82,
949d2ecfb7SGuenter Roeck 
952238835cSGuenter Roeck 	PMBUS_READ_VIN			= 0x88,
962238835cSGuenter Roeck 	PMBUS_READ_IIN			= 0x89,
972238835cSGuenter Roeck 	PMBUS_READ_VCAP			= 0x8A,
982238835cSGuenter Roeck 	PMBUS_READ_VOUT			= 0x8B,
992238835cSGuenter Roeck 	PMBUS_READ_IOUT			= 0x8C,
1002238835cSGuenter Roeck 	PMBUS_READ_TEMPERATURE_1	= 0x8D,
1012238835cSGuenter Roeck 	PMBUS_READ_TEMPERATURE_2	= 0x8E,
1022238835cSGuenter Roeck 	PMBUS_READ_TEMPERATURE_3	= 0x8F,
1032238835cSGuenter Roeck 	PMBUS_READ_FAN_SPEED_1		= 0x90,
1042238835cSGuenter Roeck 	PMBUS_READ_FAN_SPEED_2		= 0x91,
1052238835cSGuenter Roeck 	PMBUS_READ_FAN_SPEED_3		= 0x92,
1062238835cSGuenter Roeck 	PMBUS_READ_FAN_SPEED_4		= 0x93,
1072238835cSGuenter Roeck 	PMBUS_READ_DUTY_CYCLE		= 0x94,
1082238835cSGuenter Roeck 	PMBUS_READ_FREQUENCY		= 0x95,
1092238835cSGuenter Roeck 	PMBUS_READ_POUT			= 0x96,
1102238835cSGuenter Roeck 	PMBUS_READ_PIN			= 0x97,
1119d2ecfb7SGuenter Roeck 
1122238835cSGuenter Roeck 	PMBUS_REVISION			= 0x98,
1132238835cSGuenter Roeck 	PMBUS_MFR_ID			= 0x99,
1142238835cSGuenter Roeck 	PMBUS_MFR_MODEL			= 0x9A,
1152238835cSGuenter Roeck 	PMBUS_MFR_REVISION		= 0x9B,
1162238835cSGuenter Roeck 	PMBUS_MFR_LOCATION		= 0x9C,
1172238835cSGuenter Roeck 	PMBUS_MFR_DATE			= 0x9D,
1182238835cSGuenter Roeck 	PMBUS_MFR_SERIAL		= 0x9E,
1199d2ecfb7SGuenter Roeck 
1209d2ecfb7SGuenter Roeck /*
1216f183d33SGuenter Roeck  * Virtual registers.
1226f183d33SGuenter Roeck  * Useful to support attributes which are not supported by standard PMBus
1236f183d33SGuenter Roeck  * registers but exist as manufacturer specific registers on individual chips.
1246f183d33SGuenter Roeck  * Must be mapped to real registers in device specific code.
1256f183d33SGuenter Roeck  *
1266f183d33SGuenter Roeck  * Semantics:
1276f183d33SGuenter Roeck  * Virtual registers are all word size.
1286f183d33SGuenter Roeck  * READ registers are read-only; writes are either ignored or return an error.
12920fcfe17SGuenter Roeck  * RESET registers are read/write. Reading reset registers returns zero
13020fcfe17SGuenter Roeck  * (used for detection), writing any value causes the associated history to be
13120fcfe17SGuenter Roeck  * reset.
13220fcfe17SGuenter Roeck  * Virtual registers have to be handled in device specific driver code. Chip
13320fcfe17SGuenter Roeck  * driver code returns non-negative register values if a virtual register is
13420fcfe17SGuenter Roeck  * supported, or a negative error code if not. The chip driver may return
13520fcfe17SGuenter Roeck  * -ENODATA or any other error code in this case, though an error code other
13620fcfe17SGuenter Roeck  * than -ENODATA is handled more efficiently and thus preferred. Either case,
13720fcfe17SGuenter Roeck  * the calling PMBus core code will abort if the chip driver returns an error
13820fcfe17SGuenter Roeck  * code when reading or writing virtual registers.
1396f183d33SGuenter Roeck  */
1402238835cSGuenter Roeck 	PMBUS_VIRT_BASE			= 0x100,
1412238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_AVG,
1422238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_MIN,
1432238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_MAX,
1442238835cSGuenter Roeck 	PMBUS_VIRT_RESET_TEMP_HISTORY,
1452238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_AVG,
1462238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_MIN,
1472238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_MAX,
1482238835cSGuenter Roeck 	PMBUS_VIRT_RESET_VIN_HISTORY,
1492238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_AVG,
1502238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_MIN,
1512238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_MAX,
1522238835cSGuenter Roeck 	PMBUS_VIRT_RESET_IIN_HISTORY,
1532238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_AVG,
1542238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_MIN,
1552238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_MAX,
1562238835cSGuenter Roeck 	PMBUS_VIRT_RESET_PIN_HISTORY,
1572238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_AVG,
1582238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_MIN,
1592238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_MAX,
1602238835cSGuenter Roeck 	PMBUS_VIRT_RESET_POUT_HISTORY,
1612238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_AVG,
1622238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_MIN,
1632238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_MAX,
1642238835cSGuenter Roeck 	PMBUS_VIRT_RESET_VOUT_HISTORY,
1652238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_AVG,
1662238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_MIN,
1672238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_MAX,
1682238835cSGuenter Roeck 	PMBUS_VIRT_RESET_IOUT_HISTORY,
1692238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_AVG,
1702238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_MIN,
1712238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_MAX,
1722238835cSGuenter Roeck 	PMBUS_VIRT_RESET_TEMP2_HISTORY,
1736f183d33SGuenter Roeck 
1742238835cSGuenter Roeck 	PMBUS_VIRT_READ_VMON,
1752238835cSGuenter Roeck 	PMBUS_VIRT_VMON_UV_WARN_LIMIT,
1762238835cSGuenter Roeck 	PMBUS_VIRT_VMON_OV_WARN_LIMIT,
1772238835cSGuenter Roeck 	PMBUS_VIRT_VMON_UV_FAULT_LIMIT,
1782238835cSGuenter Roeck 	PMBUS_VIRT_VMON_OV_FAULT_LIMIT,
1792238835cSGuenter Roeck 	PMBUS_VIRT_STATUS_VMON,
180d206636eSAndrew Jeffery 
181d206636eSAndrew Jeffery 	/*
182d206636eSAndrew Jeffery 	 * RPM and PWM Fan control
183d206636eSAndrew Jeffery 	 *
184d206636eSAndrew Jeffery 	 * Drivers wanting to expose PWM control must define the behaviour of
185d206636eSAndrew Jeffery 	 * PMBUS_VIRT_PWM_[1-4] and PMBUS_VIRT_PWM_ENABLE_[1-4] in the
186d206636eSAndrew Jeffery 	 * {read,write}_word_data callback.
187d206636eSAndrew Jeffery 	 *
188d206636eSAndrew Jeffery 	 * pmbus core provides a default implementation for
189d206636eSAndrew Jeffery 	 * PMBUS_VIRT_FAN_TARGET_[1-4].
190d206636eSAndrew Jeffery 	 *
191d206636eSAndrew Jeffery 	 * TARGET, PWM and PWM_ENABLE members must be defined sequentially;
192d206636eSAndrew Jeffery 	 * pmbus core uses the difference between the provided register and
193d206636eSAndrew Jeffery 	 * it's _1 counterpart to calculate the FAN/PWM ID.
194d206636eSAndrew Jeffery 	 */
195d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_1,
196d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_2,
197d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_3,
198d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_4,
199d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_1,
200d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_2,
201d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_3,
202d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_4,
203d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_1,
204d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_2,
205d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_3,
206d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_4,
20749c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 
20849c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	/* Samples for average
20949c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 *
21049c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * Drivers wanting to expose functionality for changing the number of
21149c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * samples used for average values should implement support in
21249c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * {read,write}_word_data callback for either PMBUS_VIRT_SAMPLES if it
21349c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * applies to all types of measurements, or any number of specific
21449c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * PMBUS_VIRT_*_SAMPLES registers to allow for individual control.
21549c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 */
21649c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_SAMPLES,
21749c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_IN_SAMPLES,
21849c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_CURR_SAMPLES,
21949c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_POWER_SAMPLES,
22049c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_TEMP_SAMPLES,
2212238835cSGuenter Roeck };
222aebcbbfcSGuenter Roeck 
2236f183d33SGuenter Roeck /*
224ddbb4db4SAlan Tull  * OPERATION
225ddbb4db4SAlan Tull  */
2262c052d42SGuenter Roeck #define PB_OPERATION_CONTROL_ON		BIT(7)
227ddbb4db4SAlan Tull 
228ddbb4db4SAlan Tull /*
2299d2ecfb7SGuenter Roeck  * CAPABILITY
2309d2ecfb7SGuenter Roeck  */
2312c052d42SGuenter Roeck #define PB_CAPABILITY_SMBALERT		BIT(4)
2322c052d42SGuenter Roeck #define PB_CAPABILITY_ERROR_CHECK	BIT(7)
2339d2ecfb7SGuenter Roeck 
2349d2ecfb7SGuenter Roeck /*
2359d2ecfb7SGuenter Roeck  * VOUT_MODE
2369d2ecfb7SGuenter Roeck  */
2379d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_MODE_MASK		0xe0
2389d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_PARAM_MASK		0x1f
2399d2ecfb7SGuenter Roeck 
2409d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_LINEAR		0x00
2419d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_VID		0x20
2429d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_DIRECT		0x40
2439d2ecfb7SGuenter Roeck 
2449d2ecfb7SGuenter Roeck /*
2459d2ecfb7SGuenter Roeck  * Fan configuration
2469d2ecfb7SGuenter Roeck  */
2472c052d42SGuenter Roeck #define PB_FAN_2_PULSE_MASK		(BIT(0) | BIT(1))
2482c052d42SGuenter Roeck #define PB_FAN_2_RPM			BIT(2)
2492c052d42SGuenter Roeck #define PB_FAN_2_INSTALLED		BIT(3)
2502c052d42SGuenter Roeck #define PB_FAN_1_PULSE_MASK		(BIT(4) | BIT(5))
2512c052d42SGuenter Roeck #define PB_FAN_1_RPM			BIT(6)
2522c052d42SGuenter Roeck #define PB_FAN_1_INSTALLED		BIT(7)
2539d2ecfb7SGuenter Roeck 
254d206636eSAndrew Jeffery enum pmbus_fan_mode { percent = 0, rpm };
255d206636eSAndrew Jeffery 
2569d2ecfb7SGuenter Roeck /*
2579d2ecfb7SGuenter Roeck  * STATUS_BYTE, STATUS_WORD (lower)
2589d2ecfb7SGuenter Roeck  */
2592c052d42SGuenter Roeck #define PB_STATUS_NONE_ABOVE		BIT(0)
2602c052d42SGuenter Roeck #define PB_STATUS_CML			BIT(1)
2612c052d42SGuenter Roeck #define PB_STATUS_TEMPERATURE		BIT(2)
2622c052d42SGuenter Roeck #define PB_STATUS_VIN_UV		BIT(3)
2632c052d42SGuenter Roeck #define PB_STATUS_IOUT_OC		BIT(4)
2642c052d42SGuenter Roeck #define PB_STATUS_VOUT_OV		BIT(5)
2652c052d42SGuenter Roeck #define PB_STATUS_OFF			BIT(6)
2662c052d42SGuenter Roeck #define PB_STATUS_BUSY			BIT(7)
2679d2ecfb7SGuenter Roeck 
2689d2ecfb7SGuenter Roeck /*
2699d2ecfb7SGuenter Roeck  * STATUS_WORD (upper)
2709d2ecfb7SGuenter Roeck  */
2712c052d42SGuenter Roeck #define PB_STATUS_UNKNOWN		BIT(8)
2722c052d42SGuenter Roeck #define PB_STATUS_OTHER			BIT(9)
2732c052d42SGuenter Roeck #define PB_STATUS_FANS			BIT(10)
2742c052d42SGuenter Roeck #define PB_STATUS_POWER_GOOD_N		BIT(11)
2752c052d42SGuenter Roeck #define PB_STATUS_WORD_MFR		BIT(12)
2762c052d42SGuenter Roeck #define PB_STATUS_INPUT			BIT(13)
2772c052d42SGuenter Roeck #define PB_STATUS_IOUT_POUT		BIT(14)
2782c052d42SGuenter Roeck #define PB_STATUS_VOUT			BIT(15)
2799d2ecfb7SGuenter Roeck 
2809d2ecfb7SGuenter Roeck /*
2819d2ecfb7SGuenter Roeck  * STATUS_IOUT
2829d2ecfb7SGuenter Roeck  */
2832c052d42SGuenter Roeck #define PB_POUT_OP_WARNING		BIT(0)
2842c052d42SGuenter Roeck #define PB_POUT_OP_FAULT		BIT(1)
2852c052d42SGuenter Roeck #define PB_POWER_LIMITING		BIT(2)
2862c052d42SGuenter Roeck #define PB_CURRENT_SHARE_FAULT		BIT(3)
2872c052d42SGuenter Roeck #define PB_IOUT_UC_FAULT		BIT(4)
2882c052d42SGuenter Roeck #define PB_IOUT_OC_WARNING		BIT(5)
2892c052d42SGuenter Roeck #define PB_IOUT_OC_LV_FAULT		BIT(6)
2902c052d42SGuenter Roeck #define PB_IOUT_OC_FAULT		BIT(7)
2919d2ecfb7SGuenter Roeck 
2929d2ecfb7SGuenter Roeck /*
2939d2ecfb7SGuenter Roeck  * STATUS_VOUT, STATUS_INPUT
2949d2ecfb7SGuenter Roeck  */
2952c052d42SGuenter Roeck #define PB_VOLTAGE_UV_FAULT		BIT(4)
2962c052d42SGuenter Roeck #define PB_VOLTAGE_UV_WARNING		BIT(5)
2972c052d42SGuenter Roeck #define PB_VOLTAGE_OV_WARNING		BIT(6)
2982c052d42SGuenter Roeck #define PB_VOLTAGE_OV_FAULT		BIT(7)
2999d2ecfb7SGuenter Roeck 
3009d2ecfb7SGuenter Roeck /*
3019d2ecfb7SGuenter Roeck  * STATUS_INPUT
3029d2ecfb7SGuenter Roeck  */
3032c052d42SGuenter Roeck #define PB_PIN_OP_WARNING		BIT(0)
3042c052d42SGuenter Roeck #define PB_IIN_OC_WARNING		BIT(1)
3052c052d42SGuenter Roeck #define PB_IIN_OC_FAULT			BIT(2)
3069d2ecfb7SGuenter Roeck 
3079d2ecfb7SGuenter Roeck /*
3089d2ecfb7SGuenter Roeck  * STATUS_TEMPERATURE
3099d2ecfb7SGuenter Roeck  */
3102c052d42SGuenter Roeck #define PB_TEMP_UT_FAULT		BIT(4)
3112c052d42SGuenter Roeck #define PB_TEMP_UT_WARNING		BIT(5)
3122c052d42SGuenter Roeck #define PB_TEMP_OT_WARNING		BIT(6)
3132c052d42SGuenter Roeck #define PB_TEMP_OT_FAULT		BIT(7)
3149d2ecfb7SGuenter Roeck 
3159d2ecfb7SGuenter Roeck /*
3169d2ecfb7SGuenter Roeck  * STATUS_FAN
3179d2ecfb7SGuenter Roeck  */
3182c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_WARNING		BIT(0)
3192c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_FAULT		BIT(1)
3202c052d42SGuenter Roeck #define PB_FAN_FAN2_SPEED_OVERRIDE	BIT(2)
3212c052d42SGuenter Roeck #define PB_FAN_FAN1_SPEED_OVERRIDE	BIT(3)
3222c052d42SGuenter Roeck #define PB_FAN_FAN2_WARNING		BIT(4)
3232c052d42SGuenter Roeck #define PB_FAN_FAN1_WARNING		BIT(5)
3242c052d42SGuenter Roeck #define PB_FAN_FAN2_FAULT		BIT(6)
3252c052d42SGuenter Roeck #define PB_FAN_FAN1_FAULT		BIT(7)
3269d2ecfb7SGuenter Roeck 
3279d2ecfb7SGuenter Roeck /*
3289d2ecfb7SGuenter Roeck  * CML_FAULT_STATUS
3299d2ecfb7SGuenter Roeck  */
3302c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_MEM_LOGIC	BIT(0)
3312c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_COMM		BIT(1)
3322c052d42SGuenter Roeck #define PB_CML_FAULT_PROCESSOR		BIT(3)
3332c052d42SGuenter Roeck #define PB_CML_FAULT_MEMORY		BIT(4)
3342c052d42SGuenter Roeck #define PB_CML_FAULT_PACKET_ERROR	BIT(5)
3352c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_DATA	BIT(6)
3362c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_COMMAND	BIT(7)
3379d2ecfb7SGuenter Roeck 
3389d2ecfb7SGuenter Roeck enum pmbus_sensor_classes {
3399d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_IN = 0,
3409d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_OUT,
3419d2ecfb7SGuenter Roeck 	PSC_CURRENT_IN,
3429d2ecfb7SGuenter Roeck 	PSC_CURRENT_OUT,
3439d2ecfb7SGuenter Roeck 	PSC_POWER,
3449d2ecfb7SGuenter Roeck 	PSC_TEMPERATURE,
3459d2ecfb7SGuenter Roeck 	PSC_FAN,
346d206636eSAndrew Jeffery 	PSC_PWM,
3479d2ecfb7SGuenter Roeck 	PSC_NUM_CLASSES		/* Number of power sensor classes */
3489d2ecfb7SGuenter Roeck };
3499d2ecfb7SGuenter Roeck 
3509d2ecfb7SGuenter Roeck #define PMBUS_PAGES	32	/* Per PMBus specification */
3519d2ecfb7SGuenter Roeck 
3529d2ecfb7SGuenter Roeck /* Functionality bit mask */
3532c052d42SGuenter Roeck #define PMBUS_HAVE_VIN		BIT(0)
3542c052d42SGuenter Roeck #define PMBUS_HAVE_VCAP		BIT(1)
3552c052d42SGuenter Roeck #define PMBUS_HAVE_VOUT		BIT(2)
3562c052d42SGuenter Roeck #define PMBUS_HAVE_IIN		BIT(3)
3572c052d42SGuenter Roeck #define PMBUS_HAVE_IOUT		BIT(4)
3582c052d42SGuenter Roeck #define PMBUS_HAVE_PIN		BIT(5)
3592c052d42SGuenter Roeck #define PMBUS_HAVE_POUT		BIT(6)
3602c052d42SGuenter Roeck #define PMBUS_HAVE_FAN12	BIT(7)
3612c052d42SGuenter Roeck #define PMBUS_HAVE_FAN34	BIT(8)
3622c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP		BIT(9)
3632c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP2	BIT(10)
3642c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP3	BIT(11)
3652c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VOUT	BIT(12)
3662c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_IOUT	BIT(13)
3672c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_INPUT	BIT(14)
3682c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_TEMP	BIT(15)
3692c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN12	BIT(16)
3702c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN34	BIT(17)
3712c052d42SGuenter Roeck #define PMBUS_HAVE_VMON		BIT(18)
3722c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VMON	BIT(19)
373d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM12	BIT(20)
374d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM34	BIT(21)
37549c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) #define PMBUS_HAVE_SAMPLES	BIT(22)
3769d2ecfb7SGuenter Roeck 
377464df6faSAndrew Jeffery #define PMBUS_PAGE_VIRTUAL	BIT(31)
378464df6faSAndrew Jeffery 
3791061d851SGuenter Roeck enum pmbus_data_format { linear = 0, direct, vid };
380d4977c08SVadim Pasternak enum vrm_version { vr11 = 0, vr12, vr13 };
3811061d851SGuenter Roeck 
3829d2ecfb7SGuenter Roeck struct pmbus_driver_info {
3839d2ecfb7SGuenter Roeck 	int pages;		/* Total number of pages */
3841061d851SGuenter Roeck 	enum pmbus_data_format format[PSC_NUM_CLASSES];
385068c2270SGuenter Roeck 	enum vrm_version vrm_version;
3869d2ecfb7SGuenter Roeck 	/*
3879d2ecfb7SGuenter Roeck 	 * Support one set of coefficients for each sensor type
3889d2ecfb7SGuenter Roeck 	 * Used for chips providing data in direct mode.
3899d2ecfb7SGuenter Roeck 	 */
3909d2ecfb7SGuenter Roeck 	int m[PSC_NUM_CLASSES];	/* mantissa for direct data format */
3919d2ecfb7SGuenter Roeck 	int b[PSC_NUM_CLASSES];	/* offset */
3929d2ecfb7SGuenter Roeck 	int R[PSC_NUM_CLASSES];	/* exponent */
3939d2ecfb7SGuenter Roeck 
3949d2ecfb7SGuenter Roeck 	u32 func[PMBUS_PAGES];	/* Functionality, per page */
3959d2ecfb7SGuenter Roeck 	/*
3969d2ecfb7SGuenter Roeck 	 * The following functions map manufacturing specific register values
3979d2ecfb7SGuenter Roeck 	 * to PMBus standard register values. Specify only if mapping is
3989d2ecfb7SGuenter Roeck 	 * necessary.
39920fcfe17SGuenter Roeck 	 * Functions return the register value (read) or zero (write) if
40020fcfe17SGuenter Roeck 	 * successful. A return value of -ENODATA indicates that there is no
40120fcfe17SGuenter Roeck 	 * manufacturer specific register, but that a standard PMBus register
40220fcfe17SGuenter Roeck 	 * may exist. Any other negative return value indicates that the
40320fcfe17SGuenter Roeck 	 * register does not exist, and that no attempt should be made to read
40420fcfe17SGuenter Roeck 	 * the standard register.
4059d2ecfb7SGuenter Roeck 	 */
4069d2ecfb7SGuenter Roeck 	int (*read_byte_data)(struct i2c_client *client, int page, int reg);
40746243f3aSGuenter Roeck 	int (*read_word_data)(struct i2c_client *client, int page, int reg);
40846243f3aSGuenter Roeck 	int (*write_word_data)(struct i2c_client *client, int page, int reg,
40946243f3aSGuenter Roeck 			       u16 word);
410044cd3a5SGuenter Roeck 	int (*write_byte)(struct i2c_client *client, int page, u8 value);
4119d2ecfb7SGuenter Roeck 	/*
4129d2ecfb7SGuenter Roeck 	 * The identify function determines supported PMBus functionality.
4139d2ecfb7SGuenter Roeck 	 * This function is only necessary if a chip driver supports multiple
4149d2ecfb7SGuenter Roeck 	 * chips, and the chip functionality is not pre-determined.
4159d2ecfb7SGuenter Roeck 	 */
4169d2ecfb7SGuenter Roeck 	int (*identify)(struct i2c_client *client,
4179d2ecfb7SGuenter Roeck 			struct pmbus_driver_info *info);
418ddbb4db4SAlan Tull 
419ddbb4db4SAlan Tull 	/* Regulator functionality, if supported by this chip driver. */
420ddbb4db4SAlan Tull 	int num_regulators;
421ddbb4db4SAlan Tull 	const struct regulator_desc *reg_desc;
422991d6799Skrzysztof.adamski@nokia.com 
423991d6799Skrzysztof.adamski@nokia.com 	/* custom attributes */
424991d6799Skrzysztof.adamski@nokia.com 	const struct attribute_group **groups;
4259d2ecfb7SGuenter Roeck };
4269d2ecfb7SGuenter Roeck 
427ddbb4db4SAlan Tull /* Regulator ops */
428ddbb4db4SAlan Tull 
429a07d7311SAxel Lin extern const struct regulator_ops pmbus_regulator_ops;
430ddbb4db4SAlan Tull 
431ddbb4db4SAlan Tull /* Macro for filling in array of struct regulator_desc */
432ddbb4db4SAlan Tull #define PMBUS_REGULATOR(_name, _id)				\
433ddbb4db4SAlan Tull 	[_id] = {						\
434ddbb4db4SAlan Tull 		.name = (_name # _id),				\
435ddbb4db4SAlan Tull 		.id = (_id),					\
436ddbb4db4SAlan Tull 		.of_match = of_match_ptr(_name # _id),		\
437ddbb4db4SAlan Tull 		.regulators_node = of_match_ptr("regulators"),	\
438ddbb4db4SAlan Tull 		.ops = &pmbus_regulator_ops,			\
4397b7a8b42SAxel Lin 		.type = REGULATOR_VOLTAGE,			\
440ddbb4db4SAlan Tull 		.owner = THIS_MODULE,				\
441ddbb4db4SAlan Tull 	}
442ddbb4db4SAlan Tull 
4439d2ecfb7SGuenter Roeck /* Function declarations */
4449d2ecfb7SGuenter Roeck 
445ce603b18SGuenter Roeck void pmbus_clear_cache(struct i2c_client *client);
4466dcf2fb5SEdward A. James int pmbus_set_page(struct i2c_client *client, int page);
4476dcf2fb5SEdward A. James int pmbus_read_word_data(struct i2c_client *client, int page, u8 reg);
4486dcf2fb5SEdward A. James int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, u16 word);
4499c1ed894SGuenter Roeck int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
45003e9bd8dSGuenter Roeck int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
45111c11998SAlan Tull int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
45211c11998SAlan Tull 			  u8 value);
45311c11998SAlan Tull int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
45411c11998SAlan Tull 			   u8 mask, u8 value);
4559d2ecfb7SGuenter Roeck void pmbus_clear_faults(struct i2c_client *client);
4569d2ecfb7SGuenter Roeck bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
4579d2ecfb7SGuenter Roeck bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
4589d2ecfb7SGuenter Roeck int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
4599d2ecfb7SGuenter Roeck 		   struct pmbus_driver_info *info);
460dd285ad7SGuenter Roeck int pmbus_do_remove(struct i2c_client *client);
4619d2ecfb7SGuenter Roeck const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
4629d2ecfb7SGuenter Roeck 						      *client);
463d206636eSAndrew Jeffery int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id,
464d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
465d206636eSAndrew Jeffery int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id,
466d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
467d206636eSAndrew Jeffery int pmbus_update_fan(struct i2c_client *client, int page, int id,
468d206636eSAndrew Jeffery 		     u8 config, u8 mask, u16 command);
469eb6489b6SEdward A. James struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client);
470eb6489b6SEdward A. James 
4719d2ecfb7SGuenter Roeck #endif /* PMBUS_H */
472