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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45#include <linux/module.h>
46#include <linux/init.h>
47#include <linux/sched.h>
48#include <linux/delay.h>
49#include <linux/errno.h>
50#include <linux/interrupt.h>
51#include <linux/ioport.h>
52#include <linux/kernel.h>
53#include <linux/slab.h>
54#include <linux/dma-mapping.h>
55#include <linux/pci.h>
56#include <linux/pnp.h>
57#include <linux/platform_device.h>
58#include <linux/sysctl.h>
59
60#include <asm/io.h>
61#include <asm/dma.h>
62#include <asm/uaccess.h>
63
64#include <linux/parport.h>
65#include <linux/parport_pc.h>
66#include <linux/via.h>
67#include <asm/parport.h>
68
69#define PARPORT_PC_MAX_PORTS PARPORT_MAX
70
71#ifdef CONFIG_ISA_DMA_API
72#define HAS_DMA
73#endif
74
75
76#define ECR_SPP 00
77#define ECR_PS2 01
78#define ECR_PPF 02
79#define ECR_ECP 03
80#define ECR_EPP 04
81#define ECR_VND 05
82#define ECR_TST 06
83#define ECR_CNF 07
84#define ECR_MODE_MASK 0xe0
85#define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v))
86
87#undef DEBUG
88
89#ifdef DEBUG
90#define DPRINTK printk
91#else
92#define DPRINTK(stuff...)
93#endif
94
95
96#define NR_SUPERIOS 3
97static struct superio_struct {
98 int io;
99 int irq;
100 int dma;
101} superios[NR_SUPERIOS] = { {0,},};
102
103static int user_specified;
104#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
105 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
106static int verbose_probing;
107#endif
108static int pci_registered_parport;
109static int pnp_registered_parport;
110
111
112static void frob_econtrol (struct parport *pb, unsigned char m,
113 unsigned char v)
114{
115 unsigned char ectr = 0;
116
117 if (m != 0xff)
118 ectr = inb (ECONTROL (pb));
119
120 DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
121 m, v, ectr, (ectr & ~m) ^ v);
122
123 outb ((ectr & ~m) ^ v, ECONTROL (pb));
124}
125
126static __inline__ void frob_set_mode (struct parport *p, int mode)
127{
128 frob_econtrol (p, ECR_MODE_MASK, mode << 5);
129}
130
131#ifdef CONFIG_PARPORT_PC_FIFO
132
133
134
135
136
137
138static int change_mode(struct parport *p, int m)
139{
140 const struct parport_pc_private *priv = p->physport->private_data;
141 unsigned char oecr;
142 int mode;
143
144 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m);
145
146 if (!priv->ecr) {
147 printk (KERN_DEBUG "change_mode: but there's no ECR!\n");
148 return 0;
149 }
150
151
152 oecr = inb (ECONTROL (p));
153 mode = (oecr >> 5) & 0x7;
154 if (mode == m) return 0;
155
156 if (mode >= 2 && !(priv->ctr & 0x20)) {
157
158
159 unsigned long expire = jiffies + p->physport->cad->timeout;
160 int counter;
161 switch (mode) {
162 case ECR_PPF:
163 case ECR_ECP:
164
165 for (counter = 0; counter < 40; counter++) {
166 if (inb (ECONTROL (p)) & 0x01)
167 break;
168 if (signal_pending (current)) break;
169 udelay (5);
170 }
171
172
173 while (!(inb (ECONTROL (p)) & 0x01)) {
174 if (time_after_eq (jiffies, expire))
175
176 return -EBUSY;
177 schedule_timeout_interruptible(msecs_to_jiffies(10));
178 if (signal_pending (current))
179 break;
180 }
181 }
182 }
183
184 if (mode >= 2 && m >= 2) {
185
186 oecr &= ~(7 << 5);
187 oecr |= ECR_PS2 << 5;
188 ECR_WRITE (p, oecr);
189 }
190
191
192 oecr &= ~(7 << 5);
193 oecr |= m << 5;
194 ECR_WRITE (p, oecr);
195 return 0;
196}
197
198#ifdef CONFIG_PARPORT_1284
199
200#if 0
201static int get_fifo_residue (struct parport *p)
202{
203 int residue;
204 int cnfga;
205 const struct parport_pc_private *priv = p->physport->private_data;
206
207
208 for (residue = priv->fifo_depth; ; residue--) {
209 if (inb (ECONTROL (p)) & 0x2)
210
211 break;
212
213 outb (0, FIFO (p));
214 }
215
216 printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
217 residue);
218
219
220 frob_set_mode (p, ECR_PS2);
221
222
223 frob_set_mode (p, ECR_CNF);
224 cnfga = inb (CONFIGA (p));
225 printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
226
227 if (!(cnfga & (1<<2))) {
228 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
229 residue++;
230 }
231
232
233
234
235
236 frob_set_mode (p, ECR_PS2);
237
238 DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p)));
239 return residue;
240}
241#endif
242#endif
243#endif
244
245
246
247
248
249
250static int clear_epp_timeout(struct parport *pb)
251{
252 unsigned char r;
253
254 if (!(parport_pc_read_status(pb) & 0x01))
255 return 1;
256
257
258 parport_pc_read_status(pb);
259 r = parport_pc_read_status(pb);
260 outb (r | 0x01, STATUS (pb));
261 outb (r & 0xfe, STATUS (pb));
262 r = parport_pc_read_status(pb);
263
264 return !(r & 0x01);
265}
266
267
268
269
270
271
272
273
274
275static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s)
276{
277 s->u.pc.ctr = 0xc;
278 if (dev->irq_func &&
279 dev->port->irq != PARPORT_IRQ_NONE)
280
281 s->u.pc.ctr |= 0x10;
282
283 s->u.pc.ecr = 0x34;
284
285}
286
287static void parport_pc_save_state(struct parport *p, struct parport_state *s)
288{
289 const struct parport_pc_private *priv = p->physport->private_data;
290 s->u.pc.ctr = priv->ctr;
291 if (priv->ecr)
292 s->u.pc.ecr = inb (ECONTROL (p));
293}
294
295static void parport_pc_restore_state(struct parport *p, struct parport_state *s)
296{
297 struct parport_pc_private *priv = p->physport->private_data;
298 register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
299 outb (c, CONTROL (p));
300 priv->ctr = c;
301 if (priv->ecr)
302 ECR_WRITE (p, s->u.pc.ecr);
303}
304
305#ifdef CONFIG_PARPORT_1284
306static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
307 size_t length, int flags)
308{
309 size_t got = 0;
310
311 if (flags & PARPORT_W91284PIC) {
312 unsigned char status;
313 size_t left = length;
314
315
316
317
318
319 status = inb (STATUS (port));
320
321 while (!(status & 0x08) && (got < length)) {
322 if ((left >= 16) && (status & 0x20) && !(status & 0x08)) {
323
324 if (!((long)buf & 0x03)) {
325 insl (EPPDATA (port), buf, 4);
326 } else {
327 insb (EPPDATA (port), buf, 16);
328 }
329 buf += 16;
330 got += 16;
331 left -= 16;
332 } else {
333
334 *((char *)buf) = inb (EPPDATA (port));
335 buf++;
336 got++;
337 left--;
338 }
339 status = inb (STATUS (port));
340 if (status & 0x01) {
341
342 printk (KERN_DEBUG "%s: EPP timeout occurred while talking to "
343 "w91284pic (should not have done)\n", port->name);
344 clear_epp_timeout (port);
345 }
346 }
347 return got;
348 }
349 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
350 if (!(((long)buf | length) & 0x03)) {
351 insl (EPPDATA (port), buf, (length >> 2));
352 } else {
353 insb (EPPDATA (port), buf, length);
354 }
355 if (inb (STATUS (port)) & 0x01) {
356 clear_epp_timeout (port);
357 return -EIO;
358 }
359 return length;
360 }
361 for (; got < length; got++) {
362 *((char*)buf) = inb (EPPDATA(port));
363 buf++;
364 if (inb (STATUS (port)) & 0x01) {
365
366 clear_epp_timeout (port);
367 break;
368 }
369 }
370
371 return got;
372}
373
374static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
375 size_t length, int flags)
376{
377 size_t written = 0;
378
379 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
380 if (!(((long)buf | length) & 0x03)) {
381 outsl (EPPDATA (port), buf, (length >> 2));
382 } else {
383 outsb (EPPDATA (port), buf, length);
384 }
385 if (inb (STATUS (port)) & 0x01) {
386 clear_epp_timeout (port);
387 return -EIO;
388 }
389 return length;
390 }
391 for (; written < length; written++) {
392 outb (*((char*)buf), EPPDATA(port));
393 buf++;
394 if (inb (STATUS(port)) & 0x01) {
395 clear_epp_timeout (port);
396 break;
397 }
398 }
399
400 return written;
401}
402
403static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
404 size_t length, int flags)
405{
406 size_t got = 0;
407
408 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
409 insb (EPPADDR (port), buf, length);
410 if (inb (STATUS (port)) & 0x01) {
411 clear_epp_timeout (port);
412 return -EIO;
413 }
414 return length;
415 }
416 for (; got < length; got++) {
417 *((char*)buf) = inb (EPPADDR (port));
418 buf++;
419 if (inb (STATUS (port)) & 0x01) {
420 clear_epp_timeout (port);
421 break;
422 }
423 }
424
425 return got;
426}
427
428static size_t parport_pc_epp_write_addr (struct parport *port,
429 const void *buf, size_t length,
430 int flags)
431{
432 size_t written = 0;
433
434 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
435 outsb (EPPADDR (port), buf, length);
436 if (inb (STATUS (port)) & 0x01) {
437 clear_epp_timeout (port);
438 return -EIO;
439 }
440 return length;
441 }
442 for (; written < length; written++) {
443 outb (*((char*)buf), EPPADDR (port));
444 buf++;
445 if (inb (STATUS (port)) & 0x01) {
446 clear_epp_timeout (port);
447 break;
448 }
449 }
450
451 return written;
452}
453
454static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf,
455 size_t length, int flags)
456{
457 size_t got;
458
459 frob_set_mode (port, ECR_EPP);
460 parport_pc_data_reverse (port);
461 parport_pc_write_control (port, 0x4);
462 got = parport_pc_epp_read_data (port, buf, length, flags);
463 frob_set_mode (port, ECR_PS2);
464
465 return got;
466}
467
468static size_t parport_pc_ecpepp_write_data (struct parport *port,
469 const void *buf, size_t length,
470 int flags)
471{
472 size_t written;
473
474 frob_set_mode (port, ECR_EPP);
475 parport_pc_write_control (port, 0x4);
476 parport_pc_data_forward (port);
477 written = parport_pc_epp_write_data (port, buf, length, flags);
478 frob_set_mode (port, ECR_PS2);
479
480 return written;
481}
482
483static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf,
484 size_t length, int flags)
485{
486 size_t got;
487
488 frob_set_mode (port, ECR_EPP);
489 parport_pc_data_reverse (port);
490 parport_pc_write_control (port, 0x4);
491 got = parport_pc_epp_read_addr (port, buf, length, flags);
492 frob_set_mode (port, ECR_PS2);
493
494 return got;
495}
496
497static size_t parport_pc_ecpepp_write_addr (struct parport *port,
498 const void *buf, size_t length,
499 int flags)
500{
501 size_t written;
502
503 frob_set_mode (port, ECR_EPP);
504 parport_pc_write_control (port, 0x4);
505 parport_pc_data_forward (port);
506 written = parport_pc_epp_write_addr (port, buf, length, flags);
507 frob_set_mode (port, ECR_PS2);
508
509 return written;
510}
511#endif
512
513#ifdef CONFIG_PARPORT_PC_FIFO
514static size_t parport_pc_fifo_write_block_pio (struct parport *port,
515 const void *buf, size_t length)
516{
517 int ret = 0;
518 const unsigned char *bufp = buf;
519 size_t left = length;
520 unsigned long expire = jiffies + port->physport->cad->timeout;
521 const int fifo = FIFO (port);
522 int poll_for = 8;
523 const struct parport_pc_private *priv = port->physport->private_data;
524 const int fifo_depth = priv->fifo_depth;
525
526 port = port->physport;
527
528
529 parport_pc_disable_irq (port);
530
531 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
532
533
534 parport_pc_data_forward (port);
535
536 while (left) {
537 unsigned char byte;
538 unsigned char ecrval = inb (ECONTROL (port));
539 int i = 0;
540
541 if (need_resched() && time_before (jiffies, expire))
542
543 schedule ();
544
545
546 if (port->waithead) {
547 printk (KERN_DEBUG "Somebody wants the port\n");
548 break;
549 }
550
551 if (ecrval & 0x02) {
552
553
554
555 ECR_WRITE (port, ecrval & ~(1<<2));
556 false_alarm:
557 ret = parport_wait_event (port, HZ);
558 if (ret < 0) break;
559 ret = 0;
560 if (!time_before (jiffies, expire)) {
561
562 printk (KERN_DEBUG "FIFO write timed out\n");
563 break;
564 }
565 ecrval = inb (ECONTROL (port));
566 if (!(ecrval & (1<<2))) {
567 if (need_resched() &&
568 time_before (jiffies, expire))
569 schedule ();
570
571 goto false_alarm;
572 }
573
574 continue;
575 }
576
577
578 expire = jiffies + port->cad->timeout;
579
580 poll:
581 if (signal_pending (current))
582 break;
583
584 if (ecrval & 0x01) {
585
586 const int n = left < fifo_depth ? left : fifo_depth;
587 outsb (fifo, bufp, n);
588 bufp += n;
589 left -= n;
590
591
592 if (i < (poll_for - 2)) poll_for--;
593 continue;
594 } else if (i++ < poll_for) {
595 udelay (10);
596 ecrval = inb (ECONTROL (port));
597 goto poll;
598 }
599
600
601 byte = *bufp++;
602 outb (byte, fifo);
603 left--;
604 }
605
606dump_parport_state ("leave fifo_write_block_pio", port);
607 return length - left;
608}
609
610#ifdef HAS_DMA
611static size_t parport_pc_fifo_write_block_dma (struct parport *port,
612 const void *buf, size_t length)
613{
614 int ret = 0;
615 unsigned long dmaflag;
616 size_t left = length;
617 const struct parport_pc_private *priv = port->physport->private_data;
618 struct device *dev = port->physport->dev;
619 dma_addr_t dma_addr, dma_handle;
620 size_t maxlen = 0x10000;
621 unsigned long start = (unsigned long) buf;
622 unsigned long end = (unsigned long) buf + length - 1;
623
624dump_parport_state ("enter fifo_write_block_dma", port);
625 if (end < MAX_DMA_ADDRESS) {
626
627 if ((start ^ end) & ~0xffffUL)
628 maxlen = 0x10000 - (start & 0xffff);
629
630 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
631 DMA_TO_DEVICE);
632 } else {
633
634 maxlen = PAGE_SIZE;
635 dma_addr = priv->dma_handle;
636 dma_handle = 0;
637 }
638
639 port = port->physport;
640
641
642 parport_pc_disable_irq (port);
643
644 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
645
646
647 parport_pc_data_forward (port);
648
649 while (left) {
650 unsigned long expire = jiffies + port->physport->cad->timeout;
651
652 size_t count = left;
653
654 if (count > maxlen)
655 count = maxlen;
656
657 if (!dma_handle)
658 memcpy(priv->dma_buf, buf, count);
659
660 dmaflag = claim_dma_lock();
661 disable_dma(port->dma);
662 clear_dma_ff(port->dma);
663 set_dma_mode(port->dma, DMA_MODE_WRITE);
664 set_dma_addr(port->dma, dma_addr);
665 set_dma_count(port->dma, count);
666
667
668 frob_econtrol (port, 1<<3, 1<<3);
669
670
671 frob_econtrol (port, 1<<2, 0);
672
673 enable_dma(port->dma);
674 release_dma_lock(dmaflag);
675
676
677 left -= count;
678 buf += count;
679 if (dma_handle) dma_addr += count;
680
681
682 false_alarm:
683 ret = parport_wait_event (port, HZ);
684 if (ret < 0) break;
685 ret = 0;
686 if (!time_before (jiffies, expire)) {
687
688 printk (KERN_DEBUG "DMA write timed out\n");
689 break;
690 }
691
692 if (!(inb (ECONTROL (port)) & (1<<2))) {
693 cond_resched();
694
695 goto false_alarm;
696 }
697
698 dmaflag = claim_dma_lock();
699 disable_dma(port->dma);
700 clear_dma_ff(port->dma);
701 count = get_dma_residue(port->dma);
702 release_dma_lock(dmaflag);
703
704 cond_resched();
705
706
707 if (port->waithead) {
708 printk (KERN_DEBUG "Somebody wants the port\n");
709 break;
710 }
711
712
713 buf -= count;
714 left += count;
715 if (dma_handle) dma_addr -= count;
716 }
717
718
719 dmaflag = claim_dma_lock();
720 disable_dma(port->dma);
721 clear_dma_ff(port->dma);
722 left += get_dma_residue(port->dma);
723 release_dma_lock(dmaflag);
724
725
726 frob_econtrol (port, 1<<3, 0);
727
728 if (dma_handle)
729 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
730
731dump_parport_state ("leave fifo_write_block_dma", port);
732 return length - left;
733}
734#endif
735
736static inline size_t parport_pc_fifo_write_block(struct parport *port,
737 const void *buf, size_t length)
738{
739#ifdef HAS_DMA
740 if (port->dma != PARPORT_DMA_NONE)
741 return parport_pc_fifo_write_block_dma (port, buf, length);
742#endif
743 return parport_pc_fifo_write_block_pio (port, buf, length);
744}
745
746
747static size_t parport_pc_compat_write_block_pio (struct parport *port,
748 const void *buf, size_t length,
749 int flags)
750{
751 size_t written;
752 int r;
753 unsigned long expire;
754 const struct parport_pc_private *priv = port->physport->private_data;
755
756
757
758 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
759 return parport_ieee1284_write_compat (port, buf,
760 length, flags);
761
762
763 parport_pc_data_forward (port);
764 parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0);
765 r = change_mode (port, ECR_PPF);
766 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name);
767
768 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
769
770
771 written = parport_pc_fifo_write_block(port, buf, length);
772
773
774
775
776
777
778 expire = jiffies + (priv->fifo_depth * HZ * 4);
779 do {
780
781 r = change_mode (port, ECR_PS2);
782 if (r != -EBUSY) {
783 break;
784 }
785 } while (time_before (jiffies, expire));
786 if (r == -EBUSY) {
787
788 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
789
790
791 frob_set_mode (port, ECR_TST);
792
793
794 for (written -= priv->fifo_depth; ; written++) {
795 if (inb (ECONTROL (port)) & 0x2) {
796
797 break;
798 }
799 outb (0, FIFO (port));
800 }
801
802
803 frob_set_mode (port, ECR_PS2);
804 }
805
806 r = parport_wait_peripheral (port,
807 PARPORT_STATUS_BUSY,
808 PARPORT_STATUS_BUSY);
809 if (r)
810 printk (KERN_DEBUG
811 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
812 port->name, r);
813
814 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
815
816 return written;
817}
818
819
820#ifdef CONFIG_PARPORT_1284
821static size_t parport_pc_ecp_write_block_pio (struct parport *port,
822 const void *buf, size_t length,
823 int flags)
824{
825 size_t written;
826 int r;
827 unsigned long expire;
828 const struct parport_pc_private *priv = port->physport->private_data;
829
830
831
832 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
833 return parport_ieee1284_ecp_write_data (port, buf,
834 length, flags);
835
836
837 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
838
839 parport_frob_control (port,
840 PARPORT_CONTROL_INIT
841 | PARPORT_CONTROL_AUTOFD,
842 PARPORT_CONTROL_INIT
843 | PARPORT_CONTROL_AUTOFD);
844
845
846 r = parport_wait_peripheral (port,
847 PARPORT_STATUS_PAPEROUT,
848 PARPORT_STATUS_PAPEROUT);
849 if (r) {
850 printk (KERN_DEBUG "%s: PError timeout (%d) "
851 "in ecp_write_block_pio\n", port->name, r);
852 }
853 }
854
855
856 parport_pc_data_forward (port);
857 parport_pc_frob_control (port,
858 PARPORT_CONTROL_STROBE |
859 PARPORT_CONTROL_AUTOFD,
860 0);
861 r = change_mode (port, ECR_ECP);
862 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
863 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
864
865
866 written = parport_pc_fifo_write_block(port, buf, length);
867
868
869
870
871
872
873 expire = jiffies + (priv->fifo_depth * (HZ * 4));
874 do {
875
876 r = change_mode (port, ECR_PS2);
877 if (r != -EBUSY) {
878 break;
879 }
880 } while (time_before (jiffies, expire));
881 if (r == -EBUSY) {
882
883 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
884
885
886 frob_set_mode (port, ECR_TST);
887
888
889 for (written -= priv->fifo_depth; ; written++) {
890 if (inb (ECONTROL (port)) & 0x2) {
891
892 break;
893 }
894 outb (0, FIFO (port));
895 }
896
897
898 frob_set_mode (port, ECR_PS2);
899
900
901 parport_pc_data_reverse (port);
902 udelay (5);
903 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
904 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
905 if (r)
906 printk (KERN_DEBUG "%s: PE,1 timeout (%d) "
907 "in ecp_write_block_pio\n", port->name, r);
908
909 parport_frob_control (port,
910 PARPORT_CONTROL_INIT,
911 PARPORT_CONTROL_INIT);
912 r = parport_wait_peripheral (port,
913 PARPORT_STATUS_PAPEROUT,
914 PARPORT_STATUS_PAPEROUT);
915 if (r)
916 printk (KERN_DEBUG "%s: PE,2 timeout (%d) "
917 "in ecp_write_block_pio\n", port->name, r);
918 }
919
920 r = parport_wait_peripheral (port,
921 PARPORT_STATUS_BUSY,
922 PARPORT_STATUS_BUSY);
923 if(r)
924 printk (KERN_DEBUG
925 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
926 port->name, r);
927
928 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
929
930 return written;
931}
932
933#if 0
934static size_t parport_pc_ecp_read_block_pio (struct parport *port,
935 void *buf, size_t length,
936 int flags)
937{
938 size_t left = length;
939 size_t fifofull;
940 int r;
941 const int fifo = FIFO(port);
942 const struct parport_pc_private *priv = port->physport->private_data;
943 const int fifo_depth = priv->fifo_depth;
944 char *bufp = buf;
945
946 port = port->physport;
947DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
948dump_parport_state ("enter fcn", port);
949
950
951
952 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
953 return parport_ieee1284_ecp_read_data (port, buf,
954 length, flags);
955
956 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
957
958
959
960 fifofull = 128;
961 } else {
962 fifofull = fifo_depth;
963 }
964
965
966
967
968 if (length < fifofull)
969 return parport_ieee1284_ecp_read_data (port, buf,
970 length, flags);
971
972 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
973
974
975
976 parport_frob_control (port,
977 PARPORT_CONTROL_AUTOFD
978 | PARPORT_CONTROL_STROBE,
979 PARPORT_CONTROL_AUTOFD);
980 parport_pc_data_reverse (port);
981 udelay (5);
982
983 parport_frob_control (port,
984 PARPORT_CONTROL_INIT,
985 0);
986
987 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
988 if (r) {
989 printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) "
990 "in ecp_read_block_pio\n", port->name, r);
991 return 0;
992 }
993 }
994
995
996
997
998
999
1000 r = change_mode (port, ECR_ECP);
1001 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
1002
1003 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
1004
1005
1006dump_parport_state ("pre 43", port);
1007
1008 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
1009 if (r) {
1010
1011 printk (KERN_DEBUG "PIO read timed out (initial byte)\n");
1012 goto out_no_data;
1013 }
1014
1015 *bufp++ = inb (DATA (port));
1016 left--;
1017dump_parport_state ("43-44", port);
1018
1019 parport_pc_frob_control (port,
1020 PARPORT_CONTROL_AUTOFD,
1021 0);
1022dump_parport_state ("pre 45", port);
1023
1024
1025dump_parport_state ("post 45", port);
1026r = 0;
1027 if (r) {
1028
1029 printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
1030
1031
1032 goto out_no_data;
1033 }
1034
1035 parport_pc_frob_control (port,
1036 PARPORT_CONTROL_AUTOFD,
1037 PARPORT_CONTROL_AUTOFD);
1038
1039
1040dump_parport_state ("rev idle", port);
1041
1042 while (left > fifofull) {
1043 int ret;
1044 unsigned long expire = jiffies + port->cad->timeout;
1045 unsigned char ecrval = inb (ECONTROL (port));
1046
1047 if (need_resched() && time_before (jiffies, expire))
1048
1049 schedule ();
1050
1051
1052
1053
1054
1055
1056
1057 if (ecrval & 0x01) {
1058
1059dump_parport_state ("FIFO empty", port);
1060
1061
1062 if (port->waithead) {
1063 printk (KERN_DEBUG "Somebody wants the port\n");
1064 break;
1065 }
1066
1067
1068 ECR_WRITE (port, ecrval & ~(1<<2));
1069 false_alarm:
1070dump_parport_state ("waiting", port);
1071 ret = parport_wait_event (port, HZ);
1072DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret);
1073 if (ret < 0)
1074 break;
1075 ret = 0;
1076 if (!time_before (jiffies, expire)) {
1077
1078dump_parport_state ("timeout", port);
1079 printk (KERN_DEBUG "PIO read timed out\n");
1080 break;
1081 }
1082 ecrval = inb (ECONTROL (port));
1083 if (!(ecrval & (1<<2))) {
1084 if (need_resched() &&
1085 time_before (jiffies, expire)) {
1086 schedule ();
1087 }
1088 goto false_alarm;
1089 }
1090
1091
1092
1093
1094
1095 continue;
1096 }
1097
1098 if (ecrval & 0x02) {
1099
1100dump_parport_state ("FIFO full", port);
1101 insb (fifo, bufp, fifo_depth);
1102 bufp += fifo_depth;
1103 left -= fifo_depth;
1104 continue;
1105 }
1106
1107DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1108
1109
1110
1111
1112 *bufp++ = inb (fifo);
1113 left--;
1114 }
1115
1116
1117 while (left && !(inb (ECONTROL (port) & 0x01))) {
1118 *bufp++ = inb (fifo);
1119 left--;
1120 }
1121
1122 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1123dump_parport_state ("rev idle2", port);
1124
1125out_no_data:
1126
1127
1128 parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
1129
1130
1131 r = parport_wait_peripheral (port,
1132 PARPORT_STATUS_PAPEROUT,
1133 PARPORT_STATUS_PAPEROUT);
1134 if (r) {
1135 printk (KERN_DEBUG
1136 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1137 port->name, r);
1138 }
1139
1140 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1141
1142
1143 {
1144 int lost = get_fifo_residue (port);
1145 if (lost)
1146
1147 printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1148 port->name, lost);
1149 }
1150
1151dump_parport_state ("fwd idle", port);
1152 return length - left;
1153}
1154#endif
1155#endif
1156#endif
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167static const struct parport_operations parport_pc_ops =
1168{
1169 .write_data = parport_pc_write_data,
1170 .read_data = parport_pc_read_data,
1171
1172 .write_control = parport_pc_write_control,
1173 .read_control = parport_pc_read_control,
1174 .frob_control = parport_pc_frob_control,
1175
1176 .read_status = parport_pc_read_status,
1177
1178 .enable_irq = parport_pc_enable_irq,
1179 .disable_irq = parport_pc_disable_irq,
1180
1181 .data_forward = parport_pc_data_forward,
1182 .data_reverse = parport_pc_data_reverse,
1183
1184 .init_state = parport_pc_init_state,
1185 .save_state = parport_pc_save_state,
1186 .restore_state = parport_pc_restore_state,
1187
1188 .epp_write_data = parport_ieee1284_epp_write_data,
1189 .epp_read_data = parport_ieee1284_epp_read_data,
1190 .epp_write_addr = parport_ieee1284_epp_write_addr,
1191 .epp_read_addr = parport_ieee1284_epp_read_addr,
1192
1193 .ecp_write_data = parport_ieee1284_ecp_write_data,
1194 .ecp_read_data = parport_ieee1284_ecp_read_data,
1195 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1196
1197 .compat_write_data = parport_ieee1284_write_compat,
1198 .nibble_read_data = parport_ieee1284_read_nibble,
1199 .byte_read_data = parport_ieee1284_read_byte,
1200
1201 .owner = THIS_MODULE,
1202};
1203
1204#ifdef CONFIG_PARPORT_PC_SUPERIO
1205
1206static void __devinit show_parconfig_smsc37c669(int io, int key)
1207{
1208 int cr1,cr4,cra,cr23,cr26,cr27,i=0;
1209 static const char *const modes[]={
1210 "SPP and Bidirectional (PS/2)",
1211 "EPP and SPP",
1212 "ECP",
1213 "ECP and EPP" };
1214
1215 outb(key,io);
1216 outb(key,io);
1217 outb(1,io);
1218 cr1=inb(io+1);
1219 outb(4,io);
1220 cr4=inb(io+1);
1221 outb(0x0a,io);
1222 cra=inb(io+1);
1223 outb(0x23,io);
1224 cr23=inb(io+1);
1225 outb(0x26,io);
1226 cr26=inb(io+1);
1227 outb(0x27,io);
1228 cr27=inb(io+1);
1229 outb(0xaa,io);
1230
1231 if (verbose_probing) {
1232 printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1233 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1234 cr1,cr4,cra,cr23,cr26,cr27);
1235
1236
1237
1238
1239 printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1240 "fifo threshold=%d\n", cr23*4,
1241 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-',
1242 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f);
1243 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
1244 (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no");
1245 printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1246 (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03],
1247 (cr4 & 0x40) ? "1.7" : "1.9");
1248 }
1249
1250
1251
1252
1253
1254 if(cr23*4 >=0x100) {
1255 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1256 i++;
1257 if(i==NR_SUPERIOS)
1258 printk(KERN_INFO "Super-IO: too many chips!\n");
1259 else {
1260 int d;
1261 switch (cr23*4) {
1262 case 0x3bc:
1263 superios[i].io = 0x3bc;
1264 superios[i].irq = 7;
1265 break;
1266 case 0x378:
1267 superios[i].io = 0x378;
1268 superios[i].irq = 7;
1269 break;
1270 case 0x278:
1271 superios[i].io = 0x278;
1272 superios[i].irq = 5;
1273 }
1274 d=(cr26 &0x0f);
1275 if((d==1) || (d==3))
1276 superios[i].dma= d;
1277 else
1278 superios[i].dma= PARPORT_DMA_NONE;
1279 }
1280 }
1281}
1282
1283
1284static void __devinit show_parconfig_winbond(int io, int key)
1285{
1286 int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
1287 static const char *const modes[] = {
1288 "Standard (SPP) and Bidirectional(PS/2)",
1289 "EPP-1.9 and SPP",
1290 "ECP",
1291 "ECP and EPP-1.9",
1292 "Standard (SPP)",
1293 "EPP-1.7 and SPP",
1294 "undefined!",
1295 "ECP and EPP-1.7" };
1296 static char *const irqtypes[] = {
1297 "pulsed low, high-Z",
1298 "follows nACK" };
1299
1300
1301
1302
1303 outb(key,io);
1304 outb(key,io);
1305 outb(0x07,io);
1306 outb(0x01,io+1);
1307 outb(0x30,io);
1308 cr30=inb(io+1);
1309 outb(0x60,io);
1310 cr60=inb(io+1);
1311 outb(0x61,io);
1312 cr61=inb(io+1);
1313 outb(0x70,io);
1314 cr70=inb(io+1);
1315 outb(0x74,io);
1316 cr74=inb(io+1);
1317 outb(0xf0,io);
1318 crf0=inb(io+1);
1319 outb(0xaa,io);
1320
1321 if (verbose_probing) {
1322 printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1323 "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0);
1324 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1325 (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f );
1326 if ((cr74 & 0x07) > 3)
1327 printk("dma=none\n");
1328 else
1329 printk("dma=%d\n",cr74 & 0x07);
1330 printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1331 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1332 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]);
1333 }
1334
1335 if(cr30 & 0x01) {
1336 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1337 i++;
1338 if(i==NR_SUPERIOS)
1339 printk(KERN_INFO "Super-IO: too many chips!\n");
1340 else {
1341 superios[i].io = (cr60<<8)|cr61;
1342 superios[i].irq = cr70&0x0f;
1343 superios[i].dma = (((cr74 & 0x07) > 3) ?
1344 PARPORT_DMA_NONE : (cr74 & 0x07));
1345 }
1346 }
1347}
1348
1349static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1350{
1351 const char *type = "unknown";
1352 int id,progif=2;
1353
1354 if (devid == devrev)
1355
1356
1357 return;
1358
1359 id=(devid<<8) | devrev;
1360
1361
1362
1363 if (id == 0x9771) type="83977F/AF";
1364 else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x";
1365 else if (id == 0x9774) type="83977ATF";
1366 else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x";
1367 else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x";
1368 else if ((id & ~0x0f) == 0x5210) type="83627";
1369 else if ((id & ~0x0f) == 0x6010) type="83697HF";
1370 else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;}
1371 else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;}
1372 else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;}
1373 else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;}
1374 else progif=0;
1375
1376 if (verbose_probing)
1377 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
1378 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
1379 efer, key, devid, devrev, oldid, type);
1380
1381 if (progif == 2)
1382 show_parconfig_winbond(efer,key);
1383}
1384
1385static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1386{
1387 const char *type = "unknown";
1388 void (*func)(int io, int key);
1389 int id;
1390
1391 if (devid == devrev)
1392
1393
1394 return;
1395
1396 func=NULL;
1397 id=(devid<<8) | devrev;
1398
1399 if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;}
1400 else if (id==0x6582) type="37c665IR";
1401 else if (devid==0x65) type="37c665GT";
1402 else if (devid==0x66) type="37c666GT";
1403
1404 if (verbose_probing)
1405 printk(KERN_INFO "SMSC chip at EFER=0x%x "
1406 "key=0x%02x devid=%02x devrev=%02x type=%s\n",
1407 efer, key, devid, devrev, type);
1408
1409 if (func)
1410 func(efer,key);
1411}
1412
1413
1414static void __devinit winbond_check(int io, int key)
1415{
1416 int origval, devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1417
1418 if (!request_region(io, 3, __func__))
1419 return;
1420
1421 origval = inb(io);
1422
1423
1424 outb(0x20,io);
1425 x_devid=inb(io+1);
1426 outb(0x21,io);
1427 x_devrev=inb(io+1);
1428 outb(0x09,io);
1429 x_oldid=inb(io+1);
1430
1431 outb(key,io);
1432 outb(key,io);
1433
1434 outb(0x20,io);
1435 devid=inb(io+1);
1436 outb(0x21,io);
1437 devrev=inb(io+1);
1438 outb(0x09,io);
1439 oldid=inb(io+1);
1440 outb(0xaa,io);
1441
1442 outb(origval, io);
1443
1444 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1445 goto out;
1446
1447 decode_winbond(io,key,devid,devrev,oldid);
1448out:
1449 release_region(io, 3);
1450}
1451
1452static void __devinit winbond_check2(int io,int key)
1453{
1454 int origval[3], devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1455
1456 if (!request_region(io, 3, __func__))
1457 return;
1458
1459 origval[0] = inb(io);
1460 origval[1] = inb(io + 1);
1461 origval[2] = inb(io + 2);
1462
1463
1464 outb(0x20,io+2);
1465 x_devid=inb(io+2);
1466 outb(0x21,io+1);
1467 x_devrev=inb(io+2);
1468 outb(0x09,io+1);
1469 x_oldid=inb(io+2);
1470
1471 outb(key,io);
1472
1473 outb(0x20,io+2);
1474 devid=inb(io+2);
1475 outb(0x21,io+1);
1476 devrev=inb(io+2);
1477 outb(0x09,io+1);
1478 oldid=inb(io+2);
1479 outb(0xaa,io);
1480
1481 outb(origval[0], io);
1482 outb(origval[1], io + 1);
1483 outb(origval[2], io + 2);
1484
1485 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1486 goto out;
1487
1488 decode_winbond(io,key,devid,devrev,oldid);
1489out:
1490 release_region(io, 3);
1491}
1492
1493static void __devinit smsc_check(int io, int key)
1494{
1495 int origval, id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
1496
1497 if (!request_region(io, 3, __func__))
1498 return;
1499
1500 origval = inb(io);
1501
1502
1503 outb(0x0d,io);
1504 x_oldid=inb(io+1);
1505 outb(0x0e,io);
1506 x_oldrev=inb(io+1);
1507 outb(0x20,io);
1508 x_id=inb(io+1);
1509 outb(0x21,io);
1510 x_rev=inb(io+1);
1511
1512 outb(key,io);
1513 outb(key,io);
1514
1515 outb(0x0d,io);
1516 oldid=inb(io+1);
1517 outb(0x0e,io);
1518 oldrev=inb(io+1);
1519 outb(0x20,io);
1520 id=inb(io+1);
1521 outb(0x21,io);
1522 rev=inb(io+1);
1523 outb(0xaa,io);
1524
1525 outb(origval, io);
1526
1527 if ((x_id == id) && (x_oldrev == oldrev) &&
1528 (x_oldid == oldid) && (x_rev == rev))
1529 goto out;
1530
1531 decode_smsc(io,key,oldid,oldrev);
1532out:
1533 release_region(io, 3);
1534}
1535
1536
1537static void __devinit detect_and_report_winbond (void)
1538{
1539 if (verbose_probing)
1540 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1541 winbond_check(0x3f0,0x87);
1542 winbond_check(0x370,0x87);
1543 winbond_check(0x2e ,0x87);
1544 winbond_check(0x4e ,0x87);
1545 winbond_check(0x3f0,0x86);
1546 winbond_check2(0x250,0x88);
1547 winbond_check2(0x250,0x89);
1548}
1549
1550static void __devinit detect_and_report_smsc (void)
1551{
1552 if (verbose_probing)
1553 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1554 smsc_check(0x3f0,0x55);
1555 smsc_check(0x370,0x55);
1556 smsc_check(0x3f0,0x44);
1557 smsc_check(0x370,0x44);
1558}
1559
1560static void __devinit detect_and_report_it87(void)
1561{
1562 u16 dev;
1563 u8 origval, r;
1564 if (verbose_probing)
1565 printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
1566 if (!request_region(0x2e, 2, __func__))
1567 return;
1568 origval = inb(0x2e);
1569 outb(0x87, 0x2e);
1570 outb(0x01, 0x2e);
1571 outb(0x55, 0x2e);
1572 outb(0x55, 0x2e);
1573 outb(0x20, 0x2e);
1574 dev = inb(0x2f) << 8;
1575 outb(0x21, 0x2e);
1576 dev |= inb(0x2f);
1577 if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
1578 dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
1579 printk(KERN_INFO "IT%04X SuperIO detected.\n", dev);
1580 outb(0x07, 0x2E);
1581 outb(0x03, 0x2F);
1582 outb(0xF0, 0x2E);
1583 r = inb(0x2f);
1584 outb(0xF0, 0x2E);
1585 outb(r | 8, 0x2F);
1586 outb(0x02, 0x2E);
1587 outb(0x02, 0x2F);
1588 } else {
1589 outb(origval, 0x2e);
1590 }
1591 release_region(0x2e, 2);
1592}
1593#endif
1594
1595static int get_superio_dma (struct parport *p)
1596{
1597 int i=0;
1598 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1599 i++;
1600 if (i!=NR_SUPERIOS)
1601 return superios[i].dma;
1602 return PARPORT_DMA_NONE;
1603}
1604
1605static int get_superio_irq (struct parport *p)
1606{
1607 int i=0;
1608 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1609 i++;
1610 if (i!=NR_SUPERIOS)
1611 return superios[i].irq;
1612 return PARPORT_IRQ_NONE;
1613}
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627static int parport_SPP_supported(struct parport *pb)
1628{
1629 unsigned char r, w;
1630
1631
1632
1633
1634
1635
1636
1637 clear_epp_timeout(pb);
1638
1639
1640 w = 0xc;
1641 outb (w, CONTROL (pb));
1642
1643
1644
1645
1646
1647
1648 r = inb (CONTROL (pb));
1649 if ((r & 0xf) == w) {
1650 w = 0xe;
1651 outb (w, CONTROL (pb));
1652 r = inb (CONTROL (pb));
1653 outb (0xc, CONTROL (pb));
1654 if ((r & 0xf) == w)
1655 return PARPORT_MODE_PCSPP;
1656 }
1657
1658 if (user_specified)
1659
1660
1661 printk (KERN_INFO "parport 0x%lx (WARNING): CTR: "
1662 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1663
1664
1665
1666 w = 0xaa;
1667 parport_pc_write_data (pb, w);
1668 r = parport_pc_read_data (pb);
1669 if (r == w) {
1670 w = 0x55;
1671 parport_pc_write_data (pb, w);
1672 r = parport_pc_read_data (pb);
1673 if (r == w)
1674 return PARPORT_MODE_PCSPP;
1675 }
1676
1677 if (user_specified) {
1678
1679
1680 printk (KERN_INFO "parport 0x%lx (WARNING): DATA: "
1681 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1682 printk (KERN_INFO "parport 0x%lx: You gave this address, "
1683 "but there is probably no parallel port there!\n",
1684 pb->base);
1685 }
1686
1687
1688
1689 if (user_specified)
1690 return PARPORT_MODE_PCSPP;
1691
1692 return 0;
1693}
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708static int parport_ECR_present(struct parport *pb)
1709{
1710 struct parport_pc_private *priv = pb->private_data;
1711 unsigned char r = 0xc;
1712
1713 outb (r, CONTROL (pb));
1714 if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) {
1715 outb (r ^ 0x2, CONTROL (pb));
1716
1717 r = inb (CONTROL (pb));
1718 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2))
1719 goto no_reg;
1720 }
1721
1722 if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1)
1723 goto no_reg;
1724
1725 ECR_WRITE (pb, 0x34);
1726 if (inb (ECONTROL (pb)) != 0x35)
1727 goto no_reg;
1728
1729 priv->ecr = 1;
1730 outb (0xc, CONTROL (pb));
1731
1732
1733 frob_set_mode (pb, ECR_SPP);
1734
1735 return 1;
1736
1737 no_reg:
1738 outb (0xc, CONTROL (pb));
1739 return 0;
1740}
1741
1742#ifdef CONFIG_PARPORT_1284
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760static int parport_PS2_supported(struct parport *pb)
1761{
1762 int ok = 0;
1763
1764 clear_epp_timeout(pb);
1765
1766
1767 parport_pc_data_reverse (pb);
1768
1769 parport_pc_write_data(pb, 0x55);
1770 if (parport_pc_read_data(pb) != 0x55) ok++;
1771
1772 parport_pc_write_data(pb, 0xaa);
1773 if (parport_pc_read_data(pb) != 0xaa) ok++;
1774
1775
1776 parport_pc_data_forward (pb);
1777
1778 if (ok) {
1779 pb->modes |= PARPORT_MODE_TRISTATE;
1780 } else {
1781 struct parport_pc_private *priv = pb->private_data;
1782 priv->ctr_writable &= ~0x20;
1783 }
1784
1785 return ok;
1786}
1787
1788#ifdef CONFIG_PARPORT_PC_FIFO
1789static int parport_ECP_supported(struct parport *pb)
1790{
1791 int i;
1792 int config, configb;
1793 int pword;
1794 struct parport_pc_private *priv = pb->private_data;
1795
1796 static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 };
1797
1798
1799 if (!priv->ecr)
1800 return 0;
1801
1802
1803 ECR_WRITE (pb, ECR_SPP << 5);
1804 ECR_WRITE (pb, ECR_TST << 5);
1805 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++)
1806 outb (0xaa, FIFO (pb));
1807
1808
1809
1810
1811
1812 if (i == 1024) {
1813 ECR_WRITE (pb, ECR_SPP << 5);
1814 return 0;
1815 }
1816
1817 priv->fifo_depth = i;
1818 if (verbose_probing)
1819 printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
1820
1821
1822 frob_econtrol (pb, 1<<2, 1<<2);
1823 frob_econtrol (pb, 1<<2, 0);
1824 for (i = 1; i <= priv->fifo_depth; i++) {
1825 inb (FIFO (pb));
1826 udelay (50);
1827 if (inb (ECONTROL (pb)) & (1<<2))
1828 break;
1829 }
1830
1831 if (i <= priv->fifo_depth) {
1832 if (verbose_probing)
1833 printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
1834 pb->base, i);
1835 } else
1836
1837
1838 i = 0;
1839
1840 priv->writeIntrThreshold = i;
1841
1842
1843 frob_set_mode (pb, ECR_PS2);
1844 parport_pc_data_reverse (pb);
1845 frob_set_mode (pb, ECR_TST);
1846 frob_econtrol (pb, 1<<2, 1<<2);
1847 frob_econtrol (pb, 1<<2, 0);
1848 for (i = 1; i <= priv->fifo_depth; i++) {
1849 outb (0xaa, FIFO (pb));
1850 if (inb (ECONTROL (pb)) & (1<<2))
1851 break;
1852 }
1853
1854 if (i <= priv->fifo_depth) {
1855 if (verbose_probing)
1856 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1857 pb->base, i);
1858 } else
1859
1860 i = 0;
1861
1862 priv->readIntrThreshold = i;
1863
1864 ECR_WRITE (pb, ECR_SPP << 5);
1865 ECR_WRITE (pb, 0xf4);
1866 config = inb (CONFIGA (pb));
1867 pword = (config >> 4) & 0x7;
1868 switch (pword) {
1869 case 0:
1870 pword = 2;
1871 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1872 pb->base);
1873 break;
1874 case 2:
1875 pword = 4;
1876 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1877 pb->base);
1878 break;
1879 default:
1880 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n",
1881 pb->base);
1882
1883 case 1:
1884 pword = 1;
1885 }
1886 priv->pword = pword;
1887
1888 if (verbose_probing) {
1889 printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword);
1890
1891 printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1892 config & 0x80 ? "Level" : "Pulses");
1893
1894 configb = inb (CONFIGB (pb));
1895 printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1896 pb->base, config, configb);
1897 printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1898 if ((configb >>3) & 0x07)
1899 printk("%d",intrline[(configb >>3) & 0x07]);
1900 else
1901 printk("<none or set by other means>");
1902 printk (" dma=");
1903 if( (configb & 0x03 ) == 0x00)
1904 printk("<none or set by other means>\n");
1905 else
1906 printk("%d\n",configb & 0x07);
1907 }
1908
1909
1910 frob_set_mode (pb, ECR_SPP);
1911
1912 return 1;
1913}
1914#endif
1915
1916static int parport_ECPPS2_supported(struct parport *pb)
1917{
1918 const struct parport_pc_private *priv = pb->private_data;
1919 int result;
1920 unsigned char oecr;
1921
1922 if (!priv->ecr)
1923 return 0;
1924
1925 oecr = inb (ECONTROL (pb));
1926 ECR_WRITE (pb, ECR_PS2 << 5);
1927 result = parport_PS2_supported(pb);
1928 ECR_WRITE (pb, oecr);
1929 return result;
1930}
1931
1932
1933
1934static int parport_EPP_supported(struct parport *pb)
1935{
1936 const struct parport_pc_private *priv = pb->private_data;
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952 if (!clear_epp_timeout(pb)) {
1953 return 0;
1954 }
1955
1956
1957 if (priv->ecr) {
1958 unsigned char i;
1959 for (i = 0x00; i < 0x80; i += 0x20) {
1960 ECR_WRITE (pb, i);
1961 if (clear_epp_timeout (pb)) {
1962
1963 return 0;
1964 }
1965 }
1966 }
1967
1968 pb->modes |= PARPORT_MODE_EPP;
1969
1970
1971 pb->ops->epp_read_data = parport_pc_epp_read_data;
1972 pb->ops->epp_write_data = parport_pc_epp_write_data;
1973 pb->ops->epp_read_addr = parport_pc_epp_read_addr;
1974 pb->ops->epp_write_addr = parport_pc_epp_write_addr;
1975
1976 return 1;
1977}
1978
1979static int parport_ECPEPP_supported(struct parport *pb)
1980{
1981 struct parport_pc_private *priv = pb->private_data;
1982 int result;
1983 unsigned char oecr;
1984
1985 if (!priv->ecr) {
1986 return 0;
1987 }
1988
1989 oecr = inb (ECONTROL (pb));
1990
1991 ECR_WRITE (pb, 0x80);
1992 outb (0x04, CONTROL (pb));
1993 result = parport_EPP_supported(pb);
1994
1995 ECR_WRITE (pb, oecr);
1996
1997 if (result) {
1998
1999 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
2000 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
2001 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
2002 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
2003 }
2004
2005 return result;
2006}
2007
2008#else
2009
2010
2011static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
2012#ifdef CONFIG_PARPORT_PC_FIFO
2013static int parport_ECP_supported(struct parport *pb) { return 0; }
2014#endif
2015static int __devinit parport_EPP_supported(struct parport *pb) { return 0; }
2016static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;}
2017static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
2018
2019#endif
2020
2021
2022
2023
2024static int programmable_irq_support(struct parport *pb)
2025{
2026 int irq, intrLine;
2027 unsigned char oecr = inb (ECONTROL (pb));
2028 static const int lookup[8] = {
2029 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
2030 };
2031
2032 ECR_WRITE (pb, ECR_CNF << 5);
2033
2034 intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07;
2035 irq = lookup[intrLine];
2036
2037 ECR_WRITE (pb, oecr);
2038 return irq;
2039}
2040
2041static int irq_probe_ECP(struct parport *pb)
2042{
2043 int i;
2044 unsigned long irqs;
2045
2046 irqs = probe_irq_on();
2047
2048 ECR_WRITE (pb, ECR_SPP << 5);
2049 ECR_WRITE (pb, (ECR_TST << 5) | 0x04);
2050 ECR_WRITE (pb, ECR_TST << 5);
2051
2052
2053 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++)
2054 outb (0xaa, FIFO (pb));
2055
2056 pb->irq = probe_irq_off(irqs);
2057 ECR_WRITE (pb, ECR_SPP << 5);
2058
2059 if (pb->irq <= 0)
2060 pb->irq = PARPORT_IRQ_NONE;
2061
2062 return pb->irq;
2063}
2064
2065
2066
2067
2068
2069static int irq_probe_EPP(struct parport *pb)
2070{
2071#ifndef ADVANCED_DETECT
2072 return PARPORT_IRQ_NONE;
2073#else
2074 int irqs;
2075 unsigned char oecr;
2076
2077 if (pb->modes & PARPORT_MODE_PCECR)
2078 oecr = inb (ECONTROL (pb));
2079
2080 irqs = probe_irq_on();
2081
2082 if (pb->modes & PARPORT_MODE_PCECR)
2083 frob_econtrol (pb, 0x10, 0x10);
2084
2085 clear_epp_timeout(pb);
2086 parport_pc_frob_control (pb, 0x20, 0x20);
2087 parport_pc_frob_control (pb, 0x10, 0x10);
2088 clear_epp_timeout(pb);
2089
2090
2091
2092
2093 parport_pc_read_epp(pb);
2094 udelay(20);
2095
2096 pb->irq = probe_irq_off (irqs);
2097 if (pb->modes & PARPORT_MODE_PCECR)
2098 ECR_WRITE (pb, oecr);
2099 parport_pc_write_control(pb, 0xc);
2100
2101 if (pb->irq <= 0)
2102 pb->irq = PARPORT_IRQ_NONE;
2103
2104 return pb->irq;
2105#endif
2106}
2107
2108static int irq_probe_SPP(struct parport *pb)
2109{
2110
2111 return PARPORT_IRQ_NONE;
2112}
2113
2114
2115
2116
2117
2118
2119
2120
2121static int parport_irq_probe(struct parport *pb)
2122{
2123 struct parport_pc_private *priv = pb->private_data;
2124
2125 if (priv->ecr) {
2126 pb->irq = programmable_irq_support(pb);
2127
2128 if (pb->irq == PARPORT_IRQ_NONE)
2129 pb->irq = irq_probe_ECP(pb);
2130 }
2131
2132 if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
2133 (pb->modes & PARPORT_MODE_EPP))
2134 pb->irq = irq_probe_EPP(pb);
2135
2136 clear_epp_timeout(pb);
2137
2138 if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
2139 pb->irq = irq_probe_EPP(pb);
2140
2141 clear_epp_timeout(pb);
2142
2143 if (pb->irq == PARPORT_IRQ_NONE)
2144 pb->irq = irq_probe_SPP(pb);
2145
2146 if (pb->irq == PARPORT_IRQ_NONE)
2147 pb->irq = get_superio_irq(pb);
2148
2149 return pb->irq;
2150}
2151
2152
2153
2154
2155static int programmable_dma_support (struct parport *p)
2156{
2157 unsigned char oecr = inb (ECONTROL (p));
2158 int dma;
2159
2160 frob_set_mode (p, ECR_CNF);
2161
2162 dma = inb (CONFIGB(p)) & 0x07;
2163
2164
2165 if ((dma & 0x03) == 0)
2166 dma = PARPORT_DMA_NONE;
2167
2168 ECR_WRITE (p, oecr);
2169 return dma;
2170}
2171
2172static int parport_dma_probe (struct parport *p)
2173{
2174 const struct parport_pc_private *priv = p->private_data;
2175 if (priv->ecr)
2176 p->dma = programmable_dma_support(p);
2177 if (p->dma == PARPORT_DMA_NONE) {
2178
2179
2180
2181 p->dma = get_superio_dma(p);
2182 }
2183
2184 return p->dma;
2185}
2186
2187
2188
2189static LIST_HEAD(ports_list);
2190static DEFINE_SPINLOCK(ports_lock);
2191
2192struct parport *parport_pc_probe_port(unsigned long int base,
2193 unsigned long int base_hi,
2194 int irq, int dma,
2195 struct device *dev,
2196 int irqflags)
2197{
2198 struct parport_pc_private *priv;
2199 struct parport_operations *ops;
2200 struct parport *p;
2201 int probedirq = PARPORT_IRQ_NONE;
2202 struct resource *base_res;
2203 struct resource *ECR_res = NULL;
2204 struct resource *EPP_res = NULL;
2205 struct platform_device *pdev = NULL;
2206
2207 if (!dev) {
2208
2209
2210 pdev = platform_device_register_simple("parport_pc",
2211 base, NULL, 0);
2212 if (IS_ERR(pdev))
2213 return NULL;
2214 dev = &pdev->dev;
2215
2216 dev->coherent_dma_mask = DMA_BIT_MASK(24);
2217 dev->dma_mask = &dev->coherent_dma_mask;
2218 }
2219
2220 ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
2221 if (!ops)
2222 goto out1;
2223
2224 priv = kmalloc(sizeof(struct parport_pc_private), GFP_KERNEL);
2225 if (!priv)
2226 goto out2;
2227
2228
2229 p = parport_register_port(base, irq, dma, ops);
2230 if (!p)
2231 goto out3;
2232
2233 base_res = request_region(base, 3, p->name);
2234 if (!base_res)
2235 goto out4;
2236
2237 memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations));
2238 priv->ctr = 0xc;
2239 priv->ctr_writable = ~0x10;
2240 priv->ecr = 0;
2241 priv->fifo_depth = 0;
2242 priv->dma_buf = NULL;
2243 priv->dma_handle = 0;
2244 INIT_LIST_HEAD(&priv->list);
2245 priv->port = p;
2246
2247 p->dev = dev;
2248 p->base_hi = base_hi;
2249 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2250 p->private_data = priv;
2251
2252 if (base_hi) {
2253 ECR_res = request_region(base_hi, 3, p->name);
2254 if (ECR_res)
2255 parport_ECR_present(p);
2256 }
2257
2258 if (base != 0x3bc) {
2259 EPP_res = request_region(base+0x3, 5, p->name);
2260 if (EPP_res)
2261 if (!parport_EPP_supported(p))
2262 parport_ECPEPP_supported(p);
2263 }
2264 if (!parport_SPP_supported (p))
2265
2266 goto out5;
2267 if (priv->ecr)
2268 parport_ECPPS2_supported(p);
2269 else
2270 parport_PS2_supported(p);
2271
2272 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
2273
2274 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2275 if (p->base_hi && priv->ecr)
2276 printk(" (0x%lx)", p->base_hi);
2277 if (p->irq == PARPORT_IRQ_AUTO) {
2278 p->irq = PARPORT_IRQ_NONE;
2279 parport_irq_probe(p);
2280 } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2281 p->irq = PARPORT_IRQ_NONE;
2282 parport_irq_probe(p);
2283 probedirq = p->irq;
2284 p->irq = PARPORT_IRQ_NONE;
2285 }
2286 if (p->irq != PARPORT_IRQ_NONE) {
2287 printk(", irq %d", p->irq);
2288 priv->ctr_writable |= 0x10;
2289
2290 if (p->dma == PARPORT_DMA_AUTO) {
2291 p->dma = PARPORT_DMA_NONE;
2292 parport_dma_probe(p);
2293 }
2294 }
2295 if (p->dma == PARPORT_DMA_AUTO)
2296
2297 p->dma = PARPORT_DMA_NONE;
2298
2299#ifdef CONFIG_PARPORT_PC_FIFO
2300 if (parport_ECP_supported(p) &&
2301 p->dma != PARPORT_DMA_NOFIFO &&
2302 priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2303 p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
2304 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2305#ifdef CONFIG_PARPORT_1284
2306 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2307
2308
2309#endif
2310 if (p->dma != PARPORT_DMA_NONE) {
2311 printk(", dma %d", p->dma);
2312 p->modes |= PARPORT_MODE_DMA;
2313 }
2314 else printk(", using FIFO");
2315 }
2316 else
2317
2318 p->dma = PARPORT_DMA_NONE;
2319#endif
2320
2321 printk(" [");
2322#define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2323 {
2324 int f = 0;
2325 printmode(PCSPP);
2326 printmode(TRISTATE);
2327 printmode(COMPAT)
2328 printmode(EPP);
2329 printmode(ECP);
2330 printmode(DMA);
2331 }
2332#undef printmode
2333#ifndef CONFIG_PARPORT_1284
2334 printk ("(,...)");
2335#endif
2336 printk("]\n");
2337 if (probedirq != PARPORT_IRQ_NONE)
2338 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2339
2340
2341 if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
2342 release_region(base_hi, 3);
2343 ECR_res = NULL;
2344 }
2345
2346 if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
2347 release_region(base+3, 5);
2348 EPP_res = NULL;
2349 }
2350 if (p->irq != PARPORT_IRQ_NONE) {
2351 if (request_irq(p->irq, parport_irq_handler,
2352 irqflags, p->name, p)) {
2353 printk (KERN_WARNING "%s: irq %d in use, "
2354 "resorting to polled operation\n",
2355 p->name, p->irq);
2356 p->irq = PARPORT_IRQ_NONE;
2357 p->dma = PARPORT_DMA_NONE;
2358 }
2359
2360#ifdef CONFIG_PARPORT_PC_FIFO
2361#ifdef HAS_DMA
2362 if (p->dma != PARPORT_DMA_NONE) {
2363 if (request_dma (p->dma, p->name)) {
2364 printk (KERN_WARNING "%s: dma %d in use, "
2365 "resorting to PIO operation\n",
2366 p->name, p->dma);
2367 p->dma = PARPORT_DMA_NONE;
2368 } else {
2369 priv->dma_buf =
2370 dma_alloc_coherent(dev,
2371 PAGE_SIZE,
2372 &priv->dma_handle,
2373 GFP_KERNEL);
2374 if (! priv->dma_buf) {
2375 printk (KERN_WARNING "%s: "
2376 "cannot get buffer for DMA, "
2377 "resorting to PIO operation\n",
2378 p->name);
2379 free_dma(p->dma);
2380 p->dma = PARPORT_DMA_NONE;
2381 }
2382 }
2383 }
2384#endif
2385#endif
2386 }
2387
2388
2389 if (priv->ecr)
2390
2391
2392
2393
2394 ECR_WRITE (p, 0x34);
2395
2396 parport_pc_write_data(p, 0);
2397 parport_pc_data_forward (p);
2398
2399
2400
2401
2402 spin_lock(&ports_lock);
2403 list_add(&priv->list, &ports_list);
2404 spin_unlock(&ports_lock);
2405 parport_announce_port (p);
2406
2407 return p;
2408
2409out5:
2410 if (ECR_res)
2411 release_region(base_hi, 3);
2412 if (EPP_res)
2413 release_region(base+0x3, 5);
2414 release_region(base, 3);
2415out4:
2416 parport_put_port(p);
2417out3:
2418 kfree (priv);
2419out2:
2420 kfree (ops);
2421out1:
2422 if (pdev)
2423 platform_device_unregister(pdev);
2424 return NULL;
2425}
2426
2427EXPORT_SYMBOL (parport_pc_probe_port);
2428
2429void parport_pc_unregister_port (struct parport *p)
2430{
2431 struct parport_pc_private *priv = p->private_data;
2432 struct parport_operations *ops = p->ops;
2433
2434 parport_remove_port(p);
2435 spin_lock(&ports_lock);
2436 list_del_init(&priv->list);
2437 spin_unlock(&ports_lock);
2438#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2439 if (p->dma != PARPORT_DMA_NONE)
2440 free_dma(p->dma);
2441#endif
2442 if (p->irq != PARPORT_IRQ_NONE)
2443 free_irq(p->irq, p);
2444 release_region(p->base, 3);
2445 if (p->size > 3)
2446 release_region(p->base + 3, p->size - 3);
2447 if (p->modes & PARPORT_MODE_ECP)
2448 release_region(p->base_hi, 3);
2449#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
2450 if (priv->dma_buf)
2451 dma_free_coherent(p->physport->dev, PAGE_SIZE,
2452 priv->dma_buf,
2453 priv->dma_handle);
2454#endif
2455 kfree (p->private_data);
2456 parport_put_port(p);
2457 kfree (ops);
2458}
2459
2460EXPORT_SYMBOL (parport_pc_unregister_port);
2461
2462#ifdef CONFIG_PCI
2463
2464
2465static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
2466 int autodma,
2467 const struct parport_pc_via_data *via)
2468{
2469 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2470 struct resource *base_res;
2471 u32 ite8872set;
2472 u32 ite8872_lpt, ite8872_lpthi;
2473 u8 ite8872_irq, type;
2474 int irq;
2475 int i;
2476
2477 DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n");
2478
2479
2480 for(i = 0; i < 5; i++) {
2481 base_res = request_region(inta_addr[i], 32, "it887x");
2482 if (base_res) {
2483 int test;
2484 pci_write_config_dword (pdev, 0x60,
2485 0xe5000000 | inta_addr[i]);
2486 pci_write_config_dword (pdev, 0x78,
2487 0x00000000 | inta_addr[i]);
2488 test = inb (inta_addr[i]);
2489 if (test != 0xff) break;
2490 release_region(inta_addr[i], 0x8);
2491 }
2492 }
2493 if(i >= 5) {
2494 printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
2495 return 0;
2496 }
2497
2498 type = inb (inta_addr[i] + 0x18);
2499 type &= 0x0f;
2500
2501 switch (type) {
2502 case 0x2:
2503 printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n");
2504 ite8872set = 0x64200000;
2505 break;
2506 case 0xa:
2507 printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n");
2508 ite8872set = 0x64200000;
2509 break;
2510 case 0xe:
2511 printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
2512 ite8872set = 0x64e00000;
2513 break;
2514 case 0x6:
2515 printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n");
2516 return 0;
2517 case 0x8:
2518 DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
2519 return 0;
2520 default:
2521 printk (KERN_INFO "parport_pc: unknown ITE887x\n");
2522 printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' "
2523 "output to Rich.Liu@ite.com.tw\n");
2524 return 0;
2525 }
2526
2527 pci_read_config_byte (pdev, 0x3c, &ite8872_irq);
2528 pci_read_config_dword (pdev, 0x1c, &ite8872_lpt);
2529 ite8872_lpt &= 0x0000ff00;
2530 pci_read_config_dword (pdev, 0x20, &ite8872_lpthi);
2531 ite8872_lpthi &= 0x0000ff00;
2532 pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2533 pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2534 pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2535
2536
2537 pci_write_config_dword (pdev, 0x9c,
2538 ite8872set | (ite8872_irq * 0x11111));
2539
2540 DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2541 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
2542 ite8872_lpt);
2543 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
2544 ite8872_lpthi);
2545
2546
2547 irq = ite8872_irq;
2548 if (autoirq != PARPORT_IRQ_AUTO)
2549 irq = PARPORT_IRQ_NONE;
2550
2551
2552
2553
2554 release_resource(base_res);
2555 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
2556 irq, PARPORT_DMA_NONE, &pdev->dev, 0)) {
2557 printk (KERN_INFO
2558 "parport_pc: ITE 8872 parallel port: io=0x%X",
2559 ite8872_lpt);
2560 if (irq != PARPORT_IRQ_NONE)
2561 printk (", irq=%d", irq);
2562 printk ("\n");
2563 return 1;
2564 }
2565
2566 return 0;
2567}
2568
2569
2570
2571static int __devinitdata parport_init_mode = 0;
2572
2573
2574static struct parport_pc_via_data via_686a_data __devinitdata = {
2575 0x51,
2576 0x50,
2577 0x85,
2578 0x02,
2579 0xE2,
2580 0xF0,
2581 0xE6
2582};
2583static struct parport_pc_via_data via_8231_data __devinitdata = {
2584 0x45,
2585 0x44,
2586 0x50,
2587 0x04,
2588 0xF2,
2589 0xFA,
2590 0xF6
2591};
2592
2593static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
2594 int autodma,
2595 const struct parport_pc_via_data *via)
2596{
2597 u8 tmp, tmp2, siofunc;
2598 u8 ppcontrol = 0;
2599 int dma, irq;
2600 unsigned port1, port2;
2601 unsigned have_epp = 0;
2602
2603 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
2604
2605 switch(parport_init_mode)
2606 {
2607 case 1:
2608 printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
2609 siofunc = VIA_FUNCTION_PARPORT_SPP;
2610 break;
2611 case 2:
2612 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
2613 siofunc = VIA_FUNCTION_PARPORT_SPP;
2614 ppcontrol = VIA_PARPORT_BIDIR;
2615 break;
2616 case 3:
2617 printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
2618 siofunc = VIA_FUNCTION_PARPORT_EPP;
2619 ppcontrol = VIA_PARPORT_BIDIR;
2620 have_epp = 1;
2621 break;
2622 case 4:
2623 printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
2624 siofunc = VIA_FUNCTION_PARPORT_ECP;
2625 ppcontrol = VIA_PARPORT_BIDIR;
2626 break;
2627 case 5:
2628 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
2629 siofunc = VIA_FUNCTION_PARPORT_ECP;
2630 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
2631 have_epp = 1;
2632 break;
2633 default:
2634 printk(KERN_DEBUG "parport_pc: probing current configuration\n");
2635 siofunc = VIA_FUNCTION_PROBE;
2636 break;
2637 }
2638
2639
2640
2641 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2642 tmp |= via->via_pci_superio_config_data;
2643 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2644
2645
2646 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2647 tmp = inb (VIA_CONFIG_DATA);
2648
2649 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2650 tmp2 = inb (VIA_CONFIG_DATA);
2651 if (siofunc == VIA_FUNCTION_PROBE)
2652 {
2653 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
2654 ppcontrol = tmp2;
2655 }
2656 else
2657 {
2658 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2659 tmp |= siofunc;
2660 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2661 outb(tmp, VIA_CONFIG_DATA);
2662 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2663 tmp2 |= ppcontrol;
2664 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2665 outb(tmp2, VIA_CONFIG_DATA);
2666 }
2667
2668
2669 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2670 port1 = inb(VIA_CONFIG_DATA) << 2;
2671
2672 printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1);
2673 if ((port1 == 0x3BC) && have_epp)
2674 {
2675 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2676 outb((0x378 >> 2), VIA_CONFIG_DATA);
2677 printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n");
2678 port1 = 0x378;
2679 }
2680
2681
2682
2683
2684 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2685 tmp &= ~via->via_pci_superio_config_data;
2686 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2687
2688 if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
2689 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
2690 return 0;
2691 }
2692
2693
2694 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
2695 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
2696
2697 if (siofunc == VIA_FUNCTION_PARPORT_ECP)
2698 {
2699
2700 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
2701 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
2702 }
2703 else
2704
2705 dma = PARPORT_DMA_NONE;
2706
2707
2708 if (autoirq == PARPORT_IRQ_NONE) {
2709 irq = PARPORT_IRQ_NONE;
2710 dma = PARPORT_DMA_NONE;
2711 }
2712 if (autodma == PARPORT_DMA_NONE)
2713 dma = PARPORT_DMA_NONE;
2714
2715 switch (port1) {
2716 case 0x3bc: port2 = 0x7bc; break;
2717 case 0x378: port2 = 0x778; break;
2718 case 0x278: port2 = 0x678; break;
2719 default:
2720 printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
2721 port1);
2722 return 0;
2723 }
2724
2725
2726 switch (irq) {
2727 case 0:
2728 case 2:
2729 case 8:
2730 case 13:
2731 irq = PARPORT_IRQ_NONE;
2732 break;
2733
2734 default:
2735 break;
2736 }
2737
2738
2739 if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev, 0)) {
2740 printk (KERN_INFO
2741 "parport_pc: VIA parallel port: io=0x%X", port1);
2742 if (irq != PARPORT_IRQ_NONE)
2743 printk (", irq=%d", irq);
2744 if (dma != PARPORT_DMA_NONE)
2745 printk (", dma=%d", dma);
2746 printk ("\n");
2747 return 1;
2748 }
2749
2750 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
2751 port1, irq, dma);
2752 return 0;
2753}
2754
2755
2756enum parport_pc_sio_types {
2757 sio_via_686a = 0,
2758 sio_via_8231,
2759 sio_ite_8872,
2760 last_sio
2761};
2762
2763
2764static struct parport_pc_superio {
2765 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
2766 const struct parport_pc_via_data *via);
2767 const struct parport_pc_via_data *via;
2768} parport_pc_superio_info[] __devinitdata = {
2769 { sio_via_probe, &via_686a_data, },
2770 { sio_via_probe, &via_8231_data, },
2771 { sio_ite_8872_probe, NULL, },
2772};
2773
2774enum parport_pc_pci_cards {
2775 siig_1p_10x = last_sio,
2776 siig_2p_10x,
2777 siig_1p_20x,
2778 siig_2p_20x,
2779 lava_parallel,
2780 lava_parallel_dual_a,
2781 lava_parallel_dual_b,
2782 boca_ioppar,
2783 plx_9050,
2784 timedia_4078a,
2785 timedia_4079h,
2786 timedia_4085h,
2787 timedia_4088a,
2788 timedia_4089a,
2789 timedia_4095a,
2790 timedia_4096a,
2791 timedia_4078u,
2792 timedia_4079a,
2793 timedia_4085u,
2794 timedia_4079r,
2795 timedia_4079s,
2796 timedia_4079d,
2797 timedia_4079e,
2798 timedia_4079f,
2799 timedia_9079a,
2800 timedia_9079b,
2801 timedia_9079c,
2802 timedia_4006a,
2803 timedia_4014,
2804 timedia_4008a,
2805 timedia_4018,
2806 timedia_9018a,
2807 syba_2p_epp,
2808 syba_1p_ecp,
2809 titan_010l,
2810 titan_1284p1,
2811 titan_1284p2,
2812 avlab_1p,
2813 avlab_2p,
2814 oxsemi_952,
2815 oxsemi_954,
2816 oxsemi_840,
2817 oxsemi_pcie_pport,
2818 aks_0100,
2819 mobility_pp,
2820 netmos_9705,
2821 netmos_9715,
2822 netmos_9755,
2823 netmos_9805,
2824 netmos_9815,
2825 quatech_sppxp100,
2826};
2827
2828
2829
2830
2831static struct parport_pc_pci {
2832 int numports;
2833 struct {
2834
2835 int lo;
2836 int hi;
2837
2838 } addr[4];
2839
2840
2841
2842
2843 int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
2844
2845
2846
2847 void (*postinit_hook) (struct pci_dev *pdev, int failed);
2848} cards[] = {
2849 { 1, { { 2, 3 }, } },
2850 { 2, { { 2, 3 }, { 4, 5 }, } },
2851 { 1, { { 0, 1 }, } },
2852 { 2, { { 0, 1 }, { 2, 3 }, } },
2853 { 1, { { 0, -1 }, } },
2854 { 1, { { 0, -1 }, } },
2855 { 1, { { 0, -1 }, } },
2856 { 1, { { 0, -1 }, } },
2857 { 2, { { 4, -1 }, { 5, -1 }, } },
2858 { 1, { { 2, -1 }, } },
2859 { 1, { { 2, 3 }, } },
2860 { 2, { { 2, -1 }, { 4, -1 }, } },
2861 { 2, { { 2, 3 }, { 4, 5 }, } },
2862 { 2, { { 2, 3 }, { 4, 5 }, } },
2863 { 2, { { 2, 3 }, { 4, 5 }, } },
2864 { 2, { { 2, 3 }, { 4, 5 }, } },
2865 { 1, { { 2, -1 }, } },
2866 { 1, { { 2, 3 }, } },
2867 { 2, { { 2, -1 }, { 4, -1 }, } },
2868 { 1, { { 2, 3 }, } },
2869 { 1, { { 2, 3 }, } },
2870 { 1, { { 2, 3 }, } },
2871 { 1, { { 2, 3 }, } },
2872 { 1, { { 2, 3 }, } },
2873 { 1, { { 2, 3 }, } },
2874 { 1, { { 2, 3 }, } },
2875 { 1, { { 2, 3 }, } },
2876 { 1, { { 0, -1 }, } },
2877 { 2, { { 0, -1 }, { 2, -1 }, } },
2878 { 1, { { 0, 1 }, } },
2879 { 2, { { 0, 1 }, { 2, 3 }, } },
2880 { 2, { { 0, 1 }, { 2, 3 }, } },
2881
2882
2883 { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2884 { 1, { { 0, 0x078 }, } },
2885 { 1, { { 3, -1 }, } },
2886 { 1, { { 0, 1 }, } },
2887 { 2, { { 0, 1 }, { 2, 3 }, } },
2888 { 1, { { 0, 1}, } },
2889 { 2, { { 0, 1}, { 2, 3 },} },
2890
2891
2892 { 1, { { 0, 1 }, } },
2893 { 1, { { 0, -1 }, } },
2894 { 1, { { 0, 1 }, } },
2895 { 1, { { 0, 1 }, } },
2896 { 1, { { 0, -1 }, } },
2897 { 1, { { 0, 1 }, } },
2898 { 1, { { 0, -1 }, } },
2899 { 2, { { 0, 1 }, { 2, 3 },} },
2900 { 2, { { 0, 1 }, { 2, 3 },} },
2901 { 1, { { 0, -1 }, } },
2902 { 2, { { 0, -1 }, { 2, -1 }, } },
2903 { 1, { { 0, 1 }, } },
2904};
2905
2906static const struct pci_device_id parport_pc_pci_tbl[] = {
2907
2908 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2909 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
2910 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
2911 PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
2912
2913
2914 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2915 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2916 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2917 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2918 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2919 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2920 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2921 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2922 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2923 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2924 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2925 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2926 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2927 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2928 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2929 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2930 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2931 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 },
2932
2933 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2934 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2935 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2936 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2937 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2938 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2939 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2940 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2941 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2942 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2943 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2944 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2945 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2946 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2947 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2948 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2949 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
2950 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
2951 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
2952 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
2953 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
2954 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
2955 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
2956 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
2957 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
2958 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
2959 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2960 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
2961 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
2962 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
2963 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2964
2965 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
2966 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
2967 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
2968 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
2969 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
2970 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
2971 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
2972 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
2973 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840,
2974 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2975 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840_G,
2976 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2977 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0,
2978 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2979 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0_G,
2980 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2981 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1,
2982 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2983 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_G,
2984 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2985 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_U,
2986 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2987 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU,
2988 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
2989 { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
2990 PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
2991 { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
2992
2993 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
2994 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
2995 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
2996 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
2997 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
2998 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
2999 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
3000 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
3001 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
3002 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
3003
3004 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
3005 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
3006 { 0, }
3007};
3008MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
3009
3010struct pci_parport_data {
3011 int num;
3012 struct parport *ports[2];
3013};
3014
3015static int parport_pc_pci_probe (struct pci_dev *dev,
3016 const struct pci_device_id *id)
3017{
3018 int err, count, n, i = id->driver_data;
3019 struct pci_parport_data *data;
3020
3021 if (i < last_sio)
3022
3023 return 0;
3024
3025
3026 i -= last_sio;
3027 count = 0;
3028 if ((err = pci_enable_device (dev)) != 0)
3029 return err;
3030
3031 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
3032 if (!data)
3033 return -ENOMEM;
3034
3035 if (cards[i].preinit_hook &&
3036 cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
3037 kfree(data);
3038 return -ENODEV;
3039 }
3040
3041 for (n = 0; n < cards[i].numports; n++) {
3042 int lo = cards[i].addr[n].lo;
3043 int hi = cards[i].addr[n].hi;
3044 int irq;
3045 unsigned long io_lo, io_hi;
3046 io_lo = pci_resource_start (dev, lo);
3047 io_hi = 0;
3048 if ((hi >= 0) && (hi <= 6))
3049 io_hi = pci_resource_start (dev, hi);
3050 else if (hi > 6)
3051 io_lo += hi;
3052
3053
3054
3055 irq = dev->irq;
3056 if (irq == IRQ_NONE) {
3057 printk (KERN_DEBUG
3058 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n",
3059 parport_pc_pci_tbl[i + last_sio].vendor,
3060 parport_pc_pci_tbl[i + last_sio].device,
3061 io_lo, io_hi);
3062 irq = PARPORT_IRQ_NONE;
3063 } else {
3064 printk (KERN_DEBUG
3065 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n",
3066 parport_pc_pci_tbl[i + last_sio].vendor,
3067 parport_pc_pci_tbl[i + last_sio].device,
3068 io_lo, io_hi, irq);
3069 }
3070 data->ports[count] =
3071 parport_pc_probe_port(io_lo, io_hi, irq,
3072 PARPORT_DMA_NONE, &dev->dev,
3073 IRQF_SHARED);
3074 if (data->ports[count])
3075 count++;
3076 }
3077
3078 data->num = count;
3079
3080 if (cards[i].postinit_hook)
3081 cards[i].postinit_hook (dev, count == 0);
3082
3083 if (count) {
3084 pci_set_drvdata(dev, data);
3085 return 0;
3086 }
3087
3088 kfree(data);
3089
3090 return -ENODEV;
3091}
3092
3093static void __devexit parport_pc_pci_remove(struct pci_dev *dev)
3094{
3095 struct pci_parport_data *data = pci_get_drvdata(dev);
3096 int i;
3097
3098 pci_set_drvdata(dev, NULL);
3099
3100 if (data) {
3101 for (i = data->num - 1; i >= 0; i--)
3102 parport_pc_unregister_port(data->ports[i]);
3103
3104 kfree(data);
3105 }
3106}
3107
3108static struct pci_driver parport_pc_pci_driver = {
3109 .name = "parport_pc",
3110 .id_table = parport_pc_pci_tbl,
3111 .probe = parport_pc_pci_probe,
3112 .remove = __devexit_p(parport_pc_pci_remove),
3113};
3114
3115static int __init parport_pc_init_superio (int autoirq, int autodma)
3116{
3117 const struct pci_device_id *id;
3118 struct pci_dev *pdev = NULL;
3119 int ret = 0;
3120
3121 for_each_pci_dev(pdev) {
3122 id = pci_match_id(parport_pc_pci_tbl, pdev);
3123 if (id == NULL || id->driver_data >= last_sio)
3124 continue;
3125
3126 if (parport_pc_superio_info[id->driver_data].probe
3127 (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) {
3128 ret++;
3129 }
3130 }
3131
3132 return ret;
3133}
3134#else
3135static struct pci_driver parport_pc_pci_driver;
3136static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;}
3137#endif
3138
3139#ifdef CONFIG_PNP
3140
3141static const struct pnp_device_id parport_pc_pnp_tbl[] = {
3142
3143 {.id = "PNP0400", .driver_data = 0},
3144
3145 {.id = "PNP0401", .driver_data = 0},
3146 { }
3147};
3148
3149MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl);
3150
3151static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id)
3152{
3153 struct parport *pdata;
3154 unsigned long io_lo, io_hi;
3155 int dma, irq;
3156
3157 if (pnp_port_valid(dev,0) &&
3158 !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) {
3159 io_lo = pnp_port_start(dev,0);
3160 } else
3161 return -EINVAL;
3162
3163 if (pnp_port_valid(dev,1) &&
3164 !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) {
3165 io_hi = pnp_port_start(dev,1);
3166 } else
3167 io_hi = 0;
3168
3169 if (pnp_irq_valid(dev,0) &&
3170 !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) {
3171 irq = pnp_irq(dev,0);
3172 } else
3173 irq = PARPORT_IRQ_NONE;
3174
3175 if (pnp_dma_valid(dev,0) &&
3176 !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) {
3177 dma = pnp_dma(dev,0);
3178 } else
3179 dma = PARPORT_DMA_NONE;
3180
3181 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
3182 if (!(pdata = parport_pc_probe_port(io_lo, io_hi,
3183 irq, dma, &dev->dev, 0)))
3184 return -ENODEV;
3185
3186 pnp_set_drvdata(dev,pdata);
3187 return 0;
3188}
3189
3190static void parport_pc_pnp_remove(struct pnp_dev *dev)
3191{
3192 struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
3193 if (!pdata)
3194 return;
3195
3196 parport_pc_unregister_port(pdata);
3197}
3198
3199
3200static struct pnp_driver parport_pc_pnp_driver = {
3201 .name = "parport_pc",
3202 .id_table = parport_pc_pnp_tbl,
3203 .probe = parport_pc_pnp_probe,
3204 .remove = parport_pc_pnp_remove,
3205};
3206
3207#else
3208static struct pnp_driver parport_pc_pnp_driver;
3209#endif
3210
3211static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
3212{
3213
3214
3215 return 0;
3216}
3217
3218static struct platform_driver parport_pc_platform_driver = {
3219 .driver = {
3220 .owner = THIS_MODULE,
3221 .name = "parport_pc",
3222 },
3223 .probe = parport_pc_platform_probe,
3224};
3225
3226
3227static int __devinit __attribute__((unused))
3228parport_pc_find_isa_ports (int autoirq, int autodma)
3229{
3230 int count = 0;
3231
3232 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL, 0))
3233 count++;
3234 if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL, 0))
3235 count++;
3236 if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL, 0))
3237 count++;
3238
3239 return count;
3240}
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252static void __init parport_pc_find_ports (int autoirq, int autodma)
3253{
3254 int count = 0, err;
3255
3256#ifdef CONFIG_PARPORT_PC_SUPERIO
3257 detect_and_report_it87();
3258 detect_and_report_winbond();
3259 detect_and_report_smsc();
3260#endif
3261
3262
3263 count += parport_pc_init_superio(autoirq, autodma);
3264
3265
3266 if (!count) {
3267 err = pnp_register_driver(&parport_pc_pnp_driver);
3268 if (!err)
3269 pnp_registered_parport = 1;
3270 }
3271
3272
3273 parport_pc_find_nonpci_ports(autoirq, autodma);
3274
3275 err = pci_register_driver(&parport_pc_pci_driver);
3276 if (!err)
3277 pci_registered_parport = 1;
3278}
3279
3280
3281
3282
3283
3284
3285
3286static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
3287static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] =
3288 { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO };
3289static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE };
3290static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY };
3291
3292static int __init parport_parse_param(const char *s, int *val,
3293 int automatic, int none, int nofifo)
3294{
3295 if (!s)
3296 return 0;
3297 if (!strncmp(s, "auto", 4))
3298 *val = automatic;
3299 else if (!strncmp(s, "none", 4))
3300 *val = none;
3301 else if (nofifo && !strncmp(s, "nofifo", 4))
3302 *val = nofifo;
3303 else {
3304 char *ep;
3305 unsigned long r = simple_strtoul(s, &ep, 0);
3306 if (ep != s)
3307 *val = r;
3308 else {
3309 printk(KERN_ERR "parport: bad specifier `%s'\n", s);
3310 return -1;
3311 }
3312 }
3313 return 0;
3314}
3315
3316static int __init parport_parse_irq(const char *irqstr, int *val)
3317{
3318 return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
3319 PARPORT_IRQ_NONE, 0);
3320}
3321
3322static int __init parport_parse_dma(const char *dmastr, int *val)
3323{
3324 return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
3325 PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
3326}
3327
3328#ifdef CONFIG_PCI
3329static int __init parport_init_mode_setup(char *str)
3330{
3331 printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
3332
3333 if (!strcmp (str, "spp"))
3334 parport_init_mode=1;
3335 if (!strcmp (str, "ps2"))
3336 parport_init_mode=2;
3337 if (!strcmp (str, "epp"))
3338 parport_init_mode=3;
3339 if (!strcmp (str, "ecp"))
3340 parport_init_mode=4;
3341 if (!strcmp (str, "ecpepp"))
3342 parport_init_mode=5;
3343 return 1;
3344}
3345#endif
3346
3347#ifdef MODULE
3348static const char *irq[PARPORT_PC_MAX_PORTS];
3349static const char *dma[PARPORT_PC_MAX_PORTS];
3350
3351MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3352module_param_array(io, int, NULL, 0);
3353MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
3354module_param_array(io_hi, int, NULL, 0);
3355MODULE_PARM_DESC(irq, "IRQ line");
3356module_param_array(irq, charp, NULL, 0);
3357MODULE_PARM_DESC(dma, "DMA channel");
3358module_param_array(dma, charp, NULL, 0);
3359#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
3360 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
3361MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
3362module_param(verbose_probing, int, 0644);
3363#endif
3364#ifdef CONFIG_PCI
3365static char *init_mode;
3366MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
3367module_param(init_mode, charp, 0);
3368#endif
3369
3370static int __init parse_parport_params(void)
3371{
3372 unsigned int i;
3373 int val;
3374
3375#ifdef CONFIG_PCI
3376 if (init_mode)
3377 parport_init_mode_setup(init_mode);
3378#endif
3379
3380 for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
3381 if (parport_parse_irq(irq[i], &val))
3382 return 1;
3383 irqval[i] = val;
3384 if (parport_parse_dma(dma[i], &val))
3385 return 1;
3386 dmaval[i] = val;
3387 }
3388 if (!io[0]) {
3389
3390 if (irq[0] && !parport_parse_irq(irq[0], &val))
3391 switch (val) {
3392 case PARPORT_IRQ_NONE:
3393 case PARPORT_IRQ_AUTO:
3394 irqval[0] = val;
3395 break;
3396 default:
3397 printk (KERN_WARNING
3398 "parport_pc: irq specified "
3399 "without base address. Use 'io=' "
3400 "to specify one\n");
3401 }
3402
3403 if (dma[0] && !parport_parse_dma(dma[0], &val))
3404 switch (val) {
3405 case PARPORT_DMA_NONE:
3406 case PARPORT_DMA_AUTO:
3407 dmaval[0] = val;
3408 break;
3409 default:
3410 printk (KERN_WARNING
3411 "parport_pc: dma specified "
3412 "without base address. Use 'io=' "
3413 "to specify one\n");
3414 }
3415 }
3416 return 0;
3417}
3418
3419#else
3420
3421static int parport_setup_ptr __initdata = 0;
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432static int __init parport_setup (char *str)
3433{
3434 char *endptr;
3435 char *sep;
3436 int val;
3437
3438 if (!str || !*str || (*str == '0' && !*(str+1))) {
3439
3440 io[0] = PARPORT_DISABLE;
3441 return 1;
3442 }
3443
3444 if (!strncmp (str, "auto", 4)) {
3445 irqval[0] = PARPORT_IRQ_AUTO;
3446 dmaval[0] = PARPORT_DMA_AUTO;
3447 return 1;
3448 }
3449
3450 val = simple_strtoul (str, &endptr, 0);
3451 if (endptr == str) {
3452 printk (KERN_WARNING "parport=%s not understood\n", str);
3453 return 1;
3454 }
3455
3456 if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
3457 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
3458 return 1;
3459 }
3460
3461 io[parport_setup_ptr] = val;
3462 irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
3463 dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
3464
3465 sep = strchr(str, ',');
3466 if (sep++) {
3467 if (parport_parse_irq(sep, &val))
3468 return 1;
3469 irqval[parport_setup_ptr] = val;
3470 sep = strchr(sep, ',');
3471 if (sep++) {
3472 if (parport_parse_dma(sep, &val))
3473 return 1;
3474 dmaval[parport_setup_ptr] = val;
3475 }
3476 }
3477 parport_setup_ptr++;
3478 return 1;
3479}
3480
3481static int __init parse_parport_params(void)
3482{
3483 return io[0] == PARPORT_DISABLE;
3484}
3485
3486__setup ("parport=", parport_setup);
3487
3488
3489
3490
3491
3492
3493#ifdef CONFIG_PCI
3494__setup("parport_init_mode=",parport_init_mode_setup);
3495#endif
3496#endif
3497
3498
3499
3500static int __init parport_pc_init(void)
3501{
3502 int err;
3503
3504 if (parse_parport_params())
3505 return -EINVAL;
3506
3507 err = platform_driver_register(&parport_pc_platform_driver);
3508 if (err)
3509 return err;
3510
3511 if (io[0]) {
3512 int i;
3513
3514 user_specified = 1;
3515 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3516 if (!io[i])
3517 break;
3518 if ((io_hi[i]) == PARPORT_IOHI_AUTO)
3519 io_hi[i] = 0x400 + io[i];
3520 parport_pc_probe_port(io[i], io_hi[i],
3521 irqval[i], dmaval[i], NULL, 0);
3522 }
3523 } else
3524 parport_pc_find_ports (irqval[0], dmaval[0]);
3525
3526 return 0;
3527}
3528
3529static void __exit parport_pc_exit(void)
3530{
3531 if (pci_registered_parport)
3532 pci_unregister_driver (&parport_pc_pci_driver);
3533 if (pnp_registered_parport)
3534 pnp_unregister_driver (&parport_pc_pnp_driver);
3535 platform_driver_unregister(&parport_pc_platform_driver);
3536
3537 while (!list_empty(&ports_list)) {
3538 struct parport_pc_private *priv;
3539 struct parport *port;
3540 priv = list_entry(ports_list.next,
3541 struct parport_pc_private, list);
3542 port = priv->port;
3543 if (port->dev && port->dev->bus == &platform_bus_type)
3544 platform_device_unregister(
3545 to_platform_device(port->dev));
3546 parport_pc_unregister_port(port);
3547 }
3548}
3549
3550MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
3551MODULE_DESCRIPTION("PC-style parallel port driver");
3552MODULE_LICENSE("GPL");
3553module_init(parport_pc_init)
3554module_exit(parport_pc_exit)
3555