4 * $Id: hfc_usb.c,v 4.36 2005/04/08 09:55:13 martinb1 Exp $
6 * modular HiSax ISDN driver for Colognechip HFC-S USB chip
8 * Authors : Peter Sprenger (sprenger@moving-bytes.de)
9 * Martin Bachem (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/config.h>
36 #include <linux/init.h>
37 #include <linux/module.h>
38 #include <linux/kernel_stat.h>
39 #include <linux/usb.h>
40 #include <linux/kernel.h>
41 #include <linux/smp_lock.h>
42 #include <linux/sched.h>
47 static const char *hfcusb_revision
=
48 "$Revision: 4.36 $ $Date: 2005/04/08 09:55:13 $ ";
50 /* Hisax debug support
51 * use "modprobe debug=x" where x is bitfield of USB_DBG & ISDN_DBG
53 #ifdef CONFIG_HISAX_DEBUG
54 #include <linux/moduleparam.h>
55 #define __debug_variable hfc_debug
56 #include "hisax_debug.h"
58 module_param(debug
, uint
, 0);
62 /* private vendor specific data */
64 __u8 led_scheme
; // led display scheme
65 signed short led_bits
[8]; // array of 8 possible LED bitmask settings
66 char *vend_name
; // device name
69 /****************************************/
70 /* data defining the devices to be used */
71 /****************************************/
72 static struct usb_device_id hfcusb_idtab
[] = {
76 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
77 {LED_OFF
, {4, 0, 2, 1},
78 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
83 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
84 {LED_SCHEME1
, {1, 2, 0, 0},
85 "DrayTek miniVigor 128 USB ISDN TA"}),
90 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
91 {LED_SCHEME1
, {0x80, -64, -32, -16},
92 "Billion tiny USB ISDN TA 128"}),
97 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
98 {LED_SCHEME1
, {4, 0, 2, 1},
104 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
105 {LED_SCHEME1
, {4, 0, 2, 1},
106 "Aceex USB ISDN TA"}),
111 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
112 {LED_SCHEME1
, {4, 0, 2, 1},
118 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
119 {LED_SCHEME1
, {2, 0, 1, 4},
125 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
126 {LED_SCHEME1
, {0x80, -64, -32, -16},
127 "Bewan Modem RNIS USB"}),
132 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
133 {LED_SCHEME1
, {0x80, -64, -32, -16},
134 "Djinn Numeris USB"}),
139 .driver_info
= (unsigned long) &((hfcsusb_vdata
)
140 {LED_SCHEME1
, {0x80, -64, -32, -16},
146 /***************************************************************/
147 /* structure defining input+output fifos (interrupt/bulk mode) */
148 /***************************************************************/
149 struct usb_fifo
; /* forward definition */
150 typedef struct iso_urb_struct
{
152 __u8 buffer
[ISO_BUFFER_SIZE
]; /* buffer incoming/outgoing data */
153 struct usb_fifo
*owner_fifo
; /* pointer to owner fifo */
157 struct hfcusb_data
; /* forward definition */
158 typedef struct usb_fifo
{
159 int fifonum
; /* fifo index attached to this structure */
160 int active
; /* fifo is currently active */
161 struct hfcusb_data
*hfc
; /* pointer to main structure */
162 int pipe
; /* address of endpoint */
163 __u8 usb_packet_maxlen
; /* maximum length for usb transfer */
164 unsigned int max_size
; /* maximum size of receive/send packet */
165 __u8 intervall
; /* interrupt interval */
166 struct sk_buff
*skbuff
; /* actual used buffer */
167 struct urb
*urb
; /* transfer structure for usb routines */
168 __u8 buffer
[128]; /* buffer incoming/outgoing data */
169 int bit_line
; /* how much bits are in the fifo? */
171 volatile __u8 usb_transfer_mode
; /* switched between ISO and INT */
172 iso_urb_struct iso
[2]; /* need two urbs to have one always for pending */
173 struct hisax_if
*hif
; /* hisax interface */
174 int delete_flg
; /* only delete skbuff once */
175 int last_urblen
; /* remember length of last packet */
179 /*********************************************/
180 /* structure holding all data for one device */
181 /*********************************************/
182 typedef struct hfcusb_data
{
183 /* HiSax Interface for loadable Layer1 drivers */
184 struct hisax_d_if d_if
; /* see hisax_if.h */
185 struct hisax_b_if b_if
[2]; /* see hisax_if.h */
188 struct usb_device
*dev
; /* our device */
189 int if_used
; /* used interface number */
190 int alt_used
; /* used alternate config */
191 int ctrl_paksize
; /* control pipe packet size */
192 int ctrl_in_pipe
, ctrl_out_pipe
; /* handles for control pipe */
193 int cfg_used
; /* configuration index used */
194 int vend_idx
; /* vendor found */
195 int b_mode
[2]; /* B-channel mode */
196 int l1_activated
; /* layer 1 activated */
197 int disc_flag
; /* TRUE if device was disonnected to avoid some USB actions */
198 int packet_size
, iso_packet_size
;
200 /* control pipe background handling */
201 ctrl_buft ctrl_buff
[HFC_CTRL_BUFSIZE
]; /* buffer holding queued data */
202 volatile int ctrl_in_idx
, ctrl_out_idx
, ctrl_cnt
; /* input/output pointer + count */
203 struct urb
*ctrl_urb
; /* transfer structure for control channel */
205 struct usb_ctrlrequest ctrl_write
; /* buffer for control write request */
206 struct usb_ctrlrequest ctrl_read
; /* same for read request */
208 __u8 old_led_state
, led_state
, led_new_data
, led_b_active
;
210 volatile __u8 threshold_mask
; /* threshold actually reported */
211 volatile __u8 bch_enables
; /* or mask for sctrl_r and sctrl register values */
213 usb_fifo fifos
[HFCUSB_NUM_FIFOS
]; /* structure holding all fifo data */
215 volatile __u8 l1_state
; /* actual l1 state */
216 struct timer_list t3_timer
; /* timer 3 for activation/deactivation */
217 struct timer_list t4_timer
; /* timer 4 for activation/deactivation */
221 static void collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
,
225 static inline const char *
226 symbolic(struct hfcusb_symbolic_list list
[], const int num
)
229 for (i
= 0; list
[i
].name
!= NULL
; i
++)
230 if (list
[i
].num
== num
)
231 return (list
[i
].name
);
232 return "<unkown ERROR>";
236 /******************************************************/
237 /* start next background transfer for control channel */
238 /******************************************************/
240 ctrl_start_transfer(hfcusb_data
* hfc
)
243 hfc
->ctrl_urb
->pipe
= hfc
->ctrl_out_pipe
;
244 hfc
->ctrl_urb
->setup_packet
= (u_char
*) & hfc
->ctrl_write
;
245 hfc
->ctrl_urb
->transfer_buffer
= NULL
;
246 hfc
->ctrl_urb
->transfer_buffer_length
= 0;
247 hfc
->ctrl_write
.wIndex
=
248 hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].hfc_reg
;
249 hfc
->ctrl_write
.wValue
=
250 hfc
->ctrl_buff
[hfc
->ctrl_out_idx
].reg_val
;
252 usb_submit_urb(hfc
->ctrl_urb
, GFP_ATOMIC
); /* start transfer */
254 } /* ctrl_start_transfer */
256 /************************************/
257 /* queue a control transfer request */
258 /* return 0 on success. */
259 /************************************/
261 queue_control_request(hfcusb_data
* hfc
, __u8 reg
, __u8 val
, int action
)
265 if (hfc
->ctrl_cnt
>= HFC_CTRL_BUFSIZE
)
266 return (1); /* no space left */
267 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_in_idx
]; /* pointer to new index */
270 buf
->action
= action
;
271 if (++hfc
->ctrl_in_idx
>= HFC_CTRL_BUFSIZE
)
272 hfc
->ctrl_in_idx
= 0; /* pointer wrap */
273 if (++hfc
->ctrl_cnt
== 1)
274 ctrl_start_transfer(hfc
);
276 } /* queue_control_request */
279 control_action_handler(hfcusb_data
* hfc
, int reg
, int val
, int action
)
282 return (1); /* no action defined */
286 /***************************************************************/
287 /* control completion routine handling background control cmds */
288 /***************************************************************/
290 ctrl_complete(struct urb
*urb
, struct pt_regs
*regs
)
292 hfcusb_data
*hfc
= (hfcusb_data
*) urb
->context
;
297 buf
= &hfc
->ctrl_buff
[hfc
->ctrl_out_idx
];
298 control_action_handler(hfc
, buf
->hfc_reg
, buf
->reg_val
,
301 hfc
->ctrl_cnt
--; /* decrement actual count */
302 if (++hfc
->ctrl_out_idx
>= HFC_CTRL_BUFSIZE
)
303 hfc
->ctrl_out_idx
= 0; /* pointer wrap */
305 ctrl_start_transfer(hfc
); /* start next transfer */
307 } /* ctrl_complete */
309 /***************************************************/
310 /* write led data to auxport & invert if necessary */
311 /***************************************************/
313 write_led(hfcusb_data
* hfc
, __u8 led_state
)
315 if (led_state
!= hfc
->old_led_state
) {
316 hfc
->old_led_state
= led_state
;
317 queue_control_request(hfc
, HFCUSB_P_DATA
, led_state
, 1);
321 /**************************/
322 /* handle LED bits */
323 /**************************/
325 set_led_bit(hfcusb_data
* hfc
, signed short led_bits
, int unset
)
329 hfc
->led_state
|= abs(led_bits
);
331 hfc
->led_state
&= ~led_bits
;
334 hfc
->led_state
&= ~abs(led_bits
);
336 hfc
->led_state
|= led_bits
;
340 /**************************/
341 /* handle LED requests */
342 /**************************/
344 handle_led(hfcusb_data
* hfc
, int event
)
346 hfcsusb_vdata
*driver_info
=
347 (hfcsusb_vdata
*) hfcusb_idtab
[hfc
->vend_idx
].driver_info
;
349 /* if no scheme -> no LED action */
350 if (driver_info
->led_scheme
== LED_OFF
)
355 set_led_bit(hfc
, driver_info
->led_bits
[0],
357 set_led_bit(hfc
, driver_info
->led_bits
[1],
359 set_led_bit(hfc
, driver_info
->led_bits
[2],
361 set_led_bit(hfc
, driver_info
->led_bits
[3],
364 case LED_POWER_OFF
: /* no Power off handling */
367 set_led_bit(hfc
, driver_info
->led_bits
[1],
371 set_led_bit(hfc
, driver_info
->led_bits
[1],
375 set_led_bit(hfc
, driver_info
->led_bits
[2],
379 set_led_bit(hfc
, driver_info
->led_bits
[2],
383 set_led_bit(hfc
, driver_info
->led_bits
[3],
387 set_led_bit(hfc
, driver_info
->led_bits
[3],
391 write_led(hfc
, hfc
->led_state
);
394 /********************************/
395 /* called when timer t3 expires */
396 /********************************/
398 l1_timer_expire_t3(hfcusb_data
* hfc
)
400 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
402 #ifdef CONFIG_HISAX_DEBUG
404 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
406 hfc
->l1_activated
= FALSE
;
407 handle_led(hfc
, LED_S0_OFF
);
409 queue_control_request(hfc
, HFCUSB_STATES
, 0x10, 1);
410 queue_control_request(hfc
, HFCUSB_STATES
, 3, 1);
413 /********************************/
414 /* called when timer t4 expires */
415 /********************************/
417 l1_timer_expire_t4(hfcusb_data
* hfc
)
419 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
, PH_DEACTIVATE
| INDICATION
,
421 #ifdef CONFIG_HISAX_DEBUG
423 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
425 hfc
->l1_activated
= FALSE
;
426 handle_led(hfc
, LED_S0_OFF
);
429 /*****************************/
430 /* handle S0 state changes */
431 /*****************************/
433 state_handler(hfcusb_data
* hfc
, __u8 state
)
437 old_state
= hfc
->l1_state
;
438 if (state
== old_state
|| state
< 1 || state
> 8)
441 #ifdef CONFIG_HISAX_DEBUG
442 DBG(ISDN_DBG
, "HFC-S USB: new S0 state:%d old_state:%d", state
,
445 if (state
< 4 || state
== 7 || state
== 8) {
446 if (timer_pending(&hfc
->t3_timer
))
447 del_timer(&hfc
->t3_timer
);
448 #ifdef CONFIG_HISAX_DEBUG
449 DBG(ISDN_DBG
, "HFC-S USB: T3 deactivated");
453 if (timer_pending(&hfc
->t4_timer
))
454 del_timer(&hfc
->t4_timer
);
455 #ifdef CONFIG_HISAX_DEBUG
456 DBG(ISDN_DBG
, "HFC-S USB: T4 deactivated");
460 if (state
== 7 && !hfc
->l1_activated
) {
461 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
462 PH_ACTIVATE
| INDICATION
, NULL
);
463 #ifdef CONFIG_HISAX_DEBUG
464 DBG(ISDN_DBG
, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
466 hfc
->l1_activated
= TRUE
;
467 handle_led(hfc
, LED_S0_ON
);
468 } else if (state
<= 3 /* && activated */ ) {
469 if (old_state
== 7 || old_state
== 8) {
470 #ifdef CONFIG_HISAX_DEBUG
471 DBG(ISDN_DBG
, "HFC-S USB: T4 activated");
473 if (!timer_pending(&hfc
->t4_timer
)) {
474 hfc
->t4_timer
.expires
=
475 jiffies
+ (HFC_TIMER_T4
* HZ
) / 1000;
476 add_timer(&hfc
->t4_timer
);
479 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
480 PH_DEACTIVATE
| INDICATION
,
482 #ifdef CONFIG_HISAX_DEBUG
484 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
486 hfc
->l1_activated
= FALSE
;
487 handle_led(hfc
, LED_S0_OFF
);
490 hfc
->l1_state
= state
;
493 /* prepare iso urb */
495 fill_isoc_urb(struct urb
*urb
, struct usb_device
*dev
, unsigned int pipe
,
496 void *buf
, int num_packets
, int packet_size
, int interval
,
497 usb_complete_t complete
, void *context
)
501 spin_lock_init(&urb
->lock
);
504 urb
->complete
= complete
;
505 urb
->number_of_packets
= num_packets
;
506 urb
->transfer_buffer_length
= packet_size
* num_packets
;
507 urb
->context
= context
;
508 urb
->transfer_buffer
= buf
;
509 urb
->transfer_flags
= URB_ISO_ASAP
;
510 urb
->actual_length
= 0;
511 urb
->interval
= interval
;
512 for (k
= 0; k
< num_packets
; k
++) {
513 urb
->iso_frame_desc
[k
].offset
= packet_size
* k
;
514 urb
->iso_frame_desc
[k
].length
= packet_size
;
515 urb
->iso_frame_desc
[k
].actual_length
= 0;
519 /* allocs urbs and start isoc transfer with two pending urbs to avoid
520 gaps in the transfer chain */
522 start_isoc_chain(usb_fifo
* fifo
, int num_packets_per_urb
,
523 usb_complete_t complete
, int packet_size
)
527 printk(KERN_INFO
"HFC-S USB: starting ISO-chain for Fifo %i\n",
530 /* allocate Memory for Iso out Urbs */
531 for (i
= 0; i
< 2; i
++) {
532 if (!(fifo
->iso
[i
].purb
)) {
534 usb_alloc_urb(num_packets_per_urb
, GFP_KERNEL
);
535 if (!(fifo
->iso
[i
].purb
)) {
537 "alloc urb for fifo %i failed!!!",
540 fifo
->iso
[i
].owner_fifo
= (struct usb_fifo
*) fifo
;
542 /* Init the first iso */
543 if (ISO_BUFFER_SIZE
>=
544 (fifo
->usb_packet_maxlen
*
545 num_packets_per_urb
)) {
546 fill_isoc_urb(fifo
->iso
[i
].purb
,
547 fifo
->hfc
->dev
, fifo
->pipe
,
550 fifo
->usb_packet_maxlen
,
551 fifo
->intervall
, complete
,
553 memset(fifo
->iso
[i
].buffer
, 0,
554 sizeof(fifo
->iso
[i
].buffer
));
555 /* defining packet delimeters in fifo->buffer */
556 for (k
= 0; k
< num_packets_per_urb
; k
++) {
558 iso_frame_desc
[k
].offset
=
561 iso_frame_desc
[k
].length
=
566 "HFC-S USB: ISO Buffer size to small!\n");
569 fifo
->bit_line
= BITLINE_INF
;
571 errcode
= usb_submit_urb(fifo
->iso
[i
].purb
, GFP_KERNEL
);
572 fifo
->active
= (errcode
>= 0) ? 1 : 0;
574 printk(KERN_INFO
"HFC-S USB: %s URB nr:%d\n",
575 symbolic(urb_errlist
, errcode
), i
);
578 return (fifo
->active
);
581 /* stops running iso chain and frees their pending urbs */
583 stop_isoc_chain(usb_fifo
* fifo
)
587 for (i
= 0; i
< 2; i
++) {
588 if (fifo
->iso
[i
].purb
) {
589 #ifdef CONFIG_HISAX_DEBUG
591 "HFC-S USB: Stopping iso chain for fifo %i.%i",
594 usb_unlink_urb(fifo
->iso
[i
].purb
);
595 usb_free_urb(fifo
->iso
[i
].purb
);
596 fifo
->iso
[i
].purb
= NULL
;
600 usb_unlink_urb(fifo
->urb
);
601 usb_free_urb(fifo
->urb
);
607 /* defines how much ISO packets are handled in one URB */
608 static int iso_packets
[8] =
609 { ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
, ISOC_PACKETS_B
,
610 ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
, ISOC_PACKETS_D
613 /*****************************************************/
614 /* transmit completion routine for all ISO tx fifos */
615 /*****************************************************/
617 tx_iso_complete(struct urb
*urb
, struct pt_regs
*regs
)
619 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
620 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
621 hfcusb_data
*hfc
= fifo
->hfc
;
622 int k
, tx_offset
, num_isoc_packets
, sink
, len
, current_len
,
624 int frame_complete
, transp_mode
, fifon
, status
;
626 __u8 threshtable
[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
628 fifon
= fifo
->fifonum
;
629 status
= urb
->status
;
633 if (fifo
->active
&& !status
) {
635 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
638 /* is FifoFull-threshold set for our channel? */
639 threshbit
= threshtable
[fifon
] & hfc
->threshold_mask
;
640 num_isoc_packets
= iso_packets
[fifon
];
642 /* predict dataflow to avoid fifo overflow */
643 if (fifon
>= HFCUSB_D_TX
) {
644 sink
= (threshbit
) ? SINK_DMIN
: SINK_DMAX
;
646 sink
= (threshbit
) ? SINK_MIN
: SINK_MAX
;
648 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
649 context_iso_urb
->buffer
, num_isoc_packets
,
650 fifo
->usb_packet_maxlen
, fifo
->intervall
,
651 tx_iso_complete
, urb
->context
);
652 memset(context_iso_urb
->buffer
, 0,
653 sizeof(context_iso_urb
->buffer
));
654 frame_complete
= FALSE
;
655 /* Generate next Iso Packets */
656 for (k
= 0; k
< num_isoc_packets
; ++k
) {
658 len
= fifo
->skbuff
->len
;
659 /* we lower data margin every msec */
660 fifo
->bit_line
-= sink
;
661 current_len
= (0 - fifo
->bit_line
) / 8;
662 /* maximum 15 byte for every ISO packet makes our life easier */
663 if (current_len
> 14)
667 current_len
) ? len
: current_len
;
668 /* how much bit do we put on the line? */
669 fifo
->bit_line
+= current_len
* 8;
671 context_iso_urb
->buffer
[tx_offset
] = 0;
672 if (current_len
== len
) {
674 /* here frame completion */
676 buffer
[tx_offset
] = 1;
677 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
678 fifo
->bit_line
+= 32;
680 frame_complete
= TRUE
;
683 memcpy(context_iso_urb
->buffer
+
684 tx_offset
+ 1, fifo
->skbuff
->data
,
686 skb_pull(fifo
->skbuff
, current_len
);
688 /* define packet delimeters within the URB buffer */
689 urb
->iso_frame_desc
[k
].offset
= tx_offset
;
690 urb
->iso_frame_desc
[k
].length
=
693 tx_offset
+= (current_len
+ 1);
695 urb
->iso_frame_desc
[k
].offset
=
698 urb
->iso_frame_desc
[k
].length
= 1;
699 fifo
->bit_line
-= sink
; /* we lower data margin every msec */
701 if (fifo
->bit_line
< BITLINE_INF
) {
702 fifo
->bit_line
= BITLINE_INF
;
706 if (frame_complete
) {
707 fifo
->delete_flg
= TRUE
;
708 fifo
->hif
->l1l2(fifo
->hif
,
710 (void *) fifo
->skbuff
->
712 if (fifo
->skbuff
&& fifo
->delete_flg
) {
713 dev_kfree_skb_any(fifo
->skbuff
);
715 fifo
->delete_flg
= FALSE
;
717 frame_complete
= FALSE
;
720 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
723 "HFC-S USB: error submitting ISO URB: %d \n",
727 if (status
&& !hfc
->disc_flag
) {
729 "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
730 symbolic(urb_errlist
, status
), status
,
734 } /* tx_iso_complete */
736 /*****************************************************/
737 /* receive completion routine for all ISO tx fifos */
738 /*****************************************************/
740 rx_iso_complete(struct urb
*urb
, struct pt_regs
*regs
)
742 iso_urb_struct
*context_iso_urb
= (iso_urb_struct
*) urb
->context
;
743 usb_fifo
*fifo
= context_iso_urb
->owner_fifo
;
744 hfcusb_data
*hfc
= fifo
->hfc
;
745 int k
, len
, errcode
, offset
, num_isoc_packets
, fifon
, maxlen
,
747 unsigned int iso_status
;
750 #ifdef CONFIG_HISAX_DEBUG
754 fifon
= fifo
->fifonum
;
755 status
= urb
->status
;
757 if (urb
->status
== -EOVERFLOW
) {
758 #ifdef CONFIG_HISAX_DEBUG
760 "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
765 if (fifo
->active
&& !status
) {
766 num_isoc_packets
= iso_packets
[fifon
];
767 maxlen
= fifo
->usb_packet_maxlen
;
768 for (k
= 0; k
< num_isoc_packets
; ++k
) {
769 len
= urb
->iso_frame_desc
[k
].actual_length
;
770 offset
= urb
->iso_frame_desc
[k
].offset
;
771 buf
= context_iso_urb
->buffer
+ offset
;
772 iso_status
= urb
->iso_frame_desc
[k
].status
;
773 #ifdef CONFIG_HISAX_DEBUG
774 if (iso_status
&& !hfc
->disc_flag
)
776 "HFC-S USB: ISO packet failure - status:%x",
779 if ((fifon
== 5) && (debug
> 1)) {
781 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
782 "act_urblen:%2d max-urblen:%2d "
784 fifo
->last_urblen
, len
, maxlen
,
786 for (i
= 0; i
< len
; i
++)
787 printk("%.2x ", buf
[i
]);
791 if (fifo
->last_urblen
!= maxlen
) {
792 /* the threshold mask is in the 2nd status byte */
793 hfc
->threshold_mask
= buf
[1];
794 /* care for L1 state only for D-Channel
795 to avoid overlapped iso completions */
797 /* the S0 state is in the upper half
798 of the 1st status byte */
799 state_handler(hfc
, buf
[0] >> 4);
801 eof
[fifon
] = buf
[0] & 1;
803 collect_rx_frame(fifo
, buf
+ 2,
809 collect_rx_frame(fifo
, buf
, len
,
811 maxlen
) ? eof
[fifon
] :
814 fifo
->last_urblen
= len
;
817 fill_isoc_urb(urb
, fifo
->hfc
->dev
, fifo
->pipe
,
818 context_iso_urb
->buffer
, num_isoc_packets
,
819 fifo
->usb_packet_maxlen
, fifo
->intervall
,
820 rx_iso_complete
, urb
->context
);
821 errcode
= usb_submit_urb(urb
, GFP_ATOMIC
);
824 "HFC-S USB: error submitting ISO URB: %d \n",
828 if (status
&& !hfc
->disc_flag
) {
830 "HFC-S USB: rx_iso_complete : "
831 "urb->status %d, fifonum %d\n",
835 } /* rx_iso_complete */
837 /*****************************************************/
838 /* collect data from interrupt or isochron in */
839 /*****************************************************/
841 collect_rx_frame(usb_fifo
* fifo
, __u8
* data
, int len
, int finish
)
843 hfcusb_data
*hfc
= fifo
->hfc
;
844 int transp_mode
, fifon
;
845 #ifdef CONFIG_HISAX_DEBUG
848 fifon
= fifo
->fifonum
;
850 if (fifon
< 4 && hfc
->b_mode
[fifon
/ 2] == L1_MODE_TRANS
)
854 fifo
->skbuff
= dev_alloc_skb(fifo
->max_size
+ 3);
857 "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
863 if (fifo
->skbuff
->len
+ len
< fifo
->max_size
) {
864 memcpy(skb_put(fifo
->skbuff
, len
), data
, len
);
866 #ifdef CONFIG_HISAX_DEBUG
867 printk(KERN_INFO
"HFC-S USB: ");
868 for (i
= 0; i
< 15; i
++)
870 fifo
->skbuff
->data
[fifo
->skbuff
->
875 "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
876 fifo
->max_size
, fifon
);
879 if (transp_mode
&& fifo
->skbuff
->len
>= 128) {
880 fifo
->hif
->l1l2(fifo
->hif
, PH_DATA
| INDICATION
,
885 /* we have a complete hdlc packet */
887 if ((!fifo
->skbuff
->data
[fifo
->skbuff
->len
- 1])
888 && (fifo
->skbuff
->len
> 3)) {
889 /* remove CRC & status */
890 skb_trim(fifo
->skbuff
, fifo
->skbuff
->len
- 3);
891 if (fifon
== HFCUSB_PCM_RX
) {
892 fifo
->hif
->l1l2(fifo
->hif
,
893 PH_DATA_E
| INDICATION
,
896 fifo
->hif
->l1l2(fifo
->hif
,
897 PH_DATA
| INDICATION
,
899 fifo
->skbuff
= NULL
; /* buffer was freed from upper layer */
901 if (fifo
->skbuff
->len
> 3) {
903 "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
904 fifo
->skbuff
->len
, fifon
);
905 #ifdef CONFIG_HISAX_DEBUG
907 printk(KERN_INFO
"HFC-S USB: ");
908 for (i
= 0; i
< 15; i
++)
917 #ifdef CONFIG_HISAX_DEBUG
920 "HFC-S USB: frame to small (%d bytes)!!!\n",
924 skb_trim(fifo
->skbuff
, 0);
929 /***********************************************/
930 /* receive completion routine for all rx fifos */
931 /***********************************************/
933 rx_complete(struct urb
*urb
, struct pt_regs
*regs
)
937 __u8
*buf
, maxlen
, fifon
;
938 usb_fifo
*fifo
= (usb_fifo
*) urb
->context
;
939 hfcusb_data
*hfc
= fifo
->hfc
;
941 #ifdef CONFIG_HISAX_DEBUG
945 urb
->dev
= hfc
->dev
; /* security init */
947 fifon
= fifo
->fifonum
;
948 if ((!fifo
->active
) || (urb
->status
)) {
949 #ifdef CONFIG_HISAX_DEBUG
950 DBG(USB_DBG
, "HFC-S USB: RX-Fifo %i is going down (%i)",
953 fifo
->urb
->interval
= 0; /* cancel automatic rescheduling */
955 dev_kfree_skb_any(fifo
->skbuff
);
960 len
= urb
->actual_length
;
962 maxlen
= fifo
->usb_packet_maxlen
;
964 #ifdef CONFIG_HISAX_DEBUG
965 if ((fifon
== 5) && (debug
> 1)) {
967 "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
968 fifo
->last_urblen
, len
, maxlen
, eof
[5]);
969 for (i
= 0; i
< len
; i
++)
970 printk("%.2x ", buf
[i
]);
975 if (fifo
->last_urblen
!= fifo
->usb_packet_maxlen
) {
976 /* the threshold mask is in the 2nd status byte */
977 hfc
->threshold_mask
= buf
[1];
978 /* the S0 state is in the upper half of the 1st status byte */
979 state_handler(hfc
, buf
[0] >> 4);
980 eof
[fifon
] = buf
[0] & 1;
981 /* if we have more than the 2 status bytes -> collect data */
983 collect_rx_frame(fifo
, buf
+ 2,
984 urb
->actual_length
- 2,
985 (len
< maxlen
) ? eof
[fifon
] : 0);
987 collect_rx_frame(fifo
, buf
, urb
->actual_length
,
988 (len
< maxlen
) ? eof
[fifon
] : 0);
990 fifo
->last_urblen
= urb
->actual_length
;
991 status
= usb_submit_urb(urb
, GFP_ATOMIC
);
994 "HFC-S USB: error resubmitting URN at rx_complete...\n");
998 /***************************************************/
999 /* start the interrupt transfer for the given fifo */
1000 /***************************************************/
1002 start_int_fifo(usb_fifo
* fifo
)
1006 printk(KERN_INFO
"HFC-S USB: starting intr IN fifo:%d\n",
1010 fifo
->urb
= usb_alloc_urb(0, GFP_KERNEL
);
1014 usb_fill_int_urb(fifo
->urb
, fifo
->hfc
->dev
, fifo
->pipe
,
1015 fifo
->buffer
, fifo
->usb_packet_maxlen
,
1016 rx_complete
, fifo
, fifo
->intervall
);
1017 fifo
->active
= 1; /* must be marked active */
1018 errcode
= usb_submit_urb(fifo
->urb
, GFP_KERNEL
);
1021 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
1024 fifo
->skbuff
= NULL
;
1026 } /* start_int_fifo */
1028 /*****************************/
1029 /* set the B-channel mode */
1030 /*****************************/
1032 set_hfcmode(hfcusb_data
* hfc
, int channel
, int mode
)
1034 __u8 val
, idx_table
[2] = { 0, 2 };
1036 if (hfc
->disc_flag
) {
1039 #ifdef CONFIG_HISAX_DEBUG
1040 DBG(ISDN_DBG
, "HFC-S USB: setting channel %d to mode %d", channel
,
1043 hfc
->b_mode
[channel
] = mode
;
1045 /* setup CON_HDLC */
1047 if (mode
!= L1_MODE_NULL
)
1048 val
= 8; /* enable fifo? */
1049 if (mode
== L1_MODE_TRANS
)
1050 val
|= 2; /* set transparent bit */
1052 /* set FIFO to transmit register */
1053 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
], 1);
1054 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
1056 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
1057 /* set FIFO to receive register */
1058 queue_control_request(hfc
, HFCUSB_FIFO
, idx_table
[channel
] + 1, 1);
1059 queue_control_request(hfc
, HFCUSB_CON_HDLC
, val
, 1);
1061 queue_control_request(hfc
, HFCUSB_INC_RES_F
, 2, 1);
1068 queue_control_request(hfc
, HFCUSB_SCTRL
, val
, 1);
1075 queue_control_request(hfc
, HFCUSB_SCTRL_R
, val
, 1);
1077 if (mode
== L1_MODE_NULL
) {
1079 handle_led(hfc
, LED_B2_OFF
);
1081 handle_led(hfc
, LED_B1_OFF
);
1084 handle_led(hfc
, LED_B2_ON
);
1086 handle_led(hfc
, LED_B1_ON
);
1091 hfc_usb_l2l1(struct hisax_if
*my_hisax_if
, int pr
, void *arg
)
1093 usb_fifo
*fifo
= my_hisax_if
->priv
;
1094 hfcusb_data
*hfc
= fifo
->hfc
;
1097 case PH_ACTIVATE
| REQUEST
:
1098 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1099 #ifdef CONFIG_HISAX_DEBUG
1101 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1103 if (hfc
->l1_state
!= 3
1104 && hfc
->l1_state
!= 7) {
1105 hfc
->d_if
.ifc
.l1l2(&hfc
->d_if
.ifc
,
1109 #ifdef CONFIG_HISAX_DEBUG
1111 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1114 if (hfc
->l1_state
== 7) { /* l1 already active */
1115 hfc
->d_if
.ifc
.l1l2(&hfc
->
1122 #ifdef CONFIG_HISAX_DEBUG
1124 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1127 /* force sending sending INFO1 */
1128 queue_control_request(hfc
,
1133 /* start l1 activation */
1134 queue_control_request(hfc
,
1151 #ifdef CONFIG_HISAX_DEBUG
1153 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
1157 HFCUSB_B1_TX
) ? 0 : 1,
1159 fifo
->hif
->l1l2(fifo
->hif
,
1160 PH_ACTIVATE
| INDICATION
,
1164 case PH_DEACTIVATE
| REQUEST
:
1165 if (fifo
->fifonum
== HFCUSB_D_TX
) {
1166 #ifdef CONFIG_HISAX_DEBUG
1168 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1171 "HFC-S USB: ISDN TE device should not deativate...\n");
1173 #ifdef CONFIG_HISAX_DEBUG
1175 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1179 HFCUSB_B1_TX
) ? 0 : 1,
1180 (int) L1_MODE_NULL
);
1181 fifo
->hif
->l1l2(fifo
->hif
,
1182 PH_DEACTIVATE
| INDICATION
,
1186 case PH_DATA
| REQUEST
:
1187 if (fifo
->skbuff
&& fifo
->delete_flg
) {
1188 dev_kfree_skb_any(fifo
->skbuff
);
1189 fifo
->skbuff
= NULL
;
1190 fifo
->delete_flg
= FALSE
;
1192 fifo
->skbuff
= arg
; /* we have a new buffer */
1196 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
1202 /***************************************************************************/
1203 /* usb_init is called once when a new matching device is detected to setup */
1204 /* main parameters. It registers the driver at the main hisax module. */
1205 /* on success 0 is returned. */
1206 /***************************************************************************/
1208 usb_init(hfcusb_data
* hfc
)
1213 struct hisax_b_if
*p_b_if
[2];
1215 /* check the chip id */
1216 if (read_usb(hfc
, HFCUSB_CHIP_ID
, &b
) != 1) {
1217 printk(KERN_INFO
"HFC-USB: cannot read chip id\n");
1220 if (b
!= HFCUSB_CHIPID
) {
1221 printk(KERN_INFO
"HFC-S USB: Invalid chip id 0x%02x\n", b
);
1225 /* first set the needed config, interface and alternate */
1226 err
= usb_set_interface(hfc
->dev
, hfc
->if_used
, hfc
->alt_used
);
1229 write_usb(hfc
, HFCUSB_CIRM
, 8);
1230 /* aux = output, reset off */
1231 write_usb(hfc
, HFCUSB_CIRM
, 0x10);
1233 /* set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers */
1234 write_usb(hfc
, HFCUSB_USB_SIZE
,
1235 (hfc
->packet_size
/ 8) | ((hfc
->packet_size
/ 8) << 4));
1237 /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */
1238 write_usb(hfc
, HFCUSB_USB_SIZE_I
, hfc
->iso_packet_size
);
1240 /* enable PCM/GCI master mode */
1241 write_usb(hfc
, HFCUSB_MST_MODE1
, 0); /* set default values */
1242 write_usb(hfc
, HFCUSB_MST_MODE0
, 1); /* enable master mode */
1244 /* init the fifos */
1245 write_usb(hfc
, HFCUSB_F_THRES
,
1246 (HFCUSB_TX_THRESHOLD
/
1247 8) | ((HFCUSB_RX_THRESHOLD
/ 8) << 4));
1250 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1251 write_usb(hfc
, HFCUSB_FIFO
, i
); /* select the desired fifo */
1252 fifo
[i
].skbuff
= NULL
; /* init buffer pointer */
1254 (i
<= HFCUSB_B2_RX
) ? MAX_BCH_SIZE
: MAX_DFRAME_LEN
;
1255 fifo
[i
].last_urblen
= 0;
1256 /* set 2 bit for D- & E-channel */
1257 write_usb(hfc
, HFCUSB_HDLC_PAR
,
1258 ((i
<= HFCUSB_B2_RX
) ? 0 : 2));
1259 /* rx hdlc, enable IFF for D-channel */
1260 write_usb(hfc
, HFCUSB_CON_HDLC
,
1261 ((i
== HFCUSB_D_TX
) ? 0x09 : 0x08));
1262 write_usb(hfc
, HFCUSB_INC_RES_F
, 2); /* reset the fifo */
1265 write_usb(hfc
, HFCUSB_CLKDEL
, 0x0f); /* clock delay value */
1266 write_usb(hfc
, HFCUSB_STATES
, 3 | 0x10); /* set deactivated mode */
1267 write_usb(hfc
, HFCUSB_STATES
, 3); /* enable state machine */
1269 write_usb(hfc
, HFCUSB_SCTRL_R
, 0); /* disable both B receivers */
1270 write_usb(hfc
, HFCUSB_SCTRL
, 0x40); /* disable B transmitters + capacitive mode */
1272 /* set both B-channel to not connected */
1273 hfc
->b_mode
[0] = L1_MODE_NULL
;
1274 hfc
->b_mode
[1] = L1_MODE_NULL
;
1276 hfc
->l1_activated
= FALSE
;
1277 hfc
->disc_flag
= FALSE
;
1279 hfc
->led_new_data
= 0;
1280 hfc
->old_led_state
= 0;
1282 /* init the t3 timer */
1283 init_timer(&hfc
->t3_timer
);
1284 hfc
->t3_timer
.data
= (long) hfc
;
1285 hfc
->t3_timer
.function
= (void *) l1_timer_expire_t3
;
1287 /* init the t4 timer */
1288 init_timer(&hfc
->t4_timer
);
1289 hfc
->t4_timer
.data
= (long) hfc
;
1290 hfc
->t4_timer
.function
= (void *) l1_timer_expire_t4
;
1292 /* init the background machinery for control requests */
1293 hfc
->ctrl_read
.bRequestType
= 0xc0;
1294 hfc
->ctrl_read
.bRequest
= 1;
1295 hfc
->ctrl_read
.wLength
= 1;
1296 hfc
->ctrl_write
.bRequestType
= 0x40;
1297 hfc
->ctrl_write
.bRequest
= 0;
1298 hfc
->ctrl_write
.wLength
= 0;
1299 usb_fill_control_urb(hfc
->ctrl_urb
,
1302 (u_char
*) & hfc
->ctrl_write
,
1303 NULL
, 0, ctrl_complete
, hfc
);
1304 /* Init All Fifos */
1305 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1306 hfc
->fifos
[i
].iso
[0].purb
= NULL
;
1307 hfc
->fifos
[i
].iso
[1].purb
= NULL
;
1308 hfc
->fifos
[i
].active
= 0;
1310 /* register Modul to upper Hisax Layers */
1311 hfc
->d_if
.owner
= THIS_MODULE
;
1312 hfc
->d_if
.ifc
.priv
= &hfc
->fifos
[HFCUSB_D_TX
];
1313 hfc
->d_if
.ifc
.l2l1
= hfc_usb_l2l1
;
1314 for (i
= 0; i
< 2; i
++) {
1315 hfc
->b_if
[i
].ifc
.priv
= &hfc
->fifos
[HFCUSB_B1_TX
+ i
* 2];
1316 hfc
->b_if
[i
].ifc
.l2l1
= hfc_usb_l2l1
;
1317 p_b_if
[i
] = &hfc
->b_if
[i
];
1319 /* default Prot: EURO ISDN, should be a module_param */
1321 hisax_register(&hfc
->d_if
, p_b_if
, "hfc_usb", hfc
->protocol
);
1323 #ifdef CONFIG_HISAX_DEBUG
1327 for (i
= 0; i
< 4; i
++)
1328 hfc
->fifos
[i
].hif
= &p_b_if
[i
/ 2]->ifc
;
1329 for (i
= 4; i
< 8; i
++)
1330 hfc
->fifos
[i
].hif
= &hfc
->d_if
.ifc
;
1332 /* 3 (+1) INT IN + 3 ISO OUT */
1333 if (hfc
->cfg_used
== CNF_3INT3ISO
|| hfc
->cfg_used
== CNF_4INT3ISO
) {
1334 start_int_fifo(hfc
->fifos
+ HFCUSB_D_RX
);
1335 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1336 start_int_fifo(hfc
->fifos
+ HFCUSB_PCM_RX
);
1337 start_int_fifo(hfc
->fifos
+ HFCUSB_B1_RX
);
1338 start_int_fifo(hfc
->fifos
+ HFCUSB_B2_RX
);
1340 /* 3 (+1) ISO IN + 3 ISO OUT */
1341 if (hfc
->cfg_used
== CNF_3ISO3ISO
|| hfc
->cfg_used
== CNF_4ISO3ISO
) {
1342 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_RX
, ISOC_PACKETS_D
,
1343 rx_iso_complete
, 16);
1344 if (hfc
->fifos
[HFCUSB_PCM_RX
].pipe
)
1345 start_isoc_chain(hfc
->fifos
+ HFCUSB_PCM_RX
,
1346 ISOC_PACKETS_D
, rx_iso_complete
,
1348 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_RX
, ISOC_PACKETS_B
,
1349 rx_iso_complete
, 16);
1350 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_RX
, ISOC_PACKETS_B
,
1351 rx_iso_complete
, 16);
1354 start_isoc_chain(hfc
->fifos
+ HFCUSB_D_TX
, ISOC_PACKETS_D
,
1355 tx_iso_complete
, 1);
1356 start_isoc_chain(hfc
->fifos
+ HFCUSB_B1_TX
, ISOC_PACKETS_B
,
1357 tx_iso_complete
, 1);
1358 start_isoc_chain(hfc
->fifos
+ HFCUSB_B2_TX
, ISOC_PACKETS_B
,
1359 tx_iso_complete
, 1);
1361 handle_led(hfc
, LED_POWER_ON
);
1366 /*************************************************/
1367 /* function called to probe a new plugged device */
1368 /*************************************************/
1370 hfc_usb_probe(struct usb_interface
*intf
, const struct usb_device_id
*id
)
1372 struct usb_device
*dev
= interface_to_usbdev(intf
);
1373 hfcusb_data
*context
;
1374 struct usb_host_interface
*iface
= intf
->cur_altsetting
;
1375 struct usb_host_interface
*iface_used
= NULL
;
1376 struct usb_host_endpoint
*ep
;
1377 int ifnum
= iface
->desc
.bInterfaceNumber
;
1378 int i
, idx
, alt_idx
, probe_alt_setting
, vend_idx
, cfg_used
, *vcf
,
1379 attr
, cfg_found
, cidx
, ep_addr
;
1380 int cmptbl
[16], small_match
, iso_packet_size
, packet_size
,
1382 hfcsusb_vdata
*driver_info
;
1385 for (i
= 0; hfcusb_idtab
[i
].idVendor
; i
++) {
1386 if (dev
->descriptor
.idVendor
== hfcusb_idtab
[i
].idVendor
1387 && dev
->descriptor
.idProduct
==
1388 hfcusb_idtab
[i
].idProduct
) {
1394 #ifdef CONFIG_HISAX_DEBUG
1396 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum
,
1397 iface
->desc
.bAlternateSetting
, intf
->minor
);
1400 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1401 ifnum
, iface
->desc
.bAlternateSetting
, intf
->minor
);
1403 if (vend_idx
!= 0xffff) {
1404 /* if vendor and product ID is OK, start probing alternate settings */
1406 small_match
= 0xffff;
1408 /* default settings */
1409 iso_packet_size
= 16;
1412 while (alt_idx
< intf
->num_altsetting
) {
1413 iface
= intf
->altsetting
+ alt_idx
;
1414 probe_alt_setting
= iface
->desc
.bAlternateSetting
;
1417 /* check for config EOL element */
1418 while (validconf
[cfg_used
][0]) {
1420 vcf
= validconf
[cfg_used
];
1421 /* first endpoint descriptor */
1422 ep
= iface
->endpoint
;
1423 #ifdef CONFIG_HISAX_DEBUG
1425 "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
1426 ifnum
, probe_alt_setting
, cfg_used
);
1428 memcpy(cmptbl
, vcf
, 16 * sizeof(int));
1430 /* check for all endpoints in this alternate setting */
1431 for (i
= 0; i
< iface
->desc
.bNumEndpoints
;
1434 ep
->desc
.bEndpointAddress
;
1435 /* get endpoint base */
1436 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1439 attr
= ep
->desc
.bmAttributes
;
1440 if (cmptbl
[idx
] == EP_NUL
) {
1443 if (attr
== USB_ENDPOINT_XFER_INT
1444 && cmptbl
[idx
] == EP_INT
)
1445 cmptbl
[idx
] = EP_NUL
;
1446 if (attr
== USB_ENDPOINT_XFER_BULK
1447 && cmptbl
[idx
] == EP_BLK
)
1448 cmptbl
[idx
] = EP_NUL
;
1449 if (attr
== USB_ENDPOINT_XFER_ISOC
1450 && cmptbl
[idx
] == EP_ISO
)
1451 cmptbl
[idx
] = EP_NUL
;
1453 /* check if all INT endpoints match minimum interval */
1454 if (attr
== USB_ENDPOINT_XFER_INT
1455 && ep
->desc
.bInterval
<
1457 #ifdef CONFIG_HISAX_DEBUG
1460 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
1467 for (i
= 0; i
< 16; i
++) {
1468 /* all entries must be EP_NOP or EP_NUL for a valid config */
1469 if (cmptbl
[i
] != EP_NOP
1470 && cmptbl
[i
] != EP_NUL
)
1474 if (cfg_used
< small_match
) {
1475 small_match
= cfg_used
;
1480 #ifdef CONFIG_HISAX_DEBUG
1482 "HFC-USB: small_match=%x %x\n",
1483 small_match
, alt_used
);
1489 } /* (alt_idx < intf->num_altsetting) */
1491 /* found a valid USB Ta Endpint config */
1492 if (small_match
!= 0xffff) {
1496 kmalloc(sizeof(hfcusb_data
), GFP_KERNEL
)))
1497 return (-ENOMEM
); /* got no mem */
1498 memset(context
, 0, sizeof(hfcusb_data
));
1500 ep
= iface
->endpoint
;
1501 vcf
= validconf
[small_match
];
1503 for (i
= 0; i
< iface
->desc
.bNumEndpoints
; i
++) {
1504 ep_addr
= ep
->desc
.bEndpointAddress
;
1505 /* get endpoint base */
1506 idx
= ((ep_addr
& 0x7f) - 1) * 2;
1510 attr
= ep
->desc
.bmAttributes
;
1512 /* init Endpoints */
1513 if (vcf
[idx
] != EP_NOP
1514 && vcf
[idx
] != EP_NUL
) {
1516 case USB_ENDPOINT_XFER_INT
:
1532 case USB_ENDPOINT_XFER_BULK
:
1561 case USB_ENDPOINT_XFER_ISOC
:
1594 } /* switch attribute */
1596 if (context
->fifos
[cidx
].pipe
) {
1597 context
->fifos
[cidx
].
1599 context
->fifos
[cidx
].hfc
=
1601 context
->fifos
[cidx
].
1605 context
->fifos
[cidx
].
1608 context
->fifos
[cidx
].
1614 context
->dev
= dev
; /* save device */
1615 context
->if_used
= ifnum
; /* save used interface */
1616 context
->alt_used
= alt_used
; /* and alternate config */
1617 context
->ctrl_paksize
= dev
->descriptor
.bMaxPacketSize0
; /* control size */
1618 context
->cfg_used
= vcf
[16]; /* store used config */
1619 context
->vend_idx
= vend_idx
; /* store found vendor */
1620 context
->packet_size
= packet_size
;
1621 context
->iso_packet_size
= iso_packet_size
;
1623 /* create the control pipes needed for register access */
1624 context
->ctrl_in_pipe
=
1625 usb_rcvctrlpipe(context
->dev
, 0);
1626 context
->ctrl_out_pipe
=
1627 usb_sndctrlpipe(context
->dev
, 0);
1628 context
->ctrl_urb
= usb_alloc_urb(0, GFP_KERNEL
);
1631 (hfcsusb_vdata
*) hfcusb_idtab
[vend_idx
].
1633 printk(KERN_INFO
"HFC-S USB: detected \"%s\"\n",
1634 driver_info
->vend_name
);
1635 #ifdef CONFIG_HISAX_DEBUG
1637 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
1638 conf_str
[small_match
], context
->if_used
,
1641 "HFC-S USB: E-channel (\"ECHO:\") logging ");
1642 if (validconf
[small_match
][18])
1643 printk(" possible\n");
1645 printk("NOT possible\n");
1647 /* init the chip and register the driver */
1648 if (usb_init(context
)) {
1649 if (context
->ctrl_urb
) {
1650 usb_unlink_urb(context
->ctrl_urb
);
1651 usb_free_urb(context
->ctrl_urb
);
1652 context
->ctrl_urb
= NULL
;
1657 usb_set_intfdata(intf
, context
);
1662 "HFC-S USB: no valid vendor found in USB descriptor\n");
1667 /****************************************************/
1668 /* function called when an active device is removed */
1669 /****************************************************/
1671 hfc_usb_disconnect(struct usb_interface
1674 hfcusb_data
*context
= usb_get_intfdata(intf
);
1676 printk(KERN_INFO
"HFC-S USB: device disconnect\n");
1677 context
->disc_flag
= TRUE
;
1678 usb_set_intfdata(intf
, NULL
);
1681 if (timer_pending(&context
->t3_timer
))
1682 del_timer(&context
->t3_timer
);
1683 if (timer_pending(&context
->t4_timer
))
1684 del_timer(&context
->t4_timer
);
1685 /* tell all fifos to terminate */
1686 for (i
= 0; i
< HFCUSB_NUM_FIFOS
; i
++) {
1687 if (context
->fifos
[i
].usb_transfer_mode
== USB_ISOC
) {
1688 if (context
->fifos
[i
].active
> 0) {
1689 stop_isoc_chain(&context
->fifos
[i
]);
1690 #ifdef CONFIG_HISAX_DEBUG
1692 "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
1697 if (context
->fifos
[i
].active
> 0) {
1698 context
->fifos
[i
].active
= 0;
1699 #ifdef CONFIG_HISAX_DEBUG
1701 "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
1705 if (context
->fifos
[i
].urb
) {
1706 usb_unlink_urb(context
->fifos
[i
].urb
);
1707 usb_free_urb(context
->fifos
[i
].urb
);
1708 context
->fifos
[i
].urb
= NULL
;
1711 context
->fifos
[i
].active
= 0;
1713 /* wait for all URBS to terminate */
1715 if (context
->ctrl_urb
) {
1716 usb_unlink_urb(context
->ctrl_urb
);
1717 usb_free_urb(context
->ctrl_urb
);
1718 context
->ctrl_urb
= NULL
;
1720 hisax_unregister(&context
->d_if
);
1721 kfree(context
); /* free our structure again */
1722 } /* hfc_usb_disconnect */
1724 /************************************/
1725 /* our driver information structure */
1726 /************************************/
1727 static struct usb_driver hfc_drv
= {
1728 .owner
= THIS_MODULE
,
1730 .id_table
= hfcusb_idtab
,
1731 .probe
= hfc_usb_probe
,
1732 .disconnect
= hfc_usb_disconnect
,
1737 #ifdef CONFIG_HISAX_DEBUG
1738 DBG(USB_DBG
, "HFC-S USB: calling \"hfc_usb_exit\" ...");
1740 usb_deregister(&hfc_drv
); /* release our driver */
1741 printk(KERN_INFO
"HFC-S USB: module removed\n");
1747 #ifndef CONFIG_HISAX_DEBUG
1748 unsigned int debug
= -1;
1750 char revstr
[30], datestr
[30], dummy
[30];
1751 sscanf(hfcusb_revision
,
1752 "%s %s $ %s %s %s $ ", dummy
, revstr
,
1753 dummy
, datestr
, dummy
);
1755 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1756 revstr
, datestr
, debug
);
1757 if (usb_register(&hfc_drv
)) {
1759 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1760 return (-1); /* unable to register */
1765 module_init(hfc_usb_init
);
1766 module_exit(hfc_usb_exit
);
1767 MODULE_AUTHOR(DRIVER_AUTHOR
);
1768 MODULE_DESCRIPTION(DRIVER_DESC
);
1769 MODULE_LICENSE("GPL");
1770 MODULE_DEVICE_TABLE(usb
, hfcusb_idtab
);