3 #undef Z_EXT_CHARS_IN_BUFFER
4 static char rcsid[] = "$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
7 * linux/drivers/char/cyclades.c
9 * This file contains the driver for the Cyclades async multiport
12 * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
13 * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
14 * Currently maintained by Cyclades team <async@cyclades.com>.
16 * For Technical support and installation problems, please send e-mail
17 * to support@cyclades.com.
19 * Much of the design and some of the code came from serial.c
20 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
21 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
22 * and then fixed as suggested by Michael K. Johnson 12/12/92.
24 * This version supports shared IRQ's (only for PCI boards).
26 * $Log: cyclades.c,v $
27 * Prevent users from opening non-existing Z ports.
29 * Revision 2.3.2.8 2000/07/06 18:14:16 ivan
30 * Fixed the PCI detection function to work properly on Alpha systems.
31 * Implemented support for TIOCSERGETLSR ioctl.
32 * Implemented full support for non-standard baud rates.
34 * Revision 2.3.2.7 2000/06/01 18:26:34 ivan
35 * Request PLX I/O region, although driver doesn't use it, to avoid
36 * problems with other drivers accessing it.
37 * Removed count for on-board buffer characters in cy_chars_in_buffer
40 * Revision 2.3.2.6 2000/05/05 13:56:05 ivan
41 * Driver now reports physical instead of virtual memory addresses.
42 * Masks were added to some Cyclades-Z read accesses.
43 * Implemented workaround for PLX9050 bug that would cause a system lockup
44 * in certain systems, depending on the MMIO addresses allocated to the
46 * Changed the Tx interrupt programming in the CD1400 chips to boost up
47 * performance (Cyclom-Y only).
48 * Code is now compliant with the new module interface (module_[init|exit]).
49 * Make use of the PCI helper functions to access PCI resources.
50 * Did some code "housekeeping".
52 * Revision 2.3.2.5 2000/01/19 14:35:33 ivan
53 * Fixed bug in cy_set_termios on CRTSCTS flag turnoff.
55 * Revision 2.3.2.4 2000/01/17 09:19:40 ivan
56 * Fixed SMP locking in Cyclom-Y interrupt handler.
58 * Revision 2.3.2.3 1999/12/28 12:11:39 ivan
59 * Added a new cyclades_card field called nports to allow the driver to
60 * know the exact number of ports found by the Z firmware after its load;
61 * RX buffer contention prevention logic on interrupt op mode revisited
63 * Revisited printk's for Z debug;
64 * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
66 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
67 * Fixed bug in cyz_poll that would make all ports but port 0
68 * unable to transmit/receive data (Cyclades-Z only);
69 * Implemented logic to prevent the RX buffer from being stuck with data
70 * due to a driver / firmware race condition in interrupt op mode
72 * Fixed bug in block_til_ready logic that would lead to a system crash;
73 * Revisited cy_close spinlock usage;
75 * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
76 * Revisited CONFIG_PCI conditional compilation for PCI board support;
77 * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
78 * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
79 * Removed CTS handling from the driver -- this is now completely handled
80 * by the firmware (Cyclades-Z only);
81 * Flush RX on-board buffers on a port open (Cyclades-Z only);
82 * Fixed handling of ASYNC_SPD_* TTY flags;
83 * Module unload now unmaps all memory area allocated by ioremap;
85 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
86 * Removed CY_PROC conditional compilation;
87 * Implemented SMP-awareness for the driver;
88 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
90 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
91 * (irq=NN) as parameters (only for ISA boards);
92 * Fixed bug in set_line_char that would prevent the Cyclades-Z
93 * ports from being configured at speeds above 115.2Kbps;
94 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
95 * switching from working properly;
96 * The driver now only prints IRQ info for the Cyclades-Z if it's
97 * configured to work in interrupt mode;
99 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
100 * Added support for interrupt mode operation for the Z cards;
101 * Removed the driver inactivity control for the Z;
102 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
103 * the Z firmware is not loaded yet;
104 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
105 * same functionality;
106 * Implemented workaround for IRQ setting loss on the PCI configuration
107 * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
109 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
110 * /proc entry location changed to /proc/tty/driver/cyclades;
111 * Added support to shared IRQ's (only for PCI boards);
112 * Added support for Cobalt Qube2 systems;
113 * IRQ [de]allocation scheme revisited;
114 * BREAK implementation changed in order to make use of the 'break_ctl'
116 * Fixed typo in TTY structure field 'driver_name';
117 * Included a PCI bridge reset and EEPROM reload in the board
118 * initialization code (for both Y and Z series).
120 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
121 * Fixed a bug in cy_wait_until_sent that was preventing the port to be
122 * closed properly after a SIGINT;
123 * Module usage counter scheme revisited;
124 * Added support to the upcoming Y PCI boards (i.e., support to additional
127 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
128 * Removed all unnecessary page-alignement operations in ioremap calls
129 * (ioremap is currently safe for these operations).
131 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
132 * Changed access to PLX PCI bridge registers from I/O to MMIO, in
133 * order to make PLX9050-based boards work with certain motherboards.
135 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
136 * cy_close function now resets (correctly) the tty->closing flag;
137 * JIFFIES_DIFF macro fixed.
139 * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
140 * Fixed bug in cy_close function, which was not informing HW of
141 * which port should have the reception disabled before doing so;
142 * fixed Cyclom-8YoP hardware detection bug.
144 * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
145 * Fixed bug in cy_close function, which causes malfunction
146 * of one of the first 4 ports when a higher port is closed
149 * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
150 * Fixed Cyclom-4Yo hardware detection bug.
152 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
153 * /proc/cyclades implementation with great collaboration of
154 * Marc Lewis <marc@blarg.net>;
155 * cyy_interrupt was changed to avoid occurrence of kernel oopses
156 * during PPP operation.
158 * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
159 * General code review in order to comply with 2.1 kernel standards;
160 * data loss prevention for slow devices revisited (cy_wait_until_sent
162 * removed conditional compilation for new/old PCI structure support
163 * (now the driver only supports the new PCI structure).
165 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
166 * added conditional compilation for new/old PCI structure support;
167 * removed kernel series (2.0.x / 2.1.x) conditional compilation.
169 * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
170 * cleaned up the data loss fix;
171 * fixed XON/XOFF handling once more (Cyclades-Z);
172 * general review of the driver routines;
173 * introduction of a mechanism to prevent data loss with slow
174 * printers, by forcing a delay before closing the port.
176 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
177 * fixed detection/handling of new CD1400 in Ye boards;
178 * fixed XON/XOFF handling (Cyclades-Z);
179 * fixed data loss caused by a premature port close;
180 * introduction of a flag that holds the CD1400 version ID per port
181 * (used by the CYGETCD1400VER new ioctl).
183 * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
184 * Code review for the module cleanup routine;
185 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
186 * includes anonymous changes regarding signal_pending.
188 * Revision 2.1 1997/11/01 17:42:41 ivan
189 * Changes in the driver to support Alpha systems (except 8Zo V_1);
190 * BREAK fix for the Cyclades-Z boards;
191 * driver inactivity control by FW implemented;
192 * introduction of flag that allows driver to take advantage of
193 * a special CD1400 feature related to HW flow control;
194 * added support for the CD1400 rev. J (Cyclom-Y boards);
195 * introduction of ioctls to:
196 * - control the rtsdtr_inv flag (Cyclom-Y);
197 * - control the rflow flag (Cyclom-Y);
198 * - adjust the polling interval (Cyclades-Z);
200 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
201 * Fixes related to kernel version conditional
204 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
205 * Compatibility issues between kernels 2.0.x and
206 * 2.1.x (mainly related to clear_bit function).
208 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
209 * Changes to define the memory window according to the
212 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
213 * Changes to support new cycladesZ boards.
215 * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
216 * Merge of Bentson's and Daniel's version 1.36.4.28.
217 * Corrects bug in cy_detect_pci: check if there are more
218 * ports than the number of static structs allocated.
219 * Warning message during initialization if this driver is
220 * used with the new generation of cycladesZ boards. Those
221 * will be supported only in next release of the driver.
222 * Corrects bug in cy_detect_pci and cy_detect_isa that
223 * returned wrong number of VALID boards, when a cyclomY
224 * was found with no serial modules connected.
225 * Changes to use current (2.1.x) kernel subroutine names
226 * and created macros for compilation with 2.0.x kernel,
227 * instead of the other way around.
229 * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
230 * Change queue_task_irq_off to queue_task_irq.
231 * The inline function queue_task_irq_off (tqueue.h)
232 * was removed from latest releases of 2.1.x kernel.
233 * Use of macro __init to mark the initialization
234 * routines, so memory can be reused.
235 * Also incorporate implementation of critical region
236 * in function cleanup_module() created by anonymous
239 * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
240 * Change to support new firmware that solves DCD problem:
241 * application could fail to receive SIGHUP signal when DCD
244 * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
245 * Changed for support linux versions 2.1.X.
246 * Backward compatible with linux versions 2.0.X.
247 * Corrected illegal use of filler field in
249 * Deleted some debug messages.
251 * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
252 * Included check for NULL tty pointer in cyz_poll.
254 * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
255 * Bill Foster at Blarg! Online services noticed that
256 * some of the switch elements of -Z modem control
257 * lacked a closing "break;"
259 * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
260 * Changed low water threshold for buffer xmit_buf
262 * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
263 * Marcio provided fix to modem status fetch for -Z
265 * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
266 * improve mapping of -Z control page (thanks to Steve
267 * Price <stevep@fa.tdktca.com> for help on this)
269 * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
270 * shift from CPU-bound to memcopy in cyz_polling operation
272 * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
273 * Added support to set and report higher speeds.
275 * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
276 * Some fixes in the HW flow control for the BETA release.
277 * Don't try to register the IRQ.
279 * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
280 * make sure "cyc" appears in all kernel messages; all soft interrupts
281 * handled by same routine; recognize out-of-band reception; comment
282 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
283 * fix race condition in -Z buffer management; only -Y needs to explicitly
284 * flush chars; tidy up some startup messages;
286 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
287 * shift MOD_INC_USE_COUNT location to match
288 * serial.c; purge some diagnostic messages;
290 * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
291 * enable modem status messages and fetch & process them; note
292 * time of last activity type for each port; set_line_char now
293 * supports more than line 0 and treats 0 baud correctly;
294 * get_modem_info senses rs_status;
296 * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
297 * barely works--now's time to turn on
298 * more features 'til it breaks
300 * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
301 * check more -Z board status; shorten boot message
303 * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
304 * fix reference to ch_ctrl in startup; verify return
305 * values from cyz_issue_cmd and cyz_update_channel;
306 * more stuff to get modem control correct;
308 * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
309 * more -Z stuff folded in; re-order changes to put -Z stuff
310 * after -Y stuff (to make changes clearer)
312 * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
313 * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
314 * Add code to send break. Clear firmware ID word at startup (so
315 * that other code won't talk to inactive board).
317 * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
318 * add code for -Z in set_line_char
320 * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
321 * fold more -Z stuff (or in some cases, error messages)
322 * into driver; add text to "don't know what to do" messages.
324 * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
325 * moved compile-time flags near top of file; cosmetic changes
326 * to narrow text (to allow 2-up printing); changed many declarations
327 * to "static" to limit external symbols; shuffled code order to
328 * coalesce -Y and -Z specific code, also to put internal functions
329 * in order of tty_driver structure; added code to recognize -Z
330 * ports (and for moment, do nothing or report error); add cy_startup
331 * to parse boot command line for extra base addresses for ISA probes;
333 * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
334 * reorder some code, fix types of some vars (int vs. long),
335 * add cy_setup to support user declared ISA addresses
337 * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
338 * dump ioctl based firmware load (it's now a user level
339 * program); ensure uninitialzed ports cannot be used
341 * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
342 * rename vars and restructure some code
344 * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
345 * get right status back after boot load
347 * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
348 * successfully loads firmware
350 * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
351 * add more of the code for the boot/load ioctls
353 * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
354 * start to add Z functionality--starting with ioctl
355 * for loading firmware
357 * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
358 * added code to recognize Z/PCI card at initialization; report
359 * presence, but card is not initialized (because firmware needs
362 * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
363 * starting minor number at zero; added missing verify_area
364 * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
366 * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
367 * remove unneeded boot message & fix CLOCAL hardware flow
368 * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
369 * remove unused diagnostic statements; minor 0 is first;
371 * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
372 * The kernel function vremap (available only in later 1.3.xx kernels)
373 * allows the access to memory addresses above the RAM. This revision
374 * of the driver supports PCI boards below 1Mb (device id 0x100) and
375 * above 1Mb (device id 0x101).
377 * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
378 * Some global changes to interrupt handling spilled into
379 * this driver--mostly unused arguments in system function
380 * calls. Also added change by Marcio Saito which should
381 * reduce lost interrupts at startup by fast processors.
383 * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
384 * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
385 * in 1.3.41 kernel to remove a possible race condition, extend
386 * some error messages, and let the driver run as a loadable module
387 * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
388 * possible race condition.
389 * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
391 * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
392 * Changes by Linus Torvalds in 1.3.33 kernel distribution
393 * required due to reordering of driver initialization.
394 * Drivers are now initialized *after* memory management.
396 * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
397 * remove printk from ISR; fix typo
399 * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
400 * Minor fixes in the PCI board support. PCI function calls in
401 * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
402 * <duncan@okay.com>. "bad serial count" message removed.
404 * Revision 1.36.3 1995/08/22 09:19:42 marcio
405 * Cyclom-Y/PCI support added. Changes in the cy_init routine and
406 * board initialization. Changes in the boot messages. The driver
407 * supports up to 4 boards and 64 ports by default.
409 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
410 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
412 * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
413 * add missing break in modem control block in ioctl switch statement
414 * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
416 * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
417 * make sure CTS flow control is set as soon as possible (thanks
418 * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
420 * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
421 * initialize defaults for receive threshold and stale data timeout;
424 * Revision 1.36 1995/03/10 23:33:53 bentson
425 * added support of chips 4-7 in 32 port Cyclom-Ye;
426 * fix cy_interrupt pointer dereference problem
427 * (Joe Portman <baron@aa.net>);
428 * give better error response if open is attempted on non-existent port
429 * (Zachariah Vaum <jchryslr@netcom.com>);
430 * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
431 * conditional compilation for -16Y on systems with fast, noisy bus;
432 * comment out diagnostic print function;
433 * cleaned up table of base addresses;
434 * set receiver time-out period register to correct value,
435 * set receive threshold to better default values,
436 * set chip timer to more accurate 200 Hz ticking,
437 * add code to monitor and modify receive parameters
438 * (Rik Faith <faith@cs.unc.edu> Nick Simicich
439 * <njs@scifi.emi.net>);
441 * Revision 1.35 1994/12/16 13:54:18 steffen
442 * additional patch by Marcio Saito for board detection
443 * Accidently left out in 1.34
445 * Revision 1.34 1994/12/10 12:37:12 steffen
446 * This is the corrected version as suggested by Marcio Saito
448 * Revision 1.33 1994/12/01 22:41:18 bentson
449 * add hooks to support more high speeds directly; add tytso
450 * patch regarding CLOCAL wakeups
452 * Revision 1.32 1994/11/23 19:50:04 bentson
453 * allow direct kernel control of higher signalling rates;
454 * look for cards at additional locations
456 * Revision 1.31 1994/11/16 04:33:28 bentson
457 * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
458 * a problem in chars_in_buffer has been resolved by some
459 * small changes; this should yield smoother output
461 * Revision 1.30 1994/11/16 04:28:05 bentson
462 * Fix from Corey Minyard, Internet: minyard@metronet.com,
463 * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
464 * cy_hangup that appears to clear up much (all?) of the
465 * DTR glitches; also he's added/cleaned-up diagnostic messages
467 * Revision 1.29 1994/11/16 04:16:07 bentson
468 * add change proposed by Ralph Sims, ralphs@halcyon.com, to
469 * operate higher speeds in same way as other serial ports;
470 * add more serial ports (for up to two 16-port muxes).
472 * Revision 1.28 1994/11/04 00:13:16 root
473 * turn off diagnostic messages
475 * Revision 1.27 1994/11/03 23:46:37 root
476 * bunch of changes to bring driver into greater conformance
477 * with the serial.c driver (looking for missed fixes)
479 * Revision 1.26 1994/11/03 22:40:36 root
480 * automatic interrupt probing fixed.
482 * Revision 1.25 1994/11/03 20:17:02 root
483 * start to implement auto-irq
485 * Revision 1.24 1994/11/03 18:01:55 root
486 * still working on modem signals--trying not to drop DTR
487 * during the getty/login processes
489 * Revision 1.23 1994/11/03 17:51:36 root
490 * extend baud rate support; set receive threshold as function
491 * of baud rate; fix some problems with RTS/CTS;
493 * Revision 1.22 1994/11/02 18:05:35 root
494 * changed arguments to udelay to type long to get
495 * delays to be of correct duration
497 * Revision 1.21 1994/11/02 17:37:30 root
498 * employ udelay (after calibrating loops_per_second earlier
499 * in init/main.c) instead of using home-grown delay routines
501 * Revision 1.20 1994/11/02 03:11:38 root
502 * cy_chars_in_buffer forces a return value of 0 to let
503 * login work (don't know why it does); some functions
504 * that were returning EFAULT, now executes the code;
505 * more work on deciding when to disable xmit interrupts;
507 * Revision 1.19 1994/11/01 20:10:14 root
508 * define routine to start transmission interrupts (by enabling
509 * transmit interrupts); directly enable/disable modem interrupts;
511 * Revision 1.18 1994/11/01 18:40:45 bentson
512 * Don't always enable transmit interrupts in startup; interrupt on
513 * TxMpty instead of TxRdy to help characters get out before shutdown;
514 * restructure xmit interrupt to check for chars first and quit if
515 * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
518 * Revision 1.17 1994/10/30 04:39:45 bentson
519 * rename serial_driver and callout_driver to cy_serial_driver and
520 * cy_callout_driver to avoid linkage interference; initialize
521 * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
522 * from cyclades_port structure; add paranoia check to cy_close;
524 * Revision 1.16 1994/10/30 01:14:33 bentson
525 * change major numbers; add some _early_ return statements;
527 * Revision 1.15 1994/10/29 06:43:15 bentson
528 * final tidying up for clean compile; enable some error reporting
530 * Revision 1.14 1994/10/28 20:30:22 Bentson
531 * lots of changes to drag the driver towards the new tty_io
532 * structures and operation. not expected to work, but may
535 * Revision 1.13 1994/07/21 23:08:57 Bentson
536 * add some diagnostic cruft; support 24 lines (for testing
537 * both -8Y and -16Y cards; be more thorough in servicing all
538 * chips during interrupt; add "volatile" a few places to
539 * circumvent compiler optimizations; fix base & offset
540 * computations in block_til_ready (was causing chip 0 to
543 * Revision 1.12 1994/07/19 16:42:11 Bentson
544 * add some hackery for kernel version 1.1.8; expand
545 * error messages; refine timing for delay loops and
546 * declare loop params volatile
548 * Revision 1.11 1994/06/11 21:53:10 bentson
549 * get use of save_car right in transmit interrupt service
551 * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
552 * add some diagnostic printing; try to fix save_car stuff
554 * Revision 1.10 1994/06/11 20:36:08 bentson
555 * clean up compiler warnings
557 * Revision 1.9 1994/06/11 19:42:46 bentson
558 * added a bunch of code to support modem signalling
560 * Revision 1.8 1994/06/11 17:57:07 bentson
561 * recognize break & parity error
563 * Revision 1.7 1994/06/05 05:51:34 bentson
564 * Reorder baud table to be monotonic; add cli to CP; discard
565 * incoming characters and status if the line isn't open; start to
566 * fold code into cy_throttle; start to port get_serial_info,
567 * set_serial_info, get_modem_info, set_modem_info, and send_break
568 * from serial.c; expand cy_ioctl; relocate and expand config_setup;
569 * get flow control characters from tty struct; invalidate ports w/o
572 * Revision 1.6 1994/05/31 18:42:21 bentson
573 * add a loop-breaker in the interrupt service routine;
574 * note when port is initialized so that it can be shut
575 * down under the right conditions; receive works without
578 * Revision 1.5 1994/05/30 00:55:02 bentson
579 * transmit works without obvious errors
581 * Revision 1.4 1994/05/27 18:46:27 bentson
582 * incorporated more code from lib_y.c; can now print short
583 * strings under interrupt control to port zero; seems to
584 * select ports/channels/lines correctly
586 * Revision 1.3 1994/05/25 22:12:44 bentson
587 * shifting from multi-port on a card to proper multiplexor
588 * data structures; added skeletons of most routines
590 * Revision 1.2 1994/05/19 13:21:43 bentson
591 * start to crib from other sources
595 /* If you need to install more boards than NR_CARDS, change the constant
596 in the definition below. No other change is necessary to support up to
597 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
602 If the total number of ports is larger than NR_PORTS, change this
603 constant in the definition below. No other change is necessary to
604 support more boards/ports. */
608 #define ZE_V1_NPORTS 64
613 #define SERIAL_PARANOIA_CHECK
615 #undef CY_DEBUG_THROTTLE
616 #undef CY_DEBUG_OTHER
618 #undef CY_DEBUG_COUNT
620 #undef CY_DEBUG_WAIT_UNTIL_SENT
621 #undef CY_DEBUG_INTERRUPTS
623 #undef CY_ENABLE_MONITORING
627 #define PAUSE __asm__("nop");
635 #include <linux/module.h>
636 #include <linux/errno.h>
637 #include <linux/signal.h>
638 #include <linux/sched.h>
639 #include <linux/timer.h>
640 #include <linux/interrupt.h>
641 #include <linux/tty.h>
642 #include <linux/tty_flip.h>
643 #include <linux/serial.h>
644 #include <linux/major.h>
645 #include <linux/string.h>
646 #include <linux/fcntl.h>
647 #include <linux/ptrace.h>
648 #include <linux/cyclades.h>
649 #include <linux/mm.h>
650 #include <linux/ioport.h>
651 #include <linux/init.h>
652 #include <linux/delay.h>
653 #include <linux/spinlock.h>
654 #include <linux/bitops.h>
656 #include <asm/system.h>
659 #include <asm/uaccess.h>
661 #define CY_LOCK(info,flags) \
663 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
666 #define CY_UNLOCK(info,flags) \
668 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
671 #include <linux/types.h>
672 #include <linux/kernel.h>
673 #include <linux/pci.h>
675 #include <linux/stat.h>
676 #include <linux/proc_fs.h>
678 static void cy_throttle(struct tty_struct *tty);
679 static void cy_send_xchar(struct tty_struct *tty, char ch);
681 #define IS_CYC_Z(card) ((card).num_chips == -1)
683 #define Z_FPGA_CHECK(card) \
684 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
685 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
687 #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
688 ((card).ctl_addr))->mail_box_0)) || \
689 Z_FPGA_CHECK(card)) && \
690 (ZFIRM_ID==cy_readl(&((struct FIRM_ID __iomem *) \
691 ((card).base_addr+ID_ADDRESS))->signature)))
693 #ifndef SERIAL_XMIT_SIZE
694 #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
696 #define WAKEUP_CHARS 256
698 #define STD_COM_FLAGS (0)
700 #define JIFFIES_DIFF(n, j) ((j) - (n))
702 static struct tty_driver *cy_serial_driver;
705 /* This is the address lookup table. The driver will probe for
706 Cyclom-Y/ISA boards at all addresses in here. If you want the
707 driver to probe addresses at a different address, add it to
708 this table. If the driver is probing some other board and
709 causing problems, remove the offending address from this table.
710 The cy_setup function extracts additional addresses from the
711 boot options line. The form is "cyclades=address,address..."
714 static unsigned int cy_isa_addresses[] = {
723 0, 0, 0, 0, 0, 0, 0, 0
726 #define NR_ISA_ADDRS ARRAY_SIZE(cy_isa_addresses)
729 static long maddr[NR_CARDS] = { 0, };
730 static int irq[NR_CARDS] = { 0, };
732 module_param_array(maddr, long, NULL, 0);
733 module_param_array(irq, int, NULL, 0);
736 #endif /* CONFIG_ISA */
738 /* This is the per-card data structure containing address, irq, number of
739 channels, etc. This driver supports a maximum of NR_CARDS cards.
741 static struct cyclades_card cy_card[NR_CARDS];
743 /* This is the per-channel data structure containing pointers, flags
744 and variables for the port. This driver supports a maximum of NR_PORTS.
746 static struct cyclades_port cy_port[NR_PORTS];
748 static int cy_next_channel; /* next minor available */
751 * This is used to look up the divisor speeds and the timeouts
752 * We're normally limited to 15 distinct baud rates. The extra
753 * are accessed via settings in info->flags.
754 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
755 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
759 static int baud_table[] = {
760 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
761 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800, 115200, 150000,
765 static char baud_co_25[] = { /* 25 MHz clock option table */
766 /* value => 00 01 02 03 04 */
767 /* divide by 8 32 128 512 2048 */
768 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
769 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
772 static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
773 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
774 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15
777 static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
778 /* value => 00 01 02 03 04 */
779 /* divide by 8 32 128 512 2048 */
780 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
781 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
785 static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
786 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
787 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
791 static char baud_cor3[] = { /* receive threshold */
792 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
793 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
798 * The Cyclades driver implements HW flow control as any serial driver.
799 * The cyclades_port structure member rflow and the vector rflow_thr
800 * allows us to take advantage of a special feature in the CD1400 to avoid
801 * data loss even when the system interrupt latency is too high. These flags
802 * are to be used only with very special applications. Setting these flags
803 * requires the use of a special cable (DTR and RTS reversed). In the new
804 * CD1400-based boards (rev. 6.00 or later), there is no need for special
808 static char rflow_thr[] = { /* rflow threshold */
809 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
810 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
814 /* The Cyclom-Ye has placed the sequential chips in non-sequential
815 * address order. This look-up table overcomes that problem.
817 static int cy_chip_offset[] = { 0x0000,
827 /* PCI related definitions */
829 static unsigned short cy_pci_nboard;
830 static unsigned short cy_isa_nboard;
831 static unsigned short cy_nboard;
833 static unsigned short cy_pci_dev_id[] = {
834 PCI_DEVICE_ID_CYCLOM_Y_Lo, /* PCI < 1Mb */
835 PCI_DEVICE_ID_CYCLOM_Y_Hi, /* PCI > 1Mb */
836 PCI_DEVICE_ID_CYCLOM_4Y_Lo, /* 4Y PCI < 1Mb */
837 PCI_DEVICE_ID_CYCLOM_4Y_Hi, /* 4Y PCI > 1Mb */
838 PCI_DEVICE_ID_CYCLOM_8Y_Lo, /* 8Y PCI < 1Mb */
839 PCI_DEVICE_ID_CYCLOM_8Y_Hi, /* 8Y PCI > 1Mb */
840 PCI_DEVICE_ID_CYCLOM_Z_Lo, /* Z PCI < 1Mb */
841 PCI_DEVICE_ID_CYCLOM_Z_Hi, /* Z PCI > 1Mb */
846 static void cy_start(struct tty_struct *);
847 static void set_line_char(struct cyclades_port *);
848 static int cyz_issue_cmd(struct cyclades_card *, uclong, ucchar, uclong);
850 static unsigned detect_isa_irq(void __iomem *);
851 #endif /* CONFIG_ISA */
853 static int cyclades_get_proc_info(char *, char **, off_t, int, int *, void *);
855 #ifndef CONFIG_CYZ_INTR
856 static void cyz_poll(unsigned long);
858 /* The Cyclades-Z polling cycle is defined by this variable */
859 static long cyz_polling_cycle = CZ_DEF_POLL;
861 static int cyz_timeron = 0;
862 static DEFINE_TIMER(cyz_timerlist, cyz_poll, 0, 0);
864 #else /* CONFIG_CYZ_INTR */
865 static void cyz_rx_restart(unsigned long);
866 static struct timer_list cyz_rx_full_timer[NR_PORTS];
867 #endif /* CONFIG_CYZ_INTR */
869 static inline int serial_paranoia_check(struct cyclades_port *info,
870 char *name, const char *routine)
872 #ifdef SERIAL_PARANOIA_CHECK
873 static const char *badmagic =
874 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
875 static const char *badinfo =
876 "cyc Warning: null cyclades_port for (%s) in %s\n";
877 static const char *badrange =
878 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
881 printk(badinfo, name, routine);
885 if ((long)info < (long)(&cy_port[0]) ||
886 (long)(&cy_port[NR_PORTS]) < (long)info) {
887 printk(badrange, name, routine);
891 if (info->magic != CYCLADES_MAGIC) {
892 printk(badmagic, name, routine);
897 } /* serial_paranoia_check */
900 * This routine is used by the interrupt handler to schedule
901 * processing in the software interrupt portion of the driver
902 * (also known as the "bottom half"). This can be called any
903 * number of times for any channel without harm.
905 static inline void cy_sched_event(struct cyclades_port *info, int event)
907 info->event |= 1 << event; /* remember what kind of event and who */
908 schedule_work(&info->tqueue);
909 } /* cy_sched_event */
912 * This routine is used to handle the "bottom half" processing for the
913 * serial driver, known also the "software interrupt" processing.
914 * This processing is done at the kernel interrupt level, after the
915 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
916 * is where time-consuming activities which can not be done in the
917 * interrupt driver proper are done; the interrupt driver schedules
918 * them using cy_sched_event(), and they get done here.
920 * This is done through one level of indirection--the task queue.
921 * When a hardware interrupt service routine wants service by the
922 * driver's bottom half, it enqueues the appropriate tq_struct (one
923 * per port) to the keventd work queue and sets a request flag
924 * that the work queue be processed.
926 * Although this may seem unwieldy, it gives the system a way to
927 * pass an argument (in this case the pointer to the cyclades_port
928 * structure) to the bottom half of the driver. Previous kernels
929 * had to poll every port to see if that port needed servicing.
932 do_softint(struct work_struct *work)
934 struct cyclades_port *info =
935 container_of(work, struct cyclades_port, tqueue);
936 struct tty_struct *tty;
942 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
943 tty_hangup(info->tty);
944 wake_up_interruptible(&info->open_wait);
945 info->flags &= ~ASYNC_NORMAL_ACTIVE;
947 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event))
948 wake_up_interruptible(&info->open_wait);
949 #ifdef CONFIG_CYZ_INTR
950 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL, &info->event)) {
951 if (cyz_rx_full_timer[info->line].function == NULL) {
952 cyz_rx_full_timer[info->line].expires = jiffies + 1;
953 cyz_rx_full_timer[info->line].function = cyz_rx_restart;
954 cyz_rx_full_timer[info->line].data =
956 add_timer(&cyz_rx_full_timer[info->line]);
960 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP, &info->event))
961 wake_up_interruptible(&info->delta_msr_wait);
964 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event))
965 wake_up_interruptible(&info->shutdown_wait);
970 /***********************************************************/
971 /********* Start of block of Cyclom-Y specific code ********/
973 /* This routine waits up to 1000 micro-seconds for the previous
974 command to the Cirrus chip to complete and then issues the
975 new command. An error is returned if the previous command
976 didn't finish within the time limit.
978 This function is only called from inside spinlock-protected code.
980 static int cyy_issue_cmd(void __iomem * base_addr, u_char cmd, int index)
984 /* Check to see that the previous command has completed */
985 for (i = 0; i < 100; i++) {
986 if (cy_readb(base_addr + (CyCCR << index)) == 0) {
991 /* if the CCR never cleared, the previous command
992 didn't finish within the "reasonable time" */
996 /* Issue the new command */
997 cy_writeb(base_addr + (CyCCR << index), cmd);
1000 } /* cyy_issue_cmd */
1003 /* ISA interrupt detection code */
1004 static unsigned detect_isa_irq(void __iomem * address)
1007 unsigned long irqs, flags;
1008 int save_xir, save_car;
1009 int index = 0; /* IRQ probing is only for ISA */
1011 /* forget possible initially masked and pending IRQ */
1012 irq = probe_irq_off(probe_irq_on());
1014 /* Clear interrupts on the board first */
1015 cy_writeb(address + (Cy_ClrIntr << index), 0);
1016 /* Cy_ClrIntr is 0x1800 */
1018 irqs = probe_irq_on();
1022 /* Enable the Tx interrupts on the CD1400 */
1023 local_irq_save(flags);
1024 cy_writeb(address + (CyCAR << index), 0);
1025 cyy_issue_cmd(address, CyCHAN_CTL | CyENB_XMTR, index);
1027 cy_writeb(address + (CyCAR << index), 0);
1028 cy_writeb(address + (CySRER << index),
1029 cy_readb(address + (CySRER << index)) | CyTxRdy);
1030 local_irq_restore(flags);
1035 /* Check which interrupt is in use */
1036 irq = probe_irq_off(irqs);
1039 save_xir = (u_char) cy_readb(address + (CyTIR << index));
1040 save_car = cy_readb(address + (CyCAR << index));
1041 cy_writeb(address + (CyCAR << index), (save_xir & 0x3));
1042 cy_writeb(address + (CySRER << index),
1043 cy_readb(address + (CySRER << index)) & ~CyTxRdy);
1044 cy_writeb(address + (CyTIR << index), (save_xir & 0x3f));
1045 cy_writeb(address + (CyCAR << index), (save_car));
1046 cy_writeb(address + (Cy_ClrIntr << index), 0);
1047 /* Cy_ClrIntr is 0x1800 */
1049 return (irq > 0) ? irq : 0;
1051 #endif /* CONFIG_ISA */
1053 static void cyy_intr_chip(struct cyclades_card *cinfo, int chip,
1054 void __iomem * base_addr, int status, int index)
1056 struct cyclades_port *info;
1057 struct tty_struct *tty;
1058 volatile int char_count;
1059 int i, j, len, mdm_change, mdm_status, outch;
1060 int save_xir, channel, save_car;
1063 if (status & CySRReceive) { /* reception interrupt */
1064 #ifdef CY_DEBUG_INTERRUPTS
1065 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip);
1067 /* determine the channel & change to that context */
1068 spin_lock(&cinfo->card_lock);
1069 save_xir = (u_char) cy_readb(base_addr + (CyRIR << index));
1070 channel = (u_short) (save_xir & CyIRChannel);
1071 i = channel + chip * 4 + cinfo->first_line;
1073 info->last_active = jiffies;
1074 save_car = cy_readb(base_addr + (CyCAR << index));
1075 cy_writeb(base_addr + (CyCAR << index), save_xir);
1077 /* if there is nowhere to put the data, discard it */
1078 if (info->tty == 0) {
1079 j = (cy_readb(base_addr + (CyRIVR << index)) &
1081 if (j == CyIVRRxEx) { /* exception */
1082 data = cy_readb(base_addr + (CyRDSR << index));
1083 } else { /* normal character reception */
1084 char_count = cy_readb(base_addr +
1086 while (char_count--) {
1087 data = cy_readb(base_addr +
1091 } else { /* there is an open port for this data */
1093 j = (cy_readb(base_addr + (CyRIVR << index)) &
1095 if (j == CyIVRRxEx) { /* exception */
1096 data = cy_readb(base_addr + (CyRDSR << index));
1098 /* For statistics only */
1101 else if (data & CyFRAME)
1102 info->icount.frame++;
1103 else if (data & CyPARITY)
1104 info->icount.parity++;
1105 else if (data & CyOVERRUN)
1106 info->icount.overrun++;
1108 if (data & info->ignore_status_mask) {
1112 if (tty_buffer_request_room(tty, 1)) {
1113 if (data & info->read_status_mask) {
1114 if (data & CyBREAK) {
1115 tty_insert_flip_char(
1127 } else if (data & CyFRAME) {
1128 tty_insert_flip_char(
1138 } else if (data & CyPARITY) {
1139 /* Pieces of seven... */
1140 tty_insert_flip_char(
1150 } else if (data & CyOVERRUN) {
1151 tty_insert_flip_char(
1155 /* If the flip buffer itself is
1156 overflowing, we still lose
1157 the next incoming character.
1159 tty_insert_flip_char(
1169 /* These two conditions may imply */
1170 /* a normal read should be done. */
1171 /* }else if(data & CyTIMEOUT){ */
1172 /* }else if(data & CySPECHAR){ */
1174 tty_insert_flip_char(
1180 tty_insert_flip_char(tty, 0,
1185 /* there was a software buffer
1186 overrun and nothing could be
1188 info->icount.buf_overrun++;
1189 info->idle_stats.overruns++;
1191 } else { /* normal character reception */
1192 /* load # chars available from the chip */
1193 char_count = cy_readb(base_addr +
1196 #ifdef CY_ENABLE_MONITORING
1197 ++info->mon.int_count;
1198 info->mon.char_count += char_count;
1199 if (char_count > info->mon.char_max)
1200 info->mon.char_max = char_count;
1201 info->mon.char_last = char_count;
1203 len = tty_buffer_request_room(tty, char_count);
1205 data = cy_readb(base_addr +
1207 tty_insert_flip_char(tty, data,
1209 info->idle_stats.recv_bytes++;
1215 info->idle_stats.recv_idle = jiffies;
1217 tty_schedule_flip(tty);
1219 /* end of service */
1220 cy_writeb(base_addr + (CyRIR << index), (save_xir & 0x3f));
1221 cy_writeb(base_addr + (CyCAR << index), (save_car));
1222 spin_unlock(&cinfo->card_lock);
1225 if (status & CySRTransmit) { /* transmission interrupt */
1226 /* Since we only get here when the transmit buffer
1227 is empty, we know we can always stuff a dozen
1229 #ifdef CY_DEBUG_INTERRUPTS
1230 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip);
1233 /* determine the channel & change to that context */
1234 spin_lock(&cinfo->card_lock);
1235 save_xir = (u_char) cy_readb(base_addr + (CyTIR << index));
1236 channel = (u_short) (save_xir & CyIRChannel);
1237 i = channel + chip * 4 + cinfo->first_line;
1238 save_car = cy_readb(base_addr + (CyCAR << index));
1239 cy_writeb(base_addr + (CyCAR << index), save_xir);
1241 /* validate the port# (as configured and open) */
1242 if ((i < 0) || (NR_PORTS <= i)) {
1243 cy_writeb(base_addr + (CySRER << index),
1244 cy_readb(base_addr + (CySRER << index)) &
1249 info->last_active = jiffies;
1250 if (info->tty == 0) {
1251 cy_writeb(base_addr + (CySRER << index),
1252 cy_readb(base_addr + (CySRER << index)) &
1257 /* load the on-chip space for outbound data */
1258 char_count = info->xmit_fifo_size;
1260 if (info->x_char) { /* send special char */
1261 outch = info->x_char;
1262 cy_writeb(base_addr + (CyTDR << index), outch);
1268 if (info->breakon || info->breakoff) {
1269 if (info->breakon) {
1270 cy_writeb(base_addr + (CyTDR << index), 0);
1271 cy_writeb(base_addr + (CyTDR << index), 0x81);
1275 if (info->breakoff) {
1276 cy_writeb(base_addr + (CyTDR << index), 0);
1277 cy_writeb(base_addr + (CyTDR << index), 0x83);
1283 while (char_count-- > 0) {
1284 if (!info->xmit_cnt) {
1285 if (cy_readb(base_addr + (CySRER << index)) &
1287 cy_writeb(base_addr + (CySRER << index),
1288 cy_readb(base_addr +
1289 (CySRER << index)) &
1292 cy_writeb(base_addr + (CySRER << index),
1293 (cy_readb(base_addr +
1294 (CySRER << index)) &
1295 ~CyTxRdy) | CyTxMpty);
1299 if (info->xmit_buf == 0) {
1300 cy_writeb(base_addr + (CySRER << index),
1301 cy_readb(base_addr + (CySRER << index))&
1305 if (info->tty->stopped || info->tty->hw_stopped) {
1306 cy_writeb(base_addr + (CySRER << index),
1307 cy_readb(base_addr + (CySRER << index))&
1311 /* Because the Embedded Transmit Commands have
1312 been enabled, we must check to see if the
1313 escape character, NULL, is being sent. If it
1314 is, we must ensure that there is room for it
1315 to be doubled in the output stream. Therefore
1316 we no longer advance the pointer when the
1317 character is fetched, but rather wait until
1318 after the check for a NULL output character.
1319 This is necessary because there may not be
1320 room for the two chars needed to send a NULL.)
1322 outch = info->xmit_buf[info->xmit_tail];
1325 info->xmit_tail = (info->xmit_tail + 1) &
1326 (SERIAL_XMIT_SIZE - 1);
1327 cy_writeb(base_addr + (CyTDR << index), outch);
1330 if (char_count > 1) {
1332 info->xmit_tail = (info->xmit_tail + 1)&
1333 (SERIAL_XMIT_SIZE - 1);
1334 cy_writeb(base_addr + (CyTDR << index),
1336 cy_writeb(base_addr + (CyTDR << index),
1346 if (info->xmit_cnt < WAKEUP_CHARS) {
1347 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1350 /* end of service */
1351 cy_writeb(base_addr + (CyTIR << index), (save_xir & 0x3f));
1352 cy_writeb(base_addr + (CyCAR << index), (save_car));
1353 spin_unlock(&cinfo->card_lock);
1356 if (status & CySRModem) { /* modem interrupt */
1358 /* determine the channel & change to that context */
1359 spin_lock(&cinfo->card_lock);
1360 save_xir = (u_char) cy_readb(base_addr + (CyMIR << index));
1361 channel = (u_short) (save_xir & CyIRChannel);
1362 info = &cy_port[channel + chip * 4 + cinfo->first_line];
1363 info->last_active = jiffies;
1364 save_car = cy_readb(base_addr + (CyCAR << index));
1365 cy_writeb(base_addr + (CyCAR << index), save_xir);
1367 mdm_change = cy_readb(base_addr + (CyMISR << index));
1368 mdm_status = cy_readb(base_addr + (CyMSVR1 << index));
1370 if (info->tty == 0) { /* no place for data, ignore it */
1373 if (mdm_change & CyANY_DELTA) {
1374 /* For statistics only */
1375 if (mdm_change & CyDCD)
1377 if (mdm_change & CyCTS)
1379 if (mdm_change & CyDSR)
1381 if (mdm_change & CyRI)
1384 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1387 if ((mdm_change & CyDCD) &&
1388 (info->flags & ASYNC_CHECK_CD)) {
1389 if (mdm_status & CyDCD) {
1390 cy_sched_event(info,
1391 Cy_EVENT_OPEN_WAKEUP);
1393 cy_sched_event(info, Cy_EVENT_HANGUP);
1396 if ((mdm_change & CyCTS) &&
1397 (info->flags & ASYNC_CTS_FLOW)) {
1398 if (info->tty->hw_stopped) {
1399 if (mdm_status & CyCTS) {
1400 /* cy_start isn't used
1402 info->tty->hw_stopped = 0;
1403 cy_writeb(base_addr +
1405 cy_readb(base_addr +
1409 cy_sched_event(info,
1410 Cy_EVENT_WRITE_WAKEUP);
1413 if (!(mdm_status & CyCTS)) {
1414 /* cy_stop isn't used
1416 info->tty->hw_stopped = 1;
1417 cy_writeb(base_addr +
1419 cy_readb(base_addr +
1426 if (mdm_change & CyDSR) {
1428 if (mdm_change & CyRI) {
1431 /* end of service */
1432 cy_writeb(base_addr + (CyMIR << index), (save_xir & 0x3f));
1433 cy_writeb(base_addr + (CyCAR << index), save_car);
1434 spin_unlock(&cinfo->card_lock);
1438 /* The real interrupt service routine is called
1439 whenever the card wants its hand held--chars
1440 received, out buffer empty, modem change, etc.
1442 static irqreturn_t cyy_interrupt(int irq, void *dev_id)
1445 struct cyclades_card *cinfo;
1446 void __iomem *base_addr, *card_base_addr;
1452 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1453 #ifdef CY_DEBUG_INTERRUPTS
1454 printk("cyy_interrupt: spurious interrupt %d\n\r", irq);
1456 return IRQ_NONE; /* spurious interrupt */
1459 card_base_addr = cinfo->base_addr;
1460 index = cinfo->bus_index;
1462 /* This loop checks all chips in the card. Make a note whenever
1463 _any_ chip had some work to do, as this is considered an
1464 indication that there will be more to do. Only when no chip
1465 has any work does this outermost loop exit.
1469 for (chip = 0; chip < cinfo->num_chips; chip++) {
1470 base_addr = cinfo->base_addr +
1471 (cy_chip_offset[chip] << index);
1473 while ((status = cy_readb(base_addr +
1474 (CySVRR << index))) != 0x00) {
1476 /* The purpose of the following test is to ensure that
1477 no chip can monopolize the driver. This forces the
1478 chips to be checked in a round-robin fashion (after
1479 draining each of a bunch (1000) of characters).
1481 if (1000 < too_many++) {
1484 cyy_intr_chip(cinfo, chip, base_addr, status,
1490 /* clear interrupts */
1491 spin_lock(&cinfo->card_lock);
1492 cy_writeb(card_base_addr + (Cy_ClrIntr << index), 0);
1493 /* Cy_ClrIntr is 0x1800 */
1494 spin_unlock(&cinfo->card_lock);
1496 } /* cyy_interrupt */
1498 /***********************************************************/
1499 /********* End of block of Cyclom-Y specific code **********/
1500 /******** Start of block of Cyclades-Z specific code *********/
1501 /***********************************************************/
1504 cyz_fetch_msg(struct cyclades_card *cinfo,
1505 uclong * channel, ucchar * cmd, uclong * param)
1507 struct FIRM_ID __iomem *firm_id;
1508 struct ZFW_CTRL __iomem *zfw_ctrl;
1509 struct BOARD_CTRL __iomem *board_ctrl;
1510 unsigned long loc_doorbell;
1512 firm_id = cinfo->base_addr + ID_ADDRESS;
1513 if (!ISZLOADED(*cinfo)) {
1516 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1518 board_ctrl = &zfw_ctrl->board_ctrl;
1520 loc_doorbell = cy_readl(&((struct RUNTIME_9060 __iomem *)
1521 (cinfo->ctl_addr))->loc_doorbell);
1523 *cmd = (char)(0xff & loc_doorbell);
1524 *channel = cy_readl(&board_ctrl->fwcmd_channel);
1525 *param = (uclong) cy_readl(&board_ctrl->fwcmd_param);
1526 cy_writel(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1527 loc_doorbell, 0xffffffff);
1531 } /* cyz_fetch_msg */
1534 cyz_issue_cmd(struct cyclades_card *cinfo,
1535 uclong channel, ucchar cmd, uclong param)
1537 struct FIRM_ID __iomem *firm_id;
1538 struct ZFW_CTRL __iomem *zfw_ctrl;
1539 struct BOARD_CTRL __iomem *board_ctrl;
1540 unsigned long __iomem *pci_doorbell;
1543 firm_id = cinfo->base_addr + ID_ADDRESS;
1544 if (!ISZLOADED(*cinfo)) {
1547 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1549 board_ctrl = &zfw_ctrl->board_ctrl;
1553 &((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->pci_doorbell;
1554 while ((cy_readl(pci_doorbell) & 0xff) != 0) {
1555 if (index++ == 1000) {
1556 return ((int)(cy_readl(pci_doorbell) & 0xff));
1560 cy_writel(&board_ctrl->hcmd_channel, channel);
1561 cy_writel(&board_ctrl->hcmd_param, param);
1562 cy_writel(pci_doorbell, (long)cmd);
1565 } /* cyz_issue_cmd */
1568 cyz_handle_rx(struct cyclades_port *info,
1569 volatile struct CH_CTRL __iomem * ch_ctrl,
1570 volatile struct BUF_CTRL __iomem * buf_ctrl)
1572 struct cyclades_card *cinfo = &cy_card[info->card];
1573 struct tty_struct *tty = info->tty;
1574 volatile int char_count;
1581 volatile uclong rx_put, rx_get, new_rx_get, rx_bufsize, rx_bufaddr;
1583 rx_get = new_rx_get = cy_readl(&buf_ctrl->rx_get);
1584 rx_put = cy_readl(&buf_ctrl->rx_put);
1585 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
1586 rx_bufaddr = cy_readl(&buf_ctrl->rx_bufaddr);
1587 if (rx_put >= rx_get)
1588 char_count = rx_put - rx_get;
1590 char_count = rx_put - rx_get + rx_bufsize;
1593 info->last_active = jiffies;
1594 info->jiffies[1] = jiffies;
1596 #ifdef CY_ENABLE_MONITORING
1597 info->mon.int_count++;
1598 info->mon.char_count += char_count;
1599 if (char_count > info->mon.char_max)
1600 info->mon.char_max = char_count;
1601 info->mon.char_last = char_count;
1604 /* flush received characters */
1605 new_rx_get = (new_rx_get + char_count) &
1607 info->rflush_count++;
1610 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1611 for performance, but because of buffer boundaries, there
1612 may be several steps to the operation */
1613 while (0 < (small_count = min_t(unsigned int,
1614 rx_bufsize - new_rx_get,
1615 min_t(unsigned int, TTY_FLIPBUF_SIZE -
1616 tty->flip.count, char_count)))){
1617 memcpy_fromio(tty->flip.char_buf_ptr,
1618 (char *)(cinfo->base_addr + rx_bufaddr +
1622 tty->flip.char_buf_ptr += small_count;
1623 memset(tty->flip.flag_buf_ptr, TTY_NORMAL,
1625 tty->flip.flag_buf_ptr += small_count;
1626 new_rx_get = (new_rx_get + small_count) &
1628 char_count -= small_count;
1629 info->icount.rx += small_count;
1630 info->idle_stats.recv_bytes += small_count;
1631 tty->flip.count += small_count;
1634 len = tty_buffer_request_room(tty, char_count);
1636 data = cy_readb(cinfo->base_addr + rx_bufaddr +
1638 new_rx_get = (new_rx_get + 1)& (rx_bufsize - 1);
1639 tty_insert_flip_char(tty, data, TTY_NORMAL);
1640 info->idle_stats.recv_bytes++;
1644 #ifdef CONFIG_CYZ_INTR
1645 /* Recalculate the number of chars in the RX buffer and issue
1646 a cmd in case it's higher than the RX high water mark */
1647 rx_put = cy_readl(&buf_ctrl->rx_put);
1648 if (rx_put >= rx_get)
1649 char_count = rx_put - rx_get;
1651 char_count = rx_put - rx_get + rx_bufsize;
1652 if (char_count >= cy_readl(&buf_ctrl->rx_threshold)) {
1653 cy_sched_event(info, Cy_EVENT_Z_RX_FULL);
1656 info->idle_stats.recv_idle = jiffies;
1657 tty_schedule_flip(tty);
1660 cy_writel(&buf_ctrl->rx_get, new_rx_get);
1665 cyz_handle_tx(struct cyclades_port *info,
1666 volatile struct CH_CTRL __iomem * ch_ctrl,
1667 volatile struct BUF_CTRL __iomem * buf_ctrl)
1669 struct cyclades_card *cinfo = &cy_card[info->card];
1670 struct tty_struct *tty = info->tty;
1672 volatile int char_count;
1676 volatile uclong tx_put, tx_get, tx_bufsize, tx_bufaddr;
1678 if (info->xmit_cnt <= 0) /* Nothing to transmit */
1681 tx_get = cy_readl(&buf_ctrl->tx_get);
1682 tx_put = cy_readl(&buf_ctrl->tx_put);
1683 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
1684 tx_bufaddr = cy_readl(&buf_ctrl->tx_bufaddr);
1685 if (tx_put >= tx_get)
1686 char_count = tx_get - tx_put - 1 + tx_bufsize;
1688 char_count = tx_get - tx_put - 1;
1696 if (info->x_char) { /* send special char */
1697 data = info->x_char;
1699 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1700 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1704 info->last_active = jiffies;
1705 info->jiffies[2] = jiffies;
1708 while (0 < (small_count = min_t(unsigned int,
1709 tx_bufsize - tx_put, min_t(unsigned int,
1710 (SERIAL_XMIT_SIZE - info->xmit_tail),
1711 min_t(unsigned int, info->xmit_cnt,
1714 memcpy_toio((char *)(cinfo->base_addr + tx_bufaddr +
1716 &info->xmit_buf[info->xmit_tail],
1719 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1720 char_count -= small_count;
1721 info->icount.tx += small_count;
1722 info->xmit_cnt -= small_count;
1723 info->xmit_tail = (info->xmit_tail + small_count) &
1724 (SERIAL_XMIT_SIZE - 1);
1725 info->last_active = jiffies;
1726 info->jiffies[2] = jiffies;
1729 while (info->xmit_cnt && char_count) {
1730 data = info->xmit_buf[info->xmit_tail];
1732 info->xmit_tail = (info->xmit_tail + 1) &
1733 (SERIAL_XMIT_SIZE - 1);
1735 cy_writeb(cinfo->base_addr + tx_bufaddr + tx_put, data);
1736 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1739 info->last_active = jiffies;
1740 info->jiffies[2] = jiffies;
1744 if (info->xmit_cnt < WAKEUP_CHARS) {
1745 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1748 cy_writel(&buf_ctrl->tx_put, tx_put);
1752 static void cyz_handle_cmd(struct cyclades_card *cinfo)
1754 struct tty_struct *tty;
1755 struct cyclades_port *info;
1756 static volatile struct FIRM_ID __iomem *firm_id;
1757 static volatile struct ZFW_CTRL __iomem *zfw_ctrl;
1758 static volatile struct BOARD_CTRL __iomem *board_ctrl;
1759 static volatile struct CH_CTRL __iomem *ch_ctrl;
1760 static volatile struct BUF_CTRL __iomem *buf_ctrl;
1764 uclong hw_ver, fw_ver;
1768 firm_id = cinfo->base_addr + ID_ADDRESS;
1769 zfw_ctrl = cinfo->base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
1771 board_ctrl = &zfw_ctrl->board_ctrl;
1772 fw_ver = cy_readl(&board_ctrl->fw_version);
1773 hw_ver = cy_readl(&((struct RUNTIME_9060 __iomem *)(cinfo->ctl_addr))->
1776 while (cyz_fetch_msg(cinfo, &channel, &cmd, ¶m) == 1) {
1779 info = &cy_port[channel + cinfo->first_line];
1780 if ((tty = info->tty) == 0) {
1783 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1784 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1788 tty_insert_flip_char(tty, 0, TTY_PARITY);
1793 tty_insert_flip_char(tty, 0, TTY_FRAME);
1798 tty_insert_flip_char(tty, 0, TTY_BREAK);
1805 if (info->flags & ASYNC_CHECK_CD) {
1806 if ((fw_ver > 241 ? ((u_long) param) :
1807 cy_readl(&ch_ctrl->rs_status)) &
1809 cy_sched_event(info,
1810 Cy_EVENT_OPEN_WAKEUP);
1812 cy_sched_event(info, Cy_EVENT_HANGUP);
1830 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
1833 #ifdef CONFIG_CYZ_INTR
1837 /* Reception Interrupt */
1838 #ifdef CY_DEBUG_INTERRUPTS
1839 printk("cyz_interrupt: rcvd intr, card %d, "
1840 "port %ld\n\r", info->card, channel);
1842 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1847 /* Transmission Interrupt */
1848 #ifdef CY_DEBUG_INTERRUPTS
1849 printk("cyz_interrupt: xmit intr, card %d, "
1850 "port %ld\n\r", info->card, channel);
1852 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1854 #endif /* CONFIG_CYZ_INTR */
1856 /* should do something with this !!! */
1862 cy_sched_event(info, Cy_EVENT_DELTA_WAKEUP);
1864 tty_schedule_flip(tty);
1868 #ifdef CONFIG_CYZ_INTR
1869 static irqreturn_t cyz_interrupt(int irq, void *dev_id)
1871 struct cyclades_card *cinfo;
1873 if ((cinfo = (struct cyclades_card *)dev_id) == 0) {
1874 #ifdef CY_DEBUG_INTERRUPTS
1875 printk("cyz_interrupt: spurious interrupt %d\n\r", irq);
1877 return IRQ_NONE; /* spurious interrupt */
1880 if (!ISZLOADED(*cinfo)) {
1881 #ifdef CY_DEBUG_INTERRUPTS
1882 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq);
1887 /* Handle the interrupts */
1888 cyz_handle_cmd(cinfo);
1891 } /* cyz_interrupt */
1893 static void cyz_rx_restart(unsigned long arg)
1895 struct cyclades_port *info = (struct cyclades_port *)arg;
1897 int card = info->card;
1898 uclong channel = (info->line) - (cy_card[card].first_line);
1899 unsigned long flags;
1901 CY_LOCK(info, flags);
1902 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK2, 0L);
1904 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1905 info->line, retval);
1907 cyz_rx_full_timer[info->line].function = NULL;
1908 CY_UNLOCK(info, flags);
1911 #else /* CONFIG_CYZ_INTR */
1913 static void cyz_poll(unsigned long arg)
1915 struct cyclades_card *cinfo;
1916 struct cyclades_port *info;
1917 struct tty_struct *tty;
1918 static volatile struct FIRM_ID *firm_id;
1919 static volatile struct ZFW_CTRL *zfw_ctrl;
1920 static volatile struct BOARD_CTRL *board_ctrl;
1921 static volatile struct CH_CTRL *ch_ctrl;
1922 static volatile struct BUF_CTRL *buf_ctrl;
1925 cyz_timerlist.expires = jiffies + (HZ);
1926 for (card = 0; card < NR_CARDS; card++) {
1927 cinfo = &cy_card[card];
1929 if (!IS_CYC_Z(*cinfo))
1931 if (!ISZLOADED(*cinfo))
1934 firm_id = cinfo->base_addr + ID_ADDRESS;
1935 zfw_ctrl = cinfo->base_addr +
1936 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
1937 board_ctrl = &(zfw_ctrl->board_ctrl);
1939 /* Skip first polling cycle to avoid racing conditions with the FW */
1940 if (!cinfo->intr_enabled) {
1941 cinfo->nports = (int)cy_readl(&board_ctrl->n_channel);
1942 cinfo->intr_enabled = 1;
1946 cyz_handle_cmd(cinfo);
1948 for (port = 0; port < cinfo->nports; port++) {
1949 info = &cy_port[port + cinfo->first_line];
1951 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1952 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
1954 if (!info->throttle)
1955 cyz_handle_rx(info, ch_ctrl, buf_ctrl);
1956 cyz_handle_tx(info, ch_ctrl, buf_ctrl);
1958 /* poll every 'cyz_polling_cycle' period */
1959 cyz_timerlist.expires = jiffies + cyz_polling_cycle;
1961 add_timer(&cyz_timerlist);
1966 #endif /* CONFIG_CYZ_INTR */
1968 /********** End of block of Cyclades-Z specific code *********/
1969 /***********************************************************/
1971 /* This is called whenever a port becomes active;
1972 interrupts are enabled and DTR & RTS are turned on.
1974 static int startup(struct cyclades_port *info)
1976 unsigned long flags;
1978 void __iomem *base_addr;
1979 int card, chip, channel, index;
1983 channel = (info->line) - (cy_card[card].first_line);
1985 page = get_zeroed_page(GFP_KERNEL);
1989 CY_LOCK(info, flags);
1991 if (info->flags & ASYNC_INITIALIZED) {
1998 set_bit(TTY_IO_ERROR, &info->tty->flags);
2007 info->xmit_buf = (unsigned char *)page;
2009 CY_UNLOCK(info, flags);
2011 set_line_char(info);
2013 if (!IS_CYC_Z(cy_card[card])) {
2014 chip = channel >> 2;
2016 index = cy_card[card].bus_index;
2017 base_addr = cy_card[card].base_addr +
2018 (cy_chip_offset[chip] << index);
2020 #ifdef CY_DEBUG_OPEN
2021 printk("cyc startup card %d, chip %d, channel %d, "
2023 card, chip, channel, (long)base_addr);
2026 CY_LOCK(info, flags);
2028 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2030 cy_writeb(base_addr + (CyRTPR << index),
2031 (info->default_timeout ? info->default_timeout : 0x02));
2032 /* 10ms rx timeout */
2034 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyENB_RCVR | CyENB_XMTR,
2037 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2038 cy_writeb(base_addr + (CyMSVR1 << index), CyRTS);
2039 cy_writeb(base_addr + (CyMSVR2 << index), CyDTR);
2042 printk("cyc:startup raising DTR\n");
2043 printk(" status: 0x%x, 0x%x\n",
2044 cy_readb(base_addr + (CyMSVR1 << index)),
2045 cy_readb(base_addr + (CyMSVR2 << index)));
2048 cy_writeb(base_addr + (CySRER << index),
2049 cy_readb(base_addr + (CySRER << index)) | CyRxData);
2050 info->flags |= ASYNC_INITIALIZED;
2053 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2055 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2056 info->breakon = info->breakoff = 0;
2057 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2058 info->idle_stats.in_use =
2059 info->idle_stats.recv_idle =
2060 info->idle_stats.xmit_idle = jiffies;
2062 CY_UNLOCK(info, flags);
2065 struct FIRM_ID __iomem *firm_id;
2066 struct ZFW_CTRL __iomem *zfw_ctrl;
2067 struct BOARD_CTRL __iomem *board_ctrl;
2068 struct CH_CTRL __iomem *ch_ctrl;
2071 base_addr = cy_card[card].base_addr;
2073 firm_id = base_addr + ID_ADDRESS;
2074 if (!ISZLOADED(cy_card[card])) {
2078 zfw_ctrl = cy_card[card].base_addr +
2079 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2080 board_ctrl = &zfw_ctrl->board_ctrl;
2081 ch_ctrl = zfw_ctrl->ch_ctrl;
2083 #ifdef CY_DEBUG_OPEN
2084 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2085 card, channel, (long)base_addr);
2088 CY_LOCK(info, flags);
2090 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2092 #ifdef CONFIG_CYZ_INTR
2093 cy_writel(&ch_ctrl[channel].intr_enable,
2094 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2095 C_IN_RXNNDT | C_IN_IOCTLW | C_IN_MDCD);
2097 cy_writel(&ch_ctrl[channel].intr_enable,
2098 C_IN_IOCTLW | C_IN_MDCD);
2099 #endif /* CONFIG_CYZ_INTR */
2101 #ifdef CONFIG_CYZ_INTR
2102 cy_writel(&ch_ctrl[channel].intr_enable,
2103 C_IN_TXBEMPTY | C_IN_TXLOWWM | C_IN_RXHIWM |
2104 C_IN_RXNNDT | C_IN_MDCD);
2106 cy_writel(&ch_ctrl[channel].intr_enable, C_IN_MDCD);
2107 #endif /* CONFIG_CYZ_INTR */
2110 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
2112 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2113 info->line, retval);
2116 /* Flush RX buffers before raising DTR and RTS */
2117 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_RX,
2120 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2121 info->line, retval);
2124 /* set timeout !!! */
2125 /* set RTS and DTR !!! */
2126 cy_writel(&ch_ctrl[channel].rs_control,
2127 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS |
2129 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2132 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2133 info->line, retval);
2136 printk("cyc:startup raising Z DTR\n");
2139 /* enable send, recv, modem !!! */
2141 info->flags |= ASYNC_INITIALIZED;
2143 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2145 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2146 info->breakon = info->breakoff = 0;
2147 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2148 info->idle_stats.in_use =
2149 info->idle_stats.recv_idle =
2150 info->idle_stats.xmit_idle = jiffies;
2152 CY_UNLOCK(info, flags);
2155 #ifdef CY_DEBUG_OPEN
2156 printk(" cyc startup done\n");
2161 CY_UNLOCK(info, flags);
2165 static void start_xmit(struct cyclades_port *info)
2167 unsigned long flags;
2168 void __iomem *base_addr;
2169 int card, chip, channel, index;
2172 channel = (info->line) - (cy_card[card].first_line);
2173 if (!IS_CYC_Z(cy_card[card])) {
2174 chip = channel >> 2;
2176 index = cy_card[card].bus_index;
2177 base_addr = cy_card[card].base_addr +
2178 (cy_chip_offset[chip] << index);
2180 CY_LOCK(info, flags);
2181 cy_writeb(base_addr + (CyCAR << index), channel);
2182 cy_writeb(base_addr + (CySRER << index),
2183 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
2184 CY_UNLOCK(info, flags);
2186 #ifdef CONFIG_CYZ_INTR
2189 CY_LOCK(info, flags);
2190 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_INTBACK,
2193 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2194 info->line, retval);
2196 CY_UNLOCK(info, flags);
2197 #else /* CONFIG_CYZ_INTR */
2198 /* Don't have to do anything at this time */
2199 #endif /* CONFIG_CYZ_INTR */
2204 * This routine shuts down a serial port; interrupts are disabled,
2205 * and DTR is dropped if the hangup on close termio flag is on.
2207 static void shutdown(struct cyclades_port *info)
2209 unsigned long flags;
2210 void __iomem *base_addr;
2211 int card, chip, channel, index;
2213 if (!(info->flags & ASYNC_INITIALIZED)) {
2218 channel = info->line - cy_card[card].first_line;
2219 if (!IS_CYC_Z(cy_card[card])) {
2220 chip = channel >> 2;
2222 index = cy_card[card].bus_index;
2223 base_addr = cy_card[card].base_addr +
2224 (cy_chip_offset[chip] << index);
2226 #ifdef CY_DEBUG_OPEN
2227 printk("cyc shutdown Y card %d, chip %d, channel %d, "
2229 card, chip, channel, (long)base_addr);
2232 CY_LOCK(info, flags);
2234 /* Clear delta_msr_wait queue to avoid mem leaks. */
2235 wake_up_interruptible(&info->delta_msr_wait);
2237 if (info->xmit_buf) {
2238 unsigned char *temp;
2239 temp = info->xmit_buf;
2240 info->xmit_buf = NULL;
2241 free_page((unsigned long)temp);
2243 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2244 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2245 cy_writeb(base_addr + (CyMSVR1 << index), ~CyRTS);
2246 cy_writeb(base_addr + (CyMSVR2 << index), ~CyDTR);
2248 printk("cyc shutdown dropping DTR\n");
2249 printk(" status: 0x%x, 0x%x\n",
2250 cy_readb(base_addr + (CyMSVR1 << index)),
2251 cy_readb(base_addr + (CyMSVR2 << index)));
2254 cyy_issue_cmd(base_addr, CyCHAN_CTL | CyDIS_RCVR, index);
2255 /* it may be appropriate to clear _XMIT at
2256 some later date (after testing)!!! */
2259 set_bit(TTY_IO_ERROR, &info->tty->flags);
2261 info->flags &= ~ASYNC_INITIALIZED;
2262 CY_UNLOCK(info, flags);
2264 struct FIRM_ID __iomem *firm_id;
2265 struct ZFW_CTRL __iomem *zfw_ctrl;
2266 struct BOARD_CTRL __iomem *board_ctrl;
2267 struct CH_CTRL __iomem *ch_ctrl;
2270 base_addr = cy_card[card].base_addr;
2271 #ifdef CY_DEBUG_OPEN
2272 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2273 card, channel, (long)base_addr);
2276 firm_id = base_addr + ID_ADDRESS;
2277 if (!ISZLOADED(cy_card[card])) {
2281 zfw_ctrl = cy_card[card].base_addr +
2282 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2283 board_ctrl = &zfw_ctrl->board_ctrl;
2284 ch_ctrl = zfw_ctrl->ch_ctrl;
2286 CY_LOCK(info, flags);
2288 if (info->xmit_buf) {
2289 unsigned char *temp;
2290 temp = info->xmit_buf;
2291 info->xmit_buf = NULL;
2292 free_page((unsigned long)temp);
2295 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2296 cy_writel(&ch_ctrl[channel].rs_control,
2297 (uclong)(cy_readl(&ch_ctrl[channel].rs_control)&
2298 ~(C_RS_RTS | C_RS_DTR)));
2299 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2302 printk("cyc:shutdown retval on ttyC%d was %x\n",
2303 info->line, retval);
2306 printk("cyc:shutdown dropping Z DTR\n");
2311 set_bit(TTY_IO_ERROR, &info->tty->flags);
2313 info->flags &= ~ASYNC_INITIALIZED;
2315 CY_UNLOCK(info, flags);
2318 #ifdef CY_DEBUG_OPEN
2319 printk(" cyc shutdown done\n");
2325 * ------------------------------------------------------------
2326 * cy_open() and friends
2327 * ------------------------------------------------------------
2331 block_til_ready(struct tty_struct *tty, struct file *filp,
2332 struct cyclades_port *info)
2334 DECLARE_WAITQUEUE(wait, current);
2335 struct cyclades_card *cinfo;
2336 unsigned long flags;
2337 int chip, channel, index;
2339 void __iomem *base_addr;
2341 cinfo = &cy_card[info->card];
2342 channel = info->line - cinfo->first_line;
2345 * If the device is in the middle of being closed, then block
2346 * until it's done, and then try again.
2348 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2349 if (info->flags & ASYNC_CLOSING) {
2350 interruptible_sleep_on(&info->close_wait);
2353 flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
2357 * If non-blocking mode is set, then make the check up front
2360 if ((filp->f_flags & O_NONBLOCK) || (tty->flags & (1 << TTY_IO_ERROR))) {
2361 info->flags |= ASYNC_NORMAL_ACTIVE;
2366 * Block waiting for the carrier detect and the line to become
2367 * free (i.e., not in use by the callout). While we are in
2368 * this loop, info->count is dropped by one, so that
2369 * cy_close() knows when to free things. We restore it upon
2370 * exit, either normal or abnormal.
2373 add_wait_queue(&info->open_wait, &wait);
2374 #ifdef CY_DEBUG_OPEN
2375 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2376 info->line, info->count);
2379 CY_LOCK(info, flags);
2380 if (!tty_hung_up_p(filp))
2382 CY_UNLOCK(info, flags);
2383 #ifdef CY_DEBUG_COUNT
2384 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2385 current->pid, info->count);
2387 info->blocked_open++;
2389 if (!IS_CYC_Z(*cinfo)) {
2390 chip = channel >> 2;
2392 index = cinfo->bus_index;
2393 base_addr = cinfo->base_addr + (cy_chip_offset[chip] << index);
2396 CY_LOCK(info, flags);
2397 if ((tty->termios->c_cflag & CBAUD)) {
2398 cy_writeb(base_addr + (CyCAR << index),
2400 cy_writeb(base_addr + (CyMSVR1 << index),
2402 cy_writeb(base_addr + (CyMSVR2 << index),
2405 printk("cyc:block_til_ready raising DTR\n");
2406 printk(" status: 0x%x, 0x%x\n",
2407 cy_readb(base_addr +
2408 (CyMSVR1 << index)),
2409 cy_readb(base_addr +
2410 (CyMSVR2 << index)));
2413 CY_UNLOCK(info, flags);
2415 set_current_state(TASK_INTERRUPTIBLE);
2416 if (tty_hung_up_p(filp) ||
2417 !(info->flags & ASYNC_INITIALIZED)) {
2418 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2419 -EAGAIN : -ERESTARTSYS);
2423 CY_LOCK(info, flags);
2424 cy_writeb(base_addr + (CyCAR << index),
2426 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2427 (cy_readb(base_addr +
2428 (CyMSVR1 << index)) & CyDCD))) {
2429 CY_UNLOCK(info, flags);
2432 CY_UNLOCK(info, flags);
2434 if (signal_pending(current)) {
2435 retval = -ERESTARTSYS;
2438 #ifdef CY_DEBUG_OPEN
2439 printk("cyc block_til_ready blocking: ttyC%d, "
2441 info->line, info->count);
2447 struct FIRM_ID __iomem *firm_id;
2448 struct ZFW_CTRL __iomem *zfw_ctrl;
2449 struct BOARD_CTRL __iomem *board_ctrl;
2450 struct CH_CTRL __iomem *ch_ctrl;
2453 base_addr = cinfo->base_addr;
2454 firm_id = base_addr + ID_ADDRESS;
2455 if (!ISZLOADED(*cinfo)) {
2456 current->state = TASK_RUNNING;
2457 remove_wait_queue(&info->open_wait, &wait);
2461 zfw_ctrl = base_addr + (cy_readl(&firm_id->zfwctrl_addr) &
2463 board_ctrl = &zfw_ctrl->board_ctrl;
2464 ch_ctrl = zfw_ctrl->ch_ctrl;
2467 if ((tty->termios->c_cflag & CBAUD)) {
2468 cy_writel(&ch_ctrl[channel].rs_control,
2469 cy_readl(&ch_ctrl[channel].
2470 rs_control) | (C_RS_RTS |
2472 retval = cyz_issue_cmd(&cy_card[info->card],
2473 channel, C_CM_IOCTLM, 0L);
2475 printk("cyc:block_til_ready retval on "
2477 info->line, retval);
2480 printk("cyc:block_til_ready raising Z DTR\n");
2484 set_current_state(TASK_INTERRUPTIBLE);
2485 if (tty_hung_up_p(filp) ||
2486 !(info->flags & ASYNC_INITIALIZED)) {
2487 retval = ((info->flags & ASYNC_HUP_NOTIFY) ?
2488 -EAGAIN : -ERESTARTSYS);
2491 if (!(info->flags & ASYNC_CLOSING) && (C_CLOCAL(tty) ||
2492 (cy_readl(&ch_ctrl[channel].rs_status) &
2496 if (signal_pending(current)) {
2497 retval = -ERESTARTSYS;
2500 #ifdef CY_DEBUG_OPEN
2501 printk("cyc block_til_ready blocking: ttyC%d, "
2503 info->line, info->count);
2509 current->state = TASK_RUNNING;
2510 remove_wait_queue(&info->open_wait, &wait);
2511 if (!tty_hung_up_p(filp)) {
2513 #ifdef CY_DEBUG_COUNT
2514 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2515 current->pid, info->count);
2518 info->blocked_open--;
2519 #ifdef CY_DEBUG_OPEN
2520 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2521 info->line, info->count);
2526 info->flags |= ASYNC_NORMAL_ACTIVE;
2528 } /* block_til_ready */
2531 * This routine is called whenever a serial port is opened. It
2532 * performs the serial-specific initialization for the tty structure.
2534 static int cy_open(struct tty_struct *tty, struct file *filp)
2536 struct cyclades_port *info;
2540 if ((line < 0) || (NR_PORTS <= line)) {
2543 info = &cy_port[line];
2544 if (info->line < 0) {
2548 /* If the card's firmware hasn't been loaded,
2549 treat it as absent from the system. This
2550 will make the user pay attention.
2552 if (IS_CYC_Z(cy_card[info->card])) {
2553 struct cyclades_card *cinfo = &cy_card[info->card];
2554 struct FIRM_ID __iomem *firm_id = cinfo->base_addr + ID_ADDRESS;
2556 if (!ISZLOADED(*cinfo)) {
2557 if (((ZE_V1 == cy_readl(
2558 &((struct RUNTIME_9060 __iomem *)
2559 (cinfo->ctl_addr))->mail_box_0)) &&
2560 Z_FPGA_CHECK(*cinfo)) &&
2561 (ZFIRM_HLT == cy_readl(
2562 &firm_id->signature))) {
2563 printk("cyc:Cyclades-Z Error: you need an "
2564 "external power supply for this number "
2565 "of ports.\n\rFirmware halted.\r\n");
2567 printk("cyc:Cyclades-Z firmware not yet "
2572 #ifdef CONFIG_CYZ_INTR
2574 /* In case this Z board is operating in interrupt mode, its
2575 interrupts should be enabled as soon as the first open
2576 happens to one of its ports. */
2577 if (!cinfo->intr_enabled) {
2578 struct ZFW_CTRL __iomem *zfw_ctrl;
2579 struct BOARD_CTRL __iomem *board_ctrl;
2581 zfw_ctrl = cinfo->base_addr +
2582 (cy_readl(&firm_id->zfwctrl_addr) &
2585 board_ctrl = &zfw_ctrl->board_ctrl;
2587 /* Enable interrupts on the PLX chip */
2588 cy_writew(cinfo->ctl_addr + 0x68,
2589 cy_readw(cinfo->ctl_addr +
2591 /* Enable interrupts on the FW */
2592 retval = cyz_issue_cmd(cinfo, 0,
2595 printk("cyc:IRQ enable retval was %x\n",
2599 (int)cy_readl(&board_ctrl->n_channel);
2600 cinfo->intr_enabled = 1;
2603 #endif /* CONFIG_CYZ_INTR */
2604 /* Make sure this Z port really exists in hardware */
2605 if (info->line > (cinfo->first_line + cinfo->nports - 1))
2608 #ifdef CY_DEBUG_OTHER
2609 printk("cyc:cy_open ttyC%d\n", info->line); /* */
2611 tty->driver_data = info;
2613 if (serial_paranoia_check(info, tty->name, "cy_open")) {
2616 #ifdef CY_DEBUG_OPEN
2617 printk("cyc:cy_open ttyC%d, count = %d\n", info->line, info->count);
2621 #ifdef CY_DEBUG_COUNT
2622 printk("cyc:cy_open (%d): incrementing count to %d\n",
2623 current->pid, info->count);
2627 * If the port is the middle of closing, bail out now
2629 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2630 if (info->flags & ASYNC_CLOSING)
2631 interruptible_sleep_on(&info->close_wait);
2633 flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
2637 * Start up serial port
2639 retval = startup(info);
2644 retval = block_til_ready(tty, filp, info);
2646 #ifdef CY_DEBUG_OPEN
2647 printk("cyc:cy_open returning after block_til_ready with %d\n",
2655 #ifdef CY_DEBUG_OPEN
2656 printk(" cyc:cy_open done\n");
2663 * cy_wait_until_sent() --- wait until the transmitter is empty
2665 static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2667 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2668 void __iomem *base_addr;
2669 int card, chip, channel, index;
2670 unsigned long orig_jiffies;
2673 if (serial_paranoia_check(info, tty->name, "cy_wait_until_sent"))
2676 if (info->xmit_fifo_size == 0)
2677 return; /* Just in case.... */
2679 orig_jiffies = jiffies;
2681 * Set the check interval to be 1/5 of the estimated time to
2682 * send a single character, and make it at least 1. The check
2683 * interval should also be less than the timeout.
2685 * Note: we have to use pretty tight timings here to satisfy
2688 char_time = (info->timeout - HZ / 50) / info->xmit_fifo_size;
2689 char_time = char_time / 5;
2695 char_time = min(char_time, timeout);
2697 * If the transmitter hasn't cleared in twice the approximate
2698 * amount of time to send the entire FIFO, it probably won't
2699 * ever clear. This assumes the UART isn't doing flow
2700 * control, which is currently the case. Hence, if it ever
2701 * takes longer than info->timeout, this is probably due to a
2702 * UART bug of some kind. So, we clamp the timeout parameter at
2705 if (!timeout || timeout > 2 * info->timeout)
2706 timeout = 2 * info->timeout;
2707 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2708 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
2709 printk("jiff=%lu...", jiffies);
2712 channel = (info->line) - (cy_card[card].first_line);
2713 if (!IS_CYC_Z(cy_card[card])) {
2714 chip = channel >> 2;
2716 index = cy_card[card].bus_index;
2718 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
2719 while (cy_readb(base_addr + (CySRER << index)) & CyTxRdy) {
2720 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2721 printk("Not clean (jiff=%lu)...", jiffies);
2723 if (msleep_interruptible(jiffies_to_msecs(char_time)))
2725 if (timeout && time_after(jiffies, orig_jiffies +
2732 /* Run one more char cycle */
2733 msleep_interruptible(jiffies_to_msecs(char_time * 5));
2734 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2735 printk("Clean (jiff=%lu)...done\n", jiffies);
2740 * This routine is called when a particular tty device is closed.
2742 static void cy_close(struct tty_struct *tty, struct file *filp)
2744 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2745 unsigned long flags;
2747 #ifdef CY_DEBUG_OTHER
2748 printk("cyc:cy_close ttyC%d\n", info->line);
2751 if (!info || serial_paranoia_check(info, tty->name, "cy_close")) {
2755 CY_LOCK(info, flags);
2756 /* If the TTY is being hung up, nothing to do */
2757 if (tty_hung_up_p(filp)) {
2758 CY_UNLOCK(info, flags);
2761 #ifdef CY_DEBUG_OPEN
2762 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
2764 if ((tty->count == 1) && (info->count != 1)) {
2766 * Uh, oh. tty->count is 1, which means that the tty
2767 * structure will be freed. Info->count should always
2768 * be one in these conditions. If it's greater than
2769 * one, we've got real problems, since it means the
2770 * serial port won't be shutdown.
2772 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2773 "info->count is %d\n", info->count);
2776 #ifdef CY_DEBUG_COUNT
2777 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2778 current->pid, info->count - 1);
2780 if (--info->count < 0) {
2781 #ifdef CY_DEBUG_COUNT
2782 printk("cyc:cyc_close setting count to 0\n");
2787 CY_UNLOCK(info, flags);
2790 info->flags |= ASYNC_CLOSING;
2793 * Now we wait for the transmit buffer to clear; and we notify
2794 * the line discipline to only process XON/XOFF characters.
2797 CY_UNLOCK(info, flags);
2798 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2799 tty_wait_until_sent(tty, info->closing_wait);
2801 CY_LOCK(info, flags);
2803 if (!IS_CYC_Z(cy_card[info->card])) {
2804 int channel = info->line - cy_card[info->card].first_line;
2805 int index = cy_card[info->card].bus_index;
2806 void __iomem *base_addr = cy_card[info->card].base_addr +
2807 (cy_chip_offset[channel >> 2] << index);
2808 /* Stop accepting input */
2810 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
2811 cy_writeb(base_addr + (CySRER << index),
2812 cy_readb(base_addr + (CySRER << index)) & ~CyRxData);
2813 if (info->flags & ASYNC_INITIALIZED) {
2814 /* Waiting for on-board buffers to be empty before closing
2816 CY_UNLOCK(info, flags);
2817 cy_wait_until_sent(tty, info->timeout);
2818 CY_LOCK(info, flags);
2822 /* Waiting for on-board buffers to be empty before closing the port */
2823 void __iomem *base_addr = cy_card[info->card].base_addr;
2824 struct FIRM_ID __iomem *firm_id = base_addr + ID_ADDRESS;
2825 struct ZFW_CTRL __iomem *zfw_ctrl =
2826 base_addr + (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
2827 struct CH_CTRL __iomem *ch_ctrl = zfw_ctrl->ch_ctrl;
2828 int channel = info->line - cy_card[info->card].first_line;
2831 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2832 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2835 printk("cyc:cy_close retval on ttyC%d was %x\n",
2836 info->line, retval);
2838 CY_UNLOCK(info, flags);
2839 interruptible_sleep_on(&info->shutdown_wait);
2840 CY_LOCK(info, flags);
2845 CY_UNLOCK(info, flags);
2847 if (tty->driver->flush_buffer)
2848 tty->driver->flush_buffer(tty);
2849 tty_ldisc_flush(tty);
2850 CY_LOCK(info, flags);
2855 if (info->blocked_open) {
2856 CY_UNLOCK(info, flags);
2857 if (info->close_delay) {
2858 msleep_interruptible(jiffies_to_msecs
2859 (info->close_delay));
2861 wake_up_interruptible(&info->open_wait);
2862 CY_LOCK(info, flags);
2864 info->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CLOSING);
2865 wake_up_interruptible(&info->close_wait);
2867 #ifdef CY_DEBUG_OTHER
2868 printk(" cyc:cy_close done\n");
2871 CY_UNLOCK(info, flags);
2875 /* This routine gets called when tty_write has put something into
2876 * the write_queue. The characters may come from user space or
2879 * This routine will return the number of characters actually
2880 * accepted for writing.
2882 * If the port is not already transmitting stuff, start it off by
2883 * enabling interrupts. The interrupt service routine will then
2884 * ensure that the characters are sent.
2885 * If the port is already active, there is no need to kick it.
2888 static int cy_write(struct tty_struct *tty, const unsigned char *buf, int count)
2890 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2891 unsigned long flags;
2895 printk("cyc:cy_write ttyC%d\n", info->line); /* */
2898 if (serial_paranoia_check(info, tty->name, "cy_write")) {
2902 if (!info->xmit_buf)
2905 CY_LOCK(info, flags);
2907 c = min(count, min((int)(SERIAL_XMIT_SIZE - info->xmit_cnt - 1),
2908 (int)(SERIAL_XMIT_SIZE - info->xmit_head)));
2913 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2914 info->xmit_head = (info->xmit_head + c) &
2915 (SERIAL_XMIT_SIZE - 1);
2916 info->xmit_cnt += c;
2921 CY_UNLOCK(info, flags);
2923 info->idle_stats.xmit_bytes += ret;
2924 info->idle_stats.xmit_idle = jiffies;
2926 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2933 * This routine is called by the kernel to write a single
2934 * character to the tty device. If the kernel uses this routine,
2935 * it must call the flush_chars() routine (if defined) when it is
2936 * done stuffing characters into the driver. If there is no room
2937 * in the queue, the character is ignored.
2939 static void cy_put_char(struct tty_struct *tty, unsigned char ch)
2941 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2942 unsigned long flags;
2945 printk("cyc:cy_put_char ttyC%d\n", info->line);
2948 if (serial_paranoia_check(info, tty->name, "cy_put_char"))
2951 if (!info->xmit_buf)
2954 CY_LOCK(info, flags);
2955 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
2956 CY_UNLOCK(info, flags);
2960 info->xmit_buf[info->xmit_head++] = ch;
2961 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
2963 info->idle_stats.xmit_bytes++;
2964 info->idle_stats.xmit_idle = jiffies;
2965 CY_UNLOCK(info, flags);
2969 * This routine is called by the kernel after it has written a
2970 * series of characters to the tty device using put_char().
2972 static void cy_flush_chars(struct tty_struct *tty)
2974 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2977 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
2980 if (serial_paranoia_check(info, tty->name, "cy_flush_chars"))
2983 if (info->xmit_cnt <= 0 || tty->stopped || tty->hw_stopped ||
2988 } /* cy_flush_chars */
2991 * This routine returns the numbers of characters the tty driver
2992 * will accept for queuing to be written. This number is subject
2993 * to change as output buffers get emptied, or if the output flow
2994 * control is activated.
2996 static int cy_write_room(struct tty_struct *tty)
2998 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3002 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
3005 if (serial_paranoia_check(info, tty->name, "cy_write_room"))
3007 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
3011 } /* cy_write_room */
3013 static int cy_chars_in_buffer(struct tty_struct *tty)
3015 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3018 if (serial_paranoia_check(info, tty->name, "cy_chars_in_buffer"))
3022 channel = (info->line) - (cy_card[card].first_line);
3024 #ifdef Z_EXT_CHARS_IN_BUFFER
3025 if (!IS_CYC_Z(cy_card[card])) {
3026 #endif /* Z_EXT_CHARS_IN_BUFFER */
3028 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt); /* */
3030 return info->xmit_cnt;
3031 #ifdef Z_EXT_CHARS_IN_BUFFER
3033 static volatile struct FIRM_ID *firm_id;
3034 static volatile struct ZFW_CTRL *zfw_ctrl;
3035 static volatile struct CH_CTRL *ch_ctrl;
3036 static volatile struct BUF_CTRL *buf_ctrl;
3038 volatile uclong tx_put, tx_get, tx_bufsize;
3040 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3041 zfw_ctrl = cy_card[card].base_addr +
3042 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3043 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3044 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
3046 tx_get = cy_readl(&buf_ctrl->tx_get);
3047 tx_put = cy_readl(&buf_ctrl->tx_put);
3048 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
3049 if (tx_put >= tx_get)
3050 char_count = tx_put - tx_get;
3052 char_count = tx_put - tx_get + tx_bufsize;
3054 printk("cyc:cy_chars_in_buffer ttyC%d %d\n", info->line, info->xmit_cnt + char_count); /* */
3056 return (info->xmit_cnt + char_count);
3058 #endif /* Z_EXT_CHARS_IN_BUFFER */
3059 } /* cy_chars_in_buffer */
3062 * ------------------------------------------------------------
3063 * cy_ioctl() and friends
3064 * ------------------------------------------------------------
3067 static void cyy_baud_calc(struct cyclades_port *info, uclong baud)
3069 int co, co_val, bpr;
3070 uclong cy_clock = ((info->chip_rev >= CD1400_REV_J) ? 60000000 :
3074 info->tbpr = info->tco = info->rbpr = info->rco = 0;
3078 /* determine which prescaler to use */
3079 for (co = 4, co_val = 2048; co; co--, co_val >>= 2) {
3080 if (cy_clock / co_val / baud > 63)
3084 bpr = (cy_clock / co_val * 2 / baud + 1) / 2;
3088 info->tbpr = info->rbpr = bpr;
3089 info->tco = info->rco = co;
3093 * This routine finds or computes the various line characteristics.
3094 * It used to be called config_setup
3096 static void set_line_char(struct cyclades_port *info)
3098 unsigned long flags;
3099 void __iomem *base_addr;
3100 int card, chip, channel, index;
3101 unsigned cflag, iflag;
3102 unsigned short chip_number;
3103 int baud, baud_rate = 0;
3106 if (!info->tty || !info->tty->termios) {
3109 if (info->line == -1) {
3112 cflag = info->tty->termios->c_cflag;
3113 iflag = info->tty->termios->c_iflag;
3116 * Set up the tty->alt_speed kludge
3119 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3120 info->tty->alt_speed = 57600;
3121 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3122 info->tty->alt_speed = 115200;
3123 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3124 info->tty->alt_speed = 230400;
3125 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3126 info->tty->alt_speed = 460800;
3130 channel = (info->line) - (cy_card[card].first_line);
3131 chip_number = channel / 4;
3133 if (!IS_CYC_Z(cy_card[card])) {
3135 index = cy_card[card].bus_index;
3138 baud = tty_get_baud_rate(info->tty);
3139 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3141 if (info->custom_divisor)
3142 baud_rate = info->baud / info->custom_divisor;
3144 baud_rate = info->baud;
3145 } else if (baud > CD1400_MAX_SPEED) {
3146 baud = CD1400_MAX_SPEED;
3148 /* find the baud index */
3149 for (i = 0; i < 20; i++) {
3150 if (baud == baud_table[i]) {
3155 i = 19; /* CD1400_MAX_SPEED */
3158 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3160 cyy_baud_calc(info, baud_rate);
3162 if (info->chip_rev >= CD1400_REV_J) {
3163 /* It is a CD1400 rev. J or later */
3164 info->tbpr = baud_bpr_60[i]; /* Tx BPR */
3165 info->tco = baud_co_60[i]; /* Tx CO */
3166 info->rbpr = baud_bpr_60[i]; /* Rx BPR */
3167 info->rco = baud_co_60[i]; /* Rx CO */
3169 info->tbpr = baud_bpr_25[i]; /* Tx BPR */
3170 info->tco = baud_co_25[i]; /* Tx CO */
3171 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3172 info->rco = baud_co_25[i]; /* Rx CO */
3175 if (baud_table[i] == 134) {
3176 /* get it right for 134.5 baud */
3177 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3179 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3181 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3183 } else if (baud_table[i]) {
3184 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3186 /* this needs to be propagated into the card info */
3190 /* By tradition (is it a standard?) a baud rate of zero
3191 implies the line should be/has been closed. A bit
3192 later in this routine such a test is performed. */
3194 /* byte size and parity */
3197 /* receive threshold */
3198 info->cor3 = (info->default_threshold ?
3199 info->default_threshold : baud_cor3[i]);
3201 switch (cflag & CSIZE) {
3203 info->cor1 = Cy_5_BITS;
3206 info->cor1 = Cy_6_BITS;
3209 info->cor1 = Cy_7_BITS;
3212 info->cor1 = Cy_8_BITS;
3215 if (cflag & CSTOPB) {
3216 info->cor1 |= Cy_2_STOP;
3218 if (cflag & PARENB) {
3219 if (cflag & PARODD) {
3220 info->cor1 |= CyPARITY_O;
3222 info->cor1 |= CyPARITY_E;
3225 info->cor1 |= CyPARITY_NONE;
3228 /* CTS flow control flag */
3229 if (cflag & CRTSCTS) {
3230 info->flags |= ASYNC_CTS_FLOW;
3231 info->cor2 |= CyCtsAE;
3233 info->flags &= ~ASYNC_CTS_FLOW;
3234 info->cor2 &= ~CyCtsAE;
3237 info->flags &= ~ASYNC_CHECK_CD;
3239 info->flags |= ASYNC_CHECK_CD;
3241 /***********************************************
3242 The hardware option, CyRtsAO, presents RTS when
3243 the chip has characters to send. Since most modems
3244 use RTS as reverse (inbound) flow control, this
3245 option is not used. If inbound flow control is
3246 necessary, DTR can be programmed to provide the
3247 appropriate signals for use with a non-standard
3248 cable. Contact Marcio Saito for details.
3249 ***********************************************/
3251 chip = channel >> 2;
3253 base_addr = cy_card[card].base_addr +
3254 (cy_chip_offset[chip] << index);
3256 CY_LOCK(info, flags);
3257 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3259 /* tx and rx baud rate */
3261 cy_writeb(base_addr + (CyTCOR << index), info->tco);
3262 cy_writeb(base_addr + (CyTBPR << index), info->tbpr);
3263 cy_writeb(base_addr + (CyRCOR << index), info->rco);
3264 cy_writeb(base_addr + (CyRBPR << index), info->rbpr);
3266 /* set line characteristics according configuration */
3268 cy_writeb(base_addr + (CySCHR1 << index),
3269 START_CHAR(info->tty));
3270 cy_writeb(base_addr + (CySCHR2 << index), STOP_CHAR(info->tty));
3271 cy_writeb(base_addr + (CyCOR1 << index), info->cor1);
3272 cy_writeb(base_addr + (CyCOR2 << index), info->cor2);
3273 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3274 cy_writeb(base_addr + (CyCOR4 << index), info->cor4);
3275 cy_writeb(base_addr + (CyCOR5 << index), info->cor5);
3277 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR1ch | CyCOR2ch |
3280 cy_writeb(base_addr + (CyCAR << index), (u_char) channel); /* !!! Is this needed? */
3281 cy_writeb(base_addr + (CyRTPR << index),
3282 (info->default_timeout ? info->default_timeout : 0x02));
3283 /* 10ms rx timeout */
3285 if (C_CLOCAL(info->tty)) {
3286 /* without modem intr */
3287 cy_writeb(base_addr + (CySRER << index),
3288 cy_readb(base_addr +
3289 (CySRER << index)) | CyMdmCh);
3290 /* act on 1->0 modem transitions */
3291 if ((cflag & CRTSCTS) && info->rflow) {
3292 cy_writeb(base_addr + (CyMCOR1 << index),
3293 (CyCTS | rflow_thr[i]));
3295 cy_writeb(base_addr + (CyMCOR1 << index),
3298 /* act on 0->1 modem transitions */
3299 cy_writeb(base_addr + (CyMCOR2 << index), CyCTS);
3301 /* without modem intr */
3302 cy_writeb(base_addr + (CySRER << index),
3303 cy_readb(base_addr +
3304 (CySRER << index)) | CyMdmCh);
3305 /* act on 1->0 modem transitions */
3306 if ((cflag & CRTSCTS) && info->rflow) {
3307 cy_writeb(base_addr + (CyMCOR1 << index),
3308 (CyDSR | CyCTS | CyRI | CyDCD |
3311 cy_writeb(base_addr + (CyMCOR1 << index),
3312 CyDSR | CyCTS | CyRI | CyDCD);
3314 /* act on 0->1 modem transitions */
3315 cy_writeb(base_addr + (CyMCOR2 << index),
3316 CyDSR | CyCTS | CyRI | CyDCD);
3319 if (i == 0) { /* baud rate is zero, turn off line */
3320 if (info->rtsdtr_inv) {
3321 cy_writeb(base_addr + (CyMSVR1 << index),
3324 cy_writeb(base_addr + (CyMSVR2 << index),
3328 printk("cyc:set_line_char dropping DTR\n");
3329 printk(" status: 0x%x, 0x%x\n",
3330 cy_readb(base_addr + (CyMSVR1 << index)),
3331 cy_readb(base_addr + (CyMSVR2 << index)));
3334 if (info->rtsdtr_inv) {
3335 cy_writeb(base_addr + (CyMSVR1 << index),
3338 cy_writeb(base_addr + (CyMSVR2 << index),
3342 printk("cyc:set_line_char raising DTR\n");
3343 printk(" status: 0x%x, 0x%x\n",
3344 cy_readb(base_addr + (CyMSVR1 << index)),
3345 cy_readb(base_addr + (CyMSVR2 << index)));
3350 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3352 CY_UNLOCK(info, flags);
3355 struct FIRM_ID __iomem *firm_id;
3356 struct ZFW_CTRL __iomem *zfw_ctrl;
3357 struct BOARD_CTRL __iomem *board_ctrl;
3358 struct CH_CTRL __iomem *ch_ctrl;
3359 struct BUF_CTRL __iomem *buf_ctrl;
3363 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3364 if (!ISZLOADED(cy_card[card])) {
3368 zfw_ctrl = cy_card[card].base_addr +
3369 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3370 board_ctrl = &zfw_ctrl->board_ctrl;
3371 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3372 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3375 baud = tty_get_baud_rate(info->tty);
3376 if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3378 if (info->custom_divisor)
3379 baud_rate = info->baud / info->custom_divisor;
3381 baud_rate = info->baud;
3382 } else if (baud > CYZ_MAX_SPEED) {
3383 baud = CYZ_MAX_SPEED;
3385 cy_writel(&ch_ctrl->comm_baud, baud);
3388 /* get it right for 134.5 baud */
3389 info->timeout = (info->xmit_fifo_size * HZ * 30 / 269) +
3391 } else if (baud == 38400 && (info->flags & ASYNC_SPD_MASK) ==
3393 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3396 info->timeout = (info->xmit_fifo_size * HZ * 15 /
3398 /* this needs to be propagated into the card info */
3403 /* byte size and parity */
3404 switch (cflag & CSIZE) {
3406 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS5);
3409 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS6);
3412 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS7);
3415 cy_writel(&ch_ctrl->comm_data_l, C_DL_CS8);
3418 if (cflag & CSTOPB) {
3419 cy_writel(&ch_ctrl->comm_data_l,
3420 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3422 cy_writel(&ch_ctrl->comm_data_l,
3423 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3425 if (cflag & PARENB) {
3426 if (cflag & PARODD) {
3427 cy_writel(&ch_ctrl->comm_parity, C_PR_ODD);
3429 cy_writel(&ch_ctrl->comm_parity, C_PR_EVEN);
3432 cy_writel(&ch_ctrl->comm_parity, C_PR_NONE);
3435 /* CTS flow control flag */
3436 if (cflag & CRTSCTS) {
3437 cy_writel(&ch_ctrl->hw_flow,
3439 hw_flow) | C_RS_CTS | C_RS_RTS);
3441 cy_writel(&ch_ctrl->hw_flow,
3443 hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3445 /* As the HW flow control is done in firmware, the driver
3446 doesn't need to care about it */
3447 info->flags &= ~ASYNC_CTS_FLOW;
3449 /* XON/XOFF/XANY flow control flags */
3452 sw_flow |= C_FL_OXX;
3454 sw_flow |= C_FL_OIXANY;
3456 cy_writel(&ch_ctrl->sw_flow, sw_flow);
3458 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
3460 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3461 info->line, retval);
3464 /* CD sensitivity */
3465 if (cflag & CLOCAL) {
3466 info->flags &= ~ASYNC_CHECK_CD;
3468 info->flags |= ASYNC_CHECK_CD;
3471 if (baud == 0) { /* baud rate is zero, turn off line */
3472 cy_writel(&ch_ctrl->rs_control,
3473 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3475 printk("cyc:set_line_char dropping Z DTR\n");
3478 cy_writel(&ch_ctrl->rs_control,
3479 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
3481 printk("cyc:set_line_char raising Z DTR\n");
3485 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTLM,0L);
3487 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3488 info->line, retval);
3492 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3495 } /* set_line_char */
3498 get_serial_info(struct cyclades_port *info,
3499 struct serial_struct __user * retinfo)
3501 struct serial_struct tmp;
3502 struct cyclades_card *cinfo = &cy_card[info->card];
3506 memset(&tmp, 0, sizeof(tmp));
3507 tmp.type = info->type;
3508 tmp.line = info->line;
3509 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3510 tmp.irq = cinfo->irq;
3511 tmp.flags = info->flags;
3512 tmp.close_delay = info->close_delay;
3513 tmp.baud_base = info->baud;
3514 tmp.custom_divisor = info->custom_divisor;
3515 tmp.hub6 = 0; /*!!! */
3516 return copy_to_user(retinfo, &tmp, sizeof(*retinfo)) ? -EFAULT : 0;
3517 } /* get_serial_info */
3520 set_serial_info(struct cyclades_port *info,
3521 struct serial_struct __user * new_info)
3523 struct serial_struct new_serial;
3524 struct cyclades_port old_info;
3526 if (copy_from_user(&new_serial, new_info, sizeof(new_serial)))
3530 if (!capable(CAP_SYS_ADMIN)) {
3531 if (new_serial.close_delay != info->close_delay ||
3532 new_serial.baud_base != info->baud ||
3533 (new_serial.flags & ASYNC_FLAGS &
3535 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK))
3537 info->flags = (info->flags & ~ASYNC_USR_MASK) |
3538 (new_serial.flags & ASYNC_USR_MASK);
3539 info->baud = new_serial.baud_base;
3540 info->custom_divisor = new_serial.custom_divisor;
3541 goto check_and_exit;
3545 * OK, past this point, all the error checking has been done.
3546 * At this point, we start making changes.....
3549 info->baud = new_serial.baud_base;
3550 info->custom_divisor = new_serial.custom_divisor;
3551 info->flags = (info->flags & ~ASYNC_FLAGS) |
3552 (new_serial.flags & ASYNC_FLAGS);
3553 info->close_delay = new_serial.close_delay * HZ / 100;
3554 info->closing_wait = new_serial.closing_wait * HZ / 100;
3557 if (info->flags & ASYNC_INITIALIZED) {
3558 set_line_char(info);
3561 return startup(info);
3563 } /* set_serial_info */
3566 * get_lsr_info - get line status register info
3568 * Purpose: Let user call ioctl() to get info when the UART physically
3569 * is emptied. On bus types like RS485, the transmitter must
3570 * release the bus after transmitting. This must be done when
3571 * the transmit shift register is empty, not be done when the
3572 * transmit holding register is empty. This functionality
3573 * allows an RS485 driver to be written in user space.
3575 static int get_lsr_info(struct cyclades_port *info, unsigned int __user * value)
3577 int card, chip, channel, index;
3578 unsigned char status;
3579 unsigned int result;
3580 unsigned long flags;
3581 void __iomem *base_addr;
3584 channel = (info->line) - (cy_card[card].first_line);
3585 if (!IS_CYC_Z(cy_card[card])) {
3586 chip = channel >> 2;
3588 index = cy_card[card].bus_index;
3590 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3592 CY_LOCK(info, flags);
3593 status = cy_readb(base_addr + (CySRER << index)) &
3594 (CyTxRdy | CyTxMpty);
3595 CY_UNLOCK(info, flags);
3596 result = (status ? 0 : TIOCSER_TEMT);
3598 /* Not supported yet */
3601 return put_user(result, (unsigned long __user *)value);
3604 static int cy_tiocmget(struct tty_struct *tty, struct file *file)
3606 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3607 int card, chip, channel, index;
3608 void __iomem *base_addr;
3609 unsigned long flags;
3610 unsigned char status;
3611 unsigned long lstatus;
3612 unsigned int result;
3613 struct FIRM_ID __iomem *firm_id;
3614 struct ZFW_CTRL __iomem *zfw_ctrl;
3615 struct BOARD_CTRL __iomem *board_ctrl;
3616 struct CH_CTRL __iomem *ch_ctrl;
3618 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3622 channel = (info->line) - (cy_card[card].first_line);
3623 if (!IS_CYC_Z(cy_card[card])) {
3624 chip = channel >> 2;
3626 index = cy_card[card].bus_index;
3628 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3630 CY_LOCK(info, flags);
3631 cy_writeb(base_addr + (CyCAR << index), (u_char) channel);
3632 status = cy_readb(base_addr + (CyMSVR1 << index));
3633 status |= cy_readb(base_addr + (CyMSVR2 << index));
3634 CY_UNLOCK(info, flags);
3636 if (info->rtsdtr_inv) {
3637 result = ((status & CyRTS) ? TIOCM_DTR : 0) |
3638 ((status & CyDTR) ? TIOCM_RTS : 0);
3640 result = ((status & CyRTS) ? TIOCM_RTS : 0) |
3641 ((status & CyDTR) ? TIOCM_DTR : 0);
3643 result |= ((status & CyDCD) ? TIOCM_CAR : 0) |
3644 ((status & CyRI) ? TIOCM_RNG : 0) |
3645 ((status & CyDSR) ? TIOCM_DSR : 0) |
3646 ((status & CyCTS) ? TIOCM_CTS : 0);
3648 base_addr = cy_card[card].base_addr;
3650 if (cy_card[card].num_chips != -1) {
3654 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3655 if (ISZLOADED(cy_card[card])) {
3656 zfw_ctrl = cy_card[card].base_addr +
3657 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3658 board_ctrl = &zfw_ctrl->board_ctrl;
3659 ch_ctrl = zfw_ctrl->ch_ctrl;
3660 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3661 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0) |
3662 ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0) |
3663 ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0) |
3664 ((lstatus & C_RS_RI) ? TIOCM_RNG : 0) |
3665 ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0) |
3666 ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3677 cy_tiocmset(struct tty_struct *tty, struct file *file,
3678 unsigned int set, unsigned int clear)
3680 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3681 int card, chip, channel, index;
3682 void __iomem *base_addr;
3683 unsigned long flags;
3684 struct FIRM_ID __iomem *firm_id;
3685 struct ZFW_CTRL __iomem *zfw_ctrl;
3686 struct BOARD_CTRL __iomem *board_ctrl;
3687 struct CH_CTRL __iomem *ch_ctrl;
3690 if (serial_paranoia_check(info, tty->name, __FUNCTION__))
3694 channel = (info->line) - (cy_card[card].first_line);
3695 if (!IS_CYC_Z(cy_card[card])) {
3696 chip = channel >> 2;
3698 index = cy_card[card].bus_index;
3700 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3702 if (set & TIOCM_RTS) {
3703 CY_LOCK(info, flags);
3704 cy_writeb(base_addr + (CyCAR << index),
3706 if (info->rtsdtr_inv) {
3707 cy_writeb(base_addr + (CyMSVR2 << index),
3710 cy_writeb(base_addr + (CyMSVR1 << index),
3713 CY_UNLOCK(info, flags);
3715 if (clear & TIOCM_RTS) {
3716 CY_LOCK(info, flags);
3717 cy_writeb(base_addr + (CyCAR << index),
3719 if (info->rtsdtr_inv) {
3720 cy_writeb(base_addr + (CyMSVR2 << index),
3723 cy_writeb(base_addr + (CyMSVR1 << index),
3726 CY_UNLOCK(info, flags);
3728 if (set & TIOCM_DTR) {
3729 CY_LOCK(info, flags);
3730 cy_writeb(base_addr + (CyCAR << index),
3732 if (info->rtsdtr_inv) {
3733 cy_writeb(base_addr + (CyMSVR1 << index),
3736 cy_writeb(base_addr + (CyMSVR2 << index),
3740 printk("cyc:set_modem_info raising DTR\n");
3741 printk(" status: 0x%x, 0x%x\n",
3742 cy_readb(base_addr + (CyMSVR1 << index)),
3743 cy_readb(base_addr + (CyMSVR2 << index)));
3745 CY_UNLOCK(info, flags);
3747 if (clear & TIOCM_DTR) {
3748 CY_LOCK(info, flags);
3749 cy_writeb(base_addr + (CyCAR << index),
3751 if (info->rtsdtr_inv) {
3752 cy_writeb(base_addr + (CyMSVR1 << index),
3755 cy_writeb(base_addr + (CyMSVR2 << index),
3760 printk("cyc:set_modem_info dropping DTR\n");
3761 printk(" status: 0x%x, 0x%x\n",
3762 cy_readb(base_addr + (CyMSVR1 << index)),
3763 cy_readb(base_addr + (CyMSVR2 << index)));
3765 CY_UNLOCK(info, flags);
3768 base_addr = cy_card[card].base_addr;
3770 firm_id = cy_card[card].base_addr + ID_ADDRESS;
3771 if (ISZLOADED(cy_card[card])) {
3772 zfw_ctrl = cy_card[card].base_addr +
3773 (cy_readl(&firm_id->zfwctrl_addr) & 0xfffff);
3774 board_ctrl = &zfw_ctrl->board_ctrl;
3775 ch_ctrl = zfw_ctrl->ch_ctrl;
3777 if (set & TIOCM_RTS) {
3778 CY_LOCK(info, flags);
3779 cy_writel(&ch_ctrl[channel].rs_control,
3780 cy_readl(&ch_ctrl[channel].
3781 rs_control) | C_RS_RTS);
3782 CY_UNLOCK(info, flags);
3784 if (clear & TIOCM_RTS) {
3785 CY_LOCK(info, flags);
3786 cy_writel(&ch_ctrl[channel].rs_control,
3787 cy_readl(&ch_ctrl[channel].
3788 rs_control) & ~C_RS_RTS);
3789 CY_UNLOCK(info, flags);
3791 if (set & TIOCM_DTR) {
3792 CY_LOCK(info, flags);
3793 cy_writel(&ch_ctrl[channel].rs_control,
3794 cy_readl(&ch_ctrl[channel].
3795 rs_control) | C_RS_DTR);
3797 printk("cyc:set_modem_info raising Z DTR\n");
3799 CY_UNLOCK(info, flags);
3801 if (clear & TIOCM_DTR) {
3802 CY_LOCK(info, flags);
3803 cy_writel(&ch_ctrl[channel].rs_control,
3804 cy_readl(&ch_ctrl[channel].
3805 rs_control) & ~C_RS_DTR);
3807 printk("cyc:set_modem_info clearing Z DTR\n");
3809 CY_UNLOCK(info, flags);
3814 CY_LOCK(info, flags);
3815 retval = cyz_issue_cmd(&cy_card[info->card],
3816 channel, C_CM_IOCTLM, 0L);
3818 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3819 info->line, retval);
3821 CY_UNLOCK(info, flags);
3827 * cy_break() --- routine which turns the break handling on or off
3829 static void cy_break(struct tty_struct *tty, int break_state)
3831 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
3832 unsigned long flags;
3834 if (serial_paranoia_check(info, tty->name, "cy_break"))
3837 CY_LOCK(info, flags);
3838 if (!IS_CYC_Z(cy_card[info->card])) {
3839 /* Let the transmit ISR take care of this (since it
3840 requires stuffing characters into the output stream).
3842 if (break_state == -1) {
3843 if (!info->breakon) {
3845 if (!info->xmit_cnt) {
3846 CY_UNLOCK(info, flags);
3848 CY_LOCK(info, flags);
3852 if (!info->breakoff) {
3854 if (!info->xmit_cnt) {
3855 CY_UNLOCK(info, flags);
3857 CY_LOCK(info, flags);
3864 if (break_state == -1) {
3865 retval = cyz_issue_cmd(&cy_card[info->card],
3866 info->line - cy_card[info->card].first_line,
3867 C_CM_SET_BREAK, 0L);
3869 printk("cyc:cy_break (set) retval on ttyC%d "
3870 "was %x\n", info->line, retval);
3873 retval = cyz_issue_cmd(&cy_card[info->card],
3874 info->line - cy_card[info->card].first_line,
3875 C_CM_CLR_BREAK, 0L);
3877 printk("cyc:cy_break (clr) retval on ttyC%d "
3878 "was %x\n", info->line, retval);
3882 CY_UNLOCK(info, flags);
3886 get_mon_info(struct cyclades_port *info, struct cyclades_monitor __user * mon)
3889 if (copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor)))
3891 info->mon.int_count = 0;
3892 info->mon.char_count = 0;
3893 info->mon.char_max = 0;
3894 info->mon.char_last = 0;
3896 } /* get_mon_info */
3898 static int set_threshold(struct cyclades_port *info, unsigned long value)
3900 void __iomem *base_addr;
3901 int card, channel, chip, index;
3902 unsigned long flags;
3905 channel = info->line - cy_card[card].first_line;
3906 if (!IS_CYC_Z(cy_card[card])) {
3907 chip = channel >> 2;
3909 index = cy_card[card].bus_index;
3911 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3913 info->cor3 &= ~CyREC_FIFO;
3914 info->cor3 |= value & CyREC_FIFO;
3916 CY_LOCK(info, flags);
3917 cy_writeb(base_addr + (CyCOR3 << index), info->cor3);
3918 cyy_issue_cmd(base_addr, CyCOR_CHANGE | CyCOR3ch, index);
3919 CY_UNLOCK(info, flags);
3924 } /* set_threshold */
3927 get_threshold(struct cyclades_port *info, unsigned long __user * value)
3929 void __iomem *base_addr;
3930 int card, channel, chip, index;
3934 channel = info->line - cy_card[card].first_line;
3935 if (!IS_CYC_Z(cy_card[card])) {
3936 chip = channel >> 2;
3938 index = cy_card[card].bus_index;
3940 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3942 tmp = cy_readb(base_addr + (CyCOR3 << index)) & CyREC_FIFO;
3943 return put_user(tmp, value);
3948 } /* get_threshold */
3951 set_default_threshold(struct cyclades_port *info, unsigned long value)
3953 info->default_threshold = value & 0x0f;
3955 } /* set_default_threshold */
3958 get_default_threshold(struct cyclades_port *info, unsigned long __user * value)
3960 return put_user(info->default_threshold, value);
3961 } /* get_default_threshold */
3963 static int set_timeout(struct cyclades_port *info, unsigned long value)
3965 void __iomem *base_addr;
3966 int card, channel, chip, index;
3967 unsigned long flags;
3970 channel = info->line - cy_card[card].first_line;
3971 if (!IS_CYC_Z(cy_card[card])) {
3972 chip = channel >> 2;
3974 index = cy_card[card].bus_index;
3976 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
3978 CY_LOCK(info, flags);
3979 cy_writeb(base_addr + (CyRTPR << index), value & 0xff);
3980 CY_UNLOCK(info, flags);
3987 static int get_timeout(struct cyclades_port *info, unsigned long __user * value)
3989 void __iomem *base_addr;
3990 int card, channel, chip, index;
3994 channel = info->line - cy_card[card].first_line;
3995 if (!IS_CYC_Z(cy_card[card])) {
3996 chip = channel >> 2;
3998 index = cy_card[card].bus_index;
4000 cy_card[card].base_addr + (cy_chip_offset[chip] << index);
4002 tmp = cy_readb(base_addr + (CyRTPR << index));
4003 return put_user(tmp, value);
4010 static int set_default_timeout(struct cyclades_port *info, unsigned long value)
4012 info->default_timeout = value & 0xff;
4014 } /* set_default_timeout */
4017 get_default_timeout(struct cyclades_port *info, unsigned long __user * value)
4019 return put_user(info->default_timeout, value);
4020 } /* get_default_timeout */
4023 * This routine allows the tty driver to implement device-
4024 * specific ioctl's. If the ioctl number passed in cmd is
4025 * not recognized by the driver, it should return ENOIOCTLCMD.
4028 cy_ioctl(struct tty_struct *tty, struct file *file,
4029 unsigned int cmd, unsigned long arg)
4031 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4032 struct cyclades_icount cprev, cnow; /* kernel counter temps */
4033 struct serial_icounter_struct __user *p_cuser; /* user space */
4035 unsigned long flags;
4036 void __user *argp = (void __user *)arg;
4038 if (serial_paranoia_check(info, tty->name, "cy_ioctl"))
4041 #ifdef CY_DEBUG_OTHER
4042 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n", info->line, cmd, arg); /* */
4047 ret_val = get_mon_info(info, argp);
4050 ret_val = get_threshold(info, argp);
4053 ret_val = set_threshold(info, arg);
4055 case CYGETDEFTHRESH:
4056 ret_val = get_default_threshold(info, argp);
4058 case CYSETDEFTHRESH:
4059 ret_val = set_default_threshold(info, arg);
4062 ret_val = get_timeout(info, argp);
4065 ret_val = set_timeout(info, arg);
4067 case CYGETDEFTIMEOUT:
4068 ret_val = get_default_timeout(info, argp);
4070 case CYSETDEFTIMEOUT:
4071 ret_val = set_default_timeout(info, arg);
4074 info->rflow = (int)arg;
4078 ret_val = info->rflow;
4080 case CYSETRTSDTR_INV:
4081 info->rtsdtr_inv = (int)arg;
4084 case CYGETRTSDTR_INV:
4085 ret_val = info->rtsdtr_inv;
4088 if (copy_to_user(argp, &cy_card[info->card],
4089 sizeof(struct cyclades_card))) {
4095 case CYGETCD1400VER:
4096 ret_val = info->chip_rev;
4098 #ifndef CONFIG_CYZ_INTR
4099 case CYZSETPOLLCYCLE:
4100 cyz_polling_cycle = (arg * HZ) / 1000;
4103 case CYZGETPOLLCYCLE:
4104 ret_val = (cyz_polling_cycle * 1000) / HZ;
4106 #endif /* CONFIG_CYZ_INTR */
4108 info->closing_wait = (unsigned short)arg *HZ / 100;
4112 ret_val = info->closing_wait / (HZ / 100);
4115 ret_val = get_serial_info(info, argp);
4118 ret_val = set_serial_info(info, argp);
4120 case TIOCSERGETLSR: /* Get line status register */
4121 ret_val = get_lsr_info(info, argp);
4124 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4125 * - mask passed in arg for lines of interest
4126 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4127 * Caller should use TIOCGICOUNT to see which one it was
4130 CY_LOCK(info, flags);
4131 /* note the counters on entry */
4132 cprev = info->icount;
4133 CY_UNLOCK(info, flags);
4135 interruptible_sleep_on(&info->delta_msr_wait);
4136 /* see if a signal did it */
4137 if (signal_pending(current)) {
4138 return -ERESTARTSYS;
4141 CY_LOCK(info, flags);
4142 cnow = info->icount; /* atomic copy */
4143 CY_UNLOCK(info, flags);
4145 if (cnow.rng == cprev.rng && cnow.dsr == cprev.dsr &&
4146 cnow.dcd == cprev.dcd && cnow.cts == cprev.cts) {
4147 return -EIO; /* no change => error */
4149 if (((arg & TIOCM_RNG) && (cnow.rng != cprev.rng)) ||
4150 ((arg & TIOCM_DSR) && (cnow.dsr != cprev.dsr)) ||
4151 ((arg & TIOCM_CD) && (cnow.dcd != cprev.dcd)) ||
4152 ((arg & TIOCM_CTS) && (cnow.cts != cprev.cts))) {
4160 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4161 * Return: write counters to the user passed counter struct
4162 * NB: both 1->0 and 0->1 transitions are counted except for
4163 * RI where only 0->1 is counted.
4166 CY_LOCK(info, flags);
4167 cnow = info->icount;
4168 CY_UNLOCK(info, flags);
4170 ret_val = put_user(cnow.cts, &p_cuser->cts);
4173 ret_val = put_user(cnow.dsr, &p_cuser->dsr);
4176 ret_val = put_user(cnow.rng, &p_cuser->rng);
4179 ret_val = put_user(cnow.dcd, &p_cuser->dcd);
4182 ret_val = put_user(cnow.rx, &p_cuser->rx);
4185 ret_val = put_user(cnow.tx, &p_cuser->tx);
4188 ret_val = put_user(cnow.frame, &p_cuser->frame);
4191 ret_val = put_user(cnow.overrun, &p_cuser->overrun);
4194 ret_val = put_user(cnow.parity, &p_cuser->parity);
4197 ret_val = put_user(cnow.brk, &p_cuser->brk);
4200 ret_val = put_user(cnow.buf_overrun, &p_cuser->buf_overrun);
4206 ret_val = -ENOIOCTLCMD;
4209 #ifdef CY_DEBUG_OTHER
4210 printk(" cyc:cy_ioctl done\n");
4217 * This routine allows the tty driver to be notified when
4218 * device's termios settings have changed. Note that a
4219 * well-designed tty driver should be prepared to accept the case
4220 * where old == NULL, and try to do something rational.
4222 static void cy_set_termios(struct tty_struct *tty, struct ktermios *old_termios)
4224 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4226 #ifdef CY_DEBUG_OTHER
4227 printk("cyc:cy_set_termios ttyC%d\n", info->line);
4230 if (tty->termios->c_cflag == old_termios->c_cflag &&
4231 (tty->termios->c_iflag & (IXON | IXANY)) ==
4232 (old_termios->c_iflag & (IXON | IXANY)))
4234 set_line_char(info);
4236 if ((old_termios->c_cflag & CRTSCTS) &&
4237 !(tty->termios->c_cflag & CRTSCTS)) {
4238 tty->hw_stopped = 0;
4243 * No need to wake up processes in open wait, since they
4244 * sample the CLOCAL flag once, and don't recheck it.
4245 * XXX It's not clear whether the current behavior is correct
4246 * or not. Hence, this may change.....
4248 if (!(old_termios->c_cflag & CLOCAL) &&
4249 (tty->termios->c_cflag & CLOCAL))
4250 wake_up_interruptible(&info->open_wait);
4254 } /* cy_set_termios */
4256 /* This function is used to send a high-priority XON/XOFF character to
4259 static void cy_send_xchar(struct tty_struct *tty, char ch)
4261 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4264 if (serial_paranoia_check(info, tty->name, "cy_send_xchar"))
4273 channel = info->line - cy_card[card].first_line;
4275 if (IS_CYC_Z(cy_card[card])) {
4276 if (ch == STOP_CHAR(tty))
4277 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXOFF,
4279 else if (ch == START_CHAR(tty))
4280 cyz_issue_cmd(&cy_card[card], channel, C_CM_SENDXON,
4285 /* This routine is called by the upper-layer tty layer to signal
4286 that incoming characters should be throttled because the input
4287 buffers are close to full.
4289 static void cy_throttle(struct tty_struct *tty)
4291 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4292 unsigned long flags;
4293 void __iomem *base_addr;
4294 int card, chip, channel, index;
4296 #ifdef CY_DEBUG_THROTTLE
4299 printk("cyc:throttle %s: %d....ttyC%d\n", tty_name(tty, buf),
4300 tty->ldisc.chars_in_buffer(tty), info->line);
4303 if (serial_paranoia_check(info, tty->name, "cy_throttle")) {
4310 if (!IS_CYC_Z(cy_card[card]))
4311 cy_send_xchar(tty, STOP_CHAR(tty));
4316 if (tty->termios->c_cflag & CRTSCTS) {
4317 channel = info->line - cy_card[card].first_line;
4318 if (!IS_CYC_Z(cy_card[card])) {
4319 chip = channel >> 2;
4321 index = cy_card[card].bus_index;
4322 base_addr = cy_card[card].base_addr +
4323 (cy_chip_offset[chip] << index);
4325 CY_LOCK(info, flags);
4326 cy_writeb(base_addr + (CyCAR << index),
4328 if (info->rtsdtr_inv) {
4329 cy_writeb(base_addr + (CyMSVR2 << index),
4332 cy_writeb(base_addr + (CyMSVR1 << index),
4335 CY_UNLOCK(info, flags);
4345 * This routine notifies the tty driver that it should signal
4346 * that characters can now be sent to the tty without fear of
4347 * overrunning the input buffers of the line disciplines.
4349 static void cy_unthrottle(struct tty_struct *tty)
4351 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4352 unsigned long flags;
4353 void __iomem *base_addr;
4354 int card, chip, channel, index;
4356 #ifdef CY_DEBUG_THROTTLE
4359 printk("cyc:unthrottle %s: %d....ttyC%d\n", tty_name(tty, buf),
4360 tty->ldisc.chars_in_buffer(tty), info->line);
4363 if (serial_paranoia_check(info, tty->name, "cy_unthrottle")) {
4371 cy_send_xchar(tty, START_CHAR(tty));
4374 if (tty->termios->c_cflag & CRTSCTS) {
4376 channel = info->line - cy_card[card].first_line;
4377 if (!IS_CYC_Z(cy_card[card])) {
4378 chip = channel >> 2;
4380 index = cy_card[card].bus_index;
4381 base_addr = cy_card[card].base_addr +
4382 (cy_chip_offset[chip] << index);
4384 CY_LOCK(info, flags);
4385 cy_writeb(base_addr + (CyCAR << index),
4387 if (info->rtsdtr_inv) {
4388 cy_writeb(base_addr + (CyMSVR2 << index),
4391 cy_writeb(base_addr + (CyMSVR1 << index),
4394 CY_UNLOCK(info, flags);
4401 } /* cy_unthrottle */
4403 /* cy_start and cy_stop provide software output flow control as a
4404 function of XON/XOFF, software CTS, and other such stuff.
4406 static void cy_stop(struct tty_struct *tty)
4408 struct cyclades_card *cinfo;
4409 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4410 void __iomem *base_addr;
4411 int chip, channel, index;
4412 unsigned long flags;
4414 #ifdef CY_DEBUG_OTHER
4415 printk("cyc:cy_stop ttyC%d\n", info->line); /* */
4418 if (serial_paranoia_check(info, tty->name, "cy_stop"))
4421 cinfo = &cy_card[info->card];
4422 channel = info->line - cinfo->first_line;
4423 if (!IS_CYC_Z(*cinfo)) {
4424 index = cinfo->bus_index;
4425 chip = channel >> 2;
4427 base_addr = cy_card[info->card].base_addr +
4428 (cy_chip_offset[chip] << index);
4430 CY_LOCK(info, flags);
4431 cy_writeb(base_addr + (CyCAR << index),
4432 (u_char)(channel & 0x0003)); /* index channel */
4433 cy_writeb(base_addr + (CySRER << index),
4434 cy_readb(base_addr + (CySRER << index)) & ~CyTxRdy);
4435 CY_UNLOCK(info, flags);
4443 static void cy_start(struct tty_struct *tty)
4445 struct cyclades_card *cinfo;
4446 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4447 void __iomem *base_addr;
4448 int chip, channel, index;
4449 unsigned long flags;
4451 #ifdef CY_DEBUG_OTHER
4452 printk("cyc:cy_start ttyC%d\n", info->line); /* */
4455 if (serial_paranoia_check(info, tty->name, "cy_start"))
4458 cinfo = &cy_card[info->card];
4459 channel = info->line - cinfo->first_line;
4460 index = cinfo->bus_index;
4461 if (!IS_CYC_Z(*cinfo)) {
4462 chip = channel >> 2;
4464 base_addr = cy_card[info->card].base_addr +
4465 (cy_chip_offset[chip] << index);
4467 CY_LOCK(info, flags);
4468 cy_writeb(base_addr + (CyCAR << index), (u_char) (channel & 0x0003)); /* index channel */
4469 cy_writeb(base_addr + (CySRER << index),
4470 cy_readb(base_addr + (CySRER << index)) | CyTxRdy);
4471 CY_UNLOCK(info, flags);
4479 static void cy_flush_buffer(struct tty_struct *tty)
4481 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4482 int card, channel, retval;
4483 unsigned long flags;
4486 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
4489 if (serial_paranoia_check(info, tty->name, "cy_flush_buffer"))
4493 channel = (info->line) - (cy_card[card].first_line);
4495 CY_LOCK(info, flags);
4496 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4497 CY_UNLOCK(info, flags);
4499 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4501 CY_LOCK(info, flags);
4503 cyz_issue_cmd(&cy_card[card], channel, C_CM_FLUSH_TX, 0L);
4505 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4506 info->line, retval);
4508 CY_UNLOCK(info, flags);
4511 wake_up_interruptible(&tty->write_wait);
4512 } /* cy_flush_buffer */
4515 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4517 static void cy_hangup(struct tty_struct *tty)
4519 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4521 #ifdef CY_DEBUG_OTHER
4522 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
4525 if (serial_paranoia_check(info, tty->name, "cy_hangup"))
4528 cy_flush_buffer(tty);
4532 #ifdef CY_DEBUG_COUNT
4533 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
4536 info->flags &= ~ASYNC_NORMAL_ACTIVE;
4537 wake_up_interruptible(&info->open_wait);
4541 * ---------------------------------------------------------------------
4542 * cy_init() and friends
4544 * cy_init() is called at boot-time to initialize the serial driver.
4545 * ---------------------------------------------------------------------
4548 /* initialize chips on Cyclom-Y card -- return number of valid
4549 chips (which is number of ports/4) */
4550 static unsigned short __init
4551 cyy_init_card(void __iomem * true_base_addr, int index)
4553 unsigned int chip_number;
4554 void __iomem *base_addr;
4556 cy_writeb(true_base_addr + (Cy_HwReset << index), 0);
4557 /* Cy_HwReset is 0x1400 */
4558 cy_writeb(true_base_addr + (Cy_ClrIntr << index), 0);
4559 /* Cy_ClrIntr is 0x1800 */
4562 for (chip_number = 0; chip_number < CyMAX_CHIPS_PER_CARD; chip_number++) {
4564 true_base_addr + (cy_chip_offset[chip_number] << index);
4566 if (cy_readb(base_addr + (CyCCR << index)) != 0x00) {
4568 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4569 chip_number, (unsigned long)base_addr);
4574 cy_writeb(base_addr + (CyGFRCR << index), 0);
4577 /* The Cyclom-16Y does not decode address bit 9 and therefore
4578 cannot distinguish between references to chip 0 and a non-
4579 existent chip 4. If the preceding clearing of the supposed
4580 chip 4 GFRCR register appears at chip 0, there is no chip 4
4581 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4583 if (chip_number == 4 && cy_readb(true_base_addr +
4584 (cy_chip_offset[0] << index) +
4585 (CyGFRCR << index)) == 0) {
4589 cy_writeb(base_addr + (CyCCR << index), CyCHIP_RESET);
4592 if (cy_readb(base_addr + (CyGFRCR << index)) == 0x00) {
4594 printk(" chip #%d at %#6lx is not responding ",
4595 chip_number, (unsigned long)base_addr);
4596 printk("(GFRCR stayed 0)\n",
4600 if ((0xf0 & (cy_readb(base_addr + (CyGFRCR << index)))) !=
4603 printk(" chip #%d at %#6lx is not valid (GFRCR == "
4605 chip_number, (unsigned long)base_addr,
4606 base_addr[CyGFRCR<<index]);
4610 cy_writeb(base_addr + (CyGCR << index), CyCH0_SERIAL);
4611 if (cy_readb(base_addr + (CyGFRCR << index)) >= CD1400_REV_J) {
4612 /* It is a CD1400 rev. J or later */
4613 /* Impossible to reach 5ms with this chip.
4614 Changed to 2ms instead (f = 500 Hz). */
4615 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_60_2MS);
4618 cy_writeb(base_addr + (CyPPR << index), CyCLOCK_25_5MS);
4622 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4623 chip_number, (unsigned long)base_addr,
4624 cy_readb(base_addr+(CyGFRCR<<index)));
4628 } /* cyy_init_card */
4631 * ---------------------------------------------------------------------
4632 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4633 * sets global variables and return the number of ISA boards found.
4634 * ---------------------------------------------------------------------
4636 static int __init cy_detect_isa(void)
4639 unsigned short cy_isa_irq, nboard;
4640 void __iomem *cy_isa_address;
4641 unsigned short i, j, cy_isa_nchan;
4649 /* Check for module parameters */
4650 for (i = 0; i < NR_CARDS; i++) {
4651 if (maddr[i] || i) {
4653 cy_isa_addresses[i] = maddr[i];
4660 /* scan the address table probing for Cyclom-Y/ISA boards */
4661 for (i = 0; i < NR_ISA_ADDRS; i++) {
4662 unsigned int isa_address = cy_isa_addresses[i];
4663 if (isa_address == 0x0000) {
4667 /* probe for CD1400... */
4668 cy_isa_address = ioremap(isa_address, CyISA_Ywin);
4669 cy_isa_nchan = CyPORTS_PER_CHIP *
4670 cyy_init_card(cy_isa_address, 0);
4671 if (cy_isa_nchan == 0) {
4675 if (isparam && irq[i])
4676 cy_isa_irq = irq[i];
4679 /* find out the board's irq by probing */
4680 cy_isa_irq = detect_isa_irq(cy_isa_address);
4681 if (cy_isa_irq == 0) {
4682 printk("Cyclom-Y/ISA found at 0x%lx ",
4683 (unsigned long)cy_isa_address);
4684 printk("but the IRQ could not be detected.\n");
4688 if ((cy_next_channel + cy_isa_nchan) > NR_PORTS) {
4689 printk("Cyclom-Y/ISA found at 0x%lx ",
4690 (unsigned long)cy_isa_address);
4691 printk("but no more channels are available.\n");
4692 printk("Change NR_PORTS in cyclades.c and recompile "
4696 /* fill the next cy_card structure available */
4697 for (j = 0; j < NR_CARDS; j++) {
4698 if (cy_card[j].base_addr == 0)
4701 if (j == NR_CARDS) { /* no more cy_cards available */
4702 printk("Cyclom-Y/ISA found at 0x%lx ",
4703 (unsigned long)cy_isa_address);
4704 printk("but no more cards can be used .\n");
4705 printk("Change NR_CARDS in cyclades.c and recompile "
4711 if (request_irq(cy_isa_irq, cyy_interrupt,
4712 IRQF_DISABLED, "Cyclom-Y", &cy_card[j])) {
4713 printk("Cyclom-Y/ISA found at 0x%lx ",
4714 (unsigned long)cy_isa_address);
4715 printk("but could not allocate IRQ#%d.\n", cy_isa_irq);
4720 cy_card[j].base_addr = cy_isa_address;
4721 cy_card[j].ctl_addr = NULL;
4722 cy_card[j].irq = (int)cy_isa_irq;
4723 cy_card[j].bus_index = 0;
4724 cy_card[j].first_line = cy_next_channel;
4725 cy_card[j].num_chips = cy_isa_nchan / 4;
4729 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4730 j + 1, (unsigned long)cy_isa_address,
4731 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4733 printk("%d channels starting from port %d.\n",
4734 cy_isa_nchan, cy_next_channel);
4735 cy_next_channel += cy_isa_nchan;
4740 #endif /* CONFIG_ISA */
4741 } /* cy_detect_isa */
4743 static void plx_init(void __iomem * addr, uclong initctl)
4746 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x40000000);
4748 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x40000000);
4750 /* Reload Config. Registers from EEPROM */
4751 cy_writel(addr + initctl, cy_readl(addr + initctl) | 0x20000000);
4753 cy_writel(addr + initctl, cy_readl(addr + initctl) & ~0x20000000);
4757 * ---------------------------------------------------------------------
4758 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4759 * sets global variables and return the number of PCI boards found.
4760 * ---------------------------------------------------------------------
4762 static int __init cy_detect_pci(void)
4766 struct pci_dev *pdev = NULL;
4767 unsigned char cyy_rev_id;
4768 unsigned char cy_pci_irq = 0;
4769 uclong cy_pci_phys0, cy_pci_phys2;
4770 void __iomem *cy_pci_addr0, *cy_pci_addr2;
4771 unsigned short i, j, cy_pci_nchan, plx_ver;
4772 unsigned short device_id, dev_index = 0;
4775 void __iomem *Ze_addr0[NR_CARDS], *Ze_addr2[NR_CARDS];
4776 uclong Ze_phys0[NR_CARDS], Ze_phys2[NR_CARDS];
4777 unsigned char Ze_irq[NR_CARDS];
4778 struct pci_dev *Ze_pdev[NR_CARDS];
4780 for (i = 0; i < NR_CARDS; i++) {
4781 /* look for a Cyclades card by vendor and device id */
4782 while ((device_id = cy_pci_dev_id[dev_index]) != 0) {
4783 if ((pdev = pci_get_device(PCI_VENDOR_ID_CYCLADES,
4784 device_id, pdev)) == NULL) {
4785 dev_index++; /* try next device id */
4787 break; /* found a board */
4794 if (pci_enable_device(pdev))
4797 /* read PCI configuration area */
4798 cy_pci_irq = pdev->irq;
4799 cy_pci_phys0 = pci_resource_start(pdev, 0);
4800 cy_pci_phys2 = pci_resource_start(pdev, 2);
4801 pci_read_config_byte(pdev, PCI_REVISION_ID, &cyy_rev_id);
4803 device_id &= ~PCI_DEVICE_ID_MASK;
4805 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo ||
4806 device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi) {
4808 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4809 pdev->bus->number, pdev->devfn);
4810 printk("rev_id=%d) IRQ%d\n",
4811 cyy_rev_id, (int)cy_pci_irq);
4812 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4814 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4817 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4818 printk(" Warning: PCI I/O bit incorrectly "
4819 "set. Ignoring it...\n");
4820 pdev->resource[2].flags &= ~IORESOURCE_IO;
4823 /* Although we don't use this I/O region, we should
4824 request it from the kernel anyway, to avoid problems
4825 with other drivers accessing it. */
4826 if (pci_request_regions(pdev, "Cyclom-Y") != 0) {
4827 printk(KERN_ERR "cyclades: failed to reserve "
4831 #if defined(__alpha__)
4832 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4833 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4834 pdev->bus->number, pdev->devfn);
4835 printk("rev_id=%d) IRQ%d\n",
4836 cyy_rev_id, (int)cy_pci_irq);
4837 printk("Cyclom-Y/PCI:found winaddr=0x%lx "
4839 (ulong)cy_pci_phys2,
4840 (ulong)cy_pci_phys0);
4841 printk("Cyclom-Y/PCI not supported for low "
4842 "addresses in Alpha systems.\n");
4847 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Yctl);
4848 cy_pci_addr2 = ioremap(cy_pci_phys2, CyPCI_Ywin);
4851 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx "
4853 (u_long)cy_pci_addr2, (u_long)cy_pci_addr0);
4855 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4856 cyy_init_card(cy_pci_addr2, 1));
4857 if (cy_pci_nchan == 0) {
4858 printk("Cyclom-Y PCI host card with ");
4859 printk("no Serial-Modules at 0x%lx.\n",
4860 (ulong) cy_pci_phys2);
4864 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
4865 printk("Cyclom-Y/PCI found at 0x%lx ",
4866 (ulong) cy_pci_phys2);
4867 printk("but no channels are available.\n");
4868 printk("Change NR_PORTS in cyclades.c and "
4869 "recompile kernel.\n");
4872 /* fill the next cy_card structure available */
4873 for (j = 0; j < NR_CARDS; j++) {
4874 if (cy_card[j].base_addr == 0)
4877 if (j == NR_CARDS) { /* no more cy_cards available */
4878 printk("Cyclom-Y/PCI found at 0x%lx ",
4879 (ulong) cy_pci_phys2);
4880 printk("but no more cards can be used.\n");
4881 printk("Change NR_CARDS in cyclades.c and "
4882 "recompile kernel.\n");
4887 if (request_irq(cy_pci_irq, cyy_interrupt,
4888 IRQF_SHARED, "Cyclom-Y", &cy_card[j])) {
4889 printk("Cyclom-Y/PCI found at 0x%lx ",
4890 (ulong) cy_pci_phys2);
4891 printk("but could not allocate IRQ%d.\n",
4897 cy_card[j].base_phys = (ulong) cy_pci_phys2;
4898 cy_card[j].ctl_phys = (ulong) cy_pci_phys0;
4899 cy_card[j].base_addr = cy_pci_addr2;
4900 cy_card[j].ctl_addr = cy_pci_addr0;
4901 cy_card[j].irq = (int)cy_pci_irq;
4902 cy_card[j].bus_index = 1;
4903 cy_card[j].first_line = cy_next_channel;
4904 cy_card[j].num_chips = cy_pci_nchan / 4;
4905 cy_card[j].pdev = pdev;
4907 /* enable interrupts in the PCI interface */
4908 plx_ver = cy_readb(cy_pci_addr2 + CyPLX_VER) & 0x0f;
4912 cy_writeb(cy_pci_addr0 + 0x4c, 0x43);
4917 default: /* Old boards, use PLX_9060 */
4919 plx_init(cy_pci_addr0, 0x6c);
4920 /* For some yet unknown reason, once the PLX9060 reloads
4921 the EEPROM, the IRQ is lost and, thus, we have to
4922 re-write it to the PCI config. registers.
4923 This will remain here until we find a permanent
4925 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4928 cy_writew(cy_pci_addr0 + 0x68,
4929 cy_readw(cy_pci_addr0 +
4935 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4936 j + 1, (ulong)cy_pci_phys2,
4937 (ulong) (cy_pci_phys2 + CyPCI_Ywin - 1),
4939 printk("%d channels starting from port %d.\n",
4940 cy_pci_nchan, cy_next_channel);
4942 cy_next_channel += cy_pci_nchan;
4943 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo) {
4945 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4946 pdev->bus->number, pdev->devfn);
4947 printk("rev_id=%d) IRQ%d\n",
4948 cyy_rev_id, (int)cy_pci_irq);
4949 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4951 (ulong)cy_pci_phys2, (ulong)cy_pci_phys0);
4952 printk("Cyclades-Z/PCI not supported for low "
4955 } else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi) {
4957 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4958 pdev->bus->number, pdev->devfn);
4959 printk("rev_id=%d) IRQ%d\n",
4960 cyy_rev_id, (int)cy_pci_irq);
4961 printk("Cyclades-Z/PCI: found winaddr=0x%lx "
4963 (ulong) cy_pci_phys2, (ulong) cy_pci_phys0);
4965 cy_pci_addr0 = ioremap(cy_pci_phys0, CyPCI_Zctl);
4967 /* Disable interrupts on the PLX before resetting it */
4968 cy_writew(cy_pci_addr0 + 0x68,
4969 cy_readw(cy_pci_addr0 + 0x68) & ~0x0900);
4971 plx_init(cy_pci_addr0, 0x6c);
4972 /* For some yet unknown reason, once the PLX9060 reloads
4973 the EEPROM, the IRQ is lost and, thus, we have to
4974 re-write it to the PCI config. registers.
4975 This will remain here until we find a permanent
4977 pci_write_config_byte(pdev, PCI_INTERRUPT_LINE,
4981 (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
4982 cy_pci_addr0)->mail_box_0);
4984 if (pci_resource_flags(pdev, 2) & IORESOURCE_IO) {
4985 printk(" Warning: PCI I/O bit incorrectly "
4986 "set. Ignoring it...\n");
4987 pdev->resource[2].flags &= ~IORESOURCE_IO;
4990 /* Although we don't use this I/O region, we should
4991 request it from the kernel anyway, to avoid problems
4992 with other drivers accessing it. */
4993 if (pci_request_regions(pdev, "Cyclades-Z") != 0) {
4994 printk(KERN_ERR "cyclades: failed to reserve "
4999 if (mailbox == ZE_V1) {
5000 cy_pci_addr2 = ioremap(cy_pci_phys2,
5002 if (ZeIndex == NR_CARDS) {
5003 printk("Cyclades-Ze/PCI found at "
5004 "0x%lx but no more cards can "
5005 "be used.\nChange NR_CARDS in "
5006 "cyclades.c and recompile "
5008 (ulong)cy_pci_phys2);
5010 Ze_phys0[ZeIndex] = cy_pci_phys0;
5011 Ze_phys2[ZeIndex] = cy_pci_phys2;
5012 Ze_addr0[ZeIndex] = cy_pci_addr0;
5013 Ze_addr2[ZeIndex] = cy_pci_addr2;
5014 Ze_irq[ZeIndex] = cy_pci_irq;
5015 Ze_pdev[ZeIndex] = pdev;
5021 cy_pci_addr2 = ioremap(cy_pci_phys2,CyPCI_Zwin);
5025 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx "
5027 (ulong) cy_pci_addr2, (ulong) cy_pci_addr0);
5028 if (mailbox == ZO_V1) {
5029 cy_writel(&((struct RUNTIME_9060 *)
5030 (cy_pci_addr0))->loc_addr_base,
5033 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver "
5034 "%lx\n", (ulong) (0xff &
5035 cy_readl(&((struct CUSTOM_REG *)
5036 (cy_pci_addr2))->fpga_id)),
5038 cy_readl(&((struct CUSTOM_REG *)
5041 cy_writel(&((struct RUNTIME_9060 *)
5042 (cy_pci_addr0))->loc_addr_base,
5045 printk("Cyclades-Z/PCI: New Cyclades-Z board. "
5046 "FPGA not loaded\n");
5049 /* The following clears the firmware id word. This
5050 ensures that the driver will not attempt to talk to
5051 the board until it has been properly initialized.
5054 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
5055 cy_writel(cy_pci_addr2 + ID_ADDRESS, 0L);
5057 /* This must be a Cyclades-8Zo/PCI. The extendable
5058 version will have a different device_id and will
5059 be allocated its maximum number of ports. */
5062 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5063 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5064 "no channels are available.\nChange "
5065 "NR_PORTS in cyclades.c and recompile "
5066 "kernel.\n", (ulong)cy_pci_phys2);
5070 /* fill the next cy_card structure available */
5071 for (j = 0; j < NR_CARDS; j++) {
5072 if (cy_card[j].base_addr == 0)
5075 if (j == NR_CARDS) { /* no more cy_cards available */
5076 printk("Cyclades-8Zo/PCI found at 0x%lx but"
5077 "no more cards can be used.\nChange "
5078 "NR_CARDS in cyclades.c and recompile "
5079 "kernel.\n", (ulong)cy_pci_phys2);
5082 #ifdef CONFIG_CYZ_INTR
5083 /* allocate IRQ only if board has an IRQ */
5084 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5085 if (request_irq(cy_pci_irq, cyz_interrupt,
5086 IRQF_SHARED, "Cyclades-Z",
5088 printk("Cyclom-8Zo/PCI found at 0x%lx "
5089 "but could not allocate "
5090 "IRQ%d.\n", (ulong)cy_pci_phys2,
5095 #endif /* CONFIG_CYZ_INTR */
5098 cy_card[j].base_phys = cy_pci_phys2;
5099 cy_card[j].ctl_phys = cy_pci_phys0;
5100 cy_card[j].base_addr = cy_pci_addr2;
5101 cy_card[j].ctl_addr = cy_pci_addr0;
5102 cy_card[j].irq = (int)cy_pci_irq;
5103 cy_card[j].bus_index = 1;
5104 cy_card[j].first_line = cy_next_channel;
5105 cy_card[j].num_chips = -1;
5106 cy_card[j].pdev = pdev;
5109 #ifdef CONFIG_CYZ_INTR
5110 /* don't report IRQ if board is no IRQ */
5111 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5112 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, "
5113 "IRQ%d, ", j + 1, (ulong)cy_pci_phys2,
5114 (ulong) (cy_pci_phys2 + CyPCI_Zwin - 1),
5117 #endif /* CONFIG_CYZ_INTR */
5118 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5119 j + 1, (ulong)cy_pci_phys2,
5120 (ulong)(cy_pci_phys2 + CyPCI_Zwin - 1));
5122 printk("%d channels starting from port %d.\n",
5123 cy_pci_nchan, cy_next_channel);
5124 cy_next_channel += cy_pci_nchan;
5128 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
5129 cy_pci_phys0 = Ze_phys0[0];
5130 cy_pci_phys2 = Ze_phys2[0];
5131 cy_pci_addr0 = Ze_addr0[0];
5132 cy_pci_addr2 = Ze_addr2[0];
5133 cy_pci_irq = Ze_irq[0];
5135 for (j = 0; j < ZeIndex - 1; j++) {
5136 Ze_phys0[j] = Ze_phys0[j + 1];
5137 Ze_phys2[j] = Ze_phys2[j + 1];
5138 Ze_addr0[j] = Ze_addr0[j + 1];
5139 Ze_addr2[j] = Ze_addr2[j + 1];
5140 Ze_irq[j] = Ze_irq[j + 1];
5141 Ze_pdev[j] = Ze_pdev[j + 1];
5144 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 __iomem *)
5145 cy_pci_addr0)->mail_box_0);
5147 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5148 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
5149 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not "
5153 /* This must be the new Cyclades-Ze/PCI. */
5154 cy_pci_nchan = ZE_V1_NPORTS;
5156 if ((cy_next_channel + cy_pci_nchan) > NR_PORTS) {
5157 printk("Cyclades-Ze/PCI found at 0x%lx but no channels "
5158 "are available.\nChange NR_PORTS in cyclades.c "
5159 "and recompile kernel.\n",
5160 (ulong) cy_pci_phys2);
5164 /* fill the next cy_card structure available */
5165 for (j = 0; j < NR_CARDS; j++) {
5166 if (cy_card[j].base_addr == 0)
5169 if (j == NR_CARDS) { /* no more cy_cards available */
5170 printk("Cyclades-Ze/PCI found at 0x%lx but no more "
5171 "cards can be used.\nChange NR_CARDS in "
5172 "cyclades.c and recompile kernel.\n",
5173 (ulong) cy_pci_phys2);
5176 #ifdef CONFIG_CYZ_INTR
5177 /* allocate IRQ only if board has an IRQ */
5178 if ((cy_pci_irq != 0) && (cy_pci_irq != 255)) {
5179 if (request_irq(cy_pci_irq, cyz_interrupt,
5180 IRQF_SHARED, "Cyclades-Z",
5182 printk("Cyclom-Ze/PCI found at 0x%lx ",
5183 (ulong) cy_pci_phys2);
5184 printk("but could not allocate IRQ%d.\n",
5189 #endif /* CONFIG_CYZ_INTR */
5192 cy_card[j].base_phys = cy_pci_phys2;
5193 cy_card[j].ctl_phys = cy_pci_phys0;
5194 cy_card[j].base_addr = cy_pci_addr2;
5195 cy_card[j].ctl_addr = cy_pci_addr0;
5196 cy_card[j].irq = (int)cy_pci_irq;
5197 cy_card[j].bus_index = 1;
5198 cy_card[j].first_line = cy_next_channel;
5199 cy_card[j].num_chips = -1;
5200 cy_card[j].pdev = pdev;
5203 #ifdef CONFIG_CYZ_INTR
5204 /* don't report IRQ if board is no IRQ */
5205 if ((cy_pci_irq != 0) && (cy_pci_irq != 255))
5206 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5207 j + 1, (ulong) cy_pci_phys2,
5208 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1),
5211 #endif /* CONFIG_CYZ_INTR */
5212 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5213 j + 1, (ulong) cy_pci_phys2,
5214 (ulong) (cy_pci_phys2 + CyPCI_Ze_win - 1));
5216 printk("%d channels starting from port %d.\n",
5217 cy_pci_nchan, cy_next_channel);
5218 cy_next_channel += cy_pci_nchan;
5221 printk("Cyclades-Ze/PCI found at 0x%x but no more cards can be "
5222 "used.\nChange NR_CARDS in cyclades.c and recompile "
5223 "kernel.\n", (unsigned int)Ze_phys2[0]);
5228 #endif /* ifdef CONFIG_PCI */
5229 } /* cy_detect_pci */
5232 * This routine prints out the appropriate serial driver version number
5233 * and identifies which options were configured into this driver.
5235 static inline void show_version(void)
5237 char *rcsvers, *rcsdate, *tmp;
5238 rcsvers = strchr(rcsid, ' ');
5240 tmp = strchr(rcsvers, ' ');
5242 rcsdate = strchr(tmp, ' ');
5244 tmp = strrchr(rcsdate, ' ');
5246 printk("Cyclades driver %s %s\n", rcsvers, rcsdate);
5247 printk(" built %s %s\n", __DATE__, __TIME__);
5248 } /* show_version */
5251 cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
5252 int *eof, void *data)
5254 struct cyclades_port *info;
5260 __u32 cur_jifs = jiffies;
5262 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn "
5263 "IdleIn Overruns Ldisc\n");
5268 /* Output one line for each known port */
5269 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
5273 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5274 "%8lu %9lu %6ld\n", info->line,
5275 JIFFIES_DIFF(info->idle_stats.in_use,
5277 info->idle_stats.xmit_bytes,
5278 JIFFIES_DIFF(info->idle_stats.xmit_idle,
5280 info->idle_stats.recv_bytes,
5281 JIFFIES_DIFF(info->idle_stats.recv_idle,
5283 info->idle_stats.overruns,
5284 (long)info->tty->ldisc.num);
5286 size = sprintf(buf + len, "%3d %8lu %10lu %8lu %10lu "
5288 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5296 if (pos > offset + length)
5301 *start = buf + (offset - begin); /* Start of wanted data */
5302 len -= (offset - begin); /* Start slop */
5304 len = length; /* Ending slop */
5310 /* The serial driver boot-time initialization code!
5311 Hardware I/O ports are mapped to character special devices on a
5312 first found, first allocated manner. That is, this code searches
5313 for Cyclom cards in the system. As each is found, it is probed
5314 to discover how many chips (and thus how many ports) are present.
5315 These ports are mapped to the tty ports 32 and upward in monotonic
5316 fashion. If an 8-port card is replaced with a 16-port card, the
5317 port mapping on a following card will shift.
5319 This approach is different from what is used in the other serial
5320 device driver because the Cyclom is more properly a multiplexer,
5321 not just an aggregation of serial ports on one card.
5323 If there are more cards with more ports than have been
5324 statically allocated above, a warning is printed and the
5325 extra ports are ignored.
5328 static const struct tty_operations cy_ops = {
5332 .put_char = cy_put_char,
5333 .flush_chars = cy_flush_chars,
5334 .write_room = cy_write_room,
5335 .chars_in_buffer = cy_chars_in_buffer,
5336 .flush_buffer = cy_flush_buffer,
5338 .throttle = cy_throttle,
5339 .unthrottle = cy_unthrottle,
5340 .set_termios = cy_set_termios,
5343 .hangup = cy_hangup,
5344 .break_ctl = cy_break,
5345 .wait_until_sent = cy_wait_until_sent,
5346 .read_proc = cyclades_get_proc_info,
5347 .tiocmget = cy_tiocmget,
5348 .tiocmset = cy_tiocmset,
5351 static int __init cy_init(void)
5353 struct cyclades_port *info;
5354 struct cyclades_card *cinfo;
5355 int number_z_boards = 0;
5356 int board, port, i, index;
5357 unsigned long mailbox;
5358 unsigned short chip_number;
5361 cy_serial_driver = alloc_tty_driver(NR_PORTS);
5362 if (!cy_serial_driver)
5366 /* Initialize the tty_driver structure */
5368 cy_serial_driver->owner = THIS_MODULE;
5369 cy_serial_driver->driver_name = "cyclades";
5370 cy_serial_driver->name = "ttyC";
5371 cy_serial_driver->major = CYCLADES_MAJOR;
5372 cy_serial_driver->minor_start = 0;
5373 cy_serial_driver->type = TTY_DRIVER_TYPE_SERIAL;
5374 cy_serial_driver->subtype = SERIAL_TYPE_NORMAL;
5375 cy_serial_driver->init_termios = tty_std_termios;
5376 cy_serial_driver->init_termios.c_cflag =
5377 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5378 cy_serial_driver->flags = TTY_DRIVER_REAL_RAW;
5379 tty_set_operations(cy_serial_driver, &cy_ops);
5381 if (tty_register_driver(cy_serial_driver))
5382 panic("Couldn't register Cyclades serial driver\n");
5384 for (i = 0; i < NR_CARDS; i++) {
5385 /* base_addr=0 indicates board not found */
5386 cy_card[i].base_addr = NULL;
5389 /* the code below is responsible to find the boards. Each different
5390 type of board has its own detection routine. If a board is found,
5391 the next cy_card structure available is set by the detection
5392 routine. These functions are responsible for checking the
5393 availability of cy_card and cy_port data structures and updating
5394 the cy_next_channel. */
5396 /* look for isa boards */
5397 cy_isa_nboard = cy_detect_isa();
5399 /* look for pci boards */
5400 cy_pci_nboard = cy_detect_pci();
5402 cy_nboard = cy_isa_nboard + cy_pci_nboard;
5404 /* invalidate remaining cy_card structures */
5405 for (i = 0; i < NR_CARDS; i++) {
5406 if (cy_card[i].base_addr == 0) {
5407 cy_card[i].first_line = -1;
5408 cy_card[i].ctl_addr = NULL;
5410 cy_card[i].bus_index = 0;
5411 cy_card[i].first_line = 0;
5412 cy_card[i].num_chips = 0;
5415 /* invalidate remaining cy_port structures */
5416 for (i = cy_next_channel; i < NR_PORTS; i++) {
5417 cy_port[i].line = -1;
5418 cy_port[i].magic = -1;
5421 /* initialize per-port data structures for each valid board found */
5422 for (board = 0; board < cy_nboard; board++) {
5423 cinfo = &cy_card[board];
5424 if (cinfo->num_chips == -1) { /* Cyclades-Z */
5426 mailbox = cy_readl(&((struct RUNTIME_9060 __iomem *)
5427 cy_card[board].ctl_addr)->
5429 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5430 cinfo->intr_enabled = 0;
5431 cinfo->nports = 0; /* Will be correctly set later, after
5433 spin_lock_init(&cinfo->card_lock);
5434 for (port = cinfo->first_line;
5435 port < cinfo->first_line + nports; port++) {
5436 info = &cy_port[port];
5437 info->magic = CYCLADES_MAGIC;
5438 info->type = PORT_STARTECH;
5442 info->flags = STD_COM_FLAGS;
5444 if (mailbox == ZO_V1)
5445 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5447 info->xmit_fifo_size =
5458 info->custom_divisor = 0;
5459 info->close_delay = 5 * HZ / 10;
5460 info->closing_wait = CLOSING_WAIT_DELAY;
5461 info->icount.cts = info->icount.dsr =
5462 info->icount.rng = info->icount.dcd = 0;
5463 info->icount.rx = info->icount.tx = 0;
5464 info->icount.frame = info->icount.parity = 0;
5465 info->icount.overrun = info->icount.brk = 0;
5469 info->blocked_open = 0;
5470 info->default_threshold = 0;
5471 info->default_timeout = 0;
5472 INIT_WORK(&info->tqueue, do_softint);
5473 init_waitqueue_head(&info->open_wait);
5474 init_waitqueue_head(&info->close_wait);
5475 init_waitqueue_head(&info->shutdown_wait);
5476 init_waitqueue_head(&info->delta_msr_wait);
5479 info->read_status_mask = 0;
5481 /* Bentson's vars */
5482 info->jiffies[0] = 0;
5483 info->jiffies[1] = 0;
5484 info->jiffies[2] = 0;
5485 info->rflush_count = 0;
5486 #ifdef CONFIG_CYZ_INTR
5487 init_timer(&cyz_rx_full_timer[port]);
5488 cyz_rx_full_timer[port].function = NULL;
5492 } else { /* Cyclom-Y of some kind */
5493 index = cinfo->bus_index;
5494 spin_lock_init(&cinfo->card_lock);
5495 cinfo->nports = CyPORTS_PER_CHIP * cinfo->num_chips;
5496 for (port = cinfo->first_line;
5497 port < cinfo->first_line + cinfo->nports; port++) {
5498 info = &cy_port[port];
5499 info->magic = CYCLADES_MAGIC;
5500 info->type = PORT_CIRRUS;
5503 info->flags = STD_COM_FLAGS;
5505 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5507 CyPARITY_NONE | Cy_1_STOP | Cy_8_BITS;
5509 info->cor3 = 0x08; /* _very_ small rcv threshold */
5512 info->custom_divisor = 0;
5513 info->close_delay = 5 * HZ / 10;
5514 info->closing_wait = CLOSING_WAIT_DELAY;
5515 info->icount.cts = info->icount.dsr =
5516 info->icount.rng = info->icount.dcd = 0;
5517 info->icount.rx = info->icount.tx = 0;
5518 info->icount.frame = info->icount.parity = 0;
5519 info->icount.overrun = info->icount.brk = 0;
5520 chip_number = (port - cinfo->first_line) / 4;
5521 if ((info->chip_rev =
5522 cy_readb(cinfo->base_addr +
5523 (cy_chip_offset[chip_number] <<
5524 index) + (CyGFRCR << index))) >=
5526 /* It is a CD1400 rev. J or later */
5527 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5528 info->tco = baud_co_60[13]; /* Tx CO */
5529 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5530 info->rco = baud_co_60[13]; /* Rx CO */
5532 info->rtsdtr_inv = 1;
5534 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5535 info->tco = baud_co_25[13]; /* Tx CO */
5536 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5537 info->rco = baud_co_25[13]; /* Rx CO */
5539 info->rtsdtr_inv = 0;
5544 info->blocked_open = 0;
5545 info->default_threshold = 0;
5546 info->default_timeout = 0;
5547 INIT_WORK(&info->tqueue, do_softint);
5548 init_waitqueue_head(&info->open_wait);
5549 init_waitqueue_head(&info->close_wait);
5550 init_waitqueue_head(&info->shutdown_wait);
5551 init_waitqueue_head(&info->delta_msr_wait);
5554 info->read_status_mask =
5555 CyTIMEOUT | CySPECHAR | CyBREAK
5556 | CyPARITY | CyFRAME | CyOVERRUN;
5562 #ifndef CONFIG_CYZ_INTR
5563 if (number_z_boards && !cyz_timeron) {
5565 cyz_timerlist.expires = jiffies + 1;
5566 add_timer(&cyz_timerlist);
5568 printk("Cyclades-Z polling initialized\n");
5571 #endif /* CONFIG_CYZ_INTR */
5577 static void __exit cy_cleanup_module(void)
5581 #ifndef CONFIG_CYZ_INTR
5584 del_timer(&cyz_timerlist);
5586 #endif /* CONFIG_CYZ_INTR */
5588 if ((e1 = tty_unregister_driver(cy_serial_driver)))
5589 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5592 put_tty_driver(cy_serial_driver);
5594 for (i = 0; i < NR_CARDS; i++) {
5595 if (cy_card[i].base_addr) {
5596 iounmap(cy_card[i].base_addr);
5597 if (cy_card[i].ctl_addr)
5598 iounmap(cy_card[i].ctl_addr);
5600 #ifndef CONFIG_CYZ_INTR
5601 && cy_card[i].num_chips != -1 /* not a Z card */
5602 #endif /* CONFIG_CYZ_INTR */
5604 free_irq(cy_card[i].irq, &cy_card[i]);
5606 if (cy_card[i].pdev)
5607 pci_release_regions(cy_card[i].pdev);
5611 } /* cy_cleanup_module */
5613 module_init(cy_init);
5614 module_exit(cy_cleanup_module);
5616 MODULE_LICENSE("GPL");