USB: fix needless failure under certain conditions
[wandboard.git] / drivers / usb / misc / uss720.c
blob70250252ae2ae404d30f5583d4396a6e70f590fa
1 /*****************************************************************************/
3 /*
4 * uss720.c -- USS720 USB Parport Cable.
6 * Copyright (C) 1999, 2005
7 * Thomas Sailer (t.sailer@alumni.ethz.ch)
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 * Based on parport_pc.c
25 * History:
26 * 0.1 04.08.1999 Created
27 * 0.2 07.08.1999 Some fixes mainly suggested by Tim Waugh
28 * Interrupt handling currently disabled because
29 * usb_request_irq crashes somewhere within ohci.c
30 * for no apparent reason (that is for me, anyway)
31 * ECP currently untested
32 * 0.3 10.08.1999 fixing merge errors
33 * 0.4 13.08.1999 Added Vendor/Product ID of Brad Hard's cable
34 * 0.5 20.09.1999 usb_control_msg wrapper used
35 * Nov01.2000 usb_device_table support by Adam J. Richter
36 * 08.04.2001 Identify version on module load. gb
37 * 0.6 02.09.2005 Fix "scheduling in interrupt" problem by making save/restore
38 * context asynchronous
42 /*****************************************************************************/
44 #include <linux/module.h>
45 #include <linux/socket.h>
46 #include <linux/parport.h>
47 #include <linux/init.h>
48 #include <linux/usb.h>
49 #include <linux/delay.h>
50 #include <linux/completion.h>
51 #include <linux/kref.h>
54 * Version Information
56 #define DRIVER_VERSION "v0.6"
57 #define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch"
58 #define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
60 /* --------------------------------------------------------------------- */
62 struct parport_uss720_private {
63 struct usb_device *usbdev;
64 struct parport *pp;
65 struct kref ref_count;
66 __u8 reg[7]; /* USB registers */
67 struct list_head asynclist;
68 spinlock_t asynclock;
71 struct uss720_async_request {
72 struct parport_uss720_private *priv;
73 struct kref ref_count;
74 struct list_head asynclist;
75 struct completion compl;
76 struct urb *urb;
77 struct usb_ctrlrequest dr;
78 __u8 reg[7];
81 /* --------------------------------------------------------------------- */
83 static void destroy_priv(struct kref *kref)
85 struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
87 usb_put_dev(priv->usbdev);
88 kfree(priv);
89 dbg("destroying priv datastructure");
92 static void destroy_async(struct kref *kref)
94 struct uss720_async_request *rq = container_of(kref, struct uss720_async_request, ref_count);
95 struct parport_uss720_private *priv = rq->priv;
96 unsigned long flags;
98 if (likely(rq->urb))
99 usb_free_urb(rq->urb);
100 spin_lock_irqsave(&priv->asynclock, flags);
101 list_del_init(&rq->asynclist);
102 spin_unlock_irqrestore(&priv->asynclock, flags);
103 kfree(rq);
104 kref_put(&priv->ref_count, destroy_priv);
107 /* --------------------------------------------------------------------- */
109 static void async_complete(struct urb *urb)
111 struct uss720_async_request *rq;
112 struct parport *pp;
113 struct parport_uss720_private *priv;
115 rq = urb->context;
116 priv = rq->priv;
117 pp = priv->pp;
118 if (urb->status) {
119 err("async_complete: urb error %d", urb->status);
120 } else if (rq->dr.bRequest == 3) {
121 memcpy(priv->reg, rq->reg, sizeof(priv->reg));
122 #if 0
123 dbg("async_complete regs %02x %02x %02x %02x %02x %02x %02x",
124 (unsigned int)priv->reg[0], (unsigned int)priv->reg[1], (unsigned int)priv->reg[2],
125 (unsigned int)priv->reg[3], (unsigned int)priv->reg[4], (unsigned int)priv->reg[5],
126 (unsigned int)priv->reg[6]);
127 #endif
128 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
129 if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
130 parport_generic_irq(0, pp);
132 complete(&rq->compl);
133 kref_put(&rq->ref_count, destroy_async);
136 static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
137 __u8 request, __u8 requesttype, __u16 value, __u16 index,
138 gfp_t mem_flags)
140 struct usb_device *usbdev;
141 struct uss720_async_request *rq;
142 unsigned long flags;
143 int ret;
145 if (!priv)
146 return NULL;
147 usbdev = priv->usbdev;
148 if (!usbdev)
149 return NULL;
150 rq = kmalloc(sizeof(struct uss720_async_request), mem_flags);
151 if (!rq) {
152 err("submit_async_request out of memory");
153 return NULL;
155 kref_init(&rq->ref_count);
156 INIT_LIST_HEAD(&rq->asynclist);
157 init_completion(&rq->compl);
158 kref_get(&priv->ref_count);
159 rq->priv = priv;
160 rq->urb = usb_alloc_urb(0, mem_flags);
161 if (!rq->urb) {
162 kref_put(&rq->ref_count, destroy_async);
163 err("submit_async_request out of memory");
164 return NULL;
166 rq->dr.bRequestType = requesttype;
167 rq->dr.bRequest = request;
168 rq->dr.wValue = cpu_to_le16(value);
169 rq->dr.wIndex = cpu_to_le16(index);
170 rq->dr.wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
171 usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
172 (unsigned char *)&rq->dr,
173 (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
174 /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
175 spin_lock_irqsave(&priv->asynclock, flags);
176 list_add_tail(&rq->asynclist, &priv->asynclist);
177 spin_unlock_irqrestore(&priv->asynclock, flags);
178 ret = usb_submit_urb(rq->urb, mem_flags);
179 if (!ret) {
180 kref_get(&rq->ref_count);
181 return rq;
183 kref_put(&rq->ref_count, destroy_async);
184 err("submit_async_request submit_urb failed with %d", ret);
185 return NULL;
188 static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
190 struct uss720_async_request *rq;
191 unsigned long flags;
192 unsigned int ret = 0;
194 spin_lock_irqsave(&priv->asynclock, flags);
195 list_for_each_entry(rq, &priv->asynclist, asynclist) {
196 usb_unlink_urb(rq->urb);
197 ret++;
199 spin_unlock_irqrestore(&priv->asynclock, flags);
200 return ret;
203 /* --------------------------------------------------------------------- */
205 static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
207 struct parport_uss720_private *priv;
208 struct uss720_async_request *rq;
209 static const unsigned char regindex[9] = {
210 4, 0, 1, 5, 5, 0, 2, 3, 6
212 int ret;
214 if (!pp)
215 return -EIO;
216 priv = pp->private_data;
217 rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
218 if (!rq) {
219 err("get_1284_register(%u) failed", (unsigned int)reg);
220 return -EIO;
222 if (!val) {
223 kref_put(&rq->ref_count, destroy_async);
224 return 0;
226 if (wait_for_completion_timeout(&rq->compl, HZ)) {
227 ret = rq->urb->status;
228 *val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
229 if (ret)
230 warn("get_1284_register: usb error %d", ret);
231 kref_put(&rq->ref_count, destroy_async);
232 return ret;
234 warn("get_1284_register timeout");
235 kill_all_async_requests_priv(priv);
236 return -EIO;
239 static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
241 struct parport_uss720_private *priv;
242 struct uss720_async_request *rq;
244 if (!pp)
245 return -EIO;
246 priv = pp->private_data;
247 rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
248 if (!rq) {
249 err("set_1284_register(%u,%u) failed", (unsigned int)reg, (unsigned int)val);
250 return -EIO;
252 kref_put(&rq->ref_count, destroy_async);
253 return 0;
256 /* --------------------------------------------------------------------- */
258 /* ECR modes */
259 #define ECR_SPP 00
260 #define ECR_PS2 01
261 #define ECR_PPF 02
262 #define ECR_ECP 03
263 #define ECR_EPP 04
265 /* Safely change the mode bits in the ECR */
266 static int change_mode(struct parport *pp, int m)
268 struct parport_uss720_private *priv = pp->private_data;
269 int mode;
270 __u8 reg;
272 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
273 return -EIO;
274 /* Bits <7:5> contain the mode. */
275 mode = (priv->reg[2] >> 5) & 0x7;
276 if (mode == m)
277 return 0;
278 /* We have to go through mode 000 or 001 */
279 if (mode > ECR_PS2 && m > ECR_PS2)
280 if (change_mode(pp, ECR_PS2))
281 return -EIO;
283 if (m <= ECR_PS2 && !(priv->reg[1] & 0x20)) {
284 /* This mode resets the FIFO, so we may
285 * have to wait for it to drain first. */
286 unsigned long expire = jiffies + pp->physport->cad->timeout;
287 switch (mode) {
288 case ECR_PPF: /* Parallel Port FIFO mode */
289 case ECR_ECP: /* ECP Parallel Port mode */
290 /* Poll slowly. */
291 for (;;) {
292 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
293 return -EIO;
294 if (priv->reg[2] & 0x01)
295 break;
296 if (time_after_eq (jiffies, expire))
297 /* The FIFO is stuck. */
298 return -EBUSY;
299 msleep_interruptible(10);
300 if (signal_pending (current))
301 break;
305 /* Set the mode. */
306 if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
307 return -EIO;
308 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
309 return -EIO;
310 return 0;
314 * Clear TIMEOUT BIT in EPP MODE
316 static int clear_epp_timeout(struct parport *pp)
318 unsigned char stat;
320 if (get_1284_register(pp, 1, &stat, GFP_KERNEL))
321 return 1;
322 return stat & 1;
326 * Access functions.
328 #if 0
329 static int uss720_irq(int usbstatus, void *buffer, int len, void *dev_id)
331 struct parport *pp = (struct parport *)dev_id;
332 struct parport_uss720_private *priv = pp->private_data;
334 if (usbstatus != 0 || len < 4 || !buffer)
335 return 1;
336 memcpy(priv->reg, buffer, 4);
337 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
338 if (priv->reg[2] & priv->reg[1] & 0x10)
339 parport_generic_irq(0, pp, NULL);
340 return 1;
342 #endif
344 static void parport_uss720_write_data(struct parport *pp, unsigned char d)
346 set_1284_register(pp, 0, d, GFP_KERNEL);
349 static unsigned char parport_uss720_read_data(struct parport *pp)
351 unsigned char ret;
353 if (get_1284_register(pp, 0, &ret, GFP_KERNEL))
354 return 0;
355 return ret;
358 static void parport_uss720_write_control(struct parport *pp, unsigned char d)
360 struct parport_uss720_private *priv = pp->private_data;
362 d = (d & 0xf) | (priv->reg[1] & 0xf0);
363 if (set_1284_register(pp, 2, d, GFP_KERNEL))
364 return;
365 priv->reg[1] = d;
368 static unsigned char parport_uss720_read_control(struct parport *pp)
370 struct parport_uss720_private *priv = pp->private_data;
371 return priv->reg[1] & 0xf; /* Use soft copy */
374 static unsigned char parport_uss720_frob_control(struct parport *pp, unsigned char mask, unsigned char val)
376 struct parport_uss720_private *priv = pp->private_data;
377 unsigned char d;
379 mask &= 0x0f;
380 val &= 0x0f;
381 d = (priv->reg[1] & (~mask)) ^ val;
382 if (set_1284_register(pp, 2, d, GFP_KERNEL))
383 return 0;
384 priv->reg[1] = d;
385 return d & 0xf;
388 static unsigned char parport_uss720_read_status(struct parport *pp)
390 unsigned char ret;
392 if (get_1284_register(pp, 1, &ret, GFP_KERNEL))
393 return 0;
394 return ret & 0xf8;
397 static void parport_uss720_disable_irq(struct parport *pp)
399 struct parport_uss720_private *priv = pp->private_data;
400 unsigned char d;
402 d = priv->reg[1] & ~0x10;
403 if (set_1284_register(pp, 2, d, GFP_KERNEL))
404 return;
405 priv->reg[1] = d;
408 static void parport_uss720_enable_irq(struct parport *pp)
410 struct parport_uss720_private *priv = pp->private_data;
411 unsigned char d;
413 d = priv->reg[1] | 0x10;
414 if (set_1284_register(pp, 2, d, GFP_KERNEL))
415 return;
416 priv->reg[1] = d;
419 static void parport_uss720_data_forward (struct parport *pp)
421 struct parport_uss720_private *priv = pp->private_data;
422 unsigned char d;
424 d = priv->reg[1] & ~0x20;
425 if (set_1284_register(pp, 2, d, GFP_KERNEL))
426 return;
427 priv->reg[1] = d;
430 static void parport_uss720_data_reverse (struct parport *pp)
432 struct parport_uss720_private *priv = pp->private_data;
433 unsigned char d;
435 d = priv->reg[1] | 0x20;
436 if (set_1284_register(pp, 2, d, GFP_KERNEL))
437 return;
438 priv->reg[1] = d;
441 static void parport_uss720_init_state(struct pardevice *dev, struct parport_state *s)
443 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
444 s->u.pc.ecr = 0x24;
447 static void parport_uss720_save_state(struct parport *pp, struct parport_state *s)
449 struct parport_uss720_private *priv = pp->private_data;
451 #if 0
452 if (get_1284_register(pp, 2, NULL, GFP_ATOMIC))
453 return;
454 #endif
455 s->u.pc.ctr = priv->reg[1];
456 s->u.pc.ecr = priv->reg[2];
459 static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s)
461 struct parport_uss720_private *priv = pp->private_data;
463 set_1284_register(pp, 2, s->u.pc.ctr, GFP_ATOMIC);
464 set_1284_register(pp, 6, s->u.pc.ecr, GFP_ATOMIC);
465 get_1284_register(pp, 2, NULL, GFP_ATOMIC);
466 priv->reg[1] = s->u.pc.ctr;
467 priv->reg[2] = s->u.pc.ecr;
470 static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags)
472 struct parport_uss720_private *priv = pp->private_data;
473 size_t got = 0;
475 if (change_mode(pp, ECR_EPP))
476 return 0;
477 for (; got < length; got++) {
478 if (get_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
479 break;
480 buf++;
481 if (priv->reg[0] & 0x01) {
482 clear_epp_timeout(pp);
483 break;
486 change_mode(pp, ECR_PS2);
487 return got;
490 static size_t parport_uss720_epp_write_data(struct parport *pp, const void *buf, size_t length, int flags)
492 #if 0
493 struct parport_uss720_private *priv = pp->private_data;
494 size_t written = 0;
496 if (change_mode(pp, ECR_EPP))
497 return 0;
498 for (; written < length; written++) {
499 if (set_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
500 break;
501 ((char*)buf)++;
502 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
503 break;
504 if (priv->reg[0] & 0x01) {
505 clear_epp_timeout(pp);
506 break;
509 change_mode(pp, ECR_PS2);
510 return written;
511 #else
512 struct parport_uss720_private *priv = pp->private_data;
513 struct usb_device *usbdev = priv->usbdev;
514 int rlen;
515 int i;
517 if (!usbdev)
518 return 0;
519 if (change_mode(pp, ECR_EPP))
520 return 0;
521 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buf, length, &rlen, 20000);
522 if (i)
523 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buf, length, rlen);
524 change_mode(pp, ECR_PS2);
525 return rlen;
526 #endif
529 static size_t parport_uss720_epp_read_addr(struct parport *pp, void *buf, size_t length, int flags)
531 struct parport_uss720_private *priv = pp->private_data;
532 size_t got = 0;
534 if (change_mode(pp, ECR_EPP))
535 return 0;
536 for (; got < length; got++) {
537 if (get_1284_register(pp, 3, (char *)buf, GFP_KERNEL))
538 break;
539 buf++;
540 if (priv->reg[0] & 0x01) {
541 clear_epp_timeout(pp);
542 break;
545 change_mode(pp, ECR_PS2);
546 return got;
549 static size_t parport_uss720_epp_write_addr(struct parport *pp, const void *buf, size_t length, int flags)
551 struct parport_uss720_private *priv = pp->private_data;
552 size_t written = 0;
554 if (change_mode(pp, ECR_EPP))
555 return 0;
556 for (; written < length; written++) {
557 if (set_1284_register(pp, 3, *(char *)buf, GFP_KERNEL))
558 break;
559 buf++;
560 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
561 break;
562 if (priv->reg[0] & 0x01) {
563 clear_epp_timeout(pp);
564 break;
567 change_mode(pp, ECR_PS2);
568 return written;
571 static size_t parport_uss720_ecp_write_data(struct parport *pp, const void *buffer, size_t len, int flags)
573 struct parport_uss720_private *priv = pp->private_data;
574 struct usb_device *usbdev = priv->usbdev;
575 int rlen;
576 int i;
578 if (!usbdev)
579 return 0;
580 if (change_mode(pp, ECR_ECP))
581 return 0;
582 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
583 if (i)
584 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
585 change_mode(pp, ECR_PS2);
586 return rlen;
589 static size_t parport_uss720_ecp_read_data(struct parport *pp, void *buffer, size_t len, int flags)
591 struct parport_uss720_private *priv = pp->private_data;
592 struct usb_device *usbdev = priv->usbdev;
593 int rlen;
594 int i;
596 if (!usbdev)
597 return 0;
598 if (change_mode(pp, ECR_ECP))
599 return 0;
600 i = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), buffer, len, &rlen, 20000);
601 if (i)
602 printk(KERN_ERR "uss720: recvbulk ep 2 buf %p len %Zu rlen %u\n", buffer, len, rlen);
603 change_mode(pp, ECR_PS2);
604 return rlen;
607 static size_t parport_uss720_ecp_write_addr(struct parport *pp, const void *buffer, size_t len, int flags)
609 size_t written = 0;
611 if (change_mode(pp, ECR_ECP))
612 return 0;
613 for (; written < len; written++) {
614 if (set_1284_register(pp, 5, *(char *)buffer, GFP_KERNEL))
615 break;
616 buffer++;
618 change_mode(pp, ECR_PS2);
619 return written;
622 static size_t parport_uss720_write_compat(struct parport *pp, const void *buffer, size_t len, int flags)
624 struct parport_uss720_private *priv = pp->private_data;
625 struct usb_device *usbdev = priv->usbdev;
626 int rlen;
627 int i;
629 if (!usbdev)
630 return 0;
631 if (change_mode(pp, ECR_PPF))
632 return 0;
633 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
634 if (i)
635 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
636 change_mode(pp, ECR_PS2);
637 return rlen;
640 /* --------------------------------------------------------------------- */
642 static struct parport_operations parport_uss720_ops =
644 .owner = THIS_MODULE,
645 .write_data = parport_uss720_write_data,
646 .read_data = parport_uss720_read_data,
648 .write_control = parport_uss720_write_control,
649 .read_control = parport_uss720_read_control,
650 .frob_control = parport_uss720_frob_control,
652 .read_status = parport_uss720_read_status,
654 .enable_irq = parport_uss720_enable_irq,
655 .disable_irq = parport_uss720_disable_irq,
657 .data_forward = parport_uss720_data_forward,
658 .data_reverse = parport_uss720_data_reverse,
660 .init_state = parport_uss720_init_state,
661 .save_state = parport_uss720_save_state,
662 .restore_state = parport_uss720_restore_state,
664 .epp_write_data = parport_uss720_epp_write_data,
665 .epp_read_data = parport_uss720_epp_read_data,
666 .epp_write_addr = parport_uss720_epp_write_addr,
667 .epp_read_addr = parport_uss720_epp_read_addr,
669 .ecp_write_data = parport_uss720_ecp_write_data,
670 .ecp_read_data = parport_uss720_ecp_read_data,
671 .ecp_write_addr = parport_uss720_ecp_write_addr,
673 .compat_write_data = parport_uss720_write_compat,
674 .nibble_read_data = parport_ieee1284_read_nibble,
675 .byte_read_data = parport_ieee1284_read_byte,
678 /* --------------------------------------------------------------------- */
680 static int uss720_probe(struct usb_interface *intf,
681 const struct usb_device_id *id)
683 struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
684 struct usb_host_interface *interface;
685 struct usb_host_endpoint *endpoint;
686 struct parport_uss720_private *priv;
687 struct parport *pp;
688 unsigned char reg;
689 int i;
691 dbg("probe: vendor id 0x%x, device id 0x%x\n",
692 le16_to_cpu(usbdev->descriptor.idVendor),
693 le16_to_cpu(usbdev->descriptor.idProduct));
695 /* our known interfaces have 3 alternate settings */
696 if (intf->num_altsetting != 3) {
697 usb_put_dev(usbdev);
698 return -ENODEV;
700 i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
701 dbg("set inteface result %d", i);
703 interface = intf->cur_altsetting;
706 * Allocate parport interface
708 if (!(priv = kzalloc(sizeof(struct parport_uss720_private), GFP_KERNEL))) {
709 usb_put_dev(usbdev);
710 return -ENOMEM;
712 priv->pp = NULL;
713 priv->usbdev = usbdev;
714 kref_init(&priv->ref_count);
715 spin_lock_init(&priv->asynclock);
716 INIT_LIST_HEAD(&priv->asynclist);
717 if (!(pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops))) {
718 warn("could not register parport");
719 goto probe_abort;
722 priv->pp = pp;
723 pp->private_data = priv;
724 pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
726 /* set the USS720 control register to manual mode, no ECP compression, enable all ints */
727 set_1284_register(pp, 7, 0x00, GFP_KERNEL);
728 set_1284_register(pp, 6, 0x30, GFP_KERNEL); /* PS/2 mode */
729 set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
730 /* debugging */
731 get_1284_register(pp, 0, &reg, GFP_KERNEL);
732 dbg("reg: %02x %02x %02x %02x %02x %02x %02x",
733 priv->reg[0], priv->reg[1], priv->reg[2], priv->reg[3], priv->reg[4], priv->reg[5], priv->reg[6]);
735 endpoint = &interface->endpoint[2];
736 dbg("epaddr %d interval %d", endpoint->desc.bEndpointAddress, endpoint->desc.bInterval);
737 parport_announce_port(pp);
739 usb_set_intfdata(intf, pp);
740 return 0;
742 probe_abort:
743 kill_all_async_requests_priv(priv);
744 kref_put(&priv->ref_count, destroy_priv);
745 return -ENODEV;
748 static void uss720_disconnect(struct usb_interface *intf)
750 struct parport *pp = usb_get_intfdata(intf);
751 struct parport_uss720_private *priv;
752 struct usb_device *usbdev;
754 dbg("disconnect");
755 usb_set_intfdata(intf, NULL);
756 if (pp) {
757 priv = pp->private_data;
758 usbdev = priv->usbdev;
759 priv->usbdev = NULL;
760 priv->pp = NULL;
761 dbg("parport_remove_port");
762 parport_remove_port(pp);
763 parport_put_port(pp);
764 kill_all_async_requests_priv(priv);
765 kref_put(&priv->ref_count, destroy_priv);
767 dbg("disconnect done");
770 /* table of cables that work through this driver */
771 static struct usb_device_id uss720_table [] = {
772 { USB_DEVICE(0x047e, 0x1001) },
773 { USB_DEVICE(0x0557, 0x2001) },
774 { USB_DEVICE(0x0729, 0x1284) },
775 { USB_DEVICE(0x1293, 0x0002) },
776 { } /* Terminating entry */
779 MODULE_DEVICE_TABLE (usb, uss720_table);
782 static struct usb_driver uss720_driver = {
783 .name = "uss720",
784 .probe = uss720_probe,
785 .disconnect = uss720_disconnect,
786 .id_table = uss720_table,
789 /* --------------------------------------------------------------------- */
791 MODULE_AUTHOR(DRIVER_AUTHOR);
792 MODULE_DESCRIPTION(DRIVER_DESC);
793 MODULE_LICENSE("GPL");
795 static int __init uss720_init(void)
797 int retval;
798 retval = usb_register(&uss720_driver);
799 if (retval)
800 goto out;
802 info(DRIVER_VERSION ":" DRIVER_DESC);
803 info("NOTE: this is a special purpose driver to allow nonstandard");
804 info("protocols (eg. bitbang) over USS720 usb to parallel cables");
805 info("If you just want to connect to a printer, use usblp instead");
806 out:
807 return retval;
810 static void __exit uss720_cleanup(void)
812 usb_deregister(&uss720_driver);
815 module_init(uss720_init);
816 module_exit(uss720_cleanup);
818 /* --------------------------------------------------------------------- */