Skip to Content
Linux Device Drivers Development
book

Linux Device Drivers Development

by John Madieu
October 2017
Intermediate to advanced
586 pages
14h 8m
English
Packt Publishing
Content preview from Linux Device Drivers Development

Claiming and configuring the GPIO

You can allocate and take ownership of a GPIO using the gpio_request() function:

static int  gpio_request(unsigned gpio, const char *label) 

gpio represents the GPIO number we are interested in, and label is the label used by the kernel for the GPIO in sysfs, as we can see in /sys/kernel/debug/gpio. You have to check the value returned, where 0 mean success and a negative error code is produced on an error. Once you've done this with the GPIO, it should be set free with the gpio_free() function:

void gpio_free(unsigned int gpio) 

If in doubt, you can use the gpio_is_valid() function to check whether this GPIO number is valid on the system prior to allocating it:

static bool gpio_is_valid(int number) 

Once ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Device Drivers, Second Edition

Linux Device Drivers, Second Edition

Jonathan Corbet, Alessandro Rubini
Linux Device Drivers, 3rd Edition

Linux Device Drivers, 3rd Edition

Jonathan Corbet, Alessandro Rubini, Greg Kroah-Hartman

Publisher Resources

ISBN: 9781785280009Supplemental Content