aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/isdn/hisax/st5481_d.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/isdn/hisax/st5481_d.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/isdn/hisax/st5481_d.c')
-rw-r--r--drivers/isdn/hisax/st5481_d.c776
1 files changed, 776 insertions, 0 deletions
diff --git a/drivers/isdn/hisax/st5481_d.c b/drivers/isdn/hisax/st5481_d.c
new file mode 100644
index 000000000000..071b1d31999f
--- /dev/null
+++ b/drivers/isdn/hisax/st5481_d.c
@@ -0,0 +1,776 @@
1/*
2 * Driver for ST5481 USB ISDN modem
3 *
4 * Author Frode Isaksen
5 * Copyright 2001 by Frode Isaksen <fisaksen@bewan.com>
6 * 2001 by Kai Germaschewski <kai.germaschewski@gmx.de>
7 *
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
10 *
11 */
12
13#include <linux/init.h>
14#include <linux/usb.h>
15#include <linux/slab.h>
16#include <linux/netdevice.h>
17#include "st5481.h"
18
19static void ph_connect(struct st5481_adapter *adapter);
20static void ph_disconnect(struct st5481_adapter *adapter);
21
22static struct Fsm l1fsm;
23
24static char *strL1State[] =
25{
26 "ST_L1_F3",
27 "ST_L1_F4",
28 "ST_L1_F6",
29 "ST_L1_F7",
30 "ST_L1_F8",
31};
32
33static char *strL1Event[] =
34{
35 "EV_IND_DP",
36 "EV_IND_1",
37 "EV_IND_2",
38 "EV_IND_3",
39 "EV_IND_RSY",
40 "EV_IND_5",
41 "EV_IND_6",
42 "EV_IND_7",
43 "EV_IND_AP",
44 "EV_IND_9",
45 "EV_IND_10",
46 "EV_IND_11",
47 "EV_IND_AI8",
48 "EV_IND_AI10",
49 "EV_IND_AIL",
50 "EV_IND_DI",
51 "EV_PH_ACTIVATE_REQ",
52 "EV_PH_DEACTIVATE_REQ",
53 "EV_TIMER3",
54};
55
56static inline void D_L1L2(struct st5481_adapter *adapter, int pr, void *arg)
57{
58 struct hisax_if *ifc = (struct hisax_if *) &adapter->hisax_d_if;
59
60 ifc->l1l2(ifc, pr, arg);
61}
62
63static void
64l1_go_f3(struct FsmInst *fi, int event, void *arg)
65{
66 struct st5481_adapter *adapter = fi->userdata;
67
68 if (fi->state == ST_L1_F7)
69 ph_disconnect(adapter);
70
71 FsmChangeState(fi, ST_L1_F3);
72 D_L1L2(adapter, PH_DEACTIVATE | INDICATION, NULL);
73}
74
75static void
76l1_go_f6(struct FsmInst *fi, int event, void *arg)
77{
78 struct st5481_adapter *adapter = fi->userdata;
79
80 if (fi->state == ST_L1_F7)
81 ph_disconnect(adapter);
82
83 FsmChangeState(fi, ST_L1_F6);
84}
85
86static void
87l1_go_f7(struct FsmInst *fi, int event, void *arg)
88{
89 struct st5481_adapter *adapter = fi->userdata;
90
91 FsmDelTimer(&adapter->timer, 0);
92 ph_connect(adapter);
93 FsmChangeState(fi, ST_L1_F7);
94 D_L1L2(adapter, PH_ACTIVATE | INDICATION, NULL);
95}
96
97static void
98l1_go_f8(struct FsmInst *fi, int event, void *arg)
99{
100 struct st5481_adapter *adapter = fi->userdata;
101
102 if (fi->state == ST_L1_F7)
103 ph_disconnect(adapter);
104
105 FsmChangeState(fi, ST_L1_F8);
106}
107
108static void
109l1_timer3(struct FsmInst *fi, int event, void *arg)
110{
111 struct st5481_adapter *adapter = fi->userdata;
112
113 st5481_ph_command(adapter, ST5481_CMD_DR);
114 FsmChangeState(fi, ST_L1_F3);
115 D_L1L2(adapter, PH_DEACTIVATE | INDICATION, NULL);
116}
117
118static void
119l1_ignore(struct FsmInst *fi, int event, void *arg)
120{
121}
122
123static void
124l1_activate(struct FsmInst *fi, int event, void *arg)
125{
126 struct st5481_adapter *adapter = fi->userdata;
127
128 st5481_ph_command(adapter, ST5481_CMD_DR);
129 st5481_ph_command(adapter, ST5481_CMD_PUP);
130 FsmRestartTimer(&adapter->timer, TIMER3_VALUE, EV_TIMER3, NULL, 2);
131 st5481_ph_command(adapter, ST5481_CMD_AR8);
132 FsmChangeState(fi, ST_L1_F4);
133}
134
135static struct FsmNode L1FnList[] __initdata =
136{
137 {ST_L1_F3, EV_IND_DP, l1_ignore},
138 {ST_L1_F3, EV_IND_AP, l1_go_f6},
139 {ST_L1_F3, EV_IND_AI8, l1_go_f7},
140 {ST_L1_F3, EV_IND_AI10, l1_go_f7},
141 {ST_L1_F3, EV_PH_ACTIVATE_REQ, l1_activate},
142
143 {ST_L1_F4, EV_TIMER3, l1_timer3},
144 {ST_L1_F4, EV_IND_DP, l1_go_f3},
145 {ST_L1_F4, EV_IND_AP, l1_go_f6},
146 {ST_L1_F4, EV_IND_AI8, l1_go_f7},
147 {ST_L1_F4, EV_IND_AI10, l1_go_f7},
148
149 {ST_L1_F6, EV_TIMER3, l1_timer3},
150 {ST_L1_F6, EV_IND_DP, l1_go_f3},
151 {ST_L1_F6, EV_IND_AP, l1_ignore},
152 {ST_L1_F6, EV_IND_AI8, l1_go_f7},
153 {ST_L1_F6, EV_IND_AI10, l1_go_f7},
154 {ST_L1_F7, EV_IND_RSY, l1_go_f8},
155
156 {ST_L1_F7, EV_IND_DP, l1_go_f3},
157 {ST_L1_F7, EV_IND_AP, l1_go_f6},
158 {ST_L1_F7, EV_IND_AI8, l1_ignore},
159 {ST_L1_F7, EV_IND_AI10, l1_ignore},
160 {ST_L1_F7, EV_IND_RSY, l1_go_f8},
161
162 {ST_L1_F8, EV_TIMER3, l1_timer3},
163 {ST_L1_F8, EV_IND_DP, l1_go_f3},
164 {ST_L1_F8, EV_IND_AP, l1_go_f6},
165 {ST_L1_F8, EV_IND_AI8, l1_go_f8},
166 {ST_L1_F8, EV_IND_AI10, l1_go_f8},
167 {ST_L1_F8, EV_IND_RSY, l1_ignore},
168};
169
170static void l1m_debug(struct FsmInst *fi, char *fmt, ...)
171{
172 va_list args;
173 char buf[256];
174
175 va_start(args, fmt);
176 vsprintf(buf, fmt, args);
177 DBG(8, "%s", buf);
178 va_end(args);
179}
180
181/* ======================================================================
182 * D-Channel out
183 */
184
185/*
186 D OUT state machine:
187 ====================
188
189 Transmit short frame (< 16 bytes of encoded data):
190
191 L1 FRAME D_OUT_STATE USB D CHANNEL
192 -------- ----------- --- ---------
193
194 FIXME
195
196 -> [xx..xx] SHORT_INIT -> [7Exx..xxC1C27EFF]
197 SHORT_WAIT_DEN <> OUT_D_COUNTER=16
198
199 END_OF_SHORT <- DEN_EVENT -> 7Exx
200 xxxx
201 xxxx
202 xxxx
203 xxxx
204 xxxx
205 C1C1
206 7EFF
207 WAIT_FOR_RESET_IDLE <- D_UNDERRUN <- (8ms)
208 IDLE <> Reset pipe
209
210
211
212 Transmit long frame (>= 16 bytes of encoded data):
213
214 L1 FRAME D_OUT_STATE USB D CHANNEL
215 -------- ----------- --- ---------
216
217 -> [xx...xx] IDLE
218 WAIT_FOR_STOP <> OUT_D_COUNTER=0
219 WAIT_FOR_RESET <> Reset pipe
220 STOP
221 INIT_LONG_FRAME -> [7Exx..xx]
222 WAIT_DEN <> OUT_D_COUNTER=16
223 OUT_NORMAL <- DEN_EVENT -> 7Exx
224 END_OF_FRAME_BUSY -> [xxxx] xxxx
225 END_OF_FRAME_NOT_BUSY -> [xxxx] xxxx
226 -> [xxxx] xxxx
227 -> [C1C2] xxxx
228 -> [7EFF] xxxx
229 xxxx
230 xxxx
231 ....
232 xxxx
233 C1C2
234 7EFF
235 <- D_UNDERRUN <- (> 8ms)
236 WAIT_FOR_STOP <> OUT_D_COUNTER=0
237 WAIT_FOR_RESET <> Reset pipe
238 STOP
239
240*/
241
242static struct Fsm dout_fsm;
243
244static char *strDoutState[] =
245{
246 "ST_DOUT_NONE",
247
248 "ST_DOUT_SHORT_INIT",
249 "ST_DOUT_SHORT_WAIT_DEN",
250
251 "ST_DOUT_LONG_INIT",
252 "ST_DOUT_LONG_WAIT_DEN",
253 "ST_DOUT_NORMAL",
254
255 "ST_DOUT_WAIT_FOR_UNDERRUN",
256 "ST_DOUT_WAIT_FOR_NOT_BUSY",
257 "ST_DOUT_WAIT_FOR_STOP",
258 "ST_DOUT_WAIT_FOR_RESET",
259};
260
261static char *strDoutEvent[] =
262{
263 "EV_DOUT_START_XMIT",
264 "EV_DOUT_COMPLETE",
265 "EV_DOUT_DEN",
266 "EV_DOUT_RESETED",
267 "EV_DOUT_STOPPED",
268 "EV_DOUT_COLL",
269 "EV_DOUT_UNDERRUN",
270};
271
272static void dout_debug(struct FsmInst *fi, char *fmt, ...)
273{
274 va_list args;
275 char buf[256];
276
277 va_start(args, fmt);
278 vsprintf(buf, fmt, args);
279 DBG(0x2, "%s", buf);
280 va_end(args);
281}
282
283static void dout_stop_event(void *context)
284{
285 struct st5481_adapter *adapter = context;
286
287 FsmEvent(&adapter->d_out.fsm, EV_DOUT_STOPPED, NULL);
288}
289
290/*
291 * Start the transfer of a D channel frame.
292 */
293static void usb_d_out(struct st5481_adapter *adapter, int buf_nr)
294{
295 struct st5481_d_out *d_out = &adapter->d_out;
296 struct urb *urb;
297 unsigned int num_packets, packet_offset;
298 int len, buf_size, bytes_sent;
299 struct sk_buff *skb;
300 struct usb_iso_packet_descriptor *desc;
301
302 if (d_out->fsm.state != ST_DOUT_NORMAL)
303 return;
304
305 if (test_and_set_bit(buf_nr, &d_out->busy)) {
306 DBG(2, "ep %d urb %d busy %#lx", EP_D_OUT, buf_nr, d_out->busy);
307 return;
308 }
309 urb = d_out->urb[buf_nr];
310
311 skb = d_out->tx_skb;
312
313 buf_size = NUM_ISO_PACKETS_D * SIZE_ISO_PACKETS_D_OUT;
314
315 if (skb) {
316 len = isdnhdlc_encode(&d_out->hdlc_state,
317 skb->data, skb->len, &bytes_sent,
318 urb->transfer_buffer, buf_size);
319 skb_pull(skb,bytes_sent);
320 } else {
321 // Send flags or idle
322 len = isdnhdlc_encode(&d_out->hdlc_state,
323 NULL, 0, &bytes_sent,
324 urb->transfer_buffer, buf_size);
325 }
326
327 if (len < buf_size) {
328 FsmChangeState(&d_out->fsm, ST_DOUT_WAIT_FOR_UNDERRUN);
329 }
330 if (skb && !skb->len) {
331 d_out->tx_skb = NULL;
332 D_L1L2(adapter, PH_DATA | CONFIRM, NULL);
333 dev_kfree_skb_any(skb);
334 }
335
336 // Prepare the URB
337 urb->transfer_buffer_length = len;
338 num_packets = 0;
339 packet_offset = 0;
340 while (packet_offset < len) {
341 desc = &urb->iso_frame_desc[num_packets];
342 desc->offset = packet_offset;
343 desc->length = SIZE_ISO_PACKETS_D_OUT;
344 if (len - packet_offset < desc->length)
345 desc->length = len - packet_offset;
346 num_packets++;
347 packet_offset += desc->length;
348 }
349 urb->number_of_packets = num_packets;
350
351 // Prepare the URB
352 urb->dev = adapter->usb_dev;
353 // Need to transmit the next buffer 2ms after the DEN_EVENT
354 urb->transfer_flags = 0;
355 urb->start_frame = usb_get_current_frame_number(adapter->usb_dev)+2;
356
357 DBG_ISO_PACKET(0x20,urb);
358
359 if (usb_submit_urb(urb, GFP_KERNEL) < 0) {
360 // There is another URB queued up
361 urb->transfer_flags = URB_ISO_ASAP;
362 SUBMIT_URB(urb, GFP_KERNEL);
363 }
364}
365
366static void fifo_reseted(void *context)
367{
368 struct st5481_adapter *adapter = context;
369
370 FsmEvent(&adapter->d_out.fsm, EV_DOUT_RESETED, NULL);
371}
372
373static void usb_d_out_complete(struct urb *urb, struct pt_regs *regs)
374{
375 struct st5481_adapter *adapter = urb->context;
376 struct st5481_d_out *d_out = &adapter->d_out;
377 int buf_nr;
378
379 DBG(2, "");
380
381 buf_nr = get_buf_nr(d_out->urb, urb);
382 test_and_clear_bit(buf_nr, &d_out->busy);
383
384 if (unlikely(urb->status < 0)) {
385 if (urb->status != -ENOENT && urb->status != -ESHUTDOWN) {
386 WARN("urb status %d",urb->status);
387 if (d_out->busy == 0) {
388 st5481_usb_pipe_reset(adapter, EP_D_OUT | USB_DIR_OUT, fifo_reseted, adapter);
389 }
390 return;
391 } else {
392 DBG(1,"urb killed");
393 return; // Give up
394 }
395 }
396
397 FsmEvent(&adapter->d_out.fsm, EV_DOUT_COMPLETE, (void *) buf_nr);
398}
399
400/* ====================================================================== */
401
402static void dout_start_xmit(struct FsmInst *fsm, int event, void *arg)
403{
404 // FIXME unify?
405 struct st5481_adapter *adapter = fsm->userdata;
406 struct st5481_d_out *d_out = &adapter->d_out;
407 struct urb *urb;
408 int len, bytes_sent;
409 struct sk_buff *skb;
410 int buf_nr = 0;
411
412 skb = d_out->tx_skb;
413
414 DBG(2,"len=%d",skb->len);
415
416 isdnhdlc_out_init(&d_out->hdlc_state, 1, 0);
417
418 if (test_and_set_bit(buf_nr, &d_out->busy)) {
419 WARN("ep %d urb %d busy %#lx", EP_D_OUT, buf_nr, d_out->busy);
420 return;
421 }
422 urb = d_out->urb[buf_nr];
423
424 DBG_SKB(0x10, skb);
425 len = isdnhdlc_encode(&d_out->hdlc_state,
426 skb->data, skb->len, &bytes_sent,
427 urb->transfer_buffer, 16);
428 skb_pull(skb, bytes_sent);
429
430 if(len < 16)
431 FsmChangeState(&d_out->fsm, ST_DOUT_SHORT_INIT);
432 else
433 FsmChangeState(&d_out->fsm, ST_DOUT_LONG_INIT);
434
435 if (skb->len == 0) {
436 d_out->tx_skb = NULL;
437 D_L1L2(adapter, PH_DATA | CONFIRM, NULL);
438 dev_kfree_skb_any(skb);
439 }
440
441// Prepare the URB
442 urb->transfer_buffer_length = len;
443
444 urb->iso_frame_desc[0].offset = 0;
445 urb->iso_frame_desc[0].length = len;
446 urb->number_of_packets = 1;
447
448 // Prepare the URB
449 urb->dev = adapter->usb_dev;
450 urb->transfer_flags = URB_ISO_ASAP;
451
452 DBG_ISO_PACKET(0x20,urb);
453 SUBMIT_URB(urb, GFP_KERNEL);
454}
455
456static void dout_short_fifo(struct FsmInst *fsm, int event, void *arg)
457{
458 struct st5481_adapter *adapter = fsm->userdata;
459 struct st5481_d_out *d_out = &adapter->d_out;
460
461 FsmChangeState(&d_out->fsm, ST_DOUT_SHORT_WAIT_DEN);
462 st5481_usb_device_ctrl_msg(adapter, OUT_D_COUNTER, 16, NULL, NULL);
463}
464
465static void dout_end_short_frame(struct FsmInst *fsm, int event, void *arg)
466{
467 struct st5481_adapter *adapter = fsm->userdata;
468 struct st5481_d_out *d_out = &adapter->d_out;
469
470 FsmChangeState(&d_out->fsm, ST_DOUT_WAIT_FOR_UNDERRUN);
471}
472
473static void dout_long_enable_fifo(struct FsmInst *fsm, int event, void *arg)
474{
475 struct st5481_adapter *adapter = fsm->userdata;
476 struct st5481_d_out *d_out = &adapter->d_out;
477
478 st5481_usb_device_ctrl_msg(adapter, OUT_D_COUNTER, 16, NULL, NULL);
479 FsmChangeState(&d_out->fsm, ST_DOUT_LONG_WAIT_DEN);
480}
481
482static void dout_long_den(struct FsmInst *fsm, int event, void *arg)
483{
484 struct st5481_adapter *adapter = fsm->userdata;
485 struct st5481_d_out *d_out = &adapter->d_out;
486
487 FsmChangeState(&d_out->fsm, ST_DOUT_NORMAL);
488 usb_d_out(adapter, 0);
489 usb_d_out(adapter, 1);
490}
491
492static void dout_reset(struct FsmInst *fsm, int event, void *arg)
493{
494 struct st5481_adapter *adapter = fsm->userdata;
495 struct st5481_d_out *d_out = &adapter->d_out;
496
497 FsmChangeState(&d_out->fsm, ST_DOUT_WAIT_FOR_RESET);
498 st5481_usb_pipe_reset(adapter, EP_D_OUT | USB_DIR_OUT, fifo_reseted, adapter);
499}
500
501static void dout_stop(struct FsmInst *fsm, int event, void *arg)
502{
503 struct st5481_adapter *adapter = fsm->userdata;
504 struct st5481_d_out *d_out = &adapter->d_out;
505
506 FsmChangeState(&d_out->fsm, ST_DOUT_WAIT_FOR_STOP);
507 st5481_usb_device_ctrl_msg(adapter, OUT_D_COUNTER, 0, dout_stop_event, adapter);
508}
509
510static void dout_underrun(struct FsmInst *fsm, int event, void *arg)
511{
512 struct st5481_adapter *adapter = fsm->userdata;
513 struct st5481_d_out *d_out = &adapter->d_out;
514
515 if (test_bit(0, &d_out->busy) || test_bit(1, &d_out->busy)) {
516 FsmChangeState(&d_out->fsm, ST_DOUT_WAIT_FOR_NOT_BUSY);
517 } else {
518 dout_stop(fsm, event, arg);
519 }
520}
521
522static void dout_check_busy(struct FsmInst *fsm, int event, void *arg)
523{
524 struct st5481_adapter *adapter = fsm->userdata;
525 struct st5481_d_out *d_out = &adapter->d_out;
526
527 if (!test_bit(0, &d_out->busy) && !test_bit(1, &d_out->busy))
528 dout_stop(fsm, event, arg);
529}
530
531static void dout_reseted(struct FsmInst *fsm, int event, void *arg)
532{
533 struct st5481_adapter *adapter = fsm->userdata;
534 struct st5481_d_out *d_out = &adapter->d_out;
535
536 FsmChangeState(&d_out->fsm, ST_DOUT_NONE);
537 // FIXME locking
538 if (d_out->tx_skb)
539 FsmEvent(&d_out->fsm, EV_DOUT_START_XMIT, NULL);
540}
541
542static void dout_complete(struct FsmInst *fsm, int event, void *arg)
543{
544 struct st5481_adapter *adapter = fsm->userdata;
545 int buf_nr = (int) arg;
546
547 usb_d_out(adapter, buf_nr);
548}
549
550static void dout_ignore(struct FsmInst *fsm, int event, void *arg)
551{
552}
553
554static struct FsmNode DoutFnList[] __initdata =
555{
556 {ST_DOUT_NONE, EV_DOUT_START_XMIT, dout_start_xmit},
557
558 {ST_DOUT_SHORT_INIT, EV_DOUT_COMPLETE, dout_short_fifo},
559
560 {ST_DOUT_SHORT_WAIT_DEN, EV_DOUT_DEN, dout_end_short_frame},
561 {ST_DOUT_SHORT_WAIT_DEN, EV_DOUT_UNDERRUN, dout_underrun},
562
563 {ST_DOUT_LONG_INIT, EV_DOUT_COMPLETE, dout_long_enable_fifo},
564
565 {ST_DOUT_LONG_WAIT_DEN, EV_DOUT_DEN, dout_long_den},
566 {ST_DOUT_LONG_WAIT_DEN, EV_DOUT_UNDERRUN, dout_underrun},
567
568 {ST_DOUT_NORMAL, EV_DOUT_UNDERRUN, dout_underrun},
569 {ST_DOUT_NORMAL, EV_DOUT_COMPLETE, dout_complete},
570
571 {ST_DOUT_WAIT_FOR_UNDERRUN, EV_DOUT_UNDERRUN, dout_underrun},
572 {ST_DOUT_WAIT_FOR_UNDERRUN, EV_DOUT_COMPLETE, dout_ignore},
573
574 {ST_DOUT_WAIT_FOR_NOT_BUSY, EV_DOUT_COMPLETE, dout_check_busy},
575
576 {ST_DOUT_WAIT_FOR_STOP, EV_DOUT_STOPPED, dout_reset},
577
578 {ST_DOUT_WAIT_FOR_RESET, EV_DOUT_RESETED, dout_reseted},
579};
580
581void st5481_d_l2l1(struct hisax_if *hisax_d_if, int pr, void *arg)
582{
583 struct st5481_adapter *adapter = hisax_d_if->priv;
584 struct sk_buff *skb = arg;
585
586 switch (pr) {
587 case PH_ACTIVATE | REQUEST:
588 FsmEvent(&adapter->l1m, EV_PH_ACTIVATE_REQ, NULL);
589 break;
590 case PH_DEACTIVATE | REQUEST:
591 FsmEvent(&adapter->l1m, EV_PH_DEACTIVATE_REQ, NULL);
592 break;
593 case PH_DATA | REQUEST:
594 DBG(2, "PH_DATA REQUEST len %d", skb->len);
595 if (adapter->d_out.tx_skb)
596 BUG();
597
598 adapter->d_out.tx_skb = skb;
599 FsmEvent(&adapter->d_out.fsm, EV_DOUT_START_XMIT, NULL);
600 break;
601 default:
602 WARN("pr %#x\n", pr);
603 break;
604 }
605}
606
607/* ======================================================================
608 */
609
610/*
611 * Start receiving on the D channel since entered state F7.
612 */
613static void ph_connect(struct st5481_adapter *adapter)
614{
615 struct st5481_d_out *d_out = &adapter->d_out;
616 struct st5481_in *d_in = &adapter->d_in;
617
618 DBG(8,"");
619
620 FsmChangeState(&d_out->fsm, ST_DOUT_NONE);
621
622 // st5481_usb_device_ctrl_msg(adapter, FFMSK_D, OUT_UNDERRUN, NULL, NULL);
623 st5481_usb_device_ctrl_msg(adapter, FFMSK_D, 0xfc, NULL, NULL);
624 st5481_in_mode(d_in, L1_MODE_HDLC);
625
626#ifdef LOOPBACK
627 // Turn loopback on (data sent on B and D looped back)
628 st5481_usb_device_ctrl_msg(cs, LBB, 0x04, NULL, NULL);
629#endif
630
631 st5481_usb_pipe_reset(adapter, EP_D_OUT | USB_DIR_OUT, NULL, NULL);
632
633 // Turn on the green LED to tell that we are in state F7
634 adapter->leds |= GREEN_LED;
635 st5481_usb_device_ctrl_msg(adapter, GPIO_OUT, adapter->leds, NULL, NULL);
636}
637
638/*
639 * Stop receiving on the D channel since not in state F7.
640 */
641static void ph_disconnect(struct st5481_adapter *adapter)
642{
643 DBG(8,"");
644
645 st5481_in_mode(&adapter->d_in, L1_MODE_NULL);
646
647 // Turn off the green LED to tell that we left state F7
648 adapter->leds &= ~GREEN_LED;
649 st5481_usb_device_ctrl_msg(adapter, GPIO_OUT, adapter->leds, NULL, NULL);
650}
651
652static int st5481_setup_d_out(struct st5481_adapter *adapter)
653{
654 struct usb_device *dev = adapter->usb_dev;
655 struct usb_interface *intf;
656 struct usb_host_interface *altsetting = NULL;
657 struct usb_host_endpoint *endpoint;
658 struct st5481_d_out *d_out = &adapter->d_out;
659
660 DBG(2,"");
661
662 intf = usb_ifnum_to_if(dev, 0);
663 if (intf)
664 altsetting = usb_altnum_to_altsetting(intf, 3);
665 if (!altsetting)
666 return -ENXIO;
667
668 // Allocate URBs and buffers for the D channel out
669 endpoint = &altsetting->endpoint[EP_D_OUT-1];
670
671 DBG(2,"endpoint address=%02x,packet size=%d",
672 endpoint->desc.bEndpointAddress, le16_to_cpu(endpoint->desc.wMaxPacketSize));
673
674 return st5481_setup_isocpipes(d_out->urb, dev,
675 usb_sndisocpipe(dev, endpoint->desc.bEndpointAddress),
676 NUM_ISO_PACKETS_D, SIZE_ISO_PACKETS_D_OUT,
677 NUM_ISO_PACKETS_D * SIZE_ISO_PACKETS_D_OUT,
678 usb_d_out_complete, adapter);
679}
680
681static void st5481_release_d_out(struct st5481_adapter *adapter)
682{
683 struct st5481_d_out *d_out = &adapter->d_out;
684
685 DBG(2,"");
686
687 st5481_release_isocpipes(d_out->urb);
688}
689
690int st5481_setup_d(struct st5481_adapter *adapter)
691{
692 int retval;
693
694 DBG(2,"");
695
696 retval = st5481_setup_d_out(adapter);
697 if (retval)
698 goto err;
699 adapter->d_in.bufsize = MAX_DFRAME_LEN_L1;
700 adapter->d_in.num_packets = NUM_ISO_PACKETS_D;
701 adapter->d_in.packet_size = SIZE_ISO_PACKETS_D_IN;
702 adapter->d_in.ep = EP_D_IN | USB_DIR_IN;
703 adapter->d_in.counter = IN_D_COUNTER;
704 adapter->d_in.adapter = adapter;
705 adapter->d_in.hisax_if = &adapter->hisax_d_if.ifc;
706 retval = st5481_setup_in(&adapter->d_in);
707 if (retval)
708 goto err_d_out;
709
710 adapter->l1m.fsm = &l1fsm;
711 adapter->l1m.state = ST_L1_F3;
712 adapter->l1m.debug = 1;
713 adapter->l1m.userdata = adapter;
714 adapter->l1m.printdebug = l1m_debug;
715 FsmInitTimer(&adapter->l1m, &adapter->timer);
716
717 adapter->d_out.fsm.fsm = &dout_fsm;
718 adapter->d_out.fsm.state = ST_DOUT_NONE;
719 adapter->d_out.fsm.debug = 1;
720 adapter->d_out.fsm.userdata = adapter;
721 adapter->d_out.fsm.printdebug = dout_debug;
722
723 return 0;
724
725 err_d_out:
726 st5481_release_d_out(adapter);
727 err:
728 return retval;
729}
730
731void st5481_release_d(struct st5481_adapter *adapter)
732{
733 DBG(2,"");
734
735 st5481_release_in(&adapter->d_in);
736 st5481_release_d_out(adapter);
737}
738
739/* ======================================================================
740 * init / exit
741 */
742
743int __init st5481_d_init(void)
744{
745 int retval;
746
747 l1fsm.state_count = L1_STATE_COUNT;
748 l1fsm.event_count = L1_EVENT_COUNT;
749 l1fsm.strEvent = strL1Event;
750 l1fsm.strState = strL1State;
751 retval = FsmNew(&l1fsm, L1FnList, ARRAY_SIZE(L1FnList));
752 if (retval)
753 goto err;
754
755 dout_fsm.state_count = DOUT_STATE_COUNT;
756 dout_fsm.event_count = DOUT_EVENT_COUNT;
757 dout_fsm.strEvent = strDoutEvent;
758 dout_fsm.strState = strDoutState;
759 retval = FsmNew(&dout_fsm, DoutFnList, ARRAY_SIZE(DoutFnList));
760 if (retval)
761 goto err_l1;
762
763 return 0;
764
765 err_l1:
766 FsmFree(&l1fsm);
767 err:
768 return retval;
769}
770
771// can't be __exit
772void st5481_d_exit(void)
773{
774 FsmFree(&l1fsm);
775 FsmFree(&dout_fsm);
776}