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>
19 #include <asm/natfeat.h>
22 static struct tty_port nfcon_tty_port
;
23 static struct tty_driver
*nfcon_tty_driver
;
25 static void nfputs(const char *str
, unsigned int count
)
32 nf_call(stderr_id
, buf
);
36 memcpy(buf
, str
, count
);
38 nf_call(stderr_id
, buf
);
41 static void nfcon_write(struct console
*con
, const char *str
,
47 static struct tty_driver
*nfcon_device(struct console
*con
, int *index
)
50 return (con
->flags
& CON_ENABLED
) ? nfcon_tty_driver
: NULL
;
53 static struct console nf_console
= {
56 .device
= nfcon_device
,
57 .flags
= CON_PRINTBUFFER
,
62 static int nfcon_tty_open(struct tty_struct
*tty
, struct file
*filp
)
67 static void nfcon_tty_close(struct tty_struct
*tty
, struct file
*filp
)
71 static int nfcon_tty_write(struct tty_struct
*tty
, const unsigned char *buf
,
78 static int nfcon_tty_put_char(struct tty_struct
*tty
, unsigned char ch
)
80 char temp
[2] = { ch
, 0 };
82 nf_call(stderr_id
, temp
);
86 static int nfcon_tty_write_room(struct tty_struct
*tty
)
91 static const struct tty_operations nfcon_tty_ops
= {
92 .open
= nfcon_tty_open
,
93 .close
= nfcon_tty_close
,
94 .write
= nfcon_tty_write
,
95 .put_char
= nfcon_tty_put_char
,
96 .write_room
= nfcon_tty_write_room
,
101 static int __init
nf_debug_setup(char *arg
)
103 if (strcmp(arg
, "nfcon"))
106 stderr_id
= nf_get_id("NF_STDERR");
108 nf_console
.flags
|= CON_ENABLED
;
109 register_console(&nf_console
);
115 early_param("debug", nf_debug_setup
);
119 static int __init
nfcon_init(void)
123 stderr_id
= nf_get_id("NF_STDERR");
127 nfcon_tty_driver
= alloc_tty_driver(1);
128 if (!nfcon_tty_driver
)
131 tty_port_init(&nfcon_tty_port
);
133 nfcon_tty_driver
->driver_name
= "nfcon";
134 nfcon_tty_driver
->name
= "nfcon";
135 nfcon_tty_driver
->type
= TTY_DRIVER_TYPE_SYSTEM
;
136 nfcon_tty_driver
->subtype
= SYSTEM_TYPE_TTY
;
137 nfcon_tty_driver
->init_termios
= tty_std_termios
;
138 nfcon_tty_driver
->flags
= TTY_DRIVER_REAL_RAW
;
140 tty_set_operations(nfcon_tty_driver
, &nfcon_tty_ops
);
141 tty_port_link_device(&nfcon_tty_port
, nfcon_tty_driver
, 0);
142 res
= tty_register_driver(nfcon_tty_driver
);
144 pr_err("failed to register nfcon tty driver\n");
145 put_tty_driver(nfcon_tty_driver
);
146 tty_port_destroy(&nfcon_tty_port
);
150 if (!(nf_console
.flags
& CON_ENABLED
))
151 register_console(&nf_console
);
156 static void __exit
nfcon_exit(void)
158 unregister_console(&nf_console
);
159 tty_unregister_driver(nfcon_tty_driver
);
160 put_tty_driver(nfcon_tty_driver
);
161 tty_port_destroy(&nfcon_tty_port
);
164 module_init(nfcon_init
);
165 module_exit(nfcon_exit
);
167 MODULE_LICENSE("GPL");