/src/barebox/include/of_gpio.h
Line | Count | Source |
1 | | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
2 | | /* |
3 | | * OF helpers for the GPIO API |
4 | | * |
5 | | * based on Linux OF_GPIO API |
6 | | */ |
7 | | |
8 | | #ifndef __OF_GPIO_H |
9 | | #define __OF_GPIO_H |
10 | | |
11 | | #include <of.h> |
12 | | |
13 | | /* |
14 | | * This is Linux-specific flags. By default controllers' and Linux' mapping |
15 | | * match, but GPIO controllers are free to translate their own flags to |
16 | | * Linux-specific in their .xlate callback. Though, 1:1 mapping is recommended. |
17 | | */ |
18 | | enum of_gpio_flags { |
19 | | OF_GPIO_ACTIVE_LOW = 0x1, |
20 | | OF_GPIO_SINGLE_ENDED = 0x2, |
21 | | OF_GPIO_OPEN_DRAIN = 0x4, |
22 | | OF_GPIO_PULL_UP = 0x10, |
23 | | OF_GPIO_PULL_DOWN = 0x20, |
24 | | OF_GPIO_PULL_DISABLE = 0x40, |
25 | | OF_GPIO_REQUESTED = 0x80000000, /* internal use */ |
26 | | }; |
27 | | |
28 | | #ifdef CONFIG_OF_GPIO |
29 | | extern int of_get_named_gpio_flags(struct device_node *np, |
30 | | const char *list_name, int index, enum of_gpio_flags *flags); |
31 | | |
32 | | #else /* CONFIG_OF_GPIO */ |
33 | | |
34 | | static inline int of_get_named_gpio_flags(struct device_node *np, |
35 | | const char *list_name, int index, enum of_gpio_flags *flags) |
36 | | { |
37 | | return -ENOSYS; |
38 | | } |
39 | | |
40 | | #endif /* CONFIG_OF_GPIO */ |
41 | | |
42 | | /** |
43 | | * of_gpio_named_count() - Count GPIOs for a device |
44 | | * @np: device node to count GPIOs for |
45 | | * @propname: property name containing gpio specifier(s) |
46 | | * |
47 | | * The function returns the count of GPIOs specified for a node. |
48 | | * Note that the empty GPIO specifiers count too. Returns either |
49 | | * Number of gpios defined in property, |
50 | | * -EINVAL for an incorrectly formed gpios property, or |
51 | | * -ENOENT for a missing gpios property |
52 | | * |
53 | | * Example: |
54 | | * gpios = <0 |
55 | | * &gpio1 1 2 |
56 | | * 0 |
57 | | * &gpio2 3 4>; |
58 | | * |
59 | | * The above example defines four GPIOs, two of which are not specified. |
60 | | * This function will return '4' |
61 | | */ |
62 | | static inline int of_gpio_named_count(struct device_node *np, const char* propname) |
63 | 0 | { |
64 | 0 | return of_count_phandle_with_args(np, propname, "#gpio-cells"); |
65 | 0 | } Unexecuted instantiation: m25p80.c:of_gpio_named_count Unexecuted instantiation: spi.c:of_gpio_named_count Unexecuted instantiation: spi-mem.c:of_gpio_named_count Unexecuted instantiation: gpio_spi.c:of_gpio_named_count Unexecuted instantiation: i2c-gpio.c:of_gpio_named_count Unexecuted instantiation: led-gpio.c:of_gpio_named_count Unexecuted instantiation: at25.c:of_gpio_named_count Unexecuted instantiation: at24.c:of_gpio_named_count Unexecuted instantiation: gpiolib.c:of_gpio_named_count Unexecuted instantiation: of_gpio.c:of_gpio_named_count |
66 | | |
67 | | /** |
68 | | * of_gpio_count() - Count GPIOs for a device |
69 | | * @np: device node to count GPIOs for |
70 | | * |
71 | | * Same as of_gpio_named_count, but hard coded to use the 'gpios' property |
72 | | */ |
73 | | static inline int of_gpio_count(struct device_node *np) |
74 | 0 | { |
75 | 0 | return of_gpio_named_count(np, "gpios"); |
76 | 0 | } Unexecuted instantiation: m25p80.c:of_gpio_count Unexecuted instantiation: spi.c:of_gpio_count Unexecuted instantiation: spi-mem.c:of_gpio_count Unexecuted instantiation: gpio_spi.c:of_gpio_count Unexecuted instantiation: i2c-gpio.c:of_gpio_count Unexecuted instantiation: led-gpio.c:of_gpio_count Unexecuted instantiation: at25.c:of_gpio_count Unexecuted instantiation: at24.c:of_gpio_count Unexecuted instantiation: gpiolib.c:of_gpio_count Unexecuted instantiation: of_gpio.c:of_gpio_count |
77 | | |
78 | | /** |
79 | | * of_gpio_count() - Count cs-gpios for a device |
80 | | * @np: device node to count cs-gpios for |
81 | | * |
82 | | * Same as of_gpio_named_count, but hard coded to use the 'cs-gpios' property |
83 | | * Returns 0 on error |
84 | | */ |
85 | | static inline int of_gpio_count_csgpios(struct device_node *np) |
86 | 0 | { |
87 | 0 | int count = of_gpio_named_count(np, "cs-gpios"); |
88 | 0 |
|
89 | 0 | if (count > 0) |
90 | 0 | return count; |
91 | 0 | else |
92 | 0 | return 0; |
93 | 0 | } Unexecuted instantiation: m25p80.c:of_gpio_count_csgpios Unexecuted instantiation: spi.c:of_gpio_count_csgpios Unexecuted instantiation: spi-mem.c:of_gpio_count_csgpios Unexecuted instantiation: gpio_spi.c:of_gpio_count_csgpios Unexecuted instantiation: i2c-gpio.c:of_gpio_count_csgpios Unexecuted instantiation: led-gpio.c:of_gpio_count_csgpios Unexecuted instantiation: at25.c:of_gpio_count_csgpios Unexecuted instantiation: at24.c:of_gpio_count_csgpios Unexecuted instantiation: gpiolib.c:of_gpio_count_csgpios Unexecuted instantiation: of_gpio.c:of_gpio_count_csgpios |
94 | | |
95 | | static inline int of_get_gpio_flags(struct device_node *np, int index, |
96 | | enum of_gpio_flags *flags) |
97 | 0 | { |
98 | 0 | return of_get_named_gpio_flags(np, "gpios", index, flags); |
99 | 0 | } Unexecuted instantiation: m25p80.c:of_get_gpio_flags Unexecuted instantiation: spi.c:of_get_gpio_flags Unexecuted instantiation: spi-mem.c:of_get_gpio_flags Unexecuted instantiation: gpio_spi.c:of_get_gpio_flags Unexecuted instantiation: i2c-gpio.c:of_get_gpio_flags Unexecuted instantiation: led-gpio.c:of_get_gpio_flags Unexecuted instantiation: at25.c:of_get_gpio_flags Unexecuted instantiation: at24.c:of_get_gpio_flags Unexecuted instantiation: gpiolib.c:of_get_gpio_flags Unexecuted instantiation: of_gpio.c:of_get_gpio_flags |
100 | | |
101 | | static inline int of_get_named_gpio(struct device_node *np, |
102 | | const char *list_name, int index) |
103 | 0 | { |
104 | 0 | return of_get_named_gpio_flags(np, list_name, index, NULL); |
105 | 0 | } Unexecuted instantiation: m25p80.c:of_get_named_gpio Unexecuted instantiation: spi.c:of_get_named_gpio Unexecuted instantiation: spi-mem.c:of_get_named_gpio Unexecuted instantiation: gpio_spi.c:of_get_named_gpio Unexecuted instantiation: i2c-gpio.c:of_get_named_gpio Unexecuted instantiation: led-gpio.c:of_get_named_gpio Unexecuted instantiation: at25.c:of_get_named_gpio Unexecuted instantiation: at24.c:of_get_named_gpio Unexecuted instantiation: gpiolib.c:of_get_named_gpio Unexecuted instantiation: of_gpio.c:of_get_named_gpio |
106 | | |
107 | | /** |
108 | | * of_get_gpio() - Get a GPIO number to use with GPIO API |
109 | | * @np: device node to get GPIO from |
110 | | * @index: index of the GPIO |
111 | | * |
112 | | * Returns GPIO number to use with Linux generic GPIO API, or one of the errno |
113 | | * value on the error condition. |
114 | | */ |
115 | | static inline int of_get_gpio(struct device_node *np, int index) |
116 | 0 | { |
117 | 0 | return of_get_gpio_flags(np, index, NULL); |
118 | 0 | } Unexecuted instantiation: m25p80.c:of_get_gpio Unexecuted instantiation: spi.c:of_get_gpio Unexecuted instantiation: spi-mem.c:of_get_gpio Unexecuted instantiation: gpio_spi.c:of_get_gpio Unexecuted instantiation: i2c-gpio.c:of_get_gpio Unexecuted instantiation: led-gpio.c:of_get_gpio Unexecuted instantiation: at25.c:of_get_gpio Unexecuted instantiation: at24.c:of_get_gpio Unexecuted instantiation: gpiolib.c:of_get_gpio Unexecuted instantiation: of_gpio.c:of_get_gpio |
119 | | |
120 | | #endif |