|
| 1 | +/* |
| 2 | + * Copyright (c) 2021 NXP |
| 3 | + * |
| 4 | + * SPDX-License-Identifier: Apache-2.0 |
| 5 | + */ |
| 6 | + |
| 7 | +#include <drivers/pinctrl.h> |
| 8 | +#include <soc.h> |
| 9 | +#include <fsl_iomuxc.h> |
| 10 | +#include <fsl_gpio.h> |
| 11 | + |
| 12 | +int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, |
| 13 | + uintptr_t reg) |
| 14 | +{ |
| 15 | + /* configure all pins */ |
| 16 | + for (uint8_t i = 0U; i < pin_cnt; i++) { |
| 17 | + uint32_t mux_register = pins[i].pinmux.mux_register; |
| 18 | + uint32_t mux_mode = pins[i].pinmux.mux_mode; |
| 19 | + uint32_t input_register = pins[i].pinmux.input_register; |
| 20 | + uint32_t input_daisy = pins[i].pinmux.input_daisy; |
| 21 | + uint32_t pin_ctrl_flags = pins[i].pin_ctrl_flags; |
| 22 | + volatile uint32_t *config_register = (uint32_t *)pins[i].pinmux.config_register; |
| 23 | + uint32_t config_val = *config_register; |
| 24 | + |
| 25 | + |
| 26 | + |
| 27 | + IOMUXC_SetPinMux(mux_register, mux_mode, input_register, |
| 28 | + input_daisy, (uint32_t)config_register, |
| 29 | + MCUX_RT_INPUT_ENABLE(pin_ctrl_flags)); |
| 30 | + |
| 31 | + if (MCUX_RT_INPUT_SCHMITT_ENABLE(pin_ctrl_flags)) { |
| 32 | + config_val |= IOMUXC_SW_PAD_CTL_PAD_HYS(1); |
| 33 | + } |
| 34 | + if (MCUX_RT_DRIVE_OPEN_DRAIN(pin_ctrl_flags)) { |
| 35 | + config_val |= IOMUXC_SW_PAD_CTL_PAD_ODE(1); |
| 36 | + } |
| 37 | + if (MCUX_RT_BIAS_BUS_HOLD(pin_ctrl_flags)) { |
| 38 | + /* Set pull keeper select to keeper, and pull keeper enable to 1 */ |
| 39 | + config_val |= IOMUXC_SW_PAD_CTL_PAD_PKE(1); |
| 40 | + config_val &= ~IOMUXC_SW_PAD_CTL_PAD_PUE_MASK; |
| 41 | + } |
| 42 | + if (MCUX_RT_BIAS_PULL_DOWN(pin_ctrl_flags)) { |
| 43 | + /* Set pull keeper select to pull, and pull keeper enable to 1 */ |
| 44 | + config_val |= IOMUXC_SW_PAD_CTL_PAD_PKE(1) | IOMUXC_SW_PAD_CTL_PAD_PUE(1); |
| 45 | + /* Set PUS to 0b00 to select pulldown resistor */ |
| 46 | + config_val &= ~IOMUXC_SW_PAD_CTL_PAD_PUS_MASK; |
| 47 | + } |
| 48 | + if (MCUX_RT_BIAS_PULL_UP(pin_ctrl_flags)) { |
| 49 | + /* Set pull keeper select to pull, and pull keeper enable to 1 */ |
| 50 | + config_val |= IOMUXC_SW_PAD_CTL_PAD_PKE(1) | IOMUXC_SW_PAD_CTL_PAD_PUE(1); |
| 51 | + /* Set PUS field to selected value */ |
| 52 | + config_val = ((config_val & ~IOMUXC_SW_PAD_CTL_PAD_PUS_MASK) | |
| 53 | + IOMUXC_SW_PAD_CTL_PAD_PUS(MCUX_RT_BIAS_PULL_UP(pin_ctrl_flags))); |
| 54 | + } |
| 55 | + /* Set drive strength field */ |
| 56 | + config_val = ((config_val & ~IOMUXC_SW_PAD_CTL_PAD_DSE_MASK) | |
| 57 | + IOMUXC_SW_PAD_CTL_PAD_DSE(MCUX_RT_DRIVE_STRENGTH(pin_ctrl_flags))); |
| 58 | + /* Set speed field */ |
| 59 | + config_val = ((config_val & ~IOMUXC_SW_PAD_CTL_PAD_SPEED_MASK) | |
| 60 | + IOMUXC_SW_PAD_CTL_PAD_SPEED(MCUX_RT_SPEED(pin_ctrl_flags))); |
| 61 | + /* Set slew rate field */ |
| 62 | + config_val = ((config_val & ~IOMUXC_SW_PAD_CTL_PAD_SRE_MASK) | |
| 63 | + IOMUXC_SW_PAD_CTL_PAD_SRE(MCUX_RT_SLEW_RATE(pin_ctrl_flags))); |
| 64 | + /* Write out config value */ |
| 65 | + *config_register = config_val; |
| 66 | + } |
| 67 | + |
| 68 | + return 0; |
| 69 | +} |
| 70 | + |
| 71 | +static int mcux_pinctrl_init(const struct device *dev) |
| 72 | +{ |
| 73 | + ARG_UNUSED(dev); |
| 74 | + |
| 75 | + CLOCK_EnableClock(kCLOCK_Iomuxc); |
| 76 | + CLOCK_EnableClock(kCLOCK_IomuxcSnvs); |
| 77 | + |
| 78 | + return 0; |
| 79 | +} |
| 80 | + |
| 81 | +SYS_INIT(mcux_pinctrl_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_DEFAULT); |
0 commit comments