Lines Matching refs:dev

46 #define reader_to_dev(x)	(&x->p_dev->dev)
147 #define ZERO_DEV(dev) memset(&((dev)->init), 0, sizeof((dev)->init)) argument
203 #define ATRLENCK(dev,pos) \ argument
204 if (pos>=dev->atr_len || pos>=MAX_ATR) \
318 static int parse_atr(struct cm4000_dev *dev) in parse_atr() argument
324 DEBUGP(3, dev, "-> parse_atr: dev->atr_len = %i\n", dev->atr_len); in parse_atr()
326 if (dev->atr_len < 3) { in parse_atr()
327 DEBUGP(5, dev, "parse_atr: atr_len < 3\n"); in parse_atr()
331 if (dev->atr[0] == 0x3f) in parse_atr()
332 set_bit(IS_INVREV, &dev->flags); in parse_atr()
334 clear_bit(IS_INVREV, &dev->flags); in parse_atr()
337 ch = dev->atr[1]; in parse_atr()
338 dev->proto = 0; /* XXX PROTO */ in parse_atr()
340 dev->ta1 = 0x11; /* defaults to 9600 baud */ in parse_atr()
344 dev->ta1 = dev->atr[2]; in parse_atr()
345 DEBUGP(5, dev, "Card says FiDi is 0x%.2x\n", dev->ta1); in parse_atr()
348 dev->ta1 = 0x11; in parse_atr()
352 DEBUGP(5, dev, "Yi=%.2x\n", ch & 0xf0); in parse_atr()
359 ch = dev->atr[ix]; in parse_atr()
362 DEBUGP(5, dev, "card is capable of T=1\n"); in parse_atr()
365 DEBUGP(5, dev, "card is capable of T=0\n"); in parse_atr()
371 DEBUGP(5, dev, "ix=%d noHist=%d any_t1=%d\n", in parse_atr()
372 ix, dev->atr[1] & 15, any_t1); in parse_atr()
373 if (ix + 1 + (dev->atr[1] & 0x0f) + any_t1 != dev->atr_len) { in parse_atr()
374 DEBUGP(5, dev, "length error\n"); in parse_atr()
378 set_bit(IS_ANY_T0, &dev->flags); in parse_atr()
381 dev->atr_csum = 0; in parse_atr()
383 for (i = 1; i < dev->atr_len; i++) in parse_atr()
384 dev->atr_csum ^= dev->atr[i]; in parse_atr()
385 if (dev->atr_csum) { in parse_atr()
386 set_bit(IS_BAD_CSUM, &dev->flags); in parse_atr()
387 DEBUGP(5, dev, "bad checksum\n"); in parse_atr()
392 dev->proto = 1; /* XXX PROTO */ in parse_atr()
393 set_bit(IS_ANY_T1, &dev->flags); in parse_atr()
419 static void set_cardparameter(struct cm4000_dev *dev) in set_cardparameter() argument
422 unsigned int iobase = dev->p_dev->resource[0]->start; in set_cardparameter()
425 DEBUGP(3, dev, "-> set_cardparameter\n"); in set_cardparameter()
427 dev->flags1 = dev->flags1 | (((dev->baudv - 1) & 0x0100) >> 8); in set_cardparameter()
428 xoutb(dev->flags1, REG_FLAGS1(iobase)); in set_cardparameter()
429 DEBUGP(5, dev, "flags1 = 0x%02x\n", dev->flags1); in set_cardparameter()
432 xoutb((unsigned char)((dev->baudv - 1) & 0xFF), REG_BAUDRATE(iobase)); in set_cardparameter()
434 DEBUGP(5, dev, "baudv = %i -> write 0x%02x\n", dev->baudv, in set_cardparameter()
435 ((dev->baudv - 1) & 0xFF)); in set_cardparameter()
439 if (!memcmp(dev->atr, card_fixups[i].atr, in set_cardparameter()
445 DEBUGP(3, dev, "<- set_cardparameter\n"); in set_cardparameter()
448 static int set_protocol(struct cm4000_dev *dev, struct ptsreq *ptsreq) in set_protocol() argument
455 unsigned int iobase = dev->p_dev->resource[0]->start; in set_protocol()
459 DEBUGP(3, dev, "-> set_protocol\n"); in set_protocol()
460 DEBUGP(5, dev, "ptsreq->Protocol = 0x%.8x, ptsreq->Flags=0x%.8x, " in set_protocol()
467 dev->pts[0] = 0xff; in set_protocol()
468 dev->pts[1] = 0x00; in set_protocol()
471 dev->pts[1]++; in set_protocol()
472 dev->proto = dev->pts[1]; /* Set new protocol */ in set_protocol()
473 dev->pts[1] = (0x01 << 4) | (dev->pts[1]); in set_protocol()
476 DEBUGP(5, dev, "Ta(1) from ATR is 0x%.2x\n", dev->ta1); in set_protocol()
478 dev->pts[2] = fi_di_table[dev->ta1 & 0x0F][(dev->ta1 >> 4) & 0x0F]; in set_protocol()
481 dev->pts[3] = dev->pts[0] ^ dev->pts[1] ^ dev->pts[2]; in set_protocol()
483 DEBUGP(5, dev, "pts0=%.2x, pts1=%.2x, pts2=%.2x, pts3=%.2x\n", in set_protocol()
484 dev->pts[0], dev->pts[1], dev->pts[2], dev->pts[3]); in set_protocol()
487 if (test_bit(IS_INVREV, &dev->flags)) in set_protocol()
488 str_invert_revert(dev->pts, 4); in set_protocol()
494 DEBUGP(5, dev, "Enable access to the messages buffer\n"); in set_protocol()
495 dev->flags1 = 0x20 /* T_Active */ in set_protocol()
496 | (test_bit(IS_INVREV, &dev->flags) ? 0x02 : 0x00) /* inv parity */ in set_protocol()
497 | ((dev->baudv >> 8) & 0x01); /* MSB-baud */ in set_protocol()
498 xoutb(dev->flags1, REG_FLAGS1(iobase)); in set_protocol()
500 DEBUGP(5, dev, "Enable message buffer -> flags1 = 0x%.2x\n", in set_protocol()
501 dev->flags1); in set_protocol()
504 DEBUGP(5, dev, "Write challenge to buffer: "); in set_protocol()
507 xoutb(dev->pts[i], REG_BUF_DATA(iobase)); /* buf data */ in set_protocol()
509 pr_debug("0x%.2x ", dev->pts[i]); in set_protocol()
517 DEBUGP(5, dev, "Set number of bytes to write\n");
525 DEBUGP(5, dev, "Waiting for NumRecBytes getting valid\n");
529 DEBUGP(5, dev, "NumRecBytes is valid\n");
536 DEBUGP(5, dev, "Timeout waiting for NumRecBytes getting "
542 DEBUGP(5, dev, "Reading NumRecBytes\n");
546 DEBUGP(2, dev, "NumRecBytes = %i\n", num_bytes_read);
562 DEBUGP(5, dev, "Timeout reading num_bytes_read\n");
567 DEBUGP(5, dev, "Reset the CARDMAN CONTROLLER\n");
571 DEBUGP(5, dev, "Read PPS reply\n");
578 DEBUGP(2, dev, "PTSreply: ");
585 DEBUGP(5, dev, "Clear Tactive in Flags1\n");
589 if ((dev->pts[0] == pts_reply[0]) &&
590 (dev->pts[1] == pts_reply[1]) &&
591 (dev->pts[2] == pts_reply[2]) && (dev->pts[3] == pts_reply[3])) {
593 dev->baudv = calc_baudv(dev->pts[2]);
594 set_cardparameter(dev);
595 } else if ((dev->pts[0] == pts_reply[0]) &&
596 ((dev->pts[1] & 0xef) == pts_reply[1]) &&
599 dev->baudv = calc_baudv(0x11);
600 set_cardparameter(dev);
605 DEBUGP(3, dev, "<- set_protocol\n");
609 static int io_detect_cm4000(unsigned int iobase, struct cm4000_dev *dev) in io_detect_cm4000() argument
614 clear_bit(IS_ATR_VALID, &dev->flags); in io_detect_cm4000()
615 set_bit(IS_CMM_ABSENT, &dev->flags); in io_detect_cm4000()
619 xoutb(dev->flags1 | 0x40, REG_FLAGS1(iobase)); in io_detect_cm4000()
621 clear_bit(IS_ATR_VALID, &dev->flags); in io_detect_cm4000()
622 set_bit(IS_CMM_ABSENT, &dev->flags); in io_detect_cm4000()
626 xoutb(dev->flags1, REG_FLAGS1(iobase)); in io_detect_cm4000()
630 static void terminate_monitor(struct cm4000_dev *dev) in terminate_monitor() argument
636 DEBUGP(3, dev, "-> terminate_monitor\n"); in terminate_monitor()
637 wait_event_interruptible(dev->devq, in terminate_monitor()
639 (void *)&dev->flags)); in terminate_monitor()
646 DEBUGP(5, dev, "Now allow last cycle of monitor!\n"); in terminate_monitor()
647 while (test_bit(LOCK_MONITOR, (void *)&dev->flags)) in terminate_monitor()
650 DEBUGP(5, dev, "Delete timer\n"); in terminate_monitor()
651 del_timer_sync(&dev->timer); in terminate_monitor()
653 dev->monitor_running = 0; in terminate_monitor()
656 DEBUGP(3, dev, "<- terminate_monitor\n"); in terminate_monitor()
669 struct cm4000_dev *dev = from_timer(dev, t, timer); in monitor_card() local
670 unsigned int iobase = dev->p_dev->resource[0]->start; in monitor_card()
675 DEBUGP(7, dev, "-> monitor_card\n"); in monitor_card()
678 if (test_and_set_bit(LOCK_MONITOR, &dev->flags)) { in monitor_card()
679 DEBUGP(4, dev, "About to stop monitor\n"); in monitor_card()
681 dev->rlen = in monitor_card()
682 dev->rpos = in monitor_card()
683 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0; in monitor_card()
684 dev->mstate = M_FETCH_ATR; in monitor_card()
685 clear_bit(LOCK_MONITOR, &dev->flags); in monitor_card()
687 wake_up_interruptible(&dev->devq); in monitor_card()
688 DEBUGP(2, dev, "<- monitor_card (we are done now)\n"); in monitor_card()
693 if (test_and_set_bit(LOCK_IO, (void *)&dev->flags)) { in monitor_card()
694 DEBUGP(4, dev, "Couldn't get IO lock\n"); in monitor_card()
699 dev->flags0 = xinb(REG_FLAGS0(iobase)); in monitor_card()
700 DEBUGP(7, dev, "dev->flags0 = 0x%2x\n", dev->flags0); in monitor_card()
701 DEBUGP(7, dev, "smartcard present: %s\n", in monitor_card()
702 dev->flags0 & 1 ? "yes" : "no"); in monitor_card()
703 DEBUGP(7, dev, "cardman present: %s\n", in monitor_card()
704 dev->flags0 == 0xff ? "no" : "yes"); in monitor_card()
706 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */ in monitor_card()
707 || dev->flags0 == 0xff) { /* no cardman inserted */ in monitor_card()
709 dev->rlen = in monitor_card()
710 dev->rpos = in monitor_card()
711 dev->atr_csum = dev->atr_len_retry = dev->cwarn = 0; in monitor_card()
712 dev->mstate = M_FETCH_ATR; in monitor_card()
714 dev->flags &= 0x000000ff; /* only keep IO and MONITOR locks */ in monitor_card()
716 if (dev->flags0 == 0xff) { in monitor_card()
717 DEBUGP(4, dev, "set IS_CMM_ABSENT bit\n"); in monitor_card()
718 set_bit(IS_CMM_ABSENT, &dev->flags); in monitor_card()
719 } else if (test_bit(IS_CMM_ABSENT, &dev->flags)) { in monitor_card()
720 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit " in monitor_card()
722 clear_bit(IS_CMM_ABSENT, &dev->flags); in monitor_card()
726 } else if ((dev->flags0 & 1) && test_bit(IS_CMM_ABSENT, &dev->flags)) { in monitor_card()
729 DEBUGP(4, dev, "clear IS_CMM_ABSENT bit (card is inserted)\n"); in monitor_card()
730 clear_bit(IS_CMM_ABSENT, &dev->flags); in monitor_card()
733 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) { in monitor_card()
734 DEBUGP(7, dev, "believe ATR is already valid (do nothing)\n"); in monitor_card()
738 switch (dev->mstate) { in monitor_card()
742 DEBUGP(4, dev, "M_CARDOFF\n"); in monitor_card()
746 dev->mdelay = T_10MSEC; in monitor_card()
754 dev->rlen = in monitor_card()
755 dev->rpos = in monitor_card()
756 dev->atr_csum = in monitor_card()
757 dev->atr_len_retry = dev->cwarn = 0; in monitor_card()
758 dev->mstate = M_FETCH_ATR; in monitor_card()
761 dev->mdelay = T_50MSEC; in monitor_card()
766 DEBUGP(4, dev, "M_FETCH_ATR\n"); in monitor_card()
768 DEBUGP(4, dev, "Reset BAUDV to 9600\n"); in monitor_card()
769 dev->baudv = 0x173; /* 9600 */ in monitor_card()
775 xoutb(dev->flags0 & 2 ? 0x46 : 0x44, REG_FLAGS0(iobase)); in monitor_card()
776 dev->mdelay = T_40MSEC; in monitor_card()
777 dev->mstate = M_TIMEOUT_WAIT; in monitor_card()
780 DEBUGP(4, dev, "M_TIMEOUT_WAIT\n"); in monitor_card()
782 io_read_num_rec_bytes(iobase, &dev->atr_len); in monitor_card()
783 dev->mdelay = T_10MSEC; in monitor_card()
784 dev->mstate = M_READ_ATR_LEN; in monitor_card()
787 DEBUGP(4, dev, "M_READ_ATR_LEN\n"); in monitor_card()
792 if (dev->atr_len == io_read_num_rec_bytes(iobase, &s)) { in monitor_card()
793 if (dev->atr_len_retry++ >= MAX_ATR_LEN_RETRY) { /* + XX msec */ in monitor_card()
794 dev->mdelay = T_10MSEC; in monitor_card()
795 dev->mstate = M_READ_ATR; in monitor_card()
798 dev->atr_len = s; in monitor_card()
799 dev->atr_len_retry = 0; /* set new timeout */ in monitor_card()
802 DEBUGP(4, dev, "Current ATR_LEN = %i\n", dev->atr_len); in monitor_card()
805 DEBUGP(4, dev, "M_READ_ATR\n"); in monitor_card()
807 for (i = 0; i < dev->atr_len; i++) { in monitor_card()
809 dev->atr[i] = inb(REG_BUF_DATA(iobase)); in monitor_card()
812 DEBUGP(4, dev, "Deactivate T_Active flags\n"); in monitor_card()
813 dev->flags1 = 0x01; in monitor_card()
814 xoutb(dev->flags1, REG_FLAGS1(iobase)); in monitor_card()
817 set_bit(IS_ATR_PRESENT, &dev->flags); in monitor_card()
818 if (dev->atr[0] == 0x03) in monitor_card()
819 str_invert_revert(dev->atr, dev->atr_len); in monitor_card()
820 atrc = parse_atr(dev); in monitor_card()
822 dev->mdelay = 0; in monitor_card()
823 dev->mstate = M_BAD_CARD; in monitor_card()
825 dev->mdelay = T_50MSEC; in monitor_card()
826 dev->mstate = M_ATR_PRESENT; in monitor_card()
827 set_bit(IS_ATR_VALID, &dev->flags); in monitor_card()
830 if (test_bit(IS_ATR_VALID, &dev->flags) == 1) { in monitor_card()
831 DEBUGP(4, dev, "monitor_card: ATR valid\n"); in monitor_card()
834 if ((test_bit(IS_AUTOPPS_ACT, &dev->flags) == 0) && in monitor_card()
835 (dev->ta1 != 0x11) && in monitor_card()
836 !(test_bit(IS_ANY_T0, &dev->flags) && in monitor_card()
837 test_bit(IS_ANY_T1, &dev->flags))) { in monitor_card()
838 DEBUGP(4, dev, "Perform AUTOPPS\n"); in monitor_card()
839 set_bit(IS_AUTOPPS_ACT, &dev->flags); in monitor_card()
840 ptsreq.protocol = (0x01 << dev->proto); in monitor_card()
845 if (set_protocol(dev, &ptsreq) == 0) { in monitor_card()
846 DEBUGP(4, dev, "AUTOPPS ret SUCC\n"); in monitor_card()
847 clear_bit(IS_AUTOPPS_ACT, &dev->flags); in monitor_card()
848 wake_up_interruptible(&dev->atrq); in monitor_card()
850 DEBUGP(4, dev, "AUTOPPS failed: " in monitor_card()
853 clear_bit(IS_ATR_PRESENT, &dev->flags); in monitor_card()
854 clear_bit(IS_ATR_VALID, &dev->flags); in monitor_card()
855 dev->rlen = in monitor_card()
856 dev->rpos = in monitor_card()
857 dev->atr_csum = in monitor_card()
858 dev->atr_len_retry = dev->cwarn = 0; in monitor_card()
859 dev->mstate = M_FETCH_ATR; in monitor_card()
861 dev->mdelay = T_50MSEC; in monitor_card()
866 set_cardparameter(dev); in monitor_card()
867 if (test_bit(IS_AUTOPPS_ACT, &dev->flags) == 1) in monitor_card()
868 DEBUGP(4, dev, "AUTOPPS already active " in monitor_card()
870 if (dev->ta1 == 0x11) in monitor_card()
871 DEBUGP(4, dev, "No AUTOPPS necessary " in monitor_card()
873 if (test_bit(IS_ANY_T0, &dev->flags) in monitor_card()
874 && test_bit(IS_ANY_T1, &dev->flags)) in monitor_card()
875 DEBUGP(4, dev, "Do NOT perform AUTOPPS " in monitor_card()
877 clear_bit(IS_AUTOPPS_ACT, &dev->flags); in monitor_card()
878 wake_up_interruptible(&dev->atrq); in monitor_card()
881 DEBUGP(4, dev, "ATR invalid\n"); in monitor_card()
882 wake_up_interruptible(&dev->atrq); in monitor_card()
886 DEBUGP(4, dev, "M_BAD_CARD\n"); in monitor_card()
888 if (dev->cwarn == 0 || dev->cwarn == 10) { in monitor_card()
889 set_bit(IS_BAD_CARD, &dev->flags); in monitor_card()
890 dev_warn(&dev->p_dev->dev, MODULE_NAME ": "); in monitor_card()
891 if (test_bit(IS_BAD_CSUM, &dev->flags)) { in monitor_card()
892 DEBUGP(4, dev, "ATR checksum (0x%.2x, should " in monitor_card()
893 "be zero) failed\n", dev->atr_csum); in monitor_card()
896 else if (test_bit(IS_BAD_LENGTH, &dev->flags)) { in monitor_card()
897 DEBUGP(4, dev, "ATR length error\n"); in monitor_card()
899 DEBUGP(4, dev, "card damaged or wrong way " in monitor_card()
903 dev->cwarn = 0; in monitor_card()
904 wake_up_interruptible(&dev->atrq); /* wake open */ in monitor_card()
906 dev->cwarn++; in monitor_card()
907 dev->mdelay = T_100MSEC; in monitor_card()
908 dev->mstate = M_FETCH_ATR; in monitor_card()
911 DEBUGP(7, dev, "Unknown action\n"); in monitor_card()
916 DEBUGP(7, dev, "release_io\n"); in monitor_card()
917 clear_bit(LOCK_IO, &dev->flags); in monitor_card()
918 wake_up_interruptible(&dev->ioq); /* whoever needs IO */ in monitor_card()
921 DEBUGP(7, dev, "<- monitor_card (returns with timer)\n"); in monitor_card()
922 mod_timer(&dev->timer, jiffies + dev->mdelay); in monitor_card()
923 clear_bit(LOCK_MONITOR, &dev->flags); in monitor_card()
931 struct cm4000_dev *dev = filp->private_data; in cmm_read() local
932 unsigned int iobase = dev->p_dev->resource[0]->start; in cmm_read()
936 DEBUGP(2, dev, "-> cmm_read(%s,%d)\n", current->comm, current->pid); in cmm_read()
941 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */ in cmm_read()
942 test_bit(IS_CMM_ABSENT, &dev->flags)) in cmm_read()
945 if (test_bit(IS_BAD_CSUM, &dev->flags)) in cmm_read()
950 (dev->atrq, in cmm_read()
952 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) { in cmm_read()
958 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) in cmm_read()
963 (dev->readq, in cmm_read()
964 ((filp->f_flags & O_NONBLOCK) || (dev->rpos < dev->rlen)))) { in cmm_read()
972 (dev->ioq, in cmm_read()
974 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) { in cmm_read()
981 dev->flags0 = inb(REG_FLAGS0(iobase)); in cmm_read()
982 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */ in cmm_read()
983 || dev->flags0 == 0xff) { /* no cardman inserted */ in cmm_read()
984 clear_bit(IS_ATR_VALID, &dev->flags); in cmm_read()
985 if (dev->flags0 & 1) { in cmm_read()
986 set_bit(IS_CMM_ABSENT, &dev->flags); in cmm_read()
994 DEBUGP(4, dev, "begin read answer\n"); in cmm_read()
995 j = min(count, (size_t)(dev->rlen - dev->rpos)); in cmm_read()
996 k = dev->rpos; in cmm_read()
999 DEBUGP(4, dev, "read1 j=%d\n", j); in cmm_read()
1002 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase)); in cmm_read()
1004 j = min(count, (size_t)(dev->rlen - dev->rpos)); in cmm_read()
1006 DEBUGP(4, dev, "read2 j=%d\n", j); in cmm_read()
1007 dev->flags1 |= 0x10; /* MSB buf addr set */ in cmm_read()
1008 xoutb(dev->flags1, REG_FLAGS1(iobase)); in cmm_read()
1011 dev->rbuf[i] = xinb(REG_BUF_DATA(iobase)); in cmm_read()
1015 if (dev->proto == 0 && count > dev->rlen - dev->rpos && i) { in cmm_read()
1016 DEBUGP(4, dev, "T=0 and count > buffer\n"); in cmm_read()
1017 dev->rbuf[i] = dev->rbuf[i - 1]; in cmm_read()
1018 dev->rbuf[i - 1] = dev->procbyte; in cmm_read()
1023 dev->rpos = dev->rlen + 1; in cmm_read()
1026 DEBUGP(4, dev, "Clear T1Active\n"); in cmm_read()
1027 dev->flags1 &= 0xdf; in cmm_read()
1028 xoutb(dev->flags1, REG_FLAGS1(iobase)); in cmm_read()
1032 if (!io_detect_cm4000(iobase, dev)) { in cmm_read()
1037 if (test_bit(IS_INVREV, &dev->flags) && count > 0) in cmm_read()
1038 str_invert_revert(dev->rbuf, count); in cmm_read()
1040 if (copy_to_user(buf, dev->rbuf, count)) in cmm_read()
1044 clear_bit(LOCK_IO, &dev->flags); in cmm_read()
1045 wake_up_interruptible(&dev->ioq); in cmm_read()
1047 DEBUGP(2, dev, "<- cmm_read returns: rc = %zi\n", in cmm_read()
1055 struct cm4000_dev *dev = filp->private_data; in cmm_write() local
1056 unsigned int iobase = dev->p_dev->resource[0]->start; in cmm_write()
1065 DEBUGP(2, dev, "-> cmm_write(%s,%d)\n", current->comm, current->pid); in cmm_write()
1070 if (dev->proto == 0 && count < 4) { in cmm_write()
1072 DEBUGP(4, dev, "T0 short write\n"); in cmm_write()
1078 sendT0 = dev->proto ? 0 : nr > 5 ? 0x08 : 0; in cmm_write()
1080 if (!pcmcia_dev_present(dev->p_dev) || /* device removed */ in cmm_write()
1081 test_bit(IS_CMM_ABSENT, &dev->flags)) in cmm_write()
1084 if (test_bit(IS_BAD_CSUM, &dev->flags)) { in cmm_write()
1085 DEBUGP(4, dev, "bad csum\n"); in cmm_write()
1101 (dev->atrq, in cmm_write()
1103 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) != 0)))) { in cmm_write()
1109 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) { /* invalid atr */ in cmm_write()
1110 DEBUGP(4, dev, "invalid ATR\n"); in cmm_write()
1116 (dev->ioq, in cmm_write()
1118 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) == 0)))) { in cmm_write()
1124 if (copy_from_user(dev->sbuf, buf, ((count > 512) ? 512 : count))) in cmm_write()
1128 dev->flags0 = inb(REG_FLAGS0(iobase)); in cmm_write()
1129 if ((dev->flags0 & 1) == 0 /* no smartcard inserted */ in cmm_write()
1130 || dev->flags0 == 0xff) { /* no cardman inserted */ in cmm_write()
1131 clear_bit(IS_ATR_VALID, &dev->flags); in cmm_write()
1132 if (dev->flags0 & 1) { in cmm_write()
1133 set_bit(IS_CMM_ABSENT, &dev->flags); in cmm_write()
1136 DEBUGP(4, dev, "IO error\n"); in cmm_write()
1144 if (!io_detect_cm4000(iobase, dev)) { in cmm_write()
1150 dev->flags1 |= (sendT0); in cmm_write()
1152 set_cardparameter(dev); in cmm_write()
1157 dev->flags1 = 0x20 /* T_Active */ in cmm_write()
1159 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0)/* inverse parity */ in cmm_write()
1160 | (((dev->baudv - 1) & 0x0100) >> 8); /* MSB-Baud */ in cmm_write()
1161 DEBUGP(1, dev, "set dev->flags1 = 0x%.2x\n", dev->flags1); in cmm_write()
1162 xoutb(dev->flags1, REG_FLAGS1(iobase)); in cmm_write()
1165 DEBUGP(4, dev, "Xmit data\n"); in cmm_write()
1168 dev->flags1 = 0x20 /* T_Active */ in cmm_write()
1171 | (test_bit(IS_INVREV, &dev->flags) ? 2 : 0) in cmm_write()
1172 | (((dev->baudv - 1) & 0x0100) >> 8) /* MSB-Baud */ in cmm_write()
1174 DEBUGP(4, dev, "dev->flags = 0x%.2x - set address " in cmm_write()
1175 "high\n", dev->flags1); in cmm_write()
1176 xoutb(dev->flags1, REG_FLAGS1(iobase)); in cmm_write()
1178 if (test_bit(IS_INVREV, &dev->flags)) { in cmm_write()
1179 DEBUGP(4, dev, "Apply inverse convention for 0x%.2x " in cmm_write()
1180 "-> 0x%.2x\n", (unsigned char)dev->sbuf[i], in cmm_write()
1181 invert_revert(dev->sbuf[i])); in cmm_write()
1183 xoutb(invert_revert(dev->sbuf[i]), in cmm_write()
1187 xoutb(dev->sbuf[i], REG_BUF_DATA(iobase)); in cmm_write()
1190 DEBUGP(4, dev, "Xmit done\n"); in cmm_write()
1192 if (dev->proto == 0) { in cmm_write()
1195 DEBUGP(4, dev, "T=0 assumes 0 byte reply\n"); in cmm_write()
1197 if (test_bit(IS_INVREV, &dev->flags)) in cmm_write()
1210 nsend = 5 + (unsigned char)dev->sbuf[4]; in cmm_write()
1211 if (dev->sbuf[4] == 0) in cmm_write()
1219 if (test_bit(IS_INVREV, &dev->flags)) { in cmm_write()
1220 DEBUGP(4, dev, "T=0 set Procedure byte (inverse-reverse) " in cmm_write()
1221 "0x%.2x\n", invert_revert(dev->sbuf[1])); in cmm_write()
1222 xoutb(invert_revert(dev->sbuf[1]), REG_NUM_BYTES(iobase)); in cmm_write()
1224 DEBUGP(4, dev, "T=0 set Procedure byte 0x%.2x\n", dev->sbuf[1]); in cmm_write()
1225 xoutb(dev->sbuf[1], REG_NUM_BYTES(iobase)); in cmm_write()
1228 DEBUGP(1, dev, "set NumSendBytes = 0x%.2x\n", in cmm_write()
1232 DEBUGP(1, dev, "Trigger CARDMAN CONTROLLER (0x%.2x)\n", in cmm_write()
1234 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */ in cmm_write()
1235 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */ in cmm_write()
1238 | (dev->flags0 & 2 ? 0 : 4) /* power on if needed */ in cmm_write()
1239 |(dev->proto ? 0x10 : 0x08) /* T=1/T=0 */ in cmm_write()
1244 if (dev->proto == 1) { in cmm_write()
1245 DEBUGP(4, dev, "Wait for xmit done\n"); in cmm_write()
1252 DEBUGP(4, dev, "timeout waiting for xmit done\n"); in cmm_write()
1261 if (dev->proto) { in cmm_write()
1267 DEBUGP(4, dev, "infolen=%d\n", infolen); in cmm_write()
1273 DEBUGP(4, dev, "timeout waiting for infoLen\n"); in cmm_write()
1278 clear_bit(IS_PROCBYTE_PRESENT, &dev->flags); in cmm_write()
1281 io_read_num_rec_bytes(iobase, &dev->rlen); in cmm_write()
1283 if (dev->proto) { in cmm_write()
1284 if (dev->rlen >= infolen + 4) in cmm_write()
1290 if (s > dev->rlen) { in cmm_write()
1291 DEBUGP(1, dev, "NumRecBytes inc (reset timeout)\n"); in cmm_write()
1293 dev->rlen = s; in cmm_write()
1302 else if (dev->proto == 0) { in cmm_write()
1305 DEBUGP(1, dev, "NoProcedure byte set\n"); in cmm_write()
1309 DEBUGP(1, dev, "NoProcedure byte unset " in cmm_write()
1311 dev->procbyte = inb(REG_FLAGS1(iobase)); in cmm_write()
1312 DEBUGP(1, dev, "Read procedure byte 0x%.2x\n", in cmm_write()
1313 dev->procbyte); in cmm_write()
1317 DEBUGP(1, dev, "T0Done flag (read reply)\n"); in cmm_write()
1321 if (dev->proto) in cmm_write()
1325 DEBUGP(1, dev, "timeout waiting for numRecBytes\n"); in cmm_write()
1329 if (dev->proto == 0) { in cmm_write()
1330 DEBUGP(1, dev, "Wait for T0Done bit to be set\n"); in cmm_write()
1337 DEBUGP(1, dev, "timeout waiting for T0Done\n"); in cmm_write()
1342 dev->procbyte = inb(REG_FLAGS1(iobase)); in cmm_write()
1343 DEBUGP(4, dev, "Read procedure byte 0x%.2x\n", in cmm_write()
1344 dev->procbyte); in cmm_write()
1346 io_read_num_rec_bytes(iobase, &dev->rlen); in cmm_write()
1347 DEBUGP(4, dev, "Read NumRecBytes = %i\n", dev->rlen); in cmm_write()
1352 dev->rpos = dev->proto ? 0 : nr == 4 ? 5 : nr > dev->rlen ? 5 : nr; in cmm_write()
1353 DEBUGP(4, dev, "dev->rlen = %i, dev->rpos = %i, nr = %i\n", in cmm_write()
1354 dev->rlen, dev->rpos, nr); in cmm_write()
1357 DEBUGP(4, dev, "Reset SM\n"); in cmm_write()
1361 DEBUGP(4, dev, "Write failed but clear T_Active\n"); in cmm_write()
1362 dev->flags1 &= 0xdf; in cmm_write()
1363 xoutb(dev->flags1, REG_FLAGS1(iobase)); in cmm_write()
1366 clear_bit(LOCK_IO, &dev->flags); in cmm_write()
1367 wake_up_interruptible(&dev->ioq); in cmm_write()
1368 wake_up_interruptible(&dev->readq); /* tell read we have data */ in cmm_write()
1371 memset((char *)dev->sbuf, 0, 512); in cmm_write()
1374 DEBUGP(2, dev, "<- cmm_write\n"); in cmm_write()
1378 static void start_monitor(struct cm4000_dev *dev) in start_monitor() argument
1380 DEBUGP(3, dev, "-> start_monitor\n"); in start_monitor()
1381 if (!dev->monitor_running) { in start_monitor()
1382 DEBUGP(5, dev, "create, init and add timer\n"); in start_monitor()
1383 timer_setup(&dev->timer, monitor_card, 0); in start_monitor()
1384 dev->monitor_running = 1; in start_monitor()
1385 mod_timer(&dev->timer, jiffies); in start_monitor()
1387 DEBUGP(5, dev, "monitor already running\n"); in start_monitor()
1388 DEBUGP(3, dev, "<- start_monitor\n"); in start_monitor()
1391 static void stop_monitor(struct cm4000_dev *dev) in stop_monitor() argument
1393 DEBUGP(3, dev, "-> stop_monitor\n"); in stop_monitor()
1394 if (dev->monitor_running) { in stop_monitor()
1395 DEBUGP(5, dev, "stopping monitor\n"); in stop_monitor()
1396 terminate_monitor(dev); in stop_monitor()
1398 clear_bit(IS_ATR_VALID, &dev->flags); in stop_monitor()
1399 clear_bit(IS_ATR_PRESENT, &dev->flags); in stop_monitor()
1401 DEBUGP(5, dev, "monitor already stopped\n"); in stop_monitor()
1402 DEBUGP(3, dev, "<- stop_monitor\n"); in stop_monitor()
1407 struct cm4000_dev *dev = filp->private_data; in cmm_ioctl() local
1408 unsigned int iobase = dev->p_dev->resource[0]->start; in cmm_ioctl()
1421 DEBUGP(3, dev, "cmm_ioctl(device=%d.%d) %s\n", imajor(inode), in cmm_ioctl()
1429 DEBUGP(4, dev, "DEV_OK false\n"); in cmm_ioctl()
1433 if (test_bit(IS_CMM_ABSENT, &dev->flags)) { in cmm_ioctl()
1434 DEBUGP(4, dev, "CMM_ABSENT flag set\n"); in cmm_ioctl()
1440 DEBUGP(4, dev, "ioctype mismatch\n"); in cmm_ioctl()
1444 DEBUGP(4, dev, "iocnr mismatch\n"); in cmm_ioctl()
1451 DEBUGP(4, dev, " ... in CM_IOCGSTATUS\n"); in cmm_ioctl()
1457 status = dev->flags0 & 3; in cmm_ioctl()
1458 if (test_bit(IS_ATR_PRESENT, &dev->flags)) in cmm_ioctl()
1460 if (test_bit(IS_ATR_VALID, &dev->flags)) in cmm_ioctl()
1462 if (test_bit(IS_CMM_ABSENT, &dev->flags)) in cmm_ioctl()
1464 if (test_bit(IS_BAD_CARD, &dev->flags)) in cmm_ioctl()
1471 DEBUGP(4, dev, "... in CM_IOCGATR\n"); in cmm_ioctl()
1477 (dev->atrq, in cmm_ioctl()
1479 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) in cmm_ioctl()
1489 if (test_bit(IS_ATR_VALID, &dev->flags) == 0) { in cmm_ioctl()
1495 if (copy_to_user(atreq->atr, dev->atr, in cmm_ioctl()
1496 dev->atr_len)) in cmm_ioctl()
1499 tmp = dev->atr_len; in cmm_ioctl()
1509 DEBUGP(4, dev, "... in CM_IOCARDOFF\n"); in cmm_ioctl()
1510 if (dev->flags0 & 0x01) { in cmm_ioctl()
1511 DEBUGP(4, dev, " Card inserted\n"); in cmm_ioctl()
1513 DEBUGP(2, dev, " No card inserted\n"); in cmm_ioctl()
1515 if (dev->flags0 & 0x02) { in cmm_ioctl()
1516 DEBUGP(4, dev, " Card powered\n"); in cmm_ioctl()
1518 DEBUGP(2, dev, " Card not powered\n"); in cmm_ioctl()
1523 if ((dev->flags0 & 0x01) && (dev->flags0 & 0x02)) { in cmm_ioctl()
1527 (dev->ioq, in cmm_ioctl()
1529 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) in cmm_ioctl()
1538 DEBUGP(4, dev, "Set Flags0=0x42 \n"); in cmm_ioctl()
1540 clear_bit(IS_ATR_PRESENT, &dev->flags); in cmm_ioctl()
1541 clear_bit(IS_ATR_VALID, &dev->flags); in cmm_ioctl()
1542 dev->mstate = M_CARDOFF; in cmm_ioctl()
1543 clear_bit(LOCK_IO, &dev->flags); in cmm_ioctl()
1545 (dev->atrq, in cmm_ioctl()
1547 || (test_bit(IS_ATR_VALID, (void *)&dev->flags) != in cmm_ioctl()
1557 clear_bit(LOCK_IO, &dev->flags); in cmm_ioctl()
1558 wake_up_interruptible(&dev->ioq); in cmm_ioctl()
1573 DEBUGP(4, dev, "... in CM_IOCSPTS\n"); in cmm_ioctl()
1576 (dev->atrq, in cmm_ioctl()
1578 || (test_bit(IS_ATR_PRESENT, (void *)&dev->flags) in cmm_ioctl()
1588 (dev->ioq, in cmm_ioctl()
1590 || (test_and_set_bit(LOCK_IO, (void *)&dev->flags) in cmm_ioctl()
1599 if ((rc = set_protocol(dev, &krnptsreq)) != 0) { in cmm_ioctl()
1601 dev->mstate = M_FETCH_ATR; in cmm_ioctl()
1602 clear_bit(IS_ATR_VALID, &dev->flags); in cmm_ioctl()
1605 clear_bit(LOCK_IO, &dev->flags); in cmm_ioctl()
1606 wake_up_interruptible(&dev->ioq); in cmm_ioctl()
1616 DEBUGP(4, dev, "... in default (unknown IOCTL code)\n"); in cmm_ioctl()
1626 struct cm4000_dev *dev; in cmm_open() local
1646 dev = link->priv; in cmm_open()
1647 filp->private_data = dev; in cmm_open()
1649 DEBUGP(2, dev, "-> cmm_open(device=%d.%d process=%s,%d)\n", in cmm_open()
1656 ZERO_DEV(dev); in cmm_open()
1669 dev->mdelay = T_50MSEC; in cmm_open()
1672 start_monitor(dev); in cmm_open()
1676 DEBUGP(2, dev, "<- cmm_open\n"); in cmm_open()
1685 struct cm4000_dev *dev; in cmm_close() local
1696 dev = link->priv; in cmm_close()
1698 DEBUGP(2, dev, "-> cmm_close(maj/min=%d.%d)\n", in cmm_close()
1701 stop_monitor(dev); in cmm_close()
1703 ZERO_DEV(dev); in cmm_close()
1706 wake_up(&dev->devq); /* socket removed? */ in cmm_close()
1708 DEBUGP(2, dev, "cmm_close\n"); in cmm_close()
1714 struct cm4000_dev *dev = link->priv; in cmm_cm4000_release() local
1719 DEBUGP(3, dev, "-> cmm_cm4000_release\n"); in cmm_cm4000_release()
1727 wait_event(dev->devq, (link->open == 0)); in cmm_cm4000_release()
1730 DEBUGP(3, dev, "<- cmm_cm4000_release\n"); in cmm_cm4000_release()
1761 struct cm4000_dev *dev; in cm4000_suspend() local
1763 dev = link->priv; in cm4000_suspend()
1764 stop_monitor(dev); in cm4000_suspend()
1771 struct cm4000_dev *dev; in cm4000_resume() local
1773 dev = link->priv; in cm4000_resume()
1775 start_monitor(dev); in cm4000_resume()
1788 struct cm4000_dev *dev; in cm4000_probe() local
1801 dev = kzalloc(sizeof(struct cm4000_dev), GFP_KERNEL); in cm4000_probe()
1802 if (dev == NULL) in cm4000_probe()
1805 dev->p_dev = link; in cm4000_probe()
1806 link->priv = dev; in cm4000_probe()
1809 init_waitqueue_head(&dev->devq); in cm4000_probe()
1810 init_waitqueue_head(&dev->ioq); in cm4000_probe()
1811 init_waitqueue_head(&dev->atrq); in cm4000_probe()
1812 init_waitqueue_head(&dev->readq); in cm4000_probe()
1817 kfree(dev); in cm4000_probe()
1828 struct cm4000_dev *dev = link->priv; in cm4000_detach() local
1838 stop_monitor(dev); in cm4000_detach()
1843 kfree(dev); in cm4000_detach()