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 spinlock_t raw3215_device_lock = SPIN_LOCK_UNLOCKED;
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) {
369 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
370 tty->ldisc.write_wakeup)
371 (tty->ldisc.write_wakeup)(tty);
372 wake_up_interruptible(&tty->write_wait);
377 * Interrupt routine, called from common io layer
380 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
382 struct raw3215_info *raw;
383 struct raw3215_req *req;
384 struct tty_struct *tty;
388 raw = cdev->dev.driver_data;
389 req = (struct raw3215_req *) intparm;
390 cstat = irb->scsw.cstat;
391 dstat = irb->scsw.dstat;
393 raw->message = KERN_WARNING
394 "Got nonzero channel status in raw3215_irq "
395 "(dev sts 0x%2x, sch sts 0x%2x)";
396 raw->msg_dstat = dstat;
397 raw->msg_cstat = cstat;
398 tasklet_schedule(&raw->tasklet);
400 if (dstat & 0x01) { /* we got a unit exception */
401 dstat &= ~0x01; /* we can ignore it */
407 /* Attention interrupt, someone hit the enter key */
408 raw3215_mk_read_req(raw);
410 memset(raw->inbuf, 0, RAW3215_INBUF_SIZE);
411 tasklet_schedule(&raw->tasklet);
415 /* Channel end interrupt. */
416 if ((raw = req->info) == NULL)
417 return; /* That shouldn't happen ... */
418 if (req->type == RAW3215_READ) {
419 /* store residual count, then wait for device end */
420 req->residual = irb->scsw.count;
425 /* Device end interrupt. */
426 if ((raw = req->info) == NULL)
427 return; /* That shouldn't happen ... */
428 if (req->type == RAW3215_READ && raw->tty != NULL) {
432 count = 160 - req->residual;
433 if (MACHINE_IS_P390) {
434 slen = strnlen(raw->inbuf, RAW3215_INBUF_SIZE);
438 if (count >= TTY_FLIPBUF_SIZE - tty->flip.count)
439 count = TTY_FLIPBUF_SIZE - tty->flip.count - 1;
440 EBCASC(raw->inbuf, count);
441 cchar = ctrlchar_handle(raw->inbuf, count, tty);
442 switch (cchar & CTRLCHAR_MASK) {
448 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
449 *tty->flip.char_buf_ptr++ = cchar;
450 tty_flip_buffer_push(raw->tty);
454 memcpy(tty->flip.char_buf_ptr,
457 (strncmp(raw->inbuf+count-2, "^n", 2) &&
458 strncmp(raw->inbuf+count-2, "\252n", 2)) ) {
459 /* don't add the auto \n */
460 tty->flip.char_buf_ptr[count] = '\n';
461 memset(tty->flip.flag_buf_ptr,
462 TTY_NORMAL, count + 1);
466 tty->flip.char_buf_ptr += count;
467 tty->flip.flag_buf_ptr += count;
468 tty->flip.count += count;
469 tty_flip_buffer_push(raw->tty);
472 } else if (req->type == RAW3215_WRITE) {
473 raw->count -= req->len;
474 raw->written -= req->len;
476 raw->flags &= ~RAW3215_WORKING;
477 raw3215_free_req(req);
478 /* check for empty wait */
479 if (waitqueue_active(&raw->empty_wait) &&
480 raw->queued_write == NULL &&
481 raw->queued_read == NULL) {
482 wake_up_interruptible(&raw->empty_wait);
484 tasklet_schedule(&raw->tasklet);
487 /* Strange interrupt, I'll do my best to clean up */
488 if (req != NULL && req->type != RAW3215_FREE) {
489 if (req->type == RAW3215_WRITE) {
490 raw->count -= req->len;
491 raw->written -= req->len;
493 raw->flags &= ~RAW3215_WORKING;
494 raw3215_free_req(req);
496 raw->message = KERN_WARNING
497 "Spurious interrupt in in raw3215_irq "
498 "(dev sts 0x%2x, sch sts 0x%2x)";
499 raw->msg_dstat = dstat;
500 raw->msg_cstat = cstat;
501 tasklet_schedule(&raw->tasklet);
507 * Wait until length bytes are available int the output buffer.
508 * Has to be called with the s390irq lock held. Can be called
512 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
514 while (RAW3215_BUFFER_SIZE - raw->count < length) {
515 /* there might be a request pending */
516 raw->flags |= RAW3215_FLUSHING;
517 raw3215_mk_write_req(raw);
519 raw->flags &= ~RAW3215_FLUSHING;
520 #ifdef CONFIG_TN3215_CONSOLE
523 /* Enough room freed up ? */
524 if (RAW3215_BUFFER_SIZE - raw->count >= length)
526 /* there might be another cpu waiting for the lock */
527 spin_unlock(raw->lock);
529 spin_lock(raw->lock);
534 * String write routine for 3215 devices
537 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
543 spin_lock_irqsave(raw->lock, flags);
544 count = (length > RAW3215_BUFFER_SIZE) ?
545 RAW3215_BUFFER_SIZE : length;
548 raw3215_make_room(raw, count);
550 /* copy string to output buffer and convert it to EBCDIC */
552 c = min_t(int, count,
553 min(RAW3215_BUFFER_SIZE - raw->count,
554 RAW3215_BUFFER_SIZE - raw->head));
557 memcpy(raw->buffer + raw->head, str, c);
558 ASCEBC(raw->buffer + raw->head, c);
559 raw->head = (raw->head + c) & (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(raw->lock, flags);
575 * Put character routine for 3215 devices
578 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
581 unsigned int length, i;
583 spin_lock_irqsave(raw->lock, flags);
585 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
586 raw->line_pos += length;
588 } else if (ch == '\n') {
595 raw3215_make_room(raw, length);
597 for (i = 0; i < length; i++) {
598 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
599 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
602 if (!(raw->flags & RAW3215_WORKING)) {
603 raw3215_mk_write_req(raw);
604 /* start or queue request */
607 spin_unlock_irqrestore(raw->lock, flags);
611 * Flush routine, it simply sets the flush flag and tries to start
615 raw3215_flush_buffer(struct raw3215_info *raw)
619 spin_lock_irqsave(raw->lock, flags);
620 if (raw->count > 0) {
621 raw->flags |= RAW3215_FLUSHING;
623 raw->flags &= ~RAW3215_FLUSHING;
625 spin_unlock_irqrestore(raw->lock, flags);
629 * Fire up a 3215 device.
632 raw3215_startup(struct raw3215_info *raw)
636 if (raw->flags & RAW3215_ACTIVE)
639 raw->flags |= RAW3215_ACTIVE;
640 spin_lock_irqsave(raw->lock, flags);
642 spin_unlock_irqrestore(raw->lock, flags);
648 * Shutdown a 3215 device.
651 raw3215_shutdown(struct raw3215_info *raw)
653 DECLARE_WAITQUEUE(wait, current);
656 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
658 /* Wait for outstanding requests, then free irq */
659 spin_lock_irqsave(raw->lock, flags);
660 if ((raw->flags & RAW3215_WORKING) ||
661 raw->queued_write != NULL ||
662 raw->queued_read != NULL) {
663 raw->flags |= RAW3215_CLOSING;
664 add_wait_queue(&raw->empty_wait, &wait);
665 set_current_state(TASK_INTERRUPTIBLE);
666 spin_unlock_irqrestore(raw->lock, flags);
668 spin_lock_irqsave(raw->lock, flags);
669 remove_wait_queue(&raw->empty_wait, &wait);
670 set_current_state(TASK_RUNNING);
671 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
673 spin_unlock_irqrestore(raw->lock, flags);
677 raw3215_probe (struct ccw_device *cdev)
679 struct raw3215_info *raw;
682 raw = kmalloc(sizeof(struct raw3215_info) +
683 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
687 spin_lock(&raw3215_device_lock);
688 for (line = 0; line < NR_3215; line++) {
689 if (!raw3215[line]) {
694 spin_unlock(&raw3215_device_lock);
695 if (line == NR_3215) {
701 raw->lock = get_ccwdev_lock(cdev);
702 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
703 memset(raw, 0, sizeof(struct raw3215_info));
704 raw->buffer = (char *) kmalloc(RAW3215_BUFFER_SIZE,
706 if (raw->buffer == NULL) {
707 spin_lock(&raw3215_device_lock);
709 spin_unlock(&raw3215_device_lock);
713 tasklet_init(&raw->tasklet,
714 (void (*)(unsigned long)) raw3215_tasklet,
715 (unsigned long) raw);
716 init_waitqueue_head(&raw->empty_wait);
718 cdev->dev.driver_data = raw;
719 cdev->handler = raw3215_irq;
725 raw3215_remove (struct ccw_device *cdev)
727 struct raw3215_info *raw;
729 ccw_device_set_offline(cdev);
730 raw = cdev->dev.driver_data;
732 cdev->dev.driver_data = NULL;
740 raw3215_set_online (struct ccw_device *cdev)
742 struct raw3215_info *raw;
744 raw = cdev->dev.driver_data;
748 return raw3215_startup(raw);
752 raw3215_set_offline (struct ccw_device *cdev)
754 struct raw3215_info *raw;
756 raw = cdev->dev.driver_data;
760 raw3215_shutdown(raw);
765 static struct ccw_device_id raw3215_id[] = {
766 { CCW_DEVICE(0x3215, 0) },
767 { /* end of list */ },
770 static struct ccw_driver raw3215_ccw_driver = {
772 .owner = THIS_MODULE,
774 .probe = &raw3215_probe,
775 .remove = &raw3215_remove,
776 .set_online = &raw3215_set_online,
777 .set_offline = &raw3215_set_offline,
780 #ifdef CONFIG_TN3215_CONSOLE
782 * Write a string to the 3215 console
785 con3215_write(struct console *co, const char *str, unsigned int count)
787 struct raw3215_info *raw;
792 raw = raw3215[0]; /* console 3215 is the first one */
794 for (i = 0; i < count; i++)
795 if (str[i] == '\t' || str[i] == '\n')
797 raw3215_write(raw, str, i);
801 raw3215_putchar(raw, *str);
808 static struct tty_driver *con3215_device(struct console *c, int *index)
811 return tty3215_driver;
815 * panic() calls console_unblank before the system enters a
816 * disabled, endless loop.
819 con3215_unblank(void)
821 struct raw3215_info *raw;
824 raw = raw3215[0]; /* console 3215 is the first one */
825 spin_lock_irqsave(raw->lock, flags);
826 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
827 spin_unlock_irqrestore(raw->lock, flags);
831 con3215_consetup(struct console *co, char *options)
837 * The console structure for the 3215 console
839 static struct console con3215 = {
841 .write = con3215_write,
842 .device = con3215_device,
843 .unblank = con3215_unblank,
844 .setup = con3215_consetup,
845 .flags = CON_PRINTBUFFER,
849 * 3215 console initialization code called from console_init().
850 * NOTE: This is called before kmalloc is available.
855 struct ccw_device *cdev;
856 struct raw3215_info *raw;
857 struct raw3215_req *req;
860 /* Check if 3215 is to be the console */
861 if (!CONSOLE_IS_3215)
864 /* Set the console mode for VM */
866 cpcmd("TERM CONMODE 3215", NULL, 0);
867 cpcmd("TERM AUTOCR OFF", NULL, 0);
870 /* allocate 3215 request structures */
871 raw3215_freelist = NULL;
872 spin_lock_init(&raw3215_freelist_lock);
873 for (i = 0; i < NR_3215_REQ; i++) {
874 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
875 req->next = raw3215_freelist;
876 raw3215_freelist = req;
879 cdev = ccw_device_probe_console();
883 raw3215[0] = raw = (struct raw3215_info *)
884 alloc_bootmem_low(sizeof(struct raw3215_info));
885 memset(raw, 0, sizeof(struct raw3215_info));
886 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
887 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
889 raw->lock = get_ccwdev_lock(cdev);
890 cdev->dev.driver_data = raw;
891 cdev->handler = raw3215_irq;
893 raw->flags |= RAW3215_FIXED;
894 tasklet_init(&raw->tasklet,
895 (void (*)(unsigned long)) raw3215_tasklet,
896 (unsigned long) raw);
897 init_waitqueue_head(&raw->empty_wait);
899 /* Request the console irq */
900 if (raw3215_startup(raw) != 0) {
901 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
902 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
903 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
905 printk("Couldn't find a 3215 console device\n");
908 register_console(&con3215);
911 console_initcall(con3215_init);
917 * This routine is called whenever a 3215 tty is opened.
920 tty3215_open(struct tty_struct *tty, struct file * filp)
922 struct raw3215_info *raw;
926 if ((line < 0) || (line >= NR_3215))
933 tty->driver_data = raw;
936 tty->low_latency = 0; /* don't use bottom half for pushing chars */
938 * Start up 3215 device
940 retval = raw3215_startup(raw);
950 * This routine is called when the 3215 tty is closed. We wait
951 * for the remaining request to be completed. Then we clean up.
954 tty3215_close(struct tty_struct *tty, struct file * filp)
956 struct raw3215_info *raw;
958 raw = (struct raw3215_info *) tty->driver_data;
959 if (raw == NULL || tty->count > 1)
962 /* Shutdown the terminal */
963 raw3215_shutdown(raw);
969 * Returns the amount of free space in the output buffer.
972 tty3215_write_room(struct tty_struct *tty)
974 struct raw3215_info *raw;
976 raw = (struct raw3215_info *) tty->driver_data;
978 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
979 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
980 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
986 * String write routine for 3215 ttys
989 tty3215_write(struct tty_struct * tty, int from_user,
990 const unsigned char *buf, int count)
992 struct raw3215_info *raw;
997 raw = (struct raw3215_info *) tty->driver_data;
999 raw3215_write(raw, buf, count);
1004 length = count < 80 ? count : 80;
1005 length -= copy_from_user(raw->ubuffer,
1006 (const unsigned char __user *)buf, length);
1012 raw3215_write(raw, raw->ubuffer, count);
1021 * Put character routine for 3215 ttys
1024 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
1026 struct raw3215_info *raw;
1030 raw = (struct raw3215_info *) tty->driver_data;
1031 raw3215_putchar(raw, ch);
1035 tty3215_flush_chars(struct tty_struct *tty)
1040 * Returns the number of characters in the output buffer
1043 tty3215_chars_in_buffer(struct tty_struct *tty)
1045 struct raw3215_info *raw;
1047 raw = (struct raw3215_info *) tty->driver_data;
1052 tty3215_flush_buffer(struct tty_struct *tty)
1054 struct raw3215_info *raw;
1056 raw = (struct raw3215_info *) tty->driver_data;
1057 raw3215_flush_buffer(raw);
1058 wake_up_interruptible(&tty->write_wait);
1059 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1060 tty->ldisc.write_wakeup)
1061 (tty->ldisc.write_wakeup)(tty);
1065 * Currently we don't have any io controls for 3215 ttys
1068 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1069 unsigned int cmd, unsigned long arg)
1071 if (tty->flags & (1 << TTY_IO_ERROR))
1076 return -ENOIOCTLCMD;
1082 * Disable reading from a 3215 tty
1085 tty3215_throttle(struct tty_struct * tty)
1087 struct raw3215_info *raw;
1089 raw = (struct raw3215_info *) tty->driver_data;
1090 raw->flags |= RAW3215_THROTTLED;
1094 * Enable reading from a 3215 tty
1097 tty3215_unthrottle(struct tty_struct * tty)
1099 struct raw3215_info *raw;
1100 unsigned long flags;
1102 raw = (struct raw3215_info *) tty->driver_data;
1103 if (raw->flags & RAW3215_THROTTLED) {
1104 spin_lock_irqsave(raw->lock, flags);
1105 raw->flags &= ~RAW3215_THROTTLED;
1106 raw3215_try_io(raw);
1107 spin_unlock_irqrestore(raw->lock, flags);
1112 * Disable writing to a 3215 tty
1115 tty3215_stop(struct tty_struct *tty)
1117 struct raw3215_info *raw;
1119 raw = (struct raw3215_info *) tty->driver_data;
1120 raw->flags |= RAW3215_STOPPED;
1124 * Enable writing to a 3215 tty
1127 tty3215_start(struct tty_struct *tty)
1129 struct raw3215_info *raw;
1130 unsigned long flags;
1132 raw = (struct raw3215_info *) tty->driver_data;
1133 if (raw->flags & RAW3215_STOPPED) {
1134 spin_lock_irqsave(raw->lock, flags);
1135 raw->flags &= ~RAW3215_STOPPED;
1136 raw3215_try_io(raw);
1137 spin_unlock_irqrestore(raw->lock, flags);
1141 static struct tty_operations tty3215_ops = {
1142 .open = tty3215_open,
1143 .close = tty3215_close,
1144 .write = tty3215_write,
1145 .put_char = tty3215_put_char,
1146 .flush_chars = tty3215_flush_chars,
1147 .write_room = tty3215_write_room,
1148 .chars_in_buffer = tty3215_chars_in_buffer,
1149 .flush_buffer = tty3215_flush_buffer,
1150 .ioctl = tty3215_ioctl,
1151 .throttle = tty3215_throttle,
1152 .unthrottle = tty3215_unthrottle,
1153 .stop = tty3215_stop,
1154 .start = tty3215_start,
1158 * 3215 tty registration code called from tty_init().
1159 * Most kernel services (incl. kmalloc) are available at this poimt.
1164 struct tty_driver *driver;
1167 if (!CONSOLE_IS_3215)
1170 driver = alloc_tty_driver(NR_3215);
1174 ret = ccw_driver_register(&raw3215_ccw_driver);
1176 put_tty_driver(driver);
1180 * Initialize the tty_driver structure
1181 * Entries in tty3215_driver that are NOT initialized:
1182 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1185 driver->owner = THIS_MODULE;
1186 driver->driver_name = "tty3215";
1187 driver->name = "ttyS";
1188 driver->major = TTY_MAJOR;
1189 driver->minor_start = 64;
1190 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1191 driver->subtype = SYSTEM_TYPE_TTY;
1192 driver->init_termios = tty_std_termios;
1193 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1194 driver->init_termios.c_oflag = ONLCR | XTABS;
1195 driver->init_termios.c_lflag = ISIG;
1196 driver->flags = TTY_DRIVER_REAL_RAW;
1197 tty_set_operations(driver, &tty3215_ops);
1198 ret = tty_register_driver(driver);
1200 printk("Couldn't register tty3215 driver\n");
1201 put_tty_driver(driver);
1204 tty3215_driver = driver;
1211 tty_unregister_driver(tty3215_driver);
1212 put_tty_driver(tty3215_driver);
1213 ccw_driver_unregister(&raw3215_ccw_driver);
1216 module_init(tty3215_init);
1217 module_exit(tty3215_exit);