Merge tag 'reset-for-v5.3' of git://git.pengutronix.de/git/pza/linux into arm/drivers
[sfrench/cifs-2.6.git] / include / linux / pinctrl / pinmux.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Interface the pinmux subsystem
4  *
5  * Copyright (C) 2011 ST-Ericsson SA
6  * Written on behalf of Linaro for ST-Ericsson
7  * Based on bits of regulator core, gpio core and clk core
8  *
9  * Author: Linus Walleij <linus.walleij@linaro.org>
10  */
11 #ifndef __LINUX_PINCTRL_PINMUX_H
12 #define __LINUX_PINCTRL_PINMUX_H
13
14 #include <linux/list.h>
15 #include <linux/seq_file.h>
16 #include <linux/pinctrl/pinctrl.h>
17
18 #ifdef CONFIG_PINMUX
19
20 struct pinctrl_dev;
21
22 /**
23  * struct pinmux_ops - pinmux operations, to be implemented by pin controller
24  * drivers that support pinmuxing
25  * @request: called by the core to see if a certain pin can be made
26  *      available for muxing. This is called by the core to acquire the pins
27  *      before selecting any actual mux setting across a function. The driver
28  *      is allowed to answer "no" by returning a negative error code
29  * @free: the reverse function of the request() callback, frees a pin after
30  *      being requested
31  * @get_functions_count: returns number of selectable named functions available
32  *      in this pinmux driver
33  * @get_function_name: return the function name of the muxing selector,
34  *      called by the core to figure out which mux setting it shall map a
35  *      certain device to
36  * @get_function_groups: return an array of groups names (in turn
37  *      referencing pins) connected to a certain function selector. The group
38  *      name can be used with the generic @pinctrl_ops to retrieve the
39  *      actual pins affected. The applicable groups will be returned in
40  *      @groups and the number of groups in @num_groups
41  * @set_mux: enable a certain muxing function with a certain pin group. The
42  *      driver does not need to figure out whether enabling this function
43  *      conflicts some other use of the pins in that group, such collisions
44  *      are handled by the pinmux subsystem. The @func_selector selects a
45  *      certain function whereas @group_selector selects a certain set of pins
46  *      to be used. On simple controllers the latter argument may be ignored
47  * @gpio_request_enable: requests and enables GPIO on a certain pin.
48  *      Implement this only if you can mux every pin individually as GPIO. The
49  *      affected GPIO range is passed along with an offset(pin number) into that
50  *      specific GPIO range - function selectors and pin groups are orthogonal
51  *      to this, the core will however make sure the pins do not collide.
52  * @gpio_disable_free: free up GPIO muxing on a certain pin, the reverse of
53  *      @gpio_request_enable
54  * @gpio_set_direction: Since controllers may need different configurations
55  *      depending on whether the GPIO is configured as input or output,
56  *      a direction selector function may be implemented as a backing
57  *      to the GPIO controllers that need pin muxing.
58  * @strict: do not allow simultaneous use of the same pin for GPIO and another
59  *      function. Check both gpio_owner and mux_owner strictly before approving
60  *      the pin request.
61  */
62 struct pinmux_ops {
63         int (*request) (struct pinctrl_dev *pctldev, unsigned offset);
64         int (*free) (struct pinctrl_dev *pctldev, unsigned offset);
65         int (*get_functions_count) (struct pinctrl_dev *pctldev);
66         const char *(*get_function_name) (struct pinctrl_dev *pctldev,
67                                           unsigned selector);
68         int (*get_function_groups) (struct pinctrl_dev *pctldev,
69                                   unsigned selector,
70                                   const char * const **groups,
71                                   unsigned *num_groups);
72         int (*set_mux) (struct pinctrl_dev *pctldev, unsigned func_selector,
73                         unsigned group_selector);
74         int (*gpio_request_enable) (struct pinctrl_dev *pctldev,
75                                     struct pinctrl_gpio_range *range,
76                                     unsigned offset);
77         void (*gpio_disable_free) (struct pinctrl_dev *pctldev,
78                                    struct pinctrl_gpio_range *range,
79                                    unsigned offset);
80         int (*gpio_set_direction) (struct pinctrl_dev *pctldev,
81                                    struct pinctrl_gpio_range *range,
82                                    unsigned offset,
83                                    bool input);
84         bool strict;
85 };
86
87 #endif /* CONFIG_PINMUX */
88
89 #endif /* __LINUX_PINCTRL_PINMUX_H */