12744e8afSLinus Walleij /* 22744e8afSLinus Walleij * Core private header for the pin control subsystem 32744e8afSLinus Walleij * 42744e8afSLinus Walleij * Copyright (C) 2011 ST-Ericsson SA 52744e8afSLinus Walleij * Written on behalf of Linaro for ST-Ericsson 62744e8afSLinus Walleij * 72744e8afSLinus Walleij * Author: Linus Walleij <linus.walleij@linaro.org> 82744e8afSLinus Walleij * 92744e8afSLinus Walleij * License terms: GNU General Public License (GPL) version 2 102744e8afSLinus Walleij */ 112744e8afSLinus Walleij 1257b676f9SStephen Warren #include <linux/mutex.h> 1357b676f9SStephen Warren #include <linux/radix-tree.h> 14ae6b4d85SLinus Walleij #include <linux/pinctrl/pinconf.h> 15872acc32SLinus Walleij #include <linux/pinctrl/machine.h> 16ae6b4d85SLinus Walleij 17ae6b4d85SLinus Walleij struct pinctrl_gpio_range; 18ae6b4d85SLinus Walleij 192744e8afSLinus Walleij /** 202744e8afSLinus Walleij * struct pinctrl_dev - pin control class device 212744e8afSLinus Walleij * @node: node to include this pin controller in the global pin controller list 222744e8afSLinus Walleij * @desc: the pin controller descriptor supplied when initializing this pin 232744e8afSLinus Walleij * controller 242744e8afSLinus Walleij * @pin_desc_tree: each pin descriptor for this pin controller is stored in 252744e8afSLinus Walleij * this radix tree 262744e8afSLinus Walleij * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, 272744e8afSLinus Walleij * ranges are added to this list at runtime 282744e8afSLinus Walleij * @dev: the device entry for this pin controller 292744e8afSLinus Walleij * @owner: module providing the pin controller, used for refcounting 302744e8afSLinus Walleij * @driver_data: driver data for drivers registering to the pin controller 312744e8afSLinus Walleij * subsystem 3246919ae6SStephen Warren * @p: result of pinctrl_get() for this device 33befe5bdfSLinus Walleij * @device_root: debugfs root for this device 342744e8afSLinus Walleij */ 352744e8afSLinus Walleij struct pinctrl_dev { 362744e8afSLinus Walleij struct list_head node; 372744e8afSLinus Walleij struct pinctrl_desc *desc; 382744e8afSLinus Walleij struct radix_tree_root pin_desc_tree; 392744e8afSLinus Walleij struct list_head gpio_ranges; 4051cd24eeSStephen Warren struct device *dev; 412744e8afSLinus Walleij struct module *owner; 422744e8afSLinus Walleij void *driver_data; 4346919ae6SStephen Warren struct pinctrl *p; 4402157160STony Lindgren #ifdef CONFIG_DEBUG_FS 4502157160STony Lindgren struct dentry *device_root; 4602157160STony Lindgren #endif 47befe5bdfSLinus Walleij }; 48befe5bdfSLinus Walleij 49befe5bdfSLinus Walleij /** 50befe5bdfSLinus Walleij * struct pinctrl - per-device pin control state holder 51befe5bdfSLinus Walleij * @node: global list node 52befe5bdfSLinus Walleij * @dev: the device using this pin control handle 536e5e959dSStephen Warren * @states: a list of states for this device 546e5e959dSStephen Warren * @state: the current state 5557291ce2SStephen Warren * @dt_maps: the mapping table chunks dynamically parsed from device tree for 5657291ce2SStephen Warren * this device, if any 57befe5bdfSLinus Walleij */ 58befe5bdfSLinus Walleij struct pinctrl { 59befe5bdfSLinus Walleij struct list_head node; 60befe5bdfSLinus Walleij struct device *dev; 616e5e959dSStephen Warren struct list_head states; 626e5e959dSStephen Warren struct pinctrl_state *state; 6357291ce2SStephen Warren struct list_head dt_maps; 646e5e959dSStephen Warren }; 656e5e959dSStephen Warren 666e5e959dSStephen Warren /** 676e5e959dSStephen Warren * struct pinctrl_state - a pinctrl state for a device 686e5e959dSStephen Warren * @node: list not for struct pinctrl's @states field 696e5e959dSStephen Warren * @name: the name of this state 706e5e959dSStephen Warren * @settings: a list of settings for this state 716e5e959dSStephen Warren */ 726e5e959dSStephen Warren struct pinctrl_state { 736e5e959dSStephen Warren struct list_head node; 746e5e959dSStephen Warren const char *name; 757ecdb16fSStephen Warren struct list_head settings; 767ecdb16fSStephen Warren }; 777ecdb16fSStephen Warren 787ecdb16fSStephen Warren /** 791e2082b5SStephen Warren * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP 801e2082b5SStephen Warren * @group: the group selector to program 811e2082b5SStephen Warren * @func: the function selector to program 821e2082b5SStephen Warren */ 831e2082b5SStephen Warren struct pinctrl_setting_mux { 841e2082b5SStephen Warren unsigned group; 851e2082b5SStephen Warren unsigned func; 861e2082b5SStephen Warren }; 871e2082b5SStephen Warren 881e2082b5SStephen Warren /** 891e2082b5SStephen Warren * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_* 901e2082b5SStephen Warren * @group_or_pin: the group selector or pin ID to program 911e2082b5SStephen Warren * @configs: a pointer to an array of config parameters/values to program into 921e2082b5SStephen Warren * hardware. Each individual pin controller defines the format and meaning 931e2082b5SStephen Warren * of config parameters. 941e2082b5SStephen Warren * @num_configs: the number of entries in array @configs 951e2082b5SStephen Warren */ 961e2082b5SStephen Warren struct pinctrl_setting_configs { 971e2082b5SStephen Warren unsigned group_or_pin; 981e2082b5SStephen Warren unsigned long *configs; 991e2082b5SStephen Warren unsigned num_configs; 1001e2082b5SStephen Warren }; 1011e2082b5SStephen Warren 1021e2082b5SStephen Warren /** 103872acc32SLinus Walleij * struct pinctrl_setting - an individual mux or config setting 1046e5e959dSStephen Warren * @node: list node for struct pinctrl_settings's @settings field 1051e2082b5SStephen Warren * @type: the type of setting 10657291ce2SStephen Warren * @pctldev: pin control device handling to be programmed. Not used for 10757291ce2SStephen Warren * PIN_MAP_TYPE_DUMMY_STATE. 108*1a78958dSLinus Walleij * @dev_name: the name of the device using this state 1091e2082b5SStephen Warren * @data: Data specific to the setting type 1107ecdb16fSStephen Warren */ 1117ecdb16fSStephen Warren struct pinctrl_setting { 1127ecdb16fSStephen Warren struct list_head node; 1131e2082b5SStephen Warren enum pinctrl_map_type type; 114befe5bdfSLinus Walleij struct pinctrl_dev *pctldev; 115*1a78958dSLinus Walleij const char *dev_name; 1161e2082b5SStephen Warren union { 1171e2082b5SStephen Warren struct pinctrl_setting_mux mux; 1181e2082b5SStephen Warren struct pinctrl_setting_configs configs; 1191e2082b5SStephen Warren } data; 1202744e8afSLinus Walleij }; 1212744e8afSLinus Walleij 1222744e8afSLinus Walleij /** 1232744e8afSLinus Walleij * struct pin_desc - pin descriptor for each physical pin in the arch 1242744e8afSLinus Walleij * @pctldev: corresponding pin control device 1252744e8afSLinus Walleij * @name: a name for the pin, e.g. the name of the pin/pad/finger on a 1262744e8afSLinus Walleij * datasheet or such 127ca53c5f1SLinus Walleij * @dynamic_name: if the name of this pin was dynamically allocated 128652162d4SStephen Warren * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL. 1290e3db173SStephen Warren * If non-zero, this pin is claimed by @owner. This field is an integer 1300e3db173SStephen Warren * rather than a boolean, since pinctrl_get() might process multiple 1310e3db173SStephen Warren * mapping table entries that refer to, and hence claim, the same group 1320e3db173SStephen Warren * or pin, and each of these will increment the @usecount. 133652162d4SStephen Warren * @mux_owner: The name of device that called pinctrl_get(). 134ba110d90SStephen Warren * @mux_setting: The most recent selected mux setting for this pin, if any. 135652162d4SStephen Warren * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is 136652162d4SStephen Warren * the name of the GPIO that "owns" this pin. 1372744e8afSLinus Walleij */ 1382744e8afSLinus Walleij struct pin_desc { 1392744e8afSLinus Walleij struct pinctrl_dev *pctldev; 1409af1e44fSStephen Warren const char *name; 141ca53c5f1SLinus Walleij bool dynamic_name; 1422744e8afSLinus Walleij /* These fields only added when supporting pinmux drivers */ 1432744e8afSLinus Walleij #ifdef CONFIG_PINMUX 144652162d4SStephen Warren unsigned mux_usecount; 145652162d4SStephen Warren const char *mux_owner; 146ba110d90SStephen Warren const struct pinctrl_setting_mux *mux_setting; 147652162d4SStephen Warren const char *gpio_owner; 1482744e8afSLinus Walleij #endif 1492744e8afSLinus Walleij }; 1502744e8afSLinus Walleij 1519dfac4fdSLinus Walleij struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); 152ae6b4d85SLinus Walleij int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); 153dcb5dbc3SDong Aisheng const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin); 1547afde8baSLinus Walleij int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, 1557afde8baSLinus Walleij const char *pin_group); 1562304b473SStephen Warren 1572304b473SStephen Warren static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, 1582304b473SStephen Warren unsigned int pin) 1592304b473SStephen Warren { 1602304b473SStephen Warren return radix_tree_lookup(&pctldev->pin_desc_tree, pin); 1612304b473SStephen Warren } 16257b676f9SStephen Warren 16357291ce2SStephen Warren int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps, 16457291ce2SStephen Warren bool dup, bool locked); 16557291ce2SStephen Warren void pinctrl_unregister_map(struct pinctrl_map const *map); 16657291ce2SStephen Warren 16757b676f9SStephen Warren extern struct mutex pinctrl_mutex; 16857291ce2SStephen Warren extern struct list_head pinctrldev_list; 169