2 * drivers/s390/char/con3215.c
3 * 3215 line mode terminal driver.
6 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
10 * Aug-2000: Added tab support
11 * Dan Morrison, IBM Corporation (dmorriso@cse.buffalo.edu)
14 #include <linux/config.h>
15 #include <linux/module.h>
16 #include <linux/types.h>
17 #include <linux/kdev_t.h>
18 #include <linux/tty.h>
19 #include <linux/tty_flip.h>
20 #include <linux/vt_kern.h>
21 #include <linux/init.h>
22 #include <linux/console.h>
23 #include <linux/interrupt.h>
24 #include <linux/err.h>
26 #include <linux/slab.h>
27 #include <linux/bootmem.h>
29 #include <asm/ccwdev.h>
32 #include <asm/ebcdic.h>
33 #include <asm/uaccess.h>
34 #include <asm/delay.h>
35 #include <asm/cpcmd.h>
36 #include <asm/setup.h>
41 #define NR_3215_REQ (4*NR_3215)
42 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
43 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
44 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
45 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
46 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
47 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
48 #define RAW3215_NR_CCWS 3
49 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
51 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
52 #define RAW3215_ACTIVE 2 /* set if the device is in use */
53 #define RAW3215_WORKING 4 /* set if a request is being worked on */
54 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
55 #define RAW3215_STOPPED 16 /* set if writing is disabled */
56 #define RAW3215_CLOSING 32 /* set while in close process */
57 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
58 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
60 #define TAB_STOP_SIZE 8 /* tab stop size */
63 * Request types for a 3215 device
66 RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
70 * Request structure for a 3215 device
73 enum raw3215_type type; /* type of the request */
74 int start, len; /* start index & len in output buffer */
75 int delayable; /* indication to wait for more data */
76 int residual; /* residual count for read request */
77 struct ccw1 ccws[RAW3215_NR_CCWS]; /* space for the channel program */
78 struct raw3215_info *info; /* pointer to main structure */
79 struct raw3215_req *next; /* pointer to next request */
80 } __attribute__ ((aligned(8)));
83 struct ccw_device *cdev; /* device for tty driver */
84 spinlock_t *lock; /* pointer to irq lock */
85 int flags; /* state flags */
86 char *buffer; /* pointer to output buffer */
87 char *inbuf; /* pointer to input buffer */
88 int head; /* first free byte in output buffer */
89 int count; /* number of bytes in output buffer */
90 int written; /* number of bytes in write requests */
91 struct tty_struct *tty; /* pointer to tty structure if present */
92 struct tasklet_struct tasklet;
93 struct raw3215_req *queued_read; /* pointer to queued read requests */
94 struct raw3215_req *queued_write;/* pointer to queued write requests */
95 wait_queue_head_t empty_wait; /* wait queue for flushing */
96 struct timer_list timer; /* timer for delayed output */
97 char *message; /* pending message from raw3215_irq */
98 int msg_dstat; /* dstat for pending message */
99 int msg_cstat; /* cstat for pending message */
100 int line_pos; /* position on the line (for tabs) */
101 char ubuffer[80]; /* copy_from_user buffer */
104 /* array of 3215 devices structures */
105 static struct raw3215_info *raw3215[NR_3215];
106 /* spinlock to protect the raw3215 array */
107 static DEFINE_SPINLOCK(raw3215_device_lock);
108 /* list of free request structures */
109 static struct raw3215_req *raw3215_freelist;
110 /* spinlock to protect free list */
111 static spinlock_t raw3215_freelist_lock;
113 static struct tty_driver *tty3215_driver;
116 * Get a request structure from the free list
118 static inline struct raw3215_req *
119 raw3215_alloc_req(void) {
120 struct raw3215_req *req;
123 spin_lock_irqsave(&raw3215_freelist_lock, flags);
124 req = raw3215_freelist;
125 raw3215_freelist = req->next;
126 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
131 * Put a request structure back to the free list
134 raw3215_free_req(struct raw3215_req *req) {
137 if (req->type == RAW3215_FREE)
138 return; /* don't free a free request */
139 req->type = RAW3215_FREE;
140 spin_lock_irqsave(&raw3215_freelist_lock, flags);
141 req->next = raw3215_freelist;
142 raw3215_freelist = req;
143 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
147 * Set up a read request that reads up to 160 byte from the 3215 device.
148 * If there is a queued read request it is used, but that shouldn't happen
149 * because a 3215 terminal won't accept a new read before the old one is
153 raw3215_mk_read_req(struct raw3215_info *raw)
155 struct raw3215_req *req;
158 /* there can only be ONE read request at a time */
159 req = raw->queued_read;
161 /* no queued read request, use new req structure */
162 req = raw3215_alloc_req();
163 req->type = RAW3215_READ;
165 raw->queued_read = req;
169 ccw->cmd_code = 0x0A; /* read inquiry */
170 ccw->flags = 0x20; /* ignore incorrect length */
172 ccw->cda = (__u32) __pa(raw->inbuf);
176 * Set up a write request with the information from the main structure.
177 * A ccw chain is created that writes as much as possible from the output
178 * buffer to the 3215 device. If a queued write exists it is replaced by
179 * the new, probably lengthened request.
182 raw3215_mk_write_req(struct raw3215_info *raw)
184 struct raw3215_req *req;
186 int len, count, ix, lines;
188 if (raw->count <= raw->written)
190 /* check if there is a queued write request */
191 req = raw->queued_write;
193 /* no queued write request, use new req structure */
194 req = raw3215_alloc_req();
195 req->type = RAW3215_WRITE;
197 raw->queued_write = req;
199 raw->written -= req->len;
203 req->start = (raw->head - raw->count + raw->written) &
204 (RAW3215_BUFFER_SIZE - 1);
206 * now we have to count newlines. We can at max accept
207 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
208 * a restriction in VM
212 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
213 if (raw->buffer[ix] == 0x15)
215 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
217 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
218 if (len > RAW3215_MAX_BYTES)
219 len = RAW3215_MAX_BYTES;
223 /* set the indication if we should try to enlarge this request */
224 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
229 ccw[-1].flags |= 0x40; /* use command chaining */
230 ccw->cmd_code = 0x01; /* write, auto carrier return */
231 ccw->flags = 0x20; /* ignore incorrect length ind. */
233 (__u32) __pa(raw->buffer + ix);
235 if (ix + count > RAW3215_BUFFER_SIZE)
236 count = RAW3215_BUFFER_SIZE - ix;
239 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
243 * Add a NOP to the channel program. 3215 devices are purely
244 * emulated and its much better to avoid the channel end
245 * interrupt in this case.
248 ccw[-1].flags |= 0x40; /* use command chaining */
249 ccw->cmd_code = 0x03; /* NOP */
256 * Start a read or a write request
259 raw3215_start_io(struct raw3215_info *raw)
261 struct raw3215_req *req;
264 req = raw->queued_read;
266 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
267 /* dequeue request */
268 raw->queued_read = NULL;
269 res = ccw_device_start(raw->cdev, req->ccws,
270 (unsigned long) req, 0, 0);
272 /* do_IO failed, put request back to queue */
273 raw->queued_read = req;
275 raw->flags |= RAW3215_WORKING;
278 req = raw->queued_write;
280 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
281 /* dequeue request */
282 raw->queued_write = NULL;
283 res = ccw_device_start(raw->cdev, req->ccws,
284 (unsigned long) req, 0, 0);
286 /* do_IO failed, put request back to queue */
287 raw->queued_write = req;
289 raw->flags |= RAW3215_WORKING;
295 * Function to start a delayed output after RAW3215_TIMEOUT seconds
298 raw3215_timeout(unsigned long __data)
300 struct raw3215_info *raw = (struct raw3215_info *) __data;
303 spin_lock_irqsave(raw->lock, flags);
304 if (raw->flags & RAW3215_TIMER_RUNS) {
305 del_timer(&raw->timer);
306 raw->flags &= ~RAW3215_TIMER_RUNS;
307 raw3215_mk_write_req(raw);
308 raw3215_start_io(raw);
310 spin_unlock_irqrestore(raw->lock, flags);
314 * Function to conditionally start an IO. A read is started immediately,
315 * a write is only started immediately if the flush flag is on or the
316 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
317 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
320 raw3215_try_io(struct raw3215_info *raw)
322 if (!(raw->flags & RAW3215_ACTIVE))
324 if (raw->queued_read != NULL)
325 raw3215_start_io(raw);
326 else if (raw->queued_write != NULL) {
327 if ((raw->queued_write->delayable == 0) ||
328 (raw->flags & RAW3215_FLUSHING)) {
329 /* execute write requests bigger than minimum size */
330 raw3215_start_io(raw);
331 if (raw->flags & RAW3215_TIMER_RUNS) {
332 del_timer(&raw->timer);
333 raw->flags &= ~RAW3215_TIMER_RUNS;
335 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
336 /* delay small writes */
337 init_timer(&raw->timer);
338 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
339 raw->timer.data = (unsigned long) raw;
340 raw->timer.function = raw3215_timeout;
341 add_timer(&raw->timer);
342 raw->flags |= RAW3215_TIMER_RUNS;
348 * The bottom half handler routine for 3215 devices. It tries to start
349 * the next IO and wakes up processes waiting on the tty.
352 raw3215_tasklet(void *data)
354 struct raw3215_info *raw;
355 struct tty_struct *tty;
358 raw = (struct raw3215_info *) data;
359 spin_lock_irqsave(raw->lock, flags);
360 raw3215_mk_write_req(raw);
362 spin_unlock_irqrestore(raw->lock, flags);
363 /* Check for pending message from raw3215_irq */
364 if (raw->message != NULL) {
365 printk(raw->message, raw->msg_dstat, raw->msg_cstat);
370 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
376 * Interrupt routine, called from common io layer
379 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
381 struct raw3215_info *raw;
382 struct raw3215_req *req;
383 struct tty_struct *tty;
387 raw = cdev->dev.driver_data;
388 req = (struct raw3215_req *) intparm;
389 cstat = irb->scsw.cstat;
390 dstat = irb->scsw.dstat;
392 raw->message = KERN_WARNING
393 "Got nonzero channel status in raw3215_irq "
394 "(dev sts 0x%2x, sch sts 0x%2x)";
395 raw->msg_dstat = dstat;
396 raw->msg_cstat = cstat;
397 tasklet_schedule(&raw->tasklet);
399 if (dstat & 0x01) { /* we got a unit exception */
400 dstat &= ~0x01; /* we can ignore it */
406 /* Attention interrupt, someone hit the enter key */
407 raw3215_mk_read_req(raw);
409 memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
410 tasklet_schedule(&raw->tasklet);
414 /* Channel end interrupt. */
415 if ((raw = req->info) == NULL)
416 return; /* That shouldn't happen ... */
417 if (req->type == RAW3215_READ) {
418 /* store residual count, then wait for device end */
419 req->residual = irb->scsw.count;
424 /* Device end interrupt. */
425 if ((raw = req->info) == NULL)
426 return; /* That shouldn't happen ... */
427 if (req->type == RAW3215_READ && raw->tty != NULL) {
431 count = 160 - req->residual;
432 if (MACHINE_IS_P390) {
433 slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE);
437 EBCASC(raw->inbuf, count);
438 cchar = ctrlchar_handle(raw->inbuf, count, tty);
439 switch (cchar & CTRLCHAR_MASK) {
444 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
445 tty_flip_buffer_push(raw->tty);
450 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
451 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
452 /* add the auto \n */
453 raw->inbuf[count] = '\n';
457 tty_insert_flip_string(tty, raw->inbuf, count);
458 tty_flip_buffer_push(raw->tty);
461 } else if (req->type == RAW3215_WRITE) {
462 raw->count -= req->len;
463 raw->written -= req->len;
465 raw->flags &= ~RAW3215_WORKING;
466 raw3215_free_req(req);
467 /* check for empty wait */
468 if (waitqueue_active(&raw->empty_wait) &&
469 raw->queued_write == NULL &&
470 raw->queued_read == NULL) {
471 wake_up_interruptible(&raw->empty_wait);
473 tasklet_schedule(&raw->tasklet);
476 /* Strange interrupt, I'll do my best to clean up */
477 if (req != NULL && req->type != RAW3215_FREE) {
478 if (req->type == RAW3215_WRITE) {
479 raw->count -= req->len;
480 raw->written -= req->len;
482 raw->flags &= ~RAW3215_WORKING;
483 raw3215_free_req(req);
485 raw->message = KERN_WARNING
486 "Spurious interrupt in in raw3215_irq "
487 "(dev sts 0x%2x, sch sts 0x%2x)";
488 raw->msg_dstat = dstat;
489 raw->msg_cstat = cstat;
490 tasklet_schedule(&raw->tasklet);
496 * Wait until length bytes are available int the output buffer.
497 * Has to be called with the s390irq lock held. Can be called
501 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
503 while (RAW3215_BUFFER_SIZE - raw->count < length) {
504 /* there might be a request pending */
505 raw->flags |= RAW3215_FLUSHING;
506 raw3215_mk_write_req(raw);
508 raw->flags &= ~RAW3215_FLUSHING;
509 #ifdef CONFIG_TN3215_CONSOLE
512 /* Enough room freed up ? */
513 if (RAW3215_BUFFER_SIZE - raw->count >= length)
515 /* there might be another cpu waiting for the lock */
516 spin_unlock(raw->lock);
518 spin_lock(raw->lock);
523 * String write routine for 3215 devices
526 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
532 spin_lock_irqsave(raw->lock, flags);
533 count = (length > RAW3215_BUFFER_SIZE) ?
534 RAW3215_BUFFER_SIZE : length;
537 raw3215_make_room(raw, count);
539 /* copy string to output buffer and convert it to EBCDIC */
541 c = min_t(int, count,
542 min(RAW3215_BUFFER_SIZE - raw->count,
543 RAW3215_BUFFER_SIZE - raw->head));
546 memcpy(raw->buffer + raw->head, str, c);
547 ASCEBC(raw->buffer + raw->head, c);
548 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
554 if (!(raw->flags & RAW3215_WORKING)) {
555 raw3215_mk_write_req(raw);
556 /* start or queue request */
559 spin_unlock_irqrestore(raw->lock, flags);
564 * Put character routine for 3215 devices
567 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
570 unsigned int length, i;
572 spin_lock_irqsave(raw->lock, flags);
574 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
575 raw->line_pos += length;
577 } else if (ch == '\n') {
584 raw3215_make_room(raw, length);
586 for (i = 0; i < length; i++) {
587 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
588 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
591 if (!(raw->flags & RAW3215_WORKING)) {
592 raw3215_mk_write_req(raw);
593 /* start or queue request */
596 spin_unlock_irqrestore(raw->lock, flags);
600 * Flush routine, it simply sets the flush flag and tries to start
604 raw3215_flush_buffer(struct raw3215_info *raw)
608 spin_lock_irqsave(raw->lock, flags);
609 if (raw->count > 0) {
610 raw->flags |= RAW3215_FLUSHING;
612 raw->flags &= ~RAW3215_FLUSHING;
614 spin_unlock_irqrestore(raw->lock, flags);
618 * Fire up a 3215 device.
621 raw3215_startup(struct raw3215_info *raw)
625 if (raw->flags & RAW3215_ACTIVE)
628 raw->flags |= RAW3215_ACTIVE;
629 spin_lock_irqsave(raw->lock, flags);
631 spin_unlock_irqrestore(raw->lock, flags);
637 * Shutdown a 3215 device.
640 raw3215_shutdown(struct raw3215_info *raw)
642 DECLARE_WAITQUEUE(wait, current);
645 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
647 /* Wait for outstanding requests, then free irq */
648 spin_lock_irqsave(raw->lock, flags);
649 if ((raw->flags & RAW3215_WORKING) ||
650 raw->queued_write != NULL ||
651 raw->queued_read != NULL) {
652 raw->flags |= RAW3215_CLOSING;
653 add_wait_queue(&raw->empty_wait, &wait);
654 set_current_state(TASK_INTERRUPTIBLE);
655 spin_unlock_irqrestore(raw->lock, flags);
657 spin_lock_irqsave(raw->lock, flags);
658 remove_wait_queue(&raw->empty_wait, &wait);
659 set_current_state(TASK_RUNNING);
660 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
662 spin_unlock_irqrestore(raw->lock, flags);
666 raw3215_probe (struct ccw_device *cdev)
668 struct raw3215_info *raw;
671 raw = kmalloc(sizeof(struct raw3215_info) +
672 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
676 spin_lock(&raw3215_device_lock);
677 for (line = 0; line < NR_3215; line++) {
678 if (!raw3215[line]) {
683 spin_unlock(&raw3215_device_lock);
684 if (line == NR_3215) {
690 raw->lock = get_ccwdev_lock(cdev);
691 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
692 memset(raw, 0, sizeof(struct raw3215_info));
693 raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE,
695 if (raw->buffer == NULL) {
696 spin_lock(&raw3215_device_lock);
698 spin_unlock(&raw3215_device_lock);
702 tasklet_init(&raw->tasklet,
703 (void (*)(unsigned long)) raw3215_tasklet,
704 (unsigned long) raw);
705 init_waitqueue_head(&raw->empty_wait);
707 cdev->dev.driver_data = raw;
708 cdev->handler = raw3215_irq;
714 raw3215_remove (struct ccw_device *cdev)
716 struct raw3215_info *raw;
718 ccw_device_set_offline(cdev);
719 raw = cdev->dev.driver_data;
721 cdev->dev.driver_data = NULL;
728 raw3215_set_online (struct ccw_device *cdev)
730 struct raw3215_info *raw;
732 raw = cdev->dev.driver_data;
736 return raw3215_startup(raw);
740 raw3215_set_offline (struct ccw_device *cdev)
742 struct raw3215_info *raw;
744 raw = cdev->dev.driver_data;
748 raw3215_shutdown(raw);
753 static struct ccw_device_id raw3215_id[] = {
754 { CCW_DEVICE(0x3215, 0) },
755 { /* end of list */ },
758 static struct ccw_driver raw3215_ccw_driver = {
760 .owner = THIS_MODULE,
762 .probe = &raw3215_probe,
763 .remove = &raw3215_remove,
764 .set_online = &raw3215_set_online,
765 .set_offline = &raw3215_set_offline,
768 #ifdef CONFIG_TN3215_CONSOLE
770 * Write a string to the 3215 console
773 con3215_write(struct console *co, const char *str, unsigned int count)
775 struct raw3215_info *raw;
780 raw = raw3215[0]; /* console 3215 is the first one */
782 for (i = 0; i < count; i++)
783 if (str[i] == '\t' || str[i] == '\n')
785 raw3215_write(raw, str, i);
789 raw3215_putchar(raw, *str);
796 static struct tty_driver *con3215_device(struct console *c, int *index)
799 return tty3215_driver;
803 * panic() calls console_unblank before the system enters a
804 * disabled, endless loop.
807 con3215_unblank(void)
809 struct raw3215_info *raw;
812 raw = raw3215[0]; /* console 3215 is the first one */
813 spin_lock_irqsave(raw->lock, flags);
814 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
815 spin_unlock_irqrestore(raw->lock, flags);
819 con3215_consetup(struct console *co, char *options)
825 * The console structure for the 3215 console
827 static struct console con3215 = {
829 .write = con3215_write,
830 .device = con3215_device,
831 .unblank = con3215_unblank,
832 .setup = con3215_consetup,
833 .flags = CON_PRINTBUFFER,
837 * 3215 console initialization code called from console_init().
838 * NOTE: This is called before kmalloc is available.
843 struct ccw_device *cdev;
844 struct raw3215_info *raw;
845 struct raw3215_req *req;
848 /* Check if 3215 is to be the console */
849 if (!CONSOLE_IS_3215)
852 /* Set the console mode for VM */
854 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
855 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
858 /* allocate 3215 request structures */
859 raw3215_freelist = NULL;
860 spin_lock_init(&raw3215_freelist_lock);
861 for (i = 0; i < NR_3215_REQ; i++) {
862 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
863 req->next = raw3215_freelist;
864 raw3215_freelist = req;
867 cdev = ccw_device_probe_console();
871 raw3215[0] = raw = (struct raw3215_info *)
872 alloc_bootmem_low(sizeof(struct raw3215_info));
873 memset(raw, 0, sizeof(struct raw3215_info));
874 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
875 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
877 raw->lock = get_ccwdev_lock(cdev);
878 cdev->dev.driver_data = raw;
879 cdev->handler = raw3215_irq;
881 raw->flags |= RAW3215_FIXED;
882 tasklet_init(&raw->tasklet,
883 (void (*)(unsigned long)) raw3215_tasklet,
884 (unsigned long) raw);
885 init_waitqueue_head(&raw->empty_wait);
887 /* Request the console irq */
888 if (raw3215_startup(raw) != 0) {
889 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
890 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
891 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
893 printk("Couldn't find a 3215 console device\n");
896 register_console(&con3215);
899 console_initcall(con3215_init);
905 * This routine is called whenever a 3215 tty is opened.
908 tty3215_open(struct tty_struct *tty, struct file * filp)
910 struct raw3215_info *raw;
914 if ((line < 0) || (line >= NR_3215))
921 tty->driver_data = raw;
924 tty->low_latency = 0; /* don't use bottom half for pushing chars */
926 * Start up 3215 device
928 retval = raw3215_startup(raw);
938 * This routine is called when the 3215 tty is closed. We wait
939 * for the remaining request to be completed. Then we clean up.
942 tty3215_close(struct tty_struct *tty, struct file * filp)
944 struct raw3215_info *raw;
946 raw = (struct raw3215_info *) tty->driver_data;
947 if (raw == NULL || tty->count > 1)
950 /* Shutdown the terminal */
951 raw3215_shutdown(raw);
957 * Returns the amount of free space in the output buffer.
960 tty3215_write_room(struct tty_struct *tty)
962 struct raw3215_info *raw;
964 raw = (struct raw3215_info *) tty->driver_data;
966 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
967 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
968 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
974 * String write routine for 3215 ttys
977 tty3215_write(struct tty_struct * tty,
978 const unsigned char *buf, int count)
980 struct raw3215_info *raw;
984 raw = (struct raw3215_info *) tty->driver_data;
985 raw3215_write(raw, buf, count);
990 * Put character routine for 3215 ttys
993 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
995 struct raw3215_info *raw;
999 raw = (struct raw3215_info *) tty->driver_data;
1000 raw3215_putchar(raw, ch);
1004 tty3215_flush_chars(struct tty_struct *tty)
1009 * Returns the number of characters in the output buffer
1012 tty3215_chars_in_buffer(struct tty_struct *tty)
1014 struct raw3215_info *raw;
1016 raw = (struct raw3215_info *) tty->driver_data;
1021 tty3215_flush_buffer(struct tty_struct *tty)
1023 struct raw3215_info *raw;
1025 raw = (struct raw3215_info *) tty->driver_data;
1026 raw3215_flush_buffer(raw);
1031 * Currently we don't have any io controls for 3215 ttys
1034 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1035 unsigned int cmd, unsigned long arg)
1037 if (tty->flags & (1 << TTY_IO_ERROR))
1042 return -ENOIOCTLCMD;
1048 * Disable reading from a 3215 tty
1051 tty3215_throttle(struct tty_struct * tty)
1053 struct raw3215_info *raw;
1055 raw = (struct raw3215_info *) tty->driver_data;
1056 raw->flags |= RAW3215_THROTTLED;
1060 * Enable reading from a 3215 tty
1063 tty3215_unthrottle(struct tty_struct * tty)
1065 struct raw3215_info *raw;
1066 unsigned long flags;
1068 raw = (struct raw3215_info *) tty->driver_data;
1069 if (raw->flags & RAW3215_THROTTLED) {
1070 spin_lock_irqsave(raw->lock, flags);
1071 raw->flags &= ~RAW3215_THROTTLED;
1072 raw3215_try_io(raw);
1073 spin_unlock_irqrestore(raw->lock, flags);
1078 * Disable writing to a 3215 tty
1081 tty3215_stop(struct tty_struct *tty)
1083 struct raw3215_info *raw;
1085 raw = (struct raw3215_info *) tty->driver_data;
1086 raw->flags |= RAW3215_STOPPED;
1090 * Enable writing to a 3215 tty
1093 tty3215_start(struct tty_struct *tty)
1095 struct raw3215_info *raw;
1096 unsigned long flags;
1098 raw = (struct raw3215_info *) tty->driver_data;
1099 if (raw->flags & RAW3215_STOPPED) {
1100 spin_lock_irqsave(raw->lock, flags);
1101 raw->flags &= ~RAW3215_STOPPED;
1102 raw3215_try_io(raw);
1103 spin_unlock_irqrestore(raw->lock, flags);
1107 static struct tty_operations tty3215_ops = {
1108 .open = tty3215_open,
1109 .close = tty3215_close,
1110 .write = tty3215_write,
1111 .put_char = tty3215_put_char,
1112 .flush_chars = tty3215_flush_chars,
1113 .write_room = tty3215_write_room,
1114 .chars_in_buffer = tty3215_chars_in_buffer,
1115 .flush_buffer = tty3215_flush_buffer,
1116 .ioctl = tty3215_ioctl,
1117 .throttle = tty3215_throttle,
1118 .unthrottle = tty3215_unthrottle,
1119 .stop = tty3215_stop,
1120 .start = tty3215_start,
1124 * 3215 tty registration code called from tty_init().
1125 * Most kernel services (incl. kmalloc) are available at this poimt.
1130 struct tty_driver *driver;
1133 if (!CONSOLE_IS_3215)
1136 driver = alloc_tty_driver(NR_3215);
1140 ret = ccw_driver_register(&raw3215_ccw_driver);
1142 put_tty_driver(driver);
1146 * Initialize the tty_driver structure
1147 * Entries in tty3215_driver that are NOT initialized:
1148 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1151 driver->owner = THIS_MODULE;
1152 driver->driver_name = "tty3215";
1153 driver->name = "ttyS";
1154 driver->major = TTY_MAJOR;
1155 driver->minor_start = 64;
1156 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1157 driver->subtype = SYSTEM_TYPE_TTY;
1158 driver->init_termios = tty_std_termios;
1159 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1160 driver->init_termios.c_oflag = ONLCR | XTABS;
1161 driver->init_termios.c_lflag = ISIG;
1162 driver->flags = TTY_DRIVER_REAL_RAW;
1163 tty_set_operations(driver, &tty3215_ops);
1164 ret = tty_register_driver(driver);
1166 printk("Couldn't register tty3215 driver\n");
1167 put_tty_driver(driver);
1170 tty3215_driver = driver;
1177 tty_unregister_driver(tty3215_driver);
1178 put_tty_driver(tty3215_driver);
1179 ccw_driver_unregister(&raw3215_ccw_driver);
1182 module_init(tty3215_init);
1183 module_exit(tty3215_exit);