From: Patrick Venture <venture@google.com>
To: venture@google.com, joel@jms.id.au, jdelvare@suse.com,
linux@roeck-us.net
Cc: linux-hwmon@vger.kernel.org, raltherr@google.com,
emilyshaffer@google.com, peterh@google.com
Subject: [PATCH 2/2] hwmon: (aspeed-pwm-tacho) Poll for fan_tach instead of sleep
Date: Tue, 20 Jun 2017 18:12:28 -0700 [thread overview]
Message-ID: <20170621011228.25128-2-venture@google.com> (raw)
In-Reply-To: <20170621011228.25128-1-venture@google.com>
The reference driver polled but mentioned it was possible to sleep
for a computed period to know when it's ready to read. However, polling
is quick and works. This also improves responsiveness from the driver.
Testing: tested on ast2400 on quanta-q71l
Signed-off-by: Patrick Venture <venture@google.com>
---
drivers/hwmon/aspeed-pwm-tacho.c | 23 +++++++++++++++++------
1 file changed, 17 insertions(+), 6 deletions(-)
diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c
index b2ab5612d8a4..a31d2648fb3a 100644
--- a/drivers/hwmon/aspeed-pwm-tacho.c
+++ b/drivers/hwmon/aspeed-pwm-tacho.c
@@ -163,6 +163,9 @@
#define M_TACH_UNIT 0x00c0
#define INIT_FAN_CTRL 0xFF
+/* How many times we poll the fan_tach controller for rpm data. */
+#define FAN_TACH_RPM_TIMEOUT 25
+
struct aspeed_pwm_tacho_data {
struct regmap *regmap;
unsigned long clk_freq;
@@ -508,7 +511,7 @@ static u32 aspeed_get_fan_tach_ch_measure_period(struct aspeed_pwm_tacho_data
static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
u8 fan_tach_ch)
{
- u32 raw_data, tach_div, clk_source, sec, val;
+ u32 raw_data, tach_div, clk_source, sec, val, timeout;
u8 fan_tach_ch_source, type, mode, both;
regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0);
@@ -517,12 +520,20 @@ static int aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv,
fan_tach_ch_source = priv->fan_tach_ch_source[fan_tach_ch];
type = priv->pwm_port_type[fan_tach_ch_source];
- sec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type));
- msleep(sec);
-
regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val);
- if (!(val & RESULT_STATUS_MASK))
- return -ETIMEDOUT;
+ /*
+ * Instead of sleeping first, poll register for result.
+ * This is based on the reference driver's approach which expects to
+ * receive a value quickly.
+ */
+ timeout = 0;
+ while (!(val & RESULT_STATUS_MASK)) {
+ timeout++;
+ if (timeout > FAN_TACH_RPM_TIMEOUT)
+ return -ETIMEDOUT;
+
+ regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val);
+ }
raw_data = val & RESULT_VALUE_MASK;
tach_div = priv->type_fan_tach_clock_division[type];
--
2.13.1.611.g7e3b11ae1-goog
next prev parent reply other threads:[~2017-06-21 1:12 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 1:12 [PATCH 1/2] hwmon: (aspeed-pwm-tacho) reduce fan_tach period Patrick Venture
2017-06-21 1:12 ` Patrick Venture [this message]
2017-06-21 1:32 ` [PATCH 2/2] hwmon: (aspeed-pwm-tacho) Poll for fan_tach instead of sleep Guenter Roeck
2017-06-21 1:39 ` Guenter Roeck
2017-06-21 1:42 ` Patrick Venture
2017-06-21 1:52 ` Guenter Roeck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170621011228.25128-2-venture@google.com \
--to=venture@google.com \
--cc=emilyshaffer@google.com \
--cc=jdelvare@suse.com \
--cc=joel@jms.id.au \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=peterh@google.com \
--cc=raltherr@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.