From patchwork Wed Jun 21 00:36:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9800485 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 36DF06086C for ; Wed, 21 Jun 2017 00:36:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 30B511FFF8 for ; Wed, 21 Jun 2017 00:36:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 251A1201A4; Wed, 21 Jun 2017 00:36:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B7A5B1FFF8 for ; Wed, 21 Jun 2017 00:36:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752676AbdFUAgf (ORCPT ); Tue, 20 Jun 2017 20:36:35 -0400 Received: from mail-pf0-f180.google.com ([209.85.192.180]:36552 "EHLO mail-pf0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752592AbdFUAge (ORCPT ); Tue, 20 Jun 2017 20:36:34 -0400 Received: by mail-pf0-f180.google.com with SMTP id x63so76869875pff.3 for ; Tue, 20 Jun 2017 17:36:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=+fC4bLgqe8THu4Q1NMHNJy5swLzEuANG/npvh8QOuO8=; b=d+Q2FH8s6/HftQYb9wnPvcbobW5m7qWZGIZIvzFg/rpsJiy+5czeZRH1/3lTr+KIgB 6dQR/2b4x+lO9CwYHN+32lzPwPCDXUpZNXl7l79MwGsuDGMWLY7rjCmkAG54zNwoo9Vj D2lAbxYnQSoEn5gZrgxLHdOnggHIgo1kJb6h+/hsIMJOk/w49en4IHmBB9WGvWyhm72H 2RGdl7axSkiBZbslCGCx7kFAUuPjNdJE07zu6kAOVhG9aVbOiP5MK/MlKWPpTkwES94c P/wstr27N2B5p1xqzqsNCxnrTSXPvhRX+JXC8FVWdPOPDvGP8gisSwNWEGJyEF4qc2Gj oY1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+fC4bLgqe8THu4Q1NMHNJy5swLzEuANG/npvh8QOuO8=; b=YPkCtu6ShC/NA+nZoLRqUNS5FxwiqisTt/aouJGE6VkfOz+eKjM+60zdlnK8jkbpDl Etx/x+tiLaeB/m07l7crqV4ecrYBjGk4H4XLBtS8OcOt/TQLvj/JoArSDCmx7JNZWEqi OAtZ5srr6nfue4z6LQ3UgsPZxh0uZGSUE94AaF0vFUFMYIOJxVptFt9UPA/nos7MWB+4 79ZJz939GyuhpYyGImsWxPQjg8pTfWBnAVWo/Ou1Y+64yCQH50D76kcBijy/kWgNpuED 33oLXcbH4Qz6Das+SykZ5kfNM+NAgNZ9wSQXFU/+j9IpRCiYxIGgSKaf17uVpyXzoSdb U4xg== X-Gm-Message-State: AKS2vOz2QhceiFpCOK3BEL6c7H9KvmrVF581GnzOQLqIJaVSmvGaaWzX orVR2C209JEJC6rZtQmycQ== X-Received: by 10.84.231.1 with SMTP id f1mr38662964plk.258.1498005393782; Tue, 20 Jun 2017 17:36:33 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id g10sm27198895pgr.18.2017.06.20.17.36.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 17:36:33 -0700 (PDT) From: Patrick Venture To: venture@google.com, joel@jms.id.au, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, raltherr@google.com, peterh@google.com, emilyshaffer@google.com Subject: [PATCH v2] hwmon: (aspeed-pwm-tacho) Poll register instead of sleep Date: Tue, 20 Jun 2017 17:36:29 -0700 Message-Id: <20170621003629.21795-1-venture@google.com> X-Mailer: git-send-email 2.13.1.611.g7e3b11ae1-goog Sender: linux-hwmon-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-hwmon@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The controller should provide an answer nearly immediately if the fan_tach period is short. I found through testing that the combination of these factors improved the device driver responsiveness. Testing: tested on quanta-q71l board with aspeed ast2400 using a slightly different tree. Signed-off-by: Patrick Venture --- 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 86e2ea8287a7..aa5174d0fd90 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -163,6 +163,9 @@ #define M_TACH_UNIT 0x1000 #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];