1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/interrupt.h>
5 #include <linux/spinlock.h>
6 #include <linux/device.h>
8 #include <linux/debugfs.h>
9 #include <linux/seq_file.h>
10 #include <linux/gpio.h>
11 #include <linux/of_gpio.h>
12 #include <linux/idr.h>
13 #include <linux/slab.h>
15 #define CREATE_TRACE_POINTS
16 #include <trace/events/gpio.h>
18 /* Optional implementation infrastructure for GPIO interfaces.
20 * Platforms may want to use this if they tend to use very many GPIOs
21 * that aren't part of a System-On-Chip core; or across I2C/SPI/etc.
23 * When kernel footprint or instruction count is an issue, simpler
24 * implementations may be preferred. The GPIO programming interface
25 * allows for inlining speed-critical get/set operations for common
26 * cases, so that access to SOC-integrated GPIOs can sometimes cost
27 * only an instruction or two per bit.
31 /* When debugging, extend minimal trust to callers and platform code.
32 * Also emit diagnostic messages that may help initial bringup, when
33 * board setup or driver bugs are most common.
35 * Otherwise, minimize overhead in what may be bitbanging codepaths.
38 #define extra_checks 1
40 #define extra_checks 0
43 /* gpio_lock prevents conflicts during gpio_desc[] table updates.
44 * While any GPIO is requested, its gpio_chip is not removable;
45 * each GPIO's "requested" flag serves as a lock and refcount.
47 static DEFINE_SPINLOCK(gpio_lock
);
50 struct gpio_chip
*chip
;
52 /* flag symbols are bit numbers */
53 #define FLAG_REQUESTED 0
55 #define FLAG_RESERVED 2
56 #define FLAG_EXPORT 3 /* protected by sysfs_lock */
57 #define FLAG_SYSFS 4 /* exported via /sys/class/gpio/control */
58 #define FLAG_TRIG_FALL 5 /* trigger on falling edge */
59 #define FLAG_TRIG_RISE 6 /* trigger on rising edge */
60 #define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */
62 #define ID_SHIFT 16 /* add new flags before this one */
64 #define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
65 #define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
67 #ifdef CONFIG_DEBUG_FS
71 static struct gpio_desc gpio_desc
[ARCH_NR_GPIOS
];
73 #ifdef CONFIG_GPIO_SYSFS
74 static DEFINE_IDR(dirent_idr
);
77 static inline void desc_set_label(struct gpio_desc
*d
, const char *label
)
79 #ifdef CONFIG_DEBUG_FS
84 /* Warn when drivers omit gpio_request() calls -- legal but ill-advised
85 * when setting direction, and otherwise illegal. Until board setup code
86 * and drivers use explicit requests everywhere (which won't happen when
87 * those calls have no teeth) we can't avoid autorequesting. This nag
88 * message should motivate switching to explicit requests... so should
89 * the weaker cleanup after faults, compared to gpio_request().
91 * NOTE: the autorequest mechanism is going away; at this point it's
92 * only "legal" in the sense that (old) code using it won't break yet,
93 * but instead only triggers a WARN() stack dump.
95 static int gpio_ensure_requested(struct gpio_desc
*desc
, unsigned offset
)
97 const struct gpio_chip
*chip
= desc
->chip
;
98 const int gpio
= chip
->base
+ offset
;
100 if (WARN(test_and_set_bit(FLAG_REQUESTED
, &desc
->flags
) == 0,
101 "autorequest GPIO-%d\n", gpio
)) {
102 if (!try_module_get(chip
->owner
)) {
103 pr_err("GPIO-%d: module can't be gotten \n", gpio
);
104 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
108 desc_set_label(desc
, "[auto]");
109 /* caller must chip->request() w/o spinlock */
116 /* caller holds gpio_lock *OR* gpio is marked as requested */
117 struct gpio_chip
*gpio_to_chip(unsigned gpio
)
119 return gpio_desc
[gpio
].chip
;
122 /* dynamic allocation of GPIOs, e.g. on a hotplugged device */
123 static int gpiochip_find_base(int ngpio
)
129 for (i
= ARCH_NR_GPIOS
- 1; i
>= 0 ; i
--) {
130 struct gpio_desc
*desc
= &gpio_desc
[i
];
131 struct gpio_chip
*chip
= desc
->chip
;
133 if (!chip
&& !test_bit(FLAG_RESERVED
, &desc
->flags
)) {
135 if (spare
== ngpio
) {
142 i
-= chip
->ngpio
- 1;
146 if (gpio_is_valid(base
))
147 pr_debug("%s: found new base at %d\n", __func__
, base
);
152 * gpiochip_reserve() - reserve range of gpios to use with platform code only
153 * @start: starting gpio number
154 * @ngpio: number of gpios to reserve
155 * Context: platform init, potentially before irqs or kmalloc will work
157 * Returns a negative errno if any gpio within the range is already reserved
158 * or registered, else returns zero as a success code. Use this function
159 * to mark a range of gpios as unavailable for dynamic gpio number allocation,
160 * for example because its driver support is not yet loaded.
162 int __init
gpiochip_reserve(int start
, int ngpio
)
168 if (!gpio_is_valid(start
) || !gpio_is_valid(start
+ ngpio
- 1))
171 spin_lock_irqsave(&gpio_lock
, flags
);
173 for (i
= start
; i
< start
+ ngpio
; i
++) {
174 struct gpio_desc
*desc
= &gpio_desc
[i
];
176 if (desc
->chip
|| test_bit(FLAG_RESERVED
, &desc
->flags
)) {
181 set_bit(FLAG_RESERVED
, &desc
->flags
);
184 pr_debug("%s: reserved gpios from %d to %d\n",
185 __func__
, start
, start
+ ngpio
- 1);
187 spin_unlock_irqrestore(&gpio_lock
, flags
);
192 #ifdef CONFIG_GPIO_SYSFS
194 /* lock protects against unexport_gpio() being called while
195 * sysfs files are active.
197 static DEFINE_MUTEX(sysfs_lock
);
200 * /sys/class/gpio/gpioN... only for GPIOs that are exported
202 * * MAY BE OMITTED if kernel won't allow direction changes
203 * * is read/write as "in" or "out"
204 * * may also be written as "high" or "low", initializing
205 * output value as specified ("out" implies "low")
207 * * always readable, subject to hardware behavior
208 * * may be writable, as zero/nonzero
210 * * configures behavior of poll(2) on /value
211 * * available only if pin can generate IRQs on input
212 * * is read/write as "none", "falling", "rising", or "both"
214 * * configures polarity of /value
215 * * is read/write as zero/nonzero
216 * * also affects existing and subsequent "falling" and "rising"
217 * /edge configuration
220 static ssize_t
gpio_direction_show(struct device
*dev
,
221 struct device_attribute
*attr
, char *buf
)
223 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
226 mutex_lock(&sysfs_lock
);
228 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
231 status
= sprintf(buf
, "%s\n",
232 test_bit(FLAG_IS_OUT
, &desc
->flags
)
235 mutex_unlock(&sysfs_lock
);
239 static ssize_t
gpio_direction_store(struct device
*dev
,
240 struct device_attribute
*attr
, const char *buf
, size_t size
)
242 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
243 unsigned gpio
= desc
- gpio_desc
;
246 mutex_lock(&sysfs_lock
);
248 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
250 else if (sysfs_streq(buf
, "high"))
251 status
= gpio_direction_output(gpio
, 1);
252 else if (sysfs_streq(buf
, "out") || sysfs_streq(buf
, "low"))
253 status
= gpio_direction_output(gpio
, 0);
254 else if (sysfs_streq(buf
, "in"))
255 status
= gpio_direction_input(gpio
);
259 mutex_unlock(&sysfs_lock
);
260 return status
? : size
;
263 static /* const */ DEVICE_ATTR(direction
, 0644,
264 gpio_direction_show
, gpio_direction_store
);
266 static ssize_t
gpio_value_show(struct device
*dev
,
267 struct device_attribute
*attr
, char *buf
)
269 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
270 unsigned gpio
= desc
- gpio_desc
;
273 mutex_lock(&sysfs_lock
);
275 if (!test_bit(FLAG_EXPORT
, &desc
->flags
)) {
280 value
= !!gpio_get_value_cansleep(gpio
);
281 if (test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
))
284 status
= sprintf(buf
, "%d\n", value
);
287 mutex_unlock(&sysfs_lock
);
291 static ssize_t
gpio_value_store(struct device
*dev
,
292 struct device_attribute
*attr
, const char *buf
, size_t size
)
294 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
295 unsigned gpio
= desc
- gpio_desc
;
298 mutex_lock(&sysfs_lock
);
300 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
302 else if (!test_bit(FLAG_IS_OUT
, &desc
->flags
))
307 status
= strict_strtol(buf
, 0, &value
);
309 if (test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
))
311 gpio_set_value_cansleep(gpio
, value
!= 0);
316 mutex_unlock(&sysfs_lock
);
320 static const DEVICE_ATTR(value
, 0644,
321 gpio_value_show
, gpio_value_store
);
323 static irqreturn_t
gpio_sysfs_irq(int irq
, void *priv
)
325 struct sysfs_dirent
*value_sd
= priv
;
327 sysfs_notify_dirent(value_sd
);
331 static int gpio_setup_irq(struct gpio_desc
*desc
, struct device
*dev
,
332 unsigned long gpio_flags
)
334 struct sysfs_dirent
*value_sd
;
335 unsigned long irq_flags
;
338 if ((desc
->flags
& GPIO_TRIGGER_MASK
) == gpio_flags
)
341 irq
= gpio_to_irq(desc
- gpio_desc
);
345 id
= desc
->flags
>> ID_SHIFT
;
346 value_sd
= idr_find(&dirent_idr
, id
);
348 free_irq(irq
, value_sd
);
350 desc
->flags
&= ~GPIO_TRIGGER_MASK
;
357 irq_flags
= IRQF_SHARED
;
358 if (test_bit(FLAG_TRIG_FALL
, &gpio_flags
))
359 irq_flags
|= test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) ?
360 IRQF_TRIGGER_RISING
: IRQF_TRIGGER_FALLING
;
361 if (test_bit(FLAG_TRIG_RISE
, &gpio_flags
))
362 irq_flags
|= test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) ?
363 IRQF_TRIGGER_FALLING
: IRQF_TRIGGER_RISING
;
366 value_sd
= sysfs_get_dirent(dev
->kobj
.sd
, NULL
, "value");
374 if (idr_pre_get(&dirent_idr
, GFP_KERNEL
))
375 ret
= idr_get_new_above(&dirent_idr
, value_sd
,
377 } while (ret
== -EAGAIN
);
382 desc
->flags
&= GPIO_FLAGS_MASK
;
383 desc
->flags
|= (unsigned long)id
<< ID_SHIFT
;
385 if (desc
->flags
>> ID_SHIFT
!= id
) {
391 ret
= request_any_context_irq(irq
, gpio_sysfs_irq
, irq_flags
,
392 "gpiolib", value_sd
);
396 desc
->flags
|= gpio_flags
;
400 idr_remove(&dirent_idr
, id
);
401 desc
->flags
&= GPIO_FLAGS_MASK
;
409 static const struct {
412 } trigger_types
[] = {
414 { "falling", BIT(FLAG_TRIG_FALL
) },
415 { "rising", BIT(FLAG_TRIG_RISE
) },
416 { "both", BIT(FLAG_TRIG_FALL
) | BIT(FLAG_TRIG_RISE
) },
419 static ssize_t
gpio_edge_show(struct device
*dev
,
420 struct device_attribute
*attr
, char *buf
)
422 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
425 mutex_lock(&sysfs_lock
);
427 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
433 for (i
= 0; i
< ARRAY_SIZE(trigger_types
); i
++)
434 if ((desc
->flags
& GPIO_TRIGGER_MASK
)
435 == trigger_types
[i
].flags
) {
436 status
= sprintf(buf
, "%s\n",
437 trigger_types
[i
].name
);
442 mutex_unlock(&sysfs_lock
);
446 static ssize_t
gpio_edge_store(struct device
*dev
,
447 struct device_attribute
*attr
, const char *buf
, size_t size
)
449 struct gpio_desc
*desc
= dev_get_drvdata(dev
);
453 for (i
= 0; i
< ARRAY_SIZE(trigger_types
); i
++)
454 if (sysfs_streq(trigger_types
[i
].name
, buf
))
459 mutex_lock(&sysfs_lock
);
461 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
464 status
= gpio_setup_irq(desc
, dev
, trigger_types
[i
].flags
);
469 mutex_unlock(&sysfs_lock
);
474 static DEVICE_ATTR(edge
, 0644, gpio_edge_show
, gpio_edge_store
);
476 static int sysfs_set_active_low(struct gpio_desc
*desc
, struct device
*dev
,
481 if (!!test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) == !!value
)
485 set_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
487 clear_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
489 /* reconfigure poll(2) support if enabled on one edge only */
490 if (dev
!= NULL
&& (!!test_bit(FLAG_TRIG_RISE
, &desc
->flags
) ^
491 !!test_bit(FLAG_TRIG_FALL
, &desc
->flags
))) {
492 unsigned long trigger_flags
= desc
->flags
& GPIO_TRIGGER_MASK
;
494 gpio_setup_irq(desc
, dev
, 0);
495 status
= gpio_setup_irq(desc
, dev
, trigger_flags
);
501 static ssize_t
gpio_active_low_show(struct device
*dev
,
502 struct device_attribute
*attr
, char *buf
)
504 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
507 mutex_lock(&sysfs_lock
);
509 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
512 status
= sprintf(buf
, "%d\n",
513 !!test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
));
515 mutex_unlock(&sysfs_lock
);
520 static ssize_t
gpio_active_low_store(struct device
*dev
,
521 struct device_attribute
*attr
, const char *buf
, size_t size
)
523 struct gpio_desc
*desc
= dev_get_drvdata(dev
);
526 mutex_lock(&sysfs_lock
);
528 if (!test_bit(FLAG_EXPORT
, &desc
->flags
)) {
533 status
= strict_strtol(buf
, 0, &value
);
535 status
= sysfs_set_active_low(desc
, dev
, value
!= 0);
538 mutex_unlock(&sysfs_lock
);
540 return status
? : size
;
543 static const DEVICE_ATTR(active_low
, 0644,
544 gpio_active_low_show
, gpio_active_low_store
);
546 static const struct attribute
*gpio_attrs
[] = {
547 &dev_attr_value
.attr
,
548 &dev_attr_active_low
.attr
,
552 static const struct attribute_group gpio_attr_group
= {
553 .attrs
= (struct attribute
**) gpio_attrs
,
557 * /sys/class/gpio/gpiochipN/
558 * /base ... matching gpio_chip.base (N)
559 * /label ... matching gpio_chip.label
560 * /ngpio ... matching gpio_chip.ngpio
563 static ssize_t
chip_base_show(struct device
*dev
,
564 struct device_attribute
*attr
, char *buf
)
566 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
568 return sprintf(buf
, "%d\n", chip
->base
);
570 static DEVICE_ATTR(base
, 0444, chip_base_show
, NULL
);
572 static ssize_t
chip_label_show(struct device
*dev
,
573 struct device_attribute
*attr
, char *buf
)
575 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
577 return sprintf(buf
, "%s\n", chip
->label
? : "");
579 static DEVICE_ATTR(label
, 0444, chip_label_show
, NULL
);
581 static ssize_t
chip_ngpio_show(struct device
*dev
,
582 struct device_attribute
*attr
, char *buf
)
584 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
586 return sprintf(buf
, "%u\n", chip
->ngpio
);
588 static DEVICE_ATTR(ngpio
, 0444, chip_ngpio_show
, NULL
);
590 static const struct attribute
*gpiochip_attrs
[] = {
592 &dev_attr_label
.attr
,
593 &dev_attr_ngpio
.attr
,
597 static const struct attribute_group gpiochip_attr_group
= {
598 .attrs
= (struct attribute
**) gpiochip_attrs
,
602 * /sys/class/gpio/export ... write-only
603 * integer N ... number of GPIO to export (full access)
604 * /sys/class/gpio/unexport ... write-only
605 * integer N ... number of GPIO to unexport
607 static ssize_t
export_store(struct class *class,
608 struct class_attribute
*attr
,
609 const char *buf
, size_t len
)
614 status
= strict_strtol(buf
, 0, &gpio
);
618 /* No extra locking here; FLAG_SYSFS just signifies that the
619 * request and export were done by on behalf of userspace, so
620 * they may be undone on its behalf too.
623 status
= gpio_request(gpio
, "sysfs");
627 status
= gpio_export(gpio
, true);
631 set_bit(FLAG_SYSFS
, &gpio_desc
[gpio
].flags
);
635 pr_debug("%s: status %d\n", __func__
, status
);
636 return status
? : len
;
639 static ssize_t
unexport_store(struct class *class,
640 struct class_attribute
*attr
,
641 const char *buf
, size_t len
)
646 status
= strict_strtol(buf
, 0, &gpio
);
652 /* reject bogus commands (gpio_unexport ignores them) */
653 if (!gpio_is_valid(gpio
))
656 /* No extra locking here; FLAG_SYSFS just signifies that the
657 * request and export were done by on behalf of userspace, so
658 * they may be undone on its behalf too.
660 if (test_and_clear_bit(FLAG_SYSFS
, &gpio_desc
[gpio
].flags
)) {
666 pr_debug("%s: status %d\n", __func__
, status
);
667 return status
? : len
;
670 static struct class_attribute gpio_class_attrs
[] = {
671 __ATTR(export
, 0200, NULL
, export_store
),
672 __ATTR(unexport
, 0200, NULL
, unexport_store
),
676 static struct class gpio_class
= {
678 .owner
= THIS_MODULE
,
680 .class_attrs
= gpio_class_attrs
,
685 * gpio_export - export a GPIO through sysfs
686 * @gpio: gpio to make available, already requested
687 * @direction_may_change: true if userspace may change gpio direction
688 * Context: arch_initcall or later
690 * When drivers want to make a GPIO accessible to userspace after they
691 * have requested it -- perhaps while debugging, or as part of their
692 * public interface -- they may use this routine. If the GPIO can
693 * change direction (some can't) and the caller allows it, userspace
694 * will see "direction" sysfs attribute which may be used to change
695 * the gpio's direction. A "value" attribute will always be provided.
697 * Returns zero on success, else an error.
699 int gpio_export(unsigned gpio
, bool direction_may_change
)
702 struct gpio_desc
*desc
;
703 int status
= -EINVAL
;
704 const char *ioname
= NULL
;
706 /* can't export until sysfs is available ... */
708 pr_debug("%s: called too early!\n", __func__
);
712 if (!gpio_is_valid(gpio
))
715 mutex_lock(&sysfs_lock
);
717 spin_lock_irqsave(&gpio_lock
, flags
);
718 desc
= &gpio_desc
[gpio
];
719 if (test_bit(FLAG_REQUESTED
, &desc
->flags
)
720 && !test_bit(FLAG_EXPORT
, &desc
->flags
)) {
722 if (!desc
->chip
->direction_input
723 || !desc
->chip
->direction_output
)
724 direction_may_change
= false;
726 spin_unlock_irqrestore(&gpio_lock
, flags
);
728 if (desc
->chip
->names
&& desc
->chip
->names
[gpio
- desc
->chip
->base
])
729 ioname
= desc
->chip
->names
[gpio
- desc
->chip
->base
];
734 dev
= device_create(&gpio_class
, desc
->chip
->dev
, MKDEV(0, 0),
735 desc
, ioname
? ioname
: "gpio%u", gpio
);
737 status
= sysfs_create_group(&dev
->kobj
,
740 if (!status
&& direction_may_change
)
741 status
= device_create_file(dev
,
742 &dev_attr_direction
);
744 if (!status
&& gpio_to_irq(gpio
) >= 0
745 && (direction_may_change
746 || !test_bit(FLAG_IS_OUT
,
748 status
= device_create_file(dev
,
752 device_unregister(dev
);
754 status
= PTR_ERR(dev
);
756 set_bit(FLAG_EXPORT
, &desc
->flags
);
759 mutex_unlock(&sysfs_lock
);
763 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
767 EXPORT_SYMBOL_GPL(gpio_export
);
769 static int match_export(struct device
*dev
, void *data
)
771 return dev_get_drvdata(dev
) == data
;
775 * gpio_export_link - create a sysfs link to an exported GPIO node
776 * @dev: device under which to create symlink
777 * @name: name of the symlink
778 * @gpio: gpio to create symlink to, already exported
780 * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN
781 * node. Caller is responsible for unlinking.
783 * Returns zero on success, else an error.
785 int gpio_export_link(struct device
*dev
, const char *name
, unsigned gpio
)
787 struct gpio_desc
*desc
;
788 int status
= -EINVAL
;
790 if (!gpio_is_valid(gpio
))
793 mutex_lock(&sysfs_lock
);
795 desc
= &gpio_desc
[gpio
];
797 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
800 tdev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
802 status
= sysfs_create_link(&dev
->kobj
, &tdev
->kobj
,
809 mutex_unlock(&sysfs_lock
);
813 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
817 EXPORT_SYMBOL_GPL(gpio_export_link
);
821 * gpio_sysfs_set_active_low - set the polarity of gpio sysfs value
822 * @gpio: gpio to change
823 * @value: non-zero to use active low, i.e. inverted values
825 * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute.
826 * The GPIO does not have to be exported yet. If poll(2) support has
827 * been enabled for either rising or falling edge, it will be
828 * reconfigured to follow the new polarity.
830 * Returns zero on success, else an error.
832 int gpio_sysfs_set_active_low(unsigned gpio
, int value
)
834 struct gpio_desc
*desc
;
835 struct device
*dev
= NULL
;
836 int status
= -EINVAL
;
838 if (!gpio_is_valid(gpio
))
841 mutex_lock(&sysfs_lock
);
843 desc
= &gpio_desc
[gpio
];
845 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
846 dev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
853 status
= sysfs_set_active_low(desc
, dev
, value
);
856 mutex_unlock(&sysfs_lock
);
860 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
864 EXPORT_SYMBOL_GPL(gpio_sysfs_set_active_low
);
867 * gpio_unexport - reverse effect of gpio_export()
868 * @gpio: gpio to make unavailable
870 * This is implicit on gpio_free().
872 void gpio_unexport(unsigned gpio
)
874 struct gpio_desc
*desc
;
876 struct device
*dev
= NULL
;
878 if (!gpio_is_valid(gpio
)) {
883 mutex_lock(&sysfs_lock
);
885 desc
= &gpio_desc
[gpio
];
887 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
889 dev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
891 gpio_setup_irq(desc
, dev
, 0);
892 clear_bit(FLAG_EXPORT
, &desc
->flags
);
897 mutex_unlock(&sysfs_lock
);
899 device_unregister(dev
);
904 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
906 EXPORT_SYMBOL_GPL(gpio_unexport
);
908 static int gpiochip_export(struct gpio_chip
*chip
)
913 /* Many systems register gpio chips for SOC support very early,
914 * before driver model support is available. In those cases we
915 * export this later, in gpiolib_sysfs_init() ... here we just
916 * verify that _some_ field of gpio_class got initialized.
921 /* use chip->base for the ID; it's already known to be unique */
922 mutex_lock(&sysfs_lock
);
923 dev
= device_create(&gpio_class
, chip
->dev
, MKDEV(0, 0), chip
,
924 "gpiochip%d", chip
->base
);
926 status
= sysfs_create_group(&dev
->kobj
,
927 &gpiochip_attr_group
);
929 status
= PTR_ERR(dev
);
930 chip
->exported
= (status
== 0);
931 mutex_unlock(&sysfs_lock
);
937 spin_lock_irqsave(&gpio_lock
, flags
);
939 while (gpio_desc
[gpio
].chip
== chip
)
940 gpio_desc
[gpio
++].chip
= NULL
;
941 spin_unlock_irqrestore(&gpio_lock
, flags
);
943 pr_debug("%s: chip %s status %d\n", __func__
,
944 chip
->label
, status
);
950 static void gpiochip_unexport(struct gpio_chip
*chip
)
955 mutex_lock(&sysfs_lock
);
956 dev
= class_find_device(&gpio_class
, NULL
, chip
, match_export
);
959 device_unregister(dev
);
964 mutex_unlock(&sysfs_lock
);
967 pr_debug("%s: chip %s status %d\n", __func__
,
968 chip
->label
, status
);
971 static int __init
gpiolib_sysfs_init(void)
977 status
= class_register(&gpio_class
);
981 /* Scan and register the gpio_chips which registered very
982 * early (e.g. before the class_register above was called).
984 * We run before arch_initcall() so chip->dev nodes can have
985 * registered, and so arch_initcall() can always gpio_export().
987 spin_lock_irqsave(&gpio_lock
, flags
);
988 for (gpio
= 0; gpio
< ARCH_NR_GPIOS
; gpio
++) {
989 struct gpio_chip
*chip
;
991 chip
= gpio_desc
[gpio
].chip
;
992 if (!chip
|| chip
->exported
)
995 spin_unlock_irqrestore(&gpio_lock
, flags
);
996 status
= gpiochip_export(chip
);
997 spin_lock_irqsave(&gpio_lock
, flags
);
999 spin_unlock_irqrestore(&gpio_lock
, flags
);
1004 postcore_initcall(gpiolib_sysfs_init
);
1007 static inline int gpiochip_export(struct gpio_chip
*chip
)
1012 static inline void gpiochip_unexport(struct gpio_chip
*chip
)
1016 #endif /* CONFIG_GPIO_SYSFS */
1019 * gpiochip_add() - register a gpio_chip
1020 * @chip: the chip to register, with chip->base initialized
1021 * Context: potentially before irqs or kmalloc will work
1023 * Returns a negative errno if the chip can't be registered, such as
1024 * because the chip->base is invalid or already associated with a
1025 * different chip. Otherwise it returns zero as a success code.
1027 * When gpiochip_add() is called very early during boot, so that GPIOs
1028 * can be freely used, the chip->dev device must be registered before
1029 * the gpio framework's arch_initcall(). Otherwise sysfs initialization
1030 * for GPIOs will fail rudely.
1032 * If chip->base is negative, this requests dynamic assignment of
1033 * a range of valid GPIOs.
1035 int gpiochip_add(struct gpio_chip
*chip
)
1037 unsigned long flags
;
1040 int base
= chip
->base
;
1042 if ((!gpio_is_valid(base
) || !gpio_is_valid(base
+ chip
->ngpio
- 1))
1048 spin_lock_irqsave(&gpio_lock
, flags
);
1051 base
= gpiochip_find_base(chip
->ngpio
);
1059 /* these GPIO numbers must not be managed by another gpio_chip */
1060 for (id
= base
; id
< base
+ chip
->ngpio
; id
++) {
1061 if (gpio_desc
[id
].chip
!= NULL
) {
1067 for (id
= base
; id
< base
+ chip
->ngpio
; id
++) {
1068 gpio_desc
[id
].chip
= chip
;
1070 /* REVISIT: most hardware initializes GPIOs as
1071 * inputs (often with pullups enabled) so power
1072 * usage is minimized. Linux code should set the
1073 * gpio direction first thing; but until it does,
1074 * we may expose the wrong direction in sysfs.
1076 gpio_desc
[id
].flags
= !chip
->direction_input
1077 ? (1 << FLAG_IS_OUT
)
1082 of_gpiochip_add(chip
);
1085 spin_unlock_irqrestore(&gpio_lock
, flags
);
1090 status
= gpiochip_export(chip
);
1094 pr_info("gpiochip_add: registered GPIOs %d to %d on device: %s\n",
1095 chip
->base
, chip
->base
+ chip
->ngpio
- 1,
1096 chip
->label
? : "generic");
1100 /* failures here can mean systems won't boot... */
1101 pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n",
1102 chip
->base
, chip
->base
+ chip
->ngpio
- 1,
1103 chip
->label
? : "generic");
1106 EXPORT_SYMBOL_GPL(gpiochip_add
);
1109 * gpiochip_remove() - unregister a gpio_chip
1110 * @chip: the chip to unregister
1112 * A gpio_chip with any GPIOs still requested may not be removed.
1114 int gpiochip_remove(struct gpio_chip
*chip
)
1116 unsigned long flags
;
1120 spin_lock_irqsave(&gpio_lock
, flags
);
1122 of_gpiochip_remove(chip
);
1124 for (id
= chip
->base
; id
< chip
->base
+ chip
->ngpio
; id
++) {
1125 if (test_bit(FLAG_REQUESTED
, &gpio_desc
[id
].flags
)) {
1131 for (id
= chip
->base
; id
< chip
->base
+ chip
->ngpio
; id
++)
1132 gpio_desc
[id
].chip
= NULL
;
1135 spin_unlock_irqrestore(&gpio_lock
, flags
);
1138 gpiochip_unexport(chip
);
1142 EXPORT_SYMBOL_GPL(gpiochip_remove
);
1145 * gpiochip_find() - iterator for locating a specific gpio_chip
1146 * @data: data to pass to match function
1147 * @callback: Callback function to check gpio_chip
1149 * Similar to bus_find_device. It returns a reference to a gpio_chip as
1150 * determined by a user supplied @match callback. The callback should return
1151 * 0 if the device doesn't match and non-zero if it does. If the callback is
1152 * non-zero, this function will return to the caller and not iterate over any
1155 struct gpio_chip
*gpiochip_find(const void *data
,
1156 int (*match
)(struct gpio_chip
*chip
,
1159 struct gpio_chip
*chip
= NULL
;
1160 unsigned long flags
;
1163 spin_lock_irqsave(&gpio_lock
, flags
);
1164 for (i
= 0; i
< ARCH_NR_GPIOS
; i
++) {
1165 if (!gpio_desc
[i
].chip
)
1168 if (match(gpio_desc
[i
].chip
, data
)) {
1169 chip
= gpio_desc
[i
].chip
;
1173 spin_unlock_irqrestore(&gpio_lock
, flags
);
1177 EXPORT_SYMBOL_GPL(gpiochip_find
);
1179 /* These "optional" allocation calls help prevent drivers from stomping
1180 * on each other, and help provide better diagnostics in debugfs.
1181 * They're called even less than the "set direction" calls.
1183 int gpio_request(unsigned gpio
, const char *label
)
1185 struct gpio_desc
*desc
;
1186 struct gpio_chip
*chip
;
1187 int status
= -EINVAL
;
1188 unsigned long flags
;
1190 spin_lock_irqsave(&gpio_lock
, flags
);
1192 if (!gpio_is_valid(gpio
))
1194 desc
= &gpio_desc
[gpio
];
1199 if (!try_module_get(chip
->owner
))
1202 /* NOTE: gpio_request() can be called in early boot,
1203 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
1206 if (test_and_set_bit(FLAG_REQUESTED
, &desc
->flags
) == 0) {
1207 desc_set_label(desc
, label
? : "?");
1211 module_put(chip
->owner
);
1215 if (chip
->request
) {
1216 /* chip->request may sleep */
1217 spin_unlock_irqrestore(&gpio_lock
, flags
);
1218 status
= chip
->request(chip
, gpio
- chip
->base
);
1219 spin_lock_irqsave(&gpio_lock
, flags
);
1222 desc_set_label(desc
, NULL
);
1223 module_put(chip
->owner
);
1224 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
1230 pr_debug("gpio_request: gpio-%d (%s) status %d\n",
1231 gpio
, label
? : "?", status
);
1232 spin_unlock_irqrestore(&gpio_lock
, flags
);
1235 EXPORT_SYMBOL_GPL(gpio_request
);
1237 void gpio_free(unsigned gpio
)
1239 unsigned long flags
;
1240 struct gpio_desc
*desc
;
1241 struct gpio_chip
*chip
;
1245 if (!gpio_is_valid(gpio
)) {
1246 WARN_ON(extra_checks
);
1250 gpio_unexport(gpio
);
1252 spin_lock_irqsave(&gpio_lock
, flags
);
1254 desc
= &gpio_desc
[gpio
];
1256 if (chip
&& test_bit(FLAG_REQUESTED
, &desc
->flags
)) {
1258 spin_unlock_irqrestore(&gpio_lock
, flags
);
1259 might_sleep_if(chip
->can_sleep
);
1260 chip
->free(chip
, gpio
- chip
->base
);
1261 spin_lock_irqsave(&gpio_lock
, flags
);
1263 desc_set_label(desc
, NULL
);
1264 module_put(desc
->chip
->owner
);
1265 clear_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
1266 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
1268 WARN_ON(extra_checks
);
1270 spin_unlock_irqrestore(&gpio_lock
, flags
);
1272 EXPORT_SYMBOL_GPL(gpio_free
);
1275 * gpio_request_one - request a single GPIO with initial configuration
1276 * @gpio: the GPIO number
1277 * @flags: GPIO configuration as specified by GPIOF_*
1278 * @label: a literal description string of this GPIO
1280 int gpio_request_one(unsigned gpio
, unsigned long flags
, const char *label
)
1284 err
= gpio_request(gpio
, label
);
1288 if (flags
& GPIOF_DIR_IN
)
1289 err
= gpio_direction_input(gpio
);
1291 err
= gpio_direction_output(gpio
,
1292 (flags
& GPIOF_INIT_HIGH
) ? 1 : 0);
1299 EXPORT_SYMBOL_GPL(gpio_request_one
);
1302 * gpio_request_array - request multiple GPIOs in a single call
1303 * @array: array of the 'struct gpio'
1304 * @num: how many GPIOs in the array
1306 int gpio_request_array(const struct gpio
*array
, size_t num
)
1310 for (i
= 0; i
< num
; i
++, array
++) {
1311 err
= gpio_request_one(array
->gpio
, array
->flags
, array
->label
);
1319 gpio_free((--array
)->gpio
);
1322 EXPORT_SYMBOL_GPL(gpio_request_array
);
1325 * gpio_free_array - release multiple GPIOs in a single call
1326 * @array: array of the 'struct gpio'
1327 * @num: how many GPIOs in the array
1329 void gpio_free_array(const struct gpio
*array
, size_t num
)
1332 gpio_free((array
++)->gpio
);
1334 EXPORT_SYMBOL_GPL(gpio_free_array
);
1337 * gpiochip_is_requested - return string iff signal was requested
1338 * @chip: controller managing the signal
1339 * @offset: of signal within controller's 0..(ngpio - 1) range
1341 * Returns NULL if the GPIO is not currently requested, else a string.
1342 * If debugfs support is enabled, the string returned is the label passed
1343 * to gpio_request(); otherwise it is a meaningless constant.
1345 * This function is for use by GPIO controller drivers. The label can
1346 * help with diagnostics, and knowing that the signal is used as a GPIO
1347 * can help avoid accidentally multiplexing it to another controller.
1349 const char *gpiochip_is_requested(struct gpio_chip
*chip
, unsigned offset
)
1351 unsigned gpio
= chip
->base
+ offset
;
1353 if (!gpio_is_valid(gpio
) || gpio_desc
[gpio
].chip
!= chip
)
1355 if (test_bit(FLAG_REQUESTED
, &gpio_desc
[gpio
].flags
) == 0)
1357 #ifdef CONFIG_DEBUG_FS
1358 return gpio_desc
[gpio
].label
;
1363 EXPORT_SYMBOL_GPL(gpiochip_is_requested
);
1366 /* Drivers MUST set GPIO direction before making get/set calls. In
1367 * some cases this is done in early boot, before IRQs are enabled.
1369 * As a rule these aren't called more than once (except for drivers
1370 * using the open-drain emulation idiom) so these are natural places
1371 * to accumulate extra debugging checks. Note that we can't (yet)
1372 * rely on gpio_request() having been called beforehand.
1375 int gpio_direction_input(unsigned gpio
)
1377 unsigned long flags
;
1378 struct gpio_chip
*chip
;
1379 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1380 int status
= -EINVAL
;
1382 spin_lock_irqsave(&gpio_lock
, flags
);
1384 if (!gpio_is_valid(gpio
))
1387 if (!chip
|| !chip
->get
|| !chip
->direction_input
)
1390 if (gpio
>= chip
->ngpio
)
1392 status
= gpio_ensure_requested(desc
, gpio
);
1396 /* now we know the gpio is valid and chip won't vanish */
1398 spin_unlock_irqrestore(&gpio_lock
, flags
);
1400 might_sleep_if(chip
->can_sleep
);
1403 status
= chip
->request(chip
, gpio
);
1405 pr_debug("GPIO-%d: chip request fail, %d\n",
1406 chip
->base
+ gpio
, status
);
1407 /* and it's not available to anyone else ...
1408 * gpio_request() is the fully clean solution.
1414 status
= chip
->direction_input(chip
, gpio
);
1416 clear_bit(FLAG_IS_OUT
, &desc
->flags
);
1418 trace_gpio_direction(chip
->base
+ gpio
, 1, status
);
1422 spin_unlock_irqrestore(&gpio_lock
, flags
);
1424 pr_debug("%s: gpio-%d status %d\n",
1425 __func__
, gpio
, status
);
1428 EXPORT_SYMBOL_GPL(gpio_direction_input
);
1430 int gpio_direction_output(unsigned gpio
, int value
)
1432 unsigned long flags
;
1433 struct gpio_chip
*chip
;
1434 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1435 int status
= -EINVAL
;
1437 spin_lock_irqsave(&gpio_lock
, flags
);
1439 if (!gpio_is_valid(gpio
))
1442 if (!chip
|| !chip
->set
|| !chip
->direction_output
)
1445 if (gpio
>= chip
->ngpio
)
1447 status
= gpio_ensure_requested(desc
, gpio
);
1451 /* now we know the gpio is valid and chip won't vanish */
1453 spin_unlock_irqrestore(&gpio_lock
, flags
);
1455 might_sleep_if(chip
->can_sleep
);
1458 status
= chip
->request(chip
, gpio
);
1460 pr_debug("GPIO-%d: chip request fail, %d\n",
1461 chip
->base
+ gpio
, status
);
1462 /* and it's not available to anyone else ...
1463 * gpio_request() is the fully clean solution.
1469 status
= chip
->direction_output(chip
, gpio
, value
);
1471 set_bit(FLAG_IS_OUT
, &desc
->flags
);
1472 trace_gpio_value(chip
->base
+ gpio
, 0, value
);
1473 trace_gpio_direction(chip
->base
+ gpio
, 0, status
);
1477 spin_unlock_irqrestore(&gpio_lock
, flags
);
1479 pr_debug("%s: gpio-%d status %d\n",
1480 __func__
, gpio
, status
);
1483 EXPORT_SYMBOL_GPL(gpio_direction_output
);
1486 * gpio_set_debounce - sets @debounce time for a @gpio
1487 * @gpio: the gpio to set debounce time
1488 * @debounce: debounce time is microseconds
1490 int gpio_set_debounce(unsigned gpio
, unsigned debounce
)
1492 unsigned long flags
;
1493 struct gpio_chip
*chip
;
1494 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1495 int status
= -EINVAL
;
1497 spin_lock_irqsave(&gpio_lock
, flags
);
1499 if (!gpio_is_valid(gpio
))
1502 if (!chip
|| !chip
->set
|| !chip
->set_debounce
)
1505 if (gpio
>= chip
->ngpio
)
1507 status
= gpio_ensure_requested(desc
, gpio
);
1511 /* now we know the gpio is valid and chip won't vanish */
1513 spin_unlock_irqrestore(&gpio_lock
, flags
);
1515 might_sleep_if(chip
->can_sleep
);
1517 return chip
->set_debounce(chip
, gpio
, debounce
);
1520 spin_unlock_irqrestore(&gpio_lock
, flags
);
1522 pr_debug("%s: gpio-%d status %d\n",
1523 __func__
, gpio
, status
);
1527 EXPORT_SYMBOL_GPL(gpio_set_debounce
);
1529 /* I/O calls are only valid after configuration completed; the relevant
1530 * "is this a valid GPIO" error checks should already have been done.
1532 * "Get" operations are often inlinable as reading a pin value register,
1533 * and masking the relevant bit in that register.
1535 * When "set" operations are inlinable, they involve writing that mask to
1536 * one register to set a low value, or a different register to set it high.
1537 * Otherwise locking is needed, so there may be little value to inlining.
1539 *------------------------------------------------------------------------
1541 * IMPORTANT!!! The hot paths -- get/set value -- assume that callers
1542 * have requested the GPIO. That can include implicit requesting by
1543 * a direction setting call. Marking a gpio as requested locks its chip
1544 * in memory, guaranteeing that these table lookups need no more locking
1545 * and that gpiochip_remove() will fail.
1547 * REVISIT when debugging, consider adding some instrumentation to ensure
1548 * that the GPIO was actually requested.
1552 * __gpio_get_value() - return a gpio's value
1553 * @gpio: gpio whose value will be returned
1556 * This is used directly or indirectly to implement gpio_get_value().
1557 * It returns the zero or nonzero value provided by the associated
1558 * gpio_chip.get() method; or zero if no such method is provided.
1560 int __gpio_get_value(unsigned gpio
)
1562 struct gpio_chip
*chip
;
1565 chip
= gpio_to_chip(gpio
);
1566 WARN_ON(chip
->can_sleep
);
1567 value
= chip
->get
? chip
->get(chip
, gpio
- chip
->base
) : 0;
1568 trace_gpio_value(gpio
, 1, value
);
1571 EXPORT_SYMBOL_GPL(__gpio_get_value
);
1574 * __gpio_set_value() - assign a gpio's value
1575 * @gpio: gpio whose value will be assigned
1576 * @value: value to assign
1579 * This is used directly or indirectly to implement gpio_set_value().
1580 * It invokes the associated gpio_chip.set() method.
1582 void __gpio_set_value(unsigned gpio
, int value
)
1584 struct gpio_chip
*chip
;
1586 chip
= gpio_to_chip(gpio
);
1587 WARN_ON(chip
->can_sleep
);
1588 trace_gpio_value(gpio
, 0, value
);
1589 chip
->set(chip
, gpio
- chip
->base
, value
);
1591 EXPORT_SYMBOL_GPL(__gpio_set_value
);
1594 * __gpio_cansleep() - report whether gpio value access will sleep
1595 * @gpio: gpio in question
1598 * This is used directly or indirectly to implement gpio_cansleep(). It
1599 * returns nonzero if access reading or writing the GPIO value can sleep.
1601 int __gpio_cansleep(unsigned gpio
)
1603 struct gpio_chip
*chip
;
1605 /* only call this on GPIOs that are valid! */
1606 chip
= gpio_to_chip(gpio
);
1608 return chip
->can_sleep
;
1610 EXPORT_SYMBOL_GPL(__gpio_cansleep
);
1613 * __gpio_to_irq() - return the IRQ corresponding to a GPIO
1614 * @gpio: gpio whose IRQ will be returned (already requested)
1617 * This is used directly or indirectly to implement gpio_to_irq().
1618 * It returns the number of the IRQ signaled by this (input) GPIO,
1619 * or a negative errno.
1621 int __gpio_to_irq(unsigned gpio
)
1623 struct gpio_chip
*chip
;
1625 chip
= gpio_to_chip(gpio
);
1626 return chip
->to_irq
? chip
->to_irq(chip
, gpio
- chip
->base
) : -ENXIO
;
1628 EXPORT_SYMBOL_GPL(__gpio_to_irq
);
1632 /* There's no value in making it easy to inline GPIO calls that may sleep.
1633 * Common examples include ones connected to I2C or SPI chips.
1636 int gpio_get_value_cansleep(unsigned gpio
)
1638 struct gpio_chip
*chip
;
1641 might_sleep_if(extra_checks
);
1642 chip
= gpio_to_chip(gpio
);
1643 value
= chip
->get
? chip
->get(chip
, gpio
- chip
->base
) : 0;
1644 trace_gpio_value(gpio
, 1, value
);
1647 EXPORT_SYMBOL_GPL(gpio_get_value_cansleep
);
1649 void gpio_set_value_cansleep(unsigned gpio
, int value
)
1651 struct gpio_chip
*chip
;
1653 might_sleep_if(extra_checks
);
1654 chip
= gpio_to_chip(gpio
);
1655 trace_gpio_value(gpio
, 0, value
);
1656 chip
->set(chip
, gpio
- chip
->base
, value
);
1658 EXPORT_SYMBOL_GPL(gpio_set_value_cansleep
);
1661 #ifdef CONFIG_DEBUG_FS
1663 static void gpiolib_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
1666 unsigned gpio
= chip
->base
;
1667 struct gpio_desc
*gdesc
= &gpio_desc
[gpio
];
1670 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++, gdesc
++) {
1671 if (!test_bit(FLAG_REQUESTED
, &gdesc
->flags
))
1674 is_out
= test_bit(FLAG_IS_OUT
, &gdesc
->flags
);
1675 seq_printf(s
, " gpio-%-3d (%-20.20s) %s %s",
1677 is_out
? "out" : "in ",
1679 ? (chip
->get(chip
, i
) ? "hi" : "lo")
1681 seq_printf(s
, "\n");
1685 static int gpiolib_show(struct seq_file
*s
, void *unused
)
1687 struct gpio_chip
*chip
= NULL
;
1691 /* REVISIT this isn't locked against gpio_chip removal ... */
1693 for (gpio
= 0; gpio_is_valid(gpio
); gpio
++) {
1696 if (chip
== gpio_desc
[gpio
].chip
)
1698 chip
= gpio_desc
[gpio
].chip
;
1702 seq_printf(s
, "%sGPIOs %d-%d",
1703 started
? "\n" : "",
1704 chip
->base
, chip
->base
+ chip
->ngpio
- 1);
1707 seq_printf(s
, ", %s/%s",
1708 dev
->bus
? dev
->bus
->name
: "no-bus",
1711 seq_printf(s
, ", %s", chip
->label
);
1712 if (chip
->can_sleep
)
1713 seq_printf(s
, ", can sleep");
1714 seq_printf(s
, ":\n");
1718 chip
->dbg_show(s
, chip
);
1720 gpiolib_dbg_show(s
, chip
);
1725 static int gpiolib_open(struct inode
*inode
, struct file
*file
)
1727 return single_open(file
, gpiolib_show
, NULL
);
1730 static const struct file_operations gpiolib_operations
= {
1731 .open
= gpiolib_open
,
1733 .llseek
= seq_lseek
,
1734 .release
= single_release
,
1737 static int __init
gpiolib_debugfs_init(void)
1739 /* /sys/kernel/debug/gpio */
1740 (void) debugfs_create_file("gpio", S_IFREG
| S_IRUGO
,
1741 NULL
, NULL
, &gpiolib_operations
);
1744 subsys_initcall(gpiolib_debugfs_init
);
1746 #endif /* DEBUG_FS */