12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kdev_t.h>
15 #include <linux/tty.h>
22 #include <linux/reboot.h>
23 #include <linux/serial.h>
24 #include <linux/slab.h>
29 #include <asm/uaccess.h>
30 #include <asm/delay.h>
32 #include <asm/setup.h>
37 #define NR_3215_REQ (4*NR_3215)
38 #define RAW3215_BUFFER_SIZE 65536
39 #define RAW3215_INBUF_SIZE 256
40 #define RAW3215_MIN_SPACE 128
41 #define RAW3215_MIN_WRITE 1024
42 #define RAW3215_MAX_BYTES 3968
43 #define RAW3215_MAX_NEWLINE 50
44 #define RAW3215_NR_CCWS 3
45 #define RAW3215_TIMEOUT HZ/10
47 #define RAW3215_WORKING 4
48 #define RAW3215_THROTTLED 8
49 #define RAW3215_STOPPED 16
50 #define RAW3215_TIMER_RUNS 64
51 #define RAW3215_FLUSHING 128
53 #define TAB_STOP_SIZE 8
108 static inline struct raw3215_req *raw3215_alloc_req(
void)
114 req = raw3215_freelist;
115 raw3215_freelist = req->
next;
116 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
131 req->
next = raw3215_freelist;
132 raw3215_freelist =
req;
133 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
151 req = raw3215_alloc_req();
170 static void raw3215_mk_write_req(
struct raw3215_info *raw)
182 req = raw3215_alloc_req();
200 while (lines < RAW3215_MAX_NEWLINE && ix != raw->
head) {
201 if (raw->
buffer[ix] == 0x15)
217 ccw[-1].
flags |= 0x40;
236 ccw[-1].
flags |= 0x40;
257 (
unsigned long) req, 0, 0);
271 (
unsigned long) req, 0, 0);
284 static void raw3215_timeout(
unsigned long __data)
294 raw3215_mk_write_req(raw);
295 raw3215_start_io(raw);
307 static inline void raw3215_try_io(
struct raw3215_info *raw)
313 raw3215_start_io(raw);
318 raw3215_start_io(raw);
335 static void raw3215_wakeup(
unsigned long data)
352 raw3215_mk_write_req(raw);
355 tasklet_schedule(&raw->
tlet);
376 raw3215_next_io(raw, tty);
385 raw3215_mk_read_req(raw);
386 raw3215_next_io(raw, tty);
427 tty_insert_flip_string(tty, raw->
inbuf, count);
436 raw3215_free_req(req);
443 raw3215_next_io(raw, tty);
453 raw3215_free_req(req);
455 raw3215_next_io(raw, tty);
471 while (raw->
count > 0) {
493 raw3215_drop_line(raw);
498 raw3215_mk_write_req(raw);
501 #ifdef CONFIG_TN3215_CONSOLE
529 raw3215_make_room(raw, count);
533 c =
min_t(
int, count,
547 raw3215_mk_write_req(raw);
558 static void raw3215_putchar(
struct raw3215_info *raw,
unsigned char ch)
568 }
else if (ch ==
'\n') {
575 raw3215_make_room(raw, length);
577 for (i = 0; i <
length; i++) {
583 raw3215_mk_write_req(raw);
594 static void raw3215_flush_buffer(
struct raw3215_info *raw)
599 if (raw->
count > 0) {
683 static int raw3215_probe (
struct ccw_device *cdev)
692 raw = raw3215_alloc_info();
700 spin_lock(&raw3215_device_lock);
701 for (line = 0; line <
NR_3215; line++) {
702 if (!raw3215[line]) {
707 spin_unlock(&raw3215_device_lock);
708 if (line == NR_3215) {
709 raw3215_free_info(raw);
716 static void raw3215_remove (
struct ccw_device *cdev)
724 spin_lock(&raw3215_device_lock);
725 for (line = 0; line <
NR_3215; line++)
726 if (raw3215[line] == raw)
728 raw3215[line] =
NULL;
729 spin_unlock(&raw3215_device_lock);
731 raw3215_free_info(raw);
735 static int raw3215_set_online (
struct ccw_device *cdev)
743 return raw3215_startup(raw);
746 static int raw3215_set_offline (
struct ccw_device *cdev)
754 raw3215_shutdown(raw);
759 static int raw3215_pm_stop(
struct ccw_device *cdev)
773 static int raw3215_pm_start(
struct ccw_device *cdev)
794 static struct ccw_driver raw3215_ccw_driver = {
800 .probe = &raw3215_probe,
801 .remove = &raw3215_remove,
802 .set_online = &raw3215_set_online,
803 .set_offline = &raw3215_set_offline,
804 .freeze = &raw3215_pm_stop,
805 .thaw = &raw3215_pm_start,
806 .restore = &raw3215_pm_start,
810 #ifdef CONFIG_TN3215_CONSOLE
814 static void con3215_write(
struct console *co,
const char *str,
824 for (i = 0; i <
count; i++)
825 if (str[i] ==
'\t' || str[i] ==
'\n')
827 raw3215_write(raw, str, i);
831 raw3215_putchar(raw, *str);
841 return tty3215_driver;
848 static void con3215_flush(
void)
865 unsigned long event,
void *data)
884 static struct console con3215 = {
886 .write = con3215_write,
887 .device = con3215_device,
894 static int __init con3215_init(
void)
912 raw3215_freelist =
NULL;
916 req->
next = raw3215_freelist;
917 raw3215_freelist =
req;
924 raw3215[0] = raw = raw3215_alloc_info();
930 if (raw3215_startup(raw) != 0) {
931 raw3215_free_info(raw);
947 raw = raw3215[tty->
index];
961 static int tty3215_open(
struct tty_struct *tty,
struct file * filp)
972 retval = raw3215_startup(raw);
985 static void tty3215_close(
struct tty_struct *tty,
struct file * filp)
994 raw3215_shutdown(raw);
1003 static int tty3215_write_room(
struct tty_struct *tty)
1019 static int tty3215_write(
struct tty_struct * tty,
1020 const unsigned char *
buf,
int count)
1027 raw3215_write(raw, buf, count);
1034 static int tty3215_put_char(
struct tty_struct *tty,
unsigned char ch)
1041 raw3215_putchar(raw, ch);
1045 static void tty3215_flush_chars(
struct tty_struct *tty)
1052 static int tty3215_chars_in_buffer(
struct tty_struct *tty)
1060 static void tty3215_flush_buffer(
struct tty_struct *tty)
1065 raw3215_flush_buffer(raw);
1072 static void tty3215_throttle(
struct tty_struct * tty)
1083 static void tty3215_unthrottle(
struct tty_struct * tty)
1086 unsigned long flags;
1092 raw3215_try_io(raw);
1100 static void tty3215_stop(
struct tty_struct *tty)
1111 static void tty3215_start(
struct tty_struct *tty)
1114 unsigned long flags;
1120 raw3215_try_io(raw);
1126 .install = tty3215_install,
1127 .open = tty3215_open,
1128 .close = tty3215_close,
1129 .write = tty3215_write,
1130 .put_char = tty3215_put_char,
1131 .flush_chars = tty3215_flush_chars,
1132 .write_room = tty3215_write_room,
1133 .chars_in_buffer = tty3215_chars_in_buffer,
1134 .flush_buffer = tty3215_flush_buffer,
1135 .throttle = tty3215_throttle,
1136 .unthrottle = tty3215_unthrottle,
1137 .stop = tty3215_stop,
1138 .start = tty3215_start,
1145 static int __init tty3215_init(
void)
1153 driver = alloc_tty_driver(NR_3215);
1169 driver->
name =
"ttyS";
1189 static void __exit tty3215_exit(
void)