1

I am using the SAMA5D27 SoM1 Ek Board (Microchip) and am using Yocto.

My linux-at91 is 4.14 version.

In this linux-at91 kernel by default sysfs gpio export and userspace control support is removed.

How do I enable export gpio in sysfs?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
yoctotutor.com
  • 5,145
  • 4
  • 26
  • 36

1 Answers1

2

Straight (but bad) answer: you'll need to rebuild your kernel with CONFIG_GPIO_SYSFS option enabled (=y).

Good answer: using GPIO via sysfs is considered obsolete now (starting from July 2008) and it's discouraged to use it. That's why it was disabled in kernel by default (in v4.10). See this commit message from Linus Walleij (who is GPIO maintainer in Linux kernel):

ARM: defconfig: drop GPIO_SYSFS on multiplatforms

The sysfs ABI to GPIO is marked obsolete and should not be
encouraged. Users should be encouraged to switch to using the
character device.

Let's begin by removing it from the multi defconfigs. Then
as time goes by I can aggressively remove it from other
defconfigs.

So basically it's recommended to use /dev/gpiochip* character device files now for GPIO manipulations (instead of sysfs way). For example, you can build user-space utils from tools/gpio/ and use them to test GPIO via that character device. You might want to write some custom user-space app to work with GPIO via character device, for your particular task. Read Documentation/ABI/testing/gpio-cdev file for details. This way you won't need to rebuild the kernel. Also, old sysfs ABI will be removed in 2020, as stated here.

Sam Protsenko
  • 14,045
  • 4
  • 59
  • 75
  • 1
    You may also mention the user space library `libgpiod` in order to help writing user space applications. – 0andriy Feb 07 '19 at 16:42
  • 1
    @0andriy Thanks, didn't know about that. – Sam Protsenko Feb 07 '19 at 20:33
  • Is that sill valid for today - the best way to go to GPIO interface is through the character device flies? – Mendes Jul 25 '23 at 13:48
  • @Mendes Depends on what you want to do. The only really correct answer: you have to access GPIOs from kernel space, by either writing your new driver or reusing some existing one. There are generic GPIO drivers already available: https://docs.kernel.org/driver-api/gpio/drivers-on-gpio.html . If you still want to do that from user space, then yes, please use the GPIO character device files. – Sam Protsenko Jul 29 '23 at 01:56