xref: /linux/drivers/hwmon/pmbus/pmbus.h (revision 42b16d3ac371a2fac9b6f08fd75f23f34ba3955a)
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 
421*20471071SPatryk Biel /* PMBus revision identifiers */
422*20471071SPatryk Biel #define PMBUS_REV_10 0x00	/* PMBus revision 1.0 */
423*20471071SPatryk Biel #define PMBUS_REV_11 0x11	/* PMBus revision 1.1 */
424*20471071SPatryk Biel #define PMBUS_REV_12 0x22	/* PMBus revision 1.2 */
425*20471071SPatryk Biel #define PMBUS_REV_13 0x33	/* PMBus revision 1.3 */
426*20471071SPatryk Biel 
4279d2ecfb7SGuenter Roeck struct pmbus_driver_info {
4289d2ecfb7SGuenter Roeck 	int pages;		/* Total number of pages */
42916358542SGuenter Roeck 	u8 phases[PMBUS_PAGES];	/* Number of phases per page */
4301061d851SGuenter Roeck 	enum pmbus_data_format format[PSC_NUM_CLASSES];
431b9fa0a3aSVadim Pasternak 	enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */
4329d2ecfb7SGuenter Roeck 	/*
4339d2ecfb7SGuenter Roeck 	 * Support one set of coefficients for each sensor type
4349d2ecfb7SGuenter Roeck 	 * Used for chips providing data in direct mode.
4359d2ecfb7SGuenter Roeck 	 */
4369d2ecfb7SGuenter Roeck 	int m[PSC_NUM_CLASSES];	/* mantissa for direct data format */
4379d2ecfb7SGuenter Roeck 	int b[PSC_NUM_CLASSES];	/* offset */
4389d2ecfb7SGuenter Roeck 	int R[PSC_NUM_CLASSES];	/* exponent */
4399d2ecfb7SGuenter Roeck 
4409d2ecfb7SGuenter Roeck 	u32 func[PMBUS_PAGES];	/* Functionality, per page */
44116358542SGuenter Roeck 	u32 pfunc[PMBUS_PHASES];/* Functionality, per phase */
4429d2ecfb7SGuenter Roeck 	/*
4439d2ecfb7SGuenter Roeck 	 * The following functions map manufacturing specific register values
4449d2ecfb7SGuenter Roeck 	 * to PMBus standard register values. Specify only if mapping is
4459d2ecfb7SGuenter Roeck 	 * necessary.
44620fcfe17SGuenter Roeck 	 * Functions return the register value (read) or zero (write) if
44720fcfe17SGuenter Roeck 	 * successful. A return value of -ENODATA indicates that there is no
44820fcfe17SGuenter Roeck 	 * manufacturer specific register, but that a standard PMBus register
44920fcfe17SGuenter Roeck 	 * may exist. Any other negative return value indicates that the
45020fcfe17SGuenter Roeck 	 * register does not exist, and that no attempt should be made to read
45120fcfe17SGuenter Roeck 	 * the standard register.
4529d2ecfb7SGuenter Roeck 	 */
4539d2ecfb7SGuenter Roeck 	int (*read_byte_data)(struct i2c_client *client, int page, int reg);
45443f33b6eSGuenter Roeck 	int (*read_word_data)(struct i2c_client *client, int page, int phase,
45543f33b6eSGuenter Roeck 			      int reg);
4565de3e13fSMårten Lindahl 	int (*write_byte_data)(struct i2c_client *client, int page, int reg,
4575de3e13fSMårten Lindahl 			      u8 byte);
45846243f3aSGuenter Roeck 	int (*write_word_data)(struct i2c_client *client, int page, int reg,
45946243f3aSGuenter Roeck 			       u16 word);
460044cd3a5SGuenter Roeck 	int (*write_byte)(struct i2c_client *client, int page, u8 value);
4619d2ecfb7SGuenter Roeck 	/*
4629d2ecfb7SGuenter Roeck 	 * The identify function determines supported PMBus functionality.
4639d2ecfb7SGuenter Roeck 	 * This function is only necessary if a chip driver supports multiple
4649d2ecfb7SGuenter Roeck 	 * chips, and the chip functionality is not pre-determined.
4659d2ecfb7SGuenter Roeck 	 */
4669d2ecfb7SGuenter Roeck 	int (*identify)(struct i2c_client *client,
4679d2ecfb7SGuenter Roeck 			struct pmbus_driver_info *info);
468ddbb4db4SAlan Tull 
469ddbb4db4SAlan Tull 	/* Regulator functionality, if supported by this chip driver. */
470ddbb4db4SAlan Tull 	int num_regulators;
471ddbb4db4SAlan Tull 	const struct regulator_desc *reg_desc;
472991d6799Skrzysztof.adamski@nokia.com 
473991d6799Skrzysztof.adamski@nokia.com 	/* custom attributes */
474991d6799Skrzysztof.adamski@nokia.com 	const struct attribute_group **groups;
4759d2ecfb7SGuenter Roeck 
4769d2ecfb7SGuenter Roeck 	/*
477ddbb4db4SAlan Tull 	 * Some chips need a little delay between SMBus communication. When
478ddbb4db4SAlan Tull 	 * set, the generic PMBus helper functions will wait if necessary
479a07d7311SAxel Lin 	 * to meet this requirement. The access delay is honored after
480ddbb4db4SAlan Tull 	 * every SMBus operation. The write delay is only honored after
4814a235369SMårten Lindahl 	 * SMBus write operations.
482b52acefcSSaravanan Sekar 	 */
483ddbb4db4SAlan Tull 	int access_delay;		/* in microseconds */
484ddbb4db4SAlan Tull 	int write_delay;		/* in microseconds */
485ddbb4db4SAlan Tull };
486ddbb4db4SAlan Tull 
487ddbb4db4SAlan Tull /* Regulator ops */
488ddbb4db4SAlan Tull 
4897b7a8b42SAxel Lin extern const struct regulator_ops pmbus_regulator_ops;
490ddbb4db4SAlan Tull 
4914a235369SMårten Lindahl /* Macros for filling in array of struct regulator_desc */
4924a235369SMårten Lindahl #define PMBUS_REGULATOR_STEP(_name, _id, _voltages, _step, _min_uV)  \
493b52acefcSSaravanan Sekar 	[_id] = {						\
494ddbb4db4SAlan Tull 		.name = (_name # _id),				\
495ddbb4db4SAlan Tull 		.id = (_id),					\
496b52acefcSSaravanan Sekar 		.of_match = of_match_ptr(_name # _id),		\
4974a235369SMårten Lindahl 		.regulators_node = of_match_ptr("regulators"),	\
49888b5970eSSaravanan Sekar 		.ops = &pmbus_regulator_ops,			\
49988b5970eSSaravanan Sekar 		.type = REGULATOR_VOLTAGE,			\
50088b5970eSSaravanan Sekar 		.owner = THIS_MODULE,				\
50188b5970eSSaravanan Sekar 		.n_voltages = _voltages,			\
50288b5970eSSaravanan Sekar 		.uV_step = _step,				\
50388b5970eSSaravanan Sekar 		.min_uV = _min_uV,				\
50488b5970eSSaravanan Sekar 	}
50588b5970eSSaravanan Sekar 
50688b5970eSSaravanan Sekar #define PMBUS_REGULATOR(_name, _id)   PMBUS_REGULATOR_STEP(_name, _id, 0, 0, 0)
50788b5970eSSaravanan Sekar 
50888b5970eSSaravanan Sekar #define PMBUS_REGULATOR_STEP_ONE(_name, _voltages, _step, _min_uV)  \
50988b5970eSSaravanan Sekar 	{							\
51088b5970eSSaravanan Sekar 		.name = (_name),				\
51188b5970eSSaravanan Sekar 		.of_match = of_match_ptr(_name),		\
51288b5970eSSaravanan Sekar 		.regulators_node = of_match_ptr("regulators"),	\
5139d2ecfb7SGuenter Roeck 		.ops = &pmbus_regulator_ops,			\
5149d2ecfb7SGuenter Roeck 		.type = REGULATOR_VOLTAGE,			\
515ce603b18SGuenter Roeck 		.owner = THIS_MODULE,				\
516d3e33067SErik Rosen 		.n_voltages = _voltages,			\
51743f33b6eSGuenter Roeck 		.uV_step = _step,				\
51843f33b6eSGuenter Roeck 		.min_uV = _min_uV,				\
51943f33b6eSGuenter Roeck 	}
52043f33b6eSGuenter Roeck 
52143f33b6eSGuenter Roeck #define PMBUS_REGULATOR_ONE(_name)   PMBUS_REGULATOR_STEP_ONE(_name, 0, 0, 0)
5229c1ed894SGuenter Roeck 
52303e9bd8dSGuenter Roeck /* Function declarations */
52411c11998SAlan Tull 
52511c11998SAlan Tull void pmbus_clear_cache(struct i2c_client *client);
52611c11998SAlan Tull void pmbus_set_update(struct i2c_client *client, u8 reg, bool update);
52711c11998SAlan Tull int pmbus_set_page(struct i2c_client *client, int page, int phase);
5289d2ecfb7SGuenter Roeck int pmbus_read_word_data(struct i2c_client *client, int page, int phase,
5299d2ecfb7SGuenter Roeck 			 u8 reg);
5309d2ecfb7SGuenter Roeck int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,
531dd431939SStephen Kitt 			  u16 word);
5329d2ecfb7SGuenter Roeck int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
5339d2ecfb7SGuenter Roeck int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
534d206636eSAndrew Jeffery int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
535d206636eSAndrew Jeffery 			  u8 value);
536d206636eSAndrew Jeffery int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
537d206636eSAndrew Jeffery 			   u8 mask, u8 value);
538a7ac3718SEddie James void pmbus_clear_faults(struct i2c_client *client);
539a7ac3718SEddie James bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
540d206636eSAndrew Jeffery bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
541d206636eSAndrew Jeffery int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
542eb6489b6SEdward A. James const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
543eb6489b6SEdward A. James 						      *client);
5449d2ecfb7SGuenter Roeck int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id,
545 			      enum pmbus_fan_mode mode);
546 int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id,
547 			      enum pmbus_fan_mode mode);
548 int pmbus_lock_interruptible(struct i2c_client *client);
549 void pmbus_unlock(struct i2c_client *client);
550 int pmbus_update_fan(struct i2c_client *client, int page, int id,
551 		     u8 config, u8 mask, u16 command);
552 struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client);
553 
554 #endif /* PMBUS_H */
555