Skip to content

Commit d23ac60

Browse files
committed
Fixed MP2869 driver issues
- Driver now gives correct readings for rails 1 and 2 - Driver no longer advertises rail 2 power in Tested: - SP7 Nigeria - SP8 Falcon Signed-off-by: Ryan Ilgen <Ryan.Ilgen@amd.com>
1 parent 5145642 commit d23ac60

1 file changed

Lines changed: 33 additions & 241 deletions

File tree

drivers/hwmon/pmbus/mp2869.c

Lines changed: 33 additions & 241 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ struct mp2869_data {
4646
int vout_gain[MP2869_PAGE_NUM];
4747
int curr_iin_gain[MP2869_PAGE_NUM];
4848
int curr_iout_gain[MP2869_PAGE_NUM];
49+
int power_gain[MP2869_PAGE_NUM];
4950
int max_phases[MP2869_PAGE_NUM];
5051
enum chips chip_id;
5152
};
@@ -54,79 +55,7 @@ struct mp2869_data {
5455
#define MAX_LIN_MANTISSA (1023 * 1000)
5556
#define MIN_LIN_MANTISSA (511 * 1000)
5657

57-
/*
58-
static int bit_x_get(int val,int high,int low )
59-
{
60-
int tmp_num;
61-
int bit_num = high-low+1;
62-
63-
int tmp_val = val & GENMASK(high,low);
64-
65-
//zsj add
66-
printk("val =%d,tmp_val =%d\n",val,tmp_val);
67-
68-
tmp_val >= low;
69-
//zsj add
70-
printk("tmp_val >=low(%d) = %d\n",tmp_val,low);
71-
72-
tmp_num = 2<<(bit_num-1);
73-
if(tmp_val > = tmp_num)
74-
{
75-
tmp_num = 2<<bit_num;
76-
tmp_val -= tmp_num;
77-
}
78-
79-
//zsj add
80-
printk("bit_x_get =(%d)\n",tmp_val);
81-
82-
return tmp_val;
83-
}
84-
85-
static u16 val2linear11(s64 val)
86-
{
87-
s16 exponent = 0, mantissa;
88-
bool negative = false;
89-
90-
if (val == 0)
91-
return 0;
92-
93-
if (val < 0) {
94-
negative = true;
95-
val = -val;
96-
}
97-
98-
// Reduce large mantissa until it fits into 10 bit
99-
while (val >= MAX_LIN_MANTISSA && exponent < 15) {
100-
exponent++;
101-
val >>= 1;
102-
}
103-
// Increase small mantissa to improve precision
104-
while (val < MIN_LIN_MANTISSA && exponent > -15) {
105-
exponent--;
106-
val <<= 1;
107-
}
108-
109-
// Convert mantissa from milli-units to units
110-
mantissa = clamp_val(DIV_ROUND_CLOSEST_ULL(val, 1000), 0, 0x3ff);
11158

112-
// restore sign
113-
if (negative)
114-
mantissa = -mantissa;
115-
116-
// Convert to 5 bit exponent, 11 bit mantissa
117-
return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800);
118-
}
119-
120-
static int
121-
mp2869_read_word_helper(struct i2c_client *client, int page, int phase, u8 reg,
122-
u16 mask)
123-
{
124-
int ret = pmbus_read_word_data(client, page, phase, reg);
125-
126-
return (ret > 0) ? ret & mask : ret;
127-
}
128-
129-
*/
13059

13160
// some values are SMBus LINEAR11 data which need a conversion
13261
static int corsairpsu_linear11_to_int(int val)
@@ -147,48 +76,12 @@ mp2869_read_vout(struct i2c_client *client, struct mp2869_data *data, int page,
14776
ret = pmbus_read_word_data(client, page, phase, reg);
14877

14978
/* convert vout result to direct format */
150-
151-
if(page == 0)
152-
{
153-
ret = (ret*1000) / data->vout_gain[page];
154-
}
155-
else if(page == 1)
156-
{
157-
ret *= data->vout_gain[page];
158-
}
79+
ret = (ret*1000) / data->vout_gain[page];
15980

16081
return ret;
16182
}
16283

163-
static int
164-
mp2869_read_iout(struct i2c_client *client, struct mp2869_data *data, int page,
165-
int phase, u8 reg)
166-
{
167-
int ret;
168-
169-
ret = pmbus_read_word_data(client, page, phase, reg);
170-
171-
ret = corsairpsu_linear11_to_int(ret);
172-
173-
/* convert vout result to direct format */
174-
ret = (ret*1000) / data->curr_iout_gain[page];
175-
176-
return ret;
177-
}
178-
179-
static int
180-
mp2869_read_iin(struct i2c_client *client, struct mp2869_data *data, int page,
181-
int phase, u8 reg)
182-
{
183-
int ret;
184-
185-
ret = pmbus_read_word_data(client, page, phase, reg);
186-
187-
/* convert vout result to direct format */
188-
ret = (ret*1000) / data->curr_iin_gain[page];
18984

190-
return ret;
191-
}
19285

19386
static int
19487
mp2869_read_word_data(struct i2c_client *client, int page,
@@ -202,12 +95,7 @@ mp2869_read_word_data(struct i2c_client *client, int page,
20295
case PMBUS_READ_VOUT:
20396
ret = mp2869_read_vout(client, data, page, phase, reg);
20497
break;
205-
case PMBUS_READ_IOUT:
206-
ret = mp2869_read_iout(client, data, page, phase, reg);
207-
break;
208-
case PMBUS_READ_IIN:
209-
ret = mp2869_read_iin(client, data, page, phase, reg);
210-
break;
98+
21199
default:
212100
return -ENODATA;
213101
}
@@ -227,134 +115,63 @@ mp2869_read_byte_data(struct i2c_client *client, int page, int reg)
227115
}
228116
}
229117

118+
119+
230120
static int
231-
mp2869_current_iin_gain_get(struct i2c_client *client,
121+
mp2869_voltage_vout_gain_get(struct i2c_client *client,
232122
struct mp2869_data *data)
233123
{
234-
int curr_gain, ret;
235-
236-
//Curr gain IIN1
124+
int vout_gain, ret;
125+
//Voltage gain VOUT1
237126
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
238127
if(ret < 0)
239128
return ret;
240129

241-
ret = i2c_smbus_read_word_data(client,MP2869_IIN_SCALE_BIT_R1);
242-
243-
printk("mp2869_current_iin_gain_get MP2869_IIN_SCALE_BIT_R1 ret =%d\n",ret);
244-
//IIN1 scale bit is 53h page0 bit[10:8]
245-
ret = ret & GENMASK(10,8);
246-
ret = ret >> 8;
130+
ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_SCALE_LOOP);
131+
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP ret =%d\n",ret);
132+
133+
//VOUT1 scale bit is 29h page0 bit[12:10]
134+
ret = ret & GENMASK(12,10);
135+
ret = ret >> 10;
247136

248137
switch (ret) {
249138
case 0:
250-
curr_gain = 8;
139+
vout_gain = 160;
251140
break;
252141
case 1:
253-
curr_gain = 256;
142+
vout_gain = 200;
254143
break;
255144
case 2:
256-
curr_gain = 128;
145+
vout_gain = 400;
257146
break;
258147
case 3:
259-
curr_gain = 64;
148+
vout_gain = 500;
260149
break;
261150
case 4:
262-
curr_gain = 32;
151+
vout_gain = 1000;
263152
break;
264153
case 5:
265-
curr_gain = 16;
154+
vout_gain = 256;
266155
break;
267156
case 6:
268-
curr_gain = 8;
157+
vout_gain = 512;
269158
break;
270159
case 7:
271-
curr_gain = 4;
272-
break;
273-
default:
274-
printk("error get iin_gain in MP2869_IIN_SCALE_BIT_R1\n");
275-
break;
276-
}
277-
278-
data->curr_iin_gain[0] = curr_gain;
279-
data->curr_iin_gain[0] = 1;
280-
//zsjadd test
281-
for(int i=0;i <2;i++)
282-
{
283-
printk("data->curr_iin_gain[%d]=%d\n",i,data->curr_iin_gain[i]);
284-
}
285-
286-
return 0;
287-
}
288-
289-
290-
static int
291-
mp2869_current_iout_gain_get(struct i2c_client *client,
292-
struct mp2869_data *data)
293-
{
294-
int curr_gain, ret;
295-
296-
//Curr gain IOUT1
297-
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
298-
if(ret < 0)
299-
return ret;
300-
301-
//IOUT1 scale bit is 67h page0 bit[2:0]
302-
ret = i2c_smbus_read_word_data(client,MP2869_IOUT_SCALE_BIT);
303-
304-
ret = ret & GENMASK(2,0);
305-
306-
switch (ret) {
307-
case 0:
308-
curr_gain = 1;
309-
break;
310-
case 1:
311-
curr_gain = 32;
312-
break;
313-
case 2:
314-
curr_gain = 16;
315-
break;
316-
case 3:
317-
curr_gain = 8;
318-
break;
319-
case 4:
320-
curr_gain = 4;
321-
break;
322-
case 5:
323-
curr_gain = 2;
160+
vout_gain = 1024;
324161
break;
325-
case 6:
326-
curr_gain = 1;
327-
break;
328162
default:
329-
printk("error get iin_gain in MP2869_IIN_SCALE_BIT_R1\n");
163+
printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
330164
break;
331165
}
166+
data->vout_gain[0] = vout_gain;
332167

333-
334-
data->curr_iout_gain[0] = curr_gain;
335-
336-
data->curr_iout_gain[1] =1;
337-
//zsjadd test
338-
for(int i=0;i <2;i++)
339-
{
340-
printk("data->curr_iout_gain[%d]=%d\n",i,data->curr_iout_gain[i]);
341-
}
342-
343-
return 0;
344-
}
345-
346-
static int
347-
mp2869_voltage_vout_gain_get(struct i2c_client *client,
348-
struct mp2869_data *data)
349-
{
350-
int vout_gain, ret;
351-
//Voltage gain VOUT1
352-
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
168+
//Voltage gain VOUT2
169+
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 1);
353170
if(ret < 0)
354-
return ret;
171+
return ret;
355172

356173
ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_SCALE_LOOP);
357-
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP ret =%d\n",ret);
174+
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP_R2 ret =%d\n",ret);
358175

359176
//VOUT1 scale bit is 29h page0 bit[12:10]
360177
ret = ret & GENMASK(12,10);
@@ -386,23 +203,9 @@ mp2869_voltage_vout_gain_get(struct i2c_client *client,
386203
vout_gain = 1024;
387204
break;
388205
default:
389-
printk("error get iin_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
206+
printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
390207
break;
391208
}
392-
data->vout_gain[0] = vout_gain;
393-
394-
//Voltage gain VOUT2
395-
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 2);
396-
if(ret < 0)
397-
return ret;
398-
399-
ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_LOOP_CTRL_R2);
400-
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_LOOP_CTRL_R2 ret =%d\n",ret);
401-
402-
//VOUT2 scale bit is BDh page2 bit[15:14]
403-
vout_gain = ret & GENMASK(15,14);
404-
vout_gain = vout_gain>>14;
405-
406209
data->vout_gain[1] = vout_gain;
407210

408211
//zsjadd test
@@ -421,8 +224,8 @@ static struct pmbus_driver_info mp2869_info = {
421224
.format[PSC_VOLTAGE_IN] = linear,
422225
.format[PSC_VOLTAGE_OUT] = direct,
423226
.format[PSC_TEMPERATURE] = linear,
424-
.format[PSC_CURRENT_IN] = direct,
425-
.format[PSC_CURRENT_OUT] = direct,
227+
.format[PSC_CURRENT_IN] = linear,
228+
.format[PSC_CURRENT_OUT] = linear,
426229
.format[PSC_POWER] = linear,
427230
.m[PSC_VOLTAGE_OUT] = 1,
428231
.R[PSC_VOLTAGE_OUT] = 3,
@@ -432,8 +235,7 @@ static struct pmbus_driver_info mp2869_info = {
432235
PMBUS_HAVE_PIN ,
433236
.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT |
434237
PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT |
435-
PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT |
436-
PMBUS_HAVE_PIN ,
238+
PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT ,
437239
.read_byte_data = mp2869_read_byte_data,
438240
.read_word_data = mp2869_read_word_data,
439241
};
@@ -457,16 +259,6 @@ static int mp2869_probe(struct i2c_client *client)
457259
memcpy(&data->info, &mp2869_info, sizeof(*info));
458260
info = &data->info;
459261

460-
/* Get IIN current stage. */
461-
ret = mp2869_current_iin_gain_get(client, data);
462-
if (ret)
463-
return ret;
464-
465-
/* Get IOUT current stage. */
466-
ret = mp2869_current_iout_gain_get(client, data);
467-
if (ret)
468-
return ret;
469-
470262
/* Get Vout stage. */
471263
ret = mp2869_voltage_vout_gain_get(client, data);
472264
if (ret)
@@ -498,4 +290,4 @@ module_i2c_driver(mp2869_driver);
498290
MODULE_AUTHOR("Shaojie Zhang");
499291
MODULE_DESCRIPTION("PMBus driver for MPS MP2869/MP29608 device");
500292
MODULE_LICENSE("GPL");
501-
MODULE_IMPORT_NS(PMBUS);
293+
MODULE_IMPORT_NS(PMBUS);

0 commit comments

Comments
 (0)