diff options
author | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-16 18:20:36 -0400 |
commit | 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch) | |
tree | 0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/parport |
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history,
even though we have it. We can create a separate "historical" git
archive of that later if we want to, and in the meantime it's about
3.2GB when imported into git - space that would just make the early
git days unnecessarily complicated, when we don't have a lot of good
infrastructure for it.
Let it rip!
Diffstat (limited to 'drivers/parport')
-rw-r--r-- | drivers/parport/BUGS-parport | 9 | ||||
-rw-r--r-- | drivers/parport/ChangeLog | 583 | ||||
-rw-r--r-- | drivers/parport/Kconfig | 145 | ||||
-rw-r--r-- | drivers/parport/Makefile | 19 | ||||
-rw-r--r-- | drivers/parport/TODO-parport | 20 | ||||
-rw-r--r-- | drivers/parport/daisy.c | 512 | ||||
-rw-r--r-- | drivers/parport/ieee1284.c | 819 | ||||
-rw-r--r-- | drivers/parport/ieee1284_ops.c | 921 | ||||
-rw-r--r-- | drivers/parport/multiface.h | 20 | ||||
-rw-r--r-- | drivers/parport/parport_amiga.c | 293 | ||||
-rw-r--r-- | drivers/parport/parport_arc.c | 139 | ||||
-rw-r--r-- | drivers/parport/parport_atari.c | 240 | ||||
-rw-r--r-- | drivers/parport/parport_cs.c | 397 | ||||
-rw-r--r-- | drivers/parport/parport_gsc.c | 437 | ||||
-rw-r--r-- | drivers/parport/parport_gsc.h | 222 | ||||
-rw-r--r-- | drivers/parport/parport_mfc3.c | 404 | ||||
-rw-r--r-- | drivers/parport/parport_pc.c | 3415 | ||||
-rw-r--r-- | drivers/parport/parport_serial.c | 485 | ||||
-rw-r--r-- | drivers/parport/parport_sunbpp.c | 412 | ||||
-rw-r--r-- | drivers/parport/probe.c | 224 | ||||
-rw-r--r-- | drivers/parport/procfs.c | 533 | ||||
-rw-r--r-- | drivers/parport/share.c | 1014 |
22 files changed, 11263 insertions, 0 deletions
diff --git a/drivers/parport/BUGS-parport b/drivers/parport/BUGS-parport new file mode 100644 index 000000000000..622ca3cc7fa0 --- /dev/null +++ b/drivers/parport/BUGS-parport | |||
@@ -0,0 +1,9 @@ | |||
1 | Currently known (or at least suspected) bugs in parport: | ||
2 | |||
3 | o lp doesn't allow you to read status while printing is in progress (is | ||
4 | this still true?). | ||
5 | |||
6 | o parport_pc_ecp_read_block_pio() is broken. parport will revert to the | ||
7 | software-driven mode in ieee1284_ops.c | ||
8 | |||
9 | See <URL:http://people.redhat.com/twaugh/parport/>. | ||
diff --git a/drivers/parport/ChangeLog b/drivers/parport/ChangeLog new file mode 100644 index 000000000000..db717c1d62a5 --- /dev/null +++ b/drivers/parport/ChangeLog | |||
@@ -0,0 +1,583 @@ | |||
1 | 2001-10-11 Tim Waugh <twaugh@redhat.com> | ||
2 | * parport_pc.c, parport_serial.c: Support for NetMos cards. | ||
3 | + Patch originally from Michael Reinelt <reinelt@eunet.at>. | ||
4 | |||
5 | 2002-04-25 Tim Waugh <twaugh@redhat.com> | ||
6 | |||
7 | * parport_serial.c, parport_pc.c: Move some SIIG cards around. | ||
8 | Patch from Andrey Panin. | ||
9 | |||
10 | 2002-01-20 Tim Waugh <twaugh@redhat.com> | ||
11 | |||
12 | * parport_pc.c (parport_pc_compat_write_block_pio, | ||
13 | parport_pc_ecp_write_block_pio, parport_pc_ecp_read_block_pio): | ||
14 | Use the default implementations if the caller wants to use | ||
15 | O_NONBLOCK. | ||
16 | |||
17 | 2002-02-25 Tim Waugh <twaugh@redhat.com> | ||
18 | |||
19 | * parport_pc.c: Make sure that priv->ctr_writable includes IntEn | ||
20 | even if IRQ is given as a parameter. | ||
21 | |||
22 | 2002-01-21 Tim Waugh <twaugh@redhat.com> | ||
23 | |||
24 | * daisy.c: Apply patch from Max Vorobiev to make parport_daisy_select | ||
25 | work for ECP/EPP modes. | ||
26 | |||
27 | 2002-01-13 Niels Kristian Bech Jensen <nkbj@image.dk> | ||
28 | |||
29 | * parport_pc.c: Change some occurrences of frob_set_mode to | ||
30 | ECR_WRITE. This fixes PLIP. | ||
31 | |||
32 | 2002-01-04 Tim Waugh <twaugh@redhat.com> | ||
33 | |||
34 | * share.c (parport_claim_or_block): Sleep interruptibly to prevent | ||
35 | a possible deadlock. | ||
36 | |||
37 | 2001-12-07 Damian Gruszka <damian.gruszka@VisionSystems.de> | ||
38 | |||
39 | * parport_pc.c (ECR_WRITE): Define. If there are forbidden bits | ||
40 | in the ECR register for some chips, this will be a useful place to | ||
41 | put that knowledge. | ||
42 | (change_mode): Use ECR_WRITE. | ||
43 | (parport_pc_restore_state): Likewise. | ||
44 | (parport_ECPPS2_supported): Likewise. | ||
45 | (parport_ECPEPP_supported): Likewise. | ||
46 | (irq_probe_EPP): Likewise. | ||
47 | (programmable_irq_support): Likewise. | ||
48 | (programmable_dma_support): Likewise. | ||
49 | (parport_pc_probe_port): Likewise. | ||
50 | |||
51 | (frob_set_mode): New function. Set the mode bits of the ECR. | ||
52 | (get_fifo_residue): Use frob_set_mode. | ||
53 | (parport_pc_ecpepp_read_data): Likewise. | ||
54 | (parport_pc_ecpepp_write_data): Likewise. | ||
55 | (parport_pc_ecpepp_read_addr): Likewise. | ||
56 | (parport_pc_ecpepp_write_addr): Likewise. | ||
57 | (parport_pc_compat_write_block_pio): Likewise. | ||
58 | (parport_pc_ecp_write_block_pio): Likewise. | ||
59 | (parport_ECR_present): Likewise. | ||
60 | (parport_ECP_supported): Likewise. | ||
61 | (parport_EPP_supported): Likewise. | ||
62 | (parport_ECPEPP_supported): Likewise. | ||
63 | (programmable_irq_support): Likewise. | ||
64 | (irq_probe_ECP): Likewise. | ||
65 | (programmable_dma_support): Likewise. | ||
66 | |||
67 | (parport_pc_enable_irq): Only enable interrupts if we know which | ||
68 | IRQ line they will come from. | ||
69 | (parport_pc_init_state): Set nErrIntrEn at initialisation. | ||
70 | (parport_pc_restore_state): Only write writable bits of CTR. | ||
71 | (parport_irq_probe): If no IRQ is found, take ackIntEn out of the | ||
72 | writable bit set. | ||
73 | |||
74 | 2001-12-07 Tim Waugh <twaugh@redhat.com> | ||
75 | |||
76 | * parport_pc.c (parport_pc_fifo_write_block_pio): Correct typo. | ||
77 | (parport_pc_init_state): Only set ackIntEn if we know which IRQ | ||
78 | line the interrupts will come from. | ||
79 | |||
80 | 2001-12-07 Tim Waugh <twaugh@redhat.com> | ||
81 | |||
82 | * ieee1284_ops.c (parport_ieee1284_epp_write_addr, | ||
83 | parport_ieee1284_epp_read_addr): Actually do something useful. | ||
84 | |||
85 | 2001-12-07 Tim Waugh <twaugh@redhat.com> | ||
86 | |||
87 | * parport_pc.c (dmaval): Don't use DMA by default. It seems to be | ||
88 | too buggy at the moment. Use 'dma=auto' to restore the previous | ||
89 | behaviour. | ||
90 | |||
91 | 2001-12-07 Tim Waugh <twaugh@redhat.com> | ||
92 | |||
93 | * daisy.c (DEBUG): Undefine. | ||
94 | |||
95 | 2001-12-06 Tim Waugh <twaugh@redhat.com> | ||
96 | |||
97 | * ieee1284_ops.c (parport_ieee1284_ecp_read_data): Mask off | ||
98 | PARPORT_CONTROL_AUTOFD as well. Bug spotted by Joe | ||
99 | <joeja@mindspring.com>. | ||
100 | |||
101 | 2001-12-03 Rich Liu <Rich.Liu@ite.com.tw> | ||
102 | |||
103 | * parport_pc.c (sio_ite_8872_probe): ITE8873 is a single-port | ||
104 | serial board, not a serial+parallel. | ||
105 | |||
106 | 2001-11-30 Niels Kristian Bech Jensen <nkbj@image.dk> | ||
107 | |||
108 | * parport_pc.c: Fix compiler warning. | ||
109 | |||
110 | 2001-11-14 Tim Waugh <twaugh@redhat.com> | ||
111 | |||
112 | * parport_pc.c (parport_pc_pci_probe): Hooks for PCI cards before | ||
113 | and after probing for ports. | ||
114 | * parport_serial.c (parport_register): Likewise. | ||
115 | |||
116 | 2001-11-12 Tim Waugh <twaugh@redhat.com> | ||
117 | |||
118 | * parport_pc.c (init_module): Warn when parameters are ignored. | ||
119 | |||
120 | 2001-11-01 Damian Gruszka <damian.gruszka@VisionSystems.de> | ||
121 | |||
122 | * parport_serial.c (serial_register): Set base_baud before | ||
123 | calling register_serial. | ||
124 | |||
125 | 2001-10-26 Tim Waugh <twaugh@redhat.com> | ||
126 | |||
127 | * parport_pc.c (parport_irq_probe): When ECR programmable IRQ | ||
128 | support fails, generate interrupts using the FIFO even if we don't | ||
129 | want to use the FIFO for real data transfers. | ||
130 | (parport_pc_probe_port): Display the ECR address if we have an | ||
131 | ECR, not just if we will use the FIFO. | ||
132 | |||
133 | 2001-10-24 Dave Strauss <D.Strauss@motorola.com> | ||
134 | |||
135 | * parport_pc.c (parport_pc_compat_write_block_pio, | ||
136 | parport_pc_ecp_write_block_pio): Allow a few seconds for an ECP | ||
137 | transfer to finish up. | ||
138 | |||
139 | 2001-10-11 Tim Waugh <twaugh@redhat.com> | ||
140 | |||
141 | * parport_pc (sio_ite_8872_probe): New function, submitted by Rich | ||
142 | Liu from ITE. Cleaned up, removed bogus phys_to_virt calls. | ||
143 | |||
144 | 2001-10-24 Tim Waugh <twaugh@redhat.com> | ||
145 | |||
146 | * parport_pc.c: Support for AKS AladdinCARD. Patch from | ||
147 | Aladdin Knowledge Systems (Christian Groessler). | ||
148 | |||
149 | 2001-10-24 Tim Waugh <twaugh@redhat.com> | ||
150 | |||
151 | * ieee1284_ops.c (parport_ieee1284_ecp_read_data): Try to minimise | ||
152 | turnaround time. | ||
153 | |||
154 | * ieee1284.c (parport_poll_peripheral): Try a couple of times | ||
155 | first without delaying. | ||
156 | |||
157 | 2001-10-10 Tim Waugh <twaugh@redhat.com> | ||
158 | |||
159 | * parport_pc.c: Support for OX16PCI954 PCI card. | ||
160 | |||
161 | 2001-10-10 Tim Waugh <twaugh@redhat.com> | ||
162 | |||
163 | * parport_pc.c: Support for OX12PCI840 PCI card (reported by | ||
164 | mk@daveg.com). Lock-ups diagnosed by Ronnie Arosa (and now we | ||
165 | just don't trust its ECR). | ||
166 | |||
167 | 2001-10-10 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
168 | |||
169 | * parport_pc.c: Support for AVLAB cards. | ||
170 | |||
171 | 2001-10-10 Tim Waugh <twaugh@redhat.com> | ||
172 | |||
173 | * ieee1284_ops.c (ecp_forward_to_reverse, ecp_reverse_to_forward): | ||
174 | Remember to retry direction switch if it fails. Patch from David | ||
175 | Lambert. | ||
176 | |||
177 | 2001-10-08 David C. Hansen <haveblue@us.ibm.com> | ||
178 | |||
179 | * share.c: Make driverlist_lock and parportlist_lock static. | ||
180 | |||
181 | 2001-10-08 Philip Blundell <philb@gnu.org> | ||
182 | |||
183 | * parport_pc.c: New modular parameter verbose_logging. | ||
184 | Make port->modes indicate the modes that we are prepared to use, | ||
185 | rather than the modes that are available. | ||
186 | |||
187 | 2001-10-07 Tim Waugh <twaugh@redhat.com> | ||
188 | |||
189 | * parport_pc.c (parport_pc_probe_port): Fix memory leak spotted by | ||
190 | Kipp Cannon. | ||
191 | |||
192 | 2001-10-07 Tim Waugh <twaugh@redhat.com> | ||
193 | |||
194 | * parport_serial.c: Remove NetMos support, since it causes problems | ||
195 | for some people. | ||
196 | |||
197 | 2001-08-30 Tim Waugh <twaugh@redhat.com> | ||
198 | |||
199 | * parport_serial.c (parport_serial_pci_probe): Clean-up on partial | ||
200 | registration failure. | ||
201 | |||
202 | 2001-08-14 Tim Waugh <twaugh@redhat.com> | ||
203 | |||
204 | * parport_pc.c (parport_pc_init_superio): Allow for more than one | ||
205 | SuperIO device. Patch from Rich Lio (ITE). | ||
206 | |||
207 | 2001-08-11 Tim Waugh <twaugh@redhat.com> | ||
208 | |||
209 | * parport_pc.c: Support for Titan Electronics cards. | ||
210 | |||
211 | 2001-08-08 Tim Waugh <twaugh@redhat.com> | ||
212 | |||
213 | * share.c (parport_unregister_device): Remove device from wait list | ||
214 | too. | ||
215 | |||
216 | 2001-06-20 Tim Waugh <twaugh@redhat.com> | ||
217 | |||
218 | * parport_pc.c: Make 'io_hi=0' work. | ||
219 | |||
220 | 2001-05-31 Tim Waugh <twaugh@redhat.com> | ||
221 | |||
222 | * parport_serial.c: New file. | ||
223 | |||
224 | 2001-06-05 Tim Waugh <twaugh@redhat.com> | ||
225 | |||
226 | * parport_pc.c (parport_pc_unregister_port): New exported function. | ||
227 | Do the opposite of parport_pc_probe_port. | ||
228 | (cleanup_module): Use it. | ||
229 | |||
230 | 2001-05-22 Juan Quintela <quintela@mandrakesoft.com> | ||
231 | |||
232 | * parport_amiga.c: Set printk levels. | ||
233 | * parport_gsc.c: Likewise. | ||
234 | * parport_mfc3.c: Likewise. | ||
235 | * parport_pc.c: Likewise. | ||
236 | * parport_sunbpp.c: Likewise. | ||
237 | * probe.c: Likewise. | ||
238 | * share.c: Likewise. | ||
239 | |||
240 | 2001-05-10 Fred Barnes <frmb2@ukc.ac.uk> | ||
241 | |||
242 | * parport_pc.c (parport_pc_epp_read_data): added support for | ||
243 | reading from a w91284pic peripheral, flag is PARPORT_W91284PIC. | ||
244 | |||
245 | 2001-05-07 Fred Barnes <frmb2@ukc.ac.uk> | ||
246 | |||
247 | * parport_pc.c (parport_pc_epp_read_data, | ||
248 | parport_pc_epp_write_data, parport_pc_epp_read_addr, | ||
249 | parport_pc_epp_write_addr): support for fast reads/writes using | ||
250 | the PARPORT_EPP_FAST flag. | ||
251 | |||
252 | * ieee1284.c (parport_read, parport_write): added code to handle | ||
253 | software EPP mode (IEEE1284_MODE_EPPSWE). Added code to allow | ||
254 | BYTE mode reverse transfers (previously always went for NIBBLE | ||
255 | mode). | ||
256 | |||
257 | * ieee1284_ops.c (parport_ieee1284_epp_read_data, | ||
258 | parport_ieee1284_epp_write_data): fixed various polarity problems. | ||
259 | Also (theoretically) fixed address versions (.._addr), but no | ||
260 | hardware to test this on. | ||
261 | |||
262 | * parport_pc.h: added parport_dump_state() function for debugging. | ||
263 | Needs to have DEBUG_PARPORT to be defined for it to be included. | ||
264 | |||
265 | 2001-05-03 Tim Waugh <twaugh@redhat.com> | ||
266 | |||
267 | * parport_pc.c: Fix the compile problem I introduce from the last | ||
268 | change. | ||
269 | |||
270 | 2001-04-20 Paul Gortmaker <p_gortmaker@yahoo.com> | ||
271 | |||
272 | * parport_pc.c: Cut down the size quite a bit (more than 4k off | ||
273 | the object, about 1k off the zImage) for the older non-PCI | ||
274 | machines which are typically resource starved anyway... | ||
275 | |||
276 | 2001-03-26 R Horn <rjh@world.std.com> | ||
277 | |||
278 | * parport_pc.c: Some commentary changes. | ||
279 | |||
280 | 2001-04-19 Tim Waugh <twaugh@redhat.com> | ||
281 | |||
282 | * parport_pc.c (parport_pc_probe_port): Remove __devinit | ||
283 | attribute. Export unconditionally. | ||
284 | |||
285 | 2001-04-14 Jeff Garzik <jgarzik@pobox.com> | ||
286 | |||
287 | Merged: 2001-03-30 Tim Waugh <twaugh@redhat.com> | ||
288 | |||
289 | * drivers/parport/parport_pc.c: Make Via SuperIO chipsets behave | ||
290 | like everything else with respect to irq= and dma= parameters. | ||
291 | |||
292 | 2001-04-08 Tim Waugh <twaugh@redhat.com> | ||
293 | |||
294 | * parport_pc.c (parport_pc_save_state): Read from the soft copy of | ||
295 | the control port. | ||
296 | (parport_pc_restore_state): Update the soft copy of the control | ||
297 | port. | ||
298 | |||
299 | 2001-03-26 Tim Waugh <twaugh@redhat.com> | ||
300 | |||
301 | * share.c (parport_find_number, parport_find_base): Trigger | ||
302 | a lowlevel driver load if there are no ports yet. | ||
303 | |||
304 | 2001-03-26 Tim Waugh <twaugh@redhat.com> | ||
305 | |||
306 | * parport_pc.c (parport_ECP_supported): Remove the IRQ conflict | ||
307 | check since it seems totally unreliable. | ||
308 | |||
309 | 2001-03-02 Tim Waugh <twaugh@redhat.com> | ||
310 | |||
311 | * ieee1284_ops.c (parport_ieee1284_read_nibble): Reset nAutoFd | ||
312 | on timeout. Matches 2.2.x behaviour. | ||
313 | |||
314 | 2001-03-02 Andrew Morton <andrewm@uow.edu.au> | ||
315 | |||
316 | * parport_pc.c (registered_parport): New static variable. | ||
317 | (parport_pc_find_ports): Set it when we register PCI driver. | ||
318 | (init_module): Unregister PCI driver if necessary when we | ||
319 | fail. | ||
320 | |||
321 | 2001-03-02 Tim Waugh <twaugh@redhat.com> | ||
322 | |||
323 | * ieee1284_ops.c (parport_ieee1284_write_compat): Don't use | ||
324 | down_trylock to reset the IRQ count. Don't even use sema_init, | ||
325 | because it's not even necessary to reset the count. I can't | ||
326 | remember why we ever did. | ||
327 | |||
328 | 2001-01-04 Peter Osterlund <peter.osterlund@mailbox.swipnet.se> | ||
329 | |||
330 | * ieee1284.c (parport_negotiate): Fix missing printk argument. | ||
331 | |||
332 | 2001-01-03 Paul Schleger <Paul.Schleger@t-online.de> | ||
333 | |||
334 | * probe.c (parse_data): Get rid of trailing blanks in values. | ||
335 | Needed for XEROX XJ8C printer. | ||
336 | |||
337 | 2001-01-03 Tim Waugh <twaugh@redhat.com> | ||
338 | |||
339 | * parport_pc.c (parport_pc_probe_port): Say something when probes | ||
340 | are omitted. | ||
341 | |||
342 | 2001-01-03 Tim Waugh <twaugh@redhat.com> | ||
343 | |||
344 | * parport_pc.c (sio_via_686a_probe): Correct dma=255 fix. | ||
345 | |||
346 | 2000-11-21 Tim Waugh <twaugh@redhat.com> | ||
347 | |||
348 | * parport_pc.c (parport_pc_ecp_write_block_pio): Fix | ||
349 | reverse-to-forward logic. Spotted by Roland Kuck | ||
350 | <rci@cityweb.de>. | ||
351 | |||
352 | 2000-09-16 Cesar Eduardo Barros <cesarb@nitnet.com.br> | ||
353 | |||
354 | * parport_pc.c (sio_via_686a_probe): Handle case | ||
355 | where hardware returns 255 for IRQ or DMA. | ||
356 | |||
357 | 2000-07-20 Eddie C. Dost <ecd@skynet.be> | ||
358 | |||
359 | * share.c (attach_driver_chain): attach[i](port) needs to be | ||
360 | replaced by attach[count](port). | ||
361 | |||
362 | 2000-07-20 Eddie C. Dost <ecd@skynet.be> | ||
363 | |||
364 | * daisy.c (add_dev): kmalloc args are in wrong order. | ||
365 | |||
366 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
367 | |||
368 | * share.c: Documentation for parport_{get,port}_port, | ||
369 | parport_find_{number,base}. | ||
370 | |||
371 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
372 | |||
373 | * share.c (parport_unregister_device): Remove unneeded locking | ||
374 | (test cad==dev). | ||
375 | (parport_claim): Likewise. | ||
376 | (parport_find_number): New function. | ||
377 | |||
378 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
379 | |||
380 | * share.c (parport_register_port): Hold the parportlist_lock while | ||
381 | looking for a free parport number. | ||
382 | (parport_register_driver): Make sure that attach can block. | ||
383 | (attach_driver_chain): Likewise. | ||
384 | |||
385 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
386 | |||
387 | * share.c (call_driver_chain): Do reference counting things. | ||
388 | (parport_get_port): New function. | ||
389 | (parport_put_port): New function. | ||
390 | (parport_register_port): Initialise reference count to zero. | ||
391 | (parport_unregister_port): Check reference count rather than | ||
392 | driver list to see if we can free the port. | ||
393 | |||
394 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
395 | |||
396 | * share.c: Clarifications in doc comments. | ||
397 | |||
398 | 2000-07-12 Tim Waugh <twaugh@redhat.com> | ||
399 | |||
400 | * share.c (parport_unregister_port): Fix typo in comment. | ||
401 | |||
402 | 2000-07-11 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
403 | |||
404 | * parport_pc.c: Support for the full range of Timedia cards. | ||
405 | |||
406 | 2000-07-08 Tim Waugh <twaugh@redhat.com> | ||
407 | |||
408 | * daisy.c: License block comments as part of parportbook. | ||
409 | * ieee1284.c: Likewise. | ||
410 | * share.c: Likewise. | ||
411 | |||
412 | 2000-06-30 Petr Vandrovec <vandrove@vc.cvut.cz> | ||
413 | |||
414 | * procfs.c (do_hardware_modes): Generated string can be up to 34 | ||
415 | chars long. | ||
416 | |||
417 | 2000-06-20 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
418 | |||
419 | * parport_pc.c (parport_pc_compat_write_block_pio): Warn about | ||
420 | change_mode failures. | ||
421 | (parport_pc_ecp_write_block_pio): Likewise. | ||
422 | (parport_pc_ecp_read_block_pio): Likewise. | ||
423 | |||
424 | 2000-06-20 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
425 | |||
426 | * parport_pc.c (parport_SPP_supported): Warn more about possibly | ||
427 | incorrect parameters. | ||
428 | |||
429 | 2000-06-15 Tim Waugh <twaugh@redhat.com> | ||
430 | |||
431 | * parport_pc.c (parport_ECP_supported): Set PARPORT_MODE_COMPAT | ||
432 | for ECP ports, since they can all do hardware accelerated | ||
433 | compatibility mode (I assume). | ||
434 | |||
435 | 2000-06-13 Tim Waugh <twaugh@redhat.com> | ||
436 | |||
437 | * parport_pc.c (cleanup_module): Remark about possible bugs. | ||
438 | |||
439 | 2000-06-13 Tim Waugh <twaugh@redhat.com> | ||
440 | |||
441 | * procfs.c: Break 'hardware' out into separate files. | ||
442 | |||
443 | 2000-05-28 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
444 | |||
445 | * Fix PCI ID printk for non-superio PCI cards. | ||
446 | |||
447 | 2000-05-28 Tim Waugh <twaugh@redhat.com> | ||
448 | |||
449 | * share.c (call_driver_chain): Get the driverlist_lock. | ||
450 | (parport_register_device): Make sure that port->devices always | ||
451 | looks consistent. | ||
452 | (parport_register_driver): Ensure that parport drivers are given | ||
453 | parameters that are valid for the duration of the callback by | ||
454 | locking the portlist against changes. | ||
455 | (parport_unregister_driver): Likewise. | ||
456 | (parport_claim): Don't overwrite flags. | ||
457 | |||
458 | 2000-05-28 Tim Waugh <twaugh@redhat.com> | ||
459 | |||
460 | * daisy.c (assign_addrs): Avoid double-probing daisy-chain devices | ||
461 | if the first probe succeeds. | ||
462 | |||
463 | 2000-05-16 Tim Waugh <twaugh@redhat.com> | ||
464 | |||
465 | * share.c (parport_claim): Fix SMP race. | ||
466 | |||
467 | 2000-05-15 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
468 | |||
469 | * parport_pc.c (parport_pc_compat_write_block_pio): Check for | ||
470 | timeouts. | ||
471 | (parport_pc_ecp_write_block_pio): Likewise. | ||
472 | (parport_pc_ecp_read_block_pio): Likewise. | ||
473 | |||
474 | 2000-05-02 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
475 | |||
476 | * parport_pc.c: PCI SYBA patch and verbose PCI detection. | ||
477 | |||
478 | 2000-05-02 Gunther Mayer <gunther.mayer@braunschweig.okersurf.de> | ||
479 | |||
480 | * parport_pc.c (decode_smsc): Fix SMSC 665/666 identification. | ||
481 | |||
482 | 2000-04-28 Tim Waugh <twaugh@redhat.com> | ||
483 | |||
484 | * ieee1284.c: Short function descriptions can't be multiline. | ||
485 | |||
486 | * daisy.c: Short function descriptions can't be multiline. | ||
487 | |||
488 | 2000-04-19 Tim Waugh <twaugh@redhat.com> | ||
489 | |||
490 | * parport_pc.c (parport_pc_fifo_write_block_dma): Make maxlen | ||
491 | calculation a bit clearer. | ||
492 | |||
493 | * ieee1284.c (parport_negotiate): Turn on data line drivers. | ||
494 | |||
495 | * ieee1284_ops.c (parport_ieee1284_read_byte): Turn off data line | ||
496 | drivers. | ||
497 | (parport_ieee1284_write_compat): Turn on data line drivers. | ||
498 | |||
499 | * daisy.c (assign_addrs): Turn on data line drivers. | ||
500 | (cpp_mux): Likewise. | ||
501 | (cpp_daisy): Likewise. | ||
502 | |||
503 | 2000-04-04 Tim Waugh <twaugh@redhat.com> | ||
504 | |||
505 | * parport_pc.c: Add support for another PCI card. | ||
506 | |||
507 | 2000-04-04 Tim Waugh <twaugh@redhat.com> | ||
508 | |||
509 | * daisy.c: Documentation in kernel-doc format. | ||
510 | |||
511 | * ieee1284.c: Likewise. | ||
512 | |||
513 | * share.c: Likewise. | ||
514 | |||
515 | 2000-04-01 Tim Waugh <twaugh@redhat.com> | ||
516 | |||
517 | * share.c (parport_register_device): Need to hold the module | ||
518 | reference counts before sleeping. | ||
519 | |||
520 | 2000-03-27 Tim Waugh <twaugh@redhat.com> | ||
521 | |||
522 | * parport_pc.c (parport_pc_ecp_read_block_pio): Correct operation | ||
523 | when peripheral is trying to send data when we stop listening. | ||
524 | |||
525 | 2000-03-22 Tim Waugh <twaugh@redhat.com> | ||
526 | |||
527 | * init.c (parport_setup): Fix return value. | ||
528 | |||
529 | 2000-03-21 Tim Waugh <twaugh@redhat.com> | ||
530 | |||
531 | * parport_pc.c (parport_pc_pci_probe): Fix return value; call | ||
532 | pci_enable_device. | ||
533 | |||
534 | 2000-03-16 Tim Waugh <twaugh@redhat.com> | ||
535 | |||
536 | * parport_pc.c (parport_ECP_supported): This seems to trigger on | ||
537 | machines that don't have an IRQ conflict; toned down the warning | ||
538 | message accordingly. | ||
539 | |||
540 | 2000-03-16 Gunther Mayer <gunther.mayer@braunschweig.netsurf.de> | ||
541 | |||
542 | * parport_pc.c (show_parconfig_smsc37c669): Fix typo. | ||
543 | (decode_winbond): More IDs. | ||
544 | (winbond_check): Protect against false positives. | ||
545 | (winbond_check2): Likewise. | ||
546 | (smsc_check): Likewise. | ||
547 | |||
548 | 2000-03-15 Tim Waugh <twaugh@redhat.com> | ||
549 | |||
550 | * parport_pc.c (cleanup_module): Don't call pci_unregister_driver | ||
551 | if we didn't call pci_register_driver first. | ||
552 | |||
553 | 2000-03-13 Tim Waugh <twaugh@redhat.com> | ||
554 | |||
555 | * parport_pc.c (parport_pc_init): Moved from asm/parport.h. | ||
556 | |||
557 | * Config.in: CONFIG_PARPORT_PC_SUPERIO: new option. | ||
558 | |||
559 | * parport_pc.c (show_parconfig_smsc37c669): Make __devinit. | ||
560 | (show_parconfig_winbond): Likewise. | ||
561 | (decode_winbond): Likewise. | ||
562 | (decode_smsc): Likewise. | ||
563 | (winbond_check): Likewise. | ||
564 | (winbond_check2): Likewise. | ||
565 | (smsc_check): Likewise. | ||
566 | (detect_and_report_winbond): Likewise. | ||
567 | (detect_and_report_smsc): Likewise. | ||
568 | (get_superio_dma): Likewise. | ||
569 | (get_superio_irq): Likewise. | ||
570 | (parport_pc_find_isa_ports): New function. | ||
571 | (parport_pc_find_ports): New function. | ||
572 | (init_module): Make superio a config option, not a parameter. | ||
573 | |||
574 | 2000-03-10 Tim Waugh <twaugh@redhat.com> | ||
575 | |||
576 | * parport_pc.c (decode_winbond): Use correct 83877ATF chip ID. | ||
577 | (decode_winbond): Fix typo. | ||
578 | |||
579 | 2000-03-09 Tim Waugh <twaugh@redhat.com> | ||
580 | |||
581 | * parport_pc.c: Integrate SuperIO PCI probe with normal PCI card | ||
582 | probe, so that the MODULE_DEVICE_TABLE is complete. | ||
583 | |||
diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig new file mode 100644 index 000000000000..731010e0e6f6 --- /dev/null +++ b/drivers/parport/Kconfig | |||
@@ -0,0 +1,145 @@ | |||
1 | # | ||
2 | # For a description of the syntax of this configuration file, | ||
3 | # see Documentation/kbuild/kconfig-language.txt. | ||
4 | # | ||
5 | # Parport configuration. | ||
6 | # | ||
7 | |||
8 | menu "Parallel port support" | ||
9 | |||
10 | config PARPORT | ||
11 | tristate "Parallel port support" | ||
12 | ---help--- | ||
13 | If you want to use devices connected to your machine's parallel port | ||
14 | (the connector at the computer with 25 holes), e.g. printer, ZIP | ||
15 | drive, PLIP link (Parallel Line Internet Protocol is mainly used to | ||
16 | create a mini network by connecting the parallel ports of two local | ||
17 | machines) etc., then you need to say Y here; please read | ||
18 | <file:Documentation/parport.txt> and | ||
19 | <file:drivers/parport/BUGS-parport>. | ||
20 | |||
21 | For extensive information about drivers for many devices attaching | ||
22 | to the parallel port see <http://www.torque.net/linux-pp.html> on | ||
23 | the WWW. | ||
24 | |||
25 | It is possible to share a single parallel port among several devices | ||
26 | and it is safe to compile all the corresponding drivers into the | ||
27 | kernel. To compile parallel port support as a module, choose M here: | ||
28 | the module will be called parport. | ||
29 | If you have more than one parallel port and want to specify which | ||
30 | port and IRQ to be used by this driver at module load time, take a | ||
31 | look at <file:Documentation/parport.txt>. | ||
32 | |||
33 | If unsure, say Y. | ||
34 | |||
35 | config PARPORT_PC | ||
36 | tristate "PC-style hardware" | ||
37 | depends on PARPORT && (!SPARC64 || PCI) && (!SPARC32 || BROKEN) | ||
38 | ---help--- | ||
39 | You should say Y here if you have a PC-style parallel port. All | ||
40 | IBM PC compatible computers and some Alphas have PC-style | ||
41 | parallel ports. PA-RISC owners should only say Y here if they | ||
42 | have a SuperIO parallel port. | ||
43 | |||
44 | To compile this driver as a module, choose M here: the | ||
45 | module will be called parport_pc. | ||
46 | |||
47 | If unsure, say Y. | ||
48 | |||
49 | config PARPORT_SERIAL | ||
50 | tristate "Multi-IO cards (parallel and serial)" | ||
51 | depends on SERIAL_8250 && PARPORT_PC && PCI | ||
52 | help | ||
53 | This adds support for multi-IO PCI cards that have parallel and | ||
54 | serial ports. You should say Y or M here. If you say M, the module | ||
55 | will be called parport_serial. | ||
56 | |||
57 | config PARPORT_PC_FIFO | ||
58 | bool "Use FIFO/DMA if available (EXPERIMENTAL)" | ||
59 | depends on PARPORT_PC && EXPERIMENTAL | ||
60 | help | ||
61 | Many parallel port chipsets provide hardware that can speed up | ||
62 | printing. Say Y here if you want to take advantage of that. | ||
63 | |||
64 | As well as actually having a FIFO, or DMA capability, the kernel | ||
65 | will need to know which IRQ the parallel port has. By default, | ||
66 | parallel port interrupts will not be used, and so neither will the | ||
67 | FIFO. See <file:Documentation/parport.txt> to find out how to | ||
68 | specify which IRQ/DMA to use. | ||
69 | |||
70 | config PARPORT_PC_SUPERIO | ||
71 | bool "SuperIO chipset support (EXPERIMENTAL)" | ||
72 | depends on PARPORT_PC && EXPERIMENTAL | ||
73 | help | ||
74 | Saying Y here enables some probes for Super-IO chipsets in order to | ||
75 | find out things like base addresses, IRQ lines and DMA channels. It | ||
76 | is safe to say N. | ||
77 | |||
78 | config PARPORT_PC_PCMCIA | ||
79 | tristate "Support for PCMCIA management for PC-style ports" | ||
80 | depends on PARPORT!=n && (PCMCIA!=n && PARPORT_PC=m && PARPORT_PC || PARPORT_PC=y && PCMCIA) | ||
81 | help | ||
82 | Say Y here if you need PCMCIA support for your PC-style parallel | ||
83 | ports. If unsure, say N. | ||
84 | |||
85 | config PARPORT_NOT_PC | ||
86 | bool | ||
87 | |||
88 | config PARPORT_ARC | ||
89 | tristate "Archimedes hardware" | ||
90 | depends on ARM && PARPORT | ||
91 | select PARPORT_NOT_PC | ||
92 | |||
93 | config PARPORT_AMIGA | ||
94 | tristate "Amiga builtin port" | ||
95 | depends on AMIGA && PARPORT | ||
96 | select PARPORT_NOT_PC | ||
97 | help | ||
98 | Say Y here if you need support for the parallel port hardware on | ||
99 | Amiga machines. This code is also available as a module (say M), | ||
100 | called parport_amiga. If in doubt, saying N is the safe plan. | ||
101 | |||
102 | config PARPORT_MFC3 | ||
103 | tristate "Multiface III parallel port" | ||
104 | depends on ZORRO && PARPORT | ||
105 | select PARPORT_NOT_PC | ||
106 | help | ||
107 | Say Y here if you need parallel port support for the MFC3 card. | ||
108 | This code is also available as a module (say M), called | ||
109 | parport_mfc3. If in doubt, saying N is the safe plan. | ||
110 | |||
111 | config PARPORT_ATARI | ||
112 | tristate "Atari hardware" | ||
113 | depends on ATARI && PARPORT | ||
114 | select PARPORT_NOT_PC | ||
115 | help | ||
116 | Say Y here if you need support for the parallel port hardware on | ||
117 | Atari machines. This code is also available as a module (say M), | ||
118 | called parport_atari. If in doubt, saying N is the safe plan. | ||
119 | |||
120 | config PARPORT_GSC | ||
121 | tristate | ||
122 | default GSC | ||
123 | depends on PARPORT | ||
124 | |||
125 | config PARPORT_SUNBPP | ||
126 | tristate "Sparc hardware (EXPERIMENTAL)" | ||
127 | depends on SBUS && PARPORT && EXPERIMENTAL | ||
128 | select PARPORT_NOT_PC | ||
129 | help | ||
130 | This driver provides support for the bidirectional parallel port | ||
131 | found on many Sun machines. Note that many of the newer Ultras | ||
132 | actually have pc style hardware instead. | ||
133 | |||
134 | config PARPORT_1284 | ||
135 | bool "IEEE 1284 transfer modes" | ||
136 | depends on PARPORT | ||
137 | help | ||
138 | If you have a printer that supports status readback or device ID, or | ||
139 | want to use a device that uses enhanced parallel port transfer modes | ||
140 | such as EPP and ECP, say Y here to enable advanced IEEE 1284 | ||
141 | transfer modes. Also say Y if you want device ID information to | ||
142 | appear in /proc/sys/dev/parport/*/autoprobe*. It is safe to say N. | ||
143 | |||
144 | endmenu | ||
145 | |||
diff --git a/drivers/parport/Makefile b/drivers/parport/Makefile new file mode 100644 index 000000000000..5372212bb9d9 --- /dev/null +++ b/drivers/parport/Makefile | |||
@@ -0,0 +1,19 @@ | |||
1 | # | ||
2 | # Makefile for the kernel Parallel port device drivers. | ||
3 | # | ||
4 | |||
5 | parport-objs := share.o ieee1284.o ieee1284_ops.o procfs.o | ||
6 | |||
7 | ifeq ($(CONFIG_PARPORT_1284),y) | ||
8 | parport-objs += daisy.o probe.o | ||
9 | endif | ||
10 | |||
11 | obj-$(CONFIG_PARPORT) += parport.o | ||
12 | obj-$(CONFIG_PARPORT_PC) += parport_pc.o | ||
13 | obj-$(CONFIG_PARPORT_SERIAL) += parport_serial.o | ||
14 | obj-$(CONFIG_PARPORT_PC_PCMCIA) += parport_cs.o | ||
15 | obj-$(CONFIG_PARPORT_AMIGA) += parport_amiga.o | ||
16 | obj-$(CONFIG_PARPORT_MFC3) += parport_mfc3.o | ||
17 | obj-$(CONFIG_PARPORT_ATARI) += parport_atari.o | ||
18 | obj-$(CONFIG_PARPORT_SUNBPP) += parport_sunbpp.o | ||
19 | obj-$(CONFIG_PARPORT_GSC) += parport_gsc.o | ||
diff --git a/drivers/parport/TODO-parport b/drivers/parport/TODO-parport new file mode 100644 index 000000000000..089b14ee446f --- /dev/null +++ b/drivers/parport/TODO-parport | |||
@@ -0,0 +1,20 @@ | |||
1 | Things to be done. | ||
2 | |||
3 | 0. Fix the bugs (see BUGS-parport). | ||
4 | |||
5 | 1. Proper documentation. | ||
6 | |||
7 | 2. A better lp.c: | ||
8 | |||
9 | a) ECP support would be nice. This can only work if both the port and | ||
10 | the printer support it. | ||
11 | |||
12 | b) Handle status readback automatically. IEEE1284 printers can post status | ||
13 | bits when they have something to say. We should read out and deal | ||
14 | with (maybe just log) whatever the printer wants to tell the world. | ||
15 | |||
16 | 3. Support more hardware (eg m68k, Sun bpp). | ||
17 | |||
18 | 4. A better PLIP (make use of bidirectional/ECP/EPP ports). | ||
19 | |||
20 | See <URL:http://people.redhat.com/twaugh/parport/>. | ||
diff --git a/drivers/parport/daisy.c b/drivers/parport/daisy.c new file mode 100644 index 000000000000..075c7eb5c85d --- /dev/null +++ b/drivers/parport/daisy.c | |||
@@ -0,0 +1,512 @@ | |||
1 | /* | ||
2 | * IEEE 1284.3 Parallel port daisy chain and multiplexor code | ||
3 | * | ||
4 | * Copyright (C) 1999, 2000 Tim Waugh <tim@cyberelk.demon.co.uk> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * ??-12-1998: Initial implementation. | ||
12 | * 31-01-1999: Make port-cloning transparent. | ||
13 | * 13-02-1999: Move DeviceID technique from parport_probe. | ||
14 | * 13-03-1999: Get DeviceID from non-IEEE 1284.3 devices too. | ||
15 | * 22-02-2000: Count devices that are actually detected. | ||
16 | * | ||
17 | * Any part of this program may be used in documents licensed under | ||
18 | * the GNU Free Documentation License, Version 1.1 or any later version | ||
19 | * published by the Free Software Foundation. | ||
20 | */ | ||
21 | |||
22 | #include <linux/module.h> | ||
23 | #include <linux/parport.h> | ||
24 | #include <linux/delay.h> | ||
25 | #include <linux/sched.h> | ||
26 | |||
27 | #include <asm/current.h> | ||
28 | #include <asm/uaccess.h> | ||
29 | |||
30 | #undef DEBUG | ||
31 | |||
32 | #ifdef DEBUG | ||
33 | #define DPRINTK(stuff...) printk (stuff) | ||
34 | #else | ||
35 | #define DPRINTK(stuff...) | ||
36 | #endif | ||
37 | |||
38 | static struct daisydev { | ||
39 | struct daisydev *next; | ||
40 | struct parport *port; | ||
41 | int daisy; | ||
42 | int devnum; | ||
43 | } *topology = NULL; | ||
44 | static DEFINE_SPINLOCK(topology_lock); | ||
45 | |||
46 | static int numdevs = 0; | ||
47 | |||
48 | /* Forward-declaration of lower-level functions. */ | ||
49 | static int mux_present (struct parport *port); | ||
50 | static int num_mux_ports (struct parport *port); | ||
51 | static int select_port (struct parport *port); | ||
52 | static int assign_addrs (struct parport *port); | ||
53 | |||
54 | /* Add a device to the discovered topology. */ | ||
55 | static void add_dev (int devnum, struct parport *port, int daisy) | ||
56 | { | ||
57 | struct daisydev *newdev, **p; | ||
58 | newdev = kmalloc (sizeof (struct daisydev), GFP_KERNEL); | ||
59 | if (newdev) { | ||
60 | newdev->port = port; | ||
61 | newdev->daisy = daisy; | ||
62 | newdev->devnum = devnum; | ||
63 | spin_lock(&topology_lock); | ||
64 | for (p = &topology; *p && (*p)->devnum<devnum; p = &(*p)->next) | ||
65 | ; | ||
66 | newdev->next = *p; | ||
67 | *p = newdev; | ||
68 | spin_unlock(&topology_lock); | ||
69 | } | ||
70 | } | ||
71 | |||
72 | /* Clone a parport (actually, make an alias). */ | ||
73 | static struct parport *clone_parport (struct parport *real, int muxport) | ||
74 | { | ||
75 | struct parport *extra = parport_register_port (real->base, | ||
76 | real->irq, | ||
77 | real->dma, | ||
78 | real->ops); | ||
79 | if (extra) { | ||
80 | extra->portnum = real->portnum; | ||
81 | extra->physport = real; | ||
82 | extra->muxport = muxport; | ||
83 | real->slaves[muxport-1] = extra; | ||
84 | } | ||
85 | |||
86 | return extra; | ||
87 | } | ||
88 | |||
89 | /* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains. | ||
90 | * Return value is number of devices actually detected. */ | ||
91 | int parport_daisy_init (struct parport *port) | ||
92 | { | ||
93 | int detected = 0; | ||
94 | char *deviceid; | ||
95 | static const char *th[] = { /*0*/"th", "st", "nd", "rd", "th" }; | ||
96 | int num_ports; | ||
97 | int i; | ||
98 | int last_try = 0; | ||
99 | |||
100 | again: | ||
101 | /* Because this is called before any other devices exist, | ||
102 | * we don't have to claim exclusive access. */ | ||
103 | |||
104 | /* If mux present on normal port, need to create new | ||
105 | * parports for each extra port. */ | ||
106 | if (port->muxport < 0 && mux_present (port) && | ||
107 | /* don't be fooled: a mux must have 2 or 4 ports. */ | ||
108 | ((num_ports = num_mux_ports (port)) == 2 || num_ports == 4)) { | ||
109 | /* Leave original as port zero. */ | ||
110 | port->muxport = 0; | ||
111 | printk (KERN_INFO | ||
112 | "%s: 1st (default) port of %d-way multiplexor\n", | ||
113 | port->name, num_ports); | ||
114 | for (i = 1; i < num_ports; i++) { | ||
115 | /* Clone the port. */ | ||
116 | struct parport *extra = clone_parport (port, i); | ||
117 | if (!extra) { | ||
118 | if (signal_pending (current)) | ||
119 | break; | ||
120 | |||
121 | schedule (); | ||
122 | continue; | ||
123 | } | ||
124 | |||
125 | printk (KERN_INFO | ||
126 | "%s: %d%s port of %d-way multiplexor on %s\n", | ||
127 | extra->name, i + 1, th[i + 1], num_ports, | ||
128 | port->name); | ||
129 | |||
130 | /* Analyse that port too. We won't recurse | ||
131 | forever because of the 'port->muxport < 0' | ||
132 | test above. */ | ||
133 | parport_daisy_init(extra); | ||
134 | } | ||
135 | } | ||
136 | |||
137 | if (port->muxport >= 0) | ||
138 | select_port (port); | ||
139 | |||
140 | parport_daisy_deselect_all (port); | ||
141 | detected += assign_addrs (port); | ||
142 | |||
143 | /* Count the potential legacy device at the end. */ | ||
144 | add_dev (numdevs++, port, -1); | ||
145 | |||
146 | /* Find out the legacy device's IEEE 1284 device ID. */ | ||
147 | deviceid = kmalloc (1000, GFP_KERNEL); | ||
148 | if (deviceid) { | ||
149 | if (parport_device_id (numdevs - 1, deviceid, 1000) > 2) | ||
150 | detected++; | ||
151 | |||
152 | kfree (deviceid); | ||
153 | } | ||
154 | |||
155 | if (!detected && !last_try) { | ||
156 | /* No devices were detected. Perhaps they are in some | ||
157 | funny state; let's try to reset them and see if | ||
158 | they wake up. */ | ||
159 | parport_daisy_fini (port); | ||
160 | parport_write_control (port, PARPORT_CONTROL_SELECT); | ||
161 | udelay (50); | ||
162 | parport_write_control (port, | ||
163 | PARPORT_CONTROL_SELECT | | ||
164 | PARPORT_CONTROL_INIT); | ||
165 | udelay (50); | ||
166 | last_try = 1; | ||
167 | goto again; | ||
168 | } | ||
169 | |||
170 | return detected; | ||
171 | } | ||
172 | |||
173 | /* Forget about devices on a physical port. */ | ||
174 | void parport_daisy_fini (struct parport *port) | ||
175 | { | ||
176 | struct daisydev **p; | ||
177 | |||
178 | spin_lock(&topology_lock); | ||
179 | p = &topology; | ||
180 | while (*p) { | ||
181 | struct daisydev *dev = *p; | ||
182 | if (dev->port != port) { | ||
183 | p = &dev->next; | ||
184 | continue; | ||
185 | } | ||
186 | *p = dev->next; | ||
187 | kfree(dev); | ||
188 | } | ||
189 | |||
190 | /* Gaps in the numbering could be handled better. How should | ||
191 | someone enumerate through all IEEE1284.3 devices in the | ||
192 | topology?. */ | ||
193 | if (!topology) numdevs = 0; | ||
194 | spin_unlock(&topology_lock); | ||
195 | return; | ||
196 | } | ||
197 | |||
198 | /** | ||
199 | * parport_open - find a device by canonical device number | ||
200 | * @devnum: canonical device number | ||
201 | * @name: name to associate with the device | ||
202 | * @pf: preemption callback | ||
203 | * @kf: kick callback | ||
204 | * @irqf: interrupt handler | ||
205 | * @flags: registration flags | ||
206 | * @handle: driver data | ||
207 | * | ||
208 | * This function is similar to parport_register_device(), except | ||
209 | * that it locates a device by its number rather than by the port | ||
210 | * it is attached to. | ||
211 | * | ||
212 | * All parameters except for @devnum are the same as for | ||
213 | * parport_register_device(). The return value is the same as | ||
214 | * for parport_register_device(). | ||
215 | **/ | ||
216 | |||
217 | struct pardevice *parport_open (int devnum, const char *name, | ||
218 | int (*pf) (void *), void (*kf) (void *), | ||
219 | void (*irqf) (int, void *, struct pt_regs *), | ||
220 | int flags, void *handle) | ||
221 | { | ||
222 | struct daisydev *p = topology; | ||
223 | struct parport *port; | ||
224 | struct pardevice *dev; | ||
225 | int daisy; | ||
226 | |||
227 | spin_lock(&topology_lock); | ||
228 | while (p && p->devnum != devnum) | ||
229 | p = p->next; | ||
230 | |||
231 | if (!p) { | ||
232 | spin_unlock(&topology_lock); | ||
233 | return NULL; | ||
234 | } | ||
235 | |||
236 | daisy = p->daisy; | ||
237 | port = parport_get_port(p->port); | ||
238 | spin_unlock(&topology_lock); | ||
239 | |||
240 | dev = parport_register_device (port, name, pf, kf, | ||
241 | irqf, flags, handle); | ||
242 | parport_put_port(port); | ||
243 | if (!dev) | ||
244 | return NULL; | ||
245 | |||
246 | dev->daisy = daisy; | ||
247 | |||
248 | /* Check that there really is a device to select. */ | ||
249 | if (daisy >= 0) { | ||
250 | int selected; | ||
251 | parport_claim_or_block (dev); | ||
252 | selected = port->daisy; | ||
253 | parport_release (dev); | ||
254 | |||
255 | if (selected != port->daisy) { | ||
256 | /* No corresponding device. */ | ||
257 | parport_unregister_device (dev); | ||
258 | return NULL; | ||
259 | } | ||
260 | } | ||
261 | |||
262 | return dev; | ||
263 | } | ||
264 | |||
265 | /** | ||
266 | * parport_close - close a device opened with parport_open() | ||
267 | * @dev: device to close | ||
268 | * | ||
269 | * This is to parport_open() as parport_unregister_device() is to | ||
270 | * parport_register_device(). | ||
271 | **/ | ||
272 | |||
273 | void parport_close (struct pardevice *dev) | ||
274 | { | ||
275 | parport_unregister_device (dev); | ||
276 | } | ||
277 | |||
278 | /** | ||
279 | * parport_device_num - convert device coordinates | ||
280 | * @parport: parallel port number | ||
281 | * @mux: multiplexor port number (-1 for no multiplexor) | ||
282 | * @daisy: daisy chain address (-1 for no daisy chain address) | ||
283 | * | ||
284 | * This tries to locate a device on the given parallel port, | ||
285 | * multiplexor port and daisy chain address, and returns its | ||
286 | * device number or -NXIO if no device with those coordinates | ||
287 | * exists. | ||
288 | **/ | ||
289 | |||
290 | int parport_device_num (int parport, int mux, int daisy) | ||
291 | { | ||
292 | int res = -ENXIO; | ||
293 | struct daisydev *dev; | ||
294 | |||
295 | spin_lock(&topology_lock); | ||
296 | dev = topology; | ||
297 | while (dev && dev->port->portnum != parport && | ||
298 | dev->port->muxport != mux && dev->daisy != daisy) | ||
299 | dev = dev->next; | ||
300 | if (dev) | ||
301 | res = dev->devnum; | ||
302 | spin_unlock(&topology_lock); | ||
303 | |||
304 | return res; | ||
305 | } | ||
306 | |||
307 | /* Send a daisy-chain-style CPP command packet. */ | ||
308 | static int cpp_daisy (struct parport *port, int cmd) | ||
309 | { | ||
310 | unsigned char s; | ||
311 | |||
312 | parport_data_forward (port); | ||
313 | parport_write_data (port, 0xaa); udelay (2); | ||
314 | parport_write_data (port, 0x55); udelay (2); | ||
315 | parport_write_data (port, 0x00); udelay (2); | ||
316 | parport_write_data (port, 0xff); udelay (2); | ||
317 | s = parport_read_status (port) & (PARPORT_STATUS_BUSY | ||
318 | | PARPORT_STATUS_PAPEROUT | ||
319 | | PARPORT_STATUS_SELECT | ||
320 | | PARPORT_STATUS_ERROR); | ||
321 | if (s != (PARPORT_STATUS_BUSY | ||
322 | | PARPORT_STATUS_PAPEROUT | ||
323 | | PARPORT_STATUS_SELECT | ||
324 | | PARPORT_STATUS_ERROR)) { | ||
325 | DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff(%02x)\n", | ||
326 | port->name, s); | ||
327 | return -ENXIO; | ||
328 | } | ||
329 | |||
330 | parport_write_data (port, 0x87); udelay (2); | ||
331 | s = parport_read_status (port) & (PARPORT_STATUS_BUSY | ||
332 | | PARPORT_STATUS_PAPEROUT | ||
333 | | PARPORT_STATUS_SELECT | ||
334 | | PARPORT_STATUS_ERROR); | ||
335 | if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) { | ||
336 | DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff87(%02x)\n", | ||
337 | port->name, s); | ||
338 | return -ENXIO; | ||
339 | } | ||
340 | |||
341 | parport_write_data (port, 0x78); udelay (2); | ||
342 | parport_write_data (port, cmd); udelay (2); | ||
343 | parport_frob_control (port, | ||
344 | PARPORT_CONTROL_STROBE, | ||
345 | PARPORT_CONTROL_STROBE); | ||
346 | udelay (1); | ||
347 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
348 | udelay (1); | ||
349 | s = parport_read_status (port); | ||
350 | parport_write_data (port, 0xff); udelay (2); | ||
351 | |||
352 | return s; | ||
353 | } | ||
354 | |||
355 | /* Send a mux-style CPP command packet. */ | ||
356 | static int cpp_mux (struct parport *port, int cmd) | ||
357 | { | ||
358 | unsigned char s; | ||
359 | int rc; | ||
360 | |||
361 | parport_data_forward (port); | ||
362 | parport_write_data (port, 0xaa); udelay (2); | ||
363 | parport_write_data (port, 0x55); udelay (2); | ||
364 | parport_write_data (port, 0xf0); udelay (2); | ||
365 | parport_write_data (port, 0x0f); udelay (2); | ||
366 | parport_write_data (port, 0x52); udelay (2); | ||
367 | parport_write_data (port, 0xad); udelay (2); | ||
368 | parport_write_data (port, cmd); udelay (2); | ||
369 | |||
370 | s = parport_read_status (port); | ||
371 | if (!(s & PARPORT_STATUS_ACK)) { | ||
372 | DPRINTK (KERN_DEBUG "%s: cpp_mux: aa55f00f52ad%02x(%02x)\n", | ||
373 | port->name, cmd, s); | ||
374 | return -EIO; | ||
375 | } | ||
376 | |||
377 | rc = (((s & PARPORT_STATUS_SELECT ? 1 : 0) << 0) | | ||
378 | ((s & PARPORT_STATUS_PAPEROUT ? 1 : 0) << 1) | | ||
379 | ((s & PARPORT_STATUS_BUSY ? 0 : 1) << 2) | | ||
380 | ((s & PARPORT_STATUS_ERROR ? 0 : 1) << 3)); | ||
381 | |||
382 | return rc; | ||
383 | } | ||
384 | |||
385 | void parport_daisy_deselect_all (struct parport *port) | ||
386 | { | ||
387 | cpp_daisy (port, 0x30); | ||
388 | } | ||
389 | |||
390 | int parport_daisy_select (struct parport *port, int daisy, int mode) | ||
391 | { | ||
392 | switch (mode) | ||
393 | { | ||
394 | // For these modes we should switch to EPP mode: | ||
395 | case IEEE1284_MODE_EPP: | ||
396 | case IEEE1284_MODE_EPPSL: | ||
397 | case IEEE1284_MODE_EPPSWE: | ||
398 | return (cpp_daisy (port, 0x20 + daisy) & | ||
399 | PARPORT_STATUS_ERROR); | ||
400 | |||
401 | // For these modes we should switch to ECP mode: | ||
402 | case IEEE1284_MODE_ECP: | ||
403 | case IEEE1284_MODE_ECPRLE: | ||
404 | case IEEE1284_MODE_ECPSWE: | ||
405 | return (cpp_daisy (port, 0xd0 + daisy) & | ||
406 | PARPORT_STATUS_ERROR); | ||
407 | |||
408 | // Nothing was told for BECP in Daisy chain specification. | ||
409 | // May be it's wise to use ECP? | ||
410 | case IEEE1284_MODE_BECP: | ||
411 | // Others use compat mode | ||
412 | case IEEE1284_MODE_NIBBLE: | ||
413 | case IEEE1284_MODE_BYTE: | ||
414 | case IEEE1284_MODE_COMPAT: | ||
415 | default: | ||
416 | return (cpp_daisy (port, 0xe0 + daisy) & | ||
417 | PARPORT_STATUS_ERROR); | ||
418 | } | ||
419 | } | ||
420 | |||
421 | static int mux_present (struct parport *port) | ||
422 | { | ||
423 | return cpp_mux (port, 0x51) == 3; | ||
424 | } | ||
425 | |||
426 | static int num_mux_ports (struct parport *port) | ||
427 | { | ||
428 | return cpp_mux (port, 0x58); | ||
429 | } | ||
430 | |||
431 | static int select_port (struct parport *port) | ||
432 | { | ||
433 | int muxport = port->muxport; | ||
434 | return cpp_mux (port, 0x60 + muxport) == muxport; | ||
435 | } | ||
436 | |||
437 | static int assign_addrs (struct parport *port) | ||
438 | { | ||
439 | unsigned char s, last_dev; | ||
440 | unsigned char daisy; | ||
441 | int thisdev = numdevs; | ||
442 | int detected; | ||
443 | char *deviceid; | ||
444 | |||
445 | parport_data_forward (port); | ||
446 | parport_write_data (port, 0xaa); udelay (2); | ||
447 | parport_write_data (port, 0x55); udelay (2); | ||
448 | parport_write_data (port, 0x00); udelay (2); | ||
449 | parport_write_data (port, 0xff); udelay (2); | ||
450 | s = parport_read_status (port) & (PARPORT_STATUS_BUSY | ||
451 | | PARPORT_STATUS_PAPEROUT | ||
452 | | PARPORT_STATUS_SELECT | ||
453 | | PARPORT_STATUS_ERROR); | ||
454 | if (s != (PARPORT_STATUS_BUSY | ||
455 | | PARPORT_STATUS_PAPEROUT | ||
456 | | PARPORT_STATUS_SELECT | ||
457 | | PARPORT_STATUS_ERROR)) { | ||
458 | DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff(%02x)\n", | ||
459 | port->name, s); | ||
460 | return 0; | ||
461 | } | ||
462 | |||
463 | parport_write_data (port, 0x87); udelay (2); | ||
464 | s = parport_read_status (port) & (PARPORT_STATUS_BUSY | ||
465 | | PARPORT_STATUS_PAPEROUT | ||
466 | | PARPORT_STATUS_SELECT | ||
467 | | PARPORT_STATUS_ERROR); | ||
468 | if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) { | ||
469 | DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff87(%02x)\n", | ||
470 | port->name, s); | ||
471 | return 0; | ||
472 | } | ||
473 | |||
474 | parport_write_data (port, 0x78); udelay (2); | ||
475 | last_dev = 0; /* We've just been speaking to a device, so we | ||
476 | know there must be at least _one_ out there. */ | ||
477 | |||
478 | for (daisy = 0; daisy < 4; daisy++) { | ||
479 | parport_write_data (port, daisy); | ||
480 | udelay (2); | ||
481 | parport_frob_control (port, | ||
482 | PARPORT_CONTROL_STROBE, | ||
483 | PARPORT_CONTROL_STROBE); | ||
484 | udelay (1); | ||
485 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
486 | udelay (1); | ||
487 | |||
488 | if (last_dev) | ||
489 | /* No more devices. */ | ||
490 | break; | ||
491 | |||
492 | last_dev = !(parport_read_status (port) | ||
493 | & PARPORT_STATUS_BUSY); | ||
494 | |||
495 | add_dev (numdevs++, port, daisy); | ||
496 | } | ||
497 | |||
498 | parport_write_data (port, 0xff); udelay (2); | ||
499 | detected = numdevs - thisdev; | ||
500 | DPRINTK (KERN_DEBUG "%s: Found %d daisy-chained devices\n", port->name, | ||
501 | detected); | ||
502 | |||
503 | /* Ask the new devices to introduce themselves. */ | ||
504 | deviceid = kmalloc (1000, GFP_KERNEL); | ||
505 | if (!deviceid) return 0; | ||
506 | |||
507 | for (daisy = 0; thisdev < numdevs; thisdev++, daisy++) | ||
508 | parport_device_id (thisdev, deviceid, 1000); | ||
509 | |||
510 | kfree (deviceid); | ||
511 | return detected; | ||
512 | } | ||
diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c new file mode 100644 index 000000000000..694bae162fed --- /dev/null +++ b/drivers/parport/ieee1284.c | |||
@@ -0,0 +1,819 @@ | |||
1 | /* $Id: parport_ieee1284.c,v 1.4 1997/10/19 21:37:21 philip Exp $ | ||
2 | * IEEE-1284 implementation for parport. | ||
3 | * | ||
4 | * Authors: Phil Blundell <philb@gnu.org> | ||
5 | * Carsten Gross <carsten@sol.wohnheim.uni-ulm.de> | ||
6 | * Jose Renau <renau@acm.org> | ||
7 | * Tim Waugh <tim@cyberelk.demon.co.uk> (largely rewritten) | ||
8 | * | ||
9 | * This file is responsible for IEEE 1284 negotiation, and for handing | ||
10 | * read/write requests to low-level drivers. | ||
11 | * | ||
12 | * Any part of this program may be used in documents licensed under | ||
13 | * the GNU Free Documentation License, Version 1.1 or any later version | ||
14 | * published by the Free Software Foundation. | ||
15 | * | ||
16 | * Various hacks, Fred Barnes <frmb2@ukc.ac.uk>, 04/2000 | ||
17 | */ | ||
18 | |||
19 | #include <linux/config.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/threads.h> | ||
22 | #include <linux/parport.h> | ||
23 | #include <linux/delay.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/interrupt.h> | ||
26 | #include <linux/timer.h> | ||
27 | #include <linux/sched.h> | ||
28 | |||
29 | #undef DEBUG /* undef me for production */ | ||
30 | |||
31 | #ifdef CONFIG_LP_CONSOLE | ||
32 | #undef DEBUG /* Don't want a garbled console */ | ||
33 | #endif | ||
34 | |||
35 | #ifdef DEBUG | ||
36 | #define DPRINTK(stuff...) printk (stuff) | ||
37 | #else | ||
38 | #define DPRINTK(stuff...) | ||
39 | #endif | ||
40 | |||
41 | /* Make parport_wait_peripheral wake up. | ||
42 | * It will be useful to call this from an interrupt handler. */ | ||
43 | static void parport_ieee1284_wakeup (struct parport *port) | ||
44 | { | ||
45 | up (&port->physport->ieee1284.irq); | ||
46 | } | ||
47 | |||
48 | static struct parport *port_from_cookie[PARPORT_MAX]; | ||
49 | static void timeout_waiting_on_port (unsigned long cookie) | ||
50 | { | ||
51 | parport_ieee1284_wakeup (port_from_cookie[cookie % PARPORT_MAX]); | ||
52 | } | ||
53 | |||
54 | /** | ||
55 | * parport_wait_event - wait for an event on a parallel port | ||
56 | * @port: port to wait on | ||
57 | * @timeout: time to wait (in jiffies) | ||
58 | * | ||
59 | * This function waits for up to @timeout jiffies for an | ||
60 | * interrupt to occur on a parallel port. If the port timeout is | ||
61 | * set to zero, it returns immediately. | ||
62 | * | ||
63 | * If an interrupt occurs before the timeout period elapses, this | ||
64 | * function returns one immediately. If it times out, it returns | ||
65 | * a value greater than zero. An error code less than zero | ||
66 | * indicates an error (most likely a pending signal), and the | ||
67 | * calling code should finish what it's doing as soon as it can. | ||
68 | */ | ||
69 | |||
70 | int parport_wait_event (struct parport *port, signed long timeout) | ||
71 | { | ||
72 | int ret; | ||
73 | struct timer_list timer; | ||
74 | |||
75 | if (!port->physport->cad->timeout) | ||
76 | /* Zero timeout is special, and we can't down() the | ||
77 | semaphore. */ | ||
78 | return 1; | ||
79 | |||
80 | init_timer (&timer); | ||
81 | timer.expires = jiffies + timeout; | ||
82 | timer.function = timeout_waiting_on_port; | ||
83 | port_from_cookie[port->number % PARPORT_MAX] = port; | ||
84 | timer.data = port->number; | ||
85 | |||
86 | add_timer (&timer); | ||
87 | ret = down_interruptible (&port->physport->ieee1284.irq); | ||
88 | if (!del_timer (&timer) && !ret) | ||
89 | /* Timed out. */ | ||
90 | ret = 1; | ||
91 | |||
92 | return ret; | ||
93 | } | ||
94 | |||
95 | /** | ||
96 | * parport_poll_peripheral - poll status lines | ||
97 | * @port: port to watch | ||
98 | * @mask: status lines to watch | ||
99 | * @result: desired values of chosen status lines | ||
100 | * @usec: timeout | ||
101 | * | ||
102 | * This function busy-waits until the masked status lines have | ||
103 | * the desired values, or until the timeout period elapses. The | ||
104 | * @mask and @result parameters are bitmasks, with the bits | ||
105 | * defined by the constants in parport.h: %PARPORT_STATUS_BUSY, | ||
106 | * and so on. | ||
107 | * | ||
108 | * This function does not call schedule(); instead it busy-waits | ||
109 | * using udelay(). It currently has a resolution of 5usec. | ||
110 | * | ||
111 | * If the status lines take on the desired values before the | ||
112 | * timeout period elapses, parport_poll_peripheral() returns zero | ||
113 | * immediately. A zero return value greater than zero indicates | ||
114 | * a timeout. An error code (less than zero) indicates an error, | ||
115 | * most likely a signal that arrived, and the caller should | ||
116 | * finish what it is doing as soon as possible. | ||
117 | */ | ||
118 | |||
119 | int parport_poll_peripheral(struct parport *port, | ||
120 | unsigned char mask, | ||
121 | unsigned char result, | ||
122 | int usec) | ||
123 | { | ||
124 | /* Zero return code is success, >0 is timeout. */ | ||
125 | int count = usec / 5 + 2; | ||
126 | int i; | ||
127 | unsigned char status; | ||
128 | for (i = 0; i < count; i++) { | ||
129 | status = parport_read_status (port); | ||
130 | if ((status & mask) == result) | ||
131 | return 0; | ||
132 | if (signal_pending (current)) | ||
133 | return -EINTR; | ||
134 | if (need_resched()) | ||
135 | break; | ||
136 | if (i >= 2) | ||
137 | udelay (5); | ||
138 | } | ||
139 | |||
140 | return 1; | ||
141 | } | ||
142 | |||
143 | /** | ||
144 | * parport_wait_peripheral - wait for status lines to change in 35ms | ||
145 | * @port: port to watch | ||
146 | * @mask: status lines to watch | ||
147 | * @result: desired values of chosen status lines | ||
148 | * | ||
149 | * This function waits until the masked status lines have the | ||
150 | * desired values, or until 35ms have elapsed (see IEEE 1284-1994 | ||
151 | * page 24 to 25 for why this value in particular is hardcoded). | ||
152 | * The @mask and @result parameters are bitmasks, with the bits | ||
153 | * defined by the constants in parport.h: %PARPORT_STATUS_BUSY, | ||
154 | * and so on. | ||
155 | * | ||
156 | * The port is polled quickly to start off with, in anticipation | ||
157 | * of a fast response from the peripheral. This fast polling | ||
158 | * time is configurable (using /proc), and defaults to 500usec. | ||
159 | * If the timeout for this port (see parport_set_timeout()) is | ||
160 | * zero, the fast polling time is 35ms, and this function does | ||
161 | * not call schedule(). | ||
162 | * | ||
163 | * If the timeout for this port is non-zero, after the fast | ||
164 | * polling fails it uses parport_wait_event() to wait for up to | ||
165 | * 10ms, waking up if an interrupt occurs. | ||
166 | */ | ||
167 | |||
168 | int parport_wait_peripheral(struct parport *port, | ||
169 | unsigned char mask, | ||
170 | unsigned char result) | ||
171 | { | ||
172 | int ret; | ||
173 | int usec; | ||
174 | unsigned long deadline; | ||
175 | unsigned char status; | ||
176 | |||
177 | usec = port->physport->spintime; /* usecs of fast polling */ | ||
178 | if (!port->physport->cad->timeout) | ||
179 | /* A zero timeout is "special": busy wait for the | ||
180 | entire 35ms. */ | ||
181 | usec = 35000; | ||
182 | |||
183 | /* Fast polling. | ||
184 | * | ||
185 | * This should be adjustable. | ||
186 | * How about making a note (in the device structure) of how long | ||
187 | * it takes, so we know for next time? | ||
188 | */ | ||
189 | ret = parport_poll_peripheral (port, mask, result, usec); | ||
190 | if (ret != 1) | ||
191 | return ret; | ||
192 | |||
193 | if (!port->physport->cad->timeout) | ||
194 | /* We may be in an interrupt handler, so we can't poll | ||
195 | * slowly anyway. */ | ||
196 | return 1; | ||
197 | |||
198 | /* 40ms of slow polling. */ | ||
199 | deadline = jiffies + (HZ + 24) / 25; | ||
200 | while (time_before (jiffies, deadline)) { | ||
201 | int ret; | ||
202 | |||
203 | if (signal_pending (current)) | ||
204 | return -EINTR; | ||
205 | |||
206 | /* Wait for 10ms (or until an interrupt occurs if | ||
207 | * the handler is set) */ | ||
208 | if ((ret = parport_wait_event (port, (HZ + 99) / 100)) < 0) | ||
209 | return ret; | ||
210 | |||
211 | status = parport_read_status (port); | ||
212 | if ((status & mask) == result) | ||
213 | return 0; | ||
214 | |||
215 | if (!ret) { | ||
216 | /* parport_wait_event didn't time out, but the | ||
217 | * peripheral wasn't actually ready either. | ||
218 | * Wait for another 10ms. */ | ||
219 | __set_current_state (TASK_INTERRUPTIBLE); | ||
220 | schedule_timeout ((HZ+ 99) / 100); | ||
221 | } | ||
222 | } | ||
223 | |||
224 | return 1; | ||
225 | } | ||
226 | |||
227 | #ifdef CONFIG_PARPORT_1284 | ||
228 | /* Terminate a negotiated mode. */ | ||
229 | static void parport_ieee1284_terminate (struct parport *port) | ||
230 | { | ||
231 | int r; | ||
232 | port = port->physport; | ||
233 | |||
234 | /* EPP terminates differently. */ | ||
235 | switch (port->ieee1284.mode) { | ||
236 | case IEEE1284_MODE_EPP: | ||
237 | case IEEE1284_MODE_EPPSL: | ||
238 | case IEEE1284_MODE_EPPSWE: | ||
239 | /* Terminate from EPP mode. */ | ||
240 | |||
241 | /* Event 68: Set nInit low */ | ||
242 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
243 | udelay (50); | ||
244 | |||
245 | /* Event 69: Set nInit high, nSelectIn low */ | ||
246 | parport_frob_control (port, | ||
247 | PARPORT_CONTROL_SELECT | ||
248 | | PARPORT_CONTROL_INIT, | ||
249 | PARPORT_CONTROL_SELECT | ||
250 | | PARPORT_CONTROL_INIT); | ||
251 | break; | ||
252 | |||
253 | case IEEE1284_MODE_ECP: | ||
254 | case IEEE1284_MODE_ECPRLE: | ||
255 | case IEEE1284_MODE_ECPSWE: | ||
256 | /* In ECP we can only terminate from fwd idle phase. */ | ||
257 | if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { | ||
258 | /* Event 47: Set nInit high */ | ||
259 | parport_frob_control (port, | ||
260 | PARPORT_CONTROL_INIT | ||
261 | | PARPORT_CONTROL_AUTOFD, | ||
262 | PARPORT_CONTROL_INIT | ||
263 | | PARPORT_CONTROL_AUTOFD); | ||
264 | |||
265 | /* Event 49: PError goes high */ | ||
266 | r = parport_wait_peripheral (port, | ||
267 | PARPORT_STATUS_PAPEROUT, | ||
268 | PARPORT_STATUS_PAPEROUT); | ||
269 | if (r) | ||
270 | DPRINTK (KERN_INFO "%s: Timeout at event 49\n", | ||
271 | port->name); | ||
272 | |||
273 | parport_data_forward (port); | ||
274 | DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n", | ||
275 | port->name); | ||
276 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
277 | } | ||
278 | |||
279 | /* fall-though.. */ | ||
280 | |||
281 | default: | ||
282 | /* Terminate from all other modes. */ | ||
283 | |||
284 | /* Event 22: Set nSelectIn low, nAutoFd high */ | ||
285 | parport_frob_control (port, | ||
286 | PARPORT_CONTROL_SELECT | ||
287 | | PARPORT_CONTROL_AUTOFD, | ||
288 | PARPORT_CONTROL_SELECT); | ||
289 | |||
290 | /* Event 24: nAck goes low */ | ||
291 | r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); | ||
292 | if (r) | ||
293 | DPRINTK (KERN_INFO "%s: Timeout at event 24\n", | ||
294 | port->name); | ||
295 | |||
296 | /* Event 25: Set nAutoFd low */ | ||
297 | parport_frob_control (port, | ||
298 | PARPORT_CONTROL_AUTOFD, | ||
299 | PARPORT_CONTROL_AUTOFD); | ||
300 | |||
301 | /* Event 27: nAck goes high */ | ||
302 | r = parport_wait_peripheral (port, | ||
303 | PARPORT_STATUS_ACK, | ||
304 | PARPORT_STATUS_ACK); | ||
305 | if (r) | ||
306 | DPRINTK (KERN_INFO "%s: Timeout at event 27\n", | ||
307 | port->name); | ||
308 | |||
309 | /* Event 29: Set nAutoFd high */ | ||
310 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
311 | } | ||
312 | |||
313 | port->ieee1284.mode = IEEE1284_MODE_COMPAT; | ||
314 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
315 | |||
316 | DPRINTK (KERN_DEBUG "%s: In compatibility (forward idle) mode\n", | ||
317 | port->name); | ||
318 | } | ||
319 | #endif /* IEEE1284 support */ | ||
320 | |||
321 | /** | ||
322 | * parport_negotiate - negotiate an IEEE 1284 mode | ||
323 | * @port: port to use | ||
324 | * @mode: mode to negotiate to | ||
325 | * | ||
326 | * Use this to negotiate to a particular IEEE 1284 transfer mode. | ||
327 | * The @mode parameter should be one of the constants in | ||
328 | * parport.h starting %IEEE1284_MODE_xxx. | ||
329 | * | ||
330 | * The return value is 0 if the peripheral has accepted the | ||
331 | * negotiation to the mode specified, -1 if the peripheral is not | ||
332 | * IEEE 1284 compliant (or not present), or 1 if the peripheral | ||
333 | * has rejected the negotiation. | ||
334 | */ | ||
335 | |||
336 | int parport_negotiate (struct parport *port, int mode) | ||
337 | { | ||
338 | #ifndef CONFIG_PARPORT_1284 | ||
339 | if (mode == IEEE1284_MODE_COMPAT) | ||
340 | return 0; | ||
341 | printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n"); | ||
342 | return -1; | ||
343 | #else | ||
344 | int m = mode & ~IEEE1284_ADDR; | ||
345 | int r; | ||
346 | unsigned char xflag; | ||
347 | |||
348 | port = port->physport; | ||
349 | |||
350 | /* Is there anything to do? */ | ||
351 | if (port->ieee1284.mode == mode) | ||
352 | return 0; | ||
353 | |||
354 | /* Is the difference just an address-or-not bit? */ | ||
355 | if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){ | ||
356 | port->ieee1284.mode = mode; | ||
357 | return 0; | ||
358 | } | ||
359 | |||
360 | /* Go to compability forward idle mode */ | ||
361 | if (port->ieee1284.mode != IEEE1284_MODE_COMPAT) | ||
362 | parport_ieee1284_terminate (port); | ||
363 | |||
364 | if (mode == IEEE1284_MODE_COMPAT) | ||
365 | /* Compatibility mode: no negotiation. */ | ||
366 | return 0; | ||
367 | |||
368 | switch (mode) { | ||
369 | case IEEE1284_MODE_ECPSWE: | ||
370 | m = IEEE1284_MODE_ECP; | ||
371 | break; | ||
372 | case IEEE1284_MODE_EPPSL: | ||
373 | case IEEE1284_MODE_EPPSWE: | ||
374 | m = IEEE1284_MODE_EPP; | ||
375 | break; | ||
376 | case IEEE1284_MODE_BECP: | ||
377 | return -ENOSYS; /* FIXME (implement BECP) */ | ||
378 | } | ||
379 | |||
380 | if (mode & IEEE1284_EXT_LINK) | ||
381 | m = 1<<7; /* request extensibility link */ | ||
382 | |||
383 | port->ieee1284.phase = IEEE1284_PH_NEGOTIATION; | ||
384 | |||
385 | /* Start off with nStrobe and nAutoFd high, and nSelectIn low */ | ||
386 | parport_frob_control (port, | ||
387 | PARPORT_CONTROL_STROBE | ||
388 | | PARPORT_CONTROL_AUTOFD | ||
389 | | PARPORT_CONTROL_SELECT, | ||
390 | PARPORT_CONTROL_SELECT); | ||
391 | udelay(1); | ||
392 | |||
393 | /* Event 0: Set data */ | ||
394 | parport_data_forward (port); | ||
395 | parport_write_data (port, m); | ||
396 | udelay (400); /* Shouldn't need to wait this long. */ | ||
397 | |||
398 | /* Event 1: Set nSelectIn high, nAutoFd low */ | ||
399 | parport_frob_control (port, | ||
400 | PARPORT_CONTROL_SELECT | ||
401 | | PARPORT_CONTROL_AUTOFD, | ||
402 | PARPORT_CONTROL_AUTOFD); | ||
403 | |||
404 | /* Event 2: PError, Select, nFault go high, nAck goes low */ | ||
405 | if (parport_wait_peripheral (port, | ||
406 | PARPORT_STATUS_ERROR | ||
407 | | PARPORT_STATUS_SELECT | ||
408 | | PARPORT_STATUS_PAPEROUT | ||
409 | | PARPORT_STATUS_ACK, | ||
410 | PARPORT_STATUS_ERROR | ||
411 | | PARPORT_STATUS_SELECT | ||
412 | | PARPORT_STATUS_PAPEROUT)) { | ||
413 | /* Timeout */ | ||
414 | parport_frob_control (port, | ||
415 | PARPORT_CONTROL_SELECT | ||
416 | | PARPORT_CONTROL_AUTOFD, | ||
417 | PARPORT_CONTROL_SELECT); | ||
418 | DPRINTK (KERN_DEBUG | ||
419 | "%s: Peripheral not IEEE1284 compliant (0x%02X)\n", | ||
420 | port->name, parport_read_status (port)); | ||
421 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
422 | return -1; /* Not IEEE1284 compliant */ | ||
423 | } | ||
424 | |||
425 | /* Event 3: Set nStrobe low */ | ||
426 | parport_frob_control (port, | ||
427 | PARPORT_CONTROL_STROBE, | ||
428 | PARPORT_CONTROL_STROBE); | ||
429 | |||
430 | /* Event 4: Set nStrobe and nAutoFd high */ | ||
431 | udelay (5); | ||
432 | parport_frob_control (port, | ||
433 | PARPORT_CONTROL_STROBE | ||
434 | | PARPORT_CONTROL_AUTOFD, | ||
435 | 0); | ||
436 | |||
437 | /* Event 6: nAck goes high */ | ||
438 | if (parport_wait_peripheral (port, | ||
439 | PARPORT_STATUS_ACK, | ||
440 | PARPORT_STATUS_ACK)) { | ||
441 | /* This shouldn't really happen with a compliant device. */ | ||
442 | DPRINTK (KERN_DEBUG | ||
443 | "%s: Mode 0x%02x not supported? (0x%02x)\n", | ||
444 | port->name, mode, port->ops->read_status (port)); | ||
445 | parport_ieee1284_terminate (port); | ||
446 | return 1; | ||
447 | } | ||
448 | |||
449 | xflag = parport_read_status (port) & PARPORT_STATUS_SELECT; | ||
450 | |||
451 | /* xflag should be high for all modes other than nibble (0). */ | ||
452 | if (mode && !xflag) { | ||
453 | /* Mode not supported. */ | ||
454 | DPRINTK (KERN_DEBUG "%s: Mode 0x%02x rejected by peripheral\n", | ||
455 | port->name, mode); | ||
456 | parport_ieee1284_terminate (port); | ||
457 | return 1; | ||
458 | } | ||
459 | |||
460 | /* More to do if we've requested extensibility link. */ | ||
461 | if (mode & IEEE1284_EXT_LINK) { | ||
462 | m = mode & 0x7f; | ||
463 | udelay (1); | ||
464 | parport_write_data (port, m); | ||
465 | udelay (1); | ||
466 | |||
467 | /* Event 51: Set nStrobe low */ | ||
468 | parport_frob_control (port, | ||
469 | PARPORT_CONTROL_STROBE, | ||
470 | PARPORT_CONTROL_STROBE); | ||
471 | |||
472 | /* Event 52: nAck goes low */ | ||
473 | if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) { | ||
474 | /* This peripheral is _very_ slow. */ | ||
475 | DPRINTK (KERN_DEBUG | ||
476 | "%s: Event 52 didn't happen\n", | ||
477 | port->name); | ||
478 | parport_ieee1284_terminate (port); | ||
479 | return 1; | ||
480 | } | ||
481 | |||
482 | /* Event 53: Set nStrobe high */ | ||
483 | parport_frob_control (port, | ||
484 | PARPORT_CONTROL_STROBE, | ||
485 | 0); | ||
486 | |||
487 | /* Event 55: nAck goes high */ | ||
488 | if (parport_wait_peripheral (port, | ||
489 | PARPORT_STATUS_ACK, | ||
490 | PARPORT_STATUS_ACK)) { | ||
491 | /* This shouldn't really happen with a compliant | ||
492 | * device. */ | ||
493 | DPRINTK (KERN_DEBUG | ||
494 | "%s: Mode 0x%02x not supported? (0x%02x)\n", | ||
495 | port->name, mode, | ||
496 | port->ops->read_status (port)); | ||
497 | parport_ieee1284_terminate (port); | ||
498 | return 1; | ||
499 | } | ||
500 | |||
501 | /* Event 54: Peripheral sets XFlag to reflect support */ | ||
502 | xflag = parport_read_status (port) & PARPORT_STATUS_SELECT; | ||
503 | |||
504 | /* xflag should be high. */ | ||
505 | if (!xflag) { | ||
506 | /* Extended mode not supported. */ | ||
507 | DPRINTK (KERN_DEBUG "%s: Extended mode 0x%02x not " | ||
508 | "supported\n", port->name, mode); | ||
509 | parport_ieee1284_terminate (port); | ||
510 | return 1; | ||
511 | } | ||
512 | |||
513 | /* Any further setup is left to the caller. */ | ||
514 | } | ||
515 | |||
516 | /* Mode is supported */ | ||
517 | DPRINTK (KERN_DEBUG "%s: In mode 0x%02x\n", port->name, mode); | ||
518 | port->ieee1284.mode = mode; | ||
519 | |||
520 | /* But ECP is special */ | ||
521 | if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) { | ||
522 | port->ieee1284.phase = IEEE1284_PH_ECP_SETUP; | ||
523 | |||
524 | /* Event 30: Set nAutoFd low */ | ||
525 | parport_frob_control (port, | ||
526 | PARPORT_CONTROL_AUTOFD, | ||
527 | PARPORT_CONTROL_AUTOFD); | ||
528 | |||
529 | /* Event 31: PError goes high. */ | ||
530 | r = parport_wait_peripheral (port, | ||
531 | PARPORT_STATUS_PAPEROUT, | ||
532 | PARPORT_STATUS_PAPEROUT); | ||
533 | if (r) { | ||
534 | DPRINTK (KERN_INFO "%s: Timeout at event 31\n", | ||
535 | port->name); | ||
536 | } | ||
537 | |||
538 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
539 | DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n", | ||
540 | port->name); | ||
541 | } else switch (mode) { | ||
542 | case IEEE1284_MODE_NIBBLE: | ||
543 | case IEEE1284_MODE_BYTE: | ||
544 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
545 | break; | ||
546 | default: | ||
547 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
548 | } | ||
549 | |||
550 | |||
551 | return 0; | ||
552 | #endif /* IEEE1284 support */ | ||
553 | } | ||
554 | |||
555 | /* Acknowledge that the peripheral has data available. | ||
556 | * Events 18-20, in order to get from Reverse Idle phase | ||
557 | * to Host Busy Data Available. | ||
558 | * This will most likely be called from an interrupt. | ||
559 | * Returns zero if data was available. | ||
560 | */ | ||
561 | #ifdef CONFIG_PARPORT_1284 | ||
562 | static int parport_ieee1284_ack_data_avail (struct parport *port) | ||
563 | { | ||
564 | if (parport_read_status (port) & PARPORT_STATUS_ERROR) | ||
565 | /* Event 18 didn't happen. */ | ||
566 | return -1; | ||
567 | |||
568 | /* Event 20: nAutoFd goes high. */ | ||
569 | port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
570 | port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; | ||
571 | return 0; | ||
572 | } | ||
573 | #endif /* IEEE1284 support */ | ||
574 | |||
575 | /* Handle an interrupt. */ | ||
576 | void parport_ieee1284_interrupt (int which, void *handle, struct pt_regs *regs) | ||
577 | { | ||
578 | struct parport *port = handle; | ||
579 | parport_ieee1284_wakeup (port); | ||
580 | |||
581 | #ifdef CONFIG_PARPORT_1284 | ||
582 | if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) { | ||
583 | /* An interrupt in this phase means that data | ||
584 | * is now available. */ | ||
585 | DPRINTK (KERN_DEBUG "%s: Data available\n", port->name); | ||
586 | parport_ieee1284_ack_data_avail (port); | ||
587 | } | ||
588 | #endif /* IEEE1284 support */ | ||
589 | } | ||
590 | |||
591 | /** | ||
592 | * parport_write - write a block of data to a parallel port | ||
593 | * @port: port to write to | ||
594 | * @buffer: data buffer (in kernel space) | ||
595 | * @len: number of bytes of data to transfer | ||
596 | * | ||
597 | * This will write up to @len bytes of @buffer to the port | ||
598 | * specified, using the IEEE 1284 transfer mode most recently | ||
599 | * negotiated to (using parport_negotiate()), as long as that | ||
600 | * mode supports forward transfers (host to peripheral). | ||
601 | * | ||
602 | * It is the caller's responsibility to ensure that the first | ||
603 | * @len bytes of @buffer are valid. | ||
604 | * | ||
605 | * This function returns the number of bytes transferred (if zero | ||
606 | * or positive), or else an error code. | ||
607 | */ | ||
608 | |||
609 | ssize_t parport_write (struct parport *port, const void *buffer, size_t len) | ||
610 | { | ||
611 | #ifndef CONFIG_PARPORT_1284 | ||
612 | return port->ops->compat_write_data (port, buffer, len, 0); | ||
613 | #else | ||
614 | ssize_t retval; | ||
615 | int mode = port->ieee1284.mode; | ||
616 | int addr = mode & IEEE1284_ADDR; | ||
617 | size_t (*fn) (struct parport *, const void *, size_t, int); | ||
618 | |||
619 | /* Ignore the device-ID-request bit and the address bit. */ | ||
620 | mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR); | ||
621 | |||
622 | /* Use the mode we're in. */ | ||
623 | switch (mode) { | ||
624 | case IEEE1284_MODE_NIBBLE: | ||
625 | case IEEE1284_MODE_BYTE: | ||
626 | parport_negotiate (port, IEEE1284_MODE_COMPAT); | ||
627 | case IEEE1284_MODE_COMPAT: | ||
628 | DPRINTK (KERN_DEBUG "%s: Using compatibility mode\n", | ||
629 | port->name); | ||
630 | fn = port->ops->compat_write_data; | ||
631 | break; | ||
632 | |||
633 | case IEEE1284_MODE_EPP: | ||
634 | DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name); | ||
635 | if (addr) { | ||
636 | fn = port->ops->epp_write_addr; | ||
637 | } else { | ||
638 | fn = port->ops->epp_write_data; | ||
639 | } | ||
640 | break; | ||
641 | case IEEE1284_MODE_EPPSWE: | ||
642 | DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n", | ||
643 | port->name); | ||
644 | if (addr) { | ||
645 | fn = parport_ieee1284_epp_write_addr; | ||
646 | } else { | ||
647 | fn = parport_ieee1284_epp_write_data; | ||
648 | } | ||
649 | break; | ||
650 | case IEEE1284_MODE_ECP: | ||
651 | case IEEE1284_MODE_ECPRLE: | ||
652 | DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name); | ||
653 | if (addr) { | ||
654 | fn = port->ops->ecp_write_addr; | ||
655 | } else { | ||
656 | fn = port->ops->ecp_write_data; | ||
657 | } | ||
658 | break; | ||
659 | |||
660 | case IEEE1284_MODE_ECPSWE: | ||
661 | DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n", | ||
662 | port->name); | ||
663 | /* The caller has specified that it must be emulated, | ||
664 | * even if we have ECP hardware! */ | ||
665 | if (addr) { | ||
666 | fn = parport_ieee1284_ecp_write_addr; | ||
667 | } else { | ||
668 | fn = parport_ieee1284_ecp_write_data; | ||
669 | } | ||
670 | break; | ||
671 | |||
672 | default: | ||
673 | DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name, | ||
674 | port->ieee1284.mode); | ||
675 | return -ENOSYS; | ||
676 | } | ||
677 | |||
678 | retval = (*fn) (port, buffer, len, 0); | ||
679 | DPRINTK (KERN_DEBUG "%s: wrote %d/%d bytes\n", port->name, retval, len); | ||
680 | return retval; | ||
681 | #endif /* IEEE1284 support */ | ||
682 | } | ||
683 | |||
684 | /** | ||
685 | * parport_read - read a block of data from a parallel port | ||
686 | * @port: port to read from | ||
687 | * @buffer: data buffer (in kernel space) | ||
688 | * @len: number of bytes of data to transfer | ||
689 | * | ||
690 | * This will read up to @len bytes of @buffer to the port | ||
691 | * specified, using the IEEE 1284 transfer mode most recently | ||
692 | * negotiated to (using parport_negotiate()), as long as that | ||
693 | * mode supports reverse transfers (peripheral to host). | ||
694 | * | ||
695 | * It is the caller's responsibility to ensure that the first | ||
696 | * @len bytes of @buffer are available to write to. | ||
697 | * | ||
698 | * This function returns the number of bytes transferred (if zero | ||
699 | * or positive), or else an error code. | ||
700 | */ | ||
701 | |||
702 | ssize_t parport_read (struct parport *port, void *buffer, size_t len) | ||
703 | { | ||
704 | #ifndef CONFIG_PARPORT_1284 | ||
705 | printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n"); | ||
706 | return -ENODEV; | ||
707 | #else | ||
708 | int mode = port->physport->ieee1284.mode; | ||
709 | int addr = mode & IEEE1284_ADDR; | ||
710 | size_t (*fn) (struct parport *, void *, size_t, int); | ||
711 | |||
712 | /* Ignore the device-ID-request bit and the address bit. */ | ||
713 | mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR); | ||
714 | |||
715 | /* Use the mode we're in. */ | ||
716 | switch (mode) { | ||
717 | case IEEE1284_MODE_COMPAT: | ||
718 | /* if we can tri-state use BYTE mode instead of NIBBLE mode, | ||
719 | * if that fails, revert to NIBBLE mode -- ought to store somewhere | ||
720 | * the device's ability to do BYTE mode reverse transfers, so we don't | ||
721 | * end up needlessly calling negotiate(BYTE) repeately.. (fb) | ||
722 | */ | ||
723 | if ((port->physport->modes & PARPORT_MODE_TRISTATE) && | ||
724 | !parport_negotiate (port, IEEE1284_MODE_BYTE)) { | ||
725 | /* got into BYTE mode OK */ | ||
726 | DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name); | ||
727 | fn = port->ops->byte_read_data; | ||
728 | break; | ||
729 | } | ||
730 | if (parport_negotiate (port, IEEE1284_MODE_NIBBLE)) { | ||
731 | return -EIO; | ||
732 | } | ||
733 | /* fall through to NIBBLE */ | ||
734 | case IEEE1284_MODE_NIBBLE: | ||
735 | DPRINTK (KERN_DEBUG "%s: Using nibble mode\n", port->name); | ||
736 | fn = port->ops->nibble_read_data; | ||
737 | break; | ||
738 | |||
739 | case IEEE1284_MODE_BYTE: | ||
740 | DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name); | ||
741 | fn = port->ops->byte_read_data; | ||
742 | break; | ||
743 | |||
744 | case IEEE1284_MODE_EPP: | ||
745 | DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name); | ||
746 | if (addr) { | ||
747 | fn = port->ops->epp_read_addr; | ||
748 | } else { | ||
749 | fn = port->ops->epp_read_data; | ||
750 | } | ||
751 | break; | ||
752 | case IEEE1284_MODE_EPPSWE: | ||
753 | DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n", | ||
754 | port->name); | ||
755 | if (addr) { | ||
756 | fn = parport_ieee1284_epp_read_addr; | ||
757 | } else { | ||
758 | fn = parport_ieee1284_epp_read_data; | ||
759 | } | ||
760 | break; | ||
761 | case IEEE1284_MODE_ECP: | ||
762 | case IEEE1284_MODE_ECPRLE: | ||
763 | DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name); | ||
764 | fn = port->ops->ecp_read_data; | ||
765 | break; | ||
766 | |||
767 | case IEEE1284_MODE_ECPSWE: | ||
768 | DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n", | ||
769 | port->name); | ||
770 | fn = parport_ieee1284_ecp_read_data; | ||
771 | break; | ||
772 | |||
773 | default: | ||
774 | DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name, | ||
775 | port->physport->ieee1284.mode); | ||
776 | return -ENOSYS; | ||
777 | } | ||
778 | |||
779 | return (*fn) (port, buffer, len, 0); | ||
780 | #endif /* IEEE1284 support */ | ||
781 | } | ||
782 | |||
783 | /** | ||
784 | * parport_set_timeout - set the inactivity timeout for a device | ||
785 | * @dev: device on a port | ||
786 | * @inactivity: inactivity timeout (in jiffies) | ||
787 | * | ||
788 | * This sets the inactivity timeout for a particular device on a | ||
789 | * port. This affects functions like parport_wait_peripheral(). | ||
790 | * The special value 0 means not to call schedule() while dealing | ||
791 | * with this device. | ||
792 | * | ||
793 | * The return value is the previous inactivity timeout. | ||
794 | * | ||
795 | * Any callers of parport_wait_event() for this device are woken | ||
796 | * up. | ||
797 | */ | ||
798 | |||
799 | long parport_set_timeout (struct pardevice *dev, long inactivity) | ||
800 | { | ||
801 | long int old = dev->timeout; | ||
802 | |||
803 | dev->timeout = inactivity; | ||
804 | |||
805 | if (dev->port->physport->cad == dev) | ||
806 | parport_ieee1284_wakeup (dev->port); | ||
807 | |||
808 | return old; | ||
809 | } | ||
810 | |||
811 | /* Exported symbols for modules. */ | ||
812 | |||
813 | EXPORT_SYMBOL(parport_negotiate); | ||
814 | EXPORT_SYMBOL(parport_write); | ||
815 | EXPORT_SYMBOL(parport_read); | ||
816 | EXPORT_SYMBOL(parport_wait_peripheral); | ||
817 | EXPORT_SYMBOL(parport_wait_event); | ||
818 | EXPORT_SYMBOL(parport_set_timeout); | ||
819 | EXPORT_SYMBOL(parport_ieee1284_interrupt); | ||
diff --git a/drivers/parport/ieee1284_ops.c b/drivers/parport/ieee1284_ops.c new file mode 100644 index 000000000000..6624278c6ed8 --- /dev/null +++ b/drivers/parport/ieee1284_ops.c | |||
@@ -0,0 +1,921 @@ | |||
1 | /* IEEE-1284 operations for parport. | ||
2 | * | ||
3 | * This file is for generic IEEE 1284 operations. The idea is that | ||
4 | * they are used by the low-level drivers. If they have a special way | ||
5 | * of doing something, they can provide their own routines (and put | ||
6 | * the function pointers in port->ops); if not, they can just use these | ||
7 | * as a fallback. | ||
8 | * | ||
9 | * Note: Make no assumptions about hardware or architecture in this file! | ||
10 | * | ||
11 | * Author: Tim Waugh <tim@cyberelk.demon.co.uk> | ||
12 | * Fixed AUTOFD polarity in ecp_forward_to_reverse(). Fred Barnes, 1999 | ||
13 | * Software emulated EPP fixes, Fred Barnes, 04/2001. | ||
14 | */ | ||
15 | |||
16 | |||
17 | #include <linux/config.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/parport.h> | ||
20 | #include <linux/delay.h> | ||
21 | #include <linux/sched.h> | ||
22 | #include <asm/uaccess.h> | ||
23 | |||
24 | #undef DEBUG /* undef me for production */ | ||
25 | |||
26 | #ifdef CONFIG_LP_CONSOLE | ||
27 | #undef DEBUG /* Don't want a garbled console */ | ||
28 | #endif | ||
29 | |||
30 | #ifdef DEBUG | ||
31 | #define DPRINTK(stuff...) printk (stuff) | ||
32 | #else | ||
33 | #define DPRINTK(stuff...) | ||
34 | #endif | ||
35 | |||
36 | /*** * | ||
37 | * One-way data transfer functions. * | ||
38 | * ***/ | ||
39 | |||
40 | /* Compatibility mode. */ | ||
41 | size_t parport_ieee1284_write_compat (struct parport *port, | ||
42 | const void *buffer, size_t len, | ||
43 | int flags) | ||
44 | { | ||
45 | int no_irq = 1; | ||
46 | ssize_t count = 0; | ||
47 | const unsigned char *addr = buffer; | ||
48 | unsigned char byte; | ||
49 | struct pardevice *dev = port->physport->cad; | ||
50 | unsigned char ctl = (PARPORT_CONTROL_SELECT | ||
51 | | PARPORT_CONTROL_INIT); | ||
52 | |||
53 | if (port->irq != PARPORT_IRQ_NONE) { | ||
54 | parport_enable_irq (port); | ||
55 | no_irq = 0; | ||
56 | } | ||
57 | |||
58 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | ||
59 | parport_write_control (port, ctl); | ||
60 | parport_data_forward (port); | ||
61 | while (count < len) { | ||
62 | unsigned long expire = jiffies + dev->timeout; | ||
63 | long wait = (HZ + 99) / 100; | ||
64 | unsigned char mask = (PARPORT_STATUS_ERROR | ||
65 | | PARPORT_STATUS_BUSY); | ||
66 | unsigned char val = (PARPORT_STATUS_ERROR | ||
67 | | PARPORT_STATUS_BUSY); | ||
68 | |||
69 | /* Wait until the peripheral's ready */ | ||
70 | do { | ||
71 | /* Is the peripheral ready yet? */ | ||
72 | if (!parport_wait_peripheral (port, mask, val)) | ||
73 | /* Skip the loop */ | ||
74 | goto ready; | ||
75 | |||
76 | /* Is the peripheral upset? */ | ||
77 | if ((parport_read_status (port) & | ||
78 | (PARPORT_STATUS_PAPEROUT | | ||
79 | PARPORT_STATUS_SELECT | | ||
80 | PARPORT_STATUS_ERROR)) | ||
81 | != (PARPORT_STATUS_SELECT | | ||
82 | PARPORT_STATUS_ERROR)) | ||
83 | /* If nFault is asserted (i.e. no | ||
84 | * error) and PAPEROUT and SELECT are | ||
85 | * just red herrings, give the driver | ||
86 | * a chance to check it's happy with | ||
87 | * that before continuing. */ | ||
88 | goto stop; | ||
89 | |||
90 | /* Have we run out of time? */ | ||
91 | if (!time_before (jiffies, expire)) | ||
92 | break; | ||
93 | |||
94 | /* Yield the port for a while. If this is the | ||
95 | first time around the loop, don't let go of | ||
96 | the port. This way, we find out if we have | ||
97 | our interrupt handler called. */ | ||
98 | if (count && no_irq) { | ||
99 | parport_release (dev); | ||
100 | __set_current_state (TASK_INTERRUPTIBLE); | ||
101 | schedule_timeout (wait); | ||
102 | parport_claim_or_block (dev); | ||
103 | } | ||
104 | else | ||
105 | /* We must have the device claimed here */ | ||
106 | parport_wait_event (port, wait); | ||
107 | |||
108 | /* Is there a signal pending? */ | ||
109 | if (signal_pending (current)) | ||
110 | break; | ||
111 | |||
112 | /* Wait longer next time. */ | ||
113 | wait *= 2; | ||
114 | } while (time_before (jiffies, expire)); | ||
115 | |||
116 | if (signal_pending (current)) | ||
117 | break; | ||
118 | |||
119 | DPRINTK (KERN_DEBUG "%s: Timed out\n", port->name); | ||
120 | break; | ||
121 | |||
122 | ready: | ||
123 | /* Write the character to the data lines. */ | ||
124 | byte = *addr++; | ||
125 | parport_write_data (port, byte); | ||
126 | udelay (1); | ||
127 | |||
128 | /* Pulse strobe. */ | ||
129 | parport_write_control (port, ctl | PARPORT_CONTROL_STROBE); | ||
130 | udelay (1); /* strobe */ | ||
131 | |||
132 | parport_write_control (port, ctl); | ||
133 | udelay (1); /* hold */ | ||
134 | |||
135 | /* Assume the peripheral received it. */ | ||
136 | count++; | ||
137 | |||
138 | /* Let another process run if it needs to. */ | ||
139 | if (time_before (jiffies, expire)) | ||
140 | if (!parport_yield_blocking (dev) | ||
141 | && need_resched()) | ||
142 | schedule (); | ||
143 | } | ||
144 | stop: | ||
145 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
146 | |||
147 | return count; | ||
148 | } | ||
149 | |||
150 | /* Nibble mode. */ | ||
151 | size_t parport_ieee1284_read_nibble (struct parport *port, | ||
152 | void *buffer, size_t len, | ||
153 | int flags) | ||
154 | { | ||
155 | #ifndef CONFIG_PARPORT_1284 | ||
156 | return 0; | ||
157 | #else | ||
158 | unsigned char *buf = buffer; | ||
159 | int i; | ||
160 | unsigned char byte = 0; | ||
161 | |||
162 | len *= 2; /* in nibbles */ | ||
163 | for (i=0; i < len; i++) { | ||
164 | unsigned char nibble; | ||
165 | |||
166 | /* Does the error line indicate end of data? */ | ||
167 | if (((i & 1) == 0) && | ||
168 | (parport_read_status(port) & PARPORT_STATUS_ERROR)) { | ||
169 | port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; | ||
170 | DPRINTK (KERN_DEBUG | ||
171 | "%s: No more nibble data (%d bytes)\n", | ||
172 | port->name, i/2); | ||
173 | |||
174 | /* Go to reverse idle phase. */ | ||
175 | parport_frob_control (port, | ||
176 | PARPORT_CONTROL_AUTOFD, | ||
177 | PARPORT_CONTROL_AUTOFD); | ||
178 | port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
179 | break; | ||
180 | } | ||
181 | |||
182 | /* Event 7: Set nAutoFd low. */ | ||
183 | parport_frob_control (port, | ||
184 | PARPORT_CONTROL_AUTOFD, | ||
185 | PARPORT_CONTROL_AUTOFD); | ||
186 | |||
187 | /* Event 9: nAck goes low. */ | ||
188 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; | ||
189 | if (parport_wait_peripheral (port, | ||
190 | PARPORT_STATUS_ACK, 0)) { | ||
191 | /* Timeout -- no more data? */ | ||
192 | DPRINTK (KERN_DEBUG | ||
193 | "%s: Nibble timeout at event 9 (%d bytes)\n", | ||
194 | port->name, i/2); | ||
195 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
196 | break; | ||
197 | } | ||
198 | |||
199 | |||
200 | /* Read a nibble. */ | ||
201 | nibble = parport_read_status (port) >> 3; | ||
202 | nibble &= ~8; | ||
203 | if ((nibble & 0x10) == 0) | ||
204 | nibble |= 8; | ||
205 | nibble &= 0xf; | ||
206 | |||
207 | /* Event 10: Set nAutoFd high. */ | ||
208 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
209 | |||
210 | /* Event 11: nAck goes high. */ | ||
211 | if (parport_wait_peripheral (port, | ||
212 | PARPORT_STATUS_ACK, | ||
213 | PARPORT_STATUS_ACK)) { | ||
214 | /* Timeout -- no more data? */ | ||
215 | DPRINTK (KERN_DEBUG | ||
216 | "%s: Nibble timeout at event 11\n", | ||
217 | port->name); | ||
218 | break; | ||
219 | } | ||
220 | |||
221 | if (i & 1) { | ||
222 | /* Second nibble */ | ||
223 | byte |= nibble << 4; | ||
224 | *buf++ = byte; | ||
225 | } else | ||
226 | byte = nibble; | ||
227 | } | ||
228 | |||
229 | i /= 2; /* i is now in bytes */ | ||
230 | |||
231 | if (i == len) { | ||
232 | /* Read the last nibble without checking data avail. */ | ||
233 | port = port->physport; | ||
234 | if (parport_read_status (port) & PARPORT_STATUS_ERROR) | ||
235 | port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; | ||
236 | else | ||
237 | port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; | ||
238 | } | ||
239 | |||
240 | return i; | ||
241 | #endif /* IEEE1284 support */ | ||
242 | } | ||
243 | |||
244 | /* Byte mode. */ | ||
245 | size_t parport_ieee1284_read_byte (struct parport *port, | ||
246 | void *buffer, size_t len, | ||
247 | int flags) | ||
248 | { | ||
249 | #ifndef CONFIG_PARPORT_1284 | ||
250 | return 0; | ||
251 | #else | ||
252 | unsigned char *buf = buffer; | ||
253 | ssize_t count = 0; | ||
254 | |||
255 | for (count = 0; count < len; count++) { | ||
256 | unsigned char byte; | ||
257 | |||
258 | /* Data available? */ | ||
259 | if (parport_read_status (port) & PARPORT_STATUS_ERROR) { | ||
260 | port->physport->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; | ||
261 | DPRINTK (KERN_DEBUG | ||
262 | "%s: No more byte data (%Zd bytes)\n", | ||
263 | port->name, count); | ||
264 | |||
265 | /* Go to reverse idle phase. */ | ||
266 | parport_frob_control (port, | ||
267 | PARPORT_CONTROL_AUTOFD, | ||
268 | PARPORT_CONTROL_AUTOFD); | ||
269 | port->physport->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
270 | break; | ||
271 | } | ||
272 | |||
273 | /* Event 14: Place data bus in high impedance state. */ | ||
274 | parport_data_reverse (port); | ||
275 | |||
276 | /* Event 7: Set nAutoFd low. */ | ||
277 | parport_frob_control (port, | ||
278 | PARPORT_CONTROL_AUTOFD, | ||
279 | PARPORT_CONTROL_AUTOFD); | ||
280 | |||
281 | /* Event 9: nAck goes low. */ | ||
282 | port->physport->ieee1284.phase = IEEE1284_PH_REV_DATA; | ||
283 | if (parport_wait_peripheral (port, | ||
284 | PARPORT_STATUS_ACK, | ||
285 | 0)) { | ||
286 | /* Timeout -- no more data? */ | ||
287 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, | ||
288 | 0); | ||
289 | DPRINTK (KERN_DEBUG "%s: Byte timeout at event 9\n", | ||
290 | port->name); | ||
291 | break; | ||
292 | } | ||
293 | |||
294 | byte = parport_read_data (port); | ||
295 | *buf++ = byte; | ||
296 | |||
297 | /* Event 10: Set nAutoFd high */ | ||
298 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
299 | |||
300 | /* Event 11: nAck goes high. */ | ||
301 | if (parport_wait_peripheral (port, | ||
302 | PARPORT_STATUS_ACK, | ||
303 | PARPORT_STATUS_ACK)) { | ||
304 | /* Timeout -- no more data? */ | ||
305 | DPRINTK (KERN_DEBUG "%s: Byte timeout at event 11\n", | ||
306 | port->name); | ||
307 | break; | ||
308 | } | ||
309 | |||
310 | /* Event 16: Set nStrobe low. */ | ||
311 | parport_frob_control (port, | ||
312 | PARPORT_CONTROL_STROBE, | ||
313 | PARPORT_CONTROL_STROBE); | ||
314 | udelay (5); | ||
315 | |||
316 | /* Event 17: Set nStrobe high. */ | ||
317 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
318 | } | ||
319 | |||
320 | if (count == len) { | ||
321 | /* Read the last byte without checking data avail. */ | ||
322 | port = port->physport; | ||
323 | if (parport_read_status (port) & PARPORT_STATUS_ERROR) | ||
324 | port->ieee1284.phase = IEEE1284_PH_HBUSY_DNA; | ||
325 | else | ||
326 | port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; | ||
327 | } | ||
328 | |||
329 | return count; | ||
330 | #endif /* IEEE1284 support */ | ||
331 | } | ||
332 | |||
333 | /*** * | ||
334 | * ECP Functions. * | ||
335 | * ***/ | ||
336 | |||
337 | #ifdef CONFIG_PARPORT_1284 | ||
338 | |||
339 | static inline | ||
340 | int ecp_forward_to_reverse (struct parport *port) | ||
341 | { | ||
342 | int retval; | ||
343 | |||
344 | /* Event 38: Set nAutoFd low */ | ||
345 | parport_frob_control (port, | ||
346 | PARPORT_CONTROL_AUTOFD, | ||
347 | PARPORT_CONTROL_AUTOFD); | ||
348 | parport_data_reverse (port); | ||
349 | udelay (5); | ||
350 | |||
351 | /* Event 39: Set nInit low to initiate bus reversal */ | ||
352 | parport_frob_control (port, | ||
353 | PARPORT_CONTROL_INIT, | ||
354 | 0); | ||
355 | |||
356 | /* Event 40: PError goes low */ | ||
357 | retval = parport_wait_peripheral (port, | ||
358 | PARPORT_STATUS_PAPEROUT, 0); | ||
359 | |||
360 | if (!retval) { | ||
361 | DPRINTK (KERN_DEBUG "%s: ECP direction: reverse\n", | ||
362 | port->name); | ||
363 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
364 | } else { | ||
365 | DPRINTK (KERN_DEBUG "%s: ECP direction: failed to reverse\n", | ||
366 | port->name); | ||
367 | port->ieee1284.phase = IEEE1284_PH_ECP_DIR_UNKNOWN; | ||
368 | } | ||
369 | |||
370 | return retval; | ||
371 | } | ||
372 | |||
373 | static inline | ||
374 | int ecp_reverse_to_forward (struct parport *port) | ||
375 | { | ||
376 | int retval; | ||
377 | |||
378 | /* Event 47: Set nInit high */ | ||
379 | parport_frob_control (port, | ||
380 | PARPORT_CONTROL_INIT | ||
381 | | PARPORT_CONTROL_AUTOFD, | ||
382 | PARPORT_CONTROL_INIT | ||
383 | | PARPORT_CONTROL_AUTOFD); | ||
384 | |||
385 | /* Event 49: PError goes high */ | ||
386 | retval = parport_wait_peripheral (port, | ||
387 | PARPORT_STATUS_PAPEROUT, | ||
388 | PARPORT_STATUS_PAPEROUT); | ||
389 | |||
390 | if (!retval) { | ||
391 | parport_data_forward (port); | ||
392 | DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n", | ||
393 | port->name); | ||
394 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
395 | } else { | ||
396 | DPRINTK (KERN_DEBUG | ||
397 | "%s: ECP direction: failed to switch forward\n", | ||
398 | port->name); | ||
399 | port->ieee1284.phase = IEEE1284_PH_ECP_DIR_UNKNOWN; | ||
400 | } | ||
401 | |||
402 | |||
403 | return retval; | ||
404 | } | ||
405 | |||
406 | #endif /* IEEE1284 support */ | ||
407 | |||
408 | /* ECP mode, forward channel, data. */ | ||
409 | size_t parport_ieee1284_ecp_write_data (struct parport *port, | ||
410 | const void *buffer, size_t len, | ||
411 | int flags) | ||
412 | { | ||
413 | #ifndef CONFIG_PARPORT_1284 | ||
414 | return 0; | ||
415 | #else | ||
416 | const unsigned char *buf = buffer; | ||
417 | size_t written; | ||
418 | int retry; | ||
419 | |||
420 | port = port->physport; | ||
421 | |||
422 | if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) | ||
423 | if (ecp_reverse_to_forward (port)) | ||
424 | return 0; | ||
425 | |||
426 | port->ieee1284.phase = IEEE1284_PH_FWD_DATA; | ||
427 | |||
428 | /* HostAck high (data, not command) */ | ||
429 | parport_frob_control (port, | ||
430 | PARPORT_CONTROL_AUTOFD | ||
431 | | PARPORT_CONTROL_STROBE | ||
432 | | PARPORT_CONTROL_INIT, | ||
433 | PARPORT_CONTROL_INIT); | ||
434 | for (written = 0; written < len; written++, buf++) { | ||
435 | unsigned long expire = jiffies + port->cad->timeout; | ||
436 | unsigned char byte; | ||
437 | |||
438 | byte = *buf; | ||
439 | try_again: | ||
440 | parport_write_data (port, byte); | ||
441 | parport_frob_control (port, PARPORT_CONTROL_STROBE, | ||
442 | PARPORT_CONTROL_STROBE); | ||
443 | udelay (5); | ||
444 | for (retry = 0; retry < 100; retry++) { | ||
445 | if (!parport_wait_peripheral (port, | ||
446 | PARPORT_STATUS_BUSY, 0)) | ||
447 | goto success; | ||
448 | |||
449 | if (signal_pending (current)) { | ||
450 | parport_frob_control (port, | ||
451 | PARPORT_CONTROL_STROBE, | ||
452 | 0); | ||
453 | break; | ||
454 | } | ||
455 | } | ||
456 | |||
457 | /* Time for Host Transfer Recovery (page 41 of IEEE1284) */ | ||
458 | DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name); | ||
459 | |||
460 | parport_frob_control (port, PARPORT_CONTROL_INIT, | ||
461 | PARPORT_CONTROL_INIT); | ||
462 | udelay (50); | ||
463 | if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) { | ||
464 | /* It's buggered. */ | ||
465 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
466 | break; | ||
467 | } | ||
468 | |||
469 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
470 | udelay (50); | ||
471 | if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT)) | ||
472 | break; | ||
473 | |||
474 | DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n", | ||
475 | port->name); | ||
476 | |||
477 | if (time_after_eq (jiffies, expire)) break; | ||
478 | goto try_again; | ||
479 | success: | ||
480 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
481 | udelay (5); | ||
482 | if (parport_wait_peripheral (port, | ||
483 | PARPORT_STATUS_BUSY, | ||
484 | PARPORT_STATUS_BUSY)) | ||
485 | /* Peripheral hasn't accepted the data. */ | ||
486 | break; | ||
487 | } | ||
488 | |||
489 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
490 | |||
491 | return written; | ||
492 | #endif /* IEEE1284 support */ | ||
493 | } | ||
494 | |||
495 | /* ECP mode, reverse channel, data. */ | ||
496 | size_t parport_ieee1284_ecp_read_data (struct parport *port, | ||
497 | void *buffer, size_t len, int flags) | ||
498 | { | ||
499 | #ifndef CONFIG_PARPORT_1284 | ||
500 | return 0; | ||
501 | #else | ||
502 | struct pardevice *dev = port->cad; | ||
503 | unsigned char *buf = buffer; | ||
504 | int rle_count = 0; /* shut gcc up */ | ||
505 | unsigned char ctl; | ||
506 | int rle = 0; | ||
507 | ssize_t count = 0; | ||
508 | |||
509 | port = port->physport; | ||
510 | |||
511 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) | ||
512 | if (ecp_forward_to_reverse (port)) | ||
513 | return 0; | ||
514 | |||
515 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; | ||
516 | |||
517 | /* Set HostAck low to start accepting data. */ | ||
518 | ctl = parport_read_control (port); | ||
519 | ctl &= ~(PARPORT_CONTROL_STROBE | PARPORT_CONTROL_INIT | | ||
520 | PARPORT_CONTROL_AUTOFD); | ||
521 | parport_write_control (port, | ||
522 | ctl | PARPORT_CONTROL_AUTOFD); | ||
523 | while (count < len) { | ||
524 | unsigned long expire = jiffies + dev->timeout; | ||
525 | unsigned char byte; | ||
526 | int command; | ||
527 | |||
528 | /* Event 43: Peripheral sets nAck low. It can take as | ||
529 | long as it wants. */ | ||
530 | while (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) { | ||
531 | /* The peripheral hasn't given us data in | ||
532 | 35ms. If we have data to give back to the | ||
533 | caller, do it now. */ | ||
534 | if (count) | ||
535 | goto out; | ||
536 | |||
537 | /* If we've used up all the time we were allowed, | ||
538 | give up altogether. */ | ||
539 | if (!time_before (jiffies, expire)) | ||
540 | goto out; | ||
541 | |||
542 | /* Yield the port for a while. */ | ||
543 | if (count && dev->port->irq != PARPORT_IRQ_NONE) { | ||
544 | parport_release (dev); | ||
545 | __set_current_state (TASK_INTERRUPTIBLE); | ||
546 | schedule_timeout ((HZ + 24) / 25); | ||
547 | parport_claim_or_block (dev); | ||
548 | } | ||
549 | else | ||
550 | /* We must have the device claimed here. */ | ||
551 | parport_wait_event (port, (HZ + 24) / 25); | ||
552 | |||
553 | /* Is there a signal pending? */ | ||
554 | if (signal_pending (current)) | ||
555 | goto out; | ||
556 | } | ||
557 | |||
558 | /* Is this a command? */ | ||
559 | if (rle) | ||
560 | /* The last byte was a run-length count, so | ||
561 | this can't be as well. */ | ||
562 | command = 0; | ||
563 | else | ||
564 | command = (parport_read_status (port) & | ||
565 | PARPORT_STATUS_BUSY) ? 1 : 0; | ||
566 | |||
567 | /* Read the data. */ | ||
568 | byte = parport_read_data (port); | ||
569 | |||
570 | /* If this is a channel command, rather than an RLE | ||
571 | command or a normal data byte, don't accept it. */ | ||
572 | if (command) { | ||
573 | if (byte & 0x80) { | ||
574 | DPRINTK (KERN_DEBUG "%s: stopping short at " | ||
575 | "channel command (%02x)\n", | ||
576 | port->name, byte); | ||
577 | goto out; | ||
578 | } | ||
579 | else if (port->ieee1284.mode != IEEE1284_MODE_ECPRLE) | ||
580 | DPRINTK (KERN_DEBUG "%s: device illegally " | ||
581 | "using RLE; accepting anyway\n", | ||
582 | port->name); | ||
583 | |||
584 | rle_count = byte + 1; | ||
585 | |||
586 | /* Are we allowed to read that many bytes? */ | ||
587 | if (rle_count > (len - count)) { | ||
588 | DPRINTK (KERN_DEBUG "%s: leaving %d RLE bytes " | ||
589 | "for next time\n", port->name, | ||
590 | rle_count); | ||
591 | break; | ||
592 | } | ||
593 | |||
594 | rle = 1; | ||
595 | } | ||
596 | |||
597 | /* Event 44: Set HostAck high, acknowledging handshake. */ | ||
598 | parport_write_control (port, ctl); | ||
599 | |||
600 | /* Event 45: The peripheral has 35ms to set nAck high. */ | ||
601 | if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, | ||
602 | PARPORT_STATUS_ACK)) { | ||
603 | /* It's gone wrong. Return what data we have | ||
604 | to the caller. */ | ||
605 | DPRINTK (KERN_DEBUG "ECP read timed out at 45\n"); | ||
606 | |||
607 | if (command) | ||
608 | printk (KERN_WARNING | ||
609 | "%s: command ignored (%02x)\n", | ||
610 | port->name, byte); | ||
611 | |||
612 | break; | ||
613 | } | ||
614 | |||
615 | /* Event 46: Set HostAck low and accept the data. */ | ||
616 | parport_write_control (port, | ||
617 | ctl | PARPORT_CONTROL_AUTOFD); | ||
618 | |||
619 | /* If we just read a run-length count, fetch the data. */ | ||
620 | if (command) | ||
621 | continue; | ||
622 | |||
623 | /* If this is the byte after a run-length count, decompress. */ | ||
624 | if (rle) { | ||
625 | rle = 0; | ||
626 | memset (buf, byte, rle_count); | ||
627 | buf += rle_count; | ||
628 | count += rle_count; | ||
629 | DPRINTK (KERN_DEBUG "%s: decompressed to %d bytes\n", | ||
630 | port->name, rle_count); | ||
631 | } else { | ||
632 | /* Normal data byte. */ | ||
633 | *buf = byte; | ||
634 | buf++, count++; | ||
635 | } | ||
636 | } | ||
637 | |||
638 | out: | ||
639 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
640 | return count; | ||
641 | #endif /* IEEE1284 support */ | ||
642 | } | ||
643 | |||
644 | /* ECP mode, forward channel, commands. */ | ||
645 | size_t parport_ieee1284_ecp_write_addr (struct parport *port, | ||
646 | const void *buffer, size_t len, | ||
647 | int flags) | ||
648 | { | ||
649 | #ifndef CONFIG_PARPORT_1284 | ||
650 | return 0; | ||
651 | #else | ||
652 | const unsigned char *buf = buffer; | ||
653 | size_t written; | ||
654 | int retry; | ||
655 | |||
656 | port = port->physport; | ||
657 | |||
658 | if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) | ||
659 | if (ecp_reverse_to_forward (port)) | ||
660 | return 0; | ||
661 | |||
662 | port->ieee1284.phase = IEEE1284_PH_FWD_DATA; | ||
663 | |||
664 | /* HostAck low (command, not data) */ | ||
665 | parport_frob_control (port, | ||
666 | PARPORT_CONTROL_AUTOFD | ||
667 | | PARPORT_CONTROL_STROBE | ||
668 | | PARPORT_CONTROL_INIT, | ||
669 | PARPORT_CONTROL_AUTOFD | ||
670 | | PARPORT_CONTROL_INIT); | ||
671 | for (written = 0; written < len; written++, buf++) { | ||
672 | unsigned long expire = jiffies + port->cad->timeout; | ||
673 | unsigned char byte; | ||
674 | |||
675 | byte = *buf; | ||
676 | try_again: | ||
677 | parport_write_data (port, byte); | ||
678 | parport_frob_control (port, PARPORT_CONTROL_STROBE, | ||
679 | PARPORT_CONTROL_STROBE); | ||
680 | udelay (5); | ||
681 | for (retry = 0; retry < 100; retry++) { | ||
682 | if (!parport_wait_peripheral (port, | ||
683 | PARPORT_STATUS_BUSY, 0)) | ||
684 | goto success; | ||
685 | |||
686 | if (signal_pending (current)) { | ||
687 | parport_frob_control (port, | ||
688 | PARPORT_CONTROL_STROBE, | ||
689 | 0); | ||
690 | break; | ||
691 | } | ||
692 | } | ||
693 | |||
694 | /* Time for Host Transfer Recovery (page 41 of IEEE1284) */ | ||
695 | DPRINTK (KERN_DEBUG "%s: ECP transfer stalled!\n", port->name); | ||
696 | |||
697 | parport_frob_control (port, PARPORT_CONTROL_INIT, | ||
698 | PARPORT_CONTROL_INIT); | ||
699 | udelay (50); | ||
700 | if (parport_read_status (port) & PARPORT_STATUS_PAPEROUT) { | ||
701 | /* It's buggered. */ | ||
702 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
703 | break; | ||
704 | } | ||
705 | |||
706 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
707 | udelay (50); | ||
708 | if (!(parport_read_status (port) & PARPORT_STATUS_PAPEROUT)) | ||
709 | break; | ||
710 | |||
711 | DPRINTK (KERN_DEBUG "%s: Host transfer recovered\n", | ||
712 | port->name); | ||
713 | |||
714 | if (time_after_eq (jiffies, expire)) break; | ||
715 | goto try_again; | ||
716 | success: | ||
717 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
718 | udelay (5); | ||
719 | if (parport_wait_peripheral (port, | ||
720 | PARPORT_STATUS_BUSY, | ||
721 | PARPORT_STATUS_BUSY)) | ||
722 | /* Peripheral hasn't accepted the data. */ | ||
723 | break; | ||
724 | } | ||
725 | |||
726 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
727 | |||
728 | return written; | ||
729 | #endif /* IEEE1284 support */ | ||
730 | } | ||
731 | |||
732 | /*** * | ||
733 | * EPP functions. * | ||
734 | * ***/ | ||
735 | |||
736 | /* EPP mode, forward channel, data. */ | ||
737 | size_t parport_ieee1284_epp_write_data (struct parport *port, | ||
738 | const void *buffer, size_t len, | ||
739 | int flags) | ||
740 | { | ||
741 | unsigned char *bp = (unsigned char *) buffer; | ||
742 | size_t ret = 0; | ||
743 | |||
744 | /* set EPP idle state (just to make sure) with strobe low */ | ||
745 | parport_frob_control (port, | ||
746 | PARPORT_CONTROL_STROBE | | ||
747 | PARPORT_CONTROL_AUTOFD | | ||
748 | PARPORT_CONTROL_SELECT | | ||
749 | PARPORT_CONTROL_INIT, | ||
750 | PARPORT_CONTROL_STROBE | | ||
751 | PARPORT_CONTROL_INIT); | ||
752 | port->ops->data_forward (port); | ||
753 | for (; len > 0; len--, bp++) { | ||
754 | /* Event 62: Write data and set autofd low */ | ||
755 | parport_write_data (port, *bp); | ||
756 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, | ||
757 | PARPORT_CONTROL_AUTOFD); | ||
758 | |||
759 | /* Event 58: wait for busy (nWait) to go high */ | ||
760 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10)) | ||
761 | break; | ||
762 | |||
763 | /* Event 63: set nAutoFd (nDStrb) high */ | ||
764 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
765 | |||
766 | /* Event 60: wait for busy (nWait) to go low */ | ||
767 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, | ||
768 | PARPORT_STATUS_BUSY, 5)) | ||
769 | break; | ||
770 | |||
771 | ret++; | ||
772 | } | ||
773 | |||
774 | /* Event 61: set strobe (nWrite) high */ | ||
775 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
776 | |||
777 | return ret; | ||
778 | } | ||
779 | |||
780 | /* EPP mode, reverse channel, data. */ | ||
781 | size_t parport_ieee1284_epp_read_data (struct parport *port, | ||
782 | void *buffer, size_t len, | ||
783 | int flags) | ||
784 | { | ||
785 | unsigned char *bp = (unsigned char *) buffer; | ||
786 | unsigned ret = 0; | ||
787 | |||
788 | /* set EPP idle state (just to make sure) with strobe high */ | ||
789 | parport_frob_control (port, | ||
790 | PARPORT_CONTROL_STROBE | | ||
791 | PARPORT_CONTROL_AUTOFD | | ||
792 | PARPORT_CONTROL_SELECT | | ||
793 | PARPORT_CONTROL_INIT, | ||
794 | PARPORT_CONTROL_INIT); | ||
795 | port->ops->data_reverse (port); | ||
796 | for (; len > 0; len--, bp++) { | ||
797 | /* Event 67: set nAutoFd (nDStrb) low */ | ||
798 | parport_frob_control (port, | ||
799 | PARPORT_CONTROL_AUTOFD, | ||
800 | PARPORT_CONTROL_AUTOFD); | ||
801 | /* Event 58: wait for Busy to go high */ | ||
802 | if (parport_wait_peripheral (port, PARPORT_STATUS_BUSY, 0)) { | ||
803 | break; | ||
804 | } | ||
805 | |||
806 | *bp = parport_read_data (port); | ||
807 | |||
808 | /* Event 63: set nAutoFd (nDStrb) high */ | ||
809 | parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); | ||
810 | |||
811 | /* Event 60: wait for Busy to go low */ | ||
812 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, | ||
813 | PARPORT_STATUS_BUSY, 5)) { | ||
814 | break; | ||
815 | } | ||
816 | |||
817 | ret++; | ||
818 | } | ||
819 | port->ops->data_forward (port); | ||
820 | |||
821 | return ret; | ||
822 | } | ||
823 | |||
824 | /* EPP mode, forward channel, addresses. */ | ||
825 | size_t parport_ieee1284_epp_write_addr (struct parport *port, | ||
826 | const void *buffer, size_t len, | ||
827 | int flags) | ||
828 | { | ||
829 | unsigned char *bp = (unsigned char *) buffer; | ||
830 | size_t ret = 0; | ||
831 | |||
832 | /* set EPP idle state (just to make sure) with strobe low */ | ||
833 | parport_frob_control (port, | ||
834 | PARPORT_CONTROL_STROBE | | ||
835 | PARPORT_CONTROL_AUTOFD | | ||
836 | PARPORT_CONTROL_SELECT | | ||
837 | PARPORT_CONTROL_INIT, | ||
838 | PARPORT_CONTROL_STROBE | | ||
839 | PARPORT_CONTROL_INIT); | ||
840 | port->ops->data_forward (port); | ||
841 | for (; len > 0; len--, bp++) { | ||
842 | /* Event 56: Write data and set nAStrb low. */ | ||
843 | parport_write_data (port, *bp); | ||
844 | parport_frob_control (port, PARPORT_CONTROL_SELECT, | ||
845 | PARPORT_CONTROL_SELECT); | ||
846 | |||
847 | /* Event 58: wait for busy (nWait) to go high */ | ||
848 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, 0, 10)) | ||
849 | break; | ||
850 | |||
851 | /* Event 59: set nAStrb high */ | ||
852 | parport_frob_control (port, PARPORT_CONTROL_SELECT, 0); | ||
853 | |||
854 | /* Event 60: wait for busy (nWait) to go low */ | ||
855 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, | ||
856 | PARPORT_STATUS_BUSY, 5)) | ||
857 | break; | ||
858 | |||
859 | ret++; | ||
860 | } | ||
861 | |||
862 | /* Event 61: set strobe (nWrite) high */ | ||
863 | parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
864 | |||
865 | return ret; | ||
866 | } | ||
867 | |||
868 | /* EPP mode, reverse channel, addresses. */ | ||
869 | size_t parport_ieee1284_epp_read_addr (struct parport *port, | ||
870 | void *buffer, size_t len, | ||
871 | int flags) | ||
872 | { | ||
873 | unsigned char *bp = (unsigned char *) buffer; | ||
874 | unsigned ret = 0; | ||
875 | |||
876 | /* Set EPP idle state (just to make sure) with strobe high */ | ||
877 | parport_frob_control (port, | ||
878 | PARPORT_CONTROL_STROBE | | ||
879 | PARPORT_CONTROL_AUTOFD | | ||
880 | PARPORT_CONTROL_SELECT | | ||
881 | PARPORT_CONTROL_INIT, | ||
882 | PARPORT_CONTROL_INIT); | ||
883 | port->ops->data_reverse (port); | ||
884 | for (; len > 0; len--, bp++) { | ||
885 | /* Event 64: set nSelectIn (nAStrb) low */ | ||
886 | parport_frob_control (port, PARPORT_CONTROL_SELECT, | ||
887 | PARPORT_CONTROL_SELECT); | ||
888 | |||
889 | /* Event 58: wait for Busy to go high */ | ||
890 | if (parport_wait_peripheral (port, PARPORT_STATUS_BUSY, 0)) { | ||
891 | break; | ||
892 | } | ||
893 | |||
894 | *bp = parport_read_data (port); | ||
895 | |||
896 | /* Event 59: set nSelectIn (nAStrb) high */ | ||
897 | parport_frob_control (port, PARPORT_CONTROL_SELECT, | ||
898 | PARPORT_CONTROL_SELECT); | ||
899 | |||
900 | /* Event 60: wait for Busy to go low */ | ||
901 | if (parport_poll_peripheral (port, PARPORT_STATUS_BUSY, | ||
902 | PARPORT_STATUS_BUSY, 5)) | ||
903 | break; | ||
904 | |||
905 | ret++; | ||
906 | } | ||
907 | port->ops->data_forward (port); | ||
908 | |||
909 | return ret; | ||
910 | } | ||
911 | |||
912 | EXPORT_SYMBOL(parport_ieee1284_ecp_write_data); | ||
913 | EXPORT_SYMBOL(parport_ieee1284_ecp_read_data); | ||
914 | EXPORT_SYMBOL(parport_ieee1284_ecp_write_addr); | ||
915 | EXPORT_SYMBOL(parport_ieee1284_write_compat); | ||
916 | EXPORT_SYMBOL(parport_ieee1284_read_nibble); | ||
917 | EXPORT_SYMBOL(parport_ieee1284_read_byte); | ||
918 | EXPORT_SYMBOL(parport_ieee1284_epp_write_data); | ||
919 | EXPORT_SYMBOL(parport_ieee1284_epp_read_data); | ||
920 | EXPORT_SYMBOL(parport_ieee1284_epp_write_addr); | ||
921 | EXPORT_SYMBOL(parport_ieee1284_epp_read_addr); | ||
diff --git a/drivers/parport/multiface.h b/drivers/parport/multiface.h new file mode 100644 index 000000000000..56769dd5d315 --- /dev/null +++ b/drivers/parport/multiface.h | |||
@@ -0,0 +1,20 @@ | |||
1 | #ifndef _MULTIFACE_H_ | ||
2 | #define _MULTIFACE_H_ | ||
3 | |||
4 | /* | ||
5 | * Defines for SerialMaster, Multiface Card II and Multiface Card III | ||
6 | * The addresses given below are offsets to the board base address | ||
7 | * | ||
8 | * 6.11.95 Joerg Dorchain (dorchain@mpi-sb.mpg.de) | ||
9 | * | ||
10 | */ | ||
11 | |||
12 | #define PIA_REG_PADWIDTH 255 | ||
13 | |||
14 | #define DUARTBASE 0x0000 | ||
15 | #define PITBASE 0x0100 | ||
16 | #define ROMBASE 0x0200 | ||
17 | #define PIABASE 0x4000 | ||
18 | |||
19 | #endif | ||
20 | |||
diff --git a/drivers/parport/parport_amiga.c b/drivers/parport/parport_amiga.c new file mode 100644 index 000000000000..5126e74ac2ec --- /dev/null +++ b/drivers/parport/parport_amiga.c | |||
@@ -0,0 +1,293 @@ | |||
1 | /* Low-level parallel port routines for the Amiga built-in port | ||
2 | * | ||
3 | * Author: Joerg Dorchain <joerg@dorchain.net> | ||
4 | * | ||
5 | * This is a complete rewrite of the code, but based heaviy upon the old | ||
6 | * lp_intern. code. | ||
7 | * | ||
8 | * The built-in Amiga parallel port provides one port at a fixed address | ||
9 | * with 8 bidirectional data lines (D0 - D7) and 3 bidirectional status | ||
10 | * lines (BUSY, POUT, SEL), 1 output control line /STROBE (raised automatically | ||
11 | * in hardware when the data register is accessed), and 1 input control line | ||
12 | * /ACK, able to cause an interrupt, but both not directly settable by | ||
13 | * software. | ||
14 | */ | ||
15 | |||
16 | #include <linux/module.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/parport.h> | ||
19 | #include <linux/ioport.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <asm/setup.h> | ||
22 | #include <asm/amigahw.h> | ||
23 | #include <asm/irq.h> | ||
24 | #include <asm/io.h> | ||
25 | #include <asm/amigaints.h> | ||
26 | |||
27 | #undef DEBUG | ||
28 | #ifdef DEBUG | ||
29 | #define DPRINTK printk | ||
30 | #else | ||
31 | #define DPRINTK(x...) do { } while (0) | ||
32 | #endif | ||
33 | |||
34 | static struct parport *this_port = NULL; | ||
35 | |||
36 | static void amiga_write_data(struct parport *p, unsigned char data) | ||
37 | { | ||
38 | DPRINTK(KERN_DEBUG "write_data %c\n",data); | ||
39 | /* Triggers also /STROBE. This behavior cannot be changed */ | ||
40 | ciaa.prb = data; | ||
41 | mb(); | ||
42 | } | ||
43 | |||
44 | static unsigned char amiga_read_data(struct parport *p) | ||
45 | { | ||
46 | /* Triggers also /STROBE. This behavior cannot be changed */ | ||
47 | return ciaa.prb; | ||
48 | } | ||
49 | |||
50 | #if 0 | ||
51 | static unsigned char control_pc_to_amiga(unsigned char control) | ||
52 | { | ||
53 | unsigned char ret = 0; | ||
54 | |||
55 | if (control & PARPORT_CONTROL_SELECT) /* XXX: What is SELECP? */ | ||
56 | ; | ||
57 | if (control & PARPORT_CONTROL_INIT) /* INITP */ | ||
58 | /* reset connected to cpu reset pin */; | ||
59 | if (control & PARPORT_CONTROL_AUTOFD) /* AUTOLF */ | ||
60 | /* Not connected */; | ||
61 | if (control & PARPORT_CONTROL_STROBE) /* Strobe */ | ||
62 | /* Handled only directly by hardware */; | ||
63 | return ret; | ||
64 | } | ||
65 | #endif | ||
66 | |||
67 | static unsigned char control_amiga_to_pc(unsigned char control) | ||
68 | { | ||
69 | return PARPORT_CONTROL_SELECT | | ||
70 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE; | ||
71 | /* fake value: interrupt enable, select in, no reset, | ||
72 | no autolf, no strobe - seems to be closest the wiring diagram */ | ||
73 | } | ||
74 | |||
75 | static void amiga_write_control(struct parport *p, unsigned char control) | ||
76 | { | ||
77 | DPRINTK(KERN_DEBUG "write_control %02x\n",control); | ||
78 | /* No implementation possible */ | ||
79 | } | ||
80 | |||
81 | static unsigned char amiga_read_control( struct parport *p) | ||
82 | { | ||
83 | DPRINTK(KERN_DEBUG "read_control \n"); | ||
84 | return control_amiga_to_pc(0); | ||
85 | } | ||
86 | |||
87 | static unsigned char amiga_frob_control( struct parport *p, unsigned char mask, unsigned char val) | ||
88 | { | ||
89 | unsigned char old; | ||
90 | |||
91 | DPRINTK(KERN_DEBUG "frob_control mask %02x, value %02x\n",mask,val); | ||
92 | old = amiga_read_control(p); | ||
93 | amiga_write_control(p, (old & ~mask) ^ val); | ||
94 | return old; | ||
95 | } | ||
96 | |||
97 | #if 0 /* currently unused */ | ||
98 | static unsigned char status_pc_to_amiga(unsigned char status) | ||
99 | { | ||
100 | unsigned char ret = 1; | ||
101 | |||
102 | if (status & PARPORT_STATUS_BUSY) /* Busy */ | ||
103 | ret &= ~1; | ||
104 | if (status & PARPORT_STATUS_ACK) /* Ack */ | ||
105 | /* handled in hardware */; | ||
106 | if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */ | ||
107 | ret |= 2; | ||
108 | if (status & PARPORT_STATUS_SELECT) /* select */ | ||
109 | ret |= 4; | ||
110 | if (status & PARPORT_STATUS_ERROR) /* error */ | ||
111 | /* not connected */; | ||
112 | return ret; | ||
113 | } | ||
114 | #endif | ||
115 | |||
116 | static unsigned char status_amiga_to_pc(unsigned char status) | ||
117 | { | ||
118 | unsigned char ret = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR; | ||
119 | |||
120 | if (status & 1) /* Busy */ | ||
121 | ret &= ~PARPORT_STATUS_BUSY; | ||
122 | if (status & 2) /* PaperOut */ | ||
123 | ret |= PARPORT_STATUS_PAPEROUT; | ||
124 | if (status & 4) /* Selected */ | ||
125 | ret |= PARPORT_STATUS_SELECT; | ||
126 | /* the rest is not connected or handled autonomously in hardware */ | ||
127 | |||
128 | return ret; | ||
129 | } | ||
130 | |||
131 | static unsigned char amiga_read_status(struct parport *p) | ||
132 | { | ||
133 | unsigned char status; | ||
134 | |||
135 | status = status_amiga_to_pc(ciab.pra & 7); | ||
136 | DPRINTK(KERN_DEBUG "read_status %02x\n", status); | ||
137 | return status; | ||
138 | } | ||
139 | |||
140 | /* as this ports irq handling is already done, we use a generic funktion */ | ||
141 | static irqreturn_t amiga_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
142 | { | ||
143 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
144 | return IRQ_HANDLED; | ||
145 | } | ||
146 | |||
147 | static void amiga_enable_irq(struct parport *p) | ||
148 | { | ||
149 | enable_irq(IRQ_AMIGA_CIAA_FLG); | ||
150 | } | ||
151 | |||
152 | static void amiga_disable_irq(struct parport *p) | ||
153 | { | ||
154 | disable_irq(IRQ_AMIGA_CIAA_FLG); | ||
155 | } | ||
156 | |||
157 | static void amiga_data_forward(struct parport *p) | ||
158 | { | ||
159 | DPRINTK(KERN_DEBUG "forward\n"); | ||
160 | ciaa.ddrb = 0xff; /* all pins output */ | ||
161 | mb(); | ||
162 | } | ||
163 | |||
164 | static void amiga_data_reverse(struct parport *p) | ||
165 | { | ||
166 | DPRINTK(KERN_DEBUG "reverse\n"); | ||
167 | ciaa.ddrb = 0; /* all pins input */ | ||
168 | mb(); | ||
169 | } | ||
170 | |||
171 | static void amiga_init_state(struct pardevice *dev, struct parport_state *s) | ||
172 | { | ||
173 | s->u.amiga.data = 0; | ||
174 | s->u.amiga.datadir = 255; | ||
175 | s->u.amiga.status = 0; | ||
176 | s->u.amiga.statusdir = 0; | ||
177 | } | ||
178 | |||
179 | static void amiga_save_state(struct parport *p, struct parport_state *s) | ||
180 | { | ||
181 | mb(); | ||
182 | s->u.amiga.data = ciaa.prb; | ||
183 | s->u.amiga.datadir = ciaa.ddrb; | ||
184 | s->u.amiga.status = ciab.pra & 7; | ||
185 | s->u.amiga.statusdir = ciab.ddra & 7; | ||
186 | mb(); | ||
187 | } | ||
188 | |||
189 | static void amiga_restore_state(struct parport *p, struct parport_state *s) | ||
190 | { | ||
191 | mb(); | ||
192 | ciaa.prb = s->u.amiga.data; | ||
193 | ciaa.ddrb = s->u.amiga.datadir; | ||
194 | ciab.pra |= (ciab.pra & 0xf8) | s->u.amiga.status; | ||
195 | ciab.ddra |= (ciab.ddra & 0xf8) | s->u.amiga.statusdir; | ||
196 | mb(); | ||
197 | } | ||
198 | |||
199 | static struct parport_operations pp_amiga_ops = { | ||
200 | .write_data = amiga_write_data, | ||
201 | .read_data = amiga_read_data, | ||
202 | |||
203 | .write_control = amiga_write_control, | ||
204 | .read_control = amiga_read_control, | ||
205 | .frob_control = amiga_frob_control, | ||
206 | |||
207 | .read_status = amiga_read_status, | ||
208 | |||
209 | .enable_irq = amiga_enable_irq, | ||
210 | .disable_irq = amiga_disable_irq, | ||
211 | |||
212 | .data_forward = amiga_data_forward, | ||
213 | .data_reverse = amiga_data_reverse, | ||
214 | |||
215 | .init_state = amiga_init_state, | ||
216 | .save_state = amiga_save_state, | ||
217 | .restore_state = amiga_restore_state, | ||
218 | |||
219 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
220 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
221 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
222 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
223 | |||
224 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
225 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
226 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
227 | |||
228 | .compat_write_data = parport_ieee1284_write_compat, | ||
229 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
230 | .byte_read_data = parport_ieee1284_read_byte, | ||
231 | |||
232 | .owner = THIS_MODULE, | ||
233 | }; | ||
234 | |||
235 | /* ----------- Initialisation code --------------------------------- */ | ||
236 | |||
237 | static int __init parport_amiga_init(void) | ||
238 | { | ||
239 | struct parport *p; | ||
240 | int err; | ||
241 | |||
242 | if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(AMI_PARALLEL)) | ||
243 | return -ENODEV; | ||
244 | |||
245 | err = -EBUSY; | ||
246 | if (!request_mem_region(CIAA_PHYSADDR-1+0x100, 0x100, "parallel")) | ||
247 | goto out_mem; | ||
248 | |||
249 | ciaa.ddrb = 0xff; | ||
250 | ciab.ddra &= 0xf8; | ||
251 | mb(); | ||
252 | |||
253 | p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG, | ||
254 | PARPORT_DMA_NONE, &pp_amiga_ops); | ||
255 | if (!p) | ||
256 | goto out_port; | ||
257 | |||
258 | err = request_irq(IRQ_AMIGA_CIAA_FLG, amiga_interrupt, 0, p->name, p); | ||
259 | if (err) | ||
260 | goto out_irq; | ||
261 | |||
262 | this_port = p; | ||
263 | printk(KERN_INFO "%s: Amiga built-in port using irq\n", p->name); | ||
264 | /* XXX: set operating mode */ | ||
265 | parport_announce_port(p); | ||
266 | |||
267 | return 0; | ||
268 | |||
269 | out_irq: | ||
270 | parport_put_port(p); | ||
271 | out_port: | ||
272 | release_mem_region(CIAA_PHYSADDR-1+0x100, 0x100); | ||
273 | out_mem: | ||
274 | return err; | ||
275 | } | ||
276 | |||
277 | static void __exit parport_amiga_exit(void) | ||
278 | { | ||
279 | parport_remove_port(this_port); | ||
280 | if (this_port->irq != PARPORT_IRQ_NONE) | ||
281 | free_irq(IRQ_AMIGA_CIAA_FLG, this_port); | ||
282 | parport_put_port(this_port); | ||
283 | release_mem_region(CIAA_PHYSADDR-1+0x100, 0x100); | ||
284 | } | ||
285 | |||
286 | |||
287 | MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>"); | ||
288 | MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port"); | ||
289 | MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port"); | ||
290 | MODULE_LICENSE("GPL"); | ||
291 | |||
292 | module_init(parport_amiga_init) | ||
293 | module_exit(parport_amiga_exit) | ||
diff --git a/drivers/parport/parport_arc.c b/drivers/parport/parport_arc.c new file mode 100644 index 000000000000..b35bb4f48d62 --- /dev/null +++ b/drivers/parport/parport_arc.c | |||
@@ -0,0 +1,139 @@ | |||
1 | /* Low-level parallel port routines for Archimedes onboard hardware | ||
2 | * | ||
3 | * Author: Phil Blundell <philb@gnu.org> | ||
4 | */ | ||
5 | |||
6 | /* This driver is for the parallel port hardware found on Acorn's old | ||
7 | * range of Archimedes machines. The A5000 and newer systems have PC-style | ||
8 | * I/O hardware and should use the parport_pc driver instead. | ||
9 | * | ||
10 | * The Acorn printer port hardware is very simple. There is a single 8-bit | ||
11 | * write-only latch for the data port and control/status bits are handled | ||
12 | * with various auxilliary input and output lines. The port is not | ||
13 | * bidirectional, does not support any modes other than SPP, and has only | ||
14 | * a subset of the standard printer control lines connected. | ||
15 | */ | ||
16 | |||
17 | #include <linux/threads.h> | ||
18 | #include <linux/delay.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/interrupt.h> | ||
21 | #include <linux/ioport.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/slab.h> | ||
24 | #include <linux/parport.h> | ||
25 | |||
26 | #include <asm/ptrace.h> | ||
27 | #include <asm/io.h> | ||
28 | #include <asm/arch/oldlatches.h> | ||
29 | #include <asm/arch/irqs.h> | ||
30 | |||
31 | #define DATA_ADDRESS 0x3350010 | ||
32 | |||
33 | /* This is equivalent to the above and only used for request_region. */ | ||
34 | #define PORT_BASE 0x80000000 | ((DATA_ADDRESS - IO_BASE) >> 2) | ||
35 | |||
36 | /* The hardware can't read from the data latch, so we must use a soft | ||
37 | copy. */ | ||
38 | static unsigned char data_copy; | ||
39 | |||
40 | /* These are pretty simple. We know the irq is never shared and the | ||
41 | kernel does all the magic that's required. */ | ||
42 | static void arc_enable_irq(struct parport *p) | ||
43 | { | ||
44 | enable_irq(p->irq); | ||
45 | } | ||
46 | |||
47 | static void arc_disable_irq(struct parport *p) | ||
48 | { | ||
49 | disable_irq(p->irq); | ||
50 | } | ||
51 | |||
52 | static void arc_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
53 | { | ||
54 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
55 | } | ||
56 | |||
57 | static void arc_write_data(struct parport *p, unsigned char data) | ||
58 | { | ||
59 | data_copy = data; | ||
60 | outb_t(data, DATA_LATCH); | ||
61 | } | ||
62 | |||
63 | static unsigned char arc_read_data(struct parport *p) | ||
64 | { | ||
65 | return data_copy; | ||
66 | } | ||
67 | |||
68 | static struct parport_operations parport_arc_ops = | ||
69 | { | ||
70 | .write_data = arc_write_data, | ||
71 | .read_data = arc_read_data, | ||
72 | |||
73 | .write_control = arc_write_control, | ||
74 | .read_control = arc_read_control, | ||
75 | .frob_control = arc_frob_control, | ||
76 | |||
77 | .read_status = arc_read_status, | ||
78 | |||
79 | .enable_irq = arc_enable_irq, | ||
80 | .disable_irq = arc_disable_irq, | ||
81 | |||
82 | .data_forward = arc_data_forward, | ||
83 | .data_reverse = arc_data_reverse, | ||
84 | |||
85 | .init_state = arc_init_state, | ||
86 | .save_state = arc_save_state, | ||
87 | .restore_state = arc_restore_state, | ||
88 | |||
89 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
90 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
91 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
92 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
93 | |||
94 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
95 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
96 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
97 | |||
98 | .compat_write_data = parport_ieee1284_write_compat, | ||
99 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
100 | .byte_read_data = parport_ieee1284_read_byte, | ||
101 | |||
102 | .owner = THIS_MODULE, | ||
103 | }; | ||
104 | |||
105 | /* --- Initialisation code -------------------------------- */ | ||
106 | |||
107 | static int parport_arc_init(void) | ||
108 | { | ||
109 | /* Archimedes hardware provides only one port, at a fixed address */ | ||
110 | struct parport *p; | ||
111 | struct resource res; | ||
112 | char *fake_name = "parport probe"); | ||
113 | |||
114 | res = request_region(PORT_BASE, 1, fake_name); | ||
115 | if (res == NULL) | ||
116 | return 0; | ||
117 | |||
118 | p = parport_register_port (PORT_BASE, IRQ_PRINTERACK, | ||
119 | PARPORT_DMA_NONE, &parport_arc_ops); | ||
120 | |||
121 | if (!p) { | ||
122 | release_region(PORT_BASE, 1); | ||
123 | return 0; | ||
124 | } | ||
125 | |||
126 | p->modes = PARPORT_MODE_ARCSPP; | ||
127 | p->size = 1; | ||
128 | rename_region(res, p->name); | ||
129 | |||
130 | printk(KERN_INFO "%s: Archimedes on-board port, using irq %d\n", | ||
131 | p->irq); | ||
132 | |||
133 | /* Tell the high-level drivers about the port. */ | ||
134 | parport_announce_port (p); | ||
135 | |||
136 | return 1; | ||
137 | } | ||
138 | |||
139 | module_init(parport_arc_init) | ||
diff --git a/drivers/parport/parport_atari.c b/drivers/parport/parport_atari.c new file mode 100644 index 000000000000..78c3f34108bc --- /dev/null +++ b/drivers/parport/parport_atari.c | |||
@@ -0,0 +1,240 @@ | |||
1 | /* Low-level parallel port routines for the Atari builtin port | ||
2 | * | ||
3 | * Author: Andreas Schwab <schwab@issan.informatik.uni-dortmund.de> | ||
4 | * | ||
5 | * Based on parport_amiga.c. | ||
6 | * | ||
7 | * The built-in Atari parallel port provides one port at a fixed address | ||
8 | * with 8 output data lines (D0 - D7), 1 output control line (STROBE) | ||
9 | * and 1 input status line (BUSY) able to cause an interrupt. | ||
10 | */ | ||
11 | |||
12 | #include <linux/module.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/parport.h> | ||
15 | #include <linux/interrupt.h> | ||
16 | #include <asm/setup.h> | ||
17 | #include <asm/atarihw.h> | ||
18 | #include <asm/irq.h> | ||
19 | #include <asm/atariints.h> | ||
20 | |||
21 | static struct parport *this_port = NULL; | ||
22 | |||
23 | static unsigned char | ||
24 | parport_atari_read_data(struct parport *p) | ||
25 | { | ||
26 | unsigned long flags; | ||
27 | unsigned char data; | ||
28 | |||
29 | local_irq_save(flags); | ||
30 | sound_ym.rd_data_reg_sel = 15; | ||
31 | data = sound_ym.rd_data_reg_sel; | ||
32 | local_irq_restore(flags); | ||
33 | return data; | ||
34 | } | ||
35 | |||
36 | static void | ||
37 | parport_atari_write_data(struct parport *p, unsigned char data) | ||
38 | { | ||
39 | unsigned long flags; | ||
40 | |||
41 | local_irq_save(flags); | ||
42 | sound_ym.rd_data_reg_sel = 15; | ||
43 | sound_ym.wd_data = data; | ||
44 | local_irq_restore(flags); | ||
45 | } | ||
46 | |||
47 | static unsigned char | ||
48 | parport_atari_read_control(struct parport *p) | ||
49 | { | ||
50 | unsigned long flags; | ||
51 | unsigned char control = 0; | ||
52 | |||
53 | local_irq_save(flags); | ||
54 | sound_ym.rd_data_reg_sel = 14; | ||
55 | if (!(sound_ym.rd_data_reg_sel & (1 << 5))) | ||
56 | control = PARPORT_CONTROL_STROBE; | ||
57 | local_irq_restore(flags); | ||
58 | return control; | ||
59 | } | ||
60 | |||
61 | static void | ||
62 | parport_atari_write_control(struct parport *p, unsigned char control) | ||
63 | { | ||
64 | unsigned long flags; | ||
65 | |||
66 | local_irq_save(flags); | ||
67 | sound_ym.rd_data_reg_sel = 14; | ||
68 | if (control & PARPORT_CONTROL_STROBE) | ||
69 | sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~(1 << 5); | ||
70 | else | ||
71 | sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5); | ||
72 | local_irq_restore(flags); | ||
73 | } | ||
74 | |||
75 | static unsigned char | ||
76 | parport_atari_frob_control(struct parport *p, unsigned char mask, | ||
77 | unsigned char val) | ||
78 | { | ||
79 | unsigned char old = parport_atari_read_control(p); | ||
80 | parport_atari_write_control(p, (old & ~mask) ^ val); | ||
81 | return old; | ||
82 | } | ||
83 | |||
84 | static unsigned char | ||
85 | parport_atari_read_status(struct parport *p) | ||
86 | { | ||
87 | return ((mfp.par_dt_reg & 1 ? 0 : PARPORT_STATUS_BUSY) | | ||
88 | PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR); | ||
89 | } | ||
90 | |||
91 | static void | ||
92 | parport_atari_init_state(struct pardevice *d, struct parport_state *s) | ||
93 | { | ||
94 | } | ||
95 | |||
96 | static void | ||
97 | parport_atari_save_state(struct parport *p, struct parport_state *s) | ||
98 | { | ||
99 | } | ||
100 | |||
101 | static void | ||
102 | parport_atari_restore_state(struct parport *p, struct parport_state *s) | ||
103 | { | ||
104 | } | ||
105 | |||
106 | static irqreturn_t | ||
107 | parport_atari_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
108 | { | ||
109 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
110 | return IRQ_HANDLED; | ||
111 | } | ||
112 | |||
113 | static void | ||
114 | parport_atari_enable_irq(struct parport *p) | ||
115 | { | ||
116 | enable_irq(IRQ_MFP_BUSY); | ||
117 | } | ||
118 | |||
119 | static void | ||
120 | parport_atari_disable_irq(struct parport *p) | ||
121 | { | ||
122 | disable_irq(IRQ_MFP_BUSY); | ||
123 | } | ||
124 | |||
125 | static void | ||
126 | parport_atari_data_forward(struct parport *p) | ||
127 | { | ||
128 | unsigned long flags; | ||
129 | |||
130 | local_irq_save(flags); | ||
131 | /* Soundchip port B as output. */ | ||
132 | sound_ym.rd_data_reg_sel = 7; | ||
133 | sound_ym.wd_data = sound_ym.rd_data_reg_sel | 0x40; | ||
134 | local_irq_restore(flags); | ||
135 | } | ||
136 | |||
137 | static void | ||
138 | parport_atari_data_reverse(struct parport *p) | ||
139 | { | ||
140 | #if 0 /* too dangerous, can kill sound chip */ | ||
141 | unsigned long flags; | ||
142 | |||
143 | local_irq_save(flags); | ||
144 | /* Soundchip port B as input. */ | ||
145 | sound_ym.rd_data_reg_sel = 7; | ||
146 | sound_ym.wd_data = sound_ym.rd_data_reg_sel & ~0x40; | ||
147 | local_irq_restore(flags); | ||
148 | #endif | ||
149 | } | ||
150 | |||
151 | static struct parport_operations parport_atari_ops = { | ||
152 | .write_data = parport_atari_write_data, | ||
153 | .read_data = parport_atari_read_data, | ||
154 | |||
155 | .write_control = parport_atari_write_control, | ||
156 | .read_control = parport_atari_read_control, | ||
157 | .frob_control = parport_atari_frob_control, | ||
158 | |||
159 | .read_status = parport_atari_read_status, | ||
160 | |||
161 | .enable_irq = parport_atari_enable_irq, | ||
162 | .disable_irq = parport_atari_disable_irq, | ||
163 | |||
164 | .data_forward = parport_atari_data_forward, | ||
165 | .data_reverse = parport_atari_data_reverse, | ||
166 | |||
167 | .init_state = parport_atari_init_state, | ||
168 | .save_state = parport_atari_save_state, | ||
169 | .restore_state = parport_atari_restore_state, | ||
170 | |||
171 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
172 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
173 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
174 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
175 | |||
176 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
177 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
178 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
179 | |||
180 | .compat_write_data = parport_ieee1284_write_compat, | ||
181 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
182 | .byte_read_data = parport_ieee1284_read_byte, | ||
183 | |||
184 | .owner = THIS_MODULE, | ||
185 | }; | ||
186 | |||
187 | |||
188 | static int __init parport_atari_init(void) | ||
189 | { | ||
190 | struct parport *p; | ||
191 | unsigned long flags; | ||
192 | |||
193 | if (MACH_IS_ATARI) { | ||
194 | local_irq_save(flags); | ||
195 | /* Soundchip port A/B as output. */ | ||
196 | sound_ym.rd_data_reg_sel = 7; | ||
197 | sound_ym.wd_data = (sound_ym.rd_data_reg_sel & 0x3f) | 0xc0; | ||
198 | /* STROBE high. */ | ||
199 | sound_ym.rd_data_reg_sel = 14; | ||
200 | sound_ym.wd_data = sound_ym.rd_data_reg_sel | (1 << 5); | ||
201 | local_irq_restore(flags); | ||
202 | /* MFP port I0 as input. */ | ||
203 | mfp.data_dir &= ~1; | ||
204 | /* MFP port I0 interrupt on high->low edge. */ | ||
205 | mfp.active_edge &= ~1; | ||
206 | p = parport_register_port((unsigned long)&sound_ym.wd_data, | ||
207 | IRQ_MFP_BUSY, PARPORT_DMA_NONE, | ||
208 | &parport_atari_ops); | ||
209 | if (!p) | ||
210 | return -ENODEV; | ||
211 | if (request_irq(IRQ_MFP_BUSY, parport_atari_interrupt, | ||
212 | IRQ_TYPE_SLOW, p->name, p)) { | ||
213 | parport_put_port (p); | ||
214 | return -ENODEV; | ||
215 | } | ||
216 | |||
217 | this_port = p; | ||
218 | printk(KERN_INFO "%s: Atari built-in port using irq\n", p->name); | ||
219 | parport_announce_port (p); | ||
220 | |||
221 | return 0; | ||
222 | } | ||
223 | return -ENODEV; | ||
224 | } | ||
225 | |||
226 | static void __exit parport_atari_exit(void) | ||
227 | { | ||
228 | parport_remove_port(this_port); | ||
229 | if (this_port->irq != PARPORT_IRQ_NONE) | ||
230 | free_irq(IRQ_MFP_BUSY, this_port); | ||
231 | parport_put_port(this_port); | ||
232 | } | ||
233 | |||
234 | MODULE_AUTHOR("Andreas Schwab"); | ||
235 | MODULE_DESCRIPTION("Parport Driver for Atari builtin Port"); | ||
236 | MODULE_SUPPORTED_DEVICE("Atari builtin Parallel Port"); | ||
237 | MODULE_LICENSE("GPL"); | ||
238 | |||
239 | module_init(parport_atari_init) | ||
240 | module_exit(parport_atari_exit) | ||
diff --git a/drivers/parport/parport_cs.c b/drivers/parport/parport_cs.c new file mode 100644 index 000000000000..a3fa8185af2a --- /dev/null +++ b/drivers/parport/parport_cs.c | |||
@@ -0,0 +1,397 @@ | |||
1 | /*====================================================================== | ||
2 | |||
3 | A driver for PCMCIA parallel port adapters | ||
4 | |||
5 | (specifically, for the Quatech SPP-100 EPP card: other cards will | ||
6 | probably require driver tweaks) | ||
7 | |||
8 | parport_cs.c 1.29 2002/10/11 06:57:41 | ||
9 | |||
10 | The contents of this file are subject to the Mozilla Public | ||
11 | License Version 1.1 (the "License"); you may not use this file | ||
12 | except in compliance with the License. You may obtain a copy of | ||
13 | the License at http://www.mozilla.org/MPL/ | ||
14 | |||
15 | Software distributed under the License is distributed on an "AS | ||
16 | IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or | ||
17 | implied. See the License for the specific language governing | ||
18 | rights and limitations under the License. | ||
19 | |||
20 | The initial developer of the original code is David A. Hinds | ||
21 | <dahinds@users.sourceforge.net>. Portions created by David A. Hinds | ||
22 | are Copyright (C) 1999 David A. Hinds. All Rights Reserved. | ||
23 | |||
24 | Alternatively, the contents of this file may be used under the | ||
25 | terms of the GNU General Public License version 2 (the "GPL"), in | ||
26 | which case the provisions of the GPL are applicable instead of the | ||
27 | above. If you wish to allow the use of your version of this file | ||
28 | only under the terms of the GPL and not to allow others to use | ||
29 | your version of this file under the MPL, indicate your decision | ||
30 | by deleting the provisions above and replace them with the notice | ||
31 | and other provisions required by the GPL. If you do not delete | ||
32 | the provisions above, a recipient may use your version of this | ||
33 | file under either the MPL or the GPL. | ||
34 | |||
35 | ======================================================================*/ | ||
36 | |||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/module.h> | ||
39 | #include <linux/init.h> | ||
40 | #include <linux/sched.h> | ||
41 | #include <linux/ptrace.h> | ||
42 | #include <linux/slab.h> | ||
43 | #include <linux/string.h> | ||
44 | #include <linux/timer.h> | ||
45 | #include <linux/ioport.h> | ||
46 | #include <linux/major.h> | ||
47 | |||
48 | #include <linux/parport.h> | ||
49 | #include <linux/parport_pc.h> | ||
50 | |||
51 | #include <pcmcia/version.h> | ||
52 | #include <pcmcia/cs_types.h> | ||
53 | #include <pcmcia/cs.h> | ||
54 | #include <pcmcia/cistpl.h> | ||
55 | #include <pcmcia/ds.h> | ||
56 | #include <pcmcia/cisreg.h> | ||
57 | #include <pcmcia/ciscode.h> | ||
58 | |||
59 | /*====================================================================*/ | ||
60 | |||
61 | /* Module parameters */ | ||
62 | |||
63 | MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>"); | ||
64 | MODULE_DESCRIPTION("PCMCIA parallel port card driver"); | ||
65 | MODULE_LICENSE("Dual MPL/GPL"); | ||
66 | |||
67 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) | ||
68 | |||
69 | INT_MODULE_PARM(epp_mode, 1); | ||
70 | |||
71 | #ifdef PCMCIA_DEBUG | ||
72 | INT_MODULE_PARM(pc_debug, PCMCIA_DEBUG); | ||
73 | #define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args) | ||
74 | static char *version = | ||
75 | "parport_cs.c 1.29 2002/10/11 06:57:41 (David Hinds)"; | ||
76 | #else | ||
77 | #define DEBUG(n, args...) | ||
78 | #endif | ||
79 | |||
80 | /*====================================================================*/ | ||
81 | |||
82 | #define FORCE_EPP_MODE 0x08 | ||
83 | |||
84 | typedef struct parport_info_t { | ||
85 | dev_link_t link; | ||
86 | int ndev; | ||
87 | dev_node_t node; | ||
88 | struct parport *port; | ||
89 | } parport_info_t; | ||
90 | |||
91 | static dev_link_t *parport_attach(void); | ||
92 | static void parport_detach(dev_link_t *); | ||
93 | static void parport_config(dev_link_t *link); | ||
94 | static void parport_cs_release(dev_link_t *); | ||
95 | static int parport_event(event_t event, int priority, | ||
96 | event_callback_args_t *args); | ||
97 | |||
98 | static dev_info_t dev_info = "parport_cs"; | ||
99 | static dev_link_t *dev_list = NULL; | ||
100 | |||
101 | /*====================================================================== | ||
102 | |||
103 | parport_attach() creates an "instance" of the driver, allocating | ||
104 | local data structures for one device. The device is registered | ||
105 | with Card Services. | ||
106 | |||
107 | ======================================================================*/ | ||
108 | |||
109 | static dev_link_t *parport_attach(void) | ||
110 | { | ||
111 | parport_info_t *info; | ||
112 | dev_link_t *link; | ||
113 | client_reg_t client_reg; | ||
114 | int ret; | ||
115 | |||
116 | DEBUG(0, "parport_attach()\n"); | ||
117 | |||
118 | /* Create new parport device */ | ||
119 | info = kmalloc(sizeof(*info), GFP_KERNEL); | ||
120 | if (!info) return NULL; | ||
121 | memset(info, 0, sizeof(*info)); | ||
122 | link = &info->link; link->priv = info; | ||
123 | |||
124 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; | ||
125 | link->io.Attributes2 = IO_DATA_PATH_WIDTH_8; | ||
126 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE; | ||
127 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; | ||
128 | link->conf.Attributes = CONF_ENABLE_IRQ; | ||
129 | link->conf.Vcc = 50; | ||
130 | link->conf.IntType = INT_MEMORY_AND_IO; | ||
131 | |||
132 | /* Register with Card Services */ | ||
133 | link->next = dev_list; | ||
134 | dev_list = link; | ||
135 | client_reg.dev_info = &dev_info; | ||
136 | client_reg.EventMask = | ||
137 | CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL | | ||
138 | CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET | | ||
139 | CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME; | ||
140 | client_reg.event_handler = &parport_event; | ||
141 | client_reg.Version = 0x0210; | ||
142 | client_reg.event_callback_args.client_data = link; | ||
143 | ret = pcmcia_register_client(&link->handle, &client_reg); | ||
144 | if (ret != CS_SUCCESS) { | ||
145 | cs_error(link->handle, RegisterClient, ret); | ||
146 | parport_detach(link); | ||
147 | return NULL; | ||
148 | } | ||
149 | |||
150 | return link; | ||
151 | } /* parport_attach */ | ||
152 | |||
153 | /*====================================================================== | ||
154 | |||
155 | This deletes a driver "instance". The device is de-registered | ||
156 | with Card Services. If it has been released, all local data | ||
157 | structures are freed. Otherwise, the structures will be freed | ||
158 | when the device is released. | ||
159 | |||
160 | ======================================================================*/ | ||
161 | |||
162 | static void parport_detach(dev_link_t *link) | ||
163 | { | ||
164 | dev_link_t **linkp; | ||
165 | int ret; | ||
166 | |||
167 | DEBUG(0, "parport_detach(0x%p)\n", link); | ||
168 | |||
169 | /* Locate device structure */ | ||
170 | for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next) | ||
171 | if (*linkp == link) break; | ||
172 | if (*linkp == NULL) | ||
173 | return; | ||
174 | |||
175 | if (link->state & DEV_CONFIG) | ||
176 | parport_cs_release(link); | ||
177 | |||
178 | if (link->handle) { | ||
179 | ret = pcmcia_deregister_client(link->handle); | ||
180 | if (ret != CS_SUCCESS) | ||
181 | cs_error(link->handle, DeregisterClient, ret); | ||
182 | } | ||
183 | |||
184 | /* Unlink, free device structure */ | ||
185 | *linkp = link->next; | ||
186 | kfree(link->priv); | ||
187 | |||
188 | } /* parport_detach */ | ||
189 | |||
190 | /*====================================================================== | ||
191 | |||
192 | parport_config() is scheduled to run after a CARD_INSERTION event | ||
193 | is received, to configure the PCMCIA socket, and to make the | ||
194 | parport device available to the system. | ||
195 | |||
196 | ======================================================================*/ | ||
197 | |||
198 | #define CS_CHECK(fn, ret) \ | ||
199 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | ||
200 | |||
201 | void parport_config(dev_link_t *link) | ||
202 | { | ||
203 | client_handle_t handle = link->handle; | ||
204 | parport_info_t *info = link->priv; | ||
205 | tuple_t tuple; | ||
206 | u_short buf[128]; | ||
207 | cisparse_t parse; | ||
208 | config_info_t conf; | ||
209 | cistpl_cftable_entry_t *cfg = &parse.cftable_entry; | ||
210 | cistpl_cftable_entry_t dflt = { 0 }; | ||
211 | struct parport *p; | ||
212 | int last_ret, last_fn; | ||
213 | |||
214 | DEBUG(0, "parport_config(0x%p)\n", link); | ||
215 | |||
216 | tuple.TupleData = (cisdata_t *)buf; | ||
217 | tuple.TupleOffset = 0; tuple.TupleDataMax = 255; | ||
218 | tuple.Attributes = 0; | ||
219 | tuple.DesiredTuple = CISTPL_CONFIG; | ||
220 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
221 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(handle, &tuple)); | ||
222 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(handle, &tuple, &parse)); | ||
223 | link->conf.ConfigBase = parse.config.base; | ||
224 | link->conf.Present = parse.config.rmask[0]; | ||
225 | |||
226 | /* Configure card */ | ||
227 | link->state |= DEV_CONFIG; | ||
228 | |||
229 | /* Not sure if this is right... look up the current Vcc */ | ||
230 | CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(handle, &conf)); | ||
231 | |||
232 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; | ||
233 | tuple.Attributes = 0; | ||
234 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(handle, &tuple)); | ||
235 | while (1) { | ||
236 | if (pcmcia_get_tuple_data(handle, &tuple) != 0 || | ||
237 | pcmcia_parse_tuple(handle, &tuple, &parse) != 0) | ||
238 | goto next_entry; | ||
239 | |||
240 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { | ||
241 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; | ||
242 | link->conf.ConfigIndex = cfg->index; | ||
243 | if (epp_mode) | ||
244 | link->conf.ConfigIndex |= FORCE_EPP_MODE; | ||
245 | link->io.BasePort1 = io->win[0].base; | ||
246 | link->io.NumPorts1 = io->win[0].len; | ||
247 | link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK; | ||
248 | if (io->nwin == 2) { | ||
249 | link->io.BasePort2 = io->win[1].base; | ||
250 | link->io.NumPorts2 = io->win[1].len; | ||
251 | } | ||
252 | if (pcmcia_request_io(link->handle, &link->io) != 0) | ||
253 | goto next_entry; | ||
254 | /* If we've got this far, we're done */ | ||
255 | break; | ||
256 | } | ||
257 | |||
258 | next_entry: | ||
259 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg; | ||
260 | CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(handle, &tuple)); | ||
261 | } | ||
262 | |||
263 | CS_CHECK(RequestIRQ, pcmcia_request_irq(handle, &link->irq)); | ||
264 | CS_CHECK(RequestConfiguration, pcmcia_request_configuration(handle, &link->conf)); | ||
265 | |||
266 | release_region(link->io.BasePort1, link->io.NumPorts1); | ||
267 | if (link->io.NumPorts2) | ||
268 | release_region(link->io.BasePort2, link->io.NumPorts2); | ||
269 | p = parport_pc_probe_port(link->io.BasePort1, link->io.BasePort2, | ||
270 | link->irq.AssignedIRQ, PARPORT_DMA_NONE, | ||
271 | NULL); | ||
272 | if (p == NULL) { | ||
273 | printk(KERN_NOTICE "parport_cs: parport_pc_probe_port() at " | ||
274 | "0x%3x, irq %u failed\n", link->io.BasePort1, | ||
275 | link->irq.AssignedIRQ); | ||
276 | goto failed; | ||
277 | } | ||
278 | |||
279 | p->modes |= PARPORT_MODE_PCSPP; | ||
280 | if (epp_mode) | ||
281 | p->modes |= PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP; | ||
282 | info->ndev = 1; | ||
283 | info->node.major = LP_MAJOR; | ||
284 | info->node.minor = p->number; | ||
285 | info->port = p; | ||
286 | strcpy(info->node.dev_name, p->name); | ||
287 | link->dev = &info->node; | ||
288 | |||
289 | link->state &= ~DEV_CONFIG_PENDING; | ||
290 | return; | ||
291 | |||
292 | cs_failed: | ||
293 | cs_error(link->handle, last_fn, last_ret); | ||
294 | failed: | ||
295 | parport_cs_release(link); | ||
296 | link->state &= ~DEV_CONFIG_PENDING; | ||
297 | |||
298 | } /* parport_config */ | ||
299 | |||
300 | /*====================================================================== | ||
301 | |||
302 | After a card is removed, parport_cs_release() will unregister the | ||
303 | device, and release the PCMCIA configuration. If the device is | ||
304 | still open, this will be postponed until it is closed. | ||
305 | |||
306 | ======================================================================*/ | ||
307 | |||
308 | void parport_cs_release(dev_link_t *link) | ||
309 | { | ||
310 | parport_info_t *info = link->priv; | ||
311 | |||
312 | DEBUG(0, "parport_release(0x%p)\n", link); | ||
313 | |||
314 | if (info->ndev) { | ||
315 | struct parport *p = info->port; | ||
316 | parport_pc_unregister_port(p); | ||
317 | request_region(link->io.BasePort1, link->io.NumPorts1, | ||
318 | info->node.dev_name); | ||
319 | if (link->io.NumPorts2) | ||
320 | request_region(link->io.BasePort2, link->io.NumPorts2, | ||
321 | info->node.dev_name); | ||
322 | } | ||
323 | info->ndev = 0; | ||
324 | link->dev = NULL; | ||
325 | |||
326 | pcmcia_release_configuration(link->handle); | ||
327 | pcmcia_release_io(link->handle, &link->io); | ||
328 | pcmcia_release_irq(link->handle, &link->irq); | ||
329 | |||
330 | link->state &= ~DEV_CONFIG; | ||
331 | |||
332 | } /* parport_cs_release */ | ||
333 | |||
334 | /*====================================================================== | ||
335 | |||
336 | The card status event handler. Mostly, this schedules other | ||
337 | stuff to run after an event is received. | ||
338 | |||
339 | ======================================================================*/ | ||
340 | |||
341 | int parport_event(event_t event, int priority, | ||
342 | event_callback_args_t *args) | ||
343 | { | ||
344 | dev_link_t *link = args->client_data; | ||
345 | |||
346 | DEBUG(1, "parport_event(0x%06x)\n", event); | ||
347 | |||
348 | switch (event) { | ||
349 | case CS_EVENT_CARD_REMOVAL: | ||
350 | link->state &= ~DEV_PRESENT; | ||
351 | if (link->state & DEV_CONFIG) | ||
352 | parport_cs_release(link); | ||
353 | break; | ||
354 | case CS_EVENT_CARD_INSERTION: | ||
355 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; | ||
356 | parport_config(link); | ||
357 | break; | ||
358 | case CS_EVENT_PM_SUSPEND: | ||
359 | link->state |= DEV_SUSPEND; | ||
360 | /* Fall through... */ | ||
361 | case CS_EVENT_RESET_PHYSICAL: | ||
362 | if (link->state & DEV_CONFIG) | ||
363 | pcmcia_release_configuration(link->handle); | ||
364 | break; | ||
365 | case CS_EVENT_PM_RESUME: | ||
366 | link->state &= ~DEV_SUSPEND; | ||
367 | /* Fall through... */ | ||
368 | case CS_EVENT_CARD_RESET: | ||
369 | if (DEV_OK(link)) | ||
370 | pcmcia_request_configuration(link->handle, &link->conf); | ||
371 | break; | ||
372 | } | ||
373 | return 0; | ||
374 | } /* parport_event */ | ||
375 | |||
376 | static struct pcmcia_driver parport_cs_driver = { | ||
377 | .owner = THIS_MODULE, | ||
378 | .drv = { | ||
379 | .name = "parport_cs", | ||
380 | }, | ||
381 | .attach = parport_attach, | ||
382 | .detach = parport_detach, | ||
383 | }; | ||
384 | |||
385 | static int __init init_parport_cs(void) | ||
386 | { | ||
387 | return pcmcia_register_driver(&parport_cs_driver); | ||
388 | } | ||
389 | |||
390 | static void __exit exit_parport_cs(void) | ||
391 | { | ||
392 | pcmcia_unregister_driver(&parport_cs_driver); | ||
393 | BUG_ON(dev_list != NULL); | ||
394 | } | ||
395 | |||
396 | module_init(init_parport_cs); | ||
397 | module_exit(exit_parport_cs); | ||
diff --git a/drivers/parport/parport_gsc.c b/drivers/parport/parport_gsc.c new file mode 100644 index 000000000000..02d72acd1c89 --- /dev/null +++ b/drivers/parport/parport_gsc.c | |||
@@ -0,0 +1,437 @@ | |||
1 | /* | ||
2 | * Low-level parallel-support for PC-style hardware integrated in the | ||
3 | * LASI-Controller (on GSC-Bus) for HP-PARISC Workstations | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * (C) 1999-2001 by Helge Deller <deller@gmx.de> | ||
11 | * | ||
12 | * | ||
13 | * based on parport_pc.c by | ||
14 | * Grant Guenther <grant@torque.net> | ||
15 | * Phil Blundell <philb@gnu.org> | ||
16 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
17 | * Jose Renau <renau@acm.org> | ||
18 | * David Campbell <campbell@torque.net> | ||
19 | * Andrea Arcangeli | ||
20 | */ | ||
21 | |||
22 | #undef DEBUG /* undef for production */ | ||
23 | |||
24 | #include <linux/module.h> | ||
25 | #include <linux/init.h> | ||
26 | #include <linux/sched.h> | ||
27 | #include <linux/delay.h> | ||
28 | #include <linux/errno.h> | ||
29 | #include <linux/interrupt.h> | ||
30 | #include <linux/ioport.h> | ||
31 | #include <linux/kernel.h> | ||
32 | #include <linux/slab.h> | ||
33 | #include <linux/pci.h> | ||
34 | #include <linux/sysctl.h> | ||
35 | |||
36 | #include <asm/io.h> | ||
37 | #include <asm/dma.h> | ||
38 | #include <asm/uaccess.h> | ||
39 | #include <asm/superio.h> | ||
40 | |||
41 | #include <linux/parport.h> | ||
42 | #include <asm/pdc.h> | ||
43 | #include <asm/parisc-device.h> | ||
44 | #include <asm/hardware.h> | ||
45 | #include "parport_gsc.h" | ||
46 | |||
47 | |||
48 | MODULE_AUTHOR("Helge Deller <deller@gmx.de>"); | ||
49 | MODULE_DESCRIPTION("HP-PARISC PC-style parallel port driver"); | ||
50 | MODULE_SUPPORTED_DEVICE("integrated PC-style parallel port"); | ||
51 | MODULE_LICENSE("GPL"); | ||
52 | |||
53 | |||
54 | /* | ||
55 | * Clear TIMEOUT BIT in EPP MODE | ||
56 | * | ||
57 | * This is also used in SPP detection. | ||
58 | */ | ||
59 | static int clear_epp_timeout(struct parport *pb) | ||
60 | { | ||
61 | unsigned char r; | ||
62 | |||
63 | if (!(parport_gsc_read_status(pb) & 0x01)) | ||
64 | return 1; | ||
65 | |||
66 | /* To clear timeout some chips require double read */ | ||
67 | parport_gsc_read_status(pb); | ||
68 | r = parport_gsc_read_status(pb); | ||
69 | parport_writeb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */ | ||
70 | parport_writeb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */ | ||
71 | r = parport_gsc_read_status(pb); | ||
72 | |||
73 | return !(r & 0x01); | ||
74 | } | ||
75 | |||
76 | /* | ||
77 | * Access functions. | ||
78 | * | ||
79 | * Most of these aren't static because they may be used by the | ||
80 | * parport_xxx_yyy macros. extern __inline__ versions of several | ||
81 | * of these are in parport_gsc.h. | ||
82 | */ | ||
83 | |||
84 | static irqreturn_t parport_gsc_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
85 | { | ||
86 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
87 | return IRQ_HANDLED; | ||
88 | } | ||
89 | |||
90 | void parport_gsc_init_state(struct pardevice *dev, struct parport_state *s) | ||
91 | { | ||
92 | s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0); | ||
93 | } | ||
94 | |||
95 | void parport_gsc_save_state(struct parport *p, struct parport_state *s) | ||
96 | { | ||
97 | s->u.pc.ctr = parport_readb (CONTROL (p)); | ||
98 | } | ||
99 | |||
100 | void parport_gsc_restore_state(struct parport *p, struct parport_state *s) | ||
101 | { | ||
102 | parport_writeb (s->u.pc.ctr, CONTROL (p)); | ||
103 | } | ||
104 | |||
105 | struct parport_operations parport_gsc_ops = | ||
106 | { | ||
107 | .write_data = parport_gsc_write_data, | ||
108 | .read_data = parport_gsc_read_data, | ||
109 | |||
110 | .write_control = parport_gsc_write_control, | ||
111 | .read_control = parport_gsc_read_control, | ||
112 | .frob_control = parport_gsc_frob_control, | ||
113 | |||
114 | .read_status = parport_gsc_read_status, | ||
115 | |||
116 | .enable_irq = parport_gsc_enable_irq, | ||
117 | .disable_irq = parport_gsc_disable_irq, | ||
118 | |||
119 | .data_forward = parport_gsc_data_forward, | ||
120 | .data_reverse = parport_gsc_data_reverse, | ||
121 | |||
122 | .init_state = parport_gsc_init_state, | ||
123 | .save_state = parport_gsc_save_state, | ||
124 | .restore_state = parport_gsc_restore_state, | ||
125 | |||
126 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
127 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
128 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
129 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
130 | |||
131 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
132 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
133 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
134 | |||
135 | .compat_write_data = parport_ieee1284_write_compat, | ||
136 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
137 | .byte_read_data = parport_ieee1284_read_byte, | ||
138 | |||
139 | .owner = THIS_MODULE, | ||
140 | }; | ||
141 | |||
142 | /* --- Mode detection ------------------------------------- */ | ||
143 | |||
144 | /* | ||
145 | * Checks for port existence, all ports support SPP MODE | ||
146 | */ | ||
147 | static int __devinit parport_SPP_supported(struct parport *pb) | ||
148 | { | ||
149 | unsigned char r, w; | ||
150 | |||
151 | /* | ||
152 | * first clear an eventually pending EPP timeout | ||
153 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset | ||
154 | * that does not even respond to SPP cycles if an EPP | ||
155 | * timeout is pending | ||
156 | */ | ||
157 | clear_epp_timeout(pb); | ||
158 | |||
159 | /* Do a simple read-write test to make sure the port exists. */ | ||
160 | w = 0xc; | ||
161 | parport_writeb (w, CONTROL (pb)); | ||
162 | |||
163 | /* Is there a control register that we can read from? Some | ||
164 | * ports don't allow reads, so read_control just returns a | ||
165 | * software copy. Some ports _do_ allow reads, so bypass the | ||
166 | * software copy here. In addition, some bits aren't | ||
167 | * writable. */ | ||
168 | r = parport_readb (CONTROL (pb)); | ||
169 | if ((r & 0xf) == w) { | ||
170 | w = 0xe; | ||
171 | parport_writeb (w, CONTROL (pb)); | ||
172 | r = parport_readb (CONTROL (pb)); | ||
173 | parport_writeb (0xc, CONTROL (pb)); | ||
174 | if ((r & 0xf) == w) | ||
175 | return PARPORT_MODE_PCSPP; | ||
176 | } | ||
177 | |||
178 | /* Try the data register. The data lines aren't tri-stated at | ||
179 | * this stage, so we expect back what we wrote. */ | ||
180 | w = 0xaa; | ||
181 | parport_gsc_write_data (pb, w); | ||
182 | r = parport_gsc_read_data (pb); | ||
183 | if (r == w) { | ||
184 | w = 0x55; | ||
185 | parport_gsc_write_data (pb, w); | ||
186 | r = parport_gsc_read_data (pb); | ||
187 | if (r == w) | ||
188 | return PARPORT_MODE_PCSPP; | ||
189 | } | ||
190 | |||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | /* Detect PS/2 support. | ||
195 | * | ||
196 | * Bit 5 (0x20) sets the PS/2 data direction; setting this high | ||
197 | * allows us to read data from the data lines. In theory we would get back | ||
198 | * 0xff but any peripheral attached to the port may drag some or all of the | ||
199 | * lines down to zero. So if we get back anything that isn't the contents | ||
200 | * of the data register we deem PS/2 support to be present. | ||
201 | * | ||
202 | * Some SPP ports have "half PS/2" ability - you can't turn off the line | ||
203 | * drivers, but an external peripheral with sufficiently beefy drivers of | ||
204 | * its own can overpower them and assert its own levels onto the bus, from | ||
205 | * where they can then be read back as normal. Ports with this property | ||
206 | * and the right type of device attached are likely to fail the SPP test, | ||
207 | * (as they will appear to have stuck bits) and so the fact that they might | ||
208 | * be misdetected here is rather academic. | ||
209 | */ | ||
210 | |||
211 | static int __devinit parport_PS2_supported(struct parport *pb) | ||
212 | { | ||
213 | int ok = 0; | ||
214 | |||
215 | clear_epp_timeout(pb); | ||
216 | |||
217 | /* try to tri-state the buffer */ | ||
218 | parport_gsc_data_reverse (pb); | ||
219 | |||
220 | parport_gsc_write_data(pb, 0x55); | ||
221 | if (parport_gsc_read_data(pb) != 0x55) ok++; | ||
222 | |||
223 | parport_gsc_write_data(pb, 0xaa); | ||
224 | if (parport_gsc_read_data(pb) != 0xaa) ok++; | ||
225 | |||
226 | /* cancel input mode */ | ||
227 | parport_gsc_data_forward (pb); | ||
228 | |||
229 | if (ok) { | ||
230 | pb->modes |= PARPORT_MODE_TRISTATE; | ||
231 | } else { | ||
232 | struct parport_gsc_private *priv = pb->private_data; | ||
233 | priv->ctr_writable &= ~0x20; | ||
234 | } | ||
235 | |||
236 | return ok; | ||
237 | } | ||
238 | |||
239 | |||
240 | /* --- Initialisation code -------------------------------- */ | ||
241 | |||
242 | struct parport *__devinit parport_gsc_probe_port (unsigned long base, | ||
243 | unsigned long base_hi, | ||
244 | int irq, int dma, | ||
245 | struct pci_dev *dev) | ||
246 | { | ||
247 | struct parport_gsc_private *priv; | ||
248 | struct parport_operations *ops; | ||
249 | struct parport tmp; | ||
250 | struct parport *p = &tmp; | ||
251 | |||
252 | priv = kmalloc (sizeof (struct parport_gsc_private), GFP_KERNEL); | ||
253 | if (!priv) { | ||
254 | printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base); | ||
255 | return NULL; | ||
256 | } | ||
257 | ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL); | ||
258 | if (!ops) { | ||
259 | printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n", | ||
260 | base); | ||
261 | kfree (priv); | ||
262 | return NULL; | ||
263 | } | ||
264 | memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations)); | ||
265 | priv->ctr = 0xc; | ||
266 | priv->ctr_writable = 0xff; | ||
267 | priv->dma_buf = 0; | ||
268 | priv->dma_handle = 0; | ||
269 | priv->dev = dev; | ||
270 | p->base = base; | ||
271 | p->base_hi = base_hi; | ||
272 | p->irq = irq; | ||
273 | p->dma = dma; | ||
274 | p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT; | ||
275 | p->ops = ops; | ||
276 | p->private_data = priv; | ||
277 | p->physport = p; | ||
278 | if (!parport_SPP_supported (p)) { | ||
279 | /* No port. */ | ||
280 | kfree (priv); | ||
281 | return NULL; | ||
282 | } | ||
283 | parport_PS2_supported (p); | ||
284 | |||
285 | if (!(p = parport_register_port(base, PARPORT_IRQ_NONE, | ||
286 | PARPORT_DMA_NONE, ops))) { | ||
287 | kfree (priv); | ||
288 | kfree (ops); | ||
289 | return NULL; | ||
290 | } | ||
291 | |||
292 | p->base_hi = base_hi; | ||
293 | p->modes = tmp.modes; | ||
294 | p->size = (p->modes & PARPORT_MODE_EPP)?8:3; | ||
295 | p->private_data = priv; | ||
296 | |||
297 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); | ||
298 | p->irq = irq; | ||
299 | if (p->irq == PARPORT_IRQ_AUTO) { | ||
300 | p->irq = PARPORT_IRQ_NONE; | ||
301 | } | ||
302 | if (p->irq != PARPORT_IRQ_NONE) { | ||
303 | printk(", irq %d", p->irq); | ||
304 | |||
305 | if (p->dma == PARPORT_DMA_AUTO) { | ||
306 | p->dma = PARPORT_DMA_NONE; | ||
307 | } | ||
308 | } | ||
309 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq | ||
310 | is mandatory (see above) */ | ||
311 | p->dma = PARPORT_DMA_NONE; | ||
312 | |||
313 | printk(" ["); | ||
314 | #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}} | ||
315 | { | ||
316 | int f = 0; | ||
317 | printmode(PCSPP); | ||
318 | printmode(TRISTATE); | ||
319 | printmode(COMPAT) | ||
320 | printmode(EPP); | ||
321 | // printmode(ECP); | ||
322 | // printmode(DMA); | ||
323 | } | ||
324 | #undef printmode | ||
325 | printk("]\n"); | ||
326 | |||
327 | if (p->irq != PARPORT_IRQ_NONE) { | ||
328 | if (request_irq (p->irq, parport_gsc_interrupt, | ||
329 | 0, p->name, p)) { | ||
330 | printk (KERN_WARNING "%s: irq %d in use, " | ||
331 | "resorting to polled operation\n", | ||
332 | p->name, p->irq); | ||
333 | p->irq = PARPORT_IRQ_NONE; | ||
334 | p->dma = PARPORT_DMA_NONE; | ||
335 | } | ||
336 | } | ||
337 | |||
338 | /* Done probing. Now put the port into a sensible start-up state. */ | ||
339 | |||
340 | parport_gsc_write_data(p, 0); | ||
341 | parport_gsc_data_forward (p); | ||
342 | |||
343 | /* Now that we've told the sharing engine about the port, and | ||
344 | found out its characteristics, let the high-level drivers | ||
345 | know about it. */ | ||
346 | parport_announce_port (p); | ||
347 | |||
348 | return p; | ||
349 | } | ||
350 | |||
351 | |||
352 | #define PARPORT_GSC_OFFSET 0x800 | ||
353 | |||
354 | static int __initdata parport_count; | ||
355 | |||
356 | static int __devinit parport_init_chip(struct parisc_device *dev) | ||
357 | { | ||
358 | struct parport *p; | ||
359 | unsigned long port; | ||
360 | |||
361 | if (!dev->irq) { | ||
362 | printk("IRQ not found for parallel device at 0x%lx\n", dev->hpa); | ||
363 | return -ENODEV; | ||
364 | } | ||
365 | |||
366 | port = dev->hpa + PARPORT_GSC_OFFSET; | ||
367 | |||
368 | /* some older machines with ASP-chip don't support | ||
369 | * the enhanced parport modes. | ||
370 | */ | ||
371 | if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) { | ||
372 | |||
373 | /* Initialize bidirectional-mode (0x10) & data-tranfer-mode #1 (0x20) */ | ||
374 | printk("%s: initialize bidirectional-mode.\n", __FUNCTION__); | ||
375 | parport_writeb ( (0x10 + 0x20), port + 4); | ||
376 | |||
377 | } else { | ||
378 | printk("%s: enhanced parport-modes not supported.\n", __FUNCTION__); | ||
379 | } | ||
380 | |||
381 | p = parport_gsc_probe_port(port, 0, dev->irq, | ||
382 | /* PARPORT_IRQ_NONE */ PARPORT_DMA_NONE, NULL); | ||
383 | if (p) | ||
384 | parport_count++; | ||
385 | dev->dev.driver_data = p; | ||
386 | |||
387 | return 0; | ||
388 | } | ||
389 | |||
390 | static int __devexit parport_remove_chip(struct parisc_device *dev) | ||
391 | { | ||
392 | struct parport *p = dev->dev.driver_data; | ||
393 | if (p) { | ||
394 | struct parport_gsc_private *priv = p->private_data; | ||
395 | struct parport_operations *ops = p->ops; | ||
396 | parport_remove_port(p); | ||
397 | if (p->dma != PARPORT_DMA_NONE) | ||
398 | free_dma(p->dma); | ||
399 | if (p->irq != PARPORT_IRQ_NONE) | ||
400 | free_irq(p->irq, p); | ||
401 | if (priv->dma_buf) | ||
402 | pci_free_consistent(priv->dev, PAGE_SIZE, | ||
403 | priv->dma_buf, | ||
404 | priv->dma_handle); | ||
405 | kfree (p->private_data); | ||
406 | parport_put_port(p); | ||
407 | kfree (ops); /* hope no-one cached it */ | ||
408 | } | ||
409 | return 0; | ||
410 | } | ||
411 | |||
412 | static struct parisc_device_id parport_tbl[] = { | ||
413 | { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x74 }, | ||
414 | { 0, } | ||
415 | }; | ||
416 | |||
417 | MODULE_DEVICE_TABLE(parisc, parport_tbl); | ||
418 | |||
419 | static struct parisc_driver parport_driver = { | ||
420 | .name = "Parallel", | ||
421 | .id_table = parport_tbl, | ||
422 | .probe = parport_init_chip, | ||
423 | .remove = __devexit_p(parport_remove_chip), | ||
424 | }; | ||
425 | |||
426 | int __devinit parport_gsc_init(void) | ||
427 | { | ||
428 | return register_parisc_driver(&parport_driver); | ||
429 | } | ||
430 | |||
431 | static void __devexit parport_gsc_exit(void) | ||
432 | { | ||
433 | unregister_parisc_driver(&parport_driver); | ||
434 | } | ||
435 | |||
436 | module_init(parport_gsc_init); | ||
437 | module_exit(parport_gsc_exit); | ||
diff --git a/drivers/parport/parport_gsc.h b/drivers/parport/parport_gsc.h new file mode 100644 index 000000000000..662f6c1fee5d --- /dev/null +++ b/drivers/parport/parport_gsc.h | |||
@@ -0,0 +1,222 @@ | |||
1 | /* | ||
2 | * Low-level parallel-support for PC-style hardware integrated in the | ||
3 | * LASI-Controller (on GSC-Bus) for HP-PARISC Workstations | ||
4 | * | ||
5 | * (C) 1999-2001 by Helge Deller <deller@gmx.de> | ||
6 | * | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify | ||
9 | * it under the terms of the GNU General Public License as published by | ||
10 | * the Free Software Foundation; either version 2 of the License, or | ||
11 | * (at your option) any later version. | ||
12 | * | ||
13 | * This program is distributed in the hope that it will be useful, | ||
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
16 | * GNU General Public License for more details. | ||
17 | * | ||
18 | * You should have received a copy of the GNU General Public License | ||
19 | * along with this program; if not, write to the Free Software | ||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
21 | * | ||
22 | * based on parport_pc.c by | ||
23 | * Grant Guenther <grant@torque.net> | ||
24 | * Phil Blundell <Philip.Blundell@pobox.com> | ||
25 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
26 | * Jose Renau <renau@acm.org> | ||
27 | * David Campbell <campbell@torque.net> | ||
28 | * Andrea Arcangeli | ||
29 | */ | ||
30 | |||
31 | #ifndef __DRIVERS_PARPORT_PARPORT_GSC_H | ||
32 | #define __DRIVERS_PARPORT_PARPORT_GSC_H | ||
33 | |||
34 | #include <asm/io.h> | ||
35 | #include <linux/delay.h> | ||
36 | |||
37 | #undef DEBUG_PARPORT /* undefine for production */ | ||
38 | #define DELAY_TIME 0 | ||
39 | |||
40 | #if DELAY_TIME == 0 | ||
41 | #define parport_readb gsc_readb | ||
42 | #define parport_writeb gsc_writeb | ||
43 | #else | ||
44 | static __inline__ unsigned char parport_readb( unsigned long port ) | ||
45 | { | ||
46 | udelay(DELAY_TIME); | ||
47 | return gsc_readb(port); | ||
48 | } | ||
49 | |||
50 | static __inline__ void parport_writeb( unsigned char value, unsigned long port ) | ||
51 | { | ||
52 | gsc_writeb(value,port); | ||
53 | udelay(DELAY_TIME); | ||
54 | } | ||
55 | #endif | ||
56 | |||
57 | /* --- register definitions ------------------------------- */ | ||
58 | |||
59 | #define EPPDATA(p) ((p)->base + 0x4) | ||
60 | #define EPPADDR(p) ((p)->base + 0x3) | ||
61 | #define CONTROL(p) ((p)->base + 0x2) | ||
62 | #define STATUS(p) ((p)->base + 0x1) | ||
63 | #define DATA(p) ((p)->base + 0x0) | ||
64 | |||
65 | struct parport_gsc_private { | ||
66 | /* Contents of CTR. */ | ||
67 | unsigned char ctr; | ||
68 | |||
69 | /* Bitmask of writable CTR bits. */ | ||
70 | unsigned char ctr_writable; | ||
71 | |||
72 | /* Number of bytes per portword. */ | ||
73 | int pword; | ||
74 | |||
75 | /* Not used yet. */ | ||
76 | int readIntrThreshold; | ||
77 | int writeIntrThreshold; | ||
78 | |||
79 | /* buffer suitable for DMA, if DMA enabled */ | ||
80 | char *dma_buf; | ||
81 | dma_addr_t dma_handle; | ||
82 | struct pci_dev *dev; | ||
83 | }; | ||
84 | |||
85 | static inline void parport_gsc_write_data(struct parport *p, unsigned char d) | ||
86 | { | ||
87 | #ifdef DEBUG_PARPORT | ||
88 | printk (KERN_DEBUG "parport_gsc_write_data(%p,0x%02x)\n", p, d); | ||
89 | #endif | ||
90 | parport_writeb(d, DATA(p)); | ||
91 | } | ||
92 | |||
93 | static inline unsigned char parport_gsc_read_data(struct parport *p) | ||
94 | { | ||
95 | unsigned char val = parport_readb (DATA (p)); | ||
96 | #ifdef DEBUG_PARPORT | ||
97 | printk (KERN_DEBUG "parport_gsc_read_data(%p) = 0x%02x\n", | ||
98 | p, val); | ||
99 | #endif | ||
100 | return val; | ||
101 | } | ||
102 | |||
103 | /* __parport_gsc_frob_control differs from parport_gsc_frob_control in that | ||
104 | * it doesn't do any extra masking. */ | ||
105 | static inline unsigned char __parport_gsc_frob_control(struct parport *p, | ||
106 | unsigned char mask, | ||
107 | unsigned char val) | ||
108 | { | ||
109 | struct parport_gsc_private *priv = p->physport->private_data; | ||
110 | unsigned char ctr = priv->ctr; | ||
111 | #ifdef DEBUG_PARPORT | ||
112 | printk (KERN_DEBUG | ||
113 | "__parport_gsc_frob_control(%02x,%02x): %02x -> %02x\n", | ||
114 | mask, val, ctr, ((ctr & ~mask) ^ val) & priv->ctr_writable); | ||
115 | #endif | ||
116 | ctr = (ctr & ~mask) ^ val; | ||
117 | ctr &= priv->ctr_writable; /* only write writable bits. */ | ||
118 | parport_writeb (ctr, CONTROL (p)); | ||
119 | priv->ctr = ctr; /* Update soft copy */ | ||
120 | return ctr; | ||
121 | } | ||
122 | |||
123 | static inline void parport_gsc_data_reverse(struct parport *p) | ||
124 | { | ||
125 | __parport_gsc_frob_control (p, 0x20, 0x20); | ||
126 | } | ||
127 | |||
128 | static inline void parport_gsc_data_forward(struct parport *p) | ||
129 | { | ||
130 | __parport_gsc_frob_control (p, 0x20, 0x00); | ||
131 | } | ||
132 | |||
133 | static inline void parport_gsc_write_control(struct parport *p, | ||
134 | unsigned char d) | ||
135 | { | ||
136 | const unsigned char wm = (PARPORT_CONTROL_STROBE | | ||
137 | PARPORT_CONTROL_AUTOFD | | ||
138 | PARPORT_CONTROL_INIT | | ||
139 | PARPORT_CONTROL_SELECT); | ||
140 | |||
141 | /* Take this out when drivers have adapted to newer interface. */ | ||
142 | if (d & 0x20) { | ||
143 | printk (KERN_DEBUG "%s (%s): use data_reverse for this!\n", | ||
144 | p->name, p->cad->name); | ||
145 | parport_gsc_data_reverse (p); | ||
146 | } | ||
147 | |||
148 | __parport_gsc_frob_control (p, wm, d & wm); | ||
149 | } | ||
150 | |||
151 | static inline unsigned char parport_gsc_read_control(struct parport *p) | ||
152 | { | ||
153 | const unsigned char rm = (PARPORT_CONTROL_STROBE | | ||
154 | PARPORT_CONTROL_AUTOFD | | ||
155 | PARPORT_CONTROL_INIT | | ||
156 | PARPORT_CONTROL_SELECT); | ||
157 | const struct parport_gsc_private *priv = p->physport->private_data; | ||
158 | return priv->ctr & rm; /* Use soft copy */ | ||
159 | } | ||
160 | |||
161 | static inline unsigned char parport_gsc_frob_control(struct parport *p, | ||
162 | unsigned char mask, | ||
163 | unsigned char val) | ||
164 | { | ||
165 | const unsigned char wm = (PARPORT_CONTROL_STROBE | | ||
166 | PARPORT_CONTROL_AUTOFD | | ||
167 | PARPORT_CONTROL_INIT | | ||
168 | PARPORT_CONTROL_SELECT); | ||
169 | |||
170 | /* Take this out when drivers have adapted to newer interface. */ | ||
171 | if (mask & 0x20) { | ||
172 | printk (KERN_DEBUG "%s (%s): use data_%s for this!\n", | ||
173 | p->name, p->cad->name, | ||
174 | (val & 0x20) ? "reverse" : "forward"); | ||
175 | if (val & 0x20) | ||
176 | parport_gsc_data_reverse (p); | ||
177 | else | ||
178 | parport_gsc_data_forward (p); | ||
179 | } | ||
180 | |||
181 | /* Restrict mask and val to control lines. */ | ||
182 | mask &= wm; | ||
183 | val &= wm; | ||
184 | |||
185 | return __parport_gsc_frob_control (p, mask, val); | ||
186 | } | ||
187 | |||
188 | static inline unsigned char parport_gsc_read_status(struct parport *p) | ||
189 | { | ||
190 | return parport_readb (STATUS(p)); | ||
191 | } | ||
192 | |||
193 | static inline void parport_gsc_disable_irq(struct parport *p) | ||
194 | { | ||
195 | __parport_gsc_frob_control (p, 0x10, 0x00); | ||
196 | } | ||
197 | |||
198 | static inline void parport_gsc_enable_irq(struct parport *p) | ||
199 | { | ||
200 | __parport_gsc_frob_control (p, 0x10, 0x10); | ||
201 | } | ||
202 | |||
203 | extern void parport_gsc_release_resources(struct parport *p); | ||
204 | |||
205 | extern int parport_gsc_claim_resources(struct parport *p); | ||
206 | |||
207 | extern void parport_gsc_init_state(struct pardevice *, struct parport_state *s); | ||
208 | |||
209 | extern void parport_gsc_save_state(struct parport *p, struct parport_state *s); | ||
210 | |||
211 | extern void parport_gsc_restore_state(struct parport *p, struct parport_state *s); | ||
212 | |||
213 | extern void parport_gsc_inc_use_count(void); | ||
214 | |||
215 | extern void parport_gsc_dec_use_count(void); | ||
216 | |||
217 | extern struct parport *parport_gsc_probe_port(unsigned long base, | ||
218 | unsigned long base_hi, | ||
219 | int irq, int dma, | ||
220 | struct pci_dev *dev); | ||
221 | |||
222 | #endif /* __DRIVERS_PARPORT_PARPORT_GSC_H */ | ||
diff --git a/drivers/parport/parport_mfc3.c b/drivers/parport/parport_mfc3.c new file mode 100644 index 000000000000..c85364765ef8 --- /dev/null +++ b/drivers/parport/parport_mfc3.c | |||
@@ -0,0 +1,404 @@ | |||
1 | /* Low-level parallel port routines for the Multiface 3 card | ||
2 | * | ||
3 | * Author: Joerg Dorchain <joerg@dorchain.net> | ||
4 | * | ||
5 | * (C) The elitist m68k Users(TM) | ||
6 | * | ||
7 | * based on the existing parport_amiga and lp_mfc | ||
8 | * | ||
9 | * | ||
10 | * From the MFC3 documentation: | ||
11 | * | ||
12 | * Miscellaneous PIA Details | ||
13 | * ------------------------- | ||
14 | * | ||
15 | * The two open-drain interrupt outputs /IRQA and /IRQB are routed to | ||
16 | * /INT2 of the Z2 bus. | ||
17 | * | ||
18 | * The CPU data bus of the PIA (D0-D7) is connected to D8-D15 on the Z2 | ||
19 | * bus. This means that any PIA registers are accessed at even addresses. | ||
20 | * | ||
21 | * Centronics Pin Connections for the PIA | ||
22 | * -------------------------------------- | ||
23 | * | ||
24 | * The following table shows the connections between the PIA and the | ||
25 | * Centronics interface connector. These connections implement a single, but | ||
26 | * very complete, Centronics type interface. The Pin column gives the pin | ||
27 | * numbers of the PIA. The Centronics pin numbers can be found in the section | ||
28 | * "Parallel Connectors". | ||
29 | * | ||
30 | * | ||
31 | * Pin | PIA | Dir | Centronics Names | ||
32 | * -------+-----+-----+--------------------------------------------------------- | ||
33 | * 19 | CB2 | --> | /STROBE (aka /DRDY) | ||
34 | * 10-17 | PBx | <-> | DATA0 - DATA7 | ||
35 | * 18 | CB1 | <-- | /ACK | ||
36 | * 40 | CA1 | <-- | BUSY | ||
37 | * 3 | PA1 | <-- | PAPER-OUT (aka POUT) | ||
38 | * 4 | PA2 | <-- | SELECTED (aka SEL) | ||
39 | * 9 | PA7 | --> | /INIT (aka /RESET or /INPUT-PRIME) | ||
40 | * 6 | PA4 | <-- | /ERROR (aka /FAULT) | ||
41 | * 7 | PA5 | --> | DIR (aka /SELECT-IN) | ||
42 | * 8 | PA6 | --> | /AUTO-FEED-XT | ||
43 | * 39 | CA2 | --> | open | ||
44 | * 5 | PA3 | <-- | /ACK (same as CB1!) | ||
45 | * 2 | PA0 | <-- | BUSY (same as CA1!) | ||
46 | * -------+-----+-----+--------------------------------------------------------- | ||
47 | * | ||
48 | * Should be enough to understand some of the driver. | ||
49 | * | ||
50 | * Per convention for normal use the port registers are visible. | ||
51 | * If you need the data direction registers, restore the value in the | ||
52 | * control register. | ||
53 | */ | ||
54 | |||
55 | #include "multiface.h" | ||
56 | #include <linux/module.h> | ||
57 | #include <linux/init.h> | ||
58 | #include <linux/parport.h> | ||
59 | #include <linux/delay.h> | ||
60 | #include <linux/mc6821.h> | ||
61 | #include <linux/zorro.h> | ||
62 | #include <linux/interrupt.h> | ||
63 | #include <asm/setup.h> | ||
64 | #include <asm/amigahw.h> | ||
65 | #include <asm/irq.h> | ||
66 | #include <asm/amigaints.h> | ||
67 | |||
68 | /* Maximum Number of Cards supported */ | ||
69 | #define MAX_MFC 5 | ||
70 | |||
71 | #undef DEBUG | ||
72 | #ifdef DEBUG | ||
73 | #define DPRINTK printk | ||
74 | #else | ||
75 | static inline int DPRINTK(void *nothing, ...) {return 0;} | ||
76 | #endif | ||
77 | |||
78 | static struct parport *this_port[MAX_MFC] = {NULL, }; | ||
79 | static volatile int dummy; /* for trigger readds */ | ||
80 | |||
81 | #define pia(dev) ((struct pia *)(dev->base)) | ||
82 | static struct parport_operations pp_mfc3_ops; | ||
83 | |||
84 | static void mfc3_write_data(struct parport *p, unsigned char data) | ||
85 | { | ||
86 | DPRINTK(KERN_DEBUG "write_data %c\n",data); | ||
87 | |||
88 | dummy = pia(p)->pprb; /* clears irq bit */ | ||
89 | /* Triggers also /STROBE.*/ | ||
90 | pia(p)->pprb = data; | ||
91 | } | ||
92 | |||
93 | static unsigned char mfc3_read_data(struct parport *p) | ||
94 | { | ||
95 | /* clears interrupt bit. Triggers also /STROBE. */ | ||
96 | return pia(p)->pprb; | ||
97 | } | ||
98 | |||
99 | static unsigned char control_pc_to_mfc3(unsigned char control) | ||
100 | { | ||
101 | unsigned char ret = 32|64; | ||
102 | |||
103 | if (control & PARPORT_CONTROL_SELECT) /* XXX: What is SELECP? */ | ||
104 | ret &= ~32; /* /SELECT_IN */ | ||
105 | if (control & PARPORT_CONTROL_INIT) /* INITP */ | ||
106 | ret |= 128; | ||
107 | if (control & PARPORT_CONTROL_AUTOFD) /* AUTOLF */ | ||
108 | ret &= ~64; | ||
109 | if (control & PARPORT_CONTROL_STROBE) /* Strobe */ | ||
110 | /* Handled directly by hardware */; | ||
111 | return ret; | ||
112 | } | ||
113 | |||
114 | static unsigned char control_mfc3_to_pc(unsigned char control) | ||
115 | { | ||
116 | unsigned char ret = PARPORT_CONTROL_STROBE | ||
117 | | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_SELECT; | ||
118 | |||
119 | if (control & 128) /* /INITP */ | ||
120 | ret |= PARPORT_CONTROL_INIT; | ||
121 | if (control & 64) /* /AUTOLF */ | ||
122 | ret &= ~PARPORT_CONTROL_AUTOFD; | ||
123 | if (control & 32) /* /SELECT_IN */ | ||
124 | ret &= ~PARPORT_CONTROL_SELECT; | ||
125 | return ret; | ||
126 | } | ||
127 | |||
128 | static void mfc3_write_control(struct parport *p, unsigned char control) | ||
129 | { | ||
130 | DPRINTK(KERN_DEBUG "write_control %02x\n",control); | ||
131 | pia(p)->ppra = (pia(p)->ppra & 0x1f) | control_pc_to_mfc3(control); | ||
132 | } | ||
133 | |||
134 | static unsigned char mfc3_read_control( struct parport *p) | ||
135 | { | ||
136 | DPRINTK(KERN_DEBUG "read_control \n"); | ||
137 | return control_mfc3_to_pc(pia(p)->ppra & 0xe0); | ||
138 | } | ||
139 | |||
140 | static unsigned char mfc3_frob_control( struct parport *p, unsigned char mask, unsigned char val) | ||
141 | { | ||
142 | unsigned char old; | ||
143 | |||
144 | DPRINTK(KERN_DEBUG "frob_control mask %02x, value %02x\n",mask,val); | ||
145 | old = mfc3_read_control(p); | ||
146 | mfc3_write_control(p, (old & ~mask) ^ val); | ||
147 | return old; | ||
148 | } | ||
149 | |||
150 | #if 0 /* currently unused */ | ||
151 | static unsigned char status_pc_to_mfc3(unsigned char status) | ||
152 | { | ||
153 | unsigned char ret = 1; | ||
154 | |||
155 | if (status & PARPORT_STATUS_BUSY) /* Busy */ | ||
156 | ret &= ~1; | ||
157 | if (status & PARPORT_STATUS_ACK) /* Ack */ | ||
158 | ret |= 8; | ||
159 | if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */ | ||
160 | ret |= 2; | ||
161 | if (status & PARPORT_STATUS_SELECT) /* select */ | ||
162 | ret |= 4; | ||
163 | if (status & PARPORT_STATUS_ERROR) /* error */ | ||
164 | ret |= 16; | ||
165 | return ret; | ||
166 | } | ||
167 | #endif | ||
168 | |||
169 | static unsigned char status_mfc3_to_pc(unsigned char status) | ||
170 | { | ||
171 | unsigned char ret = PARPORT_STATUS_BUSY; | ||
172 | |||
173 | if (status & 1) /* Busy */ | ||
174 | ret &= ~PARPORT_STATUS_BUSY; | ||
175 | if (status & 2) /* PaperOut */ | ||
176 | ret |= PARPORT_STATUS_PAPEROUT; | ||
177 | if (status & 4) /* Selected */ | ||
178 | ret |= PARPORT_STATUS_SELECT; | ||
179 | if (status & 8) /* Ack */ | ||
180 | ret |= PARPORT_STATUS_ACK; | ||
181 | if (status & 16) /* /ERROR */ | ||
182 | ret |= PARPORT_STATUS_ERROR; | ||
183 | |||
184 | return ret; | ||
185 | } | ||
186 | |||
187 | #if 0 /* currently unused */ | ||
188 | static void mfc3_write_status( struct parport *p, unsigned char status) | ||
189 | { | ||
190 | DPRINTK(KERN_DEBUG "write_status %02x\n",status); | ||
191 | pia(p)->ppra = (pia(p)->ppra & 0xe0) | status_pc_to_mfc3(status); | ||
192 | } | ||
193 | #endif | ||
194 | |||
195 | static unsigned char mfc3_read_status(struct parport *p) | ||
196 | { | ||
197 | unsigned char status; | ||
198 | |||
199 | status = status_mfc3_to_pc(pia(p)->ppra & 0x1f); | ||
200 | DPRINTK(KERN_DEBUG "read_status %02x\n", status); | ||
201 | return status; | ||
202 | } | ||
203 | |||
204 | #if 0 /* currently unused */ | ||
205 | static void mfc3_change_mode( struct parport *p, int m) | ||
206 | { | ||
207 | /* XXX: This port only has one mode, and I am | ||
208 | not sure about the corresponding PC-style mode*/ | ||
209 | } | ||
210 | #endif | ||
211 | |||
212 | static int use_cnt = 0; | ||
213 | |||
214 | static irqreturn_t mfc3_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
215 | { | ||
216 | int i; | ||
217 | |||
218 | for( i = 0; i < MAX_MFC; i++) | ||
219 | if (this_port[i] != NULL) | ||
220 | if (pia(this_port[i])->crb & 128) { /* Board caused interrupt */ | ||
221 | dummy = pia(this_port[i])->pprb; /* clear irq bit */ | ||
222 | parport_generic_irq(irq, this_port[i], regs); | ||
223 | } | ||
224 | return IRQ_HANDLED; | ||
225 | } | ||
226 | |||
227 | static void mfc3_enable_irq(struct parport *p) | ||
228 | { | ||
229 | pia(p)->crb |= PIA_C1_ENABLE_IRQ; | ||
230 | } | ||
231 | |||
232 | static void mfc3_disable_irq(struct parport *p) | ||
233 | { | ||
234 | pia(p)->crb &= ~PIA_C1_ENABLE_IRQ; | ||
235 | } | ||
236 | |||
237 | static void mfc3_data_forward(struct parport *p) | ||
238 | { | ||
239 | DPRINTK(KERN_DEBUG "forward\n"); | ||
240 | pia(p)->crb &= ~PIA_DDR; /* make data direction register visible */ | ||
241 | pia(p)->pddrb = 255; /* all pins output */ | ||
242 | pia(p)->crb |= PIA_DDR; /* make data register visible - default */ | ||
243 | } | ||
244 | |||
245 | static void mfc3_data_reverse(struct parport *p) | ||
246 | { | ||
247 | DPRINTK(KERN_DEBUG "reverse\n"); | ||
248 | pia(p)->crb &= ~PIA_DDR; /* make data direction register visible */ | ||
249 | pia(p)->pddrb = 0; /* all pins input */ | ||
250 | pia(p)->crb |= PIA_DDR; /* make data register visible - default */ | ||
251 | } | ||
252 | |||
253 | static void mfc3_init_state(struct pardevice *dev, struct parport_state *s) | ||
254 | { | ||
255 | s->u.amiga.data = 0; | ||
256 | s->u.amiga.datadir = 255; | ||
257 | s->u.amiga.status = 0; | ||
258 | s->u.amiga.statusdir = 0xe0; | ||
259 | } | ||
260 | |||
261 | static void mfc3_save_state(struct parport *p, struct parport_state *s) | ||
262 | { | ||
263 | s->u.amiga.data = pia(p)->pprb; | ||
264 | pia(p)->crb &= ~PIA_DDR; | ||
265 | s->u.amiga.datadir = pia(p)->pddrb; | ||
266 | pia(p)->crb |= PIA_DDR; | ||
267 | s->u.amiga.status = pia(p)->ppra; | ||
268 | pia(p)->cra &= ~PIA_DDR; | ||
269 | s->u.amiga.statusdir = pia(p)->pddrb; | ||
270 | pia(p)->cra |= PIA_DDR; | ||
271 | } | ||
272 | |||
273 | static void mfc3_restore_state(struct parport *p, struct parport_state *s) | ||
274 | { | ||
275 | pia(p)->pprb = s->u.amiga.data; | ||
276 | pia(p)->crb &= ~PIA_DDR; | ||
277 | pia(p)->pddrb = s->u.amiga.datadir; | ||
278 | pia(p)->crb |= PIA_DDR; | ||
279 | pia(p)->ppra = s->u.amiga.status; | ||
280 | pia(p)->cra &= ~PIA_DDR; | ||
281 | pia(p)->pddrb = s->u.amiga.statusdir; | ||
282 | pia(p)->cra |= PIA_DDR; | ||
283 | } | ||
284 | |||
285 | static struct parport_operations pp_mfc3_ops = { | ||
286 | .write_data = mfc3_write_data, | ||
287 | .read_data = mfc3_read_data, | ||
288 | |||
289 | .write_control = mfc3_write_control, | ||
290 | .read_control = mfc3_read_control, | ||
291 | .frob_control = mfc3_frob_control, | ||
292 | |||
293 | .read_status = mfc3_read_status, | ||
294 | |||
295 | .enable_irq = mfc3_enable_irq, | ||
296 | .disable_irq = mfc3_disable_irq, | ||
297 | |||
298 | .data_forward = mfc3_data_forward, | ||
299 | .data_reverse = mfc3_data_reverse, | ||
300 | |||
301 | .init_state = mfc3_init_state, | ||
302 | .save_state = mfc3_save_state, | ||
303 | .restore_state = mfc3_restore_state, | ||
304 | |||
305 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
306 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
307 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
308 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
309 | |||
310 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
311 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
312 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
313 | |||
314 | .compat_write_data = parport_ieee1284_write_compat, | ||
315 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
316 | .byte_read_data = parport_ieee1284_read_byte, | ||
317 | |||
318 | .owner = THIS_MODULE, | ||
319 | }; | ||
320 | |||
321 | /* ----------- Initialisation code --------------------------------- */ | ||
322 | |||
323 | static int __init parport_mfc3_init(void) | ||
324 | { | ||
325 | struct parport *p; | ||
326 | int pias = 0; | ||
327 | struct pia *pp; | ||
328 | struct zorro_dev *z = NULL; | ||
329 | |||
330 | if (!MACH_IS_AMIGA) | ||
331 | return -ENODEV; | ||
332 | |||
333 | while ((z = zorro_find_device(ZORRO_PROD_BSC_MULTIFACE_III, z))) { | ||
334 | unsigned long piabase = z->resource.start+PIABASE; | ||
335 | if (!request_mem_region(piabase, sizeof(struct pia), "PIA")) | ||
336 | continue; | ||
337 | |||
338 | pp = (struct pia *)ZTWO_VADDR(piabase); | ||
339 | pp->crb = 0; | ||
340 | pp->pddrb = 255; /* all data pins output */ | ||
341 | pp->crb = PIA_DDR|32|8; | ||
342 | dummy = pp->pddrb; /* reading clears interrupt */ | ||
343 | pp->cra = 0; | ||
344 | pp->pddra = 0xe0; /* /RESET, /DIR ,/AUTO-FEED output */ | ||
345 | pp->cra = PIA_DDR; | ||
346 | pp->ppra = 0; /* reset printer */ | ||
347 | udelay(10); | ||
348 | pp->ppra = 128; | ||
349 | p = parport_register_port((unsigned long)pp, IRQ_AMIGA_PORTS, | ||
350 | PARPORT_DMA_NONE, &pp_mfc3_ops); | ||
351 | if (!p) | ||
352 | goto out_port; | ||
353 | |||
354 | if (p->irq != PARPORT_IRQ_NONE) { | ||
355 | if (use_cnt++ == 0) | ||
356 | if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, SA_SHIRQ, p->name, &pp_mfc3_ops)) | ||
357 | goto out_irq; | ||
358 | } | ||
359 | |||
360 | this_port[pias++] = p; | ||
361 | printk(KERN_INFO "%s: Multiface III port using irq\n", p->name); | ||
362 | /* XXX: set operating mode */ | ||
363 | |||
364 | p->private_data = (void *)piabase; | ||
365 | parport_announce_port (p); | ||
366 | |||
367 | if (pias >= MAX_MFC) | ||
368 | break; | ||
369 | continue; | ||
370 | |||
371 | out_irq: | ||
372 | parport_put_port(p); | ||
373 | out_port: | ||
374 | release_mem_region(piabase, sizeof(struct pia)); | ||
375 | } | ||
376 | |||
377 | return pias ? 0 : -ENODEV; | ||
378 | } | ||
379 | |||
380 | static void __exit parport_mfc3_exit(void) | ||
381 | { | ||
382 | int i; | ||
383 | |||
384 | for (i = 0; i < MAX_MFC; i++) { | ||
385 | if (!this_port[i]) | ||
386 | continue; | ||
387 | parport_remove_port(this_port[i]); | ||
388 | if (!this_port[i]->irq != PARPORT_IRQ_NONE) { | ||
389 | if (--use_cnt == 0) | ||
390 | free_irq(IRQ_AMIGA_PORTS, &pp_mfc3_ops); | ||
391 | } | ||
392 | release_mem_region(ZTWO_PADDR(this_port[i]->private_data), sizeof(struct pia)); | ||
393 | parport_put_port(this_port[i]); | ||
394 | } | ||
395 | } | ||
396 | |||
397 | |||
398 | MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>"); | ||
399 | MODULE_DESCRIPTION("Parport Driver for Multiface 3 expansion cards Paralllel Port"); | ||
400 | MODULE_SUPPORTED_DEVICE("Multiface 3 Parallel Port"); | ||
401 | MODULE_LICENSE("GPL"); | ||
402 | |||
403 | module_init(parport_mfc3_init) | ||
404 | module_exit(parport_mfc3_exit) | ||
diff --git a/drivers/parport/parport_pc.c b/drivers/parport/parport_pc.c new file mode 100644 index 000000000000..c5774e7855d0 --- /dev/null +++ b/drivers/parport/parport_pc.c | |||
@@ -0,0 +1,3415 @@ | |||
1 | /* Low-level parallel-port routines for 8255-based PC-style hardware. | ||
2 | * | ||
3 | * Authors: Phil Blundell <philb@gnu.org> | ||
4 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
5 | * Jose Renau <renau@acm.org> | ||
6 | * David Campbell <campbell@torque.net> | ||
7 | * Andrea Arcangeli | ||
8 | * | ||
9 | * based on work by Grant Guenther <grant@torque.net> and Phil Blundell. | ||
10 | * | ||
11 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> | ||
12 | * DMA support - Bert De Jonghe <bert@sophis.be> | ||
13 | * Many ECP bugs fixed. Fred Barnes & Jamie Lokier, 1999 | ||
14 | * More PCI support now conditional on CONFIG_PCI, 03/2001, Paul G. | ||
15 | * Various hacks, Fred Barnes, 04/2001 | ||
16 | * Updated probing logic - Adam Belay <ambx1@neo.rr.com> | ||
17 | */ | ||
18 | |||
19 | /* This driver should work with any hardware that is broadly compatible | ||
20 | * with that in the IBM PC. This applies to the majority of integrated | ||
21 | * I/O chipsets that are commonly available. The expected register | ||
22 | * layout is: | ||
23 | * | ||
24 | * base+0 data | ||
25 | * base+1 status | ||
26 | * base+2 control | ||
27 | * | ||
28 | * In addition, there are some optional registers: | ||
29 | * | ||
30 | * base+3 EPP address | ||
31 | * base+4 EPP data | ||
32 | * base+0x400 ECP config A | ||
33 | * base+0x401 ECP config B | ||
34 | * base+0x402 ECP control | ||
35 | * | ||
36 | * All registers are 8 bits wide and read/write. If your hardware differs | ||
37 | * only in register addresses (eg because your registers are on 32-bit | ||
38 | * word boundaries) then you can alter the constants in parport_pc.h to | ||
39 | * accommodate this. | ||
40 | * | ||
41 | * Note that the ECP registers may not start at offset 0x400 for PCI cards, | ||
42 | * but rather will start at port->base_hi. | ||
43 | */ | ||
44 | |||
45 | #include <linux/config.h> | ||
46 | #include <linux/module.h> | ||
47 | #include <linux/init.h> | ||
48 | #include <linux/sched.h> | ||
49 | #include <linux/delay.h> | ||
50 | #include <linux/errno.h> | ||
51 | #include <linux/interrupt.h> | ||
52 | #include <linux/ioport.h> | ||
53 | #include <linux/kernel.h> | ||
54 | #include <linux/slab.h> | ||
55 | #include <linux/pci.h> | ||
56 | #include <linux/pnp.h> | ||
57 | #include <linux/sysctl.h> | ||
58 | |||
59 | #include <asm/io.h> | ||
60 | #include <asm/dma.h> | ||
61 | #include <asm/uaccess.h> | ||
62 | |||
63 | #include <linux/parport.h> | ||
64 | #include <linux/parport_pc.h> | ||
65 | #include <linux/via.h> | ||
66 | #include <asm/parport.h> | ||
67 | |||
68 | #define PARPORT_PC_MAX_PORTS PARPORT_MAX | ||
69 | |||
70 | /* ECR modes */ | ||
71 | #define ECR_SPP 00 | ||
72 | #define ECR_PS2 01 | ||
73 | #define ECR_PPF 02 | ||
74 | #define ECR_ECP 03 | ||
75 | #define ECR_EPP 04 | ||
76 | #define ECR_VND 05 | ||
77 | #define ECR_TST 06 | ||
78 | #define ECR_CNF 07 | ||
79 | #define ECR_MODE_MASK 0xe0 | ||
80 | #define ECR_WRITE(p,v) frob_econtrol((p),0xff,(v)) | ||
81 | |||
82 | #undef DEBUG | ||
83 | |||
84 | #ifdef DEBUG | ||
85 | #define DPRINTK printk | ||
86 | #else | ||
87 | #define DPRINTK(stuff...) | ||
88 | #endif | ||
89 | |||
90 | |||
91 | #define NR_SUPERIOS 3 | ||
92 | static struct superio_struct { /* For Super-IO chips autodetection */ | ||
93 | int io; | ||
94 | int irq; | ||
95 | int dma; | ||
96 | } superios[NR_SUPERIOS] __devinitdata = { {0,},}; | ||
97 | |||
98 | static int user_specified; | ||
99 | #if defined(CONFIG_PARPORT_PC_SUPERIO) || \ | ||
100 | (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO)) | ||
101 | static int verbose_probing; | ||
102 | #endif | ||
103 | static int pci_registered_parport; | ||
104 | static int pnp_registered_parport; | ||
105 | |||
106 | /* frob_control, but for ECR */ | ||
107 | static void frob_econtrol (struct parport *pb, unsigned char m, | ||
108 | unsigned char v) | ||
109 | { | ||
110 | unsigned char ectr = 0; | ||
111 | |||
112 | if (m != 0xff) | ||
113 | ectr = inb (ECONTROL (pb)); | ||
114 | |||
115 | DPRINTK (KERN_DEBUG "frob_econtrol(%02x,%02x): %02x -> %02x\n", | ||
116 | m, v, ectr, (ectr & ~m) ^ v); | ||
117 | |||
118 | outb ((ectr & ~m) ^ v, ECONTROL (pb)); | ||
119 | } | ||
120 | |||
121 | static __inline__ void frob_set_mode (struct parport *p, int mode) | ||
122 | { | ||
123 | frob_econtrol (p, ECR_MODE_MASK, mode << 5); | ||
124 | } | ||
125 | |||
126 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
127 | /* Safely change the mode bits in the ECR | ||
128 | Returns: | ||
129 | 0 : Success | ||
130 | -EBUSY: Could not drain FIFO in some finite amount of time, | ||
131 | mode not changed! | ||
132 | */ | ||
133 | static int change_mode(struct parport *p, int m) | ||
134 | { | ||
135 | const struct parport_pc_private *priv = p->physport->private_data; | ||
136 | unsigned char oecr; | ||
137 | int mode; | ||
138 | |||
139 | DPRINTK(KERN_INFO "parport change_mode ECP-ISA to mode 0x%02x\n",m); | ||
140 | |||
141 | if (!priv->ecr) { | ||
142 | printk (KERN_DEBUG "change_mode: but there's no ECR!\n"); | ||
143 | return 0; | ||
144 | } | ||
145 | |||
146 | /* Bits <7:5> contain the mode. */ | ||
147 | oecr = inb (ECONTROL (p)); | ||
148 | mode = (oecr >> 5) & 0x7; | ||
149 | if (mode == m) return 0; | ||
150 | |||
151 | if (mode >= 2 && !(priv->ctr & 0x20)) { | ||
152 | /* This mode resets the FIFO, so we may | ||
153 | * have to wait for it to drain first. */ | ||
154 | unsigned long expire = jiffies + p->physport->cad->timeout; | ||
155 | int counter; | ||
156 | switch (mode) { | ||
157 | case ECR_PPF: /* Parallel Port FIFO mode */ | ||
158 | case ECR_ECP: /* ECP Parallel Port mode */ | ||
159 | /* Busy wait for 200us */ | ||
160 | for (counter = 0; counter < 40; counter++) { | ||
161 | if (inb (ECONTROL (p)) & 0x01) | ||
162 | break; | ||
163 | if (signal_pending (current)) break; | ||
164 | udelay (5); | ||
165 | } | ||
166 | |||
167 | /* Poll slowly. */ | ||
168 | while (!(inb (ECONTROL (p)) & 0x01)) { | ||
169 | if (time_after_eq (jiffies, expire)) | ||
170 | /* The FIFO is stuck. */ | ||
171 | return -EBUSY; | ||
172 | __set_current_state (TASK_INTERRUPTIBLE); | ||
173 | schedule_timeout ((HZ + 99) / 100); | ||
174 | if (signal_pending (current)) | ||
175 | break; | ||
176 | } | ||
177 | } | ||
178 | } | ||
179 | |||
180 | if (mode >= 2 && m >= 2) { | ||
181 | /* We have to go through mode 001 */ | ||
182 | oecr &= ~(7 << 5); | ||
183 | oecr |= ECR_PS2 << 5; | ||
184 | ECR_WRITE (p, oecr); | ||
185 | } | ||
186 | |||
187 | /* Set the mode. */ | ||
188 | oecr &= ~(7 << 5); | ||
189 | oecr |= m << 5; | ||
190 | ECR_WRITE (p, oecr); | ||
191 | return 0; | ||
192 | } | ||
193 | |||
194 | #ifdef CONFIG_PARPORT_1284 | ||
195 | /* Find FIFO lossage; FIFO is reset */ | ||
196 | #if 0 | ||
197 | static int get_fifo_residue (struct parport *p) | ||
198 | { | ||
199 | int residue; | ||
200 | int cnfga; | ||
201 | const struct parport_pc_private *priv = p->physport->private_data; | ||
202 | |||
203 | /* Adjust for the contents of the FIFO. */ | ||
204 | for (residue = priv->fifo_depth; ; residue--) { | ||
205 | if (inb (ECONTROL (p)) & 0x2) | ||
206 | /* Full up. */ | ||
207 | break; | ||
208 | |||
209 | outb (0, FIFO (p)); | ||
210 | } | ||
211 | |||
212 | printk (KERN_DEBUG "%s: %d PWords were left in FIFO\n", p->name, | ||
213 | residue); | ||
214 | |||
215 | /* Reset the FIFO. */ | ||
216 | frob_set_mode (p, ECR_PS2); | ||
217 | |||
218 | /* Now change to config mode and clean up. FIXME */ | ||
219 | frob_set_mode (p, ECR_CNF); | ||
220 | cnfga = inb (CONFIGA (p)); | ||
221 | printk (KERN_DEBUG "%s: cnfgA contains 0x%02x\n", p->name, cnfga); | ||
222 | |||
223 | if (!(cnfga & (1<<2))) { | ||
224 | printk (KERN_DEBUG "%s: Accounting for extra byte\n", p->name); | ||
225 | residue++; | ||
226 | } | ||
227 | |||
228 | /* Don't care about partial PWords until support is added for | ||
229 | * PWord != 1 byte. */ | ||
230 | |||
231 | /* Back to PS2 mode. */ | ||
232 | frob_set_mode (p, ECR_PS2); | ||
233 | |||
234 | DPRINTK (KERN_DEBUG "*** get_fifo_residue: done residue collecting (ecr = 0x%2.2x)\n", inb (ECONTROL (p))); | ||
235 | return residue; | ||
236 | } | ||
237 | #endif /* 0 */ | ||
238 | #endif /* IEEE 1284 support */ | ||
239 | #endif /* FIFO support */ | ||
240 | |||
241 | /* | ||
242 | * Clear TIMEOUT BIT in EPP MODE | ||
243 | * | ||
244 | * This is also used in SPP detection. | ||
245 | */ | ||
246 | static int clear_epp_timeout(struct parport *pb) | ||
247 | { | ||
248 | unsigned char r; | ||
249 | |||
250 | if (!(parport_pc_read_status(pb) & 0x01)) | ||
251 | return 1; | ||
252 | |||
253 | /* To clear timeout some chips require double read */ | ||
254 | parport_pc_read_status(pb); | ||
255 | r = parport_pc_read_status(pb); | ||
256 | outb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */ | ||
257 | outb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */ | ||
258 | r = parport_pc_read_status(pb); | ||
259 | |||
260 | return !(r & 0x01); | ||
261 | } | ||
262 | |||
263 | /* | ||
264 | * Access functions. | ||
265 | * | ||
266 | * Most of these aren't static because they may be used by the | ||
267 | * parport_xxx_yyy macros. extern __inline__ versions of several | ||
268 | * of these are in parport_pc.h. | ||
269 | */ | ||
270 | |||
271 | static irqreturn_t parport_pc_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
272 | { | ||
273 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
274 | /* FIXME! Was it really ours? */ | ||
275 | return IRQ_HANDLED; | ||
276 | } | ||
277 | |||
278 | static void parport_pc_init_state(struct pardevice *dev, struct parport_state *s) | ||
279 | { | ||
280 | s->u.pc.ctr = 0xc; | ||
281 | if (dev->irq_func && | ||
282 | dev->port->irq != PARPORT_IRQ_NONE) | ||
283 | /* Set ackIntEn */ | ||
284 | s->u.pc.ctr |= 0x10; | ||
285 | |||
286 | s->u.pc.ecr = 0x34; /* NetMos chip can cause problems 0x24; | ||
287 | * D.Gruszka VScom */ | ||
288 | } | ||
289 | |||
290 | static void parport_pc_save_state(struct parport *p, struct parport_state *s) | ||
291 | { | ||
292 | const struct parport_pc_private *priv = p->physport->private_data; | ||
293 | s->u.pc.ctr = priv->ctr; | ||
294 | if (priv->ecr) | ||
295 | s->u.pc.ecr = inb (ECONTROL (p)); | ||
296 | } | ||
297 | |||
298 | static void parport_pc_restore_state(struct parport *p, struct parport_state *s) | ||
299 | { | ||
300 | struct parport_pc_private *priv = p->physport->private_data; | ||
301 | register unsigned char c = s->u.pc.ctr & priv->ctr_writable; | ||
302 | outb (c, CONTROL (p)); | ||
303 | priv->ctr = c; | ||
304 | if (priv->ecr) | ||
305 | ECR_WRITE (p, s->u.pc.ecr); | ||
306 | } | ||
307 | |||
308 | #ifdef CONFIG_PARPORT_1284 | ||
309 | static size_t parport_pc_epp_read_data (struct parport *port, void *buf, | ||
310 | size_t length, int flags) | ||
311 | { | ||
312 | size_t got = 0; | ||
313 | |||
314 | if (flags & PARPORT_W91284PIC) { | ||
315 | unsigned char status; | ||
316 | size_t left = length; | ||
317 | |||
318 | /* use knowledge about data lines..: | ||
319 | * nFault is 0 if there is at least 1 byte in the Warp's FIFO | ||
320 | * pError is 1 if there are 16 bytes in the Warp's FIFO | ||
321 | */ | ||
322 | status = inb (STATUS (port)); | ||
323 | |||
324 | while (!(status & 0x08) && (got < length)) { | ||
325 | if ((left >= 16) && (status & 0x20) && !(status & 0x08)) { | ||
326 | /* can grab 16 bytes from warp fifo */ | ||
327 | if (!((long)buf & 0x03)) { | ||
328 | insl (EPPDATA (port), buf, 4); | ||
329 | } else { | ||
330 | insb (EPPDATA (port), buf, 16); | ||
331 | } | ||
332 | buf += 16; | ||
333 | got += 16; | ||
334 | left -= 16; | ||
335 | } else { | ||
336 | /* grab single byte from the warp fifo */ | ||
337 | *((char *)buf) = inb (EPPDATA (port)); | ||
338 | buf++; | ||
339 | got++; | ||
340 | left--; | ||
341 | } | ||
342 | status = inb (STATUS (port)); | ||
343 | if (status & 0x01) { | ||
344 | /* EPP timeout should never occur... */ | ||
345 | printk (KERN_DEBUG "%s: EPP timeout occurred while talking to " | ||
346 | "w91284pic (should not have done)\n", port->name); | ||
347 | clear_epp_timeout (port); | ||
348 | } | ||
349 | } | ||
350 | return got; | ||
351 | } | ||
352 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | ||
353 | if (!(((long)buf | length) & 0x03)) { | ||
354 | insl (EPPDATA (port), buf, (length >> 2)); | ||
355 | } else { | ||
356 | insb (EPPDATA (port), buf, length); | ||
357 | } | ||
358 | if (inb (STATUS (port)) & 0x01) { | ||
359 | clear_epp_timeout (port); | ||
360 | return -EIO; | ||
361 | } | ||
362 | return length; | ||
363 | } | ||
364 | for (; got < length; got++) { | ||
365 | *((char*)buf) = inb (EPPDATA(port)); | ||
366 | buf++; | ||
367 | if (inb (STATUS (port)) & 0x01) { | ||
368 | /* EPP timeout */ | ||
369 | clear_epp_timeout (port); | ||
370 | break; | ||
371 | } | ||
372 | } | ||
373 | |||
374 | return got; | ||
375 | } | ||
376 | |||
377 | static size_t parport_pc_epp_write_data (struct parport *port, const void *buf, | ||
378 | size_t length, int flags) | ||
379 | { | ||
380 | size_t written = 0; | ||
381 | |||
382 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | ||
383 | if (!(((long)buf | length) & 0x03)) { | ||
384 | outsl (EPPDATA (port), buf, (length >> 2)); | ||
385 | } else { | ||
386 | outsb (EPPDATA (port), buf, length); | ||
387 | } | ||
388 | if (inb (STATUS (port)) & 0x01) { | ||
389 | clear_epp_timeout (port); | ||
390 | return -EIO; | ||
391 | } | ||
392 | return length; | ||
393 | } | ||
394 | for (; written < length; written++) { | ||
395 | outb (*((char*)buf), EPPDATA(port)); | ||
396 | buf++; | ||
397 | if (inb (STATUS(port)) & 0x01) { | ||
398 | clear_epp_timeout (port); | ||
399 | break; | ||
400 | } | ||
401 | } | ||
402 | |||
403 | return written; | ||
404 | } | ||
405 | |||
406 | static size_t parport_pc_epp_read_addr (struct parport *port, void *buf, | ||
407 | size_t length, int flags) | ||
408 | { | ||
409 | size_t got = 0; | ||
410 | |||
411 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | ||
412 | insb (EPPADDR (port), buf, length); | ||
413 | if (inb (STATUS (port)) & 0x01) { | ||
414 | clear_epp_timeout (port); | ||
415 | return -EIO; | ||
416 | } | ||
417 | return length; | ||
418 | } | ||
419 | for (; got < length; got++) { | ||
420 | *((char*)buf) = inb (EPPADDR (port)); | ||
421 | buf++; | ||
422 | if (inb (STATUS (port)) & 0x01) { | ||
423 | clear_epp_timeout (port); | ||
424 | break; | ||
425 | } | ||
426 | } | ||
427 | |||
428 | return got; | ||
429 | } | ||
430 | |||
431 | static size_t parport_pc_epp_write_addr (struct parport *port, | ||
432 | const void *buf, size_t length, | ||
433 | int flags) | ||
434 | { | ||
435 | size_t written = 0; | ||
436 | |||
437 | if ((flags & PARPORT_EPP_FAST) && (length > 1)) { | ||
438 | outsb (EPPADDR (port), buf, length); | ||
439 | if (inb (STATUS (port)) & 0x01) { | ||
440 | clear_epp_timeout (port); | ||
441 | return -EIO; | ||
442 | } | ||
443 | return length; | ||
444 | } | ||
445 | for (; written < length; written++) { | ||
446 | outb (*((char*)buf), EPPADDR (port)); | ||
447 | buf++; | ||
448 | if (inb (STATUS (port)) & 0x01) { | ||
449 | clear_epp_timeout (port); | ||
450 | break; | ||
451 | } | ||
452 | } | ||
453 | |||
454 | return written; | ||
455 | } | ||
456 | |||
457 | static size_t parport_pc_ecpepp_read_data (struct parport *port, void *buf, | ||
458 | size_t length, int flags) | ||
459 | { | ||
460 | size_t got; | ||
461 | |||
462 | frob_set_mode (port, ECR_EPP); | ||
463 | parport_pc_data_reverse (port); | ||
464 | parport_pc_write_control (port, 0x4); | ||
465 | got = parport_pc_epp_read_data (port, buf, length, flags); | ||
466 | frob_set_mode (port, ECR_PS2); | ||
467 | |||
468 | return got; | ||
469 | } | ||
470 | |||
471 | static size_t parport_pc_ecpepp_write_data (struct parport *port, | ||
472 | const void *buf, size_t length, | ||
473 | int flags) | ||
474 | { | ||
475 | size_t written; | ||
476 | |||
477 | frob_set_mode (port, ECR_EPP); | ||
478 | parport_pc_write_control (port, 0x4); | ||
479 | parport_pc_data_forward (port); | ||
480 | written = parport_pc_epp_write_data (port, buf, length, flags); | ||
481 | frob_set_mode (port, ECR_PS2); | ||
482 | |||
483 | return written; | ||
484 | } | ||
485 | |||
486 | static size_t parport_pc_ecpepp_read_addr (struct parport *port, void *buf, | ||
487 | size_t length, int flags) | ||
488 | { | ||
489 | size_t got; | ||
490 | |||
491 | frob_set_mode (port, ECR_EPP); | ||
492 | parport_pc_data_reverse (port); | ||
493 | parport_pc_write_control (port, 0x4); | ||
494 | got = parport_pc_epp_read_addr (port, buf, length, flags); | ||
495 | frob_set_mode (port, ECR_PS2); | ||
496 | |||
497 | return got; | ||
498 | } | ||
499 | |||
500 | static size_t parport_pc_ecpepp_write_addr (struct parport *port, | ||
501 | const void *buf, size_t length, | ||
502 | int flags) | ||
503 | { | ||
504 | size_t written; | ||
505 | |||
506 | frob_set_mode (port, ECR_EPP); | ||
507 | parport_pc_write_control (port, 0x4); | ||
508 | parport_pc_data_forward (port); | ||
509 | written = parport_pc_epp_write_addr (port, buf, length, flags); | ||
510 | frob_set_mode (port, ECR_PS2); | ||
511 | |||
512 | return written; | ||
513 | } | ||
514 | #endif /* IEEE 1284 support */ | ||
515 | |||
516 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
517 | static size_t parport_pc_fifo_write_block_pio (struct parport *port, | ||
518 | const void *buf, size_t length) | ||
519 | { | ||
520 | int ret = 0; | ||
521 | const unsigned char *bufp = buf; | ||
522 | size_t left = length; | ||
523 | unsigned long expire = jiffies + port->physport->cad->timeout; | ||
524 | const int fifo = FIFO (port); | ||
525 | int poll_for = 8; /* 80 usecs */ | ||
526 | const struct parport_pc_private *priv = port->physport->private_data; | ||
527 | const int fifo_depth = priv->fifo_depth; | ||
528 | |||
529 | port = port->physport; | ||
530 | |||
531 | /* We don't want to be interrupted every character. */ | ||
532 | parport_pc_disable_irq (port); | ||
533 | /* set nErrIntrEn and serviceIntr */ | ||
534 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | ||
535 | |||
536 | /* Forward mode. */ | ||
537 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | ||
538 | |||
539 | while (left) { | ||
540 | unsigned char byte; | ||
541 | unsigned char ecrval = inb (ECONTROL (port)); | ||
542 | int i = 0; | ||
543 | |||
544 | if (need_resched() && time_before (jiffies, expire)) | ||
545 | /* Can't yield the port. */ | ||
546 | schedule (); | ||
547 | |||
548 | /* Anyone else waiting for the port? */ | ||
549 | if (port->waithead) { | ||
550 | printk (KERN_DEBUG "Somebody wants the port\n"); | ||
551 | break; | ||
552 | } | ||
553 | |||
554 | if (ecrval & 0x02) { | ||
555 | /* FIFO is full. Wait for interrupt. */ | ||
556 | |||
557 | /* Clear serviceIntr */ | ||
558 | ECR_WRITE (port, ecrval & ~(1<<2)); | ||
559 | false_alarm: | ||
560 | ret = parport_wait_event (port, HZ); | ||
561 | if (ret < 0) break; | ||
562 | ret = 0; | ||
563 | if (!time_before (jiffies, expire)) { | ||
564 | /* Timed out. */ | ||
565 | printk (KERN_DEBUG "FIFO write timed out\n"); | ||
566 | break; | ||
567 | } | ||
568 | ecrval = inb (ECONTROL (port)); | ||
569 | if (!(ecrval & (1<<2))) { | ||
570 | if (need_resched() && | ||
571 | time_before (jiffies, expire)) | ||
572 | schedule (); | ||
573 | |||
574 | goto false_alarm; | ||
575 | } | ||
576 | |||
577 | continue; | ||
578 | } | ||
579 | |||
580 | /* Can't fail now. */ | ||
581 | expire = jiffies + port->cad->timeout; | ||
582 | |||
583 | poll: | ||
584 | if (signal_pending (current)) | ||
585 | break; | ||
586 | |||
587 | if (ecrval & 0x01) { | ||
588 | /* FIFO is empty. Blast it full. */ | ||
589 | const int n = left < fifo_depth ? left : fifo_depth; | ||
590 | outsb (fifo, bufp, n); | ||
591 | bufp += n; | ||
592 | left -= n; | ||
593 | |||
594 | /* Adjust the poll time. */ | ||
595 | if (i < (poll_for - 2)) poll_for--; | ||
596 | continue; | ||
597 | } else if (i++ < poll_for) { | ||
598 | udelay (10); | ||
599 | ecrval = inb (ECONTROL (port)); | ||
600 | goto poll; | ||
601 | } | ||
602 | |||
603 | /* Half-full (call me an optimist) */ | ||
604 | byte = *bufp++; | ||
605 | outb (byte, fifo); | ||
606 | left--; | ||
607 | } | ||
608 | |||
609 | dump_parport_state ("leave fifo_write_block_pio", port); | ||
610 | return length - left; | ||
611 | } | ||
612 | |||
613 | static size_t parport_pc_fifo_write_block_dma (struct parport *port, | ||
614 | const void *buf, size_t length) | ||
615 | { | ||
616 | int ret = 0; | ||
617 | unsigned long dmaflag; | ||
618 | size_t left = length; | ||
619 | const struct parport_pc_private *priv = port->physport->private_data; | ||
620 | dma_addr_t dma_addr, dma_handle; | ||
621 | size_t maxlen = 0x10000; /* max 64k per DMA transfer */ | ||
622 | unsigned long start = (unsigned long) buf; | ||
623 | unsigned long end = (unsigned long) buf + length - 1; | ||
624 | |||
625 | dump_parport_state ("enter fifo_write_block_dma", port); | ||
626 | if (end < MAX_DMA_ADDRESS) { | ||
627 | /* If it would cross a 64k boundary, cap it at the end. */ | ||
628 | if ((start ^ end) & ~0xffffUL) | ||
629 | maxlen = 0x10000 - (start & 0xffff); | ||
630 | |||
631 | dma_addr = dma_handle = pci_map_single(priv->dev, (void *)buf, length, | ||
632 | PCI_DMA_TODEVICE); | ||
633 | } else { | ||
634 | /* above 16 MB we use a bounce buffer as ISA-DMA is not possible */ | ||
635 | maxlen = PAGE_SIZE; /* sizeof(priv->dma_buf) */ | ||
636 | dma_addr = priv->dma_handle; | ||
637 | dma_handle = 0; | ||
638 | } | ||
639 | |||
640 | port = port->physport; | ||
641 | |||
642 | /* We don't want to be interrupted every character. */ | ||
643 | parport_pc_disable_irq (port); | ||
644 | /* set nErrIntrEn and serviceIntr */ | ||
645 | frob_econtrol (port, (1<<4) | (1<<2), (1<<4) | (1<<2)); | ||
646 | |||
647 | /* Forward mode. */ | ||
648 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | ||
649 | |||
650 | while (left) { | ||
651 | unsigned long expire = jiffies + port->physport->cad->timeout; | ||
652 | |||
653 | size_t count = left; | ||
654 | |||
655 | if (count > maxlen) | ||
656 | count = maxlen; | ||
657 | |||
658 | if (!dma_handle) /* bounce buffer ! */ | ||
659 | memcpy(priv->dma_buf, buf, count); | ||
660 | |||
661 | dmaflag = claim_dma_lock(); | ||
662 | disable_dma(port->dma); | ||
663 | clear_dma_ff(port->dma); | ||
664 | set_dma_mode(port->dma, DMA_MODE_WRITE); | ||
665 | set_dma_addr(port->dma, dma_addr); | ||
666 | set_dma_count(port->dma, count); | ||
667 | |||
668 | /* Set DMA mode */ | ||
669 | frob_econtrol (port, 1<<3, 1<<3); | ||
670 | |||
671 | /* Clear serviceIntr */ | ||
672 | frob_econtrol (port, 1<<2, 0); | ||
673 | |||
674 | enable_dma(port->dma); | ||
675 | release_dma_lock(dmaflag); | ||
676 | |||
677 | /* assume DMA will be successful */ | ||
678 | left -= count; | ||
679 | buf += count; | ||
680 | if (dma_handle) dma_addr += count; | ||
681 | |||
682 | /* Wait for interrupt. */ | ||
683 | false_alarm: | ||
684 | ret = parport_wait_event (port, HZ); | ||
685 | if (ret < 0) break; | ||
686 | ret = 0; | ||
687 | if (!time_before (jiffies, expire)) { | ||
688 | /* Timed out. */ | ||
689 | printk (KERN_DEBUG "DMA write timed out\n"); | ||
690 | break; | ||
691 | } | ||
692 | /* Is serviceIntr set? */ | ||
693 | if (!(inb (ECONTROL (port)) & (1<<2))) { | ||
694 | cond_resched(); | ||
695 | |||
696 | goto false_alarm; | ||
697 | } | ||
698 | |||
699 | dmaflag = claim_dma_lock(); | ||
700 | disable_dma(port->dma); | ||
701 | clear_dma_ff(port->dma); | ||
702 | count = get_dma_residue(port->dma); | ||
703 | release_dma_lock(dmaflag); | ||
704 | |||
705 | cond_resched(); /* Can't yield the port. */ | ||
706 | |||
707 | /* Anyone else waiting for the port? */ | ||
708 | if (port->waithead) { | ||
709 | printk (KERN_DEBUG "Somebody wants the port\n"); | ||
710 | break; | ||
711 | } | ||
712 | |||
713 | /* update for possible DMA residue ! */ | ||
714 | buf -= count; | ||
715 | left += count; | ||
716 | if (dma_handle) dma_addr -= count; | ||
717 | } | ||
718 | |||
719 | /* Maybe got here through break, so adjust for DMA residue! */ | ||
720 | dmaflag = claim_dma_lock(); | ||
721 | disable_dma(port->dma); | ||
722 | clear_dma_ff(port->dma); | ||
723 | left += get_dma_residue(port->dma); | ||
724 | release_dma_lock(dmaflag); | ||
725 | |||
726 | /* Turn off DMA mode */ | ||
727 | frob_econtrol (port, 1<<3, 0); | ||
728 | |||
729 | if (dma_handle) | ||
730 | pci_unmap_single(priv->dev, dma_handle, length, PCI_DMA_TODEVICE); | ||
731 | |||
732 | dump_parport_state ("leave fifo_write_block_dma", port); | ||
733 | return length - left; | ||
734 | } | ||
735 | |||
736 | /* Parallel Port FIFO mode (ECP chipsets) */ | ||
737 | static size_t parport_pc_compat_write_block_pio (struct parport *port, | ||
738 | const void *buf, size_t length, | ||
739 | int flags) | ||
740 | { | ||
741 | size_t written; | ||
742 | int r; | ||
743 | unsigned long expire; | ||
744 | const struct parport_pc_private *priv = port->physport->private_data; | ||
745 | |||
746 | /* Special case: a timeout of zero means we cannot call schedule(). | ||
747 | * Also if O_NONBLOCK is set then use the default implementation. */ | ||
748 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | ||
749 | return parport_ieee1284_write_compat (port, buf, | ||
750 | length, flags); | ||
751 | |||
752 | /* Set up parallel port FIFO mode.*/ | ||
753 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | ||
754 | parport_pc_frob_control (port, PARPORT_CONTROL_STROBE, 0); | ||
755 | r = change_mode (port, ECR_PPF); /* Parallel port FIFO */ | ||
756 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_PPF failed\n", port->name); | ||
757 | |||
758 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | ||
759 | |||
760 | /* Write the data to the FIFO. */ | ||
761 | if (port->dma != PARPORT_DMA_NONE) | ||
762 | written = parport_pc_fifo_write_block_dma (port, buf, length); | ||
763 | else | ||
764 | written = parport_pc_fifo_write_block_pio (port, buf, length); | ||
765 | |||
766 | /* Finish up. */ | ||
767 | /* For some hardware we don't want to touch the mode until | ||
768 | * the FIFO is empty, so allow 4 seconds for each position | ||
769 | * in the fifo. | ||
770 | */ | ||
771 | expire = jiffies + (priv->fifo_depth * HZ * 4); | ||
772 | do { | ||
773 | /* Wait for the FIFO to empty */ | ||
774 | r = change_mode (port, ECR_PS2); | ||
775 | if (r != -EBUSY) { | ||
776 | break; | ||
777 | } | ||
778 | } while (time_before (jiffies, expire)); | ||
779 | if (r == -EBUSY) { | ||
780 | |||
781 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | ||
782 | |||
783 | /* Prevent further data transfer. */ | ||
784 | frob_set_mode (port, ECR_TST); | ||
785 | |||
786 | /* Adjust for the contents of the FIFO. */ | ||
787 | for (written -= priv->fifo_depth; ; written++) { | ||
788 | if (inb (ECONTROL (port)) & 0x2) { | ||
789 | /* Full up. */ | ||
790 | break; | ||
791 | } | ||
792 | outb (0, FIFO (port)); | ||
793 | } | ||
794 | |||
795 | /* Reset the FIFO and return to PS2 mode. */ | ||
796 | frob_set_mode (port, ECR_PS2); | ||
797 | } | ||
798 | |||
799 | r = parport_wait_peripheral (port, | ||
800 | PARPORT_STATUS_BUSY, | ||
801 | PARPORT_STATUS_BUSY); | ||
802 | if (r) | ||
803 | printk (KERN_DEBUG | ||
804 | "%s: BUSY timeout (%d) in compat_write_block_pio\n", | ||
805 | port->name, r); | ||
806 | |||
807 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
808 | |||
809 | return written; | ||
810 | } | ||
811 | |||
812 | /* ECP */ | ||
813 | #ifdef CONFIG_PARPORT_1284 | ||
814 | static size_t parport_pc_ecp_write_block_pio (struct parport *port, | ||
815 | const void *buf, size_t length, | ||
816 | int flags) | ||
817 | { | ||
818 | size_t written; | ||
819 | int r; | ||
820 | unsigned long expire; | ||
821 | const struct parport_pc_private *priv = port->physport->private_data; | ||
822 | |||
823 | /* Special case: a timeout of zero means we cannot call schedule(). | ||
824 | * Also if O_NONBLOCK is set then use the default implementation. */ | ||
825 | if (port->physport->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | ||
826 | return parport_ieee1284_ecp_write_data (port, buf, | ||
827 | length, flags); | ||
828 | |||
829 | /* Switch to forward mode if necessary. */ | ||
830 | if (port->physport->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { | ||
831 | /* Event 47: Set nInit high. */ | ||
832 | parport_frob_control (port, | ||
833 | PARPORT_CONTROL_INIT | ||
834 | | PARPORT_CONTROL_AUTOFD, | ||
835 | PARPORT_CONTROL_INIT | ||
836 | | PARPORT_CONTROL_AUTOFD); | ||
837 | |||
838 | /* Event 49: PError goes high. */ | ||
839 | r = parport_wait_peripheral (port, | ||
840 | PARPORT_STATUS_PAPEROUT, | ||
841 | PARPORT_STATUS_PAPEROUT); | ||
842 | if (r) { | ||
843 | printk (KERN_DEBUG "%s: PError timeout (%d) " | ||
844 | "in ecp_write_block_pio\n", port->name, r); | ||
845 | } | ||
846 | } | ||
847 | |||
848 | /* Set up ECP parallel port mode.*/ | ||
849 | parport_pc_data_forward (port); /* Must be in PS2 mode */ | ||
850 | parport_pc_frob_control (port, | ||
851 | PARPORT_CONTROL_STROBE | | ||
852 | PARPORT_CONTROL_AUTOFD, | ||
853 | 0); | ||
854 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | ||
855 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | ||
856 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_DATA; | ||
857 | |||
858 | /* Write the data to the FIFO. */ | ||
859 | if (port->dma != PARPORT_DMA_NONE) | ||
860 | written = parport_pc_fifo_write_block_dma (port, buf, length); | ||
861 | else | ||
862 | written = parport_pc_fifo_write_block_pio (port, buf, length); | ||
863 | |||
864 | /* Finish up. */ | ||
865 | /* For some hardware we don't want to touch the mode until | ||
866 | * the FIFO is empty, so allow 4 seconds for each position | ||
867 | * in the fifo. | ||
868 | */ | ||
869 | expire = jiffies + (priv->fifo_depth * (HZ * 4)); | ||
870 | do { | ||
871 | /* Wait for the FIFO to empty */ | ||
872 | r = change_mode (port, ECR_PS2); | ||
873 | if (r != -EBUSY) { | ||
874 | break; | ||
875 | } | ||
876 | } while (time_before (jiffies, expire)); | ||
877 | if (r == -EBUSY) { | ||
878 | |||
879 | printk (KERN_DEBUG "%s: FIFO is stuck\n", port->name); | ||
880 | |||
881 | /* Prevent further data transfer. */ | ||
882 | frob_set_mode (port, ECR_TST); | ||
883 | |||
884 | /* Adjust for the contents of the FIFO. */ | ||
885 | for (written -= priv->fifo_depth; ; written++) { | ||
886 | if (inb (ECONTROL (port)) & 0x2) { | ||
887 | /* Full up. */ | ||
888 | break; | ||
889 | } | ||
890 | outb (0, FIFO (port)); | ||
891 | } | ||
892 | |||
893 | /* Reset the FIFO and return to PS2 mode. */ | ||
894 | frob_set_mode (port, ECR_PS2); | ||
895 | |||
896 | /* Host transfer recovery. */ | ||
897 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | ||
898 | udelay (5); | ||
899 | parport_frob_control (port, PARPORT_CONTROL_INIT, 0); | ||
900 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | ||
901 | if (r) | ||
902 | printk (KERN_DEBUG "%s: PE,1 timeout (%d) " | ||
903 | "in ecp_write_block_pio\n", port->name, r); | ||
904 | |||
905 | parport_frob_control (port, | ||
906 | PARPORT_CONTROL_INIT, | ||
907 | PARPORT_CONTROL_INIT); | ||
908 | r = parport_wait_peripheral (port, | ||
909 | PARPORT_STATUS_PAPEROUT, | ||
910 | PARPORT_STATUS_PAPEROUT); | ||
911 | if (r) | ||
912 | printk (KERN_DEBUG "%s: PE,2 timeout (%d) " | ||
913 | "in ecp_write_block_pio\n", port->name, r); | ||
914 | } | ||
915 | |||
916 | r = parport_wait_peripheral (port, | ||
917 | PARPORT_STATUS_BUSY, | ||
918 | PARPORT_STATUS_BUSY); | ||
919 | if(r) | ||
920 | printk (KERN_DEBUG | ||
921 | "%s: BUSY timeout (%d) in ecp_write_block_pio\n", | ||
922 | port->name, r); | ||
923 | |||
924 | port->physport->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
925 | |||
926 | return written; | ||
927 | } | ||
928 | |||
929 | #if 0 | ||
930 | static size_t parport_pc_ecp_read_block_pio (struct parport *port, | ||
931 | void *buf, size_t length, | ||
932 | int flags) | ||
933 | { | ||
934 | size_t left = length; | ||
935 | size_t fifofull; | ||
936 | int r; | ||
937 | const int fifo = FIFO(port); | ||
938 | const struct parport_pc_private *priv = port->physport->private_data; | ||
939 | const int fifo_depth = priv->fifo_depth; | ||
940 | char *bufp = buf; | ||
941 | |||
942 | port = port->physport; | ||
943 | DPRINTK (KERN_DEBUG "parport_pc: parport_pc_ecp_read_block_pio\n"); | ||
944 | dump_parport_state ("enter fcn", port); | ||
945 | |||
946 | /* Special case: a timeout of zero means we cannot call schedule(). | ||
947 | * Also if O_NONBLOCK is set then use the default implementation. */ | ||
948 | if (port->cad->timeout <= PARPORT_INACTIVITY_O_NONBLOCK) | ||
949 | return parport_ieee1284_ecp_read_data (port, buf, | ||
950 | length, flags); | ||
951 | |||
952 | if (port->ieee1284.mode == IEEE1284_MODE_ECPRLE) { | ||
953 | /* If the peripheral is allowed to send RLE compressed | ||
954 | * data, it is possible for a byte to expand to 128 | ||
955 | * bytes in the FIFO. */ | ||
956 | fifofull = 128; | ||
957 | } else { | ||
958 | fifofull = fifo_depth; | ||
959 | } | ||
960 | |||
961 | /* If the caller wants less than a full FIFO's worth of data, | ||
962 | * go through software emulation. Otherwise we may have to throw | ||
963 | * away data. */ | ||
964 | if (length < fifofull) | ||
965 | return parport_ieee1284_ecp_read_data (port, buf, | ||
966 | length, flags); | ||
967 | |||
968 | if (port->ieee1284.phase != IEEE1284_PH_REV_IDLE) { | ||
969 | /* change to reverse-idle phase (must be in forward-idle) */ | ||
970 | |||
971 | /* Event 38: Set nAutoFd low (also make sure nStrobe is high) */ | ||
972 | parport_frob_control (port, | ||
973 | PARPORT_CONTROL_AUTOFD | ||
974 | | PARPORT_CONTROL_STROBE, | ||
975 | PARPORT_CONTROL_AUTOFD); | ||
976 | parport_pc_data_reverse (port); /* Must be in PS2 mode */ | ||
977 | udelay (5); | ||
978 | /* Event 39: Set nInit low to initiate bus reversal */ | ||
979 | parport_frob_control (port, | ||
980 | PARPORT_CONTROL_INIT, | ||
981 | 0); | ||
982 | /* Event 40: Wait for nAckReverse (PError) to go low */ | ||
983 | r = parport_wait_peripheral (port, PARPORT_STATUS_PAPEROUT, 0); | ||
984 | if (r) { | ||
985 | printk (KERN_DEBUG "%s: PE timeout Event 40 (%d) " | ||
986 | "in ecp_read_block_pio\n", port->name, r); | ||
987 | return 0; | ||
988 | } | ||
989 | } | ||
990 | |||
991 | /* Set up ECP FIFO mode.*/ | ||
992 | /* parport_pc_frob_control (port, | ||
993 | PARPORT_CONTROL_STROBE | | ||
994 | PARPORT_CONTROL_AUTOFD, | ||
995 | PARPORT_CONTROL_AUTOFD); */ | ||
996 | r = change_mode (port, ECR_ECP); /* ECP FIFO */ | ||
997 | if (r) printk (KERN_DEBUG "%s: Warning change_mode ECR_ECP failed\n", port->name); | ||
998 | |||
999 | port->ieee1284.phase = IEEE1284_PH_REV_DATA; | ||
1000 | |||
1001 | /* the first byte must be collected manually */ | ||
1002 | dump_parport_state ("pre 43", port); | ||
1003 | /* Event 43: Wait for nAck to go low */ | ||
1004 | r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); | ||
1005 | if (r) { | ||
1006 | /* timed out while reading -- no data */ | ||
1007 | printk (KERN_DEBUG "PIO read timed out (initial byte)\n"); | ||
1008 | goto out_no_data; | ||
1009 | } | ||
1010 | /* read byte */ | ||
1011 | *bufp++ = inb (DATA (port)); | ||
1012 | left--; | ||
1013 | dump_parport_state ("43-44", port); | ||
1014 | /* Event 44: nAutoFd (HostAck) goes high to acknowledge */ | ||
1015 | parport_pc_frob_control (port, | ||
1016 | PARPORT_CONTROL_AUTOFD, | ||
1017 | 0); | ||
1018 | dump_parport_state ("pre 45", port); | ||
1019 | /* Event 45: Wait for nAck to go high */ | ||
1020 | /* r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, PARPORT_STATUS_ACK); */ | ||
1021 | dump_parport_state ("post 45", port); | ||
1022 | r = 0; | ||
1023 | if (r) { | ||
1024 | /* timed out while waiting for peripheral to respond to ack */ | ||
1025 | printk (KERN_DEBUG "ECP PIO read timed out (waiting for nAck)\n"); | ||
1026 | |||
1027 | /* keep hold of the byte we've got already */ | ||
1028 | goto out_no_data; | ||
1029 | } | ||
1030 | /* Event 46: nAutoFd (HostAck) goes low to accept more data */ | ||
1031 | parport_pc_frob_control (port, | ||
1032 | PARPORT_CONTROL_AUTOFD, | ||
1033 | PARPORT_CONTROL_AUTOFD); | ||
1034 | |||
1035 | |||
1036 | dump_parport_state ("rev idle", port); | ||
1037 | /* Do the transfer. */ | ||
1038 | while (left > fifofull) { | ||
1039 | int ret; | ||
1040 | unsigned long expire = jiffies + port->cad->timeout; | ||
1041 | unsigned char ecrval = inb (ECONTROL (port)); | ||
1042 | |||
1043 | if (need_resched() && time_before (jiffies, expire)) | ||
1044 | /* Can't yield the port. */ | ||
1045 | schedule (); | ||
1046 | |||
1047 | /* At this point, the FIFO may already be full. In | ||
1048 | * that case ECP is already holding back the | ||
1049 | * peripheral (assuming proper design) with a delayed | ||
1050 | * handshake. Work fast to avoid a peripheral | ||
1051 | * timeout. */ | ||
1052 | |||
1053 | if (ecrval & 0x01) { | ||
1054 | /* FIFO is empty. Wait for interrupt. */ | ||
1055 | dump_parport_state ("FIFO empty", port); | ||
1056 | |||
1057 | /* Anyone else waiting for the port? */ | ||
1058 | if (port->waithead) { | ||
1059 | printk (KERN_DEBUG "Somebody wants the port\n"); | ||
1060 | break; | ||
1061 | } | ||
1062 | |||
1063 | /* Clear serviceIntr */ | ||
1064 | ECR_WRITE (port, ecrval & ~(1<<2)); | ||
1065 | false_alarm: | ||
1066 | dump_parport_state ("waiting", port); | ||
1067 | ret = parport_wait_event (port, HZ); | ||
1068 | DPRINTK (KERN_DEBUG "parport_wait_event returned %d\n", ret); | ||
1069 | if (ret < 0) | ||
1070 | break; | ||
1071 | ret = 0; | ||
1072 | if (!time_before (jiffies, expire)) { | ||
1073 | /* Timed out. */ | ||
1074 | dump_parport_state ("timeout", port); | ||
1075 | printk (KERN_DEBUG "PIO read timed out\n"); | ||
1076 | break; | ||
1077 | } | ||
1078 | ecrval = inb (ECONTROL (port)); | ||
1079 | if (!(ecrval & (1<<2))) { | ||
1080 | if (need_resched() && | ||
1081 | time_before (jiffies, expire)) { | ||
1082 | schedule (); | ||
1083 | } | ||
1084 | goto false_alarm; | ||
1085 | } | ||
1086 | |||
1087 | /* Depending on how the FIFO threshold was | ||
1088 | * set, how long interrupt service took, and | ||
1089 | * how fast the peripheral is, we might be | ||
1090 | * lucky and have a just filled FIFO. */ | ||
1091 | continue; | ||
1092 | } | ||
1093 | |||
1094 | if (ecrval & 0x02) { | ||
1095 | /* FIFO is full. */ | ||
1096 | dump_parport_state ("FIFO full", port); | ||
1097 | insb (fifo, bufp, fifo_depth); | ||
1098 | bufp += fifo_depth; | ||
1099 | left -= fifo_depth; | ||
1100 | continue; | ||
1101 | } | ||
1102 | |||
1103 | DPRINTK (KERN_DEBUG "*** ecp_read_block_pio: reading one byte from the FIFO\n"); | ||
1104 | |||
1105 | /* FIFO not filled. We will cycle this loop for a while | ||
1106 | * and either the peripheral will fill it faster, | ||
1107 | * tripping a fast empty with insb, or we empty it. */ | ||
1108 | *bufp++ = inb (fifo); | ||
1109 | left--; | ||
1110 | } | ||
1111 | |||
1112 | /* scoop up anything left in the FIFO */ | ||
1113 | while (left && !(inb (ECONTROL (port) & 0x01))) { | ||
1114 | *bufp++ = inb (fifo); | ||
1115 | left--; | ||
1116 | } | ||
1117 | |||
1118 | port->ieee1284.phase = IEEE1284_PH_REV_IDLE; | ||
1119 | dump_parport_state ("rev idle2", port); | ||
1120 | |||
1121 | out_no_data: | ||
1122 | |||
1123 | /* Go to forward idle mode to shut the peripheral up (event 47). */ | ||
1124 | parport_frob_control (port, PARPORT_CONTROL_INIT, PARPORT_CONTROL_INIT); | ||
1125 | |||
1126 | /* event 49: PError goes high */ | ||
1127 | r = parport_wait_peripheral (port, | ||
1128 | PARPORT_STATUS_PAPEROUT, | ||
1129 | PARPORT_STATUS_PAPEROUT); | ||
1130 | if (r) { | ||
1131 | printk (KERN_DEBUG | ||
1132 | "%s: PE timeout FWDIDLE (%d) in ecp_read_block_pio\n", | ||
1133 | port->name, r); | ||
1134 | } | ||
1135 | |||
1136 | port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
1137 | |||
1138 | /* Finish up. */ | ||
1139 | { | ||
1140 | int lost = get_fifo_residue (port); | ||
1141 | if (lost) | ||
1142 | /* Shouldn't happen with compliant peripherals. */ | ||
1143 | printk (KERN_DEBUG "%s: DATA LOSS (%d bytes)!\n", | ||
1144 | port->name, lost); | ||
1145 | } | ||
1146 | |||
1147 | dump_parport_state ("fwd idle", port); | ||
1148 | return length - left; | ||
1149 | } | ||
1150 | #endif /* 0 */ | ||
1151 | #endif /* IEEE 1284 support */ | ||
1152 | #endif /* Allowed to use FIFO/DMA */ | ||
1153 | |||
1154 | |||
1155 | /* | ||
1156 | * ****************************************** | ||
1157 | * INITIALISATION AND MODULE STUFF BELOW HERE | ||
1158 | * ****************************************** | ||
1159 | */ | ||
1160 | |||
1161 | /* GCC is not inlining extern inline function later overwriten to non-inline, | ||
1162 | so we use outlined_ variants here. */ | ||
1163 | static struct parport_operations parport_pc_ops = | ||
1164 | { | ||
1165 | .write_data = parport_pc_write_data, | ||
1166 | .read_data = parport_pc_read_data, | ||
1167 | |||
1168 | .write_control = parport_pc_write_control, | ||
1169 | .read_control = parport_pc_read_control, | ||
1170 | .frob_control = parport_pc_frob_control, | ||
1171 | |||
1172 | .read_status = parport_pc_read_status, | ||
1173 | |||
1174 | .enable_irq = parport_pc_enable_irq, | ||
1175 | .disable_irq = parport_pc_disable_irq, | ||
1176 | |||
1177 | .data_forward = parport_pc_data_forward, | ||
1178 | .data_reverse = parport_pc_data_reverse, | ||
1179 | |||
1180 | .init_state = parport_pc_init_state, | ||
1181 | .save_state = parport_pc_save_state, | ||
1182 | .restore_state = parport_pc_restore_state, | ||
1183 | |||
1184 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
1185 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
1186 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
1187 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
1188 | |||
1189 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
1190 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
1191 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
1192 | |||
1193 | .compat_write_data = parport_ieee1284_write_compat, | ||
1194 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
1195 | .byte_read_data = parport_ieee1284_read_byte, | ||
1196 | |||
1197 | .owner = THIS_MODULE, | ||
1198 | }; | ||
1199 | |||
1200 | #ifdef CONFIG_PARPORT_PC_SUPERIO | ||
1201 | /* Super-IO chipset detection, Winbond, SMSC */ | ||
1202 | static void __devinit show_parconfig_smsc37c669(int io, int key) | ||
1203 | { | ||
1204 | int cr1,cr4,cra,cr23,cr26,cr27,i=0; | ||
1205 | static const char *modes[]={ "SPP and Bidirectional (PS/2)", | ||
1206 | "EPP and SPP", | ||
1207 | "ECP", | ||
1208 | "ECP and EPP" }; | ||
1209 | |||
1210 | outb(key,io); | ||
1211 | outb(key,io); | ||
1212 | outb(1,io); | ||
1213 | cr1=inb(io+1); | ||
1214 | outb(4,io); | ||
1215 | cr4=inb(io+1); | ||
1216 | outb(0x0a,io); | ||
1217 | cra=inb(io+1); | ||
1218 | outb(0x23,io); | ||
1219 | cr23=inb(io+1); | ||
1220 | outb(0x26,io); | ||
1221 | cr26=inb(io+1); | ||
1222 | outb(0x27,io); | ||
1223 | cr27=inb(io+1); | ||
1224 | outb(0xaa,io); | ||
1225 | |||
1226 | if (verbose_probing) { | ||
1227 | printk (KERN_INFO "SMSC 37c669 LPT Config: cr_1=0x%02x, 4=0x%02x, " | ||
1228 | "A=0x%2x, 23=0x%02x, 26=0x%02x, 27=0x%02x\n", | ||
1229 | cr1,cr4,cra,cr23,cr26,cr27); | ||
1230 | |||
1231 | /* The documentation calls DMA and IRQ-Lines by letters, so | ||
1232 | the board maker can/will wire them | ||
1233 | appropriately/randomly... G=reserved H=IDE-irq, */ | ||
1234 | printk (KERN_INFO "SMSC LPT Config: io=0x%04x, irq=%c, dma=%c, " | ||
1235 | "fifo threshold=%d\n", cr23*4, | ||
1236 | (cr27 &0x0f) ? 'A'-1+(cr27 &0x0f): '-', | ||
1237 | (cr26 &0x0f) ? 'A'-1+(cr26 &0x0f): '-', cra & 0x0f); | ||
1238 | printk(KERN_INFO "SMSC LPT Config: enabled=%s power=%s\n", | ||
1239 | (cr23*4 >=0x100) ?"yes":"no", (cr1 & 4) ? "yes" : "no"); | ||
1240 | printk(KERN_INFO "SMSC LPT Config: Port mode=%s, EPP version =%s\n", | ||
1241 | (cr1 & 0x08 ) ? "Standard mode only (SPP)" : modes[cr4 & 0x03], | ||
1242 | (cr4 & 0x40) ? "1.7" : "1.9"); | ||
1243 | } | ||
1244 | |||
1245 | /* Heuristics ! BIOS setup for this mainboard device limits | ||
1246 | the choices to standard settings, i.e. io-address and IRQ | ||
1247 | are related, however DMA can be 1 or 3, assume DMA_A=DMA1, | ||
1248 | DMA_C=DMA3 (this is true e.g. for TYAN 1564D Tomcat IV) */ | ||
1249 | if(cr23*4 >=0x100) { /* if active */ | ||
1250 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | ||
1251 | i++; | ||
1252 | if(i==NR_SUPERIOS) | ||
1253 | printk(KERN_INFO "Super-IO: too many chips!\n"); | ||
1254 | else { | ||
1255 | int d; | ||
1256 | switch (cr23*4) { | ||
1257 | case 0x3bc: | ||
1258 | superios[i].io = 0x3bc; | ||
1259 | superios[i].irq = 7; | ||
1260 | break; | ||
1261 | case 0x378: | ||
1262 | superios[i].io = 0x378; | ||
1263 | superios[i].irq = 7; | ||
1264 | break; | ||
1265 | case 0x278: | ||
1266 | superios[i].io = 0x278; | ||
1267 | superios[i].irq = 5; | ||
1268 | } | ||
1269 | d=(cr26 &0x0f); | ||
1270 | if((d==1) || (d==3)) | ||
1271 | superios[i].dma= d; | ||
1272 | else | ||
1273 | superios[i].dma= PARPORT_DMA_NONE; | ||
1274 | } | ||
1275 | } | ||
1276 | } | ||
1277 | |||
1278 | |||
1279 | static void __devinit show_parconfig_winbond(int io, int key) | ||
1280 | { | ||
1281 | int cr30,cr60,cr61,cr70,cr74,crf0,i=0; | ||
1282 | static const char *modes[] = { | ||
1283 | "Standard (SPP) and Bidirectional(PS/2)", /* 0 */ | ||
1284 | "EPP-1.9 and SPP", | ||
1285 | "ECP", | ||
1286 | "ECP and EPP-1.9", | ||
1287 | "Standard (SPP)", | ||
1288 | "EPP-1.7 and SPP", /* 5 */ | ||
1289 | "undefined!", | ||
1290 | "ECP and EPP-1.7" }; | ||
1291 | static char *irqtypes[] = { "pulsed low, high-Z", "follows nACK" }; | ||
1292 | |||
1293 | /* The registers are called compatible-PnP because the | ||
1294 | register layout is modelled after ISA-PnP, the access | ||
1295 | method is just another ... */ | ||
1296 | outb(key,io); | ||
1297 | outb(key,io); | ||
1298 | outb(0x07,io); /* Register 7: Select Logical Device */ | ||
1299 | outb(0x01,io+1); /* LD1 is Parallel Port */ | ||
1300 | outb(0x30,io); | ||
1301 | cr30=inb(io+1); | ||
1302 | outb(0x60,io); | ||
1303 | cr60=inb(io+1); | ||
1304 | outb(0x61,io); | ||
1305 | cr61=inb(io+1); | ||
1306 | outb(0x70,io); | ||
1307 | cr70=inb(io+1); | ||
1308 | outb(0x74,io); | ||
1309 | cr74=inb(io+1); | ||
1310 | outb(0xf0,io); | ||
1311 | crf0=inb(io+1); | ||
1312 | outb(0xaa,io); | ||
1313 | |||
1314 | if (verbose_probing) { | ||
1315 | printk(KERN_INFO "Winbond LPT Config: cr_30=%02x 60,61=%02x%02x " | ||
1316 | "70=%02x 74=%02x, f0=%02x\n", cr30,cr60,cr61,cr70,cr74,crf0); | ||
1317 | printk(KERN_INFO "Winbond LPT Config: active=%s, io=0x%02x%02x irq=%d, ", | ||
1318 | (cr30 & 0x01) ? "yes":"no", cr60,cr61,cr70&0x0f ); | ||
1319 | if ((cr74 & 0x07) > 3) | ||
1320 | printk("dma=none\n"); | ||
1321 | else | ||
1322 | printk("dma=%d\n",cr74 & 0x07); | ||
1323 | printk(KERN_INFO "Winbond LPT Config: irqtype=%s, ECP fifo threshold=%d\n", | ||
1324 | irqtypes[crf0>>7], (crf0>>3)&0x0f); | ||
1325 | printk(KERN_INFO "Winbond LPT Config: Port mode=%s\n", modes[crf0 & 0x07]); | ||
1326 | } | ||
1327 | |||
1328 | if(cr30 & 0x01) { /* the settings can be interrogated later ... */ | ||
1329 | while((superios[i].io!= 0) && (i<NR_SUPERIOS)) | ||
1330 | i++; | ||
1331 | if(i==NR_SUPERIOS) | ||
1332 | printk(KERN_INFO "Super-IO: too many chips!\n"); | ||
1333 | else { | ||
1334 | superios[i].io = (cr60<<8)|cr61; | ||
1335 | superios[i].irq = cr70&0x0f; | ||
1336 | superios[i].dma = (((cr74 & 0x07) > 3) ? | ||
1337 | PARPORT_DMA_NONE : (cr74 & 0x07)); | ||
1338 | } | ||
1339 | } | ||
1340 | } | ||
1341 | |||
1342 | static void __devinit decode_winbond(int efer, int key, int devid, int devrev, int oldid) | ||
1343 | { | ||
1344 | const char *type = "unknown"; | ||
1345 | int id,progif=2; | ||
1346 | |||
1347 | if (devid == devrev) | ||
1348 | /* simple heuristics, we happened to read some | ||
1349 | non-winbond register */ | ||
1350 | return; | ||
1351 | |||
1352 | id=(devid<<8) | devrev; | ||
1353 | |||
1354 | /* Values are from public data sheets pdf files, I can just | ||
1355 | confirm 83977TF is correct :-) */ | ||
1356 | if (id == 0x9771) type="83977F/AF"; | ||
1357 | else if (id == 0x9773) type="83977TF / SMSC 97w33x/97w34x"; | ||
1358 | else if (id == 0x9774) type="83977ATF"; | ||
1359 | else if ((id & ~0x0f) == 0x5270) type="83977CTF / SMSC 97w36x"; | ||
1360 | else if ((id & ~0x0f) == 0x52f0) type="83977EF / SMSC 97w35x"; | ||
1361 | else if ((id & ~0x0f) == 0x5210) type="83627"; | ||
1362 | else if ((id & ~0x0f) == 0x6010) type="83697HF"; | ||
1363 | else if ((oldid &0x0f ) == 0x0a) { type="83877F"; progif=1;} | ||
1364 | else if ((oldid &0x0f ) == 0x0b) { type="83877AF"; progif=1;} | ||
1365 | else if ((oldid &0x0f ) == 0x0c) { type="83877TF"; progif=1;} | ||
1366 | else if ((oldid &0x0f ) == 0x0d) { type="83877ATF"; progif=1;} | ||
1367 | else progif=0; | ||
1368 | |||
1369 | if (verbose_probing) | ||
1370 | printk(KERN_INFO "Winbond chip at EFER=0x%x key=0x%02x " | ||
1371 | "devid=%02x devrev=%02x oldid=%02x type=%s\n", | ||
1372 | efer, key, devid, devrev, oldid, type); | ||
1373 | |||
1374 | if (progif == 2) | ||
1375 | show_parconfig_winbond(efer,key); | ||
1376 | } | ||
1377 | |||
1378 | static void __devinit decode_smsc(int efer, int key, int devid, int devrev) | ||
1379 | { | ||
1380 | const char *type = "unknown"; | ||
1381 | void (*func)(int io, int key); | ||
1382 | int id; | ||
1383 | |||
1384 | if (devid == devrev) | ||
1385 | /* simple heuristics, we happened to read some | ||
1386 | non-smsc register */ | ||
1387 | return; | ||
1388 | |||
1389 | func=NULL; | ||
1390 | id=(devid<<8) | devrev; | ||
1391 | |||
1392 | if (id==0x0302) {type="37c669"; func=show_parconfig_smsc37c669;} | ||
1393 | else if (id==0x6582) type="37c665IR"; | ||
1394 | else if (devid==0x65) type="37c665GT"; | ||
1395 | else if (devid==0x66) type="37c666GT"; | ||
1396 | |||
1397 | if (verbose_probing) | ||
1398 | printk(KERN_INFO "SMSC chip at EFER=0x%x " | ||
1399 | "key=0x%02x devid=%02x devrev=%02x type=%s\n", | ||
1400 | efer, key, devid, devrev, type); | ||
1401 | |||
1402 | if (func) | ||
1403 | func(efer,key); | ||
1404 | } | ||
1405 | |||
1406 | |||
1407 | static void __devinit winbond_check(int io, int key) | ||
1408 | { | ||
1409 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | ||
1410 | |||
1411 | if (!request_region(io, 3, __FUNCTION__)) | ||
1412 | return; | ||
1413 | |||
1414 | /* First probe without key */ | ||
1415 | outb(0x20,io); | ||
1416 | x_devid=inb(io+1); | ||
1417 | outb(0x21,io); | ||
1418 | x_devrev=inb(io+1); | ||
1419 | outb(0x09,io); | ||
1420 | x_oldid=inb(io+1); | ||
1421 | |||
1422 | outb(key,io); | ||
1423 | outb(key,io); /* Write Magic Sequence to EFER, extended | ||
1424 | funtion enable register */ | ||
1425 | outb(0x20,io); /* Write EFIR, extended function index register */ | ||
1426 | devid=inb(io+1); /* Read EFDR, extended function data register */ | ||
1427 | outb(0x21,io); | ||
1428 | devrev=inb(io+1); | ||
1429 | outb(0x09,io); | ||
1430 | oldid=inb(io+1); | ||
1431 | outb(0xaa,io); /* Magic Seal */ | ||
1432 | |||
1433 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | ||
1434 | goto out; /* protection against false positives */ | ||
1435 | |||
1436 | decode_winbond(io,key,devid,devrev,oldid); | ||
1437 | out: | ||
1438 | release_region(io, 3); | ||
1439 | } | ||
1440 | |||
1441 | static void __devinit winbond_check2(int io,int key) | ||
1442 | { | ||
1443 | int devid,devrev,oldid,x_devid,x_devrev,x_oldid; | ||
1444 | |||
1445 | if (!request_region(io, 3, __FUNCTION__)) | ||
1446 | return; | ||
1447 | |||
1448 | /* First probe without the key */ | ||
1449 | outb(0x20,io+2); | ||
1450 | x_devid=inb(io+2); | ||
1451 | outb(0x21,io+1); | ||
1452 | x_devrev=inb(io+2); | ||
1453 | outb(0x09,io+1); | ||
1454 | x_oldid=inb(io+2); | ||
1455 | |||
1456 | outb(key,io); /* Write Magic Byte to EFER, extended | ||
1457 | funtion enable register */ | ||
1458 | outb(0x20,io+2); /* Write EFIR, extended function index register */ | ||
1459 | devid=inb(io+2); /* Read EFDR, extended function data register */ | ||
1460 | outb(0x21,io+1); | ||
1461 | devrev=inb(io+2); | ||
1462 | outb(0x09,io+1); | ||
1463 | oldid=inb(io+2); | ||
1464 | outb(0xaa,io); /* Magic Seal */ | ||
1465 | |||
1466 | if ((x_devid == devid) && (x_devrev == devrev) && (x_oldid == oldid)) | ||
1467 | goto out; /* protection against false positives */ | ||
1468 | |||
1469 | decode_winbond(io,key,devid,devrev,oldid); | ||
1470 | out: | ||
1471 | release_region(io, 3); | ||
1472 | } | ||
1473 | |||
1474 | static void __devinit smsc_check(int io, int key) | ||
1475 | { | ||
1476 | int id,rev,oldid,oldrev,x_id,x_rev,x_oldid,x_oldrev; | ||
1477 | |||
1478 | if (!request_region(io, 3, __FUNCTION__)) | ||
1479 | return; | ||
1480 | |||
1481 | /* First probe without the key */ | ||
1482 | outb(0x0d,io); | ||
1483 | x_oldid=inb(io+1); | ||
1484 | outb(0x0e,io); | ||
1485 | x_oldrev=inb(io+1); | ||
1486 | outb(0x20,io); | ||
1487 | x_id=inb(io+1); | ||
1488 | outb(0x21,io); | ||
1489 | x_rev=inb(io+1); | ||
1490 | |||
1491 | outb(key,io); | ||
1492 | outb(key,io); /* Write Magic Sequence to EFER, extended | ||
1493 | funtion enable register */ | ||
1494 | outb(0x0d,io); /* Write EFIR, extended function index register */ | ||
1495 | oldid=inb(io+1); /* Read EFDR, extended function data register */ | ||
1496 | outb(0x0e,io); | ||
1497 | oldrev=inb(io+1); | ||
1498 | outb(0x20,io); | ||
1499 | id=inb(io+1); | ||
1500 | outb(0x21,io); | ||
1501 | rev=inb(io+1); | ||
1502 | outb(0xaa,io); /* Magic Seal */ | ||
1503 | |||
1504 | if ((x_id == id) && (x_oldrev == oldrev) && | ||
1505 | (x_oldid == oldid) && (x_rev == rev)) | ||
1506 | goto out; /* protection against false positives */ | ||
1507 | |||
1508 | decode_smsc(io,key,oldid,oldrev); | ||
1509 | out: | ||
1510 | release_region(io, 3); | ||
1511 | } | ||
1512 | |||
1513 | |||
1514 | static void __devinit detect_and_report_winbond (void) | ||
1515 | { | ||
1516 | if (verbose_probing) | ||
1517 | printk(KERN_DEBUG "Winbond Super-IO detection, now testing ports 3F0,370,250,4E,2E ...\n"); | ||
1518 | winbond_check(0x3f0,0x87); | ||
1519 | winbond_check(0x370,0x87); | ||
1520 | winbond_check(0x2e ,0x87); | ||
1521 | winbond_check(0x4e ,0x87); | ||
1522 | winbond_check(0x3f0,0x86); | ||
1523 | winbond_check2(0x250,0x88); | ||
1524 | winbond_check2(0x250,0x89); | ||
1525 | } | ||
1526 | |||
1527 | static void __devinit detect_and_report_smsc (void) | ||
1528 | { | ||
1529 | if (verbose_probing) | ||
1530 | printk(KERN_DEBUG "SMSC Super-IO detection, now testing Ports 2F0, 370 ...\n"); | ||
1531 | smsc_check(0x3f0,0x55); | ||
1532 | smsc_check(0x370,0x55); | ||
1533 | smsc_check(0x3f0,0x44); | ||
1534 | smsc_check(0x370,0x44); | ||
1535 | } | ||
1536 | #endif /* CONFIG_PARPORT_PC_SUPERIO */ | ||
1537 | |||
1538 | static int __devinit get_superio_dma (struct parport *p) | ||
1539 | { | ||
1540 | int i=0; | ||
1541 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | ||
1542 | i++; | ||
1543 | if (i!=NR_SUPERIOS) | ||
1544 | return superios[i].dma; | ||
1545 | return PARPORT_DMA_NONE; | ||
1546 | } | ||
1547 | |||
1548 | static int __devinit get_superio_irq (struct parport *p) | ||
1549 | { | ||
1550 | int i=0; | ||
1551 | while( (superios[i].io != p->base) && (i<NR_SUPERIOS)) | ||
1552 | i++; | ||
1553 | if (i!=NR_SUPERIOS) | ||
1554 | return superios[i].irq; | ||
1555 | return PARPORT_IRQ_NONE; | ||
1556 | } | ||
1557 | |||
1558 | |||
1559 | /* --- Mode detection ------------------------------------- */ | ||
1560 | |||
1561 | /* | ||
1562 | * Checks for port existence, all ports support SPP MODE | ||
1563 | * Returns: | ||
1564 | * 0 : No parallel port at this address | ||
1565 | * PARPORT_MODE_PCSPP : SPP port detected | ||
1566 | * (if the user specified an ioport himself, | ||
1567 | * this shall always be the case!) | ||
1568 | * | ||
1569 | */ | ||
1570 | static int __devinit parport_SPP_supported(struct parport *pb) | ||
1571 | { | ||
1572 | unsigned char r, w; | ||
1573 | |||
1574 | /* | ||
1575 | * first clear an eventually pending EPP timeout | ||
1576 | * I (sailer@ife.ee.ethz.ch) have an SMSC chipset | ||
1577 | * that does not even respond to SPP cycles if an EPP | ||
1578 | * timeout is pending | ||
1579 | */ | ||
1580 | clear_epp_timeout(pb); | ||
1581 | |||
1582 | /* Do a simple read-write test to make sure the port exists. */ | ||
1583 | w = 0xc; | ||
1584 | outb (w, CONTROL (pb)); | ||
1585 | |||
1586 | /* Is there a control register that we can read from? Some | ||
1587 | * ports don't allow reads, so read_control just returns a | ||
1588 | * software copy. Some ports _do_ allow reads, so bypass the | ||
1589 | * software copy here. In addition, some bits aren't | ||
1590 | * writable. */ | ||
1591 | r = inb (CONTROL (pb)); | ||
1592 | if ((r & 0xf) == w) { | ||
1593 | w = 0xe; | ||
1594 | outb (w, CONTROL (pb)); | ||
1595 | r = inb (CONTROL (pb)); | ||
1596 | outb (0xc, CONTROL (pb)); | ||
1597 | if ((r & 0xf) == w) | ||
1598 | return PARPORT_MODE_PCSPP; | ||
1599 | } | ||
1600 | |||
1601 | if (user_specified) | ||
1602 | /* That didn't work, but the user thinks there's a | ||
1603 | * port here. */ | ||
1604 | printk (KERN_INFO "parport 0x%lx (WARNING): CTR: " | ||
1605 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | ||
1606 | |||
1607 | /* Try the data register. The data lines aren't tri-stated at | ||
1608 | * this stage, so we expect back what we wrote. */ | ||
1609 | w = 0xaa; | ||
1610 | parport_pc_write_data (pb, w); | ||
1611 | r = parport_pc_read_data (pb); | ||
1612 | if (r == w) { | ||
1613 | w = 0x55; | ||
1614 | parport_pc_write_data (pb, w); | ||
1615 | r = parport_pc_read_data (pb); | ||
1616 | if (r == w) | ||
1617 | return PARPORT_MODE_PCSPP; | ||
1618 | } | ||
1619 | |||
1620 | if (user_specified) { | ||
1621 | /* Didn't work, but the user is convinced this is the | ||
1622 | * place. */ | ||
1623 | printk (KERN_INFO "parport 0x%lx (WARNING): DATA: " | ||
1624 | "wrote 0x%02x, read 0x%02x\n", pb->base, w, r); | ||
1625 | printk (KERN_INFO "parport 0x%lx: You gave this address, " | ||
1626 | "but there is probably no parallel port there!\n", | ||
1627 | pb->base); | ||
1628 | } | ||
1629 | |||
1630 | /* It's possible that we can't read the control register or | ||
1631 | * the data register. In that case just believe the user. */ | ||
1632 | if (user_specified) | ||
1633 | return PARPORT_MODE_PCSPP; | ||
1634 | |||
1635 | return 0; | ||
1636 | } | ||
1637 | |||
1638 | /* Check for ECR | ||
1639 | * | ||
1640 | * Old style XT ports alias io ports every 0x400, hence accessing ECR | ||
1641 | * on these cards actually accesses the CTR. | ||
1642 | * | ||
1643 | * Modern cards don't do this but reading from ECR will return 0xff | ||
1644 | * regardless of what is written here if the card does NOT support | ||
1645 | * ECP. | ||
1646 | * | ||
1647 | * We first check to see if ECR is the same as CTR. If not, the low | ||
1648 | * two bits of ECR aren't writable, so we check by writing ECR and | ||
1649 | * reading it back to see if it's what we expect. | ||
1650 | */ | ||
1651 | static int __devinit parport_ECR_present(struct parport *pb) | ||
1652 | { | ||
1653 | struct parport_pc_private *priv = pb->private_data; | ||
1654 | unsigned char r = 0xc; | ||
1655 | |||
1656 | outb (r, CONTROL (pb)); | ||
1657 | if ((inb (ECONTROL (pb)) & 0x3) == (r & 0x3)) { | ||
1658 | outb (r ^ 0x2, CONTROL (pb)); /* Toggle bit 1 */ | ||
1659 | |||
1660 | r = inb (CONTROL (pb)); | ||
1661 | if ((inb (ECONTROL (pb)) & 0x2) == (r & 0x2)) | ||
1662 | goto no_reg; /* Sure that no ECR register exists */ | ||
1663 | } | ||
1664 | |||
1665 | if ((inb (ECONTROL (pb)) & 0x3 ) != 0x1) | ||
1666 | goto no_reg; | ||
1667 | |||
1668 | ECR_WRITE (pb, 0x34); | ||
1669 | if (inb (ECONTROL (pb)) != 0x35) | ||
1670 | goto no_reg; | ||
1671 | |||
1672 | priv->ecr = 1; | ||
1673 | outb (0xc, CONTROL (pb)); | ||
1674 | |||
1675 | /* Go to mode 000 */ | ||
1676 | frob_set_mode (pb, ECR_SPP); | ||
1677 | |||
1678 | return 1; | ||
1679 | |||
1680 | no_reg: | ||
1681 | outb (0xc, CONTROL (pb)); | ||
1682 | return 0; | ||
1683 | } | ||
1684 | |||
1685 | #ifdef CONFIG_PARPORT_1284 | ||
1686 | /* Detect PS/2 support. | ||
1687 | * | ||
1688 | * Bit 5 (0x20) sets the PS/2 data direction; setting this high | ||
1689 | * allows us to read data from the data lines. In theory we would get back | ||
1690 | * 0xff but any peripheral attached to the port may drag some or all of the | ||
1691 | * lines down to zero. So if we get back anything that isn't the contents | ||
1692 | * of the data register we deem PS/2 support to be present. | ||
1693 | * | ||
1694 | * Some SPP ports have "half PS/2" ability - you can't turn off the line | ||
1695 | * drivers, but an external peripheral with sufficiently beefy drivers of | ||
1696 | * its own can overpower them and assert its own levels onto the bus, from | ||
1697 | * where they can then be read back as normal. Ports with this property | ||
1698 | * and the right type of device attached are likely to fail the SPP test, | ||
1699 | * (as they will appear to have stuck bits) and so the fact that they might | ||
1700 | * be misdetected here is rather academic. | ||
1701 | */ | ||
1702 | |||
1703 | static int __devinit parport_PS2_supported(struct parport *pb) | ||
1704 | { | ||
1705 | int ok = 0; | ||
1706 | |||
1707 | clear_epp_timeout(pb); | ||
1708 | |||
1709 | /* try to tri-state the buffer */ | ||
1710 | parport_pc_data_reverse (pb); | ||
1711 | |||
1712 | parport_pc_write_data(pb, 0x55); | ||
1713 | if (parport_pc_read_data(pb) != 0x55) ok++; | ||
1714 | |||
1715 | parport_pc_write_data(pb, 0xaa); | ||
1716 | if (parport_pc_read_data(pb) != 0xaa) ok++; | ||
1717 | |||
1718 | /* cancel input mode */ | ||
1719 | parport_pc_data_forward (pb); | ||
1720 | |||
1721 | if (ok) { | ||
1722 | pb->modes |= PARPORT_MODE_TRISTATE; | ||
1723 | } else { | ||
1724 | struct parport_pc_private *priv = pb->private_data; | ||
1725 | priv->ctr_writable &= ~0x20; | ||
1726 | } | ||
1727 | |||
1728 | return ok; | ||
1729 | } | ||
1730 | |||
1731 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
1732 | static int __devinit parport_ECP_supported(struct parport *pb) | ||
1733 | { | ||
1734 | int i; | ||
1735 | int config, configb; | ||
1736 | int pword; | ||
1737 | struct parport_pc_private *priv = pb->private_data; | ||
1738 | /* Translate ECP intrLine to ISA irq value */ | ||
1739 | static const int intrline[]= { 0, 7, 9, 10, 11, 14, 15, 5 }; | ||
1740 | |||
1741 | /* If there is no ECR, we have no hope of supporting ECP. */ | ||
1742 | if (!priv->ecr) | ||
1743 | return 0; | ||
1744 | |||
1745 | /* Find out FIFO depth */ | ||
1746 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | ||
1747 | ECR_WRITE (pb, ECR_TST << 5); /* TEST FIFO */ | ||
1748 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02); i++) | ||
1749 | outb (0xaa, FIFO (pb)); | ||
1750 | |||
1751 | /* | ||
1752 | * Using LGS chipset it uses ECR register, but | ||
1753 | * it doesn't support ECP or FIFO MODE | ||
1754 | */ | ||
1755 | if (i == 1024) { | ||
1756 | ECR_WRITE (pb, ECR_SPP << 5); | ||
1757 | return 0; | ||
1758 | } | ||
1759 | |||
1760 | priv->fifo_depth = i; | ||
1761 | if (verbose_probing) | ||
1762 | printk (KERN_DEBUG "0x%lx: FIFO is %d bytes\n", pb->base, i); | ||
1763 | |||
1764 | /* Find out writeIntrThreshold */ | ||
1765 | frob_econtrol (pb, 1<<2, 1<<2); | ||
1766 | frob_econtrol (pb, 1<<2, 0); | ||
1767 | for (i = 1; i <= priv->fifo_depth; i++) { | ||
1768 | inb (FIFO (pb)); | ||
1769 | udelay (50); | ||
1770 | if (inb (ECONTROL (pb)) & (1<<2)) | ||
1771 | break; | ||
1772 | } | ||
1773 | |||
1774 | if (i <= priv->fifo_depth) { | ||
1775 | if (verbose_probing) | ||
1776 | printk (KERN_DEBUG "0x%lx: writeIntrThreshold is %d\n", | ||
1777 | pb->base, i); | ||
1778 | } else | ||
1779 | /* Number of bytes we know we can write if we get an | ||
1780 | interrupt. */ | ||
1781 | i = 0; | ||
1782 | |||
1783 | priv->writeIntrThreshold = i; | ||
1784 | |||
1785 | /* Find out readIntrThreshold */ | ||
1786 | frob_set_mode (pb, ECR_PS2); /* Reset FIFO and enable PS2 */ | ||
1787 | parport_pc_data_reverse (pb); /* Must be in PS2 mode */ | ||
1788 | frob_set_mode (pb, ECR_TST); /* Test FIFO */ | ||
1789 | frob_econtrol (pb, 1<<2, 1<<2); | ||
1790 | frob_econtrol (pb, 1<<2, 0); | ||
1791 | for (i = 1; i <= priv->fifo_depth; i++) { | ||
1792 | outb (0xaa, FIFO (pb)); | ||
1793 | if (inb (ECONTROL (pb)) & (1<<2)) | ||
1794 | break; | ||
1795 | } | ||
1796 | |||
1797 | if (i <= priv->fifo_depth) { | ||
1798 | if (verbose_probing) | ||
1799 | printk (KERN_INFO "0x%lx: readIntrThreshold is %d\n", | ||
1800 | pb->base, i); | ||
1801 | } else | ||
1802 | /* Number of bytes we can read if we get an interrupt. */ | ||
1803 | i = 0; | ||
1804 | |||
1805 | priv->readIntrThreshold = i; | ||
1806 | |||
1807 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | ||
1808 | ECR_WRITE (pb, 0xf4); /* Configuration mode */ | ||
1809 | config = inb (CONFIGA (pb)); | ||
1810 | pword = (config >> 4) & 0x7; | ||
1811 | switch (pword) { | ||
1812 | case 0: | ||
1813 | pword = 2; | ||
1814 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | ||
1815 | pb->base); | ||
1816 | break; | ||
1817 | case 2: | ||
1818 | pword = 4; | ||
1819 | printk (KERN_WARNING "0x%lx: Unsupported pword size!\n", | ||
1820 | pb->base); | ||
1821 | break; | ||
1822 | default: | ||
1823 | printk (KERN_WARNING "0x%lx: Unknown implementation ID\n", | ||
1824 | pb->base); | ||
1825 | /* Assume 1 */ | ||
1826 | case 1: | ||
1827 | pword = 1; | ||
1828 | } | ||
1829 | priv->pword = pword; | ||
1830 | |||
1831 | if (verbose_probing) { | ||
1832 | printk (KERN_DEBUG "0x%lx: PWord is %d bits\n", pb->base, 8 * pword); | ||
1833 | |||
1834 | printk (KERN_DEBUG "0x%lx: Interrupts are ISA-%s\n", pb->base, | ||
1835 | config & 0x80 ? "Level" : "Pulses"); | ||
1836 | |||
1837 | configb = inb (CONFIGB (pb)); | ||
1838 | printk (KERN_DEBUG "0x%lx: ECP port cfgA=0x%02x cfgB=0x%02x\n", | ||
1839 | pb->base, config, configb); | ||
1840 | printk (KERN_DEBUG "0x%lx: ECP settings irq=", pb->base); | ||
1841 | if ((configb >>3) & 0x07) | ||
1842 | printk("%d",intrline[(configb >>3) & 0x07]); | ||
1843 | else | ||
1844 | printk("<none or set by other means>"); | ||
1845 | printk (" dma="); | ||
1846 | if( (configb & 0x03 ) == 0x00) | ||
1847 | printk("<none or set by other means>\n"); | ||
1848 | else | ||
1849 | printk("%d\n",configb & 0x07); | ||
1850 | } | ||
1851 | |||
1852 | /* Go back to mode 000 */ | ||
1853 | frob_set_mode (pb, ECR_SPP); | ||
1854 | |||
1855 | return 1; | ||
1856 | } | ||
1857 | #endif | ||
1858 | |||
1859 | static int __devinit parport_ECPPS2_supported(struct parport *pb) | ||
1860 | { | ||
1861 | const struct parport_pc_private *priv = pb->private_data; | ||
1862 | int result; | ||
1863 | unsigned char oecr; | ||
1864 | |||
1865 | if (!priv->ecr) | ||
1866 | return 0; | ||
1867 | |||
1868 | oecr = inb (ECONTROL (pb)); | ||
1869 | ECR_WRITE (pb, ECR_PS2 << 5); | ||
1870 | result = parport_PS2_supported(pb); | ||
1871 | ECR_WRITE (pb, oecr); | ||
1872 | return result; | ||
1873 | } | ||
1874 | |||
1875 | /* EPP mode detection */ | ||
1876 | |||
1877 | static int __devinit parport_EPP_supported(struct parport *pb) | ||
1878 | { | ||
1879 | const struct parport_pc_private *priv = pb->private_data; | ||
1880 | |||
1881 | /* | ||
1882 | * Theory: | ||
1883 | * Bit 0 of STR is the EPP timeout bit, this bit is 0 | ||
1884 | * when EPP is possible and is set high when an EPP timeout | ||
1885 | * occurs (EPP uses the HALT line to stop the CPU while it does | ||
1886 | * the byte transfer, an EPP timeout occurs if the attached | ||
1887 | * device fails to respond after 10 micro seconds). | ||
1888 | * | ||
1889 | * This bit is cleared by either reading it (National Semi) | ||
1890 | * or writing a 1 to the bit (SMC, UMC, WinBond), others ??? | ||
1891 | * This bit is always high in non EPP modes. | ||
1892 | */ | ||
1893 | |||
1894 | /* If EPP timeout bit clear then EPP available */ | ||
1895 | if (!clear_epp_timeout(pb)) { | ||
1896 | return 0; /* No way to clear timeout */ | ||
1897 | } | ||
1898 | |||
1899 | /* Check for Intel bug. */ | ||
1900 | if (priv->ecr) { | ||
1901 | unsigned char i; | ||
1902 | for (i = 0x00; i < 0x80; i += 0x20) { | ||
1903 | ECR_WRITE (pb, i); | ||
1904 | if (clear_epp_timeout (pb)) { | ||
1905 | /* Phony EPP in ECP. */ | ||
1906 | return 0; | ||
1907 | } | ||
1908 | } | ||
1909 | } | ||
1910 | |||
1911 | pb->modes |= PARPORT_MODE_EPP; | ||
1912 | |||
1913 | /* Set up access functions to use EPP hardware. */ | ||
1914 | pb->ops->epp_read_data = parport_pc_epp_read_data; | ||
1915 | pb->ops->epp_write_data = parport_pc_epp_write_data; | ||
1916 | pb->ops->epp_read_addr = parport_pc_epp_read_addr; | ||
1917 | pb->ops->epp_write_addr = parport_pc_epp_write_addr; | ||
1918 | |||
1919 | return 1; | ||
1920 | } | ||
1921 | |||
1922 | static int __devinit parport_ECPEPP_supported(struct parport *pb) | ||
1923 | { | ||
1924 | struct parport_pc_private *priv = pb->private_data; | ||
1925 | int result; | ||
1926 | unsigned char oecr; | ||
1927 | |||
1928 | if (!priv->ecr) { | ||
1929 | return 0; | ||
1930 | } | ||
1931 | |||
1932 | oecr = inb (ECONTROL (pb)); | ||
1933 | /* Search for SMC style EPP+ECP mode */ | ||
1934 | ECR_WRITE (pb, 0x80); | ||
1935 | outb (0x04, CONTROL (pb)); | ||
1936 | result = parport_EPP_supported(pb); | ||
1937 | |||
1938 | ECR_WRITE (pb, oecr); | ||
1939 | |||
1940 | if (result) { | ||
1941 | /* Set up access functions to use ECP+EPP hardware. */ | ||
1942 | pb->ops->epp_read_data = parport_pc_ecpepp_read_data; | ||
1943 | pb->ops->epp_write_data = parport_pc_ecpepp_write_data; | ||
1944 | pb->ops->epp_read_addr = parport_pc_ecpepp_read_addr; | ||
1945 | pb->ops->epp_write_addr = parport_pc_ecpepp_write_addr; | ||
1946 | } | ||
1947 | |||
1948 | return result; | ||
1949 | } | ||
1950 | |||
1951 | #else /* No IEEE 1284 support */ | ||
1952 | |||
1953 | /* Don't bother probing for modes we know we won't use. */ | ||
1954 | static int __devinit parport_PS2_supported(struct parport *pb) { return 0; } | ||
1955 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
1956 | static int __devinit parport_ECP_supported(struct parport *pb) { return 0; } | ||
1957 | #endif | ||
1958 | static int __devinit parport_EPP_supported(struct parport *pb) { return 0; } | ||
1959 | static int __devinit parport_ECPEPP_supported(struct parport *pb){return 0;} | ||
1960 | static int __devinit parport_ECPPS2_supported(struct parport *pb){return 0;} | ||
1961 | |||
1962 | #endif /* No IEEE 1284 support */ | ||
1963 | |||
1964 | /* --- IRQ detection -------------------------------------- */ | ||
1965 | |||
1966 | /* Only if supports ECP mode */ | ||
1967 | static int __devinit programmable_irq_support(struct parport *pb) | ||
1968 | { | ||
1969 | int irq, intrLine; | ||
1970 | unsigned char oecr = inb (ECONTROL (pb)); | ||
1971 | static const int lookup[8] = { | ||
1972 | PARPORT_IRQ_NONE, 7, 9, 10, 11, 14, 15, 5 | ||
1973 | }; | ||
1974 | |||
1975 | ECR_WRITE (pb, ECR_CNF << 5); /* Configuration MODE */ | ||
1976 | |||
1977 | intrLine = (inb (CONFIGB (pb)) >> 3) & 0x07; | ||
1978 | irq = lookup[intrLine]; | ||
1979 | |||
1980 | ECR_WRITE (pb, oecr); | ||
1981 | return irq; | ||
1982 | } | ||
1983 | |||
1984 | static int __devinit irq_probe_ECP(struct parport *pb) | ||
1985 | { | ||
1986 | int i; | ||
1987 | unsigned long irqs; | ||
1988 | |||
1989 | irqs = probe_irq_on(); | ||
1990 | |||
1991 | ECR_WRITE (pb, ECR_SPP << 5); /* Reset FIFO */ | ||
1992 | ECR_WRITE (pb, (ECR_TST << 5) | 0x04); | ||
1993 | ECR_WRITE (pb, ECR_TST << 5); | ||
1994 | |||
1995 | /* If Full FIFO sure that writeIntrThreshold is generated */ | ||
1996 | for (i=0; i < 1024 && !(inb (ECONTROL (pb)) & 0x02) ; i++) | ||
1997 | outb (0xaa, FIFO (pb)); | ||
1998 | |||
1999 | pb->irq = probe_irq_off(irqs); | ||
2000 | ECR_WRITE (pb, ECR_SPP << 5); | ||
2001 | |||
2002 | if (pb->irq <= 0) | ||
2003 | pb->irq = PARPORT_IRQ_NONE; | ||
2004 | |||
2005 | return pb->irq; | ||
2006 | } | ||
2007 | |||
2008 | /* | ||
2009 | * This detection seems that only works in National Semiconductors | ||
2010 | * This doesn't work in SMC, LGS, and Winbond | ||
2011 | */ | ||
2012 | static int __devinit irq_probe_EPP(struct parport *pb) | ||
2013 | { | ||
2014 | #ifndef ADVANCED_DETECT | ||
2015 | return PARPORT_IRQ_NONE; | ||
2016 | #else | ||
2017 | int irqs; | ||
2018 | unsigned char oecr; | ||
2019 | |||
2020 | if (pb->modes & PARPORT_MODE_PCECR) | ||
2021 | oecr = inb (ECONTROL (pb)); | ||
2022 | |||
2023 | irqs = probe_irq_on(); | ||
2024 | |||
2025 | if (pb->modes & PARPORT_MODE_PCECR) | ||
2026 | frob_econtrol (pb, 0x10, 0x10); | ||
2027 | |||
2028 | clear_epp_timeout(pb); | ||
2029 | parport_pc_frob_control (pb, 0x20, 0x20); | ||
2030 | parport_pc_frob_control (pb, 0x10, 0x10); | ||
2031 | clear_epp_timeout(pb); | ||
2032 | |||
2033 | /* Device isn't expecting an EPP read | ||
2034 | * and generates an IRQ. | ||
2035 | */ | ||
2036 | parport_pc_read_epp(pb); | ||
2037 | udelay(20); | ||
2038 | |||
2039 | pb->irq = probe_irq_off (irqs); | ||
2040 | if (pb->modes & PARPORT_MODE_PCECR) | ||
2041 | ECR_WRITE (pb, oecr); | ||
2042 | parport_pc_write_control(pb, 0xc); | ||
2043 | |||
2044 | if (pb->irq <= 0) | ||
2045 | pb->irq = PARPORT_IRQ_NONE; | ||
2046 | |||
2047 | return pb->irq; | ||
2048 | #endif /* Advanced detection */ | ||
2049 | } | ||
2050 | |||
2051 | static int __devinit irq_probe_SPP(struct parport *pb) | ||
2052 | { | ||
2053 | /* Don't even try to do this. */ | ||
2054 | return PARPORT_IRQ_NONE; | ||
2055 | } | ||
2056 | |||
2057 | /* We will attempt to share interrupt requests since other devices | ||
2058 | * such as sound cards and network cards seem to like using the | ||
2059 | * printer IRQs. | ||
2060 | * | ||
2061 | * When ECP is available we can autoprobe for IRQs. | ||
2062 | * NOTE: If we can autoprobe it, we can register the IRQ. | ||
2063 | */ | ||
2064 | static int __devinit parport_irq_probe(struct parport *pb) | ||
2065 | { | ||
2066 | struct parport_pc_private *priv = pb->private_data; | ||
2067 | |||
2068 | if (priv->ecr) { | ||
2069 | pb->irq = programmable_irq_support(pb); | ||
2070 | |||
2071 | if (pb->irq == PARPORT_IRQ_NONE) | ||
2072 | pb->irq = irq_probe_ECP(pb); | ||
2073 | } | ||
2074 | |||
2075 | if ((pb->irq == PARPORT_IRQ_NONE) && priv->ecr && | ||
2076 | (pb->modes & PARPORT_MODE_EPP)) | ||
2077 | pb->irq = irq_probe_EPP(pb); | ||
2078 | |||
2079 | clear_epp_timeout(pb); | ||
2080 | |||
2081 | if (pb->irq == PARPORT_IRQ_NONE && (pb->modes & PARPORT_MODE_EPP)) | ||
2082 | pb->irq = irq_probe_EPP(pb); | ||
2083 | |||
2084 | clear_epp_timeout(pb); | ||
2085 | |||
2086 | if (pb->irq == PARPORT_IRQ_NONE) | ||
2087 | pb->irq = irq_probe_SPP(pb); | ||
2088 | |||
2089 | if (pb->irq == PARPORT_IRQ_NONE) | ||
2090 | pb->irq = get_superio_irq(pb); | ||
2091 | |||
2092 | return pb->irq; | ||
2093 | } | ||
2094 | |||
2095 | /* --- DMA detection -------------------------------------- */ | ||
2096 | |||
2097 | /* Only if chipset conforms to ECP ISA Interface Standard */ | ||
2098 | static int __devinit programmable_dma_support (struct parport *p) | ||
2099 | { | ||
2100 | unsigned char oecr = inb (ECONTROL (p)); | ||
2101 | int dma; | ||
2102 | |||
2103 | frob_set_mode (p, ECR_CNF); | ||
2104 | |||
2105 | dma = inb (CONFIGB(p)) & 0x07; | ||
2106 | /* 000: Indicates jumpered 8-bit DMA if read-only. | ||
2107 | 100: Indicates jumpered 16-bit DMA if read-only. */ | ||
2108 | if ((dma & 0x03) == 0) | ||
2109 | dma = PARPORT_DMA_NONE; | ||
2110 | |||
2111 | ECR_WRITE (p, oecr); | ||
2112 | return dma; | ||
2113 | } | ||
2114 | |||
2115 | static int __devinit parport_dma_probe (struct parport *p) | ||
2116 | { | ||
2117 | const struct parport_pc_private *priv = p->private_data; | ||
2118 | if (priv->ecr) | ||
2119 | p->dma = programmable_dma_support(p); /* ask ECP chipset first */ | ||
2120 | if (p->dma == PARPORT_DMA_NONE) { | ||
2121 | /* ask known Super-IO chips proper, although these | ||
2122 | claim ECP compatible, some don't report their DMA | ||
2123 | conforming to ECP standards */ | ||
2124 | p->dma = get_superio_dma(p); | ||
2125 | } | ||
2126 | |||
2127 | return p->dma; | ||
2128 | } | ||
2129 | |||
2130 | /* --- Initialisation code -------------------------------- */ | ||
2131 | |||
2132 | static LIST_HEAD(ports_list); | ||
2133 | static DEFINE_SPINLOCK(ports_lock); | ||
2134 | |||
2135 | struct parport *parport_pc_probe_port (unsigned long int base, | ||
2136 | unsigned long int base_hi, | ||
2137 | int irq, int dma, | ||
2138 | struct pci_dev *dev) | ||
2139 | { | ||
2140 | struct parport_pc_private *priv; | ||
2141 | struct parport_operations *ops; | ||
2142 | struct parport *p; | ||
2143 | int probedirq = PARPORT_IRQ_NONE; | ||
2144 | struct resource *base_res; | ||
2145 | struct resource *ECR_res = NULL; | ||
2146 | struct resource *EPP_res = NULL; | ||
2147 | |||
2148 | ops = kmalloc(sizeof (struct parport_operations), GFP_KERNEL); | ||
2149 | if (!ops) | ||
2150 | goto out1; | ||
2151 | |||
2152 | priv = kmalloc (sizeof (struct parport_pc_private), GFP_KERNEL); | ||
2153 | if (!priv) | ||
2154 | goto out2; | ||
2155 | |||
2156 | /* a misnomer, actually - it's allocate and reserve parport number */ | ||
2157 | p = parport_register_port(base, irq, dma, ops); | ||
2158 | if (!p) | ||
2159 | goto out3; | ||
2160 | |||
2161 | base_res = request_region(base, 3, p->name); | ||
2162 | if (!base_res) | ||
2163 | goto out4; | ||
2164 | |||
2165 | memcpy(ops, &parport_pc_ops, sizeof (struct parport_operations)); | ||
2166 | priv->ctr = 0xc; | ||
2167 | priv->ctr_writable = ~0x10; | ||
2168 | priv->ecr = 0; | ||
2169 | priv->fifo_depth = 0; | ||
2170 | priv->dma_buf = NULL; | ||
2171 | priv->dma_handle = 0; | ||
2172 | priv->dev = dev; | ||
2173 | INIT_LIST_HEAD(&priv->list); | ||
2174 | priv->port = p; | ||
2175 | p->base_hi = base_hi; | ||
2176 | p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT; | ||
2177 | p->private_data = priv; | ||
2178 | |||
2179 | if (base_hi) { | ||
2180 | ECR_res = request_region(base_hi, 3, p->name); | ||
2181 | if (ECR_res) | ||
2182 | parport_ECR_present(p); | ||
2183 | } | ||
2184 | |||
2185 | if (base != 0x3bc) { | ||
2186 | EPP_res = request_region(base+0x3, 5, p->name); | ||
2187 | if (EPP_res) | ||
2188 | if (!parport_EPP_supported(p)) | ||
2189 | parport_ECPEPP_supported(p); | ||
2190 | } | ||
2191 | if (!parport_SPP_supported (p)) | ||
2192 | /* No port. */ | ||
2193 | goto out5; | ||
2194 | if (priv->ecr) | ||
2195 | parport_ECPPS2_supported(p); | ||
2196 | else | ||
2197 | parport_PS2_supported(p); | ||
2198 | |||
2199 | p->size = (p->modes & PARPORT_MODE_EPP)?8:3; | ||
2200 | |||
2201 | printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base); | ||
2202 | if (p->base_hi && priv->ecr) | ||
2203 | printk(" (0x%lx)", p->base_hi); | ||
2204 | if (p->irq == PARPORT_IRQ_AUTO) { | ||
2205 | p->irq = PARPORT_IRQ_NONE; | ||
2206 | parport_irq_probe(p); | ||
2207 | } else if (p->irq == PARPORT_IRQ_PROBEONLY) { | ||
2208 | p->irq = PARPORT_IRQ_NONE; | ||
2209 | parport_irq_probe(p); | ||
2210 | probedirq = p->irq; | ||
2211 | p->irq = PARPORT_IRQ_NONE; | ||
2212 | } | ||
2213 | if (p->irq != PARPORT_IRQ_NONE) { | ||
2214 | printk(", irq %d", p->irq); | ||
2215 | priv->ctr_writable |= 0x10; | ||
2216 | |||
2217 | if (p->dma == PARPORT_DMA_AUTO) { | ||
2218 | p->dma = PARPORT_DMA_NONE; | ||
2219 | parport_dma_probe(p); | ||
2220 | } | ||
2221 | } | ||
2222 | if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq | ||
2223 | is mandatory (see above) */ | ||
2224 | p->dma = PARPORT_DMA_NONE; | ||
2225 | |||
2226 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
2227 | if (parport_ECP_supported(p) && | ||
2228 | p->dma != PARPORT_DMA_NOFIFO && | ||
2229 | priv->fifo_depth > 0 && p->irq != PARPORT_IRQ_NONE) { | ||
2230 | p->modes |= PARPORT_MODE_ECP | PARPORT_MODE_COMPAT; | ||
2231 | p->ops->compat_write_data = parport_pc_compat_write_block_pio; | ||
2232 | #ifdef CONFIG_PARPORT_1284 | ||
2233 | p->ops->ecp_write_data = parport_pc_ecp_write_block_pio; | ||
2234 | /* currently broken, but working on it.. (FB) */ | ||
2235 | /* p->ops->ecp_read_data = parport_pc_ecp_read_block_pio; */ | ||
2236 | #endif /* IEEE 1284 support */ | ||
2237 | if (p->dma != PARPORT_DMA_NONE) { | ||
2238 | printk(", dma %d", p->dma); | ||
2239 | p->modes |= PARPORT_MODE_DMA; | ||
2240 | } | ||
2241 | else printk(", using FIFO"); | ||
2242 | } | ||
2243 | else | ||
2244 | /* We can't use the DMA channel after all. */ | ||
2245 | p->dma = PARPORT_DMA_NONE; | ||
2246 | #endif /* Allowed to use FIFO/DMA */ | ||
2247 | |||
2248 | printk(" ["); | ||
2249 | #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}} | ||
2250 | { | ||
2251 | int f = 0; | ||
2252 | printmode(PCSPP); | ||
2253 | printmode(TRISTATE); | ||
2254 | printmode(COMPAT) | ||
2255 | printmode(EPP); | ||
2256 | printmode(ECP); | ||
2257 | printmode(DMA); | ||
2258 | } | ||
2259 | #undef printmode | ||
2260 | #ifndef CONFIG_PARPORT_1284 | ||
2261 | printk ("(,...)"); | ||
2262 | #endif /* CONFIG_PARPORT_1284 */ | ||
2263 | printk("]\n"); | ||
2264 | if (probedirq != PARPORT_IRQ_NONE) | ||
2265 | printk(KERN_INFO "%s: irq %d detected\n", p->name, probedirq); | ||
2266 | |||
2267 | /* If No ECP release the ports grabbed above. */ | ||
2268 | if (ECR_res && (p->modes & PARPORT_MODE_ECP) == 0) { | ||
2269 | release_region(base_hi, 3); | ||
2270 | ECR_res = NULL; | ||
2271 | } | ||
2272 | /* Likewise for EEP ports */ | ||
2273 | if (EPP_res && (p->modes & PARPORT_MODE_EPP) == 0) { | ||
2274 | release_region(base+3, 5); | ||
2275 | EPP_res = NULL; | ||
2276 | } | ||
2277 | if (p->irq != PARPORT_IRQ_NONE) { | ||
2278 | if (request_irq (p->irq, parport_pc_interrupt, | ||
2279 | 0, p->name, p)) { | ||
2280 | printk (KERN_WARNING "%s: irq %d in use, " | ||
2281 | "resorting to polled operation\n", | ||
2282 | p->name, p->irq); | ||
2283 | p->irq = PARPORT_IRQ_NONE; | ||
2284 | p->dma = PARPORT_DMA_NONE; | ||
2285 | } | ||
2286 | |||
2287 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
2288 | if (p->dma != PARPORT_DMA_NONE) { | ||
2289 | if (request_dma (p->dma, p->name)) { | ||
2290 | printk (KERN_WARNING "%s: dma %d in use, " | ||
2291 | "resorting to PIO operation\n", | ||
2292 | p->name, p->dma); | ||
2293 | p->dma = PARPORT_DMA_NONE; | ||
2294 | } else { | ||
2295 | priv->dma_buf = | ||
2296 | pci_alloc_consistent(priv->dev, | ||
2297 | PAGE_SIZE, | ||
2298 | &priv->dma_handle); | ||
2299 | if (! priv->dma_buf) { | ||
2300 | printk (KERN_WARNING "%s: " | ||
2301 | "cannot get buffer for DMA, " | ||
2302 | "resorting to PIO operation\n", | ||
2303 | p->name); | ||
2304 | free_dma(p->dma); | ||
2305 | p->dma = PARPORT_DMA_NONE; | ||
2306 | } | ||
2307 | } | ||
2308 | } | ||
2309 | #endif /* CONFIG_PARPORT_PC_FIFO */ | ||
2310 | } | ||
2311 | |||
2312 | /* Done probing. Now put the port into a sensible start-up state. */ | ||
2313 | if (priv->ecr) | ||
2314 | /* | ||
2315 | * Put the ECP detected port in PS2 mode. | ||
2316 | * Do this also for ports that have ECR but don't do ECP. | ||
2317 | */ | ||
2318 | ECR_WRITE (p, 0x34); | ||
2319 | |||
2320 | parport_pc_write_data(p, 0); | ||
2321 | parport_pc_data_forward (p); | ||
2322 | |||
2323 | /* Now that we've told the sharing engine about the port, and | ||
2324 | found out its characteristics, let the high-level drivers | ||
2325 | know about it. */ | ||
2326 | spin_lock(&ports_lock); | ||
2327 | list_add(&priv->list, &ports_list); | ||
2328 | spin_unlock(&ports_lock); | ||
2329 | parport_announce_port (p); | ||
2330 | |||
2331 | return p; | ||
2332 | |||
2333 | out5: | ||
2334 | if (ECR_res) | ||
2335 | release_region(base_hi, 3); | ||
2336 | if (EPP_res) | ||
2337 | release_region(base+0x3, 5); | ||
2338 | release_region(base, 3); | ||
2339 | out4: | ||
2340 | parport_put_port(p); | ||
2341 | out3: | ||
2342 | kfree (priv); | ||
2343 | out2: | ||
2344 | kfree (ops); | ||
2345 | out1: | ||
2346 | return NULL; | ||
2347 | } | ||
2348 | |||
2349 | EXPORT_SYMBOL (parport_pc_probe_port); | ||
2350 | |||
2351 | void parport_pc_unregister_port (struct parport *p) | ||
2352 | { | ||
2353 | struct parport_pc_private *priv = p->private_data; | ||
2354 | struct parport_operations *ops = p->ops; | ||
2355 | |||
2356 | parport_remove_port(p); | ||
2357 | spin_lock(&ports_lock); | ||
2358 | list_del_init(&priv->list); | ||
2359 | spin_unlock(&ports_lock); | ||
2360 | if (p->dma != PARPORT_DMA_NONE) | ||
2361 | free_dma(p->dma); | ||
2362 | if (p->irq != PARPORT_IRQ_NONE) | ||
2363 | free_irq(p->irq, p); | ||
2364 | release_region(p->base, 3); | ||
2365 | if (p->size > 3) | ||
2366 | release_region(p->base + 3, p->size - 3); | ||
2367 | if (p->modes & PARPORT_MODE_ECP) | ||
2368 | release_region(p->base_hi, 3); | ||
2369 | #ifdef CONFIG_PARPORT_PC_FIFO | ||
2370 | if (priv->dma_buf) | ||
2371 | pci_free_consistent(priv->dev, PAGE_SIZE, | ||
2372 | priv->dma_buf, | ||
2373 | priv->dma_handle); | ||
2374 | #endif /* CONFIG_PARPORT_PC_FIFO */ | ||
2375 | kfree (p->private_data); | ||
2376 | parport_put_port(p); | ||
2377 | kfree (ops); /* hope no-one cached it */ | ||
2378 | } | ||
2379 | |||
2380 | EXPORT_SYMBOL (parport_pc_unregister_port); | ||
2381 | |||
2382 | #ifdef CONFIG_PCI | ||
2383 | |||
2384 | /* ITE support maintained by Rich Liu <richliu@poorman.org> */ | ||
2385 | static int __devinit sio_ite_8872_probe (struct pci_dev *pdev, int autoirq, | ||
2386 | int autodma, struct parport_pc_via_data *via) | ||
2387 | { | ||
2388 | short inta_addr[6] = { 0x2A0, 0x2C0, 0x220, 0x240, 0x1E0 }; | ||
2389 | struct resource *base_res; | ||
2390 | u32 ite8872set; | ||
2391 | u32 ite8872_lpt, ite8872_lpthi; | ||
2392 | u8 ite8872_irq, type; | ||
2393 | char *fake_name = "parport probe"; | ||
2394 | int irq; | ||
2395 | int i; | ||
2396 | |||
2397 | DPRINTK (KERN_DEBUG "sio_ite_8872_probe()\n"); | ||
2398 | |||
2399 | // make sure which one chip | ||
2400 | for(i = 0; i < 5; i++) { | ||
2401 | base_res = request_region(inta_addr[i], 0x8, fake_name); | ||
2402 | if (base_res) { | ||
2403 | int test; | ||
2404 | pci_write_config_dword (pdev, 0x60, | ||
2405 | 0xe7000000 | inta_addr[i]); | ||
2406 | pci_write_config_dword (pdev, 0x78, | ||
2407 | 0x00000000 | inta_addr[i]); | ||
2408 | test = inb (inta_addr[i]); | ||
2409 | if (test != 0xff) break; | ||
2410 | release_region(inta_addr[i], 0x8); | ||
2411 | } | ||
2412 | } | ||
2413 | if(i >= 5) { | ||
2414 | printk (KERN_INFO "parport_pc: cannot find ITE8872 INTA\n"); | ||
2415 | return 0; | ||
2416 | } | ||
2417 | |||
2418 | type = inb (inta_addr[i] + 0x18); | ||
2419 | type &= 0x0f; | ||
2420 | |||
2421 | switch (type) { | ||
2422 | case 0x2: | ||
2423 | printk (KERN_INFO "parport_pc: ITE8871 found (1P)\n"); | ||
2424 | ite8872set = 0x64200000; | ||
2425 | break; | ||
2426 | case 0xa: | ||
2427 | printk (KERN_INFO "parport_pc: ITE8875 found (1P)\n"); | ||
2428 | ite8872set = 0x64200000; | ||
2429 | break; | ||
2430 | case 0xe: | ||
2431 | printk (KERN_INFO "parport_pc: ITE8872 found (2S1P)\n"); | ||
2432 | ite8872set = 0x64e00000; | ||
2433 | break; | ||
2434 | case 0x6: | ||
2435 | printk (KERN_INFO "parport_pc: ITE8873 found (1S)\n"); | ||
2436 | return 0; | ||
2437 | case 0x8: | ||
2438 | DPRINTK (KERN_DEBUG "parport_pc: ITE8874 found (2S)\n"); | ||
2439 | return 0; | ||
2440 | default: | ||
2441 | printk (KERN_INFO "parport_pc: unknown ITE887x\n"); | ||
2442 | printk (KERN_INFO "parport_pc: please mail 'lspci -nvv' " | ||
2443 | "output to Rich.Liu@ite.com.tw\n"); | ||
2444 | return 0; | ||
2445 | } | ||
2446 | |||
2447 | pci_read_config_byte (pdev, 0x3c, &ite8872_irq); | ||
2448 | pci_read_config_dword (pdev, 0x1c, &ite8872_lpt); | ||
2449 | ite8872_lpt &= 0x0000ff00; | ||
2450 | pci_read_config_dword (pdev, 0x20, &ite8872_lpthi); | ||
2451 | ite8872_lpthi &= 0x0000ff00; | ||
2452 | pci_write_config_dword (pdev, 0x6c, 0xe3000000 | ite8872_lpt); | ||
2453 | pci_write_config_dword (pdev, 0x70, 0xe3000000 | ite8872_lpthi); | ||
2454 | pci_write_config_dword (pdev, 0x80, (ite8872_lpthi<<16) | ite8872_lpt); | ||
2455 | // SET SPP&EPP , Parallel Port NO DMA , Enable All Function | ||
2456 | // SET Parallel IRQ | ||
2457 | pci_write_config_dword (pdev, 0x9c, | ||
2458 | ite8872set | (ite8872_irq * 0x11111)); | ||
2459 | |||
2460 | DPRINTK (KERN_DEBUG "ITE887x: The IRQ is %d.\n", ite8872_irq); | ||
2461 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O port is 0x%x.\n", | ||
2462 | ite8872_lpt); | ||
2463 | DPRINTK (KERN_DEBUG "ITE887x: The PARALLEL I/O porthi is 0x%x.\n", | ||
2464 | ite8872_lpthi); | ||
2465 | |||
2466 | /* Let the user (or defaults) steer us away from interrupts */ | ||
2467 | irq = ite8872_irq; | ||
2468 | if (autoirq != PARPORT_IRQ_AUTO) | ||
2469 | irq = PARPORT_IRQ_NONE; | ||
2470 | |||
2471 | /* | ||
2472 | * Release the resource so that parport_pc_probe_port can get it. | ||
2473 | */ | ||
2474 | release_resource(base_res); | ||
2475 | if (parport_pc_probe_port (ite8872_lpt, ite8872_lpthi, | ||
2476 | irq, PARPORT_DMA_NONE, NULL)) { | ||
2477 | printk (KERN_INFO | ||
2478 | "parport_pc: ITE 8872 parallel port: io=0x%X", | ||
2479 | ite8872_lpt); | ||
2480 | if (irq != PARPORT_IRQ_NONE) | ||
2481 | printk (", irq=%d", irq); | ||
2482 | printk ("\n"); | ||
2483 | return 1; | ||
2484 | } | ||
2485 | |||
2486 | return 0; | ||
2487 | } | ||
2488 | |||
2489 | /* VIA 8231 support by Pavel Fedin <sonic_amiga@rambler.ru> | ||
2490 | based on VIA 686a support code by Jeff Garzik <jgarzik@pobox.com> */ | ||
2491 | static int __devinitdata parport_init_mode = 0; | ||
2492 | |||
2493 | /* Data for two known VIA chips */ | ||
2494 | static struct parport_pc_via_data via_686a_data __devinitdata = { | ||
2495 | 0x51, | ||
2496 | 0x50, | ||
2497 | 0x85, | ||
2498 | 0x02, | ||
2499 | 0xE2, | ||
2500 | 0xF0, | ||
2501 | 0xE6 | ||
2502 | }; | ||
2503 | static struct parport_pc_via_data via_8231_data __devinitdata = { | ||
2504 | 0x45, | ||
2505 | 0x44, | ||
2506 | 0x50, | ||
2507 | 0x04, | ||
2508 | 0xF2, | ||
2509 | 0xFA, | ||
2510 | 0xF6 | ||
2511 | }; | ||
2512 | |||
2513 | static int __devinit sio_via_probe (struct pci_dev *pdev, int autoirq, | ||
2514 | int autodma, struct parport_pc_via_data *via) | ||
2515 | { | ||
2516 | u8 tmp, tmp2, siofunc; | ||
2517 | u8 ppcontrol = 0; | ||
2518 | int dma, irq; | ||
2519 | unsigned port1, port2; | ||
2520 | unsigned have_epp = 0; | ||
2521 | |||
2522 | printk(KERN_DEBUG "parport_pc: VIA 686A/8231 detected\n"); | ||
2523 | |||
2524 | switch(parport_init_mode) | ||
2525 | { | ||
2526 | case 1: | ||
2527 | printk(KERN_DEBUG "parport_pc: setting SPP mode\n"); | ||
2528 | siofunc = VIA_FUNCTION_PARPORT_SPP; | ||
2529 | break; | ||
2530 | case 2: | ||
2531 | printk(KERN_DEBUG "parport_pc: setting PS/2 mode\n"); | ||
2532 | siofunc = VIA_FUNCTION_PARPORT_SPP; | ||
2533 | ppcontrol = VIA_PARPORT_BIDIR; | ||
2534 | break; | ||
2535 | case 3: | ||
2536 | printk(KERN_DEBUG "parport_pc: setting EPP mode\n"); | ||
2537 | siofunc = VIA_FUNCTION_PARPORT_EPP; | ||
2538 | ppcontrol = VIA_PARPORT_BIDIR; | ||
2539 | have_epp = 1; | ||
2540 | break; | ||
2541 | case 4: | ||
2542 | printk(KERN_DEBUG "parport_pc: setting ECP mode\n"); | ||
2543 | siofunc = VIA_FUNCTION_PARPORT_ECP; | ||
2544 | ppcontrol = VIA_PARPORT_BIDIR; | ||
2545 | break; | ||
2546 | case 5: | ||
2547 | printk(KERN_DEBUG "parport_pc: setting EPP+ECP mode\n"); | ||
2548 | siofunc = VIA_FUNCTION_PARPORT_ECP; | ||
2549 | ppcontrol = VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP; | ||
2550 | have_epp = 1; | ||
2551 | break; | ||
2552 | default: | ||
2553 | printk(KERN_DEBUG "parport_pc: probing current configuration\n"); | ||
2554 | siofunc = VIA_FUNCTION_PROBE; | ||
2555 | break; | ||
2556 | } | ||
2557 | /* | ||
2558 | * unlock super i/o configuration | ||
2559 | */ | ||
2560 | pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp); | ||
2561 | tmp |= via->via_pci_superio_config_data; | ||
2562 | pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp); | ||
2563 | |||
2564 | /* Bits 1-0: Parallel Port Mode / Enable */ | ||
2565 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2566 | tmp = inb (VIA_CONFIG_DATA); | ||
2567 | /* Bit 5: EPP+ECP enable; bit 7: PS/2 bidirectional port enable */ | ||
2568 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2569 | tmp2 = inb (VIA_CONFIG_DATA); | ||
2570 | if (siofunc == VIA_FUNCTION_PROBE) | ||
2571 | { | ||
2572 | siofunc = tmp & VIA_FUNCTION_PARPORT_DISABLE; | ||
2573 | ppcontrol = tmp2; | ||
2574 | } | ||
2575 | else | ||
2576 | { | ||
2577 | tmp &= ~VIA_FUNCTION_PARPORT_DISABLE; | ||
2578 | tmp |= siofunc; | ||
2579 | outb(via->viacfg_function, VIA_CONFIG_INDEX); | ||
2580 | outb(tmp, VIA_CONFIG_DATA); | ||
2581 | tmp2 &= ~(VIA_PARPORT_BIDIR|VIA_PARPORT_ECPEPP); | ||
2582 | tmp2 |= ppcontrol; | ||
2583 | outb(via->viacfg_parport_control, VIA_CONFIG_INDEX); | ||
2584 | outb(tmp2, VIA_CONFIG_DATA); | ||
2585 | } | ||
2586 | |||
2587 | /* Parallel Port I/O Base Address, bits 9-2 */ | ||
2588 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | ||
2589 | port1 = inb(VIA_CONFIG_DATA) << 2; | ||
2590 | |||
2591 | printk (KERN_DEBUG "parport_pc: Current parallel port base: 0x%X\n",port1); | ||
2592 | if ((port1 == 0x3BC) && have_epp) | ||
2593 | { | ||
2594 | outb(via->viacfg_parport_base, VIA_CONFIG_INDEX); | ||
2595 | outb((0x378 >> 2), VIA_CONFIG_DATA); | ||
2596 | printk(KERN_DEBUG "parport_pc: Parallel port base changed to 0x378\n"); | ||
2597 | port1 = 0x378; | ||
2598 | } | ||
2599 | |||
2600 | /* | ||
2601 | * lock super i/o configuration | ||
2602 | */ | ||
2603 | pci_read_config_byte(pdev, via->via_pci_superio_config_reg, &tmp); | ||
2604 | tmp &= ~via->via_pci_superio_config_data; | ||
2605 | pci_write_config_byte(pdev, via->via_pci_superio_config_reg, tmp); | ||
2606 | |||
2607 | if (siofunc == VIA_FUNCTION_PARPORT_DISABLE) { | ||
2608 | printk(KERN_INFO "parport_pc: VIA parallel port disabled in BIOS\n"); | ||
2609 | return 0; | ||
2610 | } | ||
2611 | |||
2612 | /* Bits 7-4: PnP Routing for Parallel Port IRQ */ | ||
2613 | pci_read_config_byte(pdev, via->via_pci_parport_irq_reg, &tmp); | ||
2614 | irq = ((tmp & VIA_IRQCONTROL_PARALLEL) >> 4); | ||
2615 | |||
2616 | if (siofunc == VIA_FUNCTION_PARPORT_ECP) | ||
2617 | { | ||
2618 | /* Bits 3-2: PnP Routing for Parallel Port DMA */ | ||
2619 | pci_read_config_byte(pdev, via->via_pci_parport_dma_reg, &tmp); | ||
2620 | dma = ((tmp & VIA_DMACONTROL_PARALLEL) >> 2); | ||
2621 | } | ||
2622 | else | ||
2623 | /* if ECP not enabled, DMA is not enabled, assumed bogus 'dma' value */ | ||
2624 | dma = PARPORT_DMA_NONE; | ||
2625 | |||
2626 | /* Let the user (or defaults) steer us away from interrupts and DMA */ | ||
2627 | if (autoirq == PARPORT_IRQ_NONE) { | ||
2628 | irq = PARPORT_IRQ_NONE; | ||
2629 | dma = PARPORT_DMA_NONE; | ||
2630 | } | ||
2631 | if (autodma == PARPORT_DMA_NONE) | ||
2632 | dma = PARPORT_DMA_NONE; | ||
2633 | |||
2634 | switch (port1) { | ||
2635 | case 0x3bc: port2 = 0x7bc; break; | ||
2636 | case 0x378: port2 = 0x778; break; | ||
2637 | case 0x278: port2 = 0x678; break; | ||
2638 | default: | ||
2639 | printk(KERN_INFO "parport_pc: Weird VIA parport base 0x%X, ignoring\n", | ||
2640 | port1); | ||
2641 | return 0; | ||
2642 | } | ||
2643 | |||
2644 | /* filter bogus IRQs */ | ||
2645 | switch (irq) { | ||
2646 | case 0: | ||
2647 | case 2: | ||
2648 | case 8: | ||
2649 | case 13: | ||
2650 | irq = PARPORT_IRQ_NONE; | ||
2651 | break; | ||
2652 | |||
2653 | default: /* do nothing */ | ||
2654 | break; | ||
2655 | } | ||
2656 | |||
2657 | /* finally, do the probe with values obtained */ | ||
2658 | if (parport_pc_probe_port (port1, port2, irq, dma, NULL)) { | ||
2659 | printk (KERN_INFO | ||
2660 | "parport_pc: VIA parallel port: io=0x%X", port1); | ||
2661 | if (irq != PARPORT_IRQ_NONE) | ||
2662 | printk (", irq=%d", irq); | ||
2663 | if (dma != PARPORT_DMA_NONE) | ||
2664 | printk (", dma=%d", dma); | ||
2665 | printk ("\n"); | ||
2666 | return 1; | ||
2667 | } | ||
2668 | |||
2669 | printk(KERN_WARNING "parport_pc: Strange, can't probe VIA parallel port: io=0x%X, irq=%d, dma=%d\n", | ||
2670 | port1, irq, dma); | ||
2671 | return 0; | ||
2672 | } | ||
2673 | |||
2674 | |||
2675 | enum parport_pc_sio_types { | ||
2676 | sio_via_686a = 0, /* Via VT82C686A motherboard Super I/O */ | ||
2677 | sio_via_8231, /* Via VT8231 south bridge integrated Super IO */ | ||
2678 | sio_ite_8872, | ||
2679 | last_sio | ||
2680 | }; | ||
2681 | |||
2682 | /* each element directly indexed from enum list, above */ | ||
2683 | static struct parport_pc_superio { | ||
2684 | int (*probe) (struct pci_dev *pdev, int autoirq, int autodma, struct parport_pc_via_data *via); | ||
2685 | struct parport_pc_via_data *via; | ||
2686 | } parport_pc_superio_info[] __devinitdata = { | ||
2687 | { sio_via_probe, &via_686a_data, }, | ||
2688 | { sio_via_probe, &via_8231_data, }, | ||
2689 | { sio_ite_8872_probe, NULL, }, | ||
2690 | }; | ||
2691 | |||
2692 | enum parport_pc_pci_cards { | ||
2693 | siig_1p_10x = last_sio, | ||
2694 | siig_2p_10x, | ||
2695 | siig_1p_20x, | ||
2696 | siig_2p_20x, | ||
2697 | lava_parallel, | ||
2698 | lava_parallel_dual_a, | ||
2699 | lava_parallel_dual_b, | ||
2700 | boca_ioppar, | ||
2701 | plx_9050, | ||
2702 | timedia_4078a, | ||
2703 | timedia_4079h, | ||
2704 | timedia_4085h, | ||
2705 | timedia_4088a, | ||
2706 | timedia_4089a, | ||
2707 | timedia_4095a, | ||
2708 | timedia_4096a, | ||
2709 | timedia_4078u, | ||
2710 | timedia_4079a, | ||
2711 | timedia_4085u, | ||
2712 | timedia_4079r, | ||
2713 | timedia_4079s, | ||
2714 | timedia_4079d, | ||
2715 | timedia_4079e, | ||
2716 | timedia_4079f, | ||
2717 | timedia_9079a, | ||
2718 | timedia_9079b, | ||
2719 | timedia_9079c, | ||
2720 | timedia_4006a, | ||
2721 | timedia_4014, | ||
2722 | timedia_4008a, | ||
2723 | timedia_4018, | ||
2724 | timedia_9018a, | ||
2725 | syba_2p_epp, | ||
2726 | syba_1p_ecp, | ||
2727 | titan_010l, | ||
2728 | titan_1284p2, | ||
2729 | avlab_1p, | ||
2730 | avlab_2p, | ||
2731 | oxsemi_954, | ||
2732 | oxsemi_840, | ||
2733 | aks_0100, | ||
2734 | mobility_pp, | ||
2735 | netmos_9705, | ||
2736 | netmos_9715, | ||
2737 | netmos_9755, | ||
2738 | netmos_9805, | ||
2739 | netmos_9815, | ||
2740 | netmos_9855, | ||
2741 | }; | ||
2742 | |||
2743 | |||
2744 | /* each element directly indexed from enum list, above | ||
2745 | * (but offset by last_sio) */ | ||
2746 | static struct parport_pc_pci { | ||
2747 | int numports; | ||
2748 | struct { /* BAR (base address registers) numbers in the config | ||
2749 | space header */ | ||
2750 | int lo; | ||
2751 | int hi; /* -1 if not there, >6 for offset-method (max | ||
2752 | BAR is 6) */ | ||
2753 | } addr[4]; | ||
2754 | |||
2755 | /* If set, this is called immediately after pci_enable_device. | ||
2756 | * If it returns non-zero, no probing will take place and the | ||
2757 | * ports will not be used. */ | ||
2758 | int (*preinit_hook) (struct pci_dev *pdev, int autoirq, int autodma); | ||
2759 | |||
2760 | /* If set, this is called after probing for ports. If 'failed' | ||
2761 | * is non-zero we couldn't use any of the ports. */ | ||
2762 | void (*postinit_hook) (struct pci_dev *pdev, int failed); | ||
2763 | } cards[] __devinitdata = { | ||
2764 | /* siig_1p_10x */ { 1, { { 2, 3 }, } }, | ||
2765 | /* siig_2p_10x */ { 2, { { 2, 3 }, { 4, 5 }, } }, | ||
2766 | /* siig_1p_20x */ { 1, { { 0, 1 }, } }, | ||
2767 | /* siig_2p_20x */ { 2, { { 0, 1 }, { 2, 3 }, } }, | ||
2768 | /* lava_parallel */ { 1, { { 0, -1 }, } }, | ||
2769 | /* lava_parallel_dual_a */ { 1, { { 0, -1 }, } }, | ||
2770 | /* lava_parallel_dual_b */ { 1, { { 0, -1 }, } }, | ||
2771 | /* boca_ioppar */ { 1, { { 0, -1 }, } }, | ||
2772 | /* plx_9050 */ { 2, { { 4, -1 }, { 5, -1 }, } }, | ||
2773 | /* timedia_4078a */ { 1, { { 2, -1 }, } }, | ||
2774 | /* timedia_4079h */ { 1, { { 2, 3 }, } }, | ||
2775 | /* timedia_4085h */ { 2, { { 2, -1 }, { 4, -1 }, } }, | ||
2776 | /* timedia_4088a */ { 2, { { 2, 3 }, { 4, 5 }, } }, | ||
2777 | /* timedia_4089a */ { 2, { { 2, 3 }, { 4, 5 }, } }, | ||
2778 | /* timedia_4095a */ { 2, { { 2, 3 }, { 4, 5 }, } }, | ||
2779 | /* timedia_4096a */ { 2, { { 2, 3 }, { 4, 5 }, } }, | ||
2780 | /* timedia_4078u */ { 1, { { 2, -1 }, } }, | ||
2781 | /* timedia_4079a */ { 1, { { 2, 3 }, } }, | ||
2782 | /* timedia_4085u */ { 2, { { 2, -1 }, { 4, -1 }, } }, | ||
2783 | /* timedia_4079r */ { 1, { { 2, 3 }, } }, | ||
2784 | /* timedia_4079s */ { 1, { { 2, 3 }, } }, | ||
2785 | /* timedia_4079d */ { 1, { { 2, 3 }, } }, | ||
2786 | /* timedia_4079e */ { 1, { { 2, 3 }, } }, | ||
2787 | /* timedia_4079f */ { 1, { { 2, 3 }, } }, | ||
2788 | /* timedia_9079a */ { 1, { { 2, 3 }, } }, | ||
2789 | /* timedia_9079b */ { 1, { { 2, 3 }, } }, | ||
2790 | /* timedia_9079c */ { 1, { { 2, 3 }, } }, | ||
2791 | /* timedia_4006a */ { 1, { { 0, -1 }, } }, | ||
2792 | /* timedia_4014 */ { 2, { { 0, -1 }, { 2, -1 }, } }, | ||
2793 | /* timedia_4008a */ { 1, { { 0, 1 }, } }, | ||
2794 | /* timedia_4018 */ { 2, { { 0, 1 }, { 2, 3 }, } }, | ||
2795 | /* timedia_9018a */ { 2, { { 0, 1 }, { 2, 3 }, } }, | ||
2796 | /* SYBA uses fixed offsets in | ||
2797 | a 1K io window */ | ||
2798 | /* syba_2p_epp AP138B */ { 2, { { 0, 0x078 }, { 0, 0x178 }, } }, | ||
2799 | /* syba_1p_ecp W83787 */ { 1, { { 0, 0x078 }, } }, | ||
2800 | /* titan_010l */ { 1, { { 3, -1 }, } }, | ||
2801 | /* titan_1284p2 */ { 2, { { 0, 1 }, { 2, 3 }, } }, | ||
2802 | /* avlab_1p */ { 1, { { 0, 1}, } }, | ||
2803 | /* avlab_2p */ { 2, { { 0, 1}, { 2, 3 },} }, | ||
2804 | /* The Oxford Semi cards are unusual: 954 doesn't support ECP, | ||
2805 | * and 840 locks up if you write 1 to bit 2! */ | ||
2806 | /* oxsemi_954 */ { 1, { { 0, -1 }, } }, | ||
2807 | /* oxsemi_840 */ { 1, { { 0, -1 }, } }, | ||
2808 | /* aks_0100 */ { 1, { { 0, -1 }, } }, | ||
2809 | /* mobility_pp */ { 1, { { 0, 1 }, } }, | ||
2810 | /* netmos_9705 */ { 1, { { 0, -1 }, } }, /* untested */ | ||
2811 | /* netmos_9715 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | ||
2812 | /* netmos_9755 */ { 2, { { 0, 1 }, { 2, 3 },} }, /* untested */ | ||
2813 | /* netmos_9805 */ { 1, { { 0, -1 }, } }, /* untested */ | ||
2814 | /* netmos_9815 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ | ||
2815 | /* netmos_9855 */ { 2, { { 0, -1 }, { 2, -1 }, } }, /* untested */ | ||
2816 | }; | ||
2817 | |||
2818 | static struct pci_device_id parport_pc_pci_tbl[] = { | ||
2819 | /* Super-IO onboard chips */ | ||
2820 | { 0x1106, 0x0686, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_686a }, | ||
2821 | { 0x1106, 0x8231, PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_via_8231 }, | ||
2822 | { PCI_VENDOR_ID_ITE, PCI_DEVICE_ID_ITE_8872, | ||
2823 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, sio_ite_8872 }, | ||
2824 | |||
2825 | /* PCI cards */ | ||
2826 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_10x, | ||
2827 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_10x }, | ||
2828 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_10x, | ||
2829 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_10x }, | ||
2830 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1P_20x, | ||
2831 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1p_20x }, | ||
2832 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P_20x, | ||
2833 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p_20x }, | ||
2834 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_PARALLEL, | ||
2835 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel }, | ||
2836 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_A, | ||
2837 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_a }, | ||
2838 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_DUAL_PAR_B, | ||
2839 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, lava_parallel_dual_b }, | ||
2840 | { PCI_VENDOR_ID_LAVA, PCI_DEVICE_ID_LAVA_BOCA_IOPPAR, | ||
2841 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, boca_ioppar }, | ||
2842 | { PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050, | ||
2843 | PCI_SUBVENDOR_ID_EXSYS, PCI_SUBDEVICE_ID_EXSYS_4014, 0,0, plx_9050 }, | ||
2844 | /* PCI_VENDOR_ID_TIMEDIA/SUNIX has many differing cards ...*/ | ||
2845 | { 0x1409, 0x7168, 0x1409, 0x4078, 0, 0, timedia_4078a }, | ||
2846 | { 0x1409, 0x7168, 0x1409, 0x4079, 0, 0, timedia_4079h }, | ||
2847 | { 0x1409, 0x7168, 0x1409, 0x4085, 0, 0, timedia_4085h }, | ||
2848 | { 0x1409, 0x7168, 0x1409, 0x4088, 0, 0, timedia_4088a }, | ||
2849 | { 0x1409, 0x7168, 0x1409, 0x4089, 0, 0, timedia_4089a }, | ||
2850 | { 0x1409, 0x7168, 0x1409, 0x4095, 0, 0, timedia_4095a }, | ||
2851 | { 0x1409, 0x7168, 0x1409, 0x4096, 0, 0, timedia_4096a }, | ||
2852 | { 0x1409, 0x7168, 0x1409, 0x5078, 0, 0, timedia_4078u }, | ||
2853 | { 0x1409, 0x7168, 0x1409, 0x5079, 0, 0, timedia_4079a }, | ||
2854 | { 0x1409, 0x7168, 0x1409, 0x5085, 0, 0, timedia_4085u }, | ||
2855 | { 0x1409, 0x7168, 0x1409, 0x6079, 0, 0, timedia_4079r }, | ||
2856 | { 0x1409, 0x7168, 0x1409, 0x7079, 0, 0, timedia_4079s }, | ||
2857 | { 0x1409, 0x7168, 0x1409, 0x8079, 0, 0, timedia_4079d }, | ||
2858 | { 0x1409, 0x7168, 0x1409, 0x9079, 0, 0, timedia_4079e }, | ||
2859 | { 0x1409, 0x7168, 0x1409, 0xa079, 0, 0, timedia_4079f }, | ||
2860 | { 0x1409, 0x7168, 0x1409, 0xb079, 0, 0, timedia_9079a }, | ||
2861 | { 0x1409, 0x7168, 0x1409, 0xc079, 0, 0, timedia_9079b }, | ||
2862 | { 0x1409, 0x7168, 0x1409, 0xd079, 0, 0, timedia_9079c }, | ||
2863 | { 0x1409, 0x7268, 0x1409, 0x0101, 0, 0, timedia_4006a }, | ||
2864 | { 0x1409, 0x7268, 0x1409, 0x0102, 0, 0, timedia_4014 }, | ||
2865 | { 0x1409, 0x7268, 0x1409, 0x0103, 0, 0, timedia_4008a }, | ||
2866 | { 0x1409, 0x7268, 0x1409, 0x0104, 0, 0, timedia_4018 }, | ||
2867 | { 0x1409, 0x7268, 0x1409, 0x9018, 0, 0, timedia_9018a }, | ||
2868 | { 0x14f2, 0x0121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, mobility_pp }, | ||
2869 | { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_2P_EPP, | ||
2870 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_2p_epp }, | ||
2871 | { PCI_VENDOR_ID_SYBA, PCI_DEVICE_ID_SYBA_1P_ECP, | ||
2872 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, syba_1p_ecp }, | ||
2873 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_010L, | ||
2874 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_010l }, | ||
2875 | { 0x9710, 0x9815, 0x1000, 0x0020, 0, 0, titan_1284p2 }, | ||
2876 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ | ||
2877 | { 0x14db, 0x2120, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1p}, /* AFAVLAB_TK9902 */ | ||
2878 | { 0x14db, 0x2121, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2p}, | ||
2879 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_16PCI954PP, | ||
2880 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_954 }, | ||
2881 | { PCI_VENDOR_ID_OXSEMI, PCI_DEVICE_ID_OXSEMI_12PCI840, | ||
2882 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, oxsemi_840 }, | ||
2883 | { PCI_VENDOR_ID_AKS, PCI_DEVICE_ID_AKS_ALADDINCARD, | ||
2884 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, aks_0100 }, | ||
2885 | /* NetMos communication controllers */ | ||
2886 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9705, | ||
2887 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9705 }, | ||
2888 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9715, | ||
2889 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9715 }, | ||
2890 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9755, | ||
2891 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9755 }, | ||
2892 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9805, | ||
2893 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9805 }, | ||
2894 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9815, | ||
2895 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9815 }, | ||
2896 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855, | ||
2897 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9855 }, | ||
2898 | { 0, } /* terminate list */ | ||
2899 | }; | ||
2900 | MODULE_DEVICE_TABLE(pci,parport_pc_pci_tbl); | ||
2901 | |||
2902 | struct pci_parport_data { | ||
2903 | int num; | ||
2904 | struct parport *ports[2]; | ||
2905 | }; | ||
2906 | |||
2907 | static int parport_pc_pci_probe (struct pci_dev *dev, | ||
2908 | const struct pci_device_id *id) | ||
2909 | { | ||
2910 | int err, count, n, i = id->driver_data; | ||
2911 | struct pci_parport_data *data; | ||
2912 | |||
2913 | if (i < last_sio) | ||
2914 | /* This is an onboard Super-IO and has already been probed */ | ||
2915 | return 0; | ||
2916 | |||
2917 | /* This is a PCI card */ | ||
2918 | i -= last_sio; | ||
2919 | count = 0; | ||
2920 | if ((err = pci_enable_device (dev)) != 0) | ||
2921 | return err; | ||
2922 | |||
2923 | data = kmalloc(sizeof(struct pci_parport_data), GFP_KERNEL); | ||
2924 | if (!data) | ||
2925 | return -ENOMEM; | ||
2926 | |||
2927 | if (cards[i].preinit_hook && | ||
2928 | cards[i].preinit_hook (dev, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) { | ||
2929 | kfree(data); | ||
2930 | return -ENODEV; | ||
2931 | } | ||
2932 | |||
2933 | for (n = 0; n < cards[i].numports; n++) { | ||
2934 | int lo = cards[i].addr[n].lo; | ||
2935 | int hi = cards[i].addr[n].hi; | ||
2936 | unsigned long io_lo, io_hi; | ||
2937 | io_lo = pci_resource_start (dev, lo); | ||
2938 | io_hi = 0; | ||
2939 | if ((hi >= 0) && (hi <= 6)) | ||
2940 | io_hi = pci_resource_start (dev, hi); | ||
2941 | else if (hi > 6) | ||
2942 | io_lo += hi; /* Reinterpret the meaning of | ||
2943 | "hi" as an offset (see SYBA | ||
2944 | def.) */ | ||
2945 | /* TODO: test if sharing interrupts works */ | ||
2946 | printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, " | ||
2947 | "I/O at %#lx(%#lx)\n", | ||
2948 | parport_pc_pci_tbl[i + last_sio].vendor, | ||
2949 | parport_pc_pci_tbl[i + last_sio].device, io_lo, io_hi); | ||
2950 | data->ports[count] = | ||
2951 | parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, | ||
2952 | PARPORT_DMA_NONE, dev); | ||
2953 | if (data->ports[count]) | ||
2954 | count++; | ||
2955 | } | ||
2956 | |||
2957 | data->num = count; | ||
2958 | |||
2959 | if (cards[i].postinit_hook) | ||
2960 | cards[i].postinit_hook (dev, count == 0); | ||
2961 | |||
2962 | if (count) { | ||
2963 | pci_set_drvdata(dev, data); | ||
2964 | return 0; | ||
2965 | } | ||
2966 | |||
2967 | kfree(data); | ||
2968 | |||
2969 | return -ENODEV; | ||
2970 | } | ||
2971 | |||
2972 | static void __devexit parport_pc_pci_remove(struct pci_dev *dev) | ||
2973 | { | ||
2974 | struct pci_parport_data *data = pci_get_drvdata(dev); | ||
2975 | int i; | ||
2976 | |||
2977 | pci_set_drvdata(dev, NULL); | ||
2978 | |||
2979 | if (data) { | ||
2980 | for (i = data->num - 1; i >= 0; i--) | ||
2981 | parport_pc_unregister_port(data->ports[i]); | ||
2982 | |||
2983 | kfree(data); | ||
2984 | } | ||
2985 | } | ||
2986 | |||
2987 | static struct pci_driver parport_pc_pci_driver = { | ||
2988 | .name = "parport_pc", | ||
2989 | .id_table = parport_pc_pci_tbl, | ||
2990 | .probe = parport_pc_pci_probe, | ||
2991 | .remove = __devexit_p(parport_pc_pci_remove), | ||
2992 | }; | ||
2993 | |||
2994 | static int __init parport_pc_init_superio (int autoirq, int autodma) | ||
2995 | { | ||
2996 | const struct pci_device_id *id; | ||
2997 | struct pci_dev *pdev = NULL; | ||
2998 | int ret = 0; | ||
2999 | |||
3000 | while ((pdev = pci_find_device(PCI_ANY_ID, PCI_ANY_ID, pdev)) != NULL) { | ||
3001 | id = pci_match_device (parport_pc_pci_tbl, pdev); | ||
3002 | if (id == NULL || id->driver_data >= last_sio) | ||
3003 | continue; | ||
3004 | |||
3005 | if (parport_pc_superio_info[id->driver_data].probe | ||
3006 | (pdev, autoirq, autodma,parport_pc_superio_info[id->driver_data].via)) { | ||
3007 | ret++; | ||
3008 | } | ||
3009 | } | ||
3010 | |||
3011 | return ret; /* number of devices found */ | ||
3012 | } | ||
3013 | #else | ||
3014 | static struct pci_driver parport_pc_pci_driver; | ||
3015 | static int __init parport_pc_init_superio(int autoirq, int autodma) {return 0;} | ||
3016 | #endif /* CONFIG_PCI */ | ||
3017 | |||
3018 | |||
3019 | static const struct pnp_device_id parport_pc_pnp_tbl[] = { | ||
3020 | /* Standard LPT Printer Port */ | ||
3021 | {.id = "PNP0400", .driver_data = 0}, | ||
3022 | /* ECP Printer Port */ | ||
3023 | {.id = "PNP0401", .driver_data = 0}, | ||
3024 | { } | ||
3025 | }; | ||
3026 | |||
3027 | MODULE_DEVICE_TABLE(pnp,parport_pc_pnp_tbl); | ||
3028 | |||
3029 | static int parport_pc_pnp_probe(struct pnp_dev *dev, const struct pnp_device_id *id) | ||
3030 | { | ||
3031 | struct parport *pdata; | ||
3032 | unsigned long io_lo, io_hi; | ||
3033 | int dma, irq; | ||
3034 | |||
3035 | if (pnp_port_valid(dev,0) && | ||
3036 | !(pnp_port_flags(dev,0) & IORESOURCE_DISABLED)) { | ||
3037 | io_lo = pnp_port_start(dev,0); | ||
3038 | } else | ||
3039 | return -EINVAL; | ||
3040 | |||
3041 | if (pnp_port_valid(dev,1) && | ||
3042 | !(pnp_port_flags(dev,1) & IORESOURCE_DISABLED)) { | ||
3043 | io_hi = pnp_port_start(dev,1); | ||
3044 | } else | ||
3045 | io_hi = 0; | ||
3046 | |||
3047 | if (pnp_irq_valid(dev,0) && | ||
3048 | !(pnp_irq_flags(dev,0) & IORESOURCE_DISABLED)) { | ||
3049 | irq = pnp_irq(dev,0); | ||
3050 | } else | ||
3051 | irq = PARPORT_IRQ_NONE; | ||
3052 | |||
3053 | if (pnp_dma_valid(dev,0) && | ||
3054 | !(pnp_dma_flags(dev,0) & IORESOURCE_DISABLED)) { | ||
3055 | dma = pnp_dma(dev,0); | ||
3056 | } else | ||
3057 | dma = PARPORT_DMA_NONE; | ||
3058 | |||
3059 | printk(KERN_INFO "parport: PnPBIOS parport detected.\n"); | ||
3060 | if (!(pdata = parport_pc_probe_port (io_lo, io_hi, irq, dma, NULL))) | ||
3061 | return -ENODEV; | ||
3062 | |||
3063 | pnp_set_drvdata(dev,pdata); | ||
3064 | return 0; | ||
3065 | } | ||
3066 | |||
3067 | static void parport_pc_pnp_remove(struct pnp_dev *dev) | ||
3068 | { | ||
3069 | struct parport *pdata = (struct parport *)pnp_get_drvdata(dev); | ||
3070 | if (!pdata) | ||
3071 | return; | ||
3072 | |||
3073 | parport_pc_unregister_port(pdata); | ||
3074 | } | ||
3075 | |||
3076 | /* we only need the pnp layer to activate the device, at least for now */ | ||
3077 | static struct pnp_driver parport_pc_pnp_driver = { | ||
3078 | .name = "parport_pc", | ||
3079 | .id_table = parport_pc_pnp_tbl, | ||
3080 | .probe = parport_pc_pnp_probe, | ||
3081 | .remove = parport_pc_pnp_remove, | ||
3082 | }; | ||
3083 | |||
3084 | |||
3085 | /* This is called by parport_pc_find_nonpci_ports (in asm/parport.h) */ | ||
3086 | static int __devinit __attribute__((unused)) | ||
3087 | parport_pc_find_isa_ports (int autoirq, int autodma) | ||
3088 | { | ||
3089 | int count = 0; | ||
3090 | |||
3091 | if (parport_pc_probe_port(0x3bc, 0x7bc, autoirq, autodma, NULL)) | ||
3092 | count++; | ||
3093 | if (parport_pc_probe_port(0x378, 0x778, autoirq, autodma, NULL)) | ||
3094 | count++; | ||
3095 | if (parport_pc_probe_port(0x278, 0x678, autoirq, autodma, NULL)) | ||
3096 | count++; | ||
3097 | |||
3098 | return count; | ||
3099 | } | ||
3100 | |||
3101 | /* This function is called by parport_pc_init if the user didn't | ||
3102 | * specify any ports to probe. Its job is to find some ports. Order | ||
3103 | * is important here -- we want ISA ports to be registered first, | ||
3104 | * followed by PCI cards (for least surprise), but before that we want | ||
3105 | * to do chipset-specific tests for some onboard ports that we know | ||
3106 | * about. | ||
3107 | * | ||
3108 | * autoirq is PARPORT_IRQ_NONE, PARPORT_IRQ_AUTO, or PARPORT_IRQ_PROBEONLY | ||
3109 | * autodma is PARPORT_DMA_NONE or PARPORT_DMA_AUTO | ||
3110 | */ | ||
3111 | static int __init parport_pc_find_ports (int autoirq, int autodma) | ||
3112 | { | ||
3113 | int count = 0, r; | ||
3114 | |||
3115 | #ifdef CONFIG_PARPORT_PC_SUPERIO | ||
3116 | detect_and_report_winbond (); | ||
3117 | detect_and_report_smsc (); | ||
3118 | #endif | ||
3119 | |||
3120 | /* Onboard SuperIO chipsets that show themselves on the PCI bus. */ | ||
3121 | count += parport_pc_init_superio (autoirq, autodma); | ||
3122 | |||
3123 | /* PnP ports, skip detection if SuperIO already found them */ | ||
3124 | if (!count) { | ||
3125 | r = pnp_register_driver (&parport_pc_pnp_driver); | ||
3126 | if (r >= 0) { | ||
3127 | pnp_registered_parport = 1; | ||
3128 | count += r; | ||
3129 | } | ||
3130 | } | ||
3131 | |||
3132 | /* ISA ports and whatever (see asm/parport.h). */ | ||
3133 | count += parport_pc_find_nonpci_ports (autoirq, autodma); | ||
3134 | |||
3135 | r = pci_register_driver (&parport_pc_pci_driver); | ||
3136 | if (r) | ||
3137 | return r; | ||
3138 | pci_registered_parport = 1; | ||
3139 | count += 1; | ||
3140 | |||
3141 | return count; | ||
3142 | } | ||
3143 | |||
3144 | /* | ||
3145 | * Piles of crap below pretend to be a parser for module and kernel | ||
3146 | * parameters. Say "thank you" to whoever had come up with that | ||
3147 | * syntax and keep in mind that code below is a cleaned up version. | ||
3148 | */ | ||
3149 | |||
3150 | static int __initdata io[PARPORT_PC_MAX_PORTS+1] = { [0 ... PARPORT_PC_MAX_PORTS] = 0 }; | ||
3151 | static int __initdata io_hi[PARPORT_PC_MAX_PORTS+1] = | ||
3152 | { [0 ... PARPORT_PC_MAX_PORTS] = PARPORT_IOHI_AUTO }; | ||
3153 | static int __initdata dmaval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_DMA_NONE }; | ||
3154 | static int __initdata irqval[PARPORT_PC_MAX_PORTS] = { [0 ... PARPORT_PC_MAX_PORTS-1] = PARPORT_IRQ_PROBEONLY }; | ||
3155 | |||
3156 | static int __init parport_parse_param(const char *s, int *val, | ||
3157 | int automatic, int none, int nofifo) | ||
3158 | { | ||
3159 | if (!s) | ||
3160 | return 0; | ||
3161 | if (!strncmp(s, "auto", 4)) | ||
3162 | *val = automatic; | ||
3163 | else if (!strncmp(s, "none", 4)) | ||
3164 | *val = none; | ||
3165 | else if (nofifo && !strncmp(s, "nofifo", 4)) | ||
3166 | *val = nofifo; | ||
3167 | else { | ||
3168 | char *ep; | ||
3169 | unsigned long r = simple_strtoul(s, &ep, 0); | ||
3170 | if (ep != s) | ||
3171 | *val = r; | ||
3172 | else { | ||
3173 | printk(KERN_ERR "parport: bad specifier `%s'\n", s); | ||
3174 | return -1; | ||
3175 | } | ||
3176 | } | ||
3177 | return 0; | ||
3178 | } | ||
3179 | |||
3180 | static int __init parport_parse_irq(const char *irqstr, int *val) | ||
3181 | { | ||
3182 | return parport_parse_param(irqstr, val, PARPORT_IRQ_AUTO, | ||
3183 | PARPORT_IRQ_NONE, 0); | ||
3184 | } | ||
3185 | |||
3186 | static int __init parport_parse_dma(const char *dmastr, int *val) | ||
3187 | { | ||
3188 | return parport_parse_param(dmastr, val, PARPORT_DMA_AUTO, | ||
3189 | PARPORT_DMA_NONE, PARPORT_DMA_NOFIFO); | ||
3190 | } | ||
3191 | |||
3192 | #ifdef CONFIG_PCI | ||
3193 | static int __init parport_init_mode_setup(char *str) | ||
3194 | { | ||
3195 | printk(KERN_DEBUG "parport_pc.c: Specified parameter parport_init_mode=%s\n", str); | ||
3196 | |||
3197 | if (!strcmp (str, "spp")) | ||
3198 | parport_init_mode=1; | ||
3199 | if (!strcmp (str, "ps2")) | ||
3200 | parport_init_mode=2; | ||
3201 | if (!strcmp (str, "epp")) | ||
3202 | parport_init_mode=3; | ||
3203 | if (!strcmp (str, "ecp")) | ||
3204 | parport_init_mode=4; | ||
3205 | if (!strcmp (str, "ecpepp")) | ||
3206 | parport_init_mode=5; | ||
3207 | return 1; | ||
3208 | } | ||
3209 | #endif | ||
3210 | |||
3211 | #ifdef MODULE | ||
3212 | static const char *irq[PARPORT_PC_MAX_PORTS]; | ||
3213 | static const char *dma[PARPORT_PC_MAX_PORTS]; | ||
3214 | |||
3215 | MODULE_PARM_DESC(io, "Base I/O address (SPP regs)"); | ||
3216 | module_param_array(io, int, NULL, 0); | ||
3217 | MODULE_PARM_DESC(io_hi, "Base I/O address (ECR)"); | ||
3218 | module_param_array(io_hi, int, NULL, 0); | ||
3219 | MODULE_PARM_DESC(irq, "IRQ line"); | ||
3220 | module_param_array(irq, charp, NULL, 0); | ||
3221 | MODULE_PARM_DESC(dma, "DMA channel"); | ||
3222 | module_param_array(dma, charp, NULL, 0); | ||
3223 | #if defined(CONFIG_PARPORT_PC_SUPERIO) || \ | ||
3224 | (defined(CONFIG_PARPORT_1284) && defined(CONFIG_PARPORT_PC_FIFO)) | ||
3225 | MODULE_PARM_DESC(verbose_probing, "Log chit-chat during initialisation"); | ||
3226 | module_param(verbose_probing, int, 0644); | ||
3227 | #endif | ||
3228 | #ifdef CONFIG_PCI | ||
3229 | static char *init_mode; | ||
3230 | MODULE_PARM_DESC(init_mode, "Initialise mode for VIA VT8231 port (spp, ps2, epp, ecp or ecpepp)"); | ||
3231 | module_param(init_mode, charp, 0); | ||
3232 | #endif | ||
3233 | |||
3234 | static int __init parse_parport_params(void) | ||
3235 | { | ||
3236 | unsigned int i; | ||
3237 | int val; | ||
3238 | |||
3239 | #ifdef CONFIG_PCI | ||
3240 | if (init_mode) | ||
3241 | parport_init_mode_setup(init_mode); | ||
3242 | #endif | ||
3243 | |||
3244 | for (i = 0; i < PARPORT_PC_MAX_PORTS && io[i]; i++) { | ||
3245 | if (parport_parse_irq(irq[i], &val)) | ||
3246 | return 1; | ||
3247 | irqval[i] = val; | ||
3248 | if (parport_parse_dma(dma[i], &val)) | ||
3249 | return 1; | ||
3250 | dmaval[i] = val; | ||
3251 | } | ||
3252 | if (!io[0]) { | ||
3253 | /* The user can make us use any IRQs or DMAs we find. */ | ||
3254 | if (irq[0] && !parport_parse_irq(irq[0], &val)) | ||
3255 | switch (val) { | ||
3256 | case PARPORT_IRQ_NONE: | ||
3257 | case PARPORT_IRQ_AUTO: | ||
3258 | irqval[0] = val; | ||
3259 | break; | ||
3260 | default: | ||
3261 | printk (KERN_WARNING | ||
3262 | "parport_pc: irq specified " | ||
3263 | "without base address. Use 'io=' " | ||
3264 | "to specify one\n"); | ||
3265 | } | ||
3266 | |||
3267 | if (dma[0] && !parport_parse_dma(dma[0], &val)) | ||
3268 | switch (val) { | ||
3269 | case PARPORT_DMA_NONE: | ||
3270 | case PARPORT_DMA_AUTO: | ||
3271 | dmaval[0] = val; | ||
3272 | break; | ||
3273 | default: | ||
3274 | printk (KERN_WARNING | ||
3275 | "parport_pc: dma specified " | ||
3276 | "without base address. Use 'io=' " | ||
3277 | "to specify one\n"); | ||
3278 | } | ||
3279 | } | ||
3280 | return 0; | ||
3281 | } | ||
3282 | |||
3283 | #else | ||
3284 | |||
3285 | static int parport_setup_ptr __initdata = 0; | ||
3286 | |||
3287 | /* | ||
3288 | * Acceptable parameters: | ||
3289 | * | ||
3290 | * parport=0 | ||
3291 | * parport=auto | ||
3292 | * parport=0xBASE[,IRQ[,DMA]] | ||
3293 | * | ||
3294 | * IRQ/DMA may be numeric or 'auto' or 'none' | ||
3295 | */ | ||
3296 | static int __init parport_setup (char *str) | ||
3297 | { | ||
3298 | char *endptr; | ||
3299 | char *sep; | ||
3300 | int val; | ||
3301 | |||
3302 | if (!str || !*str || (*str == '0' && !*(str+1))) { | ||
3303 | /* Disable parport if "parport=0" in cmdline */ | ||
3304 | io[0] = PARPORT_DISABLE; | ||
3305 | return 1; | ||
3306 | } | ||
3307 | |||
3308 | if (!strncmp (str, "auto", 4)) { | ||
3309 | irqval[0] = PARPORT_IRQ_AUTO; | ||
3310 | dmaval[0] = PARPORT_DMA_AUTO; | ||
3311 | return 1; | ||
3312 | } | ||
3313 | |||
3314 | val = simple_strtoul (str, &endptr, 0); | ||
3315 | if (endptr == str) { | ||
3316 | printk (KERN_WARNING "parport=%s not understood\n", str); | ||
3317 | return 1; | ||
3318 | } | ||
3319 | |||
3320 | if (parport_setup_ptr == PARPORT_PC_MAX_PORTS) { | ||
3321 | printk(KERN_ERR "parport=%s ignored, too many ports\n", str); | ||
3322 | return 1; | ||
3323 | } | ||
3324 | |||
3325 | io[parport_setup_ptr] = val; | ||
3326 | irqval[parport_setup_ptr] = PARPORT_IRQ_NONE; | ||
3327 | dmaval[parport_setup_ptr] = PARPORT_DMA_NONE; | ||
3328 | |||
3329 | sep = strchr(str, ','); | ||
3330 | if (sep++) { | ||
3331 | if (parport_parse_irq(sep, &val)) | ||
3332 | return 1; | ||
3333 | irqval[parport_setup_ptr] = val; | ||
3334 | sep = strchr(sep, ','); | ||
3335 | if (sep++) { | ||
3336 | if (parport_parse_dma(sep, &val)) | ||
3337 | return 1; | ||
3338 | dmaval[parport_setup_ptr] = val; | ||
3339 | } | ||
3340 | } | ||
3341 | parport_setup_ptr++; | ||
3342 | return 1; | ||
3343 | } | ||
3344 | |||
3345 | static int __init parse_parport_params(void) | ||
3346 | { | ||
3347 | return io[0] == PARPORT_DISABLE; | ||
3348 | } | ||
3349 | |||
3350 | __setup ("parport=", parport_setup); | ||
3351 | |||
3352 | /* | ||
3353 | * Acceptable parameters: | ||
3354 | * | ||
3355 | * parport_init_mode=[spp|ps2|epp|ecp|ecpepp] | ||
3356 | */ | ||
3357 | #ifdef CONFIG_PCI | ||
3358 | __setup("parport_init_mode=",parport_init_mode_setup); | ||
3359 | #endif | ||
3360 | #endif | ||
3361 | |||
3362 | /* "Parser" ends here */ | ||
3363 | |||
3364 | static int __init parport_pc_init(void) | ||
3365 | { | ||
3366 | int count = 0; | ||
3367 | |||
3368 | if (parse_parport_params()) | ||
3369 | return -EINVAL; | ||
3370 | |||
3371 | if (io[0]) { | ||
3372 | int i; | ||
3373 | /* Only probe the ports we were given. */ | ||
3374 | user_specified = 1; | ||
3375 | for (i = 0; i < PARPORT_PC_MAX_PORTS; i++) { | ||
3376 | if (!io[i]) | ||
3377 | break; | ||
3378 | if ((io_hi[i]) == PARPORT_IOHI_AUTO) | ||
3379 | io_hi[i] = 0x400 + io[i]; | ||
3380 | if (parport_pc_probe_port(io[i], io_hi[i], | ||
3381 | irqval[i], dmaval[i], NULL)) | ||
3382 | count++; | ||
3383 | } | ||
3384 | } else | ||
3385 | count += parport_pc_find_ports (irqval[0], dmaval[0]); | ||
3386 | |||
3387 | return 0; | ||
3388 | } | ||
3389 | |||
3390 | static void __exit parport_pc_exit(void) | ||
3391 | { | ||
3392 | if (pci_registered_parport) | ||
3393 | pci_unregister_driver (&parport_pc_pci_driver); | ||
3394 | if (pnp_registered_parport) | ||
3395 | pnp_unregister_driver (&parport_pc_pnp_driver); | ||
3396 | |||
3397 | spin_lock(&ports_lock); | ||
3398 | while (!list_empty(&ports_list)) { | ||
3399 | struct parport_pc_private *priv; | ||
3400 | struct parport *port; | ||
3401 | priv = list_entry(ports_list.next, | ||
3402 | struct parport_pc_private, list); | ||
3403 | port = priv->port; | ||
3404 | spin_unlock(&ports_lock); | ||
3405 | parport_pc_unregister_port(port); | ||
3406 | spin_lock(&ports_lock); | ||
3407 | } | ||
3408 | spin_unlock(&ports_lock); | ||
3409 | } | ||
3410 | |||
3411 | MODULE_AUTHOR("Phil Blundell, Tim Waugh, others"); | ||
3412 | MODULE_DESCRIPTION("PC-style parallel port driver"); | ||
3413 | MODULE_LICENSE("GPL"); | ||
3414 | module_init(parport_pc_init) | ||
3415 | module_exit(parport_pc_exit) | ||
diff --git a/drivers/parport/parport_serial.c b/drivers/parport/parport_serial.c new file mode 100644 index 000000000000..6715a17b5d0f --- /dev/null +++ b/drivers/parport/parport_serial.c | |||
@@ -0,0 +1,485 @@ | |||
1 | /* | ||
2 | * Support for common PCI multi-I/O cards (which is most of them) | ||
3 | * | ||
4 | * Copyright (C) 2001 Tim Waugh <twaugh@redhat.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | * | ||
11 | * | ||
12 | * Multi-function PCI cards are supposed to present separate logical | ||
13 | * devices on the bus. A common thing to do seems to be to just use | ||
14 | * one logical device with lots of base address registers for both | ||
15 | * parallel ports and serial ports. This driver is for dealing with | ||
16 | * that. | ||
17 | * | ||
18 | */ | ||
19 | |||
20 | #include <linux/types.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/init.h> | ||
23 | #include <linux/pci.h> | ||
24 | #include <linux/parport.h> | ||
25 | #include <linux/parport_pc.h> | ||
26 | #include <linux/serial.h> | ||
27 | #include <linux/serialP.h> | ||
28 | #include <linux/list.h> | ||
29 | #include <linux/8250_pci.h> | ||
30 | |||
31 | #include <asm/serial.h> | ||
32 | |||
33 | enum parport_pc_pci_cards { | ||
34 | titan_110l = 0, | ||
35 | titan_210l, | ||
36 | netmos_9xx5_combo, | ||
37 | avlab_1s1p, | ||
38 | avlab_1s1p_650, | ||
39 | avlab_1s1p_850, | ||
40 | avlab_1s2p, | ||
41 | avlab_1s2p_650, | ||
42 | avlab_1s2p_850, | ||
43 | avlab_2s1p, | ||
44 | avlab_2s1p_650, | ||
45 | avlab_2s1p_850, | ||
46 | siig_1s1p_10x, | ||
47 | siig_2s1p_10x, | ||
48 | siig_2p1s_20x, | ||
49 | siig_1s1p_20x, | ||
50 | siig_2s1p_20x, | ||
51 | }; | ||
52 | |||
53 | /* each element directly indexed from enum list, above */ | ||
54 | struct parport_pc_pci { | ||
55 | int numports; | ||
56 | struct { /* BAR (base address registers) numbers in the config | ||
57 | space header */ | ||
58 | int lo; | ||
59 | int hi; /* -1 if not there, >6 for offset-method (max | ||
60 | BAR is 6) */ | ||
61 | } addr[4]; | ||
62 | |||
63 | /* If set, this is called immediately after pci_enable_device. | ||
64 | * If it returns non-zero, no probing will take place and the | ||
65 | * ports will not be used. */ | ||
66 | int (*preinit_hook) (struct pci_dev *pdev, struct parport_pc_pci *card, | ||
67 | int autoirq, int autodma); | ||
68 | |||
69 | /* If set, this is called after probing for ports. If 'failed' | ||
70 | * is non-zero we couldn't use any of the ports. */ | ||
71 | void (*postinit_hook) (struct pci_dev *pdev, | ||
72 | struct parport_pc_pci *card, int failed); | ||
73 | }; | ||
74 | |||
75 | static int __devinit netmos_parallel_init(struct pci_dev *dev, struct parport_pc_pci *card, int autoirq, int autodma) | ||
76 | { | ||
77 | /* | ||
78 | * Netmos uses the subdevice ID to indicate the number of parallel | ||
79 | * and serial ports. The form is 0x00PS, where <P> is the number of | ||
80 | * parallel ports and <S> is the number of serial ports. | ||
81 | */ | ||
82 | card->numports = (dev->subsystem_device & 0xf0) >> 4; | ||
83 | return 0; | ||
84 | } | ||
85 | |||
86 | static struct parport_pc_pci cards[] __devinitdata = { | ||
87 | /* titan_110l */ { 1, { { 3, -1 }, } }, | ||
88 | /* titan_210l */ { 1, { { 3, -1 }, } }, | ||
89 | /* netmos_9xx5_combo */ { 1, { { 2, -1 }, }, netmos_parallel_init }, | ||
90 | /* avlab_1s1p */ { 1, { { 1, 2}, } }, | ||
91 | /* avlab_1s1p_650 */ { 1, { { 1, 2}, } }, | ||
92 | /* avlab_1s1p_850 */ { 1, { { 1, 2}, } }, | ||
93 | /* avlab_1s2p */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
94 | /* avlab_1s2p_650 */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
95 | /* avlab_1s2p_850 */ { 2, { { 1, 2}, { 3, 4 },} }, | ||
96 | /* avlab_2s1p */ { 1, { { 2, 3}, } }, | ||
97 | /* avlab_2s1p_650 */ { 1, { { 2, 3}, } }, | ||
98 | /* avlab_2s1p_850 */ { 1, { { 2, 3}, } }, | ||
99 | /* siig_1s1p_10x */ { 1, { { 3, 4 }, } }, | ||
100 | /* siig_2s1p_10x */ { 1, { { 4, 5 }, } }, | ||
101 | /* siig_2p1s_20x */ { 2, { { 1, 2 }, { 3, 4 }, } }, | ||
102 | /* siig_1s1p_20x */ { 1, { { 1, 2 }, } }, | ||
103 | /* siig_2s1p_20x */ { 1, { { 2, 3 }, } }, | ||
104 | }; | ||
105 | |||
106 | static struct pci_device_id parport_serial_pci_tbl[] = { | ||
107 | /* PCI cards */ | ||
108 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_110L, | ||
109 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_110l }, | ||
110 | { PCI_VENDOR_ID_TITAN, PCI_DEVICE_ID_TITAN_210L, | ||
111 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, titan_210l }, | ||
112 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9735, | ||
113 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
114 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9745, | ||
115 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
116 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, | ||
117 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
118 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9835, | ||
119 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
120 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9845, | ||
121 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
122 | { PCI_VENDOR_ID_NETMOS, PCI_DEVICE_ID_NETMOS_9855, | ||
123 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, netmos_9xx5_combo }, | ||
124 | /* PCI_VENDOR_ID_AVLAB/Intek21 has another bunch of cards ...*/ | ||
125 | { 0x14db, 0x2110, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p}, | ||
126 | { 0x14db, 0x2111, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_650}, | ||
127 | { 0x14db, 0x2112, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s1p_850}, | ||
128 | { 0x14db, 0x2140, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p}, | ||
129 | { 0x14db, 0x2141, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_650}, | ||
130 | { 0x14db, 0x2142, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_1s2p_850}, | ||
131 | { 0x14db, 0x2160, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p}, | ||
132 | { 0x14db, 0x2161, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_650}, | ||
133 | { 0x14db, 0x2162, PCI_ANY_ID, PCI_ANY_ID, 0, 0, avlab_2s1p_850}, | ||
134 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_550, | ||
135 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
136 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_650, | ||
137 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
138 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_10x_850, | ||
139 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_10x }, | ||
140 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_550, | ||
141 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
142 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_650, | ||
143 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
144 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_10x_850, | ||
145 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_10x }, | ||
146 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_550, | ||
147 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
148 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_650, | ||
149 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
150 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2P1S_20x_850, | ||
151 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2p1s_20x }, | ||
152 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_550, | ||
153 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
154 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_650, | ||
155 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, | ||
156 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_1S1P_20x_850, | ||
157 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_1s1p_20x }, | ||
158 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_550, | ||
159 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
160 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_650, | ||
161 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
162 | { PCI_VENDOR_ID_SIIG, PCI_DEVICE_ID_SIIG_2S1P_20x_850, | ||
163 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, siig_2s1p_20x }, | ||
164 | |||
165 | { 0, } /* terminate list */ | ||
166 | }; | ||
167 | MODULE_DEVICE_TABLE(pci,parport_serial_pci_tbl); | ||
168 | |||
169 | struct pci_board_no_ids { | ||
170 | int flags; | ||
171 | int num_ports; | ||
172 | int base_baud; | ||
173 | int uart_offset; | ||
174 | int reg_shift; | ||
175 | int (*init_fn)(struct pci_dev *dev, struct pci_board_no_ids *board, | ||
176 | int enable); | ||
177 | int first_uart_offset; | ||
178 | }; | ||
179 | |||
180 | static int __devinit siig10x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
181 | { | ||
182 | return pci_siig10x_fn(dev, enable); | ||
183 | } | ||
184 | |||
185 | static int __devinit siig20x_init_fn(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
186 | { | ||
187 | return pci_siig20x_fn(dev, enable); | ||
188 | } | ||
189 | |||
190 | static int __devinit netmos_serial_init(struct pci_dev *dev, struct pci_board_no_ids *board, int enable) | ||
191 | { | ||
192 | board->num_ports = dev->subsystem_device & 0xf; | ||
193 | return 0; | ||
194 | } | ||
195 | |||
196 | static struct pci_board_no_ids pci_boards[] __devinitdata = { | ||
197 | /* | ||
198 | * PCI Flags, Number of Ports, Base (Maximum) Baud Rate, | ||
199 | * Offset to get to next UART's registers, | ||
200 | * Register shift to use for memory-mapped I/O, | ||
201 | * Initialization function, first UART offset | ||
202 | */ | ||
203 | |||
204 | // Cards not tested are marked n/t | ||
205 | // If you have one of these cards and it works for you, please tell me.. | ||
206 | |||
207 | /* titan_110l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 1, 921600 }, | ||
208 | /* titan_210l */ { SPCI_FL_BASE1 | SPCI_FL_BASE_TABLE, 2, 921600 }, | ||
209 | /* netmos_9xx5_combo */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200, 0, 0, netmos_serial_init }, | ||
210 | /* avlab_1s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
211 | /* avlab_1s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
212 | /* avlab_1s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
213 | /* avlab_1s2p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
214 | /* avlab_1s2p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
215 | /* avlab_1s2p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 1, 115200 }, | ||
216 | /* avlab_2s1p (n/t) */ { SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
217 | /* avlab_2s1p_650 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
218 | /* avlab_2s1p_850 (nt)*/{ SPCI_FL_BASE0 | SPCI_FL_BASE_TABLE, 2, 115200 }, | ||
219 | /* siig_1s1p_10x */ { SPCI_FL_BASE2, 1, 460800, 0, 0, siig10x_init_fn }, | ||
220 | /* siig_2s1p_10x */ { SPCI_FL_BASE2, 1, 921600, 0, 0, siig10x_init_fn }, | ||
221 | /* siig_2p1s_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
222 | /* siig_1s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
223 | /* siig_2s1p_20x */ { SPCI_FL_BASE0, 1, 921600, 0, 0, siig20x_init_fn }, | ||
224 | }; | ||
225 | |||
226 | struct parport_serial_private { | ||
227 | int num_ser; | ||
228 | int line[20]; | ||
229 | struct pci_board_no_ids ser; | ||
230 | int num_par; | ||
231 | struct parport *port[PARPORT_MAX]; | ||
232 | struct parport_pc_pci par; | ||
233 | }; | ||
234 | |||
235 | static int __devinit get_pci_port (struct pci_dev *dev, | ||
236 | struct pci_board_no_ids *board, | ||
237 | struct serial_struct *req, | ||
238 | int idx) | ||
239 | { | ||
240 | unsigned long port; | ||
241 | int base_idx; | ||
242 | int max_port; | ||
243 | int offset; | ||
244 | |||
245 | base_idx = SPCI_FL_GET_BASE(board->flags); | ||
246 | if (board->flags & SPCI_FL_BASE_TABLE) | ||
247 | base_idx += idx; | ||
248 | |||
249 | if (board->flags & SPCI_FL_REGION_SZ_CAP) { | ||
250 | max_port = pci_resource_len(dev, base_idx) / 8; | ||
251 | if (idx >= max_port) | ||
252 | return 1; | ||
253 | } | ||
254 | |||
255 | offset = board->first_uart_offset; | ||
256 | |||
257 | /* Timedia/SUNIX uses a mixture of BARs and offsets */ | ||
258 | /* Ugh, this is ugly as all hell --- TYT */ | ||
259 | if(dev->vendor == PCI_VENDOR_ID_TIMEDIA ) /* 0x1409 */ | ||
260 | switch(idx) { | ||
261 | case 0: base_idx=0; | ||
262 | break; | ||
263 | case 1: base_idx=0; offset=8; | ||
264 | break; | ||
265 | case 2: base_idx=1; | ||
266 | break; | ||
267 | case 3: base_idx=1; offset=8; | ||
268 | break; | ||
269 | case 4: /* BAR 2*/ | ||
270 | case 5: /* BAR 3 */ | ||
271 | case 6: /* BAR 4*/ | ||
272 | case 7: base_idx=idx-2; /* BAR 5*/ | ||
273 | } | ||
274 | |||
275 | port = pci_resource_start(dev, base_idx) + offset; | ||
276 | |||
277 | if ((board->flags & SPCI_FL_BASE_TABLE) == 0) | ||
278 | port += idx * (board->uart_offset ? board->uart_offset : 8); | ||
279 | |||
280 | if (pci_resource_flags (dev, base_idx) & IORESOURCE_IO) { | ||
281 | int high_bits_offset = ((sizeof(long)-sizeof(int))*8); | ||
282 | req->port = port; | ||
283 | if (high_bits_offset) | ||
284 | req->port_high = port >> high_bits_offset; | ||
285 | else | ||
286 | req->port_high = 0; | ||
287 | return 0; | ||
288 | } | ||
289 | req->io_type = SERIAL_IO_MEM; | ||
290 | req->iomem_base = ioremap(port, board->uart_offset); | ||
291 | req->iomem_reg_shift = board->reg_shift; | ||
292 | req->port = 0; | ||
293 | return req->iomem_base ? 0 : 1; | ||
294 | } | ||
295 | |||
296 | /* Register the serial port(s) of a PCI card. */ | ||
297 | static int __devinit serial_register (struct pci_dev *dev, | ||
298 | const struct pci_device_id *id) | ||
299 | { | ||
300 | struct pci_board_no_ids *board; | ||
301 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
302 | struct serial_struct serial_req; | ||
303 | int base_baud; | ||
304 | int k; | ||
305 | int success = 0; | ||
306 | |||
307 | priv->ser = pci_boards[id->driver_data]; | ||
308 | board = &priv->ser; | ||
309 | if (board->init_fn && ((board->init_fn) (dev, board, 1) != 0)) | ||
310 | return 1; | ||
311 | |||
312 | base_baud = board->base_baud; | ||
313 | if (!base_baud) | ||
314 | base_baud = BASE_BAUD; | ||
315 | memset (&serial_req, 0, sizeof (serial_req)); | ||
316 | |||
317 | for (k = 0; k < board->num_ports; k++) { | ||
318 | int line; | ||
319 | |||
320 | if (priv->num_ser == ARRAY_SIZE (priv->line)) { | ||
321 | printk (KERN_WARNING | ||
322 | "parport_serial: %s: only %u serial lines " | ||
323 | "supported (%d reported)\n", pci_name (dev), | ||
324 | ARRAY_SIZE (priv->line), board->num_ports); | ||
325 | break; | ||
326 | } | ||
327 | |||
328 | serial_req.irq = dev->irq; | ||
329 | if (get_pci_port (dev, board, &serial_req, k)) | ||
330 | break; | ||
331 | serial_req.flags = ASYNC_SKIP_TEST | ASYNC_AUTOPROBE; | ||
332 | serial_req.baud_base = base_baud; | ||
333 | line = register_serial (&serial_req); | ||
334 | if (line < 0) { | ||
335 | printk (KERN_DEBUG | ||
336 | "parport_serial: register_serial failed\n"); | ||
337 | continue; | ||
338 | } | ||
339 | priv->line[priv->num_ser++] = line; | ||
340 | success = 1; | ||
341 | } | ||
342 | |||
343 | return success ? 0 : 1; | ||
344 | } | ||
345 | |||
346 | /* Register the parallel port(s) of a PCI card. */ | ||
347 | static int __devinit parport_register (struct pci_dev *dev, | ||
348 | const struct pci_device_id *id) | ||
349 | { | ||
350 | struct parport_pc_pci *card; | ||
351 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
352 | int i = id->driver_data, n; | ||
353 | int success = 0; | ||
354 | |||
355 | priv->par = cards[id->driver_data]; | ||
356 | card = &priv->par; | ||
357 | if (card->preinit_hook && | ||
358 | card->preinit_hook (dev, card, PARPORT_IRQ_NONE, PARPORT_DMA_NONE)) | ||
359 | return -ENODEV; | ||
360 | |||
361 | for (n = 0; n < card->numports; n++) { | ||
362 | struct parport *port; | ||
363 | int lo = card->addr[n].lo; | ||
364 | int hi = card->addr[n].hi; | ||
365 | unsigned long io_lo, io_hi; | ||
366 | |||
367 | if (priv->num_par == ARRAY_SIZE (priv->port)) { | ||
368 | printk (KERN_WARNING | ||
369 | "parport_serial: %s: only %u parallel ports " | ||
370 | "supported (%d reported)\n", pci_name (dev), | ||
371 | ARRAY_SIZE (priv->port), card->numports); | ||
372 | break; | ||
373 | } | ||
374 | |||
375 | io_lo = pci_resource_start (dev, lo); | ||
376 | io_hi = 0; | ||
377 | if ((hi >= 0) && (hi <= 6)) | ||
378 | io_hi = pci_resource_start (dev, hi); | ||
379 | else if (hi > 6) | ||
380 | io_lo += hi; /* Reinterpret the meaning of | ||
381 | "hi" as an offset (see SYBA | ||
382 | def.) */ | ||
383 | /* TODO: test if sharing interrupts works */ | ||
384 | printk (KERN_DEBUG "PCI parallel port detected: %04x:%04x, " | ||
385 | "I/O at %#lx(%#lx)\n", | ||
386 | parport_serial_pci_tbl[i].vendor, | ||
387 | parport_serial_pci_tbl[i].device, io_lo, io_hi); | ||
388 | port = parport_pc_probe_port (io_lo, io_hi, PARPORT_IRQ_NONE, | ||
389 | PARPORT_DMA_NONE, dev); | ||
390 | if (port) { | ||
391 | priv->port[priv->num_par++] = port; | ||
392 | success = 1; | ||
393 | } | ||
394 | } | ||
395 | |||
396 | if (card->postinit_hook) | ||
397 | card->postinit_hook (dev, card, !success); | ||
398 | |||
399 | return success ? 0 : 1; | ||
400 | } | ||
401 | |||
402 | static int __devinit parport_serial_pci_probe (struct pci_dev *dev, | ||
403 | const struct pci_device_id *id) | ||
404 | { | ||
405 | struct parport_serial_private *priv; | ||
406 | int err; | ||
407 | |||
408 | priv = kmalloc (sizeof *priv, GFP_KERNEL); | ||
409 | if (!priv) | ||
410 | return -ENOMEM; | ||
411 | priv->num_ser = priv->num_par = 0; | ||
412 | pci_set_drvdata (dev, priv); | ||
413 | |||
414 | err = pci_enable_device (dev); | ||
415 | if (err) { | ||
416 | pci_set_drvdata (dev, NULL); | ||
417 | kfree (priv); | ||
418 | return err; | ||
419 | } | ||
420 | |||
421 | if (parport_register (dev, id)) { | ||
422 | pci_set_drvdata (dev, NULL); | ||
423 | kfree (priv); | ||
424 | return -ENODEV; | ||
425 | } | ||
426 | |||
427 | if (serial_register (dev, id)) { | ||
428 | int i; | ||
429 | for (i = 0; i < priv->num_par; i++) | ||
430 | parport_pc_unregister_port (priv->port[i]); | ||
431 | pci_set_drvdata (dev, NULL); | ||
432 | kfree (priv); | ||
433 | return -ENODEV; | ||
434 | } | ||
435 | |||
436 | return 0; | ||
437 | } | ||
438 | |||
439 | static void __devexit parport_serial_pci_remove (struct pci_dev *dev) | ||
440 | { | ||
441 | struct parport_serial_private *priv = pci_get_drvdata (dev); | ||
442 | int i; | ||
443 | |||
444 | // Serial ports | ||
445 | for (i = 0; i < priv->num_ser; i++) { | ||
446 | unregister_serial (priv->line[i]); | ||
447 | |||
448 | if (priv->ser.init_fn) | ||
449 | (priv->ser.init_fn) (dev, &priv->ser, 0); | ||
450 | } | ||
451 | pci_set_drvdata (dev, NULL); | ||
452 | |||
453 | // Parallel ports | ||
454 | for (i = 0; i < priv->num_par; i++) | ||
455 | parport_pc_unregister_port (priv->port[i]); | ||
456 | |||
457 | kfree (priv); | ||
458 | return; | ||
459 | } | ||
460 | |||
461 | static struct pci_driver parport_serial_pci_driver = { | ||
462 | .name = "parport_serial", | ||
463 | .id_table = parport_serial_pci_tbl, | ||
464 | .probe = parport_serial_pci_probe, | ||
465 | .remove = __devexit_p(parport_serial_pci_remove), | ||
466 | }; | ||
467 | |||
468 | |||
469 | static int __init parport_serial_init (void) | ||
470 | { | ||
471 | return pci_module_init (&parport_serial_pci_driver); | ||
472 | } | ||
473 | |||
474 | static void __exit parport_serial_exit (void) | ||
475 | { | ||
476 | pci_unregister_driver (&parport_serial_pci_driver); | ||
477 | return; | ||
478 | } | ||
479 | |||
480 | MODULE_AUTHOR("Tim Waugh <twaugh@redhat.com>"); | ||
481 | MODULE_DESCRIPTION("Driver for common parallel+serial multi-I/O PCI cards"); | ||
482 | MODULE_LICENSE("GPL"); | ||
483 | |||
484 | module_init(parport_serial_init); | ||
485 | module_exit(parport_serial_exit); | ||
diff --git a/drivers/parport/parport_sunbpp.c b/drivers/parport/parport_sunbpp.c new file mode 100644 index 000000000000..36a1556e64c7 --- /dev/null +++ b/drivers/parport/parport_sunbpp.c | |||
@@ -0,0 +1,412 @@ | |||
1 | /* $Id: parport_sunbpp.c,v 1.12 2001/05/26 03:01:42 davem Exp $ | ||
2 | * Parallel-port routines for Sun architecture | ||
3 | * | ||
4 | * Author: Derrick J. Brashear <shadow@dementia.org> | ||
5 | * | ||
6 | * based on work by: | ||
7 | * Phil Blundell <philb@gnu.org> | ||
8 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
9 | * Jose Renau <renau@acm.org> | ||
10 | * David Campbell <campbell@tirian.che.curtin.edu.au> | ||
11 | * Grant Guenther <grant@torque.net> | ||
12 | * Eddie C. Dost <ecd@skynet.be> | ||
13 | * Stephen Williams (steve@icarus.com) | ||
14 | * Gus Baldauf (gbaldauf@ix.netcom.com) | ||
15 | * Peter Zaitcev | ||
16 | * Tom Dyas | ||
17 | */ | ||
18 | |||
19 | #include <linux/string.h> | ||
20 | #include <linux/module.h> | ||
21 | #include <linux/delay.h> | ||
22 | #include <linux/errno.h> | ||
23 | #include <linux/ioport.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/slab.h> | ||
26 | #include <linux/init.h> | ||
27 | |||
28 | #include <linux/parport.h> | ||
29 | |||
30 | #include <asm/ptrace.h> | ||
31 | #include <linux/interrupt.h> | ||
32 | |||
33 | #include <asm/io.h> | ||
34 | #include <asm/oplib.h> /* OpenProm Library */ | ||
35 | #include <asm/sbus.h> | ||
36 | #include <asm/dma.h> /* BPP uses LSI 64854 for DMA */ | ||
37 | #include <asm/irq.h> | ||
38 | #include <asm/sunbpp.h> | ||
39 | |||
40 | #undef __SUNBPP_DEBUG | ||
41 | #ifdef __SUNBPP_DEBUG | ||
42 | #define dprintk(x) printk x | ||
43 | #else | ||
44 | #define dprintk(x) | ||
45 | #endif | ||
46 | |||
47 | static irqreturn_t parport_sunbpp_interrupt(int irq, void *dev_id, struct pt_regs *regs) | ||
48 | { | ||
49 | parport_generic_irq(irq, (struct parport *) dev_id, regs); | ||
50 | return IRQ_HANDLED; | ||
51 | } | ||
52 | |||
53 | static void parport_sunbpp_disable_irq(struct parport *p) | ||
54 | { | ||
55 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
56 | u32 tmp; | ||
57 | |||
58 | tmp = sbus_readl(®s->p_csr); | ||
59 | tmp &= ~DMA_INT_ENAB; | ||
60 | sbus_writel(tmp, ®s->p_csr); | ||
61 | } | ||
62 | |||
63 | static void parport_sunbpp_enable_irq(struct parport *p) | ||
64 | { | ||
65 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
66 | u32 tmp; | ||
67 | |||
68 | tmp = sbus_readl(®s->p_csr); | ||
69 | tmp |= DMA_INT_ENAB; | ||
70 | sbus_writel(tmp, ®s->p_csr); | ||
71 | } | ||
72 | |||
73 | static void parport_sunbpp_write_data(struct parport *p, unsigned char d) | ||
74 | { | ||
75 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
76 | |||
77 | sbus_writeb(d, ®s->p_dr); | ||
78 | dprintk((KERN_DEBUG "wrote 0x%x\n", d)); | ||
79 | } | ||
80 | |||
81 | static unsigned char parport_sunbpp_read_data(struct parport *p) | ||
82 | { | ||
83 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
84 | |||
85 | return sbus_readb(®s->p_dr); | ||
86 | } | ||
87 | |||
88 | #if 0 | ||
89 | static void control_pc_to_sunbpp(struct parport *p, unsigned char status) | ||
90 | { | ||
91 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
92 | unsigned char value_tcr = sbus_readb(®s->p_tcr); | ||
93 | unsigned char value_or = sbus_readb(®s->p_or); | ||
94 | |||
95 | if (status & PARPORT_CONTROL_STROBE) | ||
96 | value_tcr |= P_TCR_DS; | ||
97 | if (status & PARPORT_CONTROL_AUTOFD) | ||
98 | value_or |= P_OR_AFXN; | ||
99 | if (status & PARPORT_CONTROL_INIT) | ||
100 | value_or |= P_OR_INIT; | ||
101 | if (status & PARPORT_CONTROL_SELECT) | ||
102 | value_or |= P_OR_SLCT_IN; | ||
103 | |||
104 | sbus_writeb(value_or, ®s->p_or); | ||
105 | sbus_writeb(value_tcr, ®s->p_tcr); | ||
106 | } | ||
107 | #endif | ||
108 | |||
109 | static unsigned char status_sunbpp_to_pc(struct parport *p) | ||
110 | { | ||
111 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
112 | unsigned char bits = 0; | ||
113 | unsigned char value_tcr = sbus_readb(®s->p_tcr); | ||
114 | unsigned char value_ir = sbus_readb(®s->p_ir); | ||
115 | |||
116 | if (!(value_ir & P_IR_ERR)) | ||
117 | bits |= PARPORT_STATUS_ERROR; | ||
118 | if (!(value_ir & P_IR_SLCT)) | ||
119 | bits |= PARPORT_STATUS_SELECT; | ||
120 | if (!(value_ir & P_IR_PE)) | ||
121 | bits |= PARPORT_STATUS_PAPEROUT; | ||
122 | if (value_tcr & P_TCR_ACK) | ||
123 | bits |= PARPORT_STATUS_ACK; | ||
124 | if (!(value_tcr & P_TCR_BUSY)) | ||
125 | bits |= PARPORT_STATUS_BUSY; | ||
126 | |||
127 | dprintk((KERN_DEBUG "tcr 0x%x ir 0x%x\n", regs->p_tcr, regs->p_ir)); | ||
128 | dprintk((KERN_DEBUG "read status 0x%x\n", bits)); | ||
129 | return bits; | ||
130 | } | ||
131 | |||
132 | static unsigned char control_sunbpp_to_pc(struct parport *p) | ||
133 | { | ||
134 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
135 | unsigned char bits = 0; | ||
136 | unsigned char value_tcr = sbus_readb(®s->p_tcr); | ||
137 | unsigned char value_or = sbus_readb(®s->p_or); | ||
138 | |||
139 | if (!(value_tcr & P_TCR_DS)) | ||
140 | bits |= PARPORT_CONTROL_STROBE; | ||
141 | if (!(value_or & P_OR_AFXN)) | ||
142 | bits |= PARPORT_CONTROL_AUTOFD; | ||
143 | if (!(value_or & P_OR_INIT)) | ||
144 | bits |= PARPORT_CONTROL_INIT; | ||
145 | if (value_or & P_OR_SLCT_IN) | ||
146 | bits |= PARPORT_CONTROL_SELECT; | ||
147 | |||
148 | dprintk((KERN_DEBUG "tcr 0x%x or 0x%x\n", regs->p_tcr, regs->p_or)); | ||
149 | dprintk((KERN_DEBUG "read control 0x%x\n", bits)); | ||
150 | return bits; | ||
151 | } | ||
152 | |||
153 | static unsigned char parport_sunbpp_read_control(struct parport *p) | ||
154 | { | ||
155 | return control_sunbpp_to_pc(p); | ||
156 | } | ||
157 | |||
158 | static unsigned char parport_sunbpp_frob_control(struct parport *p, | ||
159 | unsigned char mask, | ||
160 | unsigned char val) | ||
161 | { | ||
162 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
163 | unsigned char value_tcr = sbus_readb(®s->p_tcr); | ||
164 | unsigned char value_or = sbus_readb(®s->p_or); | ||
165 | |||
166 | dprintk((KERN_DEBUG "frob1: tcr 0x%x or 0x%x\n", regs->p_tcr, regs->p_or)); | ||
167 | if (mask & PARPORT_CONTROL_STROBE) { | ||
168 | if (val & PARPORT_CONTROL_STROBE) { | ||
169 | value_tcr &= ~P_TCR_DS; | ||
170 | } else { | ||
171 | value_tcr |= P_TCR_DS; | ||
172 | } | ||
173 | } | ||
174 | if (mask & PARPORT_CONTROL_AUTOFD) { | ||
175 | if (val & PARPORT_CONTROL_AUTOFD) { | ||
176 | value_or &= ~P_OR_AFXN; | ||
177 | } else { | ||
178 | value_or |= P_OR_AFXN; | ||
179 | } | ||
180 | } | ||
181 | if (mask & PARPORT_CONTROL_INIT) { | ||
182 | if (val & PARPORT_CONTROL_INIT) { | ||
183 | value_or &= ~P_OR_INIT; | ||
184 | } else { | ||
185 | value_or |= P_OR_INIT; | ||
186 | } | ||
187 | } | ||
188 | if (mask & PARPORT_CONTROL_SELECT) { | ||
189 | if (val & PARPORT_CONTROL_SELECT) { | ||
190 | value_or |= P_OR_SLCT_IN; | ||
191 | } else { | ||
192 | value_or &= ~P_OR_SLCT_IN; | ||
193 | } | ||
194 | } | ||
195 | |||
196 | sbus_writeb(value_or, ®s->p_or); | ||
197 | sbus_writeb(value_tcr, ®s->p_tcr); | ||
198 | dprintk((KERN_DEBUG "frob2: tcr 0x%x or 0x%x\n", regs->p_tcr, regs->p_or)); | ||
199 | return parport_sunbpp_read_control(p); | ||
200 | } | ||
201 | |||
202 | static void parport_sunbpp_write_control(struct parport *p, unsigned char d) | ||
203 | { | ||
204 | const unsigned char wm = (PARPORT_CONTROL_STROBE | | ||
205 | PARPORT_CONTROL_AUTOFD | | ||
206 | PARPORT_CONTROL_INIT | | ||
207 | PARPORT_CONTROL_SELECT); | ||
208 | |||
209 | parport_sunbpp_frob_control (p, wm, d & wm); | ||
210 | } | ||
211 | |||
212 | static unsigned char parport_sunbpp_read_status(struct parport *p) | ||
213 | { | ||
214 | return status_sunbpp_to_pc(p); | ||
215 | } | ||
216 | |||
217 | static void parport_sunbpp_data_forward (struct parport *p) | ||
218 | { | ||
219 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
220 | unsigned char value_tcr = sbus_readb(®s->p_tcr); | ||
221 | |||
222 | dprintk((KERN_DEBUG "forward\n")); | ||
223 | value_tcr &= ~P_TCR_DIR; | ||
224 | sbus_writeb(value_tcr, ®s->p_tcr); | ||
225 | } | ||
226 | |||
227 | static void parport_sunbpp_data_reverse (struct parport *p) | ||
228 | { | ||
229 | struct bpp_regs __iomem *regs = (struct bpp_regs __iomem *)p->base; | ||
230 | u8 val = sbus_readb(®s->p_tcr); | ||
231 | |||
232 | dprintk((KERN_DEBUG "reverse\n")); | ||
233 | val |= P_TCR_DIR; | ||
234 | sbus_writeb(val, ®s->p_tcr); | ||
235 | } | ||
236 | |||
237 | static void parport_sunbpp_init_state(struct pardevice *dev, struct parport_state *s) | ||
238 | { | ||
239 | s->u.pc.ctr = 0xc; | ||
240 | s->u.pc.ecr = 0x0; | ||
241 | } | ||
242 | |||
243 | static void parport_sunbpp_save_state(struct parport *p, struct parport_state *s) | ||
244 | { | ||
245 | s->u.pc.ctr = parport_sunbpp_read_control(p); | ||
246 | } | ||
247 | |||
248 | static void parport_sunbpp_restore_state(struct parport *p, struct parport_state *s) | ||
249 | { | ||
250 | parport_sunbpp_write_control(p, s->u.pc.ctr); | ||
251 | } | ||
252 | |||
253 | static struct parport_operations parport_sunbpp_ops = | ||
254 | { | ||
255 | .write_data = parport_sunbpp_write_data, | ||
256 | .read_data = parport_sunbpp_read_data, | ||
257 | |||
258 | .write_control = parport_sunbpp_write_control, | ||
259 | .read_control = parport_sunbpp_read_control, | ||
260 | .frob_control = parport_sunbpp_frob_control, | ||
261 | |||
262 | .read_status = parport_sunbpp_read_status, | ||
263 | |||
264 | .enable_irq = parport_sunbpp_enable_irq, | ||
265 | .disable_irq = parport_sunbpp_disable_irq, | ||
266 | |||
267 | .data_forward = parport_sunbpp_data_forward, | ||
268 | .data_reverse = parport_sunbpp_data_reverse, | ||
269 | |||
270 | .init_state = parport_sunbpp_init_state, | ||
271 | .save_state = parport_sunbpp_save_state, | ||
272 | .restore_state = parport_sunbpp_restore_state, | ||
273 | |||
274 | .epp_write_data = parport_ieee1284_epp_write_data, | ||
275 | .epp_read_data = parport_ieee1284_epp_read_data, | ||
276 | .epp_write_addr = parport_ieee1284_epp_write_addr, | ||
277 | .epp_read_addr = parport_ieee1284_epp_read_addr, | ||
278 | |||
279 | .ecp_write_data = parport_ieee1284_ecp_write_data, | ||
280 | .ecp_read_data = parport_ieee1284_ecp_read_data, | ||
281 | .ecp_write_addr = parport_ieee1284_ecp_write_addr, | ||
282 | |||
283 | .compat_write_data = parport_ieee1284_write_compat, | ||
284 | .nibble_read_data = parport_ieee1284_read_nibble, | ||
285 | .byte_read_data = parport_ieee1284_read_byte, | ||
286 | |||
287 | .owner = THIS_MODULE, | ||
288 | }; | ||
289 | |||
290 | typedef struct { | ||
291 | struct list_head list; | ||
292 | struct parport *port; | ||
293 | } Node; | ||
294 | /* no locks, everything's serialized */ | ||
295 | static LIST_HEAD(port_list); | ||
296 | |||
297 | static int __init init_one_port(struct sbus_dev *sdev) | ||
298 | { | ||
299 | struct parport *p; | ||
300 | /* at least in theory there may be a "we don't dma" case */ | ||
301 | struct parport_operations *ops; | ||
302 | void __iomem *base; | ||
303 | int irq, dma, err = 0, size; | ||
304 | struct bpp_regs __iomem *regs; | ||
305 | unsigned char value_tcr; | ||
306 | Node *node; | ||
307 | |||
308 | dprintk((KERN_DEBUG "init_one_port(%p): ranges, alloc_io, ", sdev)); | ||
309 | node = kmalloc(sizeof(Node), GFP_KERNEL); | ||
310 | if (!node) | ||
311 | goto out0; | ||
312 | |||
313 | irq = sdev->irqs[0]; | ||
314 | base = sbus_ioremap(&sdev->resource[0], 0, | ||
315 | sdev->reg_addrs[0].reg_size, | ||
316 | "sunbpp"); | ||
317 | if (!base) | ||
318 | goto out1; | ||
319 | |||
320 | size = sdev->reg_addrs[0].reg_size; | ||
321 | dma = PARPORT_DMA_NONE; | ||
322 | |||
323 | dprintk(("alloc(ppops), ")); | ||
324 | ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL); | ||
325 | if (!ops) | ||
326 | goto out2; | ||
327 | |||
328 | memcpy (ops, &parport_sunbpp_ops, sizeof (struct parport_operations)); | ||
329 | |||
330 | dprintk(("register_port\n")); | ||
331 | if (!(p = parport_register_port((unsigned long)base, irq, dma, ops))) | ||
332 | goto out3; | ||
333 | |||
334 | p->size = size; | ||
335 | |||
336 | dprintk((KERN_DEBUG "init_one_port: request_irq(%08x:%p:%x:%s:%p) ", | ||
337 | p->irq, parport_sunbpp_interrupt, SA_SHIRQ, p->name, p)); | ||
338 | if ((err = request_irq(p->irq, parport_sunbpp_interrupt, | ||
339 | SA_SHIRQ, p->name, p)) != 0) { | ||
340 | dprintk(("ERROR %d\n", err)); | ||
341 | goto out4; | ||
342 | } | ||
343 | dprintk(("OK\n")); | ||
344 | parport_sunbpp_enable_irq(p); | ||
345 | |||
346 | regs = (struct bpp_regs __iomem *)p->base; | ||
347 | dprintk((KERN_DEBUG "forward\n")); | ||
348 | value_tcr = sbus_readb(®s->p_tcr); | ||
349 | value_tcr &= ~P_TCR_DIR; | ||
350 | sbus_writeb(value_tcr, ®s->p_tcr); | ||
351 | |||
352 | printk(KERN_INFO "%s: sunbpp at 0x%lx\n", p->name, p->base); | ||
353 | node->port = p; | ||
354 | list_add(&node->list, &port_list); | ||
355 | parport_announce_port (p); | ||
356 | |||
357 | return 1; | ||
358 | |||
359 | out4: | ||
360 | parport_put_port(p); | ||
361 | out3: | ||
362 | kfree(ops); | ||
363 | out2: | ||
364 | sbus_iounmap(base, size); | ||
365 | out1: | ||
366 | kfree(node); | ||
367 | out0: | ||
368 | return err; | ||
369 | } | ||
370 | |||
371 | static int __init parport_sunbpp_init(void) | ||
372 | { | ||
373 | struct sbus_bus *sbus; | ||
374 | struct sbus_dev *sdev; | ||
375 | int count = 0; | ||
376 | |||
377 | for_each_sbus(sbus) { | ||
378 | for_each_sbusdev(sdev, sbus) { | ||
379 | if (!strcmp(sdev->prom_name, "SUNW,bpp")) | ||
380 | count += init_one_port(sdev); | ||
381 | } | ||
382 | } | ||
383 | return count ? 0 : -ENODEV; | ||
384 | } | ||
385 | |||
386 | static void __exit parport_sunbpp_exit(void) | ||
387 | { | ||
388 | while (!list_empty(&port_list)) { | ||
389 | Node *node = list_entry(port_list.next, Node, list); | ||
390 | struct parport *p = node->port; | ||
391 | struct parport_operations *ops = p->ops; | ||
392 | parport_remove_port(p); | ||
393 | |||
394 | if (p->irq != PARPORT_IRQ_NONE) { | ||
395 | parport_sunbpp_disable_irq(p); | ||
396 | free_irq(p->irq, p); | ||
397 | } | ||
398 | sbus_iounmap((void __iomem *)p->base, p->size); | ||
399 | parport_put_port(p); | ||
400 | kfree (ops); | ||
401 | list_del(&node->list); | ||
402 | kfree (node); | ||
403 | } | ||
404 | } | ||
405 | |||
406 | MODULE_AUTHOR("Derrick J Brashear"); | ||
407 | MODULE_DESCRIPTION("Parport Driver for Sparc bidirectional Port"); | ||
408 | MODULE_SUPPORTED_DEVICE("Sparc Bidirectional Parallel Port"); | ||
409 | MODULE_LICENSE("GPL"); | ||
410 | |||
411 | module_init(parport_sunbpp_init) | ||
412 | module_exit(parport_sunbpp_exit) | ||
diff --git a/drivers/parport/probe.c b/drivers/parport/probe.c new file mode 100644 index 000000000000..c94963145e17 --- /dev/null +++ b/drivers/parport/probe.c | |||
@@ -0,0 +1,224 @@ | |||
1 | /* $Id: parport_probe.c,v 1.1 1999/07/03 08:56:17 davem Exp $ | ||
2 | * Parallel port device probing code | ||
3 | * | ||
4 | * Authors: Carsten Gross, carsten@sol.wohnheim.uni-ulm.de | ||
5 | * Philip Blundell <philb@gnu.org> | ||
6 | */ | ||
7 | |||
8 | #include <linux/module.h> | ||
9 | #include <linux/parport.h> | ||
10 | #include <linux/ctype.h> | ||
11 | #include <linux/string.h> | ||
12 | #include <asm/uaccess.h> | ||
13 | |||
14 | static struct { | ||
15 | char *token; | ||
16 | char *descr; | ||
17 | } classes[] = { | ||
18 | { "", "Legacy device" }, | ||
19 | { "PRINTER", "Printer" }, | ||
20 | { "MODEM", "Modem" }, | ||
21 | { "NET", "Network device" }, | ||
22 | { "HDC", "Hard disk" }, | ||
23 | { "PCMCIA", "PCMCIA" }, | ||
24 | { "MEDIA", "Multimedia device" }, | ||
25 | { "FDC", "Floppy disk" }, | ||
26 | { "PORTS", "Ports" }, | ||
27 | { "SCANNER", "Scanner" }, | ||
28 | { "DIGICAM", "Digital camera" }, | ||
29 | { "", "Unknown device" }, | ||
30 | { "", "Unspecified" }, | ||
31 | { "SCSIADAPTER", "SCSI adapter" }, | ||
32 | { NULL, NULL } | ||
33 | }; | ||
34 | |||
35 | static void pretty_print(struct parport *port, int device) | ||
36 | { | ||
37 | struct parport_device_info *info = &port->probe_info[device + 1]; | ||
38 | |||
39 | printk(KERN_INFO "%s", port->name); | ||
40 | |||
41 | if (device >= 0) | ||
42 | printk (" (addr %d)", device); | ||
43 | |||
44 | printk (": %s", classes[info->class].descr); | ||
45 | if (info->class) | ||
46 | printk(", %s %s", info->mfr, info->model); | ||
47 | |||
48 | printk("\n"); | ||
49 | } | ||
50 | |||
51 | static char *strdup(char *str) | ||
52 | { | ||
53 | int n = strlen(str)+1; | ||
54 | char *s = kmalloc(n, GFP_KERNEL); | ||
55 | if (!s) return NULL; | ||
56 | return strcpy(s, str); | ||
57 | } | ||
58 | |||
59 | static void parse_data(struct parport *port, int device, char *str) | ||
60 | { | ||
61 | char *txt = kmalloc(strlen(str)+1, GFP_KERNEL); | ||
62 | char *p = txt, *q; | ||
63 | int guessed_class = PARPORT_CLASS_UNSPEC; | ||
64 | struct parport_device_info *info = &port->probe_info[device + 1]; | ||
65 | |||
66 | if (!txt) { | ||
67 | printk(KERN_WARNING "%s probe: memory squeeze\n", port->name); | ||
68 | return; | ||
69 | } | ||
70 | strcpy(txt, str); | ||
71 | while (p) { | ||
72 | char *sep; | ||
73 | q = strchr(p, ';'); | ||
74 | if (q) *q = 0; | ||
75 | sep = strchr(p, ':'); | ||
76 | if (sep) { | ||
77 | char *u; | ||
78 | *(sep++) = 0; | ||
79 | /* Get rid of trailing blanks */ | ||
80 | u = sep + strlen (sep) - 1; | ||
81 | while (u >= p && *u == ' ') | ||
82 | *u-- = '\0'; | ||
83 | u = p; | ||
84 | while (*u) { | ||
85 | *u = toupper(*u); | ||
86 | u++; | ||
87 | } | ||
88 | if (!strcmp(p, "MFG") || !strcmp(p, "MANUFACTURER")) { | ||
89 | if (info->mfr) | ||
90 | kfree (info->mfr); | ||
91 | info->mfr = strdup(sep); | ||
92 | } else if (!strcmp(p, "MDL") || !strcmp(p, "MODEL")) { | ||
93 | if (info->model) | ||
94 | kfree (info->model); | ||
95 | info->model = strdup(sep); | ||
96 | } else if (!strcmp(p, "CLS") || !strcmp(p, "CLASS")) { | ||
97 | int i; | ||
98 | if (info->class_name) | ||
99 | kfree (info->class_name); | ||
100 | info->class_name = strdup(sep); | ||
101 | for (u = sep; *u; u++) | ||
102 | *u = toupper(*u); | ||
103 | for (i = 0; classes[i].token; i++) { | ||
104 | if (!strcmp(classes[i].token, sep)) { | ||
105 | info->class = i; | ||
106 | goto rock_on; | ||
107 | } | ||
108 | } | ||
109 | printk(KERN_WARNING "%s probe: warning, class '%s' not understood.\n", port->name, sep); | ||
110 | info->class = PARPORT_CLASS_OTHER; | ||
111 | } else if (!strcmp(p, "CMD") || | ||
112 | !strcmp(p, "COMMAND SET")) { | ||
113 | if (info->cmdset) | ||
114 | kfree (info->cmdset); | ||
115 | info->cmdset = strdup(sep); | ||
116 | /* if it speaks printer language, it's | ||
117 | probably a printer */ | ||
118 | if (strstr(sep, "PJL") || strstr(sep, "PCL")) | ||
119 | guessed_class = PARPORT_CLASS_PRINTER; | ||
120 | } else if (!strcmp(p, "DES") || !strcmp(p, "DESCRIPTION")) { | ||
121 | if (info->description) | ||
122 | kfree (info->description); | ||
123 | info->description = strdup(sep); | ||
124 | } | ||
125 | } | ||
126 | rock_on: | ||
127 | if (q) p = q+1; else p=NULL; | ||
128 | } | ||
129 | |||
130 | /* If the device didn't tell us its class, maybe we have managed to | ||
131 | guess one from the things it did say. */ | ||
132 | if (info->class == PARPORT_CLASS_UNSPEC) | ||
133 | info->class = guessed_class; | ||
134 | |||
135 | pretty_print (port, device); | ||
136 | |||
137 | kfree(txt); | ||
138 | } | ||
139 | |||
140 | /* Get Std 1284 Device ID. */ | ||
141 | ssize_t parport_device_id (int devnum, char *buffer, size_t len) | ||
142 | { | ||
143 | ssize_t retval = -ENXIO; | ||
144 | struct pardevice *dev = parport_open (devnum, "Device ID probe", | ||
145 | NULL, NULL, NULL, 0, NULL); | ||
146 | if (!dev) | ||
147 | return -ENXIO; | ||
148 | |||
149 | parport_claim_or_block (dev); | ||
150 | |||
151 | /* Negotiate to compatibility mode, and then to device ID mode. | ||
152 | * (This is in case we are already in device ID mode.) */ | ||
153 | parport_negotiate (dev->port, IEEE1284_MODE_COMPAT); | ||
154 | retval = parport_negotiate (dev->port, | ||
155 | IEEE1284_MODE_NIBBLE | IEEE1284_DEVICEID); | ||
156 | |||
157 | if (!retval) { | ||
158 | int idlen; | ||
159 | unsigned char length[2]; | ||
160 | |||
161 | /* First two bytes are MSB,LSB of inclusive length. */ | ||
162 | retval = parport_read (dev->port, length, 2); | ||
163 | |||
164 | if (retval != 2) goto end_id; | ||
165 | |||
166 | idlen = (length[0] << 8) + length[1] - 2; | ||
167 | /* | ||
168 | * Check if the caller-allocated buffer is large enough | ||
169 | * otherwise bail out or there will be an at least off by one. | ||
170 | */ | ||
171 | if (idlen + 1 < len) | ||
172 | len = idlen; | ||
173 | else { | ||
174 | retval = -EINVAL; | ||
175 | goto out; | ||
176 | } | ||
177 | retval = parport_read (dev->port, buffer, len); | ||
178 | |||
179 | if (retval != len) | ||
180 | printk (KERN_DEBUG "%s: only read %Zd of %Zd ID bytes\n", | ||
181 | dev->port->name, retval, | ||
182 | len); | ||
183 | |||
184 | /* Some printer manufacturers mistakenly believe that | ||
185 | the length field is supposed to be _exclusive_. | ||
186 | In addition, there are broken devices out there | ||
187 | that don't even finish off with a semi-colon. */ | ||
188 | if (buffer[len - 1] != ';') { | ||
189 | ssize_t diff; | ||
190 | diff = parport_read (dev->port, buffer + len, 2); | ||
191 | retval += diff; | ||
192 | |||
193 | if (diff) | ||
194 | printk (KERN_DEBUG | ||
195 | "%s: device reported incorrect " | ||
196 | "length field (%d, should be %Zd)\n", | ||
197 | dev->port->name, idlen, retval); | ||
198 | else { | ||
199 | /* One semi-colon short of a device ID. */ | ||
200 | buffer[len++] = ';'; | ||
201 | printk (KERN_DEBUG "%s: faking semi-colon\n", | ||
202 | dev->port->name); | ||
203 | |||
204 | /* If we get here, I don't think we | ||
205 | need to worry about the possible | ||
206 | standard violation of having read | ||
207 | more than we were told to. The | ||
208 | device is non-compliant anyhow. */ | ||
209 | } | ||
210 | } | ||
211 | |||
212 | end_id: | ||
213 | buffer[len] = '\0'; | ||
214 | parport_negotiate (dev->port, IEEE1284_MODE_COMPAT); | ||
215 | } | ||
216 | |||
217 | if (retval > 2) | ||
218 | parse_data (dev->port, dev->daisy, buffer); | ||
219 | |||
220 | out: | ||
221 | parport_release (dev); | ||
222 | parport_close (dev); | ||
223 | return retval; | ||
224 | } | ||
diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c new file mode 100644 index 000000000000..cbe17184b9c7 --- /dev/null +++ b/drivers/parport/procfs.c | |||
@@ -0,0 +1,533 @@ | |||
1 | /* Sysctl interface for parport devices. | ||
2 | * | ||
3 | * Authors: David Campbell <campbell@torque.net> | ||
4 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
5 | * Philip Blundell <philb@gnu.org> | ||
6 | * Andrea Arcangeli | ||
7 | * Riccardo Facchetti <fizban@tin.it> | ||
8 | * | ||
9 | * based on work by Grant Guenther <grant@torque.net> | ||
10 | * and Philip Blundell | ||
11 | * | ||
12 | * Cleaned up include files - Russell King <linux@arm.uk.linux.org> | ||
13 | */ | ||
14 | |||
15 | #include <linux/string.h> | ||
16 | #include <linux/config.h> | ||
17 | #include <linux/init.h> | ||
18 | #include <linux/module.h> | ||
19 | #include <linux/errno.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/parport.h> | ||
23 | #include <linux/ctype.h> | ||
24 | #include <linux/sysctl.h> | ||
25 | |||
26 | #include <asm/uaccess.h> | ||
27 | |||
28 | #if defined(CONFIG_SYSCTL) && defined(CONFIG_PROC_FS) | ||
29 | |||
30 | #define PARPORT_MIN_TIMESLICE_VALUE 1ul | ||
31 | #define PARPORT_MAX_TIMESLICE_VALUE ((unsigned long) HZ) | ||
32 | #define PARPORT_MIN_SPINTIME_VALUE 1 | ||
33 | #define PARPORT_MAX_SPINTIME_VALUE 1000 | ||
34 | |||
35 | static int do_active_device(ctl_table *table, int write, struct file *filp, | ||
36 | void __user *result, size_t *lenp, loff_t *ppos) | ||
37 | { | ||
38 | struct parport *port = (struct parport *)table->extra1; | ||
39 | char buffer[256]; | ||
40 | struct pardevice *dev; | ||
41 | int len = 0; | ||
42 | |||
43 | if (write) /* can't happen anyway */ | ||
44 | return -EACCES; | ||
45 | |||
46 | if (*ppos) { | ||
47 | *lenp = 0; | ||
48 | return 0; | ||
49 | } | ||
50 | |||
51 | for (dev = port->devices; dev ; dev = dev->next) { | ||
52 | if(dev == port->cad) { | ||
53 | len += sprintf(buffer, "%s\n", dev->name); | ||
54 | } | ||
55 | } | ||
56 | |||
57 | if(!len) { | ||
58 | len += sprintf(buffer, "%s\n", "none"); | ||
59 | } | ||
60 | |||
61 | if (len > *lenp) | ||
62 | len = *lenp; | ||
63 | else | ||
64 | *lenp = len; | ||
65 | |||
66 | *ppos += len; | ||
67 | |||
68 | return copy_to_user(result, buffer, len) ? -EFAULT : 0; | ||
69 | } | ||
70 | |||
71 | #ifdef CONFIG_PARPORT_1284 | ||
72 | static int do_autoprobe(ctl_table *table, int write, struct file *filp, | ||
73 | void __user *result, size_t *lenp, loff_t *ppos) | ||
74 | { | ||
75 | struct parport_device_info *info = table->extra2; | ||
76 | const char *str; | ||
77 | char buffer[256]; | ||
78 | int len = 0; | ||
79 | |||
80 | if (write) /* permissions stop this */ | ||
81 | return -EACCES; | ||
82 | |||
83 | if (*ppos) { | ||
84 | *lenp = 0; | ||
85 | return 0; | ||
86 | } | ||
87 | |||
88 | if ((str = info->class_name) != NULL) | ||
89 | len += sprintf (buffer + len, "CLASS:%s;\n", str); | ||
90 | |||
91 | if ((str = info->model) != NULL) | ||
92 | len += sprintf (buffer + len, "MODEL:%s;\n", str); | ||
93 | |||
94 | if ((str = info->mfr) != NULL) | ||
95 | len += sprintf (buffer + len, "MANUFACTURER:%s;\n", str); | ||
96 | |||
97 | if ((str = info->description) != NULL) | ||
98 | len += sprintf (buffer + len, "DESCRIPTION:%s;\n", str); | ||
99 | |||
100 | if ((str = info->cmdset) != NULL) | ||
101 | len += sprintf (buffer + len, "COMMAND SET:%s;\n", str); | ||
102 | |||
103 | if (len > *lenp) | ||
104 | len = *lenp; | ||
105 | else | ||
106 | *lenp = len; | ||
107 | |||
108 | *ppos += len; | ||
109 | |||
110 | return copy_to_user (result, buffer, len) ? -EFAULT : 0; | ||
111 | } | ||
112 | #endif /* IEEE1284.3 support. */ | ||
113 | |||
114 | static int do_hardware_base_addr (ctl_table *table, int write, | ||
115 | struct file *filp, void __user *result, | ||
116 | size_t *lenp, loff_t *ppos) | ||
117 | { | ||
118 | struct parport *port = (struct parport *)table->extra1; | ||
119 | char buffer[20]; | ||
120 | int len = 0; | ||
121 | |||
122 | if (*ppos) { | ||
123 | *lenp = 0; | ||
124 | return 0; | ||
125 | } | ||
126 | |||
127 | if (write) /* permissions prevent this anyway */ | ||
128 | return -EACCES; | ||
129 | |||
130 | len += sprintf (buffer, "%lu\t%lu\n", port->base, port->base_hi); | ||
131 | |||
132 | if (len > *lenp) | ||
133 | len = *lenp; | ||
134 | else | ||
135 | *lenp = len; | ||
136 | |||
137 | *ppos += len; | ||
138 | |||
139 | return copy_to_user(result, buffer, len) ? -EFAULT : 0; | ||
140 | } | ||
141 | |||
142 | static int do_hardware_irq (ctl_table *table, int write, | ||
143 | struct file *filp, void __user *result, | ||
144 | size_t *lenp, loff_t *ppos) | ||
145 | { | ||
146 | struct parport *port = (struct parport *)table->extra1; | ||
147 | char buffer[20]; | ||
148 | int len = 0; | ||
149 | |||
150 | if (*ppos) { | ||
151 | *lenp = 0; | ||
152 | return 0; | ||
153 | } | ||
154 | |||
155 | if (write) /* permissions prevent this anyway */ | ||
156 | return -EACCES; | ||
157 | |||
158 | len += sprintf (buffer, "%d\n", port->irq); | ||
159 | |||
160 | if (len > *lenp) | ||
161 | len = *lenp; | ||
162 | else | ||
163 | *lenp = len; | ||
164 | |||
165 | *ppos += len; | ||
166 | |||
167 | return copy_to_user(result, buffer, len) ? -EFAULT : 0; | ||
168 | } | ||
169 | |||
170 | static int do_hardware_dma (ctl_table *table, int write, | ||
171 | struct file *filp, void __user *result, | ||
172 | size_t *lenp, loff_t *ppos) | ||
173 | { | ||
174 | struct parport *port = (struct parport *)table->extra1; | ||
175 | char buffer[20]; | ||
176 | int len = 0; | ||
177 | |||
178 | if (*ppos) { | ||
179 | *lenp = 0; | ||
180 | return 0; | ||
181 | } | ||
182 | |||
183 | if (write) /* permissions prevent this anyway */ | ||
184 | return -EACCES; | ||
185 | |||
186 | len += sprintf (buffer, "%d\n", port->dma); | ||
187 | |||
188 | if (len > *lenp) | ||
189 | len = *lenp; | ||
190 | else | ||
191 | *lenp = len; | ||
192 | |||
193 | *ppos += len; | ||
194 | |||
195 | return copy_to_user(result, buffer, len) ? -EFAULT : 0; | ||
196 | } | ||
197 | |||
198 | static int do_hardware_modes (ctl_table *table, int write, | ||
199 | struct file *filp, void __user *result, | ||
200 | size_t *lenp, loff_t *ppos) | ||
201 | { | ||
202 | struct parport *port = (struct parport *)table->extra1; | ||
203 | char buffer[40]; | ||
204 | int len = 0; | ||
205 | |||
206 | if (*ppos) { | ||
207 | *lenp = 0; | ||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | if (write) /* permissions prevent this anyway */ | ||
212 | return -EACCES; | ||
213 | |||
214 | { | ||
215 | #define printmode(x) {if(port->modes&PARPORT_MODE_##x){len+=sprintf(buffer+len,"%s%s",f?",":"",#x);f++;}} | ||
216 | int f = 0; | ||
217 | printmode(PCSPP); | ||
218 | printmode(TRISTATE); | ||
219 | printmode(COMPAT); | ||
220 | printmode(EPP); | ||
221 | printmode(ECP); | ||
222 | printmode(DMA); | ||
223 | #undef printmode | ||
224 | } | ||
225 | buffer[len++] = '\n'; | ||
226 | |||
227 | if (len > *lenp) | ||
228 | len = *lenp; | ||
229 | else | ||
230 | *lenp = len; | ||
231 | |||
232 | *ppos += len; | ||
233 | |||
234 | return copy_to_user(result, buffer, len) ? -EFAULT : 0; | ||
235 | } | ||
236 | |||
237 | #define PARPORT_PORT_DIR(child) { 0, NULL, NULL, 0, 0555, child } | ||
238 | #define PARPORT_PARPORT_DIR(child) { DEV_PARPORT, "parport", \ | ||
239 | NULL, 0, 0555, child } | ||
240 | #define PARPORT_DEV_DIR(child) { CTL_DEV, "dev", NULL, 0, 0555, child } | ||
241 | #define PARPORT_DEVICES_ROOT_DIR { DEV_PARPORT_DEVICES, "devices", \ | ||
242 | NULL, 0, 0555, NULL } | ||
243 | |||
244 | static const unsigned long parport_min_timeslice_value = | ||
245 | PARPORT_MIN_TIMESLICE_VALUE; | ||
246 | |||
247 | static const unsigned long parport_max_timeslice_value = | ||
248 | PARPORT_MAX_TIMESLICE_VALUE; | ||
249 | |||
250 | static const int parport_min_spintime_value = | ||
251 | PARPORT_MIN_SPINTIME_VALUE; | ||
252 | |||
253 | static const int parport_max_spintime_value = | ||
254 | PARPORT_MAX_SPINTIME_VALUE; | ||
255 | |||
256 | |||
257 | struct parport_sysctl_table { | ||
258 | struct ctl_table_header *sysctl_header; | ||
259 | ctl_table vars[12]; | ||
260 | ctl_table device_dir[2]; | ||
261 | ctl_table port_dir[2]; | ||
262 | ctl_table parport_dir[2]; | ||
263 | ctl_table dev_dir[2]; | ||
264 | }; | ||
265 | |||
266 | static const struct parport_sysctl_table parport_sysctl_template = { | ||
267 | NULL, | ||
268 | { | ||
269 | { DEV_PARPORT_SPINTIME, "spintime", | ||
270 | NULL, sizeof(int), 0644, NULL, | ||
271 | &proc_dointvec_minmax, NULL, NULL, | ||
272 | (void*) &parport_min_spintime_value, | ||
273 | (void*) &parport_max_spintime_value }, | ||
274 | { DEV_PARPORT_BASE_ADDR, "base-addr", | ||
275 | NULL, 0, 0444, NULL, | ||
276 | &do_hardware_base_addr }, | ||
277 | { DEV_PARPORT_IRQ, "irq", | ||
278 | NULL, 0, 0444, NULL, | ||
279 | &do_hardware_irq }, | ||
280 | { DEV_PARPORT_DMA, "dma", | ||
281 | NULL, 0, 0444, NULL, | ||
282 | &do_hardware_dma }, | ||
283 | { DEV_PARPORT_MODES, "modes", | ||
284 | NULL, 0, 0444, NULL, | ||
285 | &do_hardware_modes }, | ||
286 | PARPORT_DEVICES_ROOT_DIR, | ||
287 | #ifdef CONFIG_PARPORT_1284 | ||
288 | { DEV_PARPORT_AUTOPROBE, "autoprobe", | ||
289 | NULL, 0, 0444, NULL, | ||
290 | &do_autoprobe }, | ||
291 | { DEV_PARPORT_AUTOPROBE + 1, "autoprobe0", | ||
292 | NULL, 0, 0444, NULL, | ||
293 | &do_autoprobe }, | ||
294 | { DEV_PARPORT_AUTOPROBE + 2, "autoprobe1", | ||
295 | NULL, 0, 0444, NULL, | ||
296 | &do_autoprobe }, | ||
297 | { DEV_PARPORT_AUTOPROBE + 3, "autoprobe2", | ||
298 | NULL, 0, 0444, NULL, | ||
299 | &do_autoprobe }, | ||
300 | { DEV_PARPORT_AUTOPROBE + 4, "autoprobe3", | ||
301 | NULL, 0, 0444, NULL, | ||
302 | &do_autoprobe }, | ||
303 | #endif /* IEEE 1284 support */ | ||
304 | {0} | ||
305 | }, | ||
306 | { {DEV_PARPORT_DEVICES_ACTIVE, "active", NULL, 0, 0444, NULL, | ||
307 | &do_active_device }, {0}}, | ||
308 | { PARPORT_PORT_DIR(NULL), {0}}, | ||
309 | { PARPORT_PARPORT_DIR(NULL), {0}}, | ||
310 | { PARPORT_DEV_DIR(NULL), {0}} | ||
311 | }; | ||
312 | |||
313 | struct parport_device_sysctl_table | ||
314 | { | ||
315 | struct ctl_table_header *sysctl_header; | ||
316 | ctl_table vars[2]; | ||
317 | ctl_table device_dir[2]; | ||
318 | ctl_table devices_root_dir[2]; | ||
319 | ctl_table port_dir[2]; | ||
320 | ctl_table parport_dir[2]; | ||
321 | ctl_table dev_dir[2]; | ||
322 | }; | ||
323 | |||
324 | static const struct parport_device_sysctl_table | ||
325 | parport_device_sysctl_template = { | ||
326 | NULL, | ||
327 | { | ||
328 | { DEV_PARPORT_DEVICE_TIMESLICE, "timeslice", | ||
329 | NULL, sizeof(int), 0644, NULL, | ||
330 | &proc_doulongvec_ms_jiffies_minmax, NULL, NULL, | ||
331 | (void*) &parport_min_timeslice_value, | ||
332 | (void*) &parport_max_timeslice_value }, | ||
333 | }, | ||
334 | { {0, NULL, NULL, 0, 0555, NULL}, {0}}, | ||
335 | { PARPORT_DEVICES_ROOT_DIR, {0}}, | ||
336 | { PARPORT_PORT_DIR(NULL), {0}}, | ||
337 | { PARPORT_PARPORT_DIR(NULL), {0}}, | ||
338 | { PARPORT_DEV_DIR(NULL), {0}} | ||
339 | }; | ||
340 | |||
341 | struct parport_default_sysctl_table | ||
342 | { | ||
343 | struct ctl_table_header *sysctl_header; | ||
344 | ctl_table vars[3]; | ||
345 | ctl_table default_dir[2]; | ||
346 | ctl_table parport_dir[2]; | ||
347 | ctl_table dev_dir[2]; | ||
348 | }; | ||
349 | |||
350 | extern unsigned long parport_default_timeslice; | ||
351 | extern int parport_default_spintime; | ||
352 | |||
353 | static struct parport_default_sysctl_table | ||
354 | parport_default_sysctl_table = { | ||
355 | NULL, | ||
356 | { | ||
357 | { DEV_PARPORT_DEFAULT_TIMESLICE, "timeslice", | ||
358 | &parport_default_timeslice, | ||
359 | sizeof(parport_default_timeslice), 0644, NULL, | ||
360 | &proc_doulongvec_ms_jiffies_minmax, NULL, NULL, | ||
361 | (void*) &parport_min_timeslice_value, | ||
362 | (void*) &parport_max_timeslice_value }, | ||
363 | { DEV_PARPORT_DEFAULT_SPINTIME, "spintime", | ||
364 | &parport_default_spintime, | ||
365 | sizeof(parport_default_spintime), 0644, NULL, | ||
366 | &proc_dointvec_minmax, NULL, NULL, | ||
367 | (void*) &parport_min_spintime_value, | ||
368 | (void*) &parport_max_spintime_value }, | ||
369 | {0} | ||
370 | }, | ||
371 | { { DEV_PARPORT_DEFAULT, "default", NULL, 0, 0555, | ||
372 | parport_default_sysctl_table.vars },{0}}, | ||
373 | { | ||
374 | PARPORT_PARPORT_DIR(parport_default_sysctl_table.default_dir), | ||
375 | {0}}, | ||
376 | { PARPORT_DEV_DIR(parport_default_sysctl_table.parport_dir), {0}} | ||
377 | }; | ||
378 | |||
379 | |||
380 | int parport_proc_register(struct parport *port) | ||
381 | { | ||
382 | struct parport_sysctl_table *t; | ||
383 | int i; | ||
384 | |||
385 | t = kmalloc(sizeof(*t), GFP_KERNEL); | ||
386 | if (t == NULL) | ||
387 | return -ENOMEM; | ||
388 | memcpy(t, &parport_sysctl_template, sizeof(*t)); | ||
389 | |||
390 | t->device_dir[0].extra1 = port; | ||
391 | |||
392 | for (i = 0; i < 8; i++) | ||
393 | t->vars[i].extra1 = port; | ||
394 | |||
395 | t->vars[0].data = &port->spintime; | ||
396 | t->vars[5].child = t->device_dir; | ||
397 | |||
398 | for (i = 0; i < 5; i++) | ||
399 | t->vars[6 + i].extra2 = &port->probe_info[i]; | ||
400 | |||
401 | t->port_dir[0].procname = port->name; | ||
402 | t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */ | ||
403 | |||
404 | t->port_dir[0].child = t->vars; | ||
405 | t->parport_dir[0].child = t->port_dir; | ||
406 | t->dev_dir[0].child = t->parport_dir; | ||
407 | |||
408 | t->sysctl_header = register_sysctl_table(t->dev_dir, 0); | ||
409 | if (t->sysctl_header == NULL) { | ||
410 | kfree(t); | ||
411 | t = NULL; | ||
412 | } | ||
413 | port->sysctl_table = t; | ||
414 | return 0; | ||
415 | } | ||
416 | |||
417 | int parport_proc_unregister(struct parport *port) | ||
418 | { | ||
419 | if (port->sysctl_table) { | ||
420 | struct parport_sysctl_table *t = port->sysctl_table; | ||
421 | port->sysctl_table = NULL; | ||
422 | unregister_sysctl_table(t->sysctl_header); | ||
423 | kfree(t); | ||
424 | } | ||
425 | return 0; | ||
426 | } | ||
427 | |||
428 | int parport_device_proc_register(struct pardevice *device) | ||
429 | { | ||
430 | struct parport_device_sysctl_table *t; | ||
431 | struct parport * port = device->port; | ||
432 | |||
433 | t = kmalloc(sizeof(*t), GFP_KERNEL); | ||
434 | if (t == NULL) | ||
435 | return -ENOMEM; | ||
436 | memcpy(t, &parport_device_sysctl_template, sizeof(*t)); | ||
437 | |||
438 | t->dev_dir[0].child = t->parport_dir; | ||
439 | t->parport_dir[0].child = t->port_dir; | ||
440 | t->port_dir[0].procname = port->name; | ||
441 | t->port_dir[0].ctl_name = port->number + 1; /* nb 0 isn't legal here */ | ||
442 | t->port_dir[0].child = t->devices_root_dir; | ||
443 | t->devices_root_dir[0].child = t->device_dir; | ||
444 | |||
445 | #ifdef CONFIG_PARPORT_1284 | ||
446 | |||
447 | t->device_dir[0].ctl_name = | ||
448 | parport_device_num(port->number, port->muxport, | ||
449 | device->daisy) | ||
450 | + 1; /* nb 0 isn't legal here */ | ||
451 | |||
452 | #else /* No IEEE 1284 support */ | ||
453 | |||
454 | /* parport_device_num isn't available. */ | ||
455 | t->device_dir[0].ctl_name = 1; | ||
456 | |||
457 | #endif /* IEEE 1284 support or not */ | ||
458 | |||
459 | t->device_dir[0].procname = device->name; | ||
460 | t->device_dir[0].extra1 = device; | ||
461 | t->device_dir[0].child = t->vars; | ||
462 | t->vars[0].data = &device->timeslice; | ||
463 | |||
464 | t->sysctl_header = register_sysctl_table(t->dev_dir, 0); | ||
465 | if (t->sysctl_header == NULL) { | ||
466 | kfree(t); | ||
467 | t = NULL; | ||
468 | } | ||
469 | device->sysctl_table = t; | ||
470 | return 0; | ||
471 | } | ||
472 | |||
473 | int parport_device_proc_unregister(struct pardevice *device) | ||
474 | { | ||
475 | if (device->sysctl_table) { | ||
476 | struct parport_device_sysctl_table *t = device->sysctl_table; | ||
477 | device->sysctl_table = NULL; | ||
478 | unregister_sysctl_table(t->sysctl_header); | ||
479 | kfree(t); | ||
480 | } | ||
481 | return 0; | ||
482 | } | ||
483 | |||
484 | static int __init parport_default_proc_register(void) | ||
485 | { | ||
486 | parport_default_sysctl_table.sysctl_header = | ||
487 | register_sysctl_table(parport_default_sysctl_table.dev_dir, 0); | ||
488 | return 0; | ||
489 | } | ||
490 | |||
491 | static void __exit parport_default_proc_unregister(void) | ||
492 | { | ||
493 | if (parport_default_sysctl_table.sysctl_header) { | ||
494 | unregister_sysctl_table(parport_default_sysctl_table. | ||
495 | sysctl_header); | ||
496 | parport_default_sysctl_table.sysctl_header = NULL; | ||
497 | } | ||
498 | } | ||
499 | |||
500 | #else /* no sysctl or no procfs*/ | ||
501 | |||
502 | int parport_proc_register(struct parport *pp) | ||
503 | { | ||
504 | return 0; | ||
505 | } | ||
506 | |||
507 | int parport_proc_unregister(struct parport *pp) | ||
508 | { | ||
509 | return 0; | ||
510 | } | ||
511 | |||
512 | int parport_device_proc_register(struct pardevice *device) | ||
513 | { | ||
514 | return 0; | ||
515 | } | ||
516 | |||
517 | int parport_device_proc_unregister(struct pardevice *device) | ||
518 | { | ||
519 | return 0; | ||
520 | } | ||
521 | |||
522 | static int __init parport_default_proc_register (void) | ||
523 | { | ||
524 | return 0; | ||
525 | } | ||
526 | |||
527 | static void __exit parport_default_proc_unregister (void) | ||
528 | { | ||
529 | } | ||
530 | #endif | ||
531 | |||
532 | module_init(parport_default_proc_register) | ||
533 | module_exit(parport_default_proc_unregister) | ||
diff --git a/drivers/parport/share.c b/drivers/parport/share.c new file mode 100644 index 000000000000..ae7becf7efa5 --- /dev/null +++ b/drivers/parport/share.c | |||
@@ -0,0 +1,1014 @@ | |||
1 | /* $Id: parport_share.c,v 1.15 1998/01/11 12:06:17 philip Exp $ | ||
2 | * Parallel-port resource manager code. | ||
3 | * | ||
4 | * Authors: David Campbell <campbell@tirian.che.curtin.edu.au> | ||
5 | * Tim Waugh <tim@cyberelk.demon.co.uk> | ||
6 | * Jose Renau <renau@acm.org> | ||
7 | * Philip Blundell <philb@gnu.org> | ||
8 | * Andrea Arcangeli | ||
9 | * | ||
10 | * based on work by Grant Guenther <grant@torque.net> | ||
11 | * and Philip Blundell | ||
12 | * | ||
13 | * Any part of this program may be used in documents licensed under | ||
14 | * the GNU Free Documentation License, Version 1.1 or any later version | ||
15 | * published by the Free Software Foundation. | ||
16 | */ | ||
17 | |||
18 | #undef PARPORT_DEBUG_SHARING /* undef for production */ | ||
19 | |||
20 | #include <linux/config.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/threads.h> | ||
24 | #include <linux/parport.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/errno.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/ioport.h> | ||
29 | #include <linux/kernel.h> | ||
30 | #include <linux/slab.h> | ||
31 | #include <linux/sched.h> | ||
32 | #include <linux/kmod.h> | ||
33 | |||
34 | #include <linux/spinlock.h> | ||
35 | #include <asm/irq.h> | ||
36 | |||
37 | #undef PARPORT_PARANOID | ||
38 | |||
39 | #define PARPORT_DEFAULT_TIMESLICE (HZ/5) | ||
40 | |||
41 | unsigned long parport_default_timeslice = PARPORT_DEFAULT_TIMESLICE; | ||
42 | int parport_default_spintime = DEFAULT_SPIN_TIME; | ||
43 | |||
44 | static LIST_HEAD(portlist); | ||
45 | static DEFINE_SPINLOCK(parportlist_lock); | ||
46 | |||
47 | /* list of all allocated ports, sorted by ->number */ | ||
48 | static LIST_HEAD(all_ports); | ||
49 | static DEFINE_SPINLOCK(full_list_lock); | ||
50 | |||
51 | static LIST_HEAD(drivers); | ||
52 | |||
53 | static DECLARE_MUTEX(registration_lock); | ||
54 | |||
55 | /* What you can do to a port that's gone away.. */ | ||
56 | static void dead_write_lines (struct parport *p, unsigned char b){} | ||
57 | static unsigned char dead_read_lines (struct parport *p) { return 0; } | ||
58 | static unsigned char dead_frob_lines (struct parport *p, unsigned char b, | ||
59 | unsigned char c) { return 0; } | ||
60 | static void dead_onearg (struct parport *p){} | ||
61 | static void dead_initstate (struct pardevice *d, struct parport_state *s) { } | ||
62 | static void dead_state (struct parport *p, struct parport_state *s) { } | ||
63 | static size_t dead_write (struct parport *p, const void *b, size_t l, int f) | ||
64 | { return 0; } | ||
65 | static size_t dead_read (struct parport *p, void *b, size_t l, int f) | ||
66 | { return 0; } | ||
67 | static struct parport_operations dead_ops = { | ||
68 | .write_data = dead_write_lines, /* data */ | ||
69 | .read_data = dead_read_lines, | ||
70 | |||
71 | .write_control = dead_write_lines, /* control */ | ||
72 | .read_control = dead_read_lines, | ||
73 | .frob_control = dead_frob_lines, | ||
74 | |||
75 | .read_status = dead_read_lines, /* status */ | ||
76 | |||
77 | .enable_irq = dead_onearg, /* enable_irq */ | ||
78 | .disable_irq = dead_onearg, /* disable_irq */ | ||
79 | |||
80 | .data_forward = dead_onearg, /* data_forward */ | ||
81 | .data_reverse = dead_onearg, /* data_reverse */ | ||
82 | |||
83 | .init_state = dead_initstate, /* init_state */ | ||
84 | .save_state = dead_state, | ||
85 | .restore_state = dead_state, | ||
86 | |||
87 | .epp_write_data = dead_write, /* epp */ | ||
88 | .epp_read_data = dead_read, | ||
89 | .epp_write_addr = dead_write, | ||
90 | .epp_read_addr = dead_read, | ||
91 | |||
92 | .ecp_write_data = dead_write, /* ecp */ | ||
93 | .ecp_read_data = dead_read, | ||
94 | .ecp_write_addr = dead_write, | ||
95 | |||
96 | .compat_write_data = dead_write, /* compat */ | ||
97 | .nibble_read_data = dead_read, /* nibble */ | ||
98 | .byte_read_data = dead_read, /* byte */ | ||
99 | |||
100 | .owner = NULL, | ||
101 | }; | ||
102 | |||
103 | /* Call attach(port) for each registered driver. */ | ||
104 | static void attach_driver_chain(struct parport *port) | ||
105 | { | ||
106 | /* caller has exclusive registration_lock */ | ||
107 | struct parport_driver *drv; | ||
108 | list_for_each_entry(drv, &drivers, list) | ||
109 | drv->attach(port); | ||
110 | } | ||
111 | |||
112 | /* Call detach(port) for each registered driver. */ | ||
113 | static void detach_driver_chain(struct parport *port) | ||
114 | { | ||
115 | struct parport_driver *drv; | ||
116 | /* caller has exclusive registration_lock */ | ||
117 | list_for_each_entry(drv, &drivers, list) | ||
118 | drv->detach (port); | ||
119 | } | ||
120 | |||
121 | /* Ask kmod for some lowlevel drivers. */ | ||
122 | static void get_lowlevel_driver (void) | ||
123 | { | ||
124 | /* There is no actual module called this: you should set | ||
125 | * up an alias for modutils. */ | ||
126 | request_module ("parport_lowlevel"); | ||
127 | } | ||
128 | |||
129 | /** | ||
130 | * parport_register_driver - register a parallel port device driver | ||
131 | * @drv: structure describing the driver | ||
132 | * | ||
133 | * This can be called by a parallel port device driver in order | ||
134 | * to receive notifications about ports being found in the | ||
135 | * system, as well as ports no longer available. | ||
136 | * | ||
137 | * The @drv structure is allocated by the caller and must not be | ||
138 | * deallocated until after calling parport_unregister_driver(). | ||
139 | * | ||
140 | * The driver's attach() function may block. The port that | ||
141 | * attach() is given will be valid for the duration of the | ||
142 | * callback, but if the driver wants to take a copy of the | ||
143 | * pointer it must call parport_get_port() to do so. Calling | ||
144 | * parport_register_device() on that port will do this for you. | ||
145 | * | ||
146 | * The driver's detach() function may block. The port that | ||
147 | * detach() is given will be valid for the duration of the | ||
148 | * callback, but if the driver wants to take a copy of the | ||
149 | * pointer it must call parport_get_port() to do so. | ||
150 | * | ||
151 | * Returns 0 on success. Currently it always succeeds. | ||
152 | **/ | ||
153 | |||
154 | int parport_register_driver (struct parport_driver *drv) | ||
155 | { | ||
156 | struct parport *port; | ||
157 | |||
158 | if (list_empty(&portlist)) | ||
159 | get_lowlevel_driver (); | ||
160 | |||
161 | down(®istration_lock); | ||
162 | list_for_each_entry(port, &portlist, list) | ||
163 | drv->attach(port); | ||
164 | list_add(&drv->list, &drivers); | ||
165 | up(®istration_lock); | ||
166 | |||
167 | return 0; | ||
168 | } | ||
169 | |||
170 | /** | ||
171 | * parport_unregister_driver - deregister a parallel port device driver | ||
172 | * @drv: structure describing the driver that was given to | ||
173 | * parport_register_driver() | ||
174 | * | ||
175 | * This should be called by a parallel port device driver that | ||
176 | * has registered itself using parport_register_driver() when it | ||
177 | * is about to be unloaded. | ||
178 | * | ||
179 | * When it returns, the driver's attach() routine will no longer | ||
180 | * be called, and for each port that attach() was called for, the | ||
181 | * detach() routine will have been called. | ||
182 | * | ||
183 | * All the driver's attach() and detach() calls are guaranteed to have | ||
184 | * finished by the time this function returns. | ||
185 | **/ | ||
186 | |||
187 | void parport_unregister_driver (struct parport_driver *drv) | ||
188 | { | ||
189 | struct parport *port; | ||
190 | |||
191 | down(®istration_lock); | ||
192 | list_del_init(&drv->list); | ||
193 | list_for_each_entry(port, &portlist, list) | ||
194 | drv->detach(port); | ||
195 | up(®istration_lock); | ||
196 | } | ||
197 | |||
198 | static void free_port (struct parport *port) | ||
199 | { | ||
200 | int d; | ||
201 | spin_lock(&full_list_lock); | ||
202 | list_del(&port->full_list); | ||
203 | spin_unlock(&full_list_lock); | ||
204 | for (d = 0; d < 5; d++) { | ||
205 | if (port->probe_info[d].class_name) | ||
206 | kfree (port->probe_info[d].class_name); | ||
207 | if (port->probe_info[d].mfr) | ||
208 | kfree (port->probe_info[d].mfr); | ||
209 | if (port->probe_info[d].model) | ||
210 | kfree (port->probe_info[d].model); | ||
211 | if (port->probe_info[d].cmdset) | ||
212 | kfree (port->probe_info[d].cmdset); | ||
213 | if (port->probe_info[d].description) | ||
214 | kfree (port->probe_info[d].description); | ||
215 | } | ||
216 | |||
217 | kfree(port->name); | ||
218 | kfree(port); | ||
219 | } | ||
220 | |||
221 | /** | ||
222 | * parport_get_port - increment a port's reference count | ||
223 | * @port: the port | ||
224 | * | ||
225 | * This ensure's that a struct parport pointer remains valid | ||
226 | * until the matching parport_put_port() call. | ||
227 | **/ | ||
228 | |||
229 | struct parport *parport_get_port (struct parport *port) | ||
230 | { | ||
231 | atomic_inc (&port->ref_count); | ||
232 | return port; | ||
233 | } | ||
234 | |||
235 | /** | ||
236 | * parport_put_port - decrement a port's reference count | ||
237 | * @port: the port | ||
238 | * | ||
239 | * This should be called once for each call to parport_get_port(), | ||
240 | * once the port is no longer needed. | ||
241 | **/ | ||
242 | |||
243 | void parport_put_port (struct parport *port) | ||
244 | { | ||
245 | if (atomic_dec_and_test (&port->ref_count)) | ||
246 | /* Can destroy it now. */ | ||
247 | free_port (port); | ||
248 | |||
249 | return; | ||
250 | } | ||
251 | |||
252 | /** | ||
253 | * parport_register_port - register a parallel port | ||
254 | * @base: base I/O address | ||
255 | * @irq: IRQ line | ||
256 | * @dma: DMA channel | ||
257 | * @ops: pointer to the port driver's port operations structure | ||
258 | * | ||
259 | * When a parallel port (lowlevel) driver finds a port that | ||
260 | * should be made available to parallel port device drivers, it | ||
261 | * should call parport_register_port(). The @base, @irq, and | ||
262 | * @dma parameters are for the convenience of port drivers, and | ||
263 | * for ports where they aren't meaningful needn't be set to | ||
264 | * anything special. They can be altered afterwards by adjusting | ||
265 | * the relevant members of the parport structure that is returned | ||
266 | * and represents the port. They should not be tampered with | ||
267 | * after calling parport_announce_port, however. | ||
268 | * | ||
269 | * If there are parallel port device drivers in the system that | ||
270 | * have registered themselves using parport_register_driver(), | ||
271 | * they are not told about the port at this time; that is done by | ||
272 | * parport_announce_port(). | ||
273 | * | ||
274 | * The @ops structure is allocated by the caller, and must not be | ||
275 | * deallocated before calling parport_remove_port(). | ||
276 | * | ||
277 | * If there is no memory to allocate a new parport structure, | ||
278 | * this function will return %NULL. | ||
279 | **/ | ||
280 | |||
281 | struct parport *parport_register_port(unsigned long base, int irq, int dma, | ||
282 | struct parport_operations *ops) | ||
283 | { | ||
284 | struct list_head *l; | ||
285 | struct parport *tmp; | ||
286 | int num; | ||
287 | int device; | ||
288 | char *name; | ||
289 | |||
290 | tmp = kmalloc(sizeof(struct parport), GFP_KERNEL); | ||
291 | if (!tmp) { | ||
292 | printk(KERN_WARNING "parport: memory squeeze\n"); | ||
293 | return NULL; | ||
294 | } | ||
295 | |||
296 | /* Init our structure */ | ||
297 | memset(tmp, 0, sizeof(struct parport)); | ||
298 | tmp->base = base; | ||
299 | tmp->irq = irq; | ||
300 | tmp->dma = dma; | ||
301 | tmp->muxport = tmp->daisy = tmp->muxsel = -1; | ||
302 | tmp->modes = 0; | ||
303 | INIT_LIST_HEAD(&tmp->list); | ||
304 | tmp->devices = tmp->cad = NULL; | ||
305 | tmp->flags = 0; | ||
306 | tmp->ops = ops; | ||
307 | tmp->physport = tmp; | ||
308 | memset (tmp->probe_info, 0, 5 * sizeof (struct parport_device_info)); | ||
309 | rwlock_init(&tmp->cad_lock); | ||
310 | spin_lock_init(&tmp->waitlist_lock); | ||
311 | spin_lock_init(&tmp->pardevice_lock); | ||
312 | tmp->ieee1284.mode = IEEE1284_MODE_COMPAT; | ||
313 | tmp->ieee1284.phase = IEEE1284_PH_FWD_IDLE; | ||
314 | init_MUTEX_LOCKED (&tmp->ieee1284.irq); /* actually a semaphore at 0 */ | ||
315 | tmp->spintime = parport_default_spintime; | ||
316 | atomic_set (&tmp->ref_count, 1); | ||
317 | INIT_LIST_HEAD(&tmp->full_list); | ||
318 | |||
319 | name = kmalloc(15, GFP_KERNEL); | ||
320 | if (!name) { | ||
321 | printk(KERN_ERR "parport: memory squeeze\n"); | ||
322 | kfree(tmp); | ||
323 | return NULL; | ||
324 | } | ||
325 | /* Search for the lowest free parport number. */ | ||
326 | |||
327 | spin_lock(&full_list_lock); | ||
328 | for (l = all_ports.next, num = 0; l != &all_ports; l = l->next, num++) { | ||
329 | struct parport *p = list_entry(l, struct parport, full_list); | ||
330 | if (p->number != num) | ||
331 | break; | ||
332 | } | ||
333 | tmp->portnum = tmp->number = num; | ||
334 | list_add_tail(&tmp->full_list, l); | ||
335 | spin_unlock(&full_list_lock); | ||
336 | |||
337 | /* | ||
338 | * Now that the portnum is known finish doing the Init. | ||
339 | */ | ||
340 | sprintf(name, "parport%d", tmp->portnum = tmp->number); | ||
341 | tmp->name = name; | ||
342 | |||
343 | for (device = 0; device < 5; device++) | ||
344 | /* assume the worst */ | ||
345 | tmp->probe_info[device].class = PARPORT_CLASS_LEGACY; | ||
346 | |||
347 | tmp->waithead = tmp->waittail = NULL; | ||
348 | |||
349 | return tmp; | ||
350 | } | ||
351 | |||
352 | /** | ||
353 | * parport_announce_port - tell device drivers about a parallel port | ||
354 | * @port: parallel port to announce | ||
355 | * | ||
356 | * After a port driver has registered a parallel port with | ||
357 | * parport_register_port, and performed any necessary | ||
358 | * initialisation or adjustments, it should call | ||
359 | * parport_announce_port() in order to notify all device drivers | ||
360 | * that have called parport_register_driver(). Their attach() | ||
361 | * functions will be called, with @port as the parameter. | ||
362 | **/ | ||
363 | |||
364 | void parport_announce_port (struct parport *port) | ||
365 | { | ||
366 | int i; | ||
367 | |||
368 | #ifdef CONFIG_PARPORT_1284 | ||
369 | /* Analyse the IEEE1284.3 topology of the port. */ | ||
370 | parport_daisy_init(port); | ||
371 | #endif | ||
372 | |||
373 | parport_proc_register(port); | ||
374 | down(®istration_lock); | ||
375 | spin_lock_irq(&parportlist_lock); | ||
376 | list_add_tail(&port->list, &portlist); | ||
377 | for (i = 1; i < 3; i++) { | ||
378 | struct parport *slave = port->slaves[i-1]; | ||
379 | if (slave) | ||
380 | list_add_tail(&slave->list, &portlist); | ||
381 | } | ||
382 | spin_unlock_irq(&parportlist_lock); | ||
383 | |||
384 | /* Let drivers know that new port(s) has arrived. */ | ||
385 | attach_driver_chain (port); | ||
386 | for (i = 1; i < 3; i++) { | ||
387 | struct parport *slave = port->slaves[i-1]; | ||
388 | if (slave) | ||
389 | attach_driver_chain(slave); | ||
390 | } | ||
391 | up(®istration_lock); | ||
392 | } | ||
393 | |||
394 | /** | ||
395 | * parport_remove_port - deregister a parallel port | ||
396 | * @port: parallel port to deregister | ||
397 | * | ||
398 | * When a parallel port driver is forcibly unloaded, or a | ||
399 | * parallel port becomes inaccessible, the port driver must call | ||
400 | * this function in order to deal with device drivers that still | ||
401 | * want to use it. | ||
402 | * | ||
403 | * The parport structure associated with the port has its | ||
404 | * operations structure replaced with one containing 'null' | ||
405 | * operations that return errors or just don't do anything. | ||
406 | * | ||
407 | * Any drivers that have registered themselves using | ||
408 | * parport_register_driver() are notified that the port is no | ||
409 | * longer accessible by having their detach() routines called | ||
410 | * with @port as the parameter. | ||
411 | **/ | ||
412 | |||
413 | void parport_remove_port(struct parport *port) | ||
414 | { | ||
415 | int i; | ||
416 | |||
417 | down(®istration_lock); | ||
418 | |||
419 | /* Spread the word. */ | ||
420 | detach_driver_chain (port); | ||
421 | |||
422 | #ifdef CONFIG_PARPORT_1284 | ||
423 | /* Forget the IEEE1284.3 topology of the port. */ | ||
424 | parport_daisy_fini(port); | ||
425 | for (i = 1; i < 3; i++) { | ||
426 | struct parport *slave = port->slaves[i-1]; | ||
427 | if (!slave) | ||
428 | continue; | ||
429 | detach_driver_chain(slave); | ||
430 | parport_daisy_fini(slave); | ||
431 | } | ||
432 | #endif | ||
433 | |||
434 | port->ops = &dead_ops; | ||
435 | spin_lock(&parportlist_lock); | ||
436 | list_del_init(&port->list); | ||
437 | for (i = 1; i < 3; i++) { | ||
438 | struct parport *slave = port->slaves[i-1]; | ||
439 | if (slave) | ||
440 | list_del_init(&slave->list); | ||
441 | } | ||
442 | spin_unlock(&parportlist_lock); | ||
443 | |||
444 | up(®istration_lock); | ||
445 | |||
446 | parport_proc_unregister(port); | ||
447 | |||
448 | for (i = 1; i < 3; i++) { | ||
449 | struct parport *slave = port->slaves[i-1]; | ||
450 | if (slave) | ||
451 | parport_put_port(slave); | ||
452 | } | ||
453 | } | ||
454 | |||
455 | /** | ||
456 | * parport_register_device - register a device on a parallel port | ||
457 | * @port: port to which the device is attached | ||
458 | * @name: a name to refer to the device | ||
459 | * @pf: preemption callback | ||
460 | * @kf: kick callback (wake-up) | ||
461 | * @irq_func: interrupt handler | ||
462 | * @flags: registration flags | ||
463 | * @handle: data for callback functions | ||
464 | * | ||
465 | * This function, called by parallel port device drivers, | ||
466 | * declares that a device is connected to a port, and tells the | ||
467 | * system all it needs to know. | ||
468 | * | ||
469 | * The @name is allocated by the caller and must not be | ||
470 | * deallocated until the caller calls @parport_unregister_device | ||
471 | * for that device. | ||
472 | * | ||
473 | * The preemption callback function, @pf, is called when this | ||
474 | * device driver has claimed access to the port but another | ||
475 | * device driver wants to use it. It is given @handle as its | ||
476 | * parameter, and should return zero if it is willing for the | ||
477 | * system to release the port to another driver on its behalf. | ||
478 | * If it wants to keep control of the port it should return | ||
479 | * non-zero, and no action will be taken. It is good manners for | ||
480 | * the driver to try to release the port at the earliest | ||
481 | * opportunity after its preemption callback rejects a preemption | ||
482 | * attempt. Note that if a preemption callback is happy for | ||
483 | * preemption to go ahead, there is no need to release the port; | ||
484 | * it is done automatically. This function may not block, as it | ||
485 | * may be called from interrupt context. If the device driver | ||
486 | * does not support preemption, @pf can be %NULL. | ||
487 | * | ||
488 | * The wake-up ("kick") callback function, @kf, is called when | ||
489 | * the port is available to be claimed for exclusive access; that | ||
490 | * is, parport_claim() is guaranteed to succeed when called from | ||
491 | * inside the wake-up callback function. If the driver wants to | ||
492 | * claim the port it should do so; otherwise, it need not take | ||
493 | * any action. This function may not block, as it may be called | ||
494 | * from interrupt context. If the device driver does not want to | ||
495 | * be explicitly invited to claim the port in this way, @kf can | ||
496 | * be %NULL. | ||
497 | * | ||
498 | * The interrupt handler, @irq_func, is called when an interrupt | ||
499 | * arrives from the parallel port. Note that if a device driver | ||
500 | * wants to use interrupts it should use parport_enable_irq(), | ||
501 | * and can also check the irq member of the parport structure | ||
502 | * representing the port. | ||
503 | * | ||
504 | * The parallel port (lowlevel) driver is the one that has called | ||
505 | * request_irq() and whose interrupt handler is called first. | ||
506 | * This handler does whatever needs to be done to the hardware to | ||
507 | * acknowledge the interrupt (for PC-style ports there is nothing | ||
508 | * special to be done). It then tells the IEEE 1284 code about | ||
509 | * the interrupt, which may involve reacting to an IEEE 1284 | ||
510 | * event depending on the current IEEE 1284 phase. After this, | ||
511 | * it calls @irq_func. Needless to say, @irq_func will be called | ||
512 | * from interrupt context, and may not block. | ||
513 | * | ||
514 | * The %PARPORT_DEV_EXCL flag is for preventing port sharing, and | ||
515 | * so should only be used when sharing the port with other device | ||
516 | * drivers is impossible and would lead to incorrect behaviour. | ||
517 | * Use it sparingly! Normally, @flags will be zero. | ||
518 | * | ||
519 | * This function returns a pointer to a structure that represents | ||
520 | * the device on the port, or %NULL if there is not enough memory | ||
521 | * to allocate space for that structure. | ||
522 | **/ | ||
523 | |||
524 | struct pardevice * | ||
525 | parport_register_device(struct parport *port, const char *name, | ||
526 | int (*pf)(void *), void (*kf)(void *), | ||
527 | void (*irq_func)(int, void *, struct pt_regs *), | ||
528 | int flags, void *handle) | ||
529 | { | ||
530 | struct pardevice *tmp; | ||
531 | |||
532 | if (port->physport->flags & PARPORT_FLAG_EXCL) { | ||
533 | /* An exclusive device is registered. */ | ||
534 | printk (KERN_DEBUG "%s: no more devices allowed\n", | ||
535 | port->name); | ||
536 | return NULL; | ||
537 | } | ||
538 | |||
539 | if (flags & PARPORT_DEV_LURK) { | ||
540 | if (!pf || !kf) { | ||
541 | printk(KERN_INFO "%s: refused to register lurking device (%s) without callbacks\n", port->name, name); | ||
542 | return NULL; | ||
543 | } | ||
544 | } | ||
545 | |||
546 | /* We up our own module reference count, and that of the port | ||
547 | on which a device is to be registered, to ensure that | ||
548 | neither of us gets unloaded while we sleep in (e.g.) | ||
549 | kmalloc. | ||
550 | */ | ||
551 | if (!try_module_get(port->ops->owner)) { | ||
552 | return NULL; | ||
553 | } | ||
554 | |||
555 | parport_get_port (port); | ||
556 | |||
557 | tmp = kmalloc(sizeof(struct pardevice), GFP_KERNEL); | ||
558 | if (tmp == NULL) { | ||
559 | printk(KERN_WARNING "%s: memory squeeze, couldn't register %s.\n", port->name, name); | ||
560 | goto out; | ||
561 | } | ||
562 | |||
563 | tmp->state = kmalloc(sizeof(struct parport_state), GFP_KERNEL); | ||
564 | if (tmp->state == NULL) { | ||
565 | printk(KERN_WARNING "%s: memory squeeze, couldn't register %s.\n", port->name, name); | ||
566 | goto out_free_pardevice; | ||
567 | } | ||
568 | |||
569 | tmp->name = name; | ||
570 | tmp->port = port; | ||
571 | tmp->daisy = -1; | ||
572 | tmp->preempt = pf; | ||
573 | tmp->wakeup = kf; | ||
574 | tmp->private = handle; | ||
575 | tmp->flags = flags; | ||
576 | tmp->irq_func = irq_func; | ||
577 | tmp->waiting = 0; | ||
578 | tmp->timeout = 5 * HZ; | ||
579 | |||
580 | /* Chain this onto the list */ | ||
581 | tmp->prev = NULL; | ||
582 | /* | ||
583 | * This function must not run from an irq handler so we don' t need | ||
584 | * to clear irq on the local CPU. -arca | ||
585 | */ | ||
586 | spin_lock(&port->physport->pardevice_lock); | ||
587 | |||
588 | if (flags & PARPORT_DEV_EXCL) { | ||
589 | if (port->physport->devices) { | ||
590 | spin_unlock (&port->physport->pardevice_lock); | ||
591 | printk (KERN_DEBUG | ||
592 | "%s: cannot grant exclusive access for " | ||
593 | "device %s\n", port->name, name); | ||
594 | goto out_free_all; | ||
595 | } | ||
596 | port->flags |= PARPORT_FLAG_EXCL; | ||
597 | } | ||
598 | |||
599 | tmp->next = port->physport->devices; | ||
600 | wmb(); /* Make sure that tmp->next is written before it's | ||
601 | added to the list; see comments marked 'no locking | ||
602 | required' */ | ||
603 | if (port->physport->devices) | ||
604 | port->physport->devices->prev = tmp; | ||
605 | port->physport->devices = tmp; | ||
606 | spin_unlock(&port->physport->pardevice_lock); | ||
607 | |||
608 | init_waitqueue_head(&tmp->wait_q); | ||
609 | tmp->timeslice = parport_default_timeslice; | ||
610 | tmp->waitnext = tmp->waitprev = NULL; | ||
611 | |||
612 | /* | ||
613 | * This has to be run as last thing since init_state may need other | ||
614 | * pardevice fields. -arca | ||
615 | */ | ||
616 | port->ops->init_state(tmp, tmp->state); | ||
617 | parport_device_proc_register(tmp); | ||
618 | return tmp; | ||
619 | |||
620 | out_free_all: | ||
621 | kfree (tmp->state); | ||
622 | out_free_pardevice: | ||
623 | kfree (tmp); | ||
624 | out: | ||
625 | parport_put_port (port); | ||
626 | module_put(port->ops->owner); | ||
627 | |||
628 | return NULL; | ||
629 | } | ||
630 | |||
631 | /** | ||
632 | * parport_unregister_device - deregister a device on a parallel port | ||
633 | * @dev: pointer to structure representing device | ||
634 | * | ||
635 | * This undoes the effect of parport_register_device(). | ||
636 | **/ | ||
637 | |||
638 | void parport_unregister_device(struct pardevice *dev) | ||
639 | { | ||
640 | struct parport *port; | ||
641 | |||
642 | #ifdef PARPORT_PARANOID | ||
643 | if (dev == NULL) { | ||
644 | printk(KERN_ERR "parport_unregister_device: passed NULL\n"); | ||
645 | return; | ||
646 | } | ||
647 | #endif | ||
648 | |||
649 | parport_device_proc_unregister(dev); | ||
650 | |||
651 | port = dev->port->physport; | ||
652 | |||
653 | if (port->cad == dev) { | ||
654 | printk(KERN_DEBUG "%s: %s forgot to release port\n", | ||
655 | port->name, dev->name); | ||
656 | parport_release (dev); | ||
657 | } | ||
658 | |||
659 | spin_lock(&port->pardevice_lock); | ||
660 | if (dev->next) | ||
661 | dev->next->prev = dev->prev; | ||
662 | if (dev->prev) | ||
663 | dev->prev->next = dev->next; | ||
664 | else | ||
665 | port->devices = dev->next; | ||
666 | |||
667 | if (dev->flags & PARPORT_DEV_EXCL) | ||
668 | port->flags &= ~PARPORT_FLAG_EXCL; | ||
669 | |||
670 | spin_unlock(&port->pardevice_lock); | ||
671 | |||
672 | /* Make sure we haven't left any pointers around in the wait | ||
673 | * list. */ | ||
674 | spin_lock (&port->waitlist_lock); | ||
675 | if (dev->waitprev || dev->waitnext || port->waithead == dev) { | ||
676 | if (dev->waitprev) | ||
677 | dev->waitprev->waitnext = dev->waitnext; | ||
678 | else | ||
679 | port->waithead = dev->waitnext; | ||
680 | if (dev->waitnext) | ||
681 | dev->waitnext->waitprev = dev->waitprev; | ||
682 | else | ||
683 | port->waittail = dev->waitprev; | ||
684 | } | ||
685 | spin_unlock (&port->waitlist_lock); | ||
686 | |||
687 | kfree(dev->state); | ||
688 | kfree(dev); | ||
689 | |||
690 | module_put(port->ops->owner); | ||
691 | parport_put_port (port); | ||
692 | } | ||
693 | |||
694 | /** | ||
695 | * parport_find_number - find a parallel port by number | ||
696 | * @number: parallel port number | ||
697 | * | ||
698 | * This returns the parallel port with the specified number, or | ||
699 | * %NULL if there is none. | ||
700 | * | ||
701 | * There is an implicit parport_get_port() done already; to throw | ||
702 | * away the reference to the port that parport_find_number() | ||
703 | * gives you, use parport_put_port(). | ||
704 | */ | ||
705 | |||
706 | struct parport *parport_find_number (int number) | ||
707 | { | ||
708 | struct parport *port, *result = NULL; | ||
709 | |||
710 | if (list_empty(&portlist)) | ||
711 | get_lowlevel_driver (); | ||
712 | |||
713 | spin_lock (&parportlist_lock); | ||
714 | list_for_each_entry(port, &portlist, list) { | ||
715 | if (port->number == number) { | ||
716 | result = parport_get_port (port); | ||
717 | break; | ||
718 | } | ||
719 | } | ||
720 | spin_unlock (&parportlist_lock); | ||
721 | return result; | ||
722 | } | ||
723 | |||
724 | /** | ||
725 | * parport_find_base - find a parallel port by base address | ||
726 | * @base: base I/O address | ||
727 | * | ||
728 | * This returns the parallel port with the specified base | ||
729 | * address, or %NULL if there is none. | ||
730 | * | ||
731 | * There is an implicit parport_get_port() done already; to throw | ||
732 | * away the reference to the port that parport_find_base() | ||
733 | * gives you, use parport_put_port(). | ||
734 | */ | ||
735 | |||
736 | struct parport *parport_find_base (unsigned long base) | ||
737 | { | ||
738 | struct parport *port, *result = NULL; | ||
739 | |||
740 | if (list_empty(&portlist)) | ||
741 | get_lowlevel_driver (); | ||
742 | |||
743 | spin_lock (&parportlist_lock); | ||
744 | list_for_each_entry(port, &portlist, list) { | ||
745 | if (port->base == base) { | ||
746 | result = parport_get_port (port); | ||
747 | break; | ||
748 | } | ||
749 | } | ||
750 | spin_unlock (&parportlist_lock); | ||
751 | return result; | ||
752 | } | ||
753 | |||
754 | /** | ||
755 | * parport_claim - claim access to a parallel port device | ||
756 | * @dev: pointer to structure representing a device on the port | ||
757 | * | ||
758 | * This function will not block and so can be used from interrupt | ||
759 | * context. If parport_claim() succeeds in claiming access to | ||
760 | * the port it returns zero and the port is available to use. It | ||
761 | * may fail (returning non-zero) if the port is in use by another | ||
762 | * driver and that driver is not willing to relinquish control of | ||
763 | * the port. | ||
764 | **/ | ||
765 | |||
766 | int parport_claim(struct pardevice *dev) | ||
767 | { | ||
768 | struct pardevice *oldcad; | ||
769 | struct parport *port = dev->port->physport; | ||
770 | unsigned long flags; | ||
771 | |||
772 | if (port->cad == dev) { | ||
773 | printk(KERN_INFO "%s: %s already owner\n", | ||
774 | dev->port->name,dev->name); | ||
775 | return 0; | ||
776 | } | ||
777 | |||
778 | /* Preempt any current device */ | ||
779 | write_lock_irqsave (&port->cad_lock, flags); | ||
780 | if ((oldcad = port->cad) != NULL) { | ||
781 | if (oldcad->preempt) { | ||
782 | if (oldcad->preempt(oldcad->private)) | ||
783 | goto blocked; | ||
784 | port->ops->save_state(port, dev->state); | ||
785 | } else | ||
786 | goto blocked; | ||
787 | |||
788 | if (port->cad != oldcad) { | ||
789 | /* I think we'll actually deadlock rather than | ||
790 | get here, but just in case.. */ | ||
791 | printk(KERN_WARNING | ||
792 | "%s: %s released port when preempted!\n", | ||
793 | port->name, oldcad->name); | ||
794 | if (port->cad) | ||
795 | goto blocked; | ||
796 | } | ||
797 | } | ||
798 | |||
799 | /* Can't fail from now on, so mark ourselves as no longer waiting. */ | ||
800 | if (dev->waiting & 1) { | ||
801 | dev->waiting = 0; | ||
802 | |||
803 | /* Take ourselves out of the wait list again. */ | ||
804 | spin_lock_irq (&port->waitlist_lock); | ||
805 | if (dev->waitprev) | ||
806 | dev->waitprev->waitnext = dev->waitnext; | ||
807 | else | ||
808 | port->waithead = dev->waitnext; | ||
809 | if (dev->waitnext) | ||
810 | dev->waitnext->waitprev = dev->waitprev; | ||
811 | else | ||
812 | port->waittail = dev->waitprev; | ||
813 | spin_unlock_irq (&port->waitlist_lock); | ||
814 | dev->waitprev = dev->waitnext = NULL; | ||
815 | } | ||
816 | |||
817 | /* Now we do the change of devices */ | ||
818 | port->cad = dev; | ||
819 | |||
820 | #ifdef CONFIG_PARPORT_1284 | ||
821 | /* If it's a mux port, select it. */ | ||
822 | if (dev->port->muxport >= 0) { | ||
823 | /* FIXME */ | ||
824 | port->muxsel = dev->port->muxport; | ||
825 | } | ||
826 | |||
827 | /* If it's a daisy chain device, select it. */ | ||
828 | if (dev->daisy >= 0) { | ||
829 | /* This could be lazier. */ | ||
830 | if (!parport_daisy_select (port, dev->daisy, | ||
831 | IEEE1284_MODE_COMPAT)) | ||
832 | port->daisy = dev->daisy; | ||
833 | } | ||
834 | #endif /* IEEE1284.3 support */ | ||
835 | |||
836 | /* Restore control registers */ | ||
837 | port->ops->restore_state(port, dev->state); | ||
838 | write_unlock_irqrestore(&port->cad_lock, flags); | ||
839 | dev->time = jiffies; | ||
840 | return 0; | ||
841 | |||
842 | blocked: | ||
843 | /* If this is the first time we tried to claim the port, register an | ||
844 | interest. This is only allowed for devices sleeping in | ||
845 | parport_claim_or_block(), or those with a wakeup function. */ | ||
846 | |||
847 | /* The cad_lock is still held for writing here */ | ||
848 | if (dev->waiting & 2 || dev->wakeup) { | ||
849 | spin_lock (&port->waitlist_lock); | ||
850 | if (test_and_set_bit(0, &dev->waiting) == 0) { | ||
851 | /* First add ourselves to the end of the wait list. */ | ||
852 | dev->waitnext = NULL; | ||
853 | dev->waitprev = port->waittail; | ||
854 | if (port->waittail) { | ||
855 | port->waittail->waitnext = dev; | ||
856 | port->waittail = dev; | ||
857 | } else | ||
858 | port->waithead = port->waittail = dev; | ||
859 | } | ||
860 | spin_unlock (&port->waitlist_lock); | ||
861 | } | ||
862 | write_unlock_irqrestore (&port->cad_lock, flags); | ||
863 | return -EAGAIN; | ||
864 | } | ||
865 | |||
866 | /** | ||
867 | * parport_claim_or_block - claim access to a parallel port device | ||
868 | * @dev: pointer to structure representing a device on the port | ||
869 | * | ||
870 | * This behaves like parport_claim(), but will block if necessary | ||
871 | * to wait for the port to be free. A return value of 1 | ||
872 | * indicates that it slept; 0 means that it succeeded without | ||
873 | * needing to sleep. A negative error code indicates failure. | ||
874 | **/ | ||
875 | |||
876 | int parport_claim_or_block(struct pardevice *dev) | ||
877 | { | ||
878 | int r; | ||
879 | |||
880 | /* Signal to parport_claim() that we can wait even without a | ||
881 | wakeup function. */ | ||
882 | dev->waiting = 2; | ||
883 | |||
884 | /* Try to claim the port. If this fails, we need to sleep. */ | ||
885 | r = parport_claim(dev); | ||
886 | if (r == -EAGAIN) { | ||
887 | #ifdef PARPORT_DEBUG_SHARING | ||
888 | printk(KERN_DEBUG "%s: parport_claim() returned -EAGAIN\n", dev->name); | ||
889 | #endif | ||
890 | /* | ||
891 | * FIXME!!! Use the proper locking for dev->waiting, | ||
892 | * and make this use the "wait_event_interruptible()" | ||
893 | * interfaces. The cli/sti that used to be here | ||
894 | * did nothing. | ||
895 | * | ||
896 | * See also parport_release() | ||
897 | */ | ||
898 | |||
899 | /* If dev->waiting is clear now, an interrupt | ||
900 | gave us the port and we would deadlock if we slept. */ | ||
901 | if (dev->waiting) { | ||
902 | interruptible_sleep_on (&dev->wait_q); | ||
903 | if (signal_pending (current)) { | ||
904 | return -EINTR; | ||
905 | } | ||
906 | r = 1; | ||
907 | } else { | ||
908 | r = 0; | ||
909 | #ifdef PARPORT_DEBUG_SHARING | ||
910 | printk(KERN_DEBUG "%s: didn't sleep in parport_claim_or_block()\n", | ||
911 | dev->name); | ||
912 | #endif | ||
913 | } | ||
914 | |||
915 | #ifdef PARPORT_DEBUG_SHARING | ||
916 | if (dev->port->physport->cad != dev) | ||
917 | printk(KERN_DEBUG "%s: exiting parport_claim_or_block " | ||
918 | "but %s owns port!\n", dev->name, | ||
919 | dev->port->physport->cad ? | ||
920 | dev->port->physport->cad->name:"nobody"); | ||
921 | #endif | ||
922 | } | ||
923 | dev->waiting = 0; | ||
924 | return r; | ||
925 | } | ||
926 | |||
927 | /** | ||
928 | * parport_release - give up access to a parallel port device | ||
929 | * @dev: pointer to structure representing parallel port device | ||
930 | * | ||
931 | * This function cannot fail, but it should not be called without | ||
932 | * the port claimed. Similarly, if the port is already claimed | ||
933 | * you should not try claiming it again. | ||
934 | **/ | ||
935 | |||
936 | void parport_release(struct pardevice *dev) | ||
937 | { | ||
938 | struct parport *port = dev->port->physport; | ||
939 | struct pardevice *pd; | ||
940 | unsigned long flags; | ||
941 | |||
942 | /* Make sure that dev is the current device */ | ||
943 | write_lock_irqsave(&port->cad_lock, flags); | ||
944 | if (port->cad != dev) { | ||
945 | write_unlock_irqrestore (&port->cad_lock, flags); | ||
946 | printk(KERN_WARNING "%s: %s tried to release parport " | ||
947 | "when not owner\n", port->name, dev->name); | ||
948 | return; | ||
949 | } | ||
950 | |||
951 | #ifdef CONFIG_PARPORT_1284 | ||
952 | /* If this is on a mux port, deselect it. */ | ||
953 | if (dev->port->muxport >= 0) { | ||
954 | /* FIXME */ | ||
955 | port->muxsel = -1; | ||
956 | } | ||
957 | |||
958 | /* If this is a daisy device, deselect it. */ | ||
959 | if (dev->daisy >= 0) { | ||
960 | parport_daisy_deselect_all (port); | ||
961 | port->daisy = -1; | ||
962 | } | ||
963 | #endif | ||
964 | |||
965 | port->cad = NULL; | ||
966 | write_unlock_irqrestore(&port->cad_lock, flags); | ||
967 | |||
968 | /* Save control registers */ | ||
969 | port->ops->save_state(port, dev->state); | ||
970 | |||
971 | /* If anybody is waiting, find out who's been there longest and | ||
972 | then wake them up. (Note: no locking required) */ | ||
973 | /* !!! LOCKING IS NEEDED HERE */ | ||
974 | for (pd = port->waithead; pd; pd = pd->waitnext) { | ||
975 | if (pd->waiting & 2) { /* sleeping in claim_or_block */ | ||
976 | parport_claim(pd); | ||
977 | if (waitqueue_active(&pd->wait_q)) | ||
978 | wake_up_interruptible(&pd->wait_q); | ||
979 | return; | ||
980 | } else if (pd->wakeup) { | ||
981 | pd->wakeup(pd->private); | ||
982 | if (dev->port->cad) /* racy but no matter */ | ||
983 | return; | ||
984 | } else { | ||
985 | printk(KERN_ERR "%s: don't know how to wake %s\n", port->name, pd->name); | ||
986 | } | ||
987 | } | ||
988 | |||
989 | /* Nobody was waiting, so walk the list to see if anyone is | ||
990 | interested in being woken up. (Note: no locking required) */ | ||
991 | /* !!! LOCKING IS NEEDED HERE */ | ||
992 | for (pd = port->devices; (port->cad == NULL) && pd; pd = pd->next) { | ||
993 | if (pd->wakeup && pd != dev) | ||
994 | pd->wakeup(pd->private); | ||
995 | } | ||
996 | } | ||
997 | |||
998 | /* Exported symbols for modules. */ | ||
999 | |||
1000 | EXPORT_SYMBOL(parport_claim); | ||
1001 | EXPORT_SYMBOL(parport_claim_or_block); | ||
1002 | EXPORT_SYMBOL(parport_release); | ||
1003 | EXPORT_SYMBOL(parport_register_port); | ||
1004 | EXPORT_SYMBOL(parport_announce_port); | ||
1005 | EXPORT_SYMBOL(parport_remove_port); | ||
1006 | EXPORT_SYMBOL(parport_register_driver); | ||
1007 | EXPORT_SYMBOL(parport_unregister_driver); | ||
1008 | EXPORT_SYMBOL(parport_register_device); | ||
1009 | EXPORT_SYMBOL(parport_unregister_device); | ||
1010 | EXPORT_SYMBOL(parport_put_port); | ||
1011 | EXPORT_SYMBOL(parport_find_number); | ||
1012 | EXPORT_SYMBOL(parport_find_base); | ||
1013 | |||
1014 | MODULE_LICENSE("GPL"); | ||