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 explictly
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/config.h>
637 #include <linux/module.h>
638 #include <linux/errno.h>
639 #include <linux/signal.h>
640 #include <linux/sched.h>
641 #include <linux/timer.h>
642 #include <linux/interrupt.h>
643 #include <linux/tty.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>
656 #include <asm/system.h>
659 #include <asm/uaccess.h>
660 #include <asm/bitops.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 (sizeof(cy_isa_addresses)/sizeof(unsigned char*))
729 static long maddr
[NR_CARDS
] = { 0, };
730 static int irq
[NR_CARDS
] = { 0, };
732 MODULE_PARM(maddr
, "1-" __MODULE_STRING(NR_CARDS
) "l");
733 MODULE_PARM(irq
, "1-" __MODULE_STRING(NR_CARDS
) "i");
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
;
761 DECLARE_MUTEX(tmp_buf_sem
);
764 * This is used to look up the divisor speeds and the timeouts
765 * We're normally limited to 15 distinct baud rates. The extra
766 * are accessed via settings in info->flags.
767 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
768 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
772 static int baud_table
[] = {
773 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
774 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
777 static char baud_co_25
[] = { /* 25 MHz clock option table */
778 /* value => 00 01 02 03 04 */
779 /* divide by 8 32 128 512 2048 */
780 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
781 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
783 static char baud_bpr_25
[] = { /* 25 MHz baud rate period table */
784 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
785 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
787 static char baud_co_60
[] = { /* 60 MHz clock option table (CD1400 J) */
788 /* value => 00 01 02 03 04 */
789 /* divide by 8 32 128 512 2048 */
790 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
791 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
794 static char baud_bpr_60
[] = { /* 60 MHz baud rate period table (CD1400 J) */
795 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
796 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
799 static char baud_cor3
[] = { /* receive threshold */
800 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
801 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
805 * The Cyclades driver implements HW flow control as any serial driver.
806 * The cyclades_port structure member rflow and the vector rflow_thr
807 * allows us to take advantage of a special feature in the CD1400 to avoid
808 * data loss even when the system interrupt latency is too high. These flags
809 * are to be used only with very special applications. Setting these flags
810 * requires the use of a special cable (DTR and RTS reversed). In the new
811 * CD1400-based boards (rev. 6.00 or later), there is no need for special
815 static char rflow_thr
[] = { /* rflow threshold */
816 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
817 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
820 /* The Cyclom-Ye has placed the sequential chips in non-sequential
821 * address order. This look-up table overcomes that problem.
823 static int cy_chip_offset
[] =
834 /* PCI related definitions */
836 static unsigned short cy_pci_nboard
;
837 static unsigned short cy_isa_nboard
;
838 static unsigned short cy_nboard
;
840 static unsigned short cy_pci_dev_id
[] = {
841 PCI_DEVICE_ID_CYCLOM_Y_Lo
, /* PCI < 1Mb */
842 PCI_DEVICE_ID_CYCLOM_Y_Hi
, /* PCI > 1Mb */
843 PCI_DEVICE_ID_CYCLOM_4Y_Lo
, /* 4Y PCI < 1Mb */
844 PCI_DEVICE_ID_CYCLOM_4Y_Hi
, /* 4Y PCI > 1Mb */
845 PCI_DEVICE_ID_CYCLOM_8Y_Lo
, /* 8Y PCI < 1Mb */
846 PCI_DEVICE_ID_CYCLOM_8Y_Hi
, /* 8Y PCI > 1Mb */
847 PCI_DEVICE_ID_CYCLOM_Z_Lo
, /* Z PCI < 1Mb */
848 PCI_DEVICE_ID_CYCLOM_Z_Hi
, /* Z PCI > 1Mb */
853 static void cy_start(struct tty_struct
*);
854 static void set_line_char(struct cyclades_port
*);
855 static int cyz_issue_cmd(struct cyclades_card
*, uclong
, ucchar
, uclong
);
857 static unsigned detect_isa_irq(void __iomem
*);
858 #endif /* CONFIG_ISA */
860 static int cyclades_get_proc_info(char *, char **, off_t
, int , int *, void *);
862 #ifndef CONFIG_CYZ_INTR
863 static void cyz_poll(unsigned long);
865 /* The Cyclades-Z polling cycle is defined by this variable */
866 static long cyz_polling_cycle
= CZ_DEF_POLL
;
868 static int cyz_timeron
= 0;
869 static struct timer_list cyz_timerlist
= TIMER_INITIALIZER(cyz_poll
, 0, 0);
871 #else /* CONFIG_CYZ_INTR */
872 static void cyz_rx_restart(unsigned long);
873 static struct timer_list cyz_rx_full_timer
[NR_PORTS
];
874 #endif /* CONFIG_CYZ_INTR */
877 serial_paranoia_check(struct cyclades_port
*info
,
878 char *name
, const char *routine
)
880 #ifdef SERIAL_PARANOIA_CHECK
881 static const char *badmagic
=
882 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
883 static const char *badinfo
=
884 "cyc Warning: null cyclades_port for (%s) in %s\n";
885 static const char *badrange
=
886 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
889 printk(badinfo
, name
, routine
);
893 if( (long)info
< (long)(&cy_port
[0])
894 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
895 printk(badrange
, name
, routine
);
899 if (info
->magic
!= CYCLADES_MAGIC
) {
900 printk(badmagic
, name
, routine
);
905 } /* serial_paranoia_check */
908 * This routine is used by the interrupt handler to schedule
909 * processing in the software interrupt portion of the driver
910 * (also known as the "bottom half"). This can be called any
911 * number of times for any channel without harm.
914 cy_sched_event(struct cyclades_port
*info
, int event
)
916 info
->event
|= 1 << event
; /* remember what kind of event and who */
917 schedule_work(&info
->tqueue
);
918 } /* cy_sched_event */
922 * This routine is used to handle the "bottom half" processing for the
923 * serial driver, known also the "software interrupt" processing.
924 * This processing is done at the kernel interrupt level, after the
925 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
926 * is where time-consuming activities which can not be done in the
927 * interrupt driver proper are done; the interrupt driver schedules
928 * them using cy_sched_event(), and they get done here.
930 * This is done through one level of indirection--the task queue.
931 * When a hardware interrupt service routine wants service by the
932 * driver's bottom half, it enqueues the appropriate tq_struct (one
933 * per port) to the keventd work queue and sets a request flag
934 * that the work queue be processed.
936 * Although this may seem unwieldy, it gives the system a way to
937 * pass an argument (in this case the pointer to the cyclades_port
938 * structure) to the bottom half of the driver. Previous kernels
939 * had to poll every port to see if that port needed servicing.
942 do_softint(void *private_
)
944 struct cyclades_port
*info
= (struct cyclades_port
*) private_
;
945 struct tty_struct
*tty
;
951 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
952 tty_hangup(info
->tty
);
953 wake_up_interruptible(&info
->open_wait
);
954 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
956 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
957 wake_up_interruptible(&info
->open_wait
);
959 #ifdef CONFIG_CYZ_INTR
960 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL
, &info
->event
)) {
961 if (cyz_rx_full_timer
[info
->line
].function
== NULL
) {
962 cyz_rx_full_timer
[info
->line
].expires
= jiffies
+ 1;
963 cyz_rx_full_timer
[info
->line
].function
= cyz_rx_restart
;
964 cyz_rx_full_timer
[info
->line
].data
= (unsigned long)info
;
965 add_timer(&cyz_rx_full_timer
[info
->line
]);
969 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP
, &info
->event
)) {
970 wake_up_interruptible(&info
->delta_msr_wait
);
972 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
974 wake_up_interruptible(&tty
->write_wait
);
977 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP
, &info
->event
)) {
978 wake_up_interruptible(&info
->shutdown_wait
);
984 /***********************************************************/
985 /********* Start of block of Cyclom-Y specific code ********/
987 /* This routine waits up to 1000 micro-seconds for the previous
988 command to the Cirrus chip to complete and then issues the
989 new command. An error is returned if the previous command
990 didn't finish within the time limit.
992 This function is only called from inside spinlock-protected code.
995 cyy_issue_cmd(void __iomem
*base_addr
, u_char cmd
, int index
)
999 /* Check to see that the previous command has completed */
1000 for(i
= 0 ; i
< 100 ; i
++){
1001 if (cy_readb(base_addr
+(CyCCR
<<index
)) == 0){
1006 /* if the CCR never cleared, the previous command
1007 didn't finish within the "reasonable time" */
1008 if (i
== 100) return (-1);
1010 /* Issue the new command */
1011 cy_writeb(base_addr
+(CyCCR
<<index
), cmd
);
1014 } /* cyy_issue_cmd */
1017 /* ISA interrupt detection code */
1019 detect_isa_irq(void __iomem
*address
)
1022 unsigned long irqs
, flags
;
1023 int save_xir
, save_car
;
1024 int index
= 0; /* IRQ probing is only for ISA */
1026 /* forget possible initially masked and pending IRQ */
1027 irq
= probe_irq_off(probe_irq_on());
1029 /* Clear interrupts on the board first */
1030 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1031 /* Cy_ClrIntr is 0x1800 */
1033 irqs
= probe_irq_on();
1037 /* Enable the Tx interrupts on the CD1400 */
1038 local_irq_save(flags
);
1039 cy_writeb(address
+ (CyCAR
<<index
), 0);
1040 cyy_issue_cmd(address
, CyCHAN_CTL
|CyENB_XMTR
, index
);
1042 cy_writeb(address
+ (CyCAR
<<index
), 0);
1043 cy_writeb(address
+ (CySRER
<<index
),
1044 cy_readb(address
+ (CySRER
<<index
)) | CyTxRdy
);
1045 local_irq_restore(flags
);
1050 /* Check which interrupt is in use */
1051 irq
= probe_irq_off(irqs
);
1054 save_xir
= (u_char
) cy_readb(address
+ (CyTIR
<<index
));
1055 save_car
= cy_readb(address
+ (CyCAR
<<index
));
1056 cy_writeb(address
+ (CyCAR
<<index
), (save_xir
& 0x3));
1057 cy_writeb(address
+ (CySRER
<<index
),
1058 cy_readb(address
+ (CySRER
<<index
)) & ~CyTxRdy
);
1059 cy_writeb(address
+ (CyTIR
<<index
), (save_xir
& 0x3f));
1060 cy_writeb(address
+ (CyCAR
<<index
), (save_car
));
1061 cy_writeb(address
+ (Cy_ClrIntr
<<index
), 0);
1062 /* Cy_ClrIntr is 0x1800 */
1064 return (irq
> 0)? irq
: 0;
1066 #endif /* CONFIG_ISA */
1068 /* The real interrupt service routine is called
1069 whenever the card wants its hand held--chars
1070 received, out buffer empty, modem change, etc.
1073 cyy_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1075 struct tty_struct
*tty
;
1077 struct cyclades_card
*cinfo
;
1078 struct cyclades_port
*info
;
1079 void __iomem
*base_addr
, *card_base_addr
;
1081 int save_xir
, channel
, save_car
;
1083 volatile int char_count
;
1091 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1092 #ifdef CY_DEBUG_INTERRUPTS
1093 printk("cyy_interrupt: spurious interrupt %d\n\r", irq
);
1095 return IRQ_NONE
; /* spurious interrupt */
1098 card_base_addr
= cinfo
->base_addr
;
1099 index
= cinfo
->bus_index
;
1102 /* This loop checks all chips in the card. Make a note whenever
1103 _any_ chip had some work to do, as this is considered an
1104 indication that there will be more to do. Only when no chip
1105 has any work does this outermost loop exit.
1109 for ( chip
= 0 ; chip
< cinfo
->num_chips
; chip
++) {
1110 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
1112 while ( (status
= cy_readb(base_addr
+(CySVRR
<<index
))) != 0x00) {
1114 /* The purpose of the following test is to ensure that
1115 no chip can monopolize the driver. This forces the
1116 chips to be checked in a round-robin fashion (after
1117 draining each of a bunch (1000) of characters).
1119 if(1000<too_many
++){
1122 if (status
& CySRReceive
) { /* reception interrupt */
1123 #ifdef CY_DEBUG_INTERRUPTS
1124 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip
);
1126 /* determine the channel & change to that context */
1127 spin_lock(&cinfo
->card_lock
);
1128 save_xir
= (u_char
) cy_readb(base_addr
+(CyRIR
<<index
));
1129 channel
= (u_short
) (save_xir
& CyIRChannel
);
1130 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1132 info
->last_active
= jiffies
;
1133 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1134 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1136 /* if there is nowhere to put the data, discard it */
1138 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1139 if ( j
== CyIVRRxEx
) { /* exception */
1140 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1141 } else { /* normal character reception */
1142 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1143 while(char_count
--){
1144 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1147 }else{ /* there is an open port for this data */
1149 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1150 if ( j
== CyIVRRxEx
) { /* exception */
1151 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1153 /* For statistics only */
1156 else if(data
& CyFRAME
)
1157 info
->icount
.frame
++;
1158 else if(data
& CyPARITY
)
1159 info
->icount
.parity
++;
1160 else if(data
& CyOVERRUN
)
1161 info
->icount
.overrun
++;
1163 if(data
& info
->ignore_status_mask
){
1167 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
){
1169 if (data
& info
->read_status_mask
){
1171 *tty
->flip
.flag_buf_ptr
++ =
1173 *tty
->flip
.char_buf_ptr
++ =
1174 cy_readb(base_addr
+(CyRDSR
<<index
));
1176 if (info
->flags
& ASYNC_SAK
){
1179 }else if(data
& CyFRAME
){
1180 *tty
->flip
.flag_buf_ptr
++ =
1182 *tty
->flip
.char_buf_ptr
++ =
1183 cy_readb(base_addr
+(CyRDSR
<<index
));
1185 info
->idle_stats
.frame_errs
++;
1186 }else if(data
& CyPARITY
){
1187 *tty
->flip
.flag_buf_ptr
++ =
1189 *tty
->flip
.char_buf_ptr
++ =
1190 cy_readb(base_addr
+(CyRDSR
<<index
));
1192 info
->idle_stats
.parity_errs
++;
1193 }else if(data
& CyOVERRUN
){
1194 *tty
->flip
.flag_buf_ptr
++ =
1196 *tty
->flip
.char_buf_ptr
++ = 0;
1198 /* If the flip buffer itself is
1199 overflowing, we still lose
1200 the next incoming character.
1203 < TTY_FLIPBUF_SIZE
){
1205 *tty
->flip
.flag_buf_ptr
++ =
1207 *tty
->flip
.char_buf_ptr
++ =
1208 cy_readb(base_addr
+(CyRDSR
<<index
));
1211 info
->idle_stats
.overruns
++;
1212 /* These two conditions may imply */
1213 /* a normal read should be done. */
1214 /* }else if(data & CyTIMEOUT){ */
1215 /* }else if(data & CySPECHAR){ */
1217 *tty
->flip
.flag_buf_ptr
++ = 0;
1218 *tty
->flip
.char_buf_ptr
++ = 0;
1222 *tty
->flip
.flag_buf_ptr
++ = 0;
1223 *tty
->flip
.char_buf_ptr
++ = 0;
1227 /* there was a software buffer
1228 overrun and nothing could be
1230 info
->icount
.buf_overrun
++;
1231 info
->idle_stats
.overruns
++;
1233 } else { /* normal character reception */
1234 /* load # chars available from the chip */
1235 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1237 #ifdef CY_ENABLE_MONITORING
1238 ++info
->mon
.int_count
;
1239 info
->mon
.char_count
+= char_count
;
1240 if (char_count
> info
->mon
.char_max
)
1241 info
->mon
.char_max
= char_count
;
1242 info
->mon
.char_last
= char_count
;
1244 while(char_count
--){
1245 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
){
1249 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1250 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1251 *tty
->flip
.char_buf_ptr
++ = data
;
1252 info
->idle_stats
.recv_bytes
++;
1258 info
->idle_stats
.recv_idle
= jiffies
;
1260 schedule_delayed_work(&tty
->flip
.work
, 1);
1262 /* end of service */
1263 cy_writeb(base_addr
+(CyRIR
<<index
), (save_xir
& 0x3f));
1264 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1265 spin_unlock(&cinfo
->card_lock
);
1269 if (status
& CySRTransmit
) { /* transmission interrupt */
1270 /* Since we only get here when the transmit buffer
1271 is empty, we know we can always stuff a dozen
1273 #ifdef CY_DEBUG_INTERRUPTS
1274 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip
);
1277 /* determine the channel & change to that context */
1278 spin_lock(&cinfo
->card_lock
);
1279 save_xir
= (u_char
) cy_readb(base_addr
+(CyTIR
<<index
));
1280 channel
= (u_short
) (save_xir
& CyIRChannel
);
1281 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1282 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1283 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1285 /* validate the port# (as configured and open) */
1286 if( (i
< 0) || (NR_PORTS
<= i
) ){
1287 cy_writeb(base_addr
+(CySRER
<<index
),
1288 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1292 info
->last_active
= jiffies
;
1294 cy_writeb(base_addr
+(CySRER
<<index
),
1295 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
1299 /* load the on-chip space for outbound data */
1300 char_count
= info
->xmit_fifo_size
;
1302 if(info
->x_char
) { /* send special char */
1303 outch
= info
->x_char
;
1304 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1310 if (info
->breakon
|| info
->breakoff
) {
1311 if (info
->breakon
) {
1312 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1313 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x81);
1317 if (info
->breakoff
) {
1318 cy_writeb(base_addr
+ (CyTDR
<<index
), 0);
1319 cy_writeb(base_addr
+ (CyTDR
<<index
), 0x83);
1325 while (char_count
-- > 0){
1326 if (!info
->xmit_cnt
){
1327 if (cy_readb(base_addr
+(CySRER
<<index
))&CyTxMpty
) {
1328 cy_writeb(base_addr
+(CySRER
<<index
),
1329 cy_readb(base_addr
+(CySRER
<<index
)) &
1332 cy_writeb(base_addr
+(CySRER
<<index
),
1333 ((cy_readb(base_addr
+(CySRER
<<index
))
1339 if (info
->xmit_buf
== 0){
1340 cy_writeb(base_addr
+(CySRER
<<index
),
1341 cy_readb(base_addr
+(CySRER
<<index
)) &
1345 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
1346 cy_writeb(base_addr
+(CySRER
<<index
),
1347 cy_readb(base_addr
+(CySRER
<<index
)) &
1351 /* Because the Embedded Transmit Commands have
1352 been enabled, we must check to see if the
1353 escape character, NULL, is being sent. If it
1354 is, we must ensure that there is room for it
1355 to be doubled in the output stream. Therefore
1356 we no longer advance the pointer when the
1357 character is fetched, but rather wait until
1358 after the check for a NULL output character.
1359 This is necessary because there may not be
1360 room for the two chars needed to send a NULL.)
1362 outch
= info
->xmit_buf
[info
->xmit_tail
];
1365 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1366 & (SERIAL_XMIT_SIZE
- 1);
1367 cy_writeb(base_addr
+(CyTDR
<<index
), outch
);
1372 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1373 & (SERIAL_XMIT_SIZE
- 1);
1374 cy_writeb(base_addr
+(CyTDR
<<index
),
1376 cy_writeb(base_addr
+(CyTDR
<<index
), 0);
1385 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1386 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1389 /* end of service */
1390 cy_writeb(base_addr
+(CyTIR
<<index
),
1392 cy_writeb(base_addr
+(CyCAR
<<index
), (save_car
));
1393 spin_unlock(&cinfo
->card_lock
);
1396 if (status
& CySRModem
) { /* modem interrupt */
1398 /* determine the channel & change to that context */
1399 spin_lock(&cinfo
->card_lock
);
1400 save_xir
= (u_char
) cy_readb(base_addr
+(CyMIR
<<index
));
1401 channel
= (u_short
) (save_xir
& CyIRChannel
);
1402 info
= &cy_port
[channel
+ chip
* 4
1403 + cinfo
->first_line
];
1404 info
->last_active
= jiffies
;
1405 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1406 cy_writeb(base_addr
+(CyCAR
<<index
), save_xir
);
1408 mdm_change
= cy_readb(base_addr
+(CyMISR
<<index
));
1409 mdm_status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
1411 if(info
->tty
== 0){/* no place for data, ignore it*/
1414 if (mdm_change
& CyANY_DELTA
) {
1415 /* For statistics only */
1416 if (mdm_change
& CyDCD
) info
->icount
.dcd
++;
1417 if (mdm_change
& CyCTS
) info
->icount
.cts
++;
1418 if (mdm_change
& CyDSR
) info
->icount
.dsr
++;
1419 if (mdm_change
& CyRI
) info
->icount
.rng
++;
1421 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1424 if((mdm_change
& CyDCD
)
1425 && (info
->flags
& ASYNC_CHECK_CD
)){
1426 if(mdm_status
& CyDCD
){
1427 cy_sched_event(info
,
1428 Cy_EVENT_OPEN_WAKEUP
);
1430 cy_sched_event(info
,
1434 if((mdm_change
& CyCTS
)
1435 && (info
->flags
& ASYNC_CTS_FLOW
)){
1436 if(info
->tty
->hw_stopped
){
1437 if(mdm_status
& CyCTS
){
1438 /* cy_start isn't used
1440 info
->tty
->hw_stopped
= 0;
1441 cy_writeb(base_addr
+(CySRER
<<index
),
1442 cy_readb(base_addr
+(CySRER
<<index
)) |
1444 cy_sched_event(info
,
1445 Cy_EVENT_WRITE_WAKEUP
);
1448 if(!(mdm_status
& CyCTS
)){
1449 /* cy_stop isn't used
1451 info
->tty
->hw_stopped
= 1;
1452 cy_writeb(base_addr
+(CySRER
<<index
),
1453 cy_readb(base_addr
+(CySRER
<<index
)) &
1458 if(mdm_change
& CyDSR
){
1460 if(mdm_change
& CyRI
){
1463 /* end of service */
1464 cy_writeb(base_addr
+(CyMIR
<<index
),
1466 cy_writeb(base_addr
+(CyCAR
<<index
), save_car
);
1467 spin_unlock(&cinfo
->card_lock
);
1469 } /* end while status != 0 */
1470 } /* end loop for chips... */
1473 /* clear interrupts */
1474 spin_lock(&cinfo
->card_lock
);
1475 cy_writeb(card_base_addr
+ (Cy_ClrIntr
<<index
), 0);
1476 /* Cy_ClrIntr is 0x1800 */
1477 spin_unlock(&cinfo
->card_lock
);
1479 } /* cyy_interrupt */
1481 /***********************************************************/
1482 /********* End of block of Cyclom-Y specific code **********/
1483 /******** Start of block of Cyclades-Z specific code *********/
1484 /***********************************************************/
1487 cyz_fetch_msg( struct cyclades_card
*cinfo
,
1488 uclong
*channel
, ucchar
*cmd
, uclong
*param
)
1490 struct FIRM_ID __iomem
*firm_id
;
1491 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1492 struct BOARD_CTRL __iomem
*board_ctrl
;
1493 unsigned long loc_doorbell
;
1495 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1496 if (!ISZLOADED(*cinfo
)){
1499 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1500 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1502 loc_doorbell
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
1503 (cinfo
->ctl_addr
))->loc_doorbell
);
1505 *cmd
= (char)(0xff & loc_doorbell
);
1506 *channel
= cy_readl(&board_ctrl
->fwcmd_channel
);
1507 *param
= (uclong
)cy_readl(&board_ctrl
->fwcmd_param
);
1508 cy_writel(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->loc_doorbell
,
1513 } /* cyz_fetch_msg */
1516 cyz_issue_cmd( struct cyclades_card
*cinfo
,
1517 uclong channel
, ucchar cmd
, uclong param
)
1519 struct FIRM_ID __iomem
*firm_id
;
1520 struct ZFW_CTRL __iomem
*zfw_ctrl
;
1521 struct BOARD_CTRL __iomem
*board_ctrl
;
1522 unsigned long __iomem
*pci_doorbell
;
1525 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1526 if (!ISZLOADED(*cinfo
)){
1529 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1530 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1533 pci_doorbell
= &((struct RUNTIME_9060 __iomem
*) (cinfo
->ctl_addr
))->pci_doorbell
;
1534 while( (cy_readl(pci_doorbell
) & 0xff) != 0){
1535 if (index
++ == 1000){
1536 return((int)(cy_readl(pci_doorbell
) & 0xff));
1540 cy_writel(&board_ctrl
->hcmd_channel
, channel
);
1541 cy_writel(&board_ctrl
->hcmd_param
, param
);
1542 cy_writel(pci_doorbell
, (long)cmd
);
1545 } /* cyz_issue_cmd */
1548 cyz_handle_rx(struct cyclades_port
*info
,
1549 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1550 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1552 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1553 struct tty_struct
*tty
= info
->tty
;
1554 volatile int char_count
;
1560 volatile uclong rx_put
, rx_get
, new_rx_get
, rx_bufsize
, rx_bufaddr
;
1562 rx_get
= new_rx_get
= cy_readl(&buf_ctrl
->rx_get
);
1563 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1564 rx_bufsize
= cy_readl(&buf_ctrl
->rx_bufsize
);
1565 rx_bufaddr
= cy_readl(&buf_ctrl
->rx_bufaddr
);
1566 if (rx_put
>= rx_get
)
1567 char_count
= rx_put
- rx_get
;
1569 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1572 info
->last_active
= jiffies
;
1573 info
->jiffies
[1] = jiffies
;
1575 #ifdef CY_ENABLE_MONITORING
1576 info
->mon
.int_count
++;
1577 info
->mon
.char_count
+= char_count
;
1578 if (char_count
> info
->mon
.char_max
)
1579 info
->mon
.char_max
= char_count
;
1580 info
->mon
.char_last
= char_count
;
1583 /* flush received characters */
1584 new_rx_get
= (new_rx_get
+ char_count
) & (rx_bufsize
- 1);
1585 info
->rflush_count
++;
1588 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1589 for performance, but because of buffer boundaries, there
1590 may be several steps to the operation */
1591 while(0 < (small_count
=
1592 min_t(unsigned int, (rx_bufsize
- new_rx_get
),
1593 min_t(unsigned int, (TTY_FLIPBUF_SIZE
- tty
->flip
.count
), char_count
))
1595 memcpy_fromio(tty
->flip
.char_buf_ptr
,
1596 (char *)(cinfo
->base_addr
1597 + rx_bufaddr
+ new_rx_get
),
1600 tty
->flip
.char_buf_ptr
+= small_count
;
1601 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, small_count
);
1602 tty
->flip
.flag_buf_ptr
+= small_count
;
1603 new_rx_get
= (new_rx_get
+ small_count
) & (rx_bufsize
- 1);
1604 char_count
-= small_count
;
1605 info
->icount
.rx
+= small_count
;
1606 info
->idle_stats
.recv_bytes
+= small_count
;
1607 tty
->flip
.count
+= small_count
;
1610 while(char_count
--){
1611 if (tty
->flip
.count
>= N_TTY_BUF_SIZE
- tty
->read_cnt
)
1614 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
)
1617 data
= cy_readb(cinfo
->base_addr
+ rx_bufaddr
+ new_rx_get
);
1618 new_rx_get
= (new_rx_get
+ 1) & (rx_bufsize
- 1);
1620 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1621 *tty
->flip
.char_buf_ptr
++ = data
;
1622 info
->idle_stats
.recv_bytes
++;
1626 #ifdef CONFIG_CYZ_INTR
1627 /* Recalculate the number of chars in the RX buffer and issue
1628 a cmd in case it's higher than the RX high water mark */
1629 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1630 if (rx_put
>= rx_get
)
1631 char_count
= rx_put
- rx_get
;
1633 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1634 if(char_count
>= cy_readl(&buf_ctrl
->rx_threshold
)) {
1635 cy_sched_event(info
, Cy_EVENT_Z_RX_FULL
);
1638 info
->idle_stats
.recv_idle
= jiffies
;
1639 schedule_delayed_work(&tty
->flip
.work
, 1);
1642 cy_writel(&buf_ctrl
->rx_get
, new_rx_get
);
1647 cyz_handle_tx(struct cyclades_port
*info
,
1648 volatile struct CH_CTRL __iomem
*ch_ctrl
,
1649 volatile struct BUF_CTRL __iomem
*buf_ctrl
)
1651 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1652 struct tty_struct
*tty
= info
->tty
;
1654 volatile int char_count
;
1658 volatile uclong tx_put
, tx_get
, tx_bufsize
, tx_bufaddr
;
1660 if (info
->xmit_cnt
<= 0) /* Nothing to transmit */
1663 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
1664 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
1665 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
1666 tx_bufaddr
= cy_readl(&buf_ctrl
->tx_bufaddr
);
1667 if (tx_put
>= tx_get
)
1668 char_count
= tx_get
- tx_put
- 1 + tx_bufsize
;
1670 char_count
= tx_get
- tx_put
- 1;
1678 if(info
->x_char
) { /* send special char */
1679 data
= info
->x_char
;
1681 cy_writeb((cinfo
->base_addr
+ tx_bufaddr
+ tx_put
), data
);
1682 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1686 info
->last_active
= jiffies
;
1687 info
->jiffies
[2] = jiffies
;
1690 while(0 < (small_count
=
1691 min_t(unsigned int, (tx_bufsize
- tx_put
),
1692 min_t(unsigned int, (SERIAL_XMIT_SIZE
- info
->xmit_tail
),
1693 min_t(unsigned int, info
->xmit_cnt
, char_count
))))) {
1695 memcpy_toio((char *)(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
),
1696 &info
->xmit_buf
[info
->xmit_tail
],
1699 tx_put
= (tx_put
+ small_count
) & (tx_bufsize
- 1);
1700 char_count
-= small_count
;
1701 info
->icount
.tx
+= small_count
;
1702 info
->xmit_cnt
-= small_count
;
1704 (info
->xmit_tail
+ small_count
) & (SERIAL_XMIT_SIZE
- 1);
1705 info
->last_active
= jiffies
;
1706 info
->jiffies
[2] = jiffies
;
1709 while (info
->xmit_cnt
&& char_count
){
1710 data
= info
->xmit_buf
[info
->xmit_tail
];
1712 info
->xmit_tail
= (info
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
1714 cy_writeb(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
, data
);
1715 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1718 info
->last_active
= jiffies
;
1719 info
->jiffies
[2] = jiffies
;
1723 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1724 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1727 cy_writel(&buf_ctrl
->tx_put
, tx_put
);
1732 cyz_handle_cmd(struct cyclades_card
*cinfo
)
1734 struct tty_struct
*tty
;
1735 struct cyclades_port
*info
;
1736 static volatile struct FIRM_ID __iomem
*firm_id
;
1737 static volatile struct ZFW_CTRL __iomem
*zfw_ctrl
;
1738 static volatile struct BOARD_CTRL __iomem
*board_ctrl
;
1739 static volatile struct CH_CTRL __iomem
*ch_ctrl
;
1740 static volatile struct BUF_CTRL __iomem
*buf_ctrl
;
1744 uclong hw_ver
, fw_ver
;
1748 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1749 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1750 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1751 fw_ver
= cy_readl(&board_ctrl
->fw_version
);
1752 hw_ver
= cy_readl(&((struct RUNTIME_9060 __iomem
*)(cinfo
->ctl_addr
))->mail_box_0
);
1755 while(cyz_fetch_msg(cinfo
, &channel
, &cmd
, ¶m
) == 1) {
1758 info
= &cy_port
[channel
+ cinfo
->first_line
];
1759 if((tty
= info
->tty
) == 0) {
1762 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
1763 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
1768 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
1769 *tty
->flip
.char_buf_ptr
++ = 0;
1775 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
1776 *tty
->flip
.char_buf_ptr
++ = 0;
1782 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
1783 *tty
->flip
.char_buf_ptr
++ = 0;
1790 if (info
->flags
& ASYNC_CHECK_CD
){
1793 cy_readl(&ch_ctrl
->rs_status
)) & C_RS_DCD
) {
1794 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
1796 cy_sched_event(info
, Cy_EVENT_HANGUP
);
1814 cy_sched_event(info
, Cy_EVENT_SHUTDOWN_WAKEUP
);
1817 #ifdef CONFIG_CYZ_INTR
1821 /* Reception Interrupt */
1822 #ifdef CY_DEBUG_INTERRUPTS
1823 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
1824 info
->card
, channel
);
1826 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1831 /* Transmission Interrupt */
1832 #ifdef CY_DEBUG_INTERRUPTS
1833 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
1834 info
->card
, channel
);
1836 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1838 #endif /* CONFIG_CYZ_INTR */
1840 /* should do something with this !!! */
1846 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1848 schedule_delayed_work(&tty
->flip
.work
, 1);
1852 #ifdef CONFIG_CYZ_INTR
1854 cyz_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1856 struct cyclades_card
*cinfo
;
1858 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1859 #ifdef CY_DEBUG_INTERRUPTS
1860 printk("cyz_interrupt: spurious interrupt %d\n\r", irq
);
1862 return IRQ_NONE
; /* spurious interrupt */
1865 if (!ISZLOADED(*cinfo
)) {
1866 #ifdef CY_DEBUG_INTERRUPTS
1867 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq
);
1872 /* Handle the interrupts */
1873 cyz_handle_cmd(cinfo
);
1876 } /* cyz_interrupt */
1879 cyz_rx_restart(unsigned long arg
)
1881 struct cyclades_port
*info
= (struct cyclades_port
*)arg
;
1883 int card
= info
->card
;
1884 uclong channel
= (info
->line
) - (cy_card
[card
].first_line
);
1885 unsigned long flags
;
1887 CY_LOCK(info
, flags
);
1888 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK2
, 0L);
1890 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1891 info
->line
, retval
);
1893 cyz_rx_full_timer
[info
->line
].function
= NULL
;
1894 CY_UNLOCK(info
, flags
);
1897 #else /* CONFIG_CYZ_INTR */
1900 cyz_poll(unsigned long arg
)
1902 struct cyclades_card
*cinfo
;
1903 struct cyclades_port
*info
;
1904 struct tty_struct
*tty
;
1905 static volatile struct FIRM_ID
*firm_id
;
1906 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1907 static volatile struct BOARD_CTRL
*board_ctrl
;
1908 static volatile struct CH_CTRL
*ch_ctrl
;
1909 static volatile struct BUF_CTRL
*buf_ctrl
;
1912 cyz_timerlist
.expires
= jiffies
+ (HZ
);
1913 for (card
= 0 ; card
< NR_CARDS
; card
++){
1914 cinfo
= &cy_card
[card
];
1916 if (!IS_CYC_Z(*cinfo
)) continue;
1917 if (!ISZLOADED(*cinfo
)) continue;
1919 firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
1920 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
1921 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1923 /* Skip first polling cycle to avoid racing conditions with the FW */
1924 if (!cinfo
->intr_enabled
) {
1925 cinfo
->nports
= (int) cy_readl(&board_ctrl
->n_channel
);
1926 cinfo
->intr_enabled
= 1;
1930 cyz_handle_cmd(cinfo
);
1932 for (port
= 0 ; port
< cinfo
->nports
; port
++) {
1933 info
= &cy_port
[ port
+ cinfo
->first_line
];
1935 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[port
]);
1936 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[port
]);
1938 if (!info
->throttle
)
1939 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1940 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1942 /* poll every 'cyz_polling_cycle' period */
1943 cyz_timerlist
.expires
= jiffies
+ cyz_polling_cycle
;
1945 add_timer(&cyz_timerlist
);
1950 #endif /* CONFIG_CYZ_INTR */
1952 /********** End of block of Cyclades-Z specific code *********/
1953 /***********************************************************/
1956 /* This is called whenever a port becomes active;
1957 interrupts are enabled and DTR & RTS are turned on.
1960 startup(struct cyclades_port
* info
)
1962 unsigned long flags
;
1964 void __iomem
*base_addr
;
1965 int card
,chip
,channel
,index
;
1969 channel
= (info
->line
) - (cy_card
[card
].first_line
);
1971 page
= get_zeroed_page(GFP_KERNEL
);
1975 CY_LOCK(info
, flags
);
1977 if (info
->flags
& ASYNC_INITIALIZED
){
1984 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
1993 info
->xmit_buf
= (unsigned char *) page
;
1995 CY_UNLOCK(info
, flags
);
1997 set_line_char(info
);
1999 if (!IS_CYC_Z(cy_card
[card
])) {
2002 index
= cy_card
[card
].bus_index
;
2003 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2005 #ifdef CY_DEBUG_OPEN
2006 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
2007 card
, chip
, channel
, (long)base_addr
);/**/
2010 CY_LOCK(info
, flags
);
2012 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2014 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
2015 ? info
->default_timeout
: 0x02)); /* 10ms rx timeout */
2017 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyENB_RCVR
|CyENB_XMTR
,index
);
2019 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2020 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
2021 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
2024 printk("cyc:startup raising DTR\n");
2025 printk(" status: 0x%x, 0x%x\n",
2026 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2027 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2030 cy_writeb(base_addr
+(CySRER
<<index
),
2031 cy_readb(base_addr
+(CySRER
<<index
)) | CyRxData
);
2032 info
->flags
|= ASYNC_INITIALIZED
;
2035 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2037 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2038 info
->breakon
= info
->breakoff
= 0;
2039 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2040 info
->idle_stats
.in_use
=
2041 info
->idle_stats
.recv_idle
=
2042 info
->idle_stats
.xmit_idle
= jiffies
;
2044 CY_UNLOCK(info
, flags
);
2047 struct FIRM_ID __iomem
*firm_id
;
2048 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2049 struct BOARD_CTRL __iomem
*board_ctrl
;
2050 struct CH_CTRL __iomem
*ch_ctrl
;
2053 base_addr
= cy_card
[card
].base_addr
;
2055 firm_id
= base_addr
+ ID_ADDRESS
;
2056 if (!ISZLOADED(cy_card
[card
])){
2060 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2061 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2062 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2064 #ifdef CY_DEBUG_OPEN
2065 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2066 card
, channel
, (long)base_addr
);/**/
2069 CY_LOCK(info
, flags
);
2071 cy_writel(&ch_ctrl
[channel
].op_mode
, C_CH_ENABLE
);
2073 #ifdef CONFIG_CYZ_INTR
2074 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2075 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2079 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2082 #endif /* CONFIG_CYZ_INTR */
2084 #ifdef CONFIG_CYZ_INTR
2085 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2086 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2089 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2091 #endif /* CONFIG_CYZ_INTR */
2094 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
2096 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2097 info
->line
, retval
);
2100 /* Flush RX buffers before raising DTR and RTS */
2101 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_RX
, 0L);
2103 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2104 info
->line
, retval
);
2107 /* set timeout !!! */
2108 /* set RTS and DTR !!! */
2109 cy_writel(&ch_ctrl
[channel
].rs_control
,
2110 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
| C_RS_DTR
) ;
2111 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2112 channel
, C_CM_IOCTLM
, 0L);
2114 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2115 info
->line
, retval
);
2118 printk("cyc:startup raising Z DTR\n");
2121 /* enable send, recv, modem !!! */
2123 info
->flags
|= ASYNC_INITIALIZED
;
2125 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2127 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2128 info
->breakon
= info
->breakoff
= 0;
2129 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2130 info
->idle_stats
.in_use
=
2131 info
->idle_stats
.recv_idle
=
2132 info
->idle_stats
.xmit_idle
= jiffies
;
2134 CY_UNLOCK(info
, flags
);
2137 #ifdef CY_DEBUG_OPEN
2138 printk(" cyc startup done\n");
2143 CY_UNLOCK(info
, flags
);
2149 start_xmit( struct cyclades_port
*info
)
2151 unsigned long flags
;
2152 void __iomem
*base_addr
;
2153 int card
,chip
,channel
,index
;
2156 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2157 if (!IS_CYC_Z(cy_card
[card
])) {
2160 index
= cy_card
[card
].bus_index
;
2161 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2163 CY_LOCK(info
, flags
);
2164 cy_writeb(base_addr
+(CyCAR
<<index
), channel
);
2165 cy_writeb(base_addr
+(CySRER
<<index
),
2166 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
2167 CY_UNLOCK(info
, flags
);
2169 #ifdef CONFIG_CYZ_INTR
2172 CY_LOCK(info
, flags
);
2173 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK
, 0L);
2175 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2176 info
->line
, retval
);
2178 CY_UNLOCK(info
, flags
);
2179 #else /* CONFIG_CYZ_INTR */
2180 /* Don't have to do anything at this time */
2181 #endif /* CONFIG_CYZ_INTR */
2186 * This routine shuts down a serial port; interrupts are disabled,
2187 * and DTR is dropped if the hangup on close termio flag is on.
2190 shutdown(struct cyclades_port
* info
)
2192 unsigned long flags
;
2193 void __iomem
*base_addr
;
2194 int card
,chip
,channel
,index
;
2196 if (!(info
->flags
& ASYNC_INITIALIZED
)){
2201 channel
= info
->line
- cy_card
[card
].first_line
;
2202 if (!IS_CYC_Z(cy_card
[card
])) {
2205 index
= cy_card
[card
].bus_index
;
2206 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2208 #ifdef CY_DEBUG_OPEN
2209 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2210 card
, chip
, channel
, (long)base_addr
);
2213 CY_LOCK(info
, flags
);
2215 /* Clear delta_msr_wait queue to avoid mem leaks. */
2216 wake_up_interruptible(&info
->delta_msr_wait
);
2218 if (info
->xmit_buf
){
2219 unsigned char * temp
;
2220 temp
= info
->xmit_buf
;
2221 info
->xmit_buf
= NULL
;
2222 free_page((unsigned long) temp
);
2224 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2225 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2226 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
2227 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
2229 printk("cyc shutdown dropping DTR\n");
2230 printk(" status: 0x%x, 0x%x\n",
2231 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2232 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2235 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyDIS_RCVR
,index
);
2236 /* it may be appropriate to clear _XMIT at
2237 some later date (after testing)!!! */
2240 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2242 info
->flags
&= ~ASYNC_INITIALIZED
;
2243 CY_UNLOCK(info
, flags
);
2245 struct FIRM_ID __iomem
*firm_id
;
2246 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2247 struct BOARD_CTRL __iomem
*board_ctrl
;
2248 struct CH_CTRL __iomem
*ch_ctrl
;
2251 base_addr
= cy_card
[card
].base_addr
;
2252 #ifdef CY_DEBUG_OPEN
2253 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2254 card
, channel
, (long)base_addr
);
2257 firm_id
= base_addr
+ ID_ADDRESS
;
2258 if (!ISZLOADED(cy_card
[card
])) {
2262 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2263 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2264 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2266 CY_LOCK(info
, flags
);
2268 if (info
->xmit_buf
){
2269 unsigned char * temp
;
2270 temp
= info
->xmit_buf
;
2271 info
->xmit_buf
= NULL
;
2272 free_page((unsigned long) temp
);
2275 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2276 cy_writel(&ch_ctrl
[channel
].rs_control
,
2277 (uclong
)(cy_readl(&ch_ctrl
[channel
].rs_control
) &
2278 ~(C_RS_RTS
| C_RS_DTR
)));
2279 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2280 channel
, C_CM_IOCTLM
, 0L);
2282 printk("cyc:shutdown retval on ttyC%d was %x\n",
2283 info
->line
, retval
);
2286 printk("cyc:shutdown dropping Z DTR\n");
2291 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2293 info
->flags
&= ~ASYNC_INITIALIZED
;
2295 CY_UNLOCK(info
, flags
);
2298 #ifdef CY_DEBUG_OPEN
2299 printk(" cyc shutdown done\n");
2306 * ------------------------------------------------------------
2307 * cy_open() and friends
2308 * ------------------------------------------------------------
2312 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2313 struct cyclades_port
*info
)
2315 DECLARE_WAITQUEUE(wait
, current
);
2316 struct cyclades_card
*cinfo
;
2317 unsigned long flags
;
2318 int chip
, channel
,index
;
2320 void __iomem
*base_addr
;
2322 cinfo
= &cy_card
[info
->card
];
2323 channel
= info
->line
- cinfo
->first_line
;
2326 * If the device is in the middle of being closed, then block
2327 * until it's done, and then try again.
2329 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2330 if (info
->flags
& ASYNC_CLOSING
) {
2331 interruptible_sleep_on(&info
->close_wait
);
2333 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2337 * If non-blocking mode is set, then make the check up front
2340 if ((filp
->f_flags
& O_NONBLOCK
) ||
2341 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2342 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2347 * Block waiting for the carrier detect and the line to become
2348 * free (i.e., not in use by the callout). While we are in
2349 * this loop, info->count is dropped by one, so that
2350 * cy_close() knows when to free things. We restore it upon
2351 * exit, either normal or abnormal.
2354 add_wait_queue(&info
->open_wait
, &wait
);
2355 #ifdef CY_DEBUG_OPEN
2356 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2357 info
->line
, info
->count
);/**/
2359 CY_LOCK(info
, flags
);
2360 if (!tty_hung_up_p(filp
))
2362 CY_UNLOCK(info
, flags
);
2363 #ifdef CY_DEBUG_COUNT
2364 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2365 current
->pid
, info
->count
);
2367 info
->blocked_open
++;
2369 if (!IS_CYC_Z(*cinfo
)) {
2372 index
= cinfo
->bus_index
;
2373 base_addr
= cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
);
2376 CY_LOCK(info
, flags
);
2377 if ((tty
->termios
->c_cflag
& CBAUD
)){
2378 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2379 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
2380 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
2382 printk("cyc:block_til_ready raising DTR\n");
2383 printk(" status: 0x%x, 0x%x\n",
2384 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2385 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2388 CY_UNLOCK(info
, flags
);
2390 set_current_state(TASK_INTERRUPTIBLE
);
2391 if (tty_hung_up_p(filp
)
2392 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2393 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2394 -EAGAIN
: -ERESTARTSYS
);
2398 CY_LOCK(info
, flags
);
2399 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2400 if (!(info
->flags
& ASYNC_CLOSING
)
2402 || (cy_readb(base_addr
+(CyMSVR1
<<index
)) & CyDCD
))) {
2403 CY_UNLOCK(info
, flags
);
2406 CY_UNLOCK(info
, flags
);
2408 if (signal_pending(current
)) {
2409 retval
= -ERESTARTSYS
;
2412 #ifdef CY_DEBUG_OPEN
2413 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2414 info
->line
, info
->count
);/**/
2419 struct FIRM_ID __iomem
*firm_id
;
2420 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2421 struct BOARD_CTRL __iomem
*board_ctrl
;
2422 struct CH_CTRL __iomem
*ch_ctrl
;
2425 base_addr
= cinfo
->base_addr
;
2426 firm_id
= base_addr
+ ID_ADDRESS
;
2427 if (!ISZLOADED(*cinfo
)){
2428 current
->state
= TASK_RUNNING
;
2429 remove_wait_queue(&info
->open_wait
, &wait
);
2433 zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2434 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2435 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2438 if ((tty
->termios
->c_cflag
& CBAUD
)){
2439 cy_writel(&ch_ctrl
[channel
].rs_control
,
2440 cy_readl(&ch_ctrl
[channel
].rs_control
) |
2441 (C_RS_RTS
| C_RS_DTR
));
2442 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2443 channel
, C_CM_IOCTLM
, 0L);
2445 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2446 info
->line
, retval
);
2449 printk("cyc:block_til_ready raising Z DTR\n");
2453 set_current_state(TASK_INTERRUPTIBLE
);
2454 if (tty_hung_up_p(filp
)
2455 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2456 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2457 -EAGAIN
: -ERESTARTSYS
);
2460 if (!(info
->flags
& ASYNC_CLOSING
)
2462 || (cy_readl(&ch_ctrl
[channel
].rs_status
) & C_RS_DCD
))) {
2465 if (signal_pending(current
)) {
2466 retval
= -ERESTARTSYS
;
2469 #ifdef CY_DEBUG_OPEN
2470 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2471 info
->line
, info
->count
);/**/
2476 current
->state
= TASK_RUNNING
;
2477 remove_wait_queue(&info
->open_wait
, &wait
);
2478 if (!tty_hung_up_p(filp
)){
2480 #ifdef CY_DEBUG_COUNT
2481 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2482 current
->pid
, info
->count
);
2485 info
->blocked_open
--;
2486 #ifdef CY_DEBUG_OPEN
2487 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2488 info
->line
, info
->count
);/**/
2492 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2494 } /* block_til_ready */
2498 * This routine is called whenever a serial port is opened. It
2499 * performs the serial-specific initialization for the tty structure.
2502 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2504 struct cyclades_port
*info
;
2509 if ((line
< 0) || (NR_PORTS
<= line
)){
2512 info
= &cy_port
[line
];
2513 if (info
->line
< 0){
2517 /* If the card's firmware hasn't been loaded,
2518 treat it as absent from the system. This
2519 will make the user pay attention.
2521 if (IS_CYC_Z(cy_card
[info
->card
])) {
2522 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
2523 struct FIRM_ID __iomem
*firm_id
= cinfo
->base_addr
+ ID_ADDRESS
;
2525 if (!ISZLOADED(*cinfo
)) {
2526 if (((ZE_V1
==cy_readl(&((struct RUNTIME_9060 __iomem
*)
2527 (cinfo
->ctl_addr
))->mail_box_0
)) &&
2528 Z_FPGA_CHECK (*cinfo
)) &&
2529 (ZFIRM_HLT
== cy_readl (&firm_id
->signature
)))
2531 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2533 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2537 #ifdef CONFIG_CYZ_INTR
2539 /* In case this Z board is operating in interrupt mode, its
2540 interrupts should be enabled as soon as the first open happens
2541 to one of its ports. */
2542 if (!cinfo
->intr_enabled
) {
2543 struct ZFW_CTRL __iomem
*zfw_ctrl
;
2544 struct BOARD_CTRL __iomem
*board_ctrl
;
2546 zfw_ctrl
= cinfo
->base_addr
+ (cy_readl (&firm_id
->zfwctrl_addr
) & 0xfffff);
2548 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2550 /* Enable interrupts on the PLX chip */
2551 cy_writew(cinfo
->ctl_addr
+0x68,
2552 cy_readw(cinfo
->ctl_addr
+0x68)|0x0900);
2553 /* Enable interrupts on the FW */
2554 retval
= cyz_issue_cmd(cinfo
,
2555 0, C_CM_IRQ_ENBL
, 0L);
2557 printk("cyc:IRQ enable retval was %x\n", retval
);
2559 cinfo
->nports
= (int) cy_readl (&board_ctrl
->n_channel
);
2560 cinfo
->intr_enabled
= 1;
2563 #endif /* CONFIG_CYZ_INTR */
2564 /* Make sure this Z port really exists in hardware */
2565 if (info
->line
> (cinfo
->first_line
+ cinfo
->nports
- 1))
2568 #ifdef CY_DEBUG_OTHER
2569 printk("cyc:cy_open ttyC%d\n", info
->line
); /* */
2571 tty
->driver_data
= info
;
2573 if (serial_paranoia_check(info
, tty
->name
, "cy_open")){
2576 #ifdef CY_DEBUG_OPEN
2577 printk("cyc:cy_open ttyC%d, count = %d\n",
2578 info
->line
, info
->count
);/**/
2581 #ifdef CY_DEBUG_COUNT
2582 printk("cyc:cy_open (%d): incrementing count to %d\n",
2583 current
->pid
, info
->count
);
2586 page
= get_zeroed_page(GFP_KERNEL
);
2592 tmp_buf
= (unsigned char *) page
;
2596 * If the port is the middle of closing, bail out now
2598 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2599 if (info
->flags
& ASYNC_CLOSING
)
2600 interruptible_sleep_on(&info
->close_wait
);
2601 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2605 * Start up serial port
2607 retval
= startup(info
);
2612 retval
= block_til_ready(tty
, filp
, info
);
2614 #ifdef CY_DEBUG_OPEN
2615 printk("cyc:cy_open returning after block_til_ready with %d\n",
2623 #ifdef CY_DEBUG_OPEN
2624 printk(" cyc:cy_open done\n");/**/
2632 * cy_wait_until_sent() --- wait until the transmitter is empty
2635 cy_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2637 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
2638 void __iomem
*base_addr
;
2639 int card
,chip
,channel
,index
;
2640 unsigned long orig_jiffies
;
2643 if (serial_paranoia_check(info
, tty
->name
, "cy_wait_until_sent"))
2646 if (info
->xmit_fifo_size
== 0)
2647 return; /* Just in case.... */
2650 orig_jiffies
= jiffies
;
2652 * Set the check interval to be 1/5 of the estimated time to
2653 * send a single character, and make it at least 1. The check
2654 * interval should also be less than the timeout.
2656 * Note: we have to use pretty tight timings here to satisfy
2659 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2660 char_time
= char_time
/ 5;
2666 char_time
= min(char_time
, timeout
);
2668 * If the transmitter hasn't cleared in twice the approximate
2669 * amount of time to send the entire FIFO, it probably won't
2670 * ever clear. This assumes the UART isn't doing flow
2671 * control, which is currently the case. Hence, if it ever
2672 * takes longer than info->timeout, this is probably due to a
2673 * UART bug of some kind. So, we clamp the timeout parameter at
2676 if (!timeout
|| timeout
> 2*info
->timeout
)
2677 timeout
= 2*info
->timeout
;
2678 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2679 printk("In cy_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2680 printk("jiff=%lu...", jiffies
);
2683 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2684 if (!IS_CYC_Z(cy_card
[card
])) {
2687 index
= cy_card
[card
].bus_index
;
2688 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
2689 while (cy_readb(base_addr
+(CySRER
<<index
)) & CyTxRdy
) {
2690 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2691 printk("Not clean (jiff=%lu)...", jiffies
);
2693 current
->state
= TASK_INTERRUPTIBLE
;
2694 schedule_timeout(char_time
);
2695 if (signal_pending(current
))
2697 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2700 current
->state
= TASK_RUNNING
;
2704 /* Run one more char cycle */
2705 current
->state
= TASK_INTERRUPTIBLE
;
2706 schedule_timeout(char_time
* 5);
2707 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2708 printk("Clean (jiff=%lu)...done\n", jiffies
);
2713 * This routine is called when a particular tty device is closed.
2716 cy_close(struct tty_struct
*tty
, struct file
*filp
)
2718 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2719 unsigned long flags
;
2721 #ifdef CY_DEBUG_OTHER
2722 printk("cyc:cy_close ttyC%d\n", info
->line
);
2725 if (!info
|| serial_paranoia_check(info
, tty
->name
, "cy_close")){
2729 CY_LOCK(info
, flags
);
2730 /* If the TTY is being hung up, nothing to do */
2731 if (tty_hung_up_p(filp
)) {
2732 CY_UNLOCK(info
, flags
);
2736 #ifdef CY_DEBUG_OPEN
2737 printk("cyc:cy_close ttyC%d, count = %d\n", info
->line
, info
->count
);
2739 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2741 * Uh, oh. tty->count is 1, which means that the tty
2742 * structure will be freed. Info->count should always
2743 * be one in these conditions. If it's greater than
2744 * one, we've got real problems, since it means the
2745 * serial port won't be shutdown.
2747 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2748 "info->count is %d\n", info
->count
);
2751 #ifdef CY_DEBUG_COUNT
2752 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2753 current
->pid
, info
->count
- 1);
2755 if (--info
->count
< 0) {
2756 #ifdef CY_DEBUG_COUNT
2757 printk("cyc:cyc_close setting count to 0\n");
2762 CY_UNLOCK(info
, flags
);
2765 info
->flags
|= ASYNC_CLOSING
;
2768 * Now we wait for the transmit buffer to clear; and we notify
2769 * the line discipline to only process XON/XOFF characters.
2772 CY_UNLOCK(info
, flags
);
2773 if (info
->closing_wait
!= CY_CLOSING_WAIT_NONE
) {
2774 tty_wait_until_sent(tty
, info
->closing_wait
);
2776 CY_LOCK(info
, flags
);
2778 if (!IS_CYC_Z(cy_card
[info
->card
])) {
2779 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2780 int index
= cy_card
[info
->card
].bus_index
;
2781 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[channel
>>2] << index
);
2782 /* Stop accepting input */
2784 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2785 cy_writeb(base_addr
+(CySRER
<<index
),
2786 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyRxData
);
2787 if (info
->flags
& ASYNC_INITIALIZED
) {
2788 /* Waiting for on-board buffers to be empty before closing
2790 CY_UNLOCK(info
, flags
);
2791 cy_wait_until_sent(tty
, info
->timeout
);
2792 CY_LOCK(info
, flags
);
2796 /* Waiting for on-board buffers to be empty before closing the port */
2797 void __iomem
*base_addr
= cy_card
[info
->card
].base_addr
;
2798 struct FIRM_ID __iomem
*firm_id
= base_addr
+ ID_ADDRESS
;
2799 struct ZFW_CTRL __iomem
*zfw_ctrl
= base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
2800 struct CH_CTRL __iomem
*ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2801 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2804 if (cy_readl(&ch_ctrl
[channel
].flow_status
) != C_FS_TXIDLE
) {
2805 retval
= cyz_issue_cmd(&cy_card
[info
->card
], channel
,
2808 printk("cyc:cy_close retval on ttyC%d was %x\n",
2809 info
->line
, retval
);
2811 CY_UNLOCK(info
, flags
);
2812 interruptible_sleep_on(&info
->shutdown_wait
);
2813 CY_LOCK(info
, flags
);
2818 CY_UNLOCK(info
, flags
);
2820 if (tty
->driver
->flush_buffer
)
2821 tty
->driver
->flush_buffer(tty
);
2822 tty_ldisc_flush(tty
);
2823 CY_LOCK(info
, flags
);
2828 if (info
->blocked_open
) {
2829 CY_UNLOCK(info
, flags
);
2830 if (info
->close_delay
) {
2831 current
->state
= TASK_INTERRUPTIBLE
;
2832 schedule_timeout(info
->close_delay
);
2834 wake_up_interruptible(&info
->open_wait
);
2835 CY_LOCK(info
, flags
);
2837 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
2838 wake_up_interruptible(&info
->close_wait
);
2840 #ifdef CY_DEBUG_OTHER
2841 printk(" cyc:cy_close done\n");
2844 CY_UNLOCK(info
, flags
);
2849 /* This routine gets called when tty_write has put something into
2850 * the write_queue. The characters may come from user space or
2853 * This routine will return the number of characters actually
2854 * accepted for writing.
2856 * If the port is not already transmitting stuff, start it off by
2857 * enabling interrupts. The interrupt service routine will then
2858 * ensure that the characters are sent.
2859 * If the port is already active, there is no need to kick it.
2863 cy_write(struct tty_struct
* tty
, int from_user
,
2864 const unsigned char *buf
, int count
)
2866 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2867 unsigned long flags
;
2871 printk("cyc:cy_write ttyC%d\n", info
->line
); /* */
2874 if (serial_paranoia_check(info
, tty
->name
, "cy_write")){
2878 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
){
2887 c
= min(count
, min((int)(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1),
2888 (int)(SERIAL_XMIT_SIZE
- info
->xmit_head
)));
2892 c
-= copy_from_user(tmp_buf
, buf
, c
);
2899 CY_LOCK(info
, flags
);
2900 c1
= min(c
, min((int)(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1),
2901 (int)(SERIAL_XMIT_SIZE
- info
->xmit_head
)));
2905 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
2906 info
->xmit_head
= ((info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1));
2907 info
->xmit_cnt
+= c
;
2908 CY_UNLOCK(info
, flags
);
2915 CY_LOCK(info
, flags
);
2917 c
= min(count
, min((int)(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1),
2918 (int)(SERIAL_XMIT_SIZE
- info
->xmit_head
)));
2923 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
2924 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
2925 info
->xmit_cnt
+= c
;
2930 CY_UNLOCK(info
, flags
);
2933 info
->idle_stats
.xmit_bytes
+= ret
;
2934 info
->idle_stats
.xmit_idle
= jiffies
;
2936 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
2944 * This routine is called by the kernel to write a single
2945 * character to the tty device. If the kernel uses this routine,
2946 * it must call the flush_chars() routine (if defined) when it is
2947 * done stuffing characters into the driver. If there is no room
2948 * in the queue, the character is ignored.
2951 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
2953 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2954 unsigned long flags
;
2957 printk("cyc:cy_put_char ttyC%d\n", info
->line
);
2960 if (serial_paranoia_check(info
, tty
->name
, "cy_put_char"))
2963 if (!tty
|| !info
->xmit_buf
)
2966 CY_LOCK(info
, flags
);
2967 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
2968 CY_UNLOCK(info
, flags
);
2972 info
->xmit_buf
[info
->xmit_head
++] = ch
;
2973 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
2975 info
->idle_stats
.xmit_bytes
++;
2976 info
->idle_stats
.xmit_idle
= jiffies
;
2977 CY_UNLOCK(info
, flags
);
2982 * This routine is called by the kernel after it has written a
2983 * series of characters to the tty device using put_char().
2986 cy_flush_chars(struct tty_struct
*tty
)
2988 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2991 printk("cyc:cy_flush_chars ttyC%d\n", info
->line
); /* */
2994 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_chars"))
2997 if (info
->xmit_cnt
<= 0 || tty
->stopped
2998 || tty
->hw_stopped
|| !info
->xmit_buf
)
3002 } /* cy_flush_chars */
3006 * This routine returns the numbers of characters the tty driver
3007 * will accept for queuing to be written. This number is subject
3008 * to change as output buffers get emptied, or if the output flow
3009 * control is activated.
3012 cy_write_room(struct tty_struct
*tty
)
3014 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3018 printk("cyc:cy_write_room ttyC%d\n", info
->line
); /* */
3021 if (serial_paranoia_check(info
, tty
->name
, "cy_write_room"))
3023 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
3027 } /* cy_write_room */
3031 cy_chars_in_buffer(struct tty_struct
*tty
)
3033 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3036 if (serial_paranoia_check(info
, tty
->name
, "cy_chars_in_buffer"))
3040 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3042 #ifdef Z_EXT_CHARS_IN_BUFFER
3043 if (!IS_CYC_Z(cy_card
[card
])) {
3044 #endif /* Z_EXT_CHARS_IN_BUFFER */
3046 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3047 info
->line
, info
->xmit_cnt
); /* */
3049 return info
->xmit_cnt
;
3050 #ifdef Z_EXT_CHARS_IN_BUFFER
3052 static volatile struct FIRM_ID
*firm_id
;
3053 static volatile struct ZFW_CTRL
*zfw_ctrl
;
3054 static volatile struct CH_CTRL
*ch_ctrl
;
3055 static volatile struct BUF_CTRL
*buf_ctrl
;
3057 volatile uclong tx_put
, tx_get
, tx_bufsize
;
3059 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3060 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3061 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3062 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
3064 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
3065 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
3066 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
3067 if (tx_put
>= tx_get
)
3068 char_count
= tx_put
- tx_get
;
3070 char_count
= tx_put
- tx_get
+ tx_bufsize
;
3072 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3073 info
->line
, info
->xmit_cnt
+ char_count
); /* */
3075 return (info
->xmit_cnt
+ char_count
);
3077 #endif /* Z_EXT_CHARS_IN_BUFFER */
3078 } /* cy_chars_in_buffer */
3082 * ------------------------------------------------------------
3083 * cy_ioctl() and friends
3084 * ------------------------------------------------------------
3088 cyy_baud_calc(struct cyclades_port
*info
, uclong baud
)
3090 int co
, co_val
, bpr
;
3091 uclong cy_clock
= ((info
->chip_rev
>= CD1400_REV_J
) ? 60000000 : 25000000);
3094 info
->tbpr
= info
->tco
= info
->rbpr
= info
->rco
= 0;
3098 /* determine which prescaler to use */
3099 for (co
= 4, co_val
= 2048; co
; co
--, co_val
>>= 2) {
3100 if (cy_clock
/ co_val
/ baud
> 63)
3104 bpr
= (cy_clock
/ co_val
* 2 / baud
+ 1) / 2;
3108 info
->tbpr
= info
->rbpr
= bpr
;
3109 info
->tco
= info
->rco
= co
;
3113 * This routine finds or computes the various line characteristics.
3114 * It used to be called config_setup
3117 set_line_char(struct cyclades_port
* info
)
3119 unsigned long flags
;
3120 void __iomem
*base_addr
;
3121 int card
,chip
,channel
,index
;
3122 unsigned cflag
, iflag
;
3123 unsigned short chip_number
;
3124 int baud
, baud_rate
= 0;
3128 if (!info
->tty
|| !info
->tty
->termios
){
3131 if (info
->line
== -1){
3134 cflag
= info
->tty
->termios
->c_cflag
;
3135 iflag
= info
->tty
->termios
->c_iflag
;
3138 * Set up the tty->alt_speed kludge
3141 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3142 info
->tty
->alt_speed
= 57600;
3143 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3144 info
->tty
->alt_speed
= 115200;
3145 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3146 info
->tty
->alt_speed
= 230400;
3147 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3148 info
->tty
->alt_speed
= 460800;
3152 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3153 chip_number
= channel
/ 4;
3155 if (!IS_CYC_Z(cy_card
[card
])) {
3157 index
= cy_card
[card
].bus_index
;
3160 baud
= tty_get_baud_rate(info
->tty
);
3161 if ((baud
== 38400) &&
3162 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3163 if (info
->custom_divisor
)
3164 baud_rate
= info
->baud
/ info
->custom_divisor
;
3166 baud_rate
= info
->baud
;
3167 } else if (baud
> CD1400_MAX_SPEED
) {
3168 baud
= CD1400_MAX_SPEED
;
3170 /* find the baud index */
3171 for (i
= 0; i
< 20; i
++) {
3172 if (baud
== baud_table
[i
]) {
3177 i
= 19; /* CD1400_MAX_SPEED */
3180 if ((baud
== 38400) &&
3181 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3182 cyy_baud_calc(info
, baud_rate
);
3184 if(info
->chip_rev
>= CD1400_REV_J
) {
3185 /* It is a CD1400 rev. J or later */
3186 info
->tbpr
= baud_bpr_60
[i
]; /* Tx BPR */
3187 info
->tco
= baud_co_60
[i
]; /* Tx CO */
3188 info
->rbpr
= baud_bpr_60
[i
]; /* Rx BPR */
3189 info
->rco
= baud_co_60
[i
]; /* Rx CO */
3191 info
->tbpr
= baud_bpr_25
[i
]; /* Tx BPR */
3192 info
->tco
= baud_co_25
[i
]; /* Tx CO */
3193 info
->rbpr
= baud_bpr_25
[i
]; /* Rx BPR */
3194 info
->rco
= baud_co_25
[i
]; /* Rx CO */
3197 if (baud_table
[i
] == 134) {
3198 /* get it right for 134.5 baud */
3199 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3200 } else if ((baud
== 38400) &&
3201 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3202 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3203 } else if (baud_table
[i
]) {
3204 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
3205 /* this needs to be propagated into the card info */
3209 /* By tradition (is it a standard?) a baud rate of zero
3210 implies the line should be/has been closed. A bit
3211 later in this routine such a test is performed. */
3213 /* byte size and parity */
3216 info
->cor3
= (info
->default_threshold
3217 ? info
->default_threshold
3218 : baud_cor3
[i
]); /* receive threshold */
3220 switch(cflag
& CSIZE
){
3222 info
->cor1
= Cy_5_BITS
;
3225 info
->cor1
= Cy_6_BITS
;
3228 info
->cor1
= Cy_7_BITS
;
3231 info
->cor1
= Cy_8_BITS
;
3235 info
->cor1
|= Cy_2_STOP
;
3237 if (cflag
& PARENB
){
3238 if (cflag
& PARODD
){
3239 info
->cor1
|= CyPARITY_O
;
3241 info
->cor1
|= CyPARITY_E
;
3244 info
->cor1
|= CyPARITY_NONE
;
3247 /* CTS flow control flag */
3248 if (cflag
& CRTSCTS
){
3249 info
->flags
|= ASYNC_CTS_FLOW
;
3250 info
->cor2
|= CyCtsAE
;
3252 info
->flags
&= ~ASYNC_CTS_FLOW
;
3253 info
->cor2
&= ~CyCtsAE
;
3256 info
->flags
&= ~ASYNC_CHECK_CD
;
3258 info
->flags
|= ASYNC_CHECK_CD
;
3260 /***********************************************
3261 The hardware option, CyRtsAO, presents RTS when
3262 the chip has characters to send. Since most modems
3263 use RTS as reverse (inbound) flow control, this
3264 option is not used. If inbound flow control is
3265 necessary, DTR can be programmed to provide the
3266 appropriate signals for use with a non-standard
3267 cable. Contact Marcio Saito for details.
3268 ***********************************************/
3272 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3274 CY_LOCK(info
, flags
);
3275 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3277 /* tx and rx baud rate */
3279 cy_writeb(base_addr
+(CyTCOR
<<index
), info
->tco
);
3280 cy_writeb(base_addr
+(CyTBPR
<<index
), info
->tbpr
);
3281 cy_writeb(base_addr
+(CyRCOR
<<index
), info
->rco
);
3282 cy_writeb(base_addr
+(CyRBPR
<<index
), info
->rbpr
);
3284 /* set line characteristics according configuration */
3286 cy_writeb(base_addr
+(CySCHR1
<<index
),
3287 START_CHAR(info
->tty
));
3288 cy_writeb(base_addr
+(CySCHR2
<<index
),
3289 STOP_CHAR(info
->tty
));
3290 cy_writeb(base_addr
+(CyCOR1
<<index
), info
->cor1
);
3291 cy_writeb(base_addr
+(CyCOR2
<<index
), info
->cor2
);
3292 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3293 cy_writeb(base_addr
+(CyCOR4
<<index
), info
->cor4
);
3294 cy_writeb(base_addr
+(CyCOR5
<<index
), info
->cor5
);
3296 cyy_issue_cmd(base_addr
,
3297 CyCOR_CHANGE
|CyCOR1ch
|CyCOR2ch
|CyCOR3ch
,index
);
3299 cy_writeb(base_addr
+(CyCAR
<<index
),
3300 (u_char
)channel
); /* !!! Is this needed? */
3301 cy_writeb(base_addr
+(CyRTPR
<<index
), (info
->default_timeout
3302 ? info
->default_timeout
3303 : 0x02)); /* 10ms rx timeout */
3305 if (C_CLOCAL(info
->tty
)) {
3306 /* without modem intr */
3307 cy_writeb(base_addr
+(CySRER
<<index
),
3308 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3309 /* act on 1->0 modem transitions */
3310 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3311 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3312 (CyCTS
|rflow_thr
[i
]));
3314 cy_writeb(base_addr
+(CyMCOR1
<<index
), CyCTS
);
3316 /* act on 0->1 modem transitions */
3317 cy_writeb(base_addr
+(CyMCOR2
<<index
), CyCTS
);
3319 /* without modem intr */
3320 cy_writeb(base_addr
+(CySRER
<<index
),
3321 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3322 /* act on 1->0 modem transitions */
3323 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3324 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3325 (CyDSR
|CyCTS
|CyRI
|CyDCD
|rflow_thr
[i
]));
3327 cy_writeb(base_addr
+(CyMCOR1
<<index
),
3328 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3330 /* act on 0->1 modem transitions */
3331 cy_writeb(base_addr
+(CyMCOR2
<<index
),
3332 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3335 if(i
== 0){ /* baud rate is zero, turn off line */
3336 if (info
->rtsdtr_inv
) {
3337 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3339 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3342 printk("cyc:set_line_char dropping DTR\n");
3343 printk(" status: 0x%x, 0x%x\n",
3344 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3345 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3348 if (info
->rtsdtr_inv
) {
3349 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3351 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3354 printk("cyc:set_line_char raising DTR\n");
3355 printk(" status: 0x%x, 0x%x\n",
3356 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3357 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3362 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3364 CY_UNLOCK(info
, flags
);
3367 struct FIRM_ID __iomem
*firm_id
;
3368 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3369 struct BOARD_CTRL __iomem
*board_ctrl
;
3370 struct CH_CTRL __iomem
*ch_ctrl
;
3371 struct BUF_CTRL __iomem
*buf_ctrl
;
3375 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3376 if (!ISZLOADED(cy_card
[card
])) {
3380 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3381 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3382 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3383 buf_ctrl
= &zfw_ctrl
->buf_ctrl
[channel
];
3386 baud
= tty_get_baud_rate(info
->tty
);
3387 if ((baud
== 38400) &&
3388 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3389 if (info
->custom_divisor
)
3390 baud_rate
= info
->baud
/ info
->custom_divisor
;
3392 baud_rate
= info
->baud
;
3393 } else if (baud
> CYZ_MAX_SPEED
) {
3394 baud
= CYZ_MAX_SPEED
;
3396 cy_writel(&ch_ctrl
->comm_baud
, baud
);
3399 /* get it right for 134.5 baud */
3400 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3401 } else if ((baud
== 38400) &&
3402 ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)) {
3403 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_rate
) + 2;
3405 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud
) + 2;
3406 /* this needs to be propagated into the card info */
3411 /* byte size and parity */
3412 switch(cflag
& CSIZE
){
3413 case CS5
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS5
); break;
3414 case CS6
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS6
); break;
3415 case CS7
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS7
); break;
3416 case CS8
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS8
); break;
3419 cy_writel(&ch_ctrl
->comm_data_l
,
3420 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_2STOP
);
3422 cy_writel(&ch_ctrl
->comm_data_l
,
3423 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_1STOP
);
3425 if (cflag
& PARENB
){
3426 if (cflag
& PARODD
){
3427 cy_writel(&ch_ctrl
->comm_parity
, C_PR_ODD
);
3429 cy_writel(&ch_ctrl
->comm_parity
, C_PR_EVEN
);
3432 cy_writel(&ch_ctrl
->comm_parity
, C_PR_NONE
);
3435 /* CTS flow control flag */
3436 if (cflag
& CRTSCTS
){
3437 cy_writel(&ch_ctrl
->hw_flow
,
3438 cy_readl(&ch_ctrl
->hw_flow
) | C_RS_CTS
| C_RS_RTS
);
3440 cy_writel(&ch_ctrl
->hw_flow
,
3441 cy_readl(&ch_ctrl
->hw_flow
) & ~(C_RS_CTS
| C_RS_RTS
));
3443 /* As the HW flow control is done in firmware, the driver doesn't
3444 need to care about it */
3445 info
->flags
&= ~ASYNC_CTS_FLOW
;
3447 /* XON/XOFF/XANY flow control flags */
3450 sw_flow
|= C_FL_OXX
;
3452 sw_flow
|= C_FL_OIXANY
;
3454 cy_writel(&ch_ctrl
->sw_flow
, sw_flow
);
3456 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
3458 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3459 info
->line
, retval
);
3462 /* CD sensitivity */
3463 if (cflag
& CLOCAL
){
3464 info
->flags
&= ~ASYNC_CHECK_CD
;
3466 info
->flags
|= ASYNC_CHECK_CD
;
3469 if(baud
== 0){ /* baud rate is zero, turn off line */
3470 cy_writel(&ch_ctrl
->rs_control
,
3471 cy_readl(&ch_ctrl
->rs_control
) & ~C_RS_DTR
);
3473 printk("cyc:set_line_char dropping Z DTR\n");
3476 cy_writel(&ch_ctrl
->rs_control
,
3477 cy_readl(&ch_ctrl
->rs_control
) | C_RS_DTR
);
3479 printk("cyc:set_line_char raising Z DTR\n");
3483 retval
= cyz_issue_cmd( &cy_card
[card
], channel
, C_CM_IOCTLM
, 0L);
3485 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3486 info
->line
, retval
);
3490 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3493 } /* set_line_char */
3497 get_serial_info(struct cyclades_port
* info
,
3498 struct serial_struct __user
* retinfo
)
3500 struct serial_struct tmp
;
3501 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
3505 memset(&tmp
, 0, sizeof(tmp
));
3506 tmp
.type
= info
->type
;
3507 tmp
.line
= info
->line
;
3508 tmp
.port
= info
->card
* 0x100 + info
->line
- cinfo
->first_line
;
3509 tmp
.irq
= cinfo
->irq
;
3510 tmp
.flags
= info
->flags
;
3511 tmp
.close_delay
= info
->close_delay
;
3512 tmp
.baud_base
= info
->baud
;
3513 tmp
.custom_divisor
= info
->custom_divisor
;
3514 tmp
.hub6
= 0; /*!!!*/
3515 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
))?-EFAULT
:0;
3516 } /* get_serial_info */
3520 set_serial_info(struct cyclades_port
* info
,
3521 struct serial_struct __user
* new_info
)
3523 struct serial_struct new_serial
;
3524 struct cyclades_port old_info
;
3526 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
3530 if (!capable(CAP_SYS_ADMIN
)) {
3531 if ((new_serial
.close_delay
!= info
->close_delay
) ||
3532 (new_serial
.baud_base
!= info
->baud
) ||
3533 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
3534 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
3536 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
3537 (new_serial
.flags
& ASYNC_USR_MASK
));
3538 info
->baud
= new_serial
.baud_base
;
3539 info
->custom_divisor
= new_serial
.custom_divisor
;
3540 goto check_and_exit
;
3545 * OK, past this point, all the error checking has been done.
3546 * At this point, we start making changes.....
3549 info
->baud
= new_serial
.baud_base
;
3550 info
->custom_divisor
= new_serial
.custom_divisor
;
3551 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
3552 (new_serial
.flags
& ASYNC_FLAGS
));
3553 info
->close_delay
= new_serial
.close_delay
* HZ
/100;
3554 info
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
3557 if (info
->flags
& ASYNC_INITIALIZED
){
3558 set_line_char(info
);
3561 return startup(info
);
3563 } /* set_serial_info */
3566 * get_lsr_info - get line status register info
3568 * Purpose: Let user call ioctl() to get info when the UART physically
3569 * is emptied. On bus types like RS485, the transmitter must
3570 * release the bus after transmitting. This must be done when
3571 * the transmit shift register is empty, not be done when the
3572 * transmit holding register is empty. This functionality
3573 * allows an RS485 driver to be written in user space.
3575 static int get_lsr_info(struct cyclades_port
*info
, unsigned int __user
*value
)
3577 int card
, chip
, channel
, index
;
3578 unsigned char status
;
3579 unsigned int result
;
3580 unsigned long flags
;
3581 void __iomem
*base_addr
;
3584 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3585 if (!IS_CYC_Z(cy_card
[card
])) {
3588 index
= cy_card
[card
].bus_index
;
3589 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3591 CY_LOCK(info
, flags
);
3592 status
= cy_readb(base_addr
+(CySRER
<<index
)) & (CyTxRdy
|CyTxMpty
);
3593 CY_UNLOCK(info
, flags
);
3594 result
= (status
? 0 : TIOCSER_TEMT
);
3596 /* Not supported yet */
3599 return put_user(result
, (unsigned long __user
*) value
);
3603 cy_tiocmget(struct tty_struct
*tty
, struct file
*file
)
3605 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3606 int card
,chip
,channel
,index
;
3607 void __iomem
*base_addr
;
3608 unsigned long flags
;
3609 unsigned char status
;
3610 unsigned long lstatus
;
3611 unsigned int result
;
3612 struct FIRM_ID __iomem
*firm_id
;
3613 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3614 struct BOARD_CTRL __iomem
*board_ctrl
;
3615 struct CH_CTRL __iomem
*ch_ctrl
;
3617 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3621 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3622 if (!IS_CYC_Z(cy_card
[card
])) {
3625 index
= cy_card
[card
].bus_index
;
3626 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3628 CY_LOCK(info
, flags
);
3629 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3630 status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
3631 status
|= cy_readb(base_addr
+(CyMSVR2
<<index
));
3632 CY_UNLOCK(info
, flags
);
3634 if (info
->rtsdtr_inv
) {
3635 result
= ((status
& CyRTS
) ? TIOCM_DTR
: 0)
3636 | ((status
& CyDTR
) ? TIOCM_RTS
: 0);
3638 result
= ((status
& CyRTS
) ? TIOCM_RTS
: 0)
3639 | ((status
& CyDTR
) ? TIOCM_DTR
: 0);
3641 result
|= ((status
& CyDCD
) ? TIOCM_CAR
: 0)
3642 | ((status
& CyRI
) ? TIOCM_RNG
: 0)
3643 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
3644 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
3646 base_addr
= cy_card
[card
].base_addr
;
3648 if (cy_card
[card
].num_chips
!= -1){
3652 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3653 if (ISZLOADED(cy_card
[card
])) {
3654 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3655 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3656 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3657 lstatus
= cy_readl(&ch_ctrl
[channel
].rs_status
);
3658 result
= ((lstatus
& C_RS_RTS
) ? TIOCM_RTS
: 0)
3659 | ((lstatus
& C_RS_DTR
) ? TIOCM_DTR
: 0)
3660 | ((lstatus
& C_RS_DCD
) ? TIOCM_CAR
: 0)
3661 | ((lstatus
& C_RS_RI
) ? TIOCM_RNG
: 0)
3662 | ((lstatus
& C_RS_DSR
) ? TIOCM_DSR
: 0)
3663 | ((lstatus
& C_RS_CTS
) ? TIOCM_CTS
: 0);
3675 cy_tiocmset(struct tty_struct
*tty
, struct file
*file
,
3676 unsigned int set
, unsigned int clear
)
3678 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3679 int card
,chip
,channel
,index
;
3680 void __iomem
*base_addr
;
3681 unsigned long flags
;
3682 struct FIRM_ID __iomem
*firm_id
;
3683 struct ZFW_CTRL __iomem
*zfw_ctrl
;
3684 struct BOARD_CTRL __iomem
*board_ctrl
;
3685 struct CH_CTRL __iomem
*ch_ctrl
;
3688 if (serial_paranoia_check(info
, tty
->name
, __FUNCTION__
))
3692 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3693 if (!IS_CYC_Z(cy_card
[card
])) {
3696 index
= cy_card
[card
].bus_index
;
3697 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3699 if (set
& TIOCM_RTS
){
3700 CY_LOCK(info
, flags
);
3701 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3702 if (info
->rtsdtr_inv
) {
3703 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3705 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3707 CY_UNLOCK(info
, flags
);
3709 if (clear
& TIOCM_RTS
) {
3710 CY_LOCK(info
, flags
);
3711 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3712 if (info
->rtsdtr_inv
) {
3713 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3715 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3717 CY_UNLOCK(info
, flags
);
3719 if (set
& TIOCM_DTR
){
3720 CY_LOCK(info
, flags
);
3721 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3722 if (info
->rtsdtr_inv
) {
3723 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
3725 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
3728 printk("cyc:set_modem_info raising DTR\n");
3729 printk(" status: 0x%x, 0x%x\n",
3730 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3731 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3733 CY_UNLOCK(info
, flags
);
3735 if (clear
& TIOCM_DTR
) {
3736 CY_LOCK(info
, flags
);
3737 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3738 if (info
->rtsdtr_inv
) {
3739 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3741 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3745 printk("cyc:set_modem_info dropping DTR\n");
3746 printk(" status: 0x%x, 0x%x\n",
3747 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3748 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3750 CY_UNLOCK(info
, flags
);
3753 base_addr
= cy_card
[card
].base_addr
;
3755 firm_id
= cy_card
[card
].base_addr
+ ID_ADDRESS
;
3756 if (ISZLOADED(cy_card
[card
])) {
3757 zfw_ctrl
= cy_card
[card
].base_addr
+ (cy_readl(&firm_id
->zfwctrl_addr
) & 0xfffff);
3758 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3759 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3761 if (set
& TIOCM_RTS
){
3762 CY_LOCK(info
, flags
);
3763 cy_writel(&ch_ctrl
[channel
].rs_control
,
3764 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3765 CY_UNLOCK(info
, flags
);
3767 if (clear
& TIOCM_RTS
) {
3768 CY_LOCK(info
, flags
);
3769 cy_writel(&ch_ctrl
[channel
].rs_control
,
3770 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3771 CY_UNLOCK(info
, flags
);
3773 if (set
& TIOCM_DTR
){
3774 CY_LOCK(info
, flags
);
3775 cy_writel(&ch_ctrl
[channel
].rs_control
,
3776 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3778 printk("cyc:set_modem_info raising Z DTR\n");
3780 CY_UNLOCK(info
, flags
);
3782 if (clear
& TIOCM_DTR
) {
3783 CY_LOCK(info
, flags
);
3784 cy_writel(&ch_ctrl
[channel
].rs_control
,
3785 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3787 printk("cyc:set_modem_info clearing Z DTR\n");
3789 CY_UNLOCK(info
, flags
);
3794 CY_LOCK(info
, flags
);
3795 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3796 channel
, C_CM_IOCTLM
,0L);
3798 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3799 info
->line
, retval
);
3801 CY_UNLOCK(info
, flags
);
3807 * cy_break() --- routine which turns the break handling on or off
3810 cy_break(struct tty_struct
*tty
, int break_state
)
3812 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3813 unsigned long flags
;
3815 if (serial_paranoia_check(info
, tty
->name
, "cy_break"))
3818 CY_LOCK(info
, flags
);
3819 if (!IS_CYC_Z(cy_card
[info
->card
])) {
3820 /* Let the transmit ISR take care of this (since it
3821 requires stuffing characters into the output stream).
3823 if (break_state
== -1) {
3824 if (!info
->breakon
) {
3826 if (!info
->xmit_cnt
) {
3827 CY_UNLOCK(info
, flags
);
3829 CY_LOCK(info
, flags
);
3833 if (!info
->breakoff
) {
3835 if (!info
->xmit_cnt
) {
3836 CY_UNLOCK(info
, flags
);
3838 CY_LOCK(info
, flags
);
3845 if (break_state
== -1) {
3846 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3847 (info
->line
) - (cy_card
[info
->card
].first_line
),
3848 C_CM_SET_BREAK
, 0L);
3850 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3851 info
->line
, retval
);
3854 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3855 (info
->line
) - (cy_card
[info
->card
].first_line
),
3856 C_CM_CLR_BREAK
, 0L);
3858 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3859 info
->line
, retval
);
3863 CY_UNLOCK(info
, flags
);
3867 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor __user
* mon
)
3870 if(copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
3872 info
->mon
.int_count
= 0;
3873 info
->mon
.char_count
= 0;
3874 info
->mon
.char_max
= 0;
3875 info
->mon
.char_last
= 0;
3881 set_threshold(struct cyclades_port
* info
, unsigned long value
)
3883 void __iomem
*base_addr
;
3884 int card
,channel
,chip
,index
;
3885 unsigned long flags
;
3888 channel
= info
->line
- cy_card
[card
].first_line
;
3889 if (!IS_CYC_Z(cy_card
[card
])) {
3892 index
= cy_card
[card
].bus_index
;
3893 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3895 info
->cor3
&= ~CyREC_FIFO
;
3896 info
->cor3
|= value
& CyREC_FIFO
;
3898 CY_LOCK(info
, flags
);
3899 cy_writeb(base_addr
+(CyCOR3
<<index
), info
->cor3
);
3900 cyy_issue_cmd(base_addr
,CyCOR_CHANGE
|CyCOR3ch
,index
);
3901 CY_UNLOCK(info
, flags
);
3906 }/* set_threshold */
3910 get_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3912 void __iomem
*base_addr
;
3913 int card
,channel
,chip
,index
;
3917 channel
= info
->line
- cy_card
[card
].first_line
;
3918 if (!IS_CYC_Z(cy_card
[card
])) {
3921 index
= cy_card
[card
].bus_index
;
3922 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3924 tmp
= cy_readb(base_addr
+(CyCOR3
<<index
)) & CyREC_FIFO
;
3925 return put_user(tmp
,value
);
3930 }/* get_threshold */
3934 set_default_threshold(struct cyclades_port
* info
, unsigned long value
)
3936 info
->default_threshold
= value
& 0x0f;
3938 }/* set_default_threshold */
3942 get_default_threshold(struct cyclades_port
* info
, unsigned long __user
*value
)
3944 return put_user(info
->default_threshold
,value
);
3945 }/* get_default_threshold */
3949 set_timeout(struct cyclades_port
* info
, unsigned long value
)
3951 void __iomem
*base_addr
;
3952 int card
,channel
,chip
,index
;
3953 unsigned long flags
;
3956 channel
= info
->line
- cy_card
[card
].first_line
;
3957 if (!IS_CYC_Z(cy_card
[card
])) {
3960 index
= cy_card
[card
].bus_index
;
3961 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3963 CY_LOCK(info
, flags
);
3964 cy_writeb(base_addr
+(CyRTPR
<<index
), value
& 0xff);
3965 CY_UNLOCK(info
, flags
);
3974 get_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
3976 void __iomem
*base_addr
;
3977 int card
,channel
,chip
,index
;
3981 channel
= info
->line
- cy_card
[card
].first_line
;
3982 if (!IS_CYC_Z(cy_card
[card
])) {
3985 index
= cy_card
[card
].bus_index
;
3986 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
3988 tmp
= cy_readb(base_addr
+(CyRTPR
<<index
));
3989 return put_user(tmp
,value
);
3998 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
4000 info
->default_timeout
= value
& 0xff;
4002 }/* set_default_timeout */
4006 get_default_timeout(struct cyclades_port
* info
, unsigned long __user
*value
)
4008 return put_user(info
->default_timeout
,value
);
4009 }/* get_default_timeout */
4012 * This routine allows the tty driver to implement device-
4013 * specific ioctl's. If the ioctl number passed in cmd is
4014 * not recognized by the driver, it should return ENOIOCTLCMD.
4017 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
4018 unsigned int cmd
, unsigned long arg
)
4020 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4021 struct cyclades_icount cprev
, cnow
; /* kernel counter temps */
4022 struct serial_icounter_struct __user
*p_cuser
; /* user space */
4024 unsigned long flags
;
4025 void __user
*argp
= (void __user
*)arg
;
4027 if (serial_paranoia_check(info
, tty
->name
, "cy_ioctl"))
4030 #ifdef CY_DEBUG_OTHER
4031 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
4032 info
->line
, cmd
, arg
); /* */
4037 ret_val
= get_mon_info(info
, argp
);
4040 ret_val
= get_threshold(info
, argp
);
4043 ret_val
= set_threshold(info
, arg
);
4045 case CYGETDEFTHRESH
:
4046 ret_val
= get_default_threshold(info
, argp
);
4048 case CYSETDEFTHRESH
:
4049 ret_val
= set_default_threshold(info
, arg
);
4052 ret_val
= get_timeout(info
, argp
);
4055 ret_val
= set_timeout(info
, arg
);
4057 case CYGETDEFTIMEOUT
:
4058 ret_val
= get_default_timeout(info
, argp
);
4060 case CYSETDEFTIMEOUT
:
4061 ret_val
= set_default_timeout(info
, arg
);
4064 info
->rflow
= (int)arg
;
4068 ret_val
= info
->rflow
;
4070 case CYSETRTSDTR_INV
:
4071 info
->rtsdtr_inv
= (int)arg
;
4074 case CYGETRTSDTR_INV
:
4075 ret_val
= info
->rtsdtr_inv
;
4078 if (copy_to_user(argp
, &cy_card
[info
->card
],
4079 sizeof (struct cyclades_card
))) {
4085 case CYGETCD1400VER
:
4086 ret_val
= info
->chip_rev
;
4088 #ifndef CONFIG_CYZ_INTR
4089 case CYZSETPOLLCYCLE
:
4090 cyz_polling_cycle
= (arg
* HZ
) / 1000;
4093 case CYZGETPOLLCYCLE
:
4094 ret_val
= (cyz_polling_cycle
* 1000) / HZ
;
4096 #endif /* CONFIG_CYZ_INTR */
4098 info
->closing_wait
= (unsigned short)arg
* HZ
/100;
4102 ret_val
= info
->closing_wait
/ (HZ
/100);
4105 ret_val
= get_serial_info(info
, argp
);
4108 ret_val
= set_serial_info(info
, argp
);
4110 case TIOCSERGETLSR
: /* Get line status register */
4111 ret_val
= get_lsr_info(info
, argp
);
4114 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4115 * - mask passed in arg for lines of interest
4116 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4117 * Caller should use TIOCGICOUNT to see which one it was
4120 CY_LOCK(info
, flags
);
4121 /* note the counters on entry */
4122 cprev
= info
->icount
;
4123 CY_UNLOCK(info
, flags
);
4125 interruptible_sleep_on(&info
->delta_msr_wait
);
4126 /* see if a signal did it */
4127 if (signal_pending(current
)) {
4128 return -ERESTARTSYS
;
4131 CY_LOCK(info
, flags
);
4132 cnow
= info
->icount
; /* atomic copy */
4133 CY_UNLOCK(info
, flags
);
4135 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
4136 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
4137 return -EIO
; /* no change => error */
4139 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
4140 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
4141 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
4142 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
4150 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4151 * Return: write counters to the user passed counter struct
4152 * NB: both 1->0 and 0->1 transitions are counted except for
4153 * RI where only 0->1 is counted.
4156 CY_LOCK(info
, flags
);
4157 cnow
= info
->icount
;
4158 CY_UNLOCK(info
, flags
);
4160 ret_val
= put_user(cnow
.cts
, &p_cuser
->cts
);
4161 if (ret_val
) return ret_val
;
4162 ret_val
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
4163 if (ret_val
) return ret_val
;
4164 ret_val
= put_user(cnow
.rng
, &p_cuser
->rng
);
4165 if (ret_val
) return ret_val
;
4166 ret_val
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
4167 if (ret_val
) return ret_val
;
4168 ret_val
= put_user(cnow
.rx
, &p_cuser
->rx
);
4169 if (ret_val
) return ret_val
;
4170 ret_val
= put_user(cnow
.tx
, &p_cuser
->tx
);
4171 if (ret_val
) return ret_val
;
4172 ret_val
= put_user(cnow
.frame
, &p_cuser
->frame
);
4173 if (ret_val
) return ret_val
;
4174 ret_val
= put_user(cnow
.overrun
, &p_cuser
->overrun
);
4175 if (ret_val
) return ret_val
;
4176 ret_val
= put_user(cnow
.parity
, &p_cuser
->parity
);
4177 if (ret_val
) return ret_val
;
4178 ret_val
= put_user(cnow
.brk
, &p_cuser
->brk
);
4179 if (ret_val
) return ret_val
;
4180 ret_val
= put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
4181 if (ret_val
) return ret_val
;
4185 ret_val
= -ENOIOCTLCMD
;
4188 #ifdef CY_DEBUG_OTHER
4189 printk(" cyc:cy_ioctl done\n");
4197 * This routine allows the tty driver to be notified when
4198 * device's termios settings have changed. Note that a
4199 * well-designed tty driver should be prepared to accept the case
4200 * where old == NULL, and try to do something rational.
4203 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
4205 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4207 #ifdef CY_DEBUG_OTHER
4208 printk("cyc:cy_set_termios ttyC%d\n", info
->line
);
4211 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
4212 ((tty
->termios
->c_iflag
& (IXON
|IXANY
)) ==
4213 (old_termios
->c_iflag
& (IXON
|IXANY
))))
4215 set_line_char(info
);
4217 if ((old_termios
->c_cflag
& CRTSCTS
) &&
4218 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
4219 tty
->hw_stopped
= 0;
4224 * No need to wake up processes in open wait, since they
4225 * sample the CLOCAL flag once, and don't recheck it.
4226 * XXX It's not clear whether the current behavior is correct
4227 * or not. Hence, this may change.....
4229 if (!(old_termios
->c_cflag
& CLOCAL
) &&
4230 (tty
->termios
->c_cflag
& CLOCAL
))
4231 wake_up_interruptible(&info
->open_wait
);
4235 } /* cy_set_termios */
4237 /* This function is used to send a high-priority XON/XOFF character to
4241 cy_send_xchar (struct tty_struct
*tty
, char ch
)
4243 struct cyclades_port
*info
= (struct cyclades_port
*) tty
->driver_data
;
4246 if (serial_paranoia_check (info
, tty
->name
, "cy_send_xchar"))
4255 channel
= info
->line
- cy_card
[card
].first_line
;
4257 if (IS_CYC_Z (cy_card
[card
])) {
4258 if (ch
== STOP_CHAR (tty
))
4259 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXOFF
, 0L);
4260 else if (ch
== START_CHAR (tty
))
4261 cyz_issue_cmd (&cy_card
[card
], channel
, C_CM_SENDXON
, 0L);
4265 /* This routine is called by the upper-layer tty layer to signal
4266 that incoming characters should be throttled because the input
4267 buffers are close to full.
4270 cy_throttle(struct tty_struct
* tty
)
4272 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4273 unsigned long flags
;
4274 void __iomem
*base_addr
;
4275 int card
,chip
,channel
,index
;
4277 #ifdef CY_DEBUG_THROTTLE
4280 printk("cyc:throttle %s: %d....ttyC%d\n",
4282 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4285 if (serial_paranoia_check(info
, tty
->name
, "cy_throttle")){
4292 if (!IS_CYC_Z (cy_card
[card
]))
4293 cy_send_xchar (tty
, STOP_CHAR (tty
));
4298 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4299 channel
= info
->line
- cy_card
[card
].first_line
;
4300 if (!IS_CYC_Z(cy_card
[card
])) {
4303 index
= cy_card
[card
].bus_index
;
4304 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4306 CY_LOCK(info
, flags
);
4307 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4308 if (info
->rtsdtr_inv
) {
4309 cy_writeb(base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
4311 cy_writeb(base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
4313 CY_UNLOCK(info
, flags
);
4324 * This routine notifies the tty driver that it should signal
4325 * that characters can now be sent to the tty without fear of
4326 * overrunning the input buffers of the line disciplines.
4329 cy_unthrottle(struct tty_struct
* tty
)
4331 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4332 unsigned long flags
;
4333 void __iomem
*base_addr
;
4334 int card
,chip
,channel
,index
;
4336 #ifdef CY_DEBUG_THROTTLE
4339 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4341 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4344 if (serial_paranoia_check(info
, tty
->name
, "cy_unthrottle")){
4352 cy_send_xchar (tty
, START_CHAR (tty
));
4355 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4357 channel
= info
->line
- cy_card
[card
].first_line
;
4358 if (!IS_CYC_Z(cy_card
[card
])) {
4361 index
= cy_card
[card
].bus_index
;
4362 base_addr
= cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4364 CY_LOCK(info
, flags
);
4365 cy_writeb(base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4366 if (info
->rtsdtr_inv
) {
4367 cy_writeb(base_addr
+(CyMSVR2
<<index
), CyDTR
);
4369 cy_writeb(base_addr
+(CyMSVR1
<<index
), CyRTS
);
4371 CY_UNLOCK(info
, flags
);
4378 } /* cy_unthrottle */
4381 /* cy_start and cy_stop provide software output flow control as a
4382 function of XON/XOFF, software CTS, and other such stuff.
4385 cy_stop(struct tty_struct
*tty
)
4387 struct cyclades_card
*cinfo
;
4388 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4389 void __iomem
*base_addr
;
4390 int chip
,channel
,index
;
4391 unsigned long flags
;
4393 #ifdef CY_DEBUG_OTHER
4394 printk("cyc:cy_stop ttyC%d\n", info
->line
); /* */
4397 if (serial_paranoia_check(info
, tty
->name
, "cy_stop"))
4400 cinfo
= &cy_card
[info
->card
];
4401 channel
= info
->line
- cinfo
->first_line
;
4402 if (!IS_CYC_Z(*cinfo
)) {
4403 index
= cinfo
->bus_index
;
4406 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4408 CY_LOCK(info
, flags
);
4409 cy_writeb(base_addr
+(CyCAR
<<index
),
4410 (u_char
)(channel
& 0x0003)); /* index channel */
4411 cy_writeb(base_addr
+(CySRER
<<index
),
4412 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxRdy
);
4413 CY_UNLOCK(info
, flags
);
4423 cy_start(struct tty_struct
*tty
)
4425 struct cyclades_card
*cinfo
;
4426 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4427 void __iomem
*base_addr
;
4428 int chip
,channel
,index
;
4429 unsigned long flags
;
4431 #ifdef CY_DEBUG_OTHER
4432 printk("cyc:cy_start ttyC%d\n", info
->line
); /* */
4435 if (serial_paranoia_check(info
, tty
->name
, "cy_start"))
4438 cinfo
= &cy_card
[info
->card
];
4439 channel
= info
->line
- cinfo
->first_line
;
4440 index
= cinfo
->bus_index
;
4441 if (!IS_CYC_Z(*cinfo
)) {
4444 base_addr
= cy_card
[info
->card
].base_addr
+ (cy_chip_offset
[chip
]<<index
);
4446 CY_LOCK(info
, flags
);
4447 cy_writeb(base_addr
+(CyCAR
<<index
),
4448 (u_char
)(channel
& 0x0003)); /* index channel */
4449 cy_writeb(base_addr
+(CySRER
<<index
),
4450 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxRdy
);
4451 CY_UNLOCK(info
, flags
);
4461 cy_flush_buffer(struct tty_struct
*tty
)
4463 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4464 int card
, channel
, retval
;
4465 unsigned long flags
;
4468 printk("cyc:cy_flush_buffer ttyC%d\n", info
->line
); /* */
4471 if (serial_paranoia_check(info
, tty
->name
, "cy_flush_buffer"))
4475 channel
= (info
->line
) - (cy_card
[card
].first_line
);
4477 CY_LOCK(info
, flags
);
4478 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
4479 CY_UNLOCK(info
, flags
);
4481 if (IS_CYC_Z(cy_card
[card
])) { /* If it is a Z card, flush the on-board
4483 CY_LOCK(info
, flags
);
4484 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_TX
, 0L);
4486 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4487 info
->line
, retval
);
4489 CY_UNLOCK(info
, flags
);
4492 wake_up_interruptible(&tty
->write_wait
);
4493 } /* cy_flush_buffer */
4497 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4500 cy_hangup(struct tty_struct
*tty
)
4502 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4504 #ifdef CY_DEBUG_OTHER
4505 printk("cyc:cy_hangup ttyC%d\n", info
->line
); /* */
4508 if (serial_paranoia_check(info
, tty
->name
, "cy_hangup"))
4511 cy_flush_buffer(tty
);
4515 #ifdef CY_DEBUG_COUNT
4516 printk("cyc:cy_hangup (%d): setting count to 0\n", current
->pid
);
4519 info
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
4520 wake_up_interruptible(&info
->open_wait
);
4525 * ---------------------------------------------------------------------
4526 * cy_init() and friends
4528 * cy_init() is called at boot-time to initialize the serial driver.
4529 * ---------------------------------------------------------------------
4532 /* initialize chips on Cyclom-Y card -- return number of valid
4533 chips (which is number of ports/4) */
4534 static unsigned short __init
4535 cyy_init_card(void __iomem
*true_base_addr
,int index
)
4537 unsigned int chip_number
;
4538 void __iomem
*base_addr
;
4540 cy_writeb(true_base_addr
+(Cy_HwReset
<<index
), 0);
4541 /* Cy_HwReset is 0x1400 */
4542 cy_writeb(true_base_addr
+(Cy_ClrIntr
<<index
), 0);
4543 /* Cy_ClrIntr is 0x1800 */
4546 for(chip_number
=0; chip_number
<CyMAX_CHIPS_PER_CARD
; chip_number
++){
4547 base_addr
= true_base_addr
+ (cy_chip_offset
[chip_number
]<<index
);
4549 if(cy_readb(base_addr
+(CyCCR
<<index
)) != 0x00){
4551 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4552 chip_number, (unsigned long)base_addr);
4557 cy_writeb(base_addr
+(CyGFRCR
<<index
), 0);
4560 /* The Cyclom-16Y does not decode address bit 9 and therefore
4561 cannot distinguish between references to chip 0 and a non-
4562 existent chip 4. If the preceding clearing of the supposed
4563 chip 4 GFRCR register appears at chip 0, there is no chip 4
4564 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4566 if (chip_number
== 4
4567 && cy_readb(true_base_addr
4568 + (cy_chip_offset
[0]<<index
)
4569 + (CyGFRCR
<<index
)) == 0){
4573 cy_writeb(base_addr
+(CyCCR
<<index
), CyCHIP_RESET
);
4576 if(cy_readb(base_addr
+(CyGFRCR
<<index
)) == 0x00){
4578 printk(" chip #%d at %#6lx is not responding ",
4579 chip_number, (unsigned long)base_addr);
4580 printk("(GFRCR stayed 0)\n",
4584 if((0xf0 & (cy_readb(base_addr
+(CyGFRCR
<<index
)))) != 0x40){
4586 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4587 chip_number, (unsigned long)base_addr,
4588 base_addr[CyGFRCR<<index]);
4592 cy_writeb(base_addr
+(CyGCR
<<index
), CyCH0_SERIAL
);
4593 if (cy_readb(base_addr
+(CyGFRCR
<<index
)) >= CD1400_REV_J
){
4594 /* It is a CD1400 rev. J or later */
4595 /* Impossible to reach 5ms with this chip.
4596 Changed to 2ms instead (f = 500 Hz). */
4597 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_60_2MS
);
4600 cy_writeb(base_addr
+(CyPPR
<<index
), CyCLOCK_25_5MS
);
4604 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4605 chip_number, (unsigned long)base_addr,
4606 cy_readb(base_addr+(CyGFRCR<<index)));
4610 } /* cyy_init_card */
4613 * ---------------------------------------------------------------------
4614 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4615 * sets global variables and return the number of ISA boards found.
4616 * ---------------------------------------------------------------------
4622 unsigned short cy_isa_irq
,nboard
;
4623 void __iomem
*cy_isa_address
;
4624 unsigned short i
,j
,cy_isa_nchan
;
4632 /* Check for module parameters */
4633 for(i
= 0 ; i
< NR_CARDS
; i
++) {
4634 if (maddr
[i
] || i
) {
4636 cy_isa_addresses
[i
] = maddr
[i
];
4643 /* scan the address table probing for Cyclom-Y/ISA boards */
4644 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
4645 unsigned int isa_address
= cy_isa_addresses
[i
];
4646 if (isa_address
== 0x0000) {
4650 /* probe for CD1400... */
4651 cy_isa_address
= ioremap(isa_address
, CyISA_Ywin
);
4652 cy_isa_nchan
= CyPORTS_PER_CHIP
*
4653 cyy_init_card(cy_isa_address
,0);
4654 if (cy_isa_nchan
== 0) {
4659 if (isparam
&& irq
[i
])
4660 cy_isa_irq
= irq
[i
];
4663 /* find out the board's irq by probing */
4664 cy_isa_irq
= detect_isa_irq(cy_isa_address
);
4665 if (cy_isa_irq
== 0) {
4666 printk("Cyclom-Y/ISA found at 0x%lx ",
4667 (unsigned long) cy_isa_address
);
4668 printk("but the IRQ could not be detected.\n");
4672 if((cy_next_channel
+cy_isa_nchan
) > NR_PORTS
) {
4673 printk("Cyclom-Y/ISA found at 0x%lx ",
4674 (unsigned long) cy_isa_address
);
4675 printk("but no more channels are available.\n");
4676 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4679 /* fill the next cy_card structure available */
4680 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4681 if (cy_card
[j
].base_addr
== 0) break;
4683 if (j
== NR_CARDS
) { /* no more cy_cards available */
4684 printk("Cyclom-Y/ISA found at 0x%lx ",
4685 (unsigned long) cy_isa_address
);
4686 printk("but no more cards can be used .\n");
4687 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4692 if(request_irq(cy_isa_irq
, cyy_interrupt
,
4693 SA_INTERRUPT
, "Cyclom-Y", &cy_card
[j
]))
4695 printk("Cyclom-Y/ISA found at 0x%lx ",
4696 (unsigned long) cy_isa_address
);
4697 printk("but could not allocate IRQ#%d.\n",
4703 cy_card
[j
].base_addr
= cy_isa_address
;
4704 cy_card
[j
].ctl_addr
= NULL
;
4705 cy_card
[j
].irq
= (int) cy_isa_irq
;
4706 cy_card
[j
].bus_index
= 0;
4707 cy_card
[j
].first_line
= cy_next_channel
;
4708 cy_card
[j
].num_chips
= cy_isa_nchan
/4;
4712 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4713 j
+1, (unsigned long) cy_isa_address
,
4714 (unsigned long)(cy_isa_address
+ (CyISA_Ywin
- 1)),
4716 printk("%d channels starting from port %d.\n",
4717 cy_isa_nchan
, cy_next_channel
);
4718 cy_next_channel
+= cy_isa_nchan
;
4723 #endif /* CONFIG_ISA */
4724 } /* cy_detect_isa */
4727 plx_init(void __iomem
*addr
, uclong initctl
)
4730 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x40000000);
4732 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x40000000);
4734 /* Reload Config. Registers from EEPROM */
4735 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x20000000);
4737 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x20000000);
4741 * ---------------------------------------------------------------------
4742 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4743 * sets global variables and return the number of PCI boards found.
4744 * ---------------------------------------------------------------------
4751 struct pci_dev
*pdev
= NULL
;
4752 unsigned char cyy_rev_id
;
4753 unsigned char cy_pci_irq
= 0;
4754 uclong cy_pci_phys0
, cy_pci_phys2
;
4755 void __iomem
*cy_pci_addr0
, *cy_pci_addr2
;
4756 unsigned short i
,j
,cy_pci_nchan
, plx_ver
;
4757 unsigned short device_id
,dev_index
= 0;
4760 void __iomem
*Ze_addr0
[NR_CARDS
], *Ze_addr2
[NR_CARDS
];
4761 uclong Ze_phys0
[NR_CARDS
], Ze_phys2
[NR_CARDS
];
4762 unsigned char Ze_irq
[NR_CARDS
];
4763 struct pci_dev
*Ze_pdev
[NR_CARDS
];
4765 for (i
= 0; i
< NR_CARDS
; i
++) {
4766 /* look for a Cyclades card by vendor and device id */
4767 while((device_id
= cy_pci_dev_id
[dev_index
]) != 0) {
4768 if((pdev
= pci_find_device(PCI_VENDOR_ID_CYCLADES
,
4769 device_id
, pdev
)) == NULL
) {
4770 dev_index
++; /* try next device id */
4772 break; /* found a board */
4779 if (pci_enable_device(pdev
))
4782 /* read PCI configuration area */
4783 cy_pci_irq
= pdev
->irq
;
4784 cy_pci_phys0
= pci_resource_start(pdev
, 0);
4785 cy_pci_phys2
= pci_resource_start(pdev
, 2);
4786 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &cyy_rev_id
);
4788 device_id
&= ~PCI_DEVICE_ID_MASK
;
4790 if ((device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
)
4791 || (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Hi
)){
4793 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4794 pdev
->bus
->number
, pdev
->devfn
);
4795 printk("rev_id=%d) IRQ%d\n",
4796 cyy_rev_id
, (int)cy_pci_irq
);
4797 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4798 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4801 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4802 printk(" Warning: PCI I/O bit incorrectly set. "
4803 "Ignoring it...\n");
4804 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4807 /* Although we don't use this I/O region, we should
4808 request it from the kernel anyway, to avoid problems
4809 with other drivers accessing it. */
4810 if (pci_request_regions(pdev
, "Cyclom-Y") != 0) {
4811 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4815 #if defined(__alpha__)
4816 if (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
) { /* below 1M? */
4817 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4818 pdev
->bus
->number
, pdev
->devfn
);
4819 printk("rev_id=%d) IRQ%d\n",
4820 cyy_rev_id
, (int)cy_pci_irq
);
4821 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4822 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4823 printk("Cyclom-Y/PCI not supported for low addresses in "
4824 "Alpha systems.\n");
4829 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Yctl
);
4830 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ywin
);
4833 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4834 (u_long
)cy_pci_addr2
, (u_long
)cy_pci_addr0
);
4836 cy_pci_nchan
= (unsigned short)(CyPORTS_PER_CHIP
*
4837 cyy_init_card(cy_pci_addr2
, 1));
4838 if(cy_pci_nchan
== 0) {
4839 printk("Cyclom-Y PCI host card with ");
4840 printk("no Serial-Modules at 0x%lx.\n",
4841 (ulong
) cy_pci_phys2
);
4845 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4846 printk("Cyclom-Y/PCI found at 0x%lx ",
4847 (ulong
) cy_pci_phys2
);
4848 printk("but no channels are available.\n");
4849 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4852 /* fill the next cy_card structure available */
4853 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4854 if (cy_card
[j
].base_addr
== 0) break;
4856 if (j
== NR_CARDS
) { /* no more cy_cards available */
4857 printk("Cyclom-Y/PCI found at 0x%lx ",
4858 (ulong
) cy_pci_phys2
);
4859 printk("but no more cards can be used.\n");
4860 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4865 if(request_irq(cy_pci_irq
, cyy_interrupt
,
4866 SA_SHIRQ
, "Cyclom-Y", &cy_card
[j
]))
4868 printk("Cyclom-Y/PCI found at 0x%lx ",
4869 (ulong
) cy_pci_phys2
);
4870 printk("but could not allocate IRQ%d.\n",
4876 cy_card
[j
].base_phys
= (ulong
)cy_pci_phys2
;
4877 cy_card
[j
].ctl_phys
= (ulong
)cy_pci_phys0
;
4878 cy_card
[j
].base_addr
= cy_pci_addr2
;
4879 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
4880 cy_card
[j
].irq
= (int) cy_pci_irq
;
4881 cy_card
[j
].bus_index
= 1;
4882 cy_card
[j
].first_line
= cy_next_channel
;
4883 cy_card
[j
].num_chips
= cy_pci_nchan
/4;
4884 cy_card
[j
].pdev
= pdev
;
4886 /* enable interrupts in the PCI interface */
4887 plx_ver
= cy_readb(cy_pci_addr2
+ CyPLX_VER
) & 0x0f;
4891 cy_writeb(cy_pci_addr0
+0x4c, 0x43);
4896 default: /* Old boards, use PLX_9060 */
4898 plx_init(cy_pci_addr0
, 0x6c);
4899 /* For some yet unknown reason, once the PLX9060 reloads
4900 the EEPROM, the IRQ is lost and, thus, we have to
4901 re-write it to the PCI config. registers.
4902 This will remain here until we find a permanent fix. */
4903 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4905 cy_writew(cy_pci_addr0
+0x68,
4906 cy_readw(cy_pci_addr0
+0x68)|0x0900);
4911 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4913 (ulong
)cy_pci_phys2
,
4914 (ulong
)(cy_pci_phys2
+ CyPCI_Ywin
- 1),
4916 printk("%d channels starting from port %d.\n",
4917 cy_pci_nchan
, cy_next_channel
);
4919 cy_next_channel
+= cy_pci_nchan
;
4920 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Lo
){
4922 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4923 pdev
->bus
->number
, pdev
->devfn
);
4924 printk("rev_id=%d) IRQ%d\n",
4925 cyy_rev_id
, (int)cy_pci_irq
);
4926 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4927 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4928 printk("Cyclades-Z/PCI not supported for low addresses\n");
4930 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Hi
){
4932 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4933 pdev
->bus
->number
, pdev
->devfn
);
4934 printk("rev_id=%d) IRQ%d\n",
4935 cyy_rev_id
, (int)cy_pci_irq
);
4936 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4937 (ulong
)cy_pci_phys2
, (ulong
)cy_pci_phys0
);
4939 cy_pci_addr0
= ioremap(cy_pci_phys0
, CyPCI_Zctl
);
4941 /* Disable interrupts on the PLX before resetting it */
4942 cy_writew(cy_pci_addr0
+0x68,
4943 cy_readw(cy_pci_addr0
+0x68) & ~0x0900);
4945 plx_init(cy_pci_addr0
, 0x6c);
4946 /* For some yet unknown reason, once the PLX9060 reloads
4947 the EEPROM, the IRQ is lost and, thus, we have to
4948 re-write it to the PCI config. registers.
4949 This will remain here until we find a permanent fix. */
4950 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4952 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
4953 cy_pci_addr0
)->mail_box_0
);
4955 if (pci_resource_flags(pdev
, 2) & IORESOURCE_IO
) {
4956 printk(" Warning: PCI I/O bit incorrectly set. "
4957 "Ignoring it...\n");
4958 pdev
->resource
[2].flags
&= ~IORESOURCE_IO
;
4961 /* Although we don't use this I/O region, we should
4962 request it from the kernel anyway, to avoid problems
4963 with other drivers accessing it. */
4964 if (pci_request_regions(pdev
, "Cyclades-Z") != 0) {
4965 printk(KERN_ERR
"cyclades: failed to reserve PCI resources\n");
4969 if (mailbox
== ZE_V1
) {
4970 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Ze_win
);
4971 if (ZeIndex
== NR_CARDS
) {
4972 printk("Cyclades-Ze/PCI found at 0x%lx ",
4973 (ulong
)cy_pci_phys2
);
4974 printk("but no more cards can be used.\n");
4975 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4977 Ze_phys0
[ZeIndex
] = cy_pci_phys0
;
4978 Ze_phys2
[ZeIndex
] = cy_pci_phys2
;
4979 Ze_addr0
[ZeIndex
] = cy_pci_addr0
;
4980 Ze_addr2
[ZeIndex
] = cy_pci_addr2
;
4981 Ze_irq
[ZeIndex
] = cy_pci_irq
;
4982 Ze_pdev
[ZeIndex
] = pdev
;
4988 cy_pci_addr2
= ioremap(cy_pci_phys2
, CyPCI_Zwin
);
4992 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4993 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4994 if (mailbox
== ZO_V1
) {
4995 cy_writel(&((struct RUNTIME_9060
*)
4996 (cy_pci_addr0
))->loc_addr_base
, WIN_CREG
);
4998 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
4999 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5000 (cy_pci_addr2
))->fpga_id
)),
5001 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5002 (cy_pci_addr2
))->fpga_version
)));
5003 cy_writel(&((struct RUNTIME_9060
*)
5004 (cy_pci_addr0
))->loc_addr_base
, WIN_RAM
);
5006 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5009 /* The following clears the firmware id word. This ensures
5010 that the driver will not attempt to talk to the board
5011 until it has been properly initialized.
5014 if ((mailbox
== ZO_V1
) || (mailbox
== ZO_V2
))
5015 cy_writel(cy_pci_addr2
+ ID_ADDRESS
, 0L);
5017 /* This must be a Cyclades-8Zo/PCI. The extendable
5018 version will have a different device_id and will
5019 be allocated its maximum number of ports. */
5022 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5023 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5024 (ulong
)cy_pci_phys2
);
5025 printk("but no channels are available.\n");
5026 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5030 /* fill the next cy_card structure available */
5031 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5032 if (cy_card
[j
].base_addr
== 0) break;
5034 if (j
== NR_CARDS
) { /* no more cy_cards available */
5035 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5036 (ulong
)cy_pci_phys2
);
5037 printk("but no more cards can be used.\n");
5038 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5042 #ifdef CONFIG_CYZ_INTR
5043 /* allocate IRQ only if board has an IRQ */
5044 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5045 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5046 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5048 printk("Cyclom-8Zo/PCI found at 0x%lx ",
5049 (ulong
) cy_pci_phys2
);
5050 printk("but could not allocate IRQ%d.\n",
5055 #endif /* CONFIG_CYZ_INTR */
5059 cy_card
[j
].base_phys
= cy_pci_phys2
;
5060 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
5061 cy_card
[j
].base_addr
= cy_pci_addr2
;
5062 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5063 cy_card
[j
].irq
= (int) cy_pci_irq
;
5064 cy_card
[j
].bus_index
= 1;
5065 cy_card
[j
].first_line
= cy_next_channel
;
5066 cy_card
[j
].num_chips
= -1;
5067 cy_card
[j
].pdev
= pdev
;
5070 #ifdef CONFIG_CYZ_INTR
5071 /* don't report IRQ if board is no IRQ */
5072 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5073 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5074 j
+1,(ulong
)cy_pci_phys2
,
5075 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1),
5078 #endif /* CONFIG_CYZ_INTR */
5079 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5080 j
+1,(ulong
)cy_pci_phys2
,
5081 (ulong
)(cy_pci_phys2
+ CyPCI_Zwin
- 1));
5083 printk("%d channels starting from port %d.\n",
5084 cy_pci_nchan
,cy_next_channel
);
5085 cy_next_channel
+= cy_pci_nchan
;
5089 for (; ZeIndex
!= 0 && i
< NR_CARDS
; i
++) {
5090 cy_pci_phys0
= Ze_phys0
[0];
5091 cy_pci_phys2
= Ze_phys2
[0];
5092 cy_pci_addr0
= Ze_addr0
[0];
5093 cy_pci_addr2
= Ze_addr2
[0];
5094 cy_pci_irq
= Ze_irq
[0];
5096 for (j
= 0 ; j
< ZeIndex
-1 ; j
++) {
5097 Ze_phys0
[j
] = Ze_phys0
[j
+1];
5098 Ze_phys2
[j
] = Ze_phys2
[j
+1];
5099 Ze_addr0
[j
] = Ze_addr0
[j
+1];
5100 Ze_addr2
[j
] = Ze_addr2
[j
+1];
5101 Ze_irq
[j
] = Ze_irq
[j
+1];
5102 Ze_pdev
[j
] = Ze_pdev
[j
+1];
5105 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060 __iomem
*)
5106 cy_pci_addr0
)->mail_box_0
);
5108 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5109 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5110 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5113 /* This must be the new Cyclades-Ze/PCI. */
5114 cy_pci_nchan
= ZE_V1_NPORTS
;
5116 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5117 printk("Cyclades-Ze/PCI found at 0x%lx ",
5118 (ulong
)cy_pci_phys2
);
5119 printk("but no channels are available.\n");
5120 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5124 /* fill the next cy_card structure available */
5125 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5126 if (cy_card
[j
].base_addr
== 0) break;
5128 if (j
== NR_CARDS
) { /* no more cy_cards available */
5129 printk("Cyclades-Ze/PCI found at 0x%lx ",
5130 (ulong
)cy_pci_phys2
);
5131 printk("but no more cards can be used.\n");
5132 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5136 #ifdef CONFIG_CYZ_INTR
5137 /* allocate IRQ only if board has an IRQ */
5138 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5139 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5140 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5142 printk("Cyclom-Ze/PCI found at 0x%lx ",
5143 (ulong
) cy_pci_phys2
);
5144 printk("but could not allocate IRQ%d.\n",
5149 #endif /* CONFIG_CYZ_INTR */
5152 cy_card
[j
].base_phys
= cy_pci_phys2
;
5153 cy_card
[j
].ctl_phys
= cy_pci_phys0
;
5154 cy_card
[j
].base_addr
= cy_pci_addr2
;
5155 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5156 cy_card
[j
].irq
= (int) cy_pci_irq
;
5157 cy_card
[j
].bus_index
= 1;
5158 cy_card
[j
].first_line
= cy_next_channel
;
5159 cy_card
[j
].num_chips
= -1;
5160 cy_card
[j
].pdev
= pdev
;
5163 #ifdef CONFIG_CYZ_INTR
5164 /* don't report IRQ if board is no IRQ */
5165 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5166 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5167 j
+1,(ulong
)cy_pci_phys2
,
5168 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1),
5171 #endif /* CONFIG_CYZ_INTR */
5172 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5173 j
+1,(ulong
)cy_pci_phys2
,
5174 (ulong
)(cy_pci_phys2
+ CyPCI_Ze_win
- 1));
5176 printk("%d channels starting from port %d.\n",
5177 cy_pci_nchan
,cy_next_channel
);
5178 cy_next_channel
+= cy_pci_nchan
;
5181 printk("Cyclades-Ze/PCI found at 0x%x ",
5182 (unsigned int) Ze_phys2
[0]);
5183 printk("but no more cards can be used.\n");
5184 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5189 #endif /* ifdef CONFIG_PCI */
5190 } /* cy_detect_pci */
5194 * This routine prints out the appropriate serial driver version number
5195 * and identifies which options were configured into this driver.
5200 char *rcsvers
, *rcsdate
, *tmp
;
5201 rcsvers
= strchr(rcsid
, ' '); rcsvers
++;
5202 tmp
= strchr(rcsvers
, ' '); *tmp
++ = '\0';
5203 rcsdate
= strchr(tmp
, ' '); rcsdate
++;
5204 tmp
= strrchr(rcsdate
, ' '); *tmp
= '\0';
5205 printk("Cyclades driver %s %s\n",
5207 printk(" built %s %s\n",
5208 __DATE__
, __TIME__
);
5209 } /* show_version */
5212 cyclades_get_proc_info(char *buf
, char **start
, off_t offset
, int length
,
5213 int *eof
, void *data
)
5215 struct cyclades_port
*info
;
5221 __u32 cur_jifs
= jiffies
;
5223 size
= sprintf(buf
, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
5228 /* Output one line for each known port */
5229 for (i
= 0; i
< NR_PORTS
&& cy_port
[i
].line
>= 0; i
++) {
5233 size
= sprintf(buf
+len
,
5234 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5236 JIFFIES_DIFF(info
->idle_stats
.in_use
, cur_jifs
) / HZ
,
5237 info
->idle_stats
.xmit_bytes
,
5238 JIFFIES_DIFF(info
->idle_stats
.xmit_idle
, cur_jifs
) / HZ
,
5239 info
->idle_stats
.recv_bytes
,
5240 JIFFIES_DIFF(info
->idle_stats
.recv_idle
, cur_jifs
) / HZ
,
5241 info
->idle_stats
.overruns
,
5242 (long) info
->tty
->ldisc
.num
);
5244 size
= sprintf(buf
+len
,
5245 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5246 info
->line
, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5254 if (pos
> offset
+ length
)
5259 *start
= buf
+ (offset
- begin
); /* Start of wanted data */
5260 len
-= (offset
- begin
); /* Start slop */
5262 len
= length
; /* Ending slop */
5268 /* The serial driver boot-time initialization code!
5269 Hardware I/O ports are mapped to character special devices on a
5270 first found, first allocated manner. That is, this code searches
5271 for Cyclom cards in the system. As each is found, it is probed
5272 to discover how many chips (and thus how many ports) are present.
5273 These ports are mapped to the tty ports 32 and upward in monotonic
5274 fashion. If an 8-port card is replaced with a 16-port card, the
5275 port mapping on a following card will shift.
5277 This approach is different from what is used in the other serial
5278 device driver because the Cyclom is more properly a multiplexer,
5279 not just an aggregation of serial ports on one card.
5281 If there are more cards with more ports than have been
5282 statically allocated above, a warning is printed and the
5283 extra ports are ignored.
5286 static struct tty_operations cy_ops
= {
5290 .put_char
= cy_put_char
,
5291 .flush_chars
= cy_flush_chars
,
5292 .write_room
= cy_write_room
,
5293 .chars_in_buffer
= cy_chars_in_buffer
,
5294 .flush_buffer
= cy_flush_buffer
,
5296 .throttle
= cy_throttle
,
5297 .unthrottle
= cy_unthrottle
,
5298 .set_termios
= cy_set_termios
,
5301 .hangup
= cy_hangup
,
5302 .break_ctl
= cy_break
,
5303 .wait_until_sent
= cy_wait_until_sent
,
5304 .read_proc
= cyclades_get_proc_info
,
5305 .tiocmget
= cy_tiocmget
,
5306 .tiocmset
= cy_tiocmset
,
5312 struct cyclades_port
*info
;
5313 struct cyclades_card
*cinfo
;
5314 int number_z_boards
= 0;
5315 int board
,port
,i
,index
;
5316 unsigned long mailbox
;
5317 unsigned short chip_number
;
5320 cy_serial_driver
= alloc_tty_driver(NR_PORTS
);
5321 if (!cy_serial_driver
)
5325 /* Initialize the tty_driver structure */
5327 cy_serial_driver
->owner
= THIS_MODULE
;
5328 cy_serial_driver
->driver_name
= "cyclades";
5329 cy_serial_driver
->name
= "ttyC";
5330 cy_serial_driver
->devfs_name
= "tts/C";
5331 cy_serial_driver
->major
= CYCLADES_MAJOR
;
5332 cy_serial_driver
->minor_start
= 0;
5333 cy_serial_driver
->type
= TTY_DRIVER_TYPE_SERIAL
;
5334 cy_serial_driver
->subtype
= SERIAL_TYPE_NORMAL
;
5335 cy_serial_driver
->init_termios
= tty_std_termios
;
5336 cy_serial_driver
->init_termios
.c_cflag
=
5337 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5338 cy_serial_driver
->flags
= TTY_DRIVER_REAL_RAW
;
5339 tty_set_operations(cy_serial_driver
, &cy_ops
);
5341 if (tty_register_driver(cy_serial_driver
))
5342 panic("Couldn't register Cyclades serial driver\n");
5344 for (i
= 0; i
< NR_CARDS
; i
++) {
5345 /* base_addr=0 indicates board not found */
5346 cy_card
[i
].base_addr
= NULL
;
5349 /* the code below is responsible to find the boards. Each different
5350 type of board has its own detection routine. If a board is found,
5351 the next cy_card structure available is set by the detection
5352 routine. These functions are responsible for checking the
5353 availability of cy_card and cy_port data structures and updating
5354 the cy_next_channel. */
5356 /* look for isa boards */
5357 cy_isa_nboard
= cy_detect_isa();
5359 /* look for pci boards */
5360 cy_pci_nboard
= cy_detect_pci();
5362 cy_nboard
= cy_isa_nboard
+ cy_pci_nboard
;
5364 /* invalidate remaining cy_card structures */
5365 for (i
= 0 ; i
< NR_CARDS
; i
++) {
5366 if (cy_card
[i
].base_addr
== 0) {
5367 cy_card
[i
].first_line
= -1;
5368 cy_card
[i
].ctl_addr
= NULL
;
5370 cy_card
[i
].bus_index
= 0;
5371 cy_card
[i
].first_line
= 0;
5372 cy_card
[i
].num_chips
= 0;
5375 /* invalidate remaining cy_port structures */
5376 for (i
= cy_next_channel
; i
< NR_PORTS
; i
++) {
5377 cy_port
[i
].line
= -1;
5378 cy_port
[i
].magic
= -1;
5381 /* initialize per-port data structures for each valid board found */
5382 for (board
= 0 ; board
< cy_nboard
; board
++) {
5383 cinfo
= &cy_card
[board
];
5384 if (cinfo
->num_chips
== -1) { /* Cyclades-Z */
5386 mailbox
= cy_readl(&((struct RUNTIME_9060 __iomem
*)
5387 cy_card
[board
].ctl_addr
)->mail_box_0
);
5388 nports
= (mailbox
== ZE_V1
) ? ZE_V1_NPORTS
: 8;
5389 cinfo
->intr_enabled
= 0;
5390 cinfo
->nports
= 0; /* Will be correctly set later, after
5392 spin_lock_init(&cinfo
->card_lock
);
5393 for (port
= cinfo
->first_line
;
5394 port
< cinfo
->first_line
+ nports
;
5397 info
= &cy_port
[port
];
5398 info
->magic
= CYCLADES_MAGIC
;
5399 info
->type
= PORT_STARTECH
;
5403 info
->flags
= STD_COM_FLAGS
;
5405 if (mailbox
== ZO_V1
)
5406 info
->xmit_fifo_size
= CYZ_FIFO_SIZE
;
5408 info
->xmit_fifo_size
= 4 * CYZ_FIFO_SIZE
;
5418 info
->custom_divisor
= 0;
5419 info
->close_delay
= 5*HZ
/10;
5420 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5421 info
->icount
.cts
= info
->icount
.dsr
=
5422 info
->icount
.rng
= info
->icount
.dcd
= 0;
5423 info
->icount
.rx
= info
->icount
.tx
= 0;
5424 info
->icount
.frame
= info
->icount
.parity
= 0;
5425 info
->icount
.overrun
= info
->icount
.brk
= 0;
5429 info
->blocked_open
= 0;
5430 info
->default_threshold
= 0;
5431 info
->default_timeout
= 0;
5432 INIT_WORK(&info
->tqueue
, do_softint
, info
);
5433 init_waitqueue_head(&info
->open_wait
);
5434 init_waitqueue_head(&info
->close_wait
);
5435 init_waitqueue_head(&info
->shutdown_wait
);
5436 init_waitqueue_head(&info
->delta_msr_wait
);
5439 info
->read_status_mask
= 0;
5441 /* Bentson's vars */
5442 info
->jiffies
[0] = 0;
5443 info
->jiffies
[1] = 0;
5444 info
->jiffies
[2] = 0;
5445 info
->rflush_count
= 0;
5446 #ifdef CONFIG_CYZ_INTR
5447 init_timer(&cyz_rx_full_timer
[port
]);
5448 cyz_rx_full_timer
[port
].function
= NULL
;
5452 }else{ /* Cyclom-Y of some kind*/
5453 index
= cinfo
->bus_index
;
5454 spin_lock_init(&cinfo
->card_lock
);
5455 cinfo
->nports
= CyPORTS_PER_CHIP
* cinfo
->num_chips
;
5456 for (port
= cinfo
->first_line
;
5457 port
< cinfo
->first_line
+ cinfo
->nports
;
5460 info
= &cy_port
[port
];
5461 info
->magic
= CYCLADES_MAGIC
;
5462 info
->type
= PORT_CIRRUS
;
5465 info
->flags
= STD_COM_FLAGS
;
5467 info
->xmit_fifo_size
= CyMAX_CHAR_FIFO
;
5468 info
->cor1
= CyPARITY_NONE
|Cy_1_STOP
|Cy_8_BITS
;
5470 info
->cor3
= 0x08; /* _very_ small rcv threshold */
5473 info
->custom_divisor
= 0;
5474 info
->close_delay
= 5*HZ
/10;
5475 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5476 info
->icount
.cts
= info
->icount
.dsr
=
5477 info
->icount
.rng
= info
->icount
.dcd
= 0;
5478 info
->icount
.rx
= info
->icount
.tx
= 0;
5479 info
->icount
.frame
= info
->icount
.parity
= 0;
5480 info
->icount
.overrun
= info
->icount
.brk
= 0;
5481 chip_number
= (port
- cinfo
->first_line
) / 4;
5482 if ((info
->chip_rev
=
5483 cy_readb(cinfo
->base_addr
+
5484 (cy_chip_offset
[chip_number
]<<index
) +
5485 (CyGFRCR
<<index
))) >= CD1400_REV_J
) {
5486 /* It is a CD1400 rev. J or later */
5487 info
->tbpr
= baud_bpr_60
[13]; /* Tx BPR */
5488 info
->tco
= baud_co_60
[13]; /* Tx CO */
5489 info
->rbpr
= baud_bpr_60
[13]; /* Rx BPR */
5490 info
->rco
= baud_co_60
[13]; /* Rx CO */
5492 info
->rtsdtr_inv
= 1;
5494 info
->tbpr
= baud_bpr_25
[13]; /* Tx BPR */
5495 info
->tco
= baud_co_25
[13]; /* Tx CO */
5496 info
->rbpr
= baud_bpr_25
[13]; /* Rx BPR */
5497 info
->rco
= baud_co_25
[13]; /* Rx CO */
5499 info
->rtsdtr_inv
= 0;
5504 info
->blocked_open
= 0;
5505 info
->default_threshold
= 0;
5506 info
->default_timeout
= 0;
5507 INIT_WORK(&info
->tqueue
, do_softint
, info
);
5508 init_waitqueue_head(&info
->open_wait
);
5509 init_waitqueue_head(&info
->close_wait
);
5510 init_waitqueue_head(&info
->shutdown_wait
);
5511 init_waitqueue_head(&info
->delta_msr_wait
);
5514 info
->read_status_mask
=
5515 CyTIMEOUT
| CySPECHAR
| CyBREAK
5516 | CyPARITY
| CyFRAME
| CyOVERRUN
;
5522 #ifndef CONFIG_CYZ_INTR
5523 if (number_z_boards
&& !cyz_timeron
){
5525 cyz_timerlist
.expires
= jiffies
+ 1;
5526 add_timer(&cyz_timerlist
);
5528 printk("Cyclades-Z polling initialized\n");
5531 #endif /* CONFIG_CYZ_INTR */
5538 cy_cleanup_module(void)
5542 #ifndef CONFIG_CYZ_INTR
5545 del_timer(&cyz_timerlist
);
5547 #endif /* CONFIG_CYZ_INTR */
5549 if ((e1
= tty_unregister_driver(cy_serial_driver
)))
5550 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5553 put_tty_driver(cy_serial_driver
);
5555 for (i
= 0; i
< NR_CARDS
; i
++) {
5556 if (cy_card
[i
].base_addr
) {
5557 iounmap(cy_card
[i
].base_addr
);
5558 if (cy_card
[i
].ctl_addr
)
5559 iounmap(cy_card
[i
].ctl_addr
);
5561 #ifndef CONFIG_CYZ_INTR
5562 && cy_card
[i
].num_chips
!= -1 /* not a Z card */
5563 #endif /* CONFIG_CYZ_INTR */
5565 free_irq(cy_card
[i
].irq
, &cy_card
[i
]);
5567 if (cy_card
[i
].pdev
)
5568 pci_release_regions(cy_card
[i
].pdev
);
5573 free_page((unsigned long) tmp_buf
);
5576 } /* cy_cleanup_module */
5578 module_init(cy_init
);
5579 module_exit(cy_cleanup_module
);
5582 /* called by linux/init/main.c to parse command line options */
5584 cy_setup(char *str
, int *ints
)
5589 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
5590 if (cy_isa_addresses
[i
] == 0) break;
5592 for (j
= 1; j
<= ints
[0]; j
++){
5593 if ( i
< NR_ISA_ADDRS
){
5594 cy_isa_addresses
[i
++] = (unsigned char *)(ints
[j
]);
5597 #endif /* CONFIG_ISA */
5601 MODULE_LICENSE("GPL");