Thomas Gleixner | af873fc | 2019-05-28 09:57:21 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Machine interface for the pinctrl subsystem. |
| 4 | * |
| 5 | * Copyright (C) 2011 ST-Ericsson SA |
| 6 | * Written on behalf of Linaro for ST-Ericsson |
| 7 | * Based on bits of regulator core, gpio core and clk core |
| 8 | * |
| 9 | * Author: Linus Walleij <linus.walleij@linaro.org> |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 10 | */ |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 11 | #ifndef __LINUX_PINCTRL_MACHINE_H |
| 12 | #define __LINUX_PINCTRL_MACHINE_H |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 13 | |
Stephen Warren | 22f099d | 2012-03-16 14:54:23 -0600 | [diff] [blame] | 14 | #include <linux/bug.h> |
| 15 | |
David Howells | a1ce392 | 2012-10-02 18:01:25 +0100 | [diff] [blame] | 16 | #include <linux/pinctrl/pinctrl-state.h> |
Stephen Warren | 46919ae | 2012-03-01 18:48:32 -0700 | [diff] [blame] | 17 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 18 | enum pinctrl_map_type { |
| 19 | PIN_MAP_TYPE_INVALID, |
| 20 | PIN_MAP_TYPE_DUMMY_STATE, |
| 21 | PIN_MAP_TYPE_MUX_GROUP, |
| 22 | PIN_MAP_TYPE_CONFIGS_PIN, |
| 23 | PIN_MAP_TYPE_CONFIGS_GROUP, |
| 24 | }; |
| 25 | |
| 26 | /** |
| 27 | * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP |
| 28 | * @group: the name of the group whose mux function is to be configured. This |
| 29 | * field may be left NULL, and the first applicable group for the function |
| 30 | * will be used. |
| 31 | * @function: the mux function to select for the group |
| 32 | */ |
| 33 | struct pinctrl_map_mux { |
| 34 | const char *group; |
| 35 | const char *function; |
| 36 | }; |
| 37 | |
| 38 | /** |
| 39 | * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_* |
| 40 | * @group_or_pin: the name of the pin or group whose configuration parameters |
| 41 | * are to be configured. |
| 42 | * @configs: a pointer to an array of config parameters/values to program into |
| 43 | * hardware. Each individual pin controller defines the format and meaning |
| 44 | * of config parameters. |
| 45 | * @num_configs: the number of entries in array @configs |
| 46 | */ |
| 47 | struct pinctrl_map_configs { |
| 48 | const char *group_or_pin; |
| 49 | unsigned long *configs; |
| 50 | unsigned num_configs; |
| 51 | }; |
| 52 | |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 53 | /** |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 54 | * struct pinctrl_map - boards/machines shall provide this map for devices |
Stephen Warren | 806d314 | 2012-02-23 17:04:39 -0700 | [diff] [blame] | 55 | * @dev_name: the name of the device using this specific mapping, the name |
| 56 | * must be the same as in your struct device*. If this name is set to the |
| 57 | * same name as the pin controllers own dev_name(), the map entry will be |
| 58 | * hogged by the driver itself upon registration |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 59 | * @name: the name of this specific map entry for the particular machine. |
Stephen Warren | 6e5e959 | 2012-03-02 13:05:47 -0700 | [diff] [blame] | 60 | * This is the parameter passed to pinmux_lookup_state() |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 61 | * @type: the type of mapping table entry |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 62 | * @ctrl_dev_name: the name of the device controlling this specific mapping, |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 63 | * the name must be the same as in your struct device*. This field is not |
| 64 | * used for PIN_MAP_TYPE_DUMMY_STATE |
| 65 | * @data: Data specific to the mapping type |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 66 | */ |
Linus Walleij | e93bcee | 2012-02-09 07:23:28 +0100 | [diff] [blame] | 67 | struct pinctrl_map { |
Stephen Warren | 806d314 | 2012-02-23 17:04:39 -0700 | [diff] [blame] | 68 | const char *dev_name; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 69 | const char *name; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 70 | enum pinctrl_map_type type; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 71 | const char *ctrl_dev_name; |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 72 | union { |
| 73 | struct pinctrl_map_mux mux; |
| 74 | struct pinctrl_map_configs configs; |
| 75 | } data; |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 76 | }; |
| 77 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 78 | /* Convenience macros to create mapping table entries */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 79 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 80 | #define PIN_MAP_DUMMY_STATE(dev, state) \ |
| 81 | { \ |
| 82 | .dev_name = dev, \ |
| 83 | .name = state, \ |
| 84 | .type = PIN_MAP_TYPE_DUMMY_STATE, \ |
| 85 | } |
Stephen Warren | 1ddb6ff | 2011-12-09 16:59:03 -0700 | [diff] [blame] | 86 | |
Stephen Warren | 1e2082b | 2012-03-02 13:05:48 -0700 | [diff] [blame] | 87 | #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \ |
| 88 | { \ |
| 89 | .dev_name = dev, \ |
| 90 | .name = state, \ |
| 91 | .type = PIN_MAP_TYPE_MUX_GROUP, \ |
| 92 | .ctrl_dev_name = pinctrl, \ |
| 93 | .data.mux = { \ |
| 94 | .group = grp, \ |
| 95 | .function = func, \ |
| 96 | }, \ |
| 97 | } |
| 98 | |
| 99 | #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \ |
| 100 | PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func) |
| 101 | |
| 102 | #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \ |
| 103 | PIN_MAP_MUX_GROUP(dev, state, dev, grp, func) |
| 104 | |
| 105 | #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \ |
| 106 | PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func) |
| 107 | |
| 108 | #define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \ |
| 109 | { \ |
| 110 | .dev_name = dev, \ |
| 111 | .name = state, \ |
| 112 | .type = PIN_MAP_TYPE_CONFIGS_PIN, \ |
| 113 | .ctrl_dev_name = pinctrl, \ |
| 114 | .data.configs = { \ |
| 115 | .group_or_pin = pin, \ |
| 116 | .configs = cfgs, \ |
| 117 | .num_configs = ARRAY_SIZE(cfgs), \ |
| 118 | }, \ |
| 119 | } |
| 120 | |
| 121 | #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \ |
| 122 | PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs) |
| 123 | |
| 124 | #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \ |
| 125 | PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs) |
| 126 | |
| 127 | #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \ |
| 128 | PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs) |
| 129 | |
| 130 | #define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \ |
| 131 | { \ |
| 132 | .dev_name = dev, \ |
| 133 | .name = state, \ |
| 134 | .type = PIN_MAP_TYPE_CONFIGS_GROUP, \ |
| 135 | .ctrl_dev_name = pinctrl, \ |
| 136 | .data.configs = { \ |
| 137 | .group_or_pin = grp, \ |
| 138 | .configs = cfgs, \ |
| 139 | .num_configs = ARRAY_SIZE(cfgs), \ |
| 140 | }, \ |
| 141 | } |
| 142 | |
| 143 | #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \ |
| 144 | PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs) |
| 145 | |
| 146 | #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \ |
| 147 | PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs) |
| 148 | |
| 149 | #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \ |
| 150 | PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs) |
Linus Walleij | 2375019 | 2011-12-14 09:30:08 +0100 | [diff] [blame] | 151 | |
Dong Aisheng | 6974f1f | 2012-04-05 17:07:23 +0800 | [diff] [blame] | 152 | #ifdef CONFIG_PINCTRL |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 153 | |
Masahiro Yamada | 3f713b7 | 2017-08-04 11:22:31 +0900 | [diff] [blame] | 154 | extern int pinctrl_register_mappings(const struct pinctrl_map *map, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 155 | unsigned num_maps); |
Hans de Goede | c72bed2 | 2019-12-16 21:51:18 +0100 | [diff] [blame] | 156 | extern void pinctrl_unregister_mappings(const struct pinctrl_map *map); |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 157 | extern void pinctrl_provide_dummies(void); |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 158 | #else |
| 159 | |
Masahiro Yamada | 3f713b7 | 2017-08-04 11:22:31 +0900 | [diff] [blame] | 160 | static inline int pinctrl_register_mappings(const struct pinctrl_map *map, |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 161 | unsigned num_maps) |
| 162 | { |
| 163 | return 0; |
| 164 | } |
| 165 | |
Hans de Goede | c72bed2 | 2019-12-16 21:51:18 +0100 | [diff] [blame] | 166 | static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map) |
| 167 | { |
| 168 | } |
| 169 | |
Dong Aisheng | 5b3aa5f | 2012-04-26 16:15:50 +0800 | [diff] [blame] | 170 | static inline void pinctrl_provide_dummies(void) |
| 171 | { |
| 172 | } |
Linus Walleij | dd51270 | 2012-04-24 15:20:02 +0200 | [diff] [blame] | 173 | #endif /* !CONFIG_PINCTRL */ |
Linus Walleij | 2744e8a | 2011-05-02 20:50:54 +0200 | [diff] [blame] | 174 | #endif |