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
, adm1281
, 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_CONTROL 0xd3
31 #define ADM1275_PMON_CONFIG 0xd4
33 #define ADM1275_CONVERT_EN BIT(0)
35 #define ADM1275_VIN_VOUT_SELECT BIT(6)
36 #define ADM1275_VRANGE BIT(5)
37 #define ADM1075_IRANGE_50 BIT(4)
38 #define ADM1075_IRANGE_25 BIT(3)
39 #define ADM1075_IRANGE_MASK (BIT(3) | BIT(4))
41 #define ADM1272_IRANGE BIT(0)
43 #define ADM1278_TSFILT BIT(15)
44 #define ADM1278_TEMP1_EN BIT(3)
45 #define ADM1278_VIN_EN BIT(2)
46 #define ADM1278_VOUT_EN BIT(1)
48 #define ADM1278_PMON_DEFCONFIG (ADM1278_VOUT_EN | ADM1278_TEMP1_EN | ADM1278_TSFILT)
50 #define ADM1293_IRANGE_25 0
51 #define ADM1293_IRANGE_50 BIT(6)
52 #define ADM1293_IRANGE_100 BIT(7)
53 #define ADM1293_IRANGE_200 (BIT(6) | BIT(7))
54 #define ADM1293_IRANGE_MASK (BIT(6) | BIT(7))
56 #define ADM1293_VIN_SEL_012 BIT(2)
57 #define ADM1293_VIN_SEL_074 BIT(3)
58 #define ADM1293_VIN_SEL_210 (BIT(2) | BIT(3))
59 #define ADM1293_VIN_SEL_MASK (BIT(2) | BIT(3))
61 #define ADM1293_VAUX_EN BIT(1)
63 #define ADM1278_PEAK_TEMP 0xd7
64 #define ADM1275_IOUT_WARN2_LIMIT 0xd7
65 #define ADM1275_DEVICE_CONFIG 0xd8
67 #define ADM1275_IOUT_WARN2_SELECT BIT(4)
69 #define ADM1276_PEAK_PIN 0xda
70 #define ADM1075_READ_VAUX 0xdd
71 #define ADM1075_VAUX_OV_WARN_LIMIT 0xde
72 #define ADM1075_VAUX_UV_WARN_LIMIT 0xdf
73 #define ADM1293_IOUT_MIN 0xe3
74 #define ADM1293_PIN_MIN 0xe4
75 #define ADM1075_VAUX_STATUS 0xf6
77 #define ADM1075_VAUX_OV_WARN BIT(7)
78 #define ADM1075_VAUX_UV_WARN BIT(6)
80 #define ADM1275_VI_AVG_SHIFT 0
81 #define ADM1275_VI_AVG_MASK GENMASK(ADM1275_VI_AVG_SHIFT + 2, \
83 #define ADM1275_SAMPLES_AVG_MAX 128
85 #define ADM1278_PWR_AVG_SHIFT 11
86 #define ADM1278_PWR_AVG_MASK GENMASK(ADM1278_PWR_AVG_SHIFT + 2, \
87 ADM1278_PWR_AVG_SHIFT)
88 #define ADM1278_VI_AVG_SHIFT 8
89 #define ADM1278_VI_AVG_MASK GENMASK(ADM1278_VI_AVG_SHIFT + 2, \
97 bool have_vaux_status
;
98 bool have_mfr_vaux_status
;
103 bool have_power_sampling
;
104 struct pmbus_driver_info info
;
107 #define to_adm1275_data(x) container_of(x, struct adm1275_data, info)
109 struct coefficients
{
115 static const struct coefficients adm1075_coefficients
[] = {
116 [0] = { 27169, 0, -1 }, /* voltage */
117 [1] = { 806, 20475, -1 }, /* current, irange25 */
118 [2] = { 404, 20475, -1 }, /* current, irange50 */
119 [3] = { 8549, 0, -1 }, /* power, irange25 */
120 [4] = { 4279, 0, -1 }, /* power, irange50 */
123 static const struct coefficients adm1272_coefficients
[] = {
124 [0] = { 6770, 0, -2 }, /* voltage, vrange 60V */
125 [1] = { 4062, 0, -2 }, /* voltage, vrange 100V */
126 [2] = { 1326, 20480, -1 }, /* current, vsense range 15mV */
127 [3] = { 663, 20480, -1 }, /* current, vsense range 30mV */
128 [4] = { 3512, 0, -2 }, /* power, vrange 60V, irange 15mV */
129 [5] = { 21071, 0, -3 }, /* power, vrange 100V, irange 15mV */
130 [6] = { 17561, 0, -3 }, /* power, vrange 60V, irange 30mV */
131 [7] = { 10535, 0, -3 }, /* power, vrange 100V, irange 30mV */
132 [8] = { 42, 31871, -1 }, /* temperature */
136 static const struct coefficients adm1275_coefficients
[] = {
137 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
138 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
139 [2] = { 807, 20475, -1 }, /* current */
142 static const struct coefficients adm1276_coefficients
[] = {
143 [0] = { 19199, 0, -2 }, /* voltage, vrange set */
144 [1] = { 6720, 0, -1 }, /* voltage, vrange not set */
145 [2] = { 807, 20475, -1 }, /* current */
146 [3] = { 6043, 0, -2 }, /* power, vrange set */
147 [4] = { 2115, 0, -1 }, /* power, vrange not set */
150 static const struct coefficients adm1278_coefficients
[] = {
151 [0] = { 19599, 0, -2 }, /* voltage */
152 [1] = { 800, 20475, -1 }, /* current */
153 [2] = { 6123, 0, -2 }, /* power */
154 [3] = { 42, 31880, -1 }, /* temperature */
157 static const struct coefficients adm1293_coefficients
[] = {
158 [0] = { 3333, -1, 0 }, /* voltage, vrange 1.2V */
159 [1] = { 5552, -5, -1 }, /* voltage, vrange 7.4V */
160 [2] = { 19604, -50, -2 }, /* voltage, vrange 21V */
161 [3] = { 8000, -100, -2 }, /* current, irange25 */
162 [4] = { 4000, -100, -2 }, /* current, irange50 */
163 [5] = { 20000, -1000, -3 }, /* current, irange100 */
164 [6] = { 10000, -1000, -3 }, /* current, irange200 */
165 [7] = { 10417, 0, -1 }, /* power, 1.2V, irange25 */
166 [8] = { 5208, 0, -1 }, /* power, 1.2V, irange50 */
167 [9] = { 26042, 0, -2 }, /* power, 1.2V, irange100 */
168 [10] = { 13021, 0, -2 }, /* power, 1.2V, irange200 */
169 [11] = { 17351, 0, -2 }, /* power, 7.4V, irange25 */
170 [12] = { 8676, 0, -2 }, /* power, 7.4V, irange50 */
171 [13] = { 4338, 0, -2 }, /* power, 7.4V, irange100 */
172 [14] = { 21689, 0, -3 }, /* power, 7.4V, irange200 */
173 [15] = { 6126, 0, -2 }, /* power, 21V, irange25 */
174 [16] = { 30631, 0, -3 }, /* power, 21V, irange50 */
175 [17] = { 15316, 0, -3 }, /* power, 21V, irange100 */
176 [18] = { 7658, 0, -3 }, /* power, 21V, irange200 */
179 static int adm1275_read_samples(const struct adm1275_data
*data
,
180 struct i2c_client
*client
, bool is_power
)
186 * The PMON configuration register is a 16-bit register only on chips
187 * supporting power average sampling. On other chips it is an 8-bit
190 if (data
->have_power_sampling
) {
191 ret
= i2c_smbus_read_word_data(client
, ADM1275_PMON_CONFIG
);
192 mask
= is_power
? ADM1278_PWR_AVG_MASK
: ADM1278_VI_AVG_MASK
;
193 shift
= is_power
? ADM1278_PWR_AVG_SHIFT
: ADM1278_VI_AVG_SHIFT
;
195 ret
= i2c_smbus_read_byte_data(client
, ADM1275_PMON_CONFIG
);
196 mask
= ADM1275_VI_AVG_MASK
;
197 shift
= ADM1275_VI_AVG_SHIFT
;
202 return (ret
& mask
) >> shift
;
205 static int adm1275_write_pmon_config(const struct adm1275_data
*data
,
206 struct i2c_client
*client
, u16 word
)
210 ret
= i2c_smbus_write_byte_data(client
, ADM1275_PMON_CONTROL
, 0);
214 if (data
->have_power_sampling
)
215 ret
= i2c_smbus_write_word_data(client
, ADM1275_PMON_CONFIG
,
218 ret
= i2c_smbus_write_byte_data(client
, ADM1275_PMON_CONFIG
,
222 * We still want to re-enable conversions if writing into
223 * ADM1275_PMON_CONFIG failed.
225 ret2
= i2c_smbus_write_byte_data(client
, ADM1275_PMON_CONTROL
,
233 static int adm1275_write_samples(const struct adm1275_data
*data
,
234 struct i2c_client
*client
,
235 bool is_power
, u16 word
)
240 if (data
->have_power_sampling
) {
241 ret
= i2c_smbus_read_word_data(client
, ADM1275_PMON_CONFIG
);
242 mask
= is_power
? ADM1278_PWR_AVG_MASK
: ADM1278_VI_AVG_MASK
;
243 shift
= is_power
? ADM1278_PWR_AVG_SHIFT
: ADM1278_VI_AVG_SHIFT
;
245 ret
= i2c_smbus_read_byte_data(client
, ADM1275_PMON_CONFIG
);
246 mask
= ADM1275_VI_AVG_MASK
;
247 shift
= ADM1275_VI_AVG_SHIFT
;
252 word
= (ret
& ~mask
) | ((word
<< shift
) & mask
);
254 return adm1275_write_pmon_config(data
, client
, word
);
257 static int adm1275_read_word_data(struct i2c_client
*client
, int page
,
260 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
261 const struct adm1275_data
*data
= to_adm1275_data(info
);
268 case PMBUS_IOUT_UC_FAULT_LIMIT
:
269 if (!data
->have_uc_fault
)
271 ret
= pmbus_read_word_data(client
, 0, 0xff,
272 ADM1275_IOUT_WARN2_LIMIT
);
274 case PMBUS_IOUT_OC_FAULT_LIMIT
:
275 if (!data
->have_oc_fault
)
277 ret
= pmbus_read_word_data(client
, 0, 0xff,
278 ADM1275_IOUT_WARN2_LIMIT
);
280 case PMBUS_VOUT_OV_WARN_LIMIT
:
283 ret
= pmbus_read_word_data(client
, 0, 0xff,
284 ADM1075_VAUX_OV_WARN_LIMIT
);
286 case PMBUS_VOUT_UV_WARN_LIMIT
:
289 ret
= pmbus_read_word_data(client
, 0, 0xff,
290 ADM1075_VAUX_UV_WARN_LIMIT
);
292 case PMBUS_READ_VOUT
:
295 ret
= pmbus_read_word_data(client
, 0, 0xff,
298 case PMBUS_VIRT_READ_IOUT_MIN
:
299 if (!data
->have_iout_min
)
301 ret
= pmbus_read_word_data(client
, 0, 0xff,
304 case PMBUS_VIRT_READ_IOUT_MAX
:
305 ret
= pmbus_read_word_data(client
, 0, 0xff,
308 case PMBUS_VIRT_READ_VOUT_MAX
:
309 ret
= pmbus_read_word_data(client
, 0, 0xff,
312 case PMBUS_VIRT_READ_VIN_MAX
:
313 ret
= pmbus_read_word_data(client
, 0, 0xff,
316 case PMBUS_VIRT_READ_PIN_MIN
:
317 if (!data
->have_pin_min
)
319 ret
= pmbus_read_word_data(client
, 0, 0xff,
322 case PMBUS_VIRT_READ_PIN_MAX
:
323 if (!data
->have_pin_max
)
325 ret
= pmbus_read_word_data(client
, 0, 0xff,
328 case PMBUS_VIRT_READ_TEMP_MAX
:
329 if (!data
->have_temp_max
)
331 ret
= pmbus_read_word_data(client
, 0, 0xff,
334 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
335 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
336 case PMBUS_VIRT_RESET_VIN_HISTORY
:
338 case PMBUS_VIRT_RESET_PIN_HISTORY
:
339 if (!data
->have_pin_max
)
342 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
343 if (!data
->have_temp_max
)
346 case PMBUS_VIRT_POWER_SAMPLES
:
347 if (!data
->have_power_sampling
)
349 ret
= adm1275_read_samples(data
, client
, true);
354 case PMBUS_VIRT_IN_SAMPLES
:
355 case PMBUS_VIRT_CURR_SAMPLES
:
356 ret
= adm1275_read_samples(data
, client
, false);
368 static int adm1275_write_word_data(struct i2c_client
*client
, int page
, int reg
,
371 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
372 const struct adm1275_data
*data
= to_adm1275_data(info
);
379 case PMBUS_IOUT_UC_FAULT_LIMIT
:
380 case PMBUS_IOUT_OC_FAULT_LIMIT
:
381 ret
= pmbus_write_word_data(client
, 0, ADM1275_IOUT_WARN2_LIMIT
,
384 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
385 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_IOUT
, 0);
386 if (!ret
&& data
->have_iout_min
)
387 ret
= pmbus_write_word_data(client
, 0,
388 ADM1293_IOUT_MIN
, 0);
390 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
391 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VOUT
, 0);
393 case PMBUS_VIRT_RESET_VIN_HISTORY
:
394 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VIN
, 0);
396 case PMBUS_VIRT_RESET_PIN_HISTORY
:
397 ret
= pmbus_write_word_data(client
, 0, ADM1276_PEAK_PIN
, 0);
398 if (!ret
&& data
->have_pin_min
)
399 ret
= pmbus_write_word_data(client
, 0,
402 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
403 ret
= pmbus_write_word_data(client
, 0, ADM1278_PEAK_TEMP
, 0);
405 case PMBUS_VIRT_POWER_SAMPLES
:
406 if (!data
->have_power_sampling
)
408 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
409 ret
= adm1275_write_samples(data
, client
, true, ilog2(word
));
411 case PMBUS_VIRT_IN_SAMPLES
:
412 case PMBUS_VIRT_CURR_SAMPLES
:
413 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
414 ret
= adm1275_write_samples(data
, client
, false, ilog2(word
));
423 static int adm1275_read_byte_data(struct i2c_client
*client
, int page
, int reg
)
425 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
426 const struct adm1275_data
*data
= to_adm1275_data(info
);
433 case PMBUS_STATUS_IOUT
:
434 ret
= pmbus_read_byte_data(client
, page
, PMBUS_STATUS_IOUT
);
437 if (!data
->have_oc_fault
&& !data
->have_uc_fault
)
439 mfr_status
= pmbus_read_byte_data(client
, page
,
440 PMBUS_STATUS_MFR_SPECIFIC
);
443 if (mfr_status
& ADM1275_MFR_STATUS_IOUT_WARN2
) {
444 ret
|= data
->have_oc_fault
?
445 PB_IOUT_OC_FAULT
: PB_IOUT_UC_FAULT
;
448 case PMBUS_STATUS_VOUT
:
452 if (data
->have_vaux_status
) {
453 mfr_status
= pmbus_read_byte_data(client
, 0,
454 ADM1075_VAUX_STATUS
);
457 if (mfr_status
& ADM1075_VAUX_OV_WARN
)
458 ret
|= PB_VOLTAGE_OV_WARNING
;
459 if (mfr_status
& ADM1075_VAUX_UV_WARN
)
460 ret
|= PB_VOLTAGE_UV_WARNING
;
461 } else if (data
->have_mfr_vaux_status
) {
462 mfr_status
= pmbus_read_byte_data(client
, page
,
463 PMBUS_STATUS_MFR_SPECIFIC
);
466 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_OV_WARN
)
467 ret
|= PB_VOLTAGE_OV_WARNING
;
468 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_UV_WARN
)
469 ret
|= PB_VOLTAGE_UV_WARNING
;
479 static const struct i2c_device_id adm1275_id
[] = {
480 { "adm1075", adm1075
},
481 { "adm1272", adm1272
},
482 { "adm1275", adm1275
},
483 { "adm1276", adm1276
},
484 { "adm1278", adm1278
},
485 { "adm1281", adm1281
},
486 { "adm1293", adm1293
},
487 { "adm1294", adm1294
},
490 MODULE_DEVICE_TABLE(i2c
, adm1275_id
);
492 /* Enable VOUT & TEMP1 if not enabled (disabled by default) */
493 static int adm1275_enable_vout_temp(struct adm1275_data
*data
,
494 struct i2c_client
*client
, int config
)
498 if ((config
& ADM1278_PMON_DEFCONFIG
) != ADM1278_PMON_DEFCONFIG
) {
499 config
|= ADM1278_PMON_DEFCONFIG
;
500 ret
= adm1275_write_pmon_config(data
, client
, config
);
502 dev_err(&client
->dev
, "Failed to enable VOUT/TEMP1 monitoring\n");
509 static int adm1275_probe(struct i2c_client
*client
)
511 s32 (*config_read_fn
)(const struct i2c_client
*client
, u8 reg
);
512 u8 block_buffer
[I2C_SMBUS_BLOCK_MAX
+ 1];
513 int config
, device_config
;
515 struct pmbus_driver_info
*info
;
516 struct adm1275_data
*data
;
517 const struct i2c_device_id
*mid
;
518 const struct coefficients
*coefficients
;
519 int vindex
= -1, voindex
= -1, cindex
= -1, pindex
= -1;
524 if (!i2c_check_functionality(client
->adapter
,
525 I2C_FUNC_SMBUS_READ_BYTE_DATA
526 | I2C_FUNC_SMBUS_BLOCK_DATA
))
529 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_ID
, block_buffer
);
531 dev_err(&client
->dev
, "Failed to read Manufacturer ID\n");
534 if (ret
!= 3 || strncmp(block_buffer
, "ADI", 3)) {
535 dev_err(&client
->dev
, "Unsupported Manufacturer ID\n");
539 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_MODEL
, block_buffer
);
541 dev_err(&client
->dev
, "Failed to read Manufacturer Model\n");
544 for (mid
= adm1275_id
; mid
->name
[0]; mid
++) {
545 if (!strncasecmp(mid
->name
, block_buffer
, strlen(mid
->name
)))
549 dev_err(&client
->dev
, "Unsupported device\n");
553 if (strcmp(client
->name
, mid
->name
) != 0)
554 dev_notice(&client
->dev
,
555 "Device mismatch: Configured %s, detected %s\n",
556 client
->name
, mid
->name
);
558 if (mid
->driver_data
== adm1272
|| mid
->driver_data
== adm1278
||
559 mid
->driver_data
== adm1281
|| mid
->driver_data
== adm1293
||
560 mid
->driver_data
== adm1294
)
561 config_read_fn
= i2c_smbus_read_word_data
;
563 config_read_fn
= i2c_smbus_read_byte_data
;
564 config
= config_read_fn(client
, ADM1275_PMON_CONFIG
);
568 device_config
= config_read_fn(client
, ADM1275_DEVICE_CONFIG
);
569 if (device_config
< 0)
570 return device_config
;
572 data
= devm_kzalloc(&client
->dev
, sizeof(struct adm1275_data
),
577 if (of_property_read_u32(client
->dev
.of_node
,
578 "shunt-resistor-micro-ohms", &shunt
))
579 shunt
= 1000; /* 1 mOhm if not set via DT */
584 data
->id
= mid
->driver_data
;
589 info
->format
[PSC_VOLTAGE_IN
] = direct
;
590 info
->format
[PSC_VOLTAGE_OUT
] = direct
;
591 info
->format
[PSC_CURRENT_OUT
] = direct
;
592 info
->format
[PSC_POWER
] = direct
;
593 info
->format
[PSC_TEMPERATURE
] = direct
;
594 info
->func
[0] = PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
597 info
->read_word_data
= adm1275_read_word_data
;
598 info
->read_byte_data
= adm1275_read_byte_data
;
599 info
->write_word_data
= adm1275_write_word_data
;
603 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
604 data
->have_oc_fault
= true;
606 data
->have_uc_fault
= true;
607 data
->have_pin_max
= true;
608 data
->have_vaux_status
= true;
610 coefficients
= adm1075_coefficients
;
612 switch (config
& ADM1075_IRANGE_MASK
) {
613 case ADM1075_IRANGE_25
:
617 case ADM1075_IRANGE_50
:
622 dev_err(&client
->dev
, "Invalid input current range");
626 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
627 | PMBUS_HAVE_STATUS_INPUT
;
628 if (config
& ADM1275_VIN_VOUT_SELECT
)
630 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
633 data
->have_vout
= true;
634 data
->have_pin_max
= true;
635 data
->have_temp_max
= true;
636 data
->have_power_sampling
= true;
638 coefficients
= adm1272_coefficients
;
639 vindex
= (config
& ADM1275_VRANGE
) ? 1 : 0;
640 cindex
= (config
& ADM1272_IRANGE
) ? 3 : 2;
641 /* pindex depends on the combination of the above */
642 switch (config
& (ADM1275_VRANGE
| ADM1272_IRANGE
)) {
653 case ADM1275_VRANGE
| ADM1272_IRANGE
:
659 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
660 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
661 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
663 ret
= adm1275_enable_vout_temp(data
, client
, config
);
667 if (config
& ADM1278_VIN_EN
)
668 info
->func
[0] |= PMBUS_HAVE_VIN
;
671 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
672 data
->have_oc_fault
= true;
674 data
->have_uc_fault
= true;
675 data
->have_vout
= true;
677 coefficients
= adm1275_coefficients
;
678 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
681 if (config
& ADM1275_VIN_VOUT_SELECT
)
683 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
686 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
689 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
690 data
->have_oc_fault
= true;
692 data
->have_uc_fault
= true;
693 data
->have_vout
= true;
694 data
->have_pin_max
= true;
696 coefficients
= adm1276_coefficients
;
697 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
699 pindex
= (config
& ADM1275_VRANGE
) ? 3 : 4;
701 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
702 | PMBUS_HAVE_STATUS_INPUT
;
703 if (config
& ADM1275_VIN_VOUT_SELECT
)
705 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
709 data
->have_vout
= true;
710 data
->have_pin_max
= true;
711 data
->have_temp_max
= true;
712 data
->have_power_sampling
= true;
714 coefficients
= adm1278_coefficients
;
720 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
721 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
722 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
724 ret
= adm1275_enable_vout_temp(data
, client
, config
);
728 if (config
& ADM1278_VIN_EN
)
729 info
->func
[0] |= PMBUS_HAVE_VIN
;
733 data
->have_iout_min
= true;
734 data
->have_pin_min
= true;
735 data
->have_pin_max
= true;
736 data
->have_mfr_vaux_status
= true;
737 data
->have_power_sampling
= true;
739 coefficients
= adm1293_coefficients
;
742 switch (config
& ADM1293_VIN_SEL_MASK
) {
743 case ADM1293_VIN_SEL_012
: /* 1.2V */
746 case ADM1293_VIN_SEL_074
: /* 7.4V */
749 case ADM1293_VIN_SEL_210
: /* 21V */
752 default: /* disabled */
756 switch (config
& ADM1293_IRANGE_MASK
) {
757 case ADM1293_IRANGE_25
:
760 case ADM1293_IRANGE_50
:
763 case ADM1293_IRANGE_100
:
766 case ADM1293_IRANGE_200
:
772 pindex
= 7 + vindex
* 4 + (cindex
- 3);
774 if (config
& ADM1293_VAUX_EN
)
776 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
778 info
->func
[0] |= PMBUS_HAVE_PIN
|
779 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
783 dev_err(&client
->dev
, "Unsupported device\n");
787 if (data
->have_power_sampling
&&
788 of_property_read_u32(client
->dev
.of_node
,
789 "adi,power-sample-average", &avg
) == 0) {
790 if (!avg
|| avg
> ADM1275_SAMPLES_AVG_MAX
||
791 BIT(__fls(avg
)) != avg
) {
792 dev_err(&client
->dev
,
793 "Invalid number of power samples");
796 ret
= adm1275_write_samples(data
, client
, true, ilog2(avg
));
798 dev_err(&client
->dev
,
799 "Setting power sample averaging failed with error %d",
805 if (of_property_read_u32(client
->dev
.of_node
,
806 "adi,volt-curr-sample-average", &avg
) == 0) {
807 if (!avg
|| avg
> ADM1275_SAMPLES_AVG_MAX
||
808 BIT(__fls(avg
)) != avg
) {
809 dev_err(&client
->dev
,
810 "Invalid number of voltage/current samples");
813 ret
= adm1275_write_samples(data
, client
, false, ilog2(avg
));
815 dev_err(&client
->dev
,
816 "Setting voltage and current sample averaging failed with error %d",
825 info
->m
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].m
;
826 info
->b
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].b
;
827 info
->R
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].R
;
830 info
->m
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].m
;
831 info
->b
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].b
;
832 info
->R
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].R
;
835 /* Scale current with sense resistor value */
836 info
->m
[PSC_CURRENT_OUT
] =
837 coefficients
[cindex
].m
* shunt
/ 1000;
838 info
->b
[PSC_CURRENT_OUT
] = coefficients
[cindex
].b
;
839 info
->R
[PSC_CURRENT_OUT
] = coefficients
[cindex
].R
;
843 coefficients
[pindex
].m
* shunt
/ 1000;
844 info
->b
[PSC_POWER
] = coefficients
[pindex
].b
;
845 info
->R
[PSC_POWER
] = coefficients
[pindex
].R
;
848 info
->m
[PSC_TEMPERATURE
] = coefficients
[tindex
].m
;
849 info
->b
[PSC_TEMPERATURE
] = coefficients
[tindex
].b
;
850 info
->R
[PSC_TEMPERATURE
] = coefficients
[tindex
].R
;
853 return pmbus_do_probe(client
, info
);
856 static struct i2c_driver adm1275_driver
= {
860 .probe
= adm1275_probe
,
861 .id_table
= adm1275_id
,
864 module_i2c_driver(adm1275_driver
);
866 MODULE_AUTHOR("Guenter Roeck");
867 MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
868 MODULE_LICENSE("GPL");
869 MODULE_IMPORT_NS("PMBUS");