From patchwork Tue May 30 19:42:01 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Leis X-Patchwork-Id: 9755197 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 D1D68601D2 for ; Tue, 30 May 2017 19:42:08 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5A2F28485 for ; Tue, 30 May 2017 19:42:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B9DF42848D; Tue, 30 May 2017 19:42:08 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, 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 52C6B2849F for ; Tue, 30 May 2017 19:42:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750871AbdE3TmH (ORCPT ); Tue, 30 May 2017 15:42:07 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:36665 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750855AbdE3TmG (ORCPT ); Tue, 30 May 2017 15:42:06 -0400 Received: by mail-pf0-f174.google.com with SMTP id m17so81085006pfg.3 for ; Tue, 30 May 2017 12:42:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:subject:date:message-id; bh=Vc5gPWgvmOE0WrE8jIAxcnXas/pxSRgv2ePDYNu55jo=; b=OB2D4GZHgSiDkHLRKwfInInIY8bbiFoitBjE5axzqfvcTbtyZ0j4VNb/3JevH4hZtO FVGbb7P4GjLDswMliSXVt/UXmYNnF1V5vsN8K0/mrE9jMstLs/onC3YZSjOPfvFjwtdt k+3/ZGnt/23vsydm07W3odOoRBJfiJA2rxJ1qL6WNtxCEJRHUuk590lBjFObLvUDKGEm WhVwU4/c79QGA6Ew+IuSirkOYKByCpKuLOSvVNb0scTcdq54AOYOUOXRchNFw/E80Qvo gavLiZA6b1qj9xikBO+l7WHO486nnrPyTKByRz+fmSyxY3ZAscq1qc07AEAVDSv9luvc BxEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Vc5gPWgvmOE0WrE8jIAxcnXas/pxSRgv2ePDYNu55jo=; b=bo3TBlfFSamSgVVUF5+yHjvYYmTtNIc+O+MUhgmFsa7EihykP0HNR1qgnUR4vIdpWG krB68dw6IxoGHtonwPXiZ2RwzlfdzY16fTrvk3TGxMt7z61IXn3DYAT/LkkFDEBWV9/h lAs+0cDR+2jqW4rHKe8TIs0JEUrLpmHNZ/1s9z+HB8nelT7aWwQTDd7hoMBndn/7Ze36 jYs2cZr81V2dzrta+1jr2g/b2er04cg2ukvnZqBY2I/OfPVFYqBP8USjRaqSlq6kFeD6 guAmJR8hONKHmCOyXq45DD2QrLDaV5k9SQXOkW/gt4bELYKycnJ1NTgqeuCaxb7J0JWv QdNg== X-Gm-Message-State: AODbwcDVBIpjR7cGZNQH9tx5fcMSIyLvfuCtZOPPsAK+tz/23esSkkZ8 hx5Xgvv8G/nWJo57 X-Received: by 10.84.228.207 with SMTP id y15mr84287283pli.172.1496173325994; Tue, 30 May 2017 12:42:05 -0700 (PDT) Received: from venture.svl.corp.google.com ([100.123.242.104]) by smtp.gmail.com with ESMTPSA id g20sm25041008pfk.21.2017.05.30.12.42.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 May 2017 12:42:05 -0700 (PDT) From: Patrick Venture To: venture@google.com, joel@jms.id.au, jdelvare@suse.com, linux-hwmon@vger.kernel.org Subject: [PATCH v3] hwmon: (aspeed-pwm-tacho) On read failure return -ETIMEDOUT Date: Tue, 30 May 2017 12:42:01 -0700 Message-Id: <20170530194201.4540-1-venture@google.com> X-Mailer: git-send-email 2.13.0.219.gdb65acc882-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 When the controller fails to provide an RPM reading within the alloted time; the driver returns -ETIMEDOUT and no file contents. Signed-off-by: Patrick Venture --- drivers/hwmon/aspeed-pwm-tacho.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/hwmon/aspeed-pwm-tacho.c b/drivers/hwmon/aspeed-pwm-tacho.c index 48403a2115be..12b716b70ead 100644 --- a/drivers/hwmon/aspeed-pwm-tacho.c +++ b/drivers/hwmon/aspeed-pwm-tacho.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -494,7 +495,7 @@ static u32 aspeed_get_fan_tach_ch_measure_period(struct aspeed_pwm_tacho_data return clk / (clk_unit * div_h * div_l * tacho_div * tacho_unit); } -static u32 aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, +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; @@ -510,6 +511,9 @@ static u32 aspeed_get_fan_tach_ch_rpm(struct aspeed_pwm_tacho_data *priv, msleep(sec); regmap_read(priv->regmap, ASPEED_PTCR_RESULT, &val); + if (!(val & RESULT_STATUS_MASK)) + return -ETIMEDOUT; + raw_data = val & RESULT_VALUE_MASK; tach_div = priv->type_fan_tach_clock_division[type]; tach_div = 0x4 << (tach_div * 2); @@ -561,12 +565,14 @@ static ssize_t show_rpm(struct device *dev, struct device_attribute *attr, { struct sensor_device_attribute *sensor_attr = to_sensor_dev_attr(attr); int index = sensor_attr->index; - u32 rpm; + int rpm; struct aspeed_pwm_tacho_data *priv = dev_get_drvdata(dev); rpm = aspeed_get_fan_tach_ch_rpm(priv, index); + if (rpm < 0) + return rpm; - return sprintf(buf, "%u\n", rpm); + return sprintf(buf, "%d\n", rpm); } static umode_t pwm_is_visible(struct kobject *kobj,