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>
24 #include <linux/reboot.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 int line_pos; /* position on the line (for tabs) */
98 char ubuffer[80]; /* copy_from_user buffer */
101 /* array of 3215 devices structures */
102 static struct raw3215_info *raw3215[NR_3215];
103 /* spinlock to protect the raw3215 array */
104 static DEFINE_SPINLOCK(raw3215_device_lock);
105 /* list of free request structures */
106 static struct raw3215_req *raw3215_freelist;
107 /* spinlock to protect free list */
108 static spinlock_t raw3215_freelist_lock;
110 static struct tty_driver *tty3215_driver;
113 * Get a request structure from the free list
115 static inline struct raw3215_req *
116 raw3215_alloc_req(void) {
117 struct raw3215_req *req;
120 spin_lock_irqsave(&raw3215_freelist_lock, flags);
121 req = raw3215_freelist;
122 raw3215_freelist = req->next;
123 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
128 * Put a request structure back to the free list
131 raw3215_free_req(struct raw3215_req *req) {
134 if (req->type == RAW3215_FREE)
135 return; /* don't free a free request */
136 req->type = RAW3215_FREE;
137 spin_lock_irqsave(&raw3215_freelist_lock, flags);
138 req->next = raw3215_freelist;
139 raw3215_freelist = req;
140 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
144 * Set up a read request that reads up to 160 byte from the 3215 device.
145 * If there is a queued read request it is used, but that shouldn't happen
146 * because a 3215 terminal won't accept a new read before the old one is
150 raw3215_mk_read_req(struct raw3215_info *raw)
152 struct raw3215_req *req;
155 /* there can only be ONE read request at a time */
156 req = raw->queued_read;
158 /* no queued read request, use new req structure */
159 req = raw3215_alloc_req();
160 req->type = RAW3215_READ;
162 raw->queued_read = req;
166 ccw->cmd_code = 0x0A; /* read inquiry */
167 ccw->flags = 0x20; /* ignore incorrect length */
169 ccw->cda = (__u32) __pa(raw->inbuf);
173 * Set up a write request with the information from the main structure.
174 * A ccw chain is created that writes as much as possible from the output
175 * buffer to the 3215 device. If a queued write exists it is replaced by
176 * the new, probably lengthened request.
179 raw3215_mk_write_req(struct raw3215_info *raw)
181 struct raw3215_req *req;
183 int len, count, ix, lines;
185 if (raw->count <= raw->written)
187 /* check if there is a queued write request */
188 req = raw->queued_write;
190 /* no queued write request, use new req structure */
191 req = raw3215_alloc_req();
192 req->type = RAW3215_WRITE;
194 raw->queued_write = req;
196 raw->written -= req->len;
200 req->start = (raw->head - raw->count + raw->written) &
201 (RAW3215_BUFFER_SIZE - 1);
203 * now we have to count newlines. We can at max accept
204 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
205 * a restriction in VM
209 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
210 if (raw->buffer[ix] == 0x15)
212 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
214 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
215 if (len > RAW3215_MAX_BYTES)
216 len = RAW3215_MAX_BYTES;
220 /* set the indication if we should try to enlarge this request */
221 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
226 ccw[-1].flags |= 0x40; /* use command chaining */
227 ccw->cmd_code = 0x01; /* write, auto carrier return */
228 ccw->flags = 0x20; /* ignore incorrect length ind. */
230 (__u32) __pa(raw->buffer + ix);
232 if (ix + count > RAW3215_BUFFER_SIZE)
233 count = RAW3215_BUFFER_SIZE - ix;
236 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
240 * Add a NOP to the channel program. 3215 devices are purely
241 * emulated and its much better to avoid the channel end
242 * interrupt in this case.
245 ccw[-1].flags |= 0x40; /* use command chaining */
246 ccw->cmd_code = 0x03; /* NOP */
253 * Start a read or a write request
256 raw3215_start_io(struct raw3215_info *raw)
258 struct raw3215_req *req;
261 req = raw->queued_read;
263 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
264 /* dequeue request */
265 raw->queued_read = NULL;
266 res = ccw_device_start(raw->cdev, req->ccws,
267 (unsigned long) req, 0, 0);
269 /* do_IO failed, put request back to queue */
270 raw->queued_read = req;
272 raw->flags |= RAW3215_WORKING;
275 req = raw->queued_write;
277 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
278 /* dequeue request */
279 raw->queued_write = NULL;
280 res = ccw_device_start(raw->cdev, req->ccws,
281 (unsigned long) req, 0, 0);
283 /* do_IO failed, put request back to queue */
284 raw->queued_write = req;
286 raw->flags |= RAW3215_WORKING;
292 * Function to start a delayed output after RAW3215_TIMEOUT seconds
295 raw3215_timeout(unsigned long __data)
297 struct raw3215_info *raw = (struct raw3215_info *) __data;
300 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
301 if (raw->flags & RAW3215_TIMER_RUNS) {
302 del_timer(&raw->timer);
303 raw->flags &= ~RAW3215_TIMER_RUNS;
304 raw3215_mk_write_req(raw);
305 raw3215_start_io(raw);
307 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
311 * Function to conditionally start an IO. A read is started immediately,
312 * a write is only started immediately if the flush flag is on or the
313 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
314 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
317 raw3215_try_io(struct raw3215_info *raw)
319 if (!(raw->flags & RAW3215_ACTIVE))
321 if (raw->queued_read != NULL)
322 raw3215_start_io(raw);
323 else if (raw->queued_write != NULL) {
324 if ((raw->queued_write->delayable == 0) ||
325 (raw->flags & RAW3215_FLUSHING)) {
326 /* execute write requests bigger than minimum size */
327 raw3215_start_io(raw);
328 if (raw->flags & RAW3215_TIMER_RUNS) {
329 del_timer(&raw->timer);
330 raw->flags &= ~RAW3215_TIMER_RUNS;
332 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
333 /* delay small writes */
334 init_timer(&raw->timer);
335 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
336 raw->timer.data = (unsigned long) raw;
337 raw->timer.function = raw3215_timeout;
338 add_timer(&raw->timer);
339 raw->flags |= RAW3215_TIMER_RUNS;
345 * The bottom half handler routine for 3215 devices. It tries to start
346 * the next IO and wakes up processes waiting on the tty.
349 raw3215_tasklet(void *data)
351 struct raw3215_info *raw;
352 struct tty_struct *tty;
355 raw = (struct raw3215_info *) data;
356 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
357 raw3215_mk_write_req(raw);
359 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
362 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
368 * Interrupt routine, called from common io layer
371 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
373 struct raw3215_info *raw;
374 struct raw3215_req *req;
375 struct tty_struct *tty;
379 raw = cdev->dev.driver_data;
380 req = (struct raw3215_req *) intparm;
381 cstat = irb->scsw.cmd.cstat;
382 dstat = irb->scsw.cmd.dstat;
384 tasklet_schedule(&raw->tasklet);
385 if (dstat & 0x01) { /* we got a unit exception */
386 dstat &= ~0x01; /* we can ignore it */
392 /* Attention interrupt, someone hit the enter key */
393 raw3215_mk_read_req(raw);
394 tasklet_schedule(&raw->tasklet);
398 /* Channel end interrupt. */
399 if ((raw = req->info) == NULL)
400 return; /* That shouldn't happen ... */
401 if (req->type == RAW3215_READ) {
402 /* store residual count, then wait for device end */
403 req->residual = irb->scsw.cmd.count;
408 /* Device end interrupt. */
409 if ((raw = req->info) == NULL)
410 return; /* That shouldn't happen ... */
411 if (req->type == RAW3215_READ && raw->tty != NULL) {
415 count = 160 - req->residual;
416 EBCASC(raw->inbuf, count);
417 cchar = ctrlchar_handle(raw->inbuf, count, tty);
418 switch (cchar & CTRLCHAR_MASK) {
423 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
424 tty_flip_buffer_push(raw->tty);
429 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
430 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
431 /* add the auto \n */
432 raw->inbuf[count] = '\n';
436 tty_insert_flip_string(tty, raw->inbuf, count);
437 tty_flip_buffer_push(raw->tty);
440 } else if (req->type == RAW3215_WRITE) {
441 raw->count -= req->len;
442 raw->written -= req->len;
444 raw->flags &= ~RAW3215_WORKING;
445 raw3215_free_req(req);
446 /* check for empty wait */
447 if (waitqueue_active(&raw->empty_wait) &&
448 raw->queued_write == NULL &&
449 raw->queued_read == NULL) {
450 wake_up_interruptible(&raw->empty_wait);
452 tasklet_schedule(&raw->tasklet);
455 /* Strange interrupt, I'll do my best to clean up */
456 if (req != NULL && req->type != RAW3215_FREE) {
457 if (req->type == RAW3215_WRITE) {
458 raw->count -= req->len;
459 raw->written -= req->len;
461 raw->flags &= ~RAW3215_WORKING;
462 raw3215_free_req(req);
464 tasklet_schedule(&raw->tasklet);
470 * Wait until length bytes are available int the output buffer.
471 * Has to be called with the s390irq lock held. Can be called
475 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
477 while (RAW3215_BUFFER_SIZE - raw->count < length) {
478 /* there might be a request pending */
479 raw->flags |= RAW3215_FLUSHING;
480 raw3215_mk_write_req(raw);
482 raw->flags &= ~RAW3215_FLUSHING;
483 #ifdef CONFIG_TN3215_CONSOLE
486 /* Enough room freed up ? */
487 if (RAW3215_BUFFER_SIZE - raw->count >= length)
489 /* there might be another cpu waiting for the lock */
490 spin_unlock(get_ccwdev_lock(raw->cdev));
492 spin_lock(get_ccwdev_lock(raw->cdev));
497 * String write routine for 3215 devices
500 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
506 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
507 count = (length > RAW3215_BUFFER_SIZE) ?
508 RAW3215_BUFFER_SIZE : length;
511 raw3215_make_room(raw, count);
513 /* copy string to output buffer and convert it to EBCDIC */
515 c = min_t(int, count,
516 min(RAW3215_BUFFER_SIZE - raw->count,
517 RAW3215_BUFFER_SIZE - raw->head));
520 memcpy(raw->buffer + raw->head, str, c);
521 ASCEBC(raw->buffer + raw->head, c);
522 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
528 if (!(raw->flags & RAW3215_WORKING)) {
529 raw3215_mk_write_req(raw);
530 /* start or queue request */
533 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
538 * Put character routine for 3215 devices
541 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
544 unsigned int length, i;
546 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
548 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
549 raw->line_pos += length;
551 } else if (ch == '\n') {
558 raw3215_make_room(raw, length);
560 for (i = 0; i < length; i++) {
561 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
562 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
565 if (!(raw->flags & RAW3215_WORKING)) {
566 raw3215_mk_write_req(raw);
567 /* start or queue request */
570 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
574 * Flush routine, it simply sets the flush flag and tries to start
578 raw3215_flush_buffer(struct raw3215_info *raw)
582 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
583 if (raw->count > 0) {
584 raw->flags |= RAW3215_FLUSHING;
586 raw->flags &= ~RAW3215_FLUSHING;
588 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
592 * Fire up a 3215 device.
595 raw3215_startup(struct raw3215_info *raw)
599 if (raw->flags & RAW3215_ACTIVE)
602 raw->flags |= RAW3215_ACTIVE;
603 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
605 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
611 * Shutdown a 3215 device.
614 raw3215_shutdown(struct raw3215_info *raw)
616 DECLARE_WAITQUEUE(wait, current);
619 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
621 /* Wait for outstanding requests, then free irq */
622 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
623 if ((raw->flags & RAW3215_WORKING) ||
624 raw->queued_write != NULL ||
625 raw->queued_read != NULL) {
626 raw->flags |= RAW3215_CLOSING;
627 add_wait_queue(&raw->empty_wait, &wait);
628 set_current_state(TASK_INTERRUPTIBLE);
629 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
631 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
632 remove_wait_queue(&raw->empty_wait, &wait);
633 set_current_state(TASK_RUNNING);
634 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
636 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
640 raw3215_probe (struct ccw_device *cdev)
642 struct raw3215_info *raw;
645 /* Console is special. */
646 if (raw3215[0] && (cdev->dev.driver_data == raw3215[0]))
648 raw = kmalloc(sizeof(struct raw3215_info) +
649 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
653 spin_lock(&raw3215_device_lock);
654 for (line = 0; line < NR_3215; line++) {
655 if (!raw3215[line]) {
660 spin_unlock(&raw3215_device_lock);
661 if (line == NR_3215) {
667 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
668 memset(raw, 0, sizeof(struct raw3215_info));
669 raw->buffer = kmalloc(RAW3215_BUFFER_SIZE,
671 if (raw->buffer == NULL) {
672 spin_lock(&raw3215_device_lock);
673 raw3215[line] = NULL;
674 spin_unlock(&raw3215_device_lock);
678 tasklet_init(&raw->tasklet,
679 (void (*)(unsigned long)) raw3215_tasklet,
680 (unsigned long) raw);
681 init_waitqueue_head(&raw->empty_wait);
683 cdev->dev.driver_data = raw;
684 cdev->handler = raw3215_irq;
690 raw3215_remove (struct ccw_device *cdev)
692 struct raw3215_info *raw;
694 ccw_device_set_offline(cdev);
695 raw = cdev->dev.driver_data;
697 cdev->dev.driver_data = NULL;
704 raw3215_set_online (struct ccw_device *cdev)
706 struct raw3215_info *raw;
708 raw = cdev->dev.driver_data;
712 return raw3215_startup(raw);
716 raw3215_set_offline (struct ccw_device *cdev)
718 struct raw3215_info *raw;
720 raw = cdev->dev.driver_data;
724 raw3215_shutdown(raw);
729 static struct ccw_device_id raw3215_id[] = {
730 { CCW_DEVICE(0x3215, 0) },
731 { /* end of list */ },
734 static struct ccw_driver raw3215_ccw_driver = {
736 .owner = THIS_MODULE,
738 .probe = &raw3215_probe,
739 .remove = &raw3215_remove,
740 .set_online = &raw3215_set_online,
741 .set_offline = &raw3215_set_offline,
744 #ifdef CONFIG_TN3215_CONSOLE
746 * Write a string to the 3215 console
749 con3215_write(struct console *co, const char *str, unsigned int count)
751 struct raw3215_info *raw;
756 raw = raw3215[0]; /* console 3215 is the first one */
758 for (i = 0; i < count; i++)
759 if (str[i] == '\t' || str[i] == '\n')
761 raw3215_write(raw, str, i);
765 raw3215_putchar(raw, *str);
772 static struct tty_driver *con3215_device(struct console *c, int *index)
775 return tty3215_driver;
779 * panic() calls con3215_flush through a panic_notifier
780 * before the system enters a disabled, endless loop.
785 struct raw3215_info *raw;
788 raw = raw3215[0]; /* console 3215 is the first one */
789 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
790 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
791 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
794 static int con3215_notify(struct notifier_block *self,
795 unsigned long event, void *data)
801 static struct notifier_block on_panic_nb = {
802 .notifier_call = con3215_notify,
806 static struct notifier_block on_reboot_nb = {
807 .notifier_call = con3215_notify,
812 * The console structure for the 3215 console
814 static struct console con3215 = {
816 .write = con3215_write,
817 .device = con3215_device,
818 .flags = CON_PRINTBUFFER,
822 * 3215 console initialization code called from console_init().
823 * NOTE: This is called before kmalloc is available.
828 struct ccw_device *cdev;
829 struct raw3215_info *raw;
830 struct raw3215_req *req;
833 /* Check if 3215 is to be the console */
834 if (!CONSOLE_IS_3215)
837 /* Set the console mode for VM */
839 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
840 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
843 /* allocate 3215 request structures */
844 raw3215_freelist = NULL;
845 spin_lock_init(&raw3215_freelist_lock);
846 for (i = 0; i < NR_3215_REQ; i++) {
847 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
848 req->next = raw3215_freelist;
849 raw3215_freelist = req;
852 cdev = ccw_device_probe_console();
856 raw3215[0] = raw = (struct raw3215_info *)
857 alloc_bootmem_low(sizeof(struct raw3215_info));
858 memset(raw, 0, sizeof(struct raw3215_info));
859 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
860 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
862 cdev->dev.driver_data = raw;
863 cdev->handler = raw3215_irq;
865 raw->flags |= RAW3215_FIXED;
866 tasklet_init(&raw->tasklet,
867 (void (*)(unsigned long)) raw3215_tasklet,
868 (unsigned long) raw);
869 init_waitqueue_head(&raw->empty_wait);
871 /* Request the console irq */
872 if (raw3215_startup(raw) != 0) {
873 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
874 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
875 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
879 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
880 register_reboot_notifier(&on_reboot_nb);
881 register_console(&con3215);
884 console_initcall(con3215_init);
890 * This routine is called whenever a 3215 tty is opened.
893 tty3215_open(struct tty_struct *tty, struct file * filp)
895 struct raw3215_info *raw;
899 if ((line < 0) || (line >= NR_3215))
906 tty->driver_data = raw;
909 tty->low_latency = 0; /* don't use bottom half for pushing chars */
911 * Start up 3215 device
913 retval = raw3215_startup(raw);
923 * This routine is called when the 3215 tty is closed. We wait
924 * for the remaining request to be completed. Then we clean up.
927 tty3215_close(struct tty_struct *tty, struct file * filp)
929 struct raw3215_info *raw;
931 raw = (struct raw3215_info *) tty->driver_data;
932 if (raw == NULL || tty->count > 1)
935 /* Shutdown the terminal */
936 raw3215_shutdown(raw);
942 * Returns the amount of free space in the output buffer.
945 tty3215_write_room(struct tty_struct *tty)
947 struct raw3215_info *raw;
949 raw = (struct raw3215_info *) tty->driver_data;
951 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
952 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
953 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
959 * String write routine for 3215 ttys
962 tty3215_write(struct tty_struct * tty,
963 const unsigned char *buf, int count)
965 struct raw3215_info *raw;
969 raw = (struct raw3215_info *) tty->driver_data;
970 raw3215_write(raw, buf, count);
975 * Put character routine for 3215 ttys
978 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
980 struct raw3215_info *raw;
984 raw = (struct raw3215_info *) tty->driver_data;
985 raw3215_putchar(raw, ch);
990 tty3215_flush_chars(struct tty_struct *tty)
995 * Returns the number of characters in the output buffer
998 tty3215_chars_in_buffer(struct tty_struct *tty)
1000 struct raw3215_info *raw;
1002 raw = (struct raw3215_info *) tty->driver_data;
1007 tty3215_flush_buffer(struct tty_struct *tty)
1009 struct raw3215_info *raw;
1011 raw = (struct raw3215_info *) tty->driver_data;
1012 raw3215_flush_buffer(raw);
1017 * Currently we don't have any io controls for 3215 ttys
1020 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1021 unsigned int cmd, unsigned long arg)
1023 if (tty->flags & (1 << TTY_IO_ERROR))
1028 return -ENOIOCTLCMD;
1034 * Disable reading from a 3215 tty
1037 tty3215_throttle(struct tty_struct * tty)
1039 struct raw3215_info *raw;
1041 raw = (struct raw3215_info *) tty->driver_data;
1042 raw->flags |= RAW3215_THROTTLED;
1046 * Enable reading from a 3215 tty
1049 tty3215_unthrottle(struct tty_struct * tty)
1051 struct raw3215_info *raw;
1052 unsigned long flags;
1054 raw = (struct raw3215_info *) tty->driver_data;
1055 if (raw->flags & RAW3215_THROTTLED) {
1056 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1057 raw->flags &= ~RAW3215_THROTTLED;
1058 raw3215_try_io(raw);
1059 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1064 * Disable writing to a 3215 tty
1067 tty3215_stop(struct tty_struct *tty)
1069 struct raw3215_info *raw;
1071 raw = (struct raw3215_info *) tty->driver_data;
1072 raw->flags |= RAW3215_STOPPED;
1076 * Enable writing to a 3215 tty
1079 tty3215_start(struct tty_struct *tty)
1081 struct raw3215_info *raw;
1082 unsigned long flags;
1084 raw = (struct raw3215_info *) tty->driver_data;
1085 if (raw->flags & RAW3215_STOPPED) {
1086 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1087 raw->flags &= ~RAW3215_STOPPED;
1088 raw3215_try_io(raw);
1089 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1093 static const struct tty_operations tty3215_ops = {
1094 .open = tty3215_open,
1095 .close = tty3215_close,
1096 .write = tty3215_write,
1097 .put_char = tty3215_put_char,
1098 .flush_chars = tty3215_flush_chars,
1099 .write_room = tty3215_write_room,
1100 .chars_in_buffer = tty3215_chars_in_buffer,
1101 .flush_buffer = tty3215_flush_buffer,
1102 .ioctl = tty3215_ioctl,
1103 .throttle = tty3215_throttle,
1104 .unthrottle = tty3215_unthrottle,
1105 .stop = tty3215_stop,
1106 .start = tty3215_start,
1110 * 3215 tty registration code called from tty_init().
1111 * Most kernel services (incl. kmalloc) are available at this poimt.
1116 struct tty_driver *driver;
1119 if (!CONSOLE_IS_3215)
1122 driver = alloc_tty_driver(NR_3215);
1126 ret = ccw_driver_register(&raw3215_ccw_driver);
1128 put_tty_driver(driver);
1132 * Initialize the tty_driver structure
1133 * Entries in tty3215_driver that are NOT initialized:
1134 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1137 driver->owner = THIS_MODULE;
1138 driver->driver_name = "tty3215";
1139 driver->name = "ttyS";
1140 driver->major = TTY_MAJOR;
1141 driver->minor_start = 64;
1142 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1143 driver->subtype = SYSTEM_TYPE_TTY;
1144 driver->init_termios = tty_std_termios;
1145 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1146 driver->init_termios.c_oflag = ONLCR | XTABS;
1147 driver->init_termios.c_lflag = ISIG;
1148 driver->flags = TTY_DRIVER_REAL_RAW;
1149 tty_set_operations(driver, &tty3215_ops);
1150 ret = tty_register_driver(driver);
1152 put_tty_driver(driver);
1155 tty3215_driver = driver;
1162 tty_unregister_driver(tty3215_driver);
1163 put_tty_driver(tty3215_driver);
1164 ccw_driver_unregister(&raw3215_ccw_driver);
1167 module_init(tty3215_init);
1168 module_exit(tty3215_exit);