Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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: 2d7a548a3eff ("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>

authored by

Loic Prylli and committed by
Guenter Roeck
1168491e 54be6c6c

+7
+7
drivers/hwmon/aspeed-pwm-tacho.c
··· 195 195 u8 fan_tach_ch_source[MAX_ASPEED_FAN_TACH_CHANNELS]; 196 196 struct aspeed_cooling_device *cdev[8]; 197 197 const struct attribute_group *groups[3]; 198 + /* protects access to shared ASPEED_PTCR_RESULT */ 199 + struct mutex tach_lock; 198 200 }; 199 201 200 202 enum type { TYPEM, TYPEN, TYPEO }; ··· 531 529 u8 fan_tach_ch_source, type, mode, both; 532 530 int ret; 533 531 532 + mutex_lock(&priv->tach_lock); 533 + 534 534 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); 535 535 regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); 536 536 ··· 549 545 (val & RESULT_STATUS_MASK), 550 546 ASPEED_RPM_STATUS_SLEEP_USEC, 551 547 usec); 548 + 549 + mutex_unlock(&priv->tach_lock); 552 550 553 551 /* return -ETIMEDOUT if we didn't get an answer. */ 554 552 if (ret) ··· 921 915 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); 922 916 if (!priv) 923 917 return -ENOMEM; 918 + mutex_init(&priv->tach_lock); 924 919 priv->regmap = devm_regmap_init(dev, NULL, (__force void *)regs, 925 920 &aspeed_pwm_tacho_regmap_config); 926 921 if (IS_ERR(priv->regmap))