Table of Contents

Using GPIO from sysfs

Where to find GPIO's in sysfs

GPIO's are listed under /sys/class/gpio

Calculate Linux GPIO Number Freescale i.MX Processor Family

Linux GPIO Number = <GPIO_bank – 1> × 32 + <GPIO Port number>

example

Calculate Linux GPIO Number Texas Instruments Sitara Family

Linux GPIO Number = <GPIO_bank x 32> + <GPIO Port number>

example

Set GPIO as output

root@MBaXXX:~ echo <gpionr> >/sys/class/gpio/export                  // export GPIO pin
root@MBaXXX:~ echo out > /sys/class/gpio/gpio<gpionr>/direction      // set GPIO direction
root@MBaXXX:~ echo 1 > /sys/class/gpio/gpio<gpionr>/value            // toggle GPIO to high 
root@MBaXXX:~ echo 0 > /sys/class/gpio/gpio<gpionr>/value            // toggle GPIO to low 

example

Set GPIO as Input

root@MBaXXX:~ echo „<gpionr>" >/sys/class/gpio/export                  // export GPIO pin 
root@MBaXXX:~ echo in > /sys/class/gpio/gpio<gpionr>/direction       // set GPIO direction
root@MBaXXX:~ cat /sys/class/gpio/gpio<gpionr>/value                   // read GPIO value

example

Using GPIO in U-Boot

Tested with TQMa28

It is possible to toggle the GPIO's in U-Boot with the gpio command. To use gpio command the desired gpio pin number has to be given as parameter to the command. The following bitmask applies to GPIO pin number in U-Boot:
[PPPP P_BBB] P = pin, B = bank

For example we toggle GPIO0_24 on MBa28

GPIO0_24 = GPIO Bank 0, Pin 24, GPIO0_24 = 11000