This source file includes following definitions.
- clear_epp_timeout
- parport_gsc_init_state
- parport_gsc_save_state
- parport_gsc_restore_state
- parport_SPP_supported
- parport_PS2_supported
- parport_gsc_probe_port
- parport_init_chip
- parport_remove_chip
- parport_gsc_init
- parport_gsc_exit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 #undef DEBUG
18
19 #include <linux/module.h>
20 #include <linux/init.h>
21 #include <linux/delay.h>
22 #include <linux/errno.h>
23 #include <linux/interrupt.h>
24 #include <linux/ioport.h>
25 #include <linux/kernel.h>
26 #include <linux/slab.h>
27 #include <linux/pci.h>
28 #include <linux/sysctl.h>
29
30 #include <asm/io.h>
31 #include <asm/dma.h>
32 #include <linux/uaccess.h>
33 #include <asm/superio.h>
34
35 #include <linux/parport.h>
36 #include <asm/pdc.h>
37 #include <asm/parisc-device.h>
38 #include <asm/hardware.h>
39 #include "parport_gsc.h"
40
41
42 MODULE_AUTHOR("Helge Deller <deller@gmx.de>");
43 MODULE_DESCRIPTION("HP-PARISC PC-style parallel port driver");
44 MODULE_SUPPORTED_DEVICE("integrated PC-style parallel port");
45 MODULE_LICENSE("GPL");
46
47
48
49
50
51
52
53 static int clear_epp_timeout(struct parport *pb)
54 {
55 unsigned char r;
56
57 if (!(parport_gsc_read_status(pb) & 0x01))
58 return 1;
59
60
61 parport_gsc_read_status(pb);
62 r = parport_gsc_read_status(pb);
63 parport_writeb (r | 0x01, STATUS (pb));
64 parport_writeb (r & 0xfe, STATUS (pb));
65 r = parport_gsc_read_status(pb);
66
67 return !(r & 0x01);
68 }
69
70
71
72
73
74
75
76
77
78 void parport_gsc_init_state(struct pardevice *dev, struct parport_state *s)
79 {
80 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
81 }
82
83 void parport_gsc_save_state(struct parport *p, struct parport_state *s)
84 {
85 s->u.pc.ctr = parport_readb (CONTROL (p));
86 }
87
88 void parport_gsc_restore_state(struct parport *p, struct parport_state *s)
89 {
90 parport_writeb (s->u.pc.ctr, CONTROL (p));
91 }
92
93 struct parport_operations parport_gsc_ops =
94 {
95 .write_data = parport_gsc_write_data,
96 .read_data = parport_gsc_read_data,
97
98 .write_control = parport_gsc_write_control,
99 .read_control = parport_gsc_read_control,
100 .frob_control = parport_gsc_frob_control,
101
102 .read_status = parport_gsc_read_status,
103
104 .enable_irq = parport_gsc_enable_irq,
105 .disable_irq = parport_gsc_disable_irq,
106
107 .data_forward = parport_gsc_data_forward,
108 .data_reverse = parport_gsc_data_reverse,
109
110 .init_state = parport_gsc_init_state,
111 .save_state = parport_gsc_save_state,
112 .restore_state = parport_gsc_restore_state,
113
114 .epp_write_data = parport_ieee1284_epp_write_data,
115 .epp_read_data = parport_ieee1284_epp_read_data,
116 .epp_write_addr = parport_ieee1284_epp_write_addr,
117 .epp_read_addr = parport_ieee1284_epp_read_addr,
118
119 .ecp_write_data = parport_ieee1284_ecp_write_data,
120 .ecp_read_data = parport_ieee1284_ecp_read_data,
121 .ecp_write_addr = parport_ieee1284_ecp_write_addr,
122
123 .compat_write_data = parport_ieee1284_write_compat,
124 .nibble_read_data = parport_ieee1284_read_nibble,
125 .byte_read_data = parport_ieee1284_read_byte,
126
127 .owner = THIS_MODULE,
128 };
129
130
131
132
133
134
135 static int parport_SPP_supported(struct parport *pb)
136 {
137 unsigned char r, w;
138
139
140
141
142
143
144
145 clear_epp_timeout(pb);
146
147
148 w = 0xc;
149 parport_writeb (w, CONTROL (pb));
150
151
152
153
154
155
156 r = parport_readb (CONTROL (pb));
157 if ((r & 0xf) == w) {
158 w = 0xe;
159 parport_writeb (w, CONTROL (pb));
160 r = parport_readb (CONTROL (pb));
161 parport_writeb (0xc, CONTROL (pb));
162 if ((r & 0xf) == w)
163 return PARPORT_MODE_PCSPP;
164 }
165
166
167
168 w = 0xaa;
169 parport_gsc_write_data (pb, w);
170 r = parport_gsc_read_data (pb);
171 if (r == w) {
172 w = 0x55;
173 parport_gsc_write_data (pb, w);
174 r = parport_gsc_read_data (pb);
175 if (r == w)
176 return PARPORT_MODE_PCSPP;
177 }
178
179 return 0;
180 }
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199 static int parport_PS2_supported(struct parport *pb)
200 {
201 int ok = 0;
202
203 clear_epp_timeout(pb);
204
205
206 parport_gsc_data_reverse (pb);
207
208 parport_gsc_write_data(pb, 0x55);
209 if (parport_gsc_read_data(pb) != 0x55) ok++;
210
211 parport_gsc_write_data(pb, 0xaa);
212 if (parport_gsc_read_data(pb) != 0xaa) ok++;
213
214
215 parport_gsc_data_forward (pb);
216
217 if (ok) {
218 pb->modes |= PARPORT_MODE_TRISTATE;
219 } else {
220 struct parport_gsc_private *priv = pb->private_data;
221 priv->ctr_writable &= ~0x20;
222 }
223
224 return ok;
225 }
226
227
228
229
230 struct parport *parport_gsc_probe_port(unsigned long base,
231 unsigned long base_hi, int irq,
232 int dma, struct parisc_device *padev)
233 {
234 struct parport_gsc_private *priv;
235 struct parport_operations *ops;
236 struct parport tmp;
237 struct parport *p = &tmp;
238
239 priv = kzalloc (sizeof (struct parport_gsc_private), GFP_KERNEL);
240 if (!priv) {
241 printk (KERN_DEBUG "parport (0x%lx): no memory!\n", base);
242 return NULL;
243 }
244 ops = kmemdup(&parport_gsc_ops, sizeof(struct parport_operations),
245 GFP_KERNEL);
246 if (!ops) {
247 printk (KERN_DEBUG "parport (0x%lx): no memory for ops!\n",
248 base);
249 kfree (priv);
250 return NULL;
251 }
252 priv->ctr = 0xc;
253 priv->ctr_writable = 0xff;
254 priv->dma_buf = NULL;
255 priv->dma_handle = 0;
256 p->base = base;
257 p->base_hi = base_hi;
258 p->irq = irq;
259 p->dma = dma;
260 p->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_SAFEININT;
261 p->ops = ops;
262 p->private_data = priv;
263 p->physport = p;
264 if (!parport_SPP_supported (p)) {
265
266 kfree (priv);
267 kfree(ops);
268 return NULL;
269 }
270 parport_PS2_supported (p);
271
272 if (!(p = parport_register_port(base, PARPORT_IRQ_NONE,
273 PARPORT_DMA_NONE, ops))) {
274 kfree (priv);
275 kfree (ops);
276 return NULL;
277 }
278
279 p->dev = &padev->dev;
280 p->base_hi = base_hi;
281 p->modes = tmp.modes;
282 p->size = (p->modes & PARPORT_MODE_EPP)?8:3;
283 p->private_data = priv;
284
285 printk(KERN_INFO "%s: PC-style at 0x%lx", p->name, p->base);
286 p->irq = irq;
287 if (p->irq == PARPORT_IRQ_AUTO) {
288 p->irq = PARPORT_IRQ_NONE;
289 }
290 if (p->irq != PARPORT_IRQ_NONE) {
291 pr_cont(", irq %d", p->irq);
292
293 if (p->dma == PARPORT_DMA_AUTO) {
294 p->dma = PARPORT_DMA_NONE;
295 }
296 }
297 if (p->dma == PARPORT_DMA_AUTO)
298
299 p->dma = PARPORT_DMA_NONE;
300
301 pr_cont(" [");
302 #define printmode(x) {if(p->modes&PARPORT_MODE_##x){pr_cont("%s%s",f?",":"",#x);f++;}}
303 {
304 int f = 0;
305 printmode(PCSPP);
306 printmode(TRISTATE);
307 printmode(COMPAT)
308 printmode(EPP);
309
310
311 }
312 #undef printmode
313 pr_cont("]\n");
314
315 if (p->irq != PARPORT_IRQ_NONE) {
316 if (request_irq (p->irq, parport_irq_handler,
317 0, p->name, p)) {
318 printk (KERN_WARNING "%s: irq %d in use, "
319 "resorting to polled operation\n",
320 p->name, p->irq);
321 p->irq = PARPORT_IRQ_NONE;
322 p->dma = PARPORT_DMA_NONE;
323 }
324 }
325
326
327
328 parport_gsc_write_data(p, 0);
329 parport_gsc_data_forward (p);
330
331
332
333
334 parport_announce_port (p);
335
336 return p;
337 }
338
339
340 #define PARPORT_GSC_OFFSET 0x800
341
342 static int parport_count;
343
344 static int __init parport_init_chip(struct parisc_device *dev)
345 {
346 struct parport *p;
347 unsigned long port;
348
349 if (!dev->irq) {
350 printk(KERN_WARNING "IRQ not found for parallel device at 0x%llx\n",
351 (unsigned long long)dev->hpa.start);
352 return -ENODEV;
353 }
354
355 port = dev->hpa.start + PARPORT_GSC_OFFSET;
356
357
358
359
360 if (boot_cpu_data.cpu_type > pcxt && !pdc_add_valid(port+4)) {
361
362
363 printk("%s: initialize bidirectional-mode.\n", __func__);
364 parport_writeb ( (0x10 + 0x20), port + 4);
365
366 } else {
367 printk("%s: enhanced parport-modes not supported.\n", __func__);
368 }
369
370 p = parport_gsc_probe_port(port, 0, dev->irq,
371 PARPORT_DMA_NONE, dev);
372 if (p)
373 parport_count++;
374 dev_set_drvdata(&dev->dev, p);
375
376 return 0;
377 }
378
379 static int __exit parport_remove_chip(struct parisc_device *dev)
380 {
381 struct parport *p = dev_get_drvdata(&dev->dev);
382 if (p) {
383 struct parport_gsc_private *priv = p->private_data;
384 struct parport_operations *ops = p->ops;
385 parport_remove_port(p);
386 if (p->dma != PARPORT_DMA_NONE)
387 free_dma(p->dma);
388 if (p->irq != PARPORT_IRQ_NONE)
389 free_irq(p->irq, p);
390 if (priv->dma_buf)
391 pci_free_consistent(priv->dev, PAGE_SIZE,
392 priv->dma_buf,
393 priv->dma_handle);
394 kfree (p->private_data);
395 parport_put_port(p);
396 kfree (ops);
397 }
398 return 0;
399 }
400
401 static const struct parisc_device_id parport_tbl[] __initconst = {
402 { HPHW_FIO, HVERSION_REV_ANY_ID, HVERSION_ANY_ID, 0x74 },
403 { 0, }
404 };
405
406 MODULE_DEVICE_TABLE(parisc, parport_tbl);
407
408 static struct parisc_driver parport_driver __refdata = {
409 .name = "Parallel",
410 .id_table = parport_tbl,
411 .probe = parport_init_chip,
412 .remove = __exit_p(parport_remove_chip),
413 };
414
415 int parport_gsc_init(void)
416 {
417 return register_parisc_driver(&parport_driver);
418 }
419
420 static void parport_gsc_exit(void)
421 {
422 unregister_parisc_driver(&parport_driver);
423 }
424
425 module_init(parport_gsc_init);
426 module_exit(parport_gsc_exit);