1
2
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#include <linux/module.h>
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/serial.h>
34#include <linux/delay.h>
35#include <linux/ctype.h>
36#include <linux/tty.h>
37#include <linux/tty_flip.h>
38#include <linux/slab.h>
39#include <linux/ioport.h>
40#include <linux/interrupt.h>
41#include <linux/uaccess.h>
42#include <linux/io.h>
43#include <linux/spinlock.h>
44#include <linux/pci.h>
45#include "digiPCI.h"
46
47
48#include "digi1.h"
49#include "digiFep1.h"
50#include "epca.h"
51#include "epcaconfig.h"
52
53#define VERSION "1.3.0.1-LK2.6"
54
55
56#define DIGIINFOMAJOR 35
57
58
59#define MAXCARDS 7
60#define epcaassert(x, msg) if (!(x)) epca_error(__LINE__, msg)
61
62#define PFX "epca: "
63
64static int nbdevs, num_cards, liloconfig;
65static int digi_poller_inhibited = 1 ;
66
67static int setup_error_code;
68static int invalid_lilo_config;
69
70
71
72
73
74static DEFINE_SPINLOCK(epca_lock);
75
76
77
78static struct board_info boards[MAXBOARDS];
79
80static struct tty_driver *pc_driver;
81static struct tty_driver *pc_info;
82
83
84
85
86
87
88
89
90
91
92static struct channel digi_channels[MAX_ALLOC];
93
94
95
96
97
98
99static struct channel *card_ptr[MAXCARDS];
100
101static struct timer_list epca_timer;
102
103
104
105
106
107static void memwinon(struct board_info *b, unsigned int win);
108static void memwinoff(struct board_info *b, unsigned int win);
109static void globalwinon(struct channel *ch);
110static void rxwinon(struct channel *ch);
111static void txwinon(struct channel *ch);
112static void memoff(struct channel *ch);
113static void assertgwinon(struct channel *ch);
114static void assertmemoff(struct channel *ch);
115
116
117
118static void pcxem_memwinon(struct board_info *b, unsigned int win);
119static void pcxem_memwinoff(struct board_info *b, unsigned int win);
120static void pcxem_globalwinon(struct channel *ch);
121static void pcxem_rxwinon(struct channel *ch);
122static void pcxem_txwinon(struct channel *ch);
123static void pcxem_memoff(struct channel *ch);
124
125
126
127static void pcxe_memwinon(struct board_info *b, unsigned int win);
128static void pcxe_memwinoff(struct board_info *b, unsigned int win);
129static void pcxe_globalwinon(struct channel *ch);
130static void pcxe_rxwinon(struct channel *ch);
131static void pcxe_txwinon(struct channel *ch);
132static void pcxe_memoff(struct channel *ch);
133
134
135
136
137static void pcxi_memwinon(struct board_info *b, unsigned int win);
138static void pcxi_memwinoff(struct board_info *b, unsigned int win);
139static void pcxi_globalwinon(struct channel *ch);
140static void pcxi_rxwinon(struct channel *ch);
141static void pcxi_txwinon(struct channel *ch);
142static void pcxi_memoff(struct channel *ch);
143
144
145
146static void dummy_memwinon(struct board_info *b, unsigned int win);
147static void dummy_memwinoff(struct board_info *b, unsigned int win);
148static void dummy_globalwinon(struct channel *ch);
149static void dummy_rxwinon(struct channel *ch);
150static void dummy_txwinon(struct channel *ch);
151static void dummy_memoff(struct channel *ch);
152static void dummy_assertgwinon(struct channel *ch);
153static void dummy_assertmemoff(struct channel *ch);
154
155static struct channel *verifyChannel(struct tty_struct *);
156static void pc_sched_event(struct channel *, int);
157static void epca_error(int, char *);
158static void pc_close(struct tty_struct *, struct file *);
159static void shutdown(struct channel *);
160static void pc_hangup(struct tty_struct *);
161static int pc_write_room(struct tty_struct *);
162static int pc_chars_in_buffer(struct tty_struct *);
163static void pc_flush_buffer(struct tty_struct *);
164static void pc_flush_chars(struct tty_struct *);
165static int block_til_ready(struct tty_struct *, struct file *,
166 struct channel *);
167static int pc_open(struct tty_struct *, struct file *);
168static void post_fep_init(unsigned int crd);
169static void epcapoll(unsigned long);
170static void doevent(int);
171static void fepcmd(struct channel *, int, int, int, int, int);
172static unsigned termios2digi_h(struct channel *ch, unsigned);
173static unsigned termios2digi_i(struct channel *ch, unsigned);
174static unsigned termios2digi_c(struct channel *ch, unsigned);
175static void epcaparam(struct tty_struct *, struct channel *);
176static void receive_data(struct channel *);
177static int pc_ioctl(struct tty_struct *, struct file *,
178 unsigned int, unsigned long);
179static int info_ioctl(struct tty_struct *, struct file *,
180 unsigned int, unsigned long);
181static void pc_set_termios(struct tty_struct *, struct ktermios *);
182static void do_softint(struct work_struct *work);
183static void pc_stop(struct tty_struct *);
184static void pc_start(struct tty_struct *);
185static void pc_throttle(struct tty_struct *tty);
186static void pc_unthrottle(struct tty_struct *tty);
187static int pc_send_break(struct tty_struct *tty, int msec);
188static void setup_empty_event(struct tty_struct *tty, struct channel *ch);
189
190static int pc_write(struct tty_struct *, const unsigned char *, int);
191static int pc_init(void);
192static int init_PCI(void);
193
194
195
196
197
198
199
200
201
202
203static void memwinon(struct board_info *b, unsigned int win)
204{
205 b->memwinon(b, win);
206}
207
208static void memwinoff(struct board_info *b, unsigned int win)
209{
210 b->memwinoff(b, win);
211}
212
213static void globalwinon(struct channel *ch)
214{
215 ch->board->globalwinon(ch);
216}
217
218static void rxwinon(struct channel *ch)
219{
220 ch->board->rxwinon(ch);
221}
222
223static void txwinon(struct channel *ch)
224{
225 ch->board->txwinon(ch);
226}
227
228static void memoff(struct channel *ch)
229{
230 ch->board->memoff(ch);
231}
232static void assertgwinon(struct channel *ch)
233{
234 ch->board->assertgwinon(ch);
235}
236
237static void assertmemoff(struct channel *ch)
238{
239 ch->board->assertmemoff(ch);
240}
241
242
243static void pcxem_memwinon(struct board_info *b, unsigned int win)
244{
245 outb_p(FEPWIN | win, b->port + 1);
246}
247
248static void pcxem_memwinoff(struct board_info *b, unsigned int win)
249{
250 outb_p(0, b->port + 1);
251}
252
253static void pcxem_globalwinon(struct channel *ch)
254{
255 outb_p(FEPWIN, (int)ch->board->port + 1);
256}
257
258static void pcxem_rxwinon(struct channel *ch)
259{
260 outb_p(ch->rxwin, (int)ch->board->port + 1);
261}
262
263static void pcxem_txwinon(struct channel *ch)
264{
265 outb_p(ch->txwin, (int)ch->board->port + 1);
266}
267
268static void pcxem_memoff(struct channel *ch)
269{
270 outb_p(0, (int)ch->board->port + 1);
271}
272
273
274static void pcxe_memwinon(struct board_info *b, unsigned int win)
275{
276 outb_p(FEPWIN | win, b->port + 1);
277}
278
279static void pcxe_memwinoff(struct board_info *b, unsigned int win)
280{
281 outb_p(inb(b->port) & ~FEPMEM, b->port + 1);
282 outb_p(0, b->port + 1);
283}
284
285static void pcxe_globalwinon(struct channel *ch)
286{
287 outb_p(FEPWIN, (int)ch->board->port + 1);
288}
289
290static void pcxe_rxwinon(struct channel *ch)
291{
292 outb_p(ch->rxwin, (int)ch->board->port + 1);
293}
294
295static void pcxe_txwinon(struct channel *ch)
296{
297 outb_p(ch->txwin, (int)ch->board->port + 1);
298}
299
300static void pcxe_memoff(struct channel *ch)
301{
302 outb_p(0, (int)ch->board->port);
303 outb_p(0, (int)ch->board->port + 1);
304}
305
306
307static void pcxi_memwinon(struct board_info *b, unsigned int win)
308{
309 outb_p(inb(b->port) | FEPMEM, b->port);
310}
311
312static void pcxi_memwinoff(struct board_info *b, unsigned int win)
313{
314 outb_p(inb(b->port) & ~FEPMEM, b->port);
315}
316
317static void pcxi_globalwinon(struct channel *ch)
318{
319 outb_p(FEPMEM, ch->board->port);
320}
321
322static void pcxi_rxwinon(struct channel *ch)
323{
324 outb_p(FEPMEM, ch->board->port);
325}
326
327static void pcxi_txwinon(struct channel *ch)
328{
329 outb_p(FEPMEM, ch->board->port);
330}
331
332static void pcxi_memoff(struct channel *ch)
333{
334 outb_p(0, ch->board->port);
335}
336
337static void pcxi_assertgwinon(struct channel *ch)
338{
339 epcaassert(inb(ch->board->port) & FEPMEM, "Global memory off");
340}
341
342static void pcxi_assertmemoff(struct channel *ch)
343{
344 epcaassert(!(inb(ch->board->port) & FEPMEM), "Memory on");
345}
346
347
348
349
350
351
352
353
354static void dummy_memwinon(struct board_info *b, unsigned int win)
355{
356}
357
358static void dummy_memwinoff(struct board_info *b, unsigned int win)
359{
360}
361
362static void dummy_globalwinon(struct channel *ch)
363{
364}
365
366static void dummy_rxwinon(struct channel *ch)
367{
368}
369
370static void dummy_txwinon(struct channel *ch)
371{
372}
373
374static void dummy_memoff(struct channel *ch)
375{
376}
377
378static void dummy_assertgwinon(struct channel *ch)
379{
380}
381
382static void dummy_assertmemoff(struct channel *ch)
383{
384}
385
386static struct channel *verifyChannel(struct tty_struct *tty)
387{
388
389
390
391
392
393
394 if (tty) {
395 struct channel *ch = (struct channel *)tty->driver_data;
396 if (ch >= &digi_channels[0] && ch < &digi_channels[nbdevs]) {
397 if (ch->magic == EPCA_MAGIC)
398 return ch;
399 }
400 }
401 return NULL;
402}
403
404static void pc_sched_event(struct channel *ch, int event)
405{
406
407
408
409
410 ch->event |= 1 << event;
411 schedule_work(&ch->tqueue);
412}
413
414static void epca_error(int line, char *msg)
415{
416 printk(KERN_ERR "epca_error (Digi): line = %d %s\n", line, msg);
417}
418
419static void pc_close(struct tty_struct *tty, struct file *filp)
420{
421 struct channel *ch;
422 unsigned long flags;
423
424
425
426
427 ch = verifyChannel(tty);
428 if (ch != NULL) {
429 spin_lock_irqsave(&epca_lock, flags);
430 if (tty_hung_up_p(filp)) {
431 spin_unlock_irqrestore(&epca_lock, flags);
432 return;
433 }
434 if (ch->port.count-- > 1) {
435
436
437
438
439
440 spin_unlock_irqrestore(&epca_lock, flags);
441 return;
442 }
443
444 BUG_ON(ch->port.count < 0);
445
446
447
448
449
450
451 ch->port.flags |= ASYNC_CLOSING;
452 tty->closing = 1;
453
454 spin_unlock_irqrestore(&epca_lock, flags);
455
456 if (ch->port.flags & ASYNC_INITIALIZED) {
457
458
459 setup_empty_event(tty, ch);
460
461 tty_wait_until_sent(tty, 3000);
462 }
463 pc_flush_buffer(tty);
464
465 tty_ldisc_flush(tty);
466 shutdown(ch);
467
468 spin_lock_irqsave(&epca_lock, flags);
469 tty->closing = 0;
470 ch->event = 0;
471 ch->port.tty = NULL;
472 spin_unlock_irqrestore(&epca_lock, flags);
473
474 if (ch->port.blocked_open) {
475 if (ch->close_delay)
476 msleep_interruptible(jiffies_to_msecs(ch->close_delay));
477 wake_up_interruptible(&ch->port.open_wait);
478 }
479 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED |
480 ASYNC_CLOSING);
481 wake_up_interruptible(&ch->port.close_wait);
482 }
483}
484
485static void shutdown(struct channel *ch)
486{
487 unsigned long flags;
488 struct tty_struct *tty;
489 struct board_chan __iomem *bc;
490
491 if (!(ch->port.flags & ASYNC_INITIALIZED))
492 return;
493
494 spin_lock_irqsave(&epca_lock, flags);
495
496 globalwinon(ch);
497 bc = ch->brdchan;
498
499
500
501
502
503
504 if (bc)
505 writeb(0, &bc->idata);
506 tty = ch->port.tty;
507
508
509 if (tty->termios->c_cflag & HUPCL) {
510 ch->omodem &= ~(ch->m_rts | ch->m_dtr);
511 fepcmd(ch, SETMODEM, 0, ch->m_dtr | ch->m_rts, 10, 1);
512 }
513 memoff(ch);
514
515
516
517
518
519
520 ch->port.flags &= ~ASYNC_INITIALIZED;
521 spin_unlock_irqrestore(&epca_lock, flags);
522}
523
524static void pc_hangup(struct tty_struct *tty)
525{
526 struct channel *ch;
527
528
529
530
531 ch = verifyChannel(tty);
532 if (ch != NULL) {
533 unsigned long flags;
534
535 pc_flush_buffer(tty);
536 tty_ldisc_flush(tty);
537 shutdown(ch);
538
539 spin_lock_irqsave(&epca_lock, flags);
540 ch->port.tty = NULL;
541 ch->event = 0;
542 ch->port.count = 0;
543 ch->port.flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_INITIALIZED);
544 spin_unlock_irqrestore(&epca_lock, flags);
545 wake_up_interruptible(&ch->port.open_wait);
546 }
547}
548
549static int pc_write(struct tty_struct *tty,
550 const unsigned char *buf, int bytesAvailable)
551{
552 unsigned int head, tail;
553 int dataLen;
554 int size;
555 int amountCopied;
556 struct channel *ch;
557 unsigned long flags;
558 int remain;
559 struct board_chan __iomem *bc;
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574 ch = verifyChannel(tty);
575 if (ch == NULL)
576 return 0;
577
578
579 bc = ch->brdchan;
580 size = ch->txbufsize;
581 amountCopied = 0;
582
583 spin_lock_irqsave(&epca_lock, flags);
584 globalwinon(ch);
585
586 head = readw(&bc->tin) & (size - 1);
587 tail = readw(&bc->tout);
588
589 if (tail != readw(&bc->tout))
590 tail = readw(&bc->tout);
591 tail &= (size - 1);
592
593 if (head >= tail) {
594
595
596
597
598
599
600
601
602
603 dataLen = size - head;
604 remain = size - (head - tail) - 1;
605 } else {
606
607 remain = tail - head - 1;
608 dataLen = remain;
609 }
610
611
612
613
614 bytesAvailable = min(remain, bytesAvailable);
615 txwinon(ch);
616 while (bytesAvailable > 0) {
617
618
619
620
621
622
623 dataLen = min(bytesAvailable, dataLen);
624 memcpy_toio(ch->txptr + head, buf, dataLen);
625 buf += dataLen;
626 head += dataLen;
627 amountCopied += dataLen;
628 bytesAvailable -= dataLen;
629
630 if (head >= size) {
631 head = 0;
632 dataLen = tail;
633 }
634 }
635 ch->statusflags |= TXBUSY;
636 globalwinon(ch);
637 writew(head, &bc->tin);
638
639 if ((ch->statusflags & LOWWAIT) == 0) {
640 ch->statusflags |= LOWWAIT;
641 writeb(1, &bc->ilow);
642 }
643 memoff(ch);
644 spin_unlock_irqrestore(&epca_lock, flags);
645 return amountCopied;
646}
647
648static int pc_write_room(struct tty_struct *tty)
649{
650 int remain = 0;
651 struct channel *ch;
652 unsigned long flags;
653 unsigned int head, tail;
654 struct board_chan __iomem *bc;
655
656
657
658
659 ch = verifyChannel(tty);
660 if (ch != NULL) {
661 spin_lock_irqsave(&epca_lock, flags);
662 globalwinon(ch);
663
664 bc = ch->brdchan;
665 head = readw(&bc->tin) & (ch->txbufsize - 1);
666 tail = readw(&bc->tout);
667
668 if (tail != readw(&bc->tout))
669 tail = readw(&bc->tout);
670
671 tail &= (ch->txbufsize - 1);
672 remain = tail - head - 1;
673 if (remain < 0)
674 remain += ch->txbufsize;
675
676 if (remain && (ch->statusflags & LOWWAIT) == 0) {
677 ch->statusflags |= LOWWAIT;
678 writeb(1, &bc->ilow);
679 }
680 memoff(ch);
681 spin_unlock_irqrestore(&epca_lock, flags);
682 }
683
684 return remain;
685}
686
687static int pc_chars_in_buffer(struct tty_struct *tty)
688{
689 int chars;
690 unsigned int ctail, head, tail;
691 int remain;
692 unsigned long flags;
693 struct channel *ch;
694 struct board_chan __iomem *bc;
695
696
697
698
699 ch = verifyChannel(tty);
700 if (ch == NULL)
701 return 0;
702
703 spin_lock_irqsave(&epca_lock, flags);
704 globalwinon(ch);
705
706 bc = ch->brdchan;
707 tail = readw(&bc->tout);
708 head = readw(&bc->tin);
709 ctail = readw(&ch->mailbox->cout);
710
711 if (tail == head && readw(&ch->mailbox->cin) == ctail &&
712 readb(&bc->tbusy) == 0)
713 chars = 0;
714 else {
715 head = readw(&bc->tin) & (ch->txbufsize - 1);
716 tail &= (ch->txbufsize - 1);
717
718
719
720
721
722 remain = tail - head - 1;
723 if (remain < 0)
724 remain += ch->txbufsize;
725 chars = (int)(ch->txbufsize - remain);
726
727
728
729
730
731
732
733 if (!(ch->statusflags & EMPTYWAIT))
734 setup_empty_event(tty, ch);
735 }
736 memoff(ch);
737 spin_unlock_irqrestore(&epca_lock, flags);
738
739 return chars;
740}
741
742static void pc_flush_buffer(struct tty_struct *tty)
743{
744 unsigned int tail;
745 unsigned long flags;
746 struct channel *ch;
747 struct board_chan __iomem *bc;
748
749
750
751
752 ch = verifyChannel(tty);
753 if (ch == NULL)
754 return;
755
756 spin_lock_irqsave(&epca_lock, flags);
757 globalwinon(ch);
758 bc = ch->brdchan;
759 tail = readw(&bc->tout);
760
761 fepcmd(ch, STOUT, (unsigned) tail, 0, 0, 0);
762 memoff(ch);
763 spin_unlock_irqrestore(&epca_lock, flags);
764 tty_wakeup(tty);
765}
766
767static void pc_flush_chars(struct tty_struct *tty)
768{
769 struct channel *ch;
770
771
772
773
774 ch = verifyChannel(tty);
775 if (ch != NULL) {
776 unsigned long flags;
777 spin_lock_irqsave(&epca_lock, flags);
778
779
780
781
782 if ((ch->statusflags & TXBUSY) &&
783 !(ch->statusflags & EMPTYWAIT))
784 setup_empty_event(tty, ch);
785 spin_unlock_irqrestore(&epca_lock, flags);
786 }
787}
788
789static int block_til_ready(struct tty_struct *tty,
790 struct file *filp, struct channel *ch)
791{
792 DECLARE_WAITQUEUE(wait, current);
793 int retval, do_clocal = 0;
794 unsigned long flags;
795
796 if (tty_hung_up_p(filp)) {
797 if (ch->port.flags & ASYNC_HUP_NOTIFY)
798 retval = -EAGAIN;
799 else
800 retval = -ERESTARTSYS;
801 return retval;
802 }
803
804
805
806
807
808 if (ch->port.flags & ASYNC_CLOSING) {
809 interruptible_sleep_on(&ch->port.close_wait);
810
811 if (ch->port.flags & ASYNC_HUP_NOTIFY)
812 return -EAGAIN;
813 else
814 return -ERESTARTSYS;
815 }
816
817 if (filp->f_flags & O_NONBLOCK) {
818
819
820
821
822 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
823 return 0;
824 }
825 if (tty->termios->c_cflag & CLOCAL)
826 do_clocal = 1;
827
828
829 retval = 0;
830 add_wait_queue(&ch->port.open_wait, &wait);
831
832 spin_lock_irqsave(&epca_lock, flags);
833
834 if (!tty_hung_up_p(filp))
835 ch->port.count--;
836 ch->port.blocked_open++;
837 while (1) {
838 set_current_state(TASK_INTERRUPTIBLE);
839 if (tty_hung_up_p(filp) ||
840 !(ch->port.flags & ASYNC_INITIALIZED)) {
841 if (ch->port.flags & ASYNC_HUP_NOTIFY)
842 retval = -EAGAIN;
843 else
844 retval = -ERESTARTSYS;
845 break;
846 }
847 if (!(ch->port.flags & ASYNC_CLOSING) &&
848 (do_clocal || (ch->imodem & ch->dcd)))
849 break;
850 if (signal_pending(current)) {
851 retval = -ERESTARTSYS;
852 break;
853 }
854 spin_unlock_irqrestore(&epca_lock, flags);
855
856
857
858
859
860
861 schedule();
862 spin_lock_irqsave(&epca_lock, flags);
863 }
864
865 __set_current_state(TASK_RUNNING);
866 remove_wait_queue(&ch->port.open_wait, &wait);
867 if (!tty_hung_up_p(filp))
868 ch->port.count++;
869 ch->port.blocked_open--;
870
871 spin_unlock_irqrestore(&epca_lock, flags);
872
873 if (retval)
874 return retval;
875
876 ch->port.flags |= ASYNC_NORMAL_ACTIVE;
877 return 0;
878}
879
880static int pc_open(struct tty_struct *tty, struct file *filp)
881{
882 struct channel *ch;
883 unsigned long flags;
884 int line, retval, boardnum;
885 struct board_chan __iomem *bc;
886 unsigned int head;
887
888 line = tty->index;
889 if (line < 0 || line >= nbdevs)
890 return -ENODEV;
891
892 ch = &digi_channels[line];
893 boardnum = ch->boardnum;
894
895
896
897
898
899
900
901
902 if (invalid_lilo_config) {
903 if (setup_error_code & INVALID_BOARD_TYPE)
904 printk(KERN_ERR "epca: pc_open: Invalid board type specified in kernel options.\n");
905 if (setup_error_code & INVALID_NUM_PORTS)
906 printk(KERN_ERR "epca: pc_open: Invalid number of ports specified in kernel options.\n");
907 if (setup_error_code & INVALID_MEM_BASE)
908 printk(KERN_ERR "epca: pc_open: Invalid board memory address specified in kernel options.\n");
909 if (setup_error_code & INVALID_PORT_BASE)
910 printk(KERN_ERR "epca; pc_open: Invalid board port address specified in kernel options.\n");
911 if (setup_error_code & INVALID_BOARD_STATUS)
912 printk(KERN_ERR "epca: pc_open: Invalid board status specified in kernel options.\n");
913 if (setup_error_code & INVALID_ALTPIN)
914 printk(KERN_ERR "epca: pc_open: Invalid board altpin specified in kernel options;\n");
915 tty->driver_data = NULL;
916 return -ENODEV;
917 }
918 if (boardnum >= num_cards || boards[boardnum].status == DISABLED) {
919 tty->driver_data = NULL;
920 return(-ENODEV);
921 }
922
923 bc = ch->brdchan;
924 if (bc == NULL) {
925 tty->driver_data = NULL;
926 return -ENODEV;
927 }
928
929 spin_lock_irqsave(&epca_lock, flags);
930
931
932
933
934
935 ch->port.count++;
936
937
938
939
940 tty->driver_data = ch;
941
942
943
944
945 globalwinon(ch);
946 ch->statusflags = 0;
947
948
949 ch->imodem = readb(&bc->mstat);
950
951
952
953
954
955 head = readw(&bc->rin);
956 writew(head, &bc->rout);
957
958
959 ch->port.tty = tty;
960
961
962
963
964
965 epcaparam(tty, ch);
966 ch->port.flags |= ASYNC_INITIALIZED;
967 memoff(ch);
968 spin_unlock_irqrestore(&epca_lock, flags);
969
970 retval = block_til_ready(tty, filp, ch);
971 if (retval)
972 return retval;
973
974
975
976
977 spin_lock_irqsave(&epca_lock, flags);
978 ch->port.tty = tty;
979 globalwinon(ch);
980
981 writeb(1, &bc->idata);
982 memoff(ch);
983 spin_unlock_irqrestore(&epca_lock, flags);
984 return 0;
985}
986
987static int __init epca_module_init(void)
988{
989 return pc_init();
990}
991module_init(epca_module_init);
992
993static struct pci_driver epca_driver;
994
995static void __exit epca_module_exit(void)
996{
997 int count, crd;
998 struct board_info *bd;
999 struct channel *ch;
1000
1001 del_timer_sync(&epca_timer);
1002
1003 if (tty_unregister_driver(pc_driver) ||
1004 tty_unregister_driver(pc_info)) {
1005 printk(KERN_WARNING "epca: cleanup_module failed to un-register tty driver\n");
1006 return;
1007 }
1008 put_tty_driver(pc_driver);
1009 put_tty_driver(pc_info);
1010
1011 for (crd = 0; crd < num_cards; crd++) {
1012 bd = &boards[crd];
1013 if (!bd) {
1014 printk(KERN_ERR "<Error> - Digi : cleanup_module failed\n");
1015 return;
1016 }
1017 ch = card_ptr[crd];
1018 for (count = 0; count < bd->numports; count++, ch++) {
1019 if (ch && ch->port.tty)
1020 tty_hangup(ch->port.tty);
1021 }
1022 }
1023 pci_unregister_driver(&epca_driver);
1024}
1025module_exit(epca_module_exit);
1026
1027static const struct tty_operations pc_ops = {
1028 .open = pc_open,
1029 .close = pc_close,
1030 .write = pc_write,
1031 .write_room = pc_write_room,
1032 .flush_buffer = pc_flush_buffer,
1033 .chars_in_buffer = pc_chars_in_buffer,
1034 .flush_chars = pc_flush_chars,
1035 .ioctl = pc_ioctl,
1036 .set_termios = pc_set_termios,
1037 .stop = pc_stop,
1038 .start = pc_start,
1039 .throttle = pc_throttle,
1040 .unthrottle = pc_unthrottle,
1041 .hangup = pc_hangup,
1042 .break_ctl = pc_send_break
1043};
1044
1045static int info_open(struct tty_struct *tty, struct file *filp)
1046{
1047 return 0;
1048}
1049
1050static struct tty_operations info_ops = {
1051 .open = info_open,
1052 .ioctl = info_ioctl,
1053};
1054
1055static int __init pc_init(void)
1056{
1057 int crd;
1058 struct board_info *bd;
1059 unsigned char board_id = 0;
1060 int err = -ENOMEM;
1061
1062 int pci_boards_found, pci_count;
1063
1064 pci_count = 0;
1065
1066 pc_driver = alloc_tty_driver(MAX_ALLOC);
1067 if (!pc_driver)
1068 goto out1;
1069
1070 pc_info = alloc_tty_driver(MAX_ALLOC);
1071 if (!pc_info)
1072 goto out2;
1073
1074
1075
1076
1077
1078
1079
1080
1081 if (!liloconfig) {
1082
1083 nbdevs = NBDEVS;
1084 num_cards = NUMCARDS;
1085 memcpy(&boards, &static_boards,
1086 sizeof(struct board_info) * NUMCARDS);
1087 }
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100 printk(KERN_INFO "DIGI epca driver version %s loaded.\n", VERSION);
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117 pci_boards_found = 0;
1118 if (num_cards < MAXBOARDS)
1119 pci_boards_found += init_PCI();
1120 num_cards += pci_boards_found;
1121
1122 pc_driver->owner = THIS_MODULE;
1123 pc_driver->name = "ttyD";
1124 pc_driver->major = DIGI_MAJOR;
1125 pc_driver->minor_start = 0;
1126 pc_driver->type = TTY_DRIVER_TYPE_SERIAL;
1127 pc_driver->subtype = SERIAL_TYPE_NORMAL;
1128 pc_driver->init_termios = tty_std_termios;
1129 pc_driver->init_termios.c_iflag = 0;
1130 pc_driver->init_termios.c_oflag = 0;
1131 pc_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | CLOCAL | HUPCL;
1132 pc_driver->init_termios.c_lflag = 0;
1133 pc_driver->init_termios.c_ispeed = 9600;
1134 pc_driver->init_termios.c_ospeed = 9600;
1135 pc_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_HARDWARE_BREAK;
1136 tty_set_operations(pc_driver, &pc_ops);
1137
1138 pc_info->owner = THIS_MODULE;
1139 pc_info->name = "digi_ctl";
1140 pc_info->major = DIGIINFOMAJOR;
1141 pc_info->minor_start = 0;
1142 pc_info->type = TTY_DRIVER_TYPE_SERIAL;
1143 pc_info->subtype = SERIAL_TYPE_INFO;
1144 pc_info->init_termios = tty_std_termios;
1145 pc_info->init_termios.c_iflag = 0;
1146 pc_info->init_termios.c_oflag = 0;
1147 pc_info->init_termios.c_lflag = 0;
1148 pc_info->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL;
1149 pc_info->init_termios.c_ispeed = 9600;
1150 pc_info->init_termios.c_ospeed = 9600;
1151 pc_info->flags = TTY_DRIVER_REAL_RAW;
1152 tty_set_operations(pc_info, &info_ops);
1153
1154
1155 for (crd = 0; crd < num_cards; crd++) {
1156
1157
1158
1159
1160
1161
1162
1163 bd = &boards[crd];
1164
1165 switch (bd->type) {
1166 case PCXEM:
1167 case EISAXEM:
1168 bd->memwinon = pcxem_memwinon;
1169 bd->memwinoff = pcxem_memwinoff;
1170 bd->globalwinon = pcxem_globalwinon;
1171 bd->txwinon = pcxem_txwinon;
1172 bd->rxwinon = pcxem_rxwinon;
1173 bd->memoff = pcxem_memoff;
1174 bd->assertgwinon = dummy_assertgwinon;
1175 bd->assertmemoff = dummy_assertmemoff;
1176 break;
1177
1178 case PCIXEM:
1179 case PCIXRJ:
1180 case PCIXR:
1181 bd->memwinon = dummy_memwinon;
1182 bd->memwinoff = dummy_memwinoff;
1183 bd->globalwinon = dummy_globalwinon;
1184 bd->txwinon = dummy_txwinon;
1185 bd->rxwinon = dummy_rxwinon;
1186 bd->memoff = dummy_memoff;
1187 bd->assertgwinon = dummy_assertgwinon;
1188 bd->assertmemoff = dummy_assertmemoff;
1189 break;
1190
1191 case PCXE:
1192 case PCXEVE:
1193 bd->memwinon = pcxe_memwinon;
1194 bd->memwinoff = pcxe_memwinoff;
1195 bd->globalwinon = pcxe_globalwinon;
1196 bd->txwinon = pcxe_txwinon;
1197 bd->rxwinon = pcxe_rxwinon;
1198 bd->memoff = pcxe_memoff;
1199 bd->assertgwinon = dummy_assertgwinon;
1200 bd->assertmemoff = dummy_assertmemoff;
1201 break;
1202
1203 case PCXI:
1204 case PC64XE:
1205 bd->memwinon = pcxi_memwinon;
1206 bd->memwinoff = pcxi_memwinoff;
1207 bd->globalwinon = pcxi_globalwinon;
1208 bd->txwinon = pcxi_txwinon;
1209 bd->rxwinon = pcxi_rxwinon;
1210 bd->memoff = pcxi_memoff;
1211 bd->assertgwinon = pcxi_assertgwinon;
1212 bd->assertmemoff = pcxi_assertmemoff;
1213 break;
1214
1215 default:
1216 break;
1217 }
1218
1219
1220
1221
1222
1223
1224
1225
1226 switch (bd->type) {
1227 case PCXE:
1228 case PCXEVE:
1229 case PC64XE:
1230 bd->memory_seg = 0xf000;
1231 break;
1232
1233 case PCXI:
1234 board_id = inb((int)bd->port);
1235 if ((board_id & 0x1) == 0x1) {
1236
1237
1238 if ((board_id & 0x30) == 0)
1239 bd->memory_seg = 0xf000;
1240
1241
1242 if ((board_id & 0x30) == 0x10)
1243 bd->memory_seg = 0xe000;
1244
1245
1246 if ((board_id & 0x30) == 0x20)
1247 bd->memory_seg = 0xc000;
1248
1249
1250 if ((board_id & 0x30) == 0x30)
1251 bd->memory_seg = 0x8000;
1252 } else
1253 printk(KERN_ERR "epca: Board at 0x%x doesn't appear to be an XI\n", (int)bd->port);
1254 break;
1255 }
1256 }
1257
1258 err = tty_register_driver(pc_driver);
1259 if (err) {
1260 printk(KERN_ERR "Couldn't register Digi PC/ driver");
1261 goto out3;
1262 }
1263
1264 err = tty_register_driver(pc_info);
1265 if (err) {
1266 printk(KERN_ERR "Couldn't register Digi PC/ info ");
1267 goto out4;
1268 }
1269
1270
1271 init_timer(&epca_timer);
1272 epca_timer.function = epcapoll;
1273 mod_timer(&epca_timer, jiffies + HZ/25);
1274 return 0;
1275
1276out4:
1277 tty_unregister_driver(pc_driver);
1278out3:
1279 put_tty_driver(pc_info);
1280out2:
1281 put_tty_driver(pc_driver);
1282out1:
1283 return err;
1284}
1285
1286static void post_fep_init(unsigned int crd)
1287{
1288 int i;
1289 void __iomem *memaddr;
1290 struct global_data __iomem *gd;
1291 struct board_info *bd;
1292 struct board_chan __iomem *bc;
1293 struct channel *ch;
1294 int shrinkmem = 0, lowwater;
1295
1296
1297
1298
1299
1300 bd = &boards[crd];
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310 if (bd->type >= PCIXEM) {
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326 bd->numports = readw(bd->re_map_membase + XEMPORTS);
1327 epcaassert(bd->numports <= 64, "PCI returned a invalid number of ports");
1328 nbdevs += (bd->numports);
1329 } else {
1330
1331
1332 bd->re_map_membase = ioremap_nocache(bd->membase, 0x10000);
1333 }
1334
1335 if (crd != 0)
1336 card_ptr[crd] = card_ptr[crd-1] + boards[crd-1].numports;
1337 else
1338 card_ptr[crd] = &digi_channels[crd];
1339
1340 ch = card_ptr[crd];
1341 epcaassert(ch <= &digi_channels[nbdevs - 1], "ch out of range");
1342
1343 memaddr = bd->re_map_membase;
1344
1345
1346
1347
1348
1349
1350 bc = memaddr + CHANSTRUCT;
1351
1352
1353
1354
1355
1356
1357 gd = memaddr + GLOBAL;
1358
1359
1360
1361
1362
1363 if ((bd->type == PCXEVE || bd->type == PCXE) &&
1364 (readw(memaddr + XEPORTS) < 3))
1365 shrinkmem = 1;
1366 if (bd->type < PCIXEM)
1367 if (!request_region((int)bd->port, 4, board_desc[bd->type]))
1368 return;
1369 memwinon(bd, 0);
1370
1371
1372
1373
1374
1375 for (i = 0; i < bd->numports; i++, ch++, bc++) {
1376 unsigned long flags;
1377 u16 tseg, rseg;
1378
1379 tty_port_init(&ch->port);
1380 ch->brdchan = bc;
1381 ch->mailbox = gd;
1382 INIT_WORK(&ch->tqueue, do_softint);
1383 ch->board = &boards[crd];
1384
1385 spin_lock_irqsave(&epca_lock, flags);
1386 switch (bd->type) {
1387
1388
1389
1390
1391
1392
1393 case EISAXEM:
1394 case PCXEM:
1395 case PCIXEM:
1396 case PCIXRJ:
1397 case PCIXR:
1398 ch->m_rts = 0x02;
1399 ch->m_dcd = 0x80;
1400 ch->m_dsr = 0x20;
1401 ch->m_cts = 0x10;
1402 ch->m_ri = 0x40;
1403 ch->m_dtr = 0x01;
1404 break;
1405
1406 case PCXE:
1407 case PCXEVE:
1408 case PCXI:
1409 case PC64XE:
1410 ch->m_rts = 0x02;
1411 ch->m_dcd = 0x08;
1412 ch->m_dsr = 0x10;
1413 ch->m_cts = 0x20;
1414 ch->m_ri = 0x40;
1415 ch->m_dtr = 0x80;
1416 break;
1417 }
1418
1419 if (boards[crd].altpin) {
1420 ch->dsr = ch->m_dcd;
1421 ch->dcd = ch->m_dsr;
1422 ch->digiext.digi_flags |= DIGI_ALTPIN;
1423 } else {
1424 ch->dcd = ch->m_dcd;
1425 ch->dsr = ch->m_dsr;
1426 }
1427
1428 ch->boardnum = crd;
1429 ch->channelnum = i;
1430 ch->magic = EPCA_MAGIC;
1431 ch->port.tty = NULL;
1432
1433 if (shrinkmem) {
1434 fepcmd(ch, SETBUFFER, 32, 0, 0, 0);
1435 shrinkmem = 0;
1436 }
1437
1438 tseg = readw(&bc->tseg);
1439 rseg = readw(&bc->rseg);
1440
1441 switch (bd->type) {
1442 case PCIXEM:
1443 case PCIXRJ:
1444 case PCIXR:
1445
1446 ch->txptr = memaddr + ((tseg << 4) & 0x1fffff);
1447 ch->rxptr = memaddr + ((rseg << 4) & 0x1fffff);
1448 ch->txwin = FEPWIN | (tseg >> 11);
1449 ch->rxwin = FEPWIN | (rseg >> 11);
1450 break;
1451
1452 case PCXEM:
1453 case EISAXEM:
1454
1455
1456 ch->txptr = memaddr + ((tseg << 4) & 0x7fff);
1457 ch->rxptr = memaddr + ((rseg << 4) & 0x7fff);
1458 ch->txwin = FEPWIN | (tseg >> 11);
1459 ch->rxwin = FEPWIN | (rseg >> 11);
1460 break;
1461
1462 case PCXEVE:
1463 case PCXE:
1464 ch->txptr = memaddr + (((tseg - bd->memory_seg) << 4)
1465 & 0x1fff);
1466 ch->txwin = FEPWIN | ((tseg - bd->memory_seg) >> 9);
1467 ch->rxptr = memaddr + (((rseg - bd->memory_seg) << 4)
1468 & 0x1fff);
1469 ch->rxwin = FEPWIN | ((rseg - bd->memory_seg) >> 9);
1470 break;
1471
1472 case PCXI:
1473 case PC64XE:
1474 ch->txptr = memaddr + ((tseg - bd->memory_seg) << 4);
1475 ch->rxptr = memaddr + ((rseg - bd->memory_seg) << 4);
1476 ch->txwin = ch->rxwin = 0;
1477 break;
1478 }
1479
1480 ch->txbufhead = 0;
1481 ch->txbufsize = readw(&bc->tmax) + 1;
1482
1483 ch->rxbufhead = 0;
1484 ch->rxbufsize = readw(&bc->rmax) + 1;
1485
1486 lowwater = ch->txbufsize >= 2000 ? 1024 : (ch->txbufsize / 2);
1487
1488
1489 fepcmd(ch, STXLWATER, lowwater, 0, 10, 0);
1490
1491
1492 fepcmd(ch, SRXLWATER, (ch->rxbufsize / 4), 0, 10, 0);
1493
1494
1495 fepcmd(ch, SRXHWATER, (3 * ch->rxbufsize / 4), 0, 10, 0);
1496
1497 writew(100, &bc->edelay);
1498 writeb(1, &bc->idata);
1499
1500 ch->startc = readb(&bc->startc);
1501 ch->stopc = readb(&bc->stopc);
1502 ch->startca = readb(&bc->startca);
1503 ch->stopca = readb(&bc->stopca);
1504
1505 ch->fepcflag = 0;
1506 ch->fepiflag = 0;
1507 ch->fepoflag = 0;
1508 ch->fepstartc = 0;
1509 ch->fepstopc = 0;
1510 ch->fepstartca = 0;
1511 ch->fepstopca = 0;
1512
1513 ch->close_delay = 50;
1514
1515 spin_unlock_irqrestore(&epca_lock, flags);
1516 }
1517
1518 printk(KERN_INFO
1519 "Digi PC/Xx Driver V%s: %s I/O = 0x%lx Mem = 0x%lx Ports = %d\n",
1520 VERSION, board_desc[bd->type], (long)bd->port,
1521 (long)bd->membase, bd->numports);
1522 memwinoff(bd, 0);
1523}
1524
1525static void epcapoll(unsigned long ignored)
1526{
1527 unsigned long flags;
1528 int crd;
1529 unsigned int head, tail;
1530 struct channel *ch;
1531 struct board_info *bd;
1532
1533
1534
1535
1536
1537
1538
1539
1540 for (crd = 0; crd < num_cards; crd++) {
1541 bd = &boards[crd];
1542 ch = card_ptr[crd];
1543
1544 if ((bd->status == DISABLED) || digi_poller_inhibited)
1545 continue;
1546
1547
1548
1549
1550
1551
1552 spin_lock_irqsave(&epca_lock, flags);
1553
1554 assertmemoff(ch);
1555
1556 globalwinon(ch);
1557
1558
1559
1560
1561
1562 head = readw(&ch->mailbox->ein);
1563 tail = readw(&ch->mailbox->eout);
1564
1565
1566 if (head != tail)
1567 doevent(crd);
1568 memoff(ch);
1569
1570 spin_unlock_irqrestore(&epca_lock, flags);
1571 }
1572 mod_timer(&epca_timer, jiffies + (HZ / 25));
1573}
1574
1575static void doevent(int crd)
1576{
1577 void __iomem *eventbuf;
1578 struct channel *ch, *chan0;
1579 static struct tty_struct *tty;
1580 struct board_info *bd;
1581 struct board_chan __iomem *bc;
1582 unsigned int tail, head;
1583 int event, channel;
1584 int mstat, lstat;
1585
1586
1587
1588
1589
1590 bd = &boards[crd];
1591
1592 chan0 = card_ptr[crd];
1593 epcaassert(chan0 <= &digi_channels[nbdevs - 1], "ch out of range");
1594 assertgwinon(chan0);
1595 while ((tail = readw(&chan0->mailbox->eout)) !=
1596 (head = readw(&chan0->mailbox->ein))) {
1597
1598 assertgwinon(chan0);
1599 eventbuf = bd->re_map_membase + tail + ISTART;
1600
1601 channel = readb(eventbuf);
1602
1603 event = readb(eventbuf + 1);
1604
1605
1606
1607
1608
1609
1610 mstat = readb(eventbuf + 2);
1611 lstat = readb(eventbuf + 3);
1612
1613 ch = chan0 + channel;
1614 if ((unsigned)channel >= bd->numports || !ch) {
1615 if (channel >= bd->numports)
1616 ch = chan0;
1617 bc = ch->brdchan;
1618 goto next;
1619 }
1620
1621 bc = ch->brdchan;
1622 if (bc == NULL)
1623 goto next;
1624
1625 if (event & DATA_IND) {
1626 receive_data(ch);
1627 assertgwinon(ch);
1628 }
1629
1630 if (event & MODEMCHG_IND) {
1631
1632 ch->imodem = mstat;
1633 if (ch->port.flags & ASYNC_CHECK_CD) {
1634
1635 if (mstat & ch->dcd)
1636 wake_up_interruptible(&ch->port.open_wait);
1637 else
1638 pc_sched_event(ch, EPCA_EVENT_HANGUP);
1639 }
1640 }
1641 tty = ch->port.tty;
1642 if (tty) {
1643 if (event & BREAK_IND) {
1644
1645 tty_insert_flip_char(tty, 0, TTY_BREAK);
1646 tty_schedule_flip(tty);
1647 } else if (event & LOWTX_IND) {
1648 if (ch->statusflags & LOWWAIT) {
1649 ch->statusflags &= ~LOWWAIT;
1650 tty_wakeup(tty);
1651 }
1652 } else if (event & EMPTYTX_IND) {
1653
1654
1655 ch->statusflags &= ~TXBUSY;
1656 if (ch->statusflags & EMPTYWAIT) {
1657 ch->statusflags &= ~EMPTYWAIT;
1658 tty_wakeup(tty);
1659 }
1660 }
1661 }
1662next:
1663 globalwinon(ch);
1664 BUG_ON(!bc);
1665 writew(1, &bc->idata);
1666 writew((tail + 4) & (IMAX - ISTART - 4), &chan0->mailbox->eout);
1667 globalwinon(chan0);
1668 }
1669}
1670
1671static void fepcmd(struct channel *ch, int cmd, int word_or_byte,
1672 int byte2, int ncmds, int bytecmd)
1673{
1674 unchar __iomem *memaddr;
1675 unsigned int head, cmdTail, cmdStart, cmdMax;
1676 long count;
1677 int n;
1678
1679
1680
1681 if (ch->board->status == DISABLED)
1682 return;
1683 assertgwinon(ch);
1684
1685 head = readw(&ch->mailbox->cin);
1686
1687 cmdStart = readw(&ch->mailbox->cstart);
1688
1689
1690
1691
1692
1693 cmdMax = (cmdStart + 4 + readw(&ch->mailbox->cmax));
1694 memaddr = ch->board->re_map_membase;
1695
1696 if (head >= (cmdMax - cmdStart) || (head & 03)) {
1697 printk(KERN_ERR "line %d: Out of range, cmd = %x, head = %x\n",
1698 __LINE__, cmd, head);
1699 printk(KERN_ERR "line %d: Out of range, cmdMax = %x, cmdStart = %x\n",
1700 __LINE__, cmdMax, cmdStart);
1701 return;
1702 }
1703 if (bytecmd) {
1704 writeb(cmd, memaddr + head + cmdStart + 0);
1705 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1706
1707 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1708
1709 writeb(byte2, memaddr + head + cmdStart + 3);
1710 } else {
1711 writeb(cmd, memaddr + head + cmdStart + 0);
1712 writeb(ch->channelnum, memaddr + head + cmdStart + 1);
1713 writeb(word_or_byte, memaddr + head + cmdStart + 2);
1714 }
1715 head = (head + 4) & (cmdMax - cmdStart - 4);
1716 writew(head, &ch->mailbox->cin);
1717 count = FEPTIMEOUT;
1718
1719 for (;;) {
1720 count--;
1721 if (count == 0) {
1722 printk(KERN_ERR "<Error> - Fep not responding in fepcmd()\n");
1723 return;
1724 }
1725 head = readw(&ch->mailbox->cin);
1726 cmdTail = readw(&ch->mailbox->cout);
1727 n = (head - cmdTail) & (cmdMax - cmdStart - 4);
1728
1729
1730
1731
1732 if (n <= ncmds * (sizeof(short) * 4))
1733 break;
1734 }
1735}
1736
1737
1738
1739
1740
1741
1742
1743static unsigned termios2digi_h(struct channel *ch, unsigned cflag)
1744{
1745 unsigned res = 0;
1746
1747 if (cflag & CRTSCTS) {
1748 ch->digiext.digi_flags |= (RTSPACE | CTSPACE);
1749 res |= ((ch->m_cts) | (ch->m_rts));
1750 }
1751
1752 if (ch->digiext.digi_flags & RTSPACE)
1753 res |= ch->m_rts;
1754
1755 if (ch->digiext.digi_flags & DTRPACE)
1756 res |= ch->m_dtr;
1757
1758 if (ch->digiext.digi_flags & CTSPACE)
1759 res |= ch->m_cts;
1760
1761 if (ch->digiext.digi_flags & DSRPACE)
1762 res |= ch->dsr;
1763
1764 if (ch->digiext.digi_flags & DCDPACE)
1765 res |= ch->dcd;
1766
1767 if (res & (ch->m_rts))
1768 ch->digiext.digi_flags |= RTSPACE;
1769
1770 if (res & (ch->m_cts))
1771 ch->digiext.digi_flags |= CTSPACE;
1772
1773 return res;
1774}
1775
1776static unsigned termios2digi_i(struct channel *ch, unsigned iflag)
1777{
1778 unsigned res = iflag & (IGNBRK | BRKINT | IGNPAR | PARMRK |
1779 INPCK | ISTRIP | IXON | IXANY | IXOFF);
1780 if (ch->digiext.digi_flags & DIGI_AIXON)
1781 res |= IAIXON;
1782 return res;
1783}
1784
1785static unsigned termios2digi_c(struct channel *ch, unsigned cflag)
1786{
1787 unsigned res = 0;
1788 if (cflag & CBAUDEX) {
1789 ch->digiext.digi_flags |= DIGI_FAST;
1790
1791
1792
1793
1794 res |= FEP_HUPCL;
1795 } else
1796 ch->digiext.digi_flags &= ~DIGI_FAST;
1797
1798
1799
1800
1801
1802
1803 res |= cflag & ((CBAUD ^ CBAUDEX) | PARODD | PARENB | CSTOPB | CSIZE);
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824 if (cflag & CBAUDEX) {
1825
1826
1827
1828
1829
1830
1831 if ((!((cflag & 0x7) ^ (B115200 & ~CBAUDEX))) ||
1832 (!((cflag & 0x7) ^ (B230400 & ~CBAUDEX))))
1833 res += 1;
1834 }
1835 return res;
1836}
1837
1838
1839static void epcaparam(struct tty_struct *tty, struct channel *ch)
1840{
1841 unsigned int cmdHead;
1842 struct ktermios *ts;
1843 struct board_chan __iomem *bc;
1844 unsigned mval, hflow, cflag, iflag;
1845
1846 bc = ch->brdchan;
1847 epcaassert(bc != NULL, "bc out of range");
1848
1849 assertgwinon(ch);
1850 ts = tty->termios;
1851 if ((ts->c_cflag & CBAUD) == 0) {
1852 cmdHead = readw(&bc->rin);
1853 writew(cmdHead, &bc->rout);
1854 cmdHead = readw(&bc->tin);
1855
1856
1857
1858
1859
1860
1861 fepcmd(ch, STOUT, (unsigned) cmdHead, 0, 0, 0);
1862 mval = 0;
1863 } else {
1864
1865
1866
1867
1868 cflag = termios2digi_c(ch, ts->c_cflag);
1869 if (cflag != ch->fepcflag) {
1870 ch->fepcflag = cflag;
1871
1872 fepcmd(ch, SETCTRLFLAGS, (unsigned) cflag, 0, 0, 0);
1873 }
1874
1875
1876
1877
1878
1879 if (ts->c_cflag & CLOCAL)
1880 ch->port.flags &= ~ASYNC_CHECK_CD;
1881 else
1882 ch->port.flags |= ASYNC_CHECK_CD;
1883 mval = ch->m_dtr | ch->m_rts;
1884 }
1885 iflag = termios2digi_i(ch, ts->c_iflag);
1886
1887 if (iflag != ch->fepiflag) {
1888 ch->fepiflag = iflag;
1889
1890
1891
1892
1893
1894
1895
1896
1897 fepcmd(ch, SETIFLAGS, (unsigned int) ch->fepiflag, 0, 0, 0);
1898 }
1899
1900
1901
1902
1903
1904 writeb(ch->dcd, &bc->mint);
1905 if ((ts->c_cflag & CLOCAL) || (ch->digiext.digi_flags & DIGI_FORCEDCD))
1906 if (ch->digiext.digi_flags & DIGI_FORCEDCD)
1907 writeb(0, &bc->mint);
1908 ch->imodem = readb(&bc->mstat);
1909 hflow = termios2digi_h(ch, ts->c_cflag);
1910 if (hflow != ch->hflow) {
1911 ch->hflow = hflow;
1912
1913
1914
1915
1916 fepcmd(ch, SETHFLOW, hflow, 0xff, 0, 1);
1917 }
1918 mval ^= ch->modemfake & (mval ^ ch->modem);
1919
1920 if (ch->omodem ^ mval) {
1921 ch->omodem = mval;
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931 fepcmd(ch, SETMODEM, 0, ((ch->m_dtr)|(ch->m_rts)), 0, 1);
1932 fepcmd(ch, SETMODEM, mval, 0, 0, 1);
1933 }
1934 if (ch->startc != ch->fepstartc || ch->stopc != ch->fepstopc) {
1935 ch->fepstartc = ch->startc;
1936 ch->fepstopc = ch->stopc;
1937
1938
1939
1940
1941 fepcmd(ch, SONOFFC, ch->fepstartc, ch->fepstopc, 0, 1);
1942 }
1943 if (ch->startca != ch->fepstartca || ch->stopca != ch->fepstopca) {
1944 ch->fepstartca = ch->startca;
1945 ch->fepstopca = ch->stopca;
1946
1947
1948
1949
1950 fepcmd(ch, SAUXONOFFC, ch->fepstartca, ch->fepstopca, 0, 1);
1951 }
1952}
1953
1954
1955static void receive_data(struct channel *ch)
1956{
1957 unchar *rptr;
1958 struct ktermios *ts = NULL;
1959 struct tty_struct *tty;
1960 struct board_chan __iomem *bc;
1961 int dataToRead, wrapgap, bytesAvailable;
1962 unsigned int tail, head;
1963 unsigned int wrapmask;
1964
1965
1966
1967
1968
1969 globalwinon(ch);
1970 if (ch->statusflags & RXSTOPPED)
1971 return;
1972 tty = ch->port.tty;
1973 if (tty)
1974 ts = tty->termios;
1975 bc = ch->brdchan;
1976 BUG_ON(!bc);
1977 wrapmask = ch->rxbufsize - 1;
1978
1979
1980
1981
1982
1983 head = readw(&bc->rin);
1984 head &= wrapmask;
1985 tail = readw(&bc->rout) & wrapmask;
1986
1987 bytesAvailable = (head - tail) & wrapmask;
1988 if (bytesAvailable == 0)
1989 return;
1990
1991
1992 if (!tty || !ts || !(ts->c_cflag & CREAD)) {
1993 writew(head, &bc->rout);
1994 return;
1995 }
1996
1997 if (tty_buffer_request_room(tty, bytesAvailable + 1) == 0)
1998 return;
1999
2000 if (readb(&bc->orun)) {
2001 writeb(0, &bc->orun);
2002 printk(KERN_WARNING "epca; overrun! DigiBoard device %s\n",
2003 tty->name);
2004 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
2005 }
2006 rxwinon(ch);
2007 while (bytesAvailable > 0) {
2008
2009 wrapgap = (head >= tail) ? head - tail : ch->rxbufsize - tail;
2010
2011
2012
2013
2014
2015 dataToRead = (wrapgap < bytesAvailable) ? wrapgap
2016 : bytesAvailable;
2017
2018 dataToRead = tty_prepare_flip_string(tty, &rptr, dataToRead);
2019 if (dataToRead == 0)
2020 break;
2021
2022
2023
2024
2025 memcpy_fromio(rptr, ch->rxptr + tail, dataToRead);
2026 tail = (tail + dataToRead) & wrapmask;
2027 bytesAvailable -= dataToRead;
2028 }
2029 globalwinon(ch);
2030 writew(tail, &bc->rout);
2031
2032 tty_schedule_flip(ch->port.tty);
2033}
2034
2035static int info_ioctl(struct tty_struct *tty, struct file *file,
2036 unsigned int cmd, unsigned long arg)
2037{
2038 switch (cmd) {
2039 case DIGI_GETINFO:
2040 {
2041 struct digi_info di;
2042 int brd;
2043
2044 if (get_user(brd, (unsigned int __user *)arg))
2045 return -EFAULT;
2046 if (brd < 0 || brd >= num_cards || num_cards == 0)
2047 return -ENODEV;
2048
2049 memset(&di, 0, sizeof(di));
2050
2051 di.board = brd;
2052 di.status = boards[brd].status;
2053 di.type = boards[brd].type ;
2054 di.numports = boards[brd].numports ;
2055
2056 di.port = (unsigned char *)boards[brd].port ;
2057 di.membase = (unsigned char *)boards[brd].membase ;
2058
2059 if (copy_to_user((void __user *)arg, &di, sizeof(di)))
2060 return -EFAULT;
2061 break;
2062
2063 }
2064
2065 case DIGI_POLLER:
2066 {
2067 int brd = arg & 0xff000000 >> 16;
2068 unsigned char state = arg & 0xff;
2069
2070 if (brd < 0 || brd >= num_cards) {
2071 printk(KERN_ERR "epca: DIGI POLLER : brd not valid!\n");
2072 return -ENODEV;
2073 }
2074 digi_poller_inhibited = state;
2075 break;
2076 }
2077
2078 case DIGI_INIT:
2079 {
2080
2081
2082
2083
2084
2085
2086
2087 int crd;
2088 for (crd = 0; crd < num_cards; crd++)
2089 post_fep_init(crd);
2090 break;
2091 }
2092 default:
2093 return -ENOTTY;
2094 }
2095 return 0;
2096}
2097
2098static int pc_tiocmget(struct tty_struct *tty, struct file *file)
2099{
2100 struct channel *ch = (struct channel *) tty->driver_data;
2101 struct board_chan __iomem *bc;
2102 unsigned int mstat, mflag = 0;
2103 unsigned long flags;
2104
2105 if (ch)
2106 bc = ch->brdchan;
2107 else
2108 return -EINVAL;
2109
2110 spin_lock_irqsave(&epca_lock, flags);
2111 globalwinon(ch);
2112 mstat = readb(&bc->mstat);
2113 memoff(ch);
2114 spin_unlock_irqrestore(&epca_lock, flags);
2115
2116 if (mstat & ch->m_dtr)
2117 mflag |= TIOCM_DTR;
2118 if (mstat & ch->m_rts)
2119 mflag |= TIOCM_RTS;
2120 if (mstat & ch->m_cts)
2121 mflag |= TIOCM_CTS;
2122 if (mstat & ch->dsr)
2123 mflag |= TIOCM_DSR;
2124 if (mstat & ch->m_ri)
2125 mflag |= TIOCM_RI;
2126 if (mstat & ch->dcd)
2127 mflag |= TIOCM_CD;
2128 return mflag;
2129}
2130
2131static int pc_tiocmset(struct tty_struct *tty, struct file *file,
2132 unsigned int set, unsigned int clear)
2133{
2134 struct channel *ch = (struct channel *) tty->driver_data;
2135 unsigned long flags;
2136
2137 if (!ch)
2138 return -EINVAL;
2139
2140 spin_lock_irqsave(&epca_lock, flags);
2141
2142
2143
2144
2145
2146 if (set & TIOCM_RTS) {
2147 ch->modemfake |= ch->m_rts;
2148 ch->modem |= ch->m_rts;
2149 }
2150 if (set & TIOCM_DTR) {
2151 ch->modemfake |= ch->m_dtr;
2152 ch->modem |= ch->m_dtr;
2153 }
2154 if (clear & TIOCM_RTS) {
2155 ch->modemfake |= ch->m_rts;
2156 ch->modem &= ~ch->m_rts;
2157 }
2158 if (clear & TIOCM_DTR) {
2159 ch->modemfake |= ch->m_dtr;
2160 ch->modem &= ~ch->m_dtr;
2161 }
2162 globalwinon(ch);
2163
2164
2165
2166
2167 epcaparam(tty, ch);
2168 memoff(ch);
2169 spin_unlock_irqrestore(&epca_lock, flags);
2170 return 0;
2171}
2172
2173static int pc_ioctl(struct tty_struct *tty, struct file *file,
2174 unsigned int cmd, unsigned long arg)
2175{
2176 digiflow_t dflow;
2177 unsigned long flags;
2178 unsigned int mflag, mstat;
2179 unsigned char startc, stopc;
2180 struct board_chan __iomem *bc;
2181 struct channel *ch = (struct channel *) tty->driver_data;
2182 void __user *argp = (void __user *)arg;
2183
2184 if (ch)
2185 bc = ch->brdchan;
2186 else
2187 return -EINVAL;
2188 switch (cmd) {
2189 case TIOCMODG:
2190 mflag = pc_tiocmget(tty, file);
2191 if (put_user(mflag, (unsigned long __user *)argp))
2192 return -EFAULT;
2193 break;
2194 case TIOCMODS:
2195 if (get_user(mstat, (unsigned __user *)argp))
2196 return -EFAULT;
2197 return pc_tiocmset(tty, file, mstat, ~mstat);
2198 case TIOCSDTR:
2199 spin_lock_irqsave(&epca_lock, flags);
2200 ch->omodem |= ch->m_dtr;
2201 globalwinon(ch);
2202 fepcmd(ch, SETMODEM, ch->m_dtr, 0, 10, 1);
2203 memoff(ch);
2204 spin_unlock_irqrestore(&epca_lock, flags);
2205 break;
2206
2207 case TIOCCDTR:
2208 spin_lock_irqsave(&epca_lock, flags);
2209 ch->omodem &= ~ch->m_dtr;
2210 globalwinon(ch);
2211 fepcmd(ch, SETMODEM, 0, ch->m_dtr, 10, 1);
2212 memoff(ch);
2213 spin_unlock_irqrestore(&epca_lock, flags);
2214 break;
2215 case DIGI_GETA:
2216 if (copy_to_user(argp, &ch->digiext, sizeof(digi_t)))
2217 return -EFAULT;
2218 break;
2219 case DIGI_SETAW:
2220 case DIGI_SETAF:
2221 lock_kernel();
2222 if (cmd == DIGI_SETAW) {
2223
2224
2225 spin_lock_irqsave(&epca_lock, flags);
2226 setup_empty_event(tty, ch);
2227 spin_unlock_irqrestore(&epca_lock, flags);
2228 tty_wait_until_sent(tty, 0);
2229 } else {
2230
2231 if (tty->ldisc.ops->flush_buffer)
2232 tty->ldisc.ops->flush_buffer(tty);
2233 }
2234 unlock_kernel();
2235
2236 case DIGI_SETA:
2237 if (copy_from_user(&ch->digiext, argp, sizeof(digi_t)))
2238 return -EFAULT;
2239
2240 if (ch->digiext.digi_flags & DIGI_ALTPIN) {
2241 ch->dcd = ch->m_dsr;
2242 ch->dsr = ch->m_dcd;
2243 } else {
2244 ch->dcd = ch->m_dcd;
2245 ch->dsr = ch->m_dsr;
2246 }
2247
2248 spin_lock_irqsave(&epca_lock, flags);
2249 globalwinon(ch);
2250
2251
2252
2253
2254
2255
2256 epcaparam(tty, ch);
2257 memoff(ch);
2258 spin_unlock_irqrestore(&epca_lock, flags);
2259 break;
2260
2261 case DIGI_GETFLOW:
2262 case DIGI_GETAFLOW:
2263 spin_lock_irqsave(&epca_lock, flags);
2264 globalwinon(ch);
2265 if (cmd == DIGI_GETFLOW) {
2266 dflow.startc = readb(&bc->startc);
2267 dflow.stopc = readb(&bc->stopc);
2268 } else {
2269 dflow.startc = readb(&bc->startca);
2270 dflow.stopc = readb(&bc->stopca);
2271 }
2272 memoff(ch);
2273 spin_unlock_irqrestore(&epca_lock, flags);
2274
2275 if (copy_to_user(argp, &dflow, sizeof(dflow)))
2276 return -EFAULT;
2277 break;
2278
2279 case DIGI_SETAFLOW:
2280 case DIGI_SETFLOW:
2281 if (cmd == DIGI_SETFLOW) {
2282 startc = ch->startc;
2283 stopc = ch->stopc;
2284 } else {
2285 startc = ch->startca;
2286 stopc = ch->stopca;
2287 }
2288
2289 if (copy_from_user(&dflow, argp, sizeof(dflow)))
2290 return -EFAULT;
2291
2292 if (dflow.startc != startc || dflow.stopc != stopc) {
2293
2294 spin_lock_irqsave(&epca_lock, flags);
2295 globalwinon(ch);
2296
2297 if (cmd == DIGI_SETFLOW) {
2298 ch->fepstartc = ch->startc = dflow.startc;
2299 ch->fepstopc = ch->stopc = dflow.stopc;
2300 fepcmd(ch, SONOFFC, ch->fepstartc,
2301 ch->fepstopc, 0, 1);
2302 } else {
2303 ch->fepstartca = ch->startca = dflow.startc;
2304 ch->fepstopca = ch->stopca = dflow.stopc;
2305 fepcmd(ch, SAUXONOFFC, ch->fepstartca,
2306 ch->fepstopca, 0, 1);
2307 }
2308
2309 if (ch->statusflags & TXSTOPPED)
2310 pc_start(tty);
2311
2312 memoff(ch);
2313 spin_unlock_irqrestore(&epca_lock, flags);
2314 }
2315 break;
2316 default:
2317 return -ENOIOCTLCMD;
2318 }
2319 return 0;
2320}
2321
2322static void pc_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
2323{
2324 struct channel *ch;
2325 unsigned long flags;
2326
2327
2328
2329
2330 ch = verifyChannel(tty);
2331
2332 if (ch != NULL) {
2333 spin_lock_irqsave(&epca_lock, flags);
2334 globalwinon(ch);
2335 epcaparam(tty, ch);
2336 memoff(ch);
2337 spin_unlock_irqrestore(&epca_lock, flags);
2338
2339 if ((old_termios->c_cflag & CRTSCTS) &&
2340 ((tty->termios->c_cflag & CRTSCTS) == 0))
2341 tty->hw_stopped = 0;
2342
2343 if (!(old_termios->c_cflag & CLOCAL) &&
2344 (tty->termios->c_cflag & CLOCAL))
2345 wake_up_interruptible(&ch->port.open_wait);
2346
2347 }
2348}
2349
2350static void do_softint(struct work_struct *work)
2351{
2352 struct channel *ch = container_of(work, struct channel, tqueue);
2353
2354 if (ch && ch->magic == EPCA_MAGIC) {
2355 struct tty_struct *tty = ch->port.tty;
2356
2357 if (tty && tty->driver_data) {
2358 if (test_and_clear_bit(EPCA_EVENT_HANGUP, &ch->event)) {
2359 tty_hangup(tty);
2360 wake_up_interruptible(&ch->port.open_wait);
2361 ch->port.flags &= ~ASYNC_NORMAL_ACTIVE;
2362 }
2363 }
2364 }
2365}
2366
2367
2368
2369
2370
2371static void pc_stop(struct tty_struct *tty)
2372{
2373 struct channel *ch;
2374 unsigned long flags;
2375
2376
2377
2378
2379 ch = verifyChannel(tty);
2380 if (ch != NULL) {
2381 spin_lock_irqsave(&epca_lock, flags);
2382 if ((ch->statusflags & TXSTOPPED) == 0) {
2383
2384 globalwinon(ch);
2385
2386 fepcmd(ch, PAUSETX, 0, 0, 0, 0);
2387 ch->statusflags |= TXSTOPPED;
2388 memoff(ch);
2389 }
2390 spin_unlock_irqrestore(&epca_lock, flags);
2391 }
2392}
2393
2394static void pc_start(struct tty_struct *tty)
2395{
2396 struct channel *ch;
2397
2398
2399
2400
2401 ch = verifyChannel(tty);
2402 if (ch != NULL) {
2403 unsigned long flags;
2404 spin_lock_irqsave(&epca_lock, flags);
2405
2406
2407 if (ch->statusflags & TXSTOPPED) {
2408
2409 struct board_chan __iomem *bc;
2410 globalwinon(ch);
2411 bc = ch->brdchan;
2412 if (ch->statusflags & LOWWAIT)
2413 writeb(1, &bc->ilow);
2414
2415 fepcmd(ch, RESUMETX, 0, 0, 0, 0);
2416 ch->statusflags &= ~TXSTOPPED;
2417 memoff(ch);
2418 }
2419 spin_unlock_irqrestore(&epca_lock, flags);
2420 }
2421}
2422
2423
2424
2425
2426
2427
2428
2429
2430static void pc_throttle(struct tty_struct *tty)
2431{
2432 struct channel *ch;
2433 unsigned long flags;
2434
2435
2436
2437
2438 ch = verifyChannel(tty);
2439 if (ch != NULL) {
2440 spin_lock_irqsave(&epca_lock, flags);
2441 if ((ch->statusflags & RXSTOPPED) == 0) {
2442 globalwinon(ch);
2443 fepcmd(ch, PAUSERX, 0, 0, 0, 0);
2444 ch->statusflags |= RXSTOPPED;
2445 memoff(ch);
2446 }
2447 spin_unlock_irqrestore(&epca_lock, flags);
2448 }
2449}
2450
2451static void pc_unthrottle(struct tty_struct *tty)
2452{
2453 struct channel *ch;
2454 unsigned long flags;
2455
2456
2457
2458
2459 ch = verifyChannel(tty);
2460 if (ch != NULL) {
2461
2462
2463 spin_lock_irqsave(&epca_lock, flags);
2464 if (ch->statusflags & RXSTOPPED) {
2465 globalwinon(ch);
2466 fepcmd(ch, RESUMERX, 0, 0, 0, 0);
2467 ch->statusflags &= ~RXSTOPPED;
2468 memoff(ch);
2469 }
2470 spin_unlock_irqrestore(&epca_lock, flags);
2471 }
2472}
2473
2474static int pc_send_break(struct tty_struct *tty, int msec)
2475{
2476 struct channel *ch = (struct channel *) tty->driver_data;
2477 unsigned long flags;
2478
2479 if (msec == -1)
2480 msec = 0xFFFF;
2481 else if (msec > 0xFFFE)
2482 msec = 0xFFFE;
2483 else if (msec < 1)
2484 msec = 1;
2485
2486 spin_lock_irqsave(&epca_lock, flags);
2487 globalwinon(ch);
2488
2489
2490
2491
2492
2493
2494
2495 fepcmd(ch, SENDBREAK, msec, 0, 10, 0);
2496 memoff(ch);
2497 spin_unlock_irqrestore(&epca_lock, flags);
2498 return 0;
2499}
2500
2501
2502static void setup_empty_event(struct tty_struct *tty, struct channel *ch)
2503{
2504 struct board_chan __iomem *bc = ch->brdchan;
2505
2506 globalwinon(ch);
2507 ch->statusflags |= EMPTYWAIT;
2508
2509
2510
2511
2512 writeb(1, &bc->iempty);
2513 memoff(ch);
2514}
2515
2516#ifndef MODULE
2517static void __init epca_setup(char *str, int *ints)
2518{
2519 struct board_info board;
2520 int index, loop, last;
2521 char *temp, *t2;
2522 unsigned len;
2523
2524
2525
2526
2527
2528
2529
2530 if (!liloconfig)
2531 liloconfig = 1;
2532
2533 memset(&board, 0, sizeof(board));
2534
2535
2536
2537 for (last = 0, index = 1; index <= ints[0]; index++)
2538 switch (index) {
2539 case 1:
2540 board.status = ints[index];
2541
2542
2543
2544
2545
2546 if (board.status == 2) {
2547
2548 nbdevs = 0;
2549 num_cards = 0;
2550 return;
2551 }
2552
2553 if (board.status > 2) {
2554 printk(KERN_ERR "epca_setup: Invalid board status 0x%x\n",
2555 board.status);
2556 invalid_lilo_config = 1;
2557 setup_error_code |= INVALID_BOARD_STATUS;
2558 return;
2559 }
2560 last = index;
2561 break;
2562 case 2:
2563 board.type = ints[index];
2564 if (board.type >= PCIXEM) {
2565 printk(KERN_ERR "epca_setup: Invalid board type 0x%x\n", board.type);
2566 invalid_lilo_config = 1;
2567 setup_error_code |= INVALID_BOARD_TYPE;
2568 return;
2569 }
2570 last = index;
2571 break;
2572 case 3:
2573 board.altpin = ints[index];
2574 if (board.altpin > 1) {
2575 printk(KERN_ERR "epca_setup: Invalid board altpin 0x%x\n", board.altpin);
2576 invalid_lilo_config = 1;
2577 setup_error_code |= INVALID_ALTPIN;
2578 return;
2579 }
2580 last = index;
2581 break;
2582
2583 case 4:
2584 board.numports = ints[index];
2585 if (board.numports < 2 || board.numports > 256) {
2586 printk(KERN_ERR "epca_setup: Invalid board numports 0x%x\n", board.numports);
2587 invalid_lilo_config = 1;
2588 setup_error_code |= INVALID_NUM_PORTS;
2589 return;
2590 }
2591 nbdevs += board.numports;
2592 last = index;
2593 break;
2594
2595 case 5:
2596 board.port = ints[index];
2597 if (ints[index] <= 0) {
2598 printk(KERN_ERR "epca_setup: Invalid io port 0x%x\n", (unsigned int)board.port);
2599 invalid_lilo_config = 1;
2600 setup_error_code |= INVALID_PORT_BASE;
2601 return;
2602 }
2603 last = index;
2604 break;
2605
2606 case 6:
2607 board.membase = ints[index];
2608 if (ints[index] <= 0) {
2609 printk(KERN_ERR "epca_setup: Invalid memory base 0x%x\n",
2610 (unsigned int)board.membase);
2611 invalid_lilo_config = 1;
2612 setup_error_code |= INVALID_MEM_BASE;
2613 return;
2614 }
2615 last = index;
2616 break;
2617
2618 default:
2619 printk(KERN_ERR "<Error> - epca_setup: Too many integer parms\n");
2620 return;
2621
2622 }
2623
2624 while (str && *str) {
2625
2626 temp = str;
2627
2628 while (*temp && (*temp != ','))
2629 temp++;
2630 if (!*temp)
2631 temp = NULL;
2632 else
2633 *temp++ = 0;
2634
2635 index = last + 1;
2636
2637 switch (index) {
2638 case 1:
2639 len = strlen(str);
2640 if (strncmp("Disable", str, len) == 0)
2641 board.status = 0;
2642 else if (strncmp("Enable", str, len) == 0)
2643 board.status = 1;
2644 else {
2645 printk(KERN_ERR "epca_setup: Invalid status %s\n", str);
2646 invalid_lilo_config = 1;
2647 setup_error_code |= INVALID_BOARD_STATUS;
2648 return;
2649 }
2650 last = index;
2651 break;
2652
2653 case 2:
2654 for (loop = 0; loop < EPCA_NUM_TYPES; loop++)
2655 if (strcmp(board_desc[loop], str) == 0)
2656 break;
2657
2658
2659
2660
2661 if (index < EPCA_NUM_TYPES)
2662 board.type = loop;
2663 else {
2664 printk(KERN_ERR "epca_setup: Invalid board type: %s\n", str);
2665 invalid_lilo_config = 1;
2666 setup_error_code |= INVALID_BOARD_TYPE;
2667 return;
2668 }
2669 last = index;
2670 break;
2671
2672 case 3:
2673 len = strlen(str);
2674 if (strncmp("Disable", str, len) == 0)
2675 board.altpin = 0;
2676 else if (strncmp("Enable", str, len) == 0)
2677 board.altpin = 1;
2678 else {
2679 printk(KERN_ERR "epca_setup: Invalid altpin %s\n", str);
2680 invalid_lilo_config = 1;
2681 setup_error_code |= INVALID_ALTPIN;
2682 return;
2683 }
2684 last = index;
2685 break;
2686
2687 case 4:
2688 t2 = str;
2689 while (isdigit(*t2))
2690 t2++;
2691
2692 if (*t2) {
2693 printk(KERN_ERR "epca_setup: Invalid port count %s\n", str);
2694 invalid_lilo_config = 1;
2695 setup_error_code |= INVALID_NUM_PORTS;
2696 return;
2697 }
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714 board.numports = simple_strtoul(str, NULL, 0);
2715 nbdevs += board.numports;
2716 last = index;
2717 break;
2718
2719 case 5:
2720 t2 = str;
2721 while (isxdigit(*t2))
2722 t2++;
2723
2724 if (*t2) {
2725 printk(KERN_ERR "epca_setup: Invalid i/o address %s\n", str);
2726 invalid_lilo_config = 1;
2727 setup_error_code |= INVALID_PORT_BASE;
2728 return;
2729 }
2730
2731 board.port = simple_strtoul(str, NULL, 16);
2732 last = index;
2733 break;
2734
2735 case 6:
2736 t2 = str;
2737 while (isxdigit(*t2))
2738 t2++;
2739
2740 if (*t2) {
2741 printk(KERN_ERR "epca_setup: Invalid memory base %s\n", str);
2742 invalid_lilo_config = 1;
2743 setup_error_code |= INVALID_MEM_BASE;
2744 return;
2745 }
2746 board.membase = simple_strtoul(str, NULL, 16);
2747 last = index;
2748 break;
2749 default:
2750 printk(KERN_ERR "epca: Too many string parms\n");
2751 return;
2752 }
2753 str = temp;
2754 }
2755
2756 if (last < 6) {
2757 printk(KERN_ERR "epca: Insufficient parms specified\n");
2758 return;
2759 }
2760
2761
2762
2763 memcpy((void *)&boards[num_cards], (void *)&board, sizeof(board));
2764
2765 printk(KERN_INFO "PC/Xx: Added board %i, %s %i ports at 0x%4.4X base 0x%6.6X\n",
2766 num_cards, board_desc[board.type],
2767 board.numports, (int)board.port, (unsigned int) board.membase);
2768 num_cards++;
2769}
2770
2771static int __init epca_real_setup(char *str)
2772{
2773 int ints[11];
2774
2775 epca_setup(get_options(str, 11, ints), ints);
2776 return 1;
2777}
2778
2779__setup("digiepca", epca_real_setup);
2780#endif
2781
2782enum epic_board_types {
2783 brd_xr = 0,
2784 brd_xem,
2785 brd_cx,
2786 brd_xrj,
2787};
2788
2789
2790static struct {
2791 unsigned char board_type;
2792 unsigned bar_idx;
2793} epca_info_tbl[] = {
2794 { PCIXR, 0, },
2795 { PCIXEM, 0, },
2796 { PCICX, 0, },
2797 { PCIXRJ, 2, },
2798};
2799
2800static int __devinit epca_init_one(struct pci_dev *pdev,
2801 const struct pci_device_id *ent)
2802{
2803 static int board_num = -1;
2804 int board_idx, info_idx = ent->driver_data;
2805 unsigned long addr;
2806
2807 if (pci_enable_device(pdev))
2808 return -EIO;
2809
2810 board_num++;
2811 board_idx = board_num + num_cards;
2812 if (board_idx >= MAXBOARDS)
2813 goto err_out;
2814
2815 addr = pci_resource_start(pdev, epca_info_tbl[info_idx].bar_idx);
2816 if (!addr) {
2817 printk(KERN_ERR PFX "PCI region #%d not available (size 0)\n",
2818 epca_info_tbl[info_idx].bar_idx);
2819 goto err_out;
2820 }
2821
2822 boards[board_idx].status = ENABLED;
2823 boards[board_idx].type = epca_info_tbl[info_idx].board_type;
2824 boards[board_idx].numports = 0x0;
2825 boards[board_idx].port = addr + PCI_IO_OFFSET;
2826 boards[board_idx].membase = addr;
2827
2828 if (!request_mem_region(addr + PCI_IO_OFFSET, 0x200000, "epca")) {
2829 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2830 0x200000, addr + PCI_IO_OFFSET);
2831 goto err_out;
2832 }
2833
2834 boards[board_idx].re_map_port = ioremap_nocache(addr + PCI_IO_OFFSET,
2835 0x200000);
2836 if (!boards[board_idx].re_map_port) {
2837 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2838 0x200000, addr + PCI_IO_OFFSET);
2839 goto err_out_free_pciio;
2840 }
2841
2842 if (!request_mem_region(addr, 0x200000, "epca")) {
2843 printk(KERN_ERR PFX "resource 0x%x @ 0x%lx unavailable\n",
2844 0x200000, addr);
2845 goto err_out_free_iounmap;
2846 }
2847
2848 boards[board_idx].re_map_membase = ioremap_nocache(addr, 0x200000);
2849 if (!boards[board_idx].re_map_membase) {
2850 printk(KERN_ERR PFX "cannot map 0x%x @ 0x%lx\n",
2851 0x200000, addr + PCI_IO_OFFSET);
2852 goto err_out_free_memregion;
2853 }
2854
2855
2856
2857
2858
2859 if (info_idx != brd_xrj) {
2860 pci_write_config_byte(pdev, 0x40, 0);
2861 pci_write_config_byte(pdev, 0x46, 0);
2862 }
2863
2864 return 0;
2865
2866err_out_free_memregion:
2867 release_mem_region(addr, 0x200000);
2868err_out_free_iounmap:
2869 iounmap(boards[board_idx].re_map_port);
2870err_out_free_pciio:
2871 release_mem_region(addr + PCI_IO_OFFSET, 0x200000);
2872err_out:
2873 return -ENODEV;
2874}
2875
2876
2877static struct pci_device_id epca_pci_tbl[] = {
2878 { PCI_VENDOR_DIGI, PCI_DEVICE_XR, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xr },
2879 { PCI_VENDOR_DIGI, PCI_DEVICE_XEM, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xem },
2880 { PCI_VENDOR_DIGI, PCI_DEVICE_CX, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_cx },
2881 { PCI_VENDOR_DIGI, PCI_DEVICE_XRJ, PCI_ANY_ID, PCI_ANY_ID, 0, 0, brd_xrj },
2882 { 0, }
2883};
2884
2885MODULE_DEVICE_TABLE(pci, epca_pci_tbl);
2886
2887static int __init init_PCI(void)
2888{
2889 memset(&epca_driver, 0, sizeof(epca_driver));
2890 epca_driver.name = "epca";
2891 epca_driver.id_table = epca_pci_tbl;
2892 epca_driver.probe = epca_init_one;
2893
2894 return pci_register_driver(&epca_driver);
2895}
2896
2897MODULE_LICENSE("GPL");