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> |
Linus Walleij | 9a01be1 | 2012-03-06 21:15:51 +0100 | [diff] [blame] | 20 | #include "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 |
Chanho Park | 3c739ad | 2011-11-11 18:47:58 +0900 | [diff] [blame] | 52 | * @pin_base: base pin number of the GPIO range |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 53 | * @npins: number of pins in the GPIO range, including the base number |
| 54 | * @gc: an optional pointer to a gpio_chip |
| 55 | */ |
| 56 | struct pinctrl_gpio_range { |
| 57 | struct list_head node; |
| 58 | const char *name; |
| 59 | unsigned int id; |
| 60 | unsigned int base; |
Chanho Park | 3c739ad | 2011-11-11 18:47:58 +0900 | [diff] [blame] | 61 | unsigned int pin_base; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 62 | unsigned int npins; |
| 63 | struct gpio_chip *gc; |
| 64 | }; |
| 65 | |
| 66 | /** |
| 67 | * struct pinctrl_ops - global pin control operations, to be implemented by |
| 68 | * pin controller drivers. |
| 69 | * @list_groups: list the number of selectable named groups available |
| 70 | * in this pinmux driver, the core will begin on 0 and call this |
| 71 | * repeatedly as long as it returns >= 0 to enumerate the groups |
| 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 |
| 77 | */ |
| 78 | struct pinctrl_ops { |
| 79 | int (*list_groups) (struct pinctrl_dev *pctldev, unsigned selector); |
| 80 | const char *(*get_group_name) (struct pinctrl_dev *pctldev, |
| 81 | unsigned selector); |
| 82 | int (*get_group_pins) (struct pinctrl_dev *pctldev, |
| 83 | unsigned selector, |
Stephen Warren | a5818a8 | 2011-10-19 16:19:25 -0600 | [diff] [blame] | 84 | const unsigned **pins, |
| 85 | unsigned *num_pins); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 86 | void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s, |
| 87 | unsigned offset); |
Stephen Warren | 57291ce | 2012-03-23 10:29:46 -0600 | [diff] [blame^] | 88 | int (*dt_node_to_map) (struct pinctrl_dev *pctldev, |
| 89 | struct device_node *np_config, |
| 90 | struct pinctrl_map **map, unsigned *num_maps); |
| 91 | void (*dt_free_map) (struct pinctrl_dev *pctldev, |
| 92 | struct pinctrl_map *map, unsigned num_maps); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 93 | }; |
| 94 | |
| 95 | /** |
| 96 | * struct pinctrl_desc - pin controller descriptor, register this to pin |
| 97 | * control subsystem |
| 98 | * @name: name for the pin controller |
| 99 | * @pins: an array of pin descriptors describing all the pins handled by |
| 100 | * this pin controller |
| 101 | * @npins: number of descriptors in the array, usually just ARRAY_SIZE() |
| 102 | * of the pins field above |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 103 | * @pctlops: pin control operation vtable, to support global concepts like |
| 104 | * grouping of pins, this is optional. |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 105 | * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver |
| 106 | * @confops: pin config operations vtable, if you support pin configuration in |
| 107 | * your driver |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 108 | * @owner: module providing the pin controller, used for refcounting |
| 109 | */ |
| 110 | struct pinctrl_desc { |
| 111 | const char *name; |
| 112 | struct pinctrl_pin_desc const *pins; |
| 113 | unsigned int npins; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 114 | struct pinctrl_ops *pctlops; |
| 115 | struct pinmux_ops *pmxops; |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 116 | struct pinconf_ops *confops; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 117 | struct module *owner; |
| 118 | }; |
| 119 | |
| 120 | /* External interface to pin controller */ |
| 121 | extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc, |
| 122 | struct device *dev, void *driver_data); |
| 123 | extern void pinctrl_unregister(struct pinctrl_dev *pctldev); |
| 124 | extern bool pin_is_valid(struct pinctrl_dev *pctldev, int pin); |
| 125 | extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev, |
| 126 | struct pinctrl_gpio_range *range); |
| 127 | extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev, |
| 128 | struct pinctrl_gpio_range *range); |
| 129 | extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev); |
| 130 | extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev); |
| 131 | #else |
| 132 | |
Barry Song | e0e2075 | 2011-10-27 20:38:24 -0700 | [diff] [blame] | 133 | struct pinctrl_dev; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 134 | |
Linus Walleij | ae6b4d8 | 2011-10-19 18:14:33 +0200 | [diff] [blame] | 135 | /* Sufficiently stupid default functions when pinctrl is not in use */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 136 | static inline bool pin_is_valid(struct pinctrl_dev *pctldev, int pin) |
| 137 | { |
| 138 | return pin >= 0; |
| 139 | } |
| 140 | |
| 141 | #endif /* !CONFIG_PINCTRL */ |
| 142 | |
| 143 | #endif /* __LINUX_PINCTRL_PINCTRL_H */ |