pinctrl.h 7.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/*
 * Interface the pinctrl subsystem
 *
 * Copyright (C) 2011 ST-Ericsson SA
 * Written on behalf of Linaro for ST-Ericsson
 * This interface is used in the core to keep track of pins.
 *
 * Author: Linus Walleij <linus.walleij@linaro.org>
 *
 * License terms: GNU General Public License (GPL) version 2
 */
#ifndef __LINUX_PINCTRL_PINCTRL_H
#define __LINUX_PINCTRL_PINCTRL_H

#ifdef CONFIG_PINCTRL

#include <linux/radix-tree.h>
#include <linux/list.h>
#include <linux/seq_file.h>
20
#include <linux/pinctrl/pinctrl-state.h>
21
#include <linux/pinctrl/devinfo.h>
22

23
struct device;
24
struct pinctrl_dev;
25
struct pinctrl_map;
26
struct pinmux_ops;
27
struct pinconf_ops;
28
struct pin_config_item;
29
struct gpio_chip;
30
struct device_node;
31 32 33 34 35 36

/**
 * struct pinctrl_pin_desc - boards/machines provide information on their
 * pins, pads or other muxable units in this struct
 * @number: unique pin number from the global pin number space
 * @name: a name for this pin
37
 * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
38 39 40 41
 */
struct pinctrl_pin_desc {
	unsigned number;
	const char *name;
42
	void *drv_data;
43 44 45 46 47 48 49 50 51 52 53 54 55
};

/* Convenience macro to define a single named or anonymous pin descriptor */
#define PINCTRL_PIN(a, b) { .number = a, .name = b }
#define PINCTRL_PIN_ANON(a) { .number = a }

/**
 * struct pinctrl_gpio_range - each pin controller can provide subranges of
 * the GPIO number space to be handled by the controller
 * @node: list node for internal use
 * @name: a name for the chip in this range
 * @id: an ID number for the chip in this range
 * @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 59 60 61 62 63 64 65
 * @npins: number of pins in the GPIO range, including the base number
 * @gc: an optional pointer to a gpio_chip
 */
struct pinctrl_gpio_range {
	struct list_head node;
	const char *name;
	unsigned int id;
	unsigned int base;
66
	unsigned int pin_base;
67
	unsigned const *pins;
68 69 70 71 72 73 74
	unsigned int npins;
	struct gpio_chip *gc;
};

/**
 * struct pinctrl_ops - global pin control operations, to be implemented by
 * pin controller drivers.
75
 * @get_groups_count: Returns the count of total number of groups registered.
76 77 78 79 80
 * @get_group_name: return the group name of the pin group
 * @get_group_pins: return an array of pins corresponding to a certain
 *	group selector @pins, and the size of the array in @num_pins
 * @pin_dbg_show: optional debugfs display hook that will provide per-device
 *	info for a certain pin in debugfs
81 82 83 84 85 86 87 88 89
 * @dt_node_to_map: parse a device tree "pin configuration node", and create
 *	mapping table entries for it. These are returned through the @map and
 *	@num_maps output parameters. This function is optional, and may be
 *	omitted for pinctrl drivers that do not support device tree.
 * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
 *	top-level @map pointer must be freed, along with any dynamically
 *	allocated members of the mapping table entries themselves. This
 *	function is optional, and may be omitted for pinctrl drivers that do
 *	not support device tree.
90 91
 */
struct pinctrl_ops {
92
	int (*get_groups_count) (struct pinctrl_dev *pctldev);
93 94 95 96
	const char *(*get_group_name) (struct pinctrl_dev *pctldev,
				       unsigned selector);
	int (*get_group_pins) (struct pinctrl_dev *pctldev,
			       unsigned selector,
97 98
			       const unsigned **pins,
			       unsigned *num_pins);
99 100
	void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
			  unsigned offset);
101 102 103 104 105
	int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
			       struct device_node *np_config,
			       struct pinctrl_map **map, unsigned *num_maps);
	void (*dt_free_map) (struct pinctrl_dev *pctldev,
			     struct pinctrl_map *map, unsigned num_maps);
106 107 108 109 110 111 112 113 114 115 116 117
};

/**
 * struct pinctrl_desc - pin controller descriptor, register this to pin
 * control subsystem
 * @name: name for the pin controller
 * @pins: an array of pin descriptors describing all the pins handled by
 *	this pin controller
 * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
 *	of the pins field above
 * @pctlops: pin control operation vtable, to support global concepts like
 *	grouping of pins, this is optional.
118 119 120
 * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
 * @confops: pin config operations vtable, if you support pin configuration in
 *	your driver
121
 * @owner: module providing the pin controller, used for refcounting
122 123 124 125 126 127
 * @num_custom_params: Number of driver-specific custom parameters to be parsed
 *	from the hardware description
 * @custom_params: List of driver_specific custom parameters to be parsed from
 *	the hardware description
 * @custom_conf_items: Information how to print @params in debugfs, must be
 *	the same size as the @custom_params, i.e. @num_custom_params
128 129 130
 */
struct pinctrl_desc {
	const char *name;
131
	const struct pinctrl_pin_desc *pins;
132
	unsigned int npins;
133 134 135
	const struct pinctrl_ops *pctlops;
	const struct pinmux_ops *pmxops;
	const struct pinconf_ops *confops;
136
	struct module *owner;
137 138 139 140
#ifdef CONFIG_GENERIC_PINCONF
	unsigned int num_custom_params;
	const struct pinconf_generic_params *custom_params;
	const struct pin_config_item *custom_conf_items;
141
#endif
142 143 144
};

/* External interface to pin controller */
145 146 147 148

extern int pinctrl_register_and_init(struct pinctrl_desc *pctldesc,
				     struct device *dev, void *driver_data,
				     struct pinctrl_dev **pctldev);
149
extern int pinctrl_enable(struct pinctrl_dev *pctldev);
150

151
/* Please use pinctrl_register_and_init() and pinctrl_enable() instead */
152 153
extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
				struct device *dev, void *driver_data);
154

155
extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
156 157 158 159 160 161 162

extern int devm_pinctrl_register_and_init(struct device *dev,
				struct pinctrl_desc *pctldesc,
				void *driver_data,
				struct pinctrl_dev **pctldev);

/* Please use devm_pinctrl_register_and_init() instead */
163 164 165
extern struct pinctrl_dev *devm_pinctrl_register(struct device *dev,
				struct pinctrl_desc *pctldesc,
				void *driver_data);
166

167 168 169
extern void devm_pinctrl_unregister(struct device *dev,
				struct pinctrl_dev *pctldev);

170 171 172
extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin);
extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
				struct pinctrl_gpio_range *range);
173 174 175
extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
				struct pinctrl_gpio_range *ranges,
				unsigned nranges);
176 177
extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
				struct pinctrl_gpio_range *range);
178

L
Linus Walleij 已提交
179
extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
180
		struct pinctrl_gpio_range *range);
181 182 183
extern struct pinctrl_gpio_range *
pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
				 unsigned int pin);
184 185 186
extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
				const char *pin_group, const unsigned **pins,
				unsigned *num_pins);
187 188

#ifdef CONFIG_OF
189
extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
190 191
#else
static inline
192
struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
193 194 195 196 197
{
	return NULL;
}
#endif /* CONFIG_OF */

198
extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
199
extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
200 201 202
extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
#else

203
struct pinctrl_dev;
204

205
/* Sufficiently stupid default functions when pinctrl is not in use */
206 207 208 209 210 211 212 213
static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin)
{
	return pin >= 0;
}

#endif /* !CONFIG_PINCTRL */

#endif /* __LINUX_PINCTRL_PINCTRL_H */