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/vt_kern.h>
20 #include <linux/init.h>
21 #include <linux/console.h>
22 #include <linux/interrupt.h>
24 #include <linux/slab.h>
25 #include <linux/bootmem.h>
27 #include <asm/ccwdev.h>
30 #include <asm/ebcdic.h>
31 #include <asm/uaccess.h>
32 #include <asm/delay.h>
33 #include <asm/cpcmd.h>
34 #include <asm/setup.h>
39 #define NR_3215_REQ (4*NR_3215)
40 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
41 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
42 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
43 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
44 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
45 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
46 #define RAW3215_NR_CCWS 3
47 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
49 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
50 #define RAW3215_ACTIVE 2 /* set if the device is in use */
51 #define RAW3215_WORKING 4 /* set if a request is being worked on */
52 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
53 #define RAW3215_STOPPED 16 /* set if writing is disabled */
54 #define RAW3215_CLOSING 32 /* set while in close process */
55 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
56 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
58 #define TAB_STOP_SIZE 8 /* tab stop size */
61 * Request types for a 3215 device
64 RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
68 * Request structure for a 3215 device
71 enum raw3215_type type; /* type of the request */
72 int start, len; /* start index & len in output buffer */
73 int delayable; /* indication to wait for more data */
74 int residual; /* residual count for read request */
75 struct ccw1 ccws[RAW3215_NR_CCWS]; /* space for the channel program */
76 struct raw3215_info *info; /* pointer to main structure */
77 struct raw3215_req *next; /* pointer to next request */
78 } __attribute__ ((aligned(8)));
81 struct ccw_device *cdev; /* device for tty driver */
82 spinlock_t *lock; /* pointer to irq lock */
83 int flags; /* state flags */
84 char *buffer; /* pointer to output buffer */
85 char *inbuf; /* pointer to input buffer */
86 int head; /* first free byte in output buffer */
87 int count; /* number of bytes in output buffer */
88 int written; /* number of bytes in write requests */
89 struct tty_struct *tty; /* pointer to tty structure if present */
90 struct tasklet_struct tasklet;
91 struct raw3215_req *queued_read; /* pointer to queued read requests */
92 struct raw3215_req *queued_write;/* pointer to queued write requests */
93 wait_queue_head_t empty_wait; /* wait queue for flushing */
94 struct timer_list timer; /* timer for delayed output */
95 char *message; /* pending message from raw3215_irq */
96 int msg_dstat; /* dstat for pending message */
97 int msg_cstat; /* cstat for pending message */
98 int line_pos; /* position on the line (for tabs) */
99 char ubuffer[80]; /* copy_from_user buffer */
102 /* array of 3215 devices structures */
103 static struct raw3215_info *raw3215[NR_3215];
104 /* spinlock to protect the raw3215 array */
105 static DEFINE_SPINLOCK(raw3215_device_lock);
106 /* list of free request structures */
107 static struct raw3215_req *raw3215_freelist;
108 /* spinlock to protect free list */
109 static spinlock_t raw3215_freelist_lock;
111 static struct tty_driver *tty3215_driver;
114 * Get a request structure from the free list
116 static inline struct raw3215_req *
117 raw3215_alloc_req(void) {
118 struct raw3215_req *req;
121 spin_lock_irqsave(&raw3215_freelist_lock, flags);
122 req = raw3215_freelist;
123 raw3215_freelist = req->next;
124 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
129 * Put a request structure back to the free list
132 raw3215_free_req(struct raw3215_req *req) {
135 if (req->type == RAW3215_FREE)
136 return; /* don't free a free request */
137 req->type = RAW3215_FREE;
138 spin_lock_irqsave(&raw3215_freelist_lock, flags);
139 req->next = raw3215_freelist;
140 raw3215_freelist = req;
141 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
145 * Set up a read request that reads up to 160 byte from the 3215 device.
146 * If there is a queued read request it is used, but that shouldn't happen
147 * because a 3215 terminal won't accept a new read before the old one is
151 raw3215_mk_read_req(struct raw3215_info *raw)
153 struct raw3215_req *req;
156 /* there can only be ONE read request at a time */
157 req = raw->queued_read;
159 /* no queued read request, use new req structure */
160 req = raw3215_alloc_req();
161 req->type = RAW3215_READ;
163 raw->queued_read = req;
167 ccw->cmd_code = 0x0A; /* read inquiry */
168 ccw->flags = 0x20; /* ignore incorrect length */
170 ccw->cda = (__u32) __pa(raw->inbuf);
174 * Set up a write request with the information from the main structure.
175 * A ccw chain is created that writes as much as possible from the output
176 * buffer to the 3215 device. If a queued write exists it is replaced by
177 * the new, probably lengthened request.
180 raw3215_mk_write_req(struct raw3215_info *raw)
182 struct raw3215_req *req;
184 int len, count, ix, lines;
186 if (raw->count <= raw->written)
188 /* check if there is a queued write request */
189 req = raw->queued_write;
191 /* no queued write request, use new req structure */
192 req = raw3215_alloc_req();
193 req->type = RAW3215_WRITE;
195 raw->queued_write = req;
197 raw->written -= req->len;
201 req->start = (raw->head - raw->count + raw->written) &
202 (RAW3215_BUFFER_SIZE - 1);
204 * now we have to count newlines. We can at max accept
205 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
206 * a restriction in VM
210 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
211 if (raw->buffer[ix] == 0x15)
213 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
215 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
216 if (len > RAW3215_MAX_BYTES)
217 len = RAW3215_MAX_BYTES;
221 /* set the indication if we should try to enlarge this request */
222 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
227 ccw[-1].flags |= 0x40; /* use command chaining */
228 ccw->cmd_code = 0x01; /* write, auto carrier return */
229 ccw->flags = 0x20; /* ignore incorrect length ind. */
231 (__u32) __pa(raw->buffer + ix);
233 if (ix + count > RAW3215_BUFFER_SIZE)
234 count = RAW3215_BUFFER_SIZE - ix;
237 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
241 * Add a NOP to the channel program. 3215 devices are purely
242 * emulated and its much better to avoid the channel end
243 * interrupt in this case.
246 ccw[-1].flags |= 0x40; /* use command chaining */
247 ccw->cmd_code = 0x03; /* NOP */
254 * Start a read or a write request
257 raw3215_start_io(struct raw3215_info *raw)
259 struct raw3215_req *req;
262 req = raw->queued_read;
264 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
265 /* dequeue request */
266 raw->queued_read = NULL;
267 res = ccw_device_start(raw->cdev, req->ccws,
268 (unsigned long) req, 0, 0);
270 /* do_IO failed, put request back to queue */
271 raw->queued_read = req;
273 raw->flags |= RAW3215_WORKING;
276 req = raw->queued_write;
278 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
279 /* dequeue request */
280 raw->queued_write = NULL;
281 res = ccw_device_start(raw->cdev, req->ccws,
282 (unsigned long) req, 0, 0);
284 /* do_IO failed, put request back to queue */
285 raw->queued_write = req;
287 raw->flags |= RAW3215_WORKING;
293 * Function to start a delayed output after RAW3215_TIMEOUT seconds
296 raw3215_timeout(unsigned long __data)
298 struct raw3215_info *raw = (struct raw3215_info *) __data;
301 spin_lock_irqsave(raw->lock, flags);
302 if (raw->flags & RAW3215_TIMER_RUNS) {
303 del_timer(&raw->timer);
304 raw->flags &= ~RAW3215_TIMER_RUNS;
305 raw3215_mk_write_req(raw);
306 raw3215_start_io(raw);
308 spin_unlock_irqrestore(raw->lock, flags);
312 * Function to conditionally start an IO. A read is started immediately,
313 * a write is only started immediately if the flush flag is on or the
314 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
315 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
318 raw3215_try_io(struct raw3215_info *raw)
320 if (!(raw->flags & RAW3215_ACTIVE))
322 if (raw->queued_read != NULL)
323 raw3215_start_io(raw);
324 else if (raw->queued_write != NULL) {
325 if ((raw->queued_write->delayable == 0) ||
326 (raw->flags & RAW3215_FLUSHING)) {
327 /* execute write requests bigger than minimum size */
328 raw3215_start_io(raw);
329 if (raw->flags & RAW3215_TIMER_RUNS) {
330 del_timer(&raw->timer);
331 raw->flags &= ~RAW3215_TIMER_RUNS;
333 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
334 /* delay small writes */
335 init_timer(&raw->timer);
336 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
337 raw->timer.data = (unsigned long) raw;
338 raw->timer.function = raw3215_timeout;
339 add_timer(&raw->timer);
340 raw->flags |= RAW3215_TIMER_RUNS;
346 * The bottom half handler routine for 3215 devices. It tries to start
347 * the next IO and wakes up processes waiting on the tty.
350 raw3215_tasklet(void *data)
352 struct raw3215_info *raw;
353 struct tty_struct *tty;
356 raw = (struct raw3215_info *) data;
357 spin_lock_irqsave(raw->lock, flags);
358 raw3215_mk_write_req(raw);
360 spin_unlock_irqrestore(raw->lock, flags);
361 /* Check for pending message from raw3215_irq */
362 if (raw->message != NULL) {
363 printk(raw->message, raw->msg_dstat, raw->msg_cstat);
368 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
374 * Interrupt routine, called from common io layer
377 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
379 struct raw3215_info *raw;
380 struct raw3215_req *req;
381 struct tty_struct *tty;
385 raw = cdev->dev.driver_data;
386 req = (struct raw3215_req *) intparm;
387 cstat = irb->scsw.cstat;
388 dstat = irb->scsw.dstat;
390 raw->message = KERN_WARNING
391 "Got nonzero channel status in raw3215_irq "
392 "(dev sts 0x%2x, sch sts 0x%2x)";
393 raw->msg_dstat = dstat;
394 raw->msg_cstat = cstat;
395 tasklet_schedule(&raw->tasklet);
397 if (dstat & 0x01) { /* we got a unit exception */
398 dstat &= ~0x01; /* we can ignore it */
404 /* Attention interrupt, someone hit the enter key */
405 raw3215_mk_read_req(raw);
407 memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
408 tasklet_schedule(&raw->tasklet);
412 /* Channel end interrupt. */
413 if ((raw = req->info) == NULL)
414 return; /* That shouldn't happen ... */
415 if (req->type == RAW3215_READ) {
416 /* store residual count, then wait for device end */
417 req->residual = irb->scsw.count;
422 /* Device end interrupt. */
423 if ((raw = req->info) == NULL)
424 return; /* That shouldn't happen ... */
425 if (req->type == RAW3215_READ && raw->tty != NULL) {
429 count = 160 - req->residual;
430 if (MACHINE_IS_P390) {
431 slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE);
435 if (count >= TTY_FLIPBUF_SIZE - tty->flip.count)
436 count = TTY_FLIPBUF_SIZE - tty->flip.count - 1;
437 EBCASC(raw->inbuf, count);
438 cchar = ctrlchar_handle(raw->inbuf, count, tty);
439 switch (cchar & CTRLCHAR_MASK) {
445 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
446 *tty->flip.char_buf_ptr++ = cchar;
447 tty_flip_buffer_push(raw->tty);
451 memcpy(tty->flip.char_buf_ptr,
454 (strncmp(raw->inbuf+count-2, "^n", 2) &&
455 strncmp(raw->inbuf+count-2, "\252n", 2)) ) {
456 /* don't add the auto \n */
457 tty->flip.char_buf_ptr[count] = '\n';
458 memset(tty->flip.flag_buf_ptr,
459 TTY_NORMAL, count + 1);
463 tty->flip.char_buf_ptr += count;
464 tty->flip.flag_buf_ptr += count;
465 tty->flip.count += count;
466 tty_flip_buffer_push(raw->tty);
469 } else if (req->type == RAW3215_WRITE) {
470 raw->count -= req->len;
471 raw->written -= req->len;
473 raw->flags &= ~RAW3215_WORKING;
474 raw3215_free_req(req);
475 /* check for empty wait */
476 if (waitqueue_active(&raw->empty_wait) &&
477 raw->queued_write == NULL &&
478 raw->queued_read == NULL) {
479 wake_up_interruptible(&raw->empty_wait);
481 tasklet_schedule(&raw->tasklet);
484 /* Strange interrupt, I'll do my best to clean up */
485 if (req != NULL && req->type != RAW3215_FREE) {
486 if (req->type == RAW3215_WRITE) {
487 raw->count -= req->len;
488 raw->written -= req->len;
490 raw->flags &= ~RAW3215_WORKING;
491 raw3215_free_req(req);
493 raw->message = KERN_WARNING
494 "Spurious interrupt in in raw3215_irq "
495 "(dev sts 0x%2x, sch sts 0x%2x)";
496 raw->msg_dstat = dstat;
497 raw->msg_cstat = cstat;
498 tasklet_schedule(&raw->tasklet);
504 * Wait until length bytes are available int the output buffer.
505 * Has to be called with the s390irq lock held. Can be called
509 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
511 while (RAW3215_BUFFER_SIZE - raw->count < length) {
512 /* there might be a request pending */
513 raw->flags |= RAW3215_FLUSHING;
514 raw3215_mk_write_req(raw);
516 raw->flags &= ~RAW3215_FLUSHING;
517 #ifdef CONFIG_TN3215_CONSOLE
520 /* Enough room freed up ? */
521 if (RAW3215_BUFFER_SIZE - raw->count >= length)
523 /* there might be another cpu waiting for the lock */
524 spin_unlock(raw->lock);
526 spin_lock(raw->lock);
531 * String write routine for 3215 devices
534 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
540 spin_lock_irqsave(raw->lock, flags);
541 count = (length > RAW3215_BUFFER_SIZE) ?
542 RAW3215_BUFFER_SIZE : length;
545 raw3215_make_room(raw, count);
547 /* copy string to output buffer and convert it to EBCDIC */
549 c = min_t(int, count,
550 min(RAW3215_BUFFER_SIZE - raw->count,
551 RAW3215_BUFFER_SIZE - raw->head));
554 memcpy(raw->buffer + raw->head, str, c);
555 ASCEBC(raw->buffer + raw->head, c);
556 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
562 if (!(raw->flags & RAW3215_WORKING)) {
563 raw3215_mk_write_req(raw);
564 /* start or queue request */
567 spin_unlock_irqrestore(raw->lock, flags);
572 * Put character routine for 3215 devices
575 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
578 unsigned int length, i;
580 spin_lock_irqsave(raw->lock, flags);
582 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
583 raw->line_pos += length;
585 } else if (ch == '\n') {
592 raw3215_make_room(raw, length);
594 for (i = 0; i < length; i++) {
595 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
596 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
599 if (!(raw->flags & RAW3215_WORKING)) {
600 raw3215_mk_write_req(raw);
601 /* start or queue request */
604 spin_unlock_irqrestore(raw->lock, flags);
608 * Flush routine, it simply sets the flush flag and tries to start
612 raw3215_flush_buffer(struct raw3215_info *raw)
616 spin_lock_irqsave(raw->lock, flags);
617 if (raw->count > 0) {
618 raw->flags |= RAW3215_FLUSHING;
620 raw->flags &= ~RAW3215_FLUSHING;
622 spin_unlock_irqrestore(raw->lock, flags);
626 * Fire up a 3215 device.
629 raw3215_startup(struct raw3215_info *raw)
633 if (raw->flags & RAW3215_ACTIVE)
636 raw->flags |= RAW3215_ACTIVE;
637 spin_lock_irqsave(raw->lock, flags);
639 spin_unlock_irqrestore(raw->lock, flags);
645 * Shutdown a 3215 device.
648 raw3215_shutdown(struct raw3215_info *raw)
650 DECLARE_WAITQUEUE(wait, current);
653 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
655 /* Wait for outstanding requests, then free irq */
656 spin_lock_irqsave(raw->lock, flags);
657 if ((raw->flags & RAW3215_WORKING) ||
658 raw->queued_write != NULL ||
659 raw->queued_read != NULL) {
660 raw->flags |= RAW3215_CLOSING;
661 add_wait_queue(&raw->empty_wait, &wait);
662 set_current_state(TASK_INTERRUPTIBLE);
663 spin_unlock_irqrestore(raw->lock, flags);
665 spin_lock_irqsave(raw->lock, flags);
666 remove_wait_queue(&raw->empty_wait, &wait);
667 set_current_state(TASK_RUNNING);
668 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
670 spin_unlock_irqrestore(raw->lock, flags);
674 raw3215_probe (struct ccw_device *cdev)
676 struct raw3215_info *raw;
679 raw = kmalloc(sizeof(struct raw3215_info) +
680 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
684 spin_lock(&raw3215_device_lock);
685 for (line = 0; line < NR_3215; line++) {
686 if (!raw3215[line]) {
691 spin_unlock(&raw3215_device_lock);
692 if (line == NR_3215) {
698 raw->lock = get_ccwdev_lock(cdev);
699 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
700 memset(raw, 0, sizeof(struct raw3215_info));
701 raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE,
703 if (raw->buffer == NULL) {
704 spin_lock(&raw3215_device_lock);
706 spin_unlock(&raw3215_device_lock);
710 tasklet_init(&raw->tasklet,
711 (void (*)(unsigned long)) raw3215_tasklet,
712 (unsigned long) raw);
713 init_waitqueue_head(&raw->empty_wait);
715 cdev->dev.driver_data = raw;
716 cdev->handler = raw3215_irq;
722 raw3215_remove (struct ccw_device *cdev)
724 struct raw3215_info *raw;
726 ccw_device_set_offline(cdev);
727 raw = cdev->dev.driver_data;
729 cdev->dev.driver_data = NULL;
737 raw3215_set_online (struct ccw_device *cdev)
739 struct raw3215_info *raw;
741 raw = cdev->dev.driver_data;
745 return raw3215_startup(raw);
749 raw3215_set_offline (struct ccw_device *cdev)
751 struct raw3215_info *raw;
753 raw = cdev->dev.driver_data;
757 raw3215_shutdown(raw);
762 static struct ccw_device_id raw3215_id[] = {
763 { CCW_DEVICE(0x3215, 0) },
764 { /* end of list */ },
767 static struct ccw_driver raw3215_ccw_driver = {
769 .owner = THIS_MODULE,
771 .probe = &raw3215_probe,
772 .remove = &raw3215_remove,
773 .set_online = &raw3215_set_online,
774 .set_offline = &raw3215_set_offline,
777 #ifdef CONFIG_TN3215_CONSOLE
779 * Write a string to the 3215 console
782 con3215_write(struct console *co, const char *str, unsigned int count)
784 struct raw3215_info *raw;
789 raw = raw3215[0]; /* console 3215 is the first one */
791 for (i = 0; i < count; i++)
792 if (str[i] == '\t' || str[i] == '\n')
794 raw3215_write(raw, str, i);
798 raw3215_putchar(raw, *str);
805 static struct tty_driver *con3215_device(struct console *c, int *index)
808 return tty3215_driver;
812 * panic() calls console_unblank before the system enters a
813 * disabled, endless loop.
816 con3215_unblank(void)
818 struct raw3215_info *raw;
821 raw = raw3215[0]; /* console 3215 is the first one */
822 spin_lock_irqsave(raw->lock, flags);
823 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
824 spin_unlock_irqrestore(raw->lock, flags);
828 con3215_consetup(struct console *co, char *options)
834 * The console structure for the 3215 console
836 static struct console con3215 = {
838 .write = con3215_write,
839 .device = con3215_device,
840 .unblank = con3215_unblank,
841 .setup = con3215_consetup,
842 .flags = CON_PRINTBUFFER,
846 * 3215 console initialization code called from console_init().
847 * NOTE: This is called before kmalloc is available.
852 struct ccw_device *cdev;
853 struct raw3215_info *raw;
854 struct raw3215_req *req;
857 /* Check if 3215 is to be the console */
858 if (!CONSOLE_IS_3215)
861 /* Set the console mode for VM */
863 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
864 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
867 /* allocate 3215 request structures */
868 raw3215_freelist = NULL;
869 spin_lock_init(&raw3215_freelist_lock);
870 for (i = 0; i < NR_3215_REQ; i++) {
871 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
872 req->next = raw3215_freelist;
873 raw3215_freelist = req;
876 cdev = ccw_device_probe_console();
880 raw3215[0] = raw = (struct raw3215_info *)
881 alloc_bootmem_low(sizeof(struct raw3215_info));
882 memset(raw, 0, sizeof(struct raw3215_info));
883 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
884 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
886 raw->lock = get_ccwdev_lock(cdev);
887 cdev->dev.driver_data = raw;
888 cdev->handler = raw3215_irq;
890 raw->flags |= RAW3215_FIXED;
891 tasklet_init(&raw->tasklet,
892 (void (*)(unsigned long)) raw3215_tasklet,
893 (unsigned long) raw);
894 init_waitqueue_head(&raw->empty_wait);
896 /* Request the console irq */
897 if (raw3215_startup(raw) != 0) {
898 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
899 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
900 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
902 printk("Couldn't find a 3215 console device\n");
905 register_console(&con3215);
908 console_initcall(con3215_init);
914 * This routine is called whenever a 3215 tty is opened.
917 tty3215_open(struct tty_struct *tty, struct file * filp)
919 struct raw3215_info *raw;
923 if ((line < 0) || (line >= NR_3215))
930 tty->driver_data = raw;
933 tty->low_latency = 0; /* don't use bottom half for pushing chars */
935 * Start up 3215 device
937 retval = raw3215_startup(raw);
947 * This routine is called when the 3215 tty is closed. We wait
948 * for the remaining request to be completed. Then we clean up.
951 tty3215_close(struct tty_struct *tty, struct file * filp)
953 struct raw3215_info *raw;
955 raw = (struct raw3215_info *) tty->driver_data;
956 if (raw == NULL || tty->count > 1)
959 /* Shutdown the terminal */
960 raw3215_shutdown(raw);
966 * Returns the amount of free space in the output buffer.
969 tty3215_write_room(struct tty_struct *tty)
971 struct raw3215_info *raw;
973 raw = (struct raw3215_info *) tty->driver_data;
975 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
976 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
977 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
983 * String write routine for 3215 ttys
986 tty3215_write(struct tty_struct * tty,
987 const unsigned char *buf, int count)
989 struct raw3215_info *raw;
993 raw = (struct raw3215_info *) tty->driver_data;
994 raw3215_write(raw, buf, count);
999 * Put character routine for 3215 ttys
1002 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
1004 struct raw3215_info *raw;
1008 raw = (struct raw3215_info *) tty->driver_data;
1009 raw3215_putchar(raw, ch);
1013 tty3215_flush_chars(struct tty_struct *tty)
1018 * Returns the number of characters in the output buffer
1021 tty3215_chars_in_buffer(struct tty_struct *tty)
1023 struct raw3215_info *raw;
1025 raw = (struct raw3215_info *) tty->driver_data;
1030 tty3215_flush_buffer(struct tty_struct *tty)
1032 struct raw3215_info *raw;
1034 raw = (struct raw3215_info *) tty->driver_data;
1035 raw3215_flush_buffer(raw);
1040 * Currently we don't have any io controls for 3215 ttys
1043 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1044 unsigned int cmd, unsigned long arg)
1046 if (tty->flags & (1 << TTY_IO_ERROR))
1051 return -ENOIOCTLCMD;
1057 * Disable reading from a 3215 tty
1060 tty3215_throttle(struct tty_struct * tty)
1062 struct raw3215_info *raw;
1064 raw = (struct raw3215_info *) tty->driver_data;
1065 raw->flags |= RAW3215_THROTTLED;
1069 * Enable reading from a 3215 tty
1072 tty3215_unthrottle(struct tty_struct * tty)
1074 struct raw3215_info *raw;
1075 unsigned long flags;
1077 raw = (struct raw3215_info *) tty->driver_data;
1078 if (raw->flags & RAW3215_THROTTLED) {
1079 spin_lock_irqsave(raw->lock, flags);
1080 raw->flags &= ~RAW3215_THROTTLED;
1081 raw3215_try_io(raw);
1082 spin_unlock_irqrestore(raw->lock, flags);
1087 * Disable writing to a 3215 tty
1090 tty3215_stop(struct tty_struct *tty)
1092 struct raw3215_info *raw;
1094 raw = (struct raw3215_info *) tty->driver_data;
1095 raw->flags |= RAW3215_STOPPED;
1099 * Enable writing to a 3215 tty
1102 tty3215_start(struct tty_struct *tty)
1104 struct raw3215_info *raw;
1105 unsigned long flags;
1107 raw = (struct raw3215_info *) tty->driver_data;
1108 if (raw->flags & RAW3215_STOPPED) {
1109 spin_lock_irqsave(raw->lock, flags);
1110 raw->flags &= ~RAW3215_STOPPED;
1111 raw3215_try_io(raw);
1112 spin_unlock_irqrestore(raw->lock, flags);
1116 static struct tty_operations tty3215_ops = {
1117 .open = tty3215_open,
1118 .close = tty3215_close,
1119 .write = tty3215_write,
1120 .put_char = tty3215_put_char,
1121 .flush_chars = tty3215_flush_chars,
1122 .write_room = tty3215_write_room,
1123 .chars_in_buffer = tty3215_chars_in_buffer,
1124 .flush_buffer = tty3215_flush_buffer,
1125 .ioctl = tty3215_ioctl,
1126 .throttle = tty3215_throttle,
1127 .unthrottle = tty3215_unthrottle,
1128 .stop = tty3215_stop,
1129 .start = tty3215_start,
1133 * 3215 tty registration code called from tty_init().
1134 * Most kernel services (incl. kmalloc) are available at this poimt.
1139 struct tty_driver *driver;
1142 if (!CONSOLE_IS_3215)
1145 driver = alloc_tty_driver(NR_3215);
1149 ret = ccw_driver_register(&raw3215_ccw_driver);
1151 put_tty_driver(driver);
1155 * Initialize the tty_driver structure
1156 * Entries in tty3215_driver that are NOT initialized:
1157 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1160 driver->owner = THIS_MODULE;
1161 driver->driver_name = "tty3215";
1162 driver->name = "ttyS";
1163 driver->major = TTY_MAJOR;
1164 driver->minor_start = 64;
1165 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1166 driver->subtype = SYSTEM_TYPE_TTY;
1167 driver->init_termios = tty_std_termios;
1168 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1169 driver->init_termios.c_oflag = ONLCR | XTABS;
1170 driver->init_termios.c_lflag = ISIG;
1171 driver->flags = TTY_DRIVER_REAL_RAW;
1172 tty_set_operations(driver, &tty3215_ops);
1173 ret = tty_register_driver(driver);
1175 printk("Couldn't register tty3215 driver\n");
1176 put_tty_driver(driver);
1179 tty3215_driver = driver;
1186 tty_unregister_driver(tty3215_driver);
1187 put_tty_driver(tty3215_driver);
1188 ccw_driver_unregister(&raw3215_ccw_driver);
1191 module_init(tty3215_init);
1192 module_exit(tty3215_exit);