General Purpose Input/Output (GPIO)

Contents:

Core

structgpio_irq_chip

GPIO interrupt controller

Definition:

struct gpio_irq_chip {    struct irq_chip *chip;    struct irq_domain *domain;#ifdef CONFIG_IRQ_DOMAIN_HIERARCHY;    struct fwnode_handle *fwnode;    struct irq_domain *parent_domain;    int (*child_to_parent_hwirq)(struct gpio_chip *gc, unsigned int child_hwirq, unsigned int child_type, unsigned int *parent_hwirq, unsigned int *parent_type);    int (*populate_parent_alloc_arg)(struct gpio_chip *gc, union gpio_irq_fwspec *fwspec, unsigned int parent_hwirq, unsigned int parent_type);    unsigned int (*child_offset_to_irq)(struct gpio_chip *gc, unsigned int pin);    struct irq_domain_ops child_irq_domain_ops;#endif;    irq_flow_handler_t handler;    unsigned int default_type;    struct lock_class_key *lock_key;    struct lock_class_key *request_key;    irq_flow_handler_t parent_handler;    union {        void *parent_handler_data;        void **parent_handler_data_array;    };    unsigned int num_parents;    unsigned int *parents;    unsigned int *map;    bool threaded;    bool per_parent_data;    bool initialized;    bool domain_is_allocated_externally;    int (*init_hw)(struct gpio_chip *gc);    void (*init_valid_mask)(struct gpio_chip *gc, unsigned long *valid_mask, unsigned int ngpios);    unsigned long *valid_mask;    unsigned int first;    void (*irq_enable)(struct irq_data *data);    void (*irq_disable)(struct irq_data *data);    void (*irq_unmask)(struct irq_data *data);    void (*irq_mask)(struct irq_data *data);};

Members

chip

GPIO IRQ chip implementation, provided by GPIO driver.

domain

Interrupt translation domain; responsible for mapping between GPIOhwirq number and Linux IRQ number.

fwnode

Firmware node corresponding to this gpiochip/irqchip, necessaryfor hierarchical irqdomain support.

parent_domain

If non-NULL, will be set as the parent of this GPIO interruptcontroller’s IRQ domain to establish a hierarchical interruptdomain. The presence of this will activate the hierarchicalinterrupt support.

child_to_parent_hwirq

This callback translates a child hardware IRQ offset to a parenthardware IRQ offset on a hierarchical interrupt chip. The childhardware IRQs correspond to the GPIO index 0..ngpio-1 (see thengpio field ofstructgpio_chip) and the corresponding parenthardware IRQ and type (such as IRQ_TYPE_*) shall be returned bythe driver. The driver can calculate this from an offset or usinga lookup table or whatever method is best for this chip. Return0 on successful translation in the driver.

If some ranges of hardware IRQs do not have a corresponding parentHWIRQ, return -EINVAL, but also make sure to fill invalid_mask andneed_valid_mask to make these GPIO lines unavailable fortranslation.

populate_parent_alloc_arg

This optional callback allocates and populates the specific structfor the parent’s IRQ domain. If this is not specified, thengpiochip_populate_parent_fwspec_twocell will be used. A four-cellvariant namedgpiochip_populate_parent_fwspec_fourcell is alsoavailable.

child_offset_to_irq

This optional callback is used to translate the child’s GPIO lineoffset on the GPIO chip to an IRQ number for the GPIOto_irq()callback. If this is not specified, then a default callback will beprovided that returns the line offset.

child_irq_domain_ops

The IRQ domain operations that will be used for this GPIO IRQchip. If no operations are provided, then default callbacks willbe populated to setup the IRQ hierarchy. Some drivers need tosupply their own translate function.

handler

The IRQ handler to use (often a predefined IRQ core function) forGPIO IRQs, provided by GPIO driver.

default_type

Default IRQ triggering type applied during GPIO driverinitialization, provided by GPIO driver.

lock_key

Per GPIO IRQ chip lockdep class for IRQ lock.

request_key

Per GPIO IRQ chip lockdep class for IRQ request.

parent_handler

The interrupt handler for the GPIO chip’s parent interrupts, may beNULL if the parent interrupts are nested rather than cascaded.

{unnamed_union}

anonymous

parent_handler_data

Ifper_parent_data is false,parent_handler_data is asingle pointer used as the data associated with everyparent interrupt.

parent_handler_data_array

Ifper_parent_data is true,parent_handler_data_array isan array ofnum_parents pointers, and is used to associatedifferent data for each parent. This cannot be NULL ifper_parent_data is true.

num_parents

The number of interrupt parents of a GPIO chip.

parents

A list of interrupt parents of a GPIO chip. This is owned by thedriver, so the core will only reference this list, not modify it.

map

A list of interrupt parents for each line of a GPIO chip.

threaded

True if set the interrupt handling uses nested threads.

per_parent_data

True if parent_handler_data_array describes anum_parentssized array to be used as parent data.

initialized

Flag to track GPIO chip irq member’s initialization.This flag will make sure GPIO chip irq members are not usedbefore they are initialized.

domain_is_allocated_externally

True it the irq_domain was allocated outside of gpiolib, in whichcase gpiolib won’t free the irq_domain itself.

init_hw

optional routine to initialize hardware beforean IRQ chip will be added. This is quite useful whena particular driver wants to clear IRQ related registersin order to avoid undesired events.

init_valid_mask

optional routine to initializevalid_mask, to beused if not all GPIO lines are valid interrupts. Sometimes somelines just cannot fire interrupts, and this routine, when defined,is passed a bitmap in “valid_mask” and it will have ngpiosbits from 0..(ngpios-1) set to “1” as in valid. The callback canthen directly set some bits to “0” if they cannot be used forinterrupts.

valid_mask

If notNULL, holds bitmask of GPIOs which are valid to be includedin IRQ domain of the chip.

first

Required for static IRQ allocation. If set,irq_domain_create_simple() will allocate and map all IRQsduring initialization.

irq_enable

Store old irq_chip irq_enable callback

irq_disable

Store old irq_chip irq_disable callback

irq_unmask

Store old irq_chip irq_unmask callback

irq_mask

Store old irq_chip irq_mask callback

structgpio_chip

abstract a GPIO controller

Definition:

struct gpio_chip {    const char              *label;    struct gpio_device      *gpiodev;    struct device           *parent;    struct fwnode_handle    *fwnode;    struct module           *owner;    int (*request)(struct gpio_chip *gc, unsigned int offset);    void (*free)(struct gpio_chip *gc, unsigned int offset);    int (*get_direction)(struct gpio_chip *gc, unsigned int offset);    int (*direction_input)(struct gpio_chip *gc, unsigned int offset);    int (*direction_output)(struct gpio_chip *gc, unsigned int offset, int value);    int (*get)(struct gpio_chip *gc, unsigned int offset);    int (*get_multiple)(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits);    int (*set)(struct gpio_chip *gc, unsigned int offset, int value);    int (*set_multiple)(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits);    int (*set_config)(struct gpio_chip *gc, unsigned int offset, unsigned long config);    int (*to_irq)(struct gpio_chip *gc, unsigned int offset);    void (*dbg_show)(struct seq_file *s, struct gpio_chip *gc);    int (*init_valid_mask)(struct gpio_chip *gc, unsigned long *valid_mask, unsigned int ngpios);    int (*add_pin_ranges)(struct gpio_chip *gc);    int (*en_hw_timestamp)(struct gpio_chip *gc, u32 offset, unsigned long flags);    int (*dis_hw_timestamp)(struct gpio_chip *gc, u32 offset, unsigned long flags);    int base;    u16 ngpio;    u16 offset;    const char              *const *names;    bool can_sleep;#ifdef CONFIG_GPIOLIB_IRQCHIP;    struct gpio_irq_chip irq;#endif;#if defined(CONFIG_OF_GPIO);    unsigned int of_gpio_n_cells;    bool (*of_node_instance_match)(struct gpio_chip *gc, unsigned int i);    int (*of_xlate)(struct gpio_chip *gc, const struct of_phandle_args *gpiospec, u32 *flags);#endif;};

Members

label

a functional name for the GPIO device, such as a partnumber or the name of the SoC IP-block implementing it.

gpiodev

the internal state holder, opaque struct

parent

optional parent device providing the GPIOs

fwnode

optional fwnode providing this controller’s properties

owner

helps prevent removal of modules exporting active GPIOs

request

optional hook for chip-specific activation, such asenabling module power and clock; may sleep; must return 0 on successor negative error number on failure

free

optional hook for chip-specific deactivation, such asdisabling module power and clock; may sleep

get_direction

returns direction for signal “offset”, 0=out, 1=in,(same as GPIO_LINE_DIRECTION_OUT / GPIO_LINE_DIRECTION_IN),or negative error. It is recommended to always implement thisfunction, even on input-only or output-only gpio chips.

direction_input

configures signal “offset” as input, returns 0 on successor a negative error number. This can be omitted on input-only oroutput-only gpio chips.

direction_output

configures signal “offset” as output, returns 0 onsuccess or a negative error number. This can be omitted on input-onlyor output-only gpio chips.

get

returns value for signal “offset”, 0=low, 1=high, or negative error

get_multiple

reads values for multiple signals defined by “mask” andstores them in “bits”, returns 0 on success or negative error

set

assigns output value for signal “offset”, returns 0 on success ornegative error value

set_multiple

assigns output values for multiple signals defined by“mask”, returns 0 on success or negative error value

set_config

optional hook for all kinds of settings. Uses the samepacked config format as generic pinconf. Must return 0 on success anda negative error number on failure.

to_irq

optional hook supporting non-staticgpiod_to_irq() mappings;implementation may not sleep

dbg_show

optional routine to show contents in debugfs; default codewill be used when this is omitted, but custom code can show extrastate (such as pullup/pulldown configuration).

init_valid_mask

optional routine to initializevalid_mask, to be used ifnot all GPIOs are valid.

add_pin_ranges

optional routine to initialize pin ranges, to be used whenrequires special mapping of the pins that provides GPIO functionality.It is called after adding GPIO chip and before adding IRQ chip.

en_hw_timestamp

Dependent on GPIO chip, an optional routine toenable hardware timestamp.

dis_hw_timestamp

Dependent on GPIO chip, an optional routine todisable hardware timestamp.

base

identifies the first GPIO number handled by this chip;or, if negative during registration, requests dynamic ID allocation.DEPRECATION: providing anything non-negative and nailing the baseoffset of GPIO chips is deprecated. Please pass -1 as base tolet gpiolib select the chip base in all possible cases. We want toget rid of the static GPIO number space in the long run.

ngpio

the number of GPIOs handled by this controller; the last GPIOhandled is (base + ngpio - 1).

offset

when multiple gpio chips belong to the same device thiscan be used as offset within the device so friendly names canbe properly assigned.

names

if set, must be an array of strings to use as alternativenames for the GPIOs in this chip. Any entry in the arraymay be NULL if there is no alias for the GPIO, however thearray must bengpio entries long.

can_sleep

flag must be set iffget()/set() methods sleep, as theymust while accessing GPIO expander chips over I2C or SPI. Thisimplies that if the chip supports IRQs, these IRQs need to be threadedas the chip access may sleep when e.g. reading out the IRQ statusregisters.

irq

Integrates interrupt chip functionality with the GPIO chip. Can beused to handle IRQs for most practical cases.

of_gpio_n_cells

Number of cells used to form the GPIO specifier. The standard is 2cells:

gpios = <gpio offset flags>;

some complex GPIO controllers instantiate more than one chip perdevice tree node and have 3 cells:

gpios = <gpio instance offset flags>;

Legacy GPIO controllers may even have 1 cell:

gpios = <gpio offset>;

of_node_instance_match

Determine if a chip is the right instance. Must be implemented byany driver using more than one gpio_chip per device tree node.Returns true if gc is the instance indicated by i (which is thefirst cell in the phandles for GPIO lines and gpio-ranges).

of_xlate

Callback to translate a device tree GPIO specifier into a chip-relative GPIO number and flags.

Description

A gpio_chip can help platforms abstract various sources of GPIOs sothey can all be accessed through a common programming interface.Example sources would be SOC controllers, FPGAs, multifunctionchips, dedicated GPIO expanders, and so on.

Each chip controls a number of signals, identified in method callsby “offset” values in the range 0..(ngpio - 1). When those signalsare referenced through calls like gpio_get_value(gpio), the offsetis calculated by subtractingbase from the gpio number.

for_each_hwgpio_in_range

for_each_hwgpio_in_range(_chip,_i,_base,_size,_label)

Iterates over all GPIOs in a given range

Parameters

_chip

Chip to iterate over.

_i

Loop counter.

_base

First GPIO in the ranger.

_size

Amount of GPIOs to check starting frombase.

_label

Place to store the address of the label if the GPIO is requested.Set to NULL for unused GPIOs.

for_each_hwgpio

for_each_hwgpio(_chip,_i,_label)

Iterates over all GPIOs for given chip.

Parameters

_chip

Chip to iterate over.

_i

Loop counter.

_label

Place to store the address of the label if the GPIO is requested.Set to NULL for unused GPIOs.

for_each_requested_gpio_in_range

for_each_requested_gpio_in_range(_chip,_i,_base,_size,_label)

iterates over requested GPIOs in a given range

Parameters

_chip

the chip to query

_i

loop variable

_base

first GPIO in the range

_size

amount of GPIOs to check starting frombase

_label

label of current GPIO

gpiochip_add_data

gpiochip_add_data(gc,data)

register a gpio_chip

Parameters

gc

the chip to register, with gc->base initialized

data

driver-private data associated with this chip

Context

potentially before irqs will work

Description

Whengpiochip_add_data() is called very early during boot, so that GPIOscan be freely used, the gc->parent device must be registered beforethe gpio framework’sarch_initcall(). Otherwise sysfs initializationfor GPIOs will fail rudely.

gpiochip_add_data() must only be called after gpiolib initialization,i.e. aftercore_initcall().

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

Return

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

structgpio_pin_range

pin range controlled by a gpio chip

Definition:

struct gpio_pin_range {    struct list_head node;    struct pinctrl_dev *pctldev;    struct pinctrl_gpio_range range;};

Members

node

list for maintaining set of pin ranges, used internally

pctldev

pinctrl device which handles corresponding pins

range

actual range of pins controlled by a gpio controller

structgpio_desc*gpio_to_desc(unsignedgpio)

Convert a GPIO number to its descriptor

Parameters

unsignedgpio

global GPIO number

Return

The GPIO descriptor associated with the given GPIO, orNULL if no GPIOwith the given number exists in the system.

structgpio_desc*gpio_device_get_desc(structgpio_device*gdev,unsignedinthwnum)

get the GPIO descriptor corresponding to the given hardware number for this GPIO device

Parameters

structgpio_device*gdev

GPIO device to get the descriptor from

unsignedinthwnum

hardware number of the GPIO for this chip

Return

A pointer to the GPIO descriptor orEINVAL if no GPIO exists in the givenchip for the specified hardware number orENODEV if the underlying chipalready vanished.

Description

The reference count ofstructgpio_device isNOT increased like when theGPIO is being requested for exclusive usage. It’s up to the caller to makesure the GPIO device will stay alive together with the descriptor returnedby this function.

intdesc_to_gpio(conststructgpio_desc*desc)

convert a GPIO descriptor to the integer namespace

Parameters

conststructgpio_desc*desc

GPIO descriptor

Description

This should disappear in the future but is needed since we stilluse GPIO numbers for error messages and sysfs nodes.

Return

The global GPIO number for the GPIO specified by its descriptor.

intgpiod_hwgpio(conststructgpio_desc*desc)

Return the GPIO number of the passed descriptor relative to its chip.

Parameters

conststructgpio_desc*desc

GPIO descriptor

Return

Hardware offset of the GPIO represented by the descriptor.

structgpio_chip*gpiod_to_chip(conststructgpio_desc*desc)

Return the GPIO chip to which a GPIO descriptor belongs

Parameters

conststructgpio_desc*desc

descriptor to return the chip of

Description

DEPRECATEDThis function is unsafe and should not be used. Using the chip addresswithout taking the SRCU read lock may result in dereferencing a danglingpointer.

Return

Address of the GPIO chip backing this device.

structgpio_device*gpiod_to_gpio_device(structgpio_desc*desc)

Return the GPIO device to which this descriptor belongs.

Parameters

structgpio_desc*desc

Descriptor for which to return the GPIO device.

Description

ThisDOES NOT increase the reference count of the GPIO device as it’sexpected that the descriptor is requested and the users already holds areference to the device.

Return

Address of the GPIO device owning this descriptor.

intgpio_device_get_base(structgpio_device*gdev)

Get the base GPIO number allocated by this device

Parameters

structgpio_device*gdev

GPIO device

Return

First GPIO number in the global GPIO numberspace for this device.

constchar*gpio_device_get_label(structgpio_device*gdev)

Get the label of this GPIO device

Parameters

structgpio_device*gdev

GPIO device

Return

Pointer to the string containing the GPIO device label. The string’slifetime is tied to that of the underlying GPIO device.

structgpio_chip*gpio_device_get_chip(structgpio_device*gdev)

Get the gpio_chip implementation of this GPIO device

Parameters

structgpio_device*gdev

GPIO device

Return

Address of the GPIO chip backing this device.

Description

DEPRECATEDUntil we can get rid of all non-driver users ofstructgpio_chip, we mustprovide a way of retrieving the pointer to it fromstructgpio_device. ThisisNOT safe as the GPIO API is considered to be hot-unpluggable and thechip can dissapear at any moment (unlike reference-countedstructgpio_device).

Use at your own risk.

boolgpiod_is_equal(conststructgpio_desc*desc,conststructgpio_desc*other)

Check if two GPIO descriptors refer to the same pin.

Parameters

conststructgpio_desc*desc

Descriptor to compare.

conststructgpio_desc*other

The second descriptor to compare against.

Return

True if the descriptors refer to the same physical pin. False otherwise.

intgpiod_get_direction(structgpio_desc*desc)

return the current direction of a GPIO

Parameters

structgpio_desc*desc

GPIO to get the direction of

Return

0 for output, 1 for input, or an error code in case of error.

Description

This function may sleep ifgpiod_cansleep() is true.

constunsignedlong*gpiochip_query_valid_mask(conststructgpio_chip*gc)

return the GPIO validity information

Parameters

conststructgpio_chip*gc

gpio chip which validity information is queried

Return

bitmap representing valid GPIOs or NULL if all GPIOs are valid

Description

Some GPIO chips may support configurations where some of the pins aren’tavailable. These chips can have valid_mask set to represent the validGPIOs. This function can be used to retrieve this information.

void*gpiochip_get_data(structgpio_chip*gc)

get per-subdriver data for the chip

Parameters

structgpio_chip*gc

GPIO chip

Return

The per-subdriver data for the chip.

voidgpiochip_remove(structgpio_chip*gc)

unregister a gpio_chip

Parameters

structgpio_chip*gc

the chip to unregister

Description

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

structgpio_device*gpio_device_find(constvoid*data,int(*match)(structgpio_chip*gc,constvoid*data))

find a specific GPIO device

Parameters

constvoid*data

data to pass to match function

int(*match)(structgpio_chip*gc,constvoid*data)

Callback function to check gpio_chip

Return

New reference tostructgpio_device.

Description

Similar tobus_find_device(). It returns a reference to a gpio_device asdetermined by a user suppliedmatch callback. The callback should return0 if the device doesn’t match and non-zero if it does. If the callbackreturns non-zero, this function will return to the caller and not iterateover any more gpio_devices.

The callback takes the GPIO chip structure as argument. During the executionof the callback function the chip is protected from being freed. TODO: Thisactually has yet to be implemented.

If the function returns non-NULL, the returned reference must be freed bythe caller usinggpio_device_put().

structgpio_device*gpio_device_find_by_label(constchar*label)

wrapper aroundgpio_device_find() finding the GPIO device by its backing chip’s label

Parameters

constchar*label

Label to lookup

Return

Reference to the GPIO device or NULL. Reference must be released withgpio_device_put().

structgpio_device*gpio_device_find_by_fwnode(conststructfwnode_handle*fwnode)

wrapper aroundgpio_device_find() finding the GPIO device by its fwnode

Parameters

conststructfwnode_handle*fwnode

Firmware node to lookup

Return

Reference to the GPIO device or NULL. Reference must be released withgpio_device_put().

structgpio_device*gpio_device_get(structgpio_device*gdev)

Increase the reference count of this GPIO device

Parameters

structgpio_device*gdev

GPIO device to increase the refcount for

Return

Pointer togdev.

voidgpio_device_put(structgpio_device*gdev)

Decrease the reference count of this GPIO device and possibly free all resources associated with it.

Parameters

structgpio_device*gdev

GPIO device to decrease the reference count for

structdevice*gpio_device_to_device(structgpio_device*gdev)

Retrieve the address of the underlyingstructdevice.

Parameters

structgpio_device*gdev

GPIO device for which to return the address.

Description

This does not increase the reference count of the GPIO device nor theunderlyingstructdevice.

Return

Address ofstructdevice backing this GPIO device.

intgpiochip_irqchip_add_domain(structgpio_chip*gc,structirq_domain*domain)

adds an irqdomain to a gpiochip

Parameters

structgpio_chip*gc

the gpiochip to add the irqchip to

structirq_domain*domain

the irqdomain to add to the gpiochip

Description

This function adds an IRQ domain to the gpiochip.

Return

0 on success, or negative errno on failure.

intgpiochip_generic_request(structgpio_chip*gc,unsignedintoffset)

request the gpio function for a pin

Parameters

structgpio_chip*gc

the gpiochip owning the GPIO

unsignedintoffset

the offset of the GPIO to request for GPIO function

Return

0 on success, or negative errno on failure.

voidgpiochip_generic_free(structgpio_chip*gc,unsignedintoffset)

free the gpio function from a pin

Parameters

structgpio_chip*gc

the gpiochip to request the gpio function for

unsignedintoffset

the offset of the GPIO to free from GPIO function

intgpiochip_generic_config(structgpio_chip*gc,unsignedintoffset,unsignedlongconfig)

apply configuration for a pin

Parameters

structgpio_chip*gc

the gpiochip owning the GPIO

unsignedintoffset

the offset of the GPIO to apply the configuration

unsignedlongconfig

the configuration to be applied

Return

0 on success, or negative errno on failure.

intgpiochip_add_pingroup_range(structgpio_chip*gc,structpinctrl_dev*pctldev,unsignedintgpio_offset,constchar*pin_group)

add a range for GPIO <-> pin mapping

Parameters

structgpio_chip*gc

the gpiochip to add the range for

structpinctrl_dev*pctldev

the pin controller to map to

unsignedintgpio_offset

the start offset in the current gpio_chip number space

constchar*pin_group

name of the pin group inside the pin controller

Description

Calling this function directly from a DeviceTree-supportedpinctrl driver is DEPRECATED. Please see Section 2.1 ofDocumentation/devicetree/bindings/gpio/gpio.txt on how tobind pinctrl and gpio drivers via the “gpio-ranges” property.

Return

0 on success, or negative errno on failure.

intgpiochip_add_pin_range_with_pins(structgpio_chip*gc,constchar*pinctl_name,unsignedintgpio_offset,unsignedintpin_offset,unsignedintconst*pins,unsignedintnpins)

add a range for GPIO <-> pin mapping

Parameters

structgpio_chip*gc

the gpiochip to add the range for

constchar*pinctl_name

thedev_name() of the pin controller to map to

unsignedintgpio_offset

the start offset in the current gpio_chip number space

unsignedintpin_offset

the start offset in the pin controller number space

unsignedintconst*pins

the list of non consecutive pins to accumulate in this range (if notNULL, pin_offset is ignored by pinctrl core)

unsignedintnpins

the number of pins from the offset of each pin space (GPIO andpin controller) to accumulate in this range

Description

Calling this function directly from a DeviceTree-supportedpinctrl driver is DEPRECATED. Please see Section 2.1 ofDocumentation/devicetree/bindings/gpio/gpio.txt on how tobind pinctrl and gpio drivers via the “gpio-ranges” property.

Return

0 on success, or a negative errno on failure.

voidgpiochip_remove_pin_ranges(structgpio_chip*gc)

remove all the GPIO <-> pin mappings

Parameters

structgpio_chip*gc

the chip to remove all the mappings for

char*gpiochip_dup_line_label(structgpio_chip*gc,unsignedintoffset)

Get a copy of the consumer label.

Parameters

structgpio_chip*gc

GPIO chip controlling this line.

unsignedintoffset

Hardware offset of the line.

Return

Pointer to a copy of the consumer label if the line is requested or NULLif it’s not. If a valid pointer was returned, it must be freed usingkfree(). In case of a memory allocation error, the function returnsENOMEM.

Description

Must not be called from atomic context.

structgpio_desc*gpiochip_request_own_desc(structgpio_chip*gc,unsignedinthwnum,constchar*label,enumgpio_lookup_flagslflags,enumgpiod_flagsdflags)

Allow GPIO chip to request its own descriptor

Parameters

structgpio_chip*gc

GPIO chip

unsignedinthwnum

hardware number of the GPIO for which to request the descriptor

constchar*label

label for the GPIO

enumgpio_lookup_flagslflags

lookup flags for this GPIO or 0 if default, this can be used tospecify things like line inversion semantics with the machine flagssuch as GPIO_OUT_LOW

enumgpiod_flagsdflags

descriptor request flags for this GPIO or 0 if default, thiscan be used to specify consumer semantics such as open drain

Description

Function allows GPIO chip drivers to request and use their own GPIOdescriptors via gpiolib API. Difference togpiod_request() is that thisfunction will not increase reference count of the GPIO chip module. Thisallows the GPIO chip module to be unloaded as needed (we assume that theGPIO chip driver handles freeing the GPIOs it has requested).

Return

A pointer to the GPIO descriptor, or anERR_PTR()-encoded negative errorcode on failure.

voidgpiochip_free_own_desc(structgpio_desc*desc)

Free GPIO requested by the chip driver

Parameters

structgpio_desc*desc

GPIO descriptor to free

Description

Function frees the given GPIO requested previously withgpiochip_request_own_desc().

intgpiod_direction_input(structgpio_desc*desc)

set the GPIO direction to input

Parameters

structgpio_desc*desc

GPIO to set to input

Description

Set the direction of the passed GPIO to input, such asgpiod_get_value() canbe called safely on it.

Return

0 on success, or negative errno on failure.

intgpiod_direction_output_raw(structgpio_desc*desc,intvalue)

set the GPIO direction to output

Parameters

structgpio_desc*desc

GPIO to set to output

intvalue

initial output value of the GPIO

Description

Set the direction of the passed GPIO to output, such asgpiod_set_value() canbe called safely on it. The initial value of the output must be specifiedas raw value on the physical line without regard for the ACTIVE_LOW status.

Return

0 on success, or negative errno on failure.

intgpiod_direction_output(structgpio_desc*desc,intvalue)

set the GPIO direction to output

Parameters

structgpio_desc*desc

GPIO to set to output

intvalue

initial output value of the GPIO

Description

Set the direction of the passed GPIO to output, such asgpiod_set_value() canbe called safely on it. The initial value of the output must be specifiedas the logical value of the GPIO, i.e. taking its ACTIVE_LOW status intoaccount.

Return

0 on success, or negative errno on failure.

intgpiod_enable_hw_timestamp_ns(structgpio_desc*desc,unsignedlongflags)

Enable hardware timestamp in nanoseconds.

Parameters

structgpio_desc*desc

GPIO to enable.

unsignedlongflags

Flags related to GPIO edge.

Return

0 on success, or negative errno on failure.

intgpiod_disable_hw_timestamp_ns(structgpio_desc*desc,unsignedlongflags)

Disable hardware timestamp.

Parameters

structgpio_desc*desc

GPIO to disable.

unsignedlongflags

Flags related to GPIO edge, same value as used during enable call.

Return

0 on success, or negative errno on failure.

intgpiod_set_config(structgpio_desc*desc,unsignedlongconfig)

setsconfig for a GPIO

Parameters

structgpio_desc*desc

descriptor of the GPIO for which to set the configuration

unsignedlongconfig

Same packed config format as generic pinconf

Return

0 on success,-ENOTSUPP if the controller doesn’t support setting theconfiguration.

intgpiod_set_debounce(structgpio_desc*desc,unsignedintdebounce)

setsdebounce time for a GPIO

Parameters

structgpio_desc*desc

descriptor of the GPIO for which to set debounce time

unsignedintdebounce

debounce time in microseconds

Return

0 on success,-ENOTSUPP if the controller doesn’t support setting thedebounce time.

intgpiod_is_active_low(conststructgpio_desc*desc)

test whether a GPIO is active-low or not

Parameters

conststructgpio_desc*desc

the gpio descriptor to test

Return

1 if the GPIO is active-low, 0 otherwise.

voidgpiod_toggle_active_low(structgpio_desc*desc)

toggle whether a GPIO is active-low or not

Parameters

structgpio_desc*desc

the gpio descriptor to change

intgpiod_get_raw_value(conststructgpio_desc*desc)

return a gpio’s raw value

Parameters

conststructgpio_desc*desc

gpio whose value will be returned

Return

The GPIO’s raw value, i.e. the value of the physical line disregardingits ACTIVE_LOW status, or negative errno on failure.

Description

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

intgpiod_get_value(conststructgpio_desc*desc)

return a gpio’s value

Parameters

conststructgpio_desc*desc

gpio whose value will be returned

Return

The GPIO’s logical value, i.e. taking the ACTIVE_LOW status intoaccount, or negative errno on failure.

Description

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

intgpiod_get_raw_array_value(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

read raw values from an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be read

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap to store the read values

Description

Read the raw values of the GPIOs, i.e. the values of the physical lineswithout regard for their ACTIVE_LOW status.

This function can be called from contexts where we cannot sleep,and it will complain if the GPIO chip functions potentially sleep.

Return

0 on success, or negative errno on failure.

intgpiod_get_array_value(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

read values from an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be read

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap to store the read values

Description

Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW statusinto account.

This function can be called from contexts where we cannot sleep,and it will complain if the GPIO chip functions potentially sleep.

Return

0 on success, or negative errno on failure.

intgpiod_set_raw_value(structgpio_desc*desc,intvalue)

assign a gpio’s raw value

Parameters

structgpio_desc*desc

gpio whose value will be assigned

intvalue

value to assign

Description

Set the raw value of the GPIO, i.e. the value of its physical line withoutregard for its ACTIVE_LOW status.

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

Return

0 on success, negative error number on failure.

intgpiod_set_value(structgpio_desc*desc,intvalue)

assign a gpio’s value

Parameters

structgpio_desc*desc

gpio whose value will be assigned

intvalue

value to assign

Description

Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW,OPEN_DRAIN and OPEN_SOURCE flags into account.

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

Return

0 on success, negative error number on failure.

intgpiod_set_raw_array_value(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

assign values to an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be assigned

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap of values to assign

Description

Set the raw values of the GPIOs, i.e. the values of the physical lineswithout regard for their ACTIVE_LOW status.

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

Return

0 on success, or negative errno on failure.

intgpiod_set_array_value(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

assign values to an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be assigned

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap of values to assign

Description

Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW statusinto account.

This function can be called from contexts where we cannot sleep, and willcomplain if the GPIO chip functions potentially sleep.

Return

0 on success, or negative errno on failure.

intgpiod_cansleep(conststructgpio_desc*desc)

report whether gpio value access may sleep

Parameters

conststructgpio_desc*desc

gpio to check

Return

0 for non-sleepable, 1 for sleepable, or an error code in case of error.

intgpiod_set_consumer_name(structgpio_desc*desc,constchar*name)

set the consumer name for the descriptor

Parameters

structgpio_desc*desc

gpio to set the consumer name on

constchar*name

the new consumer name

Return

0 on success, or negative errno on failure.

boolgpiod_is_shared(conststructgpio_desc*desc)

check if this GPIO can be shared by multiple consumers

Parameters

conststructgpio_desc*desc

GPIO to inspect

Return

True if this GPIO can be shared by multiple consumers at once. False if it’sa regular, exclusive GPIO.

Note

This function returning true does not mean that this GPIO is currently beingshared. It means the GPIO core has registered the fact that the firmwareconfiguration indicates that it can be shared by multiple consumers and isin charge of arbitrating the access.

intgpiod_to_irq(conststructgpio_desc*desc)

return the IRQ corresponding to a GPIO

Parameters

conststructgpio_desc*desc

gpio whose IRQ will be returned (already requested)

Return

The IRQ corresponding to the passed GPIO, or an error code in case of error.

intgpiochip_lock_as_irq(structgpio_chip*gc,unsignedintoffset)

lock a GPIO to be used as IRQ

Parameters

structgpio_chip*gc

the chip the GPIO to lock belongs to

unsignedintoffset

the offset of the GPIO to lock as IRQ

Description

This is used directly by GPIO drivers that want to lock downa certain GPIO line to be used for IRQs.

Return

0 on success, or negative errno on failure.

voidgpiochip_unlock_as_irq(structgpio_chip*gc,unsignedintoffset)

unlock a GPIO used as IRQ

Parameters

structgpio_chip*gc

the chip the GPIO to lock belongs to

unsignedintoffset

the offset of the GPIO to lock as IRQ

Description

This is used directly by GPIO drivers that want to indicatethat a certain GPIO is no longer used exclusively for IRQ.

intgpiod_get_raw_value_cansleep(conststructgpio_desc*desc)

return a gpio’s raw value

Parameters

conststructgpio_desc*desc

gpio whose value will be returned

Return

The GPIO’s raw value, i.e. the value of the physical line disregardingits ACTIVE_LOW status, or negative errno on failure.

Description

This function is to be called from contexts that can sleep.

intgpiod_get_value_cansleep(conststructgpio_desc*desc)

return a gpio’s value

Parameters

conststructgpio_desc*desc

gpio whose value will be returned

Return

The GPIO’s logical value, i.e. taking the ACTIVE_LOW status intoaccount, or negative errno on failure.

Description

This function is to be called from contexts that can sleep.

intgpiod_get_raw_array_value_cansleep(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

read raw values from an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be read

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap to store the read values

Description

Read the raw values of the GPIOs, i.e. the values of the physical lineswithout regard for their ACTIVE_LOW status.

This function is to be called from contexts that can sleep.

Return

0 on success, or negative errno on failure.

intgpiod_get_array_value_cansleep(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

read values from an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be read

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap to store the read values

Description

Read the logical values of the GPIOs, i.e. taking their ACTIVE_LOW statusinto account.

This function is to be called from contexts that can sleep.

Return

0 on success, or negative errno on failure.

intgpiod_set_raw_value_cansleep(structgpio_desc*desc,intvalue)

assign a gpio’s raw value

Parameters

structgpio_desc*desc

gpio whose value will be assigned

intvalue

value to assign

Description

Set the raw value of the GPIO, i.e. the value of its physical line withoutregard for its ACTIVE_LOW status.

This function is to be called from contexts that can sleep.

Return

0 on success, negative error number on failure.

intgpiod_set_value_cansleep(structgpio_desc*desc,intvalue)

assign a gpio’s value

Parameters

structgpio_desc*desc

gpio whose value will be assigned

intvalue

value to assign

Description

Set the logical value of the GPIO, i.e. taking its ACTIVE_LOW status intoaccount

This function is to be called from contexts that can sleep.

Return

0 on success, negative error number on failure.

intgpiod_set_raw_array_value_cansleep(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

assign values to an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be assigned

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap of values to assign

Description

Set the raw values of the GPIOs, i.e. the values of the physical lineswithout regard for their ACTIVE_LOW status.

This function is to be called from contexts that can sleep.

Return

0 on success, or negative errno on failure.

intgpiod_set_array_value_cansleep(unsignedintarray_size,structgpio_desc**desc_array,structgpio_array*array_info,unsignedlong*value_bitmap)

assign values to an array of GPIOs

Parameters

unsignedintarray_size

number of elements in the descriptor array / value bitmap

structgpio_desc**desc_array

array of GPIO descriptors whose values will be assigned

structgpio_array*array_info

information on applicability of fast bitmap processing path

unsignedlong*value_bitmap

bitmap of values to assign

Description

Set the logical values of the GPIOs, i.e. taking their ACTIVE_LOW statusinto account.

This function is to be called from contexts that can sleep.

Return

0 on success, or negative errno on failure.

voidgpiod_add_lookup_table(structgpiod_lookup_table*table)

register GPIO device consumers

Parameters

structgpiod_lookup_table*table

table of consumers to register

voidgpiod_remove_lookup_table(structgpiod_lookup_table*table)

unregister GPIO device consumers

Parameters

structgpiod_lookup_table*table

table of consumers to unregister

voidgpiod_add_hogs(structgpiod_hog*hogs)

register a set of GPIO hogs from machine code

Parameters

structgpiod_hog*hogs

table of gpio hog entries with a zeroed sentinel at the end

structgpio_desc*fwnode_gpiod_get_index(structfwnode_handle*fwnode,constchar*con_id,intindex,enumgpiod_flagsflags,constchar*label)

obtain a GPIO from firmware node

Parameters

structfwnode_handle*fwnode

handle of the firmware node

constchar*con_id

function within the GPIO consumer

intindex

index of the GPIO to obtain for the consumer

enumgpiod_flagsflags

GPIO initialization flags

constchar*label

label to attach to the requested GPIO

Description

This function can be used for drivers that get their configurationfrom opaque firmware.

The function properly finds the corresponding GPIO using whatever is theunderlying firmware interface and then makes sure that the GPIOdescriptor is requested before it is returned to the caller.

In case of error anERR_PTR() is returned.

Return

On successful request the GPIO pin is configured in accordance withprovidedflags.

intgpiod_count(structdevice*dev,constchar*con_id)

return the number of GPIOs associated with a device / function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

Return

The number of GPIOs associated with a device / function or -ENOENT if noGPIO has been assigned to the requested function.

structgpio_desc*gpiod_get(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

obtain a GPIO for a given GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev, -ENOENT if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*gpiod_get_optional(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

obtain an optional GPIO for a given GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

This is equivalent togpiod_get(), except that when no GPIO was assigned tothe requested function it will return NULL. This is convenient for driversthat need to handle optional GPIOs.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev, NULL if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*gpiod_get_index(structdevice*dev,constchar*con_id,unsignedintidx,enumgpiod_flagsflags)

obtain a GPIO from a multi-index GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

unsignedintidx

index of the GPIO to obtain in the consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

This variant ofgpiod_get() allows to access GPIOs other than the firstdefined one for functions that define several GPIOs.

Return

A valid GPIO descriptor, -ENOENT if no GPIO has been assigned to therequested function and/or index, or anotherIS_ERR() code if an erroroccurred while trying to acquire the GPIO.

structgpio_desc*gpiod_get_index_optional(structdevice*dev,constchar*con_id,unsignedintindex,enumgpiod_flagsflags)

obtain an optional GPIO from a multi-index GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

unsignedintindex

index of the GPIO to obtain in the consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

This is equivalent togpiod_get_index(), except that when no GPIO with thespecified index was assigned to the requested function it will return NULL.This is convenient for drivers that need to handle optional GPIOs.

Return

A valid GPIO descriptor, NULL if no GPIO has been assigned to therequested function and/or index, or anotherIS_ERR() code if an erroroccurred while trying to acquire the GPIO.

structgpio_descs*gpiod_get_array(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

obtain multiple GPIOs from a multi-index GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

This function acquires all the GPIOs defined under a given function.

Return

The GPIO descriptors corresponding to the functioncon_id of devicedev, -ENOENT if no GPIO has been assigned to the requested function,or anotherIS_ERR() code if an error occurred while trying to acquirethe GPIOs.

structgpio_descs*gpiod_get_array_optional(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

obtain multiple GPIOs from a multi-index GPIO function

Parameters

structdevice*dev

GPIO consumer, can be NULL for system-global GPIOs

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

This is equivalent togpiod_get_array(), except that when no GPIO wasassigned to the requested function it will return NULL.

Return

The GPIO descriptors corresponding to the functioncon_id of devicedev, NULL if no GPIO has been assigned to the requested function,or anotherIS_ERR() code if an error occurred while trying to acquirethe GPIOs.

voidgpiod_put(structgpio_desc*desc)

dispose of a GPIO descriptor

Parameters

structgpio_desc*desc

GPIO descriptor to dispose of

Description

No descriptor can be used aftergpiod_put() has been called on it.

voidgpiod_put_array(structgpio_descs*descs)

dispose of multiple GPIO descriptors

Parameters

structgpio_descs*descs

structgpio_descs containing an array of descriptors

ACPI support

boolacpi_gpio_get_io_resource(structacpi_resource*ares,structacpi_resource_gpio**agpio)

Fetch details of an ACPI resource if it is a GPIO I/O resource or return False if not.

Parameters

structacpi_resource*ares

Pointer to the ACPI resource to fetch

structacpi_resource_gpio**agpio

Pointer to astructacpi_resource_gpio to store the output pointer

Return

true if GpioIo resource is found,false otherwise.

voidacpi_gpiochip_request_interrupts(structgpio_chip*chip)

Register isr for gpio chip ACPI events

Parameters

structgpio_chip*chip

GPIO chip

Description

ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts arehandled by ACPI event methods which need to be called from the GPIOchip’s interrupt handler.acpi_gpiochip_request_interrupts() finds out whichGPIO pins have ACPI event methods and assigns interrupt handlers that callsthe ACPI event methods for those pins.

voidacpi_gpiochip_free_interrupts(structgpio_chip*chip)

Free GPIO ACPI event interrupts.

Parameters

structgpio_chip*chip

GPIO chip

Description

Free interrupts associated with GPIO ACPI event method for the givenGPIO chip.

intacpi_dev_gpio_irq_wake_get_by(structacpi_device*adev,constchar*con_id,intindex,bool*wake_capable)

Find GpioInt and translate it to Linux IRQ number

Parameters

structacpi_device*adev

pointer to a ACPI device to get IRQ from

constchar*con_id

optional name of GpioInt resource

intindex

index of GpioInt resource (starting from0)

bool*wake_capable

Set to true if the IRQ is wake capable

Description

If the device has one or more GpioInt resources, this function can beused to translate from the GPIO offset in the resource to the Linux IRQnumber.

The function is idempotent, though each time it runs it will configure GPIOpin direction according to the flags in GpioInt resource.

The function takes optionalcon_id parameter. If the resource hasacon_id in a property, then only those will be taken into account.

The GPIO is considered wake capable if the GpioInt resource specifiesSharedAndWake or ExclusiveAndWake.

Return

Linux IRQ number (> 0) on success, negative errno on failure.

Device tree support

intof_get_named_gpio(conststructdevice_node*np,constchar*propname,intindex)

Get a GPIO number to use with GPIO API

Parameters

conststructdevice_node*np

device node to get GPIO from

constchar*propname

Name of property containing gpio specifier(s)

intindex

index of the GPIO

Description

DEPRECATED This function is deprecated and must not be used in new code.

Return

GPIO number to use with Linux generic GPIO API, or one of the errnovalue on the error condition.

Device-managed API

structgpio_desc*devm_gpiod_get(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

Resource-managedgpiod_get()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get(). GPIO descriptors returned from this function areautomatically disposed on driver detach. Seegpiod_get() for detailedinformation about behavior and return values.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev,-ENOENT if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*devm_gpiod_get_optional(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

Resource-managedgpiod_get_optional()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get_optional(). GPIO descriptors returned from this functionare automatically disposed on driver detach. Seegpiod_get_optional() fordetailed information about behavior and return values.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev, NULL if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*devm_gpiod_get_index(structdevice*dev,constchar*con_id,unsignedintidx,enumgpiod_flagsflags)

Resource-managedgpiod_get_index()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

unsignedintidx

index of the GPIO to obtain in the consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get_index(). GPIO descriptors returned from this function areautomatically disposed on driver detach. Seegpiod_get_index() for detailedinformation about behavior and return values.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev,-ENOENT if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*devm_fwnode_gpiod_get_index(structdevice*dev,structfwnode_handle*fwnode,constchar*con_id,intindex,enumgpiod_flagsflags,constchar*label)

get a GPIO descriptor from a given node

Parameters

structdevice*dev

GPIO consumer

structfwnode_handle*fwnode

firmware node containing GPIO reference

constchar*con_id

function within the GPIO consumer

intindex

index of the GPIO to obtain in the consumer

enumgpiod_flagsflags

GPIO initialization flags

constchar*label

label to attach to the requested GPIO

Description

GPIO descriptors returned from this function are automatically disposed ondriver detach.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev,-ENOENT if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_desc*devm_gpiod_get_index_optional(structdevice*dev,constchar*con_id,unsignedintindex,enumgpiod_flagsflags)

Resource-managedgpiod_get_index_optional()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

unsignedintindex

index of the GPIO to obtain in the consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get_index_optional(). GPIO descriptors returned from thisfunction are automatically disposed on driver detach. Seegpiod_get_index_optional() for detailed information about behavior andreturn values.

Return

The GPIO descriptor corresponding to the functioncon_id of devicedev,NULL if no GPIO has been assigned to the requested function, oranotherIS_ERR() code if an error occurred while trying to acquire the GPIO.

structgpio_descs*devm_gpiod_get_array(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

Resource-managedgpiod_get_array()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get_array(). GPIO descriptors returned from this function areautomatically disposed on driver detach. Seegpiod_get_array() for detailedinformation about behavior and return values.

Return

The GPIO descriptors corresponding to the functioncon_id of devicedev,-ENOENT if no GPIO has been assigned to the requested function,or anotherIS_ERR() code if an error occurred while trying to acquirethe GPIOs.

structgpio_descs*devm_gpiod_get_array_optional(structdevice*dev,constchar*con_id,enumgpiod_flagsflags)

Resource-managedgpiod_get_array_optional()

Parameters

structdevice*dev

GPIO consumer

constchar*con_id

function within the GPIO consumer

enumgpiod_flagsflags

optional GPIO initialization flags

Description

Managedgpiod_get_array_optional(). GPIO descriptors returned from thisfunction are automatically disposed on driver detach.Seegpiod_get_array_optional() for detailed information about behavior andreturn values.

Return

The GPIO descriptors corresponding to the functioncon_id of devicedev,NULL if no GPIO has been assigned to the requested function,or anotherIS_ERR() code if an error occurred while trying to acquirethe GPIOs.

voiddevm_gpiod_put(structdevice*dev,structgpio_desc*desc)

Resource-managedgpiod_put()

Parameters

structdevice*dev

GPIO consumer

structgpio_desc*desc

GPIO descriptor to dispose of

Description

Dispose of a GPIO descriptor obtained withdevm_gpiod_get() ordevm_gpiod_get_index(). Normally this function will not be called as the GPIOwill be disposed of by the resource management code.

voiddevm_gpiod_unhinge(structdevice*dev,structgpio_desc*desc)

Remove resource management from a gpio descriptor

Parameters

structdevice*dev

GPIO consumer

structgpio_desc*desc

GPIO descriptor to remove resource management from

Description

DEPRECATEDThis function should not be used. It’s been provided as a workaround forresource ownership issues in the regulator framework and should be replacedwith a better solution.

Remove resource management from a GPIO descriptor. This is needed whenyou want to hand over lifecycle management of a descriptor to anothermechanism.

voiddevm_gpiod_put_array(structdevice*dev,structgpio_descs*descs)

Resource-managedgpiod_put_array()

Parameters

structdevice*dev

GPIO consumer

structgpio_descs*descs

GPIO descriptor array to dispose of

Description

Dispose of an array of GPIO descriptors obtained withdevm_gpiod_get_array().Normally this function will not be called as the GPIOs will be disposed ofby the resource management code.

intdevm_gpiochip_add_data_with_key(structdevice*dev,structgpio_chip*gc,void*data,structlock_class_key*lock_key,structlock_class_key*request_key)

Resource managedgpiochip_add_data_with_key()

Parameters

structdevice*dev

pointer to the device that gpio_chip belongs to.

structgpio_chip*gc

the GPIO chip to register

void*data

driver-private data associated with this chip

structlock_class_key*lock_key

lockdep class for IRQ lock

structlock_class_key*request_key

lockdep class for IRQ request

Context

potentially before irqs will work

Description

The gpio chip automatically be released when the device is unbound.

Return

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

sysfs helpers

intgpiod_export(structgpio_desc*desc,booldirection_may_change)

export a GPIO through sysfs

Parameters

structgpio_desc*desc

GPIO to make available, already requested

booldirection_may_change

true if userspace may change GPIO direction

Context

arch_initcall or later

Description

When drivers want to make a GPIO accessible to userspace after theyhave requested it -- perhaps while debugging, or as part of theirpublic interface -- they may use this routine. If the GPIO canchange direction (some can’t) and the caller allows it, userspacewill see “direction” sysfs attribute which may be used to changethe gpio’s direction. A “value” attribute will always be provided.

Return

0 on success, or negative errno on failure.

intgpiod_export_link(structdevice*dev,constchar*name,structgpio_desc*desc)

create a sysfs link to an exported GPIO node

Parameters

structdevice*dev

device under which to create symlink

constchar*name

name of the symlink

structgpio_desc*desc

GPIO to create symlink to, already exported

Description

Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioNnode. Caller is responsible for unlinking.

Return

0 on success, or negative errno on failure.

voidgpiod_unexport(structgpio_desc*desc)

reverse effect ofgpiod_export()

Parameters

structgpio_desc*desc

GPIO to make unavailable

Description

This is implicit ongpiod_free().