Skip to content

Commit 08f411b

Browse files
sammjgroeck
authored andcommitted
hwmon: (pmbus/ir35221) Remove unnecessary scaling
The ir35221 datasheet describes specific scaling factors for a number of commands which the current driver applies when reading. However now that the ir35221 has been tested on machines with more easily verifiable readings these descriptions have turned out to be superfluous and reading each command according to the linear format is sufficient. Signed-off-by: Samuel Mendoza-Jonas <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent abe6c3b commit 08f411b

File tree

1 file changed

+0
-189
lines changed

1 file changed

+0
-189
lines changed

drivers/hwmon/pmbus/ir35221.c

Lines changed: 0 additions & 189 deletions
Original file line numberDiff line numberDiff line change
@@ -25,178 +25,26 @@
2525
#define IR35221_MFR_IOUT_VALLEY 0xcb
2626
#define IR35221_MFR_TEMP_VALLEY 0xcc
2727

28-
static long ir35221_reg2data(int data, enum pmbus_sensor_classes class)
29-
{
30-
s16 exponent;
31-
s32 mantissa;
32-
long val;
33-
34-
/* We only modify LINEAR11 formats */
35-
exponent = ((s16)data) >> 11;
36-
mantissa = ((s16)((data & 0x7ff) << 5)) >> 5;
37-
38-
val = mantissa * 1000L;
39-
40-
/* scale result to micro-units for power sensors */
41-
if (class == PSC_POWER)
42-
val = val * 1000L;
43-
44-
if (exponent >= 0)
45-
val <<= exponent;
46-
else
47-
val >>= -exponent;
48-
49-
return val;
50-
}
51-
52-
#define MAX_MANTISSA (1023 * 1000)
53-
#define MIN_MANTISSA (511 * 1000)
54-
55-
static u16 ir35221_data2reg(long val, enum pmbus_sensor_classes class)
56-
{
57-
s16 exponent = 0, mantissa;
58-
bool negative = false;
59-
60-
if (val == 0)
61-
return 0;
62-
63-
if (val < 0) {
64-
negative = true;
65-
val = -val;
66-
}
67-
68-
/* Power is in uW. Convert to mW before converting. */
69-
if (class == PSC_POWER)
70-
val = DIV_ROUND_CLOSEST(val, 1000L);
71-
72-
/* Reduce large mantissa until it fits into 10 bit */
73-
while (val >= MAX_MANTISSA && exponent < 15) {
74-
exponent++;
75-
val >>= 1;
76-
}
77-
/* Increase small mantissa to improve precision */
78-
while (val < MIN_MANTISSA && exponent > -15) {
79-
exponent--;
80-
val <<= 1;
81-
}
82-
83-
/* Convert mantissa from milli-units to units */
84-
mantissa = DIV_ROUND_CLOSEST(val, 1000);
85-
86-
/* Ensure that resulting number is within range */
87-
if (mantissa > 0x3ff)
88-
mantissa = 0x3ff;
89-
90-
/* restore sign */
91-
if (negative)
92-
mantissa = -mantissa;
93-
94-
/* Convert to 5 bit exponent, 11 bit mantissa */
95-
return (mantissa & 0x7ff) | ((exponent << 11) & 0xf800);
96-
}
97-
98-
static u16 ir35221_scale_result(s16 data, int shift,
99-
enum pmbus_sensor_classes class)
100-
{
101-
long val;
102-
103-
val = ir35221_reg2data(data, class);
104-
105-
if (shift < 0)
106-
val >>= -shift;
107-
else
108-
val <<= shift;
109-
110-
return ir35221_data2reg(val, class);
111-
}
112-
11328
static int ir35221_read_word_data(struct i2c_client *client, int page, int reg)
11429
{
11530
int ret;
11631

11732
switch (reg) {
118-
case PMBUS_IOUT_OC_FAULT_LIMIT:
119-
case PMBUS_IOUT_OC_WARN_LIMIT:
120-
ret = pmbus_read_word_data(client, page, reg);
121-
if (ret < 0)
122-
break;
123-
ret = ir35221_scale_result(ret, 1, PSC_CURRENT_OUT);
124-
break;
125-
case PMBUS_VIN_OV_FAULT_LIMIT:
126-
case PMBUS_VIN_OV_WARN_LIMIT:
127-
case PMBUS_VIN_UV_WARN_LIMIT:
128-
ret = pmbus_read_word_data(client, page, reg);
129-
ret = ir35221_scale_result(ret, -4, PSC_VOLTAGE_IN);
130-
break;
131-
case PMBUS_IIN_OC_WARN_LIMIT:
132-
ret = pmbus_read_word_data(client, page, reg);
133-
if (ret < 0)
134-
break;
135-
ret = ir35221_scale_result(ret, -1, PSC_CURRENT_IN);
136-
break;
137-
case PMBUS_READ_VIN:
138-
ret = pmbus_read_word_data(client, page, PMBUS_READ_VIN);
139-
if (ret < 0)
140-
break;
141-
ret = ir35221_scale_result(ret, -5, PSC_VOLTAGE_IN);
142-
break;
143-
case PMBUS_READ_IIN:
144-
ret = pmbus_read_word_data(client, page, PMBUS_READ_IIN);
145-
if (ret < 0)
146-
break;
147-
if (page == 0)
148-
ret = ir35221_scale_result(ret, -4, PSC_CURRENT_IN);
149-
else
150-
ret = ir35221_scale_result(ret, -5, PSC_CURRENT_IN);
151-
break;
152-
case PMBUS_READ_POUT:
153-
ret = pmbus_read_word_data(client, page, PMBUS_READ_POUT);
154-
if (ret < 0)
155-
break;
156-
ret = ir35221_scale_result(ret, -1, PSC_POWER);
157-
break;
158-
case PMBUS_READ_PIN:
159-
ret = pmbus_read_word_data(client, page, PMBUS_READ_PIN);
160-
if (ret < 0)
161-
break;
162-
ret = ir35221_scale_result(ret, -1, PSC_POWER);
163-
break;
164-
case PMBUS_READ_IOUT:
165-
ret = pmbus_read_word_data(client, page, PMBUS_READ_IOUT);
166-
if (ret < 0)
167-
break;
168-
if (page == 0)
169-
ret = ir35221_scale_result(ret, -1, PSC_CURRENT_OUT);
170-
else
171-
ret = ir35221_scale_result(ret, -2, PSC_CURRENT_OUT);
172-
break;
17333
case PMBUS_VIRT_READ_VIN_MAX:
17434
ret = pmbus_read_word_data(client, page, IR35221_MFR_VIN_PEAK);
175-
if (ret < 0)
176-
break;
177-
ret = ir35221_scale_result(ret, -5, PSC_VOLTAGE_IN);
17835
break;
17936
case PMBUS_VIRT_READ_VOUT_MAX:
18037
ret = pmbus_read_word_data(client, page, IR35221_MFR_VOUT_PEAK);
18138
break;
18239
case PMBUS_VIRT_READ_IOUT_MAX:
18340
ret = pmbus_read_word_data(client, page, IR35221_MFR_IOUT_PEAK);
184-
if (ret < 0)
185-
break;
186-
if (page == 0)
187-
ret = ir35221_scale_result(ret, -1, PSC_CURRENT_IN);
188-
else
189-
ret = ir35221_scale_result(ret, -2, PSC_CURRENT_IN);
19041
break;
19142
case PMBUS_VIRT_READ_TEMP_MAX:
19243
ret = pmbus_read_word_data(client, page, IR35221_MFR_TEMP_PEAK);
19344
break;
19445
case PMBUS_VIRT_READ_VIN_MIN:
19546
ret = pmbus_read_word_data(client, page,
19647
IR35221_MFR_VIN_VALLEY);
197-
if (ret < 0)
198-
break;
199-
ret = ir35221_scale_result(ret, -5, PSC_VOLTAGE_IN);
20048
break;
20149
case PMBUS_VIRT_READ_VOUT_MIN:
20250
ret = pmbus_read_word_data(client, page,
@@ -205,12 +53,6 @@ static int ir35221_read_word_data(struct i2c_client *client, int page, int reg)
20553
case PMBUS_VIRT_READ_IOUT_MIN:
20654
ret = pmbus_read_word_data(client, page,
20755
IR35221_MFR_IOUT_VALLEY);
208-
if (ret < 0)
209-
break;
210-
if (page == 0)
211-
ret = ir35221_scale_result(ret, -1, PSC_CURRENT_IN);
212-
else
213-
ret = ir35221_scale_result(ret, -2, PSC_CURRENT_IN);
21456
break;
21557
case PMBUS_VIRT_READ_TEMP_MIN:
21658
ret = pmbus_read_word_data(client, page,
@@ -224,36 +66,6 @@ static int ir35221_read_word_data(struct i2c_client *client, int page, int reg)
22466
return ret;
22567
}
22668

227-
static int ir35221_write_word_data(struct i2c_client *client, int page, int reg,
228-
u16 word)
229-
{
230-
int ret;
231-
u16 val;
232-
233-
switch (reg) {
234-
case PMBUS_IOUT_OC_FAULT_LIMIT:
235-
case PMBUS_IOUT_OC_WARN_LIMIT:
236-
val = ir35221_scale_result(word, -1, PSC_CURRENT_OUT);
237-
ret = pmbus_write_word_data(client, page, reg, val);
238-
break;
239-
case PMBUS_VIN_OV_FAULT_LIMIT:
240-
case PMBUS_VIN_OV_WARN_LIMIT:
241-
case PMBUS_VIN_UV_WARN_LIMIT:
242-
val = ir35221_scale_result(word, 4, PSC_VOLTAGE_IN);
243-
ret = pmbus_write_word_data(client, page, reg, val);
244-
break;
245-
case PMBUS_IIN_OC_WARN_LIMIT:
246-
val = ir35221_scale_result(word, 1, PSC_CURRENT_IN);
247-
ret = pmbus_write_word_data(client, page, reg, val);
248-
break;
249-
default:
250-
ret = -ENODATA;
251-
break;
252-
}
253-
254-
return ret;
255-
}
256-
25769
static int ir35221_probe(struct i2c_client *client,
25870
const struct i2c_device_id *id)
25971
{
@@ -292,7 +104,6 @@ static int ir35221_probe(struct i2c_client *client,
292104
if (!info)
293105
return -ENOMEM;
294106

295-
info->write_word_data = ir35221_write_word_data;
296107
info->read_word_data = ir35221_read_word_data;
297108

298109
info->pages = 2;

0 commit comments

Comments
 (0)