linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Kay Sievers <kay@vrfy.org>,
	Samuel Thibault <samuel.thibault@ens-lyon.org>,
	Ming Lei <ming.lei@canonical.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH V2 03/23] printk: Move braille console support into separate braille.[ch] files
Date: Wed, 24 Oct 2012 20:43:38 -0700	[thread overview]
Message-ID: <20522b7e411bd5eba2d71f8523cf7a9ea7bad259.1351135988.git.joe@perches.com> (raw)
In-Reply-To: <cover.1351135988.git.joe@perches.com>

Create files with prototypes and static inlines for braille
support.  Make braille_console functions return 1 on success.

Corrected CONFIG_A11Y_BRAILLE_CONSOLE=n _braille_console_setup
return value to NULL.

link:  http://lkml.kernel.org/r/1350999678-17441-1-git-send-email-ming.lei@canonical.com
cc: Samuel Thibault <samuel.thibault@ens-lyon.org>
cc: Ming Lei <ming.lei@canonical.com>

Signed-off-by: Joe Perches <joe@perches.com>
---
 drivers/accessibility/braille/braille_console.c |    9 +++-
 kernel/printk/Makefile                          |    1 +
 kernel/printk/braille.c                         |   48 +++++++++++++++++++++++
 kernel/printk/braille.h                         |   48 +++++++++++++++++++++++
 kernel/printk/printk.c                          |   44 ++++++---------------
 5 files changed, 117 insertions(+), 33 deletions(-)
 create mode 100644 kernel/printk/braille.c
 create mode 100644 kernel/printk/braille.h

diff --git a/drivers/accessibility/braille/braille_console.c b/drivers/accessibility/braille/braille_console.c
index d21167b..dc34a5b 100644
--- a/drivers/accessibility/braille/braille_console.c
+++ b/drivers/accessibility/braille/braille_console.c
@@ -359,6 +359,9 @@ int braille_register_console(struct console *console, int index,
 		char *console_options, char *braille_options)
 {
 	int ret;
+
+	if (!(console->flags & CON_BRL))
+		return 0;
 	if (!console_options)
 		/* Only support VisioBraille for now */
 		console_options = "57600o8";
@@ -374,15 +377,17 @@ int braille_register_console(struct console *console, int index,
 	braille_co = console;
 	register_keyboard_notifier(&keyboard_notifier_block);
 	register_vt_notifier(&vt_notifier_block);
-	return 0;
+	return 1;
 }
 
 int braille_unregister_console(struct console *console)
 {
 	if (braille_co != console)
 		return -EINVAL;
+	if (!(console->flags & CON_BRL))
+		return 0;
 	unregister_keyboard_notifier(&keyboard_notifier_block);
 	unregister_vt_notifier(&vt_notifier_block);
 	braille_co = NULL;
-	return 0;
+	return 1;
 }
diff --git a/kernel/printk/Makefile b/kernel/printk/Makefile
index 36d306d..85405bd 100644
--- a/kernel/printk/Makefile
+++ b/kernel/printk/Makefile
@@ -1 +1,2 @@
 obj-y	= printk.o
+obj-$(CONFIG_A11Y_BRAILLE_CONSOLE)	+= braille.o
diff --git a/kernel/printk/braille.c b/kernel/printk/braille.c
new file mode 100644
index 0000000..b51087f
--- /dev/null
+++ b/kernel/printk/braille.c
@@ -0,0 +1,48 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/kernel.h>
+#include <linux/console.h>
+#include <linux/string.h>
+
+#include "console_cmdline.h"
+#include "braille.h"
+
+char *_braille_console_setup(char **str, char **brl_options)
+{
+	if (!memcmp(*str, "brl,", 4)) {
+		*brl_options = "";
+		*str += 4;
+	} else if (!memcmp(str, "brl=", 4)) {
+		*brl_options = *str + 4;
+		*str = strchr(*brl_options, ',');
+		if (!*str)
+			pr_err("need port name after brl=\n");
+		else
+			*((*str)++) = 0;
+	}
+
+	return *str;
+}
+
+int
+_braille_register_console(struct console *console, struct console_cmdline *c)
+{
+	int rtn = 0;
+
+	if (c->brl_options) {
+		console->flags |= CON_BRL;
+		rtn = braille_register_console(console, c->index, c->options,
+					       c->brl_options);
+	}
+
+	return rtn;
+}
+
+int
+_braille_unregister_console(struct console *console)
+{
+	if (console->flags & CON_BRL)
+		return braille_unregister_console(console);
+
+	return 0;
+}
diff --git a/kernel/printk/braille.h b/kernel/printk/braille.h
new file mode 100644
index 0000000..769d771
--- /dev/null
+++ b/kernel/printk/braille.h
@@ -0,0 +1,48 @@
+#ifndef _PRINTK_BRAILLE_H
+#define _PRINTK_BRAILLE_H
+
+#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
+
+static inline void
+braille_set_options(struct console_cmdline *c, char *brl_options)
+{
+	c->brl_options = brl_options;
+}
+
+char *
+_braille_console_setup(char **str, char **brl_options);
+
+int
+_braille_register_console(struct console *console, struct console_cmdline *c);
+
+int
+_braille_unregister_console(struct console *console);
+
+#else
+
+static inline void
+braille_set_options(struct console_cmdline *c, char *brl_options)
+{
+}
+
+static inline char *
+_braille_console_setup(char **str, char **brl_options)
+{
+	return NULL;
+}
+
+static inline int
+_braille_register_console(struct console *console, struct console_cmdline *c)
+{
+	return 0;
+}
+
+static inline int
+_braille_unregister_console(struct console *console)
+{
+	return 0;
+}
+
+#endif
+
+#endif
diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
index 50ef6af..df5b80f 100644
--- a/kernel/printk/printk.c
+++ b/kernel/printk/printk.c
@@ -47,6 +47,7 @@
 #include <trace/events/printk.h>
 
 #include "console_cmdline.h"
+#include "braille.h"
 
 /*
  * Architectures can override it:
@@ -1731,9 +1732,8 @@ static int __add_preferred_console(char *name, int idx, char *options,
 	c = &console_cmdline[i];
 	strlcpy(c->name, name, sizeof(c->name));
 	c->options = options;
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
-	c->brl_options = brl_options;
-#endif
+	braille_set_options(c, brl_options);
+
 	c->index = idx;
 	return 0;
 }
@@ -1746,20 +1746,8 @@ static int __init console_setup(char *str)
 	char *s, *options, *brl_options = NULL;
 	int idx;
 
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
-	if (!memcmp(str, "brl,", 4)) {
-		brl_options = "";
-		str += 4;
-	} else if (!memcmp(str, "brl=", 4)) {
-		brl_options = str + 4;
-		str = strchr(brl_options, ',');
-		if (!str) {
-			printk(KERN_ERR "need port name after brl=\n");
-			return 1;
-		}
-		*(str++) = 0;
-	}
-#endif
+	if (_braille_console_setup(&str, &brl_options))
+		return 1;
 
 	/*
 	 * Decode str into name, index, options.
@@ -2286,16 +2274,10 @@ void register_console(struct console *newcon)
 			continue;
 		if (newcon->index < 0)
 			newcon->index = console_cmdline[i].index;
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
-		if (console_cmdline[i].brl_options) {
-			newcon->flags |= CON_BRL;
-			braille_register_console(newcon,
-					console_cmdline[i].index,
-					console_cmdline[i].options,
-					console_cmdline[i].brl_options);
+
+		if (_braille_register_console(newcon, &console_cmdline[i]))
 			return;
-		}
-#endif
+
 		if (newcon->setup &&
 		    newcon->setup(newcon, console_cmdline[i].options) != 0)
 			break;
@@ -2383,13 +2365,13 @@ EXPORT_SYMBOL(register_console);
 int unregister_console(struct console *console)
 {
         struct console *a, *b;
-	int res = 1;
+	int res;
 
-#ifdef CONFIG_A11Y_BRAILLE_CONSOLE
-	if (console->flags & CON_BRL)
-		return braille_unregister_console(console);
-#endif
+	res = _braille_unregister_console(console);
+	if (res)
+		return res;
 
+	res = 1;
 	console_lock();
 	if (console_drivers == console) {
 		console_drivers=console->next;
-- 
1.7.8.112.g3fd21


  parent reply	other threads:[~2012-10-25  3:44 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-25  3:43 [PATCH V2 00/23] printk: refactoring Joe Perches
2012-10-25  3:43 ` [PATCH V2 01/23] printk: Move to separate directory for easier modification Joe Perches
2012-10-25  3:43 ` [PATCH V2 02/23] printk: Add console_cmdline.h Joe Perches
2012-10-25  3:43 ` Joe Perches [this message]
2012-10-25  3:43 ` [PATCH V2 04/23] printk: Use pointer for console_cmdline indexing Joe Perches
2012-10-25  3:43 ` [PATCH V2 05/23] printk: rename struct log to struct printk_log Joe Perches
2012-10-25  3:43 ` [PATCH V2 06/23] printk: Rename log_buf and __LOG_BUF_LEN Joe Perches
2012-10-25  3:43 ` [PATCH V2 07/23] printk: Rename log_first and log_next variables Joe Perches
2012-10-25  3:43 ` [PATCH V2 08/23] printk: Rename log_<foo> variables and functions Joe Perches
2012-10-25  3:43 ` [PATCH V2 09/23] printk: Rename enum log_flags to printk_log_flags Joe Perches
2012-10-25  3:43 ` [PATCH V2 10/23] printk: Rename log_wait to printk_log_wait Joe Perches
2012-10-25  3:43 ` [PATCH V2 11/23] printk: Rename logbuf_lock to printk_logbuf_lock Joe Perches
2012-10-25  3:43 ` [PATCH V2 12/23] printk: Rename clear_seq and clear_idx variables Joe Perches
2012-10-25  3:43 ` [PATCH V2 13/23] printk: Remove static from printk_ variables Joe Perches
2012-10-25  3:43 ` [PATCH V2 14/23] printk: Rename LOG_ALIGN to PRINTK_LOG_ALIGN Joe Perches
2012-10-25  3:43 ` [PATCH V2 15/23] printk: Add and use printk_log.h Joe Perches
2012-10-25  3:43 ` [PATCH V2 16/23] printk: Add printk_log.c Joe Perches
2012-10-25  3:43 ` [PATCH V2 17/23] printk: Make wait_queue_head_t printk_log_wait extern Joe Perches
2012-10-25  3:43 ` [PATCH V2 18/23] printk: Rename and move 2 #defines to printk_log.h Joe Perches
2012-10-25  3:43 ` [PATCH V2 19/23] printk: Move devkmsg bits to separate file Joe Perches
2012-10-25  3:43 ` [PATCH V2 20/23] printk: Prefix print_time and msg_print_text with printk_ Joe Perches
2012-10-25  3:43 ` [PATCH V2 21/23] printk: Move functions printk_print_time and printk_msg_print_text Joe Perches
2012-10-25  3:43 ` [PATCH V2 22/23] printk: Add printk_syslog.c and .h Joe Perches
2012-10-25  3:43 ` [PATCH V2 23/23] printk: Move kmsg_dump functions to separate file Joe Perches
     [not found] ` <1351864140.3537.1.camel@joe-AO722>
2012-11-12 22:54   ` [PATCH V2 00/23] printk: refactoring Joe Perches
2012-11-12 23:26     ` Andrew Morton
2012-11-12 23:30       ` Joe Perches
2012-11-29 22:08       ` Joe Perches
2012-11-29 22:21         ` Andrew Morton
2012-11-29 22:46           ` Joe Perches
2012-11-29 22:53             ` Kay Sievers
2012-11-30 10:20               ` "Jan H. Schönherr"

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20522b7e411bd5eba2d71f8523cf7a9ea7bad259.1351135988.git.joe@perches.com \
    --to=joe@perches.com \
    --cc=akpm@linux-foundation.org \
    --cc=kay@vrfy.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ming.lei@canonical.com \
    --cc=samuel.thibault@ens-lyon.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).