Template:GPIO KERNEL UBOOT DRAFT: Difference between revisions
(Created page with "<!-- Set release according to "release" parameter in URL and use RELEASE_SUMO_V1.0_VAR-SOM-MX8X as default --> {{#vardefine:RELEASE_PARAM|{{#urlget:release}}}} <!-- --> {{#lst...") |
No edit summary |
||
Line 1: | Line 1: | ||
= Kernel Device Tree GPIO configuration = | = Kernel Device Tree GPIO configuration = | ||
== Device Tree GPIO files == | == Device Tree GPIO files == |
Revision as of 08:56, 8 May 2023
Kernel Device Tree GPIO configuration
Device Tree GPIO files
Pin Func files
In the directory include/dt-bindings/pinctrl/ of the Linux kernel source you will find the pin functions definition files.
The relevant file is pads-imx8qm.h.
If you search it for GPIO2_IO07, for example, you will see a group of definitions with same prefix (pad name), "SC_P_ESAI1_SCKT".
#define SC_P_ESAI1_SCKT_AUD_ESAI1_SCKT SC_P_ESAI1_SCKT 0 #define SC_P_ESAI1_SCKT_AUD_SAI2_RXC SC_P_ESAI1_SCKT 1 #define SC_P_ESAI1_SCKT_AUD_SPDIF0_EXT_CLK SC_P_ESAI1_SCKT 2 #define SC_P_ESAI1_SCKT_LSIO_GPIO2_IO07 SC_P_ESAI1_SCKT 3
Adding only the one with the GPIO2_IO07 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.
Edit arch/arm64/boot/dts/freescale/fsl-imx8qm-var-som.dts and add the definition for the GPIO you need in the iomuxc node.
&iomuxc { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_hog>; imx8qm-var-som { pinctrl_hog: hoggrp { fsl,pins = < /* Add your GPIO definitions here */ >; }; }; ... };
Device Tree GPIO attribute
If you look at the pin control definitions in arch/arm64/boot/dts/freescale/fsl-imx8qm-var-som.dtsi 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 IOMUXD register of the relevant pad.
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.