Skip to content

Commit c02e464

Browse files
vadimp-nvidiagroeck
authored andcommitted
hwmon: (mlxreg-fan) Separate methods of fan setting coming from different subsystems
Distinct between fan speed setting request coming for hwmon and thermal subsystems. There are fields 'last_hwmon_state' and 'last_thermal_state' in the structure 'mlxreg_fan_pwm', which respectively store the cooling state set by the 'hwmon' and 'thermal' subsystem. The purpose is to make arbitration of fan speed setting. For example, if fan speed required to be not lower than some limit, such setting is to be performed through 'hwmon' subsystem, thus 'thermal' subsystem will not set fan below this limit. Currently, the 'last_thermal_state' is also be updated by 'hwmon' causing cooling state to never be set to a lower value. Eliminate update of 'last_thermal_state', when request is coming from 'hwmon' subsystem. Fixes: da74944 ("hwmon: (mlxreg-fan) Use pwm attribute for setting fan speed low limit") Signed-off-by: Vadim Pasternak <vadimp@nvidia.com> Link: https://lore.kernel.org/r/20250113084859.27064-2-vadimp@nvidia.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 5798b62 commit c02e464

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

drivers/hwmon/mlxreg-fan.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ struct mlxreg_fan {
113113
int divider;
114114
};
115115

116-
static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
117-
unsigned long state);
116+
static int _mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
117+
unsigned long state, bool thermal);
118118

119119
static int
120120
mlxreg_fan_read(struct device *dev, enum hwmon_sensor_types type, u32 attr,
@@ -224,8 +224,9 @@ mlxreg_fan_write(struct device *dev, enum hwmon_sensor_types type, u32 attr,
224224
* last thermal state.
225225
*/
226226
if (pwm->last_hwmon_state >= pwm->last_thermal_state)
227-
return mlxreg_fan_set_cur_state(pwm->cdev,
228-
pwm->last_hwmon_state);
227+
return _mlxreg_fan_set_cur_state(pwm->cdev,
228+
pwm->last_hwmon_state,
229+
false);
229230
return 0;
230231
}
231232
return regmap_write(fan->regmap, pwm->reg, val);
@@ -357,9 +358,8 @@ static int mlxreg_fan_get_cur_state(struct thermal_cooling_device *cdev,
357358
return 0;
358359
}
359360

360-
static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
361-
unsigned long state)
362-
361+
static int _mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
362+
unsigned long state, bool thermal)
363363
{
364364
struct mlxreg_fan_pwm *pwm = cdev->devdata;
365365
struct mlxreg_fan *fan = pwm->fan;
@@ -369,7 +369,8 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
369369
return -EINVAL;
370370

371371
/* Save thermal state. */
372-
pwm->last_thermal_state = state;
372+
if (thermal)
373+
pwm->last_thermal_state = state;
373374

374375
state = max_t(unsigned long, state, pwm->last_hwmon_state);
375376
err = regmap_write(fan->regmap, pwm->reg,
@@ -381,6 +382,13 @@ static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
381382
return 0;
382383
}
383384

385+
static int mlxreg_fan_set_cur_state(struct thermal_cooling_device *cdev,
386+
unsigned long state)
387+
388+
{
389+
return _mlxreg_fan_set_cur_state(cdev, state, true);
390+
}
391+
384392
static const struct thermal_cooling_device_ops mlxreg_fan_cooling_ops = {
385393
.get_max_state = mlxreg_fan_get_max_state,
386394
.get_cur_state = mlxreg_fan_get_cur_state,

0 commit comments

Comments
 (0)