#include <dm.h>
#include <errno.h>
#include <fdtdec.h>
+#include <log.h>
#include <watchdog.h>
#include <asm/io.h>
+#include <dm/device_compat.h>
+#include <linux/bitops.h>
#include <linux/compiler.h>
#include <serial.h>
+#include <linux/err.h>
#define ZYNQ_UART_SR_TXACTIVE BIT(11) /* TX active */
#define ZYNQ_UART_SR_TXFULL BIT(4) /* TX FIFO full */
u32 baud_rate_divider; /* 0x34 - Baud Rate Divider [7:0] */
};
-struct zynq_uart_priv {
+struct zynq_uart_platdata {
struct uart_zynq *regs;
};
-/* Set up the baud rate in gd struct */
+/* Set up the baud rate */
static void _uart_zynq_serial_setbrg(struct uart_zynq *regs,
unsigned long clock, unsigned long baud)
{
return 0;
}
-int zynq_serial_setbrg(struct udevice *dev, int baudrate)
+static int zynq_serial_setbrg(struct udevice *dev, int baudrate)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
unsigned long clock;
int ret;
return ret;
}
- _uart_zynq_serial_setbrg(priv->regs, clock, baudrate);
+ _uart_zynq_serial_setbrg(platdata->regs, clock, baudrate);
return 0;
}
static int zynq_serial_probe(struct udevice *dev)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
+ struct uart_zynq *regs = platdata->regs;
+ u32 val;
- _uart_zynq_serial_init(priv->regs);
+ /* No need to reinitialize the UART if TX already enabled */
+ val = readl(®s->control);
+ if (val & ZYNQ_UART_CR_TX_EN)
+ return 0;
+
+ _uart_zynq_serial_init(platdata->regs);
return 0;
}
static int zynq_serial_getc(struct udevice *dev)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
- struct uart_zynq *regs = priv->regs;
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
+ struct uart_zynq *regs = platdata->regs;
if (readl(®s->channel_sts) & ZYNQ_UART_SR_RXEMPTY)
return -EAGAIN;
static int zynq_serial_putc(struct udevice *dev, const char ch)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
- return _uart_zynq_serial_putc(priv->regs, ch);
+ return _uart_zynq_serial_putc(platdata->regs, ch);
}
static int zynq_serial_pending(struct udevice *dev, bool input)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
- struct uart_zynq *regs = priv->regs;
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
+ struct uart_zynq *regs = platdata->regs;
if (input)
return !(readl(®s->channel_sts) & ZYNQ_UART_SR_RXEMPTY);
static int zynq_serial_ofdata_to_platdata(struct udevice *dev)
{
- struct zynq_uart_priv *priv = dev_get_priv(dev);
+ struct zynq_uart_platdata *platdata = dev_get_platdata(dev);
- priv->regs = (struct uart_zynq *)dev_read_addr(dev);
- if (IS_ERR(priv->regs))
- return PTR_ERR(priv->regs);
+ platdata->regs = (struct uart_zynq *)dev_read_addr(dev);
+ if (IS_ERR(platdata->regs))
+ return PTR_ERR(platdata->regs);
return 0;
}
.id = UCLASS_SERIAL,
.of_match = zynq_serial_ids,
.ofdata_to_platdata = zynq_serial_ofdata_to_platdata,
- .priv_auto_alloc_size = sizeof(struct zynq_uart_priv),
+ .platdata_auto = sizeof(struct zynq_uart_platdata),
.probe = zynq_serial_probe,
.ops = &zynq_serial_ops,
- .flags = DM_FLAG_PRE_RELOC,
};
#ifdef CONFIG_DEBUG_UART_ZYNQ