USB: uss720.c: remove err() usage
[linux-2.6/libata-dev.git] / drivers / usb / misc / uss720.c
blob7f64147ea22902bb4a33db6597f2ec7af629c5a4
1 /*****************************************************************************/
3 /*
4 * uss720.c -- USS720 USB Parport Cable.
6 * Copyright (C) 1999, 2005, 2010
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>
52 #include <linux/slab.h>
55 * Version Information
57 #define DRIVER_VERSION "v0.6"
58 #define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch"
59 #define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
61 /* --------------------------------------------------------------------- */
63 struct parport_uss720_private {
64 struct usb_device *usbdev;
65 struct parport *pp;
66 struct kref ref_count;
67 __u8 reg[7]; /* USB registers */
68 struct list_head asynclist;
69 spinlock_t asynclock;
72 struct uss720_async_request {
73 struct parport_uss720_private *priv;
74 struct kref ref_count;
75 struct list_head asynclist;
76 struct completion compl;
77 struct urb *urb;
78 struct usb_ctrlrequest dr;
79 __u8 reg[7];
82 /* --------------------------------------------------------------------- */
84 static void destroy_priv(struct kref *kref)
86 struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
88 usb_put_dev(priv->usbdev);
89 kfree(priv);
90 dbg("destroying priv datastructure");
93 static void destroy_async(struct kref *kref)
95 struct uss720_async_request *rq = container_of(kref, struct uss720_async_request, ref_count);
96 struct parport_uss720_private *priv = rq->priv;
97 unsigned long flags;
99 if (likely(rq->urb))
100 usb_free_urb(rq->urb);
101 spin_lock_irqsave(&priv->asynclock, flags);
102 list_del_init(&rq->asynclist);
103 spin_unlock_irqrestore(&priv->asynclock, flags);
104 kfree(rq);
105 kref_put(&priv->ref_count, destroy_priv);
108 /* --------------------------------------------------------------------- */
110 static void async_complete(struct urb *urb)
112 struct uss720_async_request *rq;
113 struct parport *pp;
114 struct parport_uss720_private *priv;
115 int status = urb->status;
117 rq = urb->context;
118 priv = rq->priv;
119 pp = priv->pp;
120 if (status) {
121 dev_err(&urb->dev->dev, "async_complete: urb error %d\n",
122 status);
123 } else if (rq->dr.bRequest == 3) {
124 memcpy(priv->reg, rq->reg, sizeof(priv->reg));
125 #if 0
126 dbg("async_complete regs %02x %02x %02x %02x %02x %02x %02x",
127 (unsigned int)priv->reg[0], (unsigned int)priv->reg[1], (unsigned int)priv->reg[2],
128 (unsigned int)priv->reg[3], (unsigned int)priv->reg[4], (unsigned int)priv->reg[5],
129 (unsigned int)priv->reg[6]);
130 #endif
131 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
132 if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
133 parport_generic_irq(pp);
135 complete(&rq->compl);
136 kref_put(&rq->ref_count, destroy_async);
139 static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
140 __u8 request, __u8 requesttype, __u16 value, __u16 index,
141 gfp_t mem_flags)
143 struct usb_device *usbdev;
144 struct uss720_async_request *rq;
145 unsigned long flags;
146 int ret;
148 if (!priv)
149 return NULL;
150 usbdev = priv->usbdev;
151 if (!usbdev)
152 return NULL;
153 rq = kmalloc(sizeof(struct uss720_async_request), mem_flags);
154 if (!rq) {
155 dev_err(&usbdev->dev, "submit_async_request out of memory\n");
156 return NULL;
158 kref_init(&rq->ref_count);
159 INIT_LIST_HEAD(&rq->asynclist);
160 init_completion(&rq->compl);
161 kref_get(&priv->ref_count);
162 rq->priv = priv;
163 rq->urb = usb_alloc_urb(0, mem_flags);
164 if (!rq->urb) {
165 kref_put(&rq->ref_count, destroy_async);
166 dev_err(&usbdev->dev, "submit_async_request out of memory\n");
167 return NULL;
169 rq->dr.bRequestType = requesttype;
170 rq->dr.bRequest = request;
171 rq->dr.wValue = cpu_to_le16(value);
172 rq->dr.wIndex = cpu_to_le16(index);
173 rq->dr.wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
174 usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
175 (unsigned char *)&rq->dr,
176 (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
177 /* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
178 spin_lock_irqsave(&priv->asynclock, flags);
179 list_add_tail(&rq->asynclist, &priv->asynclist);
180 spin_unlock_irqrestore(&priv->asynclock, flags);
181 kref_get(&rq->ref_count);
182 ret = usb_submit_urb(rq->urb, mem_flags);
183 if (!ret)
184 return rq;
185 destroy_async(&rq->ref_count);
186 dev_err(&usbdev->dev, "submit_async_request submit_urb failed with %d\n", ret);
187 return NULL;
190 static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
192 struct uss720_async_request *rq;
193 unsigned long flags;
194 unsigned int ret = 0;
196 spin_lock_irqsave(&priv->asynclock, flags);
197 list_for_each_entry(rq, &priv->asynclist, asynclist) {
198 usb_unlink_urb(rq->urb);
199 ret++;
201 spin_unlock_irqrestore(&priv->asynclock, flags);
202 return ret;
205 /* --------------------------------------------------------------------- */
207 static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
209 struct parport_uss720_private *priv;
210 struct uss720_async_request *rq;
211 static const unsigned char regindex[9] = {
212 4, 0, 1, 5, 5, 0, 2, 3, 6
214 int ret;
216 if (!pp)
217 return -EIO;
218 priv = pp->private_data;
219 rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
220 if (!rq) {
221 dev_err(&priv->usbdev->dev, "get_1284_register(%u) failed",
222 (unsigned int)reg);
223 return -EIO;
225 if (!val) {
226 kref_put(&rq->ref_count, destroy_async);
227 return 0;
229 if (wait_for_completion_timeout(&rq->compl, HZ)) {
230 ret = rq->urb->status;
231 *val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
232 if (ret)
233 printk(KERN_WARNING "get_1284_register: "
234 "usb error %d\n", ret);
235 kref_put(&rq->ref_count, destroy_async);
236 return ret;
238 printk(KERN_WARNING "get_1284_register timeout\n");
239 kill_all_async_requests_priv(priv);
240 return -EIO;
243 static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
245 struct parport_uss720_private *priv;
246 struct uss720_async_request *rq;
248 if (!pp)
249 return -EIO;
250 priv = pp->private_data;
251 rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
252 if (!rq) {
253 dev_err(&priv->usbdev->dev, "set_1284_register(%u,%u) failed",
254 (unsigned int)reg, (unsigned int)val);
255 return -EIO;
257 kref_put(&rq->ref_count, destroy_async);
258 return 0;
261 /* --------------------------------------------------------------------- */
263 /* ECR modes */
264 #define ECR_SPP 00
265 #define ECR_PS2 01
266 #define ECR_PPF 02
267 #define ECR_ECP 03
268 #define ECR_EPP 04
270 /* Safely change the mode bits in the ECR */
271 static int change_mode(struct parport *pp, int m)
273 struct parport_uss720_private *priv = pp->private_data;
274 int mode;
275 __u8 reg;
277 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
278 return -EIO;
279 /* Bits <7:5> contain the mode. */
280 mode = (priv->reg[2] >> 5) & 0x7;
281 if (mode == m)
282 return 0;
283 /* We have to go through mode 000 or 001 */
284 if (mode > ECR_PS2 && m > ECR_PS2)
285 if (change_mode(pp, ECR_PS2))
286 return -EIO;
288 if (m <= ECR_PS2 && !(priv->reg[1] & 0x20)) {
289 /* This mode resets the FIFO, so we may
290 * have to wait for it to drain first. */
291 unsigned long expire = jiffies + pp->physport->cad->timeout;
292 switch (mode) {
293 case ECR_PPF: /* Parallel Port FIFO mode */
294 case ECR_ECP: /* ECP Parallel Port mode */
295 /* Poll slowly. */
296 for (;;) {
297 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
298 return -EIO;
299 if (priv->reg[2] & 0x01)
300 break;
301 if (time_after_eq (jiffies, expire))
302 /* The FIFO is stuck. */
303 return -EBUSY;
304 msleep_interruptible(10);
305 if (signal_pending (current))
306 break;
310 /* Set the mode. */
311 if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
312 return -EIO;
313 if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
314 return -EIO;
315 return 0;
319 * Clear TIMEOUT BIT in EPP MODE
321 static int clear_epp_timeout(struct parport *pp)
323 unsigned char stat;
325 if (get_1284_register(pp, 1, &stat, GFP_KERNEL))
326 return 1;
327 return stat & 1;
331 * Access functions.
333 #if 0
334 static int uss720_irq(int usbstatus, void *buffer, int len, void *dev_id)
336 struct parport *pp = (struct parport *)dev_id;
337 struct parport_uss720_private *priv = pp->private_data;
339 if (usbstatus != 0 || len < 4 || !buffer)
340 return 1;
341 memcpy(priv->reg, buffer, 4);
342 /* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
343 if (priv->reg[2] & priv->reg[1] & 0x10)
344 parport_generic_irq(pp);
345 return 1;
347 #endif
349 static void parport_uss720_write_data(struct parport *pp, unsigned char d)
351 set_1284_register(pp, 0, d, GFP_KERNEL);
354 static unsigned char parport_uss720_read_data(struct parport *pp)
356 unsigned char ret;
358 if (get_1284_register(pp, 0, &ret, GFP_KERNEL))
359 return 0;
360 return ret;
363 static void parport_uss720_write_control(struct parport *pp, unsigned char d)
365 struct parport_uss720_private *priv = pp->private_data;
367 d = (d & 0xf) | (priv->reg[1] & 0xf0);
368 if (set_1284_register(pp, 2, d, GFP_KERNEL))
369 return;
370 priv->reg[1] = d;
373 static unsigned char parport_uss720_read_control(struct parport *pp)
375 struct parport_uss720_private *priv = pp->private_data;
376 return priv->reg[1] & 0xf; /* Use soft copy */
379 static unsigned char parport_uss720_frob_control(struct parport *pp, unsigned char mask, unsigned char val)
381 struct parport_uss720_private *priv = pp->private_data;
382 unsigned char d;
384 mask &= 0x0f;
385 val &= 0x0f;
386 d = (priv->reg[1] & (~mask)) ^ val;
387 if (set_1284_register(pp, 2, d, GFP_KERNEL))
388 return 0;
389 priv->reg[1] = d;
390 return d & 0xf;
393 static unsigned char parport_uss720_read_status(struct parport *pp)
395 unsigned char ret;
397 if (get_1284_register(pp, 1, &ret, GFP_KERNEL))
398 return 0;
399 return ret & 0xf8;
402 static void parport_uss720_disable_irq(struct parport *pp)
404 struct parport_uss720_private *priv = pp->private_data;
405 unsigned char d;
407 d = priv->reg[1] & ~0x10;
408 if (set_1284_register(pp, 2, d, GFP_KERNEL))
409 return;
410 priv->reg[1] = d;
413 static void parport_uss720_enable_irq(struct parport *pp)
415 struct parport_uss720_private *priv = pp->private_data;
416 unsigned char d;
418 d = priv->reg[1] | 0x10;
419 if (set_1284_register(pp, 2, d, GFP_KERNEL))
420 return;
421 priv->reg[1] = d;
424 static void parport_uss720_data_forward (struct parport *pp)
426 struct parport_uss720_private *priv = pp->private_data;
427 unsigned char d;
429 d = priv->reg[1] & ~0x20;
430 if (set_1284_register(pp, 2, d, GFP_KERNEL))
431 return;
432 priv->reg[1] = d;
435 static void parport_uss720_data_reverse (struct parport *pp)
437 struct parport_uss720_private *priv = pp->private_data;
438 unsigned char d;
440 d = priv->reg[1] | 0x20;
441 if (set_1284_register(pp, 2, d, GFP_KERNEL))
442 return;
443 priv->reg[1] = d;
446 static void parport_uss720_init_state(struct pardevice *dev, struct parport_state *s)
448 s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
449 s->u.pc.ecr = 0x24;
452 static void parport_uss720_save_state(struct parport *pp, struct parport_state *s)
454 struct parport_uss720_private *priv = pp->private_data;
456 #if 0
457 if (get_1284_register(pp, 2, NULL, GFP_ATOMIC))
458 return;
459 #endif
460 s->u.pc.ctr = priv->reg[1];
461 s->u.pc.ecr = priv->reg[2];
464 static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s)
466 struct parport_uss720_private *priv = pp->private_data;
468 set_1284_register(pp, 2, s->u.pc.ctr, GFP_ATOMIC);
469 set_1284_register(pp, 6, s->u.pc.ecr, GFP_ATOMIC);
470 get_1284_register(pp, 2, NULL, GFP_ATOMIC);
471 priv->reg[1] = s->u.pc.ctr;
472 priv->reg[2] = s->u.pc.ecr;
475 static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags)
477 struct parport_uss720_private *priv = pp->private_data;
478 size_t got = 0;
480 if (change_mode(pp, ECR_EPP))
481 return 0;
482 for (; got < length; got++) {
483 if (get_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
484 break;
485 buf++;
486 if (priv->reg[0] & 0x01) {
487 clear_epp_timeout(pp);
488 break;
491 change_mode(pp, ECR_PS2);
492 return got;
495 static size_t parport_uss720_epp_write_data(struct parport *pp, const void *buf, size_t length, int flags)
497 #if 0
498 struct parport_uss720_private *priv = pp->private_data;
499 size_t written = 0;
501 if (change_mode(pp, ECR_EPP))
502 return 0;
503 for (; written < length; written++) {
504 if (set_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
505 break;
506 ((char*)buf)++;
507 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
508 break;
509 if (priv->reg[0] & 0x01) {
510 clear_epp_timeout(pp);
511 break;
514 change_mode(pp, ECR_PS2);
515 return written;
516 #else
517 struct parport_uss720_private *priv = pp->private_data;
518 struct usb_device *usbdev = priv->usbdev;
519 int rlen;
520 int i;
522 if (!usbdev)
523 return 0;
524 if (change_mode(pp, ECR_EPP))
525 return 0;
526 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buf, length, &rlen, 20000);
527 if (i)
528 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buf, length, rlen);
529 change_mode(pp, ECR_PS2);
530 return rlen;
531 #endif
534 static size_t parport_uss720_epp_read_addr(struct parport *pp, void *buf, size_t length, int flags)
536 struct parport_uss720_private *priv = pp->private_data;
537 size_t got = 0;
539 if (change_mode(pp, ECR_EPP))
540 return 0;
541 for (; got < length; got++) {
542 if (get_1284_register(pp, 3, (char *)buf, GFP_KERNEL))
543 break;
544 buf++;
545 if (priv->reg[0] & 0x01) {
546 clear_epp_timeout(pp);
547 break;
550 change_mode(pp, ECR_PS2);
551 return got;
554 static size_t parport_uss720_epp_write_addr(struct parport *pp, const void *buf, size_t length, int flags)
556 struct parport_uss720_private *priv = pp->private_data;
557 size_t written = 0;
559 if (change_mode(pp, ECR_EPP))
560 return 0;
561 for (; written < length; written++) {
562 if (set_1284_register(pp, 3, *(char *)buf, GFP_KERNEL))
563 break;
564 buf++;
565 if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
566 break;
567 if (priv->reg[0] & 0x01) {
568 clear_epp_timeout(pp);
569 break;
572 change_mode(pp, ECR_PS2);
573 return written;
576 static size_t parport_uss720_ecp_write_data(struct parport *pp, const void *buffer, size_t len, int flags)
578 struct parport_uss720_private *priv = pp->private_data;
579 struct usb_device *usbdev = priv->usbdev;
580 int rlen;
581 int i;
583 if (!usbdev)
584 return 0;
585 if (change_mode(pp, ECR_ECP))
586 return 0;
587 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
588 if (i)
589 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
590 change_mode(pp, ECR_PS2);
591 return rlen;
594 static size_t parport_uss720_ecp_read_data(struct parport *pp, void *buffer, size_t len, int flags)
596 struct parport_uss720_private *priv = pp->private_data;
597 struct usb_device *usbdev = priv->usbdev;
598 int rlen;
599 int i;
601 if (!usbdev)
602 return 0;
603 if (change_mode(pp, ECR_ECP))
604 return 0;
605 i = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), buffer, len, &rlen, 20000);
606 if (i)
607 printk(KERN_ERR "uss720: recvbulk ep 2 buf %p len %Zu rlen %u\n", buffer, len, rlen);
608 change_mode(pp, ECR_PS2);
609 return rlen;
612 static size_t parport_uss720_ecp_write_addr(struct parport *pp, const void *buffer, size_t len, int flags)
614 size_t written = 0;
616 if (change_mode(pp, ECR_ECP))
617 return 0;
618 for (; written < len; written++) {
619 if (set_1284_register(pp, 5, *(char *)buffer, GFP_KERNEL))
620 break;
621 buffer++;
623 change_mode(pp, ECR_PS2);
624 return written;
627 static size_t parport_uss720_write_compat(struct parport *pp, const void *buffer, size_t len, int flags)
629 struct parport_uss720_private *priv = pp->private_data;
630 struct usb_device *usbdev = priv->usbdev;
631 int rlen;
632 int i;
634 if (!usbdev)
635 return 0;
636 if (change_mode(pp, ECR_PPF))
637 return 0;
638 i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
639 if (i)
640 printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
641 change_mode(pp, ECR_PS2);
642 return rlen;
645 /* --------------------------------------------------------------------- */
647 static struct parport_operations parport_uss720_ops =
649 .owner = THIS_MODULE,
650 .write_data = parport_uss720_write_data,
651 .read_data = parport_uss720_read_data,
653 .write_control = parport_uss720_write_control,
654 .read_control = parport_uss720_read_control,
655 .frob_control = parport_uss720_frob_control,
657 .read_status = parport_uss720_read_status,
659 .enable_irq = parport_uss720_enable_irq,
660 .disable_irq = parport_uss720_disable_irq,
662 .data_forward = parport_uss720_data_forward,
663 .data_reverse = parport_uss720_data_reverse,
665 .init_state = parport_uss720_init_state,
666 .save_state = parport_uss720_save_state,
667 .restore_state = parport_uss720_restore_state,
669 .epp_write_data = parport_uss720_epp_write_data,
670 .epp_read_data = parport_uss720_epp_read_data,
671 .epp_write_addr = parport_uss720_epp_write_addr,
672 .epp_read_addr = parport_uss720_epp_read_addr,
674 .ecp_write_data = parport_uss720_ecp_write_data,
675 .ecp_read_data = parport_uss720_ecp_read_data,
676 .ecp_write_addr = parport_uss720_ecp_write_addr,
678 .compat_write_data = parport_uss720_write_compat,
679 .nibble_read_data = parport_ieee1284_read_nibble,
680 .byte_read_data = parport_ieee1284_read_byte,
683 /* --------------------------------------------------------------------- */
685 static int uss720_probe(struct usb_interface *intf,
686 const struct usb_device_id *id)
688 struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
689 struct usb_host_interface *interface;
690 struct usb_host_endpoint *endpoint;
691 struct parport_uss720_private *priv;
692 struct parport *pp;
693 unsigned char reg;
694 int i;
696 dbg("probe: vendor id 0x%x, device id 0x%x\n",
697 le16_to_cpu(usbdev->descriptor.idVendor),
698 le16_to_cpu(usbdev->descriptor.idProduct));
700 /* our known interfaces have 3 alternate settings */
701 if (intf->num_altsetting != 3) {
702 usb_put_dev(usbdev);
703 return -ENODEV;
705 i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
706 dbg("set inteface result %d", i);
708 interface = intf->cur_altsetting;
711 * Allocate parport interface
713 if (!(priv = kzalloc(sizeof(struct parport_uss720_private), GFP_KERNEL))) {
714 usb_put_dev(usbdev);
715 return -ENOMEM;
717 priv->pp = NULL;
718 priv->usbdev = usbdev;
719 kref_init(&priv->ref_count);
720 spin_lock_init(&priv->asynclock);
721 INIT_LIST_HEAD(&priv->asynclist);
722 if (!(pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops))) {
723 printk(KERN_WARNING "uss720: could not register parport\n");
724 goto probe_abort;
727 priv->pp = pp;
728 pp->private_data = priv;
729 pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
731 /* set the USS720 control register to manual mode, no ECP compression, enable all ints */
732 set_1284_register(pp, 7, 0x00, GFP_KERNEL);
733 set_1284_register(pp, 6, 0x30, GFP_KERNEL); /* PS/2 mode */
734 set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
735 /* debugging */
736 get_1284_register(pp, 0, &reg, GFP_KERNEL);
737 dbg("reg: %02x %02x %02x %02x %02x %02x %02x",
738 priv->reg[0], priv->reg[1], priv->reg[2], priv->reg[3], priv->reg[4], priv->reg[5], priv->reg[6]);
740 endpoint = &interface->endpoint[2];
741 dbg("epaddr %d interval %d", endpoint->desc.bEndpointAddress, endpoint->desc.bInterval);
742 parport_announce_port(pp);
744 usb_set_intfdata(intf, pp);
745 return 0;
747 probe_abort:
748 kill_all_async_requests_priv(priv);
749 kref_put(&priv->ref_count, destroy_priv);
750 return -ENODEV;
753 static void uss720_disconnect(struct usb_interface *intf)
755 struct parport *pp = usb_get_intfdata(intf);
756 struct parport_uss720_private *priv;
757 struct usb_device *usbdev;
759 dbg("disconnect");
760 usb_set_intfdata(intf, NULL);
761 if (pp) {
762 priv = pp->private_data;
763 usbdev = priv->usbdev;
764 priv->usbdev = NULL;
765 priv->pp = NULL;
766 dbg("parport_remove_port");
767 parport_remove_port(pp);
768 parport_put_port(pp);
769 kill_all_async_requests_priv(priv);
770 kref_put(&priv->ref_count, destroy_priv);
772 dbg("disconnect done");
775 /* table of cables that work through this driver */
776 static const struct usb_device_id uss720_table[] = {
777 { USB_DEVICE(0x047e, 0x1001) },
778 { USB_DEVICE(0x0557, 0x2001) },
779 { USB_DEVICE(0x0729, 0x1284) },
780 { USB_DEVICE(0x1293, 0x0002) },
781 { USB_DEVICE(0x050d, 0x0002) },
782 { } /* Terminating entry */
785 MODULE_DEVICE_TABLE (usb, uss720_table);
788 static struct usb_driver uss720_driver = {
789 .name = "uss720",
790 .probe = uss720_probe,
791 .disconnect = uss720_disconnect,
792 .id_table = uss720_table,
795 /* --------------------------------------------------------------------- */
797 MODULE_AUTHOR(DRIVER_AUTHOR);
798 MODULE_DESCRIPTION(DRIVER_DESC);
799 MODULE_LICENSE("GPL");
801 static int __init uss720_init(void)
803 int retval;
804 retval = usb_register(&uss720_driver);
805 if (retval)
806 goto out;
808 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
809 DRIVER_DESC "\n");
810 printk(KERN_INFO KBUILD_MODNAME ": NOTE: this is a special purpose "
811 "driver to allow nonstandard\n");
812 printk(KERN_INFO KBUILD_MODNAME ": protocols (eg. bitbang) over "
813 "USS720 usb to parallel cables\n");
814 printk(KERN_INFO KBUILD_MODNAME ": If you just want to connect to a "
815 "printer, use usblp instead\n");
816 out:
817 return retval;
820 static void __exit uss720_cleanup(void)
822 usb_deregister(&uss720_driver);
825 module_init(uss720_init);
826 module_exit(uss720_cleanup);
828 /* --------------------------------------------------------------------- */