blob: 7551611666f8988012489bbd5290a827b10ab7da [file] [log] [blame]
Linus Walleij2744e8a2011-05-02 20:50:54 +02001/*
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
Linus Walleijae6b4d82011-10-19 18:14:33 +020012#include <linux/pinctrl/pinconf.h>
13
14struct pinctrl_gpio_range;
15
Linus Walleij2744e8a2011-05-02 20:50:54 +020016/**
17 * struct pinctrl_dev - pin control class device
18 * @node: node to include this pin controller in the global pin controller list
19 * @desc: the pin controller descriptor supplied when initializing this pin
20 * controller
21 * @pin_desc_tree: each pin descriptor for this pin controller is stored in
22 * this radix tree
Linus Walleij2744e8a2011-05-02 20:50:54 +020023 * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
24 * ranges are added to this list at runtime
25 * @gpio_ranges_lock: lock for the GPIO ranges list
26 * @dev: the device entry for this pin controller
27 * @owner: module providing the pin controller, used for refcounting
28 * @driver_data: driver data for drivers registering to the pin controller
29 * subsystem
Linus Walleije93bcee2012-02-09 07:23:28 +010030 * @pinctrl_hogs: list of pin control maps hogged by this device
Linus Walleijbefe5bd2012-02-09 19:47:48 +010031 * @device_root: debugfs root for this device
Linus Walleij2744e8a2011-05-02 20:50:54 +020032 */
33struct pinctrl_dev {
34 struct list_head node;
35 struct pinctrl_desc *desc;
36 struct radix_tree_root pin_desc_tree;
Linus Walleij2744e8a2011-05-02 20:50:54 +020037 struct list_head gpio_ranges;
38 struct mutex gpio_ranges_lock;
Stephen Warren51cd24e2011-12-09 16:59:05 -070039 struct device *dev;
Linus Walleij2744e8a2011-05-02 20:50:54 +020040 struct module *owner;
41 void *driver_data;
Linus Walleijbefe5bd2012-02-09 19:47:48 +010042 struct list_head pinctrl_hogs;
Tony Lindgren02157162012-01-20 08:17:22 -080043#ifdef CONFIG_DEBUG_FS
44 struct dentry *device_root;
45#endif
Linus Walleijbefe5bd2012-02-09 19:47:48 +010046};
47
48/**
49 * struct pinctrl - per-device pin control state holder
50 * @node: global list node
51 * @dev: the device using this pin control handle
52 * @usecount: the number of active users of this pin controller setting, used
53 * to keep track of nested use cases
54 * @pctldev: pin control device handling this pin control handle
55 * @mutex: a lock for the pin control state holder
56 * @func_selector: the function selector for the pinmux device handling
57 * this pinmux
58 * @groups: the group selectors for the pinmux device and
59 * selector combination handling this pinmux, this is a list that
60 * will be traversed on all pinmux operations such as
61 * get/put/enable/disable
62 */
63struct pinctrl {
64 struct list_head node;
65 struct device *dev;
66 unsigned usecount;
67 struct pinctrl_dev *pctldev;
68 struct mutex mutex;
Linus Walleij2744e8a2011-05-02 20:50:54 +020069#ifdef CONFIG_PINMUX
Linus Walleijbefe5bd2012-02-09 19:47:48 +010070 unsigned func_selector;
71 struct list_head groups;
Linus Walleij2744e8a2011-05-02 20:50:54 +020072#endif
73};
74
75/**
76 * struct pin_desc - pin descriptor for each physical pin in the arch
77 * @pctldev: corresponding pin control device
78 * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
79 * datasheet or such
Linus Walleijca53c5f2011-12-14 20:33:37 +010080 * @dynamic_name: if the name of this pin was dynamically allocated
Linus Walleij2744e8a2011-05-02 20:50:54 +020081 * @lock: a lock to protect the descriptor structure
82 * @mux_requested: whether the pin is already requested by pinmux or not
83 * @mux_function: a named muxing function for the pin that will be passed to
84 * subdrivers and shown in debugfs etc
85 */
86struct pin_desc {
87 struct pinctrl_dev *pctldev;
Stephen Warren9af1e442011-10-19 16:19:27 -060088 const char *name;
Linus Walleijca53c5f2011-12-14 20:33:37 +010089 bool dynamic_name;
Linus Walleij2744e8a2011-05-02 20:50:54 +020090 spinlock_t lock;
91 /* These fields only added when supporting pinmux drivers */
92#ifdef CONFIG_PINMUX
Stephen Warren3cc70ed2012-02-19 23:45:44 -070093 const char *owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +020094#endif
95};
96
Linus Walleij9dfac4f2012-02-01 18:02:47 +010097struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
Linus Walleijae6b4d82011-10-19 18:14:33 +020098int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
Linus Walleij7afde8b2011-10-19 17:07:16 +020099int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
100 const char *pin_group);
Stephen Warren2304b472012-02-22 14:26:01 -0700101
102static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
103 unsigned int pin)
104{
105 return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
106}