Skip to content

Commit cd65847

Browse files
committed
hwmon: (pmbus) Introduce the concept of "write-only" attributes
Attributes intended to clear sensor history are intended to be writeable only. Reading those attributes today results in reporting more or less random values. To avoid ABI surprises, have those attributes explicitly return 0 when reading. Fixes: 787c095 ("hwmon: (pmbus/core) Add support for rated attributes") Reviewed-by: Sanman Pradhan <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent 805a5bd commit cd65847

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,12 @@ static ssize_t pmbus_show_boolean(struct device *dev,
12091209
return sysfs_emit(buf, "%d\n", val);
12101210
}
12111211

1212+
static ssize_t pmbus_show_zero(struct device *dev,
1213+
struct device_attribute *devattr, char *buf)
1214+
{
1215+
return sysfs_emit(buf, "0\n");
1216+
}
1217+
12121218
static ssize_t pmbus_show_sensor(struct device *dev,
12131219
struct device_attribute *devattr, char *buf)
12141220
{
@@ -1407,7 +1413,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
14071413
int reg,
14081414
enum pmbus_sensor_classes class,
14091415
bool update, bool readonly,
1410-
bool convert)
1416+
bool writeonly, bool convert)
14111417
{
14121418
struct pmbus_sensor *sensor;
14131419
struct device_attribute *a;
@@ -1436,7 +1442,8 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
14361442
sensor->data = -ENODATA;
14371443
pmbus_dev_attr_init(a, sensor->name,
14381444
readonly ? 0444 : 0644,
1439-
pmbus_show_sensor, pmbus_set_sensor);
1445+
writeonly ? pmbus_show_zero : pmbus_show_sensor,
1446+
pmbus_set_sensor);
14401447

14411448
if (pmbus_add_attribute(data, &a->attr))
14421449
return NULL;
@@ -1496,6 +1503,7 @@ struct pmbus_limit_attr {
14961503
u16 reg; /* Limit register */
14971504
u16 sbit; /* Alarm attribute status bit */
14981505
bool readonly:1; /* True if the attribute is read-only */
1506+
bool writeonly:1; /* True if the attribute is write-only */
14991507
bool update:1; /* True if register needs updates */
15001508
bool low:1; /* True if low limit; for limits with compare functions only */
15011509
const char *attr; /* Attribute name */
@@ -1545,7 +1553,7 @@ static int pmbus_add_limit_attrs(struct i2c_client *client,
15451553
curr = pmbus_add_sensor(data, name, l->attr, index,
15461554
page, 0xff, l->reg, attr->class,
15471555
attr->update || l->update,
1548-
l->readonly, true);
1556+
l->readonly, l->writeonly, true);
15491557
if (!curr)
15501558
return -ENOMEM;
15511559
if (l->sbit && (info->func[page] & attr->sfunc)) {
@@ -1585,7 +1593,7 @@ static int pmbus_add_sensor_attrs_one(struct i2c_client *client,
15851593
return ret;
15861594
}
15871595
base = pmbus_add_sensor(data, name, "input", index, page, phase,
1588-
attr->reg, attr->class, true, true, true);
1596+
attr->reg, attr->class, true, true, false, true);
15891597
if (!base)
15901598
return -ENOMEM;
15911599
/* No limit and alarm attributes for phase specific sensors */
@@ -1722,6 +1730,7 @@ static const struct pmbus_limit_attr vin_limit_attrs[] = {
17221730
.attr = "highest",
17231731
}, {
17241732
.reg = PMBUS_VIRT_RESET_VIN_HISTORY,
1733+
.writeonly = true,
17251734
.attr = "reset_history",
17261735
}, {
17271736
.reg = PMBUS_MFR_VIN_MIN,
@@ -1796,6 +1805,7 @@ static const struct pmbus_limit_attr vout_limit_attrs[] = {
17961805
.attr = "highest",
17971806
}, {
17981807
.reg = PMBUS_VIRT_RESET_VOUT_HISTORY,
1808+
.writeonly = true,
17991809
.attr = "reset_history",
18001810
}, {
18011811
.reg = PMBUS_MFR_VOUT_MIN,
@@ -1877,6 +1887,7 @@ static const struct pmbus_limit_attr iin_limit_attrs[] = {
18771887
.attr = "highest",
18781888
}, {
18791889
.reg = PMBUS_VIRT_RESET_IIN_HISTORY,
1890+
.writeonly = true,
18801891
.attr = "reset_history",
18811892
}, {
18821893
.reg = PMBUS_MFR_IIN_MAX,
@@ -1918,6 +1929,7 @@ static const struct pmbus_limit_attr iout_limit_attrs[] = {
19181929
.attr = "highest",
19191930
}, {
19201931
.reg = PMBUS_VIRT_RESET_IOUT_HISTORY,
1932+
.writeonly = true,
19211933
.attr = "reset_history",
19221934
}, {
19231935
.reg = PMBUS_MFR_IOUT_MAX,
@@ -1976,6 +1988,7 @@ static const struct pmbus_limit_attr pin_limit_attrs[] = {
19761988
.attr = "input_highest",
19771989
}, {
19781990
.reg = PMBUS_VIRT_RESET_PIN_HISTORY,
1991+
.writeonly = true,
19791992
.attr = "reset_history",
19801993
}, {
19811994
.reg = PMBUS_MFR_PIN_MAX,
@@ -2017,6 +2030,7 @@ static const struct pmbus_limit_attr pout_limit_attrs[] = {
20172030
.attr = "input_highest",
20182031
}, {
20192032
.reg = PMBUS_VIRT_RESET_POUT_HISTORY,
2033+
.writeonly = true,
20202034
.attr = "reset_history",
20212035
}, {
20222036
.reg = PMBUS_MFR_POUT_MAX,
@@ -2088,6 +2102,7 @@ static const struct pmbus_limit_attr temp_limit_attrs[] = {
20882102
.attr = "highest",
20892103
}, {
20902104
.reg = PMBUS_VIRT_RESET_TEMP_HISTORY,
2105+
.writeonly = true,
20912106
.attr = "reset_history",
20922107
}, {
20932108
.reg = PMBUS_MFR_MAX_TEMP_1,
@@ -2133,6 +2148,7 @@ static const struct pmbus_limit_attr temp_limit_attrs2[] = {
21332148
.attr = "highest",
21342149
}, {
21352150
.reg = PMBUS_VIRT_RESET_TEMP2_HISTORY,
2151+
.writeonly = true,
21362152
.attr = "reset_history",
21372153
}, {
21382154
.reg = PMBUS_MFR_MAX_TEMP_2,
@@ -2250,7 +2266,7 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,
22502266

22512267
sensor = pmbus_add_sensor(data, "fan", "target", index, page,
22522268
0xff, PMBUS_VIRT_FAN_TARGET_1 + id, PSC_FAN,
2253-
false, false, true);
2269+
false, false, false, true);
22542270

22552271
if (!sensor)
22562272
return -ENOMEM;
@@ -2261,14 +2277,14 @@ static int pmbus_add_fan_ctrl(struct i2c_client *client,
22612277

22622278
sensor = pmbus_add_sensor(data, "pwm", NULL, index, page,
22632279
0xff, PMBUS_VIRT_PWM_1 + id, PSC_PWM,
2264-
false, false, true);
2280+
false, false, false, true);
22652281

22662282
if (!sensor)
22672283
return -ENOMEM;
22682284

22692285
sensor = pmbus_add_sensor(data, "pwm", "enable", index, page,
22702286
0xff, PMBUS_VIRT_PWM_ENABLE_1 + id, PSC_PWM,
2271-
true, false, false);
2287+
true, false, false, false);
22722288

22732289
if (!sensor)
22742290
return -ENOMEM;
@@ -2310,7 +2326,7 @@ static int pmbus_add_fan_attributes(struct i2c_client *client,
23102326

23112327
if (pmbus_add_sensor(data, "fan", "input", index,
23122328
page, 0xff, pmbus_fan_registers[f],
2313-
PSC_FAN, true, true, true) == NULL)
2329+
PSC_FAN, true, true, false, true) == NULL)
23142330
return -ENOMEM;
23152331

23162332
/* Fan control */

0 commit comments

Comments
 (0)