cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

consumer.h (21401B)


      1/* SPDX-License-Identifier: GPL-2.0 */
      2#ifndef __LINUX_GPIO_CONSUMER_H
      3#define __LINUX_GPIO_CONSUMER_H
      4
      5#include <linux/bits.h>
      6#include <linux/bug.h>
      7#include <linux/compiler_types.h>
      8#include <linux/err.h>
      9
     10struct device;
     11struct gpio_desc;
     12struct gpio_array;
     13
     14/**
     15 * struct gpio_descs - Struct containing an array of descriptors that can be
     16 *                     obtained using gpiod_get_array()
     17 *
     18 * @info:	Pointer to the opaque gpio_array structure
     19 * @ndescs:	Number of held descriptors
     20 * @desc:	Array of pointers to GPIO descriptors
     21 */
     22struct gpio_descs {
     23	struct gpio_array *info;
     24	unsigned int ndescs;
     25	struct gpio_desc *desc[];
     26};
     27
     28#define GPIOD_FLAGS_BIT_DIR_SET		BIT(0)
     29#define GPIOD_FLAGS_BIT_DIR_OUT		BIT(1)
     30#define GPIOD_FLAGS_BIT_DIR_VAL		BIT(2)
     31#define GPIOD_FLAGS_BIT_OPEN_DRAIN	BIT(3)
     32#define GPIOD_FLAGS_BIT_NONEXCLUSIVE	BIT(4)
     33
     34/**
     35 * enum gpiod_flags - Optional flags that can be passed to one of gpiod_* to
     36 *                    configure direction and output value. These values
     37 *                    cannot be OR'd.
     38 *
     39 * @GPIOD_ASIS:			Don't change anything
     40 * @GPIOD_IN:			Set lines to input mode
     41 * @GPIOD_OUT_LOW:		Set lines to output and drive them low
     42 * @GPIOD_OUT_HIGH:		Set lines to output and drive them high
     43 * @GPIOD_OUT_LOW_OPEN_DRAIN:	Set lines to open-drain output and drive them low
     44 * @GPIOD_OUT_HIGH_OPEN_DRAIN:	Set lines to open-drain output and drive them high
     45 */
     46enum gpiod_flags {
     47	GPIOD_ASIS	= 0,
     48	GPIOD_IN	= GPIOD_FLAGS_BIT_DIR_SET,
     49	GPIOD_OUT_LOW	= GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT,
     50	GPIOD_OUT_HIGH	= GPIOD_FLAGS_BIT_DIR_SET | GPIOD_FLAGS_BIT_DIR_OUT |
     51			  GPIOD_FLAGS_BIT_DIR_VAL,
     52	GPIOD_OUT_LOW_OPEN_DRAIN = GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_OPEN_DRAIN,
     53	GPIOD_OUT_HIGH_OPEN_DRAIN = GPIOD_OUT_HIGH | GPIOD_FLAGS_BIT_OPEN_DRAIN,
     54};
     55
     56#ifdef CONFIG_GPIOLIB
     57
     58/* Return the number of GPIOs associated with a device / function */
     59int gpiod_count(struct device *dev, const char *con_id);
     60
     61/* Acquire and dispose GPIOs */
     62struct gpio_desc *__must_check gpiod_get(struct device *dev,
     63					 const char *con_id,
     64					 enum gpiod_flags flags);
     65struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
     66					       const char *con_id,
     67					       unsigned int idx,
     68					       enum gpiod_flags flags);
     69struct gpio_desc *__must_check gpiod_get_optional(struct device *dev,
     70						  const char *con_id,
     71						  enum gpiod_flags flags);
     72struct gpio_desc *__must_check gpiod_get_index_optional(struct device *dev,
     73							const char *con_id,
     74							unsigned int index,
     75							enum gpiod_flags flags);
     76struct gpio_descs *__must_check gpiod_get_array(struct device *dev,
     77						const char *con_id,
     78						enum gpiod_flags flags);
     79struct gpio_descs *__must_check gpiod_get_array_optional(struct device *dev,
     80							const char *con_id,
     81							enum gpiod_flags flags);
     82void gpiod_put(struct gpio_desc *desc);
     83void gpiod_put_array(struct gpio_descs *descs);
     84
     85struct gpio_desc *__must_check devm_gpiod_get(struct device *dev,
     86					      const char *con_id,
     87					      enum gpiod_flags flags);
     88struct gpio_desc *__must_check devm_gpiod_get_index(struct device *dev,
     89						    const char *con_id,
     90						    unsigned int idx,
     91						    enum gpiod_flags flags);
     92struct gpio_desc *__must_check devm_gpiod_get_optional(struct device *dev,
     93						       const char *con_id,
     94						       enum gpiod_flags flags);
     95struct gpio_desc *__must_check
     96devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
     97			      unsigned int index, enum gpiod_flags flags);
     98struct gpio_descs *__must_check devm_gpiod_get_array(struct device *dev,
     99						     const char *con_id,
    100						     enum gpiod_flags flags);
    101struct gpio_descs *__must_check
    102devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
    103			      enum gpiod_flags flags);
    104void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
    105void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
    106void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
    107
    108int gpiod_get_direction(struct gpio_desc *desc);
    109int gpiod_direction_input(struct gpio_desc *desc);
    110int gpiod_direction_output(struct gpio_desc *desc, int value);
    111int gpiod_direction_output_raw(struct gpio_desc *desc, int value);
    112int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
    113int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc, unsigned long flags);
    114
    115/* Value get/set from non-sleeping context */
    116int gpiod_get_value(const struct gpio_desc *desc);
    117int gpiod_get_array_value(unsigned int array_size,
    118			  struct gpio_desc **desc_array,
    119			  struct gpio_array *array_info,
    120			  unsigned long *value_bitmap);
    121void gpiod_set_value(struct gpio_desc *desc, int value);
    122int gpiod_set_array_value(unsigned int array_size,
    123			  struct gpio_desc **desc_array,
    124			  struct gpio_array *array_info,
    125			  unsigned long *value_bitmap);
    126int gpiod_get_raw_value(const struct gpio_desc *desc);
    127int gpiod_get_raw_array_value(unsigned int array_size,
    128			      struct gpio_desc **desc_array,
    129			      struct gpio_array *array_info,
    130			      unsigned long *value_bitmap);
    131void gpiod_set_raw_value(struct gpio_desc *desc, int value);
    132int gpiod_set_raw_array_value(unsigned int array_size,
    133			      struct gpio_desc **desc_array,
    134			      struct gpio_array *array_info,
    135			      unsigned long *value_bitmap);
    136
    137/* Value get/set from sleeping context */
    138int gpiod_get_value_cansleep(const struct gpio_desc *desc);
    139int gpiod_get_array_value_cansleep(unsigned int array_size,
    140				   struct gpio_desc **desc_array,
    141				   struct gpio_array *array_info,
    142				   unsigned long *value_bitmap);
    143void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
    144int gpiod_set_array_value_cansleep(unsigned int array_size,
    145				   struct gpio_desc **desc_array,
    146				   struct gpio_array *array_info,
    147				   unsigned long *value_bitmap);
    148int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
    149int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
    150				       struct gpio_desc **desc_array,
    151				       struct gpio_array *array_info,
    152				       unsigned long *value_bitmap);
    153void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
    154int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
    155				       struct gpio_desc **desc_array,
    156				       struct gpio_array *array_info,
    157				       unsigned long *value_bitmap);
    158
    159int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
    160int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce);
    161int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
    162void gpiod_toggle_active_low(struct gpio_desc *desc);
    163
    164int gpiod_is_active_low(const struct gpio_desc *desc);
    165int gpiod_cansleep(const struct gpio_desc *desc);
    166
    167int gpiod_to_irq(const struct gpio_desc *desc);
    168int gpiod_set_consumer_name(struct gpio_desc *desc, const char *name);
    169
    170/* Convert between the old gpio_ and new gpiod_ interfaces */
    171struct gpio_desc *gpio_to_desc(unsigned gpio);
    172int desc_to_gpio(const struct gpio_desc *desc);
    173
    174/* Child properties interface */
    175struct fwnode_handle;
    176
    177struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
    178					 const char *propname, int index,
    179					 enum gpiod_flags dflags,
    180					 const char *label);
    181struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
    182					 const char *con_id, int index,
    183					 enum gpiod_flags flags,
    184					 const char *label);
    185struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
    186					      struct fwnode_handle *child,
    187					      const char *con_id, int index,
    188					      enum gpiod_flags flags,
    189					      const char *label);
    190
    191#else /* CONFIG_GPIOLIB */
    192
    193#include <linux/kernel.h>
    194
    195static inline int gpiod_count(struct device *dev, const char *con_id)
    196{
    197	return 0;
    198}
    199
    200static inline struct gpio_desc *__must_check gpiod_get(struct device *dev,
    201						       const char *con_id,
    202						       enum gpiod_flags flags)
    203{
    204	return ERR_PTR(-ENOSYS);
    205}
    206static inline struct gpio_desc *__must_check
    207gpiod_get_index(struct device *dev,
    208		const char *con_id,
    209		unsigned int idx,
    210		enum gpiod_flags flags)
    211{
    212	return ERR_PTR(-ENOSYS);
    213}
    214
    215static inline struct gpio_desc *__must_check
    216gpiod_get_optional(struct device *dev, const char *con_id,
    217		   enum gpiod_flags flags)
    218{
    219	return NULL;
    220}
    221
    222static inline struct gpio_desc *__must_check
    223gpiod_get_index_optional(struct device *dev, const char *con_id,
    224			 unsigned int index, enum gpiod_flags flags)
    225{
    226	return NULL;
    227}
    228
    229static inline struct gpio_descs *__must_check
    230gpiod_get_array(struct device *dev, const char *con_id,
    231		enum gpiod_flags flags)
    232{
    233	return ERR_PTR(-ENOSYS);
    234}
    235
    236static inline struct gpio_descs *__must_check
    237gpiod_get_array_optional(struct device *dev, const char *con_id,
    238			 enum gpiod_flags flags)
    239{
    240	return NULL;
    241}
    242
    243static inline void gpiod_put(struct gpio_desc *desc)
    244{
    245	might_sleep();
    246
    247	/* GPIO can never have been requested */
    248	WARN_ON(desc);
    249}
    250
    251static inline void devm_gpiod_unhinge(struct device *dev,
    252				      struct gpio_desc *desc)
    253{
    254	might_sleep();
    255
    256	/* GPIO can never have been requested */
    257	WARN_ON(desc);
    258}
    259
    260static inline void gpiod_put_array(struct gpio_descs *descs)
    261{
    262	might_sleep();
    263
    264	/* GPIO can never have been requested */
    265	WARN_ON(descs);
    266}
    267
    268static inline struct gpio_desc *__must_check
    269devm_gpiod_get(struct device *dev,
    270		 const char *con_id,
    271		 enum gpiod_flags flags)
    272{
    273	return ERR_PTR(-ENOSYS);
    274}
    275static inline
    276struct gpio_desc *__must_check
    277devm_gpiod_get_index(struct device *dev,
    278		       const char *con_id,
    279		       unsigned int idx,
    280		       enum gpiod_flags flags)
    281{
    282	return ERR_PTR(-ENOSYS);
    283}
    284
    285static inline struct gpio_desc *__must_check
    286devm_gpiod_get_optional(struct device *dev, const char *con_id,
    287			  enum gpiod_flags flags)
    288{
    289	return NULL;
    290}
    291
    292static inline struct gpio_desc *__must_check
    293devm_gpiod_get_index_optional(struct device *dev, const char *con_id,
    294				unsigned int index, enum gpiod_flags flags)
    295{
    296	return NULL;
    297}
    298
    299static inline struct gpio_descs *__must_check
    300devm_gpiod_get_array(struct device *dev, const char *con_id,
    301		     enum gpiod_flags flags)
    302{
    303	return ERR_PTR(-ENOSYS);
    304}
    305
    306static inline struct gpio_descs *__must_check
    307devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
    308			      enum gpiod_flags flags)
    309{
    310	return NULL;
    311}
    312
    313static inline void devm_gpiod_put(struct device *dev, struct gpio_desc *desc)
    314{
    315	might_sleep();
    316
    317	/* GPIO can never have been requested */
    318	WARN_ON(desc);
    319}
    320
    321static inline void devm_gpiod_put_array(struct device *dev,
    322					struct gpio_descs *descs)
    323{
    324	might_sleep();
    325
    326	/* GPIO can never have been requested */
    327	WARN_ON(descs);
    328}
    329
    330
    331static inline int gpiod_get_direction(const struct gpio_desc *desc)
    332{
    333	/* GPIO can never have been requested */
    334	WARN_ON(desc);
    335	return -ENOSYS;
    336}
    337static inline int gpiod_direction_input(struct gpio_desc *desc)
    338{
    339	/* GPIO can never have been requested */
    340	WARN_ON(desc);
    341	return -ENOSYS;
    342}
    343static inline int gpiod_direction_output(struct gpio_desc *desc, int value)
    344{
    345	/* GPIO can never have been requested */
    346	WARN_ON(desc);
    347	return -ENOSYS;
    348}
    349static inline int gpiod_direction_output_raw(struct gpio_desc *desc, int value)
    350{
    351	/* GPIO can never have been requested */
    352	WARN_ON(desc);
    353	return -ENOSYS;
    354}
    355static inline int gpiod_enable_hw_timestamp_ns(struct gpio_desc *desc,
    356					       unsigned long flags)
    357{
    358	WARN_ON(desc);
    359	return -ENOSYS;
    360}
    361static inline int gpiod_disable_hw_timestamp_ns(struct gpio_desc *desc,
    362						unsigned long flags)
    363{
    364	WARN_ON(desc);
    365	return -ENOSYS;
    366}
    367static inline int gpiod_get_value(const struct gpio_desc *desc)
    368{
    369	/* GPIO can never have been requested */
    370	WARN_ON(desc);
    371	return 0;
    372}
    373static inline int gpiod_get_array_value(unsigned int array_size,
    374					struct gpio_desc **desc_array,
    375					struct gpio_array *array_info,
    376					unsigned long *value_bitmap)
    377{
    378	/* GPIO can never have been requested */
    379	WARN_ON(desc_array);
    380	return 0;
    381}
    382static inline void gpiod_set_value(struct gpio_desc *desc, int value)
    383{
    384	/* GPIO can never have been requested */
    385	WARN_ON(desc);
    386}
    387static inline int gpiod_set_array_value(unsigned int array_size,
    388					struct gpio_desc **desc_array,
    389					struct gpio_array *array_info,
    390					unsigned long *value_bitmap)
    391{
    392	/* GPIO can never have been requested */
    393	WARN_ON(desc_array);
    394	return 0;
    395}
    396static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
    397{
    398	/* GPIO can never have been requested */
    399	WARN_ON(desc);
    400	return 0;
    401}
    402static inline int gpiod_get_raw_array_value(unsigned int array_size,
    403					    struct gpio_desc **desc_array,
    404					    struct gpio_array *array_info,
    405					    unsigned long *value_bitmap)
    406{
    407	/* GPIO can never have been requested */
    408	WARN_ON(desc_array);
    409	return 0;
    410}
    411static inline void gpiod_set_raw_value(struct gpio_desc *desc, int value)
    412{
    413	/* GPIO can never have been requested */
    414	WARN_ON(desc);
    415}
    416static inline int gpiod_set_raw_array_value(unsigned int array_size,
    417					    struct gpio_desc **desc_array,
    418					    struct gpio_array *array_info,
    419					    unsigned long *value_bitmap)
    420{
    421	/* GPIO can never have been requested */
    422	WARN_ON(desc_array);
    423	return 0;
    424}
    425
    426static inline int gpiod_get_value_cansleep(const struct gpio_desc *desc)
    427{
    428	/* GPIO can never have been requested */
    429	WARN_ON(desc);
    430	return 0;
    431}
    432static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
    433				     struct gpio_desc **desc_array,
    434				     struct gpio_array *array_info,
    435				     unsigned long *value_bitmap)
    436{
    437	/* GPIO can never have been requested */
    438	WARN_ON(desc_array);
    439	return 0;
    440}
    441static inline void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
    442{
    443	/* GPIO can never have been requested */
    444	WARN_ON(desc);
    445}
    446static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
    447					    struct gpio_desc **desc_array,
    448					    struct gpio_array *array_info,
    449					    unsigned long *value_bitmap)
    450{
    451	/* GPIO can never have been requested */
    452	WARN_ON(desc_array);
    453	return 0;
    454}
    455static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
    456{
    457	/* GPIO can never have been requested */
    458	WARN_ON(desc);
    459	return 0;
    460}
    461static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
    462					       struct gpio_desc **desc_array,
    463					       struct gpio_array *array_info,
    464					       unsigned long *value_bitmap)
    465{
    466	/* GPIO can never have been requested */
    467	WARN_ON(desc_array);
    468	return 0;
    469}
    470static inline void gpiod_set_raw_value_cansleep(struct gpio_desc *desc,
    471						int value)
    472{
    473	/* GPIO can never have been requested */
    474	WARN_ON(desc);
    475}
    476static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
    477						struct gpio_desc **desc_array,
    478						struct gpio_array *array_info,
    479						unsigned long *value_bitmap)
    480{
    481	/* GPIO can never have been requested */
    482	WARN_ON(desc_array);
    483	return 0;
    484}
    485
    486static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
    487{
    488	/* GPIO can never have been requested */
    489	WARN_ON(desc);
    490	return -ENOSYS;
    491}
    492
    493static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned int debounce)
    494{
    495	/* GPIO can never have been requested */
    496	WARN_ON(desc);
    497	return -ENOSYS;
    498}
    499
    500static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
    501{
    502	/* GPIO can never have been requested */
    503	WARN_ON(desc);
    504	return -ENOSYS;
    505}
    506
    507static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
    508{
    509	/* GPIO can never have been requested */
    510	WARN_ON(desc);
    511}
    512
    513static inline int gpiod_is_active_low(const struct gpio_desc *desc)
    514{
    515	/* GPIO can never have been requested */
    516	WARN_ON(desc);
    517	return 0;
    518}
    519static inline int gpiod_cansleep(const struct gpio_desc *desc)
    520{
    521	/* GPIO can never have been requested */
    522	WARN_ON(desc);
    523	return 0;
    524}
    525
    526static inline int gpiod_to_irq(const struct gpio_desc *desc)
    527{
    528	/* GPIO can never have been requested */
    529	WARN_ON(desc);
    530	return -EINVAL;
    531}
    532
    533static inline int gpiod_set_consumer_name(struct gpio_desc *desc,
    534					  const char *name)
    535{
    536	/* GPIO can never have been requested */
    537	WARN_ON(desc);
    538	return -EINVAL;
    539}
    540
    541static inline struct gpio_desc *gpio_to_desc(unsigned gpio)
    542{
    543	return NULL;
    544}
    545
    546static inline int desc_to_gpio(const struct gpio_desc *desc)
    547{
    548	/* GPIO can never have been requested */
    549	WARN_ON(desc);
    550	return -EINVAL;
    551}
    552
    553/* Child properties interface */
    554struct fwnode_handle;
    555
    556static inline
    557struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
    558					 const char *propname, int index,
    559					 enum gpiod_flags dflags,
    560					 const char *label)
    561{
    562	return ERR_PTR(-ENOSYS);
    563}
    564
    565static inline
    566struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
    567					 const char *con_id, int index,
    568					 enum gpiod_flags flags,
    569					 const char *label)
    570{
    571	return ERR_PTR(-ENOSYS);
    572}
    573
    574static inline
    575struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
    576					      struct fwnode_handle *fwnode,
    577					      const char *con_id, int index,
    578					      enum gpiod_flags flags,
    579					      const char *label)
    580{
    581	return ERR_PTR(-ENOSYS);
    582}
    583
    584#endif /* CONFIG_GPIOLIB */
    585
    586static inline
    587struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
    588					struct fwnode_handle *fwnode,
    589					const char *con_id,
    590					enum gpiod_flags flags,
    591					const char *label)
    592{
    593	return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
    594					   flags, label);
    595}
    596
    597static inline
    598struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
    599						const char *con_id, int index,
    600						struct fwnode_handle *child,
    601						enum gpiod_flags flags,
    602						const char *label)
    603{
    604	return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
    605					   flags, label);
    606}
    607
    608static inline
    609struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
    610						   const char *con_id,
    611						   struct fwnode_handle *child,
    612						   enum gpiod_flags flags,
    613						   const char *label)
    614{
    615	return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
    616}
    617
    618#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
    619struct device_node;
    620
    621struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
    622					 const char *propname, int index,
    623					 enum gpiod_flags dflags,
    624					 const char *label);
    625
    626#else  /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
    627
    628struct device_node;
    629
    630static inline
    631struct gpio_desc *gpiod_get_from_of_node(const struct device_node *node,
    632					 const char *propname, int index,
    633					 enum gpiod_flags dflags,
    634					 const char *label)
    635{
    636	return ERR_PTR(-ENOSYS);
    637}
    638
    639#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
    640
    641#ifdef CONFIG_GPIOLIB
    642struct device_node;
    643
    644struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
    645					      const struct device_node *node,
    646					      const char *propname, int index,
    647					      enum gpiod_flags dflags,
    648					      const char *label);
    649
    650#else  /* CONFIG_GPIOLIB */
    651
    652struct device_node;
    653
    654static inline
    655struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
    656					      const struct device_node *node,
    657					      const char *propname, int index,
    658					      enum gpiod_flags dflags,
    659					      const char *label)
    660{
    661	return ERR_PTR(-ENOSYS);
    662}
    663
    664#endif /* CONFIG_GPIOLIB */
    665
    666struct acpi_gpio_params {
    667	unsigned int crs_entry_index;
    668	unsigned int line_index;
    669	bool active_low;
    670};
    671
    672struct acpi_gpio_mapping {
    673	const char *name;
    674	const struct acpi_gpio_params *data;
    675	unsigned int size;
    676
    677/* Ignore IoRestriction field */
    678#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION	BIT(0)
    679/*
    680 * When ACPI GPIO mapping table is in use the index parameter inside it
    681 * refers to the GPIO resource in _CRS method. That index has no
    682 * distinction of actual type of the resource. When consumer wants to
    683 * get GpioIo type explicitly, this quirk may be used.
    684 */
    685#define ACPI_GPIO_QUIRK_ONLY_GPIOIO		BIT(1)
    686/* Use given pin as an absolute GPIO number in the system */
    687#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER		BIT(2)
    688
    689	unsigned int quirks;
    690};
    691
    692struct acpi_device;
    693
    694#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
    695
    696int acpi_dev_add_driver_gpios(struct acpi_device *adev,
    697			      const struct acpi_gpio_mapping *gpios);
    698void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
    699
    700int devm_acpi_dev_add_driver_gpios(struct device *dev,
    701				   const struct acpi_gpio_mapping *gpios);
    702
    703struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin, char *label);
    704
    705#else  /* CONFIG_GPIOLIB && CONFIG_ACPI */
    706
    707static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
    708			      const struct acpi_gpio_mapping *gpios)
    709{
    710	return -ENXIO;
    711}
    712static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
    713
    714static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
    715			      const struct acpi_gpio_mapping *gpios)
    716{
    717	return -ENXIO;
    718}
    719
    720static inline struct gpio_desc *acpi_get_and_request_gpiod(char *path, unsigned int pin,
    721							   char *label)
    722{
    723	return ERR_PTR(-ENOSYS);
    724}
    725
    726#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
    727
    728
    729#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
    730
    731int gpiod_export(struct gpio_desc *desc, bool direction_may_change);
    732int gpiod_export_link(struct device *dev, const char *name,
    733		      struct gpio_desc *desc);
    734void gpiod_unexport(struct gpio_desc *desc);
    735
    736#else  /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
    737
    738static inline int gpiod_export(struct gpio_desc *desc,
    739			       bool direction_may_change)
    740{
    741	return -ENOSYS;
    742}
    743
    744static inline int gpiod_export_link(struct device *dev, const char *name,
    745				    struct gpio_desc *desc)
    746{
    747	return -ENOSYS;
    748}
    749
    750static inline void gpiod_unexport(struct gpio_desc *desc)
    751{
    752}
    753
    754#endif /* CONFIG_GPIOLIB && CONFIG_GPIO_SYSFS */
    755
    756#endif