1 // SPDX-License-Identifier: GPL-2.0+
3 * Actions Semi OWL SoCs UART driver
5 * Copyright (C) 2015 Actions Semi Co., Ltd.
6 * Copyright (C) 2018 Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
16 #include <asm/types.h>
17 #include <linux/bitops.h>
20 #define OWL_UART_CTL (0x0000)
21 #define OWL_UART_RXDAT (0x0004)
22 #define OWL_UART_TXDAT (0x0008)
23 #define OWL_UART_STAT (0x000C)
25 /* UART_CTL Register Definitions */
26 #define OWL_UART_CTL_PRS_NONE GENMASK(6, 4)
27 #define OWL_UART_CTL_STPS BIT(2)
28 #define OWL_UART_CTL_DWLS 3
30 /* UART_STAT Register Definitions */
31 #define OWL_UART_STAT_TFES BIT(10) /* TX FIFO Empty Status */
32 #define OWL_UART_STAT_RFFS BIT(9) /* RX FIFO full Status */
33 #define OWL_UART_STAT_TFFU BIT(6) /* TX FIFO full Status */
34 #define OWL_UART_STAT_RFEM BIT(5) /* RX FIFO Empty Status */
36 struct owl_serial_priv {
40 int owl_serial_setbrg(struct udevice *dev, int baudrate)
42 /* Driver supports only fixed baudrate */
46 static int owl_serial_getc(struct udevice *dev)
48 struct owl_serial_priv *priv = dev_get_priv(dev);
50 if (readl(priv->base + OWL_UART_STAT) & OWL_UART_STAT_RFEM)
53 return (int)(readl(priv->base + OWL_UART_RXDAT));
56 static int owl_serial_putc(struct udevice *dev, const char ch)
58 struct owl_serial_priv *priv = dev_get_priv(dev);
60 if (readl(priv->base + OWL_UART_STAT) & OWL_UART_STAT_TFFU)
63 writel(ch, priv->base + OWL_UART_TXDAT);
68 static int owl_serial_pending(struct udevice *dev, bool input)
70 struct owl_serial_priv *priv = dev_get_priv(dev);
71 unsigned int stat = readl(priv->base + OWL_UART_STAT);
74 return !(stat & OWL_UART_STAT_RFEM);
76 return !(stat & OWL_UART_STAT_TFES);
79 static int owl_serial_probe(struct udevice *dev)
81 struct owl_serial_priv *priv = dev_get_priv(dev);
86 /* Set data, parity and stop bits */
87 uart_ctl = readl(priv->base + OWL_UART_CTL);
88 uart_ctl &= ~(OWL_UART_CTL_PRS_NONE);
89 uart_ctl &= ~(OWL_UART_CTL_STPS);
90 uart_ctl |= OWL_UART_CTL_DWLS;
91 writel(uart_ctl, priv->base + OWL_UART_CTL);
93 /* Enable UART clock */
94 ret = clk_get_by_index(dev, 0, &clk);
98 ret = clk_enable(&clk);
105 static int owl_serial_ofdata_to_platdata(struct udevice *dev)
107 struct owl_serial_priv *priv = dev_get_priv(dev);
109 priv->base = dev_read_addr(dev);
110 if (priv->base == FDT_ADDR_T_NONE)
116 static const struct dm_serial_ops owl_serial_ops = {
117 .putc = owl_serial_putc,
118 .pending = owl_serial_pending,
119 .getc = owl_serial_getc,
120 .setbrg = owl_serial_setbrg,
123 static const struct udevice_id owl_serial_ids[] = {
124 { .compatible = "actions,owl-uart" },
128 U_BOOT_DRIVER(serial_owl) = {
129 .name = "serial_owl",
131 .of_match = owl_serial_ids,
132 .ofdata_to_platdata = owl_serial_ofdata_to_platdata,
133 .priv_auto_alloc_size = sizeof(struct owl_serial_priv),
134 .probe = owl_serial_probe,
135 .ops = &owl_serial_ops,