diff --git a/drivers/hwmon/pmbus/mp2869.c b/drivers/hwmon/pmbus/mp2869.c index 5cac1929ea6e2a..ae0e80d58a2f70 100644 --- a/drivers/hwmon/pmbus/mp2869.c +++ b/drivers/hwmon/pmbus/mp2869.c @@ -16,6 +16,7 @@ #define MP2869_MFR_VOUT_SCALE_LOOP 0x29 #define MP2869_IIN_SCALE_BIT_R1 0x53 #define MP2869_IOUT_SCALE_BIT 0x67 +#define MP2869_MFR_PWR_RPT_R1 0x68 #define MP2869_MFR_VOUT_LOOP_CTRL_R2 0xBD #define MP2869_MAX_PHASE_RAIL1 16 @@ -46,6 +47,7 @@ struct mp2869_data { int vout_gain[MP2869_PAGE_NUM]; int curr_iin_gain[MP2869_PAGE_NUM]; int curr_iout_gain[MP2869_PAGE_NUM]; + int power_gain[MP2869_PAGE_NUM]; int max_phases[MP2869_PAGE_NUM]; enum chips chip_id; }; @@ -54,79 +56,7 @@ struct mp2869_data { #define MAX_LIN_MANTISSA (1023 * 1000) #define MIN_LIN_MANTISSA (511 * 1000) -/* -static int bit_x_get(int val,int high,int low ) -{ - int tmp_num; - int bit_num = high-low+1; - - int tmp_val = val & GENMASK(high,low); - - //zsj add - printk("val =%d,tmp_val =%d\n",val,tmp_val); - - tmp_val >= low; - //zsj add - printk("tmp_val >=low(%d) = %d\n",tmp_val,low); - - tmp_num = 2<<(bit_num-1); - if(tmp_val > = tmp_num) - { - tmp_num = 2<= MAX_LIN_MANTISSA && exponent < 15) { - exponent++; - val >>= 1; - } - // Increase small mantissa to improve precision - while (val < MIN_LIN_MANTISSA && exponent > -15) { - exponent--; - val <<= 1; - } - - // Convert mantissa from milli-units to units - mantissa = clamp_val(DIV_ROUND_CLOSEST_ULL(val, 1000), 0, 0x3ff); - // restore sign - if (negative) - mantissa = -mantissa; - - // Convert to 5 bit exponent, 11 bit mantissa - return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800); -} - -static int -mp2869_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg, - u16 mask) -{ - int ret = pmbus_read_word_data(client, page, phase, reg); - - return (ret > 0) ? ret & mask : ret; -} - -*/ // some values are SMBus LINEAR11 data which need a conversion static int corsairpsu_linear11_to_int(int val) @@ -147,48 +77,12 @@ mp2869_read_vout(struct i2c_client *client, struct mp2869_data *data, int page, ret = pmbus_read_word_data(client, page, phase, reg); /* convert vout result to direct format */ - - if(page == 0) - { - ret = (ret*1000) / data->vout_gain[page]; - } - else if(page == 1) - { - ret *= data->vout_gain[page]; - } + ret = (ret*1000) / data->vout_gain[page]; return ret; } -static int -mp2869_read_iout(struct i2c_client *client, struct mp2869_data *data, int page, - int phase, u8 reg) -{ - int ret; - - ret = pmbus_read_word_data(client, page, phase, reg); - ret = corsairpsu_linear11_to_int(ret); - - /* convert vout result to direct format */ - ret = (ret*1000) / data->curr_iout_gain[page]; - - return ret; -} - -static int -mp2869_read_iin(struct i2c_client *client, struct mp2869_data *data, int page, - int phase, u8 reg) -{ - int ret; - - ret = pmbus_read_word_data(client, page, phase, reg); - - /* convert vout result to direct format */ - ret = (ret*1000) / data->curr_iin_gain[page]; - - return ret; -} static int mp2869_read_word_data(struct i2c_client *client, int page, @@ -202,12 +96,7 @@ mp2869_read_word_data(struct i2c_client *client, int page, case PMBUS_READ_VOUT: ret = mp2869_read_vout(client, data, page, phase, reg); break; - case PMBUS_READ_IOUT: - ret = mp2869_read_iout(client, data, page, phase, reg); - break; - case PMBUS_READ_IIN: - ret = mp2869_read_iin(client, data, page, phase, reg); - break; + default: return -ENODATA; } @@ -227,134 +116,63 @@ mp2869_read_byte_data(struct i2c_client *client, int page, int reg) } } + + static int -mp2869_current_iin_gain_get(struct i2c_client *client, +mp2869_voltage_vout_gain_get(struct i2c_client *client, struct mp2869_data *data) { - int curr_gain, ret; - - //Curr gain IIN1 + int vout_gain, ret; + //Voltage gain VOUT1 ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); if(ret < 0) return ret; - ret = i2c_smbus_read_word_data(client,MP2869_IIN_SCALE_BIT_R1); - - printk("mp2869_current_iin_gain_get MP2869_IIN_SCALE_BIT_R1 ret =%d\n",ret); - //IIN1 scale bit is 53h page0 bit[10:8] - ret = ret & GENMASK(10,8); - ret = ret >> 8; + ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_SCALE_LOOP); + printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP ret =%d\n",ret); + + //VOUT1 scale bit is 29h page0 bit[12:10] + ret = ret & GENMASK(12,10); + ret = ret >> 10; switch (ret) { case 0: - curr_gain = 8; + vout_gain = 160; break; case 1: - curr_gain = 256; + vout_gain = 200; break; case 2: - curr_gain = 128; + vout_gain = 400; break; case 3: - curr_gain = 64; + vout_gain = 500; break; case 4: - curr_gain = 32; + vout_gain = 1000; break; case 5: - curr_gain = 16; + vout_gain = 256; break; case 6: - curr_gain = 8; + vout_gain = 512; break; case 7: - curr_gain = 4; - break; - default: - printk("error get iin_gain in MP2869_IIN_SCALE_BIT_R1\n"); - break; - } - - data->curr_iin_gain[0] = curr_gain; - data->curr_iin_gain[0] = 1; - //zsjadd test - for(int i=0;i <2;i++) - { - printk("data->curr_iin_gain[%d]=%d\n",i,data->curr_iin_gain[i]); - } - - return 0; -} - - -static int -mp2869_current_iout_gain_get(struct i2c_client *client, - struct mp2869_data *data) -{ - int curr_gain, ret; - - //Curr gain IOUT1 - ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); - if(ret < 0) - return ret; - - //IOUT1 scale bit is 67h page0 bit[2:0] - ret = i2c_smbus_read_word_data(client,MP2869_IOUT_SCALE_BIT); - - ret = ret & GENMASK(2,0); - - switch (ret) { - case 0: - curr_gain = 1; - break; - case 1: - curr_gain = 32; - break; - case 2: - curr_gain = 16; - break; - case 3: - curr_gain = 8; - break; - case 4: - curr_gain = 4; - break; - case 5: - curr_gain = 2; + vout_gain = 1024; break; - case 6: - curr_gain = 1; - break; default: - printk("error get iin_gain in MP2869_IIN_SCALE_BIT_R1\n"); + printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n"); break; } + data->vout_gain[0] = vout_gain; - - data->curr_iout_gain[0] = curr_gain; - - data->curr_iout_gain[1] =1; - //zsjadd test - for(int i=0;i <2;i++) - { - printk("data->curr_iout_gain[%d]=%d\n",i,data->curr_iout_gain[i]); - } - - return 0; -} - -static int -mp2869_voltage_vout_gain_get(struct i2c_client *client, - struct mp2869_data *data) -{ - int vout_gain, ret; - //Voltage gain VOUT1 - ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); + //Voltage gain VOUT2 + ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 1); if(ret < 0) - return ret; + return ret; ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_SCALE_LOOP); - printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP ret =%d\n",ret); + printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP_R2 ret =%d\n",ret); //VOUT1 scale bit is 29h page0 bit[12:10] ret = ret & GENMASK(12,10); @@ -386,23 +204,9 @@ mp2869_voltage_vout_gain_get(struct i2c_client *client, vout_gain = 1024; break; default: - printk("error get iin_gain in MP2869_MFR_VOUT_SCALE_LOOP\n"); + printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n"); break; } - data->vout_gain[0] = vout_gain; - - //Voltage gain VOUT2 - ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2); - if(ret < 0) - return ret; - - ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_LOOP_CTRL_R2); - printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_LOOP_CTRL_R2 ret =%d\n",ret); - - //VOUT2 scale bit is BDh page2 bit[15:14] - vout_gain = ret & GENMASK(15,14); - vout_gain = vout_gain>>14; - data->vout_gain[1] = vout_gain; //zsjadd test @@ -421,8 +225,8 @@ static struct pmbus_driver_info mp2869_info = { .format[PSC_VOLTAGE_IN] = linear, .format[PSC_VOLTAGE_OUT] = direct, .format[PSC_TEMPERATURE] = linear, - .format[PSC_CURRENT_IN] = direct, - .format[PSC_CURRENT_OUT] = direct, + .format[PSC_CURRENT_IN] = linear, + .format[PSC_CURRENT_OUT] = linear, .format[PSC_POWER] = linear, .m[PSC_VOLTAGE_OUT] = 1, .R[PSC_VOLTAGE_OUT] = 3, @@ -432,8 +236,7 @@ static struct pmbus_driver_info mp2869_info = { PMBUS_HAVE_PIN , .func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT | PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT | - PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT | - PMBUS_HAVE_PIN , + PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT , .read_byte_data = mp2869_read_byte_data, .read_word_data = mp2869_read_word_data, }; @@ -457,20 +260,10 @@ static int mp2869_probe(struct i2c_client *client) memcpy(&data->info, &mp2869_info, sizeof(*info)); info = &data->info; - /* Get IIN current stage. */ - ret = mp2869_current_iin_gain_get(client, data); - if (ret) - return ret; - - /* Get IOUT current stage. */ - ret = mp2869_current_iout_gain_get(client, data); - if (ret) - return ret; - /* Get Vout stage. */ ret = mp2869_voltage_vout_gain_get(client, data); if (ret) - return ret; + return ret; i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0); @@ -498,4 +291,4 @@ module_i2c_driver(mp2869_driver); MODULE_AUTHOR("Shaojie Zhang"); MODULE_DESCRIPTION("PMBus driver for MPS MP2869/MP29608 device"); MODULE_LICENSE("GPL"); -MODULE_IMPORT_NS(PMBUS); \ No newline at end of file +MODULE_IMPORT_NS(PMBUS);