This source file includes following definitions.
- serial_paranoia_check
- SP
- CP
- CP1
- CP2
- CP4
- CP8
- write_cy_cmd
- cy_stop
- cy_start
- cy_sched_event
- cy_probe
- cy_interrupt
- do_cyclades_bh
- do_softint
- grab_all_interrupts
- free_all_interrupts
- check_wild_interrupts
- get_auto_irq
- do_auto_irq
- startup
- start_xmit
- shutdown
- config_setup
- cy_put_char
- cy_flush_chars
- cy_write
- cy_write_room
- cy_chars_in_buffer
- cy_flush_buffer
- cy_throttle
- cy_unthrottle
- get_serial_info
- set_serial_info
- get_modem_info
- set_modem_info
- send_break
- get_mon_info
- set_threshold
- get_threshold
- set_default_threshold
- get_default_threshold
- set_timeout
- get_timeout
- set_default_timeout
- get_default_timeout
- cy_ioctl
- cy_set_termios
- cy_close
- cy_hangup
- block_til_ready
- cy_open
- show_version
- cy_init_card
- cy_init
- show_status
1 static char rcsid[] =
2 "$Revision: 1.36.1.3 $$Date: 1995/03/23 22:15:35 $";
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204 #include <linux/errno.h>
205 #include <linux/signal.h>
206 #include <linux/sched.h>
207 #include <linux/timer.h>
208 #include <linux/tty.h>
209 #include <linux/serial.h>
210 #include <linux/interrupt.h>
211 #include <linux/string.h>
212 #include <linux/fcntl.h>
213 #include <linux/ptrace.h>
214 #include <linux/cyclades.h>
215 #include <linux/delay.h>
216 #include <linux/major.h>
217 #include <linux/mm.h>
218
219 #include <asm/system.h>
220 #include <asm/io.h>
221 #include <asm/segment.h>
222 #include <asm/bitops.h>
223
224 #define small_delay(x) for(j=0;j<x;j++)k++;
225
226
227 #define SERIAL_PARANOIA_CHECK
228 #undef SERIAL_DEBUG_OPEN
229 #undef SERIAL_DEBUG_THROTTLE
230 #undef SERIAL_DEBUG_OTHER
231 #undef SERIAL_DEBUG_IO
232 #undef SERIAL_DEBUG_COUNT
233 #undef SERIAL_DEBUG_DTR
234 #undef CYCLOM_16Y_HACK
235 #undef CYCLOM_ENABLE_MONITORING
236
237 #ifndef MIN
238 #define MIN(a,b) ((a) < (b) ? (a) : (b))
239 #endif
240
241 #define WAKEUP_CHARS 256
242
243 #define STD_COM_FLAGS (0)
244
245 #define SERIAL_TYPE_NORMAL 1
246 #define SERIAL_TYPE_CALLOUT 2
247
248
249 DECLARE_TASK_QUEUE(tq_cyclades);
250
251 struct tty_driver cy_serial_driver, cy_callout_driver;
252
253 static volatile int cy_irq_triggered;
254 static volatile int cy_triggered;
255 static int cy_wild_int_mask;
256 static unsigned char *intr_base_addr;
257
258
259
260
261
262 struct cyclades_card cy_card[] = {
263
264 {0xD0000},
265 {0xD2000},
266 {0xD4000},
267 {0xD6000},
268 {0xD8000},
269 {0xDA000},
270 {0xDC000},
271 {0xDE000}
272 };
273
274 #define NR_CARDS (sizeof(cy_card)/sizeof(struct cyclades_card))
275
276
277
278
279 int cy_chip_offset [] =
280 { 0x0000,
281 0x0400,
282 0x0800,
283 0x0C00,
284 0x0200,
285 0x0600,
286 0x0A00,
287 0x0E00
288 };
289
290
291 struct cyclades_port cy_port[] = {
292
293 {-1 },
294 {-1 },
295 {-1 },
296 {-1 },
297 {-1 },
298 {-1 },
299 {-1 },
300 {-1 },
301 {-1 },
302 {-1 },
303 {-1 },
304 {-1 },
305 {-1 },
306 {-1 },
307 {-1 },
308 {-1 },
309 {-1 },
310 {-1 },
311 {-1 },
312 {-1 },
313 {-1 },
314 {-1 },
315 {-1 },
316 {-1 },
317 {-1 },
318 {-1 },
319 {-1 },
320 {-1 },
321 {-1 },
322 {-1 },
323 {-1 },
324 {-1 }
325 };
326 #define NR_PORTS (sizeof(cy_port)/sizeof(struct cyclades_port))
327
328 static int serial_refcount;
329
330 static struct tty_struct *serial_table[NR_PORTS];
331 static struct termios *serial_termios[NR_PORTS];
332 static struct termios *serial_termios_locked[NR_PORTS];
333
334
335
336
337 struct cyclades_card * IRQ_cards[16];
338
339
340
341
342
343
344
345
346
347
348
349 static unsigned char *tmp_buf = 0;
350 static struct semaphore tmp_buf_sem = MUTEX;
351
352
353
354
355
356
357
358
359
360 static int baud_table[] = {
361 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
362 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
363 0};
364
365 static char baud_co[] = {
366
367
368 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
369 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
370
371 static char baud_bpr[] = {
372 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
373 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
374
375 static char baud_cor3[] = {
376 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
377 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07};
378
379
380
381 static void shutdown(struct cyclades_port *);
382 static int startup (struct cyclades_port *);
383 static void cy_throttle(struct tty_struct *);
384 static void cy_unthrottle(struct tty_struct *);
385 static void config_setup(struct cyclades_port *);
386 extern void console_print(const char *);
387 #ifdef CYCLOM_SHOW_STATUS
388 static void show_status(int);
389 #endif
390
391
392
393 static inline int
394 serial_paranoia_check(struct cyclades_port *info,
395 dev_t device, const char *routine)
396 {
397 #ifdef SERIAL_PARANOIA_CHECK
398 static const char *badmagic =
399 "Warning: bad magic number for serial struct (%d, %d) in %s\n";
400 static const char *badinfo =
401 "Warning: null cyclades_port for (%d, %d) in %s\n";
402 static const char *badrange =
403 "Warning: cyclades_port out of range for (%d, %d) in %s\n";
404
405 if (!info) {
406 printk(badinfo, MAJOR(device), MINOR(device), routine);
407 return 1;
408 }
409
410 if( (long)info < (long)(&cy_port[0])
411 || (long)(&cy_port[NR_PORTS]) < (long)info ){
412 printk(badrange, MAJOR(device), MINOR(device), routine);
413 return 1;
414 }
415
416 if (info->magic != CYCLADES_MAGIC) {
417 printk(badmagic, MAJOR(device), MINOR(device), routine);
418 return 1;
419 }
420 #endif
421 return 0;
422 }
423
424
425
426
427 void
428 SP(char *data){
429 unsigned long flags;
430 save_flags(flags); cli();
431 console_print(data);
432 restore_flags(flags);
433 }
434 char scrn[2];
435 void
436 CP(char data){
437 unsigned long flags;
438 save_flags(flags); cli();
439 scrn[0] = data;
440 console_print(scrn);
441 restore_flags(flags);
442 }
443
444 void CP1(int data) { (data<10)? CP(data+'0'): CP(data+'A'-10); }
445 void CP2(int data) { CP1((data>>4) & 0x0f); CP1( data & 0x0f); }
446 void CP4(int data) { CP2((data>>8) & 0xff); CP2(data & 0xff); }
447 void CP8(long data) { CP4((data>>16) & 0xffff); CP4(data & 0xffff); }
448
449
450
451
452
453
454
455 u_short
456 write_cy_cmd(u_char *base_addr, u_char cmd)
457 {
458 unsigned long flags;
459 volatile int i;
460
461 save_flags(flags); cli();
462
463 for(i = 0 ; i < 100 ; i++){
464 if (base_addr[CyCCR] == 0){
465 break;
466 }
467 udelay(10L);
468 }
469
470
471 if ( i == 10 ) {
472 restore_flags(flags);
473 return (-1);
474 }
475
476
477 base_addr[CyCCR] = cmd;
478 restore_flags(flags);
479 return(0);
480 }
481
482
483
484
485
486 static void
487 cy_stop(struct tty_struct *tty)
488 {
489 struct cyclades_card *cinfo;
490 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
491 unsigned char *base_addr;
492 int chip,channel;
493 unsigned long flags;
494
495 #ifdef SERIAL_DEBUG_OTHER
496 printk("cy_stop ttyC%d\n", info->line);
497 #endif
498
499 if (serial_paranoia_check(info, tty->device, "cy_stop"))
500 return;
501
502 cinfo = &cy_card[info->card];
503 channel = info->line - cinfo->first_line;
504 chip = channel>>2;
505 channel &= 0x03;
506 base_addr = (unsigned char*)
507 (cy_card[info->card].base_addr + cy_chip_offset[chip]);
508
509 save_flags(flags); cli();
510 base_addr[CyCAR] = (u_char)(channel & 0x0003);
511 base_addr[CySRER] &= ~CyTxMpty;
512 restore_flags(flags);
513
514 return;
515 }
516
517 static void
518 cy_start(struct tty_struct *tty)
519 {
520 struct cyclades_card *cinfo;
521 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
522 unsigned char *base_addr;
523 int chip,channel;
524 unsigned long flags;
525
526 #ifdef SERIAL_DEBUG_OTHER
527 printk("cy_start ttyC%d\n", info->line);
528 #endif
529
530 if (serial_paranoia_check(info, tty->device, "cy_start"))
531 return;
532
533 cinfo = &cy_card[info->card];
534 channel = info->line - cinfo->first_line;
535 chip = channel>>2;
536 channel &= 0x03;
537 base_addr = (unsigned char*)
538 (cy_card[info->card].base_addr + cy_chip_offset[chip]);
539
540 save_flags(flags); cli();
541 base_addr[CyCAR] = (u_char)(channel & 0x0003);
542 base_addr[CySRER] |= CyTxMpty;
543 restore_flags(flags);
544
545 return;
546 }
547
548
549
550
551
552
553
554
555 static inline void
556 cy_sched_event(struct cyclades_port *info, int event)
557 {
558 info->event |= 1 << event;
559 queue_task_irq_off(&info->tqueue, &tq_cyclades);
560 mark_bh(CYCLADES_BH);
561 }
562
563
564
565
566
567
568
569 static void
570 cy_probe(int irq, struct pt_regs *regs)
571 {
572 cy_irq_triggered = irq;
573 cy_triggered |= 1 << irq;
574 return;
575 }
576
577
578
579
580
581 static void
582 cy_interrupt(int irq, struct pt_regs *regs)
583 {
584 struct tty_struct *tty;
585 int status;
586 struct cyclades_card *cinfo;
587 struct cyclades_port *info;
588 volatile unsigned char *base_addr, *card_base_addr;
589 int chip;
590 int save_xir, channel, save_car;
591 char data;
592 volatile char vdata;
593 int char_count;
594 int outch;
595 int i,j;
596 int too_many;
597 int had_work;
598 int mdm_change;
599 int mdm_status;
600
601 if((cinfo = IRQ_cards[irq]) == 0){
602 return;
603 }
604
605
606
607
608
609
610 do{
611 had_work = 0;
612 for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) {
613 base_addr = (unsigned char *)
614 (cinfo->base_addr + cy_chip_offset[chip]);
615 too_many = 0;
616 while ( (status = base_addr[CySVRR]) != 0x00) {
617 had_work++;
618
619
620
621
622
623 if(1000<too_many++){
624 break;
625 }
626 if (status & CySRReceive) {
627
628
629 save_xir = (u_char) base_addr[CyRIR];
630 channel = (u_short ) (save_xir & CyIRChannel);
631 i = channel + chip * 4 + cinfo->first_line;
632 info = &cy_port[i];
633 info->last_active = jiffies;
634 save_car = base_addr[CyCAR];
635 base_addr[CyCAR] = save_xir;
636
637
638 if(info->tty == 0){
639 j = (base_addr[CyRIVR] & CyIVRMask);
640 if ( j == CyIVRRxEx ) {
641 data = base_addr[CyRDSR];
642 } else {
643 char_count = base_addr[CyRDCR];
644 while(char_count--){
645 data = base_addr[CyRDSR];
646 }
647 }
648 }else{
649 tty = info->tty;
650 j = (base_addr[CyRIVR] & CyIVRMask);
651 if ( j == CyIVRRxEx ) {
652 data = base_addr[CyRDSR];
653 if(data & info->ignore_status_mask){
654 continue;
655 }
656 if (tty->flip.count < TTY_FLIPBUF_SIZE){
657 tty->flip.count++;
658 if (data & info->read_status_mask){
659 if(data & CyBREAK){
660 *tty->flip.flag_buf_ptr++ =
661 TTY_BREAK;
662 *tty->flip.char_buf_ptr++ =
663 base_addr[CyRDSR];
664 if (info->flags & ASYNC_SAK){
665 do_SAK(tty);
666 }
667 }else if(data & CyFRAME){
668 *tty->flip.flag_buf_ptr++ =
669 TTY_FRAME;
670 *tty->flip.char_buf_ptr++ =
671 base_addr[CyRDSR];
672 }else if(data & CyPARITY){
673 *tty->flip.flag_buf_ptr++ =
674 TTY_PARITY;
675 *tty->flip.char_buf_ptr++ =
676 base_addr[CyRDSR];
677 }else if(data & CyOVERRUN){
678 *tty->flip.flag_buf_ptr++ =
679 TTY_OVERRUN;
680 *tty->flip.char_buf_ptr++ = 0;
681
682
683
684
685 if(tty->flip.count < TTY_FLIPBUF_SIZE){
686 tty->flip.count++;
687 *tty->flip.flag_buf_ptr++ =
688 TTY_NORMAL;
689 *tty->flip.char_buf_ptr++ =
690 base_addr[CyRDSR];
691 }
692
693
694
695
696 }else{
697 *tty->flip.flag_buf_ptr++ = 0;
698 *tty->flip.char_buf_ptr++ = 0;
699 }
700 }else{
701 *tty->flip.flag_buf_ptr++ = 0;
702 *tty->flip.char_buf_ptr++ = 0;
703 }
704 }else{
705
706
707 }
708 } else {
709
710 char_count = base_addr[CyRDCR];
711
712 #ifdef CYCLOM_ENABLE_MONITORING
713 ++info->mon.int_count;
714 info->mon.char_count += char_count;
715 if (char_count > info->mon.char_max)
716 info->mon.char_max = char_count;
717 info->mon.char_last = char_count;
718 #endif
719 while(char_count--){
720 if (tty->flip.count >= TTY_FLIPBUF_SIZE){
721 break;
722 }
723 tty->flip.count++;
724 data = base_addr[CyRDSR];
725 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
726 *tty->flip.char_buf_ptr++ = data;
727 #ifdef CYCLOM_16Y_HACK
728 udelay(10L);
729 #endif
730 }
731 }
732 queue_task_irq_off(&tty->flip.tqueue, &tq_timer);
733 }
734
735 base_addr[CyRIR] = (save_xir & 0x3f);
736 base_addr[CyCAR] = (save_car);
737 }
738
739
740 if (status & CySRTransmit) {
741
742
743
744
745 save_xir = (u_char) base_addr[CyTIR];
746 channel = (u_short ) (save_xir & CyIRChannel);
747 i = channel + chip * 4 + cinfo->first_line;
748 save_car = base_addr[CyCAR];
749 base_addr[CyCAR] = save_xir;
750
751
752 if( (i < 0) || (NR_PORTS <= i) ){
753 base_addr[CySRER] &= ~CyTxMpty;
754 goto txend;
755 }
756 info = &cy_port[i];
757 info->last_active = jiffies;
758 if(info->tty == 0){
759 base_addr[CySRER] &= ~CyTxMpty;
760 goto txdone;
761 }
762
763
764 char_count = info->xmit_fifo_size;
765
766
767 if(info->x_char) {
768 outch = info->x_char;
769 base_addr[CyTDR] = outch;
770 char_count--;
771 info->x_char = 0;
772 }
773
774 if (info->x_break){
775
776
777
778
779
780
781
782
783 base_addr[CyTDR] = 0;
784 base_addr[CyTDR] = 0x81;
785 base_addr[CyTDR] = 0;
786 base_addr[CyTDR] = 0x82;
787 base_addr[CyTDR] = info->x_break*200/HZ;
788 base_addr[CyTDR] = 0;
789 base_addr[CyTDR] = 0x83;
790 char_count -= 7;
791 info->x_break = 0;
792 }
793
794 while (char_count-- > 0){
795 if (!info->xmit_cnt){
796 base_addr[CySRER] &= ~CyTxMpty;
797 goto txdone;
798 }
799 if (info->xmit_buf == 0){
800 base_addr[CySRER] &= ~CyTxMpty;
801 goto txdone;
802 }
803 if (info->tty->stopped || info->tty->hw_stopped){
804 base_addr[CySRER] &= ~CyTxMpty;
805 goto txdone;
806 }
807
808
809
810
811
812
813
814
815
816
817
818 outch = info->xmit_buf[info->xmit_tail];
819 if( outch ){
820 info->xmit_cnt--;
821 info->xmit_tail = (info->xmit_tail + 1)
822 & (PAGE_SIZE - 1);
823 base_addr[CyTDR] = outch;
824 }else{
825 if(char_count > 1){
826 info->xmit_cnt--;
827 info->xmit_tail = (info->xmit_tail + 1)
828 & (PAGE_SIZE - 1);
829 base_addr[CyTDR] = outch;
830 base_addr[CyTDR] = 0;
831 char_count--;
832 }else{
833 }
834 }
835 }
836
837 txdone:
838 if (info->xmit_cnt < WAKEUP_CHARS) {
839 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
840 }
841
842 txend:
843
844 base_addr[CyTIR] = (save_xir & 0x3f);
845 base_addr[CyCAR] = (save_car);
846 }
847
848 if (status & CySRModem) {
849
850
851 save_xir = (u_char) base_addr[CyMIR];
852 channel = (u_short ) (save_xir & CyIRChannel);
853 info = &cy_port[channel + chip * 4 + cinfo->first_line];
854 info->last_active = jiffies;
855 save_car = base_addr[CyCAR];
856 base_addr[CyCAR] = save_xir;
857
858 mdm_change = base_addr[CyMISR];
859 mdm_status = base_addr[CyMSVR1];
860
861 if(info->tty == 0){
862 ;
863 }else{
864 if((mdm_change & CyDCD)
865 && (info->flags & ASYNC_CHECK_CD)){
866 if(mdm_status & CyDCD){
867
868 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
869 }else if(!((info->flags & ASYNC_CALLOUT_ACTIVE)
870 &&(info->flags & ASYNC_CALLOUT_NOHUP))){
871
872 cy_sched_event(info, Cy_EVENT_HANGUP);
873 }
874 }
875 if((mdm_change & CyCTS)
876 && (info->flags & ASYNC_CTS_FLOW)){
877 if(info->tty->stopped){
878 if(mdm_status & CyCTS){
879
880 info->tty->stopped = 0;
881 base_addr[CySRER] |= CyTxMpty;
882 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
883 }
884 }else{
885 if(!(mdm_status & CyCTS)){
886
887 info->tty->stopped = 1;
888 base_addr[CySRER] &= ~CyTxMpty;
889 }
890 }
891 }
892 if(mdm_status & CyDSR){
893 }
894 if(mdm_status & CyRI){
895 }
896 }
897
898 base_addr[CyMIR] = (save_xir & 0x3f);
899 base_addr[CyCAR] = save_car;
900 }
901 }
902 }
903 } while(had_work);
904
905
906 card_base_addr = (unsigned char *)cinfo->base_addr;
907 vdata = *(card_base_addr + Cy_ClrIntr);
908
909 }
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933 static void
934 do_cyclades_bh(void *unused)
935 {
936 run_task_queue(&tq_cyclades);
937 }
938
939 static void
940 do_softint(void *private_)
941 {
942 struct cyclades_port *info = (struct cyclades_port *) private_;
943 struct tty_struct *tty;
944
945 tty = info->tty;
946 if (!tty)
947 return;
948
949 if (clear_bit(Cy_EVENT_HANGUP, &info->event)) {
950 tty_hangup(info->tty);
951 wake_up_interruptible(&info->open_wait);
952 info->flags &= ~(ASYNC_NORMAL_ACTIVE|
953 ASYNC_CALLOUT_ACTIVE);
954 }
955 if (clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
956 wake_up_interruptible(&info->open_wait);
957 }
958 if (clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
959 if((tty->flags & (1<< TTY_DO_WRITE_WAKEUP))
960 && tty->ldisc.write_wakeup){
961 (tty->ldisc.write_wakeup)(tty);
962 }
963 wake_up_interruptible(&tty->write_wait);
964 }
965 }
966
967
968
969
970
971
972
973
974 static int
975 grab_all_interrupts(int dontgrab)
976 {
977 int irq_lines = 0;
978 int i, mask;
979
980 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
981 if (!(mask & dontgrab)
982 && !request_irq(i, cy_probe, SA_INTERRUPT, "serial probe")) {
983 irq_lines |= mask;
984 }
985 }
986 return irq_lines;
987 }
988
989
990
991
992 static void
993 free_all_interrupts(int irq_lines)
994 {
995 int i;
996
997 for (i = 0; i < 16; i++) {
998 if (irq_lines & (1 << i))
999 free_irq(i);
1000 }
1001 }
1002
1003
1004
1005
1006
1007 static int
1008 check_wild_interrupts(void)
1009 {
1010 int i, mask;
1011 int wild_interrupts = 0;
1012 int irq_lines;
1013 unsigned long timeout;
1014 unsigned long flags;
1015
1016
1017 save_flags(flags); sti();
1018
1019 irq_lines = grab_all_interrupts(0);
1020
1021
1022
1023
1024
1025 timeout = jiffies+10;
1026 while (timeout >= jiffies)
1027 ;
1028
1029 cy_triggered = 0;
1030
1031 timeout = jiffies+10;
1032 while (timeout >= jiffies)
1033 ;
1034
1035 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
1036 if ((cy_triggered & (1 << i)) &&
1037 (irq_lines & (1 << i))) {
1038 wild_interrupts |= mask;
1039 }
1040 }
1041 free_all_interrupts(irq_lines);
1042 restore_flags(flags);
1043 return wild_interrupts;
1044 }
1045
1046
1047
1048
1049
1050
1051 static int
1052 get_auto_irq(int card)
1053 {
1054 unsigned long timeout;
1055 unsigned char *base_addr;
1056 int save_xir, save_car;
1057 volatile char vdata;
1058
1059 base_addr = (unsigned char*) (cy_card[card].base_addr);
1060 intr_base_addr = base_addr;
1061
1062
1063
1064
1065 cy_irq_triggered = 0;
1066 cli();
1067 base_addr[CyCAR] = 0;
1068 write_cy_cmd(base_addr,CyCHAN_CTL|CyENB_XMTR);
1069 base_addr[CySRER] |= CyTxMpty;
1070 sti();
1071
1072 timeout = jiffies+2;
1073 while (timeout >= jiffies) {
1074 if (cy_irq_triggered)
1075 break;
1076 }
1077
1078
1079
1080 cli();
1081 if(intr_base_addr[CySVRR] != 0){
1082 save_xir = (u_char) intr_base_addr[CyTIR];
1083 save_car = intr_base_addr[CyCAR];
1084 if ((save_xir & 0x3) != 0){
1085 printk("channel %x requesting unexpected interrupt\n",save_xir);
1086 }
1087 intr_base_addr[CyCAR] = (save_xir & 0x3);
1088 intr_base_addr[CySRER] &= ~CyTxMpty;
1089 intr_base_addr[CyTIR] = (save_xir & 0x3f);
1090 intr_base_addr[CyCAR] = (save_car);
1091 vdata = *(intr_base_addr + Cy_ClrIntr);
1092 }
1093 sti();
1094
1095 return(cy_irq_triggered);
1096 }
1097
1098
1099
1100
1101
1102 static int
1103 do_auto_irq(int card)
1104 {
1105 int irq_lines = 0;
1106 int irq_try_1 = 0, irq_try_2 = 0;
1107 int retries;
1108 unsigned long flags;
1109
1110
1111 save_flags(flags); sti();
1112
1113 cy_wild_int_mask = check_wild_interrupts();
1114
1115 irq_lines = grab_all_interrupts(cy_wild_int_mask);
1116
1117 for (retries = 0; retries < 5; retries++) {
1118 if (!irq_try_1)
1119 irq_try_1 = get_auto_irq(card);
1120 if (!irq_try_2)
1121 irq_try_2 = get_auto_irq(card);
1122 if (irq_try_1 && irq_try_2) {
1123 if (irq_try_1 == irq_try_2)
1124 break;
1125 irq_try_1 = irq_try_2 = 0;
1126 }
1127 }
1128 restore_flags(flags);
1129 free_all_interrupts(irq_lines);
1130 return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
1131 }
1132
1133
1134
1135
1136
1137 static int
1138 startup(struct cyclades_port * info)
1139 {
1140 unsigned long flags;
1141 unsigned char *base_addr;
1142 int card,chip,channel;
1143
1144 if (info->flags & ASYNC_INITIALIZED){
1145 return 0;
1146 }
1147
1148 if (!info->type){
1149 if (info->tty){
1150 set_bit(TTY_IO_ERROR, &info->tty->flags);
1151 }
1152 return 0;
1153 }
1154 if (!info->xmit_buf){
1155 info->xmit_buf = (unsigned char *) get_free_page (GFP_KERNEL);
1156 if (!info->xmit_buf){
1157 return -ENOMEM;
1158 }
1159 }
1160
1161 config_setup(info);
1162
1163 card = info->card;
1164 channel = (info->line) - (cy_card[card].first_line);
1165 chip = channel>>2;
1166 channel &= 0x03;
1167 base_addr = (unsigned char*)
1168 (cy_card[card].base_addr + cy_chip_offset[chip]);
1169
1170 #ifdef SERIAL_DEBUG_OPEN
1171 printk("startup card %d, chip %d, channel %d, base_addr %lx",
1172 card, chip, channel, (long)base_addr);
1173 #endif
1174
1175 save_flags(flags); cli();
1176 base_addr[CyCAR] = (u_char)channel;
1177
1178 base_addr[CyRTPR] = (info->default_timeout
1179 ? info->default_timeout
1180 : 0x02);
1181
1182 write_cy_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR);
1183
1184 base_addr[CyCAR] = (u_char)channel;
1185 base_addr[CyMSVR1] = CyRTS;
1186
1187 base_addr[CyMSVR2] = CyDTR;
1188
1189 #ifdef SERIAL_DEBUG_DTR
1190 printk("cyc: %d: raising DTR\n", __LINE__);
1191 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1192 #endif
1193
1194 base_addr[CySRER] |= CyRxData;
1195 info->flags |= ASYNC_INITIALIZED;
1196
1197 if (info->tty){
1198 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1199 }
1200 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1201
1202 restore_flags(flags);
1203
1204 #ifdef SERIAL_DEBUG_OPEN
1205 printk(" done\n");
1206 #endif
1207 return 0;
1208 }
1209
1210 void
1211 start_xmit( struct cyclades_port *info )
1212 {
1213 unsigned long flags;
1214 unsigned char *base_addr;
1215 int card,chip,channel;
1216
1217 card = info->card;
1218 channel = (info->line) - (cy_card[card].first_line);
1219 chip = channel>>2;
1220 channel &= 0x03;
1221 base_addr = (unsigned char*)
1222 (cy_card[card].base_addr + cy_chip_offset[chip]);
1223 save_flags(flags); cli();
1224 base_addr[CyCAR] = channel;
1225 base_addr[CySRER] |= CyTxMpty;
1226 restore_flags(flags);
1227 }
1228
1229
1230
1231
1232
1233 static void
1234 shutdown(struct cyclades_port * info)
1235 {
1236 unsigned long flags;
1237 unsigned char *base_addr;
1238 int card,chip,channel;
1239
1240 if (!(info->flags & ASYNC_INITIALIZED)){
1241
1242 return;
1243 }
1244
1245 card = info->card;
1246 channel = info->line - cy_card[card].first_line;
1247 chip = channel>>2;
1248 channel &= 0x03;
1249 base_addr = (unsigned char*)
1250 (cy_card[card].base_addr + cy_chip_offset[chip]);
1251
1252 #ifdef SERIAL_DEBUG_OPEN
1253 printk("shutdown card %d, chip %d, channel %d, base_addr %lx\n",
1254 card, chip, channel, (long)base_addr);
1255 #endif
1256
1257
1258
1259
1260
1261
1262
1263 save_flags(flags); cli();
1264 if (info->xmit_buf){
1265 free_page((unsigned long) info->xmit_buf);
1266 info->xmit_buf = 0;
1267 }
1268
1269 base_addr[CyCAR] = (u_char)channel;
1270 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
1271 base_addr[CyMSVR1] = ~CyRTS;
1272
1273 base_addr[CyMSVR2] = ~CyDTR;
1274 #ifdef SERIAL_DEBUG_DTR
1275 printk("cyc: %d: dropping DTR\n", __LINE__);
1276 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1277 #endif
1278 }
1279 write_cy_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR);
1280
1281
1282
1283 if (info->tty){
1284 set_bit(TTY_IO_ERROR, &info->tty->flags);
1285 }
1286 info->flags &= ~ASYNC_INITIALIZED;
1287 restore_flags(flags);
1288
1289 #ifdef SERIAL_DEBUG_OPEN
1290 printk(" done\n");
1291 #endif
1292 return;
1293 }
1294
1295
1296
1297
1298 static void
1299 config_setup(struct cyclades_port * info)
1300 {
1301 unsigned long flags;
1302 unsigned char *base_addr;
1303 int card,chip,channel;
1304 unsigned cflag;
1305 int i;
1306
1307 if (!info->tty || !info->tty->termios){
1308 return;
1309 }
1310 if (info->line == -1){
1311 return;
1312 }
1313 cflag = info->tty->termios->c_cflag;
1314
1315
1316 i = cflag & CBAUD;
1317 #ifdef CBAUDEX
1318
1319
1320
1321
1322
1323
1324
1325
1326 if (i & CBAUDEX) {
1327 if (i == B57600)
1328 i = 16;
1329 else if(i == B115200)
1330 i = 18;
1331 #ifdef B78600
1332 else if(i == B78600)
1333 i = 17;
1334 #endif
1335 else
1336 info->tty->termios->c_cflag &= ~CBAUDEX;
1337 }
1338 #endif
1339 if (i == 15) {
1340 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
1341 i += 1;
1342 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
1343 i += 3;
1344 }
1345 info->tbpr = baud_bpr[i];
1346 info->tco = baud_co[i];
1347 info->rbpr = baud_bpr[i];
1348 info->rco = baud_co[i];
1349 if (baud_table[i] == 134) {
1350 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
1351
1352 } else if (baud_table[i]) {
1353 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
1354
1355 } else {
1356 info->timeout = 0;
1357 }
1358
1359
1360
1361
1362
1363 info->cor5 = 0;
1364 info->cor4 = 0;
1365 info->cor3 = (info->default_threshold
1366 ? info->default_threshold
1367 : baud_cor3[i]);
1368 info->cor2 = CyETC;
1369 switch(cflag & CSIZE){
1370 case CS5:
1371 info->cor1 = Cy_5_BITS;
1372 break;
1373 case CS6:
1374 info->cor1 = Cy_6_BITS;
1375 break;
1376 case CS7:
1377 info->cor1 = Cy_7_BITS;
1378 break;
1379 case CS8:
1380 info->cor1 = Cy_8_BITS;
1381 break;
1382 }
1383 if(cflag & CSTOPB){
1384 info->cor1 |= Cy_2_STOP;
1385 }
1386 if (cflag & PARENB){
1387 if (cflag & PARODD){
1388 info->cor1 |= CyPARITY_O;
1389 }else{
1390 info->cor1 |= CyPARITY_E;
1391 }
1392 }else{
1393 info->cor1 |= CyPARITY_NONE;
1394 }
1395
1396
1397 if (cflag & CRTSCTS){
1398 info->flags |= ASYNC_CTS_FLOW;
1399 info->cor2 |= CyCtsAE;
1400 }else{
1401 info->flags &= ~ASYNC_CTS_FLOW;
1402 info->cor2 &= ~CyCtsAE;
1403 }
1404 if (cflag & CLOCAL)
1405 info->flags &= ~ASYNC_CHECK_CD;
1406 else
1407 info->flags |= ASYNC_CHECK_CD;
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419 card = info->card;
1420 channel = (info->line) - (cy_card[card].first_line);
1421 chip = channel>>2;
1422 channel &= 0x03;
1423 base_addr = (unsigned char*)
1424 (cy_card[card].base_addr + cy_chip_offset[chip]);
1425
1426 save_flags(flags); cli();
1427 base_addr[CyCAR] = (u_char)channel;
1428
1429
1430
1431 base_addr[CyTCOR] = info->tco;
1432 base_addr[CyTBPR] = info->tbpr;
1433 base_addr[CyRCOR] = info->rco;
1434 base_addr[CyRBPR] = info->rbpr;
1435
1436
1437
1438 base_addr[CySCHR1] = START_CHAR(info->tty);
1439 base_addr[CySCHR2] = STOP_CHAR(info->tty);
1440 base_addr[CyCOR1] = info->cor1;
1441 base_addr[CyCOR2] = info->cor2;
1442 base_addr[CyCOR3] = info->cor3;
1443 base_addr[CyCOR4] = info->cor4;
1444 base_addr[CyCOR5] = info->cor5;
1445
1446 write_cy_cmd(base_addr,CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch);
1447
1448 base_addr[CyCAR] = (u_char)channel;
1449
1450 base_addr[CyRTPR] = (info->default_timeout
1451 ? info->default_timeout
1452 : 0x02);
1453
1454 if (C_CLOCAL(info->tty)) {
1455 base_addr[CySRER] |= 0;
1456
1457 base_addr[CyMCOR1] = 0x0;
1458
1459 base_addr[CyMCOR2] = 0x0;
1460 } else {
1461 base_addr[CySRER] |= CyMdmCh;
1462
1463 base_addr[CyMCOR1] = CyDSR|CyCTS|CyRI|CyDCD;
1464
1465 base_addr[CyMCOR2] = CyDSR|CyCTS|CyRI|CyDCD;
1466 }
1467
1468 if(i == 0){
1469 base_addr[CyMSVR2] = ~CyDTR;
1470 #ifdef SERIAL_DEBUG_DTR
1471 printk("cyc: %d: dropping DTR\n", __LINE__);
1472 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1473 #endif
1474 }else{
1475 base_addr[CyMSVR2] = CyDTR;
1476 #ifdef SERIAL_DEBUG_DTR
1477 printk("cyc: %d: raising DTR\n", __LINE__);
1478 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1479 #endif
1480 }
1481
1482 if (info->tty){
1483 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1484 }
1485
1486 restore_flags(flags);
1487
1488 }
1489
1490
1491 static void
1492 cy_put_char(struct tty_struct *tty, unsigned char ch)
1493 {
1494 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1495 unsigned long flags;
1496
1497 #ifdef SERIAL_DEBUG_IO
1498 printk("cy_put_char ttyC%d\n", info->line);
1499 #endif
1500
1501 if (serial_paranoia_check(info, tty->device, "cy_put_char"))
1502 return;
1503
1504 if (!tty || !info->xmit_buf)
1505 return;
1506
1507 save_flags(flags); cli();
1508 if (info->xmit_cnt >= PAGE_SIZE - 1) {
1509 restore_flags(flags);
1510 return;
1511 }
1512
1513 info->xmit_buf[info->xmit_head++] = ch;
1514 info->xmit_head &= PAGE_SIZE - 1;
1515 info->xmit_cnt++;
1516 restore_flags(flags);
1517 }
1518
1519
1520 static void
1521 cy_flush_chars(struct tty_struct *tty)
1522 {
1523 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1524 unsigned long flags;
1525 unsigned char *base_addr;
1526 int card,chip,channel;
1527
1528 #ifdef SERIAL_DEBUG_IO
1529 printk("cy_flush_chars ttyC%d\n", info->line);
1530 #endif
1531
1532 if (serial_paranoia_check(info, tty->device, "cy_flush_chars"))
1533 return;
1534
1535 if (info->xmit_cnt <= 0 || tty->stopped
1536 || tty->hw_stopped || !info->xmit_buf)
1537 return;
1538
1539 card = info->card;
1540 channel = info->line - cy_card[card].first_line;
1541 chip = channel>>2;
1542 channel &= 0x03;
1543 base_addr = (unsigned char*)
1544 (cy_card[card].base_addr + cy_chip_offset[chip]);
1545
1546 save_flags(flags); cli();
1547 base_addr[CyCAR] = channel;
1548 base_addr[CySRER] |= CyTxMpty;
1549 restore_flags(flags);
1550 }
1551
1552
1553
1554
1555
1556
1557
1558
1559 static int
1560 cy_write(struct tty_struct * tty, int from_user,
1561 unsigned char *buf, int count)
1562 {
1563 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1564 unsigned long flags;
1565 int c, total = 0;
1566
1567 #ifdef SERIAL_DEBUG_IO
1568 printk("cy_write ttyC%d\n", info->line);
1569 #endif
1570
1571 if (serial_paranoia_check(info, tty->device, "cy_write")){
1572 return 0;
1573 }
1574
1575 if (!tty || !info->xmit_buf || !tmp_buf){
1576 return 0;
1577 }
1578
1579 while (1) {
1580 save_flags(flags); cli();
1581 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1582 SERIAL_XMIT_SIZE - info->xmit_head));
1583 if (c <= 0){
1584 restore_flags(flags);
1585 break;
1586 }
1587
1588 if (from_user) {
1589 down(&tmp_buf_sem);
1590 memcpy_fromfs(tmp_buf, buf, c);
1591 c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
1592 SERIAL_XMIT_SIZE - info->xmit_head));
1593 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
1594 up(&tmp_buf_sem);
1595 } else
1596 memcpy(info->xmit_buf + info->xmit_head, buf, c);
1597 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
1598 info->xmit_cnt += c;
1599 restore_flags(flags);
1600 buf += c;
1601 count -= c;
1602 total += c;
1603 }
1604
1605
1606 if (info->xmit_cnt
1607 && !tty->stopped
1608 && !tty->hw_stopped ) {
1609 start_xmit(info);
1610 }
1611 return total;
1612 }
1613
1614
1615 static int
1616 cy_write_room(struct tty_struct *tty)
1617 {
1618 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1619 int ret;
1620
1621 #ifdef SERIAL_DEBUG_IO
1622 printk("cy_write_room ttyC%d\n", info->line);
1623 #endif
1624
1625 if (serial_paranoia_check(info, tty->device, "cy_write_room"))
1626 return 0;
1627 ret = PAGE_SIZE - info->xmit_cnt - 1;
1628 if (ret < 0)
1629 ret = 0;
1630 return ret;
1631 }
1632
1633
1634 static int
1635 cy_chars_in_buffer(struct tty_struct *tty)
1636 {
1637 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1638
1639 #ifdef SERIAL_DEBUG_IO
1640 printk("cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt);
1641 #endif
1642
1643 if (serial_paranoia_check(info, tty->device, "cy_chars_in_buffer"))
1644 return 0;
1645
1646 return info->xmit_cnt;
1647 }
1648
1649
1650 static void
1651 cy_flush_buffer(struct tty_struct *tty)
1652 {
1653 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1654 unsigned long flags;
1655
1656 #ifdef SERIAL_DEBUG_IO
1657 printk("cy_flush_buffer ttyC%d\n", info->line);
1658 #endif
1659
1660 if (serial_paranoia_check(info, tty->device, "cy_flush_buffer"))
1661 return;
1662 save_flags(flags); cli();
1663 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1664 restore_flags(flags);
1665 wake_up_interruptible(&tty->write_wait);
1666 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
1667 && tty->ldisc.write_wakeup)
1668 (tty->ldisc.write_wakeup)(tty);
1669 }
1670
1671
1672
1673
1674
1675
1676 static void
1677 cy_throttle(struct tty_struct * tty)
1678 {
1679 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1680 unsigned long flags;
1681 unsigned char *base_addr;
1682 int card,chip,channel;
1683
1684 #ifdef SERIAL_DEBUG_THROTTLE
1685 char buf[64];
1686
1687 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1688 tty->ldisc.chars_in_buffer(tty));
1689 printk("cy_throttle ttyC%d\n", info->line);
1690 #endif
1691
1692 if (serial_paranoia_check(info, tty->device, "cy_nthrottle")){
1693 return;
1694 }
1695
1696 if (I_IXOFF(tty)) {
1697 info->x_char = STOP_CHAR(tty);
1698
1699 }
1700
1701 card = info->card;
1702 channel = info->line - cy_card[card].first_line;
1703 chip = channel>>2;
1704 channel &= 0x03;
1705 base_addr = (unsigned char*)
1706 (cy_card[card].base_addr + cy_chip_offset[chip]);
1707
1708 save_flags(flags); cli();
1709 base_addr[CyCAR] = (u_char)channel;
1710 base_addr[CyMSVR1] = ~CyRTS;
1711 restore_flags(flags);
1712
1713 return;
1714 }
1715
1716
1717 static void
1718 cy_unthrottle(struct tty_struct * tty)
1719 {
1720 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
1721 unsigned long flags;
1722 unsigned char *base_addr;
1723 int card,chip,channel;
1724
1725 #ifdef SERIAL_DEBUG_THROTTLE
1726 char buf[64];
1727
1728 printk("throttle %s: %d....\n", _tty_name(tty, buf),
1729 tty->ldisc.chars_in_buffer(tty));
1730 printk("cy_unthrottle ttyC%d\n", info->line);
1731 #endif
1732
1733 if (serial_paranoia_check(info, tty->device, "cy_nthrottle")){
1734 return;
1735 }
1736
1737 if (I_IXOFF(tty)) {
1738 info->x_char = START_CHAR(tty);
1739
1740 }
1741
1742 card = info->card;
1743 channel = info->line - cy_card[card].first_line;
1744 chip = channel>>2;
1745 channel &= 0x03;
1746 base_addr = (unsigned char*)
1747 (cy_card[card].base_addr + cy_chip_offset[chip]);
1748
1749 save_flags(flags); cli();
1750 base_addr[CyCAR] = (u_char)channel;
1751 base_addr[CyMSVR1] = CyRTS;
1752 restore_flags(flags);
1753
1754 return;
1755 }
1756
1757 static int
1758 get_serial_info(struct cyclades_port * info,
1759 struct serial_struct * retinfo)
1760 {
1761 struct serial_struct tmp;
1762 struct cyclades_card *cinfo = &cy_card[info->card];
1763
1764
1765 if (!retinfo)
1766 return -EFAULT;
1767 memset(&tmp, 0, sizeof(tmp));
1768 tmp.type = info->type;
1769 tmp.line = info->line;
1770 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
1771 tmp.irq = cinfo->irq;
1772 tmp.flags = info->flags;
1773 tmp.baud_base = 0;
1774 tmp.close_delay = info->close_delay;
1775 tmp.custom_divisor = 0;
1776 tmp.hub6 = 0;
1777 memcpy_tofs(retinfo,&tmp,sizeof(*retinfo));
1778 return 0;
1779 }
1780
1781 static int
1782 set_serial_info(struct cyclades_port * info,
1783 struct serial_struct * new_info)
1784 {
1785 struct serial_struct new_serial;
1786 struct cyclades_port old_info;
1787
1788
1789 if (!new_info)
1790 return -EFAULT;
1791 memcpy_fromfs(&new_serial,new_info,sizeof(new_serial));
1792 old_info = *info;
1793
1794 if (!suser()) {
1795 if ((new_serial.close_delay != info->close_delay) ||
1796 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
1797 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
1798 return -EPERM;
1799 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
1800 (new_serial.flags & ASYNC_USR_MASK));
1801 goto check_and_exit;
1802 }
1803
1804
1805
1806
1807
1808
1809
1810 info->flags = ((info->flags & ~ASYNC_FLAGS) |
1811 (new_serial.flags & ASYNC_FLAGS));
1812 info->close_delay = new_serial.close_delay;
1813
1814
1815 check_and_exit:
1816 if (info->flags & ASYNC_INITIALIZED){
1817 config_setup(info);
1818 return 0;
1819 }else{
1820 return startup(info);
1821 }
1822 }
1823
1824 static int
1825 get_modem_info(struct cyclades_port * info, unsigned int *value)
1826 {
1827 int card,chip,channel;
1828 unsigned char *base_addr;
1829 unsigned long flags;
1830 unsigned char status;
1831 unsigned int result;
1832
1833 card = info->card;
1834 channel = (info->line) - (cy_card[card].first_line);
1835 chip = channel>>2;
1836 channel &= 0x03;
1837 base_addr = (unsigned char*)
1838 (cy_card[card].base_addr + cy_chip_offset[chip]);
1839
1840 save_flags(flags); cli();
1841 base_addr[CyCAR] = (u_char)channel;
1842 status = base_addr[CyMSVR1] | base_addr[CyMSVR2];
1843 restore_flags(flags);
1844
1845 result = ((status & CyRTS) ? TIOCM_RTS : 0)
1846 | ((status & CyDTR) ? TIOCM_DTR : 0)
1847 | ((status & CyDCD) ? TIOCM_CAR : 0)
1848 | ((status & CyRI) ? TIOCM_RNG : 0)
1849 | ((status & CyDSR) ? TIOCM_DSR : 0)
1850 | ((status & CyCTS) ? TIOCM_CTS : 0);
1851 put_fs_long(result,(unsigned long *) value);
1852 return 0;
1853 }
1854
1855 static int
1856 set_modem_info(struct cyclades_port * info, unsigned int cmd,
1857 unsigned int *value)
1858 {
1859 int card,chip,channel;
1860 unsigned char *base_addr;
1861 unsigned long flags;
1862 unsigned int arg = get_fs_long((unsigned long *) value);
1863
1864 card = info->card;
1865 channel = (info->line) - (cy_card[card].first_line);
1866 chip = channel>>2;
1867 channel &= 0x03;
1868 base_addr = (unsigned char*)
1869 (cy_card[card].base_addr + cy_chip_offset[chip]);
1870
1871 switch (cmd) {
1872 case TIOCMBIS:
1873 if (arg & TIOCM_RTS){
1874 save_flags(flags); cli();
1875 base_addr[CyCAR] = (u_char)channel;
1876 base_addr[CyMSVR1] = CyRTS;
1877 restore_flags(flags);
1878 }
1879 if (arg & TIOCM_DTR){
1880 save_flags(flags); cli();
1881 base_addr[CyCAR] = (u_char)channel;
1882
1883 base_addr[CyMSVR2] = CyDTR;
1884 #ifdef SERIAL_DEBUG_DTR
1885 printk("cyc: %d: raising DTR\n", __LINE__);
1886 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1887 #endif
1888 restore_flags(flags);
1889 }
1890 break;
1891 case TIOCMBIC:
1892 if (arg & TIOCM_RTS){
1893 save_flags(flags); cli();
1894 base_addr[CyCAR] = (u_char)channel;
1895 base_addr[CyMSVR1] = ~CyRTS;
1896 restore_flags(flags);
1897 }
1898 if (arg & TIOCM_DTR){
1899 save_flags(flags); cli();
1900 base_addr[CyCAR] = (u_char)channel;
1901
1902 base_addr[CyMSVR2] = ~CyDTR;
1903 #ifdef SERIAL_DEBUG_DTR
1904 printk("cyc: %d: dropping DTR\n", __LINE__);
1905 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1906 #endif
1907 restore_flags(flags);
1908 }
1909 break;
1910 case TIOCMSET:
1911 if (arg & TIOCM_RTS){
1912 save_flags(flags); cli();
1913 base_addr[CyCAR] = (u_char)channel;
1914 base_addr[CyMSVR1] = CyRTS;
1915 restore_flags(flags);
1916 }else{
1917 save_flags(flags); cli();
1918 base_addr[CyCAR] = (u_char)channel;
1919 base_addr[CyMSVR1] = ~CyRTS;
1920 restore_flags(flags);
1921 }
1922 if (arg & TIOCM_DTR){
1923 save_flags(flags); cli();
1924 base_addr[CyCAR] = (u_char)channel;
1925
1926 base_addr[CyMSVR2] = CyDTR;
1927 #ifdef SERIAL_DEBUG_DTR
1928 printk("cyc: %d: raising DTR\n", __LINE__);
1929 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1930 #endif
1931 restore_flags(flags);
1932 }else{
1933 save_flags(flags); cli();
1934 base_addr[CyCAR] = (u_char)channel;
1935
1936 base_addr[CyMSVR2] = ~CyDTR;
1937 #ifdef SERIAL_DEBUG_DTR
1938 printk("cyc: %d: dropping DTR\n", __LINE__);
1939 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
1940 #endif
1941 restore_flags(flags);
1942 }
1943 break;
1944 default:
1945 return -EINVAL;
1946 }
1947 return 0;
1948 }
1949
1950 static void
1951 send_break( struct cyclades_port * info, int duration)
1952 {
1953
1954
1955 info->x_break = duration;
1956 if (!info->xmit_cnt ) {
1957 start_xmit(info);
1958 }
1959 }
1960
1961 static int
1962 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
1963 {
1964
1965 memcpy_tofs(mon, &info->mon, sizeof(struct cyclades_monitor));
1966 info->mon.int_count = 0;
1967 info->mon.char_count = 0;
1968 info->mon.char_max = 0;
1969 info->mon.char_last = 0;
1970 return 0;
1971 }
1972
1973 static int
1974 set_threshold(struct cyclades_port * info, unsigned long value)
1975 {
1976 unsigned char *base_addr;
1977 int card,channel,chip;
1978
1979 card = info->card;
1980 channel = info->line - cy_card[card].first_line;
1981 chip = channel>>2;
1982 channel &= 0x03;
1983 base_addr = (unsigned char*)
1984 (cy_card[card].base_addr + cy_chip_offset[chip]);
1985
1986 info->cor3 &= ~CyREC_FIFO;
1987 info->cor3 |= value & CyREC_FIFO;
1988 base_addr[CyCOR3] = info->cor3;
1989 write_cy_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch);
1990 return 0;
1991 }
1992
1993 static int
1994 get_threshold(struct cyclades_port * info, unsigned long *value)
1995 {
1996 unsigned char *base_addr;
1997 int card,channel,chip;
1998 unsigned long tmp;
1999
2000 card = info->card;
2001 channel = info->line - cy_card[card].first_line;
2002 chip = channel>>2;
2003 channel &= 0x03;
2004 base_addr = (unsigned char*)
2005 (cy_card[card].base_addr + cy_chip_offset[chip]);
2006
2007 tmp = base_addr[CyCOR3] & CyREC_FIFO;
2008 put_fs_long(tmp,value);
2009 return 0;
2010 }
2011
2012 static int
2013 set_default_threshold(struct cyclades_port * info, unsigned long value)
2014 {
2015 info->default_threshold = value & 0x0f;
2016 return 0;
2017 }
2018
2019 static int
2020 get_default_threshold(struct cyclades_port * info, unsigned long *value)
2021 {
2022 put_fs_long(info->default_threshold,value);
2023 return 0;
2024 }
2025
2026 static int
2027 set_timeout(struct cyclades_port * info, unsigned long value)
2028 {
2029 unsigned char *base_addr;
2030 int card,channel,chip;
2031
2032 card = info->card;
2033 channel = info->line - cy_card[card].first_line;
2034 chip = channel>>2;
2035 channel &= 0x03;
2036 base_addr = (unsigned char*)
2037 (cy_card[card].base_addr + cy_chip_offset[chip]);
2038
2039 base_addr[CyRTPR] = value & 0xff;
2040 return 0;
2041 }
2042
2043 static int
2044 get_timeout(struct cyclades_port * info, unsigned long *value)
2045 {
2046 unsigned char *base_addr;
2047 int card,channel,chip;
2048 unsigned long tmp;
2049
2050 card = info->card;
2051 channel = info->line - cy_card[card].first_line;
2052 chip = channel>>2;
2053 channel &= 0x03;
2054 base_addr = (unsigned char*)
2055 (cy_card[card].base_addr + cy_chip_offset[chip]);
2056
2057 tmp = base_addr[CyRTPR];
2058 put_fs_long(tmp,value);
2059 return 0;
2060 }
2061
2062 static int
2063 set_default_timeout(struct cyclades_port * info, unsigned long value)
2064 {
2065 info->default_timeout = value & 0xff;
2066 return 0;
2067 }
2068
2069 static int
2070 get_default_timeout(struct cyclades_port * info, unsigned long *value)
2071 {
2072 put_fs_long(info->default_timeout,value);
2073 return 0;
2074 }
2075
2076 static int
2077 cy_ioctl(struct tty_struct *tty, struct file * file,
2078 unsigned int cmd, unsigned long arg)
2079 {
2080 int error;
2081 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
2082 int ret_val = 0;
2083
2084 #ifdef SERIAL_DEBUG_OTHER
2085 printk("cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg);
2086 #endif
2087
2088 switch (cmd) {
2089 case CYGETMON:
2090 error = verify_area(VERIFY_WRITE, (void *) arg
2091 ,sizeof(struct cyclades_monitor));
2092 if (error){
2093 ret_val = error;
2094 break;
2095 }
2096 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
2097 break;
2098 case CYGETTHRESH:
2099 error = verify_area(VERIFY_WRITE, (void *) arg
2100 ,sizeof(unsigned long));
2101 if (error){
2102 ret_val = error;
2103 break;
2104 }
2105 ret_val = get_threshold(info, (unsigned long *)arg);
2106 break;
2107 case CYSETTHRESH:
2108 ret_val = set_threshold(info, (unsigned long)arg);
2109 break;
2110 case CYGETDEFTHRESH:
2111 error = verify_area(VERIFY_WRITE, (void *) arg
2112 ,sizeof(unsigned long));
2113 if (error){
2114 ret_val = error;
2115 break;
2116 }
2117 ret_val = get_default_threshold(info, (unsigned long *)arg);
2118 break;
2119 case CYSETDEFTHRESH:
2120 ret_val = set_default_threshold(info, (unsigned long)arg);
2121 break;
2122 case CYGETTIMEOUT:
2123 error = verify_area(VERIFY_WRITE, (void *) arg
2124 ,sizeof(unsigned long));
2125 if (error){
2126 ret_val = error;
2127 break;
2128 }
2129 ret_val = get_timeout(info, (unsigned long *)arg);
2130 break;
2131 case CYSETTIMEOUT:
2132 ret_val = set_timeout(info, (unsigned long)arg);
2133 break;
2134 case CYGETDEFTIMEOUT:
2135 error = verify_area(VERIFY_WRITE, (void *) arg
2136 ,sizeof(unsigned long));
2137 if (error){
2138 ret_val = error;
2139 break;
2140 }
2141 ret_val = get_default_timeout(info, (unsigned long *)arg);
2142 break;
2143 case CYSETDEFTIMEOUT:
2144 ret_val = set_default_timeout(info, (unsigned long)arg);
2145 break;
2146 case TCSBRK:
2147 ret_val = tty_check_change(tty);
2148 if (ret_val)
2149 return ret_val;
2150 tty_wait_until_sent(tty,0);
2151 if (!arg)
2152 send_break(info, HZ/4);
2153 break;
2154 case TCSBRKP:
2155 ret_val = tty_check_change(tty);
2156 if (ret_val)
2157 return ret_val;
2158 tty_wait_until_sent(tty,0);
2159 send_break(info, arg ? arg*(HZ/10) : HZ/4);
2160 break;
2161 case TIOCMBIS:
2162 case TIOCMBIC:
2163 case TIOCMSET:
2164 ret_val = set_modem_info(info, cmd, (unsigned int *) arg);
2165 break;
2166
2167
2168 case TIOCGSOFTCAR:
2169 error = verify_area(VERIFY_WRITE, (void *) arg
2170 ,sizeof(unsigned int *));
2171 if (error){
2172 ret_val = error;
2173 break;
2174 }
2175 put_fs_long(C_CLOCAL(tty) ? 1 : 0,
2176 (unsigned long *) arg);
2177 break;
2178 case TIOCSSOFTCAR:
2179 arg = get_fs_long((unsigned long *) arg);
2180 tty->termios->c_cflag =
2181 ((tty->termios->c_cflag & ~CLOCAL) |
2182 (arg ? CLOCAL : 0));
2183 break;
2184 case TIOCMGET:
2185 error = verify_area(VERIFY_WRITE, (void *) arg
2186 ,sizeof(unsigned int *));
2187 if (error){
2188 ret_val = error;
2189 break;
2190 }
2191 ret_val = get_modem_info(info, (unsigned int *) arg);
2192 break;
2193 case TIOCGSERIAL:
2194 error = verify_area(VERIFY_WRITE, (void *) arg
2195 ,sizeof(struct serial_struct));
2196 if (error){
2197 ret_val = error;
2198 break;
2199 }
2200 ret_val = get_serial_info(info,
2201 (struct serial_struct *) arg);
2202 break;
2203 case TIOCSSERIAL:
2204 ret_val = set_serial_info(info,
2205 (struct serial_struct *) arg);
2206 break;
2207 default:
2208 ret_val = -ENOIOCTLCMD;
2209 }
2210
2211 #ifdef SERIAL_DEBUG_OTHER
2212 printk("cy_ioctl done\n");
2213 #endif
2214
2215 return ret_val;
2216 }
2217
2218
2219
2220
2221 static void
2222 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
2223 {
2224 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2225
2226 #ifdef SERIAL_DEBUG_OTHER
2227 printk("cy_set_termios ttyC%d\n", info->line);
2228 #endif
2229
2230 if (tty->termios->c_cflag == old_termios->c_cflag)
2231 return;
2232 config_setup(info);
2233
2234 if ((old_termios->c_cflag & CRTSCTS) &&
2235 !(tty->termios->c_cflag & CRTSCTS)) {
2236 tty->stopped = 0;
2237 cy_start(tty);
2238 }
2239 #ifdef tytso_patch_94Nov25_1726
2240 if (!(old_termios->c_cflag & CLOCAL) &&
2241 (tty->termios->c_cflag & CLOCAL))
2242 wake_up_interruptible(&info->open_wait);
2243 #endif
2244
2245 return;
2246 }
2247
2248
2249 static void
2250 cy_close(struct tty_struct * tty, struct file * filp)
2251 {
2252 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
2253
2254
2255 #ifdef SERIAL_DEBUG_OTHER
2256 printk("cy_close ttyC%d\n", info->line);
2257 #endif
2258
2259 if (!info
2260 || serial_paranoia_check(info, tty->device, "cy_close")){
2261 return;
2262 }
2263 #ifdef SERIAL_DEBUG_OPEN
2264 printk("cy_close ttyC%d, count = %d\n", info->line, info->count);
2265 #endif
2266
2267 if ((tty->count == 1) && (info->count != 1)) {
2268
2269
2270
2271
2272
2273
2274
2275 printk("cy_close: bad serial port count; tty->count is 1, "
2276 "info->count is %d\n", info->count);
2277 info->count = 1;
2278 }
2279 #ifdef SERIAL_DEBUG_COUNT
2280 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count - 1);
2281 #endif
2282 if (--info->count < 0) {
2283 printk("cy_close: bad serial port count for ttys%d: %d\n",
2284 info->line, info->count);
2285 #ifdef SERIAL_DEBUG_COUNT
2286 printk("cyc: %d: setting count to 0\n", __LINE__);
2287 #endif
2288 info->count = 0;
2289 }
2290 if (info->count)
2291 return;
2292 info->flags |= ASYNC_CLOSING;
2293
2294
2295
2296
2297 if (info->flags & ASYNC_NORMAL_ACTIVE)
2298 info->normal_termios = *tty->termios;
2299 if (info->flags & ASYNC_CALLOUT_ACTIVE)
2300 info->callout_termios = *tty->termios;
2301 if (info->flags & ASYNC_INITIALIZED)
2302 tty_wait_until_sent(tty, 3000);
2303 shutdown(info);
2304 if (tty->driver.flush_buffer)
2305 tty->driver.flush_buffer(tty);
2306 if (tty->ldisc.flush_buffer)
2307 tty->ldisc.flush_buffer(tty);
2308 info->event = 0;
2309 info->tty = 0;
2310 if (tty->ldisc.num != ldiscs[N_TTY].num) {
2311 if (tty->ldisc.close)
2312 (tty->ldisc.close)(tty);
2313 tty->ldisc = ldiscs[N_TTY];
2314 tty->termios->c_line = N_TTY;
2315 if (tty->ldisc.open)
2316 (tty->ldisc.open)(tty);
2317 }
2318 if (info->blocked_open) {
2319 if (info->close_delay) {
2320 current->state = TASK_INTERRUPTIBLE;
2321 current->timeout = jiffies + info->close_delay;
2322 schedule();
2323 }
2324 wake_up_interruptible(&info->open_wait);
2325 }
2326 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
2327 ASYNC_CLOSING);
2328 wake_up_interruptible(&info->close_wait);
2329
2330 #ifdef SERIAL_DEBUG_OTHER
2331 printk("cy_close done\n");
2332 #endif
2333
2334 return;
2335 }
2336
2337
2338
2339
2340 void
2341 cy_hangup(struct tty_struct *tty)
2342 {
2343 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
2344
2345 #ifdef SERIAL_DEBUG_OTHER
2346 printk("cy_hangup ttyC%d\n", info->line);
2347 #endif
2348
2349 if (serial_paranoia_check(info, tty->device, "cy_hangup"))
2350 return;
2351
2352 shutdown(info);
2353 #if 0
2354 info->event = 0;
2355 info->count = 0;
2356 #ifdef SERIAL_DEBUG_COUNT
2357 printk("cyc: %d: setting count to 0\n", __LINE__);
2358 #endif
2359 info->tty = 0;
2360 #endif
2361 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
2362 wake_up_interruptible(&info->open_wait);
2363 }
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373 static int
2374 block_til_ready(struct tty_struct *tty, struct file * filp,
2375 struct cyclades_port *info)
2376 {
2377 struct wait_queue wait = { current, NULL };
2378 struct cyclades_card *cinfo;
2379 unsigned long flags;
2380 int chip, channel;
2381 int retval;
2382 char *base_addr;
2383
2384
2385
2386
2387
2388 if (info->flags & ASYNC_CLOSING) {
2389 interruptible_sleep_on(&info->close_wait);
2390 if (info->flags & ASYNC_HUP_NOTIFY){
2391 return -EAGAIN;
2392 }else{
2393 return -ERESTARTSYS;
2394 }
2395 }
2396
2397
2398
2399
2400
2401 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
2402 if (info->flags & ASYNC_NORMAL_ACTIVE){
2403 return -EBUSY;
2404 }
2405 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2406 (info->flags & ASYNC_SESSION_LOCKOUT) &&
2407 (info->session != current->session)){
2408 return -EBUSY;
2409 }
2410 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2411 (info->flags & ASYNC_PGRP_LOCKOUT) &&
2412 (info->pgrp != current->pgrp)){
2413 return -EBUSY;
2414 }
2415 info->flags |= ASYNC_CALLOUT_ACTIVE;
2416 return 0;
2417 }
2418
2419
2420
2421
2422
2423 if (filp->f_flags & O_NONBLOCK) {
2424 if (info->flags & ASYNC_CALLOUT_ACTIVE){
2425 return -EBUSY;
2426 }
2427 info->flags |= ASYNC_NORMAL_ACTIVE;
2428 return 0;
2429 }
2430
2431
2432
2433
2434
2435
2436
2437
2438 retval = 0;
2439 add_wait_queue(&info->open_wait, &wait);
2440 #ifdef SERIAL_DEBUG_OPEN
2441 printk("block_til_ready before block: ttyC%d, count = %d\n",
2442 info->line, info->count);
2443 #endif
2444 info->count--;
2445 #ifdef SERIAL_DEBUG_COUNT
2446 printk("cyc: %d: decrementing count to %d\n", __LINE__, info->count);
2447 #endif
2448 info->blocked_open++;
2449
2450 cinfo = &cy_card[info->card];
2451 channel = info->line - cinfo->first_line;
2452 chip = channel>>2;
2453 channel &= 0x03;
2454 base_addr = (char *) (cinfo->base_addr + cy_chip_offset[chip]);
2455
2456 while (1) {
2457 save_flags(flags); cli();
2458 if (!(info->flags & ASYNC_CALLOUT_ACTIVE)){
2459 base_addr[CyCAR] = (u_char)channel;
2460 base_addr[CyMSVR1] = CyRTS;
2461
2462 base_addr[CyMSVR2] = CyDTR;
2463 #ifdef SERIAL_DEBUG_DTR
2464 printk("cyc: %d: raising DTR\n", __LINE__);
2465 printk(" status: 0x%x, 0x%x\n", base_addr[CyMSVR1], base_addr[CyMSVR2]);
2466 #endif
2467 }
2468 restore_flags(flags);
2469 current->state = TASK_INTERRUPTIBLE;
2470 if (tty_hung_up_p(filp)
2471 || !(info->flags & ASYNC_INITIALIZED) ){
2472 if (info->flags & ASYNC_HUP_NOTIFY) {
2473 retval = -EAGAIN;
2474 }else{
2475 retval = -ERESTARTSYS;
2476 }
2477 break;
2478 }
2479 save_flags(flags); cli();
2480 base_addr[CyCAR] = (u_char)channel;
2481
2482 if (!(info->flags & ASYNC_CALLOUT_ACTIVE)
2483 && !(info->flags & ASYNC_CLOSING)
2484 && (C_CLOCAL(tty)
2485 || (base_addr[CyMSVR1] & CyDCD))) {
2486 restore_flags(flags);
2487 break;
2488 }
2489 restore_flags(flags);
2490 if (current->signal & ~current->blocked) {
2491 retval = -ERESTARTSYS;
2492 break;
2493 }
2494 #ifdef SERIAL_DEBUG_OPEN
2495 printk("block_til_ready blocking: ttyC%d, count = %d\n",
2496 info->line, info->count);
2497 #endif
2498 schedule();
2499 }
2500 current->state = TASK_RUNNING;
2501 remove_wait_queue(&info->open_wait, &wait);
2502 if (!tty_hung_up_p(filp)){
2503 info->count++;
2504 #ifdef SERIAL_DEBUG_COUNT
2505 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2506 #endif
2507 }
2508 info->blocked_open--;
2509 #ifdef SERIAL_DEBUG_OPEN
2510 printk("block_til_ready after blocking: ttyC%d, count = %d\n",
2511 info->line, info->count);
2512 #endif
2513 if (retval)
2514 return retval;
2515 info->flags |= ASYNC_NORMAL_ACTIVE;
2516 return 0;
2517 }
2518
2519
2520
2521
2522
2523 int
2524 cy_open(struct tty_struct *tty, struct file * filp)
2525 {
2526 struct cyclades_port *info;
2527 int retval, line;
2528
2529
2530 line = MINOR(tty->device) - tty->driver.minor_start;
2531 if ((line < 0) || (NR_PORTS <= line)){
2532 return -ENODEV;
2533 }
2534 info = &cy_port[line];
2535 if (info->line < 0){
2536 return -ENODEV;
2537 }
2538 #ifdef SERIAL_DEBUG_OTHER
2539 printk("cy_open ttyC%d\n", info->line);
2540 #endif
2541 if (serial_paranoia_check(info, tty->device, "cy_open")){
2542 return -ENODEV;
2543 }
2544 #ifdef SERIAL_DEBUG_OPEN
2545 printk("cy_open ttyC%d, count = %d\n", info->line, info->count);
2546 #endif
2547 info->count++;
2548 #ifdef SERIAL_DEBUG_COUNT
2549 printk("cyc: %d: incrementing count to %d\n", __LINE__, info->count);
2550 #endif
2551 tty->driver_data = info;
2552 info->tty = tty;
2553
2554 if (!tmp_buf) {
2555 tmp_buf = (unsigned char *) get_free_page(GFP_KERNEL);
2556 if (!tmp_buf){
2557 return -ENOMEM;
2558 }
2559 }
2560
2561 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2562 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2563 *tty->termios = info->normal_termios;
2564 else
2565 *tty->termios = info->callout_termios;
2566 }
2567
2568
2569
2570 retval = startup(info);
2571 if (retval){
2572 return retval;
2573 }
2574
2575 retval = block_til_ready(tty, filp, info);
2576 if (retval) {
2577 #ifdef SERIAL_DEBUG_OPEN
2578 printk("cy_open returning after block_til_ready with %d\n",
2579 retval);
2580 #endif
2581 return retval;
2582 }
2583
2584 info->session = current->session;
2585 info->pgrp = current->pgrp;
2586
2587 #ifdef SERIAL_DEBUG_OPEN
2588 printk("cy_open done\n");
2589 #endif
2590 return 0;
2591 }
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608 static void
2609 show_version(void)
2610 {
2611 printk("Cyclom driver %s\n",rcsid);
2612 }
2613
2614
2615
2616 int
2617 cy_init_card(unsigned char *true_base_addr)
2618 {
2619 volatile unsigned short discard;
2620 unsigned int chip_number;
2621 unsigned char* base_addr;
2622
2623 discard = true_base_addr[Cy_HwReset];
2624 discard = true_base_addr[Cy_ClrIntr];
2625 udelay(500L);
2626
2627 for(chip_number=0; chip_number<CyMaxChipsPerCard; chip_number++){
2628 base_addr = true_base_addr + cy_chip_offset[chip_number];
2629 udelay(1000L);
2630 if(base_addr[CyCCR] != 0x00){
2631
2632
2633
2634
2635 return chip_number;
2636 }
2637
2638 base_addr[CyGFRCR] = 0;
2639 udelay(10L);
2640
2641 base_addr[CyCCR] = CyCHIP_RESET;
2642 udelay(1000L);
2643
2644 if(base_addr[CyGFRCR] == 0x00){
2645 printk(" chip #%d at %#6lx is not responding (GFRCR stayed 0)\n",
2646 chip_number, (unsigned long)base_addr);
2647 return chip_number;
2648 }
2649 if((0xf0 & base_addr[CyGFRCR]) != 0x40){
2650 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
2651 chip_number, (unsigned long)base_addr, base_addr[CyGFRCR]);
2652 return chip_number;
2653 }
2654 base_addr[CyGCR] = CyCH0_SERIAL;
2655 base_addr[CyPPR] = 244;
2656
2657
2658 printk(" chip #%d at %#6lx is rev 0x%2x\n",
2659 chip_number, (unsigned long)base_addr, base_addr[CyGFRCR]);
2660 }
2661
2662 return chip_number;
2663 }
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681 long
2682 cy_init(long kmem_start)
2683 {
2684 struct cyclades_port *info;
2685 struct cyclades_card *cinfo;
2686 int good_ports = 0;
2687 int port_num = 0;
2688 int index;
2689 #ifdef notyet
2690 struct sigaction sa;
2691 #endif
2692 int retval;
2693
2694 scrn[1] = '\0';
2695 show_version();
2696
2697
2698
2699 memset(&cy_serial_driver, 0, sizeof(struct tty_driver));
2700 cy_serial_driver.magic = TTY_DRIVER_MAGIC;
2701 cy_serial_driver.name = "ttyC";
2702 cy_serial_driver.major = CYCLADES_MAJOR;
2703 cy_serial_driver.minor_start = 32;
2704 cy_serial_driver.num = NR_PORTS;
2705 cy_serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
2706 cy_serial_driver.subtype = SERIAL_TYPE_NORMAL;
2707 cy_serial_driver.init_termios = tty_std_termios;
2708 cy_serial_driver.init_termios.c_cflag =
2709 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
2710 cy_serial_driver.flags = TTY_DRIVER_REAL_RAW;
2711 cy_serial_driver.refcount = &serial_refcount;
2712 cy_serial_driver.table = serial_table;
2713 cy_serial_driver.termios = serial_termios;
2714 cy_serial_driver.termios_locked = serial_termios_locked;
2715 cy_serial_driver.open = cy_open;
2716 cy_serial_driver.close = cy_close;
2717 cy_serial_driver.write = cy_write;
2718 cy_serial_driver.put_char = cy_put_char;
2719 cy_serial_driver.flush_chars = cy_flush_chars;
2720 cy_serial_driver.write_room = cy_write_room;
2721 cy_serial_driver.chars_in_buffer = cy_chars_in_buffer;
2722 cy_serial_driver.flush_buffer = cy_flush_buffer;
2723 cy_serial_driver.ioctl = cy_ioctl;
2724 cy_serial_driver.throttle = cy_throttle;
2725 cy_serial_driver.unthrottle = cy_unthrottle;
2726 cy_serial_driver.set_termios = cy_set_termios;
2727 cy_serial_driver.stop = cy_stop;
2728 cy_serial_driver.start = cy_start;
2729 cy_serial_driver.hangup = cy_hangup;
2730
2731
2732
2733
2734
2735 cy_callout_driver = cy_serial_driver;
2736 cy_callout_driver.name = "cub";
2737 cy_callout_driver.major = CYCLADESAUX_MAJOR;
2738 cy_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
2739
2740 if (tty_register_driver(&cy_serial_driver))
2741 panic("Couldn't register Cyclom serial driver\n");
2742 if (tty_register_driver(&cy_callout_driver))
2743 panic("Couldn't register Cyclom callout driver\n");
2744
2745 bh_base[CYCLADES_BH].routine = do_cyclades_bh;
2746 enable_bh(CYCLADES_BH);
2747
2748 for (index = 0; index < 16; index++) {
2749 IRQ_cards[index] = 0;
2750 }
2751
2752 port_num = 0;
2753 info = cy_port;
2754 for (index = 0, cinfo = cy_card; index < NR_CARDS; index++,cinfo++) {
2755
2756 if(0 == (cinfo->num_chips =
2757 cy_init_card((unsigned char *)cinfo->base_addr))){
2758
2759 continue;
2760 }
2761
2762 #ifndef CY_DONT_PROBE
2763
2764 cinfo->irq = do_auto_irq(index);
2765 #endif
2766
2767
2768 if (cinfo->irq) {
2769 retval = request_irq(cinfo->irq, cy_interrupt,
2770 SA_INTERRUPT, "cyclades");
2771 if (retval){
2772 printk("request_irq returned %d\n",retval);
2773
2774 }
2775 IRQ_cards[cinfo->irq] = cinfo;
2776 }else{
2777 printk("couldn't get board's irq\n");
2778 continue;
2779 }
2780
2781 printk(" share IRQ %d: ", cinfo->irq);
2782 good_ports = 4 * cinfo->num_chips;
2783
2784 if(port_num < NR_PORTS){
2785 cinfo->first_line = port_num;
2786 while( good_ports-- && port_num < NR_PORTS){
2787
2788 info->magic = CYCLADES_MAGIC;
2789 info->type = PORT_CIRRUS;
2790 info->card = index;
2791 info->line = port_num;
2792 info->flags = STD_COM_FLAGS;
2793 info->tty = 0;
2794 info->xmit_fifo_size = 12;
2795 info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS;
2796 info->cor2 = CyETC;
2797 info->cor3 = 0x08;
2798 info->cor4 = 0;
2799 info->cor5 = 0;
2800 info->tbpr = baud_bpr[13];
2801 info->tco = baud_co[13];
2802 info->rbpr = baud_bpr[13];
2803 info->rco = baud_co[13];
2804 info->close_delay = 0;
2805 info->x_char = 0;
2806 info->event = 0;
2807 info->count = 0;
2808 #ifdef SERIAL_DEBUG_COUNT
2809 printk("cyc: %d: setting count to 0\n", __LINE__);
2810 #endif
2811 info->blocked_open = 0;
2812 info->default_threshold = 0;
2813 info->default_timeout = 0;
2814 info->tqueue.routine = do_softint;
2815 info->tqueue.data = info;
2816 info->callout_termios =cy_callout_driver.init_termios;
2817 info->normal_termios = cy_serial_driver.init_termios;
2818 info->open_wait = 0;
2819 info->close_wait = 0;
2820
2821
2822
2823 info->read_status_mask = CyTIMEOUT| CySPECHAR| CyBREAK
2824 | CyPARITY| CyFRAME| CyOVERRUN;
2825
2826
2827 printk("ttyC%1d ", info->line);
2828 port_num++;info++;
2829 if(!(port_num & 7)){
2830 printk("\n ");
2831 }
2832 }
2833 }else{
2834 cinfo->first_line = -1;
2835 }
2836 printk("\n");
2837 }
2838 while( port_num < NR_PORTS){
2839 info->line = -1;
2840 port_num++;info++;
2841 }
2842 return kmem_start;
2843
2844 }
2845
2846 #ifdef CYCLOM_SHOW_STATUS
2847 static void
2848 show_status(int line_num)
2849 {
2850 unsigned char *base_addr;
2851 int card,chip,channel;
2852 struct cyclades_port * info;
2853 unsigned long flags;
2854
2855 info = &cy_port[line_num];
2856 card = info->card;
2857 channel = (info->line) - (cy_card[card].first_line);
2858 chip = channel>>2;
2859 channel &= 0x03;
2860 printk(" card %d, chip %d, channel %d\n", card, chip, channel);
2861
2862 printk(" cy_card\n");
2863 printk(" irq base_addr num_chips first_line = %d %lx %d %d\n",
2864 cy_card[card].irq, (long)cy_card[card].base_addr,
2865 cy_card[card].num_chips, cy_card[card].first_line);
2866
2867 printk(" cy_port\n");
2868 printk(" card line flags = %d %d %x\n",
2869 info->card, info->line, info->flags);
2870 printk(" *tty read_status_mask timeout xmit_fifo_size = %lx %x %x %x\n",
2871 (long)info->tty, info->read_status_mask,
2872 info->timeout, info->xmit_fifo_size);
2873 printk(" cor1,cor2,cor3,cor4,cor5 = %x %x %x %x %x\n",
2874 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5);
2875 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
2876 info->tbpr, info->tco, info->rbpr, info->rco);
2877 printk(" close_delay event count = %d %d %d\n",
2878 info->close_delay, info->event, info->count);
2879 printk(" x_char blocked_open = %x %x\n",
2880 info->x_char, info->blocked_open);
2881 printk(" session pgrp open_wait = %lx %lx %lx\n",
2882 info->session, info->pgrp, (long)info->open_wait);
2883
2884
2885 save_flags(flags); cli();
2886
2887 base_addr = (unsigned char*)
2888 (cy_card[card].base_addr + cy_chip_offset[chip]);
2889
2890
2891
2892 printk(" CyGFRCR %x\n", base_addr[CyGFRCR]);
2893 printk(" CyCAR %x\n", base_addr[CyCAR]);
2894 printk(" CyGCR %x\n", base_addr[CyGCR]);
2895 printk(" CySVRR %x\n", base_addr[CySVRR]);
2896 printk(" CyRICR %x\n", base_addr[CyRICR]);
2897 printk(" CyTICR %x\n", base_addr[CyTICR]);
2898 printk(" CyMICR %x\n", base_addr[CyMICR]);
2899 printk(" CyRIR %x\n", base_addr[CyRIR]);
2900 printk(" CyTIR %x\n", base_addr[CyTIR]);
2901 printk(" CyMIR %x\n", base_addr[CyMIR]);
2902 printk(" CyPPR %x\n", base_addr[CyPPR]);
2903
2904 base_addr[CyCAR] = (u_char)channel;
2905
2906
2907
2908 printk(" CyRIVR %x\n", base_addr[CyRIVR]);
2909 printk(" CyTIVR %x\n", base_addr[CyTIVR]);
2910 printk(" CyMIVR %x\n", base_addr[CyMIVR]);
2911 printk(" CyMISR %x\n", base_addr[CyMISR]);
2912
2913
2914
2915 printk(" CyCCR %x\n", base_addr[CyCCR]);
2916 printk(" CySRER %x\n", base_addr[CySRER]);
2917 printk(" CyCOR1 %x\n", base_addr[CyCOR1]);
2918 printk(" CyCOR2 %x\n", base_addr[CyCOR2]);
2919 printk(" CyCOR3 %x\n", base_addr[CyCOR3]);
2920 printk(" CyCOR4 %x\n", base_addr[CyCOR4]);
2921 printk(" CyCOR5 %x\n", base_addr[CyCOR5]);
2922 printk(" CyCCSR %x\n", base_addr[CyCCSR]);
2923 printk(" CyRDCR %x\n", base_addr[CyRDCR]);
2924 printk(" CySCHR1 %x\n", base_addr[CySCHR1]);
2925 printk(" CySCHR2 %x\n", base_addr[CySCHR2]);
2926 printk(" CySCHR3 %x\n", base_addr[CySCHR3]);
2927 printk(" CySCHR4 %x\n", base_addr[CySCHR4]);
2928 printk(" CySCRL %x\n", base_addr[CySCRL]);
2929 printk(" CySCRH %x\n", base_addr[CySCRH]);
2930 printk(" CyLNC %x\n", base_addr[CyLNC]);
2931 printk(" CyMCOR1 %x\n", base_addr[CyMCOR1]);
2932 printk(" CyMCOR2 %x\n", base_addr[CyMCOR2]);
2933 printk(" CyRTPR %x\n", base_addr[CyRTPR]);
2934 printk(" CyMSVR1 %x\n", base_addr[CyMSVR1]);
2935 printk(" CyMSVR2 %x\n", base_addr[CyMSVR2]);
2936 printk(" CyRBPR %x\n", base_addr[CyRBPR]);
2937 printk(" CyRCOR %x\n", base_addr[CyRCOR]);
2938 printk(" CyTBPR %x\n", base_addr[CyTBPR]);
2939 printk(" CyTCOR %x\n", base_addr[CyTCOR]);
2940
2941 restore_flags(flags);
2942 }
2943 #endif
2944