aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char/cyclades.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char/cyclades.c')
-rw-r--r--drivers/char/cyclades.c7769
1 files changed, 3938 insertions, 3831 deletions
diff --git a/drivers/char/cyclades.c b/drivers/char/cyclades.c
index acb2de5e3a98..3ffa0807754c 100644
--- a/drivers/char/cyclades.c
+++ b/drivers/char/cyclades.c
@@ -1,8 +1,6 @@
1#undef BLOCKMOVE 1#undef BLOCKMOVE
2#define Z_WAKE 2#define Z_WAKE
3#undef Z_EXT_CHARS_IN_BUFFER 3#undef Z_EXT_CHARS_IN_BUFFER
4static char rcsid[] =
5"$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
6 4
7/* 5/*
8 * linux/drivers/char/cyclades.c 6 * linux/drivers/char/cyclades.c
@@ -593,18 +591,20 @@ static char rcsid[] =
593 * 591 *
594 */ 592 */
595 593
594#define CY_VERSION "2.4"
595
596/* If you need to install more boards than NR_CARDS, change the constant 596/* If you need to install more boards than NR_CARDS, change the constant
597 in the definition below. No other change is necessary to support up to 597 in the definition below. No other change is necessary to support up to
598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */ 598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
599 599
600#define NR_CARDS 4 600#define NR_CARDS 4
601 601
602/* 602/*
603 If the total number of ports is larger than NR_PORTS, change this 603 If the total number of ports is larger than NR_PORTS, change this
604 constant in the definition below. No other change is necessary to 604 constant in the definition below. No other change is necessary to
605 support more boards/ports. */ 605 support more boards/ports. */
606 606
607#define NR_PORTS 256 607#define NR_PORTS 256
608 608
609#define ZE_V1_NPORTS 64 609#define ZE_V1_NPORTS 64
610#define ZO_V1 0 610#define ZO_V1 0
@@ -625,9 +625,9 @@ static char rcsid[] =
625#undef CY_PCI_DEBUG 625#undef CY_PCI_DEBUG
626 626
627#if 0 627#if 0
628#define PAUSE __asm__("nop"); 628#define PAUSE __asm__("nop")
629#else 629#else
630#define PAUSE ; 630#define PAUSE do {} while (0)
631#endif 631#endif
632 632
633/* 633/*
@@ -663,7 +663,7 @@ static char rcsid[] =
663 do { \ 663 do { \
664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \ 664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
665 } while (0) 665 } while (0)
666 666
667#define CY_UNLOCK(info,flags) \ 667#define CY_UNLOCK(info,flags) \
668 do { \ 668 do { \
669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \ 669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
@@ -676,14 +676,14 @@ static char rcsid[] =
676#include <linux/stat.h> 676#include <linux/stat.h>
677#include <linux/proc_fs.h> 677#include <linux/proc_fs.h>
678 678
679static void cy_throttle (struct tty_struct *tty); 679static void cy_throttle(struct tty_struct *tty);
680static void cy_send_xchar (struct tty_struct *tty, char ch); 680static void cy_send_xchar(struct tty_struct *tty, char ch);
681 681
682#define IS_CYC_Z(card) ((card).num_chips == -1) 682#define IS_CYC_Z(card) ((card).num_chips == -1)
683 683
684#define Z_FPGA_CHECK(card) \ 684#define Z_FPGA_CHECK(card) \
685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \ 685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0) 686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
687 687
688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \ 688#define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
689 ((card).ctl_addr))->mail_box_0)) || \ 689 ((card).ctl_addr))->mail_box_0)) || \
@@ -698,8 +698,6 @@ static void cy_send_xchar (struct tty_struct *tty, char ch);
698 698
699#define STD_COM_FLAGS (0) 699#define STD_COM_FLAGS (0)
700 700
701#define JIFFIES_DIFF(n, j) ((j) - (n))
702
703static struct tty_driver *cy_serial_driver; 701static struct tty_driver *cy_serial_driver;
704 702
705#ifdef CONFIG_ISA 703#ifdef CONFIG_ISA
@@ -713,27 +711,28 @@ static struct tty_driver *cy_serial_driver;
713*/ 711*/
714 712
715static unsigned int cy_isa_addresses[] = { 713static unsigned int cy_isa_addresses[] = {
716 0xD0000, 714 0xD0000,
717 0xD2000, 715 0xD2000,
718 0xD4000, 716 0xD4000,
719 0xD6000, 717 0xD6000,
720 0xD8000, 718 0xD8000,
721 0xDA000, 719 0xDA000,
722 0xDC000, 720 0xDC000,
723 0xDE000, 721 0xDE000,
724 0,0,0,0,0,0,0,0 722 0, 0, 0, 0, 0, 0, 0, 0
725}; 723};
724
726#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses) 725#define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
727 726
728#ifdef MODULE 727#ifdef MODULE
729static long maddr[NR_CARDS] = { 0, }; 728static long maddr[NR_CARDS] = { 0, };
730static int irq[NR_CARDS] = { 0, }; 729static int irq[NR_CARDS] = { 0, };
731 730
732module_param_array(maddr, long, NULL, 0); 731module_param_array(maddr, long, NULL, 0);
733module_param_array(irq, int, NULL, 0); 732module_param_array(irq, int, NULL, 0);
734#endif 733#endif
735 734
736#endif /* CONFIG_ISA */ 735#endif /* CONFIG_ISA */
737 736
738/* This is the per-card data structure containing address, irq, number of 737/* This is the per-card data structure containing address, irq, number of
739 channels, etc. This driver supports a maximum of NR_CARDS cards. 738 channels, etc. This driver supports a maximum of NR_CARDS cards.
@@ -745,7 +744,7 @@ static struct cyclades_card cy_card[NR_CARDS];
745*/ 744*/
746static struct cyclades_port cy_port[NR_PORTS]; 745static struct cyclades_port cy_port[NR_PORTS];
747 746
748static int cy_next_channel; /* next minor available */ 747static int cy_next_channel; /* next minor available */
749 748
750/* 749/*
751 * This is used to look up the divisor speeds and the timeouts 750 * This is used to look up the divisor speeds and the timeouts
@@ -757,36 +756,42 @@ static int cy_next_channel; /* next minor available */
757 * 20 756 * 20
758 */ 757 */
759static int baud_table[] = { 758static int baud_table[] = {
760 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 759 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
761 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000, 760 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
762 230400, 0}; 761 230400, 0
763 762};
764static char baud_co_25[] = { /* 25 MHz clock option table */ 763
765 /* value => 00 01 02 03 04 */ 764static char baud_co_25[] = { /* 25 MHz clock option table */
766 /* divide by 8 32 128 512 2048 */ 765 /* value => 00 01 02 03 04 */
767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02, 766 /* divide by 8 32 128 512 2048 */
768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; 767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
769 768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
770static char baud_bpr_25[] = { /* 25 MHz baud rate period table */ 769};
771 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3, 770
772 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15}; 771static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
773 772 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
774static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */ 773 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
775 /* value => 00 01 02 03 04 */ 774};
776 /* divide by 8 32 128 512 2048 */ 775
777 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 776static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
778 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 777 /* value => 00 01 02 03 04 */
779 0x00}; 778 /* divide by 8 32 128 512 2048 */
780 779 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
781static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */ 780 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
782 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62, 781 0x00
783 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32, 782};
784 0x21}; 783
785 784static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
786static char baud_cor3[] = { /* receive threshold */ 785 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
787 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 786 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
788 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07, 787 0x21
789 0x07}; 788};
789
790static char baud_cor3[] = { /* receive threshold */
791 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
792 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
793 0x07
794};
790 795
791/* 796/*
792 * The Cyclades driver implements HW flow control as any serial driver. 797 * The Cyclades driver implements HW flow control as any serial driver.
@@ -799,42 +804,42 @@ static char baud_cor3[] = { /* receive threshold */
799 * cables. 804 * cables.
800 */ 805 */
801 806
802static char rflow_thr[] = { /* rflow threshold */ 807static char rflow_thr[] = { /* rflow threshold */
803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 808 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
804 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 809 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
805 0x0a}; 810 0x0a
811};
806 812
807/* The Cyclom-Ye has placed the sequential chips in non-sequential 813/* The Cyclom-Ye has placed the sequential chips in non-sequential
808 * address order. This look-up table overcomes that problem. 814 * address order. This look-up table overcomes that problem.
809 */ 815 */
810static int cy_chip_offset [] = 816static int cy_chip_offset[] = { 0x0000,
811 { 0x0000, 817 0x0400,
812 0x0400, 818 0x0800,
813 0x0800, 819 0x0C00,
814 0x0C00, 820 0x0200,
815 0x0200, 821 0x0600,
816 0x0600, 822 0x0A00,
817 0x0A00, 823 0x0E00
818 0x0E00 824};
819 };
820 825
821/* PCI related definitions */ 826/* PCI related definitions */
822 827
823static unsigned short cy_pci_nboard; 828static unsigned short cy_pci_nboard;
824static unsigned short cy_isa_nboard; 829static unsigned short cy_isa_nboard;
825static unsigned short cy_nboard; 830static unsigned short cy_nboard;
826#ifdef CONFIG_PCI 831#ifdef CONFIG_PCI
827static unsigned short cy_pci_dev_id[] = { 832static unsigned short cy_pci_dev_id[] = {
828 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */ 833 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */
829 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */ 834 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */
830 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */ 835 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */
831 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */ 836 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */
832 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */ 837 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */
833 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */ 838 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */
834 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */ 839 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */
835 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */ 840 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */
836 0 /* end of table */ 841 0 /* end of table */
837 }; 842};
838#endif 843#endif
839 844
840static void cy_start(struct tty_struct *); 845static void cy_start(struct tty_struct *);
@@ -842,9 +847,9 @@ static void set_line_char(struct cyclades_port *);
842static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong); 847static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong);
843#ifdef CONFIG_ISA 848#ifdef CONFIG_ISA
844static unsigned detect_isa_irq(void __iomem *); 849static unsigned detect_isa_irq(void __iomem *);
845#endif /* CONFIG_ISA */ 850#endif /* CONFIG_ISA */
846 851
847static int cyclades_get_proc_info(char *, char **, off_t , int , int *, void *); 852static int cyclades_get_proc_info(char *, char **, off_t, int, int *, void *);
848 853
849#ifndef CONFIG_CYZ_INTR 854#ifndef CONFIG_CYZ_INTR
850static void cyz_poll(unsigned long); 855static void cyz_poll(unsigned long);
@@ -855,41 +860,36 @@ static long cyz_polling_cycle = CZ_DEF_POLL;
855static int cyz_timeron = 0; 860static int cyz_timeron = 0;
856static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0); 861static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
857 862
858#else /* CONFIG_CYZ_INTR */ 863#else /* CONFIG_CYZ_INTR */
859static void cyz_rx_restart(unsigned long); 864static void cyz_rx_restart(unsigned long);
860static struct timer_list cyz_rx_full_timer[NR_PORTS]; 865static struct timer_list cyz_rx_full_timer[NR_PORTS];
861#endif /* CONFIG_CYZ_INTR */ 866#endif /* CONFIG_CYZ_INTR */
862 867
863static inline int 868static inline int serial_paranoia_check(struct cyclades_port *info,
864serial_paranoia_check(struct cyclades_port *info, 869 char *name, const char *routine)
865 char *name, const char *routine)
866{ 870{
867#ifdef SERIAL_PARANOIA_CHECK 871#ifdef SERIAL_PARANOIA_CHECK
868 static const char *badmagic = 872 if (!info) {
869 "cyc Warning: bad magic number for serial struct (%s) in %s\n"; 873 printk("cyc Warning: null cyclades_port for (%s) in %s\n",
870 static const char *badinfo = 874 name, routine);
871 "cyc Warning: null cyclades_port for (%s) in %s\n"; 875 return 1;
872 static const char *badrange = 876 }
873 "cyc Warning: cyclades_port out of range for (%s) in %s\n"; 877
874 878 if ((long)info < (long)(&cy_port[0]) ||
875 if (!info) { 879 (long)(&cy_port[NR_PORTS]) < (long)info) {
876 printk(badinfo, name, routine); 880 printk("cyc Warning: cyclades_port out of range for (%s) in "
877 return 1; 881 "%s\n", name, routine);
878 } 882 return 1;
879 883 }
880 if( (long)info < (long)(&cy_port[0]) 884
881 || (long)(&cy_port[NR_PORTS]) < (long)info ){ 885 if (info->magic != CYCLADES_MAGIC) {
882 printk(badrange, name, routine); 886 printk("cyc Warning: bad magic number for serial struct (%s) "
883 return 1; 887 "in %s\n", name, routine);
884 } 888 return 1;
885 889 }
886 if (info->magic != CYCLADES_MAGIC) {
887 printk(badmagic, name, routine);
888 return 1;
889 }
890#endif 890#endif
891 return 0; 891 return 0;
892} /* serial_paranoia_check */ 892} /* serial_paranoia_check */
893 893
894/* 894/*
895 * This routine is used by the interrupt handler to schedule 895 * This routine is used by the interrupt handler to schedule
@@ -897,13 +897,11 @@ serial_paranoia_check(struct cyclades_port *info,
897 * (also known as the "bottom half"). This can be called any 897 * (also known as the "bottom half"). This can be called any
898 * number of times for any channel without harm. 898 * number of times for any channel without harm.
899 */ 899 */
900static inline void 900static inline void cy_sched_event(struct cyclades_port *info, int event)
901cy_sched_event(struct cyclades_port *info, int event)
902{ 901{
903 info->event |= 1 << event; /* remember what kind of event and who */ 902 info->event |= 1 << event; /* remember what kind of event and who */
904 schedule_work(&info->tqueue); 903 schedule_work(&info->tqueue);
905} /* cy_sched_event */ 904} /* cy_sched_event */
906
907 905
908/* 906/*
909 * This routine is used to handle the "bottom half" processing for the 907 * This routine is used to handle the "bottom half" processing for the
@@ -930,41 +928,36 @@ do_softint(struct work_struct *work)
930{ 928{
931 struct cyclades_port *info = 929 struct cyclades_port *info =
932 container_of(work, struct cyclades_port, tqueue); 930 container_of(work, struct cyclades_port, tqueue);
933 struct tty_struct *tty; 931 struct tty_struct *tty;
934 932
935 tty = info->tty; 933 tty = info->tty;
936 if (!tty) 934 if (!tty)
937 return; 935 return;
938 936
939 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) { 937 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
940 tty_hangup(info->tty); 938 tty_hangup(info->tty);
941 wake_up_interruptible(&info->open_wait); 939 wake_up_interruptible(&info->open_wait);
942 info->flags &= ~ASYNC_NORMAL_ACTIVE; 940 info->flags &= ~ASYNC_NORMAL_ACTIVE;
943 } 941 }
944 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) { 942 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
945 wake_up_interruptible(&info->open_wait); 943 wake_up_interruptible(&info->open_wait);
946 }
947#ifdef CONFIG_CYZ_INTR 944#ifdef CONFIG_CYZ_INTR
948 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) { 945 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) {
949 if (cyz_rx_full_timer[info->line].function == NULL) { 946 if (cyz_rx_full_timer[info->line].function == NULL) {
950 cyz_rx_full_timer[info->line].expires = jiffies + 1; 947 cyz_rx_full_timer[info->line].expires = jiffies + 1;
951 cyz_rx_full_timer[info->line].function = cyz_rx_restart; 948 cyz_rx_full_timer[info->line].function = cyz_rx_restart;
952 cyz_rx_full_timer[info->line].data = (unsigned long)info; 949 cyz_rx_full_timer[info->line].data =
953 add_timer(&cyz_rx_full_timer[info->line]); 950 (unsigned long)info;
951 add_timer(&cyz_rx_full_timer[info->line]);
952 }
954 } 953 }
955 }
956#endif 954#endif
957 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event)) { 955 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
958 wake_up_interruptible(&info->delta_msr_wait); 956 wake_up_interruptible(&info->delta_msr_wait);
959 } 957 tty_wakeup(tty);
960 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
961 tty_wakeup(tty);
962 wake_up_interruptible(&tty->write_wait);
963 }
964#ifdef Z_WAKE 958#ifdef Z_WAKE
965 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) { 959 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
966 wake_up_interruptible(&info->shutdown_wait); 960 wake_up_interruptible(&info->shutdown_wait);
967 }
968#endif 961#endif
969} /* do_softint */ 962} /* do_softint */
970 963
@@ -979,341 +972,339 @@ do_softint(struct work_struct *work)
979 972
980 This function is only called from inside spinlock-protected code. 973 This function is only called from inside spinlock-protected code.
981 */ 974 */
982static int 975static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
983cyy_issue_cmd(void __iomem *base_addr, u_char cmd, int index)
984{ 976{
985 volatile int i; 977 volatile int i;
986 978
987 /* Check to see that the previous command has completed */ 979 /* Check to see that the previous command has completed */
988 for(i = 0 ; i < 100 ; i++){ 980 for (i = 0; i < 100; i++) {
989 if (cy_readb(base_addr+(CyCCR<<index)) == 0){ 981 if (cy_readb(base_addr + (CyCCR << index)) == 0) {
990 break; 982 break;
983 }
984 udelay(10L);
991 } 985 }
992 udelay(10L); 986 /* if the CCR never cleared, the previous command
993 } 987 didn't finish within the "reasonable time" */
994 /* if the CCR never cleared, the previous command 988 if (i == 100)
995 didn't finish within the "reasonable time" */ 989 return -1;
996 if (i == 100) return (-1);
997 990
998 /* Issue the new command */ 991 /* Issue the new command */
999 cy_writeb(base_addr+(CyCCR<<index), cmd); 992 cy_writeb(base_addr + (CyCCR << index), cmd);
1000 993
1001 return(0); 994 return 0;
1002} /* cyy_issue_cmd */ 995} /* cyy_issue_cmd */
1003 996
1004#ifdef CONFIG_ISA 997#ifdef CONFIG_ISA
1005/* ISA interrupt detection code */ 998/* ISA interrupt detection code */
1006static unsigned 999static unsigned detect_isa_irq(void __iomem * address)
1007detect_isa_irq(void __iomem *address)
1008{ 1000{
1009 int irq; 1001 int irq;
1010 unsigned long irqs, flags; 1002 unsigned long irqs, flags;
1011 int save_xir, save_car; 1003 int save_xir, save_car;
1012 int index = 0; /* IRQ probing is only for ISA */ 1004 int index = 0; /* IRQ probing is only for ISA */
1013 1005
1014 /* forget possible initially masked and pending IRQ */ 1006 /* forget possible initially masked and pending IRQ */
1015 irq = probe_irq_off(probe_irq_on()); 1007 irq = probe_irq_off(probe_irq_on());
1016 1008
1017 /* Clear interrupts on the board first */ 1009 /* Clear interrupts on the board first */
1018 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1010 cy_writeb(address + (Cy_ClrIntr << index), 0);
1019 /* Cy_ClrIntr is 0x1800 */ 1011 /* Cy_ClrIntr is 0x1800 */
1020 1012
1021 irqs = probe_irq_on(); 1013 irqs = probe_irq_on();
1022 /* Wait ... */ 1014 /* Wait ... */
1023 udelay(5000L); 1015 udelay(5000L);
1024 1016
1025 /* Enable the Tx interrupts on the CD1400 */ 1017 /* Enable the Tx interrupts on the CD1400 */
1026 local_irq_save(flags); 1018 local_irq_save(flags);
1027 cy_writeb(address + (CyCAR<<index), 0); 1019 cy_writeb(address + (CyCAR << index), 0);
1028 cyy_issue_cmd(address, CyCHAN_CTL|CyENB_XMTR, index); 1020 cyy_issue_cmd(address, CyCHAN_CTL | CyENB_XMTR, index);
1029 1021
1030 cy_writeb(address + (CyCAR<<index), 0); 1022 cy_writeb(address + (CyCAR << index), 0);
1031 cy_writeb(address + (CySRER<<index), 1023 cy_writeb(address + (CySRER << index),
1032 cy_readb(address + (CySRER<<index)) | CyTxRdy); 1024 cy_readb(address + (CySRER << index)) | CyTxRdy);
1033 local_irq_restore(flags); 1025 local_irq_restore(flags);
1034 1026
1035 /* Wait ... */ 1027 /* Wait ... */
1036 udelay(5000L); 1028 udelay(5000L);
1037 1029
1038 /* Check which interrupt is in use */ 1030 /* Check which interrupt is in use */
1039 irq = probe_irq_off(irqs); 1031 irq = probe_irq_off(irqs);
1040 1032
1041 /* Clean up */ 1033 /* Clean up */
1042 save_xir = (u_char) cy_readb(address + (CyTIR<<index)); 1034 save_xir = (u_char) cy_readb(address + (CyTIR << index));
1043 save_car = cy_readb(address + (CyCAR<<index)); 1035 save_car = cy_readb(address + (CyCAR << index));
1044 cy_writeb(address + (CyCAR<<index), (save_xir & 0x3)); 1036 cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
1045 cy_writeb(address + (CySRER<<index), 1037 cy_writeb(address + (CySRER << index),
1046 cy_readb(address + (CySRER<<index)) & ~CyTxRdy); 1038 cy_readb(address + (CySRER << index)) & ~CyTxRdy);
1047 cy_writeb(address + (CyTIR<<index), (save_xir & 0x3f)); 1039 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
1048 cy_writeb(address + (CyCAR<<index), (save_car)); 1040 cy_writeb(address + (CyCAR << index), (save_car));
1049 cy_writeb(address + (Cy_ClrIntr<<index), 0); 1041 cy_writeb(address + (Cy_ClrIntr << index), 0);
1050 /* Cy_ClrIntr is 0x1800 */ 1042 /* Cy_ClrIntr is 0x1800 */
1051 1043
1052 return (irq > 0)? irq : 0; 1044 return (irq > 0) ? irq : 0;
1053} 1045}
1054#endif /* CONFIG_ISA */ 1046#endif /* CONFIG_ISA */
1055 1047
1056/* The real interrupt service routine is called 1048static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1057 whenever the card wants its hand held--chars 1049 void __iomem * base_addr, int status, int index)
1058 received, out buffer empty, modem change, etc.
1059 */
1060static irqreturn_t
1061cyy_interrupt(int irq, void *dev_id)
1062{ 1050{
1063 struct tty_struct *tty; 1051 struct cyclades_port *info;
1064 int status; 1052 struct tty_struct *tty;
1065 struct cyclades_card *cinfo; 1053 volatile int char_count;
1066 struct cyclades_port *info; 1054 int i, j, len, mdm_change, mdm_status, outch;
1067 void __iomem *base_addr, *card_base_addr; 1055 int save_xir, channel, save_car;
1068 int chip; 1056 char data;
1069 int save_xir, channel, save_car; 1057
1070 char data; 1058 if (status & CySRReceive) { /* reception interrupt */
1071 volatile int char_count;
1072 int outch;
1073 int i,j,index;
1074 int too_many;
1075 int had_work;
1076 int mdm_change;
1077 int mdm_status;
1078 int len;
1079 if((cinfo = (struct cyclades_card *)dev_id) == 0){
1080#ifdef CY_DEBUG_INTERRUPTS
1081 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1082#endif
1083 return IRQ_NONE; /* spurious interrupt */
1084 }
1085
1086 card_base_addr = cinfo->base_addr;
1087 index = cinfo->bus_index;
1088
1089
1090 /* This loop checks all chips in the card. Make a note whenever
1091 _any_ chip had some work to do, as this is considered an
1092 indication that there will be more to do. Only when no chip
1093 has any work does this outermost loop exit.
1094 */
1095 do{
1096 had_work = 0;
1097 for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) {
1098 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index);
1099 too_many = 0;
1100 while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) {
1101 had_work++;
1102 /* The purpose of the following test is to ensure that
1103 no chip can monopolize the driver. This forces the
1104 chips to be checked in a round-robin fashion (after
1105 draining each of a bunch (1000) of characters).
1106 */
1107 if(1000<too_many++){
1108 break;
1109 }
1110 if (status & CySRReceive) { /* reception interrupt */
1111#ifdef CY_DEBUG_INTERRUPTS 1059#ifdef CY_DEBUG_INTERRUPTS
1112 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip); 1060 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);
1113#endif 1061#endif
1114 /* determine the channel & change to that context */ 1062 /* determine the channel & change to that context */
1115 spin_lock(&cinfo->card_lock); 1063 spin_lock(&cinfo->card_lock);
1116 save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index)); 1064 save_xir = (u_char) cy_readb(base_addr + (CyRIR << index));
1117 channel = (u_short ) (save_xir & CyIRChannel); 1065 channel = (u_short) (save_xir & CyIRChannel);
1118 i = channel + chip * 4 + cinfo->first_line; 1066 i = channel + chip * 4 + cinfo->first_line;
1119 info = &cy_port[i]; 1067 info = &cy_port[i];
1120 info->last_active = jiffies; 1068 info->last_active = jiffies;
1121 save_car = cy_readb(base_addr+(CyCAR<<index)); 1069 save_car = cy_readb(base_addr + (CyCAR << index));
1122 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1070 cy_writeb(base_addr + (CyCAR << index), save_xir);
1123 1071
1124 /* if there is nowhere to put the data, discard it */ 1072 /* if there is nowhere to put the data, discard it */
1125 if(info->tty == 0){ 1073 if (info->tty == 0) {
1126 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); 1074 j = (cy_readb(base_addr + (CyRIVR << index)) &
1127 if ( j == CyIVRRxEx ) { /* exception */ 1075 CyIVRMask);
1128 data = cy_readb(base_addr+(CyRDSR<<index)); 1076 if (j == CyIVRRxEx) { /* exception */
1129 } else { /* normal character reception */ 1077 data = cy_readb(base_addr + (CyRDSR << index));
1130 char_count = cy_readb(base_addr+(CyRDCR<<index)); 1078 } else { /* normal character reception */
1131 while(char_count--){ 1079 char_count = cy_readb(base_addr +
1132 data = cy_readb(base_addr+(CyRDSR<<index)); 1080 (CyRDCR << index));
1133 } 1081 while (char_count--) {
1134 } 1082 data = cy_readb(base_addr +
1135 }else{ /* there is an open port for this data */ 1083 (CyRDSR << index));
1136 tty = info->tty; 1084 }
1137 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask); 1085 }
1138 if ( j == CyIVRRxEx ) { /* exception */ 1086 } else { /* there is an open port for this data */
1139 data = cy_readb(base_addr+(CyRDSR<<index)); 1087 tty = info->tty;
1140 1088 j = (cy_readb(base_addr + (CyRIVR << index)) &
1141 /* For statistics only */ 1089 CyIVRMask);
1142 if (data & CyBREAK) 1090 if (j == CyIVRRxEx) { /* exception */
1143 info->icount.brk++; 1091 data = cy_readb(base_addr + (CyRDSR << index));
1144 else if(data & CyFRAME) 1092
1145 info->icount.frame++; 1093 /* For statistics only */
1146 else if(data & CyPARITY) 1094 if (data & CyBREAK)
1147 info->icount.parity++; 1095 info->icount.brk++;
1148 else if(data & CyOVERRUN) 1096 else if (data & CyFRAME)
1149 info->icount.overrun++; 1097 info->icount.frame++;
1150 1098 else if (data & CyPARITY)
1151 if(data & info->ignore_status_mask){ 1099 info->icount.parity++;
1152 info->icount.rx++; 1100 else if (data & CyOVERRUN)
1153 continue; 1101 info->icount.overrun++;
1154 } 1102
1155 if (tty_buffer_request_room(tty, 1)) { 1103 if (data & info->ignore_status_mask) {
1156 if (data & info->read_status_mask){
1157 if(data & CyBREAK){
1158 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_BREAK);
1159 info->icount.rx++;
1160 if (info->flags & ASYNC_SAK){
1161 do_SAK(tty);
1162 }
1163 }else if(data & CyFRAME){
1164 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME);
1165 info->icount.rx++;
1166 info->idle_stats.frame_errs++;
1167 }else if(data & CyPARITY){
1168 /* Pieces of seven... */
1169 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_PARITY);
1170 info->icount.rx++;
1171 info->idle_stats.parity_errs++;
1172 }else if(data & CyOVERRUN){
1173 tty_insert_flip_char(tty, 0, TTY_OVERRUN);
1174 info->icount.rx++; 1104 info->icount.rx++;
1175 /* If the flip buffer itself is 1105 return;
1176 overflowing, we still lose 1106 }
1177 the next incoming character. 1107 if (tty_buffer_request_room(tty, 1)) {
1178 */ 1108 if (data & info->read_status_mask) {
1179 tty_insert_flip_char(tty, cy_readb(base_addr+(CyRDSR<<index)), TTY_FRAME); 1109 if (data & CyBREAK) {
1180 info->icount.rx++; 1110 tty_insert_flip_char(
1111 tty,
1112 cy_readb(
1113 base_addr +
1114 (CyRDSR <<
1115 index)),
1116 TTY_BREAK);
1117 info->icount.rx++;
1118 if (info->flags &
1119 ASYNC_SAK) {
1120 do_SAK(tty);
1121 }
1122 } else if (data & CyFRAME) {
1123 tty_insert_flip_char(
1124 tty,
1125 cy_readb(
1126 base_addr +
1127 (CyRDSR <<
1128 index)),
1129 TTY_FRAME);
1130 info->icount.rx++;
1131 info->idle_stats.
1132 frame_errs++;
1133 } else if (data & CyPARITY) {
1134 /* Pieces of seven... */
1135 tty_insert_flip_char(
1136 tty,
1137 cy_readb(
1138 base_addr +
1139 (CyRDSR <<
1140 index)),
1141 TTY_PARITY);
1142 info->icount.rx++;
1143 info->idle_stats.
1144 parity_errs++;
1145 } else if (data & CyOVERRUN) {
1146 tty_insert_flip_char(
1147 tty, 0,
1148 TTY_OVERRUN);
1149 info->icount.rx++;
1150 /* If the flip buffer itself is
1151 overflowing, we still lose
1152 the next incoming character.
1153 */
1154 tty_insert_flip_char(
1155 tty,
1156 cy_readb(
1157 base_addr +
1158 (CyRDSR <<
1159 index)),
1160 TTY_FRAME);
1161 info->icount.rx++;
1162 info->idle_stats.
1163 overruns++;
1164 /* These two conditions may imply */
1165 /* a normal read should be done. */
1166 /* }else if(data & CyTIMEOUT){ */
1167 /* }else if(data & CySPECHAR){ */
1168 } else {
1169 tty_insert_flip_char(
1170 tty, 0,
1171 TTY_NORMAL);
1172 info->icount.rx++;
1173 }
1174 } else {
1175 tty_insert_flip_char(tty, 0,
1176 TTY_NORMAL);
1177 info->icount.rx++;
1178 }
1179 } else {
1180 /* there was a software buffer
1181 overrun and nothing could be
1182 done about it!!! */
1183 info->icount.buf_overrun++;
1181 info->idle_stats.overruns++; 1184 info->idle_stats.overruns++;
1182 /* These two conditions may imply */ 1185 }
1183 /* a normal read should be done. */ 1186 } else { /* normal character reception */
1184 /* }else if(data & CyTIMEOUT){ */ 1187 /* load # chars available from the chip */
1185 /* }else if(data & CySPECHAR){ */ 1188 char_count = cy_readb(base_addr +
1186 }else { 1189 (CyRDCR << index));
1187 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1188 info->icount.rx++;
1189 }
1190 }else{
1191 tty_insert_flip_char(tty, 0, TTY_NORMAL);
1192 info->icount.rx++;
1193 }
1194 }else{
1195 /* there was a software buffer
1196 overrun and nothing could be
1197 done about it!!! */
1198 info->icount.buf_overrun++;
1199 info->idle_stats.overruns++;
1200 }
1201 } else { /* normal character reception */
1202 /* load # chars available from the chip */
1203 char_count = cy_readb(base_addr+(CyRDCR<<index));
1204 1190
1205#ifdef CY_ENABLE_MONITORING 1191#ifdef CY_ENABLE_MONITORING
1206 ++info->mon.int_count; 1192 ++info->mon.int_count;
1207 info->mon.char_count += char_count; 1193 info->mon.char_count += char_count;
1208 if (char_count > info->mon.char_max) 1194 if (char_count > info->mon.char_max)
1209 info->mon.char_max = char_count; 1195 info->mon.char_max = char_count;
1210 info->mon.char_last = char_count; 1196 info->mon.char_last = char_count;
1211#endif 1197#endif
1212 len = tty_buffer_request_room(tty, char_count); 1198 len = tty_buffer_request_room(tty, char_count);
1213 while(len--){ 1199 while (len--) {
1214 data = cy_readb(base_addr+(CyRDSR<<index)); 1200 data = cy_readb(base_addr +
1215 tty_insert_flip_char(tty, data, TTY_NORMAL); 1201 (CyRDSR << index));
1216 info->idle_stats.recv_bytes++; 1202 tty_insert_flip_char(tty, data,
1217 info->icount.rx++; 1203 TTY_NORMAL);
1204 info->idle_stats.recv_bytes++;
1205 info->icount.rx++;
1218#ifdef CY_16Y_HACK 1206#ifdef CY_16Y_HACK
1219 udelay(10L); 1207 udelay(10L);
1220#endif 1208#endif
1221 } 1209 }
1222 info->idle_stats.recv_idle = jiffies; 1210 info->idle_stats.recv_idle = jiffies;
1223 } 1211 }
1224 tty_schedule_flip(tty); 1212 tty_schedule_flip(tty);
1225 } 1213 }
1226 /* end of service */ 1214 /* end of service */
1227 cy_writeb(base_addr+(CyRIR<<index), (save_xir & 0x3f)); 1215 cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
1228 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1216 cy_writeb(base_addr + (CyCAR << index), (save_car));
1229 spin_unlock(&cinfo->card_lock); 1217 spin_unlock(&cinfo->card_lock);
1230 } 1218 }
1231 1219
1232 1220 if (status & CySRTransmit) { /* transmission interrupt */
1233 if (status & CySRTransmit) { /* transmission interrupt */ 1221 /* Since we only get here when the transmit buffer
1234 /* Since we only get here when the transmit buffer 1222 is empty, we know we can always stuff a dozen
1235 is empty, we know we can always stuff a dozen 1223 characters. */
1236 characters. */
1237#ifdef CY_DEBUG_INTERRUPTS 1224#ifdef CY_DEBUG_INTERRUPTS
1238 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip); 1225 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);
1239#endif 1226#endif
1240 1227
1241 /* determine the channel & change to that context */ 1228 /* determine the channel & change to that context */
1242 spin_lock(&cinfo->card_lock); 1229 spin_lock(&cinfo->card_lock);
1243 save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index)); 1230 save_xir = (u_char) cy_readb(base_addr + (CyTIR << index));
1244 channel = (u_short ) (save_xir & CyIRChannel); 1231 channel = (u_short) (save_xir & CyIRChannel);
1245 i = channel + chip * 4 + cinfo->first_line; 1232 i = channel + chip * 4 + cinfo->first_line;
1246 save_car = cy_readb(base_addr+(CyCAR<<index)); 1233 save_car = cy_readb(base_addr + (CyCAR << index));
1247 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1234 cy_writeb(base_addr + (CyCAR << index), save_xir);
1248 1235
1249 /* validate the port# (as configured and open) */ 1236 /* validate the port# (as configured and open) */
1250 if( (i < 0) || (NR_PORTS <= i) ){ 1237 if ((i < 0) || (NR_PORTS <= i)) {
1251 cy_writeb(base_addr+(CySRER<<index), 1238 cy_writeb(base_addr + (CySRER << index),
1252 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1239 cy_readb(base_addr + (CySRER << index)) &
1253 goto txend; 1240 ~CyTxRdy);
1254 } 1241 goto txend;
1255 info = &cy_port[i]; 1242 }
1256 info->last_active = jiffies; 1243 info = &cy_port[i];
1257 if(info->tty == 0){ 1244 info->last_active = jiffies;
1258 cy_writeb(base_addr+(CySRER<<index), 1245 if (info->tty == 0) {
1259 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy); 1246 cy_writeb(base_addr + (CySRER << index),
1260 goto txdone; 1247 cy_readb(base_addr + (CySRER << index)) &
1261 } 1248 ~CyTxRdy);
1262 1249 goto txdone;
1263 /* load the on-chip space for outbound data */ 1250 }
1264 char_count = info->xmit_fifo_size; 1251
1265 1252 /* load the on-chip space for outbound data */
1266 if(info->x_char) { /* send special char */ 1253 char_count = info->xmit_fifo_size;
1267 outch = info->x_char; 1254
1268 cy_writeb(base_addr+(CyTDR<<index), outch); 1255 if (info->x_char) { /* send special char */
1269 char_count--; 1256 outch = info->x_char;
1257 cy_writeb(base_addr + (CyTDR << index), outch);
1258 char_count--;
1270 info->icount.tx++; 1259 info->icount.tx++;
1271 info->x_char = 0; 1260 info->x_char = 0;
1272 } 1261 }
1273 1262
1274 if (info->breakon || info->breakoff) { 1263 if (info->breakon || info->breakoff) {
1275 if (info->breakon) { 1264 if (info->breakon) {
1276 cy_writeb(base_addr + (CyTDR<<index), 0); 1265 cy_writeb(base_addr + (CyTDR << index), 0);
1277 cy_writeb(base_addr + (CyTDR<<index), 0x81); 1266 cy_writeb(base_addr + (CyTDR << index), 0x81);
1278 info->breakon = 0; 1267 info->breakon = 0;
1279 char_count -= 2; 1268 char_count -= 2;
1280 } 1269 }
1281 if (info->breakoff) { 1270 if (info->breakoff) {
1282 cy_writeb(base_addr + (CyTDR<<index), 0); 1271 cy_writeb(base_addr + (CyTDR << index), 0);
1283 cy_writeb(base_addr + (CyTDR<<index), 0x83); 1272 cy_writeb(base_addr + (CyTDR << index), 0x83);
1284 info->breakoff = 0; 1273 info->breakoff = 0;
1285 char_count -= 2; 1274 char_count -= 2;
1286 } 1275 }
1287 } 1276 }
1288 1277
1289 while (char_count-- > 0){ 1278 while (char_count-- > 0) {
1290 if (!info->xmit_cnt){ 1279 if (!info->xmit_cnt) {
1291 if (cy_readb(base_addr+(CySRER<<index))&CyTxMpty) { 1280 if (cy_readb(base_addr + (CySRER << index)) &
1292 cy_writeb(base_addr+(CySRER<<index), 1281 CyTxMpty) {
1293 cy_readb(base_addr+(CySRER<<index)) & 1282 cy_writeb(base_addr + (CySRER << index),
1294 ~CyTxMpty); 1283 cy_readb(base_addr +
1295 } else { 1284 (CySRER << index)) &
1296 cy_writeb(base_addr+(CySRER<<index), 1285 ~CyTxMpty);
1297 ((cy_readb(base_addr+(CySRER<<index)) 1286 } else {
1298 & ~CyTxRdy) 1287 cy_writeb(base_addr + (CySRER << index),
1299 | CyTxMpty)); 1288 (cy_readb(base_addr +
1300 } 1289 (CySRER << index)) &
1301 goto txdone; 1290 ~CyTxRdy) | CyTxMpty);
1291 }
1292 goto txdone;
1302 } 1293 }
1303 if (info->xmit_buf == 0){ 1294 if (info->xmit_buf == 0) {
1304 cy_writeb(base_addr+(CySRER<<index), 1295 cy_writeb(base_addr + (CySRER << index),
1305 cy_readb(base_addr+(CySRER<<index)) & 1296 cy_readb(base_addr + (CySRER << index))&
1306 ~CyTxRdy); 1297 ~CyTxRdy);
1307 goto txdone; 1298 goto txdone;
1308 } 1299 }
1309 if (info->tty->stopped || info->tty->hw_stopped){ 1300 if (info->tty->stopped || info->tty->hw_stopped) {
1310 cy_writeb(base_addr+(CySRER<<index), 1301 cy_writeb(base_addr + (CySRER << index),
1311 cy_readb(base_addr+(CySRER<<index)) & 1302 cy_readb(base_addr + (CySRER << index))&
1312 ~CyTxRdy); 1303 ~CyTxRdy);
1313 goto txdone; 1304 goto txdone;
1314 } 1305 }
1315 /* Because the Embedded Transmit Commands have 1306 /* Because the Embedded Transmit Commands have
1316 been enabled, we must check to see if the 1307 been enabled, we must check to see if the
1317 escape character, NULL, is being sent. If it 1308 escape character, NULL, is being sent. If it
1318 is, we must ensure that there is room for it 1309 is, we must ensure that there is room for it
1319 to be doubled in the output stream. Therefore 1310 to be doubled in the output stream. Therefore
@@ -1322,125 +1313,182 @@ cyy_interrupt(int irq, void *dev_id)
1322 after the check for a NULL output character. 1313 after the check for a NULL output character.
1323 This is necessary because there may not be 1314 This is necessary because there may not be
1324 room for the two chars needed to send a NULL.) 1315 room for the two chars needed to send a NULL.)
1325 */ 1316 */
1326 outch = info->xmit_buf[info->xmit_tail]; 1317 outch = info->xmit_buf[info->xmit_tail];
1327 if( outch ){ 1318 if (outch) {
1328 info->xmit_cnt--; 1319 info->xmit_cnt--;
1329 info->xmit_tail = (info->xmit_tail + 1) 1320 info->xmit_tail = (info->xmit_tail + 1) &
1330 & (SERIAL_XMIT_SIZE - 1); 1321 (SERIAL_XMIT_SIZE - 1);
1331 cy_writeb(base_addr+(CyTDR<<index), outch); 1322 cy_writeb(base_addr + (CyTDR << index), outch);
1332 info->icount.tx++;
1333 }else{
1334 if(char_count > 1){
1335 info->xmit_cnt--;
1336 info->xmit_tail = (info->xmit_tail + 1)
1337 & (SERIAL_XMIT_SIZE - 1);
1338 cy_writeb(base_addr+(CyTDR<<index),
1339 outch);
1340 cy_writeb(base_addr+(CyTDR<<index), 0);
1341 info->icount.tx++; 1323 info->icount.tx++;
1342 char_count--; 1324 } else {
1343 }else{ 1325 if (char_count > 1) {
1344 } 1326 info->xmit_cnt--;
1345 } 1327 info->xmit_tail = (info->xmit_tail + 1)&
1346 } 1328 (SERIAL_XMIT_SIZE - 1);
1347 1329 cy_writeb(base_addr + (CyTDR << index),
1348 txdone: 1330 outch);
1349 if (info->xmit_cnt < WAKEUP_CHARS) { 1331 cy_writeb(base_addr + (CyTDR << index),
1350 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1332 0);
1351 } 1333 info->icount.tx++;
1352 txend: 1334 char_count--;
1353 /* end of service */ 1335 } else {
1354 cy_writeb(base_addr+(CyTIR<<index), 1336 }
1355 (save_xir & 0x3f)); 1337 }
1356 cy_writeb(base_addr+(CyCAR<<index), (save_car)); 1338 }
1357 spin_unlock(&cinfo->card_lock); 1339
1358 } 1340txdone:
1359 1341 if (info->xmit_cnt < WAKEUP_CHARS) {
1360 if (status & CySRModem) { /* modem interrupt */ 1342 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1361 1343 }
1362 /* determine the channel & change to that context */ 1344txend:
1363 spin_lock(&cinfo->card_lock); 1345 /* end of service */
1364 save_xir = (u_char) cy_readb(base_addr+(CyMIR<<index)); 1346 cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
1365 channel = (u_short ) (save_xir & CyIRChannel); 1347 cy_writeb(base_addr + (CyCAR << index), (save_car));
1366 info = &cy_port[channel + chip * 4 1348 spin_unlock(&cinfo->card_lock);
1367 + cinfo->first_line]; 1349 }
1368 info->last_active = jiffies; 1350
1369 save_car = cy_readb(base_addr+(CyCAR<<index)); 1351 if (status & CySRModem) { /* modem interrupt */
1370 cy_writeb(base_addr+(CyCAR<<index), save_xir); 1352
1371 1353 /* determine the channel & change to that context */
1372 mdm_change = cy_readb(base_addr+(CyMISR<<index)); 1354 spin_lock(&cinfo->card_lock);
1373 mdm_status = cy_readb(base_addr+(CyMSVR1<<index)); 1355 save_xir = (u_char) cy_readb(base_addr + (CyMIR << index));
1374 1356 channel = (u_short) (save_xir & CyIRChannel);
1375 if(info->tty == 0){/* no place for data, ignore it*/ 1357 info = &cy_port[channel + chip * 4 + cinfo->first_line];
1376 ; 1358 info->last_active = jiffies;
1377 }else{ 1359 save_car = cy_readb(base_addr + (CyCAR << index));
1360 cy_writeb(base_addr + (CyCAR << index), save_xir);
1361
1362 mdm_change = cy_readb(base_addr + (CyMISR << index));
1363 mdm_status = cy_readb(base_addr + (CyMSVR1 << index));
1364
1365 if (info->tty == 0) { /* no place for data, ignore it */
1366 ;
1367 } else {
1378 if (mdm_change & CyANY_DELTA) { 1368 if (mdm_change & CyANY_DELTA) {
1379 /* For statistics only */ 1369 /* For statistics only */
1380 if (mdm_change & CyDCD) info->icount.dcd++; 1370 if (mdm_change & CyDCD)
1381 if (mdm_change & CyCTS) info->icount.cts++; 1371 info->icount.dcd++;
1382 if (mdm_change & CyDSR) info->icount.dsr++; 1372 if (mdm_change & CyCTS)
1383 if (mdm_change & CyRI) info->icount.rng++; 1373 info->icount.cts++;
1374 if (mdm_change & CyDSR)
1375 info->icount.dsr++;
1376 if (mdm_change & CyRI)
1377 info->icount.rng++;
1378
1379 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1380 }
1381
1382 if ((mdm_change & CyDCD) &&
1383 (info->flags & ASYNC_CHECK_CD)) {
1384 if (mdm_status & CyDCD) {
1385 cy_sched_event(info,
1386 Cy_EVENT_OPEN_WAKEUP);
1387 } else {
1388 cy_sched_event(info, Cy_EVENT_HANGUP);
1389 }
1390 }
1391 if ((mdm_change & CyCTS) &&
1392 (info->flags & ASYNC_CTS_FLOW)) {
1393 if (info->tty->hw_stopped) {
1394 if (mdm_status & CyCTS) {
1395 /* cy_start isn't used
1396 because... !!! */
1397 info->tty->hw_stopped = 0;
1398 cy_writeb(base_addr +
1399 (CySRER << index),
1400 cy_readb(base_addr +
1401 (CySRER <<
1402 index))|
1403 CyTxRdy);
1404 cy_sched_event(info,
1405 Cy_EVENT_WRITE_WAKEUP);
1406 }
1407 } else {
1408 if (!(mdm_status & CyCTS)) {
1409 /* cy_stop isn't used
1410 because ... !!! */
1411 info->tty->hw_stopped = 1;
1412 cy_writeb(base_addr +
1413 (CySRER << index),
1414 cy_readb(base_addr +
1415 (CySRER <<
1416 index)) &
1417 ~CyTxRdy);
1418 }
1419 }
1420 }
1421 if (mdm_change & CyDSR) {
1422 }
1423 if (mdm_change & CyRI) {
1424 }
1425 }
1426 /* end of service */
1427 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
1428 cy_writeb(base_addr + (CyCAR << index), save_car);
1429 spin_unlock(&cinfo->card_lock);
1430 }
1431}
1432
1433/* The real interrupt service routine is called
1434 whenever the card wants its hand held--chars
1435 received, out buffer empty, modem change, etc.
1436 */
1437static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1438{
1439 int status;
1440 struct cyclades_card *cinfo;
1441 void __iomem *base_addr, *card_base_addr;
1442 int chip;
1443 int index;
1444 int too_many;
1445 int had_work;
1446
1447 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1448#ifdef CY_DEBUG_INTERRUPTS
1449 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1450#endif
1451 return IRQ_NONE; /* spurious interrupt */
1452 }
1453
1454 card_base_addr = cinfo->base_addr;
1455 index = cinfo->bus_index;
1384 1456
1385 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP); 1457 /* This loop checks all chips in the card. Make a note whenever
1458 _any_ chip had some work to do, as this is considered an
1459 indication that there will be more to do. Only when no chip
1460 has any work does this outermost loop exit.
1461 */
1462 do {
1463 had_work = 0;
1464 for (chip = 0; chip < cinfo->num_chips; chip++) {
1465 base_addr = cinfo->base_addr +
1466 (cy_chip_offset[chip] << index);
1467 too_many = 0;
1468 while ((status = cy_readb(base_addr +
1469 (CySVRR << index))) != 0x00) {
1470 had_work++;
1471 /* The purpose of the following test is to ensure that
1472 no chip can monopolize the driver. This forces the
1473 chips to be checked in a round-robin fashion (after
1474 draining each of a bunch (1000) of characters).
1475 */
1476 if (1000 < too_many++) {
1477 break;
1478 }
1479 cyy_intr_chip(cinfo, chip, base_addr, status,
1480 index);
1386 } 1481 }
1482 }
1483 } while (had_work);
1387 1484
1388 if((mdm_change & CyDCD) 1485 /* clear interrupts */
1389 && (info->flags & ASYNC_CHECK_CD)){ 1486 spin_lock(&cinfo->card_lock);
1390 if(mdm_status & CyDCD){ 1487 cy_writeb(card_base_addr + (Cy_ClrIntr << index), 0);
1391 cy_sched_event(info, 1488 /* Cy_ClrIntr is 0x1800 */
1392 Cy_EVENT_OPEN_WAKEUP); 1489 spin_unlock(&cinfo->card_lock);
1393 }else{ 1490 return IRQ_HANDLED;
1394 cy_sched_event(info, 1491} /* cyy_interrupt */
1395 Cy_EVENT_HANGUP);
1396 }
1397 }
1398 if((mdm_change & CyCTS)
1399 && (info->flags & ASYNC_CTS_FLOW)){
1400 if(info->tty->hw_stopped){
1401 if(mdm_status & CyCTS){
1402 /* cy_start isn't used
1403 because... !!! */
1404 info->tty->hw_stopped = 0;
1405 cy_writeb(base_addr+(CySRER<<index),
1406 cy_readb(base_addr+(CySRER<<index)) |
1407 CyTxRdy);
1408 cy_sched_event(info,
1409 Cy_EVENT_WRITE_WAKEUP);
1410 }
1411 }else{
1412 if(!(mdm_status & CyCTS)){
1413 /* cy_stop isn't used
1414 because ... !!! */
1415 info->tty->hw_stopped = 1;
1416 cy_writeb(base_addr+(CySRER<<index),
1417 cy_readb(base_addr+(CySRER<<index)) &
1418 ~CyTxRdy);
1419 }
1420 }
1421 }
1422 if(mdm_change & CyDSR){
1423 }
1424 if(mdm_change & CyRI){
1425 }
1426 }
1427 /* end of service */
1428 cy_writeb(base_addr+(CyMIR<<index),
1429 (save_xir & 0x3f));
1430 cy_writeb(base_addr+(CyCAR<<index), save_car);
1431 spin_unlock(&cinfo->card_lock);
1432 }
1433 } /* end while status != 0 */
1434 } /* end loop for chips... */
1435 } while(had_work);
1436
1437 /* clear interrupts */
1438 spin_lock(&cinfo->card_lock);
1439 cy_writeb(card_base_addr + (Cy_ClrIntr<<index), 0);
1440 /* Cy_ClrIntr is 0x1800 */
1441 spin_unlock(&cinfo->card_lock);
1442 return IRQ_HANDLED;
1443} /* cyy_interrupt */
1444 1492
1445/***********************************************************/ 1493/***********************************************************/
1446/********* End of block of Cyclom-Y specific code **********/ 1494/********* End of block of Cyclom-Y specific code **********/
@@ -1448,643 +1496,655 @@ cyy_interrupt(int irq, void *dev_id)
1448/***********************************************************/ 1496/***********************************************************/
1449 1497
1450static int 1498static int
1451cyz_fetch_msg( struct cyclades_card *cinfo, 1499cyz_fetch_msg(struct cyclades_card *cinfo,
1452 uclong *channel, ucchar *cmd, uclong *param) 1500 uclong * channel, ucchar * cmd, uclong * param)
1453{ 1501{
1454 struct FIRM_ID __iomem *firm_id; 1502 struct FIRM_ID __iomem *firm_id;
1455 struct ZFW_CTRL __iomem *zfw_ctrl; 1503 struct ZFW_CTRL __iomem *zfw_ctrl;
1456 struct BOARD_CTRL __iomem *board_ctrl; 1504 struct BOARD_CTRL __iomem *board_ctrl;
1457 unsigned long loc_doorbell; 1505 unsigned long loc_doorbell;
1458 1506
1459 firm_id = cinfo->base_addr + ID_ADDRESS; 1507 firm_id = cinfo->base_addr + ID_ADDRESS;
1460 if (!ISZLOADED(*cinfo)){ 1508 if (!ISZLOADED(*cinfo)) {
1461 return (-1); 1509 return -1;
1462 } 1510 }
1463 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1511 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1464 board_ctrl = &zfw_ctrl->board_ctrl; 1512 0xfffff);
1465 1513 board_ctrl = &zfw_ctrl->board_ctrl;
1466 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *) 1514
1467 (cinfo->ctl_addr))->loc_doorbell); 1515 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *)
1468 if (loc_doorbell){ 1516 (cinfo->ctl_addr))->loc_doorbell);
1469 *cmd = (char)(0xff & loc_doorbell); 1517 if (loc_doorbell) {
1470 *channel = cy_readl(&board_ctrl->fwcmd_channel); 1518 *cmd = (char)(0xff & loc_doorbell);
1471 *param = (uclong)cy_readl(&board_ctrl->fwcmd_param); 1519 *channel = cy_readl(&board_ctrl->fwcmd_channel);
1472 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->loc_doorbell, 1520 *param = (uclong) cy_readl(&board_ctrl->fwcmd_param);
1473 0xffffffff); 1521 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1474 return 1; 1522 loc_doorbell, 0xffffffff);
1475 } 1523 return 1;
1476 return 0; 1524 }
1477} /* cyz_fetch_msg */ 1525 return 0;
1526} /* cyz_fetch_msg */
1478 1527
1479static int 1528static int
1480cyz_issue_cmd( struct cyclades_card *cinfo, 1529cyz_issue_cmd(struct cyclades_card *cinfo,
1481 uclong channel, ucchar cmd, uclong param) 1530 uclong channel, ucchar cmd, uclong param)
1482{ 1531{
1483 struct FIRM_ID __iomem *firm_id; 1532 struct FIRM_ID __iomem *firm_id;
1484 struct ZFW_CTRL __iomem *zfw_ctrl; 1533 struct ZFW_CTRL __iomem *zfw_ctrl;
1485 struct BOARD_CTRL __iomem *board_ctrl; 1534 struct BOARD_CTRL __iomem *board_ctrl;
1486 unsigned long __iomem *pci_doorbell; 1535 unsigned long __iomem *pci_doorbell;
1487 int index; 1536 int index;
1488 1537
1489 firm_id = cinfo->base_addr + ID_ADDRESS; 1538 firm_id = cinfo->base_addr + ID_ADDRESS;
1490 if (!ISZLOADED(*cinfo)){ 1539 if (!ISZLOADED(*cinfo)) {
1491 return (-1); 1540 return -1;
1492 } 1541 }
1493 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1542 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1494 board_ctrl = &zfw_ctrl->board_ctrl; 1543 0xfffff);
1495 1544 board_ctrl = &zfw_ctrl->board_ctrl;
1496 index = 0; 1545
1497 pci_doorbell = &((struct RUNTIME_9060 __iomem *) (cinfo->ctl_addr))->pci_doorbell; 1546 index = 0;
1498 while( (cy_readl(pci_doorbell) & 0xff) != 0){ 1547 pci_doorbell =
1499 if (index++ == 1000){ 1548 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1500 return((int)(cy_readl(pci_doorbell) & 0xff)); 1549 while ((cy_readl(pci_doorbell) & 0xff) != 0) {
1501 } 1550 if (index++ == 1000) {
1502 udelay(50L); 1551 return (int)(cy_readl(pci_doorbell) & 0xff);
1503 } 1552 }
1504 cy_writel(&board_ctrl->hcmd_channel, channel); 1553 udelay(50L);
1505 cy_writel(&board_ctrl->hcmd_param , param); 1554 }
1506 cy_writel(pci_doorbell, (long)cmd); 1555 cy_writel(&board_ctrl->hcmd_channel, channel);
1507 1556 cy_writel(&board_ctrl->hcmd_param, param);
1508 return(0); 1557 cy_writel(pci_doorbell, (long)cmd);
1509} /* cyz_issue_cmd */ 1558
1559 return 0;
1560} /* cyz_issue_cmd */
1510 1561
1511static void 1562static void
1512cyz_handle_rx(struct cyclades_port *info, 1563cyz_handle_rx(struct cyclades_port *info,
1513 volatile struct CH_CTRL __iomem *ch_ctrl, 1564 volatile struct CH_CTRL __iomem * ch_ctrl,
1514 volatile struct BUF_CTRL __iomem *buf_ctrl) 1565 volatile struct BUF_CTRL __iomem * buf_ctrl)
1515{ 1566{
1516 struct cyclades_card *cinfo = &cy_card[info->card]; 1567 struct cyclades_card *cinfo = &cy_card[info->card];
1517 struct tty_struct *tty = info->tty; 1568 struct tty_struct *tty = info->tty;
1518 volatile int char_count; 1569 volatile int char_count;
1519 int len; 1570 int len;
1520#ifdef BLOCKMOVE 1571#ifdef BLOCKMOVE
1521 int small_count; 1572 int small_count;
1522#else 1573#else
1523 char data; 1574 char data;
1524#endif 1575#endif
1525 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr; 1576 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
1526 1577
1527 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get); 1578 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get);
1528 rx_put = cy_readl(&buf_ctrl->rx_put); 1579 rx_put = cy_readl(&buf_ctrl->rx_put);
1529 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize); 1580 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
1530 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr); 1581 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr);
1531 if (rx_put >= rx_get) 1582 if (rx_put >= rx_get)
1532 char_count = rx_put - rx_get; 1583 char_count = rx_put - rx_get;
1533 else 1584 else
1534 char_count = rx_put - rx_get + rx_bufsize; 1585 char_count = rx_put - rx_get + rx_bufsize;
1535 1586
1536 if ( char_count ) { 1587 if (char_count) {
1537 info->last_active = jiffies; 1588 info->last_active = jiffies;
1538 info->jiffies[1] = jiffies; 1589 info->jiffies[1] = jiffies;
1539 1590
1540#ifdef CY_ENABLE_MONITORING 1591#ifdef CY_ENABLE_MONITORING
1541 info->mon.int_count++; 1592 info->mon.int_count++;
1542 info->mon.char_count += char_count; 1593 info->mon.char_count += char_count;
1543 if (char_count > info->mon.char_max) 1594 if (char_count > info->mon.char_max)
1544 info->mon.char_max = char_count; 1595 info->mon.char_max = char_count;
1545 info->mon.char_last = char_count; 1596 info->mon.char_last = char_count;
1546#endif 1597#endif
1547 if(tty == 0){ 1598 if (tty == 0) {
1548 /* flush received characters */ 1599 /* flush received characters */
1549 new_rx_get = (new_rx_get + char_count) & (rx_bufsize - 1); 1600 new_rx_get = (new_rx_get + char_count) &
1550 info->rflush_count++; 1601 (rx_bufsize - 1);
1551 }else{ 1602 info->rflush_count++;
1603 } else {
1552#ifdef BLOCKMOVE 1604#ifdef BLOCKMOVE
1553 /* we'd like to use memcpy(t, f, n) and memset(s, c, count) 1605 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1554 for performance, but because of buffer boundaries, there 1606 for performance, but because of buffer boundaries, there
1555 may be several steps to the operation */ 1607 may be several steps to the operation */
1556 while(0 < (small_count = 1608 while (0 < (small_count = min_t(unsigned int,
1557 min_t(unsigned int, (rx_bufsize - new_rx_get), 1609 rx_bufsize - new_rx_get,
1558 min_t(unsigned int, (TTY_FLIPBUF_SIZE - tty->flip.count), char_count)) 1610 min_t(unsigned int, TTY_FLIPBUF_SIZE -
1559 )) { 1611 tty->flip.count, char_count)))){
1560 memcpy_fromio(tty->flip.char_buf_ptr, 1612 memcpy_fromio(tty->flip.char_buf_ptr,
1561 (char *)(cinfo->base_addr 1613 (char *)(cinfo->base_addr + rx_bufaddr +
1562 + rx_bufaddr + new_rx_get), 1614 new_rx_get),
1563 small_count); 1615 small_count);
1564 1616
1565 tty->flip.char_buf_ptr += small_count; 1617 tty->flip.char_buf_ptr += small_count;
1566 memset(tty->flip.flag_buf_ptr, TTY_NORMAL, small_count); 1618 memset(tty->flip.flag_buf_ptr, TTY_NORMAL,
1567 tty->flip.flag_buf_ptr += small_count; 1619 small_count);
1568 new_rx_get = (new_rx_get + small_count) & (rx_bufsize - 1); 1620 tty->flip.flag_buf_ptr += small_count;
1569 char_count -= small_count; 1621 new_rx_get = (new_rx_get + small_count) &
1570 info->icount.rx += small_count; 1622 (rx_bufsize - 1);
1571 info->idle_stats.recv_bytes += small_count; 1623 char_count -= small_count;
1572 tty->flip.count += small_count; 1624 info->icount.rx += small_count;
1573 } 1625 info->idle_stats.recv_bytes += small_count;
1626 tty->flip.count += small_count;
1627 }
1574#else 1628#else
1575 len = tty_buffer_request_room(tty, char_count); 1629 len = tty_buffer_request_room(tty, char_count);
1576 while(len--){ 1630 while (len--) {
1577 data = cy_readb(cinfo->base_addr + rx_bufaddr + new_rx_get); 1631 data = cy_readb(cinfo->base_addr + rx_bufaddr +
1578 new_rx_get = (new_rx_get + 1) & (rx_bufsize - 1); 1632 new_rx_get);
1579 tty_insert_flip_char(tty, data, TTY_NORMAL); 1633 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
1580 info->idle_stats.recv_bytes++; 1634 tty_insert_flip_char(tty, data, TTY_NORMAL);
1581 info->icount.rx++; 1635 info->idle_stats.recv_bytes++;
1582 } 1636 info->icount.rx++;
1637 }
1583#endif 1638#endif
1584#ifdef CONFIG_CYZ_INTR 1639#ifdef CONFIG_CYZ_INTR
1585 /* Recalculate the number of chars in the RX buffer and issue 1640 /* Recalculate the number of chars in the RX buffer and issue
1586 a cmd in case it's higher than the RX high water mark */ 1641 a cmd in case it's higher than the RX high water mark */
1587 rx_put = cy_readl(&buf_ctrl->rx_put); 1642 rx_put = cy_readl(&buf_ctrl->rx_put);
1588 if (rx_put >= rx_get) 1643 if (rx_put >= rx_get)
1589 char_count = rx_put - rx_get; 1644 char_count = rx_put - rx_get;
1590 else 1645 else
1591 char_count = rx_put - rx_get + rx_bufsize; 1646 char_count = rx_put - rx_get + rx_bufsize;
1592 if(char_count >= cy_readl(&buf_ctrl->rx_threshold)) { 1647 if (char_count >= (int)cy_readl(&buf_ctrl->
1593 cy_sched_event(info, Cy_EVENT_Z_RX_FULL); 1648 rx_threshold)) {
1594 } 1649 cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
1650 }
1595#endif 1651#endif
1596 info->idle_stats.recv_idle = jiffies; 1652 info->idle_stats.recv_idle = jiffies;
1597 tty_schedule_flip(tty); 1653 tty_schedule_flip(tty);
1654 }
1655 /* Update rx_get */
1656 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1598 } 1657 }
1599 /* Update rx_get */
1600 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1601 }
1602} 1658}
1603 1659
1604static void 1660static void
1605cyz_handle_tx(struct cyclades_port *info, 1661cyz_handle_tx(struct cyclades_port *info,
1606 volatile struct CH_CTRL __iomem *ch_ctrl, 1662 volatile struct CH_CTRL __iomem * ch_ctrl,
1607 volatile struct BUF_CTRL __iomem *buf_ctrl) 1663 volatile struct BUF_CTRL __iomem * buf_ctrl)
1608{ 1664{
1609 struct cyclades_card *cinfo = &cy_card[info->card]; 1665 struct cyclades_card *cinfo = &cy_card[info->card];
1610 struct tty_struct *tty = info->tty; 1666 struct tty_struct *tty = info->tty;
1611 char data; 1667 char data;
1612 volatile int char_count; 1668 volatile int char_count;
1613#ifdef BLOCKMOVE 1669#ifdef BLOCKMOVE
1614 int small_count; 1670 int small_count;
1615#endif 1671#endif
1616 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr; 1672 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr;
1617 1673
1618 if (info->xmit_cnt <= 0) /* Nothing to transmit */ 1674 if (info->xmit_cnt <= 0) /* Nothing to transmit */
1619 return; 1675 return;
1620 1676
1621 tx_get = cy_readl(&buf_ctrl->tx_get); 1677 tx_get = cy_readl(&buf_ctrl->tx_get);
1622 tx_put = cy_readl(&buf_ctrl->tx_put); 1678 tx_put = cy_readl(&buf_ctrl->tx_put);
1623 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 1679 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
1624 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr); 1680 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr);
1625 if (tx_put >= tx_get) 1681 if (tx_put >= tx_get)
1626 char_count = tx_get - tx_put - 1 + tx_bufsize; 1682 char_count = tx_get - tx_put - 1 + tx_bufsize;
1627 else 1683 else
1628 char_count = tx_get - tx_put - 1; 1684 char_count = tx_get - tx_put - 1;
1629 1685
1630 if ( char_count ) { 1686 if (char_count) {
1631 1687
1632 if( tty == 0 ){ 1688 if (tty == 0) {
1633 goto ztxdone; 1689 goto ztxdone;
1634 } 1690 }
1635 1691
1636 if(info->x_char) { /* send special char */ 1692 if (info->x_char) { /* send special char */
1637 data = info->x_char; 1693 data = info->x_char;
1638 1694
1639 cy_writeb((cinfo->base_addr + tx_bufaddr + tx_put), data); 1695 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1640 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1696 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1641 info->x_char = 0; 1697 info->x_char = 0;
1642 char_count--; 1698 char_count--;
1643 info->icount.tx++; 1699 info->icount.tx++;
1644 info->last_active = jiffies; 1700 info->last_active = jiffies;
1645 info->jiffies[2] = jiffies; 1701 info->jiffies[2] = jiffies;
1646 } 1702 }
1647#ifdef BLOCKMOVE 1703#ifdef BLOCKMOVE
1648 while(0 < (small_count = 1704 while (0 < (small_count = min_t(unsigned int,
1649 min_t(unsigned int, (tx_bufsize - tx_put), 1705 tx_bufsize - tx_put, min_t(unsigned int,
1650 min_t(unsigned int, (SERIAL_XMIT_SIZE - info->xmit_tail), 1706 (SERIAL_XMIT_SIZE - info->xmit_tail),
1651 min_t(unsigned int, info->xmit_cnt, char_count))))) { 1707 min_t(unsigned int, info->xmit_cnt,
1652 1708 char_count))))) {
1653 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr + tx_put), 1709
1654 &info->xmit_buf[info->xmit_tail], 1710 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr +
1655 small_count); 1711 tx_put),
1656 1712 &info->xmit_buf[info->xmit_tail],
1657 tx_put = (tx_put + small_count) & (tx_bufsize - 1); 1713 small_count);
1658 char_count -= small_count; 1714
1659 info->icount.tx += small_count; 1715 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1660 info->xmit_cnt -= small_count; 1716 char_count -= small_count;
1661 info->xmit_tail = 1717 info->icount.tx += small_count;
1662 (info->xmit_tail + small_count) & (SERIAL_XMIT_SIZE - 1); 1718 info->xmit_cnt -= small_count;
1663 info->last_active = jiffies; 1719 info->xmit_tail = (info->xmit_tail + small_count) &
1664 info->jiffies[2] = jiffies; 1720 (SERIAL_XMIT_SIZE - 1);
1665 } 1721 info->last_active = jiffies;
1722 info->jiffies[2] = jiffies;
1723 }
1666#else 1724#else
1667 while (info->xmit_cnt && char_count){ 1725 while (info->xmit_cnt && char_count) {
1668 data = info->xmit_buf[info->xmit_tail]; 1726 data = info->xmit_buf[info->xmit_tail];
1669 info->xmit_cnt--; 1727 info->xmit_cnt--;
1670 info->xmit_tail = (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1); 1728 info->xmit_tail = (info->xmit_tail + 1) &
1671 1729 (SERIAL_XMIT_SIZE - 1);
1672 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data); 1730
1673 tx_put = (tx_put + 1) & (tx_bufsize - 1); 1731 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1674 char_count--; 1732 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1675 info->icount.tx++; 1733 char_count--;
1676 info->last_active = jiffies; 1734 info->icount.tx++;
1677 info->jiffies[2] = jiffies; 1735 info->last_active = jiffies;
1678 } 1736 info->jiffies[2] = jiffies;
1737 }
1679#endif 1738#endif
1680 ztxdone: 1739ztxdone:
1681 if (info->xmit_cnt < WAKEUP_CHARS) { 1740 if (info->xmit_cnt < WAKEUP_CHARS) {
1682 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP); 1741 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1742 }
1743 /* Update tx_put */
1744 cy_writel(&buf_ctrl->tx_put, tx_put);
1683 } 1745 }
1684 /* Update tx_put */
1685 cy_writel(&buf_ctrl->tx_put, tx_put);
1686 }
1687} 1746}
1688 1747
1689static void 1748static void cyz_handle_cmd(struct cyclades_card *cinfo)
1690cyz_handle_cmd(struct cyclades_card *cinfo)
1691{ 1749{
1692 struct tty_struct *tty; 1750 struct tty_struct *tty;
1693 struct cyclades_port *info; 1751 struct cyclades_port *info;
1694 static volatile struct FIRM_ID __iomem *firm_id; 1752 static volatile struct FIRM_ID __iomem *firm_id;
1695 static volatile struct ZFW_CTRL __iomem *zfw_ctrl; 1753 static volatile struct ZFW_CTRL __iomem *zfw_ctrl;
1696 static volatile struct BOARD_CTRL __iomem *board_ctrl; 1754 static volatile struct BOARD_CTRL __iomem *board_ctrl;
1697 static volatile struct CH_CTRL __iomem *ch_ctrl; 1755 static volatile struct CH_CTRL __iomem *ch_ctrl;
1698 static volatile struct BUF_CTRL __iomem *buf_ctrl; 1756 static volatile struct BUF_CTRL __iomem *buf_ctrl;
1699 uclong channel; 1757 uclong channel;
1700 ucchar cmd; 1758 ucchar cmd;
1701 uclong param; 1759 uclong param;
1702 uclong hw_ver, fw_ver; 1760 uclong hw_ver, fw_ver;
1703 int special_count; 1761 int special_count;
1704 int delta_count; 1762 int delta_count;
1705 1763
1706 firm_id = cinfo->base_addr + ID_ADDRESS; 1764 firm_id = cinfo->base_addr + ID_ADDRESS;
1707 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1765 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1708 board_ctrl = &zfw_ctrl->board_ctrl; 1766 0xfffff);
1709 fw_ver = cy_readl(&board_ctrl->fw_version); 1767 board_ctrl = &zfw_ctrl->board_ctrl;
1710 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->mail_box_0); 1768 fw_ver = cy_readl(&board_ctrl->fw_version);
1711 1769 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1712 1770 mail_box_0);
1713 while(cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) { 1771
1714 special_count = 0; 1772 while (cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1) {
1715 delta_count = 0; 1773 special_count = 0;
1716 info = &cy_port[channel + cinfo->first_line]; 1774 delta_count = 0;
1717 if((tty = info->tty) == 0) { 1775 info = &cy_port[channel + cinfo->first_line];
1718 continue; 1776 if ((tty = info->tty) == 0) {
1719 } 1777 continue;
1720 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1721 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1722
1723 switch(cmd) {
1724 case C_CM_PR_ERROR:
1725 tty_insert_flip_char(tty, 0, TTY_PARITY);
1726 info->icount.rx++;
1727 special_count++;
1728 break;
1729 case C_CM_FR_ERROR:
1730 tty_insert_flip_char(tty, 0, TTY_FRAME);
1731 info->icount.rx++;
1732 special_count++;
1733 break;
1734 case C_CM_RXBRK:
1735 tty_insert_flip_char(tty, 0, TTY_BREAK);
1736 info->icount.rx++;
1737 special_count++;
1738 break;
1739 case C_CM_MDCD:
1740 info->icount.dcd++;
1741 delta_count++;
1742 if (info->flags & ASYNC_CHECK_CD){
1743 if ((fw_ver > 241 ?
1744 ((u_long)param) :
1745 cy_readl(&ch_ctrl->rs_status)) & C_RS_DCD) {
1746 cy_sched_event(info, Cy_EVENT_OPEN_WAKEUP);
1747 }else{
1748 cy_sched_event(info, Cy_EVENT_HANGUP);
1749 }
1750 } 1778 }
1751 break; 1779 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1752 case C_CM_MCTS: 1780 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1753 info->icount.cts++; 1781
1754 delta_count++; 1782 switch (cmd) {
1755 break; 1783 case C_CM_PR_ERROR:
1756 case C_CM_MRI: 1784 tty_insert_flip_char(tty, 0, TTY_PARITY);
1757 info->icount.rng++; 1785 info->icount.rx++;
1758 delta_count++; 1786 special_count++;
1759 break; 1787 break;
1760 case C_CM_MDSR: 1788 case C_CM_FR_ERROR:
1761 info->icount.dsr++; 1789 tty_insert_flip_char(tty, 0, TTY_FRAME);
1762 delta_count++; 1790 info->icount.rx++;
1763 break; 1791 special_count++;
1792 break;
1793 case C_CM_RXBRK:
1794 tty_insert_flip_char(tty, 0, TTY_BREAK);
1795 info->icount.rx++;
1796 special_count++;
1797 break;
1798 case C_CM_MDCD:
1799 info->icount.dcd++;
1800 delta_count++;
1801 if (info->flags & ASYNC_CHECK_CD) {
1802 if ((fw_ver > 241 ? ((u_long) param) :
1803 cy_readl(&ch_ctrl->rs_status)) &
1804 C_RS_DCD) {
1805 cy_sched_event(info,
1806 Cy_EVENT_OPEN_WAKEUP);
1807 } else {
1808 cy_sched_event(info, Cy_EVENT_HANGUP);
1809 }
1810 }
1811 break;
1812 case C_CM_MCTS:
1813 info->icount.cts++;
1814 delta_count++;
1815 break;
1816 case C_CM_MRI:
1817 info->icount.rng++;
1818 delta_count++;
1819 break;
1820 case C_CM_MDSR:
1821 info->icount.dsr++;
1822 delta_count++;
1823 break;
1764#ifdef Z_WAKE 1824#ifdef Z_WAKE
1765 case C_CM_IOCTLW: 1825 case C_CM_IOCTLW:
1766 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP); 1826 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
1767 break; 1827 break;
1768#endif 1828#endif
1769#ifdef CONFIG_CYZ_INTR 1829#ifdef CONFIG_CYZ_INTR
1770 case C_CM_RXHIWM: 1830 case C_CM_RXHIWM:
1771 case C_CM_RXNNDT: 1831 case C_CM_RXNNDT:
1772 case C_CM_INTBACK2: 1832 case C_CM_INTBACK2:
1773 /* Reception Interrupt */ 1833 /* Reception Interrupt */
1774#ifdef CY_DEBUG_INTERRUPTS 1834#ifdef CY_DEBUG_INTERRUPTS
1775 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r", 1835 printk("cyz_interrupt: rcvd intr, card %d, "
1776 info->card, channel); 1836 "port %ld\n\r", info->card, channel);
1777#endif 1837#endif
1778 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1838 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1779 break; 1839 break;
1780 case C_CM_TXBEMPTY: 1840 case C_CM_TXBEMPTY:
1781 case C_CM_TXLOWWM: 1841 case C_CM_TXLOWWM:
1782 case C_CM_INTBACK: 1842 case C_CM_INTBACK:
1783 /* Transmission Interrupt */ 1843 /* Transmission Interrupt */
1784#ifdef CY_DEBUG_INTERRUPTS 1844#ifdef CY_DEBUG_INTERRUPTS
1785 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r", 1845 printk("cyz_interrupt: xmit intr, card %d, "
1786 info->card, channel); 1846 "port %ld\n\r", info->card, channel);
1787#endif 1847#endif
1788 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1848 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1789 break; 1849 break;
1790#endif /* CONFIG_CYZ_INTR */ 1850#endif /* CONFIG_CYZ_INTR */
1791 case C_CM_FATAL: 1851 case C_CM_FATAL:
1792 /* should do something with this !!! */ 1852 /* should do something with this !!! */
1793 break; 1853 break;
1794 default: 1854 default:
1795 break; 1855 break;
1856 }
1857 if (delta_count)
1858 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1859 if (special_count)
1860 tty_schedule_flip(tty);
1796 } 1861 }
1797 if(delta_count)
1798 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1799 if(special_count)
1800 tty_schedule_flip(tty);
1801 }
1802} 1862}
1803 1863
1804#ifdef CONFIG_CYZ_INTR 1864#ifdef CONFIG_CYZ_INTR
1805static irqreturn_t 1865static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1806cyz_interrupt(int irq, void *dev_id)
1807{ 1866{
1808 struct cyclades_card *cinfo; 1867 struct cyclades_card *cinfo;
1809 1868
1810 if((cinfo = (struct cyclades_card *)dev_id) == 0){ 1869 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1811#ifdef CY_DEBUG_INTERRUPTS 1870#ifdef CY_DEBUG_INTERRUPTS
1812 printk("cyz_interrupt: spurious interrupt %d\n\r", irq); 1871 printk("cyz_interrupt: spurious interrupt %d\n\r", irq);
1813#endif 1872#endif
1814 return IRQ_NONE; /* spurious interrupt */ 1873 return IRQ_NONE; /* spurious interrupt */
1815 } 1874 }
1816 1875
1817 if (!ISZLOADED(*cinfo)) { 1876 if (!ISZLOADED(*cinfo)) {
1818#ifdef CY_DEBUG_INTERRUPTS 1877#ifdef CY_DEBUG_INTERRUPTS
1819 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq); 1878 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq);
1820#endif 1879#endif
1821 return IRQ_NONE; 1880 return IRQ_NONE;
1822 } 1881 }
1823 1882
1824 /* Handle the interrupts */ 1883 /* Handle the interrupts */
1825 cyz_handle_cmd(cinfo); 1884 cyz_handle_cmd(cinfo);
1826 1885
1827 return IRQ_HANDLED; 1886 return IRQ_HANDLED;
1828} /* cyz_interrupt */ 1887} /* cyz_interrupt */
1829 1888
1830static void 1889static void cyz_rx_restart(unsigned long arg)
1831cyz_rx_restart(unsigned long arg)
1832{ 1890{
1833 struct cyclades_port *info = (struct cyclades_port *)arg; 1891 struct cyclades_port *info = (struct cyclades_port *)arg;
1834 int retval; 1892 int retval;
1835 int card = info->card; 1893 int card = info->card;
1836 uclong channel = (info->line) - (cy_card[card].first_line); 1894 uclong channel = (info->line) - (cy_card[card].first_line);
1837 unsigned long flags; 1895 unsigned long flags;
1838 1896
1839 CY_LOCK(info, flags); 1897 CY_LOCK(info, flags);
1840 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L); 1898 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L);
1841 if (retval != 0){ 1899 if (retval != 0) {
1842 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n", 1900 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1843 info->line, retval); 1901 info->line, retval);
1844 } 1902 }
1845 cyz_rx_full_timer[info->line].function = NULL; 1903 cyz_rx_full_timer[info->line].function = NULL;
1846 CY_UNLOCK(info, flags); 1904 CY_UNLOCK(info, flags);
1847} 1905}
1848 1906
1849#else /* CONFIG_CYZ_INTR */ 1907#else /* CONFIG_CYZ_INTR */
1850 1908
1851static void 1909static void cyz_poll(unsigned long arg)
1852cyz_poll(unsigned long arg)
1853{ 1910{
1854 struct cyclades_card *cinfo; 1911 struct cyclades_card *cinfo;
1855 struct cyclades_port *info; 1912 struct cyclades_port *info;
1856 struct tty_struct *tty; 1913 struct tty_struct *tty;
1857 static volatile struct FIRM_ID *firm_id; 1914 static volatile struct FIRM_ID *firm_id;
1858 static volatile struct ZFW_CTRL *zfw_ctrl; 1915 static volatile struct ZFW_CTRL *zfw_ctrl;
1859 static volatile struct BOARD_CTRL *board_ctrl; 1916 static volatile struct BOARD_CTRL *board_ctrl;
1860 static volatile struct CH_CTRL *ch_ctrl; 1917 static volatile struct CH_CTRL *ch_ctrl;
1861 static volatile struct BUF_CTRL *buf_ctrl; 1918 static volatile struct BUF_CTRL *buf_ctrl;
1862 int card, port; 1919 int card, port;
1863
1864 cyz_timerlist.expires = jiffies + (HZ);
1865 for (card = 0 ; card < NR_CARDS ; card++){
1866 cinfo = &cy_card[card];
1867
1868 if (!IS_CYC_Z(*cinfo)) continue;
1869 if (!ISZLOADED(*cinfo)) continue;
1870 1920
1871 firm_id = cinfo->base_addr + ID_ADDRESS; 1921 cyz_timerlist.expires = jiffies + (HZ);
1872 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 1922 for (card = 0; card < NR_CARDS; card++) {
1873 board_ctrl = &(zfw_ctrl->board_ctrl); 1923 cinfo = &cy_card[card];
1924
1925 if (!IS_CYC_Z(*cinfo))
1926 continue;
1927 if (!ISZLOADED(*cinfo))
1928 continue;
1929
1930 firm_id = cinfo->base_addr + ID_ADDRESS;
1931 zfw_ctrl = cinfo->base_addr +
1932 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
1933 board_ctrl = &(zfw_ctrl->board_ctrl);
1874 1934
1875 /* Skip first polling cycle to avoid racing conditions with the FW */ 1935 /* Skip first polling cycle to avoid racing conditions with the FW */
1876 if (!cinfo->intr_enabled) { 1936 if (!cinfo->intr_enabled) {
1877 cinfo->nports = (int) cy_readl(&board_ctrl->n_channel); 1937 cinfo->nports = (int)cy_readl(&board_ctrl->n_channel);
1878 cinfo->intr_enabled = 1; 1938 cinfo->intr_enabled = 1;
1879 continue; 1939 continue;
1880 } 1940 }
1881 1941
1882 cyz_handle_cmd(cinfo); 1942 cyz_handle_cmd(cinfo);
1883 1943
1884 for (port = 0 ; port < cinfo->nports ; port++) { 1944 for (port = 0; port < cinfo->nports; port++) {
1885 info = &cy_port[ port + cinfo->first_line ]; 1945 info = &cy_port[port + cinfo->first_line];
1886 tty = info->tty; 1946 tty = info->tty;
1887 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]); 1947 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1888 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]); 1948 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
1889 1949
1890 if (!info->throttle) 1950 if (!info->throttle)
1891 cyz_handle_rx(info, ch_ctrl, buf_ctrl); 1951 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1892 cyz_handle_tx(info, ch_ctrl, buf_ctrl); 1952 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1953 }
1954 /* poll every 'cyz_polling_cycle' period */
1955 cyz_timerlist.expires = jiffies + cyz_polling_cycle;
1893 } 1956 }
1894 /* poll every 'cyz_polling_cycle' period */ 1957 add_timer(&cyz_timerlist);
1895 cyz_timerlist.expires = jiffies + cyz_polling_cycle; 1958} /* cyz_poll */
1896 }
1897 add_timer(&cyz_timerlist);
1898 1959
1899 return; 1960#endif /* CONFIG_CYZ_INTR */
1900} /* cyz_poll */
1901
1902#endif /* CONFIG_CYZ_INTR */
1903 1961
1904/********** End of block of Cyclades-Z specific code *********/ 1962/********** End of block of Cyclades-Z specific code *********/
1905/***********************************************************/ 1963/***********************************************************/
1906 1964
1907
1908/* This is called whenever a port becomes active; 1965/* This is called whenever a port becomes active;
1909 interrupts are enabled and DTR & RTS are turned on. 1966 interrupts are enabled and DTR & RTS are turned on.
1910 */ 1967 */
1911static int 1968static int startup(struct cyclades_port *info)
1912startup(struct cyclades_port * info)
1913{ 1969{
1914 unsigned long flags; 1970 unsigned long flags;
1915 int retval = 0; 1971 int retval = 0;
1916 void __iomem *base_addr; 1972 void __iomem *base_addr;
1917 int card,chip,channel,index; 1973 int card, chip, channel, index;
1918 unsigned long page; 1974 unsigned long page;
1919 1975
1920 card = info->card; 1976 card = info->card;
1921 channel = (info->line) - (cy_card[card].first_line); 1977 channel = (info->line) - (cy_card[card].first_line);
1922 1978
1923 page = get_zeroed_page(GFP_KERNEL); 1979 page = get_zeroed_page(GFP_KERNEL);
1924 if (!page) 1980 if (!page)
1925 return -ENOMEM; 1981 return -ENOMEM;
1926 1982
1927 CY_LOCK(info, flags); 1983 CY_LOCK(info, flags);
1928 1984
1929 if (info->flags & ASYNC_INITIALIZED){ 1985 if (info->flags & ASYNC_INITIALIZED) {
1930 free_page(page); 1986 free_page(page);
1931 goto errout; 1987 goto errout;
1932 } 1988 }
1933 1989
1934 if (!info->type){ 1990 if (!info->type) {
1935 if (info->tty){ 1991 if (info->tty) {
1936 set_bit(TTY_IO_ERROR, &info->tty->flags); 1992 set_bit(TTY_IO_ERROR, &info->tty->flags);
1937 } 1993 }
1938 free_page(page); 1994 free_page(page);
1939 goto errout; 1995 goto errout;
1940 } 1996 }
1941 1997
1942 if (info->xmit_buf) 1998 if (info->xmit_buf)
1943 free_page(page); 1999 free_page(page);
1944 else 2000 else
1945 info->xmit_buf = (unsigned char *) page; 2001 info->xmit_buf = (unsigned char *)page;
1946 2002
1947 CY_UNLOCK(info, flags); 2003 CY_UNLOCK(info, flags);
1948 2004
1949 set_line_char(info); 2005 set_line_char(info);
1950 2006
1951 if (!IS_CYC_Z(cy_card[card])) { 2007 if (!IS_CYC_Z(cy_card[card])) {
1952 chip = channel>>2; 2008 chip = channel >> 2;
1953 channel &= 0x03; 2009 channel &= 0x03;
1954 index = cy_card[card].bus_index; 2010 index = cy_card[card].bus_index;
1955 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2011 base_addr = cy_card[card].base_addr +
2012 (cy_chip_offset[chip] << index);
1956 2013
1957#ifdef CY_DEBUG_OPEN 2014#ifdef CY_DEBUG_OPEN
1958 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n", 2015 printk("cyc startup card %d, chip %d, channel %d, "
1959 card, chip, channel, (long)base_addr);/**/ 2016 "base_addr %lx\n",
2017 card, chip, channel, (long)base_addr);
2018 /**/
1960#endif 2019#endif
2020 CY_LOCK(info, flags);
1961 2021
1962 CY_LOCK(info, flags); 2022 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1963
1964 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
1965 2023
1966 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 2024 cy_writeb(base_addr + (CyRTPR << index),
1967 ? info->default_timeout : 0x02)); /* 10ms rx timeout */ 2025 (info->default_timeout ? info->default_timeout : 0x02));
2026 /* 10ms rx timeout */
1968 2027
1969 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR,index); 2028 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyENB_RCVR | CyENB_XMTR,
2029 index);
1970 2030
1971 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2031 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
1972 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2032 cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
1973 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2033 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
1974 2034
1975#ifdef CY_DEBUG_DTR 2035#ifdef CY_DEBUG_DTR
1976 printk("cyc:startup raising DTR\n"); 2036 printk("cyc:startup raising DTR\n");
1977 printk(" status: 0x%x, 0x%x\n", 2037 printk(" status: 0x%x, 0x%x\n",
1978 cy_readb(base_addr+(CyMSVR1<<index)), 2038 cy_readb(base_addr + (CyMSVR1 << index)),
1979 cy_readb(base_addr+(CyMSVR2<<index))); 2039 cy_readb(base_addr + (CyMSVR2 << index)));
1980#endif 2040#endif
1981 2041
1982 cy_writeb(base_addr+(CySRER<<index), 2042 cy_writeb(base_addr + (CySRER << index),
1983 cy_readb(base_addr+(CySRER<<index)) | CyRxData); 2043 cy_readb(base_addr + (CySRER << index)) | CyRxData);
1984 info->flags |= ASYNC_INITIALIZED; 2044 info->flags |= ASYNC_INITIALIZED;
1985 2045
1986 if (info->tty){ 2046 if (info->tty) {
1987 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2047 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1988 } 2048 }
1989 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2049 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1990 info->breakon = info->breakoff = 0; 2050 info->breakon = info->breakoff = 0;
1991 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2051 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
1992 info->idle_stats.in_use = 2052 info->idle_stats.in_use =
1993 info->idle_stats.recv_idle = 2053 info->idle_stats.recv_idle =
1994 info->idle_stats.xmit_idle = jiffies; 2054 info->idle_stats.xmit_idle = jiffies;
1995 2055
1996 CY_UNLOCK(info, flags); 2056 CY_UNLOCK(info, flags);
1997 2057
1998 } else { 2058 } else {
1999 struct FIRM_ID __iomem *firm_id; 2059 struct FIRM_ID __iomem *firm_id;
2000 struct ZFW_CTRL __iomem *zfw_ctrl; 2060 struct ZFW_CTRL __iomem *zfw_ctrl;
2001 struct BOARD_CTRL __iomem *board_ctrl; 2061 struct BOARD_CTRL __iomem *board_ctrl;
2002 struct CH_CTRL __iomem *ch_ctrl; 2062 struct CH_CTRL __iomem *ch_ctrl;
2003 int retval; 2063 int retval;
2004 2064
2005 base_addr = cy_card[card].base_addr; 2065 base_addr = cy_card[card].base_addr;
2006 2066
2007 firm_id = base_addr + ID_ADDRESS; 2067 firm_id = base_addr + ID_ADDRESS;
2008 if (!ISZLOADED(cy_card[card])){ 2068 if (!ISZLOADED(cy_card[card])) {
2009 return -ENODEV; 2069 return -ENODEV;
2010 } 2070 }
2011 2071
2012 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2072 zfw_ctrl = cy_card[card].base_addr +
2013 board_ctrl = &zfw_ctrl->board_ctrl; 2073 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2014 ch_ctrl = zfw_ctrl->ch_ctrl; 2074 board_ctrl = &zfw_ctrl->board_ctrl;
2075 ch_ctrl = zfw_ctrl->ch_ctrl;
2015 2076
2016#ifdef CY_DEBUG_OPEN 2077#ifdef CY_DEBUG_OPEN
2017 printk("cyc startup Z card %d, channel %d, base_addr %lx\n", 2078 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2018 card, channel, (long)base_addr);/**/ 2079 card, channel, (long)base_addr);
2080 /**/
2019#endif 2081#endif
2082 CY_LOCK(info, flags);
2020 2083
2021 CY_LOCK(info, flags); 2084 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2022
2023 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2024#ifdef Z_WAKE 2085#ifdef Z_WAKE
2025#ifdef CONFIG_CYZ_INTR 2086#ifdef CONFIG_CYZ_INTR
2026 cy_writel(&ch_ctrl[channel].intr_enable, 2087 cy_writel(&ch_ctrl[channel].intr_enable,
2027 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2088 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2028 C_IN_IOCTLW| 2089 C_IN_RXNNDT | C_IN_IOCTLW | C_IN_MDCD);
2029 C_IN_MDCD);
2030#else 2090#else
2031 cy_writel(&ch_ctrl[channel].intr_enable, 2091 cy_writel(&ch_ctrl[channel].intr_enable,
2032 C_IN_IOCTLW| 2092 C_IN_IOCTLW | C_IN_MDCD);
2033 C_IN_MDCD); 2093#endif /* CONFIG_CYZ_INTR */
2034#endif /* CONFIG_CYZ_INTR */
2035#else 2094#else
2036#ifdef CONFIG_CYZ_INTR 2095#ifdef CONFIG_CYZ_INTR
2037 cy_writel(&ch_ctrl[channel].intr_enable, 2096 cy_writel(&ch_ctrl[channel].intr_enable,
2038 C_IN_TXBEMPTY|C_IN_TXLOWWM|C_IN_RXHIWM|C_IN_RXNNDT| 2097 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2039 C_IN_MDCD); 2098 C_IN_RXNNDT | C_IN_MDCD);
2040#else 2099#else
2041 cy_writel(&ch_ctrl[channel].intr_enable, 2100 cy_writel(&ch_ctrl[channel].intr_enable, C_IN_MDCD);
2042 C_IN_MDCD); 2101#endif /* CONFIG_CYZ_INTR */
2043#endif /* CONFIG_CYZ_INTR */ 2102#endif /* Z_WAKE */
2044#endif /* Z_WAKE */ 2103
2045 2104 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
2046 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 2105 if (retval != 0) {
2047 if (retval != 0){ 2106 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2048 printk("cyc:startup(1) retval on ttyC%d was %x\n", 2107 info->line, retval);
2049 info->line, retval); 2108 }
2050 }
2051 2109
2052 /* Flush RX buffers before raising DTR and RTS */ 2110 /* Flush RX buffers before raising DTR and RTS */
2053 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX, 0L); 2111 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX,
2054 if (retval != 0){ 2112 0L);
2055 printk("cyc:startup(2) retval on ttyC%d was %x\n", 2113 if (retval != 0) {
2056 info->line, retval); 2114 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2057 } 2115 info->line, retval);
2116 }
2058 2117
2059 /* set timeout !!! */ 2118 /* set timeout !!! */
2060 /* set RTS and DTR !!! */ 2119 /* set RTS and DTR !!! */
2061 cy_writel(&ch_ctrl[channel].rs_control, 2120 cy_writel(&ch_ctrl[channel].rs_control,
2062 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR) ; 2121 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
2063 retval = cyz_issue_cmd(&cy_card[info->card], 2122 C_RS_DTR);
2064 channel, C_CM_IOCTLM, 0L); 2123 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2065 if (retval != 0){ 2124 C_CM_IOCTLM, 0L);
2066 printk("cyc:startup(3) retval on ttyC%d was %x\n", 2125 if (retval != 0) {
2067 info->line, retval); 2126 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2068 } 2127 info->line, retval);
2128 }
2069#ifdef CY_DEBUG_DTR 2129#ifdef CY_DEBUG_DTR
2070 printk("cyc:startup raising Z DTR\n"); 2130 printk("cyc:startup raising Z DTR\n");
2071#endif 2131#endif
2072 2132
2073 /* enable send, recv, modem !!! */ 2133 /* enable send, recv, modem !!! */
2074 2134
2075 info->flags |= ASYNC_INITIALIZED; 2135 info->flags |= ASYNC_INITIALIZED;
2076 if (info->tty){ 2136 if (info->tty) {
2077 clear_bit(TTY_IO_ERROR, &info->tty->flags); 2137 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2078 } 2138 }
2079 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 2139 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2080 info->breakon = info->breakoff = 0; 2140 info->breakon = info->breakoff = 0;
2081 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats)); 2141 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2082 info->idle_stats.in_use = 2142 info->idle_stats.in_use =
2083 info->idle_stats.recv_idle = 2143 info->idle_stats.recv_idle =
2084 info->idle_stats.xmit_idle = jiffies; 2144 info->idle_stats.xmit_idle = jiffies;
2085 2145
2086 CY_UNLOCK(info, flags); 2146 CY_UNLOCK(info, flags);
2087 } 2147 }
2088 2148
2089#ifdef CY_DEBUG_OPEN 2149#ifdef CY_DEBUG_OPEN
2090 printk(" cyc startup done\n"); 2150 printk(" cyc startup done\n");
@@ -2094,165 +2154,165 @@ startup(struct cyclades_port * info)
2094errout: 2154errout:
2095 CY_UNLOCK(info, flags); 2155 CY_UNLOCK(info, flags);
2096 return retval; 2156 return retval;
2097} /* startup */ 2157} /* startup */
2098
2099 2158
2100static void 2159static void start_xmit(struct cyclades_port *info)
2101start_xmit( struct cyclades_port *info )
2102{ 2160{
2103 unsigned long flags; 2161 unsigned long flags;
2104 void __iomem *base_addr; 2162 void __iomem *base_addr;
2105 int card,chip,channel,index; 2163 int card, chip, channel, index;
2106
2107 card = info->card;
2108 channel = (info->line) - (cy_card[card].first_line);
2109 if (!IS_CYC_Z(cy_card[card])) {
2110 chip = channel>>2;
2111 channel &= 0x03;
2112 index = cy_card[card].bus_index;
2113 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
2114 2164
2115 CY_LOCK(info, flags); 2165 card = info->card;
2116 cy_writeb(base_addr+(CyCAR<<index), channel); 2166 channel = (info->line) - (cy_card[card].first_line);
2117 cy_writeb(base_addr+(CySRER<<index), 2167 if (!IS_CYC_Z(cy_card[card])) {
2118 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy); 2168 chip = channel >> 2;
2119 CY_UNLOCK(info, flags); 2169 channel &= 0x03;
2120 } else { 2170 index = cy_card[card].bus_index;
2171 base_addr = cy_card[card].base_addr +
2172 (cy_chip_offset[chip] << index);
2173
2174 CY_LOCK(info, flags);
2175 cy_writeb(base_addr + (CyCAR << index), channel);
2176 cy_writeb(base_addr + (CySRER << index),
2177 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
2178 CY_UNLOCK(info, flags);
2179 } else {
2121#ifdef CONFIG_CYZ_INTR 2180#ifdef CONFIG_CYZ_INTR
2122 int retval; 2181 int retval;
2123 2182
2124 CY_LOCK(info, flags); 2183 CY_LOCK(info, flags);
2125 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK, 0L); 2184 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK,
2126 if (retval != 0){ 2185 0L);
2127 printk("cyc:start_xmit retval on ttyC%d was %x\n", 2186 if (retval != 0) {
2128 info->line, retval); 2187 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2129 } 2188 info->line, retval);
2130 CY_UNLOCK(info, flags); 2189 }
2131#else /* CONFIG_CYZ_INTR */ 2190 CY_UNLOCK(info, flags);
2132 /* Don't have to do anything at this time */ 2191#else /* CONFIG_CYZ_INTR */
2133#endif /* CONFIG_CYZ_INTR */ 2192 /* Don't have to do anything at this time */
2134 } 2193#endif /* CONFIG_CYZ_INTR */
2135} /* start_xmit */ 2194 }
2195} /* start_xmit */
2136 2196
2137/* 2197/*
2138 * This routine shuts down a serial port; interrupts are disabled, 2198 * This routine shuts down a serial port; interrupts are disabled,
2139 * and DTR is dropped if the hangup on close termio flag is on. 2199 * and DTR is dropped if the hangup on close termio flag is on.
2140 */ 2200 */
2141static void 2201static void shutdown(struct cyclades_port *info)
2142shutdown(struct cyclades_port * info)
2143{ 2202{
2144 unsigned long flags; 2203 unsigned long flags;
2145 void __iomem *base_addr; 2204 void __iomem *base_addr;
2146 int card,chip,channel,index; 2205 int card, chip, channel, index;
2147 2206
2148 if (!(info->flags & ASYNC_INITIALIZED)){ 2207 if (!(info->flags & ASYNC_INITIALIZED)) {
2149 return; 2208 return;
2150 } 2209 }
2151 2210
2152 card = info->card; 2211 card = info->card;
2153 channel = info->line - cy_card[card].first_line; 2212 channel = info->line - cy_card[card].first_line;
2154 if (!IS_CYC_Z(cy_card[card])) { 2213 if (!IS_CYC_Z(cy_card[card])) {
2155 chip = channel>>2; 2214 chip = channel >> 2;
2156 channel &= 0x03; 2215 channel &= 0x03;
2157 index = cy_card[card].bus_index; 2216 index = cy_card[card].bus_index;
2158 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2217 base_addr = cy_card[card].base_addr +
2218 (cy_chip_offset[chip] << index);
2159 2219
2160#ifdef CY_DEBUG_OPEN 2220#ifdef CY_DEBUG_OPEN
2161 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n", 2221 printk("cyc shutdown Y card %d, chip %d, channel %d, "
2162 card, chip, channel, (long)base_addr); 2222 "base_addr %lx\n",
2223 card, chip, channel, (long)base_addr);
2163#endif 2224#endif
2164 2225
2165 CY_LOCK(info, flags); 2226 CY_LOCK(info, flags);
2166 2227
2167 /* Clear delta_msr_wait queue to avoid mem leaks. */ 2228 /* Clear delta_msr_wait queue to avoid mem leaks. */
2168 wake_up_interruptible(&info->delta_msr_wait); 2229 wake_up_interruptible(&info->delta_msr_wait);
2169 2230
2170 if (info->xmit_buf){ 2231 if (info->xmit_buf) {
2171 unsigned char * temp; 2232 unsigned char *temp;
2172 temp = info->xmit_buf; 2233 temp = info->xmit_buf;
2173 info->xmit_buf = NULL; 2234 info->xmit_buf = NULL;
2174 free_page((unsigned long) temp); 2235 free_page((unsigned long)temp);
2175 } 2236 }
2176 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2237 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2177 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) { 2238 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2178 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 2239 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
2179 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 2240 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
2180#ifdef CY_DEBUG_DTR 2241#ifdef CY_DEBUG_DTR
2181 printk("cyc shutdown dropping DTR\n"); 2242 printk("cyc shutdown dropping DTR\n");
2182 printk(" status: 0x%x, 0x%x\n", 2243 printk(" status: 0x%x, 0x%x\n",
2183 cy_readb(base_addr+(CyMSVR1<<index)), 2244 cy_readb(base_addr + (CyMSVR1 << index)),
2184 cy_readb(base_addr+(CyMSVR2<<index))); 2245 cy_readb(base_addr + (CyMSVR2 << index)));
2185#endif 2246#endif
2186 } 2247 }
2187 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR,index); 2248 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
2188 /* it may be appropriate to clear _XMIT at 2249 /* it may be appropriate to clear _XMIT at
2189 some later date (after testing)!!! */ 2250 some later date (after testing)!!! */
2190 2251
2191 if (info->tty){ 2252 if (info->tty) {
2192 set_bit(TTY_IO_ERROR, &info->tty->flags); 2253 set_bit(TTY_IO_ERROR, &info->tty->flags);
2193 } 2254 }
2194 info->flags &= ~ASYNC_INITIALIZED; 2255 info->flags &= ~ASYNC_INITIALIZED;
2195 CY_UNLOCK(info, flags); 2256 CY_UNLOCK(info, flags);
2196 } else { 2257 } else {
2197 struct FIRM_ID __iomem *firm_id; 2258 struct FIRM_ID __iomem *firm_id;
2198 struct ZFW_CTRL __iomem *zfw_ctrl; 2259 struct ZFW_CTRL __iomem *zfw_ctrl;
2199 struct BOARD_CTRL __iomem *board_ctrl; 2260 struct BOARD_CTRL __iomem *board_ctrl;
2200 struct CH_CTRL __iomem *ch_ctrl; 2261 struct CH_CTRL __iomem *ch_ctrl;
2201 int retval; 2262 int retval;
2202 2263
2203 base_addr = cy_card[card].base_addr; 2264 base_addr = cy_card[card].base_addr;
2204#ifdef CY_DEBUG_OPEN 2265#ifdef CY_DEBUG_OPEN
2205 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n", 2266 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2206 card, channel, (long)base_addr); 2267 card, channel, (long)base_addr);
2207#endif 2268#endif
2208 2269
2209 firm_id = base_addr + ID_ADDRESS; 2270 firm_id = base_addr + ID_ADDRESS;
2210 if (!ISZLOADED(cy_card[card])) { 2271 if (!ISZLOADED(cy_card[card])) {
2211 return; 2272 return;
2212 } 2273 }
2213 2274
2214 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 2275 zfw_ctrl = cy_card[card].base_addr +
2215 board_ctrl = &zfw_ctrl->board_ctrl; 2276 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2216 ch_ctrl = zfw_ctrl->ch_ctrl; 2277 board_ctrl = &zfw_ctrl->board_ctrl;
2278 ch_ctrl = zfw_ctrl->ch_ctrl;
2217 2279
2218 CY_LOCK(info, flags); 2280 CY_LOCK(info, flags);
2219 2281
2220 if (info->xmit_buf){ 2282 if (info->xmit_buf) {
2221 unsigned char * temp; 2283 unsigned char *temp;
2222 temp = info->xmit_buf; 2284 temp = info->xmit_buf;
2223 info->xmit_buf = NULL; 2285 info->xmit_buf = NULL;
2224 free_page((unsigned long) temp); 2286 free_page((unsigned long)temp);
2225 }
2226
2227 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2228 cy_writel(&ch_ctrl[channel].rs_control,
2229 (uclong)(cy_readl(&ch_ctrl[channel].rs_control) &
2230 ~(C_RS_RTS | C_RS_DTR)));
2231 retval = cyz_issue_cmd(&cy_card[info->card],
2232 channel, C_CM_IOCTLM, 0L);
2233 if (retval != 0){
2234 printk("cyc:shutdown retval on ttyC%d was %x\n",
2235 info->line, retval);
2236 } 2287 }
2288
2289 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2290 cy_writel(&ch_ctrl[channel].rs_control,
2291 (uclong)(cy_readl(&ch_ctrl[channel].rs_control)&
2292 ~(C_RS_RTS | C_RS_DTR)));
2293 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2294 C_CM_IOCTLM, 0L);
2295 if (retval != 0) {
2296 printk("cyc:shutdown retval on ttyC%d was %x\n",
2297 info->line, retval);
2298 }
2237#ifdef CY_DEBUG_DTR 2299#ifdef CY_DEBUG_DTR
2238 printk("cyc:shutdown dropping Z DTR\n"); 2300 printk("cyc:shutdown dropping Z DTR\n");
2239#endif 2301#endif
2240 } 2302 }
2241
2242 if (info->tty){
2243 set_bit(TTY_IO_ERROR, &info->tty->flags);
2244 }
2245 info->flags &= ~ASYNC_INITIALIZED;
2246 2303
2247 CY_UNLOCK(info, flags); 2304 if (info->tty) {
2248 } 2305 set_bit(TTY_IO_ERROR, &info->tty->flags);
2306 }
2307 info->flags &= ~ASYNC_INITIALIZED;
2308
2309 CY_UNLOCK(info, flags);
2310 }
2249 2311
2250#ifdef CY_DEBUG_OPEN 2312#ifdef CY_DEBUG_OPEN
2251 printk(" cyc shutdown done\n"); 2313 printk(" cyc shutdown done\n");
2252#endif 2314#endif
2253 return; 2315} /* shutdown */
2254} /* shutdown */
2255
2256 2316
2257/* 2317/*
2258 * ------------------------------------------------------------ 2318 * ------------------------------------------------------------
@@ -2261,527 +2321,546 @@ shutdown(struct cyclades_port * info)
2261 */ 2321 */
2262 2322
2263static int 2323static int
2264block_til_ready(struct tty_struct *tty, struct file * filp, 2324block_til_ready(struct tty_struct *tty, struct file *filp,
2265 struct cyclades_port *info) 2325 struct cyclades_port *info)
2266{ 2326{
2267 DECLARE_WAITQUEUE(wait, current); 2327 DECLARE_WAITQUEUE(wait, current);
2268 struct cyclades_card *cinfo; 2328 struct cyclades_card *cinfo;
2269 unsigned long flags; 2329 unsigned long flags;
2270 int chip, channel,index; 2330 int chip, channel, index;
2271 int retval; 2331 int retval;
2272 void __iomem *base_addr; 2332 void __iomem *base_addr;
2273 2333
2274 cinfo = &cy_card[info->card]; 2334 cinfo = &cy_card[info->card];
2275 channel = info->line - cinfo->first_line; 2335 channel = info->line - cinfo->first_line;
2276 2336
2277 /* 2337 /*
2278 * If the device is in the middle of being closed, then block 2338 * If the device is in the middle of being closed, then block
2279 * until it's done, and then try again. 2339 * until it's done, and then try again.
2280 */ 2340 */
2281 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2341 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2282 if (info->flags & ASYNC_CLOSING) { 2342 if (info->flags & ASYNC_CLOSING) {
2283 interruptible_sleep_on(&info->close_wait); 2343 interruptible_sleep_on(&info->close_wait);
2344 }
2345 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2346 }
2347
2348 /*
2349 * If non-blocking mode is set, then make the check up front
2350 * and then exit.
2351 */
2352 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2353 info->flags |= ASYNC_NORMAL_ACTIVE;
2354 return 0;
2284 } 2355 }
2285 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 2356
2286 } 2357 /*
2287 2358 * Block waiting for the carrier detect and the line to become
2288 /* 2359 * free (i.e., not in use by the callout). While we are in
2289 * If non-blocking mode is set, then make the check up front 2360 * this loop, info->count is dropped by one, so that
2290 * and then exit. 2361 * cy_close() knows when to free things. We restore it upon
2291 */ 2362 * exit, either normal or abnormal.
2292 if ((filp->f_flags & O_NONBLOCK) || 2363 */
2293 (tty->flags & (1 << TTY_IO_ERROR))) { 2364 retval = 0;
2294 info->flags |= ASYNC_NORMAL_ACTIVE; 2365 add_wait_queue(&info->open_wait, &wait);
2295 return 0;
2296 }
2297
2298 /*
2299 * Block waiting for the carrier detect and the line to become
2300 * free (i.e., not in use by the callout). While we are in
2301 * this loop, info->count is dropped by one, so that
2302 * cy_close() knows when to free things. We restore it upon
2303 * exit, either normal or abnormal.
2304 */
2305 retval = 0;
2306 add_wait_queue(&info->open_wait, &wait);
2307#ifdef CY_DEBUG_OPEN 2366#ifdef CY_DEBUG_OPEN
2308 printk("cyc block_til_ready before block: ttyC%d, count = %d\n", 2367 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2309 info->line, info->count);/**/ 2368 info->line, info->count);
2369 /**/
2310#endif 2370#endif
2311 CY_LOCK(info, flags); 2371 CY_LOCK(info, flags);
2312 if (!tty_hung_up_p(filp)) 2372 if (!tty_hung_up_p(filp))
2313 info->count--; 2373 info->count--;
2314 CY_UNLOCK(info, flags); 2374 CY_UNLOCK(info, flags);
2315#ifdef CY_DEBUG_COUNT 2375#ifdef CY_DEBUG_COUNT
2316 printk("cyc block_til_ready: (%d): decrementing count to %d\n", 2376 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2317 current->pid, info->count); 2377 current->pid, info->count);
2318#endif 2378#endif
2319 info->blocked_open++; 2379 info->blocked_open++;
2320 2380
2321 if (!IS_CYC_Z(*cinfo)) { 2381 if (!IS_CYC_Z(*cinfo)) {
2322 chip = channel>>2; 2382 chip = channel >> 2;
2323 channel &= 0x03; 2383 channel &= 0x03;
2324 index = cinfo->bus_index; 2384 index = cinfo->bus_index;
2325 base_addr = cinfo->base_addr + (cy_chip_offset[chip]<<index); 2385 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
2326 2386
2327 while (1) { 2387 while (1) {
2328 CY_LOCK(info, flags); 2388 CY_LOCK(info, flags);
2329 if ((tty->termios->c_cflag & CBAUD)){ 2389 if ((tty->termios->c_cflag & CBAUD)) {
2330 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2390 cy_writeb(base_addr + (CyCAR << index),
2331 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 2391 (u_char) channel);
2332 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 2392 cy_writeb(base_addr + (CyMSVR1 << index),
2393 CyRTS);
2394 cy_writeb(base_addr + (CyMSVR2 << index),
2395 CyDTR);
2333#ifdef CY_DEBUG_DTR 2396#ifdef CY_DEBUG_DTR
2334 printk("cyc:block_til_ready raising DTR\n"); 2397 printk("cyc:block_til_ready raising DTR\n");
2335 printk(" status: 0x%x, 0x%x\n", 2398 printk(" status: 0x%x, 0x%x\n",
2336 cy_readb(base_addr+(CyMSVR1<<index)), 2399 cy_readb(base_addr +
2337 cy_readb(base_addr+(CyMSVR2<<index))); 2400 (CyMSVR1 << index)),
2401 cy_readb(base_addr +
2402 (CyMSVR2 << index)));
2338#endif 2403#endif
2339 } 2404 }
2340 CY_UNLOCK(info, flags); 2405 CY_UNLOCK(info, flags);
2341 2406
2342 set_current_state(TASK_INTERRUPTIBLE); 2407 set_current_state(TASK_INTERRUPTIBLE);
2343 if (tty_hung_up_p(filp) 2408 if (tty_hung_up_p(filp) ||
2344 || !(info->flags & ASYNC_INITIALIZED) ){ 2409 !(info->flags & ASYNC_INITIALIZED)) {
2345 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2410 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2346 -EAGAIN : -ERESTARTSYS); 2411 -EAGAIN : -ERESTARTSYS);
2347 break; 2412 break;
2348 } 2413 }
2349 2414
2350 CY_LOCK(info, flags); 2415 CY_LOCK(info, flags);
2351 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 2416 cy_writeb(base_addr + (CyCAR << index),
2352 if (!(info->flags & ASYNC_CLOSING) 2417 (u_char) channel);
2353 && (C_CLOCAL(tty) 2418 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2354 || (cy_readb(base_addr+(CyMSVR1<<index)) & CyDCD))) { 2419 (cy_readb(base_addr +
2420 (CyMSVR1 << index)) & CyDCD))) {
2421 CY_UNLOCK(info, flags);
2422 break;
2423 }
2355 CY_UNLOCK(info, flags); 2424 CY_UNLOCK(info, flags);
2356 break;
2357 }
2358 CY_UNLOCK(info, flags);
2359 2425
2360 if (signal_pending(current)) { 2426 if (signal_pending(current)) {
2361 retval = -ERESTARTSYS; 2427 retval = -ERESTARTSYS;
2362 break; 2428 break;
2363 } 2429 }
2364#ifdef CY_DEBUG_OPEN 2430#ifdef CY_DEBUG_OPEN
2365 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2431 printk("cyc block_til_ready blocking: ttyC%d, "
2366 info->line, info->count);/**/ 2432 "count = %d\n",
2433 info->line, info->count);
2434 /**/
2367#endif 2435#endif
2368 schedule(); 2436 schedule();
2369 } 2437 }
2370 } else { 2438 } else {
2371 struct FIRM_ID __iomem *firm_id; 2439 struct FIRM_ID __iomem *firm_id;
2372 struct ZFW_CTRL __iomem *zfw_ctrl; 2440 struct ZFW_CTRL __iomem *zfw_ctrl;
2373 struct BOARD_CTRL __iomem *board_ctrl; 2441 struct BOARD_CTRL __iomem *board_ctrl;
2374 struct CH_CTRL __iomem *ch_ctrl; 2442 struct CH_CTRL __iomem *ch_ctrl;
2375 int retval; 2443 int retval;
2376 2444
2377 base_addr = cinfo->base_addr; 2445 base_addr = cinfo->base_addr;
2378 firm_id = base_addr + ID_ADDRESS; 2446 firm_id = base_addr + ID_ADDRESS;
2379 if (!ISZLOADED(*cinfo)){ 2447 if (!ISZLOADED(*cinfo)) {
2380 current->state = TASK_RUNNING; 2448 current->state = TASK_RUNNING;
2381 remove_wait_queue(&info->open_wait, &wait); 2449 remove_wait_queue(&info->open_wait, &wait);
2382 return -EINVAL; 2450 return -EINVAL;
2383 }
2384
2385 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2386 board_ctrl = &zfw_ctrl->board_ctrl;
2387 ch_ctrl = zfw_ctrl->ch_ctrl;
2388
2389 while (1) {
2390 if ((tty->termios->c_cflag & CBAUD)){
2391 cy_writel(&ch_ctrl[channel].rs_control,
2392 cy_readl(&ch_ctrl[channel].rs_control) |
2393 (C_RS_RTS | C_RS_DTR));
2394 retval = cyz_issue_cmd(&cy_card[info->card],
2395 channel, C_CM_IOCTLM, 0L);
2396 if (retval != 0){
2397 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2398 info->line, retval);
2399 } 2451 }
2452
2453 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
2454 0xfffff);
2455 board_ctrl = &zfw_ctrl->board_ctrl;
2456 ch_ctrl = zfw_ctrl->ch_ctrl;
2457
2458 while (1) {
2459 if ((tty->termios->c_cflag & CBAUD)) {
2460 cy_writel(&ch_ctrl[channel].rs_control,
2461 cy_readl(&ch_ctrl[channel].
2462 rs_control) | (C_RS_RTS |
2463 C_RS_DTR));
2464 retval = cyz_issue_cmd(&cy_card[info->card],
2465 channel, C_CM_IOCTLM, 0L);
2466 if (retval != 0) {
2467 printk("cyc:block_til_ready retval on "
2468 "ttyC%d was %x\n",
2469 info->line, retval);
2470 }
2400#ifdef CY_DEBUG_DTR 2471#ifdef CY_DEBUG_DTR
2401 printk("cyc:block_til_ready raising Z DTR\n"); 2472 printk("cyc:block_til_ready raising Z DTR\n");
2402#endif 2473#endif
2403 } 2474 }
2404 2475
2405 set_current_state(TASK_INTERRUPTIBLE); 2476 set_current_state(TASK_INTERRUPTIBLE);
2406 if (tty_hung_up_p(filp) 2477 if (tty_hung_up_p(filp) ||
2407 || !(info->flags & ASYNC_INITIALIZED) ){ 2478 !(info->flags & ASYNC_INITIALIZED)) {
2408 retval = ((info->flags & ASYNC_HUP_NOTIFY) ? 2479 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2409 -EAGAIN : -ERESTARTSYS); 2480 -EAGAIN : -ERESTARTSYS);
2410 break; 2481 break;
2411 } 2482 }
2412 if (!(info->flags & ASYNC_CLOSING) 2483 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2413 && (C_CLOCAL(tty) 2484 (cy_readl(&ch_ctrl[channel].rs_status) &
2414 || (cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD))) { 2485 C_RS_DCD))) {
2415 break; 2486 break;
2416 } 2487 }
2417 if (signal_pending(current)) { 2488 if (signal_pending(current)) {
2418 retval = -ERESTARTSYS; 2489 retval = -ERESTARTSYS;
2419 break; 2490 break;
2420 } 2491 }
2421#ifdef CY_DEBUG_OPEN 2492#ifdef CY_DEBUG_OPEN
2422 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n", 2493 printk("cyc block_til_ready blocking: ttyC%d, "
2423 info->line, info->count);/**/ 2494 "count = %d\n",
2495 info->line, info->count);
2496 /**/
2424#endif 2497#endif
2425 schedule(); 2498 schedule();
2499 }
2426 } 2500 }
2427 } 2501 current->state = TASK_RUNNING;
2428 current->state = TASK_RUNNING; 2502 remove_wait_queue(&info->open_wait, &wait);
2429 remove_wait_queue(&info->open_wait, &wait); 2503 if (!tty_hung_up_p(filp)) {
2430 if (!tty_hung_up_p(filp)){ 2504 info->count++;
2431 info->count++;
2432#ifdef CY_DEBUG_COUNT 2505#ifdef CY_DEBUG_COUNT
2433 printk("cyc:block_til_ready (%d): incrementing count to %d\n", 2506 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2434 current->pid, info->count); 2507 current->pid, info->count);
2435#endif 2508#endif
2436 } 2509 }
2437 info->blocked_open--; 2510 info->blocked_open--;
2438#ifdef CY_DEBUG_OPEN 2511#ifdef CY_DEBUG_OPEN
2439 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n", 2512 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2440 info->line, info->count);/**/ 2513 info->line, info->count);
2514 /**/
2441#endif 2515#endif
2442 if (retval) 2516 if (retval)
2443 return retval; 2517 return retval;
2444 info->flags |= ASYNC_NORMAL_ACTIVE; 2518 info->flags |= ASYNC_NORMAL_ACTIVE;
2445 return 0; 2519 return 0;
2446} /* block_til_ready */ 2520} /* block_til_ready */
2447
2448 2521
2449/* 2522/*
2450 * This routine is called whenever a serial port is opened. It 2523 * This routine is called whenever a serial port is opened. It
2451 * performs the serial-specific initialization for the tty structure. 2524 * performs the serial-specific initialization for the tty structure.
2452 */ 2525 */
2453static int 2526static int cy_open(struct tty_struct *tty, struct file *filp)
2454cy_open(struct tty_struct *tty, struct file * filp)
2455{ 2527{
2456 struct cyclades_port *info; 2528 struct cyclades_port *info;
2457 int retval, line; 2529 int retval, line;
2458
2459 line = tty->index;
2460 if ((line < 0) || (NR_PORTS <= line)){
2461 return -ENODEV;
2462 }
2463 info = &cy_port[line];
2464 if (info->line < 0){
2465 return -ENODEV;
2466 }
2467
2468 /* If the card's firmware hasn't been loaded,
2469 treat it as absent from the system. This
2470 will make the user pay attention.
2471 */
2472 if (IS_CYC_Z(cy_card[info->card])) {
2473 struct cyclades_card *cinfo = &cy_card[info->card];
2474 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2475
2476 if (!ISZLOADED(*cinfo)) {
2477 if (((ZE_V1 ==cy_readl(&((struct RUNTIME_9060 __iomem *)
2478 (cinfo->ctl_addr))->mail_box_0)) &&
2479 Z_FPGA_CHECK (*cinfo)) &&
2480 (ZFIRM_HLT == cy_readl (&firm_id->signature)))
2481 {
2482 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2483 } else {
2484 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2485 }
2486 return -ENODEV;
2487 }
2488#ifdef CONFIG_CYZ_INTR
2489 else {
2490 /* In case this Z board is operating in interrupt mode, its
2491 interrupts should be enabled as soon as the first open happens
2492 to one of its ports. */
2493 if (!cinfo->intr_enabled) {
2494 struct ZFW_CTRL __iomem *zfw_ctrl;
2495 struct BOARD_CTRL __iomem *board_ctrl;
2496
2497 zfw_ctrl = cinfo->base_addr + (cy_readl (&firm_id->zfwctrl_addr) & 0xfffff);
2498 2530
2499 board_ctrl = &zfw_ctrl->board_ctrl; 2531 line = tty->index;
2532 if ((line < 0) || (NR_PORTS <= line)) {
2533 return -ENODEV;
2534 }
2535 info = &cy_port[line];
2536 if (info->line < 0) {
2537 return -ENODEV;
2538 }
2500 2539
2501 /* Enable interrupts on the PLX chip */ 2540 /* If the card's firmware hasn't been loaded,
2502 cy_writew(cinfo->ctl_addr+0x68, 2541 treat it as absent from the system. This
2503 cy_readw(cinfo->ctl_addr+0x68)|0x0900); 2542 will make the user pay attention.
2504 /* Enable interrupts on the FW */ 2543 */
2505 retval = cyz_issue_cmd(cinfo, 2544 if (IS_CYC_Z(cy_card[info->card])) {
2506 0, C_CM_IRQ_ENBL, 0L); 2545 struct cyclades_card *cinfo = &cy_card[info->card];
2507 if (retval != 0){ 2546 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2508 printk("cyc:IRQ enable retval was %x\n", retval); 2547
2548 if (!ISZLOADED(*cinfo)) {
2549 if (((ZE_V1 == cy_readl(
2550 &((struct RUNTIME_9060 __iomem *)
2551 (cinfo->ctl_addr))->mail_box_0)) &&
2552 Z_FPGA_CHECK(*cinfo)) &&
2553 (ZFIRM_HLT == cy_readl(
2554 &firm_id->signature))) {
2555 printk("cyc:Cyclades-Z Error: you need an "
2556 "external power supply for this number "
2557 "of ports.\n\rFirmware halted.\r\n");
2558 } else {
2559 printk("cyc:Cyclades-Z firmware not yet "
2560 "loaded\n");
2561 }
2562 return -ENODEV;
2509 } 2563 }
2510 cinfo->nports = (int) cy_readl (&board_ctrl->n_channel); 2564#ifdef CONFIG_CYZ_INTR
2511 cinfo->intr_enabled = 1; 2565 else {
2512 } 2566 /* In case this Z board is operating in interrupt mode, its
2567 interrupts should be enabled as soon as the first open
2568 happens to one of its ports. */
2569 if (!cinfo->intr_enabled) {
2570 struct ZFW_CTRL __iomem *zfw_ctrl;
2571 struct BOARD_CTRL __iomem *board_ctrl;
2572
2573 zfw_ctrl = cinfo->base_addr +
2574 (cy_readl(&firm_id->zfwctrl_addr) &
2575 0xfffff);
2576
2577 board_ctrl = &zfw_ctrl->board_ctrl;
2578
2579 /* Enable interrupts on the PLX chip */
2580 cy_writew(cinfo->ctl_addr + 0x68,
2581 cy_readw(cinfo->ctl_addr +
2582 0x68) | 0x0900);
2583 /* Enable interrupts on the FW */
2584 retval = cyz_issue_cmd(cinfo, 0,
2585 C_CM_IRQ_ENBL, 0L);
2586 if (retval != 0) {
2587 printk("cyc:IRQ enable retval was %x\n",
2588 retval);
2589 }
2590 cinfo->nports =
2591 (int)cy_readl(&board_ctrl->n_channel);
2592 cinfo->intr_enabled = 1;
2593 }
2594 }
2595#endif /* CONFIG_CYZ_INTR */
2596 /* Make sure this Z port really exists in hardware */
2597 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2598 return -ENODEV;
2513 } 2599 }
2514#endif /* CONFIG_CYZ_INTR */
2515 /* Make sure this Z port really exists in hardware */
2516 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2517 return -ENODEV;
2518 }
2519#ifdef CY_DEBUG_OTHER 2600#ifdef CY_DEBUG_OTHER
2520 printk("cyc:cy_open ttyC%d\n", info->line); /* */ 2601 printk("cyc:cy_open ttyC%d\n", info->line); /* */
2521#endif 2602#endif
2522 tty->driver_data = info; 2603 tty->driver_data = info;
2523 info->tty = tty; 2604 info->tty = tty;
2524 if (serial_paranoia_check(info, tty->name, "cy_open")){ 2605 if (serial_paranoia_check(info, tty->name, "cy_open")) {
2525 return -ENODEV; 2606 return -ENODEV;
2526 } 2607 }
2527#ifdef CY_DEBUG_OPEN 2608#ifdef CY_DEBUG_OPEN
2528 printk("cyc:cy_open ttyC%d, count = %d\n", 2609 printk("cyc:cy_open ttyC%d, count = %d\n", info->line, info->count);
2529 info->line, info->count);/**/ 2610 /**/
2530#endif 2611#endif
2531 info->count++; 2612 info->count++;
2532#ifdef CY_DEBUG_COUNT 2613#ifdef CY_DEBUG_COUNT
2533 printk("cyc:cy_open (%d): incrementing count to %d\n", 2614 printk("cyc:cy_open (%d): incrementing count to %d\n",
2534 current->pid, info->count); 2615 current->pid, info->count);
2535#endif 2616#endif
2536 2617
2537 /* 2618 /*
2538 * If the port is the middle of closing, bail out now 2619 * If the port is the middle of closing, bail out now
2539 */ 2620 */
2540 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) { 2621 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2541 if (info->flags & ASYNC_CLOSING) 2622 if (info->flags & ASYNC_CLOSING)
2542 interruptible_sleep_on(&info->close_wait); 2623 interruptible_sleep_on(&info->close_wait);
2543 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS); 2624 return (info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN: -ERESTARTSYS;
2544 } 2625 }
2545
2546 /*
2547 * Start up serial port
2548 */
2549 retval = startup(info);
2550 if (retval){
2551 return retval;
2552 }
2553
2554 retval = block_til_ready(tty, filp, info);
2555 if (retval) {
2556#ifdef CY_DEBUG_OPEN
2557 printk("cyc:cy_open returning after block_til_ready with %d\n",
2558 retval);
2559#endif
2560 return retval;
2561 }
2562 2626
2563 info->throttle = 0; 2627 /*
2628 * Start up serial port
2629 */
2630 retval = startup(info);
2631 if (retval) {
2632 return retval;
2633 }
2564 2634
2635 retval = block_til_ready(tty, filp, info);
2636 if (retval) {
2565#ifdef CY_DEBUG_OPEN 2637#ifdef CY_DEBUG_OPEN
2566 printk(" cyc:cy_open done\n");/**/ 2638 printk("cyc:cy_open returning after block_til_ready with %d\n",
2639 retval);
2567#endif 2640#endif
2641 return retval;
2642 }
2568 2643
2569 return 0; 2644 info->throttle = 0;
2570} /* cy_open */
2571 2645
2646#ifdef CY_DEBUG_OPEN
2647 printk(" cyc:cy_open done\n");
2648 /**/
2649#endif
2650 return 0;
2651} /* cy_open */
2572 2652
2573/* 2653/*
2574 * cy_wait_until_sent() --- wait until the transmitter is empty 2654 * cy_wait_until_sent() --- wait until the transmitter is empty
2575 */ 2655 */
2576static void 2656static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2577cy_wait_until_sent(struct tty_struct *tty, int timeout)
2578{ 2657{
2579 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 2658 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2580 void __iomem *base_addr; 2659 void __iomem *base_addr;
2581 int card,chip,channel,index; 2660 int card, chip, channel, index;
2582 unsigned long orig_jiffies; 2661 unsigned long orig_jiffies;
2583 int char_time; 2662 int char_time;
2584 2663
2585 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent")) 2664 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
2586 return; 2665 return;
2587 2666
2588 if (info->xmit_fifo_size == 0) 2667 if (info->xmit_fifo_size == 0)
2589 return; /* Just in case.... */ 2668 return; /* Just in case.... */
2590 2669
2591 2670 orig_jiffies = jiffies;
2592 orig_jiffies = jiffies; 2671 /*
2593 /* 2672 * Set the check interval to be 1/5 of the estimated time to
2594 * Set the check interval to be 1/5 of the estimated time to 2673 * send a single character, and make it at least 1. The check
2595 * send a single character, and make it at least 1. The check 2674 * interval should also be less than the timeout.
2596 * interval should also be less than the timeout. 2675 *
2597 * 2676 * Note: we have to use pretty tight timings here to satisfy
2598 * Note: we have to use pretty tight timings here to satisfy 2677 * the NIST-PCTS.
2599 * the NIST-PCTS. 2678 */
2600 */ 2679 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2601 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size; 2680 char_time = char_time / 5;
2602 char_time = char_time / 5; 2681 if (char_time <= 0)
2603 if (char_time <= 0) 2682 char_time = 1;
2604 char_time = 1; 2683 if (timeout < 0)
2605 if (timeout < 0) 2684 timeout = 0;
2606 timeout = 0; 2685 if (timeout)
2607 if (timeout) 2686 char_time = min(char_time, timeout);
2608 char_time = min(char_time, timeout); 2687 /*
2609 /* 2688 * If the transmitter hasn't cleared in twice the approximate
2610 * If the transmitter hasn't cleared in twice the approximate 2689 * amount of time to send the entire FIFO, it probably won't
2611 * amount of time to send the entire FIFO, it probably won't 2690 * ever clear. This assumes the UART isn't doing flow
2612 * ever clear. This assumes the UART isn't doing flow 2691 * control, which is currently the case. Hence, if it ever
2613 * control, which is currently the case. Hence, if it ever 2692 * takes longer than info->timeout, this is probably due to a
2614 * takes longer than info->timeout, this is probably due to a 2693 * UART bug of some kind. So, we clamp the timeout parameter at
2615 * UART bug of some kind. So, we clamp the timeout parameter at 2694 * 2*info->timeout.
2616 * 2*info->timeout. 2695 */
2617 */ 2696 if (!timeout || timeout > 2 * info->timeout)
2618 if (!timeout || timeout > 2*info->timeout) 2697 timeout = 2 * info->timeout;
2619 timeout = 2*info->timeout;
2620#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2698#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2621 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time); 2699 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
2622 printk("jiff=%lu...", jiffies); 2700 printk("jiff=%lu...", jiffies);
2623#endif 2701#endif
2624 card = info->card; 2702 card = info->card;
2625 channel = (info->line) - (cy_card[card].first_line); 2703 channel = (info->line) - (cy_card[card].first_line);
2626 if (!IS_CYC_Z(cy_card[card])) { 2704 if (!IS_CYC_Z(cy_card[card])) {
2627 chip = channel>>2; 2705 chip = channel >> 2;
2628 channel &= 0x03; 2706 channel &= 0x03;
2629 index = cy_card[card].bus_index; 2707 index = cy_card[card].bus_index;
2630 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 2708 base_addr =
2631 while (cy_readb(base_addr+(CySRER<<index)) & CyTxRdy) { 2709 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
2710 while (cy_readb(base_addr + (CySRER << index)) & CyTxRdy) {
2632#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2711#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2633 printk("Not clean (jiff=%lu)...", jiffies); 2712 printk("Not clean (jiff=%lu)...", jiffies);
2634#endif 2713#endif
2635 if (msleep_interruptible(jiffies_to_msecs(char_time))) 2714 if (msleep_interruptible(jiffies_to_msecs(char_time)))
2636 break; 2715 break;
2637 if (timeout && time_after(jiffies, orig_jiffies + timeout)) 2716 if (timeout && time_after(jiffies, orig_jiffies +
2638 break; 2717 timeout))
2718 break;
2719 }
2720 } else {
2721 /* Nothing to do! */
2639 } 2722 }
2640 } else { 2723 /* Run one more char cycle */
2641 // Nothing to do! 2724 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2642 }
2643 /* Run one more char cycle */
2644 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2645#ifdef CY_DEBUG_WAIT_UNTIL_SENT 2725#ifdef CY_DEBUG_WAIT_UNTIL_SENT
2646 printk("Clean (jiff=%lu)...done\n", jiffies); 2726 printk("Clean (jiff=%lu)...done\n", jiffies);
2647#endif 2727#endif
2648} 2728}
2649 2729
2650/* 2730/*
2651 * This routine is called when a particular tty device is closed. 2731 * This routine is called when a particular tty device is closed.
2652 */ 2732 */
2653static void 2733static void cy_close(struct tty_struct *tty, struct file *filp)
2654cy_close(struct tty_struct *tty, struct file *filp)
2655{ 2734{
2656 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2735 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2657 unsigned long flags; 2736 unsigned long flags;
2658 2737
2659#ifdef CY_DEBUG_OTHER 2738#ifdef CY_DEBUG_OTHER
2660 printk("cyc:cy_close ttyC%d\n", info->line); 2739 printk("cyc:cy_close ttyC%d\n", info->line);
2661#endif 2740#endif
2662 2741
2663 if (!info || serial_paranoia_check(info, tty->name, "cy_close")){ 2742 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
2664 return; 2743 return;
2665 } 2744 }
2666 2745
2667 CY_LOCK(info, flags); 2746 CY_LOCK(info, flags);
2668 /* If the TTY is being hung up, nothing to do */ 2747 /* If the TTY is being hung up, nothing to do */
2669 if (tty_hung_up_p(filp)) { 2748 if (tty_hung_up_p(filp)) {
2670 CY_UNLOCK(info, flags); 2749 CY_UNLOCK(info, flags);
2671 return; 2750 return;
2672 } 2751 }
2673
2674#ifdef CY_DEBUG_OPEN 2752#ifdef CY_DEBUG_OPEN
2675 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count); 2753 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
2676#endif 2754#endif
2677 if ((tty->count == 1) && (info->count != 1)) { 2755 if ((tty->count == 1) && (info->count != 1)) {
2678 /* 2756 /*
2679 * Uh, oh. tty->count is 1, which means that the tty 2757 * Uh, oh. tty->count is 1, which means that the tty
2680 * structure will be freed. Info->count should always 2758 * structure will be freed. Info->count should always
2681 * be one in these conditions. If it's greater than 2759 * be one in these conditions. If it's greater than
2682 * one, we've got real problems, since it means the 2760 * one, we've got real problems, since it means the
2683 * serial port won't be shutdown. 2761 * serial port won't be shutdown.
2684 */ 2762 */
2685 printk("cyc:cy_close: bad serial port count; tty->count is 1, " 2763 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2686 "info->count is %d\n", info->count); 2764 "info->count is %d\n", info->count);
2687 info->count = 1; 2765 info->count = 1;
2688 } 2766 }
2689#ifdef CY_DEBUG_COUNT 2767#ifdef CY_DEBUG_COUNT
2690 printk("cyc:cy_close at (%d): decrementing count to %d\n", 2768 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2691 current->pid, info->count - 1); 2769 current->pid, info->count - 1);
2692#endif 2770#endif
2693 if (--info->count < 0) { 2771 if (--info->count < 0) {
2694#ifdef CY_DEBUG_COUNT 2772#ifdef CY_DEBUG_COUNT
2695 printk("cyc:cyc_close setting count to 0\n"); 2773 printk("cyc:cyc_close setting count to 0\n");
2696#endif 2774#endif
2697 info->count = 0; 2775 info->count = 0;
2698 }
2699 if (info->count) {
2700 CY_UNLOCK(info, flags);
2701 return;
2702 }
2703 info->flags |= ASYNC_CLOSING;
2704
2705 /*
2706 * Now we wait for the transmit buffer to clear; and we notify
2707 * the line discipline to only process XON/XOFF characters.
2708 */
2709 tty->closing = 1;
2710 CY_UNLOCK(info, flags);
2711 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2712 tty_wait_until_sent(tty, info->closing_wait);
2713 }
2714 CY_LOCK(info, flags);
2715
2716 if (!IS_CYC_Z(cy_card[info->card])) {
2717 int channel = info->line - cy_card[info->card].first_line;
2718 int index = cy_card[info->card].bus_index;
2719 void __iomem *base_addr = cy_card[info->card].base_addr + (cy_chip_offset[channel>>2] << index);
2720 /* Stop accepting input */
2721 channel &= 0x03;
2722 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
2723 cy_writeb(base_addr+(CySRER<<index),
2724 cy_readb(base_addr+(CySRER<<index)) & ~CyRxData);
2725 if (info->flags & ASYNC_INITIALIZED) {
2726 /* Waiting for on-board buffers to be empty before closing
2727 the port */
2728 CY_UNLOCK(info, flags);
2729 cy_wait_until_sent(tty, info->timeout);
2730 CY_LOCK(info, flags);
2731 } 2776 }
2732 } else { 2777 if (info->count) {
2733#ifdef Z_WAKE 2778 CY_UNLOCK(info, flags);
2734 /* Waiting for on-board buffers to be empty before closing the port */ 2779 return;
2735 void __iomem *base_addr = cy_card[info->card].base_addr; 2780 }
2736 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS; 2781 info->flags |= ASYNC_CLOSING;
2737 struct ZFW_CTRL __iomem *zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2738 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2739 int channel = info->line - cy_card[info->card].first_line;
2740 int retval;
2741 2782
2742 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) { 2783 /*
2743 retval = cyz_issue_cmd(&cy_card[info->card], channel, 2784 * Now we wait for the transmit buffer to clear; and we notify
2744 C_CM_IOCTLW, 0L); 2785 * the line discipline to only process XON/XOFF characters.
2745 if (retval != 0){ 2786 */
2746 printk("cyc:cy_close retval on ttyC%d was %x\n", 2787 tty->closing = 1;
2747 info->line, retval); 2788 CY_UNLOCK(info, flags);
2748 } 2789 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2749 CY_UNLOCK(info, flags); 2790 tty_wait_until_sent(tty, info->closing_wait);
2750 interruptible_sleep_on(&info->shutdown_wait);
2751 CY_LOCK(info, flags);
2752 } 2791 }
2792 CY_LOCK(info, flags);
2793
2794 if (!IS_CYC_Z(cy_card[info->card])) {
2795 int channel = info->line - cy_card[info->card].first_line;
2796 int index = cy_card[info->card].bus_index;
2797 void __iomem *base_addr = cy_card[info->card].base_addr +
2798 (cy_chip_offset[channel >> 2] << index);
2799 /* Stop accepting input */
2800 channel &= 0x03;
2801 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2802 cy_writeb(base_addr + (CySRER << index),
2803 cy_readb(base_addr + (CySRER << index)) & ~CyRxData);
2804 if (info->flags & ASYNC_INITIALIZED) {
2805 /* Waiting for on-board buffers to be empty before closing
2806 the port */
2807 CY_UNLOCK(info, flags);
2808 cy_wait_until_sent(tty, info->timeout);
2809 CY_LOCK(info, flags);
2810 }
2811 } else {
2812#ifdef Z_WAKE
2813 /* Waiting for on-board buffers to be empty before closing the port */
2814 void __iomem *base_addr = cy_card[info->card].base_addr;
2815 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2816 struct ZFW_CTRL __iomem *zfw_ctrl =
2817 base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2818 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2819 int channel = info->line - cy_card[info->card].first_line;
2820 int retval;
2821
2822 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2823 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2824 C_CM_IOCTLW, 0L);
2825 if (retval != 0) {
2826 printk("cyc:cy_close retval on ttyC%d was %x\n",
2827 info->line, retval);
2828 }
2829 CY_UNLOCK(info, flags);
2830 interruptible_sleep_on(&info->shutdown_wait);
2831 CY_LOCK(info, flags);
2832 }
2753#endif 2833#endif
2754 } 2834 }
2755 2835
2756 CY_UNLOCK(info, flags);
2757 shutdown(info);
2758 if (tty->driver->flush_buffer)
2759 tty->driver->flush_buffer(tty);
2760 tty_ldisc_flush(tty);
2761 CY_LOCK(info, flags);
2762
2763 tty->closing = 0;
2764 info->event = 0;
2765 info->tty = NULL;
2766 if (info->blocked_open) {
2767 CY_UNLOCK(info, flags); 2836 CY_UNLOCK(info, flags);
2768 if (info->close_delay) { 2837 shutdown(info);
2769 msleep_interruptible(jiffies_to_msecs(info->close_delay)); 2838 if (tty->driver->flush_buffer)
2770 } 2839 tty->driver->flush_buffer(tty);
2771 wake_up_interruptible(&info->open_wait); 2840 tty_ldisc_flush(tty);
2772 CY_LOCK(info, flags); 2841 CY_LOCK(info, flags);
2773 } 2842
2774 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 2843 tty->closing = 0;
2775 wake_up_interruptible(&info->close_wait); 2844 info->event = 0;
2845 info->tty = NULL;
2846 if (info->blocked_open) {
2847 CY_UNLOCK(info, flags);
2848 if (info->close_delay) {
2849 msleep_interruptible(jiffies_to_msecs
2850 (info->close_delay));
2851 }
2852 wake_up_interruptible(&info->open_wait);
2853 CY_LOCK(info, flags);
2854 }
2855 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
2856 wake_up_interruptible(&info->close_wait);
2776 2857
2777#ifdef CY_DEBUG_OTHER 2858#ifdef CY_DEBUG_OTHER
2778 printk(" cyc:cy_close done\n"); 2859 printk(" cyc:cy_close done\n");
2779#endif 2860#endif
2780 2861
2781 CY_UNLOCK(info, flags); 2862 CY_UNLOCK(info, flags);
2782 return; 2863} /* cy_close */
2783} /* cy_close */
2784
2785 2864
2786/* This routine gets called when tty_write has put something into 2865/* This routine gets called when tty_write has put something into
2787 * the write_queue. The characters may come from user space or 2866 * the write_queue. The characters may come from user space or
@@ -2796,50 +2875,49 @@ cy_close(struct tty_struct *tty, struct file *filp)
2796 * If the port is already active, there is no need to kick it. 2875 * If the port is already active, there is no need to kick it.
2797 * 2876 *
2798 */ 2877 */
2799static int 2878static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2800cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2801{ 2879{
2802 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2880 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2803 unsigned long flags; 2881 unsigned long flags;
2804 int c, ret = 0; 2882 int c, ret = 0;
2805 2883
2806#ifdef CY_DEBUG_IO 2884#ifdef CY_DEBUG_IO
2807 printk("cyc:cy_write ttyC%d\n", info->line); /* */ 2885 printk("cyc:cy_write ttyC%d\n", info->line); /* */
2808#endif 2886#endif
2809 2887
2810 if (serial_paranoia_check(info, tty->name, "cy_write")){ 2888 if (serial_paranoia_check(info, tty->name, "cy_write")) {
2811 return 0; 2889 return 0;
2812 } 2890 }
2813
2814 if (!info->xmit_buf)
2815 return 0;
2816 2891
2817 CY_LOCK(info, flags); 2892 if (!info->xmit_buf)
2818 while (1) { 2893 return 0;
2819 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2820 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2821
2822 if (c <= 0)
2823 break;
2824
2825 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2826 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
2827 info->xmit_cnt += c;
2828 buf += c;
2829 count -= c;
2830 ret += c;
2831 }
2832 CY_UNLOCK(info, flags);
2833
2834 info->idle_stats.xmit_bytes += ret;
2835 info->idle_stats.xmit_idle = jiffies;
2836
2837 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2838 start_xmit(info);
2839 }
2840 return ret;
2841} /* cy_write */
2842 2894
2895 CY_LOCK(info, flags);
2896 while (1) {
2897 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2898 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2899
2900 if (c <= 0)
2901 break;
2902
2903 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2904 info->xmit_head = (info->xmit_head + c) &
2905 (SERIAL_XMIT_SIZE - 1);
2906 info->xmit_cnt += c;
2907 buf += c;
2908 count -= c;
2909 ret += c;
2910 }
2911 CY_UNLOCK(info, flags);
2912
2913 info->idle_stats.xmit_bytes += ret;
2914 info->idle_stats.xmit_idle = jiffies;
2915
2916 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2917 start_xmit(info);
2918 }
2919 return ret;
2920} /* cy_write */
2843 2921
2844/* 2922/*
2845 * This routine is called by the kernel to write a single 2923 * This routine is called by the kernel to write a single
@@ -2848,60 +2926,56 @@ cy_write(struct tty_struct * tty, const unsigned char *buf, int count)
2848 * done stuffing characters into the driver. If there is no room 2926 * done stuffing characters into the driver. If there is no room
2849 * in the queue, the character is ignored. 2927 * in the queue, the character is ignored.
2850 */ 2928 */
2851static void 2929static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2852cy_put_char(struct tty_struct *tty, unsigned char ch)
2853{ 2930{
2854 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2931 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2855 unsigned long flags; 2932 unsigned long flags;
2856 2933
2857#ifdef CY_DEBUG_IO 2934#ifdef CY_DEBUG_IO
2858 printk("cyc:cy_put_char ttyC%d\n", info->line); 2935 printk("cyc:cy_put_char ttyC%d\n", info->line);
2859#endif 2936#endif
2860 2937
2861 if (serial_paranoia_check(info, tty->name, "cy_put_char")) 2938 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
2862 return; 2939 return;
2863 2940
2864 if (!info->xmit_buf) 2941 if (!info->xmit_buf)
2865 return; 2942 return;
2866 2943
2867 CY_LOCK(info, flags); 2944 CY_LOCK(info, flags);
2868 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) { 2945 if (info->xmit_cnt >= (int)(SERIAL_XMIT_SIZE - 1)) {
2869 CY_UNLOCK(info, flags); 2946 CY_UNLOCK(info, flags);
2870 return; 2947 return;
2871 } 2948 }
2872 2949
2873 info->xmit_buf[info->xmit_head++] = ch; 2950 info->xmit_buf[info->xmit_head++] = ch;
2874 info->xmit_head &= SERIAL_XMIT_SIZE - 1; 2951 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
2875 info->xmit_cnt++; 2952 info->xmit_cnt++;
2876 info->idle_stats.xmit_bytes++; 2953 info->idle_stats.xmit_bytes++;
2877 info->idle_stats.xmit_idle = jiffies; 2954 info->idle_stats.xmit_idle = jiffies;
2878 CY_UNLOCK(info, flags); 2955 CY_UNLOCK(info, flags);
2879} /* cy_put_char */ 2956} /* cy_put_char */
2880
2881 2957
2882/* 2958/*
2883 * This routine is called by the kernel after it has written a 2959 * This routine is called by the kernel after it has written a
2884 * series of characters to the tty device using put_char(). 2960 * series of characters to the tty device using put_char().
2885 */ 2961 */
2886static void 2962static void cy_flush_chars(struct tty_struct *tty)
2887cy_flush_chars(struct tty_struct *tty)
2888{ 2963{
2889 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2964 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2890 2965
2891#ifdef CY_DEBUG_IO 2966#ifdef CY_DEBUG_IO
2892 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */ 2967 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
2893#endif 2968#endif
2894 2969
2895 if (serial_paranoia_check(info, tty->name, "cy_flush_chars")) 2970 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
2896 return; 2971 return;
2897
2898 if (info->xmit_cnt <= 0 || tty->stopped
2899 || tty->hw_stopped || !info->xmit_buf)
2900 return;
2901 2972
2902 start_xmit(info); 2973 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
2903} /* cy_flush_chars */ 2974 !info->xmit_buf)
2975 return;
2904 2976
2977 start_xmit(info);
2978} /* cy_flush_chars */
2905 2979
2906/* 2980/*
2907 * This routine returns the numbers of characters the tty driver 2981 * This routine returns the numbers of characters the tty driver
@@ -2909,75 +2983,70 @@ cy_flush_chars(struct tty_struct *tty)
2909 * to change as output buffers get emptied, or if the output flow 2983 * to change as output buffers get emptied, or if the output flow
2910 * control is activated. 2984 * control is activated.
2911 */ 2985 */
2912static int 2986static int cy_write_room(struct tty_struct *tty)
2913cy_write_room(struct tty_struct *tty)
2914{ 2987{
2915 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 2988 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2916 int ret; 2989 int ret;
2917 2990
2918#ifdef CY_DEBUG_IO 2991#ifdef CY_DEBUG_IO
2919 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */ 2992 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
2920#endif 2993#endif
2921 2994
2922 if (serial_paranoia_check(info, tty->name, "cy_write_room")) 2995 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
2923 return 0; 2996 return 0;
2924 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1; 2997 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
2925 if (ret < 0) 2998 if (ret < 0)
2926 ret = 0; 2999 ret = 0;
2927 return ret; 3000 return ret;
2928} /* cy_write_room */ 3001} /* cy_write_room */
2929
2930 3002
2931static int 3003static int cy_chars_in_buffer(struct tty_struct *tty)
2932cy_chars_in_buffer(struct tty_struct *tty)
2933{ 3004{
2934 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 3005 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2935 int card, channel; 3006 int card, channel;
2936 3007
2937 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer")) 3008 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
2938 return 0; 3009 return 0;
2939 3010
2940 card = info->card; 3011 card = info->card;
2941 channel = (info->line) - (cy_card[card].first_line); 3012 channel = (info->line) - (cy_card[card].first_line);
2942 3013
2943#ifdef Z_EXT_CHARS_IN_BUFFER 3014#ifdef Z_EXT_CHARS_IN_BUFFER
2944 if (!IS_CYC_Z(cy_card[card])) { 3015 if (!IS_CYC_Z(cy_card[card])) {
2945#endif /* Z_EXT_CHARS_IN_BUFFER */ 3016#endif /* Z_EXT_CHARS_IN_BUFFER */
2946#ifdef CY_DEBUG_IO 3017#ifdef CY_DEBUG_IO
2947 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3018 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt); /* */
2948 info->line, info->xmit_cnt); /* */
2949#endif 3019#endif
2950 return info->xmit_cnt; 3020 return info->xmit_cnt;
2951#ifdef Z_EXT_CHARS_IN_BUFFER 3021#ifdef Z_EXT_CHARS_IN_BUFFER
2952 } else { 3022 } else {
2953 static volatile struct FIRM_ID *firm_id; 3023 static volatile struct FIRM_ID *firm_id;
2954 static volatile struct ZFW_CTRL *zfw_ctrl; 3024 static volatile struct ZFW_CTRL *zfw_ctrl;
2955 static volatile struct CH_CTRL *ch_ctrl; 3025 static volatile struct CH_CTRL *ch_ctrl;
2956 static volatile struct BUF_CTRL *buf_ctrl; 3026 static volatile struct BUF_CTRL *buf_ctrl;
2957 int char_count; 3027 int char_count;
2958 volatile uclong tx_put, tx_get, tx_bufsize; 3028 volatile uclong tx_put, tx_get, tx_bufsize;
2959 3029
2960 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3030 firm_id = cy_card[card].base_addr + ID_ADDRESS;
2961 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3031 zfw_ctrl = cy_card[card].base_addr +
2962 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]); 3032 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2963 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]); 3033 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
2964 3034 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
2965 tx_get = cy_readl(&buf_ctrl->tx_get); 3035
2966 tx_put = cy_readl(&buf_ctrl->tx_put); 3036 tx_get = cy_readl(&buf_ctrl->tx_get);
2967 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize); 3037 tx_put = cy_readl(&buf_ctrl->tx_put);
2968 if (tx_put >= tx_get) 3038 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
2969 char_count = tx_put - tx_get; 3039 if (tx_put >= tx_get)
2970 else 3040 char_count = tx_put - tx_get;
2971 char_count = tx_put - tx_get + tx_bufsize; 3041 else
3042 char_count = tx_put - tx_get + tx_bufsize;
2972#ifdef CY_DEBUG_IO 3043#ifdef CY_DEBUG_IO
2973 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", 3044 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt + char_count); /* */
2974 info->line, info->xmit_cnt + char_count); /* */
2975#endif 3045#endif
2976 return (info->xmit_cnt + char_count); 3046 return info->xmit_cnt + char_count;
2977 } 3047 }
2978#endif /* Z_EXT_CHARS_IN_BUFFER */ 3048#endif /* Z_EXT_CHARS_IN_BUFFER */
2979} /* cy_chars_in_buffer */ 3049} /* cy_chars_in_buffer */
2980
2981 3050
2982/* 3051/*
2983 * ------------------------------------------------------------ 3052 * ------------------------------------------------------------
@@ -2985,178 +3054,179 @@ cy_chars_in_buffer(struct tty_struct *tty)
2985 * ------------------------------------------------------------ 3054 * ------------------------------------------------------------
2986 */ 3055 */
2987 3056
2988static void 3057static void cyy_baud_calc(struct cyclades_port *info, uclong baud)
2989cyy_baud_calc(struct cyclades_port *info, uclong baud)
2990{ 3058{
2991 int co, co_val, bpr; 3059 int co, co_val, bpr;
2992 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 : 25000000); 3060 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
2993 3061 25000000);
2994 if (baud == 0) { 3062
2995 info->tbpr = info->tco = info->rbpr = info->rco = 0; 3063 if (baud == 0) {
2996 return; 3064 info->tbpr = info->tco = info->rbpr = info->rco = 0;
2997 } 3065 return;
2998 3066 }
2999 /* determine which prescaler to use */ 3067
3000 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) { 3068 /* determine which prescaler to use */
3001 if (cy_clock / co_val / baud > 63) 3069 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
3002 break; 3070 if (cy_clock / co_val / baud > 63)
3003 } 3071 break;
3004 3072 }
3005 bpr = (cy_clock / co_val * 2 / baud + 1) / 2; 3073
3006 if (bpr > 255) 3074 bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
3007 bpr = 255; 3075 if (bpr > 255)
3008 3076 bpr = 255;
3009 info->tbpr = info->rbpr = bpr; 3077
3010 info->tco = info->rco = co; 3078 info->tbpr = info->rbpr = bpr;
3079 info->tco = info->rco = co;
3011} 3080}
3012 3081
3013/* 3082/*
3014 * This routine finds or computes the various line characteristics. 3083 * This routine finds or computes the various line characteristics.
3015 * It used to be called config_setup 3084 * It used to be called config_setup
3016 */ 3085 */
3017static void 3086static void set_line_char(struct cyclades_port *info)
3018set_line_char(struct cyclades_port * info)
3019{ 3087{
3020 unsigned long flags; 3088 unsigned long flags;
3021 void __iomem *base_addr; 3089 void __iomem *base_addr;
3022 int card,chip,channel,index; 3090 int card, chip, channel, index;
3023 unsigned cflag, iflag; 3091 unsigned cflag, iflag;
3024 unsigned short chip_number; 3092 unsigned short chip_number;
3025 int baud, baud_rate = 0; 3093 int baud, baud_rate = 0;
3026 int i; 3094 int i;
3027 3095
3028 3096 if (!info->tty || !info->tty->termios) {
3029 if (!info->tty || !info->tty->termios){ 3097 return;
3030 return;
3031 }
3032 if (info->line == -1){
3033 return;
3034 }
3035 cflag = info->tty->termios->c_cflag;
3036 iflag = info->tty->termios->c_iflag;
3037
3038 /*
3039 * Set up the tty->alt_speed kludge
3040 */
3041 if (info->tty) {
3042 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3043 info->tty->alt_speed = 57600;
3044 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3045 info->tty->alt_speed = 115200;
3046 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3047 info->tty->alt_speed = 230400;
3048 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3049 info->tty->alt_speed = 460800;
3050 }
3051
3052 card = info->card;
3053 channel = (info->line) - (cy_card[card].first_line);
3054 chip_number = channel / 4;
3055
3056 if (!IS_CYC_Z(cy_card[card])) {
3057
3058 index = cy_card[card].bus_index;
3059
3060 /* baud rate */
3061 baud = tty_get_baud_rate(info->tty);
3062 if ((baud == 38400) &&
3063 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3064 if (info->custom_divisor)
3065 baud_rate = info->baud / info->custom_divisor;
3066 else
3067 baud_rate = info->baud;
3068 } else if (baud > CD1400_MAX_SPEED) {
3069 baud = CD1400_MAX_SPEED;
3070 } 3098 }
3071 /* find the baud index */ 3099 if (info->line == -1) {
3072 for (i = 0; i < 20; i++) { 3100 return;
3073 if (baud == baud_table[i]) {
3074 break;
3075 }
3076 } 3101 }
3077 if (i == 20) { 3102 cflag = info->tty->termios->c_cflag;
3078 i = 19; /* CD1400_MAX_SPEED */ 3103 iflag = info->tty->termios->c_iflag;
3079 }
3080 3104
3081 if ((baud == 38400) && 3105 /*
3082 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) { 3106 * Set up the tty->alt_speed kludge
3083 cyy_baud_calc(info, baud_rate); 3107 */
3084 } else { 3108 if (info->tty) {
3085 if(info->chip_rev >= CD1400_REV_J) { 3109 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3086 /* It is a CD1400 rev. J or later */ 3110 info->tty->alt_speed = 57600;
3087 info->tbpr = baud_bpr_60[i]; /* Tx BPR */ 3111 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3088 info->tco = baud_co_60[i]; /* Tx CO */ 3112 info->tty->alt_speed = 115200;
3089 info->rbpr = baud_bpr_60[i]; /* Rx BPR */ 3113 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3090 info->rco = baud_co_60[i]; /* Rx CO */ 3114 info->tty->alt_speed = 230400;
3091 } else { 3115 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3092 info->tbpr = baud_bpr_25[i]; /* Tx BPR */ 3116 info->tty->alt_speed = 460800;
3093 info->tco = baud_co_25[i]; /* Tx CO */
3094 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3095 info->rco = baud_co_25[i]; /* Rx CO */
3096 }
3097 }
3098 if (baud_table[i] == 134) {
3099 /* get it right for 134.5 baud */
3100 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3101 } else if ((baud == 38400) &&
3102 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3103 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3104 } else if (baud_table[i]) {
3105 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
3106 /* this needs to be propagated into the card info */
3107 } else {
3108 info->timeout = 0;
3109 }
3110 /* By tradition (is it a standard?) a baud rate of zero
3111 implies the line should be/has been closed. A bit
3112 later in this routine such a test is performed. */
3113
3114 /* byte size and parity */
3115 info->cor5 = 0;
3116 info->cor4 = 0;
3117 info->cor3 = (info->default_threshold
3118 ? info->default_threshold
3119 : baud_cor3[i]); /* receive threshold */
3120 info->cor2 = CyETC;
3121 switch(cflag & CSIZE){
3122 case CS5:
3123 info->cor1 = Cy_5_BITS;
3124 break;
3125 case CS6:
3126 info->cor1 = Cy_6_BITS;
3127 break;
3128 case CS7:
3129 info->cor1 = Cy_7_BITS;
3130 break;
3131 case CS8:
3132 info->cor1 = Cy_8_BITS;
3133 break;
3134 }
3135 if(cflag & CSTOPB){
3136 info->cor1 |= Cy_2_STOP;
3137 }
3138 if (cflag & PARENB){
3139 if (cflag & PARODD){
3140 info->cor1 |= CyPARITY_O;
3141 }else{
3142 info->cor1 |= CyPARITY_E;
3143 }
3144 }else{
3145 info->cor1 |= CyPARITY_NONE;
3146 }
3147
3148 /* CTS flow control flag */
3149 if (cflag & CRTSCTS){
3150 info->flags |= ASYNC_CTS_FLOW;
3151 info->cor2 |= CyCtsAE;
3152 }else{
3153 info->flags &= ~ASYNC_CTS_FLOW;
3154 info->cor2 &= ~CyCtsAE;
3155 } 3117 }
3156 if (cflag & CLOCAL) 3118
3157 info->flags &= ~ASYNC_CHECK_CD; 3119 card = info->card;
3158 else 3120 channel = (info->line) - (cy_card[card].first_line);
3159 info->flags |= ASYNC_CHECK_CD; 3121 chip_number = channel / 4;
3122
3123 if (!IS_CYC_Z(cy_card[card])) {
3124
3125 index = cy_card[card].bus_index;
3126
3127 /* baud rate */
3128 baud = tty_get_baud_rate(info->tty);
3129 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3130 ASYNC_SPD_CUST) {
3131 if (info->custom_divisor)
3132 baud_rate = info->baud / info->custom_divisor;
3133 else
3134 baud_rate = info->baud;
3135 } else if (baud > CD1400_MAX_SPEED) {
3136 baud = CD1400_MAX_SPEED;
3137 }
3138 /* find the baud index */
3139 for (i = 0; i < 20; i++) {
3140 if (baud == baud_table[i]) {
3141 break;
3142 }
3143 }
3144 if (i == 20) {
3145 i = 19; /* CD1400_MAX_SPEED */
3146 }
3147
3148 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3149 ASYNC_SPD_CUST) {
3150 cyy_baud_calc(info, baud_rate);
3151 } else {
3152 if (info->chip_rev >= CD1400_REV_J) {
3153 /* It is a CD1400 rev. J or later */
3154 info->tbpr = baud_bpr_60[i]; /* Tx BPR */
3155 info->tco = baud_co_60[i]; /* Tx CO */
3156 info->rbpr = baud_bpr_60[i]; /* Rx BPR */
3157 info->rco = baud_co_60[i]; /* Rx CO */
3158 } else {
3159 info->tbpr = baud_bpr_25[i]; /* Tx BPR */
3160 info->tco = baud_co_25[i]; /* Tx CO */
3161 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3162 info->rco = baud_co_25[i]; /* Rx CO */
3163 }
3164 }
3165 if (baud_table[i] == 134) {
3166 /* get it right for 134.5 baud */
3167 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3168 2;
3169 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3170 ASYNC_SPD_CUST) {
3171 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3172 baud_rate) + 2;
3173 } else if (baud_table[i]) {
3174 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3175 baud_table[i]) + 2;
3176 /* this needs to be propagated into the card info */
3177 } else {
3178 info->timeout = 0;
3179 }
3180 /* By tradition (is it a standard?) a baud rate of zero
3181 implies the line should be/has been closed. A bit
3182 later in this routine such a test is performed. */
3183
3184 /* byte size and parity */
3185 info->cor5 = 0;
3186 info->cor4 = 0;
3187 /* receive threshold */
3188 info->cor3 = (info->default_threshold ?
3189 info->default_threshold : baud_cor3[i]);
3190 info->cor2 = CyETC;
3191 switch (cflag & CSIZE) {
3192 case CS5:
3193 info->cor1 = Cy_5_BITS;
3194 break;
3195 case CS6:
3196 info->cor1 = Cy_6_BITS;
3197 break;
3198 case CS7:
3199 info->cor1 = Cy_7_BITS;
3200 break;
3201 case CS8:
3202 info->cor1 = Cy_8_BITS;
3203 break;
3204 }
3205 if (cflag & CSTOPB) {
3206 info->cor1 |= Cy_2_STOP;
3207 }
3208 if (cflag & PARENB) {
3209 if (cflag & PARODD) {
3210 info->cor1 |= CyPARITY_O;
3211 } else {
3212 info->cor1 |= CyPARITY_E;
3213 }
3214 } else {
3215 info->cor1 |= CyPARITY_NONE;
3216 }
3217
3218 /* CTS flow control flag */
3219 if (cflag & CRTSCTS) {
3220 info->flags |= ASYNC_CTS_FLOW;
3221 info->cor2 |= CyCtsAE;
3222 } else {
3223 info->flags &= ~ASYNC_CTS_FLOW;
3224 info->cor2 &= ~CyCtsAE;
3225 }
3226 if (cflag & CLOCAL)
3227 info->flags &= ~ASYNC_CHECK_CD;
3228 else
3229 info->flags |= ASYNC_CHECK_CD;
3160 3230
3161 /*********************************************** 3231 /***********************************************
3162 The hardware option, CyRtsAO, presents RTS when 3232 The hardware option, CyRtsAO, presents RTS when
@@ -3168,300 +3238,319 @@ set_line_char(struct cyclades_port * info)
3168 cable. Contact Marcio Saito for details. 3238 cable. Contact Marcio Saito for details.
3169 ***********************************************/ 3239 ***********************************************/
3170 3240
3171 chip = channel>>2; 3241 chip = channel >> 2;
3172 channel &= 0x03; 3242 channel &= 0x03;
3173 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3243 base_addr = cy_card[card].base_addr +
3244 (cy_chip_offset[chip] << index);
3174 3245
3175 CY_LOCK(info, flags); 3246 CY_LOCK(info, flags);
3176 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3247 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3177 3248
3178 /* tx and rx baud rate */ 3249 /* tx and rx baud rate */
3179 3250
3180 cy_writeb(base_addr+(CyTCOR<<index), info->tco); 3251 cy_writeb(base_addr + (CyTCOR << index), info->tco);
3181 cy_writeb(base_addr+(CyTBPR<<index), info->tbpr); 3252 cy_writeb(base_addr + (CyTBPR << index), info->tbpr);
3182 cy_writeb(base_addr+(CyRCOR<<index), info->rco); 3253 cy_writeb(base_addr + (CyRCOR << index), info->rco);
3183 cy_writeb(base_addr+(CyRBPR<<index), info->rbpr); 3254 cy_writeb(base_addr + (CyRBPR << index), info->rbpr);
3184 3255
3185 /* set line characteristics according configuration */ 3256 /* set line characteristics according configuration */
3186 3257
3187 cy_writeb(base_addr+(CySCHR1<<index), 3258 cy_writeb(base_addr + (CySCHR1 << index),
3188 START_CHAR(info->tty)); 3259 START_CHAR(info->tty));
3189 cy_writeb(base_addr+(CySCHR2<<index), 3260 cy_writeb(base_addr + (CySCHR2 << index), STOP_CHAR(info->tty));
3190 STOP_CHAR(info->tty)); 3261 cy_writeb(base_addr + (CyCOR1 << index), info->cor1);
3191 cy_writeb(base_addr+(CyCOR1<<index), info->cor1); 3262 cy_writeb(base_addr + (CyCOR2 << index), info->cor2);
3192 cy_writeb(base_addr+(CyCOR2<<index), info->cor2); 3263 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3193 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3264 cy_writeb(base_addr + (CyCOR4 << index), info->cor4);
3194 cy_writeb(base_addr+(CyCOR4<<index), info->cor4); 3265 cy_writeb(base_addr + (CyCOR5 << index), info->cor5);
3195 cy_writeb(base_addr+(CyCOR5<<index), info->cor5); 3266
3196 3267 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
3197 cyy_issue_cmd(base_addr, 3268 CyCOR3ch, index);
3198 CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch,index); 3269
3199 3270 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */
3200 cy_writeb(base_addr+(CyCAR<<index), 3271 cy_writeb(base_addr + (CyRTPR << index),
3201 (u_char)channel); /* !!! Is this needed? */ 3272 (info->default_timeout ? info->default_timeout : 0x02));
3202 cy_writeb(base_addr+(CyRTPR<<index), (info->default_timeout 3273 /* 10ms rx timeout */
3203 ? info->default_timeout 3274
3204 : 0x02)); /* 10ms rx timeout */ 3275 if (C_CLOCAL(info->tty)) {
3205 3276 /* without modem intr */
3206 if (C_CLOCAL(info->tty)) { 3277 cy_writeb(base_addr + (CySRER << index),
3207 /* without modem intr */ 3278 cy_readb(base_addr +
3208 cy_writeb(base_addr+(CySRER<<index), 3279 (CySRER << index)) | CyMdmCh);
3209 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh); 3280 /* act on 1->0 modem transitions */
3210 /* act on 1->0 modem transitions */ 3281 if ((cflag & CRTSCTS) && info->rflow) {
3211 if ((cflag & CRTSCTS) && info->rflow) { 3282 cy_writeb(base_addr + (CyMCOR1 << index),
3212 cy_writeb(base_addr+(CyMCOR1<<index), 3283 (CyCTS | rflow_thr[i]));
3213 (CyCTS|rflow_thr[i])); 3284 } else {
3214 } else { 3285 cy_writeb(base_addr + (CyMCOR1 << index),
3215 cy_writeb(base_addr+(CyMCOR1<<index), CyCTS); 3286 CyCTS);
3216 } 3287 }
3217 /* act on 0->1 modem transitions */ 3288 /* act on 0->1 modem transitions */
3218 cy_writeb(base_addr+(CyMCOR2<<index), CyCTS); 3289 cy_writeb(base_addr + (CyMCOR2 << index), CyCTS);
3219 } else {
3220 /* without modem intr */
3221 cy_writeb(base_addr+(CySRER<<index),
3222 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
3223 /* act on 1->0 modem transitions */
3224 if ((cflag & CRTSCTS) && info->rflow) {
3225 cy_writeb(base_addr+(CyMCOR1<<index),
3226 (CyDSR|CyCTS|CyRI|CyDCD|rflow_thr[i]));
3227 } else {
3228 cy_writeb(base_addr+(CyMCOR1<<index),
3229 CyDSR|CyCTS|CyRI|CyDCD);
3230 }
3231 /* act on 0->1 modem transitions */
3232 cy_writeb(base_addr+(CyMCOR2<<index),
3233 CyDSR|CyCTS|CyRI|CyDCD);
3234 }
3235
3236 if(i == 0){ /* baud rate is zero, turn off line */
3237 if (info->rtsdtr_inv) {
3238 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
3239 } else { 3290 } else {
3240 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3291 /* without modem intr */
3292 cy_writeb(base_addr + (CySRER << index),
3293 cy_readb(base_addr +
3294 (CySRER << index)) | CyMdmCh);
3295 /* act on 1->0 modem transitions */
3296 if ((cflag & CRTSCTS) && info->rflow) {
3297 cy_writeb(base_addr + (CyMCOR1 << index),
3298 (CyDSR | CyCTS | CyRI | CyDCD |
3299 rflow_thr[i]));
3300 } else {
3301 cy_writeb(base_addr + (CyMCOR1 << index),
3302 CyDSR | CyCTS | CyRI | CyDCD);
3303 }
3304 /* act on 0->1 modem transitions */
3305 cy_writeb(base_addr + (CyMCOR2 << index),
3306 CyDSR | CyCTS | CyRI | CyDCD);
3241 } 3307 }
3308
3309 if (i == 0) { /* baud rate is zero, turn off line */
3310 if (info->rtsdtr_inv) {
3311 cy_writeb(base_addr + (CyMSVR1 << index),
3312 ~CyRTS);
3313 } else {
3314 cy_writeb(base_addr + (CyMSVR2 << index),
3315 ~CyDTR);
3316 }
3242#ifdef CY_DEBUG_DTR 3317#ifdef CY_DEBUG_DTR
3243 printk("cyc:set_line_char dropping DTR\n"); 3318 printk("cyc:set_line_char dropping DTR\n");
3244 printk(" status: 0x%x, 0x%x\n", 3319 printk(" status: 0x%x, 0x%x\n",
3245 cy_readb(base_addr+(CyMSVR1<<index)), 3320 cy_readb(base_addr + (CyMSVR1 << index)),
3246 cy_readb(base_addr+(CyMSVR2<<index))); 3321 cy_readb(base_addr + (CyMSVR2 << index)));
3247#endif 3322#endif
3248 }else{ 3323 } else {
3249 if (info->rtsdtr_inv) { 3324 if (info->rtsdtr_inv) {
3250 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3325 cy_writeb(base_addr + (CyMSVR1 << index),
3251 } else { 3326 CyRTS);
3252 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3327 } else {
3253 } 3328 cy_writeb(base_addr + (CyMSVR2 << index),
3329 CyDTR);
3330 }
3254#ifdef CY_DEBUG_DTR 3331#ifdef CY_DEBUG_DTR
3255 printk("cyc:set_line_char raising DTR\n"); 3332 printk("cyc:set_line_char raising DTR\n");
3256 printk(" status: 0x%x, 0x%x\n", 3333 printk(" status: 0x%x, 0x%x\n",
3257 cy_readb(base_addr+(CyMSVR1<<index)), 3334 cy_readb(base_addr + (CyMSVR1 << index)),
3258 cy_readb(base_addr+(CyMSVR2<<index))); 3335 cy_readb(base_addr + (CyMSVR2 << index)));
3259#endif 3336#endif
3260 } 3337 }
3261
3262 if (info->tty){
3263 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3264 }
3265 CY_UNLOCK(info, flags);
3266 3338
3267 } else { 3339 if (info->tty) {
3268 struct FIRM_ID __iomem *firm_id; 3340 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3269 struct ZFW_CTRL __iomem *zfw_ctrl; 3341 }
3270 struct BOARD_CTRL __iomem *board_ctrl; 3342 CY_UNLOCK(info, flags);
3271 struct CH_CTRL __iomem *ch_ctrl;
3272 struct BUF_CTRL __iomem *buf_ctrl;
3273 uclong sw_flow;
3274 int retval;
3275
3276 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3277 if (!ISZLOADED(cy_card[card])) {
3278 return;
3279 }
3280 3343
3281 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3282 board_ctrl = &zfw_ctrl->board_ctrl;
3283 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3284 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3285
3286 /* baud rate */
3287 baud = tty_get_baud_rate(info->tty);
3288 if ((baud == 38400) &&
3289 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3290 if (info->custom_divisor)
3291 baud_rate = info->baud / info->custom_divisor;
3292 else
3293 baud_rate = info->baud;
3294 } else if (baud > CYZ_MAX_SPEED) {
3295 baud = CYZ_MAX_SPEED;
3296 }
3297 cy_writel(&ch_ctrl->comm_baud , baud);
3298
3299 if (baud == 134) {
3300 /* get it right for 134.5 baud */
3301 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3302 } else if ((baud == 38400) &&
3303 ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)) {
3304 info->timeout = (info->xmit_fifo_size*HZ*15/baud_rate) + 2;
3305 } else if (baud) {
3306 info->timeout = (info->xmit_fifo_size*HZ*15/baud) + 2;
3307 /* this needs to be propagated into the card info */
3308 } else { 3344 } else {
3309 info->timeout = 0; 3345 struct FIRM_ID __iomem *firm_id;
3310 } 3346 struct ZFW_CTRL __iomem *zfw_ctrl;
3347 struct BOARD_CTRL __iomem *board_ctrl;
3348 struct CH_CTRL __iomem *ch_ctrl;
3349 struct BUF_CTRL __iomem *buf_ctrl;
3350 uclong sw_flow;
3351 int retval;
3352
3353 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3354 if (!ISZLOADED(cy_card[card])) {
3355 return;
3356 }
3311 3357
3312 /* byte size and parity */ 3358 zfw_ctrl = cy_card[card].base_addr +
3313 switch(cflag & CSIZE){ 3359 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3314 case CS5: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS5); break; 3360 board_ctrl = &zfw_ctrl->board_ctrl;
3315 case CS6: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS6); break; 3361 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3316 case CS7: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS7); break; 3362 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3317 case CS8: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS8); break; 3363
3318 } 3364 /* baud rate */
3319 if(cflag & CSTOPB){ 3365 baud = tty_get_baud_rate(info->tty);
3320 cy_writel(&ch_ctrl->comm_data_l, 3366 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3321 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP); 3367 ASYNC_SPD_CUST) {
3322 }else{ 3368 if (info->custom_divisor)
3323 cy_writel(&ch_ctrl->comm_data_l, 3369 baud_rate = info->baud / info->custom_divisor;
3324 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP); 3370 else
3325 } 3371 baud_rate = info->baud;
3326 if (cflag & PARENB){ 3372 } else if (baud > CYZ_MAX_SPEED) {
3327 if (cflag & PARODD){ 3373 baud = CYZ_MAX_SPEED;
3328 cy_writel(&ch_ctrl->comm_parity , C_PR_ODD); 3374 }
3329 }else{ 3375 cy_writel(&ch_ctrl->comm_baud, baud);
3330 cy_writel(&ch_ctrl->comm_parity , C_PR_EVEN); 3376
3331 } 3377 if (baud == 134) {
3332 }else{ 3378 /* get it right for 134.5 baud */
3333 cy_writel(&ch_ctrl->comm_parity , C_PR_NONE); 3379 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3334 } 3380 2;
3381 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3382 ASYNC_SPD_CUST) {
3383 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3384 baud_rate) + 2;
3385 } else if (baud) {
3386 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3387 baud) + 2;
3388 /* this needs to be propagated into the card info */
3389 } else {
3390 info->timeout = 0;
3391 }
3335 3392
3336 /* CTS flow control flag */ 3393 /* byte size and parity */
3337 if (cflag & CRTSCTS){ 3394 switch (cflag & CSIZE) {
3338 cy_writel(&ch_ctrl->hw_flow, 3395 case CS5:
3339 cy_readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS); 3396 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS5);
3340 }else{ 3397 break;
3341 cy_writel(&ch_ctrl->hw_flow, 3398 case CS6:
3342 cy_readl(&ch_ctrl->hw_flow) & ~(C_RS_CTS | C_RS_RTS)); 3399 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS6);
3343 } 3400 break;
3344 /* As the HW flow control is done in firmware, the driver doesn't 3401 case CS7:
3345 need to care about it */ 3402 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS7);
3346 info->flags &= ~ASYNC_CTS_FLOW; 3403 break;
3347 3404 case CS8:
3348 /* XON/XOFF/XANY flow control flags */ 3405 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS8);
3349 sw_flow = 0; 3406 break;
3350 if (iflag & IXON){ 3407 }
3351 sw_flow |= C_FL_OXX; 3408 if (cflag & CSTOPB) {
3352 if (iflag & IXANY) 3409 cy_writel(&ch_ctrl->comm_data_l,
3353 sw_flow |= C_FL_OIXANY; 3410 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3354 } 3411 } else {
3355 cy_writel(&ch_ctrl->sw_flow, sw_flow); 3412 cy_writel(&ch_ctrl->comm_data_l,
3413 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3414 }
3415 if (cflag & PARENB) {
3416 if (cflag & PARODD) {
3417 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
3418 } else {
3419 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
3420 }
3421 } else {
3422 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
3423 }
3356 3424
3357 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L); 3425 /* CTS flow control flag */
3358 if (retval != 0){ 3426 if (cflag & CRTSCTS) {
3359 printk("cyc:set_line_char retval on ttyC%d was %x\n", 3427 cy_writel(&ch_ctrl->hw_flow,
3360 info->line, retval); 3428 cy_readl(&ch_ctrl->
3361 } 3429 hw_flow) | C_RS_CTS | C_RS_RTS);
3430 } else {
3431 cy_writel(&ch_ctrl->hw_flow,
3432 cy_readl(&ch_ctrl->
3433 hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3434 }
3435 /* As the HW flow control is done in firmware, the driver
3436 doesn't need to care about it */
3437 info->flags &= ~ASYNC_CTS_FLOW;
3438
3439 /* XON/XOFF/XANY flow control flags */
3440 sw_flow = 0;
3441 if (iflag & IXON) {
3442 sw_flow |= C_FL_OXX;
3443 if (iflag & IXANY)
3444 sw_flow |= C_FL_OIXANY;
3445 }
3446 cy_writel(&ch_ctrl->sw_flow, sw_flow);
3362 3447
3363 /* CD sensitivity */ 3448 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
3364 if (cflag & CLOCAL){ 3449 if (retval != 0) {
3365 info->flags &= ~ASYNC_CHECK_CD; 3450 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3366 }else{ 3451 info->line, retval);
3367 info->flags |= ASYNC_CHECK_CD; 3452 }
3368 } 3453
3454 /* CD sensitivity */
3455 if (cflag & CLOCAL) {
3456 info->flags &= ~ASYNC_CHECK_CD;
3457 } else {
3458 info->flags |= ASYNC_CHECK_CD;
3459 }
3369 3460
3370 if(baud == 0){ /* baud rate is zero, turn off line */ 3461 if (baud == 0) { /* baud rate is zero, turn off line */
3371 cy_writel(&ch_ctrl->rs_control, 3462 cy_writel(&ch_ctrl->rs_control,
3372 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR); 3463 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3373#ifdef CY_DEBUG_DTR 3464#ifdef CY_DEBUG_DTR
3374 printk("cyc:set_line_char dropping Z DTR\n"); 3465 printk("cyc:set_line_char dropping Z DTR\n");
3375#endif 3466#endif
3376 }else{ 3467 } else {
3377 cy_writel(&ch_ctrl->rs_control, 3468 cy_writel(&ch_ctrl->rs_control,
3378 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR); 3469 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
3379#ifdef CY_DEBUG_DTR 3470#ifdef CY_DEBUG_DTR
3380 printk("cyc:set_line_char raising Z DTR\n"); 3471 printk("cyc:set_line_char raising Z DTR\n");
3381#endif 3472#endif
3382 } 3473 }
3383 3474
3384 retval = cyz_issue_cmd( &cy_card[card], channel, C_CM_IOCTLM, 0L); 3475 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTLM,0L);
3385 if (retval != 0){ 3476 if (retval != 0) {
3386 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n", 3477 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3387 info->line, retval); 3478 info->line, retval);
3388 } 3479 }
3389 3480
3390 if (info->tty){ 3481 if (info->tty) {
3391 clear_bit(TTY_IO_ERROR, &info->tty->flags); 3482 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3483 }
3392 } 3484 }
3393 } 3485} /* set_line_char */
3394} /* set_line_char */
3395
3396 3486
3397static int 3487static int
3398get_serial_info(struct cyclades_port * info, 3488get_serial_info(struct cyclades_port *info,
3399 struct serial_struct __user * retinfo) 3489 struct serial_struct __user * retinfo)
3400{ 3490{
3401 struct serial_struct tmp; 3491 struct serial_struct tmp;
3402 struct cyclades_card *cinfo = &cy_card[info->card]; 3492 struct cyclades_card *cinfo = &cy_card[info->card];
3403
3404 if (!retinfo)
3405 return -EFAULT;
3406 memset(&tmp, 0, sizeof(tmp));
3407 tmp.type = info->type;
3408 tmp.line = info->line;
3409 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3410 tmp.irq = cinfo->irq;
3411 tmp.flags = info->flags;
3412 tmp.close_delay = info->close_delay;
3413 tmp.baud_base = info->baud;
3414 tmp.custom_divisor = info->custom_divisor;
3415 tmp.hub6 = 0; /*!!!*/
3416 return copy_to_user(retinfo,&tmp,sizeof(*retinfo))?-EFAULT:0;
3417} /* get_serial_info */
3418 3493
3494 if (!retinfo)
3495 return -EFAULT;
3496 memset(&tmp, 0, sizeof(tmp));
3497 tmp.type = info->type;
3498 tmp.line = info->line;
3499 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3500 tmp.irq = cinfo->irq;
3501 tmp.flags = info->flags;
3502 tmp.close_delay = info->close_delay;
3503 tmp.baud_base = info->baud;
3504 tmp.custom_divisor = info->custom_divisor;
3505 tmp.hub6 = 0; /*!!! */
3506 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
3507} /* get_serial_info */
3419 3508
3420static int 3509static int
3421set_serial_info(struct cyclades_port * info, 3510set_serial_info(struct cyclades_port *info,
3422 struct serial_struct __user * new_info) 3511 struct serial_struct __user * new_info)
3423{ 3512{
3424 struct serial_struct new_serial; 3513 struct serial_struct new_serial;
3425 struct cyclades_port old_info; 3514 struct cyclades_port old_info;
3426 3515
3427 if (copy_from_user(&new_serial,new_info,sizeof(new_serial))) 3516 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
3428 return -EFAULT; 3517 return -EFAULT;
3429 old_info = *info; 3518 old_info = *info;
3430 3519
3431 if (!capable(CAP_SYS_ADMIN)) { 3520 if (!capable(CAP_SYS_ADMIN)) {
3432 if ((new_serial.close_delay != info->close_delay) || 3521 if (new_serial.close_delay != info->close_delay ||
3433 (new_serial.baud_base != info->baud) || 3522 new_serial.baud_base != info->baud ||
3434 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) != 3523 (new_serial.flags & ASYNC_FLAGS &
3435 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))) 3524 ~ASYNC_USR_MASK) !=
3436 return -EPERM; 3525 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
3437 info->flags = ((info->flags & ~ASYNC_USR_MASK) | 3526 return -EPERM;
3438 (new_serial.flags & ASYNC_USR_MASK)); 3527 info->flags = (info->flags & ~ASYNC_USR_MASK) |
3439 info->baud = new_serial.baud_base; 3528 (new_serial.flags & ASYNC_USR_MASK);
3440 info->custom_divisor = new_serial.custom_divisor; 3529 info->baud = new_serial.baud_base;
3441 goto check_and_exit; 3530 info->custom_divisor = new_serial.custom_divisor;
3442 } 3531 goto check_and_exit;
3443 3532 }
3444 3533
3445 /* 3534 /*
3446 * OK, past this point, all the error checking has been done. 3535 * OK, past this point, all the error checking has been done.
3447 * At this point, we start making changes..... 3536 * At this point, we start making changes.....
3448 */ 3537 */
3449 3538
3450 info->baud = new_serial.baud_base; 3539 info->baud = new_serial.baud_base;
3451 info->custom_divisor = new_serial.custom_divisor; 3540 info->custom_divisor = new_serial.custom_divisor;
3452 info->flags = ((info->flags & ~ASYNC_FLAGS) | 3541 info->flags = (info->flags & ~ASYNC_FLAGS) |
3453 (new_serial.flags & ASYNC_FLAGS)); 3542 (new_serial.flags & ASYNC_FLAGS);
3454 info->close_delay = new_serial.close_delay * HZ/100; 3543 info->close_delay = new_serial.close_delay * HZ / 100;
3455 info->closing_wait = new_serial.closing_wait * HZ/100; 3544 info->closing_wait = new_serial.closing_wait * HZ / 100;
3456 3545
3457check_and_exit: 3546check_and_exit:
3458 if (info->flags & ASYNC_INITIALIZED){ 3547 if (info->flags & ASYNC_INITIALIZED) {
3459 set_line_char(info); 3548 set_line_char(info);
3460 return 0; 3549 return 0;
3461 }else{ 3550 } else {
3462 return startup(info); 3551 return startup(info);
3463 } 3552 }
3464} /* set_serial_info */ 3553} /* set_serial_info */
3465 3554
3466/* 3555/*
3467 * get_lsr_info - get line status register info 3556 * get_lsr_info - get line status register info
@@ -3473,441 +3562,452 @@ check_and_exit:
3473 * transmit holding register is empty. This functionality 3562 * transmit holding register is empty. This functionality
3474 * allows an RS485 driver to be written in user space. 3563 * allows an RS485 driver to be written in user space.
3475 */ 3564 */
3476static int get_lsr_info(struct cyclades_port *info, unsigned int __user *value) 3565static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3477{ 3566{
3478 int card, chip, channel, index; 3567 int card, chip, channel, index;
3479 unsigned char status; 3568 unsigned char status;
3480 unsigned int result; 3569 unsigned int result;
3481 unsigned long flags; 3570 unsigned long flags;
3482 void __iomem *base_addr; 3571 void __iomem *base_addr;
3483
3484 card = info->card;
3485 channel = (info->line) - (cy_card[card].first_line);
3486 if (!IS_CYC_Z(cy_card[card])) {
3487 chip = channel>>2;
3488 channel &= 0x03;
3489 index = cy_card[card].bus_index;
3490 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3491 3572
3492 CY_LOCK(info, flags); 3573 card = info->card;
3493 status = cy_readb(base_addr+(CySRER<<index)) & (CyTxRdy|CyTxMpty); 3574 channel = (info->line) - (cy_card[card].first_line);
3494 CY_UNLOCK(info, flags); 3575 if (!IS_CYC_Z(cy_card[card])) {
3495 result = (status ? 0 : TIOCSER_TEMT); 3576 chip = channel >> 2;
3496 } else { 3577 channel &= 0x03;
3497 /* Not supported yet */ 3578 index = cy_card[card].bus_index;
3498 return -EINVAL; 3579 base_addr =
3499 } 3580 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3500 return put_user(result, (unsigned long __user *) value); 3581
3582 CY_LOCK(info, flags);
3583 status = cy_readb(base_addr + (CySRER << index)) &
3584 (CyTxRdy | CyTxMpty);
3585 CY_UNLOCK(info, flags);
3586 result = (status ? 0 : TIOCSER_TEMT);
3587 } else {
3588 /* Not supported yet */
3589 return -EINVAL;
3590 }
3591 return put_user(result, (unsigned long __user *)value);
3501} 3592}
3502 3593
3503static int 3594static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3504cy_tiocmget(struct tty_struct *tty, struct file *file)
3505{ 3595{
3506 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3596 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3507 int card,chip,channel,index; 3597 int card, chip, channel, index;
3508 void __iomem *base_addr; 3598 void __iomem *base_addr;
3509 unsigned long flags; 3599 unsigned long flags;
3510 unsigned char status; 3600 unsigned char status;
3511 unsigned long lstatus; 3601 unsigned long lstatus;
3512 unsigned int result; 3602 unsigned int result;
3513 struct FIRM_ID __iomem *firm_id; 3603 struct FIRM_ID __iomem *firm_id;
3514 struct ZFW_CTRL __iomem *zfw_ctrl; 3604 struct ZFW_CTRL __iomem *zfw_ctrl;
3515 struct BOARD_CTRL __iomem *board_ctrl; 3605 struct BOARD_CTRL __iomem *board_ctrl;
3516 struct CH_CTRL __iomem *ch_ctrl; 3606 struct CH_CTRL __iomem *ch_ctrl;
3517 3607
3518 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3608 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3519 return -ENODEV; 3609 return -ENODEV;
3520
3521 card = info->card;
3522 channel = (info->line) - (cy_card[card].first_line);
3523 if (!IS_CYC_Z(cy_card[card])) {
3524 chip = channel>>2;
3525 channel &= 0x03;
3526 index = cy_card[card].bus_index;
3527 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3528 3610
3529 CY_LOCK(info, flags); 3611 card = info->card;
3530 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3612 channel = (info->line) - (cy_card[card].first_line);
3531 status = cy_readb(base_addr+(CyMSVR1<<index)); 3613 if (!IS_CYC_Z(cy_card[card])) {
3532 status |= cy_readb(base_addr+(CyMSVR2<<index)); 3614 chip = channel >> 2;
3533 CY_UNLOCK(info, flags); 3615 channel &= 0x03;
3616 index = cy_card[card].bus_index;
3617 base_addr =
3618 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3534 3619
3535 if (info->rtsdtr_inv) { 3620 CY_LOCK(info, flags);
3536 result = ((status & CyRTS) ? TIOCM_DTR : 0) 3621 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3537 | ((status & CyDTR) ? TIOCM_RTS : 0); 3622 status = cy_readb(base_addr + (CyMSVR1 << index));
3623 status |= cy_readb(base_addr + (CyMSVR2 << index));
3624 CY_UNLOCK(info, flags);
3625
3626 if (info->rtsdtr_inv) {
3627 result = ((status & CyRTS) ? TIOCM_DTR : 0) |
3628 ((status & CyDTR) ? TIOCM_RTS : 0);
3629 } else {
3630 result = ((status & CyRTS) ? TIOCM_RTS : 0) |
3631 ((status & CyDTR) ? TIOCM_DTR : 0);
3632 }
3633 result |= ((status & CyDCD) ? TIOCM_CAR : 0) |
3634 ((status & CyRI) ? TIOCM_RNG : 0) |
3635 ((status & CyDSR) ? TIOCM_DSR : 0) |
3636 ((status & CyCTS) ? TIOCM_CTS : 0);
3538 } else { 3637 } else {
3539 result = ((status & CyRTS) ? TIOCM_RTS : 0) 3638 base_addr = cy_card[card].base_addr;
3540 | ((status & CyDTR) ? TIOCM_DTR : 0);
3541 }
3542 result |= ((status & CyDCD) ? TIOCM_CAR : 0)
3543 | ((status & CyRI) ? TIOCM_RNG : 0)
3544 | ((status & CyDSR) ? TIOCM_DSR : 0)
3545 | ((status & CyCTS) ? TIOCM_CTS : 0);
3546 } else {
3547 base_addr = cy_card[card].base_addr;
3548
3549 if (cy_card[card].num_chips != -1){
3550 return -EINVAL;
3551 }
3552 3639
3553 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3640 if (cy_card[card].num_chips != -1) {
3554 if (ISZLOADED(cy_card[card])) { 3641 return -EINVAL;
3555 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3642 }
3556 board_ctrl = &zfw_ctrl->board_ctrl;
3557 ch_ctrl = zfw_ctrl->ch_ctrl;
3558 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3559 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0)
3560 | ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0)
3561 | ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0)
3562 | ((lstatus & C_RS_RI) ? TIOCM_RNG : 0)
3563 | ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0)
3564 | ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3565 }else{
3566 result = 0;
3567 return -ENODEV;
3568 }
3569 3643
3570 } 3644 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3571 return result; 3645 if (ISZLOADED(cy_card[card])) {
3572} /* cy_tiomget */ 3646 zfw_ctrl = cy_card[card].base_addr +
3647 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3648 board_ctrl = &zfw_ctrl->board_ctrl;
3649 ch_ctrl = zfw_ctrl->ch_ctrl;
3650 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3651 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
3652 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
3653 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
3654 ((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
3655 ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
3656 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3657 } else {
3658 result = 0;
3659 return -ENODEV;
3660 }
3573 3661
3662 }
3663 return result;
3664} /* cy_tiomget */
3574 3665
3575static int 3666static int
3576cy_tiocmset(struct tty_struct *tty, struct file *file, 3667cy_tiocmset(struct tty_struct *tty, struct file *file,
3577 unsigned int set, unsigned int clear) 3668 unsigned int set, unsigned int clear)
3578{ 3669{
3579 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3670 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3580 int card,chip,channel,index; 3671 int card, chip, channel, index;
3581 void __iomem *base_addr; 3672 void __iomem *base_addr;
3582 unsigned long flags; 3673 unsigned long flags;
3583 struct FIRM_ID __iomem *firm_id; 3674 struct FIRM_ID __iomem *firm_id;
3584 struct ZFW_CTRL __iomem *zfw_ctrl; 3675 struct ZFW_CTRL __iomem *zfw_ctrl;
3585 struct BOARD_CTRL __iomem *board_ctrl; 3676 struct BOARD_CTRL __iomem *board_ctrl;
3586 struct CH_CTRL __iomem *ch_ctrl; 3677 struct CH_CTRL __iomem *ch_ctrl;
3587 int retval; 3678 int retval;
3588 3679
3589 if (serial_paranoia_check(info, tty->name, __FUNCTION__)) 3680 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3590 return -ENODEV; 3681 return -ENODEV;
3591 3682
3592 card = info->card; 3683 card = info->card;
3593 channel = (info->line) - (cy_card[card].first_line); 3684 channel = (info->line) - (cy_card[card].first_line);
3594 if (!IS_CYC_Z(cy_card[card])) { 3685 if (!IS_CYC_Z(cy_card[card])) {
3595 chip = channel>>2; 3686 chip = channel >> 2;
3596 channel &= 0x03; 3687 channel &= 0x03;
3597 index = cy_card[card].bus_index; 3688 index = cy_card[card].bus_index;
3598 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index); 3689 base_addr =
3599 3690 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3600 if (set & TIOCM_RTS){ 3691
3601 CY_LOCK(info, flags); 3692 if (set & TIOCM_RTS) {
3602 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3693 CY_LOCK(info, flags);
3603 if (info->rtsdtr_inv) { 3694 cy_writeb(base_addr + (CyCAR << index),
3604 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3695 (u_char) channel);
3605 } else { 3696 if (info->rtsdtr_inv) {
3606 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3697 cy_writeb(base_addr + (CyMSVR2 << index),
3607 } 3698 CyDTR);
3608 CY_UNLOCK(info, flags); 3699 } else {
3609 } 3700 cy_writeb(base_addr + (CyMSVR1 << index),
3610 if (clear & TIOCM_RTS) { 3701 CyRTS);
3611 CY_LOCK(info, flags); 3702 }
3612 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3703 CY_UNLOCK(info, flags);
3613 if (info->rtsdtr_inv) { 3704 }
3614 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3705 if (clear & TIOCM_RTS) {
3615 } else { 3706 CY_LOCK(info, flags);
3616 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3707 cy_writeb(base_addr + (CyCAR << index),
3617 } 3708 (u_char) channel);
3618 CY_UNLOCK(info, flags); 3709 if (info->rtsdtr_inv) {
3619 } 3710 cy_writeb(base_addr + (CyMSVR2 << index),
3620 if (set & TIOCM_DTR){ 3711 ~CyDTR);
3621 CY_LOCK(info, flags); 3712 } else {
3622 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3713 cy_writeb(base_addr + (CyMSVR1 << index),
3623 if (info->rtsdtr_inv) { 3714 ~CyRTS);
3624 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS); 3715 }
3625 } else { 3716 CY_UNLOCK(info, flags);
3626 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR); 3717 }
3627 } 3718 if (set & TIOCM_DTR) {
3719 CY_LOCK(info, flags);
3720 cy_writeb(base_addr + (CyCAR << index),
3721 (u_char) channel);
3722 if (info->rtsdtr_inv) {
3723 cy_writeb(base_addr + (CyMSVR1 << index),
3724 CyRTS);
3725 } else {
3726 cy_writeb(base_addr + (CyMSVR2 << index),
3727 CyDTR);
3728 }
3628#ifdef CY_DEBUG_DTR 3729#ifdef CY_DEBUG_DTR
3629 printk("cyc:set_modem_info raising DTR\n"); 3730 printk("cyc:set_modem_info raising DTR\n");
3630 printk(" status: 0x%x, 0x%x\n", 3731 printk(" status: 0x%x, 0x%x\n",
3631 cy_readb(base_addr+(CyMSVR1<<index)), 3732 cy_readb(base_addr + (CyMSVR1 << index)),
3632 cy_readb(base_addr+(CyMSVR2<<index))); 3733 cy_readb(base_addr + (CyMSVR2 << index)));
3633#endif 3734#endif
3634 CY_UNLOCK(info, flags); 3735 CY_UNLOCK(info, flags);
3635 } 3736 }
3636 if (clear & TIOCM_DTR) { 3737 if (clear & TIOCM_DTR) {
3637 CY_LOCK(info, flags); 3738 CY_LOCK(info, flags);
3638 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel); 3739 cy_writeb(base_addr + (CyCAR << index),
3639 if (info->rtsdtr_inv) { 3740 (u_char) channel);
3640 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS); 3741 if (info->rtsdtr_inv) {
3641 } else { 3742 cy_writeb(base_addr + (CyMSVR1 << index),
3642 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR); 3743 ~CyRTS);
3643 } 3744 } else {
3745 cy_writeb(base_addr + (CyMSVR2 << index),
3746 ~CyDTR);
3747 }
3644 3748
3645#ifdef CY_DEBUG_DTR 3749#ifdef CY_DEBUG_DTR
3646 printk("cyc:set_modem_info dropping DTR\n"); 3750 printk("cyc:set_modem_info dropping DTR\n");
3647 printk(" status: 0x%x, 0x%x\n", 3751 printk(" status: 0x%x, 0x%x\n",
3648 cy_readb(base_addr+(CyMSVR1<<index)), 3752 cy_readb(base_addr + (CyMSVR1 << index)),
3649 cy_readb(base_addr+(CyMSVR2<<index))); 3753 cy_readb(base_addr + (CyMSVR2 << index)));
3650#endif 3754#endif
3651 CY_UNLOCK(info, flags); 3755 CY_UNLOCK(info, flags);
3652 } 3756 }
3653 } else { 3757 } else {
3654 base_addr = cy_card[card].base_addr; 3758 base_addr = cy_card[card].base_addr;
3655 3759
3656 firm_id = cy_card[card].base_addr + ID_ADDRESS; 3760 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3657 if (ISZLOADED(cy_card[card])) { 3761 if (ISZLOADED(cy_card[card])) {
3658 zfw_ctrl = cy_card[card].base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff); 3762 zfw_ctrl = cy_card[card].base_addr +
3659 board_ctrl = &zfw_ctrl->board_ctrl; 3763 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3660 ch_ctrl = zfw_ctrl->ch_ctrl; 3764 board_ctrl = &zfw_ctrl->board_ctrl;
3661 3765 ch_ctrl = zfw_ctrl->ch_ctrl;
3662 if (set & TIOCM_RTS){ 3766
3663 CY_LOCK(info, flags); 3767 if (set & TIOCM_RTS) {
3664 cy_writel(&ch_ctrl[channel].rs_control, 3768 CY_LOCK(info, flags);
3665 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS); 3769 cy_writel(&ch_ctrl[channel].rs_control,
3666 CY_UNLOCK(info, flags); 3770 cy_readl(&ch_ctrl[channel].
3667 } 3771 rs_control) | C_RS_RTS);
3668 if (clear & TIOCM_RTS) { 3772 CY_UNLOCK(info, flags);
3669 CY_LOCK(info, flags); 3773 }
3670 cy_writel(&ch_ctrl[channel].rs_control, 3774 if (clear & TIOCM_RTS) {
3671 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS); 3775 CY_LOCK(info, flags);
3672 CY_UNLOCK(info, flags); 3776 cy_writel(&ch_ctrl[channel].rs_control,
3673 } 3777 cy_readl(&ch_ctrl[channel].
3674 if (set & TIOCM_DTR){ 3778 rs_control) & ~C_RS_RTS);
3675 CY_LOCK(info, flags); 3779 CY_UNLOCK(info, flags);
3676 cy_writel(&ch_ctrl[channel].rs_control, 3780 }
3677 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR); 3781 if (set & TIOCM_DTR) {
3782 CY_LOCK(info, flags);
3783 cy_writel(&ch_ctrl[channel].rs_control,
3784 cy_readl(&ch_ctrl[channel].
3785 rs_control) | C_RS_DTR);
3678#ifdef CY_DEBUG_DTR 3786#ifdef CY_DEBUG_DTR
3679 printk("cyc:set_modem_info raising Z DTR\n"); 3787 printk("cyc:set_modem_info raising Z DTR\n");
3680#endif 3788#endif
3681 CY_UNLOCK(info, flags); 3789 CY_UNLOCK(info, flags);
3682 } 3790 }
3683 if (clear & TIOCM_DTR) { 3791 if (clear & TIOCM_DTR) {
3684 CY_LOCK(info, flags); 3792 CY_LOCK(info, flags);
3685 cy_writel(&ch_ctrl[channel].rs_control, 3793 cy_writel(&ch_ctrl[channel].rs_control,
3686 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR); 3794 cy_readl(&ch_ctrl[channel].
3795 rs_control) & ~C_RS_DTR);
3687#ifdef CY_DEBUG_DTR 3796#ifdef CY_DEBUG_DTR
3688 printk("cyc:set_modem_info clearing Z DTR\n"); 3797 printk("cyc:set_modem_info clearing Z DTR\n");
3689#endif 3798#endif
3690 CY_UNLOCK(info, flags); 3799 CY_UNLOCK(info, flags);
3691 } 3800 }
3692 }else{ 3801 } else {
3693 return -ENODEV; 3802 return -ENODEV;
3694 } 3803 }
3695 CY_LOCK(info, flags); 3804 CY_LOCK(info, flags);
3696 retval = cyz_issue_cmd(&cy_card[info->card], 3805 retval = cyz_issue_cmd(&cy_card[info->card],
3697 channel, C_CM_IOCTLM,0L); 3806 channel, C_CM_IOCTLM, 0L);
3698 if (retval != 0){ 3807 if (retval != 0) {
3699 printk("cyc:set_modem_info retval on ttyC%d was %x\n", 3808 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3700 info->line, retval); 3809 info->line, retval);
3810 }
3811 CY_UNLOCK(info, flags);
3701 } 3812 }
3702 CY_UNLOCK(info, flags); 3813 return 0;
3703 } 3814} /* cy_tiocmset */
3704 return 0;
3705} /* cy_tiocmset */
3706 3815
3707/* 3816/*
3708 * cy_break() --- routine which turns the break handling on or off 3817 * cy_break() --- routine which turns the break handling on or off
3709 */ 3818 */
3710static void 3819static void cy_break(struct tty_struct *tty, int break_state)
3711cy_break(struct tty_struct *tty, int break_state)
3712{ 3820{
3713 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 3821 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3714 unsigned long flags; 3822 unsigned long flags;
3715 3823
3716 if (serial_paranoia_check(info, tty->name, "cy_break")) 3824 if (serial_paranoia_check(info, tty->name, "cy_break"))
3717 return; 3825 return;
3718 3826
3719 CY_LOCK(info, flags); 3827 CY_LOCK(info, flags);
3720 if (!IS_CYC_Z(cy_card[info->card])) { 3828 if (!IS_CYC_Z(cy_card[info->card])) {
3721 /* Let the transmit ISR take care of this (since it 3829 /* Let the transmit ISR take care of this (since it
3722 requires stuffing characters into the output stream). 3830 requires stuffing characters into the output stream).
3723 */ 3831 */
3724 if (break_state == -1) { 3832 if (break_state == -1) {
3725 if (!info->breakon) { 3833 if (!info->breakon) {
3726 info->breakon = 1; 3834 info->breakon = 1;
3727 if (!info->xmit_cnt) { 3835 if (!info->xmit_cnt) {
3728 CY_UNLOCK(info, flags); 3836 CY_UNLOCK(info, flags);
3729 start_xmit(info); 3837 start_xmit(info);
3730 CY_LOCK(info, flags); 3838 CY_LOCK(info, flags);
3839 }
3840 }
3841 } else {
3842 if (!info->breakoff) {
3843 info->breakoff = 1;
3844 if (!info->xmit_cnt) {
3845 CY_UNLOCK(info, flags);
3846 start_xmit(info);
3847 CY_LOCK(info, flags);
3848 }
3849 }
3731 } 3850 }
3732 }
3733 } else { 3851 } else {
3734 if (!info->breakoff) { 3852 int retval;
3735 info->breakoff = 1; 3853
3736 if (!info->xmit_cnt) { 3854 if (break_state == -1) {
3737 CY_UNLOCK(info, flags); 3855 retval = cyz_issue_cmd(&cy_card[info->card],
3738 start_xmit(info); 3856 info->line - cy_card[info->card].first_line,
3739 CY_LOCK(info, flags); 3857 C_CM_SET_BREAK, 0L);
3858 if (retval != 0) {
3859 printk("cyc:cy_break (set) retval on ttyC%d "
3860 "was %x\n", info->line, retval);
3861 }
3862 } else {
3863 retval = cyz_issue_cmd(&cy_card[info->card],
3864 info->line - cy_card[info->card].first_line,
3865 C_CM_CLR_BREAK, 0L);
3866 if (retval != 0) {
3867 printk("cyc:cy_break (clr) retval on ttyC%d "
3868 "was %x\n", info->line, retval);
3869 }
3740 } 3870 }
3741 }
3742 }
3743 } else {
3744 int retval;
3745
3746 if (break_state == -1) {
3747 retval = cyz_issue_cmd(&cy_card[info->card],
3748 (info->line) - (cy_card[info->card].first_line),
3749 C_CM_SET_BREAK, 0L);
3750 if (retval != 0) {
3751 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3752 info->line, retval);
3753 }
3754 } else {
3755 retval = cyz_issue_cmd(&cy_card[info->card],
3756 (info->line) - (cy_card[info->card].first_line),
3757 C_CM_CLR_BREAK, 0L);
3758 if (retval != 0) {
3759 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3760 info->line, retval);
3761 }
3762 } 3871 }
3763 } 3872 CY_UNLOCK(info, flags);
3764 CY_UNLOCK(info, flags); 3873} /* cy_break */
3765} /* cy_break */
3766 3874
3767static int 3875static int
3768get_mon_info(struct cyclades_port * info, struct cyclades_monitor __user * mon) 3876get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
3769{ 3877{
3770 3878
3771 if(copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor))) 3879 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
3772 return -EFAULT; 3880 return -EFAULT;
3773 info->mon.int_count = 0; 3881 info->mon.int_count = 0;
3774 info->mon.char_count = 0; 3882 info->mon.char_count = 0;
3775 info->mon.char_max = 0; 3883 info->mon.char_max = 0;
3776 info->mon.char_last = 0; 3884 info->mon.char_last = 0;
3777 return 0; 3885 return 0;
3778}/* get_mon_info */ 3886} /* get_mon_info */
3779
3780 3887
3781static int 3888static int set_threshold(struct cyclades_port *info, unsigned long value)
3782set_threshold(struct cyclades_port * info, unsigned long value)
3783{ 3889{
3784 void __iomem *base_addr; 3890 void __iomem *base_addr;
3785 int card,channel,chip,index; 3891 int card, channel, chip, index;
3786 unsigned long flags; 3892 unsigned long flags;
3787
3788 card = info->card;
3789 channel = info->line - cy_card[card].first_line;
3790 if (!IS_CYC_Z(cy_card[card])) {
3791 chip = channel>>2;
3792 channel &= 0x03;
3793 index = cy_card[card].bus_index;
3794 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3795
3796 info->cor3 &= ~CyREC_FIFO;
3797 info->cor3 |= value & CyREC_FIFO;
3798 3893
3799 CY_LOCK(info, flags); 3894 card = info->card;
3800 cy_writeb(base_addr+(CyCOR3<<index), info->cor3); 3895 channel = info->line - cy_card[card].first_line;
3801 cyy_issue_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch,index); 3896 if (!IS_CYC_Z(cy_card[card])) {
3802 CY_UNLOCK(info, flags); 3897 chip = channel >> 2;
3803 } else { 3898 channel &= 0x03;
3804 // Nothing to do! 3899 index = cy_card[card].bus_index;
3805 } 3900 base_addr =
3806 return 0; 3901 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3807}/* set_threshold */
3808 3902
3903 info->cor3 &= ~CyREC_FIFO;
3904 info->cor3 |= value & CyREC_FIFO;
3809 3905
3810static int 3906 CY_LOCK(info, flags);
3811get_threshold(struct cyclades_port * info, unsigned long __user *value) 3907 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3812{ 3908 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
3813 void __iomem *base_addr; 3909 CY_UNLOCK(info, flags);
3814 int card,channel,chip,index; 3910 } else {
3815 unsigned long tmp; 3911 /* Nothing to do! */
3816 3912 }
3817 card = info->card;
3818 channel = info->line - cy_card[card].first_line;
3819 if (!IS_CYC_Z(cy_card[card])) {
3820 chip = channel>>2;
3821 channel &= 0x03;
3822 index = cy_card[card].bus_index;
3823 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3824
3825 tmp = cy_readb(base_addr+(CyCOR3<<index)) & CyREC_FIFO;
3826 return put_user(tmp,value);
3827 } else {
3828 // Nothing to do!
3829 return 0; 3913 return 0;
3830 } 3914} /* set_threshold */
3831}/* get_threshold */
3832
3833 3915
3834static int 3916static int
3835set_default_threshold(struct cyclades_port * info, unsigned long value) 3917get_threshold(struct cyclades_port *info, unsigned long __user * value)
3836{ 3918{
3837 info->default_threshold = value & 0x0f; 3919 void __iomem *base_addr;
3838 return 0; 3920 int card, channel, chip, index;
3839}/* set_default_threshold */ 3921 unsigned long tmp;
3840 3922
3923 card = info->card;
3924 channel = info->line - cy_card[card].first_line;
3925 if (!IS_CYC_Z(cy_card[card])) {
3926 chip = channel >> 2;
3927 channel &= 0x03;
3928 index = cy_card[card].bus_index;
3929 base_addr =
3930 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3931
3932 tmp = cy_readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
3933 return put_user(tmp, value);
3934 } else {
3935 /* Nothing to do! */
3936 return 0;
3937 }
3938} /* get_threshold */
3841 3939
3842static int 3940static int
3843get_default_threshold(struct cyclades_port * info, unsigned long __user *value) 3941set_default_threshold(struct cyclades_port *info, unsigned long value)
3844{ 3942{
3845 return put_user(info->default_threshold,value); 3943 info->default_threshold = value & 0x0f;
3846}/* get_default_threshold */ 3944 return 0;
3847 3945} /* set_default_threshold */
3848 3946
3849static int 3947static int
3850set_timeout(struct cyclades_port * info, unsigned long value) 3948get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
3851{ 3949{
3852 void __iomem *base_addr; 3950 return put_user(info->default_threshold, value);
3853 int card,channel,chip,index; 3951} /* get_default_threshold */
3854 unsigned long flags;
3855
3856 card = info->card;
3857 channel = info->line - cy_card[card].first_line;
3858 if (!IS_CYC_Z(cy_card[card])) {
3859 chip = channel>>2;
3860 channel &= 0x03;
3861 index = cy_card[card].bus_index;
3862 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3863 3952
3864 CY_LOCK(info, flags); 3953static int set_timeout(struct cyclades_port *info, unsigned long value)
3865 cy_writeb(base_addr+(CyRTPR<<index), value & 0xff); 3954{
3866 CY_UNLOCK(info, flags); 3955 void __iomem *base_addr;
3867 } else { 3956 int card, channel, chip, index;
3868 // Nothing to do! 3957 unsigned long flags;
3869 }
3870 return 0;
3871}/* set_timeout */
3872 3958
3959 card = info->card;
3960 channel = info->line - cy_card[card].first_line;
3961 if (!IS_CYC_Z(cy_card[card])) {
3962 chip = channel >> 2;
3963 channel &= 0x03;
3964 index = cy_card[card].bus_index;
3965 base_addr =
3966 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3873 3967
3874static int 3968 CY_LOCK(info, flags);
3875get_timeout(struct cyclades_port * info, unsigned long __user *value) 3969 cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
3876{ 3970 CY_UNLOCK(info, flags);
3877 void __iomem *base_addr; 3971 } else {
3878 int card,channel,chip,index; 3972 /* Nothing to do! */
3879 unsigned long tmp; 3973 }
3880
3881 card = info->card;
3882 channel = info->line - cy_card[card].first_line;
3883 if (!IS_CYC_Z(cy_card[card])) {
3884 chip = channel>>2;
3885 channel &= 0x03;
3886 index = cy_card[card].bus_index;
3887 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
3888
3889 tmp = cy_readb(base_addr+(CyRTPR<<index));
3890 return put_user(tmp,value);
3891 } else {
3892 // Nothing to do!
3893 return 0; 3974 return 0;
3894 } 3975} /* set_timeout */
3895}/* get_timeout */
3896
3897 3976
3898static int 3977static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
3899set_default_timeout(struct cyclades_port * info, unsigned long value)
3900{ 3978{
3901 info->default_timeout = value & 0xff; 3979 void __iomem *base_addr;
3902 return 0; 3980 int card, channel, chip, index;
3903}/* set_default_timeout */ 3981 unsigned long tmp;
3904 3982
3983 card = info->card;
3984 channel = info->line - cy_card[card].first_line;
3985 if (!IS_CYC_Z(cy_card[card])) {
3986 chip = channel >> 2;
3987 channel &= 0x03;
3988 index = cy_card[card].bus_index;
3989 base_addr =
3990 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3991
3992 tmp = cy_readb(base_addr + (CyRTPR << index));
3993 return put_user(tmp, value);
3994 } else {
3995 /* Nothing to do! */
3996 return 0;
3997 }
3998} /* get_timeout */
3999
4000static int set_default_timeout(struct cyclades_port *info, unsigned long value)
4001{
4002 info->default_timeout = value & 0xff;
4003 return 0;
4004} /* set_default_timeout */
3905 4005
3906static int 4006static int
3907get_default_timeout(struct cyclades_port * info, unsigned long __user *value) 4007get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
3908{ 4008{
3909 return put_user(info->default_timeout,value); 4009 return put_user(info->default_timeout, value);
3910}/* get_default_timeout */ 4010} /* get_default_timeout */
3911 4011
3912/* 4012/*
3913 * This routine allows the tty driver to implement device- 4013 * This routine allows the tty driver to implement device-
@@ -3915,184 +4015,193 @@ get_default_timeout(struct cyclades_port * info, unsigned long __user *value)
3915 * not recognized by the driver, it should return ENOIOCTLCMD. 4015 * not recognized by the driver, it should return ENOIOCTLCMD.
3916 */ 4016 */
3917static int 4017static int
3918cy_ioctl(struct tty_struct *tty, struct file * file, 4018cy_ioctl(struct tty_struct *tty, struct file *file,
3919 unsigned int cmd, unsigned long arg) 4019 unsigned int cmd, unsigned long arg)
3920{ 4020{
3921 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4021 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3922 struct cyclades_icount cprev, cnow; /* kernel counter temps */ 4022 struct cyclades_icount cprev, cnow; /* kernel counter temps */
3923 struct serial_icounter_struct __user *p_cuser; /* user space */ 4023 struct serial_icounter_struct __user *p_cuser; /* user space */
3924 int ret_val = 0; 4024 int ret_val = 0;
3925 unsigned long flags; 4025 unsigned long flags;
3926 void __user *argp = (void __user *)arg; 4026 void __user *argp = (void __user *)arg;
3927 4027
3928 if (serial_paranoia_check(info, tty->name, "cy_ioctl")) 4028 if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
3929 return -ENODEV; 4029 return -ENODEV;
3930 4030
3931#ifdef CY_DEBUG_OTHER 4031#ifdef CY_DEBUG_OTHER
3932 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", 4032 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */
3933 info->line, cmd, arg); /* */
3934#endif 4033#endif
3935 4034
3936 switch (cmd) { 4035 switch (cmd) {
3937 case CYGETMON: 4036 case CYGETMON:
3938 ret_val = get_mon_info(info, argp); 4037 ret_val = get_mon_info(info, argp);
3939 break; 4038 break;
3940 case CYGETTHRESH: 4039 case CYGETTHRESH:
3941 ret_val = get_threshold(info, argp); 4040 ret_val = get_threshold(info, argp);
3942 break; 4041 break;
3943 case CYSETTHRESH: 4042 case CYSETTHRESH:
3944 ret_val = set_threshold(info, arg); 4043 ret_val = set_threshold(info, arg);
3945 break; 4044 break;
3946 case CYGETDEFTHRESH: 4045 case CYGETDEFTHRESH:
3947 ret_val = get_default_threshold(info, argp); 4046 ret_val = get_default_threshold(info, argp);
3948 break; 4047 break;
3949 case CYSETDEFTHRESH: 4048 case CYSETDEFTHRESH:
3950 ret_val = set_default_threshold(info, arg); 4049 ret_val = set_default_threshold(info, arg);
3951 break; 4050 break;
3952 case CYGETTIMEOUT: 4051 case CYGETTIMEOUT:
3953 ret_val = get_timeout(info, argp); 4052 ret_val = get_timeout(info, argp);
3954 break; 4053 break;
3955 case CYSETTIMEOUT: 4054 case CYSETTIMEOUT:
3956 ret_val = set_timeout(info, arg); 4055 ret_val = set_timeout(info, arg);
3957 break; 4056 break;
3958 case CYGETDEFTIMEOUT: 4057 case CYGETDEFTIMEOUT:
3959 ret_val = get_default_timeout(info, argp); 4058 ret_val = get_default_timeout(info, argp);
3960 break; 4059 break;
3961 case CYSETDEFTIMEOUT: 4060 case CYSETDEFTIMEOUT:
3962 ret_val = set_default_timeout(info, arg); 4061 ret_val = set_default_timeout(info, arg);
3963 break; 4062 break;
3964 case CYSETRFLOW: 4063 case CYSETRFLOW:
3965 info->rflow = (int)arg; 4064 info->rflow = (int)arg;
3966 ret_val = 0; 4065 ret_val = 0;
3967 break; 4066 break;
3968 case CYGETRFLOW: 4067 case CYGETRFLOW:
3969 ret_val = info->rflow; 4068 ret_val = info->rflow;
3970 break; 4069 break;
3971 case CYSETRTSDTR_INV: 4070 case CYSETRTSDTR_INV:
3972 info->rtsdtr_inv = (int)arg; 4071 info->rtsdtr_inv = (int)arg;
3973 ret_val = 0; 4072 ret_val = 0;
3974 break; 4073 break;
3975 case CYGETRTSDTR_INV: 4074 case CYGETRTSDTR_INV:
3976 ret_val = info->rtsdtr_inv; 4075 ret_val = info->rtsdtr_inv;
3977 break; 4076 break;
3978 case CYGETCARDINFO: 4077 case CYGETCARDINFO:
3979 if (copy_to_user(argp, &cy_card[info->card], 4078 if (copy_to_user(argp, &cy_card[info->card],
3980 sizeof (struct cyclades_card))) { 4079 sizeof(struct cyclades_card))) {
3981 ret_val = -EFAULT; 4080 ret_val = -EFAULT;
4081 break;
4082 }
4083 ret_val = 0;
3982 break; 4084 break;
3983 }
3984 ret_val = 0;
3985 break;
3986 case CYGETCD1400VER: 4085 case CYGETCD1400VER:
3987 ret_val = info->chip_rev; 4086 ret_val = info->chip_rev;
3988 break; 4087 break;
3989#ifndef CONFIG_CYZ_INTR 4088#ifndef CONFIG_CYZ_INTR
3990 case CYZSETPOLLCYCLE: 4089 case CYZSETPOLLCYCLE:
3991 cyz_polling_cycle = (arg * HZ) / 1000; 4090 cyz_polling_cycle = (arg * HZ) / 1000;
3992 ret_val = 0; 4091 ret_val = 0;
3993 break; 4092 break;
3994 case CYZGETPOLLCYCLE: 4093 case CYZGETPOLLCYCLE:
3995 ret_val = (cyz_polling_cycle * 1000) / HZ; 4094 ret_val = (cyz_polling_cycle * 1000) / HZ;
3996 break; 4095 break;
3997#endif /* CONFIG_CYZ_INTR */ 4096#endif /* CONFIG_CYZ_INTR */
3998 case CYSETWAIT: 4097 case CYSETWAIT:
3999 info->closing_wait = (unsigned short)arg * HZ/100; 4098 info->closing_wait = (unsigned short)arg *HZ / 100;
4000 ret_val = 0; 4099 ret_val = 0;
4001 break; 4100 break;
4002 case CYGETWAIT: 4101 case CYGETWAIT:
4003 ret_val = info->closing_wait / (HZ/100); 4102 ret_val = info->closing_wait / (HZ / 100);
4004 break; 4103 break;
4005 case TIOCGSERIAL: 4104 case TIOCGSERIAL:
4006 ret_val = get_serial_info(info, argp); 4105 ret_val = get_serial_info(info, argp);
4007 break; 4106 break;
4008 case TIOCSSERIAL: 4107 case TIOCSSERIAL:
4009 ret_val = set_serial_info(info, argp); 4108 ret_val = set_serial_info(info, argp);
4010 break; 4109 break;
4011 case TIOCSERGETLSR: /* Get line status register */ 4110 case TIOCSERGETLSR: /* Get line status register */
4012 ret_val = get_lsr_info(info, argp); 4111 ret_val = get_lsr_info(info, argp);
4013 break; 4112 break;
4014 /* 4113 /*
4015 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change 4114 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4016 * - mask passed in arg for lines of interest 4115 * - mask passed in arg for lines of interest
4017 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking) 4116 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4018 * Caller should use TIOCGICOUNT to see which one it was 4117 * Caller should use TIOCGICOUNT to see which one it was
4019 */ 4118 */
4020 case TIOCMIWAIT: 4119 case TIOCMIWAIT:
4021 CY_LOCK(info, flags);
4022 /* note the counters on entry */
4023 cprev = info->icount;
4024 CY_UNLOCK(info, flags);
4025 while (1) {
4026 interruptible_sleep_on(&info->delta_msr_wait);
4027 /* see if a signal did it */
4028 if (signal_pending(current)) {
4029 return -ERESTARTSYS;
4030 }
4031
4032 CY_LOCK(info, flags); 4120 CY_LOCK(info, flags);
4033 cnow = info->icount; /* atomic copy */ 4121 /* note the counters on entry */
4122 cprev = info->icount;
4034 CY_UNLOCK(info, flags); 4123 CY_UNLOCK(info, flags);
4124 while (1) {
4125 interruptible_sleep_on(&info->delta_msr_wait);
4126 /* see if a signal did it */
4127 if (signal_pending(current)) {
4128 return -ERESTARTSYS;
4129 }
4035 4130
4036 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr && 4131 CY_LOCK(info, flags);
4037 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) { 4132 cnow = info->icount; /* atomic copy */
4038 return -EIO; /* no change => error */ 4133 CY_UNLOCK(info, flags);
4039 }
4040 if ( ((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4041 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4042 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4043 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts)) ) {
4044 return 0;
4045 }
4046 cprev = cnow;
4047 }
4048 /* NOTREACHED */
4049 4134
4050 /* 4135 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
4051 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS) 4136 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
4052 * Return: write counters to the user passed counter struct 4137 return -EIO; /* no change => error */
4053 * NB: both 1->0 and 0->1 transitions are counted except for 4138 }
4054 * RI where only 0->1 is counted. 4139 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4055 */ 4140 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4141 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4142 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
4143 return 0;
4144 }
4145 cprev = cnow;
4146 }
4147 /* NOTREACHED */
4148
4149 /*
4150 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4151 * Return: write counters to the user passed counter struct
4152 * NB: both 1->0 and 0->1 transitions are counted except for
4153 * RI where only 0->1 is counted.
4154 */
4056 case TIOCGICOUNT: 4155 case TIOCGICOUNT:
4057 CY_LOCK(info, flags); 4156 CY_LOCK(info, flags);
4058 cnow = info->icount; 4157 cnow = info->icount;
4059 CY_UNLOCK(info, flags); 4158 CY_UNLOCK(info, flags);
4060 p_cuser = argp; 4159 p_cuser = argp;
4061 ret_val = put_user(cnow.cts, &p_cuser->cts); 4160 ret_val = put_user(cnow.cts, &p_cuser->cts);
4062 if (ret_val) return ret_val; 4161 if (ret_val)
4063 ret_val = put_user(cnow.dsr, &p_cuser->dsr); 4162 return ret_val;
4064 if (ret_val) return ret_val; 4163 ret_val = put_user(cnow.dsr, &p_cuser->dsr);
4065 ret_val = put_user(cnow.rng, &p_cuser->rng); 4164 if (ret_val)
4066 if (ret_val) return ret_val; 4165 return ret_val;
4067 ret_val = put_user(cnow.dcd, &p_cuser->dcd); 4166 ret_val = put_user(cnow.rng, &p_cuser->rng);
4068 if (ret_val) return ret_val; 4167 if (ret_val)
4069 ret_val = put_user(cnow.rx, &p_cuser->rx); 4168 return ret_val;
4070 if (ret_val) return ret_val; 4169 ret_val = put_user(cnow.dcd, &p_cuser->dcd);
4071 ret_val = put_user(cnow.tx, &p_cuser->tx); 4170 if (ret_val)
4072 if (ret_val) return ret_val; 4171 return ret_val;
4073 ret_val = put_user(cnow.frame, &p_cuser->frame); 4172 ret_val = put_user(cnow.rx, &p_cuser->rx);
4074 if (ret_val) return ret_val; 4173 if (ret_val)
4075 ret_val = put_user(cnow.overrun, &p_cuser->overrun); 4174 return ret_val;
4076 if (ret_val) return ret_val; 4175 ret_val = put_user(cnow.tx, &p_cuser->tx);
4077 ret_val = put_user(cnow.parity, &p_cuser->parity); 4176 if (ret_val)
4078 if (ret_val) return ret_val; 4177 return ret_val;
4079 ret_val = put_user(cnow.brk, &p_cuser->brk); 4178 ret_val = put_user(cnow.frame, &p_cuser->frame);
4080 if (ret_val) return ret_val; 4179 if (ret_val)
4081 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun); 4180 return ret_val;
4082 if (ret_val) return ret_val; 4181 ret_val = put_user(cnow.overrun, &p_cuser->overrun);
4083 ret_val = 0; 4182 if (ret_val)
4084 break; 4183 return ret_val;
4085 default: 4184 ret_val = put_user(cnow.parity, &p_cuser->parity);
4086 ret_val = -ENOIOCTLCMD; 4185 if (ret_val)
4087 } 4186 return ret_val;
4187 ret_val = put_user(cnow.brk, &p_cuser->brk);
4188 if (ret_val)
4189 return ret_val;
4190 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
4191 if (ret_val)
4192 return ret_val;
4193 ret_val = 0;
4194 break;
4195 default:
4196 ret_val = -ENOIOCTLCMD;
4197 }
4088 4198
4089#ifdef CY_DEBUG_OTHER 4199#ifdef CY_DEBUG_OTHER
4090 printk(" cyc:cy_ioctl done\n"); 4200 printk(" cyc:cy_ioctl done\n");
4091#endif 4201#endif
4092 4202
4093 return ret_val; 4203 return ret_val;
4094} /* cy_ioctl */ 4204} /* cy_ioctl */
4095
4096 4205
4097/* 4206/*
4098 * This routine allows the tty driver to be notified when 4207 * This routine allows the tty driver to be notified when
@@ -4100,66 +4209,64 @@ cy_ioctl(struct tty_struct *tty, struct file * file,
4100 * well-designed tty driver should be prepared to accept the case 4209 * well-designed tty driver should be prepared to accept the case
4101 * where old == NULL, and try to do something rational. 4210 * where old == NULL, and try to do something rational.
4102 */ 4211 */
4103static void 4212static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4104cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
4105{ 4213{
4106 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4214 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4107 4215
4108#ifdef CY_DEBUG_OTHER 4216#ifdef CY_DEBUG_OTHER
4109 printk("cyc:cy_set_termios ttyC%d\n", info->line); 4217 printk("cyc:cy_set_termios ttyC%d\n", info->line);
4110#endif 4218#endif
4111 4219
4112 if ((tty->termios->c_cflag == old_termios->c_cflag) && 4220 if (tty->termios->c_cflag == old_termios->c_cflag &&
4113 ((tty->termios->c_iflag & (IXON|IXANY)) == 4221 (tty->termios->c_iflag & (IXON | IXANY)) ==
4114 (old_termios->c_iflag & (IXON|IXANY)))) 4222 (old_termios->c_iflag & (IXON | IXANY)))
4115 return; 4223 return;
4116 set_line_char(info); 4224 set_line_char(info);
4117 4225
4118 if ((old_termios->c_cflag & CRTSCTS) && 4226 if ((old_termios->c_cflag & CRTSCTS) &&
4119 !(tty->termios->c_cflag & CRTSCTS)) { 4227 !(tty->termios->c_cflag & CRTSCTS)) {
4120 tty->hw_stopped = 0; 4228 tty->hw_stopped = 0;
4121 cy_start(tty); 4229 cy_start(tty);
4122 } 4230 }
4123#if 0 4231#if 0
4124 /* 4232 /*
4125 * No need to wake up processes in open wait, since they 4233 * No need to wake up processes in open wait, since they
4126 * sample the CLOCAL flag once, and don't recheck it. 4234 * sample the CLOCAL flag once, and don't recheck it.
4127 * XXX It's not clear whether the current behavior is correct 4235 * XXX It's not clear whether the current behavior is correct
4128 * or not. Hence, this may change..... 4236 * or not. Hence, this may change.....
4129 */ 4237 */
4130 if (!(old_termios->c_cflag & CLOCAL) && 4238 if (!(old_termios->c_cflag & CLOCAL) &&
4131 (tty->termios->c_cflag & CLOCAL)) 4239 (tty->termios->c_cflag & CLOCAL))
4132 wake_up_interruptible(&info->open_wait); 4240 wake_up_interruptible(&info->open_wait);
4133#endif 4241#endif
4134 4242} /* cy_set_termios */
4135 return;
4136} /* cy_set_termios */
4137 4243
4138/* This function is used to send a high-priority XON/XOFF character to 4244/* This function is used to send a high-priority XON/XOFF character to
4139 the device. 4245 the device.
4140*/ 4246*/
4141static void 4247static void cy_send_xchar(struct tty_struct *tty, char ch)
4142cy_send_xchar (struct tty_struct *tty, char ch)
4143{ 4248{
4144 struct cyclades_port *info = (struct cyclades_port *) tty->driver_data; 4249 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4145 int card, channel; 4250 int card, channel;
4146 4251
4147 if (serial_paranoia_check (info, tty->name, "cy_send_xchar")) 4252 if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
4148 return; 4253 return;
4149 4254
4150 info->x_char = ch; 4255 info->x_char = ch;
4151 4256
4152 if (ch) 4257 if (ch)
4153 cy_start (tty); 4258 cy_start(tty);
4154 4259
4155 card = info->card; 4260 card = info->card;
4156 channel = info->line - cy_card[card].first_line; 4261 channel = info->line - cy_card[card].first_line;
4157 4262
4158 if (IS_CYC_Z (cy_card[card])) { 4263 if (IS_CYC_Z(cy_card[card])) {
4159 if (ch == STOP_CHAR (tty)) 4264 if (ch == STOP_CHAR(tty))
4160 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXOFF, 0L); 4265 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXOFF,
4161 else if (ch == START_CHAR (tty)) 4266 0L);
4162 cyz_issue_cmd (&cy_card[card], channel, C_CM_SENDXON, 0L); 4267 else if (ch == START_CHAR(tty))
4268 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXON,
4269 0L);
4163 } 4270 }
4164} 4271}
4165 4272
@@ -4167,260 +4274,248 @@ cy_send_xchar (struct tty_struct *tty, char ch)
4167 that incoming characters should be throttled because the input 4274 that incoming characters should be throttled because the input
4168 buffers are close to full. 4275 buffers are close to full.
4169 */ 4276 */
4170static void 4277static void cy_throttle(struct tty_struct *tty)
4171cy_throttle(struct tty_struct * tty)
4172{ 4278{
4173 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4279 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4174 unsigned long flags; 4280 unsigned long flags;
4175 void __iomem *base_addr; 4281 void __iomem *base_addr;
4176 int card,chip,channel,index; 4282 int card, chip, channel, index;
4177 4283
4178#ifdef CY_DEBUG_THROTTLE 4284#ifdef CY_DEBUG_THROTTLE
4179 char buf[64]; 4285 char buf[64];
4180 4286
4181 printk("cyc:throttle %s: %d....ttyC%d\n", 4287 printk("cyc:throttle %s: %d....ttyC%d\n", tty_name(tty, buf),
4182 tty_name(tty, buf), 4288 tty->ldisc.chars_in_buffer(tty), info->line);
4183 tty->ldisc.chars_in_buffer(tty), info->line);
4184#endif 4289#endif
4185 4290
4186 if (serial_paranoia_check(info, tty->name, "cy_throttle")){ 4291 if (serial_paranoia_check(info, tty->name, "cy_throttle")) {
4187 return; 4292 return;
4188 } 4293 }
4189
4190 card = info->card;
4191
4192 if (I_IXOFF(tty)) {
4193 if (!IS_CYC_Z (cy_card[card]))
4194 cy_send_xchar (tty, STOP_CHAR (tty));
4195 else
4196 info->throttle = 1;
4197 }
4198
4199 if (tty->termios->c_cflag & CRTSCTS) {
4200 channel = info->line - cy_card[card].first_line;
4201 if (!IS_CYC_Z(cy_card[card])) {
4202 chip = channel>>2;
4203 channel &= 0x03;
4204 index = cy_card[card].bus_index;
4205 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4206
4207 CY_LOCK(info, flags);
4208 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4209 if (info->rtsdtr_inv) {
4210 cy_writeb(base_addr+(CyMSVR2<<index), ~CyDTR);
4211 } else {
4212 cy_writeb(base_addr+(CyMSVR1<<index), ~CyRTS);
4213 }
4214 CY_UNLOCK(info, flags);
4215 } else {
4216 info->throttle = 1;
4217 }
4218 }
4219 4294
4220 return; 4295 card = info->card;
4221} /* cy_throttle */ 4296
4297 if (I_IXOFF(tty)) {
4298 if (!IS_CYC_Z(cy_card[card]))
4299 cy_send_xchar(tty, STOP_CHAR(tty));
4300 else
4301 info->throttle = 1;
4302 }
4222 4303
4304 if (tty->termios->c_cflag & CRTSCTS) {
4305 channel = info->line - cy_card[card].first_line;
4306 if (!IS_CYC_Z(cy_card[card])) {
4307 chip = channel >> 2;
4308 channel &= 0x03;
4309 index = cy_card[card].bus_index;
4310 base_addr = cy_card[card].base_addr +
4311 (cy_chip_offset[chip] << index);
4312
4313 CY_LOCK(info, flags);
4314 cy_writeb(base_addr + (CyCAR << index),
4315 (u_char) channel);
4316 if (info->rtsdtr_inv) {
4317 cy_writeb(base_addr + (CyMSVR2 << index),
4318 ~CyDTR);
4319 } else {
4320 cy_writeb(base_addr + (CyMSVR1 << index),
4321 ~CyRTS);
4322 }
4323 CY_UNLOCK(info, flags);
4324 } else {
4325 info->throttle = 1;
4326 }
4327 }
4328} /* cy_throttle */
4223 4329
4224/* 4330/*
4225 * This routine notifies the tty driver that it should signal 4331 * This routine notifies the tty driver that it should signal
4226 * that characters can now be sent to the tty without fear of 4332 * that characters can now be sent to the tty without fear of
4227 * overrunning the input buffers of the line disciplines. 4333 * overrunning the input buffers of the line disciplines.
4228 */ 4334 */
4229static void 4335static void cy_unthrottle(struct tty_struct *tty)
4230cy_unthrottle(struct tty_struct * tty)
4231{ 4336{
4232 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4337 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4233 unsigned long flags; 4338 unsigned long flags;
4234 void __iomem *base_addr; 4339 void __iomem *base_addr;
4235 int card,chip,channel,index; 4340 int card, chip, channel, index;
4236 4341
4237#ifdef CY_DEBUG_THROTTLE 4342#ifdef CY_DEBUG_THROTTLE
4238 char buf[64]; 4343 char buf[64];
4239
4240 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4241 tty_name(tty, buf),
4242 tty->ldisc.chars_in_buffer(tty), info->line);
4243#endif
4244 4344
4245 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")){ 4345 printk("cyc:unthrottle %s: %d....ttyC%d\n", tty_name(tty, buf),
4246 return; 4346 tty->ldisc.chars_in_buffer(tty), info->line);
4247 } 4347#endif
4248 4348
4249 if (I_IXOFF(tty)) { 4349 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
4250 if (info->x_char) 4350 return;
4251 info->x_char = 0;
4252 else
4253 cy_send_xchar (tty, START_CHAR (tty));
4254 }
4255
4256 if (tty->termios->c_cflag & CRTSCTS) {
4257 card = info->card;
4258 channel = info->line - cy_card[card].first_line;
4259 if (!IS_CYC_Z(cy_card[card])) {
4260 chip = channel>>2;
4261 channel &= 0x03;
4262 index = cy_card[card].bus_index;
4263 base_addr = cy_card[card].base_addr + (cy_chip_offset[chip]<<index);
4264
4265 CY_LOCK(info, flags);
4266 cy_writeb(base_addr+(CyCAR<<index), (u_char)channel);
4267 if (info->rtsdtr_inv) {
4268 cy_writeb(base_addr+(CyMSVR2<<index), CyDTR);
4269 } else {
4270 cy_writeb(base_addr+(CyMSVR1<<index), CyRTS);
4271 }
4272 CY_UNLOCK(info, flags);
4273 } else {
4274 info->throttle = 0;
4275 } 4351 }
4276 }
4277 4352
4278 return; 4353 if (I_IXOFF(tty)) {
4279} /* cy_unthrottle */ 4354 if (info->x_char)
4355 info->x_char = 0;
4356 else
4357 cy_send_xchar(tty, START_CHAR(tty));
4358 }
4280 4359
4360 if (tty->termios->c_cflag & CRTSCTS) {
4361 card = info->card;
4362 channel = info->line - cy_card[card].first_line;
4363 if (!IS_CYC_Z(cy_card[card])) {
4364 chip = channel >> 2;
4365 channel &= 0x03;
4366 index = cy_card[card].bus_index;
4367 base_addr = cy_card[card].base_addr +
4368 (cy_chip_offset[chip] << index);
4369
4370 CY_LOCK(info, flags);
4371 cy_writeb(base_addr + (CyCAR << index),
4372 (u_char) channel);
4373 if (info->rtsdtr_inv) {
4374 cy_writeb(base_addr + (CyMSVR2 << index),
4375 CyDTR);
4376 } else {
4377 cy_writeb(base_addr + (CyMSVR1 << index),
4378 CyRTS);
4379 }
4380 CY_UNLOCK(info, flags);
4381 } else {
4382 info->throttle = 0;
4383 }
4384 }
4385} /* cy_unthrottle */
4281 4386
4282/* cy_start and cy_stop provide software output flow control as a 4387/* cy_start and cy_stop provide software output flow control as a
4283 function of XON/XOFF, software CTS, and other such stuff. 4388 function of XON/XOFF, software CTS, and other such stuff.
4284*/ 4389*/
4285static void 4390static void cy_stop(struct tty_struct *tty)
4286cy_stop(struct tty_struct *tty)
4287{ 4391{
4288 struct cyclades_card *cinfo; 4392 struct cyclades_card *cinfo;
4289 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4393 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4290 void __iomem *base_addr; 4394 void __iomem *base_addr;
4291 int chip,channel,index; 4395 int chip, channel, index;
4292 unsigned long flags; 4396 unsigned long flags;
4293 4397
4294#ifdef CY_DEBUG_OTHER 4398#ifdef CY_DEBUG_OTHER
4295 printk("cyc:cy_stop ttyC%d\n", info->line); /* */ 4399 printk("cyc:cy_stop ttyC%d\n", info->line); /* */
4296#endif 4400#endif
4297 4401
4298 if (serial_paranoia_check(info, tty->name, "cy_stop")) 4402 if (serial_paranoia_check(info, tty->name, "cy_stop"))
4299 return; 4403 return;
4300
4301 cinfo = &cy_card[info->card];
4302 channel = info->line - cinfo->first_line;
4303 if (!IS_CYC_Z(*cinfo)) {
4304 index = cinfo->bus_index;
4305 chip = channel>>2;
4306 channel &= 0x03;
4307 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4308
4309 CY_LOCK(info, flags);
4310 cy_writeb(base_addr+(CyCAR<<index),
4311 (u_char)(channel & 0x0003)); /* index channel */
4312 cy_writeb(base_addr+(CySRER<<index),
4313 cy_readb(base_addr+(CySRER<<index)) & ~CyTxRdy);
4314 CY_UNLOCK(info, flags);
4315 } else {
4316 // Nothing to do!
4317 }
4318 4404
4319 return; 4405 cinfo = &cy_card[info->card];
4320} /* cy_stop */ 4406 channel = info->line - cinfo->first_line;
4407 if (!IS_CYC_Z(*cinfo)) {
4408 index = cinfo->bus_index;
4409 chip = channel >> 2;
4410 channel &= 0x03;
4411 base_addr = cy_card[info->card].base_addr +
4412 (cy_chip_offset[chip] << index);
4321 4413
4414 CY_LOCK(info, flags);
4415 cy_writeb(base_addr + (CyCAR << index),
4416 (u_char)(channel & 0x0003)); /* index channel */
4417 cy_writeb(base_addr + (CySRER << index),
4418 cy_readb(base_addr + (CySRER << index)) & ~CyTxRdy);
4419 CY_UNLOCK(info, flags);
4420 } else {
4421 /* Nothing to do! */
4422 }
4423} /* cy_stop */
4322 4424
4323static void 4425static void cy_start(struct tty_struct *tty)
4324cy_start(struct tty_struct *tty)
4325{ 4426{
4326 struct cyclades_card *cinfo; 4427 struct cyclades_card *cinfo;
4327 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4428 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4328 void __iomem *base_addr; 4429 void __iomem *base_addr;
4329 int chip,channel,index; 4430 int chip, channel, index;
4330 unsigned long flags; 4431 unsigned long flags;
4331 4432
4332#ifdef CY_DEBUG_OTHER 4433#ifdef CY_DEBUG_OTHER
4333 printk("cyc:cy_start ttyC%d\n", info->line); /* */ 4434 printk("cyc:cy_start ttyC%d\n", info->line); /* */
4334#endif 4435#endif
4335 4436
4336 if (serial_paranoia_check(info, tty->name, "cy_start")) 4437 if (serial_paranoia_check(info, tty->name, "cy_start"))
4337 return; 4438 return;
4338
4339 cinfo = &cy_card[info->card];
4340 channel = info->line - cinfo->first_line;
4341 index = cinfo->bus_index;
4342 if (!IS_CYC_Z(*cinfo)) {
4343 chip = channel>>2;
4344 channel &= 0x03;
4345 base_addr = cy_card[info->card].base_addr + (cy_chip_offset[chip]<<index);
4346
4347 CY_LOCK(info, flags);
4348 cy_writeb(base_addr+(CyCAR<<index),
4349 (u_char)(channel & 0x0003)); /* index channel */
4350 cy_writeb(base_addr+(CySRER<<index),
4351 cy_readb(base_addr+(CySRER<<index)) | CyTxRdy);
4352 CY_UNLOCK(info, flags);
4353 } else {
4354 // Nothing to do!
4355 }
4356 4439
4357 return; 4440 cinfo = &cy_card[info->card];
4358} /* cy_start */ 4441 channel = info->line - cinfo->first_line;
4442 index = cinfo->bus_index;
4443 if (!IS_CYC_Z(*cinfo)) {
4444 chip = channel >> 2;
4445 channel &= 0x03;
4446 base_addr = cy_card[info->card].base_addr +
4447 (cy_chip_offset[chip] << index);
4359 4448
4449 CY_LOCK(info, flags);
4450 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
4451 cy_writeb(base_addr + (CySRER << index),
4452 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
4453 CY_UNLOCK(info, flags);
4454 } else {
4455 /* Nothing to do! */
4456 }
4457} /* cy_start */
4360 4458
4361static void 4459static void cy_flush_buffer(struct tty_struct *tty)
4362cy_flush_buffer(struct tty_struct *tty)
4363{ 4460{
4364 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data; 4461 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4365 int card, channel, retval; 4462 int card, channel, retval;
4366 unsigned long flags; 4463 unsigned long flags;
4367 4464
4368#ifdef CY_DEBUG_IO 4465#ifdef CY_DEBUG_IO
4369 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */ 4466 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
4370#endif 4467#endif
4371 4468
4372 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer")) 4469 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4373 return; 4470 return;
4374
4375 card = info->card;
4376 channel = (info->line) - (cy_card[card].first_line);
4377 4471
4378 CY_LOCK(info, flags); 4472 card = info->card;
4379 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0; 4473 channel = (info->line) - (cy_card[card].first_line);
4380 CY_UNLOCK(info, flags);
4381 4474
4382 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4383 buffers as well */
4384 CY_LOCK(info, flags); 4475 CY_LOCK(info, flags);
4385 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L); 4476 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4386 if (retval != 0) {
4387 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4388 info->line, retval);
4389 }
4390 CY_UNLOCK(info, flags); 4477 CY_UNLOCK(info, flags);
4391 }
4392 tty_wakeup(tty);
4393 wake_up_interruptible(&tty->write_wait);
4394} /* cy_flush_buffer */
4395 4478
4479 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4480 buffers as well */
4481 CY_LOCK(info, flags);
4482 retval =
4483 cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
4484 if (retval != 0) {
4485 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4486 info->line, retval);
4487 }
4488 CY_UNLOCK(info, flags);
4489 }
4490 tty_wakeup(tty);
4491 wake_up_interruptible(&tty->write_wait);
4492} /* cy_flush_buffer */
4396 4493
4397/* 4494/*
4398 * cy_hangup() --- called by tty_hangup() when a hangup is signaled. 4495 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4399 */ 4496 */
4400static void 4497static void cy_hangup(struct tty_struct *tty)
4401cy_hangup(struct tty_struct *tty)
4402{ 4498{
4403 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data; 4499 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4404 4500
4405#ifdef CY_DEBUG_OTHER 4501#ifdef CY_DEBUG_OTHER
4406 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */ 4502 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
4407#endif 4503#endif
4408 4504
4409 if (serial_paranoia_check(info, tty->name, "cy_hangup")) 4505 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
4410 return; 4506 return;
4411 4507
4412 cy_flush_buffer(tty); 4508 cy_flush_buffer(tty);
4413 shutdown(info); 4509 shutdown(info);
4414 info->event = 0; 4510 info->event = 0;
4415 info->count = 0; 4511 info->count = 0;
4416#ifdef CY_DEBUG_COUNT 4512#ifdef CY_DEBUG_COUNT
4417 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid); 4513 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
4418#endif 4514#endif
4419 info->tty = NULL; 4515 info->tty = NULL;
4420 info->flags &= ~ASYNC_NORMAL_ACTIVE; 4516 info->flags &= ~ASYNC_NORMAL_ACTIVE;
4421 wake_up_interruptible(&info->open_wait); 4517 wake_up_interruptible(&info->open_wait);
4422} /* cy_hangup */ 4518} /* cy_hangup */
4423
4424 4519
4425/* 4520/*
4426 * --------------------------------------------------------------------- 4521 * ---------------------------------------------------------------------
@@ -4433,82 +4528,84 @@ cy_hangup(struct tty_struct *tty)
4433/* initialize chips on Cyclom-Y card -- return number of valid 4528/* initialize chips on Cyclom-Y card -- return number of valid
4434 chips (which is number of ports/4) */ 4529 chips (which is number of ports/4) */
4435static unsigned short __init 4530static unsigned short __init
4436cyy_init_card(void __iomem *true_base_addr,int index) 4531cyy_init_card(void __iomem * true_base_addr, int index)
4437{ 4532{
4438 unsigned int chip_number; 4533 unsigned int chip_number;
4439 void __iomem *base_addr; 4534 void __iomem *base_addr;
4440 4535
4441 cy_writeb(true_base_addr+(Cy_HwReset<<index), 0); 4536 cy_writeb(true_base_addr + (Cy_HwReset << index), 0);
4442 /* Cy_HwReset is 0x1400 */ 4537 /* Cy_HwReset is 0x1400 */
4443 cy_writeb(true_base_addr+(Cy_ClrIntr<<index), 0); 4538 cy_writeb(true_base_addr + (Cy_ClrIntr << index), 0);
4444 /* Cy_ClrIntr is 0x1800 */ 4539 /* Cy_ClrIntr is 0x1800 */
4445 udelay(500L); 4540 udelay(500L);
4446 4541
4447 for(chip_number=0; chip_number<CyMAX_CHIPS_PER_CARD; chip_number++){ 4542 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) {
4448 base_addr = true_base_addr + (cy_chip_offset[chip_number]<<index); 4543 base_addr =
4449 mdelay(1); 4544 true_base_addr + (cy_chip_offset[chip_number] << index);
4450 if(cy_readb(base_addr+(CyCCR<<index)) != 0x00){ 4545 mdelay(1);
4451 /************* 4546 if (cy_readb(base_addr + (CyCCR << index)) != 0x00) {
4452 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n", 4547 /*************
4453 chip_number, (unsigned long)base_addr); 4548 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4454 *************/ 4549 chip_number, (unsigned long)base_addr);
4455 return chip_number; 4550 *************/
4456 } 4551 return chip_number;
4457 4552 }
4458 cy_writeb(base_addr+(CyGFRCR<<index), 0); 4553
4459 udelay(10L); 4554 cy_writeb(base_addr + (CyGFRCR << index), 0);
4460 4555 udelay(10L);
4461 /* The Cyclom-16Y does not decode address bit 9 and therefore 4556
4462 cannot distinguish between references to chip 0 and a non- 4557 /* The Cyclom-16Y does not decode address bit 9 and therefore
4463 existent chip 4. If the preceding clearing of the supposed 4558 cannot distinguish between references to chip 0 and a non-
4464 chip 4 GFRCR register appears at chip 0, there is no chip 4 4559 existent chip 4. If the preceding clearing of the supposed
4465 and this must be a Cyclom-16Y, not a Cyclom-32Ye. 4560 chip 4 GFRCR register appears at chip 0, there is no chip 4
4466 */ 4561 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4467 if (chip_number == 4 4562 */
4468 && cy_readb(true_base_addr 4563 if (chip_number == 4 && cy_readb(true_base_addr +
4469 + (cy_chip_offset[0]<<index) 4564 (cy_chip_offset[0] << index) +
4470 + (CyGFRCR<<index)) == 0){ 4565 (CyGFRCR << index)) == 0) {
4471 return chip_number; 4566 return chip_number;
4472 } 4567 }
4473 4568
4474 cy_writeb(base_addr+(CyCCR<<index), CyCHIP_RESET); 4569 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
4475 mdelay(1); 4570 mdelay(1);
4476 4571
4477 if(cy_readb(base_addr+(CyGFRCR<<index)) == 0x00){ 4572 if (cy_readb(base_addr + (CyGFRCR << index)) == 0x00) {
4478 /* 4573 /*
4479 printk(" chip #%d at %#6lx is not responding ", 4574 printk(" chip #%d at %#6lx is not responding ",
4480 chip_number, (unsigned long)base_addr); 4575 chip_number, (unsigned long)base_addr);
4481 printk("(GFRCR stayed 0)\n", 4576 printk("(GFRCR stayed 0)\n",
4482 */ 4577 */
4483 return chip_number; 4578 return chip_number;
4484 } 4579 }
4485 if((0xf0 & (cy_readb(base_addr+(CyGFRCR<<index)))) != 0x40){ 4580 if ((0xf0 & (cy_readb(base_addr + (CyGFRCR << index)))) !=
4486 /* 4581 0x40) {
4487 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n", 4582 /*
4488 chip_number, (unsigned long)base_addr, 4583 printk(" chip #%d at %#6lx is not valid (GFRCR == "
4489 base_addr[CyGFRCR<<index]); 4584 "%#2x)\n",
4490 */ 4585 chip_number, (unsigned long)base_addr,
4491 return chip_number; 4586 base_addr[CyGFRCR<<index]);
4492 } 4587 */
4493 cy_writeb(base_addr+(CyGCR<<index), CyCH0_SERIAL); 4588 return chip_number;
4494 if (cy_readb(base_addr+(CyGFRCR<<index)) >= CD1400_REV_J){ 4589 }
4495 /* It is a CD1400 rev. J or later */ 4590 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
4496 /* Impossible to reach 5ms with this chip. 4591 if (cy_readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
4497 Changed to 2ms instead (f = 500 Hz). */ 4592 /* It is a CD1400 rev. J or later */
4498 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_60_2MS); 4593 /* Impossible to reach 5ms with this chip.
4499 } else { 4594 Changed to 2ms instead (f = 500 Hz). */
4500 /* f = 200 Hz */ 4595 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_60_2MS);
4501 cy_writeb(base_addr+(CyPPR<<index), CyCLOCK_25_5MS); 4596 } else {
4502 } 4597 /* f = 200 Hz */
4598 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_25_5MS);
4599 }
4503 4600
4504 /* 4601 /*
4505 printk(" chip #%d at %#6lx is rev 0x%2x\n", 4602 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4506 chip_number, (unsigned long)base_addr, 4603 chip_number, (unsigned long)base_addr,
4507 cy_readb(base_addr+(CyGFRCR<<index))); 4604 cy_readb(base_addr+(CyGFRCR<<index)));
4508 */ 4605 */
4509 } 4606 }
4510 return chip_number; 4607 return chip_number;
4511} /* cyy_init_card */ 4608} /* cyy_init_card */
4512 4609
4513/* 4610/*
4514 * --------------------------------------------------------------------- 4611 * ---------------------------------------------------------------------
@@ -4516,126 +4613,124 @@ cyy_init_card(void __iomem *true_base_addr,int index)
4516 * sets global variables and return the number of ISA boards found. 4613 * sets global variables and return the number of ISA boards found.
4517 * --------------------------------------------------------------------- 4614 * ---------------------------------------------------------------------
4518 */ 4615 */
4519static int __init 4616static int __init cy_detect_isa(void)
4520cy_detect_isa(void)
4521{ 4617{
4522#ifdef CONFIG_ISA 4618#ifdef CONFIG_ISA
4523 unsigned short cy_isa_irq,nboard; 4619 unsigned short cy_isa_irq, nboard;
4524 void __iomem *cy_isa_address; 4620 void __iomem *cy_isa_address;
4525 unsigned short i,j,cy_isa_nchan; 4621 unsigned short i, j, cy_isa_nchan;
4526#ifdef MODULE 4622#ifdef MODULE
4527 int isparam = 0; 4623 int isparam = 0;
4528#endif 4624#endif
4529 4625
4530 nboard = 0; 4626 nboard = 0;
4531 4627
4532#ifdef MODULE 4628#ifdef MODULE
4533 /* Check for module parameters */ 4629 /* Check for module parameters */
4534 for(i = 0 ; i < NR_CARDS; i++) { 4630 for (i = 0; i < NR_CARDS; i++) {
4535 if (maddr[i] || i) { 4631 if (maddr[i] || i) {
4536 isparam = 1; 4632 isparam = 1;
4537 cy_isa_addresses[i] = maddr[i]; 4633 cy_isa_addresses[i] = maddr[i];
4538 } 4634 }
4539 if (!maddr[i]) 4635 if (!maddr[i])
4540 break; 4636 break;
4541 } 4637 }
4542#endif 4638#endif
4543 4639
4544 /* scan the address table probing for Cyclom-Y/ISA boards */ 4640 /* scan the address table probing for Cyclom-Y/ISA boards */
4545 for (i = 0 ; i < NR_ISA_ADDRS ; i++) { 4641 for (i = 0; i < NR_ISA_ADDRS; i++) {
4546 unsigned int isa_address = cy_isa_addresses[i]; 4642 unsigned int isa_address = cy_isa_addresses[i];
4547 if (isa_address == 0x0000) { 4643 if (isa_address == 0x0000) {
4548 return(nboard); 4644 return nboard;
4549 } 4645 }
4550 4646
4551 /* probe for CD1400... */ 4647 /* probe for CD1400... */
4552 cy_isa_address = ioremap(isa_address, CyISA_Ywin); 4648 cy_isa_address = ioremap(isa_address, CyISA_Ywin);
4553 cy_isa_nchan = CyPORTS_PER_CHIP * 4649 cy_isa_nchan = CyPORTS_PER_CHIP *
4554 cyy_init_card(cy_isa_address,0); 4650 cyy_init_card(cy_isa_address, 0);
4555 if (cy_isa_nchan == 0) { 4651 if (cy_isa_nchan == 0) {
4556 continue; 4652 continue;
4557 } 4653 }
4558
4559#ifdef MODULE 4654#ifdef MODULE
4560 if (isparam && irq[i]) 4655 if (isparam && irq[i])
4561 cy_isa_irq = irq[i]; 4656 cy_isa_irq = irq[i];
4562 else 4657 else
4563#endif 4658#endif
4564 /* find out the board's irq by probing */ 4659 /* find out the board's irq by probing */
4565 cy_isa_irq = detect_isa_irq(cy_isa_address); 4660 cy_isa_irq = detect_isa_irq(cy_isa_address);
4566 if (cy_isa_irq == 0) { 4661 if (cy_isa_irq == 0) {
4567 printk("Cyclom-Y/ISA found at 0x%lx ", 4662 printk("Cyclom-Y/ISA found at 0x%lx ",
4568 (unsigned long) cy_isa_address); 4663 (unsigned long)cy_isa_address);
4569 printk("but the IRQ could not be detected.\n"); 4664 printk("but the IRQ could not be detected.\n");
4570 continue; 4665 continue;
4571 } 4666 }
4572 4667
4573 if((cy_next_channel+cy_isa_nchan) > NR_PORTS) { 4668 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
4574 printk("Cyclom-Y/ISA found at 0x%lx ", 4669 printk("Cyclom-Y/ISA found at 0x%lx ",
4575 (unsigned long) cy_isa_address); 4670 (unsigned long)cy_isa_address);
4576 printk("but no more channels are available.\n"); 4671 printk("but no more channels are available.\n");
4577 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4672 printk("Change NR_PORTS in cyclades.c and recompile "
4578 return(nboard); 4673 "kernel.\n");
4579 } 4674 return nboard;
4580 /* fill the next cy_card structure available */ 4675 }
4581 for (j = 0 ; j < NR_CARDS ; j++) { 4676 /* fill the next cy_card structure available */
4582 if (cy_card[j].base_addr == 0) break; 4677 for (j = 0; j < NR_CARDS; j++) {
4583 } 4678 if (cy_card[j].base_addr == 0)
4584 if (j == NR_CARDS) { /* no more cy_cards available */ 4679 break;
4585 printk("Cyclom-Y/ISA found at 0x%lx ", 4680 }
4586 (unsigned long) cy_isa_address); 4681 if (j == NR_CARDS) { /* no more cy_cards available */
4587 printk("but no more cards can be used .\n"); 4682 printk("Cyclom-Y/ISA found at 0x%lx ",
4588 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4683 (unsigned long)cy_isa_address);
4589 return(nboard); 4684 printk("but no more cards can be used .\n");
4590 } 4685 printk("Change NR_CARDS in cyclades.c and recompile "
4591 4686 "kernel.\n");
4592 /* allocate IRQ */ 4687 return nboard;
4593 if(request_irq(cy_isa_irq, cyy_interrupt, 4688 }
4594 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) 4689
4595 { 4690 /* allocate IRQ */
4596 printk("Cyclom-Y/ISA found at 0x%lx ", 4691 if (request_irq(cy_isa_irq, cyy_interrupt,
4597 (unsigned long) cy_isa_address); 4692 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
4598 printk("but could not allocate IRQ#%d.\n", 4693 printk("Cyclom-Y/ISA found at 0x%lx ",
4599 cy_isa_irq); 4694 (unsigned long)cy_isa_address);
4600 return(nboard); 4695 printk("but could not allocate IRQ#%d.\n", cy_isa_irq);
4601 } 4696 return nboard;
4602 4697 }
4603 /* set cy_card */ 4698
4604 cy_card[j].base_addr = cy_isa_address; 4699 /* set cy_card */
4605 cy_card[j].ctl_addr = NULL; 4700 cy_card[j].base_addr = cy_isa_address;
4606 cy_card[j].irq = (int) cy_isa_irq; 4701 cy_card[j].ctl_addr = NULL;
4607 cy_card[j].bus_index = 0; 4702 cy_card[j].irq = (int)cy_isa_irq;
4608 cy_card[j].first_line = cy_next_channel; 4703 cy_card[j].bus_index = 0;
4609 cy_card[j].num_chips = cy_isa_nchan/4; 4704 cy_card[j].first_line = cy_next_channel;
4610 nboard++; 4705 cy_card[j].num_chips = cy_isa_nchan / 4;
4611 4706 nboard++;
4612 /* print message */ 4707
4613 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ", 4708 /* print message */
4614 j+1, (unsigned long) cy_isa_address, 4709 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4615 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)), 4710 j + 1, (unsigned long)cy_isa_address,
4616 cy_isa_irq); 4711 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4617 printk("%d channels starting from port %d.\n", 4712 cy_isa_irq);
4618 cy_isa_nchan, cy_next_channel); 4713 printk("%d channels starting from port %d.\n",
4619 cy_next_channel += cy_isa_nchan; 4714 cy_isa_nchan, cy_next_channel);
4620 } 4715 cy_next_channel += cy_isa_nchan;
4621 return(nboard); 4716 }
4717 return nboard;
4622#else 4718#else
4623 return(0); 4719 return 0;
4624#endif /* CONFIG_ISA */ 4720#endif /* CONFIG_ISA */
4625} /* cy_detect_isa */ 4721} /* cy_detect_isa */
4626 4722
4627static void 4723static void plx_init(void __iomem * addr, uclong initctl)
4628plx_init(void __iomem *addr, uclong initctl)
4629{ 4724{
4630 /* Reset PLX */ 4725 /* Reset PLX */
4631 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000); 4726 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000);
4632 udelay(100L); 4727 udelay(100L);
4633 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000); 4728 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000);
4634 4729
4635 /* Reload Config. Registers from EEPROM */ 4730 /* Reload Config. Registers from EEPROM */
4636 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000); 4731 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000);
4637 udelay(100L); 4732 udelay(100L);
4638 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000); 4733 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000);
4639} 4734}
4640 4735
4641/* 4736/*
@@ -4644,43 +4739,42 @@ plx_init(void __iomem *addr, uclong initctl)
4644 * sets global variables and return the number of PCI boards found. 4739 * sets global variables and return the number of PCI boards found.
4645 * --------------------------------------------------------------------- 4740 * ---------------------------------------------------------------------
4646 */ 4741 */
4647static int __init 4742static int __init cy_detect_pci(void)
4648cy_detect_pci(void)
4649{ 4743{
4650#ifdef CONFIG_PCI 4744#ifdef CONFIG_PCI
4651 4745
4652 struct pci_dev *pdev = NULL; 4746 struct pci_dev *pdev = NULL;
4653 unsigned char cyy_rev_id; 4747 unsigned char cyy_rev_id;
4654 unsigned char cy_pci_irq = 0; 4748 unsigned char cy_pci_irq = 0;
4655 uclong cy_pci_phys0, cy_pci_phys2; 4749 uclong cy_pci_phys0, cy_pci_phys2;
4656 void __iomem *cy_pci_addr0, *cy_pci_addr2; 4750 void __iomem *cy_pci_addr0, *cy_pci_addr2;
4657 unsigned short i,j,cy_pci_nchan, plx_ver; 4751 unsigned short i, j, cy_pci_nchan, plx_ver;
4658 unsigned short device_id,dev_index = 0; 4752 unsigned short device_id, dev_index = 0;
4659 uclong mailbox; 4753 uclong mailbox;
4660 uclong ZeIndex = 0; 4754 uclong ZeIndex = 0;
4661 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS]; 4755 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS];
4662 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS]; 4756 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
4663 unsigned char Ze_irq[NR_CARDS]; 4757 unsigned char Ze_irq[NR_CARDS];
4664 struct pci_dev *Ze_pdev[NR_CARDS]; 4758 struct pci_dev *Ze_pdev[NR_CARDS];
4665 4759
4666 for (i = 0; i < NR_CARDS; i++) { 4760 for (i = 0; i < NR_CARDS; i++) {
4667 /* look for a Cyclades card by vendor and device id */ 4761 /* look for a Cyclades card by vendor and device id */
4668 while((device_id = cy_pci_dev_id[dev_index]) != 0) { 4762 while ((device_id = cy_pci_dev_id[dev_index]) != 0) {
4669 if((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES, 4763 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4670 device_id, pdev)) == NULL) { 4764 device_id, pdev)) == NULL) {
4671 dev_index++; /* try next device id */ 4765 dev_index++; /* try next device id */
4672 } else { 4766 } else {
4673 break; /* found a board */ 4767 break; /* found a board */
4674 } 4768 }
4675 } 4769 }
4676 4770
4677 if (device_id == 0) 4771 if (device_id == 0)
4678 break; 4772 break;
4679 4773
4680 if (pci_enable_device(pdev)) 4774 if (pci_enable_device(pdev))
4681 continue; 4775 continue;
4682 4776
4683 /* read PCI configuration area */ 4777 /* read PCI configuration area */
4684 cy_pci_irq = pdev->irq; 4778 cy_pci_irq = pdev->irq;
4685 cy_pci_phys0 = pci_resource_start(pdev, 0); 4779 cy_pci_phys0 = pci_resource_start(pdev, 0);
4686 cy_pci_phys2 = pci_resource_start(pdev, 2); 4780 cy_pci_phys2 = pci_resource_start(pdev, 2);
@@ -4688,482 +4782,497 @@ cy_detect_pci(void)
4688 4782
4689 device_id &= ~PCI_DEVICE_ID_MASK; 4783 device_id &= ~PCI_DEVICE_ID_MASK;
4690 4784
4691 if ((device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) 4785 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
4692 || (device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi)){ 4786 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4693#ifdef CY_PCI_DEBUG 4787#ifdef CY_PCI_DEBUG
4694 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4788 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4695 pdev->bus->number, pdev->devfn); 4789 pdev->bus->number, pdev->devfn);
4696 printk("rev_id=%d) IRQ%d\n", 4790 printk("rev_id=%d) IRQ%d\n",
4697 cyy_rev_id, (int)cy_pci_irq); 4791 cyy_rev_id, (int)cy_pci_irq);
4698 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4792 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4699 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4793 "ctladdr=0x%lx\n",
4794 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4700#endif 4795#endif
4701 4796
4702 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4797 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4703 printk(" Warning: PCI I/O bit incorrectly set. " 4798 printk(" Warning: PCI I/O bit incorrectly "
4704 "Ignoring it...\n"); 4799 "set. Ignoring it...\n");
4705 pdev->resource[2].flags &= ~IORESOURCE_IO; 4800 pdev->resource[2].flags &= ~IORESOURCE_IO;
4706 } 4801 }
4707
4708 /* Although we don't use this I/O region, we should
4709 request it from the kernel anyway, to avoid problems
4710 with other drivers accessing it. */
4711 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4712 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n");
4713 continue;
4714 }
4715 4802
4803 /* Although we don't use this I/O region, we should
4804 request it from the kernel anyway, to avoid problems
4805 with other drivers accessing it. */
4806 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4807 printk(KERN_ERR "cyclades: failed to reserve "
4808 "PCI resources\n");
4809 continue;
4810 }
4716#if defined(__alpha__) 4811#if defined(__alpha__)
4717 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */ 4812 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4718 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ", 4813 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4719 pdev->bus->number, pdev->devfn); 4814 pdev->bus->number, pdev->devfn);
4720 printk("rev_id=%d) IRQ%d\n", 4815 printk("rev_id=%d) IRQ%d\n",
4721 cyy_rev_id, (int)cy_pci_irq); 4816 cyy_rev_id, (int)cy_pci_irq);
4722 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n", 4817 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4723 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4818 "ctladdr=0x%lx\n",
4724 printk("Cyclom-Y/PCI not supported for low addresses in " 4819 (ulong)cy_pci_phys2,
4725 "Alpha systems.\n"); 4820 (ulong)cy_pci_phys0);
4726 i--; 4821 printk("Cyclom-Y/PCI not supported for low "
4727 continue; 4822 "addresses in Alpha systems.\n");
4728 } 4823 i--;
4824 continue;
4825 }
4729#endif 4826#endif
4730 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl); 4827 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
4731 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin); 4828 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
4732 4829
4733#ifdef CY_PCI_DEBUG 4830#ifdef CY_PCI_DEBUG
4734 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 4831 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx "
4735 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0); 4832 "ctladdr=0x%lx\n",
4833 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0);
4736#endif 4834#endif
4737 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP * 4835 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4738 cyy_init_card(cy_pci_addr2, 1)); 4836 cyy_init_card(cy_pci_addr2, 1));
4739 if(cy_pci_nchan == 0) { 4837 if (cy_pci_nchan == 0) {
4740 printk("Cyclom-Y PCI host card with "); 4838 printk("Cyclom-Y PCI host card with ");
4741 printk("no Serial-Modules at 0x%lx.\n", 4839 printk("no Serial-Modules at 0x%lx.\n",
4742 (ulong) cy_pci_phys2); 4840 (ulong) cy_pci_phys2);
4743 i--; 4841 i--;
4744 continue; 4842 continue;
4745 } 4843 }
4746 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 4844 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4747 printk("Cyclom-Y/PCI found at 0x%lx ", 4845 printk("Cyclom-Y/PCI found at 0x%lx ",
4748 (ulong) cy_pci_phys2); 4846 (ulong) cy_pci_phys2);
4749 printk("but no channels are available.\n"); 4847 printk("but no channels are available.\n");
4750 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 4848 printk("Change NR_PORTS in cyclades.c and "
4751 return(i); 4849 "recompile kernel.\n");
4752 } 4850 return i;
4753 /* fill the next cy_card structure available */ 4851 }
4754 for (j = 0 ; j < NR_CARDS ; j++) { 4852 /* fill the next cy_card structure available */
4755 if (cy_card[j].base_addr == 0) break; 4853 for (j = 0; j < NR_CARDS; j++) {
4756 } 4854 if (cy_card[j].base_addr == 0)
4757 if (j == NR_CARDS) { /* no more cy_cards available */ 4855 break;
4758 printk("Cyclom-Y/PCI found at 0x%lx ", 4856 }
4759 (ulong) cy_pci_phys2); 4857 if (j == NR_CARDS) { /* no more cy_cards available */
4760 printk("but no more cards can be used.\n"); 4858 printk("Cyclom-Y/PCI found at 0x%lx ",
4761 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4859 (ulong) cy_pci_phys2);
4762 return(i); 4860 printk("but no more cards can be used.\n");
4763 } 4861 printk("Change NR_CARDS in cyclades.c and "
4764 4862 "recompile kernel.\n");
4765 /* allocate IRQ */ 4863 return i;
4766 if(request_irq(cy_pci_irq, cyy_interrupt, 4864 }
4767 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) 4865
4768 { 4866 /* allocate IRQ */
4769 printk("Cyclom-Y/PCI found at 0x%lx ", 4867 if (request_irq(cy_pci_irq, cyy_interrupt,
4770 (ulong) cy_pci_phys2); 4868 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) {
4771 printk("but could not allocate IRQ%d.\n", 4869 printk("Cyclom-Y/PCI found at 0x%lx ",
4772 cy_pci_irq); 4870 (ulong) cy_pci_phys2);
4773 return(i); 4871 printk("but could not allocate IRQ%d.\n",
4774 } 4872 cy_pci_irq);
4775 4873 return i;
4776 /* set cy_card */ 4874 }
4777 cy_card[j].base_phys = (ulong)cy_pci_phys2;
4778 cy_card[j].ctl_phys = (ulong)cy_pci_phys0;
4779 cy_card[j].base_addr = cy_pci_addr2;
4780 cy_card[j].ctl_addr = cy_pci_addr0;
4781 cy_card[j].irq = (int) cy_pci_irq;
4782 cy_card[j].bus_index = 1;
4783 cy_card[j].first_line = cy_next_channel;
4784 cy_card[j].num_chips = cy_pci_nchan/4;
4785 cy_card[j].pdev = pdev;
4786
4787 /* enable interrupts in the PCI interface */
4788 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4789 switch (plx_ver) {
4790 case PLX_9050:
4791
4792 cy_writeb(cy_pci_addr0+0x4c, 0x43);
4793 break;
4794
4795 case PLX_9060:
4796 case PLX_9080:
4797 default: /* Old boards, use PLX_9060 */
4798
4799 plx_init(cy_pci_addr0, 0x6c);
4800 /* For some yet unknown reason, once the PLX9060 reloads
4801 the EEPROM, the IRQ is lost and, thus, we have to
4802 re-write it to the PCI config. registers.
4803 This will remain here until we find a permanent fix. */
4804 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq);
4805
4806 cy_writew(cy_pci_addr0+0x68,
4807 cy_readw(cy_pci_addr0+0x68)|0x0900);
4808 break;
4809 }
4810 4875
4811 /* print message */ 4876 /* set cy_card */
4812 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 4877 cy_card[j].base_phys = (ulong) cy_pci_phys2;
4813 j+1, 4878 cy_card[j].ctl_phys = (ulong) cy_pci_phys0;
4814 (ulong)cy_pci_phys2, 4879 cy_card[j].base_addr = cy_pci_addr2;
4815 (ulong)(cy_pci_phys2 + CyPCI_Ywin - 1), 4880 cy_card[j].ctl_addr = cy_pci_addr0;
4816 (int)cy_pci_irq); 4881 cy_card[j].irq = (int)cy_pci_irq;
4817 printk("%d channels starting from port %d.\n", 4882 cy_card[j].bus_index = 1;
4818 cy_pci_nchan, cy_next_channel); 4883 cy_card[j].first_line = cy_next_channel;
4819 4884 cy_card[j].num_chips = cy_pci_nchan / 4;
4820 cy_next_channel += cy_pci_nchan; 4885 cy_card[j].pdev = pdev;
4821 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo){ 4886
4822 /* print message */ 4887 /* enable interrupts in the PCI interface */
4823 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4888 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4824 pdev->bus->number, pdev->devfn); 4889 switch (plx_ver) {
4825 printk("rev_id=%d) IRQ%d\n", 4890 case PLX_9050:
4826 cyy_rev_id, (int)cy_pci_irq); 4891
4827 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4892 cy_writeb(cy_pci_addr0 + 0x4c, 0x43);
4828 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4893 break;
4829 printk("Cyclades-Z/PCI not supported for low addresses\n"); 4894
4830 break; 4895 case PLX_9060:
4831 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi){ 4896 case PLX_9080:
4897 default: /* Old boards, use PLX_9060 */
4898
4899 plx_init(cy_pci_addr0, 0x6c);
4900 /* For some yet unknown reason, once the PLX9060 reloads
4901 the EEPROM, the IRQ is lost and, thus, we have to
4902 re-write it to the PCI config. registers.
4903 This will remain here until we find a permanent
4904 fix. */
4905 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4906 cy_pci_irq);
4907
4908 cy_writew(cy_pci_addr0 + 0x68,
4909 cy_readw(cy_pci_addr0 +
4910 0x68) | 0x0900);
4911 break;
4912 }
4913
4914 /* print message */
4915 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4916 j + 1, (ulong)cy_pci_phys2,
4917 (ulong) (cy_pci_phys2 + CyPCI_Ywin - 1),
4918 (int)cy_pci_irq);
4919 printk("%d channels starting from port %d.\n",
4920 cy_pci_nchan, cy_next_channel);
4921
4922 cy_next_channel += cy_pci_nchan;
4923 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
4924 /* print message */
4925 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4926 pdev->bus->number, pdev->devfn);
4927 printk("rev_id=%d) IRQ%d\n",
4928 cyy_rev_id, (int)cy_pci_irq);
4929 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4930 "ctladdr=0x%lx\n",
4931 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4932 printk("Cyclades-Z/PCI not supported for low "
4933 "addresses\n");
4934 break;
4935 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4832#ifdef CY_PCI_DEBUG 4936#ifdef CY_PCI_DEBUG
4833 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ", 4937 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4834 pdev->bus->number, pdev->devfn); 4938 pdev->bus->number, pdev->devfn);
4835 printk("rev_id=%d) IRQ%d\n", 4939 printk("rev_id=%d) IRQ%d\n",
4836 cyy_rev_id, (int)cy_pci_irq); 4940 cyy_rev_id, (int)cy_pci_irq);
4837 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n", 4941 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4838 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0); 4942 "ctladdr=0x%lx\n",
4943 (ulong) cy_pci_phys2, (ulong) cy_pci_phys0);
4839#endif 4944#endif
4840 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl); 4945 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
4841 4946
4842 /* Disable interrupts on the PLX before resetting it */ 4947 /* Disable interrupts on the PLX before resetting it */
4843 cy_writew(cy_pci_addr0+0x68, 4948 cy_writew(cy_pci_addr0 + 0x68,
4844 cy_readw(cy_pci_addr0+0x68) & ~0x0900); 4949 cy_readw(cy_pci_addr0 + 0x68) & ~0x0900);
4845 4950
4846 plx_init(cy_pci_addr0, 0x6c); 4951 plx_init(cy_pci_addr0, 0x6c);
4847 /* For some yet unknown reason, once the PLX9060 reloads 4952 /* For some yet unknown reason, once the PLX9060 reloads
4848 the EEPROM, the IRQ is lost and, thus, we have to 4953 the EEPROM, the IRQ is lost and, thus, we have to
4849 re-write it to the PCI config. registers. 4954 re-write it to the PCI config. registers.
4850 This will remain here until we find a permanent fix. */ 4955 This will remain here until we find a permanent
4851 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE, cy_pci_irq); 4956 fix. */
4852 4957 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4853 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *) 4958 cy_pci_irq);
4854 cy_pci_addr0)->mail_box_0); 4959
4855 4960 mailbox =
4856 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) { 4961 (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4857 printk(" Warning: PCI I/O bit incorrectly set. " 4962 cy_pci_addr0)->mail_box_0);
4858 "Ignoring it...\n"); 4963
4859 pdev->resource[2].flags &= ~IORESOURCE_IO; 4964 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4860 } 4965 printk(" Warning: PCI I/O bit incorrectly "
4966 "set. Ignoring it...\n");
4967 pdev->resource[2].flags &= ~IORESOURCE_IO;
4968 }
4861 4969
4862 /* Although we don't use this I/O region, we should 4970 /* Although we don't use this I/O region, we should
4863 request it from the kernel anyway, to avoid problems 4971 request it from the kernel anyway, to avoid problems
4864 with other drivers accessing it. */ 4972 with other drivers accessing it. */
4865 if (pci_request_regions(pdev, "Cyclades-Z") != 0) { 4973 if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
4866 printk(KERN_ERR "cyclades: failed to reserve PCI resources\n"); 4974 printk(KERN_ERR "cyclades: failed to reserve "
4867 continue; 4975 "PCI resources\n");
4868 } 4976 continue;
4869 4977 }
4870 if (mailbox == ZE_V1) { 4978
4871 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ze_win); 4979 if (mailbox == ZE_V1) {
4872 if (ZeIndex == NR_CARDS) { 4980 cy_pci_addr2 = ioremap(cy_pci_phys2,
4873 printk("Cyclades-Ze/PCI found at 0x%lx ", 4981 CyPCI_Ze_win);
4874 (ulong)cy_pci_phys2); 4982 if (ZeIndex == NR_CARDS) {
4875 printk("but no more cards can be used.\n"); 4983 printk("Cyclades-Ze/PCI found at "
4876 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n"); 4984 "0x%lx but no more cards can "
4877 } else { 4985 "be used.\nChange NR_CARDS in "
4878 Ze_phys0[ZeIndex] = cy_pci_phys0; 4986 "cyclades.c and recompile "
4879 Ze_phys2[ZeIndex] = cy_pci_phys2; 4987 "kernel.\n",
4880 Ze_addr0[ZeIndex] = cy_pci_addr0; 4988 (ulong)cy_pci_phys2);
4881 Ze_addr2[ZeIndex] = cy_pci_addr2; 4989 } else {
4882 Ze_irq[ZeIndex] = cy_pci_irq; 4990 Ze_phys0[ZeIndex] = cy_pci_phys0;
4883 Ze_pdev[ZeIndex] = pdev; 4991 Ze_phys2[ZeIndex] = cy_pci_phys2;
4884 ZeIndex++; 4992 Ze_addr0[ZeIndex] = cy_pci_addr0;
4885 } 4993 Ze_addr2[ZeIndex] = cy_pci_addr2;
4886 i--; 4994 Ze_irq[ZeIndex] = cy_pci_irq;
4887 continue; 4995 Ze_pdev[ZeIndex] = pdev;
4888 } else { 4996 ZeIndex++;
4889 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Zwin); 4997 }
4890 } 4998 i--;
4999 continue;
5000 } else {
5001 cy_pci_addr2 = ioremap(cy_pci_phys2,CyPCI_Zwin);
5002 }
4891 5003
4892#ifdef CY_PCI_DEBUG 5004#ifdef CY_PCI_DEBUG
4893 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5005 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx "
4894 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5006 "ctladdr=0x%lx\n",
4895 if (mailbox == ZO_V1) { 5007 (ulong) cy_pci_addr2, (ulong) cy_pci_addr0);
4896 cy_writel(&((struct RUNTIME_9060 *) 5008 if (mailbox == ZO_V1) {
4897 (cy_pci_addr0))->loc_addr_base, WIN_CREG); 5009 cy_writel(&((struct RUNTIME_9060 *)
4898 PAUSE 5010 (cy_pci_addr0))->loc_addr_base,
4899 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n", 5011 WIN_CREG);
4900 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5012 PAUSE;
4901 (cy_pci_addr2))->fpga_id)), 5013 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver "
4902 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *) 5014 "%lx\n", (ulong) (0xff &
4903 (cy_pci_addr2))->fpga_version))); 5015 cy_readl(&((struct CUSTOM_REG *)
4904 cy_writel(&((struct RUNTIME_9060 *) 5016 (cy_pci_addr2))->fpga_id)),
4905 (cy_pci_addr0))->loc_addr_base, WIN_RAM); 5017 (ulong)(0xff &
4906 } else { 5018 cy_readl(&((struct CUSTOM_REG *)
4907 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5019 (cy_pci_addr2))->
4908 } 5020 fpga_version)));
5021 cy_writel(&((struct RUNTIME_9060 *)
5022 (cy_pci_addr0))->loc_addr_base,
5023 WIN_RAM);
5024 } else {
5025 printk("Cyclades-Z/PCI: New Cyclades-Z board. "
5026 "FPGA not loaded\n");
5027 }
4909#endif 5028#endif
4910 /* The following clears the firmware id word. This ensures 5029 /* The following clears the firmware id word. This
4911 that the driver will not attempt to talk to the board 5030 ensures that the driver will not attempt to talk to
4912 until it has been properly initialized. 5031 the board until it has been properly initialized.
4913 */ 5032 */
4914 PAUSE 5033 PAUSE;
4915 if ((mailbox == ZO_V1) || (mailbox == ZO_V2)) 5034 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
4916 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L); 5035 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L);
4917 5036
4918 /* This must be a Cyclades-8Zo/PCI. The extendable 5037 /* This must be a Cyclades-8Zo/PCI. The extendable
4919 version will have a different device_id and will 5038 version will have a different device_id and will
4920 be allocated its maximum number of ports. */ 5039 be allocated its maximum number of ports. */
4921 cy_pci_nchan = 8; 5040 cy_pci_nchan = 8;
4922 5041
4923 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5042 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4924 printk("Cyclades-8Zo/PCI found at 0x%lx ", 5043 printk("Cyclades-8Zo/PCI found at 0x%lx but"
4925 (ulong)cy_pci_phys2); 5044 "no channels are available.\nChange "
4926 printk("but no channels are available.\n"); 5045 "NR_PORTS in cyclades.c and recompile "
4927 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5046 "kernel.\n", (ulong)cy_pci_phys2);
4928 return(i); 5047 return i;
4929 } 5048 }
4930
4931 /* fill the next cy_card structure available */
4932 for (j = 0 ; j < NR_CARDS ; j++) {
4933 if (cy_card[j].base_addr == 0) break;
4934 }
4935 if (j == NR_CARDS) { /* no more cy_cards available */
4936 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4937 (ulong)cy_pci_phys2);
4938 printk("but no more cards can be used.\n");
4939 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4940 return(i);
4941 }
4942 5049
5050 /* fill the next cy_card structure available */
5051 for (j = 0; j < NR_CARDS; j++) {
5052 if (cy_card[j].base_addr == 0)
5053 break;
5054 }
5055 if (j == NR_CARDS) { /* no more cy_cards available */
5056 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5057 "no more cards can be used.\nChange "
5058 "NR_CARDS in cyclades.c and recompile "
5059 "kernel.\n", (ulong)cy_pci_phys2);
5060 return i;
5061 }
5062#ifdef CONFIG_CYZ_INTR
5063 /* allocate IRQ only if board has an IRQ */
5064 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5065 if (request_irq(cy_pci_irq, cyz_interrupt,
5066 IRQF_SHARED, "Cyclades-Z",
5067 &cy_card[j])) {
5068 printk("Cyclom-8Zo/PCI found at 0x%lx "
5069 "but could not allocate "
5070 "IRQ%d.\n", (ulong)cy_pci_phys2,
5071 cy_pci_irq);
5072 return i;
5073 }
5074 }
5075#endif /* CONFIG_CYZ_INTR */
5076
5077 /* set cy_card */
5078 cy_card[j].base_phys = cy_pci_phys2;
5079 cy_card[j].ctl_phys = cy_pci_phys0;
5080 cy_card[j].base_addr = cy_pci_addr2;
5081 cy_card[j].ctl_addr = cy_pci_addr0;
5082 cy_card[j].irq = (int)cy_pci_irq;
5083 cy_card[j].bus_index = 1;
5084 cy_card[j].first_line = cy_next_channel;
5085 cy_card[j].num_chips = -1;
5086 cy_card[j].pdev = pdev;
5087
5088 /* print message */
4943#ifdef CONFIG_CYZ_INTR 5089#ifdef CONFIG_CYZ_INTR
4944 /* allocate IRQ only if board has an IRQ */ 5090 /* don't report IRQ if board is no IRQ */
4945 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5091 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
4946 if(request_irq(cy_pci_irq, cyz_interrupt, 5092 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, "
4947 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5093 "IRQ%d, ", j + 1, (ulong)cy_pci_phys2,
4948 { 5094 (ulong) (cy_pci_phys2 + CyPCI_Zwin - 1),
4949 printk("Cyclom-8Zo/PCI found at 0x%lx ", 5095 (int)cy_pci_irq);
4950 (ulong) cy_pci_phys2); 5096 else
4951 printk("but could not allocate IRQ%d.\n", 5097#endif /* CONFIG_CYZ_INTR */
4952 cy_pci_irq); 5098 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
4953 return(i); 5099 j + 1, (ulong)cy_pci_phys2,
4954 } 5100 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
5101
5102 printk("%d channels starting from port %d.\n",
5103 cy_pci_nchan, cy_next_channel);
5104 cy_next_channel += cy_pci_nchan;
4955 } 5105 }
4956#endif /* CONFIG_CYZ_INTR */ 5106 }
4957
4958
4959 /* set cy_card */
4960 cy_card[j].base_phys = cy_pci_phys2;
4961 cy_card[j].ctl_phys = cy_pci_phys0;
4962 cy_card[j].base_addr = cy_pci_addr2;
4963 cy_card[j].ctl_addr = cy_pci_addr0;
4964 cy_card[j].irq = (int) cy_pci_irq;
4965 cy_card[j].bus_index = 1;
4966 cy_card[j].first_line = cy_next_channel;
4967 cy_card[j].num_chips = -1;
4968 cy_card[j].pdev = pdev;
4969 5107
4970 /* print message */ 5108 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4971#ifdef CONFIG_CYZ_INTR 5109 cy_pci_phys0 = Ze_phys0[0];
4972 /* don't report IRQ if board is no IRQ */ 5110 cy_pci_phys2 = Ze_phys2[0];
4973 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5111 cy_pci_addr0 = Ze_addr0[0];
4974 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5112 cy_pci_addr2 = Ze_addr2[0];
4975 j+1,(ulong)cy_pci_phys2, 5113 cy_pci_irq = Ze_irq[0];
4976 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1), 5114 pdev = Ze_pdev[0];
4977 (int)cy_pci_irq); 5115 for (j = 0; j < ZeIndex - 1; j++) {
4978 else 5116 Ze_phys0[j] = Ze_phys0[j + 1];
4979#endif /* CONFIG_CYZ_INTR */ 5117 Ze_phys2[j] = Ze_phys2[j + 1];
4980 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ", 5118 Ze_addr0[j] = Ze_addr0[j + 1];
4981 j+1,(ulong)cy_pci_phys2, 5119 Ze_addr2[j] = Ze_addr2[j + 1];
4982 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1)); 5120 Ze_irq[j] = Ze_irq[j + 1];
4983 5121 Ze_pdev[j] = Ze_pdev[j + 1];
4984 printk("%d channels starting from port %d.\n", 5122 }
4985 cy_pci_nchan,cy_next_channel); 5123 ZeIndex--;
4986 cy_next_channel += cy_pci_nchan; 5124 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4987 } 5125 cy_pci_addr0)->mail_box_0);
4988 }
4989
4990 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4991 cy_pci_phys0 = Ze_phys0[0];
4992 cy_pci_phys2 = Ze_phys2[0];
4993 cy_pci_addr0 = Ze_addr0[0];
4994 cy_pci_addr2 = Ze_addr2[0];
4995 cy_pci_irq = Ze_irq[0];
4996 pdev = Ze_pdev[0];
4997 for (j = 0 ; j < ZeIndex-1 ; j++) {
4998 Ze_phys0[j] = Ze_phys0[j+1];
4999 Ze_phys2[j] = Ze_phys2[j+1];
5000 Ze_addr0[j] = Ze_addr0[j+1];
5001 Ze_addr2[j] = Ze_addr2[j+1];
5002 Ze_irq[j] = Ze_irq[j+1];
5003 Ze_pdev[j] = Ze_pdev[j+1];
5004 }
5005 ZeIndex--;
5006 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
5007 cy_pci_addr0)->mail_box_0);
5008#ifdef CY_PCI_DEBUG 5126#ifdef CY_PCI_DEBUG
5009 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n", 5127 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5010 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0); 5128 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
5011 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n"); 5129 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not "
5130 "loaded\n");
5012#endif 5131#endif
5013 PAUSE 5132 PAUSE;
5014 /* This must be the new Cyclades-Ze/PCI. */ 5133 /* This must be the new Cyclades-Ze/PCI. */
5015 cy_pci_nchan = ZE_V1_NPORTS; 5134 cy_pci_nchan = ZE_V1_NPORTS;
5016 5135
5017 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) { 5136 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5018 printk("Cyclades-Ze/PCI found at 0x%lx ", 5137 printk("Cyclades-Ze/PCI found at 0x%lx but no channels "
5019 (ulong)cy_pci_phys2); 5138 "are available.\nChange NR_PORTS in cyclades.c "
5020 printk("but no channels are available.\n"); 5139 "and recompile kernel.\n",
5021 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n"); 5140 (ulong) cy_pci_phys2);
5022 return(i); 5141 return i;
5023 } 5142 }
5024
5025 /* fill the next cy_card structure available */
5026 for (j = 0 ; j < NR_CARDS ; j++) {
5027 if (cy_card[j].base_addr == 0) break;
5028 }
5029 if (j == NR_CARDS) { /* no more cy_cards available */
5030 printk("Cyclades-Ze/PCI found at 0x%lx ",
5031 (ulong)cy_pci_phys2);
5032 printk("but no more cards can be used.\n");
5033 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5034 return(i);
5035 }
5036 5143
5144 /* fill the next cy_card structure available */
5145 for (j = 0; j < NR_CARDS; j++) {
5146 if (cy_card[j].base_addr == 0)
5147 break;
5148 }
5149 if (j == NR_CARDS) { /* no more cy_cards available */
5150 printk("Cyclades-Ze/PCI found at 0x%lx but no more "
5151 "cards can be used.\nChange NR_CARDS in "
5152 "cyclades.c and recompile kernel.\n",
5153 (ulong) cy_pci_phys2);
5154 return i;
5155 }
5037#ifdef CONFIG_CYZ_INTR 5156#ifdef CONFIG_CYZ_INTR
5038 /* allocate IRQ only if board has an IRQ */ 5157 /* allocate IRQ only if board has an IRQ */
5039 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) { 5158 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5040 if(request_irq(cy_pci_irq, cyz_interrupt, 5159 if (request_irq(cy_pci_irq, cyz_interrupt,
5041 IRQF_SHARED, "Cyclades-Z", &cy_card[j])) 5160 IRQF_SHARED, "Cyclades-Z",
5042 { 5161 &cy_card[j])) {
5043 printk("Cyclom-Ze/PCI found at 0x%lx ", 5162 printk("Cyclom-Ze/PCI found at 0x%lx ",
5044 (ulong) cy_pci_phys2); 5163 (ulong) cy_pci_phys2);
5045 printk("but could not allocate IRQ%d.\n", 5164 printk("but could not allocate IRQ%d.\n",
5046 cy_pci_irq); 5165 cy_pci_irq);
5047 return(i); 5166 return i;
5048 } 5167 }
5049 } 5168 }
5050#endif /* CONFIG_CYZ_INTR */ 5169#endif /* CONFIG_CYZ_INTR */
5051 5170
5052 /* set cy_card */ 5171 /* set cy_card */
5053 cy_card[j].base_phys = cy_pci_phys2; 5172 cy_card[j].base_phys = cy_pci_phys2;
5054 cy_card[j].ctl_phys = cy_pci_phys0; 5173 cy_card[j].ctl_phys = cy_pci_phys0;
5055 cy_card[j].base_addr = cy_pci_addr2; 5174 cy_card[j].base_addr = cy_pci_addr2;
5056 cy_card[j].ctl_addr = cy_pci_addr0; 5175 cy_card[j].ctl_addr = cy_pci_addr0;
5057 cy_card[j].irq = (int) cy_pci_irq; 5176 cy_card[j].irq = (int)cy_pci_irq;
5058 cy_card[j].bus_index = 1; 5177 cy_card[j].bus_index = 1;
5059 cy_card[j].first_line = cy_next_channel; 5178 cy_card[j].first_line = cy_next_channel;
5060 cy_card[j].num_chips = -1; 5179 cy_card[j].num_chips = -1;
5061 cy_card[j].pdev = pdev; 5180 cy_card[j].pdev = pdev;
5062 5181
5063 /* print message */ 5182 /* print message */
5064#ifdef CONFIG_CYZ_INTR 5183#ifdef CONFIG_CYZ_INTR
5065 /* don't report IRQ if board is no IRQ */ 5184 /* don't report IRQ if board is no IRQ */
5066 if( (cy_pci_irq != 0) && (cy_pci_irq != 255) ) 5185 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5067 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ", 5186 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5068 j+1,(ulong)cy_pci_phys2, 5187 j + 1, (ulong) cy_pci_phys2,
5069 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1), 5188 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1),
5070 (int)cy_pci_irq); 5189 (int)cy_pci_irq);
5071 else 5190 else
5072#endif /* CONFIG_CYZ_INTR */ 5191#endif /* CONFIG_CYZ_INTR */
5073 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ", 5192 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5074 j+1,(ulong)cy_pci_phys2, 5193 j + 1, (ulong) cy_pci_phys2,
5075 (ulong)(cy_pci_phys2 + CyPCI_Ze_win - 1)); 5194 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1));
5076 5195
5077 printk("%d channels starting from port %d.\n", 5196 printk("%d channels starting from port %d.\n",
5078 cy_pci_nchan,cy_next_channel); 5197 cy_pci_nchan, cy_next_channel);
5079 cy_next_channel += cy_pci_nchan; 5198 cy_next_channel += cy_pci_nchan;
5080 } 5199 }
5081 if (ZeIndex != 0) { 5200 if (ZeIndex != 0) {
5082 printk("Cyclades-Ze/PCI found at 0x%x ", 5201 printk("Cyclades-Ze/PCI found at 0x%x but no more cards can be "
5083 (unsigned int) Ze_phys2[0]); 5202 "used.\nChange NR_CARDS in cyclades.c and recompile "
5084 printk("but no more cards can be used.\n"); 5203 "kernel.\n", (unsigned int)Ze_phys2[0]);
5085 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5086 } 5204 }
5087 return(i); 5205 return i;
5088#else 5206#else
5089 return(0); 5207 return 0;
5090#endif /* ifdef CONFIG_PCI */ 5208#endif /* ifdef CONFIG_PCI */
5091} /* cy_detect_pci */ 5209} /* cy_detect_pci */
5092
5093 5210
5094/* 5211/*
5095 * This routine prints out the appropriate serial driver version number 5212 * This routine prints out the appropriate serial driver version number
5096 * and identifies which options were configured into this driver. 5213 * and identifies which options were configured into this driver.
5097 */ 5214 */
5098static inline void 5215static inline void show_version(void)
5099show_version(void)
5100{ 5216{
5101 char *rcsvers, *rcsdate, *tmp; 5217 printk("Cyclades driver " CY_VERSION "\n");
5102 rcsvers = strchr(rcsid, ' '); rcsvers++; 5218 printk(" built %s %s\n", __DATE__, __TIME__);
5103 tmp = strchr(rcsvers, ' '); *tmp++ = '\0'; 5219} /* show_version */
5104 rcsdate = strchr(tmp, ' '); rcsdate++; 5220
5105 tmp = strrchr(rcsdate, ' '); *tmp = '\0'; 5221static int
5106 printk("Cyclades driver %s %s\n",
5107 rcsvers, rcsdate);
5108 printk(" built %s %s\n",
5109 __DATE__, __TIME__);
5110} /* show_version */
5111
5112static int
5113cyclades_get_proc_info(char *buf, char **start, off_t offset, int length, 5222cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5114 int *eof, void *data) 5223 int *eof, void *data)
5115{ 5224{
5116 struct cyclades_port *info; 5225 struct cyclades_port *info;
5117 int i; 5226 int i;
5118 int len=0; 5227 int len = 0;
5119 off_t begin=0; 5228 off_t begin = 0;
5120 off_t pos=0; 5229 off_t pos = 0;
5121 int size; 5230 int size;
5122 __u32 cur_jifs = jiffies; 5231 __u32 cur_jifs = jiffies;
5123 5232
5124 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n"); 5233 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn "
5125 5234 "IdleIn Overruns Ldisc\n");
5126 pos += size; 5235
5127 len += size; 5236 pos += size;
5128
5129 /* Output one line for each known port */
5130 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5131 info = &cy_port[i];
5132
5133 if (info->count)
5134 size = sprintf(buf+len,
5135 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5136 info->line,
5137 JIFFIES_DIFF(info->idle_stats.in_use, cur_jifs) / HZ,
5138 info->idle_stats.xmit_bytes,
5139 JIFFIES_DIFF(info->idle_stats.xmit_idle, cur_jifs) / HZ,
5140 info->idle_stats.recv_bytes,
5141 JIFFIES_DIFF(info->idle_stats.recv_idle, cur_jifs) / HZ,
5142 info->idle_stats.overruns,
5143 (long) info->tty->ldisc.num);
5144 else
5145 size = sprintf(buf+len,
5146 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5147 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5148 len += size; 5237 len += size;
5149 pos = begin + len;
5150 5238
5151 if (pos < offset) { 5239 /* Output one line for each known port */
5152 len = 0; 5240 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5153 begin = pos; 5241 info = &cy_port[i];
5242
5243 if (info->count)
5244 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5245 "%8lu %9lu %6ld\n", info->line,
5246 (cur_jifs - info->idle_stats.in_use) / HZ,
5247 info->idle_stats.xmit_bytes,
5248 (cur_jifs - info->idle_stats.xmit_idle) / HZ,
5249 info->idle_stats.recv_bytes,
5250 (cur_jifs - info->idle_stats.recv_idle) / HZ,
5251 info->idle_stats.overruns,
5252 (long)info->tty->ldisc.num);
5253 else
5254 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5255 "%8lu %9lu %6ld\n",
5256 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5257 len += size;
5258 pos = begin + len;
5259
5260 if (pos < offset) {
5261 len = 0;
5262 begin = pos;
5263 }
5264 if (pos > offset + length)
5265 goto done;
5154 } 5266 }
5155 if (pos > offset + length) 5267 *eof = 1;
5156 goto done;
5157 }
5158 *eof = 1;
5159done: 5268done:
5160 *start = buf + (offset - begin); /* Start of wanted data */ 5269 *start = buf + (offset - begin); /* Start of wanted data */
5161 len -= (offset - begin); /* Start slop */ 5270 len -= (offset - begin); /* Start slop */
5162 if (len > length) 5271 if (len > length)
5163 len = length; /* Ending slop */ 5272 len = length; /* Ending slop */
5164 if (len < 0) 5273 if (len < 0)
5165 len = 0; 5274 len = 0;
5166 return len; 5275 return len;
5167} 5276}
5168 5277
5169/* The serial driver boot-time initialization code! 5278/* The serial driver boot-time initialization code!
@@ -5185,290 +5294,288 @@ done:
5185 */ 5294 */
5186 5295
5187static const struct tty_operations cy_ops = { 5296static const struct tty_operations cy_ops = {
5188 .open = cy_open, 5297 .open = cy_open,
5189 .close = cy_close, 5298 .close = cy_close,
5190 .write = cy_write, 5299 .write = cy_write,
5191 .put_char = cy_put_char, 5300 .put_char = cy_put_char,
5192 .flush_chars = cy_flush_chars, 5301 .flush_chars = cy_flush_chars,
5193 .write_room = cy_write_room, 5302 .write_room = cy_write_room,
5194 .chars_in_buffer = cy_chars_in_buffer, 5303 .chars_in_buffer = cy_chars_in_buffer,
5195 .flush_buffer = cy_flush_buffer, 5304 .flush_buffer = cy_flush_buffer,
5196 .ioctl = cy_ioctl, 5305 .ioctl = cy_ioctl,
5197 .throttle = cy_throttle, 5306 .throttle = cy_throttle,
5198 .unthrottle = cy_unthrottle, 5307 .unthrottle = cy_unthrottle,
5199 .set_termios = cy_set_termios, 5308 .set_termios = cy_set_termios,
5200 .stop = cy_stop, 5309 .stop = cy_stop,
5201 .start = cy_start, 5310 .start = cy_start,
5202 .hangup = cy_hangup, 5311 .hangup = cy_hangup,
5203 .break_ctl = cy_break, 5312 .break_ctl = cy_break,
5204 .wait_until_sent = cy_wait_until_sent, 5313 .wait_until_sent = cy_wait_until_sent,
5205 .read_proc = cyclades_get_proc_info, 5314 .read_proc = cyclades_get_proc_info,
5206 .tiocmget = cy_tiocmget, 5315 .tiocmget = cy_tiocmget,
5207 .tiocmset = cy_tiocmset, 5316 .tiocmset = cy_tiocmset,
5208}; 5317};
5209 5318
5210static int __init 5319static int __init cy_init(void)
5211cy_init(void)
5212{ 5320{
5213 struct cyclades_port *info; 5321 struct cyclades_port *info;
5214 struct cyclades_card *cinfo; 5322 struct cyclades_card *cinfo;
5215 int number_z_boards = 0; 5323 int number_z_boards = 0;
5216 int board,port,i,index; 5324 int board, port, i, index;
5217 unsigned long mailbox; 5325 unsigned long mailbox;
5218 unsigned short chip_number; 5326 unsigned short chip_number;
5219 int nports; 5327 int nports;
5220 5328
5221 cy_serial_driver = alloc_tty_driver(NR_PORTS); 5329 cy_serial_driver = alloc_tty_driver(NR_PORTS);
5222 if (!cy_serial_driver) 5330 if (!cy_serial_driver)
5223 return -ENOMEM; 5331 return -ENOMEM;
5224 show_version(); 5332 show_version();
5225 5333
5226 /* Initialize the tty_driver structure */ 5334 /* Initialize the tty_driver structure */
5227 5335
5228 cy_serial_driver->owner = THIS_MODULE; 5336 cy_serial_driver->owner = THIS_MODULE;
5229 cy_serial_driver->driver_name = "cyclades"; 5337 cy_serial_driver->driver_name = "cyclades";
5230 cy_serial_driver->name = "ttyC"; 5338 cy_serial_driver->name = "ttyC";
5231 cy_serial_driver->major = CYCLADES_MAJOR; 5339 cy_serial_driver->major = CYCLADES_MAJOR;
5232 cy_serial_driver->minor_start = 0; 5340 cy_serial_driver->minor_start = 0;
5233 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL; 5341 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5234 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL; 5342 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
5235 cy_serial_driver->init_termios = tty_std_termios; 5343 cy_serial_driver->init_termios = tty_std_termios;
5236 cy_serial_driver->init_termios.c_cflag = 5344 cy_serial_driver->init_termios.c_cflag =
5237 B9600 | CS8 | CREAD | HUPCL | CLOCAL; 5345 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5238 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW; 5346 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
5239 tty_set_operations(cy_serial_driver, &cy_ops); 5347 tty_set_operations(cy_serial_driver, &cy_ops);
5240 5348
5241 if (tty_register_driver(cy_serial_driver)) 5349 if (tty_register_driver(cy_serial_driver))
5242 panic("Couldn't register Cyclades serial driver\n"); 5350 panic("Couldn't register Cyclades serial driver\n");
5243 5351
5244 for (i = 0; i < NR_CARDS; i++) { 5352 for (i = 0; i < NR_CARDS; i++) {
5245 /* base_addr=0 indicates board not found */ 5353 /* base_addr=0 indicates board not found */
5246 cy_card[i].base_addr = NULL; 5354 cy_card[i].base_addr = NULL;
5247 } 5355 }
5248 5356
5249 /* the code below is responsible to find the boards. Each different 5357 /* the code below is responsible to find the boards. Each different
5250 type of board has its own detection routine. If a board is found, 5358 type of board has its own detection routine. If a board is found,
5251 the next cy_card structure available is set by the detection 5359 the next cy_card structure available is set by the detection
5252 routine. These functions are responsible for checking the 5360 routine. These functions are responsible for checking the
5253 availability of cy_card and cy_port data structures and updating 5361 availability of cy_card and cy_port data structures and updating
5254 the cy_next_channel. */ 5362 the cy_next_channel. */
5255 5363
5256 /* look for isa boards */ 5364 /* look for isa boards */
5257 cy_isa_nboard = cy_detect_isa(); 5365 cy_isa_nboard = cy_detect_isa();
5258 5366
5259 /* look for pci boards */ 5367 /* look for pci boards */
5260 cy_pci_nboard = cy_detect_pci(); 5368 cy_pci_nboard = cy_detect_pci();
5261 5369
5262 cy_nboard = cy_isa_nboard + cy_pci_nboard; 5370 cy_nboard = cy_isa_nboard + cy_pci_nboard;
5263 5371
5264 /* invalidate remaining cy_card structures */ 5372 /* invalidate remaining cy_card structures */
5265 for (i = 0 ; i < NR_CARDS ; i++) { 5373 for (i = 0; i < NR_CARDS; i++) {
5266 if (cy_card[i].base_addr == 0) { 5374 if (cy_card[i].base_addr == 0) {
5267 cy_card[i].first_line = -1; 5375 cy_card[i].first_line = -1;
5268 cy_card[i].ctl_addr = NULL; 5376 cy_card[i].ctl_addr = NULL;
5269 cy_card[i].irq = 0; 5377 cy_card[i].irq = 0;
5270 cy_card[i].bus_index = 0; 5378 cy_card[i].bus_index = 0;
5271 cy_card[i].first_line = 0; 5379 cy_card[i].first_line = 0;
5272 cy_card[i].num_chips = 0; 5380 cy_card[i].num_chips = 0;
5273 } 5381 }
5274 } 5382 }
5275 /* invalidate remaining cy_port structures */ 5383 /* invalidate remaining cy_port structures */
5276 for (i = cy_next_channel ; i < NR_PORTS ; i++) { 5384 for (i = cy_next_channel; i < NR_PORTS; i++) {
5277 cy_port[i].line = -1; 5385 cy_port[i].line = -1;
5278 cy_port[i].magic = -1; 5386 cy_port[i].magic = -1;
5279 } 5387 }
5280 5388
5281 /* initialize per-port data structures for each valid board found */ 5389 /* initialize per-port data structures for each valid board found */
5282 for (board = 0 ; board < cy_nboard ; board++) { 5390 for (board = 0; board < cy_nboard; board++) {
5283 cinfo = &cy_card[board]; 5391 cinfo = &cy_card[board];
5284 if (cinfo->num_chips == -1) { /* Cyclades-Z */ 5392 if (cinfo->num_chips == -1) { /* Cyclades-Z */
5285 number_z_boards++; 5393 number_z_boards++;
5286 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *) 5394 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
5287 cy_card[board].ctl_addr)->mail_box_0); 5395 cy_card[board].ctl_addr)->
5288 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8; 5396 mail_box_0);
5289 cinfo->intr_enabled = 0; 5397 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5290 cinfo->nports = 0; /* Will be correctly set later, after 5398 cinfo->intr_enabled = 0;
5291 Z FW is loaded */ 5399 cinfo->nports = 0; /* Will be correctly set later, after
5292 spin_lock_init(&cinfo->card_lock); 5400 Z FW is loaded */
5293 for (port = cinfo->first_line ; 5401 spin_lock_init(&cinfo->card_lock);
5294 port < cinfo->first_line + nports; 5402 for (port = cinfo->first_line;
5295 port++) 5403 port < cinfo->first_line + nports; port++) {
5296 { 5404 info = &cy_port[port];
5297 info = &cy_port[port]; 5405 info->magic = CYCLADES_MAGIC;
5298 info->magic = CYCLADES_MAGIC; 5406 info->type = PORT_STARTECH;
5299 info->type = PORT_STARTECH; 5407 info->card = board;
5300 info->card = board; 5408 info->line = port;
5301 info->line = port; 5409 info->chip_rev = 0;
5302 info->chip_rev = 0; 5410 info->flags = STD_COM_FLAGS;
5303 info->flags = STD_COM_FLAGS; 5411 info->tty = NULL;
5304 info->tty = NULL; 5412 if (mailbox == ZO_V1)
5305 if (mailbox == ZO_V1) 5413 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5306 info->xmit_fifo_size = CYZ_FIFO_SIZE; 5414 else
5307 else 5415 info->xmit_fifo_size =
5308 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE; 5416 4 * CYZ_FIFO_SIZE;
5309 info->cor1 = 0; 5417 info->cor1 = 0;
5310 info->cor2 = 0; 5418 info->cor2 = 0;
5311 info->cor3 = 0; 5419 info->cor3 = 0;
5312 info->cor4 = 0; 5420 info->cor4 = 0;
5313 info->cor5 = 0; 5421 info->cor5 = 0;
5314 info->tbpr = 0; 5422 info->tbpr = 0;
5315 info->tco = 0; 5423 info->tco = 0;
5316 info->rbpr = 0; 5424 info->rbpr = 0;
5317 info->rco = 0; 5425 info->rco = 0;
5318 info->custom_divisor = 0; 5426 info->custom_divisor = 0;
5319 info->close_delay = 5*HZ/10; 5427 info->close_delay = 5 * HZ / 10;
5320 info->closing_wait = CLOSING_WAIT_DELAY; 5428 info->closing_wait = CLOSING_WAIT_DELAY;
5321 info->icount.cts = info->icount.dsr = 5429 info->icount.cts = info->icount.dsr =
5322 info->icount.rng = info->icount.dcd = 0; 5430 info->icount.rng = info->icount.dcd = 0;
5323 info->icount.rx = info->icount.tx = 0; 5431 info->icount.rx = info->icount.tx = 0;
5324 info->icount.frame = info->icount.parity = 0; 5432 info->icount.frame = info->icount.parity = 0;
5325 info->icount.overrun = info->icount.brk = 0; 5433 info->icount.overrun = info->icount.brk = 0;
5326 info->x_char = 0; 5434 info->x_char = 0;
5327 info->event = 0; 5435 info->event = 0;
5328 info->count = 0; 5436 info->count = 0;
5329 info->blocked_open = 0; 5437 info->blocked_open = 0;
5330 info->default_threshold = 0; 5438 info->default_threshold = 0;
5331 info->default_timeout = 0; 5439 info->default_timeout = 0;
5332 INIT_WORK(&info->tqueue, do_softint); 5440 INIT_WORK(&info->tqueue, do_softint);
5333 init_waitqueue_head(&info->open_wait); 5441 init_waitqueue_head(&info->open_wait);
5334 init_waitqueue_head(&info->close_wait); 5442 init_waitqueue_head(&info->close_wait);
5335 init_waitqueue_head(&info->shutdown_wait); 5443 init_waitqueue_head(&info->shutdown_wait);
5336 init_waitqueue_head(&info->delta_msr_wait); 5444 init_waitqueue_head(&info->delta_msr_wait);
5337 /* info->session */ 5445 /* info->session */
5338 /* info->pgrp */ 5446 /* info->pgrp */
5339 info->read_status_mask = 0; 5447 info->read_status_mask = 0;
5340 /* info->timeout */ 5448 /* info->timeout */
5341 /* Bentson's vars */ 5449 /* Bentson's vars */
5342 info->jiffies[0] = 0; 5450 info->jiffies[0] = 0;
5343 info->jiffies[1] = 0; 5451 info->jiffies[1] = 0;
5344 info->jiffies[2] = 0; 5452 info->jiffies[2] = 0;
5345 info->rflush_count = 0; 5453 info->rflush_count = 0;
5346#ifdef CONFIG_CYZ_INTR 5454#ifdef CONFIG_CYZ_INTR
5347 init_timer(&cyz_rx_full_timer[port]); 5455 init_timer(&cyz_rx_full_timer[port]);
5348 cyz_rx_full_timer[port].function = NULL; 5456 cyz_rx_full_timer[port].function = NULL;
5349#endif 5457#endif
5350 } 5458 }
5351 continue; 5459 continue;
5352 }else{ /* Cyclom-Y of some kind*/ 5460 } else { /* Cyclom-Y of some kind */
5353 index = cinfo->bus_index; 5461 index = cinfo->bus_index;
5354 spin_lock_init(&cinfo->card_lock); 5462 spin_lock_init(&cinfo->card_lock);
5355 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips; 5463 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
5356 for (port = cinfo->first_line ; 5464 for (port = cinfo->first_line;
5357 port < cinfo->first_line + cinfo->nports ; 5465 port < cinfo->first_line + cinfo->nports; port++) {
5358 port++) 5466 info = &cy_port[port];
5359 { 5467 info->magic = CYCLADES_MAGIC;
5360 info = &cy_port[port]; 5468 info->type = PORT_CIRRUS;
5361 info->magic = CYCLADES_MAGIC; 5469 info->card = board;
5362 info->type = PORT_CIRRUS; 5470 info->line = port;
5363 info->card = board; 5471 info->flags = STD_COM_FLAGS;
5364 info->line = port; 5472 info->tty = NULL;
5365 info->flags = STD_COM_FLAGS; 5473 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5366 info->tty = NULL; 5474 info->cor1 =
5367 info->xmit_fifo_size = CyMAX_CHAR_FIFO; 5475 CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
5368 info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS; 5476 info->cor2 = CyETC;
5369 info->cor2 = CyETC; 5477 info->cor3 = 0x08; /* _very_ small rcv threshold */
5370 info->cor3 = 0x08; /* _very_ small rcv threshold */ 5478 info->cor4 = 0;
5371 info->cor4 = 0; 5479 info->cor5 = 0;
5372 info->cor5 = 0; 5480 info->custom_divisor = 0;
5373 info->custom_divisor = 0; 5481 info->close_delay = 5 * HZ / 10;
5374 info->close_delay = 5*HZ/10; 5482 info->closing_wait = CLOSING_WAIT_DELAY;
5375 info->closing_wait = CLOSING_WAIT_DELAY; 5483 info->icount.cts = info->icount.dsr =
5376 info->icount.cts = info->icount.dsr = 5484 info->icount.rng = info->icount.dcd = 0;
5377 info->icount.rng = info->icount.dcd = 0; 5485 info->icount.rx = info->icount.tx = 0;
5378 info->icount.rx = info->icount.tx = 0; 5486 info->icount.frame = info->icount.parity = 0;
5379 info->icount.frame = info->icount.parity = 0; 5487 info->icount.overrun = info->icount.brk = 0;
5380 info->icount.overrun = info->icount.brk = 0; 5488 chip_number = (port - cinfo->first_line) / 4;
5381 chip_number = (port - cinfo->first_line) / 4; 5489 if ((info->chip_rev =
5382 if ((info->chip_rev = 5490 cy_readb(cinfo->base_addr +
5383 cy_readb(cinfo->base_addr + 5491 (cy_chip_offset[chip_number] <<
5384 (cy_chip_offset[chip_number]<<index) + 5492 index) + (CyGFRCR << index))) >=
5385 (CyGFRCR<<index))) >= CD1400_REV_J) { 5493 CD1400_REV_J) {
5386 /* It is a CD1400 rev. J or later */ 5494 /* It is a CD1400 rev. J or later */
5387 info->tbpr = baud_bpr_60[13]; /* Tx BPR */ 5495 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5388 info->tco = baud_co_60[13]; /* Tx CO */ 5496 info->tco = baud_co_60[13]; /* Tx CO */
5389 info->rbpr = baud_bpr_60[13]; /* Rx BPR */ 5497 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5390 info->rco = baud_co_60[13]; /* Rx CO */ 5498 info->rco = baud_co_60[13]; /* Rx CO */
5391 info->rflow = 0; 5499 info->rflow = 0;
5392 info->rtsdtr_inv = 1; 5500 info->rtsdtr_inv = 1;
5393 } else { 5501 } else {
5394 info->tbpr = baud_bpr_25[13]; /* Tx BPR */ 5502 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5395 info->tco = baud_co_25[13]; /* Tx CO */ 5503 info->tco = baud_co_25[13]; /* Tx CO */
5396 info->rbpr = baud_bpr_25[13]; /* Rx BPR */ 5504 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5397 info->rco = baud_co_25[13]; /* Rx CO */ 5505 info->rco = baud_co_25[13]; /* Rx CO */
5398 info->rflow = 0; 5506 info->rflow = 0;
5399 info->rtsdtr_inv = 0; 5507 info->rtsdtr_inv = 0;
5400 } 5508 }
5401 info->x_char = 0; 5509 info->x_char = 0;
5402 info->event = 0; 5510 info->event = 0;
5403 info->count = 0; 5511 info->count = 0;
5404 info->blocked_open = 0; 5512 info->blocked_open = 0;
5405 info->default_threshold = 0; 5513 info->default_threshold = 0;
5406 info->default_timeout = 0; 5514 info->default_timeout = 0;
5407 INIT_WORK(&info->tqueue, do_softint); 5515 INIT_WORK(&info->tqueue, do_softint);
5408 init_waitqueue_head(&info->open_wait); 5516 init_waitqueue_head(&info->open_wait);
5409 init_waitqueue_head(&info->close_wait); 5517 init_waitqueue_head(&info->close_wait);
5410 init_waitqueue_head(&info->shutdown_wait); 5518 init_waitqueue_head(&info->shutdown_wait);
5411 init_waitqueue_head(&info->delta_msr_wait); 5519 init_waitqueue_head(&info->delta_msr_wait);
5412 /* info->session */ 5520 /* info->session */
5413 /* info->pgrp */ 5521 /* info->pgrp */
5414 info->read_status_mask = 5522 info->read_status_mask =
5415 CyTIMEOUT| CySPECHAR| CyBREAK 5523 CyTIMEOUT | CySPECHAR | CyBREAK
5416 | CyPARITY| CyFRAME| CyOVERRUN; 5524 | CyPARITY | CyFRAME | CyOVERRUN;
5417 /* info->timeout */ 5525 /* info->timeout */
5418 } 5526 }
5419 } 5527 }
5420 } 5528 }
5421 5529
5422#ifndef CONFIG_CYZ_INTR 5530#ifndef CONFIG_CYZ_INTR
5423 if (number_z_boards && !cyz_timeron){ 5531 if (number_z_boards && !cyz_timeron) {
5424 cyz_timeron++; 5532 cyz_timeron++;
5425 cyz_timerlist.expires = jiffies + 1; 5533 cyz_timerlist.expires = jiffies + 1;
5426 add_timer(&cyz_timerlist); 5534 add_timer(&cyz_timerlist);
5427#ifdef CY_PCI_DEBUG 5535#ifdef CY_PCI_DEBUG
5428 printk("Cyclades-Z polling initialized\n"); 5536 printk("Cyclades-Z polling initialized\n");
5429#endif 5537#endif
5430 } 5538 }
5431#endif /* CONFIG_CYZ_INTR */ 5539#endif /* CONFIG_CYZ_INTR */
5540
5541 return 0;
5432 5542
5433 return 0; 5543} /* cy_init */
5434
5435} /* cy_init */
5436 5544
5437static void __exit 5545static void __exit cy_cleanup_module(void)
5438cy_cleanup_module(void)
5439{ 5546{
5440 int i, e1; 5547 int i, e1;
5441 5548
5442#ifndef CONFIG_CYZ_INTR 5549#ifndef CONFIG_CYZ_INTR
5443 if (cyz_timeron){ 5550 if (cyz_timeron){
5444 cyz_timeron = 0; 5551 cyz_timeron = 0;
5445 del_timer(&cyz_timerlist); 5552 del_timer(&cyz_timerlist);
5446 } 5553 }
5447#endif /* CONFIG_CYZ_INTR */ 5554#endif /* CONFIG_CYZ_INTR */
5448 5555
5449 if ((e1 = tty_unregister_driver(cy_serial_driver))) 5556 if ((e1 = tty_unregister_driver(cy_serial_driver)))
5450 printk("cyc: failed to unregister Cyclades serial driver(%d)\n", 5557 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5451 e1); 5558 e1);
5452 5559
5453 put_tty_driver(cy_serial_driver); 5560 put_tty_driver(cy_serial_driver);
5454 5561
5455 for (i = 0; i < NR_CARDS; i++) { 5562 for (i = 0; i < NR_CARDS; i++) {
5456 if (cy_card[i].base_addr) { 5563 if (cy_card[i].base_addr) {
5457 iounmap(cy_card[i].base_addr); 5564 iounmap(cy_card[i].base_addr);
5458 if (cy_card[i].ctl_addr) 5565 if (cy_card[i].ctl_addr)
5459 iounmap(cy_card[i].ctl_addr); 5566 iounmap(cy_card[i].ctl_addr);
5460 if (cy_card[i].irq 5567 if (cy_card[i].irq
5461#ifndef CONFIG_CYZ_INTR 5568#ifndef CONFIG_CYZ_INTR
5462 && cy_card[i].num_chips != -1 /* not a Z card */ 5569 && cy_card[i].num_chips != -1 /* not a Z card */
5463#endif /* CONFIG_CYZ_INTR */ 5570#endif /* CONFIG_CYZ_INTR */
5464 ) 5571 )
5465 free_irq(cy_card[i].irq, &cy_card[i]); 5572 free_irq(cy_card[i].irq, &cy_card[i]);
5466#ifdef CONFIG_PCI 5573#ifdef CONFIG_PCI
5467 if (cy_card[i].pdev) 5574 if (cy_card[i].pdev)
5468 pci_release_regions(cy_card[i].pdev); 5575 pci_release_regions(cy_card[i].pdev);
5469#endif 5576#endif
5470 } 5577 }
5471 } 5578 }
5472} /* cy_cleanup_module */ 5579} /* cy_cleanup_module */
5473 5580
5474module_init(cy_init); 5581module_init(cy_init);