Import 2.1.118
[davej-history.git] / drivers / char / cyclades.c
blobefd4854ceddf951e6d4a2e65668033bdc6647403
1 #define BLOCKMOVE
2 #define Z_WAKE
3 static char rcsid[] =
4 "$Revision: 2.2.1.6 $$Date: 1998/08/20 17:15:39 $";
6 /*
7 * linux/drivers/char/cyclades.c
9 * This file contains the driver for the Cyclades Cyclom-Y multiport
10 * serial boards.
12 * Maintained by Ivan Passos (ivan@cyclades.com),
13 * Marcio Saito (marcio@cyclades.com) and
14 * Randolph Bentson (bentson@grieg.seaslug.org).
16 * For Technical support and installation problems, please send e-mail
17 * to support@cyclades.com.
19 * Much of the design and some of the code came from serial.c
20 * which was copyright (C) 1991, 1992 Linus Torvalds. It was
21 * extensively rewritten by Theodore Ts'o, 8/16/92 -- 9/14/92,
22 * and then fixed as suggested by Michael K. Johnson 12/12/92.
24 * This version does not support shared irq's.
26 * This module exports the following rs232 io functions:
27 * int cy_init(void);
28 * int cy_open(struct tty_struct *tty, struct file *filp);
29 * and the following functions for modularization.
30 * int init_module(void);
31 * void cleanup_module(void);
33 * $Log: cyclades.c,v $
34 * Revision 2.2.1.6 1998/08/20 17:15:39 ivan
35 * Fixed bug in cy_close function, which causes malfunction
36 * of one of the first 4 ports when a higher port is closed
37 * (Cyclom-Y only).
39 * Revision 2.2.1.5 1998/08/10 18:10:28 ivan
40 * Fixed Cyclom-4Yo hardware detection bug.
42 * Revision 2.2.1.4 1998/08/04 11:02:50 ivan
43 * /proc/cyclades implementation with great collaboration of
44 * Marc Lewis <marc@blarg.net>;
45 * cyy_interrupt was changed to avoid occurence of kernel oopses
46 * during PPP operation.
48 * Revision 2.2.1.3 1998/06/01 12:09:10 ivan
49 * General code review in order to comply with 2.1 kernel standards;
50 * data loss prevention for slow devices revisited (cy_wait_until_sent
51 * was created);
52 * removed conditional compilation for new/old PCI structure support
53 * (now the driver only supports the new PCI structure).
55 * Revision 2.2.1.1 1998/03/19 16:43:12 ivan
56 * added conditional compilation for new/old PCI structure support;
57 * removed kernel series (2.0.x / 2.1.x) conditional compilation.
59 * Revision 2.1.1.3 1998/03/16 18:01:12 ivan
60 * cleaned up the data loss fix;
61 * fixed XON/XOFF handling once more (Cyclades-Z);
62 * general review of the driver routines;
63 * introduction of a mechanism to prevent data loss with slow
64 * printers, by forcing a delay before closing the port.
66 * Revision 2.1.1.2 1998/02/17 16:50:00 ivan
67 * fixed detection/handling of new CD1400 in Ye boards;
68 * fixed XON/XOFF handling (Cyclades-Z);
69 * fixed data loss caused by a premature port close;
70 * introduction of a flag that holds the CD1400 version ID per port
71 * (used by the CYGETCD1400VER new ioctl).
73 * Revision 2.1.1.1 1997/12/03 17:31:19 ivan
74 * Code review for the module cleanup routine;
75 * fixed RTS and DTR status report for new CD1400's in get_modem_info;
76 * includes anonymous changes regarding signal_pending.
78 * Revision 2.1 1997/11/01 17:42:41 ivan
79 * Changes in the driver to support Alpha systems (except 8Zo V_1);
80 * BREAK fix for the Cyclades-Z boards;
81 * driver inactivity control by FW implemented;
82 * introduction of flag that allows driver to take advantage of
83 * a special CD1400 feature related to HW flow control;
84 * added support for the CD1400 rev. J (Cyclom-Y boards);
85 * introduction of ioctls to:
86 * - control the rtsdtr_inv flag (Cyclom-Y);
87 * - control the rflow flag (Cyclom-Y);
88 * - adjust the polling interval (Cyclades-Z);
90 * Revision 1.36.4.33 1997/06/27 19:00:00 ivan
91 * Fixes related to kernel version conditional
92 * compilation.
94 * Revision 1.36.4.32 1997/06/14 19:30:00 ivan
95 * Compatibility issues between kernels 2.0.x and
96 * 2.1.x (mainly related to clear_bit function).
98 * Revision 1.36.4.31 1997/06/03 15:30:00 ivan
99 * Changes to define the memory window according to the
100 * board type.
102 * Revision 1.36.4.30 1997/05/16 15:30:00 daniel
103 * Changes to suport new cycladesZ boards.
105 * Revision 1.36.4.29 1997/05/12 11:30:00 daniel
106 * Merge of Bentson's and Daniel's version 1.36.4.28.
107 * Corrects bug in cy_detect_pci: check if there are more
108 * ports than the number of static structs allocated.
109 * Warning message during initialization if this driver is
110 * used with the new generation of cycladesZ boards. Those
111 * will be supported only in next release of the driver.
112 * Corrects bug in cy_detect_pci and cy_detect_isa that
113 * returned wrong number of VALID boards, when a cyclomY
114 * was found with no serial modules connected.
115 * Changes to use current (2.1.x) kernel subroutine names
116 * and created macros for compilation with 2.0.x kernel,
117 * instead of the other way around.
119 * Revision 1.36.4.28 1997/05/?? ??:00:00 bentson
120 * Change queue_task_irq_off to queue_task_irq.
121 * The inline function queue_task_irq_off (tqueue.h)
122 * was removed from latest releases of 2.1.x kernel.
123 * Use of macro __initfunc to mark the initialization
124 * routines, so memory can be reused.
125 * Also incorporate implementation of critical region
126 * in function cleanup_module() created by anonymous
127 * linuxer.
129 * Revision 1.36.4.28 1997/04/25 16:00:00 daniel
130 * Change to support new firmware that solves DCD problem:
131 * application could fail to receive SIGHUP signal when DCD
132 * varying too fast.
134 * Revision 1.36.4.27 1997/03/26 10:30:00 daniel
135 * Changed for suport linux versions 2.1.X.
136 * Backward compatible with linux versions 2.0.X.
137 * Corrected illegal use of filler field in
138 * CH_CTRL struct.
139 * Deleted some debug messages.
141 * Revision 1.36.4.26 1997/02/27 12:00:00 daniel
142 * Included check for NULL tty pointer in cyz_poll.
144 * Revision 1.36.4.25 1997/02/26 16:28:30 bentson
145 * Bill Foster at Blarg! Online services noticed that
146 * some of the switch elements of -Z modem control
147 * lacked a closing "break;"
149 * Revision 1.36.4.24 1997/02/24 11:00:00 daniel
150 * Changed low water threshold for buffer xmit_buf
152 * Revision 1.36.4.23 1996/12/02 21:50:16 bentson
153 * Marcio provided fix to modem status fetch for -Z
155 * Revision 1.36.4.22 1996/10/28 22:41:17 bentson
156 * improve mapping of -Z control page (thanks to Steve
157 * Price <stevep@fa.tdktca.com> for help on this)
159 * Revision 1.36.4.21 1996/09/10 17:00:10 bentson
160 * shift from CPU-bound to memcopy in cyz_polling operation
162 * Revision 1.36.4.20 1996/09/09 18:30:32 Bentson
163 * Added support to set and report higher speeds.
165 * Revision 1.36.4.19c 1996/08/09 10:00:00 Marcio Saito
166 * Some fixes in the HW flow control for the BETA release.
167 * Don't try to register the IRQ.
169 * Revision 1.36.4.19 1996/08/08 16:23:18 Bentson
170 * make sure "cyc" appears in all kernel messages; all soft interrupts
171 * handled by same routine; recognize out-of-band reception; comment
172 * out some diagnostic messages; leave RTS/CTS flow control to hardware;
173 * fix race condition in -Z buffer management; only -Y needs to explictly
174 * flush chars; tidy up some startup messages;
176 * Revision 1.36.4.18 1996/07/25 18:57:31 bentson
177 * shift MOD_INC_USE_COUNT location to match
178 * serial.c; purge some diagnostic messages;
180 * Revision 1.36.4.17 1996/07/25 18:01:08 bentson
181 * enable modem status messages and fetch & process them; note
182 * time of last activity type for each port; set_line_char now
183 * supports more than line 0 and treats 0 baud correctly;
184 * get_modem_info senses rs_status;
186 * Revision 1.36.4.16 1996/07/20 08:43:15 bentson
187 * barely works--now's time to turn on
188 * more features 'til it breaks
190 * Revision 1.36.4.15 1996/07/19 22:30:06 bentson
191 * check more -Z board status; shorten boot message
193 * Revision 1.36.4.14 1996/07/19 22:20:37 bentson
194 * fix reference to ch_ctrl in startup; verify return
195 * values from cyz_issue_cmd and cyz_update_channel;
196 * more stuff to get modem control correct;
198 * Revision 1.36.4.13 1996/07/11 19:53:33 bentson
199 * more -Z stuff folded in; re-order changes to put -Z stuff
200 * after -Y stuff (to make changes clearer)
202 * Revision 1.36.4.12 1996/07/11 15:40:55 bentson
203 * Add code to poll Cyclades-Z. Add code to get & set RS-232 control.
204 * Add code to send break. Clear firmware ID word at startup (so
205 * that other code won't talk to inactive board).
207 * Revision 1.36.4.11 1996/07/09 05:28:29 bentson
208 * add code for -Z in set_line_char
210 * Revision 1.36.4.10 1996/07/08 19:28:37 bentson
211 * fold more -Z stuff (or in some cases, error messages)
212 * into driver; add text to "don't know what to do" messages.
214 * Revision 1.36.4.9 1996/07/08 18:38:38 bentson
215 * moved compile-time flags near top of file; cosmetic changes
216 * to narrow text (to allow 2-up printing); changed many declarations
217 * to "static" to limit external symbols; shuffled code order to
218 * coalesce -Y and -Z specific code, also to put internal functions
219 * in order of tty_driver structure; added code to recognize -Z
220 * ports (and for moment, do nothing or report error); add cy_startup
221 * to parse boot command line for extra base addresses for ISA probes;
223 * Revision 1.36.4.8 1996/06/25 17:40:19 bentson
224 * reorder some code, fix types of some vars (int vs. long),
225 * add cy_setup to support user declared ISA addresses
227 * Revision 1.36.4.7 1996/06/21 23:06:18 bentson
228 * dump ioctl based firmware load (it's now a user level
229 * program); ensure uninitialzed ports cannot be used
231 * Revision 1.36.4.6 1996/06/20 23:17:19 bentson
232 * rename vars and restructure some code
234 * Revision 1.36.4.5 1996/06/14 15:09:44 bentson
235 * get right status back after boot load
237 * Revision 1.36.4.4 1996/06/13 19:51:44 bentson
238 * successfully loads firmware
240 * Revision 1.36.4.3 1996/06/13 06:08:33 bentson
241 * add more of the code for the boot/load ioctls
243 * Revision 1.36.4.2 1996/06/11 21:00:51 bentson
244 * start to add Z functionality--starting with ioctl
245 * for loading firmware
247 * Revision 1.36.4.1 1996/06/10 18:03:02 bentson
248 * added code to recognize Z/PCI card at initialization; report
249 * presence, but card is not initialized (because firmware needs
250 * to be loaded)
252 * Revision 1.36.3.8 1996/06/07 16:29:00 bentson
253 * starting minor number at zero; added missing verify_area
254 * as noted by Heiko Eissfeldt <heiko@colossus.escape.de>
256 * Revision 1.36.3.7 1996/04/19 21:06:18 bentson
257 * remove unneeded boot message & fix CLOCAL hardware flow
258 * control (Miquel van Smoorenburg <miquels@Q.cistron.nl>);
259 * remove unused diagnostic statements; minor 0 is first;
261 * Revision 1.36.3.6 1996/03/13 13:21:17 marcio
262 * The kernel function vremap (available only in later 1.3.xx kernels)
263 * allows the access to memory addresses above the RAM. This revision
264 * of the driver supports PCI boards below 1Mb (device id 0x100) and
265 * above 1Mb (device id 0x101).
267 * Revision 1.36.3.5 1996/03/07 15:20:17 bentson
268 * Some global changes to interrupt handling spilled into
269 * this driver--mostly unused arguments in system function
270 * calls. Also added change by Marcio Saito which should
271 * reduce lost interrupts at startup by fast processors.
273 * Revision 1.36.3.4 1995/11/13 20:45:10 bentson
274 * Changes by Corey Minyard <minyard@wf-rch.cirr.com> distributed
275 * in 1.3.41 kernel to remove a possible race condition, extend
276 * some error messages, and let the driver run as a loadable module
277 * Change by Alan Wendt <alan@ez0.ezlink.com> to remove a
278 * possible race condition.
279 * Change by Marcio Saito <marcio@cyclades.com> to fix PCI addressing.
281 * Revision 1.36.3.3 1995/11/13 19:44:48 bentson
282 * Changes by Linus Torvalds in 1.3.33 kernel distribution
283 * required due to reordering of driver initialization.
284 * Drivers are now initialized *after* memory management.
286 * Revision 1.36.3.2 1995/09/08 22:07:14 bentson
287 * remove printk from ISR; fix typo
289 * Revision 1.36.3.1 1995/09/01 12:00:42 marcio
290 * Minor fixes in the PCI board support. PCI function calls in
291 * conditional compilation (CONFIG_PCI). Thanks to Jim Duncan
292 * <duncan@okay.com>. "bad serial count" message removed.
294 * Revision 1.36.3 1995/08/22 09:19:42 marcio
295 * Cyclom-Y/PCI support added. Changes in the cy_init routine and
296 * board initialization. Changes in the boot messages. The driver
297 * supports up to 4 boards and 64 ports by default.
299 * Revision 1.36.1.4 1995/03/29 06:14:14 bentson
300 * disambiguate between Cyclom-16Y and Cyclom-32Ye;
302 * Revision 1.36.1.3 1995/03/23 22:15:35 bentson
303 * add missing break in modem control block in ioctl switch statement
304 * (discovered by Michael Edward Chastain <mec@jobe.shell.portal.com>);
306 * Revision 1.36.1.2 1995/03/22 19:16:22 bentson
307 * make sure CTS flow control is set as soon as possible (thanks
308 * to note from David Lambert <lambert@chesapeake.rps.slb.com>);
310 * Revision 1.36.1.1 1995/03/13 15:44:43 bentson
311 * initialize defaults for receive threshold and stale data timeout;
312 * cosmetic changes;
314 * Revision 1.36 1995/03/10 23:33:53 bentson
315 * added support of chips 4-7 in 32 port Cyclom-Ye;
316 * fix cy_interrupt pointer dereference problem
317 * (Joe Portman <baron@aa.net>);
318 * give better error response if open is attempted on non-existent port
319 * (Zachariah Vaum <jchryslr@netcom.com>);
320 * correct command timeout (Kenneth Lerman <lerman@@seltd.newnet.com>);
321 * conditional compilation for -16Y on systems with fast, noisy bus;
322 * comment out diagnostic print function;
323 * cleaned up table of base addresses;
324 * set receiver time-out period register to correct value,
325 * set receive threshold to better default values,
326 * set chip timer to more accurate 200 Hz ticking,
327 * add code to monitor and modify receive parameters
328 * (Rik Faith <faith@cs.unc.edu> Nick Simicich
329 * <njs@scifi.emi.net>);
331 * Revision 1.35 1994/12/16 13:54:18 steffen
332 * additional patch by Marcio Saito for board detection
333 * Accidently left out in 1.34
335 * Revision 1.34 1994/12/10 12:37:12 steffen
336 * This is the corrected version as suggested by Marcio Saito
338 * Revision 1.33 1994/12/01 22:41:18 bentson
339 * add hooks to support more high speeds directly; add tytso
340 * patch regarding CLOCAL wakeups
342 * Revision 1.32 1994/11/23 19:50:04 bentson
343 * allow direct kernel control of higher signalling rates;
344 * look for cards at additional locations
346 * Revision 1.31 1994/11/16 04:33:28 bentson
347 * ANOTHER fix from Corey Minyard, minyard@wf-rch.cirr.com--
348 * a problem in chars_in_buffer has been resolved by some
349 * small changes; this should yield smoother output
351 * Revision 1.30 1994/11/16 04:28:05 bentson
352 * Fix from Corey Minyard, Internet: minyard@metronet.com,
353 * UUCP: minyard@wf-rch.cirr.com, WORK: minyardbnr.ca, to
354 * cy_hangup that appears to clear up much (all?) of the
355 * DTR glitches; also he's added/cleaned-up diagnostic messages
357 * Revision 1.29 1994/11/16 04:16:07 bentson
358 * add change proposed by Ralph Sims, ralphs@halcyon.com, to
359 * operate higher speeds in same way as other serial ports;
360 * add more serial ports (for up to two 16-port muxes).
362 * Revision 1.28 1994/11/04 00:13:16 root
363 * turn off diagnostic messages
365 * Revision 1.27 1994/11/03 23:46:37 root
366 * bunch of changes to bring driver into greater conformance
367 * with the serial.c driver (looking for missed fixes)
369 * Revision 1.26 1994/11/03 22:40:36 root
370 * automatic interrupt probing fixed.
372 * Revision 1.25 1994/11/03 20:17:02 root
373 * start to implement auto-irq
375 * Revision 1.24 1994/11/03 18:01:55 root
376 * still working on modem signals--trying not to drop DTR
377 * during the getty/login processes
379 * Revision 1.23 1994/11/03 17:51:36 root
380 * extend baud rate support; set receive threshold as function
381 * of baud rate; fix some problems with RTS/CTS;
383 * Revision 1.22 1994/11/02 18:05:35 root
384 * changed arguments to udelay to type long to get
385 * delays to be of correct duration
387 * Revision 1.21 1994/11/02 17:37:30 root
388 * employ udelay (after calibrating loops_per_second earlier
389 * in init/main.c) instead of using home-grown delay routines
391 * Revision 1.20 1994/11/02 03:11:38 root
392 * cy_chars_in_buffer forces a return value of 0 to let
393 * login work (don't know why it does); some functions
394 * that were returning EFAULT, now executes the code;
395 * more work on deciding when to disable xmit interrupts;
397 * Revision 1.19 1994/11/01 20:10:14 root
398 * define routine to start transmission interrupts (by enabling
399 * transmit interrupts); directly enable/disable modem interrupts;
401 * Revision 1.18 1994/11/01 18:40:45 bentson
402 * Don't always enable transmit interrupts in startup; interrupt on
403 * TxMpty instead of TxRdy to help characters get out before shutdown;
404 * restructure xmit interrupt to check for chars first and quit if
405 * none are ready to go; modem status (MXVRx) is upright, _not_ inverted
406 * (to my view);
408 * Revision 1.17 1994/10/30 04:39:45 bentson
409 * rename serial_driver and callout_driver to cy_serial_driver and
410 * cy_callout_driver to avoid linkage interference; initialize
411 * info->type to PORT_CIRRUS; ruggedize paranoia test; elide ->port
412 * from cyclades_port structure; add paranoia check to cy_close;
414 * Revision 1.16 1994/10/30 01:14:33 bentson
415 * change major numbers; add some _early_ return statements;
417 * Revision 1.15 1994/10/29 06:43:15 bentson
418 * final tidying up for clean compile; enable some error reporting
420 * Revision 1.14 1994/10/28 20:30:22 Bentson
421 * lots of changes to drag the driver towards the new tty_io
422 * structures and operation. not expected to work, but may
423 * compile cleanly.
425 * Revision 1.13 1994/07/21 23:08:57 Bentson
426 * add some diagnostic cruft; support 24 lines (for testing
427 * both -8Y and -16Y cards; be more thorough in servicing all
428 * chips during interrupt; add "volatile" a few places to
429 * circumvent compiler optimizations; fix base & offset
430 * computations in block_til_ready (was causing chip 0 to
431 * stop operation)
433 * Revision 1.12 1994/07/19 16:42:11 Bentson
434 * add some hackery for kernel version 1.1.8; expand
435 * error messages; refine timing for delay loops and
436 * declare loop params volatile
438 * Revision 1.11 1994/06/11 21:53:10 bentson
439 * get use of save_car right in transmit interrupt service
441 * Revision 1.10.1.1 1994/06/11 21:31:18 bentson
442 * add some diagnostic printing; try to fix save_car stuff
444 * Revision 1.10 1994/06/11 20:36:08 bentson
445 * clean up compiler warnings
447 * Revision 1.9 1994/06/11 19:42:46 bentson
448 * added a bunch of code to support modem signalling
450 * Revision 1.8 1994/06/11 17:57:07 bentson
451 * recognize break & parity error
453 * Revision 1.7 1994/06/05 05:51:34 bentson
454 * Reorder baud table to be monotonic; add cli to CP; discard
455 * incoming characters and status if the line isn't open; start to
456 * fold code into cy_throttle; start to port get_serial_info,
457 * set_serial_info, get_modem_info, set_modem_info, and send_break
458 * from serial.c; expand cy_ioctl; relocate and expand config_setup;
459 * get flow control characters from tty struct; invalidate ports w/o
460 * hardware;
462 * Revision 1.6 1994/05/31 18:42:21 bentson
463 * add a loop-breaker in the interrupt service routine;
464 * note when port is initialized so that it can be shut
465 * down under the right conditions; receive works without
466 * any obvious errors
468 * Revision 1.5 1994/05/30 00:55:02 bentson
469 * transmit works without obvious errors
471 * Revision 1.4 1994/05/27 18:46:27 bentson
472 * incorporated more code from lib_y.c; can now print short
473 * strings under interrupt control to port zero; seems to
474 * select ports/channels/lines correctly
476 * Revision 1.3 1994/05/25 22:12:44 bentson
477 * shifting from multi-port on a card to proper multiplexor
478 * data structures; added skeletons of most routines
480 * Revision 1.2 1994/05/19 13:21:43 bentson
481 * start to crib from other sources
485 /* If you need to install more boards than NR_CARDS, change the constant
486 in the definition below. No other change is necessary to support up to
487 eight boards. Beyond that you'll have to extend cy_isa_addresses. */
489 #define NR_CARDS 4
492 If the total number of ports is larger than NR_PORTS, change this
493 constant in the definition below. No other change is necessary to
494 support more boards/ports. */
496 #define NR_PORTS 128
498 #define ZE_V1_NPORTS 64
499 #define ZO_V1 0
500 #define ZO_V2 1
501 #define ZE_V1 2
503 #define SERIAL_PARANOIA_CHECK
504 #undef CY_DEBUG_OPEN
505 #undef CY_DEBUG_THROTTLE
506 #undef CY_DEBUG_OTHER
507 #undef CY_DEBUG_IO
508 #undef CY_DEBUG_COUNT
509 #undef CY_DEBUG_DTR
510 #undef CY_DEBUG_WAIT_UNTIL_SENT
511 #undef CY_16Y_HACK
512 #undef CY_ENABLE_MONITORING
513 #undef CY_PCI_DEBUG
515 #if 0
516 #define PAUSE __asm__("nop");
517 #else
518 #define PAUSE ;
519 #endif
521 #define cy_min(a,b) (((a)<(b))?(a):(b))
523 #if 0
524 /********
525 * For the next two macros, it is assumed that the buffer size is a
526 * power of 2
527 ********/
529 #define CHARS_IN_BUF(buf_ctrl) \
530 ((cy_readl(&buf_ctrl->rx_put) - \
531 cy_readl(&buf_ctrl->rx_get) + \
532 cy_readl(&buf_ctrl->rx_bufsize)) & \
533 (cy_readl(&buf_ctrl->rx_bufsize) - 1))
535 #define SPACE_IN_BUF(buf_ctrl) \
536 ((cy_readl(&buf_ctrl->tx_get) - \
537 cy_readl(&buf_ctrl->tx_put) + \
538 cy_readl(&buf_ctrl->tx_bufsize) - 1) & \
539 (cy_readl(&buf_ctrl->tx_bufsize) - 1))
540 #endif
543 * Include section
545 #include <linux/config.h>
546 #include <linux/module.h>
547 #include <linux/errno.h>
548 #include <linux/signal.h>
549 #include <linux/sched.h>
550 #include <linux/timer.h>
551 #include <linux/interrupt.h>
552 #include <linux/tty.h>
553 #include <linux/serial.h>
554 #include <linux/major.h>
555 #include <linux/string.h>
556 #include <linux/fcntl.h>
557 #include <linux/ptrace.h>
558 #include <linux/cyclades.h>
559 #include <linux/mm.h>
560 #include <linux/init.h>
561 #include <linux/delay.h>
563 #include <asm/system.h>
564 #include <asm/io.h>
565 #include <asm/irq.h>
566 #include <asm/uaccess.h>
567 #include <asm/bitops.h>
569 #include <linux/types.h>
570 #include <linux/kernel.h>
571 #include <linux/pci.h>
572 #include <linux/version.h>
574 #ifdef CONFIG_PROC_FS
575 #include <linux/stat.h>
576 #include <linux/proc_fs.h>
577 #endif
579 #define cy_put_user put_user
581 static unsigned long cy_get_user(unsigned long *addr)
583 unsigned long result = 0;
584 int error = get_user (result, addr);
585 if (error)
586 printk ("cyclades: cy_get_user: error == %d\n", error);
587 return result;
590 #ifndef MIN
591 #define MIN(a,b) ((a) < (b) ? (a) : (b))
592 #endif
594 #define IS_CYC_Z(card) ((card).num_chips == -1)
596 #define Z_FPGA_CHECK(card) \
597 ((cy_readl(&((struct RUNTIME_9060 *) \
598 ((card).ctl_addr))->init_ctrl) & (1<<17)) != 0)
600 #define ISZLOADED(card) (((ZO_V1==cy_readl(&((struct RUNTIME_9060 *) \
601 ((card).ctl_addr))->mail_box_0)) || \
602 Z_FPGA_CHECK(card)) && \
603 (ZFIRM_ID==cy_readl(&((struct FIRM_ID *) \
604 ((card).base_addr+ID_ADDRESS))->signature)))
606 #define WAKEUP_CHARS (SERIAL_XMIT_SIZE-256)
608 #define STD_COM_FLAGS (0)
610 #define JIFFIES_DIFF(n, j) ((n) - (j))
612 static DECLARE_TASK_QUEUE(tq_cyclades);
614 static struct tty_driver cy_serial_driver, cy_callout_driver;
615 static int serial_refcount;
617 static volatile int cy_irq_triggered;
618 static volatile int cy_triggered;
619 static int cy_wild_int_mask;
620 static volatile ucchar *intr_base_addr;
622 /* This is the address lookup table. The driver will probe for
623 Cyclom-Y/ISA boards at all addresses in here. If you want the
624 driver to probe addresses at a different address, add it to
625 this table. If the driver is probing some other board and
626 causing problems, remove the offending address from this table.
627 The cy_setup function extracts additional addresses from the
628 boot options line. The form is "cyclades=address,address..."
631 static unsigned char *cy_isa_addresses[] = {
632 (unsigned char *) 0xD0000,
633 (unsigned char *) 0xD2000,
634 (unsigned char *) 0xD4000,
635 (unsigned char *) 0xD6000,
636 (unsigned char *) 0xD8000,
637 (unsigned char *) 0xDA000,
638 (unsigned char *) 0xDC000,
639 (unsigned char *) 0xDE000,
640 0,0,0,0,0,0,0,0
642 #define NR_ISA_ADDRS (sizeof(cy_isa_addresses)/sizeof(unsigned char*))
644 /* This is the per-card data structure containing address, irq, number of
645 channels, etc. This driver supports a maximum of NR_CARDS cards.
647 static struct cyclades_card cy_card[NR_CARDS];
649 /* This is the per-channel data structure containing pointers, flags
650 and variables for the port. This driver supports a maximum of NR_PORTS.
652 static struct cyclades_port cy_port[NR_PORTS];
654 static int cy_next_channel = 0; /* next minor available */
656 static struct tty_struct *serial_table[NR_PORTS];
657 static struct termios *serial_termios[NR_PORTS];
658 static struct termios *serial_termios_locked[NR_PORTS];
660 /* This is the per-irq data structure,
661 it maps an irq to the corresponding card */
663 static struct cyclades_card *IRQ_cards[NR_IRQS];
666 * tmp_buf is used as a temporary buffer by serial_write. We need to
667 * lock it in case the copy_from_user blocks while swapping in a page,
668 * and some other program tries to do a serial write at the same time.
669 * Since the lock will only come under contention when the system is
670 * swapping and available memory is low, it makes sense to share one
671 * buffer across all the serial ports, since it significantly saves
672 * memory if large numbers of serial ports are open. This buffer is
673 * allocated when the first cy_open occurs.
675 static unsigned char *tmp_buf;
676 static struct semaphore tmp_buf_sem = MUTEX;
679 * This is used to look up the divisor speeds and the timeouts
680 * We're normally limited to 15 distinct baud rates. The extra
681 * are accessed via settings in info->flags.
682 * 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
683 * 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
684 * HI VHI
685 * 20
687 static int baud_table[] = {
688 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
689 1800, 2400, 4800, 9600, 19200, 38400, 57600, 76800,115200,150000,
690 230400, 0};
692 static char baud_co_25[] = { /* 25 MHz clock option table */
693 /* value => 00 01 02 03 04 */
694 /* divide by 8 32 128 512 2048 */
695 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
696 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
698 static char baud_bpr_25[] = { /* 25 MHz baud rate period table */
699 0x00, 0xf5, 0xa3, 0x6f, 0x5c, 0x51, 0xf5, 0xa3, 0x51, 0xa3,
700 0x6d, 0x51, 0xa3, 0x51, 0xa3, 0x51, 0x36, 0x29, 0x1b, 0x15};
702 static char baud_co_60[] = { /* 60 MHz clock option table (CD1400 J) */
703 /* value => 00 01 02 03 04 */
704 /* divide by 8 32 128 512 2048 */
705 0x00, 0x00, 0x00, 0x04, 0x04, 0x04, 0x04, 0x04, 0x03, 0x03,
706 0x03, 0x02, 0x02, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
707 0x00};
709 static char baud_bpr_60[] = { /* 60 MHz baud rate period table (CD1400 J) */
710 0x00, 0x82, 0x21, 0xff, 0xdb, 0xc3, 0x92, 0x62, 0xc3, 0x62,
711 0x41, 0xc3, 0x62, 0xc3, 0x62, 0xc3, 0x82, 0x62, 0x41, 0x32,
712 0x21};
714 static char baud_cor3[] = { /* receive threshold */
715 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
716 0x0a, 0x0a, 0x0a, 0x09, 0x09, 0x08, 0x08, 0x08, 0x08, 0x07,
717 0x07};
720 * The Cyclades driver implements HW flow control as any serial driver.
721 * The cyclades_port structure member rflow and the vector rflow_thr
722 * allows us to take advantage of a special feature in the CD1400 to avoid
723 * data loss even when the system interrupt latency is too high. These flags
724 * are to be used only with very special applications. Setting these flags
725 * requires the use of a special cable (DTR and RTS reversed). In the new
726 * CD1400-based boards (rev. 6.00 or later), there is no need for special
727 * cables.
730 static char rflow_thr[] = { /* rflow threshold */
731 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
732 0x00, 0x00, 0x00, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a,
733 0x0a};
735 /* The Cyclom-Ye has placed the sequential chips in non-sequential
736 * address order. This look-up table overcomes that problem.
738 static int cy_chip_offset [] =
739 { 0x0000,
740 0x0400,
741 0x0800,
742 0x0C00,
743 0x0200,
744 0x0600,
745 0x0A00,
746 0x0E00
749 /* PCI related definitions */
751 static unsigned short cy_pci_nboard = 0;
752 static unsigned short cy_isa_nboard = 0;
753 static unsigned short cy_nboard = 0;
754 static unsigned short cy_pci_dev_id[] = {
755 PCI_DEVICE_ID_CYCLOM_Y_Lo,/* PCI below 1Mb */
756 PCI_DEVICE_ID_CYCLOM_Y_Hi,/* PCI above 1Mb */
757 PCI_DEVICE_ID_CYCLOM_Z_Lo,/* PCI below 1Mb */
758 PCI_DEVICE_ID_CYCLOM_Z_Hi,/* PCI above 1Mb */
759 0 /* end of table */
763 static void cy_start(struct tty_struct *);
764 static void set_line_char(struct cyclades_port *);
765 static void cy_probe(int, void *, struct pt_regs *);
766 static void cyz_poll(unsigned long);
767 #ifdef CYCLOM_SHOW_STATUS
768 static void show_status(int);
769 #endif
771 #ifdef CONFIG_PROC_FS
772 static int cyclades_get_proc_info(char *, char **, off_t , int , int *, void *);
773 #endif
775 /* The Cyclades-Z polling cycle is defined by this variable */
776 static long cyz_polling_cycle = CZ_DEF_POLL;
778 static int cyz_timeron = 0;
779 static struct timer_list
780 cyz_timerlist = {
781 NULL, NULL, 0, 0, cyz_poll
784 /**************************************************
785 error = verify_area(VERIFY_WRITE, (void *) arg, sizeof(unsigned long));
786 copy_to_user (to, from, count);
787 ***************************************************************
788 error = verify_area(VERIFY_READ, (void *) arg, sizeof(unsigned long *));
789 copy_from_user(to, from, count);
790 **************************************************/
793 static inline int
794 serial_paranoia_check(struct cyclades_port *info,
795 kdev_t device, const char *routine)
797 #ifdef SERIAL_PARANOIA_CHECK
798 static const char *badmagic =
799 "cyc Warning: bad magic number for serial struct (%s) in %s\n";
800 static const char *badinfo =
801 "cyc Warning: null cyclades_port for (%s) in %s\n";
802 static const char *badrange =
803 "cyc Warning: cyclades_port out of range for (%s) in %s\n";
805 if (!info) {
806 printk(badinfo, kdevname(device), routine);
807 return 1;
810 if( (long)info < (long)(&cy_port[0])
811 || (long)(&cy_port[NR_PORTS]) < (long)info ){
812 printk(badrange, kdevname(device), routine);
813 return 1;
816 if (info->magic != CYCLADES_MAGIC) {
817 printk(badmagic, kdevname(device), routine);
818 return 1;
820 #endif
821 return 0;
822 } /* serial_paranoia_check */
825 * This routine is used by the interrupt handler to schedule
826 * processing in the software interrupt portion of the driver
827 * (also known as the "bottom half"). This can be called any
828 * number of times for any channel without harm.
830 static inline void
831 cy_sched_event(struct cyclades_port *info, int event)
833 info->event |= 1 << event; /* remember what kind of event and who */
834 queue_task(&info->tqueue, &tq_cyclades); /* it belongs to */
835 mark_bh(CYCLADES_BH); /* then trigger event */
836 } /* cy_sched_event */
840 * This routine is used to handle the "bottom half" processing for the
841 * serial driver, known also the "software interrupt" processing.
842 * This processing is done at the kernel interrupt level, after the
843 * cy#/_interrupt() has returned, BUT WITH INTERRUPTS TURNED ON. This
844 * is where time-consuming activities which can not be done in the
845 * interrupt driver proper are done; the interrupt driver schedules
846 * them using cy_sched_event(), and they get done here.
848 * This is done through one level of indirection--the task queue.
849 * When a hardware interrupt service routine wants service by the
850 * driver's bottom half, it enqueues the appropriate tq_struct (one
851 * per port) to the tq_cyclades work queue and sets a request flag
852 * via mark_bh for processing that queue. When the time is right,
853 * do_cyclades_bh is called (because of the mark_bh) and it requests
854 * that the work queue be processed.
856 * Although this may seem unwieldy, it gives the system a way to
857 * pass an argument (in this case the pointer to the cyclades_port
858 * structure) to the bottom half of the driver. Previous kernels
859 * had to poll every port to see if that port needed servicing.
861 static void
862 do_cyclades_bh(void)
864 run_task_queue(&tq_cyclades);
865 } /* do_cyclades_bh */
867 static void
868 do_softint(void *private_)
870 struct cyclades_port *info = (struct cyclades_port *) private_;
871 struct tty_struct *tty;
873 tty = info->tty;
874 if (!tty)
875 return;
877 if (test_and_clear_bit(Cy_EVENT_HANGUP, &info->event)) {
878 tty_hangup(info->tty);
879 wake_up_interruptible(&info->open_wait);
880 info->flags &= ~(ASYNC_NORMAL_ACTIVE|
881 ASYNC_CALLOUT_ACTIVE);
883 if (test_and_clear_bit(Cy_EVENT_OPEN_WAKEUP, &info->event)) {
884 wake_up_interruptible(&info->open_wait);
886 if (test_and_clear_bit(Cy_EVENT_WRITE_WAKEUP, &info->event)) {
887 if((tty->flags & (1<< TTY_DO_WRITE_WAKEUP))
888 && tty->ldisc.write_wakeup){
889 (tty->ldisc.write_wakeup)(tty);
891 wake_up_interruptible(&tty->write_wait);
893 #ifdef Z_WAKE
894 if (test_and_clear_bit(Cy_EVENT_SHUTDOWN_WAKEUP, &info->event)) {
895 wake_up_interruptible(&info->shutdown_wait);
897 #endif
898 } /* do_softint */
901 /***********************************************************/
902 /********* Start of block of Cyclom-Y specific code ********/
904 /* This routine waits up to 1000 micro-seconds for the previous
905 command to the Cirrus chip to complete and then issues the
906 new command. An error is returned if the previous command
907 didn't finish within the time limit.
909 static int
910 cyy_issue_cmd(volatile ucchar *base_addr, u_char cmd, int index)
912 unsigned long flags;
913 volatile int i;
915 save_flags(flags); cli();
916 /* Check to see that the previous command has completed */
917 for(i = 0 ; i < 100 ; i++){
918 if (cy_readb(base_addr+(CyCCR<<index)) == 0){
919 break;
921 udelay(10L);
923 /* if the CCR never cleared, the previous command
924 didn't finish within the "reasonable time" */
925 if ( i == 100 ) {
926 restore_flags(flags);
927 return (-1);
930 /* Issue the new command */
931 cy_writeb((u_long)base_addr+(CyCCR<<index), cmd);
932 restore_flags(flags);
933 return(0);
934 } /* cyy_issue_cmd */
936 static int probe_ready;
939 * Grab all interrupts in preparation for doing an automatic irq
940 * detection. dontgrab is a mask of irq's _not_ to grab. Returns a
941 * mask of irq's which were grabbed and should therefore be freed
942 * using free_all_interrupts().
944 static int
945 grab_all_interrupts(int dontgrab)
947 int irq_lines = 0;
948 int i, mask;
950 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
951 if (!(mask & dontgrab)
952 && !request_irq(i, cy_probe,
953 SA_INTERRUPT, "serial probe", NULL)) {
954 irq_lines |= mask;
957 return irq_lines;
958 } /* grab_all_interrupts */
961 * Release all interrupts grabbed by grab_all_interrupts
963 static void
964 free_all_interrupts(int irq_lines)
966 int i;
968 for (i = 0; i < 16; i++) {
969 if (irq_lines & (1 << i)) {
970 free_irq(i,NULL);
973 } /* free_all_interrupts */
976 * This routine returns a bitfield of "wild interrupts". Basically,
977 * any unclaimed interrupts which is flapping around.
979 static int
980 check_wild_interrupts(void)
982 int i, mask;
983 int wild_interrupts = 0;
984 int irq_lines;
985 unsigned long timeout;
986 unsigned long flags;
988 /*Turn on interrupts (they may be off) */
989 save_flags(flags); sti();
991 irq_lines = grab_all_interrupts(0);
994 * Delay for 0.1 seconds -- we use a busy loop since this may
995 * occur during the bootup sequence
997 timeout = jiffies+(HZ/10);
998 while (timeout >= jiffies)
1001 cy_triggered = 0; /* Reset after letting things settle */
1003 timeout = jiffies+(HZ/10);
1004 while (timeout >= jiffies)
1007 for (i = 0, mask = 1; i < 16; i++, mask <<= 1) {
1008 if ((cy_triggered & (1 << i)) &&
1009 (irq_lines & (1 << i))) {
1010 wild_interrupts |= mask;
1013 free_all_interrupts(irq_lines);
1014 restore_flags(flags);
1015 return wild_interrupts;
1016 } /* check_wild_interrupts */
1019 * This routine is called by do_auto_irq(); it attempts to determine
1020 * which interrupt a serial port is configured to use. It is not
1021 * fool-proof, but it works a large part of the time.
1023 static int
1024 get_auto_irq(volatile ucchar *address)
1026 unsigned long timeout;
1027 volatile ucchar *base_addr;
1028 int index;
1029 unsigned long flags;
1031 index = 0; /* IRQ probing is only for ISA */
1032 base_addr = address;
1033 intr_base_addr = address;
1036 * Enable interrupts and see who answers
1038 cy_irq_triggered = 0;
1039 save_flags(flags); cli();
1040 cy_writeb((u_long)base_addr+(CyCAR<<index), 0);
1041 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_XMTR,index);
1042 cy_writeb((u_long)base_addr+(CySRER<<index),
1043 cy_readb(base_addr+(CySRER<<index)) | CyTxMpty);
1044 probe_ready = 1;
1045 restore_flags(flags);
1047 timeout = jiffies+(HZ/50);
1048 while (timeout >= jiffies) {
1049 if (cy_irq_triggered)
1050 break;
1052 probe_ready = 0;
1053 return(cy_irq_triggered);
1054 } /* get_auto_irq */
1057 * Calls get_auto_irq() multiple times, to make sure we don't get
1058 * faked out by random interrupts
1060 static int
1061 do_auto_irq(volatile ucchar *address)
1063 int irq_lines = 0;
1064 int irq_try_1 = 0, irq_try_2 = 0;
1065 int retries;
1066 unsigned long flags;
1068 /* Turn on interrupts (they may be off) */
1069 save_flags(flags); sti();
1071 probe_ready = 0;
1073 cy_wild_int_mask = check_wild_interrupts();
1075 irq_lines = grab_all_interrupts(cy_wild_int_mask);
1077 for (retries = 0; retries < 5; retries++) {
1078 if (!irq_try_1)
1079 irq_try_1 = get_auto_irq(address);
1080 if (!irq_try_2)
1081 irq_try_2 = get_auto_irq(address);
1082 if (irq_try_1 && irq_try_2) {
1083 if (irq_try_1 == irq_try_2)
1084 break;
1085 irq_try_1 = irq_try_2 = 0;
1088 restore_flags(flags);
1089 free_all_interrupts(irq_lines);
1090 return (irq_try_1 == irq_try_2) ? irq_try_1 : 0;
1091 } /* do_auto_irq */
1095 * This interrupt routine is used
1096 * while we are probing for submarines.
1098 static void
1099 cy_probe(int irq, void *dev_id, struct pt_regs *regs)
1101 int save_xir, save_car;
1102 int index = 0; /* probing interrupts is only for ISA */
1104 if (!probe_ready) {
1105 cy_writeb((u_long)intr_base_addr+(Cy_ClrIntr<<index), 0);
1106 return;
1109 cy_irq_triggered = irq;
1110 cy_triggered |= 1 << irq;
1112 if(cy_readb(intr_base_addr+(CySVRR<<index)) != 0) {
1113 save_xir = (u_char) cy_readb(intr_base_addr+(CyTIR<<index));
1114 save_car = cy_readb(intr_base_addr+(CyCAR<<index));
1115 cy_writeb((u_long)intr_base_addr+(CyCAR<<index), (save_xir & 0x3));
1116 cy_writeb((u_long)intr_base_addr+(CySRER<<index),
1117 cy_readb(intr_base_addr+(CySRER<<index)) & ~CyTxMpty);
1118 cy_writeb((u_long)intr_base_addr+(CyTIR<<index), (save_xir & 0x3f));
1119 cy_writeb((u_long)intr_base_addr+(CyCAR<<index), (save_car));
1121 cy_writeb((u_long)intr_base_addr+(Cy_ClrIntr<<index), 0);
1122 /* Cy_ClrIntr is 0x1800 */
1123 return;
1124 } /* cy_probe */
1126 /* The real interrupt service routine is called
1127 whenever the card wants its hand held--chars
1128 received, out buffer empty, modem change, etc.
1130 static void
1131 cyy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1133 struct tty_struct *tty;
1134 int status;
1135 struct cyclades_card *cinfo;
1136 struct cyclades_port *info;
1137 volatile unsigned char *base_addr, *card_base_addr;
1138 int chip;
1139 int save_xir, channel, save_car;
1140 char data;
1141 volatile int char_count;
1142 int outch;
1143 int i,j,index;
1144 int too_many;
1145 int had_work;
1146 int mdm_change;
1147 int mdm_status;
1149 if((cinfo = IRQ_cards[irq]) == 0){
1150 #ifdef CY_DEBUG_INTERRUPTS
1151 printk("cy_interrupt: spurious interrupt %d\n\r", irq);
1152 #endif
1153 return; /* spurious interrupt */
1156 card_base_addr = (unsigned char *)cinfo->base_addr;
1157 index = cinfo->bus_index;
1160 /* This loop checks all chips in the card. Make a note whenever
1161 _any_ chip had some work to do, as this is considered an
1162 indication that there will be more to do. Only when no chip
1163 has any work does this outermost loop exit.
1166 had_work = 0;
1167 for ( chip = 0 ; chip < cinfo->num_chips ; chip ++) {
1168 base_addr = (unsigned char *)
1169 (cinfo->base_addr + (cy_chip_offset[chip]<<index));
1170 too_many = 0;
1171 while ( (status = cy_readb(base_addr+(CySVRR<<index))) != 0x00) {
1172 had_work++;
1173 /* The purpose of the following test is to ensure that
1174 no chip can monopolize the driver. This forces the
1175 chips to be checked in a round-robin fashion (after
1176 draining each of a bunch (1000) of characters).
1178 if(1000<too_many++){
1179 break;
1181 if (status & CySRReceive) { /* reception interrupt */
1182 #ifdef CY_DEBUG_INTERRUPTS
1183 printk("cy_interrupt: rcvd intr, chip %d\n\r", chip);
1184 #endif
1185 /* determine the channel & change to that context */
1186 save_xir = (u_char) cy_readb(base_addr+(CyRIR<<index));
1187 channel = (u_short ) (save_xir & CyIRChannel);
1188 i = channel + chip * 4 + cinfo->first_line;
1189 info = &cy_port[i];
1190 info->last_active = jiffies;
1191 save_car = cy_readb(base_addr+(CyCAR<<index));
1192 cy_writeb((u_long)base_addr+(CyCAR<<index), save_xir);
1194 /* if there is nowhere to put the data, discard it */
1195 if(info->tty == 0){
1196 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
1197 if ( j == CyIVRRxEx ) { /* exception */
1198 data = cy_readb(base_addr+(CyRDSR<<index));
1199 } else { /* normal character reception */
1200 char_count = cy_readb(base_addr+(CyRDCR<<index));
1201 while(char_count--){
1202 data = cy_readb(base_addr+(CyRDSR<<index));
1205 }else{ /* there is an open port for this data */
1206 tty = info->tty;
1207 j = (cy_readb(base_addr+(CyRIVR<<index)) & CyIVRMask);
1208 if ( j == CyIVRRxEx ) { /* exception */
1209 data = cy_readb(base_addr+(CyRDSR<<index));
1210 if(data & info->ignore_status_mask){
1211 continue;
1213 if (tty->flip.count < TTY_FLIPBUF_SIZE){
1214 tty->flip.count++;
1215 if (data & info->read_status_mask){
1216 if(data & CyBREAK){
1217 *tty->flip.flag_buf_ptr++ =
1218 TTY_BREAK;
1219 *tty->flip.char_buf_ptr++ =
1220 cy_readb(base_addr+(CyRDSR<<index));
1221 if (info->flags & ASYNC_SAK){
1222 do_SAK(tty);
1224 }else if(data & CyFRAME){
1225 *tty->flip.flag_buf_ptr++ =
1226 TTY_FRAME;
1227 *tty->flip.char_buf_ptr++ =
1228 cy_readb(base_addr+(CyRDSR<<index));
1229 info->idle_stats.frame_errs++;
1230 }else if(data & CyPARITY){
1231 *tty->flip.flag_buf_ptr++ =
1232 TTY_PARITY;
1233 *tty->flip.char_buf_ptr++ =
1234 cy_readb(base_addr+(CyRDSR<<index));
1235 info->idle_stats.parity_errs++;
1236 }else if(data & CyOVERRUN){
1237 *tty->flip.flag_buf_ptr++ =
1238 TTY_OVERRUN;
1239 *tty->flip.char_buf_ptr++ = 0;
1240 /* If the flip buffer itself is
1241 overflowing, we still loose
1242 the next incoming character.
1244 if(tty->flip.count
1245 < TTY_FLIPBUF_SIZE){
1246 tty->flip.count++;
1247 *tty->flip.flag_buf_ptr++ =
1248 TTY_NORMAL;
1249 *tty->flip.char_buf_ptr++ =
1250 cy_readb(base_addr+(CyRDSR<<index));
1252 info->idle_stats.overruns++;
1253 /* These two conditions may imply */
1254 /* a normal read should be done. */
1255 /* }else if(data & CyTIMEOUT){ */
1256 /* }else if(data & CySPECHAR){ */
1257 }else{
1258 *tty->flip.flag_buf_ptr++ = 0;
1259 *tty->flip.char_buf_ptr++ = 0;
1261 }else{
1262 *tty->flip.flag_buf_ptr++ = 0;
1263 *tty->flip.char_buf_ptr++ = 0;
1265 }else{
1266 /* there was a software buffer
1267 overrun and nothing could be
1268 done about it!!! */
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;
1281 #endif
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){
1286 break;
1288 tty->flip.count++;
1289 data = cy_readb(base_addr+(CyRDSR<<index));
1290 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
1291 *tty->flip.char_buf_ptr++ = data;
1292 #ifdef CY_16Y_HACK
1293 udelay(10L);
1294 #endif
1297 queue_task(&tty->flip.tqueue, &tq_timer);
1299 /* end of service */
1300 cy_writeb((u_long)base_addr+(CyRIR<<index), (save_xir & 0x3f));
1301 cy_writeb((u_long)base_addr+(CyCAR<<index), (save_car));
1305 if (status & CySRTransmit) { /* transmission interrupt */
1306 /* Since we only get here when the transmit buffer
1307 is empty, we know we can always stuff a dozen
1308 characters. */
1309 #ifdef CY_DEBUG_INTERRUPTS
1310 printk("cy_interrupt: xmit intr, chip %d\n\r", chip);
1311 #endif
1313 /* determine the channel & change to that context */
1314 save_xir = (u_char) cy_readb(base_addr+(CyTIR<<index));
1315 channel = (u_short ) (save_xir & CyIRChannel);
1316 i = channel + chip * 4 + cinfo->first_line;
1317 save_car = cy_readb(base_addr+(CyCAR<<index));
1318 cy_writeb((u_long)base_addr+(CyCAR<<index), save_xir);
1320 /* validate the port# (as configured and open) */
1321 if( (i < 0) || (NR_PORTS <= i) ){
1322 cy_writeb((u_long)base_addr+(CySRER<<index),
1323 cy_readb(base_addr+(CySRER<<index)) & ~CyTxMpty);
1324 goto txend;
1326 info = &cy_port[i];
1327 info->last_active = jiffies;
1328 if(info->tty == 0){
1329 cy_writeb((u_long)base_addr+(CySRER<<index),
1330 cy_readb(base_addr+(CySRER<<index)) & ~CyTxMpty);
1331 goto txdone;
1334 /* load the on-chip space for outbound data */
1335 char_count = info->xmit_fifo_size;
1338 if(info->x_char) { /* send special char */
1339 outch = info->x_char;
1340 cy_writeb((u_long)base_addr+(CyTDR<<index), outch);
1341 char_count--;
1342 info->x_char = 0;
1345 if (info->x_break){
1346 /* The Cirrus chip requires the "Embedded
1347 Transmit Commands" of start break, delay,
1348 and end break sequences to be sent. The
1349 duration of the break is given in TICs,
1350 which runs at HZ (typically 100) and the
1351 PPR runs at 200 Hz, so the delay is
1352 duration * 200/HZ, and thus a break can
1353 run from 1/100 sec to about 5/4 sec.
1354 For CD1400 J or later, replace the 200 Hz
1355 by 500 Hz.
1357 /* start break */
1358 cy_writeb((u_long)base_addr + (CyTDR<<index), 0);
1359 cy_writeb((u_long)base_addr + (CyTDR<<index), 0x81);
1360 /* delay a bit */
1361 cy_writeb((u_long)base_addr + (CyTDR<<index), 0);
1362 cy_writeb((u_long)base_addr + (CyTDR<<index), 0x82);
1363 if (info->chip_rev >= CD1400_REV_J ) {
1364 /* It is a CD1400 rev. J or later */
1365 cy_writeb((u_long)base_addr + (CyTDR<<index),
1366 info->x_break*500/HZ);
1367 } else {
1368 cy_writeb((u_long)base_addr + (CyTDR<<index),
1369 info->x_break*200/HZ);
1371 /* finish break */
1372 cy_writeb((u_long)base_addr + (CyTDR<<index), 0);
1373 cy_writeb((u_long)base_addr + (CyTDR<<index), 0x83);
1374 char_count -= 7;
1375 info->x_break = 0;
1378 while (char_count-- > 0){
1379 if (!info->xmit_cnt){
1380 cy_writeb((u_long)base_addr+(CySRER<<index),
1381 cy_readb(base_addr+(CySRER<<index)) &
1382 ~CyTxMpty);
1383 goto txdone;
1385 if (info->xmit_buf == 0){
1386 cy_writeb((u_long)base_addr+(CySRER<<index),
1387 cy_readb(base_addr+(CySRER<<index)) &
1388 ~CyTxMpty);
1389 goto txdone;
1391 if (info->tty->stopped || info->tty->hw_stopped){
1392 cy_writeb((u_long)base_addr+(CySRER<<index),
1393 cy_readb(base_addr+(CySRER<<index)) &
1394 ~CyTxMpty);
1395 goto txdone;
1397 /* Because the Embedded Transmit Commands have
1398 been enabled, we must check to see if the
1399 escape character, NULL, is being sent. If it
1400 is, we must ensure that there is room for it
1401 to be doubled in the output stream. Therefore
1402 we no longer advance the pointer when the
1403 character is fetched, but rather wait until
1404 after the check for a NULL output character.
1405 This is necessary because there may not be
1406 room for the two chars needed to send a NULL.)
1408 outch = info->xmit_buf[info->xmit_tail];
1409 if( outch ){
1410 info->xmit_cnt--;
1411 info->xmit_tail = (info->xmit_tail + 1)
1412 & (SERIAL_XMIT_SIZE - 1);
1413 cy_writeb((u_long)base_addr+(CyTDR<<index), outch);
1414 }else{
1415 if(char_count > 1){
1416 info->xmit_cnt--;
1417 info->xmit_tail = (info->xmit_tail + 1)
1418 & (SERIAL_XMIT_SIZE - 1);
1419 cy_writeb((u_long)base_addr+(CyTDR<<index),
1420 outch);
1421 cy_writeb((u_long)base_addr+(CyTDR<<index), 0);
1422 char_count--;
1423 }else{
1428 txdone:
1429 if (info->xmit_cnt < WAKEUP_CHARS) {
1430 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1432 txend:
1433 /* end of service */
1434 cy_writeb((u_long)base_addr+(CyTIR<<index),
1435 (save_xir & 0x3f));
1436 cy_writeb((u_long)base_addr+(CyCAR<<index), (save_car));
1439 if (status & CySRModem) { /* modem interrupt */
1441 /* determine the channel & change to that context */
1442 save_xir = (u_char) cy_readb(base_addr+(CyMIR<<index));
1443 channel = (u_short ) (save_xir & CyIRChannel);
1444 info = &cy_port[channel + chip * 4
1445 + cinfo->first_line];
1446 info->last_active = jiffies;
1447 save_car = cy_readb(base_addr+(CyCAR<<index));
1448 cy_writeb((u_long)base_addr+(CyCAR<<index), save_xir);
1450 mdm_change = cy_readb(base_addr+(CyMISR<<index));
1451 mdm_status = cy_readb(base_addr+(CyMSVR1<<index));
1453 if(info->tty == 0){/* no place for data, ignore it*/
1455 }else{
1456 if((mdm_change & CyDCD)
1457 && (info->flags & ASYNC_CHECK_CD)){
1458 if(mdm_status & CyDCD){
1459 cy_sched_event(info,
1460 Cy_EVENT_OPEN_WAKEUP);
1461 }else if(!((info->flags
1462 & ASYNC_CALLOUT_ACTIVE)
1463 &&(info->flags
1464 & ASYNC_CALLOUT_NOHUP))){
1465 cy_sched_event(info,
1466 Cy_EVENT_HANGUP);
1469 if((mdm_change & CyCTS)
1470 && (info->flags & ASYNC_CTS_FLOW)){
1471 if(info->tty->hw_stopped){
1472 if(mdm_status & CyCTS){
1473 /* cy_start isn't used
1474 because... !!! */
1475 info->tty->hw_stopped = 0;
1476 cy_writeb((u_long)base_addr+(CySRER<<index),
1477 cy_readb(base_addr+(CySRER<<index)) |
1478 CyTxMpty);
1479 cy_sched_event(info,
1480 Cy_EVENT_WRITE_WAKEUP);
1482 }else{
1483 if(!(mdm_status & CyCTS)){
1484 /* cy_stop isn't used
1485 because ... !!! */
1486 info->tty->hw_stopped = 1;
1487 cy_writeb((u_long)base_addr+(CySRER<<index),
1488 cy_readb(base_addr+(CySRER<<index)) &
1489 ~CyTxMpty);
1493 if(mdm_status & CyDSR){
1495 if(mdm_status & CyRI){
1498 /* end of service */
1499 cy_writeb((u_long)base_addr+(CyMIR<<index),
1500 (save_xir & 0x3f));
1501 cy_writeb((u_long)base_addr+(CyCAR<<index), save_car);
1503 } /* end while status != 0 */
1504 } /* end loop for chips... */
1505 } while(had_work);
1507 /* clear interrupts */
1508 cy_writeb((u_long)card_base_addr + (Cy_ClrIntr<<index), 0);
1509 /* Cy_ClrIntr is 0x1800 */
1510 } /* cyy_interrupt */
1512 /***********************************************************/
1513 /********* End of block of Cyclom-Y specific code **********/
1514 /******** Start of block of Cyclades-Z specific code *********/
1515 /***********************************************************/
1518 static int
1519 cyz_fetch_msg( struct cyclades_card *cinfo,
1520 uclong *channel, ucchar *cmd, uclong *param)
1522 struct FIRM_ID *firm_id;
1523 struct ZFW_CTRL *zfw_ctrl;
1524 struct BOARD_CTRL *board_ctrl;
1525 unsigned long loc_doorbell;
1527 firm_id = (struct FIRM_ID *)(cinfo->base_addr + ID_ADDRESS);
1528 if (!ISZLOADED(*cinfo)){
1529 return (-1);
1531 zfw_ctrl = (struct ZFW_CTRL *)
1532 (cinfo->base_addr + cy_readl(&firm_id->zfwctrl_addr));
1533 board_ctrl = &zfw_ctrl->board_ctrl;
1535 loc_doorbell = cy_readl(&((struct RUNTIME_9060 *)
1536 (cinfo->ctl_addr))->loc_doorbell);
1537 if (loc_doorbell){
1538 *cmd = (char)(0xff & loc_doorbell);
1539 *channel = cy_readl(&board_ctrl->fwcmd_channel);
1540 *param = (uclong)cy_readl(&board_ctrl->fwcmd_param);
1541 cy_writel(&((struct RUNTIME_9060 *)(cinfo->ctl_addr))->loc_doorbell,
1542 0xffffffff);
1543 return 1;
1545 return 0;
1546 } /* cyz_fetch_msg */
1549 static int
1550 cyz_issue_cmd( struct cyclades_card *cinfo,
1551 uclong channel, ucchar cmd, uclong param)
1553 struct FIRM_ID *firm_id;
1554 struct ZFW_CTRL *zfw_ctrl;
1555 struct BOARD_CTRL *board_ctrl;
1556 volatile uclong *pci_doorbell;
1557 int index;
1559 firm_id = (struct FIRM_ID *)(cinfo->base_addr + ID_ADDRESS);
1560 if (!ISZLOADED(*cinfo)){
1561 return (-1);
1563 zfw_ctrl = (struct ZFW_CTRL *)
1564 (cinfo->base_addr + cy_readl(&firm_id->zfwctrl_addr));
1565 board_ctrl = &zfw_ctrl->board_ctrl;
1567 index = 0;
1568 pci_doorbell = (uclong *)(&((struct RUNTIME_9060 *)
1569 (cinfo->ctl_addr))->pci_doorbell);
1570 while( (cy_readl(pci_doorbell) & 0xff) != 0){
1571 if (index++ == 1000){
1572 return(-1);
1574 udelay(50L);
1576 cy_writel((u_long)&board_ctrl->hcmd_channel, channel);
1577 cy_writel((u_long)&board_ctrl->hcmd_param , param);
1578 cy_writel((u_long)pci_doorbell, (long)cmd);
1580 return(0);
1581 } /* cyz_issue_cmd */
1584 #if 0
1585 static int
1586 cyz_update_channel( struct cyclades_card *cinfo,
1587 u_long channel, u_char mode, u_char cmd)
1589 struct FIRM_ID *firm_id =
1590 (struct FIRM_ID *)(cinfo->base_addr + ID_ADDRESS);
1591 struct ZFW_CTRL *zfw_ctrl;
1592 struct CH_CTRL *ch_ctrl;
1594 if (!ISZLOADED(*cinfo)){
1595 return (-1);
1597 zfw_ctrl = (struct ZFW_CTRL *)
1598 (cinfo->base_addr + cy_readl(&firm_id->zfwctrl_addr));
1599 ch_ctrl = zfw_ctrl->ch_ctrl;
1601 cy_writel(&ch_ctrl[channel].op_mode, (uclong)mode);
1603 return cyz_issue_cmd(cinfo, channel, cmd, 0L);
1605 } /* cyz_update_channel */
1606 #endif
1609 static void
1610 cyz_interrupt(int irq, void *dev_id, struct pt_regs *regs)
1612 } /* cyz_interrupt */
1615 static void
1616 cyz_poll(unsigned long arg)
1618 static volatile struct FIRM_ID *firm_id;
1619 static volatile struct ZFW_CTRL *zfw_ctrl;
1620 static volatile struct BOARD_CTRL *board_ctrl;
1621 static volatile struct CH_CTRL *ch_ctrl;
1622 static volatile struct BUF_CTRL *buf_ctrl;
1623 struct cyclades_card *cinfo;
1624 struct cyclades_port *info;
1625 struct tty_struct *tty;
1626 int card, port;
1627 int char_count;
1628 #ifdef BLOCKMOVE
1629 int small_count;
1630 #endif
1631 char data;
1632 uclong channel;
1633 ucchar cmd;
1634 uclong param;
1635 uclong hw_ver, fw_ver;
1636 volatile uclong tx_put, tx_get, tx_bufsize;
1637 volatile uclong rx_put, rx_get, rx_bufsize;
1639 cyz_timerlist.expires = jiffies + (HZ);
1640 for (card = 0 ; card < NR_CARDS ; card++){
1641 cinfo = &cy_card[card];
1642 if (!IS_CYC_Z(*cinfo)) continue;
1645 firm_id = (struct FIRM_ID *)(cinfo->base_addr + ID_ADDRESS);
1646 if (!ISZLOADED(*cinfo)) {
1647 cinfo->inact_ctrl = 0;
1648 continue;
1651 zfw_ctrl = (struct ZFW_CTRL *)
1652 (cinfo->base_addr + cy_readl(&firm_id->zfwctrl_addr));
1653 board_ctrl = &(zfw_ctrl->board_ctrl);
1654 fw_ver = cy_readl(&board_ctrl->fw_version);
1655 hw_ver = cy_readl(&((struct RUNTIME_9060 *)
1656 (cinfo->ctl_addr))->mail_box_0);
1658 /* Enables the firmware inactivity control */
1659 if ((fw_ver > 0x00000310L) && (!cinfo->inact_ctrl)) {
1660 param = cyz_issue_cmd( &cy_card[card], 0L, C_CM_TINACT, 0L);
1661 cinfo->inact_ctrl = 1;
1664 while(cyz_fetch_msg(cinfo, &channel, &cmd, &param) == 1){
1665 char_count = 0;
1666 info = &cy_port[ channel + cinfo->first_line ];
1667 if((tty = info->tty) == 0) continue;
1668 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
1669 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
1670 info->jiffies[0] = jiffies;
1672 switch(cmd){
1673 case C_CM_PR_ERROR:
1674 tty->flip.count++;
1675 *tty->flip.flag_buf_ptr++ = TTY_PARITY;
1676 *tty->flip.char_buf_ptr++ = 0;
1677 char_count++;
1678 break;
1679 case C_CM_FR_ERROR:
1680 tty->flip.count++;
1681 *tty->flip.flag_buf_ptr++ = TTY_FRAME;
1682 *tty->flip.char_buf_ptr++ = 0;
1683 char_count++;
1684 break;
1685 case C_CM_RXBRK:
1686 tty->flip.count++;
1687 *tty->flip.flag_buf_ptr++ = TTY_BREAK;
1688 *tty->flip.char_buf_ptr++ = 0;
1689 char_count++;
1690 break;
1691 case C_CM_MDCD:
1692 if (info->flags & ASYNC_CHECK_CD){
1693 if ((fw_ver > 241 ?
1694 ((u_long)param) :
1695 cy_readl(&ch_ctrl[channel].rs_status)) & C_RS_DCD) {
1696 cy_sched_event(info,
1697 Cy_EVENT_OPEN_WAKEUP);
1698 }else if(!((info->flags
1699 & ASYNC_CALLOUT_ACTIVE)
1700 &&(info->flags
1701 & ASYNC_CALLOUT_NOHUP))){
1702 cy_sched_event(info,
1703 Cy_EVENT_HANGUP);
1706 break;
1707 case C_CM_MCTS:
1708 if (info->flags & ASYNC_CTS_FLOW) {
1709 if(info->tty->hw_stopped){
1710 if( cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD){
1711 /* cy_start isn't used because...
1712 HW flow is handled by the board */
1713 cy_sched_event(info,
1714 Cy_EVENT_WRITE_WAKEUP);
1716 }else{
1717 if(!(cy_readl(&ch_ctrl[channel].rs_status) & C_RS_CTS)){
1718 /* cy_stop isn't used because
1719 HW flow is handled by the board */
1723 break;
1724 case C_CM_MRI:
1725 break;
1726 case C_CM_MDSR:
1727 break;
1728 #ifdef Z_WAKE
1729 case C_CM_IOCTLW:
1730 cy_sched_event(info, Cy_EVENT_SHUTDOWN_WAKEUP);
1731 break;
1732 #endif
1733 case C_CM_FATAL:
1734 /* should do something with this !!! */
1735 break;
1737 if(char_count){
1738 queue_task(&tty->flip.tqueue, &tq_timer);
1741 for (port = 0; port < cy_readl(&board_ctrl->n_channel); port++){
1742 info = &cy_port[ port + cinfo->first_line ];
1743 tty = info->tty;
1744 ch_ctrl = &(zfw_ctrl->ch_ctrl[port]);
1745 buf_ctrl = &(zfw_ctrl->buf_ctrl[port]);
1747 /* Removed due to compilation problems in Alpha systems */
1748 // if ((char_count = CHARS_IN_BUF(buf_ctrl))){
1750 rx_get = cy_readl(&buf_ctrl->rx_get);
1751 rx_put = cy_readl(&buf_ctrl->rx_put);
1752 rx_bufsize = cy_readl(&buf_ctrl->rx_bufsize);
1753 if (rx_put >= rx_get)
1754 char_count = rx_put - rx_get;
1755 else
1756 char_count = rx_put - rx_get + rx_bufsize;
1758 if ( char_count ){
1760 info->last_active = jiffies;
1761 info->jiffies[1] = jiffies;
1763 #ifdef CY_ENABLE_MONITORING
1764 info->mon.int_count++;
1765 info->mon.char_count += char_count;
1766 if (char_count > info->mon.char_max)
1767 info->mon.char_max = char_count;
1768 info->mon.char_last = char_count;
1769 #endif
1770 info->idle_stats.recv_bytes += char_count;
1771 info->idle_stats.recv_idle = jiffies;
1772 if( tty == 0){
1773 /* flush received characters */
1774 rx_get = (rx_get + char_count) & (rx_bufsize - 1);
1775 info->rflush_count++;
1776 }else{
1777 #ifdef BLOCKMOVE
1778 /* we'd like to use memcpy(t, f, n) and memset(s, c, count)
1779 for performance, but because of buffer boundaries, there
1780 may be several steps to the operation */
1781 while(0 < (small_count
1782 = cy_min((rx_bufsize - rx_get),
1783 cy_min((TTY_FLIPBUF_SIZE - tty->flip.count),
1784 char_count)))){
1786 memcpy_fromio(tty->flip.char_buf_ptr,
1787 (char *)(cinfo->base_addr
1788 + cy_readl(&buf_ctrl->rx_bufaddr)
1789 + rx_get),
1790 small_count);
1792 tty->flip.char_buf_ptr += small_count;
1793 memset(tty->flip.flag_buf_ptr,
1794 TTY_NORMAL,
1795 small_count);
1796 tty->flip.flag_buf_ptr += small_count;
1797 rx_get = (rx_get + small_count) & (rx_bufsize - 1);
1798 char_count -= small_count;
1799 tty->flip.count += small_count;
1801 #else
1802 while(char_count--){
1803 if (tty->flip.count >= TTY_FLIPBUF_SIZE){
1804 break;
1806 data = cy_readb(cinfo->base_addr +
1807 cy_readl(&buf_ctrl->rx_bufaddr) + rx_get);
1808 rx_get = (rx_get + 1) & (rx_bufsize - 1);
1809 tty->flip.count++;
1810 *tty->flip.flag_buf_ptr++ = TTY_NORMAL;
1811 *tty->flip.char_buf_ptr++ = data;
1813 #endif
1814 queue_task(&tty->flip.tqueue, &tq_timer);
1816 /* Update rx_get */
1817 cy_writel(&buf_ctrl->rx_get, rx_get);
1820 /* Removed due to compilation problems in Alpha systems */
1821 // if ((char_count = SPACE_IN_BUF(buf_ctrl))){
1823 tx_get = cy_readl(&buf_ctrl->tx_get);
1824 tx_put = cy_readl(&buf_ctrl->tx_put);
1825 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
1826 if (tx_put >= tx_get)
1827 char_count = tx_get - tx_put - 1 + tx_bufsize;
1828 else
1829 char_count = tx_get - tx_put - 1;
1831 if ( char_count ){
1833 if( tty == 0 ){
1834 goto ztxdone;
1837 if(info->x_char) { /* send special char */
1838 data = info->x_char;
1840 cy_writeb((cinfo->base_addr +
1841 cy_readl(&buf_ctrl->tx_bufaddr) + tx_put), data);
1842 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1843 info->x_char = 0;
1844 char_count--;
1845 info->last_active = jiffies;
1846 info->jiffies[2] = jiffies;
1848 if (info->x_break){
1849 printk("cyc cyz_poll shouldn't see x_break\n");
1850 info->x_break = 0;
1851 info->last_active = jiffies;
1852 info->jiffies[2] = jiffies;
1854 #ifdef BLOCKMOVE
1855 while(0 < (small_count
1856 = cy_min((tx_bufsize - tx_put),
1857 cy_min ((SERIAL_XMIT_SIZE - info->xmit_tail),
1858 cy_min(info->xmit_cnt, char_count))))){
1860 memcpy_toio((char *)(cinfo->base_addr
1861 + cy_readl(&buf_ctrl->tx_bufaddr) + tx_put),
1862 &info->xmit_buf[info->xmit_tail],
1863 small_count);
1865 tx_put = (tx_put + small_count) & (tx_bufsize - 1);
1866 char_count -= small_count;
1867 info->xmit_cnt -= small_count;
1868 info->xmit_tail =
1869 (info->xmit_tail + small_count) & (SERIAL_XMIT_SIZE - 1);
1870 info->last_active = jiffies;
1871 info->jiffies[2] = jiffies;
1873 #else
1874 while (info->xmit_cnt && char_count){
1875 data = info->xmit_buf[info->xmit_tail];
1876 info->xmit_cnt--;
1877 info->xmit_tail =
1878 (info->xmit_tail + 1) & (SERIAL_XMIT_SIZE - 1);
1880 cy_writeb(cinfo->base_addr +
1881 cy_readl(&buf_ctrl->tx_bufaddr) + tx_put,
1882 data);
1883 tx_put = (tx_put + 1) & (tx_bufsize - 1);
1884 char_count--;
1885 info->last_active = jiffies;
1886 info->jiffies[2] = jiffies;
1889 #endif
1890 ztxdone:
1891 if (info->xmit_cnt < WAKEUP_CHARS) {
1892 cy_sched_event(info, Cy_EVENT_WRITE_WAKEUP);
1894 /* Update tx_put */
1895 cy_writel(&buf_ctrl->tx_put, tx_put);
1898 /* poll every 40 ms */
1899 cyz_timerlist.expires = jiffies + cyz_polling_cycle;
1901 /* refresh inactivity counter */
1902 if (cinfo->inact_ctrl) {
1903 cy_writel(&board_ctrl->inactivity, (uclong) ZF_TINACT);
1906 add_timer(&cyz_timerlist);
1908 return;
1909 } /* cyz_poll */
1912 /********** End of block of Cyclades-Z specific code *********/
1913 /***********************************************************/
1916 /* This is called whenever a port becomes active;
1917 interrupts are enabled and DTR & RTS are turned on.
1919 static int
1920 startup(struct cyclades_port * info)
1922 unsigned long flags;
1923 unsigned char *base_addr;
1924 int card,chip,channel,index;
1926 if (info->flags & ASYNC_INITIALIZED){
1927 return 0;
1930 if (!info->type){
1931 if (info->tty){
1932 set_bit(TTY_IO_ERROR, &info->tty->flags);
1934 return 0;
1936 if (!info->xmit_buf){
1937 info->xmit_buf = (unsigned char *) get_free_page (GFP_KERNEL);
1938 if (!info->xmit_buf){
1939 return -ENOMEM;
1943 set_line_char(info);
1945 card = info->card;
1946 channel = (info->line) - (cy_card[card].first_line);
1947 if (!IS_CYC_Z(cy_card[card])) {
1948 chip = channel>>2;
1949 channel &= 0x03;
1950 index = cy_card[card].bus_index;
1951 base_addr = (unsigned char*)
1952 (cy_card[card].base_addr + (cy_chip_offset[chip]<<index));
1954 #ifdef CY_DEBUG_OPEN
1955 printk("cyc startup card %d, chip %d, channel %d, base_addr %lx\n",
1956 card, chip, channel, (long)base_addr);/**/
1957 #endif
1959 save_flags(flags); cli();
1960 cy_writeb((ulong)base_addr+(CyCAR<<index), (u_char)channel);
1962 cy_writeb((ulong)base_addr+(CyRTPR<<index), (info->default_timeout
1963 ? info->default_timeout
1964 : 0x02)); /* 10ms rx timeout */
1966 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyENB_RCVR|CyENB_XMTR,index);
1968 cy_writeb((ulong)base_addr+(CyCAR<<index), (u_char)channel);
1969 cy_writeb((ulong)base_addr+(CyMSVR1<<index), CyRTS);
1970 cy_writeb((ulong)base_addr+(CyMSVR2<<index), CyDTR);
1972 #ifdef CY_DEBUG_DTR
1973 printk("cyc:startup raising DTR\n");
1974 printk(" status: 0x%x, 0x%x\n",
1975 cy_readb(base_addr+(CyMSVR1<<index)),
1976 cy_readb(base_addr+(CyMSVR2<<index)));
1977 #endif
1979 cy_writeb((u_long)base_addr+(CySRER<<index),
1980 cy_readb(base_addr+(CySRER<<index)) | CyRxData);
1981 info->flags |= ASYNC_INITIALIZED;
1983 if (info->tty){
1984 clear_bit(TTY_IO_ERROR, &info->tty->flags);
1986 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
1987 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
1988 info->idle_stats.in_use =
1989 info->idle_stats.recv_idle =
1990 info->idle_stats.xmit_idle = jiffies;
1991 restore_flags(flags);
1992 } else {
1993 struct FIRM_ID *firm_id;
1994 struct ZFW_CTRL *zfw_ctrl;
1995 struct BOARD_CTRL *board_ctrl;
1996 struct CH_CTRL *ch_ctrl;
1997 int retval;
1999 base_addr = (unsigned char*) (cy_card[card].base_addr);
2001 firm_id = (struct FIRM_ID *) (base_addr + ID_ADDRESS);
2002 if (!ISZLOADED(cy_card[card])){
2003 return -ENODEV;
2006 zfw_ctrl =
2007 (struct ZFW_CTRL *)
2008 (cy_card[card].base_addr + cy_readl(&firm_id->zfwctrl_addr));
2009 board_ctrl = &zfw_ctrl->board_ctrl;
2010 ch_ctrl = zfw_ctrl->ch_ctrl;
2012 #ifdef CY_DEBUG_OPEN
2013 printk("cyc startup Z card %d, channel %d, base_addr %lx\n",
2014 card, channel, (long)base_addr);/**/
2015 #endif
2017 cy_writel(&ch_ctrl[channel].op_mode, C_CH_ENABLE);
2018 #ifdef Z_WAKE
2019 cy_writel(&ch_ctrl[channel].intr_enable,
2020 C_IN_MDCD|C_IN_MCTS|C_IN_IOCTLW);
2021 #else
2022 cy_writel(&ch_ctrl[channel].intr_enable,
2023 C_IN_MDCD|C_IN_MCTS);
2024 #endif
2025 retval = cyz_issue_cmd( &cy_card[card],
2026 channel, C_CM_IOCTL, 0L); /* was C_CM_RESET */
2027 if (retval != 0){
2028 printk("cyc:startup(1) retval was %x\n", retval);
2031 /* set timeout !!! */
2032 /* set RTS and DTR !!! */
2033 cy_writel(&ch_ctrl[channel].rs_control,
2034 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR) ;
2035 retval = cyz_issue_cmd(&cy_card[info->card],
2036 channel, C_CM_IOCTLM, 0L);
2037 if (retval != 0){
2038 printk("cyc:startup(2) retval was %x\n", retval);
2040 #ifdef CY_DEBUG_DTR
2041 printk("cyc:startup raising Z DTR\n");
2042 #endif
2044 /* enable send, recv, modem !!! */
2046 info->flags |= ASYNC_INITIALIZED;
2047 if (info->tty){
2048 clear_bit(TTY_IO_ERROR, &info->tty->flags);
2050 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
2052 memset((char *)&info->idle_stats, 0, sizeof(info->idle_stats));
2053 info->idle_stats.in_use =
2054 info->idle_stats.recv_idle =
2055 info->idle_stats.xmit_idle = jiffies;
2058 #ifdef CY_DEBUG_OPEN
2059 printk(" cyc startup done\n");
2060 #endif
2061 return 0;
2062 } /* startup */
2065 static void
2066 start_xmit( struct cyclades_port *info )
2068 unsigned long flags;
2069 unsigned char *base_addr;
2070 int card,chip,channel,index;
2072 card = info->card;
2073 channel = (info->line) - (cy_card[card].first_line);
2074 if (!IS_CYC_Z(cy_card[card])) {
2075 chip = channel>>2;
2076 channel &= 0x03;
2077 index = cy_card[card].bus_index;
2078 base_addr = (unsigned char*)
2079 (cy_card[card].base_addr
2080 + (cy_chip_offset[chip]<<index));
2082 save_flags(flags); cli();
2083 cy_writeb((u_long)base_addr+(CyCAR<<index), channel);
2084 cy_writeb((u_long)base_addr+(CySRER<<index),
2085 cy_readb(base_addr+(CySRER<<index)) | CyTxMpty);
2086 restore_flags(flags);
2087 } else {
2088 /* Don't have to do anything at this time */
2090 } /* start_xmit */
2094 * This routine shuts down a serial port; interrupts are disabled,
2095 * and DTR is dropped if the hangup on close termio flag is on.
2097 static void
2098 shutdown(struct cyclades_port * info)
2100 unsigned long flags;
2101 unsigned char *base_addr;
2102 int card,chip,channel,index;
2104 if (!(info->flags & ASYNC_INITIALIZED)){
2105 return;
2108 card = info->card;
2109 channel = info->line - cy_card[card].first_line;
2110 if (!IS_CYC_Z(cy_card[card])) {
2111 chip = channel>>2;
2112 channel &= 0x03;
2113 index = cy_card[card].bus_index;
2114 base_addr = (unsigned char*)
2115 (cy_card[card].base_addr
2116 + (cy_chip_offset[chip]<<index));
2118 #ifdef CY_DEBUG_OPEN
2119 printk("cyc shutdown Y card %d, chip %d, channel %d, base_addr %lx\n",
2120 card, chip, channel, (long)base_addr);
2121 #endif
2123 save_flags(flags); cli();
2125 if (info->xmit_buf){
2126 unsigned char * temp;
2127 temp = info->xmit_buf;
2128 info->xmit_buf = 0;
2129 free_page((unsigned long) temp);
2131 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
2132 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2133 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
2134 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
2135 #ifdef CY_DEBUG_DTR
2136 printk("cyc shutdown dropping DTR\n");
2137 printk(" status: 0x%x, 0x%x\n",
2138 cy_readb(base_addr+(CyMSVR1<<index)),
2139 cy_readb(base_addr+(CyMSVR2<<index)));
2140 #endif
2142 cyy_issue_cmd(base_addr,CyCHAN_CTL|CyDIS_RCVR,index);
2143 /* it may be appropriate to clear _XMIT at
2144 some later date (after testing)!!! */
2146 if (info->tty){
2147 set_bit(TTY_IO_ERROR, &info->tty->flags);
2149 info->flags &= ~ASYNC_INITIALIZED;
2150 restore_flags(flags);
2151 } else {
2152 struct FIRM_ID *firm_id;
2153 struct ZFW_CTRL *zfw_ctrl;
2154 struct BOARD_CTRL *board_ctrl;
2155 struct CH_CTRL *ch_ctrl;
2156 int retval;
2158 base_addr = (unsigned char*) (cy_card[card].base_addr);
2159 #ifdef CY_DEBUG_OPEN
2160 printk("cyc shutdown Z card %d, channel %d, base_addr %lx\n",
2161 card, channel, (long)base_addr);
2162 #endif
2164 firm_id = (struct FIRM_ID *) (base_addr + ID_ADDRESS);
2165 if (!ISZLOADED(cy_card[card])) {
2166 return;
2169 zfw_ctrl =
2170 (struct ZFW_CTRL *)
2171 (cy_card[card].base_addr + cy_readl(&firm_id->zfwctrl_addr));
2172 board_ctrl = &(zfw_ctrl->board_ctrl);
2173 ch_ctrl = zfw_ctrl->ch_ctrl;
2175 save_flags(flags); cli();
2177 if (info->xmit_buf){
2178 unsigned char * temp;
2179 temp = info->xmit_buf;
2180 info->xmit_buf = 0;
2181 free_page((unsigned long) temp);
2184 if (!info->tty || (info->tty->termios->c_cflag & HUPCL)) {
2185 cy_writel((u_long)&ch_ctrl[channel].rs_control,
2186 (uclong)(cy_readl(&ch_ctrl[channel].rs_control) &
2187 ~(C_RS_RTS | C_RS_DTR)));
2188 retval = cyz_issue_cmd(&cy_card[info->card],
2189 channel, C_CM_IOCTLM, 0L);
2190 if (retval != 0){
2191 printk("cyc:shutdown retval (2) was %x\n", retval);
2193 #ifdef CY_DEBUG_DTR
2194 printk("cyc:shutdown dropping Z DTR\n");
2195 #endif
2198 if (info->tty){
2199 set_bit(TTY_IO_ERROR, &info->tty->flags);
2201 info->flags &= ~ASYNC_INITIALIZED;
2203 restore_flags(flags);
2206 #ifdef CY_DEBUG_OPEN
2207 printk(" cyc shutdown done\n");
2208 #endif
2209 return;
2210 } /* shutdown */
2214 * ------------------------------------------------------------
2215 * cy_open() and friends
2216 * ------------------------------------------------------------
2219 static int
2220 block_til_ready(struct tty_struct *tty, struct file * filp,
2221 struct cyclades_port *info)
2223 struct wait_queue wait = { current, NULL };
2224 struct cyclades_card *cinfo;
2225 unsigned long flags;
2226 int chip, channel,index;
2227 int retval;
2228 char *base_addr;
2231 * If the device is in the middle of being closed, then block
2232 * until it's done, and then try again.
2234 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2235 if (info->flags & ASYNC_CLOSING) {
2236 interruptible_sleep_on(&info->close_wait);
2238 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
2242 * If this is a callout device, then just make sure the normal
2243 * device isn't being used.
2245 if (tty->driver.subtype == SERIAL_TYPE_CALLOUT) {
2246 if (info->flags & ASYNC_NORMAL_ACTIVE){
2247 return -EBUSY;
2249 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2250 (info->flags & ASYNC_SESSION_LOCKOUT) &&
2251 (info->session != current->session)){
2252 return -EBUSY;
2254 if ((info->flags & ASYNC_CALLOUT_ACTIVE) &&
2255 (info->flags & ASYNC_PGRP_LOCKOUT) &&
2256 (info->pgrp != current->pgrp)){
2257 return -EBUSY;
2259 info->flags |= ASYNC_CALLOUT_ACTIVE;
2260 return 0;
2264 * If non-blocking mode is set, then make the check up front
2265 * and then exit.
2267 if ((filp->f_flags & O_NONBLOCK) ||
2268 (tty->flags & (1 << TTY_IO_ERROR))) {
2269 if (info->flags & ASYNC_CALLOUT_ACTIVE){
2270 return -EBUSY;
2272 info->flags |= ASYNC_NORMAL_ACTIVE;
2273 return 0;
2277 * Block waiting for the carrier detect and the line to become
2278 * free (i.e., not in use by the callout). While we are in
2279 * this loop, info->count is dropped by one, so that
2280 * cy_close() knows when to free things. We restore it upon
2281 * exit, either normal or abnormal.
2283 retval = 0;
2284 add_wait_queue(&info->open_wait, &wait);
2285 #ifdef CY_DEBUG_OPEN
2286 printk("cyc block_til_ready before block: ttyC%d, count = %d\n",
2287 info->line, info->count);/**/
2288 #endif
2289 save_flags(flags); cli();
2290 if (!tty_hung_up_p(filp))
2291 info->count--;
2292 restore_flags(flags);
2293 #ifdef CY_DEBUG_COUNT
2294 printk("cyc block_til_ready: (%d): decrementing count to %d\n",
2295 current->pid, info->count);
2296 #endif
2297 info->blocked_open++;
2299 cinfo = &cy_card[info->card];
2300 channel = info->line - cinfo->first_line;
2301 if (!IS_CYC_Z(*cinfo)) {
2302 chip = channel>>2;
2303 channel &= 0x03;
2304 index = cinfo->bus_index;
2305 base_addr = (char *)(cinfo->base_addr
2306 + (cy_chip_offset[chip]<<index));
2308 while (1) {
2309 save_flags(flags); cli();
2310 if (!(info->flags & ASYNC_CALLOUT_ACTIVE) &&
2311 (tty->termios->c_cflag & CBAUD)){
2312 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
2313 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
2314 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
2315 #ifdef CY_DEBUG_DTR
2316 printk("cyc:block_til_ready raising DTR\n");
2317 printk(" status: 0x%x, 0x%x\n",
2318 cy_readb(base_addr+(CyMSVR1<<index)),
2319 cy_readb(base_addr+(CyMSVR2<<index)));
2320 #endif
2322 restore_flags(flags);
2323 current->state = TASK_INTERRUPTIBLE;
2324 if (tty_hung_up_p(filp)
2325 || !(info->flags & ASYNC_INITIALIZED) ){
2326 return ((info->flags & ASYNC_HUP_NOTIFY) ?
2327 -EAGAIN : -ERESTARTSYS);
2328 break;
2330 save_flags(flags); cli();
2331 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
2332 if (!(info->flags & ASYNC_CALLOUT_ACTIVE)
2333 && !(info->flags & ASYNC_CLOSING)
2334 && (C_CLOCAL(tty)
2335 || (cy_readb(base_addr+(CyMSVR1<<index)) & CyDCD))) {
2336 restore_flags(flags);
2337 break;
2339 restore_flags(flags);
2340 if (signal_pending(current)) {
2341 retval = -ERESTARTSYS;
2342 break;
2344 #ifdef CY_DEBUG_OPEN
2345 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2346 info->line, info->count);/**/
2347 #endif
2348 schedule();
2350 } else {
2351 struct FIRM_ID *firm_id;
2352 struct ZFW_CTRL *zfw_ctrl;
2353 struct BOARD_CTRL *board_ctrl;
2354 struct CH_CTRL *ch_ctrl;
2355 int retval;
2357 base_addr = (char *)(cinfo->base_addr);
2358 firm_id = (struct FIRM_ID *)
2359 (base_addr + ID_ADDRESS);
2360 if (!ISZLOADED(*cinfo)){
2361 return -EINVAL;
2364 zfw_ctrl =
2365 (struct ZFW_CTRL *)
2366 (base_addr + cy_readl(&firm_id->zfwctrl_addr));
2367 board_ctrl = &zfw_ctrl->board_ctrl;
2368 ch_ctrl = zfw_ctrl->ch_ctrl;
2370 while (1) {
2371 cy_writel(&ch_ctrl[channel].rs_control,
2372 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS | C_RS_DTR);
2373 retval = cyz_issue_cmd(&cy_card[info->card],
2374 channel, C_CM_IOCTLM, 0L);
2375 if (retval != 0){
2376 printk("cyc:block_til_ready retval was %x\n", retval);
2378 #ifdef CY_DEBUG_DTR
2379 printk("cyc:block_til_ready raising Z DTR\n");
2380 #endif
2382 current->state = TASK_INTERRUPTIBLE;
2383 if (tty_hung_up_p(filp)
2384 || !(info->flags & ASYNC_INITIALIZED) ){
2385 return ((info->flags & ASYNC_HUP_NOTIFY) ?
2386 -EAGAIN : -ERESTARTSYS);
2387 break;
2389 if (!(info->flags & ASYNC_CALLOUT_ACTIVE)
2390 && !(info->flags & ASYNC_CLOSING)
2391 && (C_CLOCAL(tty)
2392 || (cy_readl(&ch_ctrl[channel].rs_status) & C_RS_DCD))) {
2393 break;
2395 if (signal_pending(current)) {
2396 retval = -ERESTARTSYS;
2397 break;
2399 #ifdef CY_DEBUG_OPEN
2400 printk("cyc block_til_ready blocking: ttyC%d, count = %d\n",
2401 info->line, info->count);/**/
2402 #endif
2403 schedule();
2406 current->state = TASK_RUNNING;
2407 remove_wait_queue(&info->open_wait, &wait);
2408 if (!tty_hung_up_p(filp)){
2409 info->count++;
2410 #ifdef CY_DEBUG_COUNT
2411 printk("cyc:block_til_ready (%d): incrementing count to %d\n",
2412 current->pid, info->count);
2413 #endif
2415 info->blocked_open--;
2416 #ifdef CY_DEBUG_OPEN
2417 printk("cyc:block_til_ready after blocking: ttyC%d, count = %d\n",
2418 info->line, info->count);/**/
2419 #endif
2420 if (retval)
2421 return retval;
2422 info->flags |= ASYNC_NORMAL_ACTIVE;
2423 return 0;
2424 } /* block_til_ready */
2428 * This routine is called whenever a serial port is opened. It
2429 * performs the serial-specific initialization for the tty structure.
2431 static int
2432 cy_open(struct tty_struct *tty, struct file * filp)
2434 struct cyclades_port *info;
2435 int retval, line;
2436 unsigned long page;
2438 line = MINOR(tty->device) - tty->driver.minor_start;
2439 if ((line < 0) || (NR_PORTS <= line)){
2440 return -ENODEV;
2442 info = &cy_port[line];
2443 if (info->line < 0){
2444 return -ENODEV;
2447 /* If the card's firmware hasn't been loaded,
2448 treat it as absent from the system. This
2449 will make the user pay attention.
2451 if (IS_CYC_Z(cy_card[info->card])) {
2452 if (!ISZLOADED(cy_card[info->card])) {
2453 if (((ZE_V1 ==cy_readl(&((struct RUNTIME_9060 *)
2454 ((cy_card[info->card]).ctl_addr))->mail_box_0)) &&
2455 Z_FPGA_CHECK(cy_card[info->card])) &&
2456 (ZFIRM_HLT==cy_readl(&((struct FIRM_ID *)
2457 ((cy_card[info->card]).base_addr+ID_ADDRESS))->signature)))
2459 printk ("cyc:Cyclades-Z Error: you need an external power supply for this number of ports.\n\rFirmware halted.\r\n");
2460 } else {
2461 printk("cyc:Cyclades-Z firmware not yet loaded\n");
2463 return -ENODEV;
2466 #ifdef CY_DEBUG_OTHER
2467 printk("cyc:cy_open ttyC%d\n", info->line); /* */
2468 #endif
2469 if (serial_paranoia_check(info, tty->device, "cy_open")){
2470 return -ENODEV;
2472 #ifdef CY_DEBUG_OPEN
2473 printk("cyc:cy_open ttyC%d, count = %d\n",
2474 info->line, info->count);/**/
2475 #endif
2476 info->count++;
2477 #ifdef CY_DEBUG_COUNT
2478 printk("cyc:cy_open (%d): incrementing count to %d\n",
2479 current->pid, info->count);
2480 #endif
2481 tty->driver_data = info;
2482 info->tty = tty;
2484 if (!tmp_buf) {
2485 page = get_free_page(GFP_KERNEL);
2486 if (!page)
2487 return -ENOMEM;
2488 if (tmp_buf)
2489 free_page(page);
2490 else
2491 tmp_buf = (unsigned char *) page;
2495 * If the port is the middle of closing, bail out now
2497 if (tty_hung_up_p(filp) || (info->flags & ASYNC_CLOSING)) {
2498 if (info->flags & ASYNC_CLOSING)
2499 interruptible_sleep_on(&info->close_wait);
2500 return ((info->flags & ASYNC_HUP_NOTIFY) ? -EAGAIN : -ERESTARTSYS);
2504 * Start up serial port
2506 retval = startup(info);
2507 if (retval){
2508 return retval;
2511 MOD_INC_USE_COUNT;
2513 retval = block_til_ready(tty, filp, info);
2514 if (retval) {
2515 #ifdef CY_DEBUG_OPEN
2516 printk("cyc:cy_open returning after block_til_ready with %d\n",
2517 retval);
2518 #endif
2519 return retval;
2522 if ((info->count == 1) && (info->flags & ASYNC_SPLIT_TERMIOS)) {
2523 if (tty->driver.subtype == SERIAL_TYPE_NORMAL)
2524 *tty->termios = info->normal_termios;
2525 else
2526 *tty->termios = info->callout_termios;
2529 info->session = current->session;
2530 info->pgrp = current->pgrp;
2532 #ifdef CY_DEBUG_OPEN
2533 printk(" cyc:cy_open done\n");/**/
2534 #endif
2536 return 0;
2537 } /* cy_open */
2541 * cy_wait_until_sent() --- wait until the transmitter is empty
2543 static void cy_wait_until_sent(struct tty_struct *tty, int timeout)
2545 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
2546 unsigned char *base_addr;
2547 int card,chip,channel,index;
2548 unsigned long orig_jiffies, char_time;
2550 if (serial_paranoia_check(info, tty->device, "cy_wait_until_sent"))
2551 return;
2553 orig_jiffies = jiffies;
2555 * Set the check interval to be 1/5 of the estimated time to
2556 * send a single character, and make it at least 1. The check
2557 * interval should also be less than the timeout.
2559 * Note: we have to use pretty tight timings here to satisfy
2560 * the NIST-PCTS.
2562 char_time = (info->timeout - HZ/50) / info->xmit_fifo_size;
2563 char_time = char_time / 5;
2564 if (char_time == 0)
2565 char_time = 1;
2566 if (timeout < 0)
2567 timeout = 0;
2568 if (timeout)
2569 char_time = MIN(char_time, timeout);
2570 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2571 printk("In cy_wait_until_sent(%d) check=%lu...", timeout, char_time);
2572 printk("jiff=%lu...", jiffies);
2573 #endif
2574 card = info->card;
2575 channel = (info->line) - (cy_card[card].first_line);
2576 if (!IS_CYC_Z(cy_card[card])) {
2577 chip = channel>>2;
2578 channel &= 0x03;
2579 index = cy_card[card].bus_index;
2580 base_addr = (unsigned char *)
2581 (cy_card[card].base_addr + (cy_chip_offset[chip]<<index));
2582 while (cy_readb(base_addr+(CySRER<<index)) & CyTxMpty) {
2583 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2584 printk("Not clean (jiff=%lu)...", jiffies);
2585 #endif
2586 current->state = TASK_INTERRUPTIBLE;
2587 current->counter = 0; /* make us low-priority */
2588 current->timeout = jiffies + char_time;
2589 schedule();
2590 if (signal_pending(current))
2591 break;
2592 if (timeout && ((orig_jiffies + timeout) < jiffies))
2593 break;
2595 current->state = TASK_RUNNING;
2596 } else {
2597 // Nothing to do!
2599 /* Run one more char cycle */
2600 current->state = TASK_INTERRUPTIBLE;
2601 current->counter = 0; /* make us low-priority */
2602 current->timeout = jiffies + (char_time * 5);
2603 schedule();
2604 current->state = TASK_RUNNING;
2605 #ifdef CY_DEBUG_WAIT_UNTIL_SENT
2606 printk("Clean (jiff=%lu)...done\n", jiffies);
2607 #endif
2611 * This routine is called when a particular tty device is closed.
2613 static void
2614 cy_close(struct tty_struct * tty, struct file * filp)
2616 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
2617 unsigned long flags;
2619 #ifdef CY_DEBUG_OTHER
2620 printk("cyc:cy_close ttyC%d\n", info->line);
2621 #endif
2623 if (!info
2624 || serial_paranoia_check(info, tty->device, "cy_close")){
2625 return;
2627 #ifdef CY_DEBUG_OPEN
2628 printk("cyc:cy_close ttyC%d, count = %d\n", info->line, info->count);
2629 #endif
2631 save_flags(flags); cli();
2633 /* If the TTY is being hung up, nothing to do */
2634 if (tty_hung_up_p(filp)) {
2635 MOD_DEC_USE_COUNT;
2636 restore_flags(flags);
2637 return;
2640 if ((tty->count == 1) && (info->count != 1)) {
2642 * Uh, oh. tty->count is 1, which means that the tty
2643 * structure will be freed. Info->count should always
2644 * be one in these conditions. If it's greater than
2645 * one, we've got real problems, since it means the
2646 * serial port won't be shutdown.
2648 printk("cyc:cy_close: bad serial port count; tty->count is 1, "
2649 "info->count is %d\n", info->count);
2650 info->count = 1;
2652 #ifdef CY_DEBUG_COUNT
2653 printk("cyc:cy_close at (%d): decrementing count to %d\n",
2654 current->pid, info->count - 1);
2655 #endif
2656 if (--info->count < 0) {
2657 #ifdef CY_DEBUG_COUNT
2658 printk("cyc:cyc_close setting count to 0\n");
2659 #endif
2660 info->count = 0;
2662 if (info->count) {
2663 MOD_DEC_USE_COUNT;
2664 restore_flags(flags);
2665 return;
2667 info->flags |= ASYNC_CLOSING;
2669 * Save the termios structure, since this port may have
2670 * separate termios for callout and dialin.
2672 if (info->flags & ASYNC_NORMAL_ACTIVE)
2673 info->normal_termios = *tty->termios;
2674 if (info->flags & ASYNC_CALLOUT_ACTIVE)
2675 info->callout_termios = *tty->termios;
2678 * Now we wait for the transmit buffer to clear; and we notify
2679 * the line discipline to only process XON/XOFF characters.
2681 tty->closing = 1;
2682 if (info->closing_wait != CY_CLOSING_WAIT_NONE) {
2683 tty_wait_until_sent(tty, info->closing_wait);
2686 if (!IS_CYC_Z(cy_card[info->card])) {
2687 int channel = info->line - cy_card[info->card].first_line;
2688 int index = cy_card[info->card].bus_index;
2689 unsigned char *base_addr = (unsigned char *)
2690 (cy_card[info->card].base_addr +
2691 (cy_chip_offset[channel>>2] <<index));
2692 /* Stop accepting input */
2693 cy_writeb((u_long)base_addr+(CySRER<<index),
2694 cy_readb(base_addr+(CySRER<<index)) & ~CyRxData);
2695 if (info->flags & ASYNC_INITIALIZED) {
2696 /* Waiting for on-board buffers to be empty before closing
2697 the port */
2698 cy_wait_until_sent(tty, info->timeout);
2700 } else {
2701 #ifdef Z_WAKE
2702 /* Waiting for on-board buffers to be empty before closing the port */
2703 unsigned char *base_addr = (unsigned char *)
2704 cy_card[info->card].base_addr;
2705 struct FIRM_ID *firm_id = (struct FIRM_ID *) (base_addr + ID_ADDRESS);
2706 struct ZFW_CTRL *zfw_ctrl =
2707 (struct ZFW_CTRL *) (base_addr + cy_readl(&firm_id->zfwctrl_addr));
2708 struct CH_CTRL *ch_ctrl = zfw_ctrl->ch_ctrl;
2709 int channel = info->line - cy_card[info->card].first_line;
2710 int retval;
2712 if (cy_readl(&ch_ctrl[channel].flow_status) != C_FS_TXIDLE) {
2713 retval = cyz_issue_cmd(&cy_card[info->card], channel,
2714 C_CM_IOCTLW, 0L);
2715 if (retval != 0){
2716 printk("cyc:shutdown retval (1) was %x\n", retval);
2718 interruptible_sleep_on(&info->shutdown_wait);
2720 #endif
2723 shutdown(info);
2724 if (tty->driver.flush_buffer)
2725 tty->driver.flush_buffer(tty);
2726 if (tty->ldisc.flush_buffer)
2727 tty->ldisc.flush_buffer(tty);
2728 info->event = 0;
2729 info->tty = 0;
2730 if (info->blocked_open) {
2731 if (info->close_delay) {
2732 current->state = TASK_INTERRUPTIBLE;
2733 current->timeout = jiffies + info->close_delay;
2734 schedule();
2736 wake_up_interruptible(&info->open_wait);
2738 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE|
2739 ASYNC_CLOSING);
2740 wake_up_interruptible(&info->close_wait);
2742 #ifdef CY_DEBUG_OTHER
2743 printk(" cyc:cy_close done\n");
2744 #endif
2746 MOD_DEC_USE_COUNT;
2747 restore_flags(flags);
2748 return;
2749 } /* cy_close */
2752 /* This routine gets called when tty_write has put something into
2753 * the write_queue. The characters may come from user space or
2754 * kernel space.
2756 * This routine will return the number of characters actually
2757 * accepted for writing.
2759 * If the port is not already transmitting stuff, start it off by
2760 * enabling interrupts. The interrupt service routine will then
2761 * ensure that the characters are sent.
2762 * If the port is already active, there is no need to kick it.
2765 static int
2766 cy_write(struct tty_struct * tty, int from_user,
2767 const unsigned char *buf, int count)
2769 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2770 unsigned long flags;
2771 int c, ret = 0;
2773 #ifdef CY_DEBUG_IO
2774 printk("cyc:cy_write ttyC%d\n", info->line); /* */
2775 #endif
2777 if (serial_paranoia_check(info, tty->device, "cy_write")){
2778 return 0;
2781 if (!tty || !info->xmit_buf || !tmp_buf){
2782 return 0;
2785 save_flags(flags);
2787 if (from_user) {
2788 down(&tmp_buf_sem);
2789 while (1) {
2790 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
2791 SERIAL_XMIT_SIZE - info->xmit_head));
2792 if (c <= 0)
2793 break;
2795 c -= copy_from_user(tmp_buf, buf, c);
2796 if (!c) {
2797 if (!ret) {
2798 ret = -EFAULT;
2800 break;
2802 cli();
2803 c = MIN(c, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
2804 SERIAL_XMIT_SIZE - info->xmit_head));
2805 memcpy(info->xmit_buf + info->xmit_head, tmp_buf, c);
2806 info->xmit_head = ((info->xmit_head + c) & (SERIAL_XMIT_SIZE-1));
2807 info->xmit_cnt += c;
2808 restore_flags(flags);
2809 buf += c;
2810 count -= c;
2811 ret += c;
2813 up(&tmp_buf_sem);
2814 } else {
2815 while (1) {
2816 cli();
2817 c = MIN(count, MIN(SERIAL_XMIT_SIZE - info->xmit_cnt - 1,
2818 SERIAL_XMIT_SIZE - info->xmit_head));
2819 if (c <= 0) {
2820 restore_flags(flags);
2821 break;
2823 memcpy(info->xmit_buf + info->xmit_head, buf, c);
2824 info->xmit_head = (info->xmit_head + c) & (SERIAL_XMIT_SIZE-1);
2825 info->xmit_cnt += c;
2826 restore_flags(flags);
2827 buf += c;
2828 count -= c;
2829 ret += c;
2833 info->idle_stats.xmit_bytes += ret;
2834 info->idle_stats.xmit_idle = jiffies;
2836 if (info->xmit_cnt && !tty->stopped && !tty->hw_stopped) {
2837 start_xmit(info);
2839 return ret;
2840 } /* cy_write */
2844 * This routine is called by the kernel to write a single
2845 * character to the tty device. If the kernel uses this routine,
2846 * it must call the flush_chars() routine (if defined) when it is
2847 * done stuffing characters into the driver. If there is no room
2848 * in the queue, the character is ignored.
2850 static void
2851 cy_put_char(struct tty_struct *tty, unsigned char ch)
2853 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2854 unsigned long flags;
2856 #ifdef CY_DEBUG_IO
2857 printk("cyc:cy_put_char ttyC%d\n", info->line);
2858 #endif
2860 if (serial_paranoia_check(info, tty->device, "cy_put_char"))
2861 return;
2863 if (!tty || !info->xmit_buf)
2864 return;
2866 save_flags(flags); cli();
2867 if (info->xmit_cnt >= SERIAL_XMIT_SIZE - 1) {
2868 restore_flags(flags);
2869 return;
2872 info->xmit_buf[info->xmit_head++] = ch;
2873 info->xmit_head &= SERIAL_XMIT_SIZE - 1;
2874 info->xmit_cnt++;
2875 info->idle_stats.xmit_bytes++;
2876 info->idle_stats.xmit_idle = jiffies;
2877 restore_flags(flags);
2878 } /* cy_put_char */
2882 * This routine is called by the kernel after it has written a
2883 * series of characters to the tty device using put_char().
2885 static void
2886 cy_flush_chars(struct tty_struct *tty)
2888 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2889 unsigned long flags;
2890 unsigned char *base_addr;
2891 int card,chip,channel,index;
2893 #ifdef CY_DEBUG_IO
2894 printk("cyc:cy_flush_chars ttyC%d\n", info->line); /* */
2895 #endif
2897 if (serial_paranoia_check(info, tty->device, "cy_flush_chars"))
2898 return;
2900 if (info->xmit_cnt <= 0 || tty->stopped
2901 || tty->hw_stopped || !info->xmit_buf)
2902 return;
2904 card = info->card;
2905 channel = info->line - cy_card[card].first_line;
2906 if (!IS_CYC_Z(cy_card[card])) {
2907 chip = channel>>2;
2908 channel &= 0x03;
2909 index = cy_card[card].bus_index;
2910 base_addr = (unsigned char*)
2911 (cy_card[card].base_addr
2912 + (cy_chip_offset[chip]<<index));
2914 save_flags(flags); cli();
2915 cy_writeb((u_long)base_addr+(CyCAR<<index), channel);
2916 cy_writeb((u_long)base_addr+(CySRER<<index),
2917 cy_readb(base_addr+(CySRER<<index)) | CyTxMpty);
2918 restore_flags(flags);
2919 } else {
2920 /* Since polling is already in place,
2921 nothing further need be done. */
2923 } /* cy_flush_chars */
2927 * This routine returns the numbers of characters the tty driver
2928 * will accept for queuing to be written. This number is subject
2929 * to change as output buffers get emptied, or if the output flow
2930 * control is activated.
2932 static int
2933 cy_write_room(struct tty_struct *tty)
2935 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2936 int ret;
2938 #ifdef CY_DEBUG_IO
2939 printk("cyc:cy_write_room ttyC%d\n", info->line); /* */
2940 #endif
2942 if (serial_paranoia_check(info, tty->device, "cy_write_room"))
2943 return 0;
2944 ret = SERIAL_XMIT_SIZE - info->xmit_cnt - 1;
2945 if (ret < 0)
2946 ret = 0;
2947 return ret;
2948 } /* cy_write_room */
2951 static int
2952 cy_chars_in_buffer(struct tty_struct *tty)
2954 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
2955 int card, channel;
2957 if (serial_paranoia_check(info, tty->device, "cy_chars_in_buffer"))
2958 return 0;
2960 card = info->card;
2961 channel = (info->line) - (cy_card[card].first_line);
2963 if (!IS_CYC_Z(cy_card[card])) {
2964 #ifdef CY_DEBUG_IO
2965 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2966 info->line, info->xmit_cnt); /* */
2967 #endif
2968 return info->xmit_cnt;
2969 } else {
2970 static volatile struct FIRM_ID *firm_id;
2971 static volatile struct ZFW_CTRL *zfw_ctrl;
2972 static volatile struct CH_CTRL *ch_ctrl;
2973 static volatile struct BUF_CTRL *buf_ctrl;
2974 int char_count;
2975 volatile uclong tx_put, tx_get, tx_bufsize;
2977 firm_id = (struct FIRM_ID *)(cy_card[card].base_addr + ID_ADDRESS);
2978 zfw_ctrl = (struct ZFW_CTRL *) (cy_card[card].base_addr +
2979 cy_readl(&firm_id->zfwctrl_addr));
2980 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
2981 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
2983 tx_get = cy_readl(&buf_ctrl->tx_get);
2984 tx_put = cy_readl(&buf_ctrl->tx_put);
2985 tx_bufsize = cy_readl(&buf_ctrl->tx_bufsize);
2986 if (tx_put >= tx_get)
2987 char_count = tx_put - tx_get;
2988 else
2989 char_count = tx_put - tx_get + tx_bufsize;
2990 #ifdef CY_DEBUG_IO
2991 printk("cyc:cy_chars_in_buffer ttyC%d %d\n",
2992 info->line, info->xmit_cnt + char_count); /* */
2993 #endif
2994 return (info->xmit_cnt + char_count);
2996 } /* cy_chars_in_buffer */
3000 * ------------------------------------------------------------
3001 * cy_ioctl() and friends
3002 * ------------------------------------------------------------
3007 * This routine finds or computes the various line characteristics.
3008 * It used to be called config_setup
3010 static void
3011 set_line_char(struct cyclades_port * info)
3013 unsigned long flags;
3014 unsigned char *base_addr;
3015 int card,chip,channel,index;
3016 unsigned cflag, iflag;
3017 unsigned short chip_number;
3018 int baud;
3019 int i;
3022 if (!info->tty || !info->tty->termios){
3023 return;
3025 if (info->line == -1){
3026 return;
3028 cflag = info->tty->termios->c_cflag;
3029 iflag = info->tty->termios->c_iflag;
3031 card = info->card;
3032 channel = (info->line) - (cy_card[card].first_line);
3033 chip_number = channel / 4;
3035 if (!IS_CYC_Z(cy_card[card])) {
3037 index = cy_card[card].bus_index;
3039 /* baud rate */
3040 baud = tty_get_baud_rate(info->tty);
3041 if (baud > CD1400_MAX_SPEED) {
3042 baud = CD1400_MAX_SPEED;
3044 /* find the baud index */
3045 for (i = 0; i < 20; i++) {
3046 if (baud == baud_table[i]) {
3047 break;
3050 if (i == 20) {
3051 i = 19; /* CD1400_MAX_SPEED */
3055 if(info->chip_rev >= CD1400_REV_J) {
3056 /* It is a CD1400 rev. J or later */
3057 info->tbpr = baud_bpr_60[i]; /* Tx BPR */
3058 info->tco = baud_co_60[i]; /* Tx CO */
3059 info->rbpr = baud_bpr_60[i]; /* Rx BPR */
3060 info->rco = baud_co_60[i]; /* Rx CO */
3061 } else {
3062 info->tbpr = baud_bpr_25[i]; /* Tx BPR */
3063 info->tco = baud_co_25[i]; /* Tx CO */
3064 info->rbpr = baud_bpr_25[i]; /* Rx BPR */
3065 info->rco = baud_co_25[i]; /* Rx CO */
3067 if (baud_table[i] == 134) {
3068 info->timeout = (info->xmit_fifo_size*HZ*15/269) + 2;
3069 /* get it right for 134.5 baud */
3070 } else if (baud_table[i]) {
3071 info->timeout = (info->xmit_fifo_size*HZ*15/baud_table[i]) + 2;
3072 /* this needs to be propagated into the card info */
3073 } else {
3074 info->timeout = 0;
3076 /* By tradition (is it a standard?) a baud rate of zero
3077 implies the line should be/has been closed. A bit
3078 later in this routine such a test is performed. */
3080 /* byte size and parity */
3081 info->cor5 = 0;
3082 info->cor4 = 0;
3083 info->cor3 = (info->default_threshold
3084 ? info->default_threshold
3085 : baud_cor3[i]); /* receive threshold */
3086 info->cor2 = CyETC;
3087 switch(cflag & CSIZE){
3088 case CS5:
3089 info->cor1 = Cy_5_BITS;
3090 break;
3091 case CS6:
3092 info->cor1 = Cy_6_BITS;
3093 break;
3094 case CS7:
3095 info->cor1 = Cy_7_BITS;
3096 break;
3097 case CS8:
3098 info->cor1 = Cy_8_BITS;
3099 break;
3101 if(cflag & CSTOPB){
3102 info->cor1 |= Cy_2_STOP;
3104 if (cflag & PARENB){
3105 if (cflag & PARODD){
3106 info->cor1 |= CyPARITY_O;
3107 }else{
3108 info->cor1 |= CyPARITY_E;
3110 }else{
3111 info->cor1 |= CyPARITY_NONE;
3114 /* CTS flow control flag */
3115 if (cflag & CRTSCTS){
3116 info->flags |= ASYNC_CTS_FLOW;
3117 info->cor2 |= CyCtsAE;
3118 }else{
3119 info->flags &= ~ASYNC_CTS_FLOW;
3120 info->cor2 &= ~CyCtsAE;
3122 if (cflag & CLOCAL)
3123 info->flags &= ~ASYNC_CHECK_CD;
3124 else
3125 info->flags |= ASYNC_CHECK_CD;
3127 /***********************************************
3128 The hardware option, CyRtsAO, presents RTS when
3129 the chip has characters to send. Since most modems
3130 use RTS as reverse (inbound) flow control, this
3131 option is not used. If inbound flow control is
3132 necessary, DTR can be programmed to provide the
3133 appropriate signals for use with a non-standard
3134 cable. Contact Marcio Saito for details.
3135 ***********************************************/
3137 chip = channel>>2;
3138 channel &= 0x03;
3139 base_addr = (unsigned char*)
3140 (cy_card[card].base_addr
3141 + (cy_chip_offset[chip]<<index));
3143 save_flags(flags); cli();
3144 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3146 /* tx and rx baud rate */
3148 cy_writeb((u_long)base_addr+(CyTCOR<<index), info->tco);
3149 cy_writeb((u_long)base_addr+(CyTBPR<<index), info->tbpr);
3150 cy_writeb((u_long)base_addr+(CyRCOR<<index), info->rco);
3151 cy_writeb((u_long)base_addr+(CyRBPR<<index), info->rbpr);
3153 /* set line characteristics according configuration */
3155 cy_writeb((u_long)base_addr+(CySCHR1<<index),
3156 START_CHAR(info->tty));
3157 cy_writeb((u_long)base_addr+(CySCHR2<<index),
3158 STOP_CHAR(info->tty));
3159 cy_writeb((u_long)base_addr+(CyCOR1<<index), info->cor1);
3160 cy_writeb((u_long)base_addr+(CyCOR2<<index), info->cor2);
3161 cy_writeb((u_long)base_addr+(CyCOR3<<index), info->cor3);
3162 cy_writeb((u_long)base_addr+(CyCOR4<<index), info->cor4);
3163 cy_writeb((u_long)base_addr+(CyCOR5<<index), info->cor5);
3165 cyy_issue_cmd(base_addr,
3166 CyCOR_CHANGE|CyCOR1ch|CyCOR2ch|CyCOR3ch,index);
3168 cy_writeb((u_long)base_addr+(CyCAR<<index),
3169 (u_char)channel); /* !!! Is this needed? */
3170 cy_writeb((u_long)base_addr+(CyRTPR<<index), (info->default_timeout
3171 ? info->default_timeout
3172 : 0x02)); /* 10ms rx timeout */
3174 if (C_CLOCAL(info->tty)) {
3175 /* without modem intr */
3176 cy_writeb((u_long)base_addr+(CySRER<<index),
3177 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
3178 /* act on 1->0 modem transitions */
3179 if ((cflag & CRTSCTS) && info->rflow) {
3180 cy_writeb((u_long)base_addr+(CyMCOR1<<index),
3181 (CyCTS|rflow_thr[i]));
3182 } else {
3183 cy_writeb((u_long)base_addr+(CyMCOR1<<index), CyCTS);
3185 /* act on 0->1 modem transitions */
3186 cy_writeb((u_long)base_addr+(CyMCOR2<<index), CyCTS);
3187 } else {
3188 /* without modem intr */
3189 cy_writeb((u_long)base_addr+(CySRER<<index),
3190 cy_readb(base_addr+(CySRER<<index)) | CyMdmCh);
3191 /* act on 1->0 modem transitions */
3192 if ((cflag & CRTSCTS) && info->rflow) {
3193 cy_writeb((u_long)base_addr+(CyMCOR1<<index),
3194 (CyDSR|CyCTS|CyRI|CyDCD|rflow_thr[i]));
3195 } else {
3196 cy_writeb((u_long)base_addr+(CyMCOR1<<index),
3197 CyDSR|CyCTS|CyRI|CyDCD);
3199 /* act on 0->1 modem transitions */
3200 cy_writeb((u_long)base_addr+(CyMCOR2<<index),
3201 CyDSR|CyCTS|CyRI|CyDCD);
3204 if(i == 0){ /* baud rate is zero, turn off line */
3205 if (info->rtsdtr_inv) {
3206 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
3207 } else {
3208 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
3210 #ifdef CY_DEBUG_DTR
3211 printk("cyc:set_line_char dropping DTR\n");
3212 printk(" status: 0x%x,
3213 0x%x\n", cy_readb(base_addr+(CyMSVR1<<index)),
3214 cy_readb(base_addr+(CyMSVR2<<index)));
3215 #endif
3216 }else{
3217 if (info->rtsdtr_inv) {
3218 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
3219 } else {
3220 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
3222 #ifdef CY_DEBUG_DTR
3223 printk("cyc:set_line_char raising DTR\n");
3224 printk(" status: 0x%x, 0x%x\n",
3225 cy_readb(base_addr+(CyMSVR1<<index)),
3226 cy_readb(base_addr+(CyMSVR2<<index)));
3227 #endif
3230 if (info->tty){
3231 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3234 restore_flags(flags);
3235 } else {
3236 struct FIRM_ID *firm_id;
3237 struct ZFW_CTRL *zfw_ctrl;
3238 struct BOARD_CTRL *board_ctrl;
3239 struct CH_CTRL *ch_ctrl;
3240 struct BUF_CTRL *buf_ctrl;
3241 int retval;
3243 firm_id = (struct FIRM_ID *)
3244 (cy_card[card].base_addr + ID_ADDRESS);
3245 if (!ISZLOADED(cy_card[card])) {
3246 return;
3249 zfw_ctrl = (struct ZFW_CTRL *)
3250 (cy_card[card].base_addr + cy_readl(&firm_id->zfwctrl_addr));
3251 board_ctrl = &zfw_ctrl->board_ctrl;
3252 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
3253 buf_ctrl = &zfw_ctrl->buf_ctrl[channel];
3255 /* baud rate */
3256 baud = tty_get_baud_rate(info->tty);
3257 if (baud > CD1400_MAX_SPEED) {
3258 baud = CD1400_MAX_SPEED;
3260 cy_writel(&ch_ctrl->comm_baud , baud);
3262 if (baud == 134) {
3263 info->timeout = (info->xmit_fifo_size*HZ*30/269) + 2;
3264 /* get it right for 134.5 baud */
3265 } else if (baud) {
3266 info->timeout = (info->xmit_fifo_size*HZ*15/baud) + 2;
3267 /* this needs to be propagated into the card info */
3268 } else {
3269 info->timeout = 0;
3272 /* byte size and parity */
3273 switch(cflag & CSIZE){
3274 case CS5: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS5); break;
3275 case CS6: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS6); break;
3276 case CS7: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS7); break;
3277 case CS8: cy_writel(&ch_ctrl->comm_data_l , C_DL_CS8); break;
3279 if(cflag & CSTOPB){
3280 cy_writel(&ch_ctrl->comm_data_l,
3281 cy_readl(&ch_ctrl->comm_data_l) | C_DL_2STOP);
3282 }else{
3283 cy_writel(&ch_ctrl->comm_data_l,
3284 cy_readl(&ch_ctrl->comm_data_l) | C_DL_1STOP);
3286 if (cflag & PARENB){
3287 if (cflag & PARODD){
3288 cy_writel(&ch_ctrl->comm_parity , C_PR_ODD);
3289 }else{
3290 cy_writel(&ch_ctrl->comm_parity , C_PR_EVEN);
3292 }else{
3293 cy_writel(&ch_ctrl->comm_parity , C_PR_NONE);
3296 /* CTS flow control flag */
3297 if (cflag & CRTSCTS){
3298 info->flags |= ASYNC_CTS_FLOW;
3299 cy_writel(&ch_ctrl->hw_flow,
3300 cy_readl(&ch_ctrl->hw_flow) | C_RS_CTS | C_RS_RTS);
3301 }else{
3302 info->flags &= ~ASYNC_CTS_FLOW;
3303 cy_writel(&ch_ctrl->hw_flow,
3304 cy_readl(&ch_ctrl->hw_flow) & ~(C_RS_CTS | C_RS_RTS));
3307 retval = cyz_issue_cmd(&cy_card[card], channel, C_CM_IOCTL, 0L);
3308 if (retval != 0){
3309 printk("cyc:set_line_char retval at %d was %x\n",
3310 __LINE__, retval);
3313 /* CD sensitivity */
3314 if (cflag & CLOCAL){
3315 info->flags &= ~ASYNC_CHECK_CD;
3316 }else{
3317 info->flags |= ASYNC_CHECK_CD;
3320 if (iflag & IXON){
3321 cy_writel(&ch_ctrl->sw_flow,
3322 cy_readl(&ch_ctrl->sw_flow) | C_FL_OXX);
3323 } else {
3324 cy_writel(&ch_ctrl->sw_flow,
3325 cy_readl(&ch_ctrl->sw_flow) & ~C_FL_OXX);
3328 if(baud == 0){ /* baud rate is zero, turn off line */
3329 cy_writel(&ch_ctrl->rs_control,
3330 cy_readl(&ch_ctrl->rs_control) & ~C_RS_DTR);
3331 #ifdef CY_DEBUG_DTR
3332 printk("cyc:set_line_char dropping Z DTR\n");
3333 #endif
3334 }else{
3335 cy_writel(&ch_ctrl->rs_control,
3336 cy_readl(&ch_ctrl->rs_control) | C_RS_DTR);
3337 #ifdef CY_DEBUG_DTR
3338 printk("cyc:set_line_char raising Z DTR\n");
3339 #endif
3342 retval = cyz_issue_cmd( &cy_card[card], channel, C_CM_IOCTLM, 0L);
3343 if (retval != 0){
3344 printk("cyc:set_line_char retval at %d was %x\n",
3345 __LINE__, retval);
3348 if (info->tty){
3349 clear_bit(TTY_IO_ERROR, &info->tty->flags);
3354 * Set up the tty->alt_speed kludge
3356 if (info->tty) {
3357 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3358 info->tty->alt_speed = 57600;
3359 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3360 info->tty->alt_speed = 115200;
3361 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3362 info->tty->alt_speed = 230400;
3363 if ((info->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3364 info->tty->alt_speed = 460800;
3368 } /* set_line_char */
3371 static int
3372 get_serial_info(struct cyclades_port * info,
3373 struct serial_struct * retinfo)
3375 struct serial_struct tmp;
3376 struct cyclades_card *cinfo = &cy_card[info->card];
3378 if (!retinfo)
3379 return -EFAULT;
3380 memset(&tmp, 0, sizeof(tmp));
3381 tmp.type = info->type;
3382 tmp.line = info->line;
3383 tmp.port = info->card * 0x100 + info->line - cinfo->first_line;
3384 tmp.irq = cinfo->irq;
3385 tmp.flags = info->flags;
3386 tmp.close_delay = info->close_delay;
3387 tmp.baud_base = info->baud;
3388 tmp.custom_divisor = 0; /*!!!*/
3389 tmp.hub6 = 0; /*!!!*/
3390 copy_to_user(retinfo,&tmp,sizeof(*retinfo));
3391 return 0;
3392 } /* get_serial_info */
3395 static int
3396 set_serial_info(struct cyclades_port * info,
3397 struct serial_struct * new_info)
3399 struct serial_struct new_serial;
3400 struct cyclades_port old_info;
3402 if (copy_from_user(&new_serial,new_info,sizeof(new_serial)))
3403 return -EFAULT;
3404 old_info = *info;
3406 if (!capable(CAP_SYS_ADMIN)) {
3407 if ((new_serial.close_delay != info->close_delay) ||
3408 (new_serial.baud_base != info->baud) ||
3409 ((new_serial.flags & ASYNC_FLAGS & ~ASYNC_USR_MASK) !=
3410 (info->flags & ASYNC_FLAGS & ~ASYNC_USR_MASK)))
3411 return -EPERM;
3412 info->flags = ((info->flags & ~ASYNC_USR_MASK) |
3413 (new_serial.flags & ASYNC_USR_MASK));
3414 info->baud = new_serial.baud_base;
3415 goto check_and_exit;
3420 * OK, past this point, all the error checking has been done.
3421 * At this point, we start making changes.....
3424 info->baud = new_serial.baud_base;
3425 info->flags = ((info->flags & ~ASYNC_FLAGS) |
3426 (new_serial.flags & ASYNC_FLAGS));
3427 info->close_delay = new_serial.close_delay * HZ/100;
3428 info->closing_wait = new_serial.closing_wait * HZ/100;
3430 check_and_exit:
3431 if (info->flags & ASYNC_INITIALIZED){
3432 set_line_char(info);
3433 return 0;
3434 }else{
3435 return startup(info);
3437 } /* set_serial_info */
3440 static int
3441 get_modem_info(struct cyclades_port * info, unsigned int *value)
3443 int card,chip,channel,index;
3444 unsigned char *base_addr;
3445 unsigned long flags;
3446 unsigned char status;
3447 unsigned long lstatus;
3448 unsigned int result;
3449 struct FIRM_ID *firm_id;
3450 struct ZFW_CTRL *zfw_ctrl;
3451 struct BOARD_CTRL *board_ctrl;
3452 struct CH_CTRL *ch_ctrl;
3454 card = info->card;
3455 channel = (info->line) - (cy_card[card].first_line);
3456 if (!IS_CYC_Z(cy_card[card])) {
3457 chip = channel>>2;
3458 channel &= 0x03;
3459 index = cy_card[card].bus_index;
3460 base_addr = (unsigned char*)
3461 (cy_card[card].base_addr
3462 + (cy_chip_offset[chip]<<index));
3464 save_flags(flags); cli();
3465 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3466 status = cy_readb(base_addr+(CyMSVR1<<index));
3467 status |= cy_readb(base_addr+(CyMSVR2<<index));
3468 restore_flags(flags);
3471 if (info->rtsdtr_inv) {
3472 result = ((status & CyRTS) ? TIOCM_DTR : 0)
3473 | ((status & CyDTR) ? TIOCM_RTS : 0);
3474 } else {
3475 result = ((status & CyRTS) ? TIOCM_RTS : 0)
3476 | ((status & CyDTR) ? TIOCM_DTR : 0);
3478 result |= ((status & CyDCD) ? TIOCM_CAR : 0)
3479 | ((status & CyRI) ? TIOCM_RNG : 0)
3480 | ((status & CyDSR) ? TIOCM_DSR : 0)
3481 | ((status & CyCTS) ? TIOCM_CTS : 0);
3482 } else {
3483 base_addr = (unsigned char*) (cy_card[card].base_addr);
3485 if (cy_card[card].num_chips != -1){
3486 return -EINVAL;
3489 firm_id = (struct FIRM_ID *)
3490 (cy_card[card].base_addr + ID_ADDRESS);
3491 if (ISZLOADED(cy_card[card])) {
3492 zfw_ctrl = (struct ZFW_CTRL *)
3493 (cy_card[card].base_addr + cy_readl(&firm_id->zfwctrl_addr));
3494 board_ctrl = &zfw_ctrl->board_ctrl;
3495 ch_ctrl = zfw_ctrl->ch_ctrl;
3496 lstatus = cy_readl(&ch_ctrl[channel].rs_status);
3497 result = ((lstatus & C_RS_RTS) ? TIOCM_RTS : 0)
3498 | ((lstatus & C_RS_DTR) ? TIOCM_DTR : 0)
3499 | ((lstatus & C_RS_DCD) ? TIOCM_CAR : 0)
3500 | ((lstatus & C_RS_RI) ? TIOCM_RNG : 0)
3501 | ((lstatus & C_RS_DSR) ? TIOCM_DSR : 0)
3502 | ((lstatus & C_RS_CTS) ? TIOCM_CTS : 0);
3503 }else{
3504 result = 0;
3505 return -ENODEV;
3509 return cy_put_user(result,(unsigned long *) value);
3510 } /* get_modem_info */
3513 static int
3514 set_modem_info(struct cyclades_port * info, unsigned int cmd,
3515 unsigned int *value)
3517 int card,chip,channel,index;
3518 unsigned char *base_addr;
3519 unsigned long flags;
3520 unsigned int arg = cy_get_user((unsigned long *) value);
3521 struct FIRM_ID *firm_id;
3522 struct ZFW_CTRL *zfw_ctrl;
3523 struct BOARD_CTRL *board_ctrl;
3524 struct CH_CTRL *ch_ctrl;
3525 int retval;
3527 card = info->card;
3528 channel = (info->line) - (cy_card[card].first_line);
3529 if (!IS_CYC_Z(cy_card[card])) {
3530 chip = channel>>2;
3531 channel &= 0x03;
3532 index = cy_card[card].bus_index;
3533 base_addr = (unsigned char*)
3534 (cy_card[card].base_addr
3535 + (cy_chip_offset[chip]<<index));
3537 switch (cmd) {
3538 case TIOCMBIS:
3539 if (arg & TIOCM_RTS){
3540 save_flags(flags); cli();
3541 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3542 if (info->rtsdtr_inv) {
3543 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
3544 } else {
3545 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
3547 restore_flags(flags);
3549 if (arg & TIOCM_DTR){
3550 save_flags(flags); cli();
3551 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3552 if (info->rtsdtr_inv) {
3553 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
3554 } else {
3555 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
3557 #ifdef CY_DEBUG_DTR
3558 printk("cyc:set_modem_info raising DTR\n");
3559 printk(" status: 0x%x, 0x%x\n",
3560 cy_readb(base_addr+(CyMSVR1<<index)),
3561 cy_readb(base_addr+(CyMSVR2<<index)));
3562 #endif
3563 restore_flags(flags);
3565 break;
3566 case TIOCMBIC:
3567 if (arg & TIOCM_RTS){
3568 save_flags(flags); cli();
3569 cy_writeb((u_long)base_addr+(CyCAR<<index),
3570 (u_char)channel);
3571 if (info->rtsdtr_inv) {
3572 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
3573 } else {
3574 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
3576 restore_flags(flags);
3578 if (arg & TIOCM_DTR){
3579 save_flags(flags); cli();
3580 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3581 if (info->rtsdtr_inv) {
3582 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
3583 } else {
3584 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
3586 #ifdef CY_DEBUG_DTR
3587 printk("cyc:set_modem_info dropping DTR\n");
3588 printk(" status: 0x%x, 0x%x\n",
3589 cy_readb(base_addr+(CyMSVR1<<index)),
3590 cy_readb(base_addr+(CyMSVR2<<index)));
3591 #endif
3592 restore_flags(flags);
3594 break;
3595 case TIOCMSET:
3596 if (arg & TIOCM_RTS){
3597 save_flags(flags); cli();
3598 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3599 if (info->rtsdtr_inv) {
3600 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
3601 } else {
3602 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
3604 restore_flags(flags);
3605 }else{
3606 save_flags(flags); cli();
3607 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3608 if (info->rtsdtr_inv) {
3609 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
3610 } else {
3611 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
3613 restore_flags(flags);
3615 if (arg & TIOCM_DTR){
3616 save_flags(flags); cli();
3617 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3618 if (info->rtsdtr_inv) {
3619 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
3620 } else {
3621 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
3623 #ifdef CY_DEBUG_DTR
3624 printk("cyc:set_modem_info raising DTR\n");
3625 printk(" status: 0x%x, 0x%x\n",
3626 cy_readb(base_addr+(CyMSVR1<<index)),
3627 cy_readb(base_addr+(CyMSVR2<<index)));
3628 #endif
3629 restore_flags(flags);
3630 }else{
3631 save_flags(flags); cli();
3632 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
3633 if (info->rtsdtr_inv) {
3634 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
3635 } else {
3636 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
3639 #ifdef CY_DEBUG_DTR
3640 printk("cyc:set_modem_info dropping DTR\n");
3641 printk(" status: 0x%x, 0x%x\n",
3642 cy_readb(base_addr+(CyMSVR1<<index)),
3643 cy_readb(base_addr+(CyMSVR2<<index)));
3644 #endif
3645 restore_flags(flags);
3647 break;
3648 default:
3649 return -EINVAL;
3651 } else {
3652 base_addr = (unsigned char*) (cy_card[card].base_addr);
3654 firm_id = (struct FIRM_ID *)
3655 (cy_card[card].base_addr + ID_ADDRESS);
3656 if (ISZLOADED(cy_card[card])) {
3657 zfw_ctrl = (struct ZFW_CTRL *)
3658 (cy_card[card].base_addr + cy_readl(&firm_id->zfwctrl_addr));
3659 board_ctrl = &zfw_ctrl->board_ctrl;
3660 ch_ctrl = zfw_ctrl->ch_ctrl;
3662 switch (cmd) {
3663 case TIOCMBIS:
3664 if (arg & TIOCM_RTS){
3665 cy_writel(&ch_ctrl[channel].rs_control,
3666 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS);
3668 if (arg & TIOCM_DTR){
3669 cy_writel(&ch_ctrl[channel].rs_control,
3670 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR);
3671 #ifdef CY_DEBUG_DTR
3672 printk("cyc:set_modem_info raising Z DTR\n");
3673 #endif
3675 break;
3676 case TIOCMBIC:
3677 if (arg & TIOCM_RTS){
3678 cy_writel(&ch_ctrl[channel].rs_control,
3679 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS);
3681 if (arg & TIOCM_DTR){
3682 cy_writel(&ch_ctrl[channel].rs_control,
3683 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR);
3684 #ifdef CY_DEBUG_DTR
3685 printk("cyc:set_modem_info clearing Z DTR\n");
3686 #endif
3688 break;
3689 case TIOCMSET:
3690 if (arg & TIOCM_RTS){
3691 cy_writel(&ch_ctrl[channel].rs_control,
3692 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_RTS);
3693 }else{
3694 cy_writel(&ch_ctrl[channel].rs_control,
3695 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_RTS);
3697 if (arg & TIOCM_DTR){
3698 cy_writel(&ch_ctrl[channel].rs_control,
3699 cy_readl(&ch_ctrl[channel].rs_control) | C_RS_DTR);
3700 #ifdef CY_DEBUG_DTR
3701 printk("cyc:set_modem_info raising Z DTR\n");
3702 #endif
3703 }else{
3704 cy_writel(&ch_ctrl[channel].rs_control,
3705 cy_readl(&ch_ctrl[channel].rs_control) & ~C_RS_DTR);
3706 #ifdef CY_DEBUG_DTR
3707 printk("cyc:set_modem_info clearing Z DTR\n");
3708 #endif
3710 break;
3711 default:
3712 return -EINVAL;
3714 }else{
3715 return -ENODEV;
3717 retval = cyz_issue_cmd(&cy_card[info->card],
3718 channel, C_CM_IOCTLM,0L);
3719 if (retval != 0){
3720 printk("cyc:set_modem_info retval at %d was %x\n",
3721 __LINE__, retval);
3724 return 0;
3725 } /* set_modem_info */
3727 static void
3728 send_break( struct cyclades_port * info, int duration)
3731 if (!IS_CYC_Z(cy_card[info->card])) {
3732 /* Let the transmit ISR take care of this (since it
3733 requires stuffing characters into the output stream).
3735 info->x_break = duration;
3736 if (!info->xmit_cnt ) {
3737 start_xmit(info);
3739 } else {
3740 /* For the moment we ignore the duration parameter!!!
3741 A better implementation will use C_CM_SET_BREAK
3742 and C_CM_CLR_BREAK with the appropriate delay.
3744 #if 1
3745 // this appears to wedge the output data stream
3746 int retval;
3747 retval = cyz_issue_cmd(&cy_card[info->card],
3748 (info->line) - (cy_card[info->card].first_line),
3749 C_CM_SENDBRK, 0L);
3750 if (retval != 0){
3751 printk("cyc:send_break retval at %d was %x\n",
3752 __LINE__, retval);
3754 #endif
3756 } /* send_break */
3758 static int
3759 get_mon_info(struct cyclades_port * info, struct cyclades_monitor * mon)
3762 copy_to_user(mon, &info->mon, sizeof(struct cyclades_monitor));
3763 info->mon.int_count = 0;
3764 info->mon.char_count = 0;
3765 info->mon.char_max = 0;
3766 info->mon.char_last = 0;
3767 return 0;
3768 }/* get_mon_info */
3771 static int
3772 set_threshold(struct cyclades_port * info, unsigned long value)
3774 unsigned char *base_addr;
3775 int card,channel,chip,index;
3777 card = info->card;
3778 channel = info->line - cy_card[card].first_line;
3779 if (!IS_CYC_Z(cy_card[card])) {
3780 chip = channel>>2;
3781 channel &= 0x03;
3782 index = cy_card[card].bus_index;
3783 base_addr = (unsigned char*)
3784 (cy_card[card].base_addr
3785 + (cy_chip_offset[chip]<<index));
3787 info->cor3 &= ~CyREC_FIFO;
3788 info->cor3 |= value & CyREC_FIFO;
3789 cy_writeb((u_long)base_addr+(CyCOR3<<index), info->cor3);
3790 cyy_issue_cmd(base_addr,CyCOR_CHANGE|CyCOR3ch,index);
3791 } else {
3792 // Nothing to do!
3794 return 0;
3795 }/* set_threshold */
3798 static int
3799 get_threshold(struct cyclades_port * info, unsigned long *value)
3801 unsigned char *base_addr;
3802 int card,channel,chip,index;
3803 unsigned long tmp;
3805 card = info->card;
3806 channel = info->line - cy_card[card].first_line;
3807 if (!IS_CYC_Z(cy_card[card])) {
3808 chip = channel>>2;
3809 channel &= 0x03;
3810 index = cy_card[card].bus_index;
3811 base_addr = (unsigned char*)
3812 (cy_card[card].base_addr
3813 + (cy_chip_offset[chip]<<index));
3815 tmp = cy_readb(base_addr+(CyCOR3<<index)) & CyREC_FIFO;
3816 return cy_put_user(tmp,value);
3817 } else {
3818 // Nothing to do!
3819 return 0;
3821 }/* get_threshold */
3824 static int
3825 set_default_threshold(struct cyclades_port * info, unsigned long value)
3827 info->default_threshold = value & 0x0f;
3828 return 0;
3829 }/* set_default_threshold */
3832 static int
3833 get_default_threshold(struct cyclades_port * info, unsigned long *value)
3835 return cy_put_user(info->default_threshold,value);
3836 }/* get_default_threshold */
3839 static int
3840 set_timeout(struct cyclades_port * info, unsigned long value)
3842 unsigned char *base_addr;
3843 int card,channel,chip,index;
3845 card = info->card;
3846 channel = info->line - cy_card[card].first_line;
3847 if (!IS_CYC_Z(cy_card[card])) {
3848 chip = channel>>2;
3849 channel &= 0x03;
3850 index = cy_card[card].bus_index;
3851 base_addr = (unsigned char*)
3852 (cy_card[card].base_addr
3853 + (cy_chip_offset[chip]<<index));
3855 cy_writeb((u_long)base_addr+(CyRTPR<<index), value & 0xff);
3856 } else {
3857 // Nothing to do!
3859 return 0;
3860 }/* set_timeout */
3863 static int
3864 get_timeout(struct cyclades_port * info, unsigned long *value)
3866 unsigned char *base_addr;
3867 int card,channel,chip,index;
3868 unsigned long tmp;
3870 card = info->card;
3871 channel = info->line - cy_card[card].first_line;
3872 if (!IS_CYC_Z(cy_card[card])) {
3873 chip = channel>>2;
3874 channel &= 0x03;
3875 index = cy_card[card].bus_index;
3876 base_addr = (unsigned char*)
3877 (cy_card[card].base_addr
3878 + (cy_chip_offset[chip]<<index));
3880 tmp = cy_readb(base_addr+(CyRTPR<<index));
3881 return cy_put_user(tmp,value);
3882 } else {
3883 // Nothing to do!
3884 return 0;
3886 }/* get_timeout */
3889 static int
3890 set_default_timeout(struct cyclades_port * info, unsigned long value)
3892 info->default_timeout = value & 0xff;
3893 return 0;
3894 }/* set_default_timeout */
3897 static int
3898 get_default_timeout(struct cyclades_port * info, unsigned long *value)
3900 return cy_put_user(info->default_timeout,value);
3901 }/* get_default_timeout */
3904 * This routine allows the tty driver to implement device-
3905 * specific ioctl's. If the ioctl number passed in cmd is
3906 * not recognized by the driver, it should return ENOIOCTLCMD.
3908 static int
3909 cy_ioctl(struct tty_struct *tty, struct file * file,
3910 unsigned int cmd, unsigned long arg)
3912 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
3913 int ret_val = 0;
3915 if (serial_paranoia_check(info, tty->device, "cy_ioctl"))
3916 return -ENODEV;
3918 #ifdef CY_DEBUG_OTHER
3919 printk("cyc:cy_ioctl ttyC%d, cmd = %x arg = %lx\n",
3920 info->line, cmd, arg); /* */
3921 #endif
3923 switch (cmd) {
3924 case CYGETMON:
3925 ret_val = get_mon_info(info, (struct cyclades_monitor *)arg);
3926 break;
3927 case CYGETTHRESH:
3928 ret_val = get_threshold(info, (unsigned long *)arg);
3929 break;
3930 case CYSETTHRESH:
3931 ret_val = set_threshold(info, (unsigned long)arg);
3932 break;
3933 case CYGETDEFTHRESH:
3934 ret_val = get_default_threshold(info, (unsigned long *)arg);
3935 break;
3936 case CYSETDEFTHRESH:
3937 ret_val = set_default_threshold(info, (unsigned long)arg);
3938 break;
3939 case CYGETTIMEOUT:
3940 ret_val = get_timeout(info, (unsigned long *)arg);
3941 break;
3942 case CYSETTIMEOUT:
3943 ret_val = set_timeout(info, (unsigned long)arg);
3944 break;
3945 case CYGETDEFTIMEOUT:
3946 ret_val = get_default_timeout(info, (unsigned long *)arg);
3947 break;
3948 case CYSETDEFTIMEOUT:
3949 ret_val = set_default_timeout(info, (unsigned long)arg);
3950 break;
3951 case CYSETRFLOW:
3952 info->rflow = (int)arg;
3953 ret_val = 0;
3954 break;
3955 case CYGETRFLOW:
3956 ret_val = info->rflow;
3957 break;
3958 case CYSETRTSDTR_INV:
3959 info->rtsdtr_inv = (int)arg;
3960 ret_val = 0;
3961 break;
3962 case CYGETRTSDTR_INV:
3963 ret_val = info->rtsdtr_inv;
3964 break;
3965 case CYGETCARDINFO:
3966 if (copy_to_user((void *)arg, (void *)&cy_card[info->card],
3967 sizeof (struct cyclades_card))) {
3968 ret_val = -EFAULT;
3970 ret_val = 0;
3971 break;
3972 case CYGETCD1400VER:
3973 ret_val = info->chip_rev;
3974 break;
3975 case CYZSETPOLLCYCLE:
3976 cyz_polling_cycle = (arg * HZ) / 1000;
3977 ret_val = 0;
3978 break;
3979 case CYZGETPOLLCYCLE:
3980 ret_val = (cyz_polling_cycle * 1000) / HZ;
3981 break;
3982 case CYSETWAIT:
3983 info->closing_wait = (unsigned short)arg * HZ/100;
3984 ret_val = 0;
3985 break;
3986 case CYGETWAIT:
3987 ret_val = info->closing_wait / (HZ/100);
3988 break;
3989 case TCSBRK: /* SVID version: non-zero arg --> no break */
3990 ret_val = tty_check_change(tty);
3991 if (ret_val)
3992 return ret_val;
3993 tty_wait_until_sent(tty,0);
3994 if (!arg)
3995 send_break(info, HZ/4); /* 1/4 second */
3996 break;
3997 case TCSBRKP: /* support for POSIX tcsendbreak() */
3998 ret_val = tty_check_change(tty);
3999 if (ret_val)
4000 return ret_val;
4001 tty_wait_until_sent(tty,0);
4002 send_break(info, arg ? arg*(HZ/10) : HZ/4);
4003 break;
4004 case TIOCMGET:
4005 ret_val = get_modem_info(info, (unsigned int *) arg);
4006 break;
4007 case TIOCMBIS:
4008 case TIOCMBIC:
4009 case TIOCMSET:
4010 ret_val = set_modem_info(info, cmd, (unsigned int *) arg);
4011 break;
4012 case TIOCGSERIAL:
4013 ret_val = get_serial_info(info, (struct serial_struct *) arg);
4014 break;
4015 case TIOCSSERIAL:
4016 ret_val = set_serial_info(info, (struct serial_struct *) arg);
4017 break;
4018 default:
4019 ret_val = -ENOIOCTLCMD;
4022 #ifdef CY_DEBUG_OTHER
4023 printk(" cyc:cy_ioctl done\n");
4024 #endif
4026 return ret_val;
4027 } /* cy_ioctl */
4031 * This routine allows the tty driver to be notified when
4032 * device's termios settings have changed. Note that a
4033 * well-designed tty driver should be prepared to accept the case
4034 * where old == NULL, and try to do something rational.
4036 static void
4037 cy_set_termios(struct tty_struct *tty, struct termios * old_termios)
4039 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4041 #ifdef CY_DEBUG_OTHER
4042 printk("cyc:cy_set_termios ttyC%d\n", info->line);
4043 #endif
4045 if (tty->termios->c_cflag == old_termios->c_cflag)
4046 return;
4047 set_line_char(info);
4049 if ((old_termios->c_cflag & CRTSCTS) &&
4050 !(tty->termios->c_cflag & CRTSCTS)) {
4051 tty->stopped = 0;
4052 cy_start(tty);
4054 #ifdef tytso_patch_94Nov25_1726
4055 if (!(old_termios->c_cflag & CLOCAL) &&
4056 (tty->termios->c_cflag & CLOCAL))
4057 wake_up_interruptible(&info->open_wait);
4058 #endif
4060 return;
4061 } /* cy_set_termios */
4065 * void (*set_ldisc)(struct tty_struct *tty);
4067 * This routine allows the tty driver to be notified when the
4068 * device's termios settings have changed.
4073 /* This routine is called by the upper-layer tty layer to signal
4074 that incoming characters should be throttled because the input
4075 buffers are close to full.
4077 static void
4078 cy_throttle(struct tty_struct * tty)
4080 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4081 unsigned long flags;
4082 unsigned char *base_addr;
4083 int card,chip,channel,index;
4085 #ifdef CY_DEBUG_THROTTLE
4086 char buf[64];
4088 printk("cyc:throttle %s: %d....ttyC%d\n",
4089 tty_name(tty, buf),
4090 tty->ldisc.chars_in_buffer(tty), info->line);
4091 #endif
4093 if (serial_paranoia_check(info, tty->device, "cy_throttle")){
4094 return;
4097 if (I_IXOFF(tty)) {
4098 info->x_char = STOP_CHAR(tty);
4099 /* Should use the "Send Special Character" feature!!! */
4102 card = info->card;
4103 channel = info->line - cy_card[card].first_line;
4104 if (!IS_CYC_Z(cy_card[card])) {
4105 chip = channel>>2;
4106 channel &= 0x03;
4107 index = cy_card[card].bus_index;
4108 base_addr = (unsigned char*)
4109 (cy_card[card].base_addr
4110 + (cy_chip_offset[chip]<<index));
4112 save_flags(flags); cli();
4113 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
4114 if (info->rtsdtr_inv) {
4115 cy_writeb((u_long)base_addr+(CyMSVR2<<index), ~CyDTR);
4116 } else {
4117 cy_writeb((u_long)base_addr+(CyMSVR1<<index), ~CyRTS);
4119 restore_flags(flags);
4120 } else {
4121 // Nothing to do!
4124 return;
4125 } /* cy_throttle */
4129 * This routine notifies the tty driver that it should signal
4130 * that characters can now be sent to the tty without fear of
4131 * overrunning the input buffers of the line disciplines.
4133 static void
4134 cy_unthrottle(struct tty_struct * tty)
4136 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4137 unsigned long flags;
4138 unsigned char *base_addr;
4139 int card,chip,channel,index;
4141 #ifdef CY_DEBUG_THROTTLE
4142 char buf[64];
4144 printk("cyc:unthrottle %s: %d....ttyC%d\n",
4145 tty_name(tty, buf),
4146 tty->ldisc.chars_in_buffer(tty), info->line);
4147 #endif
4149 if (serial_paranoia_check(info, tty->device, "cy_unthrottle")){
4150 return;
4153 if (I_IXOFF(tty)) {
4154 if (info->x_char)
4155 info->x_char = 0;
4156 else
4157 info->x_char = START_CHAR(tty);
4158 /* Should use the "Send Special Character" feature!!! */
4161 card = info->card;
4162 channel = info->line - cy_card[card].first_line;
4163 if (!IS_CYC_Z(cy_card[card])) {
4164 chip = channel>>2;
4165 channel &= 0x03;
4166 index = cy_card[card].bus_index;
4167 base_addr = (unsigned char*)
4168 (cy_card[card].base_addr
4169 + (cy_chip_offset[chip]<<index));
4171 save_flags(flags); cli();
4172 cy_writeb((u_long)base_addr+(CyCAR<<index), (u_char)channel);
4173 if (info->rtsdtr_inv) {
4174 cy_writeb((u_long)base_addr+(CyMSVR2<<index), CyDTR);
4175 } else {
4176 cy_writeb((u_long)base_addr+(CyMSVR1<<index), CyRTS);
4178 restore_flags(flags);
4179 }else{
4180 // Nothing to do!
4183 return;
4184 } /* cy_unthrottle */
4187 /* cy_start and cy_stop provide software output flow control as a
4188 function of XON/XOFF, software CTS, and other such stuff.
4190 static void
4191 cy_stop(struct tty_struct *tty)
4193 struct cyclades_card *cinfo;
4194 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4195 unsigned char *base_addr;
4196 int chip,channel,index;
4197 unsigned long flags;
4199 #ifdef CY_DEBUG_OTHER
4200 printk("cyc:cy_stop ttyC%d\n", info->line); /* */
4201 #endif
4203 if (serial_paranoia_check(info, tty->device, "cy_stop"))
4204 return;
4206 cinfo = &cy_card[info->card];
4207 channel = info->line - cinfo->first_line;
4208 if (!IS_CYC_Z(*cinfo)) {
4209 index = cinfo->bus_index;
4210 chip = channel>>2;
4211 channel &= 0x03;
4212 base_addr = (unsigned char*)
4213 (cy_card[info->card].base_addr
4214 + (cy_chip_offset[chip]<<index));
4216 save_flags(flags); cli();
4217 cy_writeb((u_long)base_addr+(CyCAR<<index),
4218 (u_char)(channel & 0x0003)); /* index channel */
4219 cy_writeb((u_long)base_addr+(CySRER<<index),
4220 cy_readb(base_addr+(CySRER<<index)) & ~CyTxMpty);
4221 restore_flags(flags);
4222 } else {
4223 // Nothing to do!
4226 return;
4227 } /* cy_stop */
4230 static void
4231 cy_start(struct tty_struct *tty)
4233 struct cyclades_card *cinfo;
4234 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4235 unsigned char *base_addr;
4236 int chip,channel,index;
4237 unsigned long flags;
4239 #ifdef CY_DEBUG_OTHER
4240 printk("cyc:cy_start ttyC%d\n", info->line); /* */
4241 #endif
4243 if (serial_paranoia_check(info, tty->device, "cy_start"))
4244 return;
4246 cinfo = &cy_card[info->card];
4247 channel = info->line - cinfo->first_line;
4248 index = cinfo->bus_index;
4249 if (!IS_CYC_Z(*cinfo)) {
4250 chip = channel>>2;
4251 channel &= 0x03;
4252 base_addr = (unsigned char*)
4253 (cy_card[info->card].base_addr
4254 + (cy_chip_offset[chip]<<index));
4256 save_flags(flags); cli();
4257 cy_writeb((u_long)base_addr+(CyCAR<<index),
4258 (u_char)(channel & 0x0003)); /* index channel */
4259 cy_writeb((u_long)base_addr+(CySRER<<index),
4260 cy_readb(base_addr+(CySRER<<index)) | CyTxMpty);
4261 restore_flags(flags);
4262 } else {
4263 // Nothing to do!
4266 return;
4267 } /* cy_start */
4270 static void
4271 cy_flush_buffer(struct tty_struct *tty)
4273 struct cyclades_port *info = (struct cyclades_port *)tty->driver_data;
4274 int card, channel;
4275 unsigned long flags;
4277 #ifdef CY_DEBUG_IO
4278 printk("cyc:cy_flush_buffer ttyC%d\n", info->line); /* */
4279 #endif
4281 if (serial_paranoia_check(info, tty->device, "cy_flush_buffer"))
4282 return;
4283 save_flags(flags); cli();
4284 info->xmit_cnt = info->xmit_head = info->xmit_tail = 0;
4285 restore_flags(flags);
4287 card = info->card;
4288 channel = (info->line) - (cy_card[card].first_line);
4290 if (IS_CYC_Z(cy_card[card])) { /* If it is a Z card, flush the on-board
4291 buffers as well */
4292 static volatile struct FIRM_ID *firm_id;
4293 static volatile struct ZFW_CTRL *zfw_ctrl;
4294 static volatile struct CH_CTRL *ch_ctrl;
4295 static volatile struct BUF_CTRL *buf_ctrl;
4297 firm_id = (struct FIRM_ID *)(cy_card[card].base_addr + ID_ADDRESS);
4298 zfw_ctrl = (struct ZFW_CTRL *) (cy_card[card].base_addr +
4299 cy_readl(&firm_id->zfwctrl_addr));
4300 ch_ctrl = &(zfw_ctrl->ch_ctrl[channel]);
4301 buf_ctrl = &(zfw_ctrl->buf_ctrl[channel]);
4303 while (cy_readl(&buf_ctrl->tx_get) != cy_readl(&buf_ctrl->tx_put))
4304 cy_writel(&buf_ctrl->tx_put, cy_readl(&buf_ctrl->tx_get));
4306 wake_up_interruptible(&tty->write_wait);
4307 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP))
4308 && tty->ldisc.write_wakeup)
4309 (tty->ldisc.write_wakeup)(tty);
4310 } /* cy_flush_buffer */
4314 * cy_hangup() --- called by tty_hangup() when a hangup is signaled.
4316 static void
4317 cy_hangup(struct tty_struct *tty)
4319 struct cyclades_port * info = (struct cyclades_port *)tty->driver_data;
4321 #ifdef CY_DEBUG_OTHER
4322 printk("cyc:cy_hangup ttyC%d\n", info->line); /* */
4323 #endif
4325 if (serial_paranoia_check(info, tty->device, "cy_hangup"))
4326 return;
4328 cy_flush_buffer(tty);
4329 shutdown(info);
4330 info->event = 0;
4331 info->count = 0;
4332 #ifdef CY_DEBUG_COUNT
4333 printk("cyc:cy_hangup (%d): setting count to 0\n", current->pid);
4334 #endif
4335 info->tty = 0;
4336 info->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CALLOUT_ACTIVE);
4337 wake_up_interruptible(&info->open_wait);
4338 } /* cy_hangup */
4342 * ---------------------------------------------------------------------
4343 * cy_init() and friends
4345 * cy_init() is called at boot-time to initialize the serial driver.
4346 * ---------------------------------------------------------------------
4349 /* initialize chips on Cyclom-Y card -- return number of valid
4350 chips (which is number of ports/4) */
4351 __initfunc(static unsigned short
4352 cyy_init_card(volatile ucchar *true_base_addr,int index))
4354 unsigned int chip_number;
4355 volatile ucchar* base_addr;
4357 cy_writeb((u_long)true_base_addr+(Cy_HwReset<<index), 0);
4358 /* Cy_HwReset is 0x1400 */
4359 cy_writeb((u_long)true_base_addr+(Cy_ClrIntr<<index), 0);
4360 /* Cy_ClrIntr is 0x1800 */
4361 udelay(500L);
4363 for(chip_number=0; chip_number<CyMAX_CHIPS_PER_CARD; chip_number++){
4364 base_addr = true_base_addr
4365 + (cy_chip_offset[chip_number]<<index);
4366 mdelay(1);
4367 if(cy_readb(base_addr+(CyCCR<<index)) != 0x00){
4368 /*************
4369 printk(" chip #%d at %#6lx is never idle (CCR != 0)\n",
4370 chip_number, (unsigned long)base_addr);
4371 *************/
4372 return chip_number;
4375 cy_writeb((u_long)base_addr+(CyGFRCR<<index), 0);
4376 udelay(10L);
4378 /* The Cyclom-16Y does not decode address bit 9 and therefore
4379 cannot distinguish between references to chip 0 and a non-
4380 existent chip 4. If the preceding clearing of the supposed
4381 chip 4 GFRCR register appears at chip 0, there is no chip 4
4382 and this must be a Cyclom-16Y, not a Cyclom-32Ye.
4384 if (chip_number == 4
4385 && cy_readb(true_base_addr
4386 + (cy_chip_offset[0]<<index)
4387 + (CyGFRCR<<index)) == 0){
4388 return chip_number;
4391 cy_writeb((u_long)base_addr+(CyCCR<<index), CyCHIP_RESET);
4392 mdelay(1);
4394 if(cy_readb(base_addr+(CyGFRCR<<index)) == 0x00){
4396 printk(" chip #%d at %#6lx is not responding ",
4397 chip_number, (unsigned long)base_addr);
4398 printk("(GFRCR stayed 0)\n",
4400 return chip_number;
4402 if((0xf0 & (cy_readb(base_addr+(CyGFRCR<<index)))) != 0x40){
4404 printk(" chip #%d at %#6lx is not valid (GFRCR == %#2x)\n",
4405 chip_number, (unsigned long)base_addr,
4406 base_addr[CyGFRCR<<index]);
4408 return chip_number;
4410 cy_writeb((u_long)base_addr+(CyGCR<<index), CyCH0_SERIAL);
4411 if (cy_readb(base_addr+(CyGFRCR<<index)) >= CD1400_REV_J){
4412 /* It is a CD1400 rev. J or later */
4413 /* Impossible to reach 5ms with this chip.
4414 Changed to 2ms instead (f = 500 Hz). */
4415 cy_writeb((u_long)base_addr+(CyPPR<<index), CyCLOCK_60_2MS);
4416 } else {
4417 /* f = 200 Hz */
4418 cy_writeb((u_long)base_addr+(CyPPR<<index), CyCLOCK_25_5MS);
4422 printk(" chip #%d at %#6lx is rev 0x%2x\n",
4423 chip_number, (unsigned long)base_addr,
4424 cy_readb(base_addr+(CyGFRCR<<index)));
4427 return chip_number;
4428 } /* cyy_init_card */
4431 * ---------------------------------------------------------------------
4432 * cy_detect_isa() - Probe for Cyclom-Y/ISA boards.
4433 * sets global variables and return the number of ISA boards found.
4434 * ---------------------------------------------------------------------
4436 __initfunc(static int
4437 cy_detect_isa(void))
4439 unsigned short cy_isa_irq,nboard;
4440 volatile ucchar *cy_isa_address;
4441 unsigned short i,j,cy_isa_nchan;
4443 nboard = 0;
4445 /* scan the address table probing for Cyclom-Y/ISA boards */
4446 for (i = 0 ; i < NR_ISA_ADDRS ; i++) {
4447 cy_isa_address = cy_isa_addresses[i];
4448 if (cy_isa_address == 0x0000) {
4449 return(nboard);
4452 /* probe for CD1400... */
4454 #if !defined(__alpha__)
4455 cy_isa_address = ioremap((unsigned int)cy_isa_address,
4456 CyISA_Ywin);
4457 #endif
4458 cy_isa_nchan = CyPORTS_PER_CHIP *
4459 cyy_init_card(cy_isa_address,0);
4460 if (cy_isa_nchan == 0) {
4461 continue;
4464 /* find out the board's irq by probing */
4465 cy_isa_irq = do_auto_irq(cy_isa_address);
4466 if (cy_isa_irq == 0) {
4467 printk("Cyclom-Y/ISA found at 0x%lx ",
4468 (unsigned long) cy_isa_address);
4469 printk("but the IRQ could not be detected.\n");
4470 continue;
4473 if((cy_next_channel+cy_isa_nchan) > NR_PORTS) {
4474 printk("Cyclom-Y/ISA found at 0x%lx ",
4475 (unsigned long) cy_isa_address);
4476 printk("but no more channels are available.\n");
4477 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4478 return(nboard);
4480 /* fill the next cy_card structure available */
4481 for (j = 0 ; j < NR_CARDS ; j++) {
4482 if (cy_card[j].base_addr == 0) break;
4484 if (j == NR_CARDS) { /* no more cy_cards available */
4485 printk("Cyclom-Y/ISA found at 0x%lx ",
4486 (unsigned long) cy_isa_address);
4487 printk("but no more cards can be used .\n");
4488 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4489 return(nboard);
4492 /* allocate IRQ */
4493 if(request_irq(cy_isa_irq, cyy_interrupt,
4494 SA_INTERRUPT, "cyclomY", NULL))
4496 printk("Cyclom-Y/ISA found at 0x%lx ",
4497 (unsigned long) cy_isa_address);
4498 printk("but could not allocate IRQ#%d.\n",
4499 cy_isa_irq);
4500 return(nboard);
4503 /* set cy_card */
4504 cy_card[j].base_addr = (u_long) cy_isa_address;
4505 cy_card[j].ctl_addr = 0;
4506 cy_card[j].irq = (int) cy_isa_irq;
4507 cy_card[j].bus_index = 0;
4508 cy_card[j].first_line = cy_next_channel;
4509 cy_card[j].num_chips = cy_isa_nchan/4;
4510 IRQ_cards[cy_isa_irq] = &cy_card[j];
4511 nboard++;
4513 /* print message */
4514 printk("Cyclom-Y/ISA #%d: 0x%lx-0x%lx, IRQ%d, ",
4515 j+1, (unsigned long) cy_isa_address,
4516 (unsigned long)(cy_isa_address + (CyISA_Ywin - 1)),
4517 cy_isa_irq);
4518 printk("%d channels starting from port %d.\n",
4519 cy_isa_nchan, cy_next_channel);
4520 cy_next_channel += cy_isa_nchan;
4522 return(nboard);
4524 } /* cy_detect_isa */
4527 * ---------------------------------------------------------------------
4528 * cy_detect_pci() - Test PCI bus presence and Cyclom-Ye/PCI.
4529 * sets global variables and return the number of PCI boards found.
4530 * ---------------------------------------------------------------------
4532 __initfunc(static int
4533 cy_detect_pci(void))
4535 #ifdef CONFIG_PCI
4537 struct pci_dev *pdev = NULL;
4538 unsigned char cyy_rev_id;
4539 unsigned long pci_intr_ctrl;
4540 unsigned char cy_pci_irq = 0;
4541 uclong cy_pci_addr0, cy_pci_addr1, cy_pci_addr2;
4542 unsigned short i,j,cy_pci_nchan;
4543 unsigned short device_id,dev_index = 0;
4544 uclong mailbox;
4545 uclong Ze_addr0[NR_CARDS], Ze_addr2[NR_CARDS], ZeIndex = 0;
4547 if(pci_present() == 0) { /* PCI bus not present */
4548 return(0);
4550 for (i = 0; i < NR_CARDS; i++) {
4551 /* look for a Cyclades card by vendor and device id */
4552 while((device_id = cy_pci_dev_id[dev_index]) != 0) {
4553 if((pdev = pci_find_device(PCI_VENDOR_ID_CYCLADES,
4554 device_id, pdev)) == NULL) {
4555 dev_index++; /* try next device id */
4556 } else {
4557 break; /* found a board */
4561 if (device_id == 0)
4562 break;
4564 /* read PCI configuration area */
4565 cy_pci_irq = pdev->irq;
4566 cy_pci_addr0 = pdev->base_address[0];
4567 cy_pci_addr1 = pdev->base_address[1];
4568 cy_pci_addr2 = pdev->base_address[2];
4569 pci_read_config_byte(pdev, PCI_REVISION_ID, &cyy_rev_id);
4571 if ((device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo)
4572 || (device_id == PCI_DEVICE_ID_CYCLOM_Y_Hi)){
4573 #ifdef CY_PCI_DEBUG
4574 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4575 pdev->bus->number, pdev->devfn);
4576 printk("rev_id=%d) IRQ%d\n",
4577 cyy_rev_id, (int)cy_pci_irq);
4578 printk("Cyclom-Y/PCI:found winaddr=0x%lx ioaddr=0x%lx\n",
4579 (ulong)cy_pci_addr2, (ulong)cy_pci_addr1);
4580 #endif
4581 cy_pci_addr1 &= PCI_BASE_ADDRESS_IO_MASK;
4582 cy_pci_addr2 &= PCI_BASE_ADDRESS_MEM_MASK;
4584 #if defined(__alpha__)
4585 if (device_id == PCI_DEVICE_ID_CYCLOM_Y_Lo) { /* below 1M? */
4586 printk("Cyclom-Y/PCI (bus=0x0%x, pci_id=0x%x, ",
4587 pdev->bus->number, pdev->devfn);
4588 printk("rev_id=%d) IRQ%d\n",
4589 cyy_rev_id, (int)cy_pci_irq);
4590 printk("Cyclom-Y/PCI:found winaddr=0x%lx ioaddr=0x%lx\n",
4591 (ulong)cy_pci_addr2, (ulong)cy_pci_addr1);
4592 printk("Cyclom-Y/PCI not supported for low addresses in "
4593 "Alpha systems.\n");
4594 i--;
4595 continue;
4597 #else
4598 cy_pci_addr2 = (ulong) ioremap(cy_pci_addr2, CyPCI_Ywin);
4599 #endif
4601 #ifdef CY_PCI_DEBUG
4602 printk("Cyclom-Y/PCI: relocate winaddr=0x%lx ioaddr=0x%lx\n",
4603 (u_long)cy_pci_addr2, (u_long)cy_pci_addr1);
4604 #endif
4605 cy_pci_nchan = (unsigned short)(CyPORTS_PER_CHIP *
4606 cyy_init_card((volatile ucchar *)cy_pci_addr2, 1));
4607 if(cy_pci_nchan == 0) {
4608 printk("Cyclom-Y PCI host card with ");
4609 printk("no Serial-Modules at 0x%lx.\n",
4610 (ulong) cy_pci_addr2);
4611 i--;
4612 continue;
4614 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
4615 printk("Cyclom-Y/PCI found at 0x%lx ",
4616 (ulong) cy_pci_addr2);
4617 printk("but no channels are available.\n");
4618 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4619 return(i);
4621 /* fill the next cy_card structure available */
4622 for (j = 0 ; j < NR_CARDS ; j++) {
4623 if (cy_card[j].base_addr == 0) break;
4625 if (j == NR_CARDS) { /* no more cy_cards available */
4626 printk("Cyclom-Y/PCI found at 0x%lx ",
4627 (ulong) cy_pci_addr2);
4628 printk("but no more cards can be used.\n");
4629 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4630 return(i);
4633 /* allocate IRQ */
4634 if(request_irq(cy_pci_irq, cyy_interrupt,
4635 SA_INTERRUPT, "cyclomY", NULL))
4637 printk("Cyclom-Y/PCI found at 0x%lx ",
4638 (ulong) cy_pci_addr2);
4639 printk("but could not allocate IRQ%d.\n",
4640 cy_pci_irq);
4641 return(i);
4644 /* set cy_card */
4645 cy_card[j].base_addr = (ulong)cy_pci_addr2;
4646 cy_card[j].ctl_addr = 0;
4647 cy_card[j].irq = (int) cy_pci_irq;
4648 cy_card[j].bus_index = 1;
4649 cy_card[j].first_line = cy_next_channel;
4650 cy_card[j].num_chips = cy_pci_nchan/4;
4651 IRQ_cards[cy_pci_irq] = &cy_card[j];
4653 /* enable interrupts in the PCI interface */
4654 outw(inw(cy_pci_addr1+0x68)|0x0900,cy_pci_addr1+0x68);
4655 pci_intr_ctrl = (unsigned long)
4656 (inw(cy_pci_addr1+0x68)
4657 | inw(cy_pci_addr1+0x6a)<<16);
4659 /* print message */
4660 printk("Cyclom-Y/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4661 j+1,
4662 (ulong)cy_pci_addr2,
4663 (ulong)(cy_pci_addr2 + CyPCI_Ywin - 1),
4664 (int)cy_pci_irq);
4665 printk("%d channels starting from port %d.\n",
4666 cy_pci_nchan, cy_next_channel);
4668 cy_next_channel += cy_pci_nchan;
4669 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Lo){
4670 /* print message */
4671 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4672 pdev->bus->number, pdev->devfn);
4673 printk("rev_id=%d) IRQ%d\n",
4674 cyy_rev_id, (int)cy_pci_irq);
4675 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4676 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
4677 printk("Cyclades-Z/PCI not supported for low addresses\n");
4678 break;
4679 }else if (device_id == PCI_DEVICE_ID_CYCLOM_Z_Hi){
4680 #ifdef CY_PCI_DEBUG
4681 printk("Cyclades-Z/PCI (bus=0x0%x, pci_id=0x%x, ",
4682 pdev->bus->number, pdev->devfn);
4683 printk("rev_id=%d) IRQ%d\n",
4684 cyy_rev_id, (int)cy_pci_irq);
4685 printk("Cyclades-Z/PCI: found winaddr=0x%lx ctladdr=0x%lx\n",
4686 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
4687 #endif
4688 cy_pci_addr0 &= PCI_BASE_ADDRESS_MEM_MASK;
4689 #if !defined(__alpha__)
4690 cy_pci_addr0 = (unsigned int) ioremap(
4691 cy_pci_addr0 & PAGE_MASK,
4692 PAGE_ALIGN(CyPCI_Zctl))
4693 + (cy_pci_addr0 & (PAGE_SIZE-1));
4694 #endif
4695 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 *)
4696 cy_pci_addr0)->mail_box_0);
4697 cy_pci_addr2 &= PCI_BASE_ADDRESS_MEM_MASK;
4698 if (mailbox == ZE_V1) {
4699 #if !defined(__alpha__)
4700 cy_pci_addr2 = (unsigned int) ioremap(
4701 cy_pci_addr2 & PAGE_MASK,
4702 PAGE_ALIGN(CyPCI_Ze_win))
4703 + (cy_pci_addr2 & (PAGE_SIZE-1));
4704 #endif
4705 if (ZeIndex == NR_CARDS) {
4706 printk("Cyclades-Ze/PCI found at 0x%lx ",
4707 (ulong)cy_pci_addr2);
4708 printk("but no more cards can be used.\n");
4709 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4710 } else {
4711 Ze_addr0[ZeIndex] = cy_pci_addr0;
4712 Ze_addr2[ZeIndex] = cy_pci_addr2;
4713 ZeIndex++;
4715 i--;
4716 continue;
4717 } else {
4718 #if !defined(__alpha__)
4719 cy_pci_addr2 = (unsigned int) ioremap(
4720 cy_pci_addr2 & PAGE_MASK,
4721 PAGE_ALIGN(CyPCI_Zwin))
4722 + (cy_pci_addr2 & (PAGE_SIZE-1));
4723 #endif
4726 #ifdef CY_PCI_DEBUG
4727 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4728 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
4729 if (mailbox == ZO_V1) {
4730 cy_writel(&((struct RUNTIME_9060 *)
4731 (cy_pci_addr0))->loc_addr_base, WIN_CREG);
4732 PAUSE
4733 printk("Cyclades-8Zo/PCI: FPGA id %lx, ver %lx\n",
4734 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *)
4735 (cy_pci_addr2))->fpga_id)),
4736 (ulong)(0xff & cy_readl(&((struct CUSTOM_REG *)
4737 (cy_pci_addr2))->fpga_version)));
4738 cy_writel(&((struct RUNTIME_9060 *)
4739 (cy_pci_addr0))->loc_addr_base, WIN_RAM);
4740 } else {
4741 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
4743 #endif
4744 /* The following clears the firmware id word. This ensures
4745 that the driver will not attempt to talk to the board
4746 until it has been properly initialized.
4748 PAUSE
4749 if ((mailbox == ZO_V1) || (mailbox == ZO_V2))
4750 cy_writel((ulong)(cy_pci_addr2+ID_ADDRESS), 0L);
4752 /* This must be a Cyclades-8Zo/PCI. The extendable
4753 version will have a different device_id and will
4754 be allocated its maximum number of ports. */
4755 cy_pci_nchan = 8;
4757 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
4758 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4759 (ulong)cy_pci_addr2);
4760 printk("but no channels are available.\n");
4761 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4762 return(i);
4765 /* fill the next cy_card structure available */
4766 for (j = 0 ; j < NR_CARDS ; j++) {
4767 if (cy_card[j].base_addr == 0) break;
4769 if (j == NR_CARDS) { /* no more cy_cards available */
4770 printk("Cyclades-8Zo/PCI found at 0x%lx ",
4771 (ulong)cy_pci_addr2);
4772 printk("but no more cards can be used.\n");
4773 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4774 return(i);
4777 /* allocate IRQ only if board has an IRQ */
4778 if( (1 < cy_pci_irq) && (cy_pci_irq < 15) ) {
4779 if(request_irq(cy_pci_irq,cyz_interrupt,
4780 SA_INTERRUPT,"cyclomZ",NULL))
4782 printk("Could not allocate IRQ%d ",
4783 cy_pci_irq);
4784 printk("for Cyclades-8Zo/PCI at 0x%lx.\n",
4785 (ulong)cy_pci_addr2);
4786 return(i);
4791 /* set cy_card */
4792 cy_card[j].base_addr = cy_pci_addr2;
4793 cy_card[j].ctl_addr = cy_pci_addr0;
4794 cy_card[j].irq = (int) cy_pci_irq;
4795 cy_card[j].bus_index = 1;
4796 cy_card[j].first_line = cy_next_channel;
4797 cy_card[j].num_chips = -1;
4798 IRQ_cards[cy_pci_irq] = &cy_card[j];
4800 /* print message */
4801 /* don't report IRQ if board is no IRQ */
4802 if( (cy_pci_irq < 15) && (cy_pci_irq > 1) ) {
4803 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4804 j+1,(ulong)cy_pci_addr2,
4805 (ulong)(cy_pci_addr2 + CyPCI_Zwin - 1),
4806 (int)cy_pci_irq);
4807 }else{
4808 printk("Cyclades-8Zo/PCI #%d: 0x%lx-0x%lx, ",
4809 j+1,(ulong)cy_pci_addr2,
4810 (ulong)(cy_pci_addr2 + CyPCI_Zwin - 1));
4812 printk("%d channels starting from port %d.\n",
4813 cy_pci_nchan,cy_next_channel);
4814 cy_next_channel += cy_pci_nchan;
4818 for (; ZeIndex != 0 && i < NR_CARDS; i++) {
4819 cy_pci_addr0 = Ze_addr0[0];
4820 cy_pci_addr2 = Ze_addr2[0];
4821 for (j = 0 ; j < ZeIndex-1 ; j++) {
4822 Ze_addr0[j] = Ze_addr0[j+1];
4823 Ze_addr2[j] = Ze_addr2[j+1];
4825 ZeIndex--;
4826 mailbox = (uclong)cy_readl(&((struct RUNTIME_9060 *)
4827 cy_pci_addr0)->mail_box_0);
4828 #ifdef CY_PCI_DEBUG
4829 printk("Cyclades-Z/PCI: relocate winaddr=0x%lx ctladdr=0x%lx\n",
4830 (ulong)cy_pci_addr2, (ulong)cy_pci_addr0);
4831 printk("Cyclades-Z/PCI: New Cyclades-Z board. FPGA not loaded\n");
4832 #endif
4833 /* The following clears the firmware id word. This ensures
4834 that the driver will not attempt to talk to the board
4835 until it has been properly initialized.
4837 PAUSE
4838 /* This must be the new Cyclades-Ze/PCI. */
4839 cy_pci_nchan = ZE_V1_NPORTS;
4841 if((cy_next_channel+cy_pci_nchan) > NR_PORTS) {
4842 printk("Cyclades-Ze/PCI found at 0x%lx ",
4843 (ulong)cy_pci_addr2);
4844 printk("but no channels are available.\n");
4845 printk("Change NR_PORTS in cyclades.c and recompile kernel.\n");
4846 return(i);
4849 /* fill the next cy_card structure available */
4850 for (j = 0 ; j < NR_CARDS ; j++) {
4851 if (cy_card[j].base_addr == 0) break;
4853 if (j == NR_CARDS) { /* no more cy_cards available */
4854 printk("Cyclades-Ze/PCI found at 0x%lx ",
4855 (ulong)cy_pci_addr2);
4856 printk("but no more cards can be used.\n");
4857 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4858 return(i);
4861 /* allocate IRQ only if board has an IRQ */
4862 if( (1 < cy_pci_irq) && (cy_pci_irq < 15) ) {
4863 if(request_irq(cy_pci_irq,cyz_interrupt,
4864 SA_INTERRUPT,"cyclomZ",NULL))
4866 printk("Could not allocate IRQ%d ",
4867 cy_pci_irq);
4868 printk("for Cyclades-Ze/PCI at 0x%lx.\n",
4869 (ulong) cy_pci_addr2);
4870 return(i);
4874 /* set cy_card */
4875 cy_card[j].base_addr = cy_pci_addr2;
4876 cy_card[j].ctl_addr = cy_pci_addr0;
4877 cy_card[j].irq = (int) cy_pci_irq;
4878 cy_card[j].bus_index = 1;
4879 cy_card[j].first_line = cy_next_channel;
4880 cy_card[j].num_chips = -1;
4881 IRQ_cards[cy_pci_irq] = &cy_card[j];
4883 /* print message */
4884 /* don't report IRQ if board is no IRQ */
4885 if( (cy_pci_irq < 15) && (cy_pci_irq > 1) ) {
4886 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, IRQ%d, ",
4887 j+1,(ulong)cy_pci_addr2,
4888 (ulong)(cy_pci_addr2 + CyPCI_Ze_win - 1),
4889 (int)cy_pci_irq);
4890 }else{
4891 printk("Cyclades-Ze/PCI #%d: 0x%lx-0x%lx, ",
4892 j+1,(ulong)cy_pci_addr2,
4893 (ulong)(cy_pci_addr2 + CyPCI_Ze_win - 1));
4895 printk("%d channels starting from port %d.\n",
4896 cy_pci_nchan,cy_next_channel);
4897 cy_next_channel += cy_pci_nchan;
4899 if (ZeIndex != 0) {
4900 printk("Cyclades-Ze/PCI found at 0x%x ",
4901 (unsigned int) Ze_addr2[0]);
4902 printk("but no more cards can be used.\n");
4903 printk("Change NR_CARDS in cyclades.c and recompile kernel.\n");
4905 return(i);
4906 #else
4907 return(0);
4908 #endif /* ifdef CONFIG_PCI */
4909 } /* cy_detect_pci */
4913 * This routine prints out the appropriate serial driver version number
4914 * and identifies which options were configured into this driver.
4916 static inline void
4917 show_version(void)
4919 char *rcsvers, *rcsdate, *tmp;
4920 rcsvers = strchr(rcsid, ' '); rcsvers++;
4921 tmp = strchr(rcsvers, ' '); *tmp++ = '\0';
4922 rcsdate = strchr(tmp, ' '); rcsdate++;
4923 tmp = strrchr(rcsdate, ' '); *tmp = '\0';
4924 printk("Cyclades driver %s %s\n",
4925 rcsvers, rcsdate);
4926 printk(" built %s %s\n",
4927 __DATE__, __TIME__);
4928 } /* show_version */
4930 #ifdef CONFIG_PROC_FS
4931 static int
4932 cyclades_get_proc_info(char *buf, char **start, off_t offset, int length,
4933 int *eof, void *data)
4935 struct cyclades_port *info;
4936 int i;
4937 int len=0;
4938 off_t begin=0;
4939 off_t pos=0;
4940 int size;
4941 __u32 cur_jifs = jiffies;
4943 size = sprintf(buf, "Dev TimeOpen BytesOut IdleOut BytesIn IdleIn Overruns Ldisc\n");
4945 pos += size;
4946 len += size;
4948 /* Output one line for each known port */
4949 for (i = 0; i < NR_PORTS && cy_port[i].line >= 0; i++) {
4950 info = &cy_port[i];
4952 if (info->count)
4953 size = sprintf(buf+len,
4954 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6d\n",
4955 info->line,
4956 JIFFIES_DIFF(info->idle_stats.in_use, cur_jifs) / HZ,
4957 info->idle_stats.xmit_bytes,
4958 JIFFIES_DIFF(info->idle_stats.xmit_idle, cur_jifs) / HZ,
4959 info->idle_stats.recv_bytes,
4960 JIFFIES_DIFF(info->idle_stats.recv_idle, cur_jifs) / HZ,
4961 info->idle_stats.overruns,
4962 (long) info->tty->ldisc.num);
4963 else
4964 size = sprintf(buf+len,
4965 "%3d %8lu %10lu %8lu %10lu %8lu %9lu %6ld\n",
4966 info->line, 0L, 0L, 0L, 0L, 0L, 0L, 0L);
4967 len += size;
4968 pos = begin + len;
4970 if (pos < offset) {
4971 len = 0;
4972 begin = pos;
4974 if (pos > offset + length)
4975 goto done;
4977 *eof = 1;
4978 done:
4979 *start = buf + (offset - begin); /* Start of wanted data */
4980 len -= (offset - begin); /* Start slop */
4981 if (len > length)
4982 len = length; /* Ending slop */
4983 if (len < 0)
4984 len = 0;
4985 return len;
4987 #endif
4990 /* The serial driver boot-time initialization code!
4991 Hardware I/O ports are mapped to character special devices on a
4992 first found, first allocated manner. That is, this code searches
4993 for Cyclom cards in the system. As each is found, it is probed
4994 to discover how many chips (and thus how many ports) are present.
4995 These ports are mapped to the tty ports 32 and upward in monotonic
4996 fashion. If an 8-port card is replaced with a 16-port card, the
4997 port mapping on a following card will shift.
4999 This approach is different from what is used in the other serial
5000 device driver because the Cyclom is more properly a multiplexer,
5001 not just an aggregation of serial ports on one card.
5003 If there are more cards with more ports than have been
5004 statically allocated above, a warning is printed and the
5005 extra ports are ignored.
5008 __initfunc(int
5009 cy_init(void))
5011 struct cyclades_port *info;
5012 struct cyclades_card *cinfo;
5013 int number_z_boards = 0;
5014 int board,port,i,index;
5015 unsigned long mailbox;
5016 unsigned short chip_number;
5017 int nports;
5018 struct proc_dir_entry *ent;
5020 show_version();
5022 /* Initialize the tty_driver structure */
5024 memset(&cy_serial_driver, 0, sizeof(struct tty_driver));
5025 cy_serial_driver.magic = TTY_DRIVER_MAGIC;
5026 cy_serial_driver.name = "cyclades";
5027 cy_serial_driver.name = "ttyC";
5028 cy_serial_driver.major = CYCLADES_MAJOR;
5029 cy_serial_driver.minor_start = 0;
5030 cy_serial_driver.num = NR_PORTS;
5031 cy_serial_driver.type = TTY_DRIVER_TYPE_SERIAL;
5032 cy_serial_driver.subtype = SERIAL_TYPE_NORMAL;
5033 cy_serial_driver.init_termios = tty_std_termios;
5034 cy_serial_driver.init_termios.c_cflag =
5035 B9600 | CS8 | CREAD | HUPCL | CLOCAL;
5036 cy_serial_driver.flags = TTY_DRIVER_REAL_RAW;
5037 cy_serial_driver.refcount = &serial_refcount;
5038 cy_serial_driver.table = serial_table;
5039 cy_serial_driver.termios = serial_termios;
5040 cy_serial_driver.termios_locked = serial_termios_locked;
5041 cy_serial_driver.open = cy_open;
5042 cy_serial_driver.close = cy_close;
5043 cy_serial_driver.write = cy_write;
5044 cy_serial_driver.put_char = cy_put_char;
5045 cy_serial_driver.flush_chars = cy_flush_chars;
5046 cy_serial_driver.write_room = cy_write_room;
5047 cy_serial_driver.chars_in_buffer = cy_chars_in_buffer;
5048 cy_serial_driver.flush_buffer = cy_flush_buffer;
5049 cy_serial_driver.ioctl = cy_ioctl;
5050 cy_serial_driver.throttle = cy_throttle;
5051 cy_serial_driver.unthrottle = cy_unthrottle;
5052 cy_serial_driver.set_termios = cy_set_termios;
5053 cy_serial_driver.stop = cy_stop;
5054 cy_serial_driver.start = cy_start;
5055 cy_serial_driver.hangup = cy_hangup;
5056 cy_serial_driver.wait_until_sent = cy_wait_until_sent;
5059 * The callout device is just like normal device except for
5060 * major number and the subtype code.
5062 cy_callout_driver = cy_serial_driver;
5063 cy_callout_driver.name = "cub";
5064 cy_callout_driver.major = CYCLADESAUX_MAJOR;
5065 cy_callout_driver.subtype = SERIAL_TYPE_CALLOUT;
5066 cy_callout_driver.read_proc = 0;
5067 cy_callout_driver.proc_entry = 0;
5070 if (tty_register_driver(&cy_serial_driver))
5071 panic("Couldn't register Cyclades serial driver\n");
5072 if (tty_register_driver(&cy_callout_driver))
5073 panic("Couldn't register Cyclades callout driver\n");
5075 init_bh(CYCLADES_BH, do_cyclades_bh);
5077 for (i = 0; i < NR_IRQS; i++) {
5078 IRQ_cards[i] = 0;
5081 for (i = 0; i < NR_CARDS; i++) {
5082 /* base_addr=0 indicates board not found */
5083 cy_card[i].base_addr = 0;
5086 /* the code below is responsible to find the boards. Each different
5087 type of board has its own detection routine. If a board is found,
5088 the next cy_card structure available is set by the detection
5089 routine. These functions are responsible for checking the
5090 availability of cy_card and cy_port data structures and updating
5091 the cy_next_channel. */
5093 /* look for isa boards */
5094 cy_isa_nboard = cy_detect_isa();
5096 /* look for pci boards */
5097 cy_pci_nboard = cy_detect_pci();
5099 cy_nboard = cy_isa_nboard + cy_pci_nboard;
5101 /* invalidate remaining cy_card structures */
5102 for (i = 0 ; i < NR_CARDS ; i++) {
5103 if (cy_card[i].base_addr == 0) {
5104 cy_card[i].first_line = -1;
5105 cy_card[i].ctl_addr = 0;
5106 cy_card[i].irq = 0;
5107 cy_card[i].bus_index = 0;
5108 cy_card[i].first_line = 0;
5109 cy_card[i].num_chips = 0;
5112 /* invalidate remaining cy_port structures */
5113 for (i = cy_next_channel ; i < NR_PORTS ; i++) {
5114 cy_port[i].line = -1;
5115 cy_port[i].magic = -1;
5118 /* initialize per-port data structures for each valid board found */
5119 for (board = 0 ; board < cy_nboard ; board++) {
5120 cinfo = &cy_card[board];
5121 if (cinfo->num_chips == -1){ /* Cyclades-Z */
5122 number_z_boards++;
5123 mailbox = cy_readl(&((struct RUNTIME_9060 *)
5124 cy_card[board].ctl_addr)->mail_box_0);
5125 nports = (mailbox == ZE_V1) ? ZE_V1_NPORTS : 8;
5126 for (port = cinfo->first_line ;
5127 port < cinfo->first_line + nports;
5128 port++)
5130 info = &cy_port[port];
5131 info->magic = CYCLADES_MAGIC;
5132 info->type = PORT_STARTECH;
5133 info->card = board;
5134 info->line = port;
5135 info->chip_rev = 0;
5136 info->flags = STD_COM_FLAGS;
5137 info->tty = 0;
5138 if (mailbox == ZO_V1)
5139 info->xmit_fifo_size = CYZ_FIFO_SIZE;
5140 else
5141 info->xmit_fifo_size = 4 * CYZ_FIFO_SIZE;
5142 info->cor1 = 0;
5143 info->cor2 = 0;
5144 info->cor3 = 0;
5145 info->cor4 = 0;
5146 info->cor5 = 0;
5147 info->tbpr = 0;
5148 info->tco = 0;
5149 info->rbpr = 0;
5150 info->rco = 0;
5151 info->close_delay = 5*HZ/10;
5152 info->closing_wait = CLOSING_WAIT_DELAY;
5153 info->x_char = 0;
5154 info->event = 0;
5155 info->count = 0;
5156 #ifdef CY_DEBUG_COUNT
5157 // printk("cyc:cy_init(1) setting Z count to 0\n");
5158 #endif
5159 info->blocked_open = 0;
5160 info->default_threshold = 0;
5161 info->default_timeout = 0;
5162 info->tqueue.routine = do_softint;
5163 info->tqueue.data = info;
5164 info->callout_termios =
5165 cy_callout_driver.init_termios;
5166 info->normal_termios =
5167 cy_serial_driver.init_termios;
5168 info->open_wait = 0;
5169 info->close_wait = 0;
5170 info->shutdown_wait = 0;
5171 /* info->session */
5172 /* info->pgrp */
5173 info->read_status_mask = 0;
5174 /* info->timeout */
5175 /* Bentson's vars */
5176 info->jiffies[0] = 0;
5177 info->jiffies[1] = 0;
5178 info->jiffies[2] = 0;
5179 info->rflush_count = 0;
5181 continue;
5182 }else{ /* Cyclom-Y of some kind*/
5183 index = cinfo->bus_index;
5184 for (port = cinfo->first_line ;
5185 port < cinfo->first_line + 4*cinfo->num_chips ;
5186 port++)
5188 info = &cy_port[port];
5189 info->magic = CYCLADES_MAGIC;
5190 info->type = PORT_CIRRUS;
5191 info->card = board;
5192 info->line = port;
5193 info->flags = STD_COM_FLAGS;
5194 info->tty = 0;
5195 info->xmit_fifo_size = CyMAX_CHAR_FIFO;
5196 info->cor1 = CyPARITY_NONE|Cy_1_STOP|Cy_8_BITS;
5197 info->cor2 = CyETC;
5198 info->cor3 = 0x08; /* _very_ small rcv threshold */
5199 info->cor4 = 0;
5200 info->cor5 = 0;
5201 info->close_delay = 5*HZ/10;
5202 info->closing_wait = CLOSING_WAIT_DELAY;
5203 chip_number = (port - cinfo->first_line) / 4;
5204 if ((info->chip_rev = cy_readb(cinfo->base_addr +
5205 (cy_chip_offset[chip_number]<<index) +
5206 (CyGFRCR<<index))) >= CD1400_REV_J) {
5207 /* It is a CD1400 rev. J or later */
5208 info->tbpr = baud_bpr_60[13]; /* Tx BPR */
5209 info->tco = baud_co_60[13]; /* Tx CO */
5210 info->rbpr = baud_bpr_60[13]; /* Rx BPR */
5211 info->rco = baud_co_60[13]; /* Rx CO */
5212 info->rflow = 0;
5213 info->rtsdtr_inv = 1;
5214 } else {
5215 info->tbpr = baud_bpr_25[13]; /* Tx BPR */
5216 info->tco = baud_co_25[13]; /* Tx CO */
5217 info->rbpr = baud_bpr_25[13]; /* Rx BPR */
5218 info->rco = baud_co_25[13]; /* Rx CO */
5219 info->rflow = 0;
5220 info->rtsdtr_inv = 0;
5222 info->x_char = 0;
5223 info->event = 0;
5224 info->count = 0;
5225 #ifdef CY_DEBUG_COUNT
5226 // printk("cyc:cy_init(2) setting Y count to 0\n");
5227 #endif
5228 info->blocked_open = 0;
5229 info->default_threshold = 0;
5230 info->default_timeout = 0;
5231 info->tqueue.routine = do_softint;
5232 info->tqueue.data = info;
5233 info->callout_termios =
5234 cy_callout_driver.init_termios;
5235 info->normal_termios =
5236 cy_serial_driver.init_termios;
5237 info->open_wait = 0;
5238 info->close_wait = 0;
5239 info->shutdown_wait = 0;
5240 /* info->session */
5241 /* info->pgrp */
5242 info->read_status_mask =
5243 CyTIMEOUT| CySPECHAR| CyBREAK
5244 | CyPARITY| CyFRAME| CyOVERRUN;
5245 /* info->timeout */
5250 if ( number_z_boards && !cyz_timeron){
5251 cyz_timeron++;
5252 cyz_timerlist.expires = jiffies + 1;
5253 add_timer(&cyz_timerlist);
5254 #ifdef CY_PCI_DEBUG
5255 printk("Cyclades-Z polling initialized\n");
5256 #endif
5259 #ifdef CONFIG_PROC_FS
5260 ent = create_proc_entry("cyclades", S_IFREG | S_IRUGO, 0);
5261 ent->read_proc = cyclades_get_proc_info;
5262 #endif
5263 #if 0
5264 #ifdef CONFIG_PROC_FS
5265 proc_register(&proc_root, &cyclades_proc_entry);
5266 #endif
5267 #endif
5269 return 0;
5271 } /* cy_init */
5273 #ifdef MODULE
5274 /* See linux/drivers/char/riscom.c for ideas on how to
5275 pass additional base addresses to the driver!!! */
5277 init_module(void)
5279 return(cy_init());
5280 } /* init_module */
5282 void
5283 cleanup_module(void)
5285 int i;
5286 unsigned long flags;
5288 if (cyz_timeron){
5289 cyz_timeron = 0;
5290 del_timer(&cyz_timerlist);
5293 save_flags(flags); cli();
5294 remove_bh(CYCLADES_BH);
5296 free_page((unsigned long)tmp_buf);
5297 if (tty_unregister_driver(&cy_callout_driver))
5298 printk("Couldn't unregister Cyclades callout driver\n");
5299 if (tty_unregister_driver(&cy_serial_driver))
5300 printk("Couldn't unregister Cyclades serial driver\n");
5302 restore_flags(flags);
5304 for (i = 0; i < NR_CARDS; i++) {
5305 if (cy_card[i].base_addr != 0
5306 && cy_card[i].irq)
5308 free_irq(cy_card[i].irq,NULL);
5311 #ifdef CONFIG_PROC_FS
5312 remove_proc_entry("cyclades", 0);
5313 #endif
5315 } /* cleanup_module */
5316 #else
5317 /* called by linux/init/main.c to parse command line options */
5318 void
5319 cy_setup(char *str, int *ints)
5321 int i, j;
5323 for (i = 0 ; i < NR_ISA_ADDRS ; i++) {
5324 if (cy_isa_addresses[i] == 0) break;
5326 for (j = 1; j <= ints[0]; j++){
5327 if ( i < NR_ISA_ADDRS ){
5328 cy_isa_addresses[i++] = (unsigned char *)(ints[j]);
5332 } /* cy_setup */
5333 #endif
5336 #ifdef CYCLOM_SHOW_STATUS
5337 static void
5338 show_status(int line_num)
5340 unsigned char *base_addr;
5341 int card,chip,channel,index;
5342 struct cyclades_port * info;
5343 unsigned long flags;
5345 info = &cy_port[line_num];
5346 card = info->card;
5347 index = cy_card[card].bus_index;
5348 channel = (info->line) - (cy_card[card].first_line);
5349 chip = channel>>2;
5350 channel &= 0x03;
5351 printk(" card %d, chip %d, channel %d\n", card, chip, channel);/**/
5353 printk(" cy_card\n");
5354 printk(" irq base_addr num_chips first_line = %d %lx %d %d\n",
5355 cy_card[card].irq, (long)cy_card[card].base_addr,
5356 cy_card[card].num_chips, cy_card[card].first_line);
5358 printk(" cy_port\n");
5359 printk(" card line flags = %d %d %x\n",
5360 info->card, info->line, info->flags);
5361 printk(" *tty read_status_mask timeout xmit_fifo_size ",
5362 printk("= %lx %x %x %x\n",
5363 (long)info->tty, info->read_status_mask,
5364 info->timeout, info->xmit_fifo_size);
5365 printk(" cor1,cor2,cor3,cor4,cor5 = %x %x %x %x %x\n",
5366 info->cor1, info->cor2, info->cor3, info->cor4, info->cor5);
5367 printk(" tbpr,tco,rbpr,rco = %d %d %d %d\n",
5368 info->tbpr, info->tco, info->rbpr, info->rco);
5369 printk(" close_delay event count = %d %d %d\n",
5370 info->close_delay, info->event, info->count);
5371 printk(" x_char blocked_open = %x %x\n",
5372 info->x_char, info->blocked_open);
5373 printk(" session pgrp open_wait = %lx %lx %lx\n",
5374 info->session, info->pgrp, (long)info->open_wait);
5377 save_flags(flags); cli();
5379 base_addr = (unsigned char*)
5380 (cy_card[card].base_addr
5381 + (cy_chip_offset[chip]<<index));
5383 /* Global Registers */
5385 printk(" CyGFRCR %x\n", cy_readb(base_addr + CyGFRCR<<index));
5386 printk(" CyCAR %x\n", cy_readb(base_addr + CyCAR<<index));
5387 printk(" CyGCR %x\n", cy_readb(base_addr + CyGCR<<index));
5388 printk(" CySVRR %x\n", cy_readb(base_addr + CySVRR<<index));
5389 printk(" CyRICR %x\n", cy_readb(base_addr + CyRICR<<index));
5390 printk(" CyTICR %x\n", cy_readb(base_addr + CyTICR<<index));
5391 printk(" CyMICR %x\n", cy_readb(base_addr + CyMICR<<index));
5392 printk(" CyRIR %x\n", cy_readb(base_addr + CyRIR<<index));
5393 printk(" CyTIR %x\n", cy_readb(base_addr + CyTIR<<index));
5394 printk(" CyMIR %x\n", cy_readb(base_addr + CyMIR<<index));
5395 printk(" CyPPR %x\n", cy_readb(base_addr + CyPPR<<index));
5397 cy_writeb(base_addr + CyCAR<<index, (u_char)channel);
5399 /* Virtual Registers */
5401 printk(" CyRIVR %x\n", cy_readb(base_addr + CyRIVR<<index));
5402 printk(" CyTIVR %x\n", cy_readb(base_addr + CyTIVR<<index));
5403 printk(" CyMIVR %x\n", cy_readb(base_addr + CyMIVR<<index));
5404 printk(" CyMISR %x\n", cy_readb(base_addr + CyMISR<<index));
5406 /* Channel Registers */
5408 printk(" CyCCR %x\n", cy_readb(base_addr + CyCCR<<index));
5409 printk(" CySRER %x\n", cy_readb(base_addr + CySRER<<index));
5410 printk(" CyCOR1 %x\n", cy_readb(base_addr + CyCOR1<<index));
5411 printk(" CyCOR2 %x\n", cy_readb(base_addr + CyCOR2<<index));
5412 printk(" CyCOR3 %x\n", cy_readb(base_addr + CyCOR3<<index));
5413 printk(" CyCOR4 %x\n", cy_readb(base_addr + CyCOR4<<index));
5414 printk(" CyCOR5 %x\n", cy_readb(base_addr + CyCOR5<<index));
5415 printk(" CyCCSR %x\n", cy_readb(base_addr + CyCCSR<<index));
5416 printk(" CyRDCR %x\n", cy_readb(base_addr + CyRDCR<<index));
5417 printk(" CySCHR1 %x\n", cy_readb(base_addr + CySCHR1<<index));
5418 printk(" CySCHR2 %x\n", cy_readb(base_addr + CySCHR2<<index));
5419 printk(" CySCHR3 %x\n", cy_readb(base_addr + CySCHR3<<index));
5420 printk(" CySCHR4 %x\n", cy_readb(base_addr + CySCHR4<<index));
5421 printk(" CySCRL %x\n", cy_readb(base_addr + CySCRL<<index));
5422 printk(" CySCRH %x\n", cy_readb(base_addr + CySCRH<<index));
5423 printk(" CyLNC %x\n", cy_readb(base_addr + CyLNC<<index));
5424 printk(" CyMCOR1 %x\n", cy_readb(base_addr + CyMCOR1<<index));
5425 printk(" CyMCOR2 %x\n", cy_readb(base_addr + CyMCOR2<<index));
5426 printk(" CyRTPR %x\n", cy_readb(base_addr + CyRTPR<<index));
5427 printk(" CyMSVR1 %x\n", cy_readb(base_addr + CyMSVR1<<index));
5428 printk(" CyMSVR2 %x\n", cy_readb(base_addr + CyMSVR2<<index));
5429 printk(" CyRBPR %x\n", cy_readb(base_addr + CyRBPR<<index));
5430 printk(" CyRCOR %x\n", cy_readb(base_addr + CyRCOR<<index));
5431 printk(" CyTBPR %x\n", cy_readb(base_addr + CyTBPR<<index));
5432 printk(" CyTCOR %x\n", cy_readb(base_addr + CyTCOR<<index));
5434 restore_flags(flags);
5435 } /* show_status */
5436 #endif