Received: by 10.213.65.68 with SMTP id h4csp957520imn; Tue, 20 Mar 2018 21:43:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELtRhebJvyrHslPv7MN5BAQbOIPWHJFIVfbSplCjvk5BaFvdztSjXAv9a5HAoCri8bFeYUB3 X-Received: by 10.101.92.196 with SMTP id b4mr13714471pgt.27.1521607424685; Tue, 20 Mar 2018 21:43:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521607424; cv=none; d=google.com; s=arc-20160816; b=YNADB8MwEOLhvrCQvZMjSpvwU5t8cB+IrwRP7Z9Y00INnrBRJX412O6A0L+Vt1lppk FCVWNq5lT+lwOCWxoCx6pdjd+pgm3LjE3BhxGncBKfROU8GXlcR8J3fWweKLGm/AJivG W+hY8HCK74F5QAXpTDXgA1ouOBiq3mgYyVxUEu5IPybThA9KYky+py8sdOsI/zhtc2FF jmWm2pI8R7fWmq+Ap7FaCjodEnoyAssHDd8oN34fh18cIw/xmH6aASqP9hRmtGQ/bUSo 3XLa7Isj2CPZLYFLEr0JYCSONC/2wlVjIpHK56b3Up6xBmbYNgpaMigiPW5W4qDbV0LC /Fyw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:arc-authentication-results; bh=KnTZzAErrOzRoDAR19m+1MHotTDRmvjnqm0vVUPi+o4=; b=cvpuxgS1hwkKdpI+UpLAYjU2osMZn1YYP+JN8GLxK9JPc2vplSm54d0Y5PHJsie09P 9H+Y2YqHVLx8+9IXnTcDGT1RpgKYCWBXcQ5mOCjQbDAC0VJgfspmd6qgcnnPHHB+JKaN Ka/8bNnerUPEK4IycFalYzABk18LIX/+KsaMaiTMJtfvxMKvazHfyvUGcuH2UNeYoDCj iYgsIsPm5lGm1lAbPqN535o3J8X3eJWh5bRgskyAaVQirG86uzD5GrCRA8UtxavUtx8T w+nBNzAl38JWOUu91/thqHwxPr1is4evAbVvcgZdw1Co9YK8mscLPdfF73UzBxSbpPN0 HUhg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n3-v6si3209777plb.147.2018.03.20.21.43.31; Tue, 20 Mar 2018 21:43:44 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752188AbeCUEmI (ORCPT + 99 others); Wed, 21 Mar 2018 00:42:08 -0400 Received: from hqemgate14.nvidia.com ([216.228.121.143]:7499 "EHLO hqemgate14.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751923AbeCUEmB (ORCPT ); Wed, 21 Mar 2018 00:42:01 -0400 Received: from hqpgpgate101.nvidia.com (Not Verified[216.228.121.13]) by hqemgate14.nvidia.com id ; Tue, 20 Mar 2018 21:40:45 -0700 Received: from HQMAIL101.nvidia.com ([172.20.161.6]) by hqpgpgate101.nvidia.com (PGP Universal service); Tue, 20 Mar 2018 21:42:00 -0700 X-PGP-Universal: processed; by hqpgpgate101.nvidia.com on Tue, 20 Mar 2018 21:42:00 -0700 Received: from UKMAIL101.nvidia.com (10.26.138.13) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 21 Mar 2018 04:41:59 +0000 Received: from HQMAIL101.nvidia.com (172.20.187.10) by UKMAIL101.nvidia.com (10.26.138.13) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Wed, 21 Mar 2018 04:41:56 +0000 Received: from rrajk-ubuntu.nvidia.com (10.124.1.5) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1347.2 via Frontend Transport; Wed, 21 Mar 2018 04:41:46 +0000 From: Rajkumar Rampelli To: , , , , , , , , , , , , , , , , , , , , , CC: , , , , , , , , Subject: [PATCH V2 7/9] hwmon: pwm-fan: add sysfs node to read rpm of fan Date: Wed, 21 Mar 2018 10:10:42 +0530 Message-ID: <1521607244-29734-8-git-send-email-rrajk@nvidia.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1521607244-29734-1-git-send-email-rrajk@nvidia.com> References: <1521607244-29734-1-git-send-email-rrajk@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add fan device attribute fan1_input in pwm-fan driver to read speed of fan in rotations per minute. Signed-off-by: Rajkumar Rampelli --- V2: Removed generic-pwm-tachometer driver and using pwm-fan driver as per suggestions to read fan speed. Added fan device attribute to report speed of fan in rpms through hwmon sysfs. drivers/hwmon/pwm-fan.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/drivers/hwmon/pwm-fan.c b/drivers/hwmon/pwm-fan.c index 70cc0d1..8dda209 100644 --- a/drivers/hwmon/pwm-fan.c +++ b/drivers/hwmon/pwm-fan.c @@ -98,11 +98,34 @@ static ssize_t show_pwm(struct device *dev, return sprintf(buf, "%u\n", ctx->pwm_value); } +static ssize_t show_rpm(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct pwm_fan_ctx *ptt = dev_get_drvdata(dev); + struct pwm_device *pwm = ptt->pwm; + struct pwm_capture result; + unsigned int rpm = 0; + int ret; + + ret = pwm_capture(pwm, &result, 0); + if (ret < 0) { + pr_err("Failed to capture PWM: %d\n", ret); + return ret; + } + + if (result.period) + rpm = DIV_ROUND_CLOSEST_ULL(60ULL * NSEC_PER_SEC, + result.period); + + return sprintf(buf, "%u\n", rpm); +} static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO | S_IWUSR, show_pwm, set_pwm, 0); +static SENSOR_DEVICE_ATTR(fan1_input, 0444, show_rpm, NULL, 0); static struct attribute *pwm_fan_attrs[] = { &sensor_dev_attr_pwm1.dev_attr.attr, + &sensor_dev_attr_fan1_input.dev_attr.attr, NULL, }; -- 2.1.4