How to calculate the GPIO pin number on AGX Orin

I want to control GPIO3_PAC.00 by /sys/class/gpio, and I calculate GPIO3_PAC.00 gpio pin number by below algorithm:
1.I check the TEGRA234_MAIN_GPIO_PORT_AC number is 20 in tegra234-gpio.h
#define TEGRA234_MAIN_GPIO_PORT_AC 20

  1. I see the registered GPIOs range is 348 to 511 in kernel log, so I think gpio base index is 348.
[    5.508839] gpiochip0: registered GPIOs 348 to 511 on tegra234-gpio
[    5.514859] gpiochip1: registered GPIOs 316 to 347 on tegra234-gpio-aon

3.Accoding to TEGRA_MAIN_GPIO, and I calculate GPIO3_PAC.00 gpio result is 508

TEGRA_MAIN_GPIO(port, base) =((TEGRA_MAIN_GPIO_PORT_##port * 8) + pin) + base
TEGRA_MAIN_GPIO(port, base) =((20*8) + 0) + 348 = 508

4.But I see the /sys/class/gpio/PAG.04 after I echo 508 to /sys/class/gpio/export.
echo 508 > /sys/class/gpio/export

and I see the PAC.00 is gpio-486 in /sys/kernel/debug/gpio.

root@nvidia-orin2:/sys/class/gpio# echo 508 > export
root@nvidia-orin2:/sys/class/gpio# ll
total 0
drwxr-xr-x  2 root root    0  一  10  2022 ./
drwxr-xr-x 77 root root    0  一  10  2022 ../
--w--w----  1 root gpio 4096  七  18 11:58 export
lrwxrwxrwx  1 root root    0  一  10  2022 gpiochip276 -> ../../devices/platform/31e0000.i2c/i2c-8/8-0077/gpio/gpiochip276/
lrwxrwxrwx  1 root root    0  一  10  2022 gpiochip292 -> ../../devices/platform/31e0000.i2c/i2c-8/8-0074/gpio/gpiochip292/
lrwxrwxrwx  1 root root    0  一  10  2022 gpiochip308 -> ../../devices/platform/31e0000.i2c/i2c-8/8-0020/gpio/gpiochip308/
lrwxrwxrwx  1 root root    0  一  10  2022 gpiochip316 -> ../../devices/platform/c2f0000.gpio/gpio/gpiochip316/
lrwxrwxrwx  1 root root    0  一  10  2022 gpiochip348 -> ../../devices/platform/2200000.gpio/gpio/gpiochip348/
lrwxrwxrwx  1 root root    0  七  18 11:58 PAG.04 -> ../../devices/platform/2200000.gpio/gpiochip0/gpio/PAG.04/

How to calculate the GPIO3_PAC.00 gpio pin number to GPIO-486 in AGX Orin?

root@nvidia-orin2:/sys/class/gpio# cat /sys/kernel/debug/gpio
gpiochip4: GPIOs 276-291, parent: i2c/8-0077, 8-0077, can sleep:
 gpio-276 (                    |M2_DEVSLP           ) out lo 
 gpio-277 (                    |M21_GNSS_DISABLE    ) out lo 
 gpio-278 (                    |M21_PWR_OFF         ) out lo 
 gpio-279 (                    |EXP_PRSNT           ) in  lo 
 gpio-280 (                    |NA                  ) in  hi 
 gpio-281 (                    |BRD_1V8_ID0         ) in  lo 
 gpio-282 (                    |BRD_1V8_ID1         ) in  lo 
 gpio-283 (                    |BRD_1V8_ID2         ) in  lo 
 gpio-284 (                    |NA                  ) in  lo 
 gpio-285 (                    |PWRON_DELAYSET0     ) in  lo 
 gpio-286 (                    |PWRON_DELAYSET1     ) in  lo 
 gpio-287 (                    |PWRON_DELAYSET2     ) in  lo 
 gpio-288 (                    |COM1_En             ) out hi 
 gpio-289 (                    |COM2_En             ) out hi 
 gpio-290 (                    |MINIPCIE1_DIS       ) in  hi 
 gpio-291 (                    |MINIPCIE2_DIS       ) in  hi 

gpiochip3: GPIOs 292-307, parent: i2c/8-0074, 8-0074, can sleep:
 gpio-292 (                    |EXPA2_GPO_0         ) out lo 
 gpio-293 (                    |EXPA2_GPO_1         ) out lo 
 gpio-294 (                    |EXPA2_GPO_2         ) out lo 
 gpio-295 (                    |EXPA2_GPO_3         ) out lo 
 gpio-296 (                    |EXPA2_GPO_4         ) out lo 
 gpio-297 (                    |EXPA2_GPO_5         ) out lo 
 gpio-298 (                    |EXPA2_GPO_6         ) out lo 
 gpio-299 (                    |EXPA2_GPO_7         ) out lo 
 gpio-300 (                    |EXPA2_GPI_0         ) in  hi 
 gpio-301 (                    |EXPA2_GPI_1         ) in  hi 
 gpio-302 (                    |EXPA2_GPI_2         ) in  hi 
 gpio-303 (                    |EXPA2_GPI_3         ) in  hi 
 gpio-304 (                    |EXPA2_GPI_4         ) in  hi 
 gpio-305 (                    |EXPA2_GPI_5         ) in  hi 
 gpio-306 (                    |EXPA2_GPI_6         ) in  hi 
 gpio-307 (                    |EXPA2_GPI_7         ) in  hi 

gpiochip2: GPIOs 308-315, parent: i2c/8-0020, 8-0020, can sleep:
 gpio-308 (                    |ISO_COM1_MODE0      ) out lo 
 gpio-309 (                    |ISO_COM1_MODE1   I    ) out lo 
 gpio-310 (                    |ISO_COM1_TERM       ) out lo 
 gpio-311 (                    |ISO_COM1_RTS_REV    ) out lo 
 gpio-312 (                    |ISO_COM2_MODE0      ) out lo 
 gpio-313 (                    |ISO_COM2_MODE1      ) out lo 
 gpio-314 (                    |ISO_COM2_TERM       ) out lo 
 gpio-315 (                    |ISO_COM2_RTS_REV    ) out lo 

gpiochip1: GPIOs 316-347, parent: platform/c2f0000.gpio, tegra234-gpio-aon:
 gpio-316 (PAA.00              )
 gpio-317 (PAA.01              )
 gpio-318 (PAA.02              )
 gpio-319 (PAA.03              )
 gpio-320 (PAA.04              )
 gpio-321 (PAA.05              )
 gpio-322 (PAA.06              )
 gpio-323 (PAA.07              )
 gpio-324 (PBB.00              )
 gpio-325 (PBB.01              )
 gpio-326 (PBB.02              )
 gpio-327 (PBB.03              )
 gpio-328 (PCC.00              )
 gpio-329 (PCC.01              )
 gpio-330 (PCC.02              |fixed-regulators:reg) out lo 
 gpio-331 (PCC.03              )
 gpio-332 (PCC.04              )
 gpio-333 (PCC.05              )
 gpio-334 (PCC.06              )
 gpio-335 (PCC.07              )
 gpio-336 (PDD.00              )
 gpio-337 (PDD.01              )
 gpio-338 (PDD.02              )
 gpio-339 (PEE.00              )
 gpio-340 (PEE.01              )
 gpio-341 (PEE.02              )
 gpio-342 (PEE.03              )
 gpio-343 (PEE.04              |power-key           ) in  hi IRQ ACTIVE LOW
 gpio-344 (PEE.05              )
 gpio-345 (PEE.06              )
 gpio-346 (PEE.07              )
 gpio-347 (PGG.00              )
gpiochip0: GPIOs 348-511, parent: platform/2200000.gpio, tegra234-gpio:
 gpio-348 (PA.00               |fixed-regulators:reg) out hi 
 gpio-349 (PA.01               |fixed-regulators:reg) out hi ACTIVE LOW
 gpio-350 (PA.02               )
 gpio-351 (PA.03               |fixed-regulators:reg) out hi 
 gpio-352 (PA.04               )
 gpio-353 (PA.05               )
 gpio-354 (PA.06               )
 gpio-355 (PA.07               )
 gpio-356 (PB.00               )
 gpio-357 (PC.00               )
 gpio-358 (PC.01               )
 gpio-359 (PC.02               )
 gpio-360 (PC.03               )
 gpio-361 (PC.04               )
 gpio-362 (PC.05               )
 gpio-363 (PC.06               )
 gpio-364 (PC.07               )
 gpio-365 (PD.00               )
 gpio-366 (PD.01               )
 gpio-367 (PD.02               )
 gpio-368 (PD.03               )
 gpio-369 (PE.00               )
 gpio-370 (PE.01               )
 gpio-371 (PE.02               )
 gpio-372 (PE.03               )
 gpio-373 (PE.04               )
 gpio-374 (PE.05               )
 gpio-375 (PE.06               )
 gpio-376 (PE.07               )
 gpio-377 (PF.00               )
 gpio-378 (PF.01               )
 gpio-379 (PF.02               )
 gpio-380 (PF.03               )
 gpio-381 (PF.04               )
 gpio-382 (PF.05               )
 gpio-383 (PG.00               |force-recovery      ) in  hi IRQ ACTIVE LOW
 gpio-384 (PG.01               |temp-alert          ) in  lo IRQ 
 gpio-385 (PG.02               |sleep               ) in  hi IRQ ACTIVE LOW
 gpio-386 (PG.03               )
 gpio-387 (PG.04               )
 gpio-388 (PG.05               )
 gpio-389 (PG.06               )
 gpio-390 (PG.07               |cd                  ) in  lo IRQ 
 gpio-391 (PH.00               )
 gpio-392 (PH.01               )
 gpio-393 (PH.02               )
 gpio-394 (PH.03               |camera-control-outpu) out lo 
 gpio-395 (PH.04               )
 gpio-396 (PH.05               )
 gpio-397 (PH.06               |camera-control-outpu) out lo 
 gpio-398 (PH.07               )
 gpio-399 (PI.00               )
 gpio-400 (PI.01               )
 gpio-401 (PI.02               )
 gpio-402 (PI.03               )
 gpio-403 (PI.04               )
 gpio-404 (PI.05               )
 gpio-405 (PI.06               )
 gpio-406 (PJ.00               )
 gpio-407 (PJ.01               )
 gpio-408 (PJ.02               )
 gpio-409 (PJ.03               )
 gpio-410 (PJ.04               )
 gpio-411 (PJ.05               )
 gpio-412 (PK.00               )
 gpio-413 (PK.01               )
 gpio-414 (PK.02               )
 gpio-415 (PK.03               )
 gpio-416 (PK.04               )
 gpio-417 (PK.05               )
 gpio-418 (PK.06               )
 gpio-419 (PK.07               )
 gpio-420 (PL.00               )
 gpio-421 (PL.01               )
 gpio-422 (PL.02               )
 gpio-423 (PL.03               )
 gpio-424 (PM.00               )
 gpio-425 (PM.01               )
 gpio-426 (PM.02               )
 gpio-427 (PM.03               )
 gpio-428 (PM.04               )
 gpio-429 (PM.05               )
 gpio-430 (PM.06               )
 gpio-431 (PM.07               )
 gpio-432 (PN.00               )
 gpio-433 (PN.01               )
 gpio-434 (PN.02               )
 gpio-435 (PN.03               )
 gpio-436 (PN.04               )
 gpio-437 (PN.05               )
 gpio-438 (PN.06               )
 gpio-439 (PN.07               )
 gpio-440 (PP.00               )
 gpio-441 (PP.01               )
 gpio-442 (PP.02               )
 gpio-443 (PP.03               )
 gpio-444 (PP.04               )
 gpio-445 (PP.05               )
 gpio-446 (PP.06               )
 gpio-447 (PP.07               )
 gpio-448 (PQ.00               )
 gpio-449 (PQ.01               |fixed-regulators:reg) out lo 
 gpio-450 (PQ.02               )
 gpio-451 (PQ.03               )
 gpio-452 (PQ.04               )
 gpio-453 (PQ.05               )
 gpio-454 (PQ.06               )
 gpio-455 (PQ.07               )
 gpio-456 (PR.00               )
 gpio-457 (PR.01               )
 gpio-458 (PR.02               )
 gpio-459 (PR.03               )
 gpio-460 (PR.04               )
 gpio-461 (PR.05               )
 gpio-462 (PX.00               )
 gpio-463 (PX.01               )
 gpio-464 (PX.02               )
 gpio-465 (PX.03               )
 gpio-466 (PX.04               )
 gpio-467 (PX.05               )
 gpio-468 (PX.06               )
 gpio-469 (PX.07               )
 gpio-470 (PY.00               )
 gpio-471 (PY.01               )
 gpio-472 (PY.02               )
 gpio-473 (PY.03               )
 gpio-474 (PY.04               )
 gpio-475 (PY.05               )
 gpio-476 (PY.06               )
 gpio-477 (PY.07               )
 gpio-478 (PZ.00               )
 gpio-479 (PZ.01               )
 gpio-480 (PZ.02               |fixed-regulators:reg) out lo 
 gpio-481 (PZ.03               )
 gpio-482 (PZ.04               )
 gpio-483 (PZ.05               )
 gpio-484 (PZ.06               )
 gpio-485 (PZ.07               )
 gpio-486 (PAC.00              |camera-control-outpu) out lo 
 gpio-487 (PAC.01              |camera-control-outpu) out lo 
 gpio-488 (PAC.02              )
 gpio-489 (PAC.03              )
 gpio-490 (PAC.04              )
 gpio-491 (PAC.05              )
 gpio-492 (PAC.06              )
 gpio-493 (PAC.07              |fixed-regulators:reg) out hi 
 gpio-494 (PAD.00              )
 gpio-495 (PAD.01              )
 gpio-496 (PAD.02              )
 gpio-497 (PAD.03              )
 gpio-498 (PAE.00              )
 gpio-499 (PAE.01              )
 gpio-500 (PAF.00              )
 gpio-501 (PAF.01              )
 gpio-502 (PAF.02              )
 gpio-503 (PAF.03              )
 gpio-504 (PAG.00              )
 gpio-505 (PAG.01              )
 gpio-506 (PAG.02              )
 gpio-507 (PAG.03              )
 gpio-508 (PAG.04              )
 gpio-509 (PAG.05              )
 gpio-510 (PAG.06              )
 gpio-511 (PAG.07              )

hello SammyChenTw,

note: GPIO calculation using below formula is not valid anymore for K5.10.
#define TEGRA234_MAIN_GPIO(port, offset) \ ((TEGRA234_MAIN_GPIO_PORT_##port * 8) + offset)

please refer to developer guide, [To check a GPIO number]. please follow the GPIO debugfs for looking up the port and offset.
for example,
454 is the GPIO number of PQ.06

$ sudo cat /sys/kernel/debug/gpio | grep PQ.06
gpio-454 (PQ.06 )```

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.