1 /* SPDX-License-Identifier: GPL-2.0-only */ 1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* 2 /* 3 * Machine interface for the pinctrl subsystem 3 * Machine interface for the pinctrl subsystem. 4 * 4 * 5 * Copyright (C) 2011 ST-Ericsson SA 5 * Copyright (C) 2011 ST-Ericsson SA 6 * Written on behalf of Linaro for ST-Ericsson 6 * Written on behalf of Linaro for ST-Ericsson 7 * Based on bits of regulator core, gpio core 7 * Based on bits of regulator core, gpio core and clk core 8 * 8 * 9 * Author: Linus Walleij <linus.walleij@linaro 9 * Author: Linus Walleij <linus.walleij@linaro.org> 10 */ 10 */ 11 #ifndef __LINUX_PINCTRL_MACHINE_H 11 #ifndef __LINUX_PINCTRL_MACHINE_H 12 #define __LINUX_PINCTRL_MACHINE_H 12 #define __LINUX_PINCTRL_MACHINE_H 13 13 14 #include <linux/array_size.h> !! 14 #include <linux/kernel.h> /* ARRAY_SIZE() */ 15 15 16 #include <linux/pinctrl/pinctrl-state.h> 16 #include <linux/pinctrl/pinctrl-state.h> 17 17 18 enum pinctrl_map_type { 18 enum pinctrl_map_type { 19 PIN_MAP_TYPE_INVALID, 19 PIN_MAP_TYPE_INVALID, 20 PIN_MAP_TYPE_DUMMY_STATE, 20 PIN_MAP_TYPE_DUMMY_STATE, 21 PIN_MAP_TYPE_MUX_GROUP, 21 PIN_MAP_TYPE_MUX_GROUP, 22 PIN_MAP_TYPE_CONFIGS_PIN, 22 PIN_MAP_TYPE_CONFIGS_PIN, 23 PIN_MAP_TYPE_CONFIGS_GROUP, 23 PIN_MAP_TYPE_CONFIGS_GROUP, 24 }; 24 }; 25 25 26 /** 26 /** 27 * struct pinctrl_map_mux - mapping table cont 27 * struct pinctrl_map_mux - mapping table content for MAP_TYPE_MUX_GROUP 28 * @group: the name of the group whose mux fun 28 * @group: the name of the group whose mux function is to be configured. This 29 * field may be left NULL, and the first 29 * field may be left NULL, and the first applicable group for the function 30 * will be used. 30 * will be used. 31 * @function: the mux function to select for t 31 * @function: the mux function to select for the group 32 */ 32 */ 33 struct pinctrl_map_mux { 33 struct pinctrl_map_mux { 34 const char *group; 34 const char *group; 35 const char *function; 35 const char *function; 36 }; 36 }; 37 37 38 /** 38 /** 39 * struct pinctrl_map_configs - mapping table 39 * struct pinctrl_map_configs - mapping table content for MAP_TYPE_CONFIGS_* 40 * @group_or_pin: the name of the pin or group 40 * @group_or_pin: the name of the pin or group whose configuration parameters 41 * are to be configured. 41 * are to be configured. 42 * @configs: a pointer to an array of config p 42 * @configs: a pointer to an array of config parameters/values to program into 43 * hardware. Each individual pin controll 43 * hardware. Each individual pin controller defines the format and meaning 44 * of config parameters. 44 * of config parameters. 45 * @num_configs: the number of entries in arra 45 * @num_configs: the number of entries in array @configs 46 */ 46 */ 47 struct pinctrl_map_configs { 47 struct pinctrl_map_configs { 48 const char *group_or_pin; 48 const char *group_or_pin; 49 unsigned long *configs; 49 unsigned long *configs; 50 unsigned int num_configs; !! 50 unsigned num_configs; 51 }; 51 }; 52 52 53 /** 53 /** 54 * struct pinctrl_map - boards/machines shall 54 * struct pinctrl_map - boards/machines shall provide this map for devices 55 * @dev_name: the name of the device using thi 55 * @dev_name: the name of the device using this specific mapping, the name 56 * must be the same as in your struct dev 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 d 57 * same name as the pin controllers own dev_name(), the map entry will be 58 * hogged by the driver itself upon regis 58 * hogged by the driver itself upon registration 59 * @name: the name of this specific map entry 59 * @name: the name of this specific map entry for the particular machine. 60 * This is the parameter passed to pinmux 60 * This is the parameter passed to pinmux_lookup_state() 61 * @type: the type of mapping table entry 61 * @type: the type of mapping table entry 62 * @ctrl_dev_name: the name of the device cont 62 * @ctrl_dev_name: the name of the device controlling this specific mapping, 63 * the name must be the same as in your s 63 * the name must be the same as in your struct device*. This field is not 64 * used for PIN_MAP_TYPE_DUMMY_STATE 64 * used for PIN_MAP_TYPE_DUMMY_STATE 65 * @data: Data specific to the mapping type 65 * @data: Data specific to the mapping type 66 */ 66 */ 67 struct pinctrl_map { 67 struct pinctrl_map { 68 const char *dev_name; 68 const char *dev_name; 69 const char *name; 69 const char *name; 70 enum pinctrl_map_type type; 70 enum pinctrl_map_type type; 71 const char *ctrl_dev_name; 71 const char *ctrl_dev_name; 72 union { 72 union { 73 struct pinctrl_map_mux mux; 73 struct pinctrl_map_mux mux; 74 struct pinctrl_map_configs con 74 struct pinctrl_map_configs configs; 75 } data; 75 } data; 76 }; 76 }; 77 77 78 /* Convenience macros to create mapping table 78 /* Convenience macros to create mapping table entries */ 79 79 80 #define PIN_MAP_DUMMY_STATE(dev, state) \ 80 #define PIN_MAP_DUMMY_STATE(dev, state) \ 81 { 81 { \ 82 .dev_name = dev, 82 .dev_name = dev, \ 83 .name = state, 83 .name = state, \ 84 .type = PIN_MAP_TYPE_DUMMY_STA 84 .type = PIN_MAP_TYPE_DUMMY_STATE, \ 85 } 85 } 86 86 87 #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, 87 #define PIN_MAP_MUX_GROUP(dev, state, pinctrl, grp, func) \ 88 { 88 { \ 89 .dev_name = dev, 89 .dev_name = dev, \ 90 .name = state, 90 .name = state, \ 91 .type = PIN_MAP_TYPE_MUX_GROUP 91 .type = PIN_MAP_TYPE_MUX_GROUP, \ 92 .ctrl_dev_name = pinctrl, 92 .ctrl_dev_name = pinctrl, \ 93 .data.mux = { 93 .data.mux = { \ 94 .group = grp, 94 .group = grp, \ 95 .function = func, 95 .function = func, \ 96 }, 96 }, \ 97 } 97 } 98 98 99 #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl 99 #define PIN_MAP_MUX_GROUP_DEFAULT(dev, pinctrl, grp, func) \ 100 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_D 100 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, func) 101 101 102 #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, 102 #define PIN_MAP_MUX_GROUP_HOG(dev, state, grp, func) \ 103 PIN_MAP_MUX_GROUP(dev, state, dev, grp 103 PIN_MAP_MUX_GROUP(dev, state, dev, grp, func) 104 104 105 #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp 105 #define PIN_MAP_MUX_GROUP_HOG_DEFAULT(dev, grp, func) \ 106 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_D 106 PIN_MAP_MUX_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, func) 107 107 108 #define PIN_MAP_CONFIGS_PIN(dev, state, pinctr 108 #define PIN_MAP_CONFIGS_PIN(dev, state, pinctrl, pin, cfgs) \ 109 { 109 { \ 110 .dev_name = dev, 110 .dev_name = dev, \ 111 .name = state, 111 .name = state, \ 112 .type = PIN_MAP_TYPE_CONFIGS_P 112 .type = PIN_MAP_TYPE_CONFIGS_PIN, \ 113 .ctrl_dev_name = pinctrl, 113 .ctrl_dev_name = pinctrl, \ 114 .data.configs = { 114 .data.configs = { \ 115 .group_or_pin = pin, 115 .group_or_pin = pin, \ 116 .configs = cfgs, 116 .configs = cfgs, \ 117 .num_configs = ARRAY_S 117 .num_configs = ARRAY_SIZE(cfgs), \ 118 }, 118 }, \ 119 } 119 } 120 120 121 #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinct 121 #define PIN_MAP_CONFIGS_PIN_DEFAULT(dev, pinctrl, pin, cfgs) \ 122 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE 122 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, pinctrl, pin, cfgs) 123 123 124 #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pi 124 #define PIN_MAP_CONFIGS_PIN_HOG(dev, state, pin, cfgs) \ 125 PIN_MAP_CONFIGS_PIN(dev, state, dev, p 125 PIN_MAP_CONFIGS_PIN(dev, state, dev, pin, cfgs) 126 126 127 #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, p 127 #define PIN_MAP_CONFIGS_PIN_HOG_DEFAULT(dev, pin, cfgs) \ 128 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE 128 PIN_MAP_CONFIGS_PIN(dev, PINCTRL_STATE_DEFAULT, dev, pin, cfgs) 129 129 130 #define PIN_MAP_CONFIGS_GROUP(dev, state, pinc 130 #define PIN_MAP_CONFIGS_GROUP(dev, state, pinctrl, grp, cfgs) \ 131 { 131 { \ 132 .dev_name = dev, 132 .dev_name = dev, \ 133 .name = state, 133 .name = state, \ 134 .type = PIN_MAP_TYPE_CONFIGS_G 134 .type = PIN_MAP_TYPE_CONFIGS_GROUP, \ 135 .ctrl_dev_name = pinctrl, 135 .ctrl_dev_name = pinctrl, \ 136 .data.configs = { 136 .data.configs = { \ 137 .group_or_pin = grp, 137 .group_or_pin = grp, \ 138 .configs = cfgs, 138 .configs = cfgs, \ 139 .num_configs = ARRAY_S 139 .num_configs = ARRAY_SIZE(cfgs), \ 140 }, 140 }, \ 141 } 141 } 142 142 143 #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pin 143 #define PIN_MAP_CONFIGS_GROUP_DEFAULT(dev, pinctrl, grp, cfgs) \ 144 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STA 144 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, pinctrl, grp, cfgs) 145 145 146 #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, 146 #define PIN_MAP_CONFIGS_GROUP_HOG(dev, state, grp, cfgs) \ 147 PIN_MAP_CONFIGS_GROUP(dev, state, dev, 147 PIN_MAP_CONFIGS_GROUP(dev, state, dev, grp, cfgs) 148 148 149 #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, 149 #define PIN_MAP_CONFIGS_GROUP_HOG_DEFAULT(dev, grp, cfgs) \ 150 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STA 150 PIN_MAP_CONFIGS_GROUP(dev, PINCTRL_STATE_DEFAULT, dev, grp, cfgs) 151 151 152 struct pinctrl_map; 152 struct pinctrl_map; 153 153 154 #ifdef CONFIG_PINCTRL 154 #ifdef CONFIG_PINCTRL 155 155 156 extern int pinctrl_register_mappings(const str 156 extern int pinctrl_register_mappings(const struct pinctrl_map *map, 157 unsigned !! 157 unsigned num_maps); 158 extern void pinctrl_unregister_mappings(const 158 extern void pinctrl_unregister_mappings(const struct pinctrl_map *map); 159 extern void pinctrl_provide_dummies(void); 159 extern void pinctrl_provide_dummies(void); 160 #else 160 #else 161 161 162 static inline int pinctrl_register_mappings(co 162 static inline int pinctrl_register_mappings(const struct pinctrl_map *map, 163 un !! 163 unsigned num_maps) 164 { 164 { 165 return 0; 165 return 0; 166 } 166 } 167 167 168 static inline void pinctrl_unregister_mappings 168 static inline void pinctrl_unregister_mappings(const struct pinctrl_map *map) 169 { 169 { 170 } 170 } 171 171 172 static inline void pinctrl_provide_dummies(voi 172 static inline void pinctrl_provide_dummies(void) 173 { 173 { 174 } 174 } 175 #endif /* !CONFIG_PINCTRL */ 175 #endif /* !CONFIG_PINCTRL */ 176 #endif 176 #endif 177 177
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.