1 /* 2 * Copyright 2023-2024 NXP 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 */ 6 #include "sm_pinctrl.h" 7 #include "scmi_pinctrl.h" 8 #include "scmi_common.h" 9 10 /*! 11 * @brief Sets the IOMUXC pin mux mode. 12 * @note The first five parameters can be filled with the pin function ID macros. 13 * 14 * @param muxRegister The pin mux register 15 * @param muxMode The pin mux mode 16 * @param inputRegister The select input register 17 * @param inputDaisy The input daisy 18 * @param configRegister The config register 19 * @param inputOn The software input on 20 */ SM_PINCTRL_SetPinMux(sm_pinctrl_t * sm_pinctrl)21void SM_PINCTRL_SetPinMux(sm_pinctrl_t *sm_pinctrl) 22 { 23 scmi_pin_config_t configs[3]; 24 uint32_t numConfigs = 0; 25 uint32_t channel = sm_pinctrl->channel; 26 uint32_t muxRegister = sm_pinctrl->mux_register; 27 uint32_t muxMode = sm_pinctrl->mux_mode; 28 uint32_t inputRegister = sm_pinctrl->input_register; 29 uint32_t inputDaisy = sm_pinctrl->input_daisy; 30 uint32_t inputOnfield = sm_pinctrl->input_on_field; 31 32 if (muxRegister) 33 { 34 configs[numConfigs].type = SCMI_PINCTRL_TYPE_MUX; 35 configs[numConfigs].value = SM_PLATFORM_PINCTRL_MUX_MODE(muxMode) | SM_PLATFORM_PINCTRL_SION(inputOnfield); 36 numConfigs++; 37 } 38 39 if (inputRegister & 0xFFFF) 40 { 41 configs[numConfigs].type = SCMI_PINCTRL_TYPE_DAISY_ID; 42 configs[numConfigs].value = (inputRegister - SM_PLATFORM_PINCTRL_DAISYREG_OFF) / 4; 43 numConfigs++; 44 configs[numConfigs].type = SCMI_PINCTRL_TYPE_DAISY_CFG; 45 configs[numConfigs].value = inputDaisy; 46 numConfigs++; 47 } 48 49 if (muxRegister || inputRegister) 50 { 51 uint32_t status = SCMI_ERR_SUCCESS; 52 uint32_t attributes = 53 SCMI_PINCTRL_SET_ATTR_SELECTOR(SCMI_PINCTRL_SEL_PIN) | SCMI_PINCTRL_SET_ATTR_NUM_CONFIGS(numConfigs); 54 55 status = SCMI_PinctrlSettingsConfigure(channel, (muxRegister - SM_PLATFORM_PINCTRL_MUXREG_OFF) / 4, 0U, attributes, configs); 56 /* Find something wrong ASAP(components/scmi/scmi_common.h: scmi error code) */ 57 while (status != SCMI_ERR_SUCCESS); 58 } 59 } 60 61 /*! 62 * @brief Sets the IOMUXC pin configuration. 63 * @note The previous five parameters can be filled with the pin function ID macros. 64 * 65 * @param muxRegister The pin mux register 66 * @param muxMode The pin mux mode 67 * @param inputRegister The select input register 68 * @param inputDaisy The input daisy 69 * @param configRegister The config register 70 * @param configValue The pin config value 71 */ SM_PINCTRL_SetPinCfg(sm_pinctrl_t * sm_pinctrl)72void SM_PINCTRL_SetPinCfg(sm_pinctrl_t *sm_pinctrl) 73 { 74 uint32_t channel = sm_pinctrl->channel; 75 uint32_t configRegister = sm_pinctrl->config_register; 76 uint32_t configValue = sm_pinctrl->config_value; 77 78 if (configRegister) 79 { 80 uint32_t status = SCMI_ERR_SUCCESS; 81 uint32_t attributes = 82 SCMI_PINCTRL_SET_ATTR_SELECTOR(SCMI_PINCTRL_SEL_PIN) | SCMI_PINCTRL_SET_ATTR_NUM_CONFIGS(1); 83 scmi_pin_config_t configs; 84 85 configs.type = SCMI_PINCTRL_TYPE_CONFIG; 86 configs.value = configValue; 87 88 status = SCMI_PinctrlSettingsConfigure(channel, (configRegister - SM_PLATFORM_PINCTRL_CFGREG_OFF) / 4, 0U, attributes, &configs); 89 /* Find something wrong ASAP(components/scmi/scmi_common.h: scmi error code) */ 90 while (status != SCMI_ERR_SUCCESS); 91 } 92 } 93