OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [uclinux/] [uClinux-2.0.x/] [drivers/] [char/] [cyclades.c] - Blame information for rev 1782

Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.