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/module.h>
15 #include <linux/types.h>
16 #include <linux/kdev_t.h>
17 #include <linux/tty.h>
18 #include <linux/tty_flip.h>
19 #include <linux/vt_kern.h>
20 #include <linux/init.h>
21 #include <linux/console.h>
22 #include <linux/interrupt.h>
23 #include <linux/err.h>
25 #include <linux/slab.h>
26 #include <linux/bootmem.h>
28 #include <asm/ccwdev.h>
31 #include <asm/ebcdic.h>
32 #include <asm/uaccess.h>
33 #include <asm/delay.h>
34 #include <asm/cpcmd.h>
35 #include <asm/setup.h>
40 #define NR_3215_REQ (4*NR_3215)
41 #define RAW3215_BUFFER_SIZE 65536 /* output buffer size */
42 #define RAW3215_INBUF_SIZE 256 /* input buffer size */
43 #define RAW3215_MIN_SPACE 128 /* minimum free space for wakeup */
44 #define RAW3215_MIN_WRITE 1024 /* min. length for immediate output */
45 #define RAW3215_MAX_BYTES 3968 /* max. bytes to write with one ssch */
46 #define RAW3215_MAX_NEWLINE 50 /* max. lines to write with one ssch */
47 #define RAW3215_NR_CCWS 3
48 #define RAW3215_TIMEOUT HZ/10 /* time for delayed output */
50 #define RAW3215_FIXED 1 /* 3215 console device is not be freed */
51 #define RAW3215_ACTIVE 2 /* set if the device is in use */
52 #define RAW3215_WORKING 4 /* set if a request is being worked on */
53 #define RAW3215_THROTTLED 8 /* set if reading is disabled */
54 #define RAW3215_STOPPED 16 /* set if writing is disabled */
55 #define RAW3215_CLOSING 32 /* set while in close process */
56 #define RAW3215_TIMER_RUNS 64 /* set if the output delay timer is on */
57 #define RAW3215_FLUSHING 128 /* set to flush buffer (no delay) */
59 #define TAB_STOP_SIZE 8 /* tab stop size */
62 * Request types for a 3215 device
65 RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
69 * Request structure for a 3215 device
72 enum raw3215_type type; /* type of the request */
73 int start, len; /* start index & len in output buffer */
74 int delayable; /* indication to wait for more data */
75 int residual; /* residual count for read request */
76 struct ccw1 ccws[RAW3215_NR_CCWS]; /* space for the channel program */
77 struct raw3215_info *info; /* pointer to main structure */
78 struct raw3215_req *next; /* pointer to next request */
79 } __attribute__ ((aligned(8)));
82 struct ccw_device *cdev; /* device for tty driver */
83 spinlock_t *lock; /* pointer to irq lock */
84 int flags; /* state flags */
85 char *buffer; /* pointer to output buffer */
86 char *inbuf; /* pointer to input buffer */
87 int head; /* first free byte in output buffer */
88 int count; /* number of bytes in output buffer */
89 int written; /* number of bytes in write requests */
90 struct tty_struct *tty; /* pointer to tty structure if present */
91 struct tasklet_struct tasklet;
92 struct raw3215_req *queued_read; /* pointer to queued read requests */
93 struct raw3215_req *queued_write;/* pointer to queued write requests */
94 wait_queue_head_t empty_wait; /* wait queue for flushing */
95 struct timer_list timer; /* timer for delayed output */
96 int line_pos; /* position on the line (for tabs) */
97 char ubuffer[80]; /* copy_from_user buffer */
100 /* array of 3215 devices structures */
101 static struct raw3215_info *raw3215[NR_3215];
102 /* spinlock to protect the raw3215 array */
103 static DEFINE_SPINLOCK(raw3215_device_lock);
104 /* list of free request structures */
105 static struct raw3215_req *raw3215_freelist;
106 /* spinlock to protect free list */
107 static spinlock_t raw3215_freelist_lock;
109 static struct tty_driver *tty3215_driver;
112 * Get a request structure from the free list
114 static inline struct raw3215_req *
115 raw3215_alloc_req(void) {
116 struct raw3215_req *req;
119 spin_lock_irqsave(&raw3215_freelist_lock, flags);
120 req = raw3215_freelist;
121 raw3215_freelist = req->next;
122 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
127 * Put a request structure back to the free list
130 raw3215_free_req(struct raw3215_req *req) {
133 if (req->type == RAW3215_FREE)
134 return; /* don't free a free request */
135 req->type = RAW3215_FREE;
136 spin_lock_irqsave(&raw3215_freelist_lock, flags);
137 req->next = raw3215_freelist;
138 raw3215_freelist = req;
139 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
143 * Set up a read request that reads up to 160 byte from the 3215 device.
144 * If there is a queued read request it is used, but that shouldn't happen
145 * because a 3215 terminal won't accept a new read before the old one is
149 raw3215_mk_read_req(struct raw3215_info *raw)
151 struct raw3215_req *req;
154 /* there can only be ONE read request at a time */
155 req = raw->queued_read;
157 /* no queued read request, use new req structure */
158 req = raw3215_alloc_req();
159 req->type = RAW3215_READ;
161 raw->queued_read = req;
165 ccw->cmd_code = 0x0A; /* read inquiry */
166 ccw->flags = 0x20; /* ignore incorrect length */
168 ccw->cda = (__u32) __pa(raw->inbuf);
172 * Set up a write request with the information from the main structure.
173 * A ccw chain is created that writes as much as possible from the output
174 * buffer to the 3215 device. If a queued write exists it is replaced by
175 * the new, probably lengthened request.
178 raw3215_mk_write_req(struct raw3215_info *raw)
180 struct raw3215_req *req;
182 int len, count, ix, lines;
184 if (raw->count <= raw->written)
186 /* check if there is a queued write request */
187 req = raw->queued_write;
189 /* no queued write request, use new req structure */
190 req = raw3215_alloc_req();
191 req->type = RAW3215_WRITE;
193 raw->queued_write = req;
195 raw->written -= req->len;
199 req->start = (raw->head - raw->count + raw->written) &
200 (RAW3215_BUFFER_SIZE - 1);
202 * now we have to count newlines. We can at max accept
203 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
204 * a restriction in VM
208 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
209 if (raw->buffer[ix] == 0x15)
211 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
213 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
214 if (len > RAW3215_MAX_BYTES)
215 len = RAW3215_MAX_BYTES;
219 /* set the indication if we should try to enlarge this request */
220 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
225 ccw[-1].flags |= 0x40; /* use command chaining */
226 ccw->cmd_code = 0x01; /* write, auto carrier return */
227 ccw->flags = 0x20; /* ignore incorrect length ind. */
229 (__u32) __pa(raw->buffer + ix);
231 if (ix + count > RAW3215_BUFFER_SIZE)
232 count = RAW3215_BUFFER_SIZE - ix;
235 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
239 * Add a NOP to the channel program. 3215 devices are purely
240 * emulated and its much better to avoid the channel end
241 * interrupt in this case.
244 ccw[-1].flags |= 0x40; /* use command chaining */
245 ccw->cmd_code = 0x03; /* NOP */
252 * Start a read or a write request
255 raw3215_start_io(struct raw3215_info *raw)
257 struct raw3215_req *req;
260 req = raw->queued_read;
262 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
263 /* dequeue request */
264 raw->queued_read = NULL;
265 res = ccw_device_start(raw->cdev, req->ccws,
266 (unsigned long) req, 0, 0);
268 /* do_IO failed, put request back to queue */
269 raw->queued_read = req;
271 raw->flags |= RAW3215_WORKING;
274 req = raw->queued_write;
276 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
277 /* dequeue request */
278 raw->queued_write = NULL;
279 res = ccw_device_start(raw->cdev, req->ccws,
280 (unsigned long) req, 0, 0);
282 /* do_IO failed, put request back to queue */
283 raw->queued_write = req;
285 raw->flags |= RAW3215_WORKING;
291 * Function to start a delayed output after RAW3215_TIMEOUT seconds
294 raw3215_timeout(unsigned long __data)
296 struct raw3215_info *raw = (struct raw3215_info *) __data;
299 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
300 if (raw->flags & RAW3215_TIMER_RUNS) {
301 del_timer(&raw->timer);
302 raw->flags &= ~RAW3215_TIMER_RUNS;
303 raw3215_mk_write_req(raw);
304 raw3215_start_io(raw);
306 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
310 * Function to conditionally start an IO. A read is started immediately,
311 * a write is only started immediately if the flush flag is on or the
312 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
313 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
316 raw3215_try_io(struct raw3215_info *raw)
318 if (!(raw->flags & RAW3215_ACTIVE))
320 if (raw->queued_read != NULL)
321 raw3215_start_io(raw);
322 else if (raw->queued_write != NULL) {
323 if ((raw->queued_write->delayable == 0) ||
324 (raw->flags & RAW3215_FLUSHING)) {
325 /* execute write requests bigger than minimum size */
326 raw3215_start_io(raw);
327 if (raw->flags & RAW3215_TIMER_RUNS) {
328 del_timer(&raw->timer);
329 raw->flags &= ~RAW3215_TIMER_RUNS;
331 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
332 /* delay small writes */
333 init_timer(&raw->timer);
334 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
335 raw->timer.data = (unsigned long) raw;
336 raw->timer.function = raw3215_timeout;
337 add_timer(&raw->timer);
338 raw->flags |= RAW3215_TIMER_RUNS;
344 * The bottom half handler routine for 3215 devices. It tries to start
345 * the next IO and wakes up processes waiting on the tty.
348 raw3215_tasklet(void *data)
350 struct raw3215_info *raw;
351 struct tty_struct *tty;
354 raw = (struct raw3215_info *) data;
355 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
356 raw3215_mk_write_req(raw);
358 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
361 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
367 * Interrupt routine, called from common io layer
370 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
372 struct raw3215_info *raw;
373 struct raw3215_req *req;
374 struct tty_struct *tty;
378 raw = cdev->dev.driver_data;
379 req = (struct raw3215_req *) intparm;
380 cstat = irb->scsw.cmd.cstat;
381 dstat = irb->scsw.cmd.dstat;
383 tasklet_schedule(&raw->tasklet);
384 if (dstat & 0x01) { /* we got a unit exception */
385 dstat &= ~0x01; /* we can ignore it */
391 /* Attention interrupt, someone hit the enter key */
392 raw3215_mk_read_req(raw);
393 tasklet_schedule(&raw->tasklet);
397 /* Channel end interrupt. */
398 if ((raw = req->info) == NULL)
399 return; /* That shouldn't happen ... */
400 if (req->type == RAW3215_READ) {
401 /* store residual count, then wait for device end */
402 req->residual = irb->scsw.cmd.count;
407 /* Device end interrupt. */
408 if ((raw = req->info) == NULL)
409 return; /* That shouldn't happen ... */
410 if (req->type == RAW3215_READ && raw->tty != NULL) {
414 count = 160 - req->residual;
415 EBCASC(raw->inbuf, count);
416 cchar = ctrlchar_handle(raw->inbuf, count, tty);
417 switch (cchar & CTRLCHAR_MASK) {
422 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
423 tty_flip_buffer_push(raw->tty);
428 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
429 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
430 /* add the auto \n */
431 raw->inbuf[count] = '\n';
435 tty_insert_flip_string(tty, raw->inbuf, count);
436 tty_flip_buffer_push(raw->tty);
439 } else if (req->type == RAW3215_WRITE) {
440 raw->count -= req->len;
441 raw->written -= req->len;
443 raw->flags &= ~RAW3215_WORKING;
444 raw3215_free_req(req);
445 /* check for empty wait */
446 if (waitqueue_active(&raw->empty_wait) &&
447 raw->queued_write == NULL &&
448 raw->queued_read == NULL) {
449 wake_up_interruptible(&raw->empty_wait);
451 tasklet_schedule(&raw->tasklet);
454 /* Strange interrupt, I'll do my best to clean up */
455 if (req != NULL && req->type != RAW3215_FREE) {
456 if (req->type == RAW3215_WRITE) {
457 raw->count -= req->len;
458 raw->written -= req->len;
460 raw->flags &= ~RAW3215_WORKING;
461 raw3215_free_req(req);
463 tasklet_schedule(&raw->tasklet);
469 * Wait until length bytes are available int the output buffer.
470 * Has to be called with the s390irq lock held. Can be called
474 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
476 while (RAW3215_BUFFER_SIZE - raw->count < length) {
477 /* there might be a request pending */
478 raw->flags |= RAW3215_FLUSHING;
479 raw3215_mk_write_req(raw);
481 raw->flags &= ~RAW3215_FLUSHING;
482 #ifdef CONFIG_TN3215_CONSOLE
485 /* Enough room freed up ? */
486 if (RAW3215_BUFFER_SIZE - raw->count >= length)
488 /* there might be another cpu waiting for the lock */
489 spin_unlock(get_ccwdev_lock(raw->cdev));
491 spin_lock(get_ccwdev_lock(raw->cdev));
496 * String write routine for 3215 devices
499 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
505 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
506 count = (length > RAW3215_BUFFER_SIZE) ?
507 RAW3215_BUFFER_SIZE : length;
510 raw3215_make_room(raw, count);
512 /* copy string to output buffer and convert it to EBCDIC */
514 c = min_t(int, count,
515 min(RAW3215_BUFFER_SIZE - raw->count,
516 RAW3215_BUFFER_SIZE - raw->head));
519 memcpy(raw->buffer + raw->head, str, c);
520 ASCEBC(raw->buffer + raw->head, c);
521 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
527 if (!(raw->flags & RAW3215_WORKING)) {
528 raw3215_mk_write_req(raw);
529 /* start or queue request */
532 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
537 * Put character routine for 3215 devices
540 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
543 unsigned int length, i;
545 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
547 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
548 raw->line_pos += length;
550 } else if (ch == '\n') {
557 raw3215_make_room(raw, length);
559 for (i = 0; i < length; i++) {
560 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
561 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
564 if (!(raw->flags & RAW3215_WORKING)) {
565 raw3215_mk_write_req(raw);
566 /* start or queue request */
569 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
573 * Flush routine, it simply sets the flush flag and tries to start
577 raw3215_flush_buffer(struct raw3215_info *raw)
581 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
582 if (raw->count > 0) {
583 raw->flags |= RAW3215_FLUSHING;
585 raw->flags &= ~RAW3215_FLUSHING;
587 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
591 * Fire up a 3215 device.
594 raw3215_startup(struct raw3215_info *raw)
598 if (raw->flags & RAW3215_ACTIVE)
601 raw->flags |= RAW3215_ACTIVE;
602 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
604 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
610 * Shutdown a 3215 device.
613 raw3215_shutdown(struct raw3215_info *raw)
615 DECLARE_WAITQUEUE(wait, current);
618 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
620 /* Wait for outstanding requests, then free irq */
621 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
622 if ((raw->flags & RAW3215_WORKING) ||
623 raw->queued_write != NULL ||
624 raw->queued_read != NULL) {
625 raw->flags |= RAW3215_CLOSING;
626 add_wait_queue(&raw->empty_wait, &wait);
627 set_current_state(TASK_INTERRUPTIBLE);
628 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
630 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
631 remove_wait_queue(&raw->empty_wait, &wait);
632 set_current_state(TASK_RUNNING);
633 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
635 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
639 raw3215_probe (struct ccw_device *cdev)
641 struct raw3215_info *raw;
644 /* Console is special. */
645 if (raw3215[0] && (cdev->dev.driver_data == raw3215[0]))
647 raw = kmalloc(sizeof(struct raw3215_info) +
648 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
652 spin_lock(&raw3215_device_lock);
653 for (line = 0; line < NR_3215; line++) {
654 if (!raw3215[line]) {
659 spin_unlock(&raw3215_device_lock);
660 if (line == NR_3215) {
666 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
667 memset(raw, 0, sizeof(struct raw3215_info));
668 raw->buffer = kmalloc(RAW3215_BUFFER_SIZE,
670 if (raw->buffer == NULL) {
671 spin_lock(&raw3215_device_lock);
672 raw3215[line] = NULL;
673 spin_unlock(&raw3215_device_lock);
677 tasklet_init(&raw->tasklet,
678 (void (*)(unsigned long)) raw3215_tasklet,
679 (unsigned long) raw);
680 init_waitqueue_head(&raw->empty_wait);
682 cdev->dev.driver_data = raw;
683 cdev->handler = raw3215_irq;
689 raw3215_remove (struct ccw_device *cdev)
691 struct raw3215_info *raw;
693 ccw_device_set_offline(cdev);
694 raw = cdev->dev.driver_data;
696 cdev->dev.driver_data = NULL;
703 raw3215_set_online (struct ccw_device *cdev)
705 struct raw3215_info *raw;
707 raw = cdev->dev.driver_data;
711 return raw3215_startup(raw);
715 raw3215_set_offline (struct ccw_device *cdev)
717 struct raw3215_info *raw;
719 raw = cdev->dev.driver_data;
723 raw3215_shutdown(raw);
728 static struct ccw_device_id raw3215_id[] = {
729 { CCW_DEVICE(0x3215, 0) },
730 { /* end of list */ },
733 static struct ccw_driver raw3215_ccw_driver = {
735 .owner = THIS_MODULE,
737 .probe = &raw3215_probe,
738 .remove = &raw3215_remove,
739 .set_online = &raw3215_set_online,
740 .set_offline = &raw3215_set_offline,
743 #ifdef CONFIG_TN3215_CONSOLE
745 * Write a string to the 3215 console
748 con3215_write(struct console *co, const char *str, unsigned int count)
750 struct raw3215_info *raw;
755 raw = raw3215[0]; /* console 3215 is the first one */
757 for (i = 0; i < count; i++)
758 if (str[i] == '\t' || str[i] == '\n')
760 raw3215_write(raw, str, i);
764 raw3215_putchar(raw, *str);
771 static struct tty_driver *con3215_device(struct console *c, int *index)
774 return tty3215_driver;
778 * panic() calls console_unblank before the system enters a
779 * disabled, endless loop.
782 con3215_unblank(void)
784 struct raw3215_info *raw;
787 raw = raw3215[0]; /* console 3215 is the first one */
788 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
789 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
790 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
794 * The console structure for the 3215 console
796 static struct console con3215 = {
798 .write = con3215_write,
799 .device = con3215_device,
800 .unblank = con3215_unblank,
801 .flags = CON_PRINTBUFFER,
805 * 3215 console initialization code called from console_init().
806 * NOTE: This is called before kmalloc is available.
811 struct ccw_device *cdev;
812 struct raw3215_info *raw;
813 struct raw3215_req *req;
816 /* Check if 3215 is to be the console */
817 if (!CONSOLE_IS_3215)
820 /* Set the console mode for VM */
822 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
823 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
826 /* allocate 3215 request structures */
827 raw3215_freelist = NULL;
828 spin_lock_init(&raw3215_freelist_lock);
829 for (i = 0; i < NR_3215_REQ; i++) {
830 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
831 req->next = raw3215_freelist;
832 raw3215_freelist = req;
835 cdev = ccw_device_probe_console();
839 raw3215[0] = raw = (struct raw3215_info *)
840 alloc_bootmem_low(sizeof(struct raw3215_info));
841 memset(raw, 0, sizeof(struct raw3215_info));
842 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
843 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
845 cdev->dev.driver_data = raw;
846 cdev->handler = raw3215_irq;
848 raw->flags |= RAW3215_FIXED;
849 tasklet_init(&raw->tasklet,
850 (void (*)(unsigned long)) raw3215_tasklet,
851 (unsigned long) raw);
852 init_waitqueue_head(&raw->empty_wait);
854 /* Request the console irq */
855 if (raw3215_startup(raw) != 0) {
856 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
857 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
858 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
862 register_console(&con3215);
865 console_initcall(con3215_init);
871 * This routine is called whenever a 3215 tty is opened.
874 tty3215_open(struct tty_struct *tty, struct file * filp)
876 struct raw3215_info *raw;
880 if ((line < 0) || (line >= NR_3215))
887 tty->driver_data = raw;
890 tty->low_latency = 0; /* don't use bottom half for pushing chars */
892 * Start up 3215 device
894 retval = raw3215_startup(raw);
904 * This routine is called when the 3215 tty is closed. We wait
905 * for the remaining request to be completed. Then we clean up.
908 tty3215_close(struct tty_struct *tty, struct file * filp)
910 struct raw3215_info *raw;
912 raw = (struct raw3215_info *) tty->driver_data;
913 if (raw == NULL || tty->count > 1)
916 /* Shutdown the terminal */
917 raw3215_shutdown(raw);
923 * Returns the amount of free space in the output buffer.
926 tty3215_write_room(struct tty_struct *tty)
928 struct raw3215_info *raw;
930 raw = (struct raw3215_info *) tty->driver_data;
932 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
933 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
934 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
940 * String write routine for 3215 ttys
943 tty3215_write(struct tty_struct * tty,
944 const unsigned char *buf, int count)
946 struct raw3215_info *raw;
950 raw = (struct raw3215_info *) tty->driver_data;
951 raw3215_write(raw, buf, count);
956 * Put character routine for 3215 ttys
959 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
961 struct raw3215_info *raw;
965 raw = (struct raw3215_info *) tty->driver_data;
966 raw3215_putchar(raw, ch);
971 tty3215_flush_chars(struct tty_struct *tty)
976 * Returns the number of characters in the output buffer
979 tty3215_chars_in_buffer(struct tty_struct *tty)
981 struct raw3215_info *raw;
983 raw = (struct raw3215_info *) tty->driver_data;
988 tty3215_flush_buffer(struct tty_struct *tty)
990 struct raw3215_info *raw;
992 raw = (struct raw3215_info *) tty->driver_data;
993 raw3215_flush_buffer(raw);
998 * Currently we don't have any io controls for 3215 ttys
1001 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1002 unsigned int cmd, unsigned long arg)
1004 if (tty->flags & (1 << TTY_IO_ERROR))
1009 return -ENOIOCTLCMD;
1015 * Disable reading from a 3215 tty
1018 tty3215_throttle(struct tty_struct * tty)
1020 struct raw3215_info *raw;
1022 raw = (struct raw3215_info *) tty->driver_data;
1023 raw->flags |= RAW3215_THROTTLED;
1027 * Enable reading from a 3215 tty
1030 tty3215_unthrottle(struct tty_struct * tty)
1032 struct raw3215_info *raw;
1033 unsigned long flags;
1035 raw = (struct raw3215_info *) tty->driver_data;
1036 if (raw->flags & RAW3215_THROTTLED) {
1037 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1038 raw->flags &= ~RAW3215_THROTTLED;
1039 raw3215_try_io(raw);
1040 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1045 * Disable writing to a 3215 tty
1048 tty3215_stop(struct tty_struct *tty)
1050 struct raw3215_info *raw;
1052 raw = (struct raw3215_info *) tty->driver_data;
1053 raw->flags |= RAW3215_STOPPED;
1057 * Enable writing to a 3215 tty
1060 tty3215_start(struct tty_struct *tty)
1062 struct raw3215_info *raw;
1063 unsigned long flags;
1065 raw = (struct raw3215_info *) tty->driver_data;
1066 if (raw->flags & RAW3215_STOPPED) {
1067 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1068 raw->flags &= ~RAW3215_STOPPED;
1069 raw3215_try_io(raw);
1070 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1074 static const struct tty_operations tty3215_ops = {
1075 .open = tty3215_open,
1076 .close = tty3215_close,
1077 .write = tty3215_write,
1078 .put_char = tty3215_put_char,
1079 .flush_chars = tty3215_flush_chars,
1080 .write_room = tty3215_write_room,
1081 .chars_in_buffer = tty3215_chars_in_buffer,
1082 .flush_buffer = tty3215_flush_buffer,
1083 .ioctl = tty3215_ioctl,
1084 .throttle = tty3215_throttle,
1085 .unthrottle = tty3215_unthrottle,
1086 .stop = tty3215_stop,
1087 .start = tty3215_start,
1091 * 3215 tty registration code called from tty_init().
1092 * Most kernel services (incl. kmalloc) are available at this poimt.
1097 struct tty_driver *driver;
1100 if (!CONSOLE_IS_3215)
1103 driver = alloc_tty_driver(NR_3215);
1107 ret = ccw_driver_register(&raw3215_ccw_driver);
1109 put_tty_driver(driver);
1113 * Initialize the tty_driver structure
1114 * Entries in tty3215_driver that are NOT initialized:
1115 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1118 driver->owner = THIS_MODULE;
1119 driver->driver_name = "tty3215";
1120 driver->name = "ttyS";
1121 driver->major = TTY_MAJOR;
1122 driver->minor_start = 64;
1123 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1124 driver->subtype = SYSTEM_TYPE_TTY;
1125 driver->init_termios = tty_std_termios;
1126 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1127 driver->init_termios.c_oflag = ONLCR | XTABS;
1128 driver->init_termios.c_lflag = ISIG;
1129 driver->flags = TTY_DRIVER_REAL_RAW;
1130 tty_set_operations(driver, &tty3215_ops);
1131 ret = tty_register_driver(driver);
1133 put_tty_driver(driver);
1136 tty3215_driver = driver;
1143 tty_unregister_driver(tty3215_driver);
1144 put_tty_driver(tty3215_driver);
1145 ccw_driver_unregister(&raw3215_ccw_driver);
1148 module_init(tty3215_init);
1149 module_exit(tty3215_exit);