1 /*****************************************************************************
5 * Description: Irda KingSun Dazzle USB Dongle
7 * Author: Alex Villacís Lasso <a_villacis@palosanto.com>
9 * Based on stir4200, mcs7780, kingsun-sir drivers.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 *****************************************************************************/
27 * Following is my most current (2007-07-26) understanding of how the Kingsun
28 * 07D0:4100 dongle (sometimes known as the MA-660) is supposed to work. This
29 * information was deduced by examining the USB traffic captured with USBSnoopy
30 * from the WinXP driver. Feel free to update here as more of the dongle is
33 * General: This dongle exposes one interface with two interrupt endpoints, one
34 * IN and one OUT. In this regard, it is similar to what the Kingsun/Donshine
35 * dongle (07c0:4200) exposes. Traffic is raw and needs to be wrapped and
36 * unwrapped manually as in stir4200, kingsun-sir, and ks959-sir.
38 * Transmission: To transmit an IrDA frame, it is necessary to wrap it, then
39 * split it into multiple segments of up to 7 bytes each, and transmit each in
40 * sequence. It seems that sending a single big block (like kingsun-sir does)
41 * won't work with this dongle. Each segment needs to be prefixed with a value
42 * equal to (unsigned char)0xF8 + <number of bytes in segment>, inside a payload
43 * of exactly 8 bytes. For example, a segment of 1 byte gets prefixed by 0xF9,
44 * and one of 7 bytes gets prefixed by 0xFF. The bytes at the end of the
45 * payload, not considered by the prefix, are ignored (set to 0 by this
48 * Reception: To receive data, the driver must poll the dongle regularly (like
49 * kingsun-sir.c) with interrupt URBs. If data is available, it will be returned
50 * in payloads from 0 to 8 bytes long. When concatenated, these payloads form
51 * a raw IrDA stream that needs to be unwrapped as in stir4200 and kingsun-sir
53 * Speed change: To change the speed of the dongle, the driver prepares a
54 * control URB with the following as a setup packet:
55 * bRequestType USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE
59 * wLength 0x0008 (length of the payload)
60 * The payload is a 8-byte record, apparently identical to the one used in
61 * drivers/usb/serial/cypress_m8.c to change speed:
63 * unsigned int dataBits : 2; // 0 - 5 bits 3 - 8 bits
65 * unsigned int stopBits : 1;
66 * unsigned int parityEnable : 1;
67 * unsigned int parityType : 1;
69 * unsigned int reset : 1;
70 * unsigned char reserved[3]; // set to 0
72 * For now only SIR speeds have been observed with this dongle. Therefore,
73 * nothing is known on what changes (if any) must be done to frame wrapping /
74 * unwrapping for higher than SIR speeds. This driver assumes no change is
75 * necessary and announces support for all the way to 115200 bps.
78 #include <linux/module.h>
79 #include <linux/moduleparam.h>
80 #include <linux/kernel.h>
81 #include <linux/types.h>
82 #include <linux/errno.h>
83 #include <linux/init.h>
84 #include <linux/slab.h>
85 #include <linux/kref.h>
86 #include <linux/usb.h>
87 #include <linux/device.h>
88 #include <linux/crc32.h>
90 #include <asm/unaligned.h>
91 #include <asm/byteorder.h>
92 #include <asm/uaccess.h>
94 #include <net/irda/irda.h>
95 #include <net/irda/wrapper.h>
96 #include <net/irda/crc.h>
98 #define KSDAZZLE_VENDOR_ID 0x07d0
99 #define KSDAZZLE_PRODUCT_ID 0x4100
101 /* These are the currently known USB ids */
102 static struct usb_device_id dongles
[] = {
103 /* KingSun Co,Ltd IrDA/USB Bridge */
104 {USB_DEVICE(KSDAZZLE_VENDOR_ID
, KSDAZZLE_PRODUCT_ID
)},
108 MODULE_DEVICE_TABLE(usb
, dongles
);
110 #define KINGSUN_MTT 0x07
111 #define KINGSUN_REQ_RECV 0x01
112 #define KINGSUN_REQ_SEND 0x09
114 #define KINGSUN_SND_FIFO_SIZE 2048 /* Max packet we can send */
115 #define KINGSUN_RCV_MAX 2048 /* Max transfer we can receive */
117 struct ksdazzle_speedparams
{
118 __le32 baudrate
; /* baud rate, little endian */
121 } __attribute__ ((packed
));
123 #define KS_DATA_5_BITS 0x00
124 #define KS_DATA_6_BITS 0x01
125 #define KS_DATA_7_BITS 0x02
126 #define KS_DATA_8_BITS 0x03
128 #define KS_STOP_BITS_1 0x00
129 #define KS_STOP_BITS_2 0x08
131 #define KS_PAR_DISABLE 0x00
132 #define KS_PAR_EVEN 0x10
133 #define KS_PAR_ODD 0x30
134 #define KS_RESET 0x80
136 #define KINGSUN_EP_IN 0
137 #define KINGSUN_EP_OUT 1
140 struct usb_device
*usbdev
; /* init: probe_irda */
141 struct net_device
*netdev
; /* network layer */
142 struct irlap_cb
*irlap
; /* The link layer we are binded to */
148 unsigned int tx_buf_clear_used
;
149 unsigned int tx_buf_clear_sent
;
154 iobuff_t rx_unwrap_buff
;
156 struct usb_ctrlrequest
*speed_setuprequest
;
157 struct urb
*speed_urb
;
158 struct ksdazzle_speedparams speedparams
;
159 unsigned int new_speed
;
168 /* Callback transmission routine */
169 static void ksdazzle_speed_irq(struct urb
*urb
)
171 /* unlink, shutdown, unplug, other nasties */
172 if (urb
->status
!= 0) {
173 err("ksdazzle_speed_irq: urb asynchronously failed - %d",
178 /* Send a control request to change speed of the dongle */
179 static int ksdazzle_change_speed(struct ksdazzle_cb
*kingsun
, unsigned speed
)
181 static unsigned int supported_speeds
[] = { 2400, 9600, 19200, 38400,
182 57600, 115200, 576000, 1152000, 4000000, 0
187 if (kingsun
->speed_setuprequest
== NULL
|| kingsun
->speed_urb
== NULL
)
190 /* Check that requested speed is among the supported ones */
191 for (i
= 0; supported_speeds
[i
] && supported_speeds
[i
] != speed
; i
++) ;
192 if (supported_speeds
[i
] == 0)
195 memset(&(kingsun
->speedparams
), 0, sizeof(struct ksdazzle_speedparams
));
196 kingsun
->speedparams
.baudrate
= cpu_to_le32(speed
);
197 kingsun
->speedparams
.flags
= KS_DATA_8_BITS
;
199 /* speed_setuprequest pre-filled in ksdazzle_probe */
200 usb_fill_control_urb(kingsun
->speed_urb
, kingsun
->usbdev
,
201 usb_sndctrlpipe(kingsun
->usbdev
, 0),
202 (unsigned char *)kingsun
->speed_setuprequest
,
203 &(kingsun
->speedparams
),
204 sizeof(struct ksdazzle_speedparams
),
205 ksdazzle_speed_irq
, kingsun
);
206 kingsun
->speed_urb
->status
= 0;
207 err
= usb_submit_urb(kingsun
->speed_urb
, GFP_ATOMIC
);
212 /* Submit one fragment of an IrDA frame to the dongle */
213 static void ksdazzle_send_irq(struct urb
*urb
);
214 static int ksdazzle_submit_tx_fragment(struct ksdazzle_cb
*kingsun
)
216 unsigned int wraplen
;
219 /* We can send at most 7 bytes of payload at a time */
221 if (wraplen
> kingsun
->tx_buf_clear_used
)
222 wraplen
= kingsun
->tx_buf_clear_used
;
224 /* Prepare payload prefix with used length */
225 memset(kingsun
->tx_payload
, 0, 8);
226 kingsun
->tx_payload
[0] = (unsigned char)0xf8 + wraplen
;
227 memcpy(kingsun
->tx_payload
+ 1, kingsun
->tx_buf_clear
, wraplen
);
229 usb_fill_int_urb(kingsun
->tx_urb
, kingsun
->usbdev
,
230 usb_sndintpipe(kingsun
->usbdev
, kingsun
->ep_out
),
231 kingsun
->tx_payload
, 8, ksdazzle_send_irq
, kingsun
, 1);
232 kingsun
->tx_urb
->status
= 0;
233 ret
= usb_submit_urb(kingsun
->tx_urb
, GFP_ATOMIC
);
235 /* Remember how much data was sent, in order to update at callback */
236 kingsun
->tx_buf_clear_sent
= (ret
== 0) ? wraplen
: 0;
240 /* Callback transmission routine */
241 static void ksdazzle_send_irq(struct urb
*urb
)
243 struct ksdazzle_cb
*kingsun
= urb
->context
;
244 struct net_device
*netdev
= kingsun
->netdev
;
247 /* in process of stopping, just drop data */
248 if (!netif_running(kingsun
->netdev
)) {
249 err("ksdazzle_send_irq: Network not running!");
253 /* unlink, shutdown, unplug, other nasties */
254 if (urb
->status
!= 0) {
255 err("ksdazzle_send_irq: urb asynchronously failed - %d",
260 if (kingsun
->tx_buf_clear_used
> 0) {
261 /* Update data remaining to be sent */
262 if (kingsun
->tx_buf_clear_sent
< kingsun
->tx_buf_clear_used
) {
263 memmove(kingsun
->tx_buf_clear
,
264 kingsun
->tx_buf_clear
+
265 kingsun
->tx_buf_clear_sent
,
266 kingsun
->tx_buf_clear_used
-
267 kingsun
->tx_buf_clear_sent
);
269 kingsun
->tx_buf_clear_used
-= kingsun
->tx_buf_clear_sent
;
270 kingsun
->tx_buf_clear_sent
= 0;
272 if (kingsun
->tx_buf_clear_used
> 0) {
273 /* There is more data to be sent */
274 if ((ret
= ksdazzle_submit_tx_fragment(kingsun
)) != 0) {
275 err("ksdazzle_send_irq: failed tx_urb submit: %d", ret
);
281 netdev
->stats
.tx_errors
++;
282 netif_start_queue(netdev
);
286 /* All data sent, send next speed && wake network queue */
287 if (kingsun
->new_speed
!= -1 &&
288 cpu_to_le32(kingsun
->new_speed
) !=
289 kingsun
->speedparams
.baudrate
)
290 ksdazzle_change_speed(kingsun
,
293 netif_wake_queue(netdev
);
299 * Called from net/core when new frame is available.
301 static netdev_tx_t
ksdazzle_hard_xmit(struct sk_buff
*skb
,
302 struct net_device
*netdev
)
304 struct ksdazzle_cb
*kingsun
;
305 unsigned int wraplen
;
308 netif_stop_queue(netdev
);
310 /* the IRDA wrapping routines don't deal with non linear skb */
311 SKB_LINEAR_ASSERT(skb
);
313 kingsun
= netdev_priv(netdev
);
315 spin_lock(&kingsun
->lock
);
316 kingsun
->new_speed
= irda_get_next_speed(skb
);
318 /* Append data to the end of whatever data remains to be transmitted */
320 async_wrap_skb(skb
, kingsun
->tx_buf_clear
, KINGSUN_SND_FIFO_SIZE
);
321 kingsun
->tx_buf_clear_used
= wraplen
;
323 if ((ret
= ksdazzle_submit_tx_fragment(kingsun
)) != 0) {
324 err("ksdazzle_hard_xmit: failed tx_urb submit: %d", ret
);
330 netdev
->stats
.tx_errors
++;
331 netif_start_queue(netdev
);
334 netdev
->stats
.tx_packets
++;
335 netdev
->stats
.tx_bytes
+= skb
->len
;
340 spin_unlock(&kingsun
->lock
);
345 /* Receive callback function */
346 static void ksdazzle_rcv_irq(struct urb
*urb
)
348 struct ksdazzle_cb
*kingsun
= urb
->context
;
349 struct net_device
*netdev
= kingsun
->netdev
;
351 /* in process of stopping, just drop data */
352 if (!netif_running(netdev
)) {
353 kingsun
->receiving
= 0;
357 /* unlink, shutdown, unplug, other nasties */
358 if (urb
->status
!= 0) {
359 err("ksdazzle_rcv_irq: urb asynchronously failed - %d",
361 kingsun
->receiving
= 0;
365 if (urb
->actual_length
> 0) {
366 __u8
*bytes
= urb
->transfer_buffer
;
369 for (i
= 0; i
< urb
->actual_length
; i
++) {
370 async_unwrap_char(netdev
, &netdev
->stats
,
371 &kingsun
->rx_unwrap_buff
, bytes
[i
]);
374 (kingsun
->rx_unwrap_buff
.state
!= OUTSIDE_FRAME
) ? 1 : 0;
377 /* This urb has already been filled in ksdazzle_net_open. It is assumed that
378 urb keeps the pointer to the payload buffer.
381 usb_submit_urb(urb
, GFP_ATOMIC
);
385 * Function ksdazzle_net_open (dev)
387 * Network device is taken up. Usually this is done by "ifconfig irda0 up"
389 static int ksdazzle_net_open(struct net_device
*netdev
)
391 struct ksdazzle_cb
*kingsun
= netdev_priv(netdev
);
395 /* At this point, urbs are NULL, and skb is NULL (see ksdazzle_probe) */
396 kingsun
->receiving
= 0;
398 /* Initialize for SIR to copy data directly into skb. */
399 kingsun
->rx_unwrap_buff
.in_frame
= FALSE
;
400 kingsun
->rx_unwrap_buff
.state
= OUTSIDE_FRAME
;
401 kingsun
->rx_unwrap_buff
.truesize
= IRDA_SKB_MAX_MTU
;
402 kingsun
->rx_unwrap_buff
.skb
= dev_alloc_skb(IRDA_SKB_MAX_MTU
);
403 if (!kingsun
->rx_unwrap_buff
.skb
)
406 skb_reserve(kingsun
->rx_unwrap_buff
.skb
, 1);
407 kingsun
->rx_unwrap_buff
.head
= kingsun
->rx_unwrap_buff
.skb
->data
;
409 kingsun
->rx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
410 if (!kingsun
->rx_urb
)
413 kingsun
->tx_urb
= usb_alloc_urb(0, GFP_KERNEL
);
414 if (!kingsun
->tx_urb
)
417 kingsun
->speed_urb
= usb_alloc_urb(0, GFP_KERNEL
);
418 if (!kingsun
->speed_urb
)
421 /* Initialize speed for dongle */
422 kingsun
->new_speed
= 9600;
423 err
= ksdazzle_change_speed(kingsun
, 9600);
428 * Now that everything should be initialized properly,
429 * Open new IrLAP layer instance to take care of us...
431 sprintf(hwname
, "usb#%d", kingsun
->usbdev
->devnum
);
432 kingsun
->irlap
= irlap_open(netdev
, &kingsun
->qos
, hwname
);
433 if (!kingsun
->irlap
) {
434 err("ksdazzle-sir: irlap_open failed");
438 /* Start reception. */
439 usb_fill_int_urb(kingsun
->rx_urb
, kingsun
->usbdev
,
440 usb_rcvintpipe(kingsun
->usbdev
, kingsun
->ep_in
),
441 kingsun
->rx_buf
, KINGSUN_RCV_MAX
, ksdazzle_rcv_irq
,
443 kingsun
->rx_urb
->status
= 0;
444 err
= usb_submit_urb(kingsun
->rx_urb
, GFP_KERNEL
);
446 err("ksdazzle-sir: first urb-submit failed: %d", err
);
450 netif_start_queue(netdev
);
452 /* Situation at this point:
453 - all work buffers allocated
454 - urbs allocated and ready to fill
455 - max rx packet known (in max_rx)
456 - unwrap state machine initialized, in state outside of any frame
457 - receive request in progress
458 - IrLAP layer started, about to hand over packets to send
464 irlap_close(kingsun
->irlap
);
466 usb_free_urb(kingsun
->speed_urb
);
467 kingsun
->speed_urb
= NULL
;
468 usb_free_urb(kingsun
->tx_urb
);
469 kingsun
->tx_urb
= NULL
;
470 usb_free_urb(kingsun
->rx_urb
);
471 kingsun
->rx_urb
= NULL
;
472 if (kingsun
->rx_unwrap_buff
.skb
) {
473 kfree_skb(kingsun
->rx_unwrap_buff
.skb
);
474 kingsun
->rx_unwrap_buff
.skb
= NULL
;
475 kingsun
->rx_unwrap_buff
.head
= NULL
;
481 * Function ksdazzle_net_close (dev)
483 * Network device is taken down. Usually this is done by
484 * "ifconfig irda0 down"
486 static int ksdazzle_net_close(struct net_device
*netdev
)
488 struct ksdazzle_cb
*kingsun
= netdev_priv(netdev
);
490 /* Stop transmit processing */
491 netif_stop_queue(netdev
);
493 /* Mop up receive && transmit urb's */
494 usb_kill_urb(kingsun
->tx_urb
);
495 usb_free_urb(kingsun
->tx_urb
);
496 kingsun
->tx_urb
= NULL
;
498 usb_kill_urb(kingsun
->speed_urb
);
499 usb_free_urb(kingsun
->speed_urb
);
500 kingsun
->speed_urb
= NULL
;
502 usb_kill_urb(kingsun
->rx_urb
);
503 usb_free_urb(kingsun
->rx_urb
);
504 kingsun
->rx_urb
= NULL
;
506 kfree_skb(kingsun
->rx_unwrap_buff
.skb
);
507 kingsun
->rx_unwrap_buff
.skb
= NULL
;
508 kingsun
->rx_unwrap_buff
.head
= NULL
;
509 kingsun
->rx_unwrap_buff
.in_frame
= FALSE
;
510 kingsun
->rx_unwrap_buff
.state
= OUTSIDE_FRAME
;
511 kingsun
->receiving
= 0;
513 /* Stop and remove instance of IrLAP */
514 irlap_close(kingsun
->irlap
);
516 kingsun
->irlap
= NULL
;
522 * IOCTLs : Extra out-of-band network commands...
524 static int ksdazzle_net_ioctl(struct net_device
*netdev
, struct ifreq
*rq
,
527 struct if_irda_req
*irq
= (struct if_irda_req
*)rq
;
528 struct ksdazzle_cb
*kingsun
= netdev_priv(netdev
);
532 case SIOCSBANDWIDTH
: /* Set bandwidth */
533 if (!capable(CAP_NET_ADMIN
))
536 /* Check if the device is still there */
537 if (netif_device_present(kingsun
->netdev
))
538 return ksdazzle_change_speed(kingsun
,
542 case SIOCSMEDIABUSY
: /* Set media busy */
543 if (!capable(CAP_NET_ADMIN
))
546 /* Check if the IrDA stack is still there */
547 if (netif_running(kingsun
->netdev
))
548 irda_device_set_media_busy(kingsun
->netdev
, TRUE
);
552 /* Only approximately true */
553 irq
->ifr_receiving
= kingsun
->receiving
;
563 static const struct net_device_ops ksdazzle_ops
= {
564 .ndo_start_xmit
= ksdazzle_hard_xmit
,
565 .ndo_open
= ksdazzle_net_open
,
566 .ndo_stop
= ksdazzle_net_close
,
567 .ndo_do_ioctl
= ksdazzle_net_ioctl
,
571 * This routine is called by the USB subsystem for each new device
572 * in the system. We need to check if the device is ours, and in
573 * this case start handling it.
575 static int ksdazzle_probe(struct usb_interface
*intf
,
576 const struct usb_device_id
*id
)
578 struct usb_host_interface
*interface
;
579 struct usb_endpoint_descriptor
*endpoint
;
581 struct usb_device
*dev
= interface_to_usbdev(intf
);
582 struct ksdazzle_cb
*kingsun
= NULL
;
583 struct net_device
*net
= NULL
;
585 int pipe
, maxp_in
, maxp_out
;
589 /* Check that there really are two interrupt endpoints. Check based on the
590 one in drivers/usb/input/usbmouse.c
592 interface
= intf
->cur_altsetting
;
593 if (interface
->desc
.bNumEndpoints
!= 2) {
594 err("ksdazzle: expected 2 endpoints, found %d",
595 interface
->desc
.bNumEndpoints
);
598 endpoint
= &interface
->endpoint
[KINGSUN_EP_IN
].desc
;
599 if (!usb_endpoint_is_int_in(endpoint
)) {
600 err("ksdazzle: endpoint 0 is not interrupt IN");
604 ep_in
= endpoint
->bEndpointAddress
;
605 pipe
= usb_rcvintpipe(dev
, ep_in
);
606 maxp_in
= usb_maxpacket(dev
, pipe
, usb_pipeout(pipe
));
607 if (maxp_in
> 255 || maxp_in
<= 1) {
608 err("ksdazzle: endpoint 0 has max packet size %d not in range [2..255]", maxp_in
);
612 endpoint
= &interface
->endpoint
[KINGSUN_EP_OUT
].desc
;
613 if (!usb_endpoint_is_int_out(endpoint
)) {
614 err("ksdazzle: endpoint 1 is not interrupt OUT");
618 ep_out
= endpoint
->bEndpointAddress
;
619 pipe
= usb_sndintpipe(dev
, ep_out
);
620 maxp_out
= usb_maxpacket(dev
, pipe
, usb_pipeout(pipe
));
622 /* Allocate network device container. */
623 net
= alloc_irdadev(sizeof(*kingsun
));
627 SET_NETDEV_DEV(net
, &intf
->dev
);
628 kingsun
= netdev_priv(net
);
629 kingsun
->netdev
= net
;
630 kingsun
->usbdev
= dev
;
631 kingsun
->ep_in
= ep_in
;
632 kingsun
->ep_out
= ep_out
;
633 kingsun
->irlap
= NULL
;
634 kingsun
->tx_urb
= NULL
;
635 kingsun
->tx_buf_clear
= NULL
;
636 kingsun
->tx_buf_clear_used
= 0;
637 kingsun
->tx_buf_clear_sent
= 0;
639 kingsun
->rx_urb
= NULL
;
640 kingsun
->rx_buf
= NULL
;
641 kingsun
->rx_unwrap_buff
.in_frame
= FALSE
;
642 kingsun
->rx_unwrap_buff
.state
= OUTSIDE_FRAME
;
643 kingsun
->rx_unwrap_buff
.skb
= NULL
;
644 kingsun
->receiving
= 0;
645 spin_lock_init(&kingsun
->lock
);
647 kingsun
->speed_setuprequest
= NULL
;
648 kingsun
->speed_urb
= NULL
;
649 kingsun
->speedparams
.baudrate
= 0;
651 /* Allocate input buffer */
652 kingsun
->rx_buf
= kmalloc(KINGSUN_RCV_MAX
, GFP_KERNEL
);
653 if (!kingsun
->rx_buf
)
656 /* Allocate output buffer */
657 kingsun
->tx_buf_clear
= kmalloc(KINGSUN_SND_FIFO_SIZE
, GFP_KERNEL
);
658 if (!kingsun
->tx_buf_clear
)
661 /* Allocate and initialize speed setup packet */
662 kingsun
->speed_setuprequest
=
663 kmalloc(sizeof(struct usb_ctrlrequest
), GFP_KERNEL
);
664 if (!kingsun
->speed_setuprequest
)
666 kingsun
->speed_setuprequest
->bRequestType
=
667 USB_DIR_OUT
| USB_TYPE_CLASS
| USB_RECIP_INTERFACE
;
668 kingsun
->speed_setuprequest
->bRequest
= KINGSUN_REQ_SEND
;
669 kingsun
->speed_setuprequest
->wValue
= cpu_to_le16(0x0200);
670 kingsun
->speed_setuprequest
->wIndex
= cpu_to_le16(0x0001);
671 kingsun
->speed_setuprequest
->wLength
=
672 cpu_to_le16(sizeof(struct ksdazzle_speedparams
));
674 printk(KERN_INFO
"KingSun/Dazzle IRDA/USB found at address %d, "
675 "Vendor: %x, Product: %x\n",
676 dev
->devnum
, le16_to_cpu(dev
->descriptor
.idVendor
),
677 le16_to_cpu(dev
->descriptor
.idProduct
));
679 /* Initialize QoS for this device */
680 irda_init_max_qos_capabilies(&kingsun
->qos
);
682 /* Baud rates known to be supported. Please uncomment if devices (other
683 than a SonyEriccson K300 phone) can be shown to support higher speeds
686 kingsun
->qos
.baud_rate
.bits
=
687 IR_2400
| IR_9600
| IR_19200
| IR_38400
| IR_57600
| IR_115200
;
688 kingsun
->qos
.min_turn_time
.bits
&= KINGSUN_MTT
;
689 irda_qos_bits_to_value(&kingsun
->qos
);
691 /* Override the network functions we need to use */
692 net
->netdev_ops
= &ksdazzle_ops
;
694 ret
= register_netdev(net
);
698 dev_info(&net
->dev
, "IrDA: Registered KingSun/Dazzle device %s\n",
701 usb_set_intfdata(intf
, kingsun
);
703 /* Situation at this point:
704 - all work buffers allocated
705 - setup requests pre-filled
706 - urbs not allocated, set to NULL
707 - max rx packet known (is KINGSUN_FIFO_SIZE)
708 - unwrap state machine (partially) initialized, but skb == NULL
714 kfree(kingsun
->speed_setuprequest
);
715 kfree(kingsun
->tx_buf_clear
);
716 kfree(kingsun
->rx_buf
);
723 * The current device is removed, the USB layer tell us to shut it down...
725 static void ksdazzle_disconnect(struct usb_interface
*intf
)
727 struct ksdazzle_cb
*kingsun
= usb_get_intfdata(intf
);
732 unregister_netdev(kingsun
->netdev
);
734 /* Mop up receive && transmit urb's */
735 usb_kill_urb(kingsun
->speed_urb
);
736 usb_free_urb(kingsun
->speed_urb
);
737 kingsun
->speed_urb
= NULL
;
739 usb_kill_urb(kingsun
->tx_urb
);
740 usb_free_urb(kingsun
->tx_urb
);
741 kingsun
->tx_urb
= NULL
;
743 usb_kill_urb(kingsun
->rx_urb
);
744 usb_free_urb(kingsun
->rx_urb
);
745 kingsun
->rx_urb
= NULL
;
747 kfree(kingsun
->speed_setuprequest
);
748 kfree(kingsun
->tx_buf_clear
);
749 kfree(kingsun
->rx_buf
);
750 free_netdev(kingsun
->netdev
);
752 usb_set_intfdata(intf
, NULL
);
756 /* USB suspend, so power off the transmitter/receiver */
757 static int ksdazzle_suspend(struct usb_interface
*intf
, pm_message_t message
)
759 struct ksdazzle_cb
*kingsun
= usb_get_intfdata(intf
);
761 netif_device_detach(kingsun
->netdev
);
762 if (kingsun
->speed_urb
!= NULL
)
763 usb_kill_urb(kingsun
->speed_urb
);
764 if (kingsun
->tx_urb
!= NULL
)
765 usb_kill_urb(kingsun
->tx_urb
);
766 if (kingsun
->rx_urb
!= NULL
)
767 usb_kill_urb(kingsun
->rx_urb
);
771 /* Coming out of suspend, so reset hardware */
772 static int ksdazzle_resume(struct usb_interface
*intf
)
774 struct ksdazzle_cb
*kingsun
= usb_get_intfdata(intf
);
776 if (kingsun
->rx_urb
!= NULL
) {
777 /* Setup request already filled in ksdazzle_probe */
778 usb_submit_urb(kingsun
->rx_urb
, GFP_KERNEL
);
780 netif_device_attach(kingsun
->netdev
);
787 * USB device callbacks
789 static struct usb_driver irda_driver
= {
790 .name
= "ksdazzle-sir",
791 .probe
= ksdazzle_probe
,
792 .disconnect
= ksdazzle_disconnect
,
795 .suspend
= ksdazzle_suspend
,
796 .resume
= ksdazzle_resume
,
803 static int __init
ksdazzle_init(void)
805 return usb_register(&irda_driver
);
808 module_init(ksdazzle_init
);
813 static void __exit
ksdazzle_cleanup(void)
815 /* Deregister the driver and remove all pending instances */
816 usb_deregister(&irda_driver
);
819 module_exit(ksdazzle_cleanup
);
821 MODULE_AUTHOR("Alex Villacís Lasso <a_villacis@palosanto.com>");
822 MODULE_DESCRIPTION("IrDA-USB Dongle Driver for KingSun Dazzle");
823 MODULE_LICENSE("GPL");