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