drivers: serial: enable pin control for lpc11u6x serial driver

Enable pin control api for lpc11u6x serial driver, and remove pinmux api
usage.

Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
Daniel DeGrasse 2022-04-13 11:27:04 -05:00 committed by David Leach
commit 7e89ce9f19
5 changed files with 24 additions and 70 deletions

View file

@ -8,7 +8,6 @@
#include <zephyr/arch/arm/aarch32/cortex_m/cmsis.h>
#include <zephyr/drivers/uart.h>
#include <zephyr/drivers/pinmux.h>
#include <zephyr/drivers/clock_control.h>
#include "uart_lpc11u6x.h"
@ -345,20 +344,14 @@ static int lpc11u6x_uart0_init(const struct device *dev)
{
const struct lpc11u6x_uart0_config *cfg = dev->config;
struct lpc11u6x_uart0_data *data = dev->data;
const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv;
const struct device *clk_drv;
int err;
/* Configure RX and TX pin via the pinmux driver */
rx_pinmux_drv = device_get_binding(cfg->rx_pinmux_drv_name);
if (!rx_pinmux_drv) {
return -EINVAL;
/* Apply default pin control state to select RX and TX pins */
err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT);
if (err) {
return err;
}
pinmux_pin_set(rx_pinmux_drv, cfg->rx_pin, cfg->rx_func);
tx_pinmux_drv = device_get_binding(cfg->tx_pinmux_drv_name);
if (!tx_pinmux_drv) {
return -EINVAL;
}
pinmux_pin_set(tx_pinmux_drv, cfg->tx_pin, cfg->tx_func);
/* Call clock driver to initialize uart0 clock */
clk_drv = device_get_binding(cfg->clock_drv_name);
@ -392,19 +385,14 @@ static int lpc11u6x_uart0_init(const struct device *dev)
static void lpc11u6x_uart0_isr_config(const struct device *dev);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
PINCTRL_DT_DEFINE(DT_NODELABEL(uart0));
static const struct lpc11u6x_uart0_config uart0_config = {
.uart0 = (struct lpc11u6x_uart0_regs *)
DT_REG_ADDR(DT_NODELABEL(uart0)),
.clock_drv_name = DT_LABEL(DT_PHANDLE(DT_NODELABEL(uart0), clocks)),
.rx_pinmux_drv_name =
DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd)),
.tx_pinmux_drv_name =
DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd)),
.pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(uart0)),
.clkid = DT_PHA_BY_IDX(DT_NODELABEL(uart0), clocks, 0, clkid),
.rx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd, pin),
.rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, rxd, function),
.tx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd, pin),
.tx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart0), pinmuxs, txd, function),
.baudrate = DT_PROP(DT_NODELABEL(uart0), current_speed),
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
.irq_config_func = lpc11u6x_uart0_isr_config,
@ -791,20 +779,14 @@ static int lpc11u6x_uartx_init(const struct device *dev)
{
const struct lpc11u6x_uartx_config *cfg = dev->config;
struct lpc11u6x_uartx_data *data = dev->data;
const struct device *clk_drv, *rx_pinmux_drv, *tx_pinmux_drv;
const struct device *clk_drv;
int err;
/* Configure RX and TX pin via the pinmux driver */
rx_pinmux_drv = device_get_binding(cfg->rx_pinmux_drv_name);
if (!rx_pinmux_drv) {
return -EINVAL;
/* Apply default pin control state to select RX and TX pins */
err = pinctrl_apply_state(cfg->pincfg, PINCTRL_STATE_DEFAULT);
if (err) {
return err;
}
pinmux_pin_set(rx_pinmux_drv, cfg->rx_pin, cfg->rx_func);
tx_pinmux_drv = device_get_binding(cfg->tx_pinmux_drv_name);
if (!tx_pinmux_drv) {
return -EINVAL;
}
pinmux_pin_set(tx_pinmux_drv, cfg->tx_pin, cfg->tx_func);
/* Call clock driver to initialize uart0 clock */
clk_drv = device_get_binding(cfg->clock_drv_name);
@ -874,25 +856,15 @@ static const struct uart_driver_api uartx_api = {
#define LPC11U6X_UARTX_INIT(idx) \
PINCTRL_DT_DEFINE(DT_NODELABEL(uart##idx)); \
\
static const struct lpc11u6x_uartx_config uart_cfg_##idx = { \
.base = (struct lpc11u6x_uartx_regs *) \
DT_REG_ADDR(DT_NODELABEL(uart##idx)), \
.clock_drv_name = \
DT_LABEL(DT_PHANDLE(DT_NODELABEL(uart##idx), clocks)), \
.rx_pinmux_drv_name = \
DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, rxd)), \
.tx_pinmux_drv_name = \
DT_LABEL(DT_PHANDLE_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, txd)), \
.clkid = DT_PHA_BY_IDX(DT_NODELABEL(uart##idx), clocks, 0, clkid), \
.rx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, rxd, pin), \
.rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), \
pinmuxs, rxd, function), \
.rx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, \
rxd, function), \
.tx_pin = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, txd, pin), \
.tx_func = DT_PHA_BY_NAME(DT_NODELABEL(uart##idx), pinmuxs, \
txd, function), \
.pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(uart##idx)), \
.baudrate = DT_PROP(DT_NODELABEL(uart##idx), current_speed), \
}; \
\

View file

@ -7,6 +7,8 @@
#ifndef ZEPHYR_DRIVERS_SERIAL_UART_LPC11U6X_H_
#define ZEPHYR_DRIVERS_SERIAL_UART_LPC11U6X_H_
#include <zephyr/drivers/pinctrl.h>
#define LPC11U6X_UART0_CLK 14745600
#define LPC11U6X_UART0_LCR_WLS_5BITS 0
@ -127,14 +129,9 @@ struct lpc11u6x_uart0_regs {
struct lpc11u6x_uart0_config {
struct lpc11u6x_uart0_regs *uart0;
const char *clock_drv_name;
const char *rx_pinmux_drv_name;
const char *tx_pinmux_drv_name;
uint32_t baudrate;
uint32_t clkid;
uint8_t rx_pin;
uint8_t rx_func;
uint8_t tx_pin;
uint8_t tx_func;
const struct pinctrl_dev_config *pincfg;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
void (*irq_config_func)(const struct device *dev);
#endif /* CONFIG_UART_INTERRUPT_DRIVEN */
@ -171,14 +168,9 @@ struct lpc11u6x_uartx_regs {
struct lpc11u6x_uartx_config {
struct lpc11u6x_uartx_regs *base;
const char *clock_drv_name;
const char *rx_pinmux_drv_name;
const char *tx_pinmux_drv_name;
uint32_t baudrate;
uint32_t clkid;
uint8_t rx_pin;
uint8_t rx_func;
uint8_t tx_pin;
uint8_t tx_func;
const struct pinctrl_dev_config *pincfg;
};
struct lpc11u6x_uartx_data {