summaryrefslogtreecommitdiffstats
path: root/common/console.c
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2017-04-06 22:03:40 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2017-04-11 08:33:47 +0200
commit68d69b43ea77eac93ac382107a011617a6ef09b1 (patch)
tree335f28628f240d19b2329342a22c743d29bbcd4c /common/console.c
parent2c32db73b263b4514bea45bdbf35590c14049fbb (diff)
downloadbarebox-68d69b43ea77eac93ac382107a011617a6ef09b1.tar.gz
console: Use dev_add_param_string
dev_add_param_string allows to pass a priv * so that the device_d * argument is not needed and can be removed later. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common/console.c')
-rw-r--r--common/console.c50
1 files changed, 24 insertions, 26 deletions
diff --git a/common/console.c b/common/console.c
index 74fb684..1bcb13f 100644
--- a/common/console.c
+++ b/common/console.c
@@ -94,7 +94,7 @@ int console_close(struct console_device *cdev)
int console_set_active(struct console_device *cdev, unsigned flag)
{
- int ret, i;
+ int ret;
if (!cdev->getc)
flag &= ~CONSOLE_STDIN;
@@ -119,18 +119,6 @@ int console_set_active(struct console_device *cdev, unsigned flag)
cdev->f_active = flag;
- 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;
@@ -150,30 +138,39 @@ 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)
+static int console_active_set(struct param_d *param, void *priv)
{
- struct console_device *cdev = to_console_dev(dev);
+ struct console_device *cdev = priv;
unsigned int flag = 0;
+ int ret;
- if (val) {
- if (strchr(val, 'i'))
+ if (cdev->active_string) {
+ if (strchr(cdev->active_string, 'i'))
flag |= CONSOLE_STDIN;
- if (strchr(val, 'o'))
+ if (strchr(cdev->active_string, 'o'))
flag |= CONSOLE_STDOUT;
- if (strchr(val, 'e'))
+ if (strchr(cdev->active_string, 'e'))
flag |= CONSOLE_STDERR;
}
- return console_set_active(cdev, flag);
+ ret = console_set_active(cdev, flag);
+ if (ret)
+ return ret;
+
+ return 0;
}
-static const char *console_active_get(struct device_d *dev,
- struct param_d *param)
+static int console_active_get(struct param_d *param, void *priv)
{
- struct console_device *cdev = to_console_dev(dev);
+ struct console_device *cdev = priv;
+ unsigned int flag = cdev->f_active;
- return cdev->active;
+ free(cdev->active_string);
+ cdev->active_string = basprintf("%s%s%s",
+ flag & CONSOLE_STDIN ? "i" : "",
+ flag & CONSOLE_STDOUT ? "o" : "",
+ flag & CONSOLE_STDERR ? "e" : "");
+ return 0;
}
int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
@@ -340,7 +337,8 @@ int console_register(struct console_device *newcdev)
newcdev->open_count = 0;
- dev_add_param(dev, "active", console_active_set, console_active_get, 0);
+ dev_add_param_string(dev, "active", console_active_set, console_active_get,
+ &newcdev->active_string, newcdev);
if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
if (list_empty(&console_list))