/dev/gpiomem provides user with root-free access to the GPIO registers. Opening /dev/gpiomem device file and calling mmap() function will map the GPIO registers' memory map area to the user's pointer.
This driver is available in below's Ubuntu kernel versions:
/dev/gpiomem driver is included as module by default. In order to use gpiomem driver, it is necessary to configure account access permission.
$ sudo addgroup gpio $ sudo usermod -a -G gpio odroid $ cat /etc/udev/rules.d/90-gpiomem.rules
SUBSYSTEM=="meson-gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="exynos-gpiomem", GROUP="gpio", MODE="0660"
Hardkernel's wiringPi library which is for GPIO control uses /dev/gpiomem device file for rootless gpio control. Usage is very simple. Just open /dev/gpiomem device file instead of /dev/mem.
// Open the master /dev/memory device if (access("/dev/gpiomem",0) == 0) { if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ; } else { if (geteuid () != 0) (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; }
$ sudo addgroup gpio $ sudo usermod -a -G gpio odroid $ cat /etc/udev/rules.d/90-odroid-sysfs.rules
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'" SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"