summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-06-08 11:16:46 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-06-09 09:22:13 +0200
commit56b2fe72e856fe210ba1cdb5c154244a6d2d96ab (patch)
treec12261281856e12f393765d800ff82c4d2e1b9f3 /common/console.c
parent4cfc09da3865df1f0f8ea48d34073a8135011d04 (diff)
downloadbarebox-56b2fe72e856fe210ba1cdb5c154244a6d2d96ab.tar.gz
console: Add functions to get/set baudrate
So C code can call a function rather than fiddling with device parameters. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c37
1 files changed, 32 insertions, 5 deletions
diff --git a/common/console.c b/common/console.c
index 53030b5..7e3be8c 100644
--- a/common/console.c
+++ b/common/console.c
@@ -138,29 +138,56 @@ 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;
+ cdev->baudrate_param = 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_param);
+}
+
static void console_init_early(void)
{
kfifo_init(console_input_fifo, console_input_buffer,
@@ -230,7 +257,7 @@ int console_register(struct console_device *newcdev)
if (newcdev->setbrg) {
newcdev->baudrate = CONFIG_BAUDRATE;
dev_add_param_int(dev, "baudrate", console_baudrate_set,
- NULL, &newcdev->baudrate, "%u", newcdev);
+ NULL, &newcdev->baudrate_param, "%u", newcdev);
}
if (newcdev->putc && !newcdev->puts)