44 #include <linux/module.h>
45 #include <linux/socket.h>
46 #include <linux/parport.h>
52 #include <linux/slab.h>
57 #define DRIVER_VERSION "v0.6"
59 #define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
84 static void destroy_priv(
struct kref *
kref)
88 dev_dbg(&priv->
usbdev->dev,
"destroying priv datastructure\n");
93 static void destroy_async(
struct kref *
kref)
103 spin_unlock_irqrestore(&priv->
asynclock, flags);
105 kref_put(&priv->
ref_count, destroy_priv);
110 static void async_complete(
struct urb *
urb)
121 dev_err(&urb->dev->dev,
"async_complete: urb error %d\n",
123 }
else if (rq->
dr.bRequest == 3) {
127 "async_complete regs %02x %02x %02x %02x %02x %02x %02x\n",
128 (
unsigned int)priv->
reg[0], (
unsigned int)priv->
reg[1],
129 (
unsigned int)priv->
reg[2], (
unsigned int)priv->
reg[3],
130 (
unsigned int)priv->
reg[4], (
unsigned int)priv->
reg[5],
131 (
unsigned int)priv->
reg[6]);
134 if (rq->
reg[2] & rq->
reg[1] & 0x10 && pp)
135 parport_generic_irq(pp);
145 struct usb_device *usbdev;
157 dev_err(&usbdev->dev,
"submit_async_request out of memory\n");
162 init_completion(&rq->
compl);
168 dev_err(&usbdev->dev,
"submit_async_request out of memory\n");
171 rq->
dr.bRequestType = requesttype;
176 usb_fill_control_urb(rq->
urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
177 (
unsigned char *)&rq->
dr,
178 (request == 3) ? rq->
reg :
NULL, (request == 3) ?
sizeof(rq->
reg) : 0, async_complete, rq);
182 spin_unlock_irqrestore(&priv->
asynclock, flags);
188 dev_err(&usbdev->dev,
"submit_async_request submit_urb failed with %d\n", ret);
196 unsigned int ret = 0;
203 spin_unlock_irqrestore(&priv->
asynclock, flags);
209 static int get_1284_register(
struct parport *pp,
unsigned char reg,
unsigned char *
val,
gfp_t mem_flags)
213 static const unsigned char regindex[9] = {
214 4, 0, 1, 5, 5, 0, 2, 3, 6
221 rq = submit_async_request(priv, 3, 0xc0, ((
unsigned int)reg) << 8, 0, mem_flags);
232 ret = rq->
urb->status;
233 *val = priv->
reg[(reg >= 9) ? 0 : regindex[reg]];
236 "usb error %d\n", ret);
241 kill_all_async_requests_priv(priv);
245 static int set_1284_register(
struct parport *pp,
unsigned char reg,
unsigned char val,
gfp_t mem_flags)
253 rq = submit_async_request(priv, 4, 0x40, (((
unsigned int)reg) << 8) | val, 0, mem_flags);
255 dev_err(&priv->
usbdev->dev,
"set_1284_register(%u,%u) failed",
256 (
unsigned int)reg, (
unsigned int)val);
273 static int change_mode(
struct parport *pp,
int m)
279 if (get_1284_register(pp, 6, ®,
GFP_KERNEL))
282 mode = (priv->
reg[2] >> 5) & 0x7;
299 if (get_1284_register(pp, 6, ®,
GFP_KERNEL))
301 if (priv->
reg[2] & 0x01)
313 if (set_1284_register(pp, 6, m << 5,
GFP_KERNEL))
315 if (get_1284_register(pp, 6, ®,
GFP_KERNEL))
323 static int clear_epp_timeout(
struct parport *pp)
327 if (get_1284_register(pp, 1, &stat,
GFP_KERNEL))
336 static int uss720_irq(
int usbstatus,
void *
buffer,
int len,
void *
dev_id)
341 if (usbstatus != 0 || len < 4 || !buffer)
345 if (priv->
reg[2] & priv->
reg[1] & 0x10)
346 parport_generic_irq(pp);
351 static void parport_uss720_write_data(
struct parport *pp,
unsigned char d)
356 static unsigned char parport_uss720_read_data(
struct parport *pp)
360 if (get_1284_register(pp, 0, &ret,
GFP_KERNEL))
365 static void parport_uss720_write_control(
struct parport *pp,
unsigned char d)
369 d = (d & 0xf) | (priv->
reg[1] & 0xf0);
375 static unsigned char parport_uss720_read_control(
struct parport *pp)
378 return priv->
reg[1] & 0xf;
381 static unsigned char parport_uss720_frob_control(
struct parport *pp,
unsigned char mask,
unsigned char val)
388 d = (priv->
reg[1] & (~mask)) ^
val;
395 static unsigned char parport_uss720_read_status(
struct parport *pp)
399 if (get_1284_register(pp, 1, &ret,
GFP_KERNEL))
404 static void parport_uss720_disable_irq(
struct parport *pp)
409 d = priv->
reg[1] & ~0x10;
415 static void parport_uss720_enable_irq(
struct parport *pp)
420 d = priv->
reg[1] | 0x10;
426 static void parport_uss720_data_forward (
struct parport *pp)
431 d = priv->
reg[1] & ~0x20;
437 static void parport_uss720_data_reverse (
struct parport *pp)
442 d = priv->
reg[1] | 0x20;
462 s->
u.
pc.ctr = priv->
reg[1];
463 s->
u.
pc.ecr = priv->
reg[2];
473 priv->
reg[1] = s->
u.
pc.ctr;
474 priv->
reg[2] = s->
u.
pc.ecr;
477 static size_t parport_uss720_epp_read_data(
struct parport *pp,
void *
buf,
size_t length,
int flags)
484 for (; got <
length; got++) {
485 if (get_1284_register(pp, 4, (
char *)buf,
GFP_KERNEL))
488 if (priv->
reg[0] & 0x01) {
489 clear_epp_timeout(pp);
497 static size_t parport_uss720_epp_write_data(
struct parport *pp,
const void *buf,
size_t length,
int flags)
505 for (; written <
length; written++) {
506 if (set_1284_register(pp, 4, (
char *)buf,
GFP_KERNEL))
511 if (priv->
reg[0] & 0x01) {
512 clear_epp_timeout(pp);
520 struct usb_device *usbdev = priv->
usbdev;
528 i =
usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (
void *)buf, length, &rlen, 20000);
530 printk(
KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buf, length, rlen);
536 static size_t parport_uss720_epp_read_addr(
struct parport *pp,
void *buf,
size_t length,
int flags)
543 for (; got <
length; got++) {
544 if (get_1284_register(pp, 3, (
char *)buf,
GFP_KERNEL))
547 if (priv->
reg[0] & 0x01) {
548 clear_epp_timeout(pp);
556 static size_t parport_uss720_epp_write_addr(
struct parport *pp,
const void *buf,
size_t length,
int flags)
563 for (; written <
length; written++) {
564 if (set_1284_register(pp, 3, *(
char *)buf,
GFP_KERNEL))
569 if (priv->
reg[0] & 0x01) {
570 clear_epp_timeout(pp);
578 static size_t parport_uss720_ecp_write_data(
struct parport *pp,
const void *buffer,
size_t len,
int flags)
581 struct usb_device *usbdev = priv->
usbdev;
589 i =
usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (
void *)buffer, len, &rlen, 20000);
591 printk(
KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
596 static size_t parport_uss720_ecp_read_data(
struct parport *pp,
void *buffer,
size_t len,
int flags)
599 struct usb_device *usbdev = priv->
usbdev;
607 i =
usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), buffer, len, &rlen, 20000);
609 printk(
KERN_ERR "uss720: recvbulk ep 2 buf %p len %Zu rlen %u\n", buffer, len, rlen);
614 static size_t parport_uss720_ecp_write_addr(
struct parport *pp,
const void *buffer,
size_t len,
int flags)
620 for (; written < len; written++) {
621 if (set_1284_register(pp, 5, *(
char *)buffer,
GFP_KERNEL))
629 static size_t parport_uss720_write_compat(
struct parport *pp,
const void *buffer,
size_t len,
int flags)
632 struct usb_device *usbdev = priv->
usbdev;
640 i =
usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (
void *)buffer, len, &rlen, 20000);
642 printk(
KERN_ERR "uss720: sendbulk ep 1 buf %p len %Zu rlen %u\n", buffer, len, rlen);
652 .write_data = parport_uss720_write_data,
653 .read_data = parport_uss720_read_data,
655 .write_control = parport_uss720_write_control,
656 .read_control = parport_uss720_read_control,
657 .frob_control = parport_uss720_frob_control,
659 .read_status = parport_uss720_read_status,
661 .enable_irq = parport_uss720_enable_irq,
662 .disable_irq = parport_uss720_disable_irq,
664 .data_forward = parport_uss720_data_forward,
665 .data_reverse = parport_uss720_data_reverse,
667 .init_state = parport_uss720_init_state,
668 .save_state = parport_uss720_save_state,
669 .restore_state = parport_uss720_restore_state,
671 .epp_write_data = parport_uss720_epp_write_data,
672 .epp_read_data = parport_uss720_epp_read_data,
673 .epp_write_addr = parport_uss720_epp_write_addr,
674 .epp_read_addr = parport_uss720_epp_read_addr,
676 .ecp_write_data = parport_uss720_ecp_write_data,
677 .ecp_read_data = parport_uss720_ecp_read_data,
678 .ecp_write_addr = parport_uss720_ecp_write_addr,
680 .compat_write_data = parport_uss720_write_compat,
690 struct usb_device *usbdev =
usb_get_dev(interface_to_usbdev(intf));
698 dev_dbg(&intf->dev,
"probe: vendor id 0x%x, device id 0x%x\n",
703 if (intf->num_altsetting != 3) {
708 dev_dbg(&intf->dev,
"set inteface result %d\n", i);
710 interface = intf->cur_altsetting;
739 dev_dbg(&intf->dev,
"reg: %02x %02x %02x %02x %02x %02x %02x\n",
741 priv->
reg[4], priv->
reg[5], priv->
reg[6]);
743 endpoint = &interface->endpoint[2];
744 dev_dbg(&intf->dev,
"epaddr %d interval %d\n",
745 endpoint->desc.bEndpointAddress, endpoint->desc.bInterval);
748 usb_set_intfdata(intf, pp);
752 kill_all_async_requests_priv(priv);
753 kref_put(&priv->
ref_count, destroy_priv);
759 struct parport *pp = usb_get_intfdata(intf);
761 struct usb_device *usbdev;
763 dev_dbg(&intf->dev,
"disconnect\n");
764 usb_set_intfdata(intf,
NULL);
770 dev_dbg(&intf->dev,
"parport_remove_port\n");
773 kill_all_async_requests_priv(priv);
774 kref_put(&priv->
ref_count, destroy_priv);
776 dev_dbg(&intf->dev,
"disconnect done\n");
781 { USB_DEVICE(0x047e, 0x1001) },
782 { USB_DEVICE(0x0557, 0x2001) },
783 { USB_DEVICE(0x0729, 0x1284) },
784 { USB_DEVICE(0x1293, 0x0002) },
785 { USB_DEVICE(0x050d, 0x0002) },
792 static struct usb_driver uss720_driver = {
794 .probe = uss720_probe,
795 .disconnect = uss720_disconnect,
796 .id_table = uss720_table,
805 static int __init uss720_init(
void)
808 retval = usb_register(&uss720_driver);
815 "driver to allow nonstandard\n");
817 "USS720 usb to parallel cables\n");
819 "printer, use usblp instead\n");
824 static void __exit uss720_cleanup(
void)