2 * arch/xtensa/platforms/iss/console.c
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
8 * Copyright (C) 2001-2005 Tensilica Inc.
9 * Authors Christian Zankel, Joe Taylor
12 #include <linux/module.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
15 #include <linux/console.h>
16 #include <linux/init.h>
18 #include <linux/major.h>
19 #include <linux/param.h>
20 #include <linux/seq_file.h>
21 #include <linux/serial.h>
23 #include <linux/uaccess.h>
26 #include <platform/simcall.h>
28 #include <linux/tty.h>
29 #include <linux/tty_flip.h>
31 #define SERIAL_MAX_NUM_LINES 1
32 #define SERIAL_TIMER_VALUE (HZ / 10)
34 static void rs_poll(struct timer_list *);
36 static struct tty_driver *serial_driver;
37 static struct tty_port serial_port;
38 static DEFINE_TIMER(serial_timer, rs_poll);
39 static DEFINE_SPINLOCK(timer_lock);
41 static int rs_open(struct tty_struct *tty, struct file * filp)
43 spin_lock_bh(&timer_lock);
45 mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
46 spin_unlock_bh(&timer_lock);
51 static void rs_close(struct tty_struct *tty, struct file * filp)
53 spin_lock_bh(&timer_lock);
55 del_timer_sync(&serial_timer);
56 spin_unlock_bh(&timer_lock);
60 static int rs_write(struct tty_struct * tty,
61 const unsigned char *buf, int count)
63 /* see drivers/char/serialX.c to reference original version */
65 simc_write(1, buf, count);
69 static void rs_poll(struct timer_list *unused)
71 struct tty_port *port = &serial_port;
76 spin_lock(&timer_lock);
78 while (simc_poll(0)) {
79 rd = simc_read(0, &c, 1);
82 tty_insert_flip_char(port, c, TTY_NORMAL);
87 tty_flip_buffer_push(port);
89 mod_timer(&serial_timer, jiffies + SERIAL_TIMER_VALUE);
90 spin_unlock(&timer_lock);
94 static int rs_put_char(struct tty_struct *tty, unsigned char ch)
96 return rs_write(tty, &ch, 1);
99 static void rs_flush_chars(struct tty_struct *tty)
103 static unsigned int rs_write_room(struct tty_struct *tty)
105 /* Let's say iss can always accept 2K characters.. */
109 static void rs_hangup(struct tty_struct *tty)
111 /* Stub, once again.. */
114 static void rs_wait_until_sent(struct tty_struct *tty, int timeout)
116 /* Stub, once again.. */
119 static int rs_proc_show(struct seq_file *m, void *v)
121 seq_printf(m, "serinfo:1.0 driver:0.1\n");
125 static const struct tty_operations serial_ops = {
129 .put_char = rs_put_char,
130 .flush_chars = rs_flush_chars,
131 .write_room = rs_write_room,
133 .wait_until_sent = rs_wait_until_sent,
134 .proc_show = rs_proc_show,
137 static int __init rs_init(void)
139 tty_port_init(&serial_port);
141 serial_driver = alloc_tty_driver(SERIAL_MAX_NUM_LINES);
143 /* Initialize the tty_driver structure */
145 serial_driver->driver_name = "iss_serial";
146 serial_driver->name = "ttyS";
147 serial_driver->major = TTY_MAJOR;
148 serial_driver->minor_start = 64;
149 serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
150 serial_driver->subtype = SERIAL_TYPE_NORMAL;
151 serial_driver->init_termios = tty_std_termios;
152 serial_driver->init_termios.c_cflag =
153 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
154 serial_driver->flags = TTY_DRIVER_REAL_RAW;
156 tty_set_operations(serial_driver, &serial_ops);
157 tty_port_link_device(&serial_port, serial_driver, 0);
159 if (tty_register_driver(serial_driver))
160 panic("Couldn't register serial driver\n");
165 static __exit void rs_exit(void)
167 tty_unregister_driver(serial_driver);
168 put_tty_driver(serial_driver);
169 tty_port_destroy(&serial_port);
173 /* We use `late_initcall' instead of just `__initcall' as a workaround for
174 * the fact that (1) simcons_tty_init can't be called before tty_init,
175 * (2) tty_init is called via `module_init', (3) if statically linked,
176 * module_init == device_init, and (4) there's no ordering of init lists.
177 * We can do this easily because simcons is always statically linked, but
178 * other tty drivers that depend on tty_init and which must use
179 * `module_init' to declare their init routines are likely to be broken.
182 late_initcall(rs_init);
185 #ifdef CONFIG_SERIAL_CONSOLE
187 static void iss_console_write(struct console *co, const char *s, unsigned count)
191 simc_write(1, s, count < len ? count : len);
195 static struct tty_driver* iss_console_device(struct console *c, int *index)
198 return serial_driver;
202 static struct console sercons = {
204 .write = iss_console_write,
205 .device = iss_console_device,
206 .flags = CON_PRINTBUFFER,
210 static int __init iss_console_init(void)
212 register_console(&sercons);
216 console_initcall(iss_console_init);
218 #endif /* CONFIG_SERIAL_CONSOLE */