mirror of
https://github.com/AsahiLinux/u-boot
synced 2024-11-28 15:41:40 +00:00
dm: serial: consolidate common code more
Commit b8893327e9
(dm: serial: Put common code into separate functions)
consolidated getc() and putc(). This commit does more puts() and tsts().
Also rename locally used functions to _serial_*() for clarification
because we have similar functions names here are there in this file.
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
52a0a6f0dc
commit
eea5a4cc1b
1 changed files with 43 additions and 40 deletions
|
@ -83,7 +83,7 @@ void serial_initialize(void)
|
|||
serial_find_console_or_panic();
|
||||
}
|
||||
|
||||
static void serial_putc_dev(struct udevice *dev, char ch)
|
||||
static void _serial_putc(struct udevice *dev, char ch)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
||||
int err;
|
||||
|
@ -92,39 +92,16 @@ static void serial_putc_dev(struct udevice *dev, char ch)
|
|||
err = ops->putc(dev, ch);
|
||||
} while (err == -EAGAIN);
|
||||
if (ch == '\n')
|
||||
serial_putc_dev(dev, '\r');
|
||||
_serial_putc(dev, '\r');
|
||||
}
|
||||
|
||||
void serial_putc(char ch)
|
||||
{
|
||||
serial_putc_dev(cur_dev, ch);
|
||||
}
|
||||
|
||||
void serial_setbrg(void)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
||||
|
||||
if (ops->setbrg)
|
||||
ops->setbrg(cur_dev, gd->baudrate);
|
||||
}
|
||||
|
||||
void serial_puts(const char *str)
|
||||
static void _serial_puts(struct udevice *dev, const char *str)
|
||||
{
|
||||
while (*str)
|
||||
serial_putc(*str++);
|
||||
_serial_putc(dev, *str++);
|
||||
}
|
||||
|
||||
int serial_tstc(void)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
||||
|
||||
if (ops->pending)
|
||||
return ops->pending(cur_dev, true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int serial_getc_dev(struct udevice *dev)
|
||||
static int _serial_getc(struct udevice *dev)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
||||
int err;
|
||||
|
@ -138,9 +115,42 @@ static int serial_getc_dev(struct udevice *dev)
|
|||
return err >= 0 ? err : 0;
|
||||
}
|
||||
|
||||
static int _serial_tstc(struct udevice *dev)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
||||
|
||||
if (ops->pending)
|
||||
return ops->pending(dev, true);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void serial_putc(char ch)
|
||||
{
|
||||
_serial_putc(cur_dev, ch);
|
||||
}
|
||||
|
||||
void serial_puts(const char *str)
|
||||
{
|
||||
_serial_puts(cur_dev, str);
|
||||
}
|
||||
|
||||
int serial_getc(void)
|
||||
{
|
||||
return serial_getc_dev(cur_dev);
|
||||
return _serial_getc(cur_dev);
|
||||
}
|
||||
|
||||
int serial_tstc(void)
|
||||
{
|
||||
return _serial_tstc(cur_dev);
|
||||
}
|
||||
|
||||
void serial_setbrg(void)
|
||||
{
|
||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
||||
|
||||
if (ops->setbrg)
|
||||
ops->setbrg(cur_dev, gd->baudrate);
|
||||
}
|
||||
|
||||
void serial_stdio_init(void)
|
||||
|
@ -149,29 +159,22 @@ void serial_stdio_init(void)
|
|||
|
||||
static void serial_stub_putc(struct stdio_dev *sdev, const char ch)
|
||||
{
|
||||
serial_putc_dev(sdev->priv, ch);
|
||||
_serial_putc(sdev->priv, ch);
|
||||
}
|
||||
|
||||
void serial_stub_puts(struct stdio_dev *sdev, const char *str)
|
||||
{
|
||||
while (*str)
|
||||
serial_stub_putc(sdev, *str++);
|
||||
_serial_puts(sdev->priv, str);
|
||||
}
|
||||
|
||||
int serial_stub_getc(struct stdio_dev *sdev)
|
||||
{
|
||||
return serial_getc_dev(sdev->priv);
|
||||
return _serial_getc(sdev->priv);
|
||||
}
|
||||
|
||||
int serial_stub_tstc(struct stdio_dev *sdev)
|
||||
{
|
||||
struct udevice *dev = sdev->priv;
|
||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
||||
|
||||
if (ops->pending)
|
||||
return ops->pending(dev, true);
|
||||
|
||||
return 1;
|
||||
return _serial_tstc(sdev->priv);
|
||||
}
|
||||
|
||||
static int serial_post_probe(struct udevice *dev)
|
||||
|
|
Loading…
Reference in a new issue