4 * $Id: hfc_usb.c,v 2.3.2.13 2006/02/17 17:17:22 mbachem 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: 2.3.2.13 $ $Date: 2006/02/17 17:17:22 $ ";
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[] = {
74 USB_DEVICE(0x0959, 0x2bd0),
75 .driver_info = (unsigned long) &((hfcsusb_vdata)
76 {LED_OFF, {4, 0, 2, 1},
77 "ISDN USB TA (Cologne Chip HFC-S USB based)"}),
80 USB_DEVICE(0x0675, 0x1688),
81 .driver_info = (unsigned long) &((hfcsusb_vdata)
82 {LED_SCHEME1, {1, 2, 0, 0},
83 "DrayTek miniVigor 128 USB ISDN TA"}),
86 USB_DEVICE(0x07b0, 0x0007),
87 .driver_info = (unsigned long) &((hfcsusb_vdata)
88 {LED_SCHEME1, {0x80, -64, -32, -16},
89 "Billion tiny USB ISDN TA 128"}),
92 USB_DEVICE(0x0742, 0x2008),
93 .driver_info = (unsigned long) &((hfcsusb_vdata)
94 {LED_SCHEME1, {4, 0, 2, 1},
98 USB_DEVICE(0x0742, 0x2009),
99 .driver_info = (unsigned long) &((hfcsusb_vdata)
100 {LED_SCHEME1, {4, 0, 2, 1},
101 "Aceex USB ISDN TA"}),
104 USB_DEVICE(0x0742, 0x200A),
105 .driver_info = (unsigned long) &((hfcsusb_vdata)
106 {LED_SCHEME1, {4, 0, 2, 1},
110 USB_DEVICE(0x08e3, 0x0301),
111 .driver_info = (unsigned long) &((hfcsusb_vdata)
112 {LED_SCHEME1, {2, 0, 1, 4},
116 USB_DEVICE(0x07fa, 0x0846),
117 .driver_info = (unsigned long) &((hfcsusb_vdata)
118 {LED_SCHEME1, {0x80, -64, -32, -16},
119 "Bewan Modem RNIS USB"}),
122 USB_DEVICE(0x07fa, 0x0847),
123 .driver_info = (unsigned long) &((hfcsusb_vdata)
124 {LED_SCHEME1, {0x80, -64, -32, -16},
125 "Djinn Numeris USB"}),
128 USB_DEVICE(0x07b0, 0x0006),
129 .driver_info = (unsigned long) &((hfcsusb_vdata)
130 {LED_SCHEME1, {0x80, -64, -32, -16},
136 /***************************************************************/
137 /* structure defining input+output fifos (interrupt/bulk mode) */
138 /***************************************************************/
139 struct usb_fifo; /* forward definition */
140 typedef struct iso_urb_struct {
142 __u8 buffer[ISO_BUFFER_SIZE]; /* buffer incoming/outgoing data */
143 struct usb_fifo *owner_fifo; /* pointer to owner fifo */
147 struct hfcusb_data; /* forward definition */
148 typedef struct usb_fifo {
149 int fifonum; /* fifo index attached to this structure */
150 int active; /* fifo is currently active */
151 struct hfcusb_data *hfc; /* pointer to main structure */
152 int pipe; /* address of endpoint */
153 __u8 usb_packet_maxlen; /* maximum length for usb transfer */
154 unsigned int max_size; /* maximum size of receive/send packet */
155 __u8 intervall; /* interrupt interval */
156 struct sk_buff *skbuff; /* actual used buffer */
157 struct urb *urb; /* transfer structure for usb routines */
158 __u8 buffer[128]; /* buffer incoming/outgoing data */
159 int bit_line; /* how much bits are in the fifo? */
161 volatile __u8 usb_transfer_mode; /* switched between ISO and INT */
162 iso_urb_struct iso[2]; /* need two urbs to have one always for pending */
163 struct hisax_if *hif; /* hisax interface */
164 int delete_flg; /* only delete skbuff once */
165 int last_urblen; /* remember length of last packet */
169 /*********************************************/
170 /* structure holding all data for one device */
171 /*********************************************/
172 typedef struct hfcusb_data {
173 /* HiSax Interface for loadable Layer1 drivers */
174 struct hisax_d_if d_if; /* see hisax_if.h */
175 struct hisax_b_if b_if[2]; /* see hisax_if.h */
178 struct usb_device *dev; /* our device */
179 int if_used; /* used interface number */
180 int alt_used; /* used alternate config */
181 int ctrl_paksize; /* control pipe packet size */
182 int ctrl_in_pipe, ctrl_out_pipe; /* handles for control pipe */
183 int cfg_used; /* configuration index used */
184 int vend_idx; /* vendor found */
185 int b_mode[2]; /* B-channel mode */
186 int l1_activated; /* layer 1 activated */
187 int disc_flag; /* TRUE if device was disonnected to avoid some USB actions */
188 int packet_size, iso_packet_size;
190 /* control pipe background handling */
191 ctrl_buft ctrl_buff[HFC_CTRL_BUFSIZE]; /* buffer holding queued data */
192 volatile int ctrl_in_idx, ctrl_out_idx, ctrl_cnt; /* input/output pointer + count */
193 struct urb *ctrl_urb; /* transfer structure for control channel */
195 struct usb_ctrlrequest ctrl_write; /* buffer for control write request */
196 struct usb_ctrlrequest ctrl_read; /* same for read request */
198 __u8 old_led_state, led_state, led_new_data, led_b_active;
200 volatile __u8 threshold_mask; /* threshold actually reported */
201 volatile __u8 bch_enables; /* or mask for sctrl_r and sctrl register values */
203 usb_fifo fifos[HFCUSB_NUM_FIFOS]; /* structure holding all fifo data */
205 volatile __u8 l1_state; /* actual l1 state */
206 struct timer_list t3_timer; /* timer 3 for activation/deactivation */
207 struct timer_list t4_timer; /* timer 4 for activation/deactivation */
211 static void collect_rx_frame(usb_fifo * fifo, __u8 * data, int len,
215 static inline const char *
216 symbolic(struct hfcusb_symbolic_list list[], const int num)
219 for (i = 0; list[i].name != NULL; i++)
220 if (list[i].num == num)
221 return (list[i].name);
222 return "<unknown ERROR>";
226 /******************************************************/
227 /* start next background transfer for control channel */
228 /******************************************************/
230 ctrl_start_transfer(hfcusb_data * hfc)
233 hfc->ctrl_urb->pipe = hfc->ctrl_out_pipe;
234 hfc->ctrl_urb->setup_packet = (u_char *) & hfc->ctrl_write;
235 hfc->ctrl_urb->transfer_buffer = NULL;
236 hfc->ctrl_urb->transfer_buffer_length = 0;
237 hfc->ctrl_write.wIndex =
238 cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].hfc_reg);
239 hfc->ctrl_write.wValue =
240 cpu_to_le16(hfc->ctrl_buff[hfc->ctrl_out_idx].reg_val);
242 usb_submit_urb(hfc->ctrl_urb, GFP_ATOMIC); /* start transfer */
244 } /* ctrl_start_transfer */
246 /************************************/
247 /* queue a control transfer request */
248 /* return 0 on success. */
249 /************************************/
251 queue_control_request(hfcusb_data * hfc, __u8 reg, __u8 val, int action)
255 if (hfc->ctrl_cnt >= HFC_CTRL_BUFSIZE)
256 return (1); /* no space left */
257 buf = &hfc->ctrl_buff[hfc->ctrl_in_idx]; /* pointer to new index */
260 buf->action = action;
261 if (++hfc->ctrl_in_idx >= HFC_CTRL_BUFSIZE)
262 hfc->ctrl_in_idx = 0; /* pointer wrap */
263 if (++hfc->ctrl_cnt == 1)
264 ctrl_start_transfer(hfc);
266 } /* queue_control_request */
269 control_action_handler(hfcusb_data * hfc, int reg, int val, int action)
272 return (1); /* no action defined */
276 /***************************************************************/
277 /* control completion routine handling background control cmds */
278 /***************************************************************/
280 ctrl_complete(struct urb *urb, struct pt_regs *regs)
282 hfcusb_data *hfc = (hfcusb_data *) urb->context;
287 buf = &hfc->ctrl_buff[hfc->ctrl_out_idx];
288 control_action_handler(hfc, buf->hfc_reg, buf->reg_val,
291 hfc->ctrl_cnt--; /* decrement actual count */
292 if (++hfc->ctrl_out_idx >= HFC_CTRL_BUFSIZE)
293 hfc->ctrl_out_idx = 0; /* pointer wrap */
295 ctrl_start_transfer(hfc); /* start next transfer */
297 } /* ctrl_complete */
299 /***************************************************/
300 /* write led data to auxport & invert if necessary */
301 /***************************************************/
303 write_led(hfcusb_data * hfc, __u8 led_state)
305 if (led_state != hfc->old_led_state) {
306 hfc->old_led_state = led_state;
307 queue_control_request(hfc, HFCUSB_P_DATA, led_state, 1);
311 /**************************/
312 /* handle LED bits */
313 /**************************/
315 set_led_bit(hfcusb_data * hfc, signed short led_bits, int unset)
319 hfc->led_state |= abs(led_bits);
321 hfc->led_state &= ~led_bits;
324 hfc->led_state &= ~abs(led_bits);
326 hfc->led_state |= led_bits;
330 /**************************/
331 /* handle LED requests */
332 /**************************/
334 handle_led(hfcusb_data * hfc, int event)
336 hfcsusb_vdata *driver_info =
337 (hfcsusb_vdata *) hfcusb_idtab[hfc->vend_idx].driver_info;
339 /* if no scheme -> no LED action */
340 if (driver_info->led_scheme == LED_OFF)
345 set_led_bit(hfc, driver_info->led_bits[0],
347 set_led_bit(hfc, driver_info->led_bits[1],
349 set_led_bit(hfc, driver_info->led_bits[2],
351 set_led_bit(hfc, driver_info->led_bits[3],
354 case LED_POWER_OFF: /* no Power off handling */
357 set_led_bit(hfc, driver_info->led_bits[1],
361 set_led_bit(hfc, driver_info->led_bits[1],
365 set_led_bit(hfc, driver_info->led_bits[2],
369 set_led_bit(hfc, driver_info->led_bits[2],
373 set_led_bit(hfc, driver_info->led_bits[3],
377 set_led_bit(hfc, driver_info->led_bits[3],
381 write_led(hfc, hfc->led_state);
384 /********************************/
385 /* called when timer t3 expires */
386 /********************************/
388 l1_timer_expire_t3(hfcusb_data * hfc)
390 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
392 #ifdef CONFIG_HISAX_DEBUG
394 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T3 expire)");
396 hfc->l1_activated = FALSE;
397 handle_led(hfc, LED_S0_OFF);
399 queue_control_request(hfc, HFCUSB_STATES, 0x10, 1);
400 queue_control_request(hfc, HFCUSB_STATES, 3, 1);
403 /********************************/
404 /* called when timer t4 expires */
405 /********************************/
407 l1_timer_expire_t4(hfcusb_data * hfc)
409 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc, PH_DEACTIVATE | INDICATION,
411 #ifdef CONFIG_HISAX_DEBUG
413 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (T4 expire)");
415 hfc->l1_activated = FALSE;
416 handle_led(hfc, LED_S0_OFF);
419 /*****************************/
420 /* handle S0 state changes */
421 /*****************************/
423 state_handler(hfcusb_data * hfc, __u8 state)
427 old_state = hfc->l1_state;
428 if (state == old_state || state < 1 || state > 8)
431 #ifdef CONFIG_HISAX_DEBUG
432 DBG(ISDN_DBG, "HFC-S USB: new S0 state:%d old_state:%d", state,
435 if (state < 4 || state == 7 || state == 8) {
436 if (timer_pending(&hfc->t3_timer))
437 del_timer(&hfc->t3_timer);
438 #ifdef CONFIG_HISAX_DEBUG
439 DBG(ISDN_DBG, "HFC-S USB: T3 deactivated");
443 if (timer_pending(&hfc->t4_timer))
444 del_timer(&hfc->t4_timer);
445 #ifdef CONFIG_HISAX_DEBUG
446 DBG(ISDN_DBG, "HFC-S USB: T4 deactivated");
450 if (state == 7 && !hfc->l1_activated) {
451 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
452 PH_ACTIVATE | INDICATION, NULL);
453 #ifdef CONFIG_HISAX_DEBUG
454 DBG(ISDN_DBG, "HFC-S USB: PH_ACTIVATE | INDICATION sent");
456 hfc->l1_activated = TRUE;
457 handle_led(hfc, LED_S0_ON);
458 } else if (state <= 3 /* && activated */ ) {
459 if (old_state == 7 || old_state == 8) {
460 #ifdef CONFIG_HISAX_DEBUG
461 DBG(ISDN_DBG, "HFC-S USB: T4 activated");
463 if (!timer_pending(&hfc->t4_timer)) {
464 hfc->t4_timer.expires =
465 jiffies + (HFC_TIMER_T4 * HZ) / 1000;
466 add_timer(&hfc->t4_timer);
469 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
470 PH_DEACTIVATE | INDICATION,
472 #ifdef CONFIG_HISAX_DEBUG
474 "HFC-S USB: PH_DEACTIVATE | INDICATION sent");
476 hfc->l1_activated = FALSE;
477 handle_led(hfc, LED_S0_OFF);
480 hfc->l1_state = state;
483 /* prepare iso urb */
485 fill_isoc_urb(struct urb *urb, struct usb_device *dev, unsigned int pipe,
486 void *buf, int num_packets, int packet_size, int interval,
487 usb_complete_t complete, void *context)
491 spin_lock_init(&urb->lock);
494 urb->complete = complete;
495 urb->number_of_packets = num_packets;
496 urb->transfer_buffer_length = packet_size * num_packets;
497 urb->context = context;
498 urb->transfer_buffer = buf;
499 urb->transfer_flags = URB_ISO_ASAP;
500 urb->actual_length = 0;
501 urb->interval = interval;
502 for (k = 0; k < num_packets; k++) {
503 urb->iso_frame_desc[k].offset = packet_size * k;
504 urb->iso_frame_desc[k].length = packet_size;
505 urb->iso_frame_desc[k].actual_length = 0;
509 /* allocs urbs and start isoc transfer with two pending urbs to avoid
510 gaps in the transfer chain */
512 start_isoc_chain(usb_fifo * fifo, int num_packets_per_urb,
513 usb_complete_t complete, int packet_size)
517 printk(KERN_INFO "HFC-S USB: starting ISO-chain for Fifo %i\n",
520 /* allocate Memory for Iso out Urbs */
521 for (i = 0; i < 2; i++) {
522 if (!(fifo->iso[i].purb)) {
524 usb_alloc_urb(num_packets_per_urb, GFP_KERNEL);
525 if (!(fifo->iso[i].purb)) {
527 "alloc urb for fifo %i failed!!!",
530 fifo->iso[i].owner_fifo = (struct usb_fifo *) fifo;
532 /* Init the first iso */
533 if (ISO_BUFFER_SIZE >=
534 (fifo->usb_packet_maxlen *
535 num_packets_per_urb)) {
536 fill_isoc_urb(fifo->iso[i].purb,
537 fifo->hfc->dev, fifo->pipe,
540 fifo->usb_packet_maxlen,
541 fifo->intervall, complete,
543 memset(fifo->iso[i].buffer, 0,
544 sizeof(fifo->iso[i].buffer));
545 /* defining packet delimeters in fifo->buffer */
546 for (k = 0; k < num_packets_per_urb; k++) {
548 iso_frame_desc[k].offset =
551 iso_frame_desc[k].length =
556 "HFC-S USB: ISO Buffer size to small!\n");
559 fifo->bit_line = BITLINE_INF;
561 errcode = usb_submit_urb(fifo->iso[i].purb, GFP_KERNEL);
562 fifo->active = (errcode >= 0) ? 1 : 0;
564 printk(KERN_INFO "HFC-S USB: %s URB nr:%d\n",
565 symbolic(urb_errlist, errcode), i);
568 return (fifo->active);
571 /* stops running iso chain and frees their pending urbs */
573 stop_isoc_chain(usb_fifo * fifo)
577 for (i = 0; i < 2; i++) {
578 if (fifo->iso[i].purb) {
579 #ifdef CONFIG_HISAX_DEBUG
581 "HFC-S USB: Stopping iso chain for fifo %i.%i",
584 usb_unlink_urb(fifo->iso[i].purb);
585 usb_free_urb(fifo->iso[i].purb);
586 fifo->iso[i].purb = NULL;
590 usb_unlink_urb(fifo->urb);
591 usb_free_urb(fifo->urb);
597 /* defines how much ISO packets are handled in one URB */
598 static int iso_packets[8] =
599 { ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B, ISOC_PACKETS_B,
600 ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D, ISOC_PACKETS_D
603 /*****************************************************/
604 /* transmit completion routine for all ISO tx fifos */
605 /*****************************************************/
607 tx_iso_complete(struct urb *urb, struct pt_regs *regs)
609 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
610 usb_fifo *fifo = context_iso_urb->owner_fifo;
611 hfcusb_data *hfc = fifo->hfc;
612 int k, tx_offset, num_isoc_packets, sink, len, current_len,
614 int frame_complete, transp_mode, fifon, status;
616 __u8 threshtable[8] = { 1, 2, 4, 8, 0x10, 0x20, 0x40, 0x80 };
618 fifon = fifo->fifonum;
619 status = urb->status;
623 if (fifo->active && !status) {
625 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
628 /* is FifoFull-threshold set for our channel? */
629 threshbit = threshtable[fifon] & hfc->threshold_mask;
630 num_isoc_packets = iso_packets[fifon];
632 /* predict dataflow to avoid fifo overflow */
633 if (fifon >= HFCUSB_D_TX) {
634 sink = (threshbit) ? SINK_DMIN : SINK_DMAX;
636 sink = (threshbit) ? SINK_MIN : SINK_MAX;
638 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
639 context_iso_urb->buffer, num_isoc_packets,
640 fifo->usb_packet_maxlen, fifo->intervall,
641 tx_iso_complete, urb->context);
642 memset(context_iso_urb->buffer, 0,
643 sizeof(context_iso_urb->buffer));
644 frame_complete = FALSE;
645 /* Generate next Iso Packets */
646 for (k = 0; k < num_isoc_packets; ++k) {
648 len = fifo->skbuff->len;
649 /* we lower data margin every msec */
650 fifo->bit_line -= sink;
651 current_len = (0 - fifo->bit_line) / 8;
652 /* maximum 15 byte for every ISO packet makes our life easier */
653 if (current_len > 14)
657 current_len) ? len : current_len;
658 /* how much bit do we put on the line? */
659 fifo->bit_line += current_len * 8;
661 context_iso_urb->buffer[tx_offset] = 0;
662 if (current_len == len) {
664 /* here frame completion */
666 buffer[tx_offset] = 1;
667 /* add 2 byte flags and 16bit CRC at end of ISDN frame */
668 fifo->bit_line += 32;
670 frame_complete = TRUE;
673 memcpy(context_iso_urb->buffer +
674 tx_offset + 1, fifo->skbuff->data,
676 skb_pull(fifo->skbuff, current_len);
678 /* define packet delimeters within the URB buffer */
679 urb->iso_frame_desc[k].offset = tx_offset;
680 urb->iso_frame_desc[k].length =
683 tx_offset += (current_len + 1);
685 urb->iso_frame_desc[k].offset =
688 urb->iso_frame_desc[k].length = 1;
689 fifo->bit_line -= sink; /* we lower data margin every msec */
691 if (fifo->bit_line < BITLINE_INF) {
692 fifo->bit_line = BITLINE_INF;
696 if (frame_complete) {
697 fifo->delete_flg = TRUE;
698 fifo->hif->l1l2(fifo->hif,
700 (void *) fifo->skbuff->
702 if (fifo->skbuff && fifo->delete_flg) {
703 dev_kfree_skb_any(fifo->skbuff);
705 fifo->delete_flg = FALSE;
707 frame_complete = FALSE;
710 errcode = usb_submit_urb(urb, GFP_ATOMIC);
713 "HFC-S USB: error submitting ISO URB: %d \n",
717 if (status && !hfc->disc_flag) {
719 "HFC-S USB: tx_iso_complete : urb->status %s (%i), fifonum=%d\n",
720 symbolic(urb_errlist, status), status,
724 } /* tx_iso_complete */
726 /*****************************************************/
727 /* receive completion routine for all ISO tx fifos */
728 /*****************************************************/
730 rx_iso_complete(struct urb *urb, struct pt_regs *regs)
732 iso_urb_struct *context_iso_urb = (iso_urb_struct *) urb->context;
733 usb_fifo *fifo = context_iso_urb->owner_fifo;
734 hfcusb_data *hfc = fifo->hfc;
735 int k, len, errcode, offset, num_isoc_packets, fifon, maxlen,
737 unsigned int iso_status;
740 #ifdef CONFIG_HISAX_DEBUG
744 fifon = fifo->fifonum;
745 status = urb->status;
747 if (urb->status == -EOVERFLOW) {
748 #ifdef CONFIG_HISAX_DEBUG
750 "HFC-USB: ignoring USB DATAOVERRUN for fifo %i \n",
755 if (fifo->active && !status) {
756 num_isoc_packets = iso_packets[fifon];
757 maxlen = fifo->usb_packet_maxlen;
758 for (k = 0; k < num_isoc_packets; ++k) {
759 len = urb->iso_frame_desc[k].actual_length;
760 offset = urb->iso_frame_desc[k].offset;
761 buf = context_iso_urb->buffer + offset;
762 iso_status = urb->iso_frame_desc[k].status;
763 #ifdef CONFIG_HISAX_DEBUG
764 if (iso_status && !hfc->disc_flag)
766 "HFC-S USB: ISO packet failure - status:%x",
769 if ((fifon == 5) && (debug > 1)) {
771 "HFC-S USB: ISO-D-RX lst_urblen:%2d "
772 "act_urblen:%2d max-urblen:%2d "
774 fifo->last_urblen, len, maxlen,
776 for (i = 0; i < len; i++)
777 printk("%.2x ", buf[i]);
781 if (fifo->last_urblen != maxlen) {
782 /* the threshold mask is in the 2nd status byte */
783 hfc->threshold_mask = buf[1];
784 /* care for L1 state only for D-Channel
785 to avoid overlapped iso completions */
787 /* the S0 state is in the upper half
788 of the 1st status byte */
789 state_handler(hfc, buf[0] >> 4);
791 eof[fifon] = buf[0] & 1;
793 collect_rx_frame(fifo, buf + 2,
799 collect_rx_frame(fifo, buf, len,
801 maxlen) ? eof[fifon] :
804 fifo->last_urblen = len;
807 fill_isoc_urb(urb, fifo->hfc->dev, fifo->pipe,
808 context_iso_urb->buffer, num_isoc_packets,
809 fifo->usb_packet_maxlen, fifo->intervall,
810 rx_iso_complete, urb->context);
811 errcode = usb_submit_urb(urb, GFP_ATOMIC);
814 "HFC-S USB: error submitting ISO URB: %d \n",
818 if (status && !hfc->disc_flag) {
820 "HFC-S USB: rx_iso_complete : "
821 "urb->status %d, fifonum %d\n",
825 } /* rx_iso_complete */
827 /*****************************************************/
828 /* collect data from interrupt or isochron in */
829 /*****************************************************/
831 collect_rx_frame(usb_fifo * fifo, __u8 * data, int len, int finish)
833 hfcusb_data *hfc = fifo->hfc;
834 int transp_mode, fifon;
835 #ifdef CONFIG_HISAX_DEBUG
838 fifon = fifo->fifonum;
840 if (fifon < 4 && hfc->b_mode[fifon / 2] == L1_MODE_TRANS)
844 fifo->skbuff = dev_alloc_skb(fifo->max_size + 3);
847 "HFC-S USB: cannot allocate buffer (dev_alloc_skb) fifo:%d\n",
853 if (fifo->skbuff->len + len < fifo->max_size) {
854 memcpy(skb_put(fifo->skbuff, len), data, len);
856 #ifdef CONFIG_HISAX_DEBUG
857 printk(KERN_INFO "HFC-S USB: ");
858 for (i = 0; i < 15; i++)
860 fifo->skbuff->data[fifo->skbuff->
865 "HCF-USB: got frame exceeded fifo->max_size:%d on fifo:%d\n",
866 fifo->max_size, fifon);
869 if (transp_mode && fifo->skbuff->len >= 128) {
870 fifo->hif->l1l2(fifo->hif, PH_DATA | INDICATION,
875 /* we have a complete hdlc packet */
877 if ((!fifo->skbuff->data[fifo->skbuff->len - 1])
878 && (fifo->skbuff->len > 3)) {
879 /* remove CRC & status */
880 skb_trim(fifo->skbuff, fifo->skbuff->len - 3);
881 if (fifon == HFCUSB_PCM_RX) {
882 fifo->hif->l1l2(fifo->hif,
883 PH_DATA_E | INDICATION,
886 fifo->hif->l1l2(fifo->hif,
887 PH_DATA | INDICATION,
889 fifo->skbuff = NULL; /* buffer was freed from upper layer */
891 if (fifo->skbuff->len > 3) {
893 "HFC-S USB: got frame %d bytes but CRC ERROR on fifo:%d!!!\n",
894 fifo->skbuff->len, fifon);
895 #ifdef CONFIG_HISAX_DEBUG
897 printk(KERN_INFO "HFC-S USB: ");
898 for (i = 0; i < 15; i++)
907 #ifdef CONFIG_HISAX_DEBUG
910 "HFC-S USB: frame to small (%d bytes)!!!\n",
914 skb_trim(fifo->skbuff, 0);
919 /***********************************************/
920 /* receive completion routine for all rx fifos */
921 /***********************************************/
923 rx_complete(struct urb *urb, struct pt_regs *regs)
927 __u8 *buf, maxlen, fifon;
928 usb_fifo *fifo = (usb_fifo *) urb->context;
929 hfcusb_data *hfc = fifo->hfc;
931 #ifdef CONFIG_HISAX_DEBUG
935 urb->dev = hfc->dev; /* security init */
937 fifon = fifo->fifonum;
938 if ((!fifo->active) || (urb->status)) {
939 #ifdef CONFIG_HISAX_DEBUG
940 DBG(USB_DBG, "HFC-S USB: RX-Fifo %i is going down (%i)",
943 fifo->urb->interval = 0; /* cancel automatic rescheduling */
945 dev_kfree_skb_any(fifo->skbuff);
950 len = urb->actual_length;
952 maxlen = fifo->usb_packet_maxlen;
954 #ifdef CONFIG_HISAX_DEBUG
955 if ((fifon == 5) && (debug > 1)) {
957 "HFC-S USB: INT-D-RX lst_urblen:%2d act_urblen:%2d max-urblen:%2d EOF:0x%0x DATA: ",
958 fifo->last_urblen, len, maxlen, eof[5]);
959 for (i = 0; i < len; i++)
960 printk("%.2x ", buf[i]);
965 if (fifo->last_urblen != fifo->usb_packet_maxlen) {
966 /* the threshold mask is in the 2nd status byte */
967 hfc->threshold_mask = buf[1];
968 /* the S0 state is in the upper half of the 1st status byte */
969 state_handler(hfc, buf[0] >> 4);
970 eof[fifon] = buf[0] & 1;
971 /* if we have more than the 2 status bytes -> collect data */
973 collect_rx_frame(fifo, buf + 2,
974 urb->actual_length - 2,
975 (len < maxlen) ? eof[fifon] : 0);
977 collect_rx_frame(fifo, buf, urb->actual_length,
978 (len < maxlen) ? eof[fifon] : 0);
980 fifo->last_urblen = urb->actual_length;
981 status = usb_submit_urb(urb, GFP_ATOMIC);
984 "HFC-S USB: error resubmitting URN at rx_complete...\n");
988 /***************************************************/
989 /* start the interrupt transfer for the given fifo */
990 /***************************************************/
992 start_int_fifo(usb_fifo * fifo)
996 printk(KERN_INFO "HFC-S USB: starting intr IN fifo:%d\n",
1000 fifo->urb = usb_alloc_urb(0, GFP_KERNEL);
1004 usb_fill_int_urb(fifo->urb, fifo->hfc->dev, fifo->pipe,
1005 fifo->buffer, fifo->usb_packet_maxlen,
1006 rx_complete, fifo, fifo->intervall);
1007 fifo->active = 1; /* must be marked active */
1008 errcode = usb_submit_urb(fifo->urb, GFP_KERNEL);
1011 "HFC-S USB: submit URB error(start_int_info): status:%i\n",
1014 fifo->skbuff = NULL;
1016 } /* start_int_fifo */
1018 /*****************************/
1019 /* set the B-channel mode */
1020 /*****************************/
1022 set_hfcmode(hfcusb_data * hfc, int channel, int mode)
1024 __u8 val, idx_table[2] = { 0, 2 };
1026 if (hfc->disc_flag) {
1029 #ifdef CONFIG_HISAX_DEBUG
1030 DBG(ISDN_DBG, "HFC-S USB: setting channel %d to mode %d", channel,
1033 hfc->b_mode[channel] = mode;
1035 /* setup CON_HDLC */
1037 if (mode != L1_MODE_NULL)
1038 val = 8; /* enable fifo? */
1039 if (mode == L1_MODE_TRANS)
1040 val |= 2; /* set transparent bit */
1042 /* set FIFO to transmit register */
1043 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel], 1);
1044 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
1046 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
1047 /* set FIFO to receive register */
1048 queue_control_request(hfc, HFCUSB_FIFO, idx_table[channel] + 1, 1);
1049 queue_control_request(hfc, HFCUSB_CON_HDLC, val, 1);
1051 queue_control_request(hfc, HFCUSB_INC_RES_F, 2, 1);
1058 queue_control_request(hfc, HFCUSB_SCTRL, val, 1);
1065 queue_control_request(hfc, HFCUSB_SCTRL_R, val, 1);
1067 if (mode == L1_MODE_NULL) {
1069 handle_led(hfc, LED_B2_OFF);
1071 handle_led(hfc, LED_B1_OFF);
1074 handle_led(hfc, LED_B2_ON);
1076 handle_led(hfc, LED_B1_ON);
1081 hfc_usb_l2l1(struct hisax_if *my_hisax_if, int pr, void *arg)
1083 usb_fifo *fifo = my_hisax_if->priv;
1084 hfcusb_data *hfc = fifo->hfc;
1087 case PH_ACTIVATE | REQUEST:
1088 if (fifo->fifonum == HFCUSB_D_TX) {
1089 #ifdef CONFIG_HISAX_DEBUG
1091 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_ACTIVATE | REQUEST");
1093 if (hfc->l1_state != 3
1094 && hfc->l1_state != 7) {
1095 hfc->d_if.ifc.l1l2(&hfc->d_if.ifc,
1099 #ifdef CONFIG_HISAX_DEBUG
1101 "HFC-S USB: PH_DEACTIVATE | INDICATION sent (not state 3 or 7)");
1104 if (hfc->l1_state == 7) { /* l1 already active */
1105 hfc->d_if.ifc.l1l2(&hfc->
1112 #ifdef CONFIG_HISAX_DEBUG
1114 "HFC-S USB: PH_ACTIVATE | INDICATION sent again ;)");
1117 /* force sending sending INFO1 */
1118 queue_control_request(hfc,
1123 /* start l1 activation */
1124 queue_control_request(hfc,
1141 #ifdef CONFIG_HISAX_DEBUG
1143 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_ACTIVATE | REQUEST");
1147 HFCUSB_B1_TX) ? 0 : 1,
1149 fifo->hif->l1l2(fifo->hif,
1150 PH_ACTIVATE | INDICATION,
1154 case PH_DEACTIVATE | REQUEST:
1155 if (fifo->fifonum == HFCUSB_D_TX) {
1156 #ifdef CONFIG_HISAX_DEBUG
1158 "HFC_USB: hfc_usb_d_l2l1 D-chan: PH_DEACTIVATE | REQUEST");
1161 "HFC-S USB: ISDN TE device should not deativate...\n");
1163 #ifdef CONFIG_HISAX_DEBUG
1165 "HFC_USB: hfc_usb_d_l2l1 Bx-chan: PH_DEACTIVATE | REQUEST");
1169 HFCUSB_B1_TX) ? 0 : 1,
1170 (int) L1_MODE_NULL);
1171 fifo->hif->l1l2(fifo->hif,
1172 PH_DEACTIVATE | INDICATION,
1176 case PH_DATA | REQUEST:
1177 if (fifo->skbuff && fifo->delete_flg) {
1178 dev_kfree_skb_any(fifo->skbuff);
1179 fifo->skbuff = NULL;
1180 fifo->delete_flg = FALSE;
1182 fifo->skbuff = arg; /* we have a new buffer */
1186 "HFC_USB: hfc_usb_d_l2l1: unkown state : %#x\n",
1192 /***************************************************************************/
1193 /* usb_init is called once when a new matching device is detected to setup */
1194 /* main parameters. It registers the driver at the main hisax module. */
1195 /* on success 0 is returned. */
1196 /***************************************************************************/
1198 usb_init(hfcusb_data * hfc)
1203 struct hisax_b_if *p_b_if[2];
1205 /* check the chip id */
1206 if (read_usb(hfc, HFCUSB_CHIP_ID, &b) != 1) {
1207 printk(KERN_INFO "HFC-USB: cannot read chip id\n");
1210 if (b != HFCUSB_CHIPID) {
1211 printk(KERN_INFO "HFC-S USB: Invalid chip id 0x%02x\n", b);
1215 /* first set the needed config, interface and alternate */
1216 err = usb_set_interface(hfc->dev, hfc->if_used, hfc->alt_used);
1219 write_usb(hfc, HFCUSB_CIRM, 8);
1220 /* aux = output, reset off */
1221 write_usb(hfc, HFCUSB_CIRM, 0x10);
1223 /* set USB_SIZE to match the the wMaxPacketSize for INT or BULK transfers */
1224 write_usb(hfc, HFCUSB_USB_SIZE,
1225 (hfc->packet_size / 8) | ((hfc->packet_size / 8) << 4));
1227 /* set USB_SIZE_I to match the the wMaxPacketSize for ISO transfers */
1228 write_usb(hfc, HFCUSB_USB_SIZE_I, hfc->iso_packet_size);
1230 /* enable PCM/GCI master mode */
1231 write_usb(hfc, HFCUSB_MST_MODE1, 0); /* set default values */
1232 write_usb(hfc, HFCUSB_MST_MODE0, 1); /* enable master mode */
1234 /* init the fifos */
1235 write_usb(hfc, HFCUSB_F_THRES,
1236 (HFCUSB_TX_THRESHOLD /
1237 8) | ((HFCUSB_RX_THRESHOLD / 8) << 4));
1240 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1241 write_usb(hfc, HFCUSB_FIFO, i); /* select the desired fifo */
1242 fifo[i].skbuff = NULL; /* init buffer pointer */
1244 (i <= HFCUSB_B2_RX) ? MAX_BCH_SIZE : MAX_DFRAME_LEN;
1245 fifo[i].last_urblen = 0;
1246 /* set 2 bit for D- & E-channel */
1247 write_usb(hfc, HFCUSB_HDLC_PAR,
1248 ((i <= HFCUSB_B2_RX) ? 0 : 2));
1249 /* rx hdlc, enable IFF for D-channel */
1250 write_usb(hfc, HFCUSB_CON_HDLC,
1251 ((i == HFCUSB_D_TX) ? 0x09 : 0x08));
1252 write_usb(hfc, HFCUSB_INC_RES_F, 2); /* reset the fifo */
1255 write_usb(hfc, HFCUSB_CLKDEL, 0x0f); /* clock delay value */
1256 write_usb(hfc, HFCUSB_STATES, 3 | 0x10); /* set deactivated mode */
1257 write_usb(hfc, HFCUSB_STATES, 3); /* enable state machine */
1259 write_usb(hfc, HFCUSB_SCTRL_R, 0); /* disable both B receivers */
1260 write_usb(hfc, HFCUSB_SCTRL, 0x40); /* disable B transmitters + capacitive mode */
1262 /* set both B-channel to not connected */
1263 hfc->b_mode[0] = L1_MODE_NULL;
1264 hfc->b_mode[1] = L1_MODE_NULL;
1266 hfc->l1_activated = FALSE;
1267 hfc->disc_flag = FALSE;
1269 hfc->led_new_data = 0;
1270 hfc->old_led_state = 0;
1272 /* init the t3 timer */
1273 init_timer(&hfc->t3_timer);
1274 hfc->t3_timer.data = (long) hfc;
1275 hfc->t3_timer.function = (void *) l1_timer_expire_t3;
1277 /* init the t4 timer */
1278 init_timer(&hfc->t4_timer);
1279 hfc->t4_timer.data = (long) hfc;
1280 hfc->t4_timer.function = (void *) l1_timer_expire_t4;
1282 /* init the background machinery for control requests */
1283 hfc->ctrl_read.bRequestType = 0xc0;
1284 hfc->ctrl_read.bRequest = 1;
1285 hfc->ctrl_read.wLength = cpu_to_le16(1);
1286 hfc->ctrl_write.bRequestType = 0x40;
1287 hfc->ctrl_write.bRequest = 0;
1288 hfc->ctrl_write.wLength = 0;
1289 usb_fill_control_urb(hfc->ctrl_urb,
1292 (u_char *) & hfc->ctrl_write,
1293 NULL, 0, ctrl_complete, hfc);
1294 /* Init All Fifos */
1295 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1296 hfc->fifos[i].iso[0].purb = NULL;
1297 hfc->fifos[i].iso[1].purb = NULL;
1298 hfc->fifos[i].active = 0;
1300 /* register Modul to upper Hisax Layers */
1301 hfc->d_if.owner = THIS_MODULE;
1302 hfc->d_if.ifc.priv = &hfc->fifos[HFCUSB_D_TX];
1303 hfc->d_if.ifc.l2l1 = hfc_usb_l2l1;
1304 for (i = 0; i < 2; i++) {
1305 hfc->b_if[i].ifc.priv = &hfc->fifos[HFCUSB_B1_TX + i * 2];
1306 hfc->b_if[i].ifc.l2l1 = hfc_usb_l2l1;
1307 p_b_if[i] = &hfc->b_if[i];
1309 /* default Prot: EURO ISDN, should be a module_param */
1311 hisax_register(&hfc->d_if, p_b_if, "hfc_usb", hfc->protocol);
1313 #ifdef CONFIG_HISAX_DEBUG
1317 for (i = 0; i < 4; i++)
1318 hfc->fifos[i].hif = &p_b_if[i / 2]->ifc;
1319 for (i = 4; i < 8; i++)
1320 hfc->fifos[i].hif = &hfc->d_if.ifc;
1322 /* 3 (+1) INT IN + 3 ISO OUT */
1323 if (hfc->cfg_used == CNF_3INT3ISO || hfc->cfg_used == CNF_4INT3ISO) {
1324 start_int_fifo(hfc->fifos + HFCUSB_D_RX);
1325 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1326 start_int_fifo(hfc->fifos + HFCUSB_PCM_RX);
1327 start_int_fifo(hfc->fifos + HFCUSB_B1_RX);
1328 start_int_fifo(hfc->fifos + HFCUSB_B2_RX);
1330 /* 3 (+1) ISO IN + 3 ISO OUT */
1331 if (hfc->cfg_used == CNF_3ISO3ISO || hfc->cfg_used == CNF_4ISO3ISO) {
1332 start_isoc_chain(hfc->fifos + HFCUSB_D_RX, ISOC_PACKETS_D,
1333 rx_iso_complete, 16);
1334 if (hfc->fifos[HFCUSB_PCM_RX].pipe)
1335 start_isoc_chain(hfc->fifos + HFCUSB_PCM_RX,
1336 ISOC_PACKETS_D, rx_iso_complete,
1338 start_isoc_chain(hfc->fifos + HFCUSB_B1_RX, ISOC_PACKETS_B,
1339 rx_iso_complete, 16);
1340 start_isoc_chain(hfc->fifos + HFCUSB_B2_RX, ISOC_PACKETS_B,
1341 rx_iso_complete, 16);
1344 start_isoc_chain(hfc->fifos + HFCUSB_D_TX, ISOC_PACKETS_D,
1345 tx_iso_complete, 1);
1346 start_isoc_chain(hfc->fifos + HFCUSB_B1_TX, ISOC_PACKETS_B,
1347 tx_iso_complete, 1);
1348 start_isoc_chain(hfc->fifos + HFCUSB_B2_TX, ISOC_PACKETS_B,
1349 tx_iso_complete, 1);
1351 handle_led(hfc, LED_POWER_ON);
1356 /*************************************************/
1357 /* function called to probe a new plugged device */
1358 /*************************************************/
1360 hfc_usb_probe(struct usb_interface *intf, const struct usb_device_id *id)
1362 struct usb_device *dev = interface_to_usbdev(intf);
1363 hfcusb_data *context;
1364 struct usb_host_interface *iface = intf->cur_altsetting;
1365 struct usb_host_interface *iface_used = NULL;
1366 struct usb_host_endpoint *ep;
1367 int ifnum = iface->desc.bInterfaceNumber;
1368 int i, idx, alt_idx, probe_alt_setting, vend_idx, cfg_used, *vcf,
1369 attr, cfg_found, cidx, ep_addr;
1370 int cmptbl[16], small_match, iso_packet_size, packet_size,
1372 hfcsusb_vdata *driver_info;
1375 for (i = 0; hfcusb_idtab[i].idVendor; i++) {
1376 if ((le16_to_cpu(dev->descriptor.idVendor) == hfcusb_idtab[i].idVendor)
1377 && (le16_to_cpu(dev->descriptor.idProduct) == hfcusb_idtab[i].idProduct)) {
1383 #ifdef CONFIG_HISAX_DEBUG
1385 "HFC-USB: probing interface(%d) actalt(%d) minor(%d)\n", ifnum,
1386 iface->desc.bAlternateSetting, intf->minor);
1389 "HFC-S USB: probing interface(%d) actalt(%d) minor(%d)\n",
1390 ifnum, iface->desc.bAlternateSetting, intf->minor);
1392 if (vend_idx != 0xffff) {
1393 /* if vendor and product ID is OK, start probing alternate settings */
1395 small_match = 0xffff;
1397 /* default settings */
1398 iso_packet_size = 16;
1401 while (alt_idx < intf->num_altsetting) {
1402 iface = intf->altsetting + alt_idx;
1403 probe_alt_setting = iface->desc.bAlternateSetting;
1406 /* check for config EOL element */
1407 while (validconf[cfg_used][0]) {
1409 vcf = validconf[cfg_used];
1410 /* first endpoint descriptor */
1411 ep = iface->endpoint;
1412 #ifdef CONFIG_HISAX_DEBUG
1414 "HFC-S USB: (if=%d alt=%d cfg_used=%d)\n",
1415 ifnum, probe_alt_setting, cfg_used);
1417 memcpy(cmptbl, vcf, 16 * sizeof(int));
1419 /* check for all endpoints in this alternate setting */
1420 for (i = 0; i < iface->desc.bNumEndpoints;
1423 ep->desc.bEndpointAddress;
1424 /* get endpoint base */
1425 idx = ((ep_addr & 0x7f) - 1) * 2;
1428 attr = ep->desc.bmAttributes;
1429 if (cmptbl[idx] == EP_NUL) {
1432 if (attr == USB_ENDPOINT_XFER_INT
1433 && cmptbl[idx] == EP_INT)
1434 cmptbl[idx] = EP_NUL;
1435 if (attr == USB_ENDPOINT_XFER_BULK
1436 && cmptbl[idx] == EP_BLK)
1437 cmptbl[idx] = EP_NUL;
1438 if (attr == USB_ENDPOINT_XFER_ISOC
1439 && cmptbl[idx] == EP_ISO)
1440 cmptbl[idx] = EP_NUL;
1442 /* check if all INT endpoints match minimum interval */
1443 if (attr == USB_ENDPOINT_XFER_INT
1444 && ep->desc.bInterval <
1446 #ifdef CONFIG_HISAX_DEBUG
1449 "HFC-S USB: Interrupt Endpoint interval < %d found - skipping config",
1456 for (i = 0; i < 16; i++) {
1457 /* all entries must be EP_NOP or EP_NUL for a valid config */
1458 if (cmptbl[i] != EP_NOP
1459 && cmptbl[i] != EP_NUL)
1463 if (cfg_used < small_match) {
1464 small_match = cfg_used;
1469 #ifdef CONFIG_HISAX_DEBUG
1471 "HFC-USB: small_match=%x %x\n",
1472 small_match, alt_used);
1478 } /* (alt_idx < intf->num_altsetting) */
1480 /* found a valid USB Ta Endpint config */
1481 if (small_match != 0xffff) {
1485 kmalloc(sizeof(hfcusb_data), GFP_KERNEL)))
1486 return (-ENOMEM); /* got no mem */
1487 memset(context, 0, sizeof(hfcusb_data));
1489 ep = iface->endpoint;
1490 vcf = validconf[small_match];
1492 for (i = 0; i < iface->desc.bNumEndpoints; i++) {
1493 ep_addr = ep->desc.bEndpointAddress;
1494 /* get endpoint base */
1495 idx = ((ep_addr & 0x7f) - 1) * 2;
1499 attr = ep->desc.bmAttributes;
1501 /* init Endpoints */
1502 if (vcf[idx] != EP_NOP
1503 && vcf[idx] != EP_NUL) {
1505 case USB_ENDPOINT_XFER_INT:
1518 le16_to_cpu(ep->desc.wMaxPacketSize);
1520 case USB_ENDPOINT_XFER_BULK:
1546 le16_to_cpu(ep->desc.wMaxPacketSize);
1548 case USB_ENDPOINT_XFER_ISOC:
1574 le16_to_cpu(ep->desc.wMaxPacketSize);
1580 } /* switch attribute */
1582 if (context->fifos[cidx].pipe) {
1583 context->fifos[cidx].
1585 context->fifos[cidx].hfc =
1587 context->fifos[cidx].usb_packet_maxlen =
1588 le16_to_cpu(ep->desc.wMaxPacketSize);
1589 context->fifos[cidx].
1592 context->fifos[cidx].
1598 context->dev = dev; /* save device */
1599 context->if_used = ifnum; /* save used interface */
1600 context->alt_used = alt_used; /* and alternate config */
1601 context->ctrl_paksize = dev->descriptor.bMaxPacketSize0; /* control size */
1602 context->cfg_used = vcf[16]; /* store used config */
1603 context->vend_idx = vend_idx; /* store found vendor */
1604 context->packet_size = packet_size;
1605 context->iso_packet_size = iso_packet_size;
1607 /* create the control pipes needed for register access */
1608 context->ctrl_in_pipe =
1609 usb_rcvctrlpipe(context->dev, 0);
1610 context->ctrl_out_pipe =
1611 usb_sndctrlpipe(context->dev, 0);
1612 context->ctrl_urb = usb_alloc_urb(0, GFP_KERNEL);
1615 (hfcsusb_vdata *) hfcusb_idtab[vend_idx].
1617 printk(KERN_INFO "HFC-S USB: detected \"%s\"\n",
1618 driver_info->vend_name);
1619 #ifdef CONFIG_HISAX_DEBUG
1621 "HFC-S USB: Endpoint-Config: %s (if=%d alt=%d)\n",
1622 conf_str[small_match], context->if_used,
1625 "HFC-S USB: E-channel (\"ECHO:\") logging ");
1626 if (validconf[small_match][18])
1627 printk(" possible\n");
1629 printk("NOT possible\n");
1631 /* init the chip and register the driver */
1632 if (usb_init(context)) {
1633 if (context->ctrl_urb) {
1634 usb_unlink_urb(context->ctrl_urb);
1635 usb_free_urb(context->ctrl_urb);
1636 context->ctrl_urb = NULL;
1641 usb_set_intfdata(intf, context);
1646 "HFC-S USB: no valid vendor found in USB descriptor\n");
1651 /****************************************************/
1652 /* function called when an active device is removed */
1653 /****************************************************/
1655 hfc_usb_disconnect(struct usb_interface
1658 hfcusb_data *context = usb_get_intfdata(intf);
1660 printk(KERN_INFO "HFC-S USB: device disconnect\n");
1661 context->disc_flag = TRUE;
1662 usb_set_intfdata(intf, NULL);
1665 if (timer_pending(&context->t3_timer))
1666 del_timer(&context->t3_timer);
1667 if (timer_pending(&context->t4_timer))
1668 del_timer(&context->t4_timer);
1669 /* tell all fifos to terminate */
1670 for (i = 0; i < HFCUSB_NUM_FIFOS; i++) {
1671 if (context->fifos[i].usb_transfer_mode == USB_ISOC) {
1672 if (context->fifos[i].active > 0) {
1673 stop_isoc_chain(&context->fifos[i]);
1674 #ifdef CONFIG_HISAX_DEBUG
1676 "HFC-S USB: hfc_usb_disconnect: stopping ISOC chain Fifo no %i",
1681 if (context->fifos[i].active > 0) {
1682 context->fifos[i].active = 0;
1683 #ifdef CONFIG_HISAX_DEBUG
1685 "HFC-S USB: hfc_usb_disconnect: unlinking URB for Fifo no %i",
1689 if (context->fifos[i].urb) {
1690 usb_unlink_urb(context->fifos[i].urb);
1691 usb_free_urb(context->fifos[i].urb);
1692 context->fifos[i].urb = NULL;
1695 context->fifos[i].active = 0;
1697 /* wait for all URBS to terminate */
1699 if (context->ctrl_urb) {
1700 usb_unlink_urb(context->ctrl_urb);
1701 usb_free_urb(context->ctrl_urb);
1702 context->ctrl_urb = NULL;
1704 hisax_unregister(&context->d_if);
1705 kfree(context); /* free our structure again */
1706 } /* hfc_usb_disconnect */
1708 /************************************/
1709 /* our driver information structure */
1710 /************************************/
1711 static struct usb_driver hfc_drv = {
1713 .id_table = hfcusb_idtab,
1714 .probe = hfc_usb_probe,
1715 .disconnect = hfc_usb_disconnect,
1720 #ifdef CONFIG_HISAX_DEBUG
1721 DBG(USB_DBG, "HFC-S USB: calling \"hfc_usb_exit\" ...");
1723 usb_deregister(&hfc_drv); /* release our driver */
1724 printk(KERN_INFO "HFC-S USB: module removed\n");
1730 #ifndef CONFIG_HISAX_DEBUG
1731 unsigned int debug = -1;
1733 char revstr[30], datestr[30], dummy[30];
1734 sscanf(hfcusb_revision,
1735 "%s %s $ %s %s %s $ ", dummy, revstr,
1736 dummy, datestr, dummy);
1738 "HFC-S USB: driver module revision %s date %s loaded, (debug=%i)\n",
1739 revstr, datestr, debug);
1740 if (usb_register(&hfc_drv)) {
1742 "HFC-S USB: Unable to register HFC-S USB module at usb stack\n");
1743 return (-1); /* unable to register */
1748 module_init(hfc_usb_init);
1749 module_exit(hfc_usb_exit);
1750 MODULE_AUTHOR(DRIVER_AUTHOR);
1751 MODULE_DESCRIPTION(DRIVER_DESC);
1752 MODULE_LICENSE("GPL");
1753 MODULE_DEVICE_TABLE(usb, hfcusb_idtab);