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
chipGPIO IRQ chip implementation, provided by GPIO driver.
domainInterrupt translation domain; responsible for mapping between GPIOhwirq number and Linux IRQ number.
fwnodeFirmware node corresponding to this gpiochip/irqchip, necessaryfor hierarchical irqdomain support.
parent_domainIf 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_hwirqThis 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 of
structgpio_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_argThis optional callback allocates and populates the specific structfor the parent’s IRQ domain. If this is not specified, then
gpiochip_populate_parent_fwspec_twocellwill be used. A four-cellvariant namedgpiochip_populate_parent_fwspec_fourcellis alsoavailable.child_offset_to_irqThis optional callback is used to translate the child’s GPIO lineoffset on the GPIO chip to an IRQ number for the GPIO
to_irq()callback. If this is not specified, then a default callback will beprovided that returns the line offset.child_irq_domain_opsThe 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.
handlerThe IRQ handler to use (often a predefined IRQ core function) forGPIO IRQs, provided by GPIO driver.
default_typeDefault IRQ triggering type applied during GPIO driverinitialization, provided by GPIO driver.
lock_keyPer GPIO IRQ chip lockdep class for IRQ lock.
request_keyPer GPIO IRQ chip lockdep class for IRQ request.
parent_handlerThe 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_dataIfper_parent_data is false,parent_handler_data is asingle pointer used as the data associated with everyparent interrupt.
parent_handler_data_arrayIfper_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_parentsThe number of interrupt parents of a GPIO chip.
parentsA list of interrupt parents of a GPIO chip. This is owned by thedriver, so the core will only reference this list, not modify it.
mapA list of interrupt parents for each line of a GPIO chip.
threadedTrue if set the interrupt handling uses nested threads.
per_parent_dataTrue if parent_handler_data_array describes anum_parentssized array to be used as parent data.
initializedFlag 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_externallyTrue it the irq_domain was allocated outside of gpiolib, in whichcase gpiolib won’t free the irq_domain itself.
init_hwoptional 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_maskoptional 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_maskIf not
NULL, holds bitmask of GPIOs which are valid to be includedin IRQ domain of the chip.firstRequired for static IRQ allocation. If set,
irq_domain_create_simple()will allocate and map all IRQsduring initialization.irq_enableStore old irq_chip irq_enable callback
irq_disableStore old irq_chip irq_disable callback
irq_unmaskStore old irq_chip irq_unmask callback
irq_maskStore 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
labela functional name for the GPIO device, such as a partnumber or the name of the SoC IP-block implementing it.
gpiodevthe internal state holder, opaque struct
parentoptional parent device providing the GPIOs
fwnodeoptional fwnode providing this controller’s properties
ownerhelps prevent removal of modules exporting active GPIOs
requestoptional hook for chip-specific activation, such asenabling module power and clock; may sleep; must return 0 on successor negative error number on failure
freeoptional hook for chip-specific deactivation, such asdisabling module power and clock; may sleep
get_directionreturns 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_inputconfigures signal “offset” as input, returns 0 on successor a negative error number. This can be omitted on input-only oroutput-only gpio chips.
direction_outputconfigures signal “offset” as output, returns 0 onsuccess or a negative error number. This can be omitted on input-onlyor output-only gpio chips.
getreturns value for signal “offset”, 0=low, 1=high, or negative error
get_multiplereads values for multiple signals defined by “mask” andstores them in “bits”, returns 0 on success or negative error
setassigns output value for signal “offset”, returns 0 on success ornegative error value
set_multipleassigns output values for multiple signals defined by“mask”, returns 0 on success or negative error value
set_configoptional 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_irqoptional hook supporting non-static
gpiod_to_irq()mappings;implementation may not sleepdbg_showoptional 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_maskoptional routine to initializevalid_mask, to be used ifnot all GPIOs are valid.
add_pin_rangesoptional 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_timestampDependent on GPIO chip, an optional routine toenable hardware timestamp.
dis_hw_timestampDependent on GPIO chip, an optional routine todisable hardware timestamp.
baseidentifies 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.
ngpiothe number of GPIOs handled by this controller; the last GPIOhandled is (base + ngpio - 1).
offsetwhen multiple gpio chips belong to the same device thiscan be used as offset within the device so friendly names canbe properly assigned.
namesif 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_sleepflag must be set iff
get()/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.irqIntegrates interrupt chip functionality with the GPIO chip. Can beused to handle IRQs for most practical cases.
of_gpio_n_cellsNumber of cells used to form the GPIO specifier. The standard is 2cells:
gpios = <
gpiooffset flags>;some complex GPIO controllers instantiate more than one chip perdevice tree node and have 3 cells:
gpios = <
gpioinstance offset flags>;Legacy GPIO controllers may even have 1 cell:
gpios = <
gpiooffset>;of_node_instance_matchDetermine 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_xlateCallback 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
_chipChip to iterate over.
_iLoop counter.
_baseFirst GPIO in the ranger.
_sizeAmount of GPIOs to check starting frombase.
_labelPlace 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
_chipChip to iterate over.
_iLoop counter.
_labelPlace 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
_chipthe chip to query
_iloop variable
_basefirst GPIO in the range
_sizeamount of GPIOs to check starting frombase
_labellabel of current GPIO
- gpiochip_add_data¶
gpiochip_add_data(gc,data)
register a gpio_chip
Parameters
gcthe chip to register, with gc->base initialized
datadriver-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
nodelist for maintaining set of pin ranges, used internally
pctldevpinctrl device which handles corresponding pins
rangeactual range of pins controlled by a gpio controller
- structgpio_desc*gpio_to_desc(unsignedgpio)¶
Convert a GPIO number to its descriptor
Parameters
unsignedgpioglobal 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*gdevGPIO device to get the descriptor from
unsignedinthwnumhardware 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*descGPIO 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*descGPIO 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*descdescriptor 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*descDescriptor 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*gdevGPIO 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*gdevGPIO 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*gdevGPIO 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*descDescriptor to compare.
conststructgpio_desc*otherThe 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*descGPIO 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*gcgpio 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.
Parameters
structgpio_chip*gcGPIO chip
Return
The per-subdriver data for the chip.
Parameters
structgpio_chip*gcthe 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*datadata 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 around
gpio_device_find()finding the GPIO device by its backing chip’s label
Parameters
constchar*labelLabel 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 around
gpio_device_find()finding the GPIO device by its fwnode
Parameters
conststructfwnode_handle*fwnodeFirmware 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*gdevGPIO 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*gdevGPIO device to decrease the reference count for
- structdevice*gpio_device_to_device(structgpio_device*gdev)¶
Retrieve the address of the underlying
structdevice.
Parameters
structgpio_device*gdevGPIO 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*gcthe gpiochip to add the irqchip to
structirq_domain*domainthe 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*gcthe gpiochip owning the GPIO
unsignedintoffsetthe offset of the GPIO to request for GPIO function
Return
0 on success, or negative errno on failure.
Parameters
structgpio_chip*gcthe gpiochip to request the gpio function for
unsignedintoffsetthe 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*gcthe gpiochip owning the GPIO
unsignedintoffsetthe offset of the GPIO to apply the configuration
unsignedlongconfigthe 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*gcthe gpiochip to add the range for
structpinctrl_dev*pctldevthe pin controller to map to
unsignedintgpio_offsetthe start offset in the current gpio_chip number space
constchar*pin_groupname 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*gcthe gpiochip to add the range for
constchar*pinctl_namethe
dev_name()of the pin controller to map tounsignedintgpio_offsetthe start offset in the current gpio_chip number space
unsignedintpin_offsetthe start offset in the pin controller number space
unsignedintconst*pinsthe list of non consecutive pins to accumulate in this range (if notNULL, pin_offset is ignored by pinctrl core)
unsignedintnpinsthe 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.
Parameters
structgpio_chip*gcthe 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*gcGPIO chip controlling this line.
unsignedintoffsetHardware 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*gcGPIO chip
unsignedinthwnumhardware number of the GPIO for which to request the descriptor
constchar*labellabel for the GPIO
enumgpio_lookup_flagslflagslookup 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_flagsdflagsdescriptor 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*descGPIO 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*descGPIO 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*descGPIO to set to output
intvalueinitial 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*descGPIO to set to output
intvalueinitial 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*descGPIO to enable.
unsignedlongflagsFlags 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*descGPIO to disable.
unsignedlongflagsFlags 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*descdescriptor of the GPIO for which to set the configuration
unsignedlongconfigSame 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*descdescriptor of the GPIO for which to set debounce time
unsignedintdebouncedebounce 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*descthe 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*descthe gpio descriptor to change
- intgpiod_get_raw_value(conststructgpio_desc*desc)¶
return a gpio’s raw value
Parameters
conststructgpio_desc*descgpio 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*descgpio 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be read
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be read
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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*descgpio whose value will be assigned
intvaluevalue 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*descgpio whose value will be assigned
intvaluevalue 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be assigned
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be assigned
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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*descgpio 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*descgpio to set the consumer name on
constchar*namethe 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*descGPIO 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*descgpio whose IRQ will be returned (already requested)
Return
The IRQ corresponding to the passed GPIO, or an error code in case of error.
Parameters
structgpio_chip*gcthe chip the GPIO to lock belongs to
unsignedintoffsetthe 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.
Parameters
structgpio_chip*gcthe chip the GPIO to lock belongs to
unsignedintoffsetthe 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*descgpio 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*descgpio 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be read
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be read
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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*descgpio whose value will be assigned
intvaluevalue 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*descgpio whose value will be assigned
intvaluevalue 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be assigned
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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_sizenumber of elements in the descriptor array / value bitmap
structgpio_desc**desc_arrayarray of GPIO descriptors whose values will be assigned
structgpio_array*array_infoinformation on applicability of fast bitmap processing path
unsignedlong*value_bitmapbitmap 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*tabletable of consumers to register
- voidgpiod_remove_lookup_table(structgpiod_lookup_table*table)¶
unregister GPIO device consumers
Parameters
structgpiod_lookup_table*tabletable of consumers to unregister
- voidgpiod_add_hogs(structgpiod_hog*hogs)¶
register a set of GPIO hogs from machine code
Parameters
structgpiod_hog*hogstable 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*fwnodehandle of the firmware node
constchar*con_idfunction within the GPIO consumer
intindexindex of the GPIO to obtain for the consumer
enumgpiod_flagsflagsGPIO initialization flags
constchar*labellabel 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
unsignedintidxindex of the GPIO to obtain in the consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
unsignedintindexindex of the GPIO to obtain in the consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer, can be NULL for system-global GPIOs
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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*descGPIO 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*descsstructgpio_descscontaining 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*aresPointer to the ACPI resource to fetch
structacpi_resource_gpio**agpioPointer to a
structacpi_resource_gpioto store the output pointer
Return
true if GpioIo resource is found,false otherwise.
Parameters
structgpio_chip*chipGPIO 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.
Parameters
structgpio_chip*chipGPIO 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*adevpointer to a ACPI device to get IRQ from
constchar*con_idoptional name of GpioInt resource
intindexindex of GpioInt resource (starting from
0)bool*wake_capableSet 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*npdevice node to get GPIO from
constchar*propnameName of property containing gpio specifier(s)
intindexindex 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-managed
gpiod_get()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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-managed
gpiod_get_optional()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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-managed
gpiod_get_index()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
unsignedintidxindex of the GPIO to obtain in the consumer
enumgpiod_flagsflagsoptional 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*devGPIO consumer
structfwnode_handle*fwnodefirmware node containing GPIO reference
constchar*con_idfunction within the GPIO consumer
intindexindex of the GPIO to obtain in the consumer
enumgpiod_flagsflagsGPIO initialization flags
constchar*labellabel 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-managed
gpiod_get_index_optional()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
unsignedintindexindex of the GPIO to obtain in the consumer
enumgpiod_flagsflagsoptional 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-managed
gpiod_get_array()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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-managed
gpiod_get_array_optional()
Parameters
structdevice*devGPIO consumer
constchar*con_idfunction within the GPIO consumer
enumgpiod_flagsflagsoptional 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-managed
gpiod_put()
Parameters
structdevice*devGPIO consumer
structgpio_desc*descGPIO 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*devGPIO consumer
structgpio_desc*descGPIO 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-managed
gpiod_put_array()
Parameters
structdevice*devGPIO consumer
structgpio_descs*descsGPIO 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 managed
gpiochip_add_data_with_key()
Parameters
structdevice*devpointer to the device that gpio_chip belongs to.
structgpio_chip*gcthe GPIO chip to register
void*datadriver-private data associated with this chip
structlock_class_key*lock_keylockdep class for IRQ lock
structlock_class_key*request_keylockdep 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*descGPIO to make available, already requested
booldirection_may_changetrue 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*devdevice under which to create symlink
constchar*namename of the symlink
structgpio_desc*descGPIO 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 of
gpiod_export()
Parameters
structgpio_desc*descGPIO to make unavailable
Description
This is implicit ongpiod_free().