xref: /openbmc/linux/drivers/pinctrl/pinmux.h (revision 2455f0e1)
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 pin);
30 
31 int pinmux_request_gpio(struct pinctrl_dev *pctldev,
32 			struct pinctrl_gpio_range *range,
33 			unsigned pin, unsigned gpio);
34 void pinmux_free_gpio(struct pinctrl_dev *pctldev, unsigned pin,
35 		      struct pinctrl_gpio_range *range);
36 int pinmux_gpio_direction(struct pinctrl_dev *pctldev,
37 			  struct pinctrl_gpio_range *range,
38 			  unsigned 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 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 pin, unsigned gpio)
67 {
68 	return 0;
69 }
70 
71 static inline void pinmux_free_gpio(struct pinctrl_dev *pctldev,
72 				    unsigned 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 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  * @name: name of the function
137  * @group_names: array of pin group names
138  * @num_group_names: number of pin group names
139  * @data: pin controller driver specific data
140  */
141 struct function_desc {
142 	const char *name;
143 	const char * const *group_names;
144 	int num_group_names;
145 	void *data;
146 };
147 
148 int pinmux_generic_get_function_count(struct pinctrl_dev *pctldev);
149 
150 const char *
151 pinmux_generic_get_function_name(struct pinctrl_dev *pctldev,
152 				 unsigned int selector);
153 
154 int pinmux_generic_get_function_groups(struct pinctrl_dev *pctldev,
155 				       unsigned int selector,
156 				       const char * const **groups,
157 				       unsigned * const num_groups);
158 
159 struct function_desc *pinmux_generic_get_function(struct pinctrl_dev *pctldev,
160 						  unsigned int selector);
161 
162 int pinmux_generic_add_function(struct pinctrl_dev *pctldev,
163 				const char *name,
164 				const char * const *groups,
165 				unsigned const num_groups,
166 				void *data);
167 
168 int pinmux_generic_remove_function(struct pinctrl_dev *pctldev,
169 				   unsigned int selector);
170 
171 void pinmux_generic_free_functions(struct pinctrl_dev *pctldev);
172 
173 #else
174 
175 static inline void pinmux_generic_free_functions(struct pinctrl_dev *pctldev)
176 {
177 }
178 
179 #endif /* CONFIG_GENERIC_PINMUX_FUNCTIONS */
180