File Index
Files and directories
Sign in
FILE

pinctrl.h

File preview with syntax highlighting.

linux-6.19.14/include/linux/pinctrl/pinctrl.h C
  1/* SPDX-License-Identifier: GPL-2.0-only */
  2/*
  3 * Interface the pinctrl subsystem
  4 *
  5 * Copyright (C) 2011 ST-Ericsson SA
  6 * Written on behalf of Linaro for ST-Ericsson
  7 * This interface is used in the core to keep track of pins.
  8 *
  9 * Author: Linus Walleij <linus.walleij@linaro.org>
 10 */
 11#ifndef __LINUX_PINCTRL_PINCTRL_H
 12#define __LINUX_PINCTRL_PINCTRL_H
 13
 14#include <linux/bits.h>
 15#include <linux/types.h>
 16
 17struct device;
 18struct device_node;
 19struct gpio_chip;
 20struct module;
 21struct seq_file;
 22
 23struct pin_config_item;
 24struct pinconf_generic_params;
 25struct pinconf_ops;
 26struct pinctrl_dev;
 27struct pinctrl_map;
 28struct pinmux_ops;
 29
 30/**
 31 * struct pingroup - provides information on pingroup
 32 * @name: a name for pingroup
 33 * @pins: an array of pins in the pingroup
 34 * @npins: number of pins in the pingroup
 35 */
 36struct pingroup {
 37	const char *name;
 38	const unsigned int *pins;
 39	size_t npins;
 40};
 41
 42/* Convenience macro to define a single named or anonymous pingroup */
 43#define PINCTRL_PINGROUP(_name, _pins, _npins)	\
 44(struct pingroup) {				\
 45	.name = _name,				\
 46	.pins = _pins,				\
 47	.npins = _npins,			\
 48}
 49
 50/**
 51 * struct pinctrl_pin_desc - boards/machines provide information on their
 52 * pins, pads or other muxable units in this struct
 53 * @number: unique pin number from the global pin number space
 54 * @name: a name for this pin
 55 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
 56 */
 57struct pinctrl_pin_desc {
 58	unsigned int number;
 59	const char *name;
 60	void *drv_data;
 61};
 62
 63/* Convenience macro to define a single named or anonymous pin descriptor */
 64#define PINCTRL_PIN(a, b) { .number = a, .name = b }
 65#define PINCTRL_PIN_ANON(a) { .number = a }
 66
 67/**
 68 * struct pinctrl_gpio_range - each pin controller can provide subranges of
 69 * the GPIO number space to be handled by the controller
 70 * @node: list node for internal use
 71 * @name: a name for the chip in this range
 72 * @id: an ID number for the chip in this range
 73 * @base: base offset of the GPIO range
 74 * @pin_base: base pin number of the GPIO range if pins == NULL
 75 * @npins: number of pins in the GPIO range, including the base number
 76 * @pins: enumeration of pins in GPIO range or NULL
 77 * @gc: an optional pointer to a gpio_chip
 78 */
 79struct pinctrl_gpio_range {
 80	struct list_head node;
 81	const char *name;
 82	unsigned int id;
 83	unsigned int base;
 84	unsigned int pin_base;
 85	unsigned int npins;
 86	unsigned int const *pins;
 87	struct gpio_chip *gc;
 88};
 89
 90/**
 91 * struct pinctrl_ops - global pin control operations, to be implemented by
 92 * pin controller drivers.
 93 * @get_groups_count: Returns the count of total number of groups registered.
 94 * @get_group_name: return the group name of the pin group
 95 * @get_group_pins: return an array of pins corresponding to a certain
 96 *	group selector @pins, and the size of the array in @num_pins
 97 * @pin_dbg_show: optional debugfs display hook that will provide per-device
 98 *	info for a certain pin in debugfs
 99 * @dt_node_to_map: parse a device tree "pin configuration node", and create
100 *	mapping table entries for it. These are returned through the @map and
101 *	@num_maps output parameters. This function is optional, and may be
102 *	omitted for pinctrl drivers that do not support device tree.
103 * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
104 *	top-level @map pointer must be freed, along with any dynamically
105 *	allocated members of the mapping table entries themselves. This
106 *	function is optional, and may be omitted for pinctrl drivers that do
107 *	not support device tree.
108 */
109struct pinctrl_ops {
110	int (*get_groups_count) (struct pinctrl_dev *pctldev);
111	const char *(*get_group_name) (struct pinctrl_dev *pctldev,
112				       unsigned int selector);
113	int (*get_group_pins) (struct pinctrl_dev *pctldev,
114			       unsigned int selector,
115			       const unsigned int **pins,
116			       unsigned int *num_pins);
117	void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
118			      unsigned int offset);
119	int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
120			       struct device_node *np_config,
121			       struct pinctrl_map **map, unsigned int *num_maps);
122	void (*dt_free_map) (struct pinctrl_dev *pctldev,
123			     struct pinctrl_map *map, unsigned int num_maps);
124};
125
126/**
127 * struct pinctrl_desc - pin controller descriptor, register this to pin
128 * control subsystem
129 * @name: name for the pin controller
130 * @pins: an array of pin descriptors describing all the pins handled by
131 *	this pin controller
132 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
133 *	of the pins field above
134 * @pctlops: pin control operation vtable, to support global concepts like
135 *	grouping of pins, this is optional.
136 * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
137 * @confops: pin config operations vtable, if you support pin configuration in
138 *	your driver
139 * @owner: module providing the pin controller, used for refcounting
140 * @num_custom_params: Number of driver-specific custom parameters to be parsed
141 *	from the hardware description
142 * @custom_params: List of driver_specific custom parameters to be parsed from
143 *	the hardware description
144 * @custom_conf_items: Information how to print @params in debugfs, must be
145 *	the same size as the @custom_params, i.e. @num_custom_params
146 * @link_consumers: If true create a device link between pinctrl and its
147 *	consumers (i.e. the devices requesting pin control states). This is
148 *	sometimes necessary to ascertain the right suspend/resume order for
149 *	example.
150 */
151struct pinctrl_desc {
152	const char *name;
153	const struct pinctrl_pin_desc *pins;
154	unsigned int npins;
155	const struct pinctrl_ops *pctlops;
156	const struct pinmux_ops *pmxops;
157	const struct pinconf_ops *confops;
158	struct module *owner;
159#ifdef CONFIG_GENERIC_PINCONF
160	unsigned int num_custom_params;
161	const struct pinconf_generic_params *custom_params;
162	const struct pin_config_item *custom_conf_items;
163#endif
164	bool link_consumers;
165};
166
167/* External interface to pin controller */
168
169extern int pinctrl_register_and_init(const struct pinctrl_desc *pctldesc,
170				     struct device *dev, void *driver_data,
171				     struct pinctrl_dev **pctldev);
172extern int pinctrl_enable(struct pinctrl_dev *pctldev);
173
174/* Please use pinctrl_register_and_init() and pinctrl_enable() instead */
175extern struct pinctrl_dev *pinctrl_register(const struct pinctrl_desc *pctldesc,
176				struct device *dev, void *driver_data);
177
178extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
179
180extern int devm_pinctrl_register_and_init(struct device *dev,
181				const struct pinctrl_desc *pctldesc,
182				void *driver_data,
183				struct pinctrl_dev **pctldev);
184
185/* Please use devm_pinctrl_register_and_init() instead */
186extern struct pinctrl_dev *devm_pinctrl_register(struct device *dev,
187				const struct pinctrl_desc *pctldesc,
188				void *driver_data);
189
190extern void devm_pinctrl_unregister(struct device *dev,
191				struct pinctrl_dev *pctldev);
192
193extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
194				struct pinctrl_gpio_range *range);
195extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
196				struct pinctrl_gpio_range *ranges,
197				unsigned int nranges);
198extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
199				struct pinctrl_gpio_range *range);
200
201extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
202		struct pinctrl_gpio_range *range);
203extern struct pinctrl_gpio_range *
204pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
205				 unsigned int pin);
206extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
207				  const char *pin_group, const unsigned int **pins,
208				  unsigned int *num_pins);
209
210#define PINFUNCTION_FLAG_GPIO	BIT(0)
211
212/**
213 * struct pinfunction - Description about a function
214 * @name: Name of the function
215 * @groups: An array of groups for this function
216 * @ngroups: Number of groups in @groups
217 * @flags: Additional pin function flags
218 */
219struct pinfunction {
220	const char *name;
221	const char * const *groups;
222	size_t ngroups;
223	unsigned long flags;
224};
225
226/* Convenience macro to define a single named pinfunction */
227#define PINCTRL_PINFUNCTION(_name, _groups, _ngroups)	\
228(struct pinfunction) {					\
229		.name = (_name),			\
230		.groups = (_groups),			\
231		.ngroups = (_ngroups),			\
232	}
233
234/* Same as PINCTRL_PINFUNCTION() but for the GPIO category of functions */
235#define PINCTRL_GPIO_PINFUNCTION(_name, _groups, _ngroups)	\
236(struct pinfunction) {						\
237		.name = (_name),				\
238		.groups = (_groups),				\
239		.ngroups = (_ngroups),				\
240		.flags = PINFUNCTION_FLAG_GPIO,			\
241	}
242
243#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL)
244extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
245#else
246static inline
247struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
248{
249	return NULL;
250}
251#endif /* CONFIG_OF */
252
253extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
254extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
255extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
256
257#endif /* __LINUX_PINCTRL_PINCTRL_H */
~/ Read-only file preview.