Blame view

drivers/parport/parport_amiga.c 7.46 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  /* Low-level parallel port routines for the Amiga built-in port
   *
   * Author: Joerg Dorchain <joerg@dorchain.net>
   *
   * This is a complete rewrite of the code, but based heaviy upon the old
   * lp_intern. code.
   *
   * The built-in Amiga parallel port provides one port at a fixed address
   * with 8 bidirectional data lines (D0 - D7) and 3 bidirectional status
   * lines (BUSY, POUT, SEL), 1 output control line /STROBE (raised automatically
   * in hardware when the data register is accessed), and 1 input control line
   * /ACK, able to cause an interrupt, but both not directly settable by
   * software.
   */
  
  #include <linux/module.h>
  #include <linux/init.h>
  #include <linux/parport.h>
  #include <linux/ioport.h>
  #include <linux/interrupt.h>
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
21
  #include <linux/platform_device.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
22
23
24
25
26
27
28
29
30
31
32
33
  #include <asm/setup.h>
  #include <asm/amigahw.h>
  #include <asm/irq.h>
  #include <asm/io.h>
  #include <asm/amigaints.h>
  
  #undef DEBUG
  #ifdef DEBUG
  #define DPRINTK printk
  #else
  #define DPRINTK(x...)	do { } while (0)
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
  
  static void amiga_write_data(struct parport *p, unsigned char data)
  {
  	DPRINTK(KERN_DEBUG "write_data %c
  ",data);
  	/* Triggers also /STROBE. This behavior cannot be changed */
  	ciaa.prb = data;
  	mb();
  }
  
  static unsigned char amiga_read_data(struct parport *p)
  {
  	/* Triggers also /STROBE. This behavior cannot be changed */
  	return ciaa.prb;
  }
  
  #if 0
  static unsigned char control_pc_to_amiga(unsigned char control)
  {
  	unsigned char ret = 0;
  
  	if (control & PARPORT_CONTROL_SELECT) /* XXX: What is SELECP? */
  		;
  	if (control & PARPORT_CONTROL_INIT) /* INITP */
  		/* reset connected to cpu reset pin */;
  	if (control & PARPORT_CONTROL_AUTOFD) /* AUTOLF */
  		/* Not connected */;
  	if (control & PARPORT_CONTROL_STROBE) /* Strobe */
  		/* Handled only directly by hardware */;
  	return ret;
  }
  #endif
  
  static unsigned char control_amiga_to_pc(unsigned char control)
  {
  	return PARPORT_CONTROL_SELECT |
  	      PARPORT_CONTROL_AUTOFD | PARPORT_CONTROL_STROBE;
  	/* fake value: interrupt enable, select in, no reset,
  	no autolf, no strobe - seems to be closest the wiring diagram */
  }
  
  static void amiga_write_control(struct parport *p, unsigned char control)
  {
  	DPRINTK(KERN_DEBUG "write_control %02x
  ",control);
  	/* No implementation possible */
  }
  	
  static unsigned char amiga_read_control( struct parport *p)
  {
  	DPRINTK(KERN_DEBUG "read_control 
  ");
  	return control_amiga_to_pc(0);
  }
  
  static unsigned char amiga_frob_control( struct parport *p, unsigned char mask, unsigned char val)
  {
  	unsigned char old;
  
  	DPRINTK(KERN_DEBUG "frob_control mask %02x, value %02x
  ",mask,val);
  	old = amiga_read_control(p);
  	amiga_write_control(p, (old & ~mask) ^ val);
  	return old;
  }
  
  #if 0 /* currently unused */
  static unsigned char status_pc_to_amiga(unsigned char status)
  {
  	unsigned char ret = 1;
  
  	if (status & PARPORT_STATUS_BUSY) /* Busy */
  		ret &= ~1;
  	if (status & PARPORT_STATUS_ACK) /* Ack */
  		/* handled in hardware */;
  	if (status & PARPORT_STATUS_PAPEROUT) /* PaperOut */
  		ret |= 2;
  	if (status & PARPORT_STATUS_SELECT) /* select */
  		ret |= 4;
  	if (status & PARPORT_STATUS_ERROR) /* error */
  		/* not connected */;
  	return ret;
  }
  #endif
  
  static unsigned char status_amiga_to_pc(unsigned char status)
  {
  	unsigned char ret = PARPORT_STATUS_BUSY | PARPORT_STATUS_ACK | PARPORT_STATUS_ERROR;
  
  	if (status & 1) /* Busy */
  		ret &= ~PARPORT_STATUS_BUSY;
  	if (status & 2) /* PaperOut */
  		ret |= PARPORT_STATUS_PAPEROUT;
  	if (status & 4) /* Selected */
  		ret |= PARPORT_STATUS_SELECT;
  	/* the rest is not connected or handled autonomously in hardware */
  
  	return ret;
  }
  
  static unsigned char amiga_read_status(struct parport *p)
  {
  	unsigned char status;
  
  	status = status_amiga_to_pc(ciab.pra & 7);
  	DPRINTK(KERN_DEBUG "read_status %02x
  ", status);
  	return status;
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  static void amiga_enable_irq(struct parport *p)
  {
  	enable_irq(IRQ_AMIGA_CIAA_FLG);
  }
  
  static void amiga_disable_irq(struct parport *p)
  {
  	disable_irq(IRQ_AMIGA_CIAA_FLG);
  }
  
  static void amiga_data_forward(struct parport *p)
  {
  	DPRINTK(KERN_DEBUG "forward
  ");
  	ciaa.ddrb = 0xff; /* all pins output */
  	mb();
  }
  
  static void amiga_data_reverse(struct parport *p)
  {
  	DPRINTK(KERN_DEBUG "reverse
  ");
  	ciaa.ddrb = 0; /* all pins input */
  	mb();
  }
  
  static void amiga_init_state(struct pardevice *dev, struct parport_state *s)
  {
  	s->u.amiga.data = 0;
  	s->u.amiga.datadir = 255;
  	s->u.amiga.status = 0;
  	s->u.amiga.statusdir = 0;
  }
  
  static void amiga_save_state(struct parport *p, struct parport_state *s)
  {
  	mb();
  	s->u.amiga.data = ciaa.prb;
  	s->u.amiga.datadir = ciaa.ddrb;
  	s->u.amiga.status = ciab.pra & 7;
  	s->u.amiga.statusdir = ciab.ddra & 7;
  	mb();
  }
  
  static void amiga_restore_state(struct parport *p, struct parport_state *s)
  {
  	mb();
  	ciaa.prb = s->u.amiga.data;
  	ciaa.ddrb = s->u.amiga.datadir;
  	ciab.pra |= (ciab.pra & 0xf8) | s->u.amiga.status;
  	ciab.ddra |= (ciab.ddra & 0xf8) | s->u.amiga.statusdir;
  	mb();
  }
  
  static struct parport_operations pp_amiga_ops = {
  	.write_data	= amiga_write_data,
  	.read_data	= amiga_read_data,
  
  	.write_control	= amiga_write_control,
  	.read_control	= amiga_read_control,
  	.frob_control	= amiga_frob_control,
  
  	.read_status	= amiga_read_status,
  
  	.enable_irq	= amiga_enable_irq,
  	.disable_irq	= amiga_disable_irq,
  
  	.data_forward	= amiga_data_forward,
  	.data_reverse	= amiga_data_reverse,
  
  	.init_state	= amiga_init_state,
  	.save_state	= amiga_save_state,
  	.restore_state	= amiga_restore_state,
  
  	.epp_write_data	= parport_ieee1284_epp_write_data,
  	.epp_read_data	= parport_ieee1284_epp_read_data,
  	.epp_write_addr	= parport_ieee1284_epp_write_addr,
  	.epp_read_addr	= parport_ieee1284_epp_read_addr,
  
  	.ecp_write_data	= parport_ieee1284_ecp_write_data,
  	.ecp_read_data	= parport_ieee1284_ecp_read_data,
  	.ecp_write_addr	= parport_ieee1284_ecp_write_addr,
  
  	.compat_write_data	= parport_ieee1284_write_compat,
  	.nibble_read_data	= parport_ieee1284_read_nibble,
  	.byte_read_data		= parport_ieee1284_read_byte,
  
  	.owner		= THIS_MODULE,
  };
  
  /* ----------- Initialisation code --------------------------------- */
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
234
  static int __init amiga_parallel_probe(struct platform_device *pdev)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
235
236
237
  {
  	struct parport *p;
  	int err;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
240
241
242
243
244
  	ciaa.ddrb = 0xff;
  	ciab.ddra &= 0xf8;
  	mb();
  
  	p = parport_register_port((unsigned long)&ciaa.prb, IRQ_AMIGA_CIAA_FLG,
  				   PARPORT_DMA_NONE, &pp_amiga_ops);
  	if (!p)
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
245
  		return -EBUSY;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
246

6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
247
248
  	err = request_irq(IRQ_AMIGA_CIAA_FLG, parport_irq_handler, 0, p->name,
  			  p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
249
250
  	if (err)
  		goto out_irq;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251
252
253
254
  	printk(KERN_INFO "%s: Amiga built-in port using irq
  ", p->name);
  	/* XXX: set operating mode */
  	parport_announce_port(p);
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
255
  	platform_set_drvdata(pdev, p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
256
257
258
259
  	return 0;
  
  out_irq:
  	parport_put_port(p);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
260
261
  	return err;
  }
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
  static int __exit amiga_parallel_remove(struct platform_device *pdev)
  {
  	struct parport *port = platform_get_drvdata(pdev);
  
  	parport_remove_port(port);
  	if (port->irq != PARPORT_IRQ_NONE)
  		free_irq(IRQ_AMIGA_CIAA_FLG, port);
  	parport_put_port(port);
  	platform_set_drvdata(pdev, NULL);
  	return 0;
  }
  
  static struct platform_driver amiga_parallel_driver = {
  	.remove = __exit_p(amiga_parallel_remove),
  	.driver   = {
  		.name	= "amiga-parallel",
  		.owner	= THIS_MODULE,
  	},
  };
  
  static int __init amiga_parallel_init(void)
  {
  	return platform_driver_probe(&amiga_parallel_driver,
  				     amiga_parallel_probe);
  }
  
  module_init(amiga_parallel_init);
  
  static void __exit amiga_parallel_exit(void)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
291
  {
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
292
  	platform_driver_unregister(&amiga_parallel_driver);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
293
  }
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
294
  module_exit(amiga_parallel_exit);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
295
296
297
298
299
  
  MODULE_AUTHOR("Joerg Dorchain <joerg@dorchain.net>");
  MODULE_DESCRIPTION("Parport Driver for Amiga builtin Port");
  MODULE_SUPPORTED_DEVICE("Amiga builtin Parallel Port");
  MODULE_LICENSE("GPL");
6f8221c26   Geert Uytterhoeven   m68k: amiga - Par...
300
  MODULE_ALIAS("platform:amiga-parallel");