Lines Matching +full:v +full:- +full:pos +full:- +full:supply

1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * yam.c -- YAM radio modem driver.
15 * 0.0 F1OAT 06.06.98 Begin of work with baycom.c source code V 0.3
61 /* --------------------------------------------------------------------- */
67 /* --------------------------------------------------------------------- */
94 #define DEFAULT_PERS 64 /* 0->255 */
147 /* --------------------------------------------------------------------- */
219 /* YAM Modem <-> UART Port mapping */
301 /* turn off FPGA supply voltage */
304 /* turn on FPGA supply voltage again */
326 return -1;
352 predef--;
358 err = request_firmware(&fw, fw_name[predef], &pdev->dev);
365 if (fw->size != YAM_FPGA_SIZE) {
367 fw->size, fw_name[predef]);
371 bits = (unsigned char *)fw->data;
381 if (p->bitrate == bitrate) {
382 memcpy(p->bits, bits, YAM_FPGA_SIZE);
385 p = p->next;
393 memcpy(p->bits, bits, YAM_FPGA_SIZE);
394 p->bitrate = bitrate;
395 p->next = yam_data;
399 return p->bits;
408 if (p->bitrate == bitrate)
409 return p->bits;
410 p = p->next;
436 return -1;
442 return -1; /* write... */
452 return (rc & MSR_DSR) ? 0 : -1;
463 int divisor = 115200 / yp->baudrate;
465 outb(0, IER(dev->base_addr));
466 outb(LCR_DLAB | LCR_BIT8, LCR(dev->base_addr));
467 outb(divisor, DLL(dev->base_addr));
468 outb(0, DLM(dev->base_addr));
469 outb(LCR_BIT8, LCR(dev->base_addr));
470 outb(PTT_OFF, MCR(dev->base_addr));
471 outb(0x00, FCR(dev->base_addr));
475 inb(RBR(dev->base_addr));
476 inb(MSR(dev->base_addr));
480 outb(ENABLE_RTXINT, IER(dev->base_addr));
484 /* --------------------------------------------------------------------- */
530 if (yp->dcd && yp->rx_len >= 3 && yp->rx_len < YAM_MAX_FRAME) {
531 int pkt_len = yp->rx_len - 2 + 1; /* -CRC + kiss */
534 if ((yp->rx_crch & yp->rx_crcl) != 0xFF) {
538 printk(KERN_WARNING "%s: memory squeeze, dropping packet\n", dev->name);
539 ++dev->stats.rx_dropped;
544 memcpy(cp, yp->rx_buf, pkt_len - 1);
545 skb->protocol = ax25_type_trans(skb, dev);
547 ++dev->stats.rx_packets;
551 yp->rx_len = 0;
552 yp->rx_crcl = 0x21;
553 yp->rx_crch = 0xf3;
558 if (yp->rx_len < YAM_MAX_FRAME) {
559 unsigned char c = yp->rx_crcl;
560 yp->rx_crcl = (chktabl[c] ^ yp->rx_crch);
561 yp->rx_crch = (chktabh[c] ^ rxb);
562 yp->rx_buf[yp->rx_len++] = rxb;
572 outb(PTT_ON, MCR(dev->base_addr));
577 outb(PTT_OFF, MCR(dev->base_addr));
585 if (skb->protocol == htons(ETH_P_IP))
588 skb_queue_tail(&yp->send_queue, skb);
595 if ((yp->tx_state == TX_TAIL) || (yp->txd == 0))
596 yp->tx_count = 1;
598 yp->tx_count = (yp->bitrate * yp->txd) / 8000;
599 yp->tx_state = TX_HEAD;
607 if (yp->magic != YAM_MAGIC || yp->tx_state != TX_OFF ||
608 skb_queue_empty(&yp->send_queue))
612 if (yp->dupmode) {
617 if (yp->dcd) {
619 yp->slotcnt = yp->slot / 10;
623 if ((--yp->slotcnt) > 0)
626 yp->slotcnt = yp->slot / 10;
629 if (get_random_u8() > yp->pers)
653 switch (yp->tx_state) {
657 if (--yp->tx_count <= 0) {
658 if (!(skb = skb_dequeue(&yp->send_queue))) {
660 yp->tx_state = TX_OFF;
663 yp->tx_state = TX_DATA;
664 if (skb->data[0] != 0) {
665 /* do_kiss_params(s, skb->data, skb->len); */
669 yp->tx_len = skb->len - 1; /* strip KISS byte */
670 if (yp->tx_len >= YAM_MAX_FRAME || yp->tx_len < 2) {
675 yp->tx_buf,
676 yp->tx_len);
678 yp->tx_count = 0;
679 yp->tx_crcl = 0x21;
680 yp->tx_crch = 0xf3;
681 yp->tx_state = TX_DATA;
685 b = yp->tx_buf[yp->tx_count++];
686 outb(b, THR(dev->base_addr));
687 temp = yp->tx_crcl;
688 yp->tx_crcl = chktabl[temp] ^ yp->tx_crch;
689 yp->tx_crch = chktabh[temp] ^ b;
690 if (yp->tx_count >= yp->tx_len) {
691 yp->tx_state = TX_CRC1;
695 yp->tx_crch = chktabl[yp->tx_crcl] ^ yp->tx_crch;
696 yp->tx_crcl = chktabh[yp->tx_crcl] ^ chktabl[yp->tx_crch] ^ 0xff;
697 outb(yp->tx_crcl, THR(dev->base_addr));
698 yp->tx_state = TX_CRC2;
701 outb(chktabh[yp->tx_crch] ^ 0xFF, THR(dev->base_addr));
702 if (skb_queue_empty(&yp->send_queue)) {
703 yp->tx_count = (yp->bitrate * yp->txtail) / 8000;
704 if (yp->dupmode == 2)
705 yp->tx_count += (yp->bitrate * yp->holdd) / 8;
706 if (yp->tx_count == 0)
707 yp->tx_count = 1;
708 yp->tx_state = TX_TAIL;
710 yp->tx_count = 1;
711 yp->tx_state = TX_HEAD;
713 ++dev->stats.tx_packets;
716 if (--yp->tx_count <= 0) {
717 yp->tx_state = TX_OFF;
744 while ((iir = IIR_MASK & inb(IIR(dev->base_addr))) != IIR_NOPEND) {
745 unsigned char msr = inb(MSR(dev->base_addr));
746 unsigned char lsr = inb(LSR(dev->base_addr));
752 ++dev->stats.rx_fifo_errors;
754 yp->dcd = (msr & RX_DCD) ? 1 : 0;
756 if (--counter <= 0) {
758 dev->name, iir);
762 ++yp->nb_mdint;
766 ++yp->nb_rxint;
767 rxb = inb(RBR(dev->base_addr));
781 static void *yam_seq_start(struct seq_file *seq, loff_t *pos)
783 return (*pos < NR_PORTS) ? yam_devs[*pos] : NULL;
786 static void *yam_seq_next(struct seq_file *seq, void *v, loff_t *pos)
788 ++*pos;
789 return (*pos < NR_PORTS) ? yam_devs[*pos] : NULL;
792 static void yam_seq_stop(struct seq_file *seq, void *v)
796 static int yam_seq_show(struct seq_file *seq, void *v)
798 struct net_device *dev = v;
801 seq_printf(seq, "Device %s\n", dev->name);
803 seq_printf(seq, " Speed %u\n", yp->bitrate);
804 seq_printf(seq, " IoBase 0x%x\n", yp->iobase);
805 seq_printf(seq, " BaudRate %u\n", yp->baudrate);
806 seq_printf(seq, " IRQ %u\n", yp->irq);
807 seq_printf(seq, " TxState %u\n", yp->tx_state);
808 seq_printf(seq, " Duplex %u\n", yp->dupmode);
809 seq_printf(seq, " HoldDly %u\n", yp->holdd);
810 seq_printf(seq, " TxDelay %u\n", yp->txd);
811 seq_printf(seq, " TxTail %u\n", yp->txtail);
812 seq_printf(seq, " SlotTime %u\n", yp->slot);
813 seq_printf(seq, " Persist %u\n", yp->pers);
814 seq_printf(seq, " TxFrames %lu\n", dev->stats.tx_packets);
815 seq_printf(seq, " RxFrames %lu\n", dev->stats.rx_packets);
816 seq_printf(seq, " TxInt %u\n", yp->nb_mdint);
817 seq_printf(seq, " RxInt %u\n", yp->nb_rxint);
818 seq_printf(seq, " RxOver %lu\n", dev->stats.rx_fifo_errors);
832 /* --------------------------------------------------------------------- */
841 printk(KERN_INFO "Trying %s at iobase 0x%lx irq %u\n", dev->name, dev->base_addr, dev->irq);
843 if (!yp->bitrate)
844 return -ENXIO;
845 if (!dev->base_addr || dev->base_addr > 0x1000 - YAM_EXTENT ||
846 dev->irq < 2 || dev->irq > 15) {
847 return -ENXIO;
849 if (!request_region(dev->base_addr, YAM_EXTENT, dev->name))
851 printk(KERN_ERR "%s: cannot 0x%lx busy\n", dev->name, dev->base_addr);
852 return -EACCES;
854 if ((u = yam_check_uart(dev->base_addr)) == c_uart_unknown) {
855 printk(KERN_ERR "%s: cannot find uart type\n", dev->name);
856 ret = -EIO;
859 if (fpga_download(dev->base_addr, yp->bitrate)) {
860 printk(KERN_ERR "%s: cannot init FPGA\n", dev->name);
861 ret = -EIO;
864 outb(0, IER(dev->base_addr));
865 if (request_irq(dev->irq, yam_interrupt, IRQF_SHARED, dev->name, dev)) {
866 printk(KERN_ERR "%s: irq %d busy\n", dev->name, dev->irq);
867 ret = -EBUSY;
875 yp->slotcnt = yp->slot / 10;
877 /* Reset overruns for all ports - FPGA programming makes overruns */
881 inb(LSR(yam_dev->base_addr));
882 yam_dev->stats.rx_fifo_errors = 0;
885 printk(KERN_INFO "%s at iobase 0x%lx irq %u uart %s\n", dev->name, dev->base_addr, dev->irq,
890 release_region(dev->base_addr, YAM_EXTENT);
894 /* --------------------------------------------------------------------- */
902 return -EINVAL;
907 outb(0, IER(dev->base_addr));
908 outb(1, MCR(dev->base_addr));
910 free_irq(dev->irq,dev);
911 release_region(dev->base_addr, YAM_EXTENT);
913 while ((skb = skb_dequeue(&yp->send_queue)))
917 yam_drvname, dev->base_addr, dev->irq);
921 /* --------------------------------------------------------------------- */
931 return -EFAULT;
933 if (yp->magic != YAM_MAGIC)
934 return -EINVAL;
937 return -EPERM;
940 return -EINVAL;
945 return -EINVAL; /* unused */
949 return -EINVAL; /* Cannot change this parameter when up */
953 if (ym->cmd != SIOCYAMSMCS || ym->bitrate > YAM_MAXBITRATE) {
955 return -EINVAL;
958 add_mcs(ym->bits, ym->bitrate, 0);
964 return -EPERM;
966 return -EFAULT;
969 return -EINVAL;
971 return -EINVAL; /* Cannot change this parameter when up */
973 return -EINVAL; /* Cannot change this parameter when up */
975 return -EINVAL; /* Cannot change this parameter when up */
977 return -EINVAL; /* Cannot change this parameter when up */
980 yp->iobase = yi.cfg.iobase;
981 dev->base_addr = yi.cfg.iobase;
985 return -EINVAL;
986 yp->irq = yi.cfg.irq;
987 dev->irq = yi.cfg.irq;
991 return -EINVAL;
992 yp->bitrate = yi.cfg.bitrate;
996 return -EINVAL;
997 yp->baudrate = yi.cfg.baudrate;
1001 return -EINVAL;
1002 yp->dupmode = yi.cfg.mode;
1006 return -EINVAL;
1007 yp->holdd = yi.cfg.holddly;
1011 return -EINVAL;
1012 yp->txd = yi.cfg.txdelay;
1016 return -EINVAL;
1017 yp->txtail = yi.cfg.txtail;
1021 return -EINVAL;
1022 yp->pers = yi.cfg.persist;
1026 return -EINVAL;
1027 yp->slot = yi.cfg.slottime;
1028 yp->slotcnt = yp->slot / 10;
1035 yi.cfg.iobase = yp->iobase;
1036 yi.cfg.irq = yp->irq;
1037 yi.cfg.bitrate = yp->bitrate;
1038 yi.cfg.baudrate = yp->baudrate;
1039 yi.cfg.mode = yp->dupmode;
1040 yi.cfg.txdelay = yp->txd;
1041 yi.cfg.holddly = yp->holdd;
1042 yi.cfg.txtail = yp->txtail;
1043 yi.cfg.persist = yp->pers;
1044 yi.cfg.slottime = yp->slot;
1046 return -EFAULT;
1050 return -EINVAL;
1057 /* --------------------------------------------------------------------- */
1064 dev_addr_set(dev, sa->sa_data);
1068 /* --------------------------------------------------------------------- */
1082 yp->magic = YAM_MAGIC;
1083 yp->bitrate = DEFAULT_BITRATE;
1084 yp->baudrate = DEFAULT_BITRATE * 2;
1085 yp->iobase = 0;
1086 yp->irq = 0;
1087 yp->dupmode = 0;
1088 yp->holdd = DEFAULT_HOLDD;
1089 yp->txd = DEFAULT_TXD;
1090 yp->txtail = DEFAULT_TXTAIL;
1091 yp->slot = DEFAULT_SLOT;
1092 yp->pers = DEFAULT_PERS;
1093 yp->dev = dev;
1095 dev->base_addr = yp->iobase;
1096 dev->irq = yp->irq;
1098 skb_queue_head_init(&yp->send_queue);
1100 dev->netdev_ops = &yam_netdev_ops;
1101 dev->header_ops = &ax25_header_ops;
1103 dev->type = ARPHRD_AX25;
1104 dev->hard_header_len = AX25_MAX_HEADER_LEN;
1105 dev->mtu = AX25_MTU;
1106 dev->addr_len = AX25_ADDR_LEN;
1107 memcpy(dev->broadcast, &ax25_bcast, AX25_ADDR_LEN);
1126 err = -ENOMEM;
1132 printk(KERN_WARNING "yam: cannot register net device %s\n", dev->name);
1147 while (--i >= 0) {
1154 /* --------------------------------------------------------------------- */
1172 yam_data = yam_data->next;
1179 /* --------------------------------------------------------------------- */
1190 /* --------------------------------------------------------------------- */