Lines Matching +full:dc +full:- +full:to +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 * --------------------------------------------------------------------------
28 /* Enable this to have a lot of debug printouts */
68 /* TODO: rewrite to optimize macros... */
78 if (tbuf[data_len - 2] == '\r') \
79 tbuf[data_len - 2] = 'r'; \
96 /* Size of tmp send buffer to card */
148 F32_2 = 2048, /* 512 bytes downlink + uplink * 2 -> 2048 */
149 F32_8 = 8192, /* 3072 bytes downl. + 1024 bytes uplink * 2 -> 8192 */
173 CTRL_ERROR = -1,
183 PORT_ERROR = -1,
192 * else A-channels must always be used.
199 /* Configuration table to read at startup of card */
262 * else A-channels must always be used.
266 /* Configuration table to read at startup of card */
331 struct nozomi *dc; member
339 /* Pointers to registers */
351 spinlock_t spin_mutex; /* secures access to registers and tty */
376 return tty ? ndevs[tty->index / MAX_PORT] : NULL; in get_dc_by_tty()
382 return ndev ? &ndev->port[tty->index % MAX_PORT] : NULL; in get_port_by_tty()
387 * -Optimize
388 * -Rewrite cleaner
413 if (size_bytes - i == 2) { in read_mem32()
432 * -Optimize
433 * -Rewrite cleaner
452 * also needs to write 4 bytes in this case in write_mem32()
462 if (size_bytes - i == 2) { in write_mem32()
478 /* Setup pointers to different channels and also setup buffer sizes. */
479 static void nozomi_setup_memory(struct nozomi *dc) in nozomi_setup_memory() argument
481 void __iomem *offset = dc->base_addr + dc->config_table.dl_start; in nozomi_setup_memory()
488 dc->port[PORT_MDM].dl_addr[CH_A] = offset; in nozomi_setup_memory()
489 dc->port[PORT_MDM].dl_addr[CH_B] = in nozomi_setup_memory()
490 (offset += dc->config_table.dl_mdm_len1); in nozomi_setup_memory()
491 dc->port[PORT_MDM].dl_size[CH_A] = in nozomi_setup_memory()
492 dc->config_table.dl_mdm_len1 - buff_offset; in nozomi_setup_memory()
493 dc->port[PORT_MDM].dl_size[CH_B] = in nozomi_setup_memory()
494 dc->config_table.dl_mdm_len2 - buff_offset; in nozomi_setup_memory()
497 dc->port[PORT_DIAG].dl_addr[CH_A] = in nozomi_setup_memory()
498 (offset += dc->config_table.dl_mdm_len2); in nozomi_setup_memory()
499 dc->port[PORT_DIAG].dl_size[CH_A] = in nozomi_setup_memory()
500 dc->config_table.dl_diag_len1 - buff_offset; in nozomi_setup_memory()
501 dc->port[PORT_DIAG].dl_addr[CH_B] = in nozomi_setup_memory()
502 (offset += dc->config_table.dl_diag_len1); in nozomi_setup_memory()
503 dc->port[PORT_DIAG].dl_size[CH_B] = in nozomi_setup_memory()
504 dc->config_table.dl_diag_len2 - buff_offset; in nozomi_setup_memory()
507 dc->port[PORT_APP1].dl_addr[CH_A] = in nozomi_setup_memory()
508 (offset += dc->config_table.dl_diag_len2); in nozomi_setup_memory()
509 dc->port[PORT_APP1].dl_size[CH_A] = in nozomi_setup_memory()
510 dc->config_table.dl_app1_len - buff_offset; in nozomi_setup_memory()
513 dc->port[PORT_APP2].dl_addr[CH_A] = in nozomi_setup_memory()
514 (offset += dc->config_table.dl_app1_len); in nozomi_setup_memory()
515 dc->port[PORT_APP2].dl_size[CH_A] = in nozomi_setup_memory()
516 dc->config_table.dl_app2_len - buff_offset; in nozomi_setup_memory()
519 dc->port[PORT_CTRL].dl_addr[CH_A] = in nozomi_setup_memory()
520 (offset += dc->config_table.dl_app2_len); in nozomi_setup_memory()
521 dc->port[PORT_CTRL].dl_size[CH_A] = in nozomi_setup_memory()
522 dc->config_table.dl_ctrl_len - buff_offset; in nozomi_setup_memory()
524 offset = dc->base_addr + dc->config_table.ul_start; in nozomi_setup_memory()
527 dc->port[PORT_MDM].ul_addr[CH_A] = offset; in nozomi_setup_memory()
528 dc->port[PORT_MDM].ul_size[CH_A] = in nozomi_setup_memory()
529 dc->config_table.ul_mdm_len1 - buff_offset; in nozomi_setup_memory()
530 dc->port[PORT_MDM].ul_addr[CH_B] = in nozomi_setup_memory()
531 (offset += dc->config_table.ul_mdm_len1); in nozomi_setup_memory()
532 dc->port[PORT_MDM].ul_size[CH_B] = in nozomi_setup_memory()
533 dc->config_table.ul_mdm_len2 - buff_offset; in nozomi_setup_memory()
536 dc->port[PORT_DIAG].ul_addr[CH_A] = in nozomi_setup_memory()
537 (offset += dc->config_table.ul_mdm_len2); in nozomi_setup_memory()
538 dc->port[PORT_DIAG].ul_size[CH_A] = in nozomi_setup_memory()
539 dc->config_table.ul_diag_len - buff_offset; in nozomi_setup_memory()
542 dc->port[PORT_APP1].ul_addr[CH_A] = in nozomi_setup_memory()
543 (offset += dc->config_table.ul_diag_len); in nozomi_setup_memory()
544 dc->port[PORT_APP1].ul_size[CH_A] = in nozomi_setup_memory()
545 dc->config_table.ul_app1_len - buff_offset; in nozomi_setup_memory()
548 dc->port[PORT_APP2].ul_addr[CH_A] = in nozomi_setup_memory()
549 (offset += dc->config_table.ul_app1_len); in nozomi_setup_memory()
550 dc->port[PORT_APP2].ul_size[CH_A] = in nozomi_setup_memory()
551 dc->config_table.ul_app2_len - buff_offset; in nozomi_setup_memory()
554 dc->port[PORT_CTRL].ul_addr[CH_A] = in nozomi_setup_memory()
555 (offset += dc->config_table.ul_app2_len); in nozomi_setup_memory()
556 dc->port[PORT_CTRL].ul_size[CH_A] = in nozomi_setup_memory()
557 dc->config_table.ul_ctrl_len - buff_offset; in nozomi_setup_memory()
562 static void dump_table(const struct nozomi *dc) in dump_table() argument
564 DBG3("signature: 0x%08X", dc->config_table.signature); in dump_table()
565 DBG3("version: 0x%04X", dc->config_table.version); in dump_table()
567 dc->config_table.product_information); in dump_table()
568 DBG3("toggle enabled: %d", dc->config_table.toggle.enabled); in dump_table()
569 DBG3("toggle up_mdm: %d", dc->config_table.toggle.mdm_ul); in dump_table()
570 DBG3("toggle dl_mdm: %d", dc->config_table.toggle.mdm_dl); in dump_table()
571 DBG3("toggle dl_dbg: %d", dc->config_table.toggle.diag_dl); in dump_table()
573 DBG3("dl_start: 0x%04X", dc->config_table.dl_start); in dump_table()
574 DBG3("dl_mdm_len0: 0x%04X, %d", dc->config_table.dl_mdm_len1, in dump_table()
575 dc->config_table.dl_mdm_len1); in dump_table()
576 DBG3("dl_mdm_len1: 0x%04X, %d", dc->config_table.dl_mdm_len2, in dump_table()
577 dc->config_table.dl_mdm_len2); in dump_table()
578 DBG3("dl_diag_len0: 0x%04X, %d", dc->config_table.dl_diag_len1, in dump_table()
579 dc->config_table.dl_diag_len1); in dump_table()
580 DBG3("dl_diag_len1: 0x%04X, %d", dc->config_table.dl_diag_len2, in dump_table()
581 dc->config_table.dl_diag_len2); in dump_table()
582 DBG3("dl_app1_len: 0x%04X, %d", dc->config_table.dl_app1_len, in dump_table()
583 dc->config_table.dl_app1_len); in dump_table()
584 DBG3("dl_app2_len: 0x%04X, %d", dc->config_table.dl_app2_len, in dump_table()
585 dc->config_table.dl_app2_len); in dump_table()
586 DBG3("dl_ctrl_len: 0x%04X, %d", dc->config_table.dl_ctrl_len, in dump_table()
587 dc->config_table.dl_ctrl_len); in dump_table()
588 DBG3("ul_start: 0x%04X, %d", dc->config_table.ul_start, in dump_table()
589 dc->config_table.ul_start); in dump_table()
590 DBG3("ul_mdm_len[0]: 0x%04X, %d", dc->config_table.ul_mdm_len1, in dump_table()
591 dc->config_table.ul_mdm_len1); in dump_table()
592 DBG3("ul_mdm_len[1]: 0x%04X, %d", dc->config_table.ul_mdm_len2, in dump_table()
593 dc->config_table.ul_mdm_len2); in dump_table()
594 DBG3("ul_diag_len: 0x%04X, %d", dc->config_table.ul_diag_len, in dump_table()
595 dc->config_table.ul_diag_len); in dump_table()
596 DBG3("ul_app1_len: 0x%04X, %d", dc->config_table.ul_app1_len, in dump_table()
597 dc->config_table.ul_app1_len); in dump_table()
598 DBG3("ul_app2_len: 0x%04X, %d", dc->config_table.ul_app2_len, in dump_table()
599 dc->config_table.ul_app2_len); in dump_table()
600 DBG3("ul_ctrl_len: 0x%04X, %d", dc->config_table.ul_ctrl_len, in dump_table()
601 dc->config_table.ul_ctrl_len); in dump_table()
604 static inline void dump_table(const struct nozomi *dc) { } in dump_table() argument
611 static int nozomi_read_config_table(struct nozomi *dc) in nozomi_read_config_table() argument
613 read_mem32((u32 *) &dc->config_table, dc->base_addr + 0, in nozomi_read_config_table()
616 if (dc->config_table.signature != NOZOMI_CONFIG_MAGIC) { in nozomi_read_config_table()
617 dev_err(&dc->pdev->dev, "ConfigTable Bad! 0x%08X != 0x%08X\n", in nozomi_read_config_table()
618 dc->config_table.signature, NOZOMI_CONFIG_MAGIC); in nozomi_read_config_table()
622 if ((dc->config_table.version == 0) in nozomi_read_config_table()
623 || (dc->config_table.toggle.enabled == TOGGLE_VALID)) { in nozomi_read_config_table()
627 nozomi_setup_memory(dc); in nozomi_read_config_table()
629 dc->port[PORT_MDM].toggle_ul = dc->config_table.toggle.mdm_ul; in nozomi_read_config_table()
630 dc->port[PORT_MDM].toggle_dl = dc->config_table.toggle.mdm_dl; in nozomi_read_config_table()
631 dc->port[PORT_DIAG].toggle_dl = dc->config_table.toggle.diag_dl; in nozomi_read_config_table()
633 dc->port[PORT_MDM].toggle_ul, in nozomi_read_config_table()
634 dc->port[PORT_MDM].toggle_dl, dc->port[PORT_DIAG].toggle_dl); in nozomi_read_config_table()
636 dump_table(dc); in nozomi_read_config_table()
639 memset(&dc->port[i].ctrl_dl, 0, sizeof(struct ctrl_dl)); in nozomi_read_config_table()
640 memset(&dc->port[i].ctrl_ul, 0, sizeof(struct ctrl_ul)); in nozomi_read_config_table()
644 dc->last_ier = dc->last_ier | CTRL_DL; in nozomi_read_config_table()
645 writew(dc->last_ier, dc->reg_ier); in nozomi_read_config_table()
647 dc->state = NOZOMI_STATE_ALLOCATED; in nozomi_read_config_table()
648 dev_info(&dc->pdev->dev, "Initialization OK!\n"); in nozomi_read_config_table()
652 if ((dc->config_table.version > 0) in nozomi_read_config_table()
653 && (dc->config_table.toggle.enabled != TOGGLE_VALID)) { in nozomi_read_config_table()
657 dev_info(&dc->pdev->dev, "Version of card: %d\n", in nozomi_read_config_table()
658 dc->config_table.version); in nozomi_read_config_table()
661 nozomi_setup_memory(dc); in nozomi_read_config_table()
669 write_mem32(dc->port[PORT_MDM].ul_addr[CH_A], in nozomi_read_config_table()
671 write_mem32(dc->port[PORT_MDM].ul_addr[CH_B], in nozomi_read_config_table()
674 writew(MDM_UL | DIAG_DL | MDM_DL, dc->reg_fcr); in nozomi_read_config_table()
683 static void enable_transmit_ul(enum port_type port, struct nozomi *dc) in enable_transmit_ul() argument
688 dc->last_ier |= mask[port]; in enable_transmit_ul()
689 writew(dc->last_ier, dc->reg_ier); in enable_transmit_ul()
691 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in enable_transmit_ul()
696 static void disable_transmit_ul(enum port_type port, struct nozomi *dc) in disable_transmit_ul() argument
702 dc->last_ier &= mask[port]; in disable_transmit_ul()
703 writew(dc->last_ier, dc->reg_ier); in disable_transmit_ul()
705 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in disable_transmit_ul()
710 static void enable_transmit_dl(enum port_type port, struct nozomi *dc) in enable_transmit_dl() argument
715 dc->last_ier |= mask[port]; in enable_transmit_dl()
716 writew(dc->last_ier, dc->reg_ier); in enable_transmit_dl()
718 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in enable_transmit_dl()
723 static void disable_transmit_dl(enum port_type port, struct nozomi *dc) in disable_transmit_dl() argument
729 dc->last_ier &= mask[port]; in disable_transmit_dl()
730 writew(dc->last_ier, dc->reg_ier); in disable_transmit_dl()
732 dev_err(&dc->pdev->dev, "Called with wrong port?\n"); in disable_transmit_dl()
737 * Return 1 - send buffer to card and ack.
738 * Return 0 - don't ack, don't send buffer to card.
740 static int send_data(enum port_type index, struct nozomi *dc) in send_data() argument
743 struct port *port = &dc->port[index]; in send_data()
744 const u8 toggle = port->toggle_ul; in send_data()
745 void __iomem *addr = port->ul_addr[toggle]; in send_data()
746 const u32 ul_size = port->ul_size[toggle]; in send_data()
749 size = kfifo_out(&port->fifo_ul, dc->send_buf, in send_data()
753 DBG4("No more data to send, disable link:"); in send_data()
761 write_mem32(addr + 4, (u32 *) dc->send_buf, size); in send_data()
763 tty_port_tty_wakeup(&port->port); in send_data()
769 static int receive_data(enum port_type index, struct nozomi *dc) in receive_data() argument
774 struct port *port = &dc->port[index]; in receive_data()
775 void __iomem *addr = port->dl_addr[port->toggle_dl]; in receive_data()
776 struct tty_struct *tty = tty_port_tty_get(&port->port); in receive_data()
786 disable_transmit_dl(index, dc); in receive_data()
792 dev_err(&dc->pdev->dev, "size == 0?\n"); in receive_data()
801 tty_insert_flip_char(&port->port, buf[0], TTY_NORMAL); in receive_data()
804 size -= tty_insert_flip_string(&port->port, in receive_data()
807 i = tty_insert_flip_string(&port->port, in receive_data()
809 size -= i; in receive_data()
814 set_bit(index, &dc->flip); in receive_data()
831 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_DL2 "); in interrupt2str()
833 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL1 "); in interrupt2str()
835 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "MDM_UL2 "); in interrupt2str()
837 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL1 "); in interrupt2str()
839 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_DL2 "); in interrupt2str()
842 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "DIAG_UL "); in interrupt2str()
845 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_DL "); in interrupt2str()
847 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_DL "); in interrupt2str()
850 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP1_UL "); in interrupt2str()
852 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "APP2_UL "); in interrupt2str()
855 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_DL "); in interrupt2str()
857 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "CTRL_UL "); in interrupt2str()
860 p += scnprintf(p, TMP_BUF_MAX - (p - buf), "RESET "); in interrupt2str()
868 * Return 1 - If ok, else 0
870 static int receive_flow_control(struct nozomi *dc) in receive_flow_control() argument
877 read_mem32((u32 *) &ctrl_dl, dc->port[PORT_CTRL].dl_addr[CH_A], 2); in receive_flow_control()
881 DBG1("The Base Band sends this value as a response to a " in receive_flow_control()
900 if (dc->state == NOZOMI_STATE_ALLOCATED) { in receive_flow_control()
905 dc->state = NOZOMI_STATE_READY; in receive_flow_control()
906 dev_info(&dc->pdev->dev, "Device READY!\n"); in receive_flow_control()
910 dev_err(&dc->pdev->dev, in receive_flow_control()
911 "ERROR: flow control received for non-existing port\n"); in receive_flow_control()
915 DBG1("0x%04X->0x%04X", *((u16 *)&dc->port[port].ctrl_dl), in receive_flow_control()
918 old_ctrl = dc->port[port].ctrl_dl; in receive_flow_control()
919 dc->port[port].ctrl_dl = ctrl_dl; in receive_flow_control()
924 disable_transmit_ul(port, dc); in receive_flow_control()
928 if (kfifo_len(&dc->port[port].fifo_ul)) { in receive_flow_control()
932 kfifo_len(&dc->port[port].fifo_ul)); in receive_flow_control()
933 enable_transmit_ul(port, dc); in receive_flow_control()
945 dc->port[port].tty_icount.cts++; in receive_flow_control()
947 dc->port[port].tty_icount.dsr++; in receive_flow_control()
949 dc->port[port].tty_icount.rng++; in receive_flow_control()
951 dc->port[port].tty_icount.dcd++; in receive_flow_control()
953 wake_up_interruptible(&dc->port[port].tty_wait); in receive_flow_control()
957 dc->port[port].tty_icount.dcd, dc->port[port].tty_icount.cts, in receive_flow_control()
958 dc->port[port].tty_icount.rng, dc->port[port].tty_icount.dsr); in receive_flow_control()
964 const struct nozomi *dc) in port2ctrl() argument
976 dev_err(&dc->pdev->dev, in port2ctrl()
978 "received for non-existing port\n"); in port2ctrl()
985 * Return 0 - If we have updated all flow control
986 * Return 1 - If we need to update more flow control, ack current enable more
988 static int send_flow_control(struct nozomi *dc) in send_flow_control() argument
994 if (dc->port[i].update_flow_control) { in send_flow_control()
996 /* We have more flow control to be updated */ in send_flow_control()
999 dc->port[i].ctrl_ul.port = port2ctrl(i, dc); in send_flow_control()
1000 ctrl = (u16 *)&dc->port[i].ctrl_ul; in send_flow_control()
1001 write_mem32(dc->port[PORT_CTRL].ul_addr[0], \ in send_flow_control()
1003 dc->port[i].update_flow_control = 0; in send_flow_control()
1012 * Return 1 - ok
1013 * Return 0 - toggle fields are out of sync
1015 static int handle_data_dl(struct nozomi *dc, enum port_type port, u8 *toggle, in handle_data_dl() argument
1019 if (receive_data(port, dc)) { in handle_data_dl()
1020 writew(mask1, dc->reg_fcr); in handle_data_dl()
1025 if (receive_data(port, dc)) { in handle_data_dl()
1026 writew(mask2, dc->reg_fcr); in handle_data_dl()
1031 if (receive_data(port, dc)) { in handle_data_dl()
1032 writew(mask2, dc->reg_fcr); in handle_data_dl()
1037 if (receive_data(port, dc)) { in handle_data_dl()
1038 writew(mask1, dc->reg_fcr); in handle_data_dl()
1043 dev_err(&dc->pdev->dev, "port out of sync!, toggle:%d\n", in handle_data_dl()
1052 * Return 1 - ok
1053 * Return 0 - toggle field are out of sync
1055 static int handle_data_ul(struct nozomi *dc, enum port_type port, u16 read_iir) in handle_data_ul() argument
1057 u8 *toggle = &(dc->port[port].toggle_ul); in handle_data_ul()
1060 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1061 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1062 if (send_data(port, dc)) { in handle_data_ul()
1063 writew(MDM_UL1, dc->reg_fcr); in handle_data_ul()
1064 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1065 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1070 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1071 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1072 if (send_data(port, dc)) { in handle_data_ul()
1073 writew(MDM_UL2, dc->reg_fcr); in handle_data_ul()
1074 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1075 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1081 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1082 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1083 if (send_data(port, dc)) { in handle_data_ul()
1084 writew(MDM_UL2, dc->reg_fcr); in handle_data_ul()
1085 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1086 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1091 dc->last_ier &= ~MDM_UL; in handle_data_ul()
1092 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1093 if (send_data(port, dc)) { in handle_data_ul()
1094 writew(MDM_UL1, dc->reg_fcr); in handle_data_ul()
1095 dc->last_ier = dc->last_ier | MDM_UL; in handle_data_ul()
1096 writew(dc->last_ier, dc->reg_ier); in handle_data_ul()
1101 writew(read_iir & MDM_UL, dc->reg_fcr); in handle_data_ul()
1102 dev_err(&dc->pdev->dev, "port out of sync!\n"); in handle_data_ul()
1110 struct nozomi *dc = dev_id; in interrupt_handler() local
1114 if (!dc) in interrupt_handler()
1117 spin_lock(&dc->spin_mutex); in interrupt_handler()
1118 read_iir = readw(dc->reg_iir); in interrupt_handler()
1121 if (read_iir == (u16)-1) in interrupt_handler()
1125 * (by masking with dc->last_ier) in interrupt_handler()
1127 read_iir &= dc->last_ier; in interrupt_handler()
1134 dc->last_ier); in interrupt_handler()
1137 if (unlikely(!nozomi_read_config_table(dc))) { in interrupt_handler()
1138 dc->last_ier = 0x0; in interrupt_handler()
1139 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1140 dev_err(&dc->pdev->dev, "Could not read status from " in interrupt_handler()
1143 writew(RESET, dc->reg_fcr); in interrupt_handler()
1150 dc->last_ier &= ~CTRL_UL; in interrupt_handler()
1151 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1152 if (send_flow_control(dc)) { in interrupt_handler()
1153 writew(CTRL_UL, dc->reg_fcr); in interrupt_handler()
1154 dc->last_ier = dc->last_ier | CTRL_UL; in interrupt_handler()
1155 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1159 receive_flow_control(dc); in interrupt_handler()
1160 writew(CTRL_DL, dc->reg_fcr); in interrupt_handler()
1163 if (!handle_data_dl(dc, PORT_MDM, in interrupt_handler()
1164 &(dc->port[PORT_MDM].toggle_dl), read_iir, in interrupt_handler()
1166 dev_err(&dc->pdev->dev, "MDM_DL out of sync!\n"); in interrupt_handler()
1171 if (!handle_data_ul(dc, PORT_MDM, read_iir)) { in interrupt_handler()
1172 dev_err(&dc->pdev->dev, "MDM_UL out of sync!\n"); in interrupt_handler()
1177 if (!handle_data_dl(dc, PORT_DIAG, in interrupt_handler()
1178 &(dc->port[PORT_DIAG].toggle_dl), read_iir, in interrupt_handler()
1180 dev_err(&dc->pdev->dev, "DIAG_DL out of sync!\n"); in interrupt_handler()
1185 dc->last_ier &= ~DIAG_UL; in interrupt_handler()
1186 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1187 if (send_data(PORT_DIAG, dc)) { in interrupt_handler()
1188 writew(DIAG_UL, dc->reg_fcr); in interrupt_handler()
1189 dc->last_ier = dc->last_ier | DIAG_UL; in interrupt_handler()
1190 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1194 if (receive_data(PORT_APP1, dc)) in interrupt_handler()
1195 writew(APP1_DL, dc->reg_fcr); in interrupt_handler()
1198 dc->last_ier &= ~APP1_UL; in interrupt_handler()
1199 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1200 if (send_data(PORT_APP1, dc)) { in interrupt_handler()
1201 writew(APP1_UL, dc->reg_fcr); in interrupt_handler()
1202 dc->last_ier = dc->last_ier | APP1_UL; in interrupt_handler()
1203 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1207 if (receive_data(PORT_APP2, dc)) in interrupt_handler()
1208 writew(APP2_DL, dc->reg_fcr); in interrupt_handler()
1211 dc->last_ier &= ~APP2_UL; in interrupt_handler()
1212 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1213 if (send_data(PORT_APP2, dc)) { in interrupt_handler()
1214 writew(APP2_UL, dc->reg_fcr); in interrupt_handler()
1215 dc->last_ier = dc->last_ier | APP2_UL; in interrupt_handler()
1216 writew(dc->last_ier, dc->reg_ier); in interrupt_handler()
1221 spin_unlock(&dc->spin_mutex); in interrupt_handler()
1224 if (test_and_clear_bit(a, &dc->flip)) in interrupt_handler()
1225 tty_flip_buffer_push(&dc->port[a].port); in interrupt_handler()
1229 spin_unlock(&dc->spin_mutex); in interrupt_handler()
1233 static void nozomi_get_card_type(struct nozomi *dc) in nozomi_get_card_type() argument
1239 size += pci_resource_len(dc->pdev, i); in nozomi_get_card_type()
1242 dc->card_type = size == 2048 ? F32_2 : F32_8; in nozomi_get_card_type()
1244 dev_info(&dc->pdev->dev, "Card type is: %d\n", dc->card_type); in nozomi_get_card_type()
1247 static void nozomi_setup_private_data(struct nozomi *dc) in nozomi_setup_private_data() argument
1249 void __iomem *offset = dc->base_addr + dc->card_type / 2; in nozomi_setup_private_data()
1252 dc->reg_fcr = (void __iomem *)(offset + R_FCR); in nozomi_setup_private_data()
1253 dc->reg_iir = (void __iomem *)(offset + R_IIR); in nozomi_setup_private_data()
1254 dc->reg_ier = (void __iomem *)(offset + R_IER); in nozomi_setup_private_data()
1255 dc->last_ier = 0; in nozomi_setup_private_data()
1256 dc->flip = 0; in nozomi_setup_private_data()
1258 dc->port[PORT_MDM].token_dl = MDM_DL; in nozomi_setup_private_data()
1259 dc->port[PORT_DIAG].token_dl = DIAG_DL; in nozomi_setup_private_data()
1260 dc->port[PORT_APP1].token_dl = APP1_DL; in nozomi_setup_private_data()
1261 dc->port[PORT_APP2].token_dl = APP2_DL; in nozomi_setup_private_data()
1264 init_waitqueue_head(&dc->port[i].tty_wait); in nozomi_setup_private_data()
1270 const struct nozomi *dc = dev_get_drvdata(dev); in card_type_show() local
1272 return sprintf(buf, "%d\n", dc->card_type); in card_type_show()
1279 const struct nozomi *dc = dev_get_drvdata(dev); in open_ttys_show() local
1281 return sprintf(buf, "%u\n", dc->open_ttys); in open_ttys_show()
1285 static void make_sysfs_files(struct nozomi *dc) in make_sysfs_files() argument
1287 if (device_create_file(&dc->pdev->dev, &dev_attr_card_type)) in make_sysfs_files()
1288 dev_err(&dc->pdev->dev, in make_sysfs_files()
1290 if (device_create_file(&dc->pdev->dev, &dev_attr_open_ttys)) in make_sysfs_files()
1291 dev_err(&dc->pdev->dev, in make_sysfs_files()
1295 static void remove_sysfs_files(struct nozomi *dc) in remove_sysfs_files() argument
1297 device_remove_file(&dc->pdev->dev, &dev_attr_card_type); in remove_sysfs_files()
1298 device_remove_file(&dc->pdev->dev, &dev_attr_open_ttys); in remove_sysfs_files()
1306 struct nozomi *dc = NULL; in nozomi_card_init() local
1315 dev_err(&pdev->dev, "no free tty range for this card left\n"); in nozomi_card_init()
1316 ret = -EIO; in nozomi_card_init()
1320 dc = kzalloc(sizeof(struct nozomi), GFP_KERNEL); in nozomi_card_init()
1321 if (unlikely(!dc)) { in nozomi_card_init()
1322 dev_err(&pdev->dev, "Could not allocate memory\n"); in nozomi_card_init()
1323 ret = -ENOMEM; in nozomi_card_init()
1327 dc->pdev = pdev; in nozomi_card_init()
1329 ret = pci_enable_device(dc->pdev); in nozomi_card_init()
1331 dev_err(&pdev->dev, "Failed to enable PCI Device\n"); in nozomi_card_init()
1335 ret = pci_request_regions(dc->pdev, NOZOMI_NAME); in nozomi_card_init()
1337 dev_err(&pdev->dev, "I/O address 0x%04x already in use\n", in nozomi_card_init()
1343 nozomi_get_card_type(dc); in nozomi_card_init()
1345 dc->base_addr = pci_iomap(dc->pdev, 0, dc->card_type); in nozomi_card_init()
1346 if (!dc->base_addr) { in nozomi_card_init()
1347 dev_err(&pdev->dev, "Unable to map card MMIO\n"); in nozomi_card_init()
1348 ret = -ENODEV; in nozomi_card_init()
1352 dc->send_buf = kmalloc(SEND_BUF_MAX, GFP_KERNEL); in nozomi_card_init()
1353 if (!dc->send_buf) { in nozomi_card_init()
1354 dev_err(&pdev->dev, "Could not allocate send buffer?\n"); in nozomi_card_init()
1355 ret = -ENOMEM; in nozomi_card_init()
1360 if (kfifo_alloc(&dc->port[i].fifo_ul, FIFO_BUFFER_SIZE_UL, in nozomi_card_init()
1362 dev_err(&pdev->dev, in nozomi_card_init()
1364 ret = -ENOMEM; in nozomi_card_init()
1369 spin_lock_init(&dc->spin_mutex); in nozomi_card_init()
1371 nozomi_setup_private_data(dc); in nozomi_card_init()
1374 dc->last_ier = 0; in nozomi_card_init()
1375 writew(dc->last_ier, dc->reg_ier); in nozomi_card_init()
1377 ret = request_irq(pdev->irq, &interrupt_handler, IRQF_SHARED, in nozomi_card_init()
1378 NOZOMI_NAME, dc); in nozomi_card_init()
1380 dev_err(&pdev->dev, "can't request irq %d\n", pdev->irq); in nozomi_card_init()
1384 DBG1("base_addr: %p", dc->base_addr); in nozomi_card_init()
1386 make_sysfs_files(dc); in nozomi_card_init()
1388 dc->index_start = ndev_idx * MAX_PORT; in nozomi_card_init()
1389 ndevs[ndev_idx] = dc; in nozomi_card_init()
1391 pci_set_drvdata(pdev, dc); in nozomi_card_init()
1394 dc->last_ier = RESET; in nozomi_card_init()
1395 iowrite16(dc->last_ier, dc->reg_ier); in nozomi_card_init()
1397 dc->state = NOZOMI_STATE_ENABLED; in nozomi_card_init()
1401 struct port *port = &dc->port[i]; in nozomi_card_init()
1402 port->dc = dc; in nozomi_card_init()
1403 tty_port_init(&port->port); in nozomi_card_init()
1404 port->port.ops = &noz_tty_port_ops; in nozomi_card_init()
1405 tty_dev = tty_port_register_device(&port->port, ntty_driver, in nozomi_card_init()
1406 dc->index_start + i, &pdev->dev); in nozomi_card_init()
1410 dev_err(&pdev->dev, "Could not allocate tty?\n"); in nozomi_card_init()
1411 tty_port_destroy(&port->port); in nozomi_card_init()
1419 for (i--; i >= 0; i--) { in nozomi_card_init()
1420 tty_unregister_device(ntty_driver, dc->index_start + i); in nozomi_card_init()
1421 tty_port_destroy(&dc->port[i].port); in nozomi_card_init()
1423 free_irq(pdev->irq, dc); in nozomi_card_init()
1427 for (i--; i >= PORT_MDM; i--) in nozomi_card_init()
1428 kfifo_free(&dc->port[i].fifo_ul); in nozomi_card_init()
1430 kfree(dc->send_buf); in nozomi_card_init()
1431 iounmap(dc->base_addr); in nozomi_card_init()
1437 kfree(dc); in nozomi_card_init()
1442 static void tty_exit(struct nozomi *dc) in tty_exit() argument
1447 tty_port_tty_hangup(&dc->port[i].port, false); in tty_exit()
1449 /* Racy below - surely should wait for scheduled work to be done or in tty_exit()
1451 while (dc->open_ttys) in tty_exit()
1454 tty_unregister_device(ntty_driver, dc->index_start + i); in tty_exit()
1455 tty_port_destroy(&dc->port[i].port); in tty_exit()
1464 struct nozomi *dc = pci_get_drvdata(pdev); in nozomi_card_exit() local
1467 dc->last_ier = 0; in nozomi_card_exit()
1468 writew(dc->last_ier, dc->reg_ier); in nozomi_card_exit()
1470 tty_exit(dc); in nozomi_card_exit()
1472 /* Send 0x0001, command card to resend the reset token. */ in nozomi_card_exit()
1473 /* This is to get the reset when the module is reloaded. */ in nozomi_card_exit()
1480 /* Setup dc->reg addresses to we can use defines here */ in nozomi_card_exit()
1481 write_mem32(dc->port[PORT_CTRL].ul_addr[0], (u32 *)&ctrl, 2); in nozomi_card_exit()
1482 writew(CTRL_UL, dc->reg_fcr); /* push the token to the card. */ in nozomi_card_exit()
1484 remove_sysfs_files(dc); in nozomi_card_exit()
1486 free_irq(pdev->irq, dc); in nozomi_card_exit()
1489 kfifo_free(&dc->port[i].fifo_ul); in nozomi_card_exit()
1491 kfree(dc->send_buf); in nozomi_card_exit()
1493 iounmap(dc->base_addr); in nozomi_card_exit()
1499 ndevs[dc->index_start / MAX_PORT] = NULL; in nozomi_card_exit()
1501 kfree(dc); in nozomi_card_exit()
1508 port->ctrl_ul.RTS = rts; in set_rts()
1509 port->update_flow_control = 1; in set_rts()
1517 DBG1("SETTING DTR index: %d, dtr: %d", tty->index, dtr); in set_dtr()
1519 port->ctrl_ul.DTR = dtr; in set_dtr()
1520 port->update_flow_control = 1; in set_dtr()
1525 * ----------------------------------------------------------------------------
1527 * ----------------------------------------------------------------------------
1533 struct nozomi *dc = get_dc_by_tty(tty); in ntty_install() local
1535 if (!port || !dc || dc->state != NOZOMI_STATE_READY) in ntty_install()
1536 return -ENODEV; in ntty_install()
1539 tty->driver_data = port; in ntty_install()
1545 tty->driver_data = NULL; in ntty_cleanup()
1551 struct nozomi *dc = port->dc; in ntty_activate() local
1554 DBG1("open: %d", port->token_dl); in ntty_activate()
1555 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_activate()
1556 dc->last_ier = dc->last_ier | port->token_dl; in ntty_activate()
1557 writew(dc->last_ier, dc->reg_ier); in ntty_activate()
1558 dc->open_ttys++; in ntty_activate()
1559 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_activate()
1560 printk("noz: activated %d: %p\n", tty->index, tport); in ntty_activate()
1566 struct port *port = tty->driver_data; in ntty_open()
1567 return tty_port_open(&port->port, tty, filp); in ntty_open()
1573 struct nozomi *dc = port->dc; in ntty_shutdown() local
1576 DBG1("close: %d", port->token_dl); in ntty_shutdown()
1577 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_shutdown()
1578 dc->last_ier &= ~(port->token_dl); in ntty_shutdown()
1579 writew(dc->last_ier, dc->reg_ier); in ntty_shutdown()
1580 dc->open_ttys--; in ntty_shutdown()
1581 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_shutdown()
1587 struct port *port = tty->driver_data; in ntty_close()
1589 tty_port_close(&port->port, tty, filp); in ntty_close()
1594 struct port *port = tty->driver_data; in ntty_hangup()
1595 tty_port_hangup(&port->port); in ntty_hangup()
1599 * called when the userspace process writes to the tty (/dev/noz*).
1600 * Data is inserted into a fifo, which is then read and transferred to the modem.
1605 int rval = -EINVAL; in ntty_write()
1606 struct nozomi *dc = get_dc_by_tty(tty); in ntty_write() local
1607 struct port *port = tty->driver_data; in ntty_write()
1610 if (!dc || !port) in ntty_write()
1611 return -ENODEV; in ntty_write()
1613 rval = kfifo_in(&port->fifo_ul, buffer, count); in ntty_write()
1615 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_write()
1617 if (port == &(dc->port[PORT_MDM])) { in ntty_write()
1618 if (port->ctrl_dl.CTS) { in ntty_write()
1620 enable_transmit_ul(tty->index % MAX_PORT, dc); in ntty_write()
1622 dev_err(&dc->pdev->dev, in ntty_write()
1626 enable_transmit_ul(tty->index % MAX_PORT, dc); in ntty_write()
1628 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_write()
1636 * #according to sources N_TTY.c it expects a value >= 0 and
1644 struct port *port = tty->driver_data; in ntty_write_room()
1646 const struct nozomi *dc = get_dc_by_tty(tty); in ntty_write_room() local
1648 if (dc) in ntty_write_room()
1649 room = kfifo_avail(&port->fifo_ul); in ntty_write_room()
1657 const struct port *port = tty->driver_data; in ntty_tiocmget()
1658 const struct ctrl_dl *ctrl_dl = &port->ctrl_dl; in ntty_tiocmget()
1659 const struct ctrl_ul *ctrl_ul = &port->ctrl_ul; in ntty_tiocmget()
1663 return (ctrl_ul->RTS ? TIOCM_RTS : 0) in ntty_tiocmget()
1664 | (ctrl_ul->DTR ? TIOCM_DTR : 0) in ntty_tiocmget()
1665 | (ctrl_dl->DCD ? TIOCM_CAR : 0) in ntty_tiocmget()
1666 | (ctrl_dl->RI ? TIOCM_RNG : 0) in ntty_tiocmget()
1667 | (ctrl_dl->DSR ? TIOCM_DSR : 0) in ntty_tiocmget()
1668 | (ctrl_dl->CTS ? TIOCM_CTS : 0); in ntty_tiocmget()
1675 struct nozomi *dc = get_dc_by_tty(tty); in ntty_tiocmset() local
1678 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_tiocmset()
1688 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_tiocmset()
1696 const struct async_icount cnow = port->tty_icount; in ntty_cflags_changed()
1699 ret = ((flags & TIOCM_RNG) && (cnow.rng != cprev->rng)) in ntty_cflags_changed()
1700 || ((flags & TIOCM_DSR) && (cnow.dsr != cprev->dsr)) in ntty_cflags_changed()
1701 || ((flags & TIOCM_CD) && (cnow.dcd != cprev->dcd)) in ntty_cflags_changed()
1702 || ((flags & TIOCM_CTS) && (cnow.cts != cprev->cts)); in ntty_cflags_changed()
1712 struct port *port = tty->driver_data; in ntty_tiocgicount()
1713 const struct async_icount cnow = port->tty_icount; in ntty_tiocgicount()
1715 icount->cts = cnow.cts; in ntty_tiocgicount()
1716 icount->dsr = cnow.dsr; in ntty_tiocgicount()
1717 icount->rng = cnow.rng; in ntty_tiocgicount()
1718 icount->dcd = cnow.dcd; in ntty_tiocgicount()
1719 icount->rx = cnow.rx; in ntty_tiocgicount()
1720 icount->tx = cnow.tx; in ntty_tiocgicount()
1721 icount->frame = cnow.frame; in ntty_tiocgicount()
1722 icount->overrun = cnow.overrun; in ntty_tiocgicount()
1723 icount->parity = cnow.parity; in ntty_tiocgicount()
1724 icount->brk = cnow.brk; in ntty_tiocgicount()
1725 icount->buf_overrun = cnow.buf_overrun; in ntty_tiocgicount()
1732 struct port *port = tty->driver_data; in ntty_ioctl()
1733 int rval = -ENOIOCTLCMD; in ntty_ioctl()
1737 struct async_icount cprev = port->tty_icount; in ntty_ioctl()
1739 rval = wait_event_interruptible(port->tty_wait, in ntty_ioctl()
1753 * to receive data again after a call to throttle.
1757 struct nozomi *dc = get_dc_by_tty(tty); in ntty_unthrottle() local
1760 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_unthrottle()
1761 enable_transmit_dl(tty->index % MAX_PORT, dc); in ntty_unthrottle()
1764 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_unthrottle()
1773 struct nozomi *dc = get_dc_by_tty(tty); in ntty_throttle() local
1776 spin_lock_irqsave(&dc->spin_mutex, flags); in ntty_throttle()
1778 spin_unlock_irqrestore(&dc->spin_mutex, flags); in ntty_throttle()
1784 struct port *port = tty->driver_data; in ntty_chars_in_buffer()
1785 struct nozomi *dc = get_dc_by_tty(tty); in ntty_chars_in_buffer() local
1787 if (unlikely(!dc || !port)) in ntty_chars_in_buffer()
1790 return kfifo_len(&port->fifo_ul); in ntty_chars_in_buffer()
1832 ntty_driver->driver_name = NOZOMI_NAME_TTY; in nozomi_init()
1833 ntty_driver->name = "noz"; in nozomi_init()
1834 ntty_driver->major = 0; in nozomi_init()
1835 ntty_driver->type = TTY_DRIVER_TYPE_SERIAL; in nozomi_init()
1836 ntty_driver->subtype = SERIAL_TYPE_NORMAL; in nozomi_init()
1837 ntty_driver->init_termios = tty_std_termios; in nozomi_init()
1838 ntty_driver->init_termios.c_cflag = B115200 | CS8 | CREAD | \ in nozomi_init()
1840 ntty_driver->init_termios.c_ispeed = 115200; in nozomi_init()
1841 ntty_driver->init_termios.c_ospeed = 115200; in nozomi_init()
1846 printk(KERN_ERR "Nozomi: failed to register ntty driver\n"); in nozomi_init()