xref: /openbmc/linux/kernel/printk/braille.c (revision 976e3645923bdd2fe7893aae33fd7a21098bfb28)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
2bbeddf52SJoe Perches #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
3bbeddf52SJoe Perches 
4bbeddf52SJoe Perches #include <linux/kernel.h>
5bbeddf52SJoe Perches #include <linux/console.h>
62ed2b862SSamuel Thibault #include <linux/errno.h>
7bbeddf52SJoe Perches #include <linux/string.h>
8bbeddf52SJoe Perches 
9bbeddf52SJoe Perches #include "console_cmdline.h"
10bbeddf52SJoe Perches #include "braille.h"
11bbeddf52SJoe Perches 
_braille_console_setup(char ** str,char ** brl_options)122ed2b862SSamuel Thibault int _braille_console_setup(char **str, char **brl_options)
13bbeddf52SJoe Perches {
14*35c35493SChuhong Yuan 	size_t len;
15*35c35493SChuhong Yuan 
16*35c35493SChuhong Yuan 	len = str_has_prefix(*str, "brl,");
17*35c35493SChuhong Yuan 	if (len) {
18bbeddf52SJoe Perches 		*brl_options = "";
19*35c35493SChuhong Yuan 		*str += len;
20*35c35493SChuhong Yuan 		return 0;
21*35c35493SChuhong Yuan 	}
22*35c35493SChuhong Yuan 
23*35c35493SChuhong Yuan 	len = str_has_prefix(*str, "brl=");
24*35c35493SChuhong Yuan 	if (len) {
25*35c35493SChuhong Yuan 		*brl_options = *str + len;
26bbeddf52SJoe Perches 		*str = strchr(*brl_options, ',');
272ed2b862SSamuel Thibault 		if (!*str) {
28bbeddf52SJoe Perches 			pr_err("need port name after brl=\n");
292ed2b862SSamuel Thibault 			return -EINVAL;
302ed2b862SSamuel Thibault 		}
31bbeddf52SJoe Perches 		*((*str)++) = 0;
322ed2b862SSamuel Thibault 	}
33bbeddf52SJoe Perches 
342ed2b862SSamuel Thibault 	return 0;
35bbeddf52SJoe Perches }
36bbeddf52SJoe Perches 
37bbeddf52SJoe Perches int
_braille_register_console(struct console * console,struct console_cmdline * c)38bbeddf52SJoe Perches _braille_register_console(struct console *console, struct console_cmdline *c)
39bbeddf52SJoe Perches {
40bbeddf52SJoe Perches 	int rtn = 0;
41bbeddf52SJoe Perches 
42bbeddf52SJoe Perches 	if (c->brl_options) {
43bbeddf52SJoe Perches 		console->flags |= CON_BRL;
44bbeddf52SJoe Perches 		rtn = braille_register_console(console, c->index, c->options,
45bbeddf52SJoe Perches 					       c->brl_options);
46bbeddf52SJoe Perches 	}
47bbeddf52SJoe Perches 
48bbeddf52SJoe Perches 	return rtn;
49bbeddf52SJoe Perches }
50bbeddf52SJoe Perches 
51bbeddf52SJoe Perches int
_braille_unregister_console(struct console * console)52bbeddf52SJoe Perches _braille_unregister_console(struct console *console)
53bbeddf52SJoe Perches {
54bbeddf52SJoe Perches 	if (console->flags & CON_BRL)
55bbeddf52SJoe Perches 		return braille_unregister_console(console);
56bbeddf52SJoe Perches 
57bbeddf52SJoe Perches 	return 0;
58bbeddf52SJoe Perches }
59