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