blob: c3240a67ef8511ec69b308f0a6751fa957732752 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Low-level parallel-port routines for 8255-based PC-style hardware.
2 *
3 * Authors: Phil Blundell <philb@gnu.org>
4 * Tim Waugh <tim@cyberelk.demon.co.uk>
5 * Jose Renau <renau@acm.org>
Adrian Bunkbdca3f22006-06-26 18:19:23 +02006 * David Campbell
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Andrea Arcangeli
8 *
9 * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
10 *
11 * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
12 * DMA support - Bert De Jonghe <bert@sophis.be>
13 * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999
14 * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
15 * Various hacks, Fred Barnes, 04/2001
16 * Updated probing logic - Adam Belay <ambx1@neo.rr.com>
17 */
18
19/* This driver should work with any hardware that is broadly compatible
20 * with that in the IBM PC. This applies to the majority of integrated
21 * I/O chipsets that are commonly available. The expected register
22 * layout is:
23 *
24 * base+0 data
25 * base+1 status
26 * base+2 control
27 *
28 * In addition, there are some optional registers:
29 *
30 * base+3 EPP address
31 * base+4 EPP data
32 * base+0x400 ECP config A
33 * base+0x401 ECP config B
34 * base+0x402 ECP control
35 *
36 * All registers are 8 bits wide and read/write. If your hardware differs
37 * only in register addresses (eg because your registers are on 32-bit
38 * word boundaries) then you can alter the constants in parport_pc.h to
39 * accommodate this.
40 *
41 * Note that the ECP registers may not start at offset 0x400 for PCI cards,
42 * but rather will start at port->base_hi.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#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/pci.h>
55#include <linux/pnp.h>
56#include <linux/sysctl.h>
57
58#include <asm/io.h>
59#include <asm/dma.h>
60#include <asm/uaccess.h>
61
62#include <linux/parport.h>
63#include <linux/parport_pc.h>
64#include <linux/via.h>
65#include <asm/parport.h>
66
67#define PARPORT_PC_MAX_PORTS PARPORT_MAX
68
Al Viro7fbacd52005-05-04 05:39:32 +010069#ifdef CONFIG_ISA_DMA_API
70#define HAS_DMA
71#endif
72
Linus Torvalds1da177e2005-04-16 15:20:36 -070073/* ECR modes */
74#define ECR_SPP 00
75#define ECR_PS2 01
76#define ECR_PPF 02
77#define ECR_ECP 03
78#define ECR_EPP 04
79#define ECR_VND 05
80#define ECR_TST 06
81#define ECR_CNF 07
82#define ECR_MODE_MASK 0xe0
83#define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v))
84
85#undef DEBUG
86
87#ifdef DEBUG
88#define DPRINTK printk
89#else
90#define DPRINTK(stuff...)
91#endif
92
93
94#define NR_SUPERIOS 3
95static struct superio_struct { /* For Super-IO chips autodetection */
96 int io;
97 int irq;
98 int dma;
Randy.Dunlap96766a32006-04-18 22:21:57 -070099} superios[NR_SUPERIOS] = { {0,},};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100
101static int user_specified;
102#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
103 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
104static int verbose_probing;
105#endif
106static int pci_registered_parport;
107static int pnp_registered_parport;
108
109/* frob_control, but for ECR */
110static void frob_econtrol (struct parport *pb, unsigned char m,
111 unsigned char v)
112{
113 unsigned char ectr = 0;
114
115 if (m != 0xff)
116 ectr = inb (ECONTROL (pb));
117
118 DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
119 m, v, ectr, (ectr & ~m) ^ v);
120
121 outb ((ectr & ~m) ^ v, ECONTROL (pb));
122}
123
124static __inline__ void frob_set_mode (struct parport *p, int mode)
125{
126 frob_econtrol (p, ECR_MODE_MASK, mode << 5);
127}
128
129#ifdef CONFIG_PARPORT_PC_FIFO
130/* Safely change the mode bits in the ECR
131 Returns:
132 0 : Success
133 -EBUSY: Could not drain FIFO in some finite amount of time,
134 mode not changed!
135 */
136static int change_mode(struct parport *p, int m)
137{
138 const struct parport_pc_private *priv = p->physport->private_data;
139 unsigned char oecr;
140 int mode;
141
142 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m);
143
144 if (!priv->ecr) {
145 printk (KERN_DEBUG "change_mode: but there's no ECR!\n");
146 return 0;
147 }
148
149 /* Bits <7:5> contain the mode. */
150 oecr = inb (ECONTROL (p));
151 mode = (oecr >> 5) & 0x7;
152 if (mode == m) return 0;
153
154 if (mode >= 2 && !(priv->ctr & 0x20)) {
155 /* This mode resets the FIFO, so we may
156 * have to wait for it to drain first. */
157 unsigned long expire = jiffies + p->physport->cad->timeout;
158 int counter;
159 switch (mode) {
160 case ECR_PPF: /* Parallel Port FIFO mode */
161 case ECR_ECP: /* ECP Parallel Port mode */
162 /* Busy wait for 200us */
163 for (counter = 0; counter < 40; counter++) {
164 if (inb (ECONTROL (p)) & 0x01)
165 break;
166 if (signal_pending (current)) break;
167 udelay (5);
168 }
169
170 /* Poll slowly. */
171 while (!(inb (ECONTROL (p)) & 0x01)) {
172 if (time_after_eq (jiffies, expire))
173 /* The FIFO is stuck. */
174 return -EBUSY;
Nishanth Aravamudan7b4ccf82005-09-10 00:27:31 -0700175 schedule_timeout_interruptible(msecs_to_jiffies(10));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176 if (signal_pending (current))
177 break;
178 }
179 }
180 }
181
182 if (mode >= 2 && m >= 2) {
183 /* We have to go through mode 001 */
184 oecr &= ~(7 << 5);
185 oecr |= ECR_PS2 << 5;
186 ECR_WRITE (p, oecr);
187 }
188
189 /* Set the mode. */
190 oecr &= ~(7 << 5);
191 oecr |= m << 5;
192 ECR_WRITE (p, oecr);
193 return 0;
194}
195
196#ifdef CONFIG_PARPORT_1284
197/* Find FIFO lossage; FIFO is reset */
198#if 0
199static int get_fifo_residue (struct parport *p)
200{
201 int residue;
202 int cnfga;
203 const struct parport_pc_private *priv = p->physport->private_data;
204
205 /* Adjust for the contents of the FIFO. */
206 for (residue = priv->fifo_depth; ; residue--) {
207 if (inb (ECONTROL (p)) & 0x2)
208 /* Full up. */
209 break;
210
211 outb (0, FIFO (p));
212 }
213
214 printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
215 residue);
216
217 /* Reset the FIFO. */
218 frob_set_mode (p, ECR_PS2);
219
220 /* Now change to config mode and clean up. FIXME */
221 frob_set_mode (p, ECR_CNF);
222 cnfga = inb (CONFIGA (p));
223 printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
224
225 if (!(cnfga & (1<<2))) {
226 printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
227 residue++;
228 }
229
230 /* Don't care about partial PWords until support is added for
231 * PWord != 1 byte. */
232
233 /* Back to PS2 mode. */
234 frob_set_mode (p, ECR_PS2);
235
236 DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p)));
237 return residue;
238}
239#endif /* 0 */
240#endif /* IEEE 1284 support */
241#endif /* FIFO support */
242
243/*
244 * Clear TIMEOUT BIT in EPP MODE
245 *
246 * This is also used in SPP detection.
247 */
248static int clear_epp_timeout(struct parport *pb)
249{
250 unsigned char r;
251
252 if (!(parport_pc_read_status(pb) & 0x01))
253 return 1;
254
255 /* To clear timeout some chips require double read */
256 parport_pc_read_status(pb);
257 r = parport_pc_read_status(pb);
258 outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */
259 outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */
260 r = parport_pc_read_status(pb);
261
262 return !(r & 0x01);
263}
264
265/*
266 * Access functions.
267 *
268 * Most of these aren't static because they may be used by the
269 * parport_xxx_yyy macros. extern __inline__ versions of several
270 * of these are in parport_pc.h.
271 */
272
David Howells7d12e782006-10-05 14:55:46 +0100273static irqreturn_t parport_pc_interrupt(int irq, void *dev_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274{
David Howells7d12e782006-10-05 14:55:46 +0100275 parport_generic_irq(irq, (struct parport *) dev_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 /* FIXME! Was it really ours? */
277 return IRQ_HANDLED;
278}
279
280static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s)
281{
282 s->u.pc.ctr = 0xc;
283 if (dev->irq_func &&
284 dev->port->irq != PARPORT_IRQ_NONE)
285 /* Set ackIntEn */
286 s->u.pc.ctr |= 0x10;
287
288 s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
289 * D.Gruszka VScom */
290}
291
292static void parport_pc_save_state(struct parport *p, struct parport_state *s)
293{
294 const struct parport_pc_private *priv = p->physport->private_data;
295 s->u.pc.ctr = priv->ctr;
296 if (priv->ecr)
297 s->u.pc.ecr = inb (ECONTROL (p));
298}
299
300static void parport_pc_restore_state(struct parport *p, struct parport_state *s)
301{
302 struct parport_pc_private *priv = p->physport->private_data;
303 register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
304 outb (c, CONTROL (p));
305 priv->ctr = c;
306 if (priv->ecr)
307 ECR_WRITE (p, s->u.pc.ecr);
308}
309
310#ifdef CONFIG_PARPORT_1284
311static size_t parport_pc_epp_read_data (struct parport *port, void *buf,
312 size_t length, int flags)
313{
314 size_t got = 0;
315
316 if (flags & PARPORT_W91284PIC) {
317 unsigned char status;
318 size_t left = length;
319
320 /* use knowledge about data lines..:
321 * nFault is 0 if there is at least 1 byte in the Warp's FIFO
322 * pError is 1 if there are 16 bytes in the Warp's FIFO
323 */
324 status = inb (STATUS (port));
325
326 while (!(status & 0x08) && (got < length)) {
327 if ((left >= 16) && (status & 0x20) && !(status & 0x08)) {
328 /* can grab 16 bytes from warp fifo */
329 if (!((long)buf & 0x03)) {
330 insl (EPPDATA (port), buf, 4);
331 } else {
332 insb (EPPDATA (port), buf, 16);
333 }
334 buf += 16;
335 got += 16;
336 left -= 16;
337 } else {
338 /* grab single byte from the warp fifo */
339 *((char *)buf) = inb (EPPDATA (port));
340 buf++;
341 got++;
342 left--;
343 }
344 status = inb (STATUS (port));
345 if (status & 0x01) {
346 /* EPP timeout should never occur... */
347 printk (KERN_DEBUG "%s: EPP timeout occurred while talking to "
348 "w91284pic (should not have done)\n", port->name);
349 clear_epp_timeout (port);
350 }
351 }
352 return got;
353 }
354 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
355 if (!(((long)buf | length) & 0x03)) {
356 insl (EPPDATA (port), buf, (length >> 2));
357 } else {
358 insb (EPPDATA (port), buf, length);
359 }
360 if (inb (STATUS (port)) & 0x01) {
361 clear_epp_timeout (port);
362 return -EIO;
363 }
364 return length;
365 }
366 for (; got < length; got++) {
367 *((char*)buf) = inb (EPPDATA(port));
368 buf++;
369 if (inb (STATUS (port)) & 0x01) {
370 /* EPP timeout */
371 clear_epp_timeout (port);
372 break;
373 }
374 }
375
376 return got;
377}
378
379static size_t parport_pc_epp_write_data (struct parport *port, const void *buf,
380 size_t length, int flags)
381{
382 size_t written = 0;
383
384 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
385 if (!(((long)buf | length) & 0x03)) {
386 outsl (EPPDATA (port), buf, (length >> 2));
387 } else {
388 outsb (EPPDATA (port), buf, length);
389 }
390 if (inb (STATUS (port)) & 0x01) {
391 clear_epp_timeout (port);
392 return -EIO;
393 }
394 return length;
395 }
396 for (; written < length; written++) {
397 outb (*((char*)buf), EPPDATA(port));
398 buf++;
399 if (inb (STATUS(port)) & 0x01) {
400 clear_epp_timeout (port);
401 break;
402 }
403 }
404
405 return written;
406}
407
408static size_t parport_pc_epp_read_addr (struct parport *port, void *buf,
409 size_t length, int flags)
410{
411 size_t got = 0;
412
413 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
414 insb (EPPADDR (port), buf, length);
415 if (inb (STATUS (port)) & 0x01) {
416 clear_epp_timeout (port);
417 return -EIO;
418 }
419 return length;
420 }
421 for (; got < length; got++) {
422 *((char*)buf) = inb (EPPADDR (port));
423 buf++;
424 if (inb (STATUS (port)) & 0x01) {
425 clear_epp_timeout (port);
426 break;
427 }
428 }
429
430 return got;
431}
432
433static size_t parport_pc_epp_write_addr (struct parport *port,
434 const void *buf, size_t length,
435 int flags)
436{
437 size_t written = 0;
438
439 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
440 outsb (EPPADDR (port), buf, length);
441 if (inb (STATUS (port)) & 0x01) {
442 clear_epp_timeout (port);
443 return -EIO;
444 }
445 return length;
446 }
447 for (; written < length; written++) {
448 outb (*((char*)buf), EPPADDR (port));
449 buf++;
450 if (inb (STATUS (port)) & 0x01) {
451 clear_epp_timeout (port);
452 break;
453 }
454 }
455
456 return written;
457}
458
459static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf,
460 size_t length, int flags)
461{
462 size_t got;
463
464 frob_set_mode (port, ECR_EPP);
465 parport_pc_data_reverse (port);
466 parport_pc_write_control (port, 0x4);
467 got = parport_pc_epp_read_data (port, buf, length, flags);
468 frob_set_mode (port, ECR_PS2);
469
470 return got;
471}
472
473static size_t parport_pc_ecpepp_write_data (struct parport *port,
474 const void *buf, size_t length,
475 int flags)
476{
477 size_t written;
478
479 frob_set_mode (port, ECR_EPP);
480 parport_pc_write_control (port, 0x4);
481 parport_pc_data_forward (port);
482 written = parport_pc_epp_write_data (port, buf, length, flags);
483 frob_set_mode (port, ECR_PS2);
484
485 return written;
486}
487
488static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf,
489 size_t length, int flags)
490{
491 size_t got;
492
493 frob_set_mode (port, ECR_EPP);
494 parport_pc_data_reverse (port);
495 parport_pc_write_control (port, 0x4);
496 got = parport_pc_epp_read_addr (port, buf, length, flags);
497 frob_set_mode (port, ECR_PS2);
498
499 return got;
500}
501
502static size_t parport_pc_ecpepp_write_addr (struct parport *port,
503 const void *buf, size_t length,
504 int flags)
505{
506 size_t written;
507
508 frob_set_mode (port, ECR_EPP);
509 parport_pc_write_control (port, 0x4);
510 parport_pc_data_forward (port);
511 written = parport_pc_epp_write_addr (port, buf, length, flags);
512 frob_set_mode (port, ECR_PS2);
513
514 return written;
515}
516#endif /* IEEE 1284 support */
517
518#ifdef CONFIG_PARPORT_PC_FIFO
519static size_t parport_pc_fifo_write_block_pio (struct parport *port,
520 const void *buf, size_t length)
521{
522 int ret = 0;
523 const unsigned char *bufp = buf;
524 size_t left = length;
525 unsigned long expire = jiffies + port->physport->cad->timeout;
526 const int fifo = FIFO (port);
527 int poll_for = 8; /* 80 usecs */
528 const struct parport_pc_private *priv = port->physport->private_data;
529 const int fifo_depth = priv->fifo_depth;
530
531 port = port->physport;
532
533 /* We don't want to be interrupted every character. */
534 parport_pc_disable_irq (port);
535 /* set nErrIntrEn and serviceIntr */
536 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
537
538 /* Forward mode. */
539 parport_pc_data_forward (port); /* Must be in PS2 mode */
540
541 while (left) {
542 unsigned char byte;
543 unsigned char ecrval = inb (ECONTROL (port));
544 int i = 0;
545
546 if (need_resched() && time_before (jiffies, expire))
547 /* Can't yield the port. */
548 schedule ();
549
550 /* Anyone else waiting for the port? */
551 if (port->waithead) {
552 printk (KERN_DEBUG "Somebody wants the port\n");
553 break;
554 }
555
556 if (ecrval & 0x02) {
557 /* FIFO is full. Wait for interrupt. */
558
559 /* Clear serviceIntr */
560 ECR_WRITE (port, ecrval & ~(1<<2));
561 false_alarm:
562 ret = parport_wait_event (port, HZ);
563 if (ret < 0) break;
564 ret = 0;
565 if (!time_before (jiffies, expire)) {
566 /* Timed out. */
567 printk (KERN_DEBUG "FIFO write timed out\n");
568 break;
569 }
570 ecrval = inb (ECONTROL (port));
571 if (!(ecrval & (1<<2))) {
572 if (need_resched() &&
573 time_before (jiffies, expire))
574 schedule ();
575
576 goto false_alarm;
577 }
578
579 continue;
580 }
581
582 /* Can't fail now. */
583 expire = jiffies + port->cad->timeout;
584
585 poll:
586 if (signal_pending (current))
587 break;
588
589 if (ecrval & 0x01) {
590 /* FIFO is empty. Blast it full. */
591 const int n = left < fifo_depth ? left : fifo_depth;
592 outsb (fifo, bufp, n);
593 bufp += n;
594 left -= n;
595
596 /* Adjust the poll time. */
597 if (i < (poll_for - 2)) poll_for--;
598 continue;
599 } else if (i++ < poll_for) {
600 udelay (10);
601 ecrval = inb (ECONTROL (port));
602 goto poll;
603 }
604
605 /* Half-full (call me an optimist) */
606 byte = *bufp++;
607 outb (byte, fifo);
608 left--;
609 }
610
611dump_parport_state ("leave fifo_write_block_pio", port);
612 return length - left;
613}
614
Al Viro7fbacd52005-05-04 05:39:32 +0100615#ifdef HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616static size_t parport_pc_fifo_write_block_dma (struct parport *port,
617 const void *buf, size_t length)
618{
619 int ret = 0;
620 unsigned long dmaflag;
621 size_t left = length;
622 const struct parport_pc_private *priv = port->physport->private_data;
David Brownellc15a3832007-05-08 00:27:35 -0700623 struct device *dev = port->physport->dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 dma_addr_t dma_addr, dma_handle;
625 size_t maxlen = 0x10000; /* max 64k per DMA transfer */
626 unsigned long start = (unsigned long) buf;
627 unsigned long end = (unsigned long) buf + length - 1;
628
629dump_parport_state ("enter fifo_write_block_dma", port);
630 if (end < MAX_DMA_ADDRESS) {
631 /* If it would cross a 64k boundary, cap it at the end. */
632 if ((start ^ end) & ~0xffffUL)
633 maxlen = 0x10000 - (start & 0xffff);
634
David Brownellc15a3832007-05-08 00:27:35 -0700635 dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
636 DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 } else {
638 /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */
639 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
640 dma_addr = priv->dma_handle;
641 dma_handle = 0;
642 }
643
644 port = port->physport;
645
646 /* We don't want to be interrupted every character. */
647 parport_pc_disable_irq (port);
648 /* set nErrIntrEn and serviceIntr */
649 frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2));
650
651 /* Forward mode. */
652 parport_pc_data_forward (port); /* Must be in PS2 mode */
653
654 while (left) {
655 unsigned long expire = jiffies + port->physport->cad->timeout;
656
657 size_t count = left;
658
659 if (count > maxlen)
660 count = maxlen;
661
662 if (!dma_handle) /* bounce buffer ! */
663 memcpy(priv->dma_buf, buf, count);
664
665 dmaflag = claim_dma_lock();
666 disable_dma(port->dma);
667 clear_dma_ff(port->dma);
668 set_dma_mode(port->dma, DMA_MODE_WRITE);
669 set_dma_addr(port->dma, dma_addr);
670 set_dma_count(port->dma, count);
671
672 /* Set DMA mode */
673 frob_econtrol (port, 1<<3, 1<<3);
674
675 /* Clear serviceIntr */
676 frob_econtrol (port, 1<<2, 0);
677
678 enable_dma(port->dma);
679 release_dma_lock(dmaflag);
680
681 /* assume DMA will be successful */
682 left -= count;
683 buf += count;
684 if (dma_handle) dma_addr += count;
685
686 /* Wait for interrupt. */
687 false_alarm:
688 ret = parport_wait_event (port, HZ);
689 if (ret < 0) break;
690 ret = 0;
691 if (!time_before (jiffies, expire)) {
692 /* Timed out. */
693 printk (KERN_DEBUG "DMA write timed out\n");
694 break;
695 }
696 /* Is serviceIntr set? */
697 if (!(inb (ECONTROL (port)) & (1<<2))) {
698 cond_resched();
699
700 goto false_alarm;
701 }
702
703 dmaflag = claim_dma_lock();
704 disable_dma(port->dma);
705 clear_dma_ff(port->dma);
706 count = get_dma_residue(port->dma);
707 release_dma_lock(dmaflag);
708
709 cond_resched(); /* Can't yield the port. */
710
711 /* Anyone else waiting for the port? */
712 if (port->waithead) {
713 printk (KERN_DEBUG "Somebody wants the port\n");
714 break;
715 }
716
717 /* update for possible DMA residue ! */
718 buf -= count;
719 left += count;
720 if (dma_handle) dma_addr -= count;
721 }
722
723 /* Maybe got here through break, so adjust for DMA residue! */
724 dmaflag = claim_dma_lock();
725 disable_dma(port->dma);
726 clear_dma_ff(port->dma);
727 left += get_dma_residue(port->dma);
728 release_dma_lock(dmaflag);
729
730 /* Turn off DMA mode */
731 frob_econtrol (port, 1<<3, 0);
David Brownellc15a3832007-05-08 00:27:35 -0700732
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 if (dma_handle)
David Brownellc15a3832007-05-08 00:27:35 -0700734 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
736dump_parport_state ("leave fifo_write_block_dma", port);
737 return length - left;
738}
Al Viro7fbacd52005-05-04 05:39:32 +0100739#endif
740
741static inline size_t parport_pc_fifo_write_block(struct parport *port,
742 const void *buf, size_t length)
743{
744#ifdef HAS_DMA
745 if (port->dma != PARPORT_DMA_NONE)
746 return parport_pc_fifo_write_block_dma (port, buf, length);
747#endif
748 return parport_pc_fifo_write_block_pio (port, buf, length);
749}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
751/* Parallel Port FIFO mode (ECP chipsets) */
752static size_t parport_pc_compat_write_block_pio (struct parport *port,
753 const void *buf, size_t length,
754 int flags)
755{
756 size_t written;
757 int r;
758 unsigned long expire;
759 const struct parport_pc_private *priv = port->physport->private_data;
760
761 /* Special case: a timeout of zero means we cannot call schedule().
762 * Also if O_NONBLOCK is set then use the default implementation. */
763 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
764 return parport_ieee1284_write_compat (port, buf,
765 length, flags);
766
767 /* Set up parallel port FIFO mode.*/
768 parport_pc_data_forward (port); /* Must be in PS2 mode */
769 parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0);
770 r = change_mode (port, ECR_PPF); /* Parallel port FIFO */
771 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name);
772
773 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
774
775 /* Write the data to the FIFO. */
Al Viro7fbacd52005-05-04 05:39:32 +0100776 written = parport_pc_fifo_write_block(port, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* Finish up. */
779 /* For some hardware we don't want to touch the mode until
780 * the FIFO is empty, so allow 4 seconds for each position
781 * in the fifo.
782 */
783 expire = jiffies + (priv->fifo_depth * HZ * 4);
784 do {
785 /* Wait for the FIFO to empty */
786 r = change_mode (port, ECR_PS2);
787 if (r != -EBUSY) {
788 break;
789 }
790 } while (time_before (jiffies, expire));
791 if (r == -EBUSY) {
792
793 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
794
795 /* Prevent further data transfer. */
796 frob_set_mode (port, ECR_TST);
797
798 /* Adjust for the contents of the FIFO. */
799 for (written -= priv->fifo_depth; ; written++) {
800 if (inb (ECONTROL (port)) & 0x2) {
801 /* Full up. */
802 break;
803 }
804 outb (0, FIFO (port));
805 }
806
807 /* Reset the FIFO and return to PS2 mode. */
808 frob_set_mode (port, ECR_PS2);
809 }
810
811 r = parport_wait_peripheral (port,
812 PARPORT_STATUS_BUSY,
813 PARPORT_STATUS_BUSY);
814 if (r)
815 printk (KERN_DEBUG
816 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
817 port->name, r);
818
819 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
820
821 return written;
822}
823
824/* ECP */
825#ifdef CONFIG_PARPORT_1284
826static size_t parport_pc_ecp_write_block_pio (struct parport *port,
827 const void *buf, size_t length,
828 int flags)
829{
830 size_t written;
831 int r;
832 unsigned long expire;
833 const struct parport_pc_private *priv = port->physport->private_data;
834
835 /* Special case: a timeout of zero means we cannot call schedule().
836 * Also if O_NONBLOCK is set then use the default implementation. */
837 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
838 return parport_ieee1284_ecp_write_data (port, buf,
839 length, flags);
840
841 /* Switch to forward mode if necessary. */
842 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
843 /* Event 47: Set nInit high. */
844 parport_frob_control (port,
845 PARPORT_CONTROL_INIT
846 | PARPORT_CONTROL_AUTOFD,
847 PARPORT_CONTROL_INIT
848 | PARPORT_CONTROL_AUTOFD);
849
850 /* Event 49: PError goes high. */
851 r = parport_wait_peripheral (port,
852 PARPORT_STATUS_PAPEROUT,
853 PARPORT_STATUS_PAPEROUT);
854 if (r) {
855 printk (KERN_DEBUG "%s: PError timeout (%d) "
856 "in ecp_write_block_pio\n", port->name, r);
857 }
858 }
859
860 /* Set up ECP parallel port mode.*/
861 parport_pc_data_forward (port); /* Must be in PS2 mode */
862 parport_pc_frob_control (port,
863 PARPORT_CONTROL_STROBE |
864 PARPORT_CONTROL_AUTOFD,
865 0);
866 r = change_mode (port, ECR_ECP); /* ECP FIFO */
867 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
868 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
869
870 /* Write the data to the FIFO. */
Al Viro7fbacd52005-05-04 05:39:32 +0100871 written = parport_pc_fifo_write_block(port, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
873 /* Finish up. */
874 /* For some hardware we don't want to touch the mode until
875 * the FIFO is empty, so allow 4 seconds for each position
876 * in the fifo.
877 */
878 expire = jiffies + (priv->fifo_depth * (HZ * 4));
879 do {
880 /* Wait for the FIFO to empty */
881 r = change_mode (port, ECR_PS2);
882 if (r != -EBUSY) {
883 break;
884 }
885 } while (time_before (jiffies, expire));
886 if (r == -EBUSY) {
887
888 printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name);
889
890 /* Prevent further data transfer. */
891 frob_set_mode (port, ECR_TST);
892
893 /* Adjust for the contents of the FIFO. */
894 for (written -= priv->fifo_depth; ; written++) {
895 if (inb (ECONTROL (port)) & 0x2) {
896 /* Full up. */
897 break;
898 }
899 outb (0, FIFO (port));
900 }
901
902 /* Reset the FIFO and return to PS2 mode. */
903 frob_set_mode (port, ECR_PS2);
904
905 /* Host transfer recovery. */
906 parport_pc_data_reverse (port); /* Must be in PS2 mode */
907 udelay (5);
908 parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
909 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
910 if (r)
911 printk (KERN_DEBUG "%s: PE,1 timeout (%d) "
912 "in ecp_write_block_pio\n", port->name, r);
913
914 parport_frob_control (port,
915 PARPORT_CONTROL_INIT,
916 PARPORT_CONTROL_INIT);
917 r = parport_wait_peripheral (port,
918 PARPORT_STATUS_PAPEROUT,
919 PARPORT_STATUS_PAPEROUT);
920 if (r)
921 printk (KERN_DEBUG "%s: PE,2 timeout (%d) "
922 "in ecp_write_block_pio\n", port->name, r);
923 }
924
925 r = parport_wait_peripheral (port,
926 PARPORT_STATUS_BUSY,
927 PARPORT_STATUS_BUSY);
928 if(r)
929 printk (KERN_DEBUG
930 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
931 port->name, r);
932
933 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
934
935 return written;
936}
937
938#if 0
939static size_t parport_pc_ecp_read_block_pio (struct parport *port,
940 void *buf, size_t length,
941 int flags)
942{
943 size_t left = length;
944 size_t fifofull;
945 int r;
946 const int fifo = FIFO(port);
947 const struct parport_pc_private *priv = port->physport->private_data;
948 const int fifo_depth = priv->fifo_depth;
949 char *bufp = buf;
950
951 port = port->physport;
952DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
953dump_parport_state ("enter fcn", port);
954
955 /* Special case: a timeout of zero means we cannot call schedule().
956 * Also if O_NONBLOCK is set then use the default implementation. */
957 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
958 return parport_ieee1284_ecp_read_data (port, buf,
959 length, flags);
960
961 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
962 /* If the peripheral is allowed to send RLE compressed
963 * data, it is possible for a byte to expand to 128
964 * bytes in the FIFO. */
965 fifofull = 128;
966 } else {
967 fifofull = fifo_depth;
968 }
969
970 /* If the caller wants less than a full FIFO's worth of data,
971 * go through software emulation. Otherwise we may have to throw
972 * away data. */
973 if (length < fifofull)
974 return parport_ieee1284_ecp_read_data (port, buf,
975 length, flags);
976
977 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
978 /* change to reverse-idle phase (must be in forward-idle) */
979
980 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */
981 parport_frob_control (port,
982 PARPORT_CONTROL_AUTOFD
983 | PARPORT_CONTROL_STROBE,
984 PARPORT_CONTROL_AUTOFD);
985 parport_pc_data_reverse (port); /* Must be in PS2 mode */
986 udelay (5);
987 /* Event 39: Set nInit low to initiate bus reversal */
988 parport_frob_control (port,
989 PARPORT_CONTROL_INIT,
990 0);
991 /* Event 40: Wait for nAckReverse (PError) to go low */
992 r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0);
993 if (r) {
994 printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) "
995 "in ecp_read_block_pio\n", port->name, r);
996 return 0;
997 }
998 }
999
1000 /* Set up ECP FIFO mode.*/
1001/* parport_pc_frob_control (port,
1002 PARPORT_CONTROL_STROBE |
1003 PARPORT_CONTROL_AUTOFD,
1004 PARPORT_CONTROL_AUTOFD); */
1005 r = change_mode (port, ECR_ECP); /* ECP FIFO */
1006 if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name);
1007
1008 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
1009
1010 /* the first byte must be collected manually */
1011dump_parport_state ("pre 43", port);
1012 /* Event 43: Wait for nAck to go low */
1013 r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
1014 if (r) {
1015 /* timed out while reading -- no data */
1016 printk (KERN_DEBUG "PIO read timed out (initial byte)\n");
1017 goto out_no_data;
1018 }
1019 /* read byte */
1020 *bufp++ = inb (DATA (port));
1021 left--;
1022dump_parport_state ("43-44", port);
1023 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */
1024 parport_pc_frob_control (port,
1025 PARPORT_CONTROL_AUTOFD,
1026 0);
1027dump_parport_state ("pre 45", port);
1028 /* Event 45: Wait for nAck to go high */
1029/* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */
1030dump_parport_state ("post 45", port);
1031r = 0;
1032 if (r) {
1033 /* timed out while waiting for peripheral to respond to ack */
1034 printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
1035
1036 /* keep hold of the byte we've got already */
1037 goto out_no_data;
1038 }
1039 /* Event 46: nAutoFd (HostAck) goes low to accept more data */
1040 parport_pc_frob_control (port,
1041 PARPORT_CONTROL_AUTOFD,
1042 PARPORT_CONTROL_AUTOFD);
1043
1044
1045dump_parport_state ("rev idle", port);
1046 /* Do the transfer. */
1047 while (left > fifofull) {
1048 int ret;
1049 unsigned long expire = jiffies + port->cad->timeout;
1050 unsigned char ecrval = inb (ECONTROL (port));
1051
1052 if (need_resched() && time_before (jiffies, expire))
1053 /* Can't yield the port. */
1054 schedule ();
1055
1056 /* At this point, the FIFO may already be full. In
1057 * that case ECP is already holding back the
1058 * peripheral (assuming proper design) with a delayed
1059 * handshake. Work fast to avoid a peripheral
1060 * timeout. */
1061
1062 if (ecrval & 0x01) {
1063 /* FIFO is empty. Wait for interrupt. */
1064dump_parport_state ("FIFO empty", port);
1065
1066 /* Anyone else waiting for the port? */
1067 if (port->waithead) {
1068 printk (KERN_DEBUG "Somebody wants the port\n");
1069 break;
1070 }
1071
1072 /* Clear serviceIntr */
1073 ECR_WRITE (port, ecrval & ~(1<<2));
1074 false_alarm:
1075dump_parport_state ("waiting", port);
1076 ret = parport_wait_event (port, HZ);
1077DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret);
1078 if (ret < 0)
1079 break;
1080 ret = 0;
1081 if (!time_before (jiffies, expire)) {
1082 /* Timed out. */
1083dump_parport_state ("timeout", port);
1084 printk (KERN_DEBUG "PIO read timed out\n");
1085 break;
1086 }
1087 ecrval = inb (ECONTROL (port));
1088 if (!(ecrval & (1<<2))) {
1089 if (need_resched() &&
1090 time_before (jiffies, expire)) {
1091 schedule ();
1092 }
1093 goto false_alarm;
1094 }
1095
1096 /* Depending on how the FIFO threshold was
1097 * set, how long interrupt service took, and
1098 * how fast the peripheral is, we might be
1099 * lucky and have a just filled FIFO. */
1100 continue;
1101 }
1102
1103 if (ecrval & 0x02) {
1104 /* FIFO is full. */
1105dump_parport_state ("FIFO full", port);
1106 insb (fifo, bufp, fifo_depth);
1107 bufp += fifo_depth;
1108 left -= fifo_depth;
1109 continue;
1110 }
1111
1112DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
1113
1114 /* FIFO not filled. We will cycle this loop for a while
1115 * and either the peripheral will fill it faster,
1116 * tripping a fast empty with insb, or we empty it. */
1117 *bufp++ = inb (fifo);
1118 left--;
1119 }
1120
1121 /* scoop up anything left in the FIFO */
1122 while (left && !(inb (ECONTROL (port) & 0x01))) {
1123 *bufp++ = inb (fifo);
1124 left--;
1125 }
1126
1127 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
1128dump_parport_state ("rev idle2", port);
1129
1130out_no_data:
1131
1132 /* Go to forward idle mode to shut the peripheral up (event 47). */
1133 parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
1134
1135 /* event 49: PError goes high */
1136 r = parport_wait_peripheral (port,
1137 PARPORT_STATUS_PAPEROUT,
1138 PARPORT_STATUS_PAPEROUT);
1139 if (r) {
1140 printk (KERN_DEBUG
1141 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1142 port->name, r);
1143 }
1144
1145 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1146
1147 /* Finish up. */
1148 {
1149 int lost = get_fifo_residue (port);
1150 if (lost)
1151 /* Shouldn't happen with compliant peripherals. */
1152 printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
1153 port->name, lost);
1154 }
1155
1156dump_parport_state ("fwd idle", port);
1157 return length - left;
1158}
1159#endif /* 0 */
1160#endif /* IEEE 1284 support */
1161#endif /* Allowed to use FIFO/DMA */
1162
1163
1164/*
1165 * ******************************************
1166 * INITIALISATION AND MODULE STUFF BELOW HERE
1167 * ******************************************
1168 */
1169
1170/* GCC is not inlining extern inline function later overwriten to non-inline,
1171 so we use outlined_ variants here. */
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001172static const struct parport_operations parport_pc_ops =
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
1174 .write_data = parport_pc_write_data,
1175 .read_data = parport_pc_read_data,
1176
1177 .write_control = parport_pc_write_control,
1178 .read_control = parport_pc_read_control,
1179 .frob_control = parport_pc_frob_control,
1180
1181 .read_status = parport_pc_read_status,
1182
1183 .enable_irq = parport_pc_enable_irq,
1184 .disable_irq = parport_pc_disable_irq,
1185
1186 .data_forward = parport_pc_data_forward,
1187 .data_reverse = parport_pc_data_reverse,
1188
1189 .init_state = parport_pc_init_state,
1190 .save_state = parport_pc_save_state,
1191 .restore_state = parport_pc_restore_state,
1192
1193 .epp_write_data = parport_ieee1284_epp_write_data,
1194 .epp_read_data = parport_ieee1284_epp_read_data,
1195 .epp_write_addr = parport_ieee1284_epp_write_addr,
1196 .epp_read_addr = parport_ieee1284_epp_read_addr,
1197
1198 .ecp_write_data = parport_ieee1284_ecp_write_data,
1199 .ecp_read_data = parport_ieee1284_ecp_read_data,
1200 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1201
1202 .compat_write_data = parport_ieee1284_write_compat,
1203 .nibble_read_data = parport_ieee1284_read_nibble,
1204 .byte_read_data = parport_ieee1284_read_byte,
1205
1206 .owner = THIS_MODULE,
1207};
1208
1209#ifdef CONFIG_PARPORT_PC_SUPERIO
1210/* Super-IO chipset detection, Winbond, SMSC */
1211static void __devinit show_parconfig_smsc37c669(int io, int key)
1212{
1213 int cr1,cr4,cra,cr23,cr26,cr27,i=0;
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001214 static const char *const modes[]={
1215 "SPP and Bidirectional (PS/2)",
1216 "EPP and SPP",
1217 "ECP",
1218 "ECP and EPP" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 outb(key,io);
1221 outb(key,io);
1222 outb(1,io);
1223 cr1=inb(io+1);
1224 outb(4,io);
1225 cr4=inb(io+1);
1226 outb(0x0a,io);
1227 cra=inb(io+1);
1228 outb(0x23,io);
1229 cr23=inb(io+1);
1230 outb(0x26,io);
1231 cr26=inb(io+1);
1232 outb(0x27,io);
1233 cr27=inb(io+1);
1234 outb(0xaa,io);
1235
1236 if (verbose_probing) {
1237 printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1238 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
1239 cr1,cr4,cra,cr23,cr26,cr27);
1240
1241 /* The documentation calls DMA and IRQ-Lines by letters, so
1242 the board maker can/will wire them
1243 appropriately/randomly... G=reserved H=IDE-irq, */
1244 printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, "
1245 "fifo threshold=%d\n", cr23*4,
1246 (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-',
1247 (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f);
1248 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
1249 (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no");
1250 printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1251 (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03],
1252 (cr4 & 0x40) ? "1.7" : "1.9");
1253 }
1254
1255 /* Heuristics ! BIOS setup for this mainboard device limits
1256 the choices to standard settings, i.e. io-address and IRQ
1257 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1258 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
1259 if(cr23*4 >=0x100) { /* if active */
1260 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1261 i++;
1262 if(i==NR_SUPERIOS)
1263 printk(KERN_INFO "Super-IO: too many chips!\n");
1264 else {
1265 int d;
1266 switch (cr23*4) {
1267 case 0x3bc:
1268 superios[i].io = 0x3bc;
1269 superios[i].irq = 7;
1270 break;
1271 case 0x378:
1272 superios[i].io = 0x378;
1273 superios[i].irq = 7;
1274 break;
1275 case 0x278:
1276 superios[i].io = 0x278;
1277 superios[i].irq = 5;
1278 }
1279 d=(cr26 &0x0f);
1280 if((d==1) || (d==3))
1281 superios[i].dma= d;
1282 else
1283 superios[i].dma= PARPORT_DMA_NONE;
1284 }
1285 }
1286}
1287
1288
1289static void __devinit show_parconfig_winbond(int io, int key)
1290{
1291 int cr30,cr60,cr61,cr70,cr74,crf0,i=0;
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001292 static const char *const modes[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1294 "EPP-1.9 and SPP",
1295 "ECP",
1296 "ECP and EPP-1.9",
1297 "Standard (SPP)",
1298 "EPP-1.7 and SPP", /* 5 */
1299 "undefined!",
1300 "ECP and EPP-1.7" };
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001301 static char *const irqtypes[] = {
1302 "pulsed low, high-Z",
1303 "follows nACK" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 /* The registers are called compatible-PnP because the
1306 register layout is modelled after ISA-PnP, the access
1307 method is just another ... */
1308 outb(key,io);
1309 outb(key,io);
1310 outb(0x07,io); /* Register 7: Select Logical Device */
1311 outb(0x01,io+1); /* LD1 is Parallel Port */
1312 outb(0x30,io);
1313 cr30=inb(io+1);
1314 outb(0x60,io);
1315 cr60=inb(io+1);
1316 outb(0x61,io);
1317 cr61=inb(io+1);
1318 outb(0x70,io);
1319 cr70=inb(io+1);
1320 outb(0x74,io);
1321 cr74=inb(io+1);
1322 outb(0xf0,io);
1323 crf0=inb(io+1);
1324 outb(0xaa,io);
1325
1326 if (verbose_probing) {
1327 printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x "
1328 "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0);
1329 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1330 (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f );
1331 if ((cr74 & 0x07) > 3)
1332 printk("dma=none\n");
1333 else
1334 printk("dma=%d\n",cr74 & 0x07);
1335 printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1336 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1337 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]);
1338 }
1339
1340 if(cr30 & 0x01) { /* the settings can be interrogated later ... */
1341 while((superios[i].io!= 0) && (i<NR_SUPERIOS))
1342 i++;
1343 if(i==NR_SUPERIOS)
1344 printk(KERN_INFO "Super-IO: too many chips!\n");
1345 else {
1346 superios[i].io = (cr60<<8)|cr61;
1347 superios[i].irq = cr70&0x0f;
1348 superios[i].dma = (((cr74 & 0x07) > 3) ?
1349 PARPORT_DMA_NONE : (cr74 & 0x07));
1350 }
1351 }
1352}
1353
1354static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1355{
1356 const char *type = "unknown";
1357 int id,progif=2;
1358
1359 if (devid == devrev)
1360 /* simple heuristics, we happened to read some
1361 non-winbond register */
1362 return;
1363
1364 id=(devid<<8) | devrev;
1365
1366 /* Values are from public data sheets pdf files, I can just
1367 confirm 83977TF is correct :-) */
1368 if (id == 0x9771) type="83977F/AF";
1369 else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x";
1370 else if (id == 0x9774) type="83977ATF";
1371 else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x";
1372 else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x";
1373 else if ((id & ~0x0f) == 0x5210) type="83627";
1374 else if ((id & ~0x0f) == 0x6010) type="83697HF";
1375 else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;}
1376 else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;}
1377 else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;}
1378 else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;}
1379 else progif=0;
1380
1381 if (verbose_probing)
1382 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
1383 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
1384 efer, key, devid, devrev, oldid, type);
1385
1386 if (progif == 2)
1387 show_parconfig_winbond(efer,key);
1388}
1389
1390static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1391{
1392 const char *type = "unknown";
1393 void (*func)(int io, int key);
1394 int id;
1395
1396 if (devid == devrev)
1397 /* simple heuristics, we happened to read some
1398 non-smsc register */
1399 return;
1400
1401 func=NULL;
1402 id=(devid<<8) | devrev;
1403
1404 if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;}
1405 else if (id==0x6582) type="37c665IR";
1406 else if (devid==0x65) type="37c665GT";
1407 else if (devid==0x66) type="37c666GT";
1408
1409 if (verbose_probing)
1410 printk(KERN_INFO "SMSC chip at EFER=0x%x "
1411 "key=0x%02x devid=%02x devrev=%02x type=%s\n",
1412 efer, key, devid, devrev, type);
1413
1414 if (func)
1415 func(efer,key);
1416}
1417
1418
1419static void __devinit winbond_check(int io, int key)
1420{
1421 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1422
1423 if (!request_region(io, 3, __FUNCTION__))
1424 return;
1425
1426 /* First probe without key */
1427 outb(0x20,io);
1428 x_devid=inb(io+1);
1429 outb(0x21,io);
1430 x_devrev=inb(io+1);
1431 outb(0x09,io);
1432 x_oldid=inb(io+1);
1433
1434 outb(key,io);
1435 outb(key,io); /* Write Magic Sequence to EFER, extended
1436 funtion enable register */
1437 outb(0x20,io); /* Write EFIR, extended function index register */
1438 devid=inb(io+1); /* Read EFDR, extended function data register */
1439 outb(0x21,io);
1440 devrev=inb(io+1);
1441 outb(0x09,io);
1442 oldid=inb(io+1);
1443 outb(0xaa,io); /* Magic Seal */
1444
1445 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1446 goto out; /* protection against false positives */
1447
1448 decode_winbond(io,key,devid,devrev,oldid);
1449out:
1450 release_region(io, 3);
1451}
1452
1453static void __devinit winbond_check2(int io,int key)
1454{
1455 int devid,devrev,oldid,x_devid,x_devrev,x_oldid;
1456
1457 if (!request_region(io, 3, __FUNCTION__))
1458 return;
1459
1460 /* First probe without the key */
1461 outb(0x20,io+2);
1462 x_devid=inb(io+2);
1463 outb(0x21,io+1);
1464 x_devrev=inb(io+2);
1465 outb(0x09,io+1);
1466 x_oldid=inb(io+2);
1467
1468 outb(key,io); /* Write Magic Byte to EFER, extended
1469 funtion enable register */
1470 outb(0x20,io+2); /* Write EFIR, extended function index register */
1471 devid=inb(io+2); /* Read EFDR, extended function data register */
1472 outb(0x21,io+1);
1473 devrev=inb(io+2);
1474 outb(0x09,io+1);
1475 oldid=inb(io+2);
1476 outb(0xaa,io); /* Magic Seal */
1477
1478 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1479 goto out; /* protection against false positives */
1480
1481 decode_winbond(io,key,devid,devrev,oldid);
1482out:
1483 release_region(io, 3);
1484}
1485
1486static void __devinit smsc_check(int io, int key)
1487{
1488 int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev;
1489
1490 if (!request_region(io, 3, __FUNCTION__))
1491 return;
1492
1493 /* First probe without the key */
1494 outb(0x0d,io);
1495 x_oldid=inb(io+1);
1496 outb(0x0e,io);
1497 x_oldrev=inb(io+1);
1498 outb(0x20,io);
1499 x_id=inb(io+1);
1500 outb(0x21,io);
1501 x_rev=inb(io+1);
1502
1503 outb(key,io);
1504 outb(key,io); /* Write Magic Sequence to EFER, extended
1505 funtion enable register */
1506 outb(0x0d,io); /* Write EFIR, extended function index register */
1507 oldid=inb(io+1); /* Read EFDR, extended function data register */
1508 outb(0x0e,io);
1509 oldrev=inb(io+1);
1510 outb(0x20,io);
1511 id=inb(io+1);
1512 outb(0x21,io);
1513 rev=inb(io+1);
1514 outb(0xaa,io); /* Magic Seal */
1515
1516 if ((x_id == id) && (x_oldrev == oldrev) &&
1517 (x_oldid == oldid) && (x_rev == rev))
1518 goto out; /* protection against false positives */
1519
1520 decode_smsc(io,key,oldid,oldrev);
1521out:
1522 release_region(io, 3);
1523}
1524
1525
1526static void __devinit detect_and_report_winbond (void)
1527{
1528 if (verbose_probing)
1529 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
1530 winbond_check(0x3f0,0x87);
1531 winbond_check(0x370,0x87);
1532 winbond_check(0x2e ,0x87);
1533 winbond_check(0x4e ,0x87);
1534 winbond_check(0x3f0,0x86);
1535 winbond_check2(0x250,0x88);
1536 winbond_check2(0x250,0x89);
1537}
1538
1539static void __devinit detect_and_report_smsc (void)
1540{
1541 if (verbose_probing)
1542 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
1543 smsc_check(0x3f0,0x55);
1544 smsc_check(0x370,0x55);
1545 smsc_check(0x3f0,0x44);
1546 smsc_check(0x370,0x44);
1547}
1548#endif /* CONFIG_PARPORT_PC_SUPERIO */
1549
Jean Delvare0bb92e62007-02-20 13:58:18 -08001550static int get_superio_dma (struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551{
1552 int i=0;
1553 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1554 i++;
1555 if (i!=NR_SUPERIOS)
1556 return superios[i].dma;
1557 return PARPORT_DMA_NONE;
1558}
1559
Randy.Dunlap96766a32006-04-18 22:21:57 -07001560static int get_superio_irq (struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561{
1562 int i=0;
1563 while( (superios[i].io != p->base) && (i<NR_SUPERIOS))
1564 i++;
1565 if (i!=NR_SUPERIOS)
1566 return superios[i].irq;
1567 return PARPORT_IRQ_NONE;
1568}
1569
1570
1571/* --- Mode detection ------------------------------------- */
1572
1573/*
1574 * Checks for port existence, all ports support SPP MODE
1575 * Returns:
1576 * 0 : No parallel port at this address
1577 * PARPORT_MODE_PCSPP : SPP port detected
1578 * (if the user specified an ioport himself,
1579 * this shall always be the case!)
1580 *
1581 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07001582static int parport_SPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583{
1584 unsigned char r, w;
1585
1586 /*
1587 * first clear an eventually pending EPP timeout
1588 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1589 * that does not even respond to SPP cycles if an EPP
1590 * timeout is pending
1591 */
1592 clear_epp_timeout(pb);
1593
1594 /* Do a simple read-write test to make sure the port exists. */
1595 w = 0xc;
1596 outb (w, CONTROL (pb));
1597
1598 /* Is there a control register that we can read from? Some
1599 * ports don't allow reads, so read_control just returns a
1600 * software copy. Some ports _do_ allow reads, so bypass the
1601 * software copy here. In addition, some bits aren't
1602 * writable. */
1603 r = inb (CONTROL (pb));
1604 if ((r & 0xf) == w) {
1605 w = 0xe;
1606 outb (w, CONTROL (pb));
1607 r = inb (CONTROL (pb));
1608 outb (0xc, CONTROL (pb));
1609 if ((r & 0xf) == w)
1610 return PARPORT_MODE_PCSPP;
1611 }
1612
1613 if (user_specified)
1614 /* That didn't work, but the user thinks there's a
1615 * port here. */
1616 printk (KERN_INFO "parport 0x%lx (WARNING): CTR: "
1617 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1618
1619 /* Try the data register. The data lines aren't tri-stated at
1620 * this stage, so we expect back what we wrote. */
1621 w = 0xaa;
1622 parport_pc_write_data (pb, w);
1623 r = parport_pc_read_data (pb);
1624 if (r == w) {
1625 w = 0x55;
1626 parport_pc_write_data (pb, w);
1627 r = parport_pc_read_data (pb);
1628 if (r == w)
1629 return PARPORT_MODE_PCSPP;
1630 }
1631
1632 if (user_specified) {
1633 /* Didn't work, but the user is convinced this is the
1634 * place. */
1635 printk (KERN_INFO "parport 0x%lx (WARNING): DATA: "
1636 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1637 printk (KERN_INFO "parport 0x%lx: You gave this address, "
1638 "but there is probably no parallel port there!\n",
1639 pb->base);
1640 }
1641
1642 /* It's possible that we can't read the control register or
1643 * the data register. In that case just believe the user. */
1644 if (user_specified)
1645 return PARPORT_MODE_PCSPP;
1646
1647 return 0;
1648}
1649
1650/* Check for ECR
1651 *
1652 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1653 * on these cards actually accesses the CTR.
1654 *
1655 * Modern cards don't do this but reading from ECR will return 0xff
1656 * regardless of what is written here if the card does NOT support
1657 * ECP.
1658 *
1659 * We first check to see if ECR is the same as CTR. If not, the low
1660 * two bits of ECR aren't writable, so we check by writing ECR and
1661 * reading it back to see if it's what we expect.
1662 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07001663static int parport_ECR_present(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
1665 struct parport_pc_private *priv = pb->private_data;
1666 unsigned char r = 0xc;
1667
1668 outb (r, CONTROL (pb));
1669 if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) {
1670 outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */
1671
1672 r = inb (CONTROL (pb));
1673 if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2))
1674 goto no_reg; /* Sure that no ECR register exists */
1675 }
1676
1677 if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1)
1678 goto no_reg;
1679
1680 ECR_WRITE (pb, 0x34);
1681 if (inb (ECONTROL (pb)) != 0x35)
1682 goto no_reg;
1683
1684 priv->ecr = 1;
1685 outb (0xc, CONTROL (pb));
1686
1687 /* Go to mode 000 */
1688 frob_set_mode (pb, ECR_SPP);
1689
1690 return 1;
1691
1692 no_reg:
1693 outb (0xc, CONTROL (pb));
1694 return 0;
1695}
1696
1697#ifdef CONFIG_PARPORT_1284
1698/* Detect PS/2 support.
1699 *
1700 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1701 * allows us to read data from the data lines. In theory we would get back
1702 * 0xff but any peripheral attached to the port may drag some or all of the
1703 * lines down to zero. So if we get back anything that isn't the contents
1704 * of the data register we deem PS/2 support to be present.
1705 *
1706 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1707 * drivers, but an external peripheral with sufficiently beefy drivers of
1708 * its own can overpower them and assert its own levels onto the bus, from
1709 * where they can then be read back as normal. Ports with this property
1710 * and the right type of device attached are likely to fail the SPP test,
1711 * (as they will appear to have stuck bits) and so the fact that they might
1712 * be misdetected here is rather academic.
1713 */
1714
Randy.Dunlap96766a32006-04-18 22:21:57 -07001715static int parport_PS2_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716{
1717 int ok = 0;
1718
1719 clear_epp_timeout(pb);
1720
1721 /* try to tri-state the buffer */
1722 parport_pc_data_reverse (pb);
1723
1724 parport_pc_write_data(pb, 0x55);
1725 if (parport_pc_read_data(pb) != 0x55) ok++;
1726
1727 parport_pc_write_data(pb, 0xaa);
1728 if (parport_pc_read_data(pb) != 0xaa) ok++;
1729
1730 /* cancel input mode */
1731 parport_pc_data_forward (pb);
1732
1733 if (ok) {
1734 pb->modes |= PARPORT_MODE_TRISTATE;
1735 } else {
1736 struct parport_pc_private *priv = pb->private_data;
1737 priv->ctr_writable &= ~0x20;
1738 }
1739
1740 return ok;
1741}
1742
1743#ifdef CONFIG_PARPORT_PC_FIFO
1744static int __devinit parport_ECP_supported(struct parport *pb)
1745{
1746 int i;
1747 int config, configb;
1748 int pword;
1749 struct parport_pc_private *priv = pb->private_data;
1750 /* Translate ECP intrLine to ISA irq value */
1751 static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 };
1752
1753 /* If there is no ECR, we have no hope of supporting ECP. */
1754 if (!priv->ecr)
1755 return 0;
1756
1757 /* Find out FIFO depth */
1758 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1759 ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */
1760 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++)
1761 outb (0xaa, FIFO (pb));
1762
1763 /*
1764 * Using LGS chipset it uses ECR register, but
1765 * it doesn't support ECP or FIFO MODE
1766 */
1767 if (i == 1024) {
1768 ECR_WRITE (pb, ECR_SPP << 5);
1769 return 0;
1770 }
1771
1772 priv->fifo_depth = i;
1773 if (verbose_probing)
1774 printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
1775
1776 /* Find out writeIntrThreshold */
1777 frob_econtrol (pb, 1<<2, 1<<2);
1778 frob_econtrol (pb, 1<<2, 0);
1779 for (i = 1; i <= priv->fifo_depth; i++) {
1780 inb (FIFO (pb));
1781 udelay (50);
1782 if (inb (ECONTROL (pb)) & (1<<2))
1783 break;
1784 }
1785
1786 if (i <= priv->fifo_depth) {
1787 if (verbose_probing)
1788 printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
1789 pb->base, i);
1790 } else
1791 /* Number of bytes we know we can write if we get an
1792 interrupt. */
1793 i = 0;
1794
1795 priv->writeIntrThreshold = i;
1796
1797 /* Find out readIntrThreshold */
1798 frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */
1799 parport_pc_data_reverse (pb); /* Must be in PS2 mode */
1800 frob_set_mode (pb, ECR_TST); /* Test FIFO */
1801 frob_econtrol (pb, 1<<2, 1<<2);
1802 frob_econtrol (pb, 1<<2, 0);
1803 for (i = 1; i <= priv->fifo_depth; i++) {
1804 outb (0xaa, FIFO (pb));
1805 if (inb (ECONTROL (pb)) & (1<<2))
1806 break;
1807 }
1808
1809 if (i <= priv->fifo_depth) {
1810 if (verbose_probing)
1811 printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n",
1812 pb->base, i);
1813 } else
1814 /* Number of bytes we can read if we get an interrupt. */
1815 i = 0;
1816
1817 priv->readIntrThreshold = i;
1818
1819 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
1820 ECR_WRITE (pb, 0xf4); /* Configuration mode */
1821 config = inb (CONFIGA (pb));
1822 pword = (config >> 4) & 0x7;
1823 switch (pword) {
1824 case 0:
1825 pword = 2;
1826 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1827 pb->base);
1828 break;
1829 case 2:
1830 pword = 4;
1831 printk (KERN_WARNING "0x%lx: Unsupported pword size!\n",
1832 pb->base);
1833 break;
1834 default:
1835 printk (KERN_WARNING "0x%lx: Unknown implementation ID\n",
1836 pb->base);
1837 /* Assume 1 */
1838 case 1:
1839 pword = 1;
1840 }
1841 priv->pword = pword;
1842
1843 if (verbose_probing) {
1844 printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword);
1845
1846 printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
1847 config & 0x80 ? "Level" : "Pulses");
1848
1849 configb = inb (CONFIGB (pb));
1850 printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
1851 pb->base, config, configb);
1852 printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1853 if ((configb >>3) & 0x07)
1854 printk("%d",intrline[(configb >>3) & 0x07]);
1855 else
1856 printk("<none or set by other means>");
1857 printk (" dma=");
1858 if( (configb & 0x03 ) == 0x00)
1859 printk("<none or set by other means>\n");
1860 else
1861 printk("%d\n",configb & 0x07);
1862 }
1863
1864 /* Go back to mode 000 */
1865 frob_set_mode (pb, ECR_SPP);
1866
1867 return 1;
1868}
1869#endif
1870
Randy.Dunlap96766a32006-04-18 22:21:57 -07001871static int parport_ECPPS2_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872{
1873 const struct parport_pc_private *priv = pb->private_data;
1874 int result;
1875 unsigned char oecr;
1876
1877 if (!priv->ecr)
1878 return 0;
1879
1880 oecr = inb (ECONTROL (pb));
1881 ECR_WRITE (pb, ECR_PS2 << 5);
1882 result = parport_PS2_supported(pb);
1883 ECR_WRITE (pb, oecr);
1884 return result;
1885}
1886
1887/* EPP mode detection */
1888
Randy.Dunlap96766a32006-04-18 22:21:57 -07001889static int parport_EPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890{
1891 const struct parport_pc_private *priv = pb->private_data;
1892
1893 /*
1894 * Theory:
1895 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1896 * when EPP is possible and is set high when an EPP timeout
1897 * occurs (EPP uses the HALT line to stop the CPU while it does
1898 * the byte transfer, an EPP timeout occurs if the attached
1899 * device fails to respond after 10 micro seconds).
1900 *
1901 * This bit is cleared by either reading it (National Semi)
1902 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1903 * This bit is always high in non EPP modes.
1904 */
1905
1906 /* If EPP timeout bit clear then EPP available */
1907 if (!clear_epp_timeout(pb)) {
1908 return 0; /* No way to clear timeout */
1909 }
1910
1911 /* Check for Intel bug. */
1912 if (priv->ecr) {
1913 unsigned char i;
1914 for (i = 0x00; i < 0x80; i += 0x20) {
1915 ECR_WRITE (pb, i);
1916 if (clear_epp_timeout (pb)) {
1917 /* Phony EPP in ECP. */
1918 return 0;
1919 }
1920 }
1921 }
1922
1923 pb->modes |= PARPORT_MODE_EPP;
1924
1925 /* Set up access functions to use EPP hardware. */
1926 pb->ops->epp_read_data = parport_pc_epp_read_data;
1927 pb->ops->epp_write_data = parport_pc_epp_write_data;
1928 pb->ops->epp_read_addr = parport_pc_epp_read_addr;
1929 pb->ops->epp_write_addr = parport_pc_epp_write_addr;
1930
1931 return 1;
1932}
1933
Randy.Dunlap96766a32006-04-18 22:21:57 -07001934static int parport_ECPEPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935{
1936 struct parport_pc_private *priv = pb->private_data;
1937 int result;
1938 unsigned char oecr;
1939
1940 if (!priv->ecr) {
1941 return 0;
1942 }
1943
1944 oecr = inb (ECONTROL (pb));
1945 /* Search for SMC style EPP+ECP mode */
1946 ECR_WRITE (pb, 0x80);
1947 outb (0x04, CONTROL (pb));
1948 result = parport_EPP_supported(pb);
1949
1950 ECR_WRITE (pb, oecr);
1951
1952 if (result) {
1953 /* Set up access functions to use ECP+EPP hardware. */
1954 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
1955 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
1956 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
1957 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
1958 }
1959
1960 return result;
1961}
1962
1963#else /* No IEEE 1284 support */
1964
1965/* Don't bother probing for modes we know we won't use. */
1966static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
1967#ifdef CONFIG_PARPORT_PC_FIFO
1968static int __devinit parport_ECP_supported(struct parport *pb) { return 0; }
1969#endif
1970static int __devinit parport_EPP_supported(struct parport *pb) { return 0; }
1971static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;}
1972static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;}
1973
1974#endif /* No IEEE 1284 support */
1975
1976/* --- IRQ detection -------------------------------------- */
1977
1978/* Only if supports ECP mode */
Randy Dunlap44389822006-12-06 20:38:33 -08001979static int programmable_irq_support(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980{
1981 int irq, intrLine;
1982 unsigned char oecr = inb (ECONTROL (pb));
1983 static const int lookup[8] = {
1984 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
1985 };
1986
1987 ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */
1988
1989 intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07;
1990 irq = lookup[intrLine];
1991
1992 ECR_WRITE (pb, oecr);
1993 return irq;
1994}
1995
Randy Dunlap44389822006-12-06 20:38:33 -08001996static int irq_probe_ECP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997{
1998 int i;
1999 unsigned long irqs;
2000
2001 irqs = probe_irq_on();
2002
2003 ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */
2004 ECR_WRITE (pb, (ECR_TST << 5) | 0x04);
2005 ECR_WRITE (pb, ECR_TST << 5);
2006
2007 /* If Full FIFO sure that writeIntrThreshold is generated */
2008 for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++)
2009 outb (0xaa, FIFO (pb));
2010
2011 pb->irq = probe_irq_off(irqs);
2012 ECR_WRITE (pb, ECR_SPP << 5);
2013
2014 if (pb->irq <= 0)
2015 pb->irq = PARPORT_IRQ_NONE;
2016
2017 return pb->irq;
2018}
2019
2020/*
2021 * This detection seems that only works in National Semiconductors
2022 * This doesn't work in SMC, LGS, and Winbond
2023 */
Randy Dunlap44389822006-12-06 20:38:33 -08002024static int irq_probe_EPP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025{
2026#ifndef ADVANCED_DETECT
2027 return PARPORT_IRQ_NONE;
2028#else
2029 int irqs;
2030 unsigned char oecr;
2031
2032 if (pb->modes & PARPORT_MODE_PCECR)
2033 oecr = inb (ECONTROL (pb));
2034
2035 irqs = probe_irq_on();
2036
2037 if (pb->modes & PARPORT_MODE_PCECR)
2038 frob_econtrol (pb, 0x10, 0x10);
2039
2040 clear_epp_timeout(pb);
2041 parport_pc_frob_control (pb, 0x20, 0x20);
2042 parport_pc_frob_control (pb, 0x10, 0x10);
2043 clear_epp_timeout(pb);
2044
2045 /* Device isn't expecting an EPP read
2046 * and generates an IRQ.
2047 */
2048 parport_pc_read_epp(pb);
2049 udelay(20);
2050
2051 pb->irq = probe_irq_off (irqs);
2052 if (pb->modes & PARPORT_MODE_PCECR)
2053 ECR_WRITE (pb, oecr);
2054 parport_pc_write_control(pb, 0xc);
2055
2056 if (pb->irq <= 0)
2057 pb->irq = PARPORT_IRQ_NONE;
2058
2059 return pb->irq;
2060#endif /* Advanced detection */
2061}
2062
Randy Dunlap44389822006-12-06 20:38:33 -08002063static int irq_probe_SPP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064{
2065 /* Don't even try to do this. */
2066 return PARPORT_IRQ_NONE;
2067}
2068
2069/* We will attempt to share interrupt requests since other devices
2070 * such as sound cards and network cards seem to like using the
2071 * printer IRQs.
2072 *
2073 * When ECP is available we can autoprobe for IRQs.
2074 * NOTE: If we can autoprobe it, we can register the IRQ.
2075 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07002076static int parport_irq_probe(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077{
2078 struct parport_pc_private *priv = pb->private_data;
2079
2080 if (priv->ecr) {
2081 pb->irq = programmable_irq_support(pb);
2082
2083 if (pb->irq == PARPORT_IRQ_NONE)
2084 pb->irq = irq_probe_ECP(pb);
2085 }
2086
2087 if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
2088 (pb->modes & PARPORT_MODE_EPP))
2089 pb->irq = irq_probe_EPP(pb);
2090
2091 clear_epp_timeout(pb);
2092
2093 if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
2094 pb->irq = irq_probe_EPP(pb);
2095
2096 clear_epp_timeout(pb);
2097
2098 if (pb->irq == PARPORT_IRQ_NONE)
2099 pb->irq = irq_probe_SPP(pb);
2100
2101 if (pb->irq == PARPORT_IRQ_NONE)
2102 pb->irq = get_superio_irq(pb);
2103
2104 return pb->irq;
2105}
2106
2107/* --- DMA detection -------------------------------------- */
2108
2109/* Only if chipset conforms to ECP ISA Interface Standard */
Jean Delvare0bb92e62007-02-20 13:58:18 -08002110static int programmable_dma_support (struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111{
2112 unsigned char oecr = inb (ECONTROL (p));
2113 int dma;
2114
2115 frob_set_mode (p, ECR_CNF);
2116
2117 dma = inb (CONFIGB(p)) & 0x07;
2118 /* 000: Indicates jumpered 8-bit DMA if read-only.
2119 100: Indicates jumpered 16-bit DMA if read-only. */
2120 if ((dma & 0x03) == 0)
2121 dma = PARPORT_DMA_NONE;
2122
2123 ECR_WRITE (p, oecr);
2124 return dma;
2125}
2126
Jean Delvare0bb92e62007-02-20 13:58:18 -08002127static int parport_dma_probe (struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128{
2129 const struct parport_pc_private *priv = p->private_data;
2130 if (priv->ecr)
2131 p->dma = programmable_dma_support(p); /* ask ECP chipset first */
2132 if (p->dma == PARPORT_DMA_NONE) {
2133 /* ask known Super-IO chips proper, although these
2134 claim ECP compatible, some don't report their DMA
2135 conforming to ECP standards */
2136 p->dma = get_superio_dma(p);
2137 }
2138
2139 return p->dma;
2140}
2141
2142/* --- Initialisation code -------------------------------- */
2143
2144static LIST_HEAD(ports_list);
2145static DEFINE_SPINLOCK(ports_lock);
2146
2147struct parport *parport_pc_probe_port (unsigned long int base,
2148 unsigned long int base_hi,
2149 int irq, int dma,
David Brownellc15a3832007-05-08 00:27:35 -07002150 struct device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
2152 struct parport_pc_private *priv;
2153 struct parport_operations *ops;
2154 struct parport *p;
2155 int probedirq = PARPORT_IRQ_NONE;
2156 struct resource *base_res;
2157 struct resource *ECR_res = NULL;
2158 struct resource *EPP_res = NULL;
2159
2160 ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL);
2161 if (!ops)
2162 goto out1;
2163
2164 priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL);
2165 if (!priv)
2166 goto out2;
2167
2168 /* a misnomer, actually - it's allocate and reserve parport number */
2169 p = parport_register_port(base, irq, dma, ops);
2170 if (!p)
2171 goto out3;
2172
2173 base_res = request_region(base, 3, p->name);
2174 if (!base_res)
2175 goto out4;
2176
2177 memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations));
2178 priv->ctr = 0xc;
2179 priv->ctr_writable = ~0x10;
2180 priv->ecr = 0;
2181 priv->fifo_depth = 0;
2182 priv->dma_buf = NULL;
2183 priv->dma_handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 INIT_LIST_HEAD(&priv->list);
2185 priv->port = p;
David Brownellc15a3832007-05-08 00:27:35 -07002186
2187 p->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 p->base_hi = base_hi;
2189 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2190 p->private_data = priv;
2191
2192 if (base_hi) {
2193 ECR_res = request_region(base_hi, 3, p->name);
2194 if (ECR_res)
2195 parport_ECR_present(p);
2196 }
2197
2198 if (base != 0x3bc) {
2199 EPP_res = request_region(base+0x3, 5, p->name);
2200 if (EPP_res)
2201 if (!parport_EPP_supported(p))
2202 parport_ECPEPP_supported(p);
2203 }
2204 if (!parport_SPP_supported (p))
2205 /* No port. */
2206 goto out5;
2207 if (priv->ecr)
2208 parport_ECPPS2_supported(p);
2209 else
2210 parport_PS2_supported(p);
2211
2212 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
2213
2214 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2215 if (p->base_hi && priv->ecr)
2216 printk(" (0x%lx)", p->base_hi);
2217 if (p->irq == PARPORT_IRQ_AUTO) {
2218 p->irq = PARPORT_IRQ_NONE;
2219 parport_irq_probe(p);
2220 } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2221 p->irq = PARPORT_IRQ_NONE;
2222 parport_irq_probe(p);
2223 probedirq = p->irq;
2224 p->irq = PARPORT_IRQ_NONE;
2225 }
2226 if (p->irq != PARPORT_IRQ_NONE) {
2227 printk(", irq %d", p->irq);
2228 priv->ctr_writable |= 0x10;
2229
2230 if (p->dma == PARPORT_DMA_AUTO) {
2231 p->dma = PARPORT_DMA_NONE;
2232 parport_dma_probe(p);
2233 }
2234 }
2235 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
2236 is mandatory (see above) */
2237 p->dma = PARPORT_DMA_NONE;
2238
2239#ifdef CONFIG_PARPORT_PC_FIFO
2240 if (parport_ECP_supported(p) &&
2241 p->dma != PARPORT_DMA_NOFIFO &&
2242 priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2243 p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
2244 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2245#ifdef CONFIG_PARPORT_1284
2246 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2247 /* currently broken, but working on it.. (FB) */
2248 /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
2249#endif /* IEEE 1284 support */
2250 if (p->dma != PARPORT_DMA_NONE) {
2251 printk(", dma %d", p->dma);
2252 p->modes |= PARPORT_MODE_DMA;
2253 }
2254 else printk(", using FIFO");
2255 }
2256 else
2257 /* We can't use the DMA channel after all. */
2258 p->dma = PARPORT_DMA_NONE;
2259#endif /* Allowed to use FIFO/DMA */
2260
2261 printk(" [");
2262#define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
2263 {
2264 int f = 0;
2265 printmode(PCSPP);
2266 printmode(TRISTATE);
2267 printmode(COMPAT)
2268 printmode(EPP);
2269 printmode(ECP);
2270 printmode(DMA);
2271 }
2272#undef printmode
2273#ifndef CONFIG_PARPORT_1284
2274 printk ("(,...)");
2275#endif /* CONFIG_PARPORT_1284 */
2276 printk("]\n");
2277 if (probedirq != PARPORT_IRQ_NONE)
2278 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2279
2280 /* If No ECP release the ports grabbed above. */
2281 if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
2282 release_region(base_hi, 3);
2283 ECR_res = NULL;
2284 }
2285 /* Likewise for EEP ports */
2286 if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
2287 release_region(base+3, 5);
2288 EPP_res = NULL;
2289 }
2290 if (p->irq != PARPORT_IRQ_NONE) {
2291 if (request_irq (p->irq, parport_pc_interrupt,
2292 0, p->name, p)) {
2293 printk (KERN_WARNING "%s: irq %d in use, "
2294 "resorting to polled operation\n",
2295 p->name, p->irq);
2296 p->irq = PARPORT_IRQ_NONE;
2297 p->dma = PARPORT_DMA_NONE;
2298 }
2299
2300#ifdef CONFIG_PARPORT_PC_FIFO
Al Viro7fbacd52005-05-04 05:39:32 +01002301#ifdef HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 if (p->dma != PARPORT_DMA_NONE) {
2303 if (request_dma (p->dma, p->name)) {
2304 printk (KERN_WARNING "%s: dma %d in use, "
2305 "resorting to PIO operation\n",
2306 p->name, p->dma);
2307 p->dma = PARPORT_DMA_NONE;
2308 } else {
2309 priv->dma_buf =
David Brownellc15a3832007-05-08 00:27:35 -07002310 dma_alloc_coherent(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311 PAGE_SIZE,
David Brownellc15a3832007-05-08 00:27:35 -07002312 &priv->dma_handle,
2313 GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314 if (! priv->dma_buf) {
2315 printk (KERN_WARNING "%s: "
2316 "cannot get buffer for DMA, "
2317 "resorting to PIO operation\n",
2318 p->name);
2319 free_dma(p->dma);
2320 p->dma = PARPORT_DMA_NONE;
2321 }
2322 }
2323 }
Al Viro7fbacd52005-05-04 05:39:32 +01002324#endif
2325#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 }
2327
2328 /* Done probing. Now put the port into a sensible start-up state. */
2329 if (priv->ecr)
2330 /*
2331 * Put the ECP detected port in PS2 mode.
2332 * Do this also for ports that have ECR but don't do ECP.
2333 */
2334 ECR_WRITE (p, 0x34);
2335
2336 parport_pc_write_data(p, 0);
2337 parport_pc_data_forward (p);
2338
2339 /* Now that we've told the sharing engine about the port, and
2340 found out its characteristics, let the high-level drivers
2341 know about it. */
2342 spin_lock(&ports_lock);
2343 list_add(&priv->list, &ports_list);
2344 spin_unlock(&ports_lock);
2345 parport_announce_port (p);
2346
2347 return p;
2348
2349out5:
2350 if (ECR_res)
2351 release_region(base_hi, 3);
2352 if (EPP_res)
2353 release_region(base+0x3, 5);
2354 release_region(base, 3);
2355out4:
2356 parport_put_port(p);
2357out3:
2358 kfree (priv);
2359out2:
2360 kfree (ops);
2361out1:
2362 return NULL;
2363}
2364
2365EXPORT_SYMBOL (parport_pc_probe_port);
2366
2367void parport_pc_unregister_port (struct parport *p)
2368{
2369 struct parport_pc_private *priv = p->private_data;
2370 struct parport_operations *ops = p->ops;
2371
2372 parport_remove_port(p);
2373 spin_lock(&ports_lock);
2374 list_del_init(&priv->list);
2375 spin_unlock(&ports_lock);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002376#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 if (p->dma != PARPORT_DMA_NONE)
2378 free_dma(p->dma);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002379#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 if (p->irq != PARPORT_IRQ_NONE)
2381 free_irq(p->irq, p);
2382 release_region(p->base, 3);
2383 if (p->size > 3)
2384 release_region(p->base + 3, p->size - 3);
2385 if (p->modes & PARPORT_MODE_ECP)
2386 release_region(p->base_hi, 3);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002387#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (priv->dma_buf)
David Brownellc15a3832007-05-08 00:27:35 -07002389 dma_free_coherent(p->physport->dev, PAGE_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 priv->dma_buf,
2391 priv->dma_handle);
Al Viro7fbacd52005-05-04 05:39:32 +01002392#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 kfree (p->private_data);
2394 parport_put_port(p);
2395 kfree (ops); /* hope no-one cached it */
2396}
2397
2398EXPORT_SYMBOL (parport_pc_unregister_port);
2399
2400#ifdef CONFIG_PCI
2401
2402/* ITE support maintained by Rich Liu <richliu@poorman.org> */
2403static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq,
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002404 int autodma,
2405 const struct parport_pc_via_data *via)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406{
2407 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2408 struct resource *base_res;
2409 u32 ite8872set;
2410 u32 ite8872_lpt, ite8872_lpthi;
2411 u8 ite8872_irq, type;
2412 char *fake_name = "parport probe";
2413 int irq;
2414 int i;
2415
2416 DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n");
2417
2418 // make sure which one chip
2419 for(i = 0; i < 5; i++) {
2420 base_res = request_region(inta_addr[i], 0x8, fake_name);
2421 if (base_res) {
2422 int test;
2423 pci_write_config_dword (pdev, 0x60,
2424 0xe7000000 | inta_addr[i]);
2425 pci_write_config_dword (pdev, 0x78,
2426 0x00000000 | inta_addr[i]);
2427 test = inb (inta_addr[i]);
2428 if (test != 0xff) break;
2429 release_region(inta_addr[i], 0x8);
2430 }
2431 }
2432 if(i >= 5) {
2433 printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
2434 return 0;
2435 }
2436
2437 type = inb (inta_addr[i] + 0x18);
2438 type &= 0x0f;
2439
2440 switch (type) {
2441 case 0x2:
2442 printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n");
2443 ite8872set = 0x64200000;
2444 break;
2445 case 0xa:
2446 printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n");
2447 ite8872set = 0x64200000;
2448 break;
2449 case 0xe:
2450 printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
2451 ite8872set = 0x64e00000;
2452 break;
2453 case 0x6:
2454 printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n");
2455 return 0;
2456 case 0x8:
2457 DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
2458 return 0;
2459 default:
2460 printk (KERN_INFO "parport_pc: unknown ITE887x\n");
2461 printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' "
2462 "output to Rich.Liu@ite.com.tw\n");
2463 return 0;
2464 }
2465
2466 pci_read_config_byte (pdev, 0x3c, &ite8872_irq);
2467 pci_read_config_dword (pdev, 0x1c, &ite8872_lpt);
2468 ite8872_lpt &= 0x0000ff00;
2469 pci_read_config_dword (pdev, 0x20, &ite8872_lpthi);
2470 ite8872_lpthi &= 0x0000ff00;
2471 pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2472 pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2473 pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2474 // SET SPP&EPP , Parallel Port NO DMA , Enable All Function
2475 // SET Parallel IRQ
2476 pci_write_config_dword (pdev, 0x9c,
2477 ite8872set | (ite8872_irq * 0x11111));
2478
2479 DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2480 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
2481 ite8872_lpt);
2482 DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
2483 ite8872_lpthi);
2484
2485 /* Let the user (or defaults) steer us away from interrupts */
2486 irq = ite8872_irq;
2487 if (autoirq != PARPORT_IRQ_AUTO)
2488 irq = PARPORT_IRQ_NONE;
2489
2490 /*
2491 * Release the resource so that parport_pc_probe_port can get it.
2492 */
2493 release_resource(base_res);
2494 if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi,
David Brownellc15a3832007-05-08 00:27:35 -07002495 irq, PARPORT_DMA_NONE, &pdev->dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 printk (KERN_INFO
2497 "parport_pc: ITE 8872 parallel port: io=0x%X",
2498 ite8872_lpt);
2499 if (irq != PARPORT_IRQ_NONE)
2500 printk (", irq=%d", irq);
2501 printk ("\n");
2502 return 1;
2503 }
2504
2505 return 0;
2506}
2507
2508/* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
2509 based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
2510static int __devinitdata parport_init_mode = 0;
2511
2512/* Data for two known VIA chips */
2513static struct parport_pc_via_data via_686a_data __devinitdata = {
2514 0x51,
2515 0x50,
2516 0x85,
2517 0x02,
2518 0xE2,
2519 0xF0,
2520 0xE6
2521};
2522static struct parport_pc_via_data via_8231_data __devinitdata = {
2523 0x45,
2524 0x44,
2525 0x50,
2526 0x04,
2527 0xF2,
2528 0xFA,
2529 0xF6
2530};
2531
2532static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq,
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002533 int autodma,
2534 const struct parport_pc_via_data *via)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535{
2536 u8 tmp, tmp2, siofunc;
2537 u8 ppcontrol = 0;
2538 int dma, irq;
2539 unsigned port1, port2;
2540 unsigned have_epp = 0;
2541
2542 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
2543
2544 switch(parport_init_mode)
2545 {
2546 case 1:
2547 printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
2548 siofunc = VIA_FUNCTION_PARPORT_SPP;
2549 break;
2550 case 2:
2551 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
2552 siofunc = VIA_FUNCTION_PARPORT_SPP;
2553 ppcontrol = VIA_PARPORT_BIDIR;
2554 break;
2555 case 3:
2556 printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
2557 siofunc = VIA_FUNCTION_PARPORT_EPP;
2558 ppcontrol = VIA_PARPORT_BIDIR;
2559 have_epp = 1;
2560 break;
2561 case 4:
2562 printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
2563 siofunc = VIA_FUNCTION_PARPORT_ECP;
2564 ppcontrol = VIA_PARPORT_BIDIR;
2565 break;
2566 case 5:
2567 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
2568 siofunc = VIA_FUNCTION_PARPORT_ECP;
2569 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
2570 have_epp = 1;
2571 break;
2572 default:
2573 printk(KERN_DEBUG "parport_pc: probing current configuration\n");
2574 siofunc = VIA_FUNCTION_PROBE;
2575 break;
2576 }
2577 /*
2578 * unlock super i/o configuration
2579 */
2580 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2581 tmp |= via->via_pci_superio_config_data;
2582 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2583
2584 /* Bits 1-0: Parallel Port Mode / Enable */
2585 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2586 tmp = inb (VIA_CONFIG_DATA);
2587 /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
2588 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2589 tmp2 = inb (VIA_CONFIG_DATA);
2590 if (siofunc == VIA_FUNCTION_PROBE)
2591 {
2592 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
2593 ppcontrol = tmp2;
2594 }
2595 else
2596 {
2597 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2598 tmp |= siofunc;
2599 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2600 outb(tmp, VIA_CONFIG_DATA);
2601 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2602 tmp2 |= ppcontrol;
2603 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2604 outb(tmp2, VIA_CONFIG_DATA);
2605 }
2606
2607 /* Parallel Port I/O Base Address, bits 9-2 */
2608 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2609 port1 = inb(VIA_CONFIG_DATA) << 2;
2610
2611 printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1);
2612 if ((port1 == 0x3BC) && have_epp)
2613 {
2614 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2615 outb((0x378 >> 2), VIA_CONFIG_DATA);
2616 printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n");
2617 port1 = 0x378;
2618 }
2619
2620 /*
2621 * lock super i/o configuration
2622 */
2623 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2624 tmp &= ~via->via_pci_superio_config_data;
2625 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2626
2627 if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
2628 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
2629 return 0;
2630 }
2631
2632 /* Bits 7-4: PnP Routing for Parallel Port IRQ */
2633 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
2634 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
2635
2636 if (siofunc == VIA_FUNCTION_PARPORT_ECP)
2637 {
2638 /* Bits 3-2: PnP Routing for Parallel Port DMA */
2639 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
2640 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
2641 }
2642 else
2643 /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */
2644 dma = PARPORT_DMA_NONE;
2645
2646 /* Let the user (or defaults) steer us away from interrupts and DMA */
2647 if (autoirq == PARPORT_IRQ_NONE) {
2648 irq = PARPORT_IRQ_NONE;
2649 dma = PARPORT_DMA_NONE;
2650 }
2651 if (autodma == PARPORT_DMA_NONE)
2652 dma = PARPORT_DMA_NONE;
2653
2654 switch (port1) {
2655 case 0x3bc: port2 = 0x7bc; break;
2656 case 0x378: port2 = 0x778; break;
2657 case 0x278: port2 = 0x678; break;
2658 default:
2659 printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
2660 port1);
2661 return 0;
2662 }
2663
2664 /* filter bogus IRQs */
2665 switch (irq) {
2666 case 0:
2667 case 2:
2668 case 8:
2669 case 13:
2670 irq = PARPORT_IRQ_NONE;
2671 break;
2672
2673 default: /* do nothing */
2674 break;
2675 }
2676
2677 /* finally, do the probe with values obtained */
David Brownellc15a3832007-05-08 00:27:35 -07002678 if (parport_pc_probe_port (port1, port2, irq, dma, &pdev->dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 printk (KERN_INFO
2680 "parport_pc: VIA parallel port: io=0x%X", port1);
2681 if (irq != PARPORT_IRQ_NONE)
2682 printk (", irq=%d", irq);
2683 if (dma != PARPORT_DMA_NONE)
2684 printk (", dma=%d", dma);
2685 printk ("\n");
2686 return 1;
2687 }
2688
2689 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
2690 port1, irq, dma);
2691 return 0;
2692}
2693
2694
2695enum parport_pc_sio_types {
2696 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
2697 sio_via_8231, /* Via VT8231 south bridge integrated Super IO */
2698 sio_ite_8872,
2699 last_sio
2700};
2701
2702/* each element directly indexed from enum list, above */
2703static struct parport_pc_superio {
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002704 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
2705 const struct parport_pc_via_data *via);
2706 const struct parport_pc_via_data *via;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707} parport_pc_superio_info[] __devinitdata = {
2708 { sio_via_probe, &via_686a_data, },
2709 { sio_via_probe, &via_8231_data, },
2710 { sio_ite_8872_probe, NULL, },
2711};
2712
2713enum parport_pc_pci_cards {
2714 siig_1p_10x = last_sio,
2715 siig_2p_10x,
2716 siig_1p_20x,
2717 siig_2p_20x,
2718 lava_parallel,
2719 lava_parallel_dual_a,
2720 lava_parallel_dual_b,
2721 boca_ioppar,
2722 plx_9050,
2723 timedia_4078a,
2724 timedia_4079h,
2725 timedia_4085h,
2726 timedia_4088a,
2727 timedia_4089a,
2728 timedia_4095a,
2729 timedia_4096a,
2730 timedia_4078u,
2731 timedia_4079a,
2732 timedia_4085u,
2733 timedia_4079r,
2734 timedia_4079s,
2735 timedia_4079d,
2736 timedia_4079e,
2737 timedia_4079f,
2738 timedia_9079a,
2739 timedia_9079b,
2740 timedia_9079c,
2741 timedia_4006a,
2742 timedia_4014,
2743 timedia_4008a,
2744 timedia_4018,
2745 timedia_9018a,
2746 syba_2p_epp,
2747 syba_1p_ecp,
2748 titan_010l,
Maximilian Attems85747f02005-09-06 15:17:21 -07002749 titan_1284p1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 titan_1284p2,
2751 avlab_1p,
2752 avlab_2p,
Ryan Underwoodc140e112006-12-06 20:36:38 -08002753 oxsemi_952,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 oxsemi_954,
2755 oxsemi_840,
2756 aks_0100,
2757 mobility_pp,
2758 netmos_9705,
2759 netmos_9715,
2760 netmos_9755,
2761 netmos_9805,
2762 netmos_9815,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763};
2764
2765
2766/* each element directly indexed from enum list, above
2767 * (but offset by last_sio) */
2768static struct parport_pc_pci {
2769 int numports;
2770 struct { /* BAR (base address registers) numbers in the config
2771 space header */
2772 int lo;
2773 int hi; /* -1 if not there, >6 for offset-method (max
2774 BAR is 6) */
2775 } addr[4];
2776
2777 /* If set, this is called immediately after pci_enable_device.
2778 * If it returns non-zero, no probing will take place and the
2779 * ports will not be used. */
2780 int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
2781
2782 /* If set, this is called after probing for ports. If 'failed'
2783 * is non-zero we couldn't use any of the ports. */
2784 void (*postinit_hook) (struct pci_dev *pdev, int failed);
Randy.Dunlap96766a32006-04-18 22:21:57 -07002785} cards[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 /* siig_1p_10x */ { 1, { { 2, 3 }, } },
2787 /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
2788 /* siig_1p_20x */ { 1, { { 0, 1 }, } },
2789 /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
2790 /* lava_parallel */ { 1, { { 0, -1 }, } },
2791 /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
2792 /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
2793 /* boca_ioppar */ { 1, { { 0, -1 }, } },
2794 /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
2795 /* timedia_4078a */ { 1, { { 2, -1 }, } },
2796 /* timedia_4079h */ { 1, { { 2, 3 }, } },
2797 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
2798 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2799 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2800 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2801 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2802 /* timedia_4078u */ { 1, { { 2, -1 }, } },
2803 /* timedia_4079a */ { 1, { { 2, 3 }, } },
2804 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
2805 /* timedia_4079r */ { 1, { { 2, 3 }, } },
2806 /* timedia_4079s */ { 1, { { 2, 3 }, } },
2807 /* timedia_4079d */ { 1, { { 2, 3 }, } },
2808 /* timedia_4079e */ { 1, { { 2, 3 }, } },
2809 /* timedia_4079f */ { 1, { { 2, 3 }, } },
2810 /* timedia_9079a */ { 1, { { 2, 3 }, } },
2811 /* timedia_9079b */ { 1, { { 2, 3 }, } },
2812 /* timedia_9079c */ { 1, { { 2, 3 }, } },
2813 /* timedia_4006a */ { 1, { { 0, -1 }, } },
2814 /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2815 /* timedia_4008a */ { 1, { { 0, 1 }, } },
2816 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2817 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2818 /* SYBA uses fixed offsets in
2819 a 1K io window */
2820 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2821 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2822 /* titan_010l */ { 1, { { 3, -1 }, } },
Maximilian Attems85747f02005-09-06 15:17:21 -07002823 /* titan_1284p1 */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2825 /* avlab_1p */ { 1, { { 0, 1}, } },
2826 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
2827 /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
2828 * and 840 locks up if you write 1 to bit 2! */
Ryan Underwoodc140e112006-12-06 20:36:38 -08002829 /* oxsemi_952 */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 /* oxsemi_954 */ { 1, { { 0, -1 }, } },
2831 /* oxsemi_840 */ { 1, { { 0, -1 }, } },
2832 /* aks_0100 */ { 1, { { 0, -1 }, } },
2833 /* mobility_pp */ { 1, { { 0, 1 }, } },
2834 /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */
2835 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2836 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */
2837 /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */
2838 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839};
2840
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002841static const struct pci_device_id parport_pc_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 /* Super-IO onboard chips */
2843 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2844 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
2845 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
2846 PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
2847
2848 /* PCI cards */
2849 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2850 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2851 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2852 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2853 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2854 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2855 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2856 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2857 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2858 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2859 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2860 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2861 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2862 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2863 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2864 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2865 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
2866 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 },
2867 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2868 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2869 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2870 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2871 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2872 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2873 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2874 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2875 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2876 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2877 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2878 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2879 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2880 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2881 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2882 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2883 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2884 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
2885 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
2886 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
2887 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
2888 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
2889 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
2890 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
2891 { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
2892 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
2893 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
2894 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
2895 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
2896 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
2897 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
Maximilian Attems85747f02005-09-06 15:17:21 -07002898 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
2900 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
2901 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */
2902 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
Ryan Underwoodc140e112006-12-06 20:36:38 -08002903 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
2904 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
2906 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
2907 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
2908 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
2909 { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
2910 PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
2911 /* NetMos communication controllers */
2912 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
2913 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
2914 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
2915 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
2916 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
2917 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
2918 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
2919 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
2920 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
2921 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 { 0, } /* terminate list */
2923};
2924MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl);
2925
2926struct pci_parport_data {
2927 int num;
2928 struct parport *ports[2];
2929};
2930
2931static int parport_pc_pci_probe (struct pci_dev *dev,
2932 const struct pci_device_id *id)
2933{
2934 int err, count, n, i = id->driver_data;
2935 struct pci_parport_data *data;
2936
2937 if (i < last_sio)
2938 /* This is an onboard Super-IO and has already been probed */
2939 return 0;
2940
2941 /* This is a PCI card */
2942 i -= last_sio;
2943 count = 0;
2944 if ((err = pci_enable_device (dev)) != 0)
2945 return err;
2946
2947 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
2948 if (!data)
2949 return -ENOMEM;
2950
2951 if (cards[i].preinit_hook &&
2952 cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
2953 kfree(data);
2954 return -ENODEV;
2955 }
2956
2957 for (n = 0; n < cards[i].numports; n++) {
2958 int lo = cards[i].addr[n].lo;
2959 int hi = cards[i].addr[n].hi;
2960 unsigned long io_lo, io_hi;
2961 io_lo = pci_resource_start (dev, lo);
2962 io_hi = 0;
2963 if ((hi >= 0) && (hi <= 6))
2964 io_hi = pci_resource_start (dev, hi);
2965 else if (hi > 6)
2966 io_lo += hi; /* Reinterpret the meaning of
2967 "hi" as an offset (see SYBA
2968 def.) */
2969 /* TODO: test if sharing interrupts works */
2970 printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, "
2971 "I/O at %#lx(%#lx)\n",
2972 parport_pc_pci_tbl[i + last_sio].vendor,
2973 parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi);
2974 data->ports[count] =
2975 parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE,
David Brownellc15a3832007-05-08 00:27:35 -07002976 PARPORT_DMA_NONE, &dev->dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (data->ports[count])
2978 count++;
2979 }
2980
2981 data->num = count;
2982
2983 if (cards[i].postinit_hook)
2984 cards[i].postinit_hook (dev, count == 0);
2985
2986 if (count) {
2987 pci_set_drvdata(dev, data);
2988 return 0;
2989 }
2990
2991 kfree(data);
2992
2993 return -ENODEV;
2994}
2995
2996static void __devexit parport_pc_pci_remove(struct pci_dev *dev)
2997{
2998 struct pci_parport_data *data = pci_get_drvdata(dev);
2999 int i;
3000
3001 pci_set_drvdata(dev, NULL);
3002
3003 if (data) {
3004 for (i = data->num - 1; i >= 0; i--)
3005 parport_pc_unregister_port(data->ports[i]);
3006
3007 kfree(data);
3008 }
3009}
3010
3011static struct pci_driver parport_pc_pci_driver = {
3012 .name = "parport_pc",
3013 .id_table = parport_pc_pci_tbl,
3014 .probe = parport_pc_pci_probe,
3015 .remove = __devexit_p(parport_pc_pci_remove),
3016};
3017
3018static int __init parport_pc_init_superio (int autoirq, int autodma)
3019{
3020 const struct pci_device_id *id;
3021 struct pci_dev *pdev = NULL;
3022 int ret = 0;
3023
Jiri Slabyc9d80732005-08-10 02:09:39 +02003024 for_each_pci_dev(pdev) {
Greg Kroah-Hartman75865852005-06-30 02:18:12 -07003025 id = pci_match_id(parport_pc_pci_tbl, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (id == NULL || id->driver_data >= last_sio)
3027 continue;
3028
3029 if (parport_pc_superio_info[id->driver_data].probe
3030 (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) {
3031 ret++;
3032 }
3033 }
3034
3035 return ret; /* number of devices found */
3036}
3037#else
3038static struct pci_driver parport_pc_pci_driver;
3039static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;}
3040#endif /* CONFIG_PCI */
3041
3042
3043static const struct pnp_device_id parport_pc_pnp_tbl[] = {
3044 /* Standard LPT Printer Port */
3045 {.id = "PNP0400", .driver_data = 0},
3046 /* ECP Printer Port */
3047 {.id = "PNP0401", .driver_data = 0},
3048 { }
3049};
3050
3051MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl);
3052
3053static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id)
3054{
3055 struct parport *pdata;
3056 unsigned long io_lo, io_hi;
3057 int dma, irq;
3058
3059 if (pnp_port_valid(dev,0) &&
3060 !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) {
3061 io_lo = pnp_port_start(dev,0);
3062 } else
3063 return -EINVAL;
3064
3065 if (pnp_port_valid(dev,1) &&
3066 !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) {
3067 io_hi = pnp_port_start(dev,1);
3068 } else
3069 io_hi = 0;
3070
3071 if (pnp_irq_valid(dev,0) &&
3072 !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) {
3073 irq = pnp_irq(dev,0);
3074 } else
3075 irq = PARPORT_IRQ_NONE;
3076
3077 if (pnp_dma_valid(dev,0) &&
3078 !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) {
3079 dma = pnp_dma(dev,0);
3080 } else
3081 dma = PARPORT_DMA_NONE;
3082
David Brownellc15a3832007-05-08 00:27:35 -07003083 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
3084 if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, &dev->dev)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 return -ENODEV;
3086
3087 pnp_set_drvdata(dev,pdata);
3088 return 0;
3089}
3090
3091static void parport_pc_pnp_remove(struct pnp_dev *dev)
3092{
3093 struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
3094 if (!pdata)
3095 return;
3096
3097 parport_pc_unregister_port(pdata);
3098}
3099
3100/* we only need the pnp layer to activate the device, at least for now */
3101static struct pnp_driver parport_pc_pnp_driver = {
3102 .name = "parport_pc",
3103 .id_table = parport_pc_pnp_tbl,
3104 .probe = parport_pc_pnp_probe,
3105 .remove = parport_pc_pnp_remove,
3106};
3107
3108
3109/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3110static int __devinit __attribute__((unused))
3111parport_pc_find_isa_ports (int autoirq, int autodma)
3112{
3113 int count = 0;
3114
3115 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL))
3116 count++;
3117 if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL))
3118 count++;
3119 if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL))
3120 count++;
3121
3122 return count;
3123}
3124
3125/* This function is called by parport_pc_init if the user didn't
3126 * specify any ports to probe. Its job is to find some ports. Order
3127 * is important here -- we want ISA ports to be registered first,
3128 * followed by PCI cards (for least surprise), but before that we want
3129 * to do chipset-specific tests for some onboard ports that we know
3130 * about.
3131 *
3132 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
3133 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
3134 */
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003135static void __init parport_pc_find_ports (int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136{
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003137 int count = 0, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
3139#ifdef CONFIG_PARPORT_PC_SUPERIO
3140 detect_and_report_winbond ();
3141 detect_and_report_smsc ();
3142#endif
3143
3144 /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
3145 count += parport_pc_init_superio (autoirq, autodma);
3146
3147 /* PnP ports, skip detection if SuperIO already found them */
3148 if (!count) {
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003149 err = pnp_register_driver (&parport_pc_pnp_driver);
3150 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 pnp_registered_parport = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 }
3153
3154 /* ISA ports and whatever (see asm/parport.h). */
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003155 parport_pc_find_nonpci_ports (autoirq, autodma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003157 err = pci_register_driver (&parport_pc_pci_driver);
3158 if (!err)
3159 pci_registered_parport = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160}
3161
3162/*
3163 * Piles of crap below pretend to be a parser for module and kernel
3164 * parameters. Say "thank you" to whoever had come up with that
3165 * syntax and keep in mind that code below is a cleaned up version.
3166 */
3167
3168static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 };
3169static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] =
3170 { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO };
3171static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE };
3172static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY };
3173
3174static int __init parport_parse_param(const char *s, int *val,
3175 int automatic, int none, int nofifo)
3176{
3177 if (!s)
3178 return 0;
3179 if (!strncmp(s, "auto", 4))
3180 *val = automatic;
3181 else if (!strncmp(s, "none", 4))
3182 *val = none;
3183 else if (nofifo && !strncmp(s, "nofifo", 4))
3184 *val = nofifo;
3185 else {
3186 char *ep;
3187 unsigned long r = simple_strtoul(s, &ep, 0);
3188 if (ep != s)
3189 *val = r;
3190 else {
3191 printk(KERN_ERR "parport: bad specifier `%s'\n", s);
3192 return -1;
3193 }
3194 }
3195 return 0;
3196}
3197
3198static int __init parport_parse_irq(const char *irqstr, int *val)
3199{
3200 return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
3201 PARPORT_IRQ_NONE, 0);
3202}
3203
3204static int __init parport_parse_dma(const char *dmastr, int *val)
3205{
3206 return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
3207 PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
3208}
3209
3210#ifdef CONFIG_PCI
3211static int __init parport_init_mode_setup(char *str)
3212{
3213 printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
3214
3215 if (!strcmp (str, "spp"))
3216 parport_init_mode=1;
3217 if (!strcmp (str, "ps2"))
3218 parport_init_mode=2;
3219 if (!strcmp (str, "epp"))
3220 parport_init_mode=3;
3221 if (!strcmp (str, "ecp"))
3222 parport_init_mode=4;
3223 if (!strcmp (str, "ecpepp"))
3224 parport_init_mode=5;
3225 return 1;
3226}
3227#endif
3228
3229#ifdef MODULE
3230static const char *irq[PARPORT_PC_MAX_PORTS];
3231static const char *dma[PARPORT_PC_MAX_PORTS];
3232
3233MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3234module_param_array(io, int, NULL, 0);
3235MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
3236module_param_array(io_hi, int, NULL, 0);
3237MODULE_PARM_DESC(irq, "IRQ line");
3238module_param_array(irq, charp, NULL, 0);
3239MODULE_PARM_DESC(dma, "DMA channel");
3240module_param_array(dma, charp, NULL, 0);
3241#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
3242 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
3243MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
3244module_param(verbose_probing, int, 0644);
3245#endif
3246#ifdef CONFIG_PCI
3247static char *init_mode;
3248MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
3249module_param(init_mode, charp, 0);
3250#endif
3251
3252static int __init parse_parport_params(void)
3253{
3254 unsigned int i;
3255 int val;
3256
3257#ifdef CONFIG_PCI
3258 if (init_mode)
3259 parport_init_mode_setup(init_mode);
3260#endif
3261
3262 for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
3263 if (parport_parse_irq(irq[i], &val))
3264 return 1;
3265 irqval[i] = val;
3266 if (parport_parse_dma(dma[i], &val))
3267 return 1;
3268 dmaval[i] = val;
3269 }
3270 if (!io[0]) {
3271 /* The user can make us use any IRQs or DMAs we find. */
3272 if (irq[0] && !parport_parse_irq(irq[0], &val))
3273 switch (val) {
3274 case PARPORT_IRQ_NONE:
3275 case PARPORT_IRQ_AUTO:
3276 irqval[0] = val;
3277 break;
3278 default:
3279 printk (KERN_WARNING
3280 "parport_pc: irq specified "
3281 "without base address. Use 'io=' "
3282 "to specify one\n");
3283 }
3284
3285 if (dma[0] && !parport_parse_dma(dma[0], &val))
3286 switch (val) {
3287 case PARPORT_DMA_NONE:
3288 case PARPORT_DMA_AUTO:
3289 dmaval[0] = val;
3290 break;
3291 default:
3292 printk (KERN_WARNING
3293 "parport_pc: dma specified "
3294 "without base address. Use 'io=' "
3295 "to specify one\n");
3296 }
3297 }
3298 return 0;
3299}
3300
3301#else
3302
3303static int parport_setup_ptr __initdata = 0;
3304
3305/*
3306 * Acceptable parameters:
3307 *
3308 * parport=0
3309 * parport=auto
3310 * parport=0xBASE[,IRQ[,DMA]]
3311 *
3312 * IRQ/DMA may be numeric or 'auto' or 'none'
3313 */
3314static int __init parport_setup (char *str)
3315{
3316 char *endptr;
3317 char *sep;
3318 int val;
3319
3320 if (!str || !*str || (*str == '0' && !*(str+1))) {
3321 /* Disable parport if "parport=0" in cmdline */
3322 io[0] = PARPORT_DISABLE;
3323 return 1;
3324 }
3325
3326 if (!strncmp (str, "auto", 4)) {
3327 irqval[0] = PARPORT_IRQ_AUTO;
3328 dmaval[0] = PARPORT_DMA_AUTO;
3329 return 1;
3330 }
3331
3332 val = simple_strtoul (str, &endptr, 0);
3333 if (endptr == str) {
3334 printk (KERN_WARNING "parport=%s not understood\n", str);
3335 return 1;
3336 }
3337
3338 if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
3339 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
3340 return 1;
3341 }
3342
3343 io[parport_setup_ptr] = val;
3344 irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
3345 dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
3346
3347 sep = strchr(str, ',');
3348 if (sep++) {
3349 if (parport_parse_irq(sep, &val))
3350 return 1;
3351 irqval[parport_setup_ptr] = val;
3352 sep = strchr(sep, ',');
3353 if (sep++) {
3354 if (parport_parse_dma(sep, &val))
3355 return 1;
3356 dmaval[parport_setup_ptr] = val;
3357 }
3358 }
3359 parport_setup_ptr++;
3360 return 1;
3361}
3362
3363static int __init parse_parport_params(void)
3364{
3365 return io[0] == PARPORT_DISABLE;
3366}
3367
3368__setup ("parport=", parport_setup);
3369
3370/*
3371 * Acceptable parameters:
3372 *
3373 * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
3374 */
3375#ifdef CONFIG_PCI
3376__setup("parport_init_mode=",parport_init_mode_setup);
3377#endif
3378#endif
3379
3380/* "Parser" ends here */
3381
3382static int __init parport_pc_init(void)
3383{
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 if (parse_parport_params())
3385 return -EINVAL;
3386
3387 if (io[0]) {
3388 int i;
3389 /* Only probe the ports we were given. */
3390 user_specified = 1;
3391 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3392 if (!io[i])
3393 break;
3394 if ((io_hi[i]) == PARPORT_IOHI_AUTO)
3395 io_hi[i] = 0x400 + io[i];
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003396 parport_pc_probe_port(io[i], io_hi[i],
3397 irqval[i], dmaval[i], NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 }
3399 } else
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003400 parport_pc_find_ports (irqval[0], dmaval[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401
3402 return 0;
3403}
3404
3405static void __exit parport_pc_exit(void)
3406{
3407 if (pci_registered_parport)
3408 pci_unregister_driver (&parport_pc_pci_driver);
3409 if (pnp_registered_parport)
3410 pnp_unregister_driver (&parport_pc_pnp_driver);
3411
3412 spin_lock(&ports_lock);
3413 while (!list_empty(&ports_list)) {
3414 struct parport_pc_private *priv;
3415 struct parport *port;
3416 priv = list_entry(ports_list.next,
3417 struct parport_pc_private, list);
3418 port = priv->port;
3419 spin_unlock(&ports_lock);
3420 parport_pc_unregister_port(port);
3421 spin_lock(&ports_lock);
3422 }
3423 spin_unlock(&ports_lock);
3424}
3425
3426MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
3427MODULE_DESCRIPTION("PC-style parallel port driver");
3428MODULE_LICENSE("GPL");
3429module_init(parport_pc_init)
3430module_exit(parport_pc_exit)