xref: /linux/drivers/hwmon/pmbus/pmbus.h (revision 0c1acde1d3d0032814be89c838483471582bc32e)
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 
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 /*
2479e347728SGuenter Roeck  * WRITE_PROTECT
2489e347728SGuenter Roeck  */
2499e347728SGuenter Roeck #define PB_WP_ALL	BIT(7)	/* all but WRITE_PROTECT */
2509e347728SGuenter Roeck #define PB_WP_OP	BIT(6)	/* all but WP, OPERATION, PAGE */
2519e347728SGuenter Roeck #define PB_WP_VOUT	BIT(5)	/* all but WP, OPERATION, PAGE, VOUT, ON_OFF */
2529e347728SGuenter Roeck 
2539e347728SGuenter Roeck #define PB_WP_ANY	(PB_WP_ALL | PB_WP_OP | PB_WP_VOUT)
2549e347728SGuenter Roeck 
2559e347728SGuenter Roeck /*
2569d2ecfb7SGuenter Roeck  * CAPABILITY
2579d2ecfb7SGuenter Roeck  */
2582c052d42SGuenter Roeck #define PB_CAPABILITY_SMBALERT		BIT(4)
2592c052d42SGuenter Roeck #define PB_CAPABILITY_ERROR_CHECK	BIT(7)
2609d2ecfb7SGuenter Roeck 
2619d2ecfb7SGuenter Roeck /*
2629d2ecfb7SGuenter Roeck  * VOUT_MODE
2639d2ecfb7SGuenter Roeck  */
2649d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_MODE_MASK		0xe0
2659d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_PARAM_MASK		0x1f
2669d2ecfb7SGuenter Roeck 
2679d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_LINEAR		0x00
2689d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_VID		0x20
2699d2ecfb7SGuenter Roeck #define PB_VOUT_MODE_DIRECT		0x40
2709d2ecfb7SGuenter Roeck 
2719d2ecfb7SGuenter Roeck /*
2729d2ecfb7SGuenter Roeck  * Fan configuration
2739d2ecfb7SGuenter Roeck  */
2742c052d42SGuenter Roeck #define PB_FAN_2_PULSE_MASK		(BIT(0) | BIT(1))
2752c052d42SGuenter Roeck #define PB_FAN_2_RPM			BIT(2)
2762c052d42SGuenter Roeck #define PB_FAN_2_INSTALLED		BIT(3)
2772c052d42SGuenter Roeck #define PB_FAN_1_PULSE_MASK		(BIT(4) | BIT(5))
2782c052d42SGuenter Roeck #define PB_FAN_1_RPM			BIT(6)
2792c052d42SGuenter Roeck #define PB_FAN_1_INSTALLED		BIT(7)
2809d2ecfb7SGuenter Roeck 
281d206636eSAndrew Jeffery enum pmbus_fan_mode { percent = 0, rpm };
282d206636eSAndrew Jeffery 
2839d2ecfb7SGuenter Roeck /*
2849d2ecfb7SGuenter Roeck  * STATUS_BYTE, STATUS_WORD (lower)
2859d2ecfb7SGuenter Roeck  */
2862c052d42SGuenter Roeck #define PB_STATUS_NONE_ABOVE		BIT(0)
2872c052d42SGuenter Roeck #define PB_STATUS_CML			BIT(1)
2882c052d42SGuenter Roeck #define PB_STATUS_TEMPERATURE		BIT(2)
2892c052d42SGuenter Roeck #define PB_STATUS_VIN_UV		BIT(3)
2902c052d42SGuenter Roeck #define PB_STATUS_IOUT_OC		BIT(4)
2912c052d42SGuenter Roeck #define PB_STATUS_VOUT_OV		BIT(5)
2922c052d42SGuenter Roeck #define PB_STATUS_OFF			BIT(6)
2932c052d42SGuenter Roeck #define PB_STATUS_BUSY			BIT(7)
2949d2ecfb7SGuenter Roeck 
2959d2ecfb7SGuenter Roeck /*
2969d2ecfb7SGuenter Roeck  * STATUS_WORD (upper)
2979d2ecfb7SGuenter Roeck  */
2982c052d42SGuenter Roeck #define PB_STATUS_UNKNOWN		BIT(8)
2992c052d42SGuenter Roeck #define PB_STATUS_OTHER			BIT(9)
3002c052d42SGuenter Roeck #define PB_STATUS_FANS			BIT(10)
3012c052d42SGuenter Roeck #define PB_STATUS_POWER_GOOD_N		BIT(11)
3022c052d42SGuenter Roeck #define PB_STATUS_WORD_MFR		BIT(12)
3032c052d42SGuenter Roeck #define PB_STATUS_INPUT			BIT(13)
3042c052d42SGuenter Roeck #define PB_STATUS_IOUT_POUT		BIT(14)
3052c052d42SGuenter Roeck #define PB_STATUS_VOUT			BIT(15)
3069d2ecfb7SGuenter Roeck 
3079d2ecfb7SGuenter Roeck /*
3089d2ecfb7SGuenter Roeck  * STATUS_IOUT
3099d2ecfb7SGuenter Roeck  */
3102c052d42SGuenter Roeck #define PB_POUT_OP_WARNING		BIT(0)
3112c052d42SGuenter Roeck #define PB_POUT_OP_FAULT		BIT(1)
3122c052d42SGuenter Roeck #define PB_POWER_LIMITING		BIT(2)
3132c052d42SGuenter Roeck #define PB_CURRENT_SHARE_FAULT		BIT(3)
3142c052d42SGuenter Roeck #define PB_IOUT_UC_FAULT		BIT(4)
3152c052d42SGuenter Roeck #define PB_IOUT_OC_WARNING		BIT(5)
3162c052d42SGuenter Roeck #define PB_IOUT_OC_LV_FAULT		BIT(6)
3172c052d42SGuenter Roeck #define PB_IOUT_OC_FAULT		BIT(7)
3189d2ecfb7SGuenter Roeck 
3199d2ecfb7SGuenter Roeck /*
3209d2ecfb7SGuenter Roeck  * STATUS_VOUT, STATUS_INPUT
3219d2ecfb7SGuenter Roeck  */
3222c052d42SGuenter Roeck #define PB_VOLTAGE_UV_FAULT		BIT(4)
3232c052d42SGuenter Roeck #define PB_VOLTAGE_UV_WARNING		BIT(5)
3242c052d42SGuenter Roeck #define PB_VOLTAGE_OV_WARNING		BIT(6)
3252c052d42SGuenter Roeck #define PB_VOLTAGE_OV_FAULT		BIT(7)
3269d2ecfb7SGuenter Roeck 
3279d2ecfb7SGuenter Roeck /*
3289d2ecfb7SGuenter Roeck  * STATUS_INPUT
3299d2ecfb7SGuenter Roeck  */
3302c052d42SGuenter Roeck #define PB_PIN_OP_WARNING		BIT(0)
3312c052d42SGuenter Roeck #define PB_IIN_OC_WARNING		BIT(1)
3322c052d42SGuenter Roeck #define PB_IIN_OC_FAULT			BIT(2)
3339d2ecfb7SGuenter Roeck 
3349d2ecfb7SGuenter Roeck /*
3359d2ecfb7SGuenter Roeck  * STATUS_TEMPERATURE
3369d2ecfb7SGuenter Roeck  */
3372c052d42SGuenter Roeck #define PB_TEMP_UT_FAULT		BIT(4)
3382c052d42SGuenter Roeck #define PB_TEMP_UT_WARNING		BIT(5)
3392c052d42SGuenter Roeck #define PB_TEMP_OT_WARNING		BIT(6)
3402c052d42SGuenter Roeck #define PB_TEMP_OT_FAULT		BIT(7)
3419d2ecfb7SGuenter Roeck 
3429d2ecfb7SGuenter Roeck /*
3439d2ecfb7SGuenter Roeck  * STATUS_FAN
3449d2ecfb7SGuenter Roeck  */
3452c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_WARNING		BIT(0)
3462c052d42SGuenter Roeck #define PB_FAN_AIRFLOW_FAULT		BIT(1)
3472c052d42SGuenter Roeck #define PB_FAN_FAN2_SPEED_OVERRIDE	BIT(2)
3482c052d42SGuenter Roeck #define PB_FAN_FAN1_SPEED_OVERRIDE	BIT(3)
3492c052d42SGuenter Roeck #define PB_FAN_FAN2_WARNING		BIT(4)
3502c052d42SGuenter Roeck #define PB_FAN_FAN1_WARNING		BIT(5)
3512c052d42SGuenter Roeck #define PB_FAN_FAN2_FAULT		BIT(6)
3522c052d42SGuenter Roeck #define PB_FAN_FAN1_FAULT		BIT(7)
3539d2ecfb7SGuenter Roeck 
3549d2ecfb7SGuenter Roeck /*
3559d2ecfb7SGuenter Roeck  * CML_FAULT_STATUS
3569d2ecfb7SGuenter Roeck  */
3572c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_MEM_LOGIC	BIT(0)
3582c052d42SGuenter Roeck #define PB_CML_FAULT_OTHER_COMM		BIT(1)
3592c052d42SGuenter Roeck #define PB_CML_FAULT_PROCESSOR		BIT(3)
3602c052d42SGuenter Roeck #define PB_CML_FAULT_MEMORY		BIT(4)
3612c052d42SGuenter Roeck #define PB_CML_FAULT_PACKET_ERROR	BIT(5)
3622c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_DATA	BIT(6)
3632c052d42SGuenter Roeck #define PB_CML_FAULT_INVALID_COMMAND	BIT(7)
3649d2ecfb7SGuenter Roeck 
3659d2ecfb7SGuenter Roeck enum pmbus_sensor_classes {
3669d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_IN = 0,
3679d2ecfb7SGuenter Roeck 	PSC_VOLTAGE_OUT,
3689d2ecfb7SGuenter Roeck 	PSC_CURRENT_IN,
3699d2ecfb7SGuenter Roeck 	PSC_CURRENT_OUT,
3709d2ecfb7SGuenter Roeck 	PSC_POWER,
3719d2ecfb7SGuenter Roeck 	PSC_TEMPERATURE,
3729d2ecfb7SGuenter Roeck 	PSC_FAN,
373d206636eSAndrew Jeffery 	PSC_PWM,
3749d2ecfb7SGuenter Roeck 	PSC_NUM_CLASSES		/* Number of power sensor classes */
3759d2ecfb7SGuenter Roeck };
3769d2ecfb7SGuenter Roeck 
3779d2ecfb7SGuenter Roeck #define PMBUS_PAGES	32	/* Per PMBus specification */
378*0c1acde1SVadim Pasternak #define PMBUS_PHASES	10	/* Maximum number of phases per page */
3799d2ecfb7SGuenter Roeck 
3809d2ecfb7SGuenter Roeck /* Functionality bit mask */
3812c052d42SGuenter Roeck #define PMBUS_HAVE_VIN		BIT(0)
3822c052d42SGuenter Roeck #define PMBUS_HAVE_VCAP		BIT(1)
3832c052d42SGuenter Roeck #define PMBUS_HAVE_VOUT		BIT(2)
3842c052d42SGuenter Roeck #define PMBUS_HAVE_IIN		BIT(3)
3852c052d42SGuenter Roeck #define PMBUS_HAVE_IOUT		BIT(4)
3862c052d42SGuenter Roeck #define PMBUS_HAVE_PIN		BIT(5)
3872c052d42SGuenter Roeck #define PMBUS_HAVE_POUT		BIT(6)
3882c052d42SGuenter Roeck #define PMBUS_HAVE_FAN12	BIT(7)
3892c052d42SGuenter Roeck #define PMBUS_HAVE_FAN34	BIT(8)
3902c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP		BIT(9)
3912c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP2	BIT(10)
3922c052d42SGuenter Roeck #define PMBUS_HAVE_TEMP3	BIT(11)
3932c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VOUT	BIT(12)
3942c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_IOUT	BIT(13)
3952c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_INPUT	BIT(14)
3962c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_TEMP	BIT(15)
3972c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN12	BIT(16)
3982c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_FAN34	BIT(17)
3992c052d42SGuenter Roeck #define PMBUS_HAVE_VMON		BIT(18)
4002c052d42SGuenter Roeck #define PMBUS_HAVE_STATUS_VMON	BIT(19)
401d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM12	BIT(20)
402d206636eSAndrew Jeffery #define PMBUS_HAVE_PWM34	BIT(21)
40349c4455dSAdamski, Krzysztof (Nokia - PL/Wroclaw) #define PMBUS_HAVE_SAMPLES	BIT(22)
4049d2ecfb7SGuenter Roeck 
40516358542SGuenter Roeck #define PMBUS_PHASE_VIRTUAL	BIT(30)	/* Phases on this page are virtual */
40616358542SGuenter Roeck #define PMBUS_PAGE_VIRTUAL	BIT(31)	/* Page is virtual */
407464df6faSAndrew Jeffery 
4081061d851SGuenter Roeck enum pmbus_data_format { linear = 0, direct, vid };
4099d72340bSVadim Pasternak enum vrm_version { vr11 = 0, vr12, vr13, imvp9, amd625mv };
4101061d851SGuenter Roeck 
4119d2ecfb7SGuenter Roeck struct pmbus_driver_info {
4129d2ecfb7SGuenter Roeck 	int pages;		/* Total number of pages */
41316358542SGuenter Roeck 	u8 phases[PMBUS_PAGES];	/* Number of phases per page */
4141061d851SGuenter Roeck 	enum pmbus_data_format format[PSC_NUM_CLASSES];
415b9fa0a3aSVadim Pasternak 	enum vrm_version vrm_version[PMBUS_PAGES]; /* vrm version per page */
4169d2ecfb7SGuenter Roeck 	/*
4179d2ecfb7SGuenter Roeck 	 * Support one set of coefficients for each sensor type
4189d2ecfb7SGuenter Roeck 	 * Used for chips providing data in direct mode.
4199d2ecfb7SGuenter Roeck 	 */
4209d2ecfb7SGuenter Roeck 	int m[PSC_NUM_CLASSES];	/* mantissa for direct data format */
4219d2ecfb7SGuenter Roeck 	int b[PSC_NUM_CLASSES];	/* offset */
4229d2ecfb7SGuenter Roeck 	int R[PSC_NUM_CLASSES];	/* exponent */
4239d2ecfb7SGuenter Roeck 
4249d2ecfb7SGuenter Roeck 	u32 func[PMBUS_PAGES];	/* Functionality, per page */
42516358542SGuenter Roeck 	u32 pfunc[PMBUS_PHASES];/* Functionality, per phase */
4269d2ecfb7SGuenter Roeck 	/*
4279d2ecfb7SGuenter Roeck 	 * The following functions map manufacturing specific register values
4289d2ecfb7SGuenter Roeck 	 * to PMBus standard register values. Specify only if mapping is
4299d2ecfb7SGuenter Roeck 	 * necessary.
43020fcfe17SGuenter Roeck 	 * Functions return the register value (read) or zero (write) if
43120fcfe17SGuenter Roeck 	 * successful. A return value of -ENODATA indicates that there is no
43220fcfe17SGuenter Roeck 	 * manufacturer specific register, but that a standard PMBus register
43320fcfe17SGuenter Roeck 	 * may exist. Any other negative return value indicates that the
43420fcfe17SGuenter Roeck 	 * register does not exist, and that no attempt should be made to read
43520fcfe17SGuenter Roeck 	 * the standard register.
4369d2ecfb7SGuenter Roeck 	 */
4379d2ecfb7SGuenter Roeck 	int (*read_byte_data)(struct i2c_client *client, int page, int reg);
43843f33b6eSGuenter Roeck 	int (*read_word_data)(struct i2c_client *client, int page, int phase,
43943f33b6eSGuenter Roeck 			      int reg);
44046243f3aSGuenter Roeck 	int (*write_word_data)(struct i2c_client *client, int page, int reg,
44146243f3aSGuenter Roeck 			       u16 word);
442044cd3a5SGuenter Roeck 	int (*write_byte)(struct i2c_client *client, int page, u8 value);
4439d2ecfb7SGuenter Roeck 	/*
4449d2ecfb7SGuenter Roeck 	 * The identify function determines supported PMBus functionality.
4459d2ecfb7SGuenter Roeck 	 * This function is only necessary if a chip driver supports multiple
4469d2ecfb7SGuenter Roeck 	 * chips, and the chip functionality is not pre-determined.
4479d2ecfb7SGuenter Roeck 	 */
4489d2ecfb7SGuenter Roeck 	int (*identify)(struct i2c_client *client,
4499d2ecfb7SGuenter Roeck 			struct pmbus_driver_info *info);
450ddbb4db4SAlan Tull 
451ddbb4db4SAlan Tull 	/* Regulator functionality, if supported by this chip driver. */
452ddbb4db4SAlan Tull 	int num_regulators;
453ddbb4db4SAlan Tull 	const struct regulator_desc *reg_desc;
454991d6799Skrzysztof.adamski@nokia.com 
455991d6799Skrzysztof.adamski@nokia.com 	/* custom attributes */
456991d6799Skrzysztof.adamski@nokia.com 	const struct attribute_group **groups;
4579d2ecfb7SGuenter Roeck };
4589d2ecfb7SGuenter Roeck 
459ddbb4db4SAlan Tull /* Regulator ops */
460ddbb4db4SAlan Tull 
461a07d7311SAxel Lin extern const struct regulator_ops pmbus_regulator_ops;
462ddbb4db4SAlan Tull 
463ddbb4db4SAlan Tull /* Macro for filling in array of struct regulator_desc */
464ddbb4db4SAlan Tull #define PMBUS_REGULATOR(_name, _id)				\
465ddbb4db4SAlan Tull 	[_id] = {						\
466ddbb4db4SAlan Tull 		.name = (_name # _id),				\
467ddbb4db4SAlan Tull 		.id = (_id),					\
468ddbb4db4SAlan Tull 		.of_match = of_match_ptr(_name # _id),		\
469ddbb4db4SAlan Tull 		.regulators_node = of_match_ptr("regulators"),	\
470ddbb4db4SAlan Tull 		.ops = &pmbus_regulator_ops,			\
4717b7a8b42SAxel Lin 		.type = REGULATOR_VOLTAGE,			\
472ddbb4db4SAlan Tull 		.owner = THIS_MODULE,				\
473ddbb4db4SAlan Tull 	}
474ddbb4db4SAlan Tull 
4759d2ecfb7SGuenter Roeck /* Function declarations */
4769d2ecfb7SGuenter Roeck 
477ce603b18SGuenter Roeck void pmbus_clear_cache(struct i2c_client *client);
478d3e33067SErik Rosen void pmbus_set_update(struct i2c_client *client, u8 reg, bool update);
47943f33b6eSGuenter Roeck int pmbus_set_page(struct i2c_client *client, int page, int phase);
48043f33b6eSGuenter Roeck int pmbus_read_word_data(struct i2c_client *client, int page, int phase,
48143f33b6eSGuenter Roeck 			 u8 reg);
48243f33b6eSGuenter Roeck int pmbus_write_word_data(struct i2c_client *client, int page, u8 reg,
48343f33b6eSGuenter Roeck 			  u16 word);
4849c1ed894SGuenter Roeck int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
48503e9bd8dSGuenter Roeck int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
48611c11998SAlan Tull int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
48711c11998SAlan Tull 			  u8 value);
48811c11998SAlan Tull int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
48911c11998SAlan Tull 			   u8 mask, u8 value);
4909d2ecfb7SGuenter Roeck void pmbus_clear_faults(struct i2c_client *client);
4919d2ecfb7SGuenter Roeck bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
4929d2ecfb7SGuenter Roeck bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
493dd431939SStephen Kitt int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);
4949d2ecfb7SGuenter Roeck const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client
4959d2ecfb7SGuenter Roeck 						      *client);
496d206636eSAndrew Jeffery int pmbus_get_fan_rate_device(struct i2c_client *client, int page, int id,
497d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
498d206636eSAndrew Jeffery int pmbus_get_fan_rate_cached(struct i2c_client *client, int page, int id,
499d206636eSAndrew Jeffery 			      enum pmbus_fan_mode mode);
500d206636eSAndrew Jeffery int pmbus_update_fan(struct i2c_client *client, int page, int id,
501d206636eSAndrew Jeffery 		     u8 config, u8 mask, u16 command);
502eb6489b6SEdward A. James struct dentry *pmbus_get_debugfs_dir(struct i2c_client *client);
503eb6489b6SEdward A. James 
5049d2ecfb7SGuenter Roeck #endif /* PMBUS_H */
505