2 * 3215 line mode terminal driver.
4 * Copyright IBM Corp. 1999, 2009
5 * Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>
8 * Aug-2000: Added tab support
9 * Dan Morrison, IBM Corporation <dmorriso@cse.buffalo.edu>
12 #include <linux/module.h>
13 #include <linux/types.h>
14 #include <linux/kdev_t.h>
15 #include <linux/tty.h>
16 #include <linux/tty_flip.h>
17 #include <linux/vt_kern.h>
18 #include <linux/init.h>
19 #include <linux/console.h>
20 #include <linux/interrupt.h>
21 #include <linux/err.h>
22 #include <linux/reboot.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) */
57 #define RAW3215_FROZEN 256 /* set if 3215 is frozen for suspend */
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 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 int line_pos; /* position on the line (for tabs) */
96 char ubuffer[80]; /* copy_from_user buffer */
99 /* array of 3215 devices structures */
100 static struct raw3215_info *raw3215[NR_3215];
101 /* spinlock to protect the raw3215 array */
102 static DEFINE_SPINLOCK(raw3215_device_lock);
103 /* list of free request structures */
104 static struct raw3215_req *raw3215_freelist;
105 /* spinlock to protect free list */
106 static spinlock_t raw3215_freelist_lock;
108 static struct tty_driver *tty3215_driver;
111 * Get a request structure from the free list
113 static inline struct raw3215_req *raw3215_alloc_req(void)
115 struct raw3215_req *req;
118 spin_lock_irqsave(&raw3215_freelist_lock, flags);
119 req = raw3215_freelist;
120 raw3215_freelist = req->next;
121 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
126 * Put a request structure back to the free list
128 static inline void raw3215_free_req(struct raw3215_req *req)
132 if (req->type == RAW3215_FREE)
133 return; /* don't free a free request */
134 req->type = RAW3215_FREE;
135 spin_lock_irqsave(&raw3215_freelist_lock, flags);
136 req->next = raw3215_freelist;
137 raw3215_freelist = req;
138 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
142 * Set up a read request that reads up to 160 byte from the 3215 device.
143 * If there is a queued read request it is used, but that shouldn't happen
144 * because a 3215 terminal won't accept a new read before the old one is
147 static void raw3215_mk_read_req(struct raw3215_info *raw)
149 struct raw3215_req *req;
152 /* there can only be ONE read request at a time */
153 req = raw->queued_read;
155 /* no queued read request, use new req structure */
156 req = raw3215_alloc_req();
157 req->type = RAW3215_READ;
159 raw->queued_read = req;
163 ccw->cmd_code = 0x0A; /* read inquiry */
164 ccw->flags = 0x20; /* ignore incorrect length */
166 ccw->cda = (__u32) __pa(raw->inbuf);
170 * Set up a write request with the information from the main structure.
171 * A ccw chain is created that writes as much as possible from the output
172 * buffer to the 3215 device. If a queued write exists it is replaced by
173 * the new, probably lengthened request.
175 static void raw3215_mk_write_req(struct raw3215_info *raw)
177 struct raw3215_req *req;
179 int len, count, ix, lines;
181 if (raw->count <= raw->written)
183 /* check if there is a queued write request */
184 req = raw->queued_write;
186 /* no queued write request, use new req structure */
187 req = raw3215_alloc_req();
188 req->type = RAW3215_WRITE;
190 raw->queued_write = req;
192 raw->written -= req->len;
196 req->start = (raw->head - raw->count + raw->written) &
197 (RAW3215_BUFFER_SIZE - 1);
199 * now we have to count newlines. We can at max accept
200 * RAW3215_MAX_NEWLINE newlines in a single ssch due to
201 * a restriction in VM
205 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
206 if (raw->buffer[ix] == 0x15)
208 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
210 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
211 if (len > RAW3215_MAX_BYTES)
212 len = RAW3215_MAX_BYTES;
216 /* set the indication if we should try to enlarge this request */
217 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
222 ccw[-1].flags |= 0x40; /* use command chaining */
223 ccw->cmd_code = 0x01; /* write, auto carrier return */
224 ccw->flags = 0x20; /* ignore incorrect length ind. */
226 (__u32) __pa(raw->buffer + ix);
228 if (ix + count > RAW3215_BUFFER_SIZE)
229 count = RAW3215_BUFFER_SIZE - ix;
232 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
236 * Add a NOP to the channel program. 3215 devices are purely
237 * emulated and its much better to avoid the channel end
238 * interrupt in this case.
241 ccw[-1].flags |= 0x40; /* use command chaining */
242 ccw->cmd_code = 0x03; /* NOP */
249 * Start a read or a write request
251 static void raw3215_start_io(struct raw3215_info *raw)
253 struct raw3215_req *req;
256 req = raw->queued_read;
258 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
259 /* dequeue request */
260 raw->queued_read = NULL;
261 res = ccw_device_start(raw->cdev, req->ccws,
262 (unsigned long) req, 0, 0);
264 /* do_IO failed, put request back to queue */
265 raw->queued_read = req;
267 raw->flags |= RAW3215_WORKING;
270 req = raw->queued_write;
272 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
273 /* dequeue request */
274 raw->queued_write = NULL;
275 res = ccw_device_start(raw->cdev, req->ccws,
276 (unsigned long) req, 0, 0);
278 /* do_IO failed, put request back to queue */
279 raw->queued_write = req;
281 raw->flags |= RAW3215_WORKING;
287 * Function to start a delayed output after RAW3215_TIMEOUT seconds
289 static void raw3215_timeout(unsigned long __data)
291 struct raw3215_info *raw = (struct raw3215_info *) __data;
294 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
295 if (raw->flags & RAW3215_TIMER_RUNS) {
296 del_timer(&raw->timer);
297 raw->flags &= ~RAW3215_TIMER_RUNS;
298 if (!(raw->flags & RAW3215_FROZEN)) {
299 raw3215_mk_write_req(raw);
300 raw3215_start_io(raw);
303 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
307 * Function to conditionally start an IO. A read is started immediately,
308 * a write is only started immediately if the flush flag is on or the
309 * amount of data is bigger than RAW3215_MIN_WRITE. If a write is not
310 * done immediately a timer is started with a delay of RAW3215_TIMEOUT.
312 static inline void raw3215_try_io(struct raw3215_info *raw)
314 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FROZEN))
316 if (raw->queued_read != NULL)
317 raw3215_start_io(raw);
318 else if (raw->queued_write != NULL) {
319 if ((raw->queued_write->delayable == 0) ||
320 (raw->flags & RAW3215_FLUSHING)) {
321 /* execute write requests bigger than minimum size */
322 raw3215_start_io(raw);
323 if (raw->flags & RAW3215_TIMER_RUNS) {
324 del_timer(&raw->timer);
325 raw->flags &= ~RAW3215_TIMER_RUNS;
327 } else if (!(raw->flags & RAW3215_TIMER_RUNS)) {
328 /* delay small writes */
329 init_timer(&raw->timer);
330 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
331 raw->timer.data = (unsigned long) raw;
332 raw->timer.function = raw3215_timeout;
333 add_timer(&raw->timer);
334 raw->flags |= RAW3215_TIMER_RUNS;
340 * Try to start the next IO and wake up processes waiting on the tty.
342 static void raw3215_next_io(struct raw3215_info *raw)
344 struct tty_struct *tty;
346 raw3215_mk_write_req(raw);
350 RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE) {
356 * Interrupt routine, called from common io layer
358 static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
361 struct raw3215_info *raw;
362 struct raw3215_req *req;
363 struct tty_struct *tty;
367 raw = dev_get_drvdata(&cdev->dev);
368 req = (struct raw3215_req *) intparm;
369 cstat = irb->scsw.cmd.cstat;
370 dstat = irb->scsw.cmd.dstat;
372 raw3215_next_io(raw);
373 if (dstat & 0x01) { /* we got a unit exception */
374 dstat &= ~0x01; /* we can ignore it */
380 /* Attention interrupt, someone hit the enter key */
381 raw3215_mk_read_req(raw);
382 raw3215_next_io(raw);
386 /* Channel end interrupt. */
387 if ((raw = req->info) == NULL)
388 return; /* That shouldn't happen ... */
389 if (req->type == RAW3215_READ) {
390 /* store residual count, then wait for device end */
391 req->residual = irb->scsw.cmd.count;
396 /* Device end interrupt. */
397 if ((raw = req->info) == NULL)
398 return; /* That shouldn't happen ... */
399 if (req->type == RAW3215_READ && raw->tty != NULL) {
403 count = 160 - req->residual;
404 EBCASC(raw->inbuf, count);
405 cchar = ctrlchar_handle(raw->inbuf, count, tty);
406 switch (cchar & CTRLCHAR_MASK) {
411 tty_insert_flip_char(tty, cchar, TTY_NORMAL);
412 tty_flip_buffer_push(raw->tty);
417 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
418 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
419 /* add the auto \n */
420 raw->inbuf[count] = '\n';
424 tty_insert_flip_string(tty, raw->inbuf, count);
425 tty_flip_buffer_push(raw->tty);
428 } else if (req->type == RAW3215_WRITE) {
429 raw->count -= req->len;
430 raw->written -= req->len;
432 raw->flags &= ~RAW3215_WORKING;
433 raw3215_free_req(req);
434 /* check for empty wait */
435 if (waitqueue_active(&raw->empty_wait) &&
436 raw->queued_write == NULL &&
437 raw->queued_read == NULL) {
438 wake_up_interruptible(&raw->empty_wait);
440 raw3215_next_io(raw);
443 /* Strange interrupt, I'll do my best to clean up */
444 if (req != NULL && req->type != RAW3215_FREE) {
445 if (req->type == RAW3215_WRITE) {
446 raw->count -= req->len;
447 raw->written -= req->len;
449 raw->flags &= ~RAW3215_WORKING;
450 raw3215_free_req(req);
452 raw3215_next_io(raw);
458 * Drop the oldest line from the output buffer.
460 static void raw3215_drop_line(struct raw3215_info *raw)
465 BUG_ON(raw->written != 0);
466 ix = (raw->head - raw->count) & (RAW3215_BUFFER_SIZE - 1);
467 while (raw->count > 0) {
468 ch = raw->buffer[ix];
469 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
478 * Wait until length bytes are available int the output buffer.
479 * Has to be called with the s390irq lock held. Can be called
482 static void raw3215_make_room(struct raw3215_info *raw, unsigned int length)
484 while (RAW3215_BUFFER_SIZE - raw->count < length) {
485 /* While console is frozen for suspend we have no other
486 * choice but to drop message from the buffer to make
487 * room for even more messages. */
488 if (raw->flags & RAW3215_FROZEN) {
489 raw3215_drop_line(raw);
492 /* there might be a request pending */
493 raw->flags |= RAW3215_FLUSHING;
494 raw3215_mk_write_req(raw);
496 raw->flags &= ~RAW3215_FLUSHING;
497 #ifdef CONFIG_TN3215_CONSOLE
500 /* Enough room freed up ? */
501 if (RAW3215_BUFFER_SIZE - raw->count >= length)
503 /* there might be another cpu waiting for the lock */
504 spin_unlock(get_ccwdev_lock(raw->cdev));
506 spin_lock(get_ccwdev_lock(raw->cdev));
511 * String write routine for 3215 devices
513 static void raw3215_write(struct raw3215_info *raw, const char *str,
520 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
521 count = (length > RAW3215_BUFFER_SIZE) ?
522 RAW3215_BUFFER_SIZE : length;
525 raw3215_make_room(raw, count);
527 /* copy string to output buffer and convert it to EBCDIC */
529 c = min_t(int, count,
530 min(RAW3215_BUFFER_SIZE - raw->count,
531 RAW3215_BUFFER_SIZE - raw->head));
534 memcpy(raw->buffer + raw->head, str, c);
535 ASCEBC(raw->buffer + raw->head, c);
536 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
542 if (!(raw->flags & RAW3215_WORKING)) {
543 raw3215_mk_write_req(raw);
544 /* start or queue request */
547 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
552 * Put character routine for 3215 devices
554 static void raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
557 unsigned int length, i;
559 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
561 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
562 raw->line_pos += length;
564 } else if (ch == '\n') {
571 raw3215_make_room(raw, length);
573 for (i = 0; i < length; i++) {
574 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
575 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
578 if (!(raw->flags & RAW3215_WORKING)) {
579 raw3215_mk_write_req(raw);
580 /* start or queue request */
583 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
587 * Flush routine, it simply sets the flush flag and tries to start
590 static void raw3215_flush_buffer(struct raw3215_info *raw)
594 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
595 if (raw->count > 0) {
596 raw->flags |= RAW3215_FLUSHING;
598 raw->flags &= ~RAW3215_FLUSHING;
600 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
604 * Fire up a 3215 device.
606 static int raw3215_startup(struct raw3215_info *raw)
610 if (raw->flags & RAW3215_ACTIVE)
613 raw->flags |= RAW3215_ACTIVE;
614 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
616 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
622 * Shutdown a 3215 device.
624 static void raw3215_shutdown(struct raw3215_info *raw)
626 DECLARE_WAITQUEUE(wait, current);
629 if (!(raw->flags & RAW3215_ACTIVE) || (raw->flags & RAW3215_FIXED))
631 /* Wait for outstanding requests, then free irq */
632 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
633 if ((raw->flags & RAW3215_WORKING) ||
634 raw->queued_write != NULL ||
635 raw->queued_read != NULL) {
636 raw->flags |= RAW3215_CLOSING;
637 add_wait_queue(&raw->empty_wait, &wait);
638 set_current_state(TASK_INTERRUPTIBLE);
639 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
641 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
642 remove_wait_queue(&raw->empty_wait, &wait);
643 set_current_state(TASK_RUNNING);
644 raw->flags &= ~(RAW3215_ACTIVE | RAW3215_CLOSING);
646 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
649 static int raw3215_probe (struct ccw_device *cdev)
651 struct raw3215_info *raw;
654 /* Console is special. */
655 if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev)))
657 raw = kmalloc(sizeof(struct raw3215_info) +
658 RAW3215_INBUF_SIZE, GFP_KERNEL|GFP_DMA);
662 spin_lock(&raw3215_device_lock);
663 for (line = 0; line < NR_3215; line++) {
664 if (!raw3215[line]) {
669 spin_unlock(&raw3215_device_lock);
670 if (line == NR_3215) {
676 raw->inbuf = (char *) raw + sizeof(struct raw3215_info);
677 memset(raw, 0, sizeof(struct raw3215_info));
678 raw->buffer = kmalloc(RAW3215_BUFFER_SIZE,
680 if (raw->buffer == NULL) {
681 spin_lock(&raw3215_device_lock);
682 raw3215[line] = NULL;
683 spin_unlock(&raw3215_device_lock);
687 init_waitqueue_head(&raw->empty_wait);
689 dev_set_drvdata(&cdev->dev, raw);
690 cdev->handler = raw3215_irq;
695 static void raw3215_remove (struct ccw_device *cdev)
697 struct raw3215_info *raw;
699 ccw_device_set_offline(cdev);
700 raw = dev_get_drvdata(&cdev->dev);
702 dev_set_drvdata(&cdev->dev, NULL);
708 static int raw3215_set_online (struct ccw_device *cdev)
710 struct raw3215_info *raw;
712 raw = dev_get_drvdata(&cdev->dev);
716 return raw3215_startup(raw);
719 static int raw3215_set_offline (struct ccw_device *cdev)
721 struct raw3215_info *raw;
723 raw = dev_get_drvdata(&cdev->dev);
727 raw3215_shutdown(raw);
732 static int raw3215_pm_stop(struct ccw_device *cdev)
734 struct raw3215_info *raw;
737 /* Empty the output buffer, then prevent new I/O. */
738 raw = cdev->dev.driver_data;
739 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
740 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
741 raw->flags |= RAW3215_FROZEN;
742 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
746 static int raw3215_pm_start(struct ccw_device *cdev)
748 struct raw3215_info *raw;
751 /* Allow I/O again and flush output buffer. */
752 raw = cdev->dev.driver_data;
753 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
754 raw->flags &= ~RAW3215_FROZEN;
755 raw->flags |= RAW3215_FLUSHING;
757 raw->flags &= ~RAW3215_FLUSHING;
758 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
762 static struct ccw_device_id raw3215_id[] = {
763 { CCW_DEVICE(0x3215, 0) },
764 { /* end of list */ },
767 static struct ccw_driver raw3215_ccw_driver = {
769 .owner = THIS_MODULE,
771 .probe = &raw3215_probe,
772 .remove = &raw3215_remove,
773 .set_online = &raw3215_set_online,
774 .set_offline = &raw3215_set_offline,
775 .freeze = &raw3215_pm_stop,
776 .thaw = &raw3215_pm_start,
777 .restore = &raw3215_pm_start,
780 #ifdef CONFIG_TN3215_CONSOLE
782 * Write a string to the 3215 console
784 static void con3215_write(struct console *co, const char *str,
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 con3215_flush through a panic_notifier
816 * before the system enters a disabled, endless loop.
818 static void con3215_flush(void)
820 struct raw3215_info *raw;
823 raw = raw3215[0]; /* console 3215 is the first one */
824 if (raw->flags & RAW3215_FROZEN)
825 /* The console is still frozen for suspend. */
826 if (ccw_device_force_console())
827 /* Forcing didn't work, no panic message .. */
829 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
830 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
831 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
834 static int con3215_notify(struct notifier_block *self,
835 unsigned long event, void *data)
841 static struct notifier_block on_panic_nb = {
842 .notifier_call = con3215_notify,
846 static struct notifier_block on_reboot_nb = {
847 .notifier_call = con3215_notify,
852 * The console structure for the 3215 console
854 static struct console con3215 = {
856 .write = con3215_write,
857 .device = con3215_device,
858 .flags = CON_PRINTBUFFER,
862 * 3215 console initialization code called from console_init().
863 * NOTE: This is called before kmalloc is available.
865 static int __init con3215_init(void)
867 struct ccw_device *cdev;
868 struct raw3215_info *raw;
869 struct raw3215_req *req;
872 /* Check if 3215 is to be the console */
873 if (!CONSOLE_IS_3215)
876 /* Set the console mode for VM */
878 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
879 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
882 /* allocate 3215 request structures */
883 raw3215_freelist = NULL;
884 spin_lock_init(&raw3215_freelist_lock);
885 for (i = 0; i < NR_3215_REQ; i++) {
886 req = (struct raw3215_req *) alloc_bootmem_low(sizeof(struct raw3215_req));
887 req->next = raw3215_freelist;
888 raw3215_freelist = req;
891 cdev = ccw_device_probe_console();
895 raw3215[0] = raw = (struct raw3215_info *)
896 alloc_bootmem_low(sizeof(struct raw3215_info));
897 memset(raw, 0, sizeof(struct raw3215_info));
898 raw->buffer = (char *) alloc_bootmem_low(RAW3215_BUFFER_SIZE);
899 raw->inbuf = (char *) alloc_bootmem_low(RAW3215_INBUF_SIZE);
901 dev_set_drvdata(&cdev->dev, raw);
902 cdev->handler = raw3215_irq;
904 raw->flags |= RAW3215_FIXED;
905 init_waitqueue_head(&raw->empty_wait);
907 /* Request the console irq */
908 if (raw3215_startup(raw) != 0) {
909 free_bootmem((unsigned long) raw->inbuf, RAW3215_INBUF_SIZE);
910 free_bootmem((unsigned long) raw->buffer, RAW3215_BUFFER_SIZE);
911 free_bootmem((unsigned long) raw, sizeof(struct raw3215_info));
915 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
916 register_reboot_notifier(&on_reboot_nb);
917 register_console(&con3215);
920 console_initcall(con3215_init);
926 * This routine is called whenever a 3215 tty is opened.
928 static int tty3215_open(struct tty_struct *tty, struct file * filp)
930 struct raw3215_info *raw;
934 if ((line < 0) || (line >= NR_3215))
941 tty->driver_data = raw;
944 tty->low_latency = 0; /* don't use bottom half for pushing chars */
946 * Start up 3215 device
948 retval = raw3215_startup(raw);
958 * This routine is called when the 3215 tty is closed. We wait
959 * for the remaining request to be completed. Then we clean up.
961 static void tty3215_close(struct tty_struct *tty, struct file * filp)
963 struct raw3215_info *raw;
965 raw = (struct raw3215_info *) tty->driver_data;
966 if (raw == NULL || tty->count > 1)
969 /* Shutdown the terminal */
970 raw3215_shutdown(raw);
976 * Returns the amount of free space in the output buffer.
978 static int tty3215_write_room(struct tty_struct *tty)
980 struct raw3215_info *raw;
982 raw = (struct raw3215_info *) tty->driver_data;
984 /* Subtract TAB_STOP_SIZE to allow for a tab, 8 <<< 64K */
985 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
986 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
992 * String write routine for 3215 ttys
994 static int tty3215_write(struct tty_struct * tty,
995 const unsigned char *buf, int count)
997 struct raw3215_info *raw;
1001 raw = (struct raw3215_info *) tty->driver_data;
1002 raw3215_write(raw, buf, count);
1007 * Put character routine for 3215 ttys
1009 static int tty3215_put_char(struct tty_struct *tty, unsigned char ch)
1011 struct raw3215_info *raw;
1015 raw = (struct raw3215_info *) tty->driver_data;
1016 raw3215_putchar(raw, ch);
1020 static void tty3215_flush_chars(struct tty_struct *tty)
1025 * Returns the number of characters in the output buffer
1027 static int tty3215_chars_in_buffer(struct tty_struct *tty)
1029 struct raw3215_info *raw;
1031 raw = (struct raw3215_info *) tty->driver_data;
1035 static void tty3215_flush_buffer(struct tty_struct *tty)
1037 struct raw3215_info *raw;
1039 raw = (struct raw3215_info *) tty->driver_data;
1040 raw3215_flush_buffer(raw);
1045 * Currently we don't have any io controls for 3215 ttys
1047 static int tty3215_ioctl(struct tty_struct *tty, struct file * file,
1048 unsigned int cmd, unsigned long arg)
1050 if (tty->flags & (1 << TTY_IO_ERROR))
1055 return -ENOIOCTLCMD;
1061 * Disable reading from a 3215 tty
1063 static void tty3215_throttle(struct tty_struct * tty)
1065 struct raw3215_info *raw;
1067 raw = (struct raw3215_info *) tty->driver_data;
1068 raw->flags |= RAW3215_THROTTLED;
1072 * Enable reading from a 3215 tty
1074 static void tty3215_unthrottle(struct tty_struct * tty)
1076 struct raw3215_info *raw;
1077 unsigned long flags;
1079 raw = (struct raw3215_info *) tty->driver_data;
1080 if (raw->flags & RAW3215_THROTTLED) {
1081 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1082 raw->flags &= ~RAW3215_THROTTLED;
1083 raw3215_try_io(raw);
1084 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1089 * Disable writing to a 3215 tty
1091 static void tty3215_stop(struct tty_struct *tty)
1093 struct raw3215_info *raw;
1095 raw = (struct raw3215_info *) tty->driver_data;
1096 raw->flags |= RAW3215_STOPPED;
1100 * Enable writing to a 3215 tty
1102 static void tty3215_start(struct tty_struct *tty)
1104 struct raw3215_info *raw;
1105 unsigned long flags;
1107 raw = (struct raw3215_info *) tty->driver_data;
1108 if (raw->flags & RAW3215_STOPPED) {
1109 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1110 raw->flags &= ~RAW3215_STOPPED;
1111 raw3215_try_io(raw);
1112 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1116 static const struct tty_operations tty3215_ops = {
1117 .open = tty3215_open,
1118 .close = tty3215_close,
1119 .write = tty3215_write,
1120 .put_char = tty3215_put_char,
1121 .flush_chars = tty3215_flush_chars,
1122 .write_room = tty3215_write_room,
1123 .chars_in_buffer = tty3215_chars_in_buffer,
1124 .flush_buffer = tty3215_flush_buffer,
1125 .ioctl = tty3215_ioctl,
1126 .throttle = tty3215_throttle,
1127 .unthrottle = tty3215_unthrottle,
1128 .stop = tty3215_stop,
1129 .start = tty3215_start,
1133 * 3215 tty registration code called from tty_init().
1134 * Most kernel services (incl. kmalloc) are available at this poimt.
1136 static int __init tty3215_init(void)
1138 struct tty_driver *driver;
1141 if (!CONSOLE_IS_3215)
1144 driver = alloc_tty_driver(NR_3215);
1148 ret = ccw_driver_register(&raw3215_ccw_driver);
1150 put_tty_driver(driver);
1154 * Initialize the tty_driver structure
1155 * Entries in tty3215_driver that are NOT initialized:
1156 * proc_entry, set_termios, flush_buffer, set_ldisc, write_proc
1159 driver->owner = THIS_MODULE;
1160 driver->driver_name = "tty3215";
1161 driver->name = "ttyS";
1162 driver->major = TTY_MAJOR;
1163 driver->minor_start = 64;
1164 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1165 driver->subtype = SYSTEM_TYPE_TTY;
1166 driver->init_termios = tty_std_termios;
1167 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1168 driver->init_termios.c_oflag = ONLCR | XTABS;
1169 driver->init_termios.c_lflag = ISIG;
1170 driver->flags = TTY_DRIVER_REAL_RAW;
1171 tty_set_operations(driver, &tty3215_ops);
1172 ret = tty_register_driver(driver);
1174 put_tty_driver(driver);
1177 tty3215_driver = driver;
1181 static void __exit tty3215_exit(void)
1183 tty_unregister_driver(tty3215_driver);
1184 put_tty_driver(tty3215_driver);
1185 ccw_driver_unregister(&raw3215_ccw_driver);
1188 module_init(tty3215_init);
1189 module_exit(tty3215_exit);