SPI2 (H14, H15, G15, G16) as GPIO in tx2

Hi, I need I little help with gpio. I will appreciate your time.
I am new in this.

I know how to map the SPI1 pins as gpio .

SPI1_CLK - G13 - GPIO3_PN.03
SPI1_MISO - F14 - GPIO3_PN.04
SPI1_MOSI - F13 - GPIO3_PN.05
SPI1_CS0# - E14 - GPIO3_PN.06

I am using this pinmux sheet: Jetson Download Center | NVIDIA Developer
And this formula to get the pin number:

  1. calculate the gpio number from the formula: GPIO export value =offset+ (port number* 8 + pin value)

(from here: How do I map signal names to GPIO numbers? - #4 by khaledsalahloudz )

All seems to work fine.
Now, the question is, Can I use the next pins as gpio? How can I get the “GPIO export value”
I can not use the formula with this names (ej. SPI1_SCK) there are not “port_number” or “pin_value” in there.

SPI2_CLK - H14 - SPI1_SCK
SPI2_MISO - H15 - SPI1_DIN
SPI2_MOSI - G15 - SPI1_DOUT
SPI2_CS0# - G16 - SPI1_CS0

Can you help me with some documentation, or something to help me to know if;

Is it possible to use that pins (H14, H15, G15, G16) as gpio?
If possible, can you help me to get the “GPIO export value” to be used in /sys/class/gpio/export for this pins.

Thank you very much!

Have check below macro to figure the gpio value.
…/kernel/kernel-4.9/include/dt-bindings/gpio/tegra186-gpio.h

Check the base by below command

root@nvidia-desktop:/sys# cat /sys/kernel/debug/pinctrl/2430000.pinmux/gpio-ranges
GPIO ranges handled:
0: tegra-gpio GPIOS [320 - 463] PINS [0 - 143]
144: tegra-gpio GPIOS [464 - 471] PINS [152 - 159]
152: tegra-gpio GPIOS [472 - 487] PINS [184 - 199]
168: tegra-gpio GPIOS [488 - 511] PINS [216 - 239]
0: tegra-gpio-aon GPIOS [256 - 263] PINS [144 - 151]
8: tegra-gpio-aon GPIOS [264 - 287] PINS [160 - 183]
32: tegra-gpio-aon GPIOS [288 - 303] PINS [200 - 215]
48: tegra-gpio-aon GPIOS [304 - 319] PINS [240 - 255]

Thank you for your answer.

I am using this macros:

It is working fine with the pins:

SPI1_CLK - G13 - GPIO3_PN.03
SPI1_MISO - F14 - GPIO3_PN.04
SPI1_MOSI - F13 - GPIO3_PN.05
SPI1_CS0# - E14 - GPIO3_PN.06

I am using the “N” macro value:

#define TEGRA186_MAIN_GPIO_PORT_N 13

and 03, 04, 05, 06 as pin_value, and I am using the 320 as offset.

0: tegra-gpio GPIOS [320 - 463] PINS [0 - 143]

And the next formula

GPIO export value =offset+ (port number* 8 + pin value)

All is working fine for that pins.

But, I do not have Idea how to get the gpio value (if it is possible) of the pins:

SPI2_CLK - H14 - SPI1_SCK
SPI2_MISO - H15 - SPI1_DIN
SPI2_MOSI - G15 - SPI1_DOUT
SPI2_CS0# - G16 - SPI1_CS0

Because in the pinmux document: Jetson Download Center | NVIDIA Developer

There is no GPIO3_PX.YY for the SPI2 pins.

Is there an ease way to get gpio numbers for the SPI2 (H14, H15, G15, G16) pins?

Thank you for your time.

Sorry, no other way to get the GPIO number now.

I really appreciate your time.

So, Can not be used the pins (H14, H15, G15, G16) as gpio?

Looks like it’s phx

pinmux.0x0243d018 = 0x00000446; # gpio_wan5_ph0: spi1, pull-down, tristate-disable, input-enable
pinmux.0x0243d010 = 0x00000446; # gpio_wan6_ph1: spi1, pull-down, tristate-disable, input-enable
pinmux.0x0243d008 = 0x00000446; # gpio_wan7_ph2: spi1, pull-down, tristate-disable, input-enable
pinmux.0x0243d000 = 0x0000044a; # gpio_wan8_ph3: spi1, pull-up, tristate-disable, input-enable

1 Like

Sorry, I am new in this, do you mean that I must use phx?:

#define TEGRA186_MAIN_GPIO_PORT_H 7

Port number: 7
pin_value: x

For example, for gpio_wan5_ph0:

GPIO export value =offset + (port number* 8 + pin value)
GPIO export value   = 320 + (7* 8 + 0)  =   376

Is it correct for gpio_wan5_ph0 ?

Thank you very much!

Yes, it’s correct.

1 Like

It is working fine for the pins (H14, H15, G15, G16).

Thank you very much. I appreciate your time!