Merge remote-tracking branch 'asoc/topic/rcar' into asoc-next
[deliverable/linux.git] / include / linux / pinctrl / pinctrl.h
CommitLineData
2744e8af
LW
1/*
2 * Interface the pinctrl subsystem
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * This interface is used in the core to keep track of pins.
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12#ifndef __LINUX_PINCTRL_PINCTRL_H
13#define __LINUX_PINCTRL_PINCTRL_H
14
15#ifdef CONFIG_PINCTRL
16
17#include <linux/radix-tree.h>
2744e8af
LW
18#include <linux/list.h>
19#include <linux/seq_file.h>
a1ce3928 20#include <linux/pinctrl/pinctrl-state.h>
46919ae6 21
0acfb076 22struct device;
2744e8af 23struct pinctrl_dev;
57291ce2 24struct pinctrl_map;
2744e8af 25struct pinmux_ops;
ae6b4d85 26struct pinconf_ops;
dd4d01f7 27struct pin_config_item;
2744e8af 28struct gpio_chip;
57291ce2 29struct device_node;
2744e8af
LW
30
31/**
32 * struct pinctrl_pin_desc - boards/machines provide information on their
33 * pins, pads or other muxable units in this struct
34 * @number: unique pin number from the global pin number space
35 * @name: a name for this pin
a30d5421 36 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
2744e8af
LW
37 */
38struct pinctrl_pin_desc {
39 unsigned number;
40 const char *name;
a30d5421 41 void *drv_data;
2744e8af
LW
42};
43
44/* Convenience macro to define a single named or anonymous pin descriptor */
45#define PINCTRL_PIN(a, b) { .number = a, .name = b }
46#define PINCTRL_PIN_ANON(a) { .number = a }
47
48/**
49 * struct pinctrl_gpio_range - each pin controller can provide subranges of
50 * the GPIO number space to be handled by the controller
51 * @node: list node for internal use
52 * @name: a name for the chip in this range
53 * @id: an ID number for the chip in this range
54 * @base: base offset of the GPIO range
56a59911 55 * @pin_base: base pin number of the GPIO range if pins == NULL
c8587eee 56 * @pins: enumeration of pins in GPIO range or NULL
2744e8af
LW
57 * @npins: number of pins in the GPIO range, including the base number
58 * @gc: an optional pointer to a gpio_chip
59 */
60struct pinctrl_gpio_range {
61 struct list_head node;
62 const char *name;
63 unsigned int id;
64 unsigned int base;
3c739ad0 65 unsigned int pin_base;
c8587eee 66 unsigned const *pins;
2744e8af
LW
67 unsigned int npins;
68 struct gpio_chip *gc;
69};
70
71/**
72 * struct pinctrl_ops - global pin control operations, to be implemented by
73 * pin controller drivers.
d1e90e9e 74 * @get_groups_count: Returns the count of total number of groups registered.
2744e8af
LW
75 * @get_group_name: return the group name of the pin group
76 * @get_group_pins: return an array of pins corresponding to a certain
77 * group selector @pins, and the size of the array in @num_pins
78 * @pin_dbg_show: optional debugfs display hook that will provide per-device
79 * info for a certain pin in debugfs
02ae6da2
SW
80 * @dt_node_to_map: parse a device tree "pin configuration node", and create
81 * mapping table entries for it. These are returned through the @map and
82 * @num_maps output parameters. This function is optional, and may be
83 * omitted for pinctrl drivers that do not support device tree.
84 * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
85 * top-level @map pointer must be freed, along with any dynamically
86 * allocated members of the mapping table entries themselves. This
87 * function is optional, and may be omitted for pinctrl drivers that do
88 * not support device tree.
2744e8af
LW
89 */
90struct pinctrl_ops {
d1e90e9e 91 int (*get_groups_count) (struct pinctrl_dev *pctldev);
2744e8af
LW
92 const char *(*get_group_name) (struct pinctrl_dev *pctldev,
93 unsigned selector);
94 int (*get_group_pins) (struct pinctrl_dev *pctldev,
95 unsigned selector,
a5818a8b
SW
96 const unsigned **pins,
97 unsigned *num_pins);
2744e8af
LW
98 void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
99 unsigned offset);
57291ce2
SW
100 int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
101 struct device_node *np_config,
102 struct pinctrl_map **map, unsigned *num_maps);
103 void (*dt_free_map) (struct pinctrl_dev *pctldev,
104 struct pinctrl_map *map, unsigned num_maps);
2744e8af
LW
105};
106
107/**
108 * struct pinctrl_desc - pin controller descriptor, register this to pin
109 * control subsystem
110 * @name: name for the pin controller
111 * @pins: an array of pin descriptors describing all the pins handled by
112 * this pin controller
113 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
114 * of the pins field above
2744e8af
LW
115 * @pctlops: pin control operation vtable, to support global concepts like
116 * grouping of pins, this is optional.
ae6b4d85
LW
117 * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
118 * @confops: pin config operations vtable, if you support pin configuration in
119 * your driver
2744e8af 120 * @owner: module providing the pin controller, used for refcounting
f684e4ac
LW
121 * @num_custom_params: Number of driver-specific custom parameters to be parsed
122 * from the hardware description
123 * @custom_params: List of driver_specific custom parameters to be parsed from
124 * the hardware description
125 * @custom_conf_items: Information how to print @params in debugfs, must be
126 * the same size as the @custom_params, i.e. @num_custom_params
2744e8af
LW
127 */
128struct pinctrl_desc {
129 const char *name;
b3da97ee 130 const struct pinctrl_pin_desc *pins;
2744e8af 131 unsigned int npins;
022ab148
LP
132 const struct pinctrl_ops *pctlops;
133 const struct pinmux_ops *pmxops;
134 const struct pinconf_ops *confops;
2744e8af 135 struct module *owner;
f684e4ac
LW
136#ifdef CONFIG_GENERIC_PINCONF
137 unsigned int num_custom_params;
138 const struct pinconf_generic_params *custom_params;
139 const struct pin_config_item *custom_conf_items;
dd4d01f7 140#endif
2744e8af
LW
141};
142
143/* External interface to pin controller */
144extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
145 struct device *dev, void *driver_data);
146extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
147extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
148extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
149 struct pinctrl_gpio_range *range);
3e5e00b6
DA
150extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
151 struct pinctrl_gpio_range *ranges,
152 unsigned nranges);
7e10ee68
VK
153extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
154 struct pinctrl_gpio_range *range);
f23f1516 155
192c369c 156extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
f23f1516 157 struct pinctrl_gpio_range *range);
9afbefb2
LW
158extern struct pinctrl_gpio_range *
159pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
160 unsigned int pin);
586a87e6
CR
161extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
162 const char *pin_group, const unsigned **pins,
163 unsigned *num_pins);
f23f1516
SH
164
165#ifdef CONFIG_OF
1e63d7b9 166extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
f23f1516
SH
167#else
168static inline
1e63d7b9 169struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
f23f1516
SH
170{
171 return NULL;
172}
f23f1516
SH
173#endif /* CONFIG_OF */
174
2744e8af 175extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
d6e99abb 176extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
2744e8af
LW
177extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
178#else
179
e0e20753 180struct pinctrl_dev;
2744e8af 181
ae6b4d85 182/* Sufficiently stupid default functions when pinctrl is not in use */
2744e8af
LW
183static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
184{
185 return pin >= 0;
186}
187
188#endif /* !CONFIG_PINCTRL */
189
190#endif /* __LINUX_PINCTRL_PINCTRL_H */
This page took 0.330732 seconds and 5 git commands to generate.