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>
43 #include <asm/parisc-device.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 irqreturn_t parport_gsc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
86 parport_generic_irq(irq, (struct parport *) dev_id, regs);
90 void parport_gsc_write_data(struct parport *p, unsigned char d)
92 parport_writeb (d, DATA (p));
95 unsigned char parport_gsc_read_data(struct parport *p)
97 unsigned char c = parport_readb (DATA (p));
101 void parport_gsc_write_control(struct parport *p, unsigned char d)
103 const unsigned char wm = (PARPORT_CONTROL_STROBE |
104 PARPORT_CONTROL_AUTOFD |
105 PARPORT_CONTROL_INIT |
106 PARPORT_CONTROL_SELECT);
108 /* Take this out when drivers have adapted to the newer interface. */
110 pr_debug("%s (%s): use data_reverse for this!\n",
111 p->name, p->cad->name);
112 parport_gsc_data_reverse (p);
115 __parport_gsc_frob_control (p, wm, d & wm);
118 unsigned char parport_gsc_read_control(struct parport *p)
120 const unsigned char wm = (PARPORT_CONTROL_STROBE |
121 PARPORT_CONTROL_AUTOFD |
122 PARPORT_CONTROL_INIT |
123 PARPORT_CONTROL_SELECT);
124 const struct parport_gsc_private *priv = p->physport->private_data;
125 return priv->ctr & wm; /* Use soft copy */
128 unsigned char parport_gsc_frob_control (struct parport *p, unsigned char mask,
131 const unsigned char wm = (PARPORT_CONTROL_STROBE |
132 PARPORT_CONTROL_AUTOFD |
133 PARPORT_CONTROL_INIT |
134 PARPORT_CONTROL_SELECT);
136 /* Take this out when drivers have adapted to the newer interface. */
138 pr_debug("%s (%s): use data_%s for this!\n",
139 p->name, p->cad->name,
140 (val & 0x20) ? "reverse" : "forward");
142 parport_gsc_data_reverse (p);
144 parport_gsc_data_forward (p);
147 /* Restrict mask and val to control lines. */
151 return __parport_gsc_frob_control (p, mask, val);
154 unsigned char parport_gsc_read_status(struct parport *p)
156 return parport_readb (STATUS (p));
159 void parport_gsc_disable_irq(struct parport *p)
161 __parport_gsc_frob_control (p, 0x10, 0);
164 void parport_gsc_enable_irq(struct parport *p)
166 __parport_gsc_frob_control (p, 0x10, 0x10);
169 void parport_gsc_data_forward (struct parport *p)
171 __parport_gsc_frob_control (p, 0x20, 0);
174 void parport_gsc_data_reverse (struct parport *p)
176 __parport_gsc_frob_control (p, 0x20, 0x20);
179 void parport_gsc_init_state(struct pardevice *dev, struct parport_state *s)
181 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
184 void parport_gsc_save_state(struct parport *p, struct parport_state *s)
186 s->u.pc.ctr = parport_readb (CONTROL (p));
189 void parport_gsc_restore_state(struct parport *p, struct parport_state *s)
191 parport_writeb (s->u.pc.ctr, CONTROL (p));
194 struct parport_operations parport_gsc_ops =
196 .write_data = parport_gsc_write_data,
197 .read_data = parport_gsc_read_data,
199 .write_control = parport_gsc_write_control,
200 .read_control = parport_gsc_read_control,
201 .frob_control = parport_gsc_frob_control,
203 .read_status = parport_gsc_read_status,
205 .enable_irq = parport_gsc_enable_irq,
206 .disable_irq = parport_gsc_disable_irq,
208 .data_forward = parport_gsc_data_forward,
209 .data_reverse = parport_gsc_data_reverse,
211 .init_state = parport_gsc_init_state,
212 .save_state = parport_gsc_save_state,
213 .restore_state = parport_gsc_restore_state,
215 .epp_write_data = parport_ieee1284_epp_write_data,
216 .epp_read_data = parport_ieee1284_epp_read_data,
217 .epp_write_addr = parport_ieee1284_epp_write_addr,
218 .epp_read_addr = parport_ieee1284_epp_read_addr,
220 .ecp_write_data = parport_ieee1284_ecp_write_data,
221 .ecp_read_data = parport_ieee1284_ecp_read_data,
222 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
224 .compat_write_data = parport_ieee1284_write_compat,
225 .nibble_read_data = parport_ieee1284_read_nibble,
226 .byte_read_data = parport_ieee1284_read_byte,
228 .owner = THIS_MODULE,
231 /* --- Mode detection ------------------------------------- */
234 * Checks for port existence, all ports support SPP MODE
236 static int __devinit parport_SPP_supported(struct parport *pb)
241 * first clear an eventually pending EPP timeout
242 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
243 * that does not even respond to SPP cycles if an EPP
246 clear_epp_timeout(pb);
248 /* Do a simple read-write test to make sure the port exists. */
250 parport_writeb (w, CONTROL (pb));
252 /* Is there a control register that we can read from? Some
253 * ports don't allow reads, so read_control just returns a
254 * software copy. Some ports _do_ allow reads, so bypass the
255 * software copy here. In addition, some bits aren't
257 r = parport_readb (CONTROL (pb));
258 if ((r & 0xf) == w) {
260 parport_writeb (w, CONTROL (pb));
261 r = parport_readb (CONTROL (pb));
262 parport_writeb (0xc, CONTROL (pb));
264 return PARPORT_MODE_PCSPP;
267 /* Try the data register. The data lines aren't tri-stated at
268 * this stage, so we expect back what we wrote. */
270 parport_gsc_write_data (pb, w);
271 r = parport_gsc_read_data (pb);
274 parport_gsc_write_data (pb, w);
275 r = parport_gsc_read_data (pb);
277 return PARPORT_MODE_PCSPP;
283 /* Detect PS/2 support.
285 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
286 * allows us to read data from the data lines. In theory we would get back
287 * 0xff but any peripheral attached to the port may drag some or all of the
288 * lines down to zero. So if we get back anything that isn't the contents
289 * of the data register we deem PS/2 support to be present.
291 * Some SPP ports have "half PS/2" ability - you can't turn off the line
292 * drivers, but an external peripheral with sufficiently beefy drivers of
293 * its own can overpower them and assert its own levels onto the bus, from
294 * where they can then be read back as normal. Ports with this property
295 * and the right type of device attached are likely to fail the SPP test,
296 * (as they will appear to have stuck bits) and so the fact that they might
297 * be misdetected here is rather academic.
300 static int __devinit parport_PS2_supported(struct parport *pb)
304 clear_epp_timeout(pb);
306 /* try to tri-state the buffer */
307 parport_gsc_data_reverse (pb);
309 parport_gsc_write_data(pb, 0x55);
310 if (parport_gsc_read_data(pb) != 0x55) ok++;
312 parport_gsc_write_data(pb, 0xaa);
313 if (parport_gsc_read_data(pb) != 0xaa) ok++;
315 /* cancel input mode */
316 parport_gsc_data_forward (pb);
319 pb->modes |= PARPORT_MODE_TRISTATE;
321 struct parport_gsc_private *priv = pb->private_data;
322 priv->ctr_writable &= ~0x20;
329 /* --- Initialisation code -------------------------------- */
331 struct parport *__devinit parport_gsc_probe_port (unsigned long base,
332 unsigned long base_hi,
336 struct parport_gsc_private *priv;
337 struct parport_operations *ops;
339 struct parport *p = &tmp;
341 priv = kmalloc (sizeof (struct parport_gsc_private), GFP_KERNEL);
343 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
346 ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
348 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
353 memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
355 priv->ctr_writable = 0xff;
357 priv->dma_handle = 0;
360 p->base_hi = base_hi;
363 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
365 p->private_data = priv;
367 if (!parport_SPP_supported (p)) {
372 parport_PS2_supported (p);
374 if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
375 PARPORT_DMA_NONE, ops))) {
381 p->base_hi = base_hi;
382 p->modes = tmp.modes;
383 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
384 p->private_data = priv;
386 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
388 if (p->irq == PARPORT_IRQ_AUTO) {
389 p->irq = PARPORT_IRQ_NONE;
391 if (p->irq != PARPORT_IRQ_NONE) {
392 printk(", irq %d", p->irq);
394 if (p->dma == PARPORT_DMA_AUTO) {
395 p->dma = PARPORT_DMA_NONE;
398 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
399 is mandatory (see above) */
400 p->dma = PARPORT_DMA_NONE;
403 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
416 if (p->irq != PARPORT_IRQ_NONE) {
417 if (request_irq (p->irq, parport_gsc_interrupt,
419 printk (KERN_WARNING "%s: irq %d in use, "
420 "resorting to polled operation\n",
422 p->irq = PARPORT_IRQ_NONE;
423 p->dma = PARPORT_DMA_NONE;
427 /* Done probing. Now put the port into a sensible start-up state. */
429 parport_gsc_write_data(p, 0);
430 parport_gsc_data_forward (p);
432 /* Now that we've told the sharing engine about the port, and
433 found out its characteristics, let the high-level drivers
435 parport_announce_port (p);
441 #define PARPORT_GSC_OFFSET 0x800
443 static int __initdata parport_count;
445 static int __devinit parport_init_chip(struct parisc_device *dev)
451 printk("IRQ not found for parallel device at 0x%lx\n", dev->hpa);
455 port = dev->hpa + PARPORT_GSC_OFFSET;
457 /* some older machines with ASP-chip don't support
458 * the enhanced parport modes.
460 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) {
462 /* Initialize bidirectional-mode (0x10) & data-tranfer-mode #1 (0x20) */
463 printk("%s: initialize bidirectional-mode.\n", __FUNCTION__);
464 parport_writeb ( (0x10 + 0x20), port + 4);
467 printk("%s: enhanced parport-modes not supported.\n", __FUNCTION__);
470 p = parport_gsc_probe_port(port, 0, dev->irq,
471 /* PARPORT_IRQ_NONE */ PARPORT_DMA_NONE, NULL);
474 dev->dev.driver_data = p;
479 static int __devexit parport_remove_chip(struct parisc_device *dev)
481 struct parport *p = dev->dev.driver_data;
483 struct parport_gsc_private *priv = p->private_data;
484 struct parport_operations *ops = p->ops;
485 parport_remove_port(p);
486 if (p->dma != PARPORT_DMA_NONE)
488 if (p->irq != PARPORT_IRQ_NONE)
491 pci_free_consistent(priv->dev, PAGE_SIZE,
494 kfree (p->private_data);
496 kfree (ops); /* hope no-one cached it */
501 static struct parisc_device_id parport_tbl[] = {
502 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x74 },
506 MODULE_DEVICE_TABLE(parisc, parport_tbl);
508 static struct parisc_driver parport_driver = {
510 .id_table = parport_tbl,
511 .probe = parport_init_chip,
512 .remove = __devexit_p(parport_remove_chip),
515 int __devinit parport_gsc_init(void)
517 return register_parisc_driver(&parport_driver);
520 static void __devexit parport_gsc_exit(void)
522 unregister_parisc_driver(&parport_driver);
525 module_init(parport_gsc_init);
526 module_exit(parport_gsc_exit);