From 07d9a4292df73eb422f104038331aef292f1916f Mon Sep 17 00:00:00 2001 From: Tim Lin Date: Wed, 30 Mar 2022 17:41:17 +0800 Subject: [PATCH] ITE: drivers/serial: Use pinctrl instead of pinmux driver Use pinctrl instead of pinmux driver. Signed-off-by: Tim Lin --- boards/riscv/it8xxx2_evb/CMakeLists.txt | 6 --- boards/riscv/it8xxx2_evb/it8xxx2_evb.dts | 7 ++++ boards/riscv/it8xxx2_evb/pinmux.c | 47 ----------------------- drivers/serial/uart_ite_it8xxx2.c | 16 +++++++- dts/bindings/serial/ite,it8xxx2-uart.yaml | 8 +++- dts/riscv/ite/it8xxx2-pinctrl-map.dtsi | 24 ++++++++++++ 6 files changed, 53 insertions(+), 55 deletions(-) delete mode 100644 boards/riscv/it8xxx2_evb/CMakeLists.txt delete mode 100644 boards/riscv/it8xxx2_evb/pinmux.c create mode 100644 dts/riscv/ite/it8xxx2-pinctrl-map.dtsi diff --git a/boards/riscv/it8xxx2_evb/CMakeLists.txt b/boards/riscv/it8xxx2_evb/CMakeLists.txt deleted file mode 100644 index 4b9798beb01..00000000000 --- a/boards/riscv/it8xxx2_evb/CMakeLists.txt +++ /dev/null @@ -1,6 +0,0 @@ -# -# Copyright (c) 2020 ITE Corporation. All Rights Reserved. -# -# SPDX-License-Identifier: Apache-2.0 -zephyr_library() -zephyr_library_sources(pinmux.c) diff --git a/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts b/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts index 27c2fc671d8..e51220d3269 100644 --- a/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts +++ b/boards/riscv/it8xxx2_evb/it8xxx2_evb.dts @@ -8,6 +8,7 @@ #include #include #include +#include / { model = "IT8XXX2 EV-Board"; @@ -91,9 +92,15 @@ }; &ite_uart1_wrapper { status = "okay"; + pinctrl-0 = <&uart1_rx_gpb0_default + &uart1_tx_gpb1_default>; + pinctrl-names = "default"; }; &ite_uart2_wrapper { status = "okay"; + pinctrl-0 = <&uart2_rx_gph1_default + &uart2_tx_gph2_default>; + pinctrl-names = "default"; }; /* pwm for test */ &pwm0 { diff --git a/boards/riscv/it8xxx2_evb/pinmux.c b/boards/riscv/it8xxx2_evb/pinmux.c deleted file mode 100644 index 589485f2562..00000000000 --- a/boards/riscv/it8xxx2_evb/pinmux.c +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright (c) 2020 ITE Corporation. All Rights Reserved. - * - * SPDX-License-Identifier: Apache-2.0 - * - */ - -#include -#include -#include - -static int it8xxx2_evb_pinmux_init(const struct device *dev) -{ - ARG_UNUSED(dev); - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmuxb), okay) - const struct device *portb = DEVICE_DT_GET(DT_NODELABEL(pinmuxb)); - - __ASSERT_NO_MSG(device_is_ready(portb)); -#endif -#if DT_NODE_HAS_STATUS(DT_NODELABEL(pinmuxh), okay) - const struct device *porth = DEVICE_DT_GET(DT_NODELABEL(pinmuxh)); - - __ASSERT_NO_MSG(device_is_ready(porth)); -#endif - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) - /* SIN0 */ - pinmux_pin_set(portb, 0, IT8XXX2_PINMUX_FUNC_3); - /* SOUT0 */ - pinmux_pin_set(portb, 1, IT8XXX2_PINMUX_FUNC_3); - /* Pullup SIN0 to received data */ - pinmux_pin_pullup(portb, 0, PINMUX_PULLUP_ENABLE); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart1), okay) */ - -#if DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) - /* SIN1 */ - pinmux_pin_set(porth, 1, IT8XXX2_PINMUX_FUNC_4); - /* SOUT1 */ - pinmux_pin_set(porth, 2, IT8XXX2_PINMUX_FUNC_4); - /* Pullup SIN1 to received data */ - pinmux_pin_pullup(porth, 1, PINMUX_PULLUP_ENABLE); -#endif /* DT_NODE_HAS_STATUS(DT_NODELABEL(uart2), okay) */ - - return 0; -} -SYS_INIT(it8xxx2_evb_pinmux_init, PRE_KERNEL_1, CONFIG_PINMUX_INIT_PRIORITY); diff --git a/drivers/serial/uart_ite_it8xxx2.c b/drivers/serial/uart_ite_it8xxx2.c index 1ec34fac3f6..0999399ba4d 100644 --- a/drivers/serial/uart_ite_it8xxx2.c +++ b/drivers/serial/uart_ite_it8xxx2.c @@ -8,6 +8,7 @@ #include #include +#include #include #include #include @@ -27,6 +28,8 @@ struct uart_it8xxx2_config { struct gpio_dt_spec gpio_wui; /* UART handle */ const struct device *uart_dev; + /* UART alternate configuration */ + const struct pinctrl_dev_config *pcfg; }; struct uart_it8xxx2_data { @@ -124,8 +127,17 @@ static void uart_it8xxx2_rx_refresh_timeout(struct k_work *work) static int uart_it8xxx2_init(const struct device *dev) { -#ifdef CONFIG_PM_DEVICE const struct uart_it8xxx2_config *const config = dev->config; + int status; + + /* Set the pin to UART alternate function. */ + status = pinctrl_apply_state(config->pcfg, PINCTRL_STATE_DEFAULT); + if (status < 0) { + LOG_ERR("Failed to configure UART pins"); + return status; + } + +#ifdef CONFIG_PM_DEVICE const struct device *uart_console_dev = DEVICE_DT_GET(DT_CHOSEN(zephyr_console)); int ret = 0; @@ -175,10 +187,12 @@ static int uart_it8xxx2_init(const struct device *dev) } #define UART_ITE_IT8XXX2_INIT(inst) \ + PINCTRL_DT_INST_DEFINE(inst); \ static const struct uart_it8xxx2_config uart_it8xxx2_cfg_##inst = { \ .port = DT_INST_PROP(inst, port_num), \ .gpio_wui = GPIO_DT_SPEC_INST_GET(inst, gpios), \ .uart_dev = DEVICE_DT_GET(DT_INST_PHANDLE(inst, uart_dev)), \ + .pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \ }; \ \ static struct uart_it8xxx2_data uart_it8xxx2_data_##inst; \ diff --git a/dts/bindings/serial/ite,it8xxx2-uart.yaml b/dts/bindings/serial/ite,it8xxx2-uart.yaml index e3a8b8a3312..73689ac0213 100644 --- a/dts/bindings/serial/ite,it8xxx2-uart.yaml +++ b/dts/bindings/serial/ite,it8xxx2-uart.yaml @@ -5,7 +5,7 @@ description: ITE, IT8XXX2-UART node compatible: "ite,it8xxx2-uart" -include: uart-controller.yaml +include: [uart-controller.yaml, pinctrl-device.yaml] properties: reg: @@ -24,3 +24,9 @@ properties: type: phandle required: true description: Get the handle of the UART device + + pinctrl-0: + required: true + + pinctrl-names: + required: true diff --git a/dts/riscv/ite/it8xxx2-pinctrl-map.dtsi b/dts/riscv/ite/it8xxx2-pinctrl-map.dtsi new file mode 100644 index 00000000000..906807a3a0a --- /dev/null +++ b/dts/riscv/ite/it8xxx2-pinctrl-map.dtsi @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2022 ITE Corporation. All Rights Reserved. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +&pinctrl { + /* UART alternate function */ + uart1_rx_gpb0_default: uart1_rx_gpb0_default { + pinmuxs = <&pinctrlb 0 IT8XXX2_ALT_FUNC_3>; + }; + uart1_tx_gpb1_default: uart1_tx_gpb1_default { + pinmuxs = <&pinctrlb 1 IT8XXX2_ALT_FUNC_3>; + }; + uart2_rx_gph1_default: uart2_rx_gph1_default { + pinmuxs = <&pinctrlh 1 IT8XXX2_ALT_FUNC_4>; + }; + uart2_tx_gph2_default: uart2_tx_gph2_default { + pinmuxs = <&pinctrlh 2 IT8XXX2_ALT_FUNC_4>; + }; + +};