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