1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers 4 * 5 * Copyright (C) 2020 Nvidia Technologies Ltd. 6 */ 7 8 #include <linux/err.h> 9 #include <linux/i2c.h> 10 #include <linux/init.h> 11 #include <linux/kernel.h> 12 #include <linux/module.h> 13 #include <linux/of_device.h> 14 #include "pmbus.h" 15 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 37 38 #define MP2975_VOUT_FORMAT BIT(15) 39 #define MP2975_VID_STEP_SEL_R1 BIT(4) 40 #define MP2975_IMVP9_EN_R1 BIT(13) 41 #define MP2975_VID_STEP_SEL_R2 BIT(3) 42 #define MP2975_IMVP9_EN_R2 BIT(12) 43 #define MP2975_PRT_THRES_DIV_OV_EN BIT(14) 44 #define MP2975_DRMOS_KCS GENMASK(13, 12) 45 #define MP2975_PROT_DEV_OV_OFF 10 46 #define MP2975_PROT_DEV_OV_ON 5 47 #define MP2975_SENSE_AMPL BIT(11) 48 #define MP2975_SENSE_AMPL_UNIT 1 49 #define MP2975_SENSE_AMPL_HALF 2 50 #define MP2975_VIN_UV_LIMIT_UNIT 8 51 52 #define MP2975_MAX_PHASE_RAIL1 8 53 #define MP2975_MAX_PHASE_RAIL2 4 54 #define MP2975_PAGE_NUM 2 55 56 #define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \ 57 PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \ 58 PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL) 59 60 enum chips { 61 mp2975 62 }; 63 64 struct mp2975_data { 65 struct pmbus_driver_info info; 66 enum chips chip_id; 67 int vout_scale; 68 int vid_step[MP2975_PAGE_NUM]; 69 int vref[MP2975_PAGE_NUM]; 70 int vref_off[MP2975_PAGE_NUM]; 71 int vout_max[MP2975_PAGE_NUM]; 72 int vout_ov_fixed[MP2975_PAGE_NUM]; 73 int curr_sense_gain[MP2975_PAGE_NUM]; 74 }; 75 76 static const struct i2c_device_id mp2975_id[] = { 77 {"mp2975", mp2975}, 78 {} 79 }; 80 81 MODULE_DEVICE_TABLE(i2c, mp2975_id); 82 83 #define to_mp2975_data(x) container_of(x, struct mp2975_data, info) 84 85 static int 86 mp2975_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg, 87 u16 mask) 88 { 89 int ret = pmbus_read_word_data(client, page, phase, reg); 90 91 return (ret > 0) ? ret & mask : ret; 92 } 93 94 static int 95 mp2975_vid2direct(int vrf, int val) 96 { 97 switch (vrf) { 98 case vr12: 99 if (val >= 0x01) 100 return 250 + (val - 1) * 5; 101 break; 102 case vr13: 103 if (val >= 0x01) 104 return 500 + (val - 1) * 10; 105 break; 106 case imvp9: 107 if (val >= 0x01) 108 return 200 + (val - 1) * 10; 109 break; 110 default: 111 return -EINVAL; 112 } 113 return 0; 114 } 115 116 static int 117 mp2975_read_phase(struct i2c_client *client, struct mp2975_data *data, 118 int page, int phase, u8 reg) 119 { 120 int ph_curr, ret; 121 122 ret = pmbus_read_word_data(client, page, phase, reg); 123 if (ret < 0) 124 return ret; 125 126 if (!((phase + 1) % MP2975_PAGE_NUM)) 127 ret >>= 8; 128 ret &= 0xff; 129 130 /* 131 * Output value is calculated as: (READ_CSx / 80 – 1.23) / (Kcs * Rcs) 132 * where: 133 * - Kcs is the DrMOS current sense gain of power stage, which is 134 * obtained from the register MP2975_MFR_VR_CONFIG1, bits 13-12 with 135 * the following selection of DrMOS (data->curr_sense_gain[page]): 136 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. 137 * - Rcs is the internal phase current sense resistor which is constant 138 * value 1kΩ. 139 */ 140 ph_curr = ret * 100 - 9800; 141 142 /* 143 * Current phase sensing, providing by the device is not accurate 144 * for the light load. This because sampling of current occurrence of 145 * bit weight has a big deviation for light load. For handling such 146 * case phase current is represented as the maximum between the value 147 * calculated above and total rail current divided by number phases. 148 */ 149 ret = pmbus_read_word_data(client, page, phase, PMBUS_READ_IOUT); 150 if (ret < 0) 151 return ret; 152 153 return max_t(int, DIV_ROUND_CLOSEST(ret, data->info.phases[page]), 154 DIV_ROUND_CLOSEST(ph_curr, data->curr_sense_gain[page])); 155 } 156 157 static int 158 mp2975_read_phases(struct i2c_client *client, struct mp2975_data *data, 159 int page, int phase) 160 { 161 int ret; 162 163 if (page) { 164 switch (phase) { 165 case 0 ... 1: 166 ret = mp2975_read_phase(client, data, page, phase, 167 MP2975_MFR_READ_CS7_8); 168 break; 169 case 2 ... 3: 170 ret = mp2975_read_phase(client, data, page, phase, 171 MP2975_MFR_READ_CS9_10); 172 break; 173 case 4 ... 5: 174 ret = mp2975_read_phase(client, data, page, phase, 175 MP2975_MFR_READ_CS11_12); 176 break; 177 default: 178 return -ENODATA; 179 } 180 } else { 181 switch (phase) { 182 case 0 ... 1: 183 ret = mp2975_read_phase(client, data, page, phase, 184 MP2975_MFR_READ_CS1_2); 185 break; 186 case 2 ... 3: 187 ret = mp2975_read_phase(client, data, page, phase, 188 MP2975_MFR_READ_CS3_4); 189 break; 190 case 4 ... 5: 191 ret = mp2975_read_phase(client, data, page, phase, 192 MP2975_MFR_READ_CS5_6); 193 break; 194 case 6 ... 7: 195 ret = mp2975_read_phase(client, data, page, phase, 196 MP2975_MFR_READ_CS7_8); 197 break; 198 case 8 ... 9: 199 ret = mp2975_read_phase(client, data, page, phase, 200 MP2975_MFR_READ_CS9_10); 201 break; 202 case 10 ... 11: 203 ret = mp2975_read_phase(client, data, page, phase, 204 MP2975_MFR_READ_CS11_12); 205 break; 206 default: 207 return -ENODATA; 208 } 209 } 210 return ret; 211 } 212 213 static int mp2975_read_word_data(struct i2c_client *client, int page, 214 int phase, int reg) 215 { 216 const struct pmbus_driver_info *info = pmbus_get_driver_info(client); 217 struct mp2975_data *data = to_mp2975_data(info); 218 int ret; 219 220 switch (reg) { 221 case PMBUS_OT_FAULT_LIMIT: 222 ret = mp2975_read_word_helper(client, page, phase, reg, 223 GENMASK(7, 0)); 224 break; 225 case PMBUS_VIN_OV_FAULT_LIMIT: 226 ret = mp2975_read_word_helper(client, page, phase, reg, 227 GENMASK(7, 0)); 228 if (ret < 0) 229 return ret; 230 231 ret = DIV_ROUND_CLOSEST(ret, MP2975_VIN_UV_LIMIT_UNIT); 232 break; 233 case PMBUS_VOUT_OV_FAULT_LIMIT: 234 /* 235 * Register provides two values for over-voltage protection 236 * threshold for fixed (ovp2) and tracking (ovp1) modes. The 237 * minimum of these two values is provided as over-voltage 238 * fault alarm. 239 */ 240 ret = mp2975_read_word_helper(client, page, phase, 241 MP2975_MFR_OVP_TH_SET, 242 GENMASK(2, 0)); 243 if (ret < 0) 244 return ret; 245 246 ret = min_t(int, data->vout_max[page] + 50 * (ret + 1), 247 data->vout_ov_fixed[page]); 248 break; 249 case PMBUS_VOUT_UV_FAULT_LIMIT: 250 ret = mp2975_read_word_helper(client, page, phase, 251 MP2975_MFR_UVP_SET, 252 GENMASK(2, 0)); 253 if (ret < 0) 254 return ret; 255 256 ret = DIV_ROUND_CLOSEST(data->vref[page] * 10 - 50 * 257 (ret + 1) * data->vout_scale, 10); 258 break; 259 case PMBUS_VIRT_READ_POUT_MAX: 260 ret = mp2975_read_word_helper(client, page, phase, 261 MP2975_MFR_READ_POUT_PK, 262 GENMASK(12, 0)); 263 if (ret < 0) 264 return ret; 265 266 ret = DIV_ROUND_CLOSEST(ret, 4); 267 break; 268 case PMBUS_VIRT_READ_IOUT_MAX: 269 ret = mp2975_read_word_helper(client, page, phase, 270 MP2975_MFR_READ_IOUT_PK, 271 GENMASK(12, 0)); 272 if (ret < 0) 273 return ret; 274 275 ret = DIV_ROUND_CLOSEST(ret, 4); 276 break; 277 case PMBUS_READ_IOUT: 278 ret = mp2975_read_phases(client, data, page, phase); 279 if (ret < 0) 280 return ret; 281 282 break; 283 case PMBUS_UT_WARN_LIMIT: 284 case PMBUS_UT_FAULT_LIMIT: 285 case PMBUS_VIN_UV_WARN_LIMIT: 286 case PMBUS_VIN_UV_FAULT_LIMIT: 287 case PMBUS_VOUT_UV_WARN_LIMIT: 288 case PMBUS_VOUT_OV_WARN_LIMIT: 289 case PMBUS_VIN_OV_WARN_LIMIT: 290 case PMBUS_IIN_OC_FAULT_LIMIT: 291 case PMBUS_IOUT_OC_LV_FAULT_LIMIT: 292 case PMBUS_IIN_OC_WARN_LIMIT: 293 case PMBUS_IOUT_OC_WARN_LIMIT: 294 case PMBUS_IOUT_OC_FAULT_LIMIT: 295 case PMBUS_IOUT_UC_FAULT_LIMIT: 296 case PMBUS_POUT_OP_FAULT_LIMIT: 297 case PMBUS_POUT_OP_WARN_LIMIT: 298 case PMBUS_PIN_OP_WARN_LIMIT: 299 return -ENXIO; 300 default: 301 return -ENODATA; 302 } 303 304 return ret; 305 } 306 307 static int mp2975_identify_multiphase_rail2(struct i2c_client *client) 308 { 309 int ret; 310 311 /* 312 * Identify multiphase for rail 2 - could be from 0 to 4. 313 * In case phase number is zero – only page zero is supported 314 */ 315 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 316 if (ret < 0) 317 return ret; 318 319 /* Identify multiphase for rail 2 - could be from 0 to 4. */ 320 ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R2); 321 if (ret < 0) 322 return ret; 323 324 ret &= GENMASK(2, 0); 325 return (ret >= 4) ? 4 : ret; 326 } 327 328 static void mp2975_set_phase_rail1(struct pmbus_driver_info *info) 329 { 330 int i; 331 332 for (i = 0 ; i < info->phases[0]; i++) 333 info->pfunc[i] = PMBUS_HAVE_IOUT; 334 } 335 336 static void 337 mp2975_set_phase_rail2(struct pmbus_driver_info *info, int num_phases) 338 { 339 int i; 340 341 /* Set phases for rail 2 from upper to lower. */ 342 for (i = 1; i <= num_phases; i++) 343 info->pfunc[MP2975_MAX_PHASE_RAIL1 - i] = PMBUS_HAVE_IOUT; 344 } 345 346 static int 347 mp2975_identify_multiphase(struct i2c_client *client, struct mp2975_data *data, 348 struct pmbus_driver_info *info) 349 { 350 int num_phases2, ret; 351 352 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 353 if (ret < 0) 354 return ret; 355 356 /* Identify multiphase for rail 1 - could be from 1 to 8. */ 357 ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R1); 358 if (ret <= 0) 359 return ret; 360 361 info->phases[0] = ret & GENMASK(3, 0); 362 363 /* 364 * The device provides a total of 8 PWM pins, and can be configured 365 * to different phase count applications for rail 1 and rail 2. 366 * Rail 1 can be set to 8 phases, while rail 2 can only be set to 4 367 * phases at most. When rail 1’s phase count is configured as 0, rail 368 * 1 operates with 1-phase DCM. When rail 2 phase count is configured 369 * as 0, rail 2 is disabled. 370 */ 371 if (info->phases[0] > MP2975_MAX_PHASE_RAIL1) 372 return -EINVAL; 373 374 mp2975_set_phase_rail1(info); 375 num_phases2 = min(MP2975_MAX_PHASE_RAIL1 - info->phases[0], 376 MP2975_MAX_PHASE_RAIL2); 377 if (info->phases[1] && info->phases[1] <= num_phases2) 378 mp2975_set_phase_rail2(info, num_phases2); 379 380 return 0; 381 } 382 383 static int 384 mp2975_identify_vid(struct i2c_client *client, struct mp2975_data *data, 385 struct pmbus_driver_info *info, u32 reg, int page, 386 u32 imvp_bit, u32 vr_bit) 387 { 388 int ret; 389 390 /* Identify VID mode and step selection. */ 391 ret = i2c_smbus_read_word_data(client, reg); 392 if (ret < 0) 393 return ret; 394 395 if (ret & imvp_bit) { 396 info->vrm_version[page] = imvp9; 397 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; 398 } else if (ret & vr_bit) { 399 info->vrm_version[page] = vr12; 400 data->vid_step[page] = MP2975_PROT_DEV_OV_ON; 401 } else { 402 info->vrm_version[page] = vr13; 403 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; 404 } 405 406 return 0; 407 } 408 409 static int 410 mp2975_identify_rails_vid(struct i2c_client *client, struct mp2975_data *data, 411 struct pmbus_driver_info *info) 412 { 413 int ret; 414 415 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 416 if (ret < 0) 417 return ret; 418 419 /* Identify VID mode for rail 1. */ 420 ret = mp2975_identify_vid(client, data, info, 421 MP2975_MFR_VR_MULTI_CONFIG_R1, 0, 422 MP2975_IMVP9_EN_R1, MP2975_VID_STEP_SEL_R1); 423 if (ret < 0) 424 return ret; 425 426 /* Identify VID mode for rail 2, if connected. */ 427 if (info->phases[1]) 428 ret = mp2975_identify_vid(client, data, info, 429 MP2975_MFR_VR_MULTI_CONFIG_R2, 1, 430 MP2975_IMVP9_EN_R2, 431 MP2975_VID_STEP_SEL_R2); 432 return ret; 433 } 434 435 static int 436 mp2975_current_sense_gain_get(struct i2c_client *client, 437 struct mp2975_data *data) 438 { 439 int i, ret; 440 441 /* 442 * Obtain DrMOS current sense gain of power stage from the register 443 * MP2975_MFR_VR_CONFIG1, bits 13-12. The value is selected as below: 444 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. Other 445 * values are invalid. 446 */ 447 for (i = 0 ; i < data->info.pages; i++) { 448 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); 449 if (ret < 0) 450 return ret; 451 ret = i2c_smbus_read_word_data(client, 452 MP2975_MFR_VR_CONFIG1); 453 if (ret < 0) 454 return ret; 455 456 switch ((ret & MP2975_DRMOS_KCS) >> 12) { 457 case 0: 458 data->curr_sense_gain[i] = 50; 459 break; 460 case 1: 461 data->curr_sense_gain[i] = 85; 462 break; 463 case 2: 464 data->curr_sense_gain[i] = 97; 465 break; 466 default: 467 data->curr_sense_gain[i] = 100; 468 break; 469 } 470 } 471 472 return 0; 473 } 474 475 static int 476 mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data, 477 struct pmbus_driver_info *info) 478 { 479 int ret; 480 481 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 3); 482 if (ret < 0) 483 return ret; 484 485 /* Get voltage reference value for rail 1. */ 486 ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R1); 487 if (ret < 0) 488 return ret; 489 490 data->vref[0] = ret * data->vid_step[0]; 491 492 /* Get voltage reference value for rail 2, if connected. */ 493 if (data->info.pages == MP2975_PAGE_NUM) { 494 ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R2); 495 if (ret < 0) 496 return ret; 497 498 data->vref[1] = ret * data->vid_step[1]; 499 } 500 return 0; 501 } 502 503 static int 504 mp2975_vref_offset_get(struct i2c_client *client, struct mp2975_data *data, 505 int page) 506 { 507 int ret; 508 509 ret = i2c_smbus_read_word_data(client, MP2975_MFR_OVP_TH_SET); 510 if (ret < 0) 511 return ret; 512 513 switch ((ret & GENMASK(5, 3)) >> 3) { 514 case 1: 515 data->vref_off[page] = 140; 516 break; 517 case 2: 518 data->vref_off[page] = 220; 519 break; 520 case 4: 521 data->vref_off[page] = 400; 522 break; 523 default: 524 return -EINVAL; 525 } 526 return 0; 527 } 528 529 static int 530 mp2975_vout_max_get(struct i2c_client *client, struct mp2975_data *data, 531 struct pmbus_driver_info *info, int page) 532 { 533 int ret; 534 535 /* Get maximum reference voltage of VID-DAC in VID format. */ 536 ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_MAX); 537 if (ret < 0) 538 return ret; 539 540 data->vout_max[page] = mp2975_vid2direct(info->vrm_version[page], ret & 541 GENMASK(8, 0)); 542 return 0; 543 } 544 545 static int 546 mp2975_set_vout_format(struct i2c_client *client, 547 struct mp2975_data *data, int page) 548 { 549 int ret; 550 551 ret = i2c_smbus_read_word_data(client, MP2975_MFR_DC_LOOP_CTRL); 552 if (ret < 0) 553 return ret; 554 /* Enable DIRECT VOUT format 1mV/LSB */ 555 if (ret & MP2975_VOUT_FORMAT) { 556 ret &= ~MP2975_VOUT_FORMAT; 557 ret = i2c_smbus_write_word_data(client, MP2975_MFR_DC_LOOP_CTRL, ret); 558 } 559 return ret; 560 } 561 562 static int 563 mp2975_vout_ov_scale_get(struct i2c_client *client, struct mp2975_data *data, 564 struct pmbus_driver_info *info) 565 { 566 int thres_dev, sense_ampl, ret; 567 568 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); 569 if (ret < 0) 570 return ret; 571 572 /* 573 * Get divider for over- and under-voltage protection thresholds 574 * configuration from the Advanced Options of Auto Phase Shedding and 575 * decay register. 576 */ 577 ret = i2c_smbus_read_word_data(client, MP2975_MFR_APS_DECAY_ADV); 578 if (ret < 0) 579 return ret; 580 thres_dev = ret & MP2975_PRT_THRES_DIV_OV_EN ? MP2975_PROT_DEV_OV_ON : 581 MP2975_PROT_DEV_OV_OFF; 582 583 /* Select the gain of remote sense amplifier. */ 584 ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_SCALE_LOOP); 585 if (ret < 0) 586 return ret; 587 sense_ampl = ret & MP2975_SENSE_AMPL ? MP2975_SENSE_AMPL_HALF : 588 MP2975_SENSE_AMPL_UNIT; 589 590 data->vout_scale = sense_ampl * thres_dev; 591 592 return 0; 593 } 594 595 static int 596 mp2975_vout_per_rail_config_get(struct i2c_client *client, 597 struct mp2975_data *data, 598 struct pmbus_driver_info *info) 599 { 600 int i, ret; 601 602 for (i = 0; i < data->info.pages; i++) { 603 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); 604 if (ret < 0) 605 return ret; 606 607 /* Obtain voltage reference offsets. */ 608 ret = mp2975_vref_offset_get(client, data, i); 609 if (ret < 0) 610 return ret; 611 612 /* Obtain maximum voltage values. */ 613 ret = mp2975_vout_max_get(client, data, info, i); 614 if (ret < 0) 615 return ret; 616 617 /* Set VOUT format for READ_VOUT command : direct. */ 618 ret = mp2975_set_vout_format(client, data, i); 619 if (ret < 0) 620 return ret; 621 622 /* 623 * Set over-voltage fixed value. Thresholds are provided as 624 * fixed value, and tracking value. The minimum of them are 625 * exposed as over-voltage critical threshold. 626 */ 627 data->vout_ov_fixed[i] = data->vref[i] + 628 DIV_ROUND_CLOSEST(data->vref_off[i] * 629 data->vout_scale, 630 10); 631 } 632 633 return 0; 634 } 635 636 static struct pmbus_driver_info mp2975_info = { 637 .pages = 1, 638 .format[PSC_VOLTAGE_IN] = linear, 639 .format[PSC_VOLTAGE_OUT] = direct, 640 .format[PSC_TEMPERATURE] = direct, 641 .format[PSC_CURRENT_IN] = linear, 642 .format[PSC_CURRENT_OUT] = direct, 643 .format[PSC_POWER] = direct, 644 .m[PSC_TEMPERATURE] = 1, 645 .m[PSC_VOLTAGE_OUT] = 1, 646 .R[PSC_VOLTAGE_OUT] = 3, 647 .m[PSC_CURRENT_OUT] = 1, 648 .m[PSC_POWER] = 1, 649 .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 650 PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 651 PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | 652 PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | PMBUS_PHASE_VIRTUAL, 653 .read_word_data = mp2975_read_word_data, 654 }; 655 656 static int mp2975_probe(struct i2c_client *client) 657 { 658 struct pmbus_driver_info *info; 659 struct mp2975_data *data; 660 int ret; 661 662 data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data), 663 GFP_KERNEL); 664 if (!data) 665 return -ENOMEM; 666 667 if (client->dev.of_node) 668 data->chip_id = (enum chips)(unsigned long)of_device_get_match_data(&client->dev); 669 else 670 data->chip_id = i2c_match_id(mp2975_id, client)->driver_data; 671 672 memcpy(&data->info, &mp2975_info, sizeof(*info)); 673 info = &data->info; 674 675 /* Identify multiphase configuration for rail 2. */ 676 ret = mp2975_identify_multiphase_rail2(client); 677 if (ret < 0) 678 return ret; 679 680 if (ret) { 681 /* Two rails are connected. */ 682 data->info.pages = MP2975_PAGE_NUM; 683 data->info.phases[1] = ret; 684 data->info.func[1] = MP2975_RAIL2_FUNC; 685 } 686 687 /* Identify multiphase configuration. */ 688 ret = mp2975_identify_multiphase(client, data, info); 689 if (ret) 690 return ret; 691 692 /* Identify VID setting per rail. */ 693 ret = mp2975_identify_rails_vid(client, data, info); 694 if (ret < 0) 695 return ret; 696 697 /* Obtain current sense gain of power stage. */ 698 ret = mp2975_current_sense_gain_get(client, data); 699 if (ret) 700 return ret; 701 702 /* Obtain voltage reference values. */ 703 ret = mp2975_vref_get(client, data, info); 704 if (ret) 705 return ret; 706 707 /* Obtain vout over-voltage scales. */ 708 ret = mp2975_vout_ov_scale_get(client, data, info); 709 if (ret < 0) 710 return ret; 711 712 /* Obtain offsets, maximum and format for vout. */ 713 ret = mp2975_vout_per_rail_config_get(client, data, info); 714 if (ret) 715 return ret; 716 717 return pmbus_do_probe(client, info); 718 } 719 720 static const struct of_device_id __maybe_unused mp2975_of_match[] = { 721 {.compatible = "mps,mp2975", .data = (void *)mp2975}, 722 {} 723 }; 724 MODULE_DEVICE_TABLE(of, mp2975_of_match); 725 726 static struct i2c_driver mp2975_driver = { 727 .driver = { 728 .name = "mp2975", 729 .of_match_table = of_match_ptr(mp2975_of_match), 730 }, 731 .probe = mp2975_probe, 732 .id_table = mp2975_id, 733 }; 734 735 module_i2c_driver(mp2975_driver); 736 737 MODULE_AUTHOR("Vadim Pasternak <vadimp@nvidia.com>"); 738 MODULE_DESCRIPTION("PMBus driver for MPS MP2975 device"); 739 MODULE_LICENSE("GPL"); 740 MODULE_IMPORT_NS(PMBUS); 741