From: Rajkumar Rampelli <rrajk@nvidia.com>
To: Guenter Roeck <linux@roeck-us.net>,
robh+dt@kernel.org, mark.rutland@arm.com,
thierry.reding@gmail.com, jonathanh@nvidia.com,
jdelvare@suse.com, corbet@lwn.net, catalin.marinas@arm.com,
will.deacon@arm.com, kstewart@linuxfoundation.org,
gregkh@linuxfoundation.org, pombredanne@nexb.com,
mmaddireddy@nvidia.com, mperttunen@nvidia.com, arnd@arndb.de,
timur@codeaurora.org, andy.gross@linaro.org,
xuwei5@hisilicon.com, elder@linaro.org, heiko@sntech.de,
krzk@kernel.org, ard.biesheuvel@linaro.org
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-tegra@vger.kernel.org,
linux-hwmon@vger.kernel.org, linux-doc@vger.kernel.org,
linux-arm-kernel@lists.infradead.org, ldewangan@nvidia.com
Subject: Re: [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
Date: Wed, 28 Feb 2018 11:42:28 +0530 [thread overview]
Message-ID: <2628eff2-dd33-34f4-a7e1-cfe46ef88a3f@nvidia.com> (raw)
In-Reply-To: <cfe0d0ce-3a89-bad0-85ba-6edf1135d2dc@roeck-us.net>
On Wednesday 28 February 2018 11:28 AM, Guenter Roeck wrote:
> On 02/27/2018 09:38 PM, Rajkumar Rampelli wrote:
>>
>> On Wednesday 21 February 2018 08:20 PM, Guenter Roeck wrote:
>>> On 02/20/2018 10:58 PM, Rajkumar Rampelli wrote:
>>>> Add generic PWM based tachometer driver via HWMON interface
>>>> to report the RPM of motor. This drivers get the period/duty
>>>> cycle from PWM IP which captures the motor PWM output.
>>>>
>>>> This driver implements a simple interface for monitoring the speed of
>>>> a fan and exposes it in roatations per minute (RPM) to the user space
>>>> by using the hwmon's sysfs interface
>>>>
>>>> Signed-off-by: Rajkumar Rampelli <rrajk@nvidia.com>
>>>> ---
>>>> Documentation/hwmon/generic-pwm-tachometer | 17 +++++
>>>> drivers/hwmon/Kconfig | 10 +++
>>>> drivers/hwmon/Makefile | 1 +
>>>> drivers/hwmon/generic-pwm-tachometer.c | 112
>>>> +++++++++++++++++++++++++++++
>>>> 4 files changed, 140 insertions(+)
>>>> create mode 100644 Documentation/hwmon/generic-pwm-tachometer
>>>> create mode 100644 drivers/hwmon/generic-pwm-tachometer.c
>>>>
>>>> diff --git a/Documentation/hwmon/generic-pwm-tachometer
>>>> b/Documentation/hwmon/generic-pwm-tachometer
>>>> new file mode 100644
>>>> index 0000000..e0713ee
>>>> --- /dev/null
>>>> +++ b/Documentation/hwmon/generic-pwm-tachometer
>>>> @@ -0,0 +1,17 @@
>>>> +Kernel driver generic-pwm-tachometer
>>>> +====================================
>>>> +
>>>> +This driver enables the use of a PWM module to monitor a fan. It
>>>> uses the
>>>> +generic PWM interface and can be used on SoCs as along as the SoC
>>>> supports
>>>> +Tachometer controller that moniors the Fan speed in periods.
>>>> +
>>>> +Author: Rajkumar Rampelli <rrajk@nvidia.com>
>>>> +
>>>> +Description
>>>> +-----------
>>>> +
>>>> +The driver implements a simple interface for monitoring the Fan
>>>> speed using
>>>> +PWM module and Tachometer controller. It requests period value
>>>> through PWM
>>>> +capture interface to Tachometer and measures the Rotations per
>>>> minute using
>>>> +received period value. It exposes the Fan speed in RPM to the user
>>>> space by
>>>> +using the hwmon's sysfs interface.
>>>> diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
>>>> index ef23553..8912dcb 100644
>>>> --- a/drivers/hwmon/Kconfig
>>>> +++ b/drivers/hwmon/Kconfig
>>>> @@ -1878,6 +1878,16 @@ config SENSORS_XGENE
>>>> If you say yes here you get support for the temperature
>>>> and power sensors for APM X-Gene SoC.
>>>> +config GENERIC_PWM_TACHOMETER
>>>> + tristate "Generic PWM based tachometer driver"
>>>> + depends on PWM
>>>> + help
>>>> + Enables a driver to use PWM signal from motor to use
>>>> + for measuring the motor speed. The RPM is captured by
>>>> + PWM modules which has PWM capture capability and this
>>>> + drivers reads the captured data from PWM IP to convert
>>>> + it to speed in RPM.
>>>> +
>>>> if ACPI
>>>> comment "ACPI drivers"
>>>> diff --git a/drivers/hwmon/Makefile b/drivers/hwmon/Makefile
>>>> index f814b4a..9dcc374 100644
>>>> --- a/drivers/hwmon/Makefile
>>>> +++ b/drivers/hwmon/Makefile
>>>> @@ -175,6 +175,7 @@ obj-$(CONFIG_SENSORS_WM8350) += wm8350-hwmon.o
>>>> obj-$(CONFIG_SENSORS_XGENE) += xgene-hwmon.o
>>>> obj-$(CONFIG_PMBUS) += pmbus/
>>>> +obj-$(CONFIG_GENERIC_PWM_TACHOMETER) += generic-pwm-tachometer.o
>>>> ccflags-$(CONFIG_HWMON_DEBUG_CHIP) := -DDEBUG
>>>> diff --git a/drivers/hwmon/generic-pwm-tachometer.c
>>>> b/drivers/hwmon/generic-pwm-tachometer.c
>>>> new file mode 100644
>>>> index 0000000..9354d43
>>>> --- /dev/null
>>>> +++ b/drivers/hwmon/generic-pwm-tachometer.c
>>>> @@ -0,0 +1,112 @@
>>>> +/*
>>>> + * Copyright (c) 2017-2018, NVIDIA CORPORATION. All rights reserved.
>>>> + *
>>>> + * This program is free software; you can redistribute it and/or
>>>> modify it
>>>> + * under the terms and conditions of the GNU General Public License,
>>>> + * version 2, as published by the Free Software Foundation.
>>>> + *
>>>> + * This program is distributed in the hope it will be useful, but
>>>> WITHOUT
>>>> + * ANY WARRANTY; without even the implied warranty of
>>>> MERCHANTABILITY or
>>>> + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
>>>> License for
>>>> + * more details.
>>>> + *
>>>> + */
>>>> +
>>>> +#include <linux/module.h>
>>>> +#include <linux/platform_device.h>
>>>> +#include <linux/err.h>
>>>> +#include <linux/pwm.h>
>>>> +#include <linux/hwmon.h>
>>>> +#include <linux/hwmon-sysfs.h>
>>>> +
>>>> +struct pwm_hwmon_tach {
>>>> + struct device *dev;
>>>> + struct pwm_device *pwm;
>>>> + struct device *hwmon;
>>>> +};
>>>> +
>>>> +static ssize_t show_rpm(struct device *dev, struct
>>>> device_attribute *attr,
>>>> + char *buf)
>>>> +{
>>>> + struct pwm_hwmon_tach *ptt = dev_get_drvdata(dev);
>>>> + struct pwm_device *pwm = ptt->pwm;
>>>> + struct pwm_capture result;
>>>> + int err;
>>>> + unsigned int rpm = 0;
>>>> +
>>>> + err = pwm_capture(pwm, &result, 0);
>>>> + if (err < 0) {
>>>> + dev_err(ptt->dev, "Failed to capture PWM: %d\n", err);
>>>> + return err;
>>>> + }
>>>> +
>>>> + if (result.period)
>>>> + rpm = DIV_ROUND_CLOSEST_ULL(60ULL * NSEC_PER_SEC,
>>>> + result.period);
>>>> +
>>>> + return sprintf(buf, "%u\n", rpm);
>>>> +}
>>>> +
>>>> +static SENSOR_DEVICE_ATTR(rpm, 0444, show_rpm, NULL, 0);
>>>> +
>>>> +static struct attribute *pwm_tach_attrs[] = {
>>>> + &sensor_dev_attr_rpm.dev_attr.attr,
>>>> + NULL,
>>>> +};
>>>
>>> "rpm" is not a standard hwmon sysfs attribute. If you don't provide
>>> a single standard hwmon sysfs attribute, having a hwmon driver is
>>> pointless.
>> Guenter Roeck,
>> I will define a new hwmon sysfs attribute node called
>> "hwmon_tachometer_attributes" in hwmon.h like below and update the
>> same in tachometer hwmon driver. Is it fine ?
>> enum hwmon_tachometer_attributes {
>
> Are you kidding me ?
>
> Guenter
Sorry, I just wanted to confirm whether my understanding is correct or
not before implementing it actually.
Or, shall I add this attribute as a part of fan attributes with
"hwmon_fan_rpm" ? or any other way to do it ? I need your inputs in
fixing this.
next prev parent reply other threads:[~2018-02-28 6:12 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-21 6:58 [PATCH 00/10] Implementation of Tegra Tachometer driver Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 01/10] pwm: core: Add support for PWM HW driver with pwm capture only Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 02/10] dt-bindings: Tegra186 tachometer device tree bindings Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 03/10] pwm: tegra: Add PWM based Tachometer driver Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 04/10] hwmon: generic-pwm-tachometer: Add DT binding details Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer Rajkumar Rampelli
2018-02-21 7:15 ` Mikko Perttunen
2018-02-21 14:46 ` Guenter Roeck
2018-02-21 15:20 ` Mikko Perttunen
2018-02-21 16:08 ` Guenter Roeck
2018-02-23 11:45 ` RAJKUMAR
2018-03-01 22:08 ` Rob Herring
2018-02-21 14:50 ` Guenter Roeck
2018-02-28 5:38 ` Rajkumar Rampelli
2018-02-28 5:58 ` Guenter Roeck
2018-02-28 6:07 ` Rajkumar Rampelli
2018-02-28 6:12 ` Rajkumar Rampelli [this message]
2018-02-28 7:03 ` Mikko Perttunen
2018-02-28 14:29 ` Guenter Roeck
2018-03-07 9:47 ` Rajkumar Rampelli
2018-03-07 14:20 ` Guenter Roeck
2018-03-08 6:06 ` Laxman Dewangan
2018-03-08 14:31 ` Guenter Roeck
2018-03-08 15:21 ` Laxman Dewangan
2018-03-08 7:57 ` Mikko Perttunen
2018-03-08 14:33 ` Guenter Roeck
2018-02-21 6:58 ` [PATCH 06/10] arm64: tegra: Add Tachometer Controller on Tegra186 Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 07/10] arm64: tegra: Add PWM based Tachometer support " Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 08/10] arm64: defconfig: enable Nvidia Tegra Tachometer as a module Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 09/10] arm64: defconfig: Enable Generic PWM based Tachometer driver Rajkumar Rampelli
2018-02-21 6:58 ` [PATCH 10/10] arm64: tegra: Add PWM controller on Tegra186 soc Rajkumar Rampelli
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2628eff2-dd33-34f4-a7e1-cfe46ef88a3f@nvidia.com \
--to=rrajk@nvidia.com \
--cc=andy.gross@linaro.org \
--cc=ard.biesheuvel@linaro.org \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=elder@linaro.org \
--cc=gregkh@linuxfoundation.org \
--cc=heiko@sntech.de \
--cc=jdelvare@suse.com \
--cc=jonathanh@nvidia.com \
--cc=krzk@kernel.org \
--cc=kstewart@linuxfoundation.org \
--cc=ldewangan@nvidia.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hwmon@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=mark.rutland@arm.com \
--cc=mmaddireddy@nvidia.com \
--cc=mperttunen@nvidia.com \
--cc=pombredanne@nexb.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=timur@codeaurora.org \
--cc=will.deacon@arm.com \
--cc=xuwei5@hisilicon.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).