diff --git a/drivers/hwmon/npcm750-pwm-fan.c b/drivers/hwmon/npcm750-pwm-fan.c index d24242eea95e..9af3bd0b6fb6 100644 --- a/drivers/hwmon/npcm750-pwm-fan.c +++ b/drivers/hwmon/npcm750-pwm-fan.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -197,6 +198,8 @@ struct npcm7xx_pwm_fan_data { int pwm_modules; struct clk *pwm_clk; struct clk *fan_clk; + /* serializes CMR/CR updates from hwmon and the cooling devices */ + struct mutex pwm_lock[NPCM7XX_PWM_MAX_MODULES]; spinlock_t fan_lock[NPCM7XX_FAN_MAX_MODULE]; int fan_irq[NPCM7XX_FAN_MAX_MODULE]; bool pwm_present[NPCM7XX_PWM_MAX_CHN_NUM]; @@ -216,6 +219,8 @@ static int npcm7xx_pwm_config_set(struct npcm7xx_pwm_fan_data *data, u32 module = (channel / NPCM7XX_PWM_MAX_CHN_NUM_IN_A_MODULE); u32 tmp_buf, ctrl_en_bit, env_bit; + guard(mutex)(&data->pwm_lock[module]); + /* * Config PWM Comparator register for setting duty cycle */ @@ -986,6 +991,12 @@ static int npcm7xx_pwm_fan_probe(struct platform_device *pdev) output_freq = npcm7xx_pwm_init(data); npcm7xx_fan_init(data); + for (i = 0; i < ARRAY_SIZE(data->pwm_lock); i++) { + ret = devm_mutex_init(dev, &data->pwm_lock[i]); + if (ret) + return ret; + } + for (i = 0; i < NPCM7XX_FAN_MAX_MODULE; i++) { spin_lock_init(&data->fan_lock[i]);