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