From patchwork Tue Jun 20 22:00:55 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9800315 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 67EAF600F5 for ; Tue, 20 Jun 2017 22:01:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 54D3D223B2 for ; Tue, 20 Jun 2017 22:01:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4967828477; Tue, 20 Jun 2017 22:01:00 +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 E006428323 for ; Tue, 20 Jun 2017 22:00:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752585AbdFTWA7 (ORCPT ); Tue, 20 Jun 2017 18:00:59 -0400 Received: from mail-pg0-f41.google.com ([74.125.83.41]:35745 "EHLO mail-pg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752529AbdFTWA7 (ORCPT ); Tue, 20 Jun 2017 18:00:59 -0400 Received: by mail-pg0-f41.google.com with SMTP id 132so34739152pgb.2 for ; Tue, 20 Jun 2017 15:00:59 -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=oLJsRmA//yXsbiR8bUfsWdf0+RCImfaw6yvsBggXqd0=; b=cXpInLYZOjp2lfOx8la1YAB/a7zuuZIjgNRM12RC57V5MtEQl+KuRVh53OxYae72en s4b9tzdPA1s2ERvoxuKg7zSq3AzaSU8mF42g4CNX06h9xj0GqvwWDLXk1qNGkMwOTghF e5U9iFZvPd8KUER5rNGt6qKK45lpH/u0RmIpwGS9mUcHGuhYu4KPVOePXheNhzcjLHaG JIF/FdkptlzUPrFkkgld0SkbcXST2fYTgdgUIlxPvEBn6+hX5TchjDOmL439YDNX3Hs0 PqqxG7CjK6L4aW1ZziwmjiCiQ591FFQWhAXy4tetvFvita+AIPXa/SmQryx3Poo+qxoY K2mQ== 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=oLJsRmA//yXsbiR8bUfsWdf0+RCImfaw6yvsBggXqd0=; b=NlZWQuF0PjDNvKP+/WXEbRt9chh+s/YxrJMxoQpZKzkYfUF+Jr+/q5e/+AsqPJMyXJ z3/j7lfw61Z64LtdPGSNU2jb0QqqDWC0T1f5BH16aTJEKUrv0m8f2M1PIRc6yKhtbfX3 ndoBp3u6yyNECNI7hewOuN3wCy+2HhG+QPBEEA4IC/HOLbjLBMtUGPHLbEJsITMfzEa8 SIKQQZtalboQ8gbxLSXmqZ3KgmHFJjC5+fFoMqZW7TA8UaleYcX/A00h3r6rw7baf6/o gTBW1rM3Nycv9THtuNwrmoldNAsuUd+42lVCVO5keIuMdV31alYTrhI9TAQp6ENDAnYt CaBg== X-Gm-Message-State: AKS2vOyEMW2INEnhFEG/CGQzh6lkKELZ2rf5l5pRJ5BiIkygHe8LWWEL ciilUjs21YUulvG/ X-Received: by 10.98.157.74 with SMTP id i71mr33014874pfd.141.1497996058440; Tue, 20 Jun 2017 15:00:58 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id x12sm29226328pgc.47.2017.06.20.15.00.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 15:00:57 -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 Subject: [PATCH] hwmon: (aspeed-pwm-tacho) Poll register instead of sleep Date: Tue, 20 Jun 2017 15:00:55 -0700 Message-Id: <20170620220055.6503-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. Signed-off-by: Patrick Venture --- drivers/hwmon/aspeed-pwm-tacho.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index 86e2ea8287a7..9559c7b7e8c7 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -509,6 +509,7 @@ 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 timeout = 0; u8 fan_tach_ch_source, type, mode, both; regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); @@ -517,12 +518,17 @@ 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. + */ + while (!(val & RESULT_STATUS_MASK)) { + timeout++; + if (timeout > 25) + return -ETIMEDOUT; + } raw_data = val & RESULT_VALUE_MASK; tach_div = priv->type_fan_tach_clock_division[type];