blob: 8808f25a07d466f8ff3c1522bb02b4e9bc7e9924 [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
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
Linus Walleijbefe5bd2012-02-09 19:47:48 +010055 * @groups: the group selectors for the pinmux device and
56 * selector combination handling this pinmux, this is a list that
57 * will be traversed on all pinmux operations such as
58 * get/put/enable/disable
59 */
60struct pinctrl {
61 struct list_head node;
62 struct device *dev;
63 unsigned usecount;
64 struct pinctrl_dev *pctldev;
Linus Walleij2744e8a2011-05-02 20:50:54 +020065#ifdef CONFIG_PINMUX
Linus Walleijbefe5bd2012-02-09 19:47:48 +010066 struct list_head groups;
Linus Walleij2744e8a2011-05-02 20:50:54 +020067#endif
68};
69
70/**
71 * struct pin_desc - pin descriptor for each physical pin in the arch
72 * @pctldev: corresponding pin control device
73 * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
74 * datasheet or such
Linus Walleijca53c5f2011-12-14 20:33:37 +010075 * @dynamic_name: if the name of this pin was dynamically allocated
Linus Walleij962bcbc2012-03-02 16:52:46 +010076 * @owner: the device holding this pin or NULL of no device has claimed it
Linus Walleij2744e8a2011-05-02 20:50:54 +020077 */
78struct pin_desc {
79 struct pinctrl_dev *pctldev;
Stephen Warren9af1e442011-10-19 16:19:27 -060080 const char *name;
Linus Walleijca53c5f2011-12-14 20:33:37 +010081 bool dynamic_name;
Linus Walleij2744e8a2011-05-02 20:50:54 +020082 /* These fields only added when supporting pinmux drivers */
83#ifdef CONFIG_PINMUX
Stephen Warren3cc70ed2012-02-19 23:45:44 -070084 const char *owner;
Linus Walleij2744e8a2011-05-02 20:50:54 +020085#endif
86};
87
Linus Walleij9dfac4f2012-02-01 18:02:47 +010088struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
Linus Walleijae6b4d82011-10-19 18:14:33 +020089int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
Linus Walleij7afde8b2011-10-19 17:07:16 +020090int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
91 const char *pin_group);
Stephen Warren2304b472012-02-22 14:26:01 -070092
93static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
94 unsigned int pin)
95{
96 return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
97}
Stephen Warren57b676f2012-03-02 13:05:44 -070098
99extern struct mutex pinctrl_mutex;