mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-28 01:51:33 +00:00
dm: serial: Put common code into separate functions
Avoid duplicating the code which deals with getc() and putc(). It is fairly simple, but may expand later. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
aacc6c5d10
commit
b8893327e9
1 changed files with 17 additions and 15 deletions
|
@ -71,7 +71,7 @@ void serial_initialize(void)
|
||||||
serial_find_console_or_panic();
|
serial_find_console_or_panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_putc(char ch)
|
static void serial_putc_dev(struct udevice *dev, char ch)
|
||||||
{
|
{
|
||||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
||||||
int err;
|
int err;
|
||||||
|
@ -83,6 +83,11 @@ void serial_putc(char ch)
|
||||||
serial_putc('\r');
|
serial_putc('\r');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void serial_putc(char ch)
|
||||||
|
{
|
||||||
|
serial_putc_dev(cur_dev, ch);
|
||||||
|
}
|
||||||
|
|
||||||
void serial_setbrg(void)
|
void serial_setbrg(void)
|
||||||
{
|
{
|
||||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
||||||
|
@ -107,28 +112,32 @@ int serial_tstc(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int serial_getc(void)
|
static int serial_getc_dev(struct udevice *dev)
|
||||||
{
|
{
|
||||||
struct dm_serial_ops *ops = serial_get_ops(cur_dev);
|
struct dm_serial_ops *ops = serial_get_ops(dev);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
err = ops->getc(cur_dev);
|
err = ops->getc(dev);
|
||||||
} while (err == -EAGAIN);
|
} while (err == -EAGAIN);
|
||||||
|
|
||||||
return err >= 0 ? err : 0;
|
return err >= 0 ? err : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int serial_getc(void)
|
||||||
|
{
|
||||||
|
return serial_getc_dev(cur_dev);
|
||||||
|
}
|
||||||
|
|
||||||
void serial_stdio_init(void)
|
void serial_stdio_init(void)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_stub_putc(struct stdio_dev *sdev, const char ch)
|
static void serial_stub_putc(struct stdio_dev *sdev, const char ch)
|
||||||
{
|
{
|
||||||
struct udevice *dev = sdev->priv;
|
struct udevice *dev = sdev->priv;
|
||||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
|
||||||
|
|
||||||
ops->putc(dev, ch);
|
serial_putc_dev(dev, ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
void serial_stub_puts(struct stdio_dev *sdev, const char *str)
|
void serial_stub_puts(struct stdio_dev *sdev, const char *str)
|
||||||
|
@ -140,15 +149,8 @@ void serial_stub_puts(struct stdio_dev *sdev, const char *str)
|
||||||
int serial_stub_getc(struct stdio_dev *sdev)
|
int serial_stub_getc(struct stdio_dev *sdev)
|
||||||
{
|
{
|
||||||
struct udevice *dev = sdev->priv;
|
struct udevice *dev = sdev->priv;
|
||||||
struct dm_serial_ops *ops = serial_get_ops(dev);
|
|
||||||
|
|
||||||
int err;
|
return serial_getc_dev(dev);
|
||||||
|
|
||||||
do {
|
|
||||||
err = ops->getc(dev);
|
|
||||||
} while (err == -EAGAIN);
|
|
||||||
|
|
||||||
return err >= 0 ? err : 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int serial_stub_tstc(struct stdio_dev *sdev)
|
int serial_stub_tstc(struct stdio_dev *sdev)
|
||||||
|
|
Loading…
Add table
Reference in a new issue