|
8 | 8 | #include <zephyr/arch/arm/aarch32/cortex_m/cmsis.h>
|
9 | 9 |
|
10 | 10 | #include <zephyr/drivers/uart.h>
|
11 |
| -#include <zephyr/drivers/pinmux.h> |
12 | 11 | #include <zephyr/drivers/clock_control.h>
|
13 | 12 |
|
14 | 13 | #include "uart_lpc11u6x.h"
|
@@ -345,20 +344,14 @@ static int lpc11u6x_uart0_init(const struct device *dev)
|
345 | 344 | {
|
346 | 345 | const struct lpc11u6x_uart0_config *cfg = dev->config;
|
347 | 346 | struct lpc11u6x_uart0_data *data = dev->data;
|
348 |
| - const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv; |
| 347 | + const struct device *clk_drv; |
| 348 | + int err; |
349 | 349 |
|
350 |
| - /* Configure RX and TX pin via the pinmux driver */ |
351 |
| - rx_pinmux_drv = device_get_binding(cfg->rx_pinmux_drv_name); |
352 |
| - if (!rx_pinmux_drv) { |
353 |
| - return -EINVAL; |
| 350 | + /* Apply default pin control state to select RX and TX pins */ |
| 351 | + err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT); |
| 352 | + if (err) { |
| 353 | + return err; |
354 | 354 | }
|
355 |
| - pinmux_pin_set(rx_pinmux_drv, cfg->rx_pin, cfg->rx_func); |
356 |
| - |
357 |
| - tx_pinmux_drv = device_get_binding(cfg->tx_pinmux_drv_name); |
358 |
| - if (!tx_pinmux_drv) { |
359 |
| - return -EINVAL; |
360 |
| - } |
361 |
| - pinmux_pin_set(tx_pinmux_drv, cfg->tx_pin, cfg->tx_func); |
362 | 355 |
|
363 | 356 | /* Call clock driver to initialize uart0 clock */
|
364 | 357 | clk_drv = device_get_binding(cfg->clock_drv_name);
|
@@ -392,19 +385,14 @@ static int lpc11u6x_uart0_init(const struct device *dev)
|
392 | 385 | static void lpc11u6x_uart0_isr_config(const struct device *dev);
|
393 | 386 | #endif /* CONFIG_UART_INTERRUPT_DRIVEN */
|
394 | 387 |
|
| 388 | +PINCTRL_DT_DEFINE(DT_NODELABEL(uart0)); |
| 389 | + |
395 | 390 | static const struct lpc11u6x_uart0_config uart0_config = {
|
396 | 391 | .uart0 = (struct lpc11u6x_uart0_regs *)
|
397 | 392 | DT_REG_ADDR(DT_NODELABEL(uart0)),
|
398 | 393 | .clock_drv_name = DT_LABEL(DT_PHANDLE(DT_NODELABEL(uart0), clocks)),
|
399 |
| - .rx_pinmux_drv_name = |
400 |
| - DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd)), |
401 |
| - .tx_pinmux_drv_name = |
402 |
| - DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd)), |
| 394 | + .pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(uart0)), |
403 | 395 | .clkid = DT_PHA_BY_IDX(DT_NODELABEL(uart0), clocks, 0, clkid),
|
404 |
| - .rx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd, pin), |
405 |
| - .rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd, function), |
406 |
| - .tx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd, pin), |
407 |
| - .tx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd, function), |
408 | 396 | .baudrate = DT_PROP(DT_NODELABEL(uart0), current_speed),
|
409 | 397 | #ifdef CONFIG_UART_INTERRUPT_DRIVEN
|
410 | 398 | .irq_config_func = lpc11u6x_uart0_isr_config,
|
@@ -791,20 +779,14 @@ static int lpc11u6x_uartx_init(const struct device *dev)
|
791 | 779 | {
|
792 | 780 | const struct lpc11u6x_uartx_config *cfg = dev->config;
|
793 | 781 | struct lpc11u6x_uartx_data *data = dev->data;
|
794 |
| - const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv; |
| 782 | + const struct device *clk_drv; |
| 783 | + int err; |
795 | 784 |
|
796 |
| - /* Configure RX and TX pin via the pinmux driver */ |
797 |
| - rx_pinmux_drv = device_get_binding(cfg->rx_pinmux_drv_name); |
798 |
| - if (!rx_pinmux_drv) { |
799 |
| - return -EINVAL; |
800 |
| - } |
801 |
| - pinmux_pin_set(rx_pinmux_drv, cfg->rx_pin, cfg->rx_func); |
802 |
| - |
803 |
| - tx_pinmux_drv = device_get_binding(cfg->tx_pinmux_drv_name); |
804 |
| - if (!tx_pinmux_drv) { |
805 |
| - return -EINVAL; |
| 785 | + /* Apply default pin control state to select RX and TX pins */ |
| 786 | + err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT); |
| 787 | + if (err) { |
| 788 | + return err; |
806 | 789 | }
|
807 |
| - pinmux_pin_set(tx_pinmux_drv, cfg->tx_pin, cfg->tx_func); |
808 | 790 |
|
809 | 791 | /* Call clock driver to initialize uart0 clock */
|
810 | 792 | clk_drv = device_get_binding(cfg->clock_drv_name);
|
@@ -874,25 +856,15 @@ static const struct uart_driver_api uartx_api = {
|
874 | 856 |
|
875 | 857 |
|
876 | 858 | #define LPC11U6X_UARTX_INIT(idx) \
|
| 859 | +PINCTRL_DT_DEFINE(DT_NODELABEL(uart##idx)); \ |
877 | 860 | \
|
878 | 861 | static const struct lpc11u6x_uartx_config uart_cfg_##idx = { \
|
879 | 862 | .base = (struct lpc11u6x_uartx_regs *) \
|
880 | 863 | DT_REG_ADDR(DT_NODELABEL(uart##idx)), \
|
881 | 864 | .clock_drv_name = \
|
882 | 865 | DT_LABEL(DT_PHANDLE(DT_NODELABEL(uart##idx), clocks)), \
|
883 |
| - .rx_pinmux_drv_name = \ |
884 |
| - DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, rxd)), \ |
885 |
| - .tx_pinmux_drv_name = \ |
886 |
| - DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, txd)), \ |
887 | 866 | .clkid = DT_PHA_BY_IDX(DT_NODELABEL(uart##idx), clocks, 0, clkid), \
|
888 |
| - .rx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, rxd, pin), \ |
889 |
| - .rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), \ |
890 |
| - pinmuxs, rxd, function), \ |
891 |
| - .rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, \ |
892 |
| - rxd, function), \ |
893 |
| - .tx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, txd, pin), \ |
894 |
| - .tx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, \ |
895 |
| - txd, function), \ |
| 867 | + .pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(uart##idx)), \ |
896 | 868 | .baudrate = DT_PROP(DT_NODELABEL(uart##idx), current_speed), \
|
897 | 869 | }; \
|
898 | 870 | \
|
|
0 commit comments