4 * $Id: hfc_usb.c,v 2.3.2.24 2007/10/14 08:40:29 mbachem Exp $
6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip
8 * Authors : Peter Sprenger (sprenger@moving-bytes.de)
9 * Martin Bachem (m.bachem@gmx.de, info@colognechip.com)
11 * based on the first hfc_usb driver of
12 * Werner Cornelius (werner@isdn-development.de)
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2, or (at your option)
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 * See Version Histroy at the bottom of this file
32 #include <linux/types.h>
33 #include <linux/stddef.h>
34 #include <linux/timer.h>
35 #include <linux/init.h>
36 #include <linux/module.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/usb.h>
39 #include <linux/kernel.h>
40 #include <linux/sched.h>
41 #include <linux/moduleparam.h>
46 static const char *hfcusb_revision
=
47 "$Revision: 2.3.2.24 $ $Date: 2007/10/14 08:40:29 $ ";
49 /* Hisax debug support
50 * debug flags defined in hfc_usb.h as HFCUSB_DBG_[*]
52 #define __debug_variable hfc_debug
53 #include "hisax_debug.h"
55 module_param(debug
, uint
, 0);
59 /* private vendor specific data */
61 __u8 led_scheme
; // led display scheme
62 signed short led_bits
[8]; // array of 8 possible LED bitmask settings
63 char *vend_name
; // device name
66 /* VID/PID device list */
67 static struct usb_device_id hfcusb_idtab
[] = {
69 USB_DEVICE(0x0959, 0x2bd0),
70 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
71 {LED_OFF
, {4, 0, 2, 1},
72 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
75 USB_DEVICE(0x0675, 0x1688),
76 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
77 {LED_SCHEME1
, {1, 2, 0, 0},
78 "DrayTek miniVigor 128 USB ISDN TA"}),
81 USB_DEVICE(0x07b0, 0x0007),
82 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
83 {LED_SCHEME1
, {0x80, -64, -32, -16},
84 "Billion tiny USB ISDN TA 128"}),
87 USB_DEVICE(0x0742, 0x2008),
88 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
89 {LED_SCHEME1
, {4, 0, 2, 1},
93 USB_DEVICE(0x0742, 0x2009),
94 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
95 {LED_SCHEME1
, {4, 0, 2, 1},
96 "Aceex USB ISDN TA"}),
99 USB_DEVICE(0x0742, 0x200A),
100 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
101 {LED_SCHEME1
, {4, 0, 2, 1},
105 USB_DEVICE(0x08e3, 0x0301),
106 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
107 {LED_SCHEME1
, {2, 0, 1, 4},
111 USB_DEVICE(0x07fa, 0x0846),
112 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
113 {LED_SCHEME1
, {0x80, -64, -32, -16},
114 "Bewan Modem RNIS USB"}),
117 USB_DEVICE(0x07fa, 0x0847),
118 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
119 {LED_SCHEME1
, {0x80, -64, -32, -16},
120 "Djinn Numeris USB"}),
123 USB_DEVICE(0x07b0, 0x0006),
124 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
125 {LED_SCHEME1
, {0x80, -64, -32, -16},
129 USB_DEVICE(0x071d, 0x1005),
130 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
131 {LED_SCHEME1
, {0x02, 0, 0x01, 0x04},
132 "Eicon DIVA USB 4.0"}),
137 /* structure defining input+output fifos (interrupt/bulk mode) */
138 struct usb_fifo
; /* forward definition */
139 typedef struct iso_urb_struct
{
141 __u8 buffer
[ISO_BUFFER_SIZE
]; /* buffer incoming/outgoing data */
142 struct usb_fifo
*owner_fifo
; /* pointer to owner fifo */
145 struct hfcusb_data
; /* forward definition */
147 typedef struct usb_fifo
{
148 int fifonum
; /* fifo index attached to this structure */
149 int active
; /* fifo is currently active */
150 struct hfcusb_data
*hfc
; /* pointer to main structure */
151 int pipe
; /* address of endpoint */
152 __u8 usb_packet_maxlen
; /* maximum length for usb transfer */
153 unsigned int max_size
; /* maximum size of receive/send packet */
154 __u8 intervall
; /* interrupt interval */
155 struct sk_buff
*skbuff
; /* actual used buffer */
156 struct urb
*urb
; /* transfer structure for usb routines */
157 __u8 buffer
[128]; /* buffer incoming/outgoing data */
158 int bit_line
; /* how much bits are in the fifo? */
160 volatile __u8 usb_transfer_mode
; /* switched between ISO and INT */
161 iso_urb_struct iso
[2]; /* need two urbs to have one always for pending */
162 struct hisax_if
*hif
; /* hisax interface */
163 int delete_flg
; /* only delete skbuff once */
164 int last_urblen
; /* remember length of last packet */
167 /* structure holding all data for one device */
168 typedef struct hfcusb_data
{
169 /* HiSax Interface for loadable Layer1 drivers */
170 struct hisax_d_if d_if
; /* see hisax_if.h */
171 struct hisax_b_if b_if
[2]; /* see hisax_if.h */
174 struct usb_device
*dev
; /* our device */
175 int if_used
; /* used interface number */
176 int alt_used
; /* used alternate config */
177 int ctrl_paksize
; /* control pipe packet size */
178 int ctrl_in_pipe
, /* handles for control pipe */
180 int cfg_used
; /* configuration index used */
181 int vend_idx
; /* vendor found */
182 int b_mode
[2]; /* B-channel mode */
183 int l1_activated
; /* layer 1 activated */
184 int disc_flag
; /* TRUE if device was disonnected to avoid some USB actions */
185 int packet_size
, iso_packet_size
;
187 /* control pipe background handling */
188 ctrl_buft ctrl_buff
[HFC_CTRL_BUFSIZE
]; /* buffer holding queued data */
189 volatile int ctrl_in_idx
, ctrl_out_idx
, ctrl_cnt
; /* input/output pointer + count */
190 struct urb
*ctrl_urb
; /* transfer structure for control channel */
192 struct usb_ctrlrequest ctrl_write
; /* buffer for control write request */
193 struct usb_ctrlrequest ctrl_read
; /* same for read request */
195 __u8 old_led_state
, led_state
;
197 volatile __u8 threshold_mask
; /* threshold actually reported */
198 volatile __u8 bch_enables
; /* or mask for sctrl_r and sctrl register values */
200 usb_fifo fifos
[HFCUSB_NUM_FIFOS
]; /* structure holding all fifo data */
202 volatile __u8 l1_state
; /* actual l1 state */
203 struct timer_list t3_timer
; /* timer 3 for activation/deactivation */
204 struct timer_list t4_timer
; /* timer 4 for activation/deactivation */
208 static void collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
,
211 static inline const char *
212 symbolic(struct hfcusb_symbolic_list list
[], const int num
)
215 for (i
= 0; list
[i
].name
!= NULL
; i
++)
216 if (list
[i
].num
== num
)
217 return (list
[i
].name
);
218 return "<unknown ERROR>";
222 ctrl_start_transfer(hfcusb_data
* hfc
)
225 hfc
->ctrl_urb
->pipe
= hfc
->ctrl_out_pipe
;
226 hfc
->ctrl_urb
->setup_packet
= (u_char
*) & hfc
->ctrl_write
;
227 hfc
->ctrl_urb
->transfer_buffer
= NULL
;
228 hfc
->ctrl_urb
->transfer_buffer_length
= 0;
229 hfc
->ctrl_write
.wIndex
=
230 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].hfc_reg
);
231 hfc
->ctrl_write
.wValue
=
232 cpu_to_le16(hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].reg_val
);
234 usb_submit_urb(hfc
->ctrl_urb
, GFP_ATOMIC
); /* start transfer */
236 } /* ctrl_start_transfer */
239 queue_control_request(hfcusb_data
* hfc
, __u8 reg
, __u8 val
, int action
)
243 if (hfc
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
)
244 return (1); /* no space left */
245 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_in_idx
]; /* pointer to new index */
248 buf
->action
= action
;
249 if (++hfc
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
250 hfc
->ctrl_in_idx
= 0; /* pointer wrap */
251 if (++hfc
->ctrl_cnt
== 1)
252 ctrl_start_transfer(hfc
);
257 ctrl_complete(struct urb
*urb
)
259 hfcusb_data
*hfc
= (hfcusb_data
*) urb
->context
;
264 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_out_idx
];
265 hfc
->ctrl_cnt
--; /* decrement actual count */
266 if (++hfc
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
267 hfc
->ctrl_out_idx
= 0; /* pointer wrap */
269 ctrl_start_transfer(hfc
); /* start next transfer */
273 /* write led data to auxport & invert if necessary */
275 write_led(hfcusb_data
* hfc
, __u8 led_state
)
277 if (led_state
!= hfc
->old_led_state
) {
278 hfc
->old_led_state
= led_state
;
279 queue_control_request(hfc
, HFCUSB_P_DATA
, led_state
, 1);
284 set_led_bit(hfcusb_data
* hfc
, signed short led_bits
, int on
)
288 hfc
->led_state
&= ~abs(led_bits
);
290 hfc
->led_state
|= led_bits
;
293 hfc
->led_state
|= abs(led_bits
);
295 hfc
->led_state
&= ~led_bits
;
299 /* handle LED requests */
301 handle_led(hfcusb_data
* hfc
, int event
)
303 hfcsusb_vdata
*driver_info
=
304 (hfcsusb_vdata
*) hfcusb_idtab
[hfc
->vend_idx
].driver_info
;
306 /* if no scheme -> no LED action */
307 if (driver_info
->led_scheme
== LED_OFF
)
312 set_led_bit(hfc
, driver_info
->led_bits
[0], 1);
313 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
314 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
315 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
318 set_led_bit(hfc
, driver_info
->led_bits
[0], 0);
319 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
320 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
321 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
324 set_led_bit(hfc
, driver_info
->led_bits
[1], 1);
327 set_led_bit(hfc
, driver_info
->led_bits
[1], 0);
330 set_led_bit(hfc
, driver_info
->led_bits
[2], 1);
333 set_led_bit(hfc
, driver_info
->led_bits
[2], 0);
336 set_led_bit(hfc
, driver_info
->led_bits
[3], 1);
339 set_led_bit(hfc
, driver_info
->led_bits
[3], 0);
342 write_led(hfc
, hfc
->led_state
);
345 /* ISDN l1 timer T3 expires */
347 l1_timer_expire_t3(hfcusb_data
* hfc
)
349 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
352 DBG(HFCUSB_DBG_STATES
,
353 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
355 hfc
->l1_activated
= 0;
356 handle_led(hfc
, LED_S0_OFF
);
358 queue_control_request(hfc
, HFCUSB_STATES
, 0x10, 1);
359 queue_control_request(hfc
, HFCUSB_STATES
, 3, 1);
362 /* ISDN l1 timer T4 expires */
364 l1_timer_expire_t4(hfcusb_data
* hfc
)
366 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
369 DBG(HFCUSB_DBG_STATES
,
370 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
372 hfc
->l1_activated
= 0;
373 handle_led(hfc
, LED_S0_OFF
);
376 /* S0 state changed */
378 s0_state_handler(hfcusb_data
* hfc
, __u8 state
)
382 old_state
= hfc
->l1_state
;
383 if (state
== old_state
|| state
< 1 || state
> 8)
386 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: S0 statechange(%d -> %d)",
389 if (state
< 4 || state
== 7 || state
== 8) {
390 if (timer_pending(&hfc
->t3_timer
))
391 del_timer(&hfc
->t3_timer
);
392 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T3 deactivated");
395 if (timer_pending(&hfc
->t4_timer
))
396 del_timer(&hfc
->t4_timer
);
397 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T4 deactivated");
400 if (state
== 7 && !hfc
->l1_activated
) {
401 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
402 PH_ACTIVATE
| INDICATION
, NULL
);
403 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
404 hfc
->l1_activated
= 1;
405 handle_led(hfc
, LED_S0_ON
);
406 } else if (state
<= 3 /* && activated */ ) {
407 if (old_state
== 7 || old_state
== 8) {
408 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: T4 activated");
409 if (!timer_pending(&hfc
->t4_timer
)) {
410 hfc
->t4_timer
.expires
=
411 jiffies
+ (HFC_TIMER_T4
* HZ
) / 1000;
412 add_timer(&hfc
->t4_timer
);
415 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
416 PH_DEACTIVATE
| INDICATION
,
418 DBG(HFCUSB_DBG_STATES
,
419 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
420 hfc
->l1_activated
= 0;
421 handle_led(hfc
, LED_S0_OFF
);
424 hfc
->l1_state
= state
;
428 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
429 void *buf
, int num_packets
, int packet_size
, int interval
,
430 usb_complete_t complete
, void *context
)
436 urb
->complete
= complete
;
437 urb
->number_of_packets
= num_packets
;
438 urb
->transfer_buffer_length
= packet_size
* num_packets
;
439 urb
->context
= context
;
440 urb
->transfer_buffer
= buf
;
441 urb
->transfer_flags
= URB_ISO_ASAP
;
442 urb
->actual_length
= 0;
443 urb
->interval
= interval
;
444 for (k
= 0; k
< num_packets
; k
++) {
445 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
446 urb
->iso_frame_desc
[k
].length
= packet_size
;
447 urb
->iso_frame_desc
[k
].actual_length
= 0;
451 /* allocs urbs and start isoc transfer with two pending urbs to avoid
452 * gaps in the transfer chain
455 start_isoc_chain(usb_fifo
* fifo
, int num_packets_per_urb
,
456 usb_complete_t complete
, int packet_size
)
460 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: starting ISO-URBs for fifo:%d\n",
463 /* allocate Memory for Iso out Urbs */
464 for (i
= 0; i
< 2; i
++) {
465 if (!(fifo
->iso
[i
].purb
)) {
467 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
468 if (!(fifo
->iso
[i
].purb
)) {
470 "alloc urb for fifo %i failed!!!",
473 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
475 /* Init the first iso */
476 if (ISO_BUFFER_SIZE
>=
477 (fifo
->usb_packet_maxlen
*
478 num_packets_per_urb
)) {
479 fill_isoc_urb(fifo
->iso
[i
].purb
,
480 fifo
->hfc
->dev
, fifo
->pipe
,
483 fifo
->usb_packet_maxlen
,
484 fifo
->intervall
, complete
,
486 memset(fifo
->iso
[i
].buffer
, 0,
487 sizeof(fifo
->iso
[i
].buffer
));
488 /* defining packet delimeters in fifo->buffer */
489 for (k
= 0; k
< num_packets_per_urb
; k
++) {
491 iso_frame_desc
[k
].offset
=
494 iso_frame_desc
[k
].length
=
499 "HFC-S USB: ISO Buffer size to small!\n");
502 fifo
->bit_line
= BITLINE_INF
;
504 errcode
= usb_submit_urb(fifo
->iso
[i
].purb
, GFP_KERNEL
);
505 fifo
->active
= (errcode
>= 0) ? 1 : 0;
507 printk(KERN_INFO
"HFC-S USB: usb_submit_urb URB nr:%d, error(%i): '%s'\n",
508 i
, errcode
, symbolic(urb_errlist
, errcode
));
510 return (fifo
->active
);
513 /* stops running iso chain and frees their pending urbs */
515 stop_isoc_chain(usb_fifo
* fifo
)
519 for (i
= 0; i
< 2; i
++) {
520 if (fifo
->iso
[i
].purb
) {
522 "HFC-S USB: Stopping iso chain for fifo %i.%i",
524 usb_kill_urb(fifo
->iso
[i
].purb
);
525 usb_free_urb(fifo
->iso
[i
].purb
);
526 fifo
->iso
[i
].purb
= NULL
;
530 usb_kill_urb(fifo
->urb
);
531 usb_free_urb(fifo
->urb
);
536 /* defines how much ISO packets are handled in one URB */
537 static int iso_packets
[8] =
538 { ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
,
539 ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
543 tx_iso_complete(struct urb
*urb
)
545 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
546 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
547 hfcusb_data
*hfc
= fifo
->hfc
;
548 int k
, tx_offset
, num_isoc_packets
, sink
, len
, current_len
,
550 int frame_complete
, transp_mode
, fifon
, status
;
553 fifon
= fifo
->fifonum
;
554 status
= urb
->status
;
558 /* ISO transfer only partially completed,
559 look at individual frame status for details */
560 if (status
== -EXDEV
) {
561 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: tx_iso_complete with -EXDEV"
562 ", urb->status %d, fifonum %d\n",
565 for (k
= 0; k
< iso_packets
[fifon
]; ++k
) {
566 errcode
= urb
->iso_frame_desc
[k
].status
;
568 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: tx_iso_complete "
569 "packet %i, status: %i\n",
573 // clear status, so go on with ISO transfers
577 if (fifo
->active
&& !status
) {
579 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
582 /* is FifoFull-threshold set for our channel? */
583 threshbit
= (hfc
->threshold_mask
& (1 << fifon
));
584 num_isoc_packets
= iso_packets
[fifon
];
586 /* predict dataflow to avoid fifo overflow */
587 if (fifon
>= HFCUSB_D_TX
) {
588 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
590 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
592 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
593 context_iso_urb
->buffer
, num_isoc_packets
,
594 fifo
->usb_packet_maxlen
, fifo
->intervall
,
595 tx_iso_complete
, urb
->context
);
596 memset(context_iso_urb
->buffer
, 0,
597 sizeof(context_iso_urb
->buffer
));
600 /* Generate next ISO Packets */
601 for (k
= 0; k
< num_isoc_packets
; ++k
) {
603 len
= fifo
->skbuff
->len
;
604 /* we lower data margin every msec */
605 fifo
->bit_line
-= sink
;
606 current_len
= (0 - fifo
->bit_line
) / 8;
607 /* maximum 15 byte for every ISO packet makes our life easier */
608 if (current_len
> 14)
612 current_len
) ? len
: current_len
;
613 /* how much bit do we put on the line? */
614 fifo
->bit_line
+= current_len
* 8;
616 context_iso_urb
->buffer
[tx_offset
] = 0;
617 if (current_len
== len
) {
619 /* here frame completion */
621 buffer
[tx_offset
] = 1;
622 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
623 fifo
->bit_line
+= 32;
628 memcpy(context_iso_urb
->buffer
+
629 tx_offset
+ 1, fifo
->skbuff
->data
,
631 skb_pull(fifo
->skbuff
, current_len
);
633 /* define packet delimeters within the URB buffer */
634 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
635 urb
->iso_frame_desc
[k
].length
=
638 tx_offset
+= (current_len
+ 1);
640 urb
->iso_frame_desc
[k
].offset
=
643 urb
->iso_frame_desc
[k
].length
= 1;
644 fifo
->bit_line
-= sink
; /* we lower data margin every msec */
646 if (fifo
->bit_line
< BITLINE_INF
) {
647 fifo
->bit_line
= BITLINE_INF
;
651 if (frame_complete
) {
652 fifo
->delete_flg
= 1;
653 fifo
->hif
->l1l2(fifo
->hif
,
655 (void *) (unsigned long) fifo
->skbuff
->
657 if (fifo
->skbuff
&& fifo
->delete_flg
) {
658 dev_kfree_skb_any(fifo
->skbuff
);
660 fifo
->delete_flg
= 0;
665 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
668 "HFC-S USB: error submitting ISO URB: %d\n",
672 if (status
&& !hfc
->disc_flag
) {
674 "HFC-S USB: tx_iso_complete: error(%i): '%s', fifonum=%d\n",
675 status
, symbolic(urb_errlist
, status
), fifon
);
681 rx_iso_complete(struct urb
*urb
)
683 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
684 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
685 hfcusb_data
*hfc
= fifo
->hfc
;
686 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
688 unsigned int iso_status
;
692 fifon
= fifo
->fifonum
;
693 status
= urb
->status
;
695 if (urb
->status
== -EOVERFLOW
) {
696 DBG(HFCUSB_DBG_VERBOSE_USB
,
697 "HFC-USB: ignoring USB DATAOVERRUN fifo(%i)", fifon
);
701 /* ISO transfer only partially completed,
702 look at individual frame status for details */
703 if (status
== -EXDEV
) {
704 DBG(HFCUSB_DBG_VERBOSE_USB
, "HFC-S USB: rx_iso_complete with -EXDEV "
705 "urb->status %d, fifonum %d\n",
710 if (fifo
->active
&& !status
) {
711 num_isoc_packets
= iso_packets
[fifon
];
712 maxlen
= fifo
->usb_packet_maxlen
;
713 for (k
= 0; k
< num_isoc_packets
; ++k
) {
714 len
= urb
->iso_frame_desc
[k
].actual_length
;
715 offset
= urb
->iso_frame_desc
[k
].offset
;
716 buf
= context_iso_urb
->buffer
+ offset
;
717 iso_status
= urb
->iso_frame_desc
[k
].status
;
719 if (iso_status
&& !hfc
->disc_flag
)
720 DBG(HFCUSB_DBG_VERBOSE_USB
,
721 "HFC-S USB: rx_iso_complete "
722 "ISO packet %i, status: %i\n",
725 if (fifon
== HFCUSB_D_RX
) {
726 DBG(HFCUSB_DBG_VERBOSE_USB
,
727 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
728 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
729 fifo
->last_urblen
, len
, maxlen
,
732 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB
, buf
, len
);
735 if (fifo
->last_urblen
!= maxlen
) {
736 /* the threshold mask is in the 2nd status byte */
737 hfc
->threshold_mask
= buf
[1];
738 /* care for L1 state only for D-Channel
739 to avoid overlapped iso completions */
740 if (fifon
== HFCUSB_D_RX
) {
741 /* the S0 state is in the upper half
742 of the 1st status byte */
743 s0_state_handler(hfc
, buf
[0] >> 4);
745 eof
[fifon
] = buf
[0] & 1;
747 collect_rx_frame(fifo
, buf
+ 2,
752 collect_rx_frame(fifo
, buf
, len
,
754 maxlen
) ? eof
[fifon
] :
757 fifo
->last_urblen
= len
;
760 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
761 context_iso_urb
->buffer
, num_isoc_packets
,
762 fifo
->usb_packet_maxlen
, fifo
->intervall
,
763 rx_iso_complete
, urb
->context
);
764 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
767 "HFC-S USB: error submitting ISO URB: %d\n",
771 if (status
&& !hfc
->disc_flag
) {
773 "HFC-S USB: rx_iso_complete : "
774 "urb->status %d, fifonum %d\n",
780 /* collect rx data from INT- and ISO-URBs */
782 collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
, int finish
)
784 hfcusb_data
*hfc
= fifo
->hfc
;
785 int transp_mode
, fifon
;
787 fifon
= fifo
->fifonum
;
789 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
793 fifo
->skbuff
= dev_alloc_skb(fifo
->max_size
+ 3);
796 "HFC-S USB: cannot allocate buffer for fifo(%d)\n",
802 if (fifo
->skbuff
->len
+ len
< fifo
->max_size
) {
803 memcpy(skb_put(fifo
->skbuff
, len
), data
, len
);
805 DBG(HFCUSB_DBG_FIFO_ERR
,
806 "HCF-USB: got frame exceeded fifo->max_size(%d) fifo(%d)",
807 fifo
->max_size
, fifon
);
808 DBG_SKB(HFCUSB_DBG_VERBOSE_USB
, fifo
->skbuff
);
809 skb_trim(fifo
->skbuff
, 0);
812 if (transp_mode
&& fifo
->skbuff
->len
>= 128) {
813 fifo
->hif
->l1l2(fifo
->hif
, PH_DATA
| INDICATION
,
818 /* we have a complete hdlc packet */
820 if (fifo
->skbuff
->len
> 3 &&
821 !fifo
->skbuff
->data
[fifo
->skbuff
->len
- 1]) {
823 if (fifon
== HFCUSB_D_RX
) {
824 DBG(HFCUSB_DBG_DCHANNEL
,
825 "HFC-S USB: D-RX len(%d)", fifo
->skbuff
->len
);
826 DBG_SKB(HFCUSB_DBG_DCHANNEL
, fifo
->skbuff
);
829 /* remove CRC & status */
830 skb_trim(fifo
->skbuff
, fifo
->skbuff
->len
- 3);
831 if (fifon
== HFCUSB_PCM_RX
) {
832 fifo
->hif
->l1l2(fifo
->hif
,
833 PH_DATA_E
| INDICATION
,
836 fifo
->hif
->l1l2(fifo
->hif
,
837 PH_DATA
| INDICATION
,
839 fifo
->skbuff
= NULL
; /* buffer was freed from upper layer */
841 DBG(HFCUSB_DBG_FIFO_ERR
,
842 "HFC-S USB: ERROR frame len(%d) fifo(%d)",
843 fifo
->skbuff
->len
, fifon
);
844 DBG_SKB(HFCUSB_DBG_VERBOSE_USB
, fifo
->skbuff
);
845 skb_trim(fifo
->skbuff
, 0);
851 rx_int_complete(struct urb
*urb
)
855 __u8
*buf
, maxlen
, fifon
;
856 usb_fifo
*fifo
= (usb_fifo
*) urb
->context
;
857 hfcusb_data
*hfc
= fifo
->hfc
;
860 urb
->dev
= hfc
->dev
; /* security init */
862 fifon
= fifo
->fifonum
;
863 if ((!fifo
->active
) || (urb
->status
)) {
864 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: RX-Fifo %i is going down (%i)",
867 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
869 dev_kfree_skb_any(fifo
->skbuff
);
874 len
= urb
->actual_length
;
876 maxlen
= fifo
->usb_packet_maxlen
;
878 if (fifon
== HFCUSB_D_RX
) {
879 DBG(HFCUSB_DBG_VERBOSE_USB
,
880 "HFC-S USB: INT-D-RX lst_urblen:%2d "
881 "act_urblen:%2d max-urblen:%2d EOF:0x%0x",
882 fifo
->last_urblen
, len
, maxlen
,
884 DBG_PACKET(HFCUSB_DBG_VERBOSE_USB
, buf
, len
);
887 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
888 /* the threshold mask is in the 2nd status byte */
889 hfc
->threshold_mask
= buf
[1];
890 /* the S0 state is in the upper half of the 1st status byte */
891 s0_state_handler(hfc
, buf
[0] >> 4);
892 eof
[fifon
] = buf
[0] & 1;
893 /* if we have more than the 2 status bytes -> collect data */
895 collect_rx_frame(fifo
, buf
+ 2,
896 urb
->actual_length
- 2,
897 (len
< maxlen
) ? eof
[fifon
] : 0);
899 collect_rx_frame(fifo
, buf
, urb
->actual_length
,
900 (len
< maxlen
) ? eof
[fifon
] : 0);
902 fifo
->last_urblen
= urb
->actual_length
;
903 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
906 "HFC-S USB: %s error resubmitting URB fifo(%d)\n",
911 /* start initial INT-URB for certain fifo */
913 start_int_fifo(usb_fifo
* fifo
)
917 DBG(HFCUSB_DBG_INIT
, "HFC-S USB: starting RX INT-URB for fifo:%d\n",
921 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
925 usb_fill_int_urb(fifo
->urb
, fifo
->hfc
->dev
, fifo
->pipe
,
926 fifo
->buffer
, fifo
->usb_packet_maxlen
,
927 rx_int_complete
, fifo
, fifo
->intervall
);
928 fifo
->active
= 1; /* must be marked active */
929 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
932 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
940 setup_bchannel(hfcusb_data
* hfc
, int channel
, int mode
)
942 __u8 val
, idx_table
[2] = { 0, 2 };
944 if (hfc
->disc_flag
) {
947 DBG(HFCUSB_DBG_STATES
, "HFC-S USB: setting channel %d to mode %d",
949 hfc
->b_mode
[channel
] = mode
;
953 if (mode
!= L1_MODE_NULL
)
954 val
= 8; /* enable fifo? */
955 if (mode
== L1_MODE_TRANS
)
956 val
|= 2; /* set transparent bit */
958 /* set FIFO to transmit register */
959 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
], 1);
960 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
962 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
963 /* set FIFO to receive register */
964 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
] + 1, 1);
965 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
967 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
974 queue_control_request(hfc
, HFCUSB_SCTRL
, val
, 1);
981 queue_control_request(hfc
, HFCUSB_SCTRL_R
, val
, 1);
983 if (mode
== L1_MODE_NULL
) {
985 handle_led(hfc
, LED_B2_OFF
);
987 handle_led(hfc
, LED_B1_OFF
);
990 handle_led(hfc
, LED_B2_ON
);
992 handle_led(hfc
, LED_B1_ON
);
997 hfc_usb_l2l1(struct hisax_if
*my_hisax_if
, int pr
, void *arg
)
999 usb_fifo
*fifo
= my_hisax_if
->priv
;
1000 hfcusb_data
*hfc
= fifo
->hfc
;
1003 case PH_ACTIVATE
| REQUEST
:
1004 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1005 DBG(HFCUSB_DBG_STATES
,
1006 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1008 if (hfc
->l1_state
!= 3
1009 && hfc
->l1_state
!= 7) {
1010 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
1014 DBG(HFCUSB_DBG_STATES
,
1015 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1017 if (hfc
->l1_state
== 7) { /* l1 already active */
1018 hfc
->d_if
.ifc
.l1l2(&hfc
->
1025 DBG(HFCUSB_DBG_STATES
,
1026 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1028 /* force sending sending INFO1 */
1029 queue_control_request(hfc
,
1034 /* start l1 activation */
1035 queue_control_request(hfc
,
1052 DBG(HFCUSB_DBG_STATES
,
1053 "HFC_USB: hfc_usb_d_l2l1 B-chan: PH_ACTIVATE | REQUEST");
1056 HFCUSB_B1_TX
) ? 0 : 1,
1058 fifo
->hif
->l1l2(fifo
->hif
,
1059 PH_ACTIVATE
| INDICATION
,
1063 case PH_DEACTIVATE
| REQUEST
:
1064 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1065 DBG(HFCUSB_DBG_STATES
,
1066 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1068 DBG(HFCUSB_DBG_STATES
,
1069 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1072 HFCUSB_B1_TX
) ? 0 : 1,
1073 (int) L1_MODE_NULL
);
1074 fifo
->hif
->l1l2(fifo
->hif
,
1075 PH_DEACTIVATE
| INDICATION
,
1079 case PH_DATA
| REQUEST
:
1080 if (fifo
->skbuff
&& fifo
->delete_flg
) {
1081 dev_kfree_skb_any(fifo
->skbuff
);
1082 fifo
->skbuff
= NULL
;
1083 fifo
->delete_flg
= 0;
1085 fifo
->skbuff
= arg
; /* we have a new buffer */
1088 DBG(HFCUSB_DBG_STATES
,
1089 "HFC_USB: hfc_usb_d_l2l1: unknown state : %#x", pr
);
1094 /* initial init HFC-S USB chip registers, HiSax interface, USB URBs */
1096 hfc_usb_init(hfcusb_data
* hfc
)
1101 struct hisax_b_if
*p_b_if
[2];
1103 /* check the chip id */
1104 if (read_usb(hfc
, HFCUSB_CHIP_ID
, &b
) != 1) {
1105 printk(KERN_INFO
"HFC-USB: cannot read chip id\n");
1108 if (b
!= HFCUSB_CHIPID
) {
1109 printk(KERN_INFO
"HFC-S USB: Invalid chip id 0x%02x\n", b
);
1113 /* first set the needed config, interface and alternate */
1114 err
= usb_set_interface(hfc
->dev
, hfc
->if_used
, hfc
->alt_used
);
1117 write_usb(hfc
, HFCUSB_CIRM
, 8);
1118 /* aux = output, reset off */
1119 write_usb(hfc
, HFCUSB_CIRM
, 0x10);
1121 /* set USB_SIZE to match wMaxPacketSize for INT or BULK transfers */
1122 write_usb(hfc
, HFCUSB_USB_SIZE
,
1123 (hfc
->packet_size
/ 8) | ((hfc
->packet_size
/ 8) << 4));
1125 /* set USB_SIZE_I to match wMaxPacketSize for ISO transfers */
1126 write_usb(hfc
, HFCUSB_USB_SIZE_I
, hfc
->iso_packet_size
);
1128 /* enable PCM/GCI master mode */
1129 write_usb(hfc
, HFCUSB_MST_MODE1
, 0); /* set default values */
1130 write_usb(hfc
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1132 /* init the fifos */
1133 write_usb(hfc
, HFCUSB_F_THRES
,
1134 (HFCUSB_TX_THRESHOLD
/
1135 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1138 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1139 write_usb(hfc
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1140 fifo
[i
].skbuff
= NULL
; /* init buffer pointer */
1142 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1143 fifo
[i
].last_urblen
= 0;
1144 /* set 2 bit for D- & E-channel */
1145 write_usb(hfc
, HFCUSB_HDLC_PAR
,
1146 ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1147 /* rx hdlc, enable IFF for D-channel */
1148 write_usb(hfc
, HFCUSB_CON_HDLC
,
1149 ((i
== HFCUSB_D_TX
) ? 0x09 : 0x08));
1150 write_usb(hfc
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1153 write_usb(hfc
, HFCUSB_CLKDEL
, 0x0f); /* clock delay value */
1154 write_usb(hfc
, HFCUSB_STATES
, 3 | 0x10); /* set deactivated mode */
1155 write_usb(hfc
, HFCUSB_STATES
, 3); /* enable state machine */
1157 write_usb(hfc
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1158 write_usb(hfc
, HFCUSB_SCTRL
, 0x40); /* disable B transmitters + capacitive mode */
1160 /* set both B-channel to not connected */
1161 hfc
->b_mode
[0] = L1_MODE_NULL
;
1162 hfc
->b_mode
[1] = L1_MODE_NULL
;
1164 hfc
->l1_activated
= 0;
1167 hfc
->old_led_state
= 0;
1169 /* init the t3 timer */
1170 init_timer(&hfc
->t3_timer
);
1171 hfc
->t3_timer
.data
= (long) hfc
;
1172 hfc
->t3_timer
.function
= (void *) l1_timer_expire_t3
;
1174 /* init the t4 timer */
1175 init_timer(&hfc
->t4_timer
);
1176 hfc
->t4_timer
.data
= (long) hfc
;
1177 hfc
->t4_timer
.function
= (void *) l1_timer_expire_t4
;
1179 /* init the background machinery for control requests */
1180 hfc
->ctrl_read
.bRequestType
= 0xc0;
1181 hfc
->ctrl_read
.bRequest
= 1;
1182 hfc
->ctrl_read
.wLength
= cpu_to_le16(1);
1183 hfc
->ctrl_write
.bRequestType
= 0x40;
1184 hfc
->ctrl_write
.bRequest
= 0;
1185 hfc
->ctrl_write
.wLength
= 0;
1186 usb_fill_control_urb(hfc
->ctrl_urb
,
1189 (u_char
*) & hfc
->ctrl_write
,
1190 NULL
, 0, ctrl_complete
, hfc
);
1191 /* Init All Fifos */
1192 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1193 hfc
->fifos
[i
].iso
[0].purb
= NULL
;
1194 hfc
->fifos
[i
].iso
[1].purb
= NULL
;
1195 hfc
->fifos
[i
].active
= 0;
1197 /* register Modul to upper Hisax Layers */
1198 hfc
->d_if
.owner
= THIS_MODULE
;
1199 hfc
->d_if
.ifc
.priv
= &hfc
->fifos
[HFCUSB_D_TX
];
1200 hfc
->d_if
.ifc
.l2l1
= hfc_usb_l2l1
;
1201 for (i
= 0; i
< 2; i
++) {
1202 hfc
->b_if
[i
].ifc
.priv
= &hfc
->fifos
[HFCUSB_B1_TX
+ i
* 2];
1203 hfc
->b_if
[i
].ifc
.l2l1
= hfc_usb_l2l1
;
1204 p_b_if
[i
] = &hfc
->b_if
[i
];
1206 /* default Prot: EURO ISDN, should be a module_param */
1208 i
= hisax_register(&hfc
->d_if
, p_b_if
, "hfc_usb", hfc
->protocol
);
1210 printk(KERN_INFO
"HFC-S USB: hisax_register -> %d\n", i
);
1214 #ifdef CONFIG_HISAX_DEBUG
1218 for (i
= 0; i
< 4; i
++)
1219 hfc
->fifos
[i
].hif
= &p_b_if
[i
/ 2]->ifc
;
1220 for (i
= 4; i
< 8; i
++)
1221 hfc
->fifos
[i
].hif
= &hfc
->d_if
.ifc
;
1223 /* 3 (+1) INT IN + 3 ISO OUT */
1224 if (hfc
->cfg_used
== CNF_3INT3ISO
|| hfc
->cfg_used
== CNF_4INT3ISO
) {
1225 start_int_fifo(hfc
->fifos
+ HFCUSB_D_RX
);
1226 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1227 start_int_fifo(hfc
->fifos
+ HFCUSB_PCM_RX
);
1228 start_int_fifo(hfc
->fifos
+ HFCUSB_B1_RX
);
1229 start_int_fifo(hfc
->fifos
+ HFCUSB_B2_RX
);
1231 /* 3 (+1) ISO IN + 3 ISO OUT */
1232 if (hfc
->cfg_used
== CNF_3ISO3ISO
|| hfc
->cfg_used
== CNF_4ISO3ISO
) {
1233 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_RX
, ISOC_PACKETS_D
,
1234 rx_iso_complete
, 16);
1235 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1236 start_isoc_chain(hfc
->fifos
+ HFCUSB_PCM_RX
,
1237 ISOC_PACKETS_D
, rx_iso_complete
,
1239 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_RX
, ISOC_PACKETS_B
,
1240 rx_iso_complete
, 16);
1241 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_RX
, ISOC_PACKETS_B
,
1242 rx_iso_complete
, 16);
1245 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_TX
, ISOC_PACKETS_D
,
1246 tx_iso_complete
, 1);
1247 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_TX
, ISOC_PACKETS_B
,
1248 tx_iso_complete
, 1);
1249 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_TX
, ISOC_PACKETS_B
,
1250 tx_iso_complete
, 1);
1252 handle_led(hfc
, LED_POWER_ON
);
1257 /* initial callback for each plugged USB device */
1259 hfc_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1261 struct usb_device
*dev
= interface_to_usbdev(intf
);
1262 hfcusb_data
*context
;
1263 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1264 struct usb_host_interface
*iface_used
= NULL
;
1265 struct usb_host_endpoint
*ep
;
1266 int ifnum
= iface
->desc
.bInterfaceNumber
;
1267 int i
, idx
, alt_idx
, probe_alt_setting
, vend_idx
, cfg_used
, *vcf
,
1268 attr
, cfg_found
, cidx
, ep_addr
;
1269 int cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1271 hfcsusb_vdata
*driver_info
;
1274 for (i
= 0; hfcusb_idtab
[i
].idVendor
; i
++) {
1275 if ((le16_to_cpu(dev
->descriptor
.idVendor
) == hfcusb_idtab
[i
].idVendor
)
1276 && (le16_to_cpu(dev
->descriptor
.idProduct
) == hfcusb_idtab
[i
].idProduct
)) {
1283 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1284 ifnum
, iface
->desc
.bAlternateSetting
, intf
->minor
);
1286 if (vend_idx
!= 0xffff) {
1287 /* if vendor and product ID is OK, start probing alternate settings */
1289 small_match
= 0xffff;
1291 /* default settings */
1292 iso_packet_size
= 16;
1295 while (alt_idx
< intf
->num_altsetting
) {
1296 iface
= intf
->altsetting
+ alt_idx
;
1297 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1300 /* check for config EOL element */
1301 while (validconf
[cfg_used
][0]) {
1303 vcf
= validconf
[cfg_used
];
1304 /* first endpoint descriptor */
1305 ep
= iface
->endpoint
;
1307 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1309 /* check for all endpoints in this alternate setting */
1310 for (i
= 0; i
< iface
->desc
.bNumEndpoints
;
1313 ep
->desc
.bEndpointAddress
;
1314 /* get endpoint base */
1315 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1318 attr
= ep
->desc
.bmAttributes
;
1319 if (cmptbl
[idx
] == EP_NUL
) {
1322 if (attr
== USB_ENDPOINT_XFER_INT
1323 && cmptbl
[idx
] == EP_INT
)
1324 cmptbl
[idx
] = EP_NUL
;
1325 if (attr
== USB_ENDPOINT_XFER_BULK
1326 && cmptbl
[idx
] == EP_BLK
)
1327 cmptbl
[idx
] = EP_NUL
;
1328 if (attr
== USB_ENDPOINT_XFER_ISOC
1329 && cmptbl
[idx
] == EP_ISO
)
1330 cmptbl
[idx
] = EP_NUL
;
1332 /* check if all INT endpoints match minimum interval */
1333 if ((attr
== USB_ENDPOINT_XFER_INT
)
1334 && (ep
->desc
.bInterval
< vcf
[17])) {
1339 for (i
= 0; i
< 16; i
++) {
1340 /* all entries must be EP_NOP or EP_NUL for a valid config */
1341 if (cmptbl
[i
] != EP_NOP
1342 && cmptbl
[i
] != EP_NUL
)
1346 if (cfg_used
< small_match
) {
1347 small_match
= cfg_used
;
1356 } /* (alt_idx < intf->num_altsetting) */
1358 /* found a valid USB Ta Endpint config */
1359 if (small_match
!= 0xffff) {
1361 if (!(context
= kzalloc(sizeof(hfcusb_data
), GFP_KERNEL
)))
1362 return (-ENOMEM
); /* got no mem */
1364 ep
= iface
->endpoint
;
1365 vcf
= validconf
[small_match
];
1367 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1368 ep_addr
= ep
->desc
.bEndpointAddress
;
1369 /* get endpoint base */
1370 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1374 attr
= ep
->desc
.bmAttributes
;
1376 /* init Endpoints */
1377 if (vcf
[idx
] != EP_NOP
1378 && vcf
[idx
] != EP_NUL
) {
1380 case USB_ENDPOINT_XFER_INT
:
1393 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1395 case USB_ENDPOINT_XFER_BULK
:
1421 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1423 case USB_ENDPOINT_XFER_ISOC
:
1449 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1455 } /* switch attribute */
1457 if (context
->fifos
[cidx
].pipe
) {
1458 context
->fifos
[cidx
].
1460 context
->fifos
[cidx
].hfc
=
1462 context
->fifos
[cidx
].usb_packet_maxlen
=
1463 le16_to_cpu(ep
->desc
.wMaxPacketSize
);
1464 context
->fifos
[cidx
].
1467 context
->fifos
[cidx
].
1473 context
->dev
= dev
; /* save device */
1474 context
->if_used
= ifnum
; /* save used interface */
1475 context
->alt_used
= alt_used
; /* and alternate config */
1476 context
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
1477 context
->cfg_used
= vcf
[16]; /* store used config */
1478 context
->vend_idx
= vend_idx
; /* store found vendor */
1479 context
->packet_size
= packet_size
;
1480 context
->iso_packet_size
= iso_packet_size
;
1482 /* create the control pipes needed for register access */
1483 context
->ctrl_in_pipe
=
1484 usb_rcvctrlpipe(context
->dev
, 0);
1485 context
->ctrl_out_pipe
=
1486 usb_sndctrlpipe(context
->dev
, 0);
1487 context
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1490 (hfcsusb_vdata
*) hfcusb_idtab
[vend_idx
].
1492 printk(KERN_INFO
"HFC-S USB: detected \"%s\"\n",
1493 driver_info
->vend_name
);
1495 DBG(HFCUSB_DBG_INIT
,
1496 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d), E-Channel(%d)",
1497 conf_str
[small_match
], context
->if_used
,
1499 validconf
[small_match
][18]);
1501 /* init the chip and register the driver */
1502 if (hfc_usb_init(context
)) {
1503 usb_kill_urb(context
->ctrl_urb
);
1504 usb_free_urb(context
->ctrl_urb
);
1505 context
->ctrl_urb
= NULL
;
1509 usb_set_intfdata(intf
, context
);
1514 "HFC-S USB: no valid vendor found in USB descriptor\n");
1519 /* callback for unplugged USB device */
1521 hfc_usb_disconnect(struct usb_interface
*intf
)
1523 hfcusb_data
*context
= usb_get_intfdata(intf
);
1526 handle_led(context
, LED_POWER_OFF
);
1527 schedule_timeout(HZ
/ 100);
1529 printk(KERN_INFO
"HFC-S USB: device disconnect\n");
1530 context
->disc_flag
= 1;
1531 usb_set_intfdata(intf
, NULL
);
1533 if (timer_pending(&context
->t3_timer
))
1534 del_timer(&context
->t3_timer
);
1535 if (timer_pending(&context
->t4_timer
))
1536 del_timer(&context
->t4_timer
);
1538 /* tell all fifos to terminate */
1539 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1540 if (context
->fifos
[i
].usb_transfer_mode
== USB_ISOC
) {
1541 if (context
->fifos
[i
].active
> 0) {
1542 stop_isoc_chain(&context
->fifos
[i
]);
1543 DBG(HFCUSB_DBG_INIT
,
1544 "HFC-S USB: %s stopping ISOC chain Fifo(%i)",
1548 if (context
->fifos
[i
].active
> 0) {
1549 context
->fifos
[i
].active
= 0;
1550 DBG(HFCUSB_DBG_INIT
,
1551 "HFC-S USB: %s unlinking URB for Fifo(%i)",
1554 usb_kill_urb(context
->fifos
[i
].urb
);
1555 usb_free_urb(context
->fifos
[i
].urb
);
1556 context
->fifos
[i
].urb
= NULL
;
1558 context
->fifos
[i
].active
= 0;
1560 usb_kill_urb(context
->ctrl_urb
);
1561 usb_free_urb(context
->ctrl_urb
);
1562 context
->ctrl_urb
= NULL
;
1563 hisax_unregister(&context
->d_if
);
1564 kfree(context
); /* free our structure again */
1567 static struct usb_driver hfc_drv
= {
1569 .id_table
= hfcusb_idtab
,
1570 .probe
= hfc_usb_probe
,
1571 .disconnect
= hfc_usb_disconnect
,
1575 hfc_usb_mod_exit(void)
1577 usb_deregister(&hfc_drv
); /* release our driver */
1578 printk(KERN_INFO
"HFC-S USB: module removed\n");
1582 hfc_usb_mod_init(void)
1584 char revstr
[30], datestr
[30], dummy
[30];
1585 #ifndef CONFIG_HISAX_DEBUG
1588 sscanf(hfcusb_revision
,
1589 "%s %s $ %s %s %s $ ", dummy
, revstr
,
1590 dummy
, datestr
, dummy
);
1592 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1593 revstr
, datestr
, debug
);
1594 if (usb_register(&hfc_drv
)) {
1596 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1597 return (-1); /* unable to register */
1602 module_init(hfc_usb_mod_init
);
1603 module_exit(hfc_usb_mod_exit
);
1604 MODULE_AUTHOR(DRIVER_AUTHOR
);
1605 MODULE_DESCRIPTION(DRIVER_DESC
);
1606 MODULE_LICENSE("GPL");
1607 MODULE_DEVICE_TABLE(usb
, hfcusb_idtab
);