2 * Low-level parallel-support for PC-style hardware integrated in the
3 * LASI-Controller (on GSC-Bus) for HP-PARISC Workstations
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.
10 * (C) 1999-2001 by Helge Deller <deller@gmx.de>
13 * based on parport_pc.c by
14 * Grant Guenther <grant@torque.net>
15 * Phil Blundell <Philip.Blundell@pobox.com>
16 * Tim Waugh <tim@cyberelk.demon.co.uk>
17 * Jose Renau <renau@acm.org>
18 * David Campbell <campbell@torque.net>
22 #undef DEBUG /* undef for production */
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>
38 #include <asm/uaccess.h>
39 #include <asm/superio.h>
41 #include <linux/parport.h>
44 #include <asm/hardware.h>
45 #include <asm/parport_gsc.h>
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");
55 * Clear TIMEOUT BIT in EPP MODE
57 * This is also used in SPP detection.
59 static int clear_epp_timeout(struct parport *pb)
63 if (!(parport_gsc_read_status(pb) & 0x01))
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);
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.
84 static void parport_gsc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
86 parport_generic_irq(irq, (struct parport *) dev_id, regs);
89 void parport_gsc_write_data(struct parport *p, unsigned char d)
91 parport_writeb (d, DATA (p));
94 unsigned char parport_gsc_read_data(struct parport *p)
96 unsigned char c = parport_readb (DATA (p));
100 void parport_gsc_write_control(struct parport *p, unsigned char d)
102 const unsigned char wm = (PARPORT_CONTROL_STROBE |
103 PARPORT_CONTROL_AUTOFD |
104 PARPORT_CONTROL_INIT |
105 PARPORT_CONTROL_SELECT);
107 /* Take this out when drivers have adapted to the newer interface. */
109 pr_debug("%s (%s): use data_reverse for this!\n",
110 p->name, p->cad->name);
111 parport_gsc_data_reverse (p);
114 __parport_gsc_frob_control (p, wm, d & wm);
117 unsigned char parport_gsc_read_control(struct parport *p)
119 const unsigned char wm = (PARPORT_CONTROL_STROBE |
120 PARPORT_CONTROL_AUTOFD |
121 PARPORT_CONTROL_INIT |
122 PARPORT_CONTROL_SELECT);
123 const struct parport_gsc_private *priv = p->physport->private_data;
124 return priv->ctr & wm; /* Use soft copy */
127 unsigned char parport_gsc_frob_control (struct parport *p, unsigned char mask,
130 const unsigned char wm = (PARPORT_CONTROL_STROBE |
131 PARPORT_CONTROL_AUTOFD |
132 PARPORT_CONTROL_INIT |
133 PARPORT_CONTROL_SELECT);
135 /* Take this out when drivers have adapted to the newer interface. */
137 pr_debug("%s (%s): use data_%s for this!\n",
138 p->name, p->cad->name,
139 (val & 0x20) ? "reverse" : "forward");
141 parport_gsc_data_reverse (p);
143 parport_gsc_data_forward (p);
146 /* Restrict mask and val to control lines. */
150 return __parport_gsc_frob_control (p, mask, val);
153 unsigned char parport_gsc_read_status(struct parport *p)
155 return parport_readb (STATUS (p));
158 void parport_gsc_disable_irq(struct parport *p)
160 __parport_gsc_frob_control (p, 0x10, 0);
163 void parport_gsc_enable_irq(struct parport *p)
165 __parport_gsc_frob_control (p, 0x10, 0x10);
168 void parport_gsc_data_forward (struct parport *p)
170 __parport_gsc_frob_control (p, 0x20, 0);
173 void parport_gsc_data_reverse (struct parport *p)
175 __parport_gsc_frob_control (p, 0x20, 0x20);
178 void parport_gsc_init_state(struct pardevice *dev, struct parport_state *s)
180 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
183 void parport_gsc_save_state(struct parport *p, struct parport_state *s)
185 s->u.pc.ctr = parport_readb (CONTROL (p));
188 void parport_gsc_restore_state(struct parport *p, struct parport_state *s)
190 parport_writeb (s->u.pc.ctr, CONTROL (p));
193 void parport_gsc_inc_use_count(void)
198 void parport_gsc_dec_use_count(void)
204 struct parport_operations parport_gsc_ops =
206 write_data: parport_gsc_write_data,
207 read_data: parport_gsc_read_data,
209 write_control: parport_gsc_write_control,
210 read_control: parport_gsc_read_control,
211 frob_control: parport_gsc_frob_control,
213 read_status: parport_gsc_read_status,
215 enable_irq: parport_gsc_enable_irq,
216 disable_irq: parport_gsc_disable_irq,
218 data_forward: parport_gsc_data_forward,
219 data_reverse: parport_gsc_data_reverse,
221 init_state: parport_gsc_init_state,
222 save_state: parport_gsc_save_state,
223 restore_state: parport_gsc_restore_state,
225 inc_use_count: parport_gsc_inc_use_count,
226 dec_use_count: parport_gsc_dec_use_count,
228 epp_write_data: parport_ieee1284_epp_write_data,
229 epp_read_data: parport_ieee1284_epp_read_data,
230 epp_write_addr: parport_ieee1284_epp_write_addr,
231 epp_read_addr: parport_ieee1284_epp_read_addr,
233 ecp_write_data: parport_ieee1284_ecp_write_data,
234 ecp_read_data: parport_ieee1284_ecp_read_data,
235 ecp_write_addr: parport_ieee1284_ecp_write_addr,
237 compat_write_data: parport_ieee1284_write_compat,
238 nibble_read_data: parport_ieee1284_read_nibble,
239 byte_read_data: parport_ieee1284_read_byte,
242 /* --- Mode detection ------------------------------------- */
245 * Checks for port existence, all ports support SPP MODE
247 static int __devinit parport_SPP_supported(struct parport *pb)
252 * first clear an eventually pending EPP timeout
253 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
254 * that does not even respond to SPP cycles if an EPP
257 clear_epp_timeout(pb);
259 /* Do a simple read-write test to make sure the port exists. */
261 parport_writeb (w, CONTROL (pb));
263 /* Is there a control register that we can read from? Some
264 * ports don't allow reads, so read_control just returns a
265 * software copy. Some ports _do_ allow reads, so bypass the
266 * software copy here. In addition, some bits aren't
268 r = parport_readb (CONTROL (pb));
269 if ((r & 0xf) == w) {
271 parport_writeb (w, CONTROL (pb));
272 r = parport_readb (CONTROL (pb));
273 parport_writeb (0xc, CONTROL (pb));
275 return PARPORT_MODE_PCSPP;
278 /* Try the data register. The data lines aren't tri-stated at
279 * this stage, so we expect back what we wrote. */
281 parport_gsc_write_data (pb, w);
282 r = parport_gsc_read_data (pb);
285 parport_gsc_write_data (pb, w);
286 r = parport_gsc_read_data (pb);
288 return PARPORT_MODE_PCSPP;
294 /* Detect PS/2 support.
296 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
297 * allows us to read data from the data lines. In theory we would get back
298 * 0xff but any peripheral attached to the port may drag some or all of the
299 * lines down to zero. So if we get back anything that isn't the contents
300 * of the data register we deem PS/2 support to be present.
302 * Some SPP ports have "half PS/2" ability - you can't turn off the line
303 * drivers, but an external peripheral with sufficiently beefy drivers of
304 * its own can overpower them and assert its own levels onto the bus, from
305 * where they can then be read back as normal. Ports with this property
306 * and the right type of device attached are likely to fail the SPP test,
307 * (as they will appear to have stuck bits) and so the fact that they might
308 * be misdetected here is rather academic.
311 static int __devinit parport_PS2_supported(struct parport *pb)
315 clear_epp_timeout(pb);
317 /* try to tri-state the buffer */
318 parport_gsc_data_reverse (pb);
320 parport_gsc_write_data(pb, 0x55);
321 if (parport_gsc_read_data(pb) != 0x55) ok++;
323 parport_gsc_write_data(pb, 0xaa);
324 if (parport_gsc_read_data(pb) != 0xaa) ok++;
326 /* cancel input mode */
327 parport_gsc_data_forward (pb);
330 pb->modes |= PARPORT_MODE_TRISTATE;
332 struct parport_gsc_private *priv = pb->private_data;
333 priv->ctr_writable &= ~0x20;
340 /* --- Initialisation code -------------------------------- */
342 struct parport *__devinit parport_gsc_probe_port (unsigned long base,
343 unsigned long base_hi,
347 struct parport_gsc_private *priv;
348 struct parport_operations *ops;
350 struct parport *p = &tmp;
352 priv = kmalloc (sizeof (struct parport_gsc_private), GFP_KERNEL);
354 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
357 ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
359 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
364 memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
366 priv->ctr_writable = 0xff;
368 priv->dma_handle = 0;
371 p->base_hi = base_hi;
374 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
376 p->private_data = priv;
378 if (!parport_SPP_supported (p)) {
383 parport_PS2_supported (p);
385 if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
386 PARPORT_DMA_NONE, ops))) {
392 p->base_hi = base_hi;
393 p->modes = tmp.modes;
394 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
395 p->private_data = priv;
397 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
399 if (p->irq == PARPORT_IRQ_AUTO) {
400 p->irq = PARPORT_IRQ_NONE;
402 if (p->irq != PARPORT_IRQ_NONE) {
403 printk(", irq %d", p->irq);
405 if (p->dma == PARPORT_DMA_AUTO) {
406 p->dma = PARPORT_DMA_NONE;
409 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
410 is mandatory (see above) */
411 p->dma = PARPORT_DMA_NONE;
414 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
426 parport_proc_register(p);
428 if (p->irq != PARPORT_IRQ_NONE) {
429 if (request_irq (p->irq, parport_gsc_interrupt,
431 printk (KERN_WARNING "%s: irq %d in use, "
432 "resorting to polled operation\n",
434 p->irq = PARPORT_IRQ_NONE;
435 p->dma = PARPORT_DMA_NONE;
439 /* Done probing. Now put the port into a sensible start-up state. */
441 parport_gsc_write_data(p, 0);
442 parport_gsc_data_forward (p);
444 /* Now that we've told the sharing engine about the port, and
445 found out its characteristics, let the high-level drivers
447 parport_announce_port (p);
453 #define PARPORT_GSC_OFFSET 0x800
455 static int __initdata parport_count;
457 static int __devinit parport_init_chip(struct parisc_device *dev)
462 printk("IRQ not found for parallel device at 0x%lx\n", dev->hpa);
466 port = dev->hpa + PARPORT_GSC_OFFSET;
468 /* some older machines with ASP-chip don't support
469 * the enhanced parport modes.
471 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) {
473 /* Initialize bidirectional-mode (0x10) & data-tranfer-mode #1 (0x20) */
474 printk("%s: initialize bidirectional-mode.\n", __FUNCTION__);
475 parport_writeb ( (0x10 + 0x20), port + 4);
478 printk("%s: enhanced parport-modes not supported.\n", __FUNCTION__);
481 if (parport_gsc_probe_port(port, 0, dev->irq,
482 /* PARPORT_IRQ_NONE */ PARPORT_DMA_NONE, NULL))
488 static struct parisc_device_id parport_tbl[] = {
489 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x74 },
493 MODULE_DEVICE_TABLE(parisc, parport_tbl);
495 static struct parisc_driver parport_driver = {
497 id_table: parport_tbl,
498 probe: parport_init_chip,
501 int __devinit parport_gsc_init(void)
503 return register_parisc_driver(&parport_driver);
506 static void __devexit parport_gsc_exit(void)
508 struct parport *p = parport_enumerate(), *tmp;
511 if (p->modes & PARPORT_MODE_PCSPP) {
512 struct parport_gsc_private *priv = p->private_data;
513 struct parport_operations *ops = p->ops;
514 if (p->dma != PARPORT_DMA_NONE)
516 if (p->irq != PARPORT_IRQ_NONE)
518 parport_proc_unregister(p);
520 pci_free_consistent(priv->dev, PAGE_SIZE,
523 kfree (p->private_data);
524 parport_unregister_port(p);
525 kfree (ops); /* hope no-one cached it */
529 unregister_parisc_driver(&parport_driver);
534 module_init(parport_gsc_init);
535 module_exit(parport_gsc_exit);