Jetson Nano second PWM-FAN

Good afternoon, dear Nvidia! I already successful attached PWM2 to sysfs but now I have to read its tacho that we attached to pin PV0.
I tried to find in the internet common solution how to throw tacho to sysfs but couldn’t find anything. Then I tried to create pwm-fan2 and encountered the next problem:

turn4:~$ ls /sys/devices/pwm-fan
cur_pwm  driver_override         fan_kickstart  fan_rpm_in_limit  kickstart_params  of_node  pwm_cap        pwm_state_map  state_cap  subsystem    target_pwm    uevent
driver   fan_available_profiles  fan_profile    hwmon             modalias          power    pwm_rpm_table  rpm_measured   step_time  tach_enable  temp_control
turn4:~$ ls /sys/devices/pwm-fan2
driver_override  modalias  of_node  power  subsystem  uevent

It seems that the driver was not attached smoothly. How could I fix this? My devtree:
tegra210-porg-pwm-fen.dtsi:

/*
 * Copyright (c) 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 <dt-bindings/pwm/pwm.h>

/ {
	pwm_fan_shared_data: pfsd {
		num_resources = <0>;
		secret = <47>;
		active_steps = <10>;
		active_rpm = <0 1000 2000 3000 4000 5000 6000 7000 10000 11000>;
		active_rru = <40 2 1 1 1 1 1 1 1 1>;
		active_rrd = <40 2 1 1 1 1 1 1 1 1>;
		state_cap_lookup = <2 2 2 2 3 3 3 4 4 4>;
		pwm_period = <45334>;
		pwm_id = <3>;
		step_time = <100>; /* mesecs */
		state_cap = <7>;
		active_pwm_max = <255>;
		tach_gpio =  <&gpio TEGRA_GPIO(Z, 2) GPIO_ACTIVE_LOW>; /* TEGRA_GPIO_PZ2 */
		pwm_gpio = <&gpio TEGRA_GPIO(E, 7) GPIO_ACTIVE_LOW>; /* TEGRA_GPIO_PE7 */
		pwm_polarity = <PWM_POLARITY_NORMAL>;
		suspend_state = <0>;
		tach_period = <1000>;
	};

	pwm-fan {
		compatible = "pwm-fan";
		status = "okay";
		pwms = <&tegra_pwm 3 45334>;
		shared_data = <&pwm_fan_shared_data>;
		active_pwm = <0 80 120 160 255 255 255 255 255 255>;
	};

	pwm_fan_shared_data2: pfsd {
		num_resources = <0>;
		secret = <47>;
		active_steps = <10>;
		active_rpm = <0 1000 2000 3000 4000 5000 6000 7000 10000 11000>;
		active_rru = <40 2 1 1 1 1 1 1 1 1>;
		active_rrd = <40 2 1 1 1 1 1 1 1 1>;
		state_cap_lookup = <2 2 2 2 3 3 3 4 4 4>;
		pwm_period = <45334>;
		pwm_id = <2>;
		step_time = <100>; /* mesecs */
		state_cap = <7>;
		active_pwm_max = <255>;
		tach_gpio =  <&gpio TEGRA_GPIO(V, 0) GPIO_ACTIVE_LOW>;
		pwm_gpio = <&gpio TEGRA_GPIO(E, 6) GPIO_ACTIVE_LOW>;
		pwm_polarity = <PWM_POLARITY_NORMAL>;
		suspend_state = <0>;
		tach_period = <1000>;
	};

	pwm-fan2 {
		compatible = "pwm-fan";
		status = "okay";
		pwms = <&tegra_pwm 2 45334>;
		shared_data = <&pwm_fan_shared_data2>;
		active_pwm = <0 80 120 160 255 255 255 255 255 255>;
	};
};

pinmux for pwm and tacho pins:

			pe6 {
			    nvidia,pins = "pe6";
			    nvidia,function = "pwm2";
			    nvidia,pull = <TEGRA_PIN_PULL_NONE>;
			    nvidia,tristate = <TEGRA_PIN_DISABLE>;
			    nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			lcd_bl_pwm_pv0 {
				nvidia,pins = "lcd_bl_pwm_pv0";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};
			pe7 {
				nvidia,pins = "pe7";
				nvidia,function = "pwm3";
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_DISABLE>;
			};
			pz2 {
				nvidia,pins = "pz2";
				nvidia,pull = <TEGRA_PIN_PULL_UP>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
			};

pwm-fan is working well and tacho is working well too but my pwm-fan2 (that I created) is not at all.
I need to configure pwm-fan2 like pwm-fan with the tacho or you could help me to forward tacho2 to sysfs without pwm2 then I continue to use pwm2 separately from sysfs and will read tacho2 from sysfs separately too.

Hi ATAineri,

Are you using the devkit or custom board for Jetson Nano?
What’s your Jetpack version in use?

Do you mean that you want to read the rpm of the fan controlled by PWM2?

Please also share the full dmesg for further check.

I’m using Jetpack 32.7.4 - the final version for JN.
I only want to read tacho, I even don’t need second fan to be announced in devtree. Is it possibly to somehow simply forward tach2 to sysfs?
Now we are using custom board but in the terms of PWM and tacho it is copy of devboard.
Do you mean that you want to read the rpm of the fan controlled by PWM2?
Yes)

Could you read the tacho through /sys/devices/pwm-fan/rpm_measured?
If so, why you need another tach2?
I thought you have the second fan and want to measure its rpm.

I need tacho 2 for another FAN. I using PWM2 from sysfs manually for another FAN and it is working but I cannot read its tacho 2. In pinout I see that there are 3 tacho pin and I want to use 2 of it but I cannot understand how to provide this 2nd tacho to sysfs.

It seems something not configured for pwm-fan2.
Please share the full dmesg for further check.

Please also share the block diagram of your connection for both pwm-fan and pwm-fan2.

dmesg.txt (59.1 KB)
pwm-fan2 told that it cannot use PV0 for fan-tach I don’t understand why…

sudo cat /sys/kernel/debug/pinctrl/700008d4.pinmux/pinmux-pins
pin 168 (LCD_BL_PWM PV0): (MUX UNCLAIMED) tegra-gpio:168
sudo cat /sys/kernel/debug/gpio
 gpio-168 (GPIO07              |pwm-fan-tach        ) in  hi IRQ

Part of the scheme:
image
I checked that this pin is not using in dev tree in another part - it have to be OK, but not.
Is it even possible to use PV0 as tach?

I tried to use for tacho2 GPIO4 because it has IRQ and it didn’t work too.
Then I tried to assign GPIO4 as tacho for fan1 and gpio8 that worked on fan1 attach to fan 2 and now fan1 is working with gpio4 as tacho normally but fan2 is not forking because of GPIO8 that working normally on fan1.
Then it seems that all pins that I tried to use as tacho for the fan2 is not working with the same error -16 unable to request tacho pin and all of this pins is working normal on fan1.

I cannot understand what function is returning -EBUSY on gpio_request function:

		fan_data->tach_irq = gpio_to_irq(fan_data->tach_gpio);
		err = gpio_request(fan_data->tach_gpio, "pwm-fan-tach");
		if (err < 0) {
			dev_err(&pdev->dev, "fan tach gpio request failed\n");
			goto tach_gpio_request_fail;
		}

It is pretty obvious that tacho initialization crashes here, I greped all over gpio-tegra driver in the kernel and in the nvidia folder near the kernel, I greped pinctrl tegra driver and found only 1 function that could return -EBUSY but it appears that the only function that could threw -EBUSY gpio_is_accessible is not calling during the PWM fan initialization. I tried to printk smth out of this and nothing was peinted as if that function was not called at all.

I discovered what is throwing -EBUSY:

static int __gpiod_request(struct gpio_desc *desc, const char *label)
{
	struct gpio_chip	*chip = desc->gdev->chip;
	int			status;
	unsigned long		flags;
	bool			hogged = false;

	spin_lock_irqsave(&gpio_lock, flags);

	/* NOTE:  gpio_request() can be called in early boot,
	 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
	 */

	if (test_and_set_bit(FLAG_REQUESTED, &desc->flags) == 0) {
		desc_set_label(desc, label ? : "?");
		status = 0;
	} else {
		if (test_bit(FLAG_IS_HOGGED, &desc->flags)) {
			hogged = true;
			desc_set_label(desc, label ? : "?");
			clear_bit(FLAG_IS_HOGGED, &desc->flags);
			status = 0;
		} else {
			printk(KERN_INFO "Exact -EBUSY I tried to find!\n");
			status = -EBUSY;
			goto done;
		}
	}

It seems that the method I declared tacho pin in devtree is bringing up its IRQ before its initialization as tacho pin, why is this happening and how could I fix this?

sudo cat /sys/kernel/debug/gpio
 gpio-65  (                    |pwm-fan-tach        ) in  lo IRQ

I declared 2nd fan exact the same method that 1st fan was declared and the 1st fan is working fine but the 2nd has that problem with the tacho pin. How could I fix this?

Do you mean the GPIO pin is not initialized before it is requested from pwm-fan driver?

If so, please try to put the device node pwm-fan to the bottom in device tree.
Or try to build it as loadable kernel module to load it after boot up and check if it could work.

I just modified pwm-fan driver to add here second tacho and it worked. Solved.