Skip to content

Commit bd7a455

Browse files
t-8chgroeck
authored andcommitted
hwmon: (cros_ec) Add support for fan target speed
Use EC_CMD_PWM_GET_FAN_TARGET_RPM to retrieve the target fan speed. The EC only supports this for the first fan. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Link: https://lore.kernel.org/r/20260118-cros_ec-hwmon-pwm-v2-2-77eb1709b031@weissschuh.net Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 18ccf48 commit bd7a455

2 files changed

Lines changed: 28 additions & 1 deletion

File tree

Documentation/hwmon/cros_ec_hwmon.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ Supported features
2929
Fan readings
3030
Always supported.
3131

32+
Fan target speed
33+
If supported by the EC.
34+
3235
Temperature readings
3336
Always supported.
3437

drivers/hwmon/cros_ec_hwmon.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,20 @@ static int cros_ec_hwmon_read_pwm_enable(struct cros_ec_device *cros_ec, u8 inde
8686
return 0;
8787
}
8888

89+
static int cros_ec_hwmon_read_fan_target(struct cros_ec_device *cros_ec, u16 *speed)
90+
{
91+
struct ec_response_pwm_get_fan_rpm resp;
92+
int ret;
93+
94+
ret = cros_ec_cmd(cros_ec, 0, EC_CMD_PWM_GET_FAN_TARGET_RPM,
95+
NULL, 0, &resp, sizeof(resp));
96+
if (ret < 0)
97+
return ret;
98+
99+
*speed = resp.rpm;
100+
return 0;
101+
}
102+
89103
static int cros_ec_hwmon_read_temp(struct cros_ec_device *cros_ec, u8 index, u8 *temp)
90104
{
91105
unsigned int offset;
@@ -143,6 +157,11 @@ static int cros_ec_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
143157
ret = cros_ec_hwmon_read_fan_speed(priv->cros_ec, channel, &speed);
144158
if (ret == 0)
145159
*val = cros_ec_hwmon_is_error_fan(speed);
160+
161+
} else if (attr == hwmon_fan_target) {
162+
ret = cros_ec_hwmon_read_fan_target(priv->cros_ec, &speed);
163+
if (ret == 0)
164+
*val = speed;
146165
}
147166
} else if (type == hwmon_pwm) {
148167
if (attr == hwmon_pwm_enable) {
@@ -259,8 +278,13 @@ static umode_t cros_ec_hwmon_is_visible(const void *data, enum hwmon_sensor_type
259278
u32 attr, int channel)
260279
{
261280
const struct cros_ec_hwmon_priv *priv = data;
281+
u16 speed;
262282

263283
if (type == hwmon_fan) {
284+
if (attr == hwmon_fan_target &&
285+
cros_ec_hwmon_read_fan_target(priv->cros_ec, &speed) == -EOPNOTSUPP)
286+
return 0;
287+
264288
if (priv->usable_fans & BIT(channel))
265289
return 0444;
266290
} else if (type == hwmon_pwm) {
@@ -277,7 +301,7 @@ static umode_t cros_ec_hwmon_is_visible(const void *data, enum hwmon_sensor_type
277301
static const struct hwmon_channel_info * const cros_ec_hwmon_info[] = {
278302
HWMON_CHANNEL_INFO(chip, HWMON_C_REGISTER_TZ),
279303
HWMON_CHANNEL_INFO(fan,
280-
HWMON_F_INPUT | HWMON_F_FAULT,
304+
HWMON_F_INPUT | HWMON_F_FAULT | HWMON_F_TARGET,
281305
HWMON_F_INPUT | HWMON_F_FAULT,
282306
HWMON_F_INPUT | HWMON_F_FAULT,
283307
HWMON_F_INPUT | HWMON_F_FAULT),

0 commit comments

Comments
 (0)