Import 2.3.12pre2
[davej-history.git] / drivers / parport / parport_mfc3.c
blob1acb52aa305fd98a60363b7020c295f119ea22bc
1 /* Low-level parallel port routines for the Multiface 3 card
3 * Author: Joerg Dorchain <dorchain@wirbel.com>
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.
51 #include "multiface.h"
52 #include <linux/module.h>
53 #include <linux/init.h>
54 #include <linux/parport.h>
55 #include <linux/delay.h>
56 #include <linux/mc6821.h>
57 #include <linux/zorro.h>
58 #include <asm/setup.h>
59 #include <asm/amigahw.h>
60 #include <asm/irq.h>
61 #include <asm/amigaints.h>
63 /* Maximum Number of Cards supported */
64 #define MAX_MFC 5
66 #undef DEBUG
67 #ifdef DEBUG
68 #define DPRINTK printk
69 #else
70 static inline int DPRINTK() {return 0;}
71 #endif
73 static struct parport *this_port[MAX_MFC] = {NULL, };
74 static volatile int dummy; /* for trigger readds */
76 #define pia(dev) ((struct pia *)(dev->base))
77 static struct parport_operations pp_mfc3_ops;
79 static void mfc3_write_data(struct parport *p, unsigned char data)
81 DPRINTK("write_data %c\n",data);
83 dummy = pia(p)->pprb; /* clears irq bit */
84 /* Triggers also /STROBE.*/
85 pia(p)->pprb = data;
88 static unsigned char mfc3_read_data(struct parport *p)
90 /* clears interupt bit. Triggers also /STROBE. */
91 return pia(p)->pprb;
94 static unsigned char control_pc_to_mfc3(unsigned char control)
96 unsigned char ret = 32|64;
98 if (control & PARPORT_CONTROL_DIRECTION) /* XXX: What is this? */
100 if (control & PARPORT_CONTROL_INTEN) /* XXX: What is INTEN? */
102 if (control & PARPORT_CONTROL_SELECT) /* XXX: What is SELECP? */
103 ret &= ~32; /* /SELECT_IN */
104 if (control & PARPORT_CONTROL_INIT) /* INITP */
105 ret |= 128;
106 if (control & PARPORT_CONTROL_AUTOFD) /* AUTOLF */
107 ret &= ~64;
108 if (control & PARPORT_CONTROL_STROBE) /* Strobe */
109 /* Handled directly by hardware */;
110 return ret;
113 static unsigned char control_mfc3_to_pc(unsigned char control)
115 unsigned char ret = PARPORT_CONTROL_INTEN | PARPORT_CONTROL_STROBE
116 | PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_SELECT;
118 if (control & 128) /* /INITP */
119 ret |= PARPORT_CONTROL_INIT;
120 if (control & 64) /* /AUTOLF */
121 ret &= ~PARPORT_CONTROL_AUTOFD;
122 if (control & 32) /* /SELECT_IN */
123 ret &= ~PARPORT_CONTROL_SELECT;
124 return ret;
127 static void mfc3_write_control(struct parport *p, unsigned char control)
129 DPRINTK("write_control %02x\n",control);
130 pia(p)->ppra = (pia(p)->ppra & 0x1f) | control_pc_to_mfc3(control);
133 static unsigned char mfc3_read_control( struct parport *p)
135 DPRINTK("read_control \n");
136 return control_mfc3_to_pc(pia(p)->ppra & 0xe0);
139 static unsigned char mfc3_frob_control( struct parport *p, unsigned char mask, unsigned char val)
141 unsigned char old;
143 DPRINTK("frob_control mask %02x, value %02x\n",mask,val);
144 old = mfc3_read_control(p);
145 mfc3_write_control(p, (old & ~mask) ^ val);
146 return old;
150 static unsigned char status_pc_to_mfc3(unsigned char status)
152 unsigned char ret = 1;
154 if (status & PARPORT_STATUS_BUSY) /* Busy */
155 ret &= ~1;
156 if (status & PARPORT_STATUS_ACK) /* Ack */
157 ret |= 8;
158 if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */
159 ret |= 2;
160 if (status & PARPORT_STATUS_SELECT) /* select */
161 ret |= 4;
162 if (status & PARPORT_STATUS_ERROR) /* error */
163 ret |= 16;
164 return ret;
167 static unsigned char status_mfc3_to_pc(unsigned char status)
169 unsigned char ret = PARPORT_STATUS_BUSY;
171 if (status & 1) /* Busy */
172 ret &= ~PARPORT_STATUS_BUSY;
173 if (status & 2) /* PaperOut */
174 ret |= PARPORT_STATUS_PAPEROUT;
175 if (status & 4) /* Selected */
176 ret |= PARPORT_STATUS_SELECT;
177 if (status & 8) /* Ack */
178 ret |= PARPORT_STATUS_ACK;
179 if (status & 16) /* /ERROR */
180 ret |= PARPORT_STATUS_ERROR;
182 return ret;
185 static void mfc3_write_status( struct parport *p, unsigned char status)
187 DPRINTK("write_status %02x\n",status);
188 pia(p)->ppra = (pia(p)->ppra & 0xe0) | status_pc_to_mfc3(status);
191 static unsigned char mfc3_read_status(struct parport *p)
193 unsigned char status;
195 status = status_mfc3_to_pc(pia(p)->ppra & 0x1f);
196 DPRINTK("read_status %02x\n", status);
197 return status;
200 static void mfc3_change_mode( struct parport *p, int m)
202 /* XXX: This port only has one mode, and I am
203 not sure about the corresponding PC-style mode*/
206 static int use_cnt = 0;
208 static void mfc3_interrupt(int irq, void *dev_id, struct pt_regs *regs)
210 int i;
212 for( i = 0; i < MAX_MFC; i++)
213 if (this_port[i] != NULL)
214 if (pia(this_port[i])->crb & 128) { /* Board caused interrupt */
215 dummy = pia(this_port[i])->pprb; /* clear irq bit */
216 parport_generic_irq(irq, this_port[i], regs);
220 static int mfc3_claim_resources(struct parport *p)
222 DPRINTK("claim_resources\n");
225 static void mfc3_init_state(struct parport_state *s)
227 s->u.amiga.data = 0;
228 s->u.amiga.datadir = 255;
229 s->u.amiga.status = 0;
230 s->u.amiga.statusdir = 0xe0;
233 static void mfc3_save_state(struct parport *p, struct parport_state *s)
235 s->u.amiga.data = pia(p)->pprb;
236 pia(p)->crb &= ~PIA_DDR;
237 s->u.amiga.datadir = pia(p)->pddrb;
238 pia(p)->crb |= PIA_DDR;
239 s->u.amiga.status = pia(p)->ppra;
240 pia(p)->cra &= ~PIA_DDR;
241 s->u.amiga.statusdir = pia(p)->pddrb;
242 pia(p)->cra |= PIA_DDR;
245 static void mfc3_restore_state(struct parport *p, struct parport_state *s)
247 pia(p)->pprb = s->u.amiga.data;
248 pia(p)->crb &= ~PIA_DDR;
249 pia(p)->pddrb = s->u.amiga.datadir;
250 pia(p)->crb |= PIA_DDR;
251 pia(p)->ppra = s->u.amiga.status;
252 pia(p)->cra &= ~PIA_DDR;
253 pia(p)->pddrb = s->u.amiga.statusdir;
254 pia(p)->cra |= PIA_DDR;
257 static void mfc3_enable_irq(struct parport *p)
259 pia(p)->crb |= PIA_C1_ENABLE_IRQ;
262 static void mfc3_disable_irq(struct parport *p)
264 pia(p)->crb &= ~PIA_C1_ENABLE_IRQ;
267 static void mfc3_inc_use_count(void)
269 MOD_INC_USE_COUNT;
272 static void mfc3_dec_use_count(void)
274 MOD_DEC_USE_COUNT;
277 static void mfc3_fill_inode(struct inode *inode, int fill)
279 #ifdef MODULE
280 if (fill)
281 MOD_INC_USE_COUNT;
282 else
283 MOD_DEC_USE_COUNT;
284 #endif
287 static struct parport_operations pp_mfc3_ops = {
288 mfc3_write_data,
289 mfc3_read_data,
291 mfc3_write_control,
292 mfc3_read_control,
293 mfc3_frob_control,
295 NULL, /* write_econtrol */
296 NULL, /* read_econtrol */
297 NULL, /* frob_econtrol */
299 mfc3_write_status,
300 mfc3_read_status,
302 NULL, /* write fifo */
303 NULL, /* read fifo */
305 mfc3_change_mode,
308 mfc3_release_resources,
309 mfc3_claim_resources,
312 NULL, /* epp_write_data */
313 NULL, /* epp_read_data */
314 NULL, /* epp_write_addr */
315 NULL, /* epp_read_addr */
316 NULL, /* epp_check_timeout */
318 NULL, /* epp_write_block */
319 NULL, /* epp_read_block */
321 NULL, /* ecp_write_block */
322 NULL, /* ecp_read_block */
324 mfc3_init_state,
325 mfc3_save_state,
326 mfc3_restore_state,
328 mfc3_enable_irq,
329 mfc3_disable_irq,
330 mfc3_interrupt,
332 mfc3_inc_use_count,
333 mfc3_dec_use_count,
334 mfc3_fill_inode
337 /* ----------- Initialisation code --------------------------------- */
339 __initfunc(int parport_mfc3_init(void))
341 struct parport *p;
342 int pias = 0;
343 struct pia *pp;
344 unsigned int key = 0;
345 const struct ConfigDev *cd;
347 if (MACH_IS_AMIGA) {
348 while ((key = zorro_find(ZORRO_PROD_BSC_MULTIFACE_III, 0, key))) {
349 cd = zorro_get_board(key);
350 pp = (struct pia *)ZTWO_VADDR((((u_char *)cd->cd_BoardAddr)+PIABASE));
351 if (pias < MAX_MFC) {
352 pp->crb = 0;
353 pp->pddrb = 255; /* all data pins output */
354 pp->crb = PIA_DDR|32|8;
355 dummy = pp->pddrb; /* reading clears interrupt */
356 pp->cra = 0;
357 pp->pddra = 0xe0; /* /RESET, /DIR ,/AUTO-FEED output */
358 pp->cra = PIA_DDR;
359 pp->ppra = 0; /* reset printer */
360 udelay(10);
361 pp->ppra = 128;
362 if ((p = parport_register_port((unsigned long)pp,
363 IRQ_AMIGA_PORTS, PARPORT_DMA_NONE,
364 &pp_mfc3_ops))) {
365 this_port[pias++] = p;
366 printk(KERN_INFO "%s: Multiface III port using irq\n", p->name);
367 /* XXX: set operating mode */
368 parport_proc_register(p);
370 if (p->irq != PARPORT_IRQ_NONE)
371 if (use_cnt++ == 0)
372 if (request_irq(IRQ_AMIGA_PORTS, mfc3_interrupt, 0, p->name, &pp_mfc3_ops))
373 use_cnt--;
375 if (parport_probe_hook)
376 (*parport_probe_hook)(p);
377 zorro_config_board(key, 0);
378 p->private_data = (void *)key;
379 parport_announce_port (p);
384 return pias;
387 #ifdef MODULE
389 MODULE_AUTHOR("Joerg Dorchain");
390 MODULE_DESCRIPTION("Parport Driver for Multiface 3 expansion cards Paralllel Port");
391 MODULE_SUPPORTED_DEVICE("Multiface 3 Parallel Port");
393 int init_module(void)
395 return ! parport_mfc3_init();
398 void cleanup_module(void)
400 int i;
402 for (i = 0; i < MAX_MFC; i++)
403 if (this_port[i] != NULL) {
404 if (p->irq != PARPORT_IRQ_NONE)
405 if (--use_cnt == 0)
406 free_irq(IRQ_AMIGA_PORTS, &pp_mfc3_ops);
407 parport_proc_unregister(this_port[i]);
408 parport_unregister_port(this_port[i]);
409 zorro_unconfig_board((unsigned int)this_port[i]->private_data, 0);
412 #endif