Lines Matching +full:negative +full:- +full:phase
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Hardware monitoring driver for MPS Multi-phase Digital VR Controllers
140 return -ENODATA; in mp2975_read_byte_data()
145 mp2975_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg, in mp2975_read_word_helper() argument
148 int ret = pmbus_read_word_data(client, page, phase, reg); in mp2975_read_word_helper()
159 return 250 + (val - 1) * 5; in mp2975_vid2direct()
163 return 500 + (val - 1) * 10; in mp2975_vid2direct()
167 return 200 + (val - 1) * 10; in mp2975_vid2direct()
170 return -EINVAL; in mp2975_vid2direct()
178 /* Converts a milli-unit DIRECT value to LINEAR11 format */
182 bool negative = false; in mp2975_data2reg_linear11() local
194 while (val < MIN_LIN_MANTISSA && exponent > -15) { in mp2975_data2reg_linear11()
195 exponent--; in mp2975_data2reg_linear11()
199 /* Convert mantissa from milli-units to units */ in mp2975_data2reg_linear11()
203 if (negative) in mp2975_data2reg_linear11()
204 mantissa = -mantissa; in mp2975_data2reg_linear11()
212 int page, int phase, u8 reg) in mp2975_read_phase() argument
216 ret = pmbus_read_word_data(client, page, phase, reg); in mp2975_read_phase()
220 if (!((phase + 1) % MP2975_PAGE_NUM)) in mp2975_read_phase()
227 * - Kcs is the DrMOS current sense gain of power stage, which is in mp2975_read_phase()
228 * obtained from the register MP2975_MFR_VR_CONFIG1, bits 13-12 with in mp2975_read_phase()
229 * the following selection of DrMOS (data->curr_sense_gain[page]): in mp2975_read_phase()
230 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. in mp2975_read_phase()
231 * - Rcs is the internal phase current sense resistor which is constant in mp2975_read_phase()
234 ph_curr = ret * 100 - 9800; in mp2975_read_phase()
237 * Current phase sensing, providing by the device is not accurate in mp2975_read_phase()
240 * case phase current is represented as the maximum between the value in mp2975_read_phase()
243 ret = pmbus_read_word_data(client, page, phase, PMBUS_READ_IOUT); in mp2975_read_phase()
247 return max_t(int, DIV_ROUND_CLOSEST(ret, data->info.phases[page]), in mp2975_read_phase()
248 DIV_ROUND_CLOSEST(ph_curr, data->curr_sense_gain[page])); in mp2975_read_phase()
253 int page, int phase) in mp2975_read_phases() argument
258 switch (phase) { in mp2975_read_phases()
260 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
264 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
268 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
272 return -ENODATA; in mp2975_read_phases()
275 switch (phase) { in mp2975_read_phases()
277 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
281 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
285 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
289 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
293 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
297 ret = mp2975_read_phase(client, data, page, phase, in mp2975_read_phases()
301 return -ENODATA; in mp2975_read_phases()
308 int phase, int reg) in mp2973_read_word_data() argument
317 ret = pmbus_read_word_data(client, page, phase, reg); in mp2973_read_word_data()
321 ret = mp2975_read_word_helper(client, page, phase, reg, in mp2973_read_word_data()
325 ret = mp2975_read_word_helper(client, page, phase, reg, in mp2973_read_word_data()
336 ret = mp2975_read_word_helper(client, page, phase, in mp2973_read_word_data()
342 ret = data->vout_max[page] + 50 * (ret + 1); in mp2973_read_word_data()
345 ret = mp2975_read_word_helper(client, page, phase, reg, in mp2973_read_word_data()
349 ret = mp2975_vid2direct(info->vrm_version[page], ret); in mp2973_read_word_data()
352 ret = pmbus_read_word_data(client, page, phase, in mp2973_read_word_data()
356 ret = pmbus_read_word_data(client, page, phase, in mp2973_read_word_data()
360 ret = mp2975_read_word_helper(client, page, phase, in mp2973_read_word_data()
371 ret = mp2975_data2reg_linear11(ret * info->phases[page] * 1000); in mp2973_read_word_data()
387 return -ENXIO; in mp2973_read_word_data()
389 return -ENODATA; in mp2973_read_word_data()
396 int phase, int reg) in mp2975_read_word_data() argument
404 ret = mp2975_read_word_helper(client, page, phase, reg, in mp2975_read_word_data()
408 ret = mp2975_read_word_helper(client, page, phase, reg, in mp2975_read_word_data()
417 * Register provides two values for over-voltage protection in mp2975_read_word_data()
419 * minimum of these two values is provided as over-voltage in mp2975_read_word_data()
422 ret = mp2975_read_word_helper(client, page, phase, in mp2975_read_word_data()
428 ret = min_t(int, data->vout_max[page] + 50 * (ret + 1), in mp2975_read_word_data()
429 data->vout_ov_fixed[page]); in mp2975_read_word_data()
432 ret = mp2975_read_word_helper(client, page, phase, in mp2975_read_word_data()
438 ret = DIV_ROUND_CLOSEST(data->vref[page] * 10 - 50 * in mp2975_read_word_data()
439 (ret + 1) * data->vout_scale, 10); in mp2975_read_word_data()
442 ret = mp2975_read_word_helper(client, page, phase, in mp2975_read_word_data()
451 ret = mp2975_read_word_helper(client, page, phase, in mp2975_read_word_data()
460 ret = mp2975_read_phases(client, data, page, phase); in mp2975_read_word_data()
481 return -ENXIO; in mp2975_read_word_data()
483 return -ENODATA; in mp2975_read_word_data()
495 * Identify multiphase for rail 2 - could be from 0 to data->max_phases[1]. in mp2975_identify_multiphase_rail2()
496 * In case phase number is zero – only page zero is supported in mp2975_identify_multiphase_rail2()
507 return (ret >= data->max_phases[1]) ? data->max_phases[1] : ret; in mp2975_identify_multiphase_rail2()
514 for (i = 0 ; i < info->phases[0]; i++) in mp2975_set_phase_rail1()
515 info->pfunc[i] = PMBUS_HAVE_IOUT; in mp2975_set_phase_rail1()
525 info->pfunc[MP2975_MAX_PHASE_RAIL1 - i] = PMBUS_HAVE_IOUT; in mp2975_set_phase_rail2()
538 /* Identify multiphase for rail 1 - could be from 1 to data->max_phases[0]. */ in mp2975_identify_multiphase()
543 info->phases[0] = ret & GENMASK(3, 0); in mp2975_identify_multiphase()
547 * to different phase count applications for rail 1 and rail 2. in mp2975_identify_multiphase()
549 * that. When rail 1’s phase count is configured as 0, rail in mp2975_identify_multiphase()
550 * 1 operates with 1-phase DCM. When rail 2 phase count is configured in mp2975_identify_multiphase()
553 if (info->phases[0] > data->max_phases[0]) in mp2975_identify_multiphase()
554 return -EINVAL; in mp2975_identify_multiphase()
556 if (data->chip_id == mp2975) { in mp2975_identify_multiphase()
558 num_phases2 = min(data->max_phases[0] - info->phases[0], in mp2975_identify_multiphase()
559 data->max_phases[1]); in mp2975_identify_multiphase()
560 if (info->phases[1] && info->phases[1] <= num_phases2) in mp2975_identify_multiphase()
580 info->vrm_version[page] = imvp9; in mp2975_identify_vid()
581 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; in mp2975_identify_vid()
583 info->vrm_version[page] = vr12; in mp2975_identify_vid()
584 data->vid_step[page] = MP2975_PROT_DEV_OV_ON; in mp2975_identify_vid()
586 info->vrm_version[page] = vr13; in mp2975_identify_vid()
587 data->vid_step[page] = MP2975_PROT_DEV_OV_OFF; in mp2975_identify_vid()
611 if (info->phases[1]) in mp2975_identify_rails_vid()
639 if (info->phases[1]) in mp2973_identify_rails_vid()
656 * MP2975_MFR_VR_CONFIG1, bits 13-12. The value is selected as below: in mp2975_current_sense_gain_get()
657 * 00b - 5µA/A, 01b - 8.5µA/A, 10b - 9.7µA/A, 11b - 10µA/A. Other in mp2975_current_sense_gain_get()
660 for (i = 0 ; i < data->info.pages; i++) { in mp2975_current_sense_gain_get()
671 data->curr_sense_gain[i] = 50; in mp2975_current_sense_gain_get()
674 data->curr_sense_gain[i] = 85; in mp2975_current_sense_gain_get()
677 data->curr_sense_gain[i] = 97; in mp2975_current_sense_gain_get()
680 data->curr_sense_gain[i] = 100; in mp2975_current_sense_gain_get()
703 data->vref[0] = ret * data->vid_step[0]; in mp2975_vref_get()
706 if (data->info.pages == MP2975_PAGE_NUM) { in mp2975_vref_get()
711 data->vref[1] = ret * data->vid_step[1]; in mp2975_vref_get()
728 data->vref_off[page] = 140; in mp2975_vref_offset_get()
731 data->vref_off[page] = 220; in mp2975_vref_offset_get()
734 data->vref_off[page] = 400; in mp2975_vref_offset_get()
737 return -EINVAL; in mp2975_vref_offset_get()
748 /* Get maximum reference voltage of VID-DAC in VID format. */ in mp2975_vout_max_get()
753 data->vout_max[page] = mp2975_vid2direct(info->vrm_version[page], ret & in mp2975_vout_max_get()
765 if (data->chip_id == mp2975) { in mp2975_set_vout_format()
803 * Get divider for over- and under-voltage protection thresholds in mp2975_vout_ov_scale_get()
804 * configuration from the Advanced Options of Auto Phase Shedding and in mp2975_vout_ov_scale_get()
820 data->vout_scale = sense_ampl * thres_dev; in mp2975_vout_ov_scale_get()
832 for (i = 0; i < data->info.pages; i++) { in mp2975_vout_per_rail_config_get()
848 if (data->chip_id != mp2975) in mp2975_vout_per_rail_config_get()
857 * Set over-voltage fixed value. Thresholds are provided as in mp2975_vout_per_rail_config_get()
859 * exposed as over-voltage critical threshold. in mp2975_vout_per_rail_config_get()
861 data->vout_ov_fixed[i] = data->vref[i] + in mp2975_vout_per_rail_config_get()
862 DIV_ROUND_CLOSEST(data->vref_off[i] * in mp2975_vout_per_rail_config_get()
863 data->vout_scale, in mp2975_vout_per_rail_config_get()
922 data = devm_kzalloc(&client->dev, sizeof(struct mp2975_data), in mp2975_probe()
925 return -ENOMEM; in mp2975_probe()
927 if (client->dev.of_node) in mp2975_probe()
928 data->chip_id = (enum chips)(unsigned long)of_device_get_match_data(&client->dev); in mp2975_probe()
930 data->chip_id = i2c_match_id(mp2975_id, client)->driver_data; in mp2975_probe()
932 memcpy(data->max_phases, mp2975_max_phases[data->chip_id], in mp2975_probe()
933 sizeof(data->max_phases)); in mp2975_probe()
935 if (data->chip_id == mp2975) in mp2975_probe()
936 memcpy(&data->info, &mp2975_info, sizeof(*info)); in mp2975_probe()
938 memcpy(&data->info, &mp2973_info, sizeof(*info)); in mp2975_probe()
940 info = &data->info; in mp2975_probe()
949 data->info.pages = MP2975_PAGE_NUM; in mp2975_probe()
950 data->info.phases[1] = ret; in mp2975_probe()
951 data->info.func[1] = MP2975_RAIL2_FUNC; in mp2975_probe()
953 data->info.num_regulators = MP2975_PAGE_NUM; in mp2975_probe()
961 if (data->chip_id == mp2975) { in mp2975_probe()
977 /* Obtain vout over-voltage scales. */ in mp2975_probe()