12c6fcbb2SVadim Pasternak // SPDX-License-Identifier: GPL-2.0-or-later 22c6fcbb2SVadim Pasternak /* 32c6fcbb2SVadim Pasternak * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers 42c6fcbb2SVadim Pasternak * 52c6fcbb2SVadim Pasternak * Copyright (C) 2020 Nvidia Technologies Ltd. 62c6fcbb2SVadim Pasternak */ 72c6fcbb2SVadim Pasternak 82c6fcbb2SVadim Pasternak #include <linux/err.h> 92c6fcbb2SVadim Pasternak #include <linux/i2c.h> 102c6fcbb2SVadim Pasternak #include <linux/init.h> 112c6fcbb2SVadim Pasternak #include <linux/kernel.h> 122c6fcbb2SVadim Pasternak #include <linux/module.h> 131f6f34d0SPatrick Rudolph #include <linux/of_device.h> 142c6fcbb2SVadim Pasternak #include "pmbus.h" 152c6fcbb2SVadim Pasternak 162c6fcbb2SVadim Pasternak /* Vendor specific registers. */ 172c6fcbb2SVadim Pasternak #define MP2975_MFR_APS_HYS_R2 0x0d 182c6fcbb2SVadim Pasternak #define MP2975_MFR_SLOPE_TRIM3 0x1d 192c6fcbb2SVadim Pasternak #define MP2975_MFR_VR_MULTI_CONFIG_R1 0x0d 202c6fcbb2SVadim Pasternak #define MP2975_MFR_VR_MULTI_CONFIG_R2 0x1d 212c6fcbb2SVadim Pasternak #define MP2975_MFR_APS_DECAY_ADV 0x56 222c6fcbb2SVadim Pasternak #define MP2975_MFR_DC_LOOP_CTRL 0x59 232c6fcbb2SVadim Pasternak #define MP2975_MFR_OCP_UCP_PHASE_SET 0x65 242c6fcbb2SVadim Pasternak #define MP2975_MFR_VR_CONFIG1 0x68 252c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS1_2 0x82 262c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS3_4 0x83 272c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS5_6 0x84 282c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS7_8 0x85 292c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS9_10 0x86 302c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_CS11_12 0x87 312c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_IOUT_PK 0x90 322c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_POUT_PK 0x91 332c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_VREF_R1 0xa1 342c6fcbb2SVadim Pasternak #define MP2975_MFR_READ_VREF_R2 0xa3 352c6fcbb2SVadim Pasternak #define MP2975_MFR_OVP_TH_SET 0xe5 362c6fcbb2SVadim Pasternak #define MP2975_MFR_UVP_SET 0xe6 372c6fcbb2SVadim Pasternak 382c6fcbb2SVadim Pasternak #define MP2975_VOUT_FORMAT BIT(15) 392c6fcbb2SVadim Pasternak #define MP2975_VID_STEP_SEL_R1 BIT(4) 402c6fcbb2SVadim Pasternak #define MP2975_IMVP9_EN_R1 BIT(13) 412c6fcbb2SVadim Pasternak #define MP2975_VID_STEP_SEL_R2 BIT(3) 422c6fcbb2SVadim Pasternak #define MP2975_IMVP9_EN_R2 BIT(12) 432c6fcbb2SVadim Pasternak #define MP2975_PRT_THRES_DIV_OV_EN BIT(14) 442c6fcbb2SVadim Pasternak #define MP2975_DRMOS_KCS GENMASK(13, 12) 452c6fcbb2SVadim Pasternak #define MP2975_PROT_DEV_OV_OFF 10 462c6fcbb2SVadim Pasternak #define MP2975_PROT_DEV_OV_ON 5 472c6fcbb2SVadim Pasternak #define MP2975_SENSE_AMPL BIT(11) 482c6fcbb2SVadim Pasternak #define MP2975_SENSE_AMPL_UNIT 1 492c6fcbb2SVadim Pasternak #define MP2975_SENSE_AMPL_HALF 2 502c6fcbb2SVadim Pasternak #define MP2975_VIN_UV_LIMIT_UNIT 8 512c6fcbb2SVadim Pasternak 522c6fcbb2SVadim Pasternak #define MP2975_MAX_PHASE_RAIL1 8 532c6fcbb2SVadim Pasternak #define MP2975_MAX_PHASE_RAIL2 4 542c6fcbb2SVadim Pasternak #define MP2975_PAGE_NUM 2 552c6fcbb2SVadim Pasternak 562c6fcbb2SVadim Pasternak #define MP2975_RAIL2_FUNC (PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | \ 572c6fcbb2SVadim Pasternak PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | \ 582292e2f6SVadim Pasternak PMBUS_HAVE_POUT | PMBUS_PHASE_VIRTUAL) 592c6fcbb2SVadim Pasternak 601f6f34d0SPatrick Rudolph enum chips { 611f6f34d0SPatrick Rudolph mp2975 621f6f34d0SPatrick Rudolph }; 631f6f34d0SPatrick Rudolph 642c6fcbb2SVadim Pasternak struct mp2975_data { 652c6fcbb2SVadim Pasternak struct pmbus_driver_info info; 661f6f34d0SPatrick Rudolph enum chips chip_id; 672c6fcbb2SVadim Pasternak int vout_scale; 682c6fcbb2SVadim Pasternak int vid_step[MP2975_PAGE_NUM]; 692c6fcbb2SVadim Pasternak int vref[MP2975_PAGE_NUM]; 702c6fcbb2SVadim Pasternak int vref_off[MP2975_PAGE_NUM]; 712c6fcbb2SVadim Pasternak int vout_max[MP2975_PAGE_NUM]; 722c6fcbb2SVadim Pasternak int vout_ov_fixed[MP2975_PAGE_NUM]; 732c6fcbb2SVadim Pasternak int curr_sense_gain[MP2975_PAGE_NUM]; 742c6fcbb2SVadim Pasternak }; 752c6fcbb2SVadim Pasternak 761f6f34d0SPatrick Rudolph static const struct i2c_device_id mp2975_id[] = { 771f6f34d0SPatrick Rudolph {"mp2975", mp2975}, 781f6f34d0SPatrick Rudolph {} 791f6f34d0SPatrick Rudolph }; 801f6f34d0SPatrick Rudolph 811f6f34d0SPatrick Rudolph MODULE_DEVICE_TABLE(i2c, mp2975_id); 821f6f34d0SPatrick Rudolph 832c6fcbb2SVadim Pasternak #define to_mp2975_data(x) container_of(x, struct mp2975_data, info) 842c6fcbb2SVadim Pasternak 852c6fcbb2SVadim Pasternak static int 862c6fcbb2SVadim Pasternak mp2975_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg, 872c6fcbb2SVadim Pasternak u16 mask) 882c6fcbb2SVadim Pasternak { 892c6fcbb2SVadim Pasternak int ret = pmbus_read_word_data(client, page, phase, reg); 902c6fcbb2SVadim Pasternak 912c6fcbb2SVadim Pasternak return (ret > 0) ? ret & mask : ret; 922c6fcbb2SVadim Pasternak } 932c6fcbb2SVadim Pasternak 942c6fcbb2SVadim Pasternak static int 952c6fcbb2SVadim Pasternak mp2975_vid2direct(int vrf, int val) 962c6fcbb2SVadim Pasternak { 972c6fcbb2SVadim Pasternak switch (vrf) { 982c6fcbb2SVadim Pasternak case vr12: 992c6fcbb2SVadim Pasternak if (val >= 0x01) 1002c6fcbb2SVadim Pasternak return 250 + (val - 1) * 5; 1012c6fcbb2SVadim Pasternak break; 1022c6fcbb2SVadim Pasternak case vr13: 1032c6fcbb2SVadim Pasternak if (val >= 0x01) 1042c6fcbb2SVadim Pasternak return 500 + (val - 1) * 10; 1052c6fcbb2SVadim Pasternak break; 1062c6fcbb2SVadim Pasternak case imvp9: 1072c6fcbb2SVadim Pasternak if (val >= 0x01) 1082c6fcbb2SVadim Pasternak return 200 + (val - 1) * 10; 1092c6fcbb2SVadim Pasternak break; 1102c6fcbb2SVadim Pasternak default: 1112c6fcbb2SVadim Pasternak return -EINVAL; 1122c6fcbb2SVadim Pasternak } 1132c6fcbb2SVadim Pasternak return 0; 1142c6fcbb2SVadim Pasternak } 1152c6fcbb2SVadim Pasternak 1162c6fcbb2SVadim Pasternak static int 1172c6fcbb2SVadim Pasternak mp2975_read_phase(struct i2c_client *client, struct mp2975_data *data, 1182c6fcbb2SVadim Pasternak int page, int phase, u8 reg) 1192c6fcbb2SVadim Pasternak { 1202c6fcbb2SVadim Pasternak int ph_curr, ret; 1212c6fcbb2SVadim Pasternak 1222c6fcbb2SVadim Pasternak ret = pmbus_read_word_data(client, page, phase, reg); 1232c6fcbb2SVadim Pasternak if (ret < 0) 1242c6fcbb2SVadim Pasternak return ret; 1252c6fcbb2SVadim Pasternak 1262c6fcbb2SVadim Pasternak if (!((phase + 1) % MP2975_PAGE_NUM)) 1272c6fcbb2SVadim Pasternak ret >>= 8; 1282c6fcbb2SVadim Pasternak ret &= 0xff; 1292c6fcbb2SVadim Pasternak 1302c6fcbb2SVadim Pasternak /* 1312c6fcbb2SVadim Pasternak * Output value is calculated as: (READ_CSx / 80 – 1.23) / (Kcs * Rcs) 1322c6fcbb2SVadim Pasternak * where: 1332c6fcbb2SVadim Pasternak * - Kcs is the DrMOS current sense gain of power stage, which is 1342c6fcbb2SVadim Pasternak * obtained from the register MP2975_MFR_VR_CONFIG1, bits 13-12 with 1352c6fcbb2SVadim Pasternak * the following selection of DrMOS (data->curr_sense_gain[page]): 1362c6fcbb2SVadim Pasternak * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. 1372c6fcbb2SVadim Pasternak * - Rcs is the internal phase current sense resistor which is constant 1382c6fcbb2SVadim Pasternak * value 1kΩ. 1392c6fcbb2SVadim Pasternak */ 1402c6fcbb2SVadim Pasternak ph_curr = ret * 100 - 9800; 1412c6fcbb2SVadim Pasternak 1422c6fcbb2SVadim Pasternak /* 1432c6fcbb2SVadim Pasternak * Current phase sensing, providing by the device is not accurate 1442c6fcbb2SVadim Pasternak * for the light load. This because sampling of current occurrence of 1452c6fcbb2SVadim Pasternak * bit weight has a big deviation for light load. For handling such 1462c6fcbb2SVadim Pasternak * case phase current is represented as the maximum between the value 1472c6fcbb2SVadim Pasternak * calculated above and total rail current divided by number phases. 1482c6fcbb2SVadim Pasternak */ 1492c6fcbb2SVadim Pasternak ret = pmbus_read_word_data(client, page, phase, PMBUS_READ_IOUT); 1502c6fcbb2SVadim Pasternak if (ret < 0) 1512c6fcbb2SVadim Pasternak return ret; 1522c6fcbb2SVadim Pasternak 1532c6fcbb2SVadim Pasternak return max_t(int, DIV_ROUND_CLOSEST(ret, data->info.phases[page]), 1542c6fcbb2SVadim Pasternak DIV_ROUND_CLOSEST(ph_curr, data->curr_sense_gain[page])); 1552c6fcbb2SVadim Pasternak } 1562c6fcbb2SVadim Pasternak 1572c6fcbb2SVadim Pasternak static int 1582c6fcbb2SVadim Pasternak mp2975_read_phases(struct i2c_client *client, struct mp2975_data *data, 1592c6fcbb2SVadim Pasternak int page, int phase) 1602c6fcbb2SVadim Pasternak { 1612c6fcbb2SVadim Pasternak int ret; 1622c6fcbb2SVadim Pasternak 1632c6fcbb2SVadim Pasternak if (page) { 1642c6fcbb2SVadim Pasternak switch (phase) { 1652c6fcbb2SVadim Pasternak case 0 ... 1: 1662c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1672c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS7_8); 1682c6fcbb2SVadim Pasternak break; 1692c6fcbb2SVadim Pasternak case 2 ... 3: 1702c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1712c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS9_10); 1722c6fcbb2SVadim Pasternak break; 1732c6fcbb2SVadim Pasternak case 4 ... 5: 1742c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1752c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS11_12); 1762c6fcbb2SVadim Pasternak break; 1772c6fcbb2SVadim Pasternak default: 1782c6fcbb2SVadim Pasternak return -ENODATA; 1792c6fcbb2SVadim Pasternak } 1802c6fcbb2SVadim Pasternak } else { 1812c6fcbb2SVadim Pasternak switch (phase) { 1822c6fcbb2SVadim Pasternak case 0 ... 1: 1832c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1842c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS1_2); 1852c6fcbb2SVadim Pasternak break; 1862c6fcbb2SVadim Pasternak case 2 ... 3: 1872c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1882c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS3_4); 1892c6fcbb2SVadim Pasternak break; 1902c6fcbb2SVadim Pasternak case 4 ... 5: 1912c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1922c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS5_6); 1932c6fcbb2SVadim Pasternak break; 1942c6fcbb2SVadim Pasternak case 6 ... 7: 1952c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 1962c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS7_8); 1972c6fcbb2SVadim Pasternak break; 1982c6fcbb2SVadim Pasternak case 8 ... 9: 1992c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 2002c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS9_10); 2012c6fcbb2SVadim Pasternak break; 2022c6fcbb2SVadim Pasternak case 10 ... 11: 2032c6fcbb2SVadim Pasternak ret = mp2975_read_phase(client, data, page, phase, 2042c6fcbb2SVadim Pasternak MP2975_MFR_READ_CS11_12); 2052c6fcbb2SVadim Pasternak break; 2062c6fcbb2SVadim Pasternak default: 2072c6fcbb2SVadim Pasternak return -ENODATA; 2082c6fcbb2SVadim Pasternak } 2092c6fcbb2SVadim Pasternak } 2102c6fcbb2SVadim Pasternak return ret; 2112c6fcbb2SVadim Pasternak } 2122c6fcbb2SVadim Pasternak 2132c6fcbb2SVadim Pasternak static int mp2975_read_word_data(struct i2c_client *client, int page, 2142c6fcbb2SVadim Pasternak int phase, int reg) 2152c6fcbb2SVadim Pasternak { 2162c6fcbb2SVadim Pasternak const struct pmbus_driver_info *info = pmbus_get_driver_info(client); 2172c6fcbb2SVadim Pasternak struct mp2975_data *data = to_mp2975_data(info); 2182c6fcbb2SVadim Pasternak int ret; 2192c6fcbb2SVadim Pasternak 2202c6fcbb2SVadim Pasternak switch (reg) { 2212c6fcbb2SVadim Pasternak case PMBUS_OT_FAULT_LIMIT: 2222c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, reg, 2232c6fcbb2SVadim Pasternak GENMASK(7, 0)); 2242c6fcbb2SVadim Pasternak break; 2252c6fcbb2SVadim Pasternak case PMBUS_VIN_OV_FAULT_LIMIT: 2262c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, reg, 2272c6fcbb2SVadim Pasternak GENMASK(7, 0)); 2282c6fcbb2SVadim Pasternak if (ret < 0) 2292c6fcbb2SVadim Pasternak return ret; 2302c6fcbb2SVadim Pasternak 2312c6fcbb2SVadim Pasternak ret = DIV_ROUND_CLOSEST(ret, MP2975_VIN_UV_LIMIT_UNIT); 2322c6fcbb2SVadim Pasternak break; 2332c6fcbb2SVadim Pasternak case PMBUS_VOUT_OV_FAULT_LIMIT: 2342c6fcbb2SVadim Pasternak /* 2352c6fcbb2SVadim Pasternak * Register provides two values for over-voltage protection 2362c6fcbb2SVadim Pasternak * threshold for fixed (ovp2) and tracking (ovp1) modes. The 2372c6fcbb2SVadim Pasternak * minimum of these two values is provided as over-voltage 2382c6fcbb2SVadim Pasternak * fault alarm. 2392c6fcbb2SVadim Pasternak */ 2402c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, 2412c6fcbb2SVadim Pasternak MP2975_MFR_OVP_TH_SET, 2422c6fcbb2SVadim Pasternak GENMASK(2, 0)); 2432c6fcbb2SVadim Pasternak if (ret < 0) 2442c6fcbb2SVadim Pasternak return ret; 2452c6fcbb2SVadim Pasternak 2462c6fcbb2SVadim Pasternak ret = min_t(int, data->vout_max[page] + 50 * (ret + 1), 2472c6fcbb2SVadim Pasternak data->vout_ov_fixed[page]); 2482c6fcbb2SVadim Pasternak break; 2492c6fcbb2SVadim Pasternak case PMBUS_VOUT_UV_FAULT_LIMIT: 2502c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, 2512c6fcbb2SVadim Pasternak MP2975_MFR_UVP_SET, 2522c6fcbb2SVadim Pasternak GENMASK(2, 0)); 2532c6fcbb2SVadim Pasternak if (ret < 0) 2542c6fcbb2SVadim Pasternak return ret; 2552c6fcbb2SVadim Pasternak 2562c6fcbb2SVadim Pasternak ret = DIV_ROUND_CLOSEST(data->vref[page] * 10 - 50 * 2572c6fcbb2SVadim Pasternak (ret + 1) * data->vout_scale, 10); 2582c6fcbb2SVadim Pasternak break; 2592c6fcbb2SVadim Pasternak case PMBUS_VIRT_READ_POUT_MAX: 2602c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, 2612c6fcbb2SVadim Pasternak MP2975_MFR_READ_POUT_PK, 2622c6fcbb2SVadim Pasternak GENMASK(12, 0)); 2632c6fcbb2SVadim Pasternak if (ret < 0) 2642c6fcbb2SVadim Pasternak return ret; 2652c6fcbb2SVadim Pasternak 2662c6fcbb2SVadim Pasternak ret = DIV_ROUND_CLOSEST(ret, 4); 2672c6fcbb2SVadim Pasternak break; 2682c6fcbb2SVadim Pasternak case PMBUS_VIRT_READ_IOUT_MAX: 2692c6fcbb2SVadim Pasternak ret = mp2975_read_word_helper(client, page, phase, 2702c6fcbb2SVadim Pasternak MP2975_MFR_READ_IOUT_PK, 2712c6fcbb2SVadim Pasternak GENMASK(12, 0)); 2722c6fcbb2SVadim Pasternak if (ret < 0) 2732c6fcbb2SVadim Pasternak return ret; 2742c6fcbb2SVadim Pasternak 2752c6fcbb2SVadim Pasternak ret = DIV_ROUND_CLOSEST(ret, 4); 2762c6fcbb2SVadim Pasternak break; 2772c6fcbb2SVadim Pasternak case PMBUS_READ_IOUT: 2782c6fcbb2SVadim Pasternak ret = mp2975_read_phases(client, data, page, phase); 2792c6fcbb2SVadim Pasternak if (ret < 0) 2802c6fcbb2SVadim Pasternak return ret; 2812c6fcbb2SVadim Pasternak 2822c6fcbb2SVadim Pasternak break; 2832c6fcbb2SVadim Pasternak case PMBUS_UT_WARN_LIMIT: 2842c6fcbb2SVadim Pasternak case PMBUS_UT_FAULT_LIMIT: 2852c6fcbb2SVadim Pasternak case PMBUS_VIN_UV_WARN_LIMIT: 2862c6fcbb2SVadim Pasternak case PMBUS_VIN_UV_FAULT_LIMIT: 2872c6fcbb2SVadim Pasternak case PMBUS_VOUT_UV_WARN_LIMIT: 2882c6fcbb2SVadim Pasternak case PMBUS_VOUT_OV_WARN_LIMIT: 2892c6fcbb2SVadim Pasternak case PMBUS_VIN_OV_WARN_LIMIT: 2902c6fcbb2SVadim Pasternak case PMBUS_IIN_OC_FAULT_LIMIT: 2912c6fcbb2SVadim Pasternak case PMBUS_IOUT_OC_LV_FAULT_LIMIT: 2922c6fcbb2SVadim Pasternak case PMBUS_IIN_OC_WARN_LIMIT: 2932c6fcbb2SVadim Pasternak case PMBUS_IOUT_OC_WARN_LIMIT: 2942c6fcbb2SVadim Pasternak case PMBUS_IOUT_OC_FAULT_LIMIT: 2952c6fcbb2SVadim Pasternak case PMBUS_IOUT_UC_FAULT_LIMIT: 2962c6fcbb2SVadim Pasternak case PMBUS_POUT_OP_FAULT_LIMIT: 2972c6fcbb2SVadim Pasternak case PMBUS_POUT_OP_WARN_LIMIT: 2982c6fcbb2SVadim Pasternak case PMBUS_PIN_OP_WARN_LIMIT: 2992c6fcbb2SVadim Pasternak return -ENXIO; 3002c6fcbb2SVadim Pasternak default: 3012c6fcbb2SVadim Pasternak return -ENODATA; 3022c6fcbb2SVadim Pasternak } 3032c6fcbb2SVadim Pasternak 3042c6fcbb2SVadim Pasternak return ret; 3052c6fcbb2SVadim Pasternak } 3062c6fcbb2SVadim Pasternak 3072c6fcbb2SVadim Pasternak static int mp2975_identify_multiphase_rail2(struct i2c_client *client) 3082c6fcbb2SVadim Pasternak { 3092c6fcbb2SVadim Pasternak int ret; 3102c6fcbb2SVadim Pasternak 3112c6fcbb2SVadim Pasternak /* 3122c6fcbb2SVadim Pasternak * Identify multiphase for rail 2 - could be from 0 to 4. 3132c6fcbb2SVadim Pasternak * In case phase number is zero – only page zero is supported 3142c6fcbb2SVadim Pasternak */ 3152c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 3162c6fcbb2SVadim Pasternak if (ret < 0) 3172c6fcbb2SVadim Pasternak return ret; 3182c6fcbb2SVadim Pasternak 3192c6fcbb2SVadim Pasternak /* Identify multiphase for rail 2 - could be from 0 to 4. */ 3202c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R2); 3212c6fcbb2SVadim Pasternak if (ret < 0) 3222c6fcbb2SVadim Pasternak return ret; 3232c6fcbb2SVadim Pasternak 3242c6fcbb2SVadim Pasternak ret &= GENMASK(2, 0); 3252c6fcbb2SVadim Pasternak return (ret >= 4) ? 4 : ret; 3262c6fcbb2SVadim Pasternak } 3272c6fcbb2SVadim Pasternak 3282c6fcbb2SVadim Pasternak static void mp2975_set_phase_rail1(struct pmbus_driver_info *info) 3292c6fcbb2SVadim Pasternak { 3302c6fcbb2SVadim Pasternak int i; 3312c6fcbb2SVadim Pasternak 3322c6fcbb2SVadim Pasternak for (i = 0 ; i < info->phases[0]; i++) 3332c6fcbb2SVadim Pasternak info->pfunc[i] = PMBUS_HAVE_IOUT; 3342c6fcbb2SVadim Pasternak } 3352c6fcbb2SVadim Pasternak 3362c6fcbb2SVadim Pasternak static void 3372c6fcbb2SVadim Pasternak mp2975_set_phase_rail2(struct pmbus_driver_info *info, int num_phases) 3382c6fcbb2SVadim Pasternak { 3392c6fcbb2SVadim Pasternak int i; 3402c6fcbb2SVadim Pasternak 3412c6fcbb2SVadim Pasternak /* Set phases for rail 2 from upper to lower. */ 3422c6fcbb2SVadim Pasternak for (i = 1; i <= num_phases; i++) 3432c6fcbb2SVadim Pasternak info->pfunc[MP2975_MAX_PHASE_RAIL1 - i] = PMBUS_HAVE_IOUT; 3442c6fcbb2SVadim Pasternak } 3452c6fcbb2SVadim Pasternak 3462c6fcbb2SVadim Pasternak static int 3472c6fcbb2SVadim Pasternak mp2975_identify_multiphase(struct i2c_client *client, struct mp2975_data *data, 3482c6fcbb2SVadim Pasternak struct pmbus_driver_info *info) 3492c6fcbb2SVadim Pasternak { 3502c6fcbb2SVadim Pasternak int num_phases2, ret; 3512c6fcbb2SVadim Pasternak 3522c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 3532c6fcbb2SVadim Pasternak if (ret < 0) 3542c6fcbb2SVadim Pasternak return ret; 3552c6fcbb2SVadim Pasternak 3562c6fcbb2SVadim Pasternak /* Identify multiphase for rail 1 - could be from 1 to 8. */ 3572c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_VR_MULTI_CONFIG_R1); 3582c6fcbb2SVadim Pasternak if (ret <= 0) 3592c6fcbb2SVadim Pasternak return ret; 3602c6fcbb2SVadim Pasternak 3612c6fcbb2SVadim Pasternak info->phases[0] = ret & GENMASK(3, 0); 3622c6fcbb2SVadim Pasternak 3632c6fcbb2SVadim Pasternak /* 3642c6fcbb2SVadim Pasternak * The device provides a total of 8 PWM pins, and can be configured 3652c6fcbb2SVadim Pasternak * to different phase count applications for rail 1 and rail 2. 3662c6fcbb2SVadim Pasternak * Rail 1 can be set to 8 phases, while rail 2 can only be set to 4 3672c6fcbb2SVadim Pasternak * phases at most. When rail 1’s phase count is configured as 0, rail 3682c6fcbb2SVadim Pasternak * 1 operates with 1-phase DCM. When rail 2 phase count is configured 3692c6fcbb2SVadim Pasternak * as 0, rail 2 is disabled. 3702c6fcbb2SVadim Pasternak */ 3712c6fcbb2SVadim Pasternak if (info->phases[0] > MP2975_MAX_PHASE_RAIL1) 3722c6fcbb2SVadim Pasternak return -EINVAL; 3732c6fcbb2SVadim Pasternak 3742c6fcbb2SVadim Pasternak mp2975_set_phase_rail1(info); 3752c6fcbb2SVadim Pasternak num_phases2 = min(MP2975_MAX_PHASE_RAIL1 - info->phases[0], 3762c6fcbb2SVadim Pasternak MP2975_MAX_PHASE_RAIL2); 3772c6fcbb2SVadim Pasternak if (info->phases[1] && info->phases[1] <= num_phases2) 3782c6fcbb2SVadim Pasternak mp2975_set_phase_rail2(info, num_phases2); 3792c6fcbb2SVadim Pasternak 3802c6fcbb2SVadim Pasternak return 0; 3812c6fcbb2SVadim Pasternak } 3822c6fcbb2SVadim Pasternak 3832c6fcbb2SVadim Pasternak static int 3842c6fcbb2SVadim Pasternak mp2975_identify_vid(struct i2c_client *client, struct mp2975_data *data, 3852c6fcbb2SVadim Pasternak struct pmbus_driver_info *info, u32 reg, int page, 3862c6fcbb2SVadim Pasternak u32 imvp_bit, u32 vr_bit) 3872c6fcbb2SVadim Pasternak { 3882c6fcbb2SVadim Pasternak int ret; 3892c6fcbb2SVadim Pasternak 3902c6fcbb2SVadim Pasternak /* Identify VID mode and step selection. */ 3912c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, reg); 3922c6fcbb2SVadim Pasternak if (ret < 0) 3932c6fcbb2SVadim Pasternak return ret; 3942c6fcbb2SVadim Pasternak 3952c6fcbb2SVadim Pasternak if (ret & imvp_bit) { 3962c6fcbb2SVadim Pasternak info->vrm_version[page] = imvp9; 3972c6fcbb2SVadim Pasternak data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; 3982c6fcbb2SVadim Pasternak } else if (ret & vr_bit) { 3992c6fcbb2SVadim Pasternak info->vrm_version[page] = vr12; 4002c6fcbb2SVadim Pasternak data->vid_step[page] = MP2975_PROT_DEV_OV_ON; 4012c6fcbb2SVadim Pasternak } else { 4022c6fcbb2SVadim Pasternak info->vrm_version[page] = vr13; 4032c6fcbb2SVadim Pasternak data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; 4042c6fcbb2SVadim Pasternak } 4052c6fcbb2SVadim Pasternak 4062c6fcbb2SVadim Pasternak return 0; 4072c6fcbb2SVadim Pasternak } 4082c6fcbb2SVadim Pasternak 4092c6fcbb2SVadim Pasternak static int 4102c6fcbb2SVadim Pasternak mp2975_identify_rails_vid(struct i2c_client *client, struct mp2975_data *data, 4112c6fcbb2SVadim Pasternak struct pmbus_driver_info *info) 4122c6fcbb2SVadim Pasternak { 4132c6fcbb2SVadim Pasternak int ret; 4142c6fcbb2SVadim Pasternak 4152c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); 4162c6fcbb2SVadim Pasternak if (ret < 0) 4172c6fcbb2SVadim Pasternak return ret; 4182c6fcbb2SVadim Pasternak 4192c6fcbb2SVadim Pasternak /* Identify VID mode for rail 1. */ 4202c6fcbb2SVadim Pasternak ret = mp2975_identify_vid(client, data, info, 4212c6fcbb2SVadim Pasternak MP2975_MFR_VR_MULTI_CONFIG_R1, 0, 4222c6fcbb2SVadim Pasternak MP2975_IMVP9_EN_R1, MP2975_VID_STEP_SEL_R1); 4232c6fcbb2SVadim Pasternak if (ret < 0) 4242c6fcbb2SVadim Pasternak return ret; 4252c6fcbb2SVadim Pasternak 4262c6fcbb2SVadim Pasternak /* Identify VID mode for rail 2, if connected. */ 4272c6fcbb2SVadim Pasternak if (info->phases[1]) 4282c6fcbb2SVadim Pasternak ret = mp2975_identify_vid(client, data, info, 4292c6fcbb2SVadim Pasternak MP2975_MFR_VR_MULTI_CONFIG_R2, 1, 4302c6fcbb2SVadim Pasternak MP2975_IMVP9_EN_R2, 4312c6fcbb2SVadim Pasternak MP2975_VID_STEP_SEL_R2); 4322c6fcbb2SVadim Pasternak return ret; 4332c6fcbb2SVadim Pasternak } 4342c6fcbb2SVadim Pasternak 4352c6fcbb2SVadim Pasternak static int 4362c6fcbb2SVadim Pasternak mp2975_current_sense_gain_get(struct i2c_client *client, 4372c6fcbb2SVadim Pasternak struct mp2975_data *data) 4382c6fcbb2SVadim Pasternak { 4392c6fcbb2SVadim Pasternak int i, ret; 4402c6fcbb2SVadim Pasternak 4412c6fcbb2SVadim Pasternak /* 4422c6fcbb2SVadim Pasternak * Obtain DrMOS current sense gain of power stage from the register 4432c6fcbb2SVadim Pasternak * MP2975_MFR_VR_CONFIG1, bits 13-12. The value is selected as below: 4442c6fcbb2SVadim Pasternak * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. Other 4452c6fcbb2SVadim Pasternak * values are invalid. 4462c6fcbb2SVadim Pasternak */ 4472c6fcbb2SVadim Pasternak for (i = 0 ; i < data->info.pages; i++) { 4482c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); 4492c6fcbb2SVadim Pasternak if (ret < 0) 4502c6fcbb2SVadim Pasternak return ret; 4512c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, 4522c6fcbb2SVadim Pasternak MP2975_MFR_VR_CONFIG1); 4532c6fcbb2SVadim Pasternak if (ret < 0) 4542c6fcbb2SVadim Pasternak return ret; 4552c6fcbb2SVadim Pasternak 4562c6fcbb2SVadim Pasternak switch ((ret & MP2975_DRMOS_KCS) >> 12) { 4572c6fcbb2SVadim Pasternak case 0: 4582c6fcbb2SVadim Pasternak data->curr_sense_gain[i] = 50; 4592c6fcbb2SVadim Pasternak break; 4602c6fcbb2SVadim Pasternak case 1: 4612c6fcbb2SVadim Pasternak data->curr_sense_gain[i] = 85; 4622c6fcbb2SVadim Pasternak break; 4632c6fcbb2SVadim Pasternak case 2: 4642c6fcbb2SVadim Pasternak data->curr_sense_gain[i] = 97; 4652c6fcbb2SVadim Pasternak break; 4662c6fcbb2SVadim Pasternak default: 4672c6fcbb2SVadim Pasternak data->curr_sense_gain[i] = 100; 4682c6fcbb2SVadim Pasternak break; 4692c6fcbb2SVadim Pasternak } 4702c6fcbb2SVadim Pasternak } 4712c6fcbb2SVadim Pasternak 4722c6fcbb2SVadim Pasternak return 0; 4732c6fcbb2SVadim Pasternak } 4742c6fcbb2SVadim Pasternak 4752c6fcbb2SVadim Pasternak static int 4762c6fcbb2SVadim Pasternak mp2975_vref_get(struct i2c_client *client, struct mp2975_data *data, 4772c6fcbb2SVadim Pasternak struct pmbus_driver_info *info) 4782c6fcbb2SVadim Pasternak { 4792c6fcbb2SVadim Pasternak int ret; 4802c6fcbb2SVadim Pasternak 4812c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 3); 4822c6fcbb2SVadim Pasternak if (ret < 0) 4832c6fcbb2SVadim Pasternak return ret; 4842c6fcbb2SVadim Pasternak 4852c6fcbb2SVadim Pasternak /* Get voltage reference value for rail 1. */ 4862c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R1); 4872c6fcbb2SVadim Pasternak if (ret < 0) 4882c6fcbb2SVadim Pasternak return ret; 4892c6fcbb2SVadim Pasternak 4902c6fcbb2SVadim Pasternak data->vref[0] = ret * data->vid_step[0]; 4912c6fcbb2SVadim Pasternak 4922c6fcbb2SVadim Pasternak /* Get voltage reference value for rail 2, if connected. */ 4932c6fcbb2SVadim Pasternak if (data->info.pages == MP2975_PAGE_NUM) { 4942c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_READ_VREF_R2); 4952c6fcbb2SVadim Pasternak if (ret < 0) 4962c6fcbb2SVadim Pasternak return ret; 4972c6fcbb2SVadim Pasternak 4982c6fcbb2SVadim Pasternak data->vref[1] = ret * data->vid_step[1]; 4992c6fcbb2SVadim Pasternak } 5002c6fcbb2SVadim Pasternak return 0; 5012c6fcbb2SVadim Pasternak } 5022c6fcbb2SVadim Pasternak 5032c6fcbb2SVadim Pasternak static int 5042c6fcbb2SVadim Pasternak mp2975_vref_offset_get(struct i2c_client *client, struct mp2975_data *data, 5052c6fcbb2SVadim Pasternak int page) 5062c6fcbb2SVadim Pasternak { 5072c6fcbb2SVadim Pasternak int ret; 5082c6fcbb2SVadim Pasternak 5092c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_OVP_TH_SET); 5102c6fcbb2SVadim Pasternak if (ret < 0) 5112c6fcbb2SVadim Pasternak return ret; 5122c6fcbb2SVadim Pasternak 5132c6fcbb2SVadim Pasternak switch ((ret & GENMASK(5, 3)) >> 3) { 5142c6fcbb2SVadim Pasternak case 1: 5152c6fcbb2SVadim Pasternak data->vref_off[page] = 140; 5162c6fcbb2SVadim Pasternak break; 5172c6fcbb2SVadim Pasternak case 2: 5182c6fcbb2SVadim Pasternak data->vref_off[page] = 220; 5192c6fcbb2SVadim Pasternak break; 5202c6fcbb2SVadim Pasternak case 4: 5212c6fcbb2SVadim Pasternak data->vref_off[page] = 400; 5222c6fcbb2SVadim Pasternak break; 5232c6fcbb2SVadim Pasternak default: 5242c6fcbb2SVadim Pasternak return -EINVAL; 5252c6fcbb2SVadim Pasternak } 5262c6fcbb2SVadim Pasternak return 0; 5272c6fcbb2SVadim Pasternak } 5282c6fcbb2SVadim Pasternak 5292c6fcbb2SVadim Pasternak static int 5302c6fcbb2SVadim Pasternak mp2975_vout_max_get(struct i2c_client *client, struct mp2975_data *data, 5312c6fcbb2SVadim Pasternak struct pmbus_driver_info *info, int page) 5322c6fcbb2SVadim Pasternak { 5332c6fcbb2SVadim Pasternak int ret; 5342c6fcbb2SVadim Pasternak 5352c6fcbb2SVadim Pasternak /* Get maximum reference voltage of VID-DAC in VID format. */ 5362c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_MAX); 5372c6fcbb2SVadim Pasternak if (ret < 0) 5382c6fcbb2SVadim Pasternak return ret; 5392c6fcbb2SVadim Pasternak 5402c6fcbb2SVadim Pasternak data->vout_max[page] = mp2975_vid2direct(info->vrm_version[page], ret & 5412c6fcbb2SVadim Pasternak GENMASK(8, 0)); 5422c6fcbb2SVadim Pasternak return 0; 5432c6fcbb2SVadim Pasternak } 5442c6fcbb2SVadim Pasternak 5452c6fcbb2SVadim Pasternak static int 546*1feb31e8SPatrick Rudolph mp2975_set_vout_format(struct i2c_client *client, 5472c6fcbb2SVadim Pasternak struct mp2975_data *data, int page) 5482c6fcbb2SVadim Pasternak { 5492c6fcbb2SVadim Pasternak int ret; 5502c6fcbb2SVadim Pasternak 5512c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_DC_LOOP_CTRL); 5522c6fcbb2SVadim Pasternak if (ret < 0) 5532c6fcbb2SVadim Pasternak return ret; 554*1feb31e8SPatrick Rudolph /* Enable DIRECT VOUT format 1mV/LSB */ 555*1feb31e8SPatrick Rudolph if (ret & MP2975_VOUT_FORMAT) { 556*1feb31e8SPatrick Rudolph ret &= ~MP2975_VOUT_FORMAT; 557*1feb31e8SPatrick Rudolph ret = i2c_smbus_write_word_data(client, MP2975_MFR_DC_LOOP_CTRL, ret); 558*1feb31e8SPatrick Rudolph } 559*1feb31e8SPatrick Rudolph return ret; 5602c6fcbb2SVadim Pasternak } 5612c6fcbb2SVadim Pasternak 5622c6fcbb2SVadim Pasternak static int 5632c6fcbb2SVadim Pasternak mp2975_vout_ov_scale_get(struct i2c_client *client, struct mp2975_data *data, 5642c6fcbb2SVadim Pasternak struct pmbus_driver_info *info) 5652c6fcbb2SVadim Pasternak { 5662c6fcbb2SVadim Pasternak int thres_dev, sense_ampl, ret; 5672c6fcbb2SVadim Pasternak 5682c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); 5692c6fcbb2SVadim Pasternak if (ret < 0) 5702c6fcbb2SVadim Pasternak return ret; 5712c6fcbb2SVadim Pasternak 5722c6fcbb2SVadim Pasternak /* 5732c6fcbb2SVadim Pasternak * Get divider for over- and under-voltage protection thresholds 5742c6fcbb2SVadim Pasternak * configuration from the Advanced Options of Auto Phase Shedding and 5752c6fcbb2SVadim Pasternak * decay register. 5762c6fcbb2SVadim Pasternak */ 5772c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, MP2975_MFR_APS_DECAY_ADV); 5782c6fcbb2SVadim Pasternak if (ret < 0) 5792c6fcbb2SVadim Pasternak return ret; 5802c6fcbb2SVadim Pasternak thres_dev = ret & MP2975_PRT_THRES_DIV_OV_EN ? MP2975_PROT_DEV_OV_ON : 5812c6fcbb2SVadim Pasternak MP2975_PROT_DEV_OV_OFF; 5822c6fcbb2SVadim Pasternak 5832c6fcbb2SVadim Pasternak /* Select the gain of remote sense amplifier. */ 5842c6fcbb2SVadim Pasternak ret = i2c_smbus_read_word_data(client, PMBUS_VOUT_SCALE_LOOP); 5852c6fcbb2SVadim Pasternak if (ret < 0) 5862c6fcbb2SVadim Pasternak return ret; 5872c6fcbb2SVadim Pasternak sense_ampl = ret & MP2975_SENSE_AMPL ? MP2975_SENSE_AMPL_HALF : 5882c6fcbb2SVadim Pasternak MP2975_SENSE_AMPL_UNIT; 5892c6fcbb2SVadim Pasternak 5902c6fcbb2SVadim Pasternak data->vout_scale = sense_ampl * thres_dev; 5912c6fcbb2SVadim Pasternak 5922c6fcbb2SVadim Pasternak return 0; 5932c6fcbb2SVadim Pasternak } 5942c6fcbb2SVadim Pasternak 5952c6fcbb2SVadim Pasternak static int 5962c6fcbb2SVadim Pasternak mp2975_vout_per_rail_config_get(struct i2c_client *client, 5972c6fcbb2SVadim Pasternak struct mp2975_data *data, 5982c6fcbb2SVadim Pasternak struct pmbus_driver_info *info) 5992c6fcbb2SVadim Pasternak { 6002c6fcbb2SVadim Pasternak int i, ret; 6012c6fcbb2SVadim Pasternak 6022c6fcbb2SVadim Pasternak for (i = 0; i < data->info.pages; i++) { 6032c6fcbb2SVadim Pasternak ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, i); 6042c6fcbb2SVadim Pasternak if (ret < 0) 6052c6fcbb2SVadim Pasternak return ret; 6062c6fcbb2SVadim Pasternak 6072c6fcbb2SVadim Pasternak /* Obtain voltage reference offsets. */ 6082c6fcbb2SVadim Pasternak ret = mp2975_vref_offset_get(client, data, i); 6092c6fcbb2SVadim Pasternak if (ret < 0) 6102c6fcbb2SVadim Pasternak return ret; 6112c6fcbb2SVadim Pasternak 6122c6fcbb2SVadim Pasternak /* Obtain maximum voltage values. */ 6132c6fcbb2SVadim Pasternak ret = mp2975_vout_max_get(client, data, info, i); 6142c6fcbb2SVadim Pasternak if (ret < 0) 6152c6fcbb2SVadim Pasternak return ret; 6162c6fcbb2SVadim Pasternak 617*1feb31e8SPatrick Rudolph /* Set VOUT format for READ_VOUT command : direct. */ 618*1feb31e8SPatrick Rudolph ret = mp2975_set_vout_format(client, data, i); 6192c6fcbb2SVadim Pasternak if (ret < 0) 6202c6fcbb2SVadim Pasternak return ret; 6212c6fcbb2SVadim Pasternak 6222c6fcbb2SVadim Pasternak /* 6232c6fcbb2SVadim Pasternak * Set over-voltage fixed value. Thresholds are provided as 6242c6fcbb2SVadim Pasternak * fixed value, and tracking value. The minimum of them are 6252c6fcbb2SVadim Pasternak * exposed as over-voltage critical threshold. 6262c6fcbb2SVadim Pasternak */ 6272c6fcbb2SVadim Pasternak data->vout_ov_fixed[i] = data->vref[i] + 6282c6fcbb2SVadim Pasternak DIV_ROUND_CLOSEST(data->vref_off[i] * 6292c6fcbb2SVadim Pasternak data->vout_scale, 6302c6fcbb2SVadim Pasternak 10); 6312c6fcbb2SVadim Pasternak } 6322c6fcbb2SVadim Pasternak 6332c6fcbb2SVadim Pasternak return 0; 6342c6fcbb2SVadim Pasternak } 6352c6fcbb2SVadim Pasternak 6362c6fcbb2SVadim Pasternak static struct pmbus_driver_info mp2975_info = { 6372c6fcbb2SVadim Pasternak .pages = 1, 6382c6fcbb2SVadim Pasternak .format[PSC_VOLTAGE_IN] = linear, 6392c6fcbb2SVadim Pasternak .format[PSC_VOLTAGE_OUT] = direct, 6402c6fcbb2SVadim Pasternak .format[PSC_TEMPERATURE] = direct, 6412c6fcbb2SVadim Pasternak .format[PSC_CURRENT_IN] = linear, 6422c6fcbb2SVadim Pasternak .format[PSC_CURRENT_OUT] = direct, 6432c6fcbb2SVadim Pasternak .format[PSC_POWER] = direct, 6442c6fcbb2SVadim Pasternak .m[PSC_TEMPERATURE] = 1, 6452c6fcbb2SVadim Pasternak .m[PSC_VOLTAGE_OUT] = 1, 6462c6fcbb2SVadim Pasternak .R[PSC_VOLTAGE_OUT] = 3, 6472c6fcbb2SVadim Pasternak .m[PSC_CURRENT_OUT] = 1, 6482c6fcbb2SVadim Pasternak .m[PSC_POWER] = 1, 6492c6fcbb2SVadim Pasternak .func[0] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_STATUS_VOUT | 6502c6fcbb2SVadim Pasternak PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | PMBUS_HAVE_STATUS_IOUT | 6512c6fcbb2SVadim Pasternak PMBUS_HAVE_TEMP | PMBUS_HAVE_STATUS_TEMP | PMBUS_HAVE_POUT | 6522c6fcbb2SVadim Pasternak PMBUS_HAVE_PIN | PMBUS_HAVE_STATUS_INPUT | PMBUS_PHASE_VIRTUAL, 6532c6fcbb2SVadim Pasternak .read_word_data = mp2975_read_word_data, 6542c6fcbb2SVadim Pasternak }; 6552c6fcbb2SVadim Pasternak 6562c6fcbb2SVadim Pasternak static int mp2975_probe(struct i2c_client *client) 6572c6fcbb2SVadim Pasternak { 6582c6fcbb2SVadim Pasternak struct pmbus_driver_info *info; 6592c6fcbb2SVadim Pasternak struct mp2975_data *data; 6602c6fcbb2SVadim Pasternak int ret; 6612c6fcbb2SVadim Pasternak 6622c6fcbb2SVadim Pasternak data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data), 6632c6fcbb2SVadim Pasternak GFP_KERNEL); 6642c6fcbb2SVadim Pasternak if (!data) 6652c6fcbb2SVadim Pasternak return -ENOMEM; 6662c6fcbb2SVadim Pasternak 6671f6f34d0SPatrick Rudolph if (client->dev.of_node) 6681f6f34d0SPatrick Rudolph data->chip_id = (enum chips)(unsigned long)of_device_get_match_data(&client->dev); 6691f6f34d0SPatrick Rudolph else 6701f6f34d0SPatrick Rudolph data->chip_id = i2c_match_id(mp2975_id, client)->driver_data; 6711f6f34d0SPatrick Rudolph 6722c6fcbb2SVadim Pasternak memcpy(&data->info, &mp2975_info, sizeof(*info)); 6732c6fcbb2SVadim Pasternak info = &data->info; 6742c6fcbb2SVadim Pasternak 6752c6fcbb2SVadim Pasternak /* Identify multiphase configuration for rail 2. */ 6762c6fcbb2SVadim Pasternak ret = mp2975_identify_multiphase_rail2(client); 6772c6fcbb2SVadim Pasternak if (ret < 0) 6782c6fcbb2SVadim Pasternak return ret; 6792c6fcbb2SVadim Pasternak 6802c6fcbb2SVadim Pasternak if (ret) { 6812c6fcbb2SVadim Pasternak /* Two rails are connected. */ 6822c6fcbb2SVadim Pasternak data->info.pages = MP2975_PAGE_NUM; 6832c6fcbb2SVadim Pasternak data->info.phases[1] = ret; 6842c6fcbb2SVadim Pasternak data->info.func[1] = MP2975_RAIL2_FUNC; 6852c6fcbb2SVadim Pasternak } 6862c6fcbb2SVadim Pasternak 6872c6fcbb2SVadim Pasternak /* Identify multiphase configuration. */ 6882c6fcbb2SVadim Pasternak ret = mp2975_identify_multiphase(client, data, info); 6892c6fcbb2SVadim Pasternak if (ret) 6902c6fcbb2SVadim Pasternak return ret; 6912c6fcbb2SVadim Pasternak 6922c6fcbb2SVadim Pasternak /* Identify VID setting per rail. */ 6932c6fcbb2SVadim Pasternak ret = mp2975_identify_rails_vid(client, data, info); 6942c6fcbb2SVadim Pasternak if (ret < 0) 6952c6fcbb2SVadim Pasternak return ret; 6962c6fcbb2SVadim Pasternak 6972c6fcbb2SVadim Pasternak /* Obtain current sense gain of power stage. */ 6982c6fcbb2SVadim Pasternak ret = mp2975_current_sense_gain_get(client, data); 6992c6fcbb2SVadim Pasternak if (ret) 7002c6fcbb2SVadim Pasternak return ret; 7012c6fcbb2SVadim Pasternak 7022c6fcbb2SVadim Pasternak /* Obtain voltage reference values. */ 7032c6fcbb2SVadim Pasternak ret = mp2975_vref_get(client, data, info); 7042c6fcbb2SVadim Pasternak if (ret) 7052c6fcbb2SVadim Pasternak return ret; 7062c6fcbb2SVadim Pasternak 7072c6fcbb2SVadim Pasternak /* Obtain vout over-voltage scales. */ 7082c6fcbb2SVadim Pasternak ret = mp2975_vout_ov_scale_get(client, data, info); 7092c6fcbb2SVadim Pasternak if (ret < 0) 7102c6fcbb2SVadim Pasternak return ret; 7112c6fcbb2SVadim Pasternak 7122c6fcbb2SVadim Pasternak /* Obtain offsets, maximum and format for vout. */ 7132c6fcbb2SVadim Pasternak ret = mp2975_vout_per_rail_config_get(client, data, info); 7142c6fcbb2SVadim Pasternak if (ret) 7152c6fcbb2SVadim Pasternak return ret; 7162c6fcbb2SVadim Pasternak 7172c6fcbb2SVadim Pasternak return pmbus_do_probe(client, info); 7182c6fcbb2SVadim Pasternak } 7192c6fcbb2SVadim Pasternak 7202c6fcbb2SVadim Pasternak static const struct of_device_id __maybe_unused mp2975_of_match[] = { 7211f6f34d0SPatrick Rudolph {.compatible = "mps,mp2975", .data = (void *)mp2975}, 7222c6fcbb2SVadim Pasternak {} 7232c6fcbb2SVadim Pasternak }; 7242c6fcbb2SVadim Pasternak MODULE_DEVICE_TABLE(of, mp2975_of_match); 7252c6fcbb2SVadim Pasternak 7262c6fcbb2SVadim Pasternak static struct i2c_driver mp2975_driver = { 7272c6fcbb2SVadim Pasternak .driver = { 7282c6fcbb2SVadim Pasternak .name = "mp2975", 7292c6fcbb2SVadim Pasternak .of_match_table = of_match_ptr(mp2975_of_match), 7302c6fcbb2SVadim Pasternak }, 7311975d167SUwe Kleine-König .probe = mp2975_probe, 7322c6fcbb2SVadim Pasternak .id_table = mp2975_id, 7332c6fcbb2SVadim Pasternak }; 7342c6fcbb2SVadim Pasternak 7352c6fcbb2SVadim Pasternak module_i2c_driver(mp2975_driver); 7362c6fcbb2SVadim Pasternak 7372c6fcbb2SVadim Pasternak MODULE_AUTHOR("Vadim Pasternak <vadimp@nvidia.com>"); 7382c6fcbb2SVadim Pasternak MODULE_DESCRIPTION("PMBus driver for MPS MP2975 device"); 7392c6fcbb2SVadim Pasternak MODULE_LICENSE("GPL"); 740b94ca77eSGuenter Roeck MODULE_IMPORT_NS(PMBUS); 741