How to initial GPIO as input or output PINS

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to initial GPIO as input or output PINS

2,535 Views
tzeng015
Contributor II

Hi 

Platform : imx8mm

Linux : 5.10 

I want to check the GPIO4_14 status . Here is my check list 

u-boot

tzeng015_0-1669788777136.png

 

kernel 

tzeng015_1-1669788815577.png

 

I can't see the GPIO4_14 status. 

Anyone can help me to  initial the GPIO input or output in which file ? I don't know where is  the file can initial GPIO ?

Please help me.

thank you

tzeng015

 

 

 

0 Kudos
Reply
1 Reply

2,525 Views
edwardtyrrell
Senior Contributor I

Hi @tzeng015 

See what you get with cat /sys/kernel/debug/gpio, sys/class/gpio is being deprecated and with new builds (i.e. mine) it's not even available. 

For example my board gives:

cat /sys/kernel/debug/gpio
gpiochip0: GPIOs 0-31, parent: platform/30200000.gpio, 30200000.gpio:
gpio-15 ( |cd ) in hi IRQ ACTIVE LOW

gpiochip1: GPIOs 32-63, parent: platform/30210000.gpio, 30210000.gpio:
gpio-42 ( |reset ) out hi ACTIVE LOW
gpio-51 ( |regulator-usdhc2 ) out lo

Also, unlike /sys/class/gpio, pins used with gpiod need to be in your device-tree pinctrl_hog to work. 

opinctrl_hog: hoggrp {
fsl,pins = <
MX8MM_IOMUXC_SAI5_RXD0_GPIO3_IO21 0x19
MX8MM_IOMUXC_SAI5_RXD1_GPIO3_IO22 0x19
MX8MM_IOMUXC_SAI5_RXD2_GPIO3_IO23 0x19
MX8MM_IOMUXC_SAI5_RXD3_GPIO3_IO24 0x19
>;
};

One other thing, be careful with gpioset as the gpiod's start at gpiochip0 where the iMX8 mux registers start at 1. Whether 'gpio state -a' in UBoot is offset by one I haven't tried. Here's an example of using gpiod in userspace: 

Pin MX8MM_IOMUXC_SAI5_RXD0_GPIO3_IO21

Set GPIO3_21 high:  // As above
gpioset gpiochip2 21=1

Set GPIO3_21 low:  // As above
gpioset gpiochip2 21=0

Check the line with a scope or the memory read command  /unit_tests/memtool -32 <Address> 1

3022_0000 GPIO data register (GPIO3_DR) // Page 1691 of Ref manual

/unit_tests/memtool -32 0x30220000 1
E
Reading 0x1 count starting at address 0x30220000

0x30220000: 00200000  // if GPIO3_21 is high, 

0x30220000: 00000000 // If low

Hope this helps.

0 Kudos
Reply