1 /* 2 * Copyright (c) 2021 Telink Semiconductor 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_B91_PINCTRL_COMMON_H_ 8 #define ZEPHYR_B91_PINCTRL_COMMON_H_ 9 10 /* IDs for GPIO functions */ 11 12 #define B91_FUNC_A 0x000000 13 #define B91_FUNC_B 0x010000 14 #define B91_FUNC_C 0x020000 15 16 /* IDs for GPIO Ports */ 17 18 #define B91_PORT_A 0x0000 19 #define B91_PORT_B 0x0100 20 #define B91_PORT_C 0x0200 21 #define B91_PORT_D 0x0300 22 #define B91_PORT_E 0x0400 23 24 /* IDs for GPIO Pins */ 25 26 #define B91_PIN_0 0x01 27 #define B91_PIN_1 0x02 28 #define B91_PIN_2 0x04 29 #define B91_PIN_3 0x08 30 #define B91_PIN_4 0x10 31 #define B91_PIN_5 0x20 32 #define B91_PIN_6 0x40 33 #define B91_PIN_7 0x80 34 35 /* Setters and getters */ 36 37 #define B91_PINMUX_SET(func, port, pin) (func | port | pin) 38 #define B91_PINMUX_GET_FUNC(pinmux) ((pinmux >> 16) & 0xFF) 39 #define B91_PINMUX_GET_PIN(pinmux) (pinmux & 0xFFFF) 40 41 #define B91_PINMUX_DT_INST_GET_ELEM(idx, x, inst) \ 42 DT_PROP(DT_INST_PINCTRL_BY_IDX(inst, x, idx), pinmux), 43 44 #define B91_PINMUX_DT_INST_GET_ARRAY(inst, x) \ 45 { COND_CODE_1(DT_INST_PINCTRL_HAS_IDX(inst, x), \ 46 (UTIL_LISTIFY(DT_INST_NUM_PINCTRLS_BY_IDX(inst, x), \ 47 B91_PINMUX_DT_INST_GET_ELEM, \ 48 x, \ 49 inst)), \ 50 ()) \ 51 } 52 53 #endif /* ZEPHYR_B91_PINCTRL_COMMON_H_ */ 54