Blame view

drivers/pinctrl/core.h 8.28 KB
2744e8afb   Linus Walleij   drivers: create a...
1
2
3
4
5
6
7
8
9
10
  /*
   * Core private header for the pin control subsystem
   *
   * Copyright (C) 2011 ST-Ericsson SA
   * Written on behalf of Linaro for ST-Ericsson
   *
   * Author: Linus Walleij <linus.walleij@linaro.org>
   *
   * License terms: GNU General Public License (GPL) version 2
   */
ab78029ec   Linus Walleij   drivers/pinctrl: ...
11
  #include <linux/kref.h>
57b676f9c   Stephen Warren   pinctrl: fix and ...
12
13
  #include <linux/mutex.h>
  #include <linux/radix-tree.h>
ae6b4d858   Linus Walleij   pinctrl: add a pi...
14
  #include <linux/pinctrl/pinconf.h>
872acc322   Linus Walleij   pinctrl: include ...
15
  #include <linux/pinctrl/machine.h>
ae6b4d858   Linus Walleij   pinctrl: add a pi...
16
17
  
  struct pinctrl_gpio_range;
2744e8afb   Linus Walleij   drivers: create a...
18
19
20
21
22
23
24
  /**
   * struct pinctrl_dev - pin control class device
   * @node: node to include this pin controller in the global pin controller list
   * @desc: the pin controller descriptor supplied when initializing this pin
   *	controller
   * @pin_desc_tree: each pin descriptor for this pin controller is stored in
   *	this radix tree
c7059c5ac   Tony Lindgren   pinctrl: core: Ad...
25
26
   * @pin_group_tree: optionally each pin group can be stored in this radix tree
   * @num_groups: optionally number of groups can be kept here
a76edc89b   Tony Lindgren   pinctrl: core: Ad...
27
28
   * @pin_function_tree: optionally each function can be stored in this radix tree
   * @num_functions: optionally number of functions can be kept here
2744e8afb   Linus Walleij   drivers: create a...
29
30
   * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
   *	ranges are added to this list at runtime
2744e8afb   Linus Walleij   drivers: create a...
31
32
33
34
   * @dev: the device entry for this pin controller
   * @owner: module providing the pin controller, used for refcounting
   * @driver_data: driver data for drivers registering to the pin controller
   *	subsystem
46919ae63   Stephen Warren   pinctrl: introduc...
35
   * @p: result of pinctrl_get() for this device
840a47ba4   Julien Delacou   pinctrl: add slee...
36
37
   * @hog_default: default state for pins hogged by this device
   * @hog_sleep: sleep state for pins hogged by this device
42fed7ba4   Patrice Chotard   pinctrl: move sub...
38
   * @mutex: mutex taken on each pin controller specific action
befe5bdfb   Linus Walleij   pinctrl: factor p...
39
   * @device_root: debugfs root for this device
2744e8afb   Linus Walleij   drivers: create a...
40
41
42
43
44
   */
  struct pinctrl_dev {
  	struct list_head node;
  	struct pinctrl_desc *desc;
  	struct radix_tree_root pin_desc_tree;
c033a718f   Linus Walleij   pinctrl: stricten...
45
  #ifdef CONFIG_GENERIC_PINCTRL_GROUPS
c7059c5ac   Tony Lindgren   pinctrl: core: Ad...
46
47
  	struct radix_tree_root pin_group_tree;
  	unsigned int num_groups;
c033a718f   Linus Walleij   pinctrl: stricten...
48
  #endif
a76edc89b   Tony Lindgren   pinctrl: core: Ad...
49
50
51
52
  #ifdef CONFIG_GENERIC_PINMUX_FUNCTIONS
  	struct radix_tree_root pin_function_tree;
  	unsigned int num_functions;
  #endif
2744e8afb   Linus Walleij   drivers: create a...
53
  	struct list_head gpio_ranges;
51cd24ee6   Stephen Warren   pinctrl: don't cr...
54
  	struct device *dev;
2744e8afb   Linus Walleij   drivers: create a...
55
56
  	struct module *owner;
  	void *driver_data;
46919ae63   Stephen Warren   pinctrl: introduc...
57
  	struct pinctrl *p;
840a47ba4   Julien Delacou   pinctrl: add slee...
58
59
  	struct pinctrl_state *hog_default;
  	struct pinctrl_state *hog_sleep;
42fed7ba4   Patrice Chotard   pinctrl: move sub...
60
  	struct mutex mutex;
021571608   Tony Lindgren   pinctrl: free deb...
61
62
63
  #ifdef CONFIG_DEBUG_FS
  	struct dentry *device_root;
  #endif
befe5bdfb   Linus Walleij   pinctrl: factor p...
64
65
66
67
68
69
  };
  
  /**
   * struct pinctrl - per-device pin control state holder
   * @node: global list node
   * @dev: the device using this pin control handle
6e5e959dd   Stephen Warren   pinctrl: API chan...
70
71
   * @states: a list of states for this device
   * @state: the current state
57291ce29   Stephen Warren   pinctrl: core dev...
72
73
   * @dt_maps: the mapping table chunks dynamically parsed from device tree for
   *	this device, if any
ab78029ec   Linus Walleij   drivers/pinctrl: ...
74
   * @users: reference count
befe5bdfb   Linus Walleij   pinctrl: factor p...
75
76
77
78
   */
  struct pinctrl {
  	struct list_head node;
  	struct device *dev;
6e5e959dd   Stephen Warren   pinctrl: API chan...
79
80
  	struct list_head states;
  	struct pinctrl_state *state;
57291ce29   Stephen Warren   pinctrl: core dev...
81
  	struct list_head dt_maps;
ab78029ec   Linus Walleij   drivers/pinctrl: ...
82
  	struct kref users;
6e5e959dd   Stephen Warren   pinctrl: API chan...
83
84
85
86
  };
  
  /**
   * struct pinctrl_state - a pinctrl state for a device
2c9abf808   Richard Genoud   pinctrl: fix typo...
87
   * @node: list node for struct pinctrl's @states field
6e5e959dd   Stephen Warren   pinctrl: API chan...
88
89
90
91
92
93
   * @name: the name of this state
   * @settings: a list of settings for this state
   */
  struct pinctrl_state {
  	struct list_head node;
  	const char *name;
7ecdb16fe   Stephen Warren   pinctrl: refactor...
94
95
96
97
  	struct list_head settings;
  };
  
  /**
1e2082b52   Stephen Warren   pinctrl: enhance ...
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
   * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP
   * @group: the group selector to program
   * @func: the function selector to program
   */
  struct pinctrl_setting_mux {
  	unsigned group;
  	unsigned func;
  };
  
  /**
   * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_*
   * @group_or_pin: the group selector or pin ID to program
   * @configs: a pointer to an array of config parameters/values to program into
   *	hardware. Each individual pin controller defines the format and meaning
   *	of config parameters.
   * @num_configs: the number of entries in array @configs
   */
  struct pinctrl_setting_configs {
  	unsigned group_or_pin;
  	unsigned long *configs;
  	unsigned num_configs;
  };
  
  /**
872acc322   Linus Walleij   pinctrl: include ...
122
   * struct pinctrl_setting - an individual mux or config setting
6e5e959dd   Stephen Warren   pinctrl: API chan...
123
   * @node: list node for struct pinctrl_settings's @settings field
1e2082b52   Stephen Warren   pinctrl: enhance ...
124
   * @type: the type of setting
57291ce29   Stephen Warren   pinctrl: core dev...
125
126
   * @pctldev: pin control device handling to be programmed. Not used for
   *   PIN_MAP_TYPE_DUMMY_STATE.
1a78958dc   Linus Walleij   pinctrl: reserve ...
127
   * @dev_name: the name of the device using this state
1e2082b52   Stephen Warren   pinctrl: enhance ...
128
   * @data: Data specific to the setting type
7ecdb16fe   Stephen Warren   pinctrl: refactor...
129
130
131
   */
  struct pinctrl_setting {
  	struct list_head node;
1e2082b52   Stephen Warren   pinctrl: enhance ...
132
  	enum pinctrl_map_type type;
befe5bdfb   Linus Walleij   pinctrl: factor p...
133
  	struct pinctrl_dev *pctldev;
1a78958dc   Linus Walleij   pinctrl: reserve ...
134
  	const char *dev_name;
1e2082b52   Stephen Warren   pinctrl: enhance ...
135
136
137
138
  	union {
  		struct pinctrl_setting_mux mux;
  		struct pinctrl_setting_configs configs;
  	} data;
2744e8afb   Linus Walleij   drivers: create a...
139
140
141
142
143
144
145
  };
  
  /**
   * struct pin_desc - pin descriptor for each physical pin in the arch
   * @pctldev: corresponding pin control device
   * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
   *	datasheet or such
ca53c5f1c   Linus Walleij   pinctrl: conjure ...
146
   * @dynamic_name: if the name of this pin was dynamically allocated
cd8f61f1e   Masahiro Yamada   pinctrl: copy per...
147
   * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
652162d46   Stephen Warren   pinctrl: allow co...
148
   * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL.
0e3db173e   Stephen Warren   pinctrl: add usec...
149
150
151
152
   *	If non-zero, this pin is claimed by @owner. This field is an integer
   *	rather than a boolean, since pinctrl_get() might process multiple
   *	mapping table entries that refer to, and hence claim, the same group
   *	or pin, and each of these will increment the @usecount.
652162d46   Stephen Warren   pinctrl: allow co...
153
   * @mux_owner: The name of device that called pinctrl_get().
ba110d90c   Stephen Warren   pinctrl: Show sel...
154
   * @mux_setting: The most recent selected mux setting for this pin, if any.
652162d46   Stephen Warren   pinctrl: allow co...
155
156
   * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is
   *	the name of the GPIO that "owns" this pin.
2744e8afb   Linus Walleij   drivers: create a...
157
158
159
   */
  struct pin_desc {
  	struct pinctrl_dev *pctldev;
9af1e44fb   Stephen Warren   pinctrl: Don't co...
160
  	const char *name;
ca53c5f1c   Linus Walleij   pinctrl: conjure ...
161
  	bool dynamic_name;
cd8f61f1e   Masahiro Yamada   pinctrl: copy per...
162
  	void *drv_data;
2744e8afb   Linus Walleij   drivers: create a...
163
164
  	/* These fields only added when supporting pinmux drivers */
  #ifdef CONFIG_PINMUX
652162d46   Stephen Warren   pinctrl: allow co...
165
166
  	unsigned mux_usecount;
  	const char *mux_owner;
ba110d90c   Stephen Warren   pinctrl: Show sel...
167
  	const struct pinctrl_setting_mux *mux_setting;
652162d46   Stephen Warren   pinctrl: allow co...
168
  	const char *gpio_owner;
2744e8afb   Linus Walleij   drivers: create a...
169
170
  #endif
  };
6f9e41f4e   Laurent Meunier   pinctrl/pinconfig...
171
  /**
c033a718f   Linus Walleij   pinctrl: stricten...
172
173
174
175
176
177
178
   * struct pinctrl_maps - a list item containing part of the mapping table
   * @node: mapping table list node
   * @maps: array of mapping table entries
   * @num_maps: the number of entries in @maps
   */
  struct pinctrl_maps {
  	struct list_head node;
3f713b7c2   Masahiro Yamada   pinctrl: move con...
179
  	const struct pinctrl_map *maps;
c033a718f   Linus Walleij   pinctrl: stricten...
180
181
182
183
184
185
  	unsigned num_maps;
  };
  
  #ifdef CONFIG_GENERIC_PINCTRL_GROUPS
  
  /**
c7059c5ac   Tony Lindgren   pinctrl: core: Ad...
186
187
188
189
190
191
192
193
194
195
196
197
   * struct group_desc - generic pin group descriptor
   * @name: name of the pin group
   * @pins: array of pins that belong to the group
   * @num_pins: number of pins in the group
   * @data: pin controller driver specific data
   */
  struct group_desc {
  	const char *name;
  	int *pins;
  	int num_pins;
  	void *data;
  };
c7059c5ac   Tony Lindgren   pinctrl: core: Ad...
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
  int pinctrl_generic_get_group_count(struct pinctrl_dev *pctldev);
  
  const char *pinctrl_generic_get_group_name(struct pinctrl_dev *pctldev,
  					   unsigned int group_selector);
  
  int pinctrl_generic_get_group_pins(struct pinctrl_dev *pctldev,
  				   unsigned int group_selector,
  				   const unsigned int **pins,
  				   unsigned int *npins);
  
  struct group_desc *pinctrl_generic_get_group(struct pinctrl_dev *pctldev,
  					     unsigned int group_selector);
  
  int pinctrl_generic_add_group(struct pinctrl_dev *pctldev, const char *name,
  			      int *gpins, int ngpins, void *data);
  
  int pinctrl_generic_remove_group(struct pinctrl_dev *pctldev,
  				 unsigned int group_selector);
  
  static inline int
  pinctrl_generic_remove_last_group(struct pinctrl_dev *pctldev)
  {
  	return pinctrl_generic_remove_group(pctldev, pctldev->num_groups - 1);
  }
c033a718f   Linus Walleij   pinctrl: stricten...
222
  #endif	/* CONFIG_GENERIC_PINCTRL_GROUPS */
c7059c5ac   Tony Lindgren   pinctrl: core: Ad...
223

9dfac4fd7   Linus Walleij   pinctrl: delete r...
224
  struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
42fed7ba4   Patrice Chotard   pinctrl: move sub...
225
  struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np);
ae6b4d858   Linus Walleij   pinctrl: add a pi...
226
  int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
dcb5dbc30   Dong Aisheng   pinctrl: show pin...
227
  const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
7afde8baa   Linus Walleij   pinctrl: move gro...
228
229
  int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  			       const char *pin_group);
2304b4737   Stephen Warren   pinctrl: remove p...
230
231
232
233
234
235
  
  static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
  					    unsigned int pin)
  {
  	return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
  }
57b676f9c   Stephen Warren   pinctrl: fix and ...
236

b18537cd8   Joachim Eastwood   pinctrl: core: cr...
237
238
239
  extern struct pinctrl_gpio_range *
  pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev,
  					unsigned int pin);
3f713b7c2   Masahiro Yamada   pinctrl: move con...
240
  int pinctrl_register_map(const struct pinctrl_map *maps, unsigned num_maps,
c5272a285   Doug Anderson   pinctrl: Don't ju...
241
  			 bool dup);
3f713b7c2   Masahiro Yamada   pinctrl: move con...
242
  void pinctrl_unregister_map(const struct pinctrl_map *map);
57291ce29   Stephen Warren   pinctrl: core dev...
243

840a47ba4   Julien Delacou   pinctrl: add slee...
244
245
  extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev);
  extern int pinctrl_force_default(struct pinctrl_dev *pctldev);
42fed7ba4   Patrice Chotard   pinctrl: move sub...
246
  extern struct mutex pinctrl_maps_mutex;
6f9e41f4e   Laurent Meunier   pinctrl/pinconfig...
247
248
249
250
251
252
253
  extern struct list_head pinctrl_maps;
  
  #define for_each_maps(_maps_node_, _i_, _map_) \
  	list_for_each_entry(_maps_node_, &pinctrl_maps, node) \
  		for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \
  			_i_ < _maps_node_->num_maps; \
  			_i_++, _map_ = &_maps_node_->maps[_i_])