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