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>
16 /* Optional implementation infrastructure for GPIO interfaces.
18 * Platforms may want to use this if they tend to use very many GPIOs
19 * that aren't part of a System-On-Chip core; or across I2C/SPI/etc.
21 * When kernel footprint or instruction count is an issue, simpler
22 * implementations may be preferred. The GPIO programming interface
23 * allows for inlining speed-critical get/set operations for common
24 * cases, so that access to SOC-integrated GPIOs can sometimes cost
25 * only an instruction or two per bit.
29 /* When debugging, extend minimal trust to callers and platform code.
30 * Also emit diagnostic messages that may help initial bringup, when
31 * board setup or driver bugs are most common.
33 * Otherwise, minimize overhead in what may be bitbanging codepaths.
36 #define extra_checks 1
38 #define extra_checks 0
41 /* gpio_lock prevents conflicts during gpio_desc[] table updates.
42 * While any GPIO is requested, its gpio_chip is not removable;
43 * each GPIO's "requested" flag serves as a lock and refcount.
45 static DEFINE_SPINLOCK(gpio_lock
);
48 struct gpio_chip
*chip
;
50 /* flag symbols are bit numbers */
51 #define FLAG_REQUESTED 0
53 #define FLAG_RESERVED 2
54 #define FLAG_EXPORT 3 /* protected by sysfs_lock */
55 #define FLAG_SYSFS 4 /* exported via /sys/class/gpio/control */
56 #define FLAG_TRIG_FALL 5 /* trigger on falling edge */
57 #define FLAG_TRIG_RISE 6 /* trigger on rising edge */
58 #define FLAG_ACTIVE_LOW 7 /* sysfs value has active low */
60 #define ID_SHIFT 16 /* add new flags before this one */
62 #define GPIO_FLAGS_MASK ((1 << ID_SHIFT) - 1)
63 #define GPIO_TRIGGER_MASK (BIT(FLAG_TRIG_FALL) | BIT(FLAG_TRIG_RISE))
65 #ifdef CONFIG_DEBUG_FS
69 static struct gpio_desc gpio_desc
[ARCH_NR_GPIOS
];
71 #ifdef CONFIG_GPIO_SYSFS
72 static DEFINE_IDR(dirent_idr
);
75 static inline void desc_set_label(struct gpio_desc
*d
, const char *label
)
77 #ifdef CONFIG_DEBUG_FS
82 /* Warn when drivers omit gpio_request() calls -- legal but ill-advised
83 * when setting direction, and otherwise illegal. Until board setup code
84 * and drivers use explicit requests everywhere (which won't happen when
85 * those calls have no teeth) we can't avoid autorequesting. This nag
86 * message should motivate switching to explicit requests... so should
87 * the weaker cleanup after faults, compared to gpio_request().
89 * NOTE: the autorequest mechanism is going away; at this point it's
90 * only "legal" in the sense that (old) code using it won't break yet,
91 * but instead only triggers a WARN() stack dump.
93 static int gpio_ensure_requested(struct gpio_desc
*desc
, unsigned offset
)
95 const struct gpio_chip
*chip
= desc
->chip
;
96 const int gpio
= chip
->base
+ offset
;
98 if (WARN(test_and_set_bit(FLAG_REQUESTED
, &desc
->flags
) == 0,
99 "autorequest GPIO-%d\n", gpio
)) {
100 if (!try_module_get(chip
->owner
)) {
101 pr_err("GPIO-%d: module can't be gotten \n", gpio
);
102 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
106 desc_set_label(desc
, "[auto]");
107 /* caller must chip->request() w/o spinlock */
114 /* caller holds gpio_lock *OR* gpio is marked as requested */
115 static inline struct gpio_chip
*gpio_to_chip(unsigned gpio
)
117 return gpio_desc
[gpio
].chip
;
120 /* dynamic allocation of GPIOs, e.g. on a hotplugged device */
121 static int gpiochip_find_base(int ngpio
)
127 for (i
= ARCH_NR_GPIOS
- 1; i
>= 0 ; i
--) {
128 struct gpio_desc
*desc
= &gpio_desc
[i
];
129 struct gpio_chip
*chip
= desc
->chip
;
131 if (!chip
&& !test_bit(FLAG_RESERVED
, &desc
->flags
)) {
133 if (spare
== ngpio
) {
140 i
-= chip
->ngpio
- 1;
144 if (gpio_is_valid(base
))
145 pr_debug("%s: found new base at %d\n", __func__
, base
);
150 * gpiochip_reserve() - reserve range of gpios to use with platform code only
151 * @start: starting gpio number
152 * @ngpio: number of gpios to reserve
153 * Context: platform init, potentially before irqs or kmalloc will work
155 * Returns a negative errno if any gpio within the range is already reserved
156 * or registered, else returns zero as a success code. Use this function
157 * to mark a range of gpios as unavailable for dynamic gpio number allocation,
158 * for example because its driver support is not yet loaded.
160 int __init
gpiochip_reserve(int start
, int ngpio
)
166 if (!gpio_is_valid(start
) || !gpio_is_valid(start
+ ngpio
- 1))
169 spin_lock_irqsave(&gpio_lock
, flags
);
171 for (i
= start
; i
< start
+ ngpio
; i
++) {
172 struct gpio_desc
*desc
= &gpio_desc
[i
];
174 if (desc
->chip
|| test_bit(FLAG_RESERVED
, &desc
->flags
)) {
179 set_bit(FLAG_RESERVED
, &desc
->flags
);
182 pr_debug("%s: reserved gpios from %d to %d\n",
183 __func__
, start
, start
+ ngpio
- 1);
185 spin_unlock_irqrestore(&gpio_lock
, flags
);
190 #ifdef CONFIG_GPIO_SYSFS
192 /* lock protects against unexport_gpio() being called while
193 * sysfs files are active.
195 static DEFINE_MUTEX(sysfs_lock
);
198 * /sys/class/gpio/gpioN... only for GPIOs that are exported
200 * * MAY BE OMITTED if kernel won't allow direction changes
201 * * is read/write as "in" or "out"
202 * * may also be written as "high" or "low", initializing
203 * output value as specified ("out" implies "low")
205 * * always readable, subject to hardware behavior
206 * * may be writable, as zero/nonzero
208 * * configures behavior of poll(2) on /value
209 * * available only if pin can generate IRQs on input
210 * * is read/write as "none", "falling", "rising", or "both"
212 * * configures polarity of /value
213 * * is read/write as zero/nonzero
214 * * also affects existing and subsequent "falling" and "rising"
215 * /edge configuration
218 static ssize_t
gpio_direction_show(struct device
*dev
,
219 struct device_attribute
*attr
, char *buf
)
221 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
224 mutex_lock(&sysfs_lock
);
226 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
229 status
= sprintf(buf
, "%s\n",
230 test_bit(FLAG_IS_OUT
, &desc
->flags
)
233 mutex_unlock(&sysfs_lock
);
237 static ssize_t
gpio_direction_store(struct device
*dev
,
238 struct device_attribute
*attr
, const char *buf
, size_t size
)
240 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
241 unsigned gpio
= desc
- gpio_desc
;
244 mutex_lock(&sysfs_lock
);
246 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
248 else if (sysfs_streq(buf
, "high"))
249 status
= gpio_direction_output(gpio
, 1);
250 else if (sysfs_streq(buf
, "out") || sysfs_streq(buf
, "low"))
251 status
= gpio_direction_output(gpio
, 0);
252 else if (sysfs_streq(buf
, "in"))
253 status
= gpio_direction_input(gpio
);
257 mutex_unlock(&sysfs_lock
);
258 return status
? : size
;
261 static /* const */ DEVICE_ATTR(direction
, 0644,
262 gpio_direction_show
, gpio_direction_store
);
264 static ssize_t
gpio_value_show(struct device
*dev
,
265 struct device_attribute
*attr
, char *buf
)
267 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
268 unsigned gpio
= desc
- gpio_desc
;
271 mutex_lock(&sysfs_lock
);
273 if (!test_bit(FLAG_EXPORT
, &desc
->flags
)) {
278 value
= !!gpio_get_value_cansleep(gpio
);
279 if (test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
))
282 status
= sprintf(buf
, "%d\n", value
);
285 mutex_unlock(&sysfs_lock
);
289 static ssize_t
gpio_value_store(struct device
*dev
,
290 struct device_attribute
*attr
, const char *buf
, size_t size
)
292 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
293 unsigned gpio
= desc
- gpio_desc
;
296 mutex_lock(&sysfs_lock
);
298 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
300 else if (!test_bit(FLAG_IS_OUT
, &desc
->flags
))
305 status
= strict_strtol(buf
, 0, &value
);
307 if (test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
))
309 gpio_set_value_cansleep(gpio
, value
!= 0);
314 mutex_unlock(&sysfs_lock
);
318 static const DEVICE_ATTR(value
, 0644,
319 gpio_value_show
, gpio_value_store
);
321 static irqreturn_t
gpio_sysfs_irq(int irq
, void *priv
)
323 struct sysfs_dirent
*value_sd
= priv
;
325 sysfs_notify_dirent(value_sd
);
329 static int gpio_setup_irq(struct gpio_desc
*desc
, struct device
*dev
,
330 unsigned long gpio_flags
)
332 struct sysfs_dirent
*value_sd
;
333 unsigned long irq_flags
;
336 if ((desc
->flags
& GPIO_TRIGGER_MASK
) == gpio_flags
)
339 irq
= gpio_to_irq(desc
- gpio_desc
);
343 id
= desc
->flags
>> ID_SHIFT
;
344 value_sd
= idr_find(&dirent_idr
, id
);
346 free_irq(irq
, value_sd
);
348 desc
->flags
&= ~GPIO_TRIGGER_MASK
;
355 irq_flags
= IRQF_SHARED
;
356 if (test_bit(FLAG_TRIG_FALL
, &gpio_flags
))
357 irq_flags
|= test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) ?
358 IRQF_TRIGGER_RISING
: IRQF_TRIGGER_FALLING
;
359 if (test_bit(FLAG_TRIG_RISE
, &gpio_flags
))
360 irq_flags
|= test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) ?
361 IRQF_TRIGGER_FALLING
: IRQF_TRIGGER_RISING
;
364 value_sd
= sysfs_get_dirent(dev
->kobj
.sd
, NULL
, "value");
372 if (idr_pre_get(&dirent_idr
, GFP_KERNEL
))
373 ret
= idr_get_new_above(&dirent_idr
, value_sd
,
375 } while (ret
== -EAGAIN
);
380 desc
->flags
&= GPIO_FLAGS_MASK
;
381 desc
->flags
|= (unsigned long)id
<< ID_SHIFT
;
383 if (desc
->flags
>> ID_SHIFT
!= id
) {
389 ret
= request_any_context_irq(irq
, gpio_sysfs_irq
, irq_flags
,
390 "gpiolib", value_sd
);
394 desc
->flags
|= gpio_flags
;
398 idr_remove(&dirent_idr
, id
);
399 desc
->flags
&= GPIO_FLAGS_MASK
;
407 static const struct {
410 } trigger_types
[] = {
412 { "falling", BIT(FLAG_TRIG_FALL
) },
413 { "rising", BIT(FLAG_TRIG_RISE
) },
414 { "both", BIT(FLAG_TRIG_FALL
) | BIT(FLAG_TRIG_RISE
) },
417 static ssize_t
gpio_edge_show(struct device
*dev
,
418 struct device_attribute
*attr
, char *buf
)
420 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
423 mutex_lock(&sysfs_lock
);
425 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
431 for (i
= 0; i
< ARRAY_SIZE(trigger_types
); i
++)
432 if ((desc
->flags
& GPIO_TRIGGER_MASK
)
433 == trigger_types
[i
].flags
) {
434 status
= sprintf(buf
, "%s\n",
435 trigger_types
[i
].name
);
440 mutex_unlock(&sysfs_lock
);
444 static ssize_t
gpio_edge_store(struct device
*dev
,
445 struct device_attribute
*attr
, const char *buf
, size_t size
)
447 struct gpio_desc
*desc
= dev_get_drvdata(dev
);
451 for (i
= 0; i
< ARRAY_SIZE(trigger_types
); i
++)
452 if (sysfs_streq(trigger_types
[i
].name
, buf
))
457 mutex_lock(&sysfs_lock
);
459 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
462 status
= gpio_setup_irq(desc
, dev
, trigger_types
[i
].flags
);
467 mutex_unlock(&sysfs_lock
);
472 static DEVICE_ATTR(edge
, 0644, gpio_edge_show
, gpio_edge_store
);
474 static int sysfs_set_active_low(struct gpio_desc
*desc
, struct device
*dev
,
479 if (!!test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
) == !!value
)
483 set_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
485 clear_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
487 /* reconfigure poll(2) support if enabled on one edge only */
488 if (dev
!= NULL
&& (!!test_bit(FLAG_TRIG_RISE
, &desc
->flags
) ^
489 !!test_bit(FLAG_TRIG_FALL
, &desc
->flags
))) {
490 unsigned long trigger_flags
= desc
->flags
& GPIO_TRIGGER_MASK
;
492 gpio_setup_irq(desc
, dev
, 0);
493 status
= gpio_setup_irq(desc
, dev
, trigger_flags
);
499 static ssize_t
gpio_active_low_show(struct device
*dev
,
500 struct device_attribute
*attr
, char *buf
)
502 const struct gpio_desc
*desc
= dev_get_drvdata(dev
);
505 mutex_lock(&sysfs_lock
);
507 if (!test_bit(FLAG_EXPORT
, &desc
->flags
))
510 status
= sprintf(buf
, "%d\n",
511 !!test_bit(FLAG_ACTIVE_LOW
, &desc
->flags
));
513 mutex_unlock(&sysfs_lock
);
518 static ssize_t
gpio_active_low_store(struct device
*dev
,
519 struct device_attribute
*attr
, const char *buf
, size_t size
)
521 struct gpio_desc
*desc
= dev_get_drvdata(dev
);
524 mutex_lock(&sysfs_lock
);
526 if (!test_bit(FLAG_EXPORT
, &desc
->flags
)) {
531 status
= strict_strtol(buf
, 0, &value
);
533 status
= sysfs_set_active_low(desc
, dev
, value
!= 0);
536 mutex_unlock(&sysfs_lock
);
538 return status
? : size
;
541 static const DEVICE_ATTR(active_low
, 0644,
542 gpio_active_low_show
, gpio_active_low_store
);
544 static const struct attribute
*gpio_attrs
[] = {
545 &dev_attr_value
.attr
,
546 &dev_attr_active_low
.attr
,
550 static const struct attribute_group gpio_attr_group
= {
551 .attrs
= (struct attribute
**) gpio_attrs
,
555 * /sys/class/gpio/gpiochipN/
556 * /base ... matching gpio_chip.base (N)
557 * /label ... matching gpio_chip.label
558 * /ngpio ... matching gpio_chip.ngpio
561 static ssize_t
chip_base_show(struct device
*dev
,
562 struct device_attribute
*attr
, char *buf
)
564 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
566 return sprintf(buf
, "%d\n", chip
->base
);
568 static DEVICE_ATTR(base
, 0444, chip_base_show
, NULL
);
570 static ssize_t
chip_label_show(struct device
*dev
,
571 struct device_attribute
*attr
, char *buf
)
573 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
575 return sprintf(buf
, "%s\n", chip
->label
? : "");
577 static DEVICE_ATTR(label
, 0444, chip_label_show
, NULL
);
579 static ssize_t
chip_ngpio_show(struct device
*dev
,
580 struct device_attribute
*attr
, char *buf
)
582 const struct gpio_chip
*chip
= dev_get_drvdata(dev
);
584 return sprintf(buf
, "%u\n", chip
->ngpio
);
586 static DEVICE_ATTR(ngpio
, 0444, chip_ngpio_show
, NULL
);
588 static const struct attribute
*gpiochip_attrs
[] = {
590 &dev_attr_label
.attr
,
591 &dev_attr_ngpio
.attr
,
595 static const struct attribute_group gpiochip_attr_group
= {
596 .attrs
= (struct attribute
**) gpiochip_attrs
,
600 * /sys/class/gpio/export ... write-only
601 * integer N ... number of GPIO to export (full access)
602 * /sys/class/gpio/unexport ... write-only
603 * integer N ... number of GPIO to unexport
605 static ssize_t
export_store(struct class *class,
606 struct class_attribute
*attr
,
607 const char *buf
, size_t len
)
612 status
= strict_strtol(buf
, 0, &gpio
);
616 /* No extra locking here; FLAG_SYSFS just signifies that the
617 * request and export were done by on behalf of userspace, so
618 * they may be undone on its behalf too.
621 status
= gpio_request(gpio
, "sysfs");
625 status
= gpio_export(gpio
, true);
629 set_bit(FLAG_SYSFS
, &gpio_desc
[gpio
].flags
);
633 pr_debug("%s: status %d\n", __func__
, status
);
634 return status
? : len
;
637 static ssize_t
unexport_store(struct class *class,
638 struct class_attribute
*attr
,
639 const char *buf
, size_t len
)
644 status
= strict_strtol(buf
, 0, &gpio
);
650 /* reject bogus commands (gpio_unexport ignores them) */
651 if (!gpio_is_valid(gpio
))
654 /* No extra locking here; FLAG_SYSFS just signifies that the
655 * request and export were done by on behalf of userspace, so
656 * they may be undone on its behalf too.
658 if (test_and_clear_bit(FLAG_SYSFS
, &gpio_desc
[gpio
].flags
)) {
664 pr_debug("%s: status %d\n", __func__
, status
);
665 return status
? : len
;
668 static struct class_attribute gpio_class_attrs
[] = {
669 __ATTR(export
, 0200, NULL
, export_store
),
670 __ATTR(unexport
, 0200, NULL
, unexport_store
),
674 static struct class gpio_class
= {
676 .owner
= THIS_MODULE
,
678 .class_attrs
= gpio_class_attrs
,
683 * gpio_export - export a GPIO through sysfs
684 * @gpio: gpio to make available, already requested
685 * @direction_may_change: true if userspace may change gpio direction
686 * Context: arch_initcall or later
688 * When drivers want to make a GPIO accessible to userspace after they
689 * have requested it -- perhaps while debugging, or as part of their
690 * public interface -- they may use this routine. If the GPIO can
691 * change direction (some can't) and the caller allows it, userspace
692 * will see "direction" sysfs attribute which may be used to change
693 * the gpio's direction. A "value" attribute will always be provided.
695 * Returns zero on success, else an error.
697 int gpio_export(unsigned gpio
, bool direction_may_change
)
700 struct gpio_desc
*desc
;
701 int status
= -EINVAL
;
702 const char *ioname
= NULL
;
704 /* can't export until sysfs is available ... */
706 pr_debug("%s: called too early!\n", __func__
);
710 if (!gpio_is_valid(gpio
))
713 mutex_lock(&sysfs_lock
);
715 spin_lock_irqsave(&gpio_lock
, flags
);
716 desc
= &gpio_desc
[gpio
];
717 if (test_bit(FLAG_REQUESTED
, &desc
->flags
)
718 && !test_bit(FLAG_EXPORT
, &desc
->flags
)) {
720 if (!desc
->chip
->direction_input
721 || !desc
->chip
->direction_output
)
722 direction_may_change
= false;
724 spin_unlock_irqrestore(&gpio_lock
, flags
);
726 if (desc
->chip
->names
&& desc
->chip
->names
[gpio
- desc
->chip
->base
])
727 ioname
= desc
->chip
->names
[gpio
- desc
->chip
->base
];
732 dev
= device_create(&gpio_class
, desc
->chip
->dev
, MKDEV(0, 0),
733 desc
, ioname
? ioname
: "gpio%u", gpio
);
735 status
= sysfs_create_group(&dev
->kobj
,
738 if (!status
&& direction_may_change
)
739 status
= device_create_file(dev
,
740 &dev_attr_direction
);
742 if (!status
&& gpio_to_irq(gpio
) >= 0
743 && (direction_may_change
744 || !test_bit(FLAG_IS_OUT
,
746 status
= device_create_file(dev
,
750 device_unregister(dev
);
752 status
= PTR_ERR(dev
);
754 set_bit(FLAG_EXPORT
, &desc
->flags
);
757 mutex_unlock(&sysfs_lock
);
761 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
765 EXPORT_SYMBOL_GPL(gpio_export
);
767 static int match_export(struct device
*dev
, void *data
)
769 return dev_get_drvdata(dev
) == data
;
773 * gpio_export_link - create a sysfs link to an exported GPIO node
774 * @dev: device under which to create symlink
775 * @name: name of the symlink
776 * @gpio: gpio to create symlink to, already exported
778 * Set up a symlink from /sys/.../dev/name to /sys/class/gpio/gpioN
779 * node. Caller is responsible for unlinking.
781 * Returns zero on success, else an error.
783 int gpio_export_link(struct device
*dev
, const char *name
, unsigned gpio
)
785 struct gpio_desc
*desc
;
786 int status
= -EINVAL
;
788 if (!gpio_is_valid(gpio
))
791 mutex_lock(&sysfs_lock
);
793 desc
= &gpio_desc
[gpio
];
795 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
798 tdev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
800 status
= sysfs_create_link(&dev
->kobj
, &tdev
->kobj
,
807 mutex_unlock(&sysfs_lock
);
811 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
815 EXPORT_SYMBOL_GPL(gpio_export_link
);
819 * gpio_sysfs_set_active_low - set the polarity of gpio sysfs value
820 * @gpio: gpio to change
821 * @value: non-zero to use active low, i.e. inverted values
823 * Set the polarity of /sys/class/gpio/gpioN/value sysfs attribute.
824 * The GPIO does not have to be exported yet. If poll(2) support has
825 * been enabled for either rising or falling edge, it will be
826 * reconfigured to follow the new polarity.
828 * Returns zero on success, else an error.
830 int gpio_sysfs_set_active_low(unsigned gpio
, int value
)
832 struct gpio_desc
*desc
;
833 struct device
*dev
= NULL
;
834 int status
= -EINVAL
;
836 if (!gpio_is_valid(gpio
))
839 mutex_lock(&sysfs_lock
);
841 desc
= &gpio_desc
[gpio
];
843 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
844 dev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
851 status
= sysfs_set_active_low(desc
, dev
, value
);
854 mutex_unlock(&sysfs_lock
);
858 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
862 EXPORT_SYMBOL_GPL(gpio_sysfs_set_active_low
);
865 * gpio_unexport - reverse effect of gpio_export()
866 * @gpio: gpio to make unavailable
868 * This is implicit on gpio_free().
870 void gpio_unexport(unsigned gpio
)
872 struct gpio_desc
*desc
;
875 if (!gpio_is_valid(gpio
)) {
880 mutex_lock(&sysfs_lock
);
882 desc
= &gpio_desc
[gpio
];
884 if (test_bit(FLAG_EXPORT
, &desc
->flags
)) {
885 struct device
*dev
= NULL
;
887 dev
= class_find_device(&gpio_class
, NULL
, desc
, match_export
);
889 gpio_setup_irq(desc
, dev
, 0);
890 clear_bit(FLAG_EXPORT
, &desc
->flags
);
892 device_unregister(dev
);
897 mutex_unlock(&sysfs_lock
);
900 pr_debug("%s: gpio%d status %d\n", __func__
, gpio
, status
);
902 EXPORT_SYMBOL_GPL(gpio_unexport
);
904 static int gpiochip_export(struct gpio_chip
*chip
)
909 /* Many systems register gpio chips for SOC support very early,
910 * before driver model support is available. In those cases we
911 * export this later, in gpiolib_sysfs_init() ... here we just
912 * verify that _some_ field of gpio_class got initialized.
917 /* use chip->base for the ID; it's already known to be unique */
918 mutex_lock(&sysfs_lock
);
919 dev
= device_create(&gpio_class
, chip
->dev
, MKDEV(0, 0), chip
,
920 "gpiochip%d", chip
->base
);
922 status
= sysfs_create_group(&dev
->kobj
,
923 &gpiochip_attr_group
);
925 status
= PTR_ERR(dev
);
926 chip
->exported
= (status
== 0);
927 mutex_unlock(&sysfs_lock
);
933 spin_lock_irqsave(&gpio_lock
, flags
);
935 while (gpio_desc
[gpio
].chip
== chip
)
936 gpio_desc
[gpio
++].chip
= NULL
;
937 spin_unlock_irqrestore(&gpio_lock
, flags
);
939 pr_debug("%s: chip %s status %d\n", __func__
,
940 chip
->label
, status
);
946 static void gpiochip_unexport(struct gpio_chip
*chip
)
951 mutex_lock(&sysfs_lock
);
952 dev
= class_find_device(&gpio_class
, NULL
, chip
, match_export
);
955 device_unregister(dev
);
960 mutex_unlock(&sysfs_lock
);
963 pr_debug("%s: chip %s status %d\n", __func__
,
964 chip
->label
, status
);
967 static int __init
gpiolib_sysfs_init(void)
973 status
= class_register(&gpio_class
);
977 /* Scan and register the gpio_chips which registered very
978 * early (e.g. before the class_register above was called).
980 * We run before arch_initcall() so chip->dev nodes can have
981 * registered, and so arch_initcall() can always gpio_export().
983 spin_lock_irqsave(&gpio_lock
, flags
);
984 for (gpio
= 0; gpio
< ARCH_NR_GPIOS
; gpio
++) {
985 struct gpio_chip
*chip
;
987 chip
= gpio_desc
[gpio
].chip
;
988 if (!chip
|| chip
->exported
)
991 spin_unlock_irqrestore(&gpio_lock
, flags
);
992 status
= gpiochip_export(chip
);
993 spin_lock_irqsave(&gpio_lock
, flags
);
995 spin_unlock_irqrestore(&gpio_lock
, flags
);
1000 postcore_initcall(gpiolib_sysfs_init
);
1003 static inline int gpiochip_export(struct gpio_chip
*chip
)
1008 static inline void gpiochip_unexport(struct gpio_chip
*chip
)
1012 #endif /* CONFIG_GPIO_SYSFS */
1015 * gpiochip_add() - register a gpio_chip
1016 * @chip: the chip to register, with chip->base initialized
1017 * Context: potentially before irqs or kmalloc will work
1019 * Returns a negative errno if the chip can't be registered, such as
1020 * because the chip->base is invalid or already associated with a
1021 * different chip. Otherwise it returns zero as a success code.
1023 * When gpiochip_add() is called very early during boot, so that GPIOs
1024 * can be freely used, the chip->dev device must be registered before
1025 * the gpio framework's arch_initcall(). Otherwise sysfs initialization
1026 * for GPIOs will fail rudely.
1028 * If chip->base is negative, this requests dynamic assignment of
1029 * a range of valid GPIOs.
1031 int gpiochip_add(struct gpio_chip
*chip
)
1033 unsigned long flags
;
1036 int base
= chip
->base
;
1038 if ((!gpio_is_valid(base
) || !gpio_is_valid(base
+ chip
->ngpio
- 1))
1044 spin_lock_irqsave(&gpio_lock
, flags
);
1047 base
= gpiochip_find_base(chip
->ngpio
);
1055 /* these GPIO numbers must not be managed by another gpio_chip */
1056 for (id
= base
; id
< base
+ chip
->ngpio
; id
++) {
1057 if (gpio_desc
[id
].chip
!= NULL
) {
1063 for (id
= base
; id
< base
+ chip
->ngpio
; id
++) {
1064 gpio_desc
[id
].chip
= chip
;
1066 /* REVISIT: most hardware initializes GPIOs as
1067 * inputs (often with pullups enabled) so power
1068 * usage is minimized. Linux code should set the
1069 * gpio direction first thing; but until it does,
1070 * we may expose the wrong direction in sysfs.
1072 gpio_desc
[id
].flags
= !chip
->direction_input
1073 ? (1 << FLAG_IS_OUT
)
1078 of_gpiochip_add(chip
);
1081 spin_unlock_irqrestore(&gpio_lock
, flags
);
1086 status
= gpiochip_export(chip
);
1092 /* failures here can mean systems won't boot... */
1093 pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n",
1094 chip
->base
, chip
->base
+ chip
->ngpio
- 1,
1095 chip
->label
? : "generic");
1098 EXPORT_SYMBOL_GPL(gpiochip_add
);
1101 * gpiochip_remove() - unregister a gpio_chip
1102 * @chip: the chip to unregister
1104 * A gpio_chip with any GPIOs still requested may not be removed.
1106 int gpiochip_remove(struct gpio_chip
*chip
)
1108 unsigned long flags
;
1112 spin_lock_irqsave(&gpio_lock
, flags
);
1114 of_gpiochip_remove(chip
);
1116 for (id
= chip
->base
; id
< chip
->base
+ chip
->ngpio
; id
++) {
1117 if (test_bit(FLAG_REQUESTED
, &gpio_desc
[id
].flags
)) {
1123 for (id
= chip
->base
; id
< chip
->base
+ chip
->ngpio
; id
++)
1124 gpio_desc
[id
].chip
= NULL
;
1127 spin_unlock_irqrestore(&gpio_lock
, flags
);
1130 gpiochip_unexport(chip
);
1134 EXPORT_SYMBOL_GPL(gpiochip_remove
);
1137 * gpiochip_find() - iterator for locating a specific gpio_chip
1138 * @data: data to pass to match function
1139 * @callback: Callback function to check gpio_chip
1141 * Similar to bus_find_device. It returns a reference to a gpio_chip as
1142 * determined by a user supplied @match callback. The callback should return
1143 * 0 if the device doesn't match and non-zero if it does. If the callback is
1144 * non-zero, this function will return to the caller and not iterate over any
1147 struct gpio_chip
*gpiochip_find(void *data
,
1148 int (*match
)(struct gpio_chip
*chip
, void *data
))
1150 struct gpio_chip
*chip
= NULL
;
1151 unsigned long flags
;
1154 spin_lock_irqsave(&gpio_lock
, flags
);
1155 for (i
= 0; i
< ARCH_NR_GPIOS
; i
++) {
1156 if (!gpio_desc
[i
].chip
)
1159 if (match(gpio_desc
[i
].chip
, data
)) {
1160 chip
= gpio_desc
[i
].chip
;
1164 spin_unlock_irqrestore(&gpio_lock
, flags
);
1169 /* These "optional" allocation calls help prevent drivers from stomping
1170 * on each other, and help provide better diagnostics in debugfs.
1171 * They're called even less than the "set direction" calls.
1173 int gpio_request(unsigned gpio
, const char *label
)
1175 struct gpio_desc
*desc
;
1176 struct gpio_chip
*chip
;
1177 int status
= -EINVAL
;
1178 unsigned long flags
;
1180 spin_lock_irqsave(&gpio_lock
, flags
);
1182 if (!gpio_is_valid(gpio
))
1184 desc
= &gpio_desc
[gpio
];
1189 if (!try_module_get(chip
->owner
))
1192 /* NOTE: gpio_request() can be called in early boot,
1193 * before IRQs are enabled, for non-sleeping (SOC) GPIOs.
1196 if (test_and_set_bit(FLAG_REQUESTED
, &desc
->flags
) == 0) {
1197 desc_set_label(desc
, label
? : "?");
1201 module_put(chip
->owner
);
1205 if (chip
->request
) {
1206 /* chip->request may sleep */
1207 spin_unlock_irqrestore(&gpio_lock
, flags
);
1208 status
= chip
->request(chip
, gpio
- chip
->base
);
1209 spin_lock_irqsave(&gpio_lock
, flags
);
1212 desc_set_label(desc
, NULL
);
1213 module_put(chip
->owner
);
1214 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
1220 pr_debug("gpio_request: gpio-%d (%s) status %d\n",
1221 gpio
, label
? : "?", status
);
1222 spin_unlock_irqrestore(&gpio_lock
, flags
);
1225 EXPORT_SYMBOL_GPL(gpio_request
);
1227 void gpio_free(unsigned gpio
)
1229 unsigned long flags
;
1230 struct gpio_desc
*desc
;
1231 struct gpio_chip
*chip
;
1235 if (!gpio_is_valid(gpio
)) {
1236 WARN_ON(extra_checks
);
1240 gpio_unexport(gpio
);
1242 spin_lock_irqsave(&gpio_lock
, flags
);
1244 desc
= &gpio_desc
[gpio
];
1246 if (chip
&& test_bit(FLAG_REQUESTED
, &desc
->flags
)) {
1248 spin_unlock_irqrestore(&gpio_lock
, flags
);
1249 might_sleep_if(chip
->can_sleep
);
1250 chip
->free(chip
, gpio
- chip
->base
);
1251 spin_lock_irqsave(&gpio_lock
, flags
);
1253 desc_set_label(desc
, NULL
);
1254 module_put(desc
->chip
->owner
);
1255 clear_bit(FLAG_ACTIVE_LOW
, &desc
->flags
);
1256 clear_bit(FLAG_REQUESTED
, &desc
->flags
);
1258 WARN_ON(extra_checks
);
1260 spin_unlock_irqrestore(&gpio_lock
, flags
);
1262 EXPORT_SYMBOL_GPL(gpio_free
);
1265 * gpio_request_one - request a single GPIO with initial configuration
1266 * @gpio: the GPIO number
1267 * @flags: GPIO configuration as specified by GPIOF_*
1268 * @label: a literal description string of this GPIO
1270 int gpio_request_one(unsigned gpio
, unsigned long flags
, const char *label
)
1274 err
= gpio_request(gpio
, label
);
1278 if (flags
& GPIOF_DIR_IN
)
1279 err
= gpio_direction_input(gpio
);
1281 err
= gpio_direction_output(gpio
,
1282 (flags
& GPIOF_INIT_HIGH
) ? 1 : 0);
1289 EXPORT_SYMBOL_GPL(gpio_request_one
);
1292 * gpio_request_array - request multiple GPIOs in a single call
1293 * @array: array of the 'struct gpio'
1294 * @num: how many GPIOs in the array
1296 int gpio_request_array(struct gpio
*array
, size_t num
)
1300 for (i
= 0; i
< num
; i
++, array
++) {
1301 err
= gpio_request_one(array
->gpio
, array
->flags
, array
->label
);
1309 gpio_free((--array
)->gpio
);
1312 EXPORT_SYMBOL_GPL(gpio_request_array
);
1315 * gpio_free_array - release multiple GPIOs in a single call
1316 * @array: array of the 'struct gpio'
1317 * @num: how many GPIOs in the array
1319 void gpio_free_array(struct gpio
*array
, size_t num
)
1322 gpio_free((array
++)->gpio
);
1324 EXPORT_SYMBOL_GPL(gpio_free_array
);
1327 * gpiochip_is_requested - return string iff signal was requested
1328 * @chip: controller managing the signal
1329 * @offset: of signal within controller's 0..(ngpio - 1) range
1331 * Returns NULL if the GPIO is not currently requested, else a string.
1332 * If debugfs support is enabled, the string returned is the label passed
1333 * to gpio_request(); otherwise it is a meaningless constant.
1335 * This function is for use by GPIO controller drivers. The label can
1336 * help with diagnostics, and knowing that the signal is used as a GPIO
1337 * can help avoid accidentally multiplexing it to another controller.
1339 const char *gpiochip_is_requested(struct gpio_chip
*chip
, unsigned offset
)
1341 unsigned gpio
= chip
->base
+ offset
;
1343 if (!gpio_is_valid(gpio
) || gpio_desc
[gpio
].chip
!= chip
)
1345 if (test_bit(FLAG_REQUESTED
, &gpio_desc
[gpio
].flags
) == 0)
1347 #ifdef CONFIG_DEBUG_FS
1348 return gpio_desc
[gpio
].label
;
1353 EXPORT_SYMBOL_GPL(gpiochip_is_requested
);
1356 /* Drivers MUST set GPIO direction before making get/set calls. In
1357 * some cases this is done in early boot, before IRQs are enabled.
1359 * As a rule these aren't called more than once (except for drivers
1360 * using the open-drain emulation idiom) so these are natural places
1361 * to accumulate extra debugging checks. Note that we can't (yet)
1362 * rely on gpio_request() having been called beforehand.
1365 int gpio_direction_input(unsigned gpio
)
1367 unsigned long flags
;
1368 struct gpio_chip
*chip
;
1369 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1370 int status
= -EINVAL
;
1372 spin_lock_irqsave(&gpio_lock
, flags
);
1374 if (!gpio_is_valid(gpio
))
1377 if (!chip
|| !chip
->get
|| !chip
->direction_input
)
1380 if (gpio
>= chip
->ngpio
)
1382 status
= gpio_ensure_requested(desc
, gpio
);
1386 /* now we know the gpio is valid and chip won't vanish */
1388 spin_unlock_irqrestore(&gpio_lock
, flags
);
1390 might_sleep_if(chip
->can_sleep
);
1393 status
= chip
->request(chip
, gpio
);
1395 pr_debug("GPIO-%d: chip request fail, %d\n",
1396 chip
->base
+ gpio
, status
);
1397 /* and it's not available to anyone else ...
1398 * gpio_request() is the fully clean solution.
1404 status
= chip
->direction_input(chip
, gpio
);
1406 clear_bit(FLAG_IS_OUT
, &desc
->flags
);
1410 spin_unlock_irqrestore(&gpio_lock
, flags
);
1412 pr_debug("%s: gpio-%d status %d\n",
1413 __func__
, gpio
, status
);
1416 EXPORT_SYMBOL_GPL(gpio_direction_input
);
1418 int gpio_direction_output(unsigned gpio
, int value
)
1420 unsigned long flags
;
1421 struct gpio_chip
*chip
;
1422 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1423 int status
= -EINVAL
;
1425 spin_lock_irqsave(&gpio_lock
, flags
);
1427 if (!gpio_is_valid(gpio
))
1430 if (!chip
|| !chip
->set
|| !chip
->direction_output
)
1433 if (gpio
>= chip
->ngpio
)
1435 status
= gpio_ensure_requested(desc
, gpio
);
1439 /* now we know the gpio is valid and chip won't vanish */
1441 spin_unlock_irqrestore(&gpio_lock
, flags
);
1443 might_sleep_if(chip
->can_sleep
);
1446 status
= chip
->request(chip
, gpio
);
1448 pr_debug("GPIO-%d: chip request fail, %d\n",
1449 chip
->base
+ gpio
, status
);
1450 /* and it's not available to anyone else ...
1451 * gpio_request() is the fully clean solution.
1457 status
= chip
->direction_output(chip
, gpio
, value
);
1459 set_bit(FLAG_IS_OUT
, &desc
->flags
);
1463 spin_unlock_irqrestore(&gpio_lock
, flags
);
1465 pr_debug("%s: gpio-%d status %d\n",
1466 __func__
, gpio
, status
);
1469 EXPORT_SYMBOL_GPL(gpio_direction_output
);
1472 * gpio_set_debounce - sets @debounce time for a @gpio
1473 * @gpio: the gpio to set debounce time
1474 * @debounce: debounce time is microseconds
1476 int gpio_set_debounce(unsigned gpio
, unsigned debounce
)
1478 unsigned long flags
;
1479 struct gpio_chip
*chip
;
1480 struct gpio_desc
*desc
= &gpio_desc
[gpio
];
1481 int status
= -EINVAL
;
1483 spin_lock_irqsave(&gpio_lock
, flags
);
1485 if (!gpio_is_valid(gpio
))
1488 if (!chip
|| !chip
->set
|| !chip
->set_debounce
)
1491 if (gpio
>= chip
->ngpio
)
1493 status
= gpio_ensure_requested(desc
, gpio
);
1497 /* now we know the gpio is valid and chip won't vanish */
1499 spin_unlock_irqrestore(&gpio_lock
, flags
);
1501 might_sleep_if(chip
->can_sleep
);
1503 return chip
->set_debounce(chip
, gpio
, debounce
);
1506 spin_unlock_irqrestore(&gpio_lock
, flags
);
1508 pr_debug("%s: gpio-%d status %d\n",
1509 __func__
, gpio
, status
);
1513 EXPORT_SYMBOL_GPL(gpio_set_debounce
);
1515 /* I/O calls are only valid after configuration completed; the relevant
1516 * "is this a valid GPIO" error checks should already have been done.
1518 * "Get" operations are often inlinable as reading a pin value register,
1519 * and masking the relevant bit in that register.
1521 * When "set" operations are inlinable, they involve writing that mask to
1522 * one register to set a low value, or a different register to set it high.
1523 * Otherwise locking is needed, so there may be little value to inlining.
1525 *------------------------------------------------------------------------
1527 * IMPORTANT!!! The hot paths -- get/set value -- assume that callers
1528 * have requested the GPIO. That can include implicit requesting by
1529 * a direction setting call. Marking a gpio as requested locks its chip
1530 * in memory, guaranteeing that these table lookups need no more locking
1531 * and that gpiochip_remove() will fail.
1533 * REVISIT when debugging, consider adding some instrumentation to ensure
1534 * that the GPIO was actually requested.
1538 * __gpio_get_value() - return a gpio's value
1539 * @gpio: gpio whose value will be returned
1542 * This is used directly or indirectly to implement gpio_get_value().
1543 * It returns the zero or nonzero value provided by the associated
1544 * gpio_chip.get() method; or zero if no such method is provided.
1546 int __gpio_get_value(unsigned gpio
)
1548 struct gpio_chip
*chip
;
1550 chip
= gpio_to_chip(gpio
);
1551 WARN_ON(chip
->can_sleep
);
1552 return chip
->get
? chip
->get(chip
, gpio
- chip
->base
) : 0;
1554 EXPORT_SYMBOL_GPL(__gpio_get_value
);
1557 * __gpio_set_value() - assign a gpio's value
1558 * @gpio: gpio whose value will be assigned
1559 * @value: value to assign
1562 * This is used directly or indirectly to implement gpio_set_value().
1563 * It invokes the associated gpio_chip.set() method.
1565 void __gpio_set_value(unsigned gpio
, int value
)
1567 struct gpio_chip
*chip
;
1569 chip
= gpio_to_chip(gpio
);
1570 WARN_ON(chip
->can_sleep
);
1571 chip
->set(chip
, gpio
- chip
->base
, value
);
1573 EXPORT_SYMBOL_GPL(__gpio_set_value
);
1576 * __gpio_cansleep() - report whether gpio value access will sleep
1577 * @gpio: gpio in question
1580 * This is used directly or indirectly to implement gpio_cansleep(). It
1581 * returns nonzero if access reading or writing the GPIO value can sleep.
1583 int __gpio_cansleep(unsigned gpio
)
1585 struct gpio_chip
*chip
;
1587 /* only call this on GPIOs that are valid! */
1588 chip
= gpio_to_chip(gpio
);
1590 return chip
->can_sleep
;
1592 EXPORT_SYMBOL_GPL(__gpio_cansleep
);
1595 * __gpio_to_irq() - return the IRQ corresponding to a GPIO
1596 * @gpio: gpio whose IRQ will be returned (already requested)
1599 * This is used directly or indirectly to implement gpio_to_irq().
1600 * It returns the number of the IRQ signaled by this (input) GPIO,
1601 * or a negative errno.
1603 int __gpio_to_irq(unsigned gpio
)
1605 struct gpio_chip
*chip
;
1607 chip
= gpio_to_chip(gpio
);
1608 return chip
->to_irq
? chip
->to_irq(chip
, gpio
- chip
->base
) : -ENXIO
;
1610 EXPORT_SYMBOL_GPL(__gpio_to_irq
);
1614 /* There's no value in making it easy to inline GPIO calls that may sleep.
1615 * Common examples include ones connected to I2C or SPI chips.
1618 int gpio_get_value_cansleep(unsigned gpio
)
1620 struct gpio_chip
*chip
;
1622 might_sleep_if(extra_checks
);
1623 chip
= gpio_to_chip(gpio
);
1624 return chip
->get
? chip
->get(chip
, gpio
- chip
->base
) : 0;
1626 EXPORT_SYMBOL_GPL(gpio_get_value_cansleep
);
1628 void gpio_set_value_cansleep(unsigned gpio
, int value
)
1630 struct gpio_chip
*chip
;
1632 might_sleep_if(extra_checks
);
1633 chip
= gpio_to_chip(gpio
);
1634 chip
->set(chip
, gpio
- chip
->base
, value
);
1636 EXPORT_SYMBOL_GPL(gpio_set_value_cansleep
);
1639 #ifdef CONFIG_DEBUG_FS
1641 static void gpiolib_dbg_show(struct seq_file
*s
, struct gpio_chip
*chip
)
1644 unsigned gpio
= chip
->base
;
1645 struct gpio_desc
*gdesc
= &gpio_desc
[gpio
];
1648 for (i
= 0; i
< chip
->ngpio
; i
++, gpio
++, gdesc
++) {
1649 if (!test_bit(FLAG_REQUESTED
, &gdesc
->flags
))
1652 is_out
= test_bit(FLAG_IS_OUT
, &gdesc
->flags
);
1653 seq_printf(s
, " gpio-%-3d (%-20.20s) %s %s",
1655 is_out
? "out" : "in ",
1657 ? (chip
->get(chip
, i
) ? "hi" : "lo")
1661 int irq
= gpio_to_irq(gpio
);
1662 struct irq_desc
*desc
= irq_to_desc(irq
);
1664 /* This races with request_irq(), set_irq_type(),
1665 * and set_irq_wake() ... but those are "rare".
1667 * More significantly, trigger type flags aren't
1668 * currently maintained by genirq.
1670 if (irq
>= 0 && desc
->action
) {
1673 switch (desc
->status
& IRQ_TYPE_SENSE_MASK
) {
1675 trigger
= "(default)";
1677 case IRQ_TYPE_EDGE_FALLING
:
1678 trigger
= "edge-falling";
1680 case IRQ_TYPE_EDGE_RISING
:
1681 trigger
= "edge-rising";
1683 case IRQ_TYPE_EDGE_BOTH
:
1684 trigger
= "edge-both";
1686 case IRQ_TYPE_LEVEL_HIGH
:
1687 trigger
= "level-high";
1689 case IRQ_TYPE_LEVEL_LOW
:
1690 trigger
= "level-low";
1693 trigger
= "?trigger?";
1697 seq_printf(s
, " irq-%d %s%s",
1699 (desc
->status
& IRQ_WAKEUP
)
1704 seq_printf(s
, "\n");
1708 static int gpiolib_show(struct seq_file
*s
, void *unused
)
1710 struct gpio_chip
*chip
= NULL
;
1714 /* REVISIT this isn't locked against gpio_chip removal ... */
1716 for (gpio
= 0; gpio_is_valid(gpio
); gpio
++) {
1719 if (chip
== gpio_desc
[gpio
].chip
)
1721 chip
= gpio_desc
[gpio
].chip
;
1725 seq_printf(s
, "%sGPIOs %d-%d",
1726 started
? "\n" : "",
1727 chip
->base
, chip
->base
+ chip
->ngpio
- 1);
1730 seq_printf(s
, ", %s/%s",
1731 dev
->bus
? dev
->bus
->name
: "no-bus",
1734 seq_printf(s
, ", %s", chip
->label
);
1735 if (chip
->can_sleep
)
1736 seq_printf(s
, ", can sleep");
1737 seq_printf(s
, ":\n");
1741 chip
->dbg_show(s
, chip
);
1743 gpiolib_dbg_show(s
, chip
);
1748 static int gpiolib_open(struct inode
*inode
, struct file
*file
)
1750 return single_open(file
, gpiolib_show
, NULL
);
1753 static const struct file_operations gpiolib_operations
= {
1754 .open
= gpiolib_open
,
1756 .llseek
= seq_lseek
,
1757 .release
= single_release
,
1760 static int __init
gpiolib_debugfs_init(void)
1762 /* /sys/kernel/debug/gpio */
1763 (void) debugfs_create_file("gpio", S_IFREG
| S_IRUGO
,
1764 NULL
, NULL
, &gpiolib_operations
);
1767 subsys_initcall(gpiolib_debugfs_init
);
1769 #endif /* DEBUG_FS */