2 * pmbus.h - Common defines and structures for PMBus devices
4 * Copyright (c) 2010, 2011 Ericsson AB.
5 * Copyright (c) 2012 Guenter Roeck
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/regulator/driver.h>
32 PMBUS_OPERATION = 0x01,
33 PMBUS_ON_OFF_CONFIG = 0x02,
34 PMBUS_CLEAR_FAULTS = 0x03,
37 PMBUS_CAPABILITY = 0x19,
40 PMBUS_VOUT_MODE = 0x20,
41 PMBUS_VOUT_COMMAND = 0x21,
42 PMBUS_VOUT_TRIM = 0x22,
43 PMBUS_VOUT_CAL_OFFSET = 0x23,
44 PMBUS_VOUT_MAX = 0x24,
45 PMBUS_VOUT_MARGIN_HIGH = 0x25,
46 PMBUS_VOUT_MARGIN_LOW = 0x26,
47 PMBUS_VOUT_TRANSITION_RATE = 0x27,
48 PMBUS_VOUT_DROOP = 0x28,
49 PMBUS_VOUT_SCALE_LOOP = 0x29,
50 PMBUS_VOUT_SCALE_MONITOR = 0x2A,
52 PMBUS_COEFFICIENTS = 0x30,
53 PMBUS_POUT_MAX = 0x31,
55 PMBUS_FAN_CONFIG_12 = 0x3A,
56 PMBUS_FAN_COMMAND_1 = 0x3B,
57 PMBUS_FAN_COMMAND_2 = 0x3C,
58 PMBUS_FAN_CONFIG_34 = 0x3D,
59 PMBUS_FAN_COMMAND_3 = 0x3E,
60 PMBUS_FAN_COMMAND_4 = 0x3F,
62 PMBUS_VOUT_OV_FAULT_LIMIT = 0x40,
63 PMBUS_VOUT_OV_FAULT_RESPONSE = 0x41,
64 PMBUS_VOUT_OV_WARN_LIMIT = 0x42,
65 PMBUS_VOUT_UV_WARN_LIMIT = 0x43,
66 PMBUS_VOUT_UV_FAULT_LIMIT = 0x44,
67 PMBUS_VOUT_UV_FAULT_RESPONSE = 0x45,
68 PMBUS_IOUT_OC_FAULT_LIMIT = 0x46,
69 PMBUS_IOUT_OC_FAULT_RESPONSE = 0x47,
70 PMBUS_IOUT_OC_LV_FAULT_LIMIT = 0x48,
71 PMBUS_IOUT_OC_LV_FAULT_RESPONSE = 0x49,
72 PMBUS_IOUT_OC_WARN_LIMIT = 0x4A,
73 PMBUS_IOUT_UC_FAULT_LIMIT = 0x4B,
74 PMBUS_IOUT_UC_FAULT_RESPONSE = 0x4C,
76 PMBUS_OT_FAULT_LIMIT = 0x4F,
77 PMBUS_OT_FAULT_RESPONSE = 0x50,
78 PMBUS_OT_WARN_LIMIT = 0x51,
79 PMBUS_UT_WARN_LIMIT = 0x52,
80 PMBUS_UT_FAULT_LIMIT = 0x53,
81 PMBUS_UT_FAULT_RESPONSE = 0x54,
82 PMBUS_VIN_OV_FAULT_LIMIT = 0x55,
83 PMBUS_VIN_OV_FAULT_RESPONSE = 0x56,
84 PMBUS_VIN_OV_WARN_LIMIT = 0x57,
85 PMBUS_VIN_UV_WARN_LIMIT = 0x58,
86 PMBUS_VIN_UV_FAULT_LIMIT = 0x59,
88 PMBUS_IIN_OC_FAULT_LIMIT = 0x5B,
89 PMBUS_IIN_OC_WARN_LIMIT = 0x5D,
91 PMBUS_POUT_OP_FAULT_LIMIT = 0x68,
92 PMBUS_POUT_OP_WARN_LIMIT = 0x6A,
93 PMBUS_PIN_OP_WARN_LIMIT = 0x6B,
95 PMBUS_STATUS_BYTE = 0x78,
96 PMBUS_STATUS_WORD = 0x79,
97 PMBUS_STATUS_VOUT = 0x7A,
98 PMBUS_STATUS_IOUT = 0x7B,
99 PMBUS_STATUS_INPUT = 0x7C,
100 PMBUS_STATUS_TEMPERATURE = 0x7D,
101 PMBUS_STATUS_CML = 0x7E,
102 PMBUS_STATUS_OTHER = 0x7F,
103 PMBUS_STATUS_MFR_SPECIFIC = 0x80,
104 PMBUS_STATUS_FAN_12 = 0x81,
105 PMBUS_STATUS_FAN_34 = 0x82,
107 PMBUS_READ_VIN = 0x88,
108 PMBUS_READ_IIN = 0x89,
109 PMBUS_READ_VCAP = 0x8A,
110 PMBUS_READ_VOUT = 0x8B,
111 PMBUS_READ_IOUT = 0x8C,
112 PMBUS_READ_TEMPERATURE_1 = 0x8D,
113 PMBUS_READ_TEMPERATURE_2 = 0x8E,
114 PMBUS_READ_TEMPERATURE_3 = 0x8F,
115 PMBUS_READ_FAN_SPEED_1 = 0x90,
116 PMBUS_READ_FAN_SPEED_2 = 0x91,
117 PMBUS_READ_FAN_SPEED_3 = 0x92,
118 PMBUS_READ_FAN_SPEED_4 = 0x93,
119 PMBUS_READ_DUTY_CYCLE = 0x94,
120 PMBUS_READ_FREQUENCY = 0x95,
121 PMBUS_READ_POUT = 0x96,
122 PMBUS_READ_PIN = 0x97,
124 PMBUS_REVISION = 0x98,
126 PMBUS_MFR_MODEL = 0x9A,
127 PMBUS_MFR_REVISION = 0x9B,
128 PMBUS_MFR_LOCATION = 0x9C,
129 PMBUS_MFR_DATE = 0x9D,
130 PMBUS_MFR_SERIAL = 0x9E,
134 * Useful to support attributes which are not supported by standard PMBus
135 * registers but exist as manufacturer specific registers on individual chips.
136 * Must be mapped to real registers in device specific code.
139 * Virtual registers are all word size.
140 * READ registers are read-only; writes are either ignored or return an error.
141 * RESET registers are read/write. Reading reset registers returns zero
142 * (used for detection), writing any value causes the associated history to be
144 * Virtual registers have to be handled in device specific driver code. Chip
145 * driver code returns non-negative register values if a virtual register is
146 * supported, or a negative error code if not. The chip driver may return
147 * -ENODATA or any other error code in this case, though an error code other
148 * than -ENODATA is handled more efficiently and thus preferred. Either case,
149 * the calling PMBus core code will abort if the chip driver returns an error
150 * code when reading or writing virtual registers.
152 PMBUS_VIRT_BASE = 0x100,
153 PMBUS_VIRT_READ_TEMP_AVG,
154 PMBUS_VIRT_READ_TEMP_MIN,
155 PMBUS_VIRT_READ_TEMP_MAX,
156 PMBUS_VIRT_RESET_TEMP_HISTORY,
157 PMBUS_VIRT_READ_VIN_AVG,
158 PMBUS_VIRT_READ_VIN_MIN,
159 PMBUS_VIRT_READ_VIN_MAX,
160 PMBUS_VIRT_RESET_VIN_HISTORY,
161 PMBUS_VIRT_READ_IIN_AVG,
162 PMBUS_VIRT_READ_IIN_MIN,
163 PMBUS_VIRT_READ_IIN_MAX,
164 PMBUS_VIRT_RESET_IIN_HISTORY,
165 PMBUS_VIRT_READ_PIN_AVG,
166 PMBUS_VIRT_READ_PIN_MIN,
167 PMBUS_VIRT_READ_PIN_MAX,
168 PMBUS_VIRT_RESET_PIN_HISTORY,
169 PMBUS_VIRT_READ_POUT_AVG,
170 PMBUS_VIRT_READ_POUT_MIN,
171 PMBUS_VIRT_READ_POUT_MAX,
172 PMBUS_VIRT_RESET_POUT_HISTORY,
173 PMBUS_VIRT_READ_VOUT_AVG,
174 PMBUS_VIRT_READ_VOUT_MIN,
175 PMBUS_VIRT_READ_VOUT_MAX,
176 PMBUS_VIRT_RESET_VOUT_HISTORY,
177 PMBUS_VIRT_READ_IOUT_AVG,
178 PMBUS_VIRT_READ_IOUT_MIN,
179 PMBUS_VIRT_READ_IOUT_MAX,
180 PMBUS_VIRT_RESET_IOUT_HISTORY,
181 PMBUS_VIRT_READ_TEMP2_AVG,
182 PMBUS_VIRT_READ_TEMP2_MIN,
183 PMBUS_VIRT_READ_TEMP2_MAX,
184 PMBUS_VIRT_RESET_TEMP2_HISTORY,
186 PMBUS_VIRT_READ_VMON,
187 PMBUS_VIRT_VMON_UV_WARN_LIMIT,
188 PMBUS_VIRT_VMON_OV_WARN_LIMIT,
189 PMBUS_VIRT_VMON_UV_FAULT_LIMIT,
190 PMBUS_VIRT_VMON_OV_FAULT_LIMIT,
191 PMBUS_VIRT_STATUS_VMON,
197 #define PB_OPERATION_CONTROL_ON (1<<7)
202 #define PB_CAPABILITY_SMBALERT (1<<4)
203 #define PB_CAPABILITY_ERROR_CHECK (1<<7)
208 #define PB_VOUT_MODE_MODE_MASK 0xe0
209 #define PB_VOUT_MODE_PARAM_MASK 0x1f
211 #define PB_VOUT_MODE_LINEAR 0x00
212 #define PB_VOUT_MODE_VID 0x20
213 #define PB_VOUT_MODE_DIRECT 0x40
218 #define PB_FAN_2_PULSE_MASK ((1 << 0) | (1 << 1))
219 #define PB_FAN_2_RPM (1 << 2)
220 #define PB_FAN_2_INSTALLED (1 << 3)
221 #define PB_FAN_1_PULSE_MASK ((1 << 4) | (1 << 5))
222 #define PB_FAN_1_RPM (1 << 6)
223 #define PB_FAN_1_INSTALLED (1 << 7)
226 * STATUS_BYTE, STATUS_WORD (lower)
228 #define PB_STATUS_NONE_ABOVE (1<<0)
229 #define PB_STATUS_CML (1<<1)
230 #define PB_STATUS_TEMPERATURE (1<<2)
231 #define PB_STATUS_VIN_UV (1<<3)
232 #define PB_STATUS_IOUT_OC (1<<4)
233 #define PB_STATUS_VOUT_OV (1<<5)
234 #define PB_STATUS_OFF (1<<6)
235 #define PB_STATUS_BUSY (1<<7)
238 * STATUS_WORD (upper)
240 #define PB_STATUS_UNKNOWN (1<<8)
241 #define PB_STATUS_OTHER (1<<9)
242 #define PB_STATUS_FANS (1<<10)
243 #define PB_STATUS_POWER_GOOD_N (1<<11)
244 #define PB_STATUS_WORD_MFR (1<<12)
245 #define PB_STATUS_INPUT (1<<13)
246 #define PB_STATUS_IOUT_POUT (1<<14)
247 #define PB_STATUS_VOUT (1<<15)
252 #define PB_POUT_OP_WARNING (1<<0)
253 #define PB_POUT_OP_FAULT (1<<1)
254 #define PB_POWER_LIMITING (1<<2)
255 #define PB_CURRENT_SHARE_FAULT (1<<3)
256 #define PB_IOUT_UC_FAULT (1<<4)
257 #define PB_IOUT_OC_WARNING (1<<5)
258 #define PB_IOUT_OC_LV_FAULT (1<<6)
259 #define PB_IOUT_OC_FAULT (1<<7)
262 * STATUS_VOUT, STATUS_INPUT
264 #define PB_VOLTAGE_UV_FAULT (1<<4)
265 #define PB_VOLTAGE_UV_WARNING (1<<5)
266 #define PB_VOLTAGE_OV_WARNING (1<<6)
267 #define PB_VOLTAGE_OV_FAULT (1<<7)
272 #define PB_PIN_OP_WARNING (1<<0)
273 #define PB_IIN_OC_WARNING (1<<1)
274 #define PB_IIN_OC_FAULT (1<<2)
279 #define PB_TEMP_UT_FAULT (1<<4)
280 #define PB_TEMP_UT_WARNING (1<<5)
281 #define PB_TEMP_OT_WARNING (1<<6)
282 #define PB_TEMP_OT_FAULT (1<<7)
287 #define PB_FAN_AIRFLOW_WARNING (1<<0)
288 #define PB_FAN_AIRFLOW_FAULT (1<<1)
289 #define PB_FAN_FAN2_SPEED_OVERRIDE (1<<2)
290 #define PB_FAN_FAN1_SPEED_OVERRIDE (1<<3)
291 #define PB_FAN_FAN2_WARNING (1<<4)
292 #define PB_FAN_FAN1_WARNING (1<<5)
293 #define PB_FAN_FAN2_FAULT (1<<6)
294 #define PB_FAN_FAN1_FAULT (1<<7)
299 #define PB_CML_FAULT_OTHER_MEM_LOGIC (1<<0)
300 #define PB_CML_FAULT_OTHER_COMM (1<<1)
301 #define PB_CML_FAULT_PROCESSOR (1<<3)
302 #define PB_CML_FAULT_MEMORY (1<<4)
303 #define PB_CML_FAULT_PACKET_ERROR (1<<5)
304 #define PB_CML_FAULT_INVALID_DATA (1<<6)
305 #define PB_CML_FAULT_INVALID_COMMAND (1<<7)
307 enum pmbus_sensor_classes {
315 PSC_NUM_CLASSES /* Number of power sensor classes */
318 #define PMBUS_PAGES 32 /* Per PMBus specification */
320 /* Functionality bit mask */
321 #define PMBUS_HAVE_VIN (1 << 0)
322 #define PMBUS_HAVE_VCAP (1 << 1)
323 #define PMBUS_HAVE_VOUT (1 << 2)
324 #define PMBUS_HAVE_IIN (1 << 3)
325 #define PMBUS_HAVE_IOUT (1 << 4)
326 #define PMBUS_HAVE_PIN (1 << 5)
327 #define PMBUS_HAVE_POUT (1 << 6)
328 #define PMBUS_HAVE_FAN12 (1 << 7)
329 #define PMBUS_HAVE_FAN34 (1 << 8)
330 #define PMBUS_HAVE_TEMP (1 << 9)
331 #define PMBUS_HAVE_TEMP2 (1 << 10)
332 #define PMBUS_HAVE_TEMP3 (1 << 11)
333 #define PMBUS_HAVE_STATUS_VOUT (1 << 12)
334 #define PMBUS_HAVE_STATUS_IOUT (1 << 13)
335 #define PMBUS_HAVE_STATUS_INPUT (1 << 14)
336 #define PMBUS_HAVE_STATUS_TEMP (1 << 15)
337 #define PMBUS_HAVE_STATUS_FAN12 (1 << 16)
338 #define PMBUS_HAVE_STATUS_FAN34 (1 << 17)
339 #define PMBUS_HAVE_VMON (1 << 18)
340 #define PMBUS_HAVE_STATUS_VMON (1 << 19)
342 enum pmbus_data_format { linear = 0, direct, vid };
343 enum vrm_version { vr11 = 0, vr12 };
345 struct pmbus_driver_info {
346 int pages; /* Total number of pages */
347 enum pmbus_data_format format[PSC_NUM_CLASSES];
348 enum vrm_version vrm_version;
350 * Support one set of coefficients for each sensor type
351 * Used for chips providing data in direct mode.
353 int m[PSC_NUM_CLASSES]; /* mantissa for direct data format */
354 int b[PSC_NUM_CLASSES]; /* offset */
355 int R[PSC_NUM_CLASSES]; /* exponent */
357 u32 func[PMBUS_PAGES]; /* Functionality, per page */
359 * The following functions map manufacturing specific register values
360 * to PMBus standard register values. Specify only if mapping is
362 * Functions return the register value (read) or zero (write) if
363 * successful. A return value of -ENODATA indicates that there is no
364 * manufacturer specific register, but that a standard PMBus register
365 * may exist. Any other negative return value indicates that the
366 * register does not exist, and that no attempt should be made to read
367 * the standard register.
369 int (*read_byte_data)(struct i2c_client *client, int page, int reg);
370 int (*read_word_data)(struct i2c_client *client, int page, int reg);
371 int (*write_word_data)(struct i2c_client *client, int page, int reg,
373 int (*write_byte)(struct i2c_client *client, int page, u8 value);
375 * The identify function determines supported PMBus functionality.
376 * This function is only necessary if a chip driver supports multiple
377 * chips, and the chip functionality is not pre-determined.
379 int (*identify)(struct i2c_client *client,
380 struct pmbus_driver_info *info);
382 /* Regulator functionality, if supported by this chip driver. */
384 const struct regulator_desc *reg_desc;
389 extern const struct regulator_ops pmbus_regulator_ops;
391 /* Macro for filling in array of struct regulator_desc */
392 #define PMBUS_REGULATOR(_name, _id) \
394 .name = (_name # _id), \
396 .of_match = of_match_ptr(_name # _id), \
397 .regulators_node = of_match_ptr("regulators"), \
398 .ops = &pmbus_regulator_ops, \
399 .type = REGULATOR_VOLTAGE, \
400 .owner = THIS_MODULE, \
403 /* Function declarations */
405 void pmbus_clear_cache(struct i2c_client *client);
406 int pmbus_set_page(struct i2c_client *client, u8 page);
407 int pmbus_read_word_data(struct i2c_client *client, u8 page, u8 reg);
408 int pmbus_write_word_data(struct i2c_client *client, u8 page, u8 reg, u16 word);
409 int pmbus_read_byte_data(struct i2c_client *client, int page, u8 reg);
410 int pmbus_write_byte(struct i2c_client *client, int page, u8 value);
411 int pmbus_write_byte_data(struct i2c_client *client, int page, u8 reg,
413 int pmbus_update_byte_data(struct i2c_client *client, int page, u8 reg,
415 void pmbus_clear_faults(struct i2c_client *client);
416 bool pmbus_check_byte_register(struct i2c_client *client, int page, int reg);
417 bool pmbus_check_word_register(struct i2c_client *client, int page, int reg);
418 int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
419 struct pmbus_driver_info *info);
420 int pmbus_do_remove(struct i2c_client *client);
421 const struct pmbus_driver_info *pmbus_get_driver_info(struct i2c_client