xref: /linux/drivers/pinctrl/core.h (revision 57b676f9c1b7cd84397fe5a86c9bd2788ac4bd32)
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 
12*57b676f9SStephen Warren #include <linux/mutex.h>
13*57b676f9SStephen Warren #include <linux/radix-tree.h>
14ae6b4d85SLinus Walleij #include <linux/pinctrl/pinconf.h>
15ae6b4d85SLinus Walleij 
16ae6b4d85SLinus Walleij struct pinctrl_gpio_range;
17ae6b4d85SLinus Walleij 
182744e8afSLinus Walleij /**
192744e8afSLinus Walleij  * struct pinctrl_dev - pin control class device
202744e8afSLinus Walleij  * @node: node to include this pin controller in the global pin controller list
212744e8afSLinus Walleij  * @desc: the pin controller descriptor supplied when initializing this pin
222744e8afSLinus Walleij  *	controller
232744e8afSLinus Walleij  * @pin_desc_tree: each pin descriptor for this pin controller is stored in
242744e8afSLinus Walleij  *	this radix tree
252744e8afSLinus Walleij  * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
262744e8afSLinus Walleij  *	ranges are added to this list at runtime
272744e8afSLinus Walleij  * @dev: the device entry for this pin controller
282744e8afSLinus Walleij  * @owner: module providing the pin controller, used for refcounting
292744e8afSLinus Walleij  * @driver_data: driver data for drivers registering to the pin controller
302744e8afSLinus Walleij  *	subsystem
3146919ae6SStephen Warren  * @p: result of pinctrl_get() for this device
32befe5bdfSLinus Walleij  * @device_root: debugfs root for this device
332744e8afSLinus Walleij  */
342744e8afSLinus Walleij struct pinctrl_dev {
352744e8afSLinus Walleij 	struct list_head node;
362744e8afSLinus Walleij 	struct pinctrl_desc *desc;
372744e8afSLinus Walleij 	struct radix_tree_root pin_desc_tree;
382744e8afSLinus Walleij 	struct list_head gpio_ranges;
3951cd24eeSStephen Warren 	struct device *dev;
402744e8afSLinus Walleij 	struct module *owner;
412744e8afSLinus Walleij 	void *driver_data;
4246919ae6SStephen Warren 	struct pinctrl *p;
4302157160STony Lindgren #ifdef CONFIG_DEBUG_FS
4402157160STony Lindgren 	struct dentry *device_root;
4502157160STony Lindgren #endif
46befe5bdfSLinus Walleij };
47befe5bdfSLinus Walleij 
48befe5bdfSLinus Walleij /**
49befe5bdfSLinus Walleij  * struct pinctrl - per-device pin control state holder
50befe5bdfSLinus Walleij  * @node: global list node
51befe5bdfSLinus Walleij  * @dev: the device using this pin control handle
52befe5bdfSLinus Walleij  * @usecount: the number of active users of this pin controller setting, used
53befe5bdfSLinus Walleij  *	to keep track of nested use cases
54befe5bdfSLinus Walleij  * @pctldev: pin control device handling this pin control handle
55befe5bdfSLinus Walleij  * @groups: the group selectors for the pinmux device and
56befe5bdfSLinus Walleij  *	selector combination handling this pinmux, this is a list that
57befe5bdfSLinus Walleij  *	will be traversed on all pinmux operations such as
58befe5bdfSLinus Walleij  *	get/put/enable/disable
59befe5bdfSLinus Walleij  */
60befe5bdfSLinus Walleij struct pinctrl {
61befe5bdfSLinus Walleij 	struct list_head node;
62befe5bdfSLinus Walleij 	struct device *dev;
63befe5bdfSLinus Walleij 	unsigned usecount;
64befe5bdfSLinus Walleij 	struct pinctrl_dev *pctldev;
652744e8afSLinus Walleij #ifdef CONFIG_PINMUX
66befe5bdfSLinus Walleij 	struct list_head groups;
672744e8afSLinus Walleij #endif
682744e8afSLinus Walleij };
692744e8afSLinus Walleij 
702744e8afSLinus Walleij /**
712744e8afSLinus Walleij  * struct pin_desc - pin descriptor for each physical pin in the arch
722744e8afSLinus Walleij  * @pctldev: corresponding pin control device
732744e8afSLinus Walleij  * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
742744e8afSLinus Walleij  *	datasheet or such
75ca53c5f1SLinus Walleij  * @dynamic_name: if the name of this pin was dynamically allocated
76962bcbc5SLinus Walleij  * @owner: the device holding this pin or NULL of no device has claimed it
772744e8afSLinus Walleij  */
782744e8afSLinus Walleij struct pin_desc {
792744e8afSLinus Walleij 	struct pinctrl_dev *pctldev;
809af1e44fSStephen Warren 	const char *name;
81ca53c5f1SLinus Walleij 	bool dynamic_name;
822744e8afSLinus Walleij 	/* These fields only added when supporting pinmux drivers */
832744e8afSLinus Walleij #ifdef CONFIG_PINMUX
843cc70ed3SStephen Warren 	const char *owner;
852744e8afSLinus Walleij #endif
862744e8afSLinus Walleij };
872744e8afSLinus Walleij 
889dfac4fdSLinus Walleij struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
89ae6b4d85SLinus Walleij int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
907afde8baSLinus Walleij int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
917afde8baSLinus Walleij 			       const char *pin_group);
922304b473SStephen Warren 
932304b473SStephen Warren static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
942304b473SStephen Warren 					    unsigned int pin)
952304b473SStephen Warren {
962304b473SStephen Warren 	return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
972304b473SStephen Warren }
98*57b676f9SStephen Warren 
99*57b676f9SStephen Warren extern struct mutex pinctrl_mutex;
100