summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-06-08 11:05:30 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-06-09 08:12:33 +0200
commit4cfc09da3865df1f0f8ea48d34073a8135011d04 (patch)
treeb17d2cf3df5da0002d148f37a07591cfc7474613 /common/console.c
parentd47e89a45d8ee57c31e6afcdfcbc1288dcaa27a6 (diff)
downloadbarebox-4cfc09da3865df1f0f8ea48d34073a8135011d04.tar.gz
barebox-4cfc09da3865df1f0f8ea48d34073a8135011d04.tar.xz
console: Add functions to get/set active state of console
Currently code needs to fiddle with the active parameter of a console device directly to enable/disable consoles. Add console_set_active() to set the status and console_get_active() to get the current status. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c87
1 files changed, 53 insertions, 34 deletions
diff --git a/common/console.c b/common/console.c
index 0c32f06b93..53030b5856 100644
--- a/common/console.c
+++ b/common/console.c
@@ -58,32 +58,14 @@ static struct kfifo __console_output_fifo;
static struct kfifo *console_input_fifo = &__console_input_fifo;
static struct kfifo *console_output_fifo = &__console_output_fifo;
-static int console_std_set(struct device_d *dev, struct param_d *param,
- const char *val)
+int console_set_active(struct console_device *cdev, unsigned flag)
{
- struct console_device *cdev = to_console_dev(dev);
- char active[4];
- unsigned int flag = 0, i = 0;
- int ret;
-
- if (val) {
- if (strchr(val, 'i') && cdev->getc) {
- active[i++] = 'i';
- flag |= CONSOLE_STDIN;
- }
-
- if (cdev->putc) {
- if (strchr(val, 'o')) {
- active[i++] = 'o';
- flag |= CONSOLE_STDOUT;
- }
+ int ret, i;
- if (strchr(val, 'e')) {
- active[i++] = 'e';
- flag |= CONSOLE_STDERR;
- }
- }
- }
+ if (!cdev->getc)
+ flag &= ~CONSOLE_STDIN;
+ if (!cdev->putc)
+ flag &= ~(CONSOLE_STDOUT | CONSOLE_STDERR);
if (flag && !cdev->f_active) {
/* The device is being activated, set its baudrate */
@@ -97,16 +79,25 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
return ret;
}
- active[i] = 0;
cdev->f_active = flag;
- dev_param_set_generic(dev, param, active);
+ if (IS_ENABLED(CONFIG_PARAMETER)) {
+ i = 0;
+
+ if (flag & CONSOLE_STDIN)
+ cdev->active[i++] = 'i';
+ if (flag & CONSOLE_STDOUT)
+ cdev->active[i++] = 'o';
+ if (flag & CONSOLE_STDERR)
+ cdev->active[i++] = 'e';
+ cdev->active[i] = 0;
+ }
if (initialized < CONSOLE_INIT_FULL) {
char ch;
initialized = CONSOLE_INIT_FULL;
puts_ll("Switch to console [");
- puts_ll(dev_name(dev));
+ puts_ll(dev_name(&cdev->class_dev));
puts_ll("]\n");
barebox_banner();
while (kfifo_getc(console_output_fifo, &ch) == 0)
@@ -116,6 +107,37 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
return 0;
}
+unsigned console_get_active(struct console_device *cdev)
+{
+ return cdev->f_active;
+}
+
+static int console_active_set(struct device_d *dev, struct param_d *param,
+ const char *val)
+{
+ struct console_device *cdev = to_console_dev(dev);
+ unsigned int flag = 0;
+
+ if (val) {
+ if (strchr(val, 'i'))
+ flag |= CONSOLE_STDIN;
+ if (strchr(val, 'o'))
+ flag |= CONSOLE_STDOUT;
+ if (strchr(val, 'e'))
+ flag |= CONSOLE_STDERR;
+ }
+
+ return console_set_active(cdev, flag);
+}
+
+static const char *console_active_get(struct device_d *dev,
+ struct param_d *param)
+{
+ struct console_device *cdev = to_console_dev(dev);
+
+ return cdev->active;
+}
+
static int console_baudrate_set(struct param_d *param, void *priv)
{
struct console_device *cdev = priv;
@@ -214,7 +236,7 @@ int console_register(struct console_device *newcdev)
if (newcdev->putc && !newcdev->puts)
newcdev->puts = __console_puts;
- dev_add_param(dev, "active", console_std_set, NULL, 0);
+ dev_add_param(dev, "active", console_active_set, console_active_get, 0);
if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
if (list_empty(&console_list))
@@ -230,12 +252,9 @@ int console_register(struct console_device *newcdev)
list_add_tail(&newcdev->list, &console_list);
- if (activate) {
- if (IS_ENABLED(CONFIG_PARAMETER))
- dev_set_param(dev, "active", "ioe");
- else
- console_std_set(dev, NULL, "ioe");
- }
+ if (activate)
+ console_set_active(newcdev, CONSOLE_STDIN |
+ CONSOLE_STDOUT | CONSOLE_STDERR);
return 0;
}