• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/linux/linux-2.6.36/drivers/usb/misc/
1/*****************************************************************************/
2
3/*
4 *	uss720.c  --  USS720 USB Parport Cable.
5 *
6 *	Copyright (C) 1999, 2005, 2010
7 *	    Thomas Sailer (t.sailer@alumni.ethz.ch)
8 *
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.
13 *
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.
18 *
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.
22 *
23 *  Based on parport_pc.c
24 *
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
39 *
40 */
41
42/*****************************************************************************/
43
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>
53
54/*
55 * Version Information
56 */
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"
60
61/* --------------------------------------------------------------------- */
62
63struct 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;
70};
71
72struct 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];
80};
81
82/* --------------------------------------------------------------------- */
83
84static void destroy_priv(struct kref *kref)
85{
86	struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
87
88	usb_put_dev(priv->usbdev);
89	kfree(priv);
90	dbg("destroying priv datastructure");
91}
92
93static void destroy_async(struct kref *kref)
94{
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;
98
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);
106}
107
108/* --------------------------------------------------------------------- */
109
110static void async_complete(struct urb *urb)
111{
112	struct uss720_async_request *rq;
113	struct parport *pp;
114	struct parport_uss720_private *priv;
115	int status = urb->status;
116
117	rq = urb->context;
118	priv = rq->priv;
119	pp = priv->pp;
120	if (status) {
121		err("async_complete: urb error %d", status);
122	} else if (rq->dr.bRequest == 3) {
123		memcpy(priv->reg, rq->reg, sizeof(priv->reg));
124		/* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
125		if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
126			parport_generic_irq(pp);
127	}
128	complete(&rq->compl);
129	kref_put(&rq->ref_count, destroy_async);
130}
131
132static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
133							 __u8 request, __u8 requesttype, __u16 value, __u16 index,
134							 gfp_t mem_flags)
135{
136	struct usb_device *usbdev;
137	struct uss720_async_request *rq;
138	unsigned long flags;
139	int ret;
140
141	if (!priv)
142		return NULL;
143	usbdev = priv->usbdev;
144	if (!usbdev)
145		return NULL;
146	rq = kmalloc(sizeof(struct uss720_async_request), mem_flags);
147	if (!rq) {
148		err("submit_async_request out of memory");
149		return NULL;
150	}
151	kref_init(&rq->ref_count);
152	INIT_LIST_HEAD(&rq->asynclist);
153	init_completion(&rq->compl);
154	kref_get(&priv->ref_count);
155	rq->priv = priv;
156	rq->urb = usb_alloc_urb(0, mem_flags);
157	if (!rq->urb) {
158		kref_put(&rq->ref_count, destroy_async);
159		err("submit_async_request out of memory");
160		return NULL;
161	}
162	rq->dr.bRequestType = requesttype;
163	rq->dr.bRequest = request;
164	rq->dr.wValue = cpu_to_le16(value);
165	rq->dr.wIndex = cpu_to_le16(index);
166	rq->dr.wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
167	usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
168			     (unsigned char *)&rq->dr,
169			     (request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
170	/* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
171	spin_lock_irqsave(&priv->asynclock, flags);
172	list_add_tail(&rq->asynclist, &priv->asynclist);
173	spin_unlock_irqrestore(&priv->asynclock, flags);
174	ret = usb_submit_urb(rq->urb, mem_flags);
175	if (!ret) {
176		kref_get(&rq->ref_count);
177		return rq;
178	}
179	kref_put(&rq->ref_count, destroy_async);
180	err("submit_async_request submit_urb failed with %d", ret);
181	return NULL;
182}
183
184static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
185{
186	struct uss720_async_request *rq;
187	unsigned long flags;
188	unsigned int ret = 0;
189
190	spin_lock_irqsave(&priv->asynclock, flags);
191	list_for_each_entry(rq, &priv->asynclist, asynclist) {
192		usb_unlink_urb(rq->urb);
193		ret++;
194	}
195	spin_unlock_irqrestore(&priv->asynclock, flags);
196	return ret;
197}
198
199/* --------------------------------------------------------------------- */
200
201static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
202{
203	struct parport_uss720_private *priv;
204	struct uss720_async_request *rq;
205	static const unsigned char regindex[9] = {
206		4, 0, 1, 5, 5, 0, 2, 3, 6
207	};
208	int ret;
209
210	if (!pp)
211		return -EIO;
212	priv = pp->private_data;
213	rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
214	if (!rq) {
215		err("get_1284_register(%u) failed", (unsigned int)reg);
216		return -EIO;
217	}
218	if (!val) {
219		kref_put(&rq->ref_count, destroy_async);
220		return 0;
221	}
222	if (wait_for_completion_timeout(&rq->compl, HZ)) {
223		ret = rq->urb->status;
224		*val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
225		if (ret)
226			printk(KERN_WARNING "get_1284_register: "
227			       "usb error %d\n", ret);
228		kref_put(&rq->ref_count, destroy_async);
229		return ret;
230	}
231	printk(KERN_WARNING "get_1284_register timeout\n");
232	kill_all_async_requests_priv(priv);
233	return -EIO;
234}
235
236static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
237{
238	struct parport_uss720_private *priv;
239	struct uss720_async_request *rq;
240
241	if (!pp)
242		return -EIO;
243	priv = pp->private_data;
244	rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
245	if (!rq) {
246		err("set_1284_register(%u,%u) failed", (unsigned int)reg, (unsigned int)val);
247		return -EIO;
248	}
249	kref_put(&rq->ref_count, destroy_async);
250	return 0;
251}
252
253/* --------------------------------------------------------------------- */
254
255/* ECR modes */
256#define ECR_SPP 00
257#define ECR_PS2 01
258#define ECR_PPF 02
259#define ECR_ECP 03
260#define ECR_EPP 04
261
262/* Safely change the mode bits in the ECR */
263static int change_mode(struct parport *pp, int m)
264{
265	struct parport_uss720_private *priv = pp->private_data;
266	int mode;
267	__u8 reg;
268
269	if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
270		return -EIO;
271	/* Bits <7:5> contain the mode. */
272	mode = (priv->reg[2] >> 5) & 0x7;
273	if (mode == m)
274		return 0;
275	/* We have to go through mode 000 or 001 */
276	if (mode > ECR_PS2 && m > ECR_PS2)
277		if (change_mode(pp, ECR_PS2))
278			return -EIO;
279
280	if (m <= ECR_PS2 && !(priv->reg[1] & 0x20)) {
281		/* This mode resets the FIFO, so we may
282		 * have to wait for it to drain first. */
283		unsigned long expire = jiffies + pp->physport->cad->timeout;
284		switch (mode) {
285		case ECR_PPF: /* Parallel Port FIFO mode */
286		case ECR_ECP: /* ECP Parallel Port mode */
287			/* Poll slowly. */
288			for (;;) {
289				if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
290					return -EIO;
291				if (priv->reg[2] & 0x01)
292					break;
293				if (time_after_eq (jiffies, expire))
294					/* The FIFO is stuck. */
295					return -EBUSY;
296				msleep_interruptible(10);
297				if (signal_pending (current))
298					break;
299			}
300		}
301	}
302	/* Set the mode. */
303	if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
304		return -EIO;
305	if (get_1284_register(pp, 6, &reg, GFP_KERNEL))
306		return -EIO;
307	return 0;
308}
309
310/*
311 * Clear TIMEOUT BIT in EPP MODE
312 */
313static int clear_epp_timeout(struct parport *pp)
314{
315	unsigned char stat;
316
317	if (get_1284_register(pp, 1, &stat, GFP_KERNEL))
318		return 1;
319	return stat & 1;
320}
321
322/*
323 * Access functions.
324 */
325
326static void parport_uss720_write_data(struct parport *pp, unsigned char d)
327{
328	set_1284_register(pp, 0, d, GFP_KERNEL);
329}
330
331static unsigned char parport_uss720_read_data(struct parport *pp)
332{
333	unsigned char ret;
334
335	if (get_1284_register(pp, 0, &ret, GFP_KERNEL))
336		return 0;
337	return ret;
338}
339
340static void parport_uss720_write_control(struct parport *pp, unsigned char d)
341{
342	struct parport_uss720_private *priv = pp->private_data;
343
344	d = (d & 0xf) | (priv->reg[1] & 0xf0);
345	if (set_1284_register(pp, 2, d, GFP_KERNEL))
346		return;
347	priv->reg[1] = d;
348}
349
350static unsigned char parport_uss720_read_control(struct parport *pp)
351{
352	struct parport_uss720_private *priv = pp->private_data;
353	return priv->reg[1] & 0xf; /* Use soft copy */
354}
355
356static unsigned char parport_uss720_frob_control(struct parport *pp, unsigned char mask, unsigned char val)
357{
358	struct parport_uss720_private *priv = pp->private_data;
359	unsigned char d;
360
361	mask &= 0x0f;
362	val &= 0x0f;
363	d = (priv->reg[1] & (~mask)) ^ val;
364	if (set_1284_register(pp, 2, d, GFP_KERNEL))
365		return 0;
366	priv->reg[1] = d;
367	return d & 0xf;
368}
369
370static unsigned char parport_uss720_read_status(struct parport *pp)
371{
372	unsigned char ret;
373
374	if (get_1284_register(pp, 1, &ret, GFP_KERNEL))
375		return 0;
376	return ret & 0xf8;
377}
378
379static void parport_uss720_disable_irq(struct parport *pp)
380{
381	struct parport_uss720_private *priv = pp->private_data;
382	unsigned char d;
383
384	d = priv->reg[1] & ~0x10;
385	if (set_1284_register(pp, 2, d, GFP_KERNEL))
386		return;
387	priv->reg[1] = d;
388}
389
390static void parport_uss720_enable_irq(struct parport *pp)
391{
392	struct parport_uss720_private *priv = pp->private_data;
393	unsigned char d;
394
395	d = priv->reg[1] | 0x10;
396	if (set_1284_register(pp, 2, d, GFP_KERNEL))
397		return;
398	priv->reg[1] = d;
399}
400
401static void parport_uss720_data_forward (struct parport *pp)
402{
403	struct parport_uss720_private *priv = pp->private_data;
404	unsigned char d;
405
406	d = priv->reg[1] & ~0x20;
407	if (set_1284_register(pp, 2, d, GFP_KERNEL))
408		return;
409	priv->reg[1] = d;
410}
411
412static void parport_uss720_data_reverse (struct parport *pp)
413{
414	struct parport_uss720_private *priv = pp->private_data;
415	unsigned char d;
416
417	d = priv->reg[1] | 0x20;
418	if (set_1284_register(pp, 2, d, GFP_KERNEL))
419		return;
420	priv->reg[1] = d;
421}
422
423static void parport_uss720_init_state(struct pardevice *dev, struct parport_state *s)
424{
425	s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
426	s->u.pc.ecr = 0x24;
427}
428
429static void parport_uss720_save_state(struct parport *pp, struct parport_state *s)
430{
431	struct parport_uss720_private *priv = pp->private_data;
432
433	s->u.pc.ctr = priv->reg[1];
434	s->u.pc.ecr = priv->reg[2];
435}
436
437static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s)
438{
439	struct parport_uss720_private *priv = pp->private_data;
440
441	set_1284_register(pp, 2, s->u.pc.ctr, GFP_ATOMIC);
442	set_1284_register(pp, 6, s->u.pc.ecr, GFP_ATOMIC);
443	get_1284_register(pp, 2, NULL, GFP_ATOMIC);
444	priv->reg[1] = s->u.pc.ctr;
445	priv->reg[2] = s->u.pc.ecr;
446}
447
448static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags)
449{
450	struct parport_uss720_private *priv = pp->private_data;
451	size_t got = 0;
452
453	if (change_mode(pp, ECR_EPP))
454		return 0;
455	for (; got < length; got++) {
456		if (get_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
457			break;
458		buf++;
459		if (priv->reg[0] & 0x01) {
460			clear_epp_timeout(pp);
461			break;
462		}
463	}
464	change_mode(pp, ECR_PS2);
465	return got;
466}
467
468static size_t parport_uss720_epp_write_data(struct parport *pp, const void *buf, size_t length, int flags)
469{
470	struct parport_uss720_private *priv = pp->private_data;
471	struct usb_device *usbdev = priv->usbdev;
472	int rlen;
473	int i;
474
475	if (!usbdev)
476		return 0;
477	if (change_mode(pp, ECR_EPP))
478		return 0;
479	i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buf, length, &rlen, 20000);
480	if (i)
481		printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buf, length, rlen);
482	change_mode(pp, ECR_PS2);
483	return rlen;
484}
485
486static size_t parport_uss720_epp_read_addr(struct parport *pp, void *buf, size_t length, int flags)
487{
488	struct parport_uss720_private *priv = pp->private_data;
489	size_t got = 0;
490
491	if (change_mode(pp, ECR_EPP))
492		return 0;
493	for (; got < length; got++) {
494		if (get_1284_register(pp, 3, (char *)buf, GFP_KERNEL))
495			break;
496		buf++;
497		if (priv->reg[0] & 0x01) {
498			clear_epp_timeout(pp);
499			break;
500		}
501	}
502	change_mode(pp, ECR_PS2);
503	return got;
504}
505
506static size_t parport_uss720_epp_write_addr(struct parport *pp, const void *buf, size_t length, int flags)
507{
508	struct parport_uss720_private *priv = pp->private_data;
509	size_t written = 0;
510
511	if (change_mode(pp, ECR_EPP))
512		return 0;
513	for (; written < length; written++) {
514		if (set_1284_register(pp, 3, *(char *)buf, GFP_KERNEL))
515			break;
516		buf++;
517		if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
518			break;
519		if (priv->reg[0] & 0x01) {
520			clear_epp_timeout(pp);
521			break;
522		}
523	}
524	change_mode(pp, ECR_PS2);
525	return written;
526}
527
528static size_t parport_uss720_ecp_write_data(struct parport *pp, const void *buffer, size_t len, int flags)
529{
530	struct parport_uss720_private *priv = pp->private_data;
531	struct usb_device *usbdev = priv->usbdev;
532	int rlen;
533	int i;
534
535	if (!usbdev)
536		return 0;
537	if (change_mode(pp, ECR_ECP))
538		return 0;
539	i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
540	if (i)
541		printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
542	change_mode(pp, ECR_PS2);
543	return rlen;
544}
545
546static size_t parport_uss720_ecp_read_data(struct parport *pp, void *buffer, size_t len, int flags)
547{
548	struct parport_uss720_private *priv = pp->private_data;
549	struct usb_device *usbdev = priv->usbdev;
550	int rlen;
551	int i;
552
553	if (!usbdev)
554		return 0;
555	if (change_mode(pp, ECR_ECP))
556		return 0;
557	i = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), buffer, len, &rlen, 20000);
558	if (i)
559		printk(KERN_ERR "uss720: recvbulk ep 2 buf %p len %Zu rlen %u\n", buffer, len, rlen);
560	change_mode(pp, ECR_PS2);
561	return rlen;
562}
563
564static size_t parport_uss720_ecp_write_addr(struct parport *pp, const void *buffer, size_t len, int flags)
565{
566	size_t written = 0;
567
568	if (change_mode(pp, ECR_ECP))
569		return 0;
570	for (; written < len; written++) {
571		if (set_1284_register(pp, 5, *(char *)buffer, GFP_KERNEL))
572			break;
573		buffer++;
574	}
575	change_mode(pp, ECR_PS2);
576	return written;
577}
578
579static size_t parport_uss720_write_compat(struct parport *pp, const void *buffer, size_t len, int flags)
580{
581	struct parport_uss720_private *priv = pp->private_data;
582	struct usb_device *usbdev = priv->usbdev;
583	int rlen;
584	int i;
585
586	if (!usbdev)
587		return 0;
588	if (change_mode(pp, ECR_PPF))
589		return 0;
590	i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
591	if (i)
592		printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
593	change_mode(pp, ECR_PS2);
594	return rlen;
595}
596
597/* --------------------------------------------------------------------- */
598
599static struct parport_operations parport_uss720_ops =
600{
601	.owner =		THIS_MODULE,
602	.write_data =		parport_uss720_write_data,
603	.read_data =		parport_uss720_read_data,
604
605	.write_control =	parport_uss720_write_control,
606	.read_control =		parport_uss720_read_control,
607	.frob_control =		parport_uss720_frob_control,
608
609	.read_status =		parport_uss720_read_status,
610
611	.enable_irq =		parport_uss720_enable_irq,
612	.disable_irq =		parport_uss720_disable_irq,
613
614	.data_forward =		parport_uss720_data_forward,
615	.data_reverse =		parport_uss720_data_reverse,
616
617	.init_state =		parport_uss720_init_state,
618	.save_state =		parport_uss720_save_state,
619	.restore_state =	parport_uss720_restore_state,
620
621	.epp_write_data =	parport_uss720_epp_write_data,
622	.epp_read_data =	parport_uss720_epp_read_data,
623	.epp_write_addr =	parport_uss720_epp_write_addr,
624	.epp_read_addr =	parport_uss720_epp_read_addr,
625
626	.ecp_write_data =	parport_uss720_ecp_write_data,
627	.ecp_read_data =	parport_uss720_ecp_read_data,
628	.ecp_write_addr =	parport_uss720_ecp_write_addr,
629
630	.compat_write_data =	parport_uss720_write_compat,
631	.nibble_read_data =	parport_ieee1284_read_nibble,
632	.byte_read_data =	parport_ieee1284_read_byte,
633};
634
635/* --------------------------------------------------------------------- */
636
637static int uss720_probe(struct usb_interface *intf,
638			const struct usb_device_id *id)
639{
640	struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
641	struct usb_host_interface *interface;
642	struct usb_host_endpoint *endpoint;
643	struct parport_uss720_private *priv;
644	struct parport *pp;
645	unsigned char reg;
646	int i;
647
648	dbg("probe: vendor id 0x%x, device id 0x%x\n",
649	    le16_to_cpu(usbdev->descriptor.idVendor),
650	    le16_to_cpu(usbdev->descriptor.idProduct));
651
652	/* our known interfaces have 3 alternate settings */
653	if (intf->num_altsetting != 3) {
654		usb_put_dev(usbdev);
655		return -ENODEV;
656	}
657	i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
658	dbg("set inteface result %d", i);
659
660	interface = intf->cur_altsetting;
661
662	/*
663	 * Allocate parport interface
664	 */
665	if (!(priv = kzalloc(sizeof(struct parport_uss720_private), GFP_KERNEL))) {
666		usb_put_dev(usbdev);
667		return -ENOMEM;
668	}
669	priv->pp = NULL;
670	priv->usbdev = usbdev;
671	kref_init(&priv->ref_count);
672	spin_lock_init(&priv->asynclock);
673	INIT_LIST_HEAD(&priv->asynclist);
674	if (!(pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops))) {
675		printk(KERN_WARNING "uss720: could not register parport\n");
676		goto probe_abort;
677	}
678
679	priv->pp = pp;
680	pp->private_data = priv;
681	pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
682
683	/* set the USS720 control register to manual mode, no ECP compression, enable all ints */
684	set_1284_register(pp, 7, 0x00, GFP_KERNEL);
685	set_1284_register(pp, 6, 0x30, GFP_KERNEL);  /* PS/2 mode */
686	set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
687	/* debugging */
688	get_1284_register(pp, 0, &reg, GFP_KERNEL);
689	dbg("reg: %02x %02x %02x %02x %02x %02x %02x",
690	    priv->reg[0], priv->reg[1], priv->reg[2], priv->reg[3], priv->reg[4], priv->reg[5], priv->reg[6]);
691
692	endpoint = &interface->endpoint[2];
693	dbg("epaddr %d interval %d", endpoint->desc.bEndpointAddress, endpoint->desc.bInterval);
694	parport_announce_port(pp);
695
696	usb_set_intfdata(intf, pp);
697	return 0;
698
699probe_abort:
700	kill_all_async_requests_priv(priv);
701	kref_put(&priv->ref_count, destroy_priv);
702	return -ENODEV;
703}
704
705static void uss720_disconnect(struct usb_interface *intf)
706{
707	struct parport *pp = usb_get_intfdata(intf);
708	struct parport_uss720_private *priv;
709	struct usb_device *usbdev;
710
711	dbg("disconnect");
712	usb_set_intfdata(intf, NULL);
713	if (pp) {
714		priv = pp->private_data;
715		usbdev = priv->usbdev;
716		priv->usbdev = NULL;
717		priv->pp = NULL;
718		dbg("parport_remove_port");
719		parport_remove_port(pp);
720		parport_put_port(pp);
721		kill_all_async_requests_priv(priv);
722		kref_put(&priv->ref_count, destroy_priv);
723	}
724	dbg("disconnect done");
725}
726
727/* table of cables that work through this driver */
728static const struct usb_device_id uss720_table[] = {
729	{ USB_DEVICE(0x047e, 0x1001) },
730	{ USB_DEVICE(0x0557, 0x2001) },
731	{ USB_DEVICE(0x0729, 0x1284) },
732	{ USB_DEVICE(0x1293, 0x0002) },
733	{ USB_DEVICE(0x1293, 0x0002) },
734	{ USB_DEVICE(0x050d, 0x0002) },
735	{ }						/* Terminating entry */
736};
737
738MODULE_DEVICE_TABLE (usb, uss720_table);
739
740
741static struct usb_driver uss720_driver = {
742	.name =		"uss720",
743	.probe =	uss720_probe,
744	.disconnect =	uss720_disconnect,
745	.id_table =	uss720_table,
746};
747
748/* --------------------------------------------------------------------- */
749
750MODULE_AUTHOR(DRIVER_AUTHOR);
751MODULE_DESCRIPTION(DRIVER_DESC);
752MODULE_LICENSE("GPL");
753
754static int __init uss720_init(void)
755{
756	int retval;
757	retval = usb_register(&uss720_driver);
758	if (retval)
759		goto out;
760
761	printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
762	       DRIVER_DESC "\n");
763	printk(KERN_INFO KBUILD_MODNAME ": NOTE: this is a special purpose "
764	       "driver to allow nonstandard\n");
765	printk(KERN_INFO KBUILD_MODNAME ": protocols (eg. bitbang) over "
766	       "USS720 usb to parallel cables\n");
767	printk(KERN_INFO KBUILD_MODNAME ": If you just want to connect to a "
768	       "printer, use usblp instead\n");
769out:
770	return retval;
771}
772
773static void __exit uss720_cleanup(void)
774{
775	usb_deregister(&uss720_driver);
776}
777
778module_init(uss720_init);
779module_exit(uss720_cleanup);
780
781/* --------------------------------------------------------------------- */
782