1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Hardware monitoring driver for Analog Devices ADM1275 Hot-Swap Controller
4 * and Digital Power Monitor
6 * Copyright (c) 2011 Ericsson AB.
7 * Copyright (c) 2018 Guenter Roeck
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/err.h>
14 #include <linux/slab.h>
15 #include <linux/i2c.h>
16 #include <linux/bitops.h>
17 #include <linux/bitfield.h>
18 #include <linux/log2.h>
21 enum chips
{ adm1075
, adm1272
, adm1275
, adm1276
, adm1278
, adm1293
, adm1294
};
23 #define ADM1275_MFR_STATUS_IOUT_WARN2 BIT(0)
24 #define ADM1293_MFR_STATUS_VAUX_UV_WARN BIT(5)
25 #define ADM1293_MFR_STATUS_VAUX_OV_WARN BIT(6)
27 #define ADM1275_PEAK_IOUT 0xd0
28 #define ADM1275_PEAK_VIN 0xd1
29 #define ADM1275_PEAK_VOUT 0xd2
30 #define ADM1275_PMON_CONFIG 0xd4
32 #define ADM1275_VIN_VOUT_SELECT BIT(6)
33 #define ADM1275_VRANGE BIT(5)
34 #define ADM1075_IRANGE_50 BIT(4)
35 #define ADM1075_IRANGE_25 BIT(3)
36 #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4))
38 #define ADM1272_IRANGE BIT(0)
40 #define ADM1278_TEMP1_EN BIT(3)
41 #define ADM1278_VIN_EN BIT(2)
42 #define ADM1278_VOUT_EN BIT(1)
44 #define ADM1293_IRANGE_25 0
45 #define ADM1293_IRANGE_50 BIT(6)
46 #define ADM1293_IRANGE_100 BIT(7)
47 #define ADM1293_IRANGE_200 (BIT(6) | BIT(7))
48 #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7))
50 #define ADM1293_VIN_SEL_012 BIT(2)
51 #define ADM1293_VIN_SEL_074 BIT(3)
52 #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3))
53 #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3))
55 #define ADM1293_VAUX_EN BIT(1)
57 #define ADM1278_PEAK_TEMP 0xd7
58 #define ADM1275_IOUT_WARN2_LIMIT 0xd7
59 #define ADM1275_DEVICE_CONFIG 0xd8
61 #define ADM1275_IOUT_WARN2_SELECT BIT(4)
63 #define ADM1276_PEAK_PIN 0xda
64 #define ADM1075_READ_VAUX 0xdd
65 #define ADM1075_VAUX_OV_WARN_LIMIT 0xde
66 #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf
67 #define ADM1293_IOUT_MIN 0xe3
68 #define ADM1293_PIN_MIN 0xe4
69 #define ADM1075_VAUX_STATUS 0xf6
71 #define ADM1075_VAUX_OV_WARN BIT(7)
72 #define ADM1075_VAUX_UV_WARN BIT(6)
74 #define ADM1275_VI_AVG_SHIFT 0
75 #define ADM1275_VI_AVG_MASK GENMASK(ADM1275_VI_AVG_SHIFT + 2, \
77 #define ADM1275_SAMPLES_AVG_MAX 128
79 #define ADM1278_PWR_AVG_SHIFT 11
80 #define ADM1278_PWR_AVG_MASK GENMASK(ADM1278_PWR_AVG_SHIFT + 2, \
81 ADM1278_PWR_AVG_SHIFT)
82 #define ADM1278_VI_AVG_SHIFT 8
83 #define ADM1278_VI_AVG_MASK GENMASK(ADM1278_VI_AVG_SHIFT + 2, \
91 bool have_vaux_status
;
92 bool have_mfr_vaux_status
;
97 bool have_power_sampling
;
98 struct pmbus_driver_info info
;
101 #define to_adm1275_data(x) container_of(x, struct adm1275_data, info)
103 struct coefficients
{
109 static const struct coefficients adm1075_coefficients
[] = {
110 [0] = { 27169, 0, -1 }, /* voltage */
111 [1] = { 806, 20475, -1 }, /* current, irange25 */
112 [2] = { 404, 20475, -1 }, /* current, irange50 */
113 [3] = { 8549, 0, -1 }, /* power, irange25 */
114 [4] = { 4279, 0, -1 }, /* power, irange50 */
117 static const struct coefficients adm1272_coefficients
[] = {
118 [0] = { 6770, 0, -2 }, /* voltage, vrange 60V */
119 [1] = { 4062, 0, -2 }, /* voltage, vrange 100V */
120 [2] = { 1326, 20480, -1 }, /* current, vsense range 15mV */
121 [3] = { 663, 20480, -1 }, /* current, vsense range 30mV */
122 [4] = { 3512, 0, -2 }, /* power, vrange 60V, irange 15mV */
123 [5] = { 21071, 0, -3 }, /* power, vrange 100V, irange 15mV */
124 [6] = { 17561, 0, -3 }, /* power, vrange 60V, irange 30mV */
125 [7] = { 10535, 0, -3 }, /* power, vrange 100V, irange 30mV */
126 [8] = { 42, 31871, -1 }, /* temperature */
130 static const struct coefficients adm1275_coefficients
[] = {
131 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
132 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
133 [2] = { 807, 20475, -1 }, /* current */
136 static const struct coefficients adm1276_coefficients
[] = {
137 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
138 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
139 [2] = { 807, 20475, -1 }, /* current */
140 [3] = { 6043, 0, -2 }, /* power, vrange set */
141 [4] = { 2115, 0, -1 }, /* power, vrange not set */
144 static const struct coefficients adm1278_coefficients
[] = {
145 [0] = { 19599, 0, -2 }, /* voltage */
146 [1] = { 800, 20475, -1 }, /* current */
147 [2] = { 6123, 0, -2 }, /* power */
148 [3] = { 42, 31880, -1 }, /* temperature */
151 static const struct coefficients adm1293_coefficients
[] = {
152 [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */
153 [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */
154 [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */
155 [3] = { 8000, -100, -2 }, /* current, irange25 */
156 [4] = { 4000, -100, -2 }, /* current, irange50 */
157 [5] = { 20000, -1000, -3 }, /* current, irange100 */
158 [6] = { 10000, -1000, -3 }, /* current, irange200 */
159 [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */
160 [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */
161 [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */
162 [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */
163 [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */
164 [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */
165 [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */
166 [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */
167 [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */
168 [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */
169 [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */
170 [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */
173 static int adm1275_read_pmon_config(const struct adm1275_data
*data
,
174 struct i2c_client
*client
, bool is_power
)
180 * The PMON configuration register is a 16-bit register only on chips
181 * supporting power average sampling. On other chips it is an 8-bit
184 if (data
->have_power_sampling
) {
185 ret
= i2c_smbus_read_word_data(client
, ADM1275_PMON_CONFIG
);
186 mask
= is_power
? ADM1278_PWR_AVG_MASK
: ADM1278_VI_AVG_MASK
;
187 shift
= is_power
? ADM1278_PWR_AVG_SHIFT
: ADM1278_VI_AVG_SHIFT
;
189 ret
= i2c_smbus_read_byte_data(client
, ADM1275_PMON_CONFIG
);
190 mask
= ADM1275_VI_AVG_MASK
;
191 shift
= ADM1275_VI_AVG_SHIFT
;
196 return (ret
& mask
) >> shift
;
199 static int adm1275_write_pmon_config(const struct adm1275_data
*data
,
200 struct i2c_client
*client
,
201 bool is_power
, u16 word
)
206 if (data
->have_power_sampling
) {
207 ret
= i2c_smbus_read_word_data(client
, ADM1275_PMON_CONFIG
);
208 mask
= is_power
? ADM1278_PWR_AVG_MASK
: ADM1278_VI_AVG_MASK
;
209 shift
= is_power
? ADM1278_PWR_AVG_SHIFT
: ADM1278_VI_AVG_SHIFT
;
211 ret
= i2c_smbus_read_byte_data(client
, ADM1275_PMON_CONFIG
);
212 mask
= ADM1275_VI_AVG_MASK
;
213 shift
= ADM1275_VI_AVG_SHIFT
;
218 word
= (ret
& ~mask
) | ((word
<< shift
) & mask
);
219 if (data
->have_power_sampling
)
220 ret
= i2c_smbus_write_word_data(client
, ADM1275_PMON_CONFIG
,
223 ret
= i2c_smbus_write_byte_data(client
, ADM1275_PMON_CONFIG
,
229 static int adm1275_read_word_data(struct i2c_client
*client
, int page
, int reg
)
231 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
232 const struct adm1275_data
*data
= to_adm1275_data(info
);
239 case PMBUS_IOUT_UC_FAULT_LIMIT
:
240 if (!data
->have_uc_fault
)
242 ret
= pmbus_read_word_data(client
, 0, ADM1275_IOUT_WARN2_LIMIT
);
244 case PMBUS_IOUT_OC_FAULT_LIMIT
:
245 if (!data
->have_oc_fault
)
247 ret
= pmbus_read_word_data(client
, 0, ADM1275_IOUT_WARN2_LIMIT
);
249 case PMBUS_VOUT_OV_WARN_LIMIT
:
252 ret
= pmbus_read_word_data(client
, 0,
253 ADM1075_VAUX_OV_WARN_LIMIT
);
255 case PMBUS_VOUT_UV_WARN_LIMIT
:
258 ret
= pmbus_read_word_data(client
, 0,
259 ADM1075_VAUX_UV_WARN_LIMIT
);
261 case PMBUS_READ_VOUT
:
264 ret
= pmbus_read_word_data(client
, 0, ADM1075_READ_VAUX
);
266 case PMBUS_VIRT_READ_IOUT_MIN
:
267 if (!data
->have_iout_min
)
269 ret
= pmbus_read_word_data(client
, 0, ADM1293_IOUT_MIN
);
271 case PMBUS_VIRT_READ_IOUT_MAX
:
272 ret
= pmbus_read_word_data(client
, 0, ADM1275_PEAK_IOUT
);
274 case PMBUS_VIRT_READ_VOUT_MAX
:
275 ret
= pmbus_read_word_data(client
, 0, ADM1275_PEAK_VOUT
);
277 case PMBUS_VIRT_READ_VIN_MAX
:
278 ret
= pmbus_read_word_data(client
, 0, ADM1275_PEAK_VIN
);
280 case PMBUS_VIRT_READ_PIN_MIN
:
281 if (!data
->have_pin_min
)
283 ret
= pmbus_read_word_data(client
, 0, ADM1293_PIN_MIN
);
285 case PMBUS_VIRT_READ_PIN_MAX
:
286 if (!data
->have_pin_max
)
288 ret
= pmbus_read_word_data(client
, 0, ADM1276_PEAK_PIN
);
290 case PMBUS_VIRT_READ_TEMP_MAX
:
291 if (!data
->have_temp_max
)
293 ret
= pmbus_read_word_data(client
, 0, ADM1278_PEAK_TEMP
);
295 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
296 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
297 case PMBUS_VIRT_RESET_VIN_HISTORY
:
299 case PMBUS_VIRT_RESET_PIN_HISTORY
:
300 if (!data
->have_pin_max
)
303 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
304 if (!data
->have_temp_max
)
307 case PMBUS_VIRT_POWER_SAMPLES
:
308 if (!data
->have_power_sampling
)
310 ret
= adm1275_read_pmon_config(data
, client
, true);
315 case PMBUS_VIRT_IN_SAMPLES
:
316 case PMBUS_VIRT_CURR_SAMPLES
:
317 ret
= adm1275_read_pmon_config(data
, client
, false);
329 static int adm1275_write_word_data(struct i2c_client
*client
, int page
, int reg
,
332 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
333 const struct adm1275_data
*data
= to_adm1275_data(info
);
340 case PMBUS_IOUT_UC_FAULT_LIMIT
:
341 case PMBUS_IOUT_OC_FAULT_LIMIT
:
342 ret
= pmbus_write_word_data(client
, 0, ADM1275_IOUT_WARN2_LIMIT
,
345 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
346 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_IOUT
, 0);
347 if (!ret
&& data
->have_iout_min
)
348 ret
= pmbus_write_word_data(client
, 0,
349 ADM1293_IOUT_MIN
, 0);
351 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
352 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VOUT
, 0);
354 case PMBUS_VIRT_RESET_VIN_HISTORY
:
355 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VIN
, 0);
357 case PMBUS_VIRT_RESET_PIN_HISTORY
:
358 ret
= pmbus_write_word_data(client
, 0, ADM1276_PEAK_PIN
, 0);
359 if (!ret
&& data
->have_pin_min
)
360 ret
= pmbus_write_word_data(client
, 0,
363 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
364 ret
= pmbus_write_word_data(client
, 0, ADM1278_PEAK_TEMP
, 0);
366 case PMBUS_VIRT_POWER_SAMPLES
:
367 if (!data
->have_power_sampling
)
369 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
370 ret
= adm1275_write_pmon_config(data
, client
, true,
373 case PMBUS_VIRT_IN_SAMPLES
:
374 case PMBUS_VIRT_CURR_SAMPLES
:
375 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
376 ret
= adm1275_write_pmon_config(data
, client
, false,
386 static int adm1275_read_byte_data(struct i2c_client
*client
, int page
, int reg
)
388 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
389 const struct adm1275_data
*data
= to_adm1275_data(info
);
396 case PMBUS_STATUS_IOUT
:
397 ret
= pmbus_read_byte_data(client
, page
, PMBUS_STATUS_IOUT
);
400 if (!data
->have_oc_fault
&& !data
->have_uc_fault
)
402 mfr_status
= pmbus_read_byte_data(client
, page
,
403 PMBUS_STATUS_MFR_SPECIFIC
);
406 if (mfr_status
& ADM1275_MFR_STATUS_IOUT_WARN2
) {
407 ret
|= data
->have_oc_fault
?
408 PB_IOUT_OC_FAULT
: PB_IOUT_UC_FAULT
;
411 case PMBUS_STATUS_VOUT
:
415 if (data
->have_vaux_status
) {
416 mfr_status
= pmbus_read_byte_data(client
, 0,
417 ADM1075_VAUX_STATUS
);
420 if (mfr_status
& ADM1075_VAUX_OV_WARN
)
421 ret
|= PB_VOLTAGE_OV_WARNING
;
422 if (mfr_status
& ADM1075_VAUX_UV_WARN
)
423 ret
|= PB_VOLTAGE_UV_WARNING
;
424 } else if (data
->have_mfr_vaux_status
) {
425 mfr_status
= pmbus_read_byte_data(client
, page
,
426 PMBUS_STATUS_MFR_SPECIFIC
);
429 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_OV_WARN
)
430 ret
|= PB_VOLTAGE_OV_WARNING
;
431 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_UV_WARN
)
432 ret
|= PB_VOLTAGE_UV_WARNING
;
442 static const struct i2c_device_id adm1275_id
[] = {
443 { "adm1075", adm1075
},
444 { "adm1272", adm1272
},
445 { "adm1275", adm1275
},
446 { "adm1276", adm1276
},
447 { "adm1278", adm1278
},
448 { "adm1293", adm1293
},
449 { "adm1294", adm1294
},
452 MODULE_DEVICE_TABLE(i2c
, adm1275_id
);
454 static int adm1275_probe(struct i2c_client
*client
,
455 const struct i2c_device_id
*id
)
457 u8 block_buffer
[I2C_SMBUS_BLOCK_MAX
+ 1];
458 int config
, device_config
;
460 struct pmbus_driver_info
*info
;
461 struct adm1275_data
*data
;
462 const struct i2c_device_id
*mid
;
463 const struct coefficients
*coefficients
;
464 int vindex
= -1, voindex
= -1, cindex
= -1, pindex
= -1;
468 if (!i2c_check_functionality(client
->adapter
,
469 I2C_FUNC_SMBUS_READ_BYTE_DATA
470 | I2C_FUNC_SMBUS_BLOCK_DATA
))
473 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_ID
, block_buffer
);
475 dev_err(&client
->dev
, "Failed to read Manufacturer ID\n");
478 if (ret
!= 3 || strncmp(block_buffer
, "ADI", 3)) {
479 dev_err(&client
->dev
, "Unsupported Manufacturer ID\n");
483 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_MODEL
, block_buffer
);
485 dev_err(&client
->dev
, "Failed to read Manufacturer Model\n");
488 for (mid
= adm1275_id
; mid
->name
[0]; mid
++) {
489 if (!strncasecmp(mid
->name
, block_buffer
, strlen(mid
->name
)))
493 dev_err(&client
->dev
, "Unsupported device\n");
497 if (id
->driver_data
!= mid
->driver_data
)
498 dev_notice(&client
->dev
,
499 "Device mismatch: Configured %s, detected %s\n",
500 id
->name
, mid
->name
);
502 config
= i2c_smbus_read_byte_data(client
, ADM1275_PMON_CONFIG
);
506 device_config
= i2c_smbus_read_byte_data(client
, ADM1275_DEVICE_CONFIG
);
507 if (device_config
< 0)
508 return device_config
;
510 data
= devm_kzalloc(&client
->dev
, sizeof(struct adm1275_data
),
515 if (of_property_read_u32(client
->dev
.of_node
,
516 "shunt-resistor-micro-ohms", &shunt
))
517 shunt
= 1000; /* 1 mOhm if not set via DT */
522 data
->id
= mid
->driver_data
;
527 info
->format
[PSC_VOLTAGE_IN
] = direct
;
528 info
->format
[PSC_VOLTAGE_OUT
] = direct
;
529 info
->format
[PSC_CURRENT_OUT
] = direct
;
530 info
->format
[PSC_POWER
] = direct
;
531 info
->format
[PSC_TEMPERATURE
] = direct
;
532 info
->func
[0] = PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
535 info
->read_word_data
= adm1275_read_word_data
;
536 info
->read_byte_data
= adm1275_read_byte_data
;
537 info
->write_word_data
= adm1275_write_word_data
;
541 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
542 data
->have_oc_fault
= true;
544 data
->have_uc_fault
= true;
545 data
->have_pin_max
= true;
546 data
->have_vaux_status
= true;
548 coefficients
= adm1075_coefficients
;
550 switch (config
& ADM1075_IRANGE_MASK
) {
551 case ADM1075_IRANGE_25
:
555 case ADM1075_IRANGE_50
:
560 dev_err(&client
->dev
, "Invalid input current range");
564 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
565 | PMBUS_HAVE_STATUS_INPUT
;
566 if (config
& ADM1275_VIN_VOUT_SELECT
)
568 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
571 data
->have_vout
= true;
572 data
->have_pin_max
= true;
573 data
->have_temp_max
= true;
574 data
->have_power_sampling
= true;
576 coefficients
= adm1272_coefficients
;
577 vindex
= (config
& ADM1275_VRANGE
) ? 1 : 0;
578 cindex
= (config
& ADM1272_IRANGE
) ? 3 : 2;
579 /* pindex depends on the combination of the above */
580 switch (config
& (ADM1275_VRANGE
| ADM1272_IRANGE
)) {
591 case ADM1275_VRANGE
| ADM1272_IRANGE
:
597 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
598 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
600 /* Enable VOUT if not enabled (it is disabled by default) */
601 if (!(config
& ADM1278_VOUT_EN
)) {
602 config
|= ADM1278_VOUT_EN
;
603 ret
= i2c_smbus_write_byte_data(client
,
607 dev_err(&client
->dev
,
608 "Failed to enable VOUT monitoring\n");
613 if (config
& ADM1278_TEMP1_EN
)
615 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
616 if (config
& ADM1278_VIN_EN
)
617 info
->func
[0] |= PMBUS_HAVE_VIN
;
620 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
621 data
->have_oc_fault
= true;
623 data
->have_uc_fault
= true;
624 data
->have_vout
= true;
626 coefficients
= adm1275_coefficients
;
627 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
630 if (config
& ADM1275_VIN_VOUT_SELECT
)
632 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
635 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
638 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
639 data
->have_oc_fault
= true;
641 data
->have_uc_fault
= true;
642 data
->have_vout
= true;
643 data
->have_pin_max
= true;
645 coefficients
= adm1276_coefficients
;
646 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
648 pindex
= (config
& ADM1275_VRANGE
) ? 3 : 4;
650 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
651 | PMBUS_HAVE_STATUS_INPUT
;
652 if (config
& ADM1275_VIN_VOUT_SELECT
)
654 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
657 data
->have_vout
= true;
658 data
->have_pin_max
= true;
659 data
->have_temp_max
= true;
660 data
->have_power_sampling
= true;
662 coefficients
= adm1278_coefficients
;
668 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
669 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
671 /* Enable VOUT if not enabled (it is disabled by default) */
672 if (!(config
& ADM1278_VOUT_EN
)) {
673 config
|= ADM1278_VOUT_EN
;
674 ret
= i2c_smbus_write_byte_data(client
,
678 dev_err(&client
->dev
,
679 "Failed to enable VOUT monitoring\n");
684 if (config
& ADM1278_TEMP1_EN
)
686 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
687 if (config
& ADM1278_VIN_EN
)
688 info
->func
[0] |= PMBUS_HAVE_VIN
;
692 data
->have_iout_min
= true;
693 data
->have_pin_min
= true;
694 data
->have_pin_max
= true;
695 data
->have_mfr_vaux_status
= true;
696 data
->have_power_sampling
= true;
698 coefficients
= adm1293_coefficients
;
701 switch (config
& ADM1293_VIN_SEL_MASK
) {
702 case ADM1293_VIN_SEL_012
: /* 1.2V */
705 case ADM1293_VIN_SEL_074
: /* 7.4V */
708 case ADM1293_VIN_SEL_210
: /* 21V */
711 default: /* disabled */
715 switch (config
& ADM1293_IRANGE_MASK
) {
716 case ADM1293_IRANGE_25
:
719 case ADM1293_IRANGE_50
:
722 case ADM1293_IRANGE_100
:
725 case ADM1293_IRANGE_200
:
731 pindex
= 7 + vindex
* 4 + (cindex
- 3);
733 if (config
& ADM1293_VAUX_EN
)
735 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
737 info
->func
[0] |= PMBUS_HAVE_PIN
|
738 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
742 dev_err(&client
->dev
, "Unsupported device\n");
749 info
->m
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].m
;
750 info
->b
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].b
;
751 info
->R
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].R
;
754 info
->m
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].m
;
755 info
->b
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].b
;
756 info
->R
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].R
;
759 /* Scale current with sense resistor value */
760 info
->m
[PSC_CURRENT_OUT
] =
761 coefficients
[cindex
].m
* shunt
/ 1000;
762 info
->b
[PSC_CURRENT_OUT
] = coefficients
[cindex
].b
;
763 info
->R
[PSC_CURRENT_OUT
] = coefficients
[cindex
].R
;
767 coefficients
[pindex
].m
* shunt
/ 1000;
768 info
->b
[PSC_POWER
] = coefficients
[pindex
].b
;
769 info
->R
[PSC_POWER
] = coefficients
[pindex
].R
;
772 info
->m
[PSC_TEMPERATURE
] = coefficients
[tindex
].m
;
773 info
->b
[PSC_TEMPERATURE
] = coefficients
[tindex
].b
;
774 info
->R
[PSC_TEMPERATURE
] = coefficients
[tindex
].R
;
777 return pmbus_do_probe(client
, id
, info
);
780 static struct i2c_driver adm1275_driver
= {
784 .probe
= adm1275_probe
,
785 .remove
= pmbus_do_remove
,
786 .id_table
= adm1275_id
,
789 module_i2c_driver(adm1275_driver
);
791 MODULE_AUTHOR("Guenter Roeck");
792 MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
793 MODULE_LICENSE("GPL");