aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/aspeed-pwm-tacho.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/aspeed-pwm-tacho.c')
-rw-r--r--drivers/hwmon/aspeed-pwm-tacho.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c
index 48403a2115be..12b716b70ead 100644
--- a/drivers/hwmon/aspeed-pwm-tacho.c
+++ b/drivers/hwmon/aspeed-pwm-tacho.c
@@ -7,6 +7,7 @@
7 */ 7 */
8 8
9#include <linux/clk.h> 9#include <linux/clk.h>
10#include <linux/errno.h>
10#include <linux/gpio/consumer.h> 11#include <linux/gpio/consumer.h>
11#include <linux/delay.h> 12#include <linux/delay.h>
12#include <linux/hwmon.h> 13#include <linux/hwmon.h>
@@ -494,7 +495,7 @@ static u32 aspeed_get_fan_tach_ch_measure_period(struct aspeed_pwm_tacho_data
494 return clk / (clk_unit * div_h * div_l * tacho_div * tacho_unit); 495 return clk / (clk_unit * div_h * div_l * tacho_div * tacho_unit);
495} 496}
496 497
497static u32 aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, 498static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
498 u8 fan_tach_ch) 499 u8 fan_tach_ch)
499{ 500{
500 u32 raw_data, tach_div, clk_source, sec, val; 501 u32 raw_data, tach_div, clk_source, sec, val;
@@ -510,6 +511,9 @@ static u32 aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
510 msleep(sec); 511 msleep(sec);
511 512
512 regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val); 513 regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val);
514 if (!(val & RESULT_STATUS_MASK))
515 return -ETIMEDOUT;
516
513 raw_data = val & RESULT_VALUE_MASK; 517 raw_data = val & RESULT_VALUE_MASK;
514 tach_div = priv->type_fan_tach_clock_division[type]; 518 tach_div = priv->type_fan_tach_clock_division[type];
515 tach_div = 0x4 << (tach_div * 2); 519 tach_div = 0x4 << (tach_div * 2);
@@ -561,12 +565,14 @@ static ssize_t show_rpm(struct device *dev, struct device_attribute *attr,
561{ 565{
562 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); 566 struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr);
563 int index = sensor_attr->index; 567 int index = sensor_attr->index;
564 u32 rpm; 568 int rpm;
565 struct aspeed_pwm_tacho_data *priv = dev_get_drvdata(dev); 569 struct aspeed_pwm_tacho_data *priv = dev_get_drvdata(dev);
566 570
567 rpm = aspeed_get_fan_tach_ch_rpm(priv, index); 571 rpm = aspeed_get_fan_tach_ch_rpm(priv, index);
572 if (rpm < 0)
573 return rpm;
568 574
569 return sprintf(buf, "%u\n", rpm); 575 return sprintf(buf, "%d\n", rpm);
570} 576}
571 577
572static umode_t pwm_is_visible(struct kobject *kobj, 578static umode_t pwm_is_visible(struct kobject *kobj,