GPIO KERNEL UBOOT DRAFT: Difference between revisions

From Variscite Wiki
(Initial draft of the GPIO Kernel/Uboot wiki page)
 
(Blanked the page)
Tag: Blanking
 
Line 1: Line 1:
<!-- 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:Yocto_Platform_Customization|{{#var:RELEASE_PARAM|RELEASE_SUMO_V1.0_VAR-SOM-MX8X}}}} <!--
--> {{PageHeader|{{#var:HARDWARE_NAME}} GPIO}} {{DocImage|category1=Yocto|category2={{#var:HARDWARE_NAME}}}} __toc__


= Kernel Device Tree GPIO configuration =
== Device Tree GPIO files ==
=== Pin Func files ===
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8X |
In the directory include/dt-bindings/pinctrl/ of the Linux kernel source you will find the pin functions definition files.<br>
The relevant file is pads-imx8qxp.h.<br>
If you search it for GPIO0_IO20, for example, you will see a goup of definitions with the same prefix (pad name) "SC_P_MCLK_OUT0",
<pre>
#define SC_P_MCLK_OUT0_ADMA_ACM_MCLK_OUT0                      SC_P_MCLK_OUT0                    0
#define SC_P_MCLK_OUT0_ADMA_ESAI0_TX_HF_CLK                    SC_P_MCLK_OUT0                    1
#define SC_P_MCLK_OUT0_ADMA_LCDIF_CLK                          SC_P_MCLK_OUT0                    2
#define SC_P_MCLK_OUT0_ADMA_SPI2_SDO                            SC_P_MCLK_OUT0                    3
#define SC_P_MCLK_OUT0_LSIO_GPIO0_IO20                          SC_P_MCLK_OUT0                    4
</pre>
Adding only the one with the GPIO0_IO20 suffix (function) to your DTS file will let you use the pin as GPIO.
|
In the directory include/dt-bindings/pinctrl/ of the Linux kernel source you will find the pin functions definition files.<br>
The relevant file is pads-imx8qm.h.<br>
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".
<pre>
#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
</pre>
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|Pin Func files]] section above.<br>
{{#ifeq: {{#var:HARDWARE_NAME}} | VAR-SOM-MX8X |
Edit arch/arm64/boot/dts/freescale/fsl-imx8qxp-var-som-common.dtsi and add the definition for the GPIO you need in the iomuxc node.<br>
<pre>
&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
imx8qxp-var-som {
pinctrl_hog: hoggrp {
fsl,pins = <
/* Add your GPIO definitions here */
>;
};
};
...
};
</pre>
|
Edit arch/arm64/boot/dts/freescale/fsl-imx8qm-var-som.dts and add the definition for the GPIO you need in the iomuxc node.<br>
<pre>
&iomuxc {
pinctrl-names = "default";
pinctrl-0 = <&pinctrl_hog>;
imx8qm-var-som {
pinctrl_hog: hoggrp {
fsl,pins = <
/* Add your GPIO definitions here */
>;
};
};
...
};
</pre>
}}
=== Device Tree GPIO attribute ===
If you look at the pin control definitions in arch/arm64/boot/dts/freescale/{{#ifeq: {{#var:HARDWARE_NAME}}|VAR-SOM-MX8X|imx8qxp-var-som-common.dtsi|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.<br>
This value is written to the IOMUXD register of the relevant pad.<br>
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.<br>
== 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<br>
Usage:
gpio <input|set|clear|toggle> <pin>
    - input/set/clear/toggle the specified pin
gpio status [-a] [<bank> | <pin>]  - show [all/claimed] GPIOs
<br>
Switch the GPIO pin to input mode:
=> gpio input <pin>
<br>
Switch the GPIO pin to output mode and set its value to 1:
=> gpio set <pin>
<br>
Switch the GPIO pin to output mode and set its value to 0:
=> gpio clear <pin>
<br>
Switch the GPIO pin to output mode and toggle its value:
=> gpio toggle <pin>
<br>
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.<br>
''label'' shows the gpio label.

Latest revision as of 08:57, 8 May 2023