blob: edf83e945853b223aa2e9268191819cc192020d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Low-level parallel-port routines for 8255-based PC-style hardware.
Alan Cox3aeda9b2009-06-11 13:07:29 +01002 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
Alan Cox3aeda9b2009-06-11 13:07:29 +010014 * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * 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>
Andrew Morton8382d2b2007-05-15 23:57:08 -070054#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070055#include <linux/pci.h>
56#include <linux/pnp.h>
Jean Delvarea7d801a2007-05-08 00:27:40 -070057#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include <linux/sysctl.h>
Alan Cox3aeda9b2009-06-11 13:07:29 +010059#include <linux/io.h>
60#include <linux/uaccess.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070061
Linus Torvalds1da177e2005-04-16 15:20:36 -070062#include <asm/dma.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#include <linux/parport.h>
65#include <linux/parport_pc.h>
66#include <linux/via.h>
67#include <asm/parport.h>
68
69#define PARPORT_PC_MAX_PORTS PARPORT_MAX
70
Al Viro7fbacd52005-05-04 05:39:32 +010071#ifdef CONFIG_ISA_DMA_API
72#define HAS_DMA
73#endif
74
Linus Torvalds1da177e2005-04-16 15:20:36 -070075/* ECR modes */
76#define ECR_SPP 00
77#define ECR_PS2 01
78#define ECR_PPF 02
79#define ECR_ECP 03
80#define ECR_EPP 04
81#define ECR_VND 05
82#define ECR_TST 06
83#define ECR_CNF 07
84#define ECR_MODE_MASK 0xe0
Alan Cox3aeda9b2009-06-11 13:07:29 +010085#define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v))
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87#undef DEBUG
88
89#ifdef DEBUG
90#define DPRINTK printk
91#else
92#define DPRINTK(stuff...)
93#endif
94
95
96#define NR_SUPERIOS 3
97static struct superio_struct { /* For Super-IO chips autodetection */
98 int io;
99 int irq;
100 int dma;
Randy.Dunlap96766a32006-04-18 22:21:57 -0700101} superios[NR_SUPERIOS] = { {0,},};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
103static int user_specified;
104#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
105 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
106static int verbose_probing;
107#endif
108static int pci_registered_parport;
109static int pnp_registered_parport;
110
111/* frob_control, but for ECR */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100112static void frob_econtrol(struct parport *pb, unsigned char m,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 unsigned char v)
114{
115 unsigned char ectr = 0;
116
117 if (m != 0xff)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100118 ectr = inb(ECONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
Alan Cox3aeda9b2009-06-11 13:07:29 +0100120 DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 m, v, ectr, (ectr & ~m) ^ v);
122
Alan Cox3aeda9b2009-06-11 13:07:29 +0100123 outb((ectr & ~m) ^ v, ECONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124}
125
Alan Cox3aeda9b2009-06-11 13:07:29 +0100126static inline void frob_set_mode(struct parport *p, int mode)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127{
Alan Cox3aeda9b2009-06-11 13:07:29 +0100128 frob_econtrol(p, ECR_MODE_MASK, mode << 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129}
130
131#ifdef CONFIG_PARPORT_PC_FIFO
Alan Cox3aeda9b2009-06-11 13:07:29 +0100132/* Safely change the mode bits in the ECR
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133 Returns:
134 0 : Success
135 -EBUSY: Could not drain FIFO in some finite amount of time,
136 mode not changed!
137 */
138static int change_mode(struct parport *p, int m)
139{
140 const struct parport_pc_private *priv = p->physport->private_data;
141 unsigned char oecr;
142 int mode;
143
Alan Cox3aeda9b2009-06-11 13:07:29 +0100144 DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n", m);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
146 if (!priv->ecr) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100147 printk(KERN_DEBUG "change_mode: but there's no ECR!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 return 0;
149 }
150
151 /* Bits <7:5> contain the mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100152 oecr = inb(ECONTROL(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 mode = (oecr >> 5) & 0x7;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100154 if (mode == m)
155 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157 if (mode >= 2 && !(priv->ctr & 0x20)) {
158 /* This mode resets the FIFO, so we may
159 * have to wait for it to drain first. */
160 unsigned long expire = jiffies + p->physport->cad->timeout;
161 int counter;
162 switch (mode) {
163 case ECR_PPF: /* Parallel Port FIFO mode */
164 case ECR_ECP: /* ECP Parallel Port mode */
165 /* Busy wait for 200us */
166 for (counter = 0; counter < 40; counter++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100167 if (inb(ECONTROL(p)) & 0x01)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100169 if (signal_pending(current))
170 break;
171 udelay(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173
174 /* Poll slowly. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100175 while (!(inb(ECONTROL(p)) & 0x01)) {
176 if (time_after_eq(jiffies, expire))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /* The FIFO is stuck. */
178 return -EBUSY;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100179 schedule_timeout_interruptible(
180 msecs_to_jiffies(10));
181 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 break;
183 }
184 }
185 }
186
187 if (mode >= 2 && m >= 2) {
188 /* We have to go through mode 001 */
189 oecr &= ~(7 << 5);
190 oecr |= ECR_PS2 << 5;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100191 ECR_WRITE(p, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 }
193
194 /* Set the mode. */
195 oecr &= ~(7 << 5);
196 oecr |= m << 5;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100197 ECR_WRITE(p, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 return 0;
199}
200
201#ifdef CONFIG_PARPORT_1284
202/* Find FIFO lossage; FIFO is reset */
203#if 0
Alan Cox3aeda9b2009-06-11 13:07:29 +0100204static int get_fifo_residue(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205{
206 int residue;
207 int cnfga;
208 const struct parport_pc_private *priv = p->physport->private_data;
209
210 /* Adjust for the contents of the FIFO. */
211 for (residue = priv->fifo_depth; ; residue--) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100212 if (inb(ECONTROL(p)) & 0x2)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /* Full up. */
214 break;
215
Alan Cox3aeda9b2009-06-11 13:07:29 +0100216 outb(0, FIFO(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 }
218
Alan Cox3aeda9b2009-06-11 13:07:29 +0100219 printk(KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 residue);
221
222 /* Reset the FIFO. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100223 frob_set_mode(p, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
225 /* Now change to config mode and clean up. FIXME */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100226 frob_set_mode(p, ECR_CNF);
227 cnfga = inb(CONFIGA(p));
228 printk(KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 if (!(cnfga & (1<<2))) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100231 printk(KERN_DEBUG "%s: Accounting for extra byte\n", p->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 residue++;
233 }
234
235 /* Don't care about partial PWords until support is added for
236 * PWord != 1 byte. */
237
238 /* Back to PS2 mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100239 frob_set_mode(p, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Alan Cox3aeda9b2009-06-11 13:07:29 +0100241 DPRINTK(KERN_DEBUG
242 "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n",
243 inb(ECONTROL(p)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 return residue;
245}
246#endif /* 0 */
247#endif /* IEEE 1284 support */
248#endif /* FIFO support */
249
250/*
251 * Clear TIMEOUT BIT in EPP MODE
252 *
253 * This is also used in SPP detection.
254 */
255static int clear_epp_timeout(struct parport *pb)
256{
257 unsigned char r;
258
259 if (!(parport_pc_read_status(pb) & 0x01))
260 return 1;
261
262 /* To clear timeout some chips require double read */
263 parport_pc_read_status(pb);
264 r = parport_pc_read_status(pb);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100265 outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */
266 outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 r = parport_pc_read_status(pb);
268
269 return !(r & 0x01);
270}
271
272/*
273 * Access functions.
274 *
275 * Most of these aren't static because they may be used by the
276 * parport_xxx_yyy macros. extern __inline__ versions of several
277 * of these are in parport_pc.h.
278 */
279
Alan Cox3aeda9b2009-06-11 13:07:29 +0100280static void parport_pc_init_state(struct pardevice *dev,
281 struct parport_state *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
283 s->u.pc.ctr = 0xc;
284 if (dev->irq_func &&
285 dev->port->irq != PARPORT_IRQ_NONE)
286 /* Set ackIntEn */
287 s->u.pc.ctr |= 0x10;
288
289 s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
290 * D.Gruszka VScom */
291}
292
293static void parport_pc_save_state(struct parport *p, struct parport_state *s)
294{
295 const struct parport_pc_private *priv = p->physport->private_data;
296 s->u.pc.ctr = priv->ctr;
297 if (priv->ecr)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100298 s->u.pc.ecr = inb(ECONTROL(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299}
300
Alan Cox3aeda9b2009-06-11 13:07:29 +0100301static void parport_pc_restore_state(struct parport *p,
302 struct parport_state *s)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303{
304 struct parport_pc_private *priv = p->physport->private_data;
305 register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100306 outb(c, CONTROL(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 priv->ctr = c;
308 if (priv->ecr)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100309 ECR_WRITE(p, s->u.pc.ecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310}
311
312#ifdef CONFIG_PARPORT_1284
Alan Cox3aeda9b2009-06-11 13:07:29 +0100313static size_t parport_pc_epp_read_data(struct parport *port, void *buf,
314 size_t length, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315{
316 size_t got = 0;
317
318 if (flags & PARPORT_W91284PIC) {
319 unsigned char status;
320 size_t left = length;
321
322 /* use knowledge about data lines..:
323 * nFault is 0 if there is at least 1 byte in the Warp's FIFO
324 * pError is 1 if there are 16 bytes in the Warp's FIFO
325 */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100326 status = inb(STATUS(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Alan Cox3aeda9b2009-06-11 13:07:29 +0100328 while (!(status & 0x08) && got < length) {
329 if (left >= 16 && (status & 0x20) && !(status & 0x08)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 /* can grab 16 bytes from warp fifo */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100331 if (!((long)buf & 0x03))
332 insl(EPPDATA(port), buf, 4);
333 else
334 insb(EPPDATA(port), buf, 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 buf += 16;
336 got += 16;
337 left -= 16;
338 } else {
339 /* grab single byte from the warp fifo */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100340 *((char *)buf) = inb(EPPDATA(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 buf++;
342 got++;
343 left--;
344 }
Alan Cox3aeda9b2009-06-11 13:07:29 +0100345 status = inb(STATUS(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 if (status & 0x01) {
347 /* EPP timeout should never occur... */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100348 printk(KERN_DEBUG
349"%s: EPP timeout occurred while talking to w91284pic (should not have done)\n", port->name);
350 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352 }
353 return got;
354 }
355 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100356 if (!(((long)buf | length) & 0x03))
357 insl(EPPDATA(port), buf, (length >> 2));
358 else
359 insb(EPPDATA(port), buf, length);
360 if (inb(STATUS(port)) & 0x01) {
361 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 return -EIO;
363 }
364 return length;
365 }
366 for (; got < length; got++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100367 *((char *)buf) = inb(EPPDATA(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 buf++;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100369 if (inb(STATUS(port)) & 0x01) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370 /* EPP timeout */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100371 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 break;
373 }
374 }
375
376 return got;
377}
378
Alan Cox3aeda9b2009-06-11 13:07:29 +0100379static size_t parport_pc_epp_write_data(struct parport *port, const void *buf,
380 size_t length, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381{
382 size_t written = 0;
383
384 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100385 if (!(((long)buf | length) & 0x03))
386 outsl(EPPDATA(port), buf, (length >> 2));
387 else
388 outsb(EPPDATA(port), buf, length);
389 if (inb(STATUS(port)) & 0x01) {
390 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391 return -EIO;
392 }
393 return length;
394 }
395 for (; written < length; written++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100396 outb(*((char *)buf), EPPDATA(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 buf++;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100398 if (inb(STATUS(port)) & 0x01) {
399 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 break;
401 }
402 }
403
404 return written;
405}
406
Alan Cox3aeda9b2009-06-11 13:07:29 +0100407static size_t parport_pc_epp_read_addr(struct parport *port, void *buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 size_t length, int flags)
409{
410 size_t got = 0;
411
412 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100413 insb(EPPADDR(port), buf, length);
414 if (inb(STATUS(port)) & 0x01) {
415 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 return -EIO;
417 }
418 return length;
419 }
420 for (; got < length; got++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100421 *((char *)buf) = inb(EPPADDR(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 buf++;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100423 if (inb(STATUS(port)) & 0x01) {
424 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 break;
426 }
427 }
428
429 return got;
430}
431
Alan Cox3aeda9b2009-06-11 13:07:29 +0100432static size_t parport_pc_epp_write_addr(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433 const void *buf, size_t length,
434 int flags)
435{
436 size_t written = 0;
437
438 if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100439 outsb(EPPADDR(port), buf, length);
440 if (inb(STATUS(port)) & 0x01) {
441 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 return -EIO;
443 }
444 return length;
445 }
446 for (; written < length; written++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100447 outb(*((char *)buf), EPPADDR(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 buf++;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100449 if (inb(STATUS(port)) & 0x01) {
450 clear_epp_timeout(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 break;
452 }
453 }
454
455 return written;
456}
457
Alan Cox3aeda9b2009-06-11 13:07:29 +0100458static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf,
459 size_t length, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460{
461 size_t got;
462
Alan Cox3aeda9b2009-06-11 13:07:29 +0100463 frob_set_mode(port, ECR_EPP);
464 parport_pc_data_reverse(port);
465 parport_pc_write_control(port, 0x4);
466 got = parport_pc_epp_read_data(port, buf, length, flags);
467 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469 return got;
470}
471
Alan Cox3aeda9b2009-06-11 13:07:29 +0100472static size_t parport_pc_ecpepp_write_data(struct parport *port,
473 const void *buf, size_t length,
474 int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475{
476 size_t written;
477
Alan Cox3aeda9b2009-06-11 13:07:29 +0100478 frob_set_mode(port, ECR_EPP);
479 parport_pc_write_control(port, 0x4);
480 parport_pc_data_forward(port);
481 written = parport_pc_epp_write_data(port, buf, length, flags);
482 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 return written;
485}
486
Alan Cox3aeda9b2009-06-11 13:07:29 +0100487static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf,
488 size_t length, int flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489{
490 size_t got;
491
Alan Cox3aeda9b2009-06-11 13:07:29 +0100492 frob_set_mode(port, ECR_EPP);
493 parport_pc_data_reverse(port);
494 parport_pc_write_control(port, 0x4);
495 got = parport_pc_epp_read_addr(port, buf, length, flags);
496 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 return got;
499}
500
Alan Cox3aeda9b2009-06-11 13:07:29 +0100501static size_t parport_pc_ecpepp_write_addr(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 const void *buf, size_t length,
503 int flags)
504{
505 size_t written;
506
Alan Cox3aeda9b2009-06-11 13:07:29 +0100507 frob_set_mode(port, ECR_EPP);
508 parport_pc_write_control(port, 0x4);
509 parport_pc_data_forward(port);
510 written = parport_pc_epp_write_addr(port, buf, length, flags);
511 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 return written;
514}
515#endif /* IEEE 1284 support */
516
517#ifdef CONFIG_PARPORT_PC_FIFO
Alan Cox3aeda9b2009-06-11 13:07:29 +0100518static size_t parport_pc_fifo_write_block_pio(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519 const void *buf, size_t length)
520{
521 int ret = 0;
522 const unsigned char *bufp = buf;
523 size_t left = length;
524 unsigned long expire = jiffies + port->physport->cad->timeout;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100525 const int fifo = FIFO(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 int poll_for = 8; /* 80 usecs */
527 const struct parport_pc_private *priv = port->physport->private_data;
528 const int fifo_depth = priv->fifo_depth;
529
530 port = port->physport;
531
532 /* We don't want to be interrupted every character. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100533 parport_pc_disable_irq(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 /* set nErrIntrEn and serviceIntr */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100535 frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 /* Forward mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100538 parport_pc_data_forward(port); /* Must be in PS2 mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539
540 while (left) {
541 unsigned char byte;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100542 unsigned char ecrval = inb(ECONTROL(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 int i = 0;
544
Alan Cox3aeda9b2009-06-11 13:07:29 +0100545 if (need_resched() && time_before(jiffies, expire))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 /* Can't yield the port. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100547 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
549 /* Anyone else waiting for the port? */
550 if (port->waithead) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100551 printk(KERN_DEBUG "Somebody wants the port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 break;
553 }
554
555 if (ecrval & 0x02) {
556 /* FIFO is full. Wait for interrupt. */
557
558 /* Clear serviceIntr */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100559 ECR_WRITE(port, ecrval & ~(1<<2));
560false_alarm:
561 ret = parport_wait_event(port, HZ);
562 if (ret < 0)
563 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564 ret = 0;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100565 if (!time_before(jiffies, expire)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 /* Timed out. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100567 printk(KERN_DEBUG "FIFO write timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 break;
569 }
Alan Cox3aeda9b2009-06-11 13:07:29 +0100570 ecrval = inb(ECONTROL(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 if (!(ecrval & (1<<2))) {
572 if (need_resched() &&
Alan Cox3aeda9b2009-06-11 13:07:29 +0100573 time_before(jiffies, expire))
574 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575
576 goto false_alarm;
577 }
578
579 continue;
580 }
581
582 /* Can't fail now. */
583 expire = jiffies + port->cad->timeout;
584
Alan Cox3aeda9b2009-06-11 13:07:29 +0100585poll:
586 if (signal_pending(current))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587 break;
588
589 if (ecrval & 0x01) {
590 /* FIFO is empty. Blast it full. */
591 const int n = left < fifo_depth ? left : fifo_depth;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100592 outsb(fifo, bufp, n);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 bufp += n;
594 left -= n;
595
596 /* Adjust the poll time. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100597 if (i < (poll_for - 2))
598 poll_for--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599 continue;
600 } else if (i++ < poll_for) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100601 udelay(10);
602 ecrval = inb(ECONTROL(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 goto poll;
604 }
605
Alan Cox3aeda9b2009-06-11 13:07:29 +0100606 /* Half-full(call me an optimist) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 byte = *bufp++;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100608 outb(byte, fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 left--;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100610 }
611 dump_parport_state("leave fifo_write_block_pio", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 return length - left;
613}
614
Al Viro7fbacd52005-05-04 05:39:32 +0100615#ifdef HAS_DMA
Alan Cox3aeda9b2009-06-11 13:07:29 +0100616static size_t parport_pc_fifo_write_block_dma(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 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
Alan Cox3aeda9b2009-06-11 13:07:29 +0100629dump_parport_state("enter fifo_write_block_dma", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 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);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100637 } else {
638 /* above 16 MB we use a bounce buffer as ISA-DMA
639 is not possible */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */
641 dma_addr = priv->dma_handle;
642 dma_handle = 0;
643 }
644
645 port = port->physport;
646
647 /* We don't want to be interrupted every character. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100648 parport_pc_disable_irq(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /* set nErrIntrEn and serviceIntr */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100650 frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
652 /* Forward mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100653 parport_pc_data_forward(port); /* Must be in PS2 mode */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 while (left) {
656 unsigned long expire = jiffies + port->physport->cad->timeout;
657
658 size_t count = left;
659
660 if (count > maxlen)
661 count = maxlen;
662
663 if (!dma_handle) /* bounce buffer ! */
664 memcpy(priv->dma_buf, buf, count);
665
666 dmaflag = claim_dma_lock();
667 disable_dma(port->dma);
668 clear_dma_ff(port->dma);
669 set_dma_mode(port->dma, DMA_MODE_WRITE);
670 set_dma_addr(port->dma, dma_addr);
671 set_dma_count(port->dma, count);
672
673 /* Set DMA mode */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100674 frob_econtrol(port, 1<<3, 1<<3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
676 /* Clear serviceIntr */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100677 frob_econtrol(port, 1<<2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 enable_dma(port->dma);
680 release_dma_lock(dmaflag);
681
682 /* assume DMA will be successful */
683 left -= count;
684 buf += count;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100685 if (dma_handle)
686 dma_addr += count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 /* Wait for interrupt. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100689false_alarm:
690 ret = parport_wait_event(port, HZ);
691 if (ret < 0)
692 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 ret = 0;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100694 if (!time_before(jiffies, expire)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 /* Timed out. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100696 printk(KERN_DEBUG "DMA write timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 break;
698 }
699 /* Is serviceIntr set? */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100700 if (!(inb(ECONTROL(port)) & (1<<2))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 cond_resched();
702
703 goto false_alarm;
704 }
705
706 dmaflag = claim_dma_lock();
707 disable_dma(port->dma);
708 clear_dma_ff(port->dma);
709 count = get_dma_residue(port->dma);
710 release_dma_lock(dmaflag);
711
712 cond_resched(); /* Can't yield the port. */
713
714 /* Anyone else waiting for the port? */
715 if (port->waithead) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100716 printk(KERN_DEBUG "Somebody wants the port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 break;
718 }
719
720 /* update for possible DMA residue ! */
721 buf -= count;
722 left += count;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100723 if (dma_handle)
724 dma_addr -= count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 }
726
727 /* Maybe got here through break, so adjust for DMA residue! */
728 dmaflag = claim_dma_lock();
729 disable_dma(port->dma);
730 clear_dma_ff(port->dma);
731 left += get_dma_residue(port->dma);
732 release_dma_lock(dmaflag);
733
734 /* Turn off DMA mode */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100735 frob_econtrol(port, 1<<3, 0);
David Brownellc15a3832007-05-08 00:27:35 -0700736
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737 if (dma_handle)
David Brownellc15a3832007-05-08 00:27:35 -0700738 dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Alan Cox3aeda9b2009-06-11 13:07:29 +0100740dump_parport_state("leave fifo_write_block_dma", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 return length - left;
742}
Al Viro7fbacd52005-05-04 05:39:32 +0100743#endif
744
745static inline size_t parport_pc_fifo_write_block(struct parport *port,
746 const void *buf, size_t length)
747{
748#ifdef HAS_DMA
749 if (port->dma != PARPORT_DMA_NONE)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100750 return parport_pc_fifo_write_block_dma(port, buf, length);
Al Viro7fbacd52005-05-04 05:39:32 +0100751#endif
Alan Cox3aeda9b2009-06-11 13:07:29 +0100752 return parport_pc_fifo_write_block_pio(port, buf, length);
Al Viro7fbacd52005-05-04 05:39:32 +0100753}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755/* Parallel Port FIFO mode (ECP chipsets) */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100756static size_t parport_pc_compat_write_block_pio(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757 const void *buf, size_t length,
758 int flags)
759{
760 size_t written;
761 int r;
762 unsigned long expire;
763 const struct parport_pc_private *priv = port->physport->private_data;
764
765 /* Special case: a timeout of zero means we cannot call schedule().
766 * Also if O_NONBLOCK is set then use the default implementation. */
767 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100768 return parport_ieee1284_write_compat(port, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 length, flags);
770
771 /* Set up parallel port FIFO mode.*/
Alan Cox3aeda9b2009-06-11 13:07:29 +0100772 parport_pc_data_forward(port); /* Must be in PS2 mode */
773 parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0);
774 r = change_mode(port, ECR_PPF); /* Parallel port FIFO */
775 if (r)
776 printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n",
777 port->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
779 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
780
781 /* Write the data to the FIFO. */
Al Viro7fbacd52005-05-04 05:39:32 +0100782 written = parport_pc_fifo_write_block(port, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
784 /* Finish up. */
785 /* For some hardware we don't want to touch the mode until
786 * the FIFO is empty, so allow 4 seconds for each position
787 * in the fifo.
788 */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100789 expire = jiffies + (priv->fifo_depth * HZ * 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 do {
791 /* Wait for the FIFO to empty */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100792 r = change_mode(port, ECR_PS2);
793 if (r != -EBUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794 break;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100795 } while (time_before(jiffies, expire));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 if (r == -EBUSY) {
797
Alan Cox3aeda9b2009-06-11 13:07:29 +0100798 printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
800 /* Prevent further data transfer. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100801 frob_set_mode(port, ECR_TST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
803 /* Adjust for the contents of the FIFO. */
804 for (written -= priv->fifo_depth; ; written++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100805 if (inb(ECONTROL(port)) & 0x2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 /* Full up. */
807 break;
808 }
Alan Cox3aeda9b2009-06-11 13:07:29 +0100809 outb(0, FIFO(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810 }
811
812 /* Reset the FIFO and return to PS2 mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100813 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 }
815
Alan Cox3aeda9b2009-06-11 13:07:29 +0100816 r = parport_wait_peripheral(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 PARPORT_STATUS_BUSY,
818 PARPORT_STATUS_BUSY);
819 if (r)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100820 printk(KERN_DEBUG
821 "%s: BUSY timeout (%d) in compat_write_block_pio\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 port->name, r);
823
824 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
825
826 return written;
827}
828
829/* ECP */
830#ifdef CONFIG_PARPORT_1284
Alan Cox3aeda9b2009-06-11 13:07:29 +0100831static size_t parport_pc_ecp_write_block_pio(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 const void *buf, size_t length,
833 int flags)
834{
835 size_t written;
836 int r;
837 unsigned long expire;
838 const struct parport_pc_private *priv = port->physport->private_data;
839
840 /* Special case: a timeout of zero means we cannot call schedule().
841 * Also if O_NONBLOCK is set then use the default implementation. */
842 if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100843 return parport_ieee1284_ecp_write_data(port, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 length, flags);
845
846 /* Switch to forward mode if necessary. */
847 if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
848 /* Event 47: Set nInit high. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100849 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850 PARPORT_CONTROL_INIT
851 | PARPORT_CONTROL_AUTOFD,
852 PARPORT_CONTROL_INIT
853 | PARPORT_CONTROL_AUTOFD);
854
855 /* Event 49: PError goes high. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100856 r = parport_wait_peripheral(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 PARPORT_STATUS_PAPEROUT,
858 PARPORT_STATUS_PAPEROUT);
859 if (r) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100860 printk(KERN_DEBUG "%s: PError timeout (%d) "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 "in ecp_write_block_pio\n", port->name, r);
862 }
863 }
864
865 /* Set up ECP parallel port mode.*/
Alan Cox3aeda9b2009-06-11 13:07:29 +0100866 parport_pc_data_forward(port); /* Must be in PS2 mode */
867 parport_pc_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 PARPORT_CONTROL_STROBE |
869 PARPORT_CONTROL_AUTOFD,
870 0);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100871 r = change_mode(port, ECR_ECP); /* ECP FIFO */
872 if (r)
873 printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n",
874 port->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
876
877 /* Write the data to the FIFO. */
Al Viro7fbacd52005-05-04 05:39:32 +0100878 written = parport_pc_fifo_write_block(port, buf, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
880 /* Finish up. */
881 /* For some hardware we don't want to touch the mode until
882 * the FIFO is empty, so allow 4 seconds for each position
883 * in the fifo.
884 */
885 expire = jiffies + (priv->fifo_depth * (HZ * 4));
886 do {
887 /* Wait for the FIFO to empty */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100888 r = change_mode(port, ECR_PS2);
889 if (r != -EBUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 break;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100891 } while (time_before(jiffies, expire));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 if (r == -EBUSY) {
893
Alan Cox3aeda9b2009-06-11 13:07:29 +0100894 printk(KERN_DEBUG "%s: FIFO is stuck\n", port->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
896 /* Prevent further data transfer. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100897 frob_set_mode(port, ECR_TST);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 /* Adjust for the contents of the FIFO. */
900 for (written -= priv->fifo_depth; ; written++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +0100901 if (inb(ECONTROL(port)) & 0x2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 /* Full up. */
903 break;
904 }
Alan Cox3aeda9b2009-06-11 13:07:29 +0100905 outb(0, FIFO(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 }
907
908 /* Reset the FIFO and return to PS2 mode. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100909 frob_set_mode(port, ECR_PS2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910
911 /* Host transfer recovery. */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100912 parport_pc_data_reverse(port); /* Must be in PS2 mode */
913 udelay(5);
914 parport_frob_control(port, PARPORT_CONTROL_INIT, 0);
915 r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 if (r)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100917 printk(KERN_DEBUG "%s: PE,1 timeout (%d) "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 "in ecp_write_block_pio\n", port->name, r);
919
Alan Cox3aeda9b2009-06-11 13:07:29 +0100920 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 PARPORT_CONTROL_INIT,
922 PARPORT_CONTROL_INIT);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100923 r = parport_wait_peripheral(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 PARPORT_STATUS_PAPEROUT,
925 PARPORT_STATUS_PAPEROUT);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100926 if (r)
927 printk(KERN_DEBUG "%s: PE,2 timeout (%d) "
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928 "in ecp_write_block_pio\n", port->name, r);
929 }
930
Alan Cox3aeda9b2009-06-11 13:07:29 +0100931 r = parport_wait_peripheral(port,
932 PARPORT_STATUS_BUSY,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 PARPORT_STATUS_BUSY);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100934 if (r)
935 printk(KERN_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936 "%s: BUSY timeout (%d) in ecp_write_block_pio\n",
937 port->name, r);
938
939 port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
940
941 return written;
942}
943
944#if 0
Alan Cox3aeda9b2009-06-11 13:07:29 +0100945static size_t parport_pc_ecp_read_block_pio(struct parport *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946 void *buf, size_t length,
947 int flags)
948{
949 size_t left = length;
950 size_t fifofull;
951 int r;
952 const int fifo = FIFO(port);
953 const struct parport_pc_private *priv = port->physport->private_data;
954 const int fifo_depth = priv->fifo_depth;
955 char *bufp = buf;
956
957 port = port->physport;
Alan Cox3aeda9b2009-06-11 13:07:29 +0100958DPRINTK(KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n");
959dump_parport_state("enter fcn", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /* Special case: a timeout of zero means we cannot call schedule().
962 * Also if O_NONBLOCK is set then use the default implementation. */
963 if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100964 return parport_ieee1284_ecp_read_data(port, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965 length, flags);
966
967 if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) {
968 /* If the peripheral is allowed to send RLE compressed
969 * data, it is possible for a byte to expand to 128
970 * bytes in the FIFO. */
971 fifofull = 128;
972 } else {
973 fifofull = fifo_depth;
974 }
975
976 /* If the caller wants less than a full FIFO's worth of data,
977 * go through software emulation. Otherwise we may have to throw
978 * away data. */
979 if (length < fifofull)
Alan Cox3aeda9b2009-06-11 13:07:29 +0100980 return parport_ieee1284_ecp_read_data(port, buf,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981 length, flags);
982
983 if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) {
984 /* change to reverse-idle phase (must be in forward-idle) */
985
986 /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100987 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 PARPORT_CONTROL_AUTOFD
989 | PARPORT_CONTROL_STROBE,
990 PARPORT_CONTROL_AUTOFD);
Alan Cox3aeda9b2009-06-11 13:07:29 +0100991 parport_pc_data_reverse(port); /* Must be in PS2 mode */
992 udelay(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 /* Event 39: Set nInit low to initiate bus reversal */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100994 parport_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 PARPORT_CONTROL_INIT,
996 0);
997 /* Event 40: Wait for nAckReverse (PError) to go low */
Alan Cox3aeda9b2009-06-11 13:07:29 +0100998 r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
999 if (r) {
1000 printk(KERN_DEBUG "%s: PE timeout Event 40 (%d) "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 "in ecp_read_block_pio\n", port->name, r);
1002 return 0;
1003 }
1004 }
1005
1006 /* Set up ECP FIFO mode.*/
Alan Cox3aeda9b2009-06-11 13:07:29 +01001007/* parport_pc_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008 PARPORT_CONTROL_STROBE |
1009 PARPORT_CONTROL_AUTOFD,
1010 PARPORT_CONTROL_AUTOFD); */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001011 r = change_mode(port, ECR_ECP); /* ECP FIFO */
1012 if (r)
1013 printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n",
1014 port->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015
1016 port->ieee1284.phase = IEEE1284_PH_REV_DATA;
1017
1018 /* the first byte must be collected manually */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001019 dump_parport_state("pre 43", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020 /* Event 43: Wait for nAck to go low */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001021 r = parport_wait_peripheral(port, PARPORT_STATUS_ACK, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (r) {
1023 /* timed out while reading -- no data */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001024 printk(KERN_DEBUG "PIO read timed out (initial byte)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 goto out_no_data;
1026 }
1027 /* read byte */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001028 *bufp++ = inb(DATA(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029 left--;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001030 dump_parport_state("43-44", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 /* Event 44: nAutoFd (HostAck) goes high to acknowledge */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001032 parport_pc_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001033 PARPORT_CONTROL_AUTOFD,
1034 0);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001035 dump_parport_state("pre 45", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036 /* Event 45: Wait for nAck to go high */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001037 /* r = parport_wait_peripheral(port, PARPORT_STATUS_ACK,
1038 PARPORT_STATUS_ACK); */
1039 dump_parport_state("post 45", port);
1040 r = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 if (r) {
1042 /* timed out while waiting for peripheral to respond to ack */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001043 printk(KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001044
1045 /* keep hold of the byte we've got already */
1046 goto out_no_data;
1047 }
1048 /* Event 46: nAutoFd (HostAck) goes low to accept more data */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001049 parport_pc_frob_control(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 PARPORT_CONTROL_AUTOFD,
1051 PARPORT_CONTROL_AUTOFD);
1052
1053
Alan Cox3aeda9b2009-06-11 13:07:29 +01001054 dump_parport_state("rev idle", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 /* Do the transfer. */
1056 while (left > fifofull) {
1057 int ret;
1058 unsigned long expire = jiffies + port->cad->timeout;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001059 unsigned char ecrval = inb(ECONTROL(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
Alan Cox3aeda9b2009-06-11 13:07:29 +01001061 if (need_resched() && time_before(jiffies, expire))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 /* Can't yield the port. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001063 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 /* At this point, the FIFO may already be full. In
Alan Cox3aeda9b2009-06-11 13:07:29 +01001066 * that case ECP is already holding back the
1067 * peripheral (assuming proper design) with a delayed
1068 * handshake. Work fast to avoid a peripheral
1069 * timeout. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070
1071 if (ecrval & 0x01) {
1072 /* FIFO is empty. Wait for interrupt. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001073 dump_parport_state("FIFO empty", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
1075 /* Anyone else waiting for the port? */
1076 if (port->waithead) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001077 printk(KERN_DEBUG "Somebody wants the port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078 break;
1079 }
1080
1081 /* Clear serviceIntr */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001082 ECR_WRITE(port, ecrval & ~(1<<2));
1083false_alarm:
1084 dump_parport_state("waiting", port);
1085 ret = parport_wait_event(port, HZ);
1086 DPRINTK(KERN_DEBUG "parport_wait_event returned %d\n",
1087 ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 if (ret < 0)
1089 break;
1090 ret = 0;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001091 if (!time_before(jiffies, expire)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 /* Timed out. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001093 dump_parport_state("timeout", port);
1094 printk(KERN_DEBUG "PIO read timed out\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095 break;
1096 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01001097 ecrval = inb(ECONTROL(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 if (!(ecrval & (1<<2))) {
1099 if (need_resched() &&
Alan Cox3aeda9b2009-06-11 13:07:29 +01001100 time_before(jiffies, expire)) {
1101 schedule();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
1103 goto false_alarm;
1104 }
1105
1106 /* Depending on how the FIFO threshold was
Alan Cox3aeda9b2009-06-11 13:07:29 +01001107 * set, how long interrupt service took, and
1108 * how fast the peripheral is, we might be
1109 * lucky and have a just filled FIFO. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 continue;
1111 }
1112
1113 if (ecrval & 0x02) {
1114 /* FIFO is full. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001115dump_parport_state("FIFO full", port);
1116 insb(fifo, bufp, fifo_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 bufp += fifo_depth;
1118 left -= fifo_depth;
1119 continue;
1120 }
1121
Alan Cox3aeda9b2009-06-11 13:07:29 +01001122DPRINTK(KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001123
1124 /* FIFO not filled. We will cycle this loop for a while
Alan Cox3aeda9b2009-06-11 13:07:29 +01001125 * and either the peripheral will fill it faster,
1126 * tripping a fast empty with insb, or we empty it. */
1127 *bufp++ = inb(fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001128 left--;
1129 }
1130
1131 /* scoop up anything left in the FIFO */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001132 while (left && !(inb(ECONTROL(port) & 0x01))) {
1133 *bufp++ = inb(fifo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 left--;
1135 }
1136
1137 port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001138dump_parport_state("rev idle2", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139
1140out_no_data:
1141
1142 /* Go to forward idle mode to shut the peripheral up (event 47). */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001143 parport_frob_control(port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
1145 /* event 49: PError goes high */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001146 r = parport_wait_peripheral(port,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 PARPORT_STATUS_PAPEROUT,
1148 PARPORT_STATUS_PAPEROUT);
1149 if (r) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001150 printk(KERN_DEBUG
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151 "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n",
1152 port->name, r);
1153 }
1154
1155 port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
1156
1157 /* Finish up. */
1158 {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001159 int lost = get_fifo_residue(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 if (lost)
1161 /* Shouldn't happen with compliant peripherals. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001162 printk(KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163 port->name, lost);
1164 }
1165
Alan Cox3aeda9b2009-06-11 13:07:29 +01001166dump_parport_state("fwd idle", port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001167 return length - left;
1168}
1169#endif /* 0 */
1170#endif /* IEEE 1284 support */
1171#endif /* Allowed to use FIFO/DMA */
1172
1173
1174/*
1175 * ******************************************
1176 * INITIALISATION AND MODULE STUFF BELOW HERE
1177 * ******************************************
1178 */
1179
1180/* GCC is not inlining extern inline function later overwriten to non-inline,
1181 so we use outlined_ variants here. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001182static const struct parport_operations parport_pc_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 .write_data = parport_pc_write_data,
1184 .read_data = parport_pc_read_data,
1185
1186 .write_control = parport_pc_write_control,
1187 .read_control = parport_pc_read_control,
1188 .frob_control = parport_pc_frob_control,
1189
1190 .read_status = parport_pc_read_status,
1191
1192 .enable_irq = parport_pc_enable_irq,
1193 .disable_irq = parport_pc_disable_irq,
1194
1195 .data_forward = parport_pc_data_forward,
1196 .data_reverse = parport_pc_data_reverse,
1197
1198 .init_state = parport_pc_init_state,
1199 .save_state = parport_pc_save_state,
1200 .restore_state = parport_pc_restore_state,
1201
1202 .epp_write_data = parport_ieee1284_epp_write_data,
1203 .epp_read_data = parport_ieee1284_epp_read_data,
1204 .epp_write_addr = parport_ieee1284_epp_write_addr,
1205 .epp_read_addr = parport_ieee1284_epp_read_addr,
1206
1207 .ecp_write_data = parport_ieee1284_ecp_write_data,
1208 .ecp_read_data = parport_ieee1284_ecp_read_data,
1209 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
1210
1211 .compat_write_data = parport_ieee1284_write_compat,
1212 .nibble_read_data = parport_ieee1284_read_nibble,
1213 .byte_read_data = parport_ieee1284_read_byte,
1214
1215 .owner = THIS_MODULE,
1216};
1217
1218#ifdef CONFIG_PARPORT_PC_SUPERIO
1219/* Super-IO chipset detection, Winbond, SMSC */
1220static void __devinit show_parconfig_smsc37c669(int io, int key)
1221{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001222 int cr1, cr4, cra, cr23, cr26, cr27, i = 0;
1223 static const char *const modes[] = {
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001224 "SPP and Bidirectional (PS/2)",
1225 "EPP and SPP",
1226 "ECP",
1227 "ECP and EPP" };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228
Alan Cox3aeda9b2009-06-11 13:07:29 +01001229 outb(key, io);
1230 outb(key, io);
1231 outb(1, io);
1232 cr1 = inb(io + 1);
1233 outb(4, io);
1234 cr4 = inb(io + 1);
1235 outb(0x0a, io);
1236 cra = inb(io + 1);
1237 outb(0x23, io);
1238 cr23 = inb(io + 1);
1239 outb(0x26, io);
1240 cr26 = inb(io + 1);
1241 outb(0x27, io);
1242 cr27 = inb(io + 1);
1243 outb(0xaa, io);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244
1245 if (verbose_probing) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001246 printk(KERN_INFO
1247 "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248 "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n",
Alan Cox3aeda9b2009-06-11 13:07:29 +01001249 cr1, cr4, cra, cr23, cr26, cr27);
1250
Linus Torvalds1da177e2005-04-16 15:20:36 -07001251 /* The documentation calls DMA and IRQ-Lines by letters, so
1252 the board maker can/will wire them
1253 appropriately/randomly... G=reserved H=IDE-irq, */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001254 printk(KERN_INFO
1255 "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d\n",
1256 cr23 * 4,
1257 (cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-',
1258 (cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-',
1259 cra & 0x0f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260 printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n",
Alan Cox3aeda9b2009-06-11 13:07:29 +01001261 (cr23 * 4 >= 0x100) ? "yes" : "no",
1262 (cr1 & 4) ? "yes" : "no");
1263 printk(KERN_INFO
1264 "SMSC LPT Config: Port mode=%s, EPP version =%s\n",
1265 (cr1 & 0x08) ? "Standard mode only (SPP)"
1266 : modes[cr4 & 0x03],
1267 (cr4 & 0x40) ? "1.7" : "1.9");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268 }
Michael Buesch73e0d482009-06-11 13:06:31 +01001269
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270 /* Heuristics ! BIOS setup for this mainboard device limits
1271 the choices to standard settings, i.e. io-address and IRQ
1272 are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
1273 DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
Michael Buesch73e0d482009-06-11 13:06:31 +01001274 if (cr23 * 4 >= 0x100) { /* if active */
1275 while ((i < NR_SUPERIOS) && (superios[i].io != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276 i++;
Michael Buesch73e0d482009-06-11 13:06:31 +01001277 if (i == NR_SUPERIOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 printk(KERN_INFO "Super-IO: too many chips!\n");
Michael Buesch73e0d482009-06-11 13:06:31 +01001279 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 int d;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001281 switch (cr23 * 4) {
1282 case 0x3bc:
1283 superios[i].io = 0x3bc;
1284 superios[i].irq = 7;
1285 break;
1286 case 0x378:
1287 superios[i].io = 0x378;
1288 superios[i].irq = 7;
1289 break;
1290 case 0x278:
1291 superios[i].io = 0x278;
1292 superios[i].irq = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01001294 d = (cr26 & 0x0f);
1295 if (d == 1 || d == 3)
1296 superios[i].dma = d;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 else
Alan Cox3aeda9b2009-06-11 13:07:29 +01001298 superios[i].dma = PARPORT_DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01001300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301}
1302
1303
1304static void __devinit show_parconfig_winbond(int io, int key)
1305{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001306 int cr30, cr60, cr61, cr70, cr74, crf0, i = 0;
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001307 static const char *const modes[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 "Standard (SPP) and Bidirectional(PS/2)", /* 0 */
1309 "EPP-1.9 and SPP",
1310 "ECP",
1311 "ECP and EPP-1.9",
1312 "Standard (SPP)",
1313 "EPP-1.7 and SPP", /* 5 */
1314 "undefined!",
1315 "ECP and EPP-1.7" };
Marko Kohtalaa6767b72006-01-06 00:19:48 -08001316 static char *const irqtypes[] = {
1317 "pulsed low, high-Z",
1318 "follows nACK" };
Alan Cox3aeda9b2009-06-11 13:07:29 +01001319
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 /* The registers are called compatible-PnP because the
Alan Cox3aeda9b2009-06-11 13:07:29 +01001321 register layout is modelled after ISA-PnP, the access
1322 method is just another ... */
1323 outb(key, io);
1324 outb(key, io);
1325 outb(0x07, io); /* Register 7: Select Logical Device */
1326 outb(0x01, io + 1); /* LD1 is Parallel Port */
1327 outb(0x30, io);
1328 cr30 = inb(io + 1);
1329 outb(0x60, io);
1330 cr60 = inb(io + 1);
1331 outb(0x61, io);
1332 cr61 = inb(io + 1);
1333 outb(0x70, io);
1334 cr70 = inb(io + 1);
1335 outb(0x74, io);
1336 cr74 = inb(io + 1);
1337 outb(0xf0, io);
1338 crf0 = inb(io + 1);
1339 outb(0xaa, io);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340
1341 if (verbose_probing) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001342 printk(KERN_INFO
1343 "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x\n",
1344 cr30, cr60, cr61, cr70, cr74, crf0);
1345 printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
1346 (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 if ((cr74 & 0x07) > 3)
1348 printk("dma=none\n");
1349 else
Alan Cox3aeda9b2009-06-11 13:07:29 +01001350 printk("dma=%d\n", cr74 & 0x07);
1351 printk(KERN_INFO
1352 "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n",
1353 irqtypes[crf0>>7], (crf0>>3)&0x0f);
1354 printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n",
1355 modes[crf0 & 0x07]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 }
1357
Michael Buesch73e0d482009-06-11 13:06:31 +01001358 if (cr30 & 0x01) { /* the settings can be interrogated later ... */
1359 while ((i < NR_SUPERIOS) && (superios[i].io != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 i++;
Michael Buesch73e0d482009-06-11 13:06:31 +01001361 if (i == NR_SUPERIOS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 printk(KERN_INFO "Super-IO: too many chips!\n");
Michael Buesch73e0d482009-06-11 13:06:31 +01001363 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001364 superios[i].io = (cr60<<8)|cr61;
1365 superios[i].irq = cr70&0x0f;
1366 superios[i].dma = (((cr74 & 0x07) > 3) ?
1367 PARPORT_DMA_NONE : (cr74 & 0x07));
1368 }
1369 }
1370}
1371
Alan Cox3aeda9b2009-06-11 13:07:29 +01001372static void __devinit decode_winbond(int efer, int key, int devid,
1373 int devrev, int oldid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001374{
1375 const char *type = "unknown";
Alan Cox3aeda9b2009-06-11 13:07:29 +01001376 int id, progif = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001377
1378 if (devid == devrev)
1379 /* simple heuristics, we happened to read some
Alan Cox3aeda9b2009-06-11 13:07:29 +01001380 non-winbond register */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381 return;
1382
Alan Cox3aeda9b2009-06-11 13:07:29 +01001383 id = (devid << 8) | devrev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 /* Values are from public data sheets pdf files, I can just
Alan Cox3aeda9b2009-06-11 13:07:29 +01001386 confirm 83977TF is correct :-) */
1387 if (id == 0x9771)
1388 type = "83977F/AF";
1389 else if (id == 0x9773)
1390 type = "83977TF / SMSC 97w33x/97w34x";
1391 else if (id == 0x9774)
1392 type = "83977ATF";
1393 else if ((id & ~0x0f) == 0x5270)
1394 type = "83977CTF / SMSC 97w36x";
1395 else if ((id & ~0x0f) == 0x52f0)
1396 type = "83977EF / SMSC 97w35x";
1397 else if ((id & ~0x0f) == 0x5210)
1398 type = "83627";
1399 else if ((id & ~0x0f) == 0x6010)
1400 type = "83697HF";
1401 else if ((oldid & 0x0f) == 0x0a) {
1402 type = "83877F";
1403 progif = 1;
1404 } else if ((oldid & 0x0f) == 0x0b) {
1405 type = "83877AF";
1406 progif = 1;
1407 } else if ((oldid & 0x0f) == 0x0c) {
1408 type = "83877TF";
1409 progif = 1;
1410 } else if ((oldid & 0x0f) == 0x0d) {
1411 type = "83877ATF";
1412 progif = 1;
1413 } else
1414 progif = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001415
1416 if (verbose_probing)
1417 printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
Alan Cox3aeda9b2009-06-11 13:07:29 +01001418 "devid=%02x devrev=%02x oldid=%02x type=%s\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 efer, key, devid, devrev, oldid, type);
1420
1421 if (progif == 2)
Alan Cox3aeda9b2009-06-11 13:07:29 +01001422 show_parconfig_winbond(efer, key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423}
1424
1425static void __devinit decode_smsc(int efer, int key, int devid, int devrev)
1426{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001427 const char *type = "unknown";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 void (*func)(int io, int key);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001429 int id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430
Alan Cox3aeda9b2009-06-11 13:07:29 +01001431 if (devid == devrev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 /* simple heuristics, we happened to read some
Alan Cox3aeda9b2009-06-11 13:07:29 +01001433 non-smsc register */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 return;
1435
Alan Cox3aeda9b2009-06-11 13:07:29 +01001436 func = NULL;
1437 id = (devid << 8) | devrev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438
Alan Cox3aeda9b2009-06-11 13:07:29 +01001439 if (id == 0x0302) {
1440 type = "37c669";
1441 func = show_parconfig_smsc37c669;
1442 } else if (id == 0x6582)
1443 type = "37c665IR";
1444 else if (devid == 0x65)
1445 type = "37c665GT";
1446 else if (devid == 0x66)
1447 type = "37c666GT";
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 if (verbose_probing)
1450 printk(KERN_INFO "SMSC chip at EFER=0x%x "
1451 "key=0x%02x devid=%02x devrev=%02x type=%s\n",
1452 efer, key, devid, devrev, type);
1453
1454 if (func)
Alan Cox3aeda9b2009-06-11 13:07:29 +01001455 func(efer, key);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456}
1457
1458
1459static void __devinit winbond_check(int io, int key)
1460{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001461 int devid, devrev, oldid, x_devid, x_devrev, x_oldid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001462
Harvey Harrison145980a2008-04-30 00:54:57 -07001463 if (!request_region(io, 3, __func__))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 return;
1465
1466 /* First probe without key */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001467 outb(0x20, io);
1468 x_devid = inb(io + 1);
1469 outb(0x21, io);
1470 x_devrev = inb(io + 1);
1471 outb(0x09, io);
1472 x_oldid = inb(io + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Alan Cox3aeda9b2009-06-11 13:07:29 +01001474 outb(key, io);
1475 outb(key, io); /* Write Magic Sequence to EFER, extended
1476 funtion enable register */
1477 outb(0x20, io); /* Write EFIR, extended function index register */
1478 devid = inb(io + 1); /* Read EFDR, extended function data register */
1479 outb(0x21, io);
1480 devrev = inb(io + 1);
1481 outb(0x09, io);
1482 oldid = inb(io + 1);
1483 outb(0xaa, io); /* Magic Seal */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
1486 goto out; /* protection against false positives */
1487
Alan Cox3aeda9b2009-06-11 13:07:29 +01001488 decode_winbond(io, key, devid, devrev, oldid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489out:
1490 release_region(io, 3);
1491}
1492
Alan Cox3aeda9b2009-06-11 13:07:29 +01001493static void __devinit winbond_check2(int io, int key)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001495 int devid, devrev, oldid, x_devid, x_devrev, x_oldid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Harvey Harrison145980a2008-04-30 00:54:57 -07001497 if (!request_region(io, 3, __func__))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 return;
1499
1500 /* First probe without the key */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001501 outb(0x20, io + 2);
1502 x_devid = inb(io + 2);
1503 outb(0x21, io + 1);
1504 x_devrev = inb(io + 2);
1505 outb(0x09, io + 1);
1506 x_oldid = inb(io + 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
Alan Cox3aeda9b2009-06-11 13:07:29 +01001508 outb(key, io); /* Write Magic Byte to EFER, extended
1509 funtion enable register */
1510 outb(0x20, io + 2); /* Write EFIR, extended function index register */
1511 devid = inb(io + 2); /* Read EFDR, extended function data register */
1512 outb(0x21, io + 1);
1513 devrev = inb(io + 2);
1514 outb(0x09, io + 1);
1515 oldid = inb(io + 2);
1516 outb(0xaa, io); /* Magic Seal */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Alan Cox3aeda9b2009-06-11 13:07:29 +01001518 if (x_devid == devid && x_devrev == devrev && x_oldid == oldid)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 goto out; /* protection against false positives */
1520
Alan Cox3aeda9b2009-06-11 13:07:29 +01001521 decode_winbond(io, key, devid, devrev, oldid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522out:
1523 release_region(io, 3);
1524}
1525
1526static void __devinit smsc_check(int io, int key)
1527{
Alan Cox3aeda9b2009-06-11 13:07:29 +01001528 int id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
Harvey Harrison145980a2008-04-30 00:54:57 -07001530 if (!request_region(io, 3, __func__))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 return;
1532
1533 /* First probe without the key */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001534 outb(0x0d, io);
1535 x_oldid = inb(io + 1);
1536 outb(0x0e, io);
1537 x_oldrev = inb(io + 1);
1538 outb(0x20, io);
1539 x_id = inb(io + 1);
1540 outb(0x21, io);
1541 x_rev = inb(io + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
Alan Cox3aeda9b2009-06-11 13:07:29 +01001543 outb(key, io);
1544 outb(key, io); /* Write Magic Sequence to EFER, extended
1545 funtion enable register */
1546 outb(0x0d, io); /* Write EFIR, extended function index register */
1547 oldid = inb(io + 1); /* Read EFDR, extended function data register */
1548 outb(0x0e, io);
1549 oldrev = inb(io + 1);
1550 outb(0x20, io);
1551 id = inb(io + 1);
1552 outb(0x21, io);
1553 rev = inb(io + 1);
1554 outb(0xaa, io); /* Magic Seal */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555
Alan Cox3aeda9b2009-06-11 13:07:29 +01001556 if (x_id == id && x_oldrev == oldrev &&
1557 x_oldid == oldid && x_rev == rev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 goto out; /* protection against false positives */
1559
Alan Cox3aeda9b2009-06-11 13:07:29 +01001560 decode_smsc(io, key, oldid, oldrev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561out:
1562 release_region(io, 3);
1563}
1564
1565
Alan Cox3aeda9b2009-06-11 13:07:29 +01001566static void __devinit detect_and_report_winbond(void)
1567{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 if (verbose_probing)
1569 printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n");
Alan Cox3aeda9b2009-06-11 13:07:29 +01001570 winbond_check(0x3f0, 0x87);
1571 winbond_check(0x370, 0x87);
1572 winbond_check(0x2e , 0x87);
1573 winbond_check(0x4e , 0x87);
1574 winbond_check(0x3f0, 0x86);
1575 winbond_check2(0x250, 0x88);
1576 winbond_check2(0x250, 0x89);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577}
1578
Alan Cox3aeda9b2009-06-11 13:07:29 +01001579static void __devinit detect_and_report_smsc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
1581 if (verbose_probing)
1582 printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n");
Alan Cox3aeda9b2009-06-11 13:07:29 +01001583 smsc_check(0x3f0, 0x55);
1584 smsc_check(0x370, 0x55);
1585 smsc_check(0x3f0, 0x44);
1586 smsc_check(0x370, 0x44);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
Petr Cvekf63fd7e2008-02-06 01:37:48 -08001588
1589static void __devinit detect_and_report_it87(void)
1590{
1591 u16 dev;
1592 u8 r;
1593 if (verbose_probing)
1594 printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...\n");
Harvey Harrison145980a2008-04-30 00:54:57 -07001595 if (!request_region(0x2e, 1, __func__))
Petr Cvekf63fd7e2008-02-06 01:37:48 -08001596 return;
1597 outb(0x87, 0x2e);
1598 outb(0x01, 0x2e);
1599 outb(0x55, 0x2e);
1600 outb(0x55, 0x2e);
1601 outb(0x20, 0x2e);
1602 dev = inb(0x2f) << 8;
1603 outb(0x21, 0x2e);
1604 dev |= inb(0x2f);
1605 if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
1606 dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
1607 printk(KERN_INFO "IT%04X SuperIO detected.\n", dev);
1608 outb(0x07, 0x2E); /* Parallel Port */
1609 outb(0x03, 0x2F);
1610 outb(0xF0, 0x2E); /* BOOT 0x80 off */
1611 r = inb(0x2f);
1612 outb(0xF0, 0x2E);
1613 outb(r | 8, 0x2F);
1614 outb(0x02, 0x2E); /* Lock */
1615 outb(0x02, 0x2F);
Petr Cvekf63fd7e2008-02-06 01:37:48 -08001616 }
Linus Torvalds4ed91902008-04-04 14:30:31 -07001617 release_region(0x2e, 1);
Petr Cvekf63fd7e2008-02-06 01:37:48 -08001618}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001619#endif /* CONFIG_PARPORT_PC_SUPERIO */
1620
Alan Cox3aeda9b2009-06-11 13:07:29 +01001621static int get_superio_dma(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622{
Michael Buesch73e0d482009-06-11 13:06:31 +01001623 int i = 0;
1624
1625 while ((i < NR_SUPERIOS) && (superios[i].io != p->base))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 i++;
Michael Buesch73e0d482009-06-11 13:06:31 +01001627 if (i != NR_SUPERIOS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 return superios[i].dma;
1629 return PARPORT_DMA_NONE;
1630}
1631
Alan Cox3aeda9b2009-06-11 13:07:29 +01001632static int get_superio_irq(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
Michael Buesch73e0d482009-06-11 13:06:31 +01001634 int i = 0;
1635
Alan Cox3aeda9b2009-06-11 13:07:29 +01001636 while ((i < NR_SUPERIOS) && (superios[i].io != p->base))
1637 i++;
1638 if (i != NR_SUPERIOS)
1639 return superios[i].irq;
1640 return PARPORT_IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641}
Michael Buesch73e0d482009-06-11 13:06:31 +01001642
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
1644/* --- Mode detection ------------------------------------- */
1645
1646/*
1647 * Checks for port existence, all ports support SPP MODE
Alan Cox3aeda9b2009-06-11 13:07:29 +01001648 * Returns:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649 * 0 : No parallel port at this address
Alan Cox3aeda9b2009-06-11 13:07:29 +01001650 * PARPORT_MODE_PCSPP : SPP port detected
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 * (if the user specified an ioport himself,
1652 * this shall always be the case!)
1653 *
1654 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07001655static int parport_SPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656{
1657 unsigned char r, w;
1658
1659 /*
Alan Cox3aeda9b2009-06-11 13:07:29 +01001660 * first clear an eventually pending EPP timeout
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
1662 * that does not even respond to SPP cycles if an EPP
1663 * timeout is pending
1664 */
1665 clear_epp_timeout(pb);
1666
1667 /* Do a simple read-write test to make sure the port exists. */
1668 w = 0xc;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001669 outb(w, CONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670
1671 /* Is there a control register that we can read from? Some
1672 * ports don't allow reads, so read_control just returns a
1673 * software copy. Some ports _do_ allow reads, so bypass the
1674 * software copy here. In addition, some bits aren't
1675 * writable. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001676 r = inb(CONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 if ((r & 0xf) == w) {
1678 w = 0xe;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001679 outb(w, CONTROL(pb));
1680 r = inb(CONTROL(pb));
1681 outb(0xc, CONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 if ((r & 0xf) == w)
1683 return PARPORT_MODE_PCSPP;
1684 }
1685
1686 if (user_specified)
1687 /* That didn't work, but the user thinks there's a
1688 * port here. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001689 printk(KERN_INFO "parport 0x%lx (WARNING): CTR: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
1691
1692 /* Try the data register. The data lines aren't tri-stated at
1693 * this stage, so we expect back what we wrote. */
1694 w = 0xaa;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001695 parport_pc_write_data(pb, w);
1696 r = parport_pc_read_data(pb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 if (r == w) {
1698 w = 0x55;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001699 parport_pc_write_data(pb, w);
1700 r = parport_pc_read_data(pb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001701 if (r == w)
1702 return PARPORT_MODE_PCSPP;
1703 }
1704
1705 if (user_specified) {
1706 /* Didn't work, but the user is convinced this is the
1707 * place. */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001708 printk(KERN_INFO "parport 0x%lx (WARNING): DATA: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 "wrote 0x%02x, read 0x%02x\n", pb->base, w, r);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001710 printk(KERN_INFO "parport 0x%lx: You gave this address, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 "but there is probably no parallel port there!\n",
1712 pb->base);
1713 }
1714
1715 /* It's possible that we can't read the control register or
1716 * the data register. In that case just believe the user. */
1717 if (user_specified)
1718 return PARPORT_MODE_PCSPP;
1719
1720 return 0;
1721}
1722
1723/* Check for ECR
1724 *
1725 * Old style XT ports alias io ports every 0x400, hence accessing ECR
1726 * on these cards actually accesses the CTR.
1727 *
1728 * Modern cards don't do this but reading from ECR will return 0xff
1729 * regardless of what is written here if the card does NOT support
1730 * ECP.
1731 *
1732 * We first check to see if ECR is the same as CTR. If not, the low
1733 * two bits of ECR aren't writable, so we check by writing ECR and
1734 * reading it back to see if it's what we expect.
1735 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07001736static int parport_ECR_present(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737{
1738 struct parport_pc_private *priv = pb->private_data;
1739 unsigned char r = 0xc;
1740
Alan Cox3aeda9b2009-06-11 13:07:29 +01001741 outb(r, CONTROL(pb));
1742 if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) {
1743 outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Alan Cox3aeda9b2009-06-11 13:07:29 +01001745 r = inb(CONTROL(pb));
1746 if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 goto no_reg; /* Sure that no ECR register exists */
1748 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01001749
1750 if ((inb(ECONTROL(pb)) & 0x3) != 0x1)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 goto no_reg;
1752
Alan Cox3aeda9b2009-06-11 13:07:29 +01001753 ECR_WRITE(pb, 0x34);
1754 if (inb(ECONTROL(pb)) != 0x35)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755 goto no_reg;
1756
1757 priv->ecr = 1;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001758 outb(0xc, CONTROL(pb));
1759
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760 /* Go to mode 000 */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001761 frob_set_mode(pb, ECR_SPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001762
1763 return 1;
1764
1765 no_reg:
Alan Cox3aeda9b2009-06-11 13:07:29 +01001766 outb(0xc, CONTROL(pb));
1767 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768}
1769
1770#ifdef CONFIG_PARPORT_1284
1771/* Detect PS/2 support.
1772 *
1773 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
1774 * allows us to read data from the data lines. In theory we would get back
1775 * 0xff but any peripheral attached to the port may drag some or all of the
1776 * lines down to zero. So if we get back anything that isn't the contents
Alan Cox3aeda9b2009-06-11 13:07:29 +01001777 * of the data register we deem PS/2 support to be present.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 *
1779 * Some SPP ports have "half PS/2" ability - you can't turn off the line
1780 * drivers, but an external peripheral with sufficiently beefy drivers of
1781 * its own can overpower them and assert its own levels onto the bus, from
1782 * where they can then be read back as normal. Ports with this property
1783 * and the right type of device attached are likely to fail the SPP test,
1784 * (as they will appear to have stuck bits) and so the fact that they might
Alan Cox3aeda9b2009-06-11 13:07:29 +01001785 * be misdetected here is rather academic.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 */
1787
Randy.Dunlap96766a32006-04-18 22:21:57 -07001788static int parport_PS2_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
1790 int ok = 0;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 clear_epp_timeout(pb);
1793
1794 /* try to tri-state the buffer */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001795 parport_pc_data_reverse(pb);
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 parport_pc_write_data(pb, 0x55);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001798 if (parport_pc_read_data(pb) != 0x55)
1799 ok++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801 parport_pc_write_data(pb, 0xaa);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001802 if (parport_pc_read_data(pb) != 0xaa)
1803 ok++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804
1805 /* cancel input mode */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001806 parport_pc_data_forward(pb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 if (ok) {
1809 pb->modes |= PARPORT_MODE_TRISTATE;
1810 } else {
1811 struct parport_pc_private *priv = pb->private_data;
1812 priv->ctr_writable &= ~0x20;
1813 }
1814
1815 return ok;
1816}
1817
1818#ifdef CONFIG_PARPORT_PC_FIFO
David Brownell55265b02008-02-13 15:03:21 -08001819static int parport_ECP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820{
1821 int i;
1822 int config, configb;
1823 int pword;
1824 struct parport_pc_private *priv = pb->private_data;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001825 /* Translate ECP intrLine to ISA irq value */
1826 static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 };
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827
1828 /* If there is no ECR, we have no hope of supporting ECP. */
1829 if (!priv->ecr)
1830 return 0;
1831
1832 /* Find out FIFO depth */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001833 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
1834 ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */
1835 for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++)
1836 outb(0xaa, FIFO(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838 /*
1839 * Using LGS chipset it uses ECR register, but
1840 * it doesn't support ECP or FIFO MODE
1841 */
1842 if (i == 1024) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001843 ECR_WRITE(pb, ECR_SPP << 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 return 0;
1845 }
1846
1847 priv->fifo_depth = i;
1848 if (verbose_probing)
Alan Cox3aeda9b2009-06-11 13:07:29 +01001849 printk(KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 /* Find out writeIntrThreshold */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001852 frob_econtrol(pb, 1<<2, 1<<2);
1853 frob_econtrol(pb, 1<<2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 for (i = 1; i <= priv->fifo_depth; i++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001855 inb(FIFO(pb));
1856 udelay(50);
1857 if (inb(ECONTROL(pb)) & (1<<2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858 break;
1859 }
1860
1861 if (i <= priv->fifo_depth) {
1862 if (verbose_probing)
Alan Cox3aeda9b2009-06-11 13:07:29 +01001863 printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 pb->base, i);
1865 } else
1866 /* Number of bytes we know we can write if we get an
Alan Cox3aeda9b2009-06-11 13:07:29 +01001867 interrupt. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 i = 0;
1869
1870 priv->writeIntrThreshold = i;
1871
1872 /* Find out readIntrThreshold */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001873 frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */
1874 parport_pc_data_reverse(pb); /* Must be in PS2 mode */
1875 frob_set_mode(pb, ECR_TST); /* Test FIFO */
1876 frob_econtrol(pb, 1<<2, 1<<2);
1877 frob_econtrol(pb, 1<<2, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 for (i = 1; i <= priv->fifo_depth; i++) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001879 outb(0xaa, FIFO(pb));
1880 if (inb(ECONTROL(pb)) & (1<<2))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 break;
1882 }
1883
1884 if (i <= priv->fifo_depth) {
1885 if (verbose_probing)
Alan Cox3aeda9b2009-06-11 13:07:29 +01001886 printk(KERN_INFO "0x%lx: readIntrThreshold is %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 pb->base, i);
1888 } else
1889 /* Number of bytes we can read if we get an interrupt. */
1890 i = 0;
1891
1892 priv->readIntrThreshold = i;
1893
Alan Cox3aeda9b2009-06-11 13:07:29 +01001894 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
1895 ECR_WRITE(pb, 0xf4); /* Configuration mode */
1896 config = inb(CONFIGA(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 pword = (config >> 4) & 0x7;
1898 switch (pword) {
1899 case 0:
1900 pword = 2;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001901 printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 pb->base);
1903 break;
1904 case 2:
1905 pword = 4;
Alan Cox3aeda9b2009-06-11 13:07:29 +01001906 printk(KERN_WARNING "0x%lx: Unsupported pword size!\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001907 pb->base);
1908 break;
1909 default:
Alan Cox3aeda9b2009-06-11 13:07:29 +01001910 printk(KERN_WARNING "0x%lx: Unknown implementation ID\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 pb->base);
1912 /* Assume 1 */
1913 case 1:
1914 pword = 1;
1915 }
1916 priv->pword = pword;
1917
1918 if (verbose_probing) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001919 printk(KERN_DEBUG "0x%lx: PWord is %d bits\n",
1920 pb->base, 8 * pword);
1921
1922 printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 config & 0x80 ? "Level" : "Pulses");
1924
Alan Cox3aeda9b2009-06-11 13:07:29 +01001925 configb = inb(CONFIGB(pb));
1926 printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 pb->base, config, configb);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001928 printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
1929 if ((configb >> 3) & 0x07)
1930 printk("%d", intrline[(configb >> 3) & 0x07]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 else
1932 printk("<none or set by other means>");
Alan Cox3aeda9b2009-06-11 13:07:29 +01001933 printk(" dma=");
1934 if ((configb & 0x03) == 0x00)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 printk("<none or set by other means>\n");
1936 else
Alan Cox3aeda9b2009-06-11 13:07:29 +01001937 printk("%d\n", configb & 0x07);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 }
1939
1940 /* Go back to mode 000 */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001941 frob_set_mode(pb, ECR_SPP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
1943 return 1;
1944}
1945#endif
1946
Randy.Dunlap96766a32006-04-18 22:21:57 -07001947static int parport_ECPPS2_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
1949 const struct parport_pc_private *priv = pb->private_data;
1950 int result;
1951 unsigned char oecr;
1952
1953 if (!priv->ecr)
1954 return 0;
1955
Alan Cox3aeda9b2009-06-11 13:07:29 +01001956 oecr = inb(ECONTROL(pb));
1957 ECR_WRITE(pb, ECR_PS2 << 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 result = parport_PS2_supported(pb);
Alan Cox3aeda9b2009-06-11 13:07:29 +01001959 ECR_WRITE(pb, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 return result;
1961}
1962
1963/* EPP mode detection */
1964
Randy.Dunlap96766a32006-04-18 22:21:57 -07001965static int parport_EPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 const struct parport_pc_private *priv = pb->private_data;
1968
1969 /*
1970 * Theory:
1971 * Bit 0 of STR is the EPP timeout bit, this bit is 0
1972 * when EPP is possible and is set high when an EPP timeout
1973 * occurs (EPP uses the HALT line to stop the CPU while it does
1974 * the byte transfer, an EPP timeout occurs if the attached
1975 * device fails to respond after 10 micro seconds).
1976 *
1977 * This bit is cleared by either reading it (National Semi)
1978 * or writing a 1 to the bit (SMC, UMC, WinBond), others ???
1979 * This bit is always high in non EPP modes.
1980 */
1981
1982 /* If EPP timeout bit clear then EPP available */
Alan Cox3aeda9b2009-06-11 13:07:29 +01001983 if (!clear_epp_timeout(pb))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 return 0; /* No way to clear timeout */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985
1986 /* Check for Intel bug. */
1987 if (priv->ecr) {
1988 unsigned char i;
1989 for (i = 0x00; i < 0x80; i += 0x20) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01001990 ECR_WRITE(pb, i);
1991 if (clear_epp_timeout(pb)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 /* Phony EPP in ECP. */
1993 return 0;
1994 }
1995 }
1996 }
1997
1998 pb->modes |= PARPORT_MODE_EPP;
1999
2000 /* Set up access functions to use EPP hardware. */
2001 pb->ops->epp_read_data = parport_pc_epp_read_data;
2002 pb->ops->epp_write_data = parport_pc_epp_write_data;
2003 pb->ops->epp_read_addr = parport_pc_epp_read_addr;
2004 pb->ops->epp_write_addr = parport_pc_epp_write_addr;
2005
2006 return 1;
2007}
2008
Randy.Dunlap96766a32006-04-18 22:21:57 -07002009static int parport_ECPEPP_supported(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010{
2011 struct parport_pc_private *priv = pb->private_data;
2012 int result;
2013 unsigned char oecr;
2014
Alan Cox3aeda9b2009-06-11 13:07:29 +01002015 if (!priv->ecr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017
Alan Cox3aeda9b2009-06-11 13:07:29 +01002018 oecr = inb(ECONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 /* Search for SMC style EPP+ECP mode */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002020 ECR_WRITE(pb, 0x80);
2021 outb(0x04, CONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 result = parport_EPP_supported(pb);
2023
Alan Cox3aeda9b2009-06-11 13:07:29 +01002024 ECR_WRITE(pb, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
2026 if (result) {
2027 /* Set up access functions to use ECP+EPP hardware. */
2028 pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
2029 pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
2030 pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
2031 pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
2032 }
2033
2034 return result;
2035}
2036
2037#else /* No IEEE 1284 support */
2038
2039/* Don't bother probing for modes we know we won't use. */
2040static int __devinit parport_PS2_supported(struct parport *pb) { return 0; }
2041#ifdef CONFIG_PARPORT_PC_FIFO
Alan Cox3aeda9b2009-06-11 13:07:29 +01002042static int parport_ECP_supported(struct parport *pb)
2043{
2044 return 0;
2045}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046#endif
Alan Cox3aeda9b2009-06-11 13:07:29 +01002047static int __devinit parport_EPP_supported(struct parport *pb)
2048{
2049 return 0;
2050}
2051
2052static int __devinit parport_ECPEPP_supported(struct parport *pb)
2053{
2054 return 0;
2055}
2056
2057static int __devinit parport_ECPPS2_supported(struct parport *pb)
2058{
2059 return 0;
2060}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061
2062#endif /* No IEEE 1284 support */
2063
2064/* --- IRQ detection -------------------------------------- */
2065
2066/* Only if supports ECP mode */
Randy Dunlap44389822006-12-06 20:38:33 -08002067static int programmable_irq_support(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
2069 int irq, intrLine;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002070 unsigned char oecr = inb(ECONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071 static const int lookup[8] = {
2072 PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
2073 };
2074
Alan Cox3aeda9b2009-06-11 13:07:29 +01002075 ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
Alan Cox3aeda9b2009-06-11 13:07:29 +01002077 intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 irq = lookup[intrLine];
2079
Alan Cox3aeda9b2009-06-11 13:07:29 +01002080 ECR_WRITE(pb, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 return irq;
2082}
2083
Randy Dunlap44389822006-12-06 20:38:33 -08002084static int irq_probe_ECP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002085{
2086 int i;
2087 unsigned long irqs;
2088
2089 irqs = probe_irq_on();
Alan Cox3aeda9b2009-06-11 13:07:29 +01002090
2091 ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
2092 ECR_WRITE(pb, (ECR_TST << 5) | 0x04);
2093 ECR_WRITE(pb, ECR_TST << 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 /* If Full FIFO sure that writeIntrThreshold is generated */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002096 for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++)
2097 outb(0xaa, FIFO(pb));
2098
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 pb->irq = probe_irq_off(irqs);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002100 ECR_WRITE(pb, ECR_SPP << 5);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 if (pb->irq <= 0)
2103 pb->irq = PARPORT_IRQ_NONE;
2104
2105 return pb->irq;
2106}
2107
2108/*
2109 * This detection seems that only works in National Semiconductors
Alan Cox3aeda9b2009-06-11 13:07:29 +01002110 * This doesn't work in SMC, LGS, and Winbond
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 */
Randy Dunlap44389822006-12-06 20:38:33 -08002112static int irq_probe_EPP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114#ifndef ADVANCED_DETECT
2115 return PARPORT_IRQ_NONE;
2116#else
2117 int irqs;
2118 unsigned char oecr;
2119
2120 if (pb->modes & PARPORT_MODE_PCECR)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002121 oecr = inb(ECONTROL(pb));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
2123 irqs = probe_irq_on();
2124
2125 if (pb->modes & PARPORT_MODE_PCECR)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002126 frob_econtrol(pb, 0x10, 0x10);
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 clear_epp_timeout(pb);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002129 parport_pc_frob_control(pb, 0x20, 0x20);
2130 parport_pc_frob_control(pb, 0x10, 0x10);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002131 clear_epp_timeout(pb);
2132
2133 /* Device isn't expecting an EPP read
2134 * and generates an IRQ.
2135 */
2136 parport_pc_read_epp(pb);
2137 udelay(20);
2138
Alan Cox3aeda9b2009-06-11 13:07:29 +01002139 pb->irq = probe_irq_off(irqs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 if (pb->modes & PARPORT_MODE_PCECR)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002141 ECR_WRITE(pb, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002142 parport_pc_write_control(pb, 0xc);
2143
2144 if (pb->irq <= 0)
2145 pb->irq = PARPORT_IRQ_NONE;
2146
2147 return pb->irq;
2148#endif /* Advanced detection */
2149}
2150
Randy Dunlap44389822006-12-06 20:38:33 -08002151static int irq_probe_SPP(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152{
2153 /* Don't even try to do this. */
2154 return PARPORT_IRQ_NONE;
2155}
2156
2157/* We will attempt to share interrupt requests since other devices
2158 * such as sound cards and network cards seem to like using the
2159 * printer IRQs.
2160 *
2161 * When ECP is available we can autoprobe for IRQs.
2162 * NOTE: If we can autoprobe it, we can register the IRQ.
2163 */
Randy.Dunlap96766a32006-04-18 22:21:57 -07002164static int parport_irq_probe(struct parport *pb)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165{
2166 struct parport_pc_private *priv = pb->private_data;
2167
2168 if (priv->ecr) {
2169 pb->irq = programmable_irq_support(pb);
2170
2171 if (pb->irq == PARPORT_IRQ_NONE)
2172 pb->irq = irq_probe_ECP(pb);
2173 }
2174
2175 if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
2176 (pb->modes & PARPORT_MODE_EPP))
2177 pb->irq = irq_probe_EPP(pb);
2178
2179 clear_epp_timeout(pb);
2180
2181 if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
2182 pb->irq = irq_probe_EPP(pb);
2183
2184 clear_epp_timeout(pb);
2185
2186 if (pb->irq == PARPORT_IRQ_NONE)
2187 pb->irq = irq_probe_SPP(pb);
2188
2189 if (pb->irq == PARPORT_IRQ_NONE)
2190 pb->irq = get_superio_irq(pb);
2191
2192 return pb->irq;
2193}
2194
2195/* --- DMA detection -------------------------------------- */
2196
2197/* Only if chipset conforms to ECP ISA Interface Standard */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002198static int programmable_dma_support(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199{
Alan Cox3aeda9b2009-06-11 13:07:29 +01002200 unsigned char oecr = inb(ECONTROL(p));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201 int dma;
2202
Alan Cox3aeda9b2009-06-11 13:07:29 +01002203 frob_set_mode(p, ECR_CNF);
2204
2205 dma = inb(CONFIGB(p)) & 0x07;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 /* 000: Indicates jumpered 8-bit DMA if read-only.
2207 100: Indicates jumpered 16-bit DMA if read-only. */
2208 if ((dma & 0x03) == 0)
2209 dma = PARPORT_DMA_NONE;
2210
Alan Cox3aeda9b2009-06-11 13:07:29 +01002211 ECR_WRITE(p, oecr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 return dma;
2213}
2214
Alan Cox3aeda9b2009-06-11 13:07:29 +01002215static int parport_dma_probe(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216{
2217 const struct parport_pc_private *priv = p->private_data;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002218 if (priv->ecr) /* ask ECP chipset first */
2219 p->dma = programmable_dma_support(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 if (p->dma == PARPORT_DMA_NONE) {
2221 /* ask known Super-IO chips proper, although these
2222 claim ECP compatible, some don't report their DMA
2223 conforming to ECP standards */
2224 p->dma = get_superio_dma(p);
2225 }
2226
2227 return p->dma;
2228}
2229
2230/* --- Initialisation code -------------------------------- */
2231
2232static LIST_HEAD(ports_list);
2233static DEFINE_SPINLOCK(ports_lock);
2234
Alan Cox51dcdfe2009-04-07 15:30:57 +01002235struct parport *parport_pc_probe_port(unsigned long int base,
2236 unsigned long int base_hi,
2237 int irq, int dma,
2238 struct device *dev,
2239 int irqflags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240{
2241 struct parport_pc_private *priv;
2242 struct parport_operations *ops;
2243 struct parport *p;
2244 int probedirq = PARPORT_IRQ_NONE;
2245 struct resource *base_res;
2246 struct resource *ECR_res = NULL;
2247 struct resource *EPP_res = NULL;
Jean Delvarea7d801a2007-05-08 00:27:40 -07002248 struct platform_device *pdev = NULL;
2249
2250 if (!dev) {
2251 /* We need a physical device to attach to, but none was
2252 * provided. Create our own. */
2253 pdev = platform_device_register_simple("parport_pc",
2254 base, NULL, 0);
2255 if (IS_ERR(pdev))
2256 return NULL;
2257 dev = &pdev->dev;
2258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
Alan Cox51dcdfe2009-04-07 15:30:57 +01002260 ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 if (!ops)
2262 goto out1;
2263
Alan Cox51dcdfe2009-04-07 15:30:57 +01002264 priv = kmalloc(sizeof(struct parport_pc_private), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 if (!priv)
2266 goto out2;
2267
2268 /* a misnomer, actually - it's allocate and reserve parport number */
2269 p = parport_register_port(base, irq, dma, ops);
2270 if (!p)
2271 goto out3;
2272
2273 base_res = request_region(base, 3, p->name);
2274 if (!base_res)
2275 goto out4;
2276
Alan Cox3aeda9b2009-06-11 13:07:29 +01002277 memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 priv->ctr = 0xc;
2279 priv->ctr_writable = ~0x10;
2280 priv->ecr = 0;
2281 priv->fifo_depth = 0;
2282 priv->dma_buf = NULL;
2283 priv->dma_handle = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 INIT_LIST_HEAD(&priv->list);
2285 priv->port = p;
David Brownellc15a3832007-05-08 00:27:35 -07002286
2287 p->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 p->base_hi = base_hi;
2289 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
2290 p->private_data = priv;
2291
2292 if (base_hi) {
2293 ECR_res = request_region(base_hi, 3, p->name);
2294 if (ECR_res)
2295 parport_ECR_present(p);
2296 }
2297
2298 if (base != 0x3bc) {
2299 EPP_res = request_region(base+0x3, 5, p->name);
2300 if (EPP_res)
2301 if (!parport_EPP_supported(p))
2302 parport_ECPEPP_supported(p);
2303 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01002304 if (!parport_SPP_supported(p))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305 /* No port. */
2306 goto out5;
2307 if (priv->ecr)
2308 parport_ECPPS2_supported(p);
2309 else
2310 parport_PS2_supported(p);
2311
Alan Cox3aeda9b2009-06-11 13:07:29 +01002312 p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313
2314 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
2315 if (p->base_hi && priv->ecr)
2316 printk(" (0x%lx)", p->base_hi);
2317 if (p->irq == PARPORT_IRQ_AUTO) {
2318 p->irq = PARPORT_IRQ_NONE;
2319 parport_irq_probe(p);
2320 } else if (p->irq == PARPORT_IRQ_PROBEONLY) {
2321 p->irq = PARPORT_IRQ_NONE;
2322 parport_irq_probe(p);
2323 probedirq = p->irq;
2324 p->irq = PARPORT_IRQ_NONE;
2325 }
2326 if (p->irq != PARPORT_IRQ_NONE) {
2327 printk(", irq %d", p->irq);
2328 priv->ctr_writable |= 0x10;
2329
2330 if (p->dma == PARPORT_DMA_AUTO) {
2331 p->dma = PARPORT_DMA_NONE;
2332 parport_dma_probe(p);
2333 }
2334 }
2335 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
Alan Cox3aeda9b2009-06-11 13:07:29 +01002336 is mandatory (see above) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 p->dma = PARPORT_DMA_NONE;
2338
2339#ifdef CONFIG_PARPORT_PC_FIFO
2340 if (parport_ECP_supported(p) &&
2341 p->dma != PARPORT_DMA_NOFIFO &&
2342 priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
2343 p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
2344 p->ops->compat_write_data = parport_pc_compat_write_block_pio;
2345#ifdef CONFIG_PARPORT_1284
2346 p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
2347 /* currently broken, but working on it.. (FB) */
2348 /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
2349#endif /* IEEE 1284 support */
2350 if (p->dma != PARPORT_DMA_NONE) {
2351 printk(", dma %d", p->dma);
2352 p->modes |= PARPORT_MODE_DMA;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002353 } else
2354 printk(", using FIFO");
2355 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 /* We can't use the DMA channel after all. */
2357 p->dma = PARPORT_DMA_NONE;
2358#endif /* Allowed to use FIFO/DMA */
2359
2360 printk(" [");
Alan Cox3aeda9b2009-06-11 13:07:29 +01002361
2362#define printmode(x) \
2363 {\
2364 if (p->modes & PARPORT_MODE_##x) {\
2365 printk("%s%s", f ? "," : "", #x);\
2366 f++;\
2367 } \
2368 }
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 {
2371 int f = 0;
2372 printmode(PCSPP);
2373 printmode(TRISTATE);
2374 printmode(COMPAT)
2375 printmode(EPP);
2376 printmode(ECP);
2377 printmode(DMA);
2378 }
2379#undef printmode
2380#ifndef CONFIG_PARPORT_1284
Alan Cox3aeda9b2009-06-11 13:07:29 +01002381 printk("(,...)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382#endif /* CONFIG_PARPORT_1284 */
2383 printk("]\n");
Alan Cox3aeda9b2009-06-11 13:07:29 +01002384 if (probedirq != PARPORT_IRQ_NONE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq);
2386
2387 /* If No ECP release the ports grabbed above. */
2388 if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
2389 release_region(base_hi, 3);
2390 ECR_res = NULL;
2391 }
2392 /* Likewise for EEP ports */
2393 if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
2394 release_region(base+3, 5);
2395 EPP_res = NULL;
2396 }
2397 if (p->irq != PARPORT_IRQ_NONE) {
Alan Cox51dcdfe2009-04-07 15:30:57 +01002398 if (request_irq(p->irq, parport_irq_handler,
2399 irqflags, p->name, p)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002400 printk(KERN_WARNING "%s: irq %d in use, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401 "resorting to polled operation\n",
2402 p->name, p->irq);
2403 p->irq = PARPORT_IRQ_NONE;
2404 p->dma = PARPORT_DMA_NONE;
2405 }
2406
2407#ifdef CONFIG_PARPORT_PC_FIFO
Al Viro7fbacd52005-05-04 05:39:32 +01002408#ifdef HAS_DMA
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 if (p->dma != PARPORT_DMA_NONE) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002410 if (request_dma(p->dma, p->name)) {
2411 printk(KERN_WARNING "%s: dma %d in use, "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 "resorting to PIO operation\n",
2413 p->name, p->dma);
2414 p->dma = PARPORT_DMA_NONE;
2415 } else {
2416 priv->dma_buf =
David Brownellc15a3832007-05-08 00:27:35 -07002417 dma_alloc_coherent(dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002418 PAGE_SIZE,
David Brownellc15a3832007-05-08 00:27:35 -07002419 &priv->dma_handle,
2420 GFP_KERNEL);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002421 if (!priv->dma_buf) {
2422 printk(KERN_WARNING "%s: "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 "cannot get buffer for DMA, "
2424 "resorting to PIO operation\n",
2425 p->name);
2426 free_dma(p->dma);
2427 p->dma = PARPORT_DMA_NONE;
2428 }
2429 }
2430 }
Al Viro7fbacd52005-05-04 05:39:32 +01002431#endif
2432#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 }
2434
2435 /* Done probing. Now put the port into a sensible start-up state. */
2436 if (priv->ecr)
2437 /*
2438 * Put the ECP detected port in PS2 mode.
2439 * Do this also for ports that have ECR but don't do ECP.
2440 */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002441 ECR_WRITE(p, 0x34);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442
2443 parport_pc_write_data(p, 0);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002444 parport_pc_data_forward(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
2446 /* Now that we've told the sharing engine about the port, and
2447 found out its characteristics, let the high-level drivers
2448 know about it. */
2449 spin_lock(&ports_lock);
2450 list_add(&priv->list, &ports_list);
2451 spin_unlock(&ports_lock);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002452 parport_announce_port(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453
2454 return p;
2455
2456out5:
2457 if (ECR_res)
2458 release_region(base_hi, 3);
2459 if (EPP_res)
2460 release_region(base+0x3, 5);
2461 release_region(base, 3);
2462out4:
2463 parport_put_port(p);
2464out3:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002465 kfree(priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466out2:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002467 kfree(ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468out1:
Jean Delvarea7d801a2007-05-08 00:27:40 -07002469 if (pdev)
2470 platform_device_unregister(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 return NULL;
2472}
Alan Cox3aeda9b2009-06-11 13:07:29 +01002473EXPORT_SYMBOL(parport_pc_probe_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Alan Cox3aeda9b2009-06-11 13:07:29 +01002475void parport_pc_unregister_port(struct parport *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476{
2477 struct parport_pc_private *priv = p->private_data;
2478 struct parport_operations *ops = p->ops;
2479
2480 parport_remove_port(p);
2481 spin_lock(&ports_lock);
2482 list_del_init(&priv->list);
2483 spin_unlock(&ports_lock);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002484#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 if (p->dma != PARPORT_DMA_NONE)
2486 free_dma(p->dma);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002487#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 if (p->irq != PARPORT_IRQ_NONE)
2489 free_irq(p->irq, p);
2490 release_region(p->base, 3);
2491 if (p->size > 3)
2492 release_region(p->base + 3, p->size - 3);
2493 if (p->modes & PARPORT_MODE_ECP)
2494 release_region(p->base_hi, 3);
Andrew Mortond1c4ac42006-01-08 01:05:05 -08002495#if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 if (priv->dma_buf)
David Brownellc15a3832007-05-08 00:27:35 -07002497 dma_free_coherent(p->physport->dev, PAGE_SIZE,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 priv->dma_buf,
2499 priv->dma_handle);
Al Viro7fbacd52005-05-04 05:39:32 +01002500#endif
Alan Cox3aeda9b2009-06-11 13:07:29 +01002501 kfree(p->private_data);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 parport_put_port(p);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002503 kfree(ops); /* hope no-one cached it */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504}
Alan Cox3aeda9b2009-06-11 13:07:29 +01002505EXPORT_SYMBOL(parport_pc_unregister_port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
2507#ifdef CONFIG_PCI
2508
2509/* ITE support maintained by Rich Liu <richliu@poorman.org> */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002510static int __devinit sio_ite_8872_probe(struct pci_dev *pdev, int autoirq,
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002511 int autodma,
2512 const struct parport_pc_via_data *via)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513{
2514 short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
2515 struct resource *base_res;
2516 u32 ite8872set;
2517 u32 ite8872_lpt, ite8872_lpthi;
2518 u8 ite8872_irq, type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 int irq;
2520 int i;
2521
Alan Cox3aeda9b2009-06-11 13:07:29 +01002522 DPRINTK(KERN_DEBUG "sio_ite_8872_probe()\n");
2523
2524 /* make sure which one chip */
2525 for (i = 0; i < 5; i++) {
Niels de Vose7c310c2007-07-15 23:41:35 -07002526 base_res = request_region(inta_addr[i], 32, "it887x");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 if (base_res) {
2528 int test;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002529 pci_write_config_dword(pdev, 0x60,
Niels de Vose7c310c2007-07-15 23:41:35 -07002530 0xe5000000 | inta_addr[i]);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002531 pci_write_config_dword(pdev, 0x78,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 0x00000000 | inta_addr[i]);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002533 test = inb(inta_addr[i]);
2534 if (test != 0xff)
2535 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 release_region(inta_addr[i], 0x8);
2537 }
2538 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01002539 if (i >= 5) {
2540 printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 return 0;
2542 }
2543
Alan Cox3aeda9b2009-06-11 13:07:29 +01002544 type = inb(inta_addr[i] + 0x18);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 type &= 0x0f;
2546
2547 switch (type) {
2548 case 0x2:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002549 printk(KERN_INFO "parport_pc: ITE8871 found (1P)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 ite8872set = 0x64200000;
2551 break;
2552 case 0xa:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002553 printk(KERN_INFO "parport_pc: ITE8875 found (1P)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 ite8872set = 0x64200000;
2555 break;
2556 case 0xe:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002557 printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 ite8872set = 0x64e00000;
2559 break;
2560 case 0x6:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002561 printk(KERN_INFO "parport_pc: ITE8873 found (1S)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 return 0;
2563 case 0x8:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002564 DPRINTK(KERN_DEBUG "parport_pc: ITE8874 found (2S)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 return 0;
2566 default:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002567 printk(KERN_INFO "parport_pc: unknown ITE887x\n");
2568 printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' "
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 "output to Rich.Liu@ite.com.tw\n");
2570 return 0;
2571 }
2572
Alan Cox3aeda9b2009-06-11 13:07:29 +01002573 pci_read_config_byte(pdev, 0x3c, &ite8872_irq);
2574 pci_read_config_dword(pdev, 0x1c, &ite8872_lpt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 ite8872_lpt &= 0x0000ff00;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002576 pci_read_config_dword(pdev, 0x20, &ite8872_lpthi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 ite8872_lpthi &= 0x0000ff00;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002578 pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt);
2579 pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi);
2580 pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
2581 /* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */
2582 /* SET Parallel IRQ */
2583 pci_write_config_dword(pdev, 0x9c,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 ite8872set | (ite8872_irq * 0x11111));
2585
Alan Cox3aeda9b2009-06-11 13:07:29 +01002586 DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq);
2587 DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 ite8872_lpt);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002589 DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 ite8872_lpthi);
2591
2592 /* Let the user (or defaults) steer us away from interrupts */
2593 irq = ite8872_irq;
2594 if (autoirq != PARPORT_IRQ_AUTO)
2595 irq = PARPORT_IRQ_NONE;
2596
2597 /*
2598 * Release the resource so that parport_pc_probe_port can get it.
2599 */
2600 release_resource(base_res);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002601 if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi,
Alan Cox51dcdfe2009-04-07 15:30:57 +01002602 irq, PARPORT_DMA_NONE, &pdev->dev, 0)) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002603 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 "parport_pc: ITE 8872 parallel port: io=0x%X",
Alan Cox3aeda9b2009-06-11 13:07:29 +01002605 ite8872_lpt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 if (irq != PARPORT_IRQ_NONE)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002607 printk(", irq=%d", irq);
2608 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 return 1;
2610 }
2611
2612 return 0;
2613}
2614
2615/* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
2616 based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002617static int __devinitdata parport_init_mode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
2619/* Data for two known VIA chips */
2620static struct parport_pc_via_data via_686a_data __devinitdata = {
2621 0x51,
2622 0x50,
2623 0x85,
2624 0x02,
2625 0xE2,
2626 0xF0,
2627 0xE6
2628};
2629static struct parport_pc_via_data via_8231_data __devinitdata = {
2630 0x45,
2631 0x44,
2632 0x50,
2633 0x04,
2634 0xF2,
2635 0xFA,
2636 0xF6
2637};
2638
Alan Cox3aeda9b2009-06-11 13:07:29 +01002639static int __devinit sio_via_probe(struct pci_dev *pdev, int autoirq,
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002640 int autodma,
2641 const struct parport_pc_via_data *via)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642{
2643 u8 tmp, tmp2, siofunc;
2644 u8 ppcontrol = 0;
2645 int dma, irq;
2646 unsigned port1, port2;
2647 unsigned have_epp = 0;
2648
2649 printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n");
2650
Alan Cox3aeda9b2009-06-11 13:07:29 +01002651 switch (parport_init_mode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 case 1:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002653 printk(KERN_DEBUG "parport_pc: setting SPP mode\n");
2654 siofunc = VIA_FUNCTION_PARPORT_SPP;
2655 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656 case 2:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002657 printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n");
2658 siofunc = VIA_FUNCTION_PARPORT_SPP;
2659 ppcontrol = VIA_PARPORT_BIDIR;
2660 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002661 case 3:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002662 printk(KERN_DEBUG "parport_pc: setting EPP mode\n");
2663 siofunc = VIA_FUNCTION_PARPORT_EPP;
2664 ppcontrol = VIA_PARPORT_BIDIR;
2665 have_epp = 1;
2666 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 case 4:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002668 printk(KERN_DEBUG "parport_pc: setting ECP mode\n");
2669 siofunc = VIA_FUNCTION_PARPORT_ECP;
2670 ppcontrol = VIA_PARPORT_BIDIR;
2671 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 case 5:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002673 printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n");
2674 siofunc = VIA_FUNCTION_PARPORT_ECP;
2675 ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
2676 have_epp = 1;
2677 break;
2678 default:
2679 printk(KERN_DEBUG
2680 "parport_pc: probing current configuration\n");
2681 siofunc = VIA_FUNCTION_PROBE;
2682 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 }
2684 /*
2685 * unlock super i/o configuration
2686 */
2687 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2688 tmp |= via->via_pci_superio_config_data;
2689 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2690
2691 /* Bits 1-0: Parallel Port Mode / Enable */
2692 outb(via->viacfg_function, VIA_CONFIG_INDEX);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002693 tmp = inb(VIA_CONFIG_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
2695 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
Alan Cox3aeda9b2009-06-11 13:07:29 +01002696 tmp2 = inb(VIA_CONFIG_DATA);
2697 if (siofunc == VIA_FUNCTION_PROBE) {
2698 siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
2699 ppcontrol = tmp2;
2700 } else {
2701 tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
2702 tmp |= siofunc;
2703 outb(via->viacfg_function, VIA_CONFIG_INDEX);
2704 outb(tmp, VIA_CONFIG_DATA);
2705 tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
2706 tmp2 |= ppcontrol;
2707 outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
2708 outb(tmp2, VIA_CONFIG_DATA);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01002710
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 /* Parallel Port I/O Base Address, bits 9-2 */
2712 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2713 port1 = inb(VIA_CONFIG_DATA) << 2;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002714
2715 printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",
2716 port1);
2717 if (port1 == 0x3BC && have_epp) {
2718 outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
2719 outb((0x378 >> 2), VIA_CONFIG_DATA);
2720 printk(KERN_DEBUG
2721 "parport_pc: Parallel port base changed to 0x378\n");
2722 port1 = 0x378;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 }
2724
2725 /*
2726 * lock super i/o configuration
2727 */
2728 pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
2729 tmp &= ~via->via_pci_superio_config_data;
2730 pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
2731
2732 if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
2733 printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n");
2734 return 0;
2735 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01002736
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 /* Bits 7-4: PnP Routing for Parallel Port IRQ */
2738 pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
2739 irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
2740
Alan Cox3aeda9b2009-06-11 13:07:29 +01002741 if (siofunc == VIA_FUNCTION_PARPORT_ECP) {
2742 /* Bits 3-2: PnP Routing for Parallel Port DMA */
2743 pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
2744 dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
2745 } else
2746 /* if ECP not enabled, DMA is not enabled, assumed
2747 bogus 'dma' value */
2748 dma = PARPORT_DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750 /* Let the user (or defaults) steer us away from interrupts and DMA */
2751 if (autoirq == PARPORT_IRQ_NONE) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002752 irq = PARPORT_IRQ_NONE;
2753 dma = PARPORT_DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 }
2755 if (autodma == PARPORT_DMA_NONE)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002756 dma = PARPORT_DMA_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758 switch (port1) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002759 case 0x3bc:
2760 port2 = 0x7bc; break;
2761 case 0x378:
2762 port2 = 0x778; break;
2763 case 0x278:
2764 port2 = 0x678; break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 default:
Alan Cox3aeda9b2009-06-11 13:07:29 +01002766 printk(KERN_INFO
2767 "parport_pc: Weird VIA parport base 0x%X, ignoring\n",
2768 port1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 return 0;
2770 }
2771
2772 /* filter bogus IRQs */
2773 switch (irq) {
2774 case 0:
2775 case 2:
2776 case 8:
2777 case 13:
2778 irq = PARPORT_IRQ_NONE;
2779 break;
2780
2781 default: /* do nothing */
2782 break;
2783 }
2784
2785 /* finally, do the probe with values obtained */
Alan Cox3aeda9b2009-06-11 13:07:29 +01002786 if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) {
2787 printk(KERN_INFO
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 "parport_pc: VIA parallel port: io=0x%X", port1);
2789 if (irq != PARPORT_IRQ_NONE)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002790 printk(", irq=%d", irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 if (dma != PARPORT_DMA_NONE)
Alan Cox3aeda9b2009-06-11 13:07:29 +01002792 printk(", dma=%d", dma);
2793 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 return 1;
2795 }
Alan Cox3aeda9b2009-06-11 13:07:29 +01002796
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n",
2798 port1, irq, dma);
2799 return 0;
2800}
2801
2802
2803enum parport_pc_sio_types {
Alan Cox3aeda9b2009-06-11 13:07:29 +01002804 sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */
2805 sio_via_8231, /* Via VT8231 south bridge integrated Super IO */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 sio_ite_8872,
2807 last_sio
2808};
2809
2810/* each element directly indexed from enum list, above */
2811static struct parport_pc_superio {
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002812 int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
2813 const struct parport_pc_via_data *via);
2814 const struct parport_pc_via_data *via;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815} parport_pc_superio_info[] __devinitdata = {
2816 { sio_via_probe, &via_686a_data, },
2817 { sio_via_probe, &via_8231_data, },
2818 { sio_ite_8872_probe, NULL, },
2819};
2820
2821enum parport_pc_pci_cards {
2822 siig_1p_10x = last_sio,
2823 siig_2p_10x,
2824 siig_1p_20x,
2825 siig_2p_20x,
2826 lava_parallel,
2827 lava_parallel_dual_a,
2828 lava_parallel_dual_b,
2829 boca_ioppar,
2830 plx_9050,
2831 timedia_4078a,
2832 timedia_4079h,
2833 timedia_4085h,
2834 timedia_4088a,
2835 timedia_4089a,
2836 timedia_4095a,
2837 timedia_4096a,
2838 timedia_4078u,
2839 timedia_4079a,
2840 timedia_4085u,
2841 timedia_4079r,
2842 timedia_4079s,
2843 timedia_4079d,
2844 timedia_4079e,
2845 timedia_4079f,
2846 timedia_9079a,
2847 timedia_9079b,
2848 timedia_9079c,
2849 timedia_4006a,
2850 timedia_4014,
2851 timedia_4008a,
2852 timedia_4018,
2853 timedia_9018a,
2854 syba_2p_epp,
2855 syba_1p_ecp,
2856 titan_010l,
Maximilian Attems85747f02005-09-06 15:17:21 -07002857 titan_1284p1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 titan_1284p2,
2859 avlab_1p,
2860 avlab_2p,
Ryan Underwoodc140e112006-12-06 20:36:38 -08002861 oxsemi_952,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 oxsemi_954,
2863 oxsemi_840,
Lee Howard7106b4e2008-10-21 13:48:58 +01002864 oxsemi_pcie_pport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 aks_0100,
2866 mobility_pp,
2867 netmos_9705,
2868 netmos_9715,
2869 netmos_9755,
2870 netmos_9805,
2871 netmos_9815,
Luís P Mendesdc999152008-02-06 01:37:43 -08002872 quatech_sppxp100,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873};
2874
2875
Alan Cox3aeda9b2009-06-11 13:07:29 +01002876/* each element directly indexed from enum list, above
Linus Torvalds1da177e2005-04-16 15:20:36 -07002877 * (but offset by last_sio) */
2878static struct parport_pc_pci {
2879 int numports;
2880 struct { /* BAR (base address registers) numbers in the config
Alan Cox3aeda9b2009-06-11 13:07:29 +01002881 space header */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 int lo;
Alan Cox3aeda9b2009-06-11 13:07:29 +01002883 int hi;
2884 /* -1 if not there, >6 for offset-method (max BAR is 6) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 } addr[4];
2886
2887 /* If set, this is called immediately after pci_enable_device.
2888 * If it returns non-zero, no probing will take place and the
2889 * ports will not be used. */
2890 int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
2891
2892 /* If set, this is called after probing for ports. If 'failed'
2893 * is non-zero we couldn't use any of the ports. */
2894 void (*postinit_hook) (struct pci_dev *pdev, int failed);
Randy.Dunlap96766a32006-04-18 22:21:57 -07002895} cards[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896 /* siig_1p_10x */ { 1, { { 2, 3 }, } },
2897 /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } },
2898 /* siig_1p_20x */ { 1, { { 0, 1 }, } },
2899 /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } },
2900 /* lava_parallel */ { 1, { { 0, -1 }, } },
2901 /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } },
2902 /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } },
2903 /* boca_ioppar */ { 1, { { 0, -1 }, } },
2904 /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } },
2905 /* timedia_4078a */ { 1, { { 2, -1 }, } },
2906 /* timedia_4079h */ { 1, { { 2, 3 }, } },
2907 /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } },
2908 /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2909 /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2910 /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2911 /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } },
2912 /* timedia_4078u */ { 1, { { 2, -1 }, } },
2913 /* timedia_4079a */ { 1, { { 2, 3 }, } },
2914 /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } },
2915 /* timedia_4079r */ { 1, { { 2, 3 }, } },
2916 /* timedia_4079s */ { 1, { { 2, 3 }, } },
2917 /* timedia_4079d */ { 1, { { 2, 3 }, } },
2918 /* timedia_4079e */ { 1, { { 2, 3 }, } },
2919 /* timedia_4079f */ { 1, { { 2, 3 }, } },
2920 /* timedia_9079a */ { 1, { { 2, 3 }, } },
2921 /* timedia_9079b */ { 1, { { 2, 3 }, } },
2922 /* timedia_9079c */ { 1, { { 2, 3 }, } },
2923 /* timedia_4006a */ { 1, { { 0, -1 }, } },
2924 /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2925 /* timedia_4008a */ { 1, { { 0, 1 }, } },
2926 /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2927 /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } },
2928 /* SYBA uses fixed offsets in
Alan Cox3aeda9b2009-06-11 13:07:29 +01002929 a 1K io window */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } },
2931 /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } },
2932 /* titan_010l */ { 1, { { 3, -1 }, } },
Maximilian Attems85747f02005-09-06 15:17:21 -07002933 /* titan_1284p1 */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } },
2935 /* avlab_1p */ { 1, { { 0, 1}, } },
2936 /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} },
2937 /* The Oxford Semi cards are unusual: 954 doesn't support ECP,
2938 * and 840 locks up if you write 1 to bit 2! */
Ryan Underwoodc140e112006-12-06 20:36:38 -08002939 /* oxsemi_952 */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 /* oxsemi_954 */ { 1, { { 0, -1 }, } },
Bernhard Walleadbd3212008-07-25 19:44:56 -07002941 /* oxsemi_840 */ { 1, { { 0, 1 }, } },
Lee Howard7106b4e2008-10-21 13:48:58 +01002942 /* oxsemi_pcie_pport */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 /* aks_0100 */ { 1, { { 0, -1 }, } },
2944 /* mobility_pp */ { 1, { { 0, 1 }, } },
Alan Cox3aeda9b2009-06-11 13:07:29 +01002945
2946 /* The netmos entries below are untested */
2947 /* netmos_9705 */ { 1, { { 0, -1 }, } },
2948 /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} },
2949 /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} },
2950 /* netmos_9805 */ { 1, { { 0, -1 }, } },
2951 /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } },
2952
Luís P Mendesdc999152008-02-06 01:37:43 -08002953 /* quatech_sppxp100 */ { 1, { { 0, 1 }, } },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954};
2955
Marko Kohtalaa6767b72006-01-06 00:19:48 -08002956static const struct pci_device_id parport_pc_pci_tbl[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 /* Super-IO onboard chips */
2958 { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
2959 { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
2960 { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
2961 PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
2962
2963 /* PCI cards */
2964 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
2965 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
2966 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
2967 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
2968 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
2969 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
2970 { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
2971 PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
2972 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
2973 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
2974 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
2975 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
2976 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
2977 PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
2978 { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
2979 PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
2980 { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
Alan Cox3aeda9b2009-06-11 13:07:29 +01002981 PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
2983 { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a },
2984 { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h },
2985 { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h },
2986 { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a },
2987 { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a },
2988 { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a },
2989 { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a },
2990 { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u },
2991 { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a },
2992 { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u },
2993 { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r },
2994 { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s },
2995 { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d },
2996 { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e },
2997 { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f },
2998 { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a },
2999 { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b },
3000 { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c },
3001 { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
3002 { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
3003 { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
3004 { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
3005 { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
3007 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
3008 { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
3009 PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
3010 { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
3011 PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
Maximilian Attems85747f02005-09-06 15:17:21 -07003012 { 0x9710, 0x9805, 0x1000, 0x0010, 0, 0, titan_1284p1 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 },
3014 /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
Alan Cox3aeda9b2009-06-11 13:07:29 +01003015 /* AFAVLAB_TK9902 */
3016 { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
Ryan Underwoodc140e112006-12-06 20:36:38 -08003018 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
3019 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
3021 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
3022 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
3023 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
Lee Howard7106b4e2008-10-21 13:48:58 +01003024 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840,
3025 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3026 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840_G,
3027 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3028 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0,
3029 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3030 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0_G,
3031 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3032 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1,
3033 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3034 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_G,
3035 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3036 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_U,
3037 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
3038 { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU,
3039 PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
3041 PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
Lee Howard7106b4e2008-10-21 13:48:58 +01003042 { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 /* NetMos communication controllers */
3044 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
3045 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
3046 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
3047 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
3048 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
3049 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
3050 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
3051 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
3052 { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
3053 PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
Luís P Mendesdc999152008-02-06 01:37:43 -08003054 /* Quatech SPPXP-100 Parallel port PCI ExpressCard */
3055 { PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
3056 PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 { 0, } /* terminate list */
3058};
Alan Cox3aeda9b2009-06-11 13:07:29 +01003059MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060
3061struct pci_parport_data {
3062 int num;
3063 struct parport *ports[2];
3064};
3065
Alan Cox3aeda9b2009-06-11 13:07:29 +01003066static int parport_pc_pci_probe(struct pci_dev *dev,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 const struct pci_device_id *id)
3068{
3069 int err, count, n, i = id->driver_data;
3070 struct pci_parport_data *data;
3071
3072 if (i < last_sio)
3073 /* This is an onboard Super-IO and has already been probed */
3074 return 0;
3075
3076 /* This is a PCI card */
3077 i -= last_sio;
3078 count = 0;
Alan Cox3aeda9b2009-06-11 13:07:29 +01003079 err = pci_enable_device(dev);
3080 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 return err;
3082
3083 data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
3084 if (!data)
3085 return -ENOMEM;
3086
3087 if (cards[i].preinit_hook &&
Alan Cox3aeda9b2009-06-11 13:07:29 +01003088 cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 kfree(data);
3090 return -ENODEV;
3091 }
3092
3093 for (n = 0; n < cards[i].numports; n++) {
3094 int lo = cards[i].addr[n].lo;
3095 int hi = cards[i].addr[n].hi;
Alan Cox51dcdfe2009-04-07 15:30:57 +01003096 int irq;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 unsigned long io_lo, io_hi;
Alan Cox3aeda9b2009-06-11 13:07:29 +01003098 io_lo = pci_resource_start(dev, lo);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 io_hi = 0;
3100 if ((hi >= 0) && (hi <= 6))
Alan Cox3aeda9b2009-06-11 13:07:29 +01003101 io_hi = pci_resource_start(dev, hi);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 else if (hi > 6)
3103 io_lo += hi; /* Reinterpret the meaning of
Alan Cox3aeda9b2009-06-11 13:07:29 +01003104 "hi" as an offset (see SYBA
3105 def.) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 /* TODO: test if sharing interrupts works */
Alan Cox51dcdfe2009-04-07 15:30:57 +01003107 irq = dev->irq;
3108 if (irq == IRQ_NONE) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01003109 printk(KERN_DEBUG
Alan Cox51dcdfe2009-04-07 15:30:57 +01003110 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)\n",
3111 parport_pc_pci_tbl[i + last_sio].vendor,
3112 parport_pc_pci_tbl[i + last_sio].device,
3113 io_lo, io_hi);
3114 irq = PARPORT_IRQ_NONE;
3115 } else {
Alan Cox3aeda9b2009-06-11 13:07:29 +01003116 printk(KERN_DEBUG
Alan Cox51dcdfe2009-04-07 15:30:57 +01003117 "PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d\n",
3118 parport_pc_pci_tbl[i + last_sio].vendor,
3119 parport_pc_pci_tbl[i + last_sio].device,
3120 io_lo, io_hi, irq);
3121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 data->ports[count] =
Alan Cox51dcdfe2009-04-07 15:30:57 +01003123 parport_pc_probe_port(io_lo, io_hi, irq,
3124 PARPORT_DMA_NONE, &dev->dev,
3125 IRQF_SHARED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 if (data->ports[count])
3127 count++;
3128 }
3129
3130 data->num = count;
3131
3132 if (cards[i].postinit_hook)
Alan Cox3aeda9b2009-06-11 13:07:29 +01003133 cards[i].postinit_hook(dev, count == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 if (count) {
3136 pci_set_drvdata(dev, data);
3137 return 0;
3138 }
3139
3140 kfree(data);
3141
3142 return -ENODEV;
3143}
3144
3145static void __devexit parport_pc_pci_remove(struct pci_dev *dev)
3146{
3147 struct pci_parport_data *data = pci_get_drvdata(dev);
3148 int i;
3149
3150 pci_set_drvdata(dev, NULL);
3151
3152 if (data) {
3153 for (i = data->num - 1; i >= 0; i--)
3154 parport_pc_unregister_port(data->ports[i]);
3155
3156 kfree(data);
3157 }
3158}
3159
3160static struct pci_driver parport_pc_pci_driver = {
3161 .name = "parport_pc",
3162 .id_table = parport_pc_pci_tbl,
3163 .probe = parport_pc_pci_probe,
3164 .remove = __devexit_p(parport_pc_pci_remove),
3165};
3166
Alan Cox3aeda9b2009-06-11 13:07:29 +01003167static int __init parport_pc_init_superio(int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168{
3169 const struct pci_device_id *id;
3170 struct pci_dev *pdev = NULL;
3171 int ret = 0;
3172
Jiri Slabyc9d80732005-08-10 02:09:39 +02003173 for_each_pci_dev(pdev) {
Greg Kroah-Hartman75865852005-06-30 02:18:12 -07003174 id = pci_match_id(parport_pc_pci_tbl, pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 if (id == NULL || id->driver_data >= last_sio)
3176 continue;
3177
Alan Cox3aeda9b2009-06-11 13:07:29 +01003178 if (parport_pc_superio_info[id->driver_data].probe(
3179 pdev, autoirq, autodma,
3180 parport_pc_superio_info[id->driver_data].via)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 ret++;
3182 }
3183 }
3184
3185 return ret; /* number of devices found */
3186}
3187#else
3188static struct pci_driver parport_pc_pci_driver;
Alan Cox3aeda9b2009-06-11 13:07:29 +01003189static int __init parport_pc_init_superio(int autoirq, int autodma)
3190{
3191 return 0;
3192}
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193#endif /* CONFIG_PCI */
3194
Bjorn Helgaasf2b9a392008-04-29 01:03:22 -07003195#ifdef CONFIG_PNP
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
3197static const struct pnp_device_id parport_pc_pnp_tbl[] = {
3198 /* Standard LPT Printer Port */
3199 {.id = "PNP0400", .driver_data = 0},
3200 /* ECP Printer Port */
3201 {.id = "PNP0401", .driver_data = 0},
3202 { }
3203};
3204
Alan Cox3aeda9b2009-06-11 13:07:29 +01003205MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206
Alan Cox3aeda9b2009-06-11 13:07:29 +01003207static int parport_pc_pnp_probe(struct pnp_dev *dev,
3208 const struct pnp_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209{
3210 struct parport *pdata;
3211 unsigned long io_lo, io_hi;
3212 int dma, irq;
3213
Alan Cox3aeda9b2009-06-11 13:07:29 +01003214 if (pnp_port_valid(dev, 0) &&
3215 !(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
3216 io_lo = pnp_port_start(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217 } else
3218 return -EINVAL;
3219
Alan Cox3aeda9b2009-06-11 13:07:29 +01003220 if (pnp_port_valid(dev, 1) &&
3221 !(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) {
3222 io_hi = pnp_port_start(dev, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 } else
3224 io_hi = 0;
3225
Alan Cox3aeda9b2009-06-11 13:07:29 +01003226 if (pnp_irq_valid(dev, 0) &&
3227 !(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) {
3228 irq = pnp_irq(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 } else
3230 irq = PARPORT_IRQ_NONE;
3231
Alan Cox3aeda9b2009-06-11 13:07:29 +01003232 if (pnp_dma_valid(dev, 0) &&
3233 !(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) {
3234 dma = pnp_dma(dev, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 } else
3236 dma = PARPORT_DMA_NONE;
3237
David Brownellc15a3832007-05-08 00:27:35 -07003238 dev_info(&dev->dev, "reported by %s\n", dev->protocol->name);
Alan Cox3aeda9b2009-06-11 13:07:29 +01003239 pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0);
3240 if (pdata == NULL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 return -ENODEV;
3242
Alan Cox3aeda9b2009-06-11 13:07:29 +01003243 pnp_set_drvdata(dev, pdata);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 return 0;
3245}
3246
3247static void parport_pc_pnp_remove(struct pnp_dev *dev)
3248{
3249 struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
3250 if (!pdata)
3251 return;
3252
3253 parport_pc_unregister_port(pdata);
3254}
3255
3256/* we only need the pnp layer to activate the device, at least for now */
3257static struct pnp_driver parport_pc_pnp_driver = {
3258 .name = "parport_pc",
3259 .id_table = parport_pc_pnp_tbl,
3260 .probe = parport_pc_pnp_probe,
3261 .remove = parport_pc_pnp_remove,
3262};
3263
Bjorn Helgaasf2b9a392008-04-29 01:03:22 -07003264#else
3265static struct pnp_driver parport_pc_pnp_driver;
3266#endif /* CONFIG_PNP */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
Jean Delvarea7d801a2007-05-08 00:27:40 -07003268static int __devinit parport_pc_platform_probe(struct platform_device *pdev)
3269{
3270 /* Always succeed, the actual probing is done in
3271 * parport_pc_probe_port(). */
3272 return 0;
3273}
3274
3275static struct platform_driver parport_pc_platform_driver = {
3276 .driver = {
3277 .owner = THIS_MODULE,
3278 .name = "parport_pc",
3279 },
3280 .probe = parport_pc_platform_probe,
3281};
3282
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283/* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
3284static int __devinit __attribute__((unused))
Alan Cox3aeda9b2009-06-11 13:07:29 +01003285parport_pc_find_isa_ports(int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286{
3287 int count = 0;
3288
Alan Cox51dcdfe2009-04-07 15:30:57 +01003289 if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 count++;
Alan Cox51dcdfe2009-04-07 15:30:57 +01003291 if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 count++;
Alan Cox51dcdfe2009-04-07 15:30:57 +01003293 if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 count++;
3295
3296 return count;
3297}
3298
3299/* This function is called by parport_pc_init if the user didn't
3300 * specify any ports to probe. Its job is to find some ports. Order
3301 * is important here -- we want ISA ports to be registered first,
3302 * followed by PCI cards (for least surprise), but before that we want
3303 * to do chipset-specific tests for some onboard ports that we know
3304 * about.
3305 *
3306 * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
3307 * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
3308 */
Alan Cox3aeda9b2009-06-11 13:07:29 +01003309static void __init parport_pc_find_ports(int autoirq, int autodma)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310{
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003311 int count = 0, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312
3313#ifdef CONFIG_PARPORT_PC_SUPERIO
Petr Cvekf63fd7e2008-02-06 01:37:48 -08003314 detect_and_report_it87();
3315 detect_and_report_winbond();
3316 detect_and_report_smsc();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317#endif
3318
3319 /* Onboard SuperIO chipsets that show themselves on the PCI bus. */
Petr Cvekf63fd7e2008-02-06 01:37:48 -08003320 count += parport_pc_init_superio(autoirq, autodma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321
3322 /* PnP ports, skip detection if SuperIO already found them */
3323 if (!count) {
Petr Cvekf63fd7e2008-02-06 01:37:48 -08003324 err = pnp_register_driver(&parport_pc_pnp_driver);
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003325 if (!err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 pnp_registered_parport = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
3328
3329 /* ISA ports and whatever (see asm/parport.h). */
Petr Cvekf63fd7e2008-02-06 01:37:48 -08003330 parport_pc_find_nonpci_ports(autoirq, autodma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331
Petr Cvekf63fd7e2008-02-06 01:37:48 -08003332 err = pci_register_driver(&parport_pc_pci_driver);
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003333 if (!err)
3334 pci_registered_parport = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335}
3336
3337/*
3338 * Piles of crap below pretend to be a parser for module and kernel
3339 * parameters. Say "thank you" to whoever had come up with that
3340 * syntax and keep in mind that code below is a cleaned up version.
3341 */
3342
Alan Cox3aeda9b2009-06-11 13:07:29 +01003343static int __initdata io[PARPORT_PC_MAX_PORTS+1] = {
3344 [0 ... PARPORT_PC_MAX_PORTS] = 0
3345};
3346static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = {
3347 [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO
3348};
3349static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = {
3350 [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE
3351};
3352static int __initdata irqval[PARPORT_PC_MAX_PORTS] = {
3353 [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY
3354};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
3356static int __init parport_parse_param(const char *s, int *val,
3357 int automatic, int none, int nofifo)
3358{
3359 if (!s)
3360 return 0;
3361 if (!strncmp(s, "auto", 4))
3362 *val = automatic;
3363 else if (!strncmp(s, "none", 4))
3364 *val = none;
3365 else if (nofifo && !strncmp(s, "nofifo", 4))
3366 *val = nofifo;
3367 else {
3368 char *ep;
3369 unsigned long r = simple_strtoul(s, &ep, 0);
3370 if (ep != s)
3371 *val = r;
3372 else {
3373 printk(KERN_ERR "parport: bad specifier `%s'\n", s);
3374 return -1;
3375 }
3376 }
3377 return 0;
3378}
3379
3380static int __init parport_parse_irq(const char *irqstr, int *val)
3381{
3382 return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
3383 PARPORT_IRQ_NONE, 0);
3384}
3385
3386static int __init parport_parse_dma(const char *dmastr, int *val)
3387{
3388 return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
3389 PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
3390}
3391
3392#ifdef CONFIG_PCI
3393static int __init parport_init_mode_setup(char *str)
3394{
Alan Cox3aeda9b2009-06-11 13:07:29 +01003395 printk(KERN_DEBUG
3396 "parport_pc.c: Specified parameter parport_init_mode=%s\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
Alan Cox3aeda9b2009-06-11 13:07:29 +01003398 if (!strcmp(str, "spp"))
3399 parport_init_mode = 1;
3400 if (!strcmp(str, "ps2"))
3401 parport_init_mode = 2;
3402 if (!strcmp(str, "epp"))
3403 parport_init_mode = 3;
3404 if (!strcmp(str, "ecp"))
3405 parport_init_mode = 4;
3406 if (!strcmp(str, "ecpepp"))
3407 parport_init_mode = 5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 return 1;
3409}
3410#endif
3411
3412#ifdef MODULE
3413static const char *irq[PARPORT_PC_MAX_PORTS];
3414static const char *dma[PARPORT_PC_MAX_PORTS];
3415
3416MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
3417module_param_array(io, int, NULL, 0);
3418MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
3419module_param_array(io_hi, int, NULL, 0);
3420MODULE_PARM_DESC(irq, "IRQ line");
3421module_param_array(irq, charp, NULL, 0);
3422MODULE_PARM_DESC(dma, "DMA channel");
3423module_param_array(dma, charp, NULL, 0);
3424#if defined(CONFIG_PARPORT_PC_SUPERIO) || \
3425 (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
3426MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
3427module_param(verbose_probing, int, 0644);
3428#endif
3429#ifdef CONFIG_PCI
3430static char *init_mode;
Alan Cox3aeda9b2009-06-11 13:07:29 +01003431MODULE_PARM_DESC(init_mode,
3432 "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433module_param(init_mode, charp, 0);
3434#endif
3435
3436static int __init parse_parport_params(void)
3437{
3438 unsigned int i;
3439 int val;
3440
3441#ifdef CONFIG_PCI
3442 if (init_mode)
3443 parport_init_mode_setup(init_mode);
3444#endif
3445
3446 for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
3447 if (parport_parse_irq(irq[i], &val))
3448 return 1;
3449 irqval[i] = val;
3450 if (parport_parse_dma(dma[i], &val))
3451 return 1;
3452 dmaval[i] = val;
3453 }
3454 if (!io[0]) {
3455 /* The user can make us use any IRQs or DMAs we find. */
3456 if (irq[0] && !parport_parse_irq(irq[0], &val))
3457 switch (val) {
3458 case PARPORT_IRQ_NONE:
3459 case PARPORT_IRQ_AUTO:
3460 irqval[0] = val;
3461 break;
3462 default:
Alan Cox3aeda9b2009-06-11 13:07:29 +01003463 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 "parport_pc: irq specified "
3465 "without base address. Use 'io=' "
3466 "to specify one\n");
3467 }
3468
3469 if (dma[0] && !parport_parse_dma(dma[0], &val))
3470 switch (val) {
3471 case PARPORT_DMA_NONE:
3472 case PARPORT_DMA_AUTO:
3473 dmaval[0] = val;
3474 break;
3475 default:
Alan Cox3aeda9b2009-06-11 13:07:29 +01003476 printk(KERN_WARNING
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 "parport_pc: dma specified "
3478 "without base address. Use 'io=' "
3479 "to specify one\n");
3480 }
3481 }
3482 return 0;
3483}
3484
3485#else
3486
Alan Cox3aeda9b2009-06-11 13:07:29 +01003487static int parport_setup_ptr __initdata;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488
3489/*
3490 * Acceptable parameters:
3491 *
3492 * parport=0
3493 * parport=auto
3494 * parport=0xBASE[,IRQ[,DMA]]
3495 *
3496 * IRQ/DMA may be numeric or 'auto' or 'none'
3497 */
Alan Cox3aeda9b2009-06-11 13:07:29 +01003498static int __init parport_setup(char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499{
3500 char *endptr;
3501 char *sep;
3502 int val;
3503
3504 if (!str || !*str || (*str == '0' && !*(str+1))) {
3505 /* Disable parport if "parport=0" in cmdline */
3506 io[0] = PARPORT_DISABLE;
3507 return 1;
3508 }
3509
Alan Cox3aeda9b2009-06-11 13:07:29 +01003510 if (!strncmp(str, "auto", 4)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 irqval[0] = PARPORT_IRQ_AUTO;
3512 dmaval[0] = PARPORT_DMA_AUTO;
3513 return 1;
3514 }
3515
Alan Cox3aeda9b2009-06-11 13:07:29 +01003516 val = simple_strtoul(str, &endptr, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 if (endptr == str) {
Alan Cox3aeda9b2009-06-11 13:07:29 +01003518 printk(KERN_WARNING "parport=%s not understood\n", str);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519 return 1;
3520 }
3521
3522 if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
3523 printk(KERN_ERR "parport=%s ignored, too many ports\n", str);
3524 return 1;
3525 }
3526
3527 io[parport_setup_ptr] = val;
3528 irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
3529 dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
3530
3531 sep = strchr(str, ',');
3532 if (sep++) {
3533 if (parport_parse_irq(sep, &val))
3534 return 1;
3535 irqval[parport_setup_ptr] = val;
3536 sep = strchr(sep, ',');
3537 if (sep++) {
3538 if (parport_parse_dma(sep, &val))
3539 return 1;
3540 dmaval[parport_setup_ptr] = val;
3541 }
3542 }
3543 parport_setup_ptr++;
3544 return 1;
3545}
3546
3547static int __init parse_parport_params(void)
3548{
3549 return io[0] == PARPORT_DISABLE;
3550}
3551
Alan Cox3aeda9b2009-06-11 13:07:29 +01003552__setup("parport=", parport_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
3554/*
3555 * Acceptable parameters:
3556 *
3557 * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
3558 */
3559#ifdef CONFIG_PCI
Alan Cox3aeda9b2009-06-11 13:07:29 +01003560__setup("parport_init_mode=", parport_init_mode_setup);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561#endif
3562#endif
3563
3564/* "Parser" ends here */
3565
3566static int __init parport_pc_init(void)
3567{
Jean Delvarea7d801a2007-05-08 00:27:40 -07003568 int err;
3569
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570 if (parse_parport_params())
3571 return -EINVAL;
3572
Jean Delvarea7d801a2007-05-08 00:27:40 -07003573 err = platform_driver_register(&parport_pc_platform_driver);
3574 if (err)
3575 return err;
3576
Linus Torvalds1da177e2005-04-16 15:20:36 -07003577 if (io[0]) {
3578 int i;
3579 /* Only probe the ports we were given. */
3580 user_specified = 1;
3581 for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
3582 if (!io[i])
3583 break;
Alan Cox3aeda9b2009-06-11 13:07:29 +01003584 if (io_hi[i] == PARPORT_IOHI_AUTO)
3585 io_hi[i] = 0x400 + io[i];
Bjorn Helgaas7597fee2006-03-27 01:17:02 -08003586 parport_pc_probe_port(io[i], io_hi[i],
Alan Cox3aeda9b2009-06-11 13:07:29 +01003587 irqval[i], dmaval[i], NULL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 }
3589 } else
Alan Cox3aeda9b2009-06-11 13:07:29 +01003590 parport_pc_find_ports(irqval[0], dmaval[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591
3592 return 0;
3593}
3594
3595static void __exit parport_pc_exit(void)
3596{
3597 if (pci_registered_parport)
Alan Cox3aeda9b2009-06-11 13:07:29 +01003598 pci_unregister_driver(&parport_pc_pci_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 if (pnp_registered_parport)
Alan Cox3aeda9b2009-06-11 13:07:29 +01003600 pnp_unregister_driver(&parport_pc_pnp_driver);
Jean Delvarea7d801a2007-05-08 00:27:40 -07003601 platform_driver_unregister(&parport_pc_platform_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003602
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 while (!list_empty(&ports_list)) {
3604 struct parport_pc_private *priv;
3605 struct parport *port;
3606 priv = list_entry(ports_list.next,
3607 struct parport_pc_private, list);
3608 port = priv->port;
Jean Delvarea7d801a2007-05-08 00:27:40 -07003609 if (port->dev && port->dev->bus == &platform_bus_type)
3610 platform_device_unregister(
3611 to_platform_device(port->dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003612 parport_pc_unregister_port(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003614}
3615
3616MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
3617MODULE_DESCRIPTION("PC-style parallel port driver");
3618MODULE_LICENSE("GPL");
3619module_init(parport_pc_init)
3620module_exit(parport_pc_exit)