Skip to content

Commit 6f183d3

Browse files
author
Guenter Roeck
committed
hwmon: (pmbus) Add support for peak attributes
Most PMBus devices provide manufacturer specific commands to read low and/or high peak values for some or all of its sensors. To support providing those values as lowest/highest attributes to the user, introduce virtual PMBus commands. Those commands reside outside the normal command set and have to be implemented in device specific code, which map the virtual commands to device specific commands. Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com> Reviewed-by: Robert Coulson <robert.coulson@ericsson.com>
1 parent 0084e9f commit 6f183d3

2 files changed

Lines changed: 163 additions & 15 deletions

File tree

‎drivers/hwmon/pmbus/pmbus.h‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,42 @@
125125
#define PMBUS_MFR_DATE 0x9D
126126
#define PMBUS_MFR_SERIAL 0x9E
127127

128+
/*
129+
* Virtual registers.
130+
* Useful to support attributes which are not supported by standard PMBus
131+
* registers but exist as manufacturer specific registers on individual chips.
132+
* Must be mapped to real registers in device specific code.
133+
*
134+
* Semantics:
135+
* Virtual registers are all word size.
136+
* READ registers are read-only; writes are either ignored or return an error.
137+
* RESET registers are read/write. Reading returns zero (used for detection),
138+
* writing any value causes the associated history to be reset.
139+
*/
140+
#define PMBUS_VIRT_BASE 0x100
141+
#define PMBUS_VIRT_READ_TEMP_MIN (PMBUS_VIRT_BASE + 0)
142+
#define PMBUS_VIRT_READ_TEMP_MAX (PMBUS_VIRT_BASE + 1)
143+
#define PMBUS_VIRT_RESET_TEMP_HISTORY (PMBUS_VIRT_BASE + 2)
144+
#define PMBUS_VIRT_READ_VIN_AVG (PMBUS_VIRT_BASE + 3)
145+
#define PMBUS_VIRT_READ_VIN_MIN (PMBUS_VIRT_BASE + 4)
146+
#define PMBUS_VIRT_READ_VIN_MAX (PMBUS_VIRT_BASE + 5)
147+
#define PMBUS_VIRT_RESET_VIN_HISTORY (PMBUS_VIRT_BASE + 6)
148+
#define PMBUS_VIRT_READ_IIN_AVG (PMBUS_VIRT_BASE + 7)
149+
#define PMBUS_VIRT_READ_IIN_MIN (PMBUS_VIRT_BASE + 8)
150+
#define PMBUS_VIRT_READ_IIN_MAX (PMBUS_VIRT_BASE + 9)
151+
#define PMBUS_VIRT_RESET_IIN_HISTORY (PMBUS_VIRT_BASE + 10)
152+
#define PMBUS_VIRT_READ_PIN_AVG (PMBUS_VIRT_BASE + 11)
153+
#define PMBUS_VIRT_READ_PIN_MAX (PMBUS_VIRT_BASE + 12)
154+
#define PMBUS_VIRT_RESET_PIN_HISTORY (PMBUS_VIRT_BASE + 13)
155+
#define PMBUS_VIRT_READ_VOUT_AVG (PMBUS_VIRT_BASE + 14)
156+
#define PMBUS_VIRT_READ_VOUT_MIN (PMBUS_VIRT_BASE + 15)
157+
#define PMBUS_VIRT_READ_VOUT_MAX (PMBUS_VIRT_BASE + 16)
158+
#define PMBUS_VIRT_RESET_VOUT_HISTORY (PMBUS_VIRT_BASE + 17)
159+
#define PMBUS_VIRT_READ_IOUT_AVG (PMBUS_VIRT_BASE + 18)
160+
#define PMBUS_VIRT_READ_IOUT_MIN (PMBUS_VIRT_BASE + 19)
161+
#define PMBUS_VIRT_READ_IOUT_MAX (PMBUS_VIRT_BASE + 20)
162+
#define PMBUS_VIRT_RESET_IOUT_HISTORY (PMBUS_VIRT_BASE + 21)
163+
128164
/*
129165
* CAPABILITY
130166
*/

‎drivers/hwmon/pmbus/pmbus_core.c‎

Lines changed: 127 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,18 @@
3333
/*
3434
* Constants needed to determine number of sensors, booleans, and labels.
3535
*/
36-
#define PMBUS_MAX_INPUT_SENSORS 11 /* 6*volt, 3*curr, 2*power */
37-
#define PMBUS_VOUT_SENSORS_PER_PAGE 5 /* input, min, max, lcrit,
38-
crit */
39-
#define PMBUS_IOUT_SENSORS_PER_PAGE 4 /* input, min, max, crit */
36+
#define PMBUS_MAX_INPUT_SENSORS 22 /* 10*volt, 7*curr, 5*power */
37+
#define PMBUS_VOUT_SENSORS_PER_PAGE 9 /* input, min, max, lcrit,
38+
crit, lowest, highest, avg,
39+
reset */
40+
#define PMBUS_IOUT_SENSORS_PER_PAGE 8 /* input, min, max, crit,
41+
lowest, highest, avg,
42+
reset */
4043
#define PMBUS_POUT_SENSORS_PER_PAGE 4 /* input, cap, max, crit */
4144
#define PMBUS_MAX_SENSORS_PER_FAN 1 /* input */
42-
#define PMBUS_MAX_SENSORS_PER_TEMP 5 /* input, min, max, lcrit,
43-
crit */
45+
#define PMBUS_MAX_SENSORS_PER_TEMP 8 /* input, min, max, lcrit,
46+
crit, lowest, highest,
47+
reset */
4448

4549
#define PMBUS_MAX_INPUT_BOOLEANS 7 /* v: min_alarm, max_alarm,
4650
lcrit_alarm, crit_alarm;
@@ -80,7 +84,7 @@ struct pmbus_sensor {
8084
char name[PMBUS_NAME_SIZE]; /* sysfs sensor name */
8185
struct sensor_device_attribute attribute;
8286
u8 page; /* page number */
83-
u8 reg; /* register */
87+
u16 reg; /* register */
8488
enum pmbus_sensor_classes class; /* sensor class */
8589
bool update; /* runtime sensor update needed */
8690
int data; /* Sensor data.
@@ -237,6 +241,8 @@ static int _pmbus_read_word_data(struct i2c_client *client, int page, int reg)
237241
if (status != -ENODATA)
238242
return status;
239243
}
244+
if (reg >= PMBUS_VIRT_BASE)
245+
return -EINVAL;
240246
return pmbus_read_word_data(client, page, reg);
241247
}
242248

@@ -318,7 +324,7 @@ bool pmbus_check_word_register(struct i2c_client *client, int page, int reg)
318324
int rv;
319325
struct pmbus_data *data = i2c_get_clientdata(client);
320326

321-
rv = pmbus_read_word_data(client, page, reg);
327+
rv = _pmbus_read_word_data(client, page, reg);
322328
if (rv >= 0 && !(data->flags & PMBUS_SKIP_STATUS_CHECK))
323329
rv = pmbus_check_status_cml(client);
324330
pmbus_clear_fault_page(client, -1);
@@ -951,7 +957,8 @@ static void pmbus_find_max_attr(struct i2c_client *client,
951957
* and its associated alarm attribute.
952958
*/
953959
struct pmbus_limit_attr {
954-
u8 reg; /* Limit register */
960+
u16 reg; /* Limit register */
961+
bool update; /* True if register needs updates */
955962
const char *attr; /* Attribute name */
956963
const char *alarm; /* Alarm attribute name */
957964
u32 sbit; /* Alarm attribute status bit */
@@ -996,9 +1003,10 @@ static bool pmbus_add_limit_attrs(struct i2c_client *client,
9961003
if (pmbus_check_word_register(client, page, l->reg)) {
9971004
cindex = data->num_sensors;
9981005
pmbus_add_sensor(data, name, l->attr, index, page,
999-
l->reg, attr->class, attr->update,
1006+
l->reg, attr->class,
1007+
attr->update || l->update,
10001008
false);
1001-
if (info->func[page] & attr->sfunc) {
1009+
if (l->sbit && (info->func[page] & attr->sfunc)) {
10021010
if (attr->compare) {
10031011
pmbus_add_boolean_cmp(data, name,
10041012
l->alarm, index,
@@ -1094,6 +1102,21 @@ static const struct pmbus_limit_attr vin_limit_attrs[] = {
10941102
.attr = "crit",
10951103
.alarm = "crit_alarm",
10961104
.sbit = PB_VOLTAGE_OV_FAULT,
1105+
}, {
1106+
.reg = PMBUS_VIRT_READ_VIN_AVG,
1107+
.update = true,
1108+
.attr = "average",
1109+
}, {
1110+
.reg = PMBUS_VIRT_READ_VIN_MIN,
1111+
.update = true,
1112+
.attr = "lowest",
1113+
}, {
1114+
.reg = PMBUS_VIRT_READ_VIN_MAX,
1115+
.update = true,
1116+
.attr = "highest",
1117+
}, {
1118+
.reg = PMBUS_VIRT_RESET_VIN_HISTORY,
1119+
.attr = "reset_history",
10971120
},
10981121
};
10991122

@@ -1118,6 +1141,21 @@ static const struct pmbus_limit_attr vout_limit_attrs[] = {
11181141
.attr = "crit",
11191142
.alarm = "crit_alarm",
11201143
.sbit = PB_VOLTAGE_OV_FAULT,
1144+
}, {
1145+
.reg = PMBUS_VIRT_READ_VOUT_AVG,
1146+
.update = true,
1147+
.attr = "average",
1148+
}, {
1149+
.reg = PMBUS_VIRT_READ_VOUT_MIN,
1150+
.update = true,
1151+
.attr = "lowest",
1152+
}, {
1153+
.reg = PMBUS_VIRT_READ_VOUT_MAX,
1154+
.update = true,
1155+
.attr = "highest",
1156+
}, {
1157+
.reg = PMBUS_VIRT_RESET_VOUT_HISTORY,
1158+
.attr = "reset_history",
11211159
}
11221160
};
11231161

@@ -1164,6 +1202,21 @@ static const struct pmbus_limit_attr iin_limit_attrs[] = {
11641202
.attr = "crit",
11651203
.alarm = "crit_alarm",
11661204
.sbit = PB_IIN_OC_FAULT,
1205+
}, {
1206+
.reg = PMBUS_VIRT_READ_IIN_AVG,
1207+
.update = true,
1208+
.attr = "average",
1209+
}, {
1210+
.reg = PMBUS_VIRT_READ_IIN_MIN,
1211+
.update = true,
1212+
.attr = "lowest",
1213+
}, {
1214+
.reg = PMBUS_VIRT_READ_IIN_MAX,
1215+
.update = true,
1216+
.attr = "highest",
1217+
}, {
1218+
.reg = PMBUS_VIRT_RESET_IIN_HISTORY,
1219+
.attr = "reset_history",
11671220
}
11681221
};
11691222

@@ -1183,6 +1236,21 @@ static const struct pmbus_limit_attr iout_limit_attrs[] = {
11831236
.attr = "crit",
11841237
.alarm = "crit_alarm",
11851238
.sbit = PB_IOUT_OC_FAULT,
1239+
}, {
1240+
.reg = PMBUS_VIRT_READ_IOUT_AVG,
1241+
.update = true,
1242+
.attr = "average",
1243+
}, {
1244+
.reg = PMBUS_VIRT_READ_IOUT_MIN,
1245+
.update = true,
1246+
.attr = "lowest",
1247+
}, {
1248+
.reg = PMBUS_VIRT_READ_IOUT_MAX,
1249+
.update = true,
1250+
.attr = "highest",
1251+
}, {
1252+
.reg = PMBUS_VIRT_RESET_IOUT_HISTORY,
1253+
.attr = "reset_history",
11861254
}
11871255
};
11881256

@@ -1218,6 +1286,17 @@ static const struct pmbus_limit_attr pin_limit_attrs[] = {
12181286
.attr = "max",
12191287
.alarm = "alarm",
12201288
.sbit = PB_PIN_OP_WARNING,
1289+
}, {
1290+
.reg = PMBUS_VIRT_READ_PIN_AVG,
1291+
.update = true,
1292+
.attr = "average",
1293+
}, {
1294+
.reg = PMBUS_VIRT_READ_PIN_MAX,
1295+
.update = true,
1296+
.attr = "input_highest",
1297+
}, {
1298+
.reg = PMBUS_VIRT_RESET_PIN_HISTORY,
1299+
.attr = "reset_history",
12211300
}
12221301
};
12231302

@@ -1266,6 +1345,39 @@ static const struct pmbus_sensor_attr power_attributes[] = {
12661345
/* Temperature atributes */
12671346

12681347
static const struct pmbus_limit_attr temp_limit_attrs[] = {
1348+
{
1349+
.reg = PMBUS_UT_WARN_LIMIT,
1350+
.attr = "min",
1351+
.alarm = "min_alarm",
1352+
.sbit = PB_TEMP_UT_WARNING,
1353+
}, {
1354+
.reg = PMBUS_UT_FAULT_LIMIT,
1355+
.attr = "lcrit",
1356+
.alarm = "lcrit_alarm",
1357+
.sbit = PB_TEMP_UT_FAULT,
1358+
}, {
1359+
.reg = PMBUS_OT_WARN_LIMIT,
1360+
.attr = "max",
1361+
.alarm = "max_alarm",
1362+
.sbit = PB_TEMP_OT_WARNING,
1363+
}, {
1364+
.reg = PMBUS_OT_FAULT_LIMIT,
1365+
.attr = "crit",
1366+
.alarm = "crit_alarm",
1367+
.sbit = PB_TEMP_OT_FAULT,
1368+
}, {
1369+
.reg = PMBUS_VIRT_READ_TEMP_MIN,
1370+
.attr = "lowest",
1371+
}, {
1372+
.reg = PMBUS_VIRT_READ_TEMP_MAX,
1373+
.attr = "highest",
1374+
}, {
1375+
.reg = PMBUS_VIRT_RESET_TEMP_HISTORY,
1376+
.attr = "reset_history",
1377+
}
1378+
};
1379+
1380+
static const struct pmbus_limit_attr temp_limit_attrs23[] = {
12691381
{
12701382
.reg = PMBUS_UT_WARN_LIMIT,
12711383
.attr = "min",
@@ -1312,8 +1424,8 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
13121424
.sfunc = PMBUS_HAVE_STATUS_TEMP,
13131425
.sbase = PB_STATUS_TEMP_BASE,
13141426
.gbit = PB_STATUS_TEMPERATURE,
1315-
.limit = temp_limit_attrs,
1316-
.nlimit = ARRAY_SIZE(temp_limit_attrs),
1427+
.limit = temp_limit_attrs23,
1428+
.nlimit = ARRAY_SIZE(temp_limit_attrs23),
13171429
}, {
13181430
.reg = PMBUS_READ_TEMPERATURE_3,
13191431
.class = PSC_TEMPERATURE,
@@ -1324,8 +1436,8 @@ static const struct pmbus_sensor_attr temp_attributes[] = {
13241436
.sfunc = PMBUS_HAVE_STATUS_TEMP,
13251437
.sbase = PB_STATUS_TEMP_BASE,
13261438
.gbit = PB_STATUS_TEMPERATURE,
1327-
.limit = temp_limit_attrs,
1328-
.nlimit = ARRAY_SIZE(temp_limit_attrs),
1439+
.limit = temp_limit_attrs23,
1440+
.nlimit = ARRAY_SIZE(temp_limit_attrs23),
13291441
}
13301442
};
13311443

0 commit comments

Comments
 (0)