1 /* $Id: w6692.c,v 1.18.2.4 2004/02/11 13:21:34 keil Exp $
3 * Winbond W6692 specific routines
6 * Copyright by Petr Novak <petr.novak@i.cz>
8 * This software may be used and distributed according to the terms
9 * of the GNU General Public License, incorporated herein by reference.
13 #include <linux/init.h>
17 #include <linux/interrupt.h>
18 #include <linux/pci.h>
20 /* table entry in the PCI devices list */
28 static const PCI_ENTRY id_list[] =
30 {PCI_VENDOR_ID_WINBOND2, PCI_DEVICE_ID_WINBOND2_6692, "Winbond", "W6692"},
31 {PCI_VENDOR_ID_DYNALINK, PCI_DEVICE_ID_DYNALINK_IS64PH, "Dynalink/AsusCom", "IS64PH"},
32 {0, 0, "U.S.Robotics", "ISDN PCI Card TA"}
35 #define W6692_SV_USR 0x16ec
36 #define W6692_SD_USR 0x3409
37 #define W6692_WINBOND 0
38 #define W6692_DYNALINK 1
41 extern const char *CardType[];
43 static const char *w6692_revision = "$Revision: 1.18.2.4 $";
45 #define DBUSY_TIMER_VALUE 80
47 static char *W6692Ver[] =
48 {"W6692 V00", "W6692 V01", "W6692 V10",
52 W6692Version(struct IsdnCardState *cs, char *s)
56 val = cs->readW6692(cs, W_D_RBCH);
57 printk(KERN_INFO "%s Winbond W6692 version (%x): %s\n", s, val, W6692Ver[(val >> 6) & 3]);
61 ph_command(struct IsdnCardState *cs, unsigned int command)
63 if (cs->debug & L1_DEB_ISAC)
64 debugl1(cs, "ph_command %x", command);
65 cs->writeisac(cs, W_CIX, command);
70 W6692_new_ph(struct IsdnCardState *cs)
72 switch (cs->dc.w6692.ph_state) {
74 ph_command(cs, W_L1CMD_DRC);
75 l1_msg(cs, HW_RESET | INDICATION, NULL);
78 l1_msg(cs, HW_DEACTIVATE | CONFIRM, NULL);
81 l1_msg(cs, HW_DEACTIVATE | INDICATION, NULL);
84 l1_msg(cs, HW_POWERUP | CONFIRM, NULL);
87 l1_msg(cs, HW_RSYNC | INDICATION, NULL);
90 l1_msg(cs, HW_INFO2 | INDICATION, NULL);
93 l1_msg(cs, HW_INFO4_P8 | INDICATION, NULL);
96 l1_msg(cs, HW_INFO4_P10 | INDICATION, NULL);
104 W6692_bh(struct work_struct *work)
106 struct IsdnCardState *cs =
107 container_of(work, struct IsdnCardState, tqueue);
108 struct PStack *stptr;
112 if (test_and_clear_bit(D_CLEARBUSY, &cs->event)) {
114 debugl1(cs, "D-Channel Busy cleared");
116 while (stptr != NULL) {
117 stptr->l1.l1l2(stptr, PH_PAUSE | CONFIRM, NULL);
121 if (test_and_clear_bit(D_L1STATECHANGE, &cs->event))
123 if (test_and_clear_bit(D_RCVBUFREADY, &cs->event))
124 DChannel_proc_rcv(cs);
125 if (test_and_clear_bit(D_XMTBUFREADY, &cs->event))
126 DChannel_proc_xmt(cs);
128 if (test_and_clear_bit(D_RX_MON1, &cs->event))
129 arcofi_fsm(cs, ARCOFI_RX_END, NULL);
130 if (test_and_clear_bit(D_TX_MON1, &cs->event))
131 arcofi_fsm(cs, ARCOFI_TX_END, NULL);
136 W6692_empty_fifo(struct IsdnCardState *cs, int count)
140 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
141 debugl1(cs, "W6692_empty_fifo");
143 if ((cs->rcvidx + count) >= MAX_DFRAME_LEN_L1) {
144 if (cs->debug & L1_DEB_WARN)
145 debugl1(cs, "W6692_empty_fifo overrun %d",
147 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_RACK);
151 ptr = cs->rcvbuf + cs->rcvidx;
153 cs->readW6692fifo(cs, ptr, count);
154 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_RACK);
155 if (cs->debug & L1_DEB_ISAC_FIFO) {
158 t += sprintf(t, "W6692_empty_fifo cnt %d", count);
159 QuickHex(t, ptr, count);
160 debugl1(cs, cs->dlog);
165 W6692_fill_fifo(struct IsdnCardState *cs)
170 if ((cs->debug & L1_DEB_ISAC) && !(cs->debug & L1_DEB_ISAC_FIFO))
171 debugl1(cs, "W6692_fill_fifo");
176 count = cs->tx_skb->len;
181 if (count > W_D_FIFO_THRESH) {
183 count = W_D_FIFO_THRESH;
185 ptr = cs->tx_skb->data;
186 skb_pull(cs->tx_skb, count);
188 cs->writeW6692fifo(cs, ptr, count);
189 cs->writeW6692(cs, W_D_CMDR, more ? W_D_CMDR_XMS : (W_D_CMDR_XMS | W_D_CMDR_XME));
190 if (test_and_set_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
191 debugl1(cs, "W6692_fill_fifo dbusytimer running");
192 del_timer(&cs->dbusytimer);
194 init_timer(&cs->dbusytimer);
195 cs->dbusytimer.expires = jiffies + ((DBUSY_TIMER_VALUE * HZ) / 1000);
196 add_timer(&cs->dbusytimer);
197 if (cs->debug & L1_DEB_ISAC_FIFO) {
200 t += sprintf(t, "W6692_fill_fifo cnt %d", count);
201 QuickHex(t, ptr, count);
202 debugl1(cs, cs->dlog);
207 W6692B_empty_fifo(struct BCState *bcs, int count)
210 struct IsdnCardState *cs = bcs->cs;
212 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
213 debugl1(cs, "W6692B_empty_fifo");
215 if (bcs->hw.w6692.rcvidx + count > HSCX_BUFMAX) {
216 if (cs->debug & L1_DEB_WARN)
217 debugl1(cs, "W6692B_empty_fifo: incoming packet too large");
218 cs->BC_Write_Reg(cs, bcs->channel, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT);
219 bcs->hw.w6692.rcvidx = 0;
222 ptr = bcs->hw.w6692.rcvbuf + bcs->hw.w6692.rcvidx;
223 bcs->hw.w6692.rcvidx += count;
224 READW6692BFIFO(cs, bcs->channel, ptr, count);
225 cs->BC_Write_Reg(cs, bcs->channel, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RACT);
226 if (cs->debug & L1_DEB_HSCX_FIFO) {
229 t += sprintf(t, "W6692B_empty_fifo %c cnt %d",
230 bcs->channel + '1', count);
231 QuickHex(t, ptr, count);
232 debugl1(cs, bcs->blog);
237 W6692B_fill_fifo(struct BCState *bcs)
239 struct IsdnCardState *cs = bcs->cs;
245 if (bcs->tx_skb->len <= 0)
248 more = (bcs->mode == L1_MODE_TRANS) ? 1 : 0;
249 if (bcs->tx_skb->len > W_B_FIFO_THRESH) {
251 count = W_B_FIFO_THRESH;
253 count = bcs->tx_skb->len;
255 if ((cs->debug & L1_DEB_HSCX) && !(cs->debug & L1_DEB_HSCX_FIFO))
256 debugl1(cs, "W6692B_fill_fifo%s%d", (more ? " ": " last "), count);
258 ptr = bcs->tx_skb->data;
259 skb_pull(bcs->tx_skb, count);
260 bcs->tx_cnt -= count;
261 bcs->hw.w6692.count += count;
262 WRITEW6692BFIFO(cs, bcs->channel, ptr, count);
263 cs->BC_Write_Reg(cs, bcs->channel, W_B_CMDR, W_B_CMDR_RACT | W_B_CMDR_XMS | (more ? 0 : W_B_CMDR_XME));
264 if (cs->debug & L1_DEB_HSCX_FIFO) {
267 t += sprintf(t, "W6692B_fill_fifo %c cnt %d",
268 bcs->channel + '1', count);
269 QuickHex(t, ptr, count);
270 debugl1(cs, bcs->blog);
275 W6692B_interrupt(struct IsdnCardState *cs, u_char bchan)
283 bcs = (cs->bcs->channel == bchan) ? cs->bcs : (cs->bcs+1);
284 val = cs->BC_Read_Reg(cs, bchan, W_B_EXIR);
285 debugl1(cs, "W6692B chan %d B_EXIR 0x%02X", bchan, val);
287 if (!test_bit(BC_FLG_INIT, &bcs->Flag)) {
288 debugl1(cs, "W6692B not INIT yet");
291 if (val & W_B_EXI_RME) { /* RME */
292 r = cs->BC_Read_Reg(cs, bchan, W_B_STAR);
293 if (r & (W_B_STAR_RDOV | W_B_STAR_CRCE | W_B_STAR_RMB)) {
294 if (cs->debug & L1_DEB_WARN)
295 debugl1(cs, "W6692 B STAR %x", r);
296 if ((r & W_B_STAR_RDOV) && bcs->mode)
297 if (cs->debug & L1_DEB_WARN)
298 debugl1(cs, "W6692 B RDOV mode=%d",
300 if (r & W_B_STAR_CRCE)
301 if (cs->debug & L1_DEB_WARN)
302 debugl1(cs, "W6692 B CRC error");
303 cs->BC_Write_Reg(cs, bchan, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RRST | W_B_CMDR_RACT);
305 count = cs->BC_Read_Reg(cs, bchan, W_B_RBCL) & (W_B_FIFO_THRESH - 1);
307 count = W_B_FIFO_THRESH;
308 W6692B_empty_fifo(bcs, count);
309 if ((count = bcs->hw.w6692.rcvidx) > 0) {
310 if (cs->debug & L1_DEB_HSCX_FIFO)
311 debugl1(cs, "W6692 Bchan Frame %d", count);
312 if (!(skb = dev_alloc_skb(count)))
313 printk(KERN_WARNING "W6692: Bchan receive out of memory\n");
315 memcpy(skb_put(skb, count), bcs->hw.w6692.rcvbuf, count);
316 skb_queue_tail(&bcs->rqueue, skb);
320 bcs->hw.w6692.rcvidx = 0;
321 schedule_event(bcs, B_RCVBUFREADY);
323 if (val & W_B_EXI_RMR) { /* RMR */
324 W6692B_empty_fifo(bcs, W_B_FIFO_THRESH);
325 r = cs->BC_Read_Reg(cs, bchan, W_B_STAR);
326 if (r & W_B_STAR_RDOV) {
327 if (cs->debug & L1_DEB_WARN)
328 debugl1(cs, "W6692 B RDOV(RMR) mode=%d",bcs->mode);
329 cs->BC_Write_Reg(cs, bchan, W_B_CMDR, W_B_CMDR_RACK | W_B_CMDR_RRST | W_B_CMDR_RACT);
330 if (bcs->mode != L1_MODE_TRANS)
331 bcs->hw.w6692.rcvidx = 0;
333 if (bcs->mode == L1_MODE_TRANS) {
334 /* receive audio data */
335 if (!(skb = dev_alloc_skb(W_B_FIFO_THRESH)))
336 printk(KERN_WARNING "HiSax: receive out of memory\n");
338 memcpy(skb_put(skb, W_B_FIFO_THRESH), bcs->hw.w6692.rcvbuf, W_B_FIFO_THRESH);
339 skb_queue_tail(&bcs->rqueue, skb);
341 bcs->hw.w6692.rcvidx = 0;
342 schedule_event(bcs, B_RCVBUFREADY);
345 if (val & W_B_EXI_XDUN) { /* XDUN */
346 cs->BC_Write_Reg(cs, bchan, W_B_CMDR, W_B_CMDR_XRST | W_B_CMDR_RACT);
347 if (cs->debug & L1_DEB_WARN)
348 debugl1(cs, "W6692 B EXIR %x Lost TX", val);
350 W6692B_fill_fifo(bcs);
352 /* Here we lost an TX interrupt, so
353 * restart transmitting the whole frame.
356 skb_push(bcs->tx_skb, bcs->hw.w6692.count);
357 bcs->tx_cnt += bcs->hw.w6692.count;
358 bcs->hw.w6692.count = 0;
363 if (val & W_B_EXI_XFR) { /* XFR */
364 r = cs->BC_Read_Reg(cs, bchan, W_B_STAR);
365 if (r & W_B_STAR_XDOW) {
366 if (cs->debug & L1_DEB_WARN)
367 debugl1(cs, "W6692 B STAR %x XDOW", r);
368 cs->BC_Write_Reg(cs, bchan, W_B_CMDR, W_B_CMDR_XRST | W_B_CMDR_RACT);
369 if (bcs->tx_skb && (bcs->mode != 1)) {
370 skb_push(bcs->tx_skb, bcs->hw.w6692.count);
371 bcs->tx_cnt += bcs->hw.w6692.count;
372 bcs->hw.w6692.count = 0;
376 if (bcs->tx_skb->len) {
377 W6692B_fill_fifo(bcs);
380 if (test_bit(FLG_LLI_L1WAKEUP,&bcs->st->lli.flag) &&
381 (PACKET_NOACK != bcs->tx_skb->pkt_type)) {
383 spin_lock_irqsave(&bcs->aclock, flags);
384 bcs->ackcnt += bcs->hw.w6692.count;
385 spin_unlock_irqrestore(&bcs->aclock, flags);
386 schedule_event(bcs, B_ACKPENDING);
388 dev_kfree_skb_irq(bcs->tx_skb);
389 bcs->hw.w6692.count = 0;
393 if ((bcs->tx_skb = skb_dequeue(&bcs->squeue))) {
394 bcs->hw.w6692.count = 0;
395 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
396 W6692B_fill_fifo(bcs);
398 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
399 schedule_event(bcs, B_XMTBUFREADY);
405 W6692_interrupt(int intno, void *dev_id)
407 struct IsdnCardState *cs = dev_id;
408 u_char val, exval, v1;
414 spin_lock_irqsave(&cs->lock, flags);
415 val = cs->readW6692(cs, W_ISTA);
417 spin_unlock_irqrestore(&cs->lock, flags);
421 if (cs->debug & L1_DEB_ISAC)
422 debugl1(cs, "W6692 ISTA %x", val);
424 if (val & W_INT_D_RME) { /* RME */
425 exval = cs->readW6692(cs, W_D_RSTA);
426 if (exval & (W_D_RSTA_RDOV | W_D_RSTA_CRCE | W_D_RSTA_RMB)) {
427 if (exval & W_D_RSTA_RDOV)
428 if (cs->debug & L1_DEB_WARN)
429 debugl1(cs, "W6692 RDOV");
430 if (exval & W_D_RSTA_CRCE)
431 if (cs->debug & L1_DEB_WARN)
432 debugl1(cs, "W6692 D-channel CRC error");
433 if (exval & W_D_RSTA_RMB)
434 if (cs->debug & L1_DEB_WARN)
435 debugl1(cs, "W6692 D-channel ABORT");
436 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_RACK | W_D_CMDR_RRST);
438 count = cs->readW6692(cs, W_D_RBCL) & (W_D_FIFO_THRESH - 1);
440 count = W_D_FIFO_THRESH;
441 W6692_empty_fifo(cs, count);
442 if ((count = cs->rcvidx) > 0) {
444 if (!(skb = alloc_skb(count, GFP_ATOMIC)))
445 printk(KERN_WARNING "HiSax: D receive out of memory\n");
447 memcpy(skb_put(skb, count), cs->rcvbuf, count);
448 skb_queue_tail(&cs->rq, skb);
453 schedule_event(cs, D_RCVBUFREADY);
455 if (val & W_INT_D_RMR) { /* RMR */
456 W6692_empty_fifo(cs, W_D_FIFO_THRESH);
458 if (val & W_INT_D_XFR) { /* XFR */
459 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
460 del_timer(&cs->dbusytimer);
461 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
462 schedule_event(cs, D_CLEARBUSY);
464 if (cs->tx_skb->len) {
468 dev_kfree_skb_irq(cs->tx_skb);
473 if ((cs->tx_skb = skb_dequeue(&cs->sq))) {
477 schedule_event(cs, D_XMTBUFREADY);
480 if (val & (W_INT_XINT0 | W_INT_XINT1)) { /* XINT0/1 - never */
481 if (cs->debug & L1_DEB_ISAC)
482 debugl1(cs, "W6692 spurious XINT!");
484 if (val & W_INT_D_EXI) { /* EXI */
485 exval = cs->readW6692(cs, W_D_EXIR);
486 if (cs->debug & L1_DEB_WARN)
487 debugl1(cs, "W6692 D_EXIR %02x", exval);
488 if (exval & (W_D_EXI_XDUN | W_D_EXI_XCOL)) { /* Transmit underrun/collision */
489 debugl1(cs, "W6692 D-chan underrun/collision");
490 printk(KERN_WARNING "HiSax: W6692 XDUN/XCOL\n");
491 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
492 del_timer(&cs->dbusytimer);
493 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
494 schedule_event(cs, D_CLEARBUSY);
495 if (cs->tx_skb) { /* Restart frame */
496 skb_push(cs->tx_skb, cs->tx_cnt);
500 printk(KERN_WARNING "HiSax: W6692 XDUN/XCOL no skb\n");
501 debugl1(cs, "W6692 XDUN/XCOL no skb");
502 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_XRST);
505 if (exval & W_D_EXI_RDOV) { /* RDOV */
506 debugl1(cs, "W6692 D-channel RDOV");
507 printk(KERN_WARNING "HiSax: W6692 D-RDOV\n");
508 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_RRST);
510 if (exval & W_D_EXI_TIN2) { /* TIN2 - never */
511 debugl1(cs, "W6692 spurious TIN2 interrupt");
513 if (exval & W_D_EXI_MOC) { /* MOC - not supported */
514 debugl1(cs, "W6692 spurious MOC interrupt");
515 v1 = cs->readW6692(cs, W_MOSR);
516 debugl1(cs, "W6692 MOSR %02x", v1);
518 if (exval & W_D_EXI_ISC) { /* ISC - Level1 change */
519 v1 = cs->readW6692(cs, W_CIR);
520 if (cs->debug & L1_DEB_ISAC)
521 debugl1(cs, "W6692 ISC CIR=0x%02X", v1);
522 if (v1 & W_CIR_ICC) {
523 cs->dc.w6692.ph_state = v1 & W_CIR_COD_MASK;
524 if (cs->debug & L1_DEB_ISAC)
525 debugl1(cs, "ph_state_change %x", cs->dc.w6692.ph_state);
526 schedule_event(cs, D_L1STATECHANGE);
528 if (v1 & W_CIR_SCC) {
529 v1 = cs->readW6692(cs, W_SQR);
530 debugl1(cs, "W6692 SCC SQR=0x%02X", v1);
533 if (exval & W_D_EXI_WEXP) {
534 debugl1(cs, "W6692 spurious WEXP interrupt!");
536 if (exval & W_D_EXI_TEXP) {
537 debugl1(cs, "W6692 spurious TEXP interrupt!");
540 if (val & W_INT_B1_EXI) {
541 debugl1(cs, "W6692 B channel 1 interrupt");
542 W6692B_interrupt(cs, 0);
544 if (val & W_INT_B2_EXI) {
545 debugl1(cs, "W6692 B channel 2 interrupt");
546 W6692B_interrupt(cs, 1);
548 val = cs->readW6692(cs, W_ISTA);
554 printk(KERN_WARNING "W6692 IRQ LOOP\n");
555 cs->writeW6692(cs, W_IMASK, 0xff);
557 spin_unlock_irqrestore(&cs->lock, flags);
562 W6692_l1hw(struct PStack *st, int pr, void *arg)
564 struct IsdnCardState *cs = (struct IsdnCardState *) st->l1.hardware;
565 struct sk_buff *skb = arg;
570 case (PH_DATA | REQUEST):
571 if (cs->debug & DEB_DLOG_HEX)
572 LogFrame(cs, skb->data, skb->len);
573 if (cs->debug & DEB_DLOG_VERBOSE)
574 dlogframe(cs, skb, 0);
575 spin_lock_irqsave(&cs->lock, flags);
577 skb_queue_tail(&cs->sq, skb);
578 #ifdef L2FRAME_DEBUG /* psa */
579 if (cs->debug & L1_DEB_LAPD)
580 Logl2Frame(cs, skb, "PH_DATA Queued", 0);
585 #ifdef L2FRAME_DEBUG /* psa */
586 if (cs->debug & L1_DEB_LAPD)
587 Logl2Frame(cs, skb, "PH_DATA", 0);
591 spin_unlock_irqrestore(&cs->lock, flags);
593 case (PH_PULL | INDICATION):
594 spin_lock_irqsave(&cs->lock, flags);
596 if (cs->debug & L1_DEB_WARN)
597 debugl1(cs, " l2l1 tx_skb exist this shouldn't happen");
598 skb_queue_tail(&cs->sq, skb);
599 spin_unlock_irqrestore(&cs->lock, flags);
602 if (cs->debug & DEB_DLOG_HEX)
603 LogFrame(cs, skb->data, skb->len);
604 if (cs->debug & DEB_DLOG_VERBOSE)
605 dlogframe(cs, skb, 0);
608 #ifdef L2FRAME_DEBUG /* psa */
609 if (cs->debug & L1_DEB_LAPD)
610 Logl2Frame(cs, skb, "PH_DATA_PULLED", 0);
613 spin_unlock_irqrestore(&cs->lock, flags);
615 case (PH_PULL | REQUEST):
616 #ifdef L2FRAME_DEBUG /* psa */
617 if (cs->debug & L1_DEB_LAPD)
618 debugl1(cs, "-> PH_REQUEST_PULL");
621 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
622 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
624 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
626 case (HW_RESET | REQUEST):
627 spin_lock_irqsave(&cs->lock, flags);
628 if ((cs->dc.w6692.ph_state == W_L1IND_DRD)) {
629 ph_command(cs, W_L1CMD_ECK);
630 spin_unlock_irqrestore(&cs->lock, flags);
632 ph_command(cs, W_L1CMD_RST);
633 cs->dc.w6692.ph_state = W_L1CMD_RST;
634 spin_unlock_irqrestore(&cs->lock, flags);
638 case (HW_ENABLE | REQUEST):
639 spin_lock_irqsave(&cs->lock, flags);
640 ph_command(cs, W_L1CMD_ECK);
641 spin_unlock_irqrestore(&cs->lock, flags);
643 case (HW_INFO3 | REQUEST):
644 spin_lock_irqsave(&cs->lock, flags);
645 ph_command(cs, W_L1CMD_AR8);
646 spin_unlock_irqrestore(&cs->lock, flags);
648 case (HW_TESTLOOP | REQUEST):
654 /* !!! not implemented yet */
656 case (HW_DEACTIVATE | RESPONSE):
657 skb_queue_purge(&cs->rq);
658 skb_queue_purge(&cs->sq);
660 dev_kfree_skb_any(cs->tx_skb);
663 if (test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags))
664 del_timer(&cs->dbusytimer);
665 if (test_and_clear_bit(FLG_L1_DBUSY, &cs->HW_Flags))
666 schedule_event(cs, D_CLEARBUSY);
669 if (cs->debug & L1_DEB_WARN)
670 debugl1(cs, "W6692_l1hw unknown %04x", pr);
676 setstack_W6692(struct PStack *st, struct IsdnCardState *cs)
678 st->l1.l1hw = W6692_l1hw;
682 DC_Close_W6692(struct IsdnCardState *cs)
687 dbusy_timer_handler(struct IsdnCardState *cs)
689 struct PStack *stptr;
693 spin_lock_irqsave(&cs->lock, flags);
694 if (test_bit(FLG_DBUSY_TIMER, &cs->HW_Flags)) {
695 rbch = cs->readW6692(cs, W_D_RBCH);
696 star = cs->readW6692(cs, W_D_STAR);
698 debugl1(cs, "D-Channel Busy D_RBCH %02x D_STAR %02x",
700 if (star & W_D_STAR_XBZ) { /* D-Channel Busy */
701 test_and_set_bit(FLG_L1_DBUSY, &cs->HW_Flags);
703 while (stptr != NULL) {
704 stptr->l1.l1l2(stptr, PH_PAUSE | INDICATION, NULL);
708 /* discard frame; reset transceiver */
709 test_and_clear_bit(FLG_DBUSY_TIMER, &cs->HW_Flags);
711 dev_kfree_skb_any(cs->tx_skb);
715 printk(KERN_WARNING "HiSax: W6692 D-Channel Busy no skb\n");
716 debugl1(cs, "D-Channel Busy no skb");
718 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_XRST); /* Transmitter reset */
719 spin_unlock_irqrestore(&cs->lock, flags);
720 cs->irq_func(cs->irq, cs);
724 spin_unlock_irqrestore(&cs->lock, flags);
728 W6692Bmode(struct BCState *bcs, int mode, int bchan)
730 struct IsdnCardState *cs = bcs->cs;
732 if (cs->debug & L1_DEB_HSCX)
733 debugl1(cs, "w6692 %c mode %d ichan %d",
734 '1' + bchan, mode, bchan);
736 bcs->channel = bchan;
737 bcs->hw.w6692.bchan = bchan;
741 cs->BC_Write_Reg(cs, bchan, W_B_MODE, 0);
743 case (L1_MODE_TRANS):
744 cs->BC_Write_Reg(cs, bchan, W_B_MODE, W_B_MODE_MMS);
747 cs->BC_Write_Reg(cs, bchan, W_B_MODE, W_B_MODE_ITF);
748 cs->BC_Write_Reg(cs, bchan, W_B_ADM1, 0xff);
749 cs->BC_Write_Reg(cs, bchan, W_B_ADM2, 0xff);
753 cs->BC_Write_Reg(cs, bchan, W_B_CMDR, W_B_CMDR_RRST |
754 W_B_CMDR_RACT | W_B_CMDR_XRST);
755 cs->BC_Write_Reg(cs, bchan, W_B_EXIM, 0x00);
759 W6692_l2l1(struct PStack *st, int pr, void *arg)
761 struct sk_buff *skb = arg;
762 struct BCState *bcs = st->l1.bcs;
766 case (PH_DATA | REQUEST):
767 spin_lock_irqsave(&bcs->cs->lock, flags);
769 skb_queue_tail(&bcs->squeue, skb);
772 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
773 bcs->hw.w6692.count = 0;
774 bcs->cs->BC_Send_Data(bcs);
776 spin_unlock_irqrestore(&bcs->cs->lock, flags);
778 case (PH_PULL | INDICATION):
780 printk(KERN_WARNING "W6692_l2l1: this shouldn't happen\n");
783 spin_lock_irqsave(&bcs->cs->lock, flags);
784 test_and_set_bit(BC_FLG_BUSY, &bcs->Flag);
786 bcs->hw.w6692.count = 0;
787 bcs->cs->BC_Send_Data(bcs);
788 spin_unlock_irqrestore(&bcs->cs->lock, flags);
790 case (PH_PULL | REQUEST):
792 test_and_clear_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
793 st->l1.l1l2(st, PH_PULL | CONFIRM, NULL);
795 test_and_set_bit(FLG_L1_PULL_REQ, &st->l1.Flags);
797 case (PH_ACTIVATE | REQUEST):
798 spin_lock_irqsave(&bcs->cs->lock, flags);
799 test_and_set_bit(BC_FLG_ACTIV, &bcs->Flag);
800 W6692Bmode(bcs, st->l1.mode, st->l1.bc);
801 spin_unlock_irqrestore(&bcs->cs->lock, flags);
802 l1_msg_b(st, pr, arg);
804 case (PH_DEACTIVATE | REQUEST):
805 l1_msg_b(st, pr, arg);
807 case (PH_DEACTIVATE | CONFIRM):
808 spin_lock_irqsave(&bcs->cs->lock, flags);
809 test_and_clear_bit(BC_FLG_ACTIV, &bcs->Flag);
810 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
811 W6692Bmode(bcs, 0, st->l1.bc);
812 spin_unlock_irqrestore(&bcs->cs->lock, flags);
813 st->l1.l1l2(st, PH_DEACTIVATE | CONFIRM, NULL);
819 close_w6692state(struct BCState *bcs)
821 W6692Bmode(bcs, 0, bcs->channel);
822 if (test_and_clear_bit(BC_FLG_INIT, &bcs->Flag)) {
823 kfree(bcs->hw.w6692.rcvbuf);
824 bcs->hw.w6692.rcvbuf = NULL;
827 skb_queue_purge(&bcs->rqueue);
828 skb_queue_purge(&bcs->squeue);
830 dev_kfree_skb_any(bcs->tx_skb);
832 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
838 open_w6692state(struct IsdnCardState *cs, struct BCState *bcs)
840 if (!test_and_set_bit(BC_FLG_INIT, &bcs->Flag)) {
841 if (!(bcs->hw.w6692.rcvbuf = kmalloc(HSCX_BUFMAX, GFP_ATOMIC))) {
843 "HiSax: No memory for w6692.rcvbuf\n");
844 test_and_clear_bit(BC_FLG_INIT, &bcs->Flag);
847 if (!(bcs->blog = kmalloc(MAX_BLOG_SPACE, GFP_ATOMIC))) {
849 "HiSax: No memory for bcs->blog\n");
850 test_and_clear_bit(BC_FLG_INIT, &bcs->Flag);
851 kfree(bcs->hw.w6692.rcvbuf);
852 bcs->hw.w6692.rcvbuf = NULL;
855 skb_queue_head_init(&bcs->rqueue);
856 skb_queue_head_init(&bcs->squeue);
859 test_and_clear_bit(BC_FLG_BUSY, &bcs->Flag);
861 bcs->hw.w6692.rcvidx = 0;
867 setstack_w6692(struct PStack *st, struct BCState *bcs)
869 bcs->channel = st->l1.bc;
870 if (open_w6692state(st->l1.hardware, bcs))
873 st->l2.l2l1 = W6692_l2l1;
874 setstack_manager(st);
880 static void resetW6692(struct IsdnCardState *cs)
882 cs->writeW6692(cs, W_D_CTL, W_D_CTL_SRST);
884 cs->writeW6692(cs, W_D_CTL, 0x00);
886 cs->writeW6692(cs, W_IMASK, 0xff);
887 cs->writeW6692(cs, W_D_SAM, 0xff);
888 cs->writeW6692(cs, W_D_TAM, 0xff);
889 cs->writeW6692(cs, W_D_EXIM, 0x00);
890 cs->writeW6692(cs, W_D_MODE, W_D_MODE_RACT);
891 cs->writeW6692(cs, W_IMASK, 0x18);
892 if (cs->subtyp == W6692_USR) {
893 /* seems that USR implemented some power control features
894 * Pin 79 is connected to the oscilator circuit so we
895 * have to handle it here
897 cs->writeW6692(cs, W_PCTL, 0x80);
898 cs->writeW6692(cs, W_XDATA, 0x00);
902 static void initW6692(struct IsdnCardState *cs, int part)
905 cs->setstack_d = setstack_W6692;
906 cs->DC_Close = DC_Close_W6692;
907 cs->dbusytimer.function = (void *) dbusy_timer_handler;
908 cs->dbusytimer.data = (long) cs;
909 init_timer(&cs->dbusytimer);
911 ph_command(cs, W_L1CMD_RST);
912 cs->dc.w6692.ph_state = W_L1CMD_RST;
914 ph_command(cs, W_L1CMD_ECK);
916 cs->bcs[0].BC_SetStack = setstack_w6692;
917 cs->bcs[1].BC_SetStack = setstack_w6692;
918 cs->bcs[0].BC_Close = close_w6692state;
919 cs->bcs[1].BC_Close = close_w6692state;
920 W6692Bmode(cs->bcs, 0, 0);
921 W6692Bmode(cs->bcs + 1, 0, 0);
924 /* Reenable all IRQ */
925 cs->writeW6692(cs, W_IMASK, 0x18);
926 cs->writeW6692(cs, W_D_EXIM, 0x00);
927 cs->BC_Write_Reg(cs, 0, W_B_EXIM, 0x00);
928 cs->BC_Write_Reg(cs, 1, W_B_EXIM, 0x00);
929 /* Reset D-chan receiver and transmitter */
930 cs->writeW6692(cs, W_D_CMDR, W_D_CMDR_RRST | W_D_CMDR_XRST);
934 /* Interface functions */
937 ReadW6692(struct IsdnCardState *cs, u_char offset)
939 return (inb(cs->hw.w6692.iobase + offset));
943 WriteW6692(struct IsdnCardState *cs, u_char offset, u_char value)
945 outb(value, cs->hw.w6692.iobase + offset);
949 ReadISACfifo(struct IsdnCardState *cs, u_char * data, int size)
951 insb(cs->hw.w6692.iobase + W_D_RFIFO, data, size);
955 WriteISACfifo(struct IsdnCardState *cs, u_char * data, int size)
957 outsb(cs->hw.w6692.iobase + W_D_XFIFO, data, size);
961 ReadW6692B(struct IsdnCardState *cs, int bchan, u_char offset)
963 return (inb(cs->hw.w6692.iobase + (bchan ? 0x40 : 0) + offset));
967 WriteW6692B(struct IsdnCardState *cs, int bchan, u_char offset, u_char value)
969 outb(value, cs->hw.w6692.iobase + (bchan ? 0x40 : 0) + offset);
973 w6692_card_msg(struct IsdnCardState *cs, int mt, void *arg)
980 cs->writeW6692(cs, W_IMASK, 0xff);
981 release_region(cs->hw.w6692.iobase, 256);
982 if (cs->subtyp == W6692_USR) {
983 cs->writeW6692(cs, W_XDATA, 0x04);
997 static struct pci_dev *dev_w6692 __devinitdata = NULL;
1000 setup_w6692(struct IsdnCard *card)
1002 struct IsdnCardState *cs = card->cs;
1006 u_int pci_ioaddr = 0;
1008 strcpy(tmp, w6692_revision);
1009 printk(KERN_INFO "HiSax: W6692 driver Rev. %s\n", HiSax_getrev(tmp));
1010 if (cs->typ != ISDN_CTYPE_W6692)
1013 while (id_list[id_idx].vendor_id) {
1014 dev_w6692 = pci_find_device(id_list[id_idx].vendor_id,
1015 id_list[id_idx].device_id,
1018 if (pci_enable_device(dev_w6692))
1020 cs->subtyp = id_idx;
1027 pci_irq = dev_w6692->irq;
1028 /* I think address 0 is allways the configuration area */
1029 /* and address 1 is the real IO space KKe 03.09.99 */
1030 pci_ioaddr = pci_resource_start(dev_w6692, 1);
1031 /* USR ISDN PCI card TA need some special handling */
1032 if (cs->subtyp == W6692_WINBOND) {
1033 if ((W6692_SV_USR == dev_w6692->subsystem_vendor) &&
1034 (W6692_SD_USR == dev_w6692->subsystem_device)) {
1035 cs->subtyp = W6692_USR;
1040 printk(KERN_WARNING "W6692: No PCI card found\n");
1045 printk(KERN_WARNING "W6692: No IRQ for PCI card found\n");
1049 printk(KERN_WARNING "W6692: NO I/O Base Address found\n");
1052 cs->hw.w6692.iobase = pci_ioaddr;
1053 printk(KERN_INFO "Found: %s %s, I/O base: 0x%x, irq: %d\n",
1054 id_list[cs->subtyp].vendor_name, id_list[cs->subtyp].card_name,
1055 pci_ioaddr, pci_irq);
1056 if (!request_region(cs->hw.w6692.iobase, 256, id_list[cs->subtyp].card_name)) {
1058 "HiSax: %s I/O ports %x-%x already in use\n",
1059 id_list[cs->subtyp].card_name,
1060 cs->hw.w6692.iobase,
1061 cs->hw.w6692.iobase + 255);
1065 printk(KERN_WARNING "HiSax: W6692 and NO_PCI_BIOS\n");
1066 printk(KERN_WARNING "HiSax: W6692 unable to config\n");
1068 #endif /* CONFIG_PCI */
1071 "HiSax: %s config irq:%d I/O:%x\n",
1072 id_list[cs->subtyp].card_name, cs->irq,
1073 cs->hw.w6692.iobase);
1075 INIT_WORK(&cs->tqueue, W6692_bh);
1076 cs->readW6692 = &ReadW6692;
1077 cs->writeW6692 = &WriteW6692;
1078 cs->readisacfifo = &ReadISACfifo;
1079 cs->writeisacfifo = &WriteISACfifo;
1080 cs->BC_Read_Reg = &ReadW6692B;
1081 cs->BC_Write_Reg = &WriteW6692B;
1082 cs->BC_Send_Data = &W6692B_fill_fifo;
1083 cs->cardmsg = &w6692_card_msg;
1084 cs->irq_func = &W6692_interrupt;
1085 cs->irq_flags |= IRQF_SHARED;
1086 W6692Version(cs, "W6692:");
1087 printk(KERN_INFO "W6692 ISTA=0x%X\n", ReadW6692(cs, W_ISTA));
1088 printk(KERN_INFO "W6692 IMASK=0x%X\n", ReadW6692(cs, W_IMASK));
1089 printk(KERN_INFO "W6692 D_EXIR=0x%X\n", ReadW6692(cs, W_D_EXIR));
1090 printk(KERN_INFO "W6692 D_EXIM=0x%X\n", ReadW6692(cs, W_D_EXIM));
1091 printk(KERN_INFO "W6692 D_RSTA=0x%X\n", ReadW6692(cs, W_D_RSTA));