Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Data Structures | Macros | Functions
gpiolib.c File Reference
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/interrupt.h>
#include <linux/irq.h>
#include <linux/spinlock.h>
#include <linux/device.h>
#include <linux/err.h>
#include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/gpio.h>
#include <linux/of_gpio.h>
#include <linux/idr.h>
#include <linux/slab.h>
#include <trace/events/gpio.h>

Go to the source code of this file.

Data Structures

struct  gpio_desc
 

Macros

#define CREATE_TRACE_POINTS
 
#define extra_checks   0
 
#define FLAG_REQUESTED   0
 
#define FLAG_IS_OUT   1
 
#define FLAG_RESERVED   2
 
#define FLAG_EXPORT   3 /* protected by sysfs_lock */
 
#define FLAG_SYSFS   4 /* exported via /sys/class/gpio/control */
 
#define FLAG_TRIG_FALL   5 /* trigger on falling edge */
 
#define FLAG_TRIG_RISE   6 /* trigger on rising edge */
 
#define FLAG_ACTIVE_LOW   7 /* sysfs value has active low */
 
#define FLAG_OPEN_DRAIN   8 /* Gpio is open drain type */
 
#define FLAG_OPEN_SOURCE   9 /* Gpio is open source type */
 
#define ID_SHIFT   16 /* add new flags before this one */
 
#define GPIO_FLAGS_MASK   ((1 << ID_SHIFT) - 1)
 
#define GPIO_TRIGGER_MASK   (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
 

Functions

struct gpio_chip * gpio_to_chip (unsigned gpio)
 
int __init gpiochip_reserve (int start, int ngpio)
 
int gpiochip_add (struct gpio_chip *chip)
 
 EXPORT_SYMBOL_GPL (gpiochip_add)
 
int gpiochip_remove (struct gpio_chip *chip)
 
 EXPORT_SYMBOL_GPL (gpiochip_remove)
 
struct gpio_chip * gpiochip_find (void *data, int(*match)(struct gpio_chip *chip, void *data))
 
 EXPORT_SYMBOL_GPL (gpiochip_find)
 
int gpio_request (unsigned gpio, const char *label)
 
 EXPORT_SYMBOL_GPL (gpio_request)
 
void gpio_free (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (gpio_free)
 
int gpio_request_one (unsigned gpio, unsigned long flags, const char *label)
 
 EXPORT_SYMBOL_GPL (gpio_request_one)
 
int gpio_request_array (const struct gpio *array, size_t num)
 
 EXPORT_SYMBOL_GPL (gpio_request_array)
 
void gpio_free_array (const struct gpio *array, size_t num)
 
 EXPORT_SYMBOL_GPL (gpio_free_array)
 
const chargpiochip_is_requested (struct gpio_chip *chip, unsigned offset)
 
 EXPORT_SYMBOL_GPL (gpiochip_is_requested)
 
int gpio_direction_input (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (gpio_direction_input)
 
int gpio_direction_output (unsigned gpio, int value)
 
 EXPORT_SYMBOL_GPL (gpio_direction_output)
 
int gpio_set_debounce (unsigned gpio, unsigned debounce)
 
 EXPORT_SYMBOL_GPL (gpio_set_debounce)
 
int __gpio_get_value (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (__gpio_get_value)
 
void __gpio_set_value (unsigned gpio, int value)
 
 EXPORT_SYMBOL_GPL (__gpio_set_value)
 
int __gpio_cansleep (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (__gpio_cansleep)
 
int __gpio_to_irq (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (__gpio_to_irq)
 
int gpio_get_value_cansleep (unsigned gpio)
 
 EXPORT_SYMBOL_GPL (gpio_get_value_cansleep)
 
void gpio_set_value_cansleep (unsigned gpio, int value)
 
 EXPORT_SYMBOL_GPL (gpio_set_value_cansleep)
 

Macro Definition Documentation

#define CREATE_TRACE_POINTS

Definition at line 15 of file gpiolib.c.

#define extra_checks   0

Definition at line 40 of file gpiolib.c.

#define FLAG_ACTIVE_LOW   7 /* sysfs value has active low */

Definition at line 60 of file gpiolib.c.

#define FLAG_EXPORT   3 /* protected by sysfs_lock */

Definition at line 56 of file gpiolib.c.

#define FLAG_IS_OUT   1

Definition at line 54 of file gpiolib.c.

#define FLAG_OPEN_DRAIN   8 /* Gpio is open drain type */

Definition at line 61 of file gpiolib.c.

#define FLAG_OPEN_SOURCE   9 /* Gpio is open source type */

Definition at line 62 of file gpiolib.c.

#define FLAG_REQUESTED   0

Definition at line 53 of file gpiolib.c.

#define FLAG_RESERVED   2

Definition at line 55 of file gpiolib.c.

#define FLAG_SYSFS   4 /* exported via /sys/class/gpio/control */

Definition at line 57 of file gpiolib.c.

#define FLAG_TRIG_FALL   5 /* trigger on falling edge */

Definition at line 58 of file gpiolib.c.

#define FLAG_TRIG_RISE   6 /* trigger on rising edge */

Definition at line 59 of file gpiolib.c.

#define GPIO_FLAGS_MASK   ((1 << ID_SHIFT) - 1)

Definition at line 66 of file gpiolib.c.

#define GPIO_TRIGGER_MASK   (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))

Definition at line 67 of file gpiolib.c.

#define ID_SHIFT   16 /* add new flags before this one */

Definition at line 64 of file gpiolib.c.

Function Documentation

int __gpio_cansleep ( unsigned  gpio)

__gpio_cansleep() - report whether gpio value access will sleep : gpio in question Context: any

This is used directly or indirectly to implement gpio_cansleep(). It returns nonzero if access reading or writing the GPIO value can sleep.

Definition at line 1691 of file gpiolib.c.

int __gpio_get_value ( unsigned  gpio)

__gpio_get_value() - return a gpio's value : gpio whose value will be returned Context: any

This is used directly or indirectly to implement gpio_get_value(). It returns the zero or nonzero value provided by the associated gpio_chip.get() method; or zero if no such method is provided.

Definition at line 1592 of file gpiolib.c.

void __gpio_set_value ( unsigned  gpio,
int  value 
)

__gpio_set_value() - assign a gpio's value : gpio whose value will be assigned : value to assign Context: any

This is used directly or indirectly to implement gpio_set_value(). It invokes the associated gpio_chip.set() method.

Definition at line 1666 of file gpiolib.c.

int __gpio_to_irq ( unsigned  gpio)

__gpio_to_irq() - return the IRQ corresponding to a GPIO : gpio whose IRQ will be returned (already requested) Context: any

This is used directly or indirectly to implement gpio_to_irq(). It returns the number of the IRQ signaled by this (input) GPIO, or a negative errno.

Definition at line 1711 of file gpiolib.c.

EXPORT_SYMBOL_GPL ( gpiochip_add  )
EXPORT_SYMBOL_GPL ( gpiochip_remove  )
EXPORT_SYMBOL_GPL ( gpiochip_find  )
EXPORT_SYMBOL_GPL ( gpio_request  )
EXPORT_SYMBOL_GPL ( gpio_free  )
EXPORT_SYMBOL_GPL ( gpio_request_one  )
EXPORT_SYMBOL_GPL ( gpio_request_array  )
EXPORT_SYMBOL_GPL ( gpio_free_array  )
EXPORT_SYMBOL_GPL ( gpiochip_is_requested  )
EXPORT_SYMBOL_GPL ( gpio_direction_input  )
EXPORT_SYMBOL_GPL ( gpio_direction_output  )
EXPORT_SYMBOL_GPL ( gpio_set_debounce  )
EXPORT_SYMBOL_GPL ( __gpio_get_value  )
EXPORT_SYMBOL_GPL ( __gpio_set_value  )
EXPORT_SYMBOL_GPL ( __gpio_cansleep  )
EXPORT_SYMBOL_GPL ( __gpio_to_irq  )
EXPORT_SYMBOL_GPL ( gpio_get_value_cansleep  )
EXPORT_SYMBOL_GPL ( gpio_set_value_cansleep  )
int gpio_direction_input ( unsigned  gpio)

Definition at line 1399 of file gpiolib.c.

int gpio_direction_output ( unsigned  gpio,
int  value 
)

Definition at line 1454 of file gpiolib.c.

void gpio_free ( unsigned  gpio)

Definition at line 1243 of file gpiolib.c.

void gpio_free_array ( const struct gpio array,
size_t  num 
)

gpio_free_array - release multiple GPIOs in a single call : array of the 'struct gpio' : how many GPIOs in the array

Definition at line 1353 of file gpiolib.c.

int gpio_get_value_cansleep ( unsigned  gpio)

Definition at line 1726 of file gpiolib.c.

int gpio_request ( unsigned  gpio,
const char label 
)

Definition at line 1187 of file gpiolib.c.

int gpio_request_array ( const struct gpio array,
size_t  num 
)

gpio_request_array - request multiple GPIOs in a single call : array of the 'struct gpio' : how many GPIOs in the array

Definition at line 1330 of file gpiolib.c.

int gpio_request_one ( unsigned  gpio,
unsigned long  flags,
const char label 
)

gpio_request_one - request a single GPIO with initial configuration : the GPIO number : GPIO configuration as specified by GPIOF_* : a literal description string of this GPIO

Definition at line 1288 of file gpiolib.c.

int gpio_set_debounce ( unsigned  gpio,
unsigned  debounce 
)

gpio_set_debounce - sets time for a : the gpio to set debounce time : debounce time is microseconds

Definition at line 1522 of file gpiolib.c.

void gpio_set_value_cansleep ( unsigned  gpio,
int  value 
)

Definition at line 1739 of file gpiolib.c.

struct gpio_chip* gpio_to_chip ( unsigned  gpio)
read

Definition at line 119 of file gpiolib.c.

int gpiochip_add ( struct gpio_chip *  chip)

gpiochip_add() - register a gpio_chip : the chip to register, with chip->base initialized Context: potentially before irqs or kmalloc will work

Returns a negative errno if the chip can't be registered, such as because the chip->base is invalid or already associated with a different chip. Otherwise it returns zero as a success code.

When gpiochip_add() is called very early during boot, so that GPIOs can be freely used, the chip->dev device must be registered before the gpio framework's arch_initcall(). Otherwise sysfs initialization for GPIOs will fail rudely.

If chip->base is negative, this requests dynamic assignment of a range of valid GPIOs.

Definition at line 1039 of file gpiolib.c.

struct gpio_chip* gpiochip_find ( void data,
int(*)(struct gpio_chip *chip, void *data match 
)
read

gpiochip_find() - iterator for locating a specific gpio_chip : data to pass to match function : Callback function to check gpio_chip

Similar to bus_find_device. It returns a reference to a gpio_chip as determined by a user supplied callback. The callback should return 0 if the device doesn't match and non-zero if it does. If the callback is non-zero, this function will return to the caller and not iterate over any more gpio_chips.

Definition at line 1159 of file gpiolib.c.

const char* gpiochip_is_requested ( struct gpio_chip *  chip,
unsigned  offset 
)

gpiochip_is_requested - return string iff signal was requested : controller managing the signal : of signal within controller's 0..(ngpio - 1) range

Returns NULL if the GPIO is not currently requested, else a string. If debugfs support is enabled, the string returned is the label passed to gpio_request(); otherwise it is a meaningless constant.

This function is for use by GPIO controller drivers. The label can help with diagnostics, and knowing that the signal is used as a GPIO can help avoid accidentally multiplexing it to another controller.

Definition at line 1373 of file gpiolib.c.

int gpiochip_remove ( struct gpio_chip *  chip)

gpiochip_remove() - unregister a gpio_chip : the chip to unregister

A gpio_chip with any GPIOs still requested may not be removed.

Definition at line 1118 of file gpiolib.c.

int __init gpiochip_reserve ( int  start,
int  ngpio 
)

gpiochip_reserve() - reserve range of gpios to use with platform code only : starting gpio number : number of gpios to reserve Context: platform init, potentially before irqs or kmalloc will work

Returns a negative errno if any gpio within the range is already reserved or registered, else returns zero as a success code. Use this function to mark a range of gpios as unavailable for dynamic gpio number allocation, for example because its driver support is not yet loaded.

Definition at line 164 of file gpiolib.c.