2 * ARAnyM console driver
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file COPYING in the main directory of this archive
9 #include <linux/module.h>
10 #include <linux/init.h>
11 #include <linux/console.h>
12 #include <linux/tty.h>
13 #include <linux/tty_driver.h>
14 #include <linux/tty_flip.h>
15 #include <linux/slab.h>
16 #include <linux/err.h>
17 #include <linux/uaccess.h>
20 #include <asm/natfeat.h>
23 static struct tty_port nfcon_tty_port;
24 static struct tty_driver *nfcon_tty_driver;
26 static void nfputs(const char *str, unsigned int count)
29 unsigned long phys = virt_to_phys(buf);
34 nf_call(stderr_id, phys);
38 memcpy(buf, str, count);
40 nf_call(stderr_id, phys);
43 static void nfcon_write(struct console *con, const char *str,
49 static struct tty_driver *nfcon_device(struct console *con, int *index)
52 return console_is_registered(con) ? nfcon_tty_driver : NULL;
55 static struct console nf_console = {
58 .device = nfcon_device,
59 .flags = CON_PRINTBUFFER,
64 static int nfcon_tty_open(struct tty_struct *tty, struct file *filp)
69 static void nfcon_tty_close(struct tty_struct *tty, struct file *filp)
73 static ssize_t nfcon_tty_write(struct tty_struct *tty, const u8 *buf,
80 static int nfcon_tty_put_char(struct tty_struct *tty, u8 ch)
82 u8 temp[2] = { ch, 0 };
84 nf_call(stderr_id, virt_to_phys(temp));
88 static unsigned int nfcon_tty_write_room(struct tty_struct *tty)
93 static const struct tty_operations nfcon_tty_ops = {
94 .open = nfcon_tty_open,
95 .close = nfcon_tty_close,
96 .write = nfcon_tty_write,
97 .put_char = nfcon_tty_put_char,
98 .write_room = nfcon_tty_write_room,
103 static int __init nf_debug_setup(char *arg)
105 if (strcmp(arg, "nfcon"))
108 stderr_id = nf_get_id("NF_STDERR");
111 * The console will be enabled when debug=nfcon is specified
112 * as a kernel parameter. Since this is a non-standard way
113 * of enabling consoles, it must be explicitly enabled.
115 nf_console.flags |= CON_ENABLED;
116 register_console(&nf_console);
122 early_param("debug", nf_debug_setup);
126 static int __init nfcon_init(void)
128 struct tty_driver *driver;
131 stderr_id = nf_get_id("NF_STDERR");
135 driver = tty_alloc_driver(1, TTY_DRIVER_REAL_RAW);
137 return PTR_ERR(driver);
139 tty_port_init(&nfcon_tty_port);
141 driver->driver_name = "nfcon";
142 driver->name = "nfcon";
143 driver->type = TTY_DRIVER_TYPE_SYSTEM;
144 driver->subtype = SYSTEM_TYPE_TTY;
145 driver->init_termios = tty_std_termios;
147 tty_set_operations(driver, &nfcon_tty_ops);
148 tty_port_link_device(&nfcon_tty_port, driver, 0);
149 res = tty_register_driver(driver);
151 pr_err("failed to register nfcon tty driver\n");
152 tty_driver_kref_put(driver);
153 tty_port_destroy(&nfcon_tty_port);
157 nfcon_tty_driver = driver;
159 if (!console_is_registered(&nf_console))
160 register_console(&nf_console);
165 static void __exit nfcon_exit(void)
167 unregister_console(&nf_console);
168 tty_unregister_driver(nfcon_tty_driver);
169 tty_driver_kref_put(nfcon_tty_driver);
170 tty_port_destroy(&nfcon_tty_port);
173 module_init(nfcon_init);
174 module_exit(nfcon_exit);
176 MODULE_LICENSE("GPL");