Blame view

drivers/parport/parport_pc.c 85.4 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /* Low-level parallel-port routines for 8255-based PC-style hardware.
3aeda9bc9   Alan Cox   parport_pc: Codin...
2
   *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3
4
5
   * Authors: Phil Blundell <philb@gnu.org>
   *          Tim Waugh <tim@cyberelk.demon.co.uk>
   *	    Jose Renau <renau@acm.org>
bdca3f202   Adrian Bunk   remove the bounci...
6
   *          David Campbell
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
9
10
11
12
13
   *          Andrea Arcangeli
   *
   * based on work by Grant Guenther <grant@torque.net> and Phil Blundell.
   *
   * Cleaned up include files - Russell King <linux@arm.uk.linux.org>
   * DMA support - Bert De Jonghe <bert@sophis.be>
   * Many ECP bugs fixed.  Fred Barnes & Jamie Lokier, 1999
3aeda9bc9   Alan Cox   parport_pc: Codin...
14
   * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
   * Various hacks, Fred Barnes, 04/2001
   * Updated probing logic - Adam Belay <ambx1@neo.rr.com>
   */
  
  /* This driver should work with any hardware that is broadly compatible
   * with that in the IBM PC.  This applies to the majority of integrated
   * I/O chipsets that are commonly available.  The expected register
   * layout is:
   *
   *	base+0		data
   *	base+1		status
   *	base+2		control
   *
   * In addition, there are some optional registers:
   *
   *	base+3		EPP address
   *	base+4		EPP data
   *	base+0x400	ECP config A
   *	base+0x401	ECP config B
   *	base+0x402	ECP control
   *
   * All registers are 8 bits wide and read/write.  If your hardware differs
   * only in register addresses (eg because your registers are on 32-bit
   * word boundaries) then you can alter the constants in parport_pc.h to
   * accommodate this.
   *
   * Note that the ECP registers may not start at offset 0x400 for PCI cards,
   * but rather will start at port->base_hi.
   */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
46
47
48
49
50
51
52
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/sched.h>
  #include <linux/delay.h>
  #include <linux/errno.h>
  #include <linux/interrupt.h>
  #include <linux/ioport.h>
  #include <linux/kernel.h>
  #include <linux/slab.h>
8382d2b9a   Andrew Morton   parport_pc needs ...
53
  #include <linux/dma-mapping.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
54
55
  #include <linux/pci.h>
  #include <linux/pnp.h>
a7d801afc   Jean Delvare   legacy PC parport...
56
  #include <linux/platform_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
57
  #include <linux/sysctl.h>
3aeda9bc9   Alan Cox   parport_pc: Codin...
58
59
  #include <linux/io.h>
  #include <linux/uaccess.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
61
  #include <asm/dma.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
62
63
64
65
66
67
68
  
  #include <linux/parport.h>
  #include <linux/parport_pc.h>
  #include <linux/via.h>
  #include <asm/parport.h>
  
  #define PARPORT_PC_MAX_PORTS PARPORT_MAX
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
69
70
71
  #ifdef CONFIG_ISA_DMA_API
  #define HAS_DMA
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
73
74
75
76
77
78
79
80
81
  /* ECR modes */
  #define ECR_SPP 00
  #define ECR_PS2 01
  #define ECR_PPF 02
  #define ECR_ECP 03
  #define ECR_EPP 04
  #define ECR_VND 05
  #define ECR_TST 06
  #define ECR_CNF 07
  #define ECR_MODE_MASK 0xe0
3aeda9bc9   Alan Cox   parport_pc: Codin...
82
  #define ECR_WRITE(p, v) frob_econtrol((p), 0xff, (v))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  
  #undef DEBUG
  
  #ifdef DEBUG
  #define DPRINTK  printk
  #else
  #define DPRINTK(stuff...)
  #endif
  
  
  #define NR_SUPERIOS 3
  static struct superio_struct {	/* For Super-IO chips autodetection */
  	int io;
  	int irq;
  	int dma;
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
98
  } superios[NR_SUPERIOS] = { {0,},};
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99
100
101
102
103
104
105
106
107
108
  
  static int user_specified;
  #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
         (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
  static int verbose_probing;
  #endif
  static int pci_registered_parport;
  static int pnp_registered_parport;
  
  /* frob_control, but for ECR */
3aeda9bc9   Alan Cox   parport_pc: Codin...
109
  static void frob_econtrol(struct parport *pb, unsigned char m,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
110
111
112
113
114
  			   unsigned char v)
  {
  	unsigned char ectr = 0;
  
  	if (m != 0xff)
3aeda9bc9   Alan Cox   parport_pc: Codin...
115
  		ectr = inb(ECONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
116

3aeda9bc9   Alan Cox   parport_pc: Codin...
117
118
  	DPRINTK(KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
119
  		m, v, ectr, (ectr & ~m) ^ v);
3aeda9bc9   Alan Cox   parport_pc: Codin...
120
  	outb((ectr & ~m) ^ v, ECONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
121
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
122
  static inline void frob_set_mode(struct parport *p, int mode)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
123
  {
3aeda9bc9   Alan Cox   parport_pc: Codin...
124
  	frob_econtrol(p, ECR_MODE_MASK, mode << 5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
  }
  
  #ifdef CONFIG_PARPORT_PC_FIFO
3aeda9bc9   Alan Cox   parport_pc: Codin...
128
  /* Safely change the mode bits in the ECR
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
129
130
131
132
133
134
135
136
137
138
     Returns:
  	    0    : Success
  	   -EBUSY: Could not drain FIFO in some finite amount of time,
  		   mode not changed!
   */
  static int change_mode(struct parport *p, int m)
  {
  	const struct parport_pc_private *priv = p->physport->private_data;
  	unsigned char oecr;
  	int mode;
3aeda9bc9   Alan Cox   parport_pc: Codin...
139
140
  	DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x
  ", m);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
142
  
  	if (!priv->ecr) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
143
144
  		printk(KERN_DEBUG "change_mode: but there's no ECR!
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
145
146
147
148
  		return 0;
  	}
  
  	/* Bits <7:5> contain the mode. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
149
  	oecr = inb(ECONTROL(p));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
150
  	mode = (oecr >> 5) & 0x7;
3aeda9bc9   Alan Cox   parport_pc: Codin...
151
152
  	if (mode == m)
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
153
154
155
156
157
158
159
160
161
162
163
  
  	if (mode >= 2 && !(priv->ctr & 0x20)) {
  		/* This mode resets the FIFO, so we may
  		 * have to wait for it to drain first. */
  		unsigned long expire = jiffies + p->physport->cad->timeout;
  		int counter;
  		switch (mode) {
  		case ECR_PPF: /* Parallel Port FIFO mode */
  		case ECR_ECP: /* ECP Parallel Port mode */
  			/* Busy wait for 200us */
  			for (counter = 0; counter < 40; counter++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
164
  				if (inb(ECONTROL(p)) & 0x01)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
165
  					break;
3aeda9bc9   Alan Cox   parport_pc: Codin...
166
167
168
  				if (signal_pending(current))
  					break;
  				udelay(5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
169
170
171
  			}
  
  			/* Poll slowly. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
172
173
  			while (!(inb(ECONTROL(p)) & 0x01)) {
  				if (time_after_eq(jiffies, expire))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
174
175
  					/* The FIFO is stuck. */
  					return -EBUSY;
3aeda9bc9   Alan Cox   parport_pc: Codin...
176
177
178
  				schedule_timeout_interruptible(
  							msecs_to_jiffies(10));
  				if (signal_pending(current))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
179
180
181
182
183
184
185
186
187
  					break;
  			}
  		}
  	}
  
  	if (mode >= 2 && m >= 2) {
  		/* We have to go through mode 001 */
  		oecr &= ~(7 << 5);
  		oecr |= ECR_PS2 << 5;
3aeda9bc9   Alan Cox   parport_pc: Codin...
188
  		ECR_WRITE(p, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
189
190
191
192
193
  	}
  
  	/* Set the mode. */
  	oecr &= ~(7 << 5);
  	oecr |= m << 5;
3aeda9bc9   Alan Cox   parport_pc: Codin...
194
  	ECR_WRITE(p, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
195
196
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
  #endif /* FIFO support */
  
  /*
   * Clear TIMEOUT BIT in EPP MODE
   *
   * This is also used in SPP detection.
   */
  static int clear_epp_timeout(struct parport *pb)
  {
  	unsigned char r;
  
  	if (!(parport_pc_read_status(pb) & 0x01))
  		return 1;
  
  	/* To clear timeout some chips require double read */
  	parport_pc_read_status(pb);
  	r = parport_pc_read_status(pb);
3aeda9bc9   Alan Cox   parport_pc: Codin...
214
215
  	outb(r | 0x01, STATUS(pb)); /* Some reset by writing 1 */
  	outb(r & 0xfe, STATUS(pb)); /* Others by writing 0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
216
217
218
219
220
221
222
223
224
225
226
227
  	r = parport_pc_read_status(pb);
  
  	return !(r & 0x01);
  }
  
  /*
   * Access functions.
   *
   * Most of these aren't static because they may be used by the
   * parport_xxx_yyy macros.  extern __inline__ versions of several
   * of these are in parport_pc.h.
   */
3aeda9bc9   Alan Cox   parport_pc: Codin...
228
229
  static void parport_pc_init_state(struct pardevice *dev,
  						struct parport_state *s)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
  {
  	s->u.pc.ctr = 0xc;
  	if (dev->irq_func &&
  	    dev->port->irq != PARPORT_IRQ_NONE)
  		/* Set ackIntEn */
  		s->u.pc.ctr |= 0x10;
  
  	s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24;
  			     * D.Gruszka VScom */
  }
  
  static void parport_pc_save_state(struct parport *p, struct parport_state *s)
  {
  	const struct parport_pc_private *priv = p->physport->private_data;
  	s->u.pc.ctr = priv->ctr;
  	if (priv->ecr)
3aeda9bc9   Alan Cox   parport_pc: Codin...
246
  		s->u.pc.ecr = inb(ECONTROL(p));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
247
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
248
249
  static void parport_pc_restore_state(struct parport *p,
  						struct parport_state *s)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
250
251
252
  {
  	struct parport_pc_private *priv = p->physport->private_data;
  	register unsigned char c = s->u.pc.ctr & priv->ctr_writable;
3aeda9bc9   Alan Cox   parport_pc: Codin...
253
  	outb(c, CONTROL(p));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
254
255
  	priv->ctr = c;
  	if (priv->ecr)
3aeda9bc9   Alan Cox   parport_pc: Codin...
256
  		ECR_WRITE(p, s->u.pc.ecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
257
258
259
  }
  
  #ifdef CONFIG_PARPORT_1284
3aeda9bc9   Alan Cox   parport_pc: Codin...
260
261
  static size_t parport_pc_epp_read_data(struct parport *port, void *buf,
  				       size_t length, int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
262
263
264
265
266
267
268
269
270
271
272
  {
  	size_t got = 0;
  
  	if (flags & PARPORT_W91284PIC) {
  		unsigned char status;
  		size_t left = length;
  
  		/* use knowledge about data lines..:
  		 *  nFault is 0 if there is at least 1 byte in the Warp's FIFO
  		 *  pError is 1 if there are 16 bytes in the Warp's FIFO
  		 */
3aeda9bc9   Alan Cox   parport_pc: Codin...
273
  		status = inb(STATUS(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
274

3aeda9bc9   Alan Cox   parport_pc: Codin...
275
276
  		while (!(status & 0x08) && got < length) {
  			if (left >= 16 && (status & 0x20) && !(status & 0x08)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
277
  				/* can grab 16 bytes from warp fifo */
3aeda9bc9   Alan Cox   parport_pc: Codin...
278
279
280
281
  				if (!((long)buf & 0x03))
  					insl(EPPDATA(port), buf, 4);
  				else
  					insb(EPPDATA(port), buf, 16);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
282
283
284
285
286
  				buf += 16;
  				got += 16;
  				left -= 16;
  			} else {
  				/* grab single byte from the warp fifo */
3aeda9bc9   Alan Cox   parport_pc: Codin...
287
  				*((char *)buf) = inb(EPPDATA(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
288
289
290
291
  				buf++;
  				got++;
  				left--;
  			}
3aeda9bc9   Alan Cox   parport_pc: Codin...
292
  			status = inb(STATUS(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
294
  			if (status & 0x01) {
  				/* EPP timeout should never occur... */
3aeda9bc9   Alan Cox   parport_pc: Codin...
295
296
297
298
  				printk(KERN_DEBUG
  "%s: EPP timeout occurred while talking to w91284pic (should not have done)
  ", port->name);
  				clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
299
300
301
302
303
  			}
  		}
  		return got;
  	}
  	if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
304
305
306
307
308
309
  		if (!(((long)buf | length) & 0x03))
  			insl(EPPDATA(port), buf, (length >> 2));
  		else
  			insb(EPPDATA(port), buf, length);
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
310
311
312
313
314
  			return -EIO;
  		}
  		return length;
  	}
  	for (; got < length; got++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
315
  		*((char *)buf) = inb(EPPDATA(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
316
  		buf++;
3aeda9bc9   Alan Cox   parport_pc: Codin...
317
  		if (inb(STATUS(port)) & 0x01) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
318
  			/* EPP timeout */
3aeda9bc9   Alan Cox   parport_pc: Codin...
319
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
320
321
322
323
324
325
  			break;
  		}
  	}
  
  	return got;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
326
327
  static size_t parport_pc_epp_write_data(struct parport *port, const void *buf,
  					size_t length, int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
328
329
330
331
  {
  	size_t written = 0;
  
  	if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
332
333
334
335
336
337
  		if (!(((long)buf | length) & 0x03))
  			outsl(EPPDATA(port), buf, (length >> 2));
  		else
  			outsb(EPPDATA(port), buf, length);
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
338
339
340
341
342
  			return -EIO;
  		}
  		return length;
  	}
  	for (; written < length; written++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
343
  		outb(*((char *)buf), EPPDATA(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
344
  		buf++;
3aeda9bc9   Alan Cox   parport_pc: Codin...
345
346
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
347
348
349
350
351
352
  			break;
  		}
  	}
  
  	return written;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
353
  static size_t parport_pc_epp_read_addr(struct parport *port, void *buf,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
354
355
356
357
358
  					size_t length, int flags)
  {
  	size_t got = 0;
  
  	if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
359
360
361
  		insb(EPPADDR(port), buf, length);
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
362
363
364
365
366
  			return -EIO;
  		}
  		return length;
  	}
  	for (; got < length; got++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
367
  		*((char *)buf) = inb(EPPADDR(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
368
  		buf++;
3aeda9bc9   Alan Cox   parport_pc: Codin...
369
370
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
371
372
373
374
375
376
  			break;
  		}
  	}
  
  	return got;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
377
  static size_t parport_pc_epp_write_addr(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
378
379
380
381
382
383
  					 const void *buf, size_t length,
  					 int flags)
  {
  	size_t written = 0;
  
  	if ((flags & PARPORT_EPP_FAST) && (length > 1)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
384
385
386
  		outsb(EPPADDR(port), buf, length);
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
387
388
389
390
391
  			return -EIO;
  		}
  		return length;
  	}
  	for (; written < length; written++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
392
  		outb(*((char *)buf), EPPADDR(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
393
  		buf++;
3aeda9bc9   Alan Cox   parport_pc: Codin...
394
395
  		if (inb(STATUS(port)) & 0x01) {
  			clear_epp_timeout(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
396
397
398
399
400
401
  			break;
  		}
  	}
  
  	return written;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
402
403
  static size_t parport_pc_ecpepp_read_data(struct parport *port, void *buf,
  					  size_t length, int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
404
405
  {
  	size_t got;
3aeda9bc9   Alan Cox   parport_pc: Codin...
406
407
408
409
410
  	frob_set_mode(port, ECR_EPP);
  	parport_pc_data_reverse(port);
  	parport_pc_write_control(port, 0x4);
  	got = parport_pc_epp_read_data(port, buf, length, flags);
  	frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
411
412
413
  
  	return got;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
414
415
416
  static size_t parport_pc_ecpepp_write_data(struct parport *port,
  					   const void *buf, size_t length,
  					   int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
417
418
  {
  	size_t written;
3aeda9bc9   Alan Cox   parport_pc: Codin...
419
420
421
422
423
  	frob_set_mode(port, ECR_EPP);
  	parport_pc_write_control(port, 0x4);
  	parport_pc_data_forward(port);
  	written = parport_pc_epp_write_data(port, buf, length, flags);
  	frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
424
425
426
  
  	return written;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
427
428
  static size_t parport_pc_ecpepp_read_addr(struct parport *port, void *buf,
  					  size_t length, int flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
429
430
  {
  	size_t got;
3aeda9bc9   Alan Cox   parport_pc: Codin...
431
432
433
434
435
  	frob_set_mode(port, ECR_EPP);
  	parport_pc_data_reverse(port);
  	parport_pc_write_control(port, 0x4);
  	got = parport_pc_epp_read_addr(port, buf, length, flags);
  	frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
436
437
438
  
  	return got;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
439
  static size_t parport_pc_ecpepp_write_addr(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
440
441
442
443
  					    const void *buf, size_t length,
  					    int flags)
  {
  	size_t written;
3aeda9bc9   Alan Cox   parport_pc: Codin...
444
445
446
447
448
  	frob_set_mode(port, ECR_EPP);
  	parport_pc_write_control(port, 0x4);
  	parport_pc_data_forward(port);
  	written = parport_pc_epp_write_addr(port, buf, length, flags);
  	frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
449
450
451
452
453
454
  
  	return written;
  }
  #endif /* IEEE 1284 support */
  
  #ifdef CONFIG_PARPORT_PC_FIFO
3aeda9bc9   Alan Cox   parport_pc: Codin...
455
  static size_t parport_pc_fifo_write_block_pio(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
456
457
458
459
460
461
  					       const void *buf, size_t length)
  {
  	int ret = 0;
  	const unsigned char *bufp = buf;
  	size_t left = length;
  	unsigned long expire = jiffies + port->physport->cad->timeout;
3aeda9bc9   Alan Cox   parport_pc: Codin...
462
  	const int fifo = FIFO(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
463
464
465
466
467
468
469
  	int poll_for = 8; /* 80 usecs */
  	const struct parport_pc_private *priv = port->physport->private_data;
  	const int fifo_depth = priv->fifo_depth;
  
  	port = port->physport;
  
  	/* We don't want to be interrupted every character. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
470
  	parport_pc_disable_irq(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
471
  	/* set nErrIntrEn and serviceIntr */
3aeda9bc9   Alan Cox   parport_pc: Codin...
472
  	frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
473
474
  
  	/* Forward mode. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
475
  	parport_pc_data_forward(port); /* Must be in PS2 mode */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
476
477
478
  
  	while (left) {
  		unsigned char byte;
3aeda9bc9   Alan Cox   parport_pc: Codin...
479
  		unsigned char ecrval = inb(ECONTROL(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
480
  		int i = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
481
  		if (need_resched() && time_before(jiffies, expire))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
482
  			/* Can't yield the port. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
483
  			schedule();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
484
485
486
  
  		/* Anyone else waiting for the port? */
  		if (port->waithead) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
487
488
  			printk(KERN_DEBUG "Somebody wants the port
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
489
490
491
492
493
494
495
  			break;
  		}
  
  		if (ecrval & 0x02) {
  			/* FIFO is full. Wait for interrupt. */
  
  			/* Clear serviceIntr */
3aeda9bc9   Alan Cox   parport_pc: Codin...
496
497
498
499
500
  			ECR_WRITE(port, ecrval & ~(1<<2));
  false_alarm:
  			ret = parport_wait_event(port, HZ);
  			if (ret < 0)
  				break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
501
  			ret = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
502
  			if (!time_before(jiffies, expire)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
503
  				/* Timed out. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
504
505
  				printk(KERN_DEBUG "FIFO write timed out
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
506
507
  				break;
  			}
3aeda9bc9   Alan Cox   parport_pc: Codin...
508
  			ecrval = inb(ECONTROL(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
509
510
  			if (!(ecrval & (1<<2))) {
  				if (need_resched() &&
3aeda9bc9   Alan Cox   parport_pc: Codin...
511
512
  				    time_before(jiffies, expire))
  					schedule();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
513
514
515
516
517
518
519
520
521
  
  				goto false_alarm;
  			}
  
  			continue;
  		}
  
  		/* Can't fail now. */
  		expire = jiffies + port->cad->timeout;
3aeda9bc9   Alan Cox   parport_pc: Codin...
522
523
  poll:
  		if (signal_pending(current))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
524
525
526
527
528
  			break;
  
  		if (ecrval & 0x01) {
  			/* FIFO is empty. Blast it full. */
  			const int n = left < fifo_depth ? left : fifo_depth;
3aeda9bc9   Alan Cox   parport_pc: Codin...
529
  			outsb(fifo, bufp, n);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
530
531
532
533
  			bufp += n;
  			left -= n;
  
  			/* Adjust the poll time. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
534
535
  			if (i < (poll_for - 2))
  				poll_for--;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
536
537
  			continue;
  		} else if (i++ < poll_for) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
538
539
  			udelay(10);
  			ecrval = inb(ECONTROL(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
540
541
  			goto poll;
  		}
3aeda9bc9   Alan Cox   parport_pc: Codin...
542
  		/* Half-full(call me an optimist) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
543
  		byte = *bufp++;
3aeda9bc9   Alan Cox   parport_pc: Codin...
544
  		outb(byte, fifo);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
545
  		left--;
3aeda9bc9   Alan Cox   parport_pc: Codin...
546
547
  	}
  	dump_parport_state("leave fifo_write_block_pio", port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
548
549
  	return length - left;
  }
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
550
  #ifdef HAS_DMA
3aeda9bc9   Alan Cox   parport_pc: Codin...
551
  static size_t parport_pc_fifo_write_block_dma(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
552
553
554
555
556
557
  					       const void *buf, size_t length)
  {
  	int ret = 0;
  	unsigned long dmaflag;
  	size_t left = length;
  	const struct parport_pc_private *priv = port->physport->private_data;
c15a3837d   David Brownell   parport->dev driv...
558
  	struct device *dev = port->physport->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
559
560
561
562
  	dma_addr_t dma_addr, dma_handle;
  	size_t maxlen = 0x10000; /* max 64k per DMA transfer */
  	unsigned long start = (unsigned long) buf;
  	unsigned long end = (unsigned long) buf + length - 1;
181bf1e81   Alan Cox   parport_pc: clean...
563
  	dump_parport_state("enter fifo_write_block_dma", port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
564
565
566
567
  	if (end < MAX_DMA_ADDRESS) {
  		/* If it would cross a 64k boundary, cap it at the end. */
  		if ((start ^ end) & ~0xffffUL)
  			maxlen = 0x10000 - (start & 0xffff);
c15a3837d   David Brownell   parport->dev driv...
568
569
  		dma_addr = dma_handle = dma_map_single(dev, (void *)buf, length,
  						       DMA_TO_DEVICE);
3aeda9bc9   Alan Cox   parport_pc: Codin...
570
571
572
  	} else {
  		/* above 16 MB we use a bounce buffer as ISA-DMA
  		   is not possible */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
573
574
575
576
577
578
579
580
  		maxlen   = PAGE_SIZE;          /* sizeof(priv->dma_buf) */
  		dma_addr = priv->dma_handle;
  		dma_handle = 0;
  	}
  
  	port = port->physport;
  
  	/* We don't want to be interrupted every character. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
581
  	parport_pc_disable_irq(port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
582
  	/* set nErrIntrEn and serviceIntr */
3aeda9bc9   Alan Cox   parport_pc: Codin...
583
  	frob_econtrol(port, (1<<4) | (1<<2), (1<<4) | (1<<2));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
584
585
  
  	/* Forward mode. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
586
  	parport_pc_data_forward(port); /* Must be in PS2 mode */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
  
  	while (left) {
  		unsigned long expire = jiffies + port->physport->cad->timeout;
  
  		size_t count = left;
  
  		if (count > maxlen)
  			count = maxlen;
  
  		if (!dma_handle)   /* bounce buffer ! */
  			memcpy(priv->dma_buf, buf, count);
  
  		dmaflag = claim_dma_lock();
  		disable_dma(port->dma);
  		clear_dma_ff(port->dma);
  		set_dma_mode(port->dma, DMA_MODE_WRITE);
  		set_dma_addr(port->dma, dma_addr);
  		set_dma_count(port->dma, count);
  
  		/* Set DMA mode */
3aeda9bc9   Alan Cox   parport_pc: Codin...
607
  		frob_econtrol(port, 1<<3, 1<<3);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
608
609
  
  		/* Clear serviceIntr */
3aeda9bc9   Alan Cox   parport_pc: Codin...
610
  		frob_econtrol(port, 1<<2, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
611
612
613
614
615
616
617
  
  		enable_dma(port->dma);
  		release_dma_lock(dmaflag);
  
  		/* assume DMA will be successful */
  		left -= count;
  		buf  += count;
3aeda9bc9   Alan Cox   parport_pc: Codin...
618
619
  		if (dma_handle)
  			dma_addr += count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
620
621
  
  		/* Wait for interrupt. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
622
623
624
625
  false_alarm:
  		ret = parport_wait_event(port, HZ);
  		if (ret < 0)
  			break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
626
  		ret = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
627
  		if (!time_before(jiffies, expire)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
628
  			/* Timed out. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
629
630
  			printk(KERN_DEBUG "DMA write timed out
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
631
632
633
  			break;
  		}
  		/* Is serviceIntr set? */
3aeda9bc9   Alan Cox   parport_pc: Codin...
634
  		if (!(inb(ECONTROL(port)) & (1<<2))) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
  			cond_resched();
  
  			goto false_alarm;
  		}
  
  		dmaflag = claim_dma_lock();
  		disable_dma(port->dma);
  		clear_dma_ff(port->dma);
  		count = get_dma_residue(port->dma);
  		release_dma_lock(dmaflag);
  
  		cond_resched(); /* Can't yield the port. */
  
  		/* Anyone else waiting for the port? */
  		if (port->waithead) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
650
651
  			printk(KERN_DEBUG "Somebody wants the port
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
652
653
654
655
656
657
  			break;
  		}
  
  		/* update for possible DMA residue ! */
  		buf  -= count;
  		left += count;
3aeda9bc9   Alan Cox   parport_pc: Codin...
658
659
  		if (dma_handle)
  			dma_addr -= count;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
660
661
662
663
664
665
666
667
668
669
  	}
  
  	/* Maybe got here through break, so adjust for DMA residue! */
  	dmaflag = claim_dma_lock();
  	disable_dma(port->dma);
  	clear_dma_ff(port->dma);
  	left += get_dma_residue(port->dma);
  	release_dma_lock(dmaflag);
  
  	/* Turn off DMA mode */
3aeda9bc9   Alan Cox   parport_pc: Codin...
670
  	frob_econtrol(port, 1<<3, 0);
c15a3837d   David Brownell   parport->dev driv...
671

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
672
  	if (dma_handle)
c15a3837d   David Brownell   parport->dev driv...
673
  		dma_unmap_single(dev, dma_handle, length, DMA_TO_DEVICE);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
674

181bf1e81   Alan Cox   parport_pc: clean...
675
  	dump_parport_state("leave fifo_write_block_dma", port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
676
677
  	return length - left;
  }
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
678
679
680
681
682
683
684
  #endif
  
  static inline size_t parport_pc_fifo_write_block(struct parport *port,
  					       const void *buf, size_t length)
  {
  #ifdef HAS_DMA
  	if (port->dma != PARPORT_DMA_NONE)
3aeda9bc9   Alan Cox   parport_pc: Codin...
685
  		return parport_pc_fifo_write_block_dma(port, buf, length);
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
686
  #endif
3aeda9bc9   Alan Cox   parport_pc: Codin...
687
  	return parport_pc_fifo_write_block_pio(port, buf, length);
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
688
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
689
690
  
  /* Parallel Port FIFO mode (ECP chipsets) */
3aeda9bc9   Alan Cox   parport_pc: Codin...
691
  static size_t parport_pc_compat_write_block_pio(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
692
693
694
695
696
697
698
699
700
701
702
  						 const void *buf, size_t length,
  						 int flags)
  {
  	size_t written;
  	int r;
  	unsigned long expire;
  	const struct parport_pc_private *priv = port->physport->private_data;
  
  	/* Special case: a timeout of zero means we cannot call schedule().
  	 * Also if O_NONBLOCK is set then use the default implementation. */
  	if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
3aeda9bc9   Alan Cox   parport_pc: Codin...
703
  		return parport_ieee1284_write_compat(port, buf,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
704
705
706
  						      length, flags);
  
  	/* Set up parallel port FIFO mode.*/
3aeda9bc9   Alan Cox   parport_pc: Codin...
707
708
709
710
711
712
713
  	parport_pc_data_forward(port); /* Must be in PS2 mode */
  	parport_pc_frob_control(port, PARPORT_CONTROL_STROBE, 0);
  	r = change_mode(port, ECR_PPF); /* Parallel port FIFO */
  	if (r)
  		printk(KERN_DEBUG "%s: Warning change_mode ECR_PPF failed
  ",
  								port->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
714
715
716
717
  
  	port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
  
  	/* Write the data to the FIFO. */
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
718
  	written = parport_pc_fifo_write_block(port, buf, length);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
719
720
721
722
723
724
  
  	/* Finish up. */
  	/* For some hardware we don't want to touch the mode until
  	 * the FIFO is empty, so allow 4 seconds for each position
  	 * in the fifo.
  	 */
3aeda9bc9   Alan Cox   parport_pc: Codin...
725
  	expire = jiffies + (priv->fifo_depth * HZ * 4);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
726
727
  	do {
  		/* Wait for the FIFO to empty */
3aeda9bc9   Alan Cox   parport_pc: Codin...
728
729
  		r = change_mode(port, ECR_PS2);
  		if (r != -EBUSY)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
730
  			break;
3aeda9bc9   Alan Cox   parport_pc: Codin...
731
  	} while (time_before(jiffies, expire));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
732
  	if (r == -EBUSY) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
733
734
  		printk(KERN_DEBUG "%s: FIFO is stuck
  ", port->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
735
736
  
  		/* Prevent further data transfer. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
737
  		frob_set_mode(port, ECR_TST);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
738
739
740
  
  		/* Adjust for the contents of the FIFO. */
  		for (written -= priv->fifo_depth; ; written++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
741
  			if (inb(ECONTROL(port)) & 0x2) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
742
743
744
  				/* Full up. */
  				break;
  			}
3aeda9bc9   Alan Cox   parport_pc: Codin...
745
  			outb(0, FIFO(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
746
747
748
  		}
  
  		/* Reset the FIFO and return to PS2 mode. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
749
  		frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
750
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
751
  	r = parport_wait_peripheral(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
752
753
754
  				     PARPORT_STATUS_BUSY,
  				     PARPORT_STATUS_BUSY);
  	if (r)
3aeda9bc9   Alan Cox   parport_pc: Codin...
755
756
757
  		printk(KERN_DEBUG
  			"%s: BUSY timeout (%d) in compat_write_block_pio
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
758
759
760
761
762
763
764
765
766
  			port->name, r);
  
  	port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
  
  	return written;
  }
  
  /* ECP */
  #ifdef CONFIG_PARPORT_1284
3aeda9bc9   Alan Cox   parport_pc: Codin...
767
  static size_t parport_pc_ecp_write_block_pio(struct parport *port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
768
769
770
771
772
773
774
775
776
777
778
  					      const void *buf, size_t length,
  					      int flags)
  {
  	size_t written;
  	int r;
  	unsigned long expire;
  	const struct parport_pc_private *priv = port->physport->private_data;
  
  	/* Special case: a timeout of zero means we cannot call schedule().
  	 * Also if O_NONBLOCK is set then use the default implementation. */
  	if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK)
3aeda9bc9   Alan Cox   parport_pc: Codin...
779
  		return parport_ieee1284_ecp_write_data(port, buf,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
780
781
782
783
784
  							length, flags);
  
  	/* Switch to forward mode if necessary. */
  	if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
  		/* Event 47: Set nInit high. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
785
  		parport_frob_control(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
786
787
788
789
790
791
  				      PARPORT_CONTROL_INIT
  				      | PARPORT_CONTROL_AUTOFD,
  				      PARPORT_CONTROL_INIT
  				      | PARPORT_CONTROL_AUTOFD);
  
  		/* Event 49: PError goes high. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
792
  		r = parport_wait_peripheral(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
793
794
795
  					     PARPORT_STATUS_PAPEROUT,
  					     PARPORT_STATUS_PAPEROUT);
  		if (r) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
796
  			printk(KERN_DEBUG "%s: PError timeout (%d) "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
797
798
799
800
801
802
  				"in ecp_write_block_pio
  ", port->name, r);
  		}
  	}
  
  	/* Set up ECP parallel port mode.*/
3aeda9bc9   Alan Cox   parport_pc: Codin...
803
804
  	parport_pc_data_forward(port); /* Must be in PS2 mode */
  	parport_pc_frob_control(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
805
806
807
  				 PARPORT_CONTROL_STROBE |
  				 PARPORT_CONTROL_AUTOFD,
  				 0);
3aeda9bc9   Alan Cox   parport_pc: Codin...
808
809
810
811
812
  	r = change_mode(port, ECR_ECP); /* ECP FIFO */
  	if (r)
  		printk(KERN_DEBUG "%s: Warning change_mode ECR_ECP failed
  ",
  								port->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
813
814
815
  	port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA;
  
  	/* Write the data to the FIFO. */
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
816
  	written = parport_pc_fifo_write_block(port, buf, length);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
817
818
819
820
821
822
823
824
825
  
  	/* Finish up. */
  	/* For some hardware we don't want to touch the mode until
  	 * the FIFO is empty, so allow 4 seconds for each position
  	 * in the fifo.
  	 */
  	expire = jiffies + (priv->fifo_depth * (HZ * 4));
  	do {
  		/* Wait for the FIFO to empty */
3aeda9bc9   Alan Cox   parport_pc: Codin...
826
827
  		r = change_mode(port, ECR_PS2);
  		if (r != -EBUSY)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
828
  			break;
3aeda9bc9   Alan Cox   parport_pc: Codin...
829
  	} while (time_before(jiffies, expire));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
830
  	if (r == -EBUSY) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
831
832
  		printk(KERN_DEBUG "%s: FIFO is stuck
  ", port->name);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
833
834
  
  		/* Prevent further data transfer. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
835
  		frob_set_mode(port, ECR_TST);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
836
837
838
  
  		/* Adjust for the contents of the FIFO. */
  		for (written -= priv->fifo_depth; ; written++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
839
  			if (inb(ECONTROL(port)) & 0x2) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
840
841
842
  				/* Full up. */
  				break;
  			}
3aeda9bc9   Alan Cox   parport_pc: Codin...
843
  			outb(0, FIFO(port));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
844
845
846
  		}
  
  		/* Reset the FIFO and return to PS2 mode. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
847
  		frob_set_mode(port, ECR_PS2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
848
849
  
  		/* Host transfer recovery. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
850
851
852
853
  		parport_pc_data_reverse(port); /* Must be in PS2 mode */
  		udelay(5);
  		parport_frob_control(port, PARPORT_CONTROL_INIT, 0);
  		r = parport_wait_peripheral(port, PARPORT_STATUS_PAPEROUT, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
854
  		if (r)
3aeda9bc9   Alan Cox   parport_pc: Codin...
855
  			printk(KERN_DEBUG "%s: PE,1 timeout (%d) "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
856
857
  				"in ecp_write_block_pio
  ", port->name, r);
3aeda9bc9   Alan Cox   parport_pc: Codin...
858
  		parport_frob_control(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
859
860
  				      PARPORT_CONTROL_INIT,
  				      PARPORT_CONTROL_INIT);
3aeda9bc9   Alan Cox   parport_pc: Codin...
861
  		r = parport_wait_peripheral(port,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
862
863
  					     PARPORT_STATUS_PAPEROUT,
  					     PARPORT_STATUS_PAPEROUT);
3aeda9bc9   Alan Cox   parport_pc: Codin...
864
865
  		if (r)
  			printk(KERN_DEBUG "%s: PE,2 timeout (%d) "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
866
867
868
  				"in ecp_write_block_pio
  ", port->name, r);
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
869
870
  	r = parport_wait_peripheral(port,
  				     PARPORT_STATUS_BUSY,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
871
  				     PARPORT_STATUS_BUSY);
3aeda9bc9   Alan Cox   parport_pc: Codin...
872
873
  	if (r)
  		printk(KERN_DEBUG
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
874
875
876
877
878
879
880
881
  			"%s: BUSY timeout (%d) in ecp_write_block_pio
  ",
  			port->name, r);
  
  	port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
  
  	return written;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
882
883
884
885
886
887
888
889
890
891
892
893
  #endif /* IEEE 1284 support */
  #endif /* Allowed to use FIFO/DMA */
  
  
  /*
   *	******************************************
   *	INITIALISATION AND MODULE STUFF BELOW HERE
   *	******************************************
   */
  
  /* GCC is not inlining extern inline function later overwriten to non-inline,
     so we use outlined_ variants here.  */
3aeda9bc9   Alan Cox   parport_pc: Codin...
894
  static const struct parport_operations parport_pc_ops = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
  	.write_data	= parport_pc_write_data,
  	.read_data	= parport_pc_read_data,
  
  	.write_control	= parport_pc_write_control,
  	.read_control	= parport_pc_read_control,
  	.frob_control	= parport_pc_frob_control,
  
  	.read_status	= parport_pc_read_status,
  
  	.enable_irq	= parport_pc_enable_irq,
  	.disable_irq	= parport_pc_disable_irq,
  
  	.data_forward	= parport_pc_data_forward,
  	.data_reverse	= parport_pc_data_reverse,
  
  	.init_state	= parport_pc_init_state,
  	.save_state	= parport_pc_save_state,
  	.restore_state	= parport_pc_restore_state,
  
  	.epp_write_data	= parport_ieee1284_epp_write_data,
  	.epp_read_data	= parport_ieee1284_epp_read_data,
  	.epp_write_addr	= parport_ieee1284_epp_write_addr,
  	.epp_read_addr	= parport_ieee1284_epp_read_addr,
  
  	.ecp_write_data	= parport_ieee1284_ecp_write_data,
  	.ecp_read_data	= parport_ieee1284_ecp_read_data,
  	.ecp_write_addr	= parport_ieee1284_ecp_write_addr,
  
  	.compat_write_data	= parport_ieee1284_write_compat,
  	.nibble_read_data	= parport_ieee1284_read_nibble,
  	.byte_read_data		= parport_ieee1284_read_byte,
  
  	.owner		= THIS_MODULE,
  };
  
  #ifdef CONFIG_PARPORT_PC_SUPERIO
181bf1e81   Alan Cox   parport_pc: clean...
931
932
933
934
935
936
937
938
939
  
  static struct superio_struct *find_free_superio(void)
  {
  	int i;
  	for (i = 0; i < NR_SUPERIOS; i++)
  		if (superios[i].io == 0)
  			return &superios[i];
  	return NULL;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
940
  /* Super-IO chipset detection, Winbond, SMSC */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
941
  static void show_parconfig_smsc37c669(int io, int key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
942
  {
181bf1e81   Alan Cox   parport_pc: clean...
943
944
  	int cr1, cr4, cra, cr23, cr26, cr27;
  	struct superio_struct *s;
3aeda9bc9   Alan Cox   parport_pc: Codin...
945
  	static const char *const modes[] = {
a6767b7cc   Marko Kohtala   [PATCH] parport: ...
946
947
948
949
  		"SPP and Bidirectional (PS/2)",
  		"EPP and SPP",
  		"ECP",
  		"ECP and EPP" };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
950

3aeda9bc9   Alan Cox   parport_pc: Codin...
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
  	outb(key, io);
  	outb(key, io);
  	outb(1, io);
  	cr1 = inb(io + 1);
  	outb(4, io);
  	cr4 = inb(io + 1);
  	outb(0x0a, io);
  	cra = inb(io + 1);
  	outb(0x23, io);
  	cr23 = inb(io + 1);
  	outb(0x26, io);
  	cr26 = inb(io + 1);
  	outb(0x27, io);
  	cr27 = inb(io + 1);
  	outb(0xaa, io);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
966
967
  
  	if (verbose_probing) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
968
969
  		printk(KERN_INFO
  			"SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
970
971
  			"A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x
  ",
3aeda9bc9   Alan Cox   parport_pc: Codin...
972
  			cr1, cr4, cra, cr23, cr26, cr27);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
973
974
975
  		/* The documentation calls DMA and IRQ-Lines by letters, so
  		   the board maker can/will wire them
  		   appropriately/randomly...  G=reserved H=IDE-irq, */
3aeda9bc9   Alan Cox   parport_pc: Codin...
976
977
978
979
980
981
982
  		printk(KERN_INFO
  	"SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, fifo threshold=%d
  ",
  				cr23 * 4,
  				(cr27 & 0x0f) ? 'A' - 1 + (cr27 & 0x0f) : '-',
  				(cr26 & 0x0f) ? 'A' - 1 + (cr26 & 0x0f) : '-',
  				cra & 0x0f);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
983
984
  		printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s
  ",
3aeda9bc9   Alan Cox   parport_pc: Codin...
985
986
987
988
989
990
991
992
  		       (cr23 * 4 >= 0x100) ? "yes" : "no",
  		       (cr1 & 4) ? "yes" : "no");
  		printk(KERN_INFO
  			"SMSC LPT Config: Port mode=%s, EPP version =%s
  ",
  				(cr1 & 0x08) ? "Standard mode only (SPP)"
  					      : modes[cr4 & 0x03],
  				(cr4 & 0x40) ? "1.7" : "1.9");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
993
  	}
73e0d48b8   Michael Buesch   parport_pc: Fix s...
994

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
995
996
997
998
  	/* Heuristics !  BIOS setup for this mainboard device limits
  	   the choices to standard settings, i.e. io-address and IRQ
  	   are related, however DMA can be 1 or 3, assume DMA_A=DMA1,
  	   DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */
73e0d48b8   Michael Buesch   parport_pc: Fix s...
999
  	if (cr23 * 4 >= 0x100) { /* if active */
181bf1e81   Alan Cox   parport_pc: clean...
1000
1001
  		s = find_free_superio();
  		if (s == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1002
1003
  			printk(KERN_INFO "Super-IO: too many chips!
  ");
181bf1e81   Alan Cox   parport_pc: clean...
1004
  		else {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1005
  			int d;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1006
1007
  			switch (cr23 * 4) {
  			case 0x3bc:
181bf1e81   Alan Cox   parport_pc: clean...
1008
1009
  				s->io = 0x3bc;
  				s->irq = 7;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1010
1011
  				break;
  			case 0x378:
181bf1e81   Alan Cox   parport_pc: clean...
1012
1013
  				s->io = 0x378;
  				s->irq = 7;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1014
1015
  				break;
  			case 0x278:
181bf1e81   Alan Cox   parport_pc: clean...
1016
1017
  				s->io = 0x278;
  				s->irq = 5;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1018
  			}
3aeda9bc9   Alan Cox   parport_pc: Codin...
1019
1020
  			d = (cr26 & 0x0f);
  			if (d == 1 || d == 3)
181bf1e81   Alan Cox   parport_pc: clean...
1021
  				s->dma = d;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1022
  			else
181bf1e81   Alan Cox   parport_pc: clean...
1023
  				s->dma = PARPORT_DMA_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1024
  		}
3aeda9bc9   Alan Cox   parport_pc: Codin...
1025
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1026
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1027
  static void show_parconfig_winbond(int io, int key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1028
  {
181bf1e81   Alan Cox   parport_pc: clean...
1029
1030
  	int cr30, cr60, cr61, cr70, cr74, crf0;
  	struct superio_struct *s;
a6767b7cc   Marko Kohtala   [PATCH] parport: ...
1031
  	static const char *const modes[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1032
1033
1034
1035
1036
1037
1038
1039
  		"Standard (SPP) and Bidirectional(PS/2)", /* 0 */
  		"EPP-1.9 and SPP",
  		"ECP",
  		"ECP and EPP-1.9",
  		"Standard (SPP)",
  		"EPP-1.7 and SPP",		/* 5 */
  		"undefined!",
  		"ECP and EPP-1.7" };
a6767b7cc   Marko Kohtala   [PATCH] parport: ...
1040
1041
1042
  	static char *const irqtypes[] = {
  		"pulsed low, high-Z",
  		"follows nACK" };
3aeda9bc9   Alan Cox   parport_pc: Codin...
1043

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1044
  	/* The registers are called compatible-PnP because the
3aeda9bc9   Alan Cox   parport_pc: Codin...
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
  	   register layout is modelled after ISA-PnP, the access
  	   method is just another ... */
  	outb(key, io);
  	outb(key, io);
  	outb(0x07, io);   /* Register 7: Select Logical Device */
  	outb(0x01, io + 1); /* LD1 is Parallel Port */
  	outb(0x30, io);
  	cr30 = inb(io + 1);
  	outb(0x60, io);
  	cr60 = inb(io + 1);
  	outb(0x61, io);
  	cr61 = inb(io + 1);
  	outb(0x70, io);
  	cr70 = inb(io + 1);
  	outb(0x74, io);
  	cr74 = inb(io + 1);
  	outb(0xf0, io);
  	crf0 = inb(io + 1);
  	outb(0xaa, io);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1064
1065
  
  	if (verbose_probing) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1066
1067
1068
1069
1070
1071
  		printk(KERN_INFO
      "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x 70=%02x 74=%02x, f0=%02x
  ",
  					cr30, cr60, cr61, cr70, cr74, crf0);
  		printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ",
  		       (cr30 & 0x01) ? "yes" : "no", cr60, cr61, cr70 & 0x0f);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1072
1073
1074
1075
  		if ((cr74 & 0x07) > 3)
  			printk("dma=none
  ");
  		else
3aeda9bc9   Alan Cox   parport_pc: Codin...
1076
1077
1078
1079
1080
1081
1082
1083
1084
  			printk("dma=%d
  ", cr74 & 0x07);
  		printk(KERN_INFO
  		    "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d
  ",
  					irqtypes[crf0>>7], (crf0>>3)&0x0f);
  		printk(KERN_INFO "Winbond LPT Config: Port mode=%s
  ",
  					modes[crf0 & 0x07]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1085
  	}
73e0d48b8   Michael Buesch   parport_pc: Fix s...
1086
  	if (cr30 & 0x01) { /* the settings can be interrogated later ... */
181bf1e81   Alan Cox   parport_pc: clean...
1087
1088
  		s = find_free_superio();
  		if (s == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1089
1090
  			printk(KERN_INFO "Super-IO: too many chips!
  ");
181bf1e81   Alan Cox   parport_pc: clean...
1091
1092
1093
1094
  		else {
  			s->io = (cr60 << 8) | cr61;
  			s->irq = cr70 & 0x0f;
  			s->dma = (((cr74 & 0x07) > 3) ?
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1095
1096
1097
1098
  					   PARPORT_DMA_NONE : (cr74 & 0x07));
  		}
  	}
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1099
  static void decode_winbond(int efer, int key, int devid, int devrev, int oldid)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1100
1101
  {
  	const char *type = "unknown";
3aeda9bc9   Alan Cox   parport_pc: Codin...
1102
  	int id, progif = 2;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1103
1104
1105
  
  	if (devid == devrev)
  		/* simple heuristics, we happened to read some
3aeda9bc9   Alan Cox   parport_pc: Codin...
1106
  		   non-winbond register */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1107
  		return;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1108
  	id = (devid << 8) | devrev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1109
1110
  
  	/* Values are from public data sheets pdf files, I can just
3aeda9bc9   Alan Cox   parport_pc: Codin...
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
  	   confirm 83977TF is correct :-) */
  	if (id == 0x9771)
  		type = "83977F/AF";
  	else if (id == 0x9773)
  		type = "83977TF / SMSC 97w33x/97w34x";
  	else if (id == 0x9774)
  		type = "83977ATF";
  	else if ((id & ~0x0f) == 0x5270)
  		type = "83977CTF / SMSC 97w36x";
  	else if ((id & ~0x0f) == 0x52f0)
  		type = "83977EF / SMSC 97w35x";
  	else if ((id & ~0x0f) == 0x5210)
  		type = "83627";
  	else if ((id & ~0x0f) == 0x6010)
  		type = "83697HF";
  	else if ((oldid & 0x0f) == 0x0a) {
  		type = "83877F";
  		progif = 1;
  	} else if ((oldid & 0x0f) == 0x0b) {
  		type = "83877AF";
  		progif = 1;
  	} else if ((oldid & 0x0f) == 0x0c) {
  		type = "83877TF";
  		progif = 1;
  	} else if ((oldid & 0x0f) == 0x0d) {
  		type = "83877ATF";
  		progif = 1;
  	} else
  		progif = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1140
1141
1142
  
  	if (verbose_probing)
  		printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x "
3aeda9bc9   Alan Cox   parport_pc: Codin...
1143
1144
  		       "devid=%02x devrev=%02x oldid=%02x type=%s
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1145
1146
1147
  		       efer, key, devid, devrev, oldid, type);
  
  	if (progif == 2)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1148
  		show_parconfig_winbond(efer, key);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1149
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1150
  static void decode_smsc(int efer, int key, int devid, int devrev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1151
  {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1152
  	const char *type = "unknown";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1153
  	void (*func)(int io, int key);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1154
  	int id;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1155

3aeda9bc9   Alan Cox   parport_pc: Codin...
1156
  	if (devid == devrev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1157
  		/* simple heuristics, we happened to read some
3aeda9bc9   Alan Cox   parport_pc: Codin...
1158
  		   non-smsc register */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1159
  		return;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1160
1161
  	func = NULL;
  	id = (devid << 8) | devrev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1162

3aeda9bc9   Alan Cox   parport_pc: Codin...
1163
1164
1165
1166
1167
1168
1169
1170
1171
  	if (id == 0x0302) {
  		type = "37c669";
  		func = show_parconfig_smsc37c669;
  	} else if (id == 0x6582)
  		type = "37c665IR";
  	else if	(devid == 0x65)
  		type = "37c665GT";
  	else if	(devid == 0x66)
  		type = "37c666GT";
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1172
1173
1174
1175
1176
1177
1178
1179
  
  	if (verbose_probing)
  		printk(KERN_INFO "SMSC chip at EFER=0x%x "
  		       "key=0x%02x devid=%02x devrev=%02x type=%s
  ",
  		       efer, key, devid, devrev, type);
  
  	if (func)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1180
  		func(efer, key);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1181
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1182
  static void winbond_check(int io, int key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1183
  {
e2434dc1c   Jens Rottmann   parport_pc: after...
1184
  	int origval, devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1185

145980a0b   Harvey Harrison   drivers: replace ...
1186
  	if (!request_region(io, 3, __func__))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1187
  		return;
e2434dc1c   Jens Rottmann   parport_pc: after...
1188
  	origval = inb(io); /* Save original value */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1189
  	/* First probe without key */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1190
1191
1192
1193
1194
1195
1196
1197
1198
  	outb(0x20, io);
  	x_devid = inb(io + 1);
  	outb(0x21, io);
  	x_devrev = inb(io + 1);
  	outb(0x09, io);
  	x_oldid = inb(io + 1);
  
  	outb(key, io);
  	outb(key, io);     /* Write Magic Sequence to EFER, extended
25985edce   Lucas De Marchi   Fix common misspe...
1199
  			      function enable register */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1200
1201
1202
1203
1204
1205
1206
  	outb(0x20, io);    /* Write EFIR, extended function index register */
  	devid = inb(io + 1);  /* Read EFDR, extended function data register */
  	outb(0x21, io);
  	devrev = inb(io + 1);
  	outb(0x09, io);
  	oldid = inb(io + 1);
  	outb(0xaa, io);    /* Magic Seal */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1207

e2434dc1c   Jens Rottmann   parport_pc: after...
1208
  	outb(origval, io); /* in case we poked some entirely different hardware */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1209
1210
  	if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid))
  		goto out; /* protection against false positives */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1211
  	decode_winbond(io, key, devid, devrev, oldid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1212
1213
1214
  out:
  	release_region(io, 3);
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1215
  static void winbond_check2(int io, int key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1216
  {
e2434dc1c   Jens Rottmann   parport_pc: after...
1217
  	int origval[3], devid, devrev, oldid, x_devid, x_devrev, x_oldid;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1218

145980a0b   Harvey Harrison   drivers: replace ...
1219
  	if (!request_region(io, 3, __func__))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1220
  		return;
e2434dc1c   Jens Rottmann   parport_pc: after...
1221
1222
1223
  	origval[0] = inb(io); /* Save original values */
  	origval[1] = inb(io + 1);
  	origval[2] = inb(io + 2);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1224
  	/* First probe without the key */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1225
1226
1227
1228
1229
1230
1231
1232
  	outb(0x20, io + 2);
  	x_devid = inb(io + 2);
  	outb(0x21, io + 1);
  	x_devrev = inb(io + 2);
  	outb(0x09, io + 1);
  	x_oldid = inb(io + 2);
  
  	outb(key, io);     /* Write Magic Byte to EFER, extended
25985edce   Lucas De Marchi   Fix common misspe...
1233
  			      function enable register */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1234
1235
1236
1237
1238
1239
1240
  	outb(0x20, io + 2);  /* Write EFIR, extended function index register */
  	devid = inb(io + 2);  /* Read EFDR, extended function data register */
  	outb(0x21, io + 1);
  	devrev = inb(io + 2);
  	outb(0x09, io + 1);
  	oldid = inb(io + 2);
  	outb(0xaa, io);    /* Magic Seal */
e2434dc1c   Jens Rottmann   parport_pc: after...
1241
1242
1243
  	outb(origval[0], io); /* in case we poked some entirely different hardware */
  	outb(origval[1], io + 1);
  	outb(origval[2], io + 2);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1244
  	if (x_devid == devid && x_devrev == devrev && x_oldid == oldid)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1245
  		goto out; /* protection against false positives */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1246
  	decode_winbond(io, key, devid, devrev, oldid);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1247
1248
1249
  out:
  	release_region(io, 3);
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1250
  static void smsc_check(int io, int key)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1251
  {
e2434dc1c   Jens Rottmann   parport_pc: after...
1252
  	int origval, id, rev, oldid, oldrev, x_id, x_rev, x_oldid, x_oldrev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1253

145980a0b   Harvey Harrison   drivers: replace ...
1254
  	if (!request_region(io, 3, __func__))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1255
  		return;
e2434dc1c   Jens Rottmann   parport_pc: after...
1256
  	origval = inb(io); /* Save original value */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1257
  	/* First probe without the key */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
  	outb(0x0d, io);
  	x_oldid = inb(io + 1);
  	outb(0x0e, io);
  	x_oldrev = inb(io + 1);
  	outb(0x20, io);
  	x_id = inb(io + 1);
  	outb(0x21, io);
  	x_rev = inb(io + 1);
  
  	outb(key, io);
  	outb(key, io);     /* Write Magic Sequence to EFER, extended
25985edce   Lucas De Marchi   Fix common misspe...
1269
  			      function enable register */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1270
1271
1272
1273
1274
1275
1276
1277
1278
  	outb(0x0d, io);    /* Write EFIR, extended function index register */
  	oldid = inb(io + 1);  /* Read EFDR, extended function data register */
  	outb(0x0e, io);
  	oldrev = inb(io + 1);
  	outb(0x20, io);
  	id = inb(io + 1);
  	outb(0x21, io);
  	rev = inb(io + 1);
  	outb(0xaa, io);    /* Magic Seal */
e2434dc1c   Jens Rottmann   parport_pc: after...
1279
  	outb(origval, io); /* in case we poked some entirely different hardware */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1280
1281
  	if (x_id == id && x_oldrev == oldrev &&
  	    x_oldid == oldid && x_rev == rev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1282
  		goto out; /* protection against false positives */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1283
  	decode_smsc(io, key, oldid, oldrev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1284
1285
1286
  out:
  	release_region(io, 3);
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1287
  static void detect_and_report_winbond(void)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1288
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1289
1290
1291
  	if (verbose_probing)
  		printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...
  ");
3aeda9bc9   Alan Cox   parport_pc: Codin...
1292
1293
1294
1295
1296
1297
1298
  	winbond_check(0x3f0, 0x87);
  	winbond_check(0x370, 0x87);
  	winbond_check(0x2e , 0x87);
  	winbond_check(0x4e , 0x87);
  	winbond_check(0x3f0, 0x86);
  	winbond_check2(0x250, 0x88);
  	winbond_check2(0x250, 0x89);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1299
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1300
  static void detect_and_report_smsc(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1301
1302
1303
1304
  {
  	if (verbose_probing)
  		printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...
  ");
3aeda9bc9   Alan Cox   parport_pc: Codin...
1305
1306
1307
1308
  	smsc_check(0x3f0, 0x55);
  	smsc_check(0x370, 0x55);
  	smsc_check(0x3f0, 0x44);
  	smsc_check(0x370, 0x44);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1309
  }
f63fd7e29   Petr Cvek   parport_pc: detec...
1310

312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1311
  static void detect_and_report_it87(void)
f63fd7e29   Petr Cvek   parport_pc: detec...
1312
1313
  {
  	u16 dev;
e2434dc1c   Jens Rottmann   parport_pc: after...
1314
  	u8 origval, r;
f63fd7e29   Petr Cvek   parport_pc: detec...
1315
1316
1317
  	if (verbose_probing)
  		printk(KERN_DEBUG "IT8705 Super-IO detection, now testing port 2E ...
  ");
868d1721a   Alan Cox   parport: Use requ...
1318
  	if (!request_muxed_region(0x2e, 2, __func__))
f63fd7e29   Petr Cvek   parport_pc: detec...
1319
  		return;
e2434dc1c   Jens Rottmann   parport_pc: after...
1320
  	origval = inb(0x2e);		/* Save original value */
f63fd7e29   Petr Cvek   parport_pc: detec...
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
  	outb(0x87, 0x2e);
  	outb(0x01, 0x2e);
  	outb(0x55, 0x2e);
  	outb(0x55, 0x2e);
  	outb(0x20, 0x2e);
  	dev = inb(0x2f) << 8;
  	outb(0x21, 0x2e);
  	dev |= inb(0x2f);
  	if (dev == 0x8712 || dev == 0x8705 || dev == 0x8715 ||
  	    dev == 0x8716 || dev == 0x8718 || dev == 0x8726) {
  		printk(KERN_INFO "IT%04X SuperIO detected.
  ", dev);
  		outb(0x07, 0x2E);	/* Parallel Port */
  		outb(0x03, 0x2F);
  		outb(0xF0, 0x2E);	/* BOOT 0x80 off */
  		r = inb(0x2f);
  		outb(0xF0, 0x2E);
  		outb(r | 8, 0x2F);
  		outb(0x02, 0x2E);	/* Lock */
  		outb(0x02, 0x2F);
e2434dc1c   Jens Rottmann   parport_pc: after...
1341
1342
  	} else {
  		outb(origval, 0x2e);	/* Oops, sorry to disturb */
f63fd7e29   Petr Cvek   parport_pc: detec...
1343
  	}
e2434dc1c   Jens Rottmann   parport_pc: after...
1344
  	release_region(0x2e, 2);
f63fd7e29   Petr Cvek   parport_pc: detec...
1345
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1346
  #endif /* CONFIG_PARPORT_PC_SUPERIO */
181bf1e81   Alan Cox   parport_pc: clean...
1347
  static struct superio_struct *find_superio(struct parport *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1348
  {
181bf1e81   Alan Cox   parport_pc: clean...
1349
1350
1351
1352
1353
1354
  	int i;
  	for (i = 0; i < NR_SUPERIOS; i++)
  		if (superios[i].io != p->base)
  			return &superios[i];
  	return NULL;
  }
73e0d48b8   Michael Buesch   parport_pc: Fix s...
1355

181bf1e81   Alan Cox   parport_pc: clean...
1356
1357
1358
1359
1360
  static int get_superio_dma(struct parport *p)
  {
  	struct superio_struct *s = find_superio(p);
  	if (s)
  		return s->dma;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1361
1362
  	return PARPORT_DMA_NONE;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
1363
  static int get_superio_irq(struct parport *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1364
  {
181bf1e81   Alan Cox   parport_pc: clean...
1365
1366
1367
  	struct superio_struct *s = find_superio(p);
  	if (s)
  		return s->irq;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1368
  	return PARPORT_IRQ_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1369
  }
73e0d48b8   Michael Buesch   parport_pc: Fix s...
1370

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1371
1372
1373
1374
1375
  
  /* --- Mode detection ------------------------------------- */
  
  /*
   * Checks for port existence, all ports support SPP MODE
3aeda9bc9   Alan Cox   parport_pc: Codin...
1376
   * Returns:
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1377
   *         0           :  No parallel port at this address
3aeda9bc9   Alan Cox   parport_pc: Codin...
1378
   *  PARPORT_MODE_PCSPP :  SPP port detected
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1379
1380
1381
1382
   *                        (if the user specified an ioport himself,
   *                         this shall always be the case!)
   *
   */
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1383
  static int parport_SPP_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1384
1385
1386
1387
  {
  	unsigned char r, w;
  
  	/*
3aeda9bc9   Alan Cox   parport_pc: Codin...
1388
  	 * first clear an eventually pending EPP timeout
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1389
1390
1391
1392
1393
1394
1395
1396
  	 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
  	 * that does not even respond to SPP cycles if an EPP
  	 * timeout is pending
  	 */
  	clear_epp_timeout(pb);
  
  	/* Do a simple read-write test to make sure the port exists. */
  	w = 0xc;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1397
  	outb(w, CONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1398
1399
1400
1401
1402
1403
  
  	/* Is there a control register that we can read from?  Some
  	 * ports don't allow reads, so read_control just returns a
  	 * software copy. Some ports _do_ allow reads, so bypass the
  	 * software copy here.  In addition, some bits aren't
  	 * writable. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1404
  	r = inb(CONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1405
1406
  	if ((r & 0xf) == w) {
  		w = 0xe;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1407
1408
1409
  		outb(w, CONTROL(pb));
  		r = inb(CONTROL(pb));
  		outb(0xc, CONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1410
1411
1412
1413
1414
1415
1416
  		if ((r & 0xf) == w)
  			return PARPORT_MODE_PCSPP;
  	}
  
  	if (user_specified)
  		/* That didn't work, but the user thinks there's a
  		 * port here. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1417
  		printk(KERN_INFO "parport 0x%lx (WARNING): CTR: "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1418
1419
1420
1421
1422
1423
  			"wrote 0x%02x, read 0x%02x
  ", pb->base, w, r);
  
  	/* Try the data register.  The data lines aren't tri-stated at
  	 * this stage, so we expect back what we wrote. */
  	w = 0xaa;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1424
1425
  	parport_pc_write_data(pb, w);
  	r = parport_pc_read_data(pb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1426
1427
  	if (r == w) {
  		w = 0x55;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1428
1429
  		parport_pc_write_data(pb, w);
  		r = parport_pc_read_data(pb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1430
1431
1432
1433
1434
1435
1436
  		if (r == w)
  			return PARPORT_MODE_PCSPP;
  	}
  
  	if (user_specified) {
  		/* Didn't work, but the user is convinced this is the
  		 * place. */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1437
  		printk(KERN_INFO "parport 0x%lx (WARNING): DATA: "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1438
1439
  			"wrote 0x%02x, read 0x%02x
  ", pb->base, w, r);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1440
  		printk(KERN_INFO "parport 0x%lx: You gave this address, "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
  			"but there is probably no parallel port there!
  ",
  			pb->base);
  	}
  
  	/* It's possible that we can't read the control register or
  	 * the data register.  In that case just believe the user. */
  	if (user_specified)
  		return PARPORT_MODE_PCSPP;
  
  	return 0;
  }
  
  /* Check for ECR
   *
   * Old style XT ports alias io ports every 0x400, hence accessing ECR
   * on these cards actually accesses the CTR.
   *
   * Modern cards don't do this but reading from ECR will return 0xff
   * regardless of what is written here if the card does NOT support
   * ECP.
   *
   * We first check to see if ECR is the same as CTR.  If not, the low
   * two bits of ECR aren't writable, so we check by writing ECR and
   * reading it back to see if it's what we expect.
   */
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1467
  static int parport_ECR_present(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1468
1469
1470
  {
  	struct parport_pc_private *priv = pb->private_data;
  	unsigned char r = 0xc;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1471
1472
1473
  	outb(r, CONTROL(pb));
  	if ((inb(ECONTROL(pb)) & 0x3) == (r & 0x3)) {
  		outb(r ^ 0x2, CONTROL(pb)); /* Toggle bit 1 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1474

3aeda9bc9   Alan Cox   parport_pc: Codin...
1475
1476
  		r = inb(CONTROL(pb));
  		if ((inb(ECONTROL(pb)) & 0x2) == (r & 0x2))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1477
1478
  			goto no_reg; /* Sure that no ECR register exists */
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
1479
1480
  
  	if ((inb(ECONTROL(pb)) & 0x3) != 0x1)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1481
  		goto no_reg;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1482
1483
  	ECR_WRITE(pb, 0x34);
  	if (inb(ECONTROL(pb)) != 0x35)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1484
1485
1486
  		goto no_reg;
  
  	priv->ecr = 1;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1487
  	outb(0xc, CONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1488
  	/* Go to mode 000 */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1489
  	frob_set_mode(pb, ECR_SPP);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1490
1491
1492
1493
  
  	return 1;
  
   no_reg:
3aeda9bc9   Alan Cox   parport_pc: Codin...
1494
1495
  	outb(0xc, CONTROL(pb));
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1496
1497
1498
1499
1500
1501
1502
1503
1504
  }
  
  #ifdef CONFIG_PARPORT_1284
  /* Detect PS/2 support.
   *
   * Bit 5 (0x20) sets the PS/2 data direction; setting this high
   * allows us to read data from the data lines.  In theory we would get back
   * 0xff but any peripheral attached to the port may drag some or all of the
   * lines down to zero.  So if we get back anything that isn't the contents
3aeda9bc9   Alan Cox   parport_pc: Codin...
1505
   * of the data register we deem PS/2 support to be present.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1506
1507
1508
1509
1510
1511
1512
   *
   * Some SPP ports have "half PS/2" ability - you can't turn off the line
   * drivers, but an external peripheral with sufficiently beefy drivers of
   * its own can overpower them and assert its own levels onto the bus, from
   * where they can then be read back as normal.  Ports with this property
   * and the right type of device attached are likely to fail the SPP test,
   * (as they will appear to have stuck bits) and so the fact that they might
3aeda9bc9   Alan Cox   parport_pc: Codin...
1513
   * be misdetected here is rather academic.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1514
   */
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1515
  static int parport_PS2_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1516
1517
  {
  	int ok = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1518

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1519
1520
1521
  	clear_epp_timeout(pb);
  
  	/* try to tri-state the buffer */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1522
  	parport_pc_data_reverse(pb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1523
  	parport_pc_write_data(pb, 0x55);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1524
1525
  	if (parport_pc_read_data(pb) != 0x55)
  		ok++;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1526
1527
  
  	parport_pc_write_data(pb, 0xaa);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1528
1529
  	if (parport_pc_read_data(pb) != 0xaa)
  		ok++;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1530
1531
  
  	/* cancel input mode */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1532
  	parport_pc_data_forward(pb);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
  
  	if (ok) {
  		pb->modes |= PARPORT_MODE_TRISTATE;
  	} else {
  		struct parport_pc_private *priv = pb->private_data;
  		priv->ctr_writable &= ~0x20;
  	}
  
  	return ok;
  }
  
  #ifdef CONFIG_PARPORT_PC_FIFO
55265b00a   David Brownell   parport: section ...
1545
  static int parport_ECP_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1546
1547
1548
1549
1550
  {
  	int i;
  	int config, configb;
  	int pword;
  	struct parport_pc_private *priv = pb->private_data;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1551
1552
  	/* Translate ECP intrLine to ISA irq value */
  	static const int intrline[] = { 0, 7, 9, 10, 11, 14, 15, 5 };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1553
1554
1555
1556
1557
1558
  
  	/* If there is no ECR, we have no hope of supporting ECP. */
  	if (!priv->ecr)
  		return 0;
  
  	/* Find out FIFO depth */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1559
1560
1561
1562
  	ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  	ECR_WRITE(pb, ECR_TST << 5); /* TEST FIFO */
  	for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02); i++)
  		outb(0xaa, FIFO(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1563
1564
1565
1566
1567
1568
  
  	/*
  	 * Using LGS chipset it uses ECR register, but
  	 * it doesn't support ECP or FIFO MODE
  	 */
  	if (i == 1024) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1569
  		ECR_WRITE(pb, ECR_SPP << 5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1570
1571
1572
1573
1574
  		return 0;
  	}
  
  	priv->fifo_depth = i;
  	if (verbose_probing)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1575
1576
  		printk(KERN_DEBUG "0x%lx: FIFO is %d bytes
  ", pb->base, i);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1577
1578
  
  	/* Find out writeIntrThreshold */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1579
1580
  	frob_econtrol(pb, 1<<2, 1<<2);
  	frob_econtrol(pb, 1<<2, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1581
  	for (i = 1; i <= priv->fifo_depth; i++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1582
1583
1584
  		inb(FIFO(pb));
  		udelay(50);
  		if (inb(ECONTROL(pb)) & (1<<2))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1585
1586
1587
1588
1589
  			break;
  	}
  
  	if (i <= priv->fifo_depth) {
  		if (verbose_probing)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1590
1591
  			printk(KERN_DEBUG "0x%lx: writeIntrThreshold is %d
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1592
1593
1594
  				pb->base, i);
  	} else
  		/* Number of bytes we know we can write if we get an
3aeda9bc9   Alan Cox   parport_pc: Codin...
1595
  		   interrupt. */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1596
1597
1598
1599
1600
  		i = 0;
  
  	priv->writeIntrThreshold = i;
  
  	/* Find out readIntrThreshold */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1601
1602
1603
1604
1605
  	frob_set_mode(pb, ECR_PS2); /* Reset FIFO and enable PS2 */
  	parport_pc_data_reverse(pb); /* Must be in PS2 mode */
  	frob_set_mode(pb, ECR_TST); /* Test FIFO */
  	frob_econtrol(pb, 1<<2, 1<<2);
  	frob_econtrol(pb, 1<<2, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1606
  	for (i = 1; i <= priv->fifo_depth; i++) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1607
1608
  		outb(0xaa, FIFO(pb));
  		if (inb(ECONTROL(pb)) & (1<<2))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1609
1610
1611
1612
1613
  			break;
  	}
  
  	if (i <= priv->fifo_depth) {
  		if (verbose_probing)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1614
1615
  			printk(KERN_INFO "0x%lx: readIntrThreshold is %d
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1616
1617
1618
1619
1620
1621
  				pb->base, i);
  	} else
  		/* Number of bytes we can read if we get an interrupt. */
  		i = 0;
  
  	priv->readIntrThreshold = i;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1622
1623
1624
  	ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  	ECR_WRITE(pb, 0xf4); /* Configuration mode */
  	config = inb(CONFIGA(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1625
1626
1627
1628
  	pword = (config >> 4) & 0x7;
  	switch (pword) {
  	case 0:
  		pword = 2;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1629
1630
  		printk(KERN_WARNING "0x%lx: Unsupported pword size!
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1631
1632
1633
1634
  			pb->base);
  		break;
  	case 2:
  		pword = 4;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1635
1636
  		printk(KERN_WARNING "0x%lx: Unsupported pword size!
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1637
1638
1639
  			pb->base);
  		break;
  	default:
3aeda9bc9   Alan Cox   parport_pc: Codin...
1640
1641
  		printk(KERN_WARNING "0x%lx: Unknown implementation ID
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1642
1643
1644
1645
1646
1647
1648
1649
  			pb->base);
  		/* Assume 1 */
  	case 1:
  		pword = 1;
  	}
  	priv->pword = pword;
  
  	if (verbose_probing) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1650
1651
1652
1653
1654
1655
  		printk(KERN_DEBUG "0x%lx: PWord is %d bits
  ",
  			pb->base, 8 * pword);
  
  		printk(KERN_DEBUG "0x%lx: Interrupts are ISA-%s
  ", pb->base,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1656
  			config & 0x80 ? "Level" : "Pulses");
3aeda9bc9   Alan Cox   parport_pc: Codin...
1657
1658
1659
  		configb = inb(CONFIGB(pb));
  		printk(KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1660
  			pb->base, config, configb);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1661
1662
1663
  		printk(KERN_DEBUG "0x%lx: ECP settings irq=", pb->base);
  		if ((configb >> 3) & 0x07)
  			printk("%d", intrline[(configb >> 3) & 0x07]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1664
1665
  		else
  			printk("<none or set by other means>");
3aeda9bc9   Alan Cox   parport_pc: Codin...
1666
1667
  		printk(" dma=");
  		if ((configb & 0x03) == 0x00)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1668
1669
1670
  			printk("<none or set by other means>
  ");
  		else
3aeda9bc9   Alan Cox   parport_pc: Codin...
1671
1672
  			printk("%d
  ", configb & 0x07);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1673
1674
1675
  	}
  
  	/* Go back to mode 000 */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1676
  	frob_set_mode(pb, ECR_SPP);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1677
1678
1679
1680
  
  	return 1;
  }
  #endif
0ae39cc98   Matwey V. Kornilov   parport: parport_...
1681
1682
  #ifdef CONFIG_X86_32
  static int intel_bug_present_check_epp(struct parport *pb)
17891c8a9   Matwey V. Kornilov   parport: parport_...
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
  {
  	const struct parport_pc_private *priv = pb->private_data;
  	int bug_present = 0;
  
  	if (priv->ecr) {
  		/* store value of ECR */
  		unsigned char ecr = inb(ECONTROL(pb));
  		unsigned char i;
  		for (i = 0x00; i < 0x80; i += 0x20) {
  			ECR_WRITE(pb, i);
  			if (clear_epp_timeout(pb)) {
  				/* Phony EPP in ECP. */
  				bug_present = 1;
  				break;
  			}
  		}
  		/* return ECR into the inital state */
  		ECR_WRITE(pb, ecr);
  	}
  
  	return bug_present;
  }
0ae39cc98   Matwey V. Kornilov   parport: parport_...
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
  static int intel_bug_present(struct parport *pb)
  {
  /* Check whether the device is legacy, not PCI or PCMCIA. Only legacy is known to be affected. */
  	if (pb->dev != NULL) {
  		return 0;
  	}
  
  	return intel_bug_present_check_epp(pb);
  }
  #else
  static int intel_bug_present(struct parport *pb)
  {
  	return 0;
  }
  #endif /* CONFIG_X86_32 */
17891c8a9   Matwey V. Kornilov   parport: parport_...
1720

96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1721
  static int parport_ECPPS2_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1722
1723
1724
1725
1726
1727
1728
  {
  	const struct parport_pc_private *priv = pb->private_data;
  	int result;
  	unsigned char oecr;
  
  	if (!priv->ecr)
  		return 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1729
1730
  	oecr = inb(ECONTROL(pb));
  	ECR_WRITE(pb, ECR_PS2 << 5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1731
  	result = parport_PS2_supported(pb);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1732
  	ECR_WRITE(pb, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1733
1734
1735
1736
  	return result;
  }
  
  /* EPP mode detection  */
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1737
  static int parport_EPP_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1738
  {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
  	/*
  	 * Theory:
  	 *	Bit 0 of STR is the EPP timeout bit, this bit is 0
  	 *	when EPP is possible and is set high when an EPP timeout
  	 *	occurs (EPP uses the HALT line to stop the CPU while it does
  	 *	the byte transfer, an EPP timeout occurs if the attached
  	 *	device fails to respond after 10 micro seconds).
  	 *
  	 *	This bit is cleared by either reading it (National Semi)
  	 *	or writing a 1 to the bit (SMC, UMC, WinBond), others ???
  	 *	This bit is always high in non EPP modes.
  	 */
  
  	/* If EPP timeout bit clear then EPP available */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1753
  	if (!clear_epp_timeout(pb))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1754
  		return 0;  /* No way to clear timeout */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1755
1756
  
  	/* Check for Intel bug. */
17891c8a9   Matwey V. Kornilov   parport: parport_...
1757
1758
  	if (intel_bug_present(pb))
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
  
  	pb->modes |= PARPORT_MODE_EPP;
  
  	/* Set up access functions to use EPP hardware. */
  	pb->ops->epp_read_data = parport_pc_epp_read_data;
  	pb->ops->epp_write_data = parport_pc_epp_write_data;
  	pb->ops->epp_read_addr = parport_pc_epp_read_addr;
  	pb->ops->epp_write_addr = parport_pc_epp_write_addr;
  
  	return 1;
  }
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1770
  static int parport_ECPEPP_supported(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1771
1772
1773
1774
  {
  	struct parport_pc_private *priv = pb->private_data;
  	int result;
  	unsigned char oecr;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1775
  	if (!priv->ecr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1776
  		return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1777

3aeda9bc9   Alan Cox   parport_pc: Codin...
1778
  	oecr = inb(ECONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1779
  	/* Search for SMC style EPP+ECP mode */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1780
1781
  	ECR_WRITE(pb, 0x80);
  	outb(0x04, CONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1782
  	result = parport_EPP_supported(pb);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1783
  	ECR_WRITE(pb, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
  
  	if (result) {
  		/* Set up access functions to use ECP+EPP hardware. */
  		pb->ops->epp_read_data = parport_pc_ecpepp_read_data;
  		pb->ops->epp_write_data = parport_pc_ecpepp_write_data;
  		pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr;
  		pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr;
  	}
  
  	return result;
  }
  
  #else /* No IEEE 1284 support */
  
  /* Don't bother probing for modes we know we won't use. */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1799
  static int parport_PS2_supported(struct parport *pb) { return 0; }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1800
  #ifdef CONFIG_PARPORT_PC_FIFO
3aeda9bc9   Alan Cox   parport_pc: Codin...
1801
1802
1803
1804
  static int parport_ECP_supported(struct parport *pb)
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1805
  #endif
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1806
  static int parport_EPP_supported(struct parport *pb)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1807
1808
1809
  {
  	return 0;
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1810
  static int parport_ECPEPP_supported(struct parport *pb)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1811
1812
1813
  {
  	return 0;
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
1814
  static int parport_ECPPS2_supported(struct parport *pb)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1815
1816
1817
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1818
1819
1820
1821
1822
1823
  
  #endif /* No IEEE 1284 support */
  
  /* --- IRQ detection -------------------------------------- */
  
  /* Only if supports ECP mode */
4438982f5   Randy Dunlap   [PATCH] parport: ...
1824
  static int programmable_irq_support(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1825
1826
  {
  	int irq, intrLine;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1827
  	unsigned char oecr = inb(ECONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1828
1829
1830
  	static const int lookup[8] = {
  		PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5
  	};
3aeda9bc9   Alan Cox   parport_pc: Codin...
1831
  	ECR_WRITE(pb, ECR_CNF << 5); /* Configuration MODE */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1832

3aeda9bc9   Alan Cox   parport_pc: Codin...
1833
  	intrLine = (inb(CONFIGB(pb)) >> 3) & 0x07;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1834
  	irq = lookup[intrLine];
3aeda9bc9   Alan Cox   parport_pc: Codin...
1835
  	ECR_WRITE(pb, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1836
1837
  	return irq;
  }
4438982f5   Randy Dunlap   [PATCH] parport: ...
1838
  static int irq_probe_ECP(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1839
1840
1841
1842
1843
  {
  	int i;
  	unsigned long irqs;
  
  	irqs = probe_irq_on();
3aeda9bc9   Alan Cox   parport_pc: Codin...
1844
1845
1846
1847
  
  	ECR_WRITE(pb, ECR_SPP << 5); /* Reset FIFO */
  	ECR_WRITE(pb, (ECR_TST << 5) | 0x04);
  	ECR_WRITE(pb, ECR_TST << 5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1848
1849
  
  	/* If Full FIFO sure that writeIntrThreshold is generated */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1850
1851
  	for (i = 0; i < 1024 && !(inb(ECONTROL(pb)) & 0x02) ; i++)
  		outb(0xaa, FIFO(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1852
  	pb->irq = probe_irq_off(irqs);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1853
  	ECR_WRITE(pb, ECR_SPP << 5);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1854
1855
1856
1857
1858
1859
1860
1861
1862
  
  	if (pb->irq <= 0)
  		pb->irq = PARPORT_IRQ_NONE;
  
  	return pb->irq;
  }
  
  /*
   * This detection seems that only works in National Semiconductors
3aeda9bc9   Alan Cox   parport_pc: Codin...
1863
   * This doesn't work in SMC, LGS, and Winbond
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1864
   */
4438982f5   Randy Dunlap   [PATCH] parport: ...
1865
  static int irq_probe_EPP(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1866
1867
1868
1869
1870
1871
1872
1873
  {
  #ifndef ADVANCED_DETECT
  	return PARPORT_IRQ_NONE;
  #else
  	int irqs;
  	unsigned char oecr;
  
  	if (pb->modes & PARPORT_MODE_PCECR)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1874
  		oecr = inb(ECONTROL(pb));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1875
1876
1877
1878
  
  	irqs = probe_irq_on();
  
  	if (pb->modes & PARPORT_MODE_PCECR)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1879
  		frob_econtrol(pb, 0x10, 0x10);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1880
  	clear_epp_timeout(pb);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1881
1882
  	parport_pc_frob_control(pb, 0x20, 0x20);
  	parport_pc_frob_control(pb, 0x10, 0x10);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1883
1884
1885
1886
1887
1888
1889
  	clear_epp_timeout(pb);
  
  	/* Device isn't expecting an EPP read
  	 * and generates an IRQ.
  	 */
  	parport_pc_read_epp(pb);
  	udelay(20);
3aeda9bc9   Alan Cox   parport_pc: Codin...
1890
  	pb->irq = probe_irq_off(irqs);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1891
  	if (pb->modes & PARPORT_MODE_PCECR)
3aeda9bc9   Alan Cox   parport_pc: Codin...
1892
  		ECR_WRITE(pb, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1893
1894
1895
1896
1897
1898
1899
1900
  	parport_pc_write_control(pb, 0xc);
  
  	if (pb->irq <= 0)
  		pb->irq = PARPORT_IRQ_NONE;
  
  	return pb->irq;
  #endif /* Advanced detection */
  }
4438982f5   Randy Dunlap   [PATCH] parport: ...
1901
  static int irq_probe_SPP(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
  {
  	/* Don't even try to do this. */
  	return PARPORT_IRQ_NONE;
  }
  
  /* We will attempt to share interrupt requests since other devices
   * such as sound cards and network cards seem to like using the
   * printer IRQs.
   *
   * When ECP is available we can autoprobe for IRQs.
   * NOTE: If we can autoprobe it, we can register the IRQ.
   */
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
1914
  static int parport_irq_probe(struct parport *pb)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
  {
  	struct parport_pc_private *priv = pb->private_data;
  
  	if (priv->ecr) {
  		pb->irq = programmable_irq_support(pb);
  
  		if (pb->irq == PARPORT_IRQ_NONE)
  			pb->irq = irq_probe_ECP(pb);
  	}
  
  	if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr &&
  	    (pb->modes & PARPORT_MODE_EPP))
  		pb->irq = irq_probe_EPP(pb);
  
  	clear_epp_timeout(pb);
  
  	if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP))
  		pb->irq = irq_probe_EPP(pb);
  
  	clear_epp_timeout(pb);
  
  	if (pb->irq == PARPORT_IRQ_NONE)
  		pb->irq = irq_probe_SPP(pb);
  
  	if (pb->irq == PARPORT_IRQ_NONE)
  		pb->irq = get_superio_irq(pb);
  
  	return pb->irq;
  }
  
  /* --- DMA detection -------------------------------------- */
  
  /* Only if chipset conforms to ECP ISA Interface Standard */
3aeda9bc9   Alan Cox   parport_pc: Codin...
1948
  static int programmable_dma_support(struct parport *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1949
  {
3aeda9bc9   Alan Cox   parport_pc: Codin...
1950
  	unsigned char oecr = inb(ECONTROL(p));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1951
  	int dma;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1952
1953
1954
  	frob_set_mode(p, ECR_CNF);
  
  	dma = inb(CONFIGB(p)) & 0x07;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1955
1956
1957
1958
  	/* 000: Indicates jumpered 8-bit DMA if read-only.
  	   100: Indicates jumpered 16-bit DMA if read-only. */
  	if ((dma & 0x03) == 0)
  		dma = PARPORT_DMA_NONE;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1959
  	ECR_WRITE(p, oecr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1960
1961
  	return dma;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
1962
  static int parport_dma_probe(struct parport *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1963
1964
  {
  	const struct parport_pc_private *priv = p->private_data;
3aeda9bc9   Alan Cox   parport_pc: Codin...
1965
1966
  	if (priv->ecr)		/* ask ECP chipset first */
  		p->dma = programmable_dma_support(p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
  	if (p->dma == PARPORT_DMA_NONE) {
  		/* ask known Super-IO chips proper, although these
  		   claim ECP compatible, some don't report their DMA
  		   conforming to ECP standards */
  		p->dma = get_superio_dma(p);
  	}
  
  	return p->dma;
  }
  
  /* --- Initialisation code -------------------------------- */
  
  static LIST_HEAD(ports_list);
  static DEFINE_SPINLOCK(ports_lock);
51dcdfec6   Alan Cox   parport: Use the ...
1981
1982
1983
1984
1985
  struct parport *parport_pc_probe_port(unsigned long int base,
  				      unsigned long int base_hi,
  				      int irq, int dma,
  				      struct device *dev,
  				      int irqflags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1986
1987
1988
1989
1990
1991
1992
1993
  {
  	struct parport_pc_private *priv;
  	struct parport_operations *ops;
  	struct parport *p;
  	int probedirq = PARPORT_IRQ_NONE;
  	struct resource *base_res;
  	struct resource	*ECR_res = NULL;
  	struct resource	*EPP_res = NULL;
a7d801afc   Jean Delvare   legacy PC parport...
1994
  	struct platform_device *pdev = NULL;
93b11b258   Russell King   DMA-API: parport:...
1995
  	int ret;
a7d801afc   Jean Delvare   legacy PC parport...
1996
1997
1998
1999
2000
2001
2002
2003
2004
  
  	if (!dev) {
  		/* We need a physical device to attach to, but none was
  		 * provided. Create our own. */
  		pdev = platform_device_register_simple("parport_pc",
  						       base, NULL, 0);
  		if (IS_ERR(pdev))
  			return NULL;
  		dev = &pdev->dev;
dfa7c4d86   FUJITA Tomonori   parport_pc: set p...
2005

93b11b258   Russell King   DMA-API: parport:...
2006
2007
2008
2009
2010
2011
  		ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(24));
  		if (ret) {
  			dev_err(dev, "Unable to set coherent dma mask: disabling DMA
  ");
  			dma = PARPORT_DMA_NONE;
  		}
a7d801afc   Jean Delvare   legacy PC parport...
2012
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2013

51dcdfec6   Alan Cox   parport: Use the ...
2014
  	ops = kmalloc(sizeof(struct parport_operations), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2015
2016
  	if (!ops)
  		goto out1;
51dcdfec6   Alan Cox   parport: Use the ...
2017
  	priv = kmalloc(sizeof(struct parport_pc_private), GFP_KERNEL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
  	if (!priv)
  		goto out2;
  
  	/* a misnomer, actually - it's allocate and reserve parport number */
  	p = parport_register_port(base, irq, dma, ops);
  	if (!p)
  		goto out3;
  
  	base_res = request_region(base, 3, p->name);
  	if (!base_res)
  		goto out4;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2029
  	memcpy(ops, &parport_pc_ops, sizeof(struct parport_operations));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2030
2031
2032
2033
2034
2035
  	priv->ctr = 0xc;
  	priv->ctr_writable = ~0x10;
  	priv->ecr = 0;
  	priv->fifo_depth = 0;
  	priv->dma_buf = NULL;
  	priv->dma_handle = 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2036
2037
  	INIT_LIST_HEAD(&priv->list);
  	priv->port = p;
c15a3837d   David Brownell   parport->dev driv...
2038
2039
  
  	p->dev = dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
  	p->base_hi = base_hi;
  	p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
  	p->private_data = priv;
  
  	if (base_hi) {
  		ECR_res = request_region(base_hi, 3, p->name);
  		if (ECR_res)
  			parport_ECR_present(p);
  	}
  
  	if (base != 0x3bc) {
  		EPP_res = request_region(base+0x3, 5, p->name);
  		if (EPP_res)
  			if (!parport_EPP_supported(p))
  				parport_ECPEPP_supported(p);
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2056
  	if (!parport_SPP_supported(p))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2057
2058
2059
2060
2061
2062
  		/* No port. */
  		goto out5;
  	if (priv->ecr)
  		parport_ECPPS2_supported(p);
  	else
  		parport_PS2_supported(p);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2063
  	p->size = (p->modes & PARPORT_MODE_EPP) ? 8 : 3;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2064
2065
2066
  
  	printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
  	if (p->base_hi && priv->ecr)
2c03ead66   Kay Sievers   parport: use KERN...
2067
  		printk(KERN_CONT " (0x%lx)", p->base_hi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
  	if (p->irq == PARPORT_IRQ_AUTO) {
  		p->irq = PARPORT_IRQ_NONE;
  		parport_irq_probe(p);
  	} else if (p->irq == PARPORT_IRQ_PROBEONLY) {
  		p->irq = PARPORT_IRQ_NONE;
  		parport_irq_probe(p);
  		probedirq = p->irq;
  		p->irq = PARPORT_IRQ_NONE;
  	}
  	if (p->irq != PARPORT_IRQ_NONE) {
2c03ead66   Kay Sievers   parport: use KERN...
2078
  		printk(KERN_CONT ", irq %d", p->irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2079
2080
2081
2082
2083
2084
2085
2086
  		priv->ctr_writable |= 0x10;
  
  		if (p->dma == PARPORT_DMA_AUTO) {
  			p->dma = PARPORT_DMA_NONE;
  			parport_dma_probe(p);
  		}
  	}
  	if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
3aeda9bc9   Alan Cox   parport_pc: Codin...
2087
  					   is mandatory (see above) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
  		p->dma = PARPORT_DMA_NONE;
  
  #ifdef CONFIG_PARPORT_PC_FIFO
  	if (parport_ECP_supported(p) &&
  	    p->dma != PARPORT_DMA_NOFIFO &&
  	    priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) {
  		p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
  		p->ops->compat_write_data = parport_pc_compat_write_block_pio;
  #ifdef CONFIG_PARPORT_1284
  		p->ops->ecp_write_data = parport_pc_ecp_write_block_pio;
  		/* currently broken, but working on it.. (FB) */
  		/* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */
  #endif /* IEEE 1284 support */
  		if (p->dma != PARPORT_DMA_NONE) {
2c03ead66   Kay Sievers   parport: use KERN...
2102
  			printk(KERN_CONT ", dma %d", p->dma);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2103
  			p->modes |= PARPORT_MODE_DMA;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2104
  		} else
2c03ead66   Kay Sievers   parport: use KERN...
2105
  			printk(KERN_CONT ", using FIFO");
3aeda9bc9   Alan Cox   parport_pc: Codin...
2106
  	} else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2107
2108
2109
  		/* We can't use the DMA channel after all. */
  		p->dma = PARPORT_DMA_NONE;
  #endif /* Allowed to use FIFO/DMA */
2c03ead66   Kay Sievers   parport: use KERN...
2110
  	printk(KERN_CONT " [");
3aeda9bc9   Alan Cox   parport_pc: Codin...
2111
2112
2113
2114
  
  #define printmode(x) \
  	{\
  		if (p->modes & PARPORT_MODE_##x) {\
2c03ead66   Kay Sievers   parport: use KERN...
2115
  			printk(KERN_CONT "%s%s", f ? "," : "", #x);\
3aeda9bc9   Alan Cox   parport_pc: Codin...
2116
2117
2118
  			f++;\
  		} \
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
  	{
  		int f = 0;
  		printmode(PCSPP);
  		printmode(TRISTATE);
  		printmode(COMPAT)
  		printmode(EPP);
  		printmode(ECP);
  		printmode(DMA);
  	}
  #undef printmode
  #ifndef CONFIG_PARPORT_1284
2c03ead66   Kay Sievers   parport: use KERN...
2130
  	printk(KERN_CONT "(,...)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2131
  #endif /* CONFIG_PARPORT_1284 */
2c03ead66   Kay Sievers   parport: use KERN...
2132
2133
  	printk(KERN_CONT "]
  ");
3aeda9bc9   Alan Cox   parport_pc: Codin...
2134
  	if (probedirq != PARPORT_IRQ_NONE)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
  		printk(KERN_INFO "%s: irq %d detected
  ", p->name, probedirq);
  
  	/* If No ECP release the ports grabbed above. */
  	if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) {
  		release_region(base_hi, 3);
  		ECR_res = NULL;
  	}
  	/* Likewise for EEP ports */
  	if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) {
  		release_region(base+3, 5);
  		EPP_res = NULL;
  	}
  	if (p->irq != PARPORT_IRQ_NONE) {
51dcdfec6   Alan Cox   parport: Use the ...
2149
2150
  		if (request_irq(p->irq, parport_irq_handler,
  				 irqflags, p->name, p)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2151
  			printk(KERN_WARNING "%s: irq %d in use, "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2152
2153
2154
2155
2156
2157
2158
2159
  				"resorting to polled operation
  ",
  				p->name, p->irq);
  			p->irq = PARPORT_IRQ_NONE;
  			p->dma = PARPORT_DMA_NONE;
  		}
  
  #ifdef CONFIG_PARPORT_PC_FIFO
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
2160
  #ifdef HAS_DMA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2161
  		if (p->dma != PARPORT_DMA_NONE) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2162
2163
  			if (request_dma(p->dma, p->name)) {
  				printk(KERN_WARNING "%s: dma %d in use, "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2164
2165
2166
2167
2168
2169
  					"resorting to PIO operation
  ",
  					p->name, p->dma);
  				p->dma = PARPORT_DMA_NONE;
  			} else {
  				priv->dma_buf =
c15a3837d   David Brownell   parport->dev driv...
2170
  				  dma_alloc_coherent(dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2171
  						       PAGE_SIZE,
c15a3837d   David Brownell   parport->dev driv...
2172
2173
  						       &priv->dma_handle,
  						       GFP_KERNEL);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2174
2175
  				if (!priv->dma_buf) {
  					printk(KERN_WARNING "%s: "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2176
2177
2178
2179
2180
2181
2182
2183
2184
  						"cannot get buffer for DMA, "
  						"resorting to PIO operation
  ",
  						p->name);
  					free_dma(p->dma);
  					p->dma = PARPORT_DMA_NONE;
  				}
  			}
  		}
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
2185
2186
  #endif
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2187
2188
2189
2190
2191
2192
2193
2194
  	}
  
  	/* Done probing.  Now put the port into a sensible start-up state. */
  	if (priv->ecr)
  		/*
  		 * Put the ECP detected port in PS2 mode.
  		 * Do this also for ports that have ECR but don't do ECP.
  		 */
3aeda9bc9   Alan Cox   parport_pc: Codin...
2195
  		ECR_WRITE(p, 0x34);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2196
2197
  
  	parport_pc_write_data(p, 0);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2198
  	parport_pc_data_forward(p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2199
2200
2201
2202
2203
2204
2205
  
  	/* Now that we've told the sharing engine about the port, and
  	   found out its characteristics, let the high-level drivers
  	   know about it. */
  	spin_lock(&ports_lock);
  	list_add(&priv->list, &ports_list);
  	spin_unlock(&ports_lock);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2206
  	parport_announce_port(p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
  
  	return p;
  
  out5:
  	if (ECR_res)
  		release_region(base_hi, 3);
  	if (EPP_res)
  		release_region(base+0x3, 5);
  	release_region(base, 3);
  out4:
6fa45a226   Sudip Mukherjee   parport: add devi...
2217
  	parport_del_port(p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2218
  out3:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2219
  	kfree(priv);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2220
  out2:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2221
  	kfree(ops);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2222
  out1:
a7d801afc   Jean Delvare   legacy PC parport...
2223
2224
  	if (pdev)
  		platform_device_unregister(pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2225
2226
  	return NULL;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
2227
  EXPORT_SYMBOL(parport_pc_probe_port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2228

3aeda9bc9   Alan Cox   parport_pc: Codin...
2229
  void parport_pc_unregister_port(struct parport *p)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2230
2231
2232
2233
2234
2235
2236
2237
  {
  	struct parport_pc_private *priv = p->private_data;
  	struct parport_operations *ops = p->ops;
  
  	parport_remove_port(p);
  	spin_lock(&ports_lock);
  	list_del_init(&priv->list);
  	spin_unlock(&ports_lock);
d1c4ac408   Andrew Morton   [PATCH] parport_p...
2238
  #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2239
2240
  	if (p->dma != PARPORT_DMA_NONE)
  		free_dma(p->dma);
d1c4ac408   Andrew Morton   [PATCH] parport_p...
2241
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2242
2243
2244
2245
2246
2247
2248
  	if (p->irq != PARPORT_IRQ_NONE)
  		free_irq(p->irq, p);
  	release_region(p->base, 3);
  	if (p->size > 3)
  		release_region(p->base + 3, p->size - 3);
  	if (p->modes & PARPORT_MODE_ECP)
  		release_region(p->base_hi, 3);
d1c4ac408   Andrew Morton   [PATCH] parport_p...
2249
  #if defined(CONFIG_PARPORT_PC_FIFO) && defined(HAS_DMA)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2250
  	if (priv->dma_buf)
c15a3837d   David Brownell   parport->dev driv...
2251
  		dma_free_coherent(p->physport->dev, PAGE_SIZE,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2252
2253
  				    priv->dma_buf,
  				    priv->dma_handle);
7fbacd521   Al Viro   [PATCH] ISA_DMA K...
2254
  #endif
3aeda9bc9   Alan Cox   parport_pc: Codin...
2255
  	kfree(p->private_data);
6fa45a226   Sudip Mukherjee   parport: add devi...
2256
  	parport_del_port(p);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2257
  	kfree(ops); /* hope no-one cached it */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2258
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
2259
  EXPORT_SYMBOL(parport_pc_unregister_port);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2260
2261
2262
2263
  
  #ifdef CONFIG_PCI
  
  /* ITE support maintained by Rich Liu <richliu@poorman.org> */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2264
2265
  static int sio_ite_8872_probe(struct pci_dev *pdev, int autoirq, int autodma,
  			      const struct parport_pc_via_data *via)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2266
2267
  {
  	short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2268
2269
2270
  	u32 ite8872set;
  	u32 ite8872_lpt, ite8872_lpthi;
  	u8 ite8872_irq, type;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2271
2272
  	int irq;
  	int i;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2273
2274
2275
2276
2277
  	DPRINTK(KERN_DEBUG "sio_ite_8872_probe()
  ");
  
  	/* make sure which one chip */
  	for (i = 0; i < 5; i++) {
0f6db2172   Niels de Vos   parport_pc.c: cor...
2278
  		if (request_region(inta_addr[i], 32, "it887x")) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2279
  			int test;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2280
  			pci_write_config_dword(pdev, 0x60,
e7c310c36   Niels de Vos   parport_pc: it887...
2281
  						0xe5000000 | inta_addr[i]);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2282
  			pci_write_config_dword(pdev, 0x78,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2283
  						0x00000000 | inta_addr[i]);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2284
2285
2286
  			test = inb(inta_addr[i]);
  			if (test != 0xff)
  				break;
0f6db2172   Niels de Vos   parport_pc.c: cor...
2287
  			release_region(inta_addr[i], 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2288
2289
  		}
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2290
2291
2292
  	if (i >= 5) {
  		printk(KERN_INFO "parport_pc: cannot find ITE8872 INTA
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2293
2294
  		return 0;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2295
  	type = inb(inta_addr[i] + 0x18);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2296
2297
2298
2299
  	type &= 0x0f;
  
  	switch (type) {
  	case 0x2:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2300
2301
  		printk(KERN_INFO "parport_pc: ITE8871 found (1P)
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2302
2303
2304
  		ite8872set = 0x64200000;
  		break;
  	case 0xa:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2305
2306
  		printk(KERN_INFO "parport_pc: ITE8875 found (1P)
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2307
2308
2309
  		ite8872set = 0x64200000;
  		break;
  	case 0xe:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2310
2311
  		printk(KERN_INFO "parport_pc: ITE8872 found (2S1P)
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2312
2313
2314
  		ite8872set = 0x64e00000;
  		break;
  	case 0x6:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2315
2316
  		printk(KERN_INFO "parport_pc: ITE8873 found (1S)
  ");
9fdbdd062   Jiri Kosina   parport_pc: relea...
2317
  		release_region(inta_addr[i], 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2318
2319
  		return 0;
  	case 0x8:
6c8e4c92b   Niels de Vos   parport_pc: show ...
2320
2321
  		printk(KERN_INFO "parport_pc: ITE8874 found (2S)
  ");
9fdbdd062   Jiri Kosina   parport_pc: relea...
2322
  		release_region(inta_addr[i], 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2323
2324
  		return 0;
  	default:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2325
2326
2327
  		printk(KERN_INFO "parport_pc: unknown ITE887x
  ");
  		printk(KERN_INFO "parport_pc: please mail 'lspci -nvv' "
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2328
2329
  			"output to Rich.Liu@ite.com.tw
  ");
9fdbdd062   Jiri Kosina   parport_pc: relea...
2330
  		release_region(inta_addr[i], 32);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2331
2332
  		return 0;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2333
2334
  	pci_read_config_byte(pdev, 0x3c, &ite8872_irq);
  	pci_read_config_dword(pdev, 0x1c, &ite8872_lpt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2335
  	ite8872_lpt &= 0x0000ff00;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2336
  	pci_read_config_dword(pdev, 0x20, &ite8872_lpthi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2337
  	ite8872_lpthi &= 0x0000ff00;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2338
2339
2340
2341
2342
2343
  	pci_write_config_dword(pdev, 0x6c, 0xe3000000 | ite8872_lpt);
  	pci_write_config_dword(pdev, 0x70, 0xe3000000 | ite8872_lpthi);
  	pci_write_config_dword(pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt);
  	/* SET SPP&EPP , Parallel Port NO DMA , Enable All Function */
  	/* SET Parallel IRQ */
  	pci_write_config_dword(pdev, 0x9c,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2344
  				ite8872set | (ite8872_irq * 0x11111));
3aeda9bc9   Alan Cox   parport_pc: Codin...
2345
2346
2347
2348
  	DPRINTK(KERN_DEBUG "ITE887x: The IRQ is %d.
  ", ite8872_irq);
  	DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2349
  		 ite8872_lpt);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2350
2351
  	DPRINTK(KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.
  ",
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
  		 ite8872_lpthi);
  
  	/* Let the user (or defaults) steer us away from interrupts */
  	irq = ite8872_irq;
  	if (autoirq != PARPORT_IRQ_AUTO)
  		irq = PARPORT_IRQ_NONE;
  
  	/*
  	 * Release the resource so that parport_pc_probe_port can get it.
  	 */
0f6db2172   Niels de Vos   parport_pc.c: cor...
2362
  	release_region(inta_addr[i], 32);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2363
  	if (parport_pc_probe_port(ite8872_lpt, ite8872_lpthi,
51dcdfec6   Alan Cox   parport: Use the ...
2364
  				   irq, PARPORT_DMA_NONE, &pdev->dev, 0)) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2365
  		printk(KERN_INFO
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2366
  			"parport_pc: ITE 8872 parallel port: io=0x%X",
3aeda9bc9   Alan Cox   parport_pc: Codin...
2367
  								ite8872_lpt);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2368
  		if (irq != PARPORT_IRQ_NONE)
3aeda9bc9   Alan Cox   parport_pc: Codin...
2369
2370
2371
  			printk(", irq=%d", irq);
  		printk("
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2372
2373
2374
2375
2376
2377
2378
2379
  		return 1;
  	}
  
  	return 0;
  }
  
  /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru>
     based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2380
  static int parport_init_mode;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2381
2382
  
  /* Data for two known VIA chips */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2383
  static struct parport_pc_via_data via_686a_data = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2384
2385
2386
2387
2388
2389
2390
2391
  	0x51,
  	0x50,
  	0x85,
  	0x02,
  	0xE2,
  	0xF0,
  	0xE6
  };
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2392
  static struct parport_pc_via_data via_8231_data = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2393
2394
2395
2396
2397
2398
2399
2400
  	0x45,
  	0x44,
  	0x50,
  	0x04,
  	0xF2,
  	0xFA,
  	0xF6
  };
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2401
2402
  static int sio_via_probe(struct pci_dev *pdev, int autoirq, int autodma,
  			 const struct parport_pc_via_data *via)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2403
2404
2405
2406
2407
2408
2409
2410
2411
  {
  	u8 tmp, tmp2, siofunc;
  	u8 ppcontrol = 0;
  	int dma, irq;
  	unsigned port1, port2;
  	unsigned have_epp = 0;
  
  	printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected
  ");
3aeda9bc9   Alan Cox   parport_pc: Codin...
2412
  	switch (parport_init_mode) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2413
  	case 1:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2414
2415
2416
2417
  		printk(KERN_DEBUG "parport_pc: setting SPP mode
  ");
  		siofunc = VIA_FUNCTION_PARPORT_SPP;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2418
  	case 2:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2419
2420
2421
2422
2423
  		printk(KERN_DEBUG "parport_pc: setting PS/2 mode
  ");
  		siofunc = VIA_FUNCTION_PARPORT_SPP;
  		ppcontrol = VIA_PARPORT_BIDIR;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2424
  	case 3:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2425
2426
2427
2428
2429
2430
  		printk(KERN_DEBUG "parport_pc: setting EPP mode
  ");
  		siofunc = VIA_FUNCTION_PARPORT_EPP;
  		ppcontrol = VIA_PARPORT_BIDIR;
  		have_epp = 1;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2431
  	case 4:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2432
2433
2434
2435
2436
  		printk(KERN_DEBUG "parport_pc: setting ECP mode
  ");
  		siofunc = VIA_FUNCTION_PARPORT_ECP;
  		ppcontrol = VIA_PARPORT_BIDIR;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2437
  	case 5:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
  		printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode
  ");
  		siofunc = VIA_FUNCTION_PARPORT_ECP;
  		ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP;
  		have_epp = 1;
  		break;
  	default:
  		printk(KERN_DEBUG
  			"parport_pc: probing current configuration
  ");
  		siofunc = VIA_FUNCTION_PROBE;
  		break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
  	}
  	/*
  	 * unlock super i/o configuration
  	 */
  	pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
  	tmp |= via->via_pci_superio_config_data;
  	pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
  
  	/* Bits 1-0: Parallel Port Mode / Enable */
  	outb(via->viacfg_function, VIA_CONFIG_INDEX);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2460
  	tmp = inb(VIA_CONFIG_DATA);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2461
2462
  	/* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */
  	outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
  	tmp2 = inb(VIA_CONFIG_DATA);
  	if (siofunc == VIA_FUNCTION_PROBE) {
  		siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE;
  		ppcontrol = tmp2;
  	} else {
  		tmp &= ~VIA_FUNCTION_PARPORT_DISABLE;
  		tmp |= siofunc;
  		outb(via->viacfg_function, VIA_CONFIG_INDEX);
  		outb(tmp, VIA_CONFIG_DATA);
  		tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP);
  		tmp2 |= ppcontrol;
  		outb(via->viacfg_parport_control, VIA_CONFIG_INDEX);
  		outb(tmp2, VIA_CONFIG_DATA);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2476
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2477

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2478
2479
2480
  	/* Parallel Port I/O Base Address, bits 9-2 */
  	outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
  	port1 = inb(VIA_CONFIG_DATA) << 2;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
  
  	printk(KERN_DEBUG "parport_pc: Current parallel port base: 0x%X
  ",
  									port1);
  	if (port1 == 0x3BC && have_epp) {
  		outb(via->viacfg_parport_base, VIA_CONFIG_INDEX);
  		outb((0x378 >> 2), VIA_CONFIG_DATA);
  		printk(KERN_DEBUG
  			"parport_pc: Parallel port base changed to 0x378
  ");
  		port1 = 0x378;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
  	}
  
  	/*
  	 * lock super i/o configuration
  	 */
  	pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp);
  	tmp &= ~via->via_pci_superio_config_data;
  	pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp);
  
  	if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) {
  		printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS
  ");
  		return 0;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2506

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2507
2508
2509
  	/* Bits 7-4: PnP Routing for Parallel Port IRQ */
  	pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp);
  	irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2510
2511
2512
2513
2514
2515
2516
2517
  	if (siofunc == VIA_FUNCTION_PARPORT_ECP) {
  		/* Bits 3-2: PnP Routing for Parallel Port DMA */
  		pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp);
  		dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2);
  	} else
  		/* if ECP not enabled, DMA is not enabled, assumed
  		   bogus 'dma' value */
  		dma = PARPORT_DMA_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2518
2519
2520
  
  	/* Let the user (or defaults) steer us away from interrupts and DMA */
  	if (autoirq == PARPORT_IRQ_NONE) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2521
2522
  		irq = PARPORT_IRQ_NONE;
  		dma = PARPORT_DMA_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2523
2524
  	}
  	if (autodma == PARPORT_DMA_NONE)
3aeda9bc9   Alan Cox   parport_pc: Codin...
2525
  		dma = PARPORT_DMA_NONE;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2526
2527
  
  	switch (port1) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2528
2529
2530
2531
2532
2533
  	case 0x3bc:
  		port2 = 0x7bc; break;
  	case 0x378:
  		port2 = 0x778; break;
  	case 0x278:
  		port2 = 0x678; break;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2534
  	default:
3aeda9bc9   Alan Cox   parport_pc: Codin...
2535
2536
2537
2538
  		printk(KERN_INFO
  			"parport_pc: Weird VIA parport base 0x%X, ignoring
  ",
  									port1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
  		return 0;
  	}
  
  	/* filter bogus IRQs */
  	switch (irq) {
  	case 0:
  	case 2:
  	case 8:
  	case 13:
  		irq = PARPORT_IRQ_NONE;
  		break;
  
  	default: /* do nothing */
  		break;
  	}
  
  	/* finally, do the probe with values obtained */
3aeda9bc9   Alan Cox   parport_pc: Codin...
2556
2557
  	if (parport_pc_probe_port(port1, port2, irq, dma, &pdev->dev, 0)) {
  		printk(KERN_INFO
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2558
2559
  			"parport_pc: VIA parallel port: io=0x%X", port1);
  		if (irq != PARPORT_IRQ_NONE)
3aeda9bc9   Alan Cox   parport_pc: Codin...
2560
  			printk(", irq=%d", irq);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2561
  		if (dma != PARPORT_DMA_NONE)
3aeda9bc9   Alan Cox   parport_pc: Codin...
2562
2563
2564
  			printk(", dma=%d", dma);
  		printk("
  ");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2565
2566
  		return 1;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
2567

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2568
2569
2570
2571
2572
2573
2574
2575
  	printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d
  ",
  		port1, irq, dma);
  	return 0;
  }
  
  
  enum parport_pc_sio_types {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2576
2577
  	sio_via_686a = 0,   /* Via VT82C686A motherboard Super I/O */
  	sio_via_8231,	    /* Via VT8231 south bridge integrated Super IO */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2578
2579
2580
2581
2582
2583
  	sio_ite_8872,
  	last_sio
  };
  
  /* each element directly indexed from enum list, above */
  static struct parport_pc_superio {
a6767b7cc   Marko Kohtala   [PATCH] parport: ...
2584
2585
2586
  	int (*probe) (struct pci_dev *pdev, int autoirq, int autodma,
  		      const struct parport_pc_via_data *via);
  	const struct parport_pc_via_data *via;
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2587
  } parport_pc_superio_info[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
  	{ sio_via_probe, &via_686a_data, },
  	{ sio_via_probe, &via_8231_data, },
  	{ sio_ite_8872_probe, NULL, },
  };
  
  enum parport_pc_pci_cards {
  	siig_1p_10x = last_sio,
  	siig_2p_10x,
  	siig_1p_20x,
  	siig_2p_20x,
  	lava_parallel,
  	lava_parallel_dual_a,
  	lava_parallel_dual_b,
  	boca_ioppar,
  	plx_9050,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2603
2604
2605
2606
2607
2608
2609
2610
  	timedia_4006a,
  	timedia_4014,
  	timedia_4008a,
  	timedia_4018,
  	timedia_9018a,
  	syba_2p_epp,
  	syba_1p_ecp,
  	titan_010l,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2611
2612
  	avlab_1p,
  	avlab_2p,
c140e1100   Ryan Underwood   [PATCH] parport_p...
2613
  	oxsemi_952,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2614
2615
  	oxsemi_954,
  	oxsemi_840,
7106b4e33   Lee Howard   8250: Oxford Semi...
2616
  	oxsemi_pcie_pport,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2617
2618
2619
2620
2621
2622
2623
  	aks_0100,
  	mobility_pp,
  	netmos_9705,
  	netmos_9715,
  	netmos_9755,
  	netmos_9805,
  	netmos_9815,
c4285b47b   Michael Buesch   parport/serial: a...
2624
  	netmos_9901,
ac6ec5b1d   Ira W. Snyder   serial: 8250_pci:...
2625
  	netmos_9865,
dc999159b   Luís P Mendes   parport: add supp...
2626
  	quatech_sppxp100,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2627
  };
3aeda9bc9   Alan Cox   parport_pc: Codin...
2628
  /* each element directly indexed from enum list, above
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2629
2630
2631
2632
   * (but offset by last_sio) */
  static struct parport_pc_pci {
  	int numports;
  	struct { /* BAR (base address registers) numbers in the config
3aeda9bc9   Alan Cox   parport_pc: Codin...
2633
  		    space header */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2634
  		int lo;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2635
2636
  		int hi;
  		/* -1 if not there, >6 for offset-method (max BAR is 6) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
  	} addr[4];
  
  	/* If set, this is called immediately after pci_enable_device.
  	 * If it returns non-zero, no probing will take place and the
  	 * ports will not be used. */
  	int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma);
  
  	/* If set, this is called after probing for ports.  If 'failed'
  	 * is non-zero we couldn't use any of the ports. */
  	void (*postinit_hook) (struct pci_dev *pdev, int failed);
96766a3ca   Randy.Dunlap   [PATCH] parport_p...
2647
  } cards[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2648
2649
2650
2651
2652
2653
2654
2655
2656
  	/* siig_1p_10x */		{ 1, { { 2, 3 }, } },
  	/* siig_2p_10x */		{ 2, { { 2, 3 }, { 4, 5 }, } },
  	/* siig_1p_20x */		{ 1, { { 0, 1 }, } },
  	/* siig_2p_20x */		{ 2, { { 0, 1 }, { 2, 3 }, } },
  	/* lava_parallel */		{ 1, { { 0, -1 }, } },
  	/* lava_parallel_dual_a */	{ 1, { { 0, -1 }, } },
  	/* lava_parallel_dual_b */	{ 1, { { 0, -1 }, } },
  	/* boca_ioppar */		{ 1, { { 0, -1 }, } },
  	/* plx_9050 */			{ 2, { { 4, -1 }, { 5, -1 }, } },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2657
2658
2659
2660
2661
2662
  	/* timedia_4006a */             { 1, { { 0, -1 }, } },
  	/* timedia_4014  */             { 2, { { 0, -1 }, { 2, -1 }, } },
  	/* timedia_4008a */             { 1, { { 0, 1 }, } },
  	/* timedia_4018  */             { 2, { { 0, 1 }, { 2, 3 }, } },
  	/* timedia_9018a */             { 2, { { 0, 1 }, { 2, 3 }, } },
  					/* SYBA uses fixed offsets in
3aeda9bc9   Alan Cox   parport_pc: Codin...
2663
  					   a 1K io window */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2664
2665
2666
  	/* syba_2p_epp AP138B */	{ 2, { { 0, 0x078 }, { 0, 0x178 }, } },
  	/* syba_1p_ecp W83787 */	{ 1, { { 0, 0x078 }, } },
  	/* titan_010l */		{ 1, { { 3, -1 }, } },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2667
2668
2669
2670
  	/* avlab_1p		*/	{ 1, { { 0, 1}, } },
  	/* avlab_2p		*/	{ 2, { { 0, 1}, { 2, 3 },} },
  	/* The Oxford Semi cards are unusual: 954 doesn't support ECP,
  	 * and 840 locks up if you write 1 to bit 2! */
c140e1100   Ryan Underwood   [PATCH] parport_p...
2671
  	/* oxsemi_952 */		{ 1, { { 0, 1 }, } },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2672
  	/* oxsemi_954 */		{ 1, { { 0, -1 }, } },
adbd321a1   Bernhard Walle   parport_pc: add b...
2673
  	/* oxsemi_840 */		{ 1, { { 0, 1 }, } },
7106b4e33   Lee Howard   8250: Oxford Semi...
2674
  	/* oxsemi_pcie_pport */		{ 1, { { 0, 1 }, } },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2675
2676
  	/* aks_0100 */                  { 1, { { 0, -1 }, } },
  	/* mobility_pp */		{ 1, { { 0, 1 }, } },
3aeda9bc9   Alan Cox   parport_pc: Codin...
2677
2678
2679
2680
2681
  
  	/* The netmos entries below are untested */
  	/* netmos_9705 */               { 1, { { 0, -1 }, } },
  	/* netmos_9715 */               { 2, { { 0, 1 }, { 2, 3 },} },
  	/* netmos_9755 */               { 2, { { 0, 1 }, { 2, 3 },} },
d6a484520   Sebastian Andrzej Siewior   parport: parport_...
2682
2683
  	/* netmos_9805 */		{ 1, { { 0, 1 }, } },
  	/* netmos_9815 */		{ 2, { { 0, 1 }, { 2, 3 }, } },
c4285b47b   Michael Buesch   parport/serial: a...
2684
  	/* netmos_9901 */               { 1, { { 0, -1 }, } },
ac6ec5b1d   Ira W. Snyder   serial: 8250_pci:...
2685
  	/* netmos_9865 */               { 1, { { 0, -1 }, } },
dc999159b   Luís P Mendes   parport: add supp...
2686
  	/* quatech_sppxp100 */		{ 1, { { 0, 1 }, } },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2687
  };
a6767b7cc   Marko Kohtala   [PATCH] parport: ...
2688
  static const struct pci_device_id parport_pc_pci_tbl[] = {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
  	/* Super-IO onboard chips */
  	{ 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a },
  	{ 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 },
  	{ PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 },
  
  	/* PCI cards */
  	{ PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x },
  	{ PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x },
  	{ PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x },
  	{ PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x },
  	{ PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel },
  	{ PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a },
  	{ PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b },
  	{ PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar },
  	{ PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
3aeda9bc9   Alan Cox   parport_pc: Codin...
2713
  	  PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0, 0, plx_9050 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2714
  	/* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2715
2716
2717
2718
2719
  	{ 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a },
  	{ 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 },
  	{ 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a },
  	{ 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 },
  	{ 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2720
2721
2722
2723
2724
2725
  	{ PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp },
  	{ PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp },
  	{ PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2726
  	/* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/
3aeda9bc9   Alan Cox   parport_pc: Codin...
2727
2728
  	/* AFAVLAB_TK9902 */
  	{ 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p},
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2729
  	{ 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p},
c140e1100   Ryan Underwood   [PATCH] parport_p...
2730
2731
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI952PP,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_952 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2732
2733
2734
2735
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 },
7106b4e33   Lee Howard   8250: Oxford Semi...
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe840_G,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_0_G,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_G,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_U,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
  	{ PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_PCIe952_1_GU,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_pcie_pport },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2752
2753
  	{ PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 },
7106b4e33   Lee Howard   8250: Oxford Semi...
2754
  	{ 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
  	/* NetMos communication controllers */
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 },
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 },
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 },
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 },
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 },
c4285b47b   Michael Buesch   parport/serial: a...
2766
2767
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9901,
  	  0xA000, 0x2000, 0, 0, netmos_9901 },
ac6ec5b1d   Ira W. Snyder   serial: 8250_pci:...
2768
2769
2770
2771
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
  	  0xA000, 0x1000, 0, 0, netmos_9865 },
  	{ PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9865,
  	  0xA000, 0x2000, 0, 0, netmos_9865 },
dc999159b   Luís P Mendes   parport: add supp...
2772
2773
2774
  	/* Quatech SPPXP-100 Parallel port PCI ExpressCard */
  	{ PCI_VENDOR_ID_QUATECH, PCI_DEVICE_ID_QUATECH_SPPXP_100,
  	  PCI_ANY_ID, PCI_ANY_ID, 0, 0, quatech_sppxp100 },
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2775
2776
  	{ 0, } /* terminate list */
  };
3aeda9bc9   Alan Cox   parport_pc: Codin...
2777
  MODULE_DEVICE_TABLE(pci, parport_pc_pci_tbl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2778
2779
2780
2781
2782
  
  struct pci_parport_data {
  	int num;
  	struct parport *ports[2];
  };
3aeda9bc9   Alan Cox   parport_pc: Codin...
2783
  static int parport_pc_pci_probe(struct pci_dev *dev,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
  					   const struct pci_device_id *id)
  {
  	int err, count, n, i = id->driver_data;
  	struct pci_parport_data *data;
  
  	if (i < last_sio)
  		/* This is an onboard Super-IO and has already been probed */
  		return 0;
  
  	/* This is a PCI card */
  	i -= last_sio;
  	count = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2796
2797
  	err = pci_enable_device(dev);
  	if (err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2798
2799
2800
2801
2802
2803
2804
  		return err;
  
  	data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL);
  	if (!data)
  		return -ENOMEM;
  
  	if (cards[i].preinit_hook &&
3aeda9bc9   Alan Cox   parport_pc: Codin...
2805
  	    cards[i].preinit_hook(dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2806
2807
2808
2809
2810
2811
2812
  		kfree(data);
  		return -ENODEV;
  	}
  
  	for (n = 0; n < cards[i].numports; n++) {
  		int lo = cards[i].addr[n].lo;
  		int hi = cards[i].addr[n].hi;
51dcdfec6   Alan Cox   parport: Use the ...
2813
  		int irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2814
  		unsigned long io_lo, io_hi;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2815
  		io_lo = pci_resource_start(dev, lo);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2816
2817
  		io_hi = 0;
  		if ((hi >= 0) && (hi <= 6))
3aeda9bc9   Alan Cox   parport_pc: Codin...
2818
  			io_hi = pci_resource_start(dev, hi);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2819
2820
  		else if (hi > 6)
  			io_lo += hi; /* Reinterpret the meaning of
3aeda9bc9   Alan Cox   parport_pc: Codin...
2821
2822
  					"hi" as an offset (see SYBA
  					def.) */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2823
  		/* TODO: test if sharing interrupts works */
51dcdfec6   Alan Cox   parport: Use the ...
2824
2825
  		irq = dev->irq;
  		if (irq == IRQ_NONE) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2826
  			printk(KERN_DEBUG
51dcdfec6   Alan Cox   parport: Use the ...
2827
2828
  	"PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx)
  ",
3f6e48597   Sebastian Andrzej Siewior   parport: parport_...
2829
  				id->vendor, id->device, io_lo, io_hi);
51dcdfec6   Alan Cox   parport: Use the ...
2830
2831
  			irq = PARPORT_IRQ_NONE;
  		} else {
3aeda9bc9   Alan Cox   parport_pc: Codin...
2832
  			printk(KERN_DEBUG
51dcdfec6   Alan Cox   parport: Use the ...
2833
2834
  	"PCI parallel port detected: %04x:%04x, I/O at %#lx(%#lx), IRQ %d
  ",
3f6e48597   Sebastian Andrzej Siewior   parport: parport_...
2835
  				id->vendor, id->device, io_lo, io_hi, irq);
51dcdfec6   Alan Cox   parport: Use the ...
2836
  		}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2837
  		data->ports[count] =
51dcdfec6   Alan Cox   parport: Use the ...
2838
2839
2840
  			parport_pc_probe_port(io_lo, io_hi, irq,
  					       PARPORT_DMA_NONE, &dev->dev,
  					       IRQF_SHARED);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2841
2842
2843
2844
2845
2846
2847
  		if (data->ports[count])
  			count++;
  	}
  
  	data->num = count;
  
  	if (cards[i].postinit_hook)
3aeda9bc9   Alan Cox   parport_pc: Codin...
2848
  		cards[i].postinit_hook(dev, count == 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
  
  	if (count) {
  		pci_set_drvdata(dev, data);
  		return 0;
  	}
  
  	kfree(data);
  
  	return -ENODEV;
  }
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2859
  static void parport_pc_pci_remove(struct pci_dev *dev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2860
2861
2862
  {
  	struct pci_parport_data *data = pci_get_drvdata(dev);
  	int i;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
  	if (data) {
  		for (i = data->num - 1; i >= 0; i--)
  			parport_pc_unregister_port(data->ports[i]);
  
  		kfree(data);
  	}
  }
  
  static struct pci_driver parport_pc_pci_driver = {
  	.name		= "parport_pc",
  	.id_table	= parport_pc_pci_tbl,
  	.probe		= parport_pc_pci_probe,
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2875
  	.remove		= parport_pc_pci_remove,
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2876
  };
3aeda9bc9   Alan Cox   parport_pc: Codin...
2877
  static int __init parport_pc_init_superio(int autoirq, int autodma)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2878
2879
2880
2881
  {
  	const struct pci_device_id *id;
  	struct pci_dev *pdev = NULL;
  	int ret = 0;
c9d8073fd   Jiri Slaby   [PATCH] PCI: remo...
2882
  	for_each_pci_dev(pdev) {
758658589   Greg Kroah-Hartman   [PATCH] PCI: clea...
2883
  		id = pci_match_id(parport_pc_pci_tbl, pdev);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2884
2885
  		if (id == NULL || id->driver_data >= last_sio)
  			continue;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2886
2887
2888
  		if (parport_pc_superio_info[id->driver_data].probe(
  			pdev, autoirq, autodma,
  			parport_pc_superio_info[id->driver_data].via)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2889
2890
2891
2892
2893
2894
2895
2896
  			ret++;
  		}
  	}
  
  	return ret; /* number of devices found */
  }
  #else
  static struct pci_driver parport_pc_pci_driver;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2897
2898
2899
2900
  static int __init parport_pc_init_superio(int autoirq, int autodma)
  {
  	return 0;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2901
  #endif /* CONFIG_PCI */
f2b9a3962   Bjorn Helgaas   parport_pc: wrap ...
2902
  #ifdef CONFIG_PNP
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2903
2904
2905
2906
2907
2908
2909
2910
  
  static const struct pnp_device_id parport_pc_pnp_tbl[] = {
  	/* Standard LPT Printer Port */
  	{.id = "PNP0400", .driver_data = 0},
  	/* ECP Printer Port */
  	{.id = "PNP0401", .driver_data = 0},
  	{ }
  };
3aeda9bc9   Alan Cox   parport_pc: Codin...
2911
  MODULE_DEVICE_TABLE(pnp, parport_pc_pnp_tbl);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2912

3aeda9bc9   Alan Cox   parport_pc: Codin...
2913
2914
  static int parport_pc_pnp_probe(struct pnp_dev *dev,
  						const struct pnp_device_id *id)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2915
2916
2917
2918
  {
  	struct parport *pdata;
  	unsigned long io_lo, io_hi;
  	int dma, irq;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2919
2920
2921
  	if (pnp_port_valid(dev, 0) &&
  		!(pnp_port_flags(dev, 0) & IORESOURCE_DISABLED)) {
  		io_lo = pnp_port_start(dev, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2922
2923
  	} else
  		return -EINVAL;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2924
2925
2926
  	if (pnp_port_valid(dev, 1) &&
  		!(pnp_port_flags(dev, 1) & IORESOURCE_DISABLED)) {
  		io_hi = pnp_port_start(dev, 1);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2927
2928
  	} else
  		io_hi = 0;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2929
2930
2931
  	if (pnp_irq_valid(dev, 0) &&
  		!(pnp_irq_flags(dev, 0) & IORESOURCE_DISABLED)) {
  		irq = pnp_irq(dev, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2932
2933
  	} else
  		irq = PARPORT_IRQ_NONE;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2934
2935
2936
  	if (pnp_dma_valid(dev, 0) &&
  		!(pnp_dma_flags(dev, 0) & IORESOURCE_DISABLED)) {
  		dma = pnp_dma(dev, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2937
2938
  	} else
  		dma = PARPORT_DMA_NONE;
c15a3837d   David Brownell   parport->dev driv...
2939
2940
  	dev_info(&dev->dev, "reported by %s
  ", dev->protocol->name);
3aeda9bc9   Alan Cox   parport_pc: Codin...
2941
2942
  	pdata = parport_pc_probe_port(io_lo, io_hi, irq, dma, &dev->dev, 0);
  	if (pdata == NULL)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2943
  		return -ENODEV;
3aeda9bc9   Alan Cox   parport_pc: Codin...
2944
  	pnp_set_drvdata(dev, pdata);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
  	return 0;
  }
  
  static void parport_pc_pnp_remove(struct pnp_dev *dev)
  {
  	struct parport *pdata = (struct parport *)pnp_get_drvdata(dev);
  	if (!pdata)
  		return;
  
  	parport_pc_unregister_port(pdata);
  }
  
  /* we only need the pnp layer to activate the device, at least for now */
  static struct pnp_driver parport_pc_pnp_driver = {
  	.name		= "parport_pc",
  	.id_table	= parport_pc_pnp_tbl,
  	.probe		= parport_pc_pnp_probe,
  	.remove		= parport_pc_pnp_remove,
  };
f2b9a3962   Bjorn Helgaas   parport_pc: wrap ...
2964
2965
2966
  #else
  static struct pnp_driver parport_pc_pnp_driver;
  #endif /* CONFIG_PNP */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2967

312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2968
  static int parport_pc_platform_probe(struct platform_device *pdev)
a7d801afc   Jean Delvare   legacy PC parport...
2969
2970
2971
2972
2973
2974
2975
2976
  {
  	/* Always succeed, the actual probing is done in
  	 * parport_pc_probe_port(). */
  	return 0;
  }
  
  static struct platform_driver parport_pc_platform_driver = {
  	.driver = {
a7d801afc   Jean Delvare   legacy PC parport...
2977
2978
2979
2980
  		.name	= "parport_pc",
  	},
  	.probe		= parport_pc_platform_probe,
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2981
  /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */
312facaf9   Greg Kroah-Hartman   Drivers: parport:...
2982
  static int __attribute__((unused))
3aeda9bc9   Alan Cox   parport_pc: Codin...
2983
  parport_pc_find_isa_ports(int autoirq, int autodma)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2984
2985
  {
  	int count = 0;
51dcdfec6   Alan Cox   parport: Use the ...
2986
  	if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL, 0))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2987
  		count++;
51dcdfec6   Alan Cox   parport: Use the ...
2988
  	if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL, 0))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2989
  		count++;
51dcdfec6   Alan Cox   parport: Use the ...
2990
  	if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL, 0))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
  		count++;
  
  	return count;
  }
  
  /* This function is called by parport_pc_init if the user didn't
   * specify any ports to probe.  Its job is to find some ports.  Order
   * is important here -- we want ISA ports to be registered first,
   * followed by PCI cards (for least surprise), but before that we want
   * to do chipset-specific tests for some onboard ports that we know
   * about.
   *
   * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY
   * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO
   */
3aeda9bc9   Alan Cox   parport_pc: Codin...
3006
  static void __init parport_pc_find_ports(int autoirq, int autodma)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3007
  {
7597fee38   Bjorn Helgaas   [PATCH] pnp: parp...
3008
  	int count = 0, err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3009
3010
  
  #ifdef CONFIG_PARPORT_PC_SUPERIO
f63fd7e29   Petr Cvek   parport_pc: detec...
3011
3012
3013
  	detect_and_report_it87();
  	detect_and_report_winbond();
  	detect_and_report_smsc();
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3014
3015
3016
  #endif
  
  	/* Onboard SuperIO chipsets that show themselves on the PCI bus. */
f63fd7e29   Petr Cvek   parport_pc: detec...
3017
  	count += parport_pc_init_superio(autoirq, autodma);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3018
3019
3020
  
  	/* PnP ports, skip detection if SuperIO already found them */
  	if (!count) {
f63fd7e29   Petr Cvek   parport_pc: detec...
3021
  		err = pnp_register_driver(&parport_pc_pnp_driver);
7597fee38   Bjorn Helgaas   [PATCH] pnp: parp...
3022
  		if (!err)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3023
  			pnp_registered_parport = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3024
3025
3026
  	}
  
  	/* ISA ports and whatever (see asm/parport.h). */
f63fd7e29   Petr Cvek   parport_pc: detec...
3027
  	parport_pc_find_nonpci_ports(autoirq, autodma);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3028

f63fd7e29   Petr Cvek   parport_pc: detec...
3029
  	err = pci_register_driver(&parport_pc_pci_driver);
7597fee38   Bjorn Helgaas   [PATCH] pnp: parp...
3030
3031
  	if (!err)
  		pci_registered_parport = 1;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3032
3033
3034
3035
3036
3037
3038
  }
  
  /*
   *	Piles of crap below pretend to be a parser for module and kernel
   *	parameters.  Say "thank you" to whoever had come up with that
   *	syntax and keep in mind that code below is a cleaned up version.
   */
3aeda9bc9   Alan Cox   parport_pc: Codin...
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
  static int __initdata io[PARPORT_PC_MAX_PORTS+1] = {
  	[0 ... PARPORT_PC_MAX_PORTS] = 0
  };
  static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = {
  	[0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO
  };
  static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = {
  	[0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE
  };
  static int __initdata irqval[PARPORT_PC_MAX_PORTS] = {
  	[0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY
  };
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
  
  static int __init parport_parse_param(const char *s, int *val,
  				int automatic, int none, int nofifo)
  {
  	if (!s)
  		return 0;
  	if (!strncmp(s, "auto", 4))
  		*val = automatic;
  	else if (!strncmp(s, "none", 4))
  		*val = none;
1f2c19f8c   Joe Perches   parport_pc.c: use...
3061
  	else if (nofifo && !strncmp(s, "nofifo", 6))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
  		*val = nofifo;
  	else {
  		char *ep;
  		unsigned long r = simple_strtoul(s, &ep, 0);
  		if (ep != s)
  			*val = r;
  		else {
  			printk(KERN_ERR "parport: bad specifier `%s'
  ", s);
  			return -1;
  		}
  	}
  	return 0;
  }
  
  static int __init parport_parse_irq(const char *irqstr, int *val)
  {
  	return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO,
  				     PARPORT_IRQ_NONE, 0);
  }
  
  static int __init parport_parse_dma(const char *dmastr, int *val)
  {
  	return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO,
  				     PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO);
  }
  
  #ifdef CONFIG_PCI
  static int __init parport_init_mode_setup(char *str)
  {
3aeda9bc9   Alan Cox   parport_pc: Codin...
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
  	printk(KERN_DEBUG
  	     "parport_pc.c: Specified parameter parport_init_mode=%s
  ", str);
  
  	if (!strcmp(str, "spp"))
  		parport_init_mode = 1;
  	if (!strcmp(str, "ps2"))
  		parport_init_mode = 2;
  	if (!strcmp(str, "epp"))
  		parport_init_mode = 3;
  	if (!strcmp(str, "ecp"))
  		parport_init_mode = 4;
  	if (!strcmp(str, "ecpepp"))
  		parport_init_mode = 5;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3106
3107
3108
3109
3110
  	return 1;
  }
  #endif
  
  #ifdef MODULE
45dac90f0   Andrew Morton   drivers/parport/p...
3111
3112
  static char *irq[PARPORT_PC_MAX_PORTS];
  static char *dma[PARPORT_PC_MAX_PORTS];
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
  
  MODULE_PARM_DESC(io, "Base I/O address (SPP regs)");
  module_param_array(io, int, NULL, 0);
  MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)");
  module_param_array(io_hi, int, NULL, 0);
  MODULE_PARM_DESC(irq, "IRQ line");
  module_param_array(irq, charp, NULL, 0);
  MODULE_PARM_DESC(dma, "DMA channel");
  module_param_array(dma, charp, NULL, 0);
  #if defined(CONFIG_PARPORT_PC_SUPERIO) || \
         (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO))
  MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation");
  module_param(verbose_probing, int, 0644);
  #endif
  #ifdef CONFIG_PCI
  static char *init_mode;
3aeda9bc9   Alan Cox   parport_pc: Codin...
3129
3130
  MODULE_PARM_DESC(init_mode,
  	"Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)");
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
  module_param(init_mode, charp, 0);
  #endif
  
  static int __init parse_parport_params(void)
  {
  	unsigned int i;
  	int val;
  
  #ifdef CONFIG_PCI
  	if (init_mode)
  		parport_init_mode_setup(init_mode);
  #endif
  
  	for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) {
  		if (parport_parse_irq(irq[i], &val))
  			return 1;
  		irqval[i] = val;
  		if (parport_parse_dma(dma[i], &val))
  			return 1;
  		dmaval[i] = val;
  	}
  	if (!io[0]) {
  		/* The user can make us use any IRQs or DMAs we find. */
  		if (irq[0] && !parport_parse_irq(irq[0], &val))
  			switch (val) {
  			case PARPORT_IRQ_NONE:
  			case PARPORT_IRQ_AUTO:
  				irqval[0] = val;
  				break;
  			default:
3aeda9bc9   Alan Cox   parport_pc: Codin...
3161
  				printk(KERN_WARNING
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
  					"parport_pc: irq specified "
  					"without base address.  Use 'io=' "
  					"to specify one
  ");
  			}
  
  		if (dma[0] && !parport_parse_dma(dma[0], &val))
  			switch (val) {
  			case PARPORT_DMA_NONE:
  			case PARPORT_DMA_AUTO:
  				dmaval[0] = val;
  				break;
  			default:
3aeda9bc9   Alan Cox   parport_pc: Codin...
3175
  				printk(KERN_WARNING
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
  					"parport_pc: dma specified "
  					"without base address.  Use 'io=' "
  					"to specify one
  ");
  			}
  	}
  	return 0;
  }
  
  #else
3aeda9bc9   Alan Cox   parport_pc: Codin...
3186
  static int parport_setup_ptr __initdata;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
  
  /*
   * Acceptable parameters:
   *
   * parport=0
   * parport=auto
   * parport=0xBASE[,IRQ[,DMA]]
   *
   * IRQ/DMA may be numeric or 'auto' or 'none'
   */
3aeda9bc9   Alan Cox   parport_pc: Codin...
3197
  static int __init parport_setup(char *str)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
  {
  	char *endptr;
  	char *sep;
  	int val;
  
  	if (!str || !*str || (*str == '0' && !*(str+1))) {
  		/* Disable parport if "parport=0" in cmdline */
  		io[0] = PARPORT_DISABLE;
  		return 1;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
3208
  	if (!strncmp(str, "auto", 4)) {
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3209
3210
3211
3212
  		irqval[0] = PARPORT_IRQ_AUTO;
  		dmaval[0] = PARPORT_DMA_AUTO;
  		return 1;
  	}
3aeda9bc9   Alan Cox   parport_pc: Codin...
3213
  	val = simple_strtoul(str, &endptr, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3214
  	if (endptr == str) {
3aeda9bc9   Alan Cox   parport_pc: Codin...
3215
3216
  		printk(KERN_WARNING "parport=%s not understood
  ", str);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
  		return 1;
  	}
  
  	if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) {
  		printk(KERN_ERR "parport=%s ignored, too many ports
  ", str);
  		return 1;
  	}
  
  	io[parport_setup_ptr] = val;
  	irqval[parport_setup_ptr] = PARPORT_IRQ_NONE;
  	dmaval[parport_setup_ptr] = PARPORT_DMA_NONE;
  
  	sep = strchr(str, ',');
  	if (sep++) {
  		if (parport_parse_irq(sep, &val))
  			return 1;
  		irqval[parport_setup_ptr] = val;
  		sep = strchr(sep, ',');
  		if (sep++) {
  			if (parport_parse_dma(sep, &val))
  				return 1;
  			dmaval[parport_setup_ptr] = val;
  		}
  	}
  	parport_setup_ptr++;
  	return 1;
  }
  
  static int __init parse_parport_params(void)
  {
  	return io[0] == PARPORT_DISABLE;
  }
3aeda9bc9   Alan Cox   parport_pc: Codin...
3250
  __setup("parport=", parport_setup);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3251
3252
3253
3254
3255
3256
3257
  
  /*
   * Acceptable parameters:
   *
   * parport_init_mode=[spp|ps2|epp|ecp|ecpepp]
   */
  #ifdef CONFIG_PCI
3aeda9bc9   Alan Cox   parport_pc: Codin...
3258
  __setup("parport_init_mode=", parport_init_mode_setup);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3259
3260
3261
3262
3263
3264
3265
  #endif
  #endif
  
  /* "Parser" ends here */
  
  static int __init parport_pc_init(void)
  {
a7d801afc   Jean Delvare   legacy PC parport...
3266
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3267
3268
  	if (parse_parport_params())
  		return -EINVAL;
a7d801afc   Jean Delvare   legacy PC parport...
3269
3270
3271
  	err = platform_driver_register(&parport_pc_platform_driver);
  	if (err)
  		return err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3272
3273
3274
3275
3276
3277
3278
  	if (io[0]) {
  		int i;
  		/* Only probe the ports we were given. */
  		user_specified = 1;
  		for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) {
  			if (!io[i])
  				break;
3aeda9bc9   Alan Cox   parport_pc: Codin...
3279
3280
  			if (io_hi[i] == PARPORT_IOHI_AUTO)
  				io_hi[i] = 0x400 + io[i];
7597fee38   Bjorn Helgaas   [PATCH] pnp: parp...
3281
  			parport_pc_probe_port(io[i], io_hi[i],
3aeda9bc9   Alan Cox   parport_pc: Codin...
3282
  					irqval[i], dmaval[i], NULL, 0);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3283
3284
  		}
  	} else
3aeda9bc9   Alan Cox   parport_pc: Codin...
3285
  		parport_pc_find_ports(irqval[0], dmaval[0]);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3286
3287
3288
3289
3290
3291
3292
  
  	return 0;
  }
  
  static void __exit parport_pc_exit(void)
  {
  	if (pci_registered_parport)
3aeda9bc9   Alan Cox   parport_pc: Codin...
3293
  		pci_unregister_driver(&parport_pc_pci_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3294
  	if (pnp_registered_parport)
3aeda9bc9   Alan Cox   parport_pc: Codin...
3295
  		pnp_unregister_driver(&parport_pc_pnp_driver);
a7d801afc   Jean Delvare   legacy PC parport...
3296
  	platform_driver_unregister(&parport_pc_platform_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3297

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3298
3299
3300
  	while (!list_empty(&ports_list)) {
  		struct parport_pc_private *priv;
  		struct parport *port;
91905b6f4   Jiri Slaby   parport: parport_...
3301
  		struct device *dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3302
3303
3304
  		priv = list_entry(ports_list.next,
  				  struct parport_pc_private, list);
  		port = priv->port;
91905b6f4   Jiri Slaby   parport: parport_...
3305
  		dev = port->dev;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3306
  		parport_pc_unregister_port(port);
91905b6f4   Jiri Slaby   parport: parport_...
3307
3308
  		if (dev && dev->bus == &platform_bus_type)
  			platform_device_unregister(to_platform_device(dev));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3309
  	}
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
3310
3311
3312
3313
3314
3315
3316
  }
  
  MODULE_AUTHOR("Phil Blundell, Tim Waugh, others");
  MODULE_DESCRIPTION("PC-style parallel port driver");
  MODULE_LICENSE("GPL");
  module_init(parport_pc_init)
  module_exit(parport_pc_exit)