2018-11-15 02:08:02 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
|
|
|
/*
|
|
|
|
* MediaTek High-speed UART driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2018 MediaTek Inc.
|
|
|
|
* Author: Weijie Gao <weijie.gao@mediatek.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <clk.h>
|
|
|
|
#include <common.h>
|
|
|
|
#include <div64.h>
|
|
|
|
#include <dm.h>
|
2022-09-09 11:59:31 +00:00
|
|
|
#include <dm/device_compat.h>
|
2018-11-15 02:08:02 +00:00
|
|
|
#include <errno.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2018-11-15 02:08:02 +00:00
|
|
|
#include <serial.h>
|
|
|
|
#include <watchdog.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2018-11-15 02:08:02 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/types.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2023-09-15 00:21:46 +00:00
|
|
|
#include <linux/printk.h>
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
struct mtk_serial_regs {
|
|
|
|
u32 rbr;
|
|
|
|
u32 ier;
|
|
|
|
u32 fcr;
|
|
|
|
u32 lcr;
|
|
|
|
u32 mcr;
|
|
|
|
u32 lsr;
|
|
|
|
u32 msr;
|
|
|
|
u32 spr;
|
|
|
|
u32 mdr1;
|
|
|
|
u32 highspeed;
|
|
|
|
u32 sample_count;
|
|
|
|
u32 sample_point;
|
|
|
|
u32 fracdiv_l;
|
|
|
|
u32 fracdiv_m;
|
|
|
|
u32 escape_en;
|
|
|
|
u32 guard;
|
|
|
|
u32 rx_sel;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define thr rbr
|
|
|
|
#define iir fcr
|
|
|
|
#define dll rbr
|
|
|
|
#define dlm ier
|
|
|
|
|
|
|
|
#define UART_LCR_WLS_8 0x03 /* 8 bit character length */
|
|
|
|
#define UART_LCR_DLAB 0x80 /* Divisor latch access bit */
|
|
|
|
|
|
|
|
#define UART_LSR_DR 0x01 /* Data ready */
|
|
|
|
#define UART_LSR_THRE 0x20 /* Xmit holding register empty */
|
2019-09-25 09:45:17 +00:00
|
|
|
#define UART_LSR_TEMT 0x40 /* Xmitter empty */
|
|
|
|
|
|
|
|
#define UART_MCR_DTR 0x01 /* DTR */
|
|
|
|
#define UART_MCR_RTS 0x02 /* RTS */
|
|
|
|
|
|
|
|
#define UART_FCR_FIFO_EN 0x01 /* Fifo enable */
|
|
|
|
#define UART_FCR_RXSR 0x02 /* Receiver soft reset */
|
|
|
|
#define UART_FCR_TXSR 0x04 /* Transmitter soft reset */
|
|
|
|
|
|
|
|
#define UART_MCRVAL (UART_MCR_DTR | \
|
|
|
|
UART_MCR_RTS)
|
|
|
|
|
|
|
|
/* Clear & enable FIFOs */
|
|
|
|
#define UART_FCRVAL (UART_FCR_FIFO_EN | \
|
|
|
|
UART_FCR_RXSR | \
|
|
|
|
UART_FCR_TXSR)
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
/* the data is correct if the real baud is within 3%. */
|
|
|
|
#define BAUD_ALLOW_MAX(baud) ((baud) + (baud) * 3 / 100)
|
|
|
|
#define BAUD_ALLOW_MIX(baud) ((baud) - (baud) * 3 / 100)
|
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
/* struct mtk_serial_priv - Structure holding all information used by the
|
|
|
|
* driver
|
|
|
|
* @regs: Register base of the serial port
|
|
|
|
* @clk: The baud clock device
|
|
|
|
* @fixed_clk_rate: Fallback fixed baud clock rate if baud clock
|
|
|
|
* device is not specified
|
|
|
|
* @force_highspeed: Force using high-speed mode
|
|
|
|
*/
|
2018-11-15 02:08:02 +00:00
|
|
|
struct mtk_serial_priv {
|
|
|
|
struct mtk_serial_regs __iomem *regs;
|
2022-09-09 11:59:31 +00:00
|
|
|
struct clk clk;
|
|
|
|
u32 fixed_clk_rate;
|
2021-03-05 02:35:39 +00:00
|
|
|
bool force_highspeed;
|
2018-11-15 02:08:02 +00:00
|
|
|
};
|
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
static void _mtk_serial_setbrg(struct mtk_serial_priv *priv, int baud,
|
|
|
|
uint clk_rate)
|
2018-11-15 02:08:02 +00:00
|
|
|
{
|
2021-03-05 02:35:39 +00:00
|
|
|
u32 quot, realbaud, samplecount = 1;
|
2018-11-15 02:08:02 +00:00
|
|
|
|
2021-03-05 02:35:39 +00:00
|
|
|
/* Special case for low baud clock */
|
2022-09-09 11:59:31 +00:00
|
|
|
if (baud <= 115200 && clk_rate == 12000000) {
|
2021-03-05 02:35:39 +00:00
|
|
|
writel(3, &priv->regs->highspeed);
|
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
quot = DIV_ROUND_CLOSEST(clk_rate, 256 * baud);
|
2021-03-05 02:35:39 +00:00
|
|
|
if (quot == 0)
|
|
|
|
quot = 1;
|
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
samplecount = DIV_ROUND_CLOSEST(clk_rate, quot * baud);
|
2021-03-05 02:35:39 +00:00
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
realbaud = clk_rate / samplecount / quot;
|
2021-03-05 02:35:39 +00:00
|
|
|
if (realbaud > BAUD_ALLOW_MAX(baud) ||
|
|
|
|
realbaud < BAUD_ALLOW_MIX(baud)) {
|
|
|
|
pr_info("baud %d can't be handled\n", baud);
|
|
|
|
}
|
|
|
|
|
|
|
|
goto set_baud;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (priv->force_highspeed)
|
|
|
|
goto use_hs3;
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
if (baud <= 115200) {
|
|
|
|
writel(0, &priv->regs->highspeed);
|
2022-09-09 11:59:31 +00:00
|
|
|
quot = DIV_ROUND_CLOSEST(clk_rate, 16 * baud);
|
2018-11-15 02:08:02 +00:00
|
|
|
} else if (baud <= 576000) {
|
|
|
|
writel(2, &priv->regs->highspeed);
|
|
|
|
|
|
|
|
/* Set to next lower baudrate supported */
|
|
|
|
if ((baud == 500000) || (baud == 576000))
|
|
|
|
baud = 460800;
|
2021-03-05 02:35:39 +00:00
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
quot = DIV_ROUND_UP(clk_rate, 4 * baud);
|
2018-11-15 02:08:02 +00:00
|
|
|
} else {
|
2021-03-05 02:35:39 +00:00
|
|
|
use_hs3:
|
2018-11-15 02:08:02 +00:00
|
|
|
writel(3, &priv->regs->highspeed);
|
2021-03-05 02:35:39 +00:00
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
quot = DIV_ROUND_UP(clk_rate, 256 * baud);
|
|
|
|
samplecount = DIV_ROUND_CLOSEST(clk_rate, quot * baud);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 02:35:39 +00:00
|
|
|
set_baud:
|
2018-11-15 02:08:02 +00:00
|
|
|
/* set divisor */
|
|
|
|
writel(UART_LCR_WLS_8 | UART_LCR_DLAB, &priv->regs->lcr);
|
|
|
|
writel(quot & 0xff, &priv->regs->dll);
|
|
|
|
writel((quot >> 8) & 0xff, &priv->regs->dlm);
|
|
|
|
writel(UART_LCR_WLS_8, &priv->regs->lcr);
|
|
|
|
|
2021-03-05 02:35:39 +00:00
|
|
|
/* set highspeed mode sample count & point */
|
|
|
|
writel(samplecount - 1, &priv->regs->sample_count);
|
|
|
|
writel((samplecount - 2) >> 1, &priv->regs->sample_point);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
2019-09-25 09:45:18 +00:00
|
|
|
static int _mtk_serial_putc(struct mtk_serial_priv *priv, const char ch)
|
|
|
|
{
|
|
|
|
if (!(readl(&priv->regs->lsr) & UART_LSR_THRE))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
writel(ch, &priv->regs->thr);
|
|
|
|
|
|
|
|
if (ch == '\n')
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule();
|
2019-09-25 09:45:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _mtk_serial_getc(struct mtk_serial_priv *priv)
|
|
|
|
{
|
|
|
|
if (!(readl(&priv->regs->lsr) & UART_LSR_DR))
|
|
|
|
return -EAGAIN;
|
|
|
|
|
|
|
|
return readl(&priv->regs->rbr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int _mtk_serial_pending(struct mtk_serial_priv *priv, bool input)
|
|
|
|
{
|
|
|
|
if (input)
|
|
|
|
return (readl(&priv->regs->lsr) & UART_LSR_DR) ? 1 : 0;
|
|
|
|
else
|
|
|
|
return (readl(&priv->regs->lsr) & UART_LSR_THRE) ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
2022-12-04 15:14:13 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_SERIAL)
|
2018-11-15 02:08:02 +00:00
|
|
|
static int mtk_serial_setbrg(struct udevice *dev, int baudrate)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
2022-09-09 11:59:31 +00:00
|
|
|
u32 clk_rate;
|
|
|
|
|
|
|
|
clk_rate = clk_get_rate(&priv->clk);
|
|
|
|
if (IS_ERR_VALUE(clk_rate) || clk_rate == 0)
|
|
|
|
clk_rate = priv->fixed_clk_rate;
|
2018-11-15 02:08:02 +00:00
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
_mtk_serial_setbrg(priv, baudrate, clk_rate);
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_serial_putc(struct udevice *dev, const char ch)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-09-25 09:45:18 +00:00
|
|
|
return _mtk_serial_putc(priv, ch);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_serial_getc(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-09-25 09:45:18 +00:00
|
|
|
return _mtk_serial_getc(priv);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_serial_pending(struct udevice *dev, bool input)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
|
|
|
|
2019-09-25 09:45:18 +00:00
|
|
|
return _mtk_serial_pending(priv, input);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int mtk_serial_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* Disable interrupt */
|
|
|
|
writel(0, &priv->regs->ier);
|
|
|
|
|
2019-09-25 09:45:17 +00:00
|
|
|
writel(UART_MCRVAL, &priv->regs->mcr);
|
|
|
|
writel(UART_FCRVAL, &priv->regs->fcr);
|
|
|
|
|
2018-11-15 02:08:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int mtk_serial_of_to_plat(struct udevice *dev)
|
2018-11-15 02:08:02 +00:00
|
|
|
{
|
|
|
|
struct mtk_serial_priv *priv = dev_get_priv(dev);
|
|
|
|
fdt_addr_t addr;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
addr = dev_read_addr(dev);
|
|
|
|
if (addr == FDT_ADDR_T_NONE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
priv->regs = map_physmem(addr, 0, MAP_NOCACHE);
|
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
err = clk_get_by_index(dev, 0, &priv->clk);
|
|
|
|
if (err) {
|
|
|
|
err = dev_read_u32(dev, "clock-frequency", &priv->fixed_clk_rate);
|
|
|
|
if (err) {
|
|
|
|
dev_err(dev, "baud clock not defined\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
err = clk_get_rate(&priv->clk);
|
|
|
|
if (IS_ERR_VALUE(err)) {
|
|
|
|
dev_err(dev, "invalid baud clock\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
2021-03-05 02:35:39 +00:00
|
|
|
priv->force_highspeed = dev_read_bool(dev, "mediatek,force-highspeed");
|
|
|
|
|
2018-11-15 02:08:02 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_serial_ops mtk_serial_ops = {
|
|
|
|
.putc = mtk_serial_putc,
|
|
|
|
.pending = mtk_serial_pending,
|
|
|
|
.getc = mtk_serial_getc,
|
|
|
|
.setbrg = mtk_serial_setbrg,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id mtk_serial_ids[] = {
|
|
|
|
{ .compatible = "mediatek,hsuart" },
|
|
|
|
{ .compatible = "mediatek,mt6577-uart" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(serial_mtk) = {
|
|
|
|
.name = "serial_mtk",
|
|
|
|
.id = UCLASS_SERIAL,
|
|
|
|
.of_match = mtk_serial_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = mtk_serial_of_to_plat,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct mtk_serial_priv),
|
2018-11-15 02:08:02 +00:00
|
|
|
.probe = mtk_serial_probe,
|
|
|
|
.ops = &mtk_serial_ops,
|
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|
2019-09-25 09:45:18 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
|
|
|
#define DECLARE_HSUART_PRIV(port) \
|
|
|
|
static struct mtk_serial_priv mtk_hsuart##port = { \
|
2022-11-16 18:10:28 +00:00
|
|
|
.regs = (struct mtk_serial_regs *)CFG_SYS_NS16550_COM##port, \
|
|
|
|
.fixed_clk_rate = CFG_SYS_NS16550_CLK \
|
2019-09-25 09:45:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define DECLARE_HSUART_FUNCTIONS(port) \
|
|
|
|
static int mtk_serial##port##_init(void) \
|
|
|
|
{ \
|
|
|
|
writel(0, &mtk_hsuart##port.regs->ier); \
|
|
|
|
writel(UART_MCRVAL, &mtk_hsuart##port.regs->mcr); \
|
|
|
|
writel(UART_FCRVAL, &mtk_hsuart##port.regs->fcr); \
|
2022-09-09 11:59:31 +00:00
|
|
|
_mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate, \
|
|
|
|
mtk_hsuart##port.fixed_clk_rate); \
|
2019-09-25 09:45:18 +00:00
|
|
|
return 0 ; \
|
|
|
|
} \
|
|
|
|
static void mtk_serial##port##_setbrg(void) \
|
|
|
|
{ \
|
2022-09-09 11:59:31 +00:00
|
|
|
_mtk_serial_setbrg(&mtk_hsuart##port, gd->baudrate, \
|
|
|
|
mtk_hsuart##port.fixed_clk_rate); \
|
2019-09-25 09:45:18 +00:00
|
|
|
} \
|
|
|
|
static int mtk_serial##port##_getc(void) \
|
|
|
|
{ \
|
|
|
|
int err; \
|
|
|
|
do { \
|
|
|
|
err = _mtk_serial_getc(&mtk_hsuart##port); \
|
|
|
|
if (err == -EAGAIN) \
|
2022-09-02 12:10:46 +00:00
|
|
|
schedule(); \
|
2019-09-25 09:45:18 +00:00
|
|
|
} while (err == -EAGAIN); \
|
|
|
|
return err >= 0 ? err : 0; \
|
|
|
|
} \
|
|
|
|
static int mtk_serial##port##_tstc(void) \
|
|
|
|
{ \
|
|
|
|
return _mtk_serial_pending(&mtk_hsuart##port, true); \
|
|
|
|
} \
|
|
|
|
static void mtk_serial##port##_putc(const char c) \
|
|
|
|
{ \
|
|
|
|
int err; \
|
|
|
|
if (c == '\n') \
|
|
|
|
mtk_serial##port##_putc('\r'); \
|
|
|
|
do { \
|
|
|
|
err = _mtk_serial_putc(&mtk_hsuart##port, c); \
|
|
|
|
} while (err == -EAGAIN); \
|
|
|
|
} \
|
|
|
|
static void mtk_serial##port##_puts(const char *s) \
|
|
|
|
{ \
|
|
|
|
while (*s) { \
|
|
|
|
mtk_serial##port##_putc(*s++); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Serial device descriptor */
|
|
|
|
#define INIT_HSUART_STRUCTURE(port, __name) { \
|
|
|
|
.name = __name, \
|
|
|
|
.start = mtk_serial##port##_init, \
|
|
|
|
.stop = NULL, \
|
|
|
|
.setbrg = mtk_serial##port##_setbrg, \
|
|
|
|
.getc = mtk_serial##port##_getc, \
|
|
|
|
.tstc = mtk_serial##port##_tstc, \
|
|
|
|
.putc = mtk_serial##port##_putc, \
|
|
|
|
.puts = mtk_serial##port##_puts, \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DECLARE_HSUART(port, __name) \
|
|
|
|
DECLARE_HSUART_PRIV(port); \
|
|
|
|
DECLARE_HSUART_FUNCTIONS(port); \
|
|
|
|
struct serial_device mtk_hsuart##port##_device = \
|
|
|
|
INIT_HSUART_STRUCTURE(port, __name);
|
|
|
|
|
|
|
|
#if !defined(CONFIG_CONS_INDEX)
|
|
|
|
#elif (CONFIG_CONS_INDEX < 1) || (CONFIG_CONS_INDEX > 6)
|
|
|
|
#error "Invalid console index value."
|
|
|
|
#endif
|
|
|
|
|
2022-11-16 18:10:28 +00:00
|
|
|
#if CONFIG_CONS_INDEX == 1 && !defined(CFG_SYS_NS16550_COM1)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 1 defined but not configured."
|
2022-11-16 18:10:28 +00:00
|
|
|
#elif CONFIG_CONS_INDEX == 2 && !defined(CFG_SYS_NS16550_COM2)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 2 defined but not configured."
|
2022-11-16 18:10:28 +00:00
|
|
|
#elif CONFIG_CONS_INDEX == 3 && !defined(CFG_SYS_NS16550_COM3)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 3 defined but not configured."
|
2022-11-16 18:10:28 +00:00
|
|
|
#elif CONFIG_CONS_INDEX == 4 && !defined(CFG_SYS_NS16550_COM4)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 4 defined but not configured."
|
2022-11-16 18:10:28 +00:00
|
|
|
#elif CONFIG_CONS_INDEX == 5 && !defined(CFG_SYS_NS16550_COM5)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 5 defined but not configured."
|
2022-11-16 18:10:28 +00:00
|
|
|
#elif CONFIG_CONS_INDEX == 6 && !defined(CFG_SYS_NS16550_COM6)
|
2019-09-25 09:45:18 +00:00
|
|
|
#error "Console port 6 defined but not configured."
|
|
|
|
#endif
|
|
|
|
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM1)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(1, "mtk-hsuart0");
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM2)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(2, "mtk-hsuart1");
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM3)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(3, "mtk-hsuart2");
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM4)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(4, "mtk-hsuart3");
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM5)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(5, "mtk-hsuart4");
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM6)
|
2019-09-25 09:45:18 +00:00
|
|
|
DECLARE_HSUART(6, "mtk-hsuart5");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
__weak struct serial_device *default_serial_console(void)
|
|
|
|
{
|
|
|
|
#if CONFIG_CONS_INDEX == 1
|
|
|
|
return &mtk_hsuart1_device;
|
|
|
|
#elif CONFIG_CONS_INDEX == 2
|
|
|
|
return &mtk_hsuart2_device;
|
|
|
|
#elif CONFIG_CONS_INDEX == 3
|
|
|
|
return &mtk_hsuart3_device;
|
|
|
|
#elif CONFIG_CONS_INDEX == 4
|
|
|
|
return &mtk_hsuart4_device;
|
|
|
|
#elif CONFIG_CONS_INDEX == 5
|
|
|
|
return &mtk_hsuart5_device;
|
|
|
|
#elif CONFIG_CONS_INDEX == 6
|
|
|
|
return &mtk_hsuart6_device;
|
|
|
|
#else
|
|
|
|
#error "Bad CONFIG_CONS_INDEX."
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void mtk_serial_initialize(void)
|
|
|
|
{
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM1)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart1_device);
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM2)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart2_device);
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM3)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart3_device);
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM4)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart4_device);
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM5)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart5_device);
|
|
|
|
#endif
|
2022-11-16 18:10:28 +00:00
|
|
|
#if defined(CFG_SYS_NS16550_COM6)
|
2019-09-25 09:45:18 +00:00
|
|
|
serial_register(&mtk_hsuart6_device);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_UART_MTK
|
|
|
|
|
|
|
|
#include <debug_uart.h>
|
|
|
|
|
|
|
|
static inline void _debug_uart_init(void)
|
|
|
|
{
|
|
|
|
struct mtk_serial_priv priv;
|
|
|
|
|
2023-07-19 09:16:07 +00:00
|
|
|
memset(&priv, 0, sizeof(struct mtk_serial_priv));
|
2022-05-27 20:15:24 +00:00
|
|
|
priv.regs = (void *) CONFIG_VAL(DEBUG_UART_BASE);
|
2022-09-09 11:59:31 +00:00
|
|
|
priv.fixed_clk_rate = CONFIG_DEBUG_UART_CLOCK;
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
writel(0, &priv.regs->ier);
|
2019-09-25 09:45:17 +00:00
|
|
|
writel(UART_MCRVAL, &priv.regs->mcr);
|
|
|
|
writel(UART_FCRVAL, &priv.regs->fcr);
|
2018-11-15 02:08:02 +00:00
|
|
|
|
2022-09-09 11:59:31 +00:00
|
|
|
_mtk_serial_setbrg(&priv, CONFIG_BAUDRATE, priv.fixed_clk_rate);
|
2018-11-15 02:08:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _debug_uart_putc(int ch)
|
|
|
|
{
|
|
|
|
struct mtk_serial_regs __iomem *regs =
|
2022-05-27 20:15:24 +00:00
|
|
|
(void *) CONFIG_VAL(DEBUG_UART_BASE);
|
2018-11-15 02:08:02 +00:00
|
|
|
|
|
|
|
while (!(readl(®s->lsr) & UART_LSR_THRE))
|
|
|
|
;
|
|
|
|
|
|
|
|
writel(ch, ®s->thr);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_UART_FUNCS
|
|
|
|
|
2020-02-03 14:36:15 +00:00
|
|
|
#endif
|