Skip to content

Commit 34cd4ec

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: - Nigeria-2690 - Falcon-FPGC Signed-off-by: Ryan Ilgen <Ryan.Ilgen@amd.com>
1 parent 5145642 commit 34cd4ec

1 file changed

Lines changed: 35 additions & 242 deletions

File tree

drivers/hwmon/pmbus/mp2869.c

Lines changed: 35 additions & 242 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define MP2869_MFR_VOUT_SCALE_LOOP 0x29
1717
#define MP2869_IIN_SCALE_BIT_R1 0x53
1818
#define MP2869_IOUT_SCALE_BIT 0x67
19+
#define MP2869_MFR_PWR_RPT_R1 0x68
1920
#define MP2869_MFR_VOUT_LOOP_CTRL_R2 0xBD
2021

2122
#define MP2869_MAX_PHASE_RAIL1 16
@@ -46,6 +47,7 @@ struct mp2869_data {
4647
int vout_gain[MP2869_PAGE_NUM];
4748
int curr_iin_gain[MP2869_PAGE_NUM];
4849
int curr_iout_gain[MP2869_PAGE_NUM];
50+
int power_gain[MP2869_PAGE_NUM];
4951
int max_phases[MP2869_PAGE_NUM];
5052
enum chips chip_id;
5153
};
@@ -54,79 +56,7 @@ struct mp2869_data {
5456
#define MAX_LIN_MANTISSA (1023 * 1000)
5557
#define MIN_LIN_MANTISSA (511 * 1000)
5658

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);
11159

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-
*/
13060

13161
// some values are SMBus LINEAR11 data which need a conversion
13262
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,
14777
ret = pmbus_read_word_data(client, page, phase, reg);
14878

14979
/* 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-
}
80+
ret = (ret*1000) / data->vout_gain[page];
15981

16082
return ret;
16183
}
16284

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);
17085

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];
189-
190-
return ret;
191-
}
19286

19387
static int
19488
mp2869_read_word_data(struct i2c_client *client, int page,
@@ -202,12 +96,7 @@ mp2869_read_word_data(struct i2c_client *client, int page,
20296
case PMBUS_READ_VOUT:
20397
ret = mp2869_read_vout(client, data, page, phase, reg);
20498
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;
99+
211100
default:
212101
return -ENODATA;
213102
}
@@ -227,134 +116,63 @@ mp2869_read_byte_data(struct i2c_client *client, int page, int reg)
227116
}
228117
}
229118

119+
120+
230121
static int
231-
mp2869_current_iin_gain_get(struct i2c_client *client,
122+
mp2869_voltage_vout_gain_get(struct i2c_client *client,
232123
struct mp2869_data *data)
233124
{
234-
int curr_gain, ret;
235-
236-
//Curr gain IIN1
125+
int vout_gain, ret;
126+
//Voltage gain VOUT1
237127
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
238128
if(ret < 0)
239129
return ret;
240130

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;
131+
ret = i2c_smbus_read_word_data(client,MP2869_MFR_VOUT_SCALE_LOOP);
132+
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP ret =%d\n",ret);
133+
134+
//VOUT1 scale bit is 29h page0 bit[12:10]
135+
ret = ret & GENMASK(12,10);
136+
ret = ret >> 10;
247137

248138
switch (ret) {
249139
case 0:
250-
curr_gain = 8;
140+
vout_gain = 160;
251141
break;
252142
case 1:
253-
curr_gain = 256;
143+
vout_gain = 200;
254144
break;
255145
case 2:
256-
curr_gain = 128;
146+
vout_gain = 400;
257147
break;
258148
case 3:
259-
curr_gain = 64;
149+
vout_gain = 500;
260150
break;
261151
case 4:
262-
curr_gain = 32;
152+
vout_gain = 1000;
263153
break;
264154
case 5:
265-
curr_gain = 16;
155+
vout_gain = 256;
266156
break;
267157
case 6:
268-
curr_gain = 8;
158+
vout_gain = 512;
269159
break;
270160
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;
161+
vout_gain = 1024;
324162
break;
325-
case 6:
326-
curr_gain = 1;
327-
break;
328163
default:
329-
printk("error get iin_gain in MP2869_IIN_SCALE_BIT_R1\n");
164+
printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
330165
break;
331166
}
167+
data->vout_gain[0] = vout_gain;
332168

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);
169+
//Voltage gain VOUT2
170+
ret = i2c_smbus_write_byte_data(client, PMBUS_PAGE, 1);
353171
if(ret < 0)
354-
return ret;
172+
return ret;
355173

356174
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);
175+
printk("mp2869_voltage_vout_gain_get MP2869_MFR_VOUT_SCALE_LOOP_R2 ret =%d\n",ret);
358176

359177
//VOUT1 scale bit is 29h page0 bit[12:10]
360178
ret = ret & GENMASK(12,10);
@@ -386,23 +204,9 @@ mp2869_voltage_vout_gain_get(struct i2c_client *client,
386204
vout_gain = 1024;
387205
break;
388206
default:
389-
printk("error get iin_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
207+
printk("error get vout_gain in MP2869_MFR_VOUT_SCALE_LOOP\n");
390208
break;
391209
}
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-
406210
data->vout_gain[1] = vout_gain;
407211

408212
//zsjadd test
@@ -421,8 +225,8 @@ static struct pmbus_driver_info mp2869_info = {
421225
.format[PSC_VOLTAGE_IN] = linear,
422226
.format[PSC_VOLTAGE_OUT] = direct,
423227
.format[PSC_TEMPERATURE] = linear,
424-
.format[PSC_CURRENT_IN] = direct,
425-
.format[PSC_CURRENT_OUT] = direct,
228+
.format[PSC_CURRENT_IN] = linear,
229+
.format[PSC_CURRENT_OUT] = linear,
426230
.format[PSC_POWER] = linear,
427231
.m[PSC_VOLTAGE_OUT] = 1,
428232
.R[PSC_VOLTAGE_OUT] = 3,
@@ -432,8 +236,7 @@ static struct pmbus_driver_info mp2869_info = {
432236
PMBUS_HAVE_PIN ,
433237
.func[1] = PMBUS_HAVE_VIN | PMBUS_HAVE_VOUT |
434238
PMBUS_HAVE_IIN | PMBUS_HAVE_IOUT |
435-
PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT |
436-
PMBUS_HAVE_PIN ,
239+
PMBUS_HAVE_TEMP | PMBUS_HAVE_POUT ,
437240
.read_byte_data = mp2869_read_byte_data,
438241
.read_word_data = mp2869_read_word_data,
439242
};
@@ -457,20 +260,10 @@ static int mp2869_probe(struct i2c_client *client)
457260
memcpy(&data->info, &mp2869_info, sizeof(*info));
458261
info = &data->info;
459262

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-
470263
/* Get Vout stage. */
471264
ret = mp2869_voltage_vout_gain_get(client, data);
472265
if (ret)
473-
return ret;
266+
return ret;
474267

475268
i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
476269

@@ -498,4 +291,4 @@ module_i2c_driver(mp2869_driver);
498291
MODULE_AUTHOR("Shaojie Zhang");
499292
MODULE_DESCRIPTION("PMBus driver for MPS MP2869/MP29608 device");
500293
MODULE_LICENSE("GPL");
501-
MODULE_IMPORT_NS(PMBUS);
294+
MODULE_IMPORT_NS(PMBUS);

0 commit comments

Comments
 (0)