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 * tmp_buf is used as a temporary buffer by serial_write. We need to
752 * lock it in case the copy_from_user blocks while swapping in a page,
753 * and some other program tries to do a serial write at the same time.
754 * Since the lock will only come under contention when the system is
755 * swapping and available memory is low, it makes sense to share one
756 * buffer across all the serial ports, since it significantly saves
757 * memory if large numbers of serial ports are open. This buffer is
758 * allocated when the first cy_open occurs.
760 static unsigned char *tmp_buf
;
763 * This is used to look up the divisor speeds and the timeouts
764 * We're normally limited to 15 distinct baud rates. The extra
765 * are accessed via settings in info->flags.
766 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
767 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
771 static int baud_table
[] = {
772 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
773 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
776 static char baud_co_25
[] = { /* 25 MHz clock option table */
777 /* value => 00 01 02 03 04 */
778 /* divide by 8 32 128 512 2048 */
779 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
780 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
782 static char baud_bpr_25
[] = { /* 25 MHz baud rate period table */
783 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
784 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
786 static char baud_co_60
[] = { /* 60 MHz clock option table (CD1400 J) */
787 /* value => 00 01 02 03 04 */
788 /* divide by 8 32 128 512 2048 */
789 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
790 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
793 static char baud_bpr_60
[] = { /* 60 MHz baud rate period table (CD1400 J) */
794 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
795 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
798 static char baud_cor3
[] = { /* receive threshold */
799 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
800 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
804 * The Cyclades driver implements HW flow control as any serial driver.
805 * The cyclades_port structure member rflow and the vector rflow_thr
806 * allows us to take advantage of a special feature in the CD1400 to avoid
807 * data loss even when the system interrupt latency is too high. These flags
808 * are to be used only with very special applications. Setting these flags
809 * requires the use of a special cable (DTR and RTS reversed). In the new
810 * CD1400-based boards (rev. 6.00 or later), there is no need for special
814 static char rflow_thr
[] = { /* rflow threshold */
815 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
816 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
819 /* The Cyclom-Ye has placed the sequential chips in non-sequential
820 * address order. This look-up table overcomes that problem.
822 static int cy_chip_offset
[] =
833 /* PCI related definitions */
835 static unsigned short cy_pci_nboard
;
836 static unsigned short cy_isa_nboard
;
837 static unsigned short cy_nboard
;
839 static unsigned short cy_pci_dev_id
[] = {
840 PCI_DEVICE_ID_CYCLOM_Y_Lo
, /* PCI < 1Mb */
841 PCI_DEVICE_ID_CYCLOM_Y_Hi
, /* PCI > 1Mb */
842 PCI_DEVICE_ID_CYCLOM_4Y_Lo
, /* 4Y PCI < 1Mb */
843 PCI_DEVICE_ID_CYCLOM_4Y_Hi
, /* 4Y PCI > 1Mb */
844 PCI_DEVICE_ID_CYCLOM_8Y_Lo
, /* 8Y PCI < 1Mb */
845 PCI_DEVICE_ID_CYCLOM_8Y_Hi
, /* 8Y PCI > 1Mb */
846 PCI_DEVICE_ID_CYCLOM_Z_Lo
, /* Z PCI < 1Mb */
847 PCI_DEVICE_ID_CYCLOM_Z_Hi
, /* Z PCI > 1Mb */
852 static void cy_start(struct tty_struct
*);
853 static void set_line_char(struct cyclades_port
*);
854 static int cyz_issue_cmd(struct cyclades_card
*, uclong
, ucchar
, uclong
);
856 static unsigned detect_isa_irq(void __iomem
*);
857 #endif /* CONFIG_ISA */
859 static int cyclades_get_proc_info(char *, char **, off_t
, int , int *, void *);
861 #ifndef CONFIG_CYZ_INTR
862 static void cyz_poll(unsigned long);
864 /* The Cyclades-Z polling cycle is defined by this variable */
865 static long cyz_polling_cycle
= CZ_DEF_POLL
;
867 static int cyz_timeron
= 0;
868 static DEFINE_TIMER(cyz_timerlist
, cyz_poll
, 0, 0);
870 #else /* CONFIG_CYZ_INTR */
871 static void cyz_rx_restart(unsigned long);
872 static struct timer_list cyz_rx_full_timer
[NR_PORTS
];
873 #endif /* CONFIG_CYZ_INTR */
876 serial_paranoia_check(struct cyclades_port
*info
,
877 char *name
, const char *routine
)
879 #ifdef SERIAL_PARANOIA_CHECK
880 static const char *badmagic
=
881 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
882 static const char *badinfo
=
883 "cyc Warning: null cyclades_port for (%s) in %s\n";
884 static const char *badrange
=
885 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
888 printk(badinfo
, name
, routine
);
892 if( (long)info
< (long)(&cy_port
[0])
893 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
894 printk(badrange
, name
, routine
);
898 if (info
->magic
!= CYCLADES_MAGIC
) {
899 printk(badmagic
, name
, routine
);
904 } /* serial_paranoia_check */
907 * This routine is used by the interrupt handler to schedule
908 * processing in the software interrupt portion of the driver
909 * (also known as the "bottom half"). This can be called any
910 * number of times for any channel without harm.
913 cy_sched_event(struct cyclades_port
*info
, int event
)
915 info
->event
|= 1 << event
; /* remember what kind of event and who */
916 schedule_work(&info
->tqueue
);
917 } /* cy_sched_event */
921 * This routine is used to handle the "bottom half" processing for the
922 * serial driver, known also the "software interrupt" processing.
923 * This processing is done at the kernel interrupt level, after the
924 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
925 * is where time-consuming activities which can not be done in the
926 * interrupt driver proper are done; the interrupt driver schedules
927 * them using cy_sched_event(), and they get done here.
929 * This is done through one level of indirection--the task queue.
930 * When a hardware interrupt service routine wants service by the
931 * driver's bottom half, it enqueues the appropriate tq_struct (one
932 * per port) to the keventd work queue and sets a request flag
933 * that the work queue be processed.
935 * Although this may seem unwieldy, it gives the system a way to
936 * pass an argument (in this case the pointer to the cyclades_port
937 * structure) to the bottom half of the driver. Previous kernels
938 * had to poll every port to see if that port needed servicing.
941 do_softint(void *private_
)
943 struct cyclades_port
*info
= (struct cyclades_port
*) private_
;
944 struct tty_struct
*tty
;
950 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
951 tty_hangup(info
->tty
);
952 wake_up_interruptible(&info
->open_wait
);
953 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
955 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
956 wake_up_interruptible(&info
->open_wait
);
958 #ifdef CONFIG_CYZ_INTR
959 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL
, &info
->event
)) {
960 if (cyz_rx_full_timer
[info
->line
].function
== NULL
) {
961 cyz_rx_full_timer
[info
->line
].expires
= jiffies
+ 1;
962 cyz_rx_full_timer
[info
->line
].function
= cyz_rx_restart
;
963 cyz_rx_full_timer
[info
->line
].data
= (unsigned long)info
;
964 add_timer(&cyz_rx_full_timer
[info
->line
]);
968 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP
, &info
->event
)) {
969 wake_up_interruptible(&info
->delta_msr_wait
);
971 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
973 wake_up_interruptible(&tty
->write_wait
);
976 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP
, &info
->event
)) {
977 wake_up_interruptible(&info
->shutdown_wait
);
983 /***********************************************************/
984 /********* Start of block of Cyclom-Y specific code ********/
986 /* This routine waits up to 1000 micro-seconds for the previous
987 command to the Cirrus chip to complete and then issues the
988 new command. An error is returned if the previous command
989 didn't finish within the time limit.
991 This function is only called from inside spinlock-protected code.
994 cyy_issue_cmd(void __iomem
*base_addr
, u_char cmd
, int index
)
998 /* Check to see that the previous command has completed */
999 for(i
= 0 ; i
< 100 ; i
++){
1000 if (cy_readb(base_addr
+(CyCCR
<<index
)) == 0){
1005 /* if the CCR never cleared, the previous command
1006 didn't finish within the "reasonable time" */
1007 if (i
== 100) return (-1);
1009 /* Issue the new command */
1010 cy_writeb(base_addr
+(CyCCR
<<index
), cmd
);
1013 } /* cyy_issue_cmd */
1016 /* ISA interrupt detection code */
1018 detect_isa_irq(void __iomem
*address
)
1021 unsigned long irqs
, flags
;
1022 int save_xir
, save_car
;
1023 int index
= 0; /* IRQ probing is only for ISA */
1025 /* forget possible initially masked and pending IRQ */
1026 irq
= probe_irq_off(probe_irq_on());
1028 /* Clear interrupts on the board first */
1029 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1030 /* Cy_ClrIntr is 0x1800 */
1032 irqs
= probe_irq_on();
1036 /* Enable the Tx interrupts on the CD1400 */
1037 local_irq_save(flags
);
1038 cy_writeb(address
+ (CyCAR
<<index
), 0);
1039 cyy_issue_cmd(address
, CyCHAN_CTL
|CyENB_XMTR
, index
);
1041 cy_writeb(address
+ (CyCAR
<<index
), 0);
1042 cy_writeb(address
+ (CySRER
<<index
),
1043 cy_readb(address
+ (CySRER
<<index
)) | CyTxRdy
);
1044 local_irq_restore(flags
);
1049 /* Check which interrupt is in use */
1050 irq
= probe_irq_off(irqs
);
1053 save_xir
= (u_char
) cy_readb(address
+ (CyTIR
<<index
));
1054 save_car
= cy_readb(address
+ (CyCAR
<<index
));
1055 cy_writeb(address
+ (CyCAR
<<index
), (save_xir
& 0x3));
1056 cy_writeb(address
+ (CySRER
<<index
),
1057 cy_readb(address
+ (CySRER
<<index
)) & ~CyTxRdy
);
1058 cy_writeb(address
+ (CyTIR
<<index
), (save_xir
& 0x3f));
1059 cy_writeb(address
+ (CyCAR
<<index
), (save_car
));
1060 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1061 /* Cy_ClrIntr is 0x1800 */
1063 return (irq
> 0)? irq
: 0;
1065 #endif /* CONFIG_ISA */
1067 /* The real interrupt service routine is called
1068 whenever the card wants its hand held--chars
1069 received, out buffer empty, modem change, etc.
1072 cyy_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1074 struct tty_struct
*tty
;
1076 struct cyclades_card
*cinfo
;
1077 struct cyclades_port
*info
;
1078 void __iomem
*base_addr
, *card_base_addr
;
1080 int save_xir
, channel
, save_car
;
1082 volatile int char_count
;
1090 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1091 #ifdef CY_DEBUG_INTERRUPTS
1092 printk("cyy_interrupt: spurious interrupt %d\n\r", irq
);
1094 return IRQ_NONE
; /* spurious interrupt */
1097 card_base_addr
= cinfo
->base_addr
;
1098 index
= cinfo
->bus_index
;
1101 /* This loop checks all chips in the card. Make a note whenever
1102 _any_ chip had some work to do, as this is considered an
1103 indication that there will be more to do. Only when no chip
1104 has any work does this outermost loop exit.
1108 for ( chip
= 0 ; chip
< cinfo
->num_chips
; chip
++) {
1109 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
1111 while ( (status
= cy_readb(base_addr
+(CySVRR
<<index
))) != 0x00) {
1113 /* The purpose of the following test is to ensure that
1114 no chip can monopolize the driver. This forces the
1115 chips to be checked in a round-robin fashion (after
1116 draining each of a bunch (1000) of characters).
1118 if(1000<too_many
++){
1121 if (status
& CySRReceive
) { /* reception interrupt */
1122 #ifdef CY_DEBUG_INTERRUPTS
1123 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip
);
1125 /* determine the channel & change to that context */
1126 spin_lock(&cinfo
->card_lock
);
1127 save_xir
= (u_char
) cy_readb(base_addr
+(CyRIR
<<index
));
1128 channel
= (u_short
) (save_xir
& CyIRChannel
);
1129 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1131 info
->last_active
= jiffies
;
1132 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1133 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1135 /* if there is nowhere to put the data, discard it */
1137 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1138 if ( j
== CyIVRRxEx
) { /* exception */
1139 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1140 } else { /* normal character reception */
1141 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1142 while(char_count
--){
1143 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1146 }else{ /* there is an open port for this data */
1148 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1149 if ( j
== CyIVRRxEx
) { /* exception */
1150 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1152 /* For statistics only */
1155 else if(data
& CyFRAME
)
1156 info
->icount
.frame
++;
1157 else if(data
& CyPARITY
)
1158 info
->icount
.parity
++;
1159 else if(data
& CyOVERRUN
)
1160 info
->icount
.overrun
++;
1162 if(data
& info
->ignore_status_mask
){
1166 if (tty_buffer_request_room(tty
, 1)) {
1167 if (data
& info
->read_status_mask
){
1169 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_BREAK
);
1171 if (info
->flags
& ASYNC_SAK
){
1174 }else if(data
& CyFRAME
){
1175 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_FRAME
);
1177 info
->idle_stats
.frame_errs
++;
1178 }else if(data
& CyPARITY
){
1179 /* Pieces of seven... */
1180 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_PARITY
);
1182 info
->idle_stats
.parity_errs
++;
1183 }else if(data
& CyOVERRUN
){
1184 tty_insert_flip_char(tty
, 0, TTY_OVERRUN
);
1186 /* If the flip buffer itself is
1187 overflowing, we still lose
1188 the next incoming character.
1190 tty_insert_flip_char(tty
, cy_readb(base_addr
+(CyRDSR
<<index
)), TTY_FRAME
);
1192 info
->idle_stats
.overruns
++;
1193 /* These two conditions may imply */
1194 /* a normal read should be done. */
1195 /* }else if(data & CyTIMEOUT){ */
1196 /* }else if(data & CySPECHAR){ */
1198 tty_insert_flip_char(tty
, 0, TTY_NORMAL
);
1202 tty_insert_flip_char(tty
, 0, TTY_NORMAL
);
1206 /* there was a software buffer
1207 overrun and nothing could be
1209 info
->icount
.buf_overrun
++;
1210 info
->idle_stats
.overruns
++;
1212 } else { /* normal character reception */
1213 /* load # chars available from the chip */
1214 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1216 #ifdef CY_ENABLE_MONITORING
1217 ++info
->mon
.int_count
;
1218 info
->mon
.char_count
+= char_count
;
1219 if (char_count
> info
->mon
.char_max
)
1220 info
->mon
.char_max
= char_count
;
1221 info
->mon
.char_last
= char_count
;
1223 len
= tty_buffer_request_room(tty
, char_count
);
1225 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1226 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
1227 info
->idle_stats
.recv_bytes
++;
1233 info
->idle_stats
.recv_idle
= jiffies
;
1235 tty_schedule_flip(tty
);
1237 /* end of service */
1238 cy_writeb(base_addr
+(CyRIR
<<index
), (save_xir
& 0x3f));
1239 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1240 spin_unlock(&cinfo
->card_lock
);
1244 if (status
& CySRTransmit
) { /* transmission interrupt */
1245 /* Since we only get here when the transmit buffer
1246 is empty, we know we can always stuff a dozen
1248 #ifdef CY_DEBUG_INTERRUPTS
1249 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip
);
1252 /* determine the channel & change to that context */
1253 spin_lock(&cinfo
->card_lock
);
1254 save_xir
= (u_char
) cy_readb(base_addr
+(CyTIR
<<index
));
1255 channel
= (u_short
) (save_xir
& CyIRChannel
);
1256 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1257 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1258 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1260 /* validate the port# (as configured and open) */
1261 if( (i
< 0) || (NR_PORTS
<= i
) ){
1262 cy_writeb(base_addr
+(CySRER
<<index
),
1263 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1267 info
->last_active
= jiffies
;
1269 cy_writeb(base_addr
+(CySRER
<<index
),
1270 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1274 /* load the on-chip space for outbound data */
1275 char_count
= info
->xmit_fifo_size
;
1277 if(info
->x_char
) { /* send special char */
1278 outch
= info
->x_char
;
1279 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1285 if (info
->breakon
|| info
->breakoff
) {
1286 if (info
->breakon
) {
1287 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1288 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x81);
1292 if (info
->breakoff
) {
1293 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1294 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x83);
1300 while (char_count
-- > 0){
1301 if (!info
->xmit_cnt
){
1302 if (cy_readb(base_addr
+(CySRER
<<index
))&CyTxMpty
) {
1303 cy_writeb(base_addr
+(CySRER
<<index
),
1304 cy_readb(base_addr
+(CySRER
<<index
)) &
1307 cy_writeb(base_addr
+(CySRER
<<index
),
1308 ((cy_readb(base_addr
+(CySRER
<<index
))
1314 if (info
->xmit_buf
== 0){
1315 cy_writeb(base_addr
+(CySRER
<<index
),
1316 cy_readb(base_addr
+(CySRER
<<index
)) &
1320 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
1321 cy_writeb(base_addr
+(CySRER
<<index
),
1322 cy_readb(base_addr
+(CySRER
<<index
)) &
1326 /* Because the Embedded Transmit Commands have
1327 been enabled, we must check to see if the
1328 escape character, NULL, is being sent. If it
1329 is, we must ensure that there is room for it
1330 to be doubled in the output stream. Therefore
1331 we no longer advance the pointer when the
1332 character is fetched, but rather wait until
1333 after the check for a NULL output character.
1334 This is necessary because there may not be
1335 room for the two chars needed to send a NULL.)
1337 outch
= info
->xmit_buf
[info
->xmit_tail
];
1340 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1341 & (SERIAL_XMIT_SIZE
- 1);
1342 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1347 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1348 & (SERIAL_XMIT_SIZE
- 1);
1349 cy_writeb(base_addr
+(CyTDR
<<index
),
1351 cy_writeb(base_addr
+(CyTDR
<<index
), 0);
1360 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1361 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1364 /* end of service */
1365 cy_writeb(base_addr
+(CyTIR
<<index
),
1367 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1368 spin_unlock(&cinfo
->card_lock
);
1371 if (status
& CySRModem
) { /* modem interrupt */
1373 /* determine the channel & change to that context */
1374 spin_lock(&cinfo
->card_lock
);
1375 save_xir
= (u_char
) cy_readb(base_addr
+(CyMIR
<<index
));
1376 channel
= (u_short
) (save_xir
& CyIRChannel
);
1377 info
= &cy_port
[channel
+ chip
* 4
1378 + cinfo
->first_line
];
1379 info
->last_active
= jiffies
;
1380 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1381 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1383 mdm_change
= cy_readb(base_addr
+(CyMISR
<<index
));
1384 mdm_status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
1386 if(info
->tty
== 0){/* no place for data, ignore it*/
1389 if (mdm_change
& CyANY_DELTA
) {
1390 /* For statistics only */
1391 if (mdm_change
& CyDCD
) info
->icount
.dcd
++;
1392 if (mdm_change
& CyCTS
) info
->icount
.cts
++;
1393 if (mdm_change
& CyDSR
) info
->icount
.dsr
++;
1394 if (mdm_change
& CyRI
) info
->icount
.rng
++;
1396 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1399 if((mdm_change
& CyDCD
)
1400 && (info
->flags
& ASYNC_CHECK_CD
)){
1401 if(mdm_status
& CyDCD
){
1402 cy_sched_event(info
,
1403 Cy_EVENT_OPEN_WAKEUP
);
1405 cy_sched_event(info
,
1409 if((mdm_change
& CyCTS
)
1410 && (info
->flags
& ASYNC_CTS_FLOW
)){
1411 if(info
->tty
->hw_stopped
){
1412 if(mdm_status
& CyCTS
){
1413 /* cy_start isn't used
1415 info
->tty
->hw_stopped
= 0;
1416 cy_writeb(base_addr
+(CySRER
<<index
),
1417 cy_readb(base_addr
+(CySRER
<<index
)) |
1419 cy_sched_event(info
,
1420 Cy_EVENT_WRITE_WAKEUP
);
1423 if(!(mdm_status
& CyCTS
)){
1424 /* cy_stop isn't used
1426 info
->tty
->hw_stopped
= 1;
1427 cy_writeb(base_addr
+(CySRER
<<index
),
1428 cy_readb(base_addr
+(CySRER
<<index
)) &
1433 if(mdm_change
& CyDSR
){
1435 if(mdm_change
& CyRI
){
1438 /* end of service */
1439 cy_writeb(base_addr
+(CyMIR
<<index
),
1441 cy_writeb(base_addr
+(CyCAR
<<index
), save_car
);
1442 spin_unlock(&cinfo
->card_lock
);
1444 } /* end while status != 0 */
1445 } /* end loop for chips... */
1448 /* clear interrupts */
1449 spin_lock(&cinfo
->card_lock
);
1450 cy_writeb(card_base_addr
+ (Cy_ClrIntr
<<index
), 0);
1451 /* Cy_ClrIntr is 0x1800 */
1452 spin_unlock(&cinfo
->card_lock
);
1454 } /* cyy_interrupt */
1456 /***********************************************************/
1457 /********* End of block of Cyclom-Y specific code **********/
1458 /******** Start of block of Cyclades-Z specific code *********/
1459 /***********************************************************/
1462 cyz_fetch_msg( struct cyclades_card
*cinfo
,
1463 uclong
*channel
, ucchar
*cmd
, uclong
*param
)
1465 struct FIRM_ID __iomem
*firm_id
;
1466 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1467 struct BOARD_CTRL __iomem
*board_ctrl
;
1468 unsigned long loc_doorbell
;
1470 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1471 if (!ISZLOADED(*cinfo
)){
1474 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1475 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1477 loc_doorbell
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
1478 (cinfo
->ctl_addr
))->loc_doorbell
);
1480 *cmd
= (char)(0xff & loc_doorbell
);
1481 *channel
= cy_readl(&board_ctrl
->fwcmd_channel
);
1482 *param
= (uclong
)cy_readl(&board_ctrl
->fwcmd_param
);
1483 cy_writel(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->loc_doorbell
,
1488 } /* cyz_fetch_msg */
1491 cyz_issue_cmd( struct cyclades_card
*cinfo
,
1492 uclong channel
, ucchar cmd
, uclong param
)
1494 struct FIRM_ID __iomem
*firm_id
;
1495 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1496 struct BOARD_CTRL __iomem
*board_ctrl
;
1497 unsigned long __iomem
*pci_doorbell
;
1500 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1501 if (!ISZLOADED(*cinfo
)){
1504 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1505 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1508 pci_doorbell
= &((struct RUNTIME_9060 __iomem
*) (cinfo
->ctl_addr
))->pci_doorbell
;
1509 while( (cy_readl(pci_doorbell
) & 0xff) != 0){
1510 if (index
++ == 1000){
1511 return((int)(cy_readl(pci_doorbell
) & 0xff));
1515 cy_writel(&board_ctrl
->hcmd_channel
, channel
);
1516 cy_writel(&board_ctrl
->hcmd_param
, param
);
1517 cy_writel(pci_doorbell
, (long)cmd
);
1520 } /* cyz_issue_cmd */
1523 cyz_handle_rx(struct cyclades_port
*info
,
1524 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1525 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1527 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1528 struct tty_struct
*tty
= info
->tty
;
1529 volatile int char_count
;
1536 volatile uclong rx_put
, rx_get
, new_rx_get
, rx_bufsize
, rx_bufaddr
;
1538 rx_get
= new_rx_get
= cy_readl(&buf_ctrl
->rx_get
);
1539 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1540 rx_bufsize
= cy_readl(&buf_ctrl
->rx_bufsize
);
1541 rx_bufaddr
= cy_readl(&buf_ctrl
->rx_bufaddr
);
1542 if (rx_put
>= rx_get
)
1543 char_count
= rx_put
- rx_get
;
1545 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1548 info
->last_active
= jiffies
;
1549 info
->jiffies
[1] = jiffies
;
1551 #ifdef CY_ENABLE_MONITORING
1552 info
->mon
.int_count
++;
1553 info
->mon
.char_count
+= char_count
;
1554 if (char_count
> info
->mon
.char_max
)
1555 info
->mon
.char_max
= char_count
;
1556 info
->mon
.char_last
= char_count
;
1559 /* flush received characters */
1560 new_rx_get
= (new_rx_get
+ char_count
) & (rx_bufsize
- 1);
1561 info
->rflush_count
++;
1564 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1565 for performance, but because of buffer boundaries, there
1566 may be several steps to the operation */
1567 while(0 < (small_count
=
1568 min_t(unsigned int, (rx_bufsize
- new_rx_get
),
1569 min_t(unsigned int, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
), char_count
))
1571 memcpy_fromio(tty
->flip
.char_buf_ptr
,
1572 (char *)(cinfo
->base_addr
1573 + rx_bufaddr
+ new_rx_get
),
1576 tty
->flip
.char_buf_ptr
+= small_count
;
1577 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, small_count
);
1578 tty
->flip
.flag_buf_ptr
+= small_count
;
1579 new_rx_get
= (new_rx_get
+ small_count
) & (rx_bufsize
- 1);
1580 char_count
-= small_count
;
1581 info
->icount
.rx
+= small_count
;
1582 info
->idle_stats
.recv_bytes
+= small_count
;
1583 tty
->flip
.count
+= small_count
;
1586 len
= tty_buffer_request_room(tty
, char_count
);
1588 data
= cy_readb(cinfo
->base_addr
+ rx_bufaddr
+ new_rx_get
);
1589 new_rx_get
= (new_rx_get
+ 1) & (rx_bufsize
- 1);
1590 tty_insert_flip_char(tty
, data
, TTY_NORMAL
);
1591 info
->idle_stats
.recv_bytes
++;
1595 #ifdef CONFIG_CYZ_INTR
1596 /* Recalculate the number of chars in the RX buffer and issue
1597 a cmd in case it's higher than the RX high water mark */
1598 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1599 if (rx_put
>= rx_get
)
1600 char_count
= rx_put
- rx_get
;
1602 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1603 if(char_count
>= cy_readl(&buf_ctrl
->rx_threshold
)) {
1604 cy_sched_event(info
, Cy_EVENT_Z_RX_FULL
);
1607 info
->idle_stats
.recv_idle
= jiffies
;
1608 tty_schedule_flip(tty
);
1611 cy_writel(&buf_ctrl
->rx_get
, new_rx_get
);
1616 cyz_handle_tx(struct cyclades_port
*info
,
1617 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1618 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1620 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1621 struct tty_struct
*tty
= info
->tty
;
1623 volatile int char_count
;
1627 volatile uclong tx_put
, tx_get
, tx_bufsize
, tx_bufaddr
;
1629 if (info
->xmit_cnt
<= 0) /* Nothing to transmit */
1632 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
1633 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
1634 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
1635 tx_bufaddr
= cy_readl(&buf_ctrl
->tx_bufaddr
);
1636 if (tx_put
>= tx_get
)
1637 char_count
= tx_get
- tx_put
- 1 + tx_bufsize
;
1639 char_count
= tx_get
- tx_put
- 1;
1647 if(info
->x_char
) { /* send special char */
1648 data
= info
->x_char
;
1650 cy_writeb((cinfo
->base_addr
+ tx_bufaddr
+ tx_put
), data
);
1651 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1655 info
->last_active
= jiffies
;
1656 info
->jiffies
[2] = jiffies
;
1659 while(0 < (small_count
=
1660 min_t(unsigned int, (tx_bufsize
- tx_put
),
1661 min_t(unsigned int, (SERIAL_XMIT_SIZE
- info
->xmit_tail
),
1662 min_t(unsigned int, info
->xmit_cnt
, char_count
))))) {
1664 memcpy_toio((char *)(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
),
1665 &info
->xmit_buf
[info
->xmit_tail
],
1668 tx_put
= (tx_put
+ small_count
) & (tx_bufsize
- 1);
1669 char_count
-= small_count
;
1670 info
->icount
.tx
+= small_count
;
1671 info
->xmit_cnt
-= small_count
;
1673 (info
->xmit_tail
+ small_count
) & (SERIAL_XMIT_SIZE
- 1);
1674 info
->last_active
= jiffies
;
1675 info
->jiffies
[2] = jiffies
;
1678 while (info
->xmit_cnt
&& char_count
){
1679 data
= info
->xmit_buf
[info
->xmit_tail
];
1681 info
->xmit_tail
= (info
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
1683 cy_writeb(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
, data
);
1684 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1687 info
->last_active
= jiffies
;
1688 info
->jiffies
[2] = jiffies
;
1692 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1693 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1696 cy_writel(&buf_ctrl
->tx_put
, tx_put
);
1701 cyz_handle_cmd(struct cyclades_card
*cinfo
)
1703 struct tty_struct
*tty
;
1704 struct cyclades_port
*info
;
1705 static volatile struct FIRM_ID __iomem
*firm_id
;
1706 static volatile struct ZFW_CTRL __iomem
*zfw_ctrl
;
1707 static volatile struct BOARD_CTRL __iomem
*board_ctrl
;
1708 static volatile struct CH_CTRL __iomem
*ch_ctrl
;
1709 static volatile struct BUF_CTRL __iomem
*buf_ctrl
;
1713 uclong hw_ver
, fw_ver
;
1717 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1718 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1719 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1720 fw_ver
= cy_readl(&board_ctrl
->fw_version
);
1721 hw_ver
= cy_readl(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->mail_box_0
);
1724 while(cyz_fetch_msg(cinfo
, &channel
, &cmd
, ¶m
) == 1) {
1727 info
= &cy_port
[channel
+ cinfo
->first_line
];
1728 if((tty
= info
->tty
) == 0) {
1731 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
1732 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
1736 tty_insert_flip_char(tty
, 0, TTY_PARITY
);
1741 tty_insert_flip_char(tty
, 0, TTY_FRAME
);
1746 tty_insert_flip_char(tty
, 0, TTY_BREAK
);
1753 if (info
->flags
& ASYNC_CHECK_CD
){
1756 cy_readl(&ch_ctrl
->rs_status
)) & C_RS_DCD
) {
1757 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
1759 cy_sched_event(info
, Cy_EVENT_HANGUP
);
1777 cy_sched_event(info
, Cy_EVENT_SHUTDOWN_WAKEUP
);
1780 #ifdef CONFIG_CYZ_INTR
1784 /* Reception Interrupt */
1785 #ifdef CY_DEBUG_INTERRUPTS
1786 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
1787 info
->card
, channel
);
1789 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1794 /* Transmission Interrupt */
1795 #ifdef CY_DEBUG_INTERRUPTS
1796 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
1797 info
->card
, channel
);
1799 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1801 #endif /* CONFIG_CYZ_INTR */
1803 /* should do something with this !!! */
1809 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1811 tty_schedule_flip(tty
);
1815 #ifdef CONFIG_CYZ_INTR
1817 cyz_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1819 struct cyclades_card
*cinfo
;
1821 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1822 #ifdef CY_DEBUG_INTERRUPTS
1823 printk("cyz_interrupt: spurious interrupt %d\n\r", irq
);
1825 return IRQ_NONE
; /* spurious interrupt */
1828 if (!ISZLOADED(*cinfo
)) {
1829 #ifdef CY_DEBUG_INTERRUPTS
1830 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq
);
1835 /* Handle the interrupts */
1836 cyz_handle_cmd(cinfo
);
1839 } /* cyz_interrupt */
1842 cyz_rx_restart(unsigned long arg
)
1844 struct cyclades_port
*info
= (struct cyclades_port
*)arg
;
1846 int card
= info
->card
;
1847 uclong channel
= (info
->line
) - (cy_card
[card
].first_line
);
1848 unsigned long flags
;
1850 CY_LOCK(info
, flags
);
1851 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK2
, 0L);
1853 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1854 info
->line
, retval
);
1856 cyz_rx_full_timer
[info
->line
].function
= NULL
;
1857 CY_UNLOCK(info
, flags
);
1860 #else /* CONFIG_CYZ_INTR */
1863 cyz_poll(unsigned long arg
)
1865 struct cyclades_card
*cinfo
;
1866 struct cyclades_port
*info
;
1867 struct tty_struct
*tty
;
1868 static volatile struct FIRM_ID
*firm_id
;
1869 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1870 static volatile struct BOARD_CTRL
*board_ctrl
;
1871 static volatile struct CH_CTRL
*ch_ctrl
;
1872 static volatile struct BUF_CTRL
*buf_ctrl
;
1875 cyz_timerlist
.expires
= jiffies
+ (HZ
);
1876 for (card
= 0 ; card
< NR_CARDS
; card
++){
1877 cinfo
= &cy_card
[card
];
1879 if (!IS_CYC_Z(*cinfo
)) continue;
1880 if (!ISZLOADED(*cinfo
)) continue;
1882 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1883 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1884 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1886 /* Skip first polling cycle to avoid racing conditions with the FW */
1887 if (!cinfo
->intr_enabled
) {
1888 cinfo
->nports
= (int) cy_readl(&board_ctrl
->n_channel
);
1889 cinfo
->intr_enabled
= 1;
1893 cyz_handle_cmd(cinfo
);
1895 for (port
= 0 ; port
< cinfo
->nports
; port
++) {
1896 info
= &cy_port
[ port
+ cinfo
->first_line
];
1898 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[port
]);
1899 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[port
]);
1901 if (!info
->throttle
)
1902 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1903 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1905 /* poll every 'cyz_polling_cycle' period */
1906 cyz_timerlist
.expires
= jiffies
+ cyz_polling_cycle
;
1908 add_timer(&cyz_timerlist
);
1913 #endif /* CONFIG_CYZ_INTR */
1915 /********** End of block of Cyclades-Z specific code *********/
1916 /***********************************************************/
1919 /* This is called whenever a port becomes active;
1920 interrupts are enabled and DTR & RTS are turned on.
1923 startup(struct cyclades_port
* info
)
1925 unsigned long flags
;
1927 void __iomem
*base_addr
;
1928 int card
,chip
,channel
,index
;
1932 channel
= (info
->line
) - (cy_card
[card
].first_line
);
1934 page
= get_zeroed_page(GFP_KERNEL
);
1938 CY_LOCK(info
, flags
);
1940 if (info
->flags
& ASYNC_INITIALIZED
){
1947 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1956 info
->xmit_buf
= (unsigned char *) page
;
1958 CY_UNLOCK(info
, flags
);
1960 set_line_char(info
);
1962 if (!IS_CYC_Z(cy_card
[card
])) {
1965 index
= cy_card
[card
].bus_index
;
1966 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
1968 #ifdef CY_DEBUG_OPEN
1969 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
1970 card
, chip
, channel
, (long)base_addr
);/**/
1973 CY_LOCK(info
, flags
);
1975 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
1977 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
1978 ? info
->default_timeout
: 0x02)); /* 10ms rx timeout */
1980 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyENB_RCVR
|CyENB_XMTR
,index
);
1982 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
1983 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
1984 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
1987 printk("cyc:startup raising DTR\n");
1988 printk(" status: 0x%x, 0x%x\n",
1989 cy_readb(base_addr
+(CyMSVR1
<<index
)),
1990 cy_readb(base_addr
+(CyMSVR2
<<index
)));
1993 cy_writeb(base_addr
+(CySRER
<<index
),
1994 cy_readb(base_addr
+(CySRER
<<index
)) | CyRxData
);
1995 info
->flags
|= ASYNC_INITIALIZED
;
1998 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2000 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2001 info
->breakon
= info
->breakoff
= 0;
2002 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2003 info
->idle_stats
.in_use
=
2004 info
->idle_stats
.recv_idle
=
2005 info
->idle_stats
.xmit_idle
= jiffies
;
2007 CY_UNLOCK(info
, flags
);
2010 struct FIRM_ID __iomem
*firm_id
;
2011 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2012 struct BOARD_CTRL __iomem
*board_ctrl
;
2013 struct CH_CTRL __iomem
*ch_ctrl
;
2016 base_addr
= cy_card
[card
].base_addr
;
2018 firm_id
= base_addr
+ ID_ADDRESS
;
2019 if (!ISZLOADED(cy_card
[card
])){
2023 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2024 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2025 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2027 #ifdef CY_DEBUG_OPEN
2028 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2029 card
, channel
, (long)base_addr
);/**/
2032 CY_LOCK(info
, flags
);
2034 cy_writel(&ch_ctrl
[channel
].op_mode
, C_CH_ENABLE
);
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
|
2042 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2045 #endif /* CONFIG_CYZ_INTR */
2047 #ifdef CONFIG_CYZ_INTR
2048 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2049 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2052 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2054 #endif /* CONFIG_CYZ_INTR */
2057 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
2059 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2060 info
->line
, retval
);
2063 /* Flush RX buffers before raising DTR and RTS */
2064 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_RX
, 0L);
2066 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2067 info
->line
, retval
);
2070 /* set timeout !!! */
2071 /* set RTS and DTR !!! */
2072 cy_writel(&ch_ctrl
[channel
].rs_control
,
2073 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
| C_RS_DTR
) ;
2074 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2075 channel
, C_CM_IOCTLM
, 0L);
2077 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2078 info
->line
, retval
);
2081 printk("cyc:startup raising Z DTR\n");
2084 /* enable send, recv, modem !!! */
2086 info
->flags
|= ASYNC_INITIALIZED
;
2088 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2090 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2091 info
->breakon
= info
->breakoff
= 0;
2092 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2093 info
->idle_stats
.in_use
=
2094 info
->idle_stats
.recv_idle
=
2095 info
->idle_stats
.xmit_idle
= jiffies
;
2097 CY_UNLOCK(info
, flags
);
2100 #ifdef CY_DEBUG_OPEN
2101 printk(" cyc startup done\n");
2106 CY_UNLOCK(info
, flags
);
2112 start_xmit( struct cyclades_port
*info
)
2114 unsigned long flags
;
2115 void __iomem
*base_addr
;
2116 int card
,chip
,channel
,index
;
2119 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2120 if (!IS_CYC_Z(cy_card
[card
])) {
2123 index
= cy_card
[card
].bus_index
;
2124 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2126 CY_LOCK(info
, flags
);
2127 cy_writeb(base_addr
+(CyCAR
<<index
), channel
);
2128 cy_writeb(base_addr
+(CySRER
<<index
),
2129 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
2130 CY_UNLOCK(info
, flags
);
2132 #ifdef CONFIG_CYZ_INTR
2135 CY_LOCK(info
, flags
);
2136 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK
, 0L);
2138 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2139 info
->line
, retval
);
2141 CY_UNLOCK(info
, flags
);
2142 #else /* CONFIG_CYZ_INTR */
2143 /* Don't have to do anything at this time */
2144 #endif /* CONFIG_CYZ_INTR */
2149 * This routine shuts down a serial port; interrupts are disabled,
2150 * and DTR is dropped if the hangup on close termio flag is on.
2153 shutdown(struct cyclades_port
* info
)
2155 unsigned long flags
;
2156 void __iomem
*base_addr
;
2157 int card
,chip
,channel
,index
;
2159 if (!(info
->flags
& ASYNC_INITIALIZED
)){
2164 channel
= info
->line
- cy_card
[card
].first_line
;
2165 if (!IS_CYC_Z(cy_card
[card
])) {
2168 index
= cy_card
[card
].bus_index
;
2169 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2171 #ifdef CY_DEBUG_OPEN
2172 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2173 card
, chip
, channel
, (long)base_addr
);
2176 CY_LOCK(info
, flags
);
2178 /* Clear delta_msr_wait queue to avoid mem leaks. */
2179 wake_up_interruptible(&info
->delta_msr_wait
);
2181 if (info
->xmit_buf
){
2182 unsigned char * temp
;
2183 temp
= info
->xmit_buf
;
2184 info
->xmit_buf
= NULL
;
2185 free_page((unsigned long) temp
);
2187 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2188 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2189 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
2190 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
2192 printk("cyc shutdown dropping DTR\n");
2193 printk(" status: 0x%x, 0x%x\n",
2194 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2195 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2198 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyDIS_RCVR
,index
);
2199 /* it may be appropriate to clear _XMIT at
2200 some later date (after testing)!!! */
2203 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2205 info
->flags
&= ~ASYNC_INITIALIZED
;
2206 CY_UNLOCK(info
, flags
);
2208 struct FIRM_ID __iomem
*firm_id
;
2209 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2210 struct BOARD_CTRL __iomem
*board_ctrl
;
2211 struct CH_CTRL __iomem
*ch_ctrl
;
2214 base_addr
= cy_card
[card
].base_addr
;
2215 #ifdef CY_DEBUG_OPEN
2216 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2217 card
, channel
, (long)base_addr
);
2220 firm_id
= base_addr
+ ID_ADDRESS
;
2221 if (!ISZLOADED(cy_card
[card
])) {
2225 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2226 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2227 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2229 CY_LOCK(info
, flags
);
2231 if (info
->xmit_buf
){
2232 unsigned char * temp
;
2233 temp
= info
->xmit_buf
;
2234 info
->xmit_buf
= NULL
;
2235 free_page((unsigned long) temp
);
2238 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2239 cy_writel(&ch_ctrl
[channel
].rs_control
,
2240 (uclong
)(cy_readl(&ch_ctrl
[channel
].rs_control
) &
2241 ~(C_RS_RTS
| C_RS_DTR
)));
2242 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2243 channel
, C_CM_IOCTLM
, 0L);
2245 printk("cyc:shutdown retval on ttyC%d was %x\n",
2246 info
->line
, retval
);
2249 printk("cyc:shutdown dropping Z DTR\n");
2254 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2256 info
->flags
&= ~ASYNC_INITIALIZED
;
2258 CY_UNLOCK(info
, flags
);
2261 #ifdef CY_DEBUG_OPEN
2262 printk(" cyc shutdown done\n");
2269 * ------------------------------------------------------------
2270 * cy_open() and friends
2271 * ------------------------------------------------------------
2275 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2276 struct cyclades_port
*info
)
2278 DECLARE_WAITQUEUE(wait
, current
);
2279 struct cyclades_card
*cinfo
;
2280 unsigned long flags
;
2281 int chip
, channel
,index
;
2283 void __iomem
*base_addr
;
2285 cinfo
= &cy_card
[info
->card
];
2286 channel
= info
->line
- cinfo
->first_line
;
2289 * If the device is in the middle of being closed, then block
2290 * until it's done, and then try again.
2292 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2293 if (info
->flags
& ASYNC_CLOSING
) {
2294 interruptible_sleep_on(&info
->close_wait
);
2296 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2300 * If non-blocking mode is set, then make the check up front
2303 if ((filp
->f_flags
& O_NONBLOCK
) ||
2304 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2305 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2310 * Block waiting for the carrier detect and the line to become
2311 * free (i.e., not in use by the callout). While we are in
2312 * this loop, info->count is dropped by one, so that
2313 * cy_close() knows when to free things. We restore it upon
2314 * exit, either normal or abnormal.
2317 add_wait_queue(&info
->open_wait
, &wait
);
2318 #ifdef CY_DEBUG_OPEN
2319 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2320 info
->line
, info
->count
);/**/
2322 CY_LOCK(info
, flags
);
2323 if (!tty_hung_up_p(filp
))
2325 CY_UNLOCK(info
, flags
);
2326 #ifdef CY_DEBUG_COUNT
2327 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2328 current
->pid
, info
->count
);
2330 info
->blocked_open
++;
2332 if (!IS_CYC_Z(*cinfo
)) {
2335 index
= cinfo
->bus_index
;
2336 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
2339 CY_LOCK(info
, flags
);
2340 if ((tty
->termios
->c_cflag
& CBAUD
)){
2341 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2342 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
2343 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
2345 printk("cyc:block_til_ready raising DTR\n");
2346 printk(" status: 0x%x, 0x%x\n",
2347 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2348 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2351 CY_UNLOCK(info
, flags
);
2353 set_current_state(TASK_INTERRUPTIBLE
);
2354 if (tty_hung_up_p(filp
)
2355 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2356 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2357 -EAGAIN
: -ERESTARTSYS
);
2361 CY_LOCK(info
, flags
);
2362 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2363 if (!(info
->flags
& ASYNC_CLOSING
)
2365 || (cy_readb(base_addr
+(CyMSVR1
<<index
)) & CyDCD
))) {
2366 CY_UNLOCK(info
, flags
);
2369 CY_UNLOCK(info
, flags
);
2371 if (signal_pending(current
)) {
2372 retval
= -ERESTARTSYS
;
2375 #ifdef CY_DEBUG_OPEN
2376 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2377 info
->line
, info
->count
);/**/
2382 struct FIRM_ID __iomem
*firm_id
;
2383 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2384 struct BOARD_CTRL __iomem
*board_ctrl
;
2385 struct CH_CTRL __iomem
*ch_ctrl
;
2388 base_addr
= cinfo
->base_addr
;
2389 firm_id
= base_addr
+ ID_ADDRESS
;
2390 if (!ISZLOADED(*cinfo
)){
2391 current
->state
= TASK_RUNNING
;
2392 remove_wait_queue(&info
->open_wait
, &wait
);
2396 zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2397 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2398 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2401 if ((tty
->termios
->c_cflag
& CBAUD
)){
2402 cy_writel(&ch_ctrl
[channel
].rs_control
,
2403 cy_readl(&ch_ctrl
[channel
].rs_control
) |
2404 (C_RS_RTS
| C_RS_DTR
));
2405 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2406 channel
, C_CM_IOCTLM
, 0L);
2408 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2409 info
->line
, retval
);
2412 printk("cyc:block_til_ready raising Z DTR\n");
2416 set_current_state(TASK_INTERRUPTIBLE
);
2417 if (tty_hung_up_p(filp
)
2418 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2419 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2420 -EAGAIN
: -ERESTARTSYS
);
2423 if (!(info
->flags
& ASYNC_CLOSING
)
2425 || (cy_readl(&ch_ctrl
[channel
].rs_status
) & C_RS_DCD
))) {
2428 if (signal_pending(current
)) {
2429 retval
= -ERESTARTSYS
;
2432 #ifdef CY_DEBUG_OPEN
2433 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2434 info
->line
, info
->count
);/**/
2439 current
->state
= TASK_RUNNING
;
2440 remove_wait_queue(&info
->open_wait
, &wait
);
2441 if (!tty_hung_up_p(filp
)){
2443 #ifdef CY_DEBUG_COUNT
2444 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2445 current
->pid
, info
->count
);
2448 info
->blocked_open
--;
2449 #ifdef CY_DEBUG_OPEN
2450 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2451 info
->line
, info
->count
);/**/
2455 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2457 } /* block_til_ready */
2461 * This routine is called whenever a serial port is opened. It
2462 * performs the serial-specific initialization for the tty structure.
2465 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2467 struct cyclades_port
*info
;
2472 if ((line
< 0) || (NR_PORTS
<= line
)){
2475 info
= &cy_port
[line
];
2476 if (info
->line
< 0){
2480 /* If the card's firmware hasn't been loaded,
2481 treat it as absent from the system. This
2482 will make the user pay attention.
2484 if (IS_CYC_Z(cy_card
[info
->card
])) {
2485 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
2486 struct FIRM_ID __iomem
*firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
2488 if (!ISZLOADED(*cinfo
)) {
2489 if (((ZE_V1
==cy_readl(&((struct RUNTIME_9060 __iomem
*)
2490 (cinfo
->ctl_addr
))->mail_box_0
)) &&
2491 Z_FPGA_CHECK (*cinfo
)) &&
2492 (ZFIRM_HLT
== cy_readl (&firm_id
->signature
)))
2494 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2496 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2500 #ifdef CONFIG_CYZ_INTR
2502 /* In case this Z board is operating in interrupt mode, its
2503 interrupts should be enabled as soon as the first open happens
2504 to one of its ports. */
2505 if (!cinfo
->intr_enabled
) {
2506 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2507 struct BOARD_CTRL __iomem
*board_ctrl
;
2509 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl (&firm_id
->zfwctrl_addr
) & 0xfffff);
2511 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2513 /* Enable interrupts on the PLX chip */
2514 cy_writew(cinfo
->ctl_addr
+0x68,
2515 cy_readw(cinfo
->ctl_addr
+0x68)|0x0900);
2516 /* Enable interrupts on the FW */
2517 retval
= cyz_issue_cmd(cinfo
,
2518 0, C_CM_IRQ_ENBL
, 0L);
2520 printk("cyc:IRQ enable retval was %x\n", retval
);
2522 cinfo
->nports
= (int) cy_readl (&board_ctrl
->n_channel
);
2523 cinfo
->intr_enabled
= 1;
2526 #endif /* CONFIG_CYZ_INTR */
2527 /* Make sure this Z port really exists in hardware */
2528 if (info
->line
> (cinfo
->first_line
+ cinfo
->nports
- 1))
2531 #ifdef CY_DEBUG_OTHER
2532 printk("cyc:cy_open ttyC%d\n", info
->line
); /* */
2534 tty
->driver_data
= info
;
2536 if (serial_paranoia_check(info
, tty
->name
, "cy_open")){
2539 #ifdef CY_DEBUG_OPEN
2540 printk("cyc:cy_open ttyC%d, count = %d\n",
2541 info
->line
, info
->count
);/**/
2544 #ifdef CY_DEBUG_COUNT
2545 printk("cyc:cy_open (%d): incrementing count to %d\n",
2546 current
->pid
, info
->count
);
2549 page
= get_zeroed_page(GFP_KERNEL
);
2555 tmp_buf
= (unsigned char *) page
;
2559 * If the port is the middle of closing, bail out now
2561 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2562 if (info
->flags
& ASYNC_CLOSING
)
2563 interruptible_sleep_on(&info
->close_wait
);
2564 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2568 * Start up serial port
2570 retval
= startup(info
);
2575 retval
= block_til_ready(tty
, filp
, info
);
2577 #ifdef CY_DEBUG_OPEN
2578 printk("cyc:cy_open returning after block_til_ready with %d\n",
2586 #ifdef CY_DEBUG_OPEN
2587 printk(" cyc:cy_open done\n");/**/
2595 * cy_wait_until_sent() --- wait until the transmitter is empty
2598 cy_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2600 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
2601 void __iomem
*base_addr
;
2602 int card
,chip
,channel
,index
;
2603 unsigned long orig_jiffies
;
2606 if (serial_paranoia_check(info
, tty
->name
, "cy_wait_until_sent"))
2609 if (info
->xmit_fifo_size
== 0)
2610 return; /* Just in case.... */
2613 orig_jiffies
= jiffies
;
2615 * Set the check interval to be 1/5 of the estimated time to
2616 * send a single character, and make it at least 1. The check
2617 * interval should also be less than the timeout.
2619 * Note: we have to use pretty tight timings here to satisfy
2622 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2623 char_time
= char_time
/ 5;
2629 char_time
= min(char_time
, timeout
);
2631 * If the transmitter hasn't cleared in twice the approximate
2632 * amount of time to send the entire FIFO, it probably won't
2633 * ever clear. This assumes the UART isn't doing flow
2634 * control, which is currently the case. Hence, if it ever
2635 * takes longer than info->timeout, this is probably due to a
2636 * UART bug of some kind. So, we clamp the timeout parameter at
2639 if (!timeout
|| timeout
> 2*info
->timeout
)
2640 timeout
= 2*info
->timeout
;
2641 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2642 printk("In cy_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2643 printk("jiff=%lu...", jiffies
);
2646 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2647 if (!IS_CYC_Z(cy_card
[card
])) {
2650 index
= cy_card
[card
].bus_index
;
2651 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2652 while (cy_readb(base_addr
+(CySRER
<<index
)) & CyTxRdy
) {
2653 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2654 printk("Not clean (jiff=%lu)...", jiffies
);
2656 if (msleep_interruptible(jiffies_to_msecs(char_time
)))
2658 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2664 /* Run one more char cycle */
2665 msleep_interruptible(jiffies_to_msecs(char_time
* 5));
2666 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2667 printk("Clean (jiff=%lu)...done\n", jiffies
);
2672 * This routine is called when a particular tty device is closed.
2675 cy_close(struct tty_struct
*tty
, struct file
*filp
)
2677 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2678 unsigned long flags
;
2680 #ifdef CY_DEBUG_OTHER
2681 printk("cyc:cy_close ttyC%d\n", info
->line
);
2684 if (!info
|| serial_paranoia_check(info
, tty
->name
, "cy_close")){
2688 CY_LOCK(info
, flags
);
2689 /* If the TTY is being hung up, nothing to do */
2690 if (tty_hung_up_p(filp
)) {
2691 CY_UNLOCK(info
, flags
);
2695 #ifdef CY_DEBUG_OPEN
2696 printk("cyc:cy_close ttyC%d, count = %d\n", info
->line
, info
->count
);
2698 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2700 * Uh, oh. tty->count is 1, which means that the tty
2701 * structure will be freed. Info->count should always
2702 * be one in these conditions. If it's greater than
2703 * one, we've got real problems, since it means the
2704 * serial port won't be shutdown.
2706 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2707 "info->count is %d\n", info
->count
);
2710 #ifdef CY_DEBUG_COUNT
2711 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2712 current
->pid
, info
->count
- 1);
2714 if (--info
->count
< 0) {
2715 #ifdef CY_DEBUG_COUNT
2716 printk("cyc:cyc_close setting count to 0\n");
2721 CY_UNLOCK(info
, flags
);
2724 info
->flags
|= ASYNC_CLOSING
;
2727 * Now we wait for the transmit buffer to clear; and we notify
2728 * the line discipline to only process XON/XOFF characters.
2731 CY_UNLOCK(info
, flags
);
2732 if (info
->closing_wait
!= CY_CLOSING_WAIT_NONE
) {
2733 tty_wait_until_sent(tty
, info
->closing_wait
);
2735 CY_LOCK(info
, flags
);
2737 if (!IS_CYC_Z(cy_card
[info
->card
])) {
2738 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2739 int index
= cy_card
[info
->card
].bus_index
;
2740 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[channel
>>2] << index
);
2741 /* Stop accepting input */
2743 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2744 cy_writeb(base_addr
+(CySRER
<<index
),
2745 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyRxData
);
2746 if (info
->flags
& ASYNC_INITIALIZED
) {
2747 /* Waiting for on-board buffers to be empty before closing
2749 CY_UNLOCK(info
, flags
);
2750 cy_wait_until_sent(tty
, info
->timeout
);
2751 CY_LOCK(info
, flags
);
2755 /* Waiting for on-board buffers to be empty before closing the port */
2756 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
;
2757 struct FIRM_ID __iomem
*firm_id
= base_addr
+ ID_ADDRESS
;
2758 struct ZFW_CTRL __iomem
*zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2759 struct CH_CTRL __iomem
*ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2760 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2763 if (cy_readl(&ch_ctrl
[channel
].flow_status
) != C_FS_TXIDLE
) {
2764 retval
= cyz_issue_cmd(&cy_card
[info
->card
], channel
,
2767 printk("cyc:cy_close retval on ttyC%d was %x\n",
2768 info
->line
, retval
);
2770 CY_UNLOCK(info
, flags
);
2771 interruptible_sleep_on(&info
->shutdown_wait
);
2772 CY_LOCK(info
, flags
);
2777 CY_UNLOCK(info
, flags
);
2779 if (tty
->driver
->flush_buffer
)
2780 tty
->driver
->flush_buffer(tty
);
2781 tty_ldisc_flush(tty
);
2782 CY_LOCK(info
, flags
);
2787 if (info
->blocked_open
) {
2788 CY_UNLOCK(info
, flags
);
2789 if (info
->close_delay
) {
2790 msleep_interruptible(jiffies_to_msecs(info
->close_delay
));
2792 wake_up_interruptible(&info
->open_wait
);
2793 CY_LOCK(info
, flags
);
2795 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
2796 wake_up_interruptible(&info
->close_wait
);
2798 #ifdef CY_DEBUG_OTHER
2799 printk(" cyc:cy_close done\n");
2802 CY_UNLOCK(info
, flags
);
2807 /* This routine gets called when tty_write has put something into
2808 * the write_queue. The characters may come from user space or
2811 * This routine will return the number of characters actually
2812 * accepted for writing.
2814 * If the port is not already transmitting stuff, start it off by
2815 * enabling interrupts. The interrupt service routine will then
2816 * ensure that the characters are sent.
2817 * If the port is already active, there is no need to kick it.
2821 cy_write(struct tty_struct
* tty
, const unsigned char *buf
, int count
)
2823 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2824 unsigned long flags
;
2828 printk("cyc:cy_write ttyC%d\n", info
->line
); /* */
2831 if (serial_paranoia_check(info
, tty
->name
, "cy_write")){
2835 if (!info
->xmit_buf
|| !tmp_buf
)
2838 CY_LOCK(info
, flags
);
2840 c
= min(count
, min((int)(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1),
2841 (int)(SERIAL_XMIT_SIZE
- info
->xmit_head
)));
2846 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
2847 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
2848 info
->xmit_cnt
+= c
;
2853 CY_UNLOCK(info
, flags
);
2855 info
->idle_stats
.xmit_bytes
+= ret
;
2856 info
->idle_stats
.xmit_idle
= jiffies
;
2858 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
2866 * This routine is called by the kernel to write a single
2867 * character to the tty device. If the kernel uses this routine,
2868 * it must call the flush_chars() routine (if defined) when it is
2869 * done stuffing characters into the driver. If there is no room
2870 * in the queue, the character is ignored.
2873 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
2875 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2876 unsigned long flags
;
2879 printk("cyc:cy_put_char ttyC%d\n", info
->line
);
2882 if (serial_paranoia_check(info
, tty
->name
, "cy_put_char"))
2885 if (!info
->xmit_buf
)
2888 CY_LOCK(info
, flags
);
2889 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
2890 CY_UNLOCK(info
, flags
);
2894 info
->xmit_buf
[info
->xmit_head
++] = ch
;
2895 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
2897 info
->idle_stats
.xmit_bytes
++;
2898 info
->idle_stats
.xmit_idle
= jiffies
;
2899 CY_UNLOCK(info
, flags
);
2904 * This routine is called by the kernel after it has written a
2905 * series of characters to the tty device using put_char().
2908 cy_flush_chars(struct tty_struct
*tty
)
2910 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2913 printk("cyc:cy_flush_chars ttyC%d\n", info
->line
); /* */
2916 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_chars"))
2919 if (info
->xmit_cnt
<= 0 || tty
->stopped
2920 || tty
->hw_stopped
|| !info
->xmit_buf
)
2924 } /* cy_flush_chars */
2928 * This routine returns the numbers of characters the tty driver
2929 * will accept for queuing to be written. This number is subject
2930 * to change as output buffers get emptied, or if the output flow
2931 * control is activated.
2934 cy_write_room(struct tty_struct
*tty
)
2936 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2940 printk("cyc:cy_write_room ttyC%d\n", info
->line
); /* */
2943 if (serial_paranoia_check(info
, tty
->name
, "cy_write_room"))
2945 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
2949 } /* cy_write_room */
2953 cy_chars_in_buffer(struct tty_struct
*tty
)
2955 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2958 if (serial_paranoia_check(info
, tty
->name
, "cy_chars_in_buffer"))
2962 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2964 #ifdef Z_EXT_CHARS_IN_BUFFER
2965 if (!IS_CYC_Z(cy_card
[card
])) {
2966 #endif /* Z_EXT_CHARS_IN_BUFFER */
2968 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2969 info
->line
, info
->xmit_cnt
); /* */
2971 return info
->xmit_cnt
;
2972 #ifdef Z_EXT_CHARS_IN_BUFFER
2974 static volatile struct FIRM_ID
*firm_id
;
2975 static volatile struct ZFW_CTRL
*zfw_ctrl
;
2976 static volatile struct CH_CTRL
*ch_ctrl
;
2977 static volatile struct BUF_CTRL
*buf_ctrl
;
2979 volatile uclong tx_put
, tx_get
, tx_bufsize
;
2981 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
2982 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2983 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
2984 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
2986 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
2987 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
2988 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
2989 if (tx_put
>= tx_get
)
2990 char_count
= tx_put
- tx_get
;
2992 char_count
= tx_put
- tx_get
+ tx_bufsize
;
2994 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2995 info
->line
, info
->xmit_cnt
+ char_count
); /* */
2997 return (info
->xmit_cnt
+ char_count
);
2999 #endif /* Z_EXT_CHARS_IN_BUFFER */
3000 } /* cy_chars_in_buffer */
3004 * ------------------------------------------------------------
3005 * cy_ioctl() and friends
3006 * ------------------------------------------------------------
3010 cyy_baud_calc(struct cyclades_port
*info
, uclong baud
)
3012 int co
, co_val
, bpr
;
3013 uclong cy_clock
= ((info
->chip_rev
>= CD1400_REV_J
) ? 60000000 : 25000000);
3016 info
->tbpr
= info
->tco
= info
->rbpr
= info
->rco
= 0;
3020 /* determine which prescaler to use */
3021 for (co
= 4, co_val
= 2048; co
; co
--, co_val
>>= 2) {
3022 if (cy_clock
/ co_val
/ baud
> 63)
3026 bpr
= (cy_clock
/ co_val
* 2 / baud
+ 1) / 2;
3030 info
->tbpr
= info
->rbpr
= bpr
;
3031 info
->tco
= info
->rco
= co
;
3035 * This routine finds or computes the various line characteristics.
3036 * It used to be called config_setup
3039 set_line_char(struct cyclades_port
* info
)
3041 unsigned long flags
;
3042 void __iomem
*base_addr
;
3043 int card
,chip
,channel
,index
;
3044 unsigned cflag
, iflag
;
3045 unsigned short chip_number
;
3046 int baud
, baud_rate
= 0;
3050 if (!info
->tty
|| !info
->tty
->termios
){
3053 if (info
->line
== -1){
3056 cflag
= info
->tty
->termios
->c_cflag
;
3057 iflag
= info
->tty
->termios
->c_iflag
;
3060 * Set up the tty->alt_speed kludge
3063 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3064 info
->tty
->alt_speed
= 57600;
3065 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3066 info
->tty
->alt_speed
= 115200;
3067 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3068 info
->tty
->alt_speed
= 230400;
3069 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3070 info
->tty
->alt_speed
= 460800;
3074 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3075 chip_number
= channel
/ 4;
3077 if (!IS_CYC_Z(cy_card
[card
])) {
3079 index
= cy_card
[card
].bus_index
;
3082 baud
= tty_get_baud_rate(info
->tty
);
3083 if ((baud
== 38400) &&
3084 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3085 if (info
->custom_divisor
)
3086 baud_rate
= info
->baud
/ info
->custom_divisor
;
3088 baud_rate
= info
->baud
;
3089 } else if (baud
> CD1400_MAX_SPEED
) {
3090 baud
= CD1400_MAX_SPEED
;
3092 /* find the baud index */
3093 for (i
= 0; i
< 20; i
++) {
3094 if (baud
== baud_table
[i
]) {
3099 i
= 19; /* CD1400_MAX_SPEED */
3102 if ((baud
== 38400) &&
3103 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3104 cyy_baud_calc(info
, baud_rate
);
3106 if(info
->chip_rev
>= CD1400_REV_J
) {
3107 /* It is a CD1400 rev. J or later */
3108 info
->tbpr
= baud_bpr_60
[i
]; /* Tx BPR */
3109 info
->tco
= baud_co_60
[i
]; /* Tx CO */
3110 info
->rbpr
= baud_bpr_60
[i
]; /* Rx BPR */
3111 info
->rco
= baud_co_60
[i
]; /* Rx CO */
3113 info
->tbpr
= baud_bpr_25
[i
]; /* Tx BPR */
3114 info
->tco
= baud_co_25
[i
]; /* Tx CO */
3115 info
->rbpr
= baud_bpr_25
[i
]; /* Rx BPR */
3116 info
->rco
= baud_co_25
[i
]; /* Rx CO */
3119 if (baud_table
[i
] == 134) {
3120 /* get it right for 134.5 baud */
3121 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3122 } else if ((baud
== 38400) &&
3123 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3124 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3125 } else if (baud_table
[i
]) {
3126 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
3127 /* this needs to be propagated into the card info */
3131 /* By tradition (is it a standard?) a baud rate of zero
3132 implies the line should be/has been closed. A bit
3133 later in this routine such a test is performed. */
3135 /* byte size and parity */
3138 info
->cor3
= (info
->default_threshold
3139 ? info
->default_threshold
3140 : baud_cor3
[i
]); /* receive threshold */
3142 switch(cflag
& CSIZE
){
3144 info
->cor1
= Cy_5_BITS
;
3147 info
->cor1
= Cy_6_BITS
;
3150 info
->cor1
= Cy_7_BITS
;
3153 info
->cor1
= Cy_8_BITS
;
3157 info
->cor1
|= Cy_2_STOP
;
3159 if (cflag
& PARENB
){
3160 if (cflag
& PARODD
){
3161 info
->cor1
|= CyPARITY_O
;
3163 info
->cor1
|= CyPARITY_E
;
3166 info
->cor1
|= CyPARITY_NONE
;
3169 /* CTS flow control flag */
3170 if (cflag
& CRTSCTS
){
3171 info
->flags
|= ASYNC_CTS_FLOW
;
3172 info
->cor2
|= CyCtsAE
;
3174 info
->flags
&= ~ASYNC_CTS_FLOW
;
3175 info
->cor2
&= ~CyCtsAE
;
3178 info
->flags
&= ~ASYNC_CHECK_CD
;
3180 info
->flags
|= ASYNC_CHECK_CD
;
3182 /***********************************************
3183 The hardware option, CyRtsAO, presents RTS when
3184 the chip has characters to send. Since most modems
3185 use RTS as reverse (inbound) flow control, this
3186 option is not used. If inbound flow control is
3187 necessary, DTR can be programmed to provide the
3188 appropriate signals for use with a non-standard
3189 cable. Contact Marcio Saito for details.
3190 ***********************************************/
3194 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3196 CY_LOCK(info
, flags
);
3197 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3199 /* tx and rx baud rate */
3201 cy_writeb(base_addr
+(CyTCOR
<<index
), info
->tco
);
3202 cy_writeb(base_addr
+(CyTBPR
<<index
), info
->tbpr
);
3203 cy_writeb(base_addr
+(CyRCOR
<<index
), info
->rco
);
3204 cy_writeb(base_addr
+(CyRBPR
<<index
), info
->rbpr
);
3206 /* set line characteristics according configuration */
3208 cy_writeb(base_addr
+(CySCHR1
<<index
),
3209 START_CHAR(info
->tty
));
3210 cy_writeb(base_addr
+(CySCHR2
<<index
),
3211 STOP_CHAR(info
->tty
));
3212 cy_writeb(base_addr
+(CyCOR1
<<index
), info
->cor1
);
3213 cy_writeb(base_addr
+(CyCOR2
<<index
), info
->cor2
);
3214 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3215 cy_writeb(base_addr
+(CyCOR4
<<index
), info
->cor4
);
3216 cy_writeb(base_addr
+(CyCOR5
<<index
), info
->cor5
);
3218 cyy_issue_cmd(base_addr
,
3219 CyCOR_CHANGE
|CyCOR1ch
|CyCOR2ch
|CyCOR3ch
,index
);
3221 cy_writeb(base_addr
+(CyCAR
<<index
),
3222 (u_char
)channel
); /* !!! Is this needed? */
3223 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
3224 ? info
->default_timeout
3225 : 0x02)); /* 10ms rx timeout */
3227 if (C_CLOCAL(info
->tty
)) {
3228 /* without modem intr */
3229 cy_writeb(base_addr
+(CySRER
<<index
),
3230 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3231 /* act on 1->0 modem transitions */
3232 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3233 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3234 (CyCTS
|rflow_thr
[i
]));
3236 cy_writeb(base_addr
+(CyMCOR1
<<index
), CyCTS
);
3238 /* act on 0->1 modem transitions */
3239 cy_writeb(base_addr
+(CyMCOR2
<<index
), CyCTS
);
3241 /* without modem intr */
3242 cy_writeb(base_addr
+(CySRER
<<index
),
3243 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3244 /* act on 1->0 modem transitions */
3245 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3246 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3247 (CyDSR
|CyCTS
|CyRI
|CyDCD
|rflow_thr
[i
]));
3249 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3250 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3252 /* act on 0->1 modem transitions */
3253 cy_writeb(base_addr
+(CyMCOR2
<<index
),
3254 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3257 if(i
== 0){ /* baud rate is zero, turn off line */
3258 if (info
->rtsdtr_inv
) {
3259 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3261 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3264 printk("cyc:set_line_char dropping DTR\n");
3265 printk(" status: 0x%x, 0x%x\n",
3266 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3267 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3270 if (info
->rtsdtr_inv
) {
3271 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3273 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3276 printk("cyc:set_line_char raising DTR\n");
3277 printk(" status: 0x%x, 0x%x\n",
3278 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3279 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3284 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3286 CY_UNLOCK(info
, flags
);
3289 struct FIRM_ID __iomem
*firm_id
;
3290 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3291 struct BOARD_CTRL __iomem
*board_ctrl
;
3292 struct CH_CTRL __iomem
*ch_ctrl
;
3293 struct BUF_CTRL __iomem
*buf_ctrl
;
3297 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3298 if (!ISZLOADED(cy_card
[card
])) {
3302 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3303 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3304 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3305 buf_ctrl
= &zfw_ctrl
->buf_ctrl
[channel
];
3308 baud
= tty_get_baud_rate(info
->tty
);
3309 if ((baud
== 38400) &&
3310 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3311 if (info
->custom_divisor
)
3312 baud_rate
= info
->baud
/ info
->custom_divisor
;
3314 baud_rate
= info
->baud
;
3315 } else if (baud
> CYZ_MAX_SPEED
) {
3316 baud
= CYZ_MAX_SPEED
;
3318 cy_writel(&ch_ctrl
->comm_baud
, baud
);
3321 /* get it right for 134.5 baud */
3322 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3323 } else if ((baud
== 38400) &&
3324 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3325 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3327 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud
) + 2;
3328 /* this needs to be propagated into the card info */
3333 /* byte size and parity */
3334 switch(cflag
& CSIZE
){
3335 case CS5
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS5
); break;
3336 case CS6
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS6
); break;
3337 case CS7
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS7
); break;
3338 case CS8
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS8
); break;
3341 cy_writel(&ch_ctrl
->comm_data_l
,
3342 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_2STOP
);
3344 cy_writel(&ch_ctrl
->comm_data_l
,
3345 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_1STOP
);
3347 if (cflag
& PARENB
){
3348 if (cflag
& PARODD
){
3349 cy_writel(&ch_ctrl
->comm_parity
, C_PR_ODD
);
3351 cy_writel(&ch_ctrl
->comm_parity
, C_PR_EVEN
);
3354 cy_writel(&ch_ctrl
->comm_parity
, C_PR_NONE
);
3357 /* CTS flow control flag */
3358 if (cflag
& CRTSCTS
){
3359 cy_writel(&ch_ctrl
->hw_flow
,
3360 cy_readl(&ch_ctrl
->hw_flow
) | C_RS_CTS
| C_RS_RTS
);
3362 cy_writel(&ch_ctrl
->hw_flow
,
3363 cy_readl(&ch_ctrl
->hw_flow
) & ~(C_RS_CTS
| C_RS_RTS
));
3365 /* As the HW flow control is done in firmware, the driver doesn't
3366 need to care about it */
3367 info
->flags
&= ~ASYNC_CTS_FLOW
;
3369 /* XON/XOFF/XANY flow control flags */
3372 sw_flow
|= C_FL_OXX
;
3374 sw_flow
|= C_FL_OIXANY
;
3376 cy_writel(&ch_ctrl
->sw_flow
, sw_flow
);
3378 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
3380 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3381 info
->line
, retval
);
3384 /* CD sensitivity */
3385 if (cflag
& CLOCAL
){
3386 info
->flags
&= ~ASYNC_CHECK_CD
;
3388 info
->flags
|= ASYNC_CHECK_CD
;
3391 if(baud
== 0){ /* baud rate is zero, turn off line */
3392 cy_writel(&ch_ctrl
->rs_control
,
3393 cy_readl(&ch_ctrl
->rs_control
) & ~C_RS_DTR
);
3395 printk("cyc:set_line_char dropping Z DTR\n");
3398 cy_writel(&ch_ctrl
->rs_control
,
3399 cy_readl(&ch_ctrl
->rs_control
) | C_RS_DTR
);
3401 printk("cyc:set_line_char raising Z DTR\n");
3405 retval
= cyz_issue_cmd( &cy_card
[card
], channel
, C_CM_IOCTLM
, 0L);
3407 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3408 info
->line
, retval
);
3412 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3415 } /* set_line_char */
3419 get_serial_info(struct cyclades_port
* info
,
3420 struct serial_struct __user
* retinfo
)
3422 struct serial_struct tmp
;
3423 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
3427 memset(&tmp
, 0, sizeof(tmp
));
3428 tmp
.type
= info
->type
;
3429 tmp
.line
= info
->line
;
3430 tmp
.port
= info
->card
* 0x100 + info
->line
- cinfo
->first_line
;
3431 tmp
.irq
= cinfo
->irq
;
3432 tmp
.flags
= info
->flags
;
3433 tmp
.close_delay
= info
->close_delay
;
3434 tmp
.baud_base
= info
->baud
;
3435 tmp
.custom_divisor
= info
->custom_divisor
;
3436 tmp
.hub6
= 0; /*!!!*/
3437 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
))?-EFAULT
:0;
3438 } /* get_serial_info */
3442 set_serial_info(struct cyclades_port
* info
,
3443 struct serial_struct __user
* new_info
)
3445 struct serial_struct new_serial
;
3446 struct cyclades_port old_info
;
3448 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
3452 if (!capable(CAP_SYS_ADMIN
)) {
3453 if ((new_serial
.close_delay
!= info
->close_delay
) ||
3454 (new_serial
.baud_base
!= info
->baud
) ||
3455 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
3456 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
3458 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
3459 (new_serial
.flags
& ASYNC_USR_MASK
));
3460 info
->baud
= new_serial
.baud_base
;
3461 info
->custom_divisor
= new_serial
.custom_divisor
;
3462 goto check_and_exit
;
3467 * OK, past this point, all the error checking has been done.
3468 * At this point, we start making changes.....
3471 info
->baud
= new_serial
.baud_base
;
3472 info
->custom_divisor
= new_serial
.custom_divisor
;
3473 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
3474 (new_serial
.flags
& ASYNC_FLAGS
));
3475 info
->close_delay
= new_serial
.close_delay
* HZ
/100;
3476 info
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
3479 if (info
->flags
& ASYNC_INITIALIZED
){
3480 set_line_char(info
);
3483 return startup(info
);
3485 } /* set_serial_info */
3488 * get_lsr_info - get line status register info
3490 * Purpose: Let user call ioctl() to get info when the UART physically
3491 * is emptied. On bus types like RS485, the transmitter must
3492 * release the bus after transmitting. This must be done when
3493 * the transmit shift register is empty, not be done when the
3494 * transmit holding register is empty. This functionality
3495 * allows an RS485 driver to be written in user space.
3497 static int get_lsr_info(struct cyclades_port
*info
, unsigned int __user
*value
)
3499 int card
, chip
, channel
, index
;
3500 unsigned char status
;
3501 unsigned int result
;
3502 unsigned long flags
;
3503 void __iomem
*base_addr
;
3506 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3507 if (!IS_CYC_Z(cy_card
[card
])) {
3510 index
= cy_card
[card
].bus_index
;
3511 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3513 CY_LOCK(info
, flags
);
3514 status
= cy_readb(base_addr
+(CySRER
<<index
)) & (CyTxRdy
|CyTxMpty
);
3515 CY_UNLOCK(info
, flags
);
3516 result
= (status
? 0 : TIOCSER_TEMT
);
3518 /* Not supported yet */
3521 return put_user(result
, (unsigned long __user
*) value
);
3525 cy_tiocmget(struct tty_struct
*tty
, struct file
*file
)
3527 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3528 int card
,chip
,channel
,index
;
3529 void __iomem
*base_addr
;
3530 unsigned long flags
;
3531 unsigned char status
;
3532 unsigned long lstatus
;
3533 unsigned int result
;
3534 struct FIRM_ID __iomem
*firm_id
;
3535 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3536 struct BOARD_CTRL __iomem
*board_ctrl
;
3537 struct CH_CTRL __iomem
*ch_ctrl
;
3539 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3543 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3544 if (!IS_CYC_Z(cy_card
[card
])) {
3547 index
= cy_card
[card
].bus_index
;
3548 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3550 CY_LOCK(info
, flags
);
3551 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3552 status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
3553 status
|= cy_readb(base_addr
+(CyMSVR2
<<index
));
3554 CY_UNLOCK(info
, flags
);
3556 if (info
->rtsdtr_inv
) {
3557 result
= ((status
& CyRTS
) ? TIOCM_DTR
: 0)
3558 | ((status
& CyDTR
) ? TIOCM_RTS
: 0);
3560 result
= ((status
& CyRTS
) ? TIOCM_RTS
: 0)
3561 | ((status
& CyDTR
) ? TIOCM_DTR
: 0);
3563 result
|= ((status
& CyDCD
) ? TIOCM_CAR
: 0)
3564 | ((status
& CyRI
) ? TIOCM_RNG
: 0)
3565 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
3566 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
3568 base_addr
= cy_card
[card
].base_addr
;
3570 if (cy_card
[card
].num_chips
!= -1){
3574 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3575 if (ISZLOADED(cy_card
[card
])) {
3576 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3577 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3578 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3579 lstatus
= cy_readl(&ch_ctrl
[channel
].rs_status
);
3580 result
= ((lstatus
& C_RS_RTS
) ? TIOCM_RTS
: 0)
3581 | ((lstatus
& C_RS_DTR
) ? TIOCM_DTR
: 0)
3582 | ((lstatus
& C_RS_DCD
) ? TIOCM_CAR
: 0)
3583 | ((lstatus
& C_RS_RI
) ? TIOCM_RNG
: 0)
3584 | ((lstatus
& C_RS_DSR
) ? TIOCM_DSR
: 0)
3585 | ((lstatus
& C_RS_CTS
) ? TIOCM_CTS
: 0);
3597 cy_tiocmset(struct tty_struct
*tty
, struct file
*file
,
3598 unsigned int set
, unsigned int clear
)
3600 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3601 int card
,chip
,channel
,index
;
3602 void __iomem
*base_addr
;
3603 unsigned long flags
;
3604 struct FIRM_ID __iomem
*firm_id
;
3605 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3606 struct BOARD_CTRL __iomem
*board_ctrl
;
3607 struct CH_CTRL __iomem
*ch_ctrl
;
3610 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3614 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3615 if (!IS_CYC_Z(cy_card
[card
])) {
3618 index
= cy_card
[card
].bus_index
;
3619 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3621 if (set
& TIOCM_RTS
){
3622 CY_LOCK(info
, flags
);
3623 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3624 if (info
->rtsdtr_inv
) {
3625 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3627 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3629 CY_UNLOCK(info
, flags
);
3631 if (clear
& TIOCM_RTS
) {
3632 CY_LOCK(info
, flags
);
3633 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3634 if (info
->rtsdtr_inv
) {
3635 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3637 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3639 CY_UNLOCK(info
, flags
);
3641 if (set
& TIOCM_DTR
){
3642 CY_LOCK(info
, flags
);
3643 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3644 if (info
->rtsdtr_inv
) {
3645 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3647 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3650 printk("cyc:set_modem_info raising DTR\n");
3651 printk(" status: 0x%x, 0x%x\n",
3652 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3653 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3655 CY_UNLOCK(info
, flags
);
3657 if (clear
& TIOCM_DTR
) {
3658 CY_LOCK(info
, flags
);
3659 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3660 if (info
->rtsdtr_inv
) {
3661 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3663 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3667 printk("cyc:set_modem_info dropping DTR\n");
3668 printk(" status: 0x%x, 0x%x\n",
3669 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3670 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3672 CY_UNLOCK(info
, flags
);
3675 base_addr
= cy_card
[card
].base_addr
;
3677 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3678 if (ISZLOADED(cy_card
[card
])) {
3679 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3680 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3681 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3683 if (set
& TIOCM_RTS
){
3684 CY_LOCK(info
, flags
);
3685 cy_writel(&ch_ctrl
[channel
].rs_control
,
3686 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3687 CY_UNLOCK(info
, flags
);
3689 if (clear
& TIOCM_RTS
) {
3690 CY_LOCK(info
, flags
);
3691 cy_writel(&ch_ctrl
[channel
].rs_control
,
3692 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3693 CY_UNLOCK(info
, flags
);
3695 if (set
& TIOCM_DTR
){
3696 CY_LOCK(info
, flags
);
3697 cy_writel(&ch_ctrl
[channel
].rs_control
,
3698 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3700 printk("cyc:set_modem_info raising Z DTR\n");
3702 CY_UNLOCK(info
, flags
);
3704 if (clear
& TIOCM_DTR
) {
3705 CY_LOCK(info
, flags
);
3706 cy_writel(&ch_ctrl
[channel
].rs_control
,
3707 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3709 printk("cyc:set_modem_info clearing Z DTR\n");
3711 CY_UNLOCK(info
, flags
);
3716 CY_LOCK(info
, flags
);
3717 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3718 channel
, C_CM_IOCTLM
,0L);
3720 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3721 info
->line
, retval
);
3723 CY_UNLOCK(info
, flags
);
3729 * cy_break() --- routine which turns the break handling on or off
3732 cy_break(struct tty_struct
*tty
, int break_state
)
3734 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3735 unsigned long flags
;
3737 if (serial_paranoia_check(info
, tty
->name
, "cy_break"))
3740 CY_LOCK(info
, flags
);
3741 if (!IS_CYC_Z(cy_card
[info
->card
])) {
3742 /* Let the transmit ISR take care of this (since it
3743 requires stuffing characters into the output stream).
3745 if (break_state
== -1) {
3746 if (!info
->breakon
) {
3748 if (!info
->xmit_cnt
) {
3749 CY_UNLOCK(info
, flags
);
3751 CY_LOCK(info
, flags
);
3755 if (!info
->breakoff
) {
3757 if (!info
->xmit_cnt
) {
3758 CY_UNLOCK(info
, flags
);
3760 CY_LOCK(info
, flags
);
3767 if (break_state
== -1) {
3768 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3769 (info
->line
) - (cy_card
[info
->card
].first_line
),
3770 C_CM_SET_BREAK
, 0L);
3772 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3773 info
->line
, retval
);
3776 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3777 (info
->line
) - (cy_card
[info
->card
].first_line
),
3778 C_CM_CLR_BREAK
, 0L);
3780 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3781 info
->line
, retval
);
3785 CY_UNLOCK(info
, flags
);
3789 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor __user
* mon
)
3792 if(copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
3794 info
->mon
.int_count
= 0;
3795 info
->mon
.char_count
= 0;
3796 info
->mon
.char_max
= 0;
3797 info
->mon
.char_last
= 0;
3803 set_threshold(struct cyclades_port
* info
, unsigned long value
)
3805 void __iomem
*base_addr
;
3806 int card
,channel
,chip
,index
;
3807 unsigned long flags
;
3810 channel
= info
->line
- cy_card
[card
].first_line
;
3811 if (!IS_CYC_Z(cy_card
[card
])) {
3814 index
= cy_card
[card
].bus_index
;
3815 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3817 info
->cor3
&= ~CyREC_FIFO
;
3818 info
->cor3
|= value
& CyREC_FIFO
;
3820 CY_LOCK(info
, flags
);
3821 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3822 cyy_issue_cmd(base_addr
,CyCOR_CHANGE
|CyCOR3ch
,index
);
3823 CY_UNLOCK(info
, flags
);
3828 }/* set_threshold */
3832 get_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3834 void __iomem
*base_addr
;
3835 int card
,channel
,chip
,index
;
3839 channel
= info
->line
- cy_card
[card
].first_line
;
3840 if (!IS_CYC_Z(cy_card
[card
])) {
3843 index
= cy_card
[card
].bus_index
;
3844 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3846 tmp
= cy_readb(base_addr
+(CyCOR3
<<index
)) & CyREC_FIFO
;
3847 return put_user(tmp
,value
);
3852 }/* get_threshold */
3856 set_default_threshold(struct cyclades_port
* info
, unsigned long value
)
3858 info
->default_threshold
= value
& 0x0f;
3860 }/* set_default_threshold */
3864 get_default_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3866 return put_user(info
->default_threshold
,value
);
3867 }/* get_default_threshold */
3871 set_timeout(struct cyclades_port
* info
, unsigned long value
)
3873 void __iomem
*base_addr
;
3874 int card
,channel
,chip
,index
;
3875 unsigned long flags
;
3878 channel
= info
->line
- cy_card
[card
].first_line
;
3879 if (!IS_CYC_Z(cy_card
[card
])) {
3882 index
= cy_card
[card
].bus_index
;
3883 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3885 CY_LOCK(info
, flags
);
3886 cy_writeb(base_addr
+(CyRTPR
<<index
), value
& 0xff);
3887 CY_UNLOCK(info
, flags
);
3896 get_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
3898 void __iomem
*base_addr
;
3899 int card
,channel
,chip
,index
;
3903 channel
= info
->line
- cy_card
[card
].first_line
;
3904 if (!IS_CYC_Z(cy_card
[card
])) {
3907 index
= cy_card
[card
].bus_index
;
3908 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3910 tmp
= cy_readb(base_addr
+(CyRTPR
<<index
));
3911 return put_user(tmp
,value
);
3920 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
3922 info
->default_timeout
= value
& 0xff;
3924 }/* set_default_timeout */
3928 get_default_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
3930 return put_user(info
->default_timeout
,value
);
3931 }/* get_default_timeout */
3934 * This routine allows the tty driver to implement device-
3935 * specific ioctl's. If the ioctl number passed in cmd is
3936 * not recognized by the driver, it should return ENOIOCTLCMD.
3939 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
3940 unsigned int cmd
, unsigned long arg
)
3942 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3943 struct cyclades_icount cprev
, cnow
; /* kernel counter temps */
3944 struct serial_icounter_struct __user
*p_cuser
; /* user space */
3946 unsigned long flags
;
3947 void __user
*argp
= (void __user
*)arg
;
3949 if (serial_paranoia_check(info
, tty
->name
, "cy_ioctl"))
3952 #ifdef CY_DEBUG_OTHER
3953 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
3954 info
->line
, cmd
, arg
); /* */
3959 ret_val
= get_mon_info(info
, argp
);
3962 ret_val
= get_threshold(info
, argp
);
3965 ret_val
= set_threshold(info
, arg
);
3967 case CYGETDEFTHRESH
:
3968 ret_val
= get_default_threshold(info
, argp
);
3970 case CYSETDEFTHRESH
:
3971 ret_val
= set_default_threshold(info
, arg
);
3974 ret_val
= get_timeout(info
, argp
);
3977 ret_val
= set_timeout(info
, arg
);
3979 case CYGETDEFTIMEOUT
:
3980 ret_val
= get_default_timeout(info
, argp
);
3982 case CYSETDEFTIMEOUT
:
3983 ret_val
= set_default_timeout(info
, arg
);
3986 info
->rflow
= (int)arg
;
3990 ret_val
= info
->rflow
;
3992 case CYSETRTSDTR_INV
:
3993 info
->rtsdtr_inv
= (int)arg
;
3996 case CYGETRTSDTR_INV
:
3997 ret_val
= info
->rtsdtr_inv
;
4000 if (copy_to_user(argp
, &cy_card
[info
->card
],
4001 sizeof (struct cyclades_card
))) {
4007 case CYGETCD1400VER
:
4008 ret_val
= info
->chip_rev
;
4010 #ifndef CONFIG_CYZ_INTR
4011 case CYZSETPOLLCYCLE
:
4012 cyz_polling_cycle
= (arg
* HZ
) / 1000;
4015 case CYZGETPOLLCYCLE
:
4016 ret_val
= (cyz_polling_cycle
* 1000) / HZ
;
4018 #endif /* CONFIG_CYZ_INTR */
4020 info
->closing_wait
= (unsigned short)arg
* HZ
/100;
4024 ret_val
= info
->closing_wait
/ (HZ
/100);
4027 ret_val
= get_serial_info(info
, argp
);
4030 ret_val
= set_serial_info(info
, argp
);
4032 case TIOCSERGETLSR
: /* Get line status register */
4033 ret_val
= get_lsr_info(info
, argp
);
4036 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4037 * - mask passed in arg for lines of interest
4038 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4039 * Caller should use TIOCGICOUNT to see which one it was
4042 CY_LOCK(info
, flags
);
4043 /* note the counters on entry */
4044 cprev
= info
->icount
;
4045 CY_UNLOCK(info
, flags
);
4047 interruptible_sleep_on(&info
->delta_msr_wait
);
4048 /* see if a signal did it */
4049 if (signal_pending(current
)) {
4050 return -ERESTARTSYS
;
4053 CY_LOCK(info
, flags
);
4054 cnow
= info
->icount
; /* atomic copy */
4055 CY_UNLOCK(info
, flags
);
4057 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
4058 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
4059 return -EIO
; /* no change => error */
4061 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
4062 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
4063 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
4064 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
4072 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4073 * Return: write counters to the user passed counter struct
4074 * NB: both 1->0 and 0->1 transitions are counted except for
4075 * RI where only 0->1 is counted.
4078 CY_LOCK(info
, flags
);
4079 cnow
= info
->icount
;
4080 CY_UNLOCK(info
, flags
);
4082 ret_val
= put_user(cnow
.cts
, &p_cuser
->cts
);
4083 if (ret_val
) return ret_val
;
4084 ret_val
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
4085 if (ret_val
) return ret_val
;
4086 ret_val
= put_user(cnow
.rng
, &p_cuser
->rng
);
4087 if (ret_val
) return ret_val
;
4088 ret_val
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
4089 if (ret_val
) return ret_val
;
4090 ret_val
= put_user(cnow
.rx
, &p_cuser
->rx
);
4091 if (ret_val
) return ret_val
;
4092 ret_val
= put_user(cnow
.tx
, &p_cuser
->tx
);
4093 if (ret_val
) return ret_val
;
4094 ret_val
= put_user(cnow
.frame
, &p_cuser
->frame
);
4095 if (ret_val
) return ret_val
;
4096 ret_val
= put_user(cnow
.overrun
, &p_cuser
->overrun
);
4097 if (ret_val
) return ret_val
;
4098 ret_val
= put_user(cnow
.parity
, &p_cuser
->parity
);
4099 if (ret_val
) return ret_val
;
4100 ret_val
= put_user(cnow
.brk
, &p_cuser
->brk
);
4101 if (ret_val
) return ret_val
;
4102 ret_val
= put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
4103 if (ret_val
) return ret_val
;
4107 ret_val
= -ENOIOCTLCMD
;
4110 #ifdef CY_DEBUG_OTHER
4111 printk(" cyc:cy_ioctl done\n");
4119 * This routine allows the tty driver to be notified when
4120 * device's termios settings have changed. Note that a
4121 * well-designed tty driver should be prepared to accept the case
4122 * where old == NULL, and try to do something rational.
4125 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
4127 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4129 #ifdef CY_DEBUG_OTHER
4130 printk("cyc:cy_set_termios ttyC%d\n", info
->line
);
4133 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
4134 ((tty
->termios
->c_iflag
& (IXON
|IXANY
)) ==
4135 (old_termios
->c_iflag
& (IXON
|IXANY
))))
4137 set_line_char(info
);
4139 if ((old_termios
->c_cflag
& CRTSCTS
) &&
4140 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
4141 tty
->hw_stopped
= 0;
4146 * No need to wake up processes in open wait, since they
4147 * sample the CLOCAL flag once, and don't recheck it.
4148 * XXX It's not clear whether the current behavior is correct
4149 * or not. Hence, this may change.....
4151 if (!(old_termios
->c_cflag
& CLOCAL
) &&
4152 (tty
->termios
->c_cflag
& CLOCAL
))
4153 wake_up_interruptible(&info
->open_wait
);
4157 } /* cy_set_termios */
4159 /* This function is used to send a high-priority XON/XOFF character to
4163 cy_send_xchar (struct tty_struct
*tty
, char ch
)
4165 struct cyclades_port
*info
= (struct cyclades_port
*) tty
->driver_data
;
4168 if (serial_paranoia_check (info
, tty
->name
, "cy_send_xchar"))
4177 channel
= info
->line
- cy_card
[card
].first_line
;
4179 if (IS_CYC_Z (cy_card
[card
])) {
4180 if (ch
== STOP_CHAR (tty
))
4181 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXOFF
, 0L);
4182 else if (ch
== START_CHAR (tty
))
4183 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXON
, 0L);
4187 /* This routine is called by the upper-layer tty layer to signal
4188 that incoming characters should be throttled because the input
4189 buffers are close to full.
4192 cy_throttle(struct tty_struct
* tty
)
4194 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4195 unsigned long flags
;
4196 void __iomem
*base_addr
;
4197 int card
,chip
,channel
,index
;
4199 #ifdef CY_DEBUG_THROTTLE
4202 printk("cyc:throttle %s: %d....ttyC%d\n",
4204 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4207 if (serial_paranoia_check(info
, tty
->name
, "cy_throttle")){
4214 if (!IS_CYC_Z (cy_card
[card
]))
4215 cy_send_xchar (tty
, STOP_CHAR (tty
));
4220 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4221 channel
= info
->line
- cy_card
[card
].first_line
;
4222 if (!IS_CYC_Z(cy_card
[card
])) {
4225 index
= cy_card
[card
].bus_index
;
4226 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4228 CY_LOCK(info
, flags
);
4229 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4230 if (info
->rtsdtr_inv
) {
4231 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
4233 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
4235 CY_UNLOCK(info
, flags
);
4246 * This routine notifies the tty driver that it should signal
4247 * that characters can now be sent to the tty without fear of
4248 * overrunning the input buffers of the line disciplines.
4251 cy_unthrottle(struct tty_struct
* tty
)
4253 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4254 unsigned long flags
;
4255 void __iomem
*base_addr
;
4256 int card
,chip
,channel
,index
;
4258 #ifdef CY_DEBUG_THROTTLE
4261 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4263 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4266 if (serial_paranoia_check(info
, tty
->name
, "cy_unthrottle")){
4274 cy_send_xchar (tty
, START_CHAR (tty
));
4277 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4279 channel
= info
->line
- cy_card
[card
].first_line
;
4280 if (!IS_CYC_Z(cy_card
[card
])) {
4283 index
= cy_card
[card
].bus_index
;
4284 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4286 CY_LOCK(info
, flags
);
4287 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4288 if (info
->rtsdtr_inv
) {
4289 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
4291 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
4293 CY_UNLOCK(info
, flags
);
4300 } /* cy_unthrottle */
4303 /* cy_start and cy_stop provide software output flow control as a
4304 function of XON/XOFF, software CTS, and other such stuff.
4307 cy_stop(struct tty_struct
*tty
)
4309 struct cyclades_card
*cinfo
;
4310 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4311 void __iomem
*base_addr
;
4312 int chip
,channel
,index
;
4313 unsigned long flags
;
4315 #ifdef CY_DEBUG_OTHER
4316 printk("cyc:cy_stop ttyC%d\n", info
->line
); /* */
4319 if (serial_paranoia_check(info
, tty
->name
, "cy_stop"))
4322 cinfo
= &cy_card
[info
->card
];
4323 channel
= info
->line
- cinfo
->first_line
;
4324 if (!IS_CYC_Z(*cinfo
)) {
4325 index
= cinfo
->bus_index
;
4328 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4330 CY_LOCK(info
, flags
);
4331 cy_writeb(base_addr
+(CyCAR
<<index
),
4332 (u_char
)(channel
& 0x0003)); /* index channel */
4333 cy_writeb(base_addr
+(CySRER
<<index
),
4334 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
4335 CY_UNLOCK(info
, flags
);
4345 cy_start(struct tty_struct
*tty
)
4347 struct cyclades_card
*cinfo
;
4348 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4349 void __iomem
*base_addr
;
4350 int chip
,channel
,index
;
4351 unsigned long flags
;
4353 #ifdef CY_DEBUG_OTHER
4354 printk("cyc:cy_start ttyC%d\n", info
->line
); /* */
4357 if (serial_paranoia_check(info
, tty
->name
, "cy_start"))
4360 cinfo
= &cy_card
[info
->card
];
4361 channel
= info
->line
- cinfo
->first_line
;
4362 index
= cinfo
->bus_index
;
4363 if (!IS_CYC_Z(*cinfo
)) {
4366 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4368 CY_LOCK(info
, flags
);
4369 cy_writeb(base_addr
+(CyCAR
<<index
),
4370 (u_char
)(channel
& 0x0003)); /* index channel */
4371 cy_writeb(base_addr
+(CySRER
<<index
),
4372 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
4373 CY_UNLOCK(info
, flags
);
4383 cy_flush_buffer(struct tty_struct
*tty
)
4385 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4386 int card
, channel
, retval
;
4387 unsigned long flags
;
4390 printk("cyc:cy_flush_buffer ttyC%d\n", info
->line
); /* */
4393 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_buffer"))
4397 channel
= (info
->line
) - (cy_card
[card
].first_line
);
4399 CY_LOCK(info
, flags
);
4400 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
4401 CY_UNLOCK(info
, flags
);
4403 if (IS_CYC_Z(cy_card
[card
])) { /* If it is a Z card, flush the on-board
4405 CY_LOCK(info
, flags
);
4406 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_TX
, 0L);
4408 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4409 info
->line
, retval
);
4411 CY_UNLOCK(info
, flags
);
4414 wake_up_interruptible(&tty
->write_wait
);
4415 } /* cy_flush_buffer */
4419 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4422 cy_hangup(struct tty_struct
*tty
)
4424 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4426 #ifdef CY_DEBUG_OTHER
4427 printk("cyc:cy_hangup ttyC%d\n", info
->line
); /* */
4430 if (serial_paranoia_check(info
, tty
->name
, "cy_hangup"))
4433 cy_flush_buffer(tty
);
4437 #ifdef CY_DEBUG_COUNT
4438 printk("cyc:cy_hangup (%d): setting count to 0\n", current
->pid
);
4441 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
4442 wake_up_interruptible(&info
->open_wait
);
4447 * ---------------------------------------------------------------------
4448 * cy_init() and friends
4450 * cy_init() is called at boot-time to initialize the serial driver.
4451 * ---------------------------------------------------------------------
4454 /* initialize chips on Cyclom-Y card -- return number of valid
4455 chips (which is number of ports/4) */
4456 static unsigned short __init
4457 cyy_init_card(void __iomem
*true_base_addr
,int index
)
4459 unsigned int chip_number
;
4460 void __iomem
*base_addr
;
4462 cy_writeb(true_base_addr
+(Cy_HwReset
<<index
), 0);
4463 /* Cy_HwReset is 0x1400 */
4464 cy_writeb(true_base_addr
+(Cy_ClrIntr
<<index
), 0);
4465 /* Cy_ClrIntr is 0x1800 */
4468 for(chip_number
=0; chip_number
<CyMAX_CHIPS_PER_CARD
; chip_number
++){
4469 base_addr
= true_base_addr
+ (cy_chip_offset
[chip_number
]<<index
);
4471 if(cy_readb(base_addr
+(CyCCR
<<index
)) != 0x00){
4473 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4474 chip_number, (unsigned long)base_addr);
4479 cy_writeb(base_addr
+(CyGFRCR
<<index
), 0);
4482 /* The Cyclom-16Y does not decode address bit 9 and therefore
4483 cannot distinguish between references to chip 0 and a non-
4484 existent chip 4. If the preceding clearing of the supposed
4485 chip 4 GFRCR register appears at chip 0, there is no chip 4
4486 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4488 if (chip_number
== 4
4489 && cy_readb(true_base_addr
4490 + (cy_chip_offset
[0]<<index
)
4491 + (CyGFRCR
<<index
)) == 0){
4495 cy_writeb(base_addr
+(CyCCR
<<index
), CyCHIP_RESET
);
4498 if(cy_readb(base_addr
+(CyGFRCR
<<index
)) == 0x00){
4500 printk(" chip #%d at %#6lx is not responding ",
4501 chip_number, (unsigned long)base_addr);
4502 printk("(GFRCR stayed 0)\n",
4506 if((0xf0 & (cy_readb(base_addr
+(CyGFRCR
<<index
)))) != 0x40){
4508 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4509 chip_number, (unsigned long)base_addr,
4510 base_addr[CyGFRCR<<index]);
4514 cy_writeb(base_addr
+(CyGCR
<<index
), CyCH0_SERIAL
);
4515 if (cy_readb(base_addr
+(CyGFRCR
<<index
)) >= CD1400_REV_J
){
4516 /* It is a CD1400 rev. J or later */
4517 /* Impossible to reach 5ms with this chip.
4518 Changed to 2ms instead (f = 500 Hz). */
4519 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_60_2MS
);
4522 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_25_5MS
);
4526 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4527 chip_number, (unsigned long)base_addr,
4528 cy_readb(base_addr+(CyGFRCR<<index)));
4532 } /* cyy_init_card */
4535 * ---------------------------------------------------------------------
4536 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4537 * sets global variables and return the number of ISA boards found.
4538 * ---------------------------------------------------------------------
4544 unsigned short cy_isa_irq
,nboard
;
4545 void __iomem
*cy_isa_address
;
4546 unsigned short i
,j
,cy_isa_nchan
;
4554 /* Check for module parameters */
4555 for(i
= 0 ; i
< NR_CARDS
; i
++) {
4556 if (maddr
[i
] || i
) {
4558 cy_isa_addresses
[i
] = maddr
[i
];
4565 /* scan the address table probing for Cyclom-Y/ISA boards */
4566 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
4567 unsigned int isa_address
= cy_isa_addresses
[i
];
4568 if (isa_address
== 0x0000) {
4572 /* probe for CD1400... */
4573 cy_isa_address
= ioremap(isa_address
, CyISA_Ywin
);
4574 cy_isa_nchan
= CyPORTS_PER_CHIP
*
4575 cyy_init_card(cy_isa_address
,0);
4576 if (cy_isa_nchan
== 0) {
4581 if (isparam
&& irq
[i
])
4582 cy_isa_irq
= irq
[i
];
4585 /* find out the board's irq by probing */
4586 cy_isa_irq
= detect_isa_irq(cy_isa_address
);
4587 if (cy_isa_irq
== 0) {
4588 printk("Cyclom-Y/ISA found at 0x%lx ",
4589 (unsigned long) cy_isa_address
);
4590 printk("but the IRQ could not be detected.\n");
4594 if((cy_next_channel
+cy_isa_nchan
) > NR_PORTS
) {
4595 printk("Cyclom-Y/ISA found at 0x%lx ",
4596 (unsigned long) cy_isa_address
);
4597 printk("but no more channels are available.\n");
4598 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4601 /* fill the next cy_card structure available */
4602 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4603 if (cy_card
[j
].base_addr
== 0) break;
4605 if (j
== NR_CARDS
) { /* no more cy_cards available */
4606 printk("Cyclom-Y/ISA found at 0x%lx ",
4607 (unsigned long) cy_isa_address
);
4608 printk("but no more cards can be used .\n");
4609 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4614 if(request_irq(cy_isa_irq
, cyy_interrupt
,
4615 IRQF_DISABLED
, "Cyclom-Y", &cy_card
[j
]))
4617 printk("Cyclom-Y/ISA found at 0x%lx ",
4618 (unsigned long) cy_isa_address
);
4619 printk("but could not allocate IRQ#%d.\n",
4625 cy_card
[j
].base_addr
= cy_isa_address
;
4626 cy_card
[j
].ctl_addr
= NULL
;
4627 cy_card
[j
].irq
= (int) cy_isa_irq
;
4628 cy_card
[j
].bus_index
= 0;
4629 cy_card
[j
].first_line
= cy_next_channel
;
4630 cy_card
[j
].num_chips
= cy_isa_nchan
/4;
4634 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4635 j
+1, (unsigned long) cy_isa_address
,
4636 (unsigned long)(cy_isa_address
+ (CyISA_Ywin
- 1)),
4638 printk("%d channels starting from port %d.\n",
4639 cy_isa_nchan
, cy_next_channel
);
4640 cy_next_channel
+= cy_isa_nchan
;
4645 #endif /* CONFIG_ISA */
4646 } /* cy_detect_isa */
4649 plx_init(void __iomem
*addr
, uclong initctl
)
4652 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x40000000);
4654 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x40000000);
4656 /* Reload Config. Registers from EEPROM */
4657 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x20000000);
4659 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x20000000);
4663 * ---------------------------------------------------------------------
4664 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4665 * sets global variables and return the number of PCI boards found.
4666 * ---------------------------------------------------------------------
4673 struct pci_dev
*pdev
= NULL
;
4674 unsigned char cyy_rev_id
;
4675 unsigned char cy_pci_irq
= 0;
4676 uclong cy_pci_phys0
, cy_pci_phys2
;
4677 void __iomem
*cy_pci_addr0
, *cy_pci_addr2
;
4678 unsigned short i
,j
,cy_pci_nchan
, plx_ver
;
4679 unsigned short device_id
,dev_index
= 0;
4682 void __iomem
*Ze_addr0
[NR_CARDS
], *Ze_addr2
[NR_CARDS
];
4683 uclong Ze_phys0
[NR_CARDS
], Ze_phys2
[NR_CARDS
];
4684 unsigned char Ze_irq
[NR_CARDS
];
4685 struct pci_dev
*Ze_pdev
[NR_CARDS
];
4687 for (i
= 0; i
< NR_CARDS
; i
++) {
4688 /* look for a Cyclades card by vendor and device id */
4689 while((device_id
= cy_pci_dev_id
[dev_index
]) != 0) {
4690 if((pdev
= pci_get_device(PCI_VENDOR_ID_CYCLADES
,
4691 device_id
, pdev
)) == NULL
) {
4692 dev_index
++; /* try next device id */
4694 break; /* found a board */
4701 if (pci_enable_device(pdev
))
4704 /* read PCI configuration area */
4705 cy_pci_irq
= pdev
->irq
;
4706 cy_pci_phys0
= pci_resource_start(pdev
, 0);
4707 cy_pci_phys2
= pci_resource_start(pdev
, 2);
4708 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &cyy_rev_id
);
4710 device_id
&= ~PCI_DEVICE_ID_MASK
;
4712 if ((device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
)
4713 || (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Hi
)){
4715 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4716 pdev
->bus
->number
, pdev
->devfn
);
4717 printk("rev_id=%d) IRQ%d\n",
4718 cyy_rev_id
, (int)cy_pci_irq
);
4719 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4720 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4723 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4724 printk(" Warning: PCI I/O bit incorrectly set. "
4725 "Ignoring it...\n");
4726 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4729 /* Although we don't use this I/O region, we should
4730 request it from the kernel anyway, to avoid problems
4731 with other drivers accessing it. */
4732 if (pci_request_regions(pdev
, "Cyclom-Y") != 0) {
4733 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4737 #if defined(__alpha__)
4738 if (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
) { /* below 1M? */
4739 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4740 pdev
->bus
->number
, pdev
->devfn
);
4741 printk("rev_id=%d) IRQ%d\n",
4742 cyy_rev_id
, (int)cy_pci_irq
);
4743 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4744 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4745 printk("Cyclom-Y/PCI not supported for low addresses in "
4746 "Alpha systems.\n");
4751 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Yctl
);
4752 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ywin
);
4755 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4756 (u_long
)cy_pci_addr2
, (u_long
)cy_pci_addr0
);
4758 cy_pci_nchan
= (unsigned short)(CyPORTS_PER_CHIP
*
4759 cyy_init_card(cy_pci_addr2
, 1));
4760 if(cy_pci_nchan
== 0) {
4761 printk("Cyclom-Y PCI host card with ");
4762 printk("no Serial-Modules at 0x%lx.\n",
4763 (ulong
) cy_pci_phys2
);
4767 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4768 printk("Cyclom-Y/PCI found at 0x%lx ",
4769 (ulong
) cy_pci_phys2
);
4770 printk("but no channels are available.\n");
4771 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4774 /* fill the next cy_card structure available */
4775 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4776 if (cy_card
[j
].base_addr
== 0) break;
4778 if (j
== NR_CARDS
) { /* no more cy_cards available */
4779 printk("Cyclom-Y/PCI found at 0x%lx ",
4780 (ulong
) cy_pci_phys2
);
4781 printk("but no more cards can be used.\n");
4782 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4787 if(request_irq(cy_pci_irq
, cyy_interrupt
,
4788 IRQF_SHARED
, "Cyclom-Y", &cy_card
[j
]))
4790 printk("Cyclom-Y/PCI found at 0x%lx ",
4791 (ulong
) cy_pci_phys2
);
4792 printk("but could not allocate IRQ%d.\n",
4798 cy_card
[j
].base_phys
= (ulong
)cy_pci_phys2
;
4799 cy_card
[j
].ctl_phys
= (ulong
)cy_pci_phys0
;
4800 cy_card
[j
].base_addr
= cy_pci_addr2
;
4801 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
4802 cy_card
[j
].irq
= (int) cy_pci_irq
;
4803 cy_card
[j
].bus_index
= 1;
4804 cy_card
[j
].first_line
= cy_next_channel
;
4805 cy_card
[j
].num_chips
= cy_pci_nchan
/4;
4806 cy_card
[j
].pdev
= pdev
;
4808 /* enable interrupts in the PCI interface */
4809 plx_ver
= cy_readb(cy_pci_addr2
+ CyPLX_VER
) & 0x0f;
4813 cy_writeb(cy_pci_addr0
+0x4c, 0x43);
4818 default: /* Old boards, use PLX_9060 */
4820 plx_init(cy_pci_addr0
, 0x6c);
4821 /* For some yet unknown reason, once the PLX9060 reloads
4822 the EEPROM, the IRQ is lost and, thus, we have to
4823 re-write it to the PCI config. registers.
4824 This will remain here until we find a permanent fix. */
4825 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4827 cy_writew(cy_pci_addr0
+0x68,
4828 cy_readw(cy_pci_addr0
+0x68)|0x0900);
4833 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4835 (ulong
)cy_pci_phys2
,
4836 (ulong
)(cy_pci_phys2
+ CyPCI_Ywin
- 1),
4838 printk("%d channels starting from port %d.\n",
4839 cy_pci_nchan
, cy_next_channel
);
4841 cy_next_channel
+= cy_pci_nchan
;
4842 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Lo
){
4844 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4845 pdev
->bus
->number
, pdev
->devfn
);
4846 printk("rev_id=%d) IRQ%d\n",
4847 cyy_rev_id
, (int)cy_pci_irq
);
4848 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4849 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4850 printk("Cyclades-Z/PCI not supported for low addresses\n");
4852 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Hi
){
4854 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4855 pdev
->bus
->number
, pdev
->devfn
);
4856 printk("rev_id=%d) IRQ%d\n",
4857 cyy_rev_id
, (int)cy_pci_irq
);
4858 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4859 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4861 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Zctl
);
4863 /* Disable interrupts on the PLX before resetting it */
4864 cy_writew(cy_pci_addr0
+0x68,
4865 cy_readw(cy_pci_addr0
+0x68) & ~0x0900);
4867 plx_init(cy_pci_addr0
, 0x6c);
4868 /* For some yet unknown reason, once the PLX9060 reloads
4869 the EEPROM, the IRQ is lost and, thus, we have to
4870 re-write it to the PCI config. registers.
4871 This will remain here until we find a permanent fix. */
4872 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4874 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
4875 cy_pci_addr0
)->mail_box_0
);
4877 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4878 printk(" Warning: PCI I/O bit incorrectly set. "
4879 "Ignoring it...\n");
4880 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4883 /* Although we don't use this I/O region, we should
4884 request it from the kernel anyway, to avoid problems
4885 with other drivers accessing it. */
4886 if (pci_request_regions(pdev
, "Cyclades-Z") != 0) {
4887 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4891 if (mailbox
== ZE_V1
) {
4892 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ze_win
);
4893 if (ZeIndex
== NR_CARDS
) {
4894 printk("Cyclades-Ze/PCI found at 0x%lx ",
4895 (ulong
)cy_pci_phys2
);
4896 printk("but no more cards can be used.\n");
4897 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4899 Ze_phys0
[ZeIndex
] = cy_pci_phys0
;
4900 Ze_phys2
[ZeIndex
] = cy_pci_phys2
;
4901 Ze_addr0
[ZeIndex
] = cy_pci_addr0
;
4902 Ze_addr2
[ZeIndex
] = cy_pci_addr2
;
4903 Ze_irq
[ZeIndex
] = cy_pci_irq
;
4904 Ze_pdev
[ZeIndex
] = pdev
;
4910 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Zwin
);
4914 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4915 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4916 if (mailbox
== ZO_V1
) {
4917 cy_writel(&((struct RUNTIME_9060
*)
4918 (cy_pci_addr0
))->loc_addr_base
, WIN_CREG
);
4920 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
4921 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
4922 (cy_pci_addr2
))->fpga_id
)),
4923 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
4924 (cy_pci_addr2
))->fpga_version
)));
4925 cy_writel(&((struct RUNTIME_9060
*)
4926 (cy_pci_addr0
))->loc_addr_base
, WIN_RAM
);
4928 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
4931 /* The following clears the firmware id word. This ensures
4932 that the driver will not attempt to talk to the board
4933 until it has been properly initialized.
4936 if ((mailbox
== ZO_V1
) || (mailbox
== ZO_V2
))
4937 cy_writel(cy_pci_addr2
+ ID_ADDRESS
, 0L);
4939 /* This must be a Cyclades-8Zo/PCI. The extendable
4940 version will have a different device_id and will
4941 be allocated its maximum number of ports. */
4944 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4945 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4946 (ulong
)cy_pci_phys2
);
4947 printk("but no channels are available.\n");
4948 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4952 /* fill the next cy_card structure available */
4953 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4954 if (cy_card
[j
].base_addr
== 0) break;
4956 if (j
== NR_CARDS
) { /* no more cy_cards available */
4957 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4958 (ulong
)cy_pci_phys2
);
4959 printk("but no more cards can be used.\n");
4960 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4964 #ifdef CONFIG_CYZ_INTR
4965 /* allocate IRQ only if board has an IRQ */
4966 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
4967 if(request_irq(cy_pci_irq
, cyz_interrupt
,
4968 IRQF_SHARED
, "Cyclades-Z", &cy_card
[j
]))
4970 printk("Cyclom-8Zo/PCI found at 0x%lx ",
4971 (ulong
) cy_pci_phys2
);
4972 printk("but could not allocate IRQ%d.\n",
4977 #endif /* CONFIG_CYZ_INTR */
4981 cy_card
[j
].base_phys
= cy_pci_phys2
;
4982 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
4983 cy_card
[j
].base_addr
= cy_pci_addr2
;
4984 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
4985 cy_card
[j
].irq
= (int) cy_pci_irq
;
4986 cy_card
[j
].bus_index
= 1;
4987 cy_card
[j
].first_line
= cy_next_channel
;
4988 cy_card
[j
].num_chips
= -1;
4989 cy_card
[j
].pdev
= pdev
;
4992 #ifdef CONFIG_CYZ_INTR
4993 /* don't report IRQ if board is no IRQ */
4994 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
4995 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4996 j
+1,(ulong
)cy_pci_phys2
,
4997 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1),
5000 #endif /* CONFIG_CYZ_INTR */
5001 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5002 j
+1,(ulong
)cy_pci_phys2
,
5003 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1));
5005 printk("%d channels starting from port %d.\n",
5006 cy_pci_nchan
,cy_next_channel
);
5007 cy_next_channel
+= cy_pci_nchan
;
5011 for (; ZeIndex
!= 0 && i
< NR_CARDS
; i
++) {
5012 cy_pci_phys0
= Ze_phys0
[0];
5013 cy_pci_phys2
= Ze_phys2
[0];
5014 cy_pci_addr0
= Ze_addr0
[0];
5015 cy_pci_addr2
= Ze_addr2
[0];
5016 cy_pci_irq
= Ze_irq
[0];
5018 for (j
= 0 ; j
< ZeIndex
-1 ; j
++) {
5019 Ze_phys0
[j
] = Ze_phys0
[j
+1];
5020 Ze_phys2
[j
] = Ze_phys2
[j
+1];
5021 Ze_addr0
[j
] = Ze_addr0
[j
+1];
5022 Ze_addr2
[j
] = Ze_addr2
[j
+1];
5023 Ze_irq
[j
] = Ze_irq
[j
+1];
5024 Ze_pdev
[j
] = Ze_pdev
[j
+1];
5027 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
5028 cy_pci_addr0
)->mail_box_0
);
5030 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5031 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5032 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5035 /* This must be the new Cyclades-Ze/PCI. */
5036 cy_pci_nchan
= ZE_V1_NPORTS
;
5038 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5039 printk("Cyclades-Ze/PCI found at 0x%lx ",
5040 (ulong
)cy_pci_phys2
);
5041 printk("but no channels are available.\n");
5042 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5046 /* fill the next cy_card structure available */
5047 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5048 if (cy_card
[j
].base_addr
== 0) break;
5050 if (j
== NR_CARDS
) { /* no more cy_cards available */
5051 printk("Cyclades-Ze/PCI found at 0x%lx ",
5052 (ulong
)cy_pci_phys2
);
5053 printk("but no more cards can be used.\n");
5054 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5058 #ifdef CONFIG_CYZ_INTR
5059 /* allocate IRQ only if board has an IRQ */
5060 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5061 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5062 IRQF_SHARED
, "Cyclades-Z", &cy_card
[j
]))
5064 printk("Cyclom-Ze/PCI found at 0x%lx ",
5065 (ulong
) cy_pci_phys2
);
5066 printk("but could not allocate IRQ%d.\n",
5071 #endif /* CONFIG_CYZ_INTR */
5074 cy_card
[j
].base_phys
= cy_pci_phys2
;
5075 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
5076 cy_card
[j
].base_addr
= cy_pci_addr2
;
5077 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5078 cy_card
[j
].irq
= (int) cy_pci_irq
;
5079 cy_card
[j
].bus_index
= 1;
5080 cy_card
[j
].first_line
= cy_next_channel
;
5081 cy_card
[j
].num_chips
= -1;
5082 cy_card
[j
].pdev
= pdev
;
5085 #ifdef CONFIG_CYZ_INTR
5086 /* don't report IRQ if board is no IRQ */
5087 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5088 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5089 j
+1,(ulong
)cy_pci_phys2
,
5090 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1),
5093 #endif /* CONFIG_CYZ_INTR */
5094 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5095 j
+1,(ulong
)cy_pci_phys2
,
5096 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1));
5098 printk("%d channels starting from port %d.\n",
5099 cy_pci_nchan
,cy_next_channel
);
5100 cy_next_channel
+= cy_pci_nchan
;
5103 printk("Cyclades-Ze/PCI found at 0x%x ",
5104 (unsigned int) Ze_phys2
[0]);
5105 printk("but no more cards can be used.\n");
5106 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5111 #endif /* ifdef CONFIG_PCI */
5112 } /* cy_detect_pci */
5116 * This routine prints out the appropriate serial driver version number
5117 * and identifies which options were configured into this driver.
5122 char *rcsvers
, *rcsdate
, *tmp
;
5123 rcsvers
= strchr(rcsid
, ' '); rcsvers
++;
5124 tmp
= strchr(rcsvers
, ' '); *tmp
++ = '\0';
5125 rcsdate
= strchr(tmp
, ' '); rcsdate
++;
5126 tmp
= strrchr(rcsdate
, ' '); *tmp
= '\0';
5127 printk("Cyclades driver %s %s\n",
5129 printk(" built %s %s\n",
5130 __DATE__
, __TIME__
);
5131 } /* show_version */
5134 cyclades_get_proc_info(char *buf
, char **start
, off_t offset
, int length
,
5135 int *eof
, void *data
)
5137 struct cyclades_port
*info
;
5143 __u32 cur_jifs
= jiffies
;
5145 size
= sprintf(buf
, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
5150 /* Output one line for each known port */
5151 for (i
= 0; i
< NR_PORTS
&& cy_port
[i
].line
>= 0; i
++) {
5155 size
= sprintf(buf
+len
,
5156 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5158 JIFFIES_DIFF(info
->idle_stats
.in_use
, cur_jifs
) / HZ
,
5159 info
->idle_stats
.xmit_bytes
,
5160 JIFFIES_DIFF(info
->idle_stats
.xmit_idle
, cur_jifs
) / HZ
,
5161 info
->idle_stats
.recv_bytes
,
5162 JIFFIES_DIFF(info
->idle_stats
.recv_idle
, cur_jifs
) / HZ
,
5163 info
->idle_stats
.overruns
,
5164 (long) info
->tty
->ldisc
.num
);
5166 size
= sprintf(buf
+len
,
5167 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5168 info
->line
, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5176 if (pos
> offset
+ length
)
5181 *start
= buf
+ (offset
- begin
); /* Start of wanted data */
5182 len
-= (offset
- begin
); /* Start slop */
5184 len
= length
; /* Ending slop */
5190 /* The serial driver boot-time initialization code!
5191 Hardware I/O ports are mapped to character special devices on a
5192 first found, first allocated manner. That is, this code searches
5193 for Cyclom cards in the system. As each is found, it is probed
5194 to discover how many chips (and thus how many ports) are present.
5195 These ports are mapped to the tty ports 32 and upward in monotonic
5196 fashion. If an 8-port card is replaced with a 16-port card, the
5197 port mapping on a following card will shift.
5199 This approach is different from what is used in the other serial
5200 device driver because the Cyclom is more properly a multiplexer,
5201 not just an aggregation of serial ports on one card.
5203 If there are more cards with more ports than have been
5204 statically allocated above, a warning is printed and the
5205 extra ports are ignored.
5208 static struct tty_operations cy_ops
= {
5212 .put_char
= cy_put_char
,
5213 .flush_chars
= cy_flush_chars
,
5214 .write_room
= cy_write_room
,
5215 .chars_in_buffer
= cy_chars_in_buffer
,
5216 .flush_buffer
= cy_flush_buffer
,
5218 .throttle
= cy_throttle
,
5219 .unthrottle
= cy_unthrottle
,
5220 .set_termios
= cy_set_termios
,
5223 .hangup
= cy_hangup
,
5224 .break_ctl
= cy_break
,
5225 .wait_until_sent
= cy_wait_until_sent
,
5226 .read_proc
= cyclades_get_proc_info
,
5227 .tiocmget
= cy_tiocmget
,
5228 .tiocmset
= cy_tiocmset
,
5234 struct cyclades_port
*info
;
5235 struct cyclades_card
*cinfo
;
5236 int number_z_boards
= 0;
5237 int board
,port
,i
,index
;
5238 unsigned long mailbox
;
5239 unsigned short chip_number
;
5242 cy_serial_driver
= alloc_tty_driver(NR_PORTS
);
5243 if (!cy_serial_driver
)
5247 /* Initialize the tty_driver structure */
5249 cy_serial_driver
->owner
= THIS_MODULE
;
5250 cy_serial_driver
->driver_name
= "cyclades";
5251 cy_serial_driver
->name
= "ttyC";
5252 cy_serial_driver
->major
= CYCLADES_MAJOR
;
5253 cy_serial_driver
->minor_start
= 0;
5254 cy_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
5255 cy_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
5256 cy_serial_driver
->init_termios
= tty_std_termios
;
5257 cy_serial_driver
->init_termios
.c_cflag
=
5258 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5259 cy_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
5260 tty_set_operations(cy_serial_driver
, &cy_ops
);
5262 if (tty_register_driver(cy_serial_driver
))
5263 panic("Couldn't register Cyclades serial driver\n");
5265 for (i
= 0; i
< NR_CARDS
; i
++) {
5266 /* base_addr=0 indicates board not found */
5267 cy_card
[i
].base_addr
= NULL
;
5270 /* the code below is responsible to find the boards. Each different
5271 type of board has its own detection routine. If a board is found,
5272 the next cy_card structure available is set by the detection
5273 routine. These functions are responsible for checking the
5274 availability of cy_card and cy_port data structures and updating
5275 the cy_next_channel. */
5277 /* look for isa boards */
5278 cy_isa_nboard
= cy_detect_isa();
5280 /* look for pci boards */
5281 cy_pci_nboard
= cy_detect_pci();
5283 cy_nboard
= cy_isa_nboard
+ cy_pci_nboard
;
5285 /* invalidate remaining cy_card structures */
5286 for (i
= 0 ; i
< NR_CARDS
; i
++) {
5287 if (cy_card
[i
].base_addr
== 0) {
5288 cy_card
[i
].first_line
= -1;
5289 cy_card
[i
].ctl_addr
= NULL
;
5291 cy_card
[i
].bus_index
= 0;
5292 cy_card
[i
].first_line
= 0;
5293 cy_card
[i
].num_chips
= 0;
5296 /* invalidate remaining cy_port structures */
5297 for (i
= cy_next_channel
; i
< NR_PORTS
; i
++) {
5298 cy_port
[i
].line
= -1;
5299 cy_port
[i
].magic
= -1;
5302 /* initialize per-port data structures for each valid board found */
5303 for (board
= 0 ; board
< cy_nboard
; board
++) {
5304 cinfo
= &cy_card
[board
];
5305 if (cinfo
->num_chips
== -1) { /* Cyclades-Z */
5307 mailbox
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
5308 cy_card
[board
].ctl_addr
)->mail_box_0
);
5309 nports
= (mailbox
== ZE_V1
) ? ZE_V1_NPORTS
: 8;
5310 cinfo
->intr_enabled
= 0;
5311 cinfo
->nports
= 0; /* Will be correctly set later, after
5313 spin_lock_init(&cinfo
->card_lock
);
5314 for (port
= cinfo
->first_line
;
5315 port
< cinfo
->first_line
+ nports
;
5318 info
= &cy_port
[port
];
5319 info
->magic
= CYCLADES_MAGIC
;
5320 info
->type
= PORT_STARTECH
;
5324 info
->flags
= STD_COM_FLAGS
;
5326 if (mailbox
== ZO_V1
)
5327 info
->xmit_fifo_size
= CYZ_FIFO_SIZE
;
5329 info
->xmit_fifo_size
= 4 * CYZ_FIFO_SIZE
;
5339 info
->custom_divisor
= 0;
5340 info
->close_delay
= 5*HZ
/10;
5341 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5342 info
->icount
.cts
= info
->icount
.dsr
=
5343 info
->icount
.rng
= info
->icount
.dcd
= 0;
5344 info
->icount
.rx
= info
->icount
.tx
= 0;
5345 info
->icount
.frame
= info
->icount
.parity
= 0;
5346 info
->icount
.overrun
= info
->icount
.brk
= 0;
5350 info
->blocked_open
= 0;
5351 info
->default_threshold
= 0;
5352 info
->default_timeout
= 0;
5353 INIT_WORK(&info
->tqueue
, do_softint
, info
);
5354 init_waitqueue_head(&info
->open_wait
);
5355 init_waitqueue_head(&info
->close_wait
);
5356 init_waitqueue_head(&info
->shutdown_wait
);
5357 init_waitqueue_head(&info
->delta_msr_wait
);
5360 info
->read_status_mask
= 0;
5362 /* Bentson's vars */
5363 info
->jiffies
[0] = 0;
5364 info
->jiffies
[1] = 0;
5365 info
->jiffies
[2] = 0;
5366 info
->rflush_count
= 0;
5367 #ifdef CONFIG_CYZ_INTR
5368 init_timer(&cyz_rx_full_timer
[port
]);
5369 cyz_rx_full_timer
[port
].function
= NULL
;
5373 }else{ /* Cyclom-Y of some kind*/
5374 index
= cinfo
->bus_index
;
5375 spin_lock_init(&cinfo
->card_lock
);
5376 cinfo
->nports
= CyPORTS_PER_CHIP
* cinfo
->num_chips
;
5377 for (port
= cinfo
->first_line
;
5378 port
< cinfo
->first_line
+ cinfo
->nports
;
5381 info
= &cy_port
[port
];
5382 info
->magic
= CYCLADES_MAGIC
;
5383 info
->type
= PORT_CIRRUS
;
5386 info
->flags
= STD_COM_FLAGS
;
5388 info
->xmit_fifo_size
= CyMAX_CHAR_FIFO
;
5389 info
->cor1
= CyPARITY_NONE
|Cy_1_STOP
|Cy_8_BITS
;
5391 info
->cor3
= 0x08; /* _very_ small rcv threshold */
5394 info
->custom_divisor
= 0;
5395 info
->close_delay
= 5*HZ
/10;
5396 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5397 info
->icount
.cts
= info
->icount
.dsr
=
5398 info
->icount
.rng
= info
->icount
.dcd
= 0;
5399 info
->icount
.rx
= info
->icount
.tx
= 0;
5400 info
->icount
.frame
= info
->icount
.parity
= 0;
5401 info
->icount
.overrun
= info
->icount
.brk
= 0;
5402 chip_number
= (port
- cinfo
->first_line
) / 4;
5403 if ((info
->chip_rev
=
5404 cy_readb(cinfo
->base_addr
+
5405 (cy_chip_offset
[chip_number
]<<index
) +
5406 (CyGFRCR
<<index
))) >= CD1400_REV_J
) {
5407 /* It is a CD1400 rev. J or later */
5408 info
->tbpr
= baud_bpr_60
[13]; /* Tx BPR */
5409 info
->tco
= baud_co_60
[13]; /* Tx CO */
5410 info
->rbpr
= baud_bpr_60
[13]; /* Rx BPR */
5411 info
->rco
= baud_co_60
[13]; /* Rx CO */
5413 info
->rtsdtr_inv
= 1;
5415 info
->tbpr
= baud_bpr_25
[13]; /* Tx BPR */
5416 info
->tco
= baud_co_25
[13]; /* Tx CO */
5417 info
->rbpr
= baud_bpr_25
[13]; /* Rx BPR */
5418 info
->rco
= baud_co_25
[13]; /* Rx CO */
5420 info
->rtsdtr_inv
= 0;
5425 info
->blocked_open
= 0;
5426 info
->default_threshold
= 0;
5427 info
->default_timeout
= 0;
5428 INIT_WORK(&info
->tqueue
, do_softint
, info
);
5429 init_waitqueue_head(&info
->open_wait
);
5430 init_waitqueue_head(&info
->close_wait
);
5431 init_waitqueue_head(&info
->shutdown_wait
);
5432 init_waitqueue_head(&info
->delta_msr_wait
);
5435 info
->read_status_mask
=
5436 CyTIMEOUT
| CySPECHAR
| CyBREAK
5437 | CyPARITY
| CyFRAME
| CyOVERRUN
;
5443 #ifndef CONFIG_CYZ_INTR
5444 if (number_z_boards
&& !cyz_timeron
){
5446 cyz_timerlist
.expires
= jiffies
+ 1;
5447 add_timer(&cyz_timerlist
);
5449 printk("Cyclades-Z polling initialized\n");
5452 #endif /* CONFIG_CYZ_INTR */
5459 cy_cleanup_module(void)
5463 #ifndef CONFIG_CYZ_INTR
5466 del_timer(&cyz_timerlist
);
5468 #endif /* CONFIG_CYZ_INTR */
5470 if ((e1
= tty_unregister_driver(cy_serial_driver
)))
5471 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5474 put_tty_driver(cy_serial_driver
);
5476 for (i
= 0; i
< NR_CARDS
; i
++) {
5477 if (cy_card
[i
].base_addr
) {
5478 iounmap(cy_card
[i
].base_addr
);
5479 if (cy_card
[i
].ctl_addr
)
5480 iounmap(cy_card
[i
].ctl_addr
);
5482 #ifndef CONFIG_CYZ_INTR
5483 && cy_card
[i
].num_chips
!= -1 /* not a Z card */
5484 #endif /* CONFIG_CYZ_INTR */
5486 free_irq(cy_card
[i
].irq
, &cy_card
[i
]);
5488 if (cy_card
[i
].pdev
)
5489 pci_release_regions(cy_card
[i
].pdev
);
5494 free_page((unsigned long) tmp_buf
);
5497 } /* cy_cleanup_module */
5499 module_init(cy_init
);
5500 module_exit(cy_cleanup_module
);
5502 MODULE_LICENSE("GPL");