1
2
3
4
5
6
7
8
9
10
11
12
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>
23#include <linux/serial.h>
24#include <linux/slab.h>
25#include <asm/ccwdev.h>
26#include <asm/cio.h>
27#include <asm/io.h>
28#include <asm/ebcdic.h>
29#include <linux/uaccess.h>
30#include <asm/delay.h>
31#include <asm/cpcmd.h>
32#include <asm/setup.h>
33
34#include "ctrlchar.h"
35
36#define NR_3215 1
37#define NR_3215_REQ (4*NR_3215)
38#define RAW3215_BUFFER_SIZE 65536
39#define RAW3215_INBUF_SIZE 256
40#define RAW3215_MIN_SPACE 128
41#define RAW3215_MIN_WRITE 1024
42#define RAW3215_MAX_BYTES 3968
43#define RAW3215_MAX_NEWLINE 50
44#define RAW3215_NR_CCWS 3
45#define RAW3215_TIMEOUT HZ/10
46
47#define RAW3215_FIXED 1
48#define RAW3215_WORKING 4
49#define RAW3215_THROTTLED 8
50#define RAW3215_STOPPED 16
51#define RAW3215_TIMER_RUNS 64
52#define RAW3215_FLUSHING 128
53
54#define TAB_STOP_SIZE 8
55
56
57
58
59enum raw3215_type {
60 RAW3215_FREE, RAW3215_READ, RAW3215_WRITE
61};
62
63
64
65
66struct raw3215_req {
67 enum raw3215_type type;
68 int start, len;
69 int delayable;
70 int residual;
71 struct ccw1 ccws[RAW3215_NR_CCWS];
72 struct raw3215_info *info;
73 struct raw3215_req *next;
74} __attribute__ ((aligned(8)));
75
76struct raw3215_info {
77 struct tty_port port;
78 struct ccw_device *cdev;
79 spinlock_t *lock;
80 int flags;
81 char *buffer;
82 char *inbuf;
83 int head;
84 int count;
85 int written;
86 struct raw3215_req *queued_read;
87 struct raw3215_req *queued_write;
88 struct tasklet_struct tlet;
89 wait_queue_head_t empty_wait;
90 struct timer_list timer;
91 int line_pos;
92 char ubuffer[80];
93};
94
95
96static struct raw3215_info *raw3215[NR_3215];
97
98static DEFINE_SPINLOCK(raw3215_device_lock);
99
100static struct raw3215_req *raw3215_freelist;
101
102static spinlock_t raw3215_freelist_lock;
103
104static struct tty_driver *tty3215_driver;
105
106
107
108
109static inline struct raw3215_req *raw3215_alloc_req(void)
110{
111 struct raw3215_req *req;
112 unsigned long flags;
113
114 spin_lock_irqsave(&raw3215_freelist_lock, flags);
115 req = raw3215_freelist;
116 raw3215_freelist = req->next;
117 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
118 return req;
119}
120
121
122
123
124static inline void raw3215_free_req(struct raw3215_req *req)
125{
126 unsigned long flags;
127
128 if (req->type == RAW3215_FREE)
129 return;
130 req->type = RAW3215_FREE;
131 spin_lock_irqsave(&raw3215_freelist_lock, flags);
132 req->next = raw3215_freelist;
133 raw3215_freelist = req;
134 spin_unlock_irqrestore(&raw3215_freelist_lock, flags);
135}
136
137
138
139
140
141
142
143static void raw3215_mk_read_req(struct raw3215_info *raw)
144{
145 struct raw3215_req *req;
146 struct ccw1 *ccw;
147
148
149 req = raw->queued_read;
150 if (req == NULL) {
151
152 req = raw3215_alloc_req();
153 req->type = RAW3215_READ;
154 req->info = raw;
155 raw->queued_read = req;
156 }
157
158 ccw = req->ccws;
159 ccw->cmd_code = 0x0A;
160 ccw->flags = 0x20;
161 ccw->count = 160;
162 ccw->cda = (__u32) __pa(raw->inbuf);
163}
164
165
166
167
168
169
170
171static void raw3215_mk_write_req(struct raw3215_info *raw)
172{
173 struct raw3215_req *req;
174 struct ccw1 *ccw;
175 int len, count, ix, lines;
176
177 if (raw->count <= raw->written)
178 return;
179
180 req = raw->queued_write;
181 if (req == NULL) {
182
183 req = raw3215_alloc_req();
184 req->type = RAW3215_WRITE;
185 req->info = raw;
186 raw->queued_write = req;
187 } else {
188 raw->written -= req->len;
189 }
190
191 ccw = req->ccws;
192 req->start = (raw->head - raw->count + raw->written) &
193 (RAW3215_BUFFER_SIZE - 1);
194
195
196
197
198
199 lines = 0;
200 ix = req->start;
201 while (lines < RAW3215_MAX_NEWLINE && ix != raw->head) {
202 if (raw->buffer[ix] == 0x15)
203 lines++;
204 ix = (ix + 1) & (RAW3215_BUFFER_SIZE - 1);
205 }
206 len = ((ix - 1 - req->start) & (RAW3215_BUFFER_SIZE - 1)) + 1;
207 if (len > RAW3215_MAX_BYTES)
208 len = RAW3215_MAX_BYTES;
209 req->len = len;
210 raw->written += len;
211
212
213 req->delayable = (ix == raw->head) && (len < RAW3215_MIN_WRITE);
214
215 ix = req->start;
216 while (len > 0) {
217 if (ccw > req->ccws)
218 ccw[-1].flags |= 0x40;
219 ccw->cmd_code = 0x01;
220 ccw->flags = 0x20;
221 ccw->cda =
222 (__u32) __pa(raw->buffer + ix);
223 count = len;
224 if (ix + count > RAW3215_BUFFER_SIZE)
225 count = RAW3215_BUFFER_SIZE - ix;
226 ccw->count = count;
227 len -= count;
228 ix = (ix + count) & (RAW3215_BUFFER_SIZE - 1);
229 ccw++;
230 }
231
232
233
234
235
236 if (ccw > req->ccws)
237 ccw[-1].flags |= 0x40;
238 ccw->cmd_code = 0x03;
239 ccw->flags = 0;
240 ccw->cda = 0;
241 ccw->count = 1;
242}
243
244
245
246
247static void raw3215_start_io(struct raw3215_info *raw)
248{
249 struct raw3215_req *req;
250 int res;
251
252 req = raw->queued_read;
253 if (req != NULL &&
254 !(raw->flags & (RAW3215_WORKING | RAW3215_THROTTLED))) {
255
256 raw->queued_read = NULL;
257 res = ccw_device_start(raw->cdev, req->ccws,
258 (unsigned long) req, 0, 0);
259 if (res != 0) {
260
261 raw->queued_read = req;
262 } else {
263 raw->flags |= RAW3215_WORKING;
264 }
265 }
266 req = raw->queued_write;
267 if (req != NULL &&
268 !(raw->flags & (RAW3215_WORKING | RAW3215_STOPPED))) {
269
270 raw->queued_write = NULL;
271 res = ccw_device_start(raw->cdev, req->ccws,
272 (unsigned long) req, 0, 0);
273 if (res != 0) {
274
275 raw->queued_write = req;
276 } else {
277 raw->flags |= RAW3215_WORKING;
278 }
279 }
280}
281
282
283
284
285static void raw3215_timeout(struct timer_list *t)
286{
287 struct raw3215_info *raw = from_timer(raw, t, timer);
288 unsigned long flags;
289
290 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
291 raw->flags &= ~RAW3215_TIMER_RUNS;
292 raw3215_mk_write_req(raw);
293 raw3215_start_io(raw);
294 if ((raw->queued_read || raw->queued_write) &&
295 !(raw->flags & RAW3215_WORKING) &&
296 !(raw->flags & RAW3215_TIMER_RUNS)) {
297 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
298 add_timer(&raw->timer);
299 raw->flags |= RAW3215_TIMER_RUNS;
300 }
301 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
302}
303
304
305
306
307
308
309
310static inline void raw3215_try_io(struct raw3215_info *raw)
311{
312 if (!tty_port_initialized(&raw->port))
313 return;
314 if (raw->queued_read != NULL)
315 raw3215_start_io(raw);
316 else if (raw->queued_write != NULL) {
317 if ((raw->queued_write->delayable == 0) ||
318 (raw->flags & RAW3215_FLUSHING)) {
319
320 raw3215_start_io(raw);
321 }
322 }
323 if ((raw->queued_read || raw->queued_write) &&
324 !(raw->flags & RAW3215_WORKING) &&
325 !(raw->flags & RAW3215_TIMER_RUNS)) {
326 raw->timer.expires = RAW3215_TIMEOUT + jiffies;
327 add_timer(&raw->timer);
328 raw->flags |= RAW3215_TIMER_RUNS;
329 }
330}
331
332
333
334
335static void raw3215_wakeup(unsigned long data)
336{
337 struct raw3215_info *raw = (struct raw3215_info *) data;
338 struct tty_struct *tty;
339
340 tty = tty_port_tty_get(&raw->port);
341 if (tty) {
342 tty_wakeup(tty);
343 tty_kref_put(tty);
344 }
345}
346
347
348
349
350static void raw3215_next_io(struct raw3215_info *raw, struct tty_struct *tty)
351{
352 raw3215_mk_write_req(raw);
353 raw3215_try_io(raw);
354 if (tty && RAW3215_BUFFER_SIZE - raw->count >= RAW3215_MIN_SPACE)
355 tasklet_schedule(&raw->tlet);
356}
357
358
359
360
361static void raw3215_irq(struct ccw_device *cdev, unsigned long intparm,
362 struct irb *irb)
363{
364 struct raw3215_info *raw;
365 struct raw3215_req *req;
366 struct tty_struct *tty;
367 int cstat, dstat;
368 int count;
369
370 raw = dev_get_drvdata(&cdev->dev);
371 req = (struct raw3215_req *) intparm;
372 tty = tty_port_tty_get(&raw->port);
373 cstat = irb->scsw.cmd.cstat;
374 dstat = irb->scsw.cmd.dstat;
375 if (cstat != 0)
376 raw3215_next_io(raw, tty);
377 if (dstat & 0x01) {
378 dstat &= ~0x01;
379 }
380 switch (dstat) {
381 case 0x80:
382 if (cstat != 0)
383 break;
384
385 raw3215_mk_read_req(raw);
386 raw3215_next_io(raw, tty);
387 break;
388 case 0x08:
389 case 0x0C:
390
391 if ((raw = req->info) == NULL)
392 goto put_tty;
393 if (req->type == RAW3215_READ) {
394
395 req->residual = irb->scsw.cmd.count;
396 }
397 if (dstat == 0x08)
398 break;
399 fallthrough;
400 case 0x04:
401
402 if ((raw = req->info) == NULL)
403 goto put_tty;
404 if (req->type == RAW3215_READ && tty != NULL) {
405 unsigned int cchar;
406
407 count = 160 - req->residual;
408 EBCASC(raw->inbuf, count);
409 cchar = ctrlchar_handle(raw->inbuf, count, tty);
410 switch (cchar & CTRLCHAR_MASK) {
411 case CTRLCHAR_SYSRQ:
412 break;
413
414 case CTRLCHAR_CTRL:
415 tty_insert_flip_char(&raw->port, cchar,
416 TTY_NORMAL);
417 tty_flip_buffer_push(&raw->port);
418 break;
419
420 case CTRLCHAR_NONE:
421 if (count < 2 ||
422 (strncmp(raw->inbuf+count-2, "\252n", 2) &&
423 strncmp(raw->inbuf+count-2, "^n", 2)) ) {
424
425 raw->inbuf[count] = '\n';
426 count++;
427 } else
428 count -= 2;
429 tty_insert_flip_string(&raw->port, raw->inbuf,
430 count);
431 tty_flip_buffer_push(&raw->port);
432 break;
433 }
434 } else if (req->type == RAW3215_WRITE) {
435 raw->count -= req->len;
436 raw->written -= req->len;
437 }
438 raw->flags &= ~RAW3215_WORKING;
439 raw3215_free_req(req);
440
441 if (waitqueue_active(&raw->empty_wait) &&
442 raw->queued_write == NULL &&
443 raw->queued_read == NULL) {
444 wake_up_interruptible(&raw->empty_wait);
445 }
446 raw3215_next_io(raw, tty);
447 break;
448 default:
449
450 if (req != NULL && req->type != RAW3215_FREE) {
451 if (req->type == RAW3215_WRITE) {
452 raw->count -= req->len;
453 raw->written -= req->len;
454 }
455 raw->flags &= ~RAW3215_WORKING;
456 raw3215_free_req(req);
457 }
458 raw3215_next_io(raw, tty);
459 }
460put_tty:
461 tty_kref_put(tty);
462}
463
464
465
466
467
468
469static void raw3215_make_room(struct raw3215_info *raw, unsigned int length)
470{
471 while (RAW3215_BUFFER_SIZE - raw->count < length) {
472
473 raw->flags |= RAW3215_FLUSHING;
474 raw3215_mk_write_req(raw);
475 raw3215_try_io(raw);
476 raw->flags &= ~RAW3215_FLUSHING;
477#ifdef CONFIG_TN3215_CONSOLE
478 ccw_device_wait_idle(raw->cdev);
479#endif
480
481 if (RAW3215_BUFFER_SIZE - raw->count >= length)
482 break;
483
484 spin_unlock(get_ccwdev_lock(raw->cdev));
485 udelay(100);
486 spin_lock(get_ccwdev_lock(raw->cdev));
487 }
488}
489
490
491
492
493static void raw3215_write(struct raw3215_info *raw, const char *str,
494 unsigned int length)
495{
496 unsigned long flags;
497 int c, count;
498
499 while (length > 0) {
500 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
501 count = (length > RAW3215_BUFFER_SIZE) ?
502 RAW3215_BUFFER_SIZE : length;
503 length -= count;
504
505 raw3215_make_room(raw, count);
506
507
508 while (1) {
509 c = min_t(int, count,
510 min(RAW3215_BUFFER_SIZE - raw->count,
511 RAW3215_BUFFER_SIZE - raw->head));
512 if (c <= 0)
513 break;
514 memcpy(raw->buffer + raw->head, str, c);
515 ASCEBC(raw->buffer + raw->head, c);
516 raw->head = (raw->head + c) & (RAW3215_BUFFER_SIZE - 1);
517 raw->count += c;
518 raw->line_pos += c;
519 str += c;
520 count -= c;
521 }
522 if (!(raw->flags & RAW3215_WORKING)) {
523 raw3215_mk_write_req(raw);
524
525 raw3215_try_io(raw);
526 }
527 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
528 }
529}
530
531
532
533
534static void raw3215_putchar(struct raw3215_info *raw, unsigned char ch)
535{
536 unsigned long flags;
537 unsigned int length, i;
538
539 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
540 if (ch == '\t') {
541 length = TAB_STOP_SIZE - (raw->line_pos%TAB_STOP_SIZE);
542 raw->line_pos += length;
543 ch = ' ';
544 } else if (ch == '\n') {
545 length = 1;
546 raw->line_pos = 0;
547 } else {
548 length = 1;
549 raw->line_pos++;
550 }
551 raw3215_make_room(raw, length);
552
553 for (i = 0; i < length; i++) {
554 raw->buffer[raw->head] = (char) _ascebc[(int) ch];
555 raw->head = (raw->head + 1) & (RAW3215_BUFFER_SIZE - 1);
556 raw->count++;
557 }
558 if (!(raw->flags & RAW3215_WORKING)) {
559 raw3215_mk_write_req(raw);
560
561 raw3215_try_io(raw);
562 }
563 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
564}
565
566
567
568
569
570static void raw3215_flush_buffer(struct raw3215_info *raw)
571{
572 unsigned long flags;
573
574 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
575 if (raw->count > 0) {
576 raw->flags |= RAW3215_FLUSHING;
577 raw3215_try_io(raw);
578 raw->flags &= ~RAW3215_FLUSHING;
579 }
580 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
581}
582
583
584
585
586static int raw3215_startup(struct raw3215_info *raw)
587{
588 unsigned long flags;
589
590 if (tty_port_initialized(&raw->port))
591 return 0;
592 raw->line_pos = 0;
593 tty_port_set_initialized(&raw->port, 1);
594 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
595 raw3215_try_io(raw);
596 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
597
598 return 0;
599}
600
601
602
603
604static void raw3215_shutdown(struct raw3215_info *raw)
605{
606 DECLARE_WAITQUEUE(wait, current);
607 unsigned long flags;
608
609 if (!tty_port_initialized(&raw->port) || (raw->flags & RAW3215_FIXED))
610 return;
611
612 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
613 if ((raw->flags & RAW3215_WORKING) ||
614 raw->queued_write != NULL ||
615 raw->queued_read != NULL) {
616 add_wait_queue(&raw->empty_wait, &wait);
617 set_current_state(TASK_INTERRUPTIBLE);
618 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
619 schedule();
620 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
621 remove_wait_queue(&raw->empty_wait, &wait);
622 set_current_state(TASK_RUNNING);
623 tty_port_set_initialized(&raw->port, 1);
624 }
625 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
626}
627
628static struct raw3215_info *raw3215_alloc_info(void)
629{
630 struct raw3215_info *info;
631
632 info = kzalloc(sizeof(struct raw3215_info), GFP_KERNEL | GFP_DMA);
633 if (!info)
634 return NULL;
635
636 info->buffer = kzalloc(RAW3215_BUFFER_SIZE, GFP_KERNEL | GFP_DMA);
637 info->inbuf = kzalloc(RAW3215_INBUF_SIZE, GFP_KERNEL | GFP_DMA);
638 if (!info->buffer || !info->inbuf) {
639 kfree(info->inbuf);
640 kfree(info->buffer);
641 kfree(info);
642 return NULL;
643 }
644
645 timer_setup(&info->timer, raw3215_timeout, 0);
646 init_waitqueue_head(&info->empty_wait);
647 tasklet_init(&info->tlet, raw3215_wakeup, (unsigned long)info);
648 tty_port_init(&info->port);
649
650 return info;
651}
652
653static void raw3215_free_info(struct raw3215_info *raw)
654{
655 kfree(raw->inbuf);
656 kfree(raw->buffer);
657 tty_port_destroy(&raw->port);
658 kfree(raw);
659}
660
661static int raw3215_probe (struct ccw_device *cdev)
662{
663 struct raw3215_info *raw;
664 int line;
665
666
667 if (raw3215[0] && (raw3215[0] == dev_get_drvdata(&cdev->dev)))
668 return 0;
669
670 raw = raw3215_alloc_info();
671 if (raw == NULL)
672 return -ENOMEM;
673
674 raw->cdev = cdev;
675 dev_set_drvdata(&cdev->dev, raw);
676 cdev->handler = raw3215_irq;
677
678 spin_lock(&raw3215_device_lock);
679 for (line = 0; line < NR_3215; line++) {
680 if (!raw3215[line]) {
681 raw3215[line] = raw;
682 break;
683 }
684 }
685 spin_unlock(&raw3215_device_lock);
686 if (line == NR_3215) {
687 raw3215_free_info(raw);
688 return -ENODEV;
689 }
690
691 return 0;
692}
693
694static void raw3215_remove (struct ccw_device *cdev)
695{
696 struct raw3215_info *raw;
697 unsigned int line;
698
699 ccw_device_set_offline(cdev);
700 raw = dev_get_drvdata(&cdev->dev);
701 if (raw) {
702 spin_lock(&raw3215_device_lock);
703 for (line = 0; line < NR_3215; line++)
704 if (raw3215[line] == raw)
705 break;
706 raw3215[line] = NULL;
707 spin_unlock(&raw3215_device_lock);
708 dev_set_drvdata(&cdev->dev, NULL);
709 raw3215_free_info(raw);
710 }
711}
712
713static int raw3215_set_online (struct ccw_device *cdev)
714{
715 struct raw3215_info *raw;
716
717 raw = dev_get_drvdata(&cdev->dev);
718 if (!raw)
719 return -ENODEV;
720
721 return raw3215_startup(raw);
722}
723
724static int raw3215_set_offline (struct ccw_device *cdev)
725{
726 struct raw3215_info *raw;
727
728 raw = dev_get_drvdata(&cdev->dev);
729 if (!raw)
730 return -ENODEV;
731
732 raw3215_shutdown(raw);
733
734 return 0;
735}
736
737static struct ccw_device_id raw3215_id[] = {
738 { CCW_DEVICE(0x3215, 0) },
739 { },
740};
741
742static struct ccw_driver raw3215_ccw_driver = {
743 .driver = {
744 .name = "3215",
745 .owner = THIS_MODULE,
746 },
747 .ids = raw3215_id,
748 .probe = &raw3215_probe,
749 .remove = &raw3215_remove,
750 .set_online = &raw3215_set_online,
751 .set_offline = &raw3215_set_offline,
752 .int_class = IRQIO_C15,
753};
754
755#ifdef CONFIG_TN3215_CONSOLE
756
757
758
759static void con3215_write(struct console *co, const char *str,
760 unsigned int count)
761{
762 struct raw3215_info *raw;
763 int i;
764
765 if (count <= 0)
766 return;
767 raw = raw3215[0];
768 while (count > 0) {
769 for (i = 0; i < count; i++)
770 if (str[i] == '\t' || str[i] == '\n')
771 break;
772 raw3215_write(raw, str, i);
773 count -= i;
774 str += i;
775 if (count > 0) {
776 raw3215_putchar(raw, *str);
777 count--;
778 str++;
779 }
780 }
781}
782
783static struct tty_driver *con3215_device(struct console *c, int *index)
784{
785 *index = c->index;
786 return tty3215_driver;
787}
788
789
790
791
792
793static void con3215_flush(void)
794{
795 struct raw3215_info *raw;
796 unsigned long flags;
797
798 raw = raw3215[0];
799 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
800 raw3215_make_room(raw, RAW3215_BUFFER_SIZE);
801 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
802}
803
804static int con3215_notify(struct notifier_block *self,
805 unsigned long event, void *data)
806{
807 con3215_flush();
808 return NOTIFY_OK;
809}
810
811static struct notifier_block on_panic_nb = {
812 .notifier_call = con3215_notify,
813 .priority = 0,
814};
815
816static struct notifier_block on_reboot_nb = {
817 .notifier_call = con3215_notify,
818 .priority = 0,
819};
820
821
822
823
824static struct console con3215 = {
825 .name = "ttyS",
826 .write = con3215_write,
827 .device = con3215_device,
828 .flags = CON_PRINTBUFFER,
829};
830
831
832
833
834static int __init con3215_init(void)
835{
836 struct ccw_device *cdev;
837 struct raw3215_info *raw;
838 struct raw3215_req *req;
839 int i;
840
841
842 if (!CONSOLE_IS_3215)
843 return -ENODEV;
844
845
846 if (MACHINE_IS_VM) {
847 cpcmd("TERM CONMODE 3215", NULL, 0, NULL);
848 cpcmd("TERM AUTOCR OFF", NULL, 0, NULL);
849 }
850
851
852 raw3215_freelist = NULL;
853 spin_lock_init(&raw3215_freelist_lock);
854 for (i = 0; i < NR_3215_REQ; i++) {
855 req = kzalloc(sizeof(struct raw3215_req), GFP_KERNEL | GFP_DMA);
856 if (!req)
857 return -ENOMEM;
858 req->next = raw3215_freelist;
859 raw3215_freelist = req;
860 }
861
862 cdev = ccw_device_create_console(&raw3215_ccw_driver);
863 if (IS_ERR(cdev))
864 return -ENODEV;
865
866 raw3215[0] = raw = raw3215_alloc_info();
867 raw->cdev = cdev;
868 dev_set_drvdata(&cdev->dev, raw);
869 cdev->handler = raw3215_irq;
870
871 raw->flags |= RAW3215_FIXED;
872 if (ccw_device_enable_console(cdev)) {
873 ccw_device_destroy_console(cdev);
874 raw3215_free_info(raw);
875 raw3215[0] = NULL;
876 return -ENODEV;
877 }
878
879
880 if (raw3215_startup(raw) != 0) {
881 raw3215_free_info(raw);
882 raw3215[0] = NULL;
883 return -ENODEV;
884 }
885 atomic_notifier_chain_register(&panic_notifier_list, &on_panic_nb);
886 register_reboot_notifier(&on_reboot_nb);
887 register_console(&con3215);
888 return 0;
889}
890console_initcall(con3215_init);
891#endif
892
893static int tty3215_install(struct tty_driver *driver, struct tty_struct *tty)
894{
895 struct raw3215_info *raw;
896
897 raw = raw3215[tty->index];
898 if (raw == NULL)
899 return -ENODEV;
900
901 tty->driver_data = raw;
902
903 return tty_port_install(&raw->port, driver, tty);
904}
905
906
907
908
909
910
911static int tty3215_open(struct tty_struct *tty, struct file * filp)
912{
913 struct raw3215_info *raw = tty->driver_data;
914
915 tty_port_tty_set(&raw->port, tty);
916
917
918
919
920 return raw3215_startup(raw);
921}
922
923
924
925
926
927
928
929static void tty3215_close(struct tty_struct *tty, struct file * filp)
930{
931 struct raw3215_info *raw;
932
933 raw = (struct raw3215_info *) tty->driver_data;
934 if (raw == NULL || tty->count > 1)
935 return;
936 tty->closing = 1;
937
938 raw3215_shutdown(raw);
939 tasklet_kill(&raw->tlet);
940 tty->closing = 0;
941 tty_port_tty_set(&raw->port, NULL);
942}
943
944
945
946
947static int tty3215_write_room(struct tty_struct *tty)
948{
949 struct raw3215_info *raw;
950
951 raw = (struct raw3215_info *) tty->driver_data;
952
953
954 if ((RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE) >= 0)
955 return RAW3215_BUFFER_SIZE - raw->count - TAB_STOP_SIZE;
956 else
957 return 0;
958}
959
960
961
962
963static int tty3215_write(struct tty_struct * tty,
964 const unsigned char *buf, int count)
965{
966 struct raw3215_info *raw;
967 int i, written;
968
969 if (!tty)
970 return 0;
971 raw = (struct raw3215_info *) tty->driver_data;
972 written = count;
973 while (count > 0) {
974 for (i = 0; i < count; i++)
975 if (buf[i] == '\t' || buf[i] == '\n')
976 break;
977 raw3215_write(raw, buf, i);
978 count -= i;
979 buf += i;
980 if (count > 0) {
981 raw3215_putchar(raw, *buf);
982 count--;
983 buf++;
984 }
985 }
986 return written;
987}
988
989
990
991
992static int tty3215_put_char(struct tty_struct *tty, unsigned char ch)
993{
994 struct raw3215_info *raw;
995
996 if (!tty)
997 return 0;
998 raw = (struct raw3215_info *) tty->driver_data;
999 raw3215_putchar(raw, ch);
1000 return 1;
1001}
1002
1003static void tty3215_flush_chars(struct tty_struct *tty)
1004{
1005}
1006
1007
1008
1009
1010static int tty3215_chars_in_buffer(struct tty_struct *tty)
1011{
1012 struct raw3215_info *raw;
1013
1014 raw = (struct raw3215_info *) tty->driver_data;
1015 return raw->count;
1016}
1017
1018static void tty3215_flush_buffer(struct tty_struct *tty)
1019{
1020 struct raw3215_info *raw;
1021
1022 raw = (struct raw3215_info *) tty->driver_data;
1023 raw3215_flush_buffer(raw);
1024 tty_wakeup(tty);
1025}
1026
1027
1028
1029
1030static void tty3215_throttle(struct tty_struct * tty)
1031{
1032 struct raw3215_info *raw;
1033
1034 raw = (struct raw3215_info *) tty->driver_data;
1035 raw->flags |= RAW3215_THROTTLED;
1036}
1037
1038
1039
1040
1041static void tty3215_unthrottle(struct tty_struct * tty)
1042{
1043 struct raw3215_info *raw;
1044 unsigned long flags;
1045
1046 raw = (struct raw3215_info *) tty->driver_data;
1047 if (raw->flags & RAW3215_THROTTLED) {
1048 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1049 raw->flags &= ~RAW3215_THROTTLED;
1050 raw3215_try_io(raw);
1051 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1052 }
1053}
1054
1055
1056
1057
1058static void tty3215_stop(struct tty_struct *tty)
1059{
1060 struct raw3215_info *raw;
1061
1062 raw = (struct raw3215_info *) tty->driver_data;
1063 raw->flags |= RAW3215_STOPPED;
1064}
1065
1066
1067
1068
1069static void tty3215_start(struct tty_struct *tty)
1070{
1071 struct raw3215_info *raw;
1072 unsigned long flags;
1073
1074 raw = (struct raw3215_info *) tty->driver_data;
1075 if (raw->flags & RAW3215_STOPPED) {
1076 spin_lock_irqsave(get_ccwdev_lock(raw->cdev), flags);
1077 raw->flags &= ~RAW3215_STOPPED;
1078 raw3215_try_io(raw);
1079 spin_unlock_irqrestore(get_ccwdev_lock(raw->cdev), flags);
1080 }
1081}
1082
1083static const struct tty_operations tty3215_ops = {
1084 .install = tty3215_install,
1085 .open = tty3215_open,
1086 .close = tty3215_close,
1087 .write = tty3215_write,
1088 .put_char = tty3215_put_char,
1089 .flush_chars = tty3215_flush_chars,
1090 .write_room = tty3215_write_room,
1091 .chars_in_buffer = tty3215_chars_in_buffer,
1092 .flush_buffer = tty3215_flush_buffer,
1093 .throttle = tty3215_throttle,
1094 .unthrottle = tty3215_unthrottle,
1095 .stop = tty3215_stop,
1096 .start = tty3215_start,
1097};
1098
1099
1100
1101
1102
1103static int __init tty3215_init(void)
1104{
1105 struct tty_driver *driver;
1106 int ret;
1107
1108 if (!CONSOLE_IS_3215)
1109 return 0;
1110
1111 driver = alloc_tty_driver(NR_3215);
1112 if (!driver)
1113 return -ENOMEM;
1114
1115 ret = ccw_driver_register(&raw3215_ccw_driver);
1116 if (ret) {
1117 put_tty_driver(driver);
1118 return ret;
1119 }
1120
1121
1122
1123
1124
1125
1126 driver->driver_name = "tty3215";
1127 driver->name = "ttyS";
1128 driver->major = TTY_MAJOR;
1129 driver->minor_start = 64;
1130 driver->type = TTY_DRIVER_TYPE_SYSTEM;
1131 driver->subtype = SYSTEM_TYPE_TTY;
1132 driver->init_termios = tty_std_termios;
1133 driver->init_termios.c_iflag = IGNBRK | IGNPAR;
1134 driver->init_termios.c_oflag = ONLCR;
1135 driver->init_termios.c_lflag = ISIG;
1136 driver->flags = TTY_DRIVER_REAL_RAW;
1137 tty_set_operations(driver, &tty3215_ops);
1138 ret = tty_register_driver(driver);
1139 if (ret) {
1140 put_tty_driver(driver);
1141 return ret;
1142 }
1143 tty3215_driver = driver;
1144 return 0;
1145}
1146device_initcall(tty3215_init);
1147