RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / parport / parport_mfc3.c
blob4cdbdc556f9e3f3b5b684aa93e67ffd91557ecb9
1 /* Low-level parallel port routines for the Multiface 3 card
3 * Author: Joerg Dorchain <joerg@dorchain.net>
5 * (C) The elitist m68k Users(TM)
7 * based on the existing parport_amiga and lp_mfc
10 * From the MFC3 documentation:
12 * Miscellaneous PIA Details
13 * -------------------------
15 * The two open-drain interrupt outputs /IRQA and /IRQB are routed to
16 * /INT2 of the Z2 bus.
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.
21 * Centronics Pin Connections for the PIA
22 * --------------------------------------
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".
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 * -------+-----+-----+---------------------------------------------------------
48 * Should be enough to understand some of the driver.
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.
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>
68 /* Maximum Number of Cards supported */
69 #define MAX_MFC 5
71 #undef DEBUG
72 #ifdef DEBUG
73 #define DPRINTK printk
74 #else
75 static inline int DPRINTK(void *nothing, ...) {return 0;}
76 #endif
78 static struct parport *this_port[MAX_MFC] = {NULL, };
79 static volatile int dummy; /* for trigger readds */
81 #define pia(dev) ((struct pia *)(dev->base))
82 static struct parport_operations pp_mfc3_ops;
84 static void mfc3_write_data(struct parport *p, unsigned char data)
86 DPRINTK(KERN_DEBUG "write_data %c\n",data);
88 dummy = pia(p)->pprb; /* clears irq bit */
89 /* Triggers also /STROBE.*/
90 pia(p)->pprb = data;
93 static unsigned char mfc3_read_data(struct parport *p)
95 /* clears interrupt bit. Triggers also /STROBE. */
96 return pia(p)->pprb;
99 static unsigned char control_pc_to_mfc3(unsigned char control)
101 unsigned char ret = 32|64;
103 if (control & PARPORT_CONTROL_SELECT)
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;
114 static unsigned char control_mfc3_to_pc(unsigned char control)
116 unsigned char ret = PARPORT_CONTROL_STROBE
117 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_SELECT;
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;
128 static void mfc3_write_control(struct parport *p, unsigned char control)
130 DPRINTK(KERN_DEBUG "write_control %02x\n",control);
131 pia(p)->ppra = (pia(p)->ppra & 0x1f) | control_pc_to_mfc3(control);
134 static unsigned char mfc3_read_control( struct parport *p)
136 DPRINTK(KERN_DEBUG "read_control \n");
137 return control_mfc3_to_pc(pia(p)->ppra & 0xe0);
140 static unsigned char mfc3_frob_control( struct parport *p, unsigned char mask, unsigned char val)
142 unsigned char old;
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;
151 static unsigned char status_mfc3_to_pc(unsigned char status)
153 unsigned char ret = PARPORT_STATUS_BUSY;
155 if (status & 1) /* Busy */
156 ret &= ~PARPORT_STATUS_BUSY;
157 if (status & 2) /* PaperOut */
158 ret |= PARPORT_STATUS_PAPEROUT;
159 if (status & 4) /* Selected */
160 ret |= PARPORT_STATUS_SELECT;
161 if (status & 8) /* Ack */
162 ret |= PARPORT_STATUS_ACK;
163 if (status & 16) /* /ERROR */
164 ret |= PARPORT_STATUS_ERROR;
166 return ret;
170 static unsigned char mfc3_read_status(struct parport *p)
172 unsigned char status;
174 status = status_mfc3_to_pc(pia(p)->ppra & 0x1f);
175 DPRINTK(KERN_DEBUG "read_status %02x\n", status);
176 return status;
180 static int use_cnt = 0;
182 static irqreturn_t mfc3_interrupt(int irq, void *dev_id)
184 int i;
186 for( i = 0; i < MAX_MFC; i++)
187 if (this_port[i] != NULL)
188 if (pia(this_port[i])->crb & 128) { /* Board caused interrupt */
189 dummy = pia(this_port[i])->pprb; /* clear irq bit */
190 parport_generic_irq(this_port[i]);
192 return IRQ_HANDLED;
195 static void mfc3_enable_irq(struct parport *p)
197 pia(p)->crb |= PIA_C1_ENABLE_IRQ;
200 static void mfc3_disable_irq(struct parport *p)
202 pia(p)->crb &= ~PIA_C1_ENABLE_IRQ;
205 static void mfc3_data_forward(struct parport *p)
207 DPRINTK(KERN_DEBUG "forward\n");
208 pia(p)->crb &= ~PIA_DDR; /* make data direction register visible */
209 pia(p)->pddrb = 255; /* all pins output */
210 pia(p)->crb |= PIA_DDR; /* make data register visible - default */
213 static void mfc3_data_reverse(struct parport *p)
215 DPRINTK(KERN_DEBUG "reverse\n");
216 pia(p)->crb &= ~PIA_DDR; /* make data direction register visible */
217 pia(p)->pddrb = 0; /* all pins input */
218 pia(p)->crb |= PIA_DDR; /* make data register visible - default */
221 static void mfc3_init_state(struct pardevice *dev, struct parport_state *s)
223 s->u.amiga.data = 0;
224 s->u.amiga.datadir = 255;
225 s->u.amiga.status = 0;
226 s->u.amiga.statusdir = 0xe0;
229 static void mfc3_save_state(struct parport *p, struct parport_state *s)
231 s->u.amiga.data = pia(p)->pprb;
232 pia(p)->crb &= ~PIA_DDR;
233 s->u.amiga.datadir = pia(p)->pddrb;
234 pia(p)->crb |= PIA_DDR;
235 s->u.amiga.status = pia(p)->ppra;
236 pia(p)->cra &= ~PIA_DDR;
237 s->u.amiga.statusdir = pia(p)->pddrb;
238 pia(p)->cra |= PIA_DDR;
241 static void mfc3_restore_state(struct parport *p, struct parport_state *s)
243 pia(p)->pprb = s->u.amiga.data;
244 pia(p)->crb &= ~PIA_DDR;
245 pia(p)->pddrb = s->u.amiga.datadir;
246 pia(p)->crb |= PIA_DDR;
247 pia(p)->ppra = s->u.amiga.status;
248 pia(p)->cra &= ~PIA_DDR;
249 pia(p)->pddrb = s->u.amiga.statusdir;
250 pia(p)->cra |= PIA_DDR;
253 static struct parport_operations pp_mfc3_ops = {
254 .write_data = mfc3_write_data,
255 .read_data = mfc3_read_data,
257 .write_control = mfc3_write_control,
258 .read_control = mfc3_read_control,
259 .frob_control = mfc3_frob_control,
261 .read_status = mfc3_read_status,
263 .enable_irq = mfc3_enable_irq,
264 .disable_irq = mfc3_disable_irq,
266 .data_forward = mfc3_data_forward,
267 .data_reverse = mfc3_data_reverse,
269 .init_state = mfc3_init_state,
270 .save_state = mfc3_save_state,
271 .restore_state = mfc3_restore_state,
273 .epp_write_data = parport_ieee1284_epp_write_data,
274 .epp_read_data = parport_ieee1284_epp_read_data,
275 .epp_write_addr = parport_ieee1284_epp_write_addr,
276 .epp_read_addr = parport_ieee1284_epp_read_addr,
278 .ecp_write_data = parport_ieee1284_ecp_write_data,
279 .ecp_read_data = parport_ieee1284_ecp_read_data,
280 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
282 .compat_write_data = parport_ieee1284_write_compat,
283 .nibble_read_data = parport_ieee1284_read_nibble,
284 .byte_read_data = parport_ieee1284_read_byte,
286 .owner = THIS_MODULE,
289 /* ----------- Initialisation code --------------------------------- */
291 static int __init parport_mfc3_init(void)
293 struct parport *p;
294 int pias = 0;
295 struct pia *pp;
296 struct zorro_dev *z = NULL;
298 if (!MACH_IS_AMIGA)
299 return -ENODEV;
301 while ((z = zorro_find_device(ZORRO_PROD_BSC_MULTIFACE_III, z))) {
302 unsigned long piabase = z->resource.start+PIABASE;
303 if (!request_mem_region(piabase, sizeof(struct pia), "PIA"))
304 continue;
306 pp = (struct pia *)ZTWO_VADDR(piabase);
307 pp->crb = 0;
308 pp->pddrb = 255; /* all data pins output */
309 pp->crb = PIA_DDR|32|8;
310 dummy = pp->pddrb; /* reading clears interrupt */
311 pp->cra = 0;
312 pp->pddra = 0xe0; /* /RESET, /DIR ,/AUTO-FEED output */
313 pp->cra = PIA_DDR;
314 pp->ppra = 0; /* reset printer */
315 udelay(10);
316 pp->ppra = 128;
317 p = parport_register_port((unsigned long)pp, IRQ_AMIGA_PORTS,
318 PARPORT_DMA_NONE, &pp_mfc3_ops);
319 if (!p)
320 goto out_port;
322 if (p->irq != PARPORT_IRQ_NONE) {
323 if (use_cnt++ == 0)
324 if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, IRQF_SHARED, p->name, &pp_mfc3_ops))
325 goto out_irq;
327 p->dev = &z->dev;
329 this_port[pias++] = p;
330 printk(KERN_INFO "%s: Multiface III port using irq\n", p->name);
332 p->private_data = (void *)piabase;
333 parport_announce_port (p);
335 if (pias >= MAX_MFC)
336 break;
337 continue;
339 out_irq:
340 parport_put_port(p);
341 out_port:
342 release_mem_region(piabase, sizeof(struct pia));
345 return pias ? 0 : -ENODEV;
348 static void __exit parport_mfc3_exit(void)
350 int i;
352 for (i = 0; i < MAX_MFC; i++) {
353 if (!this_port[i])
354 continue;
355 parport_remove_port(this_port[i]);
356 if (this_port[i]->irq != PARPORT_IRQ_NONE) {
357 if (--use_cnt == 0)
358 free_irq(IRQ_AMIGA_PORTS, &pp_mfc3_ops);
360 release_mem_region(ZTWO_PADDR(this_port[i]->private_data), sizeof(struct pia));
361 parport_put_port(this_port[i]);
366 MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
367 MODULE_DESCRIPTION("Parport Driver for Multiface 3 expansion cards Paralllel Port");
368 MODULE_SUPPORTED_DEVICE("Multiface 3 Parallel Port");
369 MODULE_LICENSE("GPL");
371 module_init(parport_mfc3_init)
372 module_exit(parport_mfc3_exit)