8 #include <linux/kernel.h>
13 #include <linux/slab.h>
16 #include <linux/tty.h>
21 #include <asm/uaccess.h>
25 static int srm_is_registered_console = 0;
30 #define MAX_SRM_CONSOLE_DEVICES 1
47 srmcons_do_receive_chars(
struct tty_struct *tty)
50 int count = 0, loops = 0;
53 result.
as_long = callback_getc(0);
54 if (result.
bits.status < 2) {
55 tty_insert_flip_char(tty, (
char)result.
bits.c, 0);
58 }
while((result.
bits.status & 1) && (++loops < 10));
67 srmcons_receive_chars(
unsigned long data)
75 if (spin_trylock(&srmcons_callback_lock)) {
76 if (!srmcons_do_receive_chars(port->
tty))
78 spin_unlock(&srmcons_callback_lock);
81 spin_lock(&port->
lock);
84 spin_unlock(&port->
lock);
91 srmcons_do_write(
struct tty_struct *tty,
const char *
buf,
int count)
93 static char str_cr[1] =
"\r";
99 for (cur = (
char *)buf; remaining > 0; ) {
105 for (c = 0; c <
min_t(
long, 128L, remaining) && !need_cr; c++)
110 result.
as_long = callback_puts(0, cur, c);
112 remaining -= result.
bits.c;
113 cur += result.
bits.c;
119 srmcons_do_receive_chars(tty);
123 result.
as_long = callback_puts(0, str_cr, 1);
124 if (result.
bits.c > 0)
133 const unsigned char *buf,
int count)
138 srmcons_do_write(tty, (
const char *) buf, count);
139 spin_unlock_irqrestore(&srmcons_callback_lock, flags);
151 srmcons_chars_in_buffer(
struct tty_struct *tty)
172 spin_unlock_irqrestore(&port->
lock, flags);
186 if (tty->
count == 1) {
191 spin_unlock_irqrestore(&port->
lock, flags);
198 .open = srmcons_open,
199 .close = srmcons_close,
200 .write = srmcons_write,
201 .write_room = srmcons_write_room,
202 .chars_in_buffer= srmcons_chars_in_buffer,
211 if (srm_is_registered_console) {
219 driver->
name =
"srm";
245 srm_console_write(
struct console *co,
const char *
s,
unsigned count)
250 srmcons_do_write(
NULL, s, count);
251 spin_unlock_irqrestore(&srmcons_callback_lock, flags);
258 return srmcons_driver;
267 static struct console srmcons = {
269 .write = srm_console_write,
270 .device = srm_console_device,
271 .setup = srm_console_setup,
279 if (!srm_is_registered_console) {
280 callback_open_console();
282 srm_is_registered_console = 1;
289 if (srm_is_registered_console) {
290 callback_close_console();
292 srm_is_registered_console = 0;