pinctrl: enhance mapping table to support pin config operations
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / include / linux / pinctrl / machine.h
1 /*
2 * Machine interface for the pinctrl 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_MACHINE_H
13 #define __LINUX_PINCTRL_MACHINE_H
14
15 #include "pinctrl.h"
16
17 enum pinctrl_map_type {
18 PIN_MAP_TYPE_INVALID,
19 PIN_MAP_TYPE_DUMMY_STATE,
20 PIN_MAP_TYPE_MUX_GROUP,
21 PIN_MAP_TYPE_CONFIGS_PIN,
22 PIN_MAP_TYPE_CONFIGS_GROUP,
23 };
24
25 /**
26 * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP
27 * @group: the name of the group whose mux function is to be configured. This
28 * field may be left NULL, and the first applicable group for the function
29 * will be used.
30 * @function: the mux function to select for the group
31 */
32 struct pinctrl_map_mux {
33 const char *group;
34 const char *function;
35 };
36
37 /**
38 * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_*
39 * @group_or_pin: the name of the pin or group whose configuration parameters
40 * are to be configured.
41 * @configs: a pointer to an array of config parameters/values to program into
42 * hardware. Each individual pin controller defines the format and meaning
43 * of config parameters.
44 * @num_configs: the number of entries in array @configs
45 */
46 struct pinctrl_map_configs {
47 const char *group_or_pin;
48 unsigned long *configs;
49 unsigned num_configs;
50 };
51
52 /**
53 * struct pinctrl_map - boards/machines shall provide this map for devices
54 * @dev_name: the name of the device using this specific mapping, the name
55 * must be the same as in your struct device*. If this name is set to the
56 * same name as the pin controllers own dev_name(), the map entry will be
57 * hogged by the driver itself upon registration
58 * @name: the name of this specific map entry for the particular machine.
59 * This is the parameter passed to pinmux_lookup_state()
60 * @type: the type of mapping table entry
61 * @ctrl_dev_name: the name of the device controlling this specific mapping,
62 * the name must be the same as in your struct device*. This field is not
63 * used for PIN_MAP_TYPE_DUMMY_STATE
64 * @data: Data specific to the mapping type
65 */
66 struct pinctrl_map {
67 const char *dev_name;
68 const char *name;
69 enum pinctrl_map_type type;
70 const char *ctrl_dev_name;
71 union {
72 struct pinctrl_map_mux mux;
73 struct pinctrl_map_configs configs;
74 } data;
75 };
76
77 /* Convenience macros to create mapping table entries */
78
79 #define PIN_MAP_DUMMY_STATE(dev, state) \
80 { \
81 .dev_name = dev, \
82 .name = state, \
83 .type = PIN_MAP_TYPE_DUMMY_STATE, \
84 }
85
86 #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \
87 { \
88 .dev_name = dev, \
89 .name = state, \
90 .type = PIN_MAP_TYPE_MUX_GROUP, \
91 .ctrl_dev_name = pinctrl, \
92 .data.mux = { \
93 .group = grp, \
94 .function = func, \
95 }, \
96 }
97
98 #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \
99 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func)
100
101 #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \
102 PIN_MAP_MUX_GROUP(dev, state, dev, grp, func)
103
104 #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \
105 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func)
106
107 #define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \
108 { \
109 .dev_name = dev, \
110 .name = state, \
111 .type = PIN_MAP_TYPE_CONFIGS_PIN, \
112 .ctrl_dev_name = pinctrl, \
113 .data.configs = { \
114 .group_or_pin = pin, \
115 .configs = cfgs, \
116 .num_configs = ARRAY_SIZE(cfgs), \
117 }, \
118 }
119
120 #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \
121 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs)
122
123 #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \
124 PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs)
125
126 #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \
127 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs)
128
129 #define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \
130 { \
131 .dev_name = dev, \
132 .name = state, \
133 .type = PIN_MAP_TYPE_CONFIGS_GROUP, \
134 .ctrl_dev_name = pinctrl, \
135 .data.configs = { \
136 .group_or_pin = grp, \
137 .configs = cfgs, \
138 .num_configs = ARRAY_SIZE(cfgs), \
139 }, \
140 }
141
142 #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \
143 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs)
144
145 #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \
146 PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs)
147
148 #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \
149 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs)
150
151 #ifdef CONFIG_PINMUX
152
153 extern int pinctrl_register_mappings(struct pinctrl_map const *map,
154 unsigned num_maps);
155
156 #else
157
158 static inline int pinctrl_register_mappings(struct pinctrl_map const *map,
159 unsigned num_maps)
160 {
161 return 0;
162 }
163
164 #endif /* !CONFIG_PINMUX */
165 #endif