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/Kconfig1
-rw-r--r--drivers/char/agp/amd-k7-agp.c2
-rw-r--r--drivers/char/agp/amd64-agp.c2
-rw-r--r--drivers/char/agp/ati-agp.c35
-rw-r--r--drivers/char/agp/efficeon-agp.c2
-rw-r--r--drivers/char/agp/nvidia-agp.c27
-rw-r--r--drivers/char/agp/sgi-agp.c5
-rw-r--r--drivers/char/applicom.c9
-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.c16
-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/rio/riointr.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/tlclk.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
36 files changed, 1617 insertions, 1547 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/Kconfig b/drivers/char/agp/Kconfig
index 9826a399fa02..22f8cf218cc6 100644
--- a/drivers/char/agp/Kconfig
+++ b/drivers/char/agp/Kconfig
@@ -1,6 +1,7 @@
1config AGP 1config AGP
2 tristate "/dev/agpgart (AGP Support)" 2 tristate "/dev/agpgart (AGP Support)"
3 depends on ALPHA || IA64 || PPC || X86 3 depends on ALPHA || IA64 || PPC || X86
4 depends on PCI
4 ---help--- 5 ---help---
5 AGP (Accelerated Graphics Port) is a bus system mainly used to 6 AGP (Accelerated Graphics Port) is a bus system mainly used to
6 connect graphics cards to the rest of the system. 7 connect graphics cards to the rest of the system.
diff --git a/drivers/char/agp/amd-k7-agp.c b/drivers/char/agp/amd-k7-agp.c
index 1f776651ac64..51d0d562d01e 100644
--- a/drivers/char/agp/amd-k7-agp.c
+++ b/drivers/char/agp/amd-k7-agp.c
@@ -118,7 +118,7 @@ static int amd_create_gatt_pages(int nr_tables)
118 return retval; 118 return retval;
119} 119}
120 120
121/* Since we don't need contigious memory we just try 121/* Since we don't need contiguous memory we just try
122 * to get the gatt table once 122 * to get the gatt table once
123 */ 123 */
124 124
diff --git a/drivers/char/agp/amd64-agp.c b/drivers/char/agp/amd64-agp.c
index f690ee8cb732..f74eeeb8e377 100644
--- a/drivers/char/agp/amd64-agp.c
+++ b/drivers/char/agp/amd64-agp.c
@@ -734,7 +734,7 @@ int __init agp_amd64_init(void)
734 734
735 if (agp_off) 735 if (agp_off)
736 return -EINVAL; 736 return -EINVAL;
737 if (pci_register_driver(&agp_amd64_pci_driver) > 0) { 737 if (pci_register_driver(&agp_amd64_pci_driver) < 0) {
738 struct pci_dev *dev; 738 struct pci_dev *dev;
739 if (!agp_try_unsupported && !agp_try_unsupported_boot) { 739 if (!agp_try_unsupported && !agp_try_unsupported_boot) {
740 printk(KERN_INFO PFX "No supported AGP bridge found.\n"); 740 printk(KERN_INFO PFX "No supported AGP bridge found.\n");
diff --git a/drivers/char/agp/ati-agp.c b/drivers/char/agp/ati-agp.c
index 06fd10ba0c5e..f244c6682738 100644
--- a/drivers/char/agp/ati-agp.c
+++ b/drivers/char/agp/ati-agp.c
@@ -41,7 +41,6 @@ static struct gatt_mask ati_generic_masks[] =
41}; 41};
42 42
43 43
44
45typedef struct _ati_page_map { 44typedef struct _ati_page_map {
46 unsigned long *real; 45 unsigned long *real;
47 unsigned long __iomem *remapped; 46 unsigned long __iomem *remapped;
@@ -141,7 +140,8 @@ static int ati_create_gatt_pages(int nr_tables)
141 ati_generic_private.num_tables = nr_tables; 140 ati_generic_private.num_tables = nr_tables;
142 ati_generic_private.gatt_pages = tables; 141 ati_generic_private.gatt_pages = tables;
143 142
144 if (retval != 0) ati_free_gatt_pages(); 143 if (retval != 0)
144 ati_free_gatt_pages();
145 145
146 return retval; 146 return retval;
147} 147}
@@ -219,16 +219,16 @@ static int ati_configure(void)
219 ati_generic_private.registers = (volatile u8 __iomem *) ioremap(temp, 4096); 219 ati_generic_private.registers = (volatile u8 __iomem *) ioremap(temp, 4096);
220 220
221 if (is_r200()) 221 if (is_r200())
222 pci_write_config_dword(agp_bridge->dev, ATI_RS100_IG_AGPMODE, 0x20000); 222 pci_write_config_dword(agp_bridge->dev, ATI_RS100_IG_AGPMODE, 0x20000);
223 else 223 else
224 pci_write_config_dword(agp_bridge->dev, ATI_RS300_IG_AGPMODE, 0x20000); 224 pci_write_config_dword(agp_bridge->dev, ATI_RS300_IG_AGPMODE, 0x20000);
225 225
226 /* address to map too */ 226 /* address to map too */
227 /* 227 /*
228 pci_read_config_dword(agp_bridge.dev, AGP_APBASE, &temp); 228 pci_read_config_dword(agp_bridge.dev, AGP_APBASE, &temp);
229 agp_bridge.gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK); 229 agp_bridge.gart_bus_addr = (temp & PCI_BASE_ADDRESS_MEM_MASK);
230 printk(KERN_INFO PFX "IGP320 gart_bus_addr: %x\n", agp_bridge.gart_bus_addr); 230 printk(KERN_INFO PFX "IGP320 gart_bus_addr: %x\n", agp_bridge.gart_bus_addr);
231 */ 231 */
232 writel(0x60000, ati_generic_private.registers+ATI_GART_FEATURE_ID); 232 writel(0x60000, ati_generic_private.registers+ATI_GART_FEATURE_ID);
233 readl(ati_generic_private.registers+ATI_GART_FEATURE_ID); /* PCI Posting.*/ 233 readl(ati_generic_private.registers+ATI_GART_FEATURE_ID); /* PCI Posting.*/
234 234
@@ -245,23 +245,25 @@ static int ati_configure(void)
245 245
246 246
247#ifdef CONFIG_PM 247#ifdef CONFIG_PM
248static int agp_ati_resume(struct pci_dev *dev) 248static int agp_ati_suspend(struct pci_dev *dev, pm_message_t state)
249{ 249{
250 pci_restore_state(dev); 250 pci_save_state(dev);
251 pci_set_power_state(dev, 3);
251 252
252 return ati_configure(); 253 return 0;
253} 254}
254 255
255static int agp_ati_suspend(struct pci_dev *dev, pm_message_t state) 256static int agp_ati_resume(struct pci_dev *dev)
256{ 257{
257 pci_save_state(dev); 258 pci_set_power_state(dev, 0);
259 pci_restore_state(dev);
258 260
259 return 0; 261 return ati_configure();
260} 262}
261#endif 263#endif
262 264
263/* 265/*
264 *Since we don't need contigious memory we just try 266 *Since we don't need contiguous memory we just try
265 * to get the gatt table once 267 * to get the gatt table once
266 */ 268 */
267 269
@@ -321,9 +323,9 @@ static int ati_remove_memory(struct agp_memory * mem, off_t pg_start,
321 unsigned long __iomem *cur_gatt; 323 unsigned long __iomem *cur_gatt;
322 unsigned long addr; 324 unsigned long addr;
323 325
324 if (type != 0 || mem->type != 0) { 326 if (type != 0 || mem->type != 0)
325 return -EINVAL; 327 return -EINVAL;
326 } 328
327 for (i = pg_start; i < (mem->page_count + pg_start); i++) { 329 for (i = pg_start; i < (mem->page_count + pg_start); i++) {
328 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr; 330 addr = (i * PAGE_SIZE) + agp_bridge->gart_bus_addr;
329 cur_gatt = GET_GATT(addr); 331 cur_gatt = GET_GATT(addr);
@@ -502,9 +504,8 @@ found:
502 504
503 bridge->dev = pdev; 505 bridge->dev = pdev;
504 bridge->capndx = cap_ptr; 506 bridge->capndx = cap_ptr;
505
506 bridge->driver = &ati_generic_bridge;
507 507
508 bridge->driver = &ati_generic_bridge;
508 509
509 printk(KERN_INFO PFX "Detected Ati %s chipset\n", 510 printk(KERN_INFO PFX "Detected Ati %s chipset\n",
510 devs[j].chipset_name); 511 devs[j].chipset_name);
@@ -546,8 +547,8 @@ static struct pci_driver agp_ati_pci_driver = {
546 .probe = agp_ati_probe, 547 .probe = agp_ati_probe,
547 .remove = agp_ati_remove, 548 .remove = agp_ati_remove,
548#ifdef CONFIG_PM 549#ifdef CONFIG_PM
549 .resume = agp_ati_resume,
550 .suspend = agp_ati_suspend, 550 .suspend = agp_ati_suspend,
551 .resume = agp_ati_resume,
551#endif 552#endif
552}; 553};
553 554
diff --git a/drivers/char/agp/efficeon-agp.c b/drivers/char/agp/efficeon-agp.c
index 86a966b65236..b788b0a3bbf3 100644
--- a/drivers/char/agp/efficeon-agp.c
+++ b/drivers/char/agp/efficeon-agp.c
@@ -177,7 +177,7 @@ static int efficeon_free_gatt_table(struct agp_bridge_data *bridge)
177 177
178 178
179/* 179/*
180 * Since we don't need contigious memory we just try 180 * Since we don't need contiguous memory we just try
181 * to get the gatt table once 181 * to get the gatt table once
182 */ 182 */
183 183
diff --git a/drivers/char/agp/nvidia-agp.c b/drivers/char/agp/nvidia-agp.c
index 4c67135c12d8..df7f37b2739a 100644
--- a/drivers/char/agp/nvidia-agp.c
+++ b/drivers/char/agp/nvidia-agp.c
@@ -376,6 +376,29 @@ static void __devexit agp_nvidia_remove(struct pci_dev *pdev)
376 agp_put_bridge(bridge); 376 agp_put_bridge(bridge);
377} 377}
378 378
379#ifdef CONFIG_PM
380static int agp_nvidia_suspend(struct pci_dev *pdev, pm_message_t state)
381{
382 pci_save_state (pdev);
383 pci_set_power_state (pdev, 3);
384
385 return 0;
386}
387
388static int agp_nvidia_resume(struct pci_dev *pdev)
389{
390 /* set power state 0 and restore PCI space */
391 pci_set_power_state (pdev, 0);
392 pci_restore_state(pdev);
393
394 /* reconfigure AGP hardware again */
395 nvidia_configure();
396
397 return 0;
398}
399#endif
400
401
379static struct pci_device_id agp_nvidia_pci_table[] = { 402static struct pci_device_id agp_nvidia_pci_table[] = {
380 { 403 {
381 .class = (PCI_CLASS_BRIDGE_HOST << 8), 404 .class = (PCI_CLASS_BRIDGE_HOST << 8),
@@ -403,6 +426,10 @@ static struct pci_driver agp_nvidia_pci_driver = {
403 .id_table = agp_nvidia_pci_table, 426 .id_table = agp_nvidia_pci_table,
404 .probe = agp_nvidia_probe, 427 .probe = agp_nvidia_probe,
405 .remove = agp_nvidia_remove, 428 .remove = agp_nvidia_remove,
429#ifdef CONFIG_PM
430 .suspend = agp_nvidia_suspend,
431 .resume = agp_nvidia_resume,
432#endif
406}; 433};
407 434
408static int __init agp_nvidia_init(void) 435static int __init agp_nvidia_init(void)
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/applicom.c b/drivers/char/applicom.c
index 9275d5e52e6d..72fb60765c45 100644
--- a/drivers/char/applicom.c
+++ b/drivers/char/applicom.c
@@ -209,13 +209,16 @@ static int __init applicom_init(void)
209 RamIO = ioremap(dev->resource[0].start, LEN_RAM_IO); 209 RamIO = ioremap(dev->resource[0].start, LEN_RAM_IO);
210 210
211 if (!RamIO) { 211 if (!RamIO) {
212 printk(KERN_INFO "ac.o: Failed to ioremap PCI memory space at 0x%lx\n", dev->resource[0].start); 212 printk(KERN_INFO "ac.o: Failed to ioremap PCI memory "
213 "space at 0x%llx\n",
214 (unsigned long long)dev->resource[0].start);
213 pci_disable_device(dev); 215 pci_disable_device(dev);
214 return -EIO; 216 return -EIO;
215 } 217 }
216 218
217 printk(KERN_INFO "Applicom %s found at mem 0x%lx, irq %d\n", 219 printk(KERN_INFO "Applicom %s found at mem 0x%llx, irq %d\n",
218 applicom_pci_devnames[dev->device-1], dev->resource[0].start, 220 applicom_pci_devnames[dev->device-1],
221 (unsigned long long)dev->resource[0].start,
219 dev->irq); 222 dev->irq);
220 223
221 boardno = ac_register_board(dev->resource[0].start, RamIO,0); 224 boardno = ac_register_board(dev->resource[0].start, RamIO,0);
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 881d7426fda1..d0b3890d9302 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 2019175a2227..130dedc37568 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 23028559dbc4..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
@@ -3674,7 +3673,7 @@ static void send_panic_events(char *str)
3674} 3673}
3675#endif /* CONFIG_IPMI_PANIC_EVENT */ 3674#endif /* CONFIG_IPMI_PANIC_EVENT */
3676 3675
3677static int has_paniced = 0; 3676static int has_panicked = 0;
3678 3677
3679static int panic_event(struct notifier_block *this, 3678static int panic_event(struct notifier_block *this,
3680 unsigned long event, 3679 unsigned long event,
@@ -3683,9 +3682,9 @@ static int panic_event(struct notifier_block *this,
3683 int i; 3682 int i;
3684 ipmi_smi_t intf; 3683 ipmi_smi_t intf;
3685 3684
3686 if (has_paniced) 3685 if (has_panicked)
3687 return NOTIFY_DONE; 3686 return NOTIFY_DONE;
3688 has_paniced = 1; 3687 has_panicked = 1;
3689 3688
3690 /* For every registered interface, set it to run to completion. */ 3689 /* For every registered interface, set it to run to completion. */
3691 for (i = 0; i < MAX_IPMI_INTERFACES; i++) { 3690 for (i = 0; i < MAX_IPMI_INTERFACES; i++) {
@@ -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 1386d6a519d6..c74e5660a9b7 100644
--- a/drivers/char/istallion.c
+++ b/drivers/char/istallion.c
@@ -41,13 +41,12 @@
41#include <linux/init.h> 41#include <linux/init.h>
42#include <linux/device.h> 42#include <linux/device.h>
43#include <linux/wait.h> 43#include <linux/wait.h>
44#include <linux/eisa.h>
44 45
45#include <asm/io.h> 46#include <asm/io.h>
46#include <asm/uaccess.h> 47#include <asm/uaccess.h>
47 48
48#ifdef CONFIG_PCI
49#include <linux/pci.h> 49#include <linux/pci.h>
50#endif
51 50
52/*****************************************************************************/ 51/*****************************************************************************/
53 52
@@ -136,6 +135,10 @@ static stlconf_t stli_brdconf[] = {
136 135
137static int stli_nrbrds = ARRAY_SIZE(stli_brdconf); 136static int stli_nrbrds = ARRAY_SIZE(stli_brdconf);
138 137
138/* stli_lock must NOT be taken holding brd_lock */
139static spinlock_t stli_lock; /* TTY logic lock */
140static spinlock_t brd_lock; /* Board logic lock */
141
139/* 142/*
140 * There is some experimental EISA board detection code in this driver. 143 * There is some experimental EISA board detection code in this driver.
141 * By default it is disabled, but for those that want to try it out, 144 * By default it is disabled, but for those that want to try it out,
@@ -172,14 +175,6 @@ static char *stli_serialname = "ttyE";
172 175
173static struct tty_driver *stli_serial; 176static struct tty_driver *stli_serial;
174 177
175/*
176 * We will need to allocate a temporary write buffer for chars that
177 * come direct from user space. The problem is that a copy from user
178 * space might cause a page fault (typically on a system that is
179 * swapping!). All ports will share one buffer - since if the system
180 * is already swapping a shared buffer won't make things any worse.
181 */
182static char *stli_tmpwritebuf;
183 178
184#define STLI_TXBUFSIZE 4096 179#define STLI_TXBUFSIZE 4096
185 180
@@ -418,7 +413,7 @@ static int stli_eisamempsize = ARRAY_SIZE(stli_eisamemprobeaddrs);
418#endif 413#endif
419 414
420static struct pci_device_id istallion_pci_tbl[] = { 415static struct pci_device_id istallion_pci_tbl[] = {
421 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 416 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA), },
422 { 0 } 417 { 0 }
423}; 418};
424MODULE_DEVICE_TABLE(pci, istallion_pci_tbl); 419MODULE_DEVICE_TABLE(pci, istallion_pci_tbl);
@@ -681,7 +676,7 @@ static int stli_startbrd(stlibrd_t *brdp);
681static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp); 676static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp);
682static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp); 677static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp);
683static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg); 678static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
684static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp); 679static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp);
685static void stli_poll(unsigned long arg); 680static void stli_poll(unsigned long arg);
686static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp); 681static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp);
687static int stli_initopen(stlibrd_t *brdp, stliport_t *portp); 682static int stli_initopen(stlibrd_t *brdp, stliport_t *portp);
@@ -692,7 +687,8 @@ static void stli_dohangup(void *arg);
692static int stli_setport(stliport_t *portp); 687static int stli_setport(stliport_t *portp);
693static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 688static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
694static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback); 689static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
695static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp); 690static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback);
691static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp);
696static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp); 692static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp);
697static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts); 693static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts);
698static long stli_mktiocm(unsigned long sigvalue); 694static long stli_mktiocm(unsigned long sigvalue);
@@ -798,18 +794,8 @@ static struct class *istallion_class;
798 794
799static int __init istallion_module_init(void) 795static int __init istallion_module_init(void)
800{ 796{
801 unsigned long flags;
802
803#ifdef DEBUG
804 printk("init_module()\n");
805#endif
806
807 save_flags(flags);
808 cli();
809 stli_init(); 797 stli_init();
810 restore_flags(flags); 798 return 0;
811
812 return(0);
813} 799}
814 800
815/*****************************************************************************/ 801/*****************************************************************************/
@@ -818,33 +804,24 @@ static void __exit istallion_module_exit(void)
818{ 804{
819 stlibrd_t *brdp; 805 stlibrd_t *brdp;
820 stliport_t *portp; 806 stliport_t *portp;
821 unsigned long flags;
822 int i, j; 807 int i, j;
823 808
824#ifdef DEBUG
825 printk("cleanup_module()\n");
826#endif
827
828 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle, 809 printk(KERN_INFO "Unloading %s: version %s\n", stli_drvtitle,
829 stli_drvversion); 810 stli_drvversion);
830 811
831 save_flags(flags); 812 /*
832 cli(); 813 * Free up all allocated resources used by the ports. This includes
833 814 * memory and interrupts.
834/* 815 */
835 * Free up all allocated resources used by the ports. This includes
836 * memory and interrupts.
837 */
838 if (stli_timeron) { 816 if (stli_timeron) {
839 stli_timeron = 0; 817 stli_timeron = 0;
840 del_timer(&stli_timerlist); 818 del_timer_sync(&stli_timerlist);
841 } 819 }
842 820
843 i = tty_unregister_driver(stli_serial); 821 i = tty_unregister_driver(stli_serial);
844 if (i) { 822 if (i) {
845 printk("STALLION: failed to un-register tty driver, " 823 printk("STALLION: failed to un-register tty driver, "
846 "errno=%d\n", -i); 824 "errno=%d\n", -i);
847 restore_flags(flags);
848 return; 825 return;
849 } 826 }
850 put_tty_driver(stli_serial); 827 put_tty_driver(stli_serial);
@@ -855,16 +832,15 @@ static void __exit istallion_module_exit(void)
855 printk("STALLION: failed to un-register serial memory device, " 832 printk("STALLION: failed to un-register serial memory device, "
856 "errno=%d\n", -i); 833 "errno=%d\n", -i);
857 834
858 kfree(stli_tmpwritebuf);
859 kfree(stli_txcookbuf); 835 kfree(stli_txcookbuf);
860 836
861 for (i = 0; (i < stli_nrbrds); i++) { 837 for (i = 0; (i < stli_nrbrds); i++) {
862 if ((brdp = stli_brds[i]) == (stlibrd_t *) NULL) 838 if ((brdp = stli_brds[i]) == NULL)
863 continue; 839 continue;
864 for (j = 0; (j < STL_MAXPORTS); j++) { 840 for (j = 0; (j < STL_MAXPORTS); j++) {
865 portp = brdp->ports[j]; 841 portp = brdp->ports[j];
866 if (portp != (stliport_t *) NULL) { 842 if (portp != NULL) {
867 if (portp->tty != (struct tty_struct *) NULL) 843 if (portp->tty != NULL)
868 tty_hangup(portp->tty); 844 tty_hangup(portp->tty);
869 kfree(portp); 845 kfree(portp);
870 } 846 }
@@ -874,10 +850,8 @@ static void __exit istallion_module_exit(void)
874 if (brdp->iosize > 0) 850 if (brdp->iosize > 0)
875 release_region(brdp->iobase, brdp->iosize); 851 release_region(brdp->iobase, brdp->iosize);
876 kfree(brdp); 852 kfree(brdp);
877 stli_brds[i] = (stlibrd_t *) NULL; 853 stli_brds[i] = NULL;
878 } 854 }
879
880 restore_flags(flags);
881} 855}
882 856
883module_init(istallion_module_init); 857module_init(istallion_module_init);
@@ -891,19 +865,15 @@ module_exit(istallion_module_exit);
891 865
892static void stli_argbrds(void) 866static void stli_argbrds(void)
893{ 867{
894 stlconf_t conf; 868 stlconf_t conf;
895 stlibrd_t *brdp; 869 stlibrd_t *brdp;
896 int i; 870 int i;
897
898#ifdef DEBUG
899 printk("stli_argbrds()\n");
900#endif
901 871
902 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) { 872 for (i = stli_nrbrds; i < ARRAY_SIZE(stli_brdsp); i++) {
903 memset(&conf, 0, sizeof(conf)); 873 memset(&conf, 0, sizeof(conf));
904 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0) 874 if (stli_parsebrd(&conf, stli_brdsp[i]) == 0)
905 continue; 875 continue;
906 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 876 if ((brdp = stli_allocbrd()) == NULL)
907 continue; 877 continue;
908 stli_nrbrds = i + 1; 878 stli_nrbrds = i + 1;
909 brdp->brdnr = i; 879 brdp->brdnr = i;
@@ -922,9 +892,9 @@ static void stli_argbrds(void)
922 892
923static unsigned long stli_atol(char *str) 893static unsigned long stli_atol(char *str)
924{ 894{
925 unsigned long val; 895 unsigned long val;
926 int base, c; 896 int base, c;
927 char *sp; 897 char *sp;
928 898
929 val = 0; 899 val = 0;
930 sp = str; 900 sp = str;
@@ -958,15 +928,11 @@ static unsigned long stli_atol(char *str)
958 928
959static int stli_parsebrd(stlconf_t *confp, char **argp) 929static int stli_parsebrd(stlconf_t *confp, char **argp)
960{ 930{
961 char *sp; 931 char *sp;
962 int i; 932 int i;
963
964#ifdef DEBUG
965 printk("stli_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
966#endif
967 933
968 if ((argp[0] == (char *) NULL) || (*argp[0] == 0)) 934 if (argp[0] == NULL || *argp[0] == 0)
969 return(0); 935 return 0;
970 936
971 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++) 937 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
972 *sp = TOLOWER(*sp); 938 *sp = TOLOWER(*sp);
@@ -981,9 +947,9 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
981 } 947 }
982 948
983 confp->brdtype = stli_brdstr[i].type; 949 confp->brdtype = stli_brdstr[i].type;
984 if ((argp[1] != (char *) NULL) && (*argp[1] != 0)) 950 if (argp[1] != NULL && *argp[1] != 0)
985 confp->ioaddr1 = stli_atol(argp[1]); 951 confp->ioaddr1 = stli_atol(argp[1]);
986 if ((argp[2] != (char *) NULL) && (*argp[2] != 0)) 952 if (argp[2] != NULL && *argp[2] != 0)
987 confp->memaddr = stli_atol(argp[2]); 953 confp->memaddr = stli_atol(argp[2]);
988 return(1); 954 return(1);
989} 955}
@@ -994,34 +960,29 @@ static int stli_parsebrd(stlconf_t *confp, char **argp)
994 960
995static int stli_open(struct tty_struct *tty, struct file *filp) 961static int stli_open(struct tty_struct *tty, struct file *filp)
996{ 962{
997 stlibrd_t *brdp; 963 stlibrd_t *brdp;
998 stliport_t *portp; 964 stliport_t *portp;
999 unsigned int minordev; 965 unsigned int minordev;
1000 int brdnr, portnr, rc; 966 int brdnr, portnr, rc;
1001
1002#ifdef DEBUG
1003 printk("stli_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1004 (int) filp, tty->name);
1005#endif
1006 967
1007 minordev = tty->index; 968 minordev = tty->index;
1008 brdnr = MINOR2BRD(minordev); 969 brdnr = MINOR2BRD(minordev);
1009 if (brdnr >= stli_nrbrds) 970 if (brdnr >= stli_nrbrds)
1010 return(-ENODEV); 971 return -ENODEV;
1011 brdp = stli_brds[brdnr]; 972 brdp = stli_brds[brdnr];
1012 if (brdp == (stlibrd_t *) NULL) 973 if (brdp == NULL)
1013 return(-ENODEV); 974 return -ENODEV;
1014 if ((brdp->state & BST_STARTED) == 0) 975 if ((brdp->state & BST_STARTED) == 0)
1015 return(-ENODEV); 976 return -ENODEV;
1016 portnr = MINOR2PORT(minordev); 977 portnr = MINOR2PORT(minordev);
1017 if ((portnr < 0) || (portnr > brdp->nrports)) 978 if ((portnr < 0) || (portnr > brdp->nrports))
1018 return(-ENODEV); 979 return -ENODEV;
1019 980
1020 portp = brdp->ports[portnr]; 981 portp = brdp->ports[portnr];
1021 if (portp == (stliport_t *) NULL) 982 if (portp == NULL)
1022 return(-ENODEV); 983 return -ENODEV;
1023 if (portp->devnr < 1) 984 if (portp->devnr < 1)
1024 return(-ENODEV); 985 return -ENODEV;
1025 986
1026 987
1027/* 988/*
@@ -1033,8 +994,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1033 if (portp->flags & ASYNC_CLOSING) { 994 if (portp->flags & ASYNC_CLOSING) {
1034 interruptible_sleep_on(&portp->close_wait); 995 interruptible_sleep_on(&portp->close_wait);
1035 if (portp->flags & ASYNC_HUP_NOTIFY) 996 if (portp->flags & ASYNC_HUP_NOTIFY)
1036 return(-EAGAIN); 997 return -EAGAIN;
1037 return(-ERESTARTSYS); 998 return -ERESTARTSYS;
1038 } 999 }
1039 1000
1040/* 1001/*
@@ -1050,7 +1011,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1050 wait_event_interruptible(portp->raw_wait, 1011 wait_event_interruptible(portp->raw_wait,
1051 !test_bit(ST_INITIALIZING, &portp->state)); 1012 !test_bit(ST_INITIALIZING, &portp->state));
1052 if (signal_pending(current)) 1013 if (signal_pending(current))
1053 return(-ERESTARTSYS); 1014 return -ERESTARTSYS;
1054 1015
1055 if ((portp->flags & ASYNC_INITIALIZED) == 0) { 1016 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1056 set_bit(ST_INITIALIZING, &portp->state); 1017 set_bit(ST_INITIALIZING, &portp->state);
@@ -1061,7 +1022,7 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1061 clear_bit(ST_INITIALIZING, &portp->state); 1022 clear_bit(ST_INITIALIZING, &portp->state);
1062 wake_up_interruptible(&portp->raw_wait); 1023 wake_up_interruptible(&portp->raw_wait);
1063 if (rc < 0) 1024 if (rc < 0)
1064 return(rc); 1025 return rc;
1065 } 1026 }
1066 1027
1067/* 1028/*
@@ -1073,8 +1034,8 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1073 if (portp->flags & ASYNC_CLOSING) { 1034 if (portp->flags & ASYNC_CLOSING) {
1074 interruptible_sleep_on(&portp->close_wait); 1035 interruptible_sleep_on(&portp->close_wait);
1075 if (portp->flags & ASYNC_HUP_NOTIFY) 1036 if (portp->flags & ASYNC_HUP_NOTIFY)
1076 return(-EAGAIN); 1037 return -EAGAIN;
1077 return(-ERESTARTSYS); 1038 return -ERESTARTSYS;
1078 } 1039 }
1079 1040
1080/* 1041/*
@@ -1084,38 +1045,33 @@ static int stli_open(struct tty_struct *tty, struct file *filp)
1084 */ 1045 */
1085 if (!(filp->f_flags & O_NONBLOCK)) { 1046 if (!(filp->f_flags & O_NONBLOCK)) {
1086 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0) 1047 if ((rc = stli_waitcarrier(brdp, portp, filp)) != 0)
1087 return(rc); 1048 return rc;
1088 } 1049 }
1089 portp->flags |= ASYNC_NORMAL_ACTIVE; 1050 portp->flags |= ASYNC_NORMAL_ACTIVE;
1090 return(0); 1051 return 0;
1091} 1052}
1092 1053
1093/*****************************************************************************/ 1054/*****************************************************************************/
1094 1055
1095static void stli_close(struct tty_struct *tty, struct file *filp) 1056static void stli_close(struct tty_struct *tty, struct file *filp)
1096{ 1057{
1097 stlibrd_t *brdp; 1058 stlibrd_t *brdp;
1098 stliport_t *portp; 1059 stliport_t *portp;
1099 unsigned long flags; 1060 unsigned long flags;
1100
1101#ifdef DEBUG
1102 printk("stli_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1103#endif
1104 1061
1105 portp = tty->driver_data; 1062 portp = tty->driver_data;
1106 if (portp == (stliport_t *) NULL) 1063 if (portp == NULL)
1107 return; 1064 return;
1108 1065
1109 save_flags(flags); 1066 spin_lock_irqsave(&stli_lock, flags);
1110 cli();
1111 if (tty_hung_up_p(filp)) { 1067 if (tty_hung_up_p(filp)) {
1112 restore_flags(flags); 1068 spin_unlock_irqrestore(&stli_lock, flags);
1113 return; 1069 return;
1114 } 1070 }
1115 if ((tty->count == 1) && (portp->refcount != 1)) 1071 if ((tty->count == 1) && (portp->refcount != 1))
1116 portp->refcount = 1; 1072 portp->refcount = 1;
1117 if (portp->refcount-- > 1) { 1073 if (portp->refcount-- > 1) {
1118 restore_flags(flags); 1074 spin_unlock_irqrestore(&stli_lock, flags);
1119 return; 1075 return;
1120 } 1076 }
1121 1077
@@ -1130,6 +1086,8 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1130 if (tty == stli_txcooktty) 1086 if (tty == stli_txcooktty)
1131 stli_flushchars(tty); 1087 stli_flushchars(tty);
1132 tty->closing = 1; 1088 tty->closing = 1;
1089 spin_unlock_irqrestore(&stli_lock, flags);
1090
1133 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1091 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1134 tty_wait_until_sent(tty, portp->closing_wait); 1092 tty_wait_until_sent(tty, portp->closing_wait);
1135 1093
@@ -1153,7 +1111,7 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1153 stli_flushbuffer(tty); 1111 stli_flushbuffer(tty);
1154 1112
1155 tty->closing = 0; 1113 tty->closing = 0;
1156 portp->tty = (struct tty_struct *) NULL; 1114 portp->tty = NULL;
1157 1115
1158 if (portp->openwaitcnt) { 1116 if (portp->openwaitcnt) {
1159 if (portp->close_delay) 1117 if (portp->close_delay)
@@ -1163,7 +1121,6 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1163 1121
1164 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1122 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1165 wake_up_interruptible(&portp->close_wait); 1123 wake_up_interruptible(&portp->close_wait);
1166 restore_flags(flags);
1167} 1124}
1168 1125
1169/*****************************************************************************/ 1126/*****************************************************************************/
@@ -1178,45 +1135,41 @@ static void stli_close(struct tty_struct *tty, struct file *filp)
1178 1135
1179static int stli_initopen(stlibrd_t *brdp, stliport_t *portp) 1136static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1180{ 1137{
1181 struct tty_struct *tty; 1138 struct tty_struct *tty;
1182 asynotify_t nt; 1139 asynotify_t nt;
1183 asyport_t aport; 1140 asyport_t aport;
1184 int rc; 1141 int rc;
1185
1186#ifdef DEBUG
1187 printk("stli_initopen(brdp=%x,portp=%x)\n", (int) brdp, (int) portp);
1188#endif
1189 1142
1190 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0) 1143 if ((rc = stli_rawopen(brdp, portp, 0, 1)) < 0)
1191 return(rc); 1144 return rc;
1192 1145
1193 memset(&nt, 0, sizeof(asynotify_t)); 1146 memset(&nt, 0, sizeof(asynotify_t));
1194 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK); 1147 nt.data = (DT_TXLOW | DT_TXEMPTY | DT_RXBUSY | DT_RXBREAK);
1195 nt.signal = SG_DCD; 1148 nt.signal = SG_DCD;
1196 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt, 1149 if ((rc = stli_cmdwait(brdp, portp, A_SETNOTIFY, &nt,
1197 sizeof(asynotify_t), 0)) < 0) 1150 sizeof(asynotify_t), 0)) < 0)
1198 return(rc); 1151 return rc;
1199 1152
1200 tty = portp->tty; 1153 tty = portp->tty;
1201 if (tty == (struct tty_struct *) NULL) 1154 if (tty == NULL)
1202 return(-ENODEV); 1155 return -ENODEV;
1203 stli_mkasyport(portp, &aport, tty->termios); 1156 stli_mkasyport(portp, &aport, tty->termios);
1204 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport, 1157 if ((rc = stli_cmdwait(brdp, portp, A_SETPORT, &aport,
1205 sizeof(asyport_t), 0)) < 0) 1158 sizeof(asyport_t), 0)) < 0)
1206 return(rc); 1159 return rc;
1207 1160
1208 set_bit(ST_GETSIGS, &portp->state); 1161 set_bit(ST_GETSIGS, &portp->state);
1209 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig, 1162 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, &portp->asig,
1210 sizeof(asysigs_t), 1)) < 0) 1163 sizeof(asysigs_t), 1)) < 0)
1211 return(rc); 1164 return rc;
1212 if (test_and_clear_bit(ST_GETSIGS, &portp->state)) 1165 if (test_and_clear_bit(ST_GETSIGS, &portp->state))
1213 portp->sigs = stli_mktiocm(portp->asig.sigvalue); 1166 portp->sigs = stli_mktiocm(portp->asig.sigvalue);
1214 stli_mkasysigs(&portp->asig, 1, 1); 1167 stli_mkasysigs(&portp->asig, 1, 1);
1215 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig, 1168 if ((rc = stli_cmdwait(brdp, portp, A_SETSIGNALS, &portp->asig,
1216 sizeof(asysigs_t), 0)) < 0) 1169 sizeof(asysigs_t), 0)) < 0)
1217 return(rc); 1170 return rc;
1218 1171
1219 return(0); 1172 return 0;
1220} 1173}
1221 1174
1222/*****************************************************************************/ 1175/*****************************************************************************/
@@ -1230,22 +1183,15 @@ static int stli_initopen(stlibrd_t *brdp, stliport_t *portp)
1230 1183
1231static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1184static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1232{ 1185{
1233 volatile cdkhdr_t *hdrp; 1186 cdkhdr_t __iomem *hdrp;
1234 volatile cdkctrl_t *cp; 1187 cdkctrl_t __iomem *cp;
1235 volatile unsigned char *bits; 1188 unsigned char __iomem *bits;
1236 unsigned long flags; 1189 unsigned long flags;
1237 int rc; 1190 int rc;
1238
1239#ifdef DEBUG
1240 printk("stli_rawopen(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1241 (int) brdp, (int) portp, (int) arg, wait);
1242#endif
1243 1191
1244/* 1192/*
1245 * Send a message to the slave to open this port. 1193 * Send a message to the slave to open this port.
1246 */ 1194 */
1247 save_flags(flags);
1248 cli();
1249 1195
1250/* 1196/*
1251 * Slave is already closing this port. This can happen if a hangup 1197 * Slave is already closing this port. This can happen if a hangup
@@ -1256,7 +1202,6 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1256 wait_event_interruptible(portp->raw_wait, 1202 wait_event_interruptible(portp->raw_wait,
1257 !test_bit(ST_CLOSING, &portp->state)); 1203 !test_bit(ST_CLOSING, &portp->state));
1258 if (signal_pending(current)) { 1204 if (signal_pending(current)) {
1259 restore_flags(flags);
1260 return -ERESTARTSYS; 1205 return -ERESTARTSYS;
1261 } 1206 }
1262 1207
@@ -1265,19 +1210,20 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1265 * memory. Once the message is in set the service bits to say that 1210 * memory. Once the message is in set the service bits to say that
1266 * this port wants service. 1211 * this port wants service.
1267 */ 1212 */
1213 spin_lock_irqsave(&brd_lock, flags);
1268 EBRDENABLE(brdp); 1214 EBRDENABLE(brdp);
1269 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 1215 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1270 cp->openarg = arg; 1216 writel(arg, &cp->openarg);
1271 cp->open = 1; 1217 writeb(1, &cp->open);
1272 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1218 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1273 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1219 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1274 portp->portidx; 1220 portp->portidx;
1275 *bits |= portp->portbit; 1221 writeb(readb(bits) | portp->portbit, bits);
1276 EBRDDISABLE(brdp); 1222 EBRDDISABLE(brdp);
1277 1223
1278 if (wait == 0) { 1224 if (wait == 0) {
1279 restore_flags(flags); 1225 spin_unlock_irqrestore(&brd_lock, flags);
1280 return(0); 1226 return 0;
1281 } 1227 }
1282 1228
1283/* 1229/*
@@ -1286,15 +1232,16 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1286 */ 1232 */
1287 rc = 0; 1233 rc = 0;
1288 set_bit(ST_OPENING, &portp->state); 1234 set_bit(ST_OPENING, &portp->state);
1235 spin_unlock_irqrestore(&brd_lock, flags);
1236
1289 wait_event_interruptible(portp->raw_wait, 1237 wait_event_interruptible(portp->raw_wait,
1290 !test_bit(ST_OPENING, &portp->state)); 1238 !test_bit(ST_OPENING, &portp->state));
1291 if (signal_pending(current)) 1239 if (signal_pending(current))
1292 rc = -ERESTARTSYS; 1240 rc = -ERESTARTSYS;
1293 restore_flags(flags);
1294 1241
1295 if ((rc == 0) && (portp->rc != 0)) 1242 if ((rc == 0) && (portp->rc != 0))
1296 rc = -EIO; 1243 rc = -EIO;
1297 return(rc); 1244 return rc;
1298} 1245}
1299 1246
1300/*****************************************************************************/ 1247/*****************************************************************************/
@@ -1307,19 +1254,11 @@ static int stli_rawopen(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, i
1307 1254
1308static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait) 1255static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg, int wait)
1309{ 1256{
1310 volatile cdkhdr_t *hdrp; 1257 cdkhdr_t __iomem *hdrp;
1311 volatile cdkctrl_t *cp; 1258 cdkctrl_t __iomem *cp;
1312 volatile unsigned char *bits; 1259 unsigned char __iomem *bits;
1313 unsigned long flags; 1260 unsigned long flags;
1314 int rc; 1261 int rc;
1315
1316#ifdef DEBUG
1317 printk("stli_rawclose(brdp=%x,portp=%x,arg=%x,wait=%d)\n",
1318 (int) brdp, (int) portp, (int) arg, wait);
1319#endif
1320
1321 save_flags(flags);
1322 cli();
1323 1262
1324/* 1263/*
1325 * Slave is already closing this port. This can happen if a hangup 1264 * Slave is already closing this port. This can happen if a hangup
@@ -1329,7 +1268,6 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1329 wait_event_interruptible(portp->raw_wait, 1268 wait_event_interruptible(portp->raw_wait,
1330 !test_bit(ST_CLOSING, &portp->state)); 1269 !test_bit(ST_CLOSING, &portp->state));
1331 if (signal_pending(current)) { 1270 if (signal_pending(current)) {
1332 restore_flags(flags);
1333 return -ERESTARTSYS; 1271 return -ERESTARTSYS;
1334 } 1272 }
1335 } 1273 }
@@ -1337,21 +1275,22 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1337/* 1275/*
1338 * Write the close command into shared memory. 1276 * Write the close command into shared memory.
1339 */ 1277 */
1278 spin_lock_irqsave(&brd_lock, flags);
1340 EBRDENABLE(brdp); 1279 EBRDENABLE(brdp);
1341 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 1280 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
1342 cp->closearg = arg; 1281 writel(arg, &cp->closearg);
1343 cp->close = 1; 1282 writeb(1, &cp->close);
1344 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1283 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1345 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1284 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1346 portp->portidx; 1285 portp->portidx;
1347 *bits |= portp->portbit; 1286 writeb(readb(bits) |portp->portbit, bits);
1348 EBRDDISABLE(brdp); 1287 EBRDDISABLE(brdp);
1349 1288
1350 set_bit(ST_CLOSING, &portp->state); 1289 set_bit(ST_CLOSING, &portp->state);
1351 if (wait == 0) { 1290 spin_unlock_irqrestore(&brd_lock, flags);
1352 restore_flags(flags); 1291
1353 return(0); 1292 if (wait == 0)
1354 } 1293 return 0;
1355 1294
1356/* 1295/*
1357 * Slave is in action, so now we must wait for the open acknowledgment 1296 * Slave is in action, so now we must wait for the open acknowledgment
@@ -1362,11 +1301,10 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1362 !test_bit(ST_CLOSING, &portp->state)); 1301 !test_bit(ST_CLOSING, &portp->state));
1363 if (signal_pending(current)) 1302 if (signal_pending(current))
1364 rc = -ERESTARTSYS; 1303 rc = -ERESTARTSYS;
1365 restore_flags(flags);
1366 1304
1367 if ((rc == 0) && (portp->rc != 0)) 1305 if ((rc == 0) && (portp->rc != 0))
1368 rc = -EIO; 1306 rc = -EIO;
1369 return(rc); 1307 return rc;
1370} 1308}
1371 1309
1372/*****************************************************************************/ 1310/*****************************************************************************/
@@ -1380,36 +1318,21 @@ static int stli_rawclose(stlibrd_t *brdp, stliport_t *portp, unsigned long arg,
1380 1318
1381static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 1319static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
1382{ 1320{
1383 unsigned long flags;
1384
1385#ifdef DEBUG
1386 printk("stli_cmdwait(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
1387 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
1388 (int) arg, size, copyback);
1389#endif
1390
1391 save_flags(flags);
1392 cli();
1393 wait_event_interruptible(portp->raw_wait, 1321 wait_event_interruptible(portp->raw_wait,
1394 !test_bit(ST_CMDING, &portp->state)); 1322 !test_bit(ST_CMDING, &portp->state));
1395 if (signal_pending(current)) { 1323 if (signal_pending(current))
1396 restore_flags(flags);
1397 return -ERESTARTSYS; 1324 return -ERESTARTSYS;
1398 }
1399 1325
1400 stli_sendcmd(brdp, portp, cmd, arg, size, copyback); 1326 stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
1401 1327
1402 wait_event_interruptible(portp->raw_wait, 1328 wait_event_interruptible(portp->raw_wait,
1403 !test_bit(ST_CMDING, &portp->state)); 1329 !test_bit(ST_CMDING, &portp->state));
1404 if (signal_pending(current)) { 1330 if (signal_pending(current))
1405 restore_flags(flags);
1406 return -ERESTARTSYS; 1331 return -ERESTARTSYS;
1407 }
1408 restore_flags(flags);
1409 1332
1410 if (portp->rc != 0) 1333 if (portp->rc != 0)
1411 return(-EIO); 1334 return -EIO;
1412 return(0); 1335 return 0;
1413} 1336}
1414 1337
1415/*****************************************************************************/ 1338/*****************************************************************************/
@@ -1421,22 +1344,18 @@ static int stli_cmdwait(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, v
1421 1344
1422static int stli_setport(stliport_t *portp) 1345static int stli_setport(stliport_t *portp)
1423{ 1346{
1424 stlibrd_t *brdp; 1347 stlibrd_t *brdp;
1425 asyport_t aport; 1348 asyport_t aport;
1426
1427#ifdef DEBUG
1428 printk("stli_setport(portp=%x)\n", (int) portp);
1429#endif
1430 1349
1431 if (portp == (stliport_t *) NULL) 1350 if (portp == NULL)
1432 return(-ENODEV); 1351 return -ENODEV;
1433 if (portp->tty == (struct tty_struct *) NULL) 1352 if (portp->tty == NULL)
1434 return(-ENODEV); 1353 return -ENODEV;
1435 if ((portp->brdnr < 0) && (portp->brdnr >= stli_nrbrds)) 1354 if (portp->brdnr < 0 && portp->brdnr >= stli_nrbrds)
1436 return(-ENODEV); 1355 return -ENODEV;
1437 brdp = stli_brds[portp->brdnr]; 1356 brdp = stli_brds[portp->brdnr];
1438 if (brdp == (stlibrd_t *) NULL) 1357 if (brdp == NULL)
1439 return(-ENODEV); 1358 return -ENODEV;
1440 1359
1441 stli_mkasyport(portp, &aport, portp->tty->termios); 1360 stli_mkasyport(portp, &aport, portp->tty->termios);
1442 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0)); 1361 return(stli_cmdwait(brdp, portp, A_SETPORT, &aport, sizeof(asyport_t), 0));
@@ -1451,13 +1370,8 @@ static int stli_setport(stliport_t *portp)
1451 1370
1452static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp) 1371static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *filp)
1453{ 1372{
1454 unsigned long flags; 1373 unsigned long flags;
1455 int rc, doclocal; 1374 int rc, doclocal;
1456
1457#ifdef DEBUG
1458 printk("stli_waitcarrier(brdp=%x,portp=%x,filp=%x)\n",
1459 (int) brdp, (int) portp, (int) filp);
1460#endif
1461 1375
1462 rc = 0; 1376 rc = 0;
1463 doclocal = 0; 1377 doclocal = 0;
@@ -1465,11 +1379,11 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1465 if (portp->tty->termios->c_cflag & CLOCAL) 1379 if (portp->tty->termios->c_cflag & CLOCAL)
1466 doclocal++; 1380 doclocal++;
1467 1381
1468 save_flags(flags); 1382 spin_lock_irqsave(&stli_lock, flags);
1469 cli();
1470 portp->openwaitcnt++; 1383 portp->openwaitcnt++;
1471 if (! tty_hung_up_p(filp)) 1384 if (! tty_hung_up_p(filp))
1472 portp->refcount--; 1385 portp->refcount--;
1386 spin_unlock_irqrestore(&stli_lock, flags);
1473 1387
1474 for (;;) { 1388 for (;;) {
1475 stli_mkasysigs(&portp->asig, 1, 1); 1389 stli_mkasysigs(&portp->asig, 1, 1);
@@ -1495,12 +1409,13 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1495 interruptible_sleep_on(&portp->open_wait); 1409 interruptible_sleep_on(&portp->open_wait);
1496 } 1410 }
1497 1411
1412 spin_lock_irqsave(&stli_lock, flags);
1498 if (! tty_hung_up_p(filp)) 1413 if (! tty_hung_up_p(filp))
1499 portp->refcount++; 1414 portp->refcount++;
1500 portp->openwaitcnt--; 1415 portp->openwaitcnt--;
1501 restore_flags(flags); 1416 spin_unlock_irqrestore(&stli_lock, flags);
1502 1417
1503 return(rc); 1418 return rc;
1504} 1419}
1505 1420
1506/*****************************************************************************/ 1421/*****************************************************************************/
@@ -1513,46 +1428,38 @@ static int stli_waitcarrier(stlibrd_t *brdp, stliport_t *portp, struct file *fil
1513 1428
1514static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count) 1429static int stli_write(struct tty_struct *tty, const unsigned char *buf, int count)
1515{ 1430{
1516 volatile cdkasy_t *ap; 1431 cdkasy_t __iomem *ap;
1517 volatile cdkhdr_t *hdrp; 1432 cdkhdr_t __iomem *hdrp;
1518 volatile unsigned char *bits; 1433 unsigned char __iomem *bits;
1519 unsigned char *shbuf, *chbuf; 1434 unsigned char __iomem *shbuf;
1520 stliport_t *portp; 1435 unsigned char *chbuf;
1521 stlibrd_t *brdp; 1436 stliport_t *portp;
1522 unsigned int len, stlen, head, tail, size; 1437 stlibrd_t *brdp;
1523 unsigned long flags; 1438 unsigned int len, stlen, head, tail, size;
1524 1439 unsigned long flags;
1525#ifdef DEBUG
1526 printk("stli_write(tty=%x,buf=%x,count=%d)\n",
1527 (int) tty, (int) buf, count);
1528#endif
1529 1440
1530 if ((tty == (struct tty_struct *) NULL) ||
1531 (stli_tmpwritebuf == (char *) NULL))
1532 return(0);
1533 if (tty == stli_txcooktty) 1441 if (tty == stli_txcooktty)
1534 stli_flushchars(tty); 1442 stli_flushchars(tty);
1535 portp = tty->driver_data; 1443 portp = tty->driver_data;
1536 if (portp == (stliport_t *) NULL) 1444 if (portp == NULL)
1537 return(0); 1445 return 0;
1538 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1446 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1539 return(0); 1447 return 0;
1540 brdp = stli_brds[portp->brdnr]; 1448 brdp = stli_brds[portp->brdnr];
1541 if (brdp == (stlibrd_t *) NULL) 1449 if (brdp == NULL)
1542 return(0); 1450 return 0;
1543 chbuf = (unsigned char *) buf; 1451 chbuf = (unsigned char *) buf;
1544 1452
1545/* 1453/*
1546 * All data is now local, shove as much as possible into shared memory. 1454 * All data is now local, shove as much as possible into shared memory.
1547 */ 1455 */
1548 save_flags(flags); 1456 spin_lock_irqsave(&brd_lock, flags);
1549 cli();
1550 EBRDENABLE(brdp); 1457 EBRDENABLE(brdp);
1551 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1458 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1552 head = (unsigned int) ap->txq.head; 1459 head = (unsigned int) readw(&ap->txq.head);
1553 tail = (unsigned int) ap->txq.tail; 1460 tail = (unsigned int) readw(&ap->txq.tail);
1554 if (tail != ((unsigned int) ap->txq.tail)) 1461 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1555 tail = (unsigned int) ap->txq.tail; 1462 tail = (unsigned int) readw(&ap->txq.tail);
1556 size = portp->txsize; 1463 size = portp->txsize;
1557 if (head >= tail) { 1464 if (head >= tail) {
1558 len = size - (head - tail) - 1; 1465 len = size - (head - tail) - 1;
@@ -1564,11 +1471,11 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1564 1471
1565 len = MIN(len, count); 1472 len = MIN(len, count);
1566 count = 0; 1473 count = 0;
1567 shbuf = (char *) EBRDGETMEMPTR(brdp, portp->txoffset); 1474 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->txoffset);
1568 1475
1569 while (len > 0) { 1476 while (len > 0) {
1570 stlen = MIN(len, stlen); 1477 stlen = MIN(len, stlen);
1571 memcpy((shbuf + head), chbuf, stlen); 1478 memcpy_toio(shbuf + head, chbuf, stlen);
1572 chbuf += stlen; 1479 chbuf += stlen;
1573 len -= stlen; 1480 len -= stlen;
1574 count += stlen; 1481 count += stlen;
@@ -1579,20 +1486,19 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1579 } 1486 }
1580 } 1487 }
1581 1488
1582 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1489 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1583 ap->txq.head = head; 1490 writew(head, &ap->txq.head);
1584 if (test_bit(ST_TXBUSY, &portp->state)) { 1491 if (test_bit(ST_TXBUSY, &portp->state)) {
1585 if (ap->changed.data & DT_TXEMPTY) 1492 if (readl(&ap->changed.data) & DT_TXEMPTY)
1586 ap->changed.data &= ~DT_TXEMPTY; 1493 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1587 } 1494 }
1588 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1495 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1589 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1496 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1590 portp->portidx; 1497 portp->portidx;
1591 *bits |= portp->portbit; 1498 writeb(readb(bits) | portp->portbit, bits);
1592 set_bit(ST_TXBUSY, &portp->state); 1499 set_bit(ST_TXBUSY, &portp->state);
1593 EBRDDISABLE(brdp); 1500 EBRDDISABLE(brdp);
1594 1501 spin_unlock_irqrestore(&brd_lock, flags);
1595 restore_flags(flags);
1596 1502
1597 return(count); 1503 return(count);
1598} 1504}
@@ -1609,14 +1515,8 @@ static int stli_write(struct tty_struct *tty, const unsigned char *buf, int coun
1609 1515
1610static void stli_putchar(struct tty_struct *tty, unsigned char ch) 1516static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1611{ 1517{
1612#ifdef DEBUG
1613 printk("stli_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1614#endif
1615
1616 if (tty == (struct tty_struct *) NULL)
1617 return;
1618 if (tty != stli_txcooktty) { 1518 if (tty != stli_txcooktty) {
1619 if (stli_txcooktty != (struct tty_struct *) NULL) 1519 if (stli_txcooktty != NULL)
1620 stli_flushchars(stli_txcooktty); 1520 stli_flushchars(stli_txcooktty);
1621 stli_txcooktty = tty; 1521 stli_txcooktty = tty;
1622 } 1522 }
@@ -1636,29 +1536,26 @@ static void stli_putchar(struct tty_struct *tty, unsigned char ch)
1636 1536
1637static void stli_flushchars(struct tty_struct *tty) 1537static void stli_flushchars(struct tty_struct *tty)
1638{ 1538{
1639 volatile cdkhdr_t *hdrp; 1539 cdkhdr_t __iomem *hdrp;
1640 volatile unsigned char *bits; 1540 unsigned char __iomem *bits;
1641 volatile cdkasy_t *ap; 1541 cdkasy_t __iomem *ap;
1642 struct tty_struct *cooktty; 1542 struct tty_struct *cooktty;
1643 stliport_t *portp; 1543 stliport_t *portp;
1644 stlibrd_t *brdp; 1544 stlibrd_t *brdp;
1645 unsigned int len, stlen, head, tail, size, count, cooksize; 1545 unsigned int len, stlen, head, tail, size, count, cooksize;
1646 unsigned char *buf, *shbuf; 1546 unsigned char *buf;
1647 unsigned long flags; 1547 unsigned char __iomem *shbuf;
1648 1548 unsigned long flags;
1649#ifdef DEBUG
1650 printk("stli_flushchars(tty=%x)\n", (int) tty);
1651#endif
1652 1549
1653 cooksize = stli_txcooksize; 1550 cooksize = stli_txcooksize;
1654 cooktty = stli_txcooktty; 1551 cooktty = stli_txcooktty;
1655 stli_txcooksize = 0; 1552 stli_txcooksize = 0;
1656 stli_txcookrealsize = 0; 1553 stli_txcookrealsize = 0;
1657 stli_txcooktty = (struct tty_struct *) NULL; 1554 stli_txcooktty = NULL;
1658 1555
1659 if (tty == (struct tty_struct *) NULL) 1556 if (tty == NULL)
1660 return; 1557 return;
1661 if (cooktty == (struct tty_struct *) NULL) 1558 if (cooktty == NULL)
1662 return; 1559 return;
1663 if (tty != cooktty) 1560 if (tty != cooktty)
1664 tty = cooktty; 1561 tty = cooktty;
@@ -1666,23 +1563,22 @@ static void stli_flushchars(struct tty_struct *tty)
1666 return; 1563 return;
1667 1564
1668 portp = tty->driver_data; 1565 portp = tty->driver_data;
1669 if (portp == (stliport_t *) NULL) 1566 if (portp == NULL)
1670 return; 1567 return;
1671 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1568 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1672 return; 1569 return;
1673 brdp = stli_brds[portp->brdnr]; 1570 brdp = stli_brds[portp->brdnr];
1674 if (brdp == (stlibrd_t *) NULL) 1571 if (brdp == NULL)
1675 return; 1572 return;
1676 1573
1677 save_flags(flags); 1574 spin_lock_irqsave(&brd_lock, flags);
1678 cli();
1679 EBRDENABLE(brdp); 1575 EBRDENABLE(brdp);
1680 1576
1681 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1577 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1682 head = (unsigned int) ap->txq.head; 1578 head = (unsigned int) readw(&ap->txq.head);
1683 tail = (unsigned int) ap->txq.tail; 1579 tail = (unsigned int) readw(&ap->txq.tail);
1684 if (tail != ((unsigned int) ap->txq.tail)) 1580 if (tail != ((unsigned int) readw(&ap->txq.tail)))
1685 tail = (unsigned int) ap->txq.tail; 1581 tail = (unsigned int) readw(&ap->txq.tail);
1686 size = portp->txsize; 1582 size = portp->txsize;
1687 if (head >= tail) { 1583 if (head >= tail) {
1688 len = size - (head - tail) - 1; 1584 len = size - (head - tail) - 1;
@@ -1699,7 +1595,7 @@ static void stli_flushchars(struct tty_struct *tty)
1699 1595
1700 while (len > 0) { 1596 while (len > 0) {
1701 stlen = MIN(len, stlen); 1597 stlen = MIN(len, stlen);
1702 memcpy((shbuf + head), buf, stlen); 1598 memcpy_toio(shbuf + head, buf, stlen);
1703 buf += stlen; 1599 buf += stlen;
1704 len -= stlen; 1600 len -= stlen;
1705 count += stlen; 1601 count += stlen;
@@ -1710,73 +1606,66 @@ static void stli_flushchars(struct tty_struct *tty)
1710 } 1606 }
1711 } 1607 }
1712 1608
1713 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 1609 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
1714 ap->txq.head = head; 1610 writew(head, &ap->txq.head);
1715 1611
1716 if (test_bit(ST_TXBUSY, &portp->state)) { 1612 if (test_bit(ST_TXBUSY, &portp->state)) {
1717 if (ap->changed.data & DT_TXEMPTY) 1613 if (readl(&ap->changed.data) & DT_TXEMPTY)
1718 ap->changed.data &= ~DT_TXEMPTY; 1614 writel(readl(&ap->changed.data) & ~DT_TXEMPTY, &ap->changed.data);
1719 } 1615 }
1720 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 1616 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
1721 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 1617 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
1722 portp->portidx; 1618 portp->portidx;
1723 *bits |= portp->portbit; 1619 writeb(readb(bits) | portp->portbit, bits);
1724 set_bit(ST_TXBUSY, &portp->state); 1620 set_bit(ST_TXBUSY, &portp->state);
1725 1621
1726 EBRDDISABLE(brdp); 1622 EBRDDISABLE(brdp);
1727 restore_flags(flags); 1623 spin_unlock_irqrestore(&brd_lock, flags);
1728} 1624}
1729 1625
1730/*****************************************************************************/ 1626/*****************************************************************************/
1731 1627
1732static int stli_writeroom(struct tty_struct *tty) 1628static int stli_writeroom(struct tty_struct *tty)
1733{ 1629{
1734 volatile cdkasyrq_t *rp; 1630 cdkasyrq_t __iomem *rp;
1735 stliport_t *portp; 1631 stliport_t *portp;
1736 stlibrd_t *brdp; 1632 stlibrd_t *brdp;
1737 unsigned int head, tail, len; 1633 unsigned int head, tail, len;
1738 unsigned long flags; 1634 unsigned long flags;
1739
1740#ifdef DEBUG
1741 printk("stli_writeroom(tty=%x)\n", (int) tty);
1742#endif
1743 1635
1744 if (tty == (struct tty_struct *) NULL)
1745 return(0);
1746 if (tty == stli_txcooktty) { 1636 if (tty == stli_txcooktty) {
1747 if (stli_txcookrealsize != 0) { 1637 if (stli_txcookrealsize != 0) {
1748 len = stli_txcookrealsize - stli_txcooksize; 1638 len = stli_txcookrealsize - stli_txcooksize;
1749 return(len); 1639 return len;
1750 } 1640 }
1751 } 1641 }
1752 1642
1753 portp = tty->driver_data; 1643 portp = tty->driver_data;
1754 if (portp == (stliport_t *) NULL) 1644 if (portp == NULL)
1755 return(0); 1645 return 0;
1756 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1646 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1757 return(0); 1647 return 0;
1758 brdp = stli_brds[portp->brdnr]; 1648 brdp = stli_brds[portp->brdnr];
1759 if (brdp == (stlibrd_t *) NULL) 1649 if (brdp == NULL)
1760 return(0); 1650 return 0;
1761 1651
1762 save_flags(flags); 1652 spin_lock_irqsave(&brd_lock, flags);
1763 cli();
1764 EBRDENABLE(brdp); 1653 EBRDENABLE(brdp);
1765 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq; 1654 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1766 head = (unsigned int) rp->head; 1655 head = (unsigned int) readw(&rp->head);
1767 tail = (unsigned int) rp->tail; 1656 tail = (unsigned int) readw(&rp->tail);
1768 if (tail != ((unsigned int) rp->tail)) 1657 if (tail != ((unsigned int) readw(&rp->tail)))
1769 tail = (unsigned int) rp->tail; 1658 tail = (unsigned int) readw(&rp->tail);
1770 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head); 1659 len = (head >= tail) ? (portp->txsize - (head - tail)) : (tail - head);
1771 len--; 1660 len--;
1772 EBRDDISABLE(brdp); 1661 EBRDDISABLE(brdp);
1773 restore_flags(flags); 1662 spin_unlock_irqrestore(&brd_lock, flags);
1774 1663
1775 if (tty == stli_txcooktty) { 1664 if (tty == stli_txcooktty) {
1776 stli_txcookrealsize = len; 1665 stli_txcookrealsize = len;
1777 len -= stli_txcooksize; 1666 len -= stli_txcooksize;
1778 } 1667 }
1779 return(len); 1668 return len;
1780} 1669}
1781 1670
1782/*****************************************************************************/ 1671/*****************************************************************************/
@@ -1791,44 +1680,37 @@ static int stli_writeroom(struct tty_struct *tty)
1791 1680
1792static int stli_charsinbuffer(struct tty_struct *tty) 1681static int stli_charsinbuffer(struct tty_struct *tty)
1793{ 1682{
1794 volatile cdkasyrq_t *rp; 1683 cdkasyrq_t __iomem *rp;
1795 stliport_t *portp; 1684 stliport_t *portp;
1796 stlibrd_t *brdp; 1685 stlibrd_t *brdp;
1797 unsigned int head, tail, len; 1686 unsigned int head, tail, len;
1798 unsigned long flags; 1687 unsigned long flags;
1799
1800#ifdef DEBUG
1801 printk("stli_charsinbuffer(tty=%x)\n", (int) tty);
1802#endif
1803 1688
1804 if (tty == (struct tty_struct *) NULL)
1805 return(0);
1806 if (tty == stli_txcooktty) 1689 if (tty == stli_txcooktty)
1807 stli_flushchars(tty); 1690 stli_flushchars(tty);
1808 portp = tty->driver_data; 1691 portp = tty->driver_data;
1809 if (portp == (stliport_t *) NULL) 1692 if (portp == NULL)
1810 return(0); 1693 return 0;
1811 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1694 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
1812 return(0); 1695 return 0;
1813 brdp = stli_brds[portp->brdnr]; 1696 brdp = stli_brds[portp->brdnr];
1814 if (brdp == (stlibrd_t *) NULL) 1697 if (brdp == NULL)
1815 return(0); 1698 return 0;
1816 1699
1817 save_flags(flags); 1700 spin_lock_irqsave(&brd_lock, flags);
1818 cli();
1819 EBRDENABLE(brdp); 1701 EBRDENABLE(brdp);
1820 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->txq; 1702 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->txq;
1821 head = (unsigned int) rp->head; 1703 head = (unsigned int) readw(&rp->head);
1822 tail = (unsigned int) rp->tail; 1704 tail = (unsigned int) readw(&rp->tail);
1823 if (tail != ((unsigned int) rp->tail)) 1705 if (tail != ((unsigned int) readw(&rp->tail)))
1824 tail = (unsigned int) rp->tail; 1706 tail = (unsigned int) readw(&rp->tail);
1825 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head)); 1707 len = (head >= tail) ? (head - tail) : (portp->txsize - (tail - head));
1826 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state)) 1708 if ((len == 0) && test_bit(ST_TXBUSY, &portp->state))
1827 len = 1; 1709 len = 1;
1828 EBRDDISABLE(brdp); 1710 EBRDDISABLE(brdp);
1829 restore_flags(flags); 1711 spin_unlock_irqrestore(&brd_lock, flags);
1830 1712
1831 return(len); 1713 return len;
1832} 1714}
1833 1715
1834/*****************************************************************************/ 1716/*****************************************************************************/
@@ -1839,12 +1721,8 @@ static int stli_charsinbuffer(struct tty_struct *tty)
1839 1721
1840static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp) 1722static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1841{ 1723{
1842 struct serial_struct sio; 1724 struct serial_struct sio;
1843 stlibrd_t *brdp; 1725 stlibrd_t *brdp;
1844
1845#ifdef DEBUG
1846 printk("stli_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1847#endif
1848 1726
1849 memset(&sio, 0, sizeof(struct serial_struct)); 1727 memset(&sio, 0, sizeof(struct serial_struct));
1850 sio.type = PORT_UNKNOWN; 1728 sio.type = PORT_UNKNOWN;
@@ -1859,7 +1737,7 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1859 sio.hub6 = 0; 1737 sio.hub6 = 0;
1860 1738
1861 brdp = stli_brds[portp->brdnr]; 1739 brdp = stli_brds[portp->brdnr];
1862 if (brdp != (stlibrd_t *) NULL) 1740 if (brdp != NULL)
1863 sio.port = brdp->iobase; 1741 sio.port = brdp->iobase;
1864 1742
1865 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? 1743 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ?
@@ -1876,12 +1754,8 @@ static int stli_getserial(stliport_t *portp, struct serial_struct __user *sp)
1876 1754
1877static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp) 1755static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1878{ 1756{
1879 struct serial_struct sio; 1757 struct serial_struct sio;
1880 int rc; 1758 int rc;
1881
1882#ifdef DEBUG
1883 printk("stli_setserial(portp=%p,sp=%p)\n", portp, sp);
1884#endif
1885 1759
1886 if (copy_from_user(&sio, sp, sizeof(struct serial_struct))) 1760 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1887 return -EFAULT; 1761 return -EFAULT;
@@ -1890,7 +1764,7 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1890 (sio.close_delay != portp->close_delay) || 1764 (sio.close_delay != portp->close_delay) ||
1891 ((sio.flags & ~ASYNC_USR_MASK) != 1765 ((sio.flags & ~ASYNC_USR_MASK) !=
1892 (portp->flags & ~ASYNC_USR_MASK))) 1766 (portp->flags & ~ASYNC_USR_MASK)))
1893 return(-EPERM); 1767 return -EPERM;
1894 } 1768 }
1895 1769
1896 portp->flags = (portp->flags & ~ASYNC_USR_MASK) | 1770 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
@@ -1901,8 +1775,8 @@ static int stli_setserial(stliport_t *portp, struct serial_struct __user *sp)
1901 portp->custom_divisor = sio.custom_divisor; 1775 portp->custom_divisor = sio.custom_divisor;
1902 1776
1903 if ((rc = stli_setport(portp)) < 0) 1777 if ((rc = stli_setport(portp)) < 0)
1904 return(rc); 1778 return rc;
1905 return(0); 1779 return 0;
1906} 1780}
1907 1781
1908/*****************************************************************************/ 1782/*****************************************************************************/
@@ -1913,19 +1787,19 @@ static int stli_tiocmget(struct tty_struct *tty, struct file *file)
1913 stlibrd_t *brdp; 1787 stlibrd_t *brdp;
1914 int rc; 1788 int rc;
1915 1789
1916 if (portp == (stliport_t *) NULL) 1790 if (portp == NULL)
1917 return(-ENODEV); 1791 return -ENODEV;
1918 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1792 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1919 return(0); 1793 return 0;
1920 brdp = stli_brds[portp->brdnr]; 1794 brdp = stli_brds[portp->brdnr];
1921 if (brdp == (stlibrd_t *) NULL) 1795 if (brdp == NULL)
1922 return(0); 1796 return 0;
1923 if (tty->flags & (1 << TTY_IO_ERROR)) 1797 if (tty->flags & (1 << TTY_IO_ERROR))
1924 return(-EIO); 1798 return -EIO;
1925 1799
1926 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS, 1800 if ((rc = stli_cmdwait(brdp, portp, A_GETSIGNALS,
1927 &portp->asig, sizeof(asysigs_t), 1)) < 0) 1801 &portp->asig, sizeof(asysigs_t), 1)) < 0)
1928 return(rc); 1802 return rc;
1929 1803
1930 return stli_mktiocm(portp->asig.sigvalue); 1804 return stli_mktiocm(portp->asig.sigvalue);
1931} 1805}
@@ -1937,15 +1811,15 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1937 stlibrd_t *brdp; 1811 stlibrd_t *brdp;
1938 int rts = -1, dtr = -1; 1812 int rts = -1, dtr = -1;
1939 1813
1940 if (portp == (stliport_t *) NULL) 1814 if (portp == NULL)
1941 return(-ENODEV); 1815 return -ENODEV;
1942 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1816 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1943 return(0); 1817 return 0;
1944 brdp = stli_brds[portp->brdnr]; 1818 brdp = stli_brds[portp->brdnr];
1945 if (brdp == (stlibrd_t *) NULL) 1819 if (brdp == NULL)
1946 return(0); 1820 return 0;
1947 if (tty->flags & (1 << TTY_IO_ERROR)) 1821 if (tty->flags & (1 << TTY_IO_ERROR))
1948 return(-EIO); 1822 return -EIO;
1949 1823
1950 if (set & TIOCM_RTS) 1824 if (set & TIOCM_RTS)
1951 rts = 1; 1825 rts = 1;
@@ -1964,32 +1838,25 @@ static int stli_tiocmset(struct tty_struct *tty, struct file *file,
1964 1838
1965static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg) 1839static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1966{ 1840{
1967 stliport_t *portp; 1841 stliport_t *portp;
1968 stlibrd_t *brdp; 1842 stlibrd_t *brdp;
1969 unsigned int ival; 1843 unsigned int ival;
1970 int rc; 1844 int rc;
1971 void __user *argp = (void __user *)arg; 1845 void __user *argp = (void __user *)arg;
1972 1846
1973#ifdef DEBUG
1974 printk("stli_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1975 (int) tty, (int) file, cmd, (int) arg);
1976#endif
1977
1978 if (tty == (struct tty_struct *) NULL)
1979 return(-ENODEV);
1980 portp = tty->driver_data; 1847 portp = tty->driver_data;
1981 if (portp == (stliport_t *) NULL) 1848 if (portp == NULL)
1982 return(-ENODEV); 1849 return -ENODEV;
1983 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1850 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
1984 return(0); 1851 return 0;
1985 brdp = stli_brds[portp->brdnr]; 1852 brdp = stli_brds[portp->brdnr];
1986 if (brdp == (stlibrd_t *) NULL) 1853 if (brdp == NULL)
1987 return(0); 1854 return 0;
1988 1855
1989 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) && 1856 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1990 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) { 1857 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1991 if (tty->flags & (1 << TTY_IO_ERROR)) 1858 if (tty->flags & (1 << TTY_IO_ERROR))
1992 return(-EIO); 1859 return -EIO;
1993 } 1860 }
1994 1861
1995 rc = 0; 1862 rc = 0;
@@ -2036,7 +1903,7 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
2036 break; 1903 break;
2037 } 1904 }
2038 1905
2039 return(rc); 1906 return rc;
2040} 1907}
2041 1908
2042/*****************************************************************************/ 1909/*****************************************************************************/
@@ -2048,24 +1915,20 @@ static int stli_ioctl(struct tty_struct *tty, struct file *file, unsigned int cm
2048 1915
2049static void stli_settermios(struct tty_struct *tty, struct termios *old) 1916static void stli_settermios(struct tty_struct *tty, struct termios *old)
2050{ 1917{
2051 stliport_t *portp; 1918 stliport_t *portp;
2052 stlibrd_t *brdp; 1919 stlibrd_t *brdp;
2053 struct termios *tiosp; 1920 struct termios *tiosp;
2054 asyport_t aport; 1921 asyport_t aport;
2055
2056#ifdef DEBUG
2057 printk("stli_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
2058#endif
2059 1922
2060 if (tty == (struct tty_struct *) NULL) 1923 if (tty == NULL)
2061 return; 1924 return;
2062 portp = tty->driver_data; 1925 portp = tty->driver_data;
2063 if (portp == (stliport_t *) NULL) 1926 if (portp == NULL)
2064 return; 1927 return;
2065 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 1928 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2066 return; 1929 return;
2067 brdp = stli_brds[portp->brdnr]; 1930 brdp = stli_brds[portp->brdnr];
2068 if (brdp == (stlibrd_t *) NULL) 1931 if (brdp == NULL)
2069 return; 1932 return;
2070 1933
2071 tiosp = tty->termios; 1934 tiosp = tty->termios;
@@ -2098,18 +1961,9 @@ static void stli_settermios(struct tty_struct *tty, struct termios *old)
2098 1961
2099static void stli_throttle(struct tty_struct *tty) 1962static void stli_throttle(struct tty_struct *tty)
2100{ 1963{
2101 stliport_t *portp; 1964 stliport_t *portp = tty->driver_data;
2102 1965 if (portp == NULL)
2103#ifdef DEBUG
2104 printk("stli_throttle(tty=%x)\n", (int) tty);
2105#endif
2106
2107 if (tty == (struct tty_struct *) NULL)
2108 return; 1966 return;
2109 portp = tty->driver_data;
2110 if (portp == (stliport_t *) NULL)
2111 return;
2112
2113 set_bit(ST_RXSTOP, &portp->state); 1967 set_bit(ST_RXSTOP, &portp->state);
2114} 1968}
2115 1969
@@ -2123,88 +1977,30 @@ static void stli_throttle(struct tty_struct *tty)
2123 1977
2124static void stli_unthrottle(struct tty_struct *tty) 1978static void stli_unthrottle(struct tty_struct *tty)
2125{ 1979{
2126 stliport_t *portp; 1980 stliport_t *portp = tty->driver_data;
2127 1981 if (portp == NULL)
2128#ifdef DEBUG
2129 printk("stli_unthrottle(tty=%x)\n", (int) tty);
2130#endif
2131
2132 if (tty == (struct tty_struct *) NULL)
2133 return;
2134 portp = tty->driver_data;
2135 if (portp == (stliport_t *) NULL)
2136 return; 1982 return;
2137
2138 clear_bit(ST_RXSTOP, &portp->state); 1983 clear_bit(ST_RXSTOP, &portp->state);
2139} 1984}
2140 1985
2141/*****************************************************************************/ 1986/*****************************************************************************/
2142 1987
2143/* 1988/*
2144 * Stop the transmitter. Basically to do this we will just turn TX 1989 * Stop the transmitter.
2145 * interrupts off.
2146 */ 1990 */
2147 1991
2148static void stli_stop(struct tty_struct *tty) 1992static void stli_stop(struct tty_struct *tty)
2149{ 1993{
2150 stlibrd_t *brdp;
2151 stliport_t *portp;
2152 asyctrl_t actrl;
2153
2154#ifdef DEBUG
2155 printk("stli_stop(tty=%x)\n", (int) tty);
2156#endif
2157
2158 if (tty == (struct tty_struct *) NULL)
2159 return;
2160 portp = tty->driver_data;
2161 if (portp == (stliport_t *) NULL)
2162 return;
2163 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2164 return;
2165 brdp = stli_brds[portp->brdnr];
2166 if (brdp == (stlibrd_t *) NULL)
2167 return;
2168
2169 memset(&actrl, 0, sizeof(asyctrl_t));
2170 actrl.txctrl = CT_STOPFLOW;
2171#if 0
2172 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2173#endif
2174} 1994}
2175 1995
2176/*****************************************************************************/ 1996/*****************************************************************************/
2177 1997
2178/* 1998/*
2179 * Start the transmitter again. Just turn TX interrupts back on. 1999 * Start the transmitter again.
2180 */ 2000 */
2181 2001
2182static void stli_start(struct tty_struct *tty) 2002static void stli_start(struct tty_struct *tty)
2183{ 2003{
2184 stliport_t *portp;
2185 stlibrd_t *brdp;
2186 asyctrl_t actrl;
2187
2188#ifdef DEBUG
2189 printk("stli_start(tty=%x)\n", (int) tty);
2190#endif
2191
2192 if (tty == (struct tty_struct *) NULL)
2193 return;
2194 portp = tty->driver_data;
2195 if (portp == (stliport_t *) NULL)
2196 return;
2197 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds))
2198 return;
2199 brdp = stli_brds[portp->brdnr];
2200 if (brdp == (stlibrd_t *) NULL)
2201 return;
2202
2203 memset(&actrl, 0, sizeof(asyctrl_t));
2204 actrl.txctrl = CT_STARTFLOW;
2205#if 0
2206 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2207#endif
2208} 2004}
2209 2005
2210/*****************************************************************************/ 2006/*****************************************************************************/
@@ -2220,22 +2016,9 @@ static void stli_start(struct tty_struct *tty)
2220 2016
2221static void stli_dohangup(void *arg) 2017static void stli_dohangup(void *arg)
2222{ 2018{
2223 stliport_t *portp; 2019 stliport_t *portp = (stliport_t *) arg;
2224 2020 if (portp->tty != NULL) {
2225#ifdef DEBUG 2021 tty_hangup(portp->tty);
2226 printk(KERN_DEBUG "stli_dohangup(portp=%x)\n", (int) arg);
2227#endif
2228
2229 /*
2230 * FIXME: There's a module removal race here: tty_hangup
2231 * calls schedule_work which will call into this
2232 * driver later.
2233 */
2234 portp = (stliport_t *) arg;
2235 if (portp != (stliport_t *) NULL) {
2236 if (portp->tty != (struct tty_struct *) NULL) {
2237 tty_hangup(portp->tty);
2238 }
2239 } 2022 }
2240} 2023}
2241 2024
@@ -2250,31 +2033,25 @@ static void stli_dohangup(void *arg)
2250 2033
2251static void stli_hangup(struct tty_struct *tty) 2034static void stli_hangup(struct tty_struct *tty)
2252{ 2035{
2253 stliport_t *portp; 2036 stliport_t *portp;
2254 stlibrd_t *brdp; 2037 stlibrd_t *brdp;
2255 unsigned long flags; 2038 unsigned long flags;
2256
2257#ifdef DEBUG
2258 printk(KERN_DEBUG "stli_hangup(tty=%x)\n", (int) tty);
2259#endif
2260 2039
2261 if (tty == (struct tty_struct *) NULL)
2262 return;
2263 portp = tty->driver_data; 2040 portp = tty->driver_data;
2264 if (portp == (stliport_t *) NULL) 2041 if (portp == NULL)
2265 return; 2042 return;
2266 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2043 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2267 return; 2044 return;
2268 brdp = stli_brds[portp->brdnr]; 2045 brdp = stli_brds[portp->brdnr];
2269 if (brdp == (stlibrd_t *) NULL) 2046 if (brdp == NULL)
2270 return; 2047 return;
2271 2048
2272 portp->flags &= ~ASYNC_INITIALIZED; 2049 portp->flags &= ~ASYNC_INITIALIZED;
2273 2050
2274 save_flags(flags); 2051 if (!test_bit(ST_CLOSING, &portp->state))
2275 cli();
2276 if (! test_bit(ST_CLOSING, &portp->state))
2277 stli_rawclose(brdp, portp, 0, 0); 2052 stli_rawclose(brdp, portp, 0, 0);
2053
2054 spin_lock_irqsave(&stli_lock, flags);
2278 if (tty->termios->c_cflag & HUPCL) { 2055 if (tty->termios->c_cflag & HUPCL) {
2279 stli_mkasysigs(&portp->asig, 0, 0); 2056 stli_mkasysigs(&portp->asig, 0, 0);
2280 if (test_bit(ST_CMDING, &portp->state)) { 2057 if (test_bit(ST_CMDING, &portp->state)) {
@@ -2286,14 +2063,15 @@ static void stli_hangup(struct tty_struct *tty)
2286 &portp->asig, sizeof(asysigs_t), 0); 2063 &portp->asig, sizeof(asysigs_t), 0);
2287 } 2064 }
2288 } 2065 }
2289 restore_flags(flags);
2290 2066
2291 clear_bit(ST_TXBUSY, &portp->state); 2067 clear_bit(ST_TXBUSY, &portp->state);
2292 clear_bit(ST_RXSTOP, &portp->state); 2068 clear_bit(ST_RXSTOP, &portp->state);
2293 set_bit(TTY_IO_ERROR, &tty->flags); 2069 set_bit(TTY_IO_ERROR, &tty->flags);
2294 portp->tty = (struct tty_struct *) NULL; 2070 portp->tty = NULL;
2295 portp->flags &= ~ASYNC_NORMAL_ACTIVE; 2071 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
2296 portp->refcount = 0; 2072 portp->refcount = 0;
2073 spin_unlock_irqrestore(&stli_lock, flags);
2074
2297 wake_up_interruptible(&portp->open_wait); 2075 wake_up_interruptible(&portp->open_wait);
2298} 2076}
2299 2077
@@ -2308,29 +2086,22 @@ static void stli_hangup(struct tty_struct *tty)
2308 2086
2309static void stli_flushbuffer(struct tty_struct *tty) 2087static void stli_flushbuffer(struct tty_struct *tty)
2310{ 2088{
2311 stliport_t *portp; 2089 stliport_t *portp;
2312 stlibrd_t *brdp; 2090 stlibrd_t *brdp;
2313 unsigned long ftype, flags; 2091 unsigned long ftype, flags;
2314
2315#ifdef DEBUG
2316 printk(KERN_DEBUG "stli_flushbuffer(tty=%x)\n", (int) tty);
2317#endif
2318 2092
2319 if (tty == (struct tty_struct *) NULL)
2320 return;
2321 portp = tty->driver_data; 2093 portp = tty->driver_data;
2322 if (portp == (stliport_t *) NULL) 2094 if (portp == NULL)
2323 return; 2095 return;
2324 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2096 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2325 return; 2097 return;
2326 brdp = stli_brds[portp->brdnr]; 2098 brdp = stli_brds[portp->brdnr];
2327 if (brdp == (stlibrd_t *) NULL) 2099 if (brdp == NULL)
2328 return; 2100 return;
2329 2101
2330 save_flags(flags); 2102 spin_lock_irqsave(&brd_lock, flags);
2331 cli();
2332 if (tty == stli_txcooktty) { 2103 if (tty == stli_txcooktty) {
2333 stli_txcooktty = (struct tty_struct *) NULL; 2104 stli_txcooktty = NULL;
2334 stli_txcooksize = 0; 2105 stli_txcooksize = 0;
2335 stli_txcookrealsize = 0; 2106 stli_txcookrealsize = 0;
2336 } 2107 }
@@ -2342,15 +2113,10 @@ static void stli_flushbuffer(struct tty_struct *tty)
2342 ftype |= FLUSHRX; 2113 ftype |= FLUSHRX;
2343 clear_bit(ST_DOFLUSHRX, &portp->state); 2114 clear_bit(ST_DOFLUSHRX, &portp->state);
2344 } 2115 }
2345 stli_sendcmd(brdp, portp, A_FLUSH, &ftype, 2116 __stli_sendcmd(brdp, portp, A_FLUSH, &ftype, sizeof(u32), 0);
2346 sizeof(unsigned long), 0);
2347 } 2117 }
2348 restore_flags(flags); 2118 spin_unlock_irqrestore(&brd_lock, flags);
2349 2119 tty_wakeup(tty);
2350 wake_up_interruptible(&tty->write_wait);
2351 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2352 tty->ldisc.write_wakeup)
2353 (tty->ldisc.write_wakeup)(tty);
2354} 2120}
2355 2121
2356/*****************************************************************************/ 2122/*****************************************************************************/
@@ -2360,55 +2126,31 @@ static void stli_breakctl(struct tty_struct *tty, int state)
2360 stlibrd_t *brdp; 2126 stlibrd_t *brdp;
2361 stliport_t *portp; 2127 stliport_t *portp;
2362 long arg; 2128 long arg;
2363 /* long savestate, savetime; */
2364 2129
2365#ifdef DEBUG
2366 printk(KERN_DEBUG "stli_breakctl(tty=%x,state=%d)\n", (int) tty, state);
2367#endif
2368
2369 if (tty == (struct tty_struct *) NULL)
2370 return;
2371 portp = tty->driver_data; 2130 portp = tty->driver_data;
2372 if (portp == (stliport_t *) NULL) 2131 if (portp == NULL)
2373 return; 2132 return;
2374 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2133 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2375 return; 2134 return;
2376 brdp = stli_brds[portp->brdnr]; 2135 brdp = stli_brds[portp->brdnr];
2377 if (brdp == (stlibrd_t *) NULL) 2136 if (brdp == NULL)
2378 return; 2137 return;
2379 2138
2380/*
2381 * Due to a bug in the tty send_break() code we need to preserve
2382 * the current process state and timeout...
2383 savetime = current->timeout;
2384 savestate = current->state;
2385 */
2386
2387 arg = (state == -1) ? BREAKON : BREAKOFF; 2139 arg = (state == -1) ? BREAKON : BREAKOFF;
2388 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0); 2140 stli_cmdwait(brdp, portp, A_BREAK, &arg, sizeof(long), 0);
2389
2390/*
2391 *
2392 current->timeout = savetime;
2393 current->state = savestate;
2394 */
2395} 2141}
2396 2142
2397/*****************************************************************************/ 2143/*****************************************************************************/
2398 2144
2399static void stli_waituntilsent(struct tty_struct *tty, int timeout) 2145static void stli_waituntilsent(struct tty_struct *tty, int timeout)
2400{ 2146{
2401 stliport_t *portp; 2147 stliport_t *portp;
2402 unsigned long tend; 2148 unsigned long tend;
2403 2149
2404#ifdef DEBUG 2150 if (tty == NULL)
2405 printk(KERN_DEBUG "stli_waituntilsent(tty=%x,timeout=%x)\n", (int) tty, timeout);
2406#endif
2407
2408 if (tty == (struct tty_struct *) NULL)
2409 return; 2151 return;
2410 portp = tty->driver_data; 2152 portp = tty->driver_data;
2411 if (portp == (stliport_t *) NULL) 2153 if (portp == NULL)
2412 return; 2154 return;
2413 2155
2414 if (timeout == 0) 2156 if (timeout == 0)
@@ -2432,19 +2174,13 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2432 stliport_t *portp; 2174 stliport_t *portp;
2433 asyctrl_t actrl; 2175 asyctrl_t actrl;
2434 2176
2435#ifdef DEBUG
2436 printk(KERN_DEBUG "stli_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
2437#endif
2438
2439 if (tty == (struct tty_struct *) NULL)
2440 return;
2441 portp = tty->driver_data; 2177 portp = tty->driver_data;
2442 if (portp == (stliport_t *) NULL) 2178 if (portp == NULL)
2443 return; 2179 return;
2444 if ((portp->brdnr < 0) || (portp->brdnr >= stli_nrbrds)) 2180 if (portp->brdnr < 0 || portp->brdnr >= stli_nrbrds)
2445 return; 2181 return;
2446 brdp = stli_brds[portp->brdnr]; 2182 brdp = stli_brds[portp->brdnr];
2447 if (brdp == (stlibrd_t *) NULL) 2183 if (brdp == NULL)
2448 return; 2184 return;
2449 2185
2450 memset(&actrl, 0, sizeof(asyctrl_t)); 2186 memset(&actrl, 0, sizeof(asyctrl_t));
@@ -2456,7 +2192,6 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2456 actrl.txctrl = CT_SENDCHR; 2192 actrl.txctrl = CT_SENDCHR;
2457 actrl.tximdch = ch; 2193 actrl.tximdch = ch;
2458 } 2194 }
2459
2460 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0); 2195 stli_cmdwait(brdp, portp, A_PORTCTRL, &actrl, sizeof(asyctrl_t), 0);
2461} 2196}
2462 2197
@@ -2472,17 +2207,17 @@ static void stli_sendxchar(struct tty_struct *tty, char ch)
2472 2207
2473static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos) 2208static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *pos)
2474{ 2209{
2475 char *sp, *uart; 2210 char *sp, *uart;
2476 int rc, cnt; 2211 int rc, cnt;
2477 2212
2478 rc = stli_portcmdstats(portp); 2213 rc = stli_portcmdstats(portp);
2479 2214
2480 uart = "UNKNOWN"; 2215 uart = "UNKNOWN";
2481 if (brdp->state & BST_STARTED) { 2216 if (brdp->state & BST_STARTED) {
2482 switch (stli_comstats.hwid) { 2217 switch (stli_comstats.hwid) {
2483 case 0: uart = "2681"; break; 2218 case 0: uart = "2681"; break;
2484 case 1: uart = "SC26198"; break; 2219 case 1: uart = "SC26198"; break;
2485 default: uart = "CD1400"; break; 2220 default:uart = "CD1400"; break;
2486 } 2221 }
2487 } 2222 }
2488 2223
@@ -2533,17 +2268,11 @@ static int stli_portinfo(stlibrd_t *brdp, stliport_t *portp, int portnr, char *p
2533 2268
2534static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data) 2269static int stli_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
2535{ 2270{
2536 stlibrd_t *brdp; 2271 stlibrd_t *brdp;
2537 stliport_t *portp; 2272 stliport_t *portp;
2538 int brdnr, portnr, totalport; 2273 int brdnr, portnr, totalport;
2539 int curoff, maxoff; 2274 int curoff, maxoff;
2540 char *pos; 2275 char *pos;
2541
2542#ifdef DEBUG
2543 printk(KERN_DEBUG "stli_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2544 "data=%x\n", (int) page, (int) start, (int) off, count,
2545 (int) eof, (int) data);
2546#endif
2547 2276
2548 pos = page; 2277 pos = page;
2549 totalport = 0; 2278 totalport = 0;
@@ -2564,7 +2293,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
2564 */ 2293 */
2565 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { 2294 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
2566 brdp = stli_brds[brdnr]; 2295 brdp = stli_brds[brdnr];
2567 if (brdp == (stlibrd_t *) NULL) 2296 if (brdp == NULL)
2568 continue; 2297 continue;
2569 if (brdp->state == 0) 2298 if (brdp->state == 0)
2570 continue; 2299 continue;
@@ -2579,7 +2308,7 @@ static int stli_readproc(char *page, char **start, off_t off, int count, int *eo
2579 for (portnr = 0; (portnr < brdp->nrports); portnr++, 2308 for (portnr = 0; (portnr < brdp->nrports); portnr++,
2580 totalport++) { 2309 totalport++) {
2581 portp = brdp->ports[portnr]; 2310 portp = brdp->ports[portnr];
2582 if (portp == (stliport_t *) NULL) 2311 if (portp == NULL)
2583 continue; 2312 continue;
2584 if (off >= (curoff += MAXLINE)) 2313 if (off >= (curoff += MAXLINE))
2585 continue; 2314 continue;
@@ -2606,49 +2335,54 @@ stli_readdone:
2606 * a poll routine that does not have user context. Therefore you cannot 2335 * a poll routine that does not have user context. Therefore you cannot
2607 * copy back directly into user space, or to the kernel stack of a 2336 * copy back directly into user space, or to the kernel stack of a
2608 * process. This routine does not sleep, so can be called from anywhere. 2337 * process. This routine does not sleep, so can be called from anywhere.
2338 *
2339 * The caller must hold the brd_lock (see also stli_sendcmd the usual
2340 * entry point)
2609 */ 2341 */
2610 2342
2611static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback) 2343static void __stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2612{ 2344{
2613 volatile cdkhdr_t *hdrp; 2345 cdkhdr_t __iomem *hdrp;
2614 volatile cdkctrl_t *cp; 2346 cdkctrl_t __iomem *cp;
2615 volatile unsigned char *bits; 2347 unsigned char __iomem *bits;
2616 unsigned long flags; 2348 unsigned long flags;
2617 2349
2618#ifdef DEBUG 2350 spin_lock_irqsave(&brd_lock, flags);
2619 printk(KERN_DEBUG "stli_sendcmd(brdp=%x,portp=%x,cmd=%x,arg=%x,size=%d,"
2620 "copyback=%d)\n", (int) brdp, (int) portp, (int) cmd,
2621 (int) arg, size, copyback);
2622#endif
2623
2624 save_flags(flags);
2625 cli();
2626 2351
2627 if (test_bit(ST_CMDING, &portp->state)) { 2352 if (test_bit(ST_CMDING, &portp->state)) {
2628 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n", 2353 printk(KERN_ERR "STALLION: command already busy, cmd=%x!\n",
2629 (int) cmd); 2354 (int) cmd);
2630 restore_flags(flags); 2355 spin_unlock_irqrestore(&brd_lock, flags);
2631 return; 2356 return;
2632 } 2357 }
2633 2358
2634 EBRDENABLE(brdp); 2359 EBRDENABLE(brdp);
2635 cp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl; 2360 cp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->ctrl;
2636 if (size > 0) { 2361 if (size > 0) {
2637 memcpy((void *) &(cp->args[0]), arg, size); 2362 memcpy_toio((void __iomem *) &(cp->args[0]), arg, size);
2638 if (copyback) { 2363 if (copyback) {
2639 portp->argp = arg; 2364 portp->argp = arg;
2640 portp->argsize = size; 2365 portp->argsize = size;
2641 } 2366 }
2642 } 2367 }
2643 cp->status = 0; 2368 writel(0, &cp->status);
2644 cp->cmd = cmd; 2369 writel(cmd, &cp->cmd);
2645 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2370 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2646 bits = ((volatile unsigned char *) hdrp) + brdp->slaveoffset + 2371 bits = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset +
2647 portp->portidx; 2372 portp->portidx;
2648 *bits |= portp->portbit; 2373 writeb(readb(bits) | portp->portbit, bits);
2649 set_bit(ST_CMDING, &portp->state); 2374 set_bit(ST_CMDING, &portp->state);
2650 EBRDDISABLE(brdp); 2375 EBRDDISABLE(brdp);
2651 restore_flags(flags); 2376 spin_unlock_irqrestore(&brd_lock, flags);
2377}
2378
2379static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd, void *arg, int size, int copyback)
2380{
2381 unsigned long flags;
2382
2383 spin_lock_irqsave(&brd_lock, flags);
2384 __stli_sendcmd(brdp, portp, cmd, arg, size, copyback);
2385 spin_unlock_irqrestore(&brd_lock, flags);
2652} 2386}
2653 2387
2654/*****************************************************************************/ 2388/*****************************************************************************/
@@ -2663,28 +2397,23 @@ static void stli_sendcmd(stlibrd_t *brdp, stliport_t *portp, unsigned long cmd,
2663 2397
2664static void stli_read(stlibrd_t *brdp, stliport_t *portp) 2398static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2665{ 2399{
2666 volatile cdkasyrq_t *rp; 2400 cdkasyrq_t __iomem *rp;
2667 volatile char *shbuf; 2401 char __iomem *shbuf;
2668 struct tty_struct *tty; 2402 struct tty_struct *tty;
2669 unsigned int head, tail, size; 2403 unsigned int head, tail, size;
2670 unsigned int len, stlen; 2404 unsigned int len, stlen;
2671
2672#ifdef DEBUG
2673 printk(KERN_DEBUG "stli_read(brdp=%x,portp=%d)\n",
2674 (int) brdp, (int) portp);
2675#endif
2676 2405
2677 if (test_bit(ST_RXSTOP, &portp->state)) 2406 if (test_bit(ST_RXSTOP, &portp->state))
2678 return; 2407 return;
2679 tty = portp->tty; 2408 tty = portp->tty;
2680 if (tty == (struct tty_struct *) NULL) 2409 if (tty == NULL)
2681 return; 2410 return;
2682 2411
2683 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; 2412 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2684 head = (unsigned int) rp->head; 2413 head = (unsigned int) readw(&rp->head);
2685 if (head != ((unsigned int) rp->head)) 2414 if (head != ((unsigned int) readw(&rp->head)))
2686 head = (unsigned int) rp->head; 2415 head = (unsigned int) readw(&rp->head);
2687 tail = (unsigned int) rp->tail; 2416 tail = (unsigned int) readw(&rp->tail);
2688 size = portp->rxsize; 2417 size = portp->rxsize;
2689 if (head >= tail) { 2418 if (head >= tail) {
2690 len = head - tail; 2419 len = head - tail;
@@ -2695,12 +2424,15 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2695 } 2424 }
2696 2425
2697 len = tty_buffer_request_room(tty, len); 2426 len = tty_buffer_request_room(tty, len);
2698 /* FIXME : iomap ? */ 2427
2699 shbuf = (volatile char *) EBRDGETMEMPTR(brdp, portp->rxoffset); 2428 shbuf = (char __iomem *) EBRDGETMEMPTR(brdp, portp->rxoffset);
2700 2429
2701 while (len > 0) { 2430 while (len > 0) {
2431 unsigned char *cptr;
2432
2702 stlen = MIN(len, stlen); 2433 stlen = MIN(len, stlen);
2703 tty_insert_flip_string(tty, (char *)(shbuf + tail), stlen); 2434 tty_prepare_flip_string(tty, &cptr, stlen);
2435 memcpy_fromio(cptr, shbuf + tail, stlen);
2704 len -= stlen; 2436 len -= stlen;
2705 tail += stlen; 2437 tail += stlen;
2706 if (tail >= size) { 2438 if (tail >= size) {
@@ -2708,8 +2440,8 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2708 stlen = head; 2440 stlen = head;
2709 } 2441 }
2710 } 2442 }
2711 rp = &((volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr))->rxq; 2443 rp = &((cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr))->rxq;
2712 rp->tail = tail; 2444 writew(tail, &rp->tail);
2713 2445
2714 if (head != tail) 2446 if (head != tail)
2715 set_bit(ST_RXING, &portp->state); 2447 set_bit(ST_RXING, &portp->state);
@@ -2725,9 +2457,9 @@ static void stli_read(stlibrd_t *brdp, stliport_t *portp)
2725 * difficult to deal with them here. 2457 * difficult to deal with them here.
2726 */ 2458 */
2727 2459
2728static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp) 2460static void stli_dodelaycmd(stliport_t *portp, cdkctrl_t __iomem *cp)
2729{ 2461{
2730 int cmd; 2462 int cmd;
2731 2463
2732 if (test_bit(ST_DOSIGS, &portp->state)) { 2464 if (test_bit(ST_DOSIGS, &portp->state)) {
2733 if (test_bit(ST_DOFLUSHTX, &portp->state) && 2465 if (test_bit(ST_DOFLUSHTX, &portp->state) &&
@@ -2742,10 +2474,10 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2742 clear_bit(ST_DOFLUSHTX, &portp->state); 2474 clear_bit(ST_DOFLUSHTX, &portp->state);
2743 clear_bit(ST_DOFLUSHRX, &portp->state); 2475 clear_bit(ST_DOFLUSHRX, &portp->state);
2744 clear_bit(ST_DOSIGS, &portp->state); 2476 clear_bit(ST_DOSIGS, &portp->state);
2745 memcpy((void *) &(cp->args[0]), (void *) &portp->asig, 2477 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &portp->asig,
2746 sizeof(asysigs_t)); 2478 sizeof(asysigs_t));
2747 cp->status = 0; 2479 writel(0, &cp->status);
2748 cp->cmd = cmd; 2480 writel(cmd, &cp->cmd);
2749 set_bit(ST_CMDING, &portp->state); 2481 set_bit(ST_CMDING, &portp->state);
2750 } else if (test_bit(ST_DOFLUSHTX, &portp->state) || 2482 } else if (test_bit(ST_DOFLUSHTX, &portp->state) ||
2751 test_bit(ST_DOFLUSHRX, &portp->state)) { 2483 test_bit(ST_DOFLUSHRX, &portp->state)) {
@@ -2753,9 +2485,9 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2753 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0); 2485 cmd |= ((test_bit(ST_DOFLUSHRX, &portp->state)) ? FLUSHRX : 0);
2754 clear_bit(ST_DOFLUSHTX, &portp->state); 2486 clear_bit(ST_DOFLUSHTX, &portp->state);
2755 clear_bit(ST_DOFLUSHRX, &portp->state); 2487 clear_bit(ST_DOFLUSHRX, &portp->state);
2756 memcpy((void *) &(cp->args[0]), (void *) &cmd, sizeof(int)); 2488 memcpy_toio((void __iomem *) &(cp->args[0]), (void *) &cmd, sizeof(int));
2757 cp->status = 0; 2489 writel(0, &cp->status);
2758 cp->cmd = A_FLUSH; 2490 writel(A_FLUSH, &cp->cmd);
2759 set_bit(ST_CMDING, &portp->state); 2491 set_bit(ST_CMDING, &portp->state);
2760 } 2492 }
2761} 2493}
@@ -2775,30 +2507,25 @@ static void stli_dodelaycmd(stliport_t *portp, volatile cdkctrl_t *cp)
2775 2507
2776static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp) 2508static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2777{ 2509{
2778 volatile cdkasy_t *ap; 2510 cdkasy_t __iomem *ap;
2779 volatile cdkctrl_t *cp; 2511 cdkctrl_t __iomem *cp;
2780 struct tty_struct *tty; 2512 struct tty_struct *tty;
2781 asynotify_t nt; 2513 asynotify_t nt;
2782 unsigned long oldsigs; 2514 unsigned long oldsigs;
2783 int rc, donerx; 2515 int rc, donerx;
2784 2516
2785#ifdef DEBUG 2517 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
2786 printk(KERN_DEBUG "stli_hostcmd(brdp=%x,channr=%d)\n",
2787 (int) brdp, channr);
2788#endif
2789
2790 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr);
2791 cp = &ap->ctrl; 2518 cp = &ap->ctrl;
2792 2519
2793/* 2520/*
2794 * Check if we are waiting for an open completion message. 2521 * Check if we are waiting for an open completion message.
2795 */ 2522 */
2796 if (test_bit(ST_OPENING, &portp->state)) { 2523 if (test_bit(ST_OPENING, &portp->state)) {
2797 rc = (int) cp->openarg; 2524 rc = readl(&cp->openarg);
2798 if ((cp->open == 0) && (rc != 0)) { 2525 if (readb(&cp->open) == 0 && rc != 0) {
2799 if (rc > 0) 2526 if (rc > 0)
2800 rc--; 2527 rc--;
2801 cp->openarg = 0; 2528 writel(0, &cp->openarg);
2802 portp->rc = rc; 2529 portp->rc = rc;
2803 clear_bit(ST_OPENING, &portp->state); 2530 clear_bit(ST_OPENING, &portp->state);
2804 wake_up_interruptible(&portp->raw_wait); 2531 wake_up_interruptible(&portp->raw_wait);
@@ -2809,11 +2536,11 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2809 * Check if we are waiting for a close completion message. 2536 * Check if we are waiting for a close completion message.
2810 */ 2537 */
2811 if (test_bit(ST_CLOSING, &portp->state)) { 2538 if (test_bit(ST_CLOSING, &portp->state)) {
2812 rc = (int) cp->closearg; 2539 rc = (int) readl(&cp->closearg);
2813 if ((cp->close == 0) && (rc != 0)) { 2540 if (readb(&cp->close) == 0 && rc != 0) {
2814 if (rc > 0) 2541 if (rc > 0)
2815 rc--; 2542 rc--;
2816 cp->closearg = 0; 2543 writel(0, &cp->closearg);
2817 portp->rc = rc; 2544 portp->rc = rc;
2818 clear_bit(ST_CLOSING, &portp->state); 2545 clear_bit(ST_CLOSING, &portp->state);
2819 wake_up_interruptible(&portp->raw_wait); 2546 wake_up_interruptible(&portp->raw_wait);
@@ -2825,16 +2552,16 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2825 * need to copy out the command results associated with this command. 2552 * need to copy out the command results associated with this command.
2826 */ 2553 */
2827 if (test_bit(ST_CMDING, &portp->state)) { 2554 if (test_bit(ST_CMDING, &portp->state)) {
2828 rc = cp->status; 2555 rc = readl(&cp->status);
2829 if ((cp->cmd == 0) && (rc != 0)) { 2556 if (readl(&cp->cmd) == 0 && rc != 0) {
2830 if (rc > 0) 2557 if (rc > 0)
2831 rc--; 2558 rc--;
2832 if (portp->argp != (void *) NULL) { 2559 if (portp->argp != NULL) {
2833 memcpy(portp->argp, (void *) &(cp->args[0]), 2560 memcpy_fromio(portp->argp, (void __iomem *) &(cp->args[0]),
2834 portp->argsize); 2561 portp->argsize);
2835 portp->argp = (void *) NULL; 2562 portp->argp = NULL;
2836 } 2563 }
2837 cp->status = 0; 2564 writel(0, &cp->status);
2838 portp->rc = rc; 2565 portp->rc = rc;
2839 clear_bit(ST_CMDING, &portp->state); 2566 clear_bit(ST_CMDING, &portp->state);
2840 stli_dodelaycmd(portp, cp); 2567 stli_dodelaycmd(portp, cp);
@@ -2873,18 +2600,15 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2873 if (nt.data & DT_TXEMPTY) 2600 if (nt.data & DT_TXEMPTY)
2874 clear_bit(ST_TXBUSY, &portp->state); 2601 clear_bit(ST_TXBUSY, &portp->state);
2875 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) { 2602 if (nt.data & (DT_TXEMPTY | DT_TXLOW)) {
2876 if (tty != (struct tty_struct *) NULL) { 2603 if (tty != NULL) {
2877 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) && 2604 tty_wakeup(tty);
2878 tty->ldisc.write_wakeup) { 2605 EBRDENABLE(brdp);
2879 (tty->ldisc.write_wakeup)(tty);
2880 EBRDENABLE(brdp);
2881 }
2882 wake_up_interruptible(&tty->write_wait); 2606 wake_up_interruptible(&tty->write_wait);
2883 } 2607 }
2884 } 2608 }
2885 2609
2886 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) { 2610 if ((nt.data & DT_RXBREAK) && (portp->rxmarkmsk & BRKINT)) {
2887 if (tty != (struct tty_struct *) NULL) { 2611 if (tty != NULL) {
2888 tty_insert_flip_char(tty, 0, TTY_BREAK); 2612 tty_insert_flip_char(tty, 0, TTY_BREAK);
2889 if (portp->flags & ASYNC_SAK) { 2613 if (portp->flags & ASYNC_SAK) {
2890 do_SAK(tty); 2614 do_SAK(tty);
@@ -2928,14 +2652,14 @@ static int stli_hostcmd(stlibrd_t *brdp, stliport_t *portp)
2928 * at the cdk header structure. 2652 * at the cdk header structure.
2929 */ 2653 */
2930 2654
2931static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp) 2655static void stli_brdpoll(stlibrd_t *brdp, cdkhdr_t __iomem *hdrp)
2932{ 2656{
2933 stliport_t *portp; 2657 stliport_t *portp;
2934 unsigned char hostbits[(STL_MAXCHANS / 8) + 1]; 2658 unsigned char hostbits[(STL_MAXCHANS / 8) + 1];
2935 unsigned char slavebits[(STL_MAXCHANS / 8) + 1]; 2659 unsigned char slavebits[(STL_MAXCHANS / 8) + 1];
2936 unsigned char *slavep; 2660 unsigned char __iomem *slavep;
2937 int bitpos, bitat, bitsize; 2661 int bitpos, bitat, bitsize;
2938 int channr, nrdevs, slavebitchange; 2662 int channr, nrdevs, slavebitchange;
2939 2663
2940 bitsize = brdp->bitsize; 2664 bitsize = brdp->bitsize;
2941 nrdevs = brdp->nrdevs; 2665 nrdevs = brdp->nrdevs;
@@ -2947,7 +2671,7 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2947 * 8 service bits at a time in the inner loop, so we can bypass 2671 * 8 service bits at a time in the inner loop, so we can bypass
2948 * the lot if none of them want service. 2672 * the lot if none of them want service.
2949 */ 2673 */
2950 memcpy(&hostbits[0], (((unsigned char *) hdrp) + brdp->hostoffset), 2674 memcpy_fromio(&hostbits[0], (((unsigned char __iomem *) hdrp) + brdp->hostoffset),
2951 bitsize); 2675 bitsize);
2952 2676
2953 memset(&slavebits[0], 0, bitsize); 2677 memset(&slavebits[0], 0, bitsize);
@@ -2974,11 +2698,11 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2974 * service may initiate more slave requests. 2698 * service may initiate more slave requests.
2975 */ 2699 */
2976 if (slavebitchange) { 2700 if (slavebitchange) {
2977 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2701 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
2978 slavep = ((unsigned char *) hdrp) + brdp->slaveoffset; 2702 slavep = ((unsigned char __iomem *) hdrp) + brdp->slaveoffset;
2979 for (bitpos = 0; (bitpos < bitsize); bitpos++) { 2703 for (bitpos = 0; (bitpos < bitsize); bitpos++) {
2980 if (slavebits[bitpos]) 2704 if (readb(slavebits + bitpos))
2981 slavep[bitpos] &= ~slavebits[bitpos]; 2705 writeb(readb(slavep + bitpos) & ~slavebits[bitpos], slavebits + bitpos);
2982 } 2706 }
2983 } 2707 }
2984} 2708}
@@ -2996,9 +2720,9 @@ static void stli_brdpoll(stlibrd_t *brdp, volatile cdkhdr_t *hdrp)
2996 2720
2997static void stli_poll(unsigned long arg) 2721static void stli_poll(unsigned long arg)
2998{ 2722{
2999 volatile cdkhdr_t *hdrp; 2723 cdkhdr_t __iomem *hdrp;
3000 stlibrd_t *brdp; 2724 stlibrd_t *brdp;
3001 int brdnr; 2725 int brdnr;
3002 2726
3003 stli_timerlist.expires = STLI_TIMEOUT; 2727 stli_timerlist.expires = STLI_TIMEOUT;
3004 add_timer(&stli_timerlist); 2728 add_timer(&stli_timerlist);
@@ -3008,16 +2732,18 @@ static void stli_poll(unsigned long arg)
3008 */ 2732 */
3009 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) { 2733 for (brdnr = 0; (brdnr < stli_nrbrds); brdnr++) {
3010 brdp = stli_brds[brdnr]; 2734 brdp = stli_brds[brdnr];
3011 if (brdp == (stlibrd_t *) NULL) 2735 if (brdp == NULL)
3012 continue; 2736 continue;
3013 if ((brdp->state & BST_STARTED) == 0) 2737 if ((brdp->state & BST_STARTED) == 0)
3014 continue; 2738 continue;
3015 2739
2740 spin_lock(&brd_lock);
3016 EBRDENABLE(brdp); 2741 EBRDENABLE(brdp);
3017 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 2742 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
3018 if (hdrp->hostreq) 2743 if (readb(&hdrp->hostreq))
3019 stli_brdpoll(brdp, hdrp); 2744 stli_brdpoll(brdp, hdrp);
3020 EBRDDISABLE(brdp); 2745 EBRDDISABLE(brdp);
2746 spin_unlock(&brd_lock);
3021 } 2747 }
3022} 2748}
3023 2749
@@ -3030,11 +2756,6 @@ static void stli_poll(unsigned long arg)
3030 2756
3031static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp) 2757static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tiosp)
3032{ 2758{
3033#ifdef DEBUG
3034 printk(KERN_DEBUG "stli_mkasyport(portp=%x,pp=%x,tiosp=%d)\n",
3035 (int) portp, (int) pp, (int) tiosp);
3036#endif
3037
3038 memset(pp, 0, sizeof(asyport_t)); 2759 memset(pp, 0, sizeof(asyport_t));
3039 2760
3040/* 2761/*
@@ -3153,11 +2874,6 @@ static void stli_mkasyport(stliport_t *portp, asyport_t *pp, struct termios *tio
3153 2874
3154static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts) 2875static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3155{ 2876{
3156#ifdef DEBUG
3157 printk(KERN_DEBUG "stli_mkasysigs(sp=%x,dtr=%d,rts=%d)\n",
3158 (int) sp, dtr, rts);
3159#endif
3160
3161 memset(sp, 0, sizeof(asysigs_t)); 2877 memset(sp, 0, sizeof(asysigs_t));
3162 if (dtr >= 0) { 2878 if (dtr >= 0) {
3163 sp->signal |= SG_DTR; 2879 sp->signal |= SG_DTR;
@@ -3178,13 +2894,7 @@ static void stli_mkasysigs(asysigs_t *sp, int dtr, int rts)
3178 2894
3179static long stli_mktiocm(unsigned long sigvalue) 2895static long stli_mktiocm(unsigned long sigvalue)
3180{ 2896{
3181 long tiocm; 2897 long tiocm = 0;
3182
3183#ifdef DEBUG
3184 printk(KERN_DEBUG "stli_mktiocm(sigvalue=%x)\n", (int) sigvalue);
3185#endif
3186
3187 tiocm = 0;
3188 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0); 2898 tiocm |= ((sigvalue & SG_DCD) ? TIOCM_CD : 0);
3189 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0); 2899 tiocm |= ((sigvalue & SG_CTS) ? TIOCM_CTS : 0);
3190 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0); 2900 tiocm |= ((sigvalue & SG_RI) ? TIOCM_RI : 0);
@@ -3206,10 +2916,6 @@ static int stli_initports(stlibrd_t *brdp)
3206 stliport_t *portp; 2916 stliport_t *portp;
3207 int i, panelnr, panelport; 2917 int i, panelnr, panelport;
3208 2918
3209#ifdef DEBUG
3210 printk(KERN_DEBUG "stli_initports(brdp=%x)\n", (int) brdp);
3211#endif
3212
3213 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) { 2919 for (i = 0, panelnr = 0, panelport = 0; (i < brdp->nrports); i++) {
3214 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL); 2920 portp = kzalloc(sizeof(stliport_t), GFP_KERNEL);
3215 if (!portp) { 2921 if (!portp) {
@@ -3236,7 +2942,7 @@ static int stli_initports(stlibrd_t *brdp)
3236 brdp->ports[i] = portp; 2942 brdp->ports[i] = portp;
3237 } 2943 }
3238 2944
3239 return(0); 2945 return 0;
3240} 2946}
3241 2947
3242/*****************************************************************************/ 2948/*****************************************************************************/
@@ -3249,10 +2955,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
3249{ 2955{
3250 unsigned long memconf; 2956 unsigned long memconf;
3251 2957
3252#ifdef DEBUG
3253 printk(KERN_DEBUG "stli_ecpinit(brdp=%d)\n", (int) brdp);
3254#endif
3255
3256 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 2958 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3257 udelay(10); 2959 udelay(10);
3258 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2960 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3266,9 +2968,6 @@ static void stli_ecpinit(stlibrd_t *brdp)
3266 2968
3267static void stli_ecpenable(stlibrd_t *brdp) 2969static void stli_ecpenable(stlibrd_t *brdp)
3268{ 2970{
3269#ifdef DEBUG
3270 printk(KERN_DEBUG "stli_ecpenable(brdp=%x)\n", (int) brdp);
3271#endif
3272 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR)); 2971 outb(ECP_ATENABLE, (brdp->iobase + ECP_ATCONFR));
3273} 2972}
3274 2973
@@ -3276,9 +2975,6 @@ static void stli_ecpenable(stlibrd_t *brdp)
3276 2975
3277static void stli_ecpdisable(stlibrd_t *brdp) 2976static void stli_ecpdisable(stlibrd_t *brdp)
3278{ 2977{
3279#ifdef DEBUG
3280 printk(KERN_DEBUG "stli_ecpdisable(brdp=%x)\n", (int) brdp);
3281#endif
3282 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 2978 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
3283} 2979}
3284 2980
@@ -3286,13 +2982,8 @@ static void stli_ecpdisable(stlibrd_t *brdp)
3286 2982
3287static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 2983static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3288{ 2984{
3289 void *ptr; 2985 void *ptr;
3290 unsigned char val; 2986 unsigned char val;
3291
3292#ifdef DEBUG
3293 printk(KERN_DEBUG "stli_ecpgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3294 (int) offset);
3295#endif
3296 2987
3297 if (offset > brdp->memsize) { 2988 if (offset > brdp->memsize) {
3298 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 2989 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3312,10 +3003,6 @@ static char *stli_ecpgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3312 3003
3313static void stli_ecpreset(stlibrd_t *brdp) 3004static void stli_ecpreset(stlibrd_t *brdp)
3314{ 3005{
3315#ifdef DEBUG
3316 printk(KERN_DEBUG "stli_ecpreset(brdp=%x)\n", (int) brdp);
3317#endif
3318
3319 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR)); 3006 outb(ECP_ATSTOP, (brdp->iobase + ECP_ATCONFR));
3320 udelay(10); 3007 udelay(10);
3321 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR)); 3008 outb(ECP_ATDISABLE, (brdp->iobase + ECP_ATCONFR));
@@ -3326,9 +3013,6 @@ static void stli_ecpreset(stlibrd_t *brdp)
3326 3013
3327static void stli_ecpintr(stlibrd_t *brdp) 3014static void stli_ecpintr(stlibrd_t *brdp)
3328{ 3015{
3329#ifdef DEBUG
3330 printk(KERN_DEBUG "stli_ecpintr(brdp=%x)\n", (int) brdp);
3331#endif
3332 outb(0x1, brdp->iobase); 3016 outb(0x1, brdp->iobase);
3333} 3017}
3334 3018
@@ -3342,10 +3026,6 @@ static void stli_ecpeiinit(stlibrd_t *brdp)
3342{ 3026{
3343 unsigned long memconf; 3027 unsigned long memconf;
3344 3028
3345#ifdef DEBUG
3346 printk(KERN_DEBUG "stli_ecpeiinit(brdp=%x)\n", (int) brdp);
3347#endif
3348
3349 outb(0x1, (brdp->iobase + ECP_EIBRDENAB)); 3029 outb(0x1, (brdp->iobase + ECP_EIBRDENAB));
3350 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR)); 3030 outb(ECP_EISTOP, (brdp->iobase + ECP_EICONFR));
3351 udelay(10); 3031 udelay(10);
@@ -3379,11 +3059,6 @@ static char *stli_ecpeigetmemptr(stlibrd_t *brdp, unsigned long offset, int line
3379 void *ptr; 3059 void *ptr;
3380 unsigned char val; 3060 unsigned char val;
3381 3061
3382#ifdef DEBUG
3383 printk(KERN_DEBUG "stli_ecpeigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3384 (int) brdp, (int) offset, line);
3385#endif
3386
3387 if (offset > brdp->memsize) { 3062 if (offset > brdp->memsize) {
3388 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3063 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3389 "range at line=%d(%d), brd=%d\n", 3064 "range at line=%d(%d), brd=%d\n",
@@ -3433,8 +3108,8 @@ static void stli_ecpmcdisable(stlibrd_t *brdp)
3433 3108
3434static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3109static char *stli_ecpmcgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3435{ 3110{
3436 void *ptr; 3111 void *ptr;
3437 unsigned char val; 3112 unsigned char val;
3438 3113
3439 if (offset > brdp->memsize) { 3114 if (offset > brdp->memsize) {
3440 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3115 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3468,10 +3143,6 @@ static void stli_ecpmcreset(stlibrd_t *brdp)
3468 3143
3469static void stli_ecppciinit(stlibrd_t *brdp) 3144static void stli_ecppciinit(stlibrd_t *brdp)
3470{ 3145{
3471#ifdef DEBUG
3472 printk(KERN_DEBUG "stli_ecppciinit(brdp=%x)\n", (int) brdp);
3473#endif
3474
3475 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR)); 3146 outb(ECP_PCISTOP, (brdp->iobase + ECP_PCICONFR));
3476 udelay(10); 3147 udelay(10);
3477 outb(0, (brdp->iobase + ECP_PCICONFR)); 3148 outb(0, (brdp->iobase + ECP_PCICONFR));
@@ -3485,11 +3156,6 @@ static char *stli_ecppcigetmemptr(stlibrd_t *brdp, unsigned long offset, int lin
3485 void *ptr; 3156 void *ptr;
3486 unsigned char val; 3157 unsigned char val;
3487 3158
3488#ifdef DEBUG
3489 printk(KERN_DEBUG "stli_ecppcigetmemptr(brdp=%x,offset=%x,line=%d)\n",
3490 (int) brdp, (int) offset, line);
3491#endif
3492
3493 if (offset > brdp->memsize) { 3159 if (offset > brdp->memsize) {
3494 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3160 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3495 "range at line=%d(%d), board=%d\n", 3161 "range at line=%d(%d), board=%d\n",
@@ -3524,10 +3190,6 @@ static void stli_onbinit(stlibrd_t *brdp)
3524{ 3190{
3525 unsigned long memconf; 3191 unsigned long memconf;
3526 3192
3527#ifdef DEBUG
3528 printk(KERN_DEBUG "stli_onbinit(brdp=%d)\n", (int) brdp);
3529#endif
3530
3531 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3193 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3532 udelay(10); 3194 udelay(10);
3533 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); 3195 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3543,9 +3205,6 @@ static void stli_onbinit(stlibrd_t *brdp)
3543 3205
3544static void stli_onbenable(stlibrd_t *brdp) 3206static void stli_onbenable(stlibrd_t *brdp)
3545{ 3207{
3546#ifdef DEBUG
3547 printk(KERN_DEBUG "stli_onbenable(brdp=%x)\n", (int) brdp);
3548#endif
3549 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR)); 3208 outb((brdp->enabval | ONB_ATENABLE), (brdp->iobase + ONB_ATCONFR));
3550} 3209}
3551 3210
@@ -3553,9 +3212,6 @@ static void stli_onbenable(stlibrd_t *brdp)
3553 3212
3554static void stli_onbdisable(stlibrd_t *brdp) 3213static void stli_onbdisable(stlibrd_t *brdp)
3555{ 3214{
3556#ifdef DEBUG
3557 printk(KERN_DEBUG "stli_onbdisable(brdp=%x)\n", (int) brdp);
3558#endif
3559 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR)); 3215 outb((brdp->enabval | ONB_ATDISABLE), (brdp->iobase + ONB_ATCONFR));
3560} 3216}
3561 3217
@@ -3565,11 +3221,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3565{ 3221{
3566 void *ptr; 3222 void *ptr;
3567 3223
3568#ifdef DEBUG
3569 printk(KERN_DEBUG "stli_onbgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3570 (int) offset);
3571#endif
3572
3573 if (offset > brdp->memsize) { 3224 if (offset > brdp->memsize) {
3574 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3225 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3575 "range at line=%d(%d), brd=%d\n", 3226 "range at line=%d(%d), brd=%d\n",
@@ -3585,11 +3236,6 @@ static char *stli_onbgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3585 3236
3586static void stli_onbreset(stlibrd_t *brdp) 3237static void stli_onbreset(stlibrd_t *brdp)
3587{ 3238{
3588
3589#ifdef DEBUG
3590 printk(KERN_DEBUG "stli_onbreset(brdp=%x)\n", (int) brdp);
3591#endif
3592
3593 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR)); 3239 outb(ONB_ATSTOP, (brdp->iobase + ONB_ATCONFR));
3594 udelay(10); 3240 udelay(10);
3595 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR)); 3241 outb(ONB_ATDISABLE, (brdp->iobase + ONB_ATCONFR));
@@ -3606,10 +3252,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
3606{ 3252{
3607 unsigned long memconf; 3253 unsigned long memconf;
3608 3254
3609#ifdef DEBUG
3610 printk(KERN_DEBUG "stli_onbeinit(brdp=%d)\n", (int) brdp);
3611#endif
3612
3613 outb(0x1, (brdp->iobase + ONB_EIBRDENAB)); 3255 outb(0x1, (brdp->iobase + ONB_EIBRDENAB));
3614 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3256 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3615 udelay(10); 3257 udelay(10);
@@ -3628,9 +3270,6 @@ static void stli_onbeinit(stlibrd_t *brdp)
3628 3270
3629static void stli_onbeenable(stlibrd_t *brdp) 3271static void stli_onbeenable(stlibrd_t *brdp)
3630{ 3272{
3631#ifdef DEBUG
3632 printk(KERN_DEBUG "stli_onbeenable(brdp=%x)\n", (int) brdp);
3633#endif
3634 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR)); 3273 outb(ONB_EIENABLE, (brdp->iobase + ONB_EICONFR));
3635} 3274}
3636 3275
@@ -3638,9 +3277,6 @@ static void stli_onbeenable(stlibrd_t *brdp)
3638 3277
3639static void stli_onbedisable(stlibrd_t *brdp) 3278static void stli_onbedisable(stlibrd_t *brdp)
3640{ 3279{
3641#ifdef DEBUG
3642 printk(KERN_DEBUG "stli_onbedisable(brdp=%x)\n", (int) brdp);
3643#endif
3644 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3280 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
3645} 3281}
3646 3282
@@ -3648,13 +3284,8 @@ static void stli_onbedisable(stlibrd_t *brdp)
3648 3284
3649static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3285static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3650{ 3286{
3651 void *ptr; 3287 void *ptr;
3652 unsigned char val; 3288 unsigned char val;
3653
3654#ifdef DEBUG
3655 printk(KERN_DEBUG "stli_onbegetmemptr(brdp=%x,offset=%x,line=%d)\n",
3656 (int) brdp, (int) offset, line);
3657#endif
3658 3289
3659 if (offset > brdp->memsize) { 3290 if (offset > brdp->memsize) {
3660 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3291 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
@@ -3677,11 +3308,6 @@ static char *stli_onbegetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3677 3308
3678static void stli_onbereset(stlibrd_t *brdp) 3309static void stli_onbereset(stlibrd_t *brdp)
3679{ 3310{
3680
3681#ifdef DEBUG
3682 printk(KERN_ERR "stli_onbereset(brdp=%x)\n", (int) brdp);
3683#endif
3684
3685 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR)); 3311 outb(ONB_EISTOP, (brdp->iobase + ONB_EICONFR));
3686 udelay(10); 3312 udelay(10);
3687 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR)); 3313 outb(ONB_EIDISABLE, (brdp->iobase + ONB_EICONFR));
@@ -3696,11 +3322,6 @@ static void stli_onbereset(stlibrd_t *brdp)
3696 3322
3697static void stli_bbyinit(stlibrd_t *brdp) 3323static void stli_bbyinit(stlibrd_t *brdp)
3698{ 3324{
3699
3700#ifdef DEBUG
3701 printk(KERN_ERR "stli_bbyinit(brdp=%d)\n", (int) brdp);
3702#endif
3703
3704 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3325 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3705 udelay(10); 3326 udelay(10);
3706 outb(0, (brdp->iobase + BBY_ATCONFR)); 3327 outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3713,24 +3334,13 @@ static void stli_bbyinit(stlibrd_t *brdp)
3713 3334
3714static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3335static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3715{ 3336{
3716 void *ptr; 3337 void *ptr;
3717 unsigned char val; 3338 unsigned char val;
3718 3339
3719#ifdef DEBUG 3340 BUG_ON(offset > brdp->memsize);
3720 printk(KERN_ERR "stli_bbygetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3721 (int) offset);
3722#endif
3723 3341
3724 if (offset > brdp->memsize) { 3342 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3725 printk(KERN_ERR "STALLION: shared memory pointer=%x out of " 3343 val = (unsigned char) (offset / BBY_PAGESIZE);
3726 "range at line=%d(%d), brd=%d\n",
3727 (int) offset, line, __LINE__, brdp->brdnr);
3728 ptr = NULL;
3729 val = 0;
3730 } else {
3731 ptr = brdp->membase + (offset % BBY_PAGESIZE);
3732 val = (unsigned char) (offset / BBY_PAGESIZE);
3733 }
3734 outb(val, (brdp->iobase + BBY_ATCONFR)); 3344 outb(val, (brdp->iobase + BBY_ATCONFR));
3735 return(ptr); 3345 return(ptr);
3736} 3346}
@@ -3739,11 +3349,6 @@ static char *stli_bbygetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3739 3349
3740static void stli_bbyreset(stlibrd_t *brdp) 3350static void stli_bbyreset(stlibrd_t *brdp)
3741{ 3351{
3742
3743#ifdef DEBUG
3744 printk(KERN_DEBUG "stli_bbyreset(brdp=%x)\n", (int) brdp);
3745#endif
3746
3747 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR)); 3352 outb(BBY_ATSTOP, (brdp->iobase + BBY_ATCONFR));
3748 udelay(10); 3353 udelay(10);
3749 outb(0, (brdp->iobase + BBY_ATCONFR)); 3354 outb(0, (brdp->iobase + BBY_ATCONFR));
@@ -3758,11 +3363,6 @@ static void stli_bbyreset(stlibrd_t *brdp)
3758 3363
3759static void stli_stalinit(stlibrd_t *brdp) 3364static void stli_stalinit(stlibrd_t *brdp)
3760{ 3365{
3761
3762#ifdef DEBUG
3763 printk(KERN_DEBUG "stli_stalinit(brdp=%d)\n", (int) brdp);
3764#endif
3765
3766 outb(0x1, brdp->iobase); 3366 outb(0x1, brdp->iobase);
3767 mdelay(1000); 3367 mdelay(1000);
3768} 3368}
@@ -3771,36 +3371,18 @@ static void stli_stalinit(stlibrd_t *brdp)
3771 3371
3772static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line) 3372static char *stli_stalgetmemptr(stlibrd_t *brdp, unsigned long offset, int line)
3773{ 3373{
3774 void *ptr; 3374 BUG_ON(offset > brdp->memsize);
3775 3375 return brdp->membase + (offset % STAL_PAGESIZE);
3776#ifdef DEBUG
3777 printk(KERN_DEBUG "stli_stalgetmemptr(brdp=%x,offset=%x)\n", (int) brdp,
3778 (int) offset);
3779#endif
3780
3781 if (offset > brdp->memsize) {
3782 printk(KERN_ERR "STALLION: shared memory pointer=%x out of "
3783 "range at line=%d(%d), brd=%d\n",
3784 (int) offset, line, __LINE__, brdp->brdnr);
3785 ptr = NULL;
3786 } else {
3787 ptr = brdp->membase + (offset % STAL_PAGESIZE);
3788 }
3789 return(ptr);
3790} 3376}
3791 3377
3792/*****************************************************************************/ 3378/*****************************************************************************/
3793 3379
3794static void stli_stalreset(stlibrd_t *brdp) 3380static void stli_stalreset(stlibrd_t *brdp)
3795{ 3381{
3796 volatile unsigned long *vecp; 3382 u32 __iomem *vecp;
3797
3798#ifdef DEBUG
3799 printk(KERN_DEBUG "stli_stalreset(brdp=%x)\n", (int) brdp);
3800#endif
3801 3383
3802 vecp = (volatile unsigned long *) (brdp->membase + 0x30); 3384 vecp = (u32 __iomem *) (brdp->membase + 0x30);
3803 *vecp = 0xffff0000; 3385 writel(0xffff0000, vecp);
3804 outb(0, brdp->iobase); 3386 outb(0, brdp->iobase);
3805 mdelay(1000); 3387 mdelay(1000);
3806} 3388}
@@ -3814,15 +3396,11 @@ static void stli_stalreset(stlibrd_t *brdp)
3814 3396
3815static int stli_initecp(stlibrd_t *brdp) 3397static int stli_initecp(stlibrd_t *brdp)
3816{ 3398{
3817 cdkecpsig_t sig; 3399 cdkecpsig_t sig;
3818 cdkecpsig_t *sigsp; 3400 cdkecpsig_t __iomem *sigsp;
3819 unsigned int status, nxtid; 3401 unsigned int status, nxtid;
3820 char *name; 3402 char *name;
3821 int panelnr, nrports; 3403 int panelnr, nrports;
3822
3823#ifdef DEBUG
3824 printk(KERN_DEBUG "stli_initecp(brdp=%x)\n", (int) brdp);
3825#endif
3826 3404
3827 if (!request_region(brdp->iobase, brdp->iosize, "istallion")) 3405 if (!request_region(brdp->iobase, brdp->iosize, "istallion"))
3828 return -EIO; 3406 return -EIO;
@@ -3830,7 +3408,7 @@ static int stli_initecp(stlibrd_t *brdp)
3830 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3408 if ((brdp->iobase == 0) || (brdp->memaddr == 0))
3831 { 3409 {
3832 release_region(brdp->iobase, brdp->iosize); 3410 release_region(brdp->iobase, brdp->iosize);
3833 return(-ENODEV); 3411 return -ENODEV;
3834 } 3412 }
3835 3413
3836 brdp->iosize = ECP_IOSIZE; 3414 brdp->iosize = ECP_IOSIZE;
@@ -3899,7 +3477,7 @@ static int stli_initecp(stlibrd_t *brdp)
3899 3477
3900 default: 3478 default:
3901 release_region(brdp->iobase, brdp->iosize); 3479 release_region(brdp->iobase, brdp->iosize);
3902 return(-EINVAL); 3480 return -EINVAL;
3903 } 3481 }
3904 3482
3905/* 3483/*
@@ -3911,10 +3489,10 @@ static int stli_initecp(stlibrd_t *brdp)
3911 EBRDINIT(brdp); 3489 EBRDINIT(brdp);
3912 3490
3913 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3491 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
3914 if (brdp->membase == (void *) NULL) 3492 if (brdp->membase == NULL)
3915 { 3493 {
3916 release_region(brdp->iobase, brdp->iosize); 3494 release_region(brdp->iobase, brdp->iosize);
3917 return(-ENOMEM); 3495 return -ENOMEM;
3918 } 3496 }
3919 3497
3920/* 3498/*
@@ -3923,23 +3501,14 @@ static int stli_initecp(stlibrd_t *brdp)
3923 * this is, and what it is connected to it. 3501 * this is, and what it is connected to it.
3924 */ 3502 */
3925 EBRDENABLE(brdp); 3503 EBRDENABLE(brdp);
3926 sigsp = (cdkecpsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); 3504 sigsp = (cdkecpsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
3927 memcpy(&sig, sigsp, sizeof(cdkecpsig_t)); 3505 memcpy(&sig, sigsp, sizeof(cdkecpsig_t));
3928 EBRDDISABLE(brdp); 3506 EBRDDISABLE(brdp);
3929 3507
3930#if 0 3508 if (sig.magic != cpu_to_le32(ECP_MAGIC))
3931 printk("%s(%d): sig-> magic=%x rom=%x panel=%x,%x,%x,%x,%x,%x,%x,%x\n",
3932 __FILE__, __LINE__, (int) sig.magic, sig.romver, sig.panelid[0],
3933 (int) sig.panelid[1], (int) sig.panelid[2],
3934 (int) sig.panelid[3], (int) sig.panelid[4],
3935 (int) sig.panelid[5], (int) sig.panelid[6],
3936 (int) sig.panelid[7]);
3937#endif
3938
3939 if (sig.magic != ECP_MAGIC)
3940 { 3509 {
3941 release_region(brdp->iobase, brdp->iosize); 3510 release_region(brdp->iobase, brdp->iosize);
3942 return(-ENODEV); 3511 return -ENODEV;
3943 } 3512 }
3944 3513
3945/* 3514/*
@@ -3963,7 +3532,7 @@ static int stli_initecp(stlibrd_t *brdp)
3963 3532
3964 3533
3965 brdp->state |= BST_FOUND; 3534 brdp->state |= BST_FOUND;
3966 return(0); 3535 return 0;
3967} 3536}
3968 3537
3969/*****************************************************************************/ 3538/*****************************************************************************/
@@ -3975,20 +3544,16 @@ static int stli_initecp(stlibrd_t *brdp)
3975 3544
3976static int stli_initonb(stlibrd_t *brdp) 3545static int stli_initonb(stlibrd_t *brdp)
3977{ 3546{
3978 cdkonbsig_t sig; 3547 cdkonbsig_t sig;
3979 cdkonbsig_t *sigsp; 3548 cdkonbsig_t __iomem *sigsp;
3980 char *name; 3549 char *name;
3981 int i; 3550 int i;
3982
3983#ifdef DEBUG
3984 printk(KERN_DEBUG "stli_initonb(brdp=%x)\n", (int) brdp);
3985#endif
3986 3551
3987/* 3552/*
3988 * Do a basic sanity check on the IO and memory addresses. 3553 * Do a basic sanity check on the IO and memory addresses.
3989 */ 3554 */
3990 if ((brdp->iobase == 0) || (brdp->memaddr == 0)) 3555 if (brdp->iobase == 0 || brdp->memaddr == 0)
3991 return(-ENODEV); 3556 return -ENODEV;
3992 3557
3993 brdp->iosize = ONB_IOSIZE; 3558 brdp->iosize = ONB_IOSIZE;
3994 3559
@@ -4006,7 +3571,6 @@ static int stli_initonb(stlibrd_t *brdp)
4006 case BRD_ONBOARD2: 3571 case BRD_ONBOARD2:
4007 case BRD_ONBOARD2_32: 3572 case BRD_ONBOARD2_32:
4008 case BRD_ONBOARDRS: 3573 case BRD_ONBOARDRS:
4009 brdp->membase = (void *) brdp->memaddr;
4010 brdp->memsize = ONB_MEMSIZE; 3574 brdp->memsize = ONB_MEMSIZE;
4011 brdp->pagesize = ONB_ATPAGESIZE; 3575 brdp->pagesize = ONB_ATPAGESIZE;
4012 brdp->init = stli_onbinit; 3576 brdp->init = stli_onbinit;
@@ -4024,7 +3588,6 @@ static int stli_initonb(stlibrd_t *brdp)
4024 break; 3588 break;
4025 3589
4026 case BRD_ONBOARDE: 3590 case BRD_ONBOARDE:
4027 brdp->membase = (void *) brdp->memaddr;
4028 brdp->memsize = ONB_EIMEMSIZE; 3591 brdp->memsize = ONB_EIMEMSIZE;
4029 brdp->pagesize = ONB_EIPAGESIZE; 3592 brdp->pagesize = ONB_EIPAGESIZE;
4030 brdp->init = stli_onbeinit; 3593 brdp->init = stli_onbeinit;
@@ -4040,7 +3603,6 @@ static int stli_initonb(stlibrd_t *brdp)
4040 case BRD_BRUMBY4: 3603 case BRD_BRUMBY4:
4041 case BRD_BRUMBY8: 3604 case BRD_BRUMBY8:
4042 case BRD_BRUMBY16: 3605 case BRD_BRUMBY16:
4043 brdp->membase = (void *) brdp->memaddr;
4044 brdp->memsize = BBY_MEMSIZE; 3606 brdp->memsize = BBY_MEMSIZE;
4045 brdp->pagesize = BBY_PAGESIZE; 3607 brdp->pagesize = BBY_PAGESIZE;
4046 brdp->init = stli_bbyinit; 3608 brdp->init = stli_bbyinit;
@@ -4054,7 +3616,6 @@ static int stli_initonb(stlibrd_t *brdp)
4054 break; 3616 break;
4055 3617
4056 case BRD_STALLION: 3618 case BRD_STALLION:
4057 brdp->membase = (void *) brdp->memaddr;
4058 brdp->memsize = STAL_MEMSIZE; 3619 brdp->memsize = STAL_MEMSIZE;
4059 brdp->pagesize = STAL_PAGESIZE; 3620 brdp->pagesize = STAL_PAGESIZE;
4060 brdp->init = stli_stalinit; 3621 brdp->init = stli_stalinit;
@@ -4069,7 +3630,7 @@ static int stli_initonb(stlibrd_t *brdp)
4069 3630
4070 default: 3631 default:
4071 release_region(brdp->iobase, brdp->iosize); 3632 release_region(brdp->iobase, brdp->iosize);
4072 return(-EINVAL); 3633 return -EINVAL;
4073 } 3634 }
4074 3635
4075/* 3636/*
@@ -4081,10 +3642,10 @@ static int stli_initonb(stlibrd_t *brdp)
4081 EBRDINIT(brdp); 3642 EBRDINIT(brdp);
4082 3643
4083 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3644 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4084 if (brdp->membase == (void *) NULL) 3645 if (brdp->membase == NULL)
4085 { 3646 {
4086 release_region(brdp->iobase, brdp->iosize); 3647 release_region(brdp->iobase, brdp->iosize);
4087 return(-ENOMEM); 3648 return -ENOMEM;
4088 } 3649 }
4089 3650
4090/* 3651/*
@@ -4093,21 +3654,17 @@ static int stli_initonb(stlibrd_t *brdp)
4093 * this is, and how many ports. 3654 * this is, and how many ports.
4094 */ 3655 */
4095 EBRDENABLE(brdp); 3656 EBRDENABLE(brdp);
4096 sigsp = (cdkonbsig_t *) EBRDGETMEMPTR(brdp, CDK_SIGADDR); 3657 sigsp = (cdkonbsig_t __iomem *) EBRDGETMEMPTR(brdp, CDK_SIGADDR);
4097 memcpy(&sig, sigsp, sizeof(cdkonbsig_t)); 3658 memcpy_fromio(&sig, sigsp, sizeof(cdkonbsig_t));
4098 EBRDDISABLE(brdp); 3659 EBRDDISABLE(brdp);
4099 3660
4100#if 0 3661 if (sig.magic0 != cpu_to_le16(ONB_MAGIC0) ||
4101 printk("%s(%d): sig-> magic=%x:%x:%x:%x romver=%x amask=%x:%x:%x\n", 3662 sig.magic1 != cpu_to_le16(ONB_MAGIC1) ||
4102 __FILE__, __LINE__, sig.magic0, sig.magic1, sig.magic2, 3663 sig.magic2 != cpu_to_le16(ONB_MAGIC2) ||
4103 sig.magic3, sig.romver, sig.amask0, sig.amask1, sig.amask2); 3664 sig.magic3 != cpu_to_le16(ONB_MAGIC3))
4104#endif
4105
4106 if ((sig.magic0 != ONB_MAGIC0) || (sig.magic1 != ONB_MAGIC1) ||
4107 (sig.magic2 != ONB_MAGIC2) || (sig.magic3 != ONB_MAGIC3))
4108 { 3665 {
4109 release_region(brdp->iobase, brdp->iosize); 3666 release_region(brdp->iobase, brdp->iosize);
4110 return(-ENODEV); 3667 return -ENODEV;
4111 } 3668 }
4112 3669
4113/* 3670/*
@@ -4128,7 +3685,7 @@ static int stli_initonb(stlibrd_t *brdp)
4128 3685
4129 3686
4130 brdp->state |= BST_FOUND; 3687 brdp->state |= BST_FOUND;
4131 return(0); 3688 return 0;
4132} 3689}
4133 3690
4134/*****************************************************************************/ 3691/*****************************************************************************/
@@ -4141,31 +3698,25 @@ static int stli_initonb(stlibrd_t *brdp)
4141 3698
4142static int stli_startbrd(stlibrd_t *brdp) 3699static int stli_startbrd(stlibrd_t *brdp)
4143{ 3700{
4144 volatile cdkhdr_t *hdrp; 3701 cdkhdr_t __iomem *hdrp;
4145 volatile cdkmem_t *memp; 3702 cdkmem_t __iomem *memp;
4146 volatile cdkasy_t *ap; 3703 cdkasy_t __iomem *ap;
4147 unsigned long flags; 3704 unsigned long flags;
4148 stliport_t *portp; 3705 stliport_t *portp;
4149 int portnr, nrdevs, i, rc; 3706 int portnr, nrdevs, i, rc = 0;
4150 3707 u32 memoff;
4151#ifdef DEBUG 3708
4152 printk(KERN_DEBUG "stli_startbrd(brdp=%x)\n", (int) brdp); 3709 spin_lock_irqsave(&brd_lock, flags);
4153#endif
4154
4155 rc = 0;
4156
4157 save_flags(flags);
4158 cli();
4159 EBRDENABLE(brdp); 3710 EBRDENABLE(brdp);
4160 hdrp = (volatile cdkhdr_t *) EBRDGETMEMPTR(brdp, CDK_CDKADDR); 3711 hdrp = (cdkhdr_t __iomem *) EBRDGETMEMPTR(brdp, CDK_CDKADDR);
4161 nrdevs = hdrp->nrdevs; 3712 nrdevs = hdrp->nrdevs;
4162 3713
4163#if 0 3714#if 0
4164 printk("%s(%d): CDK version %d.%d.%d --> " 3715 printk("%s(%d): CDK version %d.%d.%d --> "
4165 "nrdevs=%d memp=%x hostp=%x slavep=%x\n", 3716 "nrdevs=%d memp=%x hostp=%x slavep=%x\n",
4166 __FILE__, __LINE__, hdrp->ver_release, hdrp->ver_modification, 3717 __FILE__, __LINE__, readb(&hdrp->ver_release), readb(&hdrp->ver_modification),
4167 hdrp->ver_fix, nrdevs, (int) hdrp->memp, (int) hdrp->hostp, 3718 readb(&hdrp->ver_fix), nrdevs, (int) readl(&hdrp->memp), readl(&hdrp->hostp),
4168 (int) hdrp->slavep); 3719 readl(&hdrp->slavep));
4169#endif 3720#endif
4170 3721
4171 if (nrdevs < (brdp->nrports + 1)) { 3722 if (nrdevs < (brdp->nrports + 1)) {
@@ -4177,14 +3728,14 @@ static int stli_startbrd(stlibrd_t *brdp)
4177 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR; 3728 brdp->hostoffset = hdrp->hostp - CDK_CDKADDR;
4178 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR; 3729 brdp->slaveoffset = hdrp->slavep - CDK_CDKADDR;
4179 brdp->bitsize = (nrdevs + 7) / 8; 3730 brdp->bitsize = (nrdevs + 7) / 8;
4180 memp = (volatile cdkmem_t *) hdrp->memp; 3731 memoff = readl(&hdrp->memp);
4181 if (((unsigned long) memp) > brdp->memsize) { 3732 if (memoff > brdp->memsize) {
4182 printk(KERN_ERR "STALLION: corrupted shared memory region?\n"); 3733 printk(KERN_ERR "STALLION: corrupted shared memory region?\n");
4183 rc = -EIO; 3734 rc = -EIO;
4184 goto stli_donestartup; 3735 goto stli_donestartup;
4185 } 3736 }
4186 memp = (volatile cdkmem_t *) EBRDGETMEMPTR(brdp, (unsigned long) memp); 3737 memp = (cdkmem_t __iomem *) EBRDGETMEMPTR(brdp, memoff);
4187 if (memp->dtype != TYP_ASYNCTRL) { 3738 if (readw(&memp->dtype) != TYP_ASYNCTRL) {
4188 printk(KERN_ERR "STALLION: no slave control device found\n"); 3739 printk(KERN_ERR "STALLION: no slave control device found\n");
4189 goto stli_donestartup; 3740 goto stli_donestartup;
4190 } 3741 }
@@ -4196,19 +3747,19 @@ static int stli_startbrd(stlibrd_t *brdp)
4196 * change pages while reading memory map. 3747 * change pages while reading memory map.
4197 */ 3748 */
4198 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) { 3749 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++, memp++) {
4199 if (memp->dtype != TYP_ASYNC) 3750 if (readw(&memp->dtype) != TYP_ASYNC)
4200 break; 3751 break;
4201 portp = brdp->ports[portnr]; 3752 portp = brdp->ports[portnr];
4202 if (portp == (stliport_t *) NULL) 3753 if (portp == NULL)
4203 break; 3754 break;
4204 portp->devnr = i; 3755 portp->devnr = i;
4205 portp->addr = memp->offset; 3756 portp->addr = readl(&memp->offset);
4206 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs)); 3757 portp->reqbit = (unsigned char) (0x1 << (i * 8 / nrdevs));
4207 portp->portidx = (unsigned char) (i / 8); 3758 portp->portidx = (unsigned char) (i / 8);
4208 portp->portbit = (unsigned char) (0x1 << (i % 8)); 3759 portp->portbit = (unsigned char) (0x1 << (i % 8));
4209 } 3760 }
4210 3761
4211 hdrp->slavereq = 0xff; 3762 writeb(0xff, &hdrp->slavereq);
4212 3763
4213/* 3764/*
4214 * For each port setup a local copy of the RX and TX buffer offsets 3765 * For each port setup a local copy of the RX and TX buffer offsets
@@ -4217,22 +3768,22 @@ static int stli_startbrd(stlibrd_t *brdp)
4217 */ 3768 */
4218 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) { 3769 for (i = 1, portnr = 0; (i < nrdevs); i++, portnr++) {
4219 portp = brdp->ports[portnr]; 3770 portp = brdp->ports[portnr];
4220 if (portp == (stliport_t *) NULL) 3771 if (portp == NULL)
4221 break; 3772 break;
4222 if (portp->addr == 0) 3773 if (portp->addr == 0)
4223 break; 3774 break;
4224 ap = (volatile cdkasy_t *) EBRDGETMEMPTR(brdp, portp->addr); 3775 ap = (cdkasy_t __iomem *) EBRDGETMEMPTR(brdp, portp->addr);
4225 if (ap != (volatile cdkasy_t *) NULL) { 3776 if (ap != NULL) {
4226 portp->rxsize = ap->rxq.size; 3777 portp->rxsize = readw(&ap->rxq.size);
4227 portp->txsize = ap->txq.size; 3778 portp->txsize = readw(&ap->txq.size);
4228 portp->rxoffset = ap->rxq.offset; 3779 portp->rxoffset = readl(&ap->rxq.offset);
4229 portp->txoffset = ap->txq.offset; 3780 portp->txoffset = readl(&ap->txq.offset);
4230 } 3781 }
4231 } 3782 }
4232 3783
4233stli_donestartup: 3784stli_donestartup:
4234 EBRDDISABLE(brdp); 3785 EBRDDISABLE(brdp);
4235 restore_flags(flags); 3786 spin_unlock_irqrestore(&brd_lock, flags);
4236 3787
4237 if (rc == 0) 3788 if (rc == 0)
4238 brdp->state |= BST_STARTED; 3789 brdp->state |= BST_STARTED;
@@ -4243,7 +3794,7 @@ stli_donestartup:
4243 add_timer(&stli_timerlist); 3794 add_timer(&stli_timerlist);
4244 } 3795 }
4245 3796
4246 return(rc); 3797 return rc;
4247} 3798}
4248 3799
4249/*****************************************************************************/ 3800/*****************************************************************************/
@@ -4254,10 +3805,6 @@ stli_donestartup:
4254 3805
4255static int __init stli_brdinit(stlibrd_t *brdp) 3806static int __init stli_brdinit(stlibrd_t *brdp)
4256{ 3807{
4257#ifdef DEBUG
4258 printk(KERN_DEBUG "stli_brdinit(brdp=%x)\n", (int) brdp);
4259#endif
4260
4261 stli_brds[brdp->brdnr] = brdp; 3808 stli_brds[brdp->brdnr] = brdp;
4262 3809
4263 switch (brdp->brdtype) { 3810 switch (brdp->brdtype) {
@@ -4285,11 +3832,11 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4285 case BRD_ECHPCI: 3832 case BRD_ECHPCI:
4286 printk(KERN_ERR "STALLION: %s board type not supported in " 3833 printk(KERN_ERR "STALLION: %s board type not supported in "
4287 "this driver\n", stli_brdnames[brdp->brdtype]); 3834 "this driver\n", stli_brdnames[brdp->brdtype]);
4288 return(ENODEV); 3835 return -ENODEV;
4289 default: 3836 default:
4290 printk(KERN_ERR "STALLION: board=%d is unknown board " 3837 printk(KERN_ERR "STALLION: board=%d is unknown board "
4291 "type=%d\n", brdp->brdnr, brdp->brdtype); 3838 "type=%d\n", brdp->brdnr, brdp->brdtype);
4292 return(ENODEV); 3839 return -ENODEV;
4293 } 3840 }
4294 3841
4295 if ((brdp->state & BST_FOUND) == 0) { 3842 if ((brdp->state & BST_FOUND) == 0) {
@@ -4297,7 +3844,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4297 "io=%x mem=%x\n", 3844 "io=%x mem=%x\n",
4298 stli_brdnames[brdp->brdtype], brdp->brdnr, 3845 stli_brdnames[brdp->brdtype], brdp->brdnr,
4299 brdp->iobase, (int) brdp->memaddr); 3846 brdp->iobase, (int) brdp->memaddr);
4300 return(ENODEV); 3847 return -ENODEV;
4301 } 3848 }
4302 3849
4303 stli_initports(brdp); 3850 stli_initports(brdp);
@@ -4305,7 +3852,7 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4305 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype], 3852 "nrpanels=%d nrports=%d\n", stli_brdnames[brdp->brdtype],
4306 brdp->brdnr, brdp->iobase, (int) brdp->memaddr, 3853 brdp->brdnr, brdp->iobase, (int) brdp->memaddr,
4307 brdp->nrpanels, brdp->nrports); 3854 brdp->nrpanels, brdp->nrports);
4308 return(0); 3855 return 0;
4309} 3856}
4310 3857
4311/*****************************************************************************/ 3858/*****************************************************************************/
@@ -4317,14 +3864,10 @@ static int __init stli_brdinit(stlibrd_t *brdp)
4317 3864
4318static int stli_eisamemprobe(stlibrd_t *brdp) 3865static int stli_eisamemprobe(stlibrd_t *brdp)
4319{ 3866{
4320 cdkecpsig_t ecpsig, *ecpsigp; 3867 cdkecpsig_t ecpsig, __iomem *ecpsigp;
4321 cdkonbsig_t onbsig, *onbsigp; 3868 cdkonbsig_t onbsig, __iomem *onbsigp;
4322 int i, foundit; 3869 int i, foundit;
4323 3870
4324#ifdef DEBUG
4325 printk(KERN_DEBUG "stli_eisamemprobe(brdp=%x)\n", (int) brdp);
4326#endif
4327
4328/* 3871/*
4329 * First up we reset the board, to get it into a known state. There 3872 * First up we reset the board, to get it into a known state. There
4330 * is only 2 board types here we need to worry about. Don;t use the 3873 * is only 2 board types here we need to worry about. Don;t use the
@@ -4348,7 +3891,7 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4348 mdelay(1); 3891 mdelay(1);
4349 stli_onbeenable(brdp); 3892 stli_onbeenable(brdp);
4350 } else { 3893 } else {
4351 return(-ENODEV); 3894 return -ENODEV;
4352 } 3895 }
4353 3896
4354 foundit = 0; 3897 foundit = 0;
@@ -4360,25 +3903,24 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4360 */ 3903 */
4361 for (i = 0; (i < stli_eisamempsize); i++) { 3904 for (i = 0; (i < stli_eisamempsize); i++) {
4362 brdp->memaddr = stli_eisamemprobeaddrs[i]; 3905 brdp->memaddr = stli_eisamemprobeaddrs[i];
4363 brdp->membase = (void *) brdp->memaddr;
4364 brdp->membase = ioremap(brdp->memaddr, brdp->memsize); 3906 brdp->membase = ioremap(brdp->memaddr, brdp->memsize);
4365 if (brdp->membase == (void *) NULL) 3907 if (brdp->membase == NULL)
4366 continue; 3908 continue;
4367 3909
4368 if (brdp->brdtype == BRD_ECPE) { 3910 if (brdp->brdtype == BRD_ECPE) {
4369 ecpsigp = (cdkecpsig_t *) stli_ecpeigetmemptr(brdp, 3911 ecpsigp = (cdkecpsig_t __iomem *) stli_ecpeigetmemptr(brdp,
4370 CDK_SIGADDR, __LINE__); 3912 CDK_SIGADDR, __LINE__);
4371 memcpy(&ecpsig, ecpsigp, sizeof(cdkecpsig_t)); 3913 memcpy_fromio(&ecpsig, ecpsigp, sizeof(cdkecpsig_t));
4372 if (ecpsig.magic == ECP_MAGIC) 3914 if (ecpsig.magic == cpu_to_le32(ECP_MAGIC))
4373 foundit = 1; 3915 foundit = 1;
4374 } else { 3916 } else {
4375 onbsigp = (cdkonbsig_t *) stli_onbegetmemptr(brdp, 3917 onbsigp = (cdkonbsig_t __iomem *) stli_onbegetmemptr(brdp,
4376 CDK_SIGADDR, __LINE__); 3918 CDK_SIGADDR, __LINE__);
4377 memcpy(&onbsig, onbsigp, sizeof(cdkonbsig_t)); 3919 memcpy_fromio(&onbsig, onbsigp, sizeof(cdkonbsig_t));
4378 if ((onbsig.magic0 == ONB_MAGIC0) && 3920 if ((onbsig.magic0 == cpu_to_le16(ONB_MAGIC0)) &&
4379 (onbsig.magic1 == ONB_MAGIC1) && 3921 (onbsig.magic1 == cpu_to_le16(ONB_MAGIC1)) &&
4380 (onbsig.magic2 == ONB_MAGIC2) && 3922 (onbsig.magic2 == cpu_to_le16(ONB_MAGIC2)) &&
4381 (onbsig.magic3 == ONB_MAGIC3)) 3923 (onbsig.magic3 == cpu_to_le16(ONB_MAGIC3)))
4382 foundit = 1; 3924 foundit = 1;
4383 } 3925 }
4384 3926
@@ -4402,9 +3944,9 @@ static int stli_eisamemprobe(stlibrd_t *brdp)
4402 printk(KERN_ERR "STALLION: failed to probe shared memory " 3944 printk(KERN_ERR "STALLION: failed to probe shared memory "
4403 "region for %s in EISA slot=%d\n", 3945 "region for %s in EISA slot=%d\n",
4404 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12)); 3946 stli_brdnames[brdp->brdtype], (brdp->iobase >> 12));
4405 return(-ENODEV); 3947 return -ENODEV;
4406 } 3948 }
4407 return(0); 3949 return 0;
4408} 3950}
4409 3951
4410static int stli_getbrdnr(void) 3952static int stli_getbrdnr(void)
@@ -4435,22 +3977,16 @@ static int stli_getbrdnr(void)
4435 3977
4436static int stli_findeisabrds(void) 3978static int stli_findeisabrds(void)
4437{ 3979{
4438 stlibrd_t *brdp; 3980 stlibrd_t *brdp;
4439 unsigned int iobase, eid; 3981 unsigned int iobase, eid;
4440 int i; 3982 int i;
4441
4442#ifdef DEBUG
4443 printk(KERN_DEBUG "stli_findeisabrds()\n");
4444#endif
4445 3983
4446/* 3984/*
4447 * Firstly check if this is an EISA system. Do this by probing for 3985 * Firstly check if this is an EISA system. If this is not an EISA system then
4448 * the system board EISA ID. If this is not an EISA system then
4449 * don't bother going any further! 3986 * don't bother going any further!
4450 */ 3987 */
4451 outb(0xff, 0xc80); 3988 if (EISA_bus)
4452 if (inb(0xc80) == 0xff) 3989 return 0;
4453 return(0);
4454 3990
4455/* 3991/*
4456 * Looks like an EISA system, so go searching for EISA boards. 3992 * Looks like an EISA system, so go searching for EISA boards.
@@ -4468,7 +4004,7 @@ static int stli_findeisabrds(void)
4468 */ 4004 */
4469 for (i = 0; (i < STL_MAXBRDS); i++) { 4005 for (i = 0; (i < STL_MAXBRDS); i++) {
4470 brdp = stli_brds[i]; 4006 brdp = stli_brds[i];
4471 if (brdp == (stlibrd_t *) NULL) 4007 if (brdp == NULL)
4472 continue; 4008 continue;
4473 if (brdp->iobase == iobase) 4009 if (brdp->iobase == iobase)
4474 break; 4010 break;
@@ -4480,10 +4016,10 @@ static int stli_findeisabrds(void)
4480 * We have found a Stallion board and it is not configured already. 4016 * We have found a Stallion board and it is not configured already.
4481 * Allocate a board structure and initialize it. 4017 * Allocate a board structure and initialize it.
4482 */ 4018 */
4483 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4019 if ((brdp = stli_allocbrd()) == NULL)
4484 return(-ENOMEM); 4020 return -ENOMEM;
4485 if ((brdp->brdnr = stli_getbrdnr()) < 0) 4021 if ((brdp->brdnr = stli_getbrdnr()) < 0)
4486 return(-ENOMEM); 4022 return -ENOMEM;
4487 eid = inb(iobase + 0xc82); 4023 eid = inb(iobase + 0xc82);
4488 if (eid == ECP_EISAID) 4024 if (eid == ECP_EISAID)
4489 brdp->brdtype = BRD_ECPE; 4025 brdp->brdtype = BRD_ECPE;
@@ -4498,7 +4034,7 @@ static int stli_findeisabrds(void)
4498 stli_brdinit(brdp); 4034 stli_brdinit(brdp);
4499 } 4035 }
4500 4036
4501 return(0); 4037 return 0;
4502} 4038}
4503 4039
4504/*****************************************************************************/ 4040/*****************************************************************************/
@@ -4519,32 +4055,18 @@ static int stli_findeisabrds(void)
4519 4055
4520static int stli_initpcibrd(int brdtype, struct pci_dev *devp) 4056static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4521{ 4057{
4522 stlibrd_t *brdp; 4058 stlibrd_t *brdp;
4523
4524#ifdef DEBUG
4525 printk(KERN_DEBUG "stli_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
4526 brdtype, dev->bus->number, dev->devfn);
4527#endif
4528 4059
4529 if (pci_enable_device(devp)) 4060 if (pci_enable_device(devp))
4530 return(-EIO); 4061 return -EIO;
4531 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4062 if ((brdp = stli_allocbrd()) == NULL)
4532 return(-ENOMEM); 4063 return -ENOMEM;
4533 if ((brdp->brdnr = stli_getbrdnr()) < 0) { 4064 if ((brdp->brdnr = stli_getbrdnr()) < 0) {
4534 printk(KERN_INFO "STALLION: too many boards found, " 4065 printk(KERN_INFO "STALLION: too many boards found, "
4535 "maximum supported %d\n", STL_MAXBRDS); 4066 "maximum supported %d\n", STL_MAXBRDS);
4536 return(0); 4067 return 0;
4537 } 4068 }
4538 brdp->brdtype = brdtype; 4069 brdp->brdtype = brdtype;
4539
4540#ifdef DEBUG
4541 printk(KERN_DEBUG "%s(%d): BAR[]=%lx,%lx,%lx,%lx\n", __FILE__, __LINE__,
4542 pci_resource_start(devp, 0),
4543 pci_resource_start(devp, 1),
4544 pci_resource_start(devp, 2),
4545 pci_resource_start(devp, 3));
4546#endif
4547
4548/* 4070/*
4549 * We have all resources from the board, so lets setup the actual 4071 * We have all resources from the board, so lets setup the actual
4550 * board structure now. 4072 * board structure now.
@@ -4553,7 +4075,7 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4553 brdp->memaddr = pci_resource_start(devp, 2); 4075 brdp->memaddr = pci_resource_start(devp, 2);
4554 stli_brdinit(brdp); 4076 stli_brdinit(brdp);
4555 4077
4556 return(0); 4078 return 0;
4557} 4079}
4558 4080
4559/*****************************************************************************/ 4081/*****************************************************************************/
@@ -4565,20 +4087,12 @@ static int stli_initpcibrd(int brdtype, struct pci_dev *devp)
4565 4087
4566static int stli_findpcibrds(void) 4088static int stli_findpcibrds(void)
4567{ 4089{
4568 struct pci_dev *dev = NULL; 4090 struct pci_dev *dev = NULL;
4569 int rc;
4570
4571#ifdef DEBUG
4572 printk("stli_findpcibrds()\n");
4573#endif
4574 4091
4575 while ((dev = pci_find_device(PCI_VENDOR_ID_STALLION, 4092 while ((dev = pci_get_device(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECRA, dev))) {
4576 PCI_DEVICE_ID_ECRA, dev))) { 4093 stli_initpcibrd(BRD_ECPPCI, dev);
4577 if ((rc = stli_initpcibrd(BRD_ECPPCI, dev)))
4578 return(rc);
4579 } 4094 }
4580 4095 return 0;
4581 return(0);
4582} 4096}
4583 4097
4584#endif 4098#endif
@@ -4591,17 +4105,16 @@ static int stli_findpcibrds(void)
4591 4105
4592static stlibrd_t *stli_allocbrd(void) 4106static stlibrd_t *stli_allocbrd(void)
4593{ 4107{
4594 stlibrd_t *brdp; 4108 stlibrd_t *brdp;
4595 4109
4596 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL); 4110 brdp = kzalloc(sizeof(stlibrd_t), GFP_KERNEL);
4597 if (!brdp) { 4111 if (!brdp) {
4598 printk(KERN_ERR "STALLION: failed to allocate memory " 4112 printk(KERN_ERR "STALLION: failed to allocate memory "
4599 "(size=%d)\n", sizeof(stlibrd_t)); 4113 "(size=%Zd)\n", sizeof(stlibrd_t));
4600 return NULL; 4114 return NULL;
4601 } 4115 }
4602
4603 brdp->magic = STLI_BOARDMAGIC; 4116 brdp->magic = STLI_BOARDMAGIC;
4604 return(brdp); 4117 return brdp;
4605} 4118}
4606 4119
4607/*****************************************************************************/ 4120/*****************************************************************************/
@@ -4613,13 +4126,9 @@ static stlibrd_t *stli_allocbrd(void)
4613 4126
4614static int stli_initbrds(void) 4127static int stli_initbrds(void)
4615{ 4128{
4616 stlibrd_t *brdp, *nxtbrdp; 4129 stlibrd_t *brdp, *nxtbrdp;
4617 stlconf_t *confp; 4130 stlconf_t *confp;
4618 int i, j; 4131 int i, j;
4619
4620#ifdef DEBUG
4621 printk(KERN_DEBUG "stli_initbrds()\n");
4622#endif
4623 4132
4624 if (stli_nrbrds > STL_MAXBRDS) { 4133 if (stli_nrbrds > STL_MAXBRDS) {
4625 printk(KERN_INFO "STALLION: too many boards in configuration " 4134 printk(KERN_INFO "STALLION: too many boards in configuration "
@@ -4634,11 +4143,9 @@ static int stli_initbrds(void)
4634 */ 4143 */
4635 for (i = 0; (i < stli_nrbrds); i++) { 4144 for (i = 0; (i < stli_nrbrds); i++) {
4636 confp = &stli_brdconf[i]; 4145 confp = &stli_brdconf[i];
4637#ifdef MODULE
4638 stli_parsebrd(confp, stli_brdsp[i]); 4146 stli_parsebrd(confp, stli_brdsp[i]);
4639#endif 4147 if ((brdp = stli_allocbrd()) == NULL)
4640 if ((brdp = stli_allocbrd()) == (stlibrd_t *) NULL) 4148 return -ENOMEM;
4641 return(-ENOMEM);
4642 brdp->brdnr = i; 4149 brdp->brdnr = i;
4643 brdp->brdtype = confp->brdtype; 4150 brdp->brdtype = confp->brdtype;
4644 brdp->iobase = confp->ioaddr1; 4151 brdp->iobase = confp->ioaddr1;
@@ -4650,9 +4157,7 @@ static int stli_initbrds(void)
4650 * Static configuration table done, so now use dynamic methods to 4157 * Static configuration table done, so now use dynamic methods to
4651 * see if any more boards should be configured. 4158 * see if any more boards should be configured.
4652 */ 4159 */
4653#ifdef MODULE
4654 stli_argbrds(); 4160 stli_argbrds();
4655#endif
4656 if (STLI_EISAPROBE) 4161 if (STLI_EISAPROBE)
4657 stli_findeisabrds(); 4162 stli_findeisabrds();
4658#ifdef CONFIG_PCI 4163#ifdef CONFIG_PCI
@@ -4668,11 +4173,11 @@ static int stli_initbrds(void)
4668 if (stli_nrbrds > 1) { 4173 if (stli_nrbrds > 1) {
4669 for (i = 0; (i < stli_nrbrds); i++) { 4174 for (i = 0; (i < stli_nrbrds); i++) {
4670 brdp = stli_brds[i]; 4175 brdp = stli_brds[i];
4671 if (brdp == (stlibrd_t *) NULL) 4176 if (brdp == NULL)
4672 continue; 4177 continue;
4673 for (j = i + 1; (j < stli_nrbrds); j++) { 4178 for (j = i + 1; (j < stli_nrbrds); j++) {
4674 nxtbrdp = stli_brds[j]; 4179 nxtbrdp = stli_brds[j];
4675 if (nxtbrdp == (stlibrd_t *) NULL) 4180 if (nxtbrdp == NULL)
4676 continue; 4181 continue;
4677 if ((brdp->membase >= nxtbrdp->membase) && 4182 if ((brdp->membase >= nxtbrdp->membase) &&
4678 (brdp->membase <= (nxtbrdp->membase + 4183 (brdp->membase <= (nxtbrdp->membase +
@@ -4687,7 +4192,7 @@ static int stli_initbrds(void)
4687 if (stli_shared == 0) { 4192 if (stli_shared == 0) {
4688 for (i = 0; (i < stli_nrbrds); i++) { 4193 for (i = 0; (i < stli_nrbrds); i++) {
4689 brdp = stli_brds[i]; 4194 brdp = stli_brds[i];
4690 if (brdp == (stlibrd_t *) NULL) 4195 if (brdp == NULL)
4691 continue; 4196 continue;
4692 if (brdp->state & BST_FOUND) { 4197 if (brdp->state & BST_FOUND) {
4693 EBRDENABLE(brdp); 4198 EBRDENABLE(brdp);
@@ -4697,7 +4202,7 @@ static int stli_initbrds(void)
4697 } 4202 }
4698 } 4203 }
4699 4204
4700 return(0); 4205 return 0;
4701} 4206}
4702 4207
4703/*****************************************************************************/ 4208/*****************************************************************************/
@@ -4710,48 +4215,55 @@ static int stli_initbrds(void)
4710 4215
4711static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp) 4216static ssize_t stli_memread(struct file *fp, char __user *buf, size_t count, loff_t *offp)
4712{ 4217{
4713 unsigned long flags; 4218 unsigned long flags;
4714 void *memptr; 4219 void *memptr;
4715 stlibrd_t *brdp; 4220 stlibrd_t *brdp;
4716 int brdnr, size, n; 4221 int brdnr, size, n;
4717 4222 void *p;
4718#ifdef DEBUG 4223 loff_t off = *offp;
4719 printk(KERN_DEBUG "stli_memread(fp=%x,buf=%x,count=%x,offp=%x)\n",
4720 (int) fp, (int) buf, count, (int) offp);
4721#endif
4722 4224
4723 brdnr = iminor(fp->f_dentry->d_inode); 4225 brdnr = iminor(fp->f_dentry->d_inode);
4724 if (brdnr >= stli_nrbrds) 4226 if (brdnr >= stli_nrbrds)
4725 return(-ENODEV); 4227 return -ENODEV;
4726 brdp = stli_brds[brdnr]; 4228 brdp = stli_brds[brdnr];
4727 if (brdp == (stlibrd_t *) NULL) 4229 if (brdp == NULL)
4728 return(-ENODEV); 4230 return -ENODEV;
4729 if (brdp->state == 0) 4231 if (brdp->state == 0)
4730 return(-ENODEV); 4232 return -ENODEV;
4731 if (fp->f_pos >= brdp->memsize) 4233 if (off >= brdp->memsize || off + count < off)
4732 return(0); 4234 return 0;
4733 4235
4734 size = MIN(count, (brdp->memsize - fp->f_pos)); 4236 size = MIN(count, (brdp->memsize - off));
4237
4238 /*
4239 * Copy the data a page at a time
4240 */
4241
4242 p = (void *)__get_free_page(GFP_KERNEL);
4243 if(p == NULL)
4244 return -ENOMEM;
4735 4245
4736 save_flags(flags);
4737 cli();
4738 EBRDENABLE(brdp);
4739 while (size > 0) { 4246 while (size > 0) {
4740 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos); 4247 spin_lock_irqsave(&brd_lock, flags);
4741 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize))); 4248 EBRDENABLE(brdp);
4742 if (copy_to_user(buf, memptr, n)) { 4249 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4250 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4251 n = MIN(n, PAGE_SIZE);
4252 memcpy_fromio(p, memptr, n);
4253 EBRDDISABLE(brdp);
4254 spin_unlock_irqrestore(&brd_lock, flags);
4255 if (copy_to_user(buf, p, n)) {
4743 count = -EFAULT; 4256 count = -EFAULT;
4744 goto out; 4257 goto out;
4745 } 4258 }
4746 fp->f_pos += n; 4259 off += n;
4747 buf += n; 4260 buf += n;
4748 size -= n; 4261 size -= n;
4749 } 4262 }
4750out: 4263out:
4751 EBRDDISABLE(brdp); 4264 *offp = off;
4752 restore_flags(flags); 4265 free_page((unsigned long)p);
4753 4266 return count;
4754 return(count);
4755} 4267}
4756 4268
4757/*****************************************************************************/ 4269/*****************************************************************************/
@@ -4760,54 +4272,65 @@ out:
4760 * Code to handle an "staliomem" write operation. This device is the 4272 * Code to handle an "staliomem" write operation. This device is the
4761 * contents of the board shared memory. It is used for down loading 4273 * contents of the board shared memory. It is used for down loading
4762 * the slave image (and debugging :-) 4274 * the slave image (and debugging :-)
4275 *
4276 * FIXME: copy under lock
4763 */ 4277 */
4764 4278
4765static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp) 4279static ssize_t stli_memwrite(struct file *fp, const char __user *buf, size_t count, loff_t *offp)
4766{ 4280{
4767 unsigned long flags; 4281 unsigned long flags;
4768 void *memptr; 4282 void *memptr;
4769 stlibrd_t *brdp; 4283 stlibrd_t *brdp;
4770 char __user *chbuf; 4284 char __user *chbuf;
4771 int brdnr, size, n; 4285 int brdnr, size, n;
4772 4286 void *p;
4773#ifdef DEBUG 4287 loff_t off = *offp;
4774 printk(KERN_DEBUG "stli_memwrite(fp=%x,buf=%x,count=%x,offp=%x)\n",
4775 (int) fp, (int) buf, count, (int) offp);
4776#endif
4777 4288
4778 brdnr = iminor(fp->f_dentry->d_inode); 4289 brdnr = iminor(fp->f_dentry->d_inode);
4290
4779 if (brdnr >= stli_nrbrds) 4291 if (brdnr >= stli_nrbrds)
4780 return(-ENODEV); 4292 return -ENODEV;
4781 brdp = stli_brds[brdnr]; 4293 brdp = stli_brds[brdnr];
4782 if (brdp == (stlibrd_t *) NULL) 4294 if (brdp == NULL)
4783 return(-ENODEV); 4295 return -ENODEV;
4784 if (brdp->state == 0) 4296 if (brdp->state == 0)
4785 return(-ENODEV); 4297 return -ENODEV;
4786 if (fp->f_pos >= brdp->memsize) 4298 if (off >= brdp->memsize || off + count < off)
4787 return(0); 4299 return 0;
4788 4300
4789 chbuf = (char __user *) buf; 4301 chbuf = (char __user *) buf;
4790 size = MIN(count, (brdp->memsize - fp->f_pos)); 4302 size = MIN(count, (brdp->memsize - off));
4303
4304 /*
4305 * Copy the data a page at a time
4306 */
4307
4308 p = (void *)__get_free_page(GFP_KERNEL);
4309 if(p == NULL)
4310 return -ENOMEM;
4791 4311
4792 save_flags(flags);
4793 cli();
4794 EBRDENABLE(brdp);
4795 while (size > 0) { 4312 while (size > 0) {
4796 memptr = (void *) EBRDGETMEMPTR(brdp, fp->f_pos); 4313 n = MIN(size, (brdp->pagesize - (((unsigned long) off) % brdp->pagesize)));
4797 n = MIN(size, (brdp->pagesize - (((unsigned long) fp->f_pos) % brdp->pagesize))); 4314 n = MIN(n, PAGE_SIZE);
4798 if (copy_from_user(memptr, chbuf, n)) { 4315 if (copy_from_user(p, chbuf, n)) {
4799 count = -EFAULT; 4316 if (count == 0)
4317 count = -EFAULT;
4800 goto out; 4318 goto out;
4801 } 4319 }
4802 fp->f_pos += n; 4320 spin_lock_irqsave(&brd_lock, flags);
4321 EBRDENABLE(brdp);
4322 memptr = (void *) EBRDGETMEMPTR(brdp, off);
4323 memcpy_toio(memptr, p, n);
4324 EBRDDISABLE(brdp);
4325 spin_unlock_irqrestore(&brd_lock, flags);
4326 off += n;
4803 chbuf += n; 4327 chbuf += n;
4804 size -= n; 4328 size -= n;
4805 } 4329 }
4806out: 4330out:
4807 EBRDDISABLE(brdp); 4331 free_page((unsigned long) p);
4808 restore_flags(flags); 4332 *offp = off;
4809 4333 return count;
4810 return(count);
4811} 4334}
4812 4335
4813/*****************************************************************************/ 4336/*****************************************************************************/
@@ -4818,16 +4341,16 @@ out:
4818 4341
4819static int stli_getbrdstats(combrd_t __user *bp) 4342static int stli_getbrdstats(combrd_t __user *bp)
4820{ 4343{
4821 stlibrd_t *brdp; 4344 stlibrd_t *brdp;
4822 int i; 4345 int i;
4823 4346
4824 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t))) 4347 if (copy_from_user(&stli_brdstats, bp, sizeof(combrd_t)))
4825 return -EFAULT; 4348 return -EFAULT;
4826 if (stli_brdstats.brd >= STL_MAXBRDS) 4349 if (stli_brdstats.brd >= STL_MAXBRDS)
4827 return(-ENODEV); 4350 return -ENODEV;
4828 brdp = stli_brds[stli_brdstats.brd]; 4351 brdp = stli_brds[stli_brdstats.brd];
4829 if (brdp == (stlibrd_t *) NULL) 4352 if (brdp == NULL)
4830 return(-ENODEV); 4353 return -ENODEV;
4831 4354
4832 memset(&stli_brdstats, 0, sizeof(combrd_t)); 4355 memset(&stli_brdstats, 0, sizeof(combrd_t));
4833 stli_brdstats.brd = brdp->brdnr; 4356 stli_brdstats.brd = brdp->brdnr;
@@ -4846,7 +4369,7 @@ static int stli_getbrdstats(combrd_t __user *bp)
4846 4369
4847 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t))) 4370 if (copy_to_user(bp, &stli_brdstats, sizeof(combrd_t)))
4848 return -EFAULT; 4371 return -EFAULT;
4849 return(0); 4372 return 0;
4850} 4373}
4851 4374
4852/*****************************************************************************/ 4375/*****************************************************************************/
@@ -4857,19 +4380,19 @@ static int stli_getbrdstats(combrd_t __user *bp)
4857 4380
4858static stliport_t *stli_getport(int brdnr, int panelnr, int portnr) 4381static stliport_t *stli_getport(int brdnr, int panelnr, int portnr)
4859{ 4382{
4860 stlibrd_t *brdp; 4383 stlibrd_t *brdp;
4861 int i; 4384 int i;
4862 4385
4863 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS)) 4386 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
4864 return((stliport_t *) NULL); 4387 return NULL;
4865 brdp = stli_brds[brdnr]; 4388 brdp = stli_brds[brdnr];
4866 if (brdp == (stlibrd_t *) NULL) 4389 if (brdp == NULL)
4867 return((stliport_t *) NULL); 4390 return NULL;
4868 for (i = 0; (i < panelnr); i++) 4391 for (i = 0; (i < panelnr); i++)
4869 portnr += brdp->panels[i]; 4392 portnr += brdp->panels[i];
4870 if ((portnr < 0) || (portnr >= brdp->nrports)) 4393 if ((portnr < 0) || (portnr >= brdp->nrports))
4871 return((stliport_t *) NULL); 4394 return NULL;
4872 return(brdp->ports[portnr]); 4395 return brdp->ports[portnr];
4873} 4396}
4874 4397
4875/*****************************************************************************/ 4398/*****************************************************************************/
@@ -4888,16 +4411,16 @@ static int stli_portcmdstats(stliport_t *portp)
4888 4411
4889 memset(&stli_comstats, 0, sizeof(comstats_t)); 4412 memset(&stli_comstats, 0, sizeof(comstats_t));
4890 4413
4891 if (portp == (stliport_t *) NULL) 4414 if (portp == NULL)
4892 return(-ENODEV); 4415 return -ENODEV;
4893 brdp = stli_brds[portp->brdnr]; 4416 brdp = stli_brds[portp->brdnr];
4894 if (brdp == (stlibrd_t *) NULL) 4417 if (brdp == NULL)
4895 return(-ENODEV); 4418 return -ENODEV;
4896 4419
4897 if (brdp->state & BST_STARTED) { 4420 if (brdp->state & BST_STARTED) {
4898 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS, 4421 if ((rc = stli_cmdwait(brdp, portp, A_GETSTATS,
4899 &stli_cdkstats, sizeof(asystats_t), 1)) < 0) 4422 &stli_cdkstats, sizeof(asystats_t), 1)) < 0)
4900 return(rc); 4423 return rc;
4901 } else { 4424 } else {
4902 memset(&stli_cdkstats, 0, sizeof(asystats_t)); 4425 memset(&stli_cdkstats, 0, sizeof(asystats_t));
4903 } 4426 }
@@ -4908,13 +4431,12 @@ static int stli_portcmdstats(stliport_t *portp)
4908 stli_comstats.state = portp->state; 4431 stli_comstats.state = portp->state;
4909 stli_comstats.flags = portp->flags; 4432 stli_comstats.flags = portp->flags;
4910 4433
4911 save_flags(flags); 4434 spin_lock_irqsave(&brd_lock, flags);
4912 cli(); 4435 if (portp->tty != NULL) {
4913 if (portp->tty != (struct tty_struct *) NULL) {
4914 if (portp->tty->driver_data == portp) { 4436 if (portp->tty->driver_data == portp) {
4915 stli_comstats.ttystate = portp->tty->flags; 4437 stli_comstats.ttystate = portp->tty->flags;
4916 stli_comstats.rxbuffered = -1 /*portp->tty->flip.count*/; 4438 stli_comstats.rxbuffered = -1;
4917 if (portp->tty->termios != (struct termios *) NULL) { 4439 if (portp->tty->termios != NULL) {
4918 stli_comstats.cflags = portp->tty->termios->c_cflag; 4440 stli_comstats.cflags = portp->tty->termios->c_cflag;
4919 stli_comstats.iflags = portp->tty->termios->c_iflag; 4441 stli_comstats.iflags = portp->tty->termios->c_iflag;
4920 stli_comstats.oflags = portp->tty->termios->c_oflag; 4442 stli_comstats.oflags = portp->tty->termios->c_oflag;
@@ -4922,7 +4444,7 @@ static int stli_portcmdstats(stliport_t *portp)
4922 } 4444 }
4923 } 4445 }
4924 } 4446 }
4925 restore_flags(flags); 4447 spin_unlock_irqrestore(&brd_lock, flags);
4926 4448
4927 stli_comstats.txtotal = stli_cdkstats.txchars; 4449 stli_comstats.txtotal = stli_cdkstats.txchars;
4928 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover; 4450 stli_comstats.rxtotal = stli_cdkstats.rxchars + stli_cdkstats.ringover;
@@ -4944,7 +4466,7 @@ static int stli_portcmdstats(stliport_t *portp)
4944 stli_comstats.hwid = stli_cdkstats.hwid; 4466 stli_comstats.hwid = stli_cdkstats.hwid;
4945 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals); 4467 stli_comstats.signals = stli_mktiocm(stli_cdkstats.signals);
4946 4468
4947 return(0); 4469 return 0;
4948} 4470}
4949 4471
4950/*****************************************************************************/ 4472/*****************************************************************************/
@@ -4957,8 +4479,8 @@ static int stli_portcmdstats(stliport_t *portp)
4957 4479
4958static int stli_getportstats(stliport_t *portp, comstats_t __user *cp) 4480static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4959{ 4481{
4960 stlibrd_t *brdp; 4482 stlibrd_t *brdp;
4961 int rc; 4483 int rc;
4962 4484
4963 if (!portp) { 4485 if (!portp) {
4964 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) 4486 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -4988,8 +4510,8 @@ static int stli_getportstats(stliport_t *portp, comstats_t __user *cp)
4988 4510
4989static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp) 4511static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
4990{ 4512{
4991 stlibrd_t *brdp; 4513 stlibrd_t *brdp;
4992 int rc; 4514 int rc;
4993 4515
4994 if (!portp) { 4516 if (!portp) {
4995 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t))) 4517 if (copy_from_user(&stli_comstats, cp, sizeof(comstats_t)))
@@ -5027,7 +4549,7 @@ static int stli_clrportstats(stliport_t *portp, comstats_t __user *cp)
5027 4549
5028static int stli_getportstruct(stliport_t __user *arg) 4550static int stli_getportstruct(stliport_t __user *arg)
5029{ 4551{
5030 stliport_t *portp; 4552 stliport_t *portp;
5031 4553
5032 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t))) 4554 if (copy_from_user(&stli_dummyport, arg, sizeof(stliport_t)))
5033 return -EFAULT; 4555 return -EFAULT;
@@ -5048,7 +4570,7 @@ static int stli_getportstruct(stliport_t __user *arg)
5048 4570
5049static int stli_getbrdstruct(stlibrd_t __user *arg) 4571static int stli_getbrdstruct(stlibrd_t __user *arg)
5050{ 4572{
5051 stlibrd_t *brdp; 4573 stlibrd_t *brdp;
5052 4574
5053 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t))) 4575 if (copy_from_user(&stli_dummybrd, arg, sizeof(stlibrd_t)))
5054 return -EFAULT; 4576 return -EFAULT;
@@ -5072,15 +4594,10 @@ static int stli_getbrdstruct(stlibrd_t __user *arg)
5072 4594
5073static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg) 4595static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
5074{ 4596{
5075 stlibrd_t *brdp; 4597 stlibrd_t *brdp;
5076 int brdnr, rc, done; 4598 int brdnr, rc, done;
5077 void __user *argp = (void __user *)arg; 4599 void __user *argp = (void __user *)arg;
5078 4600
5079#ifdef DEBUG
5080 printk(KERN_DEBUG "stli_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n",
5081 (int) ip, (int) fp, cmd, (int) arg);
5082#endif
5083
5084/* 4601/*
5085 * First up handle the board independent ioctls. 4602 * First up handle the board independent ioctls.
5086 */ 4603 */
@@ -5111,7 +4628,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5111 } 4628 }
5112 4629
5113 if (done) 4630 if (done)
5114 return(rc); 4631 return rc;
5115 4632
5116/* 4633/*
5117 * Now handle the board specific ioctls. These all depend on the 4634 * Now handle the board specific ioctls. These all depend on the
@@ -5119,12 +4636,12 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5119 */ 4636 */
5120 brdnr = iminor(ip); 4637 brdnr = iminor(ip);
5121 if (brdnr >= STL_MAXBRDS) 4638 if (brdnr >= STL_MAXBRDS)
5122 return(-ENODEV); 4639 return -ENODEV;
5123 brdp = stli_brds[brdnr]; 4640 brdp = stli_brds[brdnr];
5124 if (!brdp) 4641 if (!brdp)
5125 return(-ENODEV); 4642 return -ENODEV;
5126 if (brdp->state == 0) 4643 if (brdp->state == 0)
5127 return(-ENODEV); 4644 return -ENODEV;
5128 4645
5129 switch (cmd) { 4646 switch (cmd) {
5130 case STL_BINTR: 4647 case STL_BINTR:
@@ -5148,8 +4665,7 @@ static int stli_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, un
5148 rc = -ENOIOCTLCMD; 4665 rc = -ENOIOCTLCMD;
5149 break; 4666 break;
5150 } 4667 }
5151 4668 return rc;
5152 return(rc);
5153} 4669}
5154 4670
5155static struct tty_operations stli_ops = { 4671static struct tty_operations stli_ops = {
@@ -5183,6 +4699,9 @@ int __init stli_init(void)
5183 int i; 4699 int i;
5184 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion); 4700 printk(KERN_INFO "%s: version %s\n", stli_drvtitle, stli_drvversion);
5185 4701
4702 spin_lock_init(&stli_lock);
4703 spin_lock_init(&brd_lock);
4704
5186 stli_initbrds(); 4705 stli_initbrds();
5187 4706
5188 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); 4707 stli_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -5192,10 +4711,6 @@ int __init stli_init(void)
5192/* 4711/*
5193 * Allocate a temporary write buffer. 4712 * Allocate a temporary write buffer.
5194 */ 4713 */
5195 stli_tmpwritebuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5196 if (!stli_tmpwritebuf)
5197 printk(KERN_ERR "STALLION: failed to allocate memory "
5198 "(size=%d)\n", STLI_TXBUFSIZE);
5199 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL); 4714 stli_txcookbuf = kmalloc(STLI_TXBUFSIZE, GFP_KERNEL);
5200 if (!stli_txcookbuf) 4715 if (!stli_txcookbuf)
5201 printk(KERN_ERR "STALLION: failed to allocate memory " 4716 printk(KERN_ERR "STALLION: failed to allocate memory "
@@ -5234,7 +4749,7 @@ int __init stli_init(void)
5234 printk(KERN_ERR "STALLION: failed to register serial driver\n"); 4749 printk(KERN_ERR "STALLION: failed to register serial driver\n");
5235 return -EBUSY; 4750 return -EBUSY;
5236 } 4751 }
5237 return(0); 4752 return 0;
5238} 4753}
5239 4754
5240/*****************************************************************************/ 4755/*****************************************************************************/
diff --git a/drivers/char/moxa.c b/drivers/char/moxa.c
index afa2cda5e353..52ef61f54ba0 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 f373d0155a77..9491e4307566 100644
--- a/drivers/char/pty.c
+++ b/drivers/char/pty.c
@@ -100,7 +100,7 @@ static void pty_unthrottle(struct tty_struct * tty)
100 * 100 *
101 * FIXME: Our pty_write method is called with our ldisc lock held but 101 * FIXME: Our pty_write method is called with our ldisc lock held but
102 * not our partners. We can't just take the other one blindly without 102 * not our partners. We can't just take the other one blindly without
103 * risking deadlocks. There is also the small matter of TTY_DONT_FLIP 103 * risking deadlocks.
104 */ 104 */
105static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count) 105static int pty_write(struct tty_struct * tty, const unsigned char *buf, int count)
106{ 106{
diff --git a/drivers/char/rio/riointr.c b/drivers/char/rio/riointr.c
index eec1fea0cb92..0bd09040a5c0 100644
--- a/drivers/char/rio/riointr.c
+++ b/drivers/char/rio/riointr.c
@@ -546,7 +546,7 @@ static void RIOReceive(struct rio_info *p, struct Port *PortP)
546 ** run out of space it will be set to the offset of the 546 ** run out of space it will be set to the offset of the
547 ** next byte to copy from the packet data area. The packet 547 ** next byte to copy from the packet data area. The packet
548 ** length field is decremented by the number of bytes that 548 ** length field is decremented by the number of bytes that
549 ** we succesfully removed from the packet. When this reaches 549 ** we successfully removed from the packet. When this reaches
550 ** zero, we reset the offset pointer to be zero, and free 550 ** zero, we reset the offset pointer to be zero, and free
551 ** the packet from the front of the queue. 551 ** the packet from the front of the queue.
552 */ 552 */
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 38fdd4da2427..0f7a542d9041 100644
--- a/drivers/char/stallion.c
+++ b/drivers/char/stallion.c
@@ -140,15 +140,6 @@ static char *stl_drvversion = "5.6.0";
140static struct tty_driver *stl_serial; 140static struct tty_driver *stl_serial;
141 141
142/* 142/*
143 * We will need to allocate a temporary write buffer for chars that
144 * come direct from user space. The problem is that a copy from user
145 * space might cause a page fault (typically on a system that is
146 * swapping!). All ports will share one buffer - since if the system
147 * is already swapping a shared buffer won't make things any worse.
148 */
149static char *stl_tmpwritebuf;
150
151/*
152 * Define a local default termios struct. All ports will be created 143 * Define a local default termios struct. All ports will be created
153 * with this termios initially. Basically all it defines is a raw port 144 * with this termios initially. Basically all it defines is a raw port
154 * at 9600, 8 data bits, 1 stop bit. 145 * at 9600, 8 data bits, 1 stop bit.
@@ -362,6 +353,14 @@ static unsigned char stl_vecmap[] = {
362}; 353};
363 354
364/* 355/*
356 * Lock ordering is that you may not take stallion_lock holding
357 * brd_lock.
358 */
359
360static spinlock_t brd_lock; /* Guard the board mapping */
361static spinlock_t stallion_lock; /* Guard the tty driver */
362
363/*
365 * Set up enable and disable macros for the ECH boards. They require 364 * Set up enable and disable macros for the ECH boards. They require
366 * the secondary io address space to be activated and deactivated. 365 * the secondary io address space to be activated and deactivated.
367 * This way all ECH boards can share their secondary io region. 366 * This way all ECH boards can share their secondary io region.
@@ -724,17 +723,7 @@ static struct class *stallion_class;
724 723
725static int __init stallion_module_init(void) 724static int __init stallion_module_init(void)
726{ 725{
727 unsigned long flags;
728
729#ifdef DEBUG
730 printk("init_module()\n");
731#endif
732
733 save_flags(flags);
734 cli();
735 stl_init(); 726 stl_init();
736 restore_flags(flags);
737
738 return 0; 727 return 0;
739} 728}
740 729
@@ -745,7 +734,6 @@ static void __exit stallion_module_exit(void)
745 stlbrd_t *brdp; 734 stlbrd_t *brdp;
746 stlpanel_t *panelp; 735 stlpanel_t *panelp;
747 stlport_t *portp; 736 stlport_t *portp;
748 unsigned long flags;
749 int i, j, k; 737 int i, j, k;
750 738
751#ifdef DEBUG 739#ifdef DEBUG
@@ -755,9 +743,6 @@ static void __exit stallion_module_exit(void)
755 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle, 743 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
756 stl_drvversion); 744 stl_drvversion);
757 745
758 save_flags(flags);
759 cli();
760
761/* 746/*
762 * Free up all allocated resources used by the ports. This includes 747 * Free up all allocated resources used by the ports. This includes
763 * memory and interrupts. As part of this process we will also do 748 * memory and interrupts. As part of this process we will also do
@@ -769,7 +754,6 @@ static void __exit stallion_module_exit(void)
769 if (i) { 754 if (i) {
770 printk("STALLION: failed to un-register tty driver, " 755 printk("STALLION: failed to un-register tty driver, "
771 "errno=%d\n", -i); 756 "errno=%d\n", -i);
772 restore_flags(flags);
773 return; 757 return;
774 } 758 }
775 for (i = 0; i < 4; i++) 759 for (i = 0; i < 4; i++)
@@ -779,8 +763,6 @@ static void __exit stallion_module_exit(void)
779 "errno=%d\n", -i); 763 "errno=%d\n", -i);
780 class_destroy(stallion_class); 764 class_destroy(stallion_class);
781 765
782 kfree(stl_tmpwritebuf);
783
784 for (i = 0; (i < stl_nrbrds); i++) { 766 for (i = 0; (i < stl_nrbrds); i++) {
785 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL) 767 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
786 continue; 768 continue;
@@ -810,8 +792,6 @@ static void __exit stallion_module_exit(void)
810 kfree(brdp); 792 kfree(brdp);
811 stl_brds[i] = (stlbrd_t *) NULL; 793 stl_brds[i] = (stlbrd_t *) NULL;
812 } 794 }
813
814 restore_flags(flags);
815} 795}
816 796
817module_init(stallion_module_init); 797module_init(stallion_module_init);
@@ -944,7 +924,7 @@ static stlbrd_t *stl_allocbrd(void)
944 924
945 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL); 925 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
946 if (!brdp) { 926 if (!brdp) {
947 printk("STALLION: failed to allocate memory (size=%d)\n", 927 printk("STALLION: failed to allocate memory (size=%Zd)\n",
948 sizeof(stlbrd_t)); 928 sizeof(stlbrd_t));
949 return NULL; 929 return NULL;
950 } 930 }
@@ -1062,16 +1042,17 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1062 rc = 0; 1042 rc = 0;
1063 doclocal = 0; 1043 doclocal = 0;
1064 1044
1045 spin_lock_irqsave(&stallion_lock, flags);
1046
1065 if (portp->tty->termios->c_cflag & CLOCAL) 1047 if (portp->tty->termios->c_cflag & CLOCAL)
1066 doclocal++; 1048 doclocal++;
1067 1049
1068 save_flags(flags);
1069 cli();
1070 portp->openwaitcnt++; 1050 portp->openwaitcnt++;
1071 if (! tty_hung_up_p(filp)) 1051 if (! tty_hung_up_p(filp))
1072 portp->refcount--; 1052 portp->refcount--;
1073 1053
1074 for (;;) { 1054 for (;;) {
1055 /* Takes brd_lock internally */
1075 stl_setsignals(portp, 1, 1); 1056 stl_setsignals(portp, 1, 1);
1076 if (tty_hung_up_p(filp) || 1057 if (tty_hung_up_p(filp) ||
1077 ((portp->flags & ASYNC_INITIALIZED) == 0)) { 1058 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
@@ -1089,13 +1070,14 @@ static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1089 rc = -ERESTARTSYS; 1070 rc = -ERESTARTSYS;
1090 break; 1071 break;
1091 } 1072 }
1073 /* FIXME */
1092 interruptible_sleep_on(&portp->open_wait); 1074 interruptible_sleep_on(&portp->open_wait);
1093 } 1075 }
1094 1076
1095 if (! tty_hung_up_p(filp)) 1077 if (! tty_hung_up_p(filp))
1096 portp->refcount++; 1078 portp->refcount++;
1097 portp->openwaitcnt--; 1079 portp->openwaitcnt--;
1098 restore_flags(flags); 1080 spin_unlock_irqrestore(&stallion_lock, flags);
1099 1081
1100 return rc; 1082 return rc;
1101} 1083}
@@ -1115,16 +1097,15 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1115 if (portp == (stlport_t *) NULL) 1097 if (portp == (stlport_t *) NULL)
1116 return; 1098 return;
1117 1099
1118 save_flags(flags); 1100 spin_lock_irqsave(&stallion_lock, flags);
1119 cli();
1120 if (tty_hung_up_p(filp)) { 1101 if (tty_hung_up_p(filp)) {
1121 restore_flags(flags); 1102 spin_unlock_irqrestore(&stallion_lock, flags);
1122 return; 1103 return;
1123 } 1104 }
1124 if ((tty->count == 1) && (portp->refcount != 1)) 1105 if ((tty->count == 1) && (portp->refcount != 1))
1125 portp->refcount = 1; 1106 portp->refcount = 1;
1126 if (portp->refcount-- > 1) { 1107 if (portp->refcount-- > 1) {
1127 restore_flags(flags); 1108 spin_unlock_irqrestore(&stallion_lock, flags);
1128 return; 1109 return;
1129 } 1110 }
1130 1111
@@ -1138,11 +1119,18 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1138 * (The sc26198 has no "end-of-data" interrupt only empty FIFO) 1119 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1139 */ 1120 */
1140 tty->closing = 1; 1121 tty->closing = 1;
1122
1123 spin_unlock_irqrestore(&stallion_lock, flags);
1124
1141 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE) 1125 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1142 tty_wait_until_sent(tty, portp->closing_wait); 1126 tty_wait_until_sent(tty, portp->closing_wait);
1143 stl_waituntilsent(tty, (HZ / 2)); 1127 stl_waituntilsent(tty, (HZ / 2));
1144 1128
1129
1130 spin_lock_irqsave(&stallion_lock, flags);
1145 portp->flags &= ~ASYNC_INITIALIZED; 1131 portp->flags &= ~ASYNC_INITIALIZED;
1132 spin_unlock_irqrestore(&stallion_lock, flags);
1133
1146 stl_disableintrs(portp); 1134 stl_disableintrs(portp);
1147 if (tty->termios->c_cflag & HUPCL) 1135 if (tty->termios->c_cflag & HUPCL)
1148 stl_setsignals(portp, 0, 0); 1136 stl_setsignals(portp, 0, 0);
@@ -1169,7 +1157,6 @@ static void stl_close(struct tty_struct *tty, struct file *filp)
1169 1157
1170 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING); 1158 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1171 wake_up_interruptible(&portp->close_wait); 1159 wake_up_interruptible(&portp->close_wait);
1172 restore_flags(flags);
1173} 1160}
1174 1161
1175/*****************************************************************************/ 1162/*****************************************************************************/
@@ -1191,9 +1178,6 @@ static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count
1191 (int) tty, (int) buf, count); 1178 (int) tty, (int) buf, count);
1192#endif 1179#endif
1193 1180
1194 if ((tty == (struct tty_struct *) NULL) ||
1195 (stl_tmpwritebuf == (char *) NULL))
1196 return 0;
1197 portp = tty->driver_data; 1181 portp = tty->driver_data;
1198 if (portp == (stlport_t *) NULL) 1182 if (portp == (stlport_t *) NULL)
1199 return 0; 1183 return 0;
@@ -1298,11 +1282,6 @@ static void stl_flushchars(struct tty_struct *tty)
1298 if (portp->tx.buf == (char *) NULL) 1282 if (portp->tx.buf == (char *) NULL)
1299 return; 1283 return;
1300 1284
1301#if 0
1302 if (tty->stopped || tty->hw_stopped ||
1303 (portp->tx.head == portp->tx.tail))
1304 return;
1305#endif
1306 stl_startrxtx(portp, -1, 1); 1285 stl_startrxtx(portp, -1, 1);
1307} 1286}
1308 1287
@@ -1973,12 +1952,14 @@ static int stl_eiointr(stlbrd_t *brdp)
1973 unsigned int iobase; 1952 unsigned int iobase;
1974 int handled = 0; 1953 int handled = 0;
1975 1954
1955 spin_lock(&brd_lock);
1976 panelp = brdp->panels[0]; 1956 panelp = brdp->panels[0];
1977 iobase = panelp->iobase; 1957 iobase = panelp->iobase;
1978 while (inb(brdp->iostatus) & EIO_INTRPEND) { 1958 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1979 handled = 1; 1959 handled = 1;
1980 (* panelp->isr)(panelp, iobase); 1960 (* panelp->isr)(panelp, iobase);
1981 } 1961 }
1962 spin_unlock(&brd_lock);
1982 return handled; 1963 return handled;
1983} 1964}
1984 1965
@@ -2164,7 +2145,7 @@ static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2164 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL); 2145 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2165 if (!portp) { 2146 if (!portp) {
2166 printk("STALLION: failed to allocate memory " 2147 printk("STALLION: failed to allocate memory "
2167 "(size=%d)\n", sizeof(stlport_t)); 2148 "(size=%Zd)\n", sizeof(stlport_t));
2168 break; 2149 break;
2169 } 2150 }
2170 2151
@@ -2300,7 +2281,7 @@ static inline int stl_initeio(stlbrd_t *brdp)
2300 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2281 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2301 if (!panelp) { 2282 if (!panelp) {
2302 printk(KERN_WARNING "STALLION: failed to allocate memory " 2283 printk(KERN_WARNING "STALLION: failed to allocate memory "
2303 "(size=%d)\n", sizeof(stlpanel_t)); 2284 "(size=%Zd)\n", sizeof(stlpanel_t));
2304 return -ENOMEM; 2285 return -ENOMEM;
2305 } 2286 }
2306 2287
@@ -2474,7 +2455,7 @@ static inline int stl_initech(stlbrd_t *brdp)
2474 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL); 2455 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2475 if (!panelp) { 2456 if (!panelp) {
2476 printk("STALLION: failed to allocate memory " 2457 printk("STALLION: failed to allocate memory "
2477 "(size=%d)\n", sizeof(stlpanel_t)); 2458 "(size=%Zd)\n", sizeof(stlpanel_t));
2478 break; 2459 break;
2479 } 2460 }
2480 panelp->magic = STL_PANELMAGIC; 2461 panelp->magic = STL_PANELMAGIC;
@@ -2875,8 +2856,7 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2875 portp->stats.lflags = 0; 2856 portp->stats.lflags = 0;
2876 portp->stats.rxbuffered = 0; 2857 portp->stats.rxbuffered = 0;
2877 2858
2878 save_flags(flags); 2859 spin_lock_irqsave(&stallion_lock, flags);
2879 cli();
2880 if (portp->tty != (struct tty_struct *) NULL) { 2860 if (portp->tty != (struct tty_struct *) NULL) {
2881 if (portp->tty->driver_data == portp) { 2861 if (portp->tty->driver_data == portp) {
2882 portp->stats.ttystate = portp->tty->flags; 2862 portp->stats.ttystate = portp->tty->flags;
@@ -2890,7 +2870,7 @@ static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2890 } 2870 }
2891 } 2871 }
2892 } 2872 }
2893 restore_flags(flags); 2873 spin_unlock_irqrestore(&stallion_lock, flags);
2894 2874
2895 head = portp->tx.head; 2875 head = portp->tx.head;
2896 tail = portp->tx.tail; 2876 tail = portp->tx.tail;
@@ -3045,6 +3025,9 @@ static int __init stl_init(void)
3045 int i; 3025 int i;
3046 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion); 3026 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3047 3027
3028 spin_lock_init(&stallion_lock);
3029 spin_lock_init(&brd_lock);
3030
3048 stl_initbrds(); 3031 stl_initbrds();
3049 3032
3050 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS); 3033 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
@@ -3052,14 +3035,6 @@ static int __init stl_init(void)
3052 return -1; 3035 return -1;
3053 3036
3054/* 3037/*
3055 * Allocate a temporary write buffer.
3056 */
3057 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3058 if (!stl_tmpwritebuf)
3059 printk("STALLION: failed to allocate memory (size=%d)\n",
3060 STL_TXBUFSIZE);
3061
3062/*
3063 * Set up a character driver for per board stuff. This is mainly used 3038 * Set up a character driver for per board stuff. This is mainly used
3064 * to do stats ioctls on the ports. 3039 * to do stats ioctls on the ports.
3065 */ 3040 */
@@ -3137,11 +3112,13 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3137 unsigned int gfrcr; 3112 unsigned int gfrcr;
3138 int chipmask, i, j; 3113 int chipmask, i, j;
3139 int nrchips, uartaddr, ioaddr; 3114 int nrchips, uartaddr, ioaddr;
3115 unsigned long flags;
3140 3116
3141#ifdef DEBUG 3117#ifdef DEBUG
3142 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp); 3118 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3143#endif 3119#endif
3144 3120
3121 spin_lock_irqsave(&brd_lock, flags);
3145 BRDENABLE(panelp->brdnr, panelp->pagenr); 3122 BRDENABLE(panelp->brdnr, panelp->pagenr);
3146 3123
3147/* 3124/*
@@ -3179,6 +3156,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3179 } 3156 }
3180 3157
3181 BRDDISABLE(panelp->brdnr); 3158 BRDDISABLE(panelp->brdnr);
3159 spin_unlock_irqrestore(&brd_lock, flags);
3182 return chipmask; 3160 return chipmask;
3183} 3161}
3184 3162
@@ -3190,6 +3168,7 @@ static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3190 3168
3191static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp) 3169static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3192{ 3170{
3171 unsigned long flags;
3193#ifdef DEBUG 3172#ifdef DEBUG
3194 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n", 3173 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3195 (int) brdp, (int) panelp, (int) portp); 3174 (int) brdp, (int) panelp, (int) portp);
@@ -3199,6 +3178,7 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3199 (portp == (stlport_t *) NULL)) 3178 (portp == (stlport_t *) NULL))
3200 return; 3179 return;
3201 3180
3181 spin_lock_irqsave(&brd_lock, flags);
3202 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) || 3182 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3203 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE); 3183 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3204 portp->uartaddr = (portp->portnr & 0x04) << 5; 3184 portp->uartaddr = (portp->portnr & 0x04) << 5;
@@ -3209,6 +3189,7 @@ static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *po
3209 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3)); 3189 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3210 portp->hwid = stl_cd1400getreg(portp, GFRCR); 3190 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3211 BRDDISABLE(portp->brdnr); 3191 BRDDISABLE(portp->brdnr);
3192 spin_unlock_irqrestore(&brd_lock, flags);
3212} 3193}
3213 3194
3214/*****************************************************************************/ 3195/*****************************************************************************/
@@ -3418,8 +3399,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3418 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 3399 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3419#endif 3400#endif
3420 3401
3421 save_flags(flags); 3402 spin_lock_irqsave(&brd_lock, flags);
3422 cli();
3423 BRDENABLE(portp->brdnr, portp->pagenr); 3403 BRDENABLE(portp->brdnr, portp->pagenr);
3424 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3)); 3404 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3425 srer = stl_cd1400getreg(portp, SRER); 3405 srer = stl_cd1400getreg(portp, SRER);
@@ -3456,7 +3436,7 @@ static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3456 portp->sigs &= ~TIOCM_CD; 3436 portp->sigs &= ~TIOCM_CD;
3457 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron)); 3437 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3458 BRDDISABLE(portp->brdnr); 3438 BRDDISABLE(portp->brdnr);
3459 restore_flags(flags); 3439 spin_unlock_irqrestore(&brd_lock, flags);
3460} 3440}
3461 3441
3462/*****************************************************************************/ 3442/*****************************************************************************/
@@ -3482,8 +3462,7 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3482 if (rts > 0) 3462 if (rts > 0)
3483 msvr2 = MSVR2_RTS; 3463 msvr2 = MSVR2_RTS;
3484 3464
3485 save_flags(flags); 3465 spin_lock_irqsave(&brd_lock, flags);
3486 cli();
3487 BRDENABLE(portp->brdnr, portp->pagenr); 3466 BRDENABLE(portp->brdnr, portp->pagenr);
3488 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3467 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3489 if (rts >= 0) 3468 if (rts >= 0)
@@ -3491,7 +3470,7 @@ static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3491 if (dtr >= 0) 3470 if (dtr >= 0)
3492 stl_cd1400setreg(portp, MSVR1, msvr1); 3471 stl_cd1400setreg(portp, MSVR1, msvr1);
3493 BRDDISABLE(portp->brdnr); 3472 BRDDISABLE(portp->brdnr);
3494 restore_flags(flags); 3473 spin_unlock_irqrestore(&brd_lock, flags);
3495} 3474}
3496 3475
3497/*****************************************************************************/ 3476/*****************************************************************************/
@@ -3510,14 +3489,13 @@ static int stl_cd1400getsignals(stlport_t *portp)
3510 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp); 3489 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3511#endif 3490#endif
3512 3491
3513 save_flags(flags); 3492 spin_lock_irqsave(&brd_lock, flags);
3514 cli();
3515 BRDENABLE(portp->brdnr, portp->pagenr); 3493 BRDENABLE(portp->brdnr, portp->pagenr);
3516 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3494 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3517 msvr1 = stl_cd1400getreg(portp, MSVR1); 3495 msvr1 = stl_cd1400getreg(portp, MSVR1);
3518 msvr2 = stl_cd1400getreg(portp, MSVR2); 3496 msvr2 = stl_cd1400getreg(portp, MSVR2);
3519 BRDDISABLE(portp->brdnr); 3497 BRDDISABLE(portp->brdnr);
3520 restore_flags(flags); 3498 spin_unlock_irqrestore(&brd_lock, flags);
3521 3499
3522 sigs = 0; 3500 sigs = 0;
3523 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0; 3501 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
@@ -3559,15 +3537,14 @@ static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3559 else if (rx > 0) 3537 else if (rx > 0)
3560 ccr |= CCR_RXENABLE; 3538 ccr |= CCR_RXENABLE;
3561 3539
3562 save_flags(flags); 3540 spin_lock_irqsave(&brd_lock, flags);
3563 cli();
3564 BRDENABLE(portp->brdnr, portp->pagenr); 3541 BRDENABLE(portp->brdnr, portp->pagenr);
3565 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3542 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3566 stl_cd1400ccrwait(portp); 3543 stl_cd1400ccrwait(portp);
3567 stl_cd1400setreg(portp, CCR, ccr); 3544 stl_cd1400setreg(portp, CCR, ccr);
3568 stl_cd1400ccrwait(portp); 3545 stl_cd1400ccrwait(portp);
3569 BRDDISABLE(portp->brdnr); 3546 BRDDISABLE(portp->brdnr);
3570 restore_flags(flags); 3547 spin_unlock_irqrestore(&brd_lock, flags);
3571} 3548}
3572 3549
3573/*****************************************************************************/ 3550/*****************************************************************************/
@@ -3599,8 +3576,7 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3599 else if (rx > 0) 3576 else if (rx > 0)
3600 sreron |= SRER_RXDATA; 3577 sreron |= SRER_RXDATA;
3601 3578
3602 save_flags(flags); 3579 spin_lock_irqsave(&brd_lock, flags);
3603 cli();
3604 BRDENABLE(portp->brdnr, portp->pagenr); 3580 BRDENABLE(portp->brdnr, portp->pagenr);
3605 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3581 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3606 stl_cd1400setreg(portp, SRER, 3582 stl_cd1400setreg(portp, SRER,
@@ -3608,7 +3584,7 @@ static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3608 BRDDISABLE(portp->brdnr); 3584 BRDDISABLE(portp->brdnr);
3609 if (tx > 0) 3585 if (tx > 0)
3610 set_bit(ASYI_TXBUSY, &portp->istate); 3586 set_bit(ASYI_TXBUSY, &portp->istate);
3611 restore_flags(flags); 3587 spin_unlock_irqrestore(&brd_lock, flags);
3612} 3588}
3613 3589
3614/*****************************************************************************/ 3590/*****************************************************************************/
@@ -3624,13 +3600,12 @@ static void stl_cd1400disableintrs(stlport_t *portp)
3624#ifdef DEBUG 3600#ifdef DEBUG
3625 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp); 3601 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3626#endif 3602#endif
3627 save_flags(flags); 3603 spin_lock_irqsave(&brd_lock, flags);
3628 cli();
3629 BRDENABLE(portp->brdnr, portp->pagenr); 3604 BRDENABLE(portp->brdnr, portp->pagenr);
3630 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3605 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3631 stl_cd1400setreg(portp, SRER, 0); 3606 stl_cd1400setreg(portp, SRER, 0);
3632 BRDDISABLE(portp->brdnr); 3607 BRDDISABLE(portp->brdnr);
3633 restore_flags(flags); 3608 spin_unlock_irqrestore(&brd_lock, flags);
3634} 3609}
3635 3610
3636/*****************************************************************************/ 3611/*****************************************************************************/
@@ -3643,8 +3618,7 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3643 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len); 3618 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3644#endif 3619#endif
3645 3620
3646 save_flags(flags); 3621 spin_lock_irqsave(&brd_lock, flags);
3647 cli();
3648 BRDENABLE(portp->brdnr, portp->pagenr); 3622 BRDENABLE(portp->brdnr, portp->pagenr);
3649 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3623 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3650 stl_cd1400setreg(portp, SRER, 3624 stl_cd1400setreg(portp, SRER,
@@ -3654,7 +3628,7 @@ static void stl_cd1400sendbreak(stlport_t *portp, int len)
3654 portp->brklen = len; 3628 portp->brklen = len;
3655 if (len == 1) 3629 if (len == 1)
3656 portp->stats.txbreaks++; 3630 portp->stats.txbreaks++;
3657 restore_flags(flags); 3631 spin_unlock_irqrestore(&brd_lock, flags);
3658} 3632}
3659 3633
3660/*****************************************************************************/ 3634/*****************************************************************************/
@@ -3678,8 +3652,7 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3678 if (tty == (struct tty_struct *) NULL) 3652 if (tty == (struct tty_struct *) NULL)
3679 return; 3653 return;
3680 3654
3681 save_flags(flags); 3655 spin_lock_irqsave(&brd_lock, flags);
3682 cli();
3683 BRDENABLE(portp->brdnr, portp->pagenr); 3656 BRDENABLE(portp->brdnr, portp->pagenr);
3684 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3657 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3685 3658
@@ -3719,7 +3692,7 @@ static void stl_cd1400flowctrl(stlport_t *portp, int state)
3719 } 3692 }
3720 3693
3721 BRDDISABLE(portp->brdnr); 3694 BRDDISABLE(portp->brdnr);
3722 restore_flags(flags); 3695 spin_unlock_irqrestore(&brd_lock, flags);
3723} 3696}
3724 3697
3725/*****************************************************************************/ 3698/*****************************************************************************/
@@ -3743,8 +3716,7 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3743 if (tty == (struct tty_struct *) NULL) 3716 if (tty == (struct tty_struct *) NULL)
3744 return; 3717 return;
3745 3718
3746 save_flags(flags); 3719 spin_lock_irqsave(&brd_lock, flags);
3747 cli();
3748 BRDENABLE(portp->brdnr, portp->pagenr); 3720 BRDENABLE(portp->brdnr, portp->pagenr);
3749 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3721 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3750 if (state) { 3722 if (state) {
@@ -3759,7 +3731,7 @@ static void stl_cd1400sendflow(stlport_t *portp, int state)
3759 stl_cd1400ccrwait(portp); 3731 stl_cd1400ccrwait(portp);
3760 } 3732 }
3761 BRDDISABLE(portp->brdnr); 3733 BRDDISABLE(portp->brdnr);
3762 restore_flags(flags); 3734 spin_unlock_irqrestore(&brd_lock, flags);
3763} 3735}
3764 3736
3765/*****************************************************************************/ 3737/*****************************************************************************/
@@ -3775,8 +3747,7 @@ static void stl_cd1400flush(stlport_t *portp)
3775 if (portp == (stlport_t *) NULL) 3747 if (portp == (stlport_t *) NULL)
3776 return; 3748 return;
3777 3749
3778 save_flags(flags); 3750 spin_lock_irqsave(&brd_lock, flags);
3779 cli();
3780 BRDENABLE(portp->brdnr, portp->pagenr); 3751 BRDENABLE(portp->brdnr, portp->pagenr);
3781 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03)); 3752 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3782 stl_cd1400ccrwait(portp); 3753 stl_cd1400ccrwait(portp);
@@ -3784,7 +3755,7 @@ static void stl_cd1400flush(stlport_t *portp)
3784 stl_cd1400ccrwait(portp); 3755 stl_cd1400ccrwait(portp);
3785 portp->tx.tail = portp->tx.head; 3756 portp->tx.tail = portp->tx.head;
3786 BRDDISABLE(portp->brdnr); 3757 BRDDISABLE(portp->brdnr);
3787 restore_flags(flags); 3758 spin_unlock_irqrestore(&brd_lock, flags);
3788} 3759}
3789 3760
3790/*****************************************************************************/ 3761/*****************************************************************************/
@@ -3823,6 +3794,7 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3823 (int) panelp, iobase); 3794 (int) panelp, iobase);
3824#endif 3795#endif
3825 3796
3797 spin_lock(&brd_lock);
3826 outb(SVRR, iobase); 3798 outb(SVRR, iobase);
3827 svrtype = inb(iobase + EREG_DATA); 3799 svrtype = inb(iobase + EREG_DATA);
3828 if (panelp->nrports > 4) { 3800 if (panelp->nrports > 4) {
@@ -3836,6 +3808,8 @@ static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3836 stl_cd1400txisr(panelp, iobase); 3808 stl_cd1400txisr(panelp, iobase);
3837 else if (svrtype & SVRR_MDM) 3809 else if (svrtype & SVRR_MDM)
3838 stl_cd1400mdmisr(panelp, iobase); 3810 stl_cd1400mdmisr(panelp, iobase);
3811
3812 spin_unlock(&brd_lock);
3839} 3813}
3840 3814
3841/*****************************************************************************/ 3815/*****************************************************************************/
@@ -4423,8 +4397,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4423 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]); 4397 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4424#endif 4398#endif
4425 4399
4426 save_flags(flags); 4400 spin_lock_irqsave(&brd_lock, flags);
4427 cli();
4428 BRDENABLE(portp->brdnr, portp->pagenr); 4401 BRDENABLE(portp->brdnr, portp->pagenr);
4429 stl_sc26198setreg(portp, IMR, 0); 4402 stl_sc26198setreg(portp, IMR, 0);
4430 stl_sc26198updatereg(portp, MR0, mr0); 4403 stl_sc26198updatereg(portp, MR0, mr0);
@@ -4451,7 +4424,7 @@ static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4451 portp->imr = (portp->imr & ~imroff) | imron; 4424 portp->imr = (portp->imr & ~imroff) | imron;
4452 stl_sc26198setreg(portp, IMR, portp->imr); 4425 stl_sc26198setreg(portp, IMR, portp->imr);
4453 BRDDISABLE(portp->brdnr); 4426 BRDDISABLE(portp->brdnr);
4454 restore_flags(flags); 4427 spin_unlock_irqrestore(&brd_lock, flags);
4455} 4428}
4456 4429
4457/*****************************************************************************/ 4430/*****************************************************************************/
@@ -4481,13 +4454,12 @@ static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4481 else if (rts > 0) 4454 else if (rts > 0)
4482 iopioron |= IPR_RTS; 4455 iopioron |= IPR_RTS;
4483 4456
4484 save_flags(flags); 4457 spin_lock_irqsave(&brd_lock, flags);
4485 cli();
4486 BRDENABLE(portp->brdnr, portp->pagenr); 4458 BRDENABLE(portp->brdnr, portp->pagenr);
4487 stl_sc26198setreg(portp, IOPIOR, 4459 stl_sc26198setreg(portp, IOPIOR,
4488 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron)); 4460 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4489 BRDDISABLE(portp->brdnr); 4461 BRDDISABLE(portp->brdnr);
4490 restore_flags(flags); 4462 spin_unlock_irqrestore(&brd_lock, flags);
4491} 4463}
4492 4464
4493/*****************************************************************************/ 4465/*****************************************************************************/
@@ -4506,12 +4478,11 @@ static int stl_sc26198getsignals(stlport_t *portp)
4506 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp); 4478 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4507#endif 4479#endif
4508 4480
4509 save_flags(flags); 4481 spin_lock_irqsave(&brd_lock, flags);
4510 cli();
4511 BRDENABLE(portp->brdnr, portp->pagenr); 4482 BRDENABLE(portp->brdnr, portp->pagenr);
4512 ipr = stl_sc26198getreg(portp, IPR); 4483 ipr = stl_sc26198getreg(portp, IPR);
4513 BRDDISABLE(portp->brdnr); 4484 BRDDISABLE(portp->brdnr);
4514 restore_flags(flags); 4485 spin_unlock_irqrestore(&brd_lock, flags);
4515 4486
4516 sigs = 0; 4487 sigs = 0;
4517 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD; 4488 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
@@ -4548,13 +4519,12 @@ static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4548 else if (rx > 0) 4519 else if (rx > 0)
4549 ccr |= CR_RXENABLE; 4520 ccr |= CR_RXENABLE;
4550 4521
4551 save_flags(flags); 4522 spin_lock_irqsave(&brd_lock, flags);
4552 cli();
4553 BRDENABLE(portp->brdnr, portp->pagenr); 4523 BRDENABLE(portp->brdnr, portp->pagenr);
4554 stl_sc26198setreg(portp, SCCR, ccr); 4524 stl_sc26198setreg(portp, SCCR, ccr);
4555 BRDDISABLE(portp->brdnr); 4525 BRDDISABLE(portp->brdnr);
4556 portp->crenable = ccr; 4526 portp->crenable = ccr;
4557 restore_flags(flags); 4527 spin_unlock_irqrestore(&brd_lock, flags);
4558} 4528}
4559 4529
4560/*****************************************************************************/ 4530/*****************************************************************************/
@@ -4583,15 +4553,14 @@ static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4583 else if (rx > 0) 4553 else if (rx > 0)
4584 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG; 4554 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4585 4555
4586 save_flags(flags); 4556 spin_lock_irqsave(&brd_lock, flags);
4587 cli();
4588 BRDENABLE(portp->brdnr, portp->pagenr); 4557 BRDENABLE(portp->brdnr, portp->pagenr);
4589 stl_sc26198setreg(portp, IMR, imr); 4558 stl_sc26198setreg(portp, IMR, imr);
4590 BRDDISABLE(portp->brdnr); 4559 BRDDISABLE(portp->brdnr);
4591 portp->imr = imr; 4560 portp->imr = imr;
4592 if (tx > 0) 4561 if (tx > 0)
4593 set_bit(ASYI_TXBUSY, &portp->istate); 4562 set_bit(ASYI_TXBUSY, &portp->istate);
4594 restore_flags(flags); 4563 spin_unlock_irqrestore(&brd_lock, flags);
4595} 4564}
4596 4565
4597/*****************************************************************************/ 4566/*****************************************************************************/
@@ -4608,13 +4577,12 @@ static void stl_sc26198disableintrs(stlport_t *portp)
4608 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp); 4577 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4609#endif 4578#endif
4610 4579
4611 save_flags(flags); 4580 spin_lock_irqsave(&brd_lock, flags);
4612 cli();
4613 BRDENABLE(portp->brdnr, portp->pagenr); 4581 BRDENABLE(portp->brdnr, portp->pagenr);
4614 portp->imr = 0; 4582 portp->imr = 0;
4615 stl_sc26198setreg(portp, IMR, 0); 4583 stl_sc26198setreg(portp, IMR, 0);
4616 BRDDISABLE(portp->brdnr); 4584 BRDDISABLE(portp->brdnr);
4617 restore_flags(flags); 4585 spin_unlock_irqrestore(&brd_lock, flags);
4618} 4586}
4619 4587
4620/*****************************************************************************/ 4588/*****************************************************************************/
@@ -4627,8 +4595,7 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4627 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len); 4595 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4628#endif 4596#endif
4629 4597
4630 save_flags(flags); 4598 spin_lock_irqsave(&brd_lock, flags);
4631 cli();
4632 BRDENABLE(portp->brdnr, portp->pagenr); 4599 BRDENABLE(portp->brdnr, portp->pagenr);
4633 if (len == 1) { 4600 if (len == 1) {
4634 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK); 4601 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
@@ -4637,7 +4604,7 @@ static void stl_sc26198sendbreak(stlport_t *portp, int len)
4637 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK); 4604 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4638 } 4605 }
4639 BRDDISABLE(portp->brdnr); 4606 BRDDISABLE(portp->brdnr);
4640 restore_flags(flags); 4607 spin_unlock_irqrestore(&brd_lock, flags);
4641} 4608}
4642 4609
4643/*****************************************************************************/ 4610/*****************************************************************************/
@@ -4662,8 +4629,7 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4662 if (tty == (struct tty_struct *) NULL) 4629 if (tty == (struct tty_struct *) NULL)
4663 return; 4630 return;
4664 4631
4665 save_flags(flags); 4632 spin_lock_irqsave(&brd_lock, flags);
4666 cli();
4667 BRDENABLE(portp->brdnr, portp->pagenr); 4633 BRDENABLE(portp->brdnr, portp->pagenr);
4668 4634
4669 if (state) { 4635 if (state) {
@@ -4709,7 +4675,7 @@ static void stl_sc26198flowctrl(stlport_t *portp, int state)
4709 } 4675 }
4710 4676
4711 BRDDISABLE(portp->brdnr); 4677 BRDDISABLE(portp->brdnr);
4712 restore_flags(flags); 4678 spin_unlock_irqrestore(&brd_lock, flags);
4713} 4679}
4714 4680
4715/*****************************************************************************/ 4681/*****************************************************************************/
@@ -4734,8 +4700,7 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4734 if (tty == (struct tty_struct *) NULL) 4700 if (tty == (struct tty_struct *) NULL)
4735 return; 4701 return;
4736 4702
4737 save_flags(flags); 4703 spin_lock_irqsave(&brd_lock, flags);
4738 cli();
4739 BRDENABLE(portp->brdnr, portp->pagenr); 4704 BRDENABLE(portp->brdnr, portp->pagenr);
4740 if (state) { 4705 if (state) {
4741 mr0 = stl_sc26198getreg(portp, MR0); 4706 mr0 = stl_sc26198getreg(portp, MR0);
@@ -4755,7 +4720,7 @@ static void stl_sc26198sendflow(stlport_t *portp, int state)
4755 stl_sc26198setreg(portp, MR0, mr0); 4720 stl_sc26198setreg(portp, MR0, mr0);
4756 } 4721 }
4757 BRDDISABLE(portp->brdnr); 4722 BRDDISABLE(portp->brdnr);
4758 restore_flags(flags); 4723 spin_unlock_irqrestore(&brd_lock, flags);
4759} 4724}
4760 4725
4761/*****************************************************************************/ 4726/*****************************************************************************/
@@ -4771,14 +4736,13 @@ static void stl_sc26198flush(stlport_t *portp)
4771 if (portp == (stlport_t *) NULL) 4736 if (portp == (stlport_t *) NULL)
4772 return; 4737 return;
4773 4738
4774 save_flags(flags); 4739 spin_lock_irqsave(&brd_lock, flags);
4775 cli();
4776 BRDENABLE(portp->brdnr, portp->pagenr); 4740 BRDENABLE(portp->brdnr, portp->pagenr);
4777 stl_sc26198setreg(portp, SCCR, CR_TXRESET); 4741 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4778 stl_sc26198setreg(portp, SCCR, portp->crenable); 4742 stl_sc26198setreg(portp, SCCR, portp->crenable);
4779 BRDDISABLE(portp->brdnr); 4743 BRDDISABLE(portp->brdnr);
4780 portp->tx.tail = portp->tx.head; 4744 portp->tx.tail = portp->tx.head;
4781 restore_flags(flags); 4745 spin_unlock_irqrestore(&brd_lock, flags);
4782} 4746}
4783 4747
4784/*****************************************************************************/ 4748/*****************************************************************************/
@@ -4805,12 +4769,11 @@ static int stl_sc26198datastate(stlport_t *portp)
4805 if (test_bit(ASYI_TXBUSY, &portp->istate)) 4769 if (test_bit(ASYI_TXBUSY, &portp->istate))
4806 return 1; 4770 return 1;
4807 4771
4808 save_flags(flags); 4772 spin_lock_irqsave(&brd_lock, flags);
4809 cli();
4810 BRDENABLE(portp->brdnr, portp->pagenr); 4773 BRDENABLE(portp->brdnr, portp->pagenr);
4811 sr = stl_sc26198getreg(portp, SR); 4774 sr = stl_sc26198getreg(portp, SR);
4812 BRDDISABLE(portp->brdnr); 4775 BRDDISABLE(portp->brdnr);
4813 restore_flags(flags); 4776 spin_unlock_irqrestore(&brd_lock, flags);
4814 4777
4815 return (sr & SR_TXEMPTY) ? 0 : 1; 4778 return (sr & SR_TXEMPTY) ? 0 : 1;
4816} 4779}
@@ -4868,6 +4831,8 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4868 stlport_t *portp; 4831 stlport_t *portp;
4869 unsigned int iack; 4832 unsigned int iack;
4870 4833
4834 spin_lock(&brd_lock);
4835
4871/* 4836/*
4872 * Work around bug in sc26198 chip... Cannot have A6 address 4837 * Work around bug in sc26198 chip... Cannot have A6 address
4873 * line of UART high, else iack will be returned as 0. 4838 * line of UART high, else iack will be returned as 0.
@@ -4883,6 +4848,8 @@ static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4883 stl_sc26198txisr(portp); 4848 stl_sc26198txisr(portp);
4884 else 4849 else
4885 stl_sc26198otherisr(portp, iack); 4850 stl_sc26198otherisr(portp, iack);
4851
4852 spin_unlock(&brd_lock);
4886} 4853}
4887 4854
4888/*****************************************************************************/ 4855/*****************************************************************************/
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/tlclk.c b/drivers/char/tlclk.c
index f58ad7f68267..ef68d152d3e4 100644
--- a/drivers/char/tlclk.c
+++ b/drivers/char/tlclk.c
@@ -343,7 +343,7 @@ static ssize_t store_received_ref_clk3b(struct device *d,
343 343
344 val = (unsigned char)tmp; 344 val = (unsigned char)tmp;
345 spin_lock_irqsave(&event_lock, flags); 345 spin_lock_irqsave(&event_lock, flags);
346 SET_PORT_BITS(TLCLK_REG1, 0xef, val << 1); 346 SET_PORT_BITS(TLCLK_REG1, 0xdf, val << 1);
347 spin_unlock_irqrestore(&event_lock, flags); 347 spin_unlock_irqrestore(&event_lock, flags);
348 348
349 return strnlen(buf, count); 349 return strnlen(buf, count);
diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 6c79ff3030fa..a1143238feca 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -266,7 +266,6 @@ static struct tty_buffer *tty_buffer_alloc(size_t size)
266 p->used = 0; 266 p->used = 0;
267 p->size = size; 267 p->size = size;
268 p->next = NULL; 268 p->next = NULL;
269 p->active = 0;
270 p->commit = 0; 269 p->commit = 0;
271 p->read = 0; 270 p->read = 0;
272 p->char_buf_ptr = (char *)(p->data); 271 p->char_buf_ptr = (char *)(p->data);
@@ -326,10 +325,9 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
326 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to 325 /* OPTIMISATION: We could keep a per tty "zero" sized buffer to
327 remove this conditional if its worth it. This would be invisible 326 remove this conditional if its worth it. This would be invisible
328 to the callers */ 327 to the callers */
329 if ((b = tty->buf.tail) != NULL) { 328 if ((b = tty->buf.tail) != NULL)
330 left = b->size - b->used; 329 left = b->size - b->used;
331 b->active = 1; 330 else
332 } else
333 left = 0; 331 left = 0;
334 332
335 if (left < size) { 333 if (left < size) {
@@ -337,12 +335,10 @@ int tty_buffer_request_room(struct tty_struct *tty, size_t size)
337 if ((n = tty_buffer_find(tty, size)) != NULL) { 335 if ((n = tty_buffer_find(tty, size)) != NULL) {
338 if (b != NULL) { 336 if (b != NULL) {
339 b->next = n; 337 b->next = n;
340 b->active = 0;
341 b->commit = b->used; 338 b->commit = b->used;
342 } else 339 } else
343 tty->buf.head = n; 340 tty->buf.head = n;
344 tty->buf.tail = n; 341 tty->buf.tail = n;
345 n->active = 1;
346 } else 342 } else
347 size = left; 343 size = left;
348 } 344 }
@@ -403,10 +399,8 @@ void tty_schedule_flip(struct tty_struct *tty)
403{ 399{
404 unsigned long flags; 400 unsigned long flags;
405 spin_lock_irqsave(&tty->buf.lock, flags); 401 spin_lock_irqsave(&tty->buf.lock, flags);
406 if (tty->buf.tail != NULL) { 402 if (tty->buf.tail != NULL)
407 tty->buf.tail->active = 0;
408 tty->buf.tail->commit = tty->buf.tail->used; 403 tty->buf.tail->commit = tty->buf.tail->used;
409 }
410 spin_unlock_irqrestore(&tty->buf.lock, flags); 404 spin_unlock_irqrestore(&tty->buf.lock, flags);
411 schedule_delayed_work(&tty->buf.work, 1); 405 schedule_delayed_work(&tty->buf.work, 1);
412} 406}
@@ -783,11 +777,8 @@ restart:
783 } 777 }
784 778
785 clear_bit(TTY_LDISC, &tty->flags); 779 clear_bit(TTY_LDISC, &tty->flags);
786 clear_bit(TTY_DONT_FLIP, &tty->flags); 780 if (o_tty)
787 if (o_tty) {
788 clear_bit(TTY_LDISC, &o_tty->flags); 781 clear_bit(TTY_LDISC, &o_tty->flags);
789 clear_bit(TTY_DONT_FLIP, &o_tty->flags);
790 }
791 spin_unlock_irqrestore(&tty_ldisc_lock, flags); 782 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
792 783
793 /* 784 /*
@@ -1954,7 +1945,6 @@ static void release_dev(struct file * filp)
1954 * race with the set_ldisc code path. 1945 * race with the set_ldisc code path.
1955 */ 1946 */
1956 clear_bit(TTY_LDISC, &tty->flags); 1947 clear_bit(TTY_LDISC, &tty->flags);
1957 clear_bit(TTY_DONT_FLIP, &tty->flags);
1958 cancel_delayed_work(&tty->buf.work); 1948 cancel_delayed_work(&tty->buf.work);
1959 1949
1960 /* 1950 /*
@@ -2620,10 +2610,9 @@ int tty_ioctl(struct inode * inode, struct file * file,
2620 tty->driver->break_ctl(tty, 0); 2610 tty->driver->break_ctl(tty, 0);
2621 return 0; 2611 return 0;
2622 case TCSBRK: /* SVID version: non-zero arg --> no break */ 2612 case TCSBRK: /* SVID version: non-zero arg --> no break */
2623 /* 2613 /* non-zero arg means wait for all output data
2624 * XXX is the above comment correct, or the 2614 * to be sent (performed above) but don't send break.
2625 * code below correct? Is this ioctl used at 2615 * This is used by the tcdrain() termios function.
2626 * all by anyone?
2627 */ 2616 */
2628 if (!arg) 2617 if (!arg)
2629 return send_break(tty, 250); 2618 return send_break(tty, 250);
@@ -2775,8 +2764,7 @@ static void flush_to_ldisc(void *private_)
2775 struct tty_struct *tty = (struct tty_struct *) private_; 2764 struct tty_struct *tty = (struct tty_struct *) private_;
2776 unsigned long flags; 2765 unsigned long flags;
2777 struct tty_ldisc *disc; 2766 struct tty_ldisc *disc;
2778 struct tty_buffer *tbuf; 2767 struct tty_buffer *tbuf, *head;
2779 int count;
2780 char *char_buf; 2768 char *char_buf;
2781 unsigned char *flag_buf; 2769 unsigned char *flag_buf;
2782 2770
@@ -2784,32 +2772,37 @@ static void flush_to_ldisc(void *private_)
2784 if (disc == NULL) /* !TTY_LDISC */ 2772 if (disc == NULL) /* !TTY_LDISC */
2785 return; 2773 return;
2786 2774
2787 if (test_bit(TTY_DONT_FLIP, &tty->flags)) {
2788 /*
2789 * Do it after the next timer tick:
2790 */
2791 schedule_delayed_work(&tty->buf.work, 1);
2792 goto out;
2793 }
2794 spin_lock_irqsave(&tty->buf.lock, flags); 2775 spin_lock_irqsave(&tty->buf.lock, flags);
2795 while((tbuf = tty->buf.head) != NULL) { 2776 head = tty->buf.head;
2796 while ((count = tbuf->commit - tbuf->read) != 0) { 2777 if (head != NULL) {
2797 char_buf = tbuf->char_buf_ptr + tbuf->read; 2778 tty->buf.head = NULL;
2798 flag_buf = tbuf->flag_buf_ptr + tbuf->read; 2779 for (;;) {
2799 tbuf->read += count; 2780 int count = head->commit - head->read;
2781 if (!count) {
2782 if (head->next == NULL)
2783 break;
2784 tbuf = head;
2785 head = head->next;
2786 tty_buffer_free(tty, tbuf);
2787 continue;
2788 }
2789 if (!tty->receive_room) {
2790 schedule_delayed_work(&tty->buf.work, 1);
2791 break;
2792 }
2793 if (count > tty->receive_room)
2794 count = tty->receive_room;
2795 char_buf = head->char_buf_ptr + head->read;
2796 flag_buf = head->flag_buf_ptr + head->read;
2797 head->read += count;
2800 spin_unlock_irqrestore(&tty->buf.lock, flags); 2798 spin_unlock_irqrestore(&tty->buf.lock, flags);
2801 disc->receive_buf(tty, char_buf, flag_buf, count); 2799 disc->receive_buf(tty, char_buf, flag_buf, count);
2802 spin_lock_irqsave(&tty->buf.lock, flags); 2800 spin_lock_irqsave(&tty->buf.lock, flags);
2803 } 2801 }
2804 if (tbuf->active) 2802 tty->buf.head = head;
2805 break;
2806 tty->buf.head = tbuf->next;
2807 if (tty->buf.head == NULL)
2808 tty->buf.tail = NULL;
2809 tty_buffer_free(tty, tbuf);
2810 } 2803 }
2811 spin_unlock_irqrestore(&tty->buf.lock, flags); 2804 spin_unlock_irqrestore(&tty->buf.lock, flags);
2812out: 2805
2813 tty_ldisc_deref(disc); 2806 tty_ldisc_deref(disc);
2814} 2807}
2815 2808
@@ -2902,10 +2895,8 @@ void tty_flip_buffer_push(struct tty_struct *tty)
2902{ 2895{
2903 unsigned long flags; 2896 unsigned long flags;
2904 spin_lock_irqsave(&tty->buf.lock, flags); 2897 spin_lock_irqsave(&tty->buf.lock, flags);
2905 if (tty->buf.tail != NULL) { 2898 if (tty->buf.tail != NULL)
2906 tty->buf.tail->active = 0;
2907 tty->buf.tail->commit = tty->buf.tail->used; 2899 tty->buf.tail->commit = tty->buf.tail->used;
2908 }
2909 spin_unlock_irqrestore(&tty->buf.lock, flags); 2900 spin_unlock_irqrestore(&tty->buf.lock, flags);
2910 2901
2911 if (tty->low_latency) 2902 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 }