xref: /linux/drivers/hwmon/pmbus/pmbus.h (revision 9d72340b6ade9457fc79c7059fcc62e5b888f9a5)
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,
299d2ecfb7SGuenter Roeck 
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 
1229d2ecfb7SGuenter Roeck /*
1236f183d33SGuenter Roeck  * Virtual registers.
1246f183d33SGuenter Roeck  * Useful to support attributes which are not supported by standard PMBus
1256f183d33SGuenter Roeck  * registers but exist as manufacturer specific registers on individual chips.
1266f183d33SGuenter Roeck  * Must be mapped to real registers in device specific code.
1276f183d33SGuenter Roeck  *
1286f183d33SGuenter Roeck  * Semantics:
1296f183d33SGuenter Roeck  * Virtual registers are all word size.
1306f183d33SGuenter Roeck  * READ registers are read-only; writes are either ignored or return an error.
13120fcfe17SGuenter Roeck  * RESET registers are read/write. Reading reset registers returns zero
13220fcfe17SGuenter Roeck  * (used for detection), writing any value causes the associated history to be
13320fcfe17SGuenter Roeck  * reset.
13420fcfe17SGuenter Roeck  * Virtual registers have to be handled in device specific driver code. Chip
13520fcfe17SGuenter Roeck  * driver code returns non-negative register values if a virtual register is
13620fcfe17SGuenter Roeck  * supported, or a negative error code if not. The chip driver may return
13720fcfe17SGuenter Roeck  * -ENODATA or any other error code in this case, though an error code other
13820fcfe17SGuenter Roeck  * than -ENODATA is handled more efficiently and thus preferred. Either case,
13920fcfe17SGuenter Roeck  * the calling PMBus core code will abort if the chip driver returns an error
14020fcfe17SGuenter Roeck  * code when reading or writing virtual registers.
1416f183d33SGuenter Roeck  */
1422238835cSGuenter Roeck 	PMBUS_VIRT_BASE			= 0x100,
1432238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_AVG,
1442238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_MIN,
1452238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP_MAX,
1462238835cSGuenter Roeck 	PMBUS_VIRT_RESET_TEMP_HISTORY,
1472238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_AVG,
1482238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_MIN,
1492238835cSGuenter Roeck 	PMBUS_VIRT_READ_VIN_MAX,
1502238835cSGuenter Roeck 	PMBUS_VIRT_RESET_VIN_HISTORY,
1512238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_AVG,
1522238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_MIN,
1532238835cSGuenter Roeck 	PMBUS_VIRT_READ_IIN_MAX,
1542238835cSGuenter Roeck 	PMBUS_VIRT_RESET_IIN_HISTORY,
1552238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_AVG,
1562238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_MIN,
1572238835cSGuenter Roeck 	PMBUS_VIRT_READ_PIN_MAX,
1582238835cSGuenter Roeck 	PMBUS_VIRT_RESET_PIN_HISTORY,
1592238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_AVG,
1602238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_MIN,
1612238835cSGuenter Roeck 	PMBUS_VIRT_READ_POUT_MAX,
1622238835cSGuenter Roeck 	PMBUS_VIRT_RESET_POUT_HISTORY,
1632238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_AVG,
1642238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_MIN,
1652238835cSGuenter Roeck 	PMBUS_VIRT_READ_VOUT_MAX,
1662238835cSGuenter Roeck 	PMBUS_VIRT_RESET_VOUT_HISTORY,
1672238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_AVG,
1682238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_MIN,
1692238835cSGuenter Roeck 	PMBUS_VIRT_READ_IOUT_MAX,
1702238835cSGuenter Roeck 	PMBUS_VIRT_RESET_IOUT_HISTORY,
1712238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_AVG,
1722238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_MIN,
1732238835cSGuenter Roeck 	PMBUS_VIRT_READ_TEMP2_MAX,
1742238835cSGuenter Roeck 	PMBUS_VIRT_RESET_TEMP2_HISTORY,
1756f183d33SGuenter Roeck 
1762238835cSGuenter Roeck 	PMBUS_VIRT_READ_VMON,
1772238835cSGuenter Roeck 	PMBUS_VIRT_VMON_UV_WARN_LIMIT,
1782238835cSGuenter Roeck 	PMBUS_VIRT_VMON_OV_WARN_LIMIT,
1792238835cSGuenter Roeck 	PMBUS_VIRT_VMON_UV_FAULT_LIMIT,
1802238835cSGuenter Roeck 	PMBUS_VIRT_VMON_OV_FAULT_LIMIT,
1812238835cSGuenter Roeck 	PMBUS_VIRT_STATUS_VMON,
182d206636eSAndrew Jeffery 
183d206636eSAndrew Jeffery 	/*
184d206636eSAndrew Jeffery 	 * RPM and PWM Fan control
185d206636eSAndrew Jeffery 	 *
186d206636eSAndrew Jeffery 	 * Drivers wanting to expose PWM control must define the behaviour of
187d206636eSAndrew Jeffery 	 * PMBUS_VIRT_PWM_[1-4] and PMBUS_VIRT_PWM_ENABLE_[1-4] in the
188d206636eSAndrew Jeffery 	 * {read,write}_word_data callback.
189d206636eSAndrew Jeffery 	 *
190d206636eSAndrew Jeffery 	 * pmbus core provides a default implementation for
191d206636eSAndrew Jeffery 	 * PMBUS_VIRT_FAN_TARGET_[1-4].
192d206636eSAndrew Jeffery 	 *
193d206636eSAndrew Jeffery 	 * TARGET, PWM and PWM_ENABLE members must be defined sequentially;
194d206636eSAndrew Jeffery 	 * pmbus core uses the difference between the provided register and
195d206636eSAndrew Jeffery 	 * it's _1 counterpart to calculate the FAN/PWM ID.
196d206636eSAndrew Jeffery 	 */
197d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_1,
198d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_2,
199d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_3,
200d206636eSAndrew Jeffery 	PMBUS_VIRT_FAN_TARGET_4,
201d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_1,
202d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_2,
203d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_3,
204d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_4,
205d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_1,
206d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_2,
207d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_3,
208d206636eSAndrew Jeffery 	PMBUS_VIRT_PWM_ENABLE_4,
20949c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 
21049c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	/* Samples for average
21149c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 *
21249c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * Drivers wanting to expose functionality for changing the number of
21349c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * samples used for average values should implement support in
21449c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * {read,write}_word_data callback for either PMBUS_VIRT_SAMPLES if it
21549c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * applies to all types of measurements, or any number of specific
21649c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 * PMBUS_VIRT_*_SAMPLES registers to allow for individual control.
21749c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	 */
21849c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_SAMPLES,
21949c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_IN_SAMPLES,
22049c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_CURR_SAMPLES,
22149c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_POWER_SAMPLES,
22249c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) 	PMBUS_VIRT_TEMP_SAMPLES,
2232238835cSGuenter Roeck };
224aebcbbfcSGuenter Roeck 
2256f183d33SGuenter Roeck /*
226ddbb4db4SAlan Tull  * OPERATION
227ddbb4db4SAlan Tull  */
2282c052d42SGuenter Roeck #define PB_OPERATION_CONTROL_ON		BIT(7)
229ddbb4db4SAlan Tull 
230ddbb4db4SAlan Tull /*
2319e347728SGuenter Roeck  * WRITE_PROTECT
2329e347728SGuenter Roeck  */
2339e347728SGuenter Roeck #define PB_WP_ALL	BIT(7)	/* all but WRITE_PROTECT */
2349e347728SGuenter Roeck #define PB_WP_OP	BIT(6)	/* all but WP, OPERATION, PAGE */
2359e347728SGuenter Roeck #define PB_WP_VOUT	BIT(5)	/* all but WP, OPERATION, PAGE, VOUT, ON_OFF */
2369e347728SGuenter Roeck 
2379e347728SGuenter Roeck #define PB_WP_ANY	(PB_WP_ALL | PB_WP_OP | PB_WP_VOUT)
2389e347728SGuenter Roeck 
2399e347728SGuenter Roeck /*
2409d2ecfb7SGuenter Roeck  * CAPABILITY
2419d2ecfb7SGuenter Roeck  */
2422c052d42SGuenter Roeck #define PB_CAPABILITY_SMBALERT		BIT(4)
2432c052d42SGuenter Roeck #define PB_CAPABILITY_ERROR_CHECK	BIT(7)
2449d2ecfb7SGuenter Roeck 
2459d2ecfb7SGuenter Roeck /*
2469d2ecfb7SGuenter Roeck  * VOUT_MODE
2479d2ecfb7SGuenter Roeck  */
2489d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_MODE_MASK		0xe0
2499d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_PARAM_MASK		0x1f
2509d2ecfb7SGuenter Roeck 
2519d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_LINEAR		0x00
2529d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_VID		0x20
2539d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_DIRECT		0x40
2549d2ecfb7SGuenter Roeck 
2559d2ecfb7SGuenter Roeck /*
2569d2ecfb7SGuenter Roeck  * Fan configuration
2579d2ecfb7SGuenter Roeck  */
2582c052d42SGuenter Roeck #define PB_FAN_2_PULSE_MASK		(BIT(0) | BIT(1))
2592c052d42SGuenter Roeck #define PB_FAN_2_RPM			BIT(2)
2602c052d42SGuenter Roeck #define PB_FAN_2_INSTALLED		BIT(3)
2612c052d42SGuenter Roeck #define PB_FAN_1_PULSE_MASK		(BIT(4) | BIT(5))
2622c052d42SGuenter Roeck #define PB_FAN_1_RPM			BIT(6)
2632c052d42SGuenter Roeck #define PB_FAN_1_INSTALLED		BIT(7)
2649d2ecfb7SGuenter Roeck 
265d206636eSAndrew Jeffery enum pmbus_fan_mode { percent = 0, rpm };
266d206636eSAndrew Jeffery 
2679d2ecfb7SGuenter Roeck /*
2689d2ecfb7SGuenter Roeck  * STATUS_BYTE, STATUS_WORD (lower)
2699d2ecfb7SGuenter Roeck  */
2702c052d42SGuenter Roeck #define PB_STATUS_NONE_ABOVE		BIT(0)
2712c052d42SGuenter Roeck #define PB_STATUS_CML			BIT(1)
2722c052d42SGuenter Roeck #define PB_STATUS_TEMPERATURE		BIT(2)
2732c052d42SGuenter Roeck #define PB_STATUS_VIN_UV		BIT(3)
2742c052d42SGuenter Roeck #define PB_STATUS_IOUT_OC		BIT(4)
2752c052d42SGuenter Roeck #define PB_STATUS_VOUT_OV		BIT(5)
2762c052d42SGuenter Roeck #define PB_STATUS_OFF			BIT(6)
2772c052d42SGuenter Roeck #define PB_STATUS_BUSY			BIT(7)
2789d2ecfb7SGuenter Roeck 
2799d2ecfb7SGuenter Roeck /*
2809d2ecfb7SGuenter Roeck  * STATUS_WORD (upper)
2819d2ecfb7SGuenter Roeck  */
2822c052d42SGuenter Roeck #define PB_STATUS_UNKNOWN		BIT(8)
2832c052d42SGuenter Roeck #define PB_STATUS_OTHER			BIT(9)
2842c052d42SGuenter Roeck #define PB_STATUS_FANS			BIT(10)
2852c052d42SGuenter Roeck #define PB_STATUS_POWER_GOOD_N		BIT(11)
2862c052d42SGuenter Roeck #define PB_STATUS_WORD_MFR		BIT(12)
2872c052d42SGuenter Roeck #define PB_STATUS_INPUT			BIT(13)
2882c052d42SGuenter Roeck #define PB_STATUS_IOUT_POUT		BIT(14)
2892c052d42SGuenter Roeck #define PB_STATUS_VOUT			BIT(15)
2909d2ecfb7SGuenter Roeck 
2919d2ecfb7SGuenter Roeck /*
2929d2ecfb7SGuenter Roeck  * STATUS_IOUT
2939d2ecfb7SGuenter Roeck  */
2942c052d42SGuenter Roeck #define PB_POUT_OP_WARNING		BIT(0)
2952c052d42SGuenter Roeck #define PB_POUT_OP_FAULT		BIT(1)
2962c052d42SGuenter Roeck #define PB_POWER_LIMITING		BIT(2)
2972c052d42SGuenter Roeck #define PB_CURRENT_SHARE_FAULT		BIT(3)
2982c052d42SGuenter Roeck #define PB_IOUT_UC_FAULT		BIT(4)
2992c052d42SGuenter Roeck #define PB_IOUT_OC_WARNING		BIT(5)
3002c052d42SGuenter Roeck #define PB_IOUT_OC_LV_FAULT		BIT(6)
3012c052d42SGuenter Roeck #define PB_IOUT_OC_FAULT		BIT(7)
3029d2ecfb7SGuenter Roeck 
3039d2ecfb7SGuenter Roeck /*
3049d2ecfb7SGuenter Roeck  * STATUS_VOUT, STATUS_INPUT
3059d2ecfb7SGuenter Roeck  */
3062c052d42SGuenter Roeck #define PB_VOLTAGE_UV_FAULT		BIT(4)
3072c052d42SGuenter Roeck #define PB_VOLTAGE_UV_WARNING		BIT(5)
3082c052d42SGuenter Roeck #define PB_VOLTAGE_OV_WARNING		BIT(6)
3092c052d42SGuenter Roeck #define PB_VOLTAGE_OV_FAULT		BIT(7)
3109d2ecfb7SGuenter Roeck 
3119d2ecfb7SGuenter Roeck /*
3129d2ecfb7SGuenter Roeck  * STATUS_INPUT
3139d2ecfb7SGuenter Roeck  */
3142c052d42SGuenter Roeck #define PB_PIN_OP_WARNING		BIT(0)
3152c052d42SGuenter Roeck #define PB_IIN_OC_WARNING		BIT(1)
3162c052d42SGuenter Roeck #define PB_IIN_OC_FAULT			BIT(2)
3179d2ecfb7SGuenter Roeck 
3189d2ecfb7SGuenter Roeck /*
3199d2ecfb7SGuenter Roeck  * STATUS_TEMPERATURE
3209d2ecfb7SGuenter Roeck  */
3212c052d42SGuenter Roeck #define PB_TEMP_UT_FAULT		BIT(4)
3222c052d42SGuenter Roeck #define PB_TEMP_UT_WARNING		BIT(5)
3232c052d42SGuenter Roeck #define PB_TEMP_OT_WARNING		BIT(6)
3242c052d42SGuenter Roeck #define PB_TEMP_OT_FAULT		BIT(7)
3259d2ecfb7SGuenter Roeck 
3269d2ecfb7SGuenter Roeck /*
3279d2ecfb7SGuenter Roeck  * STATUS_FAN
3289d2ecfb7SGuenter Roeck  */
3292c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_WARNING		BIT(0)
3302c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_FAULT		BIT(1)
3312c052d42SGuenter Roeck #define PB_FAN_FAN2_SPEED_OVERRIDE	BIT(2)
3322c052d42SGuenter Roeck #define PB_FAN_FAN1_SPEED_OVERRIDE	BIT(3)
3332c052d42SGuenter Roeck #define PB_FAN_FAN2_WARNING		BIT(4)
3342c052d42SGuenter Roeck #define PB_FAN_FAN1_WARNING		BIT(5)
3352c052d42SGuenter Roeck #define PB_FAN_FAN2_FAULT		BIT(6)
3362c052d42SGuenter Roeck #define PB_FAN_FAN1_FAULT		BIT(7)
3379d2ecfb7SGuenter Roeck 
3389d2ecfb7SGuenter Roeck /*
3399d2ecfb7SGuenter Roeck  * CML_FAULT_STATUS
3409d2ecfb7SGuenter Roeck  */
3412c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_MEM_LOGIC	BIT(0)
3422c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_COMM		BIT(1)
3432c052d42SGuenter Roeck #define PB_CML_FAULT_PROCESSOR		BIT(3)
3442c052d42SGuenter Roeck #define PB_CML_FAULT_MEMORY		BIT(4)
3452c052d42SGuenter Roeck #define PB_CML_FAULT_PACKET_ERROR	BIT(5)
3462c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_DATA	BIT(6)
3472c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_COMMAND	BIT(7)
3489d2ecfb7SGuenter Roeck 
3499d2ecfb7SGuenter Roeck enum pmbus_sensor_classes {
3509d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_IN = 0,
3519d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_OUT,
3529d2ecfb7SGuenter Roeck 	PSC_CURRENT_IN,
3539d2ecfb7SGuenter Roeck 	PSC_CURRENT_OUT,
3549d2ecfb7SGuenter Roeck 	PSC_POWER,
3559d2ecfb7SGuenter Roeck 	PSC_TEMPERATURE,
3569d2ecfb7SGuenter Roeck 	PSC_FAN,
357d206636eSAndrew Jeffery 	PSC_PWM,
3589d2ecfb7SGuenter Roeck 	PSC_NUM_CLASSES		/* Number of power sensor classes */
3599d2ecfb7SGuenter Roeck };
3609d2ecfb7SGuenter Roeck 
3619d2ecfb7SGuenter Roeck #define PMBUS_PAGES	32	/* Per PMBus specification */
3629d2ecfb7SGuenter Roeck 
3639d2ecfb7SGuenter Roeck /* Functionality bit mask */
3642c052d42SGuenter Roeck #define PMBUS_HAVE_VIN		BIT(0)
3652c052d42SGuenter Roeck #define PMBUS_HAVE_VCAP		BIT(1)
3662c052d42SGuenter Roeck #define PMBUS_HAVE_VOUT		BIT(2)
3672c052d42SGuenter Roeck #define PMBUS_HAVE_IIN		BIT(3)
3682c052d42SGuenter Roeck #define PMBUS_HAVE_IOUT		BIT(4)
3692c052d42SGuenter Roeck #define PMBUS_HAVE_PIN		BIT(5)
3702c052d42SGuenter Roeck #define PMBUS_HAVE_POUT		BIT(6)
3712c052d42SGuenter Roeck #define PMBUS_HAVE_FAN12	BIT(7)
3722c052d42SGuenter Roeck #define PMBUS_HAVE_FAN34	BIT(8)
3732c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP		BIT(9)
3742c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP2	BIT(10)
3752c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP3	BIT(11)
3762c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VOUT	BIT(12)
3772c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_IOUT	BIT(13)
3782c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_INPUT	BIT(14)
3792c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_TEMP	BIT(15)
3802c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN12	BIT(16)
3812c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN34	BIT(17)
3822c052d42SGuenter Roeck #define PMBUS_HAVE_VMON		BIT(18)
3832c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VMON	BIT(19)
384d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM12	BIT(20)
385d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM34	BIT(21)
38649c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) #define PMBUS_HAVE_SAMPLES	BIT(22)
3879d2ecfb7SGuenter Roeck 
388464df6faSAndrew Jeffery #define PMBUS_PAGE_VIRTUAL	BIT(31)
389464df6faSAndrew Jeffery 
3901061d851SGuenter Roeck enum pmbus_data_format { linear = 0, direct, vid };
391*9d72340bSVadim Pasternak enum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv };
3921061d851SGuenter Roeck 
3939d2ecfb7SGuenter Roeck struct pmbus_driver_info {
3949d2ecfb7SGuenter Roeck 	int pages;		/* Total number of pages */
3951061d851SGuenter Roeck 	enum pmbus_data_format format[PSC_NUM_CLASSES];
396b9fa0a3aSVadim Pasternak 	enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */
3979d2ecfb7SGuenter Roeck 	/*
3989d2ecfb7SGuenter Roeck 	 * Support one set of coefficients for each sensor type
3999d2ecfb7SGuenter Roeck 	 * Used for chips providing data in direct mode.
4009d2ecfb7SGuenter Roeck 	 */
4019d2ecfb7SGuenter Roeck 	int m[PSC_NUM_CLASSES];	/* mantissa for direct data format */
4029d2ecfb7SGuenter Roeck 	int b[PSC_NUM_CLASSES];	/* offset */
4039d2ecfb7SGuenter Roeck 	int R[PSC_NUM_CLASSES];	/* exponent */
4049d2ecfb7SGuenter Roeck 
4059d2ecfb7SGuenter Roeck 	u32 func[PMBUS_PAGES];	/* Functionality, per page */
4069d2ecfb7SGuenter Roeck 	/*
4079d2ecfb7SGuenter Roeck 	 * The following functions map manufacturing specific register values
4089d2ecfb7SGuenter Roeck 	 * to PMBus standard register values. Specify only if mapping is
4099d2ecfb7SGuenter Roeck 	 * necessary.
41020fcfe17SGuenter Roeck 	 * Functions return the register value (read) or zero (write) if
41120fcfe17SGuenter Roeck 	 * successful. A return value of -ENODATA indicates that there is no
41220fcfe17SGuenter Roeck 	 * manufacturer specific register, but that a standard PMBus register
41320fcfe17SGuenter Roeck 	 * may exist. Any other negative return value indicates that the
41420fcfe17SGuenter Roeck 	 * register does not exist, and that no attempt should be made to read
41520fcfe17SGuenter Roeck 	 * the standard register.
4169d2ecfb7SGuenter Roeck 	 */
4179d2ecfb7SGuenter Roeck 	int (*read_byte_data)(struct i2c_client *client, int page, int reg);
41846243f3aSGuenter Roeck 	int (*read_word_data)(struct i2c_client *client, int page, int reg);
41946243f3aSGuenter Roeck 	int (*write_word_data)(struct i2c_client *client, int page, int reg,
42046243f3aSGuenter Roeck 			       u16 word);
421044cd3a5SGuenter Roeck 	int (*write_byte)(struct i2c_client *client, int page, u8 value);
4229d2ecfb7SGuenter Roeck 	/*
4239d2ecfb7SGuenter Roeck 	 * The identify function determines supported PMBus functionality.
4249d2ecfb7SGuenter Roeck 	 * This function is only necessary if a chip driver supports multiple
4259d2ecfb7SGuenter Roeck 	 * chips, and the chip functionality is not pre-determined.
4269d2ecfb7SGuenter Roeck 	 */
4279d2ecfb7SGuenter Roeck 	int (*identify)(struct i2c_client *client,
4289d2ecfb7SGuenter Roeck 			struct pmbus_driver_info *info);
429ddbb4db4SAlan Tull 
430ddbb4db4SAlan Tull 	/* Regulator functionality, if supported by this chip driver. */
431ddbb4db4SAlan Tull 	int num_regulators;
432ddbb4db4SAlan Tull 	const struct regulator_desc *reg_desc;
433991d6799Skrzysztof.adamski@nokia.com 
434991d6799Skrzysztof.adamski@nokia.com 	/* custom attributes */
435991d6799Skrzysztof.adamski@nokia.com 	const struct attribute_group **groups;
4369d2ecfb7SGuenter Roeck };
4379d2ecfb7SGuenter Roeck 
438ddbb4db4SAlan Tull /* Regulator ops */
439ddbb4db4SAlan Tull 
440a07d7311SAxel Lin extern const struct regulator_ops pmbus_regulator_ops;
441ddbb4db4SAlan Tull 
442ddbb4db4SAlan Tull /* Macro for filling in array of struct regulator_desc */
443ddbb4db4SAlan Tull #define PMBUS_REGULATOR(_name, _id)				\
444ddbb4db4SAlan Tull 	[_id] = {						\
445ddbb4db4SAlan Tull 		.name = (_name # _id),				\
446ddbb4db4SAlan Tull 		.id = (_id),					\
447ddbb4db4SAlan Tull 		.of_match = of_match_ptr(_name # _id),		\
448ddbb4db4SAlan Tull 		.regulators_node = of_match_ptr("regulators"),	\
449ddbb4db4SAlan Tull 		.ops = &pmbus_regulator_ops,			\
4507b7a8b42SAxel Lin 		.type = REGULATOR_VOLTAGE,			\
451ddbb4db4SAlan Tull 		.owner = THIS_MODULE,				\
452ddbb4db4SAlan Tull 	}
453ddbb4db4SAlan Tull 
4549d2ecfb7SGuenter Roeck /* Function declarations */
4559d2ecfb7SGuenter Roeck 
456ce603b18SGuenter Roeck void pmbus_clear_cache(struct i2c_client *client);
4576dcf2fb5SEdward A. James int pmbus_set_page(struct i2c_client *client, int page);
4586dcf2fb5SEdward A. James int pmbus_read_word_data(struct i2c_client *client, int page, u8 reg);
4596dcf2fb5SEdward A. James int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg, u16 word);
4609c1ed894SGuenter Roeck int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
46103e9bd8dSGuenter Roeck int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
46211c11998SAlan Tull int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
46311c11998SAlan Tull 			  u8 value);
46411c11998SAlan Tull int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
46511c11998SAlan Tull 			   u8 mask, u8 value);
4669d2ecfb7SGuenter Roeck void pmbus_clear_faults(struct i2c_client *client);
4679d2ecfb7SGuenter Roeck bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
4689d2ecfb7SGuenter Roeck bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
4699d2ecfb7SGuenter Roeck int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
4709d2ecfb7SGuenter Roeck 		   struct pmbus_driver_info *info);
471dd285ad7SGuenter Roeck int pmbus_do_remove(struct i2c_client *client);
4729d2ecfb7SGuenter Roeck const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
4739d2ecfb7SGuenter Roeck 						      *client);
474d206636eSAndrew Jeffery int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id,
475d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
476d206636eSAndrew Jeffery int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id,
477d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
478d206636eSAndrew Jeffery int pmbus_update_fan(struct i2c_client *client, int page, int id,
479d206636eSAndrew Jeffery 		     u8 config, u8 mask, u16 command);
480eb6489b6SEdward A. James struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client);
481eb6489b6SEdward A. James 
4829d2ecfb7SGuenter Roeck #endif /* PMBUS_H */
483