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 <philb@gnu.org>
16 * Tim Waugh <tim@cyberelk.demon.co.uk>
17 * Jose Renau <renau@acm.org>
22 #undef DEBUG /* undef for production */
24 #include <linux/module.h>
25 #include <linux/init.h>
26 #include <linux/delay.h>
27 #include <linux/errno.h>
28 #include <linux/interrupt.h>
29 #include <linux/ioport.h>
30 #include <linux/kernel.h>
31 #include <linux/slab.h>
32 #include <linux/pci.h>
33 #include <linux/sysctl.h>
37 #include <asm/uaccess.h>
38 #include <asm/superio.h>
40 #include <linux/parport.h>
42 #include <asm/parisc-device.h>
43 #include <asm/hardware.h>
44 #include "parport_gsc.h"
47 MODULE_AUTHOR("Helge Deller <deller@gmx.de>");
48 MODULE_DESCRIPTION("HP-PARISC PC-style parallel port driver");
49 MODULE_SUPPORTED_DEVICE("integrated PC-style parallel port");
50 MODULE_LICENSE("GPL");
54 * Clear TIMEOUT BIT in EPP MODE
56 * This is also used in SPP detection.
58 static int clear_epp_timeout(struct parport *pb)
62 if (!(parport_gsc_read_status(pb) & 0x01))
65 /* To clear timeout some chips require double read */
66 parport_gsc_read_status(pb);
67 r = parport_gsc_read_status(pb);
68 parport_writeb (r | 0x01, STATUS (pb)); /* Some reset by writing 1 */
69 parport_writeb (r & 0xfe, STATUS (pb)); /* Others by writing 0 */
70 r = parport_gsc_read_status(pb);
78 * Most of these aren't static because they may be used by the
79 * parport_xxx_yyy macros. extern __inline__ versions of several
80 * of these are in parport_gsc.h.
83 static irqreturn_t parport_gsc_interrupt(int irq, void *dev_id)
85 parport_generic_irq(irq, (struct parport *) dev_id);
89 void parport_gsc_init_state(struct pardevice *dev, struct parport_state *s)
91 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
94 void parport_gsc_save_state(struct parport *p, struct parport_state *s)
96 s->u.pc.ctr = parport_readb (CONTROL (p));
99 void parport_gsc_restore_state(struct parport *p, struct parport_state *s)
101 parport_writeb (s->u.pc.ctr, CONTROL (p));
104 struct parport_operations parport_gsc_ops =
106 .write_data = parport_gsc_write_data,
107 .read_data = parport_gsc_read_data,
109 .write_control = parport_gsc_write_control,
110 .read_control = parport_gsc_read_control,
111 .frob_control = parport_gsc_frob_control,
113 .read_status = parport_gsc_read_status,
115 .enable_irq = parport_gsc_enable_irq,
116 .disable_irq = parport_gsc_disable_irq,
118 .data_forward = parport_gsc_data_forward,
119 .data_reverse = parport_gsc_data_reverse,
121 .init_state = parport_gsc_init_state,
122 .save_state = parport_gsc_save_state,
123 .restore_state = parport_gsc_restore_state,
125 .epp_write_data = parport_ieee1284_epp_write_data,
126 .epp_read_data = parport_ieee1284_epp_read_data,
127 .epp_write_addr = parport_ieee1284_epp_write_addr,
128 .epp_read_addr = parport_ieee1284_epp_read_addr,
130 .ecp_write_data = parport_ieee1284_ecp_write_data,
131 .ecp_read_data = parport_ieee1284_ecp_read_data,
132 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
134 .compat_write_data = parport_ieee1284_write_compat,
135 .nibble_read_data = parport_ieee1284_read_nibble,
136 .byte_read_data = parport_ieee1284_read_byte,
138 .owner = THIS_MODULE,
141 /* --- Mode detection ------------------------------------- */
144 * Checks for port existence, all ports support SPP MODE
146 static int __devinit parport_SPP_supported(struct parport *pb)
151 * first clear an eventually pending EPP timeout
152 * I (sailer@ife.ee.ethz.ch) have an SMSC chipset
153 * that does not even respond to SPP cycles if an EPP
156 clear_epp_timeout(pb);
158 /* Do a simple read-write test to make sure the port exists. */
160 parport_writeb (w, CONTROL (pb));
162 /* Is there a control register that we can read from? Some
163 * ports don't allow reads, so read_control just returns a
164 * software copy. Some ports _do_ allow reads, so bypass the
165 * software copy here. In addition, some bits aren't
167 r = parport_readb (CONTROL (pb));
168 if ((r & 0xf) == w) {
170 parport_writeb (w, CONTROL (pb));
171 r = parport_readb (CONTROL (pb));
172 parport_writeb (0xc, CONTROL (pb));
174 return PARPORT_MODE_PCSPP;
177 /* Try the data register. The data lines aren't tri-stated at
178 * this stage, so we expect back what we wrote. */
180 parport_gsc_write_data (pb, w);
181 r = parport_gsc_read_data (pb);
184 parport_gsc_write_data (pb, w);
185 r = parport_gsc_read_data (pb);
187 return PARPORT_MODE_PCSPP;
193 /* Detect PS/2 support.
195 * Bit 5 (0x20) sets the PS/2 data direction; setting this high
196 * allows us to read data from the data lines. In theory we would get back
197 * 0xff but any peripheral attached to the port may drag some or all of the
198 * lines down to zero. So if we get back anything that isn't the contents
199 * of the data register we deem PS/2 support to be present.
201 * Some SPP ports have "half PS/2" ability - you can't turn off the line
202 * drivers, but an external peripheral with sufficiently beefy drivers of
203 * its own can overpower them and assert its own levels onto the bus, from
204 * where they can then be read back as normal. Ports with this property
205 * and the right type of device attached are likely to fail the SPP test,
206 * (as they will appear to have stuck bits) and so the fact that they might
207 * be misdetected here is rather academic.
210 static int __devinit parport_PS2_supported(struct parport *pb)
214 clear_epp_timeout(pb);
216 /* try to tri-state the buffer */
217 parport_gsc_data_reverse (pb);
219 parport_gsc_write_data(pb, 0x55);
220 if (parport_gsc_read_data(pb) != 0x55) ok++;
222 parport_gsc_write_data(pb, 0xaa);
223 if (parport_gsc_read_data(pb) != 0xaa) ok++;
225 /* cancel input mode */
226 parport_gsc_data_forward (pb);
229 pb->modes |= PARPORT_MODE_TRISTATE;
231 struct parport_gsc_private *priv = pb->private_data;
232 priv->ctr_writable &= ~0x20;
239 /* --- Initialisation code -------------------------------- */
241 struct parport *__devinit parport_gsc_probe_port (unsigned long base,
242 unsigned long base_hi,
246 struct parport_gsc_private *priv;
247 struct parport_operations *ops;
249 struct parport *p = &tmp;
251 priv = kzalloc (sizeof (struct parport_gsc_private), GFP_KERNEL);
253 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
256 ops = kmalloc (sizeof (struct parport_operations), GFP_KERNEL);
258 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
263 memcpy (ops, &parport_gsc_ops, sizeof (struct parport_operations));
265 priv->ctr_writable = 0xff;
267 priv->dma_handle = 0;
270 p->base_hi = base_hi;
273 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
275 p->private_data = priv;
277 if (!parport_SPP_supported (p)) {
282 parport_PS2_supported (p);
284 if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
285 PARPORT_DMA_NONE, ops))) {
291 p->base_hi = base_hi;
292 p->modes = tmp.modes;
293 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
294 p->private_data = priv;
296 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
298 if (p->irq == PARPORT_IRQ_AUTO) {
299 p->irq = PARPORT_IRQ_NONE;
301 if (p->irq != PARPORT_IRQ_NONE) {
302 printk(", irq %d", p->irq);
304 if (p->dma == PARPORT_DMA_AUTO) {
305 p->dma = PARPORT_DMA_NONE;
308 if (p->dma == PARPORT_DMA_AUTO) /* To use DMA, giving the irq
309 is mandatory (see above) */
310 p->dma = PARPORT_DMA_NONE;
313 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){printk("%s%s",f?",":"",#x);f++;}}
326 if (p->irq != PARPORT_IRQ_NONE) {
327 if (request_irq (p->irq, parport_gsc_interrupt,
329 printk (KERN_WARNING "%s: irq %d in use, "
330 "resorting to polled operation\n",
332 p->irq = PARPORT_IRQ_NONE;
333 p->dma = PARPORT_DMA_NONE;
337 /* Done probing. Now put the port into a sensible start-up state. */
339 parport_gsc_write_data(p, 0);
340 parport_gsc_data_forward (p);
342 /* Now that we've told the sharing engine about the port, and
343 found out its characteristics, let the high-level drivers
345 parport_announce_port (p);
351 #define PARPORT_GSC_OFFSET 0x800
353 static int __initdata parport_count;
355 static int __devinit parport_init_chip(struct parisc_device *dev)
361 printk(KERN_WARNING "IRQ not found for parallel device at 0x%lx\n",
366 port = dev->hpa.start + PARPORT_GSC_OFFSET;
368 /* some older machines with ASP-chip don't support
369 * the enhanced parport modes.
371 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) {
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);
378 printk("%s: enhanced parport-modes not supported.\n", __FUNCTION__);
381 p = parport_gsc_probe_port(port, 0, dev->irq,
382 /* PARPORT_IRQ_NONE */ PARPORT_DMA_NONE, NULL);
385 dev->dev.driver_data = p;
390 static int __devexit parport_remove_chip(struct parisc_device *dev)
392 struct parport *p = dev->dev.driver_data;
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)
399 if (p->irq != PARPORT_IRQ_NONE)
402 pci_free_consistent(priv->dev, PAGE_SIZE,
405 kfree (p->private_data);
407 kfree (ops); /* hope no-one cached it */
412 static struct parisc_device_id parport_tbl[] = {
413 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x74 },
417 MODULE_DEVICE_TABLE(parisc, parport_tbl);
419 static struct parisc_driver parport_driver = {
421 .id_table = parport_tbl,
422 .probe = parport_init_chip,
423 .remove = __devexit_p(parport_remove_chip),
426 int __devinit parport_gsc_init(void)
428 return register_parisc_driver(&parport_driver);
431 static void __devexit parport_gsc_exit(void)
433 unregister_parisc_driver(&parport_driver);
436 module_init(parport_gsc_init);
437 module_exit(parport_gsc_exit);