summaryrefslogtreecommitdiff
path: root/common/console.c
diff options
context:
space:
mode:
authorBastian Stender <bst@pengutronix.de>2017-02-28 15:31:24 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2017-02-28 15:52:35 +0100
commit123357079882de948f5f42a15c1af21a26130af2 (patch)
treee139b36d21b05e749025ef5c2825cf96b272bbd0 /common/console.c
parent3cade5ec3a8a0bbf15c8495915961c9d718877be (diff)
downloadbarebox-123357079882de948f5f42a15c1af21a26130af2.tar.gz
console: replace set_active by open/close
Opening and closing consoles should be independent from setting them active. This way it is possible to open e.g. a framebuffer console and display text on it without showing stdout/stderr. Signed-off-by: Bastian Stender <bst@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c46
1 files changed, 44 insertions, 2 deletions
diff --git a/common/console.c b/common/console.c
index 74ccfcfc3e..eccbeed0ca 100644
--- a/common/console.c
+++ b/common/console.c
@@ -59,6 +59,39 @@ static struct kfifo __console_output_fifo;
static struct kfifo *console_input_fifo = &__console_input_fifo;
static struct kfifo *console_output_fifo = &__console_output_fifo;
+int console_open(struct console_device *cdev)
+{
+ int ret;
+
+ if (cdev->open && !cdev->open_count) {
+ ret = cdev->open(cdev);
+ if (ret)
+ return ret;
+ }
+
+ cdev->open_count++;
+
+ return 0;
+}
+
+int console_close(struct console_device *cdev)
+{
+ int ret;
+
+ if (!cdev->open_count)
+ return -EBADFD;
+
+ cdev->open_count--;
+
+ if (cdev->close && !cdev->open_count) {
+ ret = cdev->close(cdev);
+ if (ret)
+ return ret;
+ }
+
+ return 0;
+}
+
int console_set_active(struct console_device *cdev, unsigned flag)
{
int ret, i;
@@ -71,8 +104,15 @@ int console_set_active(struct console_device *cdev, unsigned flag)
if (!flag && cdev->f_active && cdev->flush)
cdev->flush(cdev);
- if (cdev->set_active) {
- ret = cdev->set_active(cdev, flag);
+ if (flag == cdev->f_active)
+ return 0;
+
+ if (!flag) {
+ ret = console_close(cdev);
+ if (ret)
+ return ret;
+ } else {
+ ret = console_open(cdev);
if (ret)
return ret;
}
@@ -264,6 +304,8 @@ int console_register(struct console_device *newcdev)
if (newcdev->putc && !newcdev->puts)
newcdev->puts = __console_puts;
+ newcdev->open_count = 0;
+
dev_add_param(dev, "active", console_active_set, console_active_get, 0);
if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {