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