Skip to content

Commit

Permalink
lpuart: IMXRT/S32K3XX implement TIOCSSINGLEWIREDUPLEX
Browse files Browse the repository at this point in the history
  • Loading branch information
PetervdPerk-NXP committed May 8, 2024
1 parent ae9f627 commit 1091d86
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
28 changes: 27 additions & 1 deletion arch/arm/src/imxrt/imxrt_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)

if ((arg & SER_SINGLEWIRE_ENABLED) != 0)
{
uint32_t gpio_val = IOMUX_OPENDRAIN;
uint32_t gpio_val = 0;
gpio_val |= (arg & SER_SINGLEWIRE_PULL_MASK) ==
SER_SINGLEWIRE_PULLUP ?
IOMUX_PULL_UP : IOMUX_PULL_NONE;
Expand All @@ -2653,6 +2653,32 @@ static int imxrt_ioctl(struct file *filep, int cmd, unsigned long arg)
spin_unlock_irqrestore(NULL, flags);
}
break;

case TIOCSSINGLEWIREDUPLEX:
{
uint32_t regval;
irqstate_t flags;
struct imxrt_uart_s *priv = (struct imxrt_uart_s *)dev;

flags = spin_lock_irqsave(NULL);
regval = imxrt_serialin(priv, IMXRT_LPUART_CTRL_OFFSET);

if ((arg & SER_SINGLEWIRE_DUPLEX_TX) != 0)
{
regval &= ~(LPUART_CTRL_RSRC);
regval |= (LPUART_CTRL_TXDIR);
}
else /* RX Mode */
{
regval |= LPUART_CTRL_RSRC;
regval &= ~(LPUART_CTRL_TXDIR);
}

imxrt_serialout(priv, IMXRT_LPUART_CTRL_OFFSET, regval);

spin_unlock_irqrestore(NULL, flags);
}
break;
#endif

#ifdef CONFIG_IMXRT_LPUART_INVERT
Expand Down
26 changes: 26 additions & 0 deletions arch/arm/src/s32k3xx/s32k3xx_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -3529,6 +3529,32 @@ static int s32k3xx_ioctl(struct file *filep, int cmd, unsigned long arg)
spin_unlock_irqrestore(NULL, flags);
}
break;

case TIOCSSINGLEWIREDUPLEX:
{
uint32_t regval;
irqstate_t flags;
struct s32k3xx_uart_s *priv = (struct s32k3xx_uart_s *)dev->priv;

flags = spin_lock_irqsave(NULL);
regval = s32k3xx_serialin(priv, S32K3XX_LPUART_CTRL_OFFSET);

if ((arg & SER_SINGLEWIRE_DUPLEX_TX) != 0)
{
regval &= ~(LPUART_CTRL_RSRC);
regval |= (LPUART_CTRL_TXDIR);
}
else /* RX Mode */
{
regval |= LPUART_CTRL_RSRC;
regval &= ~(LPUART_CTRL_TXDIR);
}

s32k3xx_serialout(priv, S32K3XX_LPUART_CTRL_OFFSET, regval);

spin_unlock_irqrestore(NULL, flags);
}
break;
#endif

#ifdef CONFIG_S32K3XX_LPUART_INVERT
Expand Down

0 comments on commit 1091d86

Please sign in to comment.