Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 1 | /* |
| 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 Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 12 | #include <linux/pinctrl/pinconf.h> |
| 13 | |
| 14 | struct pinctrl_gpio_range; |
| 15 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 16 | /** |
| 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 |
| 23 | * @pin_desc_tree_lock: lock for the descriptor tree |
| 24 | * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller, |
| 25 | * ranges are added to this list at runtime |
| 26 | * @gpio_ranges_lock: lock for the GPIO ranges list |
| 27 | * @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 |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 31 | * @pinctrl_hogs_lock: lock for the pin control hog list |
| 32 | * @pinctrl_hogs: list of pin control maps hogged by this device |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame^] | 33 | * @device_root: debugfs root for this device |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 34 | */ |
| 35 | struct pinctrl_dev { |
| 36 | struct list_head node; |
| 37 | struct pinctrl_desc *desc; |
| 38 | struct radix_tree_root pin_desc_tree; |
| 39 | spinlock_t pin_desc_tree_lock; |
| 40 | struct list_head gpio_ranges; |
| 41 | struct mutex gpio_ranges_lock; |
Stephen Warren | 51cd24e | 2011-12-09 16:59:05 -0700 | [diff] [blame] | 42 | struct device *dev; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 43 | struct module *owner; |
| 44 | void *driver_data; |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame^] | 45 | struct mutex pinctrl_hogs_lock; |
| 46 | struct list_head pinctrl_hogs; |
Tony Lindgren | 0215716 | 2012-01-20 08:17:22 -0800 | [diff] [blame] | 47 | #ifdef CONFIG_DEBUG_FS |
| 48 | struct dentry *device_root; |
| 49 | #endif |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame^] | 50 | }; |
| 51 | |
| 52 | /** |
| 53 | * struct pinctrl - per-device pin control state holder |
| 54 | * @node: global list node |
| 55 | * @dev: the device using this pin control handle |
| 56 | * @usecount: the number of active users of this pin controller setting, used |
| 57 | * to keep track of nested use cases |
| 58 | * @pctldev: pin control device handling this pin control handle |
| 59 | * @mutex: a lock for the pin control state holder |
| 60 | * @func_selector: the function selector for the pinmux device handling |
| 61 | * this pinmux |
| 62 | * @groups: the group selectors for the pinmux device and |
| 63 | * selector combination handling this pinmux, this is a list that |
| 64 | * will be traversed on all pinmux operations such as |
| 65 | * get/put/enable/disable |
| 66 | */ |
| 67 | struct pinctrl { |
| 68 | struct list_head node; |
| 69 | struct device *dev; |
| 70 | unsigned usecount; |
| 71 | struct pinctrl_dev *pctldev; |
| 72 | struct mutex mutex; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 73 | #ifdef CONFIG_PINMUX |
Linus Walleij | befe5bd | 2012-02-09 19:47:48 +0100 | [diff] [blame^] | 74 | unsigned func_selector; |
| 75 | struct list_head groups; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 76 | #endif |
| 77 | }; |
| 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 Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 84 | * @dynamic_name: if the name of this pin was dynamically allocated |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 85 | * @lock: a lock to protect the descriptor structure |
| 86 | * @mux_requested: whether the pin is already requested by pinmux or not |
| 87 | * @mux_function: a named muxing function for the pin that will be passed to |
| 88 | * subdrivers and shown in debugfs etc |
| 89 | */ |
| 90 | struct pin_desc { |
| 91 | struct pinctrl_dev *pctldev; |
Stephen Warren | 9af1e44 | 2011-10-19 16:19:27 -0600 | [diff] [blame] | 92 | const char *name; |
Linus Walleij | ca53c5f | 2011-12-14 20:33:37 +0100 | [diff] [blame] | 93 | bool dynamic_name; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 94 | spinlock_t lock; |
| 95 | /* These fields only added when supporting pinmux drivers */ |
| 96 | #ifdef CONFIG_PINMUX |
Stephen Warren | 5d2eaf8 | 2011-10-19 16:19:28 -0600 | [diff] [blame] | 97 | const char *mux_function; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 98 | #endif |
| 99 | }; |
| 100 | |
Linus Walleij | 9dfac4f | 2012-02-01 18:02:47 +0100 | [diff] [blame] | 101 | struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name); |
Marek Belisko | 33d5894 | 2011-10-31 21:27:52 +0100 | [diff] [blame] | 102 | struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev, unsigned int pin); |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 103 | int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 104 | int pinctrl_get_device_gpio_range(unsigned gpio, |
| 105 | struct pinctrl_dev **outdev, |
| 106 | struct pinctrl_gpio_range **outrange); |
Linus Walleij | 7afde8b | 2011-10-19 17:07:16 +0200 | [diff] [blame] | 107 | int pinctrl_get_group_selector(struct pinctrl_dev *pctldev, |
| 108 | const char *pin_group); |