pinctrl: GPIO direction support for muxing
[deliverable/linux.git] / include / linux / pinctrl / pinmux.h
1 /*
2 * Interface the pinmux subsystem
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * Based on bits of regulator core, gpio core and clk core
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12 #ifndef __LINUX_PINCTRL_PINMUX_H
13 #define __LINUX_PINCTRL_PINMUX_H
14
15 #include <linux/list.h>
16 #include <linux/seq_file.h>
17 #include "pinctrl.h"
18
19 /* This struct is private to the core and should be regarded as a cookie */
20 struct pinmux;
21
22 #ifdef CONFIG_PINMUX
23
24 struct pinctrl_dev;
25
26 /**
27 * struct pinmux_ops - pinmux operations, to be implemented by pin controller
28 * drivers that support pinmuxing
29 * @request: called by the core to see if a certain pin can be made available
30 * available for muxing. This is called by the core to acquire the pins
31 * before selecting any actual mux setting across a function. The driver
32 * is allowed to answer "no" by returning a negative error code
33 * @free: the reverse function of the request() callback, frees a pin after
34 * being requested
35 * @list_functions: list the number of selectable named functions available
36 * in this pinmux driver, the core will begin on 0 and call this
37 * repeatedly as long as it returns >= 0 to enumerate mux settings
38 * @get_function_name: return the function name of the muxing selector,
39 * called by the core to figure out which mux setting it shall map a
40 * certain device to
41 * @get_function_groups: return an array of groups names (in turn
42 * referencing pins) connected to a certain function selector. The group
43 * name can be used with the generic @pinctrl_ops to retrieve the
44 * actual pins affected. The applicable groups will be returned in
45 * @groups and the number of groups in @num_groups
46 * @enable: enable a certain muxing function with a certain pin group. The
47 * driver does not need to figure out whether enabling this function
48 * conflicts some other use of the pins in that group, such collisions
49 * are handled by the pinmux subsystem. The @func_selector selects a
50 * certain function whereas @group_selector selects a certain set of pins
51 * to be used. On simple controllers the latter argument may be ignored
52 * @disable: disable a certain muxing selector with a certain pin group
53 * @gpio_request_enable: requests and enables GPIO on a certain pin.
54 * Implement this only if you can mux every pin individually as GPIO. The
55 * affected GPIO range is passed along with an offset(pin number) into that
56 * specific GPIO range - function selectors and pin groups are orthogonal
57 * to this, the core will however make sure the pins do not collide.
58 * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of
59 * @gpio_request_enable
60 * @gpio_set_direction: Since controllers may need different configurations
61 * depending on whether the GPIO is configured as input or output,
62 * a direction selector function may be implemented as a backing
63 * to the GPIO controllers that need pin muxing.
64 */
65 struct pinmux_ops {
66 int (*request) (struct pinctrl_dev *pctldev, unsigned offset);
67 int (*free) (struct pinctrl_dev *pctldev, unsigned offset);
68 int (*list_functions) (struct pinctrl_dev *pctldev, unsigned selector);
69 const char *(*get_function_name) (struct pinctrl_dev *pctldev,
70 unsigned selector);
71 int (*get_function_groups) (struct pinctrl_dev *pctldev,
72 unsigned selector,
73 const char * const **groups,
74 unsigned * const num_groups);
75 int (*enable) (struct pinctrl_dev *pctldev, unsigned func_selector,
76 unsigned group_selector);
77 void (*disable) (struct pinctrl_dev *pctldev, unsigned func_selector,
78 unsigned group_selector);
79 int (*gpio_request_enable) (struct pinctrl_dev *pctldev,
80 struct pinctrl_gpio_range *range,
81 unsigned offset);
82 void (*gpio_disable_free) (struct pinctrl_dev *pctldev,
83 struct pinctrl_gpio_range *range,
84 unsigned offset);
85 int (*gpio_set_direction) (struct pinctrl_dev *pctldev,
86 struct pinctrl_gpio_range *range,
87 unsigned offset,
88 bool input);
89 };
90
91 /* External interface to pinmux */
92 extern int pinmux_request_gpio(unsigned gpio);
93 extern void pinmux_free_gpio(unsigned gpio);
94 extern int pinmux_gpio_direction_input(unsigned gpio);
95 extern int pinmux_gpio_direction_output(unsigned gpio);
96 extern struct pinmux * __must_check pinmux_get(struct device *dev, const char *name);
97 extern void pinmux_put(struct pinmux *pmx);
98 extern int pinmux_enable(struct pinmux *pmx);
99 extern void pinmux_disable(struct pinmux *pmx);
100
101 #else /* !CONFIG_PINMUX */
102
103 static inline int pinmux_request_gpio(unsigned gpio)
104 {
105 return 0;
106 }
107
108 static inline void pinmux_free_gpio(unsigned gpio)
109 {
110 }
111
112 static inline int pinmux_gpio_direction_input(unsigned gpio)
113 {
114 return 0;
115 }
116
117 static inline int pinmux_gpio_direction_output(unsigned gpio)
118 {
119 return 0;
120 }
121
122 static inline struct pinmux * __must_check pinmux_get(struct device *dev, const char *name)
123 {
124 return NULL;
125 }
126
127 static inline void pinmux_put(struct pinmux *pmx)
128 {
129 }
130
131 static inline int pinmux_enable(struct pinmux *pmx)
132 {
133 return 0;
134 }
135
136 static inline void pinmux_disable(struct pinmux *pmx)
137 {
138 }
139
140 #endif /* CONFIG_PINMUX */
141
142 #endif /* __LINUX_PINCTRL_PINMUX_H */
This page took 0.03784 seconds and 5 git commands to generate.