2 * Low-level parallel port routines for the SGI Indy/Indigo2 builtin port
4 * Copyright (c) 2002 Vincent Stehlé <vincent.stehle@free.fr>
5 * (shamelessly based on other parport_xxx.c)
6 * See the "COPYING" license file at the top-level.
8 * PI1 registers have the same bits as the PC parallel port registers, but
9 * all PI1 bits are "direct"; i.e. no invertion: A 1 is TTL "high" (5 V),
10 * a 0 is TTL "low" (0 V). There are also some bits on the PI1, which have
11 * no equivalents on the PC. They are for non-SPP modes.
13 * Here follows a little summary of the signals and their meanings:
15 * A "/" in front of a signal means that the _bit_ is inverted: i.e. a "1"
16 * bit value means a TTL "low" (0 V) signal.
18 * A "-" in front of a signal means that it is low active: i.e. a TTL "low"
19 * (0 V) value means that the signal is active.
21 * Internal only signals are between ()'s.
28 * \ \ \ \ \ \ \ `- /-STROBE -STROBE
29 * \ \ \ \ \ \ `-- /-AUTO FEED -AFD
30 * \ \ \ \ \ `--- -INIT -INIT
31 * \ \ \ \ `---- /-SELECT -SLIN
32 * \ \ \ `----- (IRQ 1=enabled)
33 * \ \ `------ (DIRECTION 0=forward)
42 * \ \ \ \ \ \ \ `- DEVID
44 * \ \ \ \ \ `--- NOINK
45 * \ \ \ \ `---- -ERROR -ERROR
46 * \ \ \ `----- SELECT IN ONLINE
47 * \ \ `------ PAPER END PE
48 * \ `------- -ACK -ACK
49 * `-------- / BUSY BUSY
51 * Note that some of those information have been "guessed" with a multimeter
52 * and some spare nights :)
54 * Reminder: all functions await PC-style values, i.e. one should convert
58 #include <linux/kernel.h>
59 #include <linux/module.h>
60 #include <linux/init.h>
61 #include <linux/parport.h>
62 #include <asm/sgi/ioc.h>
63 #include <asm/sgi/pi1.h>
68 #define DPRINTK printk
70 #define DPRINTK(x...) do { } while (0)
73 const unsigned char control_invert = PARPORT_CONTROL_STROBE
74 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_SELECT;
75 const unsigned char status_invert = PARPORT_STATUS_BUSY;
77 static struct parport *this_port = NULL;
79 static inline void debug_dump_registers(void)
87 " dma control= %02x\n"
88 " interrupt status= %02x\n"
89 " interrupt mask= %02x\n"
100 sgioc->pport.intmask,
109 static unsigned char pi1_read_data(struct parport *p)
111 unsigned char data = sgioc->pport.data;
112 DPRINTK("pi1_read_data: %#x\n", data);
116 static void pi1_write_data(struct parport *p, unsigned char data)
118 DPRINTK("pi1_write_data: %#x\n", data);
119 sgioc->pport.data = data;
122 static unsigned char pi1_read_control(struct parport *p)
124 const unsigned char mask = PARPORT_CONTROL_STROBE
125 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_INIT
126 | PARPORT_CONTROL_SELECT;
127 unsigned char pctrl = sgioc->pport.ctrl,
128 control = ((pctrl & mask) ^ control_invert);
129 DPRINTK("pi1_read_control: %#x, %#x\n", pctrl, control);
133 static void pi1_write_control(struct parport *p, unsigned char control)
135 const unsigned char mask = PARPORT_CONTROL_STROBE
136 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_INIT
137 | PARPORT_CONTROL_SELECT,
138 /* we enforce some necessary bits */
140 unsigned char pctrl = ((control & mask) ^ control_invert) | force;
141 DPRINTK("pi1_write_control: %#x, %#x\n", control, pctrl);
142 sgioc->pport.ctrl = pctrl;
145 static unsigned char pi1_frob_control(struct parport *p,
146 unsigned char mask, unsigned char val)
149 DPRINTK(KERN_DEBUG "pi1_frob_control mask %02x, value %02x\n",mask,val);
150 old = pi1_read_control(p);
151 pi1_write_control(p, (old & ~mask) ^ val);
155 static unsigned char pi1_read_status(struct parport *p)
157 const unsigned mask = PARPORT_STATUS_ERROR | PARPORT_STATUS_SELECT
158 | PARPORT_STATUS_PAPEROUT | PARPORT_STATUS_ACK
159 | PARPORT_STATUS_BUSY;
160 unsigned char pstat = sgioc->pport.status,
161 status = ((pstat & mask) ^ status_invert);
162 DPRINTK("pi1_read_status: %#x, %#x\n", pstat, status);
166 static void pi1_init_state(struct pardevice *d, struct parport_state *s)
168 DPRINTK("pi1_init_state\n");
171 static void pi1_save_state(struct parport *p, struct parport_state *s)
173 DPRINTK("pi1_save_state\n");
176 static void pi1_restore_state(struct parport *p, struct parport_state *s)
178 DPRINTK("pi1_restore_state\n");
181 static void pi1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
183 DPRINTK("pi1_interrupt\n");
184 parport_generic_irq(irq, (struct parport *) dev_id, regs);
187 static void pi1_enable_irq(struct parport *p)
189 DPRINTK("pi1_enable_irq\n");
192 static void pi1_disable_irq(struct parport *p)
194 DPRINTK("pi1_disable_irq\n");
197 static void pi1_data_forward(struct parport *p)
199 DPRINTK("pi1_data_forward\n");
200 sgioc->pport.ctrl &= ~PI1_CTRL_DIR;
203 static void pi1_data_reverse(struct parport *p)
205 DPRINTK("pi1_data_reverse\n");
206 sgioc->pport.ctrl |= PI1_CTRL_DIR;
209 static void pi1_inc_use_count(void)
211 DPRINTK("pi1_inc_use_count\n");
215 static void pi1_dec_use_count(void)
217 DPRINTK("pi1_dec_use_count\n");
221 static struct parport_operations pi1_ops = {
237 parport_ieee1284_epp_write_data,
238 parport_ieee1284_epp_read_data,
239 parport_ieee1284_epp_write_addr,
240 parport_ieee1284_epp_read_addr,
241 parport_ieee1284_ecp_write_data,
242 parport_ieee1284_ecp_read_data,
243 parport_ieee1284_ecp_write_addr,
244 parport_ieee1284_write_compat,
245 parport_ieee1284_read_nibble,
246 parport_ieee1284_read_byte
249 static void init_hardware(void)
251 sgioc->pport.intmask = 0xfc;
252 sgioc->pport.dmactrl = 1;
253 sgioc->pport.ctrl = 0x3f;
254 sgioc->pport.timer1 = 0;
255 sgioc->pport.timer2 = 0;
256 sgioc->pport.timer3 = 0;
257 sgioc->pport.timer4 = 0;
258 sgioc->pport.data = 0;
261 static int __init pi1_init(void)
265 DPRINTK("pi1_init\n");
266 p = parport_register_port((unsigned long) &sgioc->pport.data,
267 PARPORT_IRQ_NONE, PARPORT_DMA_NONE,
273 err = request_irq(IRQ_AMIGA_CIAA_FLG, amiga_interrupt, 0, p->name, p);
278 /* tell what we are capable of */
279 p->modes = PARPORT_MODE_PCSPP;
282 | PARPORT_MODE_TRISTATE;*/
284 /* remember for exit */
287 /* put hardware into known initial state */
290 printk(KERN_INFO "%s: SGI PI1\n", p->name);
291 parport_proc_register(p);
292 parport_announce_port(p);
297 static void __exit pi1_exit(void)
299 DPRINTK("pi1_exit\n");
300 if (this_port->irq != PARPORT_IRQ_NONE)
301 free_irq(this_port->irq, this_port);
303 parport_proc_unregister(this_port);
304 parport_unregister_port(this_port);
307 MODULE_AUTHOR("Vincent Stehle <vincent.stehle@free.fr>");
308 MODULE_DESCRIPTION("Driver for SGI Indy/Indigo2 parallel port");
309 MODULE_SUPPORTED_DEVICE("SGI PI1 parallel port");
310 MODULE_LICENSE("GPL");
312 module_init(pi1_init);
313 module_exit(pi1_exit);