Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

at ee9dce44362b2d8132c32964656ab6dff7dfbc6a 254 lines 8.9 kB view raw
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 pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, 191 struct pinctrl_gpio_range *range); 192extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev, 193 struct pinctrl_gpio_range *ranges, 194 unsigned int nranges); 195extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, 196 struct pinctrl_gpio_range *range); 197 198extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname, 199 struct pinctrl_gpio_range *range); 200extern struct pinctrl_gpio_range * 201pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev, 202 unsigned int pin); 203extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev, 204 const char *pin_group, const unsigned int **pins, 205 unsigned int *num_pins); 206 207#define PINFUNCTION_FLAG_GPIO BIT(0) 208 209/** 210 * struct pinfunction - Description about a function 211 * @name: Name of the function 212 * @groups: An array of groups for this function 213 * @ngroups: Number of groups in @groups 214 * @flags: Additional pin function flags 215 */ 216struct pinfunction { 217 const char *name; 218 const char * const *groups; 219 size_t ngroups; 220 unsigned long flags; 221}; 222 223/* Convenience macro to define a single named pinfunction */ 224#define PINCTRL_PINFUNCTION(_name, _groups, _ngroups) \ 225(struct pinfunction) { \ 226 .name = (_name), \ 227 .groups = (_groups), \ 228 .ngroups = (_ngroups), \ 229 } 230 231/* Same as PINCTRL_PINFUNCTION() but for the GPIO category of functions */ 232#define PINCTRL_GPIO_PINFUNCTION(_name, _groups, _ngroups) \ 233(struct pinfunction) { \ 234 .name = (_name), \ 235 .groups = (_groups), \ 236 .ngroups = (_ngroups), \ 237 .flags = PINFUNCTION_FLAG_GPIO, \ 238 } 239 240#if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL) 241extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np); 242#else 243static inline 244struct pinctrl_dev *of_pinctrl_get(struct device_node *np) 245{ 246 return NULL; 247} 248#endif /* CONFIG_OF */ 249 250extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev); 251extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev); 252extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev); 253 254#endif /* __LINUX_PINCTRL_PINCTRL_H */