Re: [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
On Wednesday 21 February 2018 09:38 PM, Guenter Roeck wrote: On Wed, Feb 21, 2018 at 05:20:29PM +0200, Mikko Perttunen wrote: On 21.02.2018 16:46, Guenter Roeck wrote: On 02/20/2018 11:15 PM, Mikko Perttunen wrote: AIUI, the PWM framework already exposes a sysfs node with period information. We should just use that instead of adding a new driver for this. I am kind of lost. Please explain. Are you saying that we should drop the pwm-fan driver as well (which goes the opposite way), as well as any other drivers doing anything with pwm signals, because after all those signals are already exposed to userspace a sysfs attributes, and a kernel driver to abstract those values is thus not needed ? The only thing this driver does is do a constant division in kernelspace. I'm not really seeing why that couldn't be done in userspace. But if you think it's appropriate to do the RPM conversion in kernelspace then I'm not greatly opposed to that. Isn't that true for any conversion from and to pwm values ? Voltages, for example ? Should those be handled in userspace as well ? Note that I am not entirely convinced that the approach suggested in this patch series makes sense. Patch 4 seems to move the notion of a tachometer into the pwm subsystem. I am not really convinced that this makes sense (maybe all that code should be in the hwmon driver instead, or in a thermal driver if the author prefers). But that is a different issue. The question you raised is if there should be any abstraction to or from raw pwm values in the kernel. Since tachometer driver implements PWM capture callback feature, I have added it under pwm driver as pwm-tegra-tachometer.c driver. If the best approach is to have this tachometer driver under hwmon driver then I will move it to hwmon driver. In any case, we cannot add something like this to device tree since it's not a hardware device. So you are saying there is no means to express in devicetree that a pwm input is connected to a fan ? How is that not hardware ? If so, how do you express in devicetree that a pwm signal is connected to anything ? If we want to describe that the tachometer is connected to a fan, then we should have a fan node in the board's device tree. We don't have a chip that has a thing called "generic-pwm-tachometer" attached to it. (We have chips that have a "nvidia,tegra186-tachometer", so it's proper to have that.) So you are concerned about the property name ? I don't really care how it is called. Guenter Thanks, Mikko Guenter Mikko On 21.02.2018 08:58, 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 --- 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 000..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 + +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 re
HIGHMEM64G Kernel (2.6.23.1) makes system crawl
Hello, I am using a Core 2 Duo E6750 CPU on an intel DG33FB mother board with 4GB Ram, running Debian Lenny. Since the box has 4 GB ram I compiled a big mem kernel, but the machine is very slow while running big mem kernel. It takes about 37 minutes to compile the intel e1000 driver (e1000-7.6.5.tar.gz) from intel site. But it's performing normally when using a non big mem kernel. The diff of the .config between working and non working is as follows. --- config-nobigmem 2007-10-24 12:51:42.0 +0530 +++ config-bigmem 2007-10-24 12:48:56.0 +0530 @@ -1,7 +1,7 @@ # # Automatically generated make config: don't edit # Linux kernel version: 2.6.23.1 -# Wed Oct 24 12:50:21 2007 +# Tue Oct 23 18:08:30 2007 # CONFIG_X86_32=y CONFIG_GENERIC_TIME=y @@ -189,10 +189,11 @@ CONFIG_DELL_RBU=m CONFIG_DCDBAS=m CONFIG_DMIID=y -CONFIG_NOHIGHMEM=y +# CONFIG_NOHIGHMEM is not set # CONFIG_HIGHMEM4G is not set -# CONFIG_HIGHMEM64G is not set +CONFIG_HIGHMEM64G=y CONFIG_PAGE_OFFSET=0xC000 +CONFIG_HIGHMEM=y CONFIG_X86_PAE=y CONFIG_ARCH_FLATMEM_ENABLE=y CONFIG_ARCH_SPARSEMEM_ENABLE=y @@ -211,6 +212,7 @@ CONFIG_BOUNCE=y CONFIG_NR_QUICK=1 CONFIG_VIRT_TO_BUS=y +# CONFIG_HIGHPTE is not set # CONFIG_MATH_EMULATION is not set CONFIG_MTRR=y CONFIG_EFI=y @@ -223,11 +225,13 @@ # CONFIG_HZ_1000 is not set CONFIG_HZ=250 CONFIG_KEXEC=y +# CONFIG_CRASH_DUMP is not set CONFIG_PHYSICAL_START=0x10 # CONFIG_RELOCATABLE is not set CONFIG_PHYSICAL_ALIGN=0x10 CONFIG_HOTPLUG_CPU=y CONFIG_COMPAT_VDSO=y +CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y # # Power management options (ACPI, APM) @@ -1283,6 +1287,7 @@ CONFIG_I2O=m CONFIG_I2O_LCT_NOTIFY_ON_CHANGES=y CONFIG_I2O_EXT_ADAPTEC=y +CONFIG_I2O_EXT_ADAPTEC_DMA64=y CONFIG_I2O_CONFIG=m CONFIG_I2O_CONFIG_OLD_IOCTL=y CONFIG_I2O_BUS=m @@ -3323,6 +3328,7 @@ # CONFIG_DEBUG_SPINLOCK_SLEEP is not set # CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set # CONFIG_DEBUG_KOBJECT is not set +# CONFIG_DEBUG_HIGHMEM is not set CONFIG_DEBUG_BUGVERBOSE=y # CONFIG_DEBUG_INFO is not set # CONFIG_DEBUG_VM is not set I was having this same issue with debian kernel also (2.6.22-2-686), ie stock kernel will work, but big mem is slow. Which is why I tried latest kernel. I am posting the full .config at http://pastebin.ca/747758 dmesg while booting big mem kernel is at http://pastebin.ca/747766 raj - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: HIGHMEM64G Kernel (2.6.23.1) makes system crawl
On 10/24/07, Robert Hancock <[EMAIL PROTECTED]> wrote: > Rajkumar S wrote: > > Hello, > > > > I am using a Core 2 Duo E6750 CPU on an intel DG33FB mother board with > > 4GB Ram, running Debian Lenny. > > > > Since the box has 4 GB ram I compiled a big mem kernel, but the > > machine is very slow while running big mem kernel. It takes about 37 > > minutes to compile the intel e1000 driver (e1000-7.6.5.tar.gz) from > > intel site. But it's performing normally when using a non big mem > > kernel. The diff of the .config between working and non working is as > > follows. > > Post your contents of /proc/mtrr. Likely a BIOS bug which has been seen > on a number of Intel boards, which doesn't mark all of RAM as cachable. I have upgraded the bios to latest (v. 0293 October 02, 2007) Previously the /proc/mtrr was: ravanan:~# cat /proc/mtrr reg00: base=0x ( 0MB), size=2048MB: write-back, count=1 reg01: base=0x8000 (2048MB), size=1024MB: write-back, count=1 reg02: base=0xc000 (3072MB), size= 256MB: write-back, count=1 reg03: base=0xcf80 (3320MB), size= 8MB: uncachable, count=1 reg04: base=0xcf60 (3318MB), size= 2MB: uncachable, count=1 reg05: base=0xcf50 (3317MB), size= 1MB: uncachable, count=1 reg06: base=0x1 (4096MB), size= 512MB: write-back, count=1 reg07: base=0x12000 (4608MB), size= 128MB: write-back, count=1 Now after upgrading the bios it's reg00: base=0x ( 0MB), size=2048MB: write-back, count=1 reg01: base=0x8000 (2048MB), size=1024MB: write-back, count=1 reg02: base=0xc000 (3072MB), size= 256MB: write-back, count=1 reg03: base=0xcf80 (3320MB), size= 8MB: uncachable, count=1 reg04: base=0xcf40 (3316MB), size= 4MB: uncachable, count=1 reg05: base=0x1 (4096MB), size= 512MB: write-back, count=1 reg06: base=0x12000 (4608MB), size= 128MB: write-back, count=1 raj - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [EMAIL PROTECTED] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
On Wednesday 28 February 2018 07:59 PM, Guenter Roeck wrote: On 02/27/2018 11:03 PM, Mikko Perttunen wrote: On 02/28/2018 08:12 AM, Rajkumar Rampelli wrote: 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 --- 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 000..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 + +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 000..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 +#include +#include +#include +#include +#include + +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 attribut
[PATCH V2 2/9] arm64: tegra: Add PWM controller on Tegra186 soc
The NVIDIA Tegra186 SoC has a PWM controller which is used in FAN control use case. Signed-off-by: Rajkumar Rampelli --- V2: no changes in this patch arch/arm64/boot/dts/nvidia/tegra186.dtsi | 11 +++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index b762227..731cd01 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1031,4 +1031,15 @@ (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>; interrupt-parent = <&gic>; }; + + pwm@c34 { + compatible = "nvidia,tegra186-pwm"; + reg = <0x0 0xc34 0x0 0x1>; + clocks = <&bpmp TEGRA186_CLK_PWM4>; + clock-names = "pwm"; + #pwm-cells = <2>; + resets = <&bpmp TEGRA186_RESET_PWM4>; + reset-names = "pwm"; + status = "disabled"; + }; }; -- 2.1.4
[PATCH V2 3/9] dt-bindings: Tegra186 tachometer device tree bindings
Supply Device tree binding documentation for the NVIDIA Tegra186 SoC's Tachometer Controller Signed-off-by: Rajkumar Rampelli --- V2: Renamed compatible string to "nvidia,tegra186-pwm-tachometer" Renamed dt property values of clock-names and reset-names to "tachometer" from "tach" .../bindings/pwm/pwm-tegra-tachometer.txt | 31 ++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt diff --git a/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt b/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt new file mode 100644 index 000..4a7ead4 --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt @@ -0,0 +1,31 @@ +Bindings for a PWM based Tachometer driver + +Required properties: +- compatible: Must be "nvidia,tegra186-pwm-tachometer" +- reg: physical base addresses of the controller and length of + memory mapped region. +- #pwm-cells: should be 2. See pwm.txt in this directory for a + description of the cells format. +- clocks: phandle list of tachometer clocks +- clock-names: should be "tachometer". See clock-bindings.txt in documentations +- resets: phandle to the reset controller for the Tachometer IP +- reset-names: should be "tachometer". See reset.txt in documentations +- nvidia,pulse-per-rev: Integer, pulses per revolution of a Fan. This value + obtained from Fan specification document. +- nvidia,capture-window-len: Integer, window of the Fan Tach monitor, it indicates + that how many period of the input fan tach signal will the FAN TACH logic + monitor. Valid values are 1, 2, 4 and 8 only. + +Example: + tegra_tachometer: tachometer@39c { + compatible = "nvidia,tegra186-pwm-tachometer"; + reg = <0x0 0x039c 0x0 0x10>; + #pwm-cells = <2>; + clocks = <&tegra_car TEGRA186_CLK_TACH>; + clock-names = "tachometer"; + resets = <&tegra_car TEGRA186_RESET_TACH>; + reset-names = "tachometer"; + nvidia,pulse-per-rev = <2>; + nvidia,capture-window-len = <2>; + status = "disabled"; + }; -- 2.1.4
[PATCH V2 4/9] arm64: tegra: Add Tachometer Controller on Tegra186
The NVIDIA Tegra186 SoC has a Tachometer Controller that analyzes the PWM signal of a Fan and reports the period value through pwm interface. Signed-off-by: Rajkumar Rampelli --- V2: Renamed clock-names/reset-names dt properties values to "tachometer" Renamed compatible property value to "nvidia-tegra186-pwm-tachometer" arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts | 5 + arch/arm64/boot/dts/nvidia/tegra186.dtsi | 11 +++ 2 files changed, 16 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts b/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts index bd5305a..13c3e59 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts +++ b/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts @@ -172,4 +172,9 @@ vin-supply = <&vdd_5v0_sys>; }; }; + + tachometer@39c { + nvidia,pulse-per-rev = <2>; + nvidia,capture-window-len = <2>; + }; }; diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index 731cd01..19e1afc 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1042,4 +1042,15 @@ reset-names = "pwm"; status = "disabled"; }; + + tegra_tachometer: tachometer@39c { + compatible = "nvidia,tegra186-pwm-tachometer"; + reg = <0x0 0x039c 0x0 0x10>; + #pwm-cells = <2>; + clocks = <&bpmp TEGRA186_CLK_TACH>; + clock-names = "tachometer"; + resets = <&bpmp TEGRA186_RESET_TACH>; + reset-names = "tachometer"; + status = "disabled"; + }; }; -- 2.1.4
[PATCH V2 1/9] pwm: core: Add support for PWM HW driver with pwm capture only
Add support for pwm HW driver which has only capture functionality. This helps to implement the PWM based Tachometer driver which reads the PWM output signals from electronic fans. PWM Tachometer captures the period and duty cycle of the PWM signal Add conditional checks for callabacks enable(), disable(), config() to check if they are supported by the client driver or not. Skip these callbacks if they are not supported. Signed-off-by: Rajkumar Rampelli --- V2: Added if conditional checks for pwm callbacks since drivers may implements only pwm capture functionality. drivers/pwm/core.c | 21 +++-- 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1581f6a..f70fe68 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -246,6 +246,10 @@ static bool pwm_ops_check(const struct pwm_ops *ops) if (ops->apply) return true; + /* driver supports capture operation */ + if (ops->capture) + return true; + return false; } @@ -495,7 +499,8 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) * ->apply(). */ if (pwm->state.enabled) { - pwm->chip->ops->disable(pwm->chip, pwm); + if (pwm->chip->ops->disable) + pwm->chip->ops->disable(pwm->chip, pwm); pwm->state.enabled = false; } @@ -509,22 +514,26 @@ int pwm_apply_state(struct pwm_device *pwm, struct pwm_state *state) if (state->period != pwm->state.period || state->duty_cycle != pwm->state.duty_cycle) { - err = pwm->chip->ops->config(pwm->chip, pwm, + if (pwm->chip->ops->config) { + err = pwm->chip->ops->config(pwm->chip, pwm, state->duty_cycle, state->period); - if (err) - return err; + if (err) + return err; + } pwm->state.duty_cycle = state->duty_cycle; pwm->state.period = state->period; } if (state->enabled != pwm->state.enabled) { - if (state->enabled) { + if (state->enabled && pwm->chip->ops->enable) { err = pwm->chip->ops->enable(pwm->chip, pwm); if (err) return err; - } else { + } + + if (!state->enabled && pwm->chip->ops->disable) { pwm->chip->ops->disable(pwm->chip, pwm); } -- 2.1.4
[PATCH V2 5/9] pwm: tegra: Add PWM based Tachometer driver
PWM Tachometer driver capture the PWM signal which is output of FAN in general and provide the period of PWM signal which is converted to RPM by SW. Add Tegra Tachometer driver which implements the pwm-capture to measure period. Signed-off-by: Rajkumar Rampelli Signed-off-by: Laxman Dewangan --- V2: Renamed compatible string to "nvidia-tegra186-pwm-tachometer" Renamed arguments of reset and clk apis to "tachometer" from "tach" drivers/pwm/Kconfig| 10 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-tegra-tachometer.c | 303 + 3 files changed, 314 insertions(+) create mode 100644 drivers/pwm/pwm-tegra-tachometer.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 763ee50..29aeeeb 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -454,6 +454,16 @@ config PWM_TEGRA To compile this driver as a module, choose M here: the module will be called pwm-tegra. +config PWM_TEGRA_TACHOMETER + tristate "NVIDIA Tegra Tachometer PWM driver" + depends on ARCH_TEGRA + help + NVIDIA Tegra Tachometer reads the PWM signal and reports the PWM + signal periods. This helps in measuring the fan speed where Fan + output for speed is PWM signal. + + This driver support the Tachometer driver in PWM framework. + config PWM_TIECAP tristate "ECAP PWM support" depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 0258a74..14c183e 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_PWM_STM32_LP)+= pwm-stm32-lp.o obj-$(CONFIG_PWM_STMPE)+= pwm-stmpe.o obj-$(CONFIG_PWM_SUN4I)+= pwm-sun4i.o obj-$(CONFIG_PWM_TEGRA)+= pwm-tegra.o +obj-$(CONFIG_PWM_TEGRA_TACHOMETER) += pwm-tegra-tachometer.o obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o obj-$(CONFIG_PWM_TIPWMSS) += pwm-tipwmss.o diff --git a/drivers/pwm/pwm-tegra-tachometer.c b/drivers/pwm/pwm-tegra-tachometer.c new file mode 100644 index 000..bcc44ce --- /dev/null +++ b/drivers/pwm/pwm-tegra-tachometer.c @@ -0,0 +1,303 @@ +/* + * Tegra Tachometer Pulse-Width-Modulation driver + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Since oscillator clock (38.4MHz) serves as a clock source for + * the tach input controller, 1.0105263MHz (i.e. 38.4/38) has to be + * used as a clock value in the RPM calculations + */ +#define TACH_COUNTER_CLK 1010526 + +#define TACH_FAN_TACH0 0x0 +#define TACH_FAN_TACH0_PERIOD_MASK 0x7 +#define TACH_FAN_TACH0_PERIOD_MAX 0x7 +#define TACH_FAN_TACH0_PERIOD_MIN 0x0 +#define TACH_FAN_TACH0_WIN_LENGTH_SHIFT25 +#define TACH_FAN_TACH0_WIN_LENGTH_MASK 0x3 +#define TACH_FAN_TACH0_OVERFLOW_MASK BIT(24) + +#define TACH_FAN_TACH1 0x4 +#define TACH_FAN_TACH1_HI_MASK 0x7 +/* + * struct pwm_tegra_tach - Tegra tachometer object + * @dev: device providing the Tachometer + * @pulse_per_rev: Pulses per revolution of a Fan + * @capture_window_len: Defines the window of the FAN TACH monitor + * @regs: physical base addresses of the controller + * @clk: phandle list of tachometer clocks + * @rst: phandle to reset the controller + * @chip: PWM chip providing this PWM device + */ +struct pwm_tegra_tach { + struct device *dev; + void __iomem*regs; + struct clk *clk; + struct reset_control*rst; + u32 pulse_per_rev; + u32 capture_window_len; + struct pwm_chip chip; +}; + +static struct pwm_tegra_tach *to_tegra_pwm_chip(struct pwm_chip *chip) +{ + return container_of(chip, struct pwm_tegra_tach, chip); +} + +static u32 tachometer_readl(struct pwm_tegra_tach *ptt, unsigned long reg) +{ + return readl(ptt->regs + reg); +} + +static inline void tachometer_writel(struct pwm_tegra_tach *ptt, u32 val, +unsigned long reg) +{ + writel(val, ptt->regs + reg); +} + +stati
[PATCH V2 7/9] hwmon: pwm-fan: add sysfs node to read rpm of fan
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
[PATCH V2 8/9] arm64: defconfig: enable Nvidia Tegra Tachometer as a module
Tegra Tachometer driver implements PWM capture to measure period. Enable this driver as a module in the ARM64 defconfig. Signed-off-by: Rajkumar Rampelli --- V2: No changes in this patch arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index 634b373..8b2bda7 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -550,6 +550,7 @@ CONFIG_PWM_MESON=m CONFIG_PWM_ROCKCHIP=y CONFIG_PWM_SAMSUNG=y CONFIG_PWM_TEGRA=m +CONFIG_PWM_TEGRA_TACHOMETER=m CONFIG_PHY_RCAR_GEN3_USB2=y CONFIG_PHY_HI6220_USB=y CONFIG_PHY_QCOM_USB_HS=y -- 2.1.4
[PATCH V2 9/9] arm64: defconfig: enable pwm-fan as a loadable module
Enable pwm-fan driver to make use of a PWM interface to read speed of a fan in rotations per minute. Signed-off-by: Rajkumar Rampelli --- V2: Added pwm-fan driver support as a loadable module. Removed generic-pwm-tachometer driver support which was added as part of v1 arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index 8b2bda7..50aa3bce 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -320,6 +320,7 @@ CONFIG_SYSCON_REBOOT_MODE=y CONFIG_BATTERY_BQ27XXX=y CONFIG_SENSORS_ARM_SCPI=y CONFIG_SENSORS_LM90=m +CONFIG_SENSORS_PWM_FAN=m CONFIG_SENSORS_INA2XX=m CONFIG_THERMAL_GOV_POWER_ALLOCATOR=y CONFIG_CPU_THERMAL=y -- 2.1.4
[PATCH V2 0/9] Implementation of Tegra Tachometer driver
The following patches adds support for PWM based Tegra Tachometer driver which implements PWM capture interface to analyze the PWM signal of a electronic fan and reports it in periods and duty cycles. Added fan device attribute fan1_input in pwm-fan driver to monitor the speed of fan in rotations per minute using PWM interface. RPM of Fan will be exposed to user interface through HWMON sysfs interface avialable at location: /sys/class/hwmon/hwmon0/fan1_input Steps to validate Tachometer on Tegra186 SoC: A. push modules pwm-tegra.ko, pwm-tegra-tachometer.ko and pwm-fan.ko to linux device using scp command. scp build/tegra186/drivers/pwm/pwm-tegra.ko ubuntu@10.19.65.176:/tmp/ scp build/tegra186/drivers/pwm/pwm-tegra-tachometer.ko ubuntu@10.19.65.176:/tmp/ scp build/tegra186/drivers/hwmon/pwm-fan.ko ubuntu@10.19.65.176:/tmp/ B. On Linux device console, insert these modules using insmod command. insmod /tmp/pwm-tegra.ko insmod /tmp/pwm-tegra-tachometer.ko insmod /tmp/pwm-fan.ko C. Read RPM value at below sysfs node cat /sys/calss/hwmon/hwmon0/fan1_input D. Change the FAN speed using PWM sysfs interface. Follow below steps for the same: a. cd /sys/class/pwm/pwmchip0 b. ls -la (make sure pwm controller is c34.pwm) Output should be: device -> ../../../c34.pwm c. echo 0 > export d. cd pwmchip0:0 e. echo 8000 > period f. echo 1 > enable g. echo 8000 > duty_cycle # change duty_cycles from 0 to 8000 for FAN speed variation h. cat /sys/calss/hwmon/hwmon0/fan1_input i. echo 4000 > duty_cycle h. cat /sys/calss/hwmon/hwmon0/fan1_input i. echo 2000 > duty_cycle h. cat /sys/calss/hwmon/hwmon0/fan1_input i. echo 0 > duty_cycle h. cat /sys/calss/hwmon/hwmon0/fan1_input Rajkumar Rampelli (9): pwm: core: Add support for PWM HW driver with pwm capture only arm64: tegra: Add PWM controller on Tegra186 soc dt-bindings: Tegra186 tachometer device tree bindings arm64: tegra: Add Tachometer Controller on Tegra186 pwm: tegra: Add PWM based Tachometer driver arm64: tegra: Add pwm based fan support on Tegra186 hwmon: pwm-fan: add sysfs node to read rpm of fan arm64: defconfig: enable Nvidia Tegra Tachometer as a module arm64: defconfig: enable pwm-fan as a loadable module .../bindings/pwm/pwm-tegra-tachometer.txt | 31 +++ arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts | 5 + arch/arm64/boot/dts/nvidia/tegra186.dtsi | 28 ++ arch/arm64/configs/defconfig | 2 + drivers/hwmon/pwm-fan.c| 23 ++ drivers/pwm/Kconfig| 10 + drivers/pwm/Makefile | 1 + drivers/pwm/core.c | 21 +- drivers/pwm/pwm-tegra-tachometer.c | 303 + 9 files changed, 418 insertions(+), 6 deletions(-) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt create mode 100644 drivers/pwm/pwm-tegra-tachometer.c -- 2.1.4
[PATCH V2 6/9] arm64: tegra: Add pwm based fan support on Tegra186
Add pwm fan driver support on Tegra186 SoC. Signed-off-by: Rajkumar Rampelli --- V2: Removed generic-pwm-tachometer driver dt node and using pwm-fan driver for reading fan speed. arch/arm64/boot/dts/nvidia/tegra186.dtsi | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index 19e1afc..27ae73e 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1053,4 +1053,10 @@ reset-names = "tachometer"; status = "disabled"; }; + + pwm_fan { + compatible = "pwm-fan"; + pwms = <&tegra_tachometer 0 100>; + status = "disabled"; + }; }; -- 2.1.4
Re: [PATCH v2] ath10k: transmit queued frames after waking queues
On 2018-05-22 14:15, Niklas Cassel wrote: On Mon, May 21, 2018 at 04:11:38PM -0700, Rajkumar Manoharan wrote: On 2018-05-21 13:43, Niklas Cassel wrote: > The following problem was observed when running iperf: [...] Sorry for the late response. ath10k_mac_tx_push_pending is already called at the end of NAPI handler. Isn't that enough to process pending frames? This is true for e.g. ATH10K_BUS_PCI and ATH10K_BUS_SNOC, but not for e.g. ATH10K_BUS_SDIO and ATH10K_BUS_USB. While there is some SDIO code merged in Kalle's tree already, this problem was found when merging https://git.kernel.org/pub/scm/linux/kernel/git/kvalo/ath.git/?h=ath10k-pending-sdio-usb with Kalle's ath-next branch. Earlier we observed performance issues in calling push_pending from each tx completion. IMHO this change may introduce the same problem again. I prefer functional TX over performance issues, but I agree that it is unfortunate that SDIO doesn't use ath10k_htt_txrx_compl_task(). Erik, is there a reason for this? Thanks for details. Now I see your problem. In case of low latency devices (PCI/SNOC/AHB), all CE rings interrupts are serviced first and later consolidated data processing done from ath10k_htt_txrx_compl_task and then ath10k_mac_tx_push_pending is called from NAPI Poll. In case of high latency devices (USB/SDIO), each endpoints are serviced and all tx/rx jobs are completed from the same context. Hence no need of consolidated processing. Perhaps it would be possible to call ath10k_mac_tx_push_pending() from the equivalent to ath10k_htt_txrx_compl_task(), but from SDIO's point of view. Another solution might be to change so that we only call ath10k_mac_tx_push_pending() from ath10k_txrx_tx_unref() if (htt->num_pending_tx == 0). That should decrease the number of calls to ath10k_mac_tx_push_pending(), while still avoiding a "TX deadlock" scenario for SDIO. This issue is specific to HL devices. But your change is common which will impact LL devices. I would prefer to call ath10k_mac_tx_push_pending after processing all received mbox/urb messages. Export ath10k_mac_tx_push_pending API and call it from USB/SDIO irq handler. Any thoughts? -Rajkumar
Re: [PATCH v2] ath10k: transmit queued frames after waking queues
On 2018-05-23 09:25, Erik Stromdahl wrote: On 05/22/2018 11:15 PM, Niklas Cassel wrote: [...] Perhaps it would be possible to call ath10k_mac_tx_push_pending() from the equivalent to ath10k_htt_txrx_compl_task(), but from SDIO's point of view. An equivalent for SDIO would most likely be *ath10k_htt_htc_t2h_msg_handler* or any of the other functions called from this function. *ath10k_txrx_tx_unref* is actually called from *ath10k_htt_htc_t2h_msg_handler*, so that function could be viewed as an equivalent. If the call should be added in the bus driver (sdio.c) it should most likely be placed in *ath10k_sdio_mbox_rx_process_packets* if (!pkt->trailer_only) { ep->ep_ops.ep_rx_complete(ar_sdio->ar, pkt->skb); ath10k_mac_tx_push_pending(ar_sdio->ar); } else { kfree_skb(pkt->skb) } The above call would of course result in lot's of calls to *ath10k_mac_tx_push_pending* Adding a htt_num_pending check here wouldn't look nice. The HL RX path differs from the LL path in that the t2h_msg_handler returns false indicating that it has consumed the skb. This is because it is the HL RX indication handler that delivers the skb's to mac80211. I also dont prefer to call *_push_pending for every HTC packets. Similar to LL approach, call ath10k_mac_tx_push_pending after processing all pending rx messages like calling from ath10k_sdio_mbox_rxmsg_pending_handler. --- a/drivers/net/wireless/ath/ath10k/sdio.c +++ b/drivers/net/wireless/ath/ath10k/sdio.c @@ -807,6 +807,8 @@ static int ath10k_sdio_mbox_rxmsg_pending_handler(struct ath10k *ar, ath10k_warn(ar, "failed to get pending recv messages: %d\n", ret); + ath10k_mac_tx_push_pending(ar); + return ret; } Another solution could be to add an *else-statement* as a part of the *if (release)* in *ath10k_htt_htc_t2h_msg_handler*, where *ath10k_mac_tx_push_pending* could be called. Something like this perhaps: /* Free the indication buffer */ if (release) dev_kfree_skb_any(skb); else if (!ar->htt.num_pending_tx) ath10k_mac_tx_push_pending(ar); I think I prefer your original patch though. Better to do changes as HL specific path instead in common path. The above change will impact QCA6174 based devices. -Rajkumar
Re: [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
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 --- 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 000..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 + +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 000..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 +#include +#include +#include +#include +#include + +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 hwmo
Re: [PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
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 --- 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 000..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 + +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 000..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 +#include +#include +#include +#include +#include + +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 si
Re: [ath9k-devel] randconfig build error with next-20140519, in drivers/net/wireless/ath/ath9k/dfs.c
On Mon, May 19, 2014 at 09:31:16AM -0700, Jim Davis wrote: > Building with the attached random configuration file, > > In file included from drivers/net/wireless/ath/ath9k/eeprom.h:22:0, > from drivers/net/wireless/ath/ath9k/hw.h:27, > from drivers/net/wireless/ath/ath9k/dfs.c:18: > drivers/net/wireless/ath/ath9k/dfs.c: In function ‘ath9k_dfs_process_phyerr’: > drivers/net/wireless/ath/ath9k/dfs.c:185:14: error: ‘struct ath_softc’ > has no member named ‘debug’ > pe.ts - sc->debug.stats.dfs_stats.last_ts); > ^ > drivers/net/wireless/ath/ath9k/../ath.h:273:41: note: in definition of > macro ‘ath_dbg’ >ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__); \ > ^ > drivers/net/wireless/ath/ath9k/dfs.c:186:5: error: ‘struct ath_softc’ > has no member named ‘debug’ >sc->debug.stats.dfs_stats.last_ts = pe.ts; > ^ > make[5]: *** [drivers/net/wireless/ath/ath9k/dfs.o] Error 1 Please select CONFIG_ATH9K_DEBUGFS. -Rajkumar -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [ath9k-devel] randconfig build error with next-20140519, in drivers/net/wireless/ath/ath9k/dfs.c
On Wed, May 21, 2014 at 10:12:26PM +1000, Julian Calaby wrote: > Hi Rajkumar, > > On Wed, May 21, 2014 at 9:01 PM, Rajkumar Manoharan > wrote: > > On Mon, May 19, 2014 at 09:31:16AM -0700, Jim Davis wrote: > >> Building with the attached random configuration file, > >> > >> In file included from drivers/net/wireless/ath/ath9k/eeprom.h:22:0, > >> from drivers/net/wireless/ath/ath9k/hw.h:27, > >> from drivers/net/wireless/ath/ath9k/dfs.c:18: > >> drivers/net/wireless/ath/ath9k/dfs.c: In function > >> ‘ath9k_dfs_process_phyerr’: > >> drivers/net/wireless/ath/ath9k/dfs.c:185:14: error: ‘struct ath_softc’ > >> has no member named ‘debug’ > >> pe.ts - sc->debug.stats.dfs_stats.last_ts); > >> ^ > >> drivers/net/wireless/ath/ath9k/../ath.h:273:41: note: in definition of > >> macro ‘ath_dbg’ > >>ath_printk(KERN_DEBUG, common, fmt, ##__VA_ARGS__); \ > >> ^ > >> drivers/net/wireless/ath/ath9k/dfs.c:186:5: error: ‘struct ath_softc’ > >> has no member named ‘debug’ > >>sc->debug.stats.dfs_stats.last_ts = pe.ts; > >> ^ > >> make[5]: *** [drivers/net/wireless/ath/ath9k/dfs.o] Error 1 > > > > Please select CONFIG_ATH9K_DEBUGFS. > > The point of randconfig builds is to ensure that there it's really > unlikely that there are any config combinations that don't build, even > if they're utterly insane. > > You should really change the ath9k Kconfig rules or move or add ifdefs > to prevent this from being possible. > Completely agree. But ath9k Kconfig has proper dependecy for ATH9K_DFS_DEBUGFS. I am wondering how it is selected w/o ATH9K_DEBUGFS. config ATH9K_DFS_DEBUGFS def_bool y depends on ATH9K_DEBUGFS && ATH9K_DFS_CERTIFIED Should it be like this? config ATH9K_DFS_DEBUGFS def_bool y if (ATH9K_DEBUGFS && ATH9K_DFS_CERTIFIED) -Rajkumar -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [PATCH v2] ath10k: transmit queued frames after waking queues
On 2018-05-21 13:43, Niklas Cassel wrote: The following problem was observed when running iperf: [...] In order to avoid trying to flush the queue every time we free a frame, only do this when there are 3 or less frames pending, and while we actually have frames in the queue. This logic was copied from mt76_txq_schedule (mt76), one of few other drivers that are actually using wake_tx_queue. Suggested-by: Toke Høiland-Jørgensen Signed-off-by: Niklas Cassel --- Changes since V1: use READ_ONCE() to disallow the compiler optimizing things in undesirable ways. drivers/net/wireless/ath/ath10k/txrx.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/net/wireless/ath/ath10k/txrx.c b/drivers/net/wireless/ath/ath10k/txrx.c index cda164f6e9f6..264cf0bd5c00 100644 --- a/drivers/net/wireless/ath/ath10k/txrx.c +++ b/drivers/net/wireless/ath/ath10k/txrx.c @@ -95,6 +95,9 @@ int ath10k_txrx_tx_unref(struct ath10k_htt *htt, wake_up(&htt->empty_tx_wq); spin_unlock_bh(&htt->tx_lock); + if (READ_ONCE(htt->num_pending_tx) <= 3 && !list_empty(&ar->txqs)) + ath10k_mac_tx_push_pending(ar); + Niklas, Sorry for the late response. ath10k_mac_tx_push_pending is already called at the end of NAPI handler. Isn't that enough to process pending frames? Earlier we observed performance issues in calling push_pending from each tx completion. IMHO this change may introduce the same problem again. -Rajkumar
Re: [PATCH] ath11k: Fix some resource leaks in error path in 'ath11k_thermal_register()'
On 2020-05-13 13:14, Christophe JAILLET wrote: If 'thermal_cooling_device_register()' fails, we must undo what has been allocated so far. So we must go to 'err_thermal_destroy' instead of returning directly In case of error in 'ath11k_thermal_register()', the previous 'thermal_cooling_device_register()' call must also be undone. Move the 'ar->thermal.cdev = cdev' a few lines above in order for this to be done in 'ath11k_thermal_unregister()' which is called in the error handling path. Fixes: 2a63bbca06b2 ("ath11k: add thermal cooling device support") Signed-off-by: Christophe JAILLET --- I'm not 100% confident with this patch. - When calling 'ath11k_thermal_unregister()', we try to release some resources that have not been allocated yet. I don't know if it can be an issue or not. - I think that we should propagate the error code, instead of forcing -EINVAL. Good catch. -Rajkumar
Re: [RFC 2/7] ath10k: Add support to process rx packet in thread
On 2020-07-21 10:14, Rakesh Pillai wrote: NAPI instance gets scheduled on a CPU core on which the IRQ was triggered. The processing of rx packets can be CPU intensive and since NAPI cannot be moved to a different CPU core, to get better performance, its better to move the gist of rx packet processing in a high priority thread. Add the init/deinit part for a thread to process the receive packets. IMHO this defeat the whole purpose of NAPI. Originally in ath10k irq processing happened in tasklet (high priority) context which in turn push more data to net core even though net is unable to process driver data as both happen in different context (fast producer - slow consumer) issue. Why can't CPU governor schedule the interrupts in less loaded CPU core? Otherwise you can play with different RPS and affinity settings to meet your requirement. IMO introducing high priority tasklets/threads is not viable solution. -Rajkumar
Re: [RFC 2/7] ath10k: Add support to process rx packet in thread
On 2020-07-22 06:00, Felix Fietkau wrote: On 2020-07-22 14:55, Johannes Berg wrote: On Wed, 2020-07-22 at 14:27 +0200, Felix Fietkau wrote: I'm considering testing a different approach (with mt76 initially): - Add a mac80211 rx function that puts processed skbs into a list instead of handing them to the network stack directly. Would this be *after* all the mac80211 processing, i.e. in place of the rx-up-to-stack? Yes, it would run all the rx handlers normally and then put the resulting skbs into a list instead of calling netif_receive_skb or napi_gro_frags. Felix, This seems like split & batch processing. In past (ath9k), we observed some behavioral differences between netif_rx and netif_receive_skb. The intermediate queue in netif_rx changed not just performance but also time sensitive application data. Agree that wireless stack processing might be heavier than ethernet packet processing. If the hardware supports rx decap offload, NAPI processing shouldn't be an issue. right? -Rajkumar
Re: [PATCH v2] ath10k: Replace zero-length array with flexible-array
On 2020-05-06 21:11, Gustavo A. R. Silva wrote: [...] static inline struct htt_stats_conf_item *htt_stats_conf_next_item( @@ -1674,7 +1674,7 @@ struct htt_tx_fetch_ind { __le16 num_resp_ids; __le16 num_records; struct htt_tx_fetch_record records[0]; - __le32 resp_ids[0]; /* ath10k_htt_get_tx_fetch_ind_resp_ids() */ + __le32 resp_ids[]; /* ath10k_htt_get_tx_fetch_ind_resp_ids() */ } __packed; Missed to handle records[0]. -Rajkumar
[PATCH 00/10] Implementation of Tegra Tachometer driver
The following patches adds support for PWM based Tegra Tachometer driver which implements PWM capture interface to analyze the PWM signal of a electronic fan and reports it in periods and duty cycles. Generic PWM Tachometer implemented to monitor the speed of fan in rpms using PWM interface. RPM of Fan will be exposed to user interface through HWMON sysfs interface avialable at below location /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm Steps to validate Tachometer: A. push modules pwm-tegra.ko, pwm-tegra-tachometer.ko and generic-pwm-tachometer.ko to linux device using scp command. scp build/tegra186/drivers/pwm/pwm-tegra.ko ubuntu@10.19.65.176:/tmp/ scp build/tegra186/drivers/pwm/pwm-tegra-tachometer.ko ubuntu@10.19.65.176:/tmp/ scp build/tegra186/drivers/hwmon/generic-pwm-tachometer.ko ubuntu@10.19.65.176:/tmp/ B. On Linux device console, insert these modules using insmod command. insmod /tmp/pwm-tegra.ko insmod /tmp/pwm-tegra-tachometer.ko insmod /tmp/generic-pwm-tachometer.ko C. Read RPM value at below sysfs node cat /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm D. Change the FAN speed using PWM sysfs interface. Follow below steps for the same: a. cd /sys/class/pwm/pwmchip0 b. ls -la (make sure pwm controller is c34.pwm) Output should be: device -> ../../../c34.pwm c. echo 0 > export d. cd pwmchip0:0 e. echo 8000 > period f. echo 1 > enable g. echo 7000 > duty_cycle # change duty_cycles from 0 to 7000 and see FAN speed h. cat /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm i. echo 4000 > duty_cycle h. cat /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm i. echo 2000 > duty_cycle h. cat /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm i. echo 0 > duty_cycle h. cat /sys/devices/platform/generic_pwm_tachometer/hwmon/hwmon0/rpm Rajkumar Rampelli (10): pwm: core: Add support for PWM HW driver with pwm capture only dt-bindings: Tegra186 tachometer device tree bindings pwm: tegra: Add PWM based Tachometer driver hwmon: generic-pwm-tachometer: Add DT binding details hwmon: generic-pwm-tachometer: Add generic PWM based tachometer arm64: tegra: Add Tachometer Controller on Tegra186 arm64: tegra: Add PWM based Tachometer support on Tegra186 arm64: defconfig: enable Nvidia Tegra Tachometer as a module arm64: defconfig: Enable Generic PWM based Tachometer driver arm64: tegra: Add PWM controller on Tegra186 soc .../bindings/hwmon/generic-pwm-tachometer.txt | 25 ++ .../bindings/pwm/pwm-tegra-tachometer.txt | 31 +++ Documentation/hwmon/generic-pwm-tachometer | 17 ++ arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts | 5 + arch/arm64/boot/dts/nvidia/tegra186.dtsi | 28 ++ arch/arm64/configs/defconfig | 2 + drivers/hwmon/Kconfig | 10 + drivers/hwmon/Makefile | 1 + drivers/hwmon/generic-pwm-tachometer.c | 112 drivers/pwm/Kconfig| 10 + drivers/pwm/Makefile | 1 + drivers/pwm/core.c | 4 + drivers/pwm/pwm-tegra-tachometer.c | 303 + 13 files changed, 549 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/generic-pwm-tachometer.txt create mode 100644 Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt create mode 100644 Documentation/hwmon/generic-pwm-tachometer create mode 100644 drivers/hwmon/generic-pwm-tachometer.c create mode 100644 drivers/pwm/pwm-tegra-tachometer.c -- 2.1.4
[PATCH 03/10] pwm: tegra: Add PWM based Tachometer driver
PWM Tachometer driver capture the PWM signal which is output of FAN in general and provide the period of PWM signal which is converted to RPM by SW. Add Tegra Tachometer driver which implements the pwm-capture to measure period. Signed-off-by: Rajkumar Rampelli Signed-off-by: Laxman Dewangan --- drivers/pwm/Kconfig| 10 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-tegra-tachometer.c | 303 + 3 files changed, 314 insertions(+) create mode 100644 drivers/pwm/pwm-tegra-tachometer.c diff --git a/drivers/pwm/Kconfig b/drivers/pwm/Kconfig index 763ee50..29aeeeb 100644 --- a/drivers/pwm/Kconfig +++ b/drivers/pwm/Kconfig @@ -454,6 +454,16 @@ config PWM_TEGRA To compile this driver as a module, choose M here: the module will be called pwm-tegra. +config PWM_TEGRA_TACHOMETER + tristate "NVIDIA Tegra Tachometer PWM driver" + depends on ARCH_TEGRA + help + NVIDIA Tegra Tachometer reads the PWM signal and reports the PWM + signal periods. This helps in measuring the fan speed where Fan + output for speed is PWM signal. + + This driver support the Tachometer driver in PWM framework. + config PWM_TIECAP tristate "ECAP PWM support" depends on ARCH_OMAP2PLUS || ARCH_DAVINCI_DA8XX || ARCH_KEYSTONE diff --git a/drivers/pwm/Makefile b/drivers/pwm/Makefile index 0258a74..14c183e 100644 --- a/drivers/pwm/Makefile +++ b/drivers/pwm/Makefile @@ -45,6 +45,7 @@ obj-$(CONFIG_PWM_STM32_LP)+= pwm-stm32-lp.o obj-$(CONFIG_PWM_STMPE)+= pwm-stmpe.o obj-$(CONFIG_PWM_SUN4I)+= pwm-sun4i.o obj-$(CONFIG_PWM_TEGRA)+= pwm-tegra.o +obj-$(CONFIG_PWM_TEGRA_TACHOMETER) += pwm-tegra-tachometer.o obj-$(CONFIG_PWM_TIECAP) += pwm-tiecap.o obj-$(CONFIG_PWM_TIEHRPWM) += pwm-tiehrpwm.o obj-$(CONFIG_PWM_TIPWMSS) += pwm-tipwmss.o diff --git a/drivers/pwm/pwm-tegra-tachometer.c b/drivers/pwm/pwm-tegra-tachometer.c new file mode 100644 index 000..1304e47 --- /dev/null +++ b/drivers/pwm/pwm-tegra-tachometer.c @@ -0,0 +1,303 @@ +/* + * Tegra Tachometer Pulse-Width-Modulation driver + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Since oscillator clock (38.4MHz) serves as a clock source for + * the tach input controller, 1.0105263MHz (i.e. 38.4/38) has to be + * used as a clock value in the RPM calculations + */ +#define TACH_COUNTER_CLK 1010526 + +#define TACH_FAN_TACH0 0x0 +#define TACH_FAN_TACH0_PERIOD_MASK 0x7 +#define TACH_FAN_TACH0_PERIOD_MAX 0x7 +#define TACH_FAN_TACH0_PERIOD_MIN 0x0 +#define TACH_FAN_TACH0_WIN_LENGTH_SHIFT25 +#define TACH_FAN_TACH0_WIN_LENGTH_MASK 0x3 +#define TACH_FAN_TACH0_OVERFLOW_MASK BIT(24) + +#define TACH_FAN_TACH1 0x4 +#define TACH_FAN_TACH1_HI_MASK 0x7 +/* + * struct pwm_tegra_tach - Tegra tachometer object + * @dev: device providing the Tachometer + * @pulse_per_rev: Pulses per revolution of a Fan + * @capture_window_len: Defines the window of the FAN TACH monitor + * @regs: physical base addresses of the controller + * @clk: phandle list of tachometer clocks + * @rst: phandle to reset the controller + * @chip: PWM chip providing this PWM device + */ +struct pwm_tegra_tach { + struct device *dev; + void __iomem*regs; + struct clk *clk; + struct reset_control*rst; + u32 pulse_per_rev; + u32 capture_window_len; + struct pwm_chip chip; +}; + +static struct pwm_tegra_tach *to_tegra_pwm_chip(struct pwm_chip *chip) +{ + return container_of(chip, struct pwm_tegra_tach, chip); +} + +static u32 tachometer_readl(struct pwm_tegra_tach *ptt, unsigned long reg) +{ + return readl(ptt->regs + reg); +} + +static inline void tachometer_writel(struct pwm_tegra_tach *ptt, u32 val, +unsigned long reg) +{ + writel(val, ptt->regs + reg); +} + +static int pwm_tegra_tach_set_wlen(struct pwm_tegra_tach *ptt, + u32 window_length) +{ + u32 tach0, wlen; + + /* +* As per FAN Spec, the
[PATCH 02/10] dt-bindings: Tegra186 tachometer device tree bindings
Supply Device tree binding documentation for the NVIDIA Tegra186 SoC's Tachometer Controller Signed-off-by: Rajkumar Rampelli --- .../bindings/pwm/pwm-tegra-tachometer.txt | 31 ++ 1 file changed, 31 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt diff --git a/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt b/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt new file mode 100644 index 000..4a7ead4 --- /dev/null +++ b/Documentation/devicetree/bindings/pwm/pwm-tegra-tachometer.txt @@ -0,0 +1,31 @@ +Bindings for a PWM based Tachometer driver + +Required properties: +- compatible: Must be "nvidia,tegra186-pwm-tachometer" +- reg: physical base addresses of the controller and length of + memory mapped region. +- #pwm-cells: should be 2. See pwm.txt in this directory for a + description of the cells format. +- clocks: phandle list of tachometer clocks +- clock-names: should be "tachometer". See clock-bindings.txt in documentations +- resets: phandle to the reset controller for the Tachometer IP +- reset-names: should be "tachometer". See reset.txt in documentations +- nvidia,pulse-per-rev: Integer, pulses per revolution of a Fan. This value + obtained from Fan specification document. +- nvidia,capture-window-len: Integer, window of the Fan Tach monitor, it indicates + that how many period of the input fan tach signal will the FAN TACH logic + monitor. Valid values are 1, 2, 4 and 8 only. + +Example: + tegra_tachometer: tachometer@39c { + compatible = "nvidia,tegra186-pwm-tachometer"; + reg = <0x0 0x039c 0x0 0x10>; + #pwm-cells = <2>; + clocks = <&tegra_car TEGRA186_CLK_TACH>; + clock-names = "tachometer"; + resets = <&tegra_car TEGRA186_RESET_TACH>; + reset-names = "tachometer"; + nvidia,pulse-per-rev = <2>; + nvidia,capture-window-len = <2>; + status = "disabled"; + }; -- 2.1.4
[PATCH 01/10] pwm: core: Add support for PWM HW driver with pwm capture only
Add support for pwm HW driver which has only capture functionality. This helps to implement the PWM based Tachometer driver which reads the PWM output signals from electronic fans. PWM Tachometer captures the period and duty cycle of the PWM signal Signed-off-by: Rajkumar Rampelli --- drivers/pwm/core.c | 4 1 file changed, 4 insertions(+) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 1581f6a..87d14c9 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -246,6 +246,10 @@ static bool pwm_ops_check(const struct pwm_ops *ops) if (ops->apply) return true; + /* driver supports capture operation */ + if (ops->capture) + return true; + return false; } -- 2.1.4
[PATCH 04/10] hwmon: generic-pwm-tachometer: Add DT binding details
Add DT binding details for the PWM based generic tachometer driver which gets the period of the PWM tach-output from Fan via PWM IP having capability of capturing the signal. Signed-off-by: Rajkumar Rampelli --- .../bindings/hwmon/generic-pwm-tachometer.txt | 25 ++ 1 file changed, 25 insertions(+) create mode 100644 Documentation/devicetree/bindings/hwmon/generic-pwm-tachometer.txt diff --git a/Documentation/devicetree/bindings/hwmon/generic-pwm-tachometer.txt b/Documentation/devicetree/bindings/hwmon/generic-pwm-tachometer.txt new file mode 100644 index 000..3541fe5 --- /dev/null +++ b/Documentation/devicetree/bindings/hwmon/generic-pwm-tachometer.txt @@ -0,0 +1,25 @@ +Device tree bindings for fan tach output connected to PWM controller with +PWM capture capability. + +Required properties: +- compatible : Should be "generic-pwm-tachometer" +- pwms : PWM handle. Please refer pwm.txt DT binding for more details. + +Example: + tegra_tachometer: tachometer@39c { + compatible = "nvidia,tegra186-pwm-tachometer"; + reg = <0x0 0x039c 0x0 0x10>; + clocks = <&bpmp_clks TEGRA194_CLK_TACH>; + clock-names = "tachometer"; + resets = <&bpmp_resets TEGRA194_RESET_TACH>; + reset-names = "tachometer"; + nvidia,pulse-per-rev = <2>; + nvidia,sampling-window = <2>; + status = "okay"; + }; + + generic_pwm_tachometer { + compatible = "generic-pwm-tachometer"; + pwms = <&tegra_tachometer 0 100>; + status = "okay"; + }; -- 2.1.4
[PATCH 05/10] hwmon: generic-pwm-tachometer: Add generic PWM based tachometer
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 --- 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 000..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 + +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 000..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 +#include +#include +#include +#include +#include + +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, +}; + +ATTRIBUTE_GROUPS(pwm_tach); + +static int pwm_tach_probe(struct platform_device *pdev) +{ + struct pwm_hwmon_tach *ptt; + int err; + + ptt = devm_kzalloc(&pdev->dev, s
[PATCH 06/10] arm64: tegra: Add Tachometer Controller on Tegra186
The NVIDIA Tegra186 SoC has a Tachometer Controller that analyzes the PWM signal of a Fan and reports the period value through pwm interface. Signed-off-by: Rajkumar Rampelli --- arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts | 5 + arch/arm64/boot/dts/nvidia/tegra186.dtsi | 11 +++ 2 files changed, 16 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts b/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts index bd5305a..13c3e59 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts +++ b/arch/arm64/boot/dts/nvidia/tegra186-p2771-.dts @@ -172,4 +172,9 @@ vin-supply = <&vdd_5v0_sys>; }; }; + + tachometer@39c { + nvidia,pulse-per-rev = <2>; + nvidia,capture-window-len = <2>; + }; }; diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index b762227..8f2d598 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1031,4 +1031,15 @@ (GIC_CPU_MASK_SIMPLE(4) | IRQ_TYPE_LEVEL_LOW)>; interrupt-parent = <&gic>; }; + + tegra_tachometer: tachometer@39c { + compatible = "nvidia,tegra186-pwm-tachometer"; + reg = <0x0 0x039c 0x0 0x10>; + #pwm-cells = <2>; + clocks = <&bpmp TEGRA186_CLK_TACH>; + clock-names = "tachometer"; + resets = <&bpmp TEGRA186_RESET_TACH>; + reset-names = "tachometer"; + status = "disabled"; + }; }; -- 2.1.4
[PATCH 09/10] arm64: defconfig: Enable Generic PWM based Tachometer driver
Enable Generic PWM based Tachometer driver which implements a simple interface for monitoring the speed of a fan in roatations per minute, and exposes it to the user space by using the hwmon's sysfs interface. Enable this driver as a module in the ARM64 defconfig. Signed-off-by: Rajkumar Rampelli --- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index 8b2bda7..1b29109 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -321,6 +321,7 @@ CONFIG_BATTERY_BQ27XXX=y CONFIG_SENSORS_ARM_SCPI=y CONFIG_SENSORS_LM90=m CONFIG_SENSORS_INA2XX=m +CONFIG_GENERIC_PWM_TACHOMETER=m CONFIG_THERMAL_GOV_POWER_ALLOCATOR=y CONFIG_CPU_THERMAL=y CONFIG_THERMAL_EMULATION=y -- 2.1.4
[PATCH 10/10] arm64: tegra: Add PWM controller on Tegra186 soc
The NVIDIA Tegra186 SoC has a PWM controller which is used in FAN control use case. Signed-off-by: Rajkumar Rampelli --- arch/arm64/boot/dts/nvidia/tegra186.dtsi | 11 +++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index 37149e9..c6f154e 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1032,6 +1032,17 @@ interrupt-parent = <&gic>; }; + pwm@c34 { + compatible = "nvidia,tegra186-pwm"; + reg = <0x0 0xc34 0x0 0x1>; + clocks = <&bpmp TEGRA186_CLK_PWM4>; + clock-names = "pwm"; + #pwm-cells = <2>; + resets = <&bpmp TEGRA186_RESET_PWM4>; + reset-names = "pwm"; + status = "disabled"; + }; + tegra_tachometer: tachometer@39c { compatible = "nvidia,tegra186-pwm-tachometer"; reg = <0x0 0x039c 0x0 0x10>; -- 2.1.4
[PATCH 07/10] arm64: tegra: Add PWM based Tachometer support on Tegra186
Add PWM based Tachometer support on Tegra186 to measure number of rotations of a Fan per minute by using PWM capture interface Signed-off-by: Rajkumar Rampelli --- arch/arm64/boot/dts/nvidia/tegra186.dtsi | 6 ++ 1 file changed, 6 insertions(+) diff --git a/arch/arm64/boot/dts/nvidia/tegra186.dtsi b/arch/arm64/boot/dts/nvidia/tegra186.dtsi index 8f2d598..37149e9 100644 --- a/arch/arm64/boot/dts/nvidia/tegra186.dtsi +++ b/arch/arm64/boot/dts/nvidia/tegra186.dtsi @@ -1042,4 +1042,10 @@ reset-names = "tachometer"; status = "disabled"; }; + + generic_pwm_tachometer { + compatible = "generic-pwm-tachometer"; + pwms = <&tegra_tachometer 0 100>; + status = "disabled"; + }; }; -- 2.1.4
[PATCH 08/10] arm64: defconfig: enable Nvidia Tegra Tachometer as a module
Tegra Tachometer driver implements PWM capture to measure period. Enable this driver as a module in the ARM64 defconfig. Signed-off-by: Rajkumar Rampelli --- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig index 634b373..8b2bda7 100644 --- a/arch/arm64/configs/defconfig +++ b/arch/arm64/configs/defconfig @@ -550,6 +550,7 @@ CONFIG_PWM_MESON=m CONFIG_PWM_ROCKCHIP=y CONFIG_PWM_SAMSUNG=y CONFIG_PWM_TEGRA=m +CONFIG_PWM_TEGRA_TACHOMETER=m CONFIG_PHY_RCAR_GEN3_USB2=y CONFIG_PHY_HI6220_USB=y CONFIG_PHY_QCOM_USB_HS=y -- 2.1.4