Cannot control GPIO in my driver in the L4T35.3.1

Hi , I use my driver to control GPIO in the kernel.
And it works well in the L4T 32.7.3 (Xavier NX).

But when I change to the 35.3.1(Orin NX 8GB), I get the error

[    2.154614] failed to request rs232 enable GPIO err: -517

This is my driver source code, could you please give me some help?

struct gpio_desc rs232_enable_gpio;
rs232_enable_gpio = devm_gpiod_get_index_optional(dev, "rs232-enable", 0, GPIOD_OUT_LOW);
if (IS_ERR(rs232_enable_gpio)) {
                int err = PTR_ERR(rs232_enable_gpio);
                printk("failed to request rs232 enable GPIO err: %d\n", err);
        } else {
                printk("request rs232 enable GPIO success\n");
                gpiod_export(rs232_enable_gpio, true);
        }

And this is dts code:

rs232-enable-gpios = <&tegra_main_gpio TEGRA234_MAIN_GPIO(G, 6) GPIO_ACTIVE_HIGH>;

Hi Xzz,

Could you control this pin (PG.06) with sysfs?

Do you use the same pin for both Xavier NX and Orin NX?

Hi, KevinFFF,
I can control this pin success with sysfs.

echo PG.06 > /sys/class/gpio/export

Actually some are the same, but both can’t control in my driver.

Is there any special config between 32.7.3 and 35.3.1?

I found the same problem in this link,
Issue migration of MCP23S08 from Jetpack-4.x.y to Jetpack-5.0.1:

And I try this method but -517 error again.

rs232-enable-gpios = <&tegra_main_gpio 389 GPIO_ACTIVE_HIGH>;

So it is not a special but common problem, Please check, thanks!

Hi, @KevinFFF ,do you have any suggestion?
This question is a little urgent, thank you.

hello Xzz,

please try this to get a GPIO number by using with GPIO APIs.
for example,

int rs232_enable_gpio;
rs232_enable_gpio = of_get_named_gpio(dev->of_node, "rs232-enable", 0);

you may see-also the header file as below about this GPIO API.
i.e. $public_sources/kernel_src/kernel/kernel-5.10/include/linux/of_gpio.h

Hi, this is my code:

       int rs232_enable_gpio;
       rs232_enable_gpio = of_get_named_gpio(dev->of_node, "rs232-enable", 0);
       if (gpio_is_valid(rs232_enable_gpio)) {
              printk("xz request rs232 enable GPIO success\n");
       } else printk("xz request failed\n");

but gpio is failed again,and log is :

[    2.139903] xz request failed

I find there is something wrong with my code,

-rs232_enable_gpio = of_get_named_gpio(dev->of_node, "rs232-enable", 0);
+rs232_enable_gpio = of_get_named_gpio(dev->of_node, "rs232-enable-gpios", 0);

and the same error log happened again :(

it should be… struct device_node *np,
could you please check you’ve assign correct device node to get GPIO from.

I use this standard code to get dev and node, and it works fine in the 32.7.3.
And -517 , this error code is a standard Linux error code, which means -EINVAL, i.e., “invalid argument”.
So I suspect that the GPIO pin cannot be found cause this problem.

static int test_gpio_probe(struct platform_device *pdev){
struct device *dev = &pdev->dev;
}

could you please have a quick test.
is this gpio_is_valid(389) return true or false? since the pin number should be 389 for PG.06.

This is my code:

 rs232_enable_gpio = of_get_named_gpio(dev->of_node, "rs232-enable-gpios", 0);
        printk("xz rs232_enable_gpio is %d\n",rs232_enable_gpio);


        if (gpio_is_valid(389)) {
               printk("xz request rs232 enable GPIO success\n");
        } else printk("xz request failed\n");

the result is :

[    2.153854] xz rs232_enable_gpio is -517
[    2.157771] xz request rs232 enable GPIO success

So of_get_named_gpio function get a wrong index, and gpio_is_valid output error.

Hi,JerryChang,
Now the reason of this question is clear, and my code works ok in L4T37.2.3

what should I do next?

Could you provide your driver source for this pin and the modification in device tree for us to reproduce on the devkit?

Sure. Let me check the source, This will take some time.

Hi,JerryChang,
Thank you for waiting,this is my diff code in kernel:

--- a/hardware/nvidia/platform/t23x/p3768/kernel-dts/tegra234-p3767-0001-p3509-a02.dts
+++ b/hardware/nvidia/platform/t23x/p3768/kernel-dts/tegra234-p3767-0001-p3509-a02.dts
@@ -22,4 +22,11 @@
        nvidia,dtbbuildtime = __DATE__, __TIME__;
        compatible = "nvidia,p3509-0000+p3767-0001", "nvidia,p3767-0001", "nvidia,tegra234", "nvidia,tegra23x";
        model = "NVIDIA Orin NX Developer Kit";
+
+       seavo_gpio {
+                status = "okay";
+                compatible = "seavo,gpio";
+                rs232-enable-gpios = <&tegra_main_gpio 389 GPIO_ACTIVE_HIGH>;
+        };
+
 };
diff --git a/kernel/kernel-5.10/drivers/gpio/Makefile b/kernel/kernel-5.10/drivers/gpio/Makefile
index 09dada80a..fd6bb8720 100644
--- a/kernel/kernel-5.10/drivers/gpio/Makefile
+++ b/kernel/kernel-5.10/drivers/gpio/Makefile
@@ -180,3 +180,4 @@ obj-$(CONFIG_GPIO_XTENSA)           += gpio-xtensa.o
 obj-$(CONFIG_GPIO_ZEVIO)               += gpio-zevio.o
 obj-$(CONFIG_GPIO_ZX)                  += gpio-zx.o
 obj-$(CONFIG_GPIO_ZYNQ)                        += gpio-zynq.o
+obj-y                                  += gpio-seavo.o

This is my driver file.
gpio-seavo.c (1.7 KB)
And this is the result:

root@tegra-ubuntu:~# dmesg  | grep xz
[    2.120336] xz failed to request rs232 enable GPIO err: -517

Hi,JerryChang,
Do you find any problem in my driver or SDK?

@KevinFFF Hi,do you have any suggestion?
This issue is a bit urgent for us, Thanks a lot~

Hi,
It takes a long time for you to check, could you plese give me some reply?
And I found kernel error when system running:

[  336.451542] ------------[ cut here ]------------
[  336.451568] WARNING: CPU: 0 PID: 0 at drivers/gpio/gpio-tegra186.c:937 tegra186_gpio_irq+0x1ac/0x1f0
[  336.461003] Modules linked in: nvidia_modeset(OE) fuse(E) lzo_rle(E) lzo_compress(E) zram(E) ramoops(E) reed_solomon(E) loop(E) snd_soc_tegra186_dspk(E) snd_soc_tegra210_ope(E) snd_soc_tegra186_asrc(E) snd_soc_tegra186_arad(E) snd_soc_tegra210_mvc(E) snd_soc_tegra210_iqc(E) snd_soc_tegra210_afc(E) snd_soc_tegra210_dmic(E) snd_soc_tegra210_adx(E) snd_soc_tegra210_amx(E) snd_soc_tegra210_mixer(E) snd_soc_tegra210_i2s(E) snd_soc_tegra210_admaif(E) snd_soc_tegra_pcm(E) snd_soc_tegra210_sfc(E) cdc_acm(E) aes_ce_blk(E) crypto_simd(E) cryptd(E) aes_ce_cipher(E) ghash_ce(E) sha2_ce(E) sha256_arm64(E) sha1_ce(E) snd_soc_spdif_tx(E) snd_soc_tegra_machine_driver(E) snd_soc_tegra210_adsp(E) r8168(E) nv_imx219(E) snd_soc_tegra_utils(E) userspace_alert(E) snd_soc_simple_card_utils(E) snd_hda_codec_hdmi(E) nvadsp(E) r8169(E) tegra_bpmp_thermal(E) realtek(E) snd_hda_tegra(E) snd_soc_tegra210_ahub(E) snd_hda_codec(E) snd_hda_core(E) tegra210_adma(E) spi_tegra114(E) nvidia(OE) binfmt_misc(E) ina3221(E)
[  336.461134]  pwm_fan(E) nvgpu(E) nvmap(E) ip_tables(E) x_tables(E) [last unloaded: mtd]
[  336.461157] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G           OE     5.10.104-tegra #17
[  336.461161] Hardware name: Unknown NVIDIA Orin NX Developer Kit/NVIDIA Orin NX Developer Kit, BIOS 3.1-32827747 03/19/2023
[  336.461167] pstate: 20400089 (nzCv daIf +PAN -UAO -TCO BTYPE=--)
[  336.461172] pc : tegra186_gpio_irq+0x1ac/0x1f0
[  336.461177] lr : tegra186_gpio_irq+0x11c/0x1f0
[  336.461179] sp : ffff800010003ef0
[  336.461182] x29: ffff800010003ef0 x28: ffff6472c0db1460 
[  336.461188] x27: ffffa9285b59cff8 x26: 0000000000000018 
[  336.461193] x25: ffff6472c5833880 x24: ffff6472c5854000 
[  336.461199] x23: 000000000000000c x22: 000000000000004c 
[  336.461205] x21: 00000000000000b9 x20: 0000000000000000 
[  336.461210] x19: ffffa9285aa5ee50 x18: 0000000000000000 
[  336.461215] x17: 0000000000000000 x16: ffffa9285a976350 
[  336.461221] x15: 0000000000000000 x14: 00000000000050c9 
[  336.461226] x13: 0000000000005db3 x12: 0000000000000024 
[  336.461232] x11: 0000000000000040 x10: ffffa9285b507a80 
[  336.461238] x9 : ffffa9285b507a78 x8 : ffff6472c04b0dd8 
[  336.461244] x7 : 0000000000000000 x6 : 0000000000000001 
[  336.461249] x5 : 0000000000000000 x4 : 0000000000000000 
[  336.461255] x3 : 0000000000000000 x2 : ffffa9285993e170 
[  336.461260] x1 : 000000000000004c x0 : 0000000000000000 
[  336.461267] Call trace:
[  336.461272]  tegra186_gpio_irq+0x1ac/0x1f0
[  336.461283]  generic_handle_irq+0x40/0x60
[  336.461288]  __handle_domain_irq+0x70/0xd0
[  336.461294]  gic_handle_irq+0x68/0x134
[  336.461297]  el1_irq+0xd0/0x180
[  336.461306]  cpuidle_enter_state+0xb8/0x410
[  336.461310]  cpuidle_enter+0x40/0x60
[  336.461315]  call_cpuidle+0x44/0x80
[  336.461318]  do_idle+0x208/0x270
[  336.461321]  cpu_startup_entry+0x2c/0x70
[  336.461331]  rest_init+0xdc/0xe8
[  336.461338]  arch_call_rest_init+0x18/0x20
[  336.461341]  start_kernel+0x514/0x54c
[  336.461345] ---[ end trace 0c2cee0b48632011 ]---

This is the hole dmesg log:
GPIO报错 dmesg.txt (65.7 KB)