Skip to content

Commit 1168491

Browse files
lprylligroeck
authored andcommitted
hwmon: (aspeed-pwm-tacho) mutex for tach reading
the ASPEED_PTCR_RESULT Register can only hold the result for a single fan input. Adding a mutex to protect the register until the reading is done. Signed-off-by: Loic Prylli <lprylli@netflix.com> Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com> Fixes: 2d7a548 ("drivers: hwmon: Support for ASPEED PWM/Fan tach") Link: https://lore.kernel.org/r/121d888762a1232ef403cf35230ccf7b3887083a.1699007401.git.alexander.hansen@9elements.com Signed-off-by: Guenter Roeck <linux@roeck-us.net>
1 parent 54be6c6 commit 1168491

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

drivers/hwmon/aspeed-pwm-tacho.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ struct aspeed_pwm_tacho_data {
195195
u8 fan_tach_ch_source[MAX_ASPEED_FAN_TACH_CHANNELS];
196196
struct aspeed_cooling_device *cdev[8];
197197
const struct attribute_group *groups[3];
198+
/* protects access to shared ASPEED_PTCR_RESULT */
199+
struct mutex tach_lock;
198200
};
199201

200202
enum type { TYPEM, TYPEN, TYPEO };
@@ -529,6 +531,8 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
529531
u8 fan_tach_ch_source, type, mode, both;
530532
int ret;
531533

534+
mutex_lock(&priv->tach_lock);
535+
532536
regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0);
533537
regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch);
534538

@@ -546,6 +550,8 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
546550
ASPEED_RPM_STATUS_SLEEP_USEC,
547551
usec);
548552

553+
mutex_unlock(&priv->tach_lock);
554+
549555
/* return -ETIMEDOUT if we didn't get an answer. */
550556
if (ret)
551557
return ret;
@@ -915,6 +921,7 @@ static int aspeed_pwm_tacho_probe(struct platform_device *pdev)
915921
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
916922
if (!priv)
917923
return -ENOMEM;
924+
mutex_init(&priv->tach_lock);
918925
priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs,
919926
&aspeed_pwm_tacho_regmap_config);
920927
if (IS_ERR(priv->regmap))

0 commit comments

Comments
 (0)