1 /* Low-level parallel port routines for the Amiga buildin port
3 * Author: Joerg Dorchain <dorchain@wirbel.com>
5 * This is a complete rewrite of the code, but based heaviy upon the old
8 * The built-in Amiga parallel port provides one port at a fixed address
9 * with 8 bisdirecttional data lines (D0 - D7) and 3 bidirectional status
10 * lines (BUSY, POUT, SEL), 1 output control line /STROBE (raised automatically in
11 * hardware when the data register is accessed), and 1 input control line
12 * /ACK, able to cause an interrupt, but both not directly settable by
16 #include <linux/module.h>
17 #include <linux/init.h>
18 #include <linux/parport.h>
19 #include <asm/setup.h>
20 #include <asm/amigahw.h>
22 #include <asm/amigaints.h>
26 #define DPRINTK printk
28 static inline int DPRINTK() {return 0;}
31 static struct parport
*this_port
= NULL
;
33 static void amiga_write_data(struct parport
*p
, unsigned char data
)
35 DPRINTK("write_data %c\n",data
);
36 /* Triggers also /STROBE. This behavior cannot be changed */
40 static unsigned char amiga_read_data(struct parport
*p
)
42 /* Triggers also /STROBE. This behavior cannot be changed */
47 static unsigned char control_pc_to_amiga(unsigned char control
)
49 unsigned char ret
= 0;
51 if (control
& PARPORT_CONTROL_DIRECTION
) /* XXX: What is this? */
53 if (control
& PARPORT_CONTROL_INTEN
) /* XXX: What is INTEN? */
55 if (control
& PARPORT_CONTROL_SELECT
) /* XXX: What is SELECP? */
57 if (control
& PARPORT_CONTROL_INIT
) /* INITP */
58 /* reset connected to cpu reset pin */;
59 if (control
& PARPORT_CONTROL_AUTOFD
) /* AUTOLF */
61 if (control
& PARPORT_CONTROL_STROBE
) /* Strobe */
62 /* Handled only directly by hardware */;
67 static unsigned char control_amiga_to_pc(unsigned char control
)
69 return PARPORT_CONTROL_INTEN
| PARPORT_CONTROL_SELECT
|
70 PARPORT_CONTROL_AUTOFD
| PARPORT_CONTROL_STROBE
;
71 /* fake value: interrupt enable, select in, no reset,
72 no autolf, no strobe - seems to be closest the wiring diagram */
75 static void amiga_write_control(struct parport
*p
, unsigned char control
)
77 DPRINTK("write_control %02x\n",control
);
78 /* No implementation possible */
81 static unsigned char amiga_read_control( struct parport
*p
)
83 DPRINTK("read_control \n");
84 return control_amiga_to_pc(0);
87 static unsigned char amiga_frob_control( struct parport
*p
, unsigned char mask
, unsigned char val
)
91 DPRINTK("frob_control mask %02x, value %02x\n",mask
,val
);
92 old
= amiga_read_control(p
);
93 amiga_write_control(p
, (old
& ~mask
) ^ val
);
98 static unsigned char status_pc_to_amiga(unsigned char status
)
100 unsigned char ret
= 1;
102 if (status
& PARPORT_STATUS_BUSY
) /* Busy */
104 if (status
& PARPORT_STATUS_ACK
) /* Ack */
105 /* handled in hardware */;
106 if (status
& PARPORT_STATUS_PAPEROUT
) /* PaperOut */
108 if (status
& PARPORT_STATUS_SELECT
) /* select */
110 if (status
& PARPORT_STATUS_ERROR
) /* error */
115 static unsigned char status_amiga_to_pc(unsigned char status
)
117 unsigned char ret
= PARPORT_STATUS_BUSY
| PARPORT_STATUS_ACK
| PARPORT_STATUS_ERROR
;
119 if (status
& 1) /* Busy */
120 ret
&= ~PARPORT_STATUS_BUSY
;
121 if (status
& 2) /* PaperOut */
122 ret
|= PARPORT_STATUS_PAPEROUT
;
123 if (status
& 4) /* Selected */
124 ret
|= PARPORT_STATUS_SELECT
;
125 /* the rest is not connected or handled autonomously in hardware */
130 static void amiga_write_status( struct parport
*p
, unsigned char status
)
132 DPRINTK("write_status %02x\n",status
);
133 ciab
.pra
|= (ciab
.pra
& 0xf8) | status_pc_to_amiga(status
);
136 static unsigned char amiga_read_status(struct parport
*p
)
138 unsigned char status
;
140 status
= status_amiga_to_pc(ciab
.pra
& 7);
141 DPRINTK("read_status %02x\n", status
);
145 static void amiga_change_mode( struct parport
*p
, int m
)
147 /* XXX: This port only has one mode, and I am
148 not sure about the corresponding PC-style mode*/
151 /* as this ports irq handling is already done, we use a generic funktion */
152 static void amiga_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
154 parport_generic_irq(irq
, (struct parport
*) dev_id
, regs
);
158 static void amiga_init_state(struct parport_state
*s
)
161 s
->u
.amiga
.datadir
= 255;
162 s
->u
.amiga
.status
= 0;
163 s
->u
.amiga
.statusdir
= 0;
166 static void amiga_save_state(struct parport
*p
, struct parport_state
*s
)
168 s
->u
.amiga
.data
= ciaa
.prb
;
169 s
->u
.amiga
.datadir
= ciaa
.ddrb
;
170 s
->u
.amiga
.status
= ciab
.pra
& 7;
171 s
->u
.amiga
.statusdir
= ciab
.ddra
& 7;
174 static void amiga_restore_state(struct parport
*p
, struct parport_state
*s
)
176 ciaa
.prb
= s
->u
.amiga
.data
;
177 ciaa
.ddrb
= s
->u
.amiga
.datadir
;
178 ciab
.pra
|= (ciab
.pra
& 0xf8) | s
->u
.amiga
.status
;
179 ciab
.ddra
|= (ciab
.ddra
& 0xf8) | s
->u
.amiga
.statusdir
;
182 static void amiga_enable_irq(struct parport
*p
)
184 enable_irq(IRQ_AMIGA_CIAA_FLG
);
187 static void amiga_disable_irq(struct parport
*p
)
189 disable_irq(IRQ_AMIGA_CIAA_FLG
);
192 static void amiga_inc_use_count(void)
197 static void amiga_dec_use_count(void)
202 static void amiga_fill_inode(struct inode
*inode
, int fill
)
212 static struct parport_operations pp_amiga_ops
= {
220 NULL
, /* write_econtrol */
221 NULL
, /* read_econtrol */
222 NULL
, /* frob_econtrol */
227 NULL
, /* write fifo */
228 NULL
, /* read fifo */
233 NULL
, /* epp_write_data */
234 NULL
, /* epp_read_data */
235 NULL
, /* epp_write_addr */
236 NULL
, /* epp_read_addr */
237 NULL
, /* epp_check_timeout */
239 NULL
, /* epp_write_block */
240 NULL
, /* epp_read_block */
242 NULL
, /* ecp_write_block */
243 NULL
, /* ecp_read_block */
258 /* ----------- Initialisation code --------------------------------- */
260 __initfunc(int parport_amiga_init(void))
264 if (MACH_IS_AMIGA
&& AMIGAHW_PRESENT(AMI_PARALLEL
)) {
267 if (!(p
= parport_register_port((unsigned long)&ciaa
.prb
,
268 IRQ_AMIGA_CIAA_FLG
, PARPORT_DMA_NONE
,
272 printk(KERN_INFO
"%s: Amiga built-in port using irq\n", p
->name
);
273 /* XXX: set operating mode */
274 parport_proc_register(p
);
275 if (request_irq(IRQ_AMIGA_CIAA_FLG
, amiga_interrupt
, 0,
277 parport_unregister_port (p
);
281 if (parport_probe_hook
)
282 (*parport_probe_hook
)(p
);
284 parport_announce_port (p
);
294 MODULE_AUTHOR("Joerg Dorchain");
295 MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
296 MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port");
298 int init_module(void)
300 return ! parport_amiga_init();
303 void cleanup_module(void)
305 if (p
->irq
!= PARPORT_IRQ_NONE
)
306 free_irq(IRQ_AMIGA_CIAA_FLG
, p
);
307 parport_proc_unregister(this_port
);
308 parport_unregister_port(this_port
);