From patchwork Fri Jun 23 01:46:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9805521 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 C3E1960329 for ; Fri, 23 Jun 2017 01:46:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B70CE2859E for ; Fri, 23 Jun 2017 01:46:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AA75E285C7; Fri, 23 Jun 2017 01:46:43 +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 3603A2859E for ; Fri, 23 Jun 2017 01:46:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754039AbdFWBqm (ORCPT ); Thu, 22 Jun 2017 21:46:42 -0400 Received: from mail-pg0-f44.google.com ([74.125.83.44]:33000 "EHLO mail-pg0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754035AbdFWBql (ORCPT ); Thu, 22 Jun 2017 21:46:41 -0400 Received: by mail-pg0-f44.google.com with SMTP id f127so15158499pgc.0 for ; Thu, 22 Jun 2017 18:46:41 -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=uyt69jFhbWQWQ8bzE2rROpmKEi/ysdzQLOM73cXi0lc=; b=fcqfwDRX1xdMZYqAtdkLVGYo/5iFiqPf7yVFJTa0QkzxATOb343KdInWOnr0DtF15o FkC+kQ3UZhurozoNTBujuaha2YmuMOtGWlJJEKLahxJtB1KuCOwppIyzEV31XkdAw7QL 5NGrzf7ypo84tagdX8v+2XteNHThlvHl/e1KSHgoEXxvMpCX+2Woj10i63F3sPzoCte9 P1U+z2D4dCPveIvAAdnrB+8qLTsLce+MuJiRGJSlvOTB3WYssYN18zhxgDknfytx+16m hLWFpPzEvJuBXBCVmEyEN17nSw/6vX2NzYTdxEITGyMiLiKT7GbzEPRyuf4GgpEw/AZV cXTw== 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=uyt69jFhbWQWQ8bzE2rROpmKEi/ysdzQLOM73cXi0lc=; b=DNlcz7x5uPwKQshZTtfVTG2GjJVXKJTUnVhEPq53vvjj9MRI0uC0mwd0NUqo7clp4o vkSP5A8EfNybn6aFu+TEB8rNmrEw5NuYNZPeLB9rRay8IWnXgxzqb/tddjLdVzncUtyZ NGFD9xg+WoFFHoIx3GJ6FKn5xZ3Z7CsUSQJ2TLO5Ibsu0sVewA6XKQnCRXkmam+a0vdk tIfyApOcsEf/T77QpPfpBBzNhABdAhiVVmC5S5cvK5Tnxno5OurY15tdGKZTPq/vZD+W cL/cREvp5GvJMOxlsYytFExIrsLpcQNklWKoFIITCZHe7yumZZGwkk+rVbInFZvVrGji zKPg== X-Gm-Message-State: AKS2vOwIYDBlkxKO5F0e8FL/g/Qq+5yXp8ZUivspFXPsdfzmFjJljrwS i4umfQtLAF7CsXebtl/ncQ== X-Received: by 10.101.86.76 with SMTP id m12mr5676718pgs.137.1498182401057; Thu, 22 Jun 2017 18:46:41 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id 25sm6330735pfj.59.2017.06.22.18.46.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Jun 2017 18:46:40 -0700 (PDT) From: Patrick Venture To: venture@google.com, joel@jms.id.aum, linux@roeck-us.net Cc: linux-hwmon@vger.kernel.org, raltherr@google.com, emilyshaffer@google.com, peterh@google.com Subject: [PATCH 2/2 v2] hwmon: (aspeed-pwm-tacho) Poll with short sleeps. Date: Thu, 22 Jun 2017 18:46:37 -0700 Message-Id: <20170623014637.99846-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 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index b2ab5612d8a4..b865541f4858 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 while waiting for an RPM result. */ +#define ASPEED_RPM_STATUS_SLEEP 500 + 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, msec, usec, val; u8 fan_tach_ch_source, type, mode, both; regmap_write(priv->regmap, ASPEED_PTCR_TRIGGER, 0); @@ -517,12 +520,16 @@ 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; - regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val); - if (!(val & RESULT_STATUS_MASK)) - return -ETIMEDOUT; + regmap_read_poll_timeout( + priv->regmap, + ASPEED_PTCR_RESULT, + val, + (val & RESULT_STATUS_MASK), + ASPEED_RPM_STATUS_SLEEP, + usec); raw_data = val & RESULT_VALUE_MASK; tach_div = priv->type_fan_tach_clock_division[type];