2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2007-05-13 11:58:00 +00:00
|
|
|
/*
|
|
|
|
* SuperH SCIF device driver.
|
2013-07-23 04:58:20 +00:00
|
|
|
* Copyright (C) 2013 Renesas Electronics Corporation
|
2015-02-12 04:48:04 +00:00
|
|
|
* Copyright (C) 2007,2008,2010, 2014 Nobuhiro Iwamatsu
|
2010-10-25 18:55:15 +00:00
|
|
|
* Copyright (C) 2002 - 2008 Paul Mundt
|
2007-05-13 11:58:00 +00:00
|
|
|
*/
|
|
|
|
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2009-01-11 15:35:16 +00:00
|
|
|
#include <asm/io.h>
|
2007-05-13 11:58:00 +00:00
|
|
|
#include <asm/processor.h>
|
2023-10-16 09:25:35 +00:00
|
|
|
#include <clk.h>
|
|
|
|
#include <dm.h>
|
2023-10-19 14:30:44 +00:00
|
|
|
#include <dm/device_compat.h>
|
2015-02-12 04:48:04 +00:00
|
|
|
#include <dm/platform_data/serial_sh.h>
|
2023-10-16 09:25:35 +00:00
|
|
|
#include <errno.h>
|
|
|
|
#include <linux/compiler.h>
|
2020-05-10 17:40:11 +00:00
|
|
|
#include <linux/delay.h>
|
2023-10-19 14:30:44 +00:00
|
|
|
#include <reset.h>
|
2023-10-16 09:25:35 +00:00
|
|
|
#include <serial.h>
|
2015-02-12 04:48:04 +00:00
|
|
|
#include "serial_sh.h"
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2016-04-18 07:51:04 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2019-05-07 20:31:23 +00:00
|
|
|
#if defined(CONFIG_CPU_SH7780)
|
2010-10-25 18:55:15 +00:00
|
|
|
static int scif_rxfill(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return sci_in(port, SCRFDR) & 0xff;
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_CPU_SH7763)
|
|
|
|
static int scif_rxfill(struct uart_port *port)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
2010-10-25 18:55:15 +00:00
|
|
|
if ((port->mapbase == 0xffe00000) ||
|
2015-02-12 04:48:04 +00:00
|
|
|
(port->mapbase == 0xffe08000)) {
|
2010-10-25 18:55:15 +00:00
|
|
|
/* SCIF0/1*/
|
|
|
|
return sci_in(port, SCRFDR) & 0xff;
|
|
|
|
} else {
|
|
|
|
/* SCIF2 */
|
|
|
|
return sci_in(port, SCFDR) & SCIF2_RFDC_MASK;
|
|
|
|
}
|
|
|
|
}
|
2008-03-06 05:05:53 +00:00
|
|
|
#else
|
2010-10-25 18:55:15 +00:00
|
|
|
static int scif_rxfill(struct uart_port *port)
|
|
|
|
{
|
|
|
|
return sci_in(port, SCFDR) & SCIF_RFDC_MASK;
|
|
|
|
}
|
2008-03-06 05:05:53 +00:00
|
|
|
#endif
|
2010-10-25 18:55:15 +00:00
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static void sh_serial_init_generic(struct uart_port *port)
|
2010-10-25 18:55:15 +00:00
|
|
|
{
|
2015-02-12 04:48:04 +00:00
|
|
|
sci_out(port, SCSCR , SCSCR_INIT(port));
|
|
|
|
sci_out(port, SCSCR , SCSCR_INIT(port));
|
|
|
|
sci_out(port, SCSMR, 0);
|
|
|
|
sci_out(port, SCSMR, 0);
|
|
|
|
sci_out(port, SCFCR, SCFCR_RFRST|SCFCR_TFRST);
|
|
|
|
sci_in(port, SCFCR);
|
|
|
|
sci_out(port, SCFCR, 0);
|
2019-05-01 16:20:00 +00:00
|
|
|
#if defined(CONFIG_RZA1)
|
|
|
|
sci_out(port, SCSPTR, 0x0003);
|
|
|
|
#endif
|
2023-02-28 21:29:19 +00:00
|
|
|
|
2023-10-16 09:25:23 +00:00
|
|
|
#if IS_ENABLED(CONFIG_RCAR_GEN2) || IS_ENABLED(CONFIG_RCAR_GEN3) || IS_ENABLED(CONFIG_RCAR_GEN4)
|
2023-02-28 21:29:19 +00:00
|
|
|
if (port->type == PORT_HSCIF)
|
|
|
|
sci_out(port, HSSRR, HSSRR_SRE | HSSRR_SRCYC8);
|
2023-10-16 09:25:23 +00:00
|
|
|
#endif
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static void
|
|
|
|
sh_serial_setbrg_generic(struct uart_port *port, int clk, int baudrate)
|
2012-11-19 21:37:38 +00:00
|
|
|
{
|
2015-02-12 04:48:04 +00:00
|
|
|
if (port->clk_mode == EXT_CLK) {
|
|
|
|
unsigned short dl = DL_VALUE(baudrate, clk);
|
|
|
|
sci_out(port, DL, dl);
|
2014-12-10 05:42:05 +00:00
|
|
|
/* Need wait: Clock * 1/dl * 1/16 */
|
2015-02-12 04:48:04 +00:00
|
|
|
udelay((1000000 * dl * 16 / clk) * 1000 + 1);
|
|
|
|
} else {
|
|
|
|
sci_out(port, SCBRR, SCBRR_VALUE(baudrate, clk));
|
|
|
|
}
|
2012-11-19 21:37:38 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static void handle_error(struct uart_port *port)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
2023-10-19 14:30:43 +00:00
|
|
|
/*
|
|
|
|
* Most errors are cleared by resetting the relevant error bits to zero
|
|
|
|
* in the FSR & LSR registers. For each register, a read followed by a
|
|
|
|
* write is needed according to the relevant datasheets.
|
|
|
|
*/
|
|
|
|
unsigned short status = sci_in(port, SCxSR);
|
|
|
|
sci_out(port, SCxSR, status & ~SCxSR_ERRORS(port));
|
2015-02-12 04:48:04 +00:00
|
|
|
sci_in(port, SCLSR);
|
|
|
|
sci_out(port, SCLSR, 0x00);
|
2023-10-19 14:30:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* To clear framing errors, we also need to read and discard a
|
|
|
|
* character.
|
|
|
|
*/
|
|
|
|
if ((port->type != PORT_SCI) && (status & SCIF_FER))
|
|
|
|
sci_in(port, SCxRDR);
|
2015-02-12 04:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int serial_raw_putc(struct uart_port *port, const char c)
|
|
|
|
{
|
|
|
|
/* Tx fifo is empty */
|
|
|
|
if (!(sci_in(port, SCxSR) & SCxSR_TEND(port)))
|
|
|
|
return -EAGAIN;
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
sci_out(port, SCxTDR, c);
|
|
|
|
sci_out(port, SCxSR, sci_in(port, SCxSR) & ~SCxSR_TEND(port));
|
|
|
|
|
|
|
|
return 0;
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static int serial_rx_fifo_level(struct uart_port *port)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
2015-02-12 04:48:04 +00:00
|
|
|
return scif_rxfill(port);
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static int sh_serial_tstc_generic(struct uart_port *port)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
2015-02-12 04:48:04 +00:00
|
|
|
if (sci_in(port, SCxSR) & SCIF_ERRORS) {
|
|
|
|
handle_error(port);
|
2012-11-19 21:37:38 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
return serial_rx_fifo_level(port) ? 1 : 0;
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static int serial_getc_check(struct uart_port *port)
|
2008-06-06 07:16:08 +00:00
|
|
|
{
|
2007-05-13 11:58:00 +00:00
|
|
|
unsigned short status;
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
status = sci_in(port, SCxSR);
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2010-10-25 18:55:15 +00:00
|
|
|
if (status & SCIF_ERRORS)
|
2015-02-12 04:48:04 +00:00
|
|
|
handle_error(port);
|
|
|
|
if (sci_in(port, SCLSR) & SCxSR_ORER(port))
|
|
|
|
handle_error(port);
|
2020-05-09 20:30:05 +00:00
|
|
|
status &= (SCIF_DR | SCxSR_RDxF(port));
|
|
|
|
if (status)
|
|
|
|
return status;
|
|
|
|
return scif_rxfill(port);
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
static int sh_serial_getc_generic(struct uart_port *port)
|
2007-05-13 11:58:00 +00:00
|
|
|
{
|
2008-06-06 07:16:08 +00:00
|
|
|
unsigned short status;
|
2007-05-13 11:58:00 +00:00
|
|
|
char ch;
|
2008-08-22 08:48:51 +00:00
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
if (!serial_getc_check(port))
|
|
|
|
return -EAGAIN;
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
ch = sci_in(port, SCxRDR);
|
|
|
|
status = sci_in(port, SCxSR);
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
sci_out(port, SCxSR, SCxSR_RDxF_CLEAR(port));
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2010-10-25 18:55:15 +00:00
|
|
|
if (status & SCIF_ERRORS)
|
2015-02-12 04:48:04 +00:00
|
|
|
handle_error(port);
|
|
|
|
|
|
|
|
if (sci_in(port, SCLSR) & SCxSR_ORER(port))
|
|
|
|
handle_error(port);
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
2018-02-16 00:33:27 +00:00
|
|
|
#if CONFIG_IS_ENABLED(DM_SERIAL)
|
2015-02-12 04:48:04 +00:00
|
|
|
|
|
|
|
static int sh_serial_pending(struct udevice *dev, bool input)
|
|
|
|
{
|
|
|
|
struct uart_port *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return sh_serial_tstc_generic(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_putc(struct udevice *dev, const char ch)
|
|
|
|
{
|
|
|
|
struct uart_port *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return serial_raw_putc(priv, ch);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_getc(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct uart_port *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
return sh_serial_getc_generic(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_setbrg(struct udevice *dev, int baudrate)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct sh_serial_plat *plat = dev_get_plat(dev);
|
2015-02-12 04:48:04 +00:00
|
|
|
struct uart_port *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
sh_serial_setbrg_generic(priv, plat->clk, baudrate);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_probe(struct udevice *dev)
|
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct sh_serial_plat *plat = dev_get_plat(dev);
|
2015-02-12 04:48:04 +00:00
|
|
|
struct uart_port *priv = dev_get_priv(dev);
|
2023-10-19 14:30:44 +00:00
|
|
|
struct reset_ctl rst;
|
|
|
|
int ret;
|
2015-02-12 04:48:04 +00:00
|
|
|
|
|
|
|
priv->membase = (unsigned char *)plat->base;
|
|
|
|
priv->mapbase = plat->base;
|
|
|
|
priv->type = plat->type;
|
|
|
|
priv->clk_mode = plat->clk_mode;
|
|
|
|
|
2023-10-19 14:30:44 +00:00
|
|
|
/* De-assert the module reset if it is defined. */
|
|
|
|
ret = reset_get_by_index(dev, 0, &rst);
|
|
|
|
if (!ret) {
|
|
|
|
ret = reset_deassert(&rst);
|
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(dev, "failed to de-assert reset line\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
sh_serial_init_generic(priv);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_serial_ops sh_serial_ops = {
|
|
|
|
.putc = sh_serial_putc,
|
|
|
|
.pending = sh_serial_pending,
|
|
|
|
.getc = sh_serial_getc,
|
|
|
|
.setbrg = sh_serial_setbrg,
|
|
|
|
};
|
|
|
|
|
2018-02-16 00:33:27 +00:00
|
|
|
#if CONFIG_IS_ENABLED(OF_CONTROL)
|
2016-04-18 07:51:04 +00:00
|
|
|
static const struct udevice_id sh_serial_id[] ={
|
2016-04-18 07:51:05 +00:00
|
|
|
{.compatible = "renesas,sci", .data = PORT_SCI},
|
2016-04-18 07:51:04 +00:00
|
|
|
{.compatible = "renesas,scif", .data = PORT_SCIF},
|
2023-10-19 14:30:44 +00:00
|
|
|
{.compatible = "renesas,scif-r9a07g044", .data = PORT_SCIFA},
|
2016-04-18 07:51:04 +00:00
|
|
|
{.compatible = "renesas,scifa", .data = PORT_SCIFA},
|
2023-02-28 21:29:19 +00:00
|
|
|
{.compatible = "renesas,hscif", .data = PORT_HSCIF},
|
2016-04-18 07:51:04 +00:00
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int sh_serial_of_to_plat(struct udevice *dev)
|
2016-04-18 07:51:04 +00:00
|
|
|
{
|
2020-12-03 23:55:23 +00:00
|
|
|
struct sh_serial_plat *plat = dev_get_plat(dev);
|
2017-07-21 21:19:18 +00:00
|
|
|
struct clk sh_serial_clk;
|
2016-04-18 07:51:04 +00:00
|
|
|
fdt_addr_t addr;
|
2017-07-21 21:19:18 +00:00
|
|
|
int ret;
|
2016-04-18 07:51:04 +00:00
|
|
|
|
2020-07-17 05:36:48 +00:00
|
|
|
addr = dev_read_addr(dev);
|
2018-01-17 21:36:37 +00:00
|
|
|
if (!addr)
|
2016-04-18 07:51:04 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
plat->base = addr;
|
2017-07-21 21:19:18 +00:00
|
|
|
|
|
|
|
ret = clk_get_by_name(dev, "fck", &sh_serial_clk);
|
2017-09-15 19:11:27 +00:00
|
|
|
if (!ret) {
|
|
|
|
ret = clk_enable(&sh_serial_clk);
|
|
|
|
if (!ret)
|
|
|
|
plat->clk = clk_get_rate(&sh_serial_clk);
|
|
|
|
} else {
|
2017-07-21 21:19:18 +00:00
|
|
|
plat->clk = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
|
|
|
|
"clock", 1);
|
2017-09-15 19:11:27 +00:00
|
|
|
}
|
2017-07-21 21:19:18 +00:00
|
|
|
|
2016-04-18 07:51:04 +00:00
|
|
|
plat->type = dev_get_driver_data(dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-02-12 04:48:04 +00:00
|
|
|
U_BOOT_DRIVER(serial_sh) = {
|
|
|
|
.name = "serial_sh",
|
|
|
|
.id = UCLASS_SERIAL,
|
2016-04-18 07:51:04 +00:00
|
|
|
.of_match = of_match_ptr(sh_serial_id),
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = of_match_ptr(sh_serial_of_to_plat),
|
2020-12-03 23:55:23 +00:00
|
|
|
.plat_auto = sizeof(struct sh_serial_plat),
|
2015-02-12 04:48:04 +00:00
|
|
|
.probe = sh_serial_probe,
|
|
|
|
.ops = &sh_serial_ops,
|
2018-10-24 13:36:36 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(OF_CONTROL)
|
2015-02-12 04:48:04 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
2018-10-24 13:36:36 +00:00
|
|
|
#endif
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct uart_port),
|
2015-02-12 04:48:04 +00:00
|
|
|
};
|
2023-02-28 21:17:22 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !CONFIG_IS_ENABLED(DM_SERIAL) || IS_ENABLED(CONFIG_DEBUG_UART_SCIF)
|
2015-02-12 04:48:04 +00:00
|
|
|
|
2023-02-28 21:17:22 +00:00
|
|
|
#if defined(CFG_SCIF_A)
|
|
|
|
#define SCIF_BASE_PORT PORT_SCIFA
|
|
|
|
#elif defined(CFG_SCI)
|
|
|
|
#define SCIF_BASE_PORT PORT_SCI
|
2023-02-28 21:29:19 +00:00
|
|
|
#elif defined(CFG_HSCIF)
|
|
|
|
#define SCIF_BASE_PORT PORT_HSCIF
|
2023-02-28 21:17:22 +00:00
|
|
|
#else
|
|
|
|
#define SCIF_BASE_PORT PORT_SCIF
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void sh_serial_init_nodm(struct uart_port *port)
|
|
|
|
{
|
|
|
|
sh_serial_init_generic(port);
|
|
|
|
serial_setbrg();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_serial_putc_nondm(struct uart_port *port, const char c)
|
|
|
|
{
|
|
|
|
if (c == '\n') {
|
|
|
|
while (1) {
|
|
|
|
if (serial_raw_putc(port, '\r') != -EAGAIN)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (1) {
|
|
|
|
if (serial_raw_putc(port, c) != -EAGAIN)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2015-02-12 04:48:04 +00:00
|
|
|
|
2023-02-28 21:17:22 +00:00
|
|
|
#if !CONFIG_IS_ENABLED(DM_SERIAL)
|
2015-02-12 04:48:04 +00:00
|
|
|
#if defined(CONFIG_CONS_SCIF0)
|
|
|
|
# define SCIF_BASE SCIF0_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF1)
|
|
|
|
# define SCIF_BASE SCIF1_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF2)
|
|
|
|
# define SCIF_BASE SCIF2_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF3)
|
|
|
|
# define SCIF_BASE SCIF3_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF4)
|
|
|
|
# define SCIF_BASE SCIF4_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF5)
|
|
|
|
# define SCIF_BASE SCIF5_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF6)
|
|
|
|
# define SCIF_BASE SCIF6_BASE
|
|
|
|
#elif defined(CONFIG_CONS_SCIF7)
|
|
|
|
# define SCIF_BASE SCIF7_BASE
|
2018-04-12 13:23:46 +00:00
|
|
|
#elif defined(CONFIG_CONS_SCIFA0)
|
|
|
|
# define SCIF_BASE SCIFA0_BASE
|
2015-02-12 04:48:04 +00:00
|
|
|
#else
|
|
|
|
# error "Default SCIF doesn't set....."
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static struct uart_port sh_sci = {
|
|
|
|
.membase = (unsigned char *)SCIF_BASE,
|
|
|
|
.mapbase = SCIF_BASE,
|
|
|
|
.type = SCIF_BASE_PORT,
|
2023-02-28 21:17:21 +00:00
|
|
|
#ifdef CFG_SCIF_USE_EXT_CLK
|
2015-02-12 04:48:04 +00:00
|
|
|
.clk_mode = EXT_CLK,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static void sh_serial_setbrg(void)
|
|
|
|
{
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
struct uart_port *port = &sh_sci;
|
|
|
|
|
|
|
|
sh_serial_setbrg_generic(port, CONFIG_SH_SCIF_CLK_FREQ, gd->baudrate);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_init(void)
|
|
|
|
{
|
2023-02-28 21:17:22 +00:00
|
|
|
sh_serial_init_nodm(&sh_sci);
|
2015-02-12 04:48:04 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sh_serial_putc(const char c)
|
|
|
|
{
|
2023-02-28 21:17:22 +00:00
|
|
|
sh_serial_putc_nondm(&sh_sci, c);
|
2015-02-12 04:48:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_tstc(void)
|
|
|
|
{
|
|
|
|
struct uart_port *port = &sh_sci;
|
|
|
|
|
|
|
|
return sh_serial_tstc_generic(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int sh_serial_getc(void)
|
|
|
|
{
|
|
|
|
struct uart_port *port = &sh_sci;
|
|
|
|
int ch;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ch = sh_serial_getc_generic(port);
|
|
|
|
if (ch != -EAGAIN)
|
|
|
|
break;
|
|
|
|
}
|
2007-05-13 11:58:00 +00:00
|
|
|
|
2008-06-06 07:16:08 +00:00
|
|
|
return ch;
|
2007-05-13 11:58:00 +00:00
|
|
|
}
|
2012-09-14 20:40:08 +00:00
|
|
|
|
|
|
|
static struct serial_device sh_serial_drv = {
|
|
|
|
.name = "sh_serial",
|
|
|
|
.start = sh_serial_init,
|
|
|
|
.stop = NULL,
|
|
|
|
.setbrg = sh_serial_setbrg,
|
|
|
|
.putc = sh_serial_putc,
|
2012-10-06 14:07:02 +00:00
|
|
|
.puts = default_serial_puts,
|
2012-09-14 20:40:08 +00:00
|
|
|
.getc = sh_serial_getc,
|
|
|
|
.tstc = sh_serial_tstc,
|
|
|
|
};
|
|
|
|
|
|
|
|
void sh_serial_initialize(void)
|
|
|
|
{
|
|
|
|
serial_register(&sh_serial_drv);
|
|
|
|
}
|
|
|
|
|
|
|
|
__weak struct serial_device *default_serial_console(void)
|
|
|
|
{
|
|
|
|
return &sh_serial_drv;
|
|
|
|
}
|
2015-02-12 04:48:04 +00:00
|
|
|
#endif /* CONFIG_DM_SERIAL */
|
2023-02-28 21:17:22 +00:00
|
|
|
|
|
|
|
#ifdef CONFIG_DEBUG_UART_SCIF
|
|
|
|
#include <debug_uart.h>
|
|
|
|
|
|
|
|
static struct uart_port debug_uart_sci = {
|
|
|
|
.membase = (unsigned char *)CONFIG_DEBUG_UART_BASE,
|
|
|
|
.mapbase = CONFIG_DEBUG_UART_BASE,
|
|
|
|
.type = SCIF_BASE_PORT,
|
|
|
|
#ifdef CFG_SCIF_USE_EXT_CLK
|
|
|
|
.clk_mode = EXT_CLK,
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
static inline void _debug_uart_init(void)
|
|
|
|
{
|
|
|
|
sh_serial_init_nodm(&debug_uart_sci);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void _debug_uart_putc(int c)
|
|
|
|
{
|
|
|
|
sh_serial_putc_nondm(&debug_uart_sci, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEBUG_UART_FUNCS
|
|
|
|
|
|
|
|
#endif
|