aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/char
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/char')
-rw-r--r--drivers/char/Kconfig24
-rw-r--r--drivers/char/Makefile2
-rw-r--r--drivers/char/agp/sgi-agp.c5
-rw-r--r--drivers/char/drm/drm_memory_debug.h2
-rw-r--r--drivers/char/drm/via_dmablit.c2
-rw-r--r--drivers/char/epca.c2
-rw-r--r--drivers/char/hvcs.c11
-rw-r--r--drivers/char/ipmi/ipmi_msghandler.c10
-rw-r--r--drivers/char/ipmi/ipmi_si_intf.c69
-rw-r--r--drivers/char/ipmi/ipmi_watchdog.c18
-rw-r--r--drivers/char/istallion.c1819
-rw-r--r--drivers/char/moxa.c2
-rw-r--r--drivers/char/mxser.c1
-rw-r--r--drivers/char/n_tty.c6
-rw-r--r--drivers/char/nsc_gpio.c142
-rw-r--r--drivers/char/pc8736x_gpio.c340
-rw-r--r--drivers/char/pty.c2
-rw-r--r--drivers/char/scx200_gpio.c162
-rw-r--r--drivers/char/specialix.c2
-rw-r--r--drivers/char/stallion.c211
-rw-r--r--drivers/char/sx.c2
-rw-r--r--drivers/char/tty_io.c75
-rw-r--r--drivers/char/vr41xx_giu.c4
-rw-r--r--drivers/char/watchdog/at91_wdt.c82
-rw-r--r--drivers/char/watchdog/i8xx_tco.c28
-rw-r--r--drivers/char/watchdog/pcwd_pci.c30
-rw-r--r--drivers/char/watchdog/pcwd_usb.c23
27 files changed, 1557 insertions, 1519 deletions
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index 3610c5729553..c40e487d9f5c 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -939,12 +939,36 @@ config MWAVE
939config SCx200_GPIO 939config SCx200_GPIO
940 tristate "NatSemi SCx200 GPIO Support" 940 tristate "NatSemi SCx200 GPIO Support"
941 depends on SCx200 941 depends on SCx200
942 select NSC_GPIO
942 help 943 help
943 Give userspace access to the GPIO pins on the National 944 Give userspace access to the GPIO pins on the National
944 Semiconductor SCx200 processors. 945 Semiconductor SCx200 processors.
945 946
946 If compiled as a module, it will be called scx200_gpio. 947 If compiled as a module, it will be called scx200_gpio.
947 948
949config PC8736x_GPIO
950 tristate "NatSemi PC8736x GPIO Support"
951 depends on X86
952 default SCx200_GPIO # mostly N
953 select NSC_GPIO # needed for support routines
954 help
955 Give userspace access to the GPIO pins on the National
956 Semiconductor PC-8736x (x=[03456]) SuperIO chip. The chip
957 has multiple functional units, inc several managed by
958 hwmon/pc87360 driver. Tested with PC-87366
959
960 If compiled as a module, it will be called pc8736x_gpio.
961
962config NSC_GPIO
963 tristate "NatSemi Base GPIO Support"
964 depends on X86_32
965 # selected by SCx200_GPIO and PC8736x_GPIO
966 # what about 2 selectors differing: m != y
967 help
968 Common support used (and needed) by scx200_gpio and
969 pc8736x_gpio drivers. If those drivers are built as
970 modules, this one will be too, named nsc_gpio
971
948config CS5535_GPIO 972config CS5535_GPIO
949 tristate "AMD CS5535/CS5536 GPIO (Geode Companion Device)" 973 tristate "AMD CS5535/CS5536 GPIO (Geode Companion Device)"
950 depends on X86_32 974 depends on X86_32
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 524105597ea7..6e0f4469d8bb 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -82,6 +82,8 @@ obj-$(CONFIG_PPDEV) += ppdev.o
82obj-$(CONFIG_NWBUTTON) += nwbutton.o 82obj-$(CONFIG_NWBUTTON) += nwbutton.o
83obj-$(CONFIG_NWFLASH) += nwflash.o 83obj-$(CONFIG_NWFLASH) += nwflash.o
84obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o 84obj-$(CONFIG_SCx200_GPIO) += scx200_gpio.o
85obj-$(CONFIG_PC8736x_GPIO) += pc8736x_gpio.o
86obj-$(CONFIG_NSC_GPIO) += nsc_gpio.o
85obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o 87obj-$(CONFIG_CS5535_GPIO) += cs5535_gpio.o
86obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o 88obj-$(CONFIG_GPIO_VR41XX) += vr41xx_giu.o
87obj-$(CONFIG_TANBAC_TB0219) += tb0219.o 89obj-$(CONFIG_TANBAC_TB0219) += tb0219.o
diff --git a/drivers/char/agp/sgi-agp.c b/drivers/char/agp/sgi-agp.c
index cfa7922cb431..d73be4c2db8a 100644
--- a/drivers/char/agp/sgi-agp.c
+++ b/drivers/char/agp/sgi-agp.c
@@ -329,9 +329,8 @@ static int __devinit agp_sgi_init(void)
329 329
330static void __devexit agp_sgi_cleanup(void) 330static void __devexit agp_sgi_cleanup(void)
331{ 331{
332 if (sgi_tioca_agp_bridges) 332 kfree(sgi_tioca_agp_bridges);
333 kfree(sgi_tioca_agp_bridges); 333 sgi_tioca_agp_bridges = NULL;
334 sgi_tioca_agp_bridges=NULL;
335} 334}
336 335
337module_init(agp_sgi_init); 336module_init(agp_sgi_init);
diff --git a/drivers/char/drm/drm_memory_debug.h b/drivers/char/drm/drm_memory_debug.h
index 6543b9a14c42..d117cc997192 100644
--- a/drivers/char/drm/drm_memory_debug.h
+++ b/drivers/char/drm/drm_memory_debug.h
@@ -43,7 +43,7 @@ typedef struct drm_mem_stats {
43 unsigned long bytes_freed; 43 unsigned long bytes_freed;
44} drm_mem_stats_t; 44} drm_mem_stats_t;
45 45
46static spinlock_t drm_mem_lock = SPIN_LOCK_UNLOCKED; 46static DEFINE_SPINLOCK(drm_mem_lock);
47static unsigned long drm_ram_available = 0; /* In pages */ 47static unsigned long drm_ram_available = 0; /* In pages */
48static unsigned long drm_ram_used = 0; 48static unsigned long drm_ram_used = 0;
49static drm_mem_stats_t drm_mem_stats[] = 49static drm_mem_stats_t drm_mem_stats[] =
diff --git a/drivers/char/drm/via_dmablit.c b/drivers/char/drm/via_dmablit.c
index b7f17457b424..78a81a4a99c5 100644
--- a/drivers/char/drm/via_dmablit.c
+++ b/drivers/char/drm/via_dmablit.c
@@ -557,7 +557,7 @@ via_init_dmablit(drm_device_t *dev)
557 blitq->num_outstanding = 0; 557 blitq->num_outstanding = 0;
558 blitq->is_active = 0; 558 blitq->is_active = 0;
559 blitq->aborting = 0; 559 blitq->aborting = 0;
560 blitq->blit_lock = SPIN_LOCK_UNLOCKED; 560 spin_lock_init(&blitq->blit_lock);
561 for (j=0; j<VIA_NUM_BLIT_SLOTS; ++j) { 561 for (j=0; j<VIA_NUM_BLIT_SLOTS; ++j) {
562 DRM_INIT_WAITQUEUE(blitq->blit_queue + j); 562 DRM_INIT_WAITQUEUE(blitq->blit_queue + j);
563 } 563 }
diff --git a/drivers/char/epca.c b/drivers/char/epca.c
index 9cad8501d62c..dc0602ae8503 100644
--- a/drivers/char/epca.c
+++ b/drivers/char/epca.c
@@ -80,7 +80,7 @@ static int invalid_lilo_config;
80/* The ISA boards do window flipping into the same spaces so its only sane 80/* The ISA boards do window flipping into the same spaces so its only sane
81 with a single lock. It's still pretty efficient */ 81 with a single lock. It's still pretty efficient */
82 82
83static spinlock_t epca_lock = SPIN_LOCK_UNLOCKED; 83static DEFINE_SPINLOCK(epca_lock);
84 84
85/* ----------------------------------------------------------------------- 85/* -----------------------------------------------------------------------
86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to 86 MAXBOARDS is typically 12, but ISA and EISA cards are restricted to
diff --git a/drivers/char/hvcs.c b/drivers/char/hvcs.c
index 8d97b3911293..afa26b65dac3 100644
--- a/drivers/char/hvcs.c
+++ b/drivers/char/hvcs.c
@@ -1320,11 +1320,12 @@ static struct tty_operations hvcs_ops = {
1320static int hvcs_alloc_index_list(int n) 1320static int hvcs_alloc_index_list(int n)
1321{ 1321{
1322 int i; 1322 int i;
1323
1323 hvcs_index_list = kmalloc(n * sizeof(hvcs_index_count),GFP_KERNEL); 1324 hvcs_index_list = kmalloc(n * sizeof(hvcs_index_count),GFP_KERNEL);
1324 if (!hvcs_index_list) 1325 if (!hvcs_index_list)
1325 return -ENOMEM; 1326 return -ENOMEM;
1326 hvcs_index_count = n; 1327 hvcs_index_count = n;
1327 for(i = 0; i < hvcs_index_count; i++) 1328 for (i = 0; i < hvcs_index_count; i++)
1328 hvcs_index_list[i] = -1; 1329 hvcs_index_list[i] = -1;
1329 return 0; 1330 return 0;
1330} 1331}
@@ -1332,11 +1333,9 @@ static int hvcs_alloc_index_list(int n)
1332static void hvcs_free_index_list(void) 1333static void hvcs_free_index_list(void)
1333{ 1334{
1334 /* Paranoia check to be thorough. */ 1335 /* Paranoia check to be thorough. */
1335 if (hvcs_index_list) { 1336 kfree(hvcs_index_list);
1336 kfree(hvcs_index_list); 1337 hvcs_index_list = NULL;
1337 hvcs_index_list = NULL; 1338 hvcs_index_count = 0;
1338 hvcs_index_count = 0;
1339 }
1340} 1339}
1341 1340
1342static int __init hvcs_module_init(void) 1341static int __init hvcs_module_init(void)
diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
index b03ddab1bef5..ad26f4b997c5 100644
--- a/drivers/char/ipmi/ipmi_msghandler.c
+++ b/drivers/char/ipmi/ipmi_msghandler.c
@@ -57,8 +57,7 @@ static int ipmi_init_msghandler(void);
57static int initialized = 0; 57static int initialized = 0;
58 58
59#ifdef CONFIG_PROC_FS 59#ifdef CONFIG_PROC_FS
60struct proc_dir_entry *proc_ipmi_root = NULL; 60static struct proc_dir_entry *proc_ipmi_root = NULL;
61EXPORT_SYMBOL(proc_ipmi_root);
62#endif /* CONFIG_PROC_FS */ 61#endif /* CONFIG_PROC_FS */
63 62
64#define MAX_EVENTS_IN_QUEUE 25 63#define MAX_EVENTS_IN_QUEUE 25
@@ -3739,11 +3738,8 @@ static int ipmi_init_msghandler(void)
3739 proc_ipmi_root->owner = THIS_MODULE; 3738 proc_ipmi_root->owner = THIS_MODULE;
3740#endif /* CONFIG_PROC_FS */ 3739#endif /* CONFIG_PROC_FS */
3741 3740
3742 init_timer(&ipmi_timer); 3741 setup_timer(&ipmi_timer, ipmi_timeout, 0);
3743 ipmi_timer.data = 0; 3742 mod_timer(&ipmi_timer, jiffies + IPMI_TIMEOUT_JIFFIES);
3744 ipmi_timer.function = ipmi_timeout;
3745 ipmi_timer.expires = jiffies + IPMI_TIMEOUT_JIFFIES;
3746 add_timer(&ipmi_timer);
3747 3743
3748 atomic_notifier_chain_register(&panic_notifier_list, &panic_block); 3744 atomic_notifier_chain_register(&panic_notifier_list, &panic_block);
3749 3745
diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
index 02a7dd7a8a55..bd4f2248b758 100644
--- a/drivers/char/ipmi/ipmi_si_intf.c
+++ b/drivers/char/ipmi/ipmi_si_intf.c
@@ -55,23 +55,6 @@
55#include <linux/mutex.h> 55#include <linux/mutex.h>
56#include <linux/kthread.h> 56#include <linux/kthread.h>
57#include <asm/irq.h> 57#include <asm/irq.h>
58#ifdef CONFIG_HIGH_RES_TIMERS
59#include <linux/hrtime.h>
60# if defined(schedule_next_int)
61/* Old high-res timer code, do translations. */
62# define get_arch_cycles(a) quick_update_jiffies_sub(a)
63# define arch_cycles_per_jiffy cycles_per_jiffies
64# endif
65static inline void add_usec_to_timer(struct timer_list *t, long v)
66{
67 t->arch_cycle_expires += nsec_to_arch_cycle(v * 1000);
68 while (t->arch_cycle_expires >= arch_cycles_per_jiffy)
69 {
70 t->expires++;
71 t->arch_cycle_expires -= arch_cycles_per_jiffy;
72 }
73}
74#endif
75#include <linux/interrupt.h> 58#include <linux/interrupt.h>
76#include <linux/rcupdate.h> 59#include <linux/rcupdate.h>
77#include <linux/ipmi_smi.h> 60#include <linux/ipmi_smi.h>
@@ -243,8 +226,6 @@ static int register_xaction_notifier(struct notifier_block * nb)
243 return atomic_notifier_chain_register(&xaction_notifier_list, nb); 226 return atomic_notifier_chain_register(&xaction_notifier_list, nb);
244} 227}
245 228
246static void si_restart_short_timer(struct smi_info *smi_info);
247
248static void deliver_recv_msg(struct smi_info *smi_info, 229static void deliver_recv_msg(struct smi_info *smi_info,
249 struct ipmi_smi_msg *msg) 230 struct ipmi_smi_msg *msg)
250{ 231{
@@ -768,7 +749,6 @@ static void sender(void *send_info,
768 && (smi_info->curr_msg == NULL)) 749 && (smi_info->curr_msg == NULL))
769 { 750 {
770 start_next_msg(smi_info); 751 start_next_msg(smi_info);
771 si_restart_short_timer(smi_info);
772 } 752 }
773 spin_unlock_irqrestore(&(smi_info->si_lock), flags); 753 spin_unlock_irqrestore(&(smi_info->si_lock), flags);
774} 754}
@@ -809,7 +789,7 @@ static int ipmi_thread(void *data)
809 /* do nothing */ 789 /* do nothing */
810 } 790 }
811 else if (smi_result == SI_SM_CALL_WITH_DELAY) 791 else if (smi_result == SI_SM_CALL_WITH_DELAY)
812 udelay(1); 792 schedule();
813 else 793 else
814 schedule_timeout_interruptible(1); 794 schedule_timeout_interruptible(1);
815 } 795 }
@@ -833,37 +813,6 @@ static void request_events(void *send_info)
833 813
834static int initialized = 0; 814static int initialized = 0;
835 815
836/* Must be called with interrupts off and with the si_lock held. */
837static void si_restart_short_timer(struct smi_info *smi_info)
838{
839#if defined(CONFIG_HIGH_RES_TIMERS)
840 unsigned long flags;
841 unsigned long jiffies_now;
842 unsigned long seq;
843
844 if (del_timer(&(smi_info->si_timer))) {
845 /* If we don't delete the timer, then it will go off
846 immediately, anyway. So we only process if we
847 actually delete the timer. */
848
849 do {
850 seq = read_seqbegin_irqsave(&xtime_lock, flags);
851 jiffies_now = jiffies;
852 smi_info->si_timer.expires = jiffies_now;
853 smi_info->si_timer.arch_cycle_expires
854 = get_arch_cycles(jiffies_now);
855 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
856
857 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
858
859 add_timer(&(smi_info->si_timer));
860 spin_lock_irqsave(&smi_info->count_lock, flags);
861 smi_info->timeout_restarts++;
862 spin_unlock_irqrestore(&smi_info->count_lock, flags);
863 }
864#endif
865}
866
867static void smi_timeout(unsigned long data) 816static void smi_timeout(unsigned long data)
868{ 817{
869 struct smi_info *smi_info = (struct smi_info *) data; 818 struct smi_info *smi_info = (struct smi_info *) data;
@@ -904,31 +853,15 @@ static void smi_timeout(unsigned long data)
904 /* If the state machine asks for a short delay, then shorten 853 /* If the state machine asks for a short delay, then shorten
905 the timer timeout. */ 854 the timer timeout. */
906 if (smi_result == SI_SM_CALL_WITH_DELAY) { 855 if (smi_result == SI_SM_CALL_WITH_DELAY) {
907#if defined(CONFIG_HIGH_RES_TIMERS)
908 unsigned long seq;
909#endif
910 spin_lock_irqsave(&smi_info->count_lock, flags); 856 spin_lock_irqsave(&smi_info->count_lock, flags);
911 smi_info->short_timeouts++; 857 smi_info->short_timeouts++;
912 spin_unlock_irqrestore(&smi_info->count_lock, flags); 858 spin_unlock_irqrestore(&smi_info->count_lock, flags);
913#if defined(CONFIG_HIGH_RES_TIMERS)
914 do {
915 seq = read_seqbegin_irqsave(&xtime_lock, flags);
916 smi_info->si_timer.expires = jiffies;
917 smi_info->si_timer.arch_cycle_expires
918 = get_arch_cycles(smi_info->si_timer.expires);
919 } while (read_seqretry_irqrestore(&xtime_lock, seq, flags));
920 add_usec_to_timer(&smi_info->si_timer, SI_SHORT_TIMEOUT_USEC);
921#else
922 smi_info->si_timer.expires = jiffies + 1; 859 smi_info->si_timer.expires = jiffies + 1;
923#endif
924 } else { 860 } else {
925 spin_lock_irqsave(&smi_info->count_lock, flags); 861 spin_lock_irqsave(&smi_info->count_lock, flags);
926 smi_info->long_timeouts++; 862 smi_info->long_timeouts++;
927 spin_unlock_irqrestore(&smi_info->count_lock, flags); 863 spin_unlock_irqrestore(&smi_info->count_lock, flags);
928 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES; 864 smi_info->si_timer.expires = jiffies + SI_TIMEOUT_JIFFIES;
929#if defined(CONFIG_HIGH_RES_TIMERS)
930 smi_info->si_timer.arch_cycle_expires = 0;
931#endif
932 } 865 }
933 866
934 do_add_timer: 867 do_add_timer:
diff --git a/drivers/char/ipmi/ipmi_watchdog.c b/drivers/char/ipmi/ipmi_watchdog.c
index 8f8867170973..1a0a19c53605 100644
--- a/drivers/char/ipmi/ipmi_watchdog.c
+++ b/drivers/char/ipmi/ipmi_watchdog.c
@@ -949,9 +949,10 @@ static int wdog_reboot_handler(struct notifier_block *this,
949 /* Disable the WDT if we are shutting down. */ 949 /* Disable the WDT if we are shutting down. */
950 ipmi_watchdog_state = WDOG_TIMEOUT_NONE; 950 ipmi_watchdog_state = WDOG_TIMEOUT_NONE;
951 panic_halt_ipmi_set_timeout(); 951 panic_halt_ipmi_set_timeout();
952 } else { 952 } else if (ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
953 /* Set a long timer to let the reboot happens, but 953 /* Set a long timer to let the reboot happens, but
954 reboot if it hangs. */ 954 reboot if it hangs, but only if the watchdog
955 timer was already running. */
955 timeout = 120; 956 timeout = 120;
956 pretimeout = 0; 957 pretimeout = 0;
957 ipmi_watchdog_state = WDOG_TIMEOUT_RESET; 958 ipmi_watchdog_state = WDOG_TIMEOUT_RESET;
@@ -973,16 +974,17 @@ static int wdog_panic_handler(struct notifier_block *this,
973{ 974{
974 static int panic_event_handled = 0; 975 static int panic_event_handled = 0;
975 976
976 /* On a panic, if we have a panic timeout, make sure that the thing 977 /* On a panic, if we have a panic timeout, make sure to extend
977 reboots, even if it hangs during that panic. */ 978 the watchdog timer to a reasonable value to complete the
978 if (watchdog_user && !panic_event_handled) { 979 panic, if the watchdog timer is running. Plus the
979 /* Make sure the panic doesn't hang, and make sure we 980 pretimeout is meaningless at panic time. */
980 do this only once. */ 981 if (watchdog_user && !panic_event_handled &&
982 ipmi_watchdog_state != WDOG_TIMEOUT_NONE) {
983 /* Make sure we do this only once. */
981 panic_event_handled = 1; 984 panic_event_handled = 1;
982 985
983 timeout = 255; 986 timeout = 255;
984 pretimeout = 0; 987 pretimeout = 0;
985 ipmi_watchdog_state = WDOG_TIMEOUT_RESET;
986 panic_halt_ipmi_set_timeout(); 988 panic_halt_ipmi_set_timeout();
987 } 989 }
988 990
diff --git a/drivers/char/istallion.c b/drivers/char/istallion.c
index ef20c1fc9c4c..216c79256de3 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -42,13 +42,12 @@
42#include <linux/devfs_fs_kernel.h> 42#include <linux/devfs_fs_kernel.h>
43#include <linux/device.h> 43#include <linux/device.h>
44#include <linux/wait.h> 44#include <linux/wait.h>
45#include <linux/eisa.h>
45 46
46#include <asm/io.h> 47#include <asm/io.h>
47#include <asm/uaccess.h> 48#include <asm/uaccess.h>
48 49
49#ifdef CONFIG_PCI
50#include <linux/pci.h> 50#include <linux/pci.h>
51#endif
52 51
53/*****************************************************************************/ 52/*****************************************************************************/
54 53
@@ -137,6 +136,10 @@ static stlconf_t stli_brdconf[] = {
137 136
138static int stli_nrbrds = ARRAY_SIZE(stli_brdconf); 137static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
139 138
139/* stli_lock must NOT be taken holding brd_lock */
140static spinlock_t stli_lock; /* TTY logic lock */
141static spinlock_t brd_lock; /* Board logic lock */
142
140/* 143/*
141 * There is some experimental EISA board detection code in this driver. 144 * There is some experimental EISA board detection code in this driver.
142 * By default it is disabled, but for those that want to try it out, 145 * By default it is disabled, but for those that want to try it out,
@@ -173,14 +176,6 @@ static char *stli_serialname = "ttyE";
173 176
174static struct tty_driver *stli_serial; 177static struct tty_driver *stli_serial;
175 178
176/*
177 * We will need to allocate a temporary write buffer for chars that
178 * come direct from user space. The problem is that a copy from user
179 * space might cause a page fault (typically on a system that is
180 * swapping!). All ports will share one buffer - since if the system
181 * is already swapping a shared buffer won't make things any worse.
182 */
183static char *stli_tmpwritebuf;
184 179
185#define STLI_TXBUFSIZE 4096 180#define STLI_TXBUFSIZE 4096
186 181
@@ -419,7 +414,7 @@ static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
419#endif 414#endif
420 415
421static struct pci_device_id istallion_pci_tbl[] = { 416static struct pci_device_id istallion_pci_tbl[] = {
422 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 417 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
423 { 0 } 418 { 0 }
424}; 419};
425MODULE_DEVICE_TABLE(pci, istallion_pci_tbl); 420MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
@@ -682,7 +677,7 @@ static int stli_startbrd(stlibrd_t *brdp);
682static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); 677static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
683static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); 678static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
684static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 679static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
685static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp); 680static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
686static void stli_poll(unsigned long arg); 681static void stli_poll(unsigned long arg);
687static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp); 682static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
688static int stli_initopen(stlibrd_t *brdp, stliport_t *portp); 683static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
@@ -693,7 +688,8 @@ static void stli_dohangup(void *arg);
693static int stli_setport(stliport_t *portp); 688static int stli_setport(stliport_t *portp);
694static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 689static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
695static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 690static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
696static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp); 691static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
692static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
697static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp); 693static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
698static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); 694static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
699static long stli_mktiocm(unsigned long sigvalue); 695static long stli_mktiocm(unsigned long sigvalue);
@@ -799,18 +795,8 @@ static struct class *istallion_class;
799 795
800static int __init istallion_module_init(void) 796static int __init istallion_module_init(void)
801{ 797{
802 unsigned long flags;
803
804#ifdef DEBUG
805 printk("init_module()\n");
806#endif
807
808 save_flags(flags);
809 cli();
810 stli_init(); 798 stli_init();
811 restore_flags(flags); 799 return 0;
812
813 return(0);
814} 800}
815 801
816/*****************************************************************************/ 802/*****************************************************************************/
@@ -819,33 +805,24 @@ static void __exit istallion_module_exit(void)
819{ 805{
820 stlibrd_t *brdp; 806 stlibrd_t *brdp;
821 stliport_t *portp; 807 stliport_t *portp;
822 unsigned long flags;
823 int i, j; 808 int i, j;
824 809
825#ifdef DEBUG
826 printk("cleanup_module()\n");
827#endif
828
829 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle, 810 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
830 stli_drvversion); 811 stli_drvversion);
831 812
832 save_flags(flags); 813 /*
833 cli(); 814 * Free up all allocated resources used by the ports. This includes
834 815 * memory and interrupts.
835/* 816 */
836 * Free up all allocated resources used by the ports. This includes
837 * memory and interrupts.
838 */
839 if (stli_timeron) { 817 if (stli_timeron) {
840 stli_timeron = 0; 818 stli_timeron = 0;
841 del_timer(&stli_timerlist); 819 del_timer_sync(&stli_timerlist);
842 } 820 }
843 821
844 i = tty_unregister_driver(stli_serial); 822 i = tty_unregister_driver(stli_serial);
845 if (i) { 823 if (i) {
846 printk("STALLION: failed to un-register tty driver, " 824 printk("STALLION: failed to un-register tty driver, "
847 "errno=%d\n", -i); 825 "errno=%d\n", -i);
848 restore_flags(flags);
849 return; 826 return;
850 } 827 }
851 put_tty_driver(stli_serial); 828 put_tty_driver(stli_serial);
@@ -859,16 +836,15 @@ static void __exit istallion_module_exit(void)
859 printk("STALLION: failed to un-register serial memory device, " 836 printk("STALLION: failed to un-register serial memory device, "
860 "errno=%d\n", -i); 837 "errno=%d\n", -i);
861 838
862 kfree(stli_tmpwritebuf);
863 kfree(stli_txcookbuf); 839 kfree(stli_txcookbuf);
864 840
865 for (i = 0; (i < stli_nrbrds); i++) { 841 for (i = 0; (i < stli_nrbrds); i++) {
866 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL) 842 if ((brdp = stli_brds[i]) == NULL)
867 continue; 843 continue;
868 for (j = 0; (j < STL_MAXPORTS); j++) { 844 for (j = 0; (j < STL_MAXPORTS); j++) {
869 portp = brdp->ports[j]; 845 portp = brdp->ports[j];
870 if (portp != (stliport_t *) NULL) { 846 if (portp != NULL) {
871 if (portp->tty != (struct tty_struct *) NULL) 847 if (portp->tty != NULL)
872 tty_hangup(portp->tty); 848 tty_hangup(portp->tty);
873 kfree(portp); 849 kfree(portp);
874 } 850 }
@@ -878,10 +854,8 @@ static void __exit istallion_module_exit(void)
878 if (brdp->iosize > 0) 854 if (brdp->iosize > 0)
879 release_region(brdp->iobase, brdp->iosize); 855 release_region(brdp->iobase, brdp->iosize);
880 kfree(brdp); 856 kfree(brdp);
881 stli_brds[i] = (stlibrd_t *) NULL; 857 stli_brds[i] = NULL;
882 } 858 }
883
884 restore_flags(flags);
885} 859}
886 860
887module_init(istallion_module_init); 861module_init(istallion_module_init);
@@ -895,19 +869,15 @@ module_exit(istallion_module_exit);
895 869
896static void stli_argbrds(void) 870static void stli_argbrds(void)
897{ 871{
898 stlconf_t conf; 872 stlconf_t conf;
899 stlibrd_t *brdp; 873 stlibrd_t *brdp;
900 int i; 874 int i;
901
902#ifdef DEBUG
903 printk("stli_argbrds()\n");
904#endif
905 875
906 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) { 876 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
907 memset(&conf, 0, sizeof(conf)); 877 memset(&conf, 0, sizeof(conf));
908 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0) 878 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
909 continue; 879 continue;
910 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 880 if ((brdp = stli_allocbrd()) == NULL)
911 continue; 881 continue;
912 stli_nrbrds = i + 1; 882 stli_nrbrds = i + 1;
913 brdp->brdnr = i; 883 brdp->brdnr = i;
@@ -926,9 +896,9 @@ static void stli_argbrds(void)
926 896
927static unsigned long stli_atol(char *str) 897static unsigned long stli_atol(char *str)
928{ 898{
929 unsigned long val; 899 unsigned long val;
930 int base, c; 900 int base, c;
931 char *sp; 901 char *sp;
932 902
933 val = 0; 903 val = 0;
934 sp = str; 904 sp = str;
@@ -962,15 +932,11 @@ static unsigned long stli_atol(char *str)
962 932
963static int stli_parsebrd(stlconf_t *confp, char **argp) 933static int stli_parsebrd(stlconf_t *confp, char **argp)
964{ 934{
965 char *sp; 935 char *sp;
966 int i; 936 int i;
967
968#ifdef DEBUG
969 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
970#endif
971 937
972 if ((argp[0] == (char *) NULL) || (*argp[0] == 0)) 938 if (argp[0] == NULL || *argp[0] == 0)
973 return(0); 939 return 0;
974 940
975 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 941 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
976 *sp = TOLOWER(*sp); 942 *sp = TOLOWER(*sp);
@@ -985,9 +951,9 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
985 } 951 }
986 952
987 confp->brdtype = stli_brdstr[i].type; 953 confp->brdtype = stli_brdstr[i].type;
988 if ((argp[1] != (char *) NULL) && (*argp[1] != 0)) 954 if (argp[1] != NULL && *argp[1] != 0)
989 confp->ioaddr1 = stli_atol(argp[1]); 955 confp->ioaddr1 = stli_atol(argp[1]);
990 if ((argp[2] != (char *) NULL) && (*argp[2] != 0)) 956 if (argp[2] != NULL && *argp[2] != 0)
991 confp->memaddr = stli_atol(argp[2]); 957 confp->memaddr = stli_atol(argp[2]);
992 return(1); 958 return(1);
993} 959}
@@ -998,34 +964,29 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
998 964
999static int stli_open(struct tty_struct *tty, struct file *filp) 965static int stli_open(struct tty_struct *tty, struct file *filp)
1000{ 966{
1001 stlibrd_t *brdp; 967 stlibrd_t *brdp;
1002 stliport_t *portp; 968 stliport_t *portp;
1003 unsigned int minordev; 969 unsigned int minordev;
1004 int brdnr, portnr, rc; 970 int brdnr, portnr, rc;
1005
1006#ifdef DEBUG
1007 printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1008 (int) filp, tty->name);
1009#endif
1010 971
1011 minordev = tty->index; 972 minordev = tty->index;
1012 brdnr = MINOR2BRD(minordev); 973 brdnr = MINOR2BRD(minordev);
1013 if (brdnr >= stli_nrbrds) 974 if (brdnr >= stli_nrbrds)
1014 return(-ENODEV); 975 return -ENODEV;
1015 brdp = stli_brds[brdnr]; 976 brdp = stli_brds[brdnr];
1016 if (brdp == (stlibrd_t *) NULL) 977 if (brdp == NULL)
1017 return(-ENODEV); 978 return -ENODEV;
1018 if ((brdp->state & BST_STARTED) == 0) 979 if ((brdp->state & BST_STARTED) == 0)
1019 return(-ENODEV); 980 return -ENODEV;
1020 portnr = MINOR2PORT(minordev); 981 portnr = MINOR2PORT(minordev);
1021 if ((portnr < 0) || (portnr > brdp->nrports)) 982 if ((portnr < 0) || (portnr > brdp->nrports))
1022 return(-ENODEV); 983 return -ENODEV;
1023 984
1024 portp = brdp->ports[portnr]; 985 portp = brdp->ports[portnr];
1025 if (portp == (stliport_t *) NULL) 986 if (portp == NULL)
1026 return(-ENODEV); 987 return -ENODEV;
1027 if (portp->devnr < 1) 988 if (portp->devnr < 1)
1028 return(-ENODEV); 989 return -ENODEV;
1029 990
1030 991
1031/* 992/*
@@ -1037,8 +998,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1037 if (portp->flags & ASYNC_CLOSING) { 998 if (portp->flags & ASYNC_CLOSING) {
1038 interruptible_sleep_on(&portp->close_wait); 999 interruptible_sleep_on(&portp->close_wait);
1039 if (portp->flags & ASYNC_HUP_NOTIFY) 1000 if (portp->flags & ASYNC_HUP_NOTIFY)
1040 return(-EAGAIN); 1001 return -EAGAIN;
1041 return(-ERESTARTSYS); 1002 return -ERESTARTSYS;
1042 } 1003 }
1043 1004
1044/* 1005/*
@@ -1054,7 +1015,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1054 wait_event_interruptible(portp->raw_wait, 1015 wait_event_interruptible(portp->raw_wait,
1055 !test_bit(ST_INITIALIZING, &portp->state)); 1016 !test_bit(ST_INITIALIZING, &portp->state));
1056 if (signal_pending(current)) 1017 if (signal_pending(current))
1057 return(-ERESTARTSYS); 1018 return -ERESTARTSYS;
1058 1019
1059 if ((portp->flags & ASYNC_INITIALIZED) == 0) { 1020 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1060 set_bit(ST_INITIALIZING, &portp->state); 1021 set_bit(ST_INITIALIZING, &portp->state);
@@ -1065,7 +1026,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1065 clear_bit(ST_INITIALIZING, &portp->state); 1026 clear_bit(ST_INITIALIZING, &portp->state);
1066 wake_up_interruptible(&portp->raw_wait); 1027 wake_up_interruptible(&portp->raw_wait);
1067 if (rc < 0) 1028 if (rc < 0)
1068 return(rc); 1029 return rc;
1069 } 1030 }
1070 1031
1071/* 1032/*
@@ -1077,8 +1038,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1077 if (portp->flags & ASYNC_CLOSING) { 1038 if (portp->flags & ASYNC_CLOSING) {
1078 interruptible_sleep_on(&portp->close_wait); 1039 interruptible_sleep_on(&portp->close_wait);
1079 if (portp->flags & ASYNC_HUP_NOTIFY) 1040 if (portp->flags & ASYNC_HUP_NOTIFY)
1080 return(-EAGAIN); 1041 return -EAGAIN;
1081 return(-ERESTARTSYS); 1042 return -ERESTARTSYS;
1082 } 1043 }
1083 1044
1084/* 1045/*
@@ -1088,38 +1049,33 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1088 */ 1049 */
1089 if (!(filp->f_flags & O_NONBLOCK)) { 1050 if (!(filp->f_flags & O_NONBLOCK)) {
1090 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0) 1051 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1091 return(rc); 1052 return rc;
1092 } 1053 }
1093 portp->flags |= ASYNC_NORMAL_ACTIVE; 1054 portp->flags |= ASYNC_NORMAL_ACTIVE;
1094 return(0); 1055 return 0;
1095} 1056}
1096 1057
1097/*****************************************************************************/ 1058/*****************************************************************************/
1098 1059
1099static void stli_close(struct tty_struct *tty, struct file *filp) 1060static void stli_close(struct tty_struct *tty, struct file *filp)
1100{ 1061{
1101 stlibrd_t *brdp; 1062 stlibrd_t *brdp;
1102 stliport_t *portp; 1063 stliport_t *portp;
1103 unsigned long flags; 1064 unsigned long flags;
1104
1105#ifdef DEBUG
1106 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1107#endif
1108 1065
1109 portp = tty->driver_data; 1066 portp = tty->driver_data;
1110 if (portp == (stliport_t *) NULL) 1067 if (portp == NULL)
1111 return; 1068 return;
1112 1069
1113 save_flags(flags); 1070 spin_lock_irqsave(&stli_lock, flags);
1114 cli();
1115 if (tty_hung_up_p(filp)) { 1071 if (tty_hung_up_p(filp)) {
1116 restore_flags(flags); 1072 spin_unlock_irqrestore(&stli_lock, flags);
1117 return; 1073 return;
1118 } 1074 }
1119 if ((tty->count == 1) && (portp->refcount != 1)) 1075 if ((tty->count == 1) && (portp->refcount != 1))
1120 portp->refcount = 1; 1076 portp->refcount = 1;
1121 if (portp->refcount-- > 1) { 1077 if (portp->refcount-- > 1) {
1122 restore_flags(flags); 1078 spin_unlock_irqrestore(&stli_lock, flags);
1123 return; 1079 return;
1124 } 1080 }
1125 1081
@@ -1134,6 +1090,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1134 if (tty == stli_txcooktty) 1090 if (tty == stli_txcooktty)
1135 stli_flushchars(tty); 1091 stli_flushchars(tty);
1136 tty->closing = 1; 1092 tty->closing = 1;
1093 spin_unlock_irqrestore(&stli_lock, flags);
1094
1137 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1095 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1138 tty_wait_until_sent(tty, portp->closing_wait); 1096 tty_wait_until_sent(tty, portp->closing_wait);
1139 1097
@@ -1157,7 +1115,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1157 stli_flushbuffer(tty); 1115 stli_flushbuffer(tty);
1158 1116
1159 tty->closing = 0; 1117 tty->closing = 0;
1160 portp->tty = (struct tty_struct *) NULL; 1118 portp->tty = NULL;
1161 1119
1162 if (portp->openwaitcnt) { 1120 if (portp->openwaitcnt) {
1163 if (portp->close_delay) 1121 if (portp->close_delay)
@@ -1167,7 +1125,6 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1167 1125
1168 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1126 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1169 wake_up_interruptible(&portp->close_wait); 1127 wake_up_interruptible(&portp->close_wait);
1170 restore_flags(flags);
1171} 1128}
1172 1129
1173/*****************************************************************************/ 1130/*****************************************************************************/
@@ -1182,45 +1139,41 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1182 1139
1183static int stli_initopen(stlibrd_t *brdp, stliport_t *portp) 1140static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1184{ 1141{
1185 struct tty_struct *tty; 1142 struct tty_struct *tty;
1186 asynotify_t nt; 1143 asynotify_t nt;
1187 asyport_t aport; 1144 asyport_t aport;
1188 int rc; 1145 int rc;
1189
1190#ifdef DEBUG
1191 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1192#endif
1193 1146
1194 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0) 1147 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1195 return(rc); 1148 return rc;
1196 1149
1197 memset(&nt, 0, sizeof(asynotify_t)); 1150 memset(&nt, 0, sizeof(asynotify_t));
1198 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK); 1151 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1199 nt.signal = SG_DCD; 1152 nt.signal = SG_DCD;
1200 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt, 1153 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1201 sizeof(asynotify_t), 0)) < 0) 1154 sizeof(asynotify_t), 0)) < 0)
1202 return(rc); 1155 return rc;
1203 1156
1204 tty = portp->tty; 1157 tty = portp->tty;
1205 if (tty == (struct tty_struct *) NULL) 1158 if (tty == NULL)
1206 return(-ENODEV); 1159 return -ENODEV;
1207 stli_mkasyport(portp, &aport, tty->termios); 1160 stli_mkasyport(portp, &aport, tty->termios);
1208 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, 1161 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1209 sizeof(asyport_t), 0)) < 0) 1162 sizeof(asyport_t), 0)) < 0)
1210 return(rc); 1163 return rc;
1211 1164
1212 set_bit(ST_GETSIGS, &portp->state); 1165 set_bit(ST_GETSIGS, &portp->state);
1213 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, 1166 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1214 sizeof(asysigs_t), 1)) < 0) 1167 sizeof(asysigs_t), 1)) < 0)
1215 return(rc); 1168 return rc;
1216 if (test_and_clear_bit(ST_GETSIGS, &portp->state)) 1169 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1217 portp->sigs = stli_mktiocm(portp->asig.sigvalue); 1170 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1218 stli_mkasysigs(&portp->asig, 1, 1); 1171 stli_mkasysigs(&portp->asig, 1, 1);
1219 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, 1172 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1220 sizeof(asysigs_t), 0)) < 0) 1173 sizeof(asysigs_t), 0)) < 0)
1221 return(rc); 1174 return rc;
1222 1175
1223 return(0); 1176 return 0;
1224} 1177}
1225 1178
1226/*****************************************************************************/ 1179/*****************************************************************************/
@@ -1234,22 +1187,15 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1234 1187
1235static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1188static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1236{ 1189{
1237 volatile cdkhdr_t *hdrp; 1190 cdkhdr_t __iomem *hdrp;
1238 volatile cdkctrl_t *cp; 1191 cdkctrl_t __iomem *cp;
1239 volatile unsigned char *bits; 1192 unsigned char __iomem *bits;
1240 unsigned long flags; 1193 unsigned long flags;
1241 int rc; 1194 int rc;
1242
1243#ifdef DEBUG
1244 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1245 (int) brdp, (int) portp, (int) arg, wait);
1246#endif
1247 1195
1248/* 1196/*
1249 * Send a message to the slave to open this port. 1197 * Send a message to the slave to open this port.
1250 */ 1198 */
1251 save_flags(flags);
1252 cli();
1253 1199
1254/* 1200/*
1255 * Slave is already closing this port. This can happen if a hangup 1201 * Slave is already closing this port. This can happen if a hangup
@@ -1260,7 +1206,6 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1260 wait_event_interruptible(portp->raw_wait, 1206 wait_event_interruptible(portp->raw_wait,
1261 !test_bit(ST_CLOSING, &portp->state)); 1207 !test_bit(ST_CLOSING, &portp->state));
1262 if (signal_pending(current)) { 1208 if (signal_pending(current)) {
1263 restore_flags(flags);
1264 return -ERESTARTSYS; 1209 return -ERESTARTSYS;
1265 } 1210 }
1266 1211
@@ -1269,19 +1214,20 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1269 * memory. Once the message is in set the service bits to say that 1214 * memory. Once the message is in set the service bits to say that
1270 * this port wants service. 1215 * this port wants service.
1271 */ 1216 */
1217 spin_lock_irqsave(&brd_lock, flags);
1272 EBRDENABLE(brdp); 1218 EBRDENABLE(brdp);
1273 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 1219 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1274 cp->openarg = arg; 1220 writel(arg, &cp->openarg);
1275 cp->open = 1; 1221 writeb(1, &cp->open);
1276 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1222 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1277 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1223 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1278 portp->portidx; 1224 portp->portidx;
1279 *bits |= portp->portbit; 1225 writeb(readb(bits) | portp->portbit, bits);
1280 EBRDDISABLE(brdp); 1226 EBRDDISABLE(brdp);
1281 1227
1282 if (wait == 0) { 1228 if (wait == 0) {
1283 restore_flags(flags); 1229 spin_unlock_irqrestore(&brd_lock, flags);
1284 return(0); 1230 return 0;
1285 } 1231 }
1286 1232
1287/* 1233/*
@@ -1290,15 +1236,16 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1290 */ 1236 */
1291 rc = 0; 1237 rc = 0;
1292 set_bit(ST_OPENING, &portp->state); 1238 set_bit(ST_OPENING, &portp->state);
1239 spin_unlock_irqrestore(&brd_lock, flags);
1240
1293 wait_event_interruptible(portp->raw_wait, 1241 wait_event_interruptible(portp->raw_wait,
1294 !test_bit(ST_OPENING, &portp->state)); 1242 !test_bit(ST_OPENING, &portp->state));
1295 if (signal_pending(current)) 1243 if (signal_pending(current))
1296 rc = -ERESTARTSYS; 1244 rc = -ERESTARTSYS;
1297 restore_flags(flags);
1298 1245
1299 if ((rc == 0) && (portp->rc != 0)) 1246 if ((rc == 0) && (portp->rc != 0))
1300 rc = -EIO; 1247 rc = -EIO;
1301 return(rc); 1248 return rc;
1302} 1249}
1303 1250
1304/*****************************************************************************/ 1251/*****************************************************************************/
@@ -1311,19 +1258,11 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1311 1258
1312static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1259static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1313{ 1260{
1314 volatile cdkhdr_t *hdrp; 1261 cdkhdr_t __iomem *hdrp;
1315 volatile cdkctrl_t *cp; 1262 cdkctrl_t __iomem *cp;
1316 volatile unsigned char *bits; 1263 unsigned char __iomem *bits;
1317 unsigned long flags; 1264 unsigned long flags;
1318 int rc; 1265 int rc;
1319
1320#ifdef DEBUG
1321 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1322 (int) brdp, (int) portp, (int) arg, wait);
1323#endif
1324
1325 save_flags(flags);
1326 cli();
1327 1266
1328/* 1267/*
1329 * Slave is already closing this port. This can happen if a hangup 1268 * Slave is already closing this port. This can happen if a hangup
@@ -1333,7 +1272,6 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1333 wait_event_interruptible(portp->raw_wait, 1272 wait_event_interruptible(portp->raw_wait,
1334 !test_bit(ST_CLOSING, &portp->state)); 1273 !test_bit(ST_CLOSING, &portp->state));
1335 if (signal_pending(current)) { 1274 if (signal_pending(current)) {
1336 restore_flags(flags);
1337 return -ERESTARTSYS; 1275 return -ERESTARTSYS;
1338 } 1276 }
1339 } 1277 }
@@ -1341,21 +1279,22 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1341/* 1279/*
1342 * Write the close command into shared memory. 1280 * Write the close command into shared memory.
1343 */ 1281 */
1282 spin_lock_irqsave(&brd_lock, flags);
1344 EBRDENABLE(brdp); 1283 EBRDENABLE(brdp);
1345 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 1284 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1346 cp->closearg = arg; 1285 writel(arg, &cp->closearg);
1347 cp->close = 1; 1286 writeb(1, &cp->close);
1348 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1287 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1349 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1288 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1350 portp->portidx; 1289 portp->portidx;
1351 *bits |= portp->portbit; 1290 writeb(readb(bits) |portp->portbit, bits);
1352 EBRDDISABLE(brdp); 1291 EBRDDISABLE(brdp);
1353 1292
1354 set_bit(ST_CLOSING, &portp->state); 1293 set_bit(ST_CLOSING, &portp->state);
1355 if (wait == 0) { 1294 spin_unlock_irqrestore(&brd_lock, flags);
1356 restore_flags(flags); 1295
1357 return(0); 1296 if (wait == 0)
1358 } 1297 return 0;
1359 1298
1360/* 1299/*
1361 * Slave is in action, so now we must wait for the open acknowledgment 1300 * Slave is in action, so now we must wait for the open acknowledgment
@@ -1366,11 +1305,10 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1366 !test_bit(ST_CLOSING, &portp->state)); 1305 !test_bit(ST_CLOSING, &portp->state));
1367 if (signal_pending(current)) 1306 if (signal_pending(current))
1368 rc = -ERESTARTSYS; 1307 rc = -ERESTARTSYS;
1369 restore_flags(flags);
1370 1308
1371 if ((rc == 0) && (portp->rc != 0)) 1309 if ((rc == 0) && (portp->rc != 0))
1372 rc = -EIO; 1310 rc = -EIO;
1373 return(rc); 1311 return rc;
1374} 1312}
1375 1313
1376/*****************************************************************************/ 1314/*****************************************************************************/
@@ -1384,36 +1322,21 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1384 1322
1385static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 1323static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1386{ 1324{
1387 unsigned long flags;
1388
1389#ifdef DEBUG
1390 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1391 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1392 (int) arg, size, copyback);
1393#endif
1394
1395 save_flags(flags);
1396 cli();
1397 wait_event_interruptible(portp->raw_wait, 1325 wait_event_interruptible(portp->raw_wait,
1398 !test_bit(ST_CMDING, &portp->state)); 1326 !test_bit(ST_CMDING, &portp->state));
1399 if (signal_pending(current)) { 1327 if (signal_pending(current))
1400 restore_flags(flags);
1401 return -ERESTARTSYS; 1328 return -ERESTARTSYS;
1402 }
1403 1329
1404 stli_sendcmd(brdp, portp, cmd, arg, size, copyback); 1330 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1405 1331
1406 wait_event_interruptible(portp->raw_wait, 1332 wait_event_interruptible(portp->raw_wait,
1407 !test_bit(ST_CMDING, &portp->state)); 1333 !test_bit(ST_CMDING, &portp->state));
1408 if (signal_pending(current)) { 1334 if (signal_pending(current))
1409 restore_flags(flags);
1410 return -ERESTARTSYS; 1335 return -ERESTARTSYS;
1411 }
1412 restore_flags(flags);
1413 1336
1414 if (portp->rc != 0) 1337 if (portp->rc != 0)
1415 return(-EIO); 1338 return -EIO;
1416 return(0); 1339 return 0;
1417} 1340}
1418 1341
1419/*****************************************************************************/ 1342/*****************************************************************************/
@@ -1425,22 +1348,18 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
1425 1348
1426static int stli_setport(stliport_t *portp) 1349static int stli_setport(stliport_t *portp)
1427{ 1350{
1428 stlibrd_t *brdp; 1351 stlibrd_t *brdp;
1429 asyport_t aport; 1352 asyport_t aport;
1430
1431#ifdef DEBUG
1432 printk("stli_setport(portp=%x)\n", (int) portp);
1433#endif
1434 1353
1435 if (portp == (stliport_t *) NULL) 1354 if (portp == NULL)
1436 return(-ENODEV); 1355 return -ENODEV;
1437 if (portp->tty == (struct tty_struct *) NULL) 1356 if (portp->tty == NULL)
1438 return(-ENODEV); 1357 return -ENODEV;
1439 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds)) 1358 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1440 return(-ENODEV); 1359 return -ENODEV;
1441 brdp = stli_brds[portp->brdnr]; 1360 brdp = stli_brds[portp->brdnr];
1442 if (brdp == (stlibrd_t *) NULL) 1361 if (brdp == NULL)
1443 return(-ENODEV); 1362 return -ENODEV;
1444 1363
1445 stli_mkasyport(portp, &aport, portp->tty->termios); 1364 stli_mkasyport(portp, &aport, portp->tty->termios);
1446 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0)); 1365 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
@@ -1455,13 +1374,8 @@ static int stli_setport(stliport_t *portp)
1455 1374
1456static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp) 1375static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1457{ 1376{
1458 unsigned long flags; 1377 unsigned long flags;
1459 int rc, doclocal; 1378 int rc, doclocal;
1460
1461#ifdef DEBUG
1462 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1463 (int) brdp, (int) portp, (int) filp);
1464#endif
1465 1379
1466 rc = 0; 1380 rc = 0;
1467 doclocal = 0; 1381 doclocal = 0;
@@ -1469,11 +1383,11 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1469 if (portp->tty->termios->c_cflag & CLOCAL) 1383 if (portp->tty->termios->c_cflag & CLOCAL)
1470 doclocal++; 1384 doclocal++;
1471 1385
1472 save_flags(flags); 1386 spin_lock_irqsave(&stli_lock, flags);
1473 cli();
1474 portp->openwaitcnt++; 1387 portp->openwaitcnt++;
1475 if (! tty_hung_up_p(filp)) 1388 if (! tty_hung_up_p(filp))
1476 portp->refcount--; 1389 portp->refcount--;
1390 spin_unlock_irqrestore(&stli_lock, flags);
1477 1391
1478 for (;;) { 1392 for (;;) {
1479 stli_mkasysigs(&portp->asig, 1, 1); 1393 stli_mkasysigs(&portp->asig, 1, 1);
@@ -1499,12 +1413,13 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1499 interruptible_sleep_on(&portp->open_wait); 1413 interruptible_sleep_on(&portp->open_wait);
1500 } 1414 }
1501 1415
1416 spin_lock_irqsave(&stli_lock, flags);
1502 if (! tty_hung_up_p(filp)) 1417 if (! tty_hung_up_p(filp))
1503 portp->refcount++; 1418 portp->refcount++;
1504 portp->openwaitcnt--; 1419 portp->openwaitcnt--;
1505 restore_flags(flags); 1420 spin_unlock_irqrestore(&stli_lock, flags);
1506 1421
1507 return(rc); 1422 return rc;
1508} 1423}
1509 1424
1510/*****************************************************************************/ 1425/*****************************************************************************/
@@ -1517,46 +1432,38 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1517 1432
1518static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count) 1433static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1519{ 1434{
1520 volatile cdkasy_t *ap; 1435 cdkasy_t __iomem *ap;
1521 volatile cdkhdr_t *hdrp; 1436 cdkhdr_t __iomem *hdrp;
1522 volatile unsigned char *bits; 1437 unsigned char __iomem *bits;
1523 unsigned char *shbuf, *chbuf; 1438 unsigned char __iomem *shbuf;
1524 stliport_t *portp; 1439 unsigned char *chbuf;
1525 stlibrd_t *brdp; 1440 stliport_t *portp;
1526 unsigned int len, stlen, head, tail, size; 1441 stlibrd_t *brdp;
1527 unsigned long flags; 1442 unsigned int len, stlen, head, tail, size;
1528 1443 unsigned long flags;
1529#ifdef DEBUG
1530 printk("stli_write(tty=%x,buf=%x,count=%d)\n",
1531 (int) tty, (int) buf, count);
1532#endif
1533 1444
1534 if ((tty == (struct tty_struct *) NULL) ||
1535 (stli_tmpwritebuf == (char *) NULL))
1536 return(0);
1537 if (tty == stli_txcooktty) 1445 if (tty == stli_txcooktty)
1538 stli_flushchars(tty); 1446 stli_flushchars(tty);
1539 portp = tty->driver_data; 1447 portp = tty->driver_data;
1540 if (portp == (stliport_t *) NULL) 1448 if (portp == NULL)
1541 return(0); 1449 return 0;
1542 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1450 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1543 return(0); 1451 return 0;
1544 brdp = stli_brds[portp->brdnr]; 1452 brdp = stli_brds[portp->brdnr];
1545 if (brdp == (stlibrd_t *) NULL) 1453 if (brdp == NULL)
1546 return(0); 1454 return 0;
1547 chbuf = (unsigned char *) buf; 1455 chbuf = (unsigned char *) buf;
1548 1456
1549/* 1457/*
1550 * All data is now local, shove as much as possible into shared memory. 1458 * All data is now local, shove as much as possible into shared memory.
1551 */ 1459 */
1552 save_flags(flags); 1460 spin_lock_irqsave(&brd_lock, flags);
1553 cli();
1554 EBRDENABLE(brdp); 1461 EBRDENABLE(brdp);
1555 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1462 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1556 head = (unsigned int) ap->txq.head; 1463 head = (unsigned int) readw(&ap->txq.head);
1557 tail = (unsigned int) ap->txq.tail; 1464 tail = (unsigned int) readw(&ap->txq.tail);
1558 if (tail != ((unsigned int) ap->txq.tail)) 1465 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1559 tail = (unsigned int) ap->txq.tail; 1466 tail = (unsigned int) readw(&ap->txq.tail);
1560 size = portp->txsize; 1467 size = portp->txsize;
1561 if (head >= tail) { 1468 if (head >= tail) {
1562 len = size - (head - tail) - 1; 1469 len = size - (head - tail) - 1;
@@ -1568,11 +1475,11 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1568 1475
1569 len = MIN(len, count); 1476 len = MIN(len, count);
1570 count = 0; 1477 count = 0;
1571 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset); 1478 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1572 1479
1573 while (len > 0) { 1480 while (len > 0) {
1574 stlen = MIN(len, stlen); 1481 stlen = MIN(len, stlen);
1575 memcpy((shbuf + head), chbuf, stlen); 1482 memcpy_toio(shbuf + head, chbuf, stlen);
1576 chbuf += stlen; 1483 chbuf += stlen;
1577 len -= stlen; 1484 len -= stlen;
1578 count += stlen; 1485 count += stlen;
@@ -1583,20 +1490,19 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1583 } 1490 }
1584 } 1491 }
1585 1492
1586 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1493 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1587 ap->txq.head = head; 1494 writew(head, &ap->txq.head);
1588 if (test_bit(ST_TXBUSY, &portp->state)) { 1495 if (test_bit(ST_TXBUSY, &portp->state)) {
1589 if (ap->changed.data & DT_TXEMPTY) 1496 if (readl(&ap->changed.data) & DT_TXEMPTY)
1590 ap->changed.data &= ~DT_TXEMPTY; 1497 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1591 } 1498 }
1592 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1499 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1593 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1500 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1594 portp->portidx; 1501 portp->portidx;
1595 *bits |= portp->portbit; 1502 writeb(readb(bits) | portp->portbit, bits);
1596 set_bit(ST_TXBUSY, &portp->state); 1503 set_bit(ST_TXBUSY, &portp->state);
1597 EBRDDISABLE(brdp); 1504 EBRDDISABLE(brdp);
1598 1505 spin_unlock_irqrestore(&brd_lock, flags);
1599 restore_flags(flags);
1600 1506
1601 return(count); 1507 return(count);
1602} 1508}
@@ -1613,14 +1519,8 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1613 1519
1614static void stli_putchar(struct tty_struct *tty, unsigned char ch) 1520static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1615{ 1521{
1616#ifdef DEBUG
1617 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1618#endif
1619
1620 if (tty == (struct tty_struct *) NULL)
1621 return;
1622 if (tty != stli_txcooktty) { 1522 if (tty != stli_txcooktty) {
1623 if (stli_txcooktty != (struct tty_struct *) NULL) 1523 if (stli_txcooktty != NULL)
1624 stli_flushchars(stli_txcooktty); 1524 stli_flushchars(stli_txcooktty);
1625 stli_txcooktty = tty; 1525 stli_txcooktty = tty;
1626 } 1526 }
@@ -1640,29 +1540,26 @@ static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1640 1540
1641static void stli_flushchars(struct tty_struct *tty) 1541static void stli_flushchars(struct tty_struct *tty)
1642{ 1542{
1643 volatile cdkhdr_t *hdrp; 1543 cdkhdr_t __iomem *hdrp;
1644 volatile unsigned char *bits; 1544 unsigned char __iomem *bits;
1645 volatile cdkasy_t *ap; 1545 cdkasy_t __iomem *ap;
1646 struct tty_struct *cooktty; 1546 struct tty_struct *cooktty;
1647 stliport_t *portp; 1547 stliport_t *portp;
1648 stlibrd_t *brdp; 1548 stlibrd_t *brdp;
1649 unsigned int len, stlen, head, tail, size, count, cooksize; 1549 unsigned int len, stlen, head, tail, size, count, cooksize;
1650 unsigned char *buf, *shbuf; 1550 unsigned char *buf;
1651 unsigned long flags; 1551 unsigned char __iomem *shbuf;
1652 1552 unsigned long flags;
1653#ifdef DEBUG
1654 printk("stli_flushchars(tty=%x)\n", (int) tty);
1655#endif
1656 1553
1657 cooksize = stli_txcooksize; 1554 cooksize = stli_txcooksize;
1658 cooktty = stli_txcooktty; 1555 cooktty = stli_txcooktty;
1659 stli_txcooksize = 0; 1556 stli_txcooksize = 0;
1660 stli_txcookrealsize = 0; 1557 stli_txcookrealsize = 0;
1661 stli_txcooktty = (struct tty_struct *) NULL; 1558 stli_txcooktty = NULL;
1662 1559
1663 if (tty == (struct tty_struct *) NULL) 1560 if (tty == NULL)
1664 return; 1561 return;
1665 if (cooktty == (struct tty_struct *) NULL) 1562 if (cooktty == NULL)
1666 return; 1563 return;
1667 if (tty != cooktty) 1564 if (tty != cooktty)
1668 tty = cooktty; 1565 tty = cooktty;
@@ -1670,23 +1567,22 @@ static void stli_flushchars(struct tty_struct *tty)
1670 return; 1567 return;
1671 1568
1672 portp = tty->driver_data; 1569 portp = tty->driver_data;
1673 if (portp == (stliport_t *) NULL) 1570 if (portp == NULL)
1674 return; 1571 return;
1675 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1572 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1676 return; 1573 return;
1677 brdp = stli_brds[portp->brdnr]; 1574 brdp = stli_brds[portp->brdnr];
1678 if (brdp == (stlibrd_t *) NULL) 1575 if (brdp == NULL)
1679 return; 1576 return;
1680 1577
1681 save_flags(flags); 1578 spin_lock_irqsave(&brd_lock, flags);
1682 cli();
1683 EBRDENABLE(brdp); 1579 EBRDENABLE(brdp);
1684 1580
1685 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1581 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1686 head = (unsigned int) ap->txq.head; 1582 head = (unsigned int) readw(&ap->txq.head);
1687 tail = (unsigned int) ap->txq.tail; 1583 tail = (unsigned int) readw(&ap->txq.tail);
1688 if (tail != ((unsigned int) ap->txq.tail)) 1584 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1689 tail = (unsigned int) ap->txq.tail; 1585 tail = (unsigned int) readw(&ap->txq.tail);
1690 size = portp->txsize; 1586 size = portp->txsize;
1691 if (head >= tail) { 1587 if (head >= tail) {
1692 len = size - (head - tail) - 1; 1588 len = size - (head - tail) - 1;
@@ -1703,7 +1599,7 @@ static void stli_flushchars(struct tty_struct *tty)
1703 1599
1704 while (len > 0) { 1600 while (len > 0) {
1705 stlen = MIN(len, stlen); 1601 stlen = MIN(len, stlen);
1706 memcpy((shbuf + head), buf, stlen); 1602 memcpy_toio(shbuf + head, buf, stlen);
1707 buf += stlen; 1603 buf += stlen;
1708 len -= stlen; 1604 len -= stlen;
1709 count += stlen; 1605 count += stlen;
@@ -1714,73 +1610,66 @@ static void stli_flushchars(struct tty_struct *tty)
1714 } 1610 }
1715 } 1611 }
1716 1612
1717 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1613 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1718 ap->txq.head = head; 1614 writew(head, &ap->txq.head);
1719 1615
1720 if (test_bit(ST_TXBUSY, &portp->state)) { 1616 if (test_bit(ST_TXBUSY, &portp->state)) {
1721 if (ap->changed.data & DT_TXEMPTY) 1617 if (readl(&ap->changed.data) & DT_TXEMPTY)
1722 ap->changed.data &= ~DT_TXEMPTY; 1618 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1723 } 1619 }
1724 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1620 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1725 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1621 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1726 portp->portidx; 1622 portp->portidx;
1727 *bits |= portp->portbit; 1623 writeb(readb(bits) | portp->portbit, bits);
1728 set_bit(ST_TXBUSY, &portp->state); 1624 set_bit(ST_TXBUSY, &portp->state);
1729 1625
1730 EBRDDISABLE(brdp); 1626 EBRDDISABLE(brdp);
1731 restore_flags(flags); 1627 spin_unlock_irqrestore(&brd_lock, flags);
1732} 1628}
1733 1629
1734/*****************************************************************************/ 1630/*****************************************************************************/
1735 1631
1736static int stli_writeroom(struct tty_struct *tty) 1632static int stli_writeroom(struct tty_struct *tty)
1737{ 1633{
1738 volatile cdkasyrq_t *rp; 1634 cdkasyrq_t __iomem *rp;
1739 stliport_t *portp; 1635 stliport_t *portp;
1740 stlibrd_t *brdp; 1636 stlibrd_t *brdp;
1741 unsigned int head, tail, len; 1637 unsigned int head, tail, len;
1742 unsigned long flags; 1638 unsigned long flags;
1743
1744#ifdef DEBUG
1745 printk("stli_writeroom(tty=%x)\n", (int) tty);
1746#endif
1747 1639
1748 if (tty == (struct tty_struct *) NULL)
1749 return(0);
1750 if (tty == stli_txcooktty) { 1640 if (tty == stli_txcooktty) {
1751 if (stli_txcookrealsize != 0) { 1641 if (stli_txcookrealsize != 0) {
1752 len = stli_txcookrealsize - stli_txcooksize; 1642 len = stli_txcookrealsize - stli_txcooksize;
1753 return(len); 1643 return len;
1754 } 1644 }
1755 } 1645 }
1756 1646
1757 portp = tty->driver_data; 1647 portp = tty->driver_data;
1758 if (portp == (stliport_t *) NULL) 1648 if (portp == NULL)
1759 return(0); 1649 return 0;
1760 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1650 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1761 return(0); 1651 return 0;
1762 brdp = stli_brds[portp->brdnr]; 1652 brdp = stli_brds[portp->brdnr];
1763 if (brdp == (stlibrd_t *) NULL) 1653 if (brdp == NULL)
1764 return(0); 1654 return 0;
1765 1655
1766 save_flags(flags); 1656 spin_lock_irqsave(&brd_lock, flags);
1767 cli();
1768 EBRDENABLE(brdp); 1657 EBRDENABLE(brdp);
1769 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq; 1658 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1770 head = (unsigned int) rp->head; 1659 head = (unsigned int) readw(&rp->head);
1771 tail = (unsigned int) rp->tail; 1660 tail = (unsigned int) readw(&rp->tail);
1772 if (tail != ((unsigned int) rp->tail)) 1661 if (tail != ((unsigned int) readw(&rp->tail)))
1773 tail = (unsigned int) rp->tail; 1662 tail = (unsigned int) readw(&rp->tail);
1774 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head); 1663 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1775 len--; 1664 len--;
1776 EBRDDISABLE(brdp); 1665 EBRDDISABLE(brdp);
1777 restore_flags(flags); 1666 spin_unlock_irqrestore(&brd_lock, flags);
1778 1667
1779 if (tty == stli_txcooktty) { 1668 if (tty == stli_txcooktty) {
1780 stli_txcookrealsize = len; 1669 stli_txcookrealsize = len;
1781 len -= stli_txcooksize; 1670 len -= stli_txcooksize;
1782 } 1671 }
1783 return(len); 1672 return len;
1784} 1673}
1785 1674
1786/*****************************************************************************/ 1675/*****************************************************************************/
@@ -1795,44 +1684,37 @@ static int stli_writeroom(struct tty_struct *tty)
1795 1684
1796static int stli_charsinbuffer(struct tty_struct *tty) 1685static int stli_charsinbuffer(struct tty_struct *tty)
1797{ 1686{
1798 volatile cdkasyrq_t *rp; 1687 cdkasyrq_t __iomem *rp;
1799 stliport_t *portp; 1688 stliport_t *portp;
1800 stlibrd_t *brdp; 1689 stlibrd_t *brdp;
1801 unsigned int head, tail, len; 1690 unsigned int head, tail, len;
1802 unsigned long flags; 1691 unsigned long flags;
1803
1804#ifdef DEBUG
1805 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1806#endif
1807 1692
1808 if (tty == (struct tty_struct *) NULL)
1809 return(0);
1810 if (tty == stli_txcooktty) 1693 if (tty == stli_txcooktty)
1811 stli_flushchars(tty); 1694 stli_flushchars(tty);
1812 portp = tty->driver_data; 1695 portp = tty->driver_data;
1813 if (portp == (stliport_t *) NULL) 1696 if (portp == NULL)
1814 return(0); 1697 return 0;
1815 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1698 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1816 return(0); 1699 return 0;
1817 brdp = stli_brds[portp->brdnr]; 1700 brdp = stli_brds[portp->brdnr];
1818 if (brdp == (stlibrd_t *) NULL) 1701 if (brdp == NULL)
1819 return(0); 1702 return 0;
1820 1703
1821 save_flags(flags); 1704 spin_lock_irqsave(&brd_lock, flags);
1822 cli();
1823 EBRDENABLE(brdp); 1705 EBRDENABLE(brdp);
1824 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq; 1706 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1825 head = (unsigned int) rp->head; 1707 head = (unsigned int) readw(&rp->head);
1826 tail = (unsigned int) rp->tail; 1708 tail = (unsigned int) readw(&rp->tail);
1827 if (tail != ((unsigned int) rp->tail)) 1709 if (tail != ((unsigned int) readw(&rp->tail)))
1828 tail = (unsigned int) rp->tail; 1710 tail = (unsigned int) readw(&rp->tail);
1829 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head)); 1711 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1830 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state)) 1712 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1831 len = 1; 1713 len = 1;
1832 EBRDDISABLE(brdp); 1714 EBRDDISABLE(brdp);
1833 restore_flags(flags); 1715 spin_unlock_irqrestore(&brd_lock, flags);
1834 1716
1835 return(len); 1717 return len;
1836} 1718}
1837 1719
1838/*****************************************************************************/ 1720/*****************************************************************************/
@@ -1843,12 +1725,8 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1843 1725
1844static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp) 1726static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1845{ 1727{
1846 struct serial_struct sio; 1728 struct serial_struct sio;
1847 stlibrd_t *brdp; 1729 stlibrd_t *brdp;
1848
1849#ifdef DEBUG
1850 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1851#endif
1852 1730
1853 memset(&sio, 0, sizeof(struct serial_struct)); 1731 memset(&sio, 0, sizeof(struct serial_struct));
1854 sio.type = PORT_UNKNOWN; 1732 sio.type = PORT_UNKNOWN;
@@ -1863,7 +1741,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1863 sio.hub6 = 0; 1741 sio.hub6 = 0;
1864 1742
1865 brdp = stli_brds[portp->brdnr]; 1743 brdp = stli_brds[portp->brdnr];
1866 if (brdp != (stlibrd_t *) NULL) 1744 if (brdp != NULL)
1867 sio.port = brdp->iobase; 1745 sio.port = brdp->iobase;
1868 1746
1869 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? 1747 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
@@ -1880,12 +1758,8 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1880 1758
1881static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp) 1759static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1882{ 1760{
1883 struct serial_struct sio; 1761 struct serial_struct sio;
1884 int rc; 1762 int rc;
1885
1886#ifdef DEBUG
1887 printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
1888#endif
1889 1763
1890 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1764 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1891 return -EFAULT; 1765 return -EFAULT;
@@ -1894,7 +1768,7 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1894 (sio.close_delay != portp->close_delay) || 1768 (sio.close_delay != portp->close_delay) ||
1895 ((sio.flags & ~ASYNC_USR_MASK) != 1769 ((sio.flags & ~ASYNC_USR_MASK) !=
1896 (portp->flags & ~ASYNC_USR_MASK))) 1770 (portp->flags & ~ASYNC_USR_MASK)))
1897 return(-EPERM); 1771 return -EPERM;
1898 } 1772 }
1899 1773
1900 portp->flags = (portp->flags & ~ASYNC_USR_MASK) | 1774 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
@@ -1905,8 +1779,8 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1905 portp->custom_divisor = sio.custom_divisor; 1779 portp->custom_divisor = sio.custom_divisor;
1906 1780
1907 if ((rc = stli_setport(portp)) < 0) 1781 if ((rc = stli_setport(portp)) < 0)
1908 return(rc); 1782 return rc;
1909 return(0); 1783 return 0;
1910} 1784}
1911 1785
1912/*****************************************************************************/ 1786/*****************************************************************************/
@@ -1917,19 +1791,19 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1917 stlibrd_t *brdp; 1791 stlibrd_t *brdp;
1918 int rc; 1792 int rc;
1919 1793
1920 if (portp == (stliport_t *) NULL) 1794 if (portp == NULL)
1921 return(-ENODEV); 1795 return -ENODEV;
1922 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1796 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1923 return(0); 1797 return 0;
1924 brdp = stli_brds[portp->brdnr]; 1798 brdp = stli_brds[portp->brdnr];
1925 if (brdp == (stlibrd_t *) NULL) 1799 if (brdp == NULL)
1926 return(0); 1800 return 0;
1927 if (tty->flags & (1 << TTY_IO_ERROR)) 1801 if (tty->flags & (1 << TTY_IO_ERROR))
1928 return(-EIO); 1802 return -EIO;
1929 1803
1930 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, 1804 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1931 &portp->asig, sizeof(asysigs_t), 1)) < 0) 1805 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1932 return(rc); 1806 return rc;
1933 1807
1934 return stli_mktiocm(portp->asig.sigvalue); 1808 return stli_mktiocm(portp->asig.sigvalue);
1935} 1809}
@@ -1941,15 +1815,15 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1941 stlibrd_t *brdp; 1815 stlibrd_t *brdp;
1942 int rts = -1, dtr = -1; 1816 int rts = -1, dtr = -1;
1943 1817
1944 if (portp == (stliport_t *) NULL) 1818 if (portp == NULL)
1945 return(-ENODEV); 1819 return -ENODEV;
1946 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1820 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1947 return(0); 1821 return 0;
1948 brdp = stli_brds[portp->brdnr]; 1822 brdp = stli_brds[portp->brdnr];
1949 if (brdp == (stlibrd_t *) NULL) 1823 if (brdp == NULL)
1950 return(0); 1824 return 0;
1951 if (tty->flags & (1 << TTY_IO_ERROR)) 1825 if (tty->flags & (1 << TTY_IO_ERROR))
1952 return(-EIO); 1826 return -EIO;
1953 1827
1954 if (set & TIOCM_RTS) 1828 if (set & TIOCM_RTS)
1955 rts = 1; 1829 rts = 1;
@@ -1968,32 +1842,25 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1968 1842
1969static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1843static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1970{ 1844{
1971 stliport_t *portp; 1845 stliport_t *portp;
1972 stlibrd_t *brdp; 1846 stlibrd_t *brdp;
1973 unsigned int ival; 1847 unsigned int ival;
1974 int rc; 1848 int rc;
1975 void __user *argp = (void __user *)arg; 1849 void __user *argp = (void __user *)arg;
1976 1850
1977#ifdef DEBUG
1978 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1979 (int) tty, (int) file, cmd, (int) arg);
1980#endif
1981
1982 if (tty == (struct tty_struct *) NULL)
1983 return(-ENODEV);
1984 portp = tty->driver_data; 1851 portp = tty->driver_data;
1985 if (portp == (stliport_t *) NULL) 1852 if (portp == NULL)
1986 return(-ENODEV); 1853 return -ENODEV;
1987 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1854 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1988 return(0); 1855 return 0;
1989 brdp = stli_brds[portp->brdnr]; 1856 brdp = stli_brds[portp->brdnr];
1990 if (brdp == (stlibrd_t *) NULL) 1857 if (brdp == NULL)
1991 return(0); 1858 return 0;
1992 1859
1993 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1860 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1994 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { 1861 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1995 if (tty->flags & (1 << TTY_IO_ERROR)) 1862 if (tty->flags & (1 << TTY_IO_ERROR))
1996 return(-EIO); 1863 return -EIO;
1997 } 1864 }
1998 1865
1999 rc = 0; 1866 rc = 0;
@@ -2040,7 +1907,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
2040 break; 1907 break;
2041 } 1908 }
2042 1909
2043 return(rc); 1910 return rc;
2044} 1911}
2045 1912
2046/*****************************************************************************/ 1913/*****************************************************************************/
@@ -2052,24 +1919,20 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
2052 1919
2053static void stli_settermios(struct tty_struct *tty, struct termios *old) 1920static void stli_settermios(struct tty_struct *tty, struct termios *old)
2054{ 1921{
2055 stliport_t *portp; 1922 stliport_t *portp;
2056 stlibrd_t *brdp; 1923 stlibrd_t *brdp;
2057 struct termios *tiosp; 1924 struct termios *tiosp;
2058 asyport_t aport; 1925 asyport_t aport;
2059
2060#ifdef DEBUG
2061 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2062#endif
2063 1926
2064 if (tty == (struct tty_struct *) NULL) 1927 if (tty == NULL)
2065 return; 1928 return;
2066 portp = tty->driver_data; 1929 portp = tty->driver_data;
2067 if (portp == (stliport_t *) NULL) 1930 if (portp == NULL)
2068 return; 1931 return;
2069 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1932 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2070 return; 1933 return;
2071 brdp = stli_brds[portp->brdnr]; 1934 brdp = stli_brds[portp->brdnr];
2072 if (brdp == (stlibrd_t *) NULL) 1935 if (brdp == NULL)
2073 return; 1936 return;
2074 1937
2075 tiosp = tty->termios; 1938 tiosp = tty->termios;
@@ -2102,18 +1965,9 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
2102 1965
2103static void stli_throttle(struct tty_struct *tty) 1966static void stli_throttle(struct tty_struct *tty)
2104{ 1967{
2105 stliport_t *portp; 1968 stliport_t *portp = tty->driver_data;
2106 1969 if (portp == NULL)
2107#ifdef DEBUG
2108 printk("stli_throttle(tty=%x)\n", (int) tty);
2109#endif
2110
2111 if (tty == (struct tty_struct *) NULL)
2112 return; 1970 return;
2113 portp = tty->driver_data;
2114 if (portp == (stliport_t *) NULL)
2115 return;
2116
2117 set_bit(ST_RXSTOP, &portp->state); 1971 set_bit(ST_RXSTOP, &portp->state);
2118} 1972}
2119 1973
@@ -2127,88 +1981,30 @@ static void stli_throttle(struct tty_struct *tty)
2127 1981
2128static void stli_unthrottle(struct tty_struct *tty) 1982static void stli_unthrottle(struct tty_struct *tty)
2129{ 1983{
2130 stliport_t *portp; 1984 stliport_t *portp = tty->driver_data;
2131 1985 if (portp == NULL)
2132#ifdef DEBUG
2133 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2134#endif
2135
2136 if (tty == (struct tty_struct *) NULL)
2137 return;
2138 portp = tty->driver_data;
2139 if (portp == (stliport_t *) NULL)
2140 return; 1986 return;
2141
2142 clear_bit(ST_RXSTOP, &portp->state); 1987 clear_bit(ST_RXSTOP, &portp->state);
2143} 1988}
2144 1989
2145/*****************************************************************************/ 1990/*****************************************************************************/
2146 1991
2147/* 1992/*
2148 * Stop the transmitter. Basically to do this we will just turn TX 1993 * Stop the transmitter.
2149 * interrupts off.
2150 */ 1994 */
2151 1995
2152static void stli_stop(struct tty_struct *tty) 1996static void stli_stop(struct tty_struct *tty)
2153{ 1997{
2154 stlibrd_t *brdp;
2155 stliport_t *portp;
2156 asyctrl_t actrl;
2157
2158#ifdef DEBUG
2159 printk("stli_stop(tty=%x)\n", (int) tty);
2160#endif
2161
2162 if (tty == (struct tty_struct *) NULL)
2163 return;
2164 portp = tty->driver_data;
2165 if (portp == (stliport_t *) NULL)
2166 return;
2167 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2168 return;
2169 brdp = stli_brds[portp->brdnr];
2170 if (brdp == (stlibrd_t *) NULL)
2171 return;
2172
2173 memset(&actrl, 0, sizeof(asyctrl_t));
2174 actrl.txctrl = CT_STOPFLOW;
2175#if 0
2176 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2177#endif
2178} 1998}
2179 1999
2180/*****************************************************************************/ 2000/*****************************************************************************/
2181 2001
2182/* 2002/*
2183 * Start the transmitter again. Just turn TX interrupts back on. 2003 * Start the transmitter again.
2184 */ 2004 */
2185 2005
2186static void stli_start(struct tty_struct *tty) 2006static void stli_start(struct tty_struct *tty)
2187{ 2007{
2188 stliport_t *portp;
2189 stlibrd_t *brdp;
2190 asyctrl_t actrl;
2191
2192#ifdef DEBUG
2193 printk("stli_start(tty=%x)\n", (int) tty);
2194#endif
2195
2196 if (tty == (struct tty_struct *) NULL)
2197 return;
2198 portp = tty->driver_data;
2199 if (portp == (stliport_t *) NULL)
2200 return;
2201 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2202 return;
2203 brdp = stli_brds[portp->brdnr];
2204 if (brdp == (stlibrd_t *) NULL)
2205 return;
2206
2207 memset(&actrl, 0, sizeof(asyctrl_t));
2208 actrl.txctrl = CT_STARTFLOW;
2209#if 0
2210 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2211#endif
2212} 2008}
2213 2009
2214/*****************************************************************************/ 2010/*****************************************************************************/
@@ -2224,22 +2020,9 @@ static void stli_start(struct tty_struct *tty)
2224 2020
2225static void stli_dohangup(void *arg) 2021static void stli_dohangup(void *arg)
2226{ 2022{
2227 stliport_t *portp; 2023 stliport_t *portp = (stliport_t *) arg;
2228 2024 if (portp->tty != NULL) {
2229#ifdef DEBUG 2025 tty_hangup(portp->tty);
2230 printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
2231#endif
2232
2233 /*
2234 * FIXME: There's a module removal race here: tty_hangup
2235 * calls schedule_work which will call into this
2236 * driver later.
2237 */
2238 portp = (stliport_t *) arg;
2239 if (portp != (stliport_t *) NULL) {
2240 if (portp->tty != (struct tty_struct *) NULL) {
2241 tty_hangup(portp->tty);
2242 }
2243 } 2026 }
2244} 2027}
2245 2028
@@ -2254,31 +2037,25 @@ static void stli_dohangup(void *arg)
2254 2037
2255static void stli_hangup(struct tty_struct *tty) 2038static void stli_hangup(struct tty_struct *tty)
2256{ 2039{
2257 stliport_t *portp; 2040 stliport_t *portp;
2258 stlibrd_t *brdp; 2041 stlibrd_t *brdp;
2259 unsigned long flags; 2042 unsigned long flags;
2260
2261#ifdef DEBUG
2262 printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
2263#endif
2264 2043
2265 if (tty == (struct tty_struct *) NULL)
2266 return;
2267 portp = tty->driver_data; 2044 portp = tty->driver_data;
2268 if (portp == (stliport_t *) NULL) 2045 if (portp == NULL)
2269 return; 2046 return;
2270 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2047 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2271 return; 2048 return;
2272 brdp = stli_brds[portp->brdnr]; 2049 brdp = stli_brds[portp->brdnr];
2273 if (brdp == (stlibrd_t *) NULL) 2050 if (brdp == NULL)
2274 return; 2051 return;
2275 2052
2276 portp->flags &= ~ASYNC_INITIALIZED; 2053 portp->flags &= ~ASYNC_INITIALIZED;
2277 2054
2278 save_flags(flags); 2055 if (!test_bit(ST_CLOSING, &portp->state))
2279 cli();
2280 if (! test_bit(ST_CLOSING, &portp->state))
2281 stli_rawclose(brdp, portp, 0, 0); 2056 stli_rawclose(brdp, portp, 0, 0);
2057
2058 spin_lock_irqsave(&stli_lock, flags);
2282 if (tty->termios->c_cflag & HUPCL) { 2059 if (tty->termios->c_cflag & HUPCL) {
2283 stli_mkasysigs(&portp->asig, 0, 0); 2060 stli_mkasysigs(&portp->asig, 0, 0);
2284 if (test_bit(ST_CMDING, &portp->state)) { 2061 if (test_bit(ST_CMDING, &portp->state)) {
@@ -2290,14 +2067,15 @@ static void stli_hangup(struct tty_struct *tty)
2290 &portp->asig, sizeof(asysigs_t), 0); 2067 &portp->asig, sizeof(asysigs_t), 0);
2291 } 2068 }
2292 } 2069 }
2293 restore_flags(flags);
2294 2070
2295 clear_bit(ST_TXBUSY, &portp->state); 2071 clear_bit(ST_TXBUSY, &portp->state);
2296 clear_bit(ST_RXSTOP, &portp->state); 2072 clear_bit(ST_RXSTOP, &portp->state);
2297 set_bit(TTY_IO_ERROR, &tty->flags); 2073 set_bit(TTY_IO_ERROR, &tty->flags);
2298 portp->tty = (struct tty_struct *) NULL; 2074 portp->tty = NULL;
2299 portp->flags &= ~ASYNC_NORMAL_ACTIVE; 2075 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2300 portp->refcount = 0; 2076 portp->refcount = 0;
2077 spin_unlock_irqrestore(&stli_lock, flags);
2078
2301 wake_up_interruptible(&portp->open_wait); 2079 wake_up_interruptible(&portp->open_wait);
2302} 2080}
2303 2081
@@ -2312,29 +2090,22 @@ static void stli_hangup(struct tty_struct *tty)
2312 2090
2313static void stli_flushbuffer(struct tty_struct *tty) 2091static void stli_flushbuffer(struct tty_struct *tty)
2314{ 2092{
2315 stliport_t *portp; 2093 stliport_t *portp;
2316 stlibrd_t *brdp; 2094 stlibrd_t *brdp;
2317 unsigned long ftype, flags; 2095 unsigned long ftype, flags;
2318
2319#ifdef DEBUG
2320 printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
2321#endif
2322 2096
2323 if (tty == (struct tty_struct *) NULL)
2324 return;
2325 portp = tty->driver_data; 2097 portp = tty->driver_data;
2326 if (portp == (stliport_t *) NULL) 2098 if (portp == NULL)
2327 return; 2099 return;
2328 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2100 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2329 return; 2101 return;
2330 brdp = stli_brds[portp->brdnr]; 2102 brdp = stli_brds[portp->brdnr];
2331 if (brdp == (stlibrd_t *) NULL) 2103 if (brdp == NULL)
2332 return; 2104 return;
2333 2105
2334 save_flags(flags); 2106 spin_lock_irqsave(&brd_lock, flags);
2335 cli();
2336 if (tty == stli_txcooktty) { 2107 if (tty == stli_txcooktty) {
2337 stli_txcooktty = (struct tty_struct *) NULL; 2108 stli_txcooktty = NULL;
2338 stli_txcooksize = 0; 2109 stli_txcooksize = 0;
2339 stli_txcookrealsize = 0; 2110 stli_txcookrealsize = 0;
2340 } 2111 }
@@ -2346,15 +2117,10 @@ static void stli_flushbuffer(struct tty_struct *tty)
2346 ftype |= FLUSHRX; 2117 ftype |= FLUSHRX;
2347 clear_bit(ST_DOFLUSHRX, &portp->state); 2118 clear_bit(ST_DOFLUSHRX, &portp->state);
2348 } 2119 }
2349 stli_sendcmd(brdp, portp, A_FLUSH, &ftype, 2120 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2350 sizeof(unsigned long), 0);
2351 } 2121 }
2352 restore_flags(flags); 2122 spin_unlock_irqrestore(&brd_lock, flags);
2353 2123 tty_wakeup(tty);
2354 wake_up_interruptible(&tty->write_wait);
2355 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2356 tty->ldisc.write_wakeup)
2357 (tty->ldisc.write_wakeup)(tty);
2358} 2124}
2359 2125
2360/*****************************************************************************/ 2126/*****************************************************************************/
@@ -2364,55 +2130,31 @@ static void stli_breakctl(struct tty_struct *tty, int state)
2364 stlibrd_t *brdp; 2130 stlibrd_t *brdp;
2365 stliport_t *portp; 2131 stliport_t *portp;
2366 long arg; 2132 long arg;
2367 /* long savestate, savetime; */
2368 2133
2369#ifdef DEBUG
2370 printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2371#endif
2372
2373 if (tty == (struct tty_struct *) NULL)
2374 return;
2375 portp = tty->driver_data; 2134 portp = tty->driver_data;
2376 if (portp == (stliport_t *) NULL) 2135 if (portp == NULL)
2377 return; 2136 return;
2378 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2137 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2379 return; 2138 return;
2380 brdp = stli_brds[portp->brdnr]; 2139 brdp = stli_brds[portp->brdnr];
2381 if (brdp == (stlibrd_t *) NULL) 2140 if (brdp == NULL)
2382 return; 2141 return;
2383 2142
2384/*
2385 * Due to a bug in the tty send_break() code we need to preserve
2386 * the current process state and timeout...
2387 savetime = current->timeout;
2388 savestate = current->state;
2389 */
2390
2391 arg = (state == -1) ? BREAKON : BREAKOFF; 2143 arg = (state == -1) ? BREAKON : BREAKOFF;
2392 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0); 2144 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2393
2394/*
2395 *
2396 current->timeout = savetime;
2397 current->state = savestate;
2398 */
2399} 2145}
2400 2146
2401/*****************************************************************************/ 2147/*****************************************************************************/
2402 2148
2403static void stli_waituntilsent(struct tty_struct *tty, int timeout) 2149static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2404{ 2150{
2405 stliport_t *portp; 2151 stliport_t *portp;
2406 unsigned long tend; 2152 unsigned long tend;
2407 2153
2408#ifdef DEBUG 2154 if (tty == NULL)
2409 printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2410#endif
2411
2412 if (tty == (struct tty_struct *) NULL)
2413 return; 2155 return;
2414 portp = tty->driver_data; 2156 portp = tty->driver_data;
2415 if (portp == (stliport_t *) NULL) 2157 if (portp == NULL)
2416 return; 2158 return;
2417 2159
2418 if (timeout == 0) 2160 if (timeout == 0)
@@ -2436,19 +2178,13 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2436 stliport_t *portp; 2178 stliport_t *portp;
2437 asyctrl_t actrl; 2179 asyctrl_t actrl;
2438 2180
2439#ifdef DEBUG
2440 printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2441#endif
2442
2443 if (tty == (struct tty_struct *) NULL)
2444 return;
2445 portp = tty->driver_data; 2181 portp = tty->driver_data;
2446 if (portp == (stliport_t *) NULL) 2182 if (portp == NULL)
2447 return; 2183 return;
2448 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2184 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2449 return; 2185 return;
2450 brdp = stli_brds[portp->brdnr]; 2186 brdp = stli_brds[portp->brdnr];
2451 if (brdp == (stlibrd_t *) NULL) 2187 if (brdp == NULL)
2452 return; 2188 return;
2453 2189
2454 memset(&actrl, 0, sizeof(asyctrl_t)); 2190 memset(&actrl, 0, sizeof(asyctrl_t));
@@ -2460,7 +2196,6 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2460 actrl.txctrl = CT_SENDCHR; 2196 actrl.txctrl = CT_SENDCHR;
2461 actrl.tximdch = ch; 2197 actrl.tximdch = ch;
2462 } 2198 }
2463
2464 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0); 2199 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2465} 2200}
2466 2201
@@ -2476,17 +2211,17 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2476 2211
2477static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos) 2212static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2478{ 2213{
2479 char *sp, *uart; 2214 char *sp, *uart;
2480 int rc, cnt; 2215 int rc, cnt;
2481 2216
2482 rc = stli_portcmdstats(portp); 2217 rc = stli_portcmdstats(portp);
2483 2218
2484 uart = "UNKNOWN"; 2219 uart = "UNKNOWN";
2485 if (brdp->state & BST_STARTED) { 2220 if (brdp->state & BST_STARTED) {
2486 switch (stli_comstats.hwid) { 2221 switch (stli_comstats.hwid) {
2487 case 0: uart = "2681"; break; 2222 case 0: uart = "2681"; break;
2488 case 1: uart = "SC26198"; break; 2223 case 1: uart = "SC26198"; break;
2489 default: uart = "CD1400"; break; 2224 default:uart = "CD1400"; break;
2490 } 2225 }
2491 } 2226 }
2492 2227
@@ -2537,17 +2272,11 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
2537 2272
2538static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 2273static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2539{ 2274{
2540 stlibrd_t *brdp; 2275 stlibrd_t *brdp;
2541 stliport_t *portp; 2276 stliport_t *portp;
2542 int brdnr, portnr, totalport; 2277 int brdnr, portnr, totalport;
2543 int curoff, maxoff; 2278 int curoff, maxoff;
2544 char *pos; 2279 char *pos;
2545
2546#ifdef DEBUG
2547 printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2548 "data=%x\n", (int) page, (int) start, (int) off, count,
2549 (int) eof, (int) data);
2550#endif
2551 2280
2552 pos = page; 2281 pos = page;
2553 totalport = 0; 2282 totalport = 0;
@@ -2568,7 +2297,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
2568 */ 2297 */
2569 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { 2298 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2570 brdp = stli_brds[brdnr]; 2299 brdp = stli_brds[brdnr];
2571 if (brdp == (stlibrd_t *) NULL) 2300 if (brdp == NULL)
2572 continue; 2301 continue;
2573 if (brdp->state == 0) 2302 if (brdp->state == 0)
2574 continue; 2303 continue;
@@ -2583,7 +2312,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
2583 for (portnr = 0; (portnr < brdp->nrports); portnr++, 2312 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2584 totalport++) { 2313 totalport++) {
2585 portp = brdp->ports[portnr]; 2314 portp = brdp->ports[portnr];
2586 if (portp == (stliport_t *) NULL) 2315 if (portp == NULL)
2587 continue; 2316 continue;
2588 if (off >= (curoff += MAXLINE)) 2317 if (off >= (curoff += MAXLINE))
2589 continue; 2318 continue;
@@ -2610,49 +2339,54 @@ stli_readdone:
2610 * a poll routine that does not have user context. Therefore you cannot 2339 * a poll routine that does not have user context. Therefore you cannot
2611 * copy back directly into user space, or to the kernel stack of a 2340 * copy back directly into user space, or to the kernel stack of a
2612 * process. This routine does not sleep, so can be called from anywhere. 2341 * process. This routine does not sleep, so can be called from anywhere.
2342 *
2343 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2344 * entry point)
2613 */ 2345 */
2614 2346
2615static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2347static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2616{ 2348{
2617 volatile cdkhdr_t *hdrp; 2349 cdkhdr_t __iomem *hdrp;
2618 volatile cdkctrl_t *cp; 2350 cdkctrl_t __iomem *cp;
2619 volatile unsigned char *bits; 2351 unsigned char __iomem *bits;
2620 unsigned long flags; 2352 unsigned long flags;
2621 2353
2622#ifdef DEBUG 2354 spin_lock_irqsave(&brd_lock, flags);
2623 printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2624 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2625 (int) arg, size, copyback);
2626#endif
2627
2628 save_flags(flags);
2629 cli();
2630 2355
2631 if (test_bit(ST_CMDING, &portp->state)) { 2356 if (test_bit(ST_CMDING, &portp->state)) {
2632 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", 2357 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2633 (int) cmd); 2358 (int) cmd);
2634 restore_flags(flags); 2359 spin_unlock_irqrestore(&brd_lock, flags);
2635 return; 2360 return;
2636 } 2361 }
2637 2362
2638 EBRDENABLE(brdp); 2363 EBRDENABLE(brdp);
2639 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 2364 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2640 if (size > 0) { 2365 if (size > 0) {
2641 memcpy((void *) &(cp->args[0]), arg, size); 2366 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2642 if (copyback) { 2367 if (copyback) {
2643 portp->argp = arg; 2368 portp->argp = arg;
2644 portp->argsize = size; 2369 portp->argsize = size;
2645 } 2370 }
2646 } 2371 }
2647 cp->status = 0; 2372 writel(0, &cp->status);
2648 cp->cmd = cmd; 2373 writel(cmd, &cp->cmd);
2649 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2374 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2650 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 2375 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2651 portp->portidx; 2376 portp->portidx;
2652 *bits |= portp->portbit; 2377 writeb(readb(bits) | portp->portbit, bits);
2653 set_bit(ST_CMDING, &portp->state); 2378 set_bit(ST_CMDING, &portp->state);
2654 EBRDDISABLE(brdp); 2379 EBRDDISABLE(brdp);
2655 restore_flags(flags); 2380 spin_unlock_irqrestore(&brd_lock, flags);
2381}
2382
2383static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2384{
2385 unsigned long flags;
2386
2387 spin_lock_irqsave(&brd_lock, flags);
2388 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2389 spin_unlock_irqrestore(&brd_lock, flags);
2656} 2390}
2657 2391
2658/*****************************************************************************/ 2392/*****************************************************************************/
@@ -2667,28 +2401,23 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
2667 2401
2668static void stli_read(stlibrd_t *brdp, stliport_t *portp) 2402static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2669{ 2403{
2670 volatile cdkasyrq_t *rp; 2404 cdkasyrq_t __iomem *rp;
2671 volatile char *shbuf; 2405 char __iomem *shbuf;
2672 struct tty_struct *tty; 2406 struct tty_struct *tty;
2673 unsigned int head, tail, size; 2407 unsigned int head, tail, size;
2674 unsigned int len, stlen; 2408 unsigned int len, stlen;
2675
2676#ifdef DEBUG
2677 printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
2678 (int) brdp, (int) portp);
2679#endif
2680 2409
2681 if (test_bit(ST_RXSTOP, &portp->state)) 2410 if (test_bit(ST_RXSTOP, &portp->state))
2682 return; 2411 return;
2683 tty = portp->tty; 2412 tty = portp->tty;
2684 if (tty == (struct tty_struct *) NULL) 2413 if (tty == NULL)
2685 return; 2414 return;
2686 2415
2687 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; 2416 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2688 head = (unsigned int) rp->head; 2417 head = (unsigned int) readw(&rp->head);
2689 if (head != ((unsigned int) rp->head)) 2418 if (head != ((unsigned int) readw(&rp->head)))
2690 head = (unsigned int) rp->head; 2419 head = (unsigned int) readw(&rp->head);
2691 tail = (unsigned int) rp->tail; 2420 tail = (unsigned int) readw(&rp->tail);
2692 size = portp->rxsize; 2421 size = portp->rxsize;
2693 if (head >= tail) { 2422 if (head >= tail) {
2694 len = head - tail; 2423 len = head - tail;
@@ -2699,12 +2428,15 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2699 } 2428 }
2700 2429
2701 len = tty_buffer_request_room(tty, len); 2430 len = tty_buffer_request_room(tty, len);
2702 /* FIXME : iomap ? */ 2431
2703 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset); 2432 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2704 2433
2705 while (len > 0) { 2434 while (len > 0) {
2435 unsigned char *cptr;
2436
2706 stlen = MIN(len, stlen); 2437 stlen = MIN(len, stlen);
2707 tty_insert_flip_string(tty, (char *)(shbuf + tail), stlen); 2438 tty_prepare_flip_string(tty, &cptr, stlen);
2439 memcpy_fromio(cptr, shbuf + tail, stlen);
2708 len -= stlen; 2440 len -= stlen;
2709 tail += stlen; 2441 tail += stlen;
2710 if (tail >= size) { 2442 if (tail >= size) {
@@ -2712,8 +2444,8 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2712 stlen = head; 2444 stlen = head;
2713 } 2445 }
2714 } 2446 }
2715 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; 2447 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2716 rp->tail = tail; 2448 writew(tail, &rp->tail);
2717 2449
2718 if (head != tail) 2450 if (head != tail)
2719 set_bit(ST_RXING, &portp->state); 2451 set_bit(ST_RXING, &portp->state);
@@ -2729,9 +2461,9 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2729 * difficult to deal with them here. 2461 * difficult to deal with them here.
2730 */ 2462 */
2731 2463
2732static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp) 2464static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2733{ 2465{
2734 int cmd; 2466 int cmd;
2735 2467
2736 if (test_bit(ST_DOSIGS, &portp->state)) { 2468 if (test_bit(ST_DOSIGS, &portp->state)) {
2737 if (test_bit(ST_DOFLUSHTX, &portp->state) && 2469 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
@@ -2746,10 +2478,10 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2746 clear_bit(ST_DOFLUSHTX, &portp->state); 2478 clear_bit(ST_DOFLUSHTX, &portp->state);
2747 clear_bit(ST_DOFLUSHRX, &portp->state); 2479 clear_bit(ST_DOFLUSHRX, &portp->state);
2748 clear_bit(ST_DOSIGS, &portp->state); 2480 clear_bit(ST_DOSIGS, &portp->state);
2749 memcpy((void *) &(cp->args[0]), (void *) &portp->asig, 2481 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2750 sizeof(asysigs_t)); 2482 sizeof(asysigs_t));
2751 cp->status = 0; 2483 writel(0, &cp->status);
2752 cp->cmd = cmd; 2484 writel(cmd, &cp->cmd);
2753 set_bit(ST_CMDING, &portp->state); 2485 set_bit(ST_CMDING, &portp->state);
2754 } else if (test_bit(ST_DOFLUSHTX, &portp->state) || 2486 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2755 test_bit(ST_DOFLUSHRX, &portp->state)) { 2487 test_bit(ST_DOFLUSHRX, &portp->state)) {
@@ -2757,9 +2489,9 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2757 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0); 2489 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2758 clear_bit(ST_DOFLUSHTX, &portp->state); 2490 clear_bit(ST_DOFLUSHTX, &portp->state);
2759 clear_bit(ST_DOFLUSHRX, &portp->state); 2491 clear_bit(ST_DOFLUSHRX, &portp->state);
2760 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int)); 2492 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2761 cp->status = 0; 2493 writel(0, &cp->status);
2762 cp->cmd = A_FLUSH; 2494 writel(A_FLUSH, &cp->cmd);
2763 set_bit(ST_CMDING, &portp->state); 2495 set_bit(ST_CMDING, &portp->state);
2764 } 2496 }
2765} 2497}
@@ -2779,30 +2511,25 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2779 2511
2780static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp) 2512static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2781{ 2513{
2782 volatile cdkasy_t *ap; 2514 cdkasy_t __iomem *ap;
2783 volatile cdkctrl_t *cp; 2515 cdkctrl_t __iomem *cp;
2784 struct tty_struct *tty; 2516 struct tty_struct *tty;
2785 asynotify_t nt; 2517 asynotify_t nt;
2786 unsigned long oldsigs; 2518 unsigned long oldsigs;
2787 int rc, donerx; 2519 int rc, donerx;
2788 2520
2789#ifdef DEBUG 2521 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2790 printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
2791 (int) brdp, channr);
2792#endif
2793
2794 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2795 cp = &ap->ctrl; 2522 cp = &ap->ctrl;
2796 2523
2797/* 2524/*
2798 * Check if we are waiting for an open completion message. 2525 * Check if we are waiting for an open completion message.
2799 */ 2526 */
2800 if (test_bit(ST_OPENING, &portp->state)) { 2527 if (test_bit(ST_OPENING, &portp->state)) {
2801 rc = (int) cp->openarg; 2528 rc = readl(&cp->openarg);
2802 if ((cp->open == 0) && (rc != 0)) { 2529 if (readb(&cp->open) == 0 && rc != 0) {
2803 if (rc > 0) 2530 if (rc > 0)
2804 rc--; 2531 rc--;
2805 cp->openarg = 0; 2532 writel(0, &cp->openarg);
2806 portp->rc = rc; 2533 portp->rc = rc;
2807 clear_bit(ST_OPENING, &portp->state); 2534 clear_bit(ST_OPENING, &portp->state);
2808 wake_up_interruptible(&portp->raw_wait); 2535 wake_up_interruptible(&portp->raw_wait);
@@ -2813,11 +2540,11 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2813 * Check if we are waiting for a close completion message. 2540 * Check if we are waiting for a close completion message.
2814 */ 2541 */
2815 if (test_bit(ST_CLOSING, &portp->state)) { 2542 if (test_bit(ST_CLOSING, &portp->state)) {
2816 rc = (int) cp->closearg; 2543 rc = (int) readl(&cp->closearg);
2817 if ((cp->close == 0) && (rc != 0)) { 2544 if (readb(&cp->close) == 0 && rc != 0) {
2818 if (rc > 0) 2545 if (rc > 0)
2819 rc--; 2546 rc--;
2820 cp->closearg = 0; 2547 writel(0, &cp->closearg);
2821 portp->rc = rc; 2548 portp->rc = rc;
2822 clear_bit(ST_CLOSING, &portp->state); 2549 clear_bit(ST_CLOSING, &portp->state);
2823 wake_up_interruptible(&portp->raw_wait); 2550 wake_up_interruptible(&portp->raw_wait);
@@ -2829,16 +2556,16 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2829 * need to copy out the command results associated with this command. 2556 * need to copy out the command results associated with this command.
2830 */ 2557 */
2831 if (test_bit(ST_CMDING, &portp->state)) { 2558 if (test_bit(ST_CMDING, &portp->state)) {
2832 rc = cp->status; 2559 rc = readl(&cp->status);
2833 if ((cp->cmd == 0) && (rc != 0)) { 2560 if (readl(&cp->cmd) == 0 && rc != 0) {
2834 if (rc > 0) 2561 if (rc > 0)
2835 rc--; 2562 rc--;
2836 if (portp->argp != (void *) NULL) { 2563 if (portp->argp != NULL) {
2837 memcpy(portp->argp, (void *) &(cp->args[0]), 2564 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2838 portp->argsize); 2565 portp->argsize);
2839 portp->argp = (void *) NULL; 2566 portp->argp = NULL;
2840 } 2567 }
2841 cp->status = 0; 2568 writel(0, &cp->status);
2842 portp->rc = rc; 2569 portp->rc = rc;
2843 clear_bit(ST_CMDING, &portp->state); 2570 clear_bit(ST_CMDING, &portp->state);
2844 stli_dodelaycmd(portp, cp); 2571 stli_dodelaycmd(portp, cp);
@@ -2877,18 +2604,15 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2877 if (nt.data & DT_TXEMPTY) 2604 if (nt.data & DT_TXEMPTY)
2878 clear_bit(ST_TXBUSY, &portp->state); 2605 clear_bit(ST_TXBUSY, &portp->state);
2879 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) { 2606 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2880 if (tty != (struct tty_struct *) NULL) { 2607 if (tty != NULL) {
2881 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 2608 tty_wakeup(tty);
2882 tty->ldisc.write_wakeup) { 2609 EBRDENABLE(brdp);
2883 (tty->ldisc.write_wakeup)(tty);
2884 EBRDENABLE(brdp);
2885 }
2886 wake_up_interruptible(&tty->write_wait); 2610 wake_up_interruptible(&tty->write_wait);
2887 } 2611 }
2888 } 2612 }
2889 2613
2890 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) { 2614 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2891 if (tty != (struct tty_struct *) NULL) { 2615 if (tty != NULL) {
2892 tty_insert_flip_char(tty, 0, TTY_BREAK); 2616 tty_insert_flip_char(tty, 0, TTY_BREAK);
2893 if (portp->flags & ASYNC_SAK) { 2617 if (portp->flags & ASYNC_SAK) {
2894 do_SAK(tty); 2618 do_SAK(tty);
@@ -2932,14 +2656,14 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2932 * at the cdk header structure. 2656 * at the cdk header structure.
2933 */ 2657 */
2934 2658
2935static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp) 2659static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2936{ 2660{
2937 stliport_t *portp; 2661 stliport_t *portp;
2938 unsigned char hostbits[(STL_MAXCHANS / 8) + 1]; 2662 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2939 unsigned char slavebits[(STL_MAXCHANS / 8) + 1]; 2663 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2940 unsigned char *slavep; 2664 unsigned char __iomem *slavep;
2941 int bitpos, bitat, bitsize; 2665 int bitpos, bitat, bitsize;
2942 int channr, nrdevs, slavebitchange; 2666 int channr, nrdevs, slavebitchange;
2943 2667
2944 bitsize = brdp->bitsize; 2668 bitsize = brdp->bitsize;
2945 nrdevs = brdp->nrdevs; 2669 nrdevs = brdp->nrdevs;
@@ -2951,7 +2675,7 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2951 * 8 service bits at a time in the inner loop, so we can bypass 2675 * 8 service bits at a time in the inner loop, so we can bypass
2952 * the lot if none of them want service. 2676 * the lot if none of them want service.
2953 */ 2677 */
2954 memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset), 2678 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2955 bitsize); 2679 bitsize);
2956 2680
2957 memset(&slavebits[0], 0, bitsize); 2681 memset(&slavebits[0], 0, bitsize);
@@ -2978,11 +2702,11 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2978 * service may initiate more slave requests. 2702 * service may initiate more slave requests.
2979 */ 2703 */
2980 if (slavebitchange) { 2704 if (slavebitchange) {
2981 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2705 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2982 slavep = ((unsigned char *) hdrp) + brdp->slaveoffset; 2706 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2983 for (bitpos = 0; (bitpos < bitsize); bitpos++) { 2707 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2984 if (slavebits[bitpos]) 2708 if (readb(slavebits + bitpos))
2985 slavep[bitpos] &= ~slavebits[bitpos]; 2709 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2986 } 2710 }
2987 } 2711 }
2988} 2712}
@@ -3000,9 +2724,9 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
3000 2724
3001static void stli_poll(unsigned long arg) 2725static void stli_poll(unsigned long arg)
3002{ 2726{
3003 volatile cdkhdr_t *hdrp; 2727 cdkhdr_t __iomem *hdrp;
3004 stlibrd_t *brdp; 2728 stlibrd_t *brdp;
3005 int brdnr; 2729 int brdnr;
3006 2730
3007 stli_timerlist.expires = STLI_TIMEOUT; 2731 stli_timerlist.expires = STLI_TIMEOUT;
3008 add_timer(&stli_timerlist); 2732 add_timer(&stli_timerlist);
@@ -3012,16 +2736,18 @@ static void stli_poll(unsigned long arg)
3012 */ 2736 */
3013 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { 2737 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
3014 brdp = stli_brds[brdnr]; 2738 brdp = stli_brds[brdnr];
3015 if (brdp == (stlibrd_t *) NULL) 2739 if (brdp == NULL)
3016 continue; 2740 continue;
3017 if ((brdp->state & BST_STARTED) == 0) 2741 if ((brdp->state & BST_STARTED) == 0)
3018 continue; 2742 continue;
3019 2743
2744 spin_lock(&brd_lock);
3020 EBRDENABLE(brdp); 2745 EBRDENABLE(brdp);
3021 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2746 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3022 if (hdrp->hostreq) 2747 if (readb(&hdrp->hostreq))
3023 stli_brdpoll(brdp, hdrp); 2748 stli_brdpoll(brdp, hdrp);
3024 EBRDDISABLE(brdp); 2749 EBRDDISABLE(brdp);
2750 spin_unlock(&brd_lock);
3025 } 2751 }
3026} 2752}
3027 2753
@@ -3034,11 +2760,6 @@ static void stli_poll(unsigned long arg)
3034 2760
3035static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp) 2761static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3036{ 2762{
3037#ifdef DEBUG
3038 printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3039 (int) portp, (int) pp, (int) tiosp);
3040#endif
3041
3042 memset(pp, 0, sizeof(asyport_t)); 2763 memset(pp, 0, sizeof(asyport_t));
3043 2764
3044/* 2765/*
@@ -3157,11 +2878,6 @@ static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tio
3157 2878
3158static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts) 2879static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3159{ 2880{
3160#ifdef DEBUG
3161 printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
3162 (int) sp, dtr, rts);
3163#endif
3164
3165 memset(sp, 0, sizeof(asysigs_t)); 2881 memset(sp, 0, sizeof(asysigs_t));
3166 if (dtr >= 0) { 2882 if (dtr >= 0) {
3167 sp->signal |= SG_DTR; 2883 sp->signal |= SG_DTR;
@@ -3182,13 +2898,7 @@ static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3182 2898
3183static long stli_mktiocm(unsigned long sigvalue) 2899static long stli_mktiocm(unsigned long sigvalue)
3184{ 2900{
3185 long tiocm; 2901 long tiocm = 0;
3186
3187#ifdef DEBUG
3188 printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3189#endif
3190
3191 tiocm = 0;
3192 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0); 2902 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
3193 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0); 2903 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
3194 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0); 2904 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
@@ -3210,10 +2920,6 @@ static int stli_initports(stlibrd_t *brdp)
3210 stliport_t *portp; 2920 stliport_t *portp;
3211 int i, panelnr, panelport; 2921 int i, panelnr, panelport;
3212 2922
3213#ifdef DEBUG
3214 printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
3215#endif
3216
3217 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2923 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3218 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL); 2924 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
3219 if (!portp) { 2925 if (!portp) {
@@ -3240,7 +2946,7 @@ static int stli_initports(stlibrd_t *brdp)
3240 brdp->ports[i] = portp; 2946 brdp->ports[i] = portp;
3241 } 2947 }
3242 2948
3243 return(0); 2949 return 0;
3244} 2950}
3245 2951
3246/*****************************************************************************/ 2952/*****************************************************************************/
@@ -3253,10 +2959,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
3253{ 2959{
3254 unsigned long memconf; 2960 unsigned long memconf;
3255 2961
3256#ifdef DEBUG
3257 printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
3258#endif
3259
3260 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 2962 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3261 udelay(10); 2963 udelay(10);
3262 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2964 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3270,9 +2972,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
3270 2972
3271static void stli_ecpenable(stlibrd_t *brdp) 2973static void stli_ecpenable(stlibrd_t *brdp)
3272{ 2974{
3273#ifdef DEBUG
3274 printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
3275#endif
3276 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR)); 2975 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3277} 2976}
3278 2977
@@ -3280,9 +2979,6 @@ static void stli_ecpenable(stlibrd_t *brdp)
3280 2979
3281static void stli_ecpdisable(stlibrd_t *brdp) 2980static void stli_ecpdisable(stlibrd_t *brdp)
3282{ 2981{
3283#ifdef DEBUG
3284 printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
3285#endif
3286 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2982 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3287} 2983}
3288 2984
@@ -3290,13 +2986,8 @@ static void stli_ecpdisable(stlibrd_t *brdp)
3290 2986
3291static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2987static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3292{ 2988{
3293 void *ptr; 2989 void *ptr;
3294 unsigned char val; 2990 unsigned char val;
3295
3296#ifdef DEBUG
3297 printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3298 (int) offset);
3299#endif
3300 2991
3301 if (offset > brdp->memsize) { 2992 if (offset > brdp->memsize) {
3302 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2993 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3316,10 +3007,6 @@ static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3316 3007
3317static void stli_ecpreset(stlibrd_t *brdp) 3008static void stli_ecpreset(stlibrd_t *brdp)
3318{ 3009{
3319#ifdef DEBUG
3320 printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
3321#endif
3322
3323 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 3010 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3324 udelay(10); 3011 udelay(10);
3325 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 3012 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3330,9 +3017,6 @@ static void stli_ecpreset(stlibrd_t *brdp)
3330 3017
3331static void stli_ecpintr(stlibrd_t *brdp) 3018static void stli_ecpintr(stlibrd_t *brdp)
3332{ 3019{
3333#ifdef DEBUG
3334 printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
3335#endif
3336 outb(0x1, brdp->iobase); 3020 outb(0x1, brdp->iobase);
3337} 3021}
3338 3022
@@ -3346,10 +3030,6 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
3346{ 3030{
3347 unsigned long memconf; 3031 unsigned long memconf;
3348 3032
3349#ifdef DEBUG
3350 printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3351#endif
3352
3353 outb(0x1, (brdp->iobase + ECP_EIBRDENAB)); 3033 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3354 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); 3034 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3355 udelay(10); 3035 udelay(10);
@@ -3383,11 +3063,6 @@ static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line
3383 void *ptr; 3063 void *ptr;
3384 unsigned char val; 3064 unsigned char val;
3385 3065
3386#ifdef DEBUG
3387 printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3388 (int) brdp, (int) offset, line);
3389#endif
3390
3391 if (offset > brdp->memsize) { 3066 if (offset > brdp->memsize) {
3392 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3067 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3393 "range at line=%d(%d), brd=%d\n", 3068 "range at line=%d(%d), brd=%d\n",
@@ -3437,8 +3112,8 @@ static void stli_ecpmcdisable(stlibrd_t *brdp)
3437 3112
3438static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3113static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3439{ 3114{
3440 void *ptr; 3115 void *ptr;
3441 unsigned char val; 3116 unsigned char val;
3442 3117
3443 if (offset > brdp->memsize) { 3118 if (offset > brdp->memsize) {
3444 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3119 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3472,10 +3147,6 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
3472 3147
3473static void stli_ecppciinit(stlibrd_t *brdp) 3148static void stli_ecppciinit(stlibrd_t *brdp)
3474{ 3149{
3475#ifdef DEBUG
3476 printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
3477#endif
3478
3479 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 3150 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3480 udelay(10); 3151 udelay(10);
3481 outb(0, (brdp->iobase + ECP_PCICONFR)); 3152 outb(0, (brdp->iobase + ECP_PCICONFR));
@@ -3489,11 +3160,6 @@ static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int lin
3489 void *ptr; 3160 void *ptr;
3490 unsigned char val; 3161 unsigned char val;
3491 3162
3492#ifdef DEBUG
3493 printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3494 (int) brdp, (int) offset, line);
3495#endif
3496
3497 if (offset > brdp->memsize) { 3163 if (offset > brdp->memsize) {
3498 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3164 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3499 "range at line=%d(%d), board=%d\n", 3165 "range at line=%d(%d), board=%d\n",
@@ -3528,10 +3194,6 @@ static void stli_onbinit(stlibrd_t *brdp)
3528{ 3194{
3529 unsigned long memconf; 3195 unsigned long memconf;
3530 3196
3531#ifdef DEBUG
3532 printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
3533#endif
3534
3535 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3197 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3536 udelay(10); 3198 udelay(10);
3537 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); 3199 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3547,9 +3209,6 @@ static void stli_onbinit(stlibrd_t *brdp)
3547 3209
3548static void stli_onbenable(stlibrd_t *brdp) 3210static void stli_onbenable(stlibrd_t *brdp)
3549{ 3211{
3550#ifdef DEBUG
3551 printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
3552#endif
3553 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR)); 3212 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3554} 3213}
3555 3214
@@ -3557,9 +3216,6 @@ static void stli_onbenable(stlibrd_t *brdp)
3557 3216
3558static void stli_onbdisable(stlibrd_t *brdp) 3217static void stli_onbdisable(stlibrd_t *brdp)
3559{ 3218{
3560#ifdef DEBUG
3561 printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
3562#endif
3563 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR)); 3219 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3564} 3220}
3565 3221
@@ -3569,11 +3225,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3569{ 3225{
3570 void *ptr; 3226 void *ptr;
3571 3227
3572#ifdef DEBUG
3573 printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3574 (int) offset);
3575#endif
3576
3577 if (offset > brdp->memsize) { 3228 if (offset > brdp->memsize) {
3578 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3229 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3579 "range at line=%d(%d), brd=%d\n", 3230 "range at line=%d(%d), brd=%d\n",
@@ -3589,11 +3240,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3589 3240
3590static void stli_onbreset(stlibrd_t *brdp) 3241static void stli_onbreset(stlibrd_t *brdp)
3591{ 3242{
3592
3593#ifdef DEBUG
3594 printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
3595#endif
3596
3597 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3243 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3598 udelay(10); 3244 udelay(10);
3599 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); 3245 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3610,10 +3256,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
3610{ 3256{
3611 unsigned long memconf; 3257 unsigned long memconf;
3612 3258
3613#ifdef DEBUG
3614 printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
3615#endif
3616
3617 outb(0x1, (brdp->iobase + ONB_EIBRDENAB)); 3259 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3618 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3260 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3619 udelay(10); 3261 udelay(10);
@@ -3632,9 +3274,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
3632 3274
3633static void stli_onbeenable(stlibrd_t *brdp) 3275static void stli_onbeenable(stlibrd_t *brdp)
3634{ 3276{
3635#ifdef DEBUG
3636 printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
3637#endif
3638 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR)); 3277 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3639} 3278}
3640 3279
@@ -3642,9 +3281,6 @@ static void stli_onbeenable(stlibrd_t *brdp)
3642 3281
3643static void stli_onbedisable(stlibrd_t *brdp) 3282static void stli_onbedisable(stlibrd_t *brdp)
3644{ 3283{
3645#ifdef DEBUG
3646 printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
3647#endif
3648 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3284 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3649} 3285}
3650 3286
@@ -3652,13 +3288,8 @@ static void stli_onbedisable(stlibrd_t *brdp)
3652 3288
3653static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3289static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3654{ 3290{
3655 void *ptr; 3291 void *ptr;
3656 unsigned char val; 3292 unsigned char val;
3657
3658#ifdef DEBUG
3659 printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3660 (int) brdp, (int) offset, line);
3661#endif
3662 3293
3663 if (offset > brdp->memsize) { 3294 if (offset > brdp->memsize) {
3664 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3295 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3681,11 +3312,6 @@ static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3681 3312
3682static void stli_onbereset(stlibrd_t *brdp) 3313static void stli_onbereset(stlibrd_t *brdp)
3683{ 3314{
3684
3685#ifdef DEBUG
3686 printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
3687#endif
3688
3689 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3315 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3690 udelay(10); 3316 udelay(10);
3691 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3317 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
@@ -3700,11 +3326,6 @@ static void stli_onbereset(stlibrd_t *brdp)
3700 3326
3701static void stli_bbyinit(stlibrd_t *brdp) 3327static void stli_bbyinit(stlibrd_t *brdp)
3702{ 3328{
3703
3704#ifdef DEBUG
3705 printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
3706#endif
3707
3708 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3329 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3709 udelay(10); 3330 udelay(10);
3710 outb(0, (brdp->iobase + BBY_ATCONFR)); 3331 outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3717,24 +3338,13 @@ static void stli_bbyinit(stlibrd_t *brdp)
3717 3338
3718static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3339static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3719{ 3340{
3720 void *ptr; 3341 void *ptr;
3721 unsigned char val; 3342 unsigned char val;
3722 3343
3723#ifdef DEBUG 3344 BUG_ON(offset > brdp->memsize);
3724 printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3725 (int) offset);
3726#endif
3727 3345
3728 if (offset > brdp->memsize) { 3346 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3729 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3347 val = (unsigned char) (offset / BBY_PAGESIZE);
3730 "range at line=%d(%d), brd=%d\n",
3731 (int) offset, line, __LINE__, brdp->brdnr);
3732 ptr = NULL;
3733 val = 0;
3734 } else {
3735 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3736 val = (unsigned char) (offset / BBY_PAGESIZE);
3737 }
3738 outb(val, (brdp->iobase + BBY_ATCONFR)); 3348 outb(val, (brdp->iobase + BBY_ATCONFR));
3739 return(ptr); 3349 return(ptr);
3740} 3350}
@@ -3743,11 +3353,6 @@ static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3743 3353
3744static void stli_bbyreset(stlibrd_t *brdp) 3354static void stli_bbyreset(stlibrd_t *brdp)
3745{ 3355{
3746
3747#ifdef DEBUG
3748 printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
3749#endif
3750
3751 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3356 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3752 udelay(10); 3357 udelay(10);
3753 outb(0, (brdp->iobase + BBY_ATCONFR)); 3358 outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3762,11 +3367,6 @@ static void stli_bbyreset(stlibrd_t *brdp)
3762 3367
3763static void stli_stalinit(stlibrd_t *brdp) 3368static void stli_stalinit(stlibrd_t *brdp)
3764{ 3369{
3765
3766#ifdef DEBUG
3767 printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
3768#endif
3769
3770 outb(0x1, brdp->iobase); 3370 outb(0x1, brdp->iobase);
3771 mdelay(1000); 3371 mdelay(1000);
3772} 3372}
@@ -3775,36 +3375,18 @@ static void stli_stalinit(stlibrd_t *brdp)
3775 3375
3776static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3376static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3777{ 3377{
3778 void *ptr; 3378 BUG_ON(offset > brdp->memsize);
3779 3379 return brdp->membase + (offset % STAL_PAGESIZE);
3780#ifdef DEBUG
3781 printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3782 (int) offset);
3783#endif
3784
3785 if (offset > brdp->memsize) {
3786 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3787 "range at line=%d(%d), brd=%d\n",
3788 (int) offset, line, __LINE__, brdp->brdnr);
3789 ptr = NULL;
3790 } else {
3791 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3792 }
3793 return(ptr);
3794} 3380}
3795 3381
3796/*****************************************************************************/ 3382/*****************************************************************************/
3797 3383
3798static void stli_stalreset(stlibrd_t *brdp) 3384static void stli_stalreset(stlibrd_t *brdp)
3799{ 3385{
3800 volatile unsigned long *vecp; 3386 u32 __iomem *vecp;
3801
3802#ifdef DEBUG
3803 printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
3804#endif
3805 3387
3806 vecp = (volatile unsigned long *) (brdp->membase + 0x30); 3388 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3807 *vecp = 0xffff0000; 3389 writel(0xffff0000, vecp);
3808 outb(0, brdp->iobase); 3390 outb(0, brdp->iobase);
3809 mdelay(1000); 3391 mdelay(1000);
3810} 3392}
@@ -3818,15 +3400,11 @@ static void stli_stalreset(stlibrd_t *brdp)
3818 3400
3819static int stli_initecp(stlibrd_t *brdp) 3401static int stli_initecp(stlibrd_t *brdp)
3820{ 3402{
3821 cdkecpsig_t sig; 3403 cdkecpsig_t sig;
3822 cdkecpsig_t *sigsp; 3404 cdkecpsig_t __iomem *sigsp;
3823 unsigned int status, nxtid; 3405 unsigned int status, nxtid;
3824 char *name; 3406 char *name;
3825 int panelnr, nrports; 3407 int panelnr, nrports;
3826
3827#ifdef DEBUG
3828 printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
3829#endif
3830 3408
3831 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3409 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3832 return -EIO; 3410 return -EIO;
@@ -3834,7 +3412,7 @@ static int stli_initecp(stlibrd_t *brdp)
3834 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3412 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3835 { 3413 {
3836 release_region(brdp->iobase, brdp->iosize); 3414 release_region(brdp->iobase, brdp->iosize);
3837 return(-ENODEV); 3415 return -ENODEV;
3838 } 3416 }
3839 3417
3840 brdp->iosize = ECP_IOSIZE; 3418 brdp->iosize = ECP_IOSIZE;
@@ -3903,7 +3481,7 @@ static int stli_initecp(stlibrd_t *brdp)
3903 3481
3904 default: 3482 default:
3905 release_region(brdp->iobase, brdp->iosize); 3483 release_region(brdp->iobase, brdp->iosize);
3906 return(-EINVAL); 3484 return -EINVAL;
3907 } 3485 }
3908 3486
3909/* 3487/*
@@ -3915,10 +3493,10 @@ static int stli_initecp(stlibrd_t *brdp)
3915 EBRDINIT(brdp); 3493 EBRDINIT(brdp);
3916 3494
3917 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3495 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3918 if (brdp->membase == (void *) NULL) 3496 if (brdp->membase == NULL)
3919 { 3497 {
3920 release_region(brdp->iobase, brdp->iosize); 3498 release_region(brdp->iobase, brdp->iosize);
3921 return(-ENOMEM); 3499 return -ENOMEM;
3922 } 3500 }
3923 3501
3924/* 3502/*
@@ -3927,23 +3505,14 @@ static int stli_initecp(stlibrd_t *brdp)
3927 * this is, and what it is connected to it. 3505 * this is, and what it is connected to it.
3928 */ 3506 */
3929 EBRDENABLE(brdp); 3507 EBRDENABLE(brdp);
3930 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); 3508 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3931 memcpy(&sig, sigsp, sizeof(cdkecpsig_t)); 3509 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3932 EBRDDISABLE(brdp); 3510 EBRDDISABLE(brdp);
3933 3511
3934#if 0 3512 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3935 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
3936 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
3937 (int) sig.panelid[1], (int) sig.panelid[2],
3938 (int) sig.panelid[3], (int) sig.panelid[4],
3939 (int) sig.panelid[5], (int) sig.panelid[6],
3940 (int) sig.panelid[7]);
3941#endif
3942
3943 if (sig.magic != ECP_MAGIC)
3944 { 3513 {
3945 release_region(brdp->iobase, brdp->iosize); 3514 release_region(brdp->iobase, brdp->iosize);
3946 return(-ENODEV); 3515 return -ENODEV;
3947 } 3516 }
3948 3517
3949/* 3518/*
@@ -3967,7 +3536,7 @@ static int stli_initecp(stlibrd_t *brdp)
3967 3536
3968 3537
3969 brdp->state |= BST_FOUND; 3538 brdp->state |= BST_FOUND;
3970 return(0); 3539 return 0;
3971} 3540}
3972 3541
3973/*****************************************************************************/ 3542/*****************************************************************************/
@@ -3979,20 +3548,16 @@ static int stli_initecp(stlibrd_t *brdp)
3979 3548
3980static int stli_initonb(stlibrd_t *brdp) 3549static int stli_initonb(stlibrd_t *brdp)
3981{ 3550{
3982 cdkonbsig_t sig; 3551 cdkonbsig_t sig;
3983 cdkonbsig_t *sigsp; 3552 cdkonbsig_t __iomem *sigsp;
3984 char *name; 3553 char *name;
3985 int i; 3554 int i;
3986
3987#ifdef DEBUG
3988 printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
3989#endif
3990 3555
3991/* 3556/*
3992 * Do a basic sanity check on the IO and memory addresses. 3557 * Do a basic sanity check on the IO and memory addresses.
3993 */ 3558 */
3994 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3559 if (brdp->iobase == 0 || brdp->memaddr == 0)
3995 return(-ENODEV); 3560 return -ENODEV;
3996 3561
3997 brdp->iosize = ONB_IOSIZE; 3562 brdp->iosize = ONB_IOSIZE;
3998 3563
@@ -4010,7 +3575,6 @@ static int stli_initonb(stlibrd_t *brdp)
4010 case BRD_ONBOARD2: 3575 case BRD_ONBOARD2:
4011 case BRD_ONBOARD2_32: 3576 case BRD_ONBOARD2_32:
4012 case BRD_ONBOARDRS: 3577 case BRD_ONBOARDRS:
4013 brdp->membase = (void *) brdp->memaddr;
4014 brdp->memsize = ONB_MEMSIZE; 3578 brdp->memsize = ONB_MEMSIZE;
4015 brdp->pagesize = ONB_ATPAGESIZE; 3579 brdp->pagesize = ONB_ATPAGESIZE;
4016 brdp->init = stli_onbinit; 3580 brdp->init = stli_onbinit;
@@ -4028,7 +3592,6 @@ static int stli_initonb(stlibrd_t *brdp)
4028 break; 3592 break;
4029 3593
4030 case BRD_ONBOARDE: 3594 case BRD_ONBOARDE:
4031 brdp->membase = (void *) brdp->memaddr;
4032 brdp->memsize = ONB_EIMEMSIZE; 3595 brdp->memsize = ONB_EIMEMSIZE;
4033 brdp->pagesize = ONB_EIPAGESIZE; 3596 brdp->pagesize = ONB_EIPAGESIZE;
4034 brdp->init = stli_onbeinit; 3597 brdp->init = stli_onbeinit;
@@ -4044,7 +3607,6 @@ static int stli_initonb(stlibrd_t *brdp)
4044 case BRD_BRUMBY4: 3607 case BRD_BRUMBY4:
4045 case BRD_BRUMBY8: 3608 case BRD_BRUMBY8:
4046 case BRD_BRUMBY16: 3609 case BRD_BRUMBY16:
4047 brdp->membase = (void *) brdp->memaddr;
4048 brdp->memsize = BBY_MEMSIZE; 3610 brdp->memsize = BBY_MEMSIZE;
4049 brdp->pagesize = BBY_PAGESIZE; 3611 brdp->pagesize = BBY_PAGESIZE;
4050 brdp->init = stli_bbyinit; 3612 brdp->init = stli_bbyinit;
@@ -4058,7 +3620,6 @@ static int stli_initonb(stlibrd_t *brdp)
4058 break; 3620 break;
4059 3621
4060 case BRD_STALLION: 3622 case BRD_STALLION:
4061 brdp->membase = (void *) brdp->memaddr;
4062 brdp->memsize = STAL_MEMSIZE; 3623 brdp->memsize = STAL_MEMSIZE;
4063 brdp->pagesize = STAL_PAGESIZE; 3624 brdp->pagesize = STAL_PAGESIZE;
4064 brdp->init = stli_stalinit; 3625 brdp->init = stli_stalinit;
@@ -4073,7 +3634,7 @@ static int stli_initonb(stlibrd_t *brdp)
4073 3634
4074 default: 3635 default:
4075 release_region(brdp->iobase, brdp->iosize); 3636 release_region(brdp->iobase, brdp->iosize);
4076 return(-EINVAL); 3637 return -EINVAL;
4077 } 3638 }
4078 3639
4079/* 3640/*
@@ -4085,10 +3646,10 @@ static int stli_initonb(stlibrd_t *brdp)
4085 EBRDINIT(brdp); 3646 EBRDINIT(brdp);
4086 3647
4087 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3648 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4088 if (brdp->membase == (void *) NULL) 3649 if (brdp->membase == NULL)
4089 { 3650 {
4090 release_region(brdp->iobase, brdp->iosize); 3651 release_region(brdp->iobase, brdp->iosize);
4091 return(-ENOMEM); 3652 return -ENOMEM;
4092 } 3653 }
4093 3654
4094/* 3655/*
@@ -4097,21 +3658,17 @@ static int stli_initonb(stlibrd_t *brdp)
4097 * this is, and how many ports. 3658 * this is, and how many ports.
4098 */ 3659 */
4099 EBRDENABLE(brdp); 3660 EBRDENABLE(brdp);
4100 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); 3661 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4101 memcpy(&sig, sigsp, sizeof(cdkonbsig_t)); 3662 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
4102 EBRDDISABLE(brdp); 3663 EBRDDISABLE(brdp);
4103 3664
4104#if 0 3665 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
4105 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n", 3666 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
4106 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2, 3667 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
4107 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2); 3668 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
4108#endif
4109
4110 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4111 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4112 { 3669 {
4113 release_region(brdp->iobase, brdp->iosize); 3670 release_region(brdp->iobase, brdp->iosize);
4114 return(-ENODEV); 3671 return -ENODEV;
4115 } 3672 }
4116 3673
4117/* 3674/*
@@ -4132,7 +3689,7 @@ static int stli_initonb(stlibrd_t *brdp)
4132 3689
4133 3690
4134 brdp->state |= BST_FOUND; 3691 brdp->state |= BST_FOUND;
4135 return(0); 3692 return 0;
4136} 3693}
4137 3694
4138/*****************************************************************************/ 3695/*****************************************************************************/
@@ -4145,31 +3702,25 @@ static int stli_initonb(stlibrd_t *brdp)
4145 3702
4146static int stli_startbrd(stlibrd_t *brdp) 3703static int stli_startbrd(stlibrd_t *brdp)
4147{ 3704{
4148 volatile cdkhdr_t *hdrp; 3705 cdkhdr_t __iomem *hdrp;
4149 volatile cdkmem_t *memp; 3706 cdkmem_t __iomem *memp;
4150 volatile cdkasy_t *ap; 3707 cdkasy_t __iomem *ap;
4151 unsigned long flags; 3708 unsigned long flags;
4152 stliport_t *portp; 3709 stliport_t *portp;
4153 int portnr, nrdevs, i, rc; 3710 int portnr, nrdevs, i, rc = 0;
4154 3711 u32 memoff;
4155#ifdef DEBUG 3712
4156 printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp); 3713 spin_lock_irqsave(&brd_lock, flags);
4157#endif
4158
4159 rc = 0;
4160
4161 save_flags(flags);
4162 cli();
4163 EBRDENABLE(brdp); 3714 EBRDENABLE(brdp);
4164 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 3715 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4165 nrdevs = hdrp->nrdevs; 3716 nrdevs = hdrp->nrdevs;
4166 3717
4167#if 0 3718#if 0
4168 printk("%s(%d): CDK version %d.%d.%d --> " 3719 printk("%s(%d): CDK version %d.%d.%d --> "
4169 "nrdevs=%d memp=%x hostp=%x slavep=%x\n", 3720 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4170 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification, 3721 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
4171 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp, 3722 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
4172 (int) hdrp->slavep); 3723 readl(&hdrp->slavep));
4173#endif 3724#endif
4174 3725
4175 if (nrdevs < (brdp->nrports + 1)) { 3726 if (nrdevs < (brdp->nrports + 1)) {
@@ -4181,14 +3732,14 @@ static int stli_startbrd(stlibrd_t *brdp)
4181 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR; 3732 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
4182 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR; 3733 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
4183 brdp->bitsize = (nrdevs + 7) / 8; 3734 brdp->bitsize = (nrdevs + 7) / 8;
4184 memp = (volatile cdkmem_t *) hdrp->memp; 3735 memoff = readl(&hdrp->memp);
4185 if (((unsigned long) memp) > brdp->memsize) { 3736 if (memoff > brdp->memsize) {
4186 printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); 3737 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
4187 rc = -EIO; 3738 rc = -EIO;
4188 goto stli_donestartup; 3739 goto stli_donestartup;
4189 } 3740 }
4190 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp); 3741 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
4191 if (memp->dtype != TYP_ASYNCTRL) { 3742 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
4192 printk(KERN_ERR "STALLION: no slave control device found\n"); 3743 printk(KERN_ERR "STALLION: no slave control device found\n");
4193 goto stli_donestartup; 3744 goto stli_donestartup;
4194 } 3745 }
@@ -4200,19 +3751,19 @@ static int stli_startbrd(stlibrd_t *brdp)
4200 * change pages while reading memory map. 3751 * change pages while reading memory map.
4201 */ 3752 */
4202 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) { 3753 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
4203 if (memp->dtype != TYP_ASYNC) 3754 if (readw(&memp->dtype) != TYP_ASYNC)
4204 break; 3755 break;
4205 portp = brdp->ports[portnr]; 3756 portp = brdp->ports[portnr];
4206 if (portp == (stliport_t *) NULL) 3757 if (portp == NULL)
4207 break; 3758 break;
4208 portp->devnr = i; 3759 portp->devnr = i;
4209 portp->addr = memp->offset; 3760 portp->addr = readl(&memp->offset);
4210 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs)); 3761 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
4211 portp->portidx = (unsigned char) (i / 8); 3762 portp->portidx = (unsigned char) (i / 8);
4212 portp->portbit = (unsigned char) (0x1 << (i % 8)); 3763 portp->portbit = (unsigned char) (0x1 << (i % 8));
4213 } 3764 }
4214 3765
4215 hdrp->slavereq = 0xff; 3766 writeb(0xff, &hdrp->slavereq);
4216 3767
4217/* 3768/*
4218 * For each port setup a local copy of the RX and TX buffer offsets 3769 * For each port setup a local copy of the RX and TX buffer offsets
@@ -4221,22 +3772,22 @@ static int stli_startbrd(stlibrd_t *brdp)
4221 */ 3772 */
4222 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) { 3773 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
4223 portp = brdp->ports[portnr]; 3774 portp = brdp->ports[portnr];
4224 if (portp == (stliport_t *) NULL) 3775 if (portp == NULL)
4225 break; 3776 break;
4226 if (portp->addr == 0) 3777 if (portp->addr == 0)
4227 break; 3778 break;
4228 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 3779 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
4229 if (ap != (volatile cdkasy_t *) NULL) { 3780 if (ap != NULL) {
4230 portp->rxsize = ap->rxq.size; 3781 portp->rxsize = readw(&ap->rxq.size);
4231 portp->txsize = ap->txq.size; 3782 portp->txsize = readw(&ap->txq.size);
4232 portp->rxoffset = ap->rxq.offset; 3783 portp->rxoffset = readl(&ap->rxq.offset);
4233 portp->txoffset = ap->txq.offset; 3784 portp->txoffset = readl(&ap->txq.offset);
4234 } 3785 }
4235 } 3786 }
4236 3787
4237stli_donestartup: 3788stli_donestartup:
4238 EBRDDISABLE(brdp); 3789 EBRDDISABLE(brdp);
4239 restore_flags(flags); 3790 spin_unlock_irqrestore(&brd_lock, flags);
4240 3791
4241 if (rc == 0) 3792 if (rc == 0)
4242 brdp->state |= BST_STARTED; 3793 brdp->state |= BST_STARTED;
@@ -4247,7 +3798,7 @@ stli_donestartup:
4247 add_timer(&stli_timerlist); 3798 add_timer(&stli_timerlist);
4248 } 3799 }
4249 3800
4250 return(rc); 3801 return rc;
4251} 3802}
4252 3803
4253/*****************************************************************************/ 3804/*****************************************************************************/
@@ -4258,10 +3809,6 @@ stli_donestartup:
4258 3809
4259static int __init stli_brdinit(stlibrd_t *brdp) 3810static int __init stli_brdinit(stlibrd_t *brdp)
4260{ 3811{
4261#ifdef DEBUG
4262 printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
4263#endif
4264
4265 stli_brds[brdp->brdnr] = brdp; 3812 stli_brds[brdp->brdnr] = brdp;
4266 3813
4267 switch (brdp->brdtype) { 3814 switch (brdp->brdtype) {
@@ -4289,11 +3836,11 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4289 case BRD_ECHPCI: 3836 case BRD_ECHPCI:
4290 printk(KERN_ERR "STALLION: %s board type not supported in " 3837 printk(KERN_ERR "STALLION: %s board type not supported in "
4291 "this driver\n", stli_brdnames[brdp->brdtype]); 3838 "this driver\n", stli_brdnames[brdp->brdtype]);
4292 return(ENODEV); 3839 return -ENODEV;
4293 default: 3840 default:
4294 printk(KERN_ERR "STALLION: board=%d is unknown board " 3841 printk(KERN_ERR "STALLION: board=%d is unknown board "
4295 "type=%d\n", brdp->brdnr, brdp->brdtype); 3842 "type=%d\n", brdp->brdnr, brdp->brdtype);
4296 return(ENODEV); 3843 return -ENODEV;
4297 } 3844 }
4298 3845
4299 if ((brdp->state & BST_FOUND) == 0) { 3846 if ((brdp->state & BST_FOUND) == 0) {
@@ -4301,7 +3848,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4301 "io=%x mem=%x\n", 3848 "io=%x mem=%x\n",
4302 stli_brdnames[brdp->brdtype], brdp->brdnr, 3849 stli_brdnames[brdp->brdtype], brdp->brdnr,
4303 brdp->iobase, (int) brdp->memaddr); 3850 brdp->iobase, (int) brdp->memaddr);
4304 return(ENODEV); 3851 return -ENODEV;
4305 } 3852 }
4306 3853
4307 stli_initports(brdp); 3854 stli_initports(brdp);
@@ -4309,7 +3856,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4309 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], 3856 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
4310 brdp->brdnr, brdp->iobase, (int) brdp->memaddr, 3857 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
4311 brdp->nrpanels, brdp->nrports); 3858 brdp->nrpanels, brdp->nrports);
4312 return(0); 3859 return 0;
4313} 3860}
4314 3861
4315/*****************************************************************************/ 3862/*****************************************************************************/
@@ -4321,14 +3868,10 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4321 3868
4322static int stli_eisamemprobe(stlibrd_t *brdp) 3869static int stli_eisamemprobe(stlibrd_t *brdp)
4323{ 3870{
4324 cdkecpsig_t ecpsig, *ecpsigp; 3871 cdkecpsig_t ecpsig, __iomem *ecpsigp;
4325 cdkonbsig_t onbsig, *onbsigp; 3872 cdkonbsig_t onbsig, __iomem *onbsigp;
4326 int i, foundit; 3873 int i, foundit;
4327 3874
4328#ifdef DEBUG
4329 printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4330#endif
4331
4332/* 3875/*
4333 * First up we reset the board, to get it into a known state. There 3876 * First up we reset the board, to get it into a known state. There
4334 * is only 2 board types here we need to worry about. Don;t use the 3877 * is only 2 board types here we need to worry about. Don;t use the
@@ -4352,7 +3895,7 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4352 mdelay(1); 3895 mdelay(1);
4353 stli_onbeenable(brdp); 3896 stli_onbeenable(brdp);
4354 } else { 3897 } else {
4355 return(-ENODEV); 3898 return -ENODEV;
4356 } 3899 }
4357 3900
4358 foundit = 0; 3901 foundit = 0;
@@ -4364,25 +3907,24 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4364 */ 3907 */
4365 for (i = 0; (i < stli_eisamempsize); i++) { 3908 for (i = 0; (i < stli_eisamempsize); i++) {
4366 brdp->memaddr = stli_eisamemprobeaddrs[i]; 3909 brdp->memaddr = stli_eisamemprobeaddrs[i];
4367 brdp->membase = (void *) brdp->memaddr;
4368 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3910 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4369 if (brdp->membase == (void *) NULL) 3911 if (brdp->membase == NULL)
4370 continue; 3912 continue;
4371 3913
4372 if (brdp->brdtype == BRD_ECPE) { 3914 if (brdp->brdtype == BRD_ECPE) {
4373 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp, 3915 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
4374 CDK_SIGADDR, __LINE__); 3916 CDK_SIGADDR, __LINE__);
4375 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t)); 3917 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
4376 if (ecpsig.magic == ECP_MAGIC) 3918 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
4377 foundit = 1; 3919 foundit = 1;
4378 } else { 3920 } else {
4379 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp, 3921 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
4380 CDK_SIGADDR, __LINE__); 3922 CDK_SIGADDR, __LINE__);
4381 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t)); 3923 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
4382 if ((onbsig.magic0 == ONB_MAGIC0) && 3924 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
4383 (onbsig.magic1 == ONB_MAGIC1) && 3925 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
4384 (onbsig.magic2 == ONB_MAGIC2) && 3926 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
4385 (onbsig.magic3 == ONB_MAGIC3)) 3927 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
4386 foundit = 1; 3928 foundit = 1;
4387 } 3929 }
4388 3930
@@ -4406,9 +3948,9 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4406 printk(KERN_ERR "STALLION: failed to probe shared memory " 3948 printk(KERN_ERR "STALLION: failed to probe shared memory "
4407 "region for %s in EISA slot=%d\n", 3949 "region for %s in EISA slot=%d\n",
4408 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); 3950 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
4409 return(-ENODEV); 3951 return -ENODEV;
4410 } 3952 }
4411 return(0); 3953 return 0;
4412} 3954}
4413 3955
4414static int stli_getbrdnr(void) 3956static int stli_getbrdnr(void)
@@ -4439,22 +3981,16 @@ static int stli_getbrdnr(void)
4439 3981
4440static int stli_findeisabrds(void) 3982static int stli_findeisabrds(void)
4441{ 3983{
4442 stlibrd_t *brdp; 3984 stlibrd_t *brdp;
4443 unsigned int iobase, eid; 3985 unsigned int iobase, eid;
4444 int i; 3986 int i;
4445
4446#ifdef DEBUG
4447 printk(KERN_DEBUG "stli_findeisabrds()\n");
4448#endif
4449 3987
4450/* 3988/*
4451 * Firstly check if this is an EISA system. Do this by probing for 3989 * Firstly check if this is an EISA system. If this is not an EISA system then
4452 * the system board EISA ID. If this is not an EISA system then
4453 * don't bother going any further! 3990 * don't bother going any further!
4454 */ 3991 */
4455 outb(0xff, 0xc80); 3992 if (EISA_bus)
4456 if (inb(0xc80) == 0xff) 3993 return 0;
4457 return(0);
4458 3994
4459/* 3995/*
4460 * Looks like an EISA system, so go searching for EISA boards. 3996 * Looks like an EISA system, so go searching for EISA boards.
@@ -4472,7 +4008,7 @@ static int stli_findeisabrds(void)
4472 */ 4008 */
4473 for (i = 0; (i < STL_MAXBRDS); i++) { 4009 for (i = 0; (i < STL_MAXBRDS); i++) {
4474 brdp = stli_brds[i]; 4010 brdp = stli_brds[i];
4475 if (brdp == (stlibrd_t *) NULL) 4011 if (brdp == NULL)
4476 continue; 4012 continue;
4477 if (brdp->iobase == iobase) 4013 if (brdp->iobase == iobase)
4478 break; 4014 break;
@@ -4484,10 +4020,10 @@ static int stli_findeisabrds(void)
4484 * We have found a Stallion board and it is not configured already. 4020 * We have found a Stallion board and it is not configured already.
4485 * Allocate a board structure and initialize it. 4021 * Allocate a board structure and initialize it.
4486 */ 4022 */
4487 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4023 if ((brdp = stli_allocbrd()) == NULL)
4488 return(-ENOMEM); 4024 return -ENOMEM;
4489 if ((brdp->brdnr = stli_getbrdnr()) < 0) 4025 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4490 return(-ENOMEM); 4026 return -ENOMEM;
4491 eid = inb(iobase + 0xc82); 4027 eid = inb(iobase + 0xc82);
4492 if (eid == ECP_EISAID) 4028 if (eid == ECP_EISAID)
4493 brdp->brdtype = BRD_ECPE; 4029 brdp->brdtype = BRD_ECPE;
@@ -4502,7 +4038,7 @@ static int stli_findeisabrds(void)
4502 stli_brdinit(brdp); 4038 stli_brdinit(brdp);
4503 } 4039 }
4504 4040
4505 return(0); 4041 return 0;
4506} 4042}
4507 4043
4508/*****************************************************************************/ 4044/*****************************************************************************/
@@ -4523,32 +4059,18 @@ static int stli_findeisabrds(void)
4523 4059
4524static int stli_initpcibrd(int brdtype, struct pci_dev *devp) 4060static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4525{ 4061{
4526 stlibrd_t *brdp; 4062 stlibrd_t *brdp;
4527
4528#ifdef DEBUG
4529 printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
4530 brdtype, dev->bus->number, dev->devfn);
4531#endif
4532 4063
4533 if (pci_enable_device(devp)) 4064 if (pci_enable_device(devp))
4534 return(-EIO); 4065 return -EIO;
4535 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4066 if ((brdp = stli_allocbrd()) == NULL)
4536 return(-ENOMEM); 4067 return -ENOMEM;
4537 if ((brdp->brdnr = stli_getbrdnr()) < 0) { 4068 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4538 printk(KERN_INFO "STALLION: too many boards found, " 4069 printk(KERN_INFO "STALLION: too many boards found, "
4539 "maximum supported %d\n", STL_MAXBRDS); 4070 "maximum supported %d\n", STL_MAXBRDS);
4540 return(0); 4071 return 0;
4541 } 4072 }
4542 brdp->brdtype = brdtype; 4073 brdp->brdtype = brdtype;
4543
4544#ifdef DEBUG
4545 printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
4546 pci_resource_start(devp, 0),
4547 pci_resource_start(devp, 1),
4548 pci_resource_start(devp, 2),
4549 pci_resource_start(devp, 3));
4550#endif
4551
4552/* 4074/*
4553 * We have all resources from the board, so lets setup the actual 4075 * We have all resources from the board, so lets setup the actual
4554 * board structure now. 4076 * board structure now.
@@ -4557,7 +4079,7 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4557 brdp->memaddr = pci_resource_start(devp, 2); 4079 brdp->memaddr = pci_resource_start(devp, 2);
4558 stli_brdinit(brdp); 4080 stli_brdinit(brdp);
4559 4081
4560 return(0); 4082 return 0;
4561} 4083}
4562 4084
4563/*****************************************************************************/ 4085/*****************************************************************************/
@@ -4569,20 +4091,12 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4569 4091
4570static int stli_findpcibrds(void) 4092static int stli_findpcibrds(void)
4571{ 4093{
4572 struct pci_dev *dev = NULL; 4094 struct pci_dev *dev = NULL;
4573 int rc;
4574
4575#ifdef DEBUG
4576 printk("stli_findpcibrds()\n");
4577#endif
4578 4095
4579 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION, 4096 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
4580 PCI_DEVICE_ID_ECRA, dev))) { 4097 stli_initpcibrd(BRD_ECPPCI, dev);
4581 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4582 return(rc);
4583 } 4098 }
4584 4099 return 0;
4585 return(0);
4586} 4100}
4587 4101
4588#endif 4102#endif
@@ -4595,17 +4109,16 @@ static int stli_findpcibrds(void)
4595 4109
4596static stlibrd_t *stli_allocbrd(void) 4110static stlibrd_t *stli_allocbrd(void)
4597{ 4111{
4598 stlibrd_t *brdp; 4112 stlibrd_t *brdp;
4599 4113
4600 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL); 4114 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4601 if (!brdp) { 4115 if (!brdp) {
4602 printk(KERN_ERR "STALLION: failed to allocate memory " 4116 printk(KERN_ERR "STALLION: failed to allocate memory "
4603 "(size=%d)\n", sizeof(stlibrd_t)); 4117 "(size=%Zd)\n", sizeof(stlibrd_t));
4604 return NULL; 4118 return NULL;
4605 } 4119 }
4606
4607 brdp->magic = STLI_BOARDMAGIC; 4120 brdp->magic = STLI_BOARDMAGIC;
4608 return(brdp); 4121 return brdp;
4609} 4122}
4610 4123
4611/*****************************************************************************/ 4124/*****************************************************************************/
@@ -4617,13 +4130,9 @@ static stlibrd_t *stli_allocbrd(void)
4617 4130
4618static int stli_initbrds(void) 4131static int stli_initbrds(void)
4619{ 4132{
4620 stlibrd_t *brdp, *nxtbrdp; 4133 stlibrd_t *brdp, *nxtbrdp;
4621 stlconf_t *confp; 4134 stlconf_t *confp;
4622 int i, j; 4135 int i, j;
4623
4624#ifdef DEBUG
4625 printk(KERN_DEBUG "stli_initbrds()\n");
4626#endif
4627 4136
4628 if (stli_nrbrds > STL_MAXBRDS) { 4137 if (stli_nrbrds > STL_MAXBRDS) {
4629 printk(KERN_INFO "STALLION: too many boards in configuration " 4138 printk(KERN_INFO "STALLION: too many boards in configuration "
@@ -4638,11 +4147,9 @@ static int stli_initbrds(void)
4638 */ 4147 */
4639 for (i = 0; (i < stli_nrbrds); i++) { 4148 for (i = 0; (i < stli_nrbrds); i++) {
4640 confp = &stli_brdconf[i]; 4149 confp = &stli_brdconf[i];
4641#ifdef MODULE
4642 stli_parsebrd(confp, stli_brdsp[i]); 4150 stli_parsebrd(confp, stli_brdsp[i]);
4643#endif 4151 if ((brdp = stli_allocbrd()) == NULL)
4644 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4152 return -ENOMEM;
4645 return(-ENOMEM);
4646 brdp->brdnr = i; 4153 brdp->brdnr = i;
4647 brdp->brdtype = confp->brdtype; 4154 brdp->brdtype = confp->brdtype;
4648 brdp->iobase = confp->ioaddr1; 4155 brdp->iobase = confp->ioaddr1;
@@ -4654,9 +4161,7 @@ static int stli_initbrds(void)
4654 * Static configuration table done, so now use dynamic methods to 4161 * Static configuration table done, so now use dynamic methods to
4655 * see if any more boards should be configured. 4162 * see if any more boards should be configured.
4656 */ 4163 */
4657#ifdef MODULE
4658 stli_argbrds(); 4164 stli_argbrds();
4659#endif
4660 if (STLI_EISAPROBE) 4165 if (STLI_EISAPROBE)
4661 stli_findeisabrds(); 4166 stli_findeisabrds();
4662#ifdef CONFIG_PCI 4167#ifdef CONFIG_PCI
@@ -4672,11 +4177,11 @@ static int stli_initbrds(void)
4672 if (stli_nrbrds > 1) { 4177 if (stli_nrbrds > 1) {
4673 for (i = 0; (i < stli_nrbrds); i++) { 4178 for (i = 0; (i < stli_nrbrds); i++) {
4674 brdp = stli_brds[i]; 4179 brdp = stli_brds[i];
4675 if (brdp == (stlibrd_t *) NULL) 4180 if (brdp == NULL)
4676 continue; 4181 continue;
4677 for (j = i + 1; (j < stli_nrbrds); j++) { 4182 for (j = i + 1; (j < stli_nrbrds); j++) {
4678 nxtbrdp = stli_brds[j]; 4183 nxtbrdp = stli_brds[j];
4679 if (nxtbrdp == (stlibrd_t *) NULL) 4184 if (nxtbrdp == NULL)
4680 continue; 4185 continue;
4681 if ((brdp->membase >= nxtbrdp->membase) && 4186 if ((brdp->membase >= nxtbrdp->membase) &&
4682 (brdp->membase <= (nxtbrdp->membase + 4187 (brdp->membase <= (nxtbrdp->membase +
@@ -4691,7 +4196,7 @@ static int stli_initbrds(void)
4691 if (stli_shared == 0) { 4196 if (stli_shared == 0) {
4692 for (i = 0; (i < stli_nrbrds); i++) { 4197 for (i = 0; (i < stli_nrbrds); i++) {
4693 brdp = stli_brds[i]; 4198 brdp = stli_brds[i];
4694 if (brdp == (stlibrd_t *) NULL) 4199 if (brdp == NULL)
4695 continue; 4200 continue;
4696 if (brdp->state & BST_FOUND) { 4201 if (brdp->state & BST_FOUND) {
4697 EBRDENABLE(brdp); 4202 EBRDENABLE(brdp);
@@ -4701,7 +4206,7 @@ static int stli_initbrds(void)
4701 } 4206 }
4702 } 4207 }
4703 4208
4704 return(0); 4209 return 0;
4705} 4210}
4706 4211
4707/*****************************************************************************/ 4212/*****************************************************************************/
@@ -4714,48 +4219,55 @@ static int stli_initbrds(void)
4714 4219
4715static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp) 4220static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4716{ 4221{
4717 unsigned long flags; 4222 unsigned long flags;
4718 void *memptr; 4223 void *memptr;
4719 stlibrd_t *brdp; 4224 stlibrd_t *brdp;
4720 int brdnr, size, n; 4225 int brdnr, size, n;
4721 4226 void *p;
4722#ifdef DEBUG 4227 loff_t off = *offp;
4723 printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
4724 (int) fp, (int) buf, count, (int) offp);
4725#endif
4726 4228
4727 brdnr = iminor(fp->f_dentry->d_inode); 4229 brdnr = iminor(fp->f_dentry->d_inode);
4728 if (brdnr >= stli_nrbrds) 4230 if (brdnr >= stli_nrbrds)
4729 return(-ENODEV); 4231 return -ENODEV;
4730 brdp = stli_brds[brdnr]; 4232 brdp = stli_brds[brdnr];
4731 if (brdp == (stlibrd_t *) NULL) 4233 if (brdp == NULL)
4732 return(-ENODEV); 4234 return -ENODEV;
4733 if (brdp->state == 0) 4235 if (brdp->state == 0)
4734 return(-ENODEV); 4236 return -ENODEV;
4735 if (fp->f_pos >= brdp->memsize) 4237 if (off >= brdp->memsize || off + count < off)
4736 return(0); 4238 return 0;
4737 4239
4738 size = MIN(count, (brdp->memsize - fp->f_pos)); 4240 size = MIN(count, (brdp->memsize - off));
4241
4242 /*
4243 * Copy the data a page at a time
4244 */
4245
4246 p = (void *)__get_free_page(GFP_KERNEL);
4247 if(p == NULL)
4248 return -ENOMEM;
4739 4249
4740 save_flags(flags);
4741 cli();
4742 EBRDENABLE(brdp);
4743 while (size > 0) { 4250 while (size > 0) {
4744 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos); 4251 spin_lock_irqsave(&brd_lock, flags);
4745 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize))); 4252 EBRDENABLE(brdp);
4746 if (copy_to_user(buf, memptr, n)) { 4253 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4254 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4255 n = MIN(n, PAGE_SIZE);
4256 memcpy_fromio(p, memptr, n);
4257 EBRDDISABLE(brdp);
4258 spin_unlock_irqrestore(&brd_lock, flags);
4259 if (copy_to_user(buf, p, n)) {
4747 count = -EFAULT; 4260 count = -EFAULT;
4748 goto out; 4261 goto out;
4749 } 4262 }
4750 fp->f_pos += n; 4263 off += n;
4751 buf += n; 4264 buf += n;
4752 size -= n; 4265 size -= n;
4753 } 4266 }
4754out: 4267out:
4755 EBRDDISABLE(brdp); 4268 *offp = off;
4756 restore_flags(flags); 4269 free_page((unsigned long)p);
4757 4270 return count;
4758 return(count);
4759} 4271}
4760 4272
4761/*****************************************************************************/ 4273/*****************************************************************************/
@@ -4764,54 +4276,65 @@ out:
4764 * Code to handle an "staliomem" write operation. This device is the 4276 * Code to handle an "staliomem" write operation. This device is the
4765 * contents of the board shared memory. It is used for down loading 4277 * contents of the board shared memory. It is used for down loading
4766 * the slave image (and debugging :-) 4278 * the slave image (and debugging :-)
4279 *
4280 * FIXME: copy under lock
4767 */ 4281 */
4768 4282
4769static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp) 4283static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4770{ 4284{
4771 unsigned long flags; 4285 unsigned long flags;
4772 void *memptr; 4286 void *memptr;
4773 stlibrd_t *brdp; 4287 stlibrd_t *brdp;
4774 char __user *chbuf; 4288 char __user *chbuf;
4775 int brdnr, size, n; 4289 int brdnr, size, n;
4776 4290 void *p;
4777#ifdef DEBUG 4291 loff_t off = *offp;
4778 printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
4779 (int) fp, (int) buf, count, (int) offp);
4780#endif
4781 4292
4782 brdnr = iminor(fp->f_dentry->d_inode); 4293 brdnr = iminor(fp->f_dentry->d_inode);
4294
4783 if (brdnr >= stli_nrbrds) 4295 if (brdnr >= stli_nrbrds)
4784 return(-ENODEV); 4296 return -ENODEV;
4785 brdp = stli_brds[brdnr]; 4297 brdp = stli_brds[brdnr];
4786 if (brdp == (stlibrd_t *) NULL) 4298 if (brdp == NULL)
4787 return(-ENODEV); 4299 return -ENODEV;
4788 if (brdp->state == 0) 4300 if (brdp->state == 0)
4789 return(-ENODEV); 4301 return -ENODEV;
4790 if (fp->f_pos >= brdp->memsize) 4302 if (off >= brdp->memsize || off + count < off)
4791 return(0); 4303 return 0;
4792 4304
4793 chbuf = (char __user *) buf; 4305 chbuf = (char __user *) buf;
4794 size = MIN(count, (brdp->memsize - fp->f_pos)); 4306 size = MIN(count, (brdp->memsize - off));
4307
4308 /*
4309 * Copy the data a page at a time
4310 */
4311
4312 p = (void *)__get_free_page(GFP_KERNEL);
4313 if(p == NULL)
4314 return -ENOMEM;
4795 4315
4796 save_flags(flags);
4797 cli();
4798 EBRDENABLE(brdp);
4799 while (size > 0) { 4316 while (size > 0) {
4800 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos); 4317 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4801 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize))); 4318 n = MIN(n, PAGE_SIZE);
4802 if (copy_from_user(memptr, chbuf, n)) { 4319 if (copy_from_user(p, chbuf, n)) {
4803 count = -EFAULT; 4320 if (count == 0)
4321 count = -EFAULT;
4804 goto out; 4322 goto out;
4805 } 4323 }
4806 fp->f_pos += n; 4324 spin_lock_irqsave(&brd_lock, flags);
4325 EBRDENABLE(brdp);
4326 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4327 memcpy_toio(memptr, p, n);
4328 EBRDDISABLE(brdp);
4329 spin_unlock_irqrestore(&brd_lock, flags);
4330 off += n;
4807 chbuf += n; 4331 chbuf += n;
4808 size -= n; 4332 size -= n;
4809 } 4333 }
4810out: 4334out:
4811 EBRDDISABLE(brdp); 4335 free_page((unsigned long) p);
4812 restore_flags(flags); 4336 *offp = off;
4813 4337 return count;
4814 return(count);
4815} 4338}
4816 4339
4817/*****************************************************************************/ 4340/*****************************************************************************/
@@ -4822,16 +4345,16 @@ out:
4822 4345
4823static int stli_getbrdstats(combrd_t __user *bp) 4346static int stli_getbrdstats(combrd_t __user *bp)
4824{ 4347{
4825 stlibrd_t *brdp; 4348 stlibrd_t *brdp;
4826 int i; 4349 int i;
4827 4350
4828 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) 4351 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4829 return -EFAULT; 4352 return -EFAULT;
4830 if (stli_brdstats.brd >= STL_MAXBRDS) 4353 if (stli_brdstats.brd >= STL_MAXBRDS)
4831 return(-ENODEV); 4354 return -ENODEV;
4832 brdp = stli_brds[stli_brdstats.brd]; 4355 brdp = stli_brds[stli_brdstats.brd];
4833 if (brdp == (stlibrd_t *) NULL) 4356 if (brdp == NULL)
4834 return(-ENODEV); 4357 return -ENODEV;
4835 4358
4836 memset(&stli_brdstats, 0, sizeof(combrd_t)); 4359 memset(&stli_brdstats, 0, sizeof(combrd_t));
4837 stli_brdstats.brd = brdp->brdnr; 4360 stli_brdstats.brd = brdp->brdnr;
@@ -4850,7 +4373,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
4850 4373
4851 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t))) 4374 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4852 return -EFAULT; 4375 return -EFAULT;
4853 return(0); 4376 return 0;
4854} 4377}
4855 4378
4856/*****************************************************************************/ 4379/*****************************************************************************/
@@ -4861,19 +4384,19 @@ static int stli_getbrdstats(combrd_t __user *bp)
4861 4384
4862static stliport_t *stli_getport(int brdnr, int panelnr, int portnr) 4385static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4863{ 4386{
4864 stlibrd_t *brdp; 4387 stlibrd_t *brdp;
4865 int i; 4388 int i;
4866 4389
4867 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS)) 4390 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4868 return((stliport_t *) NULL); 4391 return NULL;
4869 brdp = stli_brds[brdnr]; 4392 brdp = stli_brds[brdnr];
4870 if (brdp == (stlibrd_t *) NULL) 4393 if (brdp == NULL)
4871 return((stliport_t *) NULL); 4394 return NULL;
4872 for (i = 0; (i < panelnr); i++) 4395 for (i = 0; (i < panelnr); i++)
4873 portnr += brdp->panels[i]; 4396 portnr += brdp->panels[i];
4874 if ((portnr < 0) || (portnr >= brdp->nrports)) 4397 if ((portnr < 0) || (portnr >= brdp->nrports))
4875 return((stliport_t *) NULL); 4398 return NULL;
4876 return(brdp->ports[portnr]); 4399 return brdp->ports[portnr];
4877} 4400}
4878 4401
4879/*****************************************************************************/ 4402/*****************************************************************************/
@@ -4892,16 +4415,16 @@ static int stli_portcmdstats(stliport_t *portp)
4892 4415
4893 memset(&stli_comstats, 0, sizeof(comstats_t)); 4416 memset(&stli_comstats, 0, sizeof(comstats_t));
4894 4417
4895 if (portp == (stliport_t *) NULL) 4418 if (portp == NULL)
4896 return(-ENODEV); 4419 return -ENODEV;
4897 brdp = stli_brds[portp->brdnr]; 4420 brdp = stli_brds[portp->brdnr];
4898 if (brdp == (stlibrd_t *) NULL) 4421 if (brdp == NULL)
4899 return(-ENODEV); 4422 return -ENODEV;
4900 4423
4901 if (brdp->state & BST_STARTED) { 4424 if (brdp->state & BST_STARTED) {
4902 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS, 4425 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4903 &stli_cdkstats, sizeof(asystats_t), 1)) < 0) 4426 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4904 return(rc); 4427 return rc;
4905 } else { 4428 } else {
4906 memset(&stli_cdkstats, 0, sizeof(asystats_t)); 4429 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4907 } 4430 }
@@ -4912,13 +4435,12 @@ static int stli_portcmdstats(stliport_t *portp)
4912 stli_comstats.state = portp->state; 4435 stli_comstats.state = portp->state;
4913 stli_comstats.flags = portp->flags; 4436 stli_comstats.flags = portp->flags;
4914 4437
4915 save_flags(flags); 4438 spin_lock_irqsave(&brd_lock, flags);
4916 cli(); 4439 if (portp->tty != NULL) {
4917 if (portp->tty != (struct tty_struct *) NULL) {
4918 if (portp->tty->driver_data == portp) { 4440 if (portp->tty->driver_data == portp) {
4919 stli_comstats.ttystate = portp->tty->flags; 4441 stli_comstats.ttystate = portp->tty->flags;
4920 stli_comstats.rxbuffered = -1 /*portp->tty->flip.count*/; 4442 stli_comstats.rxbuffered = -1;
4921 if (portp->tty->termios != (struct termios *) NULL) { 4443 if (portp->tty->termios != NULL) {
4922 stli_comstats.cflags = portp->tty->termios->c_cflag; 4444 stli_comstats.cflags = portp->tty->termios->c_cflag;
4923 stli_comstats.iflags = portp->tty->termios->c_iflag; 4445 stli_comstats.iflags = portp->tty->termios->c_iflag;
4924 stli_comstats.oflags = portp->tty->termios->c_oflag; 4446 stli_comstats.oflags = portp->tty->termios->c_oflag;
@@ -4926,7 +4448,7 @@ static int stli_portcmdstats(stliport_t *portp)
4926 } 4448 }
4927 } 4449 }
4928 } 4450 }
4929 restore_flags(flags); 4451 spin_unlock_irqrestore(&brd_lock, flags);
4930 4452
4931 stli_comstats.txtotal = stli_cdkstats.txchars; 4453 stli_comstats.txtotal = stli_cdkstats.txchars;
4932 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover; 4454 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
@@ -4948,7 +4470,7 @@ static int stli_portcmdstats(stliport_t *portp)
4948 stli_comstats.hwid = stli_cdkstats.hwid; 4470 stli_comstats.hwid = stli_cdkstats.hwid;
4949 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals); 4471 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4950 4472
4951 return(0); 4473 return 0;
4952} 4474}
4953 4475
4954/*****************************************************************************/ 4476/*****************************************************************************/
@@ -4961,8 +4483,8 @@ static int stli_portcmdstats(stliport_t *portp)
4961 4483
4962static int stli_getportstats(stliport_t *portp, comstats_t __user *cp) 4484static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4963{ 4485{
4964 stlibrd_t *brdp; 4486 stlibrd_t *brdp;
4965 int rc; 4487 int rc;
4966 4488
4967 if (!portp) { 4489 if (!portp) {
4968 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) 4490 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -4992,8 +4514,8 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4992 4514
4993static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp) 4515static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4994{ 4516{
4995 stlibrd_t *brdp; 4517 stlibrd_t *brdp;
4996 int rc; 4518 int rc;
4997 4519
4998 if (!portp) { 4520 if (!portp) {
4999 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) 4521 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -5031,7 +4553,7 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
5031 4553
5032static int stli_getportstruct(stliport_t __user *arg) 4554static int stli_getportstruct(stliport_t __user *arg)
5033{ 4555{
5034 stliport_t *portp; 4556 stliport_t *portp;
5035 4557
5036 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t))) 4558 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
5037 return -EFAULT; 4559 return -EFAULT;
@@ -5052,7 +4574,7 @@ static int stli_getportstruct(stliport_t __user *arg)
5052 4574
5053static int stli_getbrdstruct(stlibrd_t __user *arg) 4575static int stli_getbrdstruct(stlibrd_t __user *arg)
5054{ 4576{
5055 stlibrd_t *brdp; 4577 stlibrd_t *brdp;
5056 4578
5057 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t))) 4579 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
5058 return -EFAULT; 4580 return -EFAULT;
@@ -5076,15 +4598,10 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
5076 4598
5077static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 4599static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
5078{ 4600{
5079 stlibrd_t *brdp; 4601 stlibrd_t *brdp;
5080 int brdnr, rc, done; 4602 int brdnr, rc, done;
5081 void __user *argp = (void __user *)arg; 4603 void __user *argp = (void __user *)arg;
5082 4604
5083#ifdef DEBUG
5084 printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
5085 (int) ip, (int) fp, cmd, (int) arg);
5086#endif
5087
5088/* 4605/*
5089 * First up handle the board independent ioctls. 4606 * First up handle the board independent ioctls.
5090 */ 4607 */
@@ -5115,7 +4632,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5115 } 4632 }
5116 4633
5117 if (done) 4634 if (done)
5118 return(rc); 4635 return rc;
5119 4636
5120/* 4637/*
5121 * Now handle the board specific ioctls. These all depend on the 4638 * Now handle the board specific ioctls. These all depend on the
@@ -5123,12 +4640,12 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5123 */ 4640 */
5124 brdnr = iminor(ip); 4641 brdnr = iminor(ip);
5125 if (brdnr >= STL_MAXBRDS) 4642 if (brdnr >= STL_MAXBRDS)
5126 return(-ENODEV); 4643 return -ENODEV;
5127 brdp = stli_brds[brdnr]; 4644 brdp = stli_brds[brdnr];
5128 if (!brdp) 4645 if (!brdp)
5129 return(-ENODEV); 4646 return -ENODEV;
5130 if (brdp->state == 0) 4647 if (brdp->state == 0)
5131 return(-ENODEV); 4648 return -ENODEV;
5132 4649
5133 switch (cmd) { 4650 switch (cmd) {
5134 case STL_BINTR: 4651 case STL_BINTR:
@@ -5152,8 +4669,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5152 rc = -ENOIOCTLCMD; 4669 rc = -ENOIOCTLCMD;
5153 break; 4670 break;
5154 } 4671 }
5155 4672 return rc;
5156 return(rc);
5157} 4673}
5158 4674
5159static struct tty_operations stli_ops = { 4675static struct tty_operations stli_ops = {
@@ -5187,6 +4703,9 @@ int __init stli_init(void)
5187 int i; 4703 int i;
5188 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion); 4704 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5189 4705
4706 spin_lock_init(&stli_lock);
4707 spin_lock_init(&brd_lock);
4708
5190 stli_initbrds(); 4709 stli_initbrds();
5191 4710
5192 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); 4711 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -5196,10 +4715,6 @@ int __init stli_init(void)
5196/* 4715/*
5197 * Allocate a temporary write buffer. 4716 * Allocate a temporary write buffer.
5198 */ 4717 */
5199 stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5200 if (!stli_tmpwritebuf)
5201 printk(KERN_ERR "STALLION: failed to allocate memory "
5202 "(size=%d)\n", STLI_TXBUFSIZE);
5203 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4718 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5204 if (!stli_txcookbuf) 4719 if (!stli_txcookbuf)
5205 printk(KERN_ERR "STALLION: failed to allocate memory " 4720 printk(KERN_ERR "STALLION: failed to allocate memory "
@@ -5243,7 +4758,7 @@ int __init stli_init(void)
5243 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4758 printk(KERN_ERR "STALLION: failed to register serial driver\n");
5244 return -EBUSY; 4759 return -EBUSY;
5245 } 4760 }
5246 return(0); 4761 return 0;
5247} 4762}
5248 4763
5249/*****************************************************************************/ 4764/*****************************************************************************/
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index f43c2e04eadd..01247cccb89f 100644
--- a/drivers/char/moxa.c
+++ b/drivers/char/moxa.c
@@ -301,7 +301,7 @@ static struct tty_operations moxa_ops = {
301 .tiocmset = moxa_tiocmset, 301 .tiocmset = moxa_tiocmset,
302}; 302};
303 303
304static spinlock_t moxa_lock = SPIN_LOCK_UNLOCKED; 304static DEFINE_SPINLOCK(moxa_lock);
305 305
306#ifdef CONFIG_PCI 306#ifdef CONFIG_PCI
307static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board) 307static int moxa_get_PCI_conf(struct pci_dev *p, int board_type, moxa_board_conf * board)
diff --git a/drivers/char/mxser.c b/drivers/char/mxser.c
index 645d9d713aec..72cfd09091e0 100644
--- a/drivers/char/mxser.c
+++ b/drivers/char/mxser.c
@@ -996,7 +996,6 @@ static int mxser_open(struct tty_struct *tty, struct file *filp)
996 996
997 info->session = current->signal->session; 997 info->session = current->signal->session;
998 info->pgrp = process_group(current); 998 info->pgrp = process_group(current);
999 clear_bit(TTY_DONT_FLIP, &tty->flags);
1000 999
1001 /* 1000 /*
1002 status = mxser_get_msr(info->base, 0, info->port); 1001 status = mxser_get_msr(info->base, 0, info->port);
diff --git a/drivers/char/n_tty.c b/drivers/char/n_tty.c
index b9371d5bf790..603b9ade5eb0 100644
--- a/drivers/char/n_tty.c
+++ b/drivers/char/n_tty.c
@@ -1132,7 +1132,7 @@ static inline int input_available_p(struct tty_struct *tty, int amt)
1132 * buffer, and once to drain the space from the (physical) beginning of 1132 * buffer, and once to drain the space from the (physical) beginning of
1133 * the buffer to head pointer. 1133 * the buffer to head pointer.
1134 * 1134 *
1135 * Called under the tty->atomic_read_lock sem and with TTY_DONT_FLIP set 1135 * Called under the tty->atomic_read_lock sem
1136 * 1136 *
1137 */ 1137 */
1138 1138
@@ -1271,7 +1271,6 @@ do_it_again:
1271 } 1271 }
1272 1272
1273 add_wait_queue(&tty->read_wait, &wait); 1273 add_wait_queue(&tty->read_wait, &wait);
1274 set_bit(TTY_DONT_FLIP, &tty->flags);
1275 while (nr) { 1274 while (nr) {
1276 /* First test for status change. */ 1275 /* First test for status change. */
1277 if (tty->packet && tty->link->ctrl_status) { 1276 if (tty->packet && tty->link->ctrl_status) {
@@ -1315,9 +1314,7 @@ do_it_again:
1315 break; 1314 break;
1316 } 1315 }
1317 n_tty_set_room(tty); 1316 n_tty_set_room(tty);
1318 clear_bit(TTY_DONT_FLIP, &tty->flags);
1319 timeout = schedule_timeout(timeout); 1317 timeout = schedule_timeout(timeout);
1320 set_bit(TTY_DONT_FLIP, &tty->flags);
1321 continue; 1318 continue;
1322 } 1319 }
1323 __set_current_state(TASK_RUNNING); 1320 __set_current_state(TASK_RUNNING);
@@ -1394,7 +1391,6 @@ do_it_again:
1394 if (time) 1391 if (time)
1395 timeout = time; 1392 timeout = time;
1396 } 1393 }
1397 clear_bit(TTY_DONT_FLIP, &tty->flags);
1398 mutex_unlock(&tty->atomic_read_lock); 1394 mutex_unlock(&tty->atomic_read_lock);
1399 remove_wait_queue(&tty->read_wait, &wait); 1395 remove_wait_queue(&tty->read_wait, &wait);
1400 1396
diff --git a/drivers/char/nsc_gpio.c b/drivers/char/nsc_gpio.c
new file mode 100644
index 000000000000..5b91e4e25641
--- /dev/null
+++ b/drivers/char/nsc_gpio.c
@@ -0,0 +1,142 @@
1/* linux/drivers/char/nsc_gpio.c
2
3 National Semiconductor common GPIO device-file/VFS methods.
4 Allows a user space process to control the GPIO pins.
5
6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>
7 Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com>
8*/
9
10#include <linux/config.h>
11#include <linux/fs.h>
12#include <linux/module.h>
13#include <linux/errno.h>
14#include <linux/kernel.h>
15#include <linux/init.h>
16#include <linux/nsc_gpio.h>
17#include <linux/platform_device.h>
18#include <asm/uaccess.h>
19#include <asm/io.h>
20
21#define NAME "nsc_gpio"
22
23void nsc_gpio_dump(struct nsc_gpio_ops *amp, unsigned index)
24{
25 /* retrieve current config w/o changing it */
26 u32 config = amp->gpio_config(index, ~0, 0);
27
28 /* user requested via 'v' command, so its INFO */
29 dev_info(amp->dev, "io%02u: 0x%04x %s %s %s %s %s %s %s\tio:%d/%d\n",
30 index, config,
31 (config & 1) ? "OE" : "TS", /* output-enabled/tristate */
32 (config & 2) ? "PP" : "OD", /* push pull / open drain */
33 (config & 4) ? "PUE" : "PUD", /* pull up enabled/disabled */
34 (config & 8) ? "LOCKED" : "", /* locked / unlocked */
35 (config & 16) ? "LEVEL" : "EDGE",/* level/edge input */
36 (config & 32) ? "HI" : "LO", /* trigger on rise/fall edge */
37 (config & 64) ? "DEBOUNCE" : "", /* debounce */
38
39 amp->gpio_get(index), amp->gpio_current(index));
40}
41
42ssize_t nsc_gpio_write(struct file *file, const char __user *data,
43 size_t len, loff_t *ppos)
44{
45 unsigned m = iminor(file->f_dentry->d_inode);
46 struct nsc_gpio_ops *amp = file->private_data;
47 struct device *dev = amp->dev;
48 size_t i;
49 int err = 0;
50
51 for (i = 0; i < len; ++i) {
52 char c;
53 if (get_user(c, data + i))
54 return -EFAULT;
55 switch (c) {
56 case '0':
57 amp->gpio_set(m, 0);
58 break;
59 case '1':
60 amp->gpio_set(m, 1);
61 break;
62 case 'O':
63 dev_dbg(dev, "GPIO%d output enabled\n", m);
64 amp->gpio_config(m, ~1, 1);
65 break;
66 case 'o':
67 dev_dbg(dev, "GPIO%d output disabled\n", m);
68 amp->gpio_config(m, ~1, 0);
69 break;
70 case 'T':
71 dev_dbg(dev, "GPIO%d output is push pull\n",
72 m);
73 amp->gpio_config(m, ~2, 2);
74 break;
75 case 't':
76 dev_dbg(dev, "GPIO%d output is open drain\n",
77 m);
78 amp->gpio_config(m, ~2, 0);
79 break;
80 case 'P':
81 dev_dbg(dev, "GPIO%d pull up enabled\n", m);
82 amp->gpio_config(m, ~4, 4);
83 break;
84 case 'p':
85 dev_dbg(dev, "GPIO%d pull up disabled\n", m);
86 amp->gpio_config(m, ~4, 0);
87 break;
88 case 'v':
89 /* View Current pin settings */
90 amp->gpio_dump(amp, m);
91 break;
92 case '\n':
93 /* end of settings string, do nothing */
94 break;
95 default:
96 dev_err(dev, "io%2d bad setting: chr<0x%2x>\n",
97 m, (int)c);
98 err++;
99 }
100 }
101 if (err)
102 return -EINVAL; /* full string handled, report error */
103
104 return len;
105}
106
107ssize_t nsc_gpio_read(struct file *file, char __user * buf,
108 size_t len, loff_t * ppos)
109{
110 unsigned m = iminor(file->f_dentry->d_inode);
111 int value;
112 struct nsc_gpio_ops *amp = file->private_data;
113
114 value = amp->gpio_get(m);
115 if (put_user(value ? '1' : '0', buf))
116 return -EFAULT;
117
118 return 1;
119}
120
121/* common file-ops routines for both scx200_gpio and pc87360_gpio */
122EXPORT_SYMBOL(nsc_gpio_write);
123EXPORT_SYMBOL(nsc_gpio_read);
124EXPORT_SYMBOL(nsc_gpio_dump);
125
126static int __init nsc_gpio_init(void)
127{
128 printk(KERN_DEBUG NAME " initializing\n");
129 return 0;
130}
131
132static void __exit nsc_gpio_cleanup(void)
133{
134 printk(KERN_DEBUG NAME " cleanup\n");
135}
136
137module_init(nsc_gpio_init);
138module_exit(nsc_gpio_cleanup);
139
140MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
141MODULE_DESCRIPTION("NatSemi GPIO Common Methods");
142MODULE_LICENSE("GPL");
diff --git a/drivers/char/pc8736x_gpio.c b/drivers/char/pc8736x_gpio.c
new file mode 100644
index 000000000000..1c706ccfdbb3
--- /dev/null
+++ b/drivers/char/pc8736x_gpio.c
@@ -0,0 +1,340 @@
1/* linux/drivers/char/pc8736x_gpio.c
2
3 National Semiconductor PC8736x GPIO driver. Allows a user space
4 process to play with the GPIO pins.
5
6 Copyright (c) 2005 Jim Cromie <jim.cromie@gmail.com>
7
8 adapted from linux/drivers/char/scx200_gpio.c
9 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com>,
10*/
11
12#include <linux/config.h>
13#include <linux/fs.h>
14#include <linux/module.h>
15#include <linux/errno.h>
16#include <linux/kernel.h>
17#include <linux/init.h>
18#include <linux/io.h>
19#include <linux/ioport.h>
20#include <linux/mutex.h>
21#include <linux/nsc_gpio.h>
22#include <linux/platform_device.h>
23#include <asm/uaccess.h>
24
25#define DEVNAME "pc8736x_gpio"
26
27MODULE_AUTHOR("Jim Cromie <jim.cromie@gmail.com>");
28MODULE_DESCRIPTION("NatSemi PC-8736x GPIO Pin Driver");
29MODULE_LICENSE("GPL");
30
31static int major; /* default to dynamic major */
32module_param(major, int, 0);
33MODULE_PARM_DESC(major, "Major device number");
34
35static DEFINE_MUTEX(pc8736x_gpio_config_lock);
36static unsigned pc8736x_gpio_base;
37static u8 pc8736x_gpio_shadow[4];
38
39#define SIO_BASE1 0x2E /* 1st command-reg to check */
40#define SIO_BASE2 0x4E /* alt command-reg to check */
41#define SIO_BASE_OFFSET 0x20
42
43#define SIO_SID 0x20 /* SuperI/O ID Register */
44#define SIO_SID_VALUE 0xe9 /* Expected value in SuperI/O ID Register */
45
46#define SIO_CF1 0x21 /* chip config, bit0 is chip enable */
47
48#define PC8736X_GPIO_SIZE 16
49
50#define SIO_UNIT_SEL 0x7 /* unit select reg */
51#define SIO_UNIT_ACT 0x30 /* unit enable */
52#define SIO_GPIO_UNIT 0x7 /* unit number of GPIO */
53#define SIO_VLM_UNIT 0x0D
54#define SIO_TMS_UNIT 0x0E
55
56/* config-space addrs to read/write each unit's runtime addr */
57#define SIO_BASE_HADDR 0x60
58#define SIO_BASE_LADDR 0x61
59
60/* GPIO config-space pin-control addresses */
61#define SIO_GPIO_PIN_SELECT 0xF0
62#define SIO_GPIO_PIN_CONFIG 0xF1
63#define SIO_GPIO_PIN_EVENT 0xF2
64
65static unsigned char superio_cmd = 0;
66static unsigned char selected_device = 0xFF; /* bogus start val */
67
68/* GPIO port runtime access, functionality */
69static int port_offset[] = { 0, 4, 8, 10 }; /* non-uniform offsets ! */
70/* static int event_capable[] = { 1, 1, 0, 0 }; ports 2,3 are hobbled */
71
72#define PORT_OUT 0
73#define PORT_IN 1
74#define PORT_EVT_EN 2
75#define PORT_EVT_STST 3
76
77static struct platform_device *pdev; /* use in dev_*() */
78
79static inline void superio_outb(int addr, int val)
80{
81 outb_p(addr, superio_cmd);
82 outb_p(val, superio_cmd + 1);
83}
84
85static inline int superio_inb(int addr)
86{
87 outb_p(addr, superio_cmd);
88 return inb_p(superio_cmd + 1);
89}
90
91static int pc8736x_superio_present(void)
92{
93 /* try the 2 possible values, read a hardware reg to verify */
94 superio_cmd = SIO_BASE1;
95 if (superio_inb(SIO_SID) == SIO_SID_VALUE)
96 return superio_cmd;
97
98 superio_cmd = SIO_BASE2;
99 if (superio_inb(SIO_SID) == SIO_SID_VALUE)
100 return superio_cmd;
101
102 return 0;
103}
104
105static void device_select(unsigned devldn)
106{
107 superio_outb(SIO_UNIT_SEL, devldn);
108 selected_device = devldn;
109}
110
111static void select_pin(unsigned iminor)
112{
113 /* select GPIO port/pin from device minor number */
114 device_select(SIO_GPIO_UNIT);
115 superio_outb(SIO_GPIO_PIN_SELECT,
116 ((iminor << 1) & 0xF0) | (iminor & 0x7));
117}
118
119static inline u32 pc8736x_gpio_configure_fn(unsigned index, u32 mask, u32 bits,
120 u32 func_slct)
121{
122 u32 config, new_config;
123
124 mutex_lock(&pc8736x_gpio_config_lock);
125
126 device_select(SIO_GPIO_UNIT);
127 select_pin(index);
128
129 /* read current config value */
130 config = superio_inb(func_slct);
131
132 /* set new config */
133 new_config = (config & mask) | bits;
134 superio_outb(func_slct, new_config);
135
136 mutex_unlock(&pc8736x_gpio_config_lock);
137
138 return config;
139}
140
141static u32 pc8736x_gpio_configure(unsigned index, u32 mask, u32 bits)
142{
143 return pc8736x_gpio_configure_fn(index, mask, bits,
144 SIO_GPIO_PIN_CONFIG);
145}
146
147static int pc8736x_gpio_get(unsigned minor)
148{
149 int port, bit, val;
150
151 port = minor >> 3;
152 bit = minor & 7;
153 val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN);
154 val >>= bit;
155 val &= 1;
156
157 dev_dbg(&pdev->dev, "_gpio_get(%d from %x bit %d) == val %d\n",
158 minor, pc8736x_gpio_base + port_offset[port] + PORT_IN, bit,
159 val);
160
161 return val;
162}
163
164static void pc8736x_gpio_set(unsigned minor, int val)
165{
166 int port, bit, curval;
167
168 minor &= 0x1f;
169 port = minor >> 3;
170 bit = minor & 7;
171 curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT);
172
173 dev_dbg(&pdev->dev, "addr:%x cur:%x bit-pos:%d cur-bit:%x + new:%d -> bit-new:%d\n",
174 pc8736x_gpio_base + port_offset[port] + PORT_OUT,
175 curval, bit, (curval & ~(1 << bit)), val, (val << bit));
176
177 val = (curval & ~(1 << bit)) | (val << bit);
178
179 dev_dbg(&pdev->dev, "gpio_set(minor:%d port:%d bit:%d)"
180 " %2x -> %2x\n", minor, port, bit, curval, val);
181
182 outb_p(val, pc8736x_gpio_base + port_offset[port] + PORT_OUT);
183
184 curval = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_OUT);
185 val = inb_p(pc8736x_gpio_base + port_offset[port] + PORT_IN);
186
187 dev_dbg(&pdev->dev, "wrote %x, read: %x\n", curval, val);
188 pc8736x_gpio_shadow[port] = val;
189}
190
191static void pc8736x_gpio_set_high(unsigned index)
192{
193 pc8736x_gpio_set(index, 1);
194}
195
196static void pc8736x_gpio_set_low(unsigned index)
197{
198 pc8736x_gpio_set(index, 0);
199}
200
201static int pc8736x_gpio_current(unsigned minor)
202{
203 int port, bit;
204 minor &= 0x1f;
205 port = minor >> 3;
206 bit = minor & 7;
207 return ((pc8736x_gpio_shadow[port] >> bit) & 0x01);
208}
209
210static void pc8736x_gpio_change(unsigned index)
211{
212 pc8736x_gpio_set(index, !pc8736x_gpio_current(index));
213}
214
215static struct nsc_gpio_ops pc8736x_access = {
216 .owner = THIS_MODULE,
217 .gpio_config = pc8736x_gpio_configure,
218 .gpio_dump = nsc_gpio_dump,
219 .gpio_get = pc8736x_gpio_get,
220 .gpio_set = pc8736x_gpio_set,
221 .gpio_set_high = pc8736x_gpio_set_high,
222 .gpio_set_low = pc8736x_gpio_set_low,
223 .gpio_change = pc8736x_gpio_change,
224 .gpio_current = pc8736x_gpio_current
225};
226
227static int pc8736x_gpio_open(struct inode *inode, struct file *file)
228{
229 unsigned m = iminor(inode);
230 file->private_data = &pc8736x_access;
231
232 dev_dbg(&pdev->dev, "open %d\n", m);
233
234 if (m > 63)
235 return -EINVAL;
236 return nonseekable_open(inode, file);
237}
238
239static struct file_operations pc8736x_gpio_fops = {
240 .owner = THIS_MODULE,
241 .open = pc8736x_gpio_open,
242 .write = nsc_gpio_write,
243 .read = nsc_gpio_read,
244};
245
246static void __init pc8736x_init_shadow(void)
247{
248 int port;
249
250 /* read the current values driven on the GPIO signals */
251 for (port = 0; port < 4; ++port)
252 pc8736x_gpio_shadow[port]
253 = inb_p(pc8736x_gpio_base + port_offset[port]
254 + PORT_OUT);
255
256}
257
258static int __init pc8736x_gpio_init(void)
259{
260 int rc = 0;
261
262 pdev = platform_device_alloc(DEVNAME, 0);
263 if (!pdev)
264 return -ENOMEM;
265
266 rc = platform_device_add(pdev);
267 if (rc) {
268 rc = -ENODEV;
269 goto undo_platform_dev_alloc;
270 }
271 dev_info(&pdev->dev, "NatSemi pc8736x GPIO Driver Initializing\n");
272
273 if (!pc8736x_superio_present()) {
274 rc = -ENODEV;
275 dev_err(&pdev->dev, "no device found\n");
276 goto undo_platform_dev_add;
277 }
278 pc8736x_access.dev = &pdev->dev;
279
280 /* Verify that chip and it's GPIO unit are both enabled.
281 My BIOS does this, so I take minimum action here
282 */
283 rc = superio_inb(SIO_CF1);
284 if (!(rc & 0x01)) {
285 rc = -ENODEV;
286 dev_err(&pdev->dev, "device not enabled\n");
287 goto undo_platform_dev_add;
288 }
289 device_select(SIO_GPIO_UNIT);
290 if (!superio_inb(SIO_UNIT_ACT)) {
291 rc = -ENODEV;
292 dev_err(&pdev->dev, "GPIO unit not enabled\n");
293 goto undo_platform_dev_add;
294 }
295
296 /* read the GPIO unit base addr that chip responds to */
297 pc8736x_gpio_base = (superio_inb(SIO_BASE_HADDR) << 8
298 | superio_inb(SIO_BASE_LADDR));
299
300 if (!request_region(pc8736x_gpio_base, 16, DEVNAME)) {
301 rc = -ENODEV;
302 dev_err(&pdev->dev, "GPIO ioport %x busy\n",
303 pc8736x_gpio_base);
304 goto undo_platform_dev_add;
305 }
306 dev_info(&pdev->dev, "GPIO ioport %x reserved\n", pc8736x_gpio_base);
307
308 rc = register_chrdev(major, DEVNAME, &pc8736x_gpio_fops);
309 if (rc < 0) {
310 dev_err(&pdev->dev, "register-chrdev failed: %d\n", rc);
311 goto undo_platform_dev_add;
312 }
313 if (!major) {
314 major = rc;
315 dev_dbg(&pdev->dev, "got dynamic major %d\n", major);
316 }
317
318 pc8736x_init_shadow();
319 return 0;
320
321undo_platform_dev_add:
322 platform_device_put(pdev);
323undo_platform_dev_alloc:
324 kfree(pdev);
325 return rc;
326}
327
328static void __exit pc8736x_gpio_cleanup(void)
329{
330 dev_dbg(&pdev->dev, " cleanup\n");
331
332 release_region(pc8736x_gpio_base, 16);
333
334 unregister_chrdev(major, DEVNAME);
335}
336
337EXPORT_SYMBOL(pc8736x_access);
338
339module_init(pc8736x_gpio_init);
340module_exit(pc8736x_gpio_cleanup);
diff --git a/drivers/char/pty.c b/drivers/char/pty.c
index 9b5a2c0e7008..0c17f61549b4 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -101,7 +101,7 @@ static void pty_unthrottle(struct tty_struct * tty)
101 * 101 *
102 * FIXME: Our pty_write method is called with our ldisc lock held but 102 * FIXME: Our pty_write method is called with our ldisc lock held but
103 * not our partners. We can't just take the other one blindly without 103 * not our partners. We can't just take the other one blindly without
104 * risking deadlocks. There is also the small matter of TTY_DONT_FLIP 104 * risking deadlocks.
105 */ 105 */
106static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count) 106static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count)
107{ 107{
diff --git a/drivers/char/scx200_gpio.c b/drivers/char/scx200_gpio.c
index 664a6e97eb1a..5a280a330401 100644
--- a/drivers/char/scx200_gpio.c
+++ b/drivers/char/scx200_gpio.c
@@ -1,4 +1,4 @@
1/* linux/drivers/char/scx200_gpio.c 1/* linux/drivers/char/scx200_gpio.c
2 2
3 National Semiconductor SCx200 GPIO driver. Allows a user space 3 National Semiconductor SCx200 GPIO driver. Allows a user space
4 process to play with the GPIO pins. 4 process to play with the GPIO pins.
@@ -6,17 +6,26 @@
6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */ 6 Copyright (c) 2001,2002 Christer Weinigel <wingel@nano-system.com> */
7 7
8#include <linux/config.h> 8#include <linux/config.h>
9#include <linux/device.h>
9#include <linux/fs.h> 10#include <linux/fs.h>
10#include <linux/module.h> 11#include <linux/module.h>
11#include <linux/errno.h> 12#include <linux/errno.h>
12#include <linux/kernel.h> 13#include <linux/kernel.h>
13#include <linux/init.h> 14#include <linux/init.h>
15#include <linux/platform_device.h>
14#include <asm/uaccess.h> 16#include <asm/uaccess.h>
15#include <asm/io.h> 17#include <asm/io.h>
16 18
19#include <linux/types.h>
20#include <linux/cdev.h>
21
17#include <linux/scx200_gpio.h> 22#include <linux/scx200_gpio.h>
23#include <linux/nsc_gpio.h>
18 24
19#define NAME "scx200_gpio" 25#define NAME "scx200_gpio"
26#define DEVNAME NAME
27
28static struct platform_device *pdev;
20 29
21MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>"); 30MODULE_AUTHOR("Christer Weinigel <wingel@nano-system.com>");
22MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver"); 31MODULE_DESCRIPTION("NatSemi SCx200 GPIO Pin Driver");
@@ -26,70 +35,23 @@ static int major = 0; /* default to dynamic major */
26module_param(major, int, 0); 35module_param(major, int, 0);
27MODULE_PARM_DESC(major, "Major device number"); 36MODULE_PARM_DESC(major, "Major device number");
28 37
29static ssize_t scx200_gpio_write(struct file *file, const char __user *data, 38struct nsc_gpio_ops scx200_access = {
30 size_t len, loff_t *ppos) 39 .owner = THIS_MODULE,
31{ 40 .gpio_config = scx200_gpio_configure,
32 unsigned m = iminor(file->f_dentry->d_inode); 41 .gpio_dump = nsc_gpio_dump,
33 size_t i; 42 .gpio_get = scx200_gpio_get,
34 43 .gpio_set = scx200_gpio_set,
35 for (i = 0; i < len; ++i) { 44 .gpio_set_high = scx200_gpio_set_high,
36 char c; 45 .gpio_set_low = scx200_gpio_set_low,
37 if (get_user(c, data+i)) 46 .gpio_change = scx200_gpio_change,
38 return -EFAULT; 47 .gpio_current = scx200_gpio_current
39 switch (c) 48};
40 {
41 case '0':
42 scx200_gpio_set(m, 0);
43 break;
44 case '1':
45 scx200_gpio_set(m, 1);
46 break;
47 case 'O':
48 printk(KERN_INFO NAME ": GPIO%d output enabled\n", m);
49 scx200_gpio_configure(m, ~1, 1);
50 break;
51 case 'o':
52 printk(KERN_INFO NAME ": GPIO%d output disabled\n", m);
53 scx200_gpio_configure(m, ~1, 0);
54 break;
55 case 'T':
56 printk(KERN_INFO NAME ": GPIO%d output is push pull\n", m);
57 scx200_gpio_configure(m, ~2, 2);
58 break;
59 case 't':
60 printk(KERN_INFO NAME ": GPIO%d output is open drain\n", m);
61 scx200_gpio_configure(m, ~2, 0);
62 break;
63 case 'P':
64 printk(KERN_INFO NAME ": GPIO%d pull up enabled\n", m);
65 scx200_gpio_configure(m, ~4, 4);
66 break;
67 case 'p':
68 printk(KERN_INFO NAME ": GPIO%d pull up disabled\n", m);
69 scx200_gpio_configure(m, ~4, 0);
70 break;
71 }
72 }
73
74 return len;
75}
76
77static ssize_t scx200_gpio_read(struct file *file, char __user *buf,
78 size_t len, loff_t *ppos)
79{
80 unsigned m = iminor(file->f_dentry->d_inode);
81 int value;
82
83 value = scx200_gpio_get(m);
84 if (put_user(value ? '1' : '0', buf))
85 return -EFAULT;
86
87 return 1;
88}
89 49
90static int scx200_gpio_open(struct inode *inode, struct file *file) 50static int scx200_gpio_open(struct inode *inode, struct file *file)
91{ 51{
92 unsigned m = iminor(inode); 52 unsigned m = iminor(inode);
53 file->private_data = &scx200_access;
54
93 if (m > 63) 55 if (m > 63)
94 return -EINVAL; 56 return -EINVAL;
95 return nonseekable_open(inode, file); 57 return nonseekable_open(inode, file);
@@ -103,47 +65,81 @@ static int scx200_gpio_release(struct inode *inode, struct file *file)
103 65
104static struct file_operations scx200_gpio_fops = { 66static struct file_operations scx200_gpio_fops = {
105 .owner = THIS_MODULE, 67 .owner = THIS_MODULE,
106 .write = scx200_gpio_write, 68 .write = nsc_gpio_write,
107 .read = scx200_gpio_read, 69 .read = nsc_gpio_read,
108 .open = scx200_gpio_open, 70 .open = scx200_gpio_open,
109 .release = scx200_gpio_release, 71 .release = scx200_gpio_release,
110}; 72};
111 73
74struct cdev *scx200_devices;
75static int num_pins = 32;
76
112static int __init scx200_gpio_init(void) 77static int __init scx200_gpio_init(void)
113{ 78{
114 int r; 79 int rc, i;
115 80 dev_t dev = MKDEV(major, 0);
116 printk(KERN_DEBUG NAME ": NatSemi SCx200 GPIO Driver\n");
117 81
118 if (!scx200_gpio_present()) { 82 if (!scx200_gpio_present()) {
119 printk(KERN_ERR NAME ": no SCx200 gpio pins available\n"); 83 printk(KERN_ERR NAME ": no SCx200 gpio present\n");
120 return -ENODEV; 84 return -ENODEV;
121 } 85 }
122 86
123 r = register_chrdev(major, NAME, &scx200_gpio_fops); 87 /* support dev_dbg() with pdev->dev */
124 if (r < 0) { 88 pdev = platform_device_alloc(DEVNAME, 0);
125 printk(KERN_ERR NAME ": unable to register character device\n"); 89 if (!pdev)
126 return r; 90 return -ENOMEM;
91
92 rc = platform_device_add(pdev);
93 if (rc)
94 goto undo_malloc;
95
96 /* nsc_gpio uses dev_dbg(), so needs this */
97 scx200_access.dev = &pdev->dev;
98
99 if (major)
100 rc = register_chrdev_region(dev, num_pins, "scx200_gpio");
101 else {
102 rc = alloc_chrdev_region(&dev, 0, num_pins, "scx200_gpio");
103 major = MAJOR(dev);
127 } 104 }
128 if (!major) { 105 if (rc < 0) {
129 major = r; 106 dev_err(&pdev->dev, "SCx200 chrdev_region err: %d\n", rc);
130 printk(KERN_DEBUG NAME ": got dynamic major %d\n", major); 107 goto undo_platform_device_add;
108 }
109 scx200_devices = kzalloc(num_pins * sizeof(struct cdev), GFP_KERNEL);
110 if (!scx200_devices) {
111 rc = -ENOMEM;
112 goto undo_chrdev_region;
113 }
114 for (i = 0; i < num_pins; i++) {
115 struct cdev *cdev = &scx200_devices[i];
116 cdev_init(cdev, &scx200_gpio_fops);
117 cdev->owner = THIS_MODULE;
118 rc = cdev_add(cdev, MKDEV(major, i), 1);
119 /* tolerate 'minor' errors */
120 if (rc)
121 dev_err(&pdev->dev, "Error %d on minor %d", rc, i);
131 } 122 }
132 123
133 return 0; 124 return 0; /* succeed */
125
126undo_chrdev_region:
127 unregister_chrdev_region(dev, num_pins);
128undo_platform_device_add:
129 platform_device_put(pdev);
130undo_malloc:
131 kfree(pdev);
132 return rc;
134} 133}
135 134
136static void __exit scx200_gpio_cleanup(void) 135static void __exit scx200_gpio_cleanup(void)
137{ 136{
138 unregister_chrdev(major, NAME); 137 kfree(scx200_devices);
138 unregister_chrdev_region(MKDEV(major, 0), num_pins);
139 platform_device_put(pdev);
140 platform_device_unregister(pdev);
141 /* kfree(pdev); */
139} 142}
140 143
141module_init(scx200_gpio_init); 144module_init(scx200_gpio_init);
142module_exit(scx200_gpio_cleanup); 145module_exit(scx200_gpio_cleanup);
143
144/*
145 Local variables:
146 compile-command: "make -k -C ../.. SUBDIRS=drivers/char modules"
147 c-basic-offset: 8
148 End:
149*/
diff --git a/drivers/char/specialix.c b/drivers/char/specialix.c
index 1b5330299e30..d2d6b01dcd05 100644
--- a/drivers/char/specialix.c
+++ b/drivers/char/specialix.c
@@ -2477,7 +2477,7 @@ static int __init specialix_init(void)
2477#endif 2477#endif
2478 2478
2479 for (i = 0; i < SX_NBOARD; i++) 2479 for (i = 0; i < SX_NBOARD; i++)
2480 sx_board[i].lock = SPIN_LOCK_UNLOCKED; 2480 spin_lock_init(&sx_board[i].lock);
2481 2481
2482 if (sx_init_drivers()) { 2482 if (sx_init_drivers()) {
2483 func_exit(); 2483 func_exit();
diff --git a/drivers/char/stallion.c b/drivers/char/stallion.c
index a9c5a7230f89..00b4a2187164 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -141,15 +141,6 @@ static char *stl_drvversion = "5.6.0";
141static struct tty_driver *stl_serial; 141static struct tty_driver *stl_serial;
142 142
143/* 143/*
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
149 */
150static char *stl_tmpwritebuf;
151
152/*
153 * Define a local default termios struct. All ports will be created 144 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port 145 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit. 146 * at 9600, 8 data bits, 1 stop bit.
@@ -363,6 +354,14 @@ static unsigned char stl_vecmap[] = {
363}; 354};
364 355
365/* 356/*
357 * Lock ordering is that you may not take stallion_lock holding
358 * brd_lock.
359 */
360
361static spinlock_t brd_lock; /* Guard the board mapping */
362static spinlock_t stallion_lock; /* Guard the tty driver */
363
364/*
366 * Set up enable and disable macros for the ECH boards. They require 365 * Set up enable and disable macros for the ECH boards. They require
367 * the secondary io address space to be activated and deactivated. 366 * the secondary io address space to be activated and deactivated.
368 * This way all ECH boards can share their secondary io region. 367 * This way all ECH boards can share their secondary io region.
@@ -725,17 +724,7 @@ static struct class *stallion_class;
725 724
726static int __init stallion_module_init(void) 725static int __init stallion_module_init(void)
727{ 726{
728 unsigned long flags;
729
730#ifdef DEBUG
731 printk("init_module()\n");
732#endif
733
734 save_flags(flags);
735 cli();
736 stl_init(); 727 stl_init();
737 restore_flags(flags);
738
739 return 0; 728 return 0;
740} 729}
741 730
@@ -746,7 +735,6 @@ static void __exit stallion_module_exit(void)
746 stlbrd_t *brdp; 735 stlbrd_t *brdp;
747 stlpanel_t *panelp; 736 stlpanel_t *panelp;
748 stlport_t *portp; 737 stlport_t *portp;
749 unsigned long flags;
750 int i, j, k; 738 int i, j, k;
751 739
752#ifdef DEBUG 740#ifdef DEBUG
@@ -756,9 +744,6 @@ static void __exit stallion_module_exit(void)
756 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle, 744 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
757 stl_drvversion); 745 stl_drvversion);
758 746
759 save_flags(flags);
760 cli();
761
762/* 747/*
763 * Free up all allocated resources used by the ports. This includes 748 * Free up all allocated resources used by the ports. This includes
764 * memory and interrupts. As part of this process we will also do 749 * memory and interrupts. As part of this process we will also do
@@ -770,7 +755,6 @@ static void __exit stallion_module_exit(void)
770 if (i) { 755 if (i) {
771 printk("STALLION: failed to un-register tty driver, " 756 printk("STALLION: failed to un-register tty driver, "
772 "errno=%d\n", -i); 757 "errno=%d\n", -i);
773 restore_flags(flags);
774 return; 758 return;
775 } 759 }
776 for (i = 0; i < 4; i++) { 760 for (i = 0; i < 4; i++) {
@@ -783,8 +767,6 @@ static void __exit stallion_module_exit(void)
783 "errno=%d\n", -i); 767 "errno=%d\n", -i);
784 class_destroy(stallion_class); 768 class_destroy(stallion_class);
785 769
786 kfree(stl_tmpwritebuf);
787
788 for (i = 0; (i < stl_nrbrds); i++) { 770 for (i = 0; (i < stl_nrbrds); i++) {
789 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) 771 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
790 continue; 772 continue;
@@ -814,8 +796,6 @@ static void __exit stallion_module_exit(void)
814 kfree(brdp); 796 kfree(brdp);
815 stl_brds[i] = (stlbrd_t *) NULL; 797 stl_brds[i] = (stlbrd_t *) NULL;
816 } 798 }
817
818 restore_flags(flags);
819} 799}
820 800
821module_init(stallion_module_init); 801module_init(stallion_module_init);
@@ -948,7 +928,7 @@ static stlbrd_t *stl_allocbrd(void)
948 928
949 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL); 929 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
950 if (!brdp) { 930 if (!brdp) {
951 printk("STALLION: failed to allocate memory (size=%d)\n", 931 printk("STALLION: failed to allocate memory (size=%Zd)\n",
952 sizeof(stlbrd_t)); 932 sizeof(stlbrd_t));
953 return NULL; 933 return NULL;
954 } 934 }
@@ -1066,16 +1046,17 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1066 rc = 0; 1046 rc = 0;
1067 doclocal = 0; 1047 doclocal = 0;
1068 1048
1049 spin_lock_irqsave(&stallion_lock, flags);
1050
1069 if (portp->tty->termios->c_cflag & CLOCAL) 1051 if (portp->tty->termios->c_cflag & CLOCAL)
1070 doclocal++; 1052 doclocal++;
1071 1053
1072 save_flags(flags);
1073 cli();
1074 portp->openwaitcnt++; 1054 portp->openwaitcnt++;
1075 if (! tty_hung_up_p(filp)) 1055 if (! tty_hung_up_p(filp))
1076 portp->refcount--; 1056 portp->refcount--;
1077 1057
1078 for (;;) { 1058 for (;;) {
1059 /* Takes brd_lock internally */
1079 stl_setsignals(portp, 1, 1); 1060 stl_setsignals(portp, 1, 1);
1080 if (tty_hung_up_p(filp) || 1061 if (tty_hung_up_p(filp) ||
1081 ((portp->flags & ASYNC_INITIALIZED) == 0)) { 1062 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
@@ -1093,13 +1074,14 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1093 rc = -ERESTARTSYS; 1074 rc = -ERESTARTSYS;
1094 break; 1075 break;
1095 } 1076 }
1077 /* FIXME */
1096 interruptible_sleep_on(&portp->open_wait); 1078 interruptible_sleep_on(&portp->open_wait);
1097 } 1079 }
1098 1080
1099 if (! tty_hung_up_p(filp)) 1081 if (! tty_hung_up_p(filp))
1100 portp->refcount++; 1082 portp->refcount++;
1101 portp->openwaitcnt--; 1083 portp->openwaitcnt--;
1102 restore_flags(flags); 1084 spin_unlock_irqrestore(&stallion_lock, flags);
1103 1085
1104 return rc; 1086 return rc;
1105} 1087}
@@ -1119,16 +1101,15 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1119 if (portp == (stlport_t *) NULL) 1101 if (portp == (stlport_t *) NULL)
1120 return; 1102 return;
1121 1103
1122 save_flags(flags); 1104 spin_lock_irqsave(&stallion_lock, flags);
1123 cli();
1124 if (tty_hung_up_p(filp)) { 1105 if (tty_hung_up_p(filp)) {
1125 restore_flags(flags); 1106 spin_unlock_irqrestore(&stallion_lock, flags);
1126 return; 1107 return;
1127 } 1108 }
1128 if ((tty->count == 1) && (portp->refcount != 1)) 1109 if ((tty->count == 1) && (portp->refcount != 1))
1129 portp->refcount = 1; 1110 portp->refcount = 1;
1130 if (portp->refcount-- > 1) { 1111 if (portp->refcount-- > 1) {
1131 restore_flags(flags); 1112 spin_unlock_irqrestore(&stallion_lock, flags);
1132 return; 1113 return;
1133 } 1114 }
1134 1115
@@ -1142,11 +1123,18 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1142 * (The sc26198 has no "end-of-data" interrupt only empty FIFO) 1123 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1143 */ 1124 */
1144 tty->closing = 1; 1125 tty->closing = 1;
1126
1127 spin_unlock_irqrestore(&stallion_lock, flags);
1128
1145 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1129 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1146 tty_wait_until_sent(tty, portp->closing_wait); 1130 tty_wait_until_sent(tty, portp->closing_wait);
1147 stl_waituntilsent(tty, (HZ / 2)); 1131 stl_waituntilsent(tty, (HZ / 2));
1148 1132
1133
1134 spin_lock_irqsave(&stallion_lock, flags);
1149 portp->flags &= ~ASYNC_INITIALIZED; 1135 portp->flags &= ~ASYNC_INITIALIZED;
1136 spin_unlock_irqrestore(&stallion_lock, flags);
1137
1150 stl_disableintrs(portp); 1138 stl_disableintrs(portp);
1151 if (tty->termios->c_cflag & HUPCL) 1139 if (tty->termios->c_cflag & HUPCL)
1152 stl_setsignals(portp, 0, 0); 1140 stl_setsignals(portp, 0, 0);
@@ -1173,7 +1161,6 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1173 1161
1174 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1162 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1175 wake_up_interruptible(&portp->close_wait); 1163 wake_up_interruptible(&portp->close_wait);
1176 restore_flags(flags);
1177} 1164}
1178 1165
1179/*****************************************************************************/ 1166/*****************************************************************************/
@@ -1195,9 +1182,6 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1195 (int) tty, (int) buf, count); 1182 (int) tty, (int) buf, count);
1196#endif 1183#endif
1197 1184
1198 if ((tty == (struct tty_struct *) NULL) ||
1199 (stl_tmpwritebuf == (char *) NULL))
1200 return 0;
1201 portp = tty->driver_data; 1185 portp = tty->driver_data;
1202 if (portp == (stlport_t *) NULL) 1186 if (portp == (stlport_t *) NULL)
1203 return 0; 1187 return 0;
@@ -1302,11 +1286,6 @@ static void stl_flushchars(struct tty_struct *tty)
1302 if (portp->tx.buf == (char *) NULL) 1286 if (portp->tx.buf == (char *) NULL)
1303 return; 1287 return;
1304 1288
1305#if 0
1306 if (tty->stopped || tty->hw_stopped ||
1307 (portp->tx.head == portp->tx.tail))
1308 return;
1309#endif
1310 stl_startrxtx(portp, -1, 1); 1289 stl_startrxtx(portp, -1, 1);
1311} 1290}
1312 1291
@@ -1977,12 +1956,14 @@ static int stl_eiointr(stlbrd_t *brdp)
1977 unsigned int iobase; 1956 unsigned int iobase;
1978 int handled = 0; 1957 int handled = 0;
1979 1958
1959 spin_lock(&brd_lock);
1980 panelp = brdp->panels[0]; 1960 panelp = brdp->panels[0];
1981 iobase = panelp->iobase; 1961 iobase = panelp->iobase;
1982 while (inb(brdp->iostatus) & EIO_INTRPEND) { 1962 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1983 handled = 1; 1963 handled = 1;
1984 (* panelp->isr)(panelp, iobase); 1964 (* panelp->isr)(panelp, iobase);
1985 } 1965 }
1966 spin_unlock(&brd_lock);
1986 return handled; 1967 return handled;
1987} 1968}
1988 1969
@@ -2168,7 +2149,7 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2168 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL); 2149 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2169 if (!portp) { 2150 if (!portp) {
2170 printk("STALLION: failed to allocate memory " 2151 printk("STALLION: failed to allocate memory "
2171 "(size=%d)\n", sizeof(stlport_t)); 2152 "(size=%Zd)\n", sizeof(stlport_t));
2172 break; 2153 break;
2173 } 2154 }
2174 2155
@@ -2304,7 +2285,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2304 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2285 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2305 if (!panelp) { 2286 if (!panelp) {
2306 printk(KERN_WARNING "STALLION: failed to allocate memory " 2287 printk(KERN_WARNING "STALLION: failed to allocate memory "
2307 "(size=%d)\n", sizeof(stlpanel_t)); 2288 "(size=%Zd)\n", sizeof(stlpanel_t));
2308 return -ENOMEM; 2289 return -ENOMEM;
2309 } 2290 }
2310 2291
@@ -2478,7 +2459,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2478 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2459 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2479 if (!panelp) { 2460 if (!panelp) {
2480 printk("STALLION: failed to allocate memory " 2461 printk("STALLION: failed to allocate memory "
2481 "(size=%d)\n", sizeof(stlpanel_t)); 2462 "(size=%Zd)\n", sizeof(stlpanel_t));
2482 break; 2463 break;
2483 } 2464 }
2484 panelp->magic = STL_PANELMAGIC; 2465 panelp->magic = STL_PANELMAGIC;
@@ -2879,8 +2860,7 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2879 portp->stats.lflags = 0; 2860 portp->stats.lflags = 0;
2880 portp->stats.rxbuffered = 0; 2861 portp->stats.rxbuffered = 0;
2881 2862
2882 save_flags(flags); 2863 spin_lock_irqsave(&stallion_lock, flags);
2883 cli();
2884 if (portp->tty != (struct tty_struct *) NULL) { 2864 if (portp->tty != (struct tty_struct *) NULL) {
2885 if (portp->tty->driver_data == portp) { 2865 if (portp->tty->driver_data == portp) {
2886 portp->stats.ttystate = portp->tty->flags; 2866 portp->stats.ttystate = portp->tty->flags;
@@ -2894,7 +2874,7 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2894 } 2874 }
2895 } 2875 }
2896 } 2876 }
2897 restore_flags(flags); 2877 spin_unlock_irqrestore(&stallion_lock, flags);
2898 2878
2899 head = portp->tx.head; 2879 head = portp->tx.head;
2900 tail = portp->tx.tail; 2880 tail = portp->tx.tail;
@@ -3049,6 +3029,9 @@ static int __init stl_init(void)
3049 int i; 3029 int i;
3050 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion); 3030 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3051 3031
3032 spin_lock_init(&stallion_lock);
3033 spin_lock_init(&brd_lock);
3034
3052 stl_initbrds(); 3035 stl_initbrds();
3053 3036
3054 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); 3037 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -3056,14 +3039,6 @@ static int __init stl_init(void)
3056 return -1; 3039 return -1;
3057 3040
3058/* 3041/*
3059 * Allocate a temporary write buffer.
3060 */
3061 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3062 if (!stl_tmpwritebuf)
3063 printk("STALLION: failed to allocate memory (size=%d)\n",
3064 STL_TXBUFSIZE);
3065
3066/*
3067 * Set up a character driver for per board stuff. This is mainly used 3042 * Set up a character driver for per board stuff. This is mainly used
3068 * to do stats ioctls on the ports. 3043 * to do stats ioctls on the ports.
3069 */ 3044 */
@@ -3147,11 +3122,13 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3147 unsigned int gfrcr; 3122 unsigned int gfrcr;
3148 int chipmask, i, j; 3123 int chipmask, i, j;
3149 int nrchips, uartaddr, ioaddr; 3124 int nrchips, uartaddr, ioaddr;
3125 unsigned long flags;
3150 3126
3151#ifdef DEBUG 3127#ifdef DEBUG
3152 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp); 3128 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3153#endif 3129#endif
3154 3130
3131 spin_lock_irqsave(&brd_lock, flags);
3155 BRDENABLE(panelp->brdnr, panelp->pagenr); 3132 BRDENABLE(panelp->brdnr, panelp->pagenr);
3156 3133
3157/* 3134/*
@@ -3189,6 +3166,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3189 } 3166 }
3190 3167
3191 BRDDISABLE(panelp->brdnr); 3168 BRDDISABLE(panelp->brdnr);
3169 spin_unlock_irqrestore(&brd_lock, flags);
3192 return chipmask; 3170 return chipmask;
3193} 3171}
3194 3172
@@ -3200,6 +3178,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3200 3178
3201static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 3179static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3202{ 3180{
3181 unsigned long flags;
3203#ifdef DEBUG 3182#ifdef DEBUG
3204 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n", 3183 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3205 (int) brdp, (int) panelp, (int) portp); 3184 (int) brdp, (int) panelp, (int) portp);
@@ -3209,6 +3188,7 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3209 (portp == (stlport_t *) NULL)) 3188 (portp == (stlport_t *) NULL))
3210 return; 3189 return;
3211 3190
3191 spin_lock_irqsave(&brd_lock, flags);
3212 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) || 3192 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3213 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE); 3193 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3214 portp->uartaddr = (portp->portnr & 0x04) << 5; 3194 portp->uartaddr = (portp->portnr & 0x04) << 5;
@@ -3219,6 +3199,7 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3219 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3)); 3199 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3220 portp->hwid = stl_cd1400getreg(portp, GFRCR); 3200 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3221 BRDDISABLE(portp->brdnr); 3201 BRDDISABLE(portp->brdnr);
3202 spin_unlock_irqrestore(&brd_lock, flags);
3222} 3203}
3223 3204
3224/*****************************************************************************/ 3205/*****************************************************************************/
@@ -3428,8 +3409,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3428 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3409 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3429#endif 3410#endif
3430 3411
3431 save_flags(flags); 3412 spin_lock_irqsave(&brd_lock, flags);
3432 cli();
3433 BRDENABLE(portp->brdnr, portp->pagenr); 3413 BRDENABLE(portp->brdnr, portp->pagenr);
3434 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3)); 3414 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3435 srer = stl_cd1400getreg(portp, SRER); 3415 srer = stl_cd1400getreg(portp, SRER);
@@ -3466,7 +3446,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3466 portp->sigs &= ~TIOCM_CD; 3446 portp->sigs &= ~TIOCM_CD;
3467 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron)); 3447 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3468 BRDDISABLE(portp->brdnr); 3448 BRDDISABLE(portp->brdnr);
3469 restore_flags(flags); 3449 spin_unlock_irqrestore(&brd_lock, flags);
3470} 3450}
3471 3451
3472/*****************************************************************************/ 3452/*****************************************************************************/
@@ -3492,8 +3472,7 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3492 if (rts > 0) 3472 if (rts > 0)
3493 msvr2 = MSVR2_RTS; 3473 msvr2 = MSVR2_RTS;
3494 3474
3495 save_flags(flags); 3475 spin_lock_irqsave(&brd_lock, flags);
3496 cli();
3497 BRDENABLE(portp->brdnr, portp->pagenr); 3476 BRDENABLE(portp->brdnr, portp->pagenr);
3498 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3477 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3499 if (rts >= 0) 3478 if (rts >= 0)
@@ -3501,7 +3480,7 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3501 if (dtr >= 0) 3480 if (dtr >= 0)
3502 stl_cd1400setreg(portp, MSVR1, msvr1); 3481 stl_cd1400setreg(portp, MSVR1, msvr1);
3503 BRDDISABLE(portp->brdnr); 3482 BRDDISABLE(portp->brdnr);
3504 restore_flags(flags); 3483 spin_unlock_irqrestore(&brd_lock, flags);
3505} 3484}
3506 3485
3507/*****************************************************************************/ 3486/*****************************************************************************/
@@ -3520,14 +3499,13 @@ static int stl_cd1400getsignals(stlport_t *portp)
3520 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp); 3499 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3521#endif 3500#endif
3522 3501
3523 save_flags(flags); 3502 spin_lock_irqsave(&brd_lock, flags);
3524 cli();
3525 BRDENABLE(portp->brdnr, portp->pagenr); 3503 BRDENABLE(portp->brdnr, portp->pagenr);
3526 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3504 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3527 msvr1 = stl_cd1400getreg(portp, MSVR1); 3505 msvr1 = stl_cd1400getreg(portp, MSVR1);
3528 msvr2 = stl_cd1400getreg(portp, MSVR2); 3506 msvr2 = stl_cd1400getreg(portp, MSVR2);
3529 BRDDISABLE(portp->brdnr); 3507 BRDDISABLE(portp->brdnr);
3530 restore_flags(flags); 3508 spin_unlock_irqrestore(&brd_lock, flags);
3531 3509
3532 sigs = 0; 3510 sigs = 0;
3533 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0; 3511 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
@@ -3569,15 +3547,14 @@ static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3569 else if (rx > 0) 3547 else if (rx > 0)
3570 ccr |= CCR_RXENABLE; 3548 ccr |= CCR_RXENABLE;
3571 3549
3572 save_flags(flags); 3550 spin_lock_irqsave(&brd_lock, flags);
3573 cli();
3574 BRDENABLE(portp->brdnr, portp->pagenr); 3551 BRDENABLE(portp->brdnr, portp->pagenr);
3575 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3552 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3576 stl_cd1400ccrwait(portp); 3553 stl_cd1400ccrwait(portp);
3577 stl_cd1400setreg(portp, CCR, ccr); 3554 stl_cd1400setreg(portp, CCR, ccr);
3578 stl_cd1400ccrwait(portp); 3555 stl_cd1400ccrwait(portp);
3579 BRDDISABLE(portp->brdnr); 3556 BRDDISABLE(portp->brdnr);
3580 restore_flags(flags); 3557 spin_unlock_irqrestore(&brd_lock, flags);
3581} 3558}
3582 3559
3583/*****************************************************************************/ 3560/*****************************************************************************/
@@ -3609,8 +3586,7 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3609 else if (rx > 0) 3586 else if (rx > 0)
3610 sreron |= SRER_RXDATA; 3587 sreron |= SRER_RXDATA;
3611 3588
3612 save_flags(flags); 3589 spin_lock_irqsave(&brd_lock, flags);
3613 cli();
3614 BRDENABLE(portp->brdnr, portp->pagenr); 3590 BRDENABLE(portp->brdnr, portp->pagenr);
3615 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3591 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3616 stl_cd1400setreg(portp, SRER, 3592 stl_cd1400setreg(portp, SRER,
@@ -3618,7 +3594,7 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3618 BRDDISABLE(portp->brdnr); 3594 BRDDISABLE(portp->brdnr);
3619 if (tx > 0) 3595 if (tx > 0)
3620 set_bit(ASYI_TXBUSY, &portp->istate); 3596 set_bit(ASYI_TXBUSY, &portp->istate);
3621 restore_flags(flags); 3597 spin_unlock_irqrestore(&brd_lock, flags);
3622} 3598}
3623 3599
3624/*****************************************************************************/ 3600/*****************************************************************************/
@@ -3634,13 +3610,12 @@ static void stl_cd1400disableintrs(stlport_t *portp)
3634#ifdef DEBUG 3610#ifdef DEBUG
3635 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp); 3611 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3636#endif 3612#endif
3637 save_flags(flags); 3613 spin_lock_irqsave(&brd_lock, flags);
3638 cli();
3639 BRDENABLE(portp->brdnr, portp->pagenr); 3614 BRDENABLE(portp->brdnr, portp->pagenr);
3640 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3615 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3641 stl_cd1400setreg(portp, SRER, 0); 3616 stl_cd1400setreg(portp, SRER, 0);
3642 BRDDISABLE(portp->brdnr); 3617 BRDDISABLE(portp->brdnr);
3643 restore_flags(flags); 3618 spin_unlock_irqrestore(&brd_lock, flags);
3644} 3619}
3645 3620
3646/*****************************************************************************/ 3621/*****************************************************************************/
@@ -3653,8 +3628,7 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3653 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len); 3628 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3654#endif 3629#endif
3655 3630
3656 save_flags(flags); 3631 spin_lock_irqsave(&brd_lock, flags);
3657 cli();
3658 BRDENABLE(portp->brdnr, portp->pagenr); 3632 BRDENABLE(portp->brdnr, portp->pagenr);
3659 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3633 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3660 stl_cd1400setreg(portp, SRER, 3634 stl_cd1400setreg(portp, SRER,
@@ -3664,7 +3638,7 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3664 portp->brklen = len; 3638 portp->brklen = len;
3665 if (len == 1) 3639 if (len == 1)
3666 portp->stats.txbreaks++; 3640 portp->stats.txbreaks++;
3667 restore_flags(flags); 3641 spin_unlock_irqrestore(&brd_lock, flags);
3668} 3642}
3669 3643
3670/*****************************************************************************/ 3644/*****************************************************************************/
@@ -3688,8 +3662,7 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3688 if (tty == (struct tty_struct *) NULL) 3662 if (tty == (struct tty_struct *) NULL)
3689 return; 3663 return;
3690 3664
3691 save_flags(flags); 3665 spin_lock_irqsave(&brd_lock, flags);
3692 cli();
3693 BRDENABLE(portp->brdnr, portp->pagenr); 3666 BRDENABLE(portp->brdnr, portp->pagenr);
3694 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3667 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3695 3668
@@ -3729,7 +3702,7 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3729 } 3702 }
3730 3703
3731 BRDDISABLE(portp->brdnr); 3704 BRDDISABLE(portp->brdnr);
3732 restore_flags(flags); 3705 spin_unlock_irqrestore(&brd_lock, flags);
3733} 3706}
3734 3707
3735/*****************************************************************************/ 3708/*****************************************************************************/
@@ -3753,8 +3726,7 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3753 if (tty == (struct tty_struct *) NULL) 3726 if (tty == (struct tty_struct *) NULL)
3754 return; 3727 return;
3755 3728
3756 save_flags(flags); 3729 spin_lock_irqsave(&brd_lock, flags);
3757 cli();
3758 BRDENABLE(portp->brdnr, portp->pagenr); 3730 BRDENABLE(portp->brdnr, portp->pagenr);
3759 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3731 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3760 if (state) { 3732 if (state) {
@@ -3769,7 +3741,7 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3769 stl_cd1400ccrwait(portp); 3741 stl_cd1400ccrwait(portp);
3770 } 3742 }
3771 BRDDISABLE(portp->brdnr); 3743 BRDDISABLE(portp->brdnr);
3772 restore_flags(flags); 3744 spin_unlock_irqrestore(&brd_lock, flags);
3773} 3745}
3774 3746
3775/*****************************************************************************/ 3747/*****************************************************************************/
@@ -3785,8 +3757,7 @@ static void stl_cd1400flush(stlport_t *portp)
3785 if (portp == (stlport_t *) NULL) 3757 if (portp == (stlport_t *) NULL)
3786 return; 3758 return;
3787 3759
3788 save_flags(flags); 3760 spin_lock_irqsave(&brd_lock, flags);
3789 cli();
3790 BRDENABLE(portp->brdnr, portp->pagenr); 3761 BRDENABLE(portp->brdnr, portp->pagenr);
3791 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3762 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3792 stl_cd1400ccrwait(portp); 3763 stl_cd1400ccrwait(portp);
@@ -3794,7 +3765,7 @@ static void stl_cd1400flush(stlport_t *portp)
3794 stl_cd1400ccrwait(portp); 3765 stl_cd1400ccrwait(portp);
3795 portp->tx.tail = portp->tx.head; 3766 portp->tx.tail = portp->tx.head;
3796 BRDDISABLE(portp->brdnr); 3767 BRDDISABLE(portp->brdnr);
3797 restore_flags(flags); 3768 spin_unlock_irqrestore(&brd_lock, flags);
3798} 3769}
3799 3770
3800/*****************************************************************************/ 3771/*****************************************************************************/
@@ -3833,6 +3804,7 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3833 (int) panelp, iobase); 3804 (int) panelp, iobase);
3834#endif 3805#endif
3835 3806
3807 spin_lock(&brd_lock);
3836 outb(SVRR, iobase); 3808 outb(SVRR, iobase);
3837 svrtype = inb(iobase + EREG_DATA); 3809 svrtype = inb(iobase + EREG_DATA);
3838 if (panelp->nrports > 4) { 3810 if (panelp->nrports > 4) {
@@ -3846,6 +3818,8 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3846 stl_cd1400txisr(panelp, iobase); 3818 stl_cd1400txisr(panelp, iobase);
3847 else if (svrtype & SVRR_MDM) 3819 else if (svrtype & SVRR_MDM)
3848 stl_cd1400mdmisr(panelp, iobase); 3820 stl_cd1400mdmisr(panelp, iobase);
3821
3822 spin_unlock(&brd_lock);
3849} 3823}
3850 3824
3851/*****************************************************************************/ 3825/*****************************************************************************/
@@ -4433,8 +4407,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4433 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 4407 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4434#endif 4408#endif
4435 4409
4436 save_flags(flags); 4410 spin_lock_irqsave(&brd_lock, flags);
4437 cli();
4438 BRDENABLE(portp->brdnr, portp->pagenr); 4411 BRDENABLE(portp->brdnr, portp->pagenr);
4439 stl_sc26198setreg(portp, IMR, 0); 4412 stl_sc26198setreg(portp, IMR, 0);
4440 stl_sc26198updatereg(portp, MR0, mr0); 4413 stl_sc26198updatereg(portp, MR0, mr0);
@@ -4461,7 +4434,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4461 portp->imr = (portp->imr & ~imroff) | imron; 4434 portp->imr = (portp->imr & ~imroff) | imron;
4462 stl_sc26198setreg(portp, IMR, portp->imr); 4435 stl_sc26198setreg(portp, IMR, portp->imr);
4463 BRDDISABLE(portp->brdnr); 4436 BRDDISABLE(portp->brdnr);
4464 restore_flags(flags); 4437 spin_unlock_irqrestore(&brd_lock, flags);
4465} 4438}
4466 4439
4467/*****************************************************************************/ 4440/*****************************************************************************/
@@ -4491,13 +4464,12 @@ static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4491 else if (rts > 0) 4464 else if (rts > 0)
4492 iopioron |= IPR_RTS; 4465 iopioron |= IPR_RTS;
4493 4466
4494 save_flags(flags); 4467 spin_lock_irqsave(&brd_lock, flags);
4495 cli();
4496 BRDENABLE(portp->brdnr, portp->pagenr); 4468 BRDENABLE(portp->brdnr, portp->pagenr);
4497 stl_sc26198setreg(portp, IOPIOR, 4469 stl_sc26198setreg(portp, IOPIOR,
4498 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron)); 4470 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4499 BRDDISABLE(portp->brdnr); 4471 BRDDISABLE(portp->brdnr);
4500 restore_flags(flags); 4472 spin_unlock_irqrestore(&brd_lock, flags);
4501} 4473}
4502 4474
4503/*****************************************************************************/ 4475/*****************************************************************************/
@@ -4516,12 +4488,11 @@ static int stl_sc26198getsignals(stlport_t *portp)
4516 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp); 4488 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4517#endif 4489#endif
4518 4490
4519 save_flags(flags); 4491 spin_lock_irqsave(&brd_lock, flags);
4520 cli();
4521 BRDENABLE(portp->brdnr, portp->pagenr); 4492 BRDENABLE(portp->brdnr, portp->pagenr);
4522 ipr = stl_sc26198getreg(portp, IPR); 4493 ipr = stl_sc26198getreg(portp, IPR);
4523 BRDDISABLE(portp->brdnr); 4494 BRDDISABLE(portp->brdnr);
4524 restore_flags(flags); 4495 spin_unlock_irqrestore(&brd_lock, flags);
4525 4496
4526 sigs = 0; 4497 sigs = 0;
4527 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD; 4498 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
@@ -4558,13 +4529,12 @@ static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4558 else if (rx > 0) 4529 else if (rx > 0)
4559 ccr |= CR_RXENABLE; 4530 ccr |= CR_RXENABLE;
4560 4531
4561 save_flags(flags); 4532 spin_lock_irqsave(&brd_lock, flags);
4562 cli();
4563 BRDENABLE(portp->brdnr, portp->pagenr); 4533 BRDENABLE(portp->brdnr, portp->pagenr);
4564 stl_sc26198setreg(portp, SCCR, ccr); 4534 stl_sc26198setreg(portp, SCCR, ccr);
4565 BRDDISABLE(portp->brdnr); 4535 BRDDISABLE(portp->brdnr);
4566 portp->crenable = ccr; 4536 portp->crenable = ccr;
4567 restore_flags(flags); 4537 spin_unlock_irqrestore(&brd_lock, flags);
4568} 4538}
4569 4539
4570/*****************************************************************************/ 4540/*****************************************************************************/
@@ -4593,15 +4563,14 @@ static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4593 else if (rx > 0) 4563 else if (rx > 0)
4594 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG; 4564 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4595 4565
4596 save_flags(flags); 4566 spin_lock_irqsave(&brd_lock, flags);
4597 cli();
4598 BRDENABLE(portp->brdnr, portp->pagenr); 4567 BRDENABLE(portp->brdnr, portp->pagenr);
4599 stl_sc26198setreg(portp, IMR, imr); 4568 stl_sc26198setreg(portp, IMR, imr);
4600 BRDDISABLE(portp->brdnr); 4569 BRDDISABLE(portp->brdnr);
4601 portp->imr = imr; 4570 portp->imr = imr;
4602 if (tx > 0) 4571 if (tx > 0)
4603 set_bit(ASYI_TXBUSY, &portp->istate); 4572 set_bit(ASYI_TXBUSY, &portp->istate);
4604 restore_flags(flags); 4573 spin_unlock_irqrestore(&brd_lock, flags);
4605} 4574}
4606 4575
4607/*****************************************************************************/ 4576/*****************************************************************************/
@@ -4618,13 +4587,12 @@ static void stl_sc26198disableintrs(stlport_t *portp)
4618 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp); 4587 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4619#endif 4588#endif
4620 4589
4621 save_flags(flags); 4590 spin_lock_irqsave(&brd_lock, flags);
4622 cli();
4623 BRDENABLE(portp->brdnr, portp->pagenr); 4591 BRDENABLE(portp->brdnr, portp->pagenr);
4624 portp->imr = 0; 4592 portp->imr = 0;
4625 stl_sc26198setreg(portp, IMR, 0); 4593 stl_sc26198setreg(portp, IMR, 0);
4626 BRDDISABLE(portp->brdnr); 4594 BRDDISABLE(portp->brdnr);
4627 restore_flags(flags); 4595 spin_unlock_irqrestore(&brd_lock, flags);
4628} 4596}
4629 4597
4630/*****************************************************************************/ 4598/*****************************************************************************/
@@ -4637,8 +4605,7 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4637 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len); 4605 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4638#endif 4606#endif
4639 4607
4640 save_flags(flags); 4608 spin_lock_irqsave(&brd_lock, flags);
4641 cli();
4642 BRDENABLE(portp->brdnr, portp->pagenr); 4609 BRDENABLE(portp->brdnr, portp->pagenr);
4643 if (len == 1) { 4610 if (len == 1) {
4644 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK); 4611 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
@@ -4647,7 +4614,7 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4647 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK); 4614 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4648 } 4615 }
4649 BRDDISABLE(portp->brdnr); 4616 BRDDISABLE(portp->brdnr);
4650 restore_flags(flags); 4617 spin_unlock_irqrestore(&brd_lock, flags);
4651} 4618}
4652 4619
4653/*****************************************************************************/ 4620/*****************************************************************************/
@@ -4672,8 +4639,7 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4672 if (tty == (struct tty_struct *) NULL) 4639 if (tty == (struct tty_struct *) NULL)
4673 return; 4640 return;
4674 4641
4675 save_flags(flags); 4642 spin_lock_irqsave(&brd_lock, flags);
4676 cli();
4677 BRDENABLE(portp->brdnr, portp->pagenr); 4643 BRDENABLE(portp->brdnr, portp->pagenr);
4678 4644
4679 if (state) { 4645 if (state) {
@@ -4719,7 +4685,7 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4719 } 4685 }
4720 4686
4721 BRDDISABLE(portp->brdnr); 4687 BRDDISABLE(portp->brdnr);
4722 restore_flags(flags); 4688 spin_unlock_irqrestore(&brd_lock, flags);
4723} 4689}
4724 4690
4725/*****************************************************************************/ 4691/*****************************************************************************/
@@ -4744,8 +4710,7 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4744 if (tty == (struct tty_struct *) NULL) 4710 if (tty == (struct tty_struct *) NULL)
4745 return; 4711 return;
4746 4712
4747 save_flags(flags); 4713 spin_lock_irqsave(&brd_lock, flags);
4748 cli();
4749 BRDENABLE(portp->brdnr, portp->pagenr); 4714 BRDENABLE(portp->brdnr, portp->pagenr);
4750 if (state) { 4715 if (state) {
4751 mr0 = stl_sc26198getreg(portp, MR0); 4716 mr0 = stl_sc26198getreg(portp, MR0);
@@ -4765,7 +4730,7 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4765 stl_sc26198setreg(portp, MR0, mr0); 4730 stl_sc26198setreg(portp, MR0, mr0);
4766 } 4731 }
4767 BRDDISABLE(portp->brdnr); 4732 BRDDISABLE(portp->brdnr);
4768 restore_flags(flags); 4733 spin_unlock_irqrestore(&brd_lock, flags);
4769} 4734}
4770 4735
4771/*****************************************************************************/ 4736/*****************************************************************************/
@@ -4781,14 +4746,13 @@ static void stl_sc26198flush(stlport_t *portp)
4781 if (portp == (stlport_t *) NULL) 4746 if (portp == (stlport_t *) NULL)
4782 return; 4747 return;
4783 4748
4784 save_flags(flags); 4749 spin_lock_irqsave(&brd_lock, flags);
4785 cli();
4786 BRDENABLE(portp->brdnr, portp->pagenr); 4750 BRDENABLE(portp->brdnr, portp->pagenr);
4787 stl_sc26198setreg(portp, SCCR, CR_TXRESET); 4751 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4788 stl_sc26198setreg(portp, SCCR, portp->crenable); 4752 stl_sc26198setreg(portp, SCCR, portp->crenable);
4789 BRDDISABLE(portp->brdnr); 4753 BRDDISABLE(portp->brdnr);
4790 portp->tx.tail = portp->tx.head; 4754 portp->tx.tail = portp->tx.head;
4791 restore_flags(flags); 4755 spin_unlock_irqrestore(&brd_lock, flags);
4792} 4756}
4793 4757
4794/*****************************************************************************/ 4758/*****************************************************************************/
@@ -4815,12 +4779,11 @@ static int stl_sc26198datastate(stlport_t *portp)
4815 if (test_bit(ASYI_TXBUSY, &portp->istate)) 4779 if (test_bit(ASYI_TXBUSY, &portp->istate))
4816 return 1; 4780 return 1;
4817 4781
4818 save_flags(flags); 4782 spin_lock_irqsave(&brd_lock, flags);
4819 cli();
4820 BRDENABLE(portp->brdnr, portp->pagenr); 4783 BRDENABLE(portp->brdnr, portp->pagenr);
4821 sr = stl_sc26198getreg(portp, SR); 4784 sr = stl_sc26198getreg(portp, SR);
4822 BRDDISABLE(portp->brdnr); 4785 BRDDISABLE(portp->brdnr);
4823 restore_flags(flags); 4786 spin_unlock_irqrestore(&brd_lock, flags);
4824 4787
4825 return (sr & SR_TXEMPTY) ? 0 : 1; 4788 return (sr & SR_TXEMPTY) ? 0 : 1;
4826} 4789}
@@ -4878,6 +4841,8 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4878 stlport_t *portp; 4841 stlport_t *portp;
4879 unsigned int iack; 4842 unsigned int iack;
4880 4843
4844 spin_lock(&brd_lock);
4845
4881/* 4846/*
4882 * Work around bug in sc26198 chip... Cannot have A6 address 4847 * Work around bug in sc26198 chip... Cannot have A6 address
4883 * line of UART high, else iack will be returned as 0. 4848 * line of UART high, else iack will be returned as 0.
@@ -4893,6 +4858,8 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4893 stl_sc26198txisr(portp); 4858 stl_sc26198txisr(portp);
4894 else 4859 else
4895 stl_sc26198otherisr(portp, iack); 4860 stl_sc26198otherisr(portp, iack);
4861
4862 spin_unlock(&brd_lock);
4896} 4863}
4897 4864
4898/*****************************************************************************/ 4865/*****************************************************************************/
diff --git a/drivers/char/sx.c b/drivers/char/sx.c
index 3b4747230270..76b9107f7f81 100644
--- a/drivers/char/sx.c
+++ b/drivers/char/sx.c
@@ -2320,7 +2320,7 @@ static int sx_init_portstructs (int nboards, int nports)
2320#ifdef NEW_WRITE_LOCKING 2320#ifdef NEW_WRITE_LOCKING
2321 port->gs.port_write_mutex = MUTEX; 2321 port->gs.port_write_mutex = MUTEX;
2322#endif 2322#endif
2323 port->gs.driver_lock = SPIN_LOCK_UNLOCKED; 2323 spin_lock_init(&port->gs.driver_lock);
2324 /* 2324 /*
2325 * Initializing wait queue 2325 * Initializing wait queue
2326 */ 2326 */
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 8b2a59969868..8d19f7281f0b 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -267,7 +267,6 @@ static struct tty_buffer *tty_buffer_alloc(size_t size)
267 p->used = 0; 267 p->used = 0;
268 p->size = size; 268 p->size = size;
269 p->next = NULL; 269 p->next = NULL;
270 p->active = 0;
271 p->commit = 0; 270 p->commit = 0;
272 p->read = 0; 271 p->read = 0;
273 p->char_buf_ptr = (char *)(p->data); 272 p->char_buf_ptr = (char *)(p->data);
@@ -327,10 +326,9 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
327 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 326 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
328 remove this conditional if its worth it. This would be invisible 327 remove this conditional if its worth it. This would be invisible
329 to the callers */ 328 to the callers */
330 if ((b = tty->buf.tail) != NULL) { 329 if ((b = tty->buf.tail) != NULL)
331 left = b->size - b->used; 330 left = b->size - b->used;
332 b->active = 1; 331 else
333 } else
334 left = 0; 332 left = 0;
335 333
336 if (left < size) { 334 if (left < size) {
@@ -338,12 +336,10 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
338 if ((n = tty_buffer_find(tty, size)) != NULL) { 336 if ((n = tty_buffer_find(tty, size)) != NULL) {
339 if (b != NULL) { 337 if (b != NULL) {
340 b->next = n; 338 b->next = n;
341 b->active = 0;
342 b->commit = b->used; 339 b->commit = b->used;
343 } else 340 } else
344 tty->buf.head = n; 341 tty->buf.head = n;
345 tty->buf.tail = n; 342 tty->buf.tail = n;
346 n->active = 1;
347 } else 343 } else
348 size = left; 344 size = left;
349 } 345 }
@@ -404,10 +400,8 @@ void tty_schedule_flip(struct tty_struct *tty)
404{ 400{
405 unsigned long flags; 401 unsigned long flags;
406 spin_lock_irqsave(&tty->buf.lock, flags); 402 spin_lock_irqsave(&tty->buf.lock, flags);
407 if (tty->buf.tail != NULL) { 403 if (tty->buf.tail != NULL)
408 tty->buf.tail->active = 0;
409 tty->buf.tail->commit = tty->buf.tail->used; 404 tty->buf.tail->commit = tty->buf.tail->used;
410 }
411 spin_unlock_irqrestore(&tty->buf.lock, flags); 405 spin_unlock_irqrestore(&tty->buf.lock, flags);
412 schedule_delayed_work(&tty->buf.work, 1); 406 schedule_delayed_work(&tty->buf.work, 1);
413} 407}
@@ -784,11 +778,8 @@ restart:
784 } 778 }
785 779
786 clear_bit(TTY_LDISC, &tty->flags); 780 clear_bit(TTY_LDISC, &tty->flags);
787 clear_bit(TTY_DONT_FLIP, &tty->flags); 781 if (o_tty)
788 if (o_tty) {
789 clear_bit(TTY_LDISC, &o_tty->flags); 782 clear_bit(TTY_LDISC, &o_tty->flags);
790 clear_bit(TTY_DONT_FLIP, &o_tty->flags);
791 }
792 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 783 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
793 784
794 /* 785 /*
@@ -1955,7 +1946,6 @@ static void release_dev(struct file * filp)
1955 * race with the set_ldisc code path. 1946 * race with the set_ldisc code path.
1956 */ 1947 */
1957 clear_bit(TTY_LDISC, &tty->flags); 1948 clear_bit(TTY_LDISC, &tty->flags);
1958 clear_bit(TTY_DONT_FLIP, &tty->flags);
1959 cancel_delayed_work(&tty->buf.work); 1949 cancel_delayed_work(&tty->buf.work);
1960 1950
1961 /* 1951 /*
@@ -2621,10 +2611,9 @@ int tty_ioctl(struct inode * inode, struct file * file,
2621 tty->driver->break_ctl(tty, 0); 2611 tty->driver->break_ctl(tty, 0);
2622 return 0; 2612 return 0;
2623 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2613 case TCSBRK: /* SVID version: non-zero arg --> no break */
2624 /* 2614 /* non-zero arg means wait for all output data
2625 * XXX is the above comment correct, or the 2615 * to be sent (performed above) but don't send break.
2626 * code below correct? Is this ioctl used at 2616 * This is used by the tcdrain() termios function.
2627 * all by anyone?
2628 */ 2617 */
2629 if (!arg) 2618 if (!arg)
2630 return send_break(tty, 250); 2619 return send_break(tty, 250);
@@ -2776,8 +2765,7 @@ static void flush_to_ldisc(void *private_)
2776 struct tty_struct *tty = (struct tty_struct *) private_; 2765 struct tty_struct *tty = (struct tty_struct *) private_;
2777 unsigned long flags; 2766 unsigned long flags;
2778 struct tty_ldisc *disc; 2767 struct tty_ldisc *disc;
2779 struct tty_buffer *tbuf; 2768 struct tty_buffer *tbuf, *head;
2780 int count;
2781 char *char_buf; 2769 char *char_buf;
2782 unsigned char *flag_buf; 2770 unsigned char *flag_buf;
2783 2771
@@ -2785,32 +2773,37 @@ static void flush_to_ldisc(void *private_)
2785 if (disc == NULL) /* !TTY_LDISC */ 2773 if (disc == NULL) /* !TTY_LDISC */
2786 return; 2774 return;
2787 2775
2788 if (test_bit(TTY_DONT_FLIP, &tty->flags)) {
2789 /*
2790 * Do it after the next timer tick:
2791 */
2792 schedule_delayed_work(&tty->buf.work, 1);
2793 goto out;
2794 }
2795 spin_lock_irqsave(&tty->buf.lock, flags); 2776 spin_lock_irqsave(&tty->buf.lock, flags);
2796 while((tbuf = tty->buf.head) != NULL) { 2777 head = tty->buf.head;
2797 while ((count = tbuf->commit - tbuf->read) != 0) { 2778 if (head != NULL) {
2798 char_buf = tbuf->char_buf_ptr + tbuf->read; 2779 tty->buf.head = NULL;
2799 flag_buf = tbuf->flag_buf_ptr + tbuf->read; 2780 for (;;) {
2800 tbuf->read += count; 2781 int count = head->commit - head->read;
2782 if (!count) {
2783 if (head->next == NULL)
2784 break;
2785 tbuf = head;
2786 head = head->next;
2787 tty_buffer_free(tty, tbuf);
2788 continue;
2789 }
2790 if (!tty->receive_room) {
2791 schedule_delayed_work(&tty->buf.work, 1);
2792 break;
2793 }
2794 if (count > tty->receive_room)
2795 count = tty->receive_room;
2796 char_buf = head->char_buf_ptr + head->read;
2797 flag_buf = head->flag_buf_ptr + head->read;
2798 head->read += count;
2801 spin_unlock_irqrestore(&tty->buf.lock, flags); 2799 spin_unlock_irqrestore(&tty->buf.lock, flags);
2802 disc->receive_buf(tty, char_buf, flag_buf, count); 2800 disc->receive_buf(tty, char_buf, flag_buf, count);
2803 spin_lock_irqsave(&tty->buf.lock, flags); 2801 spin_lock_irqsave(&tty->buf.lock, flags);
2804 } 2802 }
2805 if (tbuf->active) 2803 tty->buf.head = head;
2806 break;
2807 tty->buf.head = tbuf->next;
2808 if (tty->buf.head == NULL)
2809 tty->buf.tail = NULL;
2810 tty_buffer_free(tty, tbuf);
2811 } 2804 }
2812 spin_unlock_irqrestore(&tty->buf.lock, flags); 2805 spin_unlock_irqrestore(&tty->buf.lock, flags);
2813out: 2806
2814 tty_ldisc_deref(disc); 2807 tty_ldisc_deref(disc);
2815} 2808}
2816 2809
@@ -2903,10 +2896,8 @@ void tty_flip_buffer_push(struct tty_struct *tty)
2903{ 2896{
2904 unsigned long flags; 2897 unsigned long flags;
2905 spin_lock_irqsave(&tty->buf.lock, flags); 2898 spin_lock_irqsave(&tty->buf.lock, flags);
2906 if (tty->buf.tail != NULL) { 2899 if (tty->buf.tail != NULL)
2907 tty->buf.tail->active = 0;
2908 tty->buf.tail->commit = tty->buf.tail->used; 2900 tty->buf.tail->commit = tty->buf.tail->used;
2909 }
2910 spin_unlock_irqrestore(&tty->buf.lock, flags); 2901 spin_unlock_irqrestore(&tty->buf.lock, flags);
2911 2902
2912 if (tty->low_latency) 2903 if (tty->low_latency)
diff --git a/drivers/char/vr41xx_giu.c b/drivers/char/vr41xx_giu.c
index 05e6e814d86f..073da48c092e 100644
--- a/drivers/char/vr41xx_giu.c
+++ b/drivers/char/vr41xx_giu.c
@@ -689,9 +689,9 @@ static int __devinit giu_probe(struct platform_device *dev)
689 689
690 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) { 690 for (i = GIU_IRQ_BASE; i <= GIU_IRQ_LAST; i++) {
691 if (i < GIU_IRQ(GIUINT_HIGH_OFFSET)) 691 if (i < GIU_IRQ(GIUINT_HIGH_OFFSET))
692 irq_desc[i].handler = &giuint_low_irq_type; 692 irq_desc[i].chip = &giuint_low_irq_type;
693 else 693 else
694 irq_desc[i].handler = &giuint_high_irq_type; 694 irq_desc[i].chip = &giuint_high_irq_type;
695 } 695 }
696 696
697 return cascade_irq(GIUINT_IRQ, giu_get_irq); 697 return cascade_irq(GIUINT_IRQ, giu_get_irq);
diff --git a/drivers/char/watchdog/at91_wdt.c b/drivers/char/watchdog/at91_wdt.c
index ac83bc4b019a..00080655533d 100644
--- a/drivers/char/watchdog/at91_wdt.c
+++ b/drivers/char/watchdog/at91_wdt.c
@@ -17,14 +17,15 @@
17#include <linux/miscdevice.h> 17#include <linux/miscdevice.h>
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/moduleparam.h> 19#include <linux/moduleparam.h>
20#include <linux/platform_device.h>
20#include <linux/types.h> 21#include <linux/types.h>
21#include <linux/watchdog.h> 22#include <linux/watchdog.h>
22#include <asm/bitops.h> 23#include <asm/bitops.h>
23#include <asm/uaccess.h> 24#include <asm/uaccess.h>
24 25
25 26
26#define WDT_DEFAULT_TIME 5 /* 5 seconds */ 27#define WDT_DEFAULT_TIME 5 /* seconds */
27#define WDT_MAX_TIME 256 /* 256 seconds */ 28#define WDT_MAX_TIME 256 /* seconds */
28 29
29static int wdt_time = WDT_DEFAULT_TIME; 30static int wdt_time = WDT_DEFAULT_TIME;
30static int nowayout = WATCHDOG_NOWAYOUT; 31static int nowayout = WATCHDOG_NOWAYOUT;
@@ -32,8 +33,10 @@ static int nowayout = WATCHDOG_NOWAYOUT;
32module_param(wdt_time, int, 0); 33module_param(wdt_time, int, 0);
33MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="__MODULE_STRING(WDT_DEFAULT_TIME) ")"); 34MODULE_PARM_DESC(wdt_time, "Watchdog time in seconds. (default="__MODULE_STRING(WDT_DEFAULT_TIME) ")");
34 35
36#ifdef CONFIG_WATCHDOG_NOWAYOUT
35module_param(nowayout, int, 0); 37module_param(nowayout, int, 0);
36MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")"); 38MODULE_PARM_DESC(nowayout, "Watchdog cannot be stopped once started (default=" __MODULE_STRING(WATCHDOG_NOWAYOUT) ")");
39#endif
37 40
38 41
39static unsigned long at91wdt_busy; 42static unsigned long at91wdt_busy;
@@ -138,7 +141,7 @@ static int at91_wdt_ioctl(struct inode *inode, struct file *file,
138 case WDIOC_SETTIMEOUT: 141 case WDIOC_SETTIMEOUT:
139 if (get_user(new_value, p)) 142 if (get_user(new_value, p))
140 return -EFAULT; 143 return -EFAULT;
141 144
142 if (at91_wdt_settimeout(new_value)) 145 if (at91_wdt_settimeout(new_value))
143 return -EINVAL; 146 return -EINVAL;
144 147
@@ -196,27 +199,84 @@ static struct miscdevice at91wdt_miscdev = {
196 .fops = &at91wdt_fops, 199 .fops = &at91wdt_fops,
197}; 200};
198 201
199static int __init at91_wdt_init(void) 202static int __init at91wdt_probe(struct platform_device *pdev)
200{ 203{
201 int res; 204 int res;
202 205
203 /* Check that the heartbeat value is within range; if not reset to the default */ 206 if (at91wdt_miscdev.dev)
204 if (at91_wdt_settimeout(wdt_time)) { 207 return -EBUSY;
205 at91_wdt_settimeout(WDT_DEFAULT_TIME); 208 at91wdt_miscdev.dev = &pdev->dev;
206 printk(KERN_INFO "at91_wdt: wdt_time value must be 1 <= wdt_time <= 256, using %d\n", wdt_time);
207 }
208 209
209 res = misc_register(&at91wdt_miscdev); 210 res = misc_register(&at91wdt_miscdev);
210 if (res) 211 if (res)
211 return res; 212 return res;
212 213
213 printk("AT91 Watchdog Timer enabled (%d seconds, nowayout=%d)\n", wdt_time, nowayout); 214 printk("AT91 Watchdog Timer enabled (%d seconds%s)\n", wdt_time, nowayout ? ", nowayout" : "");
214 return 0; 215 return 0;
215} 216}
216 217
218static int __exit at91wdt_remove(struct platform_device *pdev)
219{
220 int res;
221
222 res = misc_deregister(&at91wdt_miscdev);
223 if (!res)
224 at91wdt_miscdev.dev = NULL;
225
226 return res;
227}
228
229static void at91wdt_shutdown(struct platform_device *pdev)
230{
231 at91_wdt_stop();
232}
233
234#ifdef CONFIG_PM
235
236static int at91wdt_suspend(struct platform_device *pdev, pm_message_t message)
237{
238 at91_wdt_stop();
239 return 0;
240}
241
242static int at91wdt_resume(struct platform_device *pdev)
243{
244 if (at91wdt_busy)
245 at91_wdt_start();
246 return 0;
247}
248
249#else
250#define at91wdt_suspend NULL
251#define at91wdt_resume NULL
252#endif
253
254static struct platform_driver at91wdt_driver = {
255 .probe = at91wdt_probe,
256 .remove = __exit_p(at91wdt_remove),
257 .shutdown = at91wdt_shutdown,
258 .suspend = at91wdt_suspend,
259 .resume = at91wdt_resume,
260 .driver = {
261 .name = "at91_wdt",
262 .owner = THIS_MODULE,
263 },
264};
265
266static int __init at91_wdt_init(void)
267{
268 /* Check that the heartbeat value is within range; if not reset to the default */
269 if (at91_wdt_settimeout(wdt_time)) {
270 at91_wdt_settimeout(WDT_DEFAULT_TIME);
271 pr_info("at91_wdt: wdt_time value must be 1 <= wdt_time <= 256, using %d\n", wdt_time);
272 }
273
274 return platform_driver_register(&at91wdt_driver);
275}
276
217static void __exit at91_wdt_exit(void) 277static void __exit at91_wdt_exit(void)
218{ 278{
219 misc_deregister(&at91wdt_miscdev); 279 platform_driver_unregister(&at91wdt_driver);
220} 280}
221 281
222module_init(at91_wdt_init); 282module_init(at91_wdt_init);
diff --git a/drivers/char/watchdog/i8xx_tco.c b/drivers/char/watchdog/i8xx_tco.c
index fa2ba9ebe42a..bfbdbbf3c2f2 100644
--- a/drivers/char/watchdog/i8xx_tco.c
+++ b/drivers/char/watchdog/i8xx_tco.c
@@ -205,6 +205,23 @@ static int tco_timer_set_heartbeat (int t)
205 return 0; 205 return 0;
206} 206}
207 207
208static int tco_timer_get_timeleft (int *time_left)
209{
210 unsigned char val;
211
212 spin_lock(&tco_lock);
213
214 /* read the TCO Timer */
215 val = inb (TCO1_RLD);
216 val &= 0x3f;
217
218 spin_unlock(&tco_lock);
219
220 *time_left = (int)((val * 6) / 10);
221
222 return 0;
223}
224
208/* 225/*
209 * /dev/watchdog handling 226 * /dev/watchdog handling
210 */ 227 */
@@ -272,6 +289,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
272{ 289{
273 int new_options, retval = -EINVAL; 290 int new_options, retval = -EINVAL;
274 int new_heartbeat; 291 int new_heartbeat;
292 int time_left;
275 void __user *argp = (void __user *)arg; 293 void __user *argp = (void __user *)arg;
276 int __user *p = argp; 294 int __user *p = argp;
277 static struct watchdog_info ident = { 295 static struct watchdog_info ident = {
@@ -320,7 +338,7 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
320 return -EFAULT; 338 return -EFAULT;
321 339
322 if (tco_timer_set_heartbeat(new_heartbeat)) 340 if (tco_timer_set_heartbeat(new_heartbeat))
323 return -EINVAL; 341 return -EINVAL;
324 342
325 tco_timer_keepalive (); 343 tco_timer_keepalive ();
326 /* Fall */ 344 /* Fall */
@@ -329,6 +347,14 @@ static int i8xx_tco_ioctl (struct inode *inode, struct file *file,
329 case WDIOC_GETTIMEOUT: 347 case WDIOC_GETTIMEOUT:
330 return put_user(heartbeat, p); 348 return put_user(heartbeat, p);
331 349
350 case WDIOC_GETTIMELEFT:
351 {
352 if (tco_timer_get_timeleft(&time_left))
353 return -EINVAL;
354
355 return put_user(time_left, p);
356 }
357
332 default: 358 default:
333 return -ENOIOCTLCMD; 359 return -ENOIOCTLCMD;
334 } 360 }
diff --git a/drivers/char/watchdog/pcwd_pci.c b/drivers/char/watchdog/pcwd_pci.c
index 2451edbefece..1f40ecefbf72 100644
--- a/drivers/char/watchdog/pcwd_pci.c
+++ b/drivers/char/watchdog/pcwd_pci.c
@@ -21,7 +21,7 @@
21 */ 21 */
22 22
23/* 23/*
24 * A bells and whistles driver is available from: 24 * A bells and whistles driver is available from:
25 * http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/ 25 * http://www.kernel.org/pub/linux/kernel/people/wim/pcwd/pcwd_pci/
26 * 26 *
27 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/ 27 * More info available at http://www.berkprod.com/ or http://www.pcwatchdog.com/
@@ -390,6 +390,24 @@ static int pcipcwd_get_temperature(int *temperature)
390 return 0; 390 return 0;
391} 391}
392 392
393static int pcipcwd_get_timeleft(int *time_left)
394{
395 int msb;
396 int lsb;
397
398 /* Read the time that's left before rebooting */
399 /* Note: if the board is not yet armed then we will read 0xFFFF */
400 send_command(CMD_READ_WATCHDOG_TIMEOUT, &msb, &lsb);
401
402 *time_left = (msb << 8) + lsb;
403
404 if (debug >= VERBOSE)
405 printk(KERN_DEBUG PFX "Time left before next reboot: %d\n",
406 *time_left);
407
408 return 0;
409}
410
393/* 411/*
394 * /dev/watchdog handling 412 * /dev/watchdog handling
395 */ 413 */
@@ -512,6 +530,16 @@ static int pcipcwd_ioctl(struct inode *inode, struct file *file,
512 case WDIOC_GETTIMEOUT: 530 case WDIOC_GETTIMEOUT:
513 return put_user(heartbeat, p); 531 return put_user(heartbeat, p);
514 532
533 case WDIOC_GETTIMELEFT:
534 {
535 int time_left;
536
537 if (pcipcwd_get_timeleft(&time_left))
538 return -EFAULT;
539
540 return put_user(time_left, p);
541 }
542
515 default: 543 default:
516 return -ENOIOCTLCMD; 544 return -ENOIOCTLCMD;
517 } 545 }
diff --git a/drivers/char/watchdog/pcwd_usb.c b/drivers/char/watchdog/pcwd_usb.c
index 3fdfda9324fa..0d072bed501d 100644
--- a/drivers/char/watchdog/pcwd_usb.c
+++ b/drivers/char/watchdog/pcwd_usb.c
@@ -317,6 +317,19 @@ static int usb_pcwd_get_temperature(struct usb_pcwd_private *usb_pcwd, int *temp
317 return 0; 317 return 0;
318} 318}
319 319
320static int usb_pcwd_get_timeleft(struct usb_pcwd_private *usb_pcwd, int *time_left)
321{
322 unsigned char msb, lsb;
323
324 /* Read the time that's left before rebooting */
325 /* Note: if the board is not yet armed then we will read 0xFFFF */
326 usb_pcwd_send_command(usb_pcwd, CMD_READ_WATCHDOG_TIMEOUT, &msb, &lsb);
327
328 *time_left = (msb << 8) + lsb;
329
330 return 0;
331}
332
320/* 333/*
321 * /dev/watchdog handling 334 * /dev/watchdog handling
322 */ 335 */
@@ -422,6 +435,16 @@ static int usb_pcwd_ioctl(struct inode *inode, struct file *file,
422 case WDIOC_GETTIMEOUT: 435 case WDIOC_GETTIMEOUT:
423 return put_user(heartbeat, p); 436 return put_user(heartbeat, p);
424 437
438 case WDIOC_GETTIMELEFT:
439 {
440 int time_left;
441
442 if (usb_pcwd_get_timeleft(usb_pcwd_device, &time_left))
443 return -EFAULT;
444
445 return put_user(time_left, p);
446 }
447
425 default: 448 default:
426 return -ENOIOCTLCMD; 449 return -ENOIOCTLCMD;
427 } 450 }