xref: /linux/drivers/pinctrl/pinmux.h (revision 746680ec6696585e30db3e18c93a63df9cbec39c)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Internal interface between the core pin control system and the
4  * pinmux portions
5  *
6  * Copyright (C) 2011 ST-Ericsson SA
7  * Written on behalf of Linaro for ST-Ericsson
8  * Based on bits of regulator core, gpio core and clk core
9  *
10  * Author: Linus Walleij <linus.walleij@linaro.org>
11  */
12 
13 #include <linux/types.h>
14 
15 struct dentry;
16 struct seq_file;
17 
18 struct pinctrl_dev;
19 struct pinctrl_gpio_range;
20 struct pinctrl_map;
21 struct pinctrl_setting;
22 
23 #ifdef CONFIG_PINMUX
24 
25 int pinmux_check_ops(struct pinctrl_dev *pctldev);
26 
27 int pinmux_validate_map(const struct pinctrl_map *map, int i);
28 
29 bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev, unsigned int pin);
30 
31 int pinmux_request_gpio(struct pinctrl_dev *pctldev,
32 			struct pinctrl_gpio_range *range,
33 			unsigned int pin, unsigned int gpio);
34 void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned int pin,
35 		      struct pinctrl_gpio_range *range);
36 int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
37 			  struct pinctrl_gpio_range *range,
38 			  unsigned int pin, bool input);
39 
40 int pinmux_map_to_setting(const struct pinctrl_map *map,
41 			  struct pinctrl_setting *setting);
42 void pinmux_free_setting(const struct pinctrl_setting *setting);
43 int pinmux_enable_setting(const struct pinctrl_setting *setting);
44 void pinmux_disable_setting(const struct pinctrl_setting *setting);
45 
46 #else
47 
48 static inline int pinmux_check_ops(struct pinctrl_dev *pctldev)
49 {
50 	return 0;
51 }
52 
53 static inline int pinmux_validate_map(const struct pinctrl_map *map, int i)
54 {
55 	return 0;
56 }
57 
58 static inline bool pinmux_can_be_used_for_gpio(struct pinctrl_dev *pctldev,
59 					       unsigned int pin)
60 {
61 	return true;
62 }
63 
64 static inline int pinmux_request_gpio(struct pinctrl_dev *pctldev,
65 			struct pinctrl_gpio_range *range,
66 			unsigned int pin, unsigned int gpio)
67 {
68 	return 0;
69 }
70 
71 static inline void pinmux_free_gpio(struct pinctrl_dev *pctldev,
72 				    unsigned int pin,
73 				    struct pinctrl_gpio_range *range)
74 {
75 }
76 
77 static inline int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
78 					struct pinctrl_gpio_range *range,
79 					unsigned int pin, bool input)
80 {
81 	return 0;
82 }
83 
84 static inline int pinmux_map_to_setting(const struct pinctrl_map *map,
85 			  struct pinctrl_setting *setting)
86 {
87 	return 0;
88 }
89 
90 static inline void pinmux_free_setting(const struct pinctrl_setting *setting)
91 {
92 }
93 
94 static inline int pinmux_enable_setting(const struct pinctrl_setting *setting)
95 {
96 	return 0;
97 }
98 
99 static inline void pinmux_disable_setting(const struct pinctrl_setting *setting)
100 {
101 }
102 
103 #endif
104 
105 #if defined(CONFIG_PINMUX) && defined(CONFIG_DEBUG_FS)
106 
107 void pinmux_show_map(struct seq_file *s, const struct pinctrl_map *map);
108 void pinmux_show_setting(struct seq_file *s,
109 			 const struct pinctrl_setting *setting);
110 void pinmux_init_device_debugfs(struct dentry *devroot,
111 				struct pinctrl_dev *pctldev);
112 
113 #else
114 
115 static inline void pinmux_show_map(struct seq_file *s,
116 				   const struct pinctrl_map *map)
117 {
118 }
119 
120 static inline void pinmux_show_setting(struct seq_file *s,
121 				       const struct pinctrl_setting *setting)
122 {
123 }
124 
125 static inline void pinmux_init_device_debugfs(struct dentry *devroot,
126 					      struct pinctrl_dev *pctldev)
127 {
128 }
129 
130 #endif
131 
132 #ifdef CONFIG_GENERIC_PINMUX_FUNCTIONS
133 
134 /**
135  * struct function_desc - generic function descriptor
136  * @func: generic data of the pin function (name and groups of pins)
137  * @data: pin controller driver specific data
138  */
139 struct function_desc {
140 	struct pinfunction func;
141 	void *data;
142 };
143 
144 int pinmux_generic_get_function_count(struct pinctrl_dev *pctldev);
145 
146 const char *
147 pinmux_generic_get_function_name(struct pinctrl_dev *pctldev,
148 				 unsigned int selector);
149 
150 int pinmux_generic_get_function_groups(struct pinctrl_dev *pctldev,
151 				       unsigned int selector,
152 				       const char * const **groups,
153 				       unsigned int * const ngroups);
154 
155 struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev,
156 						  unsigned int selector);
157 
158 int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
159 				const char *name,
160 				const char * const *groups,
161 				unsigned int const ngroups,
162 				void *data);
163 
164 int pinmux_generic_add_pinfunction(struct pinctrl_dev *pctldev,
165 				   const struct pinfunction *func, void *data);
166 
167 int pinmux_generic_remove_function(struct pinctrl_dev *pctldev,
168 				   unsigned int selector);
169 
170 void pinmux_generic_free_functions(struct pinctrl_dev *pctldev);
171 
172 #else
173 
174 static inline void pinmux_generic_free_functions(struct pinctrl_dev *pctldev)
175 {
176 }
177 
178 #endif /* CONFIG_GENERIC_PINMUX_FUNCTIONS */
179