2 * Interface the pinctrl subsystem
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.
8 * Author: Linus Walleij <linus.walleij@linaro.org>
10 * License terms: GNU General Public License (GPL) version 2
12 #ifndef __LINUX_PINCTRL_PINCTRL_H
13 #define __LINUX_PINCTRL_PINCTRL_H
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>
28 struct pin_config_item
;
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
39 struct pinctrl_pin_desc
{
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 }
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
61 struct pinctrl_gpio_range
{
62 struct list_head node
;
66 unsigned int pin_base
;
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.
92 int (*get_groups_count
) (struct pinctrl_dev
*pctldev
);
93 const char *(*get_group_name
) (struct pinctrl_dev
*pctldev
,
95 int (*get_group_pins
) (struct pinctrl_dev
*pctldev
,
97 const unsigned **pins
,
99 void (*pin_dbg_show
) (struct pinctrl_dev
*pctldev
, struct seq_file
*s
,
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
);
109 * struct pinctrl_desc - pin controller descriptor, register this to pin
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
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
129 struct pinctrl_desc
{
131 const struct pinctrl_pin_desc
*pins
;
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
;
144 /* External interface to pin controller */
146 extern int pinctrl_register_and_init(struct pinctrl_desc
*pctldesc
,
147 struct device
*dev
, void *driver_data
,
148 struct pinctrl_dev
**pctldev
);
149 extern int pinctrl_enable(struct pinctrl_dev
*pctldev
);
151 /* Please use pinctrl_register_and_init() and pinctrl_enable() instead */
152 extern struct pinctrl_dev
*pinctrl_register(struct pinctrl_desc
*pctldesc
,
153 struct device
*dev
, void *driver_data
);
155 extern void pinctrl_unregister(struct pinctrl_dev
*pctldev
);
157 extern int devm_pinctrl_register_and_init(struct device
*dev
,
158 struct pinctrl_desc
*pctldesc
,
160 struct pinctrl_dev
**pctldev
);
162 /* Please use devm_pinctrl_register_and_init() instead */
163 extern struct pinctrl_dev
*devm_pinctrl_register(struct device
*dev
,
164 struct pinctrl_desc
*pctldesc
,
167 extern void devm_pinctrl_unregister(struct device
*dev
,
168 struct pinctrl_dev
*pctldev
);
170 extern bool pin_is_valid(struct pinctrl_dev
*pctldev
, int pin
);
171 extern void pinctrl_add_gpio_range(struct pinctrl_dev
*pctldev
,
172 struct pinctrl_gpio_range
*range
);
173 extern void pinctrl_add_gpio_ranges(struct pinctrl_dev
*pctldev
,
174 struct pinctrl_gpio_range
*ranges
,
176 extern void pinctrl_remove_gpio_range(struct pinctrl_dev
*pctldev
,
177 struct pinctrl_gpio_range
*range
);
179 extern struct pinctrl_dev
*pinctrl_find_and_add_gpio_range(const char *devname
,
180 struct pinctrl_gpio_range
*range
);
181 extern struct pinctrl_gpio_range
*
182 pinctrl_find_gpio_range_from_pin(struct pinctrl_dev
*pctldev
,
184 extern int pinctrl_get_group_pins(struct pinctrl_dev
*pctldev
,
185 const char *pin_group
, const unsigned **pins
,
189 extern struct pinctrl_dev
*of_pinctrl_get(struct device_node
*np
);
192 struct pinctrl_dev
*of_pinctrl_get(struct device_node
*np
)
196 #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 extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev
*pctldev
);
205 /* Sufficiently stupid default functions when pinctrl is not in use */
206 static inline bool pin_is_valid(struct pinctrl_dev
*pctldev
, int pin
)
211 #endif /* !CONFIG_PINCTRL */
213 #endif /* __LINUX_PINCTRL_PINCTRL_H */