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>
61 #include <asm/amigaints.h>
63 /* Maximum Number of Cards supported */
68 #define DPRINTK printk
70 static inline int DPRINTK() {return 0;}
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.*/
88 static unsigned char mfc3_read_data(struct parport
*p
)
90 /* clears interupt bit. Triggers also /STROBE. */
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 */
106 if (control
& PARPORT_CONTROL_AUTOFD
) /* AUTOLF */
108 if (control
& PARPORT_CONTROL_STROBE
) /* Strobe */
109 /* Handled directly by hardware */;
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
;
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
)
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
);
150 static unsigned char status_pc_to_mfc3(unsigned char status
)
152 unsigned char ret
= 1;
154 if (status
& PARPORT_STATUS_BUSY
) /* Busy */
156 if (status
& PARPORT_STATUS_ACK
) /* Ack */
158 if (status
& PARPORT_STATUS_PAPEROUT
) /* PaperOut */
160 if (status
& PARPORT_STATUS_SELECT
) /* select */
162 if (status
& PARPORT_STATUS_ERROR
) /* error */
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
;
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
);
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
)
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
)
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)
272 static void mfc3_dec_use_count(void)
277 static struct parport_operations pp_mfc3_ops
= {
290 NULL
, /* data_forward - FIXME */
291 NULL
, /* data_reverse - FIXME */
300 parport_ieee1284_epp_write_data
,
301 parport_ieee1284_epp_read_data
,
302 parport_ieee1284_epp_write_addr
,
303 parport_ieee1284_epp_read_addr
,
305 parport_ieee1284_ecp_write_data
,
306 parport_ieee1284_ecp_read_data
,
307 parport_ieee1284_ecp_write_addr
,
309 parport_ieee1284_write_compat
,
310 parport_ieee1284_read_nibble
,
311 parport_ieee1284_read_byte
,
314 /* ----------- Initialisation code --------------------------------- */
316 int __init
parport_mfc3_init(void)
321 unsigned int key
= 0;
322 const struct ConfigDev
*cd
;
325 while ((key
= zorro_find(ZORRO_PROD_BSC_MULTIFACE_III
, 0, key
))) {
326 cd
= zorro_get_board(key
);
327 pp
= (struct pia
*)ZTWO_VADDR((((u_char
*)cd
->cd_BoardAddr
)+PIABASE
));
328 if (pias
< MAX_MFC
) {
330 pp
->pddrb
= 255; /* all data pins output */
331 pp
->crb
= PIA_DDR
|32|8;
332 dummy
= pp
->pddrb
; /* reading clears interrupt */
334 pp
->pddra
= 0xe0; /* /RESET, /DIR ,/AUTO-FEED output */
336 pp
->ppra
= 0; /* reset printer */
339 if ((p
= parport_register_port((unsigned long)pp
,
340 IRQ_AMIGA_PORTS
, PARPORT_DMA_NONE
,
342 this_port
[pias
++] = p
;
343 printk(KERN_INFO
"%s: Multiface III port using irq\n", p
->name
);
344 /* XXX: set operating mode */
345 parport_proc_register(p
);
347 if (p
->irq
!= PARPORT_IRQ_NONE
)
349 if (request_irq(IRQ_AMIGA_PORTS
, mfc3_interrupt
, SA_SHIRQ
, p
->name
, &pp_mfc3_ops
))
352 if (parport_probe_hook
)
353 (*parport_probe_hook
)(p
);
354 zorro_config_board(key
, 0);
355 p
->private_data
= (void *)key
;
356 parport_announce_port (p
);
366 MODULE_AUTHOR("Joerg Dorchain");
367 MODULE_DESCRIPTION("Parport Driver for Multiface 3 expansion cards Paralllel Port");
368 MODULE_SUPPORTED_DEVICE("Multiface 3 Parallel Port");
370 int init_module(void)
372 return ! parport_mfc3_init();
375 void cleanup_module(void)
379 for (i
= 0; i
< MAX_MFC
; i
++)
380 if (this_port
[i
] != NULL
) {
381 if (p
->irq
!= PARPORT_IRQ_NONE
)
383 free_irq(IRQ_AMIGA_PORTS
, &pp_mfc3_ops
);
384 parport_proc_unregister(this_port
[i
]);
385 parport_unregister_port(this_port
[i
]);
386 zorro_unconfig_board((unsigned int)this_port
[i
]->private_data
, 0);