1 /* 2 * Copyright (c) 2023 Antmicro <www.antmicro.com> 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/drivers/pinctrl.h> 8 9 /* ambiq-sdk includes */ 10 #include <am_mcu_apollo.h> 11 pinctrl_configure_pin(const pinctrl_soc_pin_t * pin)12static void pinctrl_configure_pin(const pinctrl_soc_pin_t *pin) 13 { 14 am_hal_gpio_pincfg_t pin_config = {0}; 15 16 #if defined(CONFIG_SOC_SERIES_APOLLO3X) 17 pin_config.uFuncSel = pin->alt_func; 18 pin_config.eGPInput = 19 pin->input_enable ? AM_HAL_GPIO_PIN_INPUT_ENABLE : AM_HAL_GPIO_PIN_INPUT_NONE; 20 pin_config.eGPOutcfg = pin->push_pull ? AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL 21 : pin->open_drain ? AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN 22 : pin->tristate ? AM_HAL_GPIO_PIN_OUTCFG_TRISTATE 23 : AM_HAL_GPIO_PIN_OUTCFG_DISABLE; 24 pin_config.eDriveStrength = pin->drive_strength; 25 pin_config.uNCE = pin->iom_nce; 26 #if defined(CONFIG_SOC_APOLLO3P_BLUE) 27 pin_config.bIomMSPIn = pin->iom_mspi; 28 #endif 29 pin_config.uIOMnum = pin->iom_num; 30 31 if (pin->bias_pull_up) { 32 pin_config.ePullup = pin->ambiq_pull_up_ohms + AM_HAL_GPIO_PIN_PULLUP_1_5K; 33 } else if (pin->bias_pull_down) { 34 pin_config.ePullup = AM_HAL_GPIO_PIN_PULLDOWN; 35 } 36 #else 37 pin_config.GP.cfg_b.uFuncSel = pin->alt_func; 38 pin_config.GP.cfg_b.eGPInput = 39 pin->input_enable ? AM_HAL_GPIO_PIN_INPUT_ENABLE : AM_HAL_GPIO_PIN_INPUT_NONE; 40 pin_config.GP.cfg_b.eGPOutCfg = pin->push_pull ? AM_HAL_GPIO_PIN_OUTCFG_PUSHPULL 41 : pin->open_drain ? AM_HAL_GPIO_PIN_OUTCFG_OPENDRAIN 42 : pin->tristate ? AM_HAL_GPIO_PIN_OUTCFG_TRISTATE 43 : AM_HAL_GPIO_PIN_OUTCFG_DISABLE; 44 pin_config.GP.cfg_b.eDriveStrength = pin->drive_strength; 45 pin_config.GP.cfg_b.uSlewRate = pin->slew_rate; 46 pin_config.GP.cfg_b.uNCE = pin->iom_nce; 47 pin_config.GP.cfg_b.eIntDir = pin->interrupt_direction; 48 49 if (pin->bias_pull_up) { 50 pin_config.GP.cfg_b.ePullup = pin->ambiq_pull_up_ohms + AM_HAL_GPIO_PIN_PULLUP_1_5K; 51 } else if (pin->bias_pull_down) { 52 pin_config.GP.cfg_b.ePullup = AM_HAL_GPIO_PIN_PULLDOWN_50K; 53 } 54 #endif 55 am_hal_gpio_pinconfig(pin->pin_num, pin_config); 56 } 57 pinctrl_configure_pins(const pinctrl_soc_pin_t * pins,uint8_t pin_cnt,uintptr_t reg)58int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg) 59 { 60 ARG_UNUSED(reg); 61 62 for (uint8_t i = 0U; i < pin_cnt; i++) { 63 pinctrl_configure_pin(pins++); 64 } 65 66 return 0; 67 } 68