From patchwork Wed Jun 21 01:12:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9800563 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 33BE36038C for ; Wed, 21 Jun 2017 01:12:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0F0E42624A for ; Wed, 21 Jun 2017 01:12:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 03DED26E46; Wed, 21 Jun 2017 01:12:39 +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 93C792624A for ; Wed, 21 Jun 2017 01:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752927AbdFUBMi (ORCPT ); Tue, 20 Jun 2017 21:12:38 -0400 Received: from mail-pf0-f179.google.com ([209.85.192.179]:36720 "EHLO mail-pf0-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752915AbdFUBMh (ORCPT ); Tue, 20 Jun 2017 21:12:37 -0400 Received: by mail-pf0-f179.google.com with SMTP id x63so77232982pff.3 for ; Tue, 20 Jun 2017 18:12:37 -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:in-reply-to:references; bh=39TBNlBQHBavdY0iGz7wvs8p8ANNhHKUFFuQ+FpP+J4=; b=L7FFUy9jra88EjD7LlZJXPWojaqx3LDTlFJqgGtU7cbz+qR6SL2uI5V+CmFjXxlREm FSSaNxyq6YohmV5DFe5hsX3eOgewCdLKEDUayNf2ZujREMMgyldVQ42hBdJo9ArRdfix oN8Up/j3qmvJItau/DhR6mldv2MVEWYg250EjZkqJ8y34RhgqM66b9bB7VG0QP/+HyLA ovccsiIbn3vYQna7zOyq1/CsbMyOoPxlNCDkXsuitbWyzF+Xs6nZ3KmmSa/pvAo7t/a6 Y7qU6EB1o+I7FxltBpGso+ijIVK0wtT/YWwJaZeNVmvIPAp0LIfnmDvKDeQYM+vxs228 M6Uw== 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:in-reply-to :references; bh=39TBNlBQHBavdY0iGz7wvs8p8ANNhHKUFFuQ+FpP+J4=; b=IzKiDTfAiXtKjKQxODTiPnXLvy6eFd+yO7IRyjIjJr/LxdrvhuUNrMXeIG/wJlJ2EC kq/NYX1F1ZbedQPKP/KIJta9fE2U4i1xFjACoa1JIKsfWcTGTZ9yvlf/5EYHqMMkZWzf tvRoy4dvwtWlv4B2Ond52CCc+Q7GGK7yYFVdGcy2fbqmuf/KVIYFL8SiqwPxcNbVPy1u ZOMsM9SCtfEv1DtdsiEJeQ8ct/rBeJ1PJktydu0uSCxsVwVokGCBqCXIkTZ+2sscUWci fiq8KUaItLsqPEKSWJrjjP5d6mCOK0ppkE7CmuXpgcmQjAJ4WyOvK651yfBQrF5ZjkVV J/Mg== X-Gm-Message-State: AKS2vOzH1Y8+E2VVvl3xntrkcONsCSD68QWt/038JDojf32SDxPqD/LZ KzSUE3H2CrApd2e6 X-Received: by 10.99.170.76 with SMTP id x12mr4352935pgo.109.1498007556517; Tue, 20 Jun 2017 18:12:36 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id m132sm7580371pfc.76.2017.06.20.18.12.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Jun 2017 18:12:35 -0700 (PDT) From: Patrick Venture 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 Message-Id: <20170621011228.25128-2-venture@google.com> X-Mailer: git-send-email 2.13.1.611.g7e3b11ae1-goog In-Reply-To: <20170621011228.25128-1-venture@google.com> References: <20170621011228.25128-1-venture@google.com> 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 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 --- 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];