summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2015-06-09 09:26:43 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2015-06-09 09:26:43 +0200
commitd036dd5a66a2eaf4ae1486c0b57b342c8f1d537d (patch)
treea0c0e74348759168c767dc4cc09d53261c7b64b3 /common
parentee2ac17df0a9acdc49dc776668cc693eaebb330e (diff)
parentb4d5c8a03917decfe9a6c2f27d1a4e0fddfc07c3 (diff)
downloadbarebox-d036dd5a66a2eaf4ae1486c0b57b342c8f1d537d.tar.gz
barebox-d036dd5a66a2eaf4ae1486c0b57b342c8f1d537d.tar.xz
Merge branch 'for-next/console'
Diffstat (limited to 'common')
-rw-r--r--common/console.c126
-rw-r--r--common/console_common.c13
2 files changed, 99 insertions, 40 deletions
diff --git a/common/console.c b/common/console.c
index 0c32f06b93..0a6fc3e9bf 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;
- }
+ int ret, i;
- if (cdev->putc) {
- if (strchr(val, 'o')) {
- active[i++] = 'o';
- flag |= CONSOLE_STDOUT;
- }
-
- 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,29 +107,87 @@ static int console_std_set(struct device_d *dev, struct param_d *param,
return 0;
}
-static int console_baudrate_set(struct param_d *param, void *priv)
+unsigned console_get_active(struct console_device *cdev)
{
- struct console_device *cdev = priv;
+ 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;
+}
+
+int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
+{
+ 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);
+ printf("## Switch baudrate on console %s to %d bps and press ENTER ...\n",
+ dev_name(&cdev->class_dev), 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,
@@ -208,13 +257,13 @@ 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)
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 +279,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;
}
diff --git a/common/console_common.c b/common/console_common.c
index 41a6929dba..1e362ab4e4 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -260,6 +260,19 @@ struct console_device *console_get_by_dev(struct device_d *dev)
}
EXPORT_SYMBOL(console_get_by_dev);
+struct console_device *console_get_by_name(const char *name)
+{
+ struct console_device *cdev;
+
+ for_each_console(cdev) {
+ if (!strcmp(cdev->devname, name))
+ return cdev;
+ }
+
+ return NULL;
+}
+EXPORT_SYMBOL(console_get_by_name);
+
/*
* @brief returns current used console device
*