Skip to content

Conversation

jmacagba
Copy link
Contributor

/sys/class/gpio is deprecated in newer Linux Kernel

Pull Request Description

Resolves #2517.
Replaces deprecated /sys/class/gpio for controlling GPIOs and using GPIO Character Device Userspace API instead.

PR Type

  • Bug fix (change that fixes an issue)
  • New feature (change that adds new functionality)
  • Breaking change (has dependencies in other repos or will cause CI to fail)

PR Checklist

  • I have followed the Coding style guidelines
  • I have complied with the Submission Checklist
  • I have performed a self-review of the changes
  • I have commented my code, at least hard-to-understand parts
  • I have build all projects affected by the changes in this PR
  • I have tested in hardware affected projects, at the relevant boards
  • I have signed off all commits from this PR
  • I have updated the documentation (wiki pages, ReadMe etc), if applies

@jmacagba jmacagba marked this pull request as ready for review July 17, 2025 04:54
Copy link
Contributor

@CiprianRegus CiprianRegus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall. Apart from these minor remarks, please provide more details in the commit message (what are you replacing the /sys/class/gpio interface with and the kernel version in which the old interface was deprecated).

else
ret = write(linux_desc->value_fd, "0", 2);
// Set Line Value
memset(&line_value, 0, sizeof(line_value));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can set the value of line_value whenever you declare it:

struct gpio_v2_line_values line_value = {0};

Applies to multiple cases in this file, so please update all of them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 6b1a03f

Comment on lines 337 to 341
if (line_info.flags & GPIO_V2_LINE_FLAG_OUTPUT) {
*direction = NO_OS_GPIO_OUT;
else
} else if (line_info.flags & GPIO_V2_LINE_FLAG_INPUT) {
*direction = NO_OS_GPIO_IN;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use braces in case the if statement contains just one line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 6b1a03f

// Set Line Value
memset(&line_value, 0, sizeof(line_value));
line_value.bits = value;
line_value.mask = 1; // Only set one line (or one GPIO)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment style should be /* */.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in commit 6b1a03f

@jmacagba
Copy link
Contributor Author

Looks good overall. Apart from these minor remarks, please provide more details in the commit message (what are you replacing the /sys/class/gpio interface with and the kernel version in which the old interface was deprecated).

Hi @CiprianRegus , I can only find this documentation stating that /sys/class/gpio will be obsolete starting 2020: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/ABI/obsolete/sysfs-gpio?h=v5.16&id=fe95046e960b4b76e73dc1486955d93f47276134

/sys/class/gpio is deprecated and was removed after 2020.
It is replaced with GPIO character device.

Signed-off-by: Jamila Macagba <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Linux GPIO /sys/class/gpio is deprecated
2 participants