2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2004-03-14 15:06:13 +00:00
|
|
|
/*
|
|
|
|
* (C) Copyright 2000
|
|
|
|
* Rob Taylor, Flying Pig Systems. robt@flyingpig.com.
|
|
|
|
*
|
|
|
|
* (C) Copyright 2004
|
|
|
|
* ARM Ltd.
|
|
|
|
* Philippe Robin, <philippe.robin@arm.com>
|
|
|
|
*/
|
|
|
|
|
2008-09-08 12:30:53 +00:00
|
|
|
/* Simple U-Boot driver for the PrimeCell PL010/PL011 UARTs */
|
2004-03-14 15:06:13 +00:00
|
|
|
|
|
|
|
#include <common.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-04-27 18:17:59 +00:00
|
|
|
/* For get_bus_freq() */
|
|
|
|
#include <clock_legacy.h>
|
2014-09-22 23:30:58 +00:00
|
|
|
#include <dm.h>
|
2020-04-27 18:17:59 +00:00
|
|
|
#include <clk.h>
|
2014-09-22 23:30:57 +00:00
|
|
|
#include <errno.h>
|
2008-06-02 20:42:19 +00:00
|
|
|
#include <watchdog.h>
|
2010-10-07 21:48:46 +00:00
|
|
|
#include <asm/io.h>
|
2012-09-14 20:38:46 +00:00
|
|
|
#include <serial.h>
|
2020-10-13 13:00:24 +00:00
|
|
|
#include <dm/device_compat.h>
|
2014-10-24 03:41:19 +00:00
|
|
|
#include <dm/platform_data/serial_pl01x.h>
|
2012-09-14 20:38:46 +00:00
|
|
|
#include <linux/compiler.h>
|
2014-09-22 23:30:57 +00:00
|
|
|
#include "serial_pl01x_internal.h"
|
2015-05-06 18:46:29 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
2004-03-14 15:06:13 +00:00
|
|
|
|
2022-12-04 15:14:13 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_SERIAL)
|
2022-12-04 15:13:31 +00:00
|
|
|
static volatile unsigned char *const port[] = CFG_PL01x_PORTS;
|
2021-05-20 11:23:52 +00:00
|
|
|
static enum pl01x_type pl01x_type __section(".data");
|
|
|
|
static struct pl01x_regs *base_regs __section(".data");
|
2004-08-02 23:22:59 +00:00
|
|
|
#define NUM_PORTS (sizeof(port)/sizeof(port[0]))
|
2004-03-14 15:06:13 +00:00
|
|
|
|
2014-09-22 23:30:58 +00:00
|
|
|
#endif
|
2004-03-14 15:06:13 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_putc(struct pl01x_regs *regs, char c)
|
2010-05-05 03:53:07 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Wait until there is space in the FIFO */
|
|
|
|
if (readl(®s->fr) & UART_PL01x_FR_TXFF)
|
|
|
|
return -EAGAIN;
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Send the character */
|
|
|
|
writel(c, ®s->dr);
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_getc(struct pl01x_regs *regs)
|
|
|
|
{
|
|
|
|
unsigned int data;
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Wait until there is data in the FIFO */
|
|
|
|
if (readl(®s->fr) & UART_PL01x_FR_RXFE)
|
|
|
|
return -EAGAIN;
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
data = readl(®s->dr);
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Check for an error flag */
|
|
|
|
if (data & 0xFFFFFF00) {
|
|
|
|
/* Clear the error */
|
|
|
|
writel(0xFFFFFFFF, ®s->ecr);
|
|
|
|
return -1;
|
2004-03-14 22:25:36 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
return (int) data;
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_tstc(struct pl01x_regs *regs)
|
|
|
|
{
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2014-09-22 23:30:57 +00:00
|
|
|
return !(readl(®s->fr) & UART_PL01x_FR_RXFE);
|
|
|
|
}
|
2008-09-08 08:17:31 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_generic_serial_init(struct pl01x_regs *regs,
|
|
|
|
enum pl01x_type type)
|
2008-09-08 08:17:31 +00:00
|
|
|
{
|
2014-11-21 18:34:23 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_PL010:
|
|
|
|
/* disable everything */
|
|
|
|
writel(0, ®s->pl010_cr);
|
|
|
|
break;
|
|
|
|
case TYPE_PL011:
|
2014-11-21 18:34:22 +00:00
|
|
|
/* disable everything */
|
|
|
|
writel(0, ®s->pl011_cr);
|
2014-11-21 18:34:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 13:10:06 +00:00
|
|
|
static int pl011_set_line_control(struct pl01x_regs *regs)
|
2014-11-21 18:34:21 +00:00
|
|
|
{
|
|
|
|
unsigned int lcr;
|
|
|
|
/*
|
|
|
|
* Internal update of baud rate register require line
|
|
|
|
* control register write
|
|
|
|
*/
|
|
|
|
lcr = UART_PL011_LCRH_WLEN_8 | UART_PL011_LCRH_FEN;
|
|
|
|
writel(lcr, ®s->pl011_lcrh);
|
2008-09-08 08:17:31 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_generic_setbrg(struct pl01x_regs *regs, enum pl01x_type type,
|
|
|
|
int clock, int baudrate)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
switch (type) {
|
|
|
|
case TYPE_PL010: {
|
|
|
|
unsigned int divisor;
|
|
|
|
|
2015-04-21 13:10:06 +00:00
|
|
|
/* disable everything */
|
|
|
|
writel(0, ®s->pl010_cr);
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
switch (baudrate) {
|
|
|
|
case 9600:
|
|
|
|
divisor = UART_PL010_BAUD_9600;
|
|
|
|
break;
|
|
|
|
case 19200:
|
2017-04-07 16:48:22 +00:00
|
|
|
divisor = UART_PL010_BAUD_19200;
|
2014-09-22 23:30:57 +00:00
|
|
|
break;
|
|
|
|
case 38400:
|
|
|
|
divisor = UART_PL010_BAUD_38400;
|
|
|
|
break;
|
|
|
|
case 57600:
|
|
|
|
divisor = UART_PL010_BAUD_57600;
|
|
|
|
break;
|
|
|
|
case 115200:
|
|
|
|
divisor = UART_PL010_BAUD_115200;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
divisor = UART_PL010_BAUD_38400;
|
|
|
|
}
|
|
|
|
|
|
|
|
writel((divisor & 0xf00) >> 8, ®s->pl010_lcrm);
|
|
|
|
writel(divisor & 0xff, ®s->pl010_lcrl);
|
|
|
|
|
2015-04-21 13:10:06 +00:00
|
|
|
/*
|
|
|
|
* Set line control for the PL010 to be 8 bits, 1 stop bit,
|
|
|
|
* no parity, fifo enabled
|
|
|
|
*/
|
|
|
|
writel(UART_PL010_LCRH_WLEN_8 | UART_PL010_LCRH_FEN,
|
|
|
|
®s->pl010_lcrh);
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Finally, enable the UART */
|
|
|
|
writel(UART_PL010_CR_UARTEN, ®s->pl010_cr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TYPE_PL011: {
|
|
|
|
unsigned int temp;
|
|
|
|
unsigned int divider;
|
|
|
|
unsigned int remainder;
|
|
|
|
unsigned int fraction;
|
2004-03-14 15:06:13 +00:00
|
|
|
|
2020-04-27 18:17:59 +00:00
|
|
|
/* Without a valid clock rate we cannot set up the baudrate. */
|
|
|
|
if (clock) {
|
|
|
|
/*
|
|
|
|
* Set baud rate
|
|
|
|
*
|
|
|
|
* IBRD = UART_CLK / (16 * BAUD_RATE)
|
|
|
|
* FBRD = RND((64 * MOD(UART_CLK,(16 * BAUD_RATE)))
|
|
|
|
* / (16 * BAUD_RATE))
|
|
|
|
*/
|
|
|
|
temp = 16 * baudrate;
|
|
|
|
divider = clock / temp;
|
|
|
|
remainder = clock % temp;
|
|
|
|
temp = (8 * remainder) / baudrate;
|
|
|
|
fraction = (temp >> 1) + (temp & 1);
|
|
|
|
|
|
|
|
writel(divider, ®s->pl011_ibrd);
|
|
|
|
writel(fraction, ®s->pl011_fbrd);
|
|
|
|
}
|
2014-09-22 23:30:57 +00:00
|
|
|
|
2015-04-21 13:10:06 +00:00
|
|
|
pl011_set_line_control(regs);
|
2014-09-22 23:30:57 +00:00
|
|
|
/* Finally, enable the UART */
|
|
|
|
writel(UART_PL011_CR_UARTEN | UART_PL011_CR_TXE |
|
|
|
|
UART_PL011_CR_RXE | UART_PL011_CR_RTS, ®s->pl011_cr);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2004-03-14 15:06:13 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
return 0;
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2022-12-04 15:14:13 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_SERIAL)
|
2014-09-22 23:30:57 +00:00
|
|
|
static void pl01x_serial_init_baud(int baudrate)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
int clock = 0;
|
|
|
|
|
2021-05-22 12:47:08 +00:00
|
|
|
#if defined(CONFIG_PL011_SERIAL)
|
2014-09-22 23:30:57 +00:00
|
|
|
pl01x_type = TYPE_PL011;
|
2022-12-04 15:13:30 +00:00
|
|
|
clock = CFG_PL011_CLOCK;
|
2014-09-22 23:30:57 +00:00
|
|
|
#endif
|
|
|
|
base_regs = (struct pl01x_regs *)port[CONFIG_CONS_INDEX];
|
|
|
|
|
|
|
|
pl01x_generic_serial_init(base_regs, pl01x_type);
|
2014-11-21 18:34:19 +00:00
|
|
|
pl01x_generic_setbrg(base_regs, pl01x_type, clock, baudrate);
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
/*
|
|
|
|
* Integrator AP has two UARTs, we use the first one, at 38400-8-N-1
|
|
|
|
* Integrator CP has two UARTs, use the first one, at 38400-8-N-1
|
|
|
|
* Versatile PB has four UARTs.
|
|
|
|
*/
|
|
|
|
int pl01x_serial_init(void)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
pl01x_serial_init_baud(CONFIG_BAUDRATE);
|
2011-10-02 11:52:52 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
return 0;
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static void pl01x_serial_putc(const char c)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
if (c == '\n')
|
|
|
|
while (pl01x_putc(base_regs, '\r') == -EAGAIN);
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
while (pl01x_putc(base_regs, c) == -EAGAIN);
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_serial_getc(void)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
while (1) {
|
|
|
|
int ch = pl01x_getc(base_regs);
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
if (ch == -EAGAIN) {
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2014-09-22 23:30:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2004-03-14 22:25:36 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
return ch;
|
2004-03-14 22:25:36 +00:00
|
|
|
}
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static int pl01x_serial_tstc(void)
|
2004-03-14 15:06:13 +00:00
|
|
|
{
|
2014-09-22 23:30:57 +00:00
|
|
|
return pl01x_tstc(base_regs);
|
|
|
|
}
|
2010-05-05 03:53:07 +00:00
|
|
|
|
2014-09-22 23:30:57 +00:00
|
|
|
static void pl01x_serial_setbrg(void)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Flush FIFO and wait for non-busy before changing baudrate to avoid
|
|
|
|
* crap in console
|
|
|
|
*/
|
|
|
|
while (!(readl(&base_regs->fr) & UART_PL01x_FR_TXFE))
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2014-09-22 23:30:57 +00:00
|
|
|
while (readl(&base_regs->fr) & UART_PL01x_FR_BUSY)
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2014-09-22 23:30:57 +00:00
|
|
|
pl01x_serial_init_baud(gd->baudrate);
|
2004-03-14 15:06:13 +00:00
|
|
|
}
|
2012-09-14 20:38:46 +00:00
|
|
|
|
|
|
|
static struct serial_device pl01x_serial_drv = {
|
|
|
|
.name = "pl01x_serial",
|
|
|
|
.start = pl01x_serial_init,
|
|
|
|
.stop = NULL,
|
|
|
|
.setbrg = pl01x_serial_setbrg,
|
|
|
|
.putc = pl01x_serial_putc,
|
2012-10-06 14:07:02 +00:00
|
|
|
.puts = default_serial_puts,
|
2012-09-14 20:38:46 +00:00
|
|
|
.getc = pl01x_serial_getc,
|
|
|
|
.tstc = pl01x_serial_tstc,
|
|
|
|
};
|
|
|
|
|
|
|
|
void pl01x_serial_initialize(void)
|
|
|
|
{
|
|
|
|
serial_register(&pl01x_serial_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak struct serial_device *default_serial_console(void)
|
|
|
|
{
|
|
|
|
return &pl01x_serial_drv;
|
|
|
|
}
|
2022-12-04 15:14:13 +00:00
|
|
|
#else
|
2018-03-07 21:08:25 +00:00
|
|
|
int pl01x_serial_setbrg(struct udevice *dev, int baudrate)
|
2014-09-22 23:30:58 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl01x_serial_plat *plat = dev_get_plat(dev);
|
2014-09-22 23:30:58 +00:00
|
|
|
struct pl01x_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2016-03-14 01:16:54 +00:00
|
|
|
if (!plat->skip_init) {
|
|
|
|
pl01x_generic_setbrg(priv->regs, priv->type, plat->clock,
|
|
|
|
baudrate);
|
|
|
|
}
|
2014-09-22 23:30:58 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-01-25 11:05:55 +00:00
|
|
|
int pl01x_serial_probe(struct udevice *dev)
|
2014-09-22 23:30:58 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl01x_serial_plat *plat = dev_get_plat(dev);
|
2014-09-22 23:30:58 +00:00
|
|
|
struct pl01x_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2023-05-19 10:43:52 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_PLATDATA)
|
|
|
|
struct dtd_serial_pl01x *dtplat = &plat->dtplat;
|
|
|
|
|
|
|
|
priv->regs = (struct pl01x_regs *)dtplat->reg[0];
|
|
|
|
plat->type = dtplat->type;
|
|
|
|
#else
|
2014-09-22 23:30:58 +00:00
|
|
|
priv->regs = (struct pl01x_regs *)plat->base;
|
2023-05-19 10:43:52 +00:00
|
|
|
#endif
|
2014-09-22 23:30:58 +00:00
|
|
|
priv->type = plat->type;
|
2023-05-19 10:43:52 +00:00
|
|
|
|
2016-03-14 01:16:54 +00:00
|
|
|
if (!plat->skip_init)
|
|
|
|
return pl01x_generic_serial_init(priv->regs, priv->type);
|
|
|
|
else
|
|
|
|
return 0;
|
2014-09-22 23:30:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 21:08:25 +00:00
|
|
|
int pl01x_serial_getc(struct udevice *dev)
|
2014-09-22 23:30:58 +00:00
|
|
|
{
|
|
|
|
struct pl01x_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return pl01x_getc(priv->regs);
|
|
|
|
}
|
|
|
|
|
2018-03-07 21:08:25 +00:00
|
|
|
int pl01x_serial_putc(struct udevice *dev, const char ch)
|
2014-09-22 23:30:58 +00:00
|
|
|
{
|
|
|
|
struct pl01x_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return pl01x_putc(priv->regs, ch);
|
|
|
|
}
|
|
|
|
|
2018-03-07 21:08:25 +00:00
|
|
|
int pl01x_serial_pending(struct udevice *dev, bool input)
|
2014-09-22 23:30:58 +00:00
|
|
|
{
|
|
|
|
struct pl01x_priv *priv = dev_get_priv(dev);
|
|
|
|
unsigned int fr = readl(&priv->regs->fr);
|
|
|
|
|
|
|
|
if (input)
|
|
|
|
return pl01x_tstc(priv->regs);
|
|
|
|
else
|
2023-05-19 10:43:53 +00:00
|
|
|
return fr & UART_PL01x_FR_TXFE ? 0 : 1;
|
2014-09-22 23:30:58 +00:00
|
|
|
}
|
|
|
|
|
2018-03-07 21:08:25 +00:00
|
|
|
static const struct dm_serial_ops pl01x_serial_ops = {
|
2014-09-22 23:30:58 +00:00
|
|
|
.putc = pl01x_serial_putc,
|
|
|
|
.pending = pl01x_serial_pending,
|
|
|
|
.getc = pl01x_serial_getc,
|
|
|
|
.setbrg = pl01x_serial_setbrg,
|
|
|
|
};
|
|
|
|
|
2023-05-19 10:43:51 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_REAL)
|
2015-05-06 18:46:29 +00:00
|
|
|
static const struct udevice_id pl01x_serial_id[] ={
|
|
|
|
{.compatible = "arm,pl011", .data = TYPE_PL011},
|
|
|
|
{.compatible = "arm,pl010", .data = TYPE_PL010},
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2022-12-04 15:13:30 +00:00
|
|
|
#ifndef CFG_PL011_CLOCK
|
|
|
|
#define CFG_PL011_CLOCK 0
|
2020-04-27 18:17:59 +00:00
|
|
|
#endif
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
int pl01x_serial_of_to_plat(struct udevice *dev)
|
2015-05-06 18:46:29 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct pl01x_serial_plat *plat = dev_get_plat(dev);
|
2020-04-27 18:17:59 +00:00
|
|
|
struct clk clk;
|
2015-05-06 18:46:29 +00:00
|
|
|
fdt_addr_t addr;
|
2020-04-27 18:17:59 +00:00
|
|
|
int ret;
|
2015-05-06 18:46:29 +00:00
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
addr = dev_read_addr(dev);
|
2015-05-06 18:46:29 +00:00
|
|
|
if (addr == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
plat->base = addr;
|
2022-12-04 15:13:30 +00:00
|
|
|
plat->clock = dev_read_u32_default(dev, "clock", CFG_PL011_CLOCK);
|
2020-04-27 18:17:59 +00:00
|
|
|
ret = clk_get_by_index(dev, 0, &clk);
|
|
|
|
if (!ret) {
|
2020-10-13 13:00:24 +00:00
|
|
|
ret = clk_enable(&clk);
|
|
|
|
if (ret && ret != -ENOSYS) {
|
|
|
|
dev_err(dev, "failed to enable clock\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-27 18:17:59 +00:00
|
|
|
plat->clock = clk_get_rate(&clk);
|
2020-10-13 13:00:24 +00:00
|
|
|
if (IS_ERR_VALUE(plat->clock)) {
|
|
|
|
dev_err(dev, "failed to get rate\n");
|
|
|
|
return plat->clock;
|
|
|
|
}
|
|
|
|
debug("%s: CLK %d\n", __func__, plat->clock);
|
2020-04-27 18:17:59 +00:00
|
|
|
}
|
2015-05-06 18:46:29 +00:00
|
|
|
plat->type = dev_get_driver_data(dev);
|
2018-01-25 11:05:49 +00:00
|
|
|
plat->skip_init = dev_read_bool(dev, "skip-init");
|
|
|
|
|
2015-05-06 18:46:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-09-22 23:30:58 +00:00
|
|
|
U_BOOT_DRIVER(serial_pl01x) = {
|
|
|
|
.name = "serial_pl01x",
|
|
|
|
.id = UCLASS_SERIAL,
|
2023-05-19 10:43:52 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_REAL)
|
2015-05-06 18:46:29 +00:00
|
|
|
.of_match = of_match_ptr(pl01x_serial_id),
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = of_match_ptr(pl01x_serial_of_to_plat),
|
2023-05-19 10:43:52 +00:00
|
|
|
#endif
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct pl01x_serial_plat),
|
2014-09-22 23:30:58 +00:00
|
|
|
.probe = pl01x_serial_probe,
|
|
|
|
.ops = &pl01x_serial_ops,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct pl01x_priv),
|
2014-09-22 23:30:58 +00:00
|
|
|
};
|
|
|
|
|
2023-05-19 10:43:52 +00:00
|
|
|
DM_DRIVER_ALIAS(serial_pl01x, arm_pl011)
|
|
|
|
DM_DRIVER_ALIAS(serial_pl01x, arm_pl010)
|
2014-09-22 23:30:58 +00:00
|
|
|
#endif
|
2015-10-14 16:54:23 +00:00
|
|
|
|
|
|
|
#if defined(CONFIG_DEBUG_UART_PL010) || defined(CONFIG_DEBUG_UART_PL011)
|
|
|
|
|
|
|
|
#include <debug_uart.h>
|
|
|
|
|
|
|
|
static void _debug_uart_init(void)
|
|
|
|
{
|
|
|
|
#ifndef CONFIG_DEBUG_UART_SKIP_INIT
|
2022-05-27 20:15:24 +00:00
|
|
|
struct pl01x_regs *regs = (struct pl01x_regs *)CONFIG_VAL(DEBUG_UART_BASE);
|
2021-07-21 06:11:26 +00:00
|
|
|
enum pl01x_type type;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_DEBUG_UART_PL011))
|
|
|
|
type = TYPE_PL011;
|
|
|
|
else
|
|
|
|
type = TYPE_PL010;
|
2015-10-14 16:54:23 +00:00
|
|
|
|
|
|
|
pl01x_generic_serial_init(regs, type);
|
|
|
|
pl01x_generic_setbrg(regs, type,
|
|
|
|
CONFIG_DEBUG_UART_CLOCK, CONFIG_BAUDRATE);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _debug_uart_putc(int ch)
|
|
|
|
{
|
2022-05-27 20:15:24 +00:00
|
|
|
struct pl01x_regs *regs = (struct pl01x_regs *)CONFIG_VAL(DEBUG_UART_BASE);
|
2015-10-14 16:54:23 +00:00
|
|
|
|
2021-07-19 07:36:04 +00:00
|
|
|
while (pl01x_putc(regs, ch) == -EAGAIN)
|
|
|
|
;
|
2015-10-14 16:54:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_UART_FUNCS
|
|
|
|
|
|
|
|
#endif
|