mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 02/12] console: Add functions to get/set baudrate
Date: Tue,  9 Jun 2015 08:21:05 +0200	[thread overview]
Message-ID: <1433830875-31119-3-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1433830875-31119-1-git-send-email-s.hauer@pengutronix.de>

So C code can call a function rather than fiddling with device parameters.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c  | 34 ++++++++++++++++++++++++++++++----
 include/console.h |  2 ++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/common/console.c b/common/console.c
index 53030b5..957f539 100644
--- a/common/console.c
+++ b/common/console.c
@@ -138,29 +138,55 @@ static const char *console_active_get(struct device_d *dev,
 	return cdev->active;
 }
 
-static int console_baudrate_set(struct param_d *param, void *priv)
+int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
 {
-	struct console_device *cdev = priv;
+	int ret;
 	unsigned char c;
 
+	if (!cdev->setbrg)
+		return -ENOSYS;
+
+	if (cdev->baudrate == baudrate)
+		return 0;
+
 	/*
 	 * If the device is already active, change its baudrate.
 	 * The baudrate of an inactive device will be set at activation time.
 	 */
 	if (cdev->f_active) {
 		printf("## Switch baudrate to %d bps and press ENTER ...\n",
-			cdev->baudrate);
+			baudrate);
 		mdelay(50);
-		cdev->setbrg(cdev, cdev->baudrate);
+	}
+
+	ret = cdev->setbrg(cdev, baudrate);
+	if (ret)
+		return ret;
+
+	if (cdev->f_active) {
 		mdelay(50);
 		do {
 			c = getc();
 		} while (c != '\r' && c != '\n');
 	}
 
+	cdev->baudrate = baudrate;
+
 	return 0;
 }
 
+unsigned console_get_baudrate(struct console_device *cdev)
+{
+	return cdev->baudrate;
+}
+
+static int console_baudrate_set(struct param_d *param, void *priv)
+{
+	struct console_device *cdev = priv;
+
+	return console_set_baudrate(cdev, cdev->baudrate);
+}
+
 static void console_init_early(void)
 {
 	kfifo_init(console_input_fifo, console_input_buffer,
diff --git a/include/console.h b/include/console.h
index f7055e6..945bdcb 100644
--- a/include/console.h
+++ b/include/console.h
@@ -78,5 +78,7 @@ struct console_device *console_get_first_active(void);
 
 int console_set_active(struct console_device *cdev, unsigned active);
 unsigned console_get_active(struct console_device *cdev);
+int console_set_baudrate(struct console_device *cdev, unsigned baudrate);
+unsigned console_get_baudrate(struct console_device *cdev);
 
 #endif
-- 
2.1.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2015-06-09  6:21 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-09  6:21 Add functions for (de)activating consoles and for setting baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 01/12] console: Add functions to get/set active state of console Sascha Hauer
2015-06-09  6:21 ` Sascha Hauer [this message]
2015-06-09  6:21 ` [PATCH 03/12] console: Add console_get_by_name Sascha Hauer
2015-06-09  6:21 ` [PATCH 04/12] console: When switching baudrate print console name Sascha Hauer
2015-06-09  6:21 ` [PATCH 05/12] usb: gadget: serial: Use console_set_active to activate console Sascha Hauer
2015-06-09  6:21 ` [PATCH 06/12] loadxy: Use console_get_by_name Sascha Hauer
2015-06-09  6:21 ` [PATCH 07/12] loadxy: use console_get_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 08/12] loadx: ignore -c option Sascha Hauer
2015-06-09  6:21 ` [PATCH 09/12] loadxy: use console_set_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 10/12] loadb: use console_get_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 11/12] loadb: Use console_set_baudrate Sascha Hauer
2015-06-09  6:21 ` [PATCH 12/12] loadb: ignore -c option Sascha Hauer
2015-06-09  7:26 ` Add functions for (de)activating consoles and for setting baudrate Sascha Hauer

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=1433830875-31119-3-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox