1 /** 2 * @file 3 * @brief DMA 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_DMAS_H_ 13 #define ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_ 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /** 20 * @defgroup devicetree-dmas Devicetree DMA API 21 * @ingroup devicetree 22 * @{ 23 */ 24 25 /** 26 * @brief Get the node identifier for the DMA controller from a 27 * dmas property at an index 28 * 29 * Example devicetree fragment: 30 * 31 * dma1: dma@... { ... }; 32 * 33 * dma2: dma@... { ... }; 34 * 35 * n: node { 36 * dmas = <&dma1 1 2 0x400 0x3>, 37 * <&dma2 6 3 0x404 0x5>; 38 * }; 39 * 40 * Example usage: 41 * 42 * DT_DMAS_CTLR_BY_IDX(DT_NODELABEL(n), 0) // DT_NODELABEL(dma1) 43 * DT_DMAS_CTLR_BY_IDX(DT_NODELABEL(n), 1) // DT_NODELABEL(dma2) 44 * 45 * @param node_id node identifier for a node with a dmas property 46 * @param idx logical index into dmas property 47 * @return the node identifier for the DMA controller referenced at 48 * index "idx" 49 * @see DT_PROP_BY_PHANDLE_IDX() 50 */ 51 #define DT_DMAS_CTLR_BY_IDX(node_id, idx) DT_PHANDLE_BY_IDX(node_id, dmas, idx) 52 53 /** 54 * @brief Get the node identifier for the DMA controller from a 55 * dmas property by name 56 * 57 * Example devicetree fragment: 58 * 59 * dma1: dma@... { ... }; 60 * 61 * dma2: dma@... { ... }; 62 * 63 * n: node { 64 * dmas = <&dma1 1 2 0x400 0x3>, 65 * <&dma2 6 3 0x404 0x5>; 66 * dma-names = "tx", "rx"; 67 * }; 68 * 69 * Example usage: 70 * 71 * DT_DMAS_CTLR_BY_NAME(DT_NODELABEL(n), tx) // DT_NODELABEL(dma1) 72 * DT_DMAS_CTLR_BY_NAME(DT_NODELABEL(n), rx) // DT_NODELABEL(dma2) 73 * 74 * @param node_id node identifier for a node with a dmas property 75 * @param name lowercase-and-underscores name of a dmas element 76 * as defined by the node's dma-names property 77 * @return the node identifier for the DMA controller in the named element 78 * @see DT_PHANDLE_BY_NAME() 79 */ 80 #define DT_DMAS_CTLR_BY_NAME(node_id, name) \ 81 DT_PHANDLE_BY_NAME(node_id, dmas, name) 82 83 /** 84 * @brief Equivalent to DT_DMAS_CTLR_BY_IDX(node_id, 0) 85 * @param node_id node identifier for a node with a dmas property 86 * @return the node identifier for the DMA controller at index 0 87 * in the node's "dmas" property 88 * @see DT_DMAS_CTLR_BY_IDX() 89 */ 90 #define DT_DMAS_CTLR(node_id) DT_DMAS_CTLR_BY_IDX(node_id, 0) 91 92 /** 93 * @brief Get the node identifier for the DMA controller from a 94 * DT_DRV_COMPAT instance's dmas property at an index 95 * 96 * @param inst DT_DRV_COMPAT instance number 97 * @param idx logical index into dmas property 98 * @return the node identifier for the DMA controller referenced at 99 * index "idx" 100 * @see DT_DMAS_CTLR_BY_IDX() 101 */ 102 #define DT_INST_DMAS_CTLR_BY_IDX(inst, idx) \ 103 DT_DMAS_CTLR_BY_IDX(DT_DRV_INST(inst), idx) 104 105 /** 106 * @brief Get the node identifier for the DMA controller from a 107 * DT_DRV_COMPAT instance's dmas property by name 108 * @param inst DT_DRV_COMPAT instance number 109 * @param name lowercase-and-underscores name of a dmas element 110 * as defined by the node's dma-names property 111 * @return the node identifier for the DMA controller in the named element 112 * @see DT_DMAS_CTLR_BY_NAME() 113 */ 114 #define DT_INST_DMAS_CTLR_BY_NAME(inst, name) \ 115 DT_DMAS_CTLR_BY_NAME(DT_DRV_INST(inst), name) 116 117 /** 118 * @brief Equivalent to DT_INST_DMAS_CTLR_BY_IDX(inst, 0) 119 * @param inst DT_DRV_COMPAT instance number 120 * @return the node identifier for the DMA controller at index 0 121 * in the instance's "dmas" property 122 * @see DT_DMAS_CTLR_BY_IDX() 123 */ 124 #define DT_INST_DMAS_CTLR(inst) DT_INST_DMAS_CTLR_BY_IDX(inst, 0) 125 126 /** 127 * @brief Get a DMA specifier's cell value at an index 128 * 129 * Example devicetree fragment: 130 * 131 * dma1: dma@... { 132 * compatible = "vnd,dma"; 133 * #dma-cells = <2>; 134 * }; 135 * 136 * dma2: dma@... { 137 * compatible = "vnd,dma"; 138 * #dma-cells = <2>; 139 * }; 140 * 141 * n: node { 142 * dmas = <&dma1 1 0x400>, 143 * <&dma2 6 0x404>; 144 * }; 145 * 146 * Bindings fragment for the vnd,dma compatible: 147 * 148 * dma-cells: 149 * - channel 150 * - config 151 * 152 * Example usage: 153 * 154 * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 0, channel) // 1 155 * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 1, channel) // 6 156 * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 0, config) // 0x400 157 * DT_DMAS_CELL_BY_IDX(DT_NODELABEL(n), 1, config) // 0x404 158 * 159 * @param node_id node identifier for a node with a dmas property 160 * @param idx logical index into dmas property 161 * @param cell lowercase-and-underscores cell name 162 * @return the cell value at index "idx" 163 * @see DT_PHA_BY_IDX() 164 */ 165 #define DT_DMAS_CELL_BY_IDX(node_id, idx, cell) \ 166 DT_PHA_BY_IDX(node_id, dmas, idx, cell) 167 168 /** 169 * @brief Get a DT_DRV_COMPAT instance's DMA specifier's cell value at an index 170 * @param inst DT_DRV_COMPAT instance number 171 * @param idx logical index into dmas property 172 * @param cell lowercase-and-underscores cell name 173 * @return the cell value at index "idx" 174 * @see DT_DMAS_CELL_BY_IDX() 175 */ 176 #define DT_INST_DMAS_CELL_BY_IDX(inst, idx, cell) \ 177 DT_PHA_BY_IDX(DT_DRV_INST(inst), dmas, idx, cell) 178 179 /** 180 * @brief Get a DMA specifier's cell value by name 181 * 182 * Example devicetree fragment: 183 * 184 * dma1: dma@... { 185 * compatible = "vnd,dma"; 186 * #dma-cells = <2>; 187 * }; 188 * 189 * dma2: dma@... { 190 * compatible = "vnd,dma"; 191 * #dma-cells = <2>; 192 * }; 193 * 194 * n: node { 195 * dmas = <&dma1 1 0x400>, 196 * <&dma2 6 0x404>; 197 * dma-names = "tx", "rx"; 198 * }; 199 * 200 * Bindings fragment for the vnd,dma compatible: 201 * 202 * dma-cells: 203 * - channel 204 * - config 205 * 206 * Example usage: 207 * 208 * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), tx, channel) // 1 209 * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), rx, channel) // 6 210 * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), tx, config) // 0x400 211 * DT_DMAS_CELL_BY_NAME(DT_NODELABEL(n), rx, config) // 0x404 212 * 213 * @param node_id node identifier for a node with a dmas property 214 * @param name lowercase-and-underscores name of a dmas element 215 * as defined by the node's dma-names property 216 * @param cell lowercase-and-underscores cell name 217 * @return the cell value in the specifier at the named element 218 * @see DT_PHA_BY_NAME() 219 */ 220 #define DT_DMAS_CELL_BY_NAME(node_id, name, cell) \ 221 DT_PHA_BY_NAME(node_id, dmas, name, cell) 222 223 /** 224 * @brief Get a DT_DRV_COMPAT instance's DMA specifier's cell value by name 225 * @param inst DT_DRV_COMPAT instance number 226 * @param name lowercase-and-underscores name of a dmas element 227 * as defined by the node's dma-names property 228 * @param cell lowercase-and-underscores cell name 229 * @return the cell value in the specifier at the named element 230 * @see DT_DMAS_CELL_BY_NAME() 231 */ 232 #define DT_INST_DMAS_CELL_BY_NAME(inst, name, cell) \ 233 DT_DMAS_CELL_BY_NAME(DT_DRV_INST(inst), name, cell) 234 235 /** 236 * @brief Is index "idx" valid for a dmas property? 237 * @param node_id node identifier for a node with a dmas property 238 * @param idx logical index into dmas property 239 * @return 1 if the "dmas" property has index "idx", 0 otherwise 240 */ 241 #define DT_DMAS_HAS_IDX(node_id, idx) \ 242 IS_ENABLED(DT_CAT4(node_id, _P_dmas_IDX_, idx, _EXISTS)) 243 244 /** 245 * @brief Is index "idx" valid for a DT_DRV_COMPAT instance's dmas property? 246 * @param inst DT_DRV_COMPAT instance number 247 * @param idx logical index into dmas property 248 * @return 1 if the "dmas" property has a specifier at index "idx", 0 otherwise 249 */ 250 #define DT_INST_DMAS_HAS_IDX(inst, idx) \ 251 DT_DMAS_HAS_IDX(DT_DRV_INST(inst), idx) 252 253 /** 254 * @brief Does a dmas property have a named element? 255 * @param node_id node identifier for a node with a dmas property 256 * @param name lowercase-and-underscores name of a dmas element 257 * as defined by the node's dma-names property 258 * @return 1 if the dmas property has the named element, 0 otherwise 259 */ 260 #define DT_DMAS_HAS_NAME(node_id, name) \ 261 DT_PROP_HAS_NAME(node_id, dmas, name) 262 263 /** 264 * @brief Does a DT_DRV_COMPAT instance's dmas property have a named element? 265 * @param inst DT_DRV_COMPAT instance number 266 * @param name lowercase-and-underscores name of a dmas element 267 * as defined by the node's dma-names property 268 * @return 1 if the dmas property has the named element, 0 otherwise 269 */ 270 #define DT_INST_DMAS_HAS_NAME(inst, name) \ 271 DT_DMAS_HAS_NAME(DT_DRV_INST(inst), name) 272 273 /** 274 * @} 275 */ 276 277 #ifdef __cplusplus 278 } 279 #endif 280 281 #endif /* ZEPHYR_INCLUDE_DEVICETREE_DMAS_H_ */ 282