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