1 /* 2 * Copyright (c) 2023 Nuvoton Technology Corporation. 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef _NUVOTON_NUMAKER_PINCTRL_SOC_H_ 8 #define _NUVOTON_NUMAKER_PINCTRL_SOC_H_ 9 10 #include <zephyr/devicetree.h> 11 #include <stdint.h> 12 13 #define PORT_INDEX(pinmux) (((pinmux)&0xF0000000) >> 28) 14 #define PIN_INDEX(pinmux) (((pinmux)&0x0F000000) >> 24) 15 #define MFP_CFG(pinmux) (((pinmux)&0x000000FF) << ((PIN_INDEX(pinmux) % 4) * 8)) 16 #define NU_MFP_POS(pinindex) ((pinindex % 4) * 8) 17 #define NU_MFP_MASK(pinindex) (0x1f << NU_MFP_POS(pinindex)) 18 19 #ifdef __cplusplus 20 extern "C" { 21 #endif 22 23 typedef struct pinctrl_soc_pin_t { 24 uint32_t pin_mux; 25 uint32_t open_drain: 1; 26 uint32_t schmitt_enable: 1; 27 uint32_t slew_rate: 2; 28 uint32_t digital_disable: 1; 29 } pinctrl_soc_pin_t; 30 31 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 32 { \ 33 .pin_mux = DT_PROP_BY_IDX(node_id, prop, idx), \ 34 .open_drain = DT_PROP(node_id, drive_open_drain), \ 35 .schmitt_enable = DT_PROP(node_id, input_schmitt_enable), \ 36 .slew_rate = DT_ENUM_IDX(node_id, slew_rate), \ 37 .digital_disable = DT_PROP(node_id, digital_path_disable), \ 38 }, 39 40 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 41 { \ 42 DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ 43 Z_PINCTRL_STATE_PIN_INIT) \ 44 } 45 46 #ifdef __cplusplus 47 } 48 #endif 49 50 #endif /* _NUVOTON_NUMAKER_PINCTRL_SOC_H_ */ 51