1 /* 2 * Copyright (c) 2023 Ambiq Micro Inc. <www.ambiq.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_SOC_ARM_AMBIQ_APOLLO3_PINCTRL_SOC_H_ 8 #define ZEPHYR_SOC_ARM_AMBIQ_APOLLO3_PINCTRL_SOC_H_ 9 10 #include <zephyr/dt-bindings/pinctrl/ambiq-apollo3-pinctrl.h> 11 12 /** 13 * @brief Type to hold a pin's pinctrl configuration. 14 */ 15 struct apollo3_pinctrl_soc_pin { 16 /** Pin number 0..74 */ 17 uint32_t pin_num: 7; 18 /** Alternative function (UART, SPI, etc.) */ 19 uint32_t alt_func: 3; 20 /** Enable the pin as an input */ 21 uint32_t input_enable: 1; 22 /** Drive strength, relative to full-driver strength */ 23 uint32_t drive_strength: 2; 24 /** Drive actively high or low */ 25 uint32_t push_pull: 1; 26 /** Drive with open drain */ 27 uint32_t open_drain: 1; 28 /** High impedance mode */ 29 uint32_t tristate: 1; 30 /** Enable the internal pull up resistor */ 31 uint32_t bias_pull_up: 1; 32 /** Enable the internal pull down resistor */ 33 uint32_t bias_pull_down: 1; 34 /** pullup resistor value */ 35 uint32_t ambiq_pull_up_ohms: 3; 36 /** IOM nCE module select */ 37 uint32_t iom_nce: 2; 38 /** IOM or MSPI */ 39 uint32_t iom_mspi: 1; 40 /** IOM/MSPI instance number */ 41 uint32_t iom_num: 3; 42 }; 43 44 typedef struct apollo3_pinctrl_soc_pin pinctrl_soc_pin_t; 45 46 /** 47 * @brief Utility macro to initialize each pin. 48 * 49 * @param node_id Node identifier. 50 * @param prop Property name. 51 * @param idx Property entry index. 52 */ 53 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \ 54 { \ 55 APOLLO3_GET_PIN_NUM(DT_PROP_BY_IDX(node_id, prop, idx)), \ 56 APOLLO3_GET_PIN_ALT_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)), \ 57 DT_PROP(node_id, input_enable), \ 58 DT_ENUM_IDX(node_id, drive_strength), \ 59 DT_PROP(node_id, drive_push_pull), \ 60 DT_PROP(node_id, drive_open_drain), \ 61 DT_PROP(node_id, bias_high_impedance), \ 62 DT_PROP(node_id, bias_pull_up), \ 63 DT_PROP(node_id, bias_pull_down), \ 64 DT_ENUM_IDX(node_id, ambiq_pull_up_ohms), \ 65 DT_PROP(node_id, ambiq_iom_nce_module), \ 66 DT_PROP(node_id, ambiq_iom_mspi), \ 67 DT_PROP(node_id, ambiq_iom_num), \ 68 }, 69 70 /** 71 * @brief Utility macro to initialize state pins contained in a given property. 72 * 73 * @param node_id Node identifier. 74 * @param prop Property name describing state pins. 75 */ 76 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \ 77 { \ 78 DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \ 79 Z_PINCTRL_STATE_PIN_INIT) \ 80 } 81 82 #define APOLLO3_GET_PIN_NUM(pinctrl) (((pinctrl) >> APOLLO3_PIN_NUM_POS) & APOLLO3_PIN_NUM_MASK) 83 #define APOLLO3_GET_PIN_ALT_FUNC(pinctrl) \ 84 (((pinctrl) >> APOLLO3_ALT_FUNC_POS) & APOLLO3_ALT_FUNC_MASK) 85 86 #endif /* ZEPHYR_SOC_ARM_AMBIQ_APOLLO3_PINCTRL_SOC_H_ */ 87