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_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 { "adm1293", adm1293 },
486 { "adm1294", adm1294 },
489 MODULE_DEVICE_TABLE(i2c, adm1275_id);
491 /* Enable VOUT & TEMP1 if not enabled (disabled by default) */
492 static int adm1275_enable_vout_temp(struct adm1275_data *data,
493 struct i2c_client *client, int config)
497 if ((config & ADM1278_PMON_DEFCONFIG) != ADM1278_PMON_DEFCONFIG) {
498 config |= ADM1278_PMON_DEFCONFIG;
499 ret = adm1275_write_pmon_config(data, client, config);
501 dev_err(&client->dev, "Failed to enable VOUT/TEMP1 monitoring\n");
508 static int adm1275_probe(struct i2c_client *client)
510 s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
511 u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
512 int config, device_config;
514 struct pmbus_driver_info *info;
515 struct adm1275_data *data;
516 const struct i2c_device_id *mid;
517 const struct coefficients *coefficients;
518 int vindex = -1, voindex = -1, cindex = -1, pindex = -1;
523 if (!i2c_check_functionality(client->adapter,
524 I2C_FUNC_SMBUS_READ_BYTE_DATA
525 | I2C_FUNC_SMBUS_BLOCK_DATA))
528 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_ID, block_buffer);
530 dev_err(&client->dev, "Failed to read Manufacturer ID\n");
533 if (ret != 3 || strncmp(block_buffer, "ADI", 3)) {
534 dev_err(&client->dev, "Unsupported Manufacturer ID\n");
538 ret = i2c_smbus_read_block_data(client, PMBUS_MFR_MODEL, block_buffer);
540 dev_err(&client->dev, "Failed to read Manufacturer Model\n");
543 for (mid = adm1275_id; mid->name[0]; mid++) {
544 if (!strncasecmp(mid->name, block_buffer, strlen(mid->name)))
548 dev_err(&client->dev, "Unsupported device\n");
552 if (strcmp(client->name, mid->name) != 0)
553 dev_notice(&client->dev,
554 "Device mismatch: Configured %s, detected %s\n",
555 client->name, mid->name);
557 if (mid->driver_data == adm1272 || mid->driver_data == adm1278 ||
558 mid->driver_data == adm1293 || mid->driver_data == adm1294)
559 config_read_fn = i2c_smbus_read_word_data;
561 config_read_fn = i2c_smbus_read_byte_data;
562 config = config_read_fn(client, ADM1275_PMON_CONFIG);
566 device_config = config_read_fn(client, ADM1275_DEVICE_CONFIG);
567 if (device_config < 0)
568 return device_config;
570 data = devm_kzalloc(&client->dev, sizeof(struct adm1275_data),
575 if (of_property_read_u32(client->dev.of_node,
576 "shunt-resistor-micro-ohms", &shunt))
577 shunt = 1000; /* 1 mOhm if not set via DT */
582 data->id = mid->driver_data;
587 info->format[PSC_VOLTAGE_IN] = direct;
588 info->format[PSC_VOLTAGE_OUT] = direct;
589 info->format[PSC_CURRENT_OUT] = direct;
590 info->format[PSC_POWER] = direct;
591 info->format[PSC_TEMPERATURE] = direct;
592 info->func[0] = PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
595 info->read_word_data = adm1275_read_word_data;
596 info->read_byte_data = adm1275_read_byte_data;
597 info->write_word_data = adm1275_write_word_data;
601 if (device_config & ADM1275_IOUT_WARN2_SELECT)
602 data->have_oc_fault = true;
604 data->have_uc_fault = true;
605 data->have_pin_max = true;
606 data->have_vaux_status = true;
608 coefficients = adm1075_coefficients;
610 switch (config & ADM1075_IRANGE_MASK) {
611 case ADM1075_IRANGE_25:
615 case ADM1075_IRANGE_50:
620 dev_err(&client->dev, "Invalid input current range");
624 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
625 | PMBUS_HAVE_STATUS_INPUT;
626 if (config & ADM1275_VIN_VOUT_SELECT)
628 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
631 data->have_vout = true;
632 data->have_pin_max = true;
633 data->have_temp_max = true;
634 data->have_power_sampling = true;
636 coefficients = adm1272_coefficients;
637 vindex = (config & ADM1275_VRANGE) ? 1 : 0;
638 cindex = (config & ADM1272_IRANGE) ? 3 : 2;
639 /* pindex depends on the combination of the above */
640 switch (config & (ADM1275_VRANGE | ADM1272_IRANGE)) {
651 case ADM1275_VRANGE | ADM1272_IRANGE:
657 info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
658 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
659 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
661 ret = adm1275_enable_vout_temp(data, client, config);
665 if (config & ADM1278_VIN_EN)
666 info->func[0] |= PMBUS_HAVE_VIN;
669 if (device_config & ADM1275_IOUT_WARN2_SELECT)
670 data->have_oc_fault = true;
672 data->have_uc_fault = true;
673 data->have_vout = true;
675 coefficients = adm1275_coefficients;
676 vindex = (config & ADM1275_VRANGE) ? 0 : 1;
679 if (config & ADM1275_VIN_VOUT_SELECT)
681 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
684 PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
687 if (device_config & ADM1275_IOUT_WARN2_SELECT)
688 data->have_oc_fault = true;
690 data->have_uc_fault = true;
691 data->have_vout = true;
692 data->have_pin_max = true;
694 coefficients = adm1276_coefficients;
695 vindex = (config & ADM1275_VRANGE) ? 0 : 1;
697 pindex = (config & ADM1275_VRANGE) ? 3 : 4;
699 info->func[0] |= PMBUS_HAVE_VIN | PMBUS_HAVE_PIN
700 | PMBUS_HAVE_STATUS_INPUT;
701 if (config & ADM1275_VIN_VOUT_SELECT)
703 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
706 data->have_vout = true;
707 data->have_pin_max = true;
708 data->have_temp_max = true;
709 data->have_power_sampling = true;
711 coefficients = adm1278_coefficients;
717 info->func[0] |= PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT |
718 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
719 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP;
721 ret = adm1275_enable_vout_temp(data, client, config);
725 if (config & ADM1278_VIN_EN)
726 info->func[0] |= PMBUS_HAVE_VIN;
730 data->have_iout_min = true;
731 data->have_pin_min = true;
732 data->have_pin_max = true;
733 data->have_mfr_vaux_status = true;
734 data->have_power_sampling = true;
736 coefficients = adm1293_coefficients;
739 switch (config & ADM1293_VIN_SEL_MASK) {
740 case ADM1293_VIN_SEL_012: /* 1.2V */
743 case ADM1293_VIN_SEL_074: /* 7.4V */
746 case ADM1293_VIN_SEL_210: /* 21V */
749 default: /* disabled */
753 switch (config & ADM1293_IRANGE_MASK) {
754 case ADM1293_IRANGE_25:
757 case ADM1293_IRANGE_50:
760 case ADM1293_IRANGE_100:
763 case ADM1293_IRANGE_200:
769 pindex = 7 + vindex * 4 + (cindex - 3);
771 if (config & ADM1293_VAUX_EN)
773 PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT;
775 info->func[0] |= PMBUS_HAVE_PIN |
776 PMBUS_HAVE_VIN | PMBUS_HAVE_STATUS_INPUT;
780 dev_err(&client->dev, "Unsupported device\n");
784 if (data->have_power_sampling &&
785 of_property_read_u32(client->dev.of_node,
786 "adi,power-sample-average", &avg) == 0) {
787 if (!avg || avg > ADM1275_SAMPLES_AVG_MAX ||
788 BIT(__fls(avg)) != avg) {
789 dev_err(&client->dev,
790 "Invalid number of power samples");
793 ret = adm1275_write_samples(data, client, true, ilog2(avg));
795 dev_err(&client->dev,
796 "Setting power sample averaging failed with error %d",
802 if (of_property_read_u32(client->dev.of_node,
803 "adi,volt-curr-sample-average", &avg) == 0) {
804 if (!avg || avg > ADM1275_SAMPLES_AVG_MAX ||
805 BIT(__fls(avg)) != avg) {
806 dev_err(&client->dev,
807 "Invalid number of voltage/current samples");
810 ret = adm1275_write_samples(data, client, false, ilog2(avg));
812 dev_err(&client->dev,
813 "Setting voltage and current sample averaging failed with error %d",
822 info->m[PSC_VOLTAGE_IN] = coefficients[vindex].m;
823 info->b[PSC_VOLTAGE_IN] = coefficients[vindex].b;
824 info->R[PSC_VOLTAGE_IN] = coefficients[vindex].R;
827 info->m[PSC_VOLTAGE_OUT] = coefficients[voindex].m;
828 info->b[PSC_VOLTAGE_OUT] = coefficients[voindex].b;
829 info->R[PSC_VOLTAGE_OUT] = coefficients[voindex].R;
832 /* Scale current with sense resistor value */
833 info->m[PSC_CURRENT_OUT] =
834 coefficients[cindex].m * shunt / 1000;
835 info->b[PSC_CURRENT_OUT] = coefficients[cindex].b;
836 info->R[PSC_CURRENT_OUT] = coefficients[cindex].R;
840 coefficients[pindex].m * shunt / 1000;
841 info->b[PSC_POWER] = coefficients[pindex].b;
842 info->R[PSC_POWER] = coefficients[pindex].R;
845 info->m[PSC_TEMPERATURE] = coefficients[tindex].m;
846 info->b[PSC_TEMPERATURE] = coefficients[tindex].b;
847 info->R[PSC_TEMPERATURE] = coefficients[tindex].R;
850 return pmbus_do_probe(client, info);
853 static struct i2c_driver adm1275_driver = {
857 .probe = adm1275_probe,
858 .id_table = adm1275_id,
861 module_i2c_driver(adm1275_driver);
863 MODULE_AUTHOR("Guenter Roeck");
864 MODULE_DESCRIPTION("PMBus driver for Analog Devices ADM1275 and compatibles");
865 MODULE_LICENSE("GPL");
866 MODULE_IMPORT_NS(PMBUS);