1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers
5 * Copyright (C) 2020 Nvidia Technologies Ltd.
10 #include <linux/init.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
13 #include <linux/of_device.h>
16 /* Vendor specific registers. */
17 #define MP2975_MFR_APS_HYS_R2 0x0d
18 #define MP2975_MFR_SLOPE_TRIM3 0x1d
19 #define MP2975_MFR_VR_MULTI_CONFIG_R1 0x0d
20 #define MP2975_MFR_VR_MULTI_CONFIG_R2 0x1d
21 #define MP2975_MFR_APS_DECAY_ADV 0x56
22 #define MP2975_MFR_DC_LOOP_CTRL 0x59
23 #define MP2975_MFR_OCP_UCP_PHASE_SET 0x65
24 #define MP2975_MFR_VR_CONFIG1 0x68
25 #define MP2975_MFR_READ_CS1_2 0x82
26 #define MP2975_MFR_READ_CS3_4 0x83
27 #define MP2975_MFR_READ_CS5_6 0x84
28 #define MP2975_MFR_READ_CS7_8 0x85
29 #define MP2975_MFR_READ_CS9_10 0x86
30 #define MP2975_MFR_READ_CS11_12 0x87
31 #define MP2975_MFR_READ_IOUT_PK 0x90
32 #define MP2975_MFR_READ_POUT_PK 0x91
33 #define MP2975_MFR_READ_VREF_R1 0xa1
34 #define MP2975_MFR_READ_VREF_R2 0xa3
35 #define MP2975_MFR_OVP_TH_SET 0xe5
36 #define MP2975_MFR_UVP_SET 0xe6
38 #define MP2973_MFR_RESO_SET 0xc7
40 #define MP2975_VOUT_FORMAT BIT(15)
41 #define MP2975_VID_STEP_SEL_R1 BIT(4)
42 #define MP2975_IMVP9_EN_R1 BIT(13)
43 #define MP2975_VID_STEP_SEL_R2 BIT(3)
44 #define MP2975_IMVP9_EN_R2 BIT(12)
45 #define MP2975_PRT_THRES_DIV_OV_EN BIT(14)
46 #define MP2975_DRMOS_KCS GENMASK(13, 12)
47 #define MP2975_PROT_DEV_OV_OFF 10
48 #define MP2975_PROT_DEV_OV_ON 5
49 #define MP2975_SENSE_AMPL BIT(11)
50 #define MP2975_SENSE_AMPL_UNIT 1
51 #define MP2975_SENSE_AMPL_HALF 2
52 #define MP2975_VIN_UV_LIMIT_UNIT 8
54 #define MP2973_VOUT_FORMAT_R1 GENMASK(7, 6)
55 #define MP2973_VOUT_FORMAT_R2 GENMASK(4, 3)
56 #define MP2973_VOUT_FORMAT_DIRECT_R1 BIT(7)
57 #define MP2973_VOUT_FORMAT_LINEAR_R1 BIT(6)
58 #define MP2973_VOUT_FORMAT_DIRECT_R2 BIT(4)
59 #define MP2973_VOUT_FORMAT_LINEAR_R2 BIT(3)
61 #define MP2973_MFR_VR_MULTI_CONFIG_R1 0x0d
62 #define MP2973_MFR_VR_MULTI_CONFIG_R2 0x1d
63 #define MP2973_VID_STEP_SEL_R1 BIT(4)
64 #define MP2973_IMVP9_EN_R1 BIT(14)
65 #define MP2973_VID_STEP_SEL_R2 BIT(3)
66 #define MP2973_IMVP9_EN_R2 BIT(13)
68 #define MP2973_MFR_OCP_TOTAL_SET 0x5f
69 #define MP2973_OCP_TOTAL_CUR_MASK GENMASK(6, 0)
70 #define MP2973_MFR_OCP_LEVEL_RES BIT(15)
72 #define MP2973_MFR_READ_IOUT_PK 0x90
73 #define MP2973_MFR_READ_POUT_PK 0x91
75 #define MP2975_MAX_PHASE_RAIL1 8
76 #define MP2975_MAX_PHASE_RAIL2 4
78 #define MP2973_MAX_PHASE_RAIL1 14
79 #define MP2973_MAX_PHASE_RAIL2 6
81 #define MP2971_MAX_PHASE_RAIL1 8
82 #define MP2971_MAX_PHASE_RAIL2 3
84 #define MP2975_PAGE_NUM 2
86 #define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \
87 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \
88 PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL)
91 mp2971, mp2973, mp2975
94 static const int mp2975_max_phases[][MP2975_PAGE_NUM] = {
95 [mp2975] = { MP2975_MAX_PHASE_RAIL1, MP2975_MAX_PHASE_RAIL2 },
96 [mp2973] = { MP2973_MAX_PHASE_RAIL1, MP2973_MAX_PHASE_RAIL2 },
97 [mp2971] = { MP2971_MAX_PHASE_RAIL1, MP2971_MAX_PHASE_RAIL2 },
101 struct pmbus_driver_info info;
104 int max_phases[MP2975_PAGE_NUM];
105 int vid_step[MP2975_PAGE_NUM];
106 int vref[MP2975_PAGE_NUM];
107 int vref_off[MP2975_PAGE_NUM];
108 int vout_max[MP2975_PAGE_NUM];
109 int vout_ov_fixed[MP2975_PAGE_NUM];
110 int curr_sense_gain[MP2975_PAGE_NUM];
113 static const struct i2c_device_id mp2975_id[] = {
120 MODULE_DEVICE_TABLE(i2c, mp2975_id);
122 static const struct regulator_desc __maybe_unused mp2975_reg_desc[] = {
123 PMBUS_REGULATOR("vout", 0),
124 PMBUS_REGULATOR("vout", 1),
127 #define to_mp2975_data(x) container_of(x, struct mp2975_data, info)
129 static int mp2975_read_byte_data(struct i2c_client *client, int page, int reg)
132 case PMBUS_VOUT_MODE:
134 * Report direct format as configured by MFR_DC_LOOP_CTRL.
135 * Unlike on MP2971/MP2973 the reported VOUT_MODE isn't automatically
136 * internally updated, but always reads as PB_VOUT_MODE_VID.
138 return PB_VOUT_MODE_DIRECT;
145 mp2975_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg,
148 int ret = pmbus_read_word_data(client, page, phase, reg);
150 return (ret > 0) ? ret & mask : ret;
154 mp2975_vid2direct(int vrf, int val)
159 return 250 + (val - 1) * 5;
163 return 500 + (val - 1) * 10;
167 return 200 + (val - 1) * 10;
175 #define MAX_LIN_MANTISSA (1023 * 1000)
176 #define MIN_LIN_MANTISSA (511 * 1000)
178 /* Converts a milli-unit DIRECT value to LINEAR11 format */
179 static u16 mp2975_data2reg_linear11(s64 val)
181 s16 exponent = 0, mantissa;
182 bool negative = false;
188 /* Reduce large mantissa until it fits into 10 bit */
189 while (val >= MAX_LIN_MANTISSA && exponent < 15) {
193 /* Increase small mantissa to improve precision */
194 while (val < MIN_LIN_MANTISSA && exponent > -15) {
199 /* Convert mantissa from milli-units to units */
200 mantissa = clamp_val(DIV_ROUND_CLOSEST_ULL(val, 1000), 0, 0x3ff);
204 mantissa = -mantissa;
206 /* Convert to 5 bit exponent, 11 bit mantissa */
207 return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800);
211 mp2975_read_phase(struct i2c_client *client, struct mp2975_data *data,
212 int page, int phase, u8 reg)
216 ret = pmbus_read_word_data(client, page, phase, reg);
220 if (!((phase + 1) % MP2975_PAGE_NUM))
225 * Output value is calculated as: (READ_CSx / 80 – 1.23) / (Kcs * Rcs)
227 * - Kcs is the DrMOS current sense gain of power stage, which is
228 * obtained from the register MP2975_MFR_VR_CONFIG1, bits 13-12 with
229 * the following selection of DrMOS (data->curr_sense_gain[page]):
230 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A.
231 * - Rcs is the internal phase current sense resistor which is constant
234 ph_curr = ret * 100 - 9800;
237 * Current phase sensing, providing by the device is not accurate
238 * for the light load. This because sampling of current occurrence of
239 * bit weight has a big deviation for light load. For handling such
240 * case phase current is represented as the maximum between the value
241 * calculated above and total rail current divided by number phases.
243 ret = pmbus_read_word_data(client, page, phase, PMBUS_READ_IOUT);
247 return max_t(int, DIV_ROUND_CLOSEST(ret, data->info.phases[page]),
248 DIV_ROUND_CLOSEST(ph_curr, data->curr_sense_gain[page]));
252 mp2975_read_phases(struct i2c_client *client, struct mp2975_data *data,
260 ret = mp2975_read_phase(client, data, page, phase,
261 MP2975_MFR_READ_CS7_8);
264 ret = mp2975_read_phase(client, data, page, phase,
265 MP2975_MFR_READ_CS9_10);
268 ret = mp2975_read_phase(client, data, page, phase,
269 MP2975_MFR_READ_CS11_12);
277 ret = mp2975_read_phase(client, data, page, phase,
278 MP2975_MFR_READ_CS1_2);
281 ret = mp2975_read_phase(client, data, page, phase,
282 MP2975_MFR_READ_CS3_4);
285 ret = mp2975_read_phase(client, data, page, phase,
286 MP2975_MFR_READ_CS5_6);
289 ret = mp2975_read_phase(client, data, page, phase,
290 MP2975_MFR_READ_CS7_8);
293 ret = mp2975_read_phase(client, data, page, phase,
294 MP2975_MFR_READ_CS9_10);
297 ret = mp2975_read_phase(client, data, page, phase,
298 MP2975_MFR_READ_CS11_12);
307 static int mp2973_read_word_data(struct i2c_client *client, int page,
310 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
311 struct mp2975_data *data = to_mp2975_data(info);
315 case PMBUS_STATUS_WORD:
316 /* MP2973 & MP2971 return PGOOD instead of PB_STATUS_POWER_GOOD_N. */
317 ret = pmbus_read_word_data(client, page, phase, reg);
318 ret ^= PB_STATUS_POWER_GOOD_N;
320 case PMBUS_OT_FAULT_LIMIT:
321 ret = mp2975_read_word_helper(client, page, phase, reg,
324 case PMBUS_VIN_OV_FAULT_LIMIT:
325 ret = mp2975_read_word_helper(client, page, phase, reg,
330 ret = DIV_ROUND_CLOSEST(ret, MP2975_VIN_UV_LIMIT_UNIT);
332 case PMBUS_VOUT_OV_FAULT_LIMIT:
334 * MP2971 and mp2973 only supports tracking (ovp1) mode.
336 ret = mp2975_read_word_helper(client, page, phase,
337 MP2975_MFR_OVP_TH_SET,
342 ret = data->vout_max[page] + 50 * (ret + 1);
344 case PMBUS_VOUT_UV_FAULT_LIMIT:
345 ret = mp2975_read_word_helper(client, page, phase, reg,
349 ret = mp2975_vid2direct(info->vrm_version[page], ret);
351 case PMBUS_VIRT_READ_POUT_MAX:
352 ret = pmbus_read_word_data(client, page, phase,
353 MP2973_MFR_READ_POUT_PK);
355 case PMBUS_VIRT_READ_IOUT_MAX:
356 ret = pmbus_read_word_data(client, page, phase,
357 MP2973_MFR_READ_IOUT_PK);
359 case PMBUS_IOUT_OC_FAULT_LIMIT:
360 ret = mp2975_read_word_helper(client, page, phase,
361 MP2973_MFR_OCP_TOTAL_SET,
366 if (ret & MP2973_MFR_OCP_LEVEL_RES)
367 ret = 2 * (ret & MP2973_OCP_TOTAL_CUR_MASK);
369 ret = ret & MP2973_OCP_TOTAL_CUR_MASK;
371 ret = mp2975_data2reg_linear11(ret * info->phases[page] * 1000);
373 case PMBUS_UT_WARN_LIMIT:
374 case PMBUS_UT_FAULT_LIMIT:
375 case PMBUS_VIN_UV_WARN_LIMIT:
376 case PMBUS_VIN_UV_FAULT_LIMIT:
377 case PMBUS_VOUT_UV_WARN_LIMIT:
378 case PMBUS_VOUT_OV_WARN_LIMIT:
379 case PMBUS_VIN_OV_WARN_LIMIT:
380 case PMBUS_IIN_OC_FAULT_LIMIT:
381 case PMBUS_IOUT_OC_LV_FAULT_LIMIT:
382 case PMBUS_IOUT_OC_WARN_LIMIT:
383 case PMBUS_IOUT_UC_FAULT_LIMIT:
384 case PMBUS_POUT_OP_FAULT_LIMIT:
385 case PMBUS_POUT_OP_WARN_LIMIT:
386 case PMBUS_PIN_OP_WARN_LIMIT:
395 static int mp2975_read_word_data(struct i2c_client *client, int page,
398 const struct pmbus_driver_info *info = pmbus_get_driver_info(client);
399 struct mp2975_data *data = to_mp2975_data(info);
403 case PMBUS_OT_FAULT_LIMIT:
404 ret = mp2975_read_word_helper(client, page, phase, reg,
407 case PMBUS_VIN_OV_FAULT_LIMIT:
408 ret = mp2975_read_word_helper(client, page, phase, reg,
413 ret = DIV_ROUND_CLOSEST(ret, MP2975_VIN_UV_LIMIT_UNIT);
415 case PMBUS_VOUT_OV_FAULT_LIMIT:
417 * Register provides two values for over-voltage protection
418 * threshold for fixed (ovp2) and tracking (ovp1) modes. The
419 * minimum of these two values is provided as over-voltage
422 ret = mp2975_read_word_helper(client, page, phase,
423 MP2975_MFR_OVP_TH_SET,
428 ret = min_t(int, data->vout_max[page] + 50 * (ret + 1),
429 data->vout_ov_fixed[page]);
431 case PMBUS_VOUT_UV_FAULT_LIMIT:
432 ret = mp2975_read_word_helper(client, page, phase,
438 ret = DIV_ROUND_CLOSEST(data->vref[page] * 10 - 50 *
439 (ret + 1) * data->vout_scale, 10);
441 case PMBUS_VIRT_READ_POUT_MAX:
442 ret = mp2975_read_word_helper(client, page, phase,
443 MP2975_MFR_READ_POUT_PK,
448 ret = DIV_ROUND_CLOSEST(ret, 4);
450 case PMBUS_VIRT_READ_IOUT_MAX:
451 ret = mp2975_read_word_helper(client, page, phase,
452 MP2975_MFR_READ_IOUT_PK,
457 ret = DIV_ROUND_CLOSEST(ret, 4);
459 case PMBUS_READ_IOUT:
460 ret = mp2975_read_phases(client, data, page, phase);
465 case PMBUS_UT_WARN_LIMIT:
466 case PMBUS_UT_FAULT_LIMIT:
467 case PMBUS_VIN_UV_WARN_LIMIT:
468 case PMBUS_VIN_UV_FAULT_LIMIT:
469 case PMBUS_VOUT_UV_WARN_LIMIT:
470 case PMBUS_VOUT_OV_WARN_LIMIT:
471 case PMBUS_VIN_OV_WARN_LIMIT:
472 case PMBUS_IIN_OC_FAULT_LIMIT:
473 case PMBUS_IOUT_OC_LV_FAULT_LIMIT:
474 case PMBUS_IIN_OC_WARN_LIMIT:
475 case PMBUS_IOUT_OC_WARN_LIMIT:
476 case PMBUS_IOUT_OC_FAULT_LIMIT:
477 case PMBUS_IOUT_UC_FAULT_LIMIT:
478 case PMBUS_POUT_OP_FAULT_LIMIT:
479 case PMBUS_POUT_OP_WARN_LIMIT:
480 case PMBUS_PIN_OP_WARN_LIMIT:
489 static int mp2975_identify_multiphase_rail2(struct i2c_client *client,
490 struct mp2975_data *data)
495 * Identify multiphase for rail 2 - could be from 0 to data->max_phases[1].
496 * In case phase number is zero – only page zero is supported
498 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2);
502 ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R2);
506 ret &= GENMASK(2, 0);
507 return (ret >= data->max_phases[1]) ? data->max_phases[1] : ret;
510 static void mp2975_set_phase_rail1(struct pmbus_driver_info *info)
514 for (i = 0 ; i < info->phases[0]; i++)
515 info->pfunc[i] = PMBUS_HAVE_IOUT;
519 mp2975_set_phase_rail2(struct pmbus_driver_info *info, int num_phases)
523 /* Set phases for rail 2 from upper to lower. */
524 for (i = 1; i <= num_phases; i++)
525 info->pfunc[MP2975_MAX_PHASE_RAIL1 - i] = PMBUS_HAVE_IOUT;
529 mp2975_identify_multiphase(struct i2c_client *client, struct mp2975_data *data,
530 struct pmbus_driver_info *info)
532 int num_phases2, ret;
534 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2);
538 /* Identify multiphase for rail 1 - could be from 1 to data->max_phases[0]. */
539 ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R1);
543 info->phases[0] = ret & GENMASK(3, 0);
546 * The device provides a total of $n PWM pins, and can be configured
547 * to different phase count applications for rail 1 and rail 2.
548 * Rail 1 can be set to $n phases, while rail 2 can be set to less than
549 * that. When rail 1’s phase count is configured as 0, rail
550 * 1 operates with 1-phase DCM. When rail 2 phase count is configured
551 * as 0, rail 2 is disabled.
553 if (info->phases[0] > data->max_phases[0])
556 if (data->chip_id == mp2975) {
557 mp2975_set_phase_rail1(info);
558 num_phases2 = min(data->max_phases[0] - info->phases[0],
559 data->max_phases[1]);
560 if (info->phases[1] && info->phases[1] <= num_phases2)
561 mp2975_set_phase_rail2(info, num_phases2);
568 mp2975_identify_vid(struct i2c_client *client, struct mp2975_data *data,
569 struct pmbus_driver_info *info, u32 reg, int page,
570 u32 imvp_bit, u32 vr_bit)
574 /* Identify VID mode and step selection. */
575 ret = i2c_smbus_read_word_data(client, reg);
579 if (ret & imvp_bit) {
580 info->vrm_version[page] = imvp9;
581 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF;
582 } else if (ret & vr_bit) {
583 info->vrm_version[page] = vr12;
584 data->vid_step[page] = MP2975_PROT_DEV_OV_ON;
586 info->vrm_version[page] = vr13;
587 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF;
594 mp2975_identify_rails_vid(struct i2c_client *client, struct mp2975_data *data,
595 struct pmbus_driver_info *info)
599 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2);
603 /* Identify VID mode for rail 1. */
604 ret = mp2975_identify_vid(client, data, info,
605 MP2975_MFR_VR_MULTI_CONFIG_R1, 0,
606 MP2975_IMVP9_EN_R1, MP2975_VID_STEP_SEL_R1);
610 /* Identify VID mode for rail 2, if connected. */
612 ret = mp2975_identify_vid(client, data, info,
613 MP2975_MFR_VR_MULTI_CONFIG_R2, 1,
615 MP2975_VID_STEP_SEL_R2);
621 mp2973_identify_rails_vid(struct i2c_client *client, struct mp2975_data *data,
622 struct pmbus_driver_info *info)
626 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2);
630 /* Identify VID mode for rail 1. */
631 ret = mp2975_identify_vid(client, data, info,
632 MP2973_MFR_VR_MULTI_CONFIG_R1, 0,
633 MP2973_IMVP9_EN_R1, MP2973_VID_STEP_SEL_R1);
638 /* Identify VID mode for rail 2, if connected. */
640 ret = mp2975_identify_vid(client, data, info,
641 MP2973_MFR_VR_MULTI_CONFIG_R2, 1,
643 MP2973_VID_STEP_SEL_R2);
649 mp2975_current_sense_gain_get(struct i2c_client *client,
650 struct mp2975_data *data)
655 * Obtain DrMOS current sense gain of power stage from the register
656 * MP2975_MFR_VR_CONFIG1, bits 13-12. The value is selected as below:
657 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. Other
658 * values are invalid.
660 for (i = 0 ; i < data->info.pages; i++) {
661 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i);
664 ret = i2c_smbus_read_word_data(client,
665 MP2975_MFR_VR_CONFIG1);
669 switch ((ret & MP2975_DRMOS_KCS) >> 12) {
671 data->curr_sense_gain[i] = 50;
674 data->curr_sense_gain[i] = 85;
677 data->curr_sense_gain[i] = 97;
680 data->curr_sense_gain[i] = 100;
689 mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data,
690 struct pmbus_driver_info *info)
694 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 3);
698 /* Get voltage reference value for rail 1. */
699 ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R1);
703 data->vref[0] = ret * data->vid_step[0];
705 /* Get voltage reference value for rail 2, if connected. */
706 if (data->info.pages == MP2975_PAGE_NUM) {
707 ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R2);
711 data->vref[1] = ret * data->vid_step[1];
717 mp2975_vref_offset_get(struct i2c_client *client, struct mp2975_data *data,
722 ret = i2c_smbus_read_word_data(client, MP2975_MFR_OVP_TH_SET);
726 switch ((ret & GENMASK(5, 3)) >> 3) {
728 data->vref_off[page] = 140;
731 data->vref_off[page] = 220;
734 data->vref_off[page] = 400;
743 mp2975_vout_max_get(struct i2c_client *client, struct mp2975_data *data,
744 struct pmbus_driver_info *info, int page)
748 /* Get maximum reference voltage of VID-DAC in VID format. */
749 ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_MAX);
753 data->vout_max[page] = mp2975_vid2direct(info->vrm_version[page], ret &
759 mp2975_set_vout_format(struct i2c_client *client,
760 struct mp2975_data *data, int page)
764 /* Enable DIRECT VOUT format 1mV/LSB */
765 if (data->chip_id == mp2975) {
766 ret = i2c_smbus_read_word_data(client, MP2975_MFR_DC_LOOP_CTRL);
769 if (ret & MP2975_VOUT_FORMAT) {
770 ret &= ~MP2975_VOUT_FORMAT;
771 ret = i2c_smbus_write_word_data(client, MP2975_MFR_DC_LOOP_CTRL, ret);
774 ret = i2c_smbus_read_word_data(client, MP2973_MFR_RESO_SET);
780 i &= ~MP2973_VOUT_FORMAT_R1;
781 i |= MP2973_VOUT_FORMAT_DIRECT_R1;
783 i &= ~MP2973_VOUT_FORMAT_R2;
784 i |= MP2973_VOUT_FORMAT_DIRECT_R2;
787 ret = i2c_smbus_write_word_data(client, MP2973_MFR_RESO_SET, i);
793 mp2975_vout_ov_scale_get(struct i2c_client *client, struct mp2975_data *data,
794 struct pmbus_driver_info *info)
796 int thres_dev, sense_ampl, ret;
798 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
803 * Get divider for over- and under-voltage protection thresholds
804 * configuration from the Advanced Options of Auto Phase Shedding and
807 ret = i2c_smbus_read_word_data(client, MP2975_MFR_APS_DECAY_ADV);
810 thres_dev = ret & MP2975_PRT_THRES_DIV_OV_EN ? MP2975_PROT_DEV_OV_ON :
811 MP2975_PROT_DEV_OV_OFF;
813 /* Select the gain of remote sense amplifier. */
814 ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_SCALE_LOOP);
817 sense_ampl = ret & MP2975_SENSE_AMPL ? MP2975_SENSE_AMPL_HALF :
818 MP2975_SENSE_AMPL_UNIT;
820 data->vout_scale = sense_ampl * thres_dev;
826 mp2975_vout_per_rail_config_get(struct i2c_client *client,
827 struct mp2975_data *data,
828 struct pmbus_driver_info *info)
832 for (i = 0; i < data->info.pages; i++) {
833 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i);
837 /* Set VOUT format for READ_VOUT command : direct. */
838 ret = mp2975_set_vout_format(client, data, i);
842 /* Obtain maximum voltage values. */
843 ret = mp2975_vout_max_get(client, data, info, i);
847 /* Skip if reading Vref is unsupported */
848 if (data->chip_id != mp2975)
851 /* Obtain voltage reference offsets. */
852 ret = mp2975_vref_offset_get(client, data, i);
857 * Set over-voltage fixed value. Thresholds are provided as
858 * fixed value, and tracking value. The minimum of them are
859 * exposed as over-voltage critical threshold.
861 data->vout_ov_fixed[i] = data->vref[i] +
862 DIV_ROUND_CLOSEST(data->vref_off[i] *
870 static struct pmbus_driver_info mp2975_info = {
872 .format[PSC_VOLTAGE_IN] = linear,
873 .format[PSC_VOLTAGE_OUT] = direct,
874 .format[PSC_TEMPERATURE] = direct,
875 .format[PSC_CURRENT_IN] = linear,
876 .format[PSC_CURRENT_OUT] = direct,
877 .format[PSC_POWER] = direct,
878 .m[PSC_TEMPERATURE] = 1,
879 .m[PSC_VOLTAGE_OUT] = 1,
880 .R[PSC_VOLTAGE_OUT] = 3,
881 .m[PSC_CURRENT_OUT] = 1,
883 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
884 PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
885 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT |
886 PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | PMBUS_PHASE_VIRTUAL,
887 .read_byte_data = mp2975_read_byte_data,
888 .read_word_data = mp2975_read_word_data,
889 #if IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR)
891 .reg_desc = mp2975_reg_desc,
895 static struct pmbus_driver_info mp2973_info = {
897 .format[PSC_VOLTAGE_IN] = linear,
898 .format[PSC_VOLTAGE_OUT] = direct,
899 .format[PSC_TEMPERATURE] = linear,
900 .format[PSC_CURRENT_IN] = linear,
901 .format[PSC_CURRENT_OUT] = linear,
902 .format[PSC_POWER] = linear,
903 .m[PSC_VOLTAGE_OUT] = 1,
904 .R[PSC_VOLTAGE_OUT] = 3,
905 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT |
906 PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT |
907 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT |
908 PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT,
909 .read_word_data = mp2973_read_word_data,
910 #if IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR)
912 .reg_desc = mp2975_reg_desc,
916 static int mp2975_probe(struct i2c_client *client)
918 struct pmbus_driver_info *info;
919 struct mp2975_data *data;
922 data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data),
927 if (client->dev.of_node)
928 data->chip_id = (enum chips)(unsigned long)of_device_get_match_data(&client->dev);
930 data->chip_id = i2c_match_id(mp2975_id, client)->driver_data;
932 memcpy(data->max_phases, mp2975_max_phases[data->chip_id],
933 sizeof(data->max_phases));
935 if (data->chip_id == mp2975)
936 memcpy(&data->info, &mp2975_info, sizeof(*info));
938 memcpy(&data->info, &mp2973_info, sizeof(*info));
942 /* Identify multiphase configuration for rail 2. */
943 ret = mp2975_identify_multiphase_rail2(client, data);
948 /* Two rails are connected. */
949 data->info.pages = MP2975_PAGE_NUM;
950 data->info.phases[1] = ret;
951 data->info.func[1] = MP2975_RAIL2_FUNC;
952 if (IS_ENABLED(CONFIG_SENSORS_MP2975_REGULATOR))
953 data->info.num_regulators = MP2975_PAGE_NUM;
956 /* Identify multiphase configuration. */
957 ret = mp2975_identify_multiphase(client, data, info);
961 if (data->chip_id == mp2975) {
962 /* Identify VID setting per rail. */
963 ret = mp2975_identify_rails_vid(client, data, info);
967 /* Obtain current sense gain of power stage. */
968 ret = mp2975_current_sense_gain_get(client, data);
972 /* Obtain voltage reference values. */
973 ret = mp2975_vref_get(client, data, info);
977 /* Obtain vout over-voltage scales. */
978 ret = mp2975_vout_ov_scale_get(client, data, info);
982 /* Identify VID setting per rail. */
983 ret = mp2973_identify_rails_vid(client, data, info);
988 /* Obtain offsets, maximum and format for vout. */
989 ret = mp2975_vout_per_rail_config_get(client, data, info);
993 return pmbus_do_probe(client, info);
996 static const struct of_device_id __maybe_unused mp2975_of_match[] = {
997 {.compatible = "mps,mp2971", .data = (void *)mp2971},
998 {.compatible = "mps,mp2973", .data = (void *)mp2973},
999 {.compatible = "mps,mp2975", .data = (void *)mp2975},
1002 MODULE_DEVICE_TABLE(of, mp2975_of_match);
1004 static struct i2c_driver mp2975_driver = {
1007 .of_match_table = of_match_ptr(mp2975_of_match),
1009 .probe = mp2975_probe,
1010 .id_table = mp2975_id,
1013 module_i2c_driver(mp2975_driver);
1015 MODULE_AUTHOR("Vadim Pasternak <vadimp@nvidia.com>");
1016 MODULE_DESCRIPTION("PMBus driver for MPS MP2975 device");
1017 MODULE_LICENSE("GPL");
1018 MODULE_IMPORT_NS(PMBUS);