3 #undef Z_EXT_CHARS_IN_BUFFER
5 "$Revision: 2.3.2.20 $$Date: 2004/02/25 18:14:16 $";
8 * linux/drivers/char/cyclades.c
10 * This file contains the driver for the Cyclades async multiport
13 * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
14 * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
15 * Currently maintained by Cyclades team <async@cyclades.com>.
17 * For Technical support and installation problems, please send e-mail
18 * to support@cyclades.com.
20 * Much of the design and some of the code came from serial.c
21 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
22 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
23 * and then fixed as suggested by Michael K. Johnson 12/12/92.
25 * This version supports shared IRQ's (only for PCI boards).
27 * $Log: cyclades.c,v $
28 * Prevent users from opening non-existing Z ports.
30 * Revision 2.3.2.8 2000/07/06 18:14:16 ivan
31 * Fixed the PCI detection function to work properly on Alpha systems.
32 * Implemented support for TIOCSERGETLSR ioctl.
33 * Implemented full support for non-standard baud rates.
35 * Revision 2.3.2.7 2000/06/01 18:26:34 ivan
36 * Request PLX I/O region, although driver doesn't use it, to avoid
37 * problems with other drivers accessing it.
38 * Removed count for on-board buffer characters in cy_chars_in_buffer
41 * Revision 2.3.2.6 2000/05/05 13:56:05 ivan
42 * Driver now reports physical instead of virtual memory addresses.
43 * Masks were added to some Cyclades-Z read accesses.
44 * Implemented workaround for PLX9050 bug that would cause a system lockup
45 * in certain systems, depending on the MMIO addresses allocated to the
47 * Changed the Tx interrupt programming in the CD1400 chips to boost up
48 * performance (Cyclom-Y only).
49 * Code is now compliant with the new module interface (module_[init|exit]).
50 * Make use of the PCI helper functions to access PCI resources.
51 * Did some code "housekeeping".
53 * Revision 2.3.2.5 2000/01/19 14:35:33 ivan
54 * Fixed bug in cy_set_termios on CRTSCTS flag turnoff.
56 * Revision 2.3.2.4 2000/01/17 09:19:40 ivan
57 * Fixed SMP locking in Cyclom-Y interrupt handler.
59 * Revision 2.3.2.3 1999/12/28 12:11:39 ivan
60 * Added a new cyclades_card field called nports to allow the driver to
61 * know the exact number of ports found by the Z firmware after its load;
62 * RX buffer contention prevention logic on interrupt op mode revisited
64 * Revisited printk's for Z debug;
65 * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
67 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
68 * Fixed bug in cyz_poll that would make all ports but port 0
69 * unable to transmit/receive data (Cyclades-Z only);
70 * Implemented logic to prevent the RX buffer from being stuck with data
71 * due to a driver / firmware race condition in interrupt op mode
73 * Fixed bug in block_til_ready logic that would lead to a system crash;
74 * Revisited cy_close spinlock usage;
76 * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
77 * Revisited CONFIG_PCI conditional compilation for PCI board support;
78 * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
79 * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
80 * Removed CTS handling from the driver -- this is now completely handled
81 * by the firmware (Cyclades-Z only);
82 * Flush RX on-board buffers on a port open (Cyclades-Z only);
83 * Fixed handling of ASYNC_SPD_* TTY flags;
84 * Module unload now unmaps all memory area allocated by ioremap;
86 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
87 * Removed CY_PROC conditional compilation;
88 * Implemented SMP-awareness for the driver;
89 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
91 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
92 * (irq=NN) as parameters (only for ISA boards);
93 * Fixed bug in set_line_char that would prevent the Cyclades-Z
94 * ports from being configured at speeds above 115.2Kbps;
95 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
96 * switching from working properly;
97 * The driver now only prints IRQ info for the Cyclades-Z if it's
98 * configured to work in interrupt mode;
100 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
101 * Added support for interrupt mode operation for the Z cards;
102 * Removed the driver inactivity control for the Z;
103 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
104 * the Z firmware is not loaded yet;
105 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
106 * same functionality;
107 * Implemented workaround for IRQ setting loss on the PCI configuration
108 * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
110 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
111 * /proc entry location changed to /proc/tty/driver/cyclades;
112 * Added support to shared IRQ's (only for PCI boards);
113 * Added support for Cobalt Qube2 systems;
114 * IRQ [de]allocation scheme revisited;
115 * BREAK implementation changed in order to make use of the 'break_ctl'
117 * Fixed typo in TTY structure field 'driver_name';
118 * Included a PCI bridge reset and EEPROM reload in the board
119 * initialization code (for both Y and Z series).
121 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
122 * Fixed a bug in cy_wait_until_sent that was preventing the port to be
123 * closed properly after a SIGINT;
124 * Module usage counter scheme revisited;
125 * Added support to the upcoming Y PCI boards (i.e., support to additional
128 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
129 * Removed all unnecessary page-alignement operations in ioremap calls
130 * (ioremap is currently safe for these operations).
132 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
133 * Changed access to PLX PCI bridge registers from I/O to MMIO, in
134 * order to make PLX9050-based boards work with certain motherboards.
136 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
137 * cy_close function now resets (correctly) the tty->closing flag;
138 * JIFFIES_DIFF macro fixed.
140 * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
141 * Fixed bug in cy_close function, which was not informing HW of
142 * which port should have the reception disabled before doing so;
143 * fixed Cyclom-8YoP hardware detection bug.
145 * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
146 * Fixed bug in cy_close function, which causes malfunction
147 * of one of the first 4 ports when a higher port is closed
150 * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
151 * Fixed Cyclom-4Yo hardware detection bug.
153 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
154 * /proc/cyclades implementation with great collaboration of
155 * Marc Lewis <marc@blarg.net>;
156 * cyy_interrupt was changed to avoid occurrence of kernel oopses
157 * during PPP operation.
159 * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
160 * General code review in order to comply with 2.1 kernel standards;
161 * data loss prevention for slow devices revisited (cy_wait_until_sent
163 * removed conditional compilation for new/old PCI structure support
164 * (now the driver only supports the new PCI structure).
166 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
167 * added conditional compilation for new/old PCI structure support;
168 * removed kernel series (2.0.x / 2.1.x) conditional compilation.
170 * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
171 * cleaned up the data loss fix;
172 * fixed XON/XOFF handling once more (Cyclades-Z);
173 * general review of the driver routines;
174 * introduction of a mechanism to prevent data loss with slow
175 * printers, by forcing a delay before closing the port.
177 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
178 * fixed detection/handling of new CD1400 in Ye boards;
179 * fixed XON/XOFF handling (Cyclades-Z);
180 * fixed data loss caused by a premature port close;
181 * introduction of a flag that holds the CD1400 version ID per port
182 * (used by the CYGETCD1400VER new ioctl).
184 * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
185 * Code review for the module cleanup routine;
186 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
187 * includes anonymous changes regarding signal_pending.
189 * Revision 2.1 1997/11/01 17:42:41 ivan
190 * Changes in the driver to support Alpha systems (except 8Zo V_1);
191 * BREAK fix for the Cyclades-Z boards;
192 * driver inactivity control by FW implemented;
193 * introduction of flag that allows driver to take advantage of
194 * a special CD1400 feature related to HW flow control;
195 * added support for the CD1400 rev. J (Cyclom-Y boards);
196 * introduction of ioctls to:
197 * - control the rtsdtr_inv flag (Cyclom-Y);
198 * - control the rflow flag (Cyclom-Y);
199 * - adjust the polling interval (Cyclades-Z);
201 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
202 * Fixes related to kernel version conditional
205 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
206 * Compatibility issues between kernels 2.0.x and
207 * 2.1.x (mainly related to clear_bit function).
209 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
210 * Changes to define the memory window according to the
213 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
214 * Changes to support new cycladesZ boards.
216 * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
217 * Merge of Bentson's and Daniel's version 1.36.4.28.
218 * Corrects bug in cy_detect_pci: check if there are more
219 * ports than the number of static structs allocated.
220 * Warning message during initialization if this driver is
221 * used with the new generation of cycladesZ boards. Those
222 * will be supported only in next release of the driver.
223 * Corrects bug in cy_detect_pci and cy_detect_isa that
224 * returned wrong number of VALID boards, when a cyclomY
225 * was found with no serial modules connected.
226 * Changes to use current (2.1.x) kernel subroutine names
227 * and created macros for compilation with 2.0.x kernel,
228 * instead of the other way around.
230 * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
231 * Change queue_task_irq_off to queue_task_irq.
232 * The inline function queue_task_irq_off (tqueue.h)
233 * was removed from latest releases of 2.1.x kernel.
234 * Use of macro __init to mark the initialization
235 * routines, so memory can be reused.
236 * Also incorporate implementation of critical region
237 * in function cleanup_module() created by anonymous
240 * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
241 * Change to support new firmware that solves DCD problem:
242 * application could fail to receive SIGHUP signal when DCD
245 * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
246 * Changed for support linux versions 2.1.X.
247 * Backward compatible with linux versions 2.0.X.
248 * Corrected illegal use of filler field in
250 * Deleted some debug messages.
252 * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
253 * Included check for NULL tty pointer in cyz_poll.
255 * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
256 * Bill Foster at Blarg! Online services noticed that
257 * some of the switch elements of -Z modem control
258 * lacked a closing "break;"
260 * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
261 * Changed low water threshold for buffer xmit_buf
263 * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
264 * Marcio provided fix to modem status fetch for -Z
266 * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
267 * improve mapping of -Z control page (thanks to Steve
268 * Price <stevep@fa.tdktca.com> for help on this)
270 * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
271 * shift from CPU-bound to memcopy in cyz_polling operation
273 * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
274 * Added support to set and report higher speeds.
276 * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
277 * Some fixes in the HW flow control for the BETA release.
278 * Don't try to register the IRQ.
280 * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
281 * make sure "cyc" appears in all kernel messages; all soft interrupts
282 * handled by same routine; recognize out-of-band reception; comment
283 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
284 * fix race condition in -Z buffer management; only -Y needs to explicitly
285 * flush chars; tidy up some startup messages;
287 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
288 * shift MOD_INC_USE_COUNT location to match
289 * serial.c; purge some diagnostic messages;
291 * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
292 * enable modem status messages and fetch & process them; note
293 * time of last activity type for each port; set_line_char now
294 * supports more than line 0 and treats 0 baud correctly;
295 * get_modem_info senses rs_status;
297 * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
298 * barely works--now's time to turn on
299 * more features 'til it breaks
301 * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
302 * check more -Z board status; shorten boot message
304 * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
305 * fix reference to ch_ctrl in startup; verify return
306 * values from cyz_issue_cmd and cyz_update_channel;
307 * more stuff to get modem control correct;
309 * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
310 * more -Z stuff folded in; re-order changes to put -Z stuff
311 * after -Y stuff (to make changes clearer)
313 * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
314 * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
315 * Add code to send break. Clear firmware ID word at startup (so
316 * that other code won't talk to inactive board).
318 * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
319 * add code for -Z in set_line_char
321 * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
322 * fold more -Z stuff (or in some cases, error messages)
323 * into driver; add text to "don't know what to do" messages.
325 * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
326 * moved compile-time flags near top of file; cosmetic changes
327 * to narrow text (to allow 2-up printing); changed many declarations
328 * to "static" to limit external symbols; shuffled code order to
329 * coalesce -Y and -Z specific code, also to put internal functions
330 * in order of tty_driver structure; added code to recognize -Z
331 * ports (and for moment, do nothing or report error); add cy_startup
332 * to parse boot command line for extra base addresses for ISA probes;
334 * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
335 * reorder some code, fix types of some vars (int vs. long),
336 * add cy_setup to support user declared ISA addresses
338 * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
339 * dump ioctl based firmware load (it's now a user level
340 * program); ensure uninitialzed ports cannot be used
342 * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
343 * rename vars and restructure some code
345 * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
346 * get right status back after boot load
348 * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
349 * successfully loads firmware
351 * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
352 * add more of the code for the boot/load ioctls
354 * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
355 * start to add Z functionality--starting with ioctl
356 * for loading firmware
358 * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
359 * added code to recognize Z/PCI card at initialization; report
360 * presence, but card is not initialized (because firmware needs
363 * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
364 * starting minor number at zero; added missing verify_area
365 * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
367 * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
368 * remove unneeded boot message & fix CLOCAL hardware flow
369 * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
370 * remove unused diagnostic statements; minor 0 is first;
372 * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
373 * The kernel function vremap (available only in later 1.3.xx kernels)
374 * allows the access to memory addresses above the RAM. This revision
375 * of the driver supports PCI boards below 1Mb (device id 0x100) and
376 * above 1Mb (device id 0x101).
378 * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
379 * Some global changes to interrupt handling spilled into
380 * this driver--mostly unused arguments in system function
381 * calls. Also added change by Marcio Saito which should
382 * reduce lost interrupts at startup by fast processors.
384 * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
385 * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
386 * in 1.3.41 kernel to remove a possible race condition, extend
387 * some error messages, and let the driver run as a loadable module
388 * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
389 * possible race condition.
390 * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
392 * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
393 * Changes by Linus Torvalds in 1.3.33 kernel distribution
394 * required due to reordering of driver initialization.
395 * Drivers are now initialized *after* memory management.
397 * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
398 * remove printk from ISR; fix typo
400 * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
401 * Minor fixes in the PCI board support. PCI function calls in
402 * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
403 * <duncan@okay.com>. "bad serial count" message removed.
405 * Revision 1.36.3 1995/08/22 09:19:42 marcio
406 * Cyclom-Y/PCI support added. Changes in the cy_init routine and
407 * board initialization. Changes in the boot messages. The driver
408 * supports up to 4 boards and 64 ports by default.
410 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
411 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
413 * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
414 * add missing break in modem control block in ioctl switch statement
415 * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
417 * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
418 * make sure CTS flow control is set as soon as possible (thanks
419 * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
421 * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
422 * initialize defaults for receive threshold and stale data timeout;
425 * Revision 1.36 1995/03/10 23:33:53 bentson
426 * added support of chips 4-7 in 32 port Cyclom-Ye;
427 * fix cy_interrupt pointer dereference problem
428 * (Joe Portman <baron@aa.net>);
429 * give better error response if open is attempted on non-existent port
430 * (Zachariah Vaum <jchryslr@netcom.com>);
431 * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
432 * conditional compilation for -16Y on systems with fast, noisy bus;
433 * comment out diagnostic print function;
434 * cleaned up table of base addresses;
435 * set receiver time-out period register to correct value,
436 * set receive threshold to better default values,
437 * set chip timer to more accurate 200 Hz ticking,
438 * add code to monitor and modify receive parameters
439 * (Rik Faith <faith@cs.unc.edu> Nick Simicich
440 * <njs@scifi.emi.net>);
442 * Revision 1.35 1994/12/16 13:54:18 steffen
443 * additional patch by Marcio Saito for board detection
444 * Accidently left out in 1.34
446 * Revision 1.34 1994/12/10 12:37:12 steffen
447 * This is the corrected version as suggested by Marcio Saito
449 * Revision 1.33 1994/12/01 22:41:18 bentson
450 * add hooks to support more high speeds directly; add tytso
451 * patch regarding CLOCAL wakeups
453 * Revision 1.32 1994/11/23 19:50:04 bentson
454 * allow direct kernel control of higher signalling rates;
455 * look for cards at additional locations
457 * Revision 1.31 1994/11/16 04:33:28 bentson
458 * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
459 * a problem in chars_in_buffer has been resolved by some
460 * small changes; this should yield smoother output
462 * Revision 1.30 1994/11/16 04:28:05 bentson
463 * Fix from Corey Minyard, Internet: minyard@metronet.com,
464 * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
465 * cy_hangup that appears to clear up much (all?) of the
466 * DTR glitches; also he's added/cleaned-up diagnostic messages
468 * Revision 1.29 1994/11/16 04:16:07 bentson
469 * add change proposed by Ralph Sims, ralphs@halcyon.com, to
470 * operate higher speeds in same way as other serial ports;
471 * add more serial ports (for up to two 16-port muxes).
473 * Revision 1.28 1994/11/04 00:13:16 root
474 * turn off diagnostic messages
476 * Revision 1.27 1994/11/03 23:46:37 root
477 * bunch of changes to bring driver into greater conformance
478 * with the serial.c driver (looking for missed fixes)
480 * Revision 1.26 1994/11/03 22:40:36 root
481 * automatic interrupt probing fixed.
483 * Revision 1.25 1994/11/03 20:17:02 root
484 * start to implement auto-irq
486 * Revision 1.24 1994/11/03 18:01:55 root
487 * still working on modem signals--trying not to drop DTR
488 * during the getty/login processes
490 * Revision 1.23 1994/11/03 17:51:36 root
491 * extend baud rate support; set receive threshold as function
492 * of baud rate; fix some problems with RTS/CTS;
494 * Revision 1.22 1994/11/02 18:05:35 root
495 * changed arguments to udelay to type long to get
496 * delays to be of correct duration
498 * Revision 1.21 1994/11/02 17:37:30 root
499 * employ udelay (after calibrating loops_per_second earlier
500 * in init/main.c) instead of using home-grown delay routines
502 * Revision 1.20 1994/11/02 03:11:38 root
503 * cy_chars_in_buffer forces a return value of 0 to let
504 * login work (don't know why it does); some functions
505 * that were returning EFAULT, now executes the code;
506 * more work on deciding when to disable xmit interrupts;
508 * Revision 1.19 1994/11/01 20:10:14 root
509 * define routine to start transmission interrupts (by enabling
510 * transmit interrupts); directly enable/disable modem interrupts;
512 * Revision 1.18 1994/11/01 18:40:45 bentson
513 * Don't always enable transmit interrupts in startup; interrupt on
514 * TxMpty instead of TxRdy to help characters get out before shutdown;
515 * restructure xmit interrupt to check for chars first and quit if
516 * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
519 * Revision 1.17 1994/10/30 04:39:45 bentson
520 * rename serial_driver and callout_driver to cy_serial_driver and
521 * cy_callout_driver to avoid linkage interference; initialize
522 * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
523 * from cyclades_port structure; add paranoia check to cy_close;
525 * Revision 1.16 1994/10/30 01:14:33 bentson
526 * change major numbers; add some _early_ return statements;
528 * Revision 1.15 1994/10/29 06:43:15 bentson
529 * final tidying up for clean compile; enable some error reporting
531 * Revision 1.14 1994/10/28 20:30:22 Bentson
532 * lots of changes to drag the driver towards the new tty_io
533 * structures and operation. not expected to work, but may
536 * Revision 1.13 1994/07/21 23:08:57 Bentson
537 * add some diagnostic cruft; support 24 lines (for testing
538 * both -8Y and -16Y cards; be more thorough in servicing all
539 * chips during interrupt; add "volatile" a few places to
540 * circumvent compiler optimizations; fix base & offset
541 * computations in block_til_ready (was causing chip 0 to
544 * Revision 1.12 1994/07/19 16:42:11 Bentson
545 * add some hackery for kernel version 1.1.8; expand
546 * error messages; refine timing for delay loops and
547 * declare loop params volatile
549 * Revision 1.11 1994/06/11 21:53:10 bentson
550 * get use of save_car right in transmit interrupt service
552 * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
553 * add some diagnostic printing; try to fix save_car stuff
555 * Revision 1.10 1994/06/11 20:36:08 bentson
556 * clean up compiler warnings
558 * Revision 1.9 1994/06/11 19:42:46 bentson
559 * added a bunch of code to support modem signalling
561 * Revision 1.8 1994/06/11 17:57:07 bentson
562 * recognize break & parity error
564 * Revision 1.7 1994/06/05 05:51:34 bentson
565 * Reorder baud table to be monotonic; add cli to CP; discard
566 * incoming characters and status if the line isn't open; start to
567 * fold code into cy_throttle; start to port get_serial_info,
568 * set_serial_info, get_modem_info, set_modem_info, and send_break
569 * from serial.c; expand cy_ioctl; relocate and expand config_setup;
570 * get flow control characters from tty struct; invalidate ports w/o
573 * Revision 1.6 1994/05/31 18:42:21 bentson
574 * add a loop-breaker in the interrupt service routine;
575 * note when port is initialized so that it can be shut
576 * down under the right conditions; receive works without
579 * Revision 1.5 1994/05/30 00:55:02 bentson
580 * transmit works without obvious errors
582 * Revision 1.4 1994/05/27 18:46:27 bentson
583 * incorporated more code from lib_y.c; can now print short
584 * strings under interrupt control to port zero; seems to
585 * select ports/channels/lines correctly
587 * Revision 1.3 1994/05/25 22:12:44 bentson
588 * shifting from multi-port on a card to proper multiplexor
589 * data structures; added skeletons of most routines
591 * Revision 1.2 1994/05/19 13:21:43 bentson
592 * start to crib from other sources
596 /* If you need to install more boards than NR_CARDS, change the constant
597 in the definition below. No other change is necessary to support up to
598 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
603 If the total number of ports is larger than NR_PORTS, change this
604 constant in the definition below. No other change is necessary to
605 support more boards/ports. */
609 #define ZE_V1_NPORTS 64
614 #define SERIAL_PARANOIA_CHECK
616 #undef CY_DEBUG_THROTTLE
617 #undef CY_DEBUG_OTHER
619 #undef CY_DEBUG_COUNT
621 #undef CY_DEBUG_WAIT_UNTIL_SENT
622 #undef CY_DEBUG_INTERRUPTS
624 #undef CY_ENABLE_MONITORING
628 #define PAUSE __asm__("nop");
636 #include <linux/module.h>
637 #include <linux/errno.h>
638 #include <linux/signal.h>
639 #include <linux/sched.h>
640 #include <linux/timer.h>
641 #include <linux/interrupt.h>
642 #include <linux/tty.h>
643 #include <linux/tty_flip.h>
644 #include <linux/serial.h>
645 #include <linux/major.h>
646 #include <linux/string.h>
647 #include <linux/fcntl.h>
648 #include <linux/ptrace.h>
649 #include <linux/cyclades.h>
650 #include <linux/mm.h>
651 #include <linux/ioport.h>
652 #include <linux/init.h>
653 #include <linux/delay.h>
654 #include <linux/spinlock.h>
655 #include <linux/bitops.h>
657 #include <asm/system.h>
660 #include <asm/uaccess.h>
662 #define CY_LOCK(info,flags) \
664 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
667 #define CY_UNLOCK(info,flags) \
669 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
672 #include <linux/types.h>
673 #include <linux/kernel.h>
674 #include <linux/pci.h>
676 #include <linux/stat.h>
677 #include <linux/proc_fs.h>
679 static void cy_throttle (struct tty_struct
*tty
);
680 static void cy_send_xchar (struct tty_struct
*tty
, char ch
);
682 #define IS_CYC_Z(card) ((card).num_chips == -1)
684 #define Z_FPGA_CHECK(card) \
685 ((cy_readl(&((struct RUNTIME_9060 __iomem *) \
686 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
688 #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 __iomem *) \
689 ((card).ctl_addr))->mail_box_0)) || \
690 Z_FPGA_CHECK(card)) && \
691 (ZFIRM_ID==cy_readl(&((struct FIRM_ID __iomem *) \
692 ((card).base_addr+ID_ADDRESS))->signature)))
694 #ifndef SERIAL_XMIT_SIZE
695 #define SERIAL_XMIT_SIZE (min(PAGE_SIZE, 4096))
697 #define WAKEUP_CHARS 256
699 #define STD_COM_FLAGS (0)
701 #define JIFFIES_DIFF(n, j) ((j) - (n))
703 static struct tty_driver
*cy_serial_driver
;
706 /* This is the address lookup table. The driver will probe for
707 Cyclom-Y/ISA boards at all addresses in here. If you want the
708 driver to probe addresses at a different address, add it to
709 this table. If the driver is probing some other board and
710 causing problems, remove the offending address from this table.
711 The cy_setup function extracts additional addresses from the
712 boot options line. The form is "cyclades=address,address..."
715 static unsigned int cy_isa_addresses
[] = {
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,
764 static char baud_co_25
[] = { /* 25 MHz clock option table */
765 /* value => 00 01 02 03 04 */
766 /* divide by 8 32 128 512 2048 */
767 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
768 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
770 static char baud_bpr_25
[] = { /* 25 MHz baud rate period table */
771 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
772 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
774 static char baud_co_60
[] = { /* 60 MHz clock option table (CD1400 J) */
775 /* value => 00 01 02 03 04 */
776 /* divide by 8 32 128 512 2048 */
777 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
778 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
781 static char baud_bpr_60
[] = { /* 60 MHz baud rate period table (CD1400 J) */
782 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
783 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
786 static char baud_cor3
[] = { /* receive threshold */
787 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
788 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
792 * The Cyclades driver implements HW flow control as any serial driver.
793 * The cyclades_port structure member rflow and the vector rflow_thr
794 * allows us to take advantage of a special feature in the CD1400 to avoid
795 * data loss even when the system interrupt latency is too high. These flags
796 * are to be used only with very special applications. Setting these flags
797 * requires the use of a special cable (DTR and RTS reversed). In the new
798 * CD1400-based boards (rev. 6.00 or later), there is no need for special
802 static char rflow_thr
[] = { /* rflow threshold */
803 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
804 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
807 /* The Cyclom-Ye has placed the sequential chips in non-sequential
808 * address order. This look-up table overcomes that problem.
810 static int cy_chip_offset
[] =
821 /* PCI related definitions */
823 static unsigned short cy_pci_nboard
;
824 static unsigned short cy_isa_nboard
;
825 static unsigned short cy_nboard
;
827 static unsigned short cy_pci_dev_id
[] = {
828 PCI_DEVICE_ID_CYCLOM_Y_Lo
, /* PCI < 1Mb */
829 PCI_DEVICE_ID_CYCLOM_Y_Hi
, /* PCI > 1Mb */
830 PCI_DEVICE_ID_CYCLOM_4Y_Lo
, /* 4Y PCI < 1Mb */
831 PCI_DEVICE_ID_CYCLOM_4Y_Hi
, /* 4Y PCI > 1Mb */
832 PCI_DEVICE_ID_CYCLOM_8Y_Lo
, /* 8Y PCI < 1Mb */
833 PCI_DEVICE_ID_CYCLOM_8Y_Hi
, /* 8Y PCI > 1Mb */
834 PCI_DEVICE_ID_CYCLOM_Z_Lo
, /* Z PCI < 1Mb */
835 PCI_DEVICE_ID_CYCLOM_Z_Hi
, /* Z PCI > 1Mb */
840 static void cy_start(struct tty_struct
*);
841 static void set_line_char(struct cyclades_port
*);
842 static int cyz_issue_cmd(struct cyclades_card
*, uclong
, ucchar
, uclong
);
844 static unsigned detect_isa_irq(void __iomem
*);
845 #endif /* CONFIG_ISA */
847 static int cyclades_get_proc_info(char *, char **, off_t
, int , int *, void *);
849 #ifndef CONFIG_CYZ_INTR
850 static void cyz_poll(unsigned long);
852 /* The Cyclades-Z polling cycle is defined by this variable */
853 static long cyz_polling_cycle
= CZ_DEF_POLL
;
855 static int cyz_timeron
= 0;
856 static DEFINE_TIMER(cyz_timerlist
, cyz_poll
, 0, 0);
858 #else /* CONFIG_CYZ_INTR */
859 static void cyz_rx_restart(unsigned long);
860 static struct timer_list cyz_rx_full_timer
[NR_PORTS
];
861 #endif /* CONFIG_CYZ_INTR */
864 serial_paranoia_check(struct cyclades_port
*info
,
865 char *name
, const char *routine
)
867 #ifdef SERIAL_PARANOIA_CHECK
868 static const char *badmagic
=
869 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
870 static const char *badinfo
=
871 "cyc Warning: null cyclades_port for (%s) in %s\n";
872 static const char *badrange
=
873 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
876 printk(badinfo
, name
, routine
);
880 if( (long)info
< (long)(&cy_port
[0])
881 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
882 printk(badrange
, name
, routine
);
886 if (info
->magic
!= CYCLADES_MAGIC
) {
887 printk(badmagic
, name
, routine
);
892 } /* serial_paranoia_check */
895 * This routine is used by the interrupt handler to schedule
896 * processing in the software interrupt portion of the driver
897 * (also known as the "bottom half"). This can be called any
898 * number of times for any channel without harm.
901 cy_sched_event(struct cyclades_port
*info
, int event
)
903 info
->event
|= 1 << event
; /* remember what kind of event and who */
904 schedule_work(&info
->tqueue
);
905 } /* cy_sched_event */
909 * This routine is used to handle the "bottom half" processing for the
910 * serial driver, known also the "software interrupt" processing.
911 * This processing is done at the kernel interrupt level, after the
912 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
913 * is where time-consuming activities which can not be done in the
914 * interrupt driver proper are done; the interrupt driver schedules
915 * them using cy_sched_event(), and they get done here.
917 * This is done through one level of indirection--the task queue.
918 * When a hardware interrupt service routine wants service by the
919 * driver's bottom half, it enqueues the appropriate tq_struct (one
920 * per port) to the keventd work queue and sets a request flag
921 * that the work queue be processed.
923 * Although this may seem unwieldy, it gives the system a way to
924 * pass an argument (in this case the pointer to the cyclades_port
925 * structure) to the bottom half of the driver. Previous kernels
926 * had to poll every port to see if that port needed servicing.
929 do_softint(struct work_struct
*work
)
931 struct cyclades_port
*info
=
932 container_of(work
, struct cyclades_port
, tqueue
);
933 struct tty_struct
*tty
;
939 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
940 tty_hangup(info
->tty
);
941 wake_up_interruptible(&info
->open_wait
);
942 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
944 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
945 wake_up_interruptible(&info
->open_wait
);
947 #ifdef CONFIG_CYZ_INTR
948 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL
, &info
->event
)) {
949 if (cyz_rx_full_timer
[info
->line
].function
== NULL
) {
950 cyz_rx_full_timer
[info
->line
].expires
= jiffies
+ 1;
951 cyz_rx_full_timer
[info
->line
].function
= cyz_rx_restart
;
952 cyz_rx_full_timer
[info
->line
].data
= (unsigned long)info
;
953 add_timer(&cyz_rx_full_timer
[info
->line
]);
957 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP
, &info
->event
)) {
958 wake_up_interruptible(&info
->delta_msr_wait
);
960 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
962 wake_up_interruptible(&tty
->write_wait
);
965 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP
, &info
->event
)) {
966 wake_up_interruptible(&info
->shutdown_wait
);
972 /***********************************************************/
973 /********* Start of block of Cyclom-Y specific code ********/
975 /* This routine waits up to 1000 micro-seconds for the previous
976 command to the Cirrus chip to complete and then issues the
977 new command. An error is returned if the previous command
978 didn't finish within the time limit.
980 This function is only called from inside spinlock-protected code.
983 cyy_issue_cmd(void __iomem
*base_addr
, u_char cmd
, int index
)
987 /* Check to see that the previous command has completed */
988 for(i
= 0 ; i
< 100 ; i
++){
989 if (cy_readb(base_addr
+(CyCCR
<<index
)) == 0){
994 /* if the CCR never cleared, the previous command
995 didn't finish within the "reasonable time" */
996 if (i
== 100) return (-1);
998 /* Issue the new command */
999 cy_writeb(base_addr
+(CyCCR
<<index
), cmd
);
1002 } /* cyy_issue_cmd */
1005 /* ISA interrupt detection code */
1007 detect_isa_irq(void __iomem
*address
)
1010 unsigned long irqs
, flags
;
1011 int save_xir
, save_car
;
1012 int index
= 0; /* IRQ probing is only for ISA */
1014 /* forget possible initially masked and pending IRQ */
1015 irq
= probe_irq_off(probe_irq_on());
1017 /* Clear interrupts on the board first */
1018 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1019 /* Cy_ClrIntr is 0x1800 */
1021 irqs
= probe_irq_on();
1025 /* Enable the Tx interrupts on the CD1400 */
1026 local_irq_save(flags
);
1027 cy_writeb(address
+ (CyCAR
<<index
), 0);
1028 cyy_issue_cmd(address
, CyCHAN_CTL
|CyENB_XMTR
, index
);
1030 cy_writeb(address
+ (CyCAR
<<index
), 0);
1031 cy_writeb(address
+ (CySRER
<<index
),
1032 cy_readb(address
+ (CySRER
<<index
)) | CyTxRdy
);
1033 local_irq_restore(flags
);
1038 /* Check which interrupt is in use */
1039 irq
= probe_irq_off(irqs
);
1042 save_xir
= (u_char
) cy_readb(address
+ (CyTIR
<<index
));
1043 save_car
= cy_readb(address
+ (CyCAR
<<index
));
1044 cy_writeb(address
+ (CyCAR
<<index
), (save_xir
& 0x3));
1045 cy_writeb(address
+ (CySRER
<<index
),
1046 cy_readb(address
+ (CySRER
<<index
)) & ~CyTxRdy
);
1047 cy_writeb(address
+ (CyTIR
<<index
), (save_xir
& 0x3f));
1048 cy_writeb(address
+ (CyCAR
<<index
), (save_car
));
1049 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1050 /* Cy_ClrIntr is 0x1800 */
1052 return (irq
> 0)? irq
: 0;
1054 #endif /* CONFIG_ISA */
1056 /* The real interrupt service routine is called
1057 whenever the card wants its hand held--chars
1058 received, out buffer empty, modem change, etc.
1061 cyy_interrupt(int irq
, void *dev_id
)
1063 struct tty_struct
*tty
;
1065 struct cyclades_card
*cinfo
;
1066 struct cyclades_port
*info
;
1067 void __iomem
*base_addr
, *card_base_addr
;
1069 int save_xir
, channel
, save_car
;
1071 volatile int char_count
;
1079 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1080 #ifdef CY_DEBUG_INTERRUPTS
1081 printk("cyy_interrupt: spurious interrupt %d\n\r", irq
);
1083 return IRQ_NONE
; /* spurious interrupt */
1086 card_base_addr
= cinfo
->base_addr
;
1087 index
= cinfo
->bus_index
;
1090 /* This loop checks all chips in the card. Make a note whenever
1091 _any_ chip had some work to do, as this is considered an
1092 indication that there will be more to do. Only when no chip
1093 has any work does this outermost loop exit.
1097 for ( chip
= 0 ; chip
< cinfo
->num_chips
; chip
++) {
1098 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
1100 while ( (status
= cy_readb(base_addr
+(CySVRR
<<index
))) != 0x00) {
1102 /* The purpose of the following test is to ensure that
1103 no chip can monopolize the driver. This forces the
1104 chips to be checked in a round-robin fashion (after
1105 draining each of a bunch (1000) of characters).
1107 if(1000<too_many
++){
1110 if (status
& CySRReceive
) { /* reception interrupt */
1111 #ifdef CY_DEBUG_INTERRUPTS
1112 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip
);
1114 /* determine the channel & change to that context */
1115 spin_lock(&cinfo
->card_lock
);
1116 save_xir
= (u_char
) cy_readb(base_addr
+(CyRIR
<<index
));
1117 channel
= (u_short
) (save_xir
& CyIRChannel
);
1118 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1120 info
->last_active
= jiffies
;
1121 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1122 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1124 /* if there is nowhere to put the data, discard it */
1126 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1127 if ( j
== CyIVRRxEx
) { /* exception */
1128 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1129 } else { /* normal character reception */
1130 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1131 while(char_count
--){
1132 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1135 }else{ /* there is an open port for this data */
1137 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1138 if ( j
== CyIVRRxEx
) { /* exception */
1139 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1141 /* For statistics only */
1144 else if(data
& CyFRAME
)
1145 info
->icount
.frame
++;
1146 else if(data
& CyPARITY
)
1147 info
->icount
.parity
++;
1148 else if(data
& CyOVERRUN
)
1149 info
->icount
.overrun
++;
1151 if(data
& info
->ignore_status_mask
){
1155 if (tty_buffer_request_room(tty
, 1)) {
1156 if (data
& info
->read_status_mask
){
1158 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_BREAK
);
1160 if (info
->flags
& ASYNC_SAK
){
1163 }else if(data
& CyFRAME
){
1164 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_FRAME
);
1166 info
->idle_stats
.frame_errs
++;
1167 }else if(data
& CyPARITY
){
1168 /* Pieces of seven... */
1169 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_PARITY
);
1171 info
->idle_stats
.parity_errs
++;
1172 }else if(data
& CyOVERRUN
){
1173 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
1175 /* If the flip buffer itself is
1176 overflowing, we still lose
1177 the next incoming character.
1179 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_FRAME
);
1181 info
->idle_stats
.overruns
++;
1182 /* These two conditions may imply */
1183 /* a normal read should be done. */
1184 /* }else if(data & CyTIMEOUT){ */
1185 /* }else if(data & CySPECHAR){ */
1187 tty_insert_flip_char(tty
, 0, TTY_NORMAL
);
1191 tty_insert_flip_char(tty
, 0, TTY_NORMAL
);
1195 /* there was a software buffer
1196 overrun and nothing could be
1198 info
->icount
.buf_overrun
++;
1199 info
->idle_stats
.overruns
++;
1201 } else { /* normal character reception */
1202 /* load # chars available from the chip */
1203 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1205 #ifdef CY_ENABLE_MONITORING
1206 ++info
->mon
.int_count
;
1207 info
->mon
.char_count
+= char_count
;
1208 if (char_count
> info
->mon
.char_max
)
1209 info
->mon
.char_max
= char_count
;
1210 info
->mon
.char_last
= char_count
;
1212 len
= tty_buffer_request_room(tty
, char_count
);
1214 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1215 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
1216 info
->idle_stats
.recv_bytes
++;
1222 info
->idle_stats
.recv_idle
= jiffies
;
1224 tty_schedule_flip(tty
);
1226 /* end of service */
1227 cy_writeb(base_addr
+(CyRIR
<<index
), (save_xir
& 0x3f));
1228 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1229 spin_unlock(&cinfo
->card_lock
);
1233 if (status
& CySRTransmit
) { /* transmission interrupt */
1234 /* Since we only get here when the transmit buffer
1235 is empty, we know we can always stuff a dozen
1237 #ifdef CY_DEBUG_INTERRUPTS
1238 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip
);
1241 /* determine the channel & change to that context */
1242 spin_lock(&cinfo
->card_lock
);
1243 save_xir
= (u_char
) cy_readb(base_addr
+(CyTIR
<<index
));
1244 channel
= (u_short
) (save_xir
& CyIRChannel
);
1245 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1246 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1247 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1249 /* validate the port# (as configured and open) */
1250 if( (i
< 0) || (NR_PORTS
<= i
) ){
1251 cy_writeb(base_addr
+(CySRER
<<index
),
1252 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1256 info
->last_active
= jiffies
;
1258 cy_writeb(base_addr
+(CySRER
<<index
),
1259 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1263 /* load the on-chip space for outbound data */
1264 char_count
= info
->xmit_fifo_size
;
1266 if(info
->x_char
) { /* send special char */
1267 outch
= info
->x_char
;
1268 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1274 if (info
->breakon
|| info
->breakoff
) {
1275 if (info
->breakon
) {
1276 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1277 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x81);
1281 if (info
->breakoff
) {
1282 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1283 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x83);
1289 while (char_count
-- > 0){
1290 if (!info
->xmit_cnt
){
1291 if (cy_readb(base_addr
+(CySRER
<<index
))&CyTxMpty
) {
1292 cy_writeb(base_addr
+(CySRER
<<index
),
1293 cy_readb(base_addr
+(CySRER
<<index
)) &
1296 cy_writeb(base_addr
+(CySRER
<<index
),
1297 ((cy_readb(base_addr
+(CySRER
<<index
))
1303 if (info
->xmit_buf
== 0){
1304 cy_writeb(base_addr
+(CySRER
<<index
),
1305 cy_readb(base_addr
+(CySRER
<<index
)) &
1309 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
1310 cy_writeb(base_addr
+(CySRER
<<index
),
1311 cy_readb(base_addr
+(CySRER
<<index
)) &
1315 /* Because the Embedded Transmit Commands have
1316 been enabled, we must check to see if the
1317 escape character, NULL, is being sent. If it
1318 is, we must ensure that there is room for it
1319 to be doubled in the output stream. Therefore
1320 we no longer advance the pointer when the
1321 character is fetched, but rather wait until
1322 after the check for a NULL output character.
1323 This is necessary because there may not be
1324 room for the two chars needed to send a NULL.)
1326 outch
= info
->xmit_buf
[info
->xmit_tail
];
1329 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1330 & (SERIAL_XMIT_SIZE
- 1);
1331 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1336 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1337 & (SERIAL_XMIT_SIZE
- 1);
1338 cy_writeb(base_addr
+(CyTDR
<<index
),
1340 cy_writeb(base_addr
+(CyTDR
<<index
), 0);
1349 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1350 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1353 /* end of service */
1354 cy_writeb(base_addr
+(CyTIR
<<index
),
1356 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1357 spin_unlock(&cinfo
->card_lock
);
1360 if (status
& CySRModem
) { /* modem interrupt */
1362 /* determine the channel & change to that context */
1363 spin_lock(&cinfo
->card_lock
);
1364 save_xir
= (u_char
) cy_readb(base_addr
+(CyMIR
<<index
));
1365 channel
= (u_short
) (save_xir
& CyIRChannel
);
1366 info
= &cy_port
[channel
+ chip
* 4
1367 + cinfo
->first_line
];
1368 info
->last_active
= jiffies
;
1369 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1370 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1372 mdm_change
= cy_readb(base_addr
+(CyMISR
<<index
));
1373 mdm_status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
1375 if(info
->tty
== 0){/* no place for data, ignore it*/
1378 if (mdm_change
& CyANY_DELTA
) {
1379 /* For statistics only */
1380 if (mdm_change
& CyDCD
) info
->icount
.dcd
++;
1381 if (mdm_change
& CyCTS
) info
->icount
.cts
++;
1382 if (mdm_change
& CyDSR
) info
->icount
.dsr
++;
1383 if (mdm_change
& CyRI
) info
->icount
.rng
++;
1385 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1388 if((mdm_change
& CyDCD
)
1389 && (info
->flags
& ASYNC_CHECK_CD
)){
1390 if(mdm_status
& CyDCD
){
1391 cy_sched_event(info
,
1392 Cy_EVENT_OPEN_WAKEUP
);
1394 cy_sched_event(info
,
1398 if((mdm_change
& CyCTS
)
1399 && (info
->flags
& ASYNC_CTS_FLOW
)){
1400 if(info
->tty
->hw_stopped
){
1401 if(mdm_status
& CyCTS
){
1402 /* cy_start isn't used
1404 info
->tty
->hw_stopped
= 0;
1405 cy_writeb(base_addr
+(CySRER
<<index
),
1406 cy_readb(base_addr
+(CySRER
<<index
)) |
1408 cy_sched_event(info
,
1409 Cy_EVENT_WRITE_WAKEUP
);
1412 if(!(mdm_status
& CyCTS
)){
1413 /* cy_stop isn't used
1415 info
->tty
->hw_stopped
= 1;
1416 cy_writeb(base_addr
+(CySRER
<<index
),
1417 cy_readb(base_addr
+(CySRER
<<index
)) &
1422 if(mdm_change
& CyDSR
){
1424 if(mdm_change
& CyRI
){
1427 /* end of service */
1428 cy_writeb(base_addr
+(CyMIR
<<index
),
1430 cy_writeb(base_addr
+(CyCAR
<<index
), save_car
);
1431 spin_unlock(&cinfo
->card_lock
);
1433 } /* end while status != 0 */
1434 } /* end loop for chips... */
1437 /* clear interrupts */
1438 spin_lock(&cinfo
->card_lock
);
1439 cy_writeb(card_base_addr
+ (Cy_ClrIntr
<<index
), 0);
1440 /* Cy_ClrIntr is 0x1800 */
1441 spin_unlock(&cinfo
->card_lock
);
1443 } /* cyy_interrupt */
1445 /***********************************************************/
1446 /********* End of block of Cyclom-Y specific code **********/
1447 /******** Start of block of Cyclades-Z specific code *********/
1448 /***********************************************************/
1451 cyz_fetch_msg( struct cyclades_card
*cinfo
,
1452 uclong
*channel
, ucchar
*cmd
, uclong
*param
)
1454 struct FIRM_ID __iomem
*firm_id
;
1455 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1456 struct BOARD_CTRL __iomem
*board_ctrl
;
1457 unsigned long loc_doorbell
;
1459 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1460 if (!ISZLOADED(*cinfo
)){
1463 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1464 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1466 loc_doorbell
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
1467 (cinfo
->ctl_addr
))->loc_doorbell
);
1469 *cmd
= (char)(0xff & loc_doorbell
);
1470 *channel
= cy_readl(&board_ctrl
->fwcmd_channel
);
1471 *param
= (uclong
)cy_readl(&board_ctrl
->fwcmd_param
);
1472 cy_writel(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->loc_doorbell
,
1477 } /* cyz_fetch_msg */
1480 cyz_issue_cmd( struct cyclades_card
*cinfo
,
1481 uclong channel
, ucchar cmd
, uclong param
)
1483 struct FIRM_ID __iomem
*firm_id
;
1484 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1485 struct BOARD_CTRL __iomem
*board_ctrl
;
1486 unsigned long __iomem
*pci_doorbell
;
1489 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1490 if (!ISZLOADED(*cinfo
)){
1493 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1494 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1497 pci_doorbell
= &((struct RUNTIME_9060 __iomem
*) (cinfo
->ctl_addr
))->pci_doorbell
;
1498 while( (cy_readl(pci_doorbell
) & 0xff) != 0){
1499 if (index
++ == 1000){
1500 return((int)(cy_readl(pci_doorbell
) & 0xff));
1504 cy_writel(&board_ctrl
->hcmd_channel
, channel
);
1505 cy_writel(&board_ctrl
->hcmd_param
, param
);
1506 cy_writel(pci_doorbell
, (long)cmd
);
1509 } /* cyz_issue_cmd */
1512 cyz_handle_rx(struct cyclades_port
*info
,
1513 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1514 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1516 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1517 struct tty_struct
*tty
= info
->tty
;
1518 volatile int char_count
;
1525 volatile uclong rx_put
, rx_get
, new_rx_get
, rx_bufsize
, rx_bufaddr
;
1527 rx_get
= new_rx_get
= cy_readl(&buf_ctrl
->rx_get
);
1528 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1529 rx_bufsize
= cy_readl(&buf_ctrl
->rx_bufsize
);
1530 rx_bufaddr
= cy_readl(&buf_ctrl
->rx_bufaddr
);
1531 if (rx_put
>= rx_get
)
1532 char_count
= rx_put
- rx_get
;
1534 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1537 info
->last_active
= jiffies
;
1538 info
->jiffies
[1] = jiffies
;
1540 #ifdef CY_ENABLE_MONITORING
1541 info
->mon
.int_count
++;
1542 info
->mon
.char_count
+= char_count
;
1543 if (char_count
> info
->mon
.char_max
)
1544 info
->mon
.char_max
= char_count
;
1545 info
->mon
.char_last
= char_count
;
1548 /* flush received characters */
1549 new_rx_get
= (new_rx_get
+ char_count
) & (rx_bufsize
- 1);
1550 info
->rflush_count
++;
1553 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1554 for performance, but because of buffer boundaries, there
1555 may be several steps to the operation */
1556 while(0 < (small_count
=
1557 min_t(unsigned int, (rx_bufsize
- new_rx_get
),
1558 min_t(unsigned int, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
), char_count
))
1560 memcpy_fromio(tty
->flip
.char_buf_ptr
,
1561 (char *)(cinfo
->base_addr
1562 + rx_bufaddr
+ new_rx_get
),
1565 tty
->flip
.char_buf_ptr
+= small_count
;
1566 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, small_count
);
1567 tty
->flip
.flag_buf_ptr
+= small_count
;
1568 new_rx_get
= (new_rx_get
+ small_count
) & (rx_bufsize
- 1);
1569 char_count
-= small_count
;
1570 info
->icount
.rx
+= small_count
;
1571 info
->idle_stats
.recv_bytes
+= small_count
;
1572 tty
->flip
.count
+= small_count
;
1575 len
= tty_buffer_request_room(tty
, char_count
);
1577 data
= cy_readb(cinfo
->base_addr
+ rx_bufaddr
+ new_rx_get
);
1578 new_rx_get
= (new_rx_get
+ 1) & (rx_bufsize
- 1);
1579 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
1580 info
->idle_stats
.recv_bytes
++;
1584 #ifdef CONFIG_CYZ_INTR
1585 /* Recalculate the number of chars in the RX buffer and issue
1586 a cmd in case it's higher than the RX high water mark */
1587 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1588 if (rx_put
>= rx_get
)
1589 char_count
= rx_put
- rx_get
;
1591 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1592 if(char_count
>= cy_readl(&buf_ctrl
->rx_threshold
)) {
1593 cy_sched_event(info
, Cy_EVENT_Z_RX_FULL
);
1596 info
->idle_stats
.recv_idle
= jiffies
;
1597 tty_schedule_flip(tty
);
1600 cy_writel(&buf_ctrl
->rx_get
, new_rx_get
);
1605 cyz_handle_tx(struct cyclades_port
*info
,
1606 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1607 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1609 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1610 struct tty_struct
*tty
= info
->tty
;
1612 volatile int char_count
;
1616 volatile uclong tx_put
, tx_get
, tx_bufsize
, tx_bufaddr
;
1618 if (info
->xmit_cnt
<= 0) /* Nothing to transmit */
1621 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
1622 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
1623 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
1624 tx_bufaddr
= cy_readl(&buf_ctrl
->tx_bufaddr
);
1625 if (tx_put
>= tx_get
)
1626 char_count
= tx_get
- tx_put
- 1 + tx_bufsize
;
1628 char_count
= tx_get
- tx_put
- 1;
1636 if(info
->x_char
) { /* send special char */
1637 data
= info
->x_char
;
1639 cy_writeb((cinfo
->base_addr
+ tx_bufaddr
+ tx_put
), data
);
1640 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1644 info
->last_active
= jiffies
;
1645 info
->jiffies
[2] = jiffies
;
1648 while(0 < (small_count
=
1649 min_t(unsigned int, (tx_bufsize
- tx_put
),
1650 min_t(unsigned int, (SERIAL_XMIT_SIZE
- info
->xmit_tail
),
1651 min_t(unsigned int, info
->xmit_cnt
, char_count
))))) {
1653 memcpy_toio((char *)(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
),
1654 &info
->xmit_buf
[info
->xmit_tail
],
1657 tx_put
= (tx_put
+ small_count
) & (tx_bufsize
- 1);
1658 char_count
-= small_count
;
1659 info
->icount
.tx
+= small_count
;
1660 info
->xmit_cnt
-= small_count
;
1662 (info
->xmit_tail
+ small_count
) & (SERIAL_XMIT_SIZE
- 1);
1663 info
->last_active
= jiffies
;
1664 info
->jiffies
[2] = jiffies
;
1667 while (info
->xmit_cnt
&& char_count
){
1668 data
= info
->xmit_buf
[info
->xmit_tail
];
1670 info
->xmit_tail
= (info
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
1672 cy_writeb(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
, data
);
1673 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1676 info
->last_active
= jiffies
;
1677 info
->jiffies
[2] = jiffies
;
1681 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1682 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1685 cy_writel(&buf_ctrl
->tx_put
, tx_put
);
1690 cyz_handle_cmd(struct cyclades_card
*cinfo
)
1692 struct tty_struct
*tty
;
1693 struct cyclades_port
*info
;
1694 static volatile struct FIRM_ID __iomem
*firm_id
;
1695 static volatile struct ZFW_CTRL __iomem
*zfw_ctrl
;
1696 static volatile struct BOARD_CTRL __iomem
*board_ctrl
;
1697 static volatile struct CH_CTRL __iomem
*ch_ctrl
;
1698 static volatile struct BUF_CTRL __iomem
*buf_ctrl
;
1702 uclong hw_ver
, fw_ver
;
1706 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1707 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1708 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1709 fw_ver
= cy_readl(&board_ctrl
->fw_version
);
1710 hw_ver
= cy_readl(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->mail_box_0
);
1713 while(cyz_fetch_msg(cinfo
, &channel
, &cmd
, ¶m
) == 1) {
1716 info
= &cy_port
[channel
+ cinfo
->first_line
];
1717 if((tty
= info
->tty
) == 0) {
1720 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
1721 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
1725 tty_insert_flip_char(tty
, 0, TTY_PARITY
);
1730 tty_insert_flip_char(tty
, 0, TTY_FRAME
);
1735 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
1742 if (info
->flags
& ASYNC_CHECK_CD
){
1745 cy_readl(&ch_ctrl
->rs_status
)) & C_RS_DCD
) {
1746 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
1748 cy_sched_event(info
, Cy_EVENT_HANGUP
);
1766 cy_sched_event(info
, Cy_EVENT_SHUTDOWN_WAKEUP
);
1769 #ifdef CONFIG_CYZ_INTR
1773 /* Reception Interrupt */
1774 #ifdef CY_DEBUG_INTERRUPTS
1775 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
1776 info
->card
, channel
);
1778 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1783 /* Transmission Interrupt */
1784 #ifdef CY_DEBUG_INTERRUPTS
1785 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
1786 info
->card
, channel
);
1788 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1790 #endif /* CONFIG_CYZ_INTR */
1792 /* should do something with this !!! */
1798 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1800 tty_schedule_flip(tty
);
1804 #ifdef CONFIG_CYZ_INTR
1806 cyz_interrupt(int irq
, void *dev_id
)
1808 struct cyclades_card
*cinfo
;
1810 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1811 #ifdef CY_DEBUG_INTERRUPTS
1812 printk("cyz_interrupt: spurious interrupt %d\n\r", irq
);
1814 return IRQ_NONE
; /* spurious interrupt */
1817 if (!ISZLOADED(*cinfo
)) {
1818 #ifdef CY_DEBUG_INTERRUPTS
1819 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq
);
1824 /* Handle the interrupts */
1825 cyz_handle_cmd(cinfo
);
1828 } /* cyz_interrupt */
1831 cyz_rx_restart(unsigned long arg
)
1833 struct cyclades_port
*info
= (struct cyclades_port
*)arg
;
1835 int card
= info
->card
;
1836 uclong channel
= (info
->line
) - (cy_card
[card
].first_line
);
1837 unsigned long flags
;
1839 CY_LOCK(info
, flags
);
1840 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK2
, 0L);
1842 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1843 info
->line
, retval
);
1845 cyz_rx_full_timer
[info
->line
].function
= NULL
;
1846 CY_UNLOCK(info
, flags
);
1849 #else /* CONFIG_CYZ_INTR */
1852 cyz_poll(unsigned long arg
)
1854 struct cyclades_card
*cinfo
;
1855 struct cyclades_port
*info
;
1856 struct tty_struct
*tty
;
1857 static volatile struct FIRM_ID
*firm_id
;
1858 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1859 static volatile struct BOARD_CTRL
*board_ctrl
;
1860 static volatile struct CH_CTRL
*ch_ctrl
;
1861 static volatile struct BUF_CTRL
*buf_ctrl
;
1864 cyz_timerlist
.expires
= jiffies
+ (HZ
);
1865 for (card
= 0 ; card
< NR_CARDS
; card
++){
1866 cinfo
= &cy_card
[card
];
1868 if (!IS_CYC_Z(*cinfo
)) continue;
1869 if (!ISZLOADED(*cinfo
)) continue;
1871 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1872 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1873 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1875 /* Skip first polling cycle to avoid racing conditions with the FW */
1876 if (!cinfo
->intr_enabled
) {
1877 cinfo
->nports
= (int) cy_readl(&board_ctrl
->n_channel
);
1878 cinfo
->intr_enabled
= 1;
1882 cyz_handle_cmd(cinfo
);
1884 for (port
= 0 ; port
< cinfo
->nports
; port
++) {
1885 info
= &cy_port
[ port
+ cinfo
->first_line
];
1887 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[port
]);
1888 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[port
]);
1890 if (!info
->throttle
)
1891 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1892 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1894 /* poll every 'cyz_polling_cycle' period */
1895 cyz_timerlist
.expires
= jiffies
+ cyz_polling_cycle
;
1897 add_timer(&cyz_timerlist
);
1902 #endif /* CONFIG_CYZ_INTR */
1904 /********** End of block of Cyclades-Z specific code *********/
1905 /***********************************************************/
1908 /* This is called whenever a port becomes active;
1909 interrupts are enabled and DTR & RTS are turned on.
1912 startup(struct cyclades_port
* info
)
1914 unsigned long flags
;
1916 void __iomem
*base_addr
;
1917 int card
,chip
,channel
,index
;
1921 channel
= (info
->line
) - (cy_card
[card
].first_line
);
1923 page
= get_zeroed_page(GFP_KERNEL
);
1927 CY_LOCK(info
, flags
);
1929 if (info
->flags
& ASYNC_INITIALIZED
){
1936 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1945 info
->xmit_buf
= (unsigned char *) page
;
1947 CY_UNLOCK(info
, flags
);
1949 set_line_char(info
);
1951 if (!IS_CYC_Z(cy_card
[card
])) {
1954 index
= cy_card
[card
].bus_index
;
1955 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
1957 #ifdef CY_DEBUG_OPEN
1958 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
1959 card
, chip
, channel
, (long)base_addr
);/**/
1962 CY_LOCK(info
, flags
);
1964 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
1966 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
1967 ? info
->default_timeout
: 0x02)); /* 10ms rx timeout */
1969 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyENB_RCVR
|CyENB_XMTR
,index
);
1971 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
1972 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
1973 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
1976 printk("cyc:startup raising DTR\n");
1977 printk(" status: 0x%x, 0x%x\n",
1978 cy_readb(base_addr
+(CyMSVR1
<<index
)),
1979 cy_readb(base_addr
+(CyMSVR2
<<index
)));
1982 cy_writeb(base_addr
+(CySRER
<<index
),
1983 cy_readb(base_addr
+(CySRER
<<index
)) | CyRxData
);
1984 info
->flags
|= ASYNC_INITIALIZED
;
1987 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1989 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
1990 info
->breakon
= info
->breakoff
= 0;
1991 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
1992 info
->idle_stats
.in_use
=
1993 info
->idle_stats
.recv_idle
=
1994 info
->idle_stats
.xmit_idle
= jiffies
;
1996 CY_UNLOCK(info
, flags
);
1999 struct FIRM_ID __iomem
*firm_id
;
2000 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2001 struct BOARD_CTRL __iomem
*board_ctrl
;
2002 struct CH_CTRL __iomem
*ch_ctrl
;
2005 base_addr
= cy_card
[card
].base_addr
;
2007 firm_id
= base_addr
+ ID_ADDRESS
;
2008 if (!ISZLOADED(cy_card
[card
])){
2012 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2013 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2014 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2016 #ifdef CY_DEBUG_OPEN
2017 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2018 card
, channel
, (long)base_addr
);/**/
2021 CY_LOCK(info
, flags
);
2023 cy_writel(&ch_ctrl
[channel
].op_mode
, C_CH_ENABLE
);
2025 #ifdef CONFIG_CYZ_INTR
2026 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2027 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2031 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2034 #endif /* CONFIG_CYZ_INTR */
2036 #ifdef CONFIG_CYZ_INTR
2037 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2038 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2041 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2043 #endif /* CONFIG_CYZ_INTR */
2046 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
2048 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2049 info
->line
, retval
);
2052 /* Flush RX buffers before raising DTR and RTS */
2053 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_RX
, 0L);
2055 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2056 info
->line
, retval
);
2059 /* set timeout !!! */
2060 /* set RTS and DTR !!! */
2061 cy_writel(&ch_ctrl
[channel
].rs_control
,
2062 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
| C_RS_DTR
) ;
2063 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2064 channel
, C_CM_IOCTLM
, 0L);
2066 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2067 info
->line
, retval
);
2070 printk("cyc:startup raising Z DTR\n");
2073 /* enable send, recv, modem !!! */
2075 info
->flags
|= ASYNC_INITIALIZED
;
2077 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2079 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2080 info
->breakon
= info
->breakoff
= 0;
2081 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2082 info
->idle_stats
.in_use
=
2083 info
->idle_stats
.recv_idle
=
2084 info
->idle_stats
.xmit_idle
= jiffies
;
2086 CY_UNLOCK(info
, flags
);
2089 #ifdef CY_DEBUG_OPEN
2090 printk(" cyc startup done\n");
2095 CY_UNLOCK(info
, flags
);
2101 start_xmit( struct cyclades_port
*info
)
2103 unsigned long flags
;
2104 void __iomem
*base_addr
;
2105 int card
,chip
,channel
,index
;
2108 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2109 if (!IS_CYC_Z(cy_card
[card
])) {
2112 index
= cy_card
[card
].bus_index
;
2113 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2115 CY_LOCK(info
, flags
);
2116 cy_writeb(base_addr
+(CyCAR
<<index
), channel
);
2117 cy_writeb(base_addr
+(CySRER
<<index
),
2118 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
2119 CY_UNLOCK(info
, flags
);
2121 #ifdef CONFIG_CYZ_INTR
2124 CY_LOCK(info
, flags
);
2125 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK
, 0L);
2127 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2128 info
->line
, retval
);
2130 CY_UNLOCK(info
, flags
);
2131 #else /* CONFIG_CYZ_INTR */
2132 /* Don't have to do anything at this time */
2133 #endif /* CONFIG_CYZ_INTR */
2138 * This routine shuts down a serial port; interrupts are disabled,
2139 * and DTR is dropped if the hangup on close termio flag is on.
2142 shutdown(struct cyclades_port
* info
)
2144 unsigned long flags
;
2145 void __iomem
*base_addr
;
2146 int card
,chip
,channel
,index
;
2148 if (!(info
->flags
& ASYNC_INITIALIZED
)){
2153 channel
= info
->line
- cy_card
[card
].first_line
;
2154 if (!IS_CYC_Z(cy_card
[card
])) {
2157 index
= cy_card
[card
].bus_index
;
2158 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2160 #ifdef CY_DEBUG_OPEN
2161 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2162 card
, chip
, channel
, (long)base_addr
);
2165 CY_LOCK(info
, flags
);
2167 /* Clear delta_msr_wait queue to avoid mem leaks. */
2168 wake_up_interruptible(&info
->delta_msr_wait
);
2170 if (info
->xmit_buf
){
2171 unsigned char * temp
;
2172 temp
= info
->xmit_buf
;
2173 info
->xmit_buf
= NULL
;
2174 free_page((unsigned long) temp
);
2176 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2177 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2178 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
2179 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
2181 printk("cyc shutdown dropping DTR\n");
2182 printk(" status: 0x%x, 0x%x\n",
2183 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2184 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2187 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyDIS_RCVR
,index
);
2188 /* it may be appropriate to clear _XMIT at
2189 some later date (after testing)!!! */
2192 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2194 info
->flags
&= ~ASYNC_INITIALIZED
;
2195 CY_UNLOCK(info
, flags
);
2197 struct FIRM_ID __iomem
*firm_id
;
2198 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2199 struct BOARD_CTRL __iomem
*board_ctrl
;
2200 struct CH_CTRL __iomem
*ch_ctrl
;
2203 base_addr
= cy_card
[card
].base_addr
;
2204 #ifdef CY_DEBUG_OPEN
2205 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2206 card
, channel
, (long)base_addr
);
2209 firm_id
= base_addr
+ ID_ADDRESS
;
2210 if (!ISZLOADED(cy_card
[card
])) {
2214 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2215 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2216 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2218 CY_LOCK(info
, flags
);
2220 if (info
->xmit_buf
){
2221 unsigned char * temp
;
2222 temp
= info
->xmit_buf
;
2223 info
->xmit_buf
= NULL
;
2224 free_page((unsigned long) temp
);
2227 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2228 cy_writel(&ch_ctrl
[channel
].rs_control
,
2229 (uclong
)(cy_readl(&ch_ctrl
[channel
].rs_control
) &
2230 ~(C_RS_RTS
| C_RS_DTR
)));
2231 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2232 channel
, C_CM_IOCTLM
, 0L);
2234 printk("cyc:shutdown retval on ttyC%d was %x\n",
2235 info
->line
, retval
);
2238 printk("cyc:shutdown dropping Z DTR\n");
2243 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2245 info
->flags
&= ~ASYNC_INITIALIZED
;
2247 CY_UNLOCK(info
, flags
);
2250 #ifdef CY_DEBUG_OPEN
2251 printk(" cyc shutdown done\n");
2258 * ------------------------------------------------------------
2259 * cy_open() and friends
2260 * ------------------------------------------------------------
2264 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2265 struct cyclades_port
*info
)
2267 DECLARE_WAITQUEUE(wait
, current
);
2268 struct cyclades_card
*cinfo
;
2269 unsigned long flags
;
2270 int chip
, channel
,index
;
2272 void __iomem
*base_addr
;
2274 cinfo
= &cy_card
[info
->card
];
2275 channel
= info
->line
- cinfo
->first_line
;
2278 * If the device is in the middle of being closed, then block
2279 * until it's done, and then try again.
2281 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2282 if (info
->flags
& ASYNC_CLOSING
) {
2283 interruptible_sleep_on(&info
->close_wait
);
2285 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2289 * If non-blocking mode is set, then make the check up front
2292 if ((filp
->f_flags
& O_NONBLOCK
) ||
2293 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2294 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2299 * Block waiting for the carrier detect and the line to become
2300 * free (i.e., not in use by the callout). While we are in
2301 * this loop, info->count is dropped by one, so that
2302 * cy_close() knows when to free things. We restore it upon
2303 * exit, either normal or abnormal.
2306 add_wait_queue(&info
->open_wait
, &wait
);
2307 #ifdef CY_DEBUG_OPEN
2308 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2309 info
->line
, info
->count
);/**/
2311 CY_LOCK(info
, flags
);
2312 if (!tty_hung_up_p(filp
))
2314 CY_UNLOCK(info
, flags
);
2315 #ifdef CY_DEBUG_COUNT
2316 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2317 current
->pid
, info
->count
);
2319 info
->blocked_open
++;
2321 if (!IS_CYC_Z(*cinfo
)) {
2324 index
= cinfo
->bus_index
;
2325 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
2328 CY_LOCK(info
, flags
);
2329 if ((tty
->termios
->c_cflag
& CBAUD
)){
2330 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2331 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
2332 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
2334 printk("cyc:block_til_ready raising DTR\n");
2335 printk(" status: 0x%x, 0x%x\n",
2336 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2337 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2340 CY_UNLOCK(info
, flags
);
2342 set_current_state(TASK_INTERRUPTIBLE
);
2343 if (tty_hung_up_p(filp
)
2344 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2345 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2346 -EAGAIN
: -ERESTARTSYS
);
2350 CY_LOCK(info
, flags
);
2351 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2352 if (!(info
->flags
& ASYNC_CLOSING
)
2354 || (cy_readb(base_addr
+(CyMSVR1
<<index
)) & CyDCD
))) {
2355 CY_UNLOCK(info
, flags
);
2358 CY_UNLOCK(info
, flags
);
2360 if (signal_pending(current
)) {
2361 retval
= -ERESTARTSYS
;
2364 #ifdef CY_DEBUG_OPEN
2365 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2366 info
->line
, info
->count
);/**/
2371 struct FIRM_ID __iomem
*firm_id
;
2372 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2373 struct BOARD_CTRL __iomem
*board_ctrl
;
2374 struct CH_CTRL __iomem
*ch_ctrl
;
2377 base_addr
= cinfo
->base_addr
;
2378 firm_id
= base_addr
+ ID_ADDRESS
;
2379 if (!ISZLOADED(*cinfo
)){
2380 current
->state
= TASK_RUNNING
;
2381 remove_wait_queue(&info
->open_wait
, &wait
);
2385 zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2386 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2387 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2390 if ((tty
->termios
->c_cflag
& CBAUD
)){
2391 cy_writel(&ch_ctrl
[channel
].rs_control
,
2392 cy_readl(&ch_ctrl
[channel
].rs_control
) |
2393 (C_RS_RTS
| C_RS_DTR
));
2394 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2395 channel
, C_CM_IOCTLM
, 0L);
2397 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2398 info
->line
, retval
);
2401 printk("cyc:block_til_ready raising Z DTR\n");
2405 set_current_state(TASK_INTERRUPTIBLE
);
2406 if (tty_hung_up_p(filp
)
2407 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2408 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2409 -EAGAIN
: -ERESTARTSYS
);
2412 if (!(info
->flags
& ASYNC_CLOSING
)
2414 || (cy_readl(&ch_ctrl
[channel
].rs_status
) & C_RS_DCD
))) {
2417 if (signal_pending(current
)) {
2418 retval
= -ERESTARTSYS
;
2421 #ifdef CY_DEBUG_OPEN
2422 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2423 info
->line
, info
->count
);/**/
2428 current
->state
= TASK_RUNNING
;
2429 remove_wait_queue(&info
->open_wait
, &wait
);
2430 if (!tty_hung_up_p(filp
)){
2432 #ifdef CY_DEBUG_COUNT
2433 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2434 current
->pid
, info
->count
);
2437 info
->blocked_open
--;
2438 #ifdef CY_DEBUG_OPEN
2439 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2440 info
->line
, info
->count
);/**/
2444 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2446 } /* block_til_ready */
2450 * This routine is called whenever a serial port is opened. It
2451 * performs the serial-specific initialization for the tty structure.
2454 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2456 struct cyclades_port
*info
;
2460 if ((line
< 0) || (NR_PORTS
<= line
)){
2463 info
= &cy_port
[line
];
2464 if (info
->line
< 0){
2468 /* If the card's firmware hasn't been loaded,
2469 treat it as absent from the system. This
2470 will make the user pay attention.
2472 if (IS_CYC_Z(cy_card
[info
->card
])) {
2473 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
2474 struct FIRM_ID __iomem
*firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
2476 if (!ISZLOADED(*cinfo
)) {
2477 if (((ZE_V1
==cy_readl(&((struct RUNTIME_9060 __iomem
*)
2478 (cinfo
->ctl_addr
))->mail_box_0
)) &&
2479 Z_FPGA_CHECK (*cinfo
)) &&
2480 (ZFIRM_HLT
== cy_readl (&firm_id
->signature
)))
2482 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2484 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2488 #ifdef CONFIG_CYZ_INTR
2490 /* In case this Z board is operating in interrupt mode, its
2491 interrupts should be enabled as soon as the first open happens
2492 to one of its ports. */
2493 if (!cinfo
->intr_enabled
) {
2494 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2495 struct BOARD_CTRL __iomem
*board_ctrl
;
2497 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl (&firm_id
->zfwctrl_addr
) & 0xfffff);
2499 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2501 /* Enable interrupts on the PLX chip */
2502 cy_writew(cinfo
->ctl_addr
+0x68,
2503 cy_readw(cinfo
->ctl_addr
+0x68)|0x0900);
2504 /* Enable interrupts on the FW */
2505 retval
= cyz_issue_cmd(cinfo
,
2506 0, C_CM_IRQ_ENBL
, 0L);
2508 printk("cyc:IRQ enable retval was %x\n", retval
);
2510 cinfo
->nports
= (int) cy_readl (&board_ctrl
->n_channel
);
2511 cinfo
->intr_enabled
= 1;
2514 #endif /* CONFIG_CYZ_INTR */
2515 /* Make sure this Z port really exists in hardware */
2516 if (info
->line
> (cinfo
->first_line
+ cinfo
->nports
- 1))
2519 #ifdef CY_DEBUG_OTHER
2520 printk("cyc:cy_open ttyC%d\n", info
->line
); /* */
2522 tty
->driver_data
= info
;
2524 if (serial_paranoia_check(info
, tty
->name
, "cy_open")){
2527 #ifdef CY_DEBUG_OPEN
2528 printk("cyc:cy_open ttyC%d, count = %d\n",
2529 info
->line
, info
->count
);/**/
2532 #ifdef CY_DEBUG_COUNT
2533 printk("cyc:cy_open (%d): incrementing count to %d\n",
2534 current
->pid
, info
->count
);
2538 * If the port is the middle of closing, bail out now
2540 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2541 if (info
->flags
& ASYNC_CLOSING
)
2542 interruptible_sleep_on(&info
->close_wait
);
2543 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2547 * Start up serial port
2549 retval
= startup(info
);
2554 retval
= block_til_ready(tty
, filp
, info
);
2556 #ifdef CY_DEBUG_OPEN
2557 printk("cyc:cy_open returning after block_til_ready with %d\n",
2565 #ifdef CY_DEBUG_OPEN
2566 printk(" cyc:cy_open done\n");/**/
2574 * cy_wait_until_sent() --- wait until the transmitter is empty
2577 cy_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2579 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
2580 void __iomem
*base_addr
;
2581 int card
,chip
,channel
,index
;
2582 unsigned long orig_jiffies
;
2585 if (serial_paranoia_check(info
, tty
->name
, "cy_wait_until_sent"))
2588 if (info
->xmit_fifo_size
== 0)
2589 return; /* Just in case.... */
2592 orig_jiffies
= jiffies
;
2594 * Set the check interval to be 1/5 of the estimated time to
2595 * send a single character, and make it at least 1. The check
2596 * interval should also be less than the timeout.
2598 * Note: we have to use pretty tight timings here to satisfy
2601 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2602 char_time
= char_time
/ 5;
2608 char_time
= min(char_time
, timeout
);
2610 * If the transmitter hasn't cleared in twice the approximate
2611 * amount of time to send the entire FIFO, it probably won't
2612 * ever clear. This assumes the UART isn't doing flow
2613 * control, which is currently the case. Hence, if it ever
2614 * takes longer than info->timeout, this is probably due to a
2615 * UART bug of some kind. So, we clamp the timeout parameter at
2618 if (!timeout
|| timeout
> 2*info
->timeout
)
2619 timeout
= 2*info
->timeout
;
2620 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2621 printk("In cy_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2622 printk("jiff=%lu...", jiffies
);
2625 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2626 if (!IS_CYC_Z(cy_card
[card
])) {
2629 index
= cy_card
[card
].bus_index
;
2630 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2631 while (cy_readb(base_addr
+(CySRER
<<index
)) & CyTxRdy
) {
2632 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2633 printk("Not clean (jiff=%lu)...", jiffies
);
2635 if (msleep_interruptible(jiffies_to_msecs(char_time
)))
2637 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2643 /* Run one more char cycle */
2644 msleep_interruptible(jiffies_to_msecs(char_time
* 5));
2645 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2646 printk("Clean (jiff=%lu)...done\n", jiffies
);
2651 * This routine is called when a particular tty device is closed.
2654 cy_close(struct tty_struct
*tty
, struct file
*filp
)
2656 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2657 unsigned long flags
;
2659 #ifdef CY_DEBUG_OTHER
2660 printk("cyc:cy_close ttyC%d\n", info
->line
);
2663 if (!info
|| serial_paranoia_check(info
, tty
->name
, "cy_close")){
2667 CY_LOCK(info
, flags
);
2668 /* If the TTY is being hung up, nothing to do */
2669 if (tty_hung_up_p(filp
)) {
2670 CY_UNLOCK(info
, flags
);
2674 #ifdef CY_DEBUG_OPEN
2675 printk("cyc:cy_close ttyC%d, count = %d\n", info
->line
, info
->count
);
2677 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2679 * Uh, oh. tty->count is 1, which means that the tty
2680 * structure will be freed. Info->count should always
2681 * be one in these conditions. If it's greater than
2682 * one, we've got real problems, since it means the
2683 * serial port won't be shutdown.
2685 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2686 "info->count is %d\n", info
->count
);
2689 #ifdef CY_DEBUG_COUNT
2690 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2691 current
->pid
, info
->count
- 1);
2693 if (--info
->count
< 0) {
2694 #ifdef CY_DEBUG_COUNT
2695 printk("cyc:cyc_close setting count to 0\n");
2700 CY_UNLOCK(info
, flags
);
2703 info
->flags
|= ASYNC_CLOSING
;
2706 * Now we wait for the transmit buffer to clear; and we notify
2707 * the line discipline to only process XON/XOFF characters.
2710 CY_UNLOCK(info
, flags
);
2711 if (info
->closing_wait
!= CY_CLOSING_WAIT_NONE
) {
2712 tty_wait_until_sent(tty
, info
->closing_wait
);
2714 CY_LOCK(info
, flags
);
2716 if (!IS_CYC_Z(cy_card
[info
->card
])) {
2717 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2718 int index
= cy_card
[info
->card
].bus_index
;
2719 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[channel
>>2] << index
);
2720 /* Stop accepting input */
2722 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2723 cy_writeb(base_addr
+(CySRER
<<index
),
2724 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyRxData
);
2725 if (info
->flags
& ASYNC_INITIALIZED
) {
2726 /* Waiting for on-board buffers to be empty before closing
2728 CY_UNLOCK(info
, flags
);
2729 cy_wait_until_sent(tty
, info
->timeout
);
2730 CY_LOCK(info
, flags
);
2734 /* Waiting for on-board buffers to be empty before closing the port */
2735 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
;
2736 struct FIRM_ID __iomem
*firm_id
= base_addr
+ ID_ADDRESS
;
2737 struct ZFW_CTRL __iomem
*zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2738 struct CH_CTRL __iomem
*ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2739 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2742 if (cy_readl(&ch_ctrl
[channel
].flow_status
) != C_FS_TXIDLE
) {
2743 retval
= cyz_issue_cmd(&cy_card
[info
->card
], channel
,
2746 printk("cyc:cy_close retval on ttyC%d was %x\n",
2747 info
->line
, retval
);
2749 CY_UNLOCK(info
, flags
);
2750 interruptible_sleep_on(&info
->shutdown_wait
);
2751 CY_LOCK(info
, flags
);
2756 CY_UNLOCK(info
, flags
);
2758 if (tty
->driver
->flush_buffer
)
2759 tty
->driver
->flush_buffer(tty
);
2760 tty_ldisc_flush(tty
);
2761 CY_LOCK(info
, flags
);
2766 if (info
->blocked_open
) {
2767 CY_UNLOCK(info
, flags
);
2768 if (info
->close_delay
) {
2769 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
2771 wake_up_interruptible(&info
->open_wait
);
2772 CY_LOCK(info
, flags
);
2774 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
2775 wake_up_interruptible(&info
->close_wait
);
2777 #ifdef CY_DEBUG_OTHER
2778 printk(" cyc:cy_close done\n");
2781 CY_UNLOCK(info
, flags
);
2786 /* This routine gets called when tty_write has put something into
2787 * the write_queue. The characters may come from user space or
2790 * This routine will return the number of characters actually
2791 * accepted for writing.
2793 * If the port is not already transmitting stuff, start it off by
2794 * enabling interrupts. The interrupt service routine will then
2795 * ensure that the characters are sent.
2796 * If the port is already active, there is no need to kick it.
2800 cy_write(struct tty_struct
* tty
, const unsigned char *buf
, int count
)
2802 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2803 unsigned long flags
;
2807 printk("cyc:cy_write ttyC%d\n", info
->line
); /* */
2810 if (serial_paranoia_check(info
, tty
->name
, "cy_write")){
2814 if (!info
->xmit_buf
)
2817 CY_LOCK(info
, flags
);
2819 c
= min(count
, min((int)(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1),
2820 (int)(SERIAL_XMIT_SIZE
- info
->xmit_head
)));
2825 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
2826 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
2827 info
->xmit_cnt
+= c
;
2832 CY_UNLOCK(info
, flags
);
2834 info
->idle_stats
.xmit_bytes
+= ret
;
2835 info
->idle_stats
.xmit_idle
= jiffies
;
2837 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
2845 * This routine is called by the kernel to write a single
2846 * character to the tty device. If the kernel uses this routine,
2847 * it must call the flush_chars() routine (if defined) when it is
2848 * done stuffing characters into the driver. If there is no room
2849 * in the queue, the character is ignored.
2852 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
2854 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2855 unsigned long flags
;
2858 printk("cyc:cy_put_char ttyC%d\n", info
->line
);
2861 if (serial_paranoia_check(info
, tty
->name
, "cy_put_char"))
2864 if (!info
->xmit_buf
)
2867 CY_LOCK(info
, flags
);
2868 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
2869 CY_UNLOCK(info
, flags
);
2873 info
->xmit_buf
[info
->xmit_head
++] = ch
;
2874 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
2876 info
->idle_stats
.xmit_bytes
++;
2877 info
->idle_stats
.xmit_idle
= jiffies
;
2878 CY_UNLOCK(info
, flags
);
2883 * This routine is called by the kernel after it has written a
2884 * series of characters to the tty device using put_char().
2887 cy_flush_chars(struct tty_struct
*tty
)
2889 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2892 printk("cyc:cy_flush_chars ttyC%d\n", info
->line
); /* */
2895 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_chars"))
2898 if (info
->xmit_cnt
<= 0 || tty
->stopped
2899 || tty
->hw_stopped
|| !info
->xmit_buf
)
2903 } /* cy_flush_chars */
2907 * This routine returns the numbers of characters the tty driver
2908 * will accept for queuing to be written. This number is subject
2909 * to change as output buffers get emptied, or if the output flow
2910 * control is activated.
2913 cy_write_room(struct tty_struct
*tty
)
2915 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2919 printk("cyc:cy_write_room ttyC%d\n", info
->line
); /* */
2922 if (serial_paranoia_check(info
, tty
->name
, "cy_write_room"))
2924 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
2928 } /* cy_write_room */
2932 cy_chars_in_buffer(struct tty_struct
*tty
)
2934 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2937 if (serial_paranoia_check(info
, tty
->name
, "cy_chars_in_buffer"))
2941 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2943 #ifdef Z_EXT_CHARS_IN_BUFFER
2944 if (!IS_CYC_Z(cy_card
[card
])) {
2945 #endif /* Z_EXT_CHARS_IN_BUFFER */
2947 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2948 info
->line
, info
->xmit_cnt
); /* */
2950 return info
->xmit_cnt
;
2951 #ifdef Z_EXT_CHARS_IN_BUFFER
2953 static volatile struct FIRM_ID
*firm_id
;
2954 static volatile struct ZFW_CTRL
*zfw_ctrl
;
2955 static volatile struct CH_CTRL
*ch_ctrl
;
2956 static volatile struct BUF_CTRL
*buf_ctrl
;
2958 volatile uclong tx_put
, tx_get
, tx_bufsize
;
2960 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
2961 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2962 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
2963 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
2965 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
2966 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
2967 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
2968 if (tx_put
>= tx_get
)
2969 char_count
= tx_put
- tx_get
;
2971 char_count
= tx_put
- tx_get
+ tx_bufsize
;
2973 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2974 info
->line
, info
->xmit_cnt
+ char_count
); /* */
2976 return (info
->xmit_cnt
+ char_count
);
2978 #endif /* Z_EXT_CHARS_IN_BUFFER */
2979 } /* cy_chars_in_buffer */
2983 * ------------------------------------------------------------
2984 * cy_ioctl() and friends
2985 * ------------------------------------------------------------
2989 cyy_baud_calc(struct cyclades_port
*info
, uclong baud
)
2991 int co
, co_val
, bpr
;
2992 uclong cy_clock
= ((info
->chip_rev
>= CD1400_REV_J
) ? 60000000 : 25000000);
2995 info
->tbpr
= info
->tco
= info
->rbpr
= info
->rco
= 0;
2999 /* determine which prescaler to use */
3000 for (co
= 4, co_val
= 2048; co
; co
--, co_val
>>= 2) {
3001 if (cy_clock
/ co_val
/ baud
> 63)
3005 bpr
= (cy_clock
/ co_val
* 2 / baud
+ 1) / 2;
3009 info
->tbpr
= info
->rbpr
= bpr
;
3010 info
->tco
= info
->rco
= co
;
3014 * This routine finds or computes the various line characteristics.
3015 * It used to be called config_setup
3018 set_line_char(struct cyclades_port
* info
)
3020 unsigned long flags
;
3021 void __iomem
*base_addr
;
3022 int card
,chip
,channel
,index
;
3023 unsigned cflag
, iflag
;
3024 unsigned short chip_number
;
3025 int baud
, baud_rate
= 0;
3029 if (!info
->tty
|| !info
->tty
->termios
){
3032 if (info
->line
== -1){
3035 cflag
= info
->tty
->termios
->c_cflag
;
3036 iflag
= info
->tty
->termios
->c_iflag
;
3039 * Set up the tty->alt_speed kludge
3042 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3043 info
->tty
->alt_speed
= 57600;
3044 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3045 info
->tty
->alt_speed
= 115200;
3046 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3047 info
->tty
->alt_speed
= 230400;
3048 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3049 info
->tty
->alt_speed
= 460800;
3053 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3054 chip_number
= channel
/ 4;
3056 if (!IS_CYC_Z(cy_card
[card
])) {
3058 index
= cy_card
[card
].bus_index
;
3061 baud
= tty_get_baud_rate(info
->tty
);
3062 if ((baud
== 38400) &&
3063 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3064 if (info
->custom_divisor
)
3065 baud_rate
= info
->baud
/ info
->custom_divisor
;
3067 baud_rate
= info
->baud
;
3068 } else if (baud
> CD1400_MAX_SPEED
) {
3069 baud
= CD1400_MAX_SPEED
;
3071 /* find the baud index */
3072 for (i
= 0; i
< 20; i
++) {
3073 if (baud
== baud_table
[i
]) {
3078 i
= 19; /* CD1400_MAX_SPEED */
3081 if ((baud
== 38400) &&
3082 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3083 cyy_baud_calc(info
, baud_rate
);
3085 if(info
->chip_rev
>= CD1400_REV_J
) {
3086 /* It is a CD1400 rev. J or later */
3087 info
->tbpr
= baud_bpr_60
[i
]; /* Tx BPR */
3088 info
->tco
= baud_co_60
[i
]; /* Tx CO */
3089 info
->rbpr
= baud_bpr_60
[i
]; /* Rx BPR */
3090 info
->rco
= baud_co_60
[i
]; /* Rx CO */
3092 info
->tbpr
= baud_bpr_25
[i
]; /* Tx BPR */
3093 info
->tco
= baud_co_25
[i
]; /* Tx CO */
3094 info
->rbpr
= baud_bpr_25
[i
]; /* Rx BPR */
3095 info
->rco
= baud_co_25
[i
]; /* Rx CO */
3098 if (baud_table
[i
] == 134) {
3099 /* get it right for 134.5 baud */
3100 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3101 } else if ((baud
== 38400) &&
3102 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3103 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3104 } else if (baud_table
[i
]) {
3105 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
3106 /* this needs to be propagated into the card info */
3110 /* By tradition (is it a standard?) a baud rate of zero
3111 implies the line should be/has been closed. A bit
3112 later in this routine such a test is performed. */
3114 /* byte size and parity */
3117 info
->cor3
= (info
->default_threshold
3118 ? info
->default_threshold
3119 : baud_cor3
[i
]); /* receive threshold */
3121 switch(cflag
& CSIZE
){
3123 info
->cor1
= Cy_5_BITS
;
3126 info
->cor1
= Cy_6_BITS
;
3129 info
->cor1
= Cy_7_BITS
;
3132 info
->cor1
= Cy_8_BITS
;
3136 info
->cor1
|= Cy_2_STOP
;
3138 if (cflag
& PARENB
){
3139 if (cflag
& PARODD
){
3140 info
->cor1
|= CyPARITY_O
;
3142 info
->cor1
|= CyPARITY_E
;
3145 info
->cor1
|= CyPARITY_NONE
;
3148 /* CTS flow control flag */
3149 if (cflag
& CRTSCTS
){
3150 info
->flags
|= ASYNC_CTS_FLOW
;
3151 info
->cor2
|= CyCtsAE
;
3153 info
->flags
&= ~ASYNC_CTS_FLOW
;
3154 info
->cor2
&= ~CyCtsAE
;
3157 info
->flags
&= ~ASYNC_CHECK_CD
;
3159 info
->flags
|= ASYNC_CHECK_CD
;
3161 /***********************************************
3162 The hardware option, CyRtsAO, presents RTS when
3163 the chip has characters to send. Since most modems
3164 use RTS as reverse (inbound) flow control, this
3165 option is not used. If inbound flow control is
3166 necessary, DTR can be programmed to provide the
3167 appropriate signals for use with a non-standard
3168 cable. Contact Marcio Saito for details.
3169 ***********************************************/
3173 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3175 CY_LOCK(info
, flags
);
3176 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3178 /* tx and rx baud rate */
3180 cy_writeb(base_addr
+(CyTCOR
<<index
), info
->tco
);
3181 cy_writeb(base_addr
+(CyTBPR
<<index
), info
->tbpr
);
3182 cy_writeb(base_addr
+(CyRCOR
<<index
), info
->rco
);
3183 cy_writeb(base_addr
+(CyRBPR
<<index
), info
->rbpr
);
3185 /* set line characteristics according configuration */
3187 cy_writeb(base_addr
+(CySCHR1
<<index
),
3188 START_CHAR(info
->tty
));
3189 cy_writeb(base_addr
+(CySCHR2
<<index
),
3190 STOP_CHAR(info
->tty
));
3191 cy_writeb(base_addr
+(CyCOR1
<<index
), info
->cor1
);
3192 cy_writeb(base_addr
+(CyCOR2
<<index
), info
->cor2
);
3193 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3194 cy_writeb(base_addr
+(CyCOR4
<<index
), info
->cor4
);
3195 cy_writeb(base_addr
+(CyCOR5
<<index
), info
->cor5
);
3197 cyy_issue_cmd(base_addr
,
3198 CyCOR_CHANGE
|CyCOR1ch
|CyCOR2ch
|CyCOR3ch
,index
);
3200 cy_writeb(base_addr
+(CyCAR
<<index
),
3201 (u_char
)channel
); /* !!! Is this needed? */
3202 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
3203 ? info
->default_timeout
3204 : 0x02)); /* 10ms rx timeout */
3206 if (C_CLOCAL(info
->tty
)) {
3207 /* without modem intr */
3208 cy_writeb(base_addr
+(CySRER
<<index
),
3209 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3210 /* act on 1->0 modem transitions */
3211 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3212 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3213 (CyCTS
|rflow_thr
[i
]));
3215 cy_writeb(base_addr
+(CyMCOR1
<<index
), CyCTS
);
3217 /* act on 0->1 modem transitions */
3218 cy_writeb(base_addr
+(CyMCOR2
<<index
), CyCTS
);
3220 /* without modem intr */
3221 cy_writeb(base_addr
+(CySRER
<<index
),
3222 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3223 /* act on 1->0 modem transitions */
3224 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3225 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3226 (CyDSR
|CyCTS
|CyRI
|CyDCD
|rflow_thr
[i
]));
3228 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3229 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3231 /* act on 0->1 modem transitions */
3232 cy_writeb(base_addr
+(CyMCOR2
<<index
),
3233 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3236 if(i
== 0){ /* baud rate is zero, turn off line */
3237 if (info
->rtsdtr_inv
) {
3238 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3240 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3243 printk("cyc:set_line_char dropping DTR\n");
3244 printk(" status: 0x%x, 0x%x\n",
3245 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3246 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3249 if (info
->rtsdtr_inv
) {
3250 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3252 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3255 printk("cyc:set_line_char raising DTR\n");
3256 printk(" status: 0x%x, 0x%x\n",
3257 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3258 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3263 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3265 CY_UNLOCK(info
, flags
);
3268 struct FIRM_ID __iomem
*firm_id
;
3269 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3270 struct BOARD_CTRL __iomem
*board_ctrl
;
3271 struct CH_CTRL __iomem
*ch_ctrl
;
3272 struct BUF_CTRL __iomem
*buf_ctrl
;
3276 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3277 if (!ISZLOADED(cy_card
[card
])) {
3281 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3282 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3283 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3284 buf_ctrl
= &zfw_ctrl
->buf_ctrl
[channel
];
3287 baud
= tty_get_baud_rate(info
->tty
);
3288 if ((baud
== 38400) &&
3289 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3290 if (info
->custom_divisor
)
3291 baud_rate
= info
->baud
/ info
->custom_divisor
;
3293 baud_rate
= info
->baud
;
3294 } else if (baud
> CYZ_MAX_SPEED
) {
3295 baud
= CYZ_MAX_SPEED
;
3297 cy_writel(&ch_ctrl
->comm_baud
, baud
);
3300 /* get it right for 134.5 baud */
3301 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3302 } else if ((baud
== 38400) &&
3303 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3304 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3306 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud
) + 2;
3307 /* this needs to be propagated into the card info */
3312 /* byte size and parity */
3313 switch(cflag
& CSIZE
){
3314 case CS5
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS5
); break;
3315 case CS6
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS6
); break;
3316 case CS7
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS7
); break;
3317 case CS8
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS8
); break;
3320 cy_writel(&ch_ctrl
->comm_data_l
,
3321 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_2STOP
);
3323 cy_writel(&ch_ctrl
->comm_data_l
,
3324 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_1STOP
);
3326 if (cflag
& PARENB
){
3327 if (cflag
& PARODD
){
3328 cy_writel(&ch_ctrl
->comm_parity
, C_PR_ODD
);
3330 cy_writel(&ch_ctrl
->comm_parity
, C_PR_EVEN
);
3333 cy_writel(&ch_ctrl
->comm_parity
, C_PR_NONE
);
3336 /* CTS flow control flag */
3337 if (cflag
& CRTSCTS
){
3338 cy_writel(&ch_ctrl
->hw_flow
,
3339 cy_readl(&ch_ctrl
->hw_flow
) | C_RS_CTS
| C_RS_RTS
);
3341 cy_writel(&ch_ctrl
->hw_flow
,
3342 cy_readl(&ch_ctrl
->hw_flow
) & ~(C_RS_CTS
| C_RS_RTS
));
3344 /* As the HW flow control is done in firmware, the driver doesn't
3345 need to care about it */
3346 info
->flags
&= ~ASYNC_CTS_FLOW
;
3348 /* XON/XOFF/XANY flow control flags */
3351 sw_flow
|= C_FL_OXX
;
3353 sw_flow
|= C_FL_OIXANY
;
3355 cy_writel(&ch_ctrl
->sw_flow
, sw_flow
);
3357 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
3359 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3360 info
->line
, retval
);
3363 /* CD sensitivity */
3364 if (cflag
& CLOCAL
){
3365 info
->flags
&= ~ASYNC_CHECK_CD
;
3367 info
->flags
|= ASYNC_CHECK_CD
;
3370 if(baud
== 0){ /* baud rate is zero, turn off line */
3371 cy_writel(&ch_ctrl
->rs_control
,
3372 cy_readl(&ch_ctrl
->rs_control
) & ~C_RS_DTR
);
3374 printk("cyc:set_line_char dropping Z DTR\n");
3377 cy_writel(&ch_ctrl
->rs_control
,
3378 cy_readl(&ch_ctrl
->rs_control
) | C_RS_DTR
);
3380 printk("cyc:set_line_char raising Z DTR\n");
3384 retval
= cyz_issue_cmd( &cy_card
[card
], channel
, C_CM_IOCTLM
, 0L);
3386 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3387 info
->line
, retval
);
3391 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3394 } /* set_line_char */
3398 get_serial_info(struct cyclades_port
* info
,
3399 struct serial_struct __user
* retinfo
)
3401 struct serial_struct tmp
;
3402 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
3406 memset(&tmp
, 0, sizeof(tmp
));
3407 tmp
.type
= info
->type
;
3408 tmp
.line
= info
->line
;
3409 tmp
.port
= info
->card
* 0x100 + info
->line
- cinfo
->first_line
;
3410 tmp
.irq
= cinfo
->irq
;
3411 tmp
.flags
= info
->flags
;
3412 tmp
.close_delay
= info
->close_delay
;
3413 tmp
.baud_base
= info
->baud
;
3414 tmp
.custom_divisor
= info
->custom_divisor
;
3415 tmp
.hub6
= 0; /*!!!*/
3416 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
))?-EFAULT
:0;
3417 } /* get_serial_info */
3421 set_serial_info(struct cyclades_port
* info
,
3422 struct serial_struct __user
* new_info
)
3424 struct serial_struct new_serial
;
3425 struct cyclades_port old_info
;
3427 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
3431 if (!capable(CAP_SYS_ADMIN
)) {
3432 if ((new_serial
.close_delay
!= info
->close_delay
) ||
3433 (new_serial
.baud_base
!= info
->baud
) ||
3434 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
3435 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
3437 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
3438 (new_serial
.flags
& ASYNC_USR_MASK
));
3439 info
->baud
= new_serial
.baud_base
;
3440 info
->custom_divisor
= new_serial
.custom_divisor
;
3441 goto check_and_exit
;
3446 * OK, past this point, all the error checking has been done.
3447 * At this point, we start making changes.....
3450 info
->baud
= new_serial
.baud_base
;
3451 info
->custom_divisor
= new_serial
.custom_divisor
;
3452 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
3453 (new_serial
.flags
& ASYNC_FLAGS
));
3454 info
->close_delay
= new_serial
.close_delay
* HZ
/100;
3455 info
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
3458 if (info
->flags
& ASYNC_INITIALIZED
){
3459 set_line_char(info
);
3462 return startup(info
);
3464 } /* set_serial_info */
3467 * get_lsr_info - get line status register info
3469 * Purpose: Let user call ioctl() to get info when the UART physically
3470 * is emptied. On bus types like RS485, the transmitter must
3471 * release the bus after transmitting. This must be done when
3472 * the transmit shift register is empty, not be done when the
3473 * transmit holding register is empty. This functionality
3474 * allows an RS485 driver to be written in user space.
3476 static int get_lsr_info(struct cyclades_port
*info
, unsigned int __user
*value
)
3478 int card
, chip
, channel
, index
;
3479 unsigned char status
;
3480 unsigned int result
;
3481 unsigned long flags
;
3482 void __iomem
*base_addr
;
3485 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3486 if (!IS_CYC_Z(cy_card
[card
])) {
3489 index
= cy_card
[card
].bus_index
;
3490 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3492 CY_LOCK(info
, flags
);
3493 status
= cy_readb(base_addr
+(CySRER
<<index
)) & (CyTxRdy
|CyTxMpty
);
3494 CY_UNLOCK(info
, flags
);
3495 result
= (status
? 0 : TIOCSER_TEMT
);
3497 /* Not supported yet */
3500 return put_user(result
, (unsigned long __user
*) value
);
3504 cy_tiocmget(struct tty_struct
*tty
, struct file
*file
)
3506 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3507 int card
,chip
,channel
,index
;
3508 void __iomem
*base_addr
;
3509 unsigned long flags
;
3510 unsigned char status
;
3511 unsigned long lstatus
;
3512 unsigned int result
;
3513 struct FIRM_ID __iomem
*firm_id
;
3514 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3515 struct BOARD_CTRL __iomem
*board_ctrl
;
3516 struct CH_CTRL __iomem
*ch_ctrl
;
3518 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3522 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3523 if (!IS_CYC_Z(cy_card
[card
])) {
3526 index
= cy_card
[card
].bus_index
;
3527 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3529 CY_LOCK(info
, flags
);
3530 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3531 status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
3532 status
|= cy_readb(base_addr
+(CyMSVR2
<<index
));
3533 CY_UNLOCK(info
, flags
);
3535 if (info
->rtsdtr_inv
) {
3536 result
= ((status
& CyRTS
) ? TIOCM_DTR
: 0)
3537 | ((status
& CyDTR
) ? TIOCM_RTS
: 0);
3539 result
= ((status
& CyRTS
) ? TIOCM_RTS
: 0)
3540 | ((status
& CyDTR
) ? TIOCM_DTR
: 0);
3542 result
|= ((status
& CyDCD
) ? TIOCM_CAR
: 0)
3543 | ((status
& CyRI
) ? TIOCM_RNG
: 0)
3544 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
3545 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
3547 base_addr
= cy_card
[card
].base_addr
;
3549 if (cy_card
[card
].num_chips
!= -1){
3553 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3554 if (ISZLOADED(cy_card
[card
])) {
3555 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3556 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3557 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3558 lstatus
= cy_readl(&ch_ctrl
[channel
].rs_status
);
3559 result
= ((lstatus
& C_RS_RTS
) ? TIOCM_RTS
: 0)
3560 | ((lstatus
& C_RS_DTR
) ? TIOCM_DTR
: 0)
3561 | ((lstatus
& C_RS_DCD
) ? TIOCM_CAR
: 0)
3562 | ((lstatus
& C_RS_RI
) ? TIOCM_RNG
: 0)
3563 | ((lstatus
& C_RS_DSR
) ? TIOCM_DSR
: 0)
3564 | ((lstatus
& C_RS_CTS
) ? TIOCM_CTS
: 0);
3576 cy_tiocmset(struct tty_struct
*tty
, struct file
*file
,
3577 unsigned int set
, unsigned int clear
)
3579 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3580 int card
,chip
,channel
,index
;
3581 void __iomem
*base_addr
;
3582 unsigned long flags
;
3583 struct FIRM_ID __iomem
*firm_id
;
3584 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3585 struct BOARD_CTRL __iomem
*board_ctrl
;
3586 struct CH_CTRL __iomem
*ch_ctrl
;
3589 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3593 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3594 if (!IS_CYC_Z(cy_card
[card
])) {
3597 index
= cy_card
[card
].bus_index
;
3598 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3600 if (set
& TIOCM_RTS
){
3601 CY_LOCK(info
, flags
);
3602 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3603 if (info
->rtsdtr_inv
) {
3604 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3606 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3608 CY_UNLOCK(info
, flags
);
3610 if (clear
& TIOCM_RTS
) {
3611 CY_LOCK(info
, flags
);
3612 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3613 if (info
->rtsdtr_inv
) {
3614 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3616 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3618 CY_UNLOCK(info
, flags
);
3620 if (set
& TIOCM_DTR
){
3621 CY_LOCK(info
, flags
);
3622 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3623 if (info
->rtsdtr_inv
) {
3624 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3626 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3629 printk("cyc:set_modem_info raising DTR\n");
3630 printk(" status: 0x%x, 0x%x\n",
3631 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3632 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3634 CY_UNLOCK(info
, flags
);
3636 if (clear
& TIOCM_DTR
) {
3637 CY_LOCK(info
, flags
);
3638 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3639 if (info
->rtsdtr_inv
) {
3640 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3642 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3646 printk("cyc:set_modem_info dropping DTR\n");
3647 printk(" status: 0x%x, 0x%x\n",
3648 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3649 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3651 CY_UNLOCK(info
, flags
);
3654 base_addr
= cy_card
[card
].base_addr
;
3656 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3657 if (ISZLOADED(cy_card
[card
])) {
3658 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3659 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3660 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3662 if (set
& TIOCM_RTS
){
3663 CY_LOCK(info
, flags
);
3664 cy_writel(&ch_ctrl
[channel
].rs_control
,
3665 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3666 CY_UNLOCK(info
, flags
);
3668 if (clear
& TIOCM_RTS
) {
3669 CY_LOCK(info
, flags
);
3670 cy_writel(&ch_ctrl
[channel
].rs_control
,
3671 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3672 CY_UNLOCK(info
, flags
);
3674 if (set
& TIOCM_DTR
){
3675 CY_LOCK(info
, flags
);
3676 cy_writel(&ch_ctrl
[channel
].rs_control
,
3677 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3679 printk("cyc:set_modem_info raising Z DTR\n");
3681 CY_UNLOCK(info
, flags
);
3683 if (clear
& TIOCM_DTR
) {
3684 CY_LOCK(info
, flags
);
3685 cy_writel(&ch_ctrl
[channel
].rs_control
,
3686 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3688 printk("cyc:set_modem_info clearing Z DTR\n");
3690 CY_UNLOCK(info
, flags
);
3695 CY_LOCK(info
, flags
);
3696 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3697 channel
, C_CM_IOCTLM
,0L);
3699 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3700 info
->line
, retval
);
3702 CY_UNLOCK(info
, flags
);
3708 * cy_break() --- routine which turns the break handling on or off
3711 cy_break(struct tty_struct
*tty
, int break_state
)
3713 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3714 unsigned long flags
;
3716 if (serial_paranoia_check(info
, tty
->name
, "cy_break"))
3719 CY_LOCK(info
, flags
);
3720 if (!IS_CYC_Z(cy_card
[info
->card
])) {
3721 /* Let the transmit ISR take care of this (since it
3722 requires stuffing characters into the output stream).
3724 if (break_state
== -1) {
3725 if (!info
->breakon
) {
3727 if (!info
->xmit_cnt
) {
3728 CY_UNLOCK(info
, flags
);
3730 CY_LOCK(info
, flags
);
3734 if (!info
->breakoff
) {
3736 if (!info
->xmit_cnt
) {
3737 CY_UNLOCK(info
, flags
);
3739 CY_LOCK(info
, flags
);
3746 if (break_state
== -1) {
3747 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3748 (info
->line
) - (cy_card
[info
->card
].first_line
),
3749 C_CM_SET_BREAK
, 0L);
3751 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3752 info
->line
, retval
);
3755 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3756 (info
->line
) - (cy_card
[info
->card
].first_line
),
3757 C_CM_CLR_BREAK
, 0L);
3759 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3760 info
->line
, retval
);
3764 CY_UNLOCK(info
, flags
);
3768 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor __user
* mon
)
3771 if(copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
3773 info
->mon
.int_count
= 0;
3774 info
->mon
.char_count
= 0;
3775 info
->mon
.char_max
= 0;
3776 info
->mon
.char_last
= 0;
3782 set_threshold(struct cyclades_port
* info
, unsigned long value
)
3784 void __iomem
*base_addr
;
3785 int card
,channel
,chip
,index
;
3786 unsigned long flags
;
3789 channel
= info
->line
- cy_card
[card
].first_line
;
3790 if (!IS_CYC_Z(cy_card
[card
])) {
3793 index
= cy_card
[card
].bus_index
;
3794 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3796 info
->cor3
&= ~CyREC_FIFO
;
3797 info
->cor3
|= value
& CyREC_FIFO
;
3799 CY_LOCK(info
, flags
);
3800 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3801 cyy_issue_cmd(base_addr
,CyCOR_CHANGE
|CyCOR3ch
,index
);
3802 CY_UNLOCK(info
, flags
);
3807 }/* set_threshold */
3811 get_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3813 void __iomem
*base_addr
;
3814 int card
,channel
,chip
,index
;
3818 channel
= info
->line
- cy_card
[card
].first_line
;
3819 if (!IS_CYC_Z(cy_card
[card
])) {
3822 index
= cy_card
[card
].bus_index
;
3823 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3825 tmp
= cy_readb(base_addr
+(CyCOR3
<<index
)) & CyREC_FIFO
;
3826 return put_user(tmp
,value
);
3831 }/* get_threshold */
3835 set_default_threshold(struct cyclades_port
* info
, unsigned long value
)
3837 info
->default_threshold
= value
& 0x0f;
3839 }/* set_default_threshold */
3843 get_default_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3845 return put_user(info
->default_threshold
,value
);
3846 }/* get_default_threshold */
3850 set_timeout(struct cyclades_port
* info
, unsigned long value
)
3852 void __iomem
*base_addr
;
3853 int card
,channel
,chip
,index
;
3854 unsigned long flags
;
3857 channel
= info
->line
- cy_card
[card
].first_line
;
3858 if (!IS_CYC_Z(cy_card
[card
])) {
3861 index
= cy_card
[card
].bus_index
;
3862 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3864 CY_LOCK(info
, flags
);
3865 cy_writeb(base_addr
+(CyRTPR
<<index
), value
& 0xff);
3866 CY_UNLOCK(info
, flags
);
3875 get_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
3877 void __iomem
*base_addr
;
3878 int card
,channel
,chip
,index
;
3882 channel
= info
->line
- cy_card
[card
].first_line
;
3883 if (!IS_CYC_Z(cy_card
[card
])) {
3886 index
= cy_card
[card
].bus_index
;
3887 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3889 tmp
= cy_readb(base_addr
+(CyRTPR
<<index
));
3890 return put_user(tmp
,value
);
3899 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
3901 info
->default_timeout
= value
& 0xff;
3903 }/* set_default_timeout */
3907 get_default_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
3909 return put_user(info
->default_timeout
,value
);
3910 }/* get_default_timeout */
3913 * This routine allows the tty driver to implement device-
3914 * specific ioctl's. If the ioctl number passed in cmd is
3915 * not recognized by the driver, it should return ENOIOCTLCMD.
3918 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
3919 unsigned int cmd
, unsigned long arg
)
3921 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3922 struct cyclades_icount cprev
, cnow
; /* kernel counter temps */
3923 struct serial_icounter_struct __user
*p_cuser
; /* user space */
3925 unsigned long flags
;
3926 void __user
*argp
= (void __user
*)arg
;
3928 if (serial_paranoia_check(info
, tty
->name
, "cy_ioctl"))
3931 #ifdef CY_DEBUG_OTHER
3932 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
3933 info
->line
, cmd
, arg
); /* */
3938 ret_val
= get_mon_info(info
, argp
);
3941 ret_val
= get_threshold(info
, argp
);
3944 ret_val
= set_threshold(info
, arg
);
3946 case CYGETDEFTHRESH
:
3947 ret_val
= get_default_threshold(info
, argp
);
3949 case CYSETDEFTHRESH
:
3950 ret_val
= set_default_threshold(info
, arg
);
3953 ret_val
= get_timeout(info
, argp
);
3956 ret_val
= set_timeout(info
, arg
);
3958 case CYGETDEFTIMEOUT
:
3959 ret_val
= get_default_timeout(info
, argp
);
3961 case CYSETDEFTIMEOUT
:
3962 ret_val
= set_default_timeout(info
, arg
);
3965 info
->rflow
= (int)arg
;
3969 ret_val
= info
->rflow
;
3971 case CYSETRTSDTR_INV
:
3972 info
->rtsdtr_inv
= (int)arg
;
3975 case CYGETRTSDTR_INV
:
3976 ret_val
= info
->rtsdtr_inv
;
3979 if (copy_to_user(argp
, &cy_card
[info
->card
],
3980 sizeof (struct cyclades_card
))) {
3986 case CYGETCD1400VER
:
3987 ret_val
= info
->chip_rev
;
3989 #ifndef CONFIG_CYZ_INTR
3990 case CYZSETPOLLCYCLE
:
3991 cyz_polling_cycle
= (arg
* HZ
) / 1000;
3994 case CYZGETPOLLCYCLE
:
3995 ret_val
= (cyz_polling_cycle
* 1000) / HZ
;
3997 #endif /* CONFIG_CYZ_INTR */
3999 info
->closing_wait
= (unsigned short)arg
* HZ
/100;
4003 ret_val
= info
->closing_wait
/ (HZ
/100);
4006 ret_val
= get_serial_info(info
, argp
);
4009 ret_val
= set_serial_info(info
, argp
);
4011 case TIOCSERGETLSR
: /* Get line status register */
4012 ret_val
= get_lsr_info(info
, argp
);
4015 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4016 * - mask passed in arg for lines of interest
4017 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4018 * Caller should use TIOCGICOUNT to see which one it was
4021 CY_LOCK(info
, flags
);
4022 /* note the counters on entry */
4023 cprev
= info
->icount
;
4024 CY_UNLOCK(info
, flags
);
4026 interruptible_sleep_on(&info
->delta_msr_wait
);
4027 /* see if a signal did it */
4028 if (signal_pending(current
)) {
4029 return -ERESTARTSYS
;
4032 CY_LOCK(info
, flags
);
4033 cnow
= info
->icount
; /* atomic copy */
4034 CY_UNLOCK(info
, flags
);
4036 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
4037 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
4038 return -EIO
; /* no change => error */
4040 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
4041 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
4042 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
4043 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
4051 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4052 * Return: write counters to the user passed counter struct
4053 * NB: both 1->0 and 0->1 transitions are counted except for
4054 * RI where only 0->1 is counted.
4057 CY_LOCK(info
, flags
);
4058 cnow
= info
->icount
;
4059 CY_UNLOCK(info
, flags
);
4061 ret_val
= put_user(cnow
.cts
, &p_cuser
->cts
);
4062 if (ret_val
) return ret_val
;
4063 ret_val
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
4064 if (ret_val
) return ret_val
;
4065 ret_val
= put_user(cnow
.rng
, &p_cuser
->rng
);
4066 if (ret_val
) return ret_val
;
4067 ret_val
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
4068 if (ret_val
) return ret_val
;
4069 ret_val
= put_user(cnow
.rx
, &p_cuser
->rx
);
4070 if (ret_val
) return ret_val
;
4071 ret_val
= put_user(cnow
.tx
, &p_cuser
->tx
);
4072 if (ret_val
) return ret_val
;
4073 ret_val
= put_user(cnow
.frame
, &p_cuser
->frame
);
4074 if (ret_val
) return ret_val
;
4075 ret_val
= put_user(cnow
.overrun
, &p_cuser
->overrun
);
4076 if (ret_val
) return ret_val
;
4077 ret_val
= put_user(cnow
.parity
, &p_cuser
->parity
);
4078 if (ret_val
) return ret_val
;
4079 ret_val
= put_user(cnow
.brk
, &p_cuser
->brk
);
4080 if (ret_val
) return ret_val
;
4081 ret_val
= put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
4082 if (ret_val
) return ret_val
;
4086 ret_val
= -ENOIOCTLCMD
;
4089 #ifdef CY_DEBUG_OTHER
4090 printk(" cyc:cy_ioctl done\n");
4098 * This routine allows the tty driver to be notified when
4099 * device's termios settings have changed. Note that a
4100 * well-designed tty driver should be prepared to accept the case
4101 * where old == NULL, and try to do something rational.
4104 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
4106 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4108 #ifdef CY_DEBUG_OTHER
4109 printk("cyc:cy_set_termios ttyC%d\n", info
->line
);
4112 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
4113 ((tty
->termios
->c_iflag
& (IXON
|IXANY
)) ==
4114 (old_termios
->c_iflag
& (IXON
|IXANY
))))
4116 set_line_char(info
);
4118 if ((old_termios
->c_cflag
& CRTSCTS
) &&
4119 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
4120 tty
->hw_stopped
= 0;
4125 * No need to wake up processes in open wait, since they
4126 * sample the CLOCAL flag once, and don't recheck it.
4127 * XXX It's not clear whether the current behavior is correct
4128 * or not. Hence, this may change.....
4130 if (!(old_termios
->c_cflag
& CLOCAL
) &&
4131 (tty
->termios
->c_cflag
& CLOCAL
))
4132 wake_up_interruptible(&info
->open_wait
);
4136 } /* cy_set_termios */
4138 /* This function is used to send a high-priority XON/XOFF character to
4142 cy_send_xchar (struct tty_struct
*tty
, char ch
)
4144 struct cyclades_port
*info
= (struct cyclades_port
*) tty
->driver_data
;
4147 if (serial_paranoia_check (info
, tty
->name
, "cy_send_xchar"))
4156 channel
= info
->line
- cy_card
[card
].first_line
;
4158 if (IS_CYC_Z (cy_card
[card
])) {
4159 if (ch
== STOP_CHAR (tty
))
4160 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXOFF
, 0L);
4161 else if (ch
== START_CHAR (tty
))
4162 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXON
, 0L);
4166 /* This routine is called by the upper-layer tty layer to signal
4167 that incoming characters should be throttled because the input
4168 buffers are close to full.
4171 cy_throttle(struct tty_struct
* tty
)
4173 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4174 unsigned long flags
;
4175 void __iomem
*base_addr
;
4176 int card
,chip
,channel
,index
;
4178 #ifdef CY_DEBUG_THROTTLE
4181 printk("cyc:throttle %s: %d....ttyC%d\n",
4183 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4186 if (serial_paranoia_check(info
, tty
->name
, "cy_throttle")){
4193 if (!IS_CYC_Z (cy_card
[card
]))
4194 cy_send_xchar (tty
, STOP_CHAR (tty
));
4199 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4200 channel
= info
->line
- cy_card
[card
].first_line
;
4201 if (!IS_CYC_Z(cy_card
[card
])) {
4204 index
= cy_card
[card
].bus_index
;
4205 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4207 CY_LOCK(info
, flags
);
4208 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4209 if (info
->rtsdtr_inv
) {
4210 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
4212 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
4214 CY_UNLOCK(info
, flags
);
4225 * This routine notifies the tty driver that it should signal
4226 * that characters can now be sent to the tty without fear of
4227 * overrunning the input buffers of the line disciplines.
4230 cy_unthrottle(struct tty_struct
* tty
)
4232 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4233 unsigned long flags
;
4234 void __iomem
*base_addr
;
4235 int card
,chip
,channel
,index
;
4237 #ifdef CY_DEBUG_THROTTLE
4240 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4242 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4245 if (serial_paranoia_check(info
, tty
->name
, "cy_unthrottle")){
4253 cy_send_xchar (tty
, START_CHAR (tty
));
4256 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4258 channel
= info
->line
- cy_card
[card
].first_line
;
4259 if (!IS_CYC_Z(cy_card
[card
])) {
4262 index
= cy_card
[card
].bus_index
;
4263 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4265 CY_LOCK(info
, flags
);
4266 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4267 if (info
->rtsdtr_inv
) {
4268 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
4270 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
4272 CY_UNLOCK(info
, flags
);
4279 } /* cy_unthrottle */
4282 /* cy_start and cy_stop provide software output flow control as a
4283 function of XON/XOFF, software CTS, and other such stuff.
4286 cy_stop(struct tty_struct
*tty
)
4288 struct cyclades_card
*cinfo
;
4289 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4290 void __iomem
*base_addr
;
4291 int chip
,channel
,index
;
4292 unsigned long flags
;
4294 #ifdef CY_DEBUG_OTHER
4295 printk("cyc:cy_stop ttyC%d\n", info
->line
); /* */
4298 if (serial_paranoia_check(info
, tty
->name
, "cy_stop"))
4301 cinfo
= &cy_card
[info
->card
];
4302 channel
= info
->line
- cinfo
->first_line
;
4303 if (!IS_CYC_Z(*cinfo
)) {
4304 index
= cinfo
->bus_index
;
4307 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4309 CY_LOCK(info
, flags
);
4310 cy_writeb(base_addr
+(CyCAR
<<index
),
4311 (u_char
)(channel
& 0x0003)); /* index channel */
4312 cy_writeb(base_addr
+(CySRER
<<index
),
4313 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
4314 CY_UNLOCK(info
, flags
);
4324 cy_start(struct tty_struct
*tty
)
4326 struct cyclades_card
*cinfo
;
4327 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4328 void __iomem
*base_addr
;
4329 int chip
,channel
,index
;
4330 unsigned long flags
;
4332 #ifdef CY_DEBUG_OTHER
4333 printk("cyc:cy_start ttyC%d\n", info
->line
); /* */
4336 if (serial_paranoia_check(info
, tty
->name
, "cy_start"))
4339 cinfo
= &cy_card
[info
->card
];
4340 channel
= info
->line
- cinfo
->first_line
;
4341 index
= cinfo
->bus_index
;
4342 if (!IS_CYC_Z(*cinfo
)) {
4345 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4347 CY_LOCK(info
, flags
);
4348 cy_writeb(base_addr
+(CyCAR
<<index
),
4349 (u_char
)(channel
& 0x0003)); /* index channel */
4350 cy_writeb(base_addr
+(CySRER
<<index
),
4351 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
4352 CY_UNLOCK(info
, flags
);
4362 cy_flush_buffer(struct tty_struct
*tty
)
4364 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4365 int card
, channel
, retval
;
4366 unsigned long flags
;
4369 printk("cyc:cy_flush_buffer ttyC%d\n", info
->line
); /* */
4372 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_buffer"))
4376 channel
= (info
->line
) - (cy_card
[card
].first_line
);
4378 CY_LOCK(info
, flags
);
4379 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
4380 CY_UNLOCK(info
, flags
);
4382 if (IS_CYC_Z(cy_card
[card
])) { /* If it is a Z card, flush the on-board
4384 CY_LOCK(info
, flags
);
4385 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_TX
, 0L);
4387 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4388 info
->line
, retval
);
4390 CY_UNLOCK(info
, flags
);
4393 wake_up_interruptible(&tty
->write_wait
);
4394 } /* cy_flush_buffer */
4398 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4401 cy_hangup(struct tty_struct
*tty
)
4403 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4405 #ifdef CY_DEBUG_OTHER
4406 printk("cyc:cy_hangup ttyC%d\n", info
->line
); /* */
4409 if (serial_paranoia_check(info
, tty
->name
, "cy_hangup"))
4412 cy_flush_buffer(tty
);
4416 #ifdef CY_DEBUG_COUNT
4417 printk("cyc:cy_hangup (%d): setting count to 0\n", current
->pid
);
4420 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
4421 wake_up_interruptible(&info
->open_wait
);
4426 * ---------------------------------------------------------------------
4427 * cy_init() and friends
4429 * cy_init() is called at boot-time to initialize the serial driver.
4430 * ---------------------------------------------------------------------
4433 /* initialize chips on Cyclom-Y card -- return number of valid
4434 chips (which is number of ports/4) */
4435 static unsigned short __init
4436 cyy_init_card(void __iomem
*true_base_addr
,int index
)
4438 unsigned int chip_number
;
4439 void __iomem
*base_addr
;
4441 cy_writeb(true_base_addr
+(Cy_HwReset
<<index
), 0);
4442 /* Cy_HwReset is 0x1400 */
4443 cy_writeb(true_base_addr
+(Cy_ClrIntr
<<index
), 0);
4444 /* Cy_ClrIntr is 0x1800 */
4447 for(chip_number
=0; chip_number
<CyMAX_CHIPS_PER_CARD
; chip_number
++){
4448 base_addr
= true_base_addr
+ (cy_chip_offset
[chip_number
]<<index
);
4450 if(cy_readb(base_addr
+(CyCCR
<<index
)) != 0x00){
4452 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4453 chip_number, (unsigned long)base_addr);
4458 cy_writeb(base_addr
+(CyGFRCR
<<index
), 0);
4461 /* The Cyclom-16Y does not decode address bit 9 and therefore
4462 cannot distinguish between references to chip 0 and a non-
4463 existent chip 4. If the preceding clearing of the supposed
4464 chip 4 GFRCR register appears at chip 0, there is no chip 4
4465 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4467 if (chip_number
== 4
4468 && cy_readb(true_base_addr
4469 + (cy_chip_offset
[0]<<index
)
4470 + (CyGFRCR
<<index
)) == 0){
4474 cy_writeb(base_addr
+(CyCCR
<<index
), CyCHIP_RESET
);
4477 if(cy_readb(base_addr
+(CyGFRCR
<<index
)) == 0x00){
4479 printk(" chip #%d at %#6lx is not responding ",
4480 chip_number, (unsigned long)base_addr);
4481 printk("(GFRCR stayed 0)\n",
4485 if((0xf0 & (cy_readb(base_addr
+(CyGFRCR
<<index
)))) != 0x40){
4487 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4488 chip_number, (unsigned long)base_addr,
4489 base_addr[CyGFRCR<<index]);
4493 cy_writeb(base_addr
+(CyGCR
<<index
), CyCH0_SERIAL
);
4494 if (cy_readb(base_addr
+(CyGFRCR
<<index
)) >= CD1400_REV_J
){
4495 /* It is a CD1400 rev. J or later */
4496 /* Impossible to reach 5ms with this chip.
4497 Changed to 2ms instead (f = 500 Hz). */
4498 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_60_2MS
);
4501 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_25_5MS
);
4505 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4506 chip_number, (unsigned long)base_addr,
4507 cy_readb(base_addr+(CyGFRCR<<index)));
4511 } /* cyy_init_card */
4514 * ---------------------------------------------------------------------
4515 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4516 * sets global variables and return the number of ISA boards found.
4517 * ---------------------------------------------------------------------
4523 unsigned short cy_isa_irq
,nboard
;
4524 void __iomem
*cy_isa_address
;
4525 unsigned short i
,j
,cy_isa_nchan
;
4533 /* Check for module parameters */
4534 for(i
= 0 ; i
< NR_CARDS
; i
++) {
4535 if (maddr
[i
] || i
) {
4537 cy_isa_addresses
[i
] = maddr
[i
];
4544 /* scan the address table probing for Cyclom-Y/ISA boards */
4545 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
4546 unsigned int isa_address
= cy_isa_addresses
[i
];
4547 if (isa_address
== 0x0000) {
4551 /* probe for CD1400... */
4552 cy_isa_address
= ioremap(isa_address
, CyISA_Ywin
);
4553 cy_isa_nchan
= CyPORTS_PER_CHIP
*
4554 cyy_init_card(cy_isa_address
,0);
4555 if (cy_isa_nchan
== 0) {
4560 if (isparam
&& irq
[i
])
4561 cy_isa_irq
= irq
[i
];
4564 /* find out the board's irq by probing */
4565 cy_isa_irq
= detect_isa_irq(cy_isa_address
);
4566 if (cy_isa_irq
== 0) {
4567 printk("Cyclom-Y/ISA found at 0x%lx ",
4568 (unsigned long) cy_isa_address
);
4569 printk("but the IRQ could not be detected.\n");
4573 if((cy_next_channel
+cy_isa_nchan
) > NR_PORTS
) {
4574 printk("Cyclom-Y/ISA found at 0x%lx ",
4575 (unsigned long) cy_isa_address
);
4576 printk("but no more channels are available.\n");
4577 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4580 /* fill the next cy_card structure available */
4581 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4582 if (cy_card
[j
].base_addr
== 0) break;
4584 if (j
== NR_CARDS
) { /* no more cy_cards available */
4585 printk("Cyclom-Y/ISA found at 0x%lx ",
4586 (unsigned long) cy_isa_address
);
4587 printk("but no more cards can be used .\n");
4588 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4593 if(request_irq(cy_isa_irq
, cyy_interrupt
,
4594 IRQF_DISABLED
, "Cyclom-Y", &cy_card
[j
]))
4596 printk("Cyclom-Y/ISA found at 0x%lx ",
4597 (unsigned long) cy_isa_address
);
4598 printk("but could not allocate IRQ#%d.\n",
4604 cy_card
[j
].base_addr
= cy_isa_address
;
4605 cy_card
[j
].ctl_addr
= NULL
;
4606 cy_card
[j
].irq
= (int) cy_isa_irq
;
4607 cy_card
[j
].bus_index
= 0;
4608 cy_card
[j
].first_line
= cy_next_channel
;
4609 cy_card
[j
].num_chips
= cy_isa_nchan
/4;
4613 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4614 j
+1, (unsigned long) cy_isa_address
,
4615 (unsigned long)(cy_isa_address
+ (CyISA_Ywin
- 1)),
4617 printk("%d channels starting from port %d.\n",
4618 cy_isa_nchan
, cy_next_channel
);
4619 cy_next_channel
+= cy_isa_nchan
;
4624 #endif /* CONFIG_ISA */
4625 } /* cy_detect_isa */
4628 plx_init(void __iomem
*addr
, uclong initctl
)
4631 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x40000000);
4633 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x40000000);
4635 /* Reload Config. Registers from EEPROM */
4636 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x20000000);
4638 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x20000000);
4642 * ---------------------------------------------------------------------
4643 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4644 * sets global variables and return the number of PCI boards found.
4645 * ---------------------------------------------------------------------
4652 struct pci_dev
*pdev
= NULL
;
4653 unsigned char cyy_rev_id
;
4654 unsigned char cy_pci_irq
= 0;
4655 uclong cy_pci_phys0
, cy_pci_phys2
;
4656 void __iomem
*cy_pci_addr0
, *cy_pci_addr2
;
4657 unsigned short i
,j
,cy_pci_nchan
, plx_ver
;
4658 unsigned short device_id
,dev_index
= 0;
4661 void __iomem
*Ze_addr0
[NR_CARDS
], *Ze_addr2
[NR_CARDS
];
4662 uclong Ze_phys0
[NR_CARDS
], Ze_phys2
[NR_CARDS
];
4663 unsigned char Ze_irq
[NR_CARDS
];
4664 struct pci_dev
*Ze_pdev
[NR_CARDS
];
4666 for (i
= 0; i
< NR_CARDS
; i
++) {
4667 /* look for a Cyclades card by vendor and device id */
4668 while((device_id
= cy_pci_dev_id
[dev_index
]) != 0) {
4669 if((pdev
= pci_get_device(PCI_VENDOR_ID_CYCLADES
,
4670 device_id
, pdev
)) == NULL
) {
4671 dev_index
++; /* try next device id */
4673 break; /* found a board */
4680 if (pci_enable_device(pdev
))
4683 /* read PCI configuration area */
4684 cy_pci_irq
= pdev
->irq
;
4685 cy_pci_phys0
= pci_resource_start(pdev
, 0);
4686 cy_pci_phys2
= pci_resource_start(pdev
, 2);
4687 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &cyy_rev_id
);
4689 device_id
&= ~PCI_DEVICE_ID_MASK
;
4691 if ((device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
)
4692 || (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Hi
)){
4694 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4695 pdev
->bus
->number
, pdev
->devfn
);
4696 printk("rev_id=%d) IRQ%d\n",
4697 cyy_rev_id
, (int)cy_pci_irq
);
4698 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4699 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4702 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4703 printk(" Warning: PCI I/O bit incorrectly set. "
4704 "Ignoring it...\n");
4705 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4708 /* Although we don't use this I/O region, we should
4709 request it from the kernel anyway, to avoid problems
4710 with other drivers accessing it. */
4711 if (pci_request_regions(pdev
, "Cyclom-Y") != 0) {
4712 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4716 #if defined(__alpha__)
4717 if (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
) { /* below 1M? */
4718 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4719 pdev
->bus
->number
, pdev
->devfn
);
4720 printk("rev_id=%d) IRQ%d\n",
4721 cyy_rev_id
, (int)cy_pci_irq
);
4722 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4723 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4724 printk("Cyclom-Y/PCI not supported for low addresses in "
4725 "Alpha systems.\n");
4730 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Yctl
);
4731 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ywin
);
4734 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4735 (u_long
)cy_pci_addr2
, (u_long
)cy_pci_addr0
);
4737 cy_pci_nchan
= (unsigned short)(CyPORTS_PER_CHIP
*
4738 cyy_init_card(cy_pci_addr2
, 1));
4739 if(cy_pci_nchan
== 0) {
4740 printk("Cyclom-Y PCI host card with ");
4741 printk("no Serial-Modules at 0x%lx.\n",
4742 (ulong
) cy_pci_phys2
);
4746 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4747 printk("Cyclom-Y/PCI found at 0x%lx ",
4748 (ulong
) cy_pci_phys2
);
4749 printk("but no channels are available.\n");
4750 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4753 /* fill the next cy_card structure available */
4754 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4755 if (cy_card
[j
].base_addr
== 0) break;
4757 if (j
== NR_CARDS
) { /* no more cy_cards available */
4758 printk("Cyclom-Y/PCI found at 0x%lx ",
4759 (ulong
) cy_pci_phys2
);
4760 printk("but no more cards can be used.\n");
4761 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4766 if(request_irq(cy_pci_irq
, cyy_interrupt
,
4767 IRQF_SHARED
, "Cyclom-Y", &cy_card
[j
]))
4769 printk("Cyclom-Y/PCI found at 0x%lx ",
4770 (ulong
) cy_pci_phys2
);
4771 printk("but could not allocate IRQ%d.\n",
4777 cy_card
[j
].base_phys
= (ulong
)cy_pci_phys2
;
4778 cy_card
[j
].ctl_phys
= (ulong
)cy_pci_phys0
;
4779 cy_card
[j
].base_addr
= cy_pci_addr2
;
4780 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
4781 cy_card
[j
].irq
= (int) cy_pci_irq
;
4782 cy_card
[j
].bus_index
= 1;
4783 cy_card
[j
].first_line
= cy_next_channel
;
4784 cy_card
[j
].num_chips
= cy_pci_nchan
/4;
4785 cy_card
[j
].pdev
= pdev
;
4787 /* enable interrupts in the PCI interface */
4788 plx_ver
= cy_readb(cy_pci_addr2
+ CyPLX_VER
) & 0x0f;
4792 cy_writeb(cy_pci_addr0
+0x4c, 0x43);
4797 default: /* Old boards, use PLX_9060 */
4799 plx_init(cy_pci_addr0
, 0x6c);
4800 /* For some yet unknown reason, once the PLX9060 reloads
4801 the EEPROM, the IRQ is lost and, thus, we have to
4802 re-write it to the PCI config. registers.
4803 This will remain here until we find a permanent fix. */
4804 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4806 cy_writew(cy_pci_addr0
+0x68,
4807 cy_readw(cy_pci_addr0
+0x68)|0x0900);
4812 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4814 (ulong
)cy_pci_phys2
,
4815 (ulong
)(cy_pci_phys2
+ CyPCI_Ywin
- 1),
4817 printk("%d channels starting from port %d.\n",
4818 cy_pci_nchan
, cy_next_channel
);
4820 cy_next_channel
+= cy_pci_nchan
;
4821 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Lo
){
4823 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4824 pdev
->bus
->number
, pdev
->devfn
);
4825 printk("rev_id=%d) IRQ%d\n",
4826 cyy_rev_id
, (int)cy_pci_irq
);
4827 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4828 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4829 printk("Cyclades-Z/PCI not supported for low addresses\n");
4831 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Hi
){
4833 printk("Cyclades-Z/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("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4838 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4840 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Zctl
);
4842 /* Disable interrupts on the PLX before resetting it */
4843 cy_writew(cy_pci_addr0
+0x68,
4844 cy_readw(cy_pci_addr0
+0x68) & ~0x0900);
4846 plx_init(cy_pci_addr0
, 0x6c);
4847 /* For some yet unknown reason, once the PLX9060 reloads
4848 the EEPROM, the IRQ is lost and, thus, we have to
4849 re-write it to the PCI config. registers.
4850 This will remain here until we find a permanent fix. */
4851 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4853 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
4854 cy_pci_addr0
)->mail_box_0
);
4856 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4857 printk(" Warning: PCI I/O bit incorrectly set. "
4858 "Ignoring it...\n");
4859 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4862 /* Although we don't use this I/O region, we should
4863 request it from the kernel anyway, to avoid problems
4864 with other drivers accessing it. */
4865 if (pci_request_regions(pdev
, "Cyclades-Z") != 0) {
4866 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4870 if (mailbox
== ZE_V1
) {
4871 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ze_win
);
4872 if (ZeIndex
== NR_CARDS
) {
4873 printk("Cyclades-Ze/PCI found at 0x%lx ",
4874 (ulong
)cy_pci_phys2
);
4875 printk("but no more cards can be used.\n");
4876 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4878 Ze_phys0
[ZeIndex
] = cy_pci_phys0
;
4879 Ze_phys2
[ZeIndex
] = cy_pci_phys2
;
4880 Ze_addr0
[ZeIndex
] = cy_pci_addr0
;
4881 Ze_addr2
[ZeIndex
] = cy_pci_addr2
;
4882 Ze_irq
[ZeIndex
] = cy_pci_irq
;
4883 Ze_pdev
[ZeIndex
] = pdev
;
4889 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Zwin
);
4893 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4894 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4895 if (mailbox
== ZO_V1
) {
4896 cy_writel(&((struct RUNTIME_9060
*)
4897 (cy_pci_addr0
))->loc_addr_base
, WIN_CREG
);
4899 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
4900 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
4901 (cy_pci_addr2
))->fpga_id
)),
4902 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
4903 (cy_pci_addr2
))->fpga_version
)));
4904 cy_writel(&((struct RUNTIME_9060
*)
4905 (cy_pci_addr0
))->loc_addr_base
, WIN_RAM
);
4907 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
4910 /* The following clears the firmware id word. This ensures
4911 that the driver will not attempt to talk to the board
4912 until it has been properly initialized.
4915 if ((mailbox
== ZO_V1
) || (mailbox
== ZO_V2
))
4916 cy_writel(cy_pci_addr2
+ ID_ADDRESS
, 0L);
4918 /* This must be a Cyclades-8Zo/PCI. The extendable
4919 version will have a different device_id and will
4920 be allocated its maximum number of ports. */
4923 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4924 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4925 (ulong
)cy_pci_phys2
);
4926 printk("but no channels are available.\n");
4927 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4931 /* fill the next cy_card structure available */
4932 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4933 if (cy_card
[j
].base_addr
== 0) break;
4935 if (j
== NR_CARDS
) { /* no more cy_cards available */
4936 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4937 (ulong
)cy_pci_phys2
);
4938 printk("but no more cards can be used.\n");
4939 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4943 #ifdef CONFIG_CYZ_INTR
4944 /* allocate IRQ only if board has an IRQ */
4945 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
4946 if(request_irq(cy_pci_irq
, cyz_interrupt
,
4947 IRQF_SHARED
, "Cyclades-Z", &cy_card
[j
]))
4949 printk("Cyclom-8Zo/PCI found at 0x%lx ",
4950 (ulong
) cy_pci_phys2
);
4951 printk("but could not allocate IRQ%d.\n",
4956 #endif /* CONFIG_CYZ_INTR */
4960 cy_card
[j
].base_phys
= cy_pci_phys2
;
4961 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
4962 cy_card
[j
].base_addr
= cy_pci_addr2
;
4963 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
4964 cy_card
[j
].irq
= (int) cy_pci_irq
;
4965 cy_card
[j
].bus_index
= 1;
4966 cy_card
[j
].first_line
= cy_next_channel
;
4967 cy_card
[j
].num_chips
= -1;
4968 cy_card
[j
].pdev
= pdev
;
4971 #ifdef CONFIG_CYZ_INTR
4972 /* don't report IRQ if board is no IRQ */
4973 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
4974 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4975 j
+1,(ulong
)cy_pci_phys2
,
4976 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1),
4979 #endif /* CONFIG_CYZ_INTR */
4980 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
4981 j
+1,(ulong
)cy_pci_phys2
,
4982 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1));
4984 printk("%d channels starting from port %d.\n",
4985 cy_pci_nchan
,cy_next_channel
);
4986 cy_next_channel
+= cy_pci_nchan
;
4990 for (; ZeIndex
!= 0 && i
< NR_CARDS
; i
++) {
4991 cy_pci_phys0
= Ze_phys0
[0];
4992 cy_pci_phys2
= Ze_phys2
[0];
4993 cy_pci_addr0
= Ze_addr0
[0];
4994 cy_pci_addr2
= Ze_addr2
[0];
4995 cy_pci_irq
= Ze_irq
[0];
4997 for (j
= 0 ; j
< ZeIndex
-1 ; j
++) {
4998 Ze_phys0
[j
] = Ze_phys0
[j
+1];
4999 Ze_phys2
[j
] = Ze_phys2
[j
+1];
5000 Ze_addr0
[j
] = Ze_addr0
[j
+1];
5001 Ze_addr2
[j
] = Ze_addr2
[j
+1];
5002 Ze_irq
[j
] = Ze_irq
[j
+1];
5003 Ze_pdev
[j
] = Ze_pdev
[j
+1];
5006 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
5007 cy_pci_addr0
)->mail_box_0
);
5009 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5010 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5011 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5014 /* This must be the new Cyclades-Ze/PCI. */
5015 cy_pci_nchan
= ZE_V1_NPORTS
;
5017 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5018 printk("Cyclades-Ze/PCI found at 0x%lx ",
5019 (ulong
)cy_pci_phys2
);
5020 printk("but no channels are available.\n");
5021 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5025 /* fill the next cy_card structure available */
5026 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5027 if (cy_card
[j
].base_addr
== 0) break;
5029 if (j
== NR_CARDS
) { /* no more cy_cards available */
5030 printk("Cyclades-Ze/PCI found at 0x%lx ",
5031 (ulong
)cy_pci_phys2
);
5032 printk("but no more cards can be used.\n");
5033 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5037 #ifdef CONFIG_CYZ_INTR
5038 /* allocate IRQ only if board has an IRQ */
5039 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5040 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5041 IRQF_SHARED
, "Cyclades-Z", &cy_card
[j
]))
5043 printk("Cyclom-Ze/PCI found at 0x%lx ",
5044 (ulong
) cy_pci_phys2
);
5045 printk("but could not allocate IRQ%d.\n",
5050 #endif /* CONFIG_CYZ_INTR */
5053 cy_card
[j
].base_phys
= cy_pci_phys2
;
5054 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
5055 cy_card
[j
].base_addr
= cy_pci_addr2
;
5056 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5057 cy_card
[j
].irq
= (int) cy_pci_irq
;
5058 cy_card
[j
].bus_index
= 1;
5059 cy_card
[j
].first_line
= cy_next_channel
;
5060 cy_card
[j
].num_chips
= -1;
5061 cy_card
[j
].pdev
= pdev
;
5064 #ifdef CONFIG_CYZ_INTR
5065 /* don't report IRQ if board is no IRQ */
5066 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5067 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5068 j
+1,(ulong
)cy_pci_phys2
,
5069 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1),
5072 #endif /* CONFIG_CYZ_INTR */
5073 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5074 j
+1,(ulong
)cy_pci_phys2
,
5075 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1));
5077 printk("%d channels starting from port %d.\n",
5078 cy_pci_nchan
,cy_next_channel
);
5079 cy_next_channel
+= cy_pci_nchan
;
5082 printk("Cyclades-Ze/PCI found at 0x%x ",
5083 (unsigned int) Ze_phys2
[0]);
5084 printk("but no more cards can be used.\n");
5085 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5090 #endif /* ifdef CONFIG_PCI */
5091 } /* cy_detect_pci */
5095 * This routine prints out the appropriate serial driver version number
5096 * and identifies which options were configured into this driver.
5101 char *rcsvers
, *rcsdate
, *tmp
;
5102 rcsvers
= strchr(rcsid
, ' '); rcsvers
++;
5103 tmp
= strchr(rcsvers
, ' '); *tmp
++ = '\0';
5104 rcsdate
= strchr(tmp
, ' '); rcsdate
++;
5105 tmp
= strrchr(rcsdate
, ' '); *tmp
= '\0';
5106 printk("Cyclades driver %s %s\n",
5108 printk(" built %s %s\n",
5109 __DATE__
, __TIME__
);
5110 } /* show_version */
5113 cyclades_get_proc_info(char *buf
, char **start
, off_t offset
, int length
,
5114 int *eof
, void *data
)
5116 struct cyclades_port
*info
;
5122 __u32 cur_jifs
= jiffies
;
5124 size
= sprintf(buf
, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
5129 /* Output one line for each known port */
5130 for (i
= 0; i
< NR_PORTS
&& cy_port
[i
].line
>= 0; i
++) {
5134 size
= sprintf(buf
+len
,
5135 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5137 JIFFIES_DIFF(info
->idle_stats
.in_use
, cur_jifs
) / HZ
,
5138 info
->idle_stats
.xmit_bytes
,
5139 JIFFIES_DIFF(info
->idle_stats
.xmit_idle
, cur_jifs
) / HZ
,
5140 info
->idle_stats
.recv_bytes
,
5141 JIFFIES_DIFF(info
->idle_stats
.recv_idle
, cur_jifs
) / HZ
,
5142 info
->idle_stats
.overruns
,
5143 (long) info
->tty
->ldisc
.num
);
5145 size
= sprintf(buf
+len
,
5146 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5147 info
->line
, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5155 if (pos
> offset
+ length
)
5160 *start
= buf
+ (offset
- begin
); /* Start of wanted data */
5161 len
-= (offset
- begin
); /* Start slop */
5163 len
= length
; /* Ending slop */
5169 /* The serial driver boot-time initialization code!
5170 Hardware I/O ports are mapped to character special devices on a
5171 first found, first allocated manner. That is, this code searches
5172 for Cyclom cards in the system. As each is found, it is probed
5173 to discover how many chips (and thus how many ports) are present.
5174 These ports are mapped to the tty ports 32 and upward in monotonic
5175 fashion. If an 8-port card is replaced with a 16-port card, the
5176 port mapping on a following card will shift.
5178 This approach is different from what is used in the other serial
5179 device driver because the Cyclom is more properly a multiplexer,
5180 not just an aggregation of serial ports on one card.
5182 If there are more cards with more ports than have been
5183 statically allocated above, a warning is printed and the
5184 extra ports are ignored.
5187 static const struct tty_operations cy_ops
= {
5191 .put_char
= cy_put_char
,
5192 .flush_chars
= cy_flush_chars
,
5193 .write_room
= cy_write_room
,
5194 .chars_in_buffer
= cy_chars_in_buffer
,
5195 .flush_buffer
= cy_flush_buffer
,
5197 .throttle
= cy_throttle
,
5198 .unthrottle
= cy_unthrottle
,
5199 .set_termios
= cy_set_termios
,
5202 .hangup
= cy_hangup
,
5203 .break_ctl
= cy_break
,
5204 .wait_until_sent
= cy_wait_until_sent
,
5205 .read_proc
= cyclades_get_proc_info
,
5206 .tiocmget
= cy_tiocmget
,
5207 .tiocmset
= cy_tiocmset
,
5213 struct cyclades_port
*info
;
5214 struct cyclades_card
*cinfo
;
5215 int number_z_boards
= 0;
5216 int board
,port
,i
,index
;
5217 unsigned long mailbox
;
5218 unsigned short chip_number
;
5221 cy_serial_driver
= alloc_tty_driver(NR_PORTS
);
5222 if (!cy_serial_driver
)
5226 /* Initialize the tty_driver structure */
5228 cy_serial_driver
->owner
= THIS_MODULE
;
5229 cy_serial_driver
->driver_name
= "cyclades";
5230 cy_serial_driver
->name
= "ttyC";
5231 cy_serial_driver
->major
= CYCLADES_MAJOR
;
5232 cy_serial_driver
->minor_start
= 0;
5233 cy_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
5234 cy_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
5235 cy_serial_driver
->init_termios
= tty_std_termios
;
5236 cy_serial_driver
->init_termios
.c_cflag
=
5237 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5238 cy_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
5239 tty_set_operations(cy_serial_driver
, &cy_ops
);
5241 if (tty_register_driver(cy_serial_driver
))
5242 panic("Couldn't register Cyclades serial driver\n");
5244 for (i
= 0; i
< NR_CARDS
; i
++) {
5245 /* base_addr=0 indicates board not found */
5246 cy_card
[i
].base_addr
= NULL
;
5249 /* the code below is responsible to find the boards. Each different
5250 type of board has its own detection routine. If a board is found,
5251 the next cy_card structure available is set by the detection
5252 routine. These functions are responsible for checking the
5253 availability of cy_card and cy_port data structures and updating
5254 the cy_next_channel. */
5256 /* look for isa boards */
5257 cy_isa_nboard
= cy_detect_isa();
5259 /* look for pci boards */
5260 cy_pci_nboard
= cy_detect_pci();
5262 cy_nboard
= cy_isa_nboard
+ cy_pci_nboard
;
5264 /* invalidate remaining cy_card structures */
5265 for (i
= 0 ; i
< NR_CARDS
; i
++) {
5266 if (cy_card
[i
].base_addr
== 0) {
5267 cy_card
[i
].first_line
= -1;
5268 cy_card
[i
].ctl_addr
= NULL
;
5270 cy_card
[i
].bus_index
= 0;
5271 cy_card
[i
].first_line
= 0;
5272 cy_card
[i
].num_chips
= 0;
5275 /* invalidate remaining cy_port structures */
5276 for (i
= cy_next_channel
; i
< NR_PORTS
; i
++) {
5277 cy_port
[i
].line
= -1;
5278 cy_port
[i
].magic
= -1;
5281 /* initialize per-port data structures for each valid board found */
5282 for (board
= 0 ; board
< cy_nboard
; board
++) {
5283 cinfo
= &cy_card
[board
];
5284 if (cinfo
->num_chips
== -1) { /* Cyclades-Z */
5286 mailbox
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
5287 cy_card
[board
].ctl_addr
)->mail_box_0
);
5288 nports
= (mailbox
== ZE_V1
) ? ZE_V1_NPORTS
: 8;
5289 cinfo
->intr_enabled
= 0;
5290 cinfo
->nports
= 0; /* Will be correctly set later, after
5292 spin_lock_init(&cinfo
->card_lock
);
5293 for (port
= cinfo
->first_line
;
5294 port
< cinfo
->first_line
+ nports
;
5297 info
= &cy_port
[port
];
5298 info
->magic
= CYCLADES_MAGIC
;
5299 info
->type
= PORT_STARTECH
;
5303 info
->flags
= STD_COM_FLAGS
;
5305 if (mailbox
== ZO_V1
)
5306 info
->xmit_fifo_size
= CYZ_FIFO_SIZE
;
5308 info
->xmit_fifo_size
= 4 * CYZ_FIFO_SIZE
;
5318 info
->custom_divisor
= 0;
5319 info
->close_delay
= 5*HZ
/10;
5320 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5321 info
->icount
.cts
= info
->icount
.dsr
=
5322 info
->icount
.rng
= info
->icount
.dcd
= 0;
5323 info
->icount
.rx
= info
->icount
.tx
= 0;
5324 info
->icount
.frame
= info
->icount
.parity
= 0;
5325 info
->icount
.overrun
= info
->icount
.brk
= 0;
5329 info
->blocked_open
= 0;
5330 info
->default_threshold
= 0;
5331 info
->default_timeout
= 0;
5332 INIT_WORK(&info
->tqueue
, do_softint
);
5333 init_waitqueue_head(&info
->open_wait
);
5334 init_waitqueue_head(&info
->close_wait
);
5335 init_waitqueue_head(&info
->shutdown_wait
);
5336 init_waitqueue_head(&info
->delta_msr_wait
);
5339 info
->read_status_mask
= 0;
5341 /* Bentson's vars */
5342 info
->jiffies
[0] = 0;
5343 info
->jiffies
[1] = 0;
5344 info
->jiffies
[2] = 0;
5345 info
->rflush_count
= 0;
5346 #ifdef CONFIG_CYZ_INTR
5347 init_timer(&cyz_rx_full_timer
[port
]);
5348 cyz_rx_full_timer
[port
].function
= NULL
;
5352 }else{ /* Cyclom-Y of some kind*/
5353 index
= cinfo
->bus_index
;
5354 spin_lock_init(&cinfo
->card_lock
);
5355 cinfo
->nports
= CyPORTS_PER_CHIP
* cinfo
->num_chips
;
5356 for (port
= cinfo
->first_line
;
5357 port
< cinfo
->first_line
+ cinfo
->nports
;
5360 info
= &cy_port
[port
];
5361 info
->magic
= CYCLADES_MAGIC
;
5362 info
->type
= PORT_CIRRUS
;
5365 info
->flags
= STD_COM_FLAGS
;
5367 info
->xmit_fifo_size
= CyMAX_CHAR_FIFO
;
5368 info
->cor1
= CyPARITY_NONE
|Cy_1_STOP
|Cy_8_BITS
;
5370 info
->cor3
= 0x08; /* _very_ small rcv threshold */
5373 info
->custom_divisor
= 0;
5374 info
->close_delay
= 5*HZ
/10;
5375 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5376 info
->icount
.cts
= info
->icount
.dsr
=
5377 info
->icount
.rng
= info
->icount
.dcd
= 0;
5378 info
->icount
.rx
= info
->icount
.tx
= 0;
5379 info
->icount
.frame
= info
->icount
.parity
= 0;
5380 info
->icount
.overrun
= info
->icount
.brk
= 0;
5381 chip_number
= (port
- cinfo
->first_line
) / 4;
5382 if ((info
->chip_rev
=
5383 cy_readb(cinfo
->base_addr
+
5384 (cy_chip_offset
[chip_number
]<<index
) +
5385 (CyGFRCR
<<index
))) >= CD1400_REV_J
) {
5386 /* It is a CD1400 rev. J or later */
5387 info
->tbpr
= baud_bpr_60
[13]; /* Tx BPR */
5388 info
->tco
= baud_co_60
[13]; /* Tx CO */
5389 info
->rbpr
= baud_bpr_60
[13]; /* Rx BPR */
5390 info
->rco
= baud_co_60
[13]; /* Rx CO */
5392 info
->rtsdtr_inv
= 1;
5394 info
->tbpr
= baud_bpr_25
[13]; /* Tx BPR */
5395 info
->tco
= baud_co_25
[13]; /* Tx CO */
5396 info
->rbpr
= baud_bpr_25
[13]; /* Rx BPR */
5397 info
->rco
= baud_co_25
[13]; /* Rx CO */
5399 info
->rtsdtr_inv
= 0;
5404 info
->blocked_open
= 0;
5405 info
->default_threshold
= 0;
5406 info
->default_timeout
= 0;
5407 INIT_WORK(&info
->tqueue
, do_softint
);
5408 init_waitqueue_head(&info
->open_wait
);
5409 init_waitqueue_head(&info
->close_wait
);
5410 init_waitqueue_head(&info
->shutdown_wait
);
5411 init_waitqueue_head(&info
->delta_msr_wait
);
5414 info
->read_status_mask
=
5415 CyTIMEOUT
| CySPECHAR
| CyBREAK
5416 | CyPARITY
| CyFRAME
| CyOVERRUN
;
5422 #ifndef CONFIG_CYZ_INTR
5423 if (number_z_boards
&& !cyz_timeron
){
5425 cyz_timerlist
.expires
= jiffies
+ 1;
5426 add_timer(&cyz_timerlist
);
5428 printk("Cyclades-Z polling initialized\n");
5431 #endif /* CONFIG_CYZ_INTR */
5438 cy_cleanup_module(void)
5442 #ifndef CONFIG_CYZ_INTR
5445 del_timer(&cyz_timerlist
);
5447 #endif /* CONFIG_CYZ_INTR */
5449 if ((e1
= tty_unregister_driver(cy_serial_driver
)))
5450 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5453 put_tty_driver(cy_serial_driver
);
5455 for (i
= 0; i
< NR_CARDS
; i
++) {
5456 if (cy_card
[i
].base_addr
) {
5457 iounmap(cy_card
[i
].base_addr
);
5458 if (cy_card
[i
].ctl_addr
)
5459 iounmap(cy_card
[i
].ctl_addr
);
5461 #ifndef CONFIG_CYZ_INTR
5462 && cy_card
[i
].num_chips
!= -1 /* not a Z card */
5463 #endif /* CONFIG_CYZ_INTR */
5465 free_irq(cy_card
[i
].irq
, &cy_card
[i
]);
5467 if (cy_card
[i
].pdev
)
5468 pci_release_regions(cy_card
[i
].pdev
);
5472 } /* cy_cleanup_module */
5474 module_init(cy_init
);
5475 module_exit(cy_cleanup_module
);
5477 MODULE_LICENSE("GPL");