Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
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>
18#include <linux/list.h>
19#include <linux/seq_file.h>
20#include <linux/pinctrl/pinctrl-state.h>
21#include <linux/pinctrl/devinfo.h>
22
23struct device;
24struct pinctrl_dev;
25struct pinctrl_map;
26struct pinmux_ops;
27struct pinconf_ops;
28struct pin_config_item;
29struct gpio_chip;
30struct device_node;
31
32/**
33 * struct pinctrl_pin_desc - boards/machines provide information on their
34 * pins, pads or other muxable units in this struct
35 * @number: unique pin number from the global pin number space
36 * @name: a name for this pin
37 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
38 */
39struct pinctrl_pin_desc {
40 unsigned number;
41 const char *name;
42 void *drv_data;
43};
44
45/* Convenience macro to define a single named or anonymous pin descriptor */
46#define PINCTRL_PIN(a, b) { .number = a, .name = b }
47#define PINCTRL_PIN_ANON(a) { .number = a }
48
49/**
50 * struct pinctrl_gpio_range - each pin controller can provide subranges of
51 * the GPIO number space to be handled by the controller
52 * @node: list node for internal use
53 * @name: a name for the chip in this range
54 * @id: an ID number for the chip in this range
55 * @base: base offset of the GPIO range
56 * @pin_base: base pin number of the GPIO range if pins == NULL
57 * @pins: enumeration of pins in GPIO range or NULL
58 * @npins: number of pins in the GPIO range, including the base number
59 * @gc: an optional pointer to a gpio_chip
60 */
61struct pinctrl_gpio_range {
62 struct list_head node;
63 const char *name;
64 unsigned int id;
65 unsigned int base;
66 unsigned int pin_base;
67 unsigned const *pins;
68 unsigned int npins;
69 struct gpio_chip *gc;
70};
71
72/**
73 * struct pinctrl_ops - global pin control operations, to be implemented by
74 * pin controller drivers.
75 * @get_groups_count: Returns the count of total number of groups registered.
76 * @get_group_name: return the group name of the pin group
77 * @get_group_pins: return an array of pins corresponding to a certain
78 * group selector @pins, and the size of the array in @num_pins
79 * @pin_dbg_show: optional debugfs display hook that will provide per-device
80 * info for a certain pin in debugfs
81 * @dt_node_to_map: parse a device tree "pin configuration node", and create
82 * mapping table entries for it. These are returned through the @map and
83 * @num_maps output parameters. This function is optional, and may be
84 * omitted for pinctrl drivers that do not support device tree.
85 * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
86 * top-level @map pointer must be freed, along with any dynamically
87 * allocated members of the mapping table entries themselves. This
88 * function is optional, and may be omitted for pinctrl drivers that do
89 * not support device tree.
90 */
91struct pinctrl_ops {
92 int (*get_groups_count) (struct pinctrl_dev *pctldev);
93 const char *(*get_group_name) (struct pinctrl_dev *pctldev,
94 unsigned selector);
95 int (*get_group_pins) (struct pinctrl_dev *pctldev,
96 unsigned selector,
97 const unsigned **pins,
98 unsigned *num_pins);
99 void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
100 unsigned offset);
101 int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
102 struct device_node *np_config,
103 struct pinctrl_map **map, unsigned *num_maps);
104 void (*dt_free_map) (struct pinctrl_dev *pctldev,
105 struct pinctrl_map *map, unsigned num_maps);
106};
107
108/**
109 * struct pinctrl_desc - pin controller descriptor, register this to pin
110 * control subsystem
111 * @name: name for the pin controller
112 * @pins: an array of pin descriptors describing all the pins handled by
113 * this pin controller
114 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
115 * of the pins field above
116 * @pctlops: pin control operation vtable, to support global concepts like
117 * grouping of pins, this is optional.
118 * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
119 * @confops: pin config operations vtable, if you support pin configuration in
120 * your driver
121 * @owner: module providing the pin controller, used for refcounting
122 * @num_custom_params: Number of driver-specific custom parameters to be parsed
123 * from the hardware description
124 * @custom_params: List of driver_specific custom parameters to be parsed from
125 * the hardware description
126 * @custom_conf_items: Information how to print @params in debugfs, must be
127 * the same size as the @custom_params, i.e. @num_custom_params
128 */
129struct pinctrl_desc {
130 const char *name;
131 const struct pinctrl_pin_desc *pins;
132 unsigned int npins;
133 const struct pinctrl_ops *pctlops;
134 const struct pinmux_ops *pmxops;
135 const struct pinconf_ops *confops;
136 struct module *owner;
137#ifdef CONFIG_GENERIC_PINCONF
138 unsigned int num_custom_params;
139 const struct pinconf_generic_params *custom_params;
140 const struct pin_config_item *custom_conf_items;
141#endif
142};
143
144/* External interface to pin controller */
145
146extern int pinctrl_register_and_init(struct pinctrl_desc *pctldesc,
147 struct device *dev, void *driver_data,
148 struct pinctrl_dev **pctldev);
149extern int pinctrl_enable(struct pinctrl_dev *pctldev);
150
151/* Please use pinctrl_register_and_init() and pinctrl_enable() instead */
152extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
153 struct device *dev, void *driver_data);
154
155extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
156
157extern int devm_pinctrl_register_and_init(struct device *dev,
158 struct pinctrl_desc *pctldesc,
159 void *driver_data,
160 struct pinctrl_dev **pctldev);
161
162/* Please use devm_pinctrl_register_and_init() instead */
163extern struct pinctrl_dev *devm_pinctrl_register(struct device *dev,
164 struct pinctrl_desc *pctldesc,
165 void *driver_data);
166
167extern void devm_pinctrl_unregister(struct device *dev,
168 struct pinctrl_dev *pctldev);
169
170extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
171extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
172 struct pinctrl_gpio_range *range);
173extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
174 struct pinctrl_gpio_range *ranges,
175 unsigned nranges);
176extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
177 struct pinctrl_gpio_range *range);
178
179extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
180 struct pinctrl_gpio_range *range);
181extern struct pinctrl_gpio_range *
182pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
183 unsigned int pin);
184extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
185 const char *pin_group, const unsigned **pins,
186 unsigned *num_pins);
187
188#ifdef CONFIG_OF
189extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
190#else
191static inline
192struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
193{
194 return NULL;
195}
196#endif /* CONFIG_OF */
197
198extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
199extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
200extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
201#else
202
203struct pinctrl_dev;
204
205/* Sufficiently stupid default functions when pinctrl is not in use */
206static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
207{
208 return pin >= 0;
209}
210
211#endif /* !CONFIG_PINCTRL */
212
213#endif /* __LINUX_PINCTRL_PINCTRL_H */