From patchwork Fri Jun 23 15:05:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9806763 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 7368460349 for ; Fri, 23 Jun 2017 15:05:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A2728429 for ; Fri, 23 Jun 2017 15:05:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 541BF2877A; Fri, 23 Jun 2017 15:05:50 +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 D7A2728429 for ; Fri, 23 Jun 2017 15:05:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752878AbdFWPFt (ORCPT ); Fri, 23 Jun 2017 11:05:49 -0400 Received: from mail-pf0-f172.google.com ([209.85.192.172]:35423 "EHLO mail-pf0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750932AbdFWPFt (ORCPT ); Fri, 23 Jun 2017 11:05:49 -0400 Received: by mail-pf0-f172.google.com with SMTP id c73so24657776pfk.2 for ; Fri, 23 Jun 2017 08:05:48 -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=juAU+ysYA58a/FALcochDC4C+ZVbIwBpjL3n+SREwLc=; b=leRc9/VxCu1P9UkrlwERD1ZjtmhsKYcueowIi+50BKH+OJLZEEgi4axzIMinV8HIil rld/DjfAQ98Z/s3e/n934ssZfBwjlFm4HKWRxqB9Ub/oFt6knPmPqWmcWb+tDuzYI+/A xBpR9nhRLKgQEQUnZtriQLRL8ZewnsxBybtvpiBqC62oia6jtHAmRYfEvYR64x0fjHQJ 0PZujtGBuqslzb7UkIpZtEgnz2Y679gPiacn/Ho77SEb9u2BpZRaOuYuOHKdRagP7JDy QYPhCHnCRJnQz4KfrANmZ8BLwQk7s94Wa7acirk1KbGN9GNOwi30vUpVBSlGLBkHUOQh A3KA== 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=juAU+ysYA58a/FALcochDC4C+ZVbIwBpjL3n+SREwLc=; b=Z1IGwTxrr60DsZWw2hr0DF6VFv4yb5BBB772Scql0wkDBeY1TAhkZZfH6x035U1gyL otYZcInmug94pxYBl9fx171vxZdH5kJ+NdYW/aGEAWDE4V8J1Xp2CC2HuM74XmWHRVKo 760aXR+ytkrhwckGRljXvkUQ/qc/XWkQWyAatJY0IA1gRMnV8fd9dMkPC+LScphK1gFy ldeVIxss0TgQvV1OIBJeifpb1MoZ1TJLv24SGsCnDlTD4mLqZfXYC1ETvEH8pIoEaOnl ab6t4kpuji22kcIYnMBJvjW7mysWI77hHEHxUpNl4IGhBleieTG6flGEN1k32v5t3tvr Sb3g== X-Gm-Message-State: AKS2vOxGrfEpHZupNPXk3lKTvg0PxHEYJm6k2Yow98uV83Ey6k3dYUw0 8uSgHjZa19FwUDBu X-Received: by 10.98.60.5 with SMTP id j5mr8708713pfa.56.1498230348268; Fri, 23 Jun 2017 08:05:48 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id t11sm10507314pfl.3.2017.06.23.08.05.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Jun 2017 08:05:47 -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 v3] hwmon: (aspeed-pwm-tacho) Poll with short sleeps. Date: Fri, 23 Jun 2017 08:05:42 -0700 Message-Id: <20170623150542.7088-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 --- 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];