Import 2.3.12pre1
[davej-history.git] / drivers / misc / parport_amiga.c
blobeebd44cbc1c90002d9d2a97747ac0e28fc8e0eb3
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
6 * lp_intern. code.
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
13 * software.
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>
21 #include <asm/irq.h>
22 #include <asm/amigaints.h>
24 #undef DEBUG
25 #ifdef DEBUG
26 #define DPRINTK printk
27 #else
28 static inline int DPRINTK() {return 0;}
29 #endif
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 */
37 ciaa.prb = data;
40 static unsigned char amiga_read_data(struct parport *p)
42 /* Triggers also /STROBE. This behavior cannot be changed */
43 return ciaa.prb;
46 #if 0
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 */
60 /* Not connected */;
61 if (control & PARPORT_CONTROL_STROBE) /* Strobe */
62 /* Handled only directly by hardware */;
63 return ret;
65 #endif
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)
89 unsigned char old;
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);
94 return old;
98 static unsigned char status_pc_to_amiga(unsigned char status)
100 unsigned char ret = 1;
102 if (status & PARPORT_STATUS_BUSY) /* Busy */
103 ret &= ~1;
104 if (status & PARPORT_STATUS_ACK) /* Ack */
105 /* handled in hardware */;
106 if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */
107 ret |= 2;
108 if (status & PARPORT_STATUS_SELECT) /* select */
109 ret |= 4;
110 if (status & PARPORT_STATUS_ERROR) /* error */
111 /* not connected */;
112 return ret;
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 */
127 return ret;
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);
142 return 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)
160 s->u.amiga.data = 0;
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)
194 MOD_INC_USE_COUNT;
197 static void amiga_dec_use_count(void)
199 MOD_DEC_USE_COUNT;
202 static void amiga_fill_inode(struct inode *inode, int fill)
204 #ifdef MODULE
205 if (fill)
206 MOD_INC_USE_COUNT;
207 else
208 MOD_DEC_USE_COUNT;
209 #endif
212 static struct parport_operations pp_amiga_ops = {
213 amiga_write_data,
214 amiga_read_data,
216 amiga_write_control,
217 amiga_read_control,
218 amiga_frob_control,
220 NULL, /* write_econtrol */
221 NULL, /* read_econtrol */
222 NULL, /* frob_econtrol */
224 amiga_write_status,
225 amiga_read_status,
227 NULL, /* write fifo */
228 NULL, /* read fifo */
230 amiga_change_mode,
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 */
245 amiga_init_state,
246 amiga_save_state,
247 amiga_restore_state,
249 amiga_enable_irq,
250 amiga_disable_irq,
251 amiga_interrupt,
253 amiga_inc_use_count,
254 amiga_dec_use_count,
255 amiga_fill_inode
258 /* ----------- Initialisation code --------------------------------- */
260 __initfunc(int parport_amiga_init(void))
262 struct parport *p;
264 if (MACH_IS_AMIGA && AMIGAHW_PRESENT(AMI_PARALLEL)) {
265 ciaa.ddrb = 0xff;
266 ciab.ddra &= 0xf8;
267 if (!(p = parport_register_port((unsigned long)&ciaa.prb,
268 IRQ_AMIGA_CIAA_FLG, PARPORT_DMA_NONE,
269 &pp_amiga_ops)))
270 return 0;
271 this_port = p;
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,
276 p->name, p)) {
277 parport_unregister_port (p);
278 return 0;
281 if (parport_probe_hook)
282 (*parport_probe_hook)(p);
284 parport_announce_port (p);
286 return 1;
289 return 0;
292 #ifdef MODULE
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);
310 #endif