1 /*
2 * Copyright 2024 NXP
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/pinctrl.h>
8 #include <zephyr/drivers/firmware/scmi/pinctrl.h>
9
scmi_pinctrl_configure_pin(const pinctrl_soc_pin_t * pin)10 static int scmi_pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
11 {
12 struct scmi_pinctrl_settings settings;
13 int ret, config_num;
14
15 config_num = 0;
16
17 /* set mux value, and daisy */
18 settings.id = (pin->pinmux.mux_register - IOMUXC_MUXREG) / 4;
19 settings.config[0] = PIN_CONFIG_TYPE_MUX;
20 settings.config[1] = IOMUXC_INPUT_ENABLE(pin->pin_ctrl_flags)
21 ? (pin->pinmux.mux_mode | IOMUXC_SION(1))
22 : pin->pinmux.mux_mode;
23 config_num++;
24
25 if (pin->pinmux.input_register) {
26 settings.config[2] = PIN_CONFIG_TYPE_DAISY_ID;
27 settings.config[3] = (pin->pinmux.input_register - IOMUXC_DAISYREG) / 4;
28 config_num++;
29
30 settings.config[4] = PIN_CONFIG_TYPE_DAISY_CFG;
31 settings.config[5] = pin->pinmux.input_daisy;
32 config_num++;
33 }
34
35 settings.attributes =
36 SCMI_PINCTRL_CONFIG_ATTRIBUTES(0x0, config_num, SCMI_PINCTRL_SELECTOR_PIN);
37
38 ret = scmi_pinctrl_settings_configure(&settings);
39 if (ret < 0) {
40 return ret;
41 }
42
43 /* set config value */
44 settings.attributes = SCMI_PINCTRL_CONFIG_ATTRIBUTES(0x0, 0x1, SCMI_PINCTRL_SELECTOR_PIN);
45 settings.id = (pin->pinmux.config_register - IOMUXC_CFGREG) / 4;
46 settings.config[0] = PIN_CONFIG_TYPE_CONFIG;
47 settings.config[1] = pin->pin_ctrl_flags & (~(1 << IOMUXC_INPUT_ENABLE_SHIFT));
48
49 ret = scmi_pinctrl_settings_configure(&settings);
50 if (ret < 0) {
51 return ret;
52 }
53
54 return 0;
55 }
56
pinctrl_configure_pins(const pinctrl_soc_pin_t * pins,uint8_t pin_cnt,uintptr_t reg)57 int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
58 {
59 int ret;
60 /* configure all pins */
61 for (uint8_t i = 0U; i < pin_cnt; i++) {
62 ret = scmi_pinctrl_configure_pin(&pins[i]);
63 if (ret < 0) {
64 return ret;
65 }
66 }
67 return 0;
68 }
69