Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 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 <linus.walleij@linaro.org> |
| 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 | #ifdef CONFIG_PINCTRL |
| 16 | |
| 17 | #include <linux/radix-tree.h> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 18 | #include <linux/list.h> |
| 19 | #include <linux/seq_file.h> |
David Howells | a1ce392 | 2012-10-02 18:01:25 +0100 | [diff] [blame] | 20 | #include <linux/pinctrl/pinctrl-state.h> |
Stephen Warren | 46919ae | 2012-03-01 18:48:32 -0700 | [diff] [blame] | 21 | |
Stephen Warren | 0acfb07 | 2012-03-06 12:12:12 -0700 | [diff] [blame] | 22 | struct device; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 23 | struct pinctrl_dev; |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 24 | struct pinctrl_map; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 25 | struct pinmux_ops; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 26 | struct pinconf_ops; |
Soren Brinkmann | dd4d01f | 2015-01-09 07:43:46 -0800 | [diff] [blame^] | 27 | struct pin_config_item; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 28 | struct gpio_chip; |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 29 | struct device_node; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * struct pinctrl_pin_desc - boards/machines provide information on their |
| 33 | * pins, pads or other muxable units in this struct |
| 34 | * @number: unique pin number from the global pin number space |
| 35 | * @name: a name for this pin |
Sherman Yin | a30d5421 | 2013-12-20 18:13:33 -0800 | [diff] [blame] | 36 | * @drv_data: driver-defined per-pin data. pinctrl core does not touch this |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 37 | */ |
| 38 | struct pinctrl_pin_desc { |
| 39 | unsigned number; |
| 40 | const char *name; |
Sherman Yin | a30d5421 | 2013-12-20 18:13:33 -0800 | [diff] [blame] | 41 | void *drv_data; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 42 | }; |
| 43 | |
| 44 | /* Convenience macro to define a single named or anonymous pin descriptor */ |
| 45 | #define PINCTRL_PIN(a, b) { .number = a, .name = b } |
| 46 | #define PINCTRL_PIN_ANON(a) { .number = a } |
| 47 | |
| 48 | /** |
| 49 | * struct pinctrl_gpio_range - each pin controller can provide subranges of |
| 50 | * the GPIO number space to be handled by the controller |
| 51 | * @node: list node for internal use |
| 52 | * @name: a name for the chip in this range |
| 53 | * @id: an ID number for the chip in this range |
| 54 | * @base: base offset of the GPIO range |
Christian Ruppert | 56a5991 | 2013-06-14 10:24:48 +0200 | [diff] [blame] | 55 | * @pin_base: base pin number of the GPIO range if pins == NULL |
Christian Ruppert | c8587ee | 2013-06-13 14:55:31 +0200 | [diff] [blame] | 56 | * @pins: enumeration of pins in GPIO range or NULL |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 57 | * @npins: number of pins in the GPIO range, including the base number |
| 58 | * @gc: an optional pointer to a gpio_chip |
| 59 | */ |
| 60 | struct pinctrl_gpio_range { |
| 61 | struct list_head node; |
| 62 | const char *name; |
| 63 | unsigned int id; |
| 64 | unsigned int base; |
Chanho Park | 3c739ad | 2011-11-11 18:47:58 +0900 | [diff] [blame] | 65 | unsigned int pin_base; |
Christian Ruppert | c8587ee | 2013-06-13 14:55:31 +0200 | [diff] [blame] | 66 | unsigned const *pins; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 67 | unsigned int npins; |
| 68 | struct gpio_chip *gc; |
| 69 | }; |
| 70 | |
| 71 | /** |
| 72 | * struct pinctrl_ops - global pin control operations, to be implemented by |
| 73 | * pin controller drivers. |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 74 | * @get_groups_count: Returns the count of total number of groups registered. |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 75 | * @get_group_name: return the group name of the pin group |
| 76 | * @get_group_pins: return an array of pins corresponding to a certain |
| 77 | * group selector @pins, and the size of the array in @num_pins |
| 78 | * @pin_dbg_show: optional debugfs display hook that will provide per-device |
| 79 | * info for a certain pin in debugfs |
Stephen Warren | 02ae6da | 2012-04-26 10:18:52 -0600 | [diff] [blame] | 80 | * @dt_node_to_map: parse a device tree "pin configuration node", and create |
| 81 | * mapping table entries for it. These are returned through the @map and |
| 82 | * @num_maps output parameters. This function is optional, and may be |
| 83 | * omitted for pinctrl drivers that do not support device tree. |
| 84 | * @dt_free_map: free mapping table entries created via @dt_node_to_map. The |
| 85 | * top-level @map pointer must be freed, along with any dynamically |
| 86 | * allocated members of the mapping table entries themselves. This |
| 87 | * function is optional, and may be omitted for pinctrl drivers that do |
| 88 | * not support device tree. |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 89 | */ |
| 90 | struct pinctrl_ops { |
Viresh Kumar | d1e90e9 | 2012-03-30 11:25:40 +0530 | [diff] [blame] | 91 | int (*get_groups_count) (struct pinctrl_dev *pctldev); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 92 | const char *(*get_group_name) (struct pinctrl_dev *pctldev, |
| 93 | unsigned selector); |
| 94 | int (*get_group_pins) (struct pinctrl_dev *pctldev, |
| 95 | unsigned selector, |
Stephen Warren | a5818a8 | 2011-10-19 16:19:25 -0600 | [diff] [blame] | 96 | const unsigned **pins, |
| 97 | unsigned *num_pins); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 98 | void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s, |
| 99 | unsigned offset); |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame] | 100 | int (*dt_node_to_map) (struct pinctrl_dev *pctldev, |
| 101 | struct device_node *np_config, |
| 102 | struct pinctrl_map **map, unsigned *num_maps); |
| 103 | void (*dt_free_map) (struct pinctrl_dev *pctldev, |
| 104 | struct pinctrl_map *map, unsigned num_maps); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 105 | }; |
| 106 | |
| 107 | /** |
| 108 | * struct pinctrl_desc - pin controller descriptor, register this to pin |
| 109 | * control subsystem |
| 110 | * @name: name for the pin controller |
| 111 | * @pins: an array of pin descriptors describing all the pins handled by |
| 112 | * this pin controller |
| 113 | * @npins: number of descriptors in the array, usually just ARRAY_SIZE() |
| 114 | * of the pins field above |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 115 | * @pctlops: pin control operation vtable, to support global concepts like |
| 116 | * grouping of pins, this is optional. |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 117 | * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver |
| 118 | * @confops: pin config operations vtable, if you support pin configuration in |
| 119 | * your driver |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 120 | * @owner: module providing the pin controller, used for refcounting |
Soren Brinkmann | dd4d01f | 2015-01-09 07:43:46 -0800 | [diff] [blame^] | 121 | * @num_dt_params: Number of driver-specific DT parameters |
| 122 | * @params: List of DT parameters |
| 123 | * @conf_items: Information how to print @params in debugfs |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 124 | */ |
| 125 | struct pinctrl_desc { |
| 126 | const char *name; |
| 127 | struct pinctrl_pin_desc const *pins; |
| 128 | unsigned int npins; |
Laurent Pinchart | 022ab14 | 2013-02-16 10:25:07 +0100 | [diff] [blame] | 129 | const struct pinctrl_ops *pctlops; |
| 130 | const struct pinmux_ops *pmxops; |
| 131 | const struct pinconf_ops *confops; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 132 | struct module *owner; |
Soren Brinkmann | dd4d01f | 2015-01-09 07:43:46 -0800 | [diff] [blame^] | 133 | #if defined(CONFIG_GENERIC_PINCONF) && defined(CONFIG_OF) |
| 134 | unsigned int num_dt_params; |
| 135 | const struct pinconf_generic_dt_params *params; |
| 136 | const struct pin_config_item *conf_items; |
| 137 | #endif |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | /* External interface to pin controller */ |
| 141 | extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, |
| 142 | struct device *dev, void *driver_data); |
| 143 | extern void pinctrl_unregister(struct pinctrl_dev *pctldev); |
| 144 | extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin); |
| 145 | extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, |
| 146 | struct pinctrl_gpio_range *range); |
Dong Aisheng | 3e5e00b | 2012-05-23 21:22:41 +0800 | [diff] [blame] | 147 | extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev, |
| 148 | struct pinctrl_gpio_range *ranges, |
| 149 | unsigned nranges); |
Viresh Kumar | 7e10ee6 | 2012-10-27 15:21:35 +0530 | [diff] [blame] | 150 | extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, |
| 151 | struct pinctrl_gpio_range *range); |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 152 | |
Linus Walleij | 192c369 | 2012-11-20 14:03:37 +0100 | [diff] [blame] | 153 | extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname, |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 154 | struct pinctrl_gpio_range *range); |
Linus Walleij | 9afbefb | 2012-11-20 14:25:07 +0100 | [diff] [blame] | 155 | extern struct pinctrl_gpio_range * |
| 156 | pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev, |
| 157 | unsigned int pin); |
Christian Ruppert | 586a87e | 2013-10-15 15:37:54 +0200 | [diff] [blame] | 158 | extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev, |
| 159 | const char *pin_group, const unsigned **pins, |
| 160 | unsigned *num_pins); |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 161 | |
| 162 | #ifdef CONFIG_OF |
Linus Walleij | 1e63d7b | 2012-11-06 16:03:35 +0100 | [diff] [blame] | 163 | extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np); |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 164 | #else |
| 165 | static inline |
Linus Walleij | 1e63d7b | 2012-11-06 16:03:35 +0100 | [diff] [blame] | 166 | struct pinctrl_dev *of_pinctrl_get(struct device_node *np) |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 167 | { |
| 168 | return NULL; |
| 169 | } |
Shiraz Hashim | f23f151 | 2012-10-27 15:21:36 +0530 | [diff] [blame] | 170 | #endif /* CONFIG_OF */ |
| 171 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 172 | extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev); |
Haojian Zhuang | d6e99ab | 2013-01-18 15:31:06 +0800 | [diff] [blame] | 173 | extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 174 | extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev); |
| 175 | #else |
| 176 | |
Barry Song | e0e2075 | 2011-10-27 20:38:24 -0700 | [diff] [blame] | 177 | struct pinctrl_dev; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 178 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 179 | /* Sufficiently stupid default functions when pinctrl is not in use */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 180 | static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin) |
| 181 | { |
| 182 | return pin >= 0; |
| 183 | } |
| 184 | |
| 185 | #endif /* !CONFIG_PINCTRL */ |
| 186 | |
| 187 | #endif /* __LINUX_PINCTRL_PINCTRL_H */ |