4 "$Revision: 2.3.2.4 $$Date: 2000/01/17 09:19:40 $";
7 * linux/drivers/char/cyclades.c
9 * This file contains the driver for the Cyclades Cyclom-Y multiport
12 * Initially written by Randolph Bentson <bentson@grieg.seaslug.org>.
13 * Modified and maintained by Marcio Saito <marcio@cyclades.com>.
14 * Currently maintained by Ivan Passos <ivan@cyclades.com>.
16 * For Technical support and installation problems, please send e-mail
17 * to support@cyclades.com.
19 * Much of the design and some of the code came from serial.c
20 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
21 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
22 * and then fixed as suggested by Michael K. Johnson 12/12/92.
24 * This version supports shared IRQ's (only for PCI boards).
26 * This module exports the following rs232 io functions:
28 * int cy_open(struct tty_struct *tty, struct file *filp);
29 * and the following functions for modularization.
30 * int init_module(void);
31 * void cleanup_module(void);
33 * $Log: cyclades.c,v $
34 * Revision 2.3.2.4 2000/01/17 09:19:40 ivan
35 * Fixed SMP locking in Cyclom-Y interrupt handler.
37 * Revision 2.3.2.3 1999/12/28 12:11:39 ivan
38 * Added a new cyclades_card field called nports to allow the driver to
39 * know the exact number of ports found by the Z firmware after its load;
40 * RX buffer contention prevention logic on interrupt op mode revisited
42 * Revisited printk's for Z debug;
43 * Driver now makes sure that the constant SERIAL_XMIT_SIZE is defined;
45 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
46 * Fixed bug in cyz_poll that would make all ports but port 0
47 * unable to transmit/receive data (Cyclades-Z only);
48 * Implemented logic to prevent the RX buffer from being stuck with data
49 * due to a driver / firmware race condition in interrupt op mode
51 * Fixed bug in block_til_ready logic that would lead to a system crash;
52 * Revisited cy_close spinlock usage;
54 * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
55 * Revisited CONFIG_PCI conditional compilation for PCI board support;
56 * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
57 * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
58 * Removed CTS handling from the driver -- this is now completely handled
59 * by the firmware (Cyclades-Z only);
60 * Flush RX on-board buffers on a port open (Cyclades-Z only);
61 * Fixed handling of ASYNC_SPD_* TTY flags;
62 * Module unload now unmaps all memory area allocated by ioremap;
64 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
65 * Removed CY_PROC conditional compilation;
66 * Implemented SMP-awareness for the driver;
67 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
69 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
70 * (irq=NN) as parameters (only for ISA boards);
71 * Fixed bug in set_line_char that would prevent the Cyclades-Z
72 * ports from being configured at speeds above 115.2Kbps;
73 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
74 * switching from working properly;
75 * The driver now only prints IRQ info for the Cyclades-Z if it's
76 * configured to work in interrupt mode;
78 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
79 * Added support for interrupt mode operation for the Z cards;
80 * Removed the driver inactivity control for the Z;
81 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
82 * the Z firmware is not loaded yet;
83 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
85 * Implemented workaround for IRQ setting loss on the PCI configuration
86 * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
88 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
89 * /proc entry location changed to /proc/tty/driver/cyclades;
90 * Added support to shared IRQ's (only for PCI boards);
91 * Added support for Cobalt Qube2 systems;
92 * IRQ [de]allocation scheme revisited;
93 * BREAK implementation changed in order to make use of the 'break_ctl'
95 * Fixed typo in TTY structure field 'driver_name';
96 * Included a PCI bridge reset and EEPROM reload in the board
97 * initialization code (for both Y and Z series).
99 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
100 * Fixed a bug in cy_wait_until_sent that was preventing the port to be
101 * closed properly after a SIGINT;
102 * Module usage counter scheme revisited;
103 * Added support to the upcoming Y PCI boards (i.e., support to additional
106 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
107 * Removed all unnecessary page-alignement operations in ioremap calls
108 * (ioremap is currently safe for these operations).
110 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
111 * Changed access to PLX PCI bridge registers from I/O to MMIO, in
112 * order to make PLX9050-based boards work with certain motherboards.
114 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
115 * cy_close function now resets (correctly) the tty->closing flag;
116 * JIFFIES_DIFF macro fixed.
118 * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
119 * Fixed bug in cy_close function, which was not informing HW of
120 * which port should have the reception disabled before doing so;
121 * fixed Cyclom-8YoP hardware detection bug.
123 * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
124 * Fixed bug in cy_close function, which causes malfunction
125 * of one of the first 4 ports when a higher port is closed
128 * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
129 * Fixed Cyclom-4Yo hardware detection bug.
131 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
132 * /proc/cyclades implementation with great collaboration of
133 * Marc Lewis <marc@blarg.net>;
134 * cyy_interrupt was changed to avoid occurence of kernel oopses
135 * during PPP operation.
137 * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
138 * General code review in order to comply with 2.1 kernel standards;
139 * data loss prevention for slow devices revisited (cy_wait_until_sent
141 * removed conditional compilation for new/old PCI structure support
142 * (now the driver only supports the new PCI structure).
144 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
145 * added conditional compilation for new/old PCI structure support;
146 * removed kernel series (2.0.x / 2.1.x) conditional compilation.
148 * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
149 * cleaned up the data loss fix;
150 * fixed XON/XOFF handling once more (Cyclades-Z);
151 * general review of the driver routines;
152 * introduction of a mechanism to prevent data loss with slow
153 * printers, by forcing a delay before closing the port.
155 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
156 * fixed detection/handling of new CD1400 in Ye boards;
157 * fixed XON/XOFF handling (Cyclades-Z);
158 * fixed data loss caused by a premature port close;
159 * introduction of a flag that holds the CD1400 version ID per port
160 * (used by the CYGETCD1400VER new ioctl).
162 * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
163 * Code review for the module cleanup routine;
164 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
165 * includes anonymous changes regarding signal_pending.
167 * Revision 2.1 1997/11/01 17:42:41 ivan
168 * Changes in the driver to support Alpha systems (except 8Zo V_1);
169 * BREAK fix for the Cyclades-Z boards;
170 * driver inactivity control by FW implemented;
171 * introduction of flag that allows driver to take advantage of
172 * a special CD1400 feature related to HW flow control;
173 * added support for the CD1400 rev. J (Cyclom-Y boards);
174 * introduction of ioctls to:
175 * - control the rtsdtr_inv flag (Cyclom-Y);
176 * - control the rflow flag (Cyclom-Y);
177 * - adjust the polling interval (Cyclades-Z);
179 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
180 * Fixes related to kernel version conditional
183 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
184 * Compatibility issues between kernels 2.0.x and
185 * 2.1.x (mainly related to clear_bit function).
187 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
188 * Changes to define the memory window according to the
191 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
192 * Changes to suport new cycladesZ boards.
194 * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
195 * Merge of Bentson's and Daniel's version 1.36.4.28.
196 * Corrects bug in cy_detect_pci: check if there are more
197 * ports than the number of static structs allocated.
198 * Warning message during initialization if this driver is
199 * used with the new generation of cycladesZ boards. Those
200 * will be supported only in next release of the driver.
201 * Corrects bug in cy_detect_pci and cy_detect_isa that
202 * returned wrong number of VALID boards, when a cyclomY
203 * was found with no serial modules connected.
204 * Changes to use current (2.1.x) kernel subroutine names
205 * and created macros for compilation with 2.0.x kernel,
206 * instead of the other way around.
208 * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
209 * Change queue_task_irq_off to queue_task_irq.
210 * The inline function queue_task_irq_off (tqueue.h)
211 * was removed from latest releases of 2.1.x kernel.
212 * Use of macro __init to mark the initialization
213 * routines, so memory can be reused.
214 * Also incorporate implementation of critical region
215 * in function cleanup_module() created by anonymous
218 * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
219 * Change to support new firmware that solves DCD problem:
220 * application could fail to receive SIGHUP signal when DCD
223 * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
224 * Changed for suport linux versions 2.1.X.
225 * Backward compatible with linux versions 2.0.X.
226 * Corrected illegal use of filler field in
228 * Deleted some debug messages.
230 * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
231 * Included check for NULL tty pointer in cyz_poll.
233 * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
234 * Bill Foster at Blarg! Online services noticed that
235 * some of the switch elements of -Z modem control
236 * lacked a closing "break;"
238 * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
239 * Changed low water threshold for buffer xmit_buf
241 * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
242 * Marcio provided fix to modem status fetch for -Z
244 * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
245 * improve mapping of -Z control page (thanks to Steve
246 * Price <stevep@fa.tdktca.com> for help on this)
248 * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
249 * shift from CPU-bound to memcopy in cyz_polling operation
251 * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
252 * Added support to set and report higher speeds.
254 * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
255 * Some fixes in the HW flow control for the BETA release.
256 * Don't try to register the IRQ.
258 * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
259 * make sure "cyc" appears in all kernel messages; all soft interrupts
260 * handled by same routine; recognize out-of-band reception; comment
261 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
262 * fix race condition in -Z buffer management; only -Y needs to explictly
263 * flush chars; tidy up some startup messages;
265 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
266 * shift MOD_INC_USE_COUNT location to match
267 * serial.c; purge some diagnostic messages;
269 * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
270 * enable modem status messages and fetch & process them; note
271 * time of last activity type for each port; set_line_char now
272 * supports more than line 0 and treats 0 baud correctly;
273 * get_modem_info senses rs_status;
275 * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
276 * barely works--now's time to turn on
277 * more features 'til it breaks
279 * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
280 * check more -Z board status; shorten boot message
282 * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
283 * fix reference to ch_ctrl in startup; verify return
284 * values from cyz_issue_cmd and cyz_update_channel;
285 * more stuff to get modem control correct;
287 * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
288 * more -Z stuff folded in; re-order changes to put -Z stuff
289 * after -Y stuff (to make changes clearer)
291 * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
292 * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
293 * Add code to send break. Clear firmware ID word at startup (so
294 * that other code won't talk to inactive board).
296 * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
297 * add code for -Z in set_line_char
299 * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
300 * fold more -Z stuff (or in some cases, error messages)
301 * into driver; add text to "don't know what to do" messages.
303 * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
304 * moved compile-time flags near top of file; cosmetic changes
305 * to narrow text (to allow 2-up printing); changed many declarations
306 * to "static" to limit external symbols; shuffled code order to
307 * coalesce -Y and -Z specific code, also to put internal functions
308 * in order of tty_driver structure; added code to recognize -Z
309 * ports (and for moment, do nothing or report error); add cy_startup
310 * to parse boot command line for extra base addresses for ISA probes;
312 * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
313 * reorder some code, fix types of some vars (int vs. long),
314 * add cy_setup to support user declared ISA addresses
316 * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
317 * dump ioctl based firmware load (it's now a user level
318 * program); ensure uninitialzed ports cannot be used
320 * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
321 * rename vars and restructure some code
323 * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
324 * get right status back after boot load
326 * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
327 * successfully loads firmware
329 * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
330 * add more of the code for the boot/load ioctls
332 * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
333 * start to add Z functionality--starting with ioctl
334 * for loading firmware
336 * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
337 * added code to recognize Z/PCI card at initialization; report
338 * presence, but card is not initialized (because firmware needs
341 * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
342 * starting minor number at zero; added missing verify_area
343 * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
345 * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
346 * remove unneeded boot message & fix CLOCAL hardware flow
347 * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
348 * remove unused diagnostic statements; minor 0 is first;
350 * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
351 * The kernel function vremap (available only in later 1.3.xx kernels)
352 * allows the access to memory addresses above the RAM. This revision
353 * of the driver supports PCI boards below 1Mb (device id 0x100) and
354 * above 1Mb (device id 0x101).
356 * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
357 * Some global changes to interrupt handling spilled into
358 * this driver--mostly unused arguments in system function
359 * calls. Also added change by Marcio Saito which should
360 * reduce lost interrupts at startup by fast processors.
362 * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
363 * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
364 * in 1.3.41 kernel to remove a possible race condition, extend
365 * some error messages, and let the driver run as a loadable module
366 * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
367 * possible race condition.
368 * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
370 * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
371 * Changes by Linus Torvalds in 1.3.33 kernel distribution
372 * required due to reordering of driver initialization.
373 * Drivers are now initialized *after* memory management.
375 * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
376 * remove printk from ISR; fix typo
378 * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
379 * Minor fixes in the PCI board support. PCI function calls in
380 * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
381 * <duncan@okay.com>. "bad serial count" message removed.
383 * Revision 1.36.3 1995/08/22 09:19:42 marcio
384 * Cyclom-Y/PCI support added. Changes in the cy_init routine and
385 * board initialization. Changes in the boot messages. The driver
386 * supports up to 4 boards and 64 ports by default.
388 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
389 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
391 * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
392 * add missing break in modem control block in ioctl switch statement
393 * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
395 * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
396 * make sure CTS flow control is set as soon as possible (thanks
397 * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
399 * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
400 * initialize defaults for receive threshold and stale data timeout;
403 * Revision 1.36 1995/03/10 23:33:53 bentson
404 * added support of chips 4-7 in 32 port Cyclom-Ye;
405 * fix cy_interrupt pointer dereference problem
406 * (Joe Portman <baron@aa.net>);
407 * give better error response if open is attempted on non-existent port
408 * (Zachariah Vaum <jchryslr@netcom.com>);
409 * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
410 * conditional compilation for -16Y on systems with fast, noisy bus;
411 * comment out diagnostic print function;
412 * cleaned up table of base addresses;
413 * set receiver time-out period register to correct value,
414 * set receive threshold to better default values,
415 * set chip timer to more accurate 200 Hz ticking,
416 * add code to monitor and modify receive parameters
417 * (Rik Faith <faith@cs.unc.edu> Nick Simicich
418 * <njs@scifi.emi.net>);
420 * Revision 1.35 1994/12/16 13:54:18 steffen
421 * additional patch by Marcio Saito for board detection
422 * Accidently left out in 1.34
424 * Revision 1.34 1994/12/10 12:37:12 steffen
425 * This is the corrected version as suggested by Marcio Saito
427 * Revision 1.33 1994/12/01 22:41:18 bentson
428 * add hooks to support more high speeds directly; add tytso
429 * patch regarding CLOCAL wakeups
431 * Revision 1.32 1994/11/23 19:50:04 bentson
432 * allow direct kernel control of higher signalling rates;
433 * look for cards at additional locations
435 * Revision 1.31 1994/11/16 04:33:28 bentson
436 * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
437 * a problem in chars_in_buffer has been resolved by some
438 * small changes; this should yield smoother output
440 * Revision 1.30 1994/11/16 04:28:05 bentson
441 * Fix from Corey Minyard, Internet: minyard@metronet.com,
442 * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
443 * cy_hangup that appears to clear up much (all?) of the
444 * DTR glitches; also he's added/cleaned-up diagnostic messages
446 * Revision 1.29 1994/11/16 04:16:07 bentson
447 * add change proposed by Ralph Sims, ralphs@halcyon.com, to
448 * operate higher speeds in same way as other serial ports;
449 * add more serial ports (for up to two 16-port muxes).
451 * Revision 1.28 1994/11/04 00:13:16 root
452 * turn off diagnostic messages
454 * Revision 1.27 1994/11/03 23:46:37 root
455 * bunch of changes to bring driver into greater conformance
456 * with the serial.c driver (looking for missed fixes)
458 * Revision 1.26 1994/11/03 22:40:36 root
459 * automatic interrupt probing fixed.
461 * Revision 1.25 1994/11/03 20:17:02 root
462 * start to implement auto-irq
464 * Revision 1.24 1994/11/03 18:01:55 root
465 * still working on modem signals--trying not to drop DTR
466 * during the getty/login processes
468 * Revision 1.23 1994/11/03 17:51:36 root
469 * extend baud rate support; set receive threshold as function
470 * of baud rate; fix some problems with RTS/CTS;
472 * Revision 1.22 1994/11/02 18:05:35 root
473 * changed arguments to udelay to type long to get
474 * delays to be of correct duration
476 * Revision 1.21 1994/11/02 17:37:30 root
477 * employ udelay (after calibrating loops_per_second earlier
478 * in init/main.c) instead of using home-grown delay routines
480 * Revision 1.20 1994/11/02 03:11:38 root
481 * cy_chars_in_buffer forces a return value of 0 to let
482 * login work (don't know why it does); some functions
483 * that were returning EFAULT, now executes the code;
484 * more work on deciding when to disable xmit interrupts;
486 * Revision 1.19 1994/11/01 20:10:14 root
487 * define routine to start transmission interrupts (by enabling
488 * transmit interrupts); directly enable/disable modem interrupts;
490 * Revision 1.18 1994/11/01 18:40:45 bentson
491 * Don't always enable transmit interrupts in startup; interrupt on
492 * TxMpty instead of TxRdy to help characters get out before shutdown;
493 * restructure xmit interrupt to check for chars first and quit if
494 * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
497 * Revision 1.17 1994/10/30 04:39:45 bentson
498 * rename serial_driver and callout_driver to cy_serial_driver and
499 * cy_callout_driver to avoid linkage interference; initialize
500 * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
501 * from cyclades_port structure; add paranoia check to cy_close;
503 * Revision 1.16 1994/10/30 01:14:33 bentson
504 * change major numbers; add some _early_ return statements;
506 * Revision 1.15 1994/10/29 06:43:15 bentson
507 * final tidying up for clean compile; enable some error reporting
509 * Revision 1.14 1994/10/28 20:30:22 Bentson
510 * lots of changes to drag the driver towards the new tty_io
511 * structures and operation. not expected to work, but may
514 * Revision 1.13 1994/07/21 23:08:57 Bentson
515 * add some diagnostic cruft; support 24 lines (for testing
516 * both -8Y and -16Y cards; be more thorough in servicing all
517 * chips during interrupt; add "volatile" a few places to
518 * circumvent compiler optimizations; fix base & offset
519 * computations in block_til_ready (was causing chip 0 to
522 * Revision 1.12 1994/07/19 16:42:11 Bentson
523 * add some hackery for kernel version 1.1.8; expand
524 * error messages; refine timing for delay loops and
525 * declare loop params volatile
527 * Revision 1.11 1994/06/11 21:53:10 bentson
528 * get use of save_car right in transmit interrupt service
530 * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
531 * add some diagnostic printing; try to fix save_car stuff
533 * Revision 1.10 1994/06/11 20:36:08 bentson
534 * clean up compiler warnings
536 * Revision 1.9 1994/06/11 19:42:46 bentson
537 * added a bunch of code to support modem signalling
539 * Revision 1.8 1994/06/11 17:57:07 bentson
540 * recognize break & parity error
542 * Revision 1.7 1994/06/05 05:51:34 bentson
543 * Reorder baud table to be monotonic; add cli to CP; discard
544 * incoming characters and status if the line isn't open; start to
545 * fold code into cy_throttle; start to port get_serial_info,
546 * set_serial_info, get_modem_info, set_modem_info, and send_break
547 * from serial.c; expand cy_ioctl; relocate and expand config_setup;
548 * get flow control characters from tty struct; invalidate ports w/o
551 * Revision 1.6 1994/05/31 18:42:21 bentson
552 * add a loop-breaker in the interrupt service routine;
553 * note when port is initialized so that it can be shut
554 * down under the right conditions; receive works without
557 * Revision 1.5 1994/05/30 00:55:02 bentson
558 * transmit works without obvious errors
560 * Revision 1.4 1994/05/27 18:46:27 bentson
561 * incorporated more code from lib_y.c; can now print short
562 * strings under interrupt control to port zero; seems to
563 * select ports/channels/lines correctly
565 * Revision 1.3 1994/05/25 22:12:44 bentson
566 * shifting from multi-port on a card to proper multiplexor
567 * data structures; added skeletons of most routines
569 * Revision 1.2 1994/05/19 13:21:43 bentson
570 * start to crib from other sources
574 /* If you need to install more boards than NR_CARDS, change the constant
575 in the definition below. No other change is necessary to support up to
576 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
581 If the total number of ports is larger than NR_PORTS, change this
582 constant in the definition below. No other change is necessary to
583 support more boards/ports. */
587 #define ZE_V1_NPORTS 64
592 #define SERIAL_PARANOIA_CHECK
594 #undef CY_DEBUG_THROTTLE
595 #undef CY_DEBUG_OTHER
597 #undef CY_DEBUG_COUNT
599 #undef CY_DEBUG_WAIT_UNTIL_SENT
600 #undef CY_DEBUG_INTERRUPTS
602 #undef CY_ENABLE_MONITORING
606 #define PAUSE __asm__("nop");
611 #define cy_min(a,b) (((a)<(b))?(a):(b))
616 #include <linux/config.h>
617 #include <linux/module.h>
618 #include <linux/errno.h>
619 #include <linux/signal.h>
620 #include <linux/sched.h>
621 #include <linux/timer.h>
622 #include <linux/interrupt.h>
623 #include <linux/tty.h>
624 #include <linux/serial.h>
625 #include <linux/major.h>
626 #include <linux/string.h>
627 #include <linux/fcntl.h>
628 #include <linux/ptrace.h>
629 #include <linux/cyclades.h>
630 #include <linux/mm.h>
631 #include <linux/init.h>
632 #include <linux/delay.h>
633 #include <linux/spinlock.h>
635 #include <asm/system.h>
638 #include <asm/uaccess.h>
639 #include <asm/bitops.h>
641 #define CY_LOCK(info,flags) \
643 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
646 #define CY_UNLOCK(info,flags) \
648 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
651 #include <linux/types.h>
652 #include <linux/kernel.h>
653 #include <linux/pci.h>
654 #include <linux/version.h>
656 #include <linux/stat.h>
657 #include <linux/proc_fs.h>
659 #ifdef CONFIG_COBALT_27
660 #include <asm/page.h>
661 #include <asm/pgtable.h>
663 #define CACHED_TO_UNCACHED(x) (((unsigned long)(x) & \
664 (unsigned long)0x1fffffff) + KSEG1)
667 #define cy_put_user put_user
670 cy_get_user(unsigned long *addr
)
672 unsigned long result
= 0;
673 int error
= get_user (result
, addr
);
675 printk ("cyclades: cy_get_user: error == %d\n", error
);
680 #define MIN(a,b) ((a) < (b) ? (a) : (b))
683 #define IS_CYC_Z(card) ((card).num_chips == -1)
685 #define Z_FPGA_CHECK(card) \
686 ((cy_readl(&((struct RUNTIME_9060 *) \
687 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
689 #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 *) \
690 ((card).ctl_addr))->mail_box_0)) || \
691 Z_FPGA_CHECK(card)) && \
692 (ZFIRM_ID==cy_readl(&((struct FIRM_ID *) \
693 ((card).base_addr+ID_ADDRESS))->signature)))
695 #ifndef SERIAL_XMIT_SIZE
696 #define SERIAL_XMIT_SIZE (MIN(PAGE_SIZE, 4096))
698 #define WAKEUP_CHARS (SERIAL_XMIT_SIZE-256)
700 #define STD_COM_FLAGS (0)
702 #define JIFFIES_DIFF(n, j) ((j) - (n))
704 static DECLARE_TASK_QUEUE(tq_cyclades
);
706 static struct tty_driver cy_serial_driver
, cy_callout_driver
;
707 static int serial_refcount
;
709 #ifndef CONFIG_COBALT_27
710 /* This is the address lookup table. The driver will probe for
711 Cyclom-Y/ISA boards at all addresses in here. If you want the
712 driver to probe addresses at a different address, add it to
713 this table. If the driver is probing some other board and
714 causing problems, remove the offending address from this table.
715 The cy_setup function extracts additional addresses from the
716 boot options line. The form is "cyclades=address,address..."
719 static unsigned char *cy_isa_addresses
[] = {
720 (unsigned char *) 0xD0000,
721 (unsigned char *) 0xD2000,
722 (unsigned char *) 0xD4000,
723 (unsigned char *) 0xD6000,
724 (unsigned char *) 0xD8000,
725 (unsigned char *) 0xDA000,
726 (unsigned char *) 0xDC000,
727 (unsigned char *) 0xDE000,
730 #define NR_ISA_ADDRS (sizeof(cy_isa_addresses)/sizeof(unsigned char*))
733 static int maddr
[NR_CARDS
] = { 0, };
734 static int irq
[NR_CARDS
] = { 0, };
736 MODULE_PARM(maddr
, "1-" __MODULE_STRING(NR_CARDS
) "l");
737 MODULE_PARM(irq
, "1-" __MODULE_STRING(NR_CARDS
) "i");
740 #endif /* CONFIG_COBALT_27 */
742 /* This is the per-card data structure containing address, irq, number of
743 channels, etc. This driver supports a maximum of NR_CARDS cards.
745 static struct cyclades_card cy_card
[NR_CARDS
];
747 /* This is the per-channel data structure containing pointers, flags
748 and variables for the port. This driver supports a maximum of NR_PORTS.
750 static struct cyclades_port cy_port
[NR_PORTS
];
752 static int cy_next_channel
= 0; /* next minor available */
754 static struct tty_struct
*serial_table
[NR_PORTS
];
755 static struct termios
*serial_termios
[NR_PORTS
];
756 static struct termios
*serial_termios_locked
[NR_PORTS
];
759 * tmp_buf is used as a temporary buffer by serial_write. We need to
760 * lock it in case the copy_from_user blocks while swapping in a page,
761 * and some other program tries to do a serial write at the same time.
762 * Since the lock will only come under contention when the system is
763 * swapping and available memory is low, it makes sense to share one
764 * buffer across all the serial ports, since it significantly saves
765 * memory if large numbers of serial ports are open. This buffer is
766 * allocated when the first cy_open occurs.
768 static unsigned char *tmp_buf
;
769 DECLARE_MUTEX(tmp_buf_sem
);
772 * This is used to look up the divisor speeds and the timeouts
773 * We're normally limited to 15 distinct baud rates. The extra
774 * are accessed via settings in info->flags.
775 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
776 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
780 static int baud_table
[] = {
781 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
782 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
785 static char baud_co_25
[] = { /* 25 MHz clock option table */
786 /* value => 00 01 02 03 04 */
787 /* divide by 8 32 128 512 2048 */
788 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
789 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
791 static char baud_bpr_25
[] = { /* 25 MHz baud rate period table */
792 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
793 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
795 static char baud_co_60
[] = { /* 60 MHz clock option table (CD1400 J) */
796 /* value => 00 01 02 03 04 */
797 /* divide by 8 32 128 512 2048 */
798 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
799 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
802 static char baud_bpr_60
[] = { /* 60 MHz baud rate period table (CD1400 J) */
803 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
804 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
807 static char baud_cor3
[] = { /* receive threshold */
808 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
809 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
813 * The Cyclades driver implements HW flow control as any serial driver.
814 * The cyclades_port structure member rflow and the vector rflow_thr
815 * allows us to take advantage of a special feature in the CD1400 to avoid
816 * data loss even when the system interrupt latency is too high. These flags
817 * are to be used only with very special applications. Setting these flags
818 * requires the use of a special cable (DTR and RTS reversed). In the new
819 * CD1400-based boards (rev. 6.00 or later), there is no need for special
823 static char rflow_thr
[] = { /* rflow threshold */
824 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
825 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
828 /* The Cyclom-Ye has placed the sequential chips in non-sequential
829 * address order. This look-up table overcomes that problem.
831 static int cy_chip_offset
[] =
842 /* PCI related definitions */
844 static unsigned short cy_pci_nboard
= 0;
845 static unsigned short cy_isa_nboard
= 0;
846 static unsigned short cy_nboard
= 0;
848 static unsigned short cy_pci_dev_id
[] = {
849 PCI_DEVICE_ID_CYCLOM_Y_Lo
, /* PCI < 1Mb */
850 PCI_DEVICE_ID_CYCLOM_Y_Hi
, /* PCI > 1Mb */
851 PCI_DEVICE_ID_CYCLOM_4Y_Lo
, /* 4Y PCI < 1Mb */
852 PCI_DEVICE_ID_CYCLOM_4Y_Hi
, /* 4Y PCI > 1Mb */
853 PCI_DEVICE_ID_CYCLOM_8Y_Lo
, /* 8Y PCI < 1Mb */
854 PCI_DEVICE_ID_CYCLOM_8Y_Hi
, /* 8Y PCI > 1Mb */
855 PCI_DEVICE_ID_CYCLOM_Z_Lo
, /* Z PCI < 1Mb */
856 PCI_DEVICE_ID_CYCLOM_Z_Hi
, /* Z PCI > 1Mb */
861 static void cy_start(struct tty_struct
*);
862 static void set_line_char(struct cyclades_port
*);
863 static int cyz_issue_cmd(struct cyclades_card
*, uclong
, ucchar
, uclong
);
864 #ifndef CONFIG_COBALT_27
865 static unsigned detect_isa_irq (volatile ucchar
*);
866 #endif /* CONFIG_COBALT_27 */
867 #ifdef CYCLOM_SHOW_STATUS
868 static void show_status(int);
871 static int cyclades_get_proc_info(char *, char **, off_t
, int , int *, void *);
873 #ifndef CONFIG_CYZ_INTR
874 static void cyz_poll(unsigned long);
876 /* The Cyclades-Z polling cycle is defined by this variable */
877 static long cyz_polling_cycle
= CZ_DEF_POLL
;
879 static int cyz_timeron
= 0;
880 static struct timer_list
882 NULL
, NULL
, 0, 0, cyz_poll
884 #else /* CONFIG_CYZ_INTR */
885 static void cyz_rx_restart(unsigned long);
886 static struct timer_list cyz_rx_full_timer
[NR_PORTS
];
887 #endif /* CONFIG_CYZ_INTR */
889 /**************************************************
890 error = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned long));
891 copy_to_user (to, from, count);
892 ***************************************************************
893 error = verify_area(VERIFY_READ, (void *) arg, sizeof(unsigned long *));
894 copy_from_user(to, from, count);
895 **************************************************/
899 serial_paranoia_check(struct cyclades_port
*info
,
900 kdev_t device
, const char *routine
)
902 #ifdef SERIAL_PARANOIA_CHECK
903 static const char *badmagic
=
904 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
905 static const char *badinfo
=
906 "cyc Warning: null cyclades_port for (%s) in %s\n";
907 static const char *badrange
=
908 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
911 printk(badinfo
, kdevname(device
), routine
);
915 if( (long)info
< (long)(&cy_port
[0])
916 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
917 printk(badrange
, kdevname(device
), routine
);
921 if (info
->magic
!= CYCLADES_MAGIC
) {
922 printk(badmagic
, kdevname(device
), routine
);
927 } /* serial_paranoia_check */
930 * This routine is used by the interrupt handler to schedule
931 * processing in the software interrupt portion of the driver
932 * (also known as the "bottom half"). This can be called any
933 * number of times for any channel without harm.
936 cy_sched_event(struct cyclades_port
*info
, int event
)
938 info
->event
|= 1 << event
; /* remember what kind of event and who */
939 queue_task(&info
->tqueue
, &tq_cyclades
); /* it belongs to */
940 mark_bh(CYCLADES_BH
); /* then trigger event */
941 } /* cy_sched_event */
945 * This routine is used to handle the "bottom half" processing for the
946 * serial driver, known also the "software interrupt" processing.
947 * This processing is done at the kernel interrupt level, after the
948 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
949 * is where time-consuming activities which can not be done in the
950 * interrupt driver proper are done; the interrupt driver schedules
951 * them using cy_sched_event(), and they get done here.
953 * This is done through one level of indirection--the task queue.
954 * When a hardware interrupt service routine wants service by the
955 * driver's bottom half, it enqueues the appropriate tq_struct (one
956 * per port) to the tq_cyclades work queue and sets a request flag
957 * via mark_bh for processing that queue. When the time is right,
958 * do_cyclades_bh is called (because of the mark_bh) and it requests
959 * that the work queue be processed.
961 * Although this may seem unwieldy, it gives the system a way to
962 * pass an argument (in this case the pointer to the cyclades_port
963 * structure) to the bottom half of the driver. Previous kernels
964 * had to poll every port to see if that port needed servicing.
969 run_task_queue(&tq_cyclades
);
970 } /* do_cyclades_bh */
973 do_softint(void *private_
)
975 struct cyclades_port
*info
= (struct cyclades_port
*) private_
;
976 struct tty_struct
*tty
;
982 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
983 tty_hangup(info
->tty
);
984 wake_up_interruptible(&info
->open_wait
);
985 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|
986 ASYNC_CALLOUT_ACTIVE
);
988 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
989 wake_up_interruptible(&info
->open_wait
);
991 #ifdef CONFIG_CYZ_INTR
992 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL
, &info
->event
)) {
993 if (cyz_rx_full_timer
[info
->line
].function
== NULL
) {
994 cyz_rx_full_timer
[info
->line
].expires
= jiffies
+ 1;
995 cyz_rx_full_timer
[info
->line
].function
= cyz_rx_restart
;
996 cyz_rx_full_timer
[info
->line
].data
= (unsigned long)info
;
997 add_timer(&cyz_rx_full_timer
[info
->line
]);
1001 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP
, &info
->event
)) {
1002 wake_up_interruptible(&info
->delta_msr_wait
);
1004 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
1005 if((tty
->flags
& (1<< TTY_DO_WRITE_WAKEUP
))
1006 && tty
->ldisc
.write_wakeup
){
1007 (tty
->ldisc
.write_wakeup
)(tty
);
1009 wake_up_interruptible(&tty
->write_wait
);
1012 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP
, &info
->event
)) {
1013 wake_up_interruptible(&info
->shutdown_wait
);
1019 /***********************************************************/
1020 /********* Start of block of Cyclom-Y specific code ********/
1022 /* This routine waits up to 1000 micro-seconds for the previous
1023 command to the Cirrus chip to complete and then issues the
1024 new command. An error is returned if the previous command
1025 didn't finish within the time limit.
1027 This function is only called from inside spinlock-protected code.
1030 cyy_issue_cmd(volatile ucchar
*base_addr
, u_char cmd
, int index
)
1034 /* Check to see that the previous command has completed */
1035 for(i
= 0 ; i
< 100 ; i
++){
1036 if (cy_readb(base_addr
+(CyCCR
<<index
)) == 0){
1041 /* if the CCR never cleared, the previous command
1042 didn't finish within the "reasonable time" */
1043 if (i
== 100) return (-1);
1045 /* Issue the new command */
1046 cy_writeb((u_long
)base_addr
+(CyCCR
<<index
), cmd
);
1049 } /* cyy_issue_cmd */
1051 #ifndef CONFIG_COBALT_27 /* ISA interrupt detection code */
1053 detect_isa_irq (volatile ucchar
*address
)
1056 unsigned long irqs
, flags
;
1057 int save_xir
, save_car
;
1058 int index
= 0; /* IRQ probing is only for ISA */
1060 /* forget possible initially masked and pending IRQ */
1061 irq
= probe_irq_off(probe_irq_on());
1063 /* Clear interrupts on the board first */
1064 cy_writeb((u_long
)address
+ (Cy_ClrIntr
<<index
), 0);
1065 /* Cy_ClrIntr is 0x1800 */
1067 irqs
= probe_irq_on();
1071 /* Enable the Tx interrupts on the CD1400 */
1072 save_flags(flags
); cli();
1073 cy_writeb((u_long
)address
+ (CyCAR
<<index
), 0);
1074 cyy_issue_cmd(address
, CyCHAN_CTL
|CyENB_XMTR
, index
);
1076 cy_writeb((u_long
)address
+ (CyCAR
<<index
), 0);
1077 cy_writeb((u_long
)address
+ (CySRER
<<index
),
1078 cy_readb(address
+ (CySRER
<<index
)) | CyTxMpty
);
1079 restore_flags(flags
);
1084 /* Check which interrupt is in use */
1085 irq
= probe_irq_off(irqs
);
1088 save_xir
= (u_char
) cy_readb(address
+ (CyTIR
<<index
));
1089 save_car
= cy_readb(address
+ (CyCAR
<<index
));
1090 cy_writeb((u_long
)address
+ (CyCAR
<<index
), (save_xir
& 0x3));
1091 cy_writeb((u_long
)address
+ (CySRER
<<index
),
1092 cy_readb(address
+ (CySRER
<<index
)) & ~CyTxMpty
);
1093 cy_writeb((u_long
)address
+ (CyTIR
<<index
), (save_xir
& 0x3f));
1094 cy_writeb((u_long
)address
+ (CyCAR
<<index
), (save_car
));
1095 cy_writeb((u_long
)address
+ (Cy_ClrIntr
<<index
), 0);
1096 /* Cy_ClrIntr is 0x1800 */
1098 return (irq
> 0)? irq
: 0;
1100 #endif /* CONFIG_COBALT_27 */
1102 /* The real interrupt service routine is called
1103 whenever the card wants its hand held--chars
1104 received, out buffer empty, modem change, etc.
1107 cyy_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1109 struct tty_struct
*tty
;
1111 struct cyclades_card
*cinfo
;
1112 struct cyclades_port
*info
;
1113 volatile unsigned char *base_addr
, *card_base_addr
;
1115 int save_xir
, channel
, save_car
;
1117 volatile int char_count
;
1125 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1126 #ifdef CY_DEBUG_INTERRUPTS
1127 printk("cyy_interrupt: spurious interrupt %d\n\r", irq
);
1129 return; /* spurious interrupt */
1132 card_base_addr
= (unsigned char *)cinfo
->base_addr
;
1133 index
= cinfo
->bus_index
;
1136 /* This loop checks all chips in the card. Make a note whenever
1137 _any_ chip had some work to do, as this is considered an
1138 indication that there will be more to do. Only when no chip
1139 has any work does this outermost loop exit.
1143 for ( chip
= 0 ; chip
< cinfo
->num_chips
; chip
++) {
1144 base_addr
= (unsigned char *)
1145 (cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
));
1147 while ( (status
= cy_readb(base_addr
+(CySVRR
<<index
))) != 0x00) {
1149 /* The purpose of the following test is to ensure that
1150 no chip can monopolize the driver. This forces the
1151 chips to be checked in a round-robin fashion (after
1152 draining each of a bunch (1000) of characters).
1154 if(1000<too_many
++){
1157 if (status
& CySRReceive
) { /* reception interrupt */
1158 #ifdef CY_DEBUG_INTERRUPTS
1159 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip
);
1161 /* determine the channel & change to that context */
1162 spin_lock(&cinfo
->card_lock
);
1163 save_xir
= (u_char
) cy_readb(base_addr
+(CyRIR
<<index
));
1164 channel
= (u_short
) (save_xir
& CyIRChannel
);
1165 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1167 info
->last_active
= jiffies
;
1168 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1169 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1171 /* if there is nowhere to put the data, discard it */
1173 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1174 if ( j
== CyIVRRxEx
) { /* exception */
1175 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1176 } else { /* normal character reception */
1177 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1178 while(char_count
--){
1179 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1182 }else{ /* there is an open port for this data */
1184 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1185 if ( j
== CyIVRRxEx
) { /* exception */
1186 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1188 /* For statistics only */
1191 else if(data
& CyFRAME
)
1192 info
->icount
.frame
++;
1193 else if(data
& CyPARITY
)
1194 info
->icount
.parity
++;
1195 else if(data
& CyOVERRUN
)
1196 info
->icount
.overrun
++;
1198 if(data
& info
->ignore_status_mask
){
1202 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
){
1204 if (data
& info
->read_status_mask
){
1206 *tty
->flip
.flag_buf_ptr
++ =
1208 *tty
->flip
.char_buf_ptr
++ =
1209 cy_readb(base_addr
+(CyRDSR
<<index
));
1211 if (info
->flags
& ASYNC_SAK
){
1214 }else if(data
& CyFRAME
){
1215 *tty
->flip
.flag_buf_ptr
++ =
1217 *tty
->flip
.char_buf_ptr
++ =
1218 cy_readb(base_addr
+(CyRDSR
<<index
));
1220 info
->idle_stats
.frame_errs
++;
1221 }else if(data
& CyPARITY
){
1222 *tty
->flip
.flag_buf_ptr
++ =
1224 *tty
->flip
.char_buf_ptr
++ =
1225 cy_readb(base_addr
+(CyRDSR
<<index
));
1227 info
->idle_stats
.parity_errs
++;
1228 }else if(data
& CyOVERRUN
){
1229 *tty
->flip
.flag_buf_ptr
++ =
1231 *tty
->flip
.char_buf_ptr
++ = 0;
1233 /* If the flip buffer itself is
1234 overflowing, we still lose
1235 the next incoming character.
1238 < TTY_FLIPBUF_SIZE
){
1240 *tty
->flip
.flag_buf_ptr
++ =
1242 *tty
->flip
.char_buf_ptr
++ =
1243 cy_readb(base_addr
+(CyRDSR
<<index
));
1246 info
->idle_stats
.overruns
++;
1247 /* These two conditions may imply */
1248 /* a normal read should be done. */
1249 /* }else if(data & CyTIMEOUT){ */
1250 /* }else if(data & CySPECHAR){ */
1252 *tty
->flip
.flag_buf_ptr
++ = 0;
1253 *tty
->flip
.char_buf_ptr
++ = 0;
1257 *tty
->flip
.flag_buf_ptr
++ = 0;
1258 *tty
->flip
.char_buf_ptr
++ = 0;
1262 /* there was a software buffer
1263 overrun and nothing could be
1265 info
->icount
.buf_overrun
++;
1266 info
->idle_stats
.overruns
++;
1268 } else { /* normal character reception */
1269 /* load # chars available from the chip */
1270 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1272 #ifdef CY_ENABLE_MONITORING
1273 ++info
->mon
.int_count
;
1274 info
->mon
.char_count
+= char_count
;
1275 if (char_count
> info
->mon
.char_max
)
1276 info
->mon
.char_max
= char_count
;
1277 info
->mon
.char_last
= char_count
;
1279 info
->idle_stats
.recv_bytes
+= char_count
;
1280 info
->idle_stats
.recv_idle
= jiffies
;
1281 while(char_count
--){
1282 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
){
1286 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1287 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1288 *tty
->flip
.char_buf_ptr
++ = data
;
1295 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1297 /* end of service */
1298 cy_writeb((u_long
)base_addr
+(CyRIR
<<index
), (save_xir
& 0x3f));
1299 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (save_car
));
1300 spin_unlock(&cinfo
->card_lock
);
1304 if (status
& CySRTransmit
) { /* transmission interrupt */
1305 /* Since we only get here when the transmit buffer
1306 is empty, we know we can always stuff a dozen
1308 #ifdef CY_DEBUG_INTERRUPTS
1309 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip
);
1312 /* determine the channel & change to that context */
1313 spin_lock(&cinfo
->card_lock
);
1314 save_xir
= (u_char
) cy_readb(base_addr
+(CyTIR
<<index
));
1315 channel
= (u_short
) (save_xir
& CyIRChannel
);
1316 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1317 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1318 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1320 /* validate the port# (as configured and open) */
1321 if( (i
< 0) || (NR_PORTS
<= i
) ){
1322 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1323 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
1327 info
->last_active
= jiffies
;
1329 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1330 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
1334 /* load the on-chip space for outbound data */
1335 char_count
= info
->xmit_fifo_size
;
1337 if(info
->x_char
) { /* send special char */
1338 outch
= info
->x_char
;
1339 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), outch
);
1345 if (info
->breakon
|| info
->breakoff
) {
1346 if (info
->breakon
) {
1347 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0);
1348 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0x81);
1352 if (info
->breakoff
) {
1353 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0);
1354 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0x83);
1360 while (char_count
-- > 0){
1361 if (!info
->xmit_cnt
){
1362 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1363 cy_readb(base_addr
+(CySRER
<<index
)) &
1367 if (info
->xmit_buf
== 0){
1368 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1369 cy_readb(base_addr
+(CySRER
<<index
)) &
1373 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
1374 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1375 cy_readb(base_addr
+(CySRER
<<index
)) &
1379 /* Because the Embedded Transmit Commands have
1380 been enabled, we must check to see if the
1381 escape character, NULL, is being sent. If it
1382 is, we must ensure that there is room for it
1383 to be doubled in the output stream. Therefore
1384 we no longer advance the pointer when the
1385 character is fetched, but rather wait until
1386 after the check for a NULL output character.
1387 This is necessary because there may not be
1388 room for the two chars needed to send a NULL.)
1390 outch
= info
->xmit_buf
[info
->xmit_tail
];
1393 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1394 & (SERIAL_XMIT_SIZE
- 1);
1395 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), outch
);
1400 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1401 & (SERIAL_XMIT_SIZE
- 1);
1402 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
),
1404 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), 0);
1413 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1414 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1417 /* end of service */
1418 cy_writeb((u_long
)base_addr
+(CyTIR
<<index
),
1420 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (save_car
));
1421 spin_unlock(&cinfo
->card_lock
);
1424 if (status
& CySRModem
) { /* modem interrupt */
1426 /* determine the channel & change to that context */
1427 spin_lock(&cinfo
->card_lock
);
1428 save_xir
= (u_char
) cy_readb(base_addr
+(CyMIR
<<index
));
1429 channel
= (u_short
) (save_xir
& CyIRChannel
);
1430 info
= &cy_port
[channel
+ chip
* 4
1431 + cinfo
->first_line
];
1432 info
->last_active
= jiffies
;
1433 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1434 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1436 mdm_change
= cy_readb(base_addr
+(CyMISR
<<index
));
1437 mdm_status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
1439 if(info
->tty
== 0){/* no place for data, ignore it*/
1442 if (mdm_change
& CyANY_DELTA
) {
1443 /* For statistics only */
1444 if (mdm_change
& CyDCD
) info
->icount
.dcd
++;
1445 if (mdm_change
& CyCTS
) info
->icount
.cts
++;
1446 if (mdm_change
& CyDSR
) info
->icount
.dsr
++;
1447 if (mdm_change
& CyRI
) info
->icount
.rng
++;
1449 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1452 if((mdm_change
& CyDCD
)
1453 && (info
->flags
& ASYNC_CHECK_CD
)){
1454 if(mdm_status
& CyDCD
){
1455 cy_sched_event(info
,
1456 Cy_EVENT_OPEN_WAKEUP
);
1457 }else if(!((info
->flags
1458 & ASYNC_CALLOUT_ACTIVE
)
1460 & ASYNC_CALLOUT_NOHUP
))){
1461 cy_sched_event(info
,
1465 if((mdm_change
& CyCTS
)
1466 && (info
->flags
& ASYNC_CTS_FLOW
)){
1467 if(info
->tty
->hw_stopped
){
1468 if(mdm_status
& CyCTS
){
1469 /* cy_start isn't used
1471 info
->tty
->hw_stopped
= 0;
1472 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1473 cy_readb(base_addr
+(CySRER
<<index
)) |
1475 cy_sched_event(info
,
1476 Cy_EVENT_WRITE_WAKEUP
);
1479 if(!(mdm_status
& CyCTS
)){
1480 /* cy_stop isn't used
1482 info
->tty
->hw_stopped
= 1;
1483 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1484 cy_readb(base_addr
+(CySRER
<<index
)) &
1489 if(mdm_change
& CyDSR
){
1491 if(mdm_change
& CyRI
){
1494 /* end of service */
1495 cy_writeb((u_long
)base_addr
+(CyMIR
<<index
),
1497 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_car
);
1498 spin_unlock(&cinfo
->card_lock
);
1500 } /* end while status != 0 */
1501 } /* end loop for chips... */
1504 /* clear interrupts */
1505 spin_lock(&cinfo
->card_lock
);
1506 cy_writeb((u_long
)card_base_addr
+ (Cy_ClrIntr
<<index
), 0);
1507 /* Cy_ClrIntr is 0x1800 */
1508 spin_unlock(&cinfo
->card_lock
);
1509 } /* cyy_interrupt */
1511 /***********************************************************/
1512 /********* End of block of Cyclom-Y specific code **********/
1513 /******** Start of block of Cyclades-Z specific code *********/
1514 /***********************************************************/
1517 cyz_fetch_msg( struct cyclades_card
*cinfo
,
1518 uclong
*channel
, ucchar
*cmd
, uclong
*param
)
1520 struct FIRM_ID
*firm_id
;
1521 struct ZFW_CTRL
*zfw_ctrl
;
1522 struct BOARD_CTRL
*board_ctrl
;
1523 unsigned long loc_doorbell
;
1525 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1526 if (!ISZLOADED(*cinfo
)){
1529 zfw_ctrl
= (struct ZFW_CTRL
*)
1530 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1531 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1533 loc_doorbell
= cy_readl(&((struct RUNTIME_9060
*)
1534 (cinfo
->ctl_addr
))->loc_doorbell
);
1536 *cmd
= (char)(0xff & loc_doorbell
);
1537 *channel
= cy_readl(&board_ctrl
->fwcmd_channel
);
1538 *param
= (uclong
)cy_readl(&board_ctrl
->fwcmd_param
);
1539 cy_writel(&((struct RUNTIME_9060
*)(cinfo
->ctl_addr
))->loc_doorbell
,
1544 } /* cyz_fetch_msg */
1547 cyz_issue_cmd( struct cyclades_card
*cinfo
,
1548 uclong channel
, ucchar cmd
, uclong param
)
1550 struct FIRM_ID
*firm_id
;
1551 struct ZFW_CTRL
*zfw_ctrl
;
1552 struct BOARD_CTRL
*board_ctrl
;
1553 volatile uclong
*pci_doorbell
;
1556 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1557 if (!ISZLOADED(*cinfo
)){
1560 zfw_ctrl
= (struct ZFW_CTRL
*)
1561 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1562 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1565 pci_doorbell
= (uclong
*)(&((struct RUNTIME_9060
*)
1566 (cinfo
->ctl_addr
))->pci_doorbell
);
1567 while( (cy_readl(pci_doorbell
) & 0xff) != 0){
1568 if (index
++ == 1000){
1569 return((int)(cy_readl(pci_doorbell
) & 0xff));
1573 cy_writel((u_long
)&board_ctrl
->hcmd_channel
, channel
);
1574 cy_writel((u_long
)&board_ctrl
->hcmd_param
, param
);
1575 cy_writel((u_long
)pci_doorbell
, (long)cmd
);
1578 } /* cyz_issue_cmd */
1581 cyz_handle_rx(struct cyclades_port
*info
, volatile struct CH_CTRL
*ch_ctrl
,
1582 volatile struct BUF_CTRL
*buf_ctrl
)
1584 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1585 struct tty_struct
*tty
= info
->tty
;
1586 volatile int char_count
;
1592 volatile uclong rx_put
, rx_get
, new_rx_get
, rx_bufsize
, rx_bufaddr
;
1594 rx_get
= new_rx_get
= cy_readl(&buf_ctrl
->rx_get
);
1595 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1596 rx_bufsize
= cy_readl(&buf_ctrl
->rx_bufsize
);
1597 rx_bufaddr
= cy_readl(&buf_ctrl
->rx_bufaddr
);
1598 if (rx_put
>= rx_get
)
1599 char_count
= rx_put
- rx_get
;
1601 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1604 info
->last_active
= jiffies
;
1605 info
->jiffies
[1] = jiffies
;
1607 #ifdef CY_ENABLE_MONITORING
1608 info
->mon
.int_count
++;
1609 info
->mon
.char_count
+= char_count
;
1610 if (char_count
> info
->mon
.char_max
)
1611 info
->mon
.char_max
= char_count
;
1612 info
->mon
.char_last
= char_count
;
1615 /* flush received characters */
1616 new_rx_get
= (new_rx_get
+ char_count
) & (rx_bufsize
- 1);
1617 info
->rflush_count
++;
1620 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1621 for performance, but because of buffer boundaries, there
1622 may be several steps to the operation */
1623 while(0 < (small_count
=
1624 cy_min((rx_bufsize
- new_rx_get
),
1625 cy_min((TTY_FLIPBUF_SIZE
- tty
->flip
.count
), char_count
))
1627 memcpy_fromio(tty
->flip
.char_buf_ptr
,
1628 (char *)(cinfo
->base_addr
1629 + rx_bufaddr
+ new_rx_get
),
1632 tty
->flip
.char_buf_ptr
+= small_count
;
1633 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, small_count
);
1634 tty
->flip
.flag_buf_ptr
+= small_count
;
1635 new_rx_get
= (new_rx_get
+ small_count
) & (rx_bufsize
- 1);
1636 char_count
-= small_count
;
1637 info
->icount
.rx
+= small_count
;
1638 info
->idle_stats
.recv_bytes
+= small_count
;
1639 tty
->flip
.count
+= small_count
;
1642 while(char_count
--){
1643 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
){
1646 data
= cy_readb(cinfo
->base_addr
+ rx_bufaddr
+ new_rx_get
);
1647 new_rx_get
= (new_rx_get
+ 1) & (rx_bufsize
- 1);
1649 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1650 *tty
->flip
.char_buf_ptr
++ = data
;
1651 info
->idle_stats
.recv_bytes
++;
1655 #ifdef CONFIG_CYZ_INTR
1656 /* Recalculate the number of chars in the RX buffer and issue
1657 a cmd in case it's higher than the RX high water mark */
1658 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1659 if (rx_put
>= rx_get
)
1660 char_count
= rx_put
- rx_get
;
1662 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1663 if(char_count
>= cy_readl(&buf_ctrl
->rx_threshold
)) {
1664 cy_sched_event(info
, Cy_EVENT_Z_RX_FULL
);
1667 info
->idle_stats
.recv_idle
= jiffies
;
1668 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1671 cy_writel(&buf_ctrl
->rx_get
, new_rx_get
);
1676 cyz_handle_tx(struct cyclades_port
*info
, volatile struct CH_CTRL
*ch_ctrl
,
1677 volatile struct BUF_CTRL
*buf_ctrl
)
1679 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1680 struct tty_struct
*tty
= info
->tty
;
1682 volatile int char_count
;
1686 volatile uclong tx_put
, tx_get
, tx_bufsize
, tx_bufaddr
;
1688 if (info
->xmit_cnt
<= 0) /* Nothing to transmit */
1691 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
1692 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
1693 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
1694 tx_bufaddr
= cy_readl(&buf_ctrl
->tx_bufaddr
);
1695 if (tx_put
>= tx_get
)
1696 char_count
= tx_get
- tx_put
- 1 + tx_bufsize
;
1698 char_count
= tx_get
- tx_put
- 1;
1706 if(info
->x_char
) { /* send special char */
1707 data
= info
->x_char
;
1709 cy_writeb((cinfo
->base_addr
+ tx_bufaddr
+ tx_put
), data
);
1710 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1714 info
->last_active
= jiffies
;
1715 info
->jiffies
[2] = jiffies
;
1718 while(0 < (small_count
=
1719 cy_min((tx_bufsize
- tx_put
),
1720 cy_min ((SERIAL_XMIT_SIZE
- info
->xmit_tail
),
1721 cy_min(info
->xmit_cnt
, char_count
))))){
1723 memcpy_toio((char *)(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
),
1724 &info
->xmit_buf
[info
->xmit_tail
],
1727 tx_put
= (tx_put
+ small_count
) & (tx_bufsize
- 1);
1728 char_count
-= small_count
;
1729 info
->icount
.tx
+= small_count
;
1730 info
->xmit_cnt
-= small_count
;
1732 (info
->xmit_tail
+ small_count
) & (SERIAL_XMIT_SIZE
- 1);
1733 info
->last_active
= jiffies
;
1734 info
->jiffies
[2] = jiffies
;
1737 while (info
->xmit_cnt
&& char_count
){
1738 data
= info
->xmit_buf
[info
->xmit_tail
];
1740 info
->xmit_tail
= (info
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
1742 cy_writeb(cinfo
->base_addr
+ tx_bufaddr
+ tx_put
, data
);
1743 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1746 info
->last_active
= jiffies
;
1747 info
->jiffies
[2] = jiffies
;
1751 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1752 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1755 cy_writel(&buf_ctrl
->tx_put
, tx_put
);
1760 cyz_handle_cmd(struct cyclades_card
*cinfo
)
1762 struct tty_struct
*tty
;
1763 struct cyclades_port
*info
;
1764 static volatile struct FIRM_ID
*firm_id
;
1765 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1766 static volatile struct BOARD_CTRL
*board_ctrl
;
1767 static volatile struct CH_CTRL
*ch_ctrl
;
1768 static volatile struct BUF_CTRL
*buf_ctrl
;
1772 uclong hw_ver
, fw_ver
;
1776 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1777 zfw_ctrl
= (struct ZFW_CTRL
*)
1778 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1779 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1780 fw_ver
= cy_readl(&board_ctrl
->fw_version
);
1781 hw_ver
= cy_readl(&((struct RUNTIME_9060
*)(cinfo
->ctl_addr
))->mail_box_0
);
1783 #ifdef CONFIG_CYZ_INTR
1785 cinfo
->nports
= (int) cy_readl(&board_ctrl
->n_channel
);
1788 while(cyz_fetch_msg(cinfo
, &channel
, &cmd
, ¶m
) == 1) {
1791 info
= &cy_port
[channel
+ cinfo
->first_line
];
1792 if((tty
= info
->tty
) == 0) {
1795 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
1796 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
1801 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
1802 *tty
->flip
.char_buf_ptr
++ = 0;
1808 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
1809 *tty
->flip
.char_buf_ptr
++ = 0;
1815 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
1816 *tty
->flip
.char_buf_ptr
++ = 0;
1823 if (info
->flags
& ASYNC_CHECK_CD
){
1826 cy_readl(&ch_ctrl
->rs_status
)) & C_RS_DCD
) {
1827 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
1828 }else if(!((info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1829 &&(info
->flags
& ASYNC_CALLOUT_NOHUP
))){
1830 cy_sched_event(info
, Cy_EVENT_HANGUP
);
1848 cy_sched_event(info
, Cy_EVENT_SHUTDOWN_WAKEUP
);
1851 #ifdef CONFIG_CYZ_INTR
1855 /* Reception Interrupt */
1856 #ifdef CY_DEBUG_INTERRUPTS
1857 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
1858 info
->card
, channel
);
1860 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1865 /* Transmission Interrupt */
1866 #ifdef CY_DEBUG_INTERRUPTS
1867 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
1868 info
->card
, channel
);
1870 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1872 #endif /* CONFIG_CYZ_INTR */
1874 /* should do something with this !!! */
1880 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1882 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1886 #ifdef CONFIG_CYZ_INTR
1888 cyz_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1890 struct cyclades_card
*cinfo
;
1892 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1893 #ifdef CY_DEBUG_INTERRUPTS
1894 printk("cyz_interrupt: spurious interrupt %d\n\r", irq
);
1896 return; /* spurious interrupt */
1899 if (!ISZLOADED(*cinfo
)) {
1900 #ifdef CY_DEBUG_INTERRUPTS
1901 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq
);
1906 /* Handle the interrupts */
1907 cyz_handle_cmd(cinfo
);
1910 } /* cyz_interrupt */
1913 cyz_rx_restart(unsigned long arg
)
1915 struct cyclades_port
*info
= (struct cyclades_port
*)arg
;
1917 int card
= info
->card
;
1918 uclong channel
= (info
->line
) - (cy_card
[card
].first_line
);
1919 unsigned long flags
;
1921 CY_LOCK(info
, flags
);
1922 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK2
, 0L);
1924 printk("cyc:cyz_rx_restart retval on ttyC%d was %x\n",
1925 info
->line
, retval
);
1927 cyz_rx_full_timer
[info
->line
].function
= NULL
;
1928 CY_UNLOCK(info
, flags
);
1931 #else /* CONFIG_CYZ_INTR */
1934 cyz_poll(unsigned long arg
)
1936 struct cyclades_card
*cinfo
;
1937 struct cyclades_port
*info
;
1938 struct tty_struct
*tty
;
1939 static volatile struct FIRM_ID
*firm_id
;
1940 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1941 static volatile struct BOARD_CTRL
*board_ctrl
;
1942 static volatile struct CH_CTRL
*ch_ctrl
;
1943 static volatile struct BUF_CTRL
*buf_ctrl
;
1946 cyz_timerlist
.expires
= jiffies
+ (HZ
);
1947 for (card
= 0 ; card
< NR_CARDS
; card
++){
1948 cinfo
= &cy_card
[card
];
1950 if (!IS_CYC_Z(*cinfo
)) continue;
1951 if (!ISZLOADED(*cinfo
)) continue;
1953 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1954 zfw_ctrl
= (struct ZFW_CTRL
*)
1955 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1956 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1958 /* Skip first polling cycle to avoid racing conditions with the FW */
1959 if (!cinfo
->intr_enabled
) {
1960 cinfo
->nports
= (int) cy_readl(&board_ctrl
->n_channel
);
1961 cinfo
->intr_enabled
= 1;
1965 cyz_handle_cmd(cinfo
);
1967 for (port
= 0 ; port
< cinfo
->nports
; port
++) {
1968 info
= &cy_port
[ port
+ cinfo
->first_line
];
1970 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[port
]);
1971 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[port
]);
1973 cyz_handle_rx(info
, ch_ctrl
, buf_ctrl
);
1974 cyz_handle_tx(info
, ch_ctrl
, buf_ctrl
);
1976 /* poll every 'cyz_polling_cycle' period */
1977 cyz_timerlist
.expires
= jiffies
+ cyz_polling_cycle
;
1979 add_timer(&cyz_timerlist
);
1984 #endif /* CONFIG_CYZ_INTR */
1986 /********** End of block of Cyclades-Z specific code *********/
1987 /***********************************************************/
1990 /* This is called whenever a port becomes active;
1991 interrupts are enabled and DTR & RTS are turned on.
1994 startup(struct cyclades_port
* info
)
1996 unsigned long flags
;
1998 unsigned char *base_addr
;
1999 int card
,chip
,channel
,index
;
2003 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2005 page
= get_free_page(GFP_KERNEL
);
2009 CY_LOCK(info
, flags
);
2011 if (info
->flags
& ASYNC_INITIALIZED
){
2018 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2027 info
->xmit_buf
= (unsigned char *) page
;
2029 CY_UNLOCK(info
, flags
);
2031 set_line_char(info
);
2033 if (!IS_CYC_Z(cy_card
[card
])) {
2036 index
= cy_card
[card
].bus_index
;
2037 base_addr
= (unsigned char*)
2038 (cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
));
2040 #ifdef CY_DEBUG_OPEN
2041 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
2042 card
, chip
, channel
, (long)base_addr
);/**/
2045 CY_LOCK(info
, flags
);
2047 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2049 cy_writeb((ulong
)base_addr
+(CyRTPR
<<index
), (info
->default_timeout
2050 ? info
->default_timeout
: 0x02)); /* 10ms rx timeout */
2052 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyENB_RCVR
|CyENB_XMTR
,index
);
2054 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2055 cy_writeb((ulong
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
2056 cy_writeb((ulong
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
2059 printk("cyc:startup raising DTR\n");
2060 printk(" status: 0x%x, 0x%x\n",
2061 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2062 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2065 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2066 cy_readb(base_addr
+(CySRER
<<index
)) | CyRxData
);
2067 info
->flags
|= ASYNC_INITIALIZED
;
2070 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2072 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2073 info
->breakon
= info
->breakoff
= 0;
2074 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2075 info
->idle_stats
.in_use
=
2076 info
->idle_stats
.recv_idle
=
2077 info
->idle_stats
.xmit_idle
= jiffies
;
2079 CY_UNLOCK(info
, flags
);
2082 struct FIRM_ID
*firm_id
;
2083 struct ZFW_CTRL
*zfw_ctrl
;
2084 struct BOARD_CTRL
*board_ctrl
;
2085 struct CH_CTRL
*ch_ctrl
;
2088 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
2090 firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2091 if (!ISZLOADED(cy_card
[card
])){
2097 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2098 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2099 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2101 #ifdef CY_DEBUG_OPEN
2102 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2103 card
, channel
, (long)base_addr
);/**/
2106 CY_LOCK(info
, flags
);
2108 cy_writel(&ch_ctrl
[channel
].op_mode
, C_CH_ENABLE
);
2110 #ifdef CONFIG_CYZ_INTR
2111 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2112 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2116 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2119 #endif /* CONFIG_CYZ_INTR */
2121 #ifdef CONFIG_CYZ_INTR
2122 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2123 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2126 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2128 #endif /* CONFIG_CYZ_INTR */
2131 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
2133 printk("cyc:startup(1) retval on ttyC%d was %x\n",
2134 info
->line
, retval
);
2137 /* Flush RX buffers before raising DTR and RTS */
2138 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_RX
, 0L);
2140 printk("cyc:startup(2) retval on ttyC%d was %x\n",
2141 info
->line
, retval
);
2144 /* set timeout !!! */
2145 /* set RTS and DTR !!! */
2146 cy_writel(&ch_ctrl
[channel
].rs_control
,
2147 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
| C_RS_DTR
) ;
2148 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2149 channel
, C_CM_IOCTLM
, 0L);
2151 printk("cyc:startup(3) retval on ttyC%d was %x\n",
2152 info
->line
, retval
);
2155 printk("cyc:startup raising Z DTR\n");
2158 /* enable send, recv, modem !!! */
2160 info
->flags
|= ASYNC_INITIALIZED
;
2162 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2164 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2165 info
->breakon
= info
->breakoff
= 0;
2166 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2167 info
->idle_stats
.in_use
=
2168 info
->idle_stats
.recv_idle
=
2169 info
->idle_stats
.xmit_idle
= jiffies
;
2171 CY_UNLOCK(info
, flags
);
2174 #ifdef CY_DEBUG_OPEN
2175 printk(" cyc startup done\n");
2180 CY_UNLOCK(info
, flags
);
2186 start_xmit( struct cyclades_port
*info
)
2188 unsigned long flags
;
2189 unsigned char *base_addr
;
2190 int card
,chip
,channel
,index
;
2193 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2194 if (!IS_CYC_Z(cy_card
[card
])) {
2197 index
= cy_card
[card
].bus_index
;
2198 base_addr
= (unsigned char*)
2199 (cy_card
[card
].base_addr
2200 + (cy_chip_offset
[chip
]<<index
));
2202 CY_LOCK(info
, flags
);
2203 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), channel
);
2204 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2205 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxMpty
);
2206 CY_UNLOCK(info
, flags
);
2208 #ifdef CONFIG_CYZ_INTR
2211 CY_LOCK(info
, flags
);
2212 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK
, 0L);
2214 printk("cyc:start_xmit retval on ttyC%d was %x\n",
2215 info
->line
, retval
);
2217 CY_UNLOCK(info
, flags
);
2218 #else /* CONFIG_CYZ_INTR */
2219 /* Don't have to do anything at this time */
2220 #endif /* CONFIG_CYZ_INTR */
2225 * This routine shuts down a serial port; interrupts are disabled,
2226 * and DTR is dropped if the hangup on close termio flag is on.
2229 shutdown(struct cyclades_port
* info
)
2231 unsigned long flags
;
2232 unsigned char *base_addr
;
2233 int card
,chip
,channel
,index
;
2235 if (!(info
->flags
& ASYNC_INITIALIZED
)){
2240 channel
= info
->line
- cy_card
[card
].first_line
;
2241 if (!IS_CYC_Z(cy_card
[card
])) {
2244 index
= cy_card
[card
].bus_index
;
2245 base_addr
= (unsigned char*)
2246 (cy_card
[card
].base_addr
2247 + (cy_chip_offset
[chip
]<<index
));
2249 #ifdef CY_DEBUG_OPEN
2250 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2251 card
, chip
, channel
, (long)base_addr
);
2254 CY_LOCK(info
, flags
);
2256 /* Clear delta_msr_wait queue to avoid mem leaks. */
2257 wake_up_interruptible(&info
->delta_msr_wait
);
2259 if (info
->xmit_buf
){
2260 unsigned char * temp
;
2261 temp
= info
->xmit_buf
;
2263 free_page((unsigned long) temp
);
2265 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2266 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2267 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
2268 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
2270 printk("cyc shutdown dropping DTR\n");
2271 printk(" status: 0x%x, 0x%x\n",
2272 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2273 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2276 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyDIS_RCVR
,index
);
2277 /* it may be appropriate to clear _XMIT at
2278 some later date (after testing)!!! */
2281 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2283 info
->flags
&= ~ASYNC_INITIALIZED
;
2284 CY_UNLOCK(info
, flags
);
2286 struct FIRM_ID
*firm_id
;
2287 struct ZFW_CTRL
*zfw_ctrl
;
2288 struct BOARD_CTRL
*board_ctrl
;
2289 struct CH_CTRL
*ch_ctrl
;
2292 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
2293 #ifdef CY_DEBUG_OPEN
2294 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2295 card
, channel
, (long)base_addr
);
2298 firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2299 if (!ISZLOADED(cy_card
[card
])) {
2305 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2306 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
2307 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2309 CY_LOCK(info
, flags
);
2311 if (info
->xmit_buf
){
2312 unsigned char * temp
;
2313 temp
= info
->xmit_buf
;
2315 free_page((unsigned long) temp
);
2318 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2319 cy_writel((u_long
)&ch_ctrl
[channel
].rs_control
,
2320 (uclong
)(cy_readl(&ch_ctrl
[channel
].rs_control
) &
2321 ~(C_RS_RTS
| C_RS_DTR
)));
2322 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2323 channel
, C_CM_IOCTLM
, 0L);
2325 printk("cyc:shutdown retval on ttyC%d was %x\n",
2326 info
->line
, retval
);
2329 printk("cyc:shutdown dropping Z DTR\n");
2334 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2336 info
->flags
&= ~ASYNC_INITIALIZED
;
2338 CY_UNLOCK(info
, flags
);
2341 #ifdef CY_DEBUG_OPEN
2342 printk(" cyc shutdown done\n");
2349 * ------------------------------------------------------------
2350 * cy_open() and friends
2351 * ------------------------------------------------------------
2355 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2356 struct cyclades_port
*info
)
2358 DECLARE_WAITQUEUE(wait
, current
);
2359 struct cyclades_card
*cinfo
;
2360 unsigned long flags
;
2361 int chip
, channel
,index
;
2365 cinfo
= &cy_card
[info
->card
];
2366 channel
= info
->line
- cinfo
->first_line
;
2369 * If the device is in the middle of being closed, then block
2370 * until it's done, and then try again.
2372 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2373 if (info
->flags
& ASYNC_CLOSING
) {
2374 interruptible_sleep_on(&info
->close_wait
);
2376 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2380 * If this is a callout device, then just make sure the normal
2381 * device isn't being used.
2383 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
2384 if (info
->flags
& ASYNC_NORMAL_ACTIVE
){
2387 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2388 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
2389 (info
->session
!= current
->session
)){
2392 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2393 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
2394 (info
->pgrp
!= current
->pgrp
)){
2397 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
2402 * If non-blocking mode is set, then make the check up front
2405 if ((filp
->f_flags
& O_NONBLOCK
) ||
2406 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2407 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
){
2410 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2415 * Block waiting for the carrier detect and the line to become
2416 * free (i.e., not in use by the callout). While we are in
2417 * this loop, info->count is dropped by one, so that
2418 * cy_close() knows when to free things. We restore it upon
2419 * exit, either normal or abnormal.
2422 add_wait_queue(&info
->open_wait
, &wait
);
2423 #ifdef CY_DEBUG_OPEN
2424 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2425 info
->line
, info
->count
);/**/
2427 CY_LOCK(info
, flags
);
2428 if (!tty_hung_up_p(filp
))
2430 CY_UNLOCK(info
, flags
);
2431 #ifdef CY_DEBUG_COUNT
2432 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2433 current
->pid
, info
->count
);
2435 info
->blocked_open
++;
2437 if (!IS_CYC_Z(*cinfo
)) {
2440 index
= cinfo
->bus_index
;
2441 base_addr
= (char *)(cinfo
->base_addr
2442 + (cy_chip_offset
[chip
]<<index
));
2445 CY_LOCK(info
, flags
);
2446 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2447 (tty
->termios
->c_cflag
& CBAUD
)){
2448 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2449 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
2450 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
2452 printk("cyc:block_til_ready raising DTR\n");
2453 printk(" status: 0x%x, 0x%x\n",
2454 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2455 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2458 CY_UNLOCK(info
, flags
);
2460 set_current_state(TASK_INTERRUPTIBLE
);
2461 if (tty_hung_up_p(filp
)
2462 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2463 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2464 -EAGAIN
: -ERESTARTSYS
);
2468 CY_LOCK(info
, flags
);
2469 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2470 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2471 && !(info
->flags
& ASYNC_CLOSING
)
2473 || (cy_readb(base_addr
+(CyMSVR1
<<index
)) & CyDCD
))) {
2474 CY_UNLOCK(info
, flags
);
2477 CY_UNLOCK(info
, flags
);
2479 if (signal_pending(current
)) {
2480 retval
= -ERESTARTSYS
;
2483 #ifdef CY_DEBUG_OPEN
2484 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2485 info
->line
, info
->count
);/**/
2490 struct FIRM_ID
*firm_id
;
2491 struct ZFW_CTRL
*zfw_ctrl
;
2492 struct BOARD_CTRL
*board_ctrl
;
2493 struct CH_CTRL
*ch_ctrl
;
2496 base_addr
= (char *)(cinfo
->base_addr
);
2497 firm_id
= (struct FIRM_ID
*)
2498 (base_addr
+ ID_ADDRESS
);
2499 if (!ISZLOADED(*cinfo
)){
2505 (base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2506 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2507 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2510 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2511 (tty
->termios
->c_cflag
& CBAUD
)){
2512 cy_writel(&ch_ctrl
[channel
].rs_control
,
2513 cy_readl(&ch_ctrl
[channel
].rs_control
) |
2514 (C_RS_RTS
| C_RS_DTR
));
2515 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2516 channel
, C_CM_IOCTLM
, 0L);
2518 printk("cyc:block_til_ready retval on ttyC%d was %x\n",
2519 info
->line
, retval
);
2522 printk("cyc:block_til_ready raising Z DTR\n");
2526 set_current_state(TASK_INTERRUPTIBLE
);
2527 if (tty_hung_up_p(filp
)
2528 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2529 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2530 -EAGAIN
: -ERESTARTSYS
);
2533 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2534 && !(info
->flags
& ASYNC_CLOSING
)
2536 || (cy_readl(&ch_ctrl
[channel
].rs_status
) & C_RS_DCD
))) {
2539 if (signal_pending(current
)) {
2540 retval
= -ERESTARTSYS
;
2543 #ifdef CY_DEBUG_OPEN
2544 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2545 info
->line
, info
->count
);/**/
2550 current
->state
= TASK_RUNNING
;
2551 remove_wait_queue(&info
->open_wait
, &wait
);
2552 if (!tty_hung_up_p(filp
)){
2554 #ifdef CY_DEBUG_COUNT
2555 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2556 current
->pid
, info
->count
);
2559 info
->blocked_open
--;
2560 #ifdef CY_DEBUG_OPEN
2561 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2562 info
->line
, info
->count
);/**/
2566 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2568 } /* block_til_ready */
2572 * This routine is called whenever a serial port is opened. It
2573 * performs the serial-specific initialization for the tty structure.
2576 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2578 struct cyclades_port
*info
;
2583 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2584 if ((line
< 0) || (NR_PORTS
<= line
)){
2588 info
= &cy_port
[line
];
2589 if (info
->line
< 0){
2594 /* If the card's firmware hasn't been loaded,
2595 treat it as absent from the system. This
2596 will make the user pay attention.
2598 if (IS_CYC_Z(cy_card
[info
->card
])) {
2599 if (!ISZLOADED(cy_card
[info
->card
])) {
2600 if (((ZE_V1
==cy_readl(&((struct RUNTIME_9060
*)
2601 ((cy_card
[info
->card
]).ctl_addr
))->mail_box_0
)) &&
2602 Z_FPGA_CHECK(cy_card
[info
->card
])) &&
2603 (ZFIRM_HLT
==cy_readl(&((struct FIRM_ID
*)
2604 ((cy_card
[info
->card
]).base_addr
+ID_ADDRESS
))->signature
)))
2606 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2608 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2613 #ifdef CONFIG_CYZ_INTR
2615 /* In case this Z board is operating in interrupt mode, its
2616 interrupts should be enabled as soon as the first open happens
2617 to one of its ports. */
2618 if (!cy_card
[info
->card
].intr_enabled
) {
2619 /* Enable interrupts on the PLX chip */
2620 cy_writew(cy_card
[info
->card
].ctl_addr
+0x68,
2621 cy_readw(cy_card
[info
->card
].ctl_addr
+0x68)|0x0900);
2622 /* Enable interrupts on the FW */
2623 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2624 0, C_CM_IRQ_ENBL
, 0L);
2626 printk("cyc:IRQ enable retval was %x\n", retval
);
2628 cy_card
[info
->card
].intr_enabled
= 1;
2631 #endif /* CONFIG_CYZ_INTR */
2633 #ifdef CY_DEBUG_OTHER
2634 printk("cyc:cy_open ttyC%d\n", info
->line
); /* */
2636 tty
->driver_data
= info
;
2638 if (serial_paranoia_check(info
, tty
->device
, "cy_open")){
2641 #ifdef CY_DEBUG_OPEN
2642 printk("cyc:cy_open ttyC%d, count = %d\n",
2643 info
->line
, info
->count
);/**/
2646 #ifdef CY_DEBUG_COUNT
2647 printk("cyc:cy_open (%d): incrementing count to %d\n",
2648 current
->pid
, info
->count
);
2651 page
= get_free_page(GFP_KERNEL
);
2657 tmp_buf
= (unsigned char *) page
;
2661 * If the port is the middle of closing, bail out now
2663 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2664 if (info
->flags
& ASYNC_CLOSING
)
2665 interruptible_sleep_on(&info
->close_wait
);
2666 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2670 * Start up serial port
2672 retval
= startup(info
);
2677 retval
= block_til_ready(tty
, filp
, info
);
2679 #ifdef CY_DEBUG_OPEN
2680 printk("cyc:cy_open returning after block_til_ready with %d\n",
2686 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
2687 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
2688 *tty
->termios
= info
->normal_termios
;
2690 *tty
->termios
= info
->callout_termios
;
2693 info
->session
= current
->session
;
2694 info
->pgrp
= current
->pgrp
;
2696 #ifdef CY_DEBUG_OPEN
2697 printk(" cyc:cy_open done\n");/**/
2705 * cy_wait_until_sent() --- wait until the transmitter is empty
2708 cy_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2710 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
2711 unsigned char *base_addr
;
2712 int card
,chip
,channel
,index
;
2713 unsigned long orig_jiffies
, char_time
;
2715 if (serial_paranoia_check(info
, tty
->device
, "cy_wait_until_sent"))
2718 if (info
->xmit_fifo_size
== 0)
2719 return; /* Just in case.... */
2722 orig_jiffies
= jiffies
;
2724 * Set the check interval to be 1/5 of the estimated time to
2725 * send a single character, and make it at least 1. The check
2726 * interval should also be less than the timeout.
2728 * Note: we have to use pretty tight timings here to satisfy
2731 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2732 char_time
= char_time
/ 5;
2738 char_time
= MIN(char_time
, timeout
);
2740 * If the transmitter hasn't cleared in twice the approximate
2741 * amount of time to send the entire FIFO, it probably won't
2742 * ever clear. This assumes the UART isn't doing flow
2743 * control, which is currently the case. Hence, if it ever
2744 * takes longer than info->timeout, this is probably due to a
2745 * UART bug of some kind. So, we clamp the timeout parameter at
2748 if (!timeout
|| timeout
> 2*info
->timeout
)
2749 timeout
= 2*info
->timeout
;
2750 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2751 printk("In cy_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2752 printk("jiff=%lu...", jiffies
);
2755 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2756 if (!IS_CYC_Z(cy_card
[card
])) {
2759 index
= cy_card
[card
].bus_index
;
2760 base_addr
= (unsigned char *)
2761 (cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
));
2762 while (cy_readb(base_addr
+(CySRER
<<index
)) & CyTxMpty
) {
2763 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2764 printk("Not clean (jiff=%lu)...", jiffies
);
2766 current
->state
= TASK_INTERRUPTIBLE
;
2767 schedule_timeout(char_time
);
2768 if (signal_pending(current
))
2770 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2773 current
->state
= TASK_RUNNING
;
2777 /* Run one more char cycle */
2778 current
->state
= TASK_INTERRUPTIBLE
;
2779 schedule_timeout(char_time
* 5);
2780 current
->state
= TASK_RUNNING
;
2781 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2782 printk("Clean (jiff=%lu)...done\n", jiffies
);
2787 * This routine is called when a particular tty device is closed.
2790 cy_close(struct tty_struct
*tty
, struct file
*filp
)
2792 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2793 unsigned long flags
;
2795 #ifdef CY_DEBUG_OTHER
2796 printk("cyc:cy_close ttyC%d\n", info
->line
);
2799 if (!info
|| serial_paranoia_check(info
, tty
->device
, "cy_close")){
2803 CY_LOCK(info
, flags
);
2804 /* If the TTY is being hung up, nothing to do */
2805 if (tty_hung_up_p(filp
)) {
2807 CY_UNLOCK(info
, flags
);
2811 #ifdef CY_DEBUG_OPEN
2812 printk("cyc:cy_close ttyC%d, count = %d\n", info
->line
, info
->count
);
2814 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2816 * Uh, oh. tty->count is 1, which means that the tty
2817 * structure will be freed. Info->count should always
2818 * be one in these conditions. If it's greater than
2819 * one, we've got real problems, since it means the
2820 * serial port won't be shutdown.
2822 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2823 "info->count is %d\n", info
->count
);
2826 #ifdef CY_DEBUG_COUNT
2827 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2828 current
->pid
, info
->count
- 1);
2830 if (--info
->count
< 0) {
2831 #ifdef CY_DEBUG_COUNT
2832 printk("cyc:cyc_close setting count to 0\n");
2838 CY_UNLOCK(info
, flags
);
2841 info
->flags
|= ASYNC_CLOSING
;
2843 * Save the termios structure, since this port may have
2844 * separate termios for callout and dialin.
2846 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2847 info
->normal_termios
= *tty
->termios
;
2848 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2849 info
->callout_termios
= *tty
->termios
;
2852 * Now we wait for the transmit buffer to clear; and we notify
2853 * the line discipline to only process XON/XOFF characters.
2856 CY_UNLOCK(info
, flags
);
2857 if (info
->closing_wait
!= CY_CLOSING_WAIT_NONE
) {
2858 tty_wait_until_sent(tty
, info
->closing_wait
);
2860 CY_LOCK(info
, flags
);
2862 if (!IS_CYC_Z(cy_card
[info
->card
])) {
2863 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2864 int index
= cy_card
[info
->card
].bus_index
;
2865 unsigned char *base_addr
= (unsigned char *)
2866 (cy_card
[info
->card
].base_addr
+
2867 (cy_chip_offset
[channel
>>2] <<index
));
2868 /* Stop accepting input */
2870 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2871 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2872 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyRxData
);
2873 if (info
->flags
& ASYNC_INITIALIZED
) {
2874 /* Waiting for on-board buffers to be empty before closing
2876 CY_UNLOCK(info
, flags
);
2877 cy_wait_until_sent(tty
, info
->timeout
);
2878 CY_LOCK(info
, flags
);
2882 /* Waiting for on-board buffers to be empty before closing the port */
2883 unsigned char *base_addr
= (unsigned char *)
2884 cy_card
[info
->card
].base_addr
;
2885 struct FIRM_ID
*firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2886 struct ZFW_CTRL
*zfw_ctrl
=
2887 (struct ZFW_CTRL
*) (base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2888 struct CH_CTRL
*ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2889 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2892 if (cy_readl(&ch_ctrl
[channel
].flow_status
) != C_FS_TXIDLE
) {
2893 retval
= cyz_issue_cmd(&cy_card
[info
->card
], channel
,
2896 printk("cyc:cy_close retval on ttyC%d was %x\n",
2897 info
->line
, retval
);
2899 CY_UNLOCK(info
, flags
);
2900 interruptible_sleep_on(&info
->shutdown_wait
);
2901 CY_LOCK(info
, flags
);
2906 CY_UNLOCK(info
, flags
);
2908 if (tty
->driver
.flush_buffer
)
2909 tty
->driver
.flush_buffer(tty
);
2910 if (tty
->ldisc
.flush_buffer
)
2911 tty
->ldisc
.flush_buffer(tty
);
2912 CY_LOCK(info
, flags
);
2917 if (info
->blocked_open
) {
2918 CY_UNLOCK(info
, flags
);
2919 if (info
->close_delay
) {
2920 current
->state
= TASK_INTERRUPTIBLE
;
2921 schedule_timeout(info
->close_delay
);
2923 wake_up_interruptible(&info
->open_wait
);
2924 CY_LOCK(info
, flags
);
2926 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
2928 wake_up_interruptible(&info
->close_wait
);
2930 #ifdef CY_DEBUG_OTHER
2931 printk(" cyc:cy_close done\n");
2935 CY_UNLOCK(info
, flags
);
2940 /* This routine gets called when tty_write has put something into
2941 * the write_queue. The characters may come from user space or
2944 * This routine will return the number of characters actually
2945 * accepted for writing.
2947 * If the port is not already transmitting stuff, start it off by
2948 * enabling interrupts. The interrupt service routine will then
2949 * ensure that the characters are sent.
2950 * If the port is already active, there is no need to kick it.
2954 cy_write(struct tty_struct
* tty
, int from_user
,
2955 const unsigned char *buf
, int count
)
2957 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2958 unsigned long flags
;
2962 printk("cyc:cy_write ttyC%d\n", info
->line
); /* */
2965 if (serial_paranoia_check(info
, tty
->device
, "cy_write")){
2969 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
){
2973 CY_LOCK(info
, flags
);
2977 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
2978 SERIAL_XMIT_SIZE
- info
->xmit_head
));
2982 c
-= copy_from_user(tmp_buf
, buf
, c
);
2989 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
2990 SERIAL_XMIT_SIZE
- info
->xmit_head
));
2991 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
2992 info
->xmit_head
= ((info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1));
2993 info
->xmit_cnt
+= c
;
3001 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
3002 SERIAL_XMIT_SIZE
- info
->xmit_head
));
3006 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
3007 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
3008 info
->xmit_cnt
+= c
;
3014 CY_UNLOCK(info
, flags
);
3016 info
->idle_stats
.xmit_bytes
+= ret
;
3017 info
->idle_stats
.xmit_idle
= jiffies
;
3019 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
3027 * This routine is called by the kernel to write a single
3028 * character to the tty device. If the kernel uses this routine,
3029 * it must call the flush_chars() routine (if defined) when it is
3030 * done stuffing characters into the driver. If there is no room
3031 * in the queue, the character is ignored.
3034 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
3036 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3037 unsigned long flags
;
3040 printk("cyc:cy_put_char ttyC%d\n", info
->line
);
3043 if (serial_paranoia_check(info
, tty
->device
, "cy_put_char"))
3046 if (!tty
|| !info
->xmit_buf
)
3049 CY_LOCK(info
, flags
);
3050 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
3051 CY_UNLOCK(info
, flags
);
3055 info
->xmit_buf
[info
->xmit_head
++] = ch
;
3056 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
3058 info
->idle_stats
.xmit_bytes
++;
3059 info
->idle_stats
.xmit_idle
= jiffies
;
3060 CY_UNLOCK(info
, flags
);
3065 * This routine is called by the kernel after it has written a
3066 * series of characters to the tty device using put_char().
3069 cy_flush_chars(struct tty_struct
*tty
)
3071 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3074 printk("cyc:cy_flush_chars ttyC%d\n", info
->line
); /* */
3077 if (serial_paranoia_check(info
, tty
->device
, "cy_flush_chars"))
3080 if (info
->xmit_cnt
<= 0 || tty
->stopped
3081 || tty
->hw_stopped
|| !info
->xmit_buf
)
3085 } /* cy_flush_chars */
3089 * This routine returns the numbers of characters the tty driver
3090 * will accept for queuing to be written. This number is subject
3091 * to change as output buffers get emptied, or if the output flow
3092 * control is activated.
3095 cy_write_room(struct tty_struct
*tty
)
3097 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3101 printk("cyc:cy_write_room ttyC%d\n", info
->line
); /* */
3104 if (serial_paranoia_check(info
, tty
->device
, "cy_write_room"))
3106 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
3110 } /* cy_write_room */
3114 cy_chars_in_buffer(struct tty_struct
*tty
)
3116 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3119 if (serial_paranoia_check(info
, tty
->device
, "cy_chars_in_buffer"))
3123 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3125 if (!IS_CYC_Z(cy_card
[card
])) {
3127 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3128 info
->line
, info
->xmit_cnt
); /* */
3130 return info
->xmit_cnt
;
3132 static volatile struct FIRM_ID
*firm_id
;
3133 static volatile struct ZFW_CTRL
*zfw_ctrl
;
3134 static volatile struct CH_CTRL
*ch_ctrl
;
3135 static volatile struct BUF_CTRL
*buf_ctrl
;
3137 volatile uclong tx_put
, tx_get
, tx_bufsize
;
3139 firm_id
= (struct FIRM_ID
*)(cy_card
[card
].base_addr
+ ID_ADDRESS
);
3140 zfw_ctrl
= (struct ZFW_CTRL
*) (cy_card
[card
].base_addr
+
3141 cy_readl(&firm_id
->zfwctrl_addr
));
3142 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3143 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
3145 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
3146 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
3147 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
3148 if (tx_put
>= tx_get
)
3149 char_count
= tx_put
- tx_get
;
3151 char_count
= tx_put
- tx_get
+ tx_bufsize
;
3153 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3154 info
->line
, info
->xmit_cnt
+ char_count
); /* */
3156 return (info
->xmit_cnt
+ char_count
);
3158 } /* cy_chars_in_buffer */
3162 * ------------------------------------------------------------
3163 * cy_ioctl() and friends
3164 * ------------------------------------------------------------
3169 * This routine finds or computes the various line characteristics.
3170 * It used to be called config_setup
3173 set_line_char(struct cyclades_port
* info
)
3175 unsigned long flags
;
3176 unsigned char *base_addr
;
3177 int card
,chip
,channel
,index
;
3178 unsigned cflag
, iflag
;
3179 unsigned short chip_number
;
3184 if (!info
->tty
|| !info
->tty
->termios
){
3187 if (info
->line
== -1){
3190 cflag
= info
->tty
->termios
->c_cflag
;
3191 iflag
= info
->tty
->termios
->c_iflag
;
3194 * Set up the tty->alt_speed kludge
3197 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3198 info
->tty
->alt_speed
= 57600;
3199 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3200 info
->tty
->alt_speed
= 115200;
3201 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3202 info
->tty
->alt_speed
= 230400;
3203 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3204 info
->tty
->alt_speed
= 460800;
3208 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3209 chip_number
= channel
/ 4;
3211 if (!IS_CYC_Z(cy_card
[card
])) {
3213 index
= cy_card
[card
].bus_index
;
3216 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
) {
3219 baud
= tty_get_baud_rate(info
->tty
);
3221 if (baud
> CD1400_MAX_SPEED
) {
3222 baud
= CD1400_MAX_SPEED
;
3224 /* find the baud index */
3225 for (i
= 0; i
< 20; i
++) {
3226 if (baud
== baud_table
[i
]) {
3231 i
= 19; /* CD1400_MAX_SPEED */
3235 if(info
->chip_rev
>= CD1400_REV_J
) {
3236 /* It is a CD1400 rev. J or later */
3237 info
->tbpr
= baud_bpr_60
[i
]; /* Tx BPR */
3238 info
->tco
= baud_co_60
[i
]; /* Tx CO */
3239 info
->rbpr
= baud_bpr_60
[i
]; /* Rx BPR */
3240 info
->rco
= baud_co_60
[i
]; /* Rx CO */
3242 info
->tbpr
= baud_bpr_25
[i
]; /* Tx BPR */
3243 info
->tco
= baud_co_25
[i
]; /* Tx CO */
3244 info
->rbpr
= baud_bpr_25
[i
]; /* Rx BPR */
3245 info
->rco
= baud_co_25
[i
]; /* Rx CO */
3247 if (baud_table
[i
] == 134) {
3248 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/269) + 2;
3249 /* get it right for 134.5 baud */
3250 } else if (baud_table
[i
]) {
3251 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
3252 /* this needs to be propagated into the card info */
3256 /* By tradition (is it a standard?) a baud rate of zero
3257 implies the line should be/has been closed. A bit
3258 later in this routine such a test is performed. */
3260 /* byte size and parity */
3263 info
->cor3
= (info
->default_threshold
3264 ? info
->default_threshold
3265 : baud_cor3
[i
]); /* receive threshold */
3267 switch(cflag
& CSIZE
){
3269 info
->cor1
= Cy_5_BITS
;
3272 info
->cor1
= Cy_6_BITS
;
3275 info
->cor1
= Cy_7_BITS
;
3278 info
->cor1
= Cy_8_BITS
;
3282 info
->cor1
|= Cy_2_STOP
;
3284 if (cflag
& PARENB
){
3285 if (cflag
& PARODD
){
3286 info
->cor1
|= CyPARITY_O
;
3288 info
->cor1
|= CyPARITY_E
;
3291 info
->cor1
|= CyPARITY_NONE
;
3294 /* CTS flow control flag */
3295 if (cflag
& CRTSCTS
){
3296 info
->flags
|= ASYNC_CTS_FLOW
;
3297 info
->cor2
|= CyCtsAE
;
3299 info
->flags
&= ~ASYNC_CTS_FLOW
;
3300 info
->cor2
&= ~CyCtsAE
;
3303 info
->flags
&= ~ASYNC_CHECK_CD
;
3305 info
->flags
|= ASYNC_CHECK_CD
;
3307 /***********************************************
3308 The hardware option, CyRtsAO, presents RTS when
3309 the chip has characters to send. Since most modems
3310 use RTS as reverse (inbound) flow control, this
3311 option is not used. If inbound flow control is
3312 necessary, DTR can be programmed to provide the
3313 appropriate signals for use with a non-standard
3314 cable. Contact Marcio Saito for details.
3315 ***********************************************/
3319 base_addr
= (unsigned char*)
3320 (cy_card
[card
].base_addr
3321 + (cy_chip_offset
[chip
]<<index
));
3323 CY_LOCK(info
, flags
);
3324 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3326 /* tx and rx baud rate */
3328 cy_writeb((u_long
)base_addr
+(CyTCOR
<<index
), info
->tco
);
3329 cy_writeb((u_long
)base_addr
+(CyTBPR
<<index
), info
->tbpr
);
3330 cy_writeb((u_long
)base_addr
+(CyRCOR
<<index
), info
->rco
);
3331 cy_writeb((u_long
)base_addr
+(CyRBPR
<<index
), info
->rbpr
);
3333 /* set line characteristics according configuration */
3335 cy_writeb((u_long
)base_addr
+(CySCHR1
<<index
),
3336 START_CHAR(info
->tty
));
3337 cy_writeb((u_long
)base_addr
+(CySCHR2
<<index
),
3338 STOP_CHAR(info
->tty
));
3339 cy_writeb((u_long
)base_addr
+(CyCOR1
<<index
), info
->cor1
);
3340 cy_writeb((u_long
)base_addr
+(CyCOR2
<<index
), info
->cor2
);
3341 cy_writeb((u_long
)base_addr
+(CyCOR3
<<index
), info
->cor3
);
3342 cy_writeb((u_long
)base_addr
+(CyCOR4
<<index
), info
->cor4
);
3343 cy_writeb((u_long
)base_addr
+(CyCOR5
<<index
), info
->cor5
);
3345 cyy_issue_cmd(base_addr
,
3346 CyCOR_CHANGE
|CyCOR1ch
|CyCOR2ch
|CyCOR3ch
,index
);
3348 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
3349 (u_char
)channel
); /* !!! Is this needed? */
3350 cy_writeb((u_long
)base_addr
+(CyRTPR
<<index
), (info
->default_timeout
3351 ? info
->default_timeout
3352 : 0x02)); /* 10ms rx timeout */
3354 if (C_CLOCAL(info
->tty
)) {
3355 /* without modem intr */
3356 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
3357 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3358 /* act on 1->0 modem transitions */
3359 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3360 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3361 (CyCTS
|rflow_thr
[i
]));
3363 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
), CyCTS
);
3365 /* act on 0->1 modem transitions */
3366 cy_writeb((u_long
)base_addr
+(CyMCOR2
<<index
), CyCTS
);
3368 /* without modem intr */
3369 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
3370 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3371 /* act on 1->0 modem transitions */
3372 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3373 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3374 (CyDSR
|CyCTS
|CyRI
|CyDCD
|rflow_thr
[i
]));
3376 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3377 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3379 /* act on 0->1 modem transitions */
3380 cy_writeb((u_long
)base_addr
+(CyMCOR2
<<index
),
3381 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3384 if(i
== 0){ /* baud rate is zero, turn off line */
3385 if (info
->rtsdtr_inv
) {
3386 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3388 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3391 printk("cyc:set_line_char dropping DTR\n");
3392 printk(" status: 0x%x,
3393 0x%x\n", cy_readb(base_addr
+(CyMSVR1
<<index
)),
3394 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3397 if (info
->rtsdtr_inv
) {
3398 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3400 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3403 printk("cyc:set_line_char raising DTR\n");
3404 printk(" status: 0x%x, 0x%x\n",
3405 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3406 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3411 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3413 CY_UNLOCK(info
, flags
);
3416 struct FIRM_ID
*firm_id
;
3417 struct ZFW_CTRL
*zfw_ctrl
;
3418 struct BOARD_CTRL
*board_ctrl
;
3419 struct CH_CTRL
*ch_ctrl
;
3420 struct BUF_CTRL
*buf_ctrl
;
3424 firm_id
= (struct FIRM_ID
*)
3425 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3426 if (!ISZLOADED(cy_card
[card
])) {
3430 zfw_ctrl
= (struct ZFW_CTRL
*)
3431 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3432 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3433 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3434 buf_ctrl
= &zfw_ctrl
->buf_ctrl
[channel
];
3437 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
) {
3440 baud
= tty_get_baud_rate(info
->tty
);
3442 if (baud
> CYZ_MAX_SPEED
) {
3443 baud
= CYZ_MAX_SPEED
;
3445 cy_writel(&ch_ctrl
->comm_baud
, baud
);
3448 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3449 /* get it right for 134.5 baud */
3451 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud
) + 2;
3452 /* this needs to be propagated into the card info */
3457 /* byte size and parity */
3458 switch(cflag
& CSIZE
){
3459 case CS5
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS5
); break;
3460 case CS6
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS6
); break;
3461 case CS7
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS7
); break;
3462 case CS8
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS8
); break;
3465 cy_writel(&ch_ctrl
->comm_data_l
,
3466 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_2STOP
);
3468 cy_writel(&ch_ctrl
->comm_data_l
,
3469 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_1STOP
);
3471 if (cflag
& PARENB
){
3472 if (cflag
& PARODD
){
3473 cy_writel(&ch_ctrl
->comm_parity
, C_PR_ODD
);
3475 cy_writel(&ch_ctrl
->comm_parity
, C_PR_EVEN
);
3478 cy_writel(&ch_ctrl
->comm_parity
, C_PR_NONE
);
3481 /* CTS flow control flag */
3482 if (cflag
& CRTSCTS
){
3483 cy_writel(&ch_ctrl
->hw_flow
,
3484 cy_readl(&ch_ctrl
->hw_flow
) | C_RS_CTS
| C_RS_RTS
);
3486 cy_writel(&ch_ctrl
->hw_flow
,
3487 cy_readl(&ch_ctrl
->hw_flow
) & ~(C_RS_CTS
| C_RS_RTS
));
3489 /* As the HW flow control is done in firmware, the driver doesn't
3490 need to care about it */
3491 info
->flags
&= ~ASYNC_CTS_FLOW
;
3493 /* XON/XOFF/XANY flow control flags */
3496 sw_flow
|= C_FL_OXX
;
3498 sw_flow
|= C_FL_OIXANY
;
3500 cy_writel(&ch_ctrl
->sw_flow
, sw_flow
);
3502 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
3504 printk("cyc:set_line_char retval on ttyC%d was %x\n",
3505 info
->line
, retval
);
3508 /* CD sensitivity */
3509 if (cflag
& CLOCAL
){
3510 info
->flags
&= ~ASYNC_CHECK_CD
;
3512 info
->flags
|= ASYNC_CHECK_CD
;
3515 if(baud
== 0){ /* baud rate is zero, turn off line */
3516 cy_writel(&ch_ctrl
->rs_control
,
3517 cy_readl(&ch_ctrl
->rs_control
) & ~C_RS_DTR
);
3519 printk("cyc:set_line_char dropping Z DTR\n");
3522 cy_writel(&ch_ctrl
->rs_control
,
3523 cy_readl(&ch_ctrl
->rs_control
) | C_RS_DTR
);
3525 printk("cyc:set_line_char raising Z DTR\n");
3529 retval
= cyz_issue_cmd( &cy_card
[card
], channel
, C_CM_IOCTLM
, 0L);
3531 printk("cyc:set_line_char(2) retval on ttyC%d was %x\n",
3532 info
->line
, retval
);
3536 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3541 } /* set_line_char */
3545 get_serial_info(struct cyclades_port
* info
,
3546 struct serial_struct
* retinfo
)
3548 struct serial_struct tmp
;
3549 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
3553 memset(&tmp
, 0, sizeof(tmp
));
3554 tmp
.type
= info
->type
;
3555 tmp
.line
= info
->line
;
3556 tmp
.port
= info
->card
* 0x100 + info
->line
- cinfo
->first_line
;
3557 tmp
.irq
= cinfo
->irq
;
3558 tmp
.flags
= info
->flags
;
3559 tmp
.close_delay
= info
->close_delay
;
3560 tmp
.baud_base
= info
->baud
;
3561 tmp
.custom_divisor
= 0; /*!!!*/
3562 tmp
.hub6
= 0; /*!!!*/
3563 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
))?-EFAULT
:0;
3564 } /* get_serial_info */
3568 set_serial_info(struct cyclades_port
* info
,
3569 struct serial_struct
* new_info
)
3571 struct serial_struct new_serial
;
3572 struct cyclades_port old_info
;
3574 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
3578 if (!capable(CAP_SYS_ADMIN
)) {
3579 if ((new_serial
.close_delay
!= info
->close_delay
) ||
3580 (new_serial
.baud_base
!= info
->baud
) ||
3581 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
3582 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
3584 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
3585 (new_serial
.flags
& ASYNC_USR_MASK
));
3586 info
->baud
= new_serial
.baud_base
;
3587 goto check_and_exit
;
3592 * OK, past this point, all the error checking has been done.
3593 * At this point, we start making changes.....
3596 info
->baud
= new_serial
.baud_base
;
3597 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
3598 (new_serial
.flags
& ASYNC_FLAGS
));
3599 info
->close_delay
= new_serial
.close_delay
* HZ
/100;
3600 info
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
3603 if (info
->flags
& ASYNC_INITIALIZED
){
3604 set_line_char(info
);
3607 return startup(info
);
3609 } /* set_serial_info */
3613 get_modem_info(struct cyclades_port
* info
, unsigned int *value
)
3615 int card
,chip
,channel
,index
;
3616 unsigned char *base_addr
;
3617 unsigned long flags
;
3618 unsigned char status
;
3619 unsigned long lstatus
;
3620 unsigned int result
;
3621 struct FIRM_ID
*firm_id
;
3622 struct ZFW_CTRL
*zfw_ctrl
;
3623 struct BOARD_CTRL
*board_ctrl
;
3624 struct CH_CTRL
*ch_ctrl
;
3627 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3628 if (!IS_CYC_Z(cy_card
[card
])) {
3631 index
= cy_card
[card
].bus_index
;
3632 base_addr
= (unsigned char*)
3633 (cy_card
[card
].base_addr
3634 + (cy_chip_offset
[chip
]<<index
));
3636 CY_LOCK(info
, flags
);
3637 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3638 status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
3639 status
|= cy_readb(base_addr
+(CyMSVR2
<<index
));
3640 CY_UNLOCK(info
, flags
);
3642 if (info
->rtsdtr_inv
) {
3643 result
= ((status
& CyRTS
) ? TIOCM_DTR
: 0)
3644 | ((status
& CyDTR
) ? TIOCM_RTS
: 0);
3646 result
= ((status
& CyRTS
) ? TIOCM_RTS
: 0)
3647 | ((status
& CyDTR
) ? TIOCM_DTR
: 0);
3649 result
|= ((status
& CyDCD
) ? TIOCM_CAR
: 0)
3650 | ((status
& CyRI
) ? TIOCM_RNG
: 0)
3651 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
3652 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
3654 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
3656 if (cy_card
[card
].num_chips
!= -1){
3660 firm_id
= (struct FIRM_ID
*)
3661 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3662 if (ISZLOADED(cy_card
[card
])) {
3663 zfw_ctrl
= (struct ZFW_CTRL
*)
3664 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3665 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3666 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3667 lstatus
= cy_readl(&ch_ctrl
[channel
].rs_status
);
3668 result
= ((lstatus
& C_RS_RTS
) ? TIOCM_RTS
: 0)
3669 | ((lstatus
& C_RS_DTR
) ? TIOCM_DTR
: 0)
3670 | ((lstatus
& C_RS_DCD
) ? TIOCM_CAR
: 0)
3671 | ((lstatus
& C_RS_RI
) ? TIOCM_RNG
: 0)
3672 | ((lstatus
& C_RS_DSR
) ? TIOCM_DSR
: 0)
3673 | ((lstatus
& C_RS_CTS
) ? TIOCM_CTS
: 0);
3680 return cy_put_user(result
, value
);
3681 } /* get_modem_info */
3685 set_modem_info(struct cyclades_port
* info
, unsigned int cmd
,
3686 unsigned int *value
)
3688 int card
,chip
,channel
,index
;
3689 unsigned char *base_addr
;
3690 unsigned long flags
;
3691 unsigned int arg
= cy_get_user((unsigned long *) value
);
3692 struct FIRM_ID
*firm_id
;
3693 struct ZFW_CTRL
*zfw_ctrl
;
3694 struct BOARD_CTRL
*board_ctrl
;
3695 struct CH_CTRL
*ch_ctrl
;
3699 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3700 if (!IS_CYC_Z(cy_card
[card
])) {
3703 index
= cy_card
[card
].bus_index
;
3704 base_addr
= (unsigned char*)
3705 (cy_card
[card
].base_addr
3706 + (cy_chip_offset
[chip
]<<index
));
3710 if (arg
& TIOCM_RTS
){
3711 CY_LOCK(info
, flags
);
3712 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3713 if (info
->rtsdtr_inv
) {
3714 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3716 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3718 CY_UNLOCK(info
, flags
);
3720 if (arg
& TIOCM_DTR
){
3721 CY_LOCK(info
, flags
);
3722 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3723 if (info
->rtsdtr_inv
) {
3724 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3726 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3729 printk("cyc:set_modem_info raising DTR\n");
3730 printk(" status: 0x%x, 0x%x\n",
3731 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3732 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3734 CY_UNLOCK(info
, flags
);
3738 if (arg
& TIOCM_RTS
){
3739 CY_LOCK(info
, flags
);
3740 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
3742 if (info
->rtsdtr_inv
) {
3743 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3745 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3747 CY_UNLOCK(info
, flags
);
3749 if (arg
& TIOCM_DTR
){
3750 CY_LOCK(info
, flags
);
3751 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3752 if (info
->rtsdtr_inv
) {
3753 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3755 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3758 printk("cyc:set_modem_info dropping DTR\n");
3759 printk(" status: 0x%x, 0x%x\n",
3760 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3761 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3763 CY_UNLOCK(info
, flags
);
3767 if (arg
& TIOCM_RTS
){
3768 CY_LOCK(info
, flags
);
3769 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3770 if (info
->rtsdtr_inv
) {
3771 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3773 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3775 CY_UNLOCK(info
, flags
);
3777 CY_LOCK(info
, flags
);
3778 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3779 if (info
->rtsdtr_inv
) {
3780 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3782 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3784 CY_UNLOCK(info
, flags
);
3786 if (arg
& TIOCM_DTR
){
3787 CY_LOCK(info
, flags
);
3788 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3789 if (info
->rtsdtr_inv
) {
3790 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3792 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3795 printk("cyc:set_modem_info raising DTR\n");
3796 printk(" status: 0x%x, 0x%x\n",
3797 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3798 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3800 CY_UNLOCK(info
, flags
);
3802 CY_LOCK(info
, flags
);
3803 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3804 if (info
->rtsdtr_inv
) {
3805 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3807 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3811 printk("cyc:set_modem_info dropping DTR\n");
3812 printk(" status: 0x%x, 0x%x\n",
3813 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3814 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3816 CY_UNLOCK(info
, flags
);
3823 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
3825 firm_id
= (struct FIRM_ID
*)
3826 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3827 if (ISZLOADED(cy_card
[card
])) {
3828 zfw_ctrl
= (struct ZFW_CTRL
*)
3829 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3830 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3831 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3835 if (arg
& TIOCM_RTS
){
3836 CY_LOCK(info
, flags
);
3837 cy_writel(&ch_ctrl
[channel
].rs_control
,
3838 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3839 CY_UNLOCK(info
, flags
);
3841 if (arg
& TIOCM_DTR
){
3842 CY_LOCK(info
, flags
);
3843 cy_writel(&ch_ctrl
[channel
].rs_control
,
3844 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3846 printk("cyc:set_modem_info raising Z DTR\n");
3848 CY_UNLOCK(info
, flags
);
3852 if (arg
& TIOCM_RTS
){
3853 CY_LOCK(info
, flags
);
3854 cy_writel(&ch_ctrl
[channel
].rs_control
,
3855 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3856 CY_UNLOCK(info
, flags
);
3858 if (arg
& TIOCM_DTR
){
3859 CY_LOCK(info
, flags
);
3860 cy_writel(&ch_ctrl
[channel
].rs_control
,
3861 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3863 printk("cyc:set_modem_info clearing Z DTR\n");
3865 CY_UNLOCK(info
, flags
);
3869 if (arg
& TIOCM_RTS
){
3870 CY_LOCK(info
, flags
);
3871 cy_writel(&ch_ctrl
[channel
].rs_control
,
3872 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3873 CY_UNLOCK(info
, flags
);
3875 CY_LOCK(info
, flags
);
3876 cy_writel(&ch_ctrl
[channel
].rs_control
,
3877 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3878 CY_UNLOCK(info
, flags
);
3880 if (arg
& TIOCM_DTR
){
3881 CY_LOCK(info
, flags
);
3882 cy_writel(&ch_ctrl
[channel
].rs_control
,
3883 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3885 printk("cyc:set_modem_info raising Z DTR\n");
3887 CY_UNLOCK(info
, flags
);
3889 CY_LOCK(info
, flags
);
3890 cy_writel(&ch_ctrl
[channel
].rs_control
,
3891 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3893 printk("cyc:set_modem_info clearing Z DTR\n");
3895 CY_UNLOCK(info
, flags
);
3904 CY_LOCK(info
, flags
);
3905 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3906 channel
, C_CM_IOCTLM
,0L);
3908 printk("cyc:set_modem_info retval on ttyC%d was %x\n",
3909 info
->line
, retval
);
3911 CY_UNLOCK(info
, flags
);
3914 } /* set_modem_info */
3917 * cy_break() --- routine which turns the break handling on or off
3920 cy_break(struct tty_struct
*tty
, int break_state
)
3922 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3923 unsigned long flags
;
3925 if (serial_paranoia_check(info
, tty
->device
, "cy_break"))
3928 CY_LOCK(info
, flags
);
3929 if (!IS_CYC_Z(cy_card
[info
->card
])) {
3930 /* Let the transmit ISR take care of this (since it
3931 requires stuffing characters into the output stream).
3933 if (break_state
== -1) {
3934 if (!info
->breakon
) {
3936 if (!info
->xmit_cnt
) {
3937 CY_UNLOCK(info
, flags
);
3939 CY_LOCK(info
, flags
);
3943 if (!info
->breakoff
) {
3945 if (!info
->xmit_cnt
) {
3946 CY_UNLOCK(info
, flags
);
3948 CY_LOCK(info
, flags
);
3955 if (break_state
== -1) {
3956 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3957 (info
->line
) - (cy_card
[info
->card
].first_line
),
3958 C_CM_SET_BREAK
, 0L);
3960 printk("cyc:cy_break (set) retval on ttyC%d was %x\n",
3961 info
->line
, retval
);
3964 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3965 (info
->line
) - (cy_card
[info
->card
].first_line
),
3966 C_CM_CLR_BREAK
, 0L);
3968 printk("cyc:cy_break (clr) retval on ttyC%d was %x\n",
3969 info
->line
, retval
);
3973 CY_UNLOCK(info
, flags
);
3977 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor
* mon
)
3980 if(copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
3982 info
->mon
.int_count
= 0;
3983 info
->mon
.char_count
= 0;
3984 info
->mon
.char_max
= 0;
3985 info
->mon
.char_last
= 0;
3991 set_threshold(struct cyclades_port
* info
, unsigned long value
)
3993 unsigned char *base_addr
;
3994 int card
,channel
,chip
,index
;
3995 unsigned long flags
;
3998 channel
= info
->line
- cy_card
[card
].first_line
;
3999 if (!IS_CYC_Z(cy_card
[card
])) {
4002 index
= cy_card
[card
].bus_index
;
4003 base_addr
= (unsigned char*)
4004 (cy_card
[card
].base_addr
4005 + (cy_chip_offset
[chip
]<<index
));
4007 info
->cor3
&= ~CyREC_FIFO
;
4008 info
->cor3
|= value
& CyREC_FIFO
;
4010 CY_LOCK(info
, flags
);
4011 cy_writeb((u_long
)base_addr
+(CyCOR3
<<index
), info
->cor3
);
4012 cyy_issue_cmd(base_addr
,CyCOR_CHANGE
|CyCOR3ch
,index
);
4013 CY_UNLOCK(info
, flags
);
4018 }/* set_threshold */
4022 get_threshold(struct cyclades_port
* info
, unsigned long *value
)
4024 unsigned char *base_addr
;
4025 int card
,channel
,chip
,index
;
4029 channel
= info
->line
- cy_card
[card
].first_line
;
4030 if (!IS_CYC_Z(cy_card
[card
])) {
4033 index
= cy_card
[card
].bus_index
;
4034 base_addr
= (unsigned char*)
4035 (cy_card
[card
].base_addr
4036 + (cy_chip_offset
[chip
]<<index
));
4038 tmp
= cy_readb(base_addr
+(CyCOR3
<<index
)) & CyREC_FIFO
;
4039 return cy_put_user(tmp
,value
);
4044 }/* get_threshold */
4048 set_default_threshold(struct cyclades_port
* info
, unsigned long value
)
4050 info
->default_threshold
= value
& 0x0f;
4052 }/* set_default_threshold */
4056 get_default_threshold(struct cyclades_port
* info
, unsigned long *value
)
4058 return cy_put_user(info
->default_threshold
,value
);
4059 }/* get_default_threshold */
4063 set_timeout(struct cyclades_port
* info
, unsigned long value
)
4065 unsigned char *base_addr
;
4066 int card
,channel
,chip
,index
;
4067 unsigned long flags
;
4070 channel
= info
->line
- cy_card
[card
].first_line
;
4071 if (!IS_CYC_Z(cy_card
[card
])) {
4074 index
= cy_card
[card
].bus_index
;
4075 base_addr
= (unsigned char*)
4076 (cy_card
[card
].base_addr
4077 + (cy_chip_offset
[chip
]<<index
));
4079 CY_LOCK(info
, flags
);
4080 cy_writeb((u_long
)base_addr
+(CyRTPR
<<index
), value
& 0xff);
4081 CY_UNLOCK(info
, flags
);
4090 get_timeout(struct cyclades_port
* info
, unsigned long *value
)
4092 unsigned char *base_addr
;
4093 int card
,channel
,chip
,index
;
4097 channel
= info
->line
- cy_card
[card
].first_line
;
4098 if (!IS_CYC_Z(cy_card
[card
])) {
4101 index
= cy_card
[card
].bus_index
;
4102 base_addr
= (unsigned char*)
4103 (cy_card
[card
].base_addr
4104 + (cy_chip_offset
[chip
]<<index
));
4106 tmp
= cy_readb(base_addr
+(CyRTPR
<<index
));
4107 return cy_put_user(tmp
,value
);
4116 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
4118 info
->default_timeout
= value
& 0xff;
4120 }/* set_default_timeout */
4124 get_default_timeout(struct cyclades_port
* info
, unsigned long *value
)
4126 return cy_put_user(info
->default_timeout
,value
);
4127 }/* get_default_timeout */
4130 * This routine allows the tty driver to implement device-
4131 * specific ioctl's. If the ioctl number passed in cmd is
4132 * not recognized by the driver, it should return ENOIOCTLCMD.
4135 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
4136 unsigned int cmd
, unsigned long arg
)
4138 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4139 struct cyclades_icount cprev
, cnow
; /* kernel counter temps */
4140 struct serial_icounter_struct
*p_cuser
; /* user space */
4142 unsigned long flags
;
4144 if (serial_paranoia_check(info
, tty
->device
, "cy_ioctl"))
4147 #ifdef CY_DEBUG_OTHER
4148 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
4149 info
->line
, cmd
, arg
); /* */
4154 ret_val
= get_mon_info(info
, (struct cyclades_monitor
*)arg
);
4157 ret_val
= get_threshold(info
, (unsigned long *)arg
);
4160 ret_val
= set_threshold(info
, (unsigned long)arg
);
4162 case CYGETDEFTHRESH
:
4163 ret_val
= get_default_threshold(info
, (unsigned long *)arg
);
4165 case CYSETDEFTHRESH
:
4166 ret_val
= set_default_threshold(info
, (unsigned long)arg
);
4169 ret_val
= get_timeout(info
, (unsigned long *)arg
);
4172 ret_val
= set_timeout(info
, (unsigned long)arg
);
4174 case CYGETDEFTIMEOUT
:
4175 ret_val
= get_default_timeout(info
, (unsigned long *)arg
);
4177 case CYSETDEFTIMEOUT
:
4178 ret_val
= set_default_timeout(info
, (unsigned long)arg
);
4181 info
->rflow
= (int)arg
;
4185 ret_val
= info
->rflow
;
4187 case CYSETRTSDTR_INV
:
4188 info
->rtsdtr_inv
= (int)arg
;
4191 case CYGETRTSDTR_INV
:
4192 ret_val
= info
->rtsdtr_inv
;
4195 if (copy_to_user((void *)arg
, (void *)&cy_card
[info
->card
],
4196 sizeof (struct cyclades_card
))) {
4202 case CYGETCD1400VER
:
4203 ret_val
= info
->chip_rev
;
4205 #ifndef CONFIG_CYZ_INTR
4206 case CYZSETPOLLCYCLE
:
4207 cyz_polling_cycle
= (arg
* HZ
) / 1000;
4210 case CYZGETPOLLCYCLE
:
4211 ret_val
= (cyz_polling_cycle
* 1000) / HZ
;
4213 #endif /* CONFIG_CYZ_INTR */
4215 info
->closing_wait
= (unsigned short)arg
* HZ
/100;
4219 ret_val
= info
->closing_wait
/ (HZ
/100);
4222 ret_val
= get_modem_info(info
, (unsigned int *) arg
);
4227 ret_val
= set_modem_info(info
, cmd
, (unsigned int *) arg
);
4230 ret_val
= get_serial_info(info
, (struct serial_struct
*) arg
);
4233 ret_val
= set_serial_info(info
, (struct serial_struct
*) arg
);
4236 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4237 * - mask passed in arg for lines of interest
4238 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4239 * Caller should use TIOCGICOUNT to see which one it was
4242 CY_LOCK(info
, flags
);
4243 /* note the counters on entry */
4244 cprev
= info
->icount
;
4245 CY_UNLOCK(info
, flags
);
4247 interruptible_sleep_on(&info
->delta_msr_wait
);
4248 /* see if a signal did it */
4249 if (signal_pending(current
)) {
4250 return -ERESTARTSYS
;
4253 CY_LOCK(info
, flags
);
4254 cnow
= info
->icount
; /* atomic copy */
4255 CY_UNLOCK(info
, flags
);
4257 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
4258 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
4259 return -EIO
; /* no change => error */
4261 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
4262 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
4263 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
4264 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
4272 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4273 * Return: write counters to the user passed counter struct
4274 * NB: both 1->0 and 0->1 transitions are counted except for
4275 * RI where only 0->1 is counted.
4278 CY_LOCK(info
, flags
);
4279 cnow
= info
->icount
;
4280 CY_UNLOCK(info
, flags
);
4281 p_cuser
= (struct serial_icounter_struct
*) arg
;
4282 ret_val
= put_user(cnow
.cts
, &p_cuser
->cts
);
4283 if (ret_val
) return ret_val
;
4284 ret_val
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
4285 if (ret_val
) return ret_val
;
4286 ret_val
= put_user(cnow
.rng
, &p_cuser
->rng
);
4287 if (ret_val
) return ret_val
;
4288 ret_val
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
4289 if (ret_val
) return ret_val
;
4290 ret_val
= put_user(cnow
.rx
, &p_cuser
->rx
);
4291 if (ret_val
) return ret_val
;
4292 ret_val
= put_user(cnow
.tx
, &p_cuser
->tx
);
4293 if (ret_val
) return ret_val
;
4294 ret_val
= put_user(cnow
.frame
, &p_cuser
->frame
);
4295 if (ret_val
) return ret_val
;
4296 ret_val
= put_user(cnow
.overrun
, &p_cuser
->overrun
);
4297 if (ret_val
) return ret_val
;
4298 ret_val
= put_user(cnow
.parity
, &p_cuser
->parity
);
4299 if (ret_val
) return ret_val
;
4300 ret_val
= put_user(cnow
.brk
, &p_cuser
->brk
);
4301 if (ret_val
) return ret_val
;
4302 ret_val
= put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
4303 if (ret_val
) return ret_val
;
4307 ret_val
= -ENOIOCTLCMD
;
4310 #ifdef CY_DEBUG_OTHER
4311 printk(" cyc:cy_ioctl done\n");
4319 * This routine allows the tty driver to be notified when
4320 * device's termios settings have changed. Note that a
4321 * well-designed tty driver should be prepared to accept the case
4322 * where old == NULL, and try to do something rational.
4325 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
4327 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4329 #ifdef CY_DEBUG_OTHER
4330 printk("cyc:cy_set_termios ttyC%d\n", info
->line
);
4333 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
4334 ((tty
->termios
->c_iflag
& (IXON
|IXANY
)) ==
4335 (old_termios
->c_iflag
& (IXON
|IXANY
))))
4337 set_line_char(info
);
4339 if ((old_termios
->c_cflag
& CRTSCTS
) &&
4340 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
4346 * No need to wake up processes in open wait, since they
4347 * sample the CLOCAL flag once, and don't recheck it.
4348 * XXX It's not clear whether the current behavior is correct
4349 * or not. Hence, this may change.....
4351 if (!(old_termios
->c_cflag
& CLOCAL
) &&
4352 (tty
->termios
->c_cflag
& CLOCAL
))
4353 wake_up_interruptible(&info
->open_wait
);
4357 } /* cy_set_termios */
4359 /* This routine is called by the upper-layer tty layer to signal
4360 that incoming characters should be throttled because the input
4361 buffers are close to full.
4364 cy_throttle(struct tty_struct
* tty
)
4366 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4367 unsigned long flags
;
4368 unsigned char *base_addr
;
4369 int card
,chip
,channel
,index
;
4371 #ifdef CY_DEBUG_THROTTLE
4374 printk("cyc:throttle %s: %d....ttyC%d\n",
4376 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4379 if (serial_paranoia_check(info
, tty
->device
, "cy_throttle")){
4384 info
->x_char
= STOP_CHAR(tty
);
4385 /* Should use the "Send Special Character" feature!!! */
4389 channel
= info
->line
- cy_card
[card
].first_line
;
4390 if (!IS_CYC_Z(cy_card
[card
])) {
4393 index
= cy_card
[card
].bus_index
;
4394 base_addr
= (unsigned char*)
4395 (cy_card
[card
].base_addr
4396 + (cy_chip_offset
[chip
]<<index
));
4398 CY_LOCK(info
, flags
);
4399 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4400 if (info
->rtsdtr_inv
) {
4401 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
4403 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
4405 CY_UNLOCK(info
, flags
);
4415 * This routine notifies the tty driver that it should signal
4416 * that characters can now be sent to the tty without fear of
4417 * overrunning the input buffers of the line disciplines.
4420 cy_unthrottle(struct tty_struct
* tty
)
4422 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4423 unsigned long flags
;
4424 unsigned char *base_addr
;
4425 int card
,chip
,channel
,index
;
4427 #ifdef CY_DEBUG_THROTTLE
4430 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4432 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4435 if (serial_paranoia_check(info
, tty
->device
, "cy_unthrottle")){
4443 info
->x_char
= START_CHAR(tty
);
4444 /* Should use the "Send Special Character" feature!!! */
4448 channel
= info
->line
- cy_card
[card
].first_line
;
4449 if (!IS_CYC_Z(cy_card
[card
])) {
4452 index
= cy_card
[card
].bus_index
;
4453 base_addr
= (unsigned char*)
4454 (cy_card
[card
].base_addr
4455 + (cy_chip_offset
[chip
]<<index
));
4457 CY_LOCK(info
, flags
);
4458 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4459 if (info
->rtsdtr_inv
) {
4460 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
4462 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
4464 CY_UNLOCK(info
, flags
);
4470 } /* cy_unthrottle */
4473 /* cy_start and cy_stop provide software output flow control as a
4474 function of XON/XOFF, software CTS, and other such stuff.
4477 cy_stop(struct tty_struct
*tty
)
4479 struct cyclades_card
*cinfo
;
4480 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4481 unsigned char *base_addr
;
4482 int chip
,channel
,index
;
4483 unsigned long flags
;
4485 #ifdef CY_DEBUG_OTHER
4486 printk("cyc:cy_stop ttyC%d\n", info
->line
); /* */
4489 if (serial_paranoia_check(info
, tty
->device
, "cy_stop"))
4492 cinfo
= &cy_card
[info
->card
];
4493 channel
= info
->line
- cinfo
->first_line
;
4494 if (!IS_CYC_Z(*cinfo
)) {
4495 index
= cinfo
->bus_index
;
4498 base_addr
= (unsigned char*)
4499 (cy_card
[info
->card
].base_addr
4500 + (cy_chip_offset
[chip
]<<index
));
4502 CY_LOCK(info
, flags
);
4503 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
4504 (u_char
)(channel
& 0x0003)); /* index channel */
4505 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
4506 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
4507 CY_UNLOCK(info
, flags
);
4517 cy_start(struct tty_struct
*tty
)
4519 struct cyclades_card
*cinfo
;
4520 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4521 unsigned char *base_addr
;
4522 int chip
,channel
,index
;
4523 unsigned long flags
;
4525 #ifdef CY_DEBUG_OTHER
4526 printk("cyc:cy_start ttyC%d\n", info
->line
); /* */
4529 if (serial_paranoia_check(info
, tty
->device
, "cy_start"))
4532 cinfo
= &cy_card
[info
->card
];
4533 channel
= info
->line
- cinfo
->first_line
;
4534 index
= cinfo
->bus_index
;
4535 if (!IS_CYC_Z(*cinfo
)) {
4538 base_addr
= (unsigned char*)
4539 (cy_card
[info
->card
].base_addr
4540 + (cy_chip_offset
[chip
]<<index
));
4542 CY_LOCK(info
, flags
);
4543 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
4544 (u_char
)(channel
& 0x0003)); /* index channel */
4545 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
4546 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxMpty
);
4547 CY_UNLOCK(info
, flags
);
4557 cy_flush_buffer(struct tty_struct
*tty
)
4559 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4560 int card
, channel
, retval
;
4561 unsigned long flags
;
4564 printk("cyc:cy_flush_buffer ttyC%d\n", info
->line
); /* */
4567 if (serial_paranoia_check(info
, tty
->device
, "cy_flush_buffer"))
4571 channel
= (info
->line
) - (cy_card
[card
].first_line
);
4573 CY_LOCK(info
, flags
);
4574 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
4575 CY_UNLOCK(info
, flags
);
4577 if (IS_CYC_Z(cy_card
[card
])) { /* If it is a Z card, flush the on-board
4579 CY_LOCK(info
, flags
);
4580 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_TX
, 0L);
4582 printk("cyc: flush_buffer retval on ttyC%d was %x\n",
4583 info
->line
, retval
);
4585 CY_UNLOCK(info
, flags
);
4587 wake_up_interruptible(&tty
->write_wait
);
4588 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
))
4589 && tty
->ldisc
.write_wakeup
)
4590 (tty
->ldisc
.write_wakeup
)(tty
);
4591 } /* cy_flush_buffer */
4595 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4598 cy_hangup(struct tty_struct
*tty
)
4600 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4602 #ifdef CY_DEBUG_OTHER
4603 printk("cyc:cy_hangup ttyC%d\n", info
->line
); /* */
4606 if (serial_paranoia_check(info
, tty
->device
, "cy_hangup"))
4609 cy_flush_buffer(tty
);
4613 #ifdef CY_DEBUG_COUNT
4614 printk("cyc:cy_hangup (%d): setting count to 0\n", current
->pid
);
4617 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
4618 wake_up_interruptible(&info
->open_wait
);
4623 * ---------------------------------------------------------------------
4624 * cy_init() and friends
4626 * cy_init() is called at boot-time to initialize the serial driver.
4627 * ---------------------------------------------------------------------
4630 /* initialize chips on Cyclom-Y card -- return number of valid
4631 chips (which is number of ports/4) */
4632 static unsigned short __init
4633 cyy_init_card(volatile ucchar
*true_base_addr
,int index
)
4635 unsigned int chip_number
;
4636 volatile ucchar
* base_addr
;
4638 cy_writeb((u_long
)true_base_addr
+(Cy_HwReset
<<index
), 0);
4639 /* Cy_HwReset is 0x1400 */
4640 cy_writeb((u_long
)true_base_addr
+(Cy_ClrIntr
<<index
), 0);
4641 /* Cy_ClrIntr is 0x1800 */
4644 for(chip_number
=0; chip_number
<CyMAX_CHIPS_PER_CARD
; chip_number
++){
4645 base_addr
= true_base_addr
4646 + (cy_chip_offset
[chip_number
]<<index
);
4648 if(cy_readb(base_addr
+(CyCCR
<<index
)) != 0x00){
4650 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4651 chip_number, (unsigned long)base_addr);
4656 cy_writeb((u_long
)base_addr
+(CyGFRCR
<<index
), 0);
4659 /* The Cyclom-16Y does not decode address bit 9 and therefore
4660 cannot distinguish between references to chip 0 and a non-
4661 existent chip 4. If the preceding clearing of the supposed
4662 chip 4 GFRCR register appears at chip 0, there is no chip 4
4663 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4665 if (chip_number
== 4
4666 && cy_readb(true_base_addr
4667 + (cy_chip_offset
[0]<<index
)
4668 + (CyGFRCR
<<index
)) == 0){
4672 cy_writeb((u_long
)base_addr
+(CyCCR
<<index
), CyCHIP_RESET
);
4675 if(cy_readb(base_addr
+(CyGFRCR
<<index
)) == 0x00){
4677 printk(" chip #%d at %#6lx is not responding ",
4678 chip_number, (unsigned long)base_addr);
4679 printk("(GFRCR stayed 0)\n",
4683 if((0xf0 & (cy_readb(base_addr
+(CyGFRCR
<<index
)))) != 0x40){
4685 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4686 chip_number, (unsigned long)base_addr,
4687 base_addr[CyGFRCR<<index]);
4691 cy_writeb((u_long
)base_addr
+(CyGCR
<<index
), CyCH0_SERIAL
);
4692 if (cy_readb(base_addr
+(CyGFRCR
<<index
)) >= CD1400_REV_J
){
4693 /* It is a CD1400 rev. J or later */
4694 /* Impossible to reach 5ms with this chip.
4695 Changed to 2ms instead (f = 500 Hz). */
4696 cy_writeb((u_long
)base_addr
+(CyPPR
<<index
), CyCLOCK_60_2MS
);
4699 cy_writeb((u_long
)base_addr
+(CyPPR
<<index
), CyCLOCK_25_5MS
);
4703 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4704 chip_number, (unsigned long)base_addr,
4705 cy_readb(base_addr+(CyGFRCR<<index)));
4709 } /* cyy_init_card */
4711 #ifndef CONFIG_COBALT_27
4713 * ---------------------------------------------------------------------
4714 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4715 * sets global variables and return the number of ISA boards found.
4716 * ---------------------------------------------------------------------
4721 unsigned short cy_isa_irq
,nboard
;
4722 volatile ucchar
*cy_isa_address
;
4723 unsigned short i
,j
,cy_isa_nchan
;
4731 /* Check for module parameters */
4732 for(i
= 0 ; i
< NR_CARDS
; i
++) {
4733 if (maddr
[i
] || i
) {
4735 cy_isa_addresses
[i
] = (ucchar
*)maddr
[i
];
4742 /* scan the address table probing for Cyclom-Y/ISA boards */
4743 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
4744 cy_isa_address
= cy_isa_addresses
[i
];
4745 if (cy_isa_address
== 0x0000) {
4749 /* probe for CD1400... */
4751 #if !defined(__alpha__)
4752 cy_isa_address
= ioremap((ulong
)cy_isa_address
, CyISA_Ywin
);
4754 cy_isa_nchan
= CyPORTS_PER_CHIP
*
4755 cyy_init_card(cy_isa_address
,0);
4756 if (cy_isa_nchan
== 0) {
4761 if (isparam
&& irq
[i
])
4762 cy_isa_irq
= irq
[i
];
4765 /* find out the board's irq by probing */
4766 cy_isa_irq
= detect_isa_irq(cy_isa_address
);
4767 if (cy_isa_irq
== 0) {
4768 printk("Cyclom-Y/ISA found at 0x%lx ",
4769 (unsigned long) cy_isa_address
);
4770 printk("but the IRQ could not be detected.\n");
4774 if((cy_next_channel
+cy_isa_nchan
) > NR_PORTS
) {
4775 printk("Cyclom-Y/ISA found at 0x%lx ",
4776 (unsigned long) cy_isa_address
);
4777 printk("but no more channels are available.\n");
4778 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4781 /* fill the next cy_card structure available */
4782 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4783 if (cy_card
[j
].base_addr
== 0) break;
4785 if (j
== NR_CARDS
) { /* no more cy_cards available */
4786 printk("Cyclom-Y/ISA found at 0x%lx ",
4787 (unsigned long) cy_isa_address
);
4788 printk("but no more cards can be used .\n");
4789 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4794 if(request_irq(cy_isa_irq
, cyy_interrupt
,
4795 SA_INTERRUPT
, "Cyclom-Y", &cy_card
[j
]))
4797 printk("Cyclom-Y/ISA found at 0x%lx ",
4798 (unsigned long) cy_isa_address
);
4799 printk("but could not allocate IRQ#%d.\n",
4805 cy_card
[j
].base_addr
= (u_long
) cy_isa_address
;
4806 cy_card
[j
].ctl_addr
= 0;
4807 cy_card
[j
].irq
= (int) cy_isa_irq
;
4808 cy_card
[j
].bus_index
= 0;
4809 cy_card
[j
].first_line
= cy_next_channel
;
4810 cy_card
[j
].num_chips
= cy_isa_nchan
/4;
4814 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4815 j
+1, (unsigned long) cy_isa_address
,
4816 (unsigned long)(cy_isa_address
+ (CyISA_Ywin
- 1)),
4818 printk("%d channels starting from port %d.\n",
4819 cy_isa_nchan
, cy_next_channel
);
4820 cy_next_channel
+= cy_isa_nchan
;
4824 } /* cy_detect_isa */
4825 #endif /* CONFIG_COBALT_27 */
4828 plx_init(uclong addr
, uclong initctl
)
4831 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x40000000);
4833 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x40000000);
4835 /* Reload Config. Registers from EEPROM */
4836 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x20000000);
4838 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x20000000);
4842 * ---------------------------------------------------------------------
4843 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4844 * sets global variables and return the number of PCI boards found.
4845 * ---------------------------------------------------------------------
4852 struct pci_dev
*pdev
= NULL
;
4853 unsigned char cyy_rev_id
;
4854 unsigned char cy_pci_irq
= 0;
4855 uclong cy_pci_addr0
, cy_pci_addr1
, cy_pci_addr2
;
4856 unsigned short i
,j
,cy_pci_nchan
, plx_ver
;
4857 unsigned short device_id
,dev_index
= 0;
4859 uclong Ze_addr0
[NR_CARDS
], Ze_addr2
[NR_CARDS
], ZeIndex
= 0;
4860 unsigned char Ze_irq
[NR_CARDS
];
4862 for (i
= 0; i
< NR_CARDS
; i
++) {
4863 /* look for a Cyclades card by vendor and device id */
4864 while((device_id
= cy_pci_dev_id
[dev_index
]) != 0) {
4865 if((pdev
= pci_find_device(PCI_VENDOR_ID_CYCLADES
,
4866 device_id
, pdev
)) == NULL
) {
4867 dev_index
++; /* try next device id */
4869 break; /* found a board */
4876 if (pci_enable_device(pdev
))
4879 /* read PCI configuration area */
4880 cy_pci_irq
= pdev
->irq
;
4881 cy_pci_addr0
= pci_resource_start(pdev
, 0);
4882 cy_pci_addr1
= pci_resource_start(pdev
, 1);
4883 cy_pci_addr2
= pci_resource_start(pdev
, 2);
4884 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &cyy_rev_id
);
4886 device_id
&= ~PCI_DEVICE_ID_MASK
;
4888 if ((device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
)
4889 || (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Hi
)){
4891 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4892 pdev
->bus
->number
, pdev
->devfn
);
4893 printk("rev_id=%d) IRQ%d\n",
4894 cyy_rev_id
, (int)cy_pci_irq
);
4895 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4896 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4899 if (pdev
->resource
[2].flags
& ~PCI_BASE_ADDRESS_IO_MASK
) {
4900 printk(" Warning: PCI I/O bit incorrectly set. "
4901 "Ignoring it...\n");
4902 pdev
->resource
[2].flags
&= PCI_BASE_ADDRESS_IO_MASK
;
4905 #if defined(__alpha__)
4906 if (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
) { /* below 1M? */
4907 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4908 pdev
->bus
->number
, pdev
->devfn
);
4909 printk("rev_id=%d) IRQ%d\n",
4910 cyy_rev_id
, (int)cy_pci_irq
);
4911 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4912 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4913 printk("Cyclom-Y/PCI not supported for low addresses in "
4914 "Alpha systems.\n");
4919 cy_pci_addr0
= (ulong
)ioremap(cy_pci_addr0
, CyPCI_Yctl
);
4920 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Ywin
);
4924 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4925 (u_long
)cy_pci_addr2
, (u_long
)cy_pci_addr0
);
4927 cy_pci_nchan
= (unsigned short)(CyPORTS_PER_CHIP
*
4928 cyy_init_card((volatile ucchar
*)cy_pci_addr2
, 1));
4929 if(cy_pci_nchan
== 0) {
4930 printk("Cyclom-Y PCI host card with ");
4931 printk("no Serial-Modules at 0x%lx.\n",
4932 (ulong
) cy_pci_addr2
);
4936 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4937 printk("Cyclom-Y/PCI found at 0x%lx ",
4938 (ulong
) cy_pci_addr2
);
4939 printk("but no channels are available.\n");
4940 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4943 /* fill the next cy_card structure available */
4944 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4945 if (cy_card
[j
].base_addr
== 0) break;
4947 if (j
== NR_CARDS
) { /* no more cy_cards available */
4948 printk("Cyclom-Y/PCI found at 0x%lx ",
4949 (ulong
) cy_pci_addr2
);
4950 printk("but no more cards can be used.\n");
4951 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4956 if(request_irq(cy_pci_irq
, cyy_interrupt
,
4957 SA_SHIRQ
, "Cyclom-Y", &cy_card
[j
]))
4959 printk("Cyclom-Y/PCI found at 0x%lx ",
4960 (ulong
) cy_pci_addr2
);
4961 printk("but could not allocate IRQ%d.\n",
4967 cy_card
[j
].base_addr
= (ulong
)cy_pci_addr2
;
4968 cy_card
[j
].ctl_addr
= (ulong
)cy_pci_addr0
;
4969 cy_card
[j
].irq
= (int) cy_pci_irq
;
4970 cy_card
[j
].bus_index
= 1;
4971 cy_card
[j
].first_line
= cy_next_channel
;
4972 cy_card
[j
].num_chips
= cy_pci_nchan
/4;
4974 /* enable interrupts in the PCI interface */
4975 plx_ver
= cy_readb(cy_pci_addr2
+ CyPLX_VER
) & 0x0f;
4979 plx_init(cy_pci_addr0
, 0x50);
4981 cy_writew(cy_pci_addr0
+0x4c,
4982 cy_readw(cy_pci_addr0
+0x4c)|0x0040);
4987 default: /* Old boards, use PLX_9060 */
4989 plx_init(cy_pci_addr0
, 0x6c);
4990 /* For some yet unknown reason, once the PLX9060 reloads
4991 the EEPROM, the IRQ is lost and, thus, we have to
4992 re-write it to the PCI config. registers.
4993 This will remain here until we find a permanent fix. */
4994 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4996 cy_writew(cy_pci_addr0
+0x68,
4997 cy_readw(cy_pci_addr0
+0x68)|0x0900);
5002 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5004 (ulong
)cy_pci_addr2
,
5005 (ulong
)(cy_pci_addr2
+ CyPCI_Ywin
- 1),
5007 printk("%d channels starting from port %d.\n",
5008 cy_pci_nchan
, cy_next_channel
);
5010 cy_next_channel
+= cy_pci_nchan
;
5011 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Lo
){
5013 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
5014 pdev
->bus
->number
, pdev
->devfn
);
5015 printk("rev_id=%d) IRQ%d\n",
5016 cyy_rev_id
, (int)cy_pci_irq
);
5017 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
5018 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5019 printk("Cyclades-Z/PCI not supported for low addresses\n");
5021 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Hi
){
5023 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
5024 pdev
->bus
->number
, pdev
->devfn
);
5025 printk("rev_id=%d) IRQ%d\n",
5026 cyy_rev_id
, (int)cy_pci_irq
);
5027 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
5028 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5030 #if !defined(__alpha__)
5031 cy_pci_addr0
= (ulong
)ioremap(cy_pci_addr0
, CyPCI_Zctl
);
5034 /* Disable interrupts on the PLX before resetting it */
5035 cy_writew(cy_pci_addr0
+0x68,
5036 cy_readw(cy_pci_addr0
+0x68) & ~0x0900);
5038 plx_init(cy_pci_addr0
, 0x6c);
5039 /* For some yet unknown reason, once the PLX9060 reloads
5040 the EEPROM, the IRQ is lost and, thus, we have to
5041 re-write it to the PCI config. registers.
5042 This will remain here until we find a permanent fix. */
5043 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
5045 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060
*)
5046 cy_pci_addr0
)->mail_box_0
);
5048 if (pdev
->resource
[2].flags
& ~PCI_BASE_ADDRESS_IO_MASK
) {
5049 printk(" Warning: PCI I/O bit incorrectly set. "
5050 "Ignoring it...\n");
5051 pdev
->resource
[2].flags
&= PCI_BASE_ADDRESS_IO_MASK
;
5053 if (mailbox
== ZE_V1
) {
5054 #if !defined(__alpha__)
5055 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Ze_win
);
5057 if (ZeIndex
== NR_CARDS
) {
5058 printk("Cyclades-Ze/PCI found at 0x%lx ",
5059 (ulong
)cy_pci_addr2
);
5060 printk("but no more cards can be used.\n");
5061 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5063 Ze_addr0
[ZeIndex
] = cy_pci_addr0
;
5064 Ze_addr2
[ZeIndex
] = cy_pci_addr2
;
5065 Ze_irq
[ZeIndex
] = cy_pci_irq
;
5071 #if !defined(__alpha__)
5072 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Zwin
);
5077 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5078 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5079 if (mailbox
== ZO_V1
) {
5080 cy_writel(&((struct RUNTIME_9060
*)
5081 (cy_pci_addr0
))->loc_addr_base
, WIN_CREG
);
5083 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
5084 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5085 (cy_pci_addr2
))->fpga_id
)),
5086 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5087 (cy_pci_addr2
))->fpga_version
)));
5088 cy_writel(&((struct RUNTIME_9060
*)
5089 (cy_pci_addr0
))->loc_addr_base
, WIN_RAM
);
5091 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5094 /* The following clears the firmware id word. This ensures
5095 that the driver will not attempt to talk to the board
5096 until it has been properly initialized.
5099 if ((mailbox
== ZO_V1
) || (mailbox
== ZO_V2
))
5100 cy_writel((ulong
)(cy_pci_addr2
+ID_ADDRESS
), 0L);
5102 /* This must be a Cyclades-8Zo/PCI. The extendable
5103 version will have a different device_id and will
5104 be allocated its maximum number of ports. */
5107 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5108 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5109 (ulong
)cy_pci_addr2
);
5110 printk("but no channels are available.\n");
5111 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5115 /* fill the next cy_card structure available */
5116 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5117 if (cy_card
[j
].base_addr
== 0) break;
5119 if (j
== NR_CARDS
) { /* no more cy_cards available */
5120 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5121 (ulong
)cy_pci_addr2
);
5122 printk("but no more cards can be used.\n");
5123 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5127 #ifdef CONFIG_CYZ_INTR
5128 /* allocate IRQ only if board has an IRQ */
5129 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5130 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5131 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5133 printk("Could not allocate IRQ%d ",
5135 printk("for Cyclades-8Zo/PCI at 0x%lx.\n",
5136 (ulong
)cy_pci_addr2
);
5140 #endif /* CONFIG_CYZ_INTR */
5144 cy_card
[j
].base_addr
= cy_pci_addr2
;
5145 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5146 cy_card
[j
].irq
= (int) cy_pci_irq
;
5147 cy_card
[j
].bus_index
= 1;
5148 cy_card
[j
].first_line
= cy_next_channel
;
5149 cy_card
[j
].num_chips
= -1;
5152 #ifdef CONFIG_CYZ_INTR
5153 /* don't report IRQ if board is no IRQ */
5154 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5155 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5156 j
+1,(ulong
)cy_pci_addr2
,
5157 (ulong
)(cy_pci_addr2
+ CyPCI_Zwin
- 1),
5160 #endif /* CONFIG_CYZ_INTR */
5161 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5162 j
+1,(ulong
)cy_pci_addr2
,
5163 (ulong
)(cy_pci_addr2
+ CyPCI_Zwin
- 1));
5165 printk("%d channels starting from port %d.\n",
5166 cy_pci_nchan
,cy_next_channel
);
5167 cy_next_channel
+= cy_pci_nchan
;
5171 for (; ZeIndex
!= 0 && i
< NR_CARDS
; i
++) {
5172 cy_pci_addr0
= Ze_addr0
[0];
5173 cy_pci_addr2
= Ze_addr2
[0];
5174 cy_pci_irq
= Ze_irq
[0];
5175 for (j
= 0 ; j
< ZeIndex
-1 ; j
++) {
5176 Ze_addr0
[j
] = Ze_addr0
[j
+1];
5177 Ze_addr2
[j
] = Ze_addr2
[j
+1];
5178 Ze_irq
[j
] = Ze_irq
[j
+1];
5181 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060
*)
5182 cy_pci_addr0
)->mail_box_0
);
5184 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5185 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5186 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5189 /* This must be the new Cyclades-Ze/PCI. */
5190 cy_pci_nchan
= ZE_V1_NPORTS
;
5192 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5193 printk("Cyclades-Ze/PCI found at 0x%lx ",
5194 (ulong
)cy_pci_addr2
);
5195 printk("but no channels are available.\n");
5196 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5200 /* fill the next cy_card structure available */
5201 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5202 if (cy_card
[j
].base_addr
== 0) break;
5204 if (j
== NR_CARDS
) { /* no more cy_cards available */
5205 printk("Cyclades-Ze/PCI found at 0x%lx ",
5206 (ulong
)cy_pci_addr2
);
5207 printk("but no more cards can be used.\n");
5208 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5212 #ifdef CONFIG_CYZ_INTR
5213 /* allocate IRQ only if board has an IRQ */
5214 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5215 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5216 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5218 printk("Could not allocate IRQ%d ",
5220 printk("for Cyclades-Ze/PCI at 0x%lx.\n",
5221 (ulong
) cy_pci_addr2
);
5225 #endif /* CONFIG_CYZ_INTR */
5228 cy_card
[j
].base_addr
= cy_pci_addr2
;
5229 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5230 cy_card
[j
].irq
= (int) cy_pci_irq
;
5231 cy_card
[j
].bus_index
= 1;
5232 cy_card
[j
].first_line
= cy_next_channel
;
5233 cy_card
[j
].num_chips
= -1;
5236 #ifdef CONFIG_CYZ_INTR
5237 /* don't report IRQ if board is no IRQ */
5238 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5239 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5240 j
+1,(ulong
)cy_pci_addr2
,
5241 (ulong
)(cy_pci_addr2
+ CyPCI_Ze_win
- 1),
5244 #endif /* CONFIG_CYZ_INTR */
5245 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5246 j
+1,(ulong
)cy_pci_addr2
,
5247 (ulong
)(cy_pci_addr2
+ CyPCI_Ze_win
- 1));
5249 printk("%d channels starting from port %d.\n",
5250 cy_pci_nchan
,cy_next_channel
);
5251 cy_next_channel
+= cy_pci_nchan
;
5254 printk("Cyclades-Ze/PCI found at 0x%x ",
5255 (unsigned int) Ze_addr2
[0]);
5256 printk("but no more cards can be used.\n");
5257 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5262 #endif /* ifdef CONFIG_PCI */
5263 } /* cy_detect_pci */
5267 * This routine prints out the appropriate serial driver version number
5268 * and identifies which options were configured into this driver.
5273 char *rcsvers
, *rcsdate
, *tmp
;
5274 rcsvers
= strchr(rcsid
, ' '); rcsvers
++;
5275 tmp
= strchr(rcsvers
, ' '); *tmp
++ = '\0';
5276 rcsdate
= strchr(tmp
, ' '); rcsdate
++;
5277 tmp
= strrchr(rcsdate
, ' '); *tmp
= '\0';
5278 printk("Cyclades driver %s %s\n",
5280 printk(" built %s %s\n",
5281 __DATE__
, __TIME__
);
5282 } /* show_version */
5285 cyclades_get_proc_info(char *buf
, char **start
, off_t offset
, int length
,
5286 int *eof
, void *data
)
5288 struct cyclades_port
*info
;
5294 __u32 cur_jifs
= jiffies
;
5296 size
= sprintf(buf
, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
5301 /* Output one line for each known port */
5302 for (i
= 0; i
< NR_PORTS
&& cy_port
[i
].line
>= 0; i
++) {
5306 size
= sprintf(buf
+len
,
5307 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5309 JIFFIES_DIFF(info
->idle_stats
.in_use
, cur_jifs
) / HZ
,
5310 info
->idle_stats
.xmit_bytes
,
5311 JIFFIES_DIFF(info
->idle_stats
.xmit_idle
, cur_jifs
) / HZ
,
5312 info
->idle_stats
.recv_bytes
,
5313 JIFFIES_DIFF(info
->idle_stats
.recv_idle
, cur_jifs
) / HZ
,
5314 info
->idle_stats
.overruns
,
5315 (long) info
->tty
->ldisc
.num
);
5317 size
= sprintf(buf
+len
,
5318 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5319 info
->line
, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5327 if (pos
> offset
+ length
)
5332 *start
= buf
+ (offset
- begin
); /* Start of wanted data */
5333 len
-= (offset
- begin
); /* Start slop */
5335 len
= length
; /* Ending slop */
5341 /* The serial driver boot-time initialization code!
5342 Hardware I/O ports are mapped to character special devices on a
5343 first found, first allocated manner. That is, this code searches
5344 for Cyclom cards in the system. As each is found, it is probed
5345 to discover how many chips (and thus how many ports) are present.
5346 These ports are mapped to the tty ports 32 and upward in monotonic
5347 fashion. If an 8-port card is replaced with a 16-port card, the
5348 port mapping on a following card will shift.
5350 This approach is different from what is used in the other serial
5351 device driver because the Cyclom is more properly a multiplexer,
5352 not just an aggregation of serial ports on one card.
5354 If there are more cards with more ports than have been
5355 statically allocated above, a warning is printed and the
5356 extra ports are ignored.
5362 struct cyclades_port
*info
;
5363 struct cyclades_card
*cinfo
;
5364 int number_z_boards
= 0;
5365 int board
,port
,i
,index
;
5366 unsigned long mailbox
;
5367 unsigned short chip_number
;
5370 init_bh(CYCLADES_BH
, do_cyclades_bh
);
5374 /* Initialize the tty_driver structure */
5376 memset(&cy_serial_driver
, 0, sizeof(struct tty_driver
));
5377 cy_serial_driver
.magic
= TTY_DRIVER_MAGIC
;
5378 cy_serial_driver
.driver_name
= "cyclades";
5379 cy_serial_driver
.name
= "ttyC";
5380 cy_serial_driver
.major
= CYCLADES_MAJOR
;
5381 cy_serial_driver
.minor_start
= 0;
5382 cy_serial_driver
.num
= NR_PORTS
;
5383 cy_serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
5384 cy_serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
5385 cy_serial_driver
.init_termios
= tty_std_termios
;
5386 cy_serial_driver
.init_termios
.c_cflag
=
5387 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5388 cy_serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
5389 cy_serial_driver
.refcount
= &serial_refcount
;
5390 cy_serial_driver
.table
= serial_table
;
5391 cy_serial_driver
.termios
= serial_termios
;
5392 cy_serial_driver
.termios_locked
= serial_termios_locked
;
5394 cy_serial_driver
.open
= cy_open
;
5395 cy_serial_driver
.close
= cy_close
;
5396 cy_serial_driver
.write
= cy_write
;
5397 cy_serial_driver
.put_char
= cy_put_char
;
5398 cy_serial_driver
.flush_chars
= cy_flush_chars
;
5399 cy_serial_driver
.write_room
= cy_write_room
;
5400 cy_serial_driver
.chars_in_buffer
= cy_chars_in_buffer
;
5401 cy_serial_driver
.flush_buffer
= cy_flush_buffer
;
5402 cy_serial_driver
.ioctl
= cy_ioctl
;
5403 cy_serial_driver
.throttle
= cy_throttle
;
5404 cy_serial_driver
.unthrottle
= cy_unthrottle
;
5405 cy_serial_driver
.set_termios
= cy_set_termios
;
5406 cy_serial_driver
.stop
= cy_stop
;
5407 cy_serial_driver
.start
= cy_start
;
5408 cy_serial_driver
.hangup
= cy_hangup
;
5409 cy_serial_driver
.break_ctl
= cy_break
;
5410 cy_serial_driver
.wait_until_sent
= cy_wait_until_sent
;
5411 cy_serial_driver
.read_proc
= cyclades_get_proc_info
;
5414 * The callout device is just like normal device except for
5415 * major number and the subtype code.
5417 cy_callout_driver
= cy_serial_driver
;
5418 cy_callout_driver
.name
= "cub";
5419 cy_callout_driver
.major
= CYCLADESAUX_MAJOR
;
5420 cy_callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
5421 cy_callout_driver
.read_proc
= 0;
5422 cy_callout_driver
.proc_entry
= 0;
5425 if (tty_register_driver(&cy_serial_driver
))
5426 panic("Couldn't register Cyclades serial driver\n");
5427 if (tty_register_driver(&cy_callout_driver
))
5428 panic("Couldn't register Cyclades callout driver\n");
5430 for (i
= 0; i
< NR_CARDS
; i
++) {
5431 /* base_addr=0 indicates board not found */
5432 cy_card
[i
].base_addr
= 0;
5435 /* the code below is responsible to find the boards. Each different
5436 type of board has its own detection routine. If a board is found,
5437 the next cy_card structure available is set by the detection
5438 routine. These functions are responsible for checking the
5439 availability of cy_card and cy_port data structures and updating
5440 the cy_next_channel. */
5442 #ifndef CONFIG_COBALT_27
5443 /* look for isa boards */
5444 cy_isa_nboard
= cy_detect_isa();
5445 #endif /* CONFIG_COBALT_27 */
5447 /* look for pci boards */
5448 cy_pci_nboard
= cy_detect_pci();
5450 cy_nboard
= cy_isa_nboard
+ cy_pci_nboard
;
5452 /* invalidate remaining cy_card structures */
5453 for (i
= 0 ; i
< NR_CARDS
; i
++) {
5454 if (cy_card
[i
].base_addr
== 0) {
5455 cy_card
[i
].first_line
= -1;
5456 cy_card
[i
].ctl_addr
= 0;
5458 cy_card
[i
].bus_index
= 0;
5459 cy_card
[i
].first_line
= 0;
5460 cy_card
[i
].num_chips
= 0;
5463 /* invalidate remaining cy_port structures */
5464 for (i
= cy_next_channel
; i
< NR_PORTS
; i
++) {
5465 cy_port
[i
].line
= -1;
5466 cy_port
[i
].magic
= -1;
5469 /* initialize per-port data structures for each valid board found */
5470 for (board
= 0 ; board
< cy_nboard
; board
++) {
5471 cinfo
= &cy_card
[board
];
5472 if (cinfo
->num_chips
== -1) { /* Cyclades-Z */
5474 mailbox
= cy_readl(&((struct RUNTIME_9060
*)
5475 cy_card
[board
].ctl_addr
)->mail_box_0
);
5476 nports
= (mailbox
== ZE_V1
) ? ZE_V1_NPORTS
: 8;
5477 cinfo
->intr_enabled
= 0;
5478 cinfo
->nports
= 0; /* Will be correctly set later, after
5480 spin_lock_init(&cinfo
->card_lock
);
5481 for (port
= cinfo
->first_line
;
5482 port
< cinfo
->first_line
+ nports
;
5485 info
= &cy_port
[port
];
5486 info
->magic
= CYCLADES_MAGIC
;
5487 info
->type
= PORT_STARTECH
;
5491 info
->flags
= STD_COM_FLAGS
;
5493 if (mailbox
== ZO_V1
)
5494 info
->xmit_fifo_size
= CYZ_FIFO_SIZE
;
5496 info
->xmit_fifo_size
= 4 * CYZ_FIFO_SIZE
;
5506 info
->close_delay
= 5*HZ
/10;
5507 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5508 info
->icount
.cts
= info
->icount
.dsr
=
5509 info
->icount
.rng
= info
->icount
.dcd
= 0;
5510 info
->icount
.rx
= info
->icount
.tx
= 0;
5511 info
->icount
.frame
= info
->icount
.parity
= 0;
5512 info
->icount
.overrun
= info
->icount
.brk
= 0;
5516 info
->blocked_open
= 0;
5517 info
->default_threshold
= 0;
5518 info
->default_timeout
= 0;
5519 info
->tqueue
.routine
= do_softint
;
5520 info
->tqueue
.data
= info
;
5521 info
->callout_termios
=
5522 cy_callout_driver
.init_termios
;
5523 info
->normal_termios
=
5524 cy_serial_driver
.init_termios
;
5525 init_waitqueue_head(&info
->open_wait
);
5526 init_waitqueue_head(&info
->close_wait
);
5527 init_waitqueue_head(&info
->shutdown_wait
);
5528 init_waitqueue_head(&info
->delta_msr_wait
);
5531 info
->read_status_mask
= 0;
5533 /* Bentson's vars */
5534 info
->jiffies
[0] = 0;
5535 info
->jiffies
[1] = 0;
5536 info
->jiffies
[2] = 0;
5537 info
->rflush_count
= 0;
5538 #ifdef CONFIG_CYZ_INTR
5539 cyz_rx_full_timer
[port
].function
= NULL
;
5543 }else{ /* Cyclom-Y of some kind*/
5544 index
= cinfo
->bus_index
;
5545 spin_lock_init(&cinfo
->card_lock
);
5546 cinfo
->nports
= CyPORTS_PER_CHIP
* cinfo
->num_chips
;
5547 for (port
= cinfo
->first_line
;
5548 port
< cinfo
->first_line
+ cinfo
->nports
;
5551 info
= &cy_port
[port
];
5552 info
->magic
= CYCLADES_MAGIC
;
5553 info
->type
= PORT_CIRRUS
;
5556 info
->flags
= STD_COM_FLAGS
;
5558 info
->xmit_fifo_size
= CyMAX_CHAR_FIFO
;
5559 info
->cor1
= CyPARITY_NONE
|Cy_1_STOP
|Cy_8_BITS
;
5561 info
->cor3
= 0x08; /* _very_ small rcv threshold */
5564 info
->close_delay
= 5*HZ
/10;
5565 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5566 info
->icount
.cts
= info
->icount
.dsr
=
5567 info
->icount
.rng
= info
->icount
.dcd
= 0;
5568 info
->icount
.rx
= info
->icount
.tx
= 0;
5569 info
->icount
.frame
= info
->icount
.parity
= 0;
5570 info
->icount
.overrun
= info
->icount
.brk
= 0;
5571 chip_number
= (port
- cinfo
->first_line
) / 4;
5572 if ((info
->chip_rev
= cy_readb(cinfo
->base_addr
+
5573 (cy_chip_offset
[chip_number
]<<index
) +
5574 (CyGFRCR
<<index
))) >= CD1400_REV_J
) {
5575 /* It is a CD1400 rev. J or later */
5576 info
->tbpr
= baud_bpr_60
[13]; /* Tx BPR */
5577 info
->tco
= baud_co_60
[13]; /* Tx CO */
5578 info
->rbpr
= baud_bpr_60
[13]; /* Rx BPR */
5579 info
->rco
= baud_co_60
[13]; /* Rx CO */
5581 info
->rtsdtr_inv
= 1;
5583 info
->tbpr
= baud_bpr_25
[13]; /* Tx BPR */
5584 info
->tco
= baud_co_25
[13]; /* Tx CO */
5585 info
->rbpr
= baud_bpr_25
[13]; /* Rx BPR */
5586 info
->rco
= baud_co_25
[13]; /* Rx CO */
5588 info
->rtsdtr_inv
= 0;
5593 info
->blocked_open
= 0;
5594 info
->default_threshold
= 0;
5595 info
->default_timeout
= 0;
5596 info
->tqueue
.routine
= do_softint
;
5597 info
->tqueue
.data
= info
;
5598 info
->callout_termios
=
5599 cy_callout_driver
.init_termios
;
5600 info
->normal_termios
=
5601 cy_serial_driver
.init_termios
;
5602 init_waitqueue_head(&info
->open_wait
);
5603 init_waitqueue_head(&info
->close_wait
);
5604 init_waitqueue_head(&info
->shutdown_wait
);
5605 init_waitqueue_head(&info
->delta_msr_wait
);
5608 info
->read_status_mask
=
5609 CyTIMEOUT
| CySPECHAR
| CyBREAK
5610 | CyPARITY
| CyFRAME
| CyOVERRUN
;
5616 #ifndef CONFIG_CYZ_INTR
5617 if (number_z_boards
&& !cyz_timeron
){
5619 cyz_timerlist
.expires
= jiffies
+ 1;
5620 add_timer(&cyz_timerlist
);
5622 printk("Cyclades-Z polling initialized\n");
5625 #endif /* CONFIG_CYZ_INTR */
5632 /* See linux/drivers/char/riscom.c for ideas on how to
5633 pass additional base addresses to the driver!!! */
5641 cleanup_module(void)
5645 unsigned long flags
;
5647 #ifndef CONFIG_CYZ_INTR
5650 del_timer(&cyz_timerlist
);
5652 #endif /* CONFIG_CYZ_INTR */
5654 save_flags(flags
); cli();
5655 remove_bh(CYCLADES_BH
);
5657 if ((e1
= tty_unregister_driver(&cy_serial_driver
)))
5658 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5660 if ((e2
= tty_unregister_driver(&cy_callout_driver
)))
5661 printk("cyc: failed to unregister Cyclades callout driver (%d)\n",
5664 restore_flags(flags
);
5666 for (i
= 0; i
< NR_CARDS
; i
++) {
5667 if (cy_card
[i
].base_addr
!= 0) {
5668 iounmap((void *)cy_card
[i
].base_addr
);
5669 if (cy_card
[i
].ctl_addr
!= 0)
5670 iounmap((void *)cy_card
[i
].ctl_addr
);
5672 #ifndef CONFIG_CYZ_INTR
5673 && cy_card
[i
].num_chips
!= -1 /* not a Z card */
5674 #endif /* CONFIG_CYZ_INTR */
5676 free_irq(cy_card
[i
].irq
, &cy_card
[i
]);
5680 free_page((unsigned long) tmp_buf
);
5683 } /* cleanup_module */
5685 /* called by linux/init/main.c to parse command line options */
5687 cy_setup(char *str
, int *ints
)
5689 #ifndef CONFIG_COBALT_27
5692 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
5693 if (cy_isa_addresses
[i
] == 0) break;
5695 for (j
= 1; j
<= ints
[0]; j
++){
5696 if ( i
< NR_ISA_ADDRS
){
5697 cy_isa_addresses
[i
++] = (unsigned char *)(ints
[j
]);
5700 #endif /* CONFIG_COBALT_27 */
5706 #ifdef CYCLOM_SHOW_STATUS
5708 show_status(int line_num
)
5710 unsigned char *base_addr
;
5711 int card
,chip
,channel
,index
;
5712 struct cyclades_port
* info
;
5713 unsigned long flags
;
5715 info
= &cy_port
[line_num
];
5717 index
= cy_card
[card
].bus_index
;
5718 channel
= (info
->line
) - (cy_card
[card
].first_line
);
5721 printk(" card %d, chip %d, channel %d\n", card
, chip
, channel
);/**/
5723 printk(" cy_card\n");
5724 printk(" irq base_addr num_chips first_line = %d %lx %d %d\n",
5725 cy_card
[card
].irq
, (long)cy_card
[card
].base_addr
,
5726 cy_card
[card
].num_chips
, cy_card
[card
].first_line
);
5728 printk(" cy_port\n");
5729 printk(" card line flags = %d %d %x\n",
5730 info
->card
, info
->line
, info
->flags
);
5731 printk(" *tty read_status_mask timeout xmit_fifo_size ",
5732 printk("= %lx %x %x %x\n",
5733 (long)info
->tty
, info
->read_status_mask
,
5734 info
->timeout
, info
->xmit_fifo_size
);
5735 printk(" cor1,cor2,cor3,cor4,cor5 = %x %x %x %x %x\n",
5736 info
->cor1
, info
->cor2
, info
->cor3
, info
->cor4
, info
->cor5
);
5737 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
5738 info
->tbpr
, info
->tco
, info
->rbpr
, info
->rco
);
5739 printk(" close_delay event count = %d %d %d\n",
5740 info
->close_delay
, info
->event
, info
->count
);
5741 printk(" x_char blocked_open = %x %x\n",
5742 info
->x_char
, info
->blocked_open
);
5743 printk(" session pgrp open_wait = %lx %lx %lx\n",
5744 info
->session
, info
->pgrp
, (long)info
->open_wait
);
5746 CY_LOCK(info
, flags
);
5748 base_addr
= (unsigned char*)
5749 (cy_card
[card
].base_addr
5750 + (cy_chip_offset
[chip
]<<index
));
5752 /* Global Registers */
5754 printk(" CyGFRCR %x\n", cy_readb(base_addr
+ CyGFRCR
<<index
));
5755 printk(" CyCAR %x\n", cy_readb(base_addr
+ CyCAR
<<index
));
5756 printk(" CyGCR %x\n", cy_readb(base_addr
+ CyGCR
<<index
));
5757 printk(" CySVRR %x\n", cy_readb(base_addr
+ CySVRR
<<index
));
5758 printk(" CyRICR %x\n", cy_readb(base_addr
+ CyRICR
<<index
));
5759 printk(" CyTICR %x\n", cy_readb(base_addr
+ CyTICR
<<index
));
5760 printk(" CyMICR %x\n", cy_readb(base_addr
+ CyMICR
<<index
));
5761 printk(" CyRIR %x\n", cy_readb(base_addr
+ CyRIR
<<index
));
5762 printk(" CyTIR %x\n", cy_readb(base_addr
+ CyTIR
<<index
));
5763 printk(" CyMIR %x\n", cy_readb(base_addr
+ CyMIR
<<index
));
5764 printk(" CyPPR %x\n", cy_readb(base_addr
+ CyPPR
<<index
));
5766 cy_writeb(base_addr
+ CyCAR
<<index
, (u_char
)channel
);
5768 /* Virtual Registers */
5770 printk(" CyRIVR %x\n", cy_readb(base_addr
+ CyRIVR
<<index
));
5771 printk(" CyTIVR %x\n", cy_readb(base_addr
+ CyTIVR
<<index
));
5772 printk(" CyMIVR %x\n", cy_readb(base_addr
+ CyMIVR
<<index
));
5773 printk(" CyMISR %x\n", cy_readb(base_addr
+ CyMISR
<<index
));
5775 /* Channel Registers */
5777 printk(" CyCCR %x\n", cy_readb(base_addr
+ CyCCR
<<index
));
5778 printk(" CySRER %x\n", cy_readb(base_addr
+ CySRER
<<index
));
5779 printk(" CyCOR1 %x\n", cy_readb(base_addr
+ CyCOR1
<<index
));
5780 printk(" CyCOR2 %x\n", cy_readb(base_addr
+ CyCOR2
<<index
));
5781 printk(" CyCOR3 %x\n", cy_readb(base_addr
+ CyCOR3
<<index
));
5782 printk(" CyCOR4 %x\n", cy_readb(base_addr
+ CyCOR4
<<index
));
5783 printk(" CyCOR5 %x\n", cy_readb(base_addr
+ CyCOR5
<<index
));
5784 printk(" CyCCSR %x\n", cy_readb(base_addr
+ CyCCSR
<<index
));
5785 printk(" CyRDCR %x\n", cy_readb(base_addr
+ CyRDCR
<<index
));
5786 printk(" CySCHR1 %x\n", cy_readb(base_addr
+ CySCHR1
<<index
));
5787 printk(" CySCHR2 %x\n", cy_readb(base_addr
+ CySCHR2
<<index
));
5788 printk(" CySCHR3 %x\n", cy_readb(base_addr
+ CySCHR3
<<index
));
5789 printk(" CySCHR4 %x\n", cy_readb(base_addr
+ CySCHR4
<<index
));
5790 printk(" CySCRL %x\n", cy_readb(base_addr
+ CySCRL
<<index
));
5791 printk(" CySCRH %x\n", cy_readb(base_addr
+ CySCRH
<<index
));
5792 printk(" CyLNC %x\n", cy_readb(base_addr
+ CyLNC
<<index
));
5793 printk(" CyMCOR1 %x\n", cy_readb(base_addr
+ CyMCOR1
<<index
));
5794 printk(" CyMCOR2 %x\n", cy_readb(base_addr
+ CyMCOR2
<<index
));
5795 printk(" CyRTPR %x\n", cy_readb(base_addr
+ CyRTPR
<<index
));
5796 printk(" CyMSVR1 %x\n", cy_readb(base_addr
+ CyMSVR1
<<index
));
5797 printk(" CyMSVR2 %x\n", cy_readb(base_addr
+ CyMSVR2
<<index
));
5798 printk(" CyRBPR %x\n", cy_readb(base_addr
+ CyRBPR
<<index
));
5799 printk(" CyRCOR %x\n", cy_readb(base_addr
+ CyRCOR
<<index
));
5800 printk(" CyTBPR %x\n", cy_readb(base_addr
+ CyTBPR
<<index
));
5801 printk(" CyTCOR %x\n", cy_readb(base_addr
+ CyTCOR
<<index
));
5803 CY_UNLOCK(info
, flags
);