From patchwork Sat Jun 24 03:39:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9807575 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 7394D6032A for ; Sat, 24 Jun 2017 03:40:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6873F287D7 for ; Sat, 24 Jun 2017 03:40:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5AE5B287DC; Sat, 24 Jun 2017 03:40:02 +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 77903287D7 for ; Sat, 24 Jun 2017 03:40:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754937AbdFXDkA (ORCPT ); Fri, 23 Jun 2017 23:40:00 -0400 Received: from mail-pf0-f177.google.com ([209.85.192.177]:34479 "EHLO mail-pf0-f177.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754933AbdFXDj7 (ORCPT ); Fri, 23 Jun 2017 23:39:59 -0400 Received: by mail-pf0-f177.google.com with SMTP id s66so31339207pfs.1 for ; Fri, 23 Jun 2017 20:39: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=HaPw5H7L+xQ1LL2ZBgHQIBh+tgNfGe/mXW9EJ7m2YQw=; b=tyZ3qJ79B7HlPVQILmjNdTGYTVN5sQHRUZ1u0HnMVR3lCkCqyz3NhPNaMlQ8lhBKZC 5u8HZdXY53NyjqSSJkfoUJqw6/8pG+ZM6ZZ0RGzBTkLCgZElQExSlv4yizio/27mJwbS wVnKWFAfzFUDSHqy7IgAV0cbBf+QzfQoqKqt8sCFEJOpmm7yAyRpXBXCp/hSc4t97KBs U0NdSSqRizcKvB1KsAC5FnRE8fjNzoEtEdkbFg+o0ilBsnbdQkCj5LTMYyWg/QNzfyNS GjIVM3DzrZwRVCh9nlDqQ8xnCeN9TDqf7nZlL4zzgN96wT2wno17dAr0LoYa4iRUPhB4 3bKg== 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=HaPw5H7L+xQ1LL2ZBgHQIBh+tgNfGe/mXW9EJ7m2YQw=; b=UTVjiIq2oRqDXix/PPt4eQnzUcUamCGQ3EmLWRX/+IJIhOEfpCrsLuc6Z+Nvn0UArP FiJ/ZOXiKjlW2LiIDFL/PAgrbA8jL6YwZZN/eNsCTY8CxquV+kDXkdfHciRCwXhtSw/t vORN7tHHfF26K9k0MSoFT9CP0q1gJmLHwEC/mzdH+YB8rvCPOldK11+jgDAhgGEs05UT 50uW8r4luQyzWuG/uulfFz/CucOibzgZCOcUYBlkk7+35G7S7612P14tI3S3EYjIJFUr eKl6KosQdJrZsUM8yJgHU/oQh0sFNWDjI6/tuBWJsbCRSyD7z9860zJqASdwjO3ytlq0 wDKQ== X-Gm-Message-State: AKS2vOzNIeG4IabGRULazlEd65Rmuj1UUchFM2W+od5/eii+eUOt7Ov9 1D12sb3O2TkfrTYc X-Received: by 10.84.233.204 with SMTP id m12mr12424687pln.292.1498275598743; Fri, 23 Jun 2017 20:39:58 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id 25sm12913569pfj.59.2017.06.23.20.39.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Jun 2017 20:39:57 -0700 (PDT) From: Patrick Venture To: venture@google.com, joel@jms.id.au, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, emilyshaffer@google.com, peterh@google.com Subject: [PATCH 2/2 v4] hwmon: (aspeed-pwm-tacho) Poll with short sleeps. Date: Fri, 23 Jun 2017 20:39:56 -0700 Message-Id: <20170624033956.120552-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 reference driver polled but mentioned it was possible to sleep for a computed period to know when it's ready to read. However, polling with minimal sleeps is quick and works. This also improves responsiveness from the driver. Testing: tested on ast2400 on quanta-q71l Signed-off-by: Patrick Venture --- v4: Added missing change log v3: Added missing return value check v2: Fixed poll to sleep instead of an increment loop --- drivers/hwmon/aspeed-pwm-tacho.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index b2ab5612d8a4..cfcd769175e6 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 long we sleep in us while waiting for an RPM result. */ +#define ASPEED_RPM_STATUS_SLEEP_USEC 500 + struct aspeed_pwm_tacho_data { struct regmap *regmap; unsigned long clk_freq; @@ -508,8 +511,9 @@ 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, msec, usec, val; u8 fan_tach_ch_source, type, mode, both; + int ret; regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0x1 << fan_tach_ch); @@ -517,12 +521,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); + msec = (1000 / aspeed_get_fan_tach_ch_measure_period(priv, type)); + usec = msec * 1000; + + ret = regmap_read_poll_timeout( + priv->regmap, + ASPEED_PTCR_RESULT, + val, + (val & RESULT_STATUS_MASK), + ASPEED_RPM_STATUS_SLEEP_USEC, + usec); - regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val); - if (!(val & RESULT_STATUS_MASK)) - return -ETIMEDOUT; + /* return -ETIMEDOUT if we didn't get an answer. */ + if (ret) + return ret; raw_data = val & RESULT_VALUE_MASK; tach_div = priv->type_fan_tach_clock_division[type];