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 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 * Try to start the next IO and wake up processes waiting on the tty.
346 static void raw3215_next_io(struct raw3215_info *raw)
348 struct tty_struct *tty;
350 raw3215_mk_write_req(raw);
354 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
360 * Interrupt routine, called from common io layer
363 raw3215_irq(struct ccw_device *cdev, unsigned long intparm, struct irb *irb)
365 struct raw3215_info *raw;
366 struct raw3215_req *req;
367 struct tty_struct *tty;
371 raw = cdev->dev.driver_data;
372 req = (struct raw3215_req *) intparm;
373 cstat = irb->scsw.cmd.cstat;
374 dstat = irb->scsw.cmd.dstat;
376 raw3215_next_io(raw);
377 if (dstat & 0x01) { /* we got a unit exception */
378 dstat &= ~0x01; /* we can ignore it */
384 /* Attention interrupt, someone hit the enter key */
385 raw3215_mk_read_req(raw);
386 raw3215_next_io(raw);
390 /* Channel end interrupt. */
391 if ((raw = req->info) == NULL)
392 return; /* That shouldn't happen ... */
393 if (req->type == RAW3215_READ) {
394 /* store residual count, then wait for device end */
395 req->residual = irb->scsw.cmd.count;
400 /* Device end interrupt. */
401 if ((raw = req->info) == NULL)
402 return; /* That shouldn't happen ... */
403 if (req->type == RAW3215_READ && raw->tty != NULL) {
407 count = 160 - req->residual;
408 EBCASC(raw->inbuf, count);
409 cchar = ctrlchar_handle(raw->inbuf, count, tty);
410 switch (cchar & CTRLCHAR_MASK) {
415 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
416 tty_flip_buffer_push(raw->tty);
421 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
422 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
423 /* add the auto \n */
424 raw->inbuf[count] = '\n';
428 tty_insert_flip_string(tty, raw->inbuf, count);
429 tty_flip_buffer_push(raw->tty);
432 } else if (req->type == RAW3215_WRITE) {
433 raw->count -= req->len;
434 raw->written -= req->len;
436 raw->flags &= ~RAW3215_WORKING;
437 raw3215_free_req(req);
438 /* check for empty wait */
439 if (waitqueue_active(&raw->empty_wait) &&
440 raw->queued_write == NULL &&
441 raw->queued_read == NULL) {
442 wake_up_interruptible(&raw->empty_wait);
444 raw3215_next_io(raw);
447 /* Strange interrupt, I'll do my best to clean up */
448 if (req != NULL && req->type != RAW3215_FREE) {
449 if (req->type == RAW3215_WRITE) {
450 raw->count -= req->len;
451 raw->written -= req->len;
453 raw->flags &= ~RAW3215_WORKING;
454 raw3215_free_req(req);
456 raw3215_next_io(raw);
462 * Wait until length bytes are available int the output buffer.
463 * Has to be called with the s390irq lock held. Can be called
467 raw3215_make_room(struct raw3215_info *raw, unsigned int length)
469 while (RAW3215_BUFFER_SIZE - raw->count < length) {
470 /* there might be a request pending */
471 raw->flags |= RAW3215_FLUSHING;
472 raw3215_mk_write_req(raw);
474 raw->flags &= ~RAW3215_FLUSHING;
475 #ifdef CONFIG_TN3215_CONSOLE
478 /* Enough room freed up ? */
479 if (RAW3215_BUFFER_SIZE - raw->count >= length)
481 /* there might be another cpu waiting for the lock */
482 spin_unlock(get_ccwdev_lock(raw->cdev));
484 spin_lock(get_ccwdev_lock(raw->cdev));
489 * String write routine for 3215 devices
492 raw3215_write(struct raw3215_info *raw, const char *str, unsigned int length)
498 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
499 count = (length > RAW3215_BUFFER_SIZE) ?
500 RAW3215_BUFFER_SIZE : length;
503 raw3215_make_room(raw, count);
505 /* copy string to output buffer and convert it to EBCDIC */
507 c = min_t(int, count,
508 min(RAW3215_BUFFER_SIZE - raw->count,
509 RAW3215_BUFFER_SIZE - raw->head));
512 memcpy(raw->buffer + raw->head, str, c);
513 ASCEBC(raw->buffer + raw->head, c);
514 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
520 if (!(raw->flags & RAW3215_WORKING)) {
521 raw3215_mk_write_req(raw);
522 /* start or queue request */
525 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
530 * Put character routine for 3215 devices
533 raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
536 unsigned int length, i;
538 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
540 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
541 raw->line_pos += length;
543 } else if (ch == '\n') {
550 raw3215_make_room(raw, length);
552 for (i = 0; i < length; i++) {
553 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
554 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
557 if (!(raw->flags & RAW3215_WORKING)) {
558 raw3215_mk_write_req(raw);
559 /* start or queue request */
562 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
566 * Flush routine, it simply sets the flush flag and tries to start
570 raw3215_flush_buffer(struct raw3215_info *raw)
574 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
575 if (raw->count > 0) {
576 raw->flags |= RAW3215_FLUSHING;
578 raw->flags &= ~RAW3215_FLUSHING;
580 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
584 * Fire up a 3215 device.
587 raw3215_startup(struct raw3215_info *raw)
591 if (raw->flags & RAW3215_ACTIVE)
594 raw->flags |= RAW3215_ACTIVE;
595 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
597 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
603 * Shutdown a 3215 device.
606 raw3215_shutdown(struct raw3215_info *raw)
608 DECLARE_WAITQUEUE(wait, current);
611 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
613 /* Wait for outstanding requests, then free irq */
614 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
615 if ((raw->flags & RAW3215_WORKING) ||
616 raw->queued_write != NULL ||
617 raw->queued_read != NULL) {
618 raw->flags |= RAW3215_CLOSING;
619 add_wait_queue(&raw->empty_wait, &wait);
620 set_current_state(TASK_INTERRUPTIBLE);
621 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
623 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
624 remove_wait_queue(&raw->empty_wait, &wait);
625 set_current_state(TASK_RUNNING);
626 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
628 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
632 raw3215_probe (struct ccw_device *cdev)
634 struct raw3215_info *raw;
637 /* Console is special. */
638 if (raw3215[0] && (cdev->dev.driver_data == raw3215[0]))
640 raw = kmalloc(sizeof(struct raw3215_info) +
641 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
645 spin_lock(&raw3215_device_lock);
646 for (line = 0; line < NR_3215; line++) {
647 if (!raw3215[line]) {
652 spin_unlock(&raw3215_device_lock);
653 if (line == NR_3215) {
659 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
660 memset(raw, 0, sizeof(struct raw3215_info));
661 raw->buffer = kmalloc(RAW3215_BUFFER_SIZE,
663 if (raw->buffer == NULL) {
664 spin_lock(&raw3215_device_lock);
665 raw3215[line] = NULL;
666 spin_unlock(&raw3215_device_lock);
670 init_waitqueue_head(&raw->empty_wait);
672 cdev->dev.driver_data = raw;
673 cdev->handler = raw3215_irq;
679 raw3215_remove (struct ccw_device *cdev)
681 struct raw3215_info *raw;
683 ccw_device_set_offline(cdev);
684 raw = cdev->dev.driver_data;
686 cdev->dev.driver_data = NULL;
693 raw3215_set_online (struct ccw_device *cdev)
695 struct raw3215_info *raw;
697 raw = cdev->dev.driver_data;
701 return raw3215_startup(raw);
705 raw3215_set_offline (struct ccw_device *cdev)
707 struct raw3215_info *raw;
709 raw = cdev->dev.driver_data;
713 raw3215_shutdown(raw);
718 static struct ccw_device_id raw3215_id[] = {
719 { CCW_DEVICE(0x3215, 0) },
720 { /* end of list */ },
723 static struct ccw_driver raw3215_ccw_driver = {
725 .owner = THIS_MODULE,
727 .probe = &raw3215_probe,
728 .remove = &raw3215_remove,
729 .set_online = &raw3215_set_online,
730 .set_offline = &raw3215_set_offline,
733 #ifdef CONFIG_TN3215_CONSOLE
735 * Write a string to the 3215 console
738 con3215_write(struct console *co, const char *str, unsigned int count)
740 struct raw3215_info *raw;
745 raw = raw3215[0]; /* console 3215 is the first one */
747 for (i = 0; i < count; i++)
748 if (str[i] == '\t' || str[i] == '\n')
750 raw3215_write(raw, str, i);
754 raw3215_putchar(raw, *str);
761 static struct tty_driver *con3215_device(struct console *c, int *index)
764 return tty3215_driver;
768 * panic() calls con3215_flush through a panic_notifier
769 * before the system enters a disabled, endless loop.
774 struct raw3215_info *raw;
777 raw = raw3215[0]; /* console 3215 is the first one */
778 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
779 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
780 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
783 static int con3215_notify(struct notifier_block *self,
784 unsigned long event, void *data)
790 static struct notifier_block on_panic_nb = {
791 .notifier_call = con3215_notify,
795 static struct notifier_block on_reboot_nb = {
796 .notifier_call = con3215_notify,
801 * The console structure for the 3215 console
803 static struct console con3215 = {
805 .write = con3215_write,
806 .device = con3215_device,
807 .flags = CON_PRINTBUFFER,
811 * 3215 console initialization code called from console_init().
812 * NOTE: This is called before kmalloc is available.
817 struct ccw_device *cdev;
818 struct raw3215_info *raw;
819 struct raw3215_req *req;
822 /* Check if 3215 is to be the console */
823 if (!CONSOLE_IS_3215)
826 /* Set the console mode for VM */
828 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
829 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
832 /* allocate 3215 request structures */
833 raw3215_freelist = NULL;
834 spin_lock_init(&raw3215_freelist_lock);
835 for (i = 0; i < NR_3215_REQ; i++) {
836 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
837 req->next = raw3215_freelist;
838 raw3215_freelist = req;
841 cdev = ccw_device_probe_console();
845 raw3215[0] = raw = (struct raw3215_info *)
846 alloc_bootmem_low(sizeof(struct raw3215_info));
847 memset(raw, 0, sizeof(struct raw3215_info));
848 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
849 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
851 cdev->dev.driver_data = raw;
852 cdev->handler = raw3215_irq;
854 raw->flags |= RAW3215_FIXED;
855 init_waitqueue_head(&raw->empty_wait);
857 /* Request the console irq */
858 if (raw3215_startup(raw) != 0) {
859 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
860 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
861 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
865 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
866 register_reboot_notifier(&on_reboot_nb);
867 register_console(&con3215);
870 console_initcall(con3215_init);
876 * This routine is called whenever a 3215 tty is opened.
879 tty3215_open(struct tty_struct *tty, struct file * filp)
881 struct raw3215_info *raw;
885 if ((line < 0) || (line >= NR_3215))
892 tty->driver_data = raw;
895 tty->low_latency = 0; /* don't use bottom half for pushing chars */
897 * Start up 3215 device
899 retval = raw3215_startup(raw);
909 * This routine is called when the 3215 tty is closed. We wait
910 * for the remaining request to be completed. Then we clean up.
913 tty3215_close(struct tty_struct *tty, struct file * filp)
915 struct raw3215_info *raw;
917 raw = (struct raw3215_info *) tty->driver_data;
918 if (raw == NULL || tty->count > 1)
921 /* Shutdown the terminal */
922 raw3215_shutdown(raw);
928 * Returns the amount of free space in the output buffer.
931 tty3215_write_room(struct tty_struct *tty)
933 struct raw3215_info *raw;
935 raw = (struct raw3215_info *) tty->driver_data;
937 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
938 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
939 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
945 * String write routine for 3215 ttys
948 tty3215_write(struct tty_struct * tty,
949 const unsigned char *buf, int count)
951 struct raw3215_info *raw;
955 raw = (struct raw3215_info *) tty->driver_data;
956 raw3215_write(raw, buf, count);
961 * Put character routine for 3215 ttys
964 tty3215_put_char(struct tty_struct *tty, unsigned char ch)
966 struct raw3215_info *raw;
970 raw = (struct raw3215_info *) tty->driver_data;
971 raw3215_putchar(raw, ch);
976 tty3215_flush_chars(struct tty_struct *tty)
981 * Returns the number of characters in the output buffer
984 tty3215_chars_in_buffer(struct tty_struct *tty)
986 struct raw3215_info *raw;
988 raw = (struct raw3215_info *) tty->driver_data;
993 tty3215_flush_buffer(struct tty_struct *tty)
995 struct raw3215_info *raw;
997 raw = (struct raw3215_info *) tty->driver_data;
998 raw3215_flush_buffer(raw);
1003 * Currently we don't have any io controls for 3215 ttys
1006 tty3215_ioctl(struct tty_struct *tty, struct file * file,
1007 unsigned int cmd, unsigned long arg)
1009 if (tty->flags & (1 << TTY_IO_ERROR))
1014 return -ENOIOCTLCMD;
1020 * Disable reading from a 3215 tty
1023 tty3215_throttle(struct tty_struct * tty)
1025 struct raw3215_info *raw;
1027 raw = (struct raw3215_info *) tty->driver_data;
1028 raw->flags |= RAW3215_THROTTLED;
1032 * Enable reading from a 3215 tty
1035 tty3215_unthrottle(struct tty_struct * tty)
1037 struct raw3215_info *raw;
1038 unsigned long flags;
1040 raw = (struct raw3215_info *) tty->driver_data;
1041 if (raw->flags & RAW3215_THROTTLED) {
1042 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1043 raw->flags &= ~RAW3215_THROTTLED;
1044 raw3215_try_io(raw);
1045 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1050 * Disable writing to a 3215 tty
1053 tty3215_stop(struct tty_struct *tty)
1055 struct raw3215_info *raw;
1057 raw = (struct raw3215_info *) tty->driver_data;
1058 raw->flags |= RAW3215_STOPPED;
1062 * Enable writing to a 3215 tty
1065 tty3215_start(struct tty_struct *tty)
1067 struct raw3215_info *raw;
1068 unsigned long flags;
1070 raw = (struct raw3215_info *) tty->driver_data;
1071 if (raw->flags & RAW3215_STOPPED) {
1072 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1073 raw->flags &= ~RAW3215_STOPPED;
1074 raw3215_try_io(raw);
1075 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1079 static const struct tty_operations tty3215_ops = {
1080 .open = tty3215_open,
1081 .close = tty3215_close,
1082 .write = tty3215_write,
1083 .put_char = tty3215_put_char,
1084 .flush_chars = tty3215_flush_chars,
1085 .write_room = tty3215_write_room,
1086 .chars_in_buffer = tty3215_chars_in_buffer,
1087 .flush_buffer = tty3215_flush_buffer,
1088 .ioctl = tty3215_ioctl,
1089 .throttle = tty3215_throttle,
1090 .unthrottle = tty3215_unthrottle,
1091 .stop = tty3215_stop,
1092 .start = tty3215_start,
1096 * 3215 tty registration code called from tty_init().
1097 * Most kernel services (incl. kmalloc) are available at this poimt.
1102 struct tty_driver *driver;
1105 if (!CONSOLE_IS_3215)
1108 driver = alloc_tty_driver(NR_3215);
1112 ret = ccw_driver_register(&raw3215_ccw_driver);
1114 put_tty_driver(driver);
1118 * Initialize the tty_driver structure
1119 * Entries in tty3215_driver that are NOT initialized:
1120 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1123 driver->owner = THIS_MODULE;
1124 driver->driver_name = "tty3215";
1125 driver->name = "ttyS";
1126 driver->major = TTY_MAJOR;
1127 driver->minor_start = 64;
1128 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1129 driver->subtype = SYSTEM_TYPE_TTY;
1130 driver->init_termios = tty_std_termios;
1131 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1132 driver->init_termios.c_oflag = ONLCR | XTABS;
1133 driver->init_termios.c_lflag = ISIG;
1134 driver->flags = TTY_DRIVER_REAL_RAW;
1135 tty_set_operations(driver, &tty3215_ops);
1136 ret = tty_register_driver(driver);
1138 put_tty_driver(driver);
1141 tty3215_driver = driver;
1148 tty_unregister_driver(tty3215_driver);
1149 put_tty_driver(tty3215_driver);
1150 ccw_driver_unregister(&raw3215_ccw_driver);
1153 module_init(tty3215_init);
1154 module_exit(tty3215_exit);