add gpio389 to the kernel


How to add gpio389 to the kernel and initialize it.What are the specific steps of the operation?

Just a starting point…go here and get the PINMUX spreadsheet for TX2:

Also the Parker series TRM for TX2:

The TRM will have a listing of some labels for GPIO along with a system address map. The system address map (section 2.6.2, table 2) gives some controller names along with their base address. The base address is used in many places, e.g., device tree and “/sys” files. Those names are just within the module itself and have no knowledge of the carrier board. The spreadsheet has knowledge of the carrier board.

You will find multiple banks of identical controllers containing multiple GPIO. Each controller is identical other than base address. In some places GPIO are listed basically as a serial number, and in other cases naming a function. You’ll be interested in the TRM section 8.30. If you see something (such as Table 77) naming “controller 0” or “controller 3”, then this is the same as saying one of the base addresses…just as an index instead of the address. If there are 8 GPIO with one base address, then that is from one particular controller. In “/sys” you may find listings of “gpio@someaddress”. This is how they relate. Lots of ways to see GPIO.

Explore “/sys”:

sudo -s
find /sys -name '*gpio*'
# See current GPIO setup:
cat /sys/kernel/debug/tegra_pinctrl_reg
# Go to where export/unexport are:
[b]cd /sys/class/gpio
# Note that symbolic links exist for enabled GPIO.
# Export or unexport 398:
echo 398 > export
echo 398 > unexport
# Re-export 398:
echo 398 > export
# See details:
cd ./gpio398
cat active_low
cat edge
cat value
cat direction
# Assuming direction is "out", convert it to "in":
echo in > direction
cat in
# Put it back to out:
echo out > direction
cat direction[/b]
# If done, exit root shell:

If interested in doing this in the kernel space look up “gpio_get_value()” and “gpio_set_value()”. See kernel file “drivers/gpio/gpio-tegra.c”.

Hello linuxdev:
I am a newcomer to the Linux kernel.I want to add GPIO11_AP_WAKE_BT to the kernel. Can you tell me the specific steps?Could you please be as specific as possible?Thank you very, very much.

Not exact steps, but if you open that spreadsheet and enable macros you’ll see line 51, first column, shows GPIO11_AP_WAKE_BT. Next to this is the actual pin number on the module, but you probably don’t care about that unless you’re looking at the schematic.

Further to the right you’ll see this has a logical name of GPIO_PQ5…this is how the TRM names that pin/function. Searching the TRM for this shows some of the possible uses/configurations of this pin which can be set up by the device tree during boot (you don’t have to use the device tree for this).

Since you already know it is 398 though (I have not verified), check my first reply where it says to explore “/sys” (those are specific commands to use 398). The echo statements are one way of controlling GPIO 398. I have no idea what it is you want to use the pin for, so there are a lot of variations I can’t answer. Just using it as GPIO is what is shown in the previous post.

Note that the reason the spreadsheet is of use (beyond matching naming conventions between different documents) is that there is a device tree, and that the device tree can be edited to name how you want this pin to behave right from the moment it starts up (but the “echo” statements in that first post do this as well…controlling a file in “/sys” is simpler than editing a device tree, especially when testing). What is it you want to accomplish? How do you want to use this GPIO?

I am a Chinese.I through the pin to control an LED lamp, now under the system, /sys/class/gpio/by echo 389 > export can successfully control LED lights, but restarting and before did not enter the system, the LED in the wrong state, so I want to change in the kernel, ensure LED before did not enter the system state is normal.But I know how to operate it. Do I need to modify the device tree?How do I do that?

An LED is too high of a load, you’ll need to isolate, e.g., a buffer.

This is what the spreadsheet URL is for. Download that spreadsheet. Run it with macros enabled. You can find the pin there, enable it, and use the macro to generate a new device tree.

If you want to do this the hard way, then what follows will help:

Some clues on what to look for…run “sudo cat /sys/kernel/debug/gpio”. You’ll see the controller at address 0x2200000 manages GPIO 320 through 521. This is the “gpio@address” (“gpio@2200000”) you are interested in for device tree notation.

If you look at your existing device tree:

dtc -I fs -O dts -o extracted.dts /proc/device-tree/

…then you will find a block with “gpio@2200000”. This is the block which will be modified for 398. Try creating a version with 398 enabled via the spreadsheet, and then compare to this block in your existing device tree. Entries with this are enabled:

status = "okay";

…entries with this are disabled:

status = "disabled";

See this for more details, but keep in mind editing a dtsi file in kernel source versus directly editing a dts file versus generating a file via spreadsheet macro will all accomplish the same thing…the preparation and setup will differ: