Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 | /* * Copyright (c) 2020 Linaro Ltd. * * SPDX-License-Identifier: Apache-2.0 */ /** @file * @brief ST STM32 MCU family devicetree helper macros */ #ifndef _ST_STM32_DT_H_ #define _ST_STM32_DT_H_ #include <devicetree.h> /* Devicetree related macros to construct pinctrl config data */ #define STM32_NO_PULL 0x0 #define STM32_PULL_UP 0x1 #define STM32_PULL_DOWN 0x2 #define STM32_PUSH_PULL 0x0 #define STM32_OPEN_DRAIN 0x1 /** * @brief Internal: Get a node indentifier for an element in a * pinctrl-x property for a given device instance inst * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @return elements's node identifier */ #define ST_STM32_DT_INST_NODE_ID_FROM_PINCTRL(inst, x, i) \ DT_INST_PHANDLE_BY_IDX(inst, pinctrl_##x, i) /** * @brief Internal: Get a node indentifier for an element in a * pinctrl-x property for a given device * * @param name device node label identifier * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @return elements's node identifier */ #define ST_STM32_DT_NODE_ID_FROM_PINCTRL(name, x, i) \ DT_PHANDLE_BY_IDX(DT_NODELABEL(name), pinctrl_##x, i) /** * @brief Internal: Get pinmux property of a node indentifier for an element * in a pinctrl-x property for a given device instance inst * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @return pinmux property value */ #define ST_STM32_DT_INST_PINMUX(inst, x, i) \ DT_PROP(ST_STM32_DT_INST_NODE_ID_FROM_PINCTRL(inst, x, i), pinmux) /** * @brief Internal: Get pinmux property of a node indentifier for an element * in a pinctrl-x property for a given device * * @param name device node label identifier * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @return pinmux property value */ #define ST_STM32_DT_PINMUX(name, x, i) \ DT_PROP(ST_STM32_DT_NODE_ID_FROM_PINCTRL(name, x, i), pinmux) /** * @brief Internal: Get <function> property of a node indentifier for an element * in a pinctrl-x property for a given device instance inst * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @param function property of a targeted element * @return <function> property value */ #define ST_STM32_DT_INST_FUNC(inst, x, i, function) \ DT_PROP(ST_STM32_DT_INST_NODE_ID_FROM_PINCTRL(inst, x, i), function) /** * @brief Internal: Get <function> property of a node indentifier for an element * in a pinctrl-x property for a given device * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param name device node label identifier * @param function property of a targeted element * @return <function> property value */ #define ST_STM32_DT_FUNC(name, x, i, function) \ DT_PROP(ST_STM32_DT_NODE_ID_FROM_PINCTRL(name, x, i), function) /** * @brief Internal: Provide slew-rate value for a pin with index i of a * pinctrl-x property for a given device instance inst * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param i index of soc_gpio_pinctrl element * @return slew rate value */ #define ST_STM32_DT_INST_SLEW_RATE(inst, x, i) \ DT_ENUM_IDX(ST_STM32_DT_INST_NODE_ID_FROM_PINCTRL(inst, x, i), \ slew_rate) /** * @brief Internal: Provide slew-rate value for a pin with index i of a * pinctrl-x property for a given device * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param name device node label identifier * @return slew rate value */ #define ST_STM32_DT_SLEW_RATE(name, x, i) \ DT_ENUM_IDX(ST_STM32_DT_NODE_ID_FROM_PINCTRL(name, x, i), slew_rate) /** * @brief Internal: Contruct a pincfg field of a soc_gpio_pinctrl element * with index i of a pinctrl-x property for a given device instance inst * * @param i index of soc_gpio_pinctrl element * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param inst device instance number * @return pincfg field */ #ifndef CONFIG_SOC_SERIES_STM32F1X #define ST_STM32_DT_INST_PINCFG(inst, x, i) \ (((STM32_NO_PULL * ST_STM32_DT_INST_FUNC(inst, x, i, bias_disable)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PULL_UP * ST_STM32_DT_INST_FUNC(inst, x, i, bias_pull_up)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PULL_DOWN * ST_STM32_DT_INST_FUNC(inst, x, i, bias_pull_down)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PUSH_PULL * ST_STM32_DT_INST_FUNC(inst, x, i, drive_push_pull))\ << STM32_OTYPER_SHIFT) | \ ((STM32_OPEN_DRAIN * ST_STM32_DT_INST_FUNC(inst, x, i, \ drive_open_drain)) \ << STM32_OTYPER_SHIFT) | \ (ST_STM32_DT_INST_SLEW_RATE(inst, x, i) << STM32_OSPEEDR_SHIFT)) #else #define ST_STM32_DT_INST_PINCFG(inst, x, i) \ (((STM32_NO_PULL * ST_STM32_DT_INST_FUNC(inst, x, i, bias_disable)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PULL_UP * ST_STM32_DT_INST_FUNC(inst, x, i, bias_pull_up)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PULL_DOWN * ST_STM32_DT_INST_FUNC(inst, x, i, bias_pull_down)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PUSH_PULL * ST_STM32_DT_INST_FUNC(inst, x, i, drive_push_pull))\ << STM32_CNF_OUT_0_SHIFT) | \ ((STM32_OPEN_DRAIN * ST_STM32_DT_INST_FUNC(inst, x, i, \ drive_open_drain)) \ << STM32_CNF_OUT_0_SHIFT) | \ (ST_STM32_DT_INST_SLEW_RATE(inst, x, i) << STM32_MODE_OSPEED_SHIFT)) #endif /* CONFIG_SOC_SERIES_STM32F1X */ /** * @brief Internal: Contruct a pincfg field of a soc_gpio_pinctrl element * with index i of a pinctrl-x property for a given device * * @param i index of soc_gpio_pinctrl element * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param name device node label identifier * @return pincfg field */ #ifndef CONFIG_SOC_SERIES_STM32F1X #define ST_STM32_DT_PINCFG(name, x, i) \ (((STM32_NO_PULL * ST_STM32_DT_FUNC(name, x, i, bias_disable)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PULL_UP * ST_STM32_DT_FUNC(name, x, i, bias_pull_up)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PULL_DOWN * ST_STM32_DT_FUNC(name, x, i, bias_pull_down)) \ << STM32_PUPDR_SHIFT) | \ ((STM32_PUSH_PULL * ST_STM32_DT_FUNC(name, x, i, drive_push_pull)) \ << STM32_OTYPER_SHIFT) | \ ((STM32_OPEN_DRAIN * ST_STM32_DT_FUNC(name, x, i, drive_open_drain))\ << STM32_OTYPER_SHIFT) | \ (ST_STM32_DT_SLEW_RATE(name, x, i) << STM32_OSPEEDR_SHIFT)) #else #define ST_STM32_DT_PINCFG(name, x, i) \ (((STM32_NO_PULL * ST_STM32_DT_FUNC(name, x, i, bias_disable)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PULL_UP * ST_STM32_DT_FUNC(name, x, i, bias_pull_up)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PULL_DOWN * ST_STM32_DT_FUNC(name, x, i, bias_pull_down)) \ << STM32_PUPD_SHIFT) | \ ((STM32_PUSH_PULL * ST_STM32_DT_FUNC(name, x, i, drive_push_pull)) \ << STM32_CNF_OUT_0_SHIFT) | \ ((STM32_OPEN_DRAIN * ST_STM32_DT_FUNC(name, x, i, drive_open_drain))\ << STM32_CNF_OUT_0_SHIFT) | \ (ST_STM32_DT_SLEW_RATE(name, x, i) << STM32_MODE_OSPEED_SHIFT)) #endif /* CONFIG_SOC_SERIES_STM32F1X */ /** * @brief Internal: Contruct a soc_gpio_pinctrl element index i of * a pinctrl-x property for a given device instance inst * * @param i element index * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param inst device instance number * @return soc_gpio_pinctrl element */ #define ST_STM32_DT_INST_PIN_ELEM(i, x, inst) \ { \ ST_STM32_DT_INST_PINMUX(inst, x, i), \ ST_STM32_DT_INST_PINCFG(inst, x, i) \ }, /** * @brief Internal: Contruct a soc_gpio_pinctrl element index i of * a pinctrl-x property for a given device * * @param i element index * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @param name device node label identifier * @return soc_gpio_pinctrl element */ #define ST_STM32_DT_PIN_ELEM(i, x, name) \ { \ ST_STM32_DT_PINMUX(name, x, i), \ ST_STM32_DT_PINCFG(name, x, i) \ }, /** * @brief Internal: Return the number of elements of a pinctrl-x property * for a given device instance * * This macro returns the number of element in property pcintrl-<x> of * device instance <inst> * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @return number of element in property */ #define ST_STM32_DT_INST_NUM_PINS(inst, x) DT_INST_PROP_LEN(inst, pinctrl_##x) /** * @brief Internal: Return the number of elements of a pinctrl-x property * for a given device * * This macro returns the number of element in property pcintrl-<x> of * device "name" * * @param name device node label identifier * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @return number of element in property */ #define ST_STM32_DT_NUM_PINS(name, x) \ DT_PROP_LEN(DT_NODELABEL(name), pinctrl_##x) /** * @brief Construct a soc_gpio_pinctrl array of a specific pcintrl property * for a given device instance * * This macro returns an array of soc_gpio_pinctrl, each line matching a pinctrl * configuration provived in property pcintrl-<x> of device instance <inst> * * @param inst device instance number * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @return array of soc_gpio_pinctrl */ #define ST_STM32_DT_INST_PINCTRL(inst, x) \ { COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, pinctrl_##x), \ (UTIL_LISTIFY(ST_STM32_DT_INST_NUM_PINS(inst, x), \ ST_STM32_DT_INST_PIN_ELEM, \ x, \ inst)), \ ()) \ } /** * @brief Construct a soc_gpio_pinctrl array of a specific pcintrl property * for a given device name * * This macro returns an array of soc_gpio_pinctrl, each line matching a pinctrl * configuration provived in property pcintrl-<x> of a device referenced by * its node label identifier. * * @param name device node label identifier * @param x index of targeted pinctrl- property (eg: pinctrl-<x>) * @return array of soc_gpio_pinctrl */ #define ST_STM32_DT_PINCTRL(name, x) \ { COND_CODE_1(DT_NODE_HAS_PROP(DT_NODELABEL(name), pinctrl_##x),\ (UTIL_LISTIFY(ST_STM32_DT_NUM_PINS(name, x), \ ST_STM32_DT_PIN_ELEM, \ x, \ name)), \ ()) \ } #endif /* _ST_STM32_DT_H_ */ |