Skip to content

Commit 740d7f7

Browse files
simonguinotnashif
authored andcommitted
drivers: serial: lpc11u6x: allow to configure data polarity
This patch adds support for the rx-invert and tx-invert device-tree properties to the uart_lpc11u6x driver for USARTs 1, 2, 3 and 4. Note that this feature is not supported by USART 0. Signed-off-by: Simon Guinot <[email protected]>
1 parent 3416f9a commit 740d7f7

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

drivers/serial/uart_lpc11u6x.c

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,11 @@ static void lpc11u6x_uart0_isr_config(const struct device *dev);
380380

381381
PINCTRL_DT_DEFINE(DT_NODELABEL(uart0));
382382

383+
BUILD_ASSERT(DT_PROP(DT_NODELABEL(uart0), rx_invert) == 0,
384+
"rx-invert not supported for UART0");
385+
BUILD_ASSERT(DT_PROP(DT_NODELABEL(uart0), tx_invert) == 0,
386+
"tx-invert not supported for UART0");
387+
383388
static const struct lpc11u6x_uart0_config uart0_config = {
384389
.uart0 = (struct lpc11u6x_uart0_regs *)
385390
DT_REG_ADDR(DT_NODELABEL(uart0)),
@@ -568,6 +573,13 @@ static int lpc11u6x_uartx_configure(const struct device *dev,
568573
return -ENOTSUP;
569574
}
570575

576+
if (dev_cfg->rx_invert) {
577+
flags |= LPC11U6X_UARTX_CFG_RXPOL(1);
578+
}
579+
if (dev_cfg->tx_invert) {
580+
flags |= LPC11U6X_UARTX_CFG_TXPOL(1);
581+
}
582+
571583
/* Disable UART */
572584
dev_cfg->base->cfg = 0;
573585

@@ -786,6 +798,13 @@ static int lpc11u6x_uartx_init(const struct device *dev)
786798
data->data_bits = UART_CFG_DATA_BITS_8;
787799
data->flow_ctrl = UART_CFG_FLOW_CTRL_NONE;
788800

801+
if (cfg->rx_invert) {
802+
cfg->base->cfg |= LPC11U6X_UARTX_CFG_RXPOL(1);
803+
}
804+
if (cfg->tx_invert) {
805+
cfg->base->cfg |= LPC11U6X_UARTX_CFG_TXPOL(1);
806+
}
807+
789808
/* Enable UART */
790809
cfg->base->cfg = (cfg->base->cfg & LPC11U6X_UARTX_CFG_MASK) |
791810
LPC11U6X_UARTX_CFG_ENABLE;
@@ -845,6 +864,8 @@ static const struct lpc11u6x_uartx_config uart_cfg_##idx = { \
845864
.clkid = DT_PHA_BY_IDX(DT_NODELABEL(uart##idx), clocks, 0, clkid), \
846865
.pincfg = PINCTRL_DT_DEV_CONFIG_GET(DT_NODELABEL(uart##idx)), \
847866
.baudrate = DT_PROP(DT_NODELABEL(uart##idx), current_speed), \
867+
.rx_invert = DT_PROP(DT_NODELABEL(uart##idx), rx_invert), \
868+
.tx_invert = DT_PROP(DT_NODELABEL(uart##idx), tx_invert), \
848869
}; \
849870
\
850871
static struct lpc11u6x_uartx_data uart_data_##idx; \

drivers/serial/uart_lpc11u6x.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@
5858
#define LPC11U6X_UARTX_CFG_STOP_1BIT (0x0 << 6)
5959
#define LPC11U6X_UARTX_CFG_STOP_2BIT (0x1 << 6)
6060

61+
#define LPC11U6X_UARTX_CFG_RXPOL(x) (((x) & 0x1) << 22)
62+
#define LPC11U6X_UARTX_CFG_TXPOL(x) (((x) & 0x1) << 23)
63+
6164
#define LPC11U6X_UARTX_CFG_MASK (0x00FCDAFD)
6265

6366
#define LPC11U6X_UARTX_STAT_RXRDY (1 << 0)
@@ -170,6 +173,8 @@ struct lpc11u6x_uartx_config {
170173
const struct device *clock_dev;
171174
uint32_t baudrate;
172175
uint32_t clkid;
176+
bool rx_invert;
177+
bool tx_invert;
173178
const struct pinctrl_dev_config *pincfg;
174179
};
175180

dts/bindings/serial/nxp,lpc11u6x-uart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ description: LPC11U6X UART
22

33
compatible: "nxp,lpc11u6x-uart"
44

5-
include: [uart-controller.yaml, pinctrl-device.yaml]
5+
include: [uart-controller.yaml, uart-controller-pin-inversion.yaml, pinctrl-device.yaml]
66

77
properties:
88
reg:

0 commit comments

Comments
 (0)