Skip to content

Commit 805a5bd

Browse files
committed
hwmon: (pmbus) Mark lowest/average/highest/rated attributes as read-only
Writing those attributes is not supported, so mark them as read-only. Prior to this change, attempts to write into these attributes returned an error. Mark boolean fields in struct pmbus_limit_attr and in struct pmbus_sensor_attr as bit fields to reduce configuration data size. The data is scanned only while probing, so performance is not a concern. Fixes: 6f183d3 ("hwmon: (pmbus) Add support for peak attributes") Reviewed-by: Sanman Pradhan <[email protected]> Signed-off-by: Guenter Roeck <[email protected]>
1 parent bf08749 commit 805a5bd

1 file changed

Lines changed: 42 additions & 6 deletions

File tree

drivers/hwmon/pmbus/pmbus_core.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1495,8 +1495,9 @@ static int pmbus_add_label(struct pmbus_data *data,
14951495
struct pmbus_limit_attr {
14961496
u16 reg; /* Limit register */
14971497
u16 sbit; /* Alarm attribute status bit */
1498-
bool update; /* True if register needs updates */
1499-
bool low; /* True if low limit; for limits with compare functions only */
1498+
bool readonly:1; /* True if the attribute is read-only */
1499+
bool update:1; /* True if register needs updates */
1500+
bool low:1; /* True if low limit; for limits with compare functions only */
15001501
const char *attr; /* Attribute name */
15011502
const char *alarm; /* Alarm attribute name */
15021503
};
@@ -1511,9 +1512,9 @@ struct pmbus_sensor_attr {
15111512
u8 nlimit; /* # of limit registers */
15121513
enum pmbus_sensor_classes class;/* sensor class */
15131514
const char *label; /* sensor label */
1514-
bool paged; /* true if paged sensor */
1515-
bool update; /* true if update needed */
1516-
bool compare; /* true if compare function needed */
1515+
bool paged:1; /* true if paged sensor */
1516+
bool update:1; /* true if update needed */
1517+
bool compare:1; /* true if compare function needed */
15171518
u32 func; /* sensor mask */
15181519
u32 sfunc; /* sensor status mask */
15191520
int sreg; /* status register */
@@ -1544,7 +1545,7 @@ static int pmbus_add_limit_attrs(struct i2c_client *client,
15441545
curr = pmbus_add_sensor(data, name, l->attr, index,
15451546
page, 0xff, l->reg, attr->class,
15461547
attr->update || l->update,
1547-
false, true);
1548+
l->readonly, true);
15481549
if (!curr)
15491550
return -ENOMEM;
15501551
if (l->sbit && (info->func[page] & attr->sfunc)) {
@@ -1707,23 +1708,28 @@ static const struct pmbus_limit_attr vin_limit_attrs[] = {
17071708
}, {
17081709
.reg = PMBUS_VIRT_READ_VIN_AVG,
17091710
.update = true,
1711+
.readonly = true,
17101712
.attr = "average",
17111713
}, {
17121714
.reg = PMBUS_VIRT_READ_VIN_MIN,
17131715
.update = true,
1716+
.readonly = true,
17141717
.attr = "lowest",
17151718
}, {
17161719
.reg = PMBUS_VIRT_READ_VIN_MAX,
17171720
.update = true,
1721+
.readonly = true,
17181722
.attr = "highest",
17191723
}, {
17201724
.reg = PMBUS_VIRT_RESET_VIN_HISTORY,
17211725
.attr = "reset_history",
17221726
}, {
17231727
.reg = PMBUS_MFR_VIN_MIN,
1728+
.readonly = true,
17241729
.attr = "rated_min",
17251730
}, {
17261731
.reg = PMBUS_MFR_VIN_MAX,
1732+
.readonly = true,
17271733
.attr = "rated_max",
17281734
},
17291735
};
@@ -1776,23 +1782,28 @@ static const struct pmbus_limit_attr vout_limit_attrs[] = {
17761782
}, {
17771783
.reg = PMBUS_VIRT_READ_VOUT_AVG,
17781784
.update = true,
1785+
.readonly = true,
17791786
.attr = "average",
17801787
}, {
17811788
.reg = PMBUS_VIRT_READ_VOUT_MIN,
17821789
.update = true,
1790+
.readonly = true,
17831791
.attr = "lowest",
17841792
}, {
17851793
.reg = PMBUS_VIRT_READ_VOUT_MAX,
17861794
.update = true,
1795+
.readonly = true,
17871796
.attr = "highest",
17881797
}, {
17891798
.reg = PMBUS_VIRT_RESET_VOUT_HISTORY,
17901799
.attr = "reset_history",
17911800
}, {
17921801
.reg = PMBUS_MFR_VOUT_MIN,
1802+
.readonly = true,
17931803
.attr = "rated_min",
17941804
}, {
17951805
.reg = PMBUS_MFR_VOUT_MAX,
1806+
.readonly = true,
17961807
.attr = "rated_max",
17971808
},
17981809
};
@@ -1852,20 +1863,24 @@ static const struct pmbus_limit_attr iin_limit_attrs[] = {
18521863
}, {
18531864
.reg = PMBUS_VIRT_READ_IIN_AVG,
18541865
.update = true,
1866+
.readonly = true,
18551867
.attr = "average",
18561868
}, {
18571869
.reg = PMBUS_VIRT_READ_IIN_MIN,
18581870
.update = true,
1871+
.readonly = true,
18591872
.attr = "lowest",
18601873
}, {
18611874
.reg = PMBUS_VIRT_READ_IIN_MAX,
18621875
.update = true,
1876+
.readonly = true,
18631877
.attr = "highest",
18641878
}, {
18651879
.reg = PMBUS_VIRT_RESET_IIN_HISTORY,
18661880
.attr = "reset_history",
18671881
}, {
18681882
.reg = PMBUS_MFR_IIN_MAX,
1883+
.readonly = true,
18691884
.attr = "rated_max",
18701885
},
18711886
};
@@ -1889,20 +1904,24 @@ static const struct pmbus_limit_attr iout_limit_attrs[] = {
18891904
}, {
18901905
.reg = PMBUS_VIRT_READ_IOUT_AVG,
18911906
.update = true,
1907+
.readonly = true,
18921908
.attr = "average",
18931909
}, {
18941910
.reg = PMBUS_VIRT_READ_IOUT_MIN,
18951911
.update = true,
1912+
.readonly = true,
18961913
.attr = "lowest",
18971914
}, {
18981915
.reg = PMBUS_VIRT_READ_IOUT_MAX,
18991916
.update = true,
1917+
.readonly = true,
19001918
.attr = "highest",
19011919
}, {
19021920
.reg = PMBUS_VIRT_RESET_IOUT_HISTORY,
19031921
.attr = "reset_history",
19041922
}, {
19051923
.reg = PMBUS_MFR_IOUT_MAX,
1924+
.readonly = true,
19061925
.attr = "rated_max",
19071926
},
19081927
};
@@ -1943,20 +1962,24 @@ static const struct pmbus_limit_attr pin_limit_attrs[] = {
19431962
}, {
19441963
.reg = PMBUS_VIRT_READ_PIN_AVG,
19451964
.update = true,
1965+
.readonly = true,
19461966
.attr = "average",
19471967
}, {
19481968
.reg = PMBUS_VIRT_READ_PIN_MIN,
19491969
.update = true,
1970+
.readonly = true,
19501971
.attr = "input_lowest",
19511972
}, {
19521973
.reg = PMBUS_VIRT_READ_PIN_MAX,
19531974
.update = true,
1975+
.readonly = true,
19541976
.attr = "input_highest",
19551977
}, {
19561978
.reg = PMBUS_VIRT_RESET_PIN_HISTORY,
19571979
.attr = "reset_history",
19581980
}, {
19591981
.reg = PMBUS_MFR_PIN_MAX,
1982+
.readonly = true,
19601983
.attr = "rated_max",
19611984
},
19621985
};
@@ -1980,20 +2003,24 @@ static const struct pmbus_limit_attr pout_limit_attrs[] = {
19802003
}, {
19812004
.reg = PMBUS_VIRT_READ_POUT_AVG,
19822005
.update = true,
2006+
.readonly = true,
19832007
.attr = "average",
19842008
}, {
19852009
.reg = PMBUS_VIRT_READ_POUT_MIN,
19862010
.update = true,
2011+
.readonly = true,
19872012
.attr = "input_lowest",
19882013
}, {
19892014
.reg = PMBUS_VIRT_READ_POUT_MAX,
19902015
.update = true,
2016+
.readonly = true,
19912017
.attr = "input_highest",
19922018
}, {
19932019
.reg = PMBUS_VIRT_RESET_POUT_HISTORY,
19942020
.attr = "reset_history",
19952021
}, {
19962022
.reg = PMBUS_MFR_POUT_MAX,
2023+
.readonly = true,
19972024
.attr = "rated_max",
19982025
},
19992026
};
@@ -2049,18 +2076,22 @@ static const struct pmbus_limit_attr temp_limit_attrs[] = {
20492076
.sbit = PB_TEMP_OT_FAULT,
20502077
}, {
20512078
.reg = PMBUS_VIRT_READ_TEMP_MIN,
2079+
.readonly = true,
20522080
.attr = "lowest",
20532081
}, {
20542082
.reg = PMBUS_VIRT_READ_TEMP_AVG,
2083+
.readonly = true,
20552084
.attr = "average",
20562085
}, {
20572086
.reg = PMBUS_VIRT_READ_TEMP_MAX,
2087+
.readonly = true,
20582088
.attr = "highest",
20592089
}, {
20602090
.reg = PMBUS_VIRT_RESET_TEMP_HISTORY,
20612091
.attr = "reset_history",
20622092
}, {
20632093
.reg = PMBUS_MFR_MAX_TEMP_1,
2094+
.readonly = true,
20642095
.attr = "rated_max",
20652096
},
20662097
};
@@ -2090,18 +2121,22 @@ static const struct pmbus_limit_attr temp_limit_attrs2[] = {
20902121
.sbit = PB_TEMP_OT_FAULT,
20912122
}, {
20922123
.reg = PMBUS_VIRT_READ_TEMP2_MIN,
2124+
.readonly = true,
20932125
.attr = "lowest",
20942126
}, {
20952127
.reg = PMBUS_VIRT_READ_TEMP2_AVG,
2128+
.readonly = true,
20962129
.attr = "average",
20972130
}, {
20982131
.reg = PMBUS_VIRT_READ_TEMP2_MAX,
2132+
.readonly = true,
20992133
.attr = "highest",
21002134
}, {
21012135
.reg = PMBUS_VIRT_RESET_TEMP2_HISTORY,
21022136
.attr = "reset_history",
21032137
}, {
21042138
.reg = PMBUS_MFR_MAX_TEMP_2,
2139+
.readonly = true,
21052140
.attr = "rated_max",
21062141
},
21072142
};
@@ -2131,6 +2166,7 @@ static const struct pmbus_limit_attr temp_limit_attrs3[] = {
21312166
.sbit = PB_TEMP_OT_FAULT,
21322167
}, {
21332168
.reg = PMBUS_MFR_MAX_TEMP_3,
2169+
.readonly = true,
21342170
.attr = "rated_max",
21352171
},
21362172
};

0 commit comments

Comments
 (0)