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
,
232 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
233 const struct adm1275_data
*data
= to_adm1275_data(info
);
240 case PMBUS_IOUT_UC_FAULT_LIMIT
:
241 if (!data
->have_uc_fault
)
243 ret
= pmbus_read_word_data(client
, 0, 0xff,
244 ADM1275_IOUT_WARN2_LIMIT
);
246 case PMBUS_IOUT_OC_FAULT_LIMIT
:
247 if (!data
->have_oc_fault
)
249 ret
= pmbus_read_word_data(client
, 0, 0xff,
250 ADM1275_IOUT_WARN2_LIMIT
);
252 case PMBUS_VOUT_OV_WARN_LIMIT
:
255 ret
= pmbus_read_word_data(client
, 0, 0xff,
256 ADM1075_VAUX_OV_WARN_LIMIT
);
258 case PMBUS_VOUT_UV_WARN_LIMIT
:
261 ret
= pmbus_read_word_data(client
, 0, 0xff,
262 ADM1075_VAUX_UV_WARN_LIMIT
);
264 case PMBUS_READ_VOUT
:
267 ret
= pmbus_read_word_data(client
, 0, 0xff,
270 case PMBUS_VIRT_READ_IOUT_MIN
:
271 if (!data
->have_iout_min
)
273 ret
= pmbus_read_word_data(client
, 0, 0xff,
276 case PMBUS_VIRT_READ_IOUT_MAX
:
277 ret
= pmbus_read_word_data(client
, 0, 0xff,
280 case PMBUS_VIRT_READ_VOUT_MAX
:
281 ret
= pmbus_read_word_data(client
, 0, 0xff,
284 case PMBUS_VIRT_READ_VIN_MAX
:
285 ret
= pmbus_read_word_data(client
, 0, 0xff,
288 case PMBUS_VIRT_READ_PIN_MIN
:
289 if (!data
->have_pin_min
)
291 ret
= pmbus_read_word_data(client
, 0, 0xff,
294 case PMBUS_VIRT_READ_PIN_MAX
:
295 if (!data
->have_pin_max
)
297 ret
= pmbus_read_word_data(client
, 0, 0xff,
300 case PMBUS_VIRT_READ_TEMP_MAX
:
301 if (!data
->have_temp_max
)
303 ret
= pmbus_read_word_data(client
, 0, 0xff,
306 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
307 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
308 case PMBUS_VIRT_RESET_VIN_HISTORY
:
310 case PMBUS_VIRT_RESET_PIN_HISTORY
:
311 if (!data
->have_pin_max
)
314 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
315 if (!data
->have_temp_max
)
318 case PMBUS_VIRT_POWER_SAMPLES
:
319 if (!data
->have_power_sampling
)
321 ret
= adm1275_read_pmon_config(data
, client
, true);
326 case PMBUS_VIRT_IN_SAMPLES
:
327 case PMBUS_VIRT_CURR_SAMPLES
:
328 ret
= adm1275_read_pmon_config(data
, client
, false);
340 static int adm1275_write_word_data(struct i2c_client
*client
, int page
, int reg
,
343 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
344 const struct adm1275_data
*data
= to_adm1275_data(info
);
351 case PMBUS_IOUT_UC_FAULT_LIMIT
:
352 case PMBUS_IOUT_OC_FAULT_LIMIT
:
353 ret
= pmbus_write_word_data(client
, 0, ADM1275_IOUT_WARN2_LIMIT
,
356 case PMBUS_VIRT_RESET_IOUT_HISTORY
:
357 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_IOUT
, 0);
358 if (!ret
&& data
->have_iout_min
)
359 ret
= pmbus_write_word_data(client
, 0,
360 ADM1293_IOUT_MIN
, 0);
362 case PMBUS_VIRT_RESET_VOUT_HISTORY
:
363 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VOUT
, 0);
365 case PMBUS_VIRT_RESET_VIN_HISTORY
:
366 ret
= pmbus_write_word_data(client
, 0, ADM1275_PEAK_VIN
, 0);
368 case PMBUS_VIRT_RESET_PIN_HISTORY
:
369 ret
= pmbus_write_word_data(client
, 0, ADM1276_PEAK_PIN
, 0);
370 if (!ret
&& data
->have_pin_min
)
371 ret
= pmbus_write_word_data(client
, 0,
374 case PMBUS_VIRT_RESET_TEMP_HISTORY
:
375 ret
= pmbus_write_word_data(client
, 0, ADM1278_PEAK_TEMP
, 0);
377 case PMBUS_VIRT_POWER_SAMPLES
:
378 if (!data
->have_power_sampling
)
380 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
381 ret
= adm1275_write_pmon_config(data
, client
, true,
384 case PMBUS_VIRT_IN_SAMPLES
:
385 case PMBUS_VIRT_CURR_SAMPLES
:
386 word
= clamp_val(word
, 1, ADM1275_SAMPLES_AVG_MAX
);
387 ret
= adm1275_write_pmon_config(data
, client
, false,
397 static int adm1275_read_byte_data(struct i2c_client
*client
, int page
, int reg
)
399 const struct pmbus_driver_info
*info
= pmbus_get_driver_info(client
);
400 const struct adm1275_data
*data
= to_adm1275_data(info
);
407 case PMBUS_STATUS_IOUT
:
408 ret
= pmbus_read_byte_data(client
, page
, PMBUS_STATUS_IOUT
);
411 if (!data
->have_oc_fault
&& !data
->have_uc_fault
)
413 mfr_status
= pmbus_read_byte_data(client
, page
,
414 PMBUS_STATUS_MFR_SPECIFIC
);
417 if (mfr_status
& ADM1275_MFR_STATUS_IOUT_WARN2
) {
418 ret
|= data
->have_oc_fault
?
419 PB_IOUT_OC_FAULT
: PB_IOUT_UC_FAULT
;
422 case PMBUS_STATUS_VOUT
:
426 if (data
->have_vaux_status
) {
427 mfr_status
= pmbus_read_byte_data(client
, 0,
428 ADM1075_VAUX_STATUS
);
431 if (mfr_status
& ADM1075_VAUX_OV_WARN
)
432 ret
|= PB_VOLTAGE_OV_WARNING
;
433 if (mfr_status
& ADM1075_VAUX_UV_WARN
)
434 ret
|= PB_VOLTAGE_UV_WARNING
;
435 } else if (data
->have_mfr_vaux_status
) {
436 mfr_status
= pmbus_read_byte_data(client
, page
,
437 PMBUS_STATUS_MFR_SPECIFIC
);
440 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_OV_WARN
)
441 ret
|= PB_VOLTAGE_OV_WARNING
;
442 if (mfr_status
& ADM1293_MFR_STATUS_VAUX_UV_WARN
)
443 ret
|= PB_VOLTAGE_UV_WARNING
;
453 static const struct i2c_device_id adm1275_id
[] = {
454 { "adm1075", adm1075
},
455 { "adm1272", adm1272
},
456 { "adm1275", adm1275
},
457 { "adm1276", adm1276
},
458 { "adm1278", adm1278
},
459 { "adm1293", adm1293
},
460 { "adm1294", adm1294
},
463 MODULE_DEVICE_TABLE(i2c
, adm1275_id
);
465 static int adm1275_probe(struct i2c_client
*client
,
466 const struct i2c_device_id
*id
)
468 s32 (*config_read_fn
)(const struct i2c_client
*client
, u8 reg
);
469 u8 block_buffer
[I2C_SMBUS_BLOCK_MAX
+ 1];
470 int config
, device_config
;
472 struct pmbus_driver_info
*info
;
473 struct adm1275_data
*data
;
474 const struct i2c_device_id
*mid
;
475 const struct coefficients
*coefficients
;
476 int vindex
= -1, voindex
= -1, cindex
= -1, pindex
= -1;
480 if (!i2c_check_functionality(client
->adapter
,
481 I2C_FUNC_SMBUS_READ_BYTE_DATA
482 | I2C_FUNC_SMBUS_BLOCK_DATA
))
485 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_ID
, block_buffer
);
487 dev_err(&client
->dev
, "Failed to read Manufacturer ID\n");
490 if (ret
!= 3 || strncmp(block_buffer
, "ADI", 3)) {
491 dev_err(&client
->dev
, "Unsupported Manufacturer ID\n");
495 ret
= i2c_smbus_read_block_data(client
, PMBUS_MFR_MODEL
, block_buffer
);
497 dev_err(&client
->dev
, "Failed to read Manufacturer Model\n");
500 for (mid
= adm1275_id
; mid
->name
[0]; mid
++) {
501 if (!strncasecmp(mid
->name
, block_buffer
, strlen(mid
->name
)))
505 dev_err(&client
->dev
, "Unsupported device\n");
509 if (id
->driver_data
!= mid
->driver_data
)
510 dev_notice(&client
->dev
,
511 "Device mismatch: Configured %s, detected %s\n",
512 id
->name
, mid
->name
);
514 if (mid
->driver_data
== adm1272
|| mid
->driver_data
== adm1278
||
515 mid
->driver_data
== adm1293
|| mid
->driver_data
== adm1294
)
516 config_read_fn
= i2c_smbus_read_word_data
;
518 config_read_fn
= i2c_smbus_read_byte_data
;
519 config
= config_read_fn(client
, ADM1275_PMON_CONFIG
);
523 device_config
= config_read_fn(client
, ADM1275_DEVICE_CONFIG
);
524 if (device_config
< 0)
525 return device_config
;
527 data
= devm_kzalloc(&client
->dev
, sizeof(struct adm1275_data
),
532 if (of_property_read_u32(client
->dev
.of_node
,
533 "shunt-resistor-micro-ohms", &shunt
))
534 shunt
= 1000; /* 1 mOhm if not set via DT */
539 data
->id
= mid
->driver_data
;
544 info
->format
[PSC_VOLTAGE_IN
] = direct
;
545 info
->format
[PSC_VOLTAGE_OUT
] = direct
;
546 info
->format
[PSC_CURRENT_OUT
] = direct
;
547 info
->format
[PSC_POWER
] = direct
;
548 info
->format
[PSC_TEMPERATURE
] = direct
;
549 info
->func
[0] = PMBUS_HAVE_IOUT
| PMBUS_HAVE_STATUS_IOUT
|
552 info
->read_word_data
= adm1275_read_word_data
;
553 info
->read_byte_data
= adm1275_read_byte_data
;
554 info
->write_word_data
= adm1275_write_word_data
;
558 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
559 data
->have_oc_fault
= true;
561 data
->have_uc_fault
= true;
562 data
->have_pin_max
= true;
563 data
->have_vaux_status
= true;
565 coefficients
= adm1075_coefficients
;
567 switch (config
& ADM1075_IRANGE_MASK
) {
568 case ADM1075_IRANGE_25
:
572 case ADM1075_IRANGE_50
:
577 dev_err(&client
->dev
, "Invalid input current range");
581 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
582 | PMBUS_HAVE_STATUS_INPUT
;
583 if (config
& ADM1275_VIN_VOUT_SELECT
)
585 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
588 data
->have_vout
= true;
589 data
->have_pin_max
= true;
590 data
->have_temp_max
= true;
591 data
->have_power_sampling
= true;
593 coefficients
= adm1272_coefficients
;
594 vindex
= (config
& ADM1275_VRANGE
) ? 1 : 0;
595 cindex
= (config
& ADM1272_IRANGE
) ? 3 : 2;
596 /* pindex depends on the combination of the above */
597 switch (config
& (ADM1275_VRANGE
| ADM1272_IRANGE
)) {
608 case ADM1275_VRANGE
| ADM1272_IRANGE
:
614 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
615 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
617 /* Enable VOUT if not enabled (it is disabled by default) */
618 if (!(config
& ADM1278_VOUT_EN
)) {
619 config
|= ADM1278_VOUT_EN
;
620 ret
= i2c_smbus_write_byte_data(client
,
624 dev_err(&client
->dev
,
625 "Failed to enable VOUT monitoring\n");
630 if (config
& ADM1278_TEMP1_EN
)
632 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
633 if (config
& ADM1278_VIN_EN
)
634 info
->func
[0] |= PMBUS_HAVE_VIN
;
637 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
638 data
->have_oc_fault
= true;
640 data
->have_uc_fault
= true;
641 data
->have_vout
= true;
643 coefficients
= adm1275_coefficients
;
644 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
647 if (config
& ADM1275_VIN_VOUT_SELECT
)
649 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
652 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
655 if (device_config
& ADM1275_IOUT_WARN2_SELECT
)
656 data
->have_oc_fault
= true;
658 data
->have_uc_fault
= true;
659 data
->have_vout
= true;
660 data
->have_pin_max
= true;
662 coefficients
= adm1276_coefficients
;
663 vindex
= (config
& ADM1275_VRANGE
) ? 0 : 1;
665 pindex
= (config
& ADM1275_VRANGE
) ? 3 : 4;
667 info
->func
[0] |= PMBUS_HAVE_VIN
| PMBUS_HAVE_PIN
668 | PMBUS_HAVE_STATUS_INPUT
;
669 if (config
& ADM1275_VIN_VOUT_SELECT
)
671 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
674 data
->have_vout
= true;
675 data
->have_pin_max
= true;
676 data
->have_temp_max
= true;
677 data
->have_power_sampling
= true;
679 coefficients
= adm1278_coefficients
;
685 info
->func
[0] |= PMBUS_HAVE_PIN
| PMBUS_HAVE_STATUS_INPUT
|
686 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
|
687 PMBUS_HAVE_TEMP
| PMBUS_HAVE_STATUS_TEMP
;
689 /* Enable VOUT & TEMP1 if not enabled (disabled by default) */
690 if ((config
& (ADM1278_VOUT_EN
| ADM1278_TEMP1_EN
)) !=
691 (ADM1278_VOUT_EN
| ADM1278_TEMP1_EN
)) {
692 config
|= ADM1278_VOUT_EN
| ADM1278_TEMP1_EN
;
693 ret
= i2c_smbus_write_byte_data(client
,
697 dev_err(&client
->dev
,
698 "Failed to enable VOUT monitoring\n");
703 if (config
& ADM1278_VIN_EN
)
704 info
->func
[0] |= PMBUS_HAVE_VIN
;
708 data
->have_iout_min
= true;
709 data
->have_pin_min
= true;
710 data
->have_pin_max
= true;
711 data
->have_mfr_vaux_status
= true;
712 data
->have_power_sampling
= true;
714 coefficients
= adm1293_coefficients
;
717 switch (config
& ADM1293_VIN_SEL_MASK
) {
718 case ADM1293_VIN_SEL_012
: /* 1.2V */
721 case ADM1293_VIN_SEL_074
: /* 7.4V */
724 case ADM1293_VIN_SEL_210
: /* 21V */
727 default: /* disabled */
731 switch (config
& ADM1293_IRANGE_MASK
) {
732 case ADM1293_IRANGE_25
:
735 case ADM1293_IRANGE_50
:
738 case ADM1293_IRANGE_100
:
741 case ADM1293_IRANGE_200
:
747 pindex
= 7 + vindex
* 4 + (cindex
- 3);
749 if (config
& ADM1293_VAUX_EN
)
751 PMBUS_HAVE_VOUT
| PMBUS_HAVE_STATUS_VOUT
;
753 info
->func
[0] |= PMBUS_HAVE_PIN
|
754 PMBUS_HAVE_VIN
| PMBUS_HAVE_STATUS_INPUT
;
758 dev_err(&client
->dev
, "Unsupported device\n");
765 info
->m
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].m
;
766 info
->b
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].b
;
767 info
->R
[PSC_VOLTAGE_IN
] = coefficients
[vindex
].R
;
770 info
->m
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].m
;
771 info
->b
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].b
;
772 info
->R
[PSC_VOLTAGE_OUT
] = coefficients
[voindex
].R
;
775 /* Scale current with sense resistor value */
776 info
->m
[PSC_CURRENT_OUT
] =
777 coefficients
[cindex
].m
* shunt
/ 1000;
778 info
->b
[PSC_CURRENT_OUT
] = coefficients
[cindex
].b
;
779 info
->R
[PSC_CURRENT_OUT
] = coefficients
[cindex
].R
;
783 coefficients
[pindex
].m
* shunt
/ 1000;
784 info
->b
[PSC_POWER
] = coefficients
[pindex
].b
;
785 info
->R
[PSC_POWER
] = coefficients
[pindex
].R
;
788 info
->m
[PSC_TEMPERATURE
] = coefficients
[tindex
].m
;
789 info
->b
[PSC_TEMPERATURE
] = coefficients
[tindex
].b
;
790 info
->R
[PSC_TEMPERATURE
] = coefficients
[tindex
].R
;
793 return pmbus_do_probe(client
, id
, info
);
796 static struct i2c_driver adm1275_driver
= {
800 .probe
= adm1275_probe
,
801 .remove
= pmbus_do_remove
,
802 .id_table
= adm1275_id
,
805 module_i2c_driver(adm1275_driver
);
807 MODULE_AUTHOR("Guenter Roeck");
808 MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
809 MODULE_LICENSE("GPL");