1 /** 2 * @file 3 * @brief IO channels devicetree macro public API header file. 4 */ 5 6 /* 7 * Copyright (c) 2020, Linaro Ltd. 8 * 9 * SPDX-License-Identifier: Apache-2.0 10 */ 11 12 #ifndef ZEPHYR_INCLUDE_DEVICETREE_IO_CHANNELS_H_ 13 #define ZEPHYR_INCLUDE_DEVICETREE_IO_CHANNELS_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @defgroup devicetree-io-channels Devicetree IO Channels API 21 * @ingroup devicetree 22 * @{ 23 */ 24 25 /** 26 * @brief Get a label property from the node referenced by an 27 * io-channels property at an index 28 * 29 * It's an error if the node referenced by the phandle in node_id's 30 * io-channels property at index "idx" has no label property. 31 * 32 * Example devicetree fragment: 33 * 34 * adc1: adc@... { 35 * label = "ADC_1"; 36 * }; 37 * 38 * adc2: adc@... { 39 * label = "ADC_2"; 40 * }; 41 * 42 * n: node { 43 * io-channels = <&adc1 10>, <&adc2 20>; 44 * }; 45 * 46 * Example usage: 47 * 48 * DT_IO_CHANNELS_LABEL_BY_IDX(DT_NODELABEL(n), 1) // "ADC_2" 49 * 50 * @param node_id node identifier for a node with an io-channels property 51 * @param idx logical index into io-channels property 52 * @return the label property of the node referenced at index "idx" 53 * @see DT_PROP_BY_PHANDLE_IDX() 54 */ 55 #define DT_IO_CHANNELS_LABEL_BY_IDX(node_id, idx) \ 56 __DEPRECATED_MACRO \ 57 DT_PROP_BY_PHANDLE_IDX(node_id, io_channels, idx, label) 58 59 /** 60 * @brief Get a label property from an io-channels property by name 61 * 62 * It's an error if the node referenced by the phandle in node_id's 63 * io-channels property at the element named "name" has no label 64 * property. 65 * 66 * Example devicetree fragment: 67 * 68 * adc1: adc@... { 69 * label = "ADC_1"; 70 * }; 71 * 72 * adc2: adc@... { 73 * label = "ADC_2"; 74 * }; 75 * 76 * n: node { 77 * io-channels = <&adc1 10>, <&adc2 20>; 78 * io-channel-names = "SENSOR", "BANDGAP"; 79 * }; 80 * 81 * Example usage: 82 * 83 * DT_IO_CHANNELS_LABEL_BY_NAME(DT_NODELABEL(n), bandgap) // "ADC_2" 84 * 85 * @param node_id node identifier for a node with an io-channels property 86 * @param name lowercase-and-underscores name of an io-channels element 87 * as defined by the node's io-channel-names property 88 * @return the label property of the node referenced at the named element 89 * @see DT_PHANDLE_BY_NAME() 90 */ 91 #define DT_IO_CHANNELS_LABEL_BY_NAME(node_id, name) \ 92 __DEPRECATED_MACRO \ 93 DT_PROP(DT_PHANDLE_BY_NAME(node_id, io_channels, name), label) 94 95 /** 96 * @brief Equivalent to DT_IO_CHANNELS_LABEL_BY_IDX(node_id, 0) 97 * @param node_id node identifier for a node with an io-channels property 98 * @return the label property of the node referenced at index 0 99 * @see DT_IO_CHANNELS_LABEL_BY_IDX() 100 */ 101 #define DT_IO_CHANNELS_LABEL(node_id) \ 102 __DEPRECATED_MACRO DT_IO_CHANNELS_LABEL_BY_IDX(node_id, 0) 103 104 /** 105 * 106 * @brief Get the node identifier for the node referenced by an 107 * io-channels property at an index 108 * 109 * Example devicetree fragment: 110 * 111 * adc1: adc@... { ... }; 112 * 113 * adc2: adc@... { ... }; 114 * 115 * n: node { 116 * io-channels = <&adc1 10>, <&adc2 20>; 117 * }; 118 * 119 * Example usage: 120 * 121 * DT_IO_CHANNELS_CTLR_BY_IDX(DT_NODELABEL(n), 0) // DT_NODELABEL(adc1) 122 * DT_IO_CHANNELS_CTLR_BY_IDX(DT_NODELABEL(n), 1) // DT_NODELABEL(adc2) 123 * 124 * @param node_id node identifier for a node with an io-channels property 125 * @param idx logical index into io-channels property 126 * @return the node identifier for the node referenced at index "idx" 127 * @see DT_PROP_BY_PHANDLE_IDX() 128 */ 129 #define DT_IO_CHANNELS_CTLR_BY_IDX(node_id, idx) \ 130 DT_PHANDLE_BY_IDX(node_id, io_channels, idx) 131 132 /** 133 * @brief Get the node identifier for the node referenced by an 134 * io-channels property by name 135 * 136 * Example devicetree fragment: 137 * 138 * adc1: adc@... { ... }; 139 * 140 * adc2: adc@... { ... }; 141 * 142 * n: node { 143 * io-channels = <&adc1 10>, <&adc2 20>; 144 * io-channel-names = "SENSOR", "BANDGAP"; 145 * }; 146 * 147 * Example usage: 148 * 149 * DT_IO_CHANNELS_CTLR_BY_NAME(DT_NODELABEL(n), sensor) // DT_NODELABEL(adc1) 150 * DT_IO_CHANNELS_CTLR_BY_NAME(DT_NODELABEL(n), bandgap) // DT_NODELABEL(adc2) 151 * 152 * @param node_id node identifier for a node with an io-channels property 153 * @param name lowercase-and-underscores name of an io-channels element 154 * as defined by the node's io-channel-names property 155 * @return the node identifier for the node referenced at the named element 156 * @see DT_PHANDLE_BY_NAME() 157 */ 158 #define DT_IO_CHANNELS_CTLR_BY_NAME(node_id, name) \ 159 DT_PHANDLE_BY_NAME(node_id, io_channels, name) 160 161 /** 162 * @brief Equivalent to DT_IO_CHANNELS_CTLR_BY_IDX(node_id, 0) 163 * @param node_id node identifier for a node with an io-channels property 164 * @return the node identifier for the node referenced at index 0 165 * in the node's "io-channels" property 166 * @see DT_IO_CHANNELS_CTLR_BY_IDX() 167 */ 168 #define DT_IO_CHANNELS_CTLR(node_id) DT_IO_CHANNELS_CTLR_BY_IDX(node_id, 0) 169 170 /** 171 * @brief Get a label property from a DT_DRV_COMPAT instance's io-channels 172 * property at an index 173 * @param inst DT_DRV_COMPAT instance number 174 * @param idx logical index into io-channels property 175 * @return the label property of the node referenced at index "idx" 176 * @see DT_IO_CHANNELS_LABEL_BY_IDX() 177 */ 178 #define DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, idx) \ 179 __DEPRECATED_MACRO \ 180 DT_IO_CHANNELS_LABEL_BY_IDX(DT_DRV_INST(inst), idx) 181 182 /** 183 * @brief Get a label property from a DT_DRV_COMPAT instance's io-channels 184 * property by name 185 * @param inst DT_DRV_COMPAT instance number 186 * @param name lowercase-and-underscores name of an io-channels element 187 * as defined by the instance's io-channel-names property 188 * @return the label property of the node referenced at the named element 189 * @see DT_IO_CHANNELS_LABEL_BY_NAME() 190 */ 191 #define DT_INST_IO_CHANNELS_LABEL_BY_NAME(inst, name) \ 192 __DEPRECATED_MACRO \ 193 DT_IO_CHANNELS_LABEL_BY_NAME(DT_DRV_INST(inst), name) 194 195 /** 196 * @brief Equivalent to DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, 0) 197 * @param inst DT_DRV_COMPAT instance number 198 * @return the label property of the node referenced at index 0 199 */ 200 #define DT_INST_IO_CHANNELS_LABEL(inst) \ 201 __DEPRECATED_MACRO DT_INST_IO_CHANNELS_LABEL_BY_IDX(inst, 0) 202 203 /** 204 * @brief Get the node identifier from a DT_DRV_COMPAT instance's io-channels 205 * property at an index 206 * 207 * @param inst DT_DRV_COMPAT instance number 208 * @param idx logical index into io-channels property 209 * @return the node identifier for the node referenced at index "idx" 210 * @see DT_IO_CHANNELS_CTLR_BY_IDX() 211 */ 212 #define DT_INST_IO_CHANNELS_CTLR_BY_IDX(inst, idx) \ 213 DT_IO_CHANNELS_CTLR_BY_IDX(DT_DRV_INST(inst), idx) 214 215 /** 216 * @brief Get the node identifier from a DT_DRV_COMPAT instance's io-channels 217 * property by name 218 * @param inst DT_DRV_COMPAT instance number 219 * @param name lowercase-and-underscores name of an io-channels element 220 * as defined by the node's io-channel-names property 221 * @return the node identifier for the node referenced at the named element 222 * @see DT_IO_CHANNELS_CTLR_BY_NAME() 223 */ 224 #define DT_INST_IO_CHANNELS_CTLR_BY_NAME(inst, name) \ 225 DT_IO_CHANNELS_CTLR_BY_NAME(DT_DRV_INST(inst), name) 226 227 /** 228 * @brief Equivalent to DT_INST_IO_CHANNELS_CTLR_BY_IDX(inst, 0) 229 * @param inst DT_DRV_COMPAT instance number 230 * @return the node identifier for the node referenced at index 0 231 * in the node's "io-channels" property 232 * @see DT_IO_CHANNELS_CTLR_BY_IDX() 233 */ 234 #define DT_INST_IO_CHANNELS_CTLR(inst) DT_INST_IO_CHANNELS_CTLR_BY_IDX(inst, 0) 235 236 /** 237 * @brief Get an io-channels specifier input cell at an index 238 * 239 * This macro only works for io-channels specifiers with cells named 240 * "input". Refer to the node's binding to check if necessary. 241 * 242 * Example devicetree fragment: 243 * 244 * adc1: adc@... { 245 * compatible = "vnd,adc"; 246 * #io-channel-cells = <1>; 247 * }; 248 * 249 * adc2: adc@... { 250 * compatible = "vnd,adc"; 251 * #io-channel-cells = <1>; 252 * }; 253 * 254 * n: node { 255 * io-channels = <&adc1 10>, <&adc2 20>; 256 * }; 257 * 258 * Bindings fragment for the vnd,adc compatible: 259 * 260 * io-channel-cells: 261 * - input 262 * 263 * Example usage: 264 * 265 * DT_IO_CHANNELS_INPUT_BY_IDX(DT_NODELABEL(n), 0) // 10 266 * DT_IO_CHANNELS_INPUT_BY_IDX(DT_NODELABEL(n), 1) // 20 267 * 268 * @param node_id node identifier for a node with an io-channels property 269 * @param idx logical index into io-channels property 270 * @return the input cell in the specifier at index "idx" 271 * @see DT_PHA_BY_IDX() 272 */ 273 #define DT_IO_CHANNELS_INPUT_BY_IDX(node_id, idx) \ 274 DT_PHA_BY_IDX(node_id, io_channels, idx, input) 275 276 /** 277 * @brief Get an io-channels specifier input cell by name 278 * 279 * This macro only works for io-channels specifiers with cells named 280 * "input". Refer to the node's binding to check if necessary. 281 * 282 * Example devicetree fragment: 283 * 284 * adc1: adc@... { 285 * compatible = "vnd,adc"; 286 * #io-channel-cells = <1>; 287 * }; 288 * 289 * adc2: adc@... { 290 * compatible = "vnd,adc"; 291 * #io-channel-cells = <1>; 292 * }; 293 * 294 * n: node { 295 * io-channels = <&adc1 10>, <&adc2 20>; 296 * io-channel-names = "SENSOR", "BANDGAP"; 297 * }; 298 * 299 * Bindings fragment for the vnd,adc compatible: 300 * 301 * io-channel-cells: 302 * - input 303 * 304 * Example usage: 305 * 306 * DT_IO_CHANNELS_INPUT_BY_NAME(DT_NODELABEL(n), sensor) // 10 307 * DT_IO_CHANNELS_INPUT_BY_NAME(DT_NODELABEL(n), bandgap) // 20 308 * 309 * @param node_id node identifier for a node with an io-channels property 310 * @param name lowercase-and-underscores name of an io-channels element 311 * as defined by the node's io-channel-names property 312 * @return the input cell in the specifier at the named element 313 * @see DT_PHA_BY_NAME() 314 */ 315 #define DT_IO_CHANNELS_INPUT_BY_NAME(node_id, name) \ 316 DT_PHA_BY_NAME(node_id, io_channels, name, input) 317 /** 318 * @brief Equivalent to DT_IO_CHANNELS_INPUT_BY_IDX(node_id, 0) 319 * @param node_id node identifier for a node with an io-channels property 320 * @return the input cell in the specifier at index 0 321 * @see DT_IO_CHANNELS_INPUT_BY_IDX() 322 */ 323 #define DT_IO_CHANNELS_INPUT(node_id) DT_IO_CHANNELS_INPUT_BY_IDX(node_id, 0) 324 325 /** 326 * @brief Get an input cell from the "DT_DRV_INST(inst)" io-channels 327 * property at an index 328 * @param inst DT_DRV_COMPAT instance number 329 * @param idx logical index into io-channels property 330 * @return the input cell in the specifier at index "idx" 331 * @see DT_IO_CHANNELS_INPUT_BY_IDX() 332 */ 333 #define DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, idx) \ 334 DT_IO_CHANNELS_INPUT_BY_IDX(DT_DRV_INST(inst), idx) 335 336 /** 337 * @brief Get an input cell from the "DT_DRV_INST(inst)" io-channels 338 * property by name 339 * @param inst DT_DRV_COMPAT instance number 340 * @param name lowercase-and-underscores name of an io-channels element 341 * as defined by the instance's io-channel-names property 342 * @return the input cell in the specifier at the named element 343 * @see DT_IO_CHANNELS_INPUT_BY_NAME() 344 */ 345 #define DT_INST_IO_CHANNELS_INPUT_BY_NAME(inst, name) \ 346 DT_IO_CHANNELS_INPUT_BY_NAME(DT_DRV_INST(inst), name) 347 348 /** 349 * @brief Equivalent to DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, 0) 350 * @param inst DT_DRV_COMPAT instance number 351 * @return the input cell in the specifier at index 0 352 */ 353 #define DT_INST_IO_CHANNELS_INPUT(inst) DT_INST_IO_CHANNELS_INPUT_BY_IDX(inst, 0) 354 355 /** 356 * @} 357 */ 358 359 #ifdef __cplusplus 360 } 361 #endif 362 363 #endif /* ZEPHYR_INCLUDE_DEVICETREE_IO_CHANNELS_H_ */ 364