2 * (C) Copyright 2016 Stephen Warren <swarren@wwwdotorg.org>
4 * Derived from pl01x code:
7 * Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
11 * Philippe Robin, <philippe.robin@arm.com>
13 * SPDX-License-Identifier: GPL-2.0+
16 /* Simple U-Boot driver for the BCM283x mini UART */
24 #include <dm/platform_data/serial_bcm283x_mu.h>
25 #include <linux/compiler.h>
28 struct bcm283x_mu_regs {
42 #define BCM283X_MU_LCR_DATA_SIZE_8 3
44 #define BCM283X_MU_LSR_TX_IDLE BIT(6)
45 /* This actually means not full, but is named not empty in the docs */
46 #define BCM283X_MU_LSR_TX_EMPTY BIT(5)
47 #define BCM283X_MU_LSR_RX_READY BIT(0)
49 struct bcm283x_mu_priv {
50 struct bcm283x_mu_regs *regs;
53 static int bcm283x_mu_serial_setbrg(struct udevice *dev, int baudrate)
55 struct bcm283x_mu_serial_platdata *plat = dev_get_platdata(dev);
56 struct bcm283x_mu_priv *priv = dev_get_priv(dev);
57 struct bcm283x_mu_regs *regs = priv->regs;
63 divider = plat->clock / (baudrate * 8);
65 writel(BCM283X_MU_LCR_DATA_SIZE_8, ®s->lcr);
66 writel(divider - 1, ®s->baud);
71 static int bcm283x_mu_serial_probe(struct udevice *dev)
73 struct bcm283x_mu_serial_platdata *plat = dev_get_platdata(dev);
74 struct bcm283x_mu_priv *priv = dev_get_priv(dev);
76 priv->regs = (struct bcm283x_mu_regs *)plat->base;
81 static int bcm283x_mu_serial_getc(struct udevice *dev)
83 struct bcm283x_mu_priv *priv = dev_get_priv(dev);
84 struct bcm283x_mu_regs *regs = priv->regs;
87 /* Wait until there is data in the FIFO */
88 if (!(readl(®s->lsr) & BCM283X_MU_LSR_RX_READY))
91 data = readl(®s->io);
96 static int bcm283x_mu_serial_putc(struct udevice *dev, const char data)
98 struct bcm283x_mu_priv *priv = dev_get_priv(dev);
99 struct bcm283x_mu_regs *regs = priv->regs;
101 /* Wait until there is space in the FIFO */
102 if (!(readl(®s->lsr) & BCM283X_MU_LSR_TX_EMPTY))
105 /* Send the character */
106 writel(data, ®s->io);
111 static int bcm283x_mu_serial_pending(struct udevice *dev, bool input)
113 struct bcm283x_mu_priv *priv = dev_get_priv(dev);
114 struct bcm283x_mu_regs *regs = priv->regs;
115 unsigned int lsr = readl(®s->lsr);
119 return (lsr & BCM283X_MU_LSR_RX_READY) ? 1 : 0;
121 return (lsr & BCM283X_MU_LSR_TX_IDLE) ? 0 : 1;
125 static const struct dm_serial_ops bcm283x_mu_serial_ops = {
126 .putc = bcm283x_mu_serial_putc,
127 .pending = bcm283x_mu_serial_pending,
128 .getc = bcm283x_mu_serial_getc,
129 .setbrg = bcm283x_mu_serial_setbrg,
132 U_BOOT_DRIVER(serial_bcm283x_mu) = {
133 .name = "serial_bcm283x_mu",
135 .platdata_auto_alloc_size = sizeof(struct bcm283x_mu_serial_platdata),
136 .probe = bcm283x_mu_serial_probe,
137 .ops = &bcm283x_mu_serial_ops,
138 .flags = DM_FLAG_PRE_RELOC,
139 .priv_auto_alloc_size = sizeof(struct bcm283x_mu_priv),