Template:GPIO KERNEL UBOOT DRAFT

From Variscite Wiki
Revision as of 09:37, 8 May 2023 by Alifer (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Kernel Device Tree GPIO configuration

Device Tree GPIO files

Pin Func files

Adding only the one with the GPIO4_IO2 suffix (function) to your dts file will let you use the pin as GPIO.

Define a pin as GPIO in the kernel Device Tree

You need to add the relevant definitions to your device tree, as explained in the Pin Func files section above.


Device Tree GPIO attribute

If you look at the pin control definitions in arch/arm64/boot/dts/ in the Linux kernel source tree, the number to the right of the pin mux macro can be used for additional attributes like pull-up, slew rate, open drain, drive strength, etc.
This value is written to the IOMUXC_SW_PAD_CTRL_ register of the relevant pin.
Please consult the SOC reference manual for details about the relevant register.

U-Boot GPIO

In U-Boot, GPIO pins can be configured and manipulated using the "gpio" command. This command provides various options to configure the GPIO pins, set their direction (input or output), and toggle their values.

Installation

To enable the "gpio" command line tool in U-Boot, the defconfig file must have the following line:

CONFIG_CMD_GPIO=y

Usage

=> gpio help
gpio - query and control gpio pins
Usage: gpio <input|set|clear|toggle> <pin> - input/set/clear/toggle the specified pin gpio status [-a] [<bank> | <pin>] - show [all/claimed] GPIOs


Switch the GPIO pin to input mode:

=> gpio input <pin>


Switch the GPIO pin to output mode and set its value to 1:

=> gpio set <pin>


Switch the GPIO pin to output mode and set its value to 0:

=> gpio clear <pin>


Switch the GPIO pin to output mode and toggle its value:

=> gpio toggle <pin>


Display the status of one or multiple GPIOs:

=> gpio status

By default only claimed GPIOs are displayed. To show unclaimed GPIOs, the -a parameter must be used:

=> gpio status -a

gpio status command output fields are:

<name>: <function>: <value> [x] <label>

function can take the following values:

  • output: pin configured in gpio output, the value indicates the pin’s level
  • input: pin configured in gpio input, the value indicates the pin’s level
  • func: pin configured in alternate function, followed by the label which shows pinmuxing label.
  • unused: pin not configured

[x] or [ ] indicate, respectively, if the gpio is used or not.
label shows the gpio label.