This article describes how to enable the GPIO support in SPL for i.MX 93 and how to use the associated library.
Available GPIO banks
| Bank |
Registers' Base Address |
| GPIO1 |
0x47400000 |
| GPIO2 |
0x43810000 |
| GPIO3 |
0x43820000 |
| GPIO4 |
0x43830000 |
Software
Tests performed using the LF6.12.20-2.0.0 BSP, but should work similarly in other versions.
Enable the GPIO support in SPL
Enable the CONFIG_SPL_GPIO through menuconfig.
Configure the GPIO pin
Make sure the chosen GPIO pin is not used by any other peripheral, by checking U-Boot's device tree (example: imx93-11x11-evk.dts and its included files). If used, disable the conflicting peripheral in the device tree.
To identify the exact macro associated to the GPIO functionality, please check the arch/arm/dts/imx93-pinfunc.h file.
- Example 1: Use an available GPIO pin (e.g. GPIO2_IO05)
This pin is not used by other peripheral, so there is nothing to disable.
To use the pin with the GPIO functionality, the following pin muxing must be added in the iomux node of the imx93-11x11-evk.dts file (located in dts/upstream/src/arm64/freescale/
pinctrl_hog: hoggrp {
fsl,pins = <
MX93_PAD_GPIO_IO05__GPIO2_IO05 0x51e
>;
};
Note: 0x51e represents the value you want in the PAD register (SW_PAD_CTL_PAD_GPIO_IO05). You may configure it as you want.
- Example 2: Use the XSPI1_TXC pin as GPIO (GPIO1_IO12)
In our BSP, by default, this pin is used by the SAI1 peripheral. To use this pin as GPIO, SAI1 must be disabled in device tree.
&sai1 {
status = "disabled";
};
To use the XSPI1_TXC pin with the GPIO functionality, the following pin muxing must be added in the iomux node of the imx93-11x11-evk.dts file (located in dts/upstream/src/arm64/freescale/
pinctrl_hog: hoggrp {
fsl,pins = <
MX93_PAD_SAI1_TXC__GPIO1_IO12 0x51e
>;
};
Include the correct header files
In the file you want to use the GPIO, include the following headers:
#include <asm/arch-mx7ulp/gpio.h>
#include <asm-generic/gpio.h>
Define the GPIO
To define the GPIO's handle, use the IMX_GPIO_NR(bank, index) macro.
- index = The pin number within the bank.
- bank = The GPIO bank number, mapped as follows (due to the way they are placed in memory):
| GPIO Bank |
bank value for IMX_GPIO_NR |
| GPIO1 |
4 |
| GPIO2 |
1 |
| GPIO3 |
2 |
| GPIO4 |
3 |
- Example 1: Compute the handle for GPIO2_IO05
#define TIMED_GPIO IMX_GPIO_NR(1, 5)
- Example 2: Compute the handle for XSPI1_TXC (GPIO1_IO12)
#define TIMED_GPIO IMX_GPIO_NR(4, 12)
Read the GPIO pin
gpio_request(TIMED_GPIO, "timed_gpio");
gpio_direction_input(TIMED_GPIO);
int val = gpio_get_value(TIMED_GPIO);
printf("GPIO value is %d\n", val);
Write the GPIO pin
gpio_request(TIMED_GPIO, "timed_gpio");
// set the pin as output and make it high
gpio_direction_output(TIMED_GPIO, 1);
The driver used is drivers/gpio/gpio-uclass.c.