• Home
  • Raw
  • Download

Lines Matching +full:disable +full:- +full:dc

1 // SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
3 * nozomi.c -- HSDPA driver Broadband Wireless Data Card - Globe Trotter
18 * --------------------------------------------------------------------------
25 * --------------------------------------------------------------------------
81 if (tbuf[data_len - 2] == '\r') \
82 tbuf[data_len - 2] = 'r'; \
152 F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
153 F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
177 CTRL_ERROR = -1,
187 PORT_ERROR = -1,
196 * else A-channels must always be used.
266 * else A-channels must always be used.
335 struct nozomi *dc; member
386 return tty ? ndevs[tty->index / MAX_PORT] : NULL; in get_dc_by_tty()
392 return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL; in get_port_by_tty()
397 * -Optimize
398 * -Rewrite cleaner
425 if (size_bytes - i == 2) { in read_mem32()
444 * -Optimize
445 * -Rewrite cleaner
475 if (size_bytes - i == 2) { in write_mem32()
492 static void nozomi_setup_memory(struct nozomi *dc) in nozomi_setup_memory() argument
494 void __iomem *offset = dc->base_addr + dc->config_table.dl_start; in nozomi_setup_memory()
501 dc->port[PORT_MDM].dl_addr[CH_A] = offset; in nozomi_setup_memory()
502 dc->port[PORT_MDM].dl_addr[CH_B] = in nozomi_setup_memory()
503 (offset += dc->config_table.dl_mdm_len1); in nozomi_setup_memory()
504 dc->port[PORT_MDM].dl_size[CH_A] = in nozomi_setup_memory()
505 dc->config_table.dl_mdm_len1 - buff_offset; in nozomi_setup_memory()
506 dc->port[PORT_MDM].dl_size[CH_B] = in nozomi_setup_memory()
507 dc->config_table.dl_mdm_len2 - buff_offset; in nozomi_setup_memory()
510 dc->port[PORT_DIAG].dl_addr[CH_A] = in nozomi_setup_memory()
511 (offset += dc->config_table.dl_mdm_len2); in nozomi_setup_memory()
512 dc->port[PORT_DIAG].dl_size[CH_A] = in nozomi_setup_memory()
513 dc->config_table.dl_diag_len1 - buff_offset; in nozomi_setup_memory()
514 dc->port[PORT_DIAG].dl_addr[CH_B] = in nozomi_setup_memory()
515 (offset += dc->config_table.dl_diag_len1); in nozomi_setup_memory()
516 dc->port[PORT_DIAG].dl_size[CH_B] = in nozomi_setup_memory()
517 dc->config_table.dl_diag_len2 - buff_offset; in nozomi_setup_memory()
520 dc->port[PORT_APP1].dl_addr[CH_A] = in nozomi_setup_memory()
521 (offset += dc->config_table.dl_diag_len2); in nozomi_setup_memory()
522 dc->port[PORT_APP1].dl_size[CH_A] = in nozomi_setup_memory()
523 dc->config_table.dl_app1_len - buff_offset; in nozomi_setup_memory()
526 dc->port[PORT_APP2].dl_addr[CH_A] = in nozomi_setup_memory()
527 (offset += dc->config_table.dl_app1_len); in nozomi_setup_memory()
528 dc->port[PORT_APP2].dl_size[CH_A] = in nozomi_setup_memory()
529 dc->config_table.dl_app2_len - buff_offset; in nozomi_setup_memory()
532 dc->port[PORT_CTRL].dl_addr[CH_A] = in nozomi_setup_memory()
533 (offset += dc->config_table.dl_app2_len); in nozomi_setup_memory()
534 dc->port[PORT_CTRL].dl_size[CH_A] = in nozomi_setup_memory()
535 dc->config_table.dl_ctrl_len - buff_offset; in nozomi_setup_memory()
537 offset = dc->base_addr + dc->config_table.ul_start; in nozomi_setup_memory()
540 dc->port[PORT_MDM].ul_addr[CH_A] = offset; in nozomi_setup_memory()
541 dc->port[PORT_MDM].ul_size[CH_A] = in nozomi_setup_memory()
542 dc->config_table.ul_mdm_len1 - buff_offset; in nozomi_setup_memory()
543 dc->port[PORT_MDM].ul_addr[CH_B] = in nozomi_setup_memory()
544 (offset += dc->config_table.ul_mdm_len1); in nozomi_setup_memory()
545 dc->port[PORT_MDM].ul_size[CH_B] = in nozomi_setup_memory()
546 dc->config_table.ul_mdm_len2 - buff_offset; in nozomi_setup_memory()
549 dc->port[PORT_DIAG].ul_addr[CH_A] = in nozomi_setup_memory()
550 (offset += dc->config_table.ul_mdm_len2); in nozomi_setup_memory()
551 dc->port[PORT_DIAG].ul_size[CH_A] = in nozomi_setup_memory()
552 dc->config_table.ul_diag_len - buff_offset; in nozomi_setup_memory()
555 dc->port[PORT_APP1].ul_addr[CH_A] = in nozomi_setup_memory()
556 (offset += dc->config_table.ul_diag_len); in nozomi_setup_memory()
557 dc->port[PORT_APP1].ul_size[CH_A] = in nozomi_setup_memory()
558 dc->config_table.ul_app1_len - buff_offset; in nozomi_setup_memory()
561 dc->port[PORT_APP2].ul_addr[CH_A] = in nozomi_setup_memory()
562 (offset += dc->config_table.ul_app1_len); in nozomi_setup_memory()
563 dc->port[PORT_APP2].ul_size[CH_A] = in nozomi_setup_memory()
564 dc->config_table.ul_app2_len - buff_offset; in nozomi_setup_memory()
567 dc->port[PORT_CTRL].ul_addr[CH_A] = in nozomi_setup_memory()
568 (offset += dc->config_table.ul_app2_len); in nozomi_setup_memory()
569 dc->port[PORT_CTRL].ul_size[CH_A] = in nozomi_setup_memory()
570 dc->config_table.ul_ctrl_len - buff_offset; in nozomi_setup_memory()
575 static void dump_table(const struct nozomi *dc) in dump_table() argument
577 DBG3("signature: 0x%08X", dc->config_table.signature); in dump_table()
578 DBG3("version: 0x%04X", dc->config_table.version); in dump_table()
580 dc->config_table.product_information); in dump_table()
581 DBG3("toggle enabled: %d", dc->config_table.toggle.enabled); in dump_table()
582 DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul); in dump_table()
583 DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl); in dump_table()
584 DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl); in dump_table()
586 DBG3("dl_start: 0x%04X", dc->config_table.dl_start); in dump_table()
587 DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1, in dump_table()
588 dc->config_table.dl_mdm_len1); in dump_table()
589 DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2, in dump_table()
590 dc->config_table.dl_mdm_len2); in dump_table()
591 DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1, in dump_table()
592 dc->config_table.dl_diag_len1); in dump_table()
593 DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2, in dump_table()
594 dc->config_table.dl_diag_len2); in dump_table()
595 DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len, in dump_table()
596 dc->config_table.dl_app1_len); in dump_table()
597 DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len, in dump_table()
598 dc->config_table.dl_app2_len); in dump_table()
599 DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len, in dump_table()
600 dc->config_table.dl_ctrl_len); in dump_table()
601 DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start, in dump_table()
602 dc->config_table.ul_start); in dump_table()
603 DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1, in dump_table()
604 dc->config_table.ul_mdm_len1); in dump_table()
605 DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2, in dump_table()
606 dc->config_table.ul_mdm_len2); in dump_table()
607 DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len, in dump_table()
608 dc->config_table.ul_diag_len); in dump_table()
609 DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len, in dump_table()
610 dc->config_table.ul_app1_len); in dump_table()
611 DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len, in dump_table()
612 dc->config_table.ul_app2_len); in dump_table()
613 DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len, in dump_table()
614 dc->config_table.ul_ctrl_len); in dump_table()
617 static inline void dump_table(const struct nozomi *dc) { } in dump_table() argument
624 static int nozomi_read_config_table(struct nozomi *dc) in nozomi_read_config_table() argument
626 read_mem32((u32 *) &dc->config_table, dc->base_addr + 0, in nozomi_read_config_table()
629 if (dc->config_table.signature != NOZOMI_CONFIG_MAGIC) { in nozomi_read_config_table()
630 dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n", in nozomi_read_config_table()
631 dc->config_table.signature, NOZOMI_CONFIG_MAGIC); in nozomi_read_config_table()
635 if ((dc->config_table.version == 0) in nozomi_read_config_table()
636 || (dc->config_table.toggle.enabled == TOGGLE_VALID)) { in nozomi_read_config_table()
640 nozomi_setup_memory(dc); in nozomi_read_config_table()
642 dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul; in nozomi_read_config_table()
643 dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl; in nozomi_read_config_table()
644 dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl; in nozomi_read_config_table()
646 dc->port[PORT_MDM].toggle_ul, in nozomi_read_config_table()
647 dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl); in nozomi_read_config_table()
649 dump_table(dc); in nozomi_read_config_table()
652 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); in nozomi_read_config_table()
653 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); in nozomi_read_config_table()
657 dc->last_ier = dc->last_ier | CTRL_DL; in nozomi_read_config_table()
658 writew(dc->last_ier, dc->reg_ier); in nozomi_read_config_table()
660 dc->state = NOZOMI_STATE_ALLOCATED; in nozomi_read_config_table()
661 dev_info(&dc->pdev->dev, "Initialization OK!\n"); in nozomi_read_config_table()
665 if ((dc->config_table.version > 0) in nozomi_read_config_table()
666 && (dc->config_table.toggle.enabled != TOGGLE_VALID)) { in nozomi_read_config_table()
670 dev_info(&dc->pdev->dev, "Version of card: %d\n", in nozomi_read_config_table()
671 dc->config_table.version); in nozomi_read_config_table()
673 /* Here we should disable all I/O over F32. */ in nozomi_read_config_table()
674 nozomi_setup_memory(dc); in nozomi_read_config_table()
682 write_mem32(dc->port[PORT_MDM].ul_addr[CH_A], in nozomi_read_config_table()
684 write_mem32(dc->port[PORT_MDM].ul_addr[CH_B], in nozomi_read_config_table()
687 writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr); in nozomi_read_config_table()
696 static void enable_transmit_ul(enum port_type port, struct nozomi *dc) in enable_transmit_ul() argument
701 dc->last_ier |= mask[port]; in enable_transmit_ul()
702 writew(dc->last_ier, dc->reg_ier); in enable_transmit_ul()
704 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in enable_transmit_ul()
708 /* Disable uplink interrupts */
709 static void disable_transmit_ul(enum port_type port, struct nozomi *dc) in disable_transmit_ul() argument
715 dc->last_ier &= mask[port]; in disable_transmit_ul()
716 writew(dc->last_ier, dc->reg_ier); in disable_transmit_ul()
718 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in disable_transmit_ul()
723 static void enable_transmit_dl(enum port_type port, struct nozomi *dc) in enable_transmit_dl() argument
728 dc->last_ier |= mask[port]; in enable_transmit_dl()
729 writew(dc->last_ier, dc->reg_ier); in enable_transmit_dl()
731 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in enable_transmit_dl()
735 /* Disable downlink interrupts */
736 static void disable_transmit_dl(enum port_type port, struct nozomi *dc) in disable_transmit_dl() argument
742 dc->last_ier &= mask[port]; in disable_transmit_dl()
743 writew(dc->last_ier, dc->reg_ier); in disable_transmit_dl()
745 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in disable_transmit_dl()
750 * Return 1 - send buffer to card and ack.
751 * Return 0 - don't ack, don't send buffer to card.
753 static int send_data(enum port_type index, struct nozomi *dc) in send_data() argument
756 struct port *port = &dc->port[index]; in send_data()
757 const u8 toggle = port->toggle_ul; in send_data()
758 void __iomem *addr = port->ul_addr[toggle]; in send_data()
759 const u32 ul_size = port->ul_size[toggle]; in send_data()
762 size = kfifo_out(&port->fifo_ul, dc->send_buf, in send_data()
766 DBG4("No more data to send, disable link:"); in send_data()
774 write_mem32(addr + 4, (u32 *) dc->send_buf, size); in send_data()
776 tty_port_tty_wakeup(&port->port); in send_data()
782 static int receive_data(enum port_type index, struct nozomi *dc) in receive_data() argument
787 struct port *port = &dc->port[index]; in receive_data()
788 void __iomem *addr = port->dl_addr[port->toggle_dl]; in receive_data()
789 struct tty_struct *tty = tty_port_tty_get(&port->port); in receive_data()
797 "disable interrupt"); in receive_data()
799 /* disable interrupt in downlink... */ in receive_data()
800 disable_transmit_dl(index, dc); in receive_data()
806 dev_err(&dc->pdev->dev, "size == 0?\n"); in receive_data()
815 tty_insert_flip_char(&port->port, buf[0], TTY_NORMAL); in receive_data()
818 size -= tty_insert_flip_string(&port->port, in receive_data()
821 i = tty_insert_flip_string(&port->port, in receive_data()
823 size -= i; in receive_data()
828 set_bit(index, &dc->flip); in receive_data()
845 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_DL2 "); in interrupt2str()
847 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL1 "); in interrupt2str()
849 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL2 "); in interrupt2str()
851 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL1 "); in interrupt2str()
853 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL2 "); in interrupt2str()
856 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_UL "); in interrupt2str()
859 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_DL "); in interrupt2str()
861 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_DL "); in interrupt2str()
864 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_UL "); in interrupt2str()
866 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_UL "); in interrupt2str()
869 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_DL "); in interrupt2str()
871 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_UL "); in interrupt2str()
874 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "RESET "); in interrupt2str()
882 * Return 1 - If ok, else 0
884 static int receive_flow_control(struct nozomi *dc) in receive_flow_control() argument
891 read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2); in receive_flow_control()
914 if (dc->state == NOZOMI_STATE_ALLOCATED) { in receive_flow_control()
919 dc->state = NOZOMI_STATE_READY; in receive_flow_control()
920 dev_info(&dc->pdev->dev, "Device READY!\n"); in receive_flow_control()
924 dev_err(&dc->pdev->dev, in receive_flow_control()
925 "ERROR: flow control received for non-existing port\n"); in receive_flow_control()
929 DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl), in receive_flow_control()
932 old_ctrl = dc->port[port].ctrl_dl; in receive_flow_control()
933 dc->port[port].ctrl_dl = ctrl_dl; in receive_flow_control()
936 DBG1("Disable interrupt (0x%04X) on port: %d", in receive_flow_control()
938 disable_transmit_ul(port, dc); in receive_flow_control()
942 if (kfifo_len(&dc->port[port].fifo_ul)) { in receive_flow_control()
946 kfifo_len(&dc->port[port].fifo_ul)); in receive_flow_control()
947 enable_transmit_ul(port, dc); in receive_flow_control()
959 dc->port[port].tty_icount.cts++; in receive_flow_control()
961 dc->port[port].tty_icount.dsr++; in receive_flow_control()
963 dc->port[port].tty_icount.rng++; in receive_flow_control()
965 dc->port[port].tty_icount.dcd++; in receive_flow_control()
967 wake_up_interruptible(&dc->port[port].tty_wait); in receive_flow_control()
971 dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts, in receive_flow_control()
972 dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr); in receive_flow_control()
978 const struct nozomi *dc) in port2ctrl() argument
990 dev_err(&dc->pdev->dev, in port2ctrl()
992 "received for non-existing port\n"); in port2ctrl()
999 * Return 0 - If we have updated all flow control
1000 * Return 1 - If we need to update more flow control, ack current enable more
1002 static int send_flow_control(struct nozomi *dc) in send_flow_control() argument
1008 if (dc->port[i].update_flow_control) { in send_flow_control()
1013 dc->port[i].ctrl_ul.port = port2ctrl(i, dc); in send_flow_control()
1014 ctrl = (u16 *)&dc->port[i].ctrl_ul; in send_flow_control()
1015 write_mem32(dc->port[PORT_CTRL].ul_addr[0], \ in send_flow_control()
1017 dc->port[i].update_flow_control = 0; in send_flow_control()
1026 * Return 1 - ok
1027 * Return 0 - toggle fields are out of sync
1029 static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle, in handle_data_dl() argument
1033 if (receive_data(port, dc)) { in handle_data_dl()
1034 writew(mask1, dc->reg_fcr); in handle_data_dl()
1039 if (receive_data(port, dc)) { in handle_data_dl()
1040 writew(mask2, dc->reg_fcr); in handle_data_dl()
1045 if (receive_data(port, dc)) { in handle_data_dl()
1046 writew(mask2, dc->reg_fcr); in handle_data_dl()
1051 if (receive_data(port, dc)) { in handle_data_dl()
1052 writew(mask1, dc->reg_fcr); in handle_data_dl()
1057 dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n", in handle_data_dl()
1066 * Return 1 - ok
1067 * Return 0 - toggle field are out of sync
1069 static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir) in handle_data_ul() argument
1071 u8 *toggle = &(dc->port[port].toggle_ul); in handle_data_ul()
1074 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1075 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1076 if (send_data(port, dc)) { in handle_data_ul()
1077 writew(MDM_UL1, dc->reg_fcr); in handle_data_ul()
1078 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1079 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1084 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1085 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1086 if (send_data(port, dc)) { in handle_data_ul()
1087 writew(MDM_UL2, dc->reg_fcr); in handle_data_ul()
1088 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1089 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1095 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1096 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1097 if (send_data(port, dc)) { in handle_data_ul()
1098 writew(MDM_UL2, dc->reg_fcr); in handle_data_ul()
1099 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1100 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1105 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1106 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1107 if (send_data(port, dc)) { in handle_data_ul()
1108 writew(MDM_UL1, dc->reg_fcr); in handle_data_ul()
1109 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1110 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1115 writew(read_iir & MDM_UL, dc->reg_fcr); in handle_data_ul()
1116 dev_err(&dc->pdev->dev, "port out of sync!\n"); in handle_data_ul()
1124 struct nozomi *dc = dev_id; in interrupt_handler() local
1128 if (!dc) in interrupt_handler()
1131 spin_lock(&dc->spin_mutex); in interrupt_handler()
1132 read_iir = readw(dc->reg_iir); in interrupt_handler()
1135 if (read_iir == (u16)-1) in interrupt_handler()
1139 * (by masking with dc->last_ier) in interrupt_handler()
1141 read_iir &= dc->last_ier; in interrupt_handler()
1148 dc->last_ier); in interrupt_handler()
1151 if (unlikely(!nozomi_read_config_table(dc))) { in interrupt_handler()
1152 dc->last_ier = 0x0; in interrupt_handler()
1153 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1154 dev_err(&dc->pdev->dev, "Could not read status from " in interrupt_handler()
1155 "card, we should disable interface\n"); in interrupt_handler()
1157 writew(RESET, dc->reg_fcr); in interrupt_handler()
1164 dc->last_ier &= ~CTRL_UL; in interrupt_handler()
1165 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1166 if (send_flow_control(dc)) { in interrupt_handler()
1167 writew(CTRL_UL, dc->reg_fcr); in interrupt_handler()
1168 dc->last_ier = dc->last_ier | CTRL_UL; in interrupt_handler()
1169 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1173 receive_flow_control(dc); in interrupt_handler()
1174 writew(CTRL_DL, dc->reg_fcr); in interrupt_handler()
1177 if (!handle_data_dl(dc, PORT_MDM, in interrupt_handler()
1178 &(dc->port[PORT_MDM].toggle_dl), read_iir, in interrupt_handler()
1180 dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n"); in interrupt_handler()
1185 if (!handle_data_ul(dc, PORT_MDM, read_iir)) { in interrupt_handler()
1186 dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n"); in interrupt_handler()
1191 if (!handle_data_dl(dc, PORT_DIAG, in interrupt_handler()
1192 &(dc->port[PORT_DIAG].toggle_dl), read_iir, in interrupt_handler()
1194 dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n"); in interrupt_handler()
1199 dc->last_ier &= ~DIAG_UL; in interrupt_handler()
1200 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1201 if (send_data(PORT_DIAG, dc)) { in interrupt_handler()
1202 writew(DIAG_UL, dc->reg_fcr); in interrupt_handler()
1203 dc->last_ier = dc->last_ier | DIAG_UL; in interrupt_handler()
1204 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1208 if (receive_data(PORT_APP1, dc)) in interrupt_handler()
1209 writew(APP1_DL, dc->reg_fcr); in interrupt_handler()
1212 dc->last_ier &= ~APP1_UL; in interrupt_handler()
1213 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1214 if (send_data(PORT_APP1, dc)) { in interrupt_handler()
1215 writew(APP1_UL, dc->reg_fcr); in interrupt_handler()
1216 dc->last_ier = dc->last_ier | APP1_UL; in interrupt_handler()
1217 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1221 if (receive_data(PORT_APP2, dc)) in interrupt_handler()
1222 writew(APP2_DL, dc->reg_fcr); in interrupt_handler()
1225 dc->last_ier &= ~APP2_UL; in interrupt_handler()
1226 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1227 if (send_data(PORT_APP2, dc)) { in interrupt_handler()
1228 writew(APP2_UL, dc->reg_fcr); in interrupt_handler()
1229 dc->last_ier = dc->last_ier | APP2_UL; in interrupt_handler()
1230 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1235 spin_unlock(&dc->spin_mutex); in interrupt_handler()
1238 if (test_and_clear_bit(a, &dc->flip)) in interrupt_handler()
1239 tty_flip_buffer_push(&dc->port[a].port); in interrupt_handler()
1243 spin_unlock(&dc->spin_mutex); in interrupt_handler()
1247 static void nozomi_get_card_type(struct nozomi *dc) in nozomi_get_card_type() argument
1253 size += pci_resource_len(dc->pdev, i); in nozomi_get_card_type()
1256 dc->card_type = size == 2048 ? F32_2 : F32_8; in nozomi_get_card_type()
1258 dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type); in nozomi_get_card_type()
1261 static void nozomi_setup_private_data(struct nozomi *dc) in nozomi_setup_private_data() argument
1263 void __iomem *offset = dc->base_addr + dc->card_type / 2; in nozomi_setup_private_data()
1266 dc->reg_fcr = (void __iomem *)(offset + R_FCR); in nozomi_setup_private_data()
1267 dc->reg_iir = (void __iomem *)(offset + R_IIR); in nozomi_setup_private_data()
1268 dc->reg_ier = (void __iomem *)(offset + R_IER); in nozomi_setup_private_data()
1269 dc->last_ier = 0; in nozomi_setup_private_data()
1270 dc->flip = 0; in nozomi_setup_private_data()
1272 dc->port[PORT_MDM].token_dl = MDM_DL; in nozomi_setup_private_data()
1273 dc->port[PORT_DIAG].token_dl = DIAG_DL; in nozomi_setup_private_data()
1274 dc->port[PORT_APP1].token_dl = APP1_DL; in nozomi_setup_private_data()
1275 dc->port[PORT_APP2].token_dl = APP2_DL; in nozomi_setup_private_data()
1278 init_waitqueue_head(&dc->port[i].tty_wait); in nozomi_setup_private_data()
1284 const struct nozomi *dc = dev_get_drvdata(dev); in card_type_show() local
1286 return sprintf(buf, "%d\n", dc->card_type); in card_type_show()
1293 const struct nozomi *dc = dev_get_drvdata(dev); in open_ttys_show() local
1295 return sprintf(buf, "%u\n", dc->open_ttys); in open_ttys_show()
1299 static void make_sysfs_files(struct nozomi *dc) in make_sysfs_files() argument
1301 if (device_create_file(&dc->pdev->dev, &dev_attr_card_type)) in make_sysfs_files()
1302 dev_err(&dc->pdev->dev, in make_sysfs_files()
1304 if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys)) in make_sysfs_files()
1305 dev_err(&dc->pdev->dev, in make_sysfs_files()
1309 static void remove_sysfs_files(struct nozomi *dc) in remove_sysfs_files() argument
1311 device_remove_file(&dc->pdev->dev, &dev_attr_card_type); in remove_sysfs_files()
1312 device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys); in remove_sysfs_files()
1320 struct nozomi *dc = NULL; in nozomi_card_init() local
1324 dev_dbg(&pdev->dev, "Init, new card found\n"); in nozomi_card_init()
1331 dev_err(&pdev->dev, "no free tty range for this card left\n"); in nozomi_card_init()
1332 ret = -EIO; in nozomi_card_init()
1336 dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL); in nozomi_card_init()
1337 if (unlikely(!dc)) { in nozomi_card_init()
1338 dev_err(&pdev->dev, "Could not allocate memory\n"); in nozomi_card_init()
1339 ret = -ENOMEM; in nozomi_card_init()
1343 dc->pdev = pdev; in nozomi_card_init()
1345 ret = pci_enable_device(dc->pdev); in nozomi_card_init()
1347 dev_err(&pdev->dev, "Failed to enable PCI Device\n"); in nozomi_card_init()
1351 ret = pci_request_regions(dc->pdev, NOZOMI_NAME); in nozomi_card_init()
1353 dev_err(&pdev->dev, "I/O address 0x%04x already in use\n", in nozomi_card_init()
1359 nozomi_get_card_type(dc); in nozomi_card_init()
1361 dc->base_addr = pci_iomap(dc->pdev, 0, dc->card_type); in nozomi_card_init()
1362 if (!dc->base_addr) { in nozomi_card_init()
1363 dev_err(&pdev->dev, "Unable to map card MMIO\n"); in nozomi_card_init()
1364 ret = -ENODEV; in nozomi_card_init()
1368 dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL); in nozomi_card_init()
1369 if (!dc->send_buf) { in nozomi_card_init()
1370 dev_err(&pdev->dev, "Could not allocate send buffer?\n"); in nozomi_card_init()
1371 ret = -ENOMEM; in nozomi_card_init()
1376 if (kfifo_alloc(&dc->port[i].fifo_ul, FIFO_BUFFER_SIZE_UL, in nozomi_card_init()
1378 dev_err(&pdev->dev, in nozomi_card_init()
1380 ret = -ENOMEM; in nozomi_card_init()
1385 spin_lock_init(&dc->spin_mutex); in nozomi_card_init()
1387 nozomi_setup_private_data(dc); in nozomi_card_init()
1389 /* Disable all interrupts */ in nozomi_card_init()
1390 dc->last_ier = 0; in nozomi_card_init()
1391 writew(dc->last_ier, dc->reg_ier); in nozomi_card_init()
1393 ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED, in nozomi_card_init()
1394 NOZOMI_NAME, dc); in nozomi_card_init()
1396 dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq); in nozomi_card_init()
1400 DBG1("base_addr: %p", dc->base_addr); in nozomi_card_init()
1402 make_sysfs_files(dc); in nozomi_card_init()
1404 dc->index_start = ndev_idx * MAX_PORT; in nozomi_card_init()
1405 ndevs[ndev_idx] = dc; in nozomi_card_init()
1407 pci_set_drvdata(pdev, dc); in nozomi_card_init()
1410 dc->last_ier = RESET; in nozomi_card_init()
1411 iowrite16(dc->last_ier, dc->reg_ier); in nozomi_card_init()
1413 dc->state = NOZOMI_STATE_ENABLED; in nozomi_card_init()
1417 struct port *port = &dc->port[i]; in nozomi_card_init()
1418 port->dc = dc; in nozomi_card_init()
1419 tty_port_init(&port->port); in nozomi_card_init()
1420 port->port.ops = &noz_tty_port_ops; in nozomi_card_init()
1421 tty_dev = tty_port_register_device(&port->port, ntty_driver, in nozomi_card_init()
1422 dc->index_start + i, &pdev->dev); in nozomi_card_init()
1426 dev_err(&pdev->dev, "Could not allocate tty?\n"); in nozomi_card_init()
1427 tty_port_destroy(&port->port); in nozomi_card_init()
1435 for (i--; i >= 0; i--) { in nozomi_card_init()
1436 tty_unregister_device(ntty_driver, dc->index_start + i); in nozomi_card_init()
1437 tty_port_destroy(&dc->port[i].port); in nozomi_card_init()
1439 free_irq(pdev->irq, dc); in nozomi_card_init()
1443 for (i--; i >= PORT_MDM; i--) in nozomi_card_init()
1444 kfifo_free(&dc->port[i].fifo_ul); in nozomi_card_init()
1446 kfree(dc->send_buf); in nozomi_card_init()
1447 iounmap(dc->base_addr); in nozomi_card_init()
1453 kfree(dc); in nozomi_card_init()
1458 static void tty_exit(struct nozomi *dc) in tty_exit() argument
1465 tty_port_tty_hangup(&dc->port[i].port, false); in tty_exit()
1467 /* Racy below - surely should wait for scheduled work to be done or in tty_exit()
1469 while (dc->open_ttys) in tty_exit()
1472 tty_unregister_device(ntty_driver, dc->index_start + i); in tty_exit()
1473 tty_port_destroy(&dc->port[i].port); in tty_exit()
1482 struct nozomi *dc = pci_get_drvdata(pdev); in nozomi_card_exit() local
1484 /* Disable all interrupts */ in nozomi_card_exit()
1485 dc->last_ier = 0; in nozomi_card_exit()
1486 writew(dc->last_ier, dc->reg_ier); in nozomi_card_exit()
1488 tty_exit(dc); in nozomi_card_exit()
1498 /* Setup dc->reg addresses to we can use defines here */ in nozomi_card_exit()
1499 write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2); in nozomi_card_exit()
1500 writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */ in nozomi_card_exit()
1502 remove_sysfs_files(dc); in nozomi_card_exit()
1504 free_irq(pdev->irq, dc); in nozomi_card_exit()
1507 kfifo_free(&dc->port[i].fifo_ul); in nozomi_card_exit()
1509 kfree(dc->send_buf); in nozomi_card_exit()
1511 iounmap(dc->base_addr); in nozomi_card_exit()
1517 ndevs[dc->index_start / MAX_PORT] = NULL; in nozomi_card_exit()
1519 kfree(dc); in nozomi_card_exit()
1526 port->ctrl_ul.RTS = rts; in set_rts()
1527 port->update_flow_control = 1; in set_rts()
1535 DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr); in set_dtr()
1537 port->ctrl_ul.DTR = dtr; in set_dtr()
1538 port->update_flow_control = 1; in set_dtr()
1543 * ----------------------------------------------------------------------------
1545 * ----------------------------------------------------------------------------
1551 struct nozomi *dc = get_dc_by_tty(tty); in ntty_install() local
1553 if (!port || !dc || dc->state != NOZOMI_STATE_READY) in ntty_install()
1554 return -ENODEV; in ntty_install()
1557 tty->driver_data = port; in ntty_install()
1563 tty->driver_data = NULL; in ntty_cleanup()
1569 struct nozomi *dc = port->dc; in ntty_activate() local
1572 DBG1("open: %d", port->token_dl); in ntty_activate()
1573 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_activate()
1574 dc->last_ier = dc->last_ier | port->token_dl; in ntty_activate()
1575 writew(dc->last_ier, dc->reg_ier); in ntty_activate()
1576 dc->open_ttys++; in ntty_activate()
1577 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_activate()
1578 printk("noz: activated %d: %p\n", tty->index, tport); in ntty_activate()
1584 struct port *port = tty->driver_data; in ntty_open()
1585 return tty_port_open(&port->port, tty, filp); in ntty_open()
1591 struct nozomi *dc = port->dc; in ntty_shutdown() local
1594 DBG1("close: %d", port->token_dl); in ntty_shutdown()
1595 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_shutdown()
1596 dc->last_ier &= ~(port->token_dl); in ntty_shutdown()
1597 writew(dc->last_ier, dc->reg_ier); in ntty_shutdown()
1598 dc->open_ttys--; in ntty_shutdown()
1599 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_shutdown()
1605 struct port *port = tty->driver_data; in ntty_close()
1607 tty_port_close(&port->port, tty, filp); in ntty_close()
1612 struct port *port = tty->driver_data; in ntty_hangup()
1613 tty_port_hangup(&port->port); in ntty_hangup()
1623 int rval = -EINVAL; in ntty_write()
1624 struct nozomi *dc = get_dc_by_tty(tty); in ntty_write() local
1625 struct port *port = tty->driver_data; in ntty_write()
1630 if (!dc || !port) in ntty_write()
1631 return -ENODEV; in ntty_write()
1633 rval = kfifo_in(&port->fifo_ul, (unsigned char *)buffer, count); in ntty_write()
1635 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_write()
1637 if (port == &(dc->port[PORT_MDM])) { in ntty_write()
1638 if (port->ctrl_dl.CTS) { in ntty_write()
1640 enable_transmit_ul(tty->index % MAX_PORT, dc); in ntty_write()
1642 dev_err(&dc->pdev->dev, in ntty_write()
1646 enable_transmit_ul(tty->index % MAX_PORT, dc); in ntty_write()
1648 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_write()
1664 struct port *port = tty->driver_data; in ntty_write_room()
1666 const struct nozomi *dc = get_dc_by_tty(tty); in ntty_write_room() local
1668 if (dc) in ntty_write_room()
1669 room = kfifo_avail(&port->fifo_ul); in ntty_write_room()
1677 const struct port *port = tty->driver_data; in ntty_tiocmget()
1678 const struct ctrl_dl *ctrl_dl = &port->ctrl_dl; in ntty_tiocmget()
1679 const struct ctrl_ul *ctrl_ul = &port->ctrl_ul; in ntty_tiocmget()
1683 return (ctrl_ul->RTS ? TIOCM_RTS : 0) in ntty_tiocmget()
1684 | (ctrl_ul->DTR ? TIOCM_DTR : 0) in ntty_tiocmget()
1685 | (ctrl_dl->DCD ? TIOCM_CAR : 0) in ntty_tiocmget()
1686 | (ctrl_dl->RI ? TIOCM_RNG : 0) in ntty_tiocmget()
1687 | (ctrl_dl->DSR ? TIOCM_DSR : 0) in ntty_tiocmget()
1688 | (ctrl_dl->CTS ? TIOCM_CTS : 0); in ntty_tiocmget()
1695 struct nozomi *dc = get_dc_by_tty(tty); in ntty_tiocmset() local
1698 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_tiocmset()
1708 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_tiocmset()
1716 const struct async_icount cnow = port->tty_icount; in ntty_cflags_changed()
1719 ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) in ntty_cflags_changed()
1720 || ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) in ntty_cflags_changed()
1721 || ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd)) in ntty_cflags_changed()
1722 || ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts)); in ntty_cflags_changed()
1732 struct port *port = tty->driver_data; in ntty_tiocgicount()
1733 const struct async_icount cnow = port->tty_icount; in ntty_tiocgicount()
1735 icount->cts = cnow.cts; in ntty_tiocgicount()
1736 icount->dsr = cnow.dsr; in ntty_tiocgicount()
1737 icount->rng = cnow.rng; in ntty_tiocgicount()
1738 icount->dcd = cnow.dcd; in ntty_tiocgicount()
1739 icount->rx = cnow.rx; in ntty_tiocgicount()
1740 icount->tx = cnow.tx; in ntty_tiocgicount()
1741 icount->frame = cnow.frame; in ntty_tiocgicount()
1742 icount->overrun = cnow.overrun; in ntty_tiocgicount()
1743 icount->parity = cnow.parity; in ntty_tiocgicount()
1744 icount->brk = cnow.brk; in ntty_tiocgicount()
1745 icount->buf_overrun = cnow.buf_overrun; in ntty_tiocgicount()
1752 struct port *port = tty->driver_data; in ntty_ioctl()
1753 int rval = -ENOIOCTLCMD; in ntty_ioctl()
1759 struct async_icount cprev = port->tty_icount; in ntty_ioctl()
1761 rval = wait_event_interruptible(port->tty_wait, in ntty_ioctl()
1779 struct nozomi *dc = get_dc_by_tty(tty); in ntty_unthrottle() local
1783 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_unthrottle()
1784 enable_transmit_dl(tty->index % MAX_PORT, dc); in ntty_unthrottle()
1787 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_unthrottle()
1796 struct nozomi *dc = get_dc_by_tty(tty); in ntty_throttle() local
1800 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_throttle()
1802 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_throttle()
1808 struct port *port = tty->driver_data; in ntty_chars_in_buffer()
1809 struct nozomi *dc = get_dc_by_tty(tty); in ntty_chars_in_buffer() local
1812 if (unlikely(!dc || !port)) { in ntty_chars_in_buffer()
1816 rval = kfifo_len(&port->fifo_ul); in ntty_chars_in_buffer()
1860 return -ENOMEM; in nozomi_init()
1862 ntty_driver->driver_name = NOZOMI_NAME_TTY; in nozomi_init()
1863 ntty_driver->name = "noz"; in nozomi_init()
1864 ntty_driver->major = 0; in nozomi_init()
1865 ntty_driver->type = TTY_DRIVER_TYPE_SERIAL; in nozomi_init()
1866 ntty_driver->subtype = SERIAL_TYPE_NORMAL; in nozomi_init()
1867 ntty_driver->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV; in nozomi_init()
1868 ntty_driver->init_termios = tty_std_termios; in nozomi_init()
1869 ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \ in nozomi_init()
1871 ntty_driver->init_termios.c_ispeed = 115200; in nozomi_init()
1872 ntty_driver->init_termios.c_ospeed = 115200; in nozomi_init()