1 /* 2 * Core private header for the pin control subsystem 3 * 4 * Copyright (C) 2011 ST-Ericsson SA 5 * Written on behalf of Linaro for ST-Ericsson 6 * 7 * Author: Linus Walleij <linus.walleij@linaro.org> 8 * 9 * License terms: GNU General Public License (GPL) version 2 10 */ 11 12 #include <linux/kref.h> 13 #include <linux/mutex.h> 14 #include <linux/radix-tree.h> 15 #include <linux/pinctrl/pinconf.h> 16 #include <linux/pinctrl/machine.h> 17 18 struct pinctrl_gpio_range; 19 20 /** 21 * struct pinctrl_dev - pin control class device 22 * @node: node to include this pin controller in the global pin controller list 23 * @desc: the pin controller descriptor supplied when initializing this pin 24 * controller 25 * @pin_desc_tree: each pin descriptor for this pin controller is stored in 26 * this radix tree 27 * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, 28 * ranges are added to this list at runtime 29 * @dev: the device entry for this pin controller 30 * @owner: module providing the pin controller, used for refcounting 31 * @driver_data: driver data for drivers registering to the pin controller 32 * subsystem 33 * @p: result of pinctrl_get() for this device 34 * @hog_default: default state for pins hogged by this device 35 * @hog_sleep: sleep state for pins hogged by this device 36 * @late_init: delayed work for pin controller to finish registration 37 * @mutex: mutex taken on each pin controller specific action 38 * @device_root: debugfs root for this device 39 */ 40 struct pinctrl_dev { 41 struct list_head node; 42 struct pinctrl_desc *desc; 43 struct radix_tree_root pin_desc_tree; 44 struct list_head gpio_ranges; 45 struct device *dev; 46 struct module *owner; 47 void *driver_data; 48 struct pinctrl *p; 49 struct pinctrl_state *hog_default; 50 struct pinctrl_state *hog_sleep; 51 struct delayed_work late_init; 52 struct mutex mutex; 53 #ifdef CONFIG_DEBUG_FS 54 struct dentry *device_root; 55 #endif 56 }; 57 58 /** 59 * struct pinctrl - per-device pin control state holder 60 * @node: global list node 61 * @dev: the device using this pin control handle 62 * @states: a list of states for this device 63 * @state: the current state 64 * @dt_maps: the mapping table chunks dynamically parsed from device tree for 65 * this device, if any 66 * @users: reference count 67 */ 68 struct pinctrl { 69 struct list_head node; 70 struct device *dev; 71 struct list_head states; 72 struct pinctrl_state *state; 73 struct list_head dt_maps; 74 struct kref users; 75 }; 76 77 /** 78 * struct pinctrl_state - a pinctrl state for a device 79 * @node: list node for struct pinctrl's @states field 80 * @name: the name of this state 81 * @settings: a list of settings for this state 82 */ 83 struct pinctrl_state { 84 struct list_head node; 85 const char *name; 86 struct list_head settings; 87 }; 88 89 /** 90 * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP 91 * @group: the group selector to program 92 * @func: the function selector to program 93 */ 94 struct pinctrl_setting_mux { 95 unsigned group; 96 unsigned func; 97 }; 98 99 /** 100 * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_* 101 * @group_or_pin: the group selector or pin ID to program 102 * @configs: a pointer to an array of config parameters/values to program into 103 * hardware. Each individual pin controller defines the format and meaning 104 * of config parameters. 105 * @num_configs: the number of entries in array @configs 106 */ 107 struct pinctrl_setting_configs { 108 unsigned group_or_pin; 109 unsigned long *configs; 110 unsigned num_configs; 111 }; 112 113 /** 114 * struct pinctrl_setting - an individual mux or config setting 115 * @node: list node for struct pinctrl_settings's @settings field 116 * @type: the type of setting 117 * @pctldev: pin control device handling to be programmed. Not used for 118 * PIN_MAP_TYPE_DUMMY_STATE. 119 * @dev_name: the name of the device using this state 120 * @data: Data specific to the setting type 121 */ 122 struct pinctrl_setting { 123 struct list_head node; 124 enum pinctrl_map_type type; 125 struct pinctrl_dev *pctldev; 126 const char *dev_name; 127 union { 128 struct pinctrl_setting_mux mux; 129 struct pinctrl_setting_configs configs; 130 } data; 131 }; 132 133 /** 134 * struct pin_desc - pin descriptor for each physical pin in the arch 135 * @pctldev: corresponding pin control device 136 * @name: a name for the pin, e.g. the name of the pin/pad/finger on a 137 * datasheet or such 138 * @dynamic_name: if the name of this pin was dynamically allocated 139 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this 140 * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL. 141 * If non-zero, this pin is claimed by @owner. This field is an integer 142 * rather than a boolean, since pinctrl_get() might process multiple 143 * mapping table entries that refer to, and hence claim, the same group 144 * or pin, and each of these will increment the @usecount. 145 * @mux_owner: The name of device that called pinctrl_get(). 146 * @mux_setting: The most recent selected mux setting for this pin, if any. 147 * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is 148 * the name of the GPIO that "owns" this pin. 149 */ 150 struct pin_desc { 151 struct pinctrl_dev *pctldev; 152 const char *name; 153 bool dynamic_name; 154 void *drv_data; 155 /* These fields only added when supporting pinmux drivers */ 156 #ifdef CONFIG_PINMUX 157 unsigned mux_usecount; 158 const char *mux_owner; 159 const struct pinctrl_setting_mux *mux_setting; 160 const char *gpio_owner; 161 #endif 162 }; 163 164 /** 165 * struct pinctrl_maps - a list item containing part of the mapping table 166 * @node: mapping table list node 167 * @maps: array of mapping table entries 168 * @num_maps: the number of entries in @maps 169 */ 170 struct pinctrl_maps { 171 struct list_head node; 172 struct pinctrl_map const *maps; 173 unsigned num_maps; 174 }; 175 176 struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); 177 struct pinctrl_dev *get_pinctrl_dev_from_of_node(struct device_node *np); 178 int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); 179 const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); 180 int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, 181 const char *pin_group); 182 183 static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, 184 unsigned int pin) 185 { 186 return radix_tree_lookup(&pctldev->pin_desc_tree, pin); 187 } 188 189 extern struct pinctrl_gpio_range * 190 pinctrl_find_gpio_range_from_pin_nolock(struct pinctrl_dev *pctldev, 191 unsigned int pin); 192 193 int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, 194 bool dup); 195 void pinctrl_unregister_map(struct pinctrl_map const *map); 196 197 extern int pinctrl_force_sleep(struct pinctrl_dev *pctldev); 198 extern int pinctrl_force_default(struct pinctrl_dev *pctldev); 199 200 extern struct mutex pinctrl_maps_mutex; 201 extern struct list_head pinctrl_maps; 202 203 #define for_each_maps(_maps_node_, _i_, _map_) \ 204 list_for_each_entry(_maps_node_, &pinctrl_maps, node) \ 205 for (_i_ = 0, _map_ = &_maps_node_->maps[_i_]; \ 206 _i_ < _maps_node_->num_maps; \ 207 _i_++, _map_ = &_maps_node_->maps[_i_]) 208