hc
2024-05-16 8d2a02b24d66aa359e83eebc1ed3c0f85367a1cb
kernel/include/linux/gpio/consumer.h
....@@ -2,9 +2,10 @@
22 #ifndef __LINUX_GPIO_CONSUMER_H
33 #define __LINUX_GPIO_CONSUMER_H
44
5
+#include <linux/bits.h>
56 #include <linux/bug.h>
7
+#include <linux/compiler_types.h>
68 #include <linux/err.h>
7
-#include <linux/kernel.h>
89
910 struct device;
1011
....@@ -18,10 +19,19 @@
1819 struct gpio_desc;
1920
2021 /**
22
+ * Opaque descriptor for a structure of GPIO array attributes. This structure
23
+ * is attached to struct gpiod_descs obtained from gpiod_get_array() and can be
24
+ * passed back to get/set array functions in order to activate fast processing
25
+ * path if applicable.
26
+ */
27
+struct gpio_array;
28
+
29
+/**
2130 * Struct containing an array of descriptors that can be obtained using
2231 * gpiod_get_array().
2332 */
2433 struct gpio_descs {
34
+ struct gpio_array *info;
2535 unsigned int ndescs;
2636 struct gpio_desc *desc[];
2737 };
....@@ -30,6 +40,7 @@
3040 #define GPIOD_FLAGS_BIT_DIR_OUT BIT(1)
3141 #define GPIOD_FLAGS_BIT_DIR_VAL BIT(2)
3242 #define GPIOD_FLAGS_BIT_OPEN_DRAIN BIT(3)
43
+#define GPIOD_FLAGS_BIT_NONEXCLUSIVE BIT(4)
3344
3445 /**
3546 * Optional flags that can be passed to one of gpiod_* to configure direction
....@@ -94,6 +105,7 @@
94105 devm_gpiod_get_array_optional(struct device *dev, const char *con_id,
95106 enum gpiod_flags flags);
96107 void devm_gpiod_put(struct device *dev, struct gpio_desc *desc);
108
+void devm_gpiod_unhinge(struct device *dev, struct gpio_desc *desc);
97109 void devm_gpiod_put_array(struct device *dev, struct gpio_descs *descs);
98110
99111 int gpiod_get_direction(struct gpio_desc *desc);
....@@ -104,39 +116,51 @@
104116 /* Value get/set from non-sleeping context */
105117 int gpiod_get_value(const struct gpio_desc *desc);
106118 int gpiod_get_array_value(unsigned int array_size,
107
- struct gpio_desc **desc_array, int *value_array);
119
+ struct gpio_desc **desc_array,
120
+ struct gpio_array *array_info,
121
+ unsigned long *value_bitmap);
108122 void gpiod_set_value(struct gpio_desc *desc, int value);
109
-void gpiod_set_array_value(unsigned int array_size,
110
- struct gpio_desc **desc_array, int *value_array);
123
+int gpiod_set_array_value(unsigned int array_size,
124
+ struct gpio_desc **desc_array,
125
+ struct gpio_array *array_info,
126
+ unsigned long *value_bitmap);
111127 int gpiod_get_raw_value(const struct gpio_desc *desc);
112128 int gpiod_get_raw_array_value(unsigned int array_size,
113129 struct gpio_desc **desc_array,
114
- int *value_array);
130
+ struct gpio_array *array_info,
131
+ unsigned long *value_bitmap);
115132 void gpiod_set_raw_value(struct gpio_desc *desc, int value);
116133 int gpiod_set_raw_array_value(unsigned int array_size,
117
- struct gpio_desc **desc_array,
118
- int *value_array);
134
+ struct gpio_desc **desc_array,
135
+ struct gpio_array *array_info,
136
+ unsigned long *value_bitmap);
119137
120138 /* Value get/set from sleeping context */
121139 int gpiod_get_value_cansleep(const struct gpio_desc *desc);
122140 int gpiod_get_array_value_cansleep(unsigned int array_size,
123141 struct gpio_desc **desc_array,
124
- int *value_array);
142
+ struct gpio_array *array_info,
143
+ unsigned long *value_bitmap);
125144 void gpiod_set_value_cansleep(struct gpio_desc *desc, int value);
126
-void gpiod_set_array_value_cansleep(unsigned int array_size,
127
- struct gpio_desc **desc_array,
128
- int *value_array);
145
+int gpiod_set_array_value_cansleep(unsigned int array_size,
146
+ struct gpio_desc **desc_array,
147
+ struct gpio_array *array_info,
148
+ unsigned long *value_bitmap);
129149 int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc);
130150 int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
131151 struct gpio_desc **desc_array,
132
- int *value_array);
152
+ struct gpio_array *array_info,
153
+ unsigned long *value_bitmap);
133154 void gpiod_set_raw_value_cansleep(struct gpio_desc *desc, int value);
134155 int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
135
- struct gpio_desc **desc_array,
136
- int *value_array);
156
+ struct gpio_desc **desc_array,
157
+ struct gpio_array *array_info,
158
+ unsigned long *value_bitmap);
137159
160
+int gpiod_set_config(struct gpio_desc *desc, unsigned long config);
138161 int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
139162 int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
163
+void gpiod_toggle_active_low(struct gpio_desc *desc);
140164
141165 int gpiod_is_active_low(const struct gpio_desc *desc);
142166 int gpiod_cansleep(const struct gpio_desc *desc);
....@@ -149,25 +173,25 @@
149173 int desc_to_gpio(const struct gpio_desc *desc);
150174
151175 /* Child properties interface */
152
-struct device_node;
153176 struct fwnode_handle;
154177
155
-struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
156
- struct device_node *node,
157
- const char *propname, int index,
158
- enum gpiod_flags dflags,
159
- const char *label);
160178 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
161179 const char *propname, int index,
162180 enum gpiod_flags dflags,
163181 const char *label);
164
-struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
165
- const char *con_id, int index,
166
- struct fwnode_handle *child,
167
- enum gpiod_flags flags,
168
- const char *label);
182
+struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
183
+ const char *con_id, int index,
184
+ enum gpiod_flags flags,
185
+ const char *label);
186
+struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
187
+ struct fwnode_handle *child,
188
+ const char *con_id, int index,
189
+ enum gpiod_flags flags,
190
+ const char *label);
169191
170192 #else /* CONFIG_GPIOLIB */
193
+
194
+#include <linux/kernel.h>
171195
172196 static inline int gpiod_count(struct device *dev, const char *con_id)
173197 {
....@@ -218,6 +242,15 @@
218242 }
219243
220244 static inline void gpiod_put(struct gpio_desc *desc)
245
+{
246
+ might_sleep();
247
+
248
+ /* GPIO can never have been requested */
249
+ WARN_ON(desc);
250
+}
251
+
252
+static inline void devm_gpiod_unhinge(struct device *dev,
253
+ struct gpio_desc *desc)
221254 {
222255 might_sleep();
223256
....@@ -330,7 +363,8 @@
330363 }
331364 static inline int gpiod_get_array_value(unsigned int array_size,
332365 struct gpio_desc **desc_array,
333
- int *value_array)
366
+ struct gpio_array *array_info,
367
+ unsigned long *value_bitmap)
334368 {
335369 /* GPIO can never have been requested */
336370 WARN_ON(desc_array);
....@@ -341,12 +375,14 @@
341375 /* GPIO can never have been requested */
342376 WARN_ON(desc);
343377 }
344
-static inline void gpiod_set_array_value(unsigned int array_size,
345
- struct gpio_desc **desc_array,
346
- int *value_array)
378
+static inline int gpiod_set_array_value(unsigned int array_size,
379
+ struct gpio_desc **desc_array,
380
+ struct gpio_array *array_info,
381
+ unsigned long *value_bitmap)
347382 {
348383 /* GPIO can never have been requested */
349384 WARN_ON(desc_array);
385
+ return 0;
350386 }
351387 static inline int gpiod_get_raw_value(const struct gpio_desc *desc)
352388 {
....@@ -356,7 +392,8 @@
356392 }
357393 static inline int gpiod_get_raw_array_value(unsigned int array_size,
358394 struct gpio_desc **desc_array,
359
- int *value_array)
395
+ struct gpio_array *array_info,
396
+ unsigned long *value_bitmap)
360397 {
361398 /* GPIO can never have been requested */
362399 WARN_ON(desc_array);
....@@ -368,8 +405,9 @@
368405 WARN_ON(desc);
369406 }
370407 static inline int gpiod_set_raw_array_value(unsigned int array_size,
371
- struct gpio_desc **desc_array,
372
- int *value_array)
408
+ struct gpio_desc **desc_array,
409
+ struct gpio_array *array_info,
410
+ unsigned long *value_bitmap)
373411 {
374412 /* GPIO can never have been requested */
375413 WARN_ON(desc_array);
....@@ -384,7 +422,8 @@
384422 }
385423 static inline int gpiod_get_array_value_cansleep(unsigned int array_size,
386424 struct gpio_desc **desc_array,
387
- int *value_array)
425
+ struct gpio_array *array_info,
426
+ unsigned long *value_bitmap)
388427 {
389428 /* GPIO can never have been requested */
390429 WARN_ON(desc_array);
....@@ -395,12 +434,14 @@
395434 /* GPIO can never have been requested */
396435 WARN_ON(desc);
397436 }
398
-static inline void gpiod_set_array_value_cansleep(unsigned int array_size,
437
+static inline int gpiod_set_array_value_cansleep(unsigned int array_size,
399438 struct gpio_desc **desc_array,
400
- int *value_array)
439
+ struct gpio_array *array_info,
440
+ unsigned long *value_bitmap)
401441 {
402442 /* GPIO can never have been requested */
403443 WARN_ON(desc_array);
444
+ return 0;
404445 }
405446 static inline int gpiod_get_raw_value_cansleep(const struct gpio_desc *desc)
406447 {
....@@ -410,7 +451,8 @@
410451 }
411452 static inline int gpiod_get_raw_array_value_cansleep(unsigned int array_size,
412453 struct gpio_desc **desc_array,
413
- int *value_array)
454
+ struct gpio_array *array_info,
455
+ unsigned long *value_bitmap)
414456 {
415457 /* GPIO can never have been requested */
416458 WARN_ON(desc_array);
....@@ -424,11 +466,19 @@
424466 }
425467 static inline int gpiod_set_raw_array_value_cansleep(unsigned int array_size,
426468 struct gpio_desc **desc_array,
427
- int *value_array)
469
+ struct gpio_array *array_info,
470
+ unsigned long *value_bitmap)
428471 {
429472 /* GPIO can never have been requested */
430473 WARN_ON(desc_array);
431474 return 0;
475
+}
476
+
477
+static inline int gpiod_set_config(struct gpio_desc *desc, unsigned long config)
478
+{
479
+ /* GPIO can never have been requested */
480
+ WARN_ON(desc);
481
+ return -ENOSYS;
432482 }
433483
434484 static inline int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce)
....@@ -443,6 +493,12 @@
443493 /* GPIO can never have been requested */
444494 WARN_ON(desc);
445495 return -ENOSYS;
496
+}
497
+
498
+static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
499
+{
500
+ /* GPIO can never have been requested */
501
+ WARN_ON(desc);
446502 }
447503
448504 static inline int gpiod_is_active_low(const struct gpio_desc *desc)
....@@ -486,18 +542,7 @@
486542 }
487543
488544 /* Child properties interface */
489
-struct device_node;
490545 struct fwnode_handle;
491
-
492
-static inline
493
-struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
494
- struct device_node *node,
495
- const char *propname, int index,
496
- enum gpiod_flags dflags,
497
- const char *label)
498
-{
499
- return ERR_PTR(-ENOSYS);
500
-}
501546
502547 static inline
503548 struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode,
....@@ -509,16 +554,47 @@
509554 }
510555
511556 static inline
557
+struct gpio_desc *fwnode_gpiod_get_index(struct fwnode_handle *fwnode,
558
+ const char *con_id, int index,
559
+ enum gpiod_flags flags,
560
+ const char *label)
561
+{
562
+ return ERR_PTR(-ENOSYS);
563
+}
564
+
565
+static inline
566
+struct gpio_desc *devm_fwnode_gpiod_get_index(struct device *dev,
567
+ struct fwnode_handle *fwnode,
568
+ const char *con_id, int index,
569
+ enum gpiod_flags flags,
570
+ const char *label)
571
+{
572
+ return ERR_PTR(-ENOSYS);
573
+}
574
+
575
+#endif /* CONFIG_GPIOLIB */
576
+
577
+static inline
578
+struct gpio_desc *devm_fwnode_gpiod_get(struct device *dev,
579
+ struct fwnode_handle *fwnode,
580
+ const char *con_id,
581
+ enum gpiod_flags flags,
582
+ const char *label)
583
+{
584
+ return devm_fwnode_gpiod_get_index(dev, fwnode, con_id, 0,
585
+ flags, label);
586
+}
587
+
588
+static inline
512589 struct gpio_desc *devm_fwnode_get_index_gpiod_from_child(struct device *dev,
513590 const char *con_id, int index,
514591 struct fwnode_handle *child,
515592 enum gpiod_flags flags,
516593 const char *label)
517594 {
518
- return ERR_PTR(-ENOSYS);
595
+ return devm_fwnode_gpiod_get_index(dev, child, con_id, index,
596
+ flags, label);
519597 }
520
-
521
-#endif /* CONFIG_GPIOLIB */
522598
523599 static inline
524600 struct gpio_desc *devm_fwnode_get_gpiod_from_child(struct device *dev,
....@@ -527,10 +603,116 @@
527603 enum gpiod_flags flags,
528604 const char *label)
529605 {
530
- return devm_fwnode_get_index_gpiod_from_child(dev, con_id, 0, child,
531
- flags, label);
606
+ return devm_fwnode_gpiod_get_index(dev, child, con_id, 0, flags, label);
532607 }
533608
609
+#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_OF_GPIO)
610
+struct device_node;
611
+
612
+struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
613
+ const char *propname, int index,
614
+ enum gpiod_flags dflags,
615
+ const char *label);
616
+
617
+#else /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
618
+
619
+struct device_node;
620
+
621
+static inline
622
+struct gpio_desc *gpiod_get_from_of_node(struct device_node *node,
623
+ const char *propname, int index,
624
+ enum gpiod_flags dflags,
625
+ const char *label)
626
+{
627
+ return ERR_PTR(-ENOSYS);
628
+}
629
+
630
+#endif /* CONFIG_GPIOLIB && CONFIG_OF_GPIO */
631
+
632
+#ifdef CONFIG_GPIOLIB
633
+struct device_node;
634
+
635
+struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
636
+ struct device_node *node,
637
+ const char *propname, int index,
638
+ enum gpiod_flags dflags,
639
+ const char *label);
640
+
641
+#else /* CONFIG_GPIOLIB */
642
+
643
+struct device_node;
644
+
645
+static inline
646
+struct gpio_desc *devm_gpiod_get_from_of_node(struct device *dev,
647
+ struct device_node *node,
648
+ const char *propname, int index,
649
+ enum gpiod_flags dflags,
650
+ const char *label)
651
+{
652
+ return ERR_PTR(-ENOSYS);
653
+}
654
+
655
+#endif /* CONFIG_GPIOLIB */
656
+
657
+struct acpi_gpio_params {
658
+ unsigned int crs_entry_index;
659
+ unsigned int line_index;
660
+ bool active_low;
661
+};
662
+
663
+struct acpi_gpio_mapping {
664
+ const char *name;
665
+ const struct acpi_gpio_params *data;
666
+ unsigned int size;
667
+
668
+/* Ignore IoRestriction field */
669
+#define ACPI_GPIO_QUIRK_NO_IO_RESTRICTION BIT(0)
670
+/*
671
+ * When ACPI GPIO mapping table is in use the index parameter inside it
672
+ * refers to the GPIO resource in _CRS method. That index has no
673
+ * distinction of actual type of the resource. When consumer wants to
674
+ * get GpioIo type explicitly, this quirk may be used.
675
+ */
676
+#define ACPI_GPIO_QUIRK_ONLY_GPIOIO BIT(1)
677
+/* Use given pin as an absolute GPIO number in the system */
678
+#define ACPI_GPIO_QUIRK_ABSOLUTE_NUMBER BIT(2)
679
+
680
+ unsigned int quirks;
681
+};
682
+
683
+#if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_ACPI)
684
+
685
+struct acpi_device;
686
+
687
+int acpi_dev_add_driver_gpios(struct acpi_device *adev,
688
+ const struct acpi_gpio_mapping *gpios);
689
+void acpi_dev_remove_driver_gpios(struct acpi_device *adev);
690
+
691
+int devm_acpi_dev_add_driver_gpios(struct device *dev,
692
+ const struct acpi_gpio_mapping *gpios);
693
+void devm_acpi_dev_remove_driver_gpios(struct device *dev);
694
+
695
+#else /* CONFIG_GPIOLIB && CONFIG_ACPI */
696
+
697
+struct acpi_device;
698
+
699
+static inline int acpi_dev_add_driver_gpios(struct acpi_device *adev,
700
+ const struct acpi_gpio_mapping *gpios)
701
+{
702
+ return -ENXIO;
703
+}
704
+static inline void acpi_dev_remove_driver_gpios(struct acpi_device *adev) {}
705
+
706
+static inline int devm_acpi_dev_add_driver_gpios(struct device *dev,
707
+ const struct acpi_gpio_mapping *gpios)
708
+{
709
+ return -ENXIO;
710
+}
711
+static inline void devm_acpi_dev_remove_driver_gpios(struct device *dev) {}
712
+
713
+#endif /* CONFIG_GPIOLIB && CONFIG_ACPI */
714
+
715
+
534716 #if IS_ENABLED(CONFIG_GPIOLIB) && IS_ENABLED(CONFIG_GPIO_SYSFS)
535717
536718 int gpiod_export(struct gpio_desc *desc, bool direction_may_change);