All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v4 4/9] dm: serial: Put common code into separate functions
Date: Wed,  1 Oct 2014 19:57:23 -0600	[thread overview]
Message-ID: <1412215048-565-5-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1412215048-565-1-git-send-email-sjg@chromium.org>

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>
---

Changes in v4: None
Changes in v3: None
Changes in v2: None

 drivers/serial/serial-uclass.c | 32 +++++++++++++++++---------------
 1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 1ac943f..e93c624 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -71,7 +71,7 @@ void serial_initialize(void)
 	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);
 	int err;
@@ -83,6 +83,11 @@ void serial_putc(char ch)
 		serial_putc('\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);
@@ -107,28 +112,32 @@ int serial_tstc(void)
 	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;
 
 	do {
-		err = ops->getc(cur_dev);
+		err = ops->getc(dev);
 	} while (err == -EAGAIN);
 
 	return err >= 0 ? err : 0;
 }
 
+int serial_getc(void)
+{
+	return serial_getc_dev(cur_dev);
+}
+
 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 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)
@@ -140,15 +149,8 @@ void serial_stub_puts(struct stdio_dev *sdev, const char *str)
 int serial_stub_getc(struct stdio_dev *sdev)
 {
 	struct udevice *dev = sdev->priv;
-	struct dm_serial_ops *ops = serial_get_ops(dev);
-
-	int err;
 
-	do {
-		err = ops->getc(dev);
-	} while (err == -EAGAIN);
-
-	return err >= 0 ? err : 0;
+	return serial_getc_dev(dev);
 }
 
 int serial_stub_tstc(struct stdio_dev *sdev)
-- 
2.1.0.rc2.206.gedb03e5

  parent reply	other threads:[~2014-10-02  1:57 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-02  1:57 [U-Boot] [PATCH v4 0/9] dm: imx: Add driver model support for GPIO and serial on cm_fx6 Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 1/9] dm: linker_lists: Add a way to declare multiple objects Simon Glass
2014-10-23  3:05   ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 2/9] dm: core: Allow a list of devices to be declared in one step Simon Glass
2014-10-23  3:05   ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 3/9] initcall: Display error number when an error occurs Simon Glass
2014-10-23  3:05   ` Simon Glass
2014-10-02  1:57 ` Simon Glass [this message]
2014-10-23  3:05   ` [U-Boot] [PATCH v4 4/9] dm: serial: Put common code into separate functions Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 5/9] imx: Add error checking to setup_i2c() Simon Glass
2014-10-23  3:06   ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 6/9] dm: imx: Use gpio_request() to request GPIOs Simon Glass
2014-10-02 14:17   ` [U-Boot] [PATCH 0/2] Split "dm: imx: Use gpio_request() to request GPIOs" Nikita Kiryanov
2014-10-02 14:17     ` [U-Boot] [PATCH 1/2] dm: imx: i2c: Use gpio_request() to request GPIOs Nikita Kiryanov
2014-10-03  6:39       ` Igor Grinberg
2014-10-14  7:25         ` Simon Glass
2014-10-21  9:51           ` Igor Grinberg
2014-10-23  3:06             ` Simon Glass
2014-10-02 14:17     ` [U-Boot] [PATCH 2/2] arm: mx6: cm_fx6: use gpio request Nikita Kiryanov
2014-10-02 19:22       ` Simon Glass
2014-10-03  7:41         ` Igor Grinberg
2014-10-03 14:04           ` Simon Glass
2014-10-05 10:52             ` Igor Grinberg
2014-10-05 18:32               ` Simon Glass
2014-10-06  5:47                 ` Igor Grinberg
2014-10-03  6:45       ` Igor Grinberg
2014-10-23  3:06       ` Simon Glass
2014-10-02 14:18   ` [U-Boot] [PATCH v4 6/9] dm: imx: Use gpio_request() to request GPIOs Nikita Kiryanov
2014-10-02 16:06     ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 7/9] dm: imx: gpio: Support driver model in MXC gpio driver Simon Glass
2014-10-23  3:06   ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 8/9] dm: imx: serial: Support driver model in the MXC serial driver Simon Glass
2014-10-23  3:06   ` Simon Glass
2014-10-02  1:57 ` [U-Boot] [PATCH v4 9/9] dm: imx: Move cm_fx6 to use driver model for serial and GPIO Simon Glass
2014-10-02 14:16   ` Nikita Kiryanov
2014-10-23  3:06   ` Simon Glass
2014-10-02  1:59 ` [U-Boot] [PATCH v4 0/9] dm: imx: Add driver model support for GPIO and serial on cm_fx6 Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1412215048-565-5-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.