Skip to content

Commit be762d8

Browse files
committed
Merge tag 'hwmon-for-v7.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging
Pull hwmon fixes from Guenter Roeck: - PMBus driver fixes: - Add mutex protection for regulator operations - Fix reading from "write-only" attributes - Mark lowest/average/highest/rated attributes as read-only - isl68137: Add mutex protection for AVS enable sysfs attributes - ina233: Fix error handling and sign extension when reading shunt voltage - adm1177: Fix sysfs ABI violation and current unit conversion - peci: Fix off-by-one in cputemp_is_visible(), and crit_hyst returning delta instead of absolute temperature * tag 'hwmon-for-v7.0-rc6' of git://git.kernel.org/pub/scm/linux/kernel/git/groeck/linux-staging: hwmon: (pmbus/core) Protect regulator operations with mutex hwmon: (pmbus) Introduce the concept of "write-only" attributes hwmon: (pmbus) Mark lowest/average/highest/rated attributes as read-only hwmon: (adm1177) fix sysfs ABI violation and current unit conversion hwmon: (peci/cputemp) Fix off-by-one in cputemp_is_visible() hwmon: (peci/cputemp) Fix crit_hyst returning delta instead of absolute temperature hwmon: (pmbus/isl68137) Add mutex protection for AVS enable sysfs attributes hwmon: (pmbus/ina233) Fix error handling and sign extension in shunt voltage read
2 parents afb54c1 + 754bd2b commit be762d8

7 files changed

Lines changed: 217 additions & 75 deletions

File tree

Documentation/hwmon/adm1177.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ for details.
2727
Sysfs entries
2828
-------------
2929

30-
The following attributes are supported. Current maxim attribute
30+
The following attributes are supported. Current maximum attribute
3131
is read-write, all other attributes are read-only.
3232

33-
in0_input Measured voltage in microvolts.
33+
in0_input Measured voltage in millivolts.
3434

35-
curr1_input Measured current in microamperes.
36-
curr1_max_alarm Overcurrent alarm in microamperes.
35+
curr1_input Measured current in milliamperes.
36+
curr1_max Overcurrent shutdown threshold in milliamperes.

Documentation/hwmon/peci-cputemp.rst

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ temp1_max Provides thermal control temperature of the CPU package
5151
temp1_crit Provides shutdown temperature of the CPU package which
5252
is also known as the maximum processor junction
5353
temperature, Tjmax or Tprochot.
54-
temp1_crit_hyst Provides the hysteresis value from Tcontrol to Tjmax of
55-
the CPU package.
54+
temp1_crit_hyst Provides the hysteresis temperature of the CPU
55+
package. Returns Tcontrol, the temperature at which
56+
the critical condition clears.
5657

5758
temp2_label "DTS"
5859
temp2_input Provides current temperature of the CPU package scaled
@@ -62,8 +63,9 @@ temp2_max Provides thermal control temperature of the CPU package
6263
temp2_crit Provides shutdown temperature of the CPU package which
6364
is also known as the maximum processor junction
6465
temperature, Tjmax or Tprochot.
65-
temp2_crit_hyst Provides the hysteresis value from Tcontrol to Tjmax of
66-
the CPU package.
66+
temp2_crit_hyst Provides the hysteresis temperature of the CPU
67+
package. Returns Tcontrol, the temperature at which
68+
the critical condition clears.
6769

6870
temp3_label "Tcontrol"
6971
temp3_input Provides current Tcontrol temperature of the CPU

drivers/hwmon/adm1177.c

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#include <linux/hwmon.h>
1111
#include <linux/i2c.h>
1212
#include <linux/init.h>
13+
#include <linux/math64.h>
14+
#include <linux/minmax.h>
1315
#include <linux/module.h>
1416
#include <linux/regulator/consumer.h>
1517

@@ -33,7 +35,7 @@
3335
struct adm1177_state {
3436
struct i2c_client *client;
3537
u32 r_sense_uohm;
36-
u32 alert_threshold_ua;
38+
u64 alert_threshold_ua;
3739
bool vrange_high;
3840
};
3941

@@ -48,7 +50,7 @@ static int adm1177_write_cmd(struct adm1177_state *st, u8 cmd)
4850
}
4951

5052
static int adm1177_write_alert_thr(struct adm1177_state *st,
51-
u32 alert_threshold_ua)
53+
u64 alert_threshold_ua)
5254
{
5355
u64 val;
5456
int ret;
@@ -91,8 +93,8 @@ static int adm1177_read(struct device *dev, enum hwmon_sensor_types type,
9193
*val = div_u64((105840000ull * dummy),
9294
4096 * st->r_sense_uohm);
9395
return 0;
94-
case hwmon_curr_max_alarm:
95-
*val = st->alert_threshold_ua;
96+
case hwmon_curr_max:
97+
*val = div_u64(st->alert_threshold_ua, 1000);
9698
return 0;
9799
default:
98100
return -EOPNOTSUPP;
@@ -126,9 +128,10 @@ static int adm1177_write(struct device *dev, enum hwmon_sensor_types type,
126128
switch (type) {
127129
case hwmon_curr:
128130
switch (attr) {
129-
case hwmon_curr_max_alarm:
130-
adm1177_write_alert_thr(st, val);
131-
return 0;
131+
case hwmon_curr_max:
132+
val = clamp_val(val, 0,
133+
div_u64(105840000ULL, st->r_sense_uohm));
134+
return adm1177_write_alert_thr(st, (u64)val * 1000);
132135
default:
133136
return -EOPNOTSUPP;
134137
}
@@ -156,7 +159,7 @@ static umode_t adm1177_is_visible(const void *data,
156159
if (st->r_sense_uohm)
157160
return 0444;
158161
return 0;
159-
case hwmon_curr_max_alarm:
162+
case hwmon_curr_max:
160163
if (st->r_sense_uohm)
161164
return 0644;
162165
return 0;
@@ -170,7 +173,7 @@ static umode_t adm1177_is_visible(const void *data,
170173

171174
static const struct hwmon_channel_info * const adm1177_info[] = {
172175
HWMON_CHANNEL_INFO(curr,
173-
HWMON_C_INPUT | HWMON_C_MAX_ALARM),
176+
HWMON_C_INPUT | HWMON_C_MAX),
174177
HWMON_CHANNEL_INFO(in,
175178
HWMON_I_INPUT),
176179
NULL
@@ -192,7 +195,8 @@ static int adm1177_probe(struct i2c_client *client)
192195
struct device *dev = &client->dev;
193196
struct device *hwmon_dev;
194197
struct adm1177_state *st;
195-
u32 alert_threshold_ua;
198+
u64 alert_threshold_ua;
199+
u32 prop;
196200
int ret;
197201

198202
st = devm_kzalloc(dev, sizeof(*st), GFP_KERNEL);
@@ -208,22 +212,26 @@ static int adm1177_probe(struct i2c_client *client)
208212
if (device_property_read_u32(dev, "shunt-resistor-micro-ohms",
209213
&st->r_sense_uohm))
210214
st->r_sense_uohm = 0;
211-
if (device_property_read_u32(dev, "adi,shutdown-threshold-microamp",
212-
&alert_threshold_ua)) {
213-
if (st->r_sense_uohm)
214-
/*
215-
* set maximum default value from datasheet based on
216-
* shunt-resistor
217-
*/
218-
alert_threshold_ua = div_u64(105840000000,
219-
st->r_sense_uohm);
220-
else
221-
alert_threshold_ua = 0;
215+
if (!device_property_read_u32(dev, "adi,shutdown-threshold-microamp",
216+
&prop)) {
217+
alert_threshold_ua = prop;
218+
} else if (st->r_sense_uohm) {
219+
/*
220+
* set maximum default value from datasheet based on
221+
* shunt-resistor
222+
*/
223+
alert_threshold_ua = div_u64(105840000000ULL,
224+
st->r_sense_uohm);
225+
} else {
226+
alert_threshold_ua = 0;
222227
}
223228
st->vrange_high = device_property_read_bool(dev,
224229
"adi,vrange-high-enable");
225-
if (alert_threshold_ua && st->r_sense_uohm)
226-
adm1177_write_alert_thr(st, alert_threshold_ua);
230+
if (alert_threshold_ua && st->r_sense_uohm) {
231+
ret = adm1177_write_alert_thr(st, alert_threshold_ua);
232+
if (ret)
233+
return ret;
234+
}
227235

228236
ret = adm1177_write_cmd(st, ADM1177_CMD_V_CONT |
229237
ADM1177_CMD_I_CONT |

drivers/hwmon/peci/cputemp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ static int get_temp_target(struct peci_cputemp *priv, enum peci_temp_target_type
131131
*val = priv->temp.target.tjmax;
132132
break;
133133
case crit_hyst_type:
134-
*val = priv->temp.target.tjmax - priv->temp.target.tcontrol;
134+
*val = priv->temp.target.tcontrol;
135135
break;
136136
default:
137137
ret = -EOPNOTSUPP;
@@ -319,7 +319,7 @@ static umode_t cputemp_is_visible(const void *data, enum hwmon_sensor_types type
319319
{
320320
const struct peci_cputemp *priv = data;
321321

322-
if (channel > CPUTEMP_CHANNEL_NUMS)
322+
if (channel >= CPUTEMP_CHANNEL_NUMS)
323323
return 0;
324324

325325
if (channel < channel_core)

drivers/hwmon/pmbus/ina233.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ static int ina233_read_word_data(struct i2c_client *client, int page,
7272

7373
/* Adjust returned value to match VIN coefficients */
7474
/* VIN: 1.25 mV VSHUNT: 2.5 uV LSB */
75-
ret = DIV_ROUND_CLOSEST(ret * 25, 12500);
75+
ret = clamp_val(DIV_ROUND_CLOSEST((s16)ret * 25, 12500),
76+
S16_MIN, S16_MAX) & 0xffff;
7677
break;
7778
default:
7879
ret = -ENODATA;

drivers/hwmon/pmbus/isl68137.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ static ssize_t isl68137_avs_enable_show_page(struct i2c_client *client,
9696
int page,
9797
char *buf)
9898
{
99-
int val = pmbus_read_byte_data(client, page, PMBUS_OPERATION);
99+
int val;
100+
101+
val = pmbus_lock_interruptible(client);
102+
if (val)
103+
return val;
104+
105+
val = pmbus_read_byte_data(client, page, PMBUS_OPERATION);
106+
107+
pmbus_unlock(client);
100108

101109
if (val < 0)
102110
return val;
@@ -118,6 +126,10 @@ static ssize_t isl68137_avs_enable_store_page(struct i2c_client *client,
118126

119127
op_val = result ? ISL68137_VOUT_AVS : 0;
120128

129+
rc = pmbus_lock_interruptible(client);
130+
if (rc)
131+
return rc;
132+
121133
/*
122134
* Writes to VOUT setpoint over AVSBus will persist after the VRM is
123135
* switched to PMBus control. Switching back to AVSBus control
@@ -129,17 +141,20 @@ static ssize_t isl68137_avs_enable_store_page(struct i2c_client *client,
129141
rc = pmbus_read_word_data(client, page, 0xff,
130142
PMBUS_VOUT_COMMAND);
131143
if (rc < 0)
132-
return rc;
144+
goto unlock;
133145

134146
rc = pmbus_write_word_data(client, page, PMBUS_VOUT_COMMAND,
135147
rc);
136148
if (rc < 0)
137-
return rc;
149+
goto unlock;
138150
}
139151

140152
rc = pmbus_update_byte_data(client, page, PMBUS_OPERATION,
141153
ISL68137_VOUT_AVS, op_val);
142154

155+
unlock:
156+
pmbus_unlock(client);
157+
143158
return (rc < 0) ? rc : count;
144159
}
145160

0 commit comments

Comments
 (0)