1 /* 2 * Copyright (c) 2021 ITE Corporation. All Rights Reserved. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _ITE_IT8XXX2_SOC_DT_H_ 8 #define _ITE_IT8XXX2_SOC_DT_H_ 9 10 /* 11 * For it8xxx2 wake-up controller (WUC) 12 */ 13 #define IT8XXX2_DEV_WUC(idx, inst) \ 14 DEVICE_DT_GET(DT_PHANDLE(IT8XXX2_DT_INST_WUCCTRL(inst, idx), wucs)) 15 #define IT8XXX2_DEV_WUC_MASK(idx, inst) \ 16 DT_PHA(IT8XXX2_DT_INST_WUCCTRL(inst, idx), wucs, mask) 17 18 /** 19 * @brief For it8xxx2, get a node identifier from a wucctrl property 20 * for a DT_DRV_COMPAT instance 21 * 22 * @param inst instance number 23 * @param idx index in the wucctrl property 24 * @return node identifier for the phandle at index idx in the wucctrl 25 * property of that DT_DRV_COMPAT instance 26 */ 27 #define IT8XXX2_DT_INST_WUCCTRL(inst, idx) \ 28 DT_INST_PHANDLE_BY_IDX(inst, wucctrl, idx) 29 30 /** 31 * @brief For it8xxx2, construct wuc map structure in LISTIFY extension 32 * 33 * @param idx index in LISTIFY extension 34 * @param inst instance number for compatible defined in DT_DRV_COMPAT 35 * @return a structure of *_wuc_map_cfg 36 */ 37 #define IT8XXX2_DT_WUC_ITEMS_FUNC(idx, inst) \ 38 { \ 39 .wucs = IT8XXX2_DEV_WUC(idx, inst), \ 40 .mask = IT8XXX2_DEV_WUC_MASK(idx, inst), \ 41 } 42 43 /** 44 * @brief For it8xxx2, get the length of wucctrl property which 45 * type is 'phandle-array' for a DT_DRV_COMPAT instance 46 * 47 * @param inst instance number 48 * @return length of wucctrl property which type is 'phandle-array' 49 */ 50 #define IT8XXX2_DT_INST_WUCCTRL_LEN(inst) \ 51 DT_INST_PROP_LEN(inst, wucctrl) 52 53 /** 54 * @brief For it8xxx2, construct an array of it8xxx2 wuc map structure 55 * with compatible defined in DT_DRV_COMPAT by LISTIFY func 56 * 57 * @param inst instance number for compatible defined in DT_DRV_COMPAT 58 * @return an array of *_wuc_map_cfg structure 59 */ 60 #define IT8XXX2_DT_WUC_ITEMS_LIST(inst) { \ 61 LISTIFY(IT8XXX2_DT_INST_WUCCTRL_LEN(inst), \ 62 IT8XXX2_DT_WUC_ITEMS_FUNC, (,), \ 63 inst) \ 64 } 65 66 /** 67 * @brief Macro function to construct it8xxx2 GPIO IRQ in LISTIFY extension. 68 * 69 * @param idx index in LISTIFY extension. 70 * @param inst instance number for compatible defined in DT_DRV_COMPAT. 71 * @return an IRQ number of GPIO. 72 */ 73 #define IT8XXX2_DT_GPIO_IRQ_FUNC(idx, inst) \ 74 DT_INST_IRQ_BY_IDX(inst, idx, irq) 75 76 /** 77 * @brief Macro function to construct a list of it8xxx2 GPIO IRQ number 78 * with compatible defined in DT_DRV_COMPAT by LISTIFY func. 79 * 80 * @param inst instance number for compatible defined in DT_DRV_COMPAT. 81 * @return an array of GPIO IRQ number. 82 */ 83 #define IT8XXX2_DT_GPIO_IRQ_LIST(inst) { \ 84 LISTIFY(DT_INST_PROP(inst, ngpios), \ 85 IT8XXX2_DT_GPIO_IRQ_FUNC, (,), \ 86 inst) \ 87 } 88 89 #endif /* _ITE_IT8XXX2_SOC_DT_H_ */ 90