4 "$Revision: 2.3.2.2 $$Date: 1999/10/01 11:27:43 $";
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 * Maintained by Ivan Passos (ivan@cyclades.com).
15 * For Technical support and installation problems, please send e-mail
16 * to support@cyclades.com.
18 * Much of the design and some of the code came from serial.c
19 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
20 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
21 * and then fixed as suggested by Michael K. Johnson 12/12/92.
23 * This version supports shared IRQ's (only for PCI boards).
25 * This module exports the following rs232 io functions:
27 * int cy_open(struct tty_struct *tty, struct file *filp);
28 * and the following functions for modularization.
29 * int init_module(void);
30 * void cleanup_module(void);
32 * $Log: cyclades.c,v $
33 * Revision 2.3.2.2 1999/10/01 11:27:43 ivan
34 * Fixed bug in cyz_poll that would make all ports but port 0
35 * unable to transmit/receive data (Cyclades-Z only);
36 * Implemented logic to prevent the RX buffer from being stuck with
37 * due to a driver / firmware race condition in interrupt op mode
39 * Fixed bug in block_til_ready logic that would lead to a system crash;
40 * Revisited cy_close spinlock usage;
42 * Revision 2.3.2.1 1999/09/28 11:01:22 ivan
43 * Revisited CONFIG_PCI conditional compilation for PCI board support;
44 * Implemented TIOCGICOUNT and TIOCMIWAIT ioctl support;
45 * _Major_ cleanup on the Cyclades-Z interrupt support code / logic;
46 * Removed CTS handling from the driver -- this is now completely handled
47 * by the firmware (Cyclades-Z only);
48 * Flush RX on-board buffers on a port open (Cyclades-Z only);
49 * Fixed handling of ASYNC_SPD_* TTY flags;
50 * Module unload now unmaps all memory area allocated by ioremap;
52 * Revision 2.3.1.1 1999/07/15 16:45:53 ivan
53 * Removed CY_PROC conditional compilation;
54 * Implemented SMP-awareness for the driver;
55 * Implemented a new ISA IRQ autoprobe that uses the irq_probe_[on|off]
57 * The driver now accepts memory addresses (maddr=0xMMMMM) and IRQs
58 * (irq=NN) as parameters (only for ISA boards);
59 * Fixed bug in set_line_char that would prevent the Cyclades-Z
60 * ports from being configured at speeds above 115.2Kbps;
61 * Fixed bug in cy_set_termios that would prevent XON/XOFF flow control
62 * switching from working properly;
63 * The driver now only prints IRQ info for the Cyclades-Z if it's
64 * configured to work in interrupt mode;
66 * Revision 2.2.2.3 1999/06/28 11:13:29 ivan
67 * Added support for interrupt mode operation for the Z cards;
68 * Removed the driver inactivity control for the Z;
69 * Added a missing MOD_DEC_USE_COUNT in the cy_open function for when
70 * the Z firmware is not loaded yet;
71 * Replaced the "manual" Z Tx flush buffer by a call to a FW command of
73 * Implemented workaround for IRQ setting loss on the PCI configuration
74 * registers after a PCI bridge EEPROM reload (affects PLX9060 only);
76 * Revision 2.2.2.2 1999/05/14 17:18:15 ivan
77 * /proc entry location changed to /proc/tty/driver/cyclades;
78 * Added support to shared IRQ's (only for PCI boards);
79 * Added support for Cobalt Qube2 systems;
80 * IRQ [de]allocation scheme revisited;
81 * BREAK implementation changed in order to make use of the 'break_ctl'
83 * Fixed typo in TTY structure field 'driver_name';
84 * Included a PCI bridge reset and EEPROM reload in the board
85 * initialization code (for both Y and Z series).
87 * Revision 2.2.2.1 1999/04/08 16:17:43 ivan
88 * Fixed a bug in cy_wait_until_sent that was preventing the port to be
89 * closed properly after a SIGINT;
90 * Module usage counter scheme revisited;
91 * Added support to the upcoming Y PCI boards (i.e., support to additional
94 * Revision 2.2.1.10 1999/01/20 16:14:29 ivan
95 * Removed all unnecessary page-alignement operations in ioremap calls
96 * (ioremap is currently safe for these operations).
98 * Revision 2.2.1.9 1998/12/30 18:18:30 ivan
99 * Changed access to PLX PCI bridge registers from I/O to MMIO, in
100 * order to make PLX9050-based boards work with certain motherboards.
102 * Revision 2.2.1.8 1998/11/13 12:46:20 ivan
103 * cy_close function now resets (correctly) the tty->closing flag;
104 * JIFFIES_DIFF macro fixed.
106 * Revision 2.2.1.7 1998/09/03 12:07:28 ivan
107 * Fixed bug in cy_close function, which was not informing HW of
108 * which port should have the reception disabled before doing so;
109 * fixed Cyclom-8YoP hardware detection bug.
111 * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
112 * Fixed bug in cy_close function, which causes malfunction
113 * of one of the first 4 ports when a higher port is closed
116 * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
117 * Fixed Cyclom-4Yo hardware detection bug.
119 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
120 * /proc/cyclades implementation with great collaboration of
121 * Marc Lewis <marc@blarg.net>;
122 * cyy_interrupt was changed to avoid occurence of kernel oopses
123 * during PPP operation.
125 * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
126 * General code review in order to comply with 2.1 kernel standards;
127 * data loss prevention for slow devices revisited (cy_wait_until_sent
129 * removed conditional compilation for new/old PCI structure support
130 * (now the driver only supports the new PCI structure).
132 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
133 * added conditional compilation for new/old PCI structure support;
134 * removed kernel series (2.0.x / 2.1.x) conditional compilation.
136 * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
137 * cleaned up the data loss fix;
138 * fixed XON/XOFF handling once more (Cyclades-Z);
139 * general review of the driver routines;
140 * introduction of a mechanism to prevent data loss with slow
141 * printers, by forcing a delay before closing the port.
143 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
144 * fixed detection/handling of new CD1400 in Ye boards;
145 * fixed XON/XOFF handling (Cyclades-Z);
146 * fixed data loss caused by a premature port close;
147 * introduction of a flag that holds the CD1400 version ID per port
148 * (used by the CYGETCD1400VER new ioctl).
150 * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
151 * Code review for the module cleanup routine;
152 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
153 * includes anonymous changes regarding signal_pending.
155 * Revision 2.1 1997/11/01 17:42:41 ivan
156 * Changes in the driver to support Alpha systems (except 8Zo V_1);
157 * BREAK fix for the Cyclades-Z boards;
158 * driver inactivity control by FW implemented;
159 * introduction of flag that allows driver to take advantage of
160 * a special CD1400 feature related to HW flow control;
161 * added support for the CD1400 rev. J (Cyclom-Y boards);
162 * introduction of ioctls to:
163 * - control the rtsdtr_inv flag (Cyclom-Y);
164 * - control the rflow flag (Cyclom-Y);
165 * - adjust the polling interval (Cyclades-Z);
167 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
168 * Fixes related to kernel version conditional
171 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
172 * Compatibility issues between kernels 2.0.x and
173 * 2.1.x (mainly related to clear_bit function).
175 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
176 * Changes to define the memory window according to the
179 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
180 * Changes to suport new cycladesZ boards.
182 * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
183 * Merge of Bentson's and Daniel's version 1.36.4.28.
184 * Corrects bug in cy_detect_pci: check if there are more
185 * ports than the number of static structs allocated.
186 * Warning message during initialization if this driver is
187 * used with the new generation of cycladesZ boards. Those
188 * will be supported only in next release of the driver.
189 * Corrects bug in cy_detect_pci and cy_detect_isa that
190 * returned wrong number of VALID boards, when a cyclomY
191 * was found with no serial modules connected.
192 * Changes to use current (2.1.x) kernel subroutine names
193 * and created macros for compilation with 2.0.x kernel,
194 * instead of the other way around.
196 * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
197 * Change queue_task_irq_off to queue_task_irq.
198 * The inline function queue_task_irq_off (tqueue.h)
199 * was removed from latest releases of 2.1.x kernel.
200 * Use of macro __init to mark the initialization
201 * routines, so memory can be reused.
202 * Also incorporate implementation of critical region
203 * in function cleanup_module() created by anonymous
206 * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
207 * Change to support new firmware that solves DCD problem:
208 * application could fail to receive SIGHUP signal when DCD
211 * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
212 * Changed for suport linux versions 2.1.X.
213 * Backward compatible with linux versions 2.0.X.
214 * Corrected illegal use of filler field in
216 * Deleted some debug messages.
218 * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
219 * Included check for NULL tty pointer in cyz_poll.
221 * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
222 * Bill Foster at Blarg! Online services noticed that
223 * some of the switch elements of -Z modem control
224 * lacked a closing "break;"
226 * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
227 * Changed low water threshold for buffer xmit_buf
229 * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
230 * Marcio provided fix to modem status fetch for -Z
232 * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
233 * improve mapping of -Z control page (thanks to Steve
234 * Price <stevep@fa.tdktca.com> for help on this)
236 * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
237 * shift from CPU-bound to memcopy in cyz_polling operation
239 * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
240 * Added support to set and report higher speeds.
242 * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
243 * Some fixes in the HW flow control for the BETA release.
244 * Don't try to register the IRQ.
246 * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
247 * make sure "cyc" appears in all kernel messages; all soft interrupts
248 * handled by same routine; recognize out-of-band reception; comment
249 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
250 * fix race condition in -Z buffer management; only -Y needs to explictly
251 * flush chars; tidy up some startup messages;
253 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
254 * shift MOD_INC_USE_COUNT location to match
255 * serial.c; purge some diagnostic messages;
257 * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
258 * enable modem status messages and fetch & process them; note
259 * time of last activity type for each port; set_line_char now
260 * supports more than line 0 and treats 0 baud correctly;
261 * get_modem_info senses rs_status;
263 * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
264 * barely works--now's time to turn on
265 * more features 'til it breaks
267 * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
268 * check more -Z board status; shorten boot message
270 * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
271 * fix reference to ch_ctrl in startup; verify return
272 * values from cyz_issue_cmd and cyz_update_channel;
273 * more stuff to get modem control correct;
275 * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
276 * more -Z stuff folded in; re-order changes to put -Z stuff
277 * after -Y stuff (to make changes clearer)
279 * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
280 * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
281 * Add code to send break. Clear firmware ID word at startup (so
282 * that other code won't talk to inactive board).
284 * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
285 * add code for -Z in set_line_char
287 * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
288 * fold more -Z stuff (or in some cases, error messages)
289 * into driver; add text to "don't know what to do" messages.
291 * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
292 * moved compile-time flags near top of file; cosmetic changes
293 * to narrow text (to allow 2-up printing); changed many declarations
294 * to "static" to limit external symbols; shuffled code order to
295 * coalesce -Y and -Z specific code, also to put internal functions
296 * in order of tty_driver structure; added code to recognize -Z
297 * ports (and for moment, do nothing or report error); add cy_startup
298 * to parse boot command line for extra base addresses for ISA probes;
300 * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
301 * reorder some code, fix types of some vars (int vs. long),
302 * add cy_setup to support user declared ISA addresses
304 * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
305 * dump ioctl based firmware load (it's now a user level
306 * program); ensure uninitialzed ports cannot be used
308 * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
309 * rename vars and restructure some code
311 * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
312 * get right status back after boot load
314 * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
315 * successfully loads firmware
317 * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
318 * add more of the code for the boot/load ioctls
320 * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
321 * start to add Z functionality--starting with ioctl
322 * for loading firmware
324 * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
325 * added code to recognize Z/PCI card at initialization; report
326 * presence, but card is not initialized (because firmware needs
329 * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
330 * starting minor number at zero; added missing verify_area
331 * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
333 * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
334 * remove unneeded boot message & fix CLOCAL hardware flow
335 * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
336 * remove unused diagnostic statements; minor 0 is first;
338 * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
339 * The kernel function vremap (available only in later 1.3.xx kernels)
340 * allows the access to memory addresses above the RAM. This revision
341 * of the driver supports PCI boards below 1Mb (device id 0x100) and
342 * above 1Mb (device id 0x101).
344 * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
345 * Some global changes to interrupt handling spilled into
346 * this driver--mostly unused arguments in system function
347 * calls. Also added change by Marcio Saito which should
348 * reduce lost interrupts at startup by fast processors.
350 * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
351 * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
352 * in 1.3.41 kernel to remove a possible race condition, extend
353 * some error messages, and let the driver run as a loadable module
354 * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
355 * possible race condition.
356 * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
358 * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
359 * Changes by Linus Torvalds in 1.3.33 kernel distribution
360 * required due to reordering of driver initialization.
361 * Drivers are now initialized *after* memory management.
363 * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
364 * remove printk from ISR; fix typo
366 * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
367 * Minor fixes in the PCI board support. PCI function calls in
368 * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
369 * <duncan@okay.com>. "bad serial count" message removed.
371 * Revision 1.36.3 1995/08/22 09:19:42 marcio
372 * Cyclom-Y/PCI support added. Changes in the cy_init routine and
373 * board initialization. Changes in the boot messages. The driver
374 * supports up to 4 boards and 64 ports by default.
376 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
377 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
379 * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
380 * add missing break in modem control block in ioctl switch statement
381 * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
383 * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
384 * make sure CTS flow control is set as soon as possible (thanks
385 * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
387 * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
388 * initialize defaults for receive threshold and stale data timeout;
391 * Revision 1.36 1995/03/10 23:33:53 bentson
392 * added support of chips 4-7 in 32 port Cyclom-Ye;
393 * fix cy_interrupt pointer dereference problem
394 * (Joe Portman <baron@aa.net>);
395 * give better error response if open is attempted on non-existent port
396 * (Zachariah Vaum <jchryslr@netcom.com>);
397 * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
398 * conditional compilation for -16Y on systems with fast, noisy bus;
399 * comment out diagnostic print function;
400 * cleaned up table of base addresses;
401 * set receiver time-out period register to correct value,
402 * set receive threshold to better default values,
403 * set chip timer to more accurate 200 Hz ticking,
404 * add code to monitor and modify receive parameters
405 * (Rik Faith <faith@cs.unc.edu> Nick Simicich
406 * <njs@scifi.emi.net>);
408 * Revision 1.35 1994/12/16 13:54:18 steffen
409 * additional patch by Marcio Saito for board detection
410 * Accidently left out in 1.34
412 * Revision 1.34 1994/12/10 12:37:12 steffen
413 * This is the corrected version as suggested by Marcio Saito
415 * Revision 1.33 1994/12/01 22:41:18 bentson
416 * add hooks to support more high speeds directly; add tytso
417 * patch regarding CLOCAL wakeups
419 * Revision 1.32 1994/11/23 19:50:04 bentson
420 * allow direct kernel control of higher signalling rates;
421 * look for cards at additional locations
423 * Revision 1.31 1994/11/16 04:33:28 bentson
424 * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
425 * a problem in chars_in_buffer has been resolved by some
426 * small changes; this should yield smoother output
428 * Revision 1.30 1994/11/16 04:28:05 bentson
429 * Fix from Corey Minyard, Internet: minyard@metronet.com,
430 * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
431 * cy_hangup that appears to clear up much (all?) of the
432 * DTR glitches; also he's added/cleaned-up diagnostic messages
434 * Revision 1.29 1994/11/16 04:16:07 bentson
435 * add change proposed by Ralph Sims, ralphs@halcyon.com, to
436 * operate higher speeds in same way as other serial ports;
437 * add more serial ports (for up to two 16-port muxes).
439 * Revision 1.28 1994/11/04 00:13:16 root
440 * turn off diagnostic messages
442 * Revision 1.27 1994/11/03 23:46:37 root
443 * bunch of changes to bring driver into greater conformance
444 * with the serial.c driver (looking for missed fixes)
446 * Revision 1.26 1994/11/03 22:40:36 root
447 * automatic interrupt probing fixed.
449 * Revision 1.25 1994/11/03 20:17:02 root
450 * start to implement auto-irq
452 * Revision 1.24 1994/11/03 18:01:55 root
453 * still working on modem signals--trying not to drop DTR
454 * during the getty/login processes
456 * Revision 1.23 1994/11/03 17:51:36 root
457 * extend baud rate support; set receive threshold as function
458 * of baud rate; fix some problems with RTS/CTS;
460 * Revision 1.22 1994/11/02 18:05:35 root
461 * changed arguments to udelay to type long to get
462 * delays to be of correct duration
464 * Revision 1.21 1994/11/02 17:37:30 root
465 * employ udelay (after calibrating loops_per_second earlier
466 * in init/main.c) instead of using home-grown delay routines
468 * Revision 1.20 1994/11/02 03:11:38 root
469 * cy_chars_in_buffer forces a return value of 0 to let
470 * login work (don't know why it does); some functions
471 * that were returning EFAULT, now executes the code;
472 * more work on deciding when to disable xmit interrupts;
474 * Revision 1.19 1994/11/01 20:10:14 root
475 * define routine to start transmission interrupts (by enabling
476 * transmit interrupts); directly enable/disable modem interrupts;
478 * Revision 1.18 1994/11/01 18:40:45 bentson
479 * Don't always enable transmit interrupts in startup; interrupt on
480 * TxMpty instead of TxRdy to help characters get out before shutdown;
481 * restructure xmit interrupt to check for chars first and quit if
482 * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
485 * Revision 1.17 1994/10/30 04:39:45 bentson
486 * rename serial_driver and callout_driver to cy_serial_driver and
487 * cy_callout_driver to avoid linkage interference; initialize
488 * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
489 * from cyclades_port structure; add paranoia check to cy_close;
491 * Revision 1.16 1994/10/30 01:14:33 bentson
492 * change major numbers; add some _early_ return statements;
494 * Revision 1.15 1994/10/29 06:43:15 bentson
495 * final tidying up for clean compile; enable some error reporting
497 * Revision 1.14 1994/10/28 20:30:22 Bentson
498 * lots of changes to drag the driver towards the new tty_io
499 * structures and operation. not expected to work, but may
502 * Revision 1.13 1994/07/21 23:08:57 Bentson
503 * add some diagnostic cruft; support 24 lines (for testing
504 * both -8Y and -16Y cards; be more thorough in servicing all
505 * chips during interrupt; add "volatile" a few places to
506 * circumvent compiler optimizations; fix base & offset
507 * computations in block_til_ready (was causing chip 0 to
510 * Revision 1.12 1994/07/19 16:42:11 Bentson
511 * add some hackery for kernel version 1.1.8; expand
512 * error messages; refine timing for delay loops and
513 * declare loop params volatile
515 * Revision 1.11 1994/06/11 21:53:10 bentson
516 * get use of save_car right in transmit interrupt service
518 * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
519 * add some diagnostic printing; try to fix save_car stuff
521 * Revision 1.10 1994/06/11 20:36:08 bentson
522 * clean up compiler warnings
524 * Revision 1.9 1994/06/11 19:42:46 bentson
525 * added a bunch of code to support modem signalling
527 * Revision 1.8 1994/06/11 17:57:07 bentson
528 * recognize break & parity error
530 * Revision 1.7 1994/06/05 05:51:34 bentson
531 * Reorder baud table to be monotonic; add cli to CP; discard
532 * incoming characters and status if the line isn't open; start to
533 * fold code into cy_throttle; start to port get_serial_info,
534 * set_serial_info, get_modem_info, set_modem_info, and send_break
535 * from serial.c; expand cy_ioctl; relocate and expand config_setup;
536 * get flow control characters from tty struct; invalidate ports w/o
539 * Revision 1.6 1994/05/31 18:42:21 bentson
540 * add a loop-breaker in the interrupt service routine;
541 * note when port is initialized so that it can be shut
542 * down under the right conditions; receive works without
545 * Revision 1.5 1994/05/30 00:55:02 bentson
546 * transmit works without obvious errors
548 * Revision 1.4 1994/05/27 18:46:27 bentson
549 * incorporated more code from lib_y.c; can now print short
550 * strings under interrupt control to port zero; seems to
551 * select ports/channels/lines correctly
553 * Revision 1.3 1994/05/25 22:12:44 bentson
554 * shifting from multi-port on a card to proper multiplexor
555 * data structures; added skeletons of most routines
557 * Revision 1.2 1994/05/19 13:21:43 bentson
558 * start to crib from other sources
562 /* If you need to install more boards than NR_CARDS, change the constant
563 in the definition below. No other change is necessary to support up to
564 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
569 If the total number of ports is larger than NR_PORTS, change this
570 constant in the definition below. No other change is necessary to
571 support more boards/ports. */
575 #define ZE_V1_NPORTS 64
580 #define SERIAL_PARANOIA_CHECK
582 #undef CY_DEBUG_THROTTLE
583 #undef CY_DEBUG_OTHER
585 #undef CY_DEBUG_COUNT
587 #undef CY_DEBUG_WAIT_UNTIL_SENT
588 #undef CY_DEBUG_INTERRUPTS
590 #undef CY_ENABLE_MONITORING
594 #define PAUSE __asm__("nop");
599 #define cy_min(a,b) (((a)<(b))?(a):(b))
603 * For the next two macros, it is assumed that the buffer size is a
607 #define CHARS_IN_BUF(buf_ctrl) \
608 ((cy_readl(&buf_ctrl->rx_put) - \
609 cy_readl(&buf_ctrl->rx_get) + \
610 cy_readl(&buf_ctrl->rx_bufsize)) & \
611 (cy_readl(&buf_ctrl->rx_bufsize) - 1))
613 #define SPACE_IN_BUF(buf_ctrl) \
614 ((cy_readl(&buf_ctrl->tx_get) - \
615 cy_readl(&buf_ctrl->tx_put) + \
616 cy_readl(&buf_ctrl->tx_bufsize) - 1) & \
617 (cy_readl(&buf_ctrl->tx_bufsize) - 1))
623 #include <linux/config.h>
624 #include <linux/module.h>
625 #include <linux/errno.h>
626 #include <linux/signal.h>
627 #include <linux/sched.h>
628 #include <linux/timer.h>
629 #include <linux/interrupt.h>
630 #include <linux/tty.h>
631 #include <linux/serial.h>
632 #include <linux/major.h>
633 #include <linux/string.h>
634 #include <linux/fcntl.h>
635 #include <linux/ptrace.h>
636 #include <linux/cyclades.h>
637 #include <linux/mm.h>
638 #include <linux/init.h>
639 #include <linux/delay.h>
640 #include <linux/spinlock.h>
642 #include <asm/system.h>
645 #include <asm/uaccess.h>
646 #include <asm/bitops.h>
648 #define CY_LOCK(info,flags) \
650 spin_lock_irqsave(&cy_card[info->card].card_lock, flags); \
653 #define CY_UNLOCK(info,flags) \
655 spin_unlock_irqrestore(&cy_card[info->card].card_lock, flags); \
658 #include <linux/types.h>
659 #include <linux/kernel.h>
660 #include <linux/pci.h>
661 #include <linux/version.h>
663 #include <linux/stat.h>
664 #include <linux/proc_fs.h>
666 #ifdef CONFIG_COBALT_27
667 #include <asm/page.h>
668 #include <asm/pgtable.h>
670 #define CACHED_TO_UNCACHED(x) (((unsigned long)(x) & \
671 (unsigned long)0x1fffffff) + KSEG1)
674 #define cy_put_user put_user
677 cy_get_user(unsigned long *addr
)
679 unsigned long result
= 0;
680 int error
= get_user (result
, addr
);
682 printk ("cyclades: cy_get_user: error == %d\n", error
);
687 #define MIN(a,b) ((a) < (b) ? (a) : (b))
690 #define IS_CYC_Z(card) ((card).num_chips == -1)
692 #define Z_FPGA_CHECK(card) \
693 ((cy_readl(&((struct RUNTIME_9060 *) \
694 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
696 #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 *) \
697 ((card).ctl_addr))->mail_box_0)) || \
698 Z_FPGA_CHECK(card)) && \
699 (ZFIRM_ID==cy_readl(&((struct FIRM_ID *) \
700 ((card).base_addr+ID_ADDRESS))->signature)))
702 #define WAKEUP_CHARS (SERIAL_XMIT_SIZE-256)
704 #define STD_COM_FLAGS (0)
706 #define JIFFIES_DIFF(n, j) ((j) - (n))
708 static DECLARE_TASK_QUEUE(tq_cyclades
);
710 static struct tty_driver cy_serial_driver
, cy_callout_driver
;
711 static int serial_refcount
;
713 #ifndef CONFIG_COBALT_27
714 /* This is the address lookup table. The driver will probe for
715 Cyclom-Y/ISA boards at all addresses in here. If you want the
716 driver to probe addresses at a different address, add it to
717 this table. If the driver is probing some other board and
718 causing problems, remove the offending address from this table.
719 The cy_setup function extracts additional addresses from the
720 boot options line. The form is "cyclades=address,address..."
723 static unsigned char *cy_isa_addresses
[] = {
724 (unsigned char *) 0xD0000,
725 (unsigned char *) 0xD2000,
726 (unsigned char *) 0xD4000,
727 (unsigned char *) 0xD6000,
728 (unsigned char *) 0xD8000,
729 (unsigned char *) 0xDA000,
730 (unsigned char *) 0xDC000,
731 (unsigned char *) 0xDE000,
734 #define NR_ISA_ADDRS (sizeof(cy_isa_addresses)/sizeof(unsigned char*))
737 static int maddr
[NR_CARDS
] = { 0, };
738 static int irq
[NR_CARDS
] = { 0, };
740 MODULE_PARM(maddr
, "1-" __MODULE_STRING(NR_CARDS
) "l");
741 MODULE_PARM(irq
, "1-" __MODULE_STRING(NR_CARDS
) "i");
744 #endif /* CONFIG_COBALT_27 */
746 /* This is the per-card data structure containing address, irq, number of
747 channels, etc. This driver supports a maximum of NR_CARDS cards.
749 static struct cyclades_card cy_card
[NR_CARDS
];
751 /* This is the per-channel data structure containing pointers, flags
752 and variables for the port. This driver supports a maximum of NR_PORTS.
754 static struct cyclades_port cy_port
[NR_PORTS
];
756 static int cy_next_channel
= 0; /* next minor available */
758 static struct tty_struct
*serial_table
[NR_PORTS
];
759 static struct termios
*serial_termios
[NR_PORTS
];
760 static struct termios
*serial_termios_locked
[NR_PORTS
];
763 * tmp_buf is used as a temporary buffer by serial_write. We need to
764 * lock it in case the copy_from_user blocks while swapping in a page,
765 * and some other program tries to do a serial write at the same time.
766 * Since the lock will only come under contention when the system is
767 * swapping and available memory is low, it makes sense to share one
768 * buffer across all the serial ports, since it significantly saves
769 * memory if large numbers of serial ports are open. This buffer is
770 * allocated when the first cy_open occurs.
772 static unsigned char *tmp_buf
;
773 DECLARE_MUTEX(tmp_buf_sem
);
776 * This is used to look up the divisor speeds and the timeouts
777 * We're normally limited to 15 distinct baud rates. The extra
778 * are accessed via settings in info->flags.
779 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
780 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
784 static int baud_table
[] = {
785 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
786 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
789 static char baud_co_25
[] = { /* 25 MHz clock option table */
790 /* value => 00 01 02 03 04 */
791 /* divide by 8 32 128 512 2048 */
792 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
793 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
795 static char baud_bpr_25
[] = { /* 25 MHz baud rate period table */
796 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
797 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
799 static char baud_co_60
[] = { /* 60 MHz clock option table (CD1400 J) */
800 /* value => 00 01 02 03 04 */
801 /* divide by 8 32 128 512 2048 */
802 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
803 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
806 static char baud_bpr_60
[] = { /* 60 MHz baud rate period table (CD1400 J) */
807 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
808 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
811 static char baud_cor3
[] = { /* receive threshold */
812 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
813 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
817 * The Cyclades driver implements HW flow control as any serial driver.
818 * The cyclades_port structure member rflow and the vector rflow_thr
819 * allows us to take advantage of a special feature in the CD1400 to avoid
820 * data loss even when the system interrupt latency is too high. These flags
821 * are to be used only with very special applications. Setting these flags
822 * requires the use of a special cable (DTR and RTS reversed). In the new
823 * CD1400-based boards (rev. 6.00 or later), there is no need for special
827 static char rflow_thr
[] = { /* rflow threshold */
828 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
829 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
832 /* The Cyclom-Ye has placed the sequential chips in non-sequential
833 * address order. This look-up table overcomes that problem.
835 static int cy_chip_offset
[] =
846 /* PCI related definitions */
848 static unsigned short cy_pci_nboard
= 0;
849 static unsigned short cy_isa_nboard
= 0;
850 static unsigned short cy_nboard
= 0;
852 static unsigned short cy_pci_dev_id
[] = {
853 PCI_DEVICE_ID_CYCLOM_Y_Lo
, /* PCI < 1Mb */
854 PCI_DEVICE_ID_CYCLOM_Y_Hi
, /* PCI > 1Mb */
855 PCI_DEVICE_ID_CYCLOM_4Y_Lo
, /* 4Y PCI < 1Mb */
856 PCI_DEVICE_ID_CYCLOM_4Y_Hi
, /* 4Y PCI > 1Mb */
857 PCI_DEVICE_ID_CYCLOM_8Y_Lo
, /* 8Y PCI < 1Mb */
858 PCI_DEVICE_ID_CYCLOM_8Y_Hi
, /* 8Y PCI > 1Mb */
859 PCI_DEVICE_ID_CYCLOM_Z_Lo
, /* Z PCI < 1Mb */
860 PCI_DEVICE_ID_CYCLOM_Z_Hi
, /* Z PCI > 1Mb */
865 static void cy_start(struct tty_struct
*);
866 static void set_line_char(struct cyclades_port
*);
867 static int cyz_issue_cmd(struct cyclades_card
*, uclong
, ucchar
, uclong
);
868 #ifndef CONFIG_COBALT_27
869 static unsigned detect_isa_irq (volatile ucchar
*);
870 #endif /* CONFIG_COBALT_27 */
871 #ifdef CYCLOM_SHOW_STATUS
872 static void show_status(int);
875 static int cyclades_get_proc_info(char *, char **, off_t
, int , int *, void *);
877 #ifndef CONFIG_CYZ_INTR
878 static void cyz_poll(unsigned long);
880 /* The Cyclades-Z polling cycle is defined by this variable */
881 static long cyz_polling_cycle
= CZ_DEF_POLL
;
883 static int cyz_timeron
= 0;
884 static struct timer_list
886 NULL
, NULL
, 0, 0, cyz_poll
888 #else /* CONFIG_CYZ_INTR */
889 static void cyz_rx_restart(unsigned long);
890 static struct timer_list cyz_rx_full_timer
[NR_PORTS
];
891 #endif /* CONFIG_CYZ_INTR */
893 /**************************************************
894 error = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned long));
895 copy_to_user (to, from, count);
896 ***************************************************************
897 error = verify_area(VERIFY_READ, (void *) arg, sizeof(unsigned long *));
898 copy_from_user(to, from, count);
899 **************************************************/
903 serial_paranoia_check(struct cyclades_port
*info
,
904 kdev_t device
, const char *routine
)
906 #ifdef SERIAL_PARANOIA_CHECK
907 static const char *badmagic
=
908 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
909 static const char *badinfo
=
910 "cyc Warning: null cyclades_port for (%s) in %s\n";
911 static const char *badrange
=
912 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
915 printk(badinfo
, kdevname(device
), routine
);
919 if( (long)info
< (long)(&cy_port
[0])
920 || (long)(&cy_port
[NR_PORTS
]) < (long)info
){
921 printk(badrange
, kdevname(device
), routine
);
925 if (info
->magic
!= CYCLADES_MAGIC
) {
926 printk(badmagic
, kdevname(device
), routine
);
931 } /* serial_paranoia_check */
934 * This routine is used by the interrupt handler to schedule
935 * processing in the software interrupt portion of the driver
936 * (also known as the "bottom half"). This can be called any
937 * number of times for any channel without harm.
940 cy_sched_event(struct cyclades_port
*info
, int event
)
942 info
->event
|= 1 << event
; /* remember what kind of event and who */
943 queue_task(&info
->tqueue
, &tq_cyclades
); /* it belongs to */
944 mark_bh(CYCLADES_BH
); /* then trigger event */
945 } /* cy_sched_event */
949 * This routine is used to handle the "bottom half" processing for the
950 * serial driver, known also the "software interrupt" processing.
951 * This processing is done at the kernel interrupt level, after the
952 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
953 * is where time-consuming activities which can not be done in the
954 * interrupt driver proper are done; the interrupt driver schedules
955 * them using cy_sched_event(), and they get done here.
957 * This is done through one level of indirection--the task queue.
958 * When a hardware interrupt service routine wants service by the
959 * driver's bottom half, it enqueues the appropriate tq_struct (one
960 * per port) to the tq_cyclades work queue and sets a request flag
961 * via mark_bh for processing that queue. When the time is right,
962 * do_cyclades_bh is called (because of the mark_bh) and it requests
963 * that the work queue be processed.
965 * Although this may seem unwieldy, it gives the system a way to
966 * pass an argument (in this case the pointer to the cyclades_port
967 * structure) to the bottom half of the driver. Previous kernels
968 * had to poll every port to see if that port needed servicing.
973 run_task_queue(&tq_cyclades
);
974 } /* do_cyclades_bh */
977 do_softint(void *private_
)
979 struct cyclades_port
*info
= (struct cyclades_port
*) private_
;
980 struct tty_struct
*tty
;
986 if (test_and_clear_bit(Cy_EVENT_HANGUP
, &info
->event
)) {
987 tty_hangup(info
->tty
);
988 wake_up_interruptible(&info
->open_wait
);
989 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|
990 ASYNC_CALLOUT_ACTIVE
);
992 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP
, &info
->event
)) {
993 wake_up_interruptible(&info
->open_wait
);
995 #ifdef CONFIG_CYZ_INTR
996 if (test_and_clear_bit(Cy_EVENT_Z_RX_FULL
, &info
->event
)) {
997 cyz_rx_full_timer
[info
->line
].expires
= jiffies
+ 1;
998 cyz_rx_full_timer
[info
->line
].function
= cyz_rx_restart
;
999 cyz_rx_full_timer
[info
->line
].data
= (unsigned long)info
;
1000 add_timer(&cyz_rx_full_timer
[info
->line
]);
1003 if (test_and_clear_bit(Cy_EVENT_DELTA_WAKEUP
, &info
->event
)) {
1004 wake_up_interruptible(&info
->delta_msr_wait
);
1006 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP
, &info
->event
)) {
1007 if((tty
->flags
& (1<< TTY_DO_WRITE_WAKEUP
))
1008 && tty
->ldisc
.write_wakeup
){
1009 (tty
->ldisc
.write_wakeup
)(tty
);
1011 wake_up_interruptible(&tty
->write_wait
);
1014 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP
, &info
->event
)) {
1015 wake_up_interruptible(&info
->shutdown_wait
);
1021 /***********************************************************/
1022 /********* Start of block of Cyclom-Y specific code ********/
1024 /* This routine waits up to 1000 micro-seconds for the previous
1025 command to the Cirrus chip to complete and then issues the
1026 new command. An error is returned if the previous command
1027 didn't finish within the time limit.
1029 This function is only called from inside spinlock-protected code.
1032 cyy_issue_cmd(volatile ucchar
*base_addr
, u_char cmd
, int index
)
1036 /* Check to see that the previous command has completed */
1037 for(i
= 0 ; i
< 100 ; i
++){
1038 if (cy_readb(base_addr
+(CyCCR
<<index
)) == 0){
1043 /* if the CCR never cleared, the previous command
1044 didn't finish within the "reasonable time" */
1045 if (i
== 100) return (-1);
1047 /* Issue the new command */
1048 cy_writeb((u_long
)base_addr
+(CyCCR
<<index
), cmd
);
1051 } /* cyy_issue_cmd */
1053 #ifndef CONFIG_COBALT_27 /* ISA interrupt detection code */
1055 detect_isa_irq (volatile ucchar
*address
)
1058 unsigned long irqs
, flags
;
1059 int save_xir
, save_car
;
1060 int index
= 0; /* IRQ probing is only for ISA */
1062 /* forget possible initially masked and pending IRQ */
1063 irq
= probe_irq_off(probe_irq_on());
1065 /* Clear interrupts on the board first */
1066 cy_writeb((u_long
)address
+ (Cy_ClrIntr
<<index
), 0);
1067 /* Cy_ClrIntr is 0x1800 */
1069 irqs
= probe_irq_on();
1073 /* Enable the Tx interrupts on the CD1400 */
1074 save_flags(flags
); cli();
1075 cy_writeb((u_long
)address
+ (CyCAR
<<index
), 0);
1076 cyy_issue_cmd(address
, CyCHAN_CTL
|CyENB_XMTR
, index
);
1078 cy_writeb((u_long
)address
+ (CyCAR
<<index
), 0);
1079 cy_writeb((u_long
)address
+ (CySRER
<<index
),
1080 cy_readb(address
+ (CySRER
<<index
)) | CyTxMpty
);
1081 restore_flags(flags
);
1086 /* Check which interrupt is in use */
1087 irq
= probe_irq_off(irqs
);
1090 save_xir
= (u_char
) cy_readb(address
+ (CyTIR
<<index
));
1091 save_car
= cy_readb(address
+ (CyCAR
<<index
));
1092 cy_writeb((u_long
)address
+ (CyCAR
<<index
), (save_xir
& 0x3));
1093 cy_writeb((u_long
)address
+ (CySRER
<<index
),
1094 cy_readb(address
+ (CySRER
<<index
)) & ~CyTxMpty
);
1095 cy_writeb((u_long
)address
+ (CyTIR
<<index
), (save_xir
& 0x3f));
1096 cy_writeb((u_long
)address
+ (CyCAR
<<index
), (save_car
));
1097 cy_writeb((u_long
)address
+ (Cy_ClrIntr
<<index
), 0);
1098 /* Cy_ClrIntr is 0x1800 */
1100 return (irq
> 0)? irq
: 0;
1102 #endif /* CONFIG_COBALT_27 */
1104 /* The real interrupt service routine is called
1105 whenever the card wants its hand held--chars
1106 received, out buffer empty, modem change, etc.
1109 cyy_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1111 struct tty_struct
*tty
;
1113 struct cyclades_card
*cinfo
;
1114 struct cyclades_port
*info
;
1115 volatile unsigned char *base_addr
, *card_base_addr
;
1117 int save_xir
, channel
, save_car
;
1119 volatile int char_count
;
1127 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1128 #ifdef CY_DEBUG_INTERRUPTS
1129 printk("cyy_interrupt: spurious interrupt %d\n\r", irq
);
1131 return; /* spurious interrupt */
1134 card_base_addr
= (unsigned char *)cinfo
->base_addr
;
1135 index
= cinfo
->bus_index
;
1138 /* This loop checks all chips in the card. Make a note whenever
1139 _any_ chip had some work to do, as this is considered an
1140 indication that there will be more to do. Only when no chip
1141 has any work does this outermost loop exit.
1145 for ( chip
= 0 ; chip
< cinfo
->num_chips
; chip
++) {
1146 base_addr
= (unsigned char *)
1147 (cinfo
->base_addr
+ (cy_chip_offset
[chip
]<<index
));
1149 while ( (status
= cy_readb(base_addr
+(CySVRR
<<index
))) != 0x00) {
1151 /* The purpose of the following test is to ensure that
1152 no chip can monopolize the driver. This forces the
1153 chips to be checked in a round-robin fashion (after
1154 draining each of a bunch (1000) of characters).
1156 if(1000<too_many
++){
1159 if (status
& CySRReceive
) { /* reception interrupt */
1160 #ifdef CY_DEBUG_INTERRUPTS
1161 printk("cyy_interrupt: rcvd intr, chip %d\n\r", chip
);
1163 /* determine the channel & change to that context */
1164 spin_lock(&cinfo
->card_lock
);
1165 save_xir
= (u_char
) cy_readb(base_addr
+(CyRIR
<<index
));
1166 channel
= (u_short
) (save_xir
& CyIRChannel
);
1167 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1169 info
->last_active
= jiffies
;
1170 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1171 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1172 spin_unlock(&cinfo
->card_lock
);
1174 /* if there is nowhere to put the data, discard it */
1176 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1177 if ( j
== CyIVRRxEx
) { /* exception */
1178 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1179 } else { /* normal character reception */
1180 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1181 while(char_count
--){
1182 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1185 }else{ /* there is an open port for this data */
1187 j
= (cy_readb(base_addr
+(CyRIVR
<<index
)) & CyIVRMask
);
1188 if ( j
== CyIVRRxEx
) { /* exception */
1189 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1191 /* For statistics only */
1194 else if(data
& CyFRAME
)
1195 info
->icount
.frame
++;
1196 else if(data
& CyPARITY
)
1197 info
->icount
.parity
++;
1198 else if(data
& CyOVERRUN
)
1199 info
->icount
.overrun
++;
1201 if(data
& info
->ignore_status_mask
){
1205 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
){
1207 if (data
& info
->read_status_mask
){
1209 *tty
->flip
.flag_buf_ptr
++ =
1211 *tty
->flip
.char_buf_ptr
++ =
1212 cy_readb(base_addr
+(CyRDSR
<<index
));
1214 if (info
->flags
& ASYNC_SAK
){
1217 }else if(data
& CyFRAME
){
1218 *tty
->flip
.flag_buf_ptr
++ =
1220 *tty
->flip
.char_buf_ptr
++ =
1221 cy_readb(base_addr
+(CyRDSR
<<index
));
1223 info
->idle_stats
.frame_errs
++;
1224 }else if(data
& CyPARITY
){
1225 *tty
->flip
.flag_buf_ptr
++ =
1227 *tty
->flip
.char_buf_ptr
++ =
1228 cy_readb(base_addr
+(CyRDSR
<<index
));
1230 info
->idle_stats
.parity_errs
++;
1231 }else if(data
& CyOVERRUN
){
1232 *tty
->flip
.flag_buf_ptr
++ =
1234 *tty
->flip
.char_buf_ptr
++ = 0;
1236 /* If the flip buffer itself is
1237 overflowing, we still lose
1238 the next incoming character.
1241 < TTY_FLIPBUF_SIZE
){
1243 *tty
->flip
.flag_buf_ptr
++ =
1245 *tty
->flip
.char_buf_ptr
++ =
1246 cy_readb(base_addr
+(CyRDSR
<<index
));
1249 info
->idle_stats
.overruns
++;
1250 /* These two conditions may imply */
1251 /* a normal read should be done. */
1252 /* }else if(data & CyTIMEOUT){ */
1253 /* }else if(data & CySPECHAR){ */
1255 *tty
->flip
.flag_buf_ptr
++ = 0;
1256 *tty
->flip
.char_buf_ptr
++ = 0;
1260 *tty
->flip
.flag_buf_ptr
++ = 0;
1261 *tty
->flip
.char_buf_ptr
++ = 0;
1265 /* there was a software buffer
1266 overrun and nothing could be
1268 info
->icount
.buf_overrun
++;
1269 info
->idle_stats
.overruns
++;
1271 } else { /* normal character reception */
1272 /* load # chars available from the chip */
1273 char_count
= cy_readb(base_addr
+(CyRDCR
<<index
));
1275 #ifdef CY_ENABLE_MONITORING
1276 ++info
->mon
.int_count
;
1277 info
->mon
.char_count
+= char_count
;
1278 if (char_count
> info
->mon
.char_max
)
1279 info
->mon
.char_max
= char_count
;
1280 info
->mon
.char_last
= char_count
;
1282 info
->idle_stats
.recv_bytes
+= char_count
;
1283 info
->idle_stats
.recv_idle
= jiffies
;
1284 while(char_count
--){
1285 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
){
1289 data
= cy_readb(base_addr
+(CyRDSR
<<index
));
1290 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1291 *tty
->flip
.char_buf_ptr
++ = data
;
1298 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1300 /* end of service */
1301 spin_lock(&cinfo
->card_lock
);
1302 cy_writeb((u_long
)base_addr
+(CyRIR
<<index
), (save_xir
& 0x3f));
1303 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (save_car
));
1304 spin_unlock(&cinfo
->card_lock
);
1308 if (status
& CySRTransmit
) { /* transmission interrupt */
1309 /* Since we only get here when the transmit buffer
1310 is empty, we know we can always stuff a dozen
1312 #ifdef CY_DEBUG_INTERRUPTS
1313 printk("cyy_interrupt: xmit intr, chip %d\n\r", chip
);
1316 /* determine the channel & change to that context */
1317 spin_lock(&cinfo
->card_lock
);
1318 save_xir
= (u_char
) cy_readb(base_addr
+(CyTIR
<<index
));
1319 channel
= (u_short
) (save_xir
& CyIRChannel
);
1320 i
= channel
+ chip
* 4 + cinfo
->first_line
;
1321 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1322 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1323 spin_unlock(&cinfo
->card_lock
);
1325 /* validate the port# (as configured and open) */
1326 if( (i
< 0) || (NR_PORTS
<= i
) ){
1327 spin_lock(&cinfo
->card_lock
);
1328 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1329 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
1330 spin_unlock(&cinfo
->card_lock
);
1334 info
->last_active
= jiffies
;
1336 spin_lock(&cinfo
->card_lock
);
1337 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1338 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
1339 spin_unlock(&cinfo
->card_lock
);
1343 /* load the on-chip space for outbound data */
1344 char_count
= info
->xmit_fifo_size
;
1346 if(info
->x_char
) { /* send special char */
1347 outch
= info
->x_char
;
1348 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), outch
);
1354 if (info
->breakon
|| info
->breakoff
) {
1355 if (info
->breakon
) {
1356 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0);
1357 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0x81);
1361 if (info
->breakoff
) {
1362 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0);
1363 cy_writeb((u_long
)base_addr
+ (CyTDR
<<index
), 0x83);
1369 while (char_count
-- > 0){
1370 if (!info
->xmit_cnt
){
1371 spin_lock(&cinfo
->card_lock
);
1372 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1373 cy_readb(base_addr
+(CySRER
<<index
)) &
1375 spin_unlock(&cinfo
->card_lock
);
1378 if (info
->xmit_buf
== 0){
1379 spin_lock(&cinfo
->card_lock
);
1380 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1381 cy_readb(base_addr
+(CySRER
<<index
)) &
1383 spin_unlock(&cinfo
->card_lock
);
1386 if (info
->tty
->stopped
|| info
->tty
->hw_stopped
){
1387 spin_lock(&cinfo
->card_lock
);
1388 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1389 cy_readb(base_addr
+(CySRER
<<index
)) &
1391 spin_unlock(&cinfo
->card_lock
);
1394 /* Because the Embedded Transmit Commands have
1395 been enabled, we must check to see if the
1396 escape character, NULL, is being sent. If it
1397 is, we must ensure that there is room for it
1398 to be doubled in the output stream. Therefore
1399 we no longer advance the pointer when the
1400 character is fetched, but rather wait until
1401 after the check for a NULL output character.
1402 This is necessary because there may not be
1403 room for the two chars needed to send a NULL.)
1405 outch
= info
->xmit_buf
[info
->xmit_tail
];
1408 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1409 & (SERIAL_XMIT_SIZE
- 1);
1410 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), outch
);
1415 info
->xmit_tail
= (info
->xmit_tail
+ 1)
1416 & (SERIAL_XMIT_SIZE
- 1);
1417 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
),
1419 cy_writeb((u_long
)base_addr
+(CyTDR
<<index
), 0);
1428 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1429 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1432 /* end of service */
1433 spin_lock(&cinfo
->card_lock
);
1434 cy_writeb((u_long
)base_addr
+(CyTIR
<<index
),
1436 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (save_car
));
1437 spin_unlock(&cinfo
->card_lock
);
1440 if (status
& CySRModem
) { /* modem interrupt */
1442 /* determine the channel & change to that context */
1443 spin_lock(&cinfo
->card_lock
);
1444 save_xir
= (u_char
) cy_readb(base_addr
+(CyMIR
<<index
));
1445 channel
= (u_short
) (save_xir
& CyIRChannel
);
1446 info
= &cy_port
[channel
+ chip
* 4
1447 + cinfo
->first_line
];
1448 info
->last_active
= jiffies
;
1449 save_car
= cy_readb(base_addr
+(CyCAR
<<index
));
1450 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_xir
);
1452 mdm_change
= cy_readb(base_addr
+(CyMISR
<<index
));
1453 mdm_status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
1454 spin_unlock(&cinfo
->card_lock
);
1456 if(info
->tty
== 0){/* no place for data, ignore it*/
1459 if (mdm_change
& CyANY_DELTA
) {
1460 /* For statistics only */
1461 if (mdm_change
& CyDCD
) info
->icount
.dcd
++;
1462 if (mdm_change
& CyCTS
) info
->icount
.cts
++;
1463 if (mdm_change
& CyDSR
) info
->icount
.dsr
++;
1464 if (mdm_change
& CyRI
) info
->icount
.rng
++;
1466 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1469 if((mdm_change
& CyDCD
)
1470 && (info
->flags
& ASYNC_CHECK_CD
)){
1471 if(mdm_status
& CyDCD
){
1472 cy_sched_event(info
,
1473 Cy_EVENT_OPEN_WAKEUP
);
1474 }else if(!((info
->flags
1475 & ASYNC_CALLOUT_ACTIVE
)
1477 & ASYNC_CALLOUT_NOHUP
))){
1478 cy_sched_event(info
,
1482 if((mdm_change
& CyCTS
)
1483 && (info
->flags
& ASYNC_CTS_FLOW
)){
1484 if(info
->tty
->hw_stopped
){
1485 if(mdm_status
& CyCTS
){
1486 /* cy_start isn't used
1488 info
->tty
->hw_stopped
= 0;
1489 spin_lock(&cinfo
->card_lock
);
1490 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1491 cy_readb(base_addr
+(CySRER
<<index
)) |
1493 spin_unlock(&cinfo
->card_lock
);
1494 cy_sched_event(info
,
1495 Cy_EVENT_WRITE_WAKEUP
);
1498 if(!(mdm_status
& CyCTS
)){
1499 /* cy_stop isn't used
1501 info
->tty
->hw_stopped
= 1;
1502 spin_lock(&cinfo
->card_lock
);
1503 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
1504 cy_readb(base_addr
+(CySRER
<<index
)) &
1506 spin_unlock(&cinfo
->card_lock
);
1510 if(mdm_change
& CyDSR
){
1512 if(mdm_change
& CyRI
){
1515 /* end of service */
1516 spin_lock(&cinfo
->card_lock
);
1517 cy_writeb((u_long
)base_addr
+(CyMIR
<<index
),
1519 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), save_car
);
1520 spin_unlock(&cinfo
->card_lock
);
1522 } /* end while status != 0 */
1523 } /* end loop for chips... */
1526 /* clear interrupts */
1527 spin_lock(&cinfo
->card_lock
);
1528 cy_writeb((u_long
)card_base_addr
+ (Cy_ClrIntr
<<index
), 0);
1529 /* Cy_ClrIntr is 0x1800 */
1530 spin_unlock(&cinfo
->card_lock
);
1531 } /* cyy_interrupt */
1533 /***********************************************************/
1534 /********* End of block of Cyclom-Y specific code **********/
1535 /******** Start of block of Cyclades-Z specific code *********/
1536 /***********************************************************/
1540 cyz_fetch_msg( struct cyclades_card
*cinfo
,
1541 uclong
*channel
, ucchar
*cmd
, uclong
*param
)
1543 struct FIRM_ID
*firm_id
;
1544 struct ZFW_CTRL
*zfw_ctrl
;
1545 struct BOARD_CTRL
*board_ctrl
;
1546 unsigned long loc_doorbell
;
1548 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1549 if (!ISZLOADED(*cinfo
)){
1552 zfw_ctrl
= (struct ZFW_CTRL
*)
1553 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1554 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1556 loc_doorbell
= cy_readl(&((struct RUNTIME_9060
*)
1557 (cinfo
->ctl_addr
))->loc_doorbell
);
1559 *cmd
= (char)(0xff & loc_doorbell
);
1560 *channel
= cy_readl(&board_ctrl
->fwcmd_channel
);
1561 *param
= (uclong
)cy_readl(&board_ctrl
->fwcmd_param
);
1562 cy_writel(&((struct RUNTIME_9060
*)(cinfo
->ctl_addr
))->loc_doorbell
,
1567 } /* cyz_fetch_msg */
1570 cyz_issue_cmd( struct cyclades_card
*cinfo
,
1571 uclong channel
, ucchar cmd
, uclong param
)
1573 struct FIRM_ID
*firm_id
;
1574 struct ZFW_CTRL
*zfw_ctrl
;
1575 struct BOARD_CTRL
*board_ctrl
;
1576 volatile uclong
*pci_doorbell
;
1579 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1580 if (!ISZLOADED(*cinfo
)){
1583 zfw_ctrl
= (struct ZFW_CTRL
*)
1584 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1585 board_ctrl
= &zfw_ctrl
->board_ctrl
;
1588 pci_doorbell
= (uclong
*)(&((struct RUNTIME_9060
*)
1589 (cinfo
->ctl_addr
))->pci_doorbell
);
1590 while( (cy_readl(pci_doorbell
) & 0xff) != 0){
1591 if (index
++ == 1000){
1596 cy_writel((u_long
)&board_ctrl
->hcmd_channel
, channel
);
1597 cy_writel((u_long
)&board_ctrl
->hcmd_param
, param
);
1598 cy_writel((u_long
)pci_doorbell
, (long)cmd
);
1601 } /* cyz_issue_cmd */
1604 cyz_handle_rx(struct cyclades_port
*info
, volatile struct BUF_CTRL
*buf_ctrl
)
1606 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1607 struct tty_struct
*tty
= info
->tty
;
1608 volatile int char_count
;
1614 volatile uclong rx_put
, rx_get
, rx_bufsize
;
1616 /* Removed due to compilation problems in Alpha systems */
1617 // if ((char_count = CHARS_IN_BUF(buf_ctrl))){
1619 rx_get
= cy_readl(&buf_ctrl
->rx_get
);
1620 rx_put
= cy_readl(&buf_ctrl
->rx_put
);
1621 rx_bufsize
= cy_readl(&buf_ctrl
->rx_bufsize
);
1622 if (rx_put
>= rx_get
)
1623 char_count
= rx_put
- rx_get
;
1625 char_count
= rx_put
- rx_get
+ rx_bufsize
;
1628 info
->last_active
= jiffies
;
1629 info
->jiffies
[1] = jiffies
;
1631 #ifdef CY_ENABLE_MONITORING
1632 info
->mon
.int_count
++;
1633 info
->mon
.char_count
+= char_count
;
1634 if (char_count
> info
->mon
.char_max
)
1635 info
->mon
.char_max
= char_count
;
1636 info
->mon
.char_last
= char_count
;
1639 /* flush received characters */
1640 rx_get
= (rx_get
+ char_count
) & (rx_bufsize
- 1);
1641 info
->rflush_count
++;
1644 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1645 for performance, but because of buffer boundaries, there
1646 may be several steps to the operation */
1647 while(0 < (small_count
=
1648 cy_min((rx_bufsize
- rx_get
),
1649 cy_min((TTY_FLIPBUF_SIZE
- tty
->flip
.count
), char_count
))
1651 memcpy_fromio(tty
->flip
.char_buf_ptr
,
1652 (char *)(cinfo
->base_addr
1653 + cy_readl(&buf_ctrl
->rx_bufaddr
)
1657 tty
->flip
.char_buf_ptr
+= small_count
;
1658 memset(tty
->flip
.flag_buf_ptr
, TTY_NORMAL
, small_count
);
1659 tty
->flip
.flag_buf_ptr
+= small_count
;
1660 rx_get
= (rx_get
+ small_count
) & (rx_bufsize
- 1);
1661 char_count
-= small_count
;
1662 info
->icount
.rx
+= small_count
;
1663 info
->idle_stats
.recv_bytes
+= small_count
;
1664 tty
->flip
.count
+= small_count
;
1667 while(char_count
--){
1668 if (tty
->flip
.count
>= TTY_FLIPBUF_SIZE
){
1669 #ifdef CONFIG_CYZ_INTR
1670 cy_sched_event(info
, Cy_EVENT_Z_RX_FULL
);
1674 data
= cy_readb(cinfo
->base_addr
+
1675 cy_readl(&buf_ctrl
->rx_bufaddr
) + rx_get
);
1676 rx_get
= (rx_get
+ 1) & (rx_bufsize
- 1);
1678 *tty
->flip
.flag_buf_ptr
++ = TTY_NORMAL
;
1679 *tty
->flip
.char_buf_ptr
++ = data
;
1680 info
->idle_stats
.recv_bytes
++;
1684 info
->idle_stats
.recv_idle
= jiffies
;
1685 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1688 cy_writel(&buf_ctrl
->rx_get
, rx_get
);
1693 cyz_handle_tx(struct cyclades_port
*info
, volatile struct BUF_CTRL
*buf_ctrl
)
1695 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
1696 struct tty_struct
*tty
= info
->tty
;
1698 volatile int char_count
;
1702 volatile uclong tx_put
, tx_get
, tx_bufsize
;
1704 /* Removed due to compilation problems in Alpha systems */
1705 // if ((char_count = SPACE_IN_BUF(buf_ctrl))){
1707 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
1708 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
1709 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
1710 if (tx_put
>= tx_get
)
1711 char_count
= tx_get
- tx_put
- 1 + tx_bufsize
;
1713 char_count
= tx_get
- tx_put
- 1;
1721 if(info
->x_char
) { /* send special char */
1722 data
= info
->x_char
;
1724 cy_writeb((cinfo
->base_addr
+
1725 cy_readl(&buf_ctrl
->tx_bufaddr
) + tx_put
), data
);
1726 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1730 info
->last_active
= jiffies
;
1731 info
->jiffies
[2] = jiffies
;
1734 while(0 < (small_count
=
1735 cy_min((tx_bufsize
- tx_put
),
1736 cy_min ((SERIAL_XMIT_SIZE
- info
->xmit_tail
),
1737 cy_min(info
->xmit_cnt
, char_count
))))){
1739 memcpy_toio((char *)(cinfo
->base_addr
1740 + cy_readl(&buf_ctrl
->tx_bufaddr
) + tx_put
),
1741 &info
->xmit_buf
[info
->xmit_tail
],
1744 tx_put
= (tx_put
+ small_count
) & (tx_bufsize
- 1);
1745 char_count
-= small_count
;
1746 info
->icount
.tx
+= small_count
;
1747 info
->xmit_cnt
-= small_count
;
1749 (info
->xmit_tail
+ small_count
) & (SERIAL_XMIT_SIZE
- 1);
1750 info
->last_active
= jiffies
;
1751 info
->jiffies
[2] = jiffies
;
1754 while (info
->xmit_cnt
&& char_count
){
1755 data
= info
->xmit_buf
[info
->xmit_tail
];
1757 info
->xmit_tail
= (info
->xmit_tail
+ 1) & (SERIAL_XMIT_SIZE
- 1);
1759 cy_writeb(cinfo
->base_addr
+
1760 cy_readl(&buf_ctrl
->tx_bufaddr
) + tx_put
, data
);
1761 tx_put
= (tx_put
+ 1) & (tx_bufsize
- 1);
1764 info
->last_active
= jiffies
;
1765 info
->jiffies
[2] = jiffies
;
1769 if (info
->xmit_cnt
< WAKEUP_CHARS
) {
1770 cy_sched_event(info
, Cy_EVENT_WRITE_WAKEUP
);
1773 cy_writel(&buf_ctrl
->tx_put
, tx_put
);
1778 cyz_handle_cmd(struct cyclades_card
*cinfo
)
1780 struct tty_struct
*tty
;
1781 struct cyclades_port
*info
;
1782 static volatile struct FIRM_ID
*firm_id
;
1783 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1784 static volatile struct BOARD_CTRL
*board_ctrl
;
1785 static volatile struct CH_CTRL
*ch_ctrl
;
1786 static volatile struct BUF_CTRL
*buf_ctrl
;
1790 uclong hw_ver
, fw_ver
;
1794 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1795 zfw_ctrl
= (struct ZFW_CTRL
*)
1796 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1797 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1798 fw_ver
= cy_readl(&board_ctrl
->fw_version
);
1799 hw_ver
= cy_readl(&((struct RUNTIME_9060
*)(cinfo
->ctl_addr
))->mail_box_0
);
1801 while(cyz_fetch_msg(cinfo
, &channel
, &cmd
, ¶m
) == 1) {
1804 info
= &cy_port
[channel
+ cinfo
->first_line
];
1805 if((tty
= info
->tty
) == 0) {
1808 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
1809 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
1814 *tty
->flip
.flag_buf_ptr
++ = TTY_PARITY
;
1815 *tty
->flip
.char_buf_ptr
++ = 0;
1821 *tty
->flip
.flag_buf_ptr
++ = TTY_FRAME
;
1822 *tty
->flip
.char_buf_ptr
++ = 0;
1828 *tty
->flip
.flag_buf_ptr
++ = TTY_BREAK
;
1829 *tty
->flip
.char_buf_ptr
++ = 0;
1836 if (info
->flags
& ASYNC_CHECK_CD
){
1839 cy_readl(&ch_ctrl
->rs_status
)) & C_RS_DCD
) {
1840 cy_sched_event(info
, Cy_EVENT_OPEN_WAKEUP
);
1841 }else if(!((info
->flags
& ASYNC_CALLOUT_ACTIVE
)
1842 &&(info
->flags
& ASYNC_CALLOUT_NOHUP
))){
1843 cy_sched_event(info
, Cy_EVENT_HANGUP
);
1861 cy_sched_event(info
, Cy_EVENT_SHUTDOWN_WAKEUP
);
1864 #ifdef CONFIG_CYZ_INTR
1868 /* Reception Interrupt */
1869 #ifdef CY_DEBUG_INTERRUPTS
1870 printk("cyz_interrupt: rcvd intr, card %d, port %ld\n\r",
1871 info
->card
, channel
);
1873 cyz_handle_rx(info
, buf_ctrl
);
1878 /* Transmission Interrupt */
1879 #ifdef CY_DEBUG_INTERRUPTS
1880 printk("cyz_interrupt: xmit intr, card %d, port %ld\n\r",
1881 info
->card
, channel
);
1883 cyz_handle_tx(info
, buf_ctrl
);
1885 #endif /* CONFIG_CYZ_INTR */
1887 /* should do something with this !!! */
1893 cy_sched_event(info
, Cy_EVENT_DELTA_WAKEUP
);
1895 queue_task(&tty
->flip
.tqueue
, &tq_timer
);
1899 #ifdef CONFIG_CYZ_INTR
1901 cyz_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
1903 struct cyclades_card
*cinfo
;
1905 if((cinfo
= (struct cyclades_card
*)dev_id
) == 0){
1906 #ifdef CY_DEBUG_INTERRUPTS
1907 printk("cyz_interrupt: spurious interrupt %d\n\r", irq
);
1909 return; /* spurious interrupt */
1912 if (!ISZLOADED(*cinfo
)) {
1913 #ifdef CY_DEBUG_INTERRUPTS
1914 printk("cyz_interrupt: board not yet loaded (IRQ%d).\n\r", irq
);
1919 /* Handle the interrupts */
1920 cyz_handle_cmd(cinfo
);
1923 } /* cyz_interrupt */
1926 cyz_rx_restart(unsigned long arg
)
1928 struct cyclades_port
*info
= (struct cyclades_port
*)arg
;
1930 int card
= info
->card
;
1931 uclong channel
= (info
->line
) - (cy_card
[card
].first_line
);
1933 cyz_rx_full_timer
[info
->card
].expires
= jiffies
+ HZ
;
1934 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK2
, 0L);
1936 printk("cyc:cyz_rx_restart retval was %x\n", retval
);
1940 #else /* CONFIG_CYZ_INTR */
1943 cyz_poll(unsigned long arg
)
1945 struct cyclades_card
*cinfo
;
1946 struct cyclades_port
*info
;
1947 struct tty_struct
*tty
;
1948 static volatile struct FIRM_ID
*firm_id
;
1949 static volatile struct ZFW_CTRL
*zfw_ctrl
;
1950 static volatile struct BOARD_CTRL
*board_ctrl
;
1951 static volatile struct CH_CTRL
*ch_ctrl
;
1952 static volatile struct BUF_CTRL
*buf_ctrl
;
1955 cyz_timerlist
.expires
= jiffies
+ (HZ
);
1956 for (card
= 0 ; card
< NR_CARDS
; card
++){
1957 cinfo
= &cy_card
[card
];
1959 if (!IS_CYC_Z(*cinfo
)) continue;
1960 if (!ISZLOADED(*cinfo
)) continue;
1962 /* Skip first polling cycle to avoid racing conditions with the FW */
1963 if (!cinfo
->intr_enabled
) {
1964 cinfo
->intr_enabled
= 1;
1968 firm_id
= (struct FIRM_ID
*)(cinfo
->base_addr
+ ID_ADDRESS
);
1969 zfw_ctrl
= (struct ZFW_CTRL
*)
1970 (cinfo
->base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
1971 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
1973 cyz_handle_cmd(cinfo
);
1975 for (port
= 0; port
< cy_readl(&board_ctrl
->n_channel
); port
++){
1976 info
= &cy_port
[ port
+ cinfo
->first_line
];
1978 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[port
]);
1979 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[port
]);
1981 cyz_handle_rx(info
, buf_ctrl
);
1982 cyz_handle_tx(info
, buf_ctrl
);
1984 /* poll every 'cyz_polling_cycle' period */
1985 cyz_timerlist
.expires
= jiffies
+ cyz_polling_cycle
;
1987 add_timer(&cyz_timerlist
);
1992 #endif /* CONFIG_CYZ_INTR */
1994 /********** End of block of Cyclades-Z specific code *********/
1995 /***********************************************************/
1998 /* This is called whenever a port becomes active;
1999 interrupts are enabled and DTR & RTS are turned on.
2002 startup(struct cyclades_port
* info
)
2004 unsigned long flags
;
2006 unsigned char *base_addr
;
2007 int card
,chip
,channel
,index
;
2011 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2013 page
= get_free_page(GFP_KERNEL
);
2017 CY_LOCK(info
, flags
);
2019 if (info
->flags
& ASYNC_INITIALIZED
){
2026 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2035 info
->xmit_buf
= (unsigned char *) page
;
2037 CY_UNLOCK(info
, flags
);
2039 set_line_char(info
);
2041 if (!IS_CYC_Z(cy_card
[card
])) {
2044 index
= cy_card
[card
].bus_index
;
2045 base_addr
= (unsigned char*)
2046 (cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
));
2048 #ifdef CY_DEBUG_OPEN
2049 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
2050 card
, chip
, channel
, (long)base_addr
);/**/
2053 CY_LOCK(info
, flags
);
2055 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2057 cy_writeb((ulong
)base_addr
+(CyRTPR
<<index
), (info
->default_timeout
2058 ? info
->default_timeout
: 0x02)); /* 10ms rx timeout */
2060 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyENB_RCVR
|CyENB_XMTR
,index
);
2062 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2063 cy_writeb((ulong
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
2064 cy_writeb((ulong
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
2067 printk("cyc:startup raising DTR\n");
2068 printk(" status: 0x%x, 0x%x\n",
2069 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2070 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2073 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2074 cy_readb(base_addr
+(CySRER
<<index
)) | CyRxData
);
2075 info
->flags
|= ASYNC_INITIALIZED
;
2078 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2080 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2081 info
->breakon
= info
->breakoff
= 0;
2082 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2083 info
->idle_stats
.in_use
=
2084 info
->idle_stats
.recv_idle
=
2085 info
->idle_stats
.xmit_idle
= jiffies
;
2087 CY_UNLOCK(info
, flags
);
2090 struct FIRM_ID
*firm_id
;
2091 struct ZFW_CTRL
*zfw_ctrl
;
2092 struct BOARD_CTRL
*board_ctrl
;
2093 struct CH_CTRL
*ch_ctrl
;
2096 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
2098 firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2099 if (!ISZLOADED(cy_card
[card
])){
2105 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2106 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2107 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2109 #ifdef CY_DEBUG_OPEN
2110 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2111 card
, channel
, (long)base_addr
);/**/
2114 CY_LOCK(info
, flags
);
2116 cy_writel(&ch_ctrl
[channel
].op_mode
, C_CH_ENABLE
);
2118 #ifdef CONFIG_CYZ_INTR
2119 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2120 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2124 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2127 #endif /* CONFIG_CYZ_INTR */
2129 #ifdef CONFIG_CYZ_INTR
2130 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2131 C_IN_TXBEMPTY
|C_IN_TXLOWWM
|C_IN_RXHIWM
|C_IN_RXNNDT
|
2134 cy_writel(&ch_ctrl
[channel
].intr_enable
,
2136 #endif /* CONFIG_CYZ_INTR */
2139 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
2141 printk("cyc:startup(1) retval was %x\n", retval
);
2144 /* Flush RX buffers before raising DTR and RTS */
2145 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_RX
, 0L);
2147 printk("cyc:startup(2) retval was %x\n", retval
);
2150 /* set timeout !!! */
2151 /* set RTS and DTR !!! */
2152 cy_writel(&ch_ctrl
[channel
].rs_control
,
2153 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
| C_RS_DTR
) ;
2154 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2155 channel
, C_CM_IOCTLM
, 0L);
2157 printk("cyc:startup(3) retval was %x\n", retval
);
2160 printk("cyc:startup raising Z DTR\n");
2163 /* enable send, recv, modem !!! */
2165 info
->flags
|= ASYNC_INITIALIZED
;
2167 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2169 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
2170 info
->breakon
= info
->breakoff
= 0;
2171 memset((char *)&info
->idle_stats
, 0, sizeof(info
->idle_stats
));
2172 info
->idle_stats
.in_use
=
2173 info
->idle_stats
.recv_idle
=
2174 info
->idle_stats
.xmit_idle
= jiffies
;
2176 CY_UNLOCK(info
, flags
);
2179 #ifdef CY_DEBUG_OPEN
2180 printk(" cyc startup done\n");
2185 CY_UNLOCK(info
, flags
);
2191 start_xmit( struct cyclades_port
*info
)
2193 unsigned long flags
;
2194 unsigned char *base_addr
;
2195 int card
,chip
,channel
,index
;
2198 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2199 if (!IS_CYC_Z(cy_card
[card
])) {
2202 index
= cy_card
[card
].bus_index
;
2203 base_addr
= (unsigned char*)
2204 (cy_card
[card
].base_addr
2205 + (cy_chip_offset
[chip
]<<index
));
2207 CY_LOCK(info
, flags
);
2208 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), channel
);
2209 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2210 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxMpty
);
2211 CY_UNLOCK(info
, flags
);
2213 #ifdef CONFIG_CYZ_INTR
2216 CY_LOCK(info
, flags
);
2217 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_INTBACK
, 0L);
2219 printk("cyc:start_xmit retval was %x\n", retval
);
2221 CY_UNLOCK(info
, flags
);
2222 #else /* CONFIG_CYZ_INTR */
2223 /* Don't have to do anything at this time */
2224 #endif /* CONFIG_CYZ_INTR */
2229 * This routine shuts down a serial port; interrupts are disabled,
2230 * and DTR is dropped if the hangup on close termio flag is on.
2233 shutdown(struct cyclades_port
* info
)
2235 unsigned long flags
;
2236 unsigned char *base_addr
;
2237 int card
,chip
,channel
,index
;
2239 if (!(info
->flags
& ASYNC_INITIALIZED
)){
2244 channel
= info
->line
- cy_card
[card
].first_line
;
2245 if (!IS_CYC_Z(cy_card
[card
])) {
2248 index
= cy_card
[card
].bus_index
;
2249 base_addr
= (unsigned char*)
2250 (cy_card
[card
].base_addr
2251 + (cy_chip_offset
[chip
]<<index
));
2253 #ifdef CY_DEBUG_OPEN
2254 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2255 card
, chip
, channel
, (long)base_addr
);
2258 CY_LOCK(info
, flags
);
2260 /* Clear delta_msr_wait queue to avoid mem leaks. */
2261 wake_up_interruptible(&info
->delta_msr_wait
);
2263 if (info
->xmit_buf
){
2264 unsigned char * temp
;
2265 temp
= info
->xmit_buf
;
2267 free_page((unsigned long) temp
);
2269 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2270 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2271 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
2272 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
2274 printk("cyc shutdown dropping DTR\n");
2275 printk(" status: 0x%x, 0x%x\n",
2276 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2277 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2280 cyy_issue_cmd(base_addr
,CyCHAN_CTL
|CyDIS_RCVR
,index
);
2281 /* it may be appropriate to clear _XMIT at
2282 some later date (after testing)!!! */
2285 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2287 info
->flags
&= ~ASYNC_INITIALIZED
;
2288 CY_UNLOCK(info
, flags
);
2290 struct FIRM_ID
*firm_id
;
2291 struct ZFW_CTRL
*zfw_ctrl
;
2292 struct BOARD_CTRL
*board_ctrl
;
2293 struct CH_CTRL
*ch_ctrl
;
2296 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
2297 #ifdef CY_DEBUG_OPEN
2298 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2299 card
, channel
, (long)base_addr
);
2302 firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2303 if (!ISZLOADED(cy_card
[card
])) {
2309 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2310 board_ctrl
= &(zfw_ctrl
->board_ctrl
);
2311 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2313 CY_LOCK(info
, flags
);
2315 if (info
->xmit_buf
){
2316 unsigned char * temp
;
2317 temp
= info
->xmit_buf
;
2319 free_page((unsigned long) temp
);
2322 if (!info
->tty
|| (info
->tty
->termios
->c_cflag
& HUPCL
)) {
2323 cy_writel((u_long
)&ch_ctrl
[channel
].rs_control
,
2324 (uclong
)(cy_readl(&ch_ctrl
[channel
].rs_control
) &
2325 ~(C_RS_RTS
| C_RS_DTR
)));
2326 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2327 channel
, C_CM_IOCTLM
, 0L);
2329 printk("cyc:shutdown retval was %x\n", retval
);
2332 printk("cyc:shutdown dropping Z DTR\n");
2337 set_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
2339 info
->flags
&= ~ASYNC_INITIALIZED
;
2341 CY_UNLOCK(info
, flags
);
2344 #ifdef CY_DEBUG_OPEN
2345 printk(" cyc shutdown done\n");
2352 * ------------------------------------------------------------
2353 * cy_open() and friends
2354 * ------------------------------------------------------------
2358 block_til_ready(struct tty_struct
*tty
, struct file
* filp
,
2359 struct cyclades_port
*info
)
2361 DECLARE_WAITQUEUE(wait
, current
);
2362 struct cyclades_card
*cinfo
;
2363 unsigned long flags
;
2364 int chip
, channel
,index
;
2368 cinfo
= &cy_card
[info
->card
];
2369 channel
= info
->line
- cinfo
->first_line
;
2372 * If the device is in the middle of being closed, then block
2373 * until it's done, and then try again.
2375 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2376 if (info
->flags
& ASYNC_CLOSING
) {
2377 interruptible_sleep_on(&info
->close_wait
);
2379 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2383 * If this is a callout device, then just make sure the normal
2384 * device isn't being used.
2386 if (tty
->driver
.subtype
== SERIAL_TYPE_CALLOUT
) {
2387 if (info
->flags
& ASYNC_NORMAL_ACTIVE
){
2390 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2391 (info
->flags
& ASYNC_SESSION_LOCKOUT
) &&
2392 (info
->session
!= current
->session
)){
2395 if ((info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2396 (info
->flags
& ASYNC_PGRP_LOCKOUT
) &&
2397 (info
->pgrp
!= current
->pgrp
)){
2400 info
->flags
|= ASYNC_CALLOUT_ACTIVE
;
2405 * If non-blocking mode is set, then make the check up front
2408 if ((filp
->f_flags
& O_NONBLOCK
) ||
2409 (tty
->flags
& (1 << TTY_IO_ERROR
))) {
2410 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
){
2413 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2418 * Block waiting for the carrier detect and the line to become
2419 * free (i.e., not in use by the callout). While we are in
2420 * this loop, info->count is dropped by one, so that
2421 * cy_close() knows when to free things. We restore it upon
2422 * exit, either normal or abnormal.
2425 add_wait_queue(&info
->open_wait
, &wait
);
2426 #ifdef CY_DEBUG_OPEN
2427 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2428 info
->line
, info
->count
);/**/
2430 CY_LOCK(info
, flags
);
2431 if (!tty_hung_up_p(filp
))
2433 CY_UNLOCK(info
, flags
);
2434 #ifdef CY_DEBUG_COUNT
2435 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2436 current
->pid
, info
->count
);
2438 info
->blocked_open
++;
2440 if (!IS_CYC_Z(*cinfo
)) {
2443 index
= cinfo
->bus_index
;
2444 base_addr
= (char *)(cinfo
->base_addr
2445 + (cy_chip_offset
[chip
]<<index
));
2448 CY_LOCK(info
, flags
);
2449 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2450 (tty
->termios
->c_cflag
& CBAUD
)){
2451 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2452 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
2453 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
2455 printk("cyc:block_til_ready raising DTR\n");
2456 printk(" status: 0x%x, 0x%x\n",
2457 cy_readb(base_addr
+(CyMSVR1
<<index
)),
2458 cy_readb(base_addr
+(CyMSVR2
<<index
)));
2461 CY_UNLOCK(info
, flags
);
2463 set_current_state(TASK_INTERRUPTIBLE
);
2464 if (tty_hung_up_p(filp
)
2465 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2466 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2467 -EAGAIN
: -ERESTARTSYS
);
2471 CY_LOCK(info
, flags
);
2472 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2473 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2474 && !(info
->flags
& ASYNC_CLOSING
)
2476 || (cy_readb(base_addr
+(CyMSVR1
<<index
)) & CyDCD
))) {
2477 CY_UNLOCK(info
, flags
);
2480 CY_UNLOCK(info
, flags
);
2482 if (signal_pending(current
)) {
2483 retval
= -ERESTARTSYS
;
2486 #ifdef CY_DEBUG_OPEN
2487 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2488 info
->line
, info
->count
);/**/
2493 struct FIRM_ID
*firm_id
;
2494 struct ZFW_CTRL
*zfw_ctrl
;
2495 struct BOARD_CTRL
*board_ctrl
;
2496 struct CH_CTRL
*ch_ctrl
;
2499 base_addr
= (char *)(cinfo
->base_addr
);
2500 firm_id
= (struct FIRM_ID
*)
2501 (base_addr
+ ID_ADDRESS
);
2502 if (!ISZLOADED(*cinfo
)){
2508 (base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2509 board_ctrl
= &zfw_ctrl
->board_ctrl
;
2510 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2513 cy_writel(&ch_ctrl
[channel
].rs_control
,
2514 cy_readl(&ch_ctrl
[channel
].rs_control
) | 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 was %x\n", retval
);
2521 printk("cyc:block_til_ready raising Z DTR\n");
2524 set_current_state(TASK_INTERRUPTIBLE
);
2525 if (tty_hung_up_p(filp
)
2526 || !(info
->flags
& ASYNC_INITIALIZED
) ){
2527 retval
= ((info
->flags
& ASYNC_HUP_NOTIFY
) ?
2528 -EAGAIN
: -ERESTARTSYS
);
2531 if (!(info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2532 && !(info
->flags
& ASYNC_CLOSING
)
2534 || (cy_readl(&ch_ctrl
[channel
].rs_status
) & C_RS_DCD
))) {
2537 if (signal_pending(current
)) {
2538 retval
= -ERESTARTSYS
;
2541 #ifdef CY_DEBUG_OPEN
2542 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2543 info
->line
, info
->count
);/**/
2548 current
->state
= TASK_RUNNING
;
2549 remove_wait_queue(&info
->open_wait
, &wait
);
2550 if (!tty_hung_up_p(filp
)){
2552 #ifdef CY_DEBUG_COUNT
2553 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2554 current
->pid
, info
->count
);
2557 info
->blocked_open
--;
2558 #ifdef CY_DEBUG_OPEN
2559 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2560 info
->line
, info
->count
);/**/
2564 info
->flags
|= ASYNC_NORMAL_ACTIVE
;
2566 } /* block_til_ready */
2570 * This routine is called whenever a serial port is opened. It
2571 * performs the serial-specific initialization for the tty structure.
2574 cy_open(struct tty_struct
*tty
, struct file
* filp
)
2576 struct cyclades_port
*info
;
2581 line
= MINOR(tty
->device
) - tty
->driver
.minor_start
;
2582 if ((line
< 0) || (NR_PORTS
<= line
)){
2586 info
= &cy_port
[line
];
2587 if (info
->line
< 0){
2592 /* If the card's firmware hasn't been loaded,
2593 treat it as absent from the system. This
2594 will make the user pay attention.
2596 if (IS_CYC_Z(cy_card
[info
->card
])) {
2597 if (!ISZLOADED(cy_card
[info
->card
])) {
2598 if (((ZE_V1
==cy_readl(&((struct RUNTIME_9060
*)
2599 ((cy_card
[info
->card
]).ctl_addr
))->mail_box_0
)) &&
2600 Z_FPGA_CHECK(cy_card
[info
->card
])) &&
2601 (ZFIRM_HLT
==cy_readl(&((struct FIRM_ID
*)
2602 ((cy_card
[info
->card
]).base_addr
+ID_ADDRESS
))->signature
)))
2604 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2606 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2611 #ifdef CONFIG_CYZ_INTR
2613 /* In case this Z board is operating in interrupt mode, its
2614 interrupts should be enabled as soon as the first open happens
2615 to one of its ports. */
2616 if (!cy_card
[info
->card
].intr_enabled
) {
2617 /* Enable interrupts on the PLX chip */
2618 cy_writew(cy_card
[info
->card
].ctl_addr
+0x68,
2619 cy_readw(cy_card
[info
->card
].ctl_addr
+0x68)|0x0900);
2620 /* Enable interrupts on the FW */
2621 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
2622 0, C_CM_IRQ_ENBL
, 0L);
2624 printk("cyc:IRQ enable retval was %x\n", retval
);
2626 cy_card
[info
->card
].intr_enabled
= 1;
2629 #endif /* CONFIG_CYZ_INTR */
2631 #ifdef CY_DEBUG_OTHER
2632 printk("cyc:cy_open ttyC%d\n", info
->line
); /* */
2634 tty
->driver_data
= info
;
2636 if (serial_paranoia_check(info
, tty
->device
, "cy_open")){
2639 #ifdef CY_DEBUG_OPEN
2640 printk("cyc:cy_open ttyC%d, count = %d\n",
2641 info
->line
, info
->count
);/**/
2644 #ifdef CY_DEBUG_COUNT
2645 printk("cyc:cy_open (%d): incrementing count to %d\n",
2646 current
->pid
, info
->count
);
2649 page
= get_free_page(GFP_KERNEL
);
2655 tmp_buf
= (unsigned char *) page
;
2659 * If the port is the middle of closing, bail out now
2661 if (tty_hung_up_p(filp
) || (info
->flags
& ASYNC_CLOSING
)) {
2662 if (info
->flags
& ASYNC_CLOSING
)
2663 interruptible_sleep_on(&info
->close_wait
);
2664 return ((info
->flags
& ASYNC_HUP_NOTIFY
) ? -EAGAIN
: -ERESTARTSYS
);
2668 * Start up serial port
2670 retval
= startup(info
);
2675 retval
= block_til_ready(tty
, filp
, info
);
2677 #ifdef CY_DEBUG_OPEN
2678 printk("cyc:cy_open returning after block_til_ready with %d\n",
2684 if ((info
->count
== 1) && (info
->flags
& ASYNC_SPLIT_TERMIOS
)) {
2685 if (tty
->driver
.subtype
== SERIAL_TYPE_NORMAL
)
2686 *tty
->termios
= info
->normal_termios
;
2688 *tty
->termios
= info
->callout_termios
;
2691 info
->session
= current
->session
;
2692 info
->pgrp
= current
->pgrp
;
2694 #ifdef CY_DEBUG_OPEN
2695 printk(" cyc:cy_open done\n");/**/
2703 * cy_wait_until_sent() --- wait until the transmitter is empty
2706 cy_wait_until_sent(struct tty_struct
*tty
, int timeout
)
2708 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
2709 unsigned char *base_addr
;
2710 int card
,chip
,channel
,index
;
2711 unsigned long orig_jiffies
, char_time
;
2713 if (serial_paranoia_check(info
, tty
->device
, "cy_wait_until_sent"))
2716 if (info
->xmit_fifo_size
== 0)
2717 return; /* Just in case.... */
2720 orig_jiffies
= jiffies
;
2722 * Set the check interval to be 1/5 of the estimated time to
2723 * send a single character, and make it at least 1. The check
2724 * interval should also be less than the timeout.
2726 * Note: we have to use pretty tight timings here to satisfy
2729 char_time
= (info
->timeout
- HZ
/50) / info
->xmit_fifo_size
;
2730 char_time
= char_time
/ 5;
2736 char_time
= MIN(char_time
, timeout
);
2738 * If the transmitter hasn't cleared in twice the approximate
2739 * amount of time to send the entire FIFO, it probably won't
2740 * ever clear. This assumes the UART isn't doing flow
2741 * control, which is currently the case. Hence, if it ever
2742 * takes longer than info->timeout, this is probably due to a
2743 * UART bug of some kind. So, we clamp the timeout parameter at
2746 if (!timeout
|| timeout
> 2*info
->timeout
)
2747 timeout
= 2*info
->timeout
;
2748 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2749 printk("In cy_wait_until_sent(%d) check=%lu...", timeout
, char_time
);
2750 printk("jiff=%lu...", jiffies
);
2753 channel
= (info
->line
) - (cy_card
[card
].first_line
);
2754 if (!IS_CYC_Z(cy_card
[card
])) {
2757 index
= cy_card
[card
].bus_index
;
2758 base_addr
= (unsigned char *)
2759 (cy_card
[card
].base_addr
+ (cy_chip_offset
[chip
]<<index
));
2760 while (cy_readb(base_addr
+(CySRER
<<index
)) & CyTxMpty
) {
2761 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2762 printk("Not clean (jiff=%lu)...", jiffies
);
2764 current
->state
= TASK_INTERRUPTIBLE
;
2765 schedule_timeout(char_time
);
2766 if (signal_pending(current
))
2768 if (timeout
&& time_after(jiffies
, orig_jiffies
+ timeout
))
2771 current
->state
= TASK_RUNNING
;
2775 /* Run one more char cycle */
2776 current
->state
= TASK_INTERRUPTIBLE
;
2777 schedule_timeout(char_time
* 5);
2778 current
->state
= TASK_RUNNING
;
2779 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2780 printk("Clean (jiff=%lu)...done\n", jiffies
);
2785 * This routine is called when a particular tty device is closed.
2788 cy_close(struct tty_struct
*tty
, struct file
*filp
)
2790 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2791 unsigned long flags
;
2793 #ifdef CY_DEBUG_OTHER
2794 printk("cyc:cy_close ttyC%d\n", info
->line
);
2797 if (!info
|| serial_paranoia_check(info
, tty
->device
, "cy_close")){
2801 CY_LOCK(info
, flags
);
2802 /* If the TTY is being hung up, nothing to do */
2803 if (tty_hung_up_p(filp
)) {
2805 CY_UNLOCK(info
, flags
);
2809 #ifdef CY_DEBUG_OPEN
2810 printk("cyc:cy_close ttyC%d, count = %d\n", info
->line
, info
->count
);
2812 if ((tty
->count
== 1) && (info
->count
!= 1)) {
2814 * Uh, oh. tty->count is 1, which means that the tty
2815 * structure will be freed. Info->count should always
2816 * be one in these conditions. If it's greater than
2817 * one, we've got real problems, since it means the
2818 * serial port won't be shutdown.
2820 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2821 "info->count is %d\n", info
->count
);
2824 #ifdef CY_DEBUG_COUNT
2825 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2826 current
->pid
, info
->count
- 1);
2828 if (--info
->count
< 0) {
2829 #ifdef CY_DEBUG_COUNT
2830 printk("cyc:cyc_close setting count to 0\n");
2836 CY_UNLOCK(info
, flags
);
2839 info
->flags
|= ASYNC_CLOSING
;
2841 * Save the termios structure, since this port may have
2842 * separate termios for callout and dialin.
2844 if (info
->flags
& ASYNC_NORMAL_ACTIVE
)
2845 info
->normal_termios
= *tty
->termios
;
2846 if (info
->flags
& ASYNC_CALLOUT_ACTIVE
)
2847 info
->callout_termios
= *tty
->termios
;
2850 * Now we wait for the transmit buffer to clear; and we notify
2851 * the line discipline to only process XON/XOFF characters.
2854 CY_UNLOCK(info
, flags
);
2855 if (info
->closing_wait
!= CY_CLOSING_WAIT_NONE
) {
2856 tty_wait_until_sent(tty
, info
->closing_wait
);
2858 CY_LOCK(info
, flags
);
2860 if (!IS_CYC_Z(cy_card
[info
->card
])) {
2861 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2862 int index
= cy_card
[info
->card
].bus_index
;
2863 unsigned char *base_addr
= (unsigned char *)
2864 (cy_card
[info
->card
].base_addr
+
2865 (cy_chip_offset
[channel
>>2] <<index
));
2866 /* Stop accepting input */
2868 cy_writeb((ulong
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
2869 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
2870 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyRxData
);
2871 if (info
->flags
& ASYNC_INITIALIZED
) {
2872 /* Waiting for on-board buffers to be empty before closing
2874 CY_UNLOCK(info
, flags
);
2875 cy_wait_until_sent(tty
, info
->timeout
);
2876 CY_LOCK(info
, flags
);
2880 /* Waiting for on-board buffers to be empty before closing the port */
2881 unsigned char *base_addr
= (unsigned char *)
2882 cy_card
[info
->card
].base_addr
;
2883 struct FIRM_ID
*firm_id
= (struct FIRM_ID
*) (base_addr
+ ID_ADDRESS
);
2884 struct ZFW_CTRL
*zfw_ctrl
=
2885 (struct ZFW_CTRL
*) (base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
2886 struct CH_CTRL
*ch_ctrl
= zfw_ctrl
->ch_ctrl
;
2887 int channel
= info
->line
- cy_card
[info
->card
].first_line
;
2890 if (cy_readl(&ch_ctrl
[channel
].flow_status
) != C_FS_TXIDLE
) {
2891 retval
= cyz_issue_cmd(&cy_card
[info
->card
], channel
,
2894 printk("cyc:cy_close retval was %x\n", retval
);
2896 CY_UNLOCK(info
, flags
);
2897 interruptible_sleep_on(&info
->shutdown_wait
);
2898 CY_LOCK(info
, flags
);
2903 CY_UNLOCK(info
, flags
);
2905 if (tty
->driver
.flush_buffer
)
2906 tty
->driver
.flush_buffer(tty
);
2907 if (tty
->ldisc
.flush_buffer
)
2908 tty
->ldisc
.flush_buffer(tty
);
2909 CY_LOCK(info
, flags
);
2914 if (info
->blocked_open
) {
2915 CY_UNLOCK(info
, flags
);
2916 if (info
->close_delay
) {
2917 current
->state
= TASK_INTERRUPTIBLE
;
2918 schedule_timeout(info
->close_delay
);
2920 wake_up_interruptible(&info
->open_wait
);
2921 CY_LOCK(info
, flags
);
2923 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
|
2925 wake_up_interruptible(&info
->close_wait
);
2927 #ifdef CY_DEBUG_OTHER
2928 printk(" cyc:cy_close done\n");
2932 CY_UNLOCK(info
, flags
);
2937 /* This routine gets called when tty_write has put something into
2938 * the write_queue. The characters may come from user space or
2941 * This routine will return the number of characters actually
2942 * accepted for writing.
2944 * If the port is not already transmitting stuff, start it off by
2945 * enabling interrupts. The interrupt service routine will then
2946 * ensure that the characters are sent.
2947 * If the port is already active, there is no need to kick it.
2951 cy_write(struct tty_struct
* tty
, int from_user
,
2952 const unsigned char *buf
, int count
)
2954 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
2955 unsigned long flags
;
2959 printk("cyc:cy_write ttyC%d\n", info
->line
); /* */
2962 if (serial_paranoia_check(info
, tty
->device
, "cy_write")){
2966 if (!tty
|| !info
->xmit_buf
|| !tmp_buf
){
2970 CY_LOCK(info
, flags
);
2974 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
2975 SERIAL_XMIT_SIZE
- info
->xmit_head
));
2979 c
-= copy_from_user(tmp_buf
, buf
, c
);
2986 c
= MIN(c
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
2987 SERIAL_XMIT_SIZE
- info
->xmit_head
));
2988 memcpy(info
->xmit_buf
+ info
->xmit_head
, tmp_buf
, c
);
2989 info
->xmit_head
= ((info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1));
2990 info
->xmit_cnt
+= c
;
2998 c
= MIN(count
, MIN(SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1,
2999 SERIAL_XMIT_SIZE
- info
->xmit_head
));
3003 memcpy(info
->xmit_buf
+ info
->xmit_head
, buf
, c
);
3004 info
->xmit_head
= (info
->xmit_head
+ c
) & (SERIAL_XMIT_SIZE
-1);
3005 info
->xmit_cnt
+= c
;
3011 CY_UNLOCK(info
, flags
);
3013 info
->idle_stats
.xmit_bytes
+= ret
;
3014 info
->idle_stats
.xmit_idle
= jiffies
;
3016 if (info
->xmit_cnt
&& !tty
->stopped
&& !tty
->hw_stopped
) {
3024 * This routine is called by the kernel to write a single
3025 * character to the tty device. If the kernel uses this routine,
3026 * it must call the flush_chars() routine (if defined) when it is
3027 * done stuffing characters into the driver. If there is no room
3028 * in the queue, the character is ignored.
3031 cy_put_char(struct tty_struct
*tty
, unsigned char ch
)
3033 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3034 unsigned long flags
;
3037 printk("cyc:cy_put_char ttyC%d\n", info
->line
);
3040 if (serial_paranoia_check(info
, tty
->device
, "cy_put_char"))
3043 if (!tty
|| !info
->xmit_buf
)
3046 CY_LOCK(info
, flags
);
3047 if (info
->xmit_cnt
>= SERIAL_XMIT_SIZE
- 1) {
3048 CY_UNLOCK(info
, flags
);
3052 info
->xmit_buf
[info
->xmit_head
++] = ch
;
3053 info
->xmit_head
&= SERIAL_XMIT_SIZE
- 1;
3055 info
->idle_stats
.xmit_bytes
++;
3056 info
->idle_stats
.xmit_idle
= jiffies
;
3057 CY_UNLOCK(info
, flags
);
3062 * This routine is called by the kernel after it has written a
3063 * series of characters to the tty device using put_char().
3066 cy_flush_chars(struct tty_struct
*tty
)
3068 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3071 printk("cyc:cy_flush_chars ttyC%d\n", info
->line
); /* */
3074 if (serial_paranoia_check(info
, tty
->device
, "cy_flush_chars"))
3077 if (info
->xmit_cnt
<= 0 || tty
->stopped
3078 || tty
->hw_stopped
|| !info
->xmit_buf
)
3082 } /* cy_flush_chars */
3086 * This routine returns the numbers of characters the tty driver
3087 * will accept for queuing to be written. This number is subject
3088 * to change as output buffers get emptied, or if the output flow
3089 * control is activated.
3092 cy_write_room(struct tty_struct
*tty
)
3094 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3098 printk("cyc:cy_write_room ttyC%d\n", info
->line
); /* */
3101 if (serial_paranoia_check(info
, tty
->device
, "cy_write_room"))
3103 ret
= SERIAL_XMIT_SIZE
- info
->xmit_cnt
- 1;
3107 } /* cy_write_room */
3111 cy_chars_in_buffer(struct tty_struct
*tty
)
3113 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
3116 if (serial_paranoia_check(info
, tty
->device
, "cy_chars_in_buffer"))
3120 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3122 if (!IS_CYC_Z(cy_card
[card
])) {
3124 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3125 info
->line
, info
->xmit_cnt
); /* */
3127 return info
->xmit_cnt
;
3129 static volatile struct FIRM_ID
*firm_id
;
3130 static volatile struct ZFW_CTRL
*zfw_ctrl
;
3131 static volatile struct CH_CTRL
*ch_ctrl
;
3132 static volatile struct BUF_CTRL
*buf_ctrl
;
3134 volatile uclong tx_put
, tx_get
, tx_bufsize
;
3136 firm_id
= (struct FIRM_ID
*)(cy_card
[card
].base_addr
+ ID_ADDRESS
);
3137 zfw_ctrl
= (struct ZFW_CTRL
*) (cy_card
[card
].base_addr
+
3138 cy_readl(&firm_id
->zfwctrl_addr
));
3139 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3140 buf_ctrl
= &(zfw_ctrl
->buf_ctrl
[channel
]);
3142 tx_get
= cy_readl(&buf_ctrl
->tx_get
);
3143 tx_put
= cy_readl(&buf_ctrl
->tx_put
);
3144 tx_bufsize
= cy_readl(&buf_ctrl
->tx_bufsize
);
3145 if (tx_put
>= tx_get
)
3146 char_count
= tx_put
- tx_get
;
3148 char_count
= tx_put
- tx_get
+ tx_bufsize
;
3150 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
3151 info
->line
, info
->xmit_cnt
+ char_count
); /* */
3153 return (info
->xmit_cnt
+ char_count
);
3155 } /* cy_chars_in_buffer */
3159 * ------------------------------------------------------------
3160 * cy_ioctl() and friends
3161 * ------------------------------------------------------------
3166 * This routine finds or computes the various line characteristics.
3167 * It used to be called config_setup
3170 set_line_char(struct cyclades_port
* info
)
3172 unsigned long flags
;
3173 unsigned char *base_addr
;
3174 int card
,chip
,channel
,index
;
3175 unsigned cflag
, iflag
;
3176 unsigned short chip_number
;
3181 if (!info
->tty
|| !info
->tty
->termios
){
3184 if (info
->line
== -1){
3187 cflag
= info
->tty
->termios
->c_cflag
;
3188 iflag
= info
->tty
->termios
->c_iflag
;
3191 * Set up the tty->alt_speed kludge
3194 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3195 info
->tty
->alt_speed
= 57600;
3196 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3197 info
->tty
->alt_speed
= 115200;
3198 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3199 info
->tty
->alt_speed
= 230400;
3200 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3201 info
->tty
->alt_speed
= 460800;
3205 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3206 chip_number
= channel
/ 4;
3208 if (!IS_CYC_Z(cy_card
[card
])) {
3210 index
= cy_card
[card
].bus_index
;
3213 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
) {
3216 baud
= tty_get_baud_rate(info
->tty
);
3218 if (baud
> CD1400_MAX_SPEED
) {
3219 baud
= CD1400_MAX_SPEED
;
3221 /* find the baud index */
3222 for (i
= 0; i
< 20; i
++) {
3223 if (baud
== baud_table
[i
]) {
3228 i
= 19; /* CD1400_MAX_SPEED */
3232 if(info
->chip_rev
>= CD1400_REV_J
) {
3233 /* It is a CD1400 rev. J or later */
3234 info
->tbpr
= baud_bpr_60
[i
]; /* Tx BPR */
3235 info
->tco
= baud_co_60
[i
]; /* Tx CO */
3236 info
->rbpr
= baud_bpr_60
[i
]; /* Rx BPR */
3237 info
->rco
= baud_co_60
[i
]; /* Rx CO */
3239 info
->tbpr
= baud_bpr_25
[i
]; /* Tx BPR */
3240 info
->tco
= baud_co_25
[i
]; /* Tx CO */
3241 info
->rbpr
= baud_bpr_25
[i
]; /* Rx BPR */
3242 info
->rco
= baud_co_25
[i
]; /* Rx CO */
3244 if (baud_table
[i
] == 134) {
3245 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/269) + 2;
3246 /* get it right for 134.5 baud */
3247 } else if (baud_table
[i
]) {
3248 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud_table
[i
]) + 2;
3249 /* this needs to be propagated into the card info */
3253 /* By tradition (is it a standard?) a baud rate of zero
3254 implies the line should be/has been closed. A bit
3255 later in this routine such a test is performed. */
3257 /* byte size and parity */
3260 info
->cor3
= (info
->default_threshold
3261 ? info
->default_threshold
3262 : baud_cor3
[i
]); /* receive threshold */
3264 switch(cflag
& CSIZE
){
3266 info
->cor1
= Cy_5_BITS
;
3269 info
->cor1
= Cy_6_BITS
;
3272 info
->cor1
= Cy_7_BITS
;
3275 info
->cor1
= Cy_8_BITS
;
3279 info
->cor1
|= Cy_2_STOP
;
3281 if (cflag
& PARENB
){
3282 if (cflag
& PARODD
){
3283 info
->cor1
|= CyPARITY_O
;
3285 info
->cor1
|= CyPARITY_E
;
3288 info
->cor1
|= CyPARITY_NONE
;
3291 /* CTS flow control flag */
3292 if (cflag
& CRTSCTS
){
3293 info
->flags
|= ASYNC_CTS_FLOW
;
3294 info
->cor2
|= CyCtsAE
;
3296 info
->flags
&= ~ASYNC_CTS_FLOW
;
3297 info
->cor2
&= ~CyCtsAE
;
3300 info
->flags
&= ~ASYNC_CHECK_CD
;
3302 info
->flags
|= ASYNC_CHECK_CD
;
3304 /***********************************************
3305 The hardware option, CyRtsAO, presents RTS when
3306 the chip has characters to send. Since most modems
3307 use RTS as reverse (inbound) flow control, this
3308 option is not used. If inbound flow control is
3309 necessary, DTR can be programmed to provide the
3310 appropriate signals for use with a non-standard
3311 cable. Contact Marcio Saito for details.
3312 ***********************************************/
3316 base_addr
= (unsigned char*)
3317 (cy_card
[card
].base_addr
3318 + (cy_chip_offset
[chip
]<<index
));
3320 CY_LOCK(info
, flags
);
3321 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3323 /* tx and rx baud rate */
3325 cy_writeb((u_long
)base_addr
+(CyTCOR
<<index
), info
->tco
);
3326 cy_writeb((u_long
)base_addr
+(CyTBPR
<<index
), info
->tbpr
);
3327 cy_writeb((u_long
)base_addr
+(CyRCOR
<<index
), info
->rco
);
3328 cy_writeb((u_long
)base_addr
+(CyRBPR
<<index
), info
->rbpr
);
3330 /* set line characteristics according configuration */
3332 cy_writeb((u_long
)base_addr
+(CySCHR1
<<index
),
3333 START_CHAR(info
->tty
));
3334 cy_writeb((u_long
)base_addr
+(CySCHR2
<<index
),
3335 STOP_CHAR(info
->tty
));
3336 cy_writeb((u_long
)base_addr
+(CyCOR1
<<index
), info
->cor1
);
3337 cy_writeb((u_long
)base_addr
+(CyCOR2
<<index
), info
->cor2
);
3338 cy_writeb((u_long
)base_addr
+(CyCOR3
<<index
), info
->cor3
);
3339 cy_writeb((u_long
)base_addr
+(CyCOR4
<<index
), info
->cor4
);
3340 cy_writeb((u_long
)base_addr
+(CyCOR5
<<index
), info
->cor5
);
3342 cyy_issue_cmd(base_addr
,
3343 CyCOR_CHANGE
|CyCOR1ch
|CyCOR2ch
|CyCOR3ch
,index
);
3345 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
3346 (u_char
)channel
); /* !!! Is this needed? */
3347 cy_writeb((u_long
)base_addr
+(CyRTPR
<<index
), (info
->default_timeout
3348 ? info
->default_timeout
3349 : 0x02)); /* 10ms rx timeout */
3351 if (C_CLOCAL(info
->tty
)) {
3352 /* without modem intr */
3353 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
3354 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3355 /* act on 1->0 modem transitions */
3356 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3357 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3358 (CyCTS
|rflow_thr
[i
]));
3360 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
), CyCTS
);
3362 /* act on 0->1 modem transitions */
3363 cy_writeb((u_long
)base_addr
+(CyMCOR2
<<index
), CyCTS
);
3365 /* without modem intr */
3366 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
3367 cy_readb(base_addr
+(CySRER
<<index
)) | CyMdmCh
);
3368 /* act on 1->0 modem transitions */
3369 if ((cflag
& CRTSCTS
) && info
->rflow
) {
3370 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3371 (CyDSR
|CyCTS
|CyRI
|CyDCD
|rflow_thr
[i
]));
3373 cy_writeb((u_long
)base_addr
+(CyMCOR1
<<index
),
3374 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3376 /* act on 0->1 modem transitions */
3377 cy_writeb((u_long
)base_addr
+(CyMCOR2
<<index
),
3378 CyDSR
|CyCTS
|CyRI
|CyDCD
);
3381 if(i
== 0){ /* baud rate is zero, turn off line */
3382 if (info
->rtsdtr_inv
) {
3383 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3385 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3388 printk("cyc:set_line_char dropping DTR\n");
3389 printk(" status: 0x%x,
3390 0x%x\n", cy_readb(base_addr
+(CyMSVR1
<<index
)),
3391 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3394 if (info
->rtsdtr_inv
) {
3395 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3397 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3400 printk("cyc:set_line_char raising DTR\n");
3401 printk(" status: 0x%x, 0x%x\n",
3402 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3403 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3408 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3410 CY_UNLOCK(info
, flags
);
3413 struct FIRM_ID
*firm_id
;
3414 struct ZFW_CTRL
*zfw_ctrl
;
3415 struct BOARD_CTRL
*board_ctrl
;
3416 struct CH_CTRL
*ch_ctrl
;
3417 struct BUF_CTRL
*buf_ctrl
;
3421 firm_id
= (struct FIRM_ID
*)
3422 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3423 if (!ISZLOADED(cy_card
[card
])) {
3427 zfw_ctrl
= (struct ZFW_CTRL
*)
3428 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3429 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3430 ch_ctrl
= &(zfw_ctrl
->ch_ctrl
[channel
]);
3431 buf_ctrl
= &zfw_ctrl
->buf_ctrl
[channel
];
3434 if ((info
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
) {
3437 baud
= tty_get_baud_rate(info
->tty
);
3439 if (baud
> CYZ_MAX_SPEED
) {
3440 baud
= CYZ_MAX_SPEED
;
3442 cy_writel(&ch_ctrl
->comm_baud
, baud
);
3445 info
->timeout
= (info
->xmit_fifo_size
*HZ
*30/269) + 2;
3446 /* get it right for 134.5 baud */
3448 info
->timeout
= (info
->xmit_fifo_size
*HZ
*15/baud
) + 2;
3449 /* this needs to be propagated into the card info */
3454 /* byte size and parity */
3455 switch(cflag
& CSIZE
){
3456 case CS5
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS5
); break;
3457 case CS6
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS6
); break;
3458 case CS7
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS7
); break;
3459 case CS8
: cy_writel(&ch_ctrl
->comm_data_l
, C_DL_CS8
); break;
3462 cy_writel(&ch_ctrl
->comm_data_l
,
3463 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_2STOP
);
3465 cy_writel(&ch_ctrl
->comm_data_l
,
3466 cy_readl(&ch_ctrl
->comm_data_l
) | C_DL_1STOP
);
3468 if (cflag
& PARENB
){
3469 if (cflag
& PARODD
){
3470 cy_writel(&ch_ctrl
->comm_parity
, C_PR_ODD
);
3472 cy_writel(&ch_ctrl
->comm_parity
, C_PR_EVEN
);
3475 cy_writel(&ch_ctrl
->comm_parity
, C_PR_NONE
);
3478 /* CTS flow control flag */
3479 if (cflag
& CRTSCTS
){
3480 cy_writel(&ch_ctrl
->hw_flow
,
3481 cy_readl(&ch_ctrl
->hw_flow
) | C_RS_CTS
| C_RS_RTS
);
3483 cy_writel(&ch_ctrl
->hw_flow
,
3484 cy_readl(&ch_ctrl
->hw_flow
) & ~(C_RS_CTS
| C_RS_RTS
));
3486 /* As the HW flow control is done in firmware, the driver doesn't
3487 need to care about it */
3488 info
->flags
&= ~ASYNC_CTS_FLOW
;
3490 /* XON/XOFF/XANY flow control flags */
3493 sw_flow
|= C_FL_OXX
;
3495 sw_flow
|= C_FL_OIXANY
;
3497 cy_writel(&ch_ctrl
->sw_flow
, sw_flow
);
3499 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_IOCTL
, 0L);
3501 printk("cyc:set_line_char retval at %d was %x\n",
3505 /* CD sensitivity */
3506 if (cflag
& CLOCAL
){
3507 info
->flags
&= ~ASYNC_CHECK_CD
;
3509 info
->flags
|= ASYNC_CHECK_CD
;
3512 if(baud
== 0){ /* baud rate is zero, turn off line */
3513 cy_writel(&ch_ctrl
->rs_control
,
3514 cy_readl(&ch_ctrl
->rs_control
) & ~C_RS_DTR
);
3516 printk("cyc:set_line_char dropping Z DTR\n");
3519 cy_writel(&ch_ctrl
->rs_control
,
3520 cy_readl(&ch_ctrl
->rs_control
) | C_RS_DTR
);
3522 printk("cyc:set_line_char raising Z DTR\n");
3526 retval
= cyz_issue_cmd( &cy_card
[card
], channel
, C_CM_IOCTLM
, 0L);
3528 printk("cyc:set_line_char retval at %d was %x\n",
3533 clear_bit(TTY_IO_ERROR
, &info
->tty
->flags
);
3538 } /* set_line_char */
3542 get_serial_info(struct cyclades_port
* info
,
3543 struct serial_struct
* retinfo
)
3545 struct serial_struct tmp
;
3546 struct cyclades_card
*cinfo
= &cy_card
[info
->card
];
3550 memset(&tmp
, 0, sizeof(tmp
));
3551 tmp
.type
= info
->type
;
3552 tmp
.line
= info
->line
;
3553 tmp
.port
= info
->card
* 0x100 + info
->line
- cinfo
->first_line
;
3554 tmp
.irq
= cinfo
->irq
;
3555 tmp
.flags
= info
->flags
;
3556 tmp
.close_delay
= info
->close_delay
;
3557 tmp
.baud_base
= info
->baud
;
3558 tmp
.custom_divisor
= 0; /*!!!*/
3559 tmp
.hub6
= 0; /*!!!*/
3560 return copy_to_user(retinfo
,&tmp
,sizeof(*retinfo
))?-EFAULT
:0;
3561 } /* get_serial_info */
3565 set_serial_info(struct cyclades_port
* info
,
3566 struct serial_struct
* new_info
)
3568 struct serial_struct new_serial
;
3569 struct cyclades_port old_info
;
3571 if (copy_from_user(&new_serial
,new_info
,sizeof(new_serial
)))
3575 if (!capable(CAP_SYS_ADMIN
)) {
3576 if ((new_serial
.close_delay
!= info
->close_delay
) ||
3577 (new_serial
.baud_base
!= info
->baud
) ||
3578 ((new_serial
.flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
) !=
3579 (info
->flags
& ASYNC_FLAGS
& ~ASYNC_USR_MASK
)))
3581 info
->flags
= ((info
->flags
& ~ASYNC_USR_MASK
) |
3582 (new_serial
.flags
& ASYNC_USR_MASK
));
3583 info
->baud
= new_serial
.baud_base
;
3584 goto check_and_exit
;
3589 * OK, past this point, all the error checking has been done.
3590 * At this point, we start making changes.....
3593 info
->baud
= new_serial
.baud_base
;
3594 info
->flags
= ((info
->flags
& ~ASYNC_FLAGS
) |
3595 (new_serial
.flags
& ASYNC_FLAGS
));
3596 info
->close_delay
= new_serial
.close_delay
* HZ
/100;
3597 info
->closing_wait
= new_serial
.closing_wait
* HZ
/100;
3600 if (info
->flags
& ASYNC_INITIALIZED
){
3601 set_line_char(info
);
3604 return startup(info
);
3606 } /* set_serial_info */
3610 get_modem_info(struct cyclades_port
* info
, unsigned int *value
)
3612 int card
,chip
,channel
,index
;
3613 unsigned char *base_addr
;
3614 unsigned long flags
;
3615 unsigned char status
;
3616 unsigned long lstatus
;
3617 unsigned int result
;
3618 struct FIRM_ID
*firm_id
;
3619 struct ZFW_CTRL
*zfw_ctrl
;
3620 struct BOARD_CTRL
*board_ctrl
;
3621 struct CH_CTRL
*ch_ctrl
;
3624 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3625 if (!IS_CYC_Z(cy_card
[card
])) {
3628 index
= cy_card
[card
].bus_index
;
3629 base_addr
= (unsigned char*)
3630 (cy_card
[card
].base_addr
3631 + (cy_chip_offset
[chip
]<<index
));
3633 CY_LOCK(info
, flags
);
3634 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3635 status
= cy_readb(base_addr
+(CyMSVR1
<<index
));
3636 status
|= cy_readb(base_addr
+(CyMSVR2
<<index
));
3637 CY_UNLOCK(info
, flags
);
3639 if (info
->rtsdtr_inv
) {
3640 result
= ((status
& CyRTS
) ? TIOCM_DTR
: 0)
3641 | ((status
& CyDTR
) ? TIOCM_RTS
: 0);
3643 result
= ((status
& CyRTS
) ? TIOCM_RTS
: 0)
3644 | ((status
& CyDTR
) ? TIOCM_DTR
: 0);
3646 result
|= ((status
& CyDCD
) ? TIOCM_CAR
: 0)
3647 | ((status
& CyRI
) ? TIOCM_RNG
: 0)
3648 | ((status
& CyDSR
) ? TIOCM_DSR
: 0)
3649 | ((status
& CyCTS
) ? TIOCM_CTS
: 0);
3651 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
3653 if (cy_card
[card
].num_chips
!= -1){
3657 firm_id
= (struct FIRM_ID
*)
3658 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3659 if (ISZLOADED(cy_card
[card
])) {
3660 zfw_ctrl
= (struct ZFW_CTRL
*)
3661 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3662 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3663 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3664 lstatus
= cy_readl(&ch_ctrl
[channel
].rs_status
);
3665 result
= ((lstatus
& C_RS_RTS
) ? TIOCM_RTS
: 0)
3666 | ((lstatus
& C_RS_DTR
) ? TIOCM_DTR
: 0)
3667 | ((lstatus
& C_RS_DCD
) ? TIOCM_CAR
: 0)
3668 | ((lstatus
& C_RS_RI
) ? TIOCM_RNG
: 0)
3669 | ((lstatus
& C_RS_DSR
) ? TIOCM_DSR
: 0)
3670 | ((lstatus
& C_RS_CTS
) ? TIOCM_CTS
: 0);
3677 return cy_put_user(result
, value
);
3678 } /* get_modem_info */
3682 set_modem_info(struct cyclades_port
* info
, unsigned int cmd
,
3683 unsigned int *value
)
3685 int card
,chip
,channel
,index
;
3686 unsigned char *base_addr
;
3687 unsigned long flags
;
3688 unsigned int arg
= cy_get_user((unsigned long *) value
);
3689 struct FIRM_ID
*firm_id
;
3690 struct ZFW_CTRL
*zfw_ctrl
;
3691 struct BOARD_CTRL
*board_ctrl
;
3692 struct CH_CTRL
*ch_ctrl
;
3696 channel
= (info
->line
) - (cy_card
[card
].first_line
);
3697 if (!IS_CYC_Z(cy_card
[card
])) {
3700 index
= cy_card
[card
].bus_index
;
3701 base_addr
= (unsigned char*)
3702 (cy_card
[card
].base_addr
3703 + (cy_chip_offset
[chip
]<<index
));
3707 if (arg
& TIOCM_RTS
){
3708 CY_LOCK(info
, flags
);
3709 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3710 if (info
->rtsdtr_inv
) {
3711 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3713 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3715 CY_UNLOCK(info
, flags
);
3717 if (arg
& TIOCM_DTR
){
3718 CY_LOCK(info
, flags
);
3719 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3720 if (info
->rtsdtr_inv
) {
3721 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3723 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3726 printk("cyc:set_modem_info raising DTR\n");
3727 printk(" status: 0x%x, 0x%x\n",
3728 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3729 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3731 CY_UNLOCK(info
, flags
);
3735 if (arg
& TIOCM_RTS
){
3736 CY_LOCK(info
, flags
);
3737 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
3739 if (info
->rtsdtr_inv
) {
3740 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3742 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3744 CY_UNLOCK(info
, flags
);
3746 if (arg
& TIOCM_DTR
){
3747 CY_LOCK(info
, flags
);
3748 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3749 if (info
->rtsdtr_inv
) {
3750 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3752 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3755 printk("cyc:set_modem_info dropping DTR\n");
3756 printk(" status: 0x%x, 0x%x\n",
3757 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3758 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3760 CY_UNLOCK(info
, flags
);
3764 if (arg
& TIOCM_RTS
){
3765 CY_LOCK(info
, flags
);
3766 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3767 if (info
->rtsdtr_inv
) {
3768 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3770 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3772 CY_UNLOCK(info
, flags
);
3774 CY_LOCK(info
, flags
);
3775 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3776 if (info
->rtsdtr_inv
) {
3777 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3779 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3781 CY_UNLOCK(info
, flags
);
3783 if (arg
& TIOCM_DTR
){
3784 CY_LOCK(info
, flags
);
3785 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3786 if (info
->rtsdtr_inv
) {
3787 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
3789 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
3792 printk("cyc:set_modem_info raising DTR\n");
3793 printk(" status: 0x%x, 0x%x\n",
3794 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3795 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3797 CY_UNLOCK(info
, flags
);
3799 CY_LOCK(info
, flags
);
3800 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
3801 if (info
->rtsdtr_inv
) {
3802 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
3804 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
3808 printk("cyc:set_modem_info dropping DTR\n");
3809 printk(" status: 0x%x, 0x%x\n",
3810 cy_readb(base_addr
+(CyMSVR1
<<index
)),
3811 cy_readb(base_addr
+(CyMSVR2
<<index
)));
3813 CY_UNLOCK(info
, flags
);
3820 base_addr
= (unsigned char*) (cy_card
[card
].base_addr
);
3822 firm_id
= (struct FIRM_ID
*)
3823 (cy_card
[card
].base_addr
+ ID_ADDRESS
);
3824 if (ISZLOADED(cy_card
[card
])) {
3825 zfw_ctrl
= (struct ZFW_CTRL
*)
3826 (cy_card
[card
].base_addr
+ cy_readl(&firm_id
->zfwctrl_addr
));
3827 board_ctrl
= &zfw_ctrl
->board_ctrl
;
3828 ch_ctrl
= zfw_ctrl
->ch_ctrl
;
3832 if (arg
& TIOCM_RTS
){
3833 CY_LOCK(info
, flags
);
3834 cy_writel(&ch_ctrl
[channel
].rs_control
,
3835 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3836 CY_UNLOCK(info
, flags
);
3838 if (arg
& TIOCM_DTR
){
3839 CY_LOCK(info
, flags
);
3840 cy_writel(&ch_ctrl
[channel
].rs_control
,
3841 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3843 printk("cyc:set_modem_info raising Z DTR\n");
3845 CY_UNLOCK(info
, flags
);
3849 if (arg
& TIOCM_RTS
){
3850 CY_LOCK(info
, flags
);
3851 cy_writel(&ch_ctrl
[channel
].rs_control
,
3852 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3853 CY_UNLOCK(info
, flags
);
3855 if (arg
& TIOCM_DTR
){
3856 CY_LOCK(info
, flags
);
3857 cy_writel(&ch_ctrl
[channel
].rs_control
,
3858 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3860 printk("cyc:set_modem_info clearing Z DTR\n");
3862 CY_UNLOCK(info
, flags
);
3866 if (arg
& TIOCM_RTS
){
3867 CY_LOCK(info
, flags
);
3868 cy_writel(&ch_ctrl
[channel
].rs_control
,
3869 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_RTS
);
3870 CY_UNLOCK(info
, flags
);
3872 CY_LOCK(info
, flags
);
3873 cy_writel(&ch_ctrl
[channel
].rs_control
,
3874 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_RTS
);
3875 CY_UNLOCK(info
, flags
);
3877 if (arg
& TIOCM_DTR
){
3878 CY_LOCK(info
, flags
);
3879 cy_writel(&ch_ctrl
[channel
].rs_control
,
3880 cy_readl(&ch_ctrl
[channel
].rs_control
) | C_RS_DTR
);
3882 printk("cyc:set_modem_info raising Z DTR\n");
3884 CY_UNLOCK(info
, flags
);
3886 CY_LOCK(info
, flags
);
3887 cy_writel(&ch_ctrl
[channel
].rs_control
,
3888 cy_readl(&ch_ctrl
[channel
].rs_control
) & ~C_RS_DTR
);
3890 printk("cyc:set_modem_info clearing Z DTR\n");
3892 CY_UNLOCK(info
, flags
);
3901 CY_LOCK(info
, flags
);
3902 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3903 channel
, C_CM_IOCTLM
,0L);
3905 printk("cyc:set_modem_info retval at %d was %x\n",
3908 CY_UNLOCK(info
, flags
);
3911 } /* set_modem_info */
3914 * cy_break() --- routine which turns the break handling on or off
3917 cy_break(struct tty_struct
*tty
, int break_state
)
3919 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
3920 unsigned long flags
;
3922 if (serial_paranoia_check(info
, tty
->device
, "cy_break"))
3925 CY_LOCK(info
, flags
);
3926 if (!IS_CYC_Z(cy_card
[info
->card
])) {
3927 /* Let the transmit ISR take care of this (since it
3928 requires stuffing characters into the output stream).
3930 if (break_state
== -1) {
3931 if (!info
->breakon
) {
3933 if (!info
->xmit_cnt
) {
3934 CY_UNLOCK(info
, flags
);
3936 CY_LOCK(info
, flags
);
3940 if (!info
->breakoff
) {
3942 if (!info
->xmit_cnt
) {
3943 CY_UNLOCK(info
, flags
);
3945 CY_LOCK(info
, flags
);
3952 if (break_state
== -1) {
3953 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3954 (info
->line
) - (cy_card
[info
->card
].first_line
),
3955 C_CM_SET_BREAK
, 0L);
3957 printk("cyc:cy_break (set) retval at %d was %x\n",
3961 retval
= cyz_issue_cmd(&cy_card
[info
->card
],
3962 (info
->line
) - (cy_card
[info
->card
].first_line
),
3963 C_CM_CLR_BREAK
, 0L);
3965 printk("cyc:cy_break (clr) retval at %d was %x\n",
3970 CY_UNLOCK(info
, flags
);
3974 get_mon_info(struct cyclades_port
* info
, struct cyclades_monitor
* mon
)
3977 if(copy_to_user(mon
, &info
->mon
, sizeof(struct cyclades_monitor
)))
3979 info
->mon
.int_count
= 0;
3980 info
->mon
.char_count
= 0;
3981 info
->mon
.char_max
= 0;
3982 info
->mon
.char_last
= 0;
3988 set_threshold(struct cyclades_port
* info
, unsigned long value
)
3990 unsigned char *base_addr
;
3991 int card
,channel
,chip
,index
;
3992 unsigned long flags
;
3995 channel
= info
->line
- cy_card
[card
].first_line
;
3996 if (!IS_CYC_Z(cy_card
[card
])) {
3999 index
= cy_card
[card
].bus_index
;
4000 base_addr
= (unsigned char*)
4001 (cy_card
[card
].base_addr
4002 + (cy_chip_offset
[chip
]<<index
));
4004 info
->cor3
&= ~CyREC_FIFO
;
4005 info
->cor3
|= value
& CyREC_FIFO
;
4007 CY_LOCK(info
, flags
);
4008 cy_writeb((u_long
)base_addr
+(CyCOR3
<<index
), info
->cor3
);
4009 cyy_issue_cmd(base_addr
,CyCOR_CHANGE
|CyCOR3ch
,index
);
4010 CY_UNLOCK(info
, flags
);
4015 }/* set_threshold */
4019 get_threshold(struct cyclades_port
* info
, unsigned long *value
)
4021 unsigned char *base_addr
;
4022 int card
,channel
,chip
,index
;
4026 channel
= info
->line
- cy_card
[card
].first_line
;
4027 if (!IS_CYC_Z(cy_card
[card
])) {
4030 index
= cy_card
[card
].bus_index
;
4031 base_addr
= (unsigned char*)
4032 (cy_card
[card
].base_addr
4033 + (cy_chip_offset
[chip
]<<index
));
4035 tmp
= cy_readb(base_addr
+(CyCOR3
<<index
)) & CyREC_FIFO
;
4036 return cy_put_user(tmp
,value
);
4041 }/* get_threshold */
4045 set_default_threshold(struct cyclades_port
* info
, unsigned long value
)
4047 info
->default_threshold
= value
& 0x0f;
4049 }/* set_default_threshold */
4053 get_default_threshold(struct cyclades_port
* info
, unsigned long *value
)
4055 return cy_put_user(info
->default_threshold
,value
);
4056 }/* get_default_threshold */
4060 set_timeout(struct cyclades_port
* info
, unsigned long value
)
4062 unsigned char *base_addr
;
4063 int card
,channel
,chip
,index
;
4064 unsigned long flags
;
4067 channel
= info
->line
- cy_card
[card
].first_line
;
4068 if (!IS_CYC_Z(cy_card
[card
])) {
4071 index
= cy_card
[card
].bus_index
;
4072 base_addr
= (unsigned char*)
4073 (cy_card
[card
].base_addr
4074 + (cy_chip_offset
[chip
]<<index
));
4076 CY_LOCK(info
, flags
);
4077 cy_writeb((u_long
)base_addr
+(CyRTPR
<<index
), value
& 0xff);
4078 CY_UNLOCK(info
, flags
);
4087 get_timeout(struct cyclades_port
* info
, unsigned long *value
)
4089 unsigned char *base_addr
;
4090 int card
,channel
,chip
,index
;
4094 channel
= info
->line
- cy_card
[card
].first_line
;
4095 if (!IS_CYC_Z(cy_card
[card
])) {
4098 index
= cy_card
[card
].bus_index
;
4099 base_addr
= (unsigned char*)
4100 (cy_card
[card
].base_addr
4101 + (cy_chip_offset
[chip
]<<index
));
4103 tmp
= cy_readb(base_addr
+(CyRTPR
<<index
));
4104 return cy_put_user(tmp
,value
);
4113 set_default_timeout(struct cyclades_port
* info
, unsigned long value
)
4115 info
->default_timeout
= value
& 0xff;
4117 }/* set_default_timeout */
4121 get_default_timeout(struct cyclades_port
* info
, unsigned long *value
)
4123 return cy_put_user(info
->default_timeout
,value
);
4124 }/* get_default_timeout */
4127 * This routine allows the tty driver to implement device-
4128 * specific ioctl's. If the ioctl number passed in cmd is
4129 * not recognized by the driver, it should return ENOIOCTLCMD.
4132 cy_ioctl(struct tty_struct
*tty
, struct file
* file
,
4133 unsigned int cmd
, unsigned long arg
)
4135 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4136 struct cyclades_icount cprev
, cnow
; /* kernel counter temps */
4137 struct serial_icounter_struct
*p_cuser
; /* user space */
4139 unsigned long flags
;
4141 if (serial_paranoia_check(info
, tty
->device
, "cy_ioctl"))
4144 #ifdef CY_DEBUG_OTHER
4145 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
4146 info
->line
, cmd
, arg
); /* */
4151 ret_val
= get_mon_info(info
, (struct cyclades_monitor
*)arg
);
4154 ret_val
= get_threshold(info
, (unsigned long *)arg
);
4157 ret_val
= set_threshold(info
, (unsigned long)arg
);
4159 case CYGETDEFTHRESH
:
4160 ret_val
= get_default_threshold(info
, (unsigned long *)arg
);
4162 case CYSETDEFTHRESH
:
4163 ret_val
= set_default_threshold(info
, (unsigned long)arg
);
4166 ret_val
= get_timeout(info
, (unsigned long *)arg
);
4169 ret_val
= set_timeout(info
, (unsigned long)arg
);
4171 case CYGETDEFTIMEOUT
:
4172 ret_val
= get_default_timeout(info
, (unsigned long *)arg
);
4174 case CYSETDEFTIMEOUT
:
4175 ret_val
= set_default_timeout(info
, (unsigned long)arg
);
4178 info
->rflow
= (int)arg
;
4182 ret_val
= info
->rflow
;
4184 case CYSETRTSDTR_INV
:
4185 info
->rtsdtr_inv
= (int)arg
;
4188 case CYGETRTSDTR_INV
:
4189 ret_val
= info
->rtsdtr_inv
;
4192 if (copy_to_user((void *)arg
, (void *)&cy_card
[info
->card
],
4193 sizeof (struct cyclades_card
))) {
4199 case CYGETCD1400VER
:
4200 ret_val
= info
->chip_rev
;
4202 #ifndef CONFIG_CYZ_INTR
4203 case CYZSETPOLLCYCLE
:
4204 cyz_polling_cycle
= (arg
* HZ
) / 1000;
4207 case CYZGETPOLLCYCLE
:
4208 ret_val
= (cyz_polling_cycle
* 1000) / HZ
;
4210 #endif /* CONFIG_CYZ_INTR */
4212 info
->closing_wait
= (unsigned short)arg
* HZ
/100;
4216 ret_val
= info
->closing_wait
/ (HZ
/100);
4219 ret_val
= get_modem_info(info
, (unsigned int *) arg
);
4224 ret_val
= set_modem_info(info
, cmd
, (unsigned int *) arg
);
4227 ret_val
= get_serial_info(info
, (struct serial_struct
*) arg
);
4230 ret_val
= set_serial_info(info
, (struct serial_struct
*) arg
);
4233 * Wait for any of the 4 modem inputs (DCD,RI,DSR,CTS) to change
4234 * - mask passed in arg for lines of interest
4235 * (use |'ed TIOCM_RNG/DSR/CD/CTS for masking)
4236 * Caller should use TIOCGICOUNT to see which one it was
4239 CY_LOCK(info
, flags
);
4240 /* note the counters on entry */
4241 cprev
= info
->icount
;
4242 CY_UNLOCK(info
, flags
);
4244 interruptible_sleep_on(&info
->delta_msr_wait
);
4245 /* see if a signal did it */
4246 if (signal_pending(current
)) {
4247 return -ERESTARTSYS
;
4250 CY_LOCK(info
, flags
);
4251 cnow
= info
->icount
; /* atomic copy */
4252 CY_UNLOCK(info
, flags
);
4254 if (cnow
.rng
== cprev
.rng
&& cnow
.dsr
== cprev
.dsr
&&
4255 cnow
.dcd
== cprev
.dcd
&& cnow
.cts
== cprev
.cts
) {
4256 return -EIO
; /* no change => error */
4258 if ( ((arg
& TIOCM_RNG
) && (cnow
.rng
!= cprev
.rng
)) ||
4259 ((arg
& TIOCM_DSR
) && (cnow
.dsr
!= cprev
.dsr
)) ||
4260 ((arg
& TIOCM_CD
) && (cnow
.dcd
!= cprev
.dcd
)) ||
4261 ((arg
& TIOCM_CTS
) && (cnow
.cts
!= cprev
.cts
)) ) {
4269 * Get counter of input serial line interrupts (DCD,RI,DSR,CTS)
4270 * Return: write counters to the user passed counter struct
4271 * NB: both 1->0 and 0->1 transitions are counted except for
4272 * RI where only 0->1 is counted.
4275 CY_LOCK(info
, flags
);
4276 cnow
= info
->icount
;
4277 CY_UNLOCK(info
, flags
);
4278 p_cuser
= (struct serial_icounter_struct
*) arg
;
4279 ret_val
= put_user(cnow
.cts
, &p_cuser
->cts
);
4280 if (ret_val
) return ret_val
;
4281 ret_val
= put_user(cnow
.dsr
, &p_cuser
->dsr
);
4282 if (ret_val
) return ret_val
;
4283 ret_val
= put_user(cnow
.rng
, &p_cuser
->rng
);
4284 if (ret_val
) return ret_val
;
4285 ret_val
= put_user(cnow
.dcd
, &p_cuser
->dcd
);
4286 if (ret_val
) return ret_val
;
4287 ret_val
= put_user(cnow
.rx
, &p_cuser
->rx
);
4288 if (ret_val
) return ret_val
;
4289 ret_val
= put_user(cnow
.tx
, &p_cuser
->tx
);
4290 if (ret_val
) return ret_val
;
4291 ret_val
= put_user(cnow
.frame
, &p_cuser
->frame
);
4292 if (ret_val
) return ret_val
;
4293 ret_val
= put_user(cnow
.overrun
, &p_cuser
->overrun
);
4294 if (ret_val
) return ret_val
;
4295 ret_val
= put_user(cnow
.parity
, &p_cuser
->parity
);
4296 if (ret_val
) return ret_val
;
4297 ret_val
= put_user(cnow
.brk
, &p_cuser
->brk
);
4298 if (ret_val
) return ret_val
;
4299 ret_val
= put_user(cnow
.buf_overrun
, &p_cuser
->buf_overrun
);
4300 if (ret_val
) return ret_val
;
4304 ret_val
= -ENOIOCTLCMD
;
4307 #ifdef CY_DEBUG_OTHER
4308 printk(" cyc:cy_ioctl done\n");
4316 * This routine allows the tty driver to be notified when
4317 * device's termios settings have changed. Note that a
4318 * well-designed tty driver should be prepared to accept the case
4319 * where old == NULL, and try to do something rational.
4322 cy_set_termios(struct tty_struct
*tty
, struct termios
* old_termios
)
4324 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4326 #ifdef CY_DEBUG_OTHER
4327 printk("cyc:cy_set_termios ttyC%d\n", info
->line
);
4330 if ((tty
->termios
->c_cflag
== old_termios
->c_cflag
) &&
4331 ((tty
->termios
->c_iflag
& (IXON
|IXANY
)) ==
4332 (old_termios
->c_iflag
& (IXON
|IXANY
))))
4334 set_line_char(info
);
4336 if ((old_termios
->c_cflag
& CRTSCTS
) &&
4337 !(tty
->termios
->c_cflag
& CRTSCTS
)) {
4343 * No need to wake up processes in open wait, since they
4344 * sample the CLOCAL flag once, and don't recheck it.
4345 * XXX It's not clear whether the current behavior is correct
4346 * or not. Hence, this may change.....
4348 if (!(old_termios
->c_cflag
& CLOCAL
) &&
4349 (tty
->termios
->c_cflag
& CLOCAL
))
4350 wake_up_interruptible(&info
->open_wait
);
4354 } /* cy_set_termios */
4356 /* This routine is called by the upper-layer tty layer to signal
4357 that incoming characters should be throttled because the input
4358 buffers are close to full.
4361 cy_throttle(struct tty_struct
* tty
)
4363 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4364 unsigned long flags
;
4365 unsigned char *base_addr
;
4366 int card
,chip
,channel
,index
;
4368 #ifdef CY_DEBUG_THROTTLE
4371 printk("cyc:throttle %s: %d....ttyC%d\n",
4373 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4376 if (serial_paranoia_check(info
, tty
->device
, "cy_throttle")){
4381 info
->x_char
= STOP_CHAR(tty
);
4382 /* Should use the "Send Special Character" feature!!! */
4386 channel
= info
->line
- cy_card
[card
].first_line
;
4387 if (!IS_CYC_Z(cy_card
[card
])) {
4390 index
= cy_card
[card
].bus_index
;
4391 base_addr
= (unsigned char*)
4392 (cy_card
[card
].base_addr
4393 + (cy_chip_offset
[chip
]<<index
));
4395 CY_LOCK(info
, flags
);
4396 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4397 if (info
->rtsdtr_inv
) {
4398 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), ~CyDTR
);
4400 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), ~CyRTS
);
4402 CY_UNLOCK(info
, flags
);
4412 * This routine notifies the tty driver that it should signal
4413 * that characters can now be sent to the tty without fear of
4414 * overrunning the input buffers of the line disciplines.
4417 cy_unthrottle(struct tty_struct
* tty
)
4419 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4420 unsigned long flags
;
4421 unsigned char *base_addr
;
4422 int card
,chip
,channel
,index
;
4424 #ifdef CY_DEBUG_THROTTLE
4427 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4429 tty
->ldisc
.chars_in_buffer(tty
), info
->line
);
4432 if (serial_paranoia_check(info
, tty
->device
, "cy_unthrottle")){
4440 info
->x_char
= START_CHAR(tty
);
4441 /* Should use the "Send Special Character" feature!!! */
4445 channel
= info
->line
- cy_card
[card
].first_line
;
4446 if (!IS_CYC_Z(cy_card
[card
])) {
4449 index
= cy_card
[card
].bus_index
;
4450 base_addr
= (unsigned char*)
4451 (cy_card
[card
].base_addr
4452 + (cy_chip_offset
[chip
]<<index
));
4454 CY_LOCK(info
, flags
);
4455 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
), (u_char
)channel
);
4456 if (info
->rtsdtr_inv
) {
4457 cy_writeb((u_long
)base_addr
+(CyMSVR2
<<index
), CyDTR
);
4459 cy_writeb((u_long
)base_addr
+(CyMSVR1
<<index
), CyRTS
);
4461 CY_UNLOCK(info
, flags
);
4467 } /* cy_unthrottle */
4470 /* cy_start and cy_stop provide software output flow control as a
4471 function of XON/XOFF, software CTS, and other such stuff.
4474 cy_stop(struct tty_struct
*tty
)
4476 struct cyclades_card
*cinfo
;
4477 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4478 unsigned char *base_addr
;
4479 int chip
,channel
,index
;
4480 unsigned long flags
;
4482 #ifdef CY_DEBUG_OTHER
4483 printk("cyc:cy_stop ttyC%d\n", info
->line
); /* */
4486 if (serial_paranoia_check(info
, tty
->device
, "cy_stop"))
4489 cinfo
= &cy_card
[info
->card
];
4490 channel
= info
->line
- cinfo
->first_line
;
4491 if (!IS_CYC_Z(*cinfo
)) {
4492 index
= cinfo
->bus_index
;
4495 base_addr
= (unsigned char*)
4496 (cy_card
[info
->card
].base_addr
4497 + (cy_chip_offset
[chip
]<<index
));
4499 CY_LOCK(info
, flags
);
4500 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
4501 (u_char
)(channel
& 0x0003)); /* index channel */
4502 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
4503 cy_readb(base_addr
+(CySRER
<<index
)) & ~CyTxMpty
);
4504 CY_UNLOCK(info
, flags
);
4514 cy_start(struct tty_struct
*tty
)
4516 struct cyclades_card
*cinfo
;
4517 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4518 unsigned char *base_addr
;
4519 int chip
,channel
,index
;
4520 unsigned long flags
;
4522 #ifdef CY_DEBUG_OTHER
4523 printk("cyc:cy_start ttyC%d\n", info
->line
); /* */
4526 if (serial_paranoia_check(info
, tty
->device
, "cy_start"))
4529 cinfo
= &cy_card
[info
->card
];
4530 channel
= info
->line
- cinfo
->first_line
;
4531 index
= cinfo
->bus_index
;
4532 if (!IS_CYC_Z(*cinfo
)) {
4535 base_addr
= (unsigned char*)
4536 (cy_card
[info
->card
].base_addr
4537 + (cy_chip_offset
[chip
]<<index
));
4539 CY_LOCK(info
, flags
);
4540 cy_writeb((u_long
)base_addr
+(CyCAR
<<index
),
4541 (u_char
)(channel
& 0x0003)); /* index channel */
4542 cy_writeb((u_long
)base_addr
+(CySRER
<<index
),
4543 cy_readb(base_addr
+(CySRER
<<index
)) | CyTxMpty
);
4544 CY_UNLOCK(info
, flags
);
4554 cy_flush_buffer(struct tty_struct
*tty
)
4556 struct cyclades_port
*info
= (struct cyclades_port
*)tty
->driver_data
;
4557 int card
, channel
, retval
;
4558 unsigned long flags
;
4561 printk("cyc:cy_flush_buffer ttyC%d\n", info
->line
); /* */
4564 if (serial_paranoia_check(info
, tty
->device
, "cy_flush_buffer"))
4568 channel
= (info
->line
) - (cy_card
[card
].first_line
);
4570 CY_LOCK(info
, flags
);
4571 info
->xmit_cnt
= info
->xmit_head
= info
->xmit_tail
= 0;
4572 CY_UNLOCK(info
, flags
);
4574 if (IS_CYC_Z(cy_card
[card
])) { /* If it is a Z card, flush the on-board
4576 CY_LOCK(info
, flags
);
4577 retval
= cyz_issue_cmd(&cy_card
[card
], channel
, C_CM_FLUSH_TX
, 0L);
4579 printk("cyc: flush_buffer retval was %x\n", retval
);
4581 CY_UNLOCK(info
, flags
);
4583 wake_up_interruptible(&tty
->write_wait
);
4584 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
))
4585 && tty
->ldisc
.write_wakeup
)
4586 (tty
->ldisc
.write_wakeup
)(tty
);
4587 } /* cy_flush_buffer */
4591 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4594 cy_hangup(struct tty_struct
*tty
)
4596 struct cyclades_port
* info
= (struct cyclades_port
*)tty
->driver_data
;
4598 #ifdef CY_DEBUG_OTHER
4599 printk("cyc:cy_hangup ttyC%d\n", info
->line
); /* */
4602 if (serial_paranoia_check(info
, tty
->device
, "cy_hangup"))
4605 cy_flush_buffer(tty
);
4609 #ifdef CY_DEBUG_COUNT
4610 printk("cyc:cy_hangup (%d): setting count to 0\n", current
->pid
);
4613 info
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CALLOUT_ACTIVE
);
4614 wake_up_interruptible(&info
->open_wait
);
4619 * ---------------------------------------------------------------------
4620 * cy_init() and friends
4622 * cy_init() is called at boot-time to initialize the serial driver.
4623 * ---------------------------------------------------------------------
4626 /* initialize chips on Cyclom-Y card -- return number of valid
4627 chips (which is number of ports/4) */
4628 static unsigned short __init
4629 cyy_init_card(volatile ucchar
*true_base_addr
,int index
)
4631 unsigned int chip_number
;
4632 volatile ucchar
* base_addr
;
4634 cy_writeb((u_long
)true_base_addr
+(Cy_HwReset
<<index
), 0);
4635 /* Cy_HwReset is 0x1400 */
4636 cy_writeb((u_long
)true_base_addr
+(Cy_ClrIntr
<<index
), 0);
4637 /* Cy_ClrIntr is 0x1800 */
4640 for(chip_number
=0; chip_number
<CyMAX_CHIPS_PER_CARD
; chip_number
++){
4641 base_addr
= true_base_addr
4642 + (cy_chip_offset
[chip_number
]<<index
);
4644 if(cy_readb(base_addr
+(CyCCR
<<index
)) != 0x00){
4646 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4647 chip_number, (unsigned long)base_addr);
4652 cy_writeb((u_long
)base_addr
+(CyGFRCR
<<index
), 0);
4655 /* The Cyclom-16Y does not decode address bit 9 and therefore
4656 cannot distinguish between references to chip 0 and a non-
4657 existent chip 4. If the preceding clearing of the supposed
4658 chip 4 GFRCR register appears at chip 0, there is no chip 4
4659 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4661 if (chip_number
== 4
4662 && cy_readb(true_base_addr
4663 + (cy_chip_offset
[0]<<index
)
4664 + (CyGFRCR
<<index
)) == 0){
4668 cy_writeb((u_long
)base_addr
+(CyCCR
<<index
), CyCHIP_RESET
);
4671 if(cy_readb(base_addr
+(CyGFRCR
<<index
)) == 0x00){
4673 printk(" chip #%d at %#6lx is not responding ",
4674 chip_number, (unsigned long)base_addr);
4675 printk("(GFRCR stayed 0)\n",
4679 if((0xf0 & (cy_readb(base_addr
+(CyGFRCR
<<index
)))) != 0x40){
4681 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4682 chip_number, (unsigned long)base_addr,
4683 base_addr[CyGFRCR<<index]);
4687 cy_writeb((u_long
)base_addr
+(CyGCR
<<index
), CyCH0_SERIAL
);
4688 if (cy_readb(base_addr
+(CyGFRCR
<<index
)) >= CD1400_REV_J
){
4689 /* It is a CD1400 rev. J or later */
4690 /* Impossible to reach 5ms with this chip.
4691 Changed to 2ms instead (f = 500 Hz). */
4692 cy_writeb((u_long
)base_addr
+(CyPPR
<<index
), CyCLOCK_60_2MS
);
4695 cy_writeb((u_long
)base_addr
+(CyPPR
<<index
), CyCLOCK_25_5MS
);
4699 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4700 chip_number, (unsigned long)base_addr,
4701 cy_readb(base_addr+(CyGFRCR<<index)));
4705 } /* cyy_init_card */
4707 #ifndef CONFIG_COBALT_27
4709 * ---------------------------------------------------------------------
4710 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4711 * sets global variables and return the number of ISA boards found.
4712 * ---------------------------------------------------------------------
4717 unsigned short cy_isa_irq
,nboard
;
4718 volatile ucchar
*cy_isa_address
;
4719 unsigned short i
,j
,cy_isa_nchan
;
4727 /* Check for module parameters */
4728 for(i
= 0 ; i
< NR_CARDS
; i
++) {
4729 if (maddr
[i
] || i
) {
4731 cy_isa_addresses
[i
] = (ucchar
*)maddr
[i
];
4738 /* scan the address table probing for Cyclom-Y/ISA boards */
4739 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
4740 cy_isa_address
= cy_isa_addresses
[i
];
4741 if (cy_isa_address
== 0x0000) {
4745 /* probe for CD1400... */
4747 #if !defined(__alpha__)
4748 cy_isa_address
= ioremap((ulong
)cy_isa_address
, CyISA_Ywin
);
4750 cy_isa_nchan
= CyPORTS_PER_CHIP
*
4751 cyy_init_card(cy_isa_address
,0);
4752 if (cy_isa_nchan
== 0) {
4757 if (isparam
&& irq
[i
])
4758 cy_isa_irq
= irq
[i
];
4761 /* find out the board's irq by probing */
4762 cy_isa_irq
= detect_isa_irq(cy_isa_address
);
4763 if (cy_isa_irq
== 0) {
4764 printk("Cyclom-Y/ISA found at 0x%lx ",
4765 (unsigned long) cy_isa_address
);
4766 printk("but the IRQ could not be detected.\n");
4770 if((cy_next_channel
+cy_isa_nchan
) > NR_PORTS
) {
4771 printk("Cyclom-Y/ISA found at 0x%lx ",
4772 (unsigned long) cy_isa_address
);
4773 printk("but no more channels are available.\n");
4774 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4777 /* fill the next cy_card structure available */
4778 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4779 if (cy_card
[j
].base_addr
== 0) break;
4781 if (j
== NR_CARDS
) { /* no more cy_cards available */
4782 printk("Cyclom-Y/ISA found at 0x%lx ",
4783 (unsigned long) cy_isa_address
);
4784 printk("but no more cards can be used .\n");
4785 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4790 if(request_irq(cy_isa_irq
, cyy_interrupt
,
4791 SA_INTERRUPT
, "Cyclom-Y", &cy_card
[j
]))
4793 printk("Cyclom-Y/ISA found at 0x%lx ",
4794 (unsigned long) cy_isa_address
);
4795 printk("but could not allocate IRQ#%d.\n",
4801 cy_card
[j
].base_addr
= (u_long
) cy_isa_address
;
4802 cy_card
[j
].ctl_addr
= 0;
4803 cy_card
[j
].irq
= (int) cy_isa_irq
;
4804 cy_card
[j
].bus_index
= 0;
4805 cy_card
[j
].first_line
= cy_next_channel
;
4806 cy_card
[j
].num_chips
= cy_isa_nchan
/4;
4810 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4811 j
+1, (unsigned long) cy_isa_address
,
4812 (unsigned long)(cy_isa_address
+ (CyISA_Ywin
- 1)),
4814 printk("%d channels starting from port %d.\n",
4815 cy_isa_nchan
, cy_next_channel
);
4816 cy_next_channel
+= cy_isa_nchan
;
4820 } /* cy_detect_isa */
4821 #endif /* CONFIG_COBALT_27 */
4824 plx_init(uclong addr
, uclong initctl
)
4827 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x40000000);
4829 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x40000000);
4831 /* Reload Config. Registers from EEPROM */
4832 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) | 0x20000000);
4834 cy_writel(addr
+ initctl
, cy_readl(addr
+ initctl
) & ~0x20000000);
4838 * ---------------------------------------------------------------------
4839 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4840 * sets global variables and return the number of PCI boards found.
4841 * ---------------------------------------------------------------------
4848 struct pci_dev
*pdev
= NULL
;
4849 unsigned char cyy_rev_id
;
4850 unsigned char cy_pci_irq
= 0;
4851 uclong cy_pci_addr0
, cy_pci_addr1
, cy_pci_addr2
;
4852 unsigned short i
,j
,cy_pci_nchan
, plx_ver
;
4853 unsigned short device_id
,dev_index
= 0;
4855 uclong Ze_addr0
[NR_CARDS
], Ze_addr2
[NR_CARDS
], ZeIndex
= 0;
4856 unsigned char Ze_irq
[NR_CARDS
];
4858 if(pci_present() == 0) { /* PCI bus not present */
4861 for (i
= 0; i
< NR_CARDS
; i
++) {
4862 /* look for a Cyclades card by vendor and device id */
4863 while((device_id
= cy_pci_dev_id
[dev_index
]) != 0) {
4864 if((pdev
= pci_find_device(PCI_VENDOR_ID_CYCLADES
,
4865 device_id
, pdev
)) == NULL
) {
4866 dev_index
++; /* try next device id */
4868 break; /* found a board */
4875 /* read PCI configuration area */
4876 cy_pci_irq
= pdev
->irq
;
4877 cy_pci_addr0
= pdev
->resource
[0].start
;
4878 cy_pci_addr1
= pdev
->resource
[1].start
;
4879 cy_pci_addr2
= pdev
->resource
[2].start
;
4880 pci_read_config_byte(pdev
, PCI_REVISION_ID
, &cyy_rev_id
);
4882 device_id
&= ~PCI_DEVICE_ID_MASK
;
4884 if ((device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
)
4885 || (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Hi
)){
4887 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4888 pdev
->bus
->number
, pdev
->devfn
);
4889 printk("rev_id=%d) IRQ%d\n",
4890 cyy_rev_id
, (int)cy_pci_irq
);
4891 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4892 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4895 if (pdev
->resource
[2].flags
& ~PCI_BASE_ADDRESS_IO_MASK
) {
4896 printk(" Warning: PCI I/O bit incorrectly set. "
4897 "Ignoring it...\n");
4898 pdev
->resource
[2].flags
&= PCI_BASE_ADDRESS_IO_MASK
;
4901 #if defined(__alpha__)
4902 if (device_id
== PCI_DEVICE_ID_CYCLOM_Y_Lo
) { /* below 1M? */
4903 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4904 pdev
->bus
->number
, pdev
->devfn
);
4905 printk("rev_id=%d) IRQ%d\n",
4906 cyy_rev_id
, (int)cy_pci_irq
);
4907 printk("Cyclom-Y/PCI:found winaddr=0x%lx ctladdr=0x%lx\n",
4908 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
4909 printk("Cyclom-Y/PCI not supported for low addresses in "
4910 "Alpha systems.\n");
4915 cy_pci_addr0
= (ulong
)ioremap(cy_pci_addr0
, CyPCI_Yctl
);
4916 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Ywin
);
4920 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4921 (u_long
)cy_pci_addr2
, (u_long
)cy_pci_addr0
);
4923 cy_pci_nchan
= (unsigned short)(CyPORTS_PER_CHIP
*
4924 cyy_init_card((volatile ucchar
*)cy_pci_addr2
, 1));
4925 if(cy_pci_nchan
== 0) {
4926 printk("Cyclom-Y PCI host card with ");
4927 printk("no Serial-Modules at 0x%lx.\n",
4928 (ulong
) cy_pci_addr2
);
4932 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
4933 printk("Cyclom-Y/PCI found at 0x%lx ",
4934 (ulong
) cy_pci_addr2
);
4935 printk("but no channels are available.\n");
4936 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4939 /* fill the next cy_card structure available */
4940 for (j
= 0 ; j
< NR_CARDS
; j
++) {
4941 if (cy_card
[j
].base_addr
== 0) break;
4943 if (j
== NR_CARDS
) { /* no more cy_cards available */
4944 printk("Cyclom-Y/PCI found at 0x%lx ",
4945 (ulong
) cy_pci_addr2
);
4946 printk("but no more cards can be used.\n");
4947 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4952 if(request_irq(cy_pci_irq
, cyy_interrupt
,
4953 SA_SHIRQ
, "Cyclom-Y", &cy_card
[j
]))
4955 printk("Cyclom-Y/PCI found at 0x%lx ",
4956 (ulong
) cy_pci_addr2
);
4957 printk("but could not allocate IRQ%d.\n",
4963 cy_card
[j
].base_addr
= (ulong
)cy_pci_addr2
;
4964 cy_card
[j
].ctl_addr
= (ulong
)cy_pci_addr0
;
4965 cy_card
[j
].irq
= (int) cy_pci_irq
;
4966 cy_card
[j
].bus_index
= 1;
4967 cy_card
[j
].first_line
= cy_next_channel
;
4968 cy_card
[j
].num_chips
= cy_pci_nchan
/4;
4970 /* enable interrupts in the PCI interface */
4971 plx_ver
= cy_readb(cy_pci_addr2
+ CyPLX_VER
) & 0x0f;
4975 plx_init(cy_pci_addr0
, 0x50);
4977 cy_writew(cy_pci_addr0
+0x4c,
4978 cy_readw(cy_pci_addr0
+0x4c)|0x0040);
4983 default: /* Old boards, use PLX_9060 */
4985 plx_init(cy_pci_addr0
, 0x6c);
4986 /* For some yet unknown reason, once the PLX9060 reloads
4987 the EEPROM, the IRQ is lost and, thus, we have to
4988 re-write it to the PCI config. registers.
4989 This will remain here until we find a permanent fix. */
4990 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
4992 cy_writew(cy_pci_addr0
+0x68,
4993 cy_readw(cy_pci_addr0
+0x68)|0x0900);
4998 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5000 (ulong
)cy_pci_addr2
,
5001 (ulong
)(cy_pci_addr2
+ CyPCI_Ywin
- 1),
5003 printk("%d channels starting from port %d.\n",
5004 cy_pci_nchan
, cy_next_channel
);
5006 cy_next_channel
+= cy_pci_nchan
;
5007 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Lo
){
5009 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
5010 pdev
->bus
->number
, pdev
->devfn
);
5011 printk("rev_id=%d) IRQ%d\n",
5012 cyy_rev_id
, (int)cy_pci_irq
);
5013 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
5014 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5015 printk("Cyclades-Z/PCI not supported for low addresses\n");
5017 }else if (device_id
== PCI_DEVICE_ID_CYCLOM_Z_Hi
){
5019 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
5020 pdev
->bus
->number
, pdev
->devfn
);
5021 printk("rev_id=%d) IRQ%d\n",
5022 cyy_rev_id
, (int)cy_pci_irq
);
5023 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
5024 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5026 #if !defined(__alpha__)
5027 cy_pci_addr0
= (ulong
)ioremap(cy_pci_addr0
, CyPCI_Zctl
);
5030 /* Disable interrupts on the PLX before resetting it */
5031 cy_writew(cy_pci_addr0
+0x68,
5032 cy_readw(cy_pci_addr0
+0x68) & ~0x0900);
5034 plx_init(cy_pci_addr0
, 0x6c);
5035 /* For some yet unknown reason, once the PLX9060 reloads
5036 the EEPROM, the IRQ is lost and, thus, we have to
5037 re-write it to the PCI config. registers.
5038 This will remain here until we find a permanent fix. */
5039 pci_write_config_byte(pdev
, PCI_INTERRUPT_LINE
, cy_pci_irq
);
5041 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060
*)
5042 cy_pci_addr0
)->mail_box_0
);
5044 if (pdev
->resource
[2].flags
& ~PCI_BASE_ADDRESS_IO_MASK
) {
5045 printk(" Warning: PCI I/O bit incorrectly set. "
5046 "Ignoring it...\n");
5047 pdev
->resource
[2].flags
&= PCI_BASE_ADDRESS_IO_MASK
;
5049 if (mailbox
== ZE_V1
) {
5050 #if !defined(__alpha__)
5051 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Ze_win
);
5053 if (ZeIndex
== NR_CARDS
) {
5054 printk("Cyclades-Ze/PCI found at 0x%lx ",
5055 (ulong
)cy_pci_addr2
);
5056 printk("but no more cards can be used.\n");
5057 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5059 Ze_addr0
[ZeIndex
] = cy_pci_addr0
;
5060 Ze_addr2
[ZeIndex
] = cy_pci_addr2
;
5061 Ze_irq
[ZeIndex
] = cy_pci_irq
;
5067 #if !defined(__alpha__)
5068 cy_pci_addr2
= (ulong
)ioremap(cy_pci_addr2
, CyPCI_Zwin
);
5073 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5074 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5075 if (mailbox
== ZO_V1
) {
5076 cy_writel(&((struct RUNTIME_9060
*)
5077 (cy_pci_addr0
))->loc_addr_base
, WIN_CREG
);
5079 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
5080 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5081 (cy_pci_addr2
))->fpga_id
)),
5082 (ulong
)(0xff & cy_readl(&((struct CUSTOM_REG
*)
5083 (cy_pci_addr2
))->fpga_version
)));
5084 cy_writel(&((struct RUNTIME_9060
*)
5085 (cy_pci_addr0
))->loc_addr_base
, WIN_RAM
);
5087 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5090 /* The following clears the firmware id word. This ensures
5091 that the driver will not attempt to talk to the board
5092 until it has been properly initialized.
5095 if ((mailbox
== ZO_V1
) || (mailbox
== ZO_V2
))
5096 cy_writel((ulong
)(cy_pci_addr2
+ID_ADDRESS
), 0L);
5098 /* This must be a Cyclades-8Zo/PCI. The extendable
5099 version will have a different device_id and will
5100 be allocated its maximum number of ports. */
5103 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5104 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5105 (ulong
)cy_pci_addr2
);
5106 printk("but no channels are available.\n");
5107 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5111 /* fill the next cy_card structure available */
5112 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5113 if (cy_card
[j
].base_addr
== 0) break;
5115 if (j
== NR_CARDS
) { /* no more cy_cards available */
5116 printk("Cyclades-8Zo/PCI found at 0x%lx ",
5117 (ulong
)cy_pci_addr2
);
5118 printk("but no more cards can be used.\n");
5119 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5123 #ifdef CONFIG_CYZ_INTR
5124 /* allocate IRQ only if board has an IRQ */
5125 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5126 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5127 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5129 printk("Could not allocate IRQ%d ",
5131 printk("for Cyclades-8Zo/PCI at 0x%lx.\n",
5132 (ulong
)cy_pci_addr2
);
5136 #endif /* CONFIG_CYZ_INTR */
5140 cy_card
[j
].base_addr
= cy_pci_addr2
;
5141 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5142 cy_card
[j
].irq
= (int) cy_pci_irq
;
5143 cy_card
[j
].bus_index
= 1;
5144 cy_card
[j
].first_line
= cy_next_channel
;
5145 cy_card
[j
].num_chips
= -1;
5148 #ifdef CONFIG_CYZ_INTR
5149 /* don't report IRQ if board is no IRQ */
5150 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5151 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5152 j
+1,(ulong
)cy_pci_addr2
,
5153 (ulong
)(cy_pci_addr2
+ CyPCI_Zwin
- 1),
5156 #endif /* CONFIG_CYZ_INTR */
5157 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
5158 j
+1,(ulong
)cy_pci_addr2
,
5159 (ulong
)(cy_pci_addr2
+ CyPCI_Zwin
- 1));
5161 printk("%d channels starting from port %d.\n",
5162 cy_pci_nchan
,cy_next_channel
);
5163 cy_next_channel
+= cy_pci_nchan
;
5167 for (; ZeIndex
!= 0 && i
< NR_CARDS
; i
++) {
5168 cy_pci_addr0
= Ze_addr0
[0];
5169 cy_pci_addr2
= Ze_addr2
[0];
5170 cy_pci_irq
= Ze_irq
[0];
5171 for (j
= 0 ; j
< ZeIndex
-1 ; j
++) {
5172 Ze_addr0
[j
] = Ze_addr0
[j
+1];
5173 Ze_addr2
[j
] = Ze_addr2
[j
+1];
5174 Ze_irq
[j
] = Ze_irq
[j
+1];
5177 mailbox
= (uclong
)cy_readl(&((struct RUNTIME_9060
*)
5178 cy_pci_addr0
)->mail_box_0
);
5180 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
5181 (ulong
)cy_pci_addr2
, (ulong
)cy_pci_addr0
);
5182 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
5185 /* This must be the new Cyclades-Ze/PCI. */
5186 cy_pci_nchan
= ZE_V1_NPORTS
;
5188 if((cy_next_channel
+cy_pci_nchan
) > NR_PORTS
) {
5189 printk("Cyclades-Ze/PCI found at 0x%lx ",
5190 (ulong
)cy_pci_addr2
);
5191 printk("but no channels are available.\n");
5192 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
5196 /* fill the next cy_card structure available */
5197 for (j
= 0 ; j
< NR_CARDS
; j
++) {
5198 if (cy_card
[j
].base_addr
== 0) break;
5200 if (j
== NR_CARDS
) { /* no more cy_cards available */
5201 printk("Cyclades-Ze/PCI found at 0x%lx ",
5202 (ulong
)cy_pci_addr2
);
5203 printk("but no more cards can be used.\n");
5204 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5208 #ifdef CONFIG_CYZ_INTR
5209 /* allocate IRQ only if board has an IRQ */
5210 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) ) {
5211 if(request_irq(cy_pci_irq
, cyz_interrupt
,
5212 SA_SHIRQ
, "Cyclades-Z", &cy_card
[j
]))
5214 printk("Could not allocate IRQ%d ",
5216 printk("for Cyclades-Ze/PCI at 0x%lx.\n",
5217 (ulong
) cy_pci_addr2
);
5221 #endif /* CONFIG_CYZ_INTR */
5224 cy_card
[j
].base_addr
= cy_pci_addr2
;
5225 cy_card
[j
].ctl_addr
= cy_pci_addr0
;
5226 cy_card
[j
].irq
= (int) cy_pci_irq
;
5227 cy_card
[j
].bus_index
= 1;
5228 cy_card
[j
].first_line
= cy_next_channel
;
5229 cy_card
[j
].num_chips
= -1;
5232 #ifdef CONFIG_CYZ_INTR
5233 /* don't report IRQ if board is no IRQ */
5234 if( (cy_pci_irq
!= 0) && (cy_pci_irq
!= 255) )
5235 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
5236 j
+1,(ulong
)cy_pci_addr2
,
5237 (ulong
)(cy_pci_addr2
+ CyPCI_Ze_win
- 1),
5240 #endif /* CONFIG_CYZ_INTR */
5241 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
5242 j
+1,(ulong
)cy_pci_addr2
,
5243 (ulong
)(cy_pci_addr2
+ CyPCI_Ze_win
- 1));
5245 printk("%d channels starting from port %d.\n",
5246 cy_pci_nchan
,cy_next_channel
);
5247 cy_next_channel
+= cy_pci_nchan
;
5250 printk("Cyclades-Ze/PCI found at 0x%x ",
5251 (unsigned int) Ze_addr2
[0]);
5252 printk("but no more cards can be used.\n");
5253 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
5258 #endif /* ifdef CONFIG_PCI */
5259 } /* cy_detect_pci */
5263 * This routine prints out the appropriate serial driver version number
5264 * and identifies which options were configured into this driver.
5269 char *rcsvers
, *rcsdate
, *tmp
;
5270 rcsvers
= strchr(rcsid
, ' '); rcsvers
++;
5271 tmp
= strchr(rcsvers
, ' '); *tmp
++ = '\0';
5272 rcsdate
= strchr(tmp
, ' '); rcsdate
++;
5273 tmp
= strrchr(rcsdate
, ' '); *tmp
= '\0';
5274 printk("Cyclades driver %s %s\n",
5276 printk(" built %s %s\n",
5277 __DATE__
, __TIME__
);
5278 } /* show_version */
5281 cyclades_get_proc_info(char *buf
, char **start
, off_t offset
, int length
,
5282 int *eof
, void *data
)
5284 struct cyclades_port
*info
;
5290 __u32 cur_jifs
= jiffies
;
5292 size
= sprintf(buf
, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
5297 /* Output one line for each known port */
5298 for (i
= 0; i
< NR_PORTS
&& cy_port
[i
].line
>= 0; i
++) {
5302 size
= sprintf(buf
+len
,
5303 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5305 JIFFIES_DIFF(info
->idle_stats
.in_use
, cur_jifs
) / HZ
,
5306 info
->idle_stats
.xmit_bytes
,
5307 JIFFIES_DIFF(info
->idle_stats
.xmit_idle
, cur_jifs
) / HZ
,
5308 info
->idle_stats
.recv_bytes
,
5309 JIFFIES_DIFF(info
->idle_stats
.recv_idle
, cur_jifs
) / HZ
,
5310 info
->idle_stats
.overruns
,
5311 (long) info
->tty
->ldisc
.num
);
5313 size
= sprintf(buf
+len
,
5314 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
5315 info
->line
, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
5323 if (pos
> offset
+ length
)
5328 *start
= buf
+ (offset
- begin
); /* Start of wanted data */
5329 len
-= (offset
- begin
); /* Start slop */
5331 len
= length
; /* Ending slop */
5337 /* The serial driver boot-time initialization code!
5338 Hardware I/O ports are mapped to character special devices on a
5339 first found, first allocated manner. That is, this code searches
5340 for Cyclom cards in the system. As each is found, it is probed
5341 to discover how many chips (and thus how many ports) are present.
5342 These ports are mapped to the tty ports 32 and upward in monotonic
5343 fashion. If an 8-port card is replaced with a 16-port card, the
5344 port mapping on a following card will shift.
5346 This approach is different from what is used in the other serial
5347 device driver because the Cyclom is more properly a multiplexer,
5348 not just an aggregation of serial ports on one card.
5350 If there are more cards with more ports than have been
5351 statically allocated above, a warning is printed and the
5352 extra ports are ignored.
5358 struct cyclades_port
*info
;
5359 struct cyclades_card
*cinfo
;
5360 int number_z_boards
= 0;
5361 int board
,port
,i
,index
;
5362 unsigned long mailbox
;
5363 unsigned short chip_number
;
5366 init_bh(CYCLADES_BH
, do_cyclades_bh
);
5370 /* Initialize the tty_driver structure */
5372 memset(&cy_serial_driver
, 0, sizeof(struct tty_driver
));
5373 cy_serial_driver
.magic
= TTY_DRIVER_MAGIC
;
5374 cy_serial_driver
.driver_name
= "cyclades";
5375 cy_serial_driver
.name
= "ttyC";
5376 cy_serial_driver
.major
= CYCLADES_MAJOR
;
5377 cy_serial_driver
.minor_start
= 0;
5378 cy_serial_driver
.num
= NR_PORTS
;
5379 cy_serial_driver
.type
= TTY_DRIVER_TYPE_SERIAL
;
5380 cy_serial_driver
.subtype
= SERIAL_TYPE_NORMAL
;
5381 cy_serial_driver
.init_termios
= tty_std_termios
;
5382 cy_serial_driver
.init_termios
.c_cflag
=
5383 B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
;
5384 cy_serial_driver
.flags
= TTY_DRIVER_REAL_RAW
;
5385 cy_serial_driver
.refcount
= &serial_refcount
;
5386 cy_serial_driver
.table
= serial_table
;
5387 cy_serial_driver
.termios
= serial_termios
;
5388 cy_serial_driver
.termios_locked
= serial_termios_locked
;
5390 cy_serial_driver
.open
= cy_open
;
5391 cy_serial_driver
.close
= cy_close
;
5392 cy_serial_driver
.write
= cy_write
;
5393 cy_serial_driver
.put_char
= cy_put_char
;
5394 cy_serial_driver
.flush_chars
= cy_flush_chars
;
5395 cy_serial_driver
.write_room
= cy_write_room
;
5396 cy_serial_driver
.chars_in_buffer
= cy_chars_in_buffer
;
5397 cy_serial_driver
.flush_buffer
= cy_flush_buffer
;
5398 cy_serial_driver
.ioctl
= cy_ioctl
;
5399 cy_serial_driver
.throttle
= cy_throttle
;
5400 cy_serial_driver
.unthrottle
= cy_unthrottle
;
5401 cy_serial_driver
.set_termios
= cy_set_termios
;
5402 cy_serial_driver
.stop
= cy_stop
;
5403 cy_serial_driver
.start
= cy_start
;
5404 cy_serial_driver
.hangup
= cy_hangup
;
5405 cy_serial_driver
.break_ctl
= cy_break
;
5406 cy_serial_driver
.wait_until_sent
= cy_wait_until_sent
;
5407 cy_serial_driver
.read_proc
= cyclades_get_proc_info
;
5410 * The callout device is just like normal device except for
5411 * major number and the subtype code.
5413 cy_callout_driver
= cy_serial_driver
;
5414 cy_callout_driver
.name
= "cub";
5415 cy_callout_driver
.major
= CYCLADESAUX_MAJOR
;
5416 cy_callout_driver
.subtype
= SERIAL_TYPE_CALLOUT
;
5417 cy_callout_driver
.read_proc
= 0;
5418 cy_callout_driver
.proc_entry
= 0;
5421 if (tty_register_driver(&cy_serial_driver
))
5422 panic("Couldn't register Cyclades serial driver\n");
5423 if (tty_register_driver(&cy_callout_driver
))
5424 panic("Couldn't register Cyclades callout driver\n");
5426 for (i
= 0; i
< NR_CARDS
; i
++) {
5427 /* base_addr=0 indicates board not found */
5428 cy_card
[i
].base_addr
= 0;
5431 /* the code below is responsible to find the boards. Each different
5432 type of board has its own detection routine. If a board is found,
5433 the next cy_card structure available is set by the detection
5434 routine. These functions are responsible for checking the
5435 availability of cy_card and cy_port data structures and updating
5436 the cy_next_channel. */
5438 #ifndef CONFIG_COBALT_27
5439 /* look for isa boards */
5440 cy_isa_nboard
= cy_detect_isa();
5441 #endif /* CONFIG_COBALT_27 */
5443 /* look for pci boards */
5444 cy_pci_nboard
= cy_detect_pci();
5446 cy_nboard
= cy_isa_nboard
+ cy_pci_nboard
;
5448 /* invalidate remaining cy_card structures */
5449 for (i
= 0 ; i
< NR_CARDS
; i
++) {
5450 if (cy_card
[i
].base_addr
== 0) {
5451 cy_card
[i
].first_line
= -1;
5452 cy_card
[i
].ctl_addr
= 0;
5454 cy_card
[i
].bus_index
= 0;
5455 cy_card
[i
].first_line
= 0;
5456 cy_card
[i
].num_chips
= 0;
5459 /* invalidate remaining cy_port structures */
5460 for (i
= cy_next_channel
; i
< NR_PORTS
; i
++) {
5461 cy_port
[i
].line
= -1;
5462 cy_port
[i
].magic
= -1;
5465 /* initialize per-port data structures for each valid board found */
5466 for (board
= 0 ; board
< cy_nboard
; board
++) {
5467 cinfo
= &cy_card
[board
];
5468 if (cinfo
->num_chips
== -1) { /* Cyclades-Z */
5470 mailbox
= cy_readl(&((struct RUNTIME_9060
*)
5471 cy_card
[board
].ctl_addr
)->mail_box_0
);
5472 nports
= (mailbox
== ZE_V1
) ? ZE_V1_NPORTS
: 8;
5473 cinfo
->intr_enabled
= 0;
5474 spin_lock_init(&cinfo
->card_lock
);
5475 for (port
= cinfo
->first_line
;
5476 port
< cinfo
->first_line
+ nports
;
5479 info
= &cy_port
[port
];
5480 info
->magic
= CYCLADES_MAGIC
;
5481 info
->type
= PORT_STARTECH
;
5485 info
->flags
= STD_COM_FLAGS
;
5487 if (mailbox
== ZO_V1
)
5488 info
->xmit_fifo_size
= CYZ_FIFO_SIZE
;
5490 info
->xmit_fifo_size
= 4 * CYZ_FIFO_SIZE
;
5500 info
->close_delay
= 5*HZ
/10;
5501 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5502 info
->icount
.cts
= info
->icount
.dsr
=
5503 info
->icount
.rng
= info
->icount
.dcd
= 0;
5504 info
->icount
.rx
= info
->icount
.tx
= 0;
5505 info
->icount
.frame
= info
->icount
.parity
= 0;
5506 info
->icount
.overrun
= info
->icount
.brk
= 0;
5510 #ifdef CY_DEBUG_COUNT
5511 // printk("cyc:cy_init(1) setting Z count to 0\n");
5513 info
->blocked_open
= 0;
5514 info
->default_threshold
= 0;
5515 info
->default_timeout
= 0;
5516 info
->tqueue
.routine
= do_softint
;
5517 info
->tqueue
.data
= info
;
5518 info
->callout_termios
=
5519 cy_callout_driver
.init_termios
;
5520 info
->normal_termios
=
5521 cy_serial_driver
.init_termios
;
5522 init_waitqueue_head(&info
->open_wait
);
5523 init_waitqueue_head(&info
->close_wait
);
5524 init_waitqueue_head(&info
->shutdown_wait
);
5525 init_waitqueue_head(&info
->delta_msr_wait
);
5528 info
->read_status_mask
= 0;
5530 /* Bentson's vars */
5531 info
->jiffies
[0] = 0;
5532 info
->jiffies
[1] = 0;
5533 info
->jiffies
[2] = 0;
5534 info
->rflush_count
= 0;
5537 }else{ /* Cyclom-Y of some kind*/
5538 index
= cinfo
->bus_index
;
5539 spin_lock_init(&cinfo
->card_lock
);
5540 for (port
= cinfo
->first_line
;
5541 port
< cinfo
->first_line
+ 4*cinfo
->num_chips
;
5544 info
= &cy_port
[port
];
5545 info
->magic
= CYCLADES_MAGIC
;
5546 info
->type
= PORT_CIRRUS
;
5549 info
->flags
= STD_COM_FLAGS
;
5551 info
->xmit_fifo_size
= CyMAX_CHAR_FIFO
;
5552 info
->cor1
= CyPARITY_NONE
|Cy_1_STOP
|Cy_8_BITS
;
5554 info
->cor3
= 0x08; /* _very_ small rcv threshold */
5557 info
->close_delay
= 5*HZ
/10;
5558 info
->closing_wait
= CLOSING_WAIT_DELAY
;
5559 info
->icount
.cts
= info
->icount
.dsr
=
5560 info
->icount
.rng
= info
->icount
.dcd
= 0;
5561 info
->icount
.rx
= info
->icount
.tx
= 0;
5562 info
->icount
.frame
= info
->icount
.parity
= 0;
5563 info
->icount
.overrun
= info
->icount
.brk
= 0;
5564 chip_number
= (port
- cinfo
->first_line
) / 4;
5565 if ((info
->chip_rev
= cy_readb(cinfo
->base_addr
+
5566 (cy_chip_offset
[chip_number
]<<index
) +
5567 (CyGFRCR
<<index
))) >= CD1400_REV_J
) {
5568 /* It is a CD1400 rev. J or later */
5569 info
->tbpr
= baud_bpr_60
[13]; /* Tx BPR */
5570 info
->tco
= baud_co_60
[13]; /* Tx CO */
5571 info
->rbpr
= baud_bpr_60
[13]; /* Rx BPR */
5572 info
->rco
= baud_co_60
[13]; /* Rx CO */
5574 info
->rtsdtr_inv
= 1;
5576 info
->tbpr
= baud_bpr_25
[13]; /* Tx BPR */
5577 info
->tco
= baud_co_25
[13]; /* Tx CO */
5578 info
->rbpr
= baud_bpr_25
[13]; /* Rx BPR */
5579 info
->rco
= baud_co_25
[13]; /* Rx CO */
5581 info
->rtsdtr_inv
= 0;
5586 #ifdef CY_DEBUG_COUNT
5587 // printk("cyc:cy_init(2) setting Y count to 0\n");
5589 info
->blocked_open
= 0;
5590 info
->default_threshold
= 0;
5591 info
->default_timeout
= 0;
5592 info
->tqueue
.routine
= do_softint
;
5593 info
->tqueue
.data
= info
;
5594 info
->callout_termios
=
5595 cy_callout_driver
.init_termios
;
5596 info
->normal_termios
=
5597 cy_serial_driver
.init_termios
;
5598 init_waitqueue_head(&info
->open_wait
);
5599 init_waitqueue_head(&info
->close_wait
);
5600 init_waitqueue_head(&info
->shutdown_wait
);
5601 init_waitqueue_head(&info
->delta_msr_wait
);
5604 info
->read_status_mask
=
5605 CyTIMEOUT
| CySPECHAR
| CyBREAK
5606 | CyPARITY
| CyFRAME
| CyOVERRUN
;
5612 #ifndef CONFIG_CYZ_INTR
5613 if (number_z_boards
&& !cyz_timeron
){
5615 cyz_timerlist
.expires
= jiffies
+ 1;
5616 add_timer(&cyz_timerlist
);
5618 printk("Cyclades-Z polling initialized\n");
5621 #endif /* CONFIG_CYZ_INTR */
5628 /* See linux/drivers/char/riscom.c for ideas on how to
5629 pass additional base addresses to the driver!!! */
5637 cleanup_module(void)
5641 unsigned long flags
;
5643 #ifndef CONFIG_CYZ_INTR
5646 del_timer(&cyz_timerlist
);
5648 #endif /* CONFIG_CYZ_INTR */
5650 save_flags(flags
); cli();
5651 remove_bh(CYCLADES_BH
);
5653 if ((e1
= tty_unregister_driver(&cy_serial_driver
)))
5654 printk("cyc: failed to unregister Cyclades serial driver(%d)\n",
5656 if ((e2
= tty_unregister_driver(&cy_callout_driver
)))
5657 printk("cyc: failed to unregister Cyclades callout driver (%d)\n",
5660 restore_flags(flags
);
5662 for (i
= 0; i
< NR_CARDS
; i
++) {
5663 if (cy_card
[i
].base_addr
!= 0) {
5664 iounmap((void *)cy_card
[i
].base_addr
);
5665 if (cy_card
[i
].ctl_addr
!= 0)
5666 iounmap((void *)cy_card
[i
].ctl_addr
);
5668 #ifndef CONFIG_CYZ_INTR
5669 && cy_card
[i
].num_chips
!= -1 /* not a Z card */
5670 #endif /* CONFIG_CYZ_INTR */
5672 free_irq(cy_card
[i
].irq
, &cy_card
[i
]);
5676 free_page((unsigned long) tmp_buf
);
5679 } /* cleanup_module */
5681 /* called by linux/init/main.c to parse command line options */
5683 cy_setup(char *str
, int *ints
)
5685 #ifndef CONFIG_COBALT_27
5688 for (i
= 0 ; i
< NR_ISA_ADDRS
; i
++) {
5689 if (cy_isa_addresses
[i
] == 0) break;
5691 for (j
= 1; j
<= ints
[0]; j
++){
5692 if ( i
< NR_ISA_ADDRS
){
5693 cy_isa_addresses
[i
++] = (unsigned char *)(ints
[j
]);
5696 #endif /* CONFIG_COBALT_27 */
5702 #ifdef CYCLOM_SHOW_STATUS
5704 show_status(int line_num
)
5706 unsigned char *base_addr
;
5707 int card
,chip
,channel
,index
;
5708 struct cyclades_port
* info
;
5709 unsigned long flags
;
5711 info
= &cy_port
[line_num
];
5713 index
= cy_card
[card
].bus_index
;
5714 channel
= (info
->line
) - (cy_card
[card
].first_line
);
5717 printk(" card %d, chip %d, channel %d\n", card
, chip
, channel
);/**/
5719 printk(" cy_card\n");
5720 printk(" irq base_addr num_chips first_line = %d %lx %d %d\n",
5721 cy_card
[card
].irq
, (long)cy_card
[card
].base_addr
,
5722 cy_card
[card
].num_chips
, cy_card
[card
].first_line
);
5724 printk(" cy_port\n");
5725 printk(" card line flags = %d %d %x\n",
5726 info
->card
, info
->line
, info
->flags
);
5727 printk(" *tty read_status_mask timeout xmit_fifo_size ",
5728 printk("= %lx %x %x %x\n",
5729 (long)info
->tty
, info
->read_status_mask
,
5730 info
->timeout
, info
->xmit_fifo_size
);
5731 printk(" cor1,cor2,cor3,cor4,cor5 = %x %x %x %x %x\n",
5732 info
->cor1
, info
->cor2
, info
->cor3
, info
->cor4
, info
->cor5
);
5733 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
5734 info
->tbpr
, info
->tco
, info
->rbpr
, info
->rco
);
5735 printk(" close_delay event count = %d %d %d\n",
5736 info
->close_delay
, info
->event
, info
->count
);
5737 printk(" x_char blocked_open = %x %x\n",
5738 info
->x_char
, info
->blocked_open
);
5739 printk(" session pgrp open_wait = %lx %lx %lx\n",
5740 info
->session
, info
->pgrp
, (long)info
->open_wait
);
5742 CY_LOCK(info
, flags
);
5744 base_addr
= (unsigned char*)
5745 (cy_card
[card
].base_addr
5746 + (cy_chip_offset
[chip
]<<index
));
5748 /* Global Registers */
5750 printk(" CyGFRCR %x\n", cy_readb(base_addr
+ CyGFRCR
<<index
));
5751 printk(" CyCAR %x\n", cy_readb(base_addr
+ CyCAR
<<index
));
5752 printk(" CyGCR %x\n", cy_readb(base_addr
+ CyGCR
<<index
));
5753 printk(" CySVRR %x\n", cy_readb(base_addr
+ CySVRR
<<index
));
5754 printk(" CyRICR %x\n", cy_readb(base_addr
+ CyRICR
<<index
));
5755 printk(" CyTICR %x\n", cy_readb(base_addr
+ CyTICR
<<index
));
5756 printk(" CyMICR %x\n", cy_readb(base_addr
+ CyMICR
<<index
));
5757 printk(" CyRIR %x\n", cy_readb(base_addr
+ CyRIR
<<index
));
5758 printk(" CyTIR %x\n", cy_readb(base_addr
+ CyTIR
<<index
));
5759 printk(" CyMIR %x\n", cy_readb(base_addr
+ CyMIR
<<index
));
5760 printk(" CyPPR %x\n", cy_readb(base_addr
+ CyPPR
<<index
));
5762 cy_writeb(base_addr
+ CyCAR
<<index
, (u_char
)channel
);
5764 /* Virtual Registers */
5766 printk(" CyRIVR %x\n", cy_readb(base_addr
+ CyRIVR
<<index
));
5767 printk(" CyTIVR %x\n", cy_readb(base_addr
+ CyTIVR
<<index
));
5768 printk(" CyMIVR %x\n", cy_readb(base_addr
+ CyMIVR
<<index
));
5769 printk(" CyMISR %x\n", cy_readb(base_addr
+ CyMISR
<<index
));
5771 /* Channel Registers */
5773 printk(" CyCCR %x\n", cy_readb(base_addr
+ CyCCR
<<index
));
5774 printk(" CySRER %x\n", cy_readb(base_addr
+ CySRER
<<index
));
5775 printk(" CyCOR1 %x\n", cy_readb(base_addr
+ CyCOR1
<<index
));
5776 printk(" CyCOR2 %x\n", cy_readb(base_addr
+ CyCOR2
<<index
));
5777 printk(" CyCOR3 %x\n", cy_readb(base_addr
+ CyCOR3
<<index
));
5778 printk(" CyCOR4 %x\n", cy_readb(base_addr
+ CyCOR4
<<index
));
5779 printk(" CyCOR5 %x\n", cy_readb(base_addr
+ CyCOR5
<<index
));
5780 printk(" CyCCSR %x\n", cy_readb(base_addr
+ CyCCSR
<<index
));
5781 printk(" CyRDCR %x\n", cy_readb(base_addr
+ CyRDCR
<<index
));
5782 printk(" CySCHR1 %x\n", cy_readb(base_addr
+ CySCHR1
<<index
));
5783 printk(" CySCHR2 %x\n", cy_readb(base_addr
+ CySCHR2
<<index
));
5784 printk(" CySCHR3 %x\n", cy_readb(base_addr
+ CySCHR3
<<index
));
5785 printk(" CySCHR4 %x\n", cy_readb(base_addr
+ CySCHR4
<<index
));
5786 printk(" CySCRL %x\n", cy_readb(base_addr
+ CySCRL
<<index
));
5787 printk(" CySCRH %x\n", cy_readb(base_addr
+ CySCRH
<<index
));
5788 printk(" CyLNC %x\n", cy_readb(base_addr
+ CyLNC
<<index
));
5789 printk(" CyMCOR1 %x\n", cy_readb(base_addr
+ CyMCOR1
<<index
));
5790 printk(" CyMCOR2 %x\n", cy_readb(base_addr
+ CyMCOR2
<<index
));
5791 printk(" CyRTPR %x\n", cy_readb(base_addr
+ CyRTPR
<<index
));
5792 printk(" CyMSVR1 %x\n", cy_readb(base_addr
+ CyMSVR1
<<index
));
5793 printk(" CyMSVR2 %x\n", cy_readb(base_addr
+ CyMSVR2
<<index
));
5794 printk(" CyRBPR %x\n", cy_readb(base_addr
+ CyRBPR
<<index
));
5795 printk(" CyRCOR %x\n", cy_readb(base_addr
+ CyRCOR
<<index
));
5796 printk(" CyTBPR %x\n", cy_readb(base_addr
+ CyTBPR
<<index
));
5797 printk(" CyTCOR %x\n", cy_readb(base_addr
+ CyTCOR
<<index
));
5799 CY_UNLOCK(info
, flags
);