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