blob: 5f258b793400bb8f2f24ba9fad53b15b619e63b9 [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
Stephen Warren57b676f2012-03-02 13:05:44 -070012#include <linux/mutex.h>
13#include <linux/radix-tree.h>
Linus Walleijae6b4d82011-10-19 18:14:33 +020014#include <linux/pinctrl/pinconf.h>
15
16struct pinctrl_gpio_range;
17
Linus Walleij2744e8a2011-05-02 20:50:54 +020018/**
19 * struct pinctrl_dev - pin control class device
20 * @node: node to include this pin controller in the global pin controller list
21 * @desc: the pin controller descriptor supplied when initializing this pin
22 * controller
23 * @pin_desc_tree: each pin descriptor for this pin controller is stored in
24 * this radix tree
Linus Walleij2744e8a2011-05-02 20:50:54 +020025 * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
26 * ranges are added to this list at runtime
Linus Walleij2744e8a2011-05-02 20:50:54 +020027 * @dev: the device entry for this pin controller
28 * @owner: module providing the pin controller, used for refcounting
29 * @driver_data: driver data for drivers registering to the pin controller
30 * subsystem
Stephen Warren46919ae2012-03-01 18:48:32 -070031 * @p: result of pinctrl_get() for this device
Linus Walleijbefe5bd2012-02-09 19:47:48 +010032 * @device_root: debugfs root for this device
Linus Walleij2744e8a2011-05-02 20:50:54 +020033 */
34struct pinctrl_dev {
35 struct list_head node;
36 struct pinctrl_desc *desc;
37 struct radix_tree_root pin_desc_tree;
Linus Walleij2744e8a2011-05-02 20:50:54 +020038 struct list_head gpio_ranges;
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;
Stephen Warren46919ae2012-03-01 18:48:32 -070042 struct pinctrl *p;
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
Stephen Warren7ecdb162012-03-02 13:05:45 -070052 * @state: the state name passed to pinctrl_get()
Linus Walleijbefe5bd2012-02-09 19:47:48 +010053 * @usecount: the number of active users of this pin controller setting, used
54 * to keep track of nested use cases
Stephen Warren7ecdb162012-03-02 13:05:45 -070055 * @settings: a list of settings for this device/state
Linus Walleijbefe5bd2012-02-09 19:47:48 +010056 */
57struct pinctrl {
58 struct list_head node;
59 struct device *dev;
Stephen Warren7ecdb162012-03-02 13:05:45 -070060 const char *state;
Linus Walleijbefe5bd2012-02-09 19:47:48 +010061 unsigned usecount;
Stephen Warren7ecdb162012-03-02 13:05:45 -070062 struct list_head settings;
63};
64
65/**
66 * struct pinctrl_setting - an individual mux setting
67 * @node: list node for struct pinctrl's @settings field
68 * @pctldev: pin control device handling to be programmed
69 * @group_selector: the group selector to program
70 * @func_selector: the function selector to program
71 */
72struct pinctrl_setting {
73 struct list_head node;
Linus Walleijbefe5bd2012-02-09 19:47:48 +010074 struct pinctrl_dev *pctldev;
Stephen Warren7ecdb162012-03-02 13:05:45 -070075 unsigned group_selector;
76 unsigned func_selector;
Linus Walleij2744e8a2011-05-02 20:50:54 +020077};
78
79/**
80 * struct pin_desc - pin descriptor for each physical pin in the arch
81 * @pctldev: corresponding pin control device
82 * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
83 * datasheet or such
Linus Walleijca53c5f2011-12-14 20:33:37 +010084 * @dynamic_name: if the name of this pin was dynamically allocated
Linus Walleij962bcbc2012-03-02 16:52:46 +010085 * @owner: the device holding this pin or NULL of no device has claimed it
Linus Walleij2744e8a2011-05-02 20:50:54 +020086 */
87struct pin_desc {
88 struct pinctrl_dev *pctldev;
Stephen Warren9af1e442011-10-19 16:19:27 -060089 const char *name;
Linus Walleijca53c5f2011-12-14 20:33:37 +010090 bool dynamic_name;
Linus Walleij2744e8a2011-05-02 20:50:54 +020091 /* 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}
Stephen Warren57b676f2012-03-02 13:05:44 -0700107
108extern struct mutex pinctrl_mutex;