blob: 2162439bbe487544c589c6f0c054e6d849257a94 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* sx.c -- driver for the Specialix SX series cards.
2 *
3 * This driver will also support the older SI, and XIO cards.
4 *
5 *
6 * (C) 1998 - 2004 R.E.Wolff@BitWizard.nl
7 *
8 * Simon Allen (simonallen@cix.compulink.co.uk) wrote a previous
9 * version of this driver. Some fragments may have been copied. (none
10 * yet :-)
11 *
12 * Specialix pays for the development and support of this driver.
13 * Please DO contact support@specialix.co.uk if you require
14 * support. But please read the documentation (sx.txt) first.
15 *
16 *
17 *
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License as
20 * published by the Free Software Foundation; either version 2 of
21 * the License, or (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be
24 * useful, but WITHOUT ANY WARRANTY; without even the implied
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
26 * PURPOSE. See the GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public
29 * License along with this program; if not, write to the Free
30 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
31 * USA.
32 *
33 * Revision history:
Linus Torvalds1da177e2005-04-16 15:20:36 -070034 * Revision 1.33 2000/03/09 10:00:00 pvdl,wolff
35 * - Fixed module and port counting
36 * - Fixed signal handling
37 * - Fixed an Ooops
38 *
39 * Revision 1.32 2000/03/07 09:00:00 wolff,pvdl
40 * - Fixed some sx_dprintk typos
41 * - added detection for an invalid board/module configuration
42 *
43 * Revision 1.31 2000/03/06 12:00:00 wolff,pvdl
44 * - Added support for EISA
45 *
46 * Revision 1.30 2000/01/21 17:43:06 wolff
47 * - Added support for SX+
48 *
49 * Revision 1.26 1999/08/05 15:22:14 wolff
50 * - Port to 2.3.x
51 * - Reformatted to Linus' liking.
52 *
53 * Revision 1.25 1999/07/30 14:24:08 wolff
54 * Had accidentally left "gs_debug" set to "-1" instead of "off" (=0).
55 *
56 * Revision 1.24 1999/07/28 09:41:52 wolff
57 * - I noticed the remark about use-count straying in sx.txt. I checked
58 * sx_open, and found a few places where that could happen. I hope it's
59 * fixed now.
60 *
61 * Revision 1.23 1999/07/28 08:56:06 wolff
62 * - Fixed crash when sx_firmware run twice.
63 * - Added sx_slowpoll as a module parameter (I guess nobody really wanted
64 * to change it from the default... )
65 * - Fixed a stupid editing problem I introduced in 1.22.
66 * - Fixed dropping characters on a termios change.
67 *
68 * Revision 1.22 1999/07/26 21:01:43 wolff
69 * Russell Brown noticed that I had overlooked 4 out of six modem control
70 * signals in sx_getsignals. Ooops.
71 *
72 * Revision 1.21 1999/07/23 09:11:33 wolff
73 * I forgot to free dynamically allocated memory when the driver is unloaded.
74 *
75 * Revision 1.20 1999/07/20 06:25:26 wolff
76 * The "closing wait" wasn't honoured. Thanks to James Griffiths for
77 * reporting this.
78 *
79 * Revision 1.19 1999/07/11 08:59:59 wolff
80 * Fixed an oops in close, when an open was pending. Changed the memtest
81 * a bit. Should also test the board in word-mode, however my card fails the
82 * memtest then. I still have to figure out what is wrong...
83 *
84 * Revision 1.18 1999/06/10 09:38:42 wolff
85 * Changed the format of the firmware revision from %04x to %x.%02x .
86 *
87 * Revision 1.17 1999/06/04 09:44:35 wolff
88 * fixed problem: reference to pci stuff when config_pci was off...
89 * Thanks to Jorge Novo for noticing this.
90 *
91 * Revision 1.16 1999/06/02 08:30:15 wolff
92 * added/removed the workaround for the DCD bug in the Firmware.
93 * A bit more debugging code to locate that...
94 *
95 * Revision 1.15 1999/06/01 11:35:30 wolff
96 * when DCD is left low (floating?), on TA's the firmware first tells us
97 * that DCD is high, but after a short while suddenly comes to the
98 * conclusion that it is low. All this would be fine, if it weren't that
99 * Unix requires us to send a "hangup" signal in that case. This usually
100 * all happens BEFORE the program has had a chance to ioctl the device
101 * into clocal mode..
102 *
103 * Revision 1.14 1999/05/25 11:18:59 wolff
104 * Added PCI-fix.
105 * Added checks for return code of sx_sendcommand.
106 * Don't issue "reconfig" if port isn't open yet. (bit us on TA modules...)
107 *
108 * Revision 1.13 1999/04/29 15:18:01 wolff
109 * Fixed an "oops" that showed on SuSE 6.0 systems.
110 * Activate DTR again after stty 0.
111 *
112 * Revision 1.12 1999/04/29 07:49:52 wolff
113 * Improved "stty 0" handling a bit. (used to change baud to 9600 assuming
114 * the connection would be dropped anyway. That is not always the case,
115 * and confuses people).
116 * Told the card to always monitor the modem signals.
117 * Added support for dynamic gs_debug adjustments.
118 * Now tells the rest of the system the number of ports.
119 *
120 * Revision 1.11 1999/04/24 11:11:30 wolff
121 * Fixed two stupid typos in the memory test.
122 *
123 * Revision 1.10 1999/04/24 10:53:39 wolff
124 * Added some of Christian's suggestions.
125 * Fixed an HW_COOK_IN bug (ISIG was not in I_OTHER. We used to trust the
126 * card to send the signal to the process.....)
127 *
128 * Revision 1.9 1999/04/23 07:26:38 wolff
129 * Included Christian Lademann's 2.0 compile-warning fixes and interrupt
130 * assignment redesign.
131 * Cleanup of some other stuff.
132 *
133 * Revision 1.8 1999/04/16 13:05:30 wolff
134 * fixed a DCD change unnoticed bug.
135 *
136 * Revision 1.7 1999/04/14 22:19:51 wolff
137 * Fixed typo that showed up in 2.0.x builds (get_user instead of Get_user!)
138 *
139 * Revision 1.6 1999/04/13 18:40:20 wolff
140 * changed misc-minor to 161, as assigned by HPA.
141 *
142 * Revision 1.5 1999/04/13 15:12:25 wolff
143 * Fixed use-count leak when "hangup" occurred.
144 * Added workaround for a stupid-PCIBIOS bug.
145 *
146 *
147 * Revision 1.4 1999/04/01 22:47:40 wolff
148 * Fixed < 1M linux-2.0 problem.
149 * (vremap isn't compatible with ioremap in that case)
150 *
151 * Revision 1.3 1999/03/31 13:45:45 wolff
152 * Firmware loading is now done through a separate IOCTL.
153 *
154 * Revision 1.2 1999/03/28 12:22:29 wolff
155 * rcs cleanup
156 *
157 * Revision 1.1 1999/03/28 12:10:34 wolff
158 * Readying for release on 2.0.x (sorry David, 1.01 becomes 1.1 for RCS).
159 *
160 * Revision 0.12 1999/03/28 09:20:10 wolff
161 * Fixed problem in 0.11, continueing cleanup.
162 *
163 * Revision 0.11 1999/03/28 08:46:44 wolff
164 * cleanup. Not good.
165 *
166 * Revision 0.10 1999/03/28 08:09:43 wolff
167 * Fixed loosing characters on close.
168 *
169 * Revision 0.9 1999/03/21 22:52:01 wolff
170 * Ported back to 2.2.... (minor things)
171 *
172 * Revision 0.8 1999/03/21 22:40:33 wolff
173 * Port to 2.0
174 *
175 * Revision 0.7 1999/03/21 19:06:34 wolff
176 * Fixed hangup processing.
177 *
178 * Revision 0.6 1999/02/05 08:45:14 wolff
179 * fixed real_raw problems. Inclusion into kernel imminent.
180 *
181 * Revision 0.5 1998/12/21 23:51:06 wolff
182 * Snatched a nasty bug: sx_transmit_chars was getting re-entered, and it
183 * shouldn't have. THATs why I want to have transmit interrupts even when
184 * the buffer is empty.
185 *
186 * Revision 0.4 1998/12/17 09:34:46 wolff
187 * PPP works. ioctl works. Basically works!
188 *
189 * Revision 0.3 1998/12/15 13:05:18 wolff
190 * It works! Wow! Gotta start implementing IOCTL and stuff....
191 *
192 * Revision 0.2 1998/12/01 08:33:53 wolff
193 * moved over to 2.1.130
194 *
195 * Revision 0.1 1998/11/03 21:23:51 wolff
196 * Initial revision. Detects SX card.
197 *
198 * */
199
Jiri Slaby11c83872006-12-08 02:38:56 -0800200#define SX_VERSION 1.33
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203#include <linux/kdev_t.h>
204#include <linux/kernel.h>
205#include <linux/sched.h>
206#include <linux/ioport.h>
207#include <linux/interrupt.h>
208#include <linux/errno.h>
209#include <linux/tty.h>
210#include <linux/tty_flip.h>
211#include <linux/mm.h>
212#include <linux/serial.h>
213#include <linux/fcntl.h>
214#include <linux/major.h>
215#include <linux/delay.h>
Jiri Slaby18f813e2006-12-08 02:39:01 -0800216#include <linux/eisa.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217#include <linux/pci.h>
218#include <linux/slab.h>
219#include <linux/init.h>
220#include <linux/miscdevice.h>
221#include <linux/bitops.h>
222
223#include <asm/io.h>
224#include <asm/uaccess.h>
225
226/* The 3.0.0 version of sxboards/sxwindow.h uses BYTE and WORD.... */
227#define BYTE u8
228#define WORD u16
229
230/* .... but the 3.0.4 version uses _u8 and _u16. */
231#define _u8 u8
232#define _u16 u16
233
234#include "sxboards.h"
235#include "sxwindow.h"
236
237#include <linux/generic_serial.h>
238#include "sx.h"
239
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240/* I don't think that this driver can handle more than 256 ports on
241 one machine. You'll have to increase the number of boards in sx.h
242 if you want more than 4 boards. */
243
244#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
245#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
246#endif
247
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248/* Configurable options:
249 (Don't be too sure that it'll work if you toggle them) */
250
251/* Am I paranoid or not ? ;-) */
252#undef SX_PARANOIA_CHECK
253
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254/* 20 -> 2000 per second. The card should rate-limit interrupts at 100
255 Hz, but it is user configurable. I don't recommend going above 1000
256 Hz. The interrupt ratelimit might trigger if the interrupt is
257 shared with a very active other device. */
258#define IRQ_RATE_LIMIT 20
259
260/* Sharing interrupts is possible now. If the other device wants more
261 than 2000 interrupts per second, we'd gracefully decline further
262 interrupts. That's not what we want. On the other hand, if the
263 other device interrupts 2000 times a second, don't use the SX
264 interrupt. Use polling. */
265#undef IRQ_RATE_LIMIT
266
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267#if 0
268/* Not implemented */
269/*
270 * The following defines are mostly for testing purposes. But if you need
271 * some nice reporting in your syslog, you can define them also.
272 */
273#define SX_REPORT_FIFO
274#define SX_REPORT_OVERRUN
Jiri Slaby15b611f2006-12-08 02:39:04 -0800275#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277/* Function prototypes */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800278static void sx_disable_tx_interrupts(void *ptr);
279static void sx_enable_tx_interrupts(void *ptr);
280static void sx_disable_rx_interrupts(void *ptr);
281static void sx_enable_rx_interrupts(void *ptr);
282static int sx_get_CD(void *ptr);
283static void sx_shutdown_port(void *ptr);
284static int sx_set_real_termios(void *ptr);
285static void sx_close(void *ptr);
286static int sx_chars_in_buffer(void *ptr);
287static int sx_init_board(struct sx_board *board);
288static int sx_init_portstructs(int nboards, int nports);
289static int sx_fw_ioctl(struct inode *inode, struct file *filp,
290 unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291static int sx_init_drivers(void);
292
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293static struct tty_driver *sx_driver;
294
Jiri Slaby42f63842006-12-08 02:39:03 -0800295static DEFINE_MUTEX(sx_boards_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296static struct sx_board boards[SX_NBOARDS];
297static struct sx_port *sx_ports;
298static int sx_initialized;
299static int sx_nports;
300static int sx_debug;
301
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302/* You can have the driver poll your card.
303 - Set sx_poll to 1 to poll every timer tick (10ms on Intel).
304 This is used when the card cannot use an interrupt for some reason.
305
306 - set sx_slowpoll to 100 to do an extra poll once a second (on Intel). If
307 the driver misses an interrupt (report this if it DOES happen to you!)
308 everything will continue to work....
309 */
310static int sx_poll = 1;
311static int sx_slowpoll;
312
313/* The card limits the number of interrupts per second.
314 At 115k2 "100" should be sufficient.
315 If you're using higher baudrates, you can increase this...
316 */
317
318static int sx_maxints = 100;
319
Jiri Slaby927a6f92006-12-08 02:39:02 -0800320#ifdef CONFIG_ISA
321
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/* These are the only open spaces in my computer. Yours may have more
323 or less.... -- REW
324 duh: Card at 0xa0000 is possible on HP Netserver?? -- pvdl
325*/
Jiri Slaby15b611f2006-12-08 02:39:04 -0800326static int sx_probe_addrs[] = {
327 0xc0000, 0xd0000, 0xe0000,
328 0xc8000, 0xd8000, 0xe8000
329};
330static int si_probe_addrs[] = {
331 0xc0000, 0xd0000, 0xe0000,
332 0xc8000, 0xd8000, 0xe8000, 0xa0000
333};
334static int si1_probe_addrs[] = {
335 0xd0000
336};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
Tobias Klauserfe971072006-01-09 20:54:02 -0800338#define NR_SX_ADDRS ARRAY_SIZE(sx_probe_addrs)
339#define NR_SI_ADDRS ARRAY_SIZE(si_probe_addrs)
340#define NR_SI1_ADDRS ARRAY_SIZE(si1_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Jiri Slaby927a6f92006-12-08 02:39:02 -0800342module_param_array(sx_probe_addrs, int, NULL, 0);
343module_param_array(si_probe_addrs, int, NULL, 0);
344#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345
346/* Set the mask to all-ones. This alas, only supports 32 interrupts.
347 Some architectures may need more. */
348static int sx_irqmask = -1;
349
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350module_param(sx_poll, int, 0);
351module_param(sx_slowpoll, int, 0);
352module_param(sx_maxints, int, 0);
353module_param(sx_debug, int, 0);
354module_param(sx_irqmask, int, 0);
355
356MODULE_LICENSE("GPL");
357
358static struct real_driver sx_real_driver = {
359 sx_disable_tx_interrupts,
360 sx_enable_tx_interrupts,
361 sx_disable_rx_interrupts,
362 sx_enable_rx_interrupts,
363 sx_get_CD,
Jiri Slaby15b611f2006-12-08 02:39:04 -0800364 sx_shutdown_port,
365 sx_set_real_termios,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 sx_chars_in_buffer,
367 sx_close,
368};
369
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370/*
371 This driver can spew a whole lot of debugging output at you. If you
372 need maximum performance, you should disable the DEBUG define. To
373 aid in debugging in the field, I'm leaving the compile-time debug
374 features enabled, and disable them "runtime". That allows me to
375 instruct people with problems to enable debugging without requiring
376 them to recompile...
377*/
378#define DEBUG
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380#ifdef DEBUG
Jiri Slaby15b611f2006-12-08 02:39:04 -0800381#define sx_dprintk(f, str...) if (sx_debug & f) printk (str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#else
Jiri Slaby15b611f2006-12-08 02:39:04 -0800383#define sx_dprintk(f, str...) /* nothing */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#endif
385
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700386#define func_enter() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s\n",__func__)
387#define func_exit() sx_dprintk(SX_DEBUG_FLOW, "sx: exit %s\n",__func__)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700388
Jiri Slaby15b611f2006-12-08 02:39:04 -0800389#define func_enter2() sx_dprintk(SX_DEBUG_FLOW, "sx: enter %s (port %d)\n", \
Harvey Harrisonbf9d8922008-04-30 00:55:10 -0700390 __func__, port->line)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
392/*
393 * Firmware loader driver specific routines
394 *
395 */
396
Arjan van de Ven62322d22006-07-03 00:24:21 -0700397static const struct file_operations sx_fw_fops = {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800398 .owner = THIS_MODULE,
399 .ioctl = sx_fw_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400};
401
402static struct miscdevice sx_fw_device = {
403 SXCTL_MISC_MINOR, "sxctl", &sx_fw_fops
404};
405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406#ifdef SX_PARANOIA_CHECK
407
408/* This doesn't work. Who's paranoid around here? Not me! */
409
Jiri Slaby15b611f2006-12-08 02:39:04 -0800410static inline int sx_paranoia_check(struct sx_port const *port,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 char *name, const char *routine)
412{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800413 static const char *badmagic = KERN_ERR "sx: Warning: bad sx port magic "
414 "number for device %s in %s\n";
415 static const char *badinfo = KERN_ERR "sx: Warning: null sx port for "
416 "device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 if (!port) {
419 printk(badinfo, name, routine);
420 return 1;
421 }
422 if (port->magic != SX_MAGIC) {
423 printk(badmagic, name, routine);
424 return 1;
425 }
426
427 return 0;
428}
429#else
430#define sx_paranoia_check(a,b,c) 0
431#endif
432
433/* The timeouts. First try 30 times as fast as possible. Then give
434 the card some time to breathe between accesses. (Otherwise the
435 processor on the card might not be able to access its OWN bus... */
436
437#define TIMEOUT_1 30
438#define TIMEOUT_2 1000000
439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440#ifdef DEBUG
441static void my_hd_io(void __iomem *p, int len)
442{
443 int i, j, ch;
444 unsigned char __iomem *addr = p;
445
Jiri Slaby15b611f2006-12-08 02:39:04 -0800446 for (i = 0; i < len; i += 16) {
447 printk("%p ", addr + i);
448 for (j = 0; j < 16; j++) {
449 printk("%02x %s", readb(addr + j + i),
450 (j == 7) ? " " : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800452 for (j = 0; j < 16; j++) {
453 ch = readb(addr + j + i);
454 printk("%c", (ch < 0x20) ? '.' :
455 ((ch > 0x7f) ? '.' : ch));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800457 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 }
459}
460static void my_hd(void *p, int len)
461{
462 int i, j, ch;
463 unsigned char *addr = p;
464
Jiri Slaby15b611f2006-12-08 02:39:04 -0800465 for (i = 0; i < len; i += 16) {
466 printk("%p ", addr + i);
467 for (j = 0; j < 16; j++) {
468 printk("%02x %s", addr[j + i], (j == 7) ? " " : "");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800470 for (j = 0; j < 16; j++) {
471 ch = addr[j + i];
472 printk("%c", (ch < 0x20) ? '.' :
473 ((ch > 0x7f) ? '.' : ch));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800475 printk("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476 }
477}
478#endif
479
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480/* This needs redoing for Alpha -- REW -- Done. */
481
Jiri Slaby15b611f2006-12-08 02:39:04 -0800482static inline void write_sx_byte(struct sx_board *board, int offset, u8 byte)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800484 writeb(byte, board->base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485}
486
Jiri Slaby15b611f2006-12-08 02:39:04 -0800487static inline u8 read_sx_byte(struct sx_board *board, int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800489 return readb(board->base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Jiri Slaby15b611f2006-12-08 02:39:04 -0800492static inline void write_sx_word(struct sx_board *board, int offset, u16 word)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800494 writew(word, board->base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
Jiri Slaby15b611f2006-12-08 02:39:04 -0800497static inline u16 read_sx_word(struct sx_board *board, int offset)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800499 return readw(board->base + offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500}
501
Jiri Slaby15b611f2006-12-08 02:39:04 -0800502static int sx_busy_wait_eq(struct sx_board *board,
503 int offset, int mask, int correctval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504{
505 int i;
506
Jiri Slaby15b611f2006-12-08 02:39:04 -0800507 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Jiri Slaby15b611f2006-12-08 02:39:04 -0800509 for (i = 0; i < TIMEOUT_1; i++)
510 if ((read_sx_byte(board, offset) & mask) == correctval) {
511 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 return 1;
513 }
514
Jiri Slaby15b611f2006-12-08 02:39:04 -0800515 for (i = 0; i < TIMEOUT_2; i++) {
516 if ((read_sx_byte(board, offset) & mask) == correctval) {
517 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return 1;
519 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800520 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 }
522
Jiri Slaby15b611f2006-12-08 02:39:04 -0800523 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 return 0;
525}
526
Jiri Slaby15b611f2006-12-08 02:39:04 -0800527static int sx_busy_wait_neq(struct sx_board *board,
528 int offset, int mask, int badval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 int i;
531
Jiri Slaby15b611f2006-12-08 02:39:04 -0800532 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Jiri Slaby15b611f2006-12-08 02:39:04 -0800534 for (i = 0; i < TIMEOUT_1; i++)
535 if ((read_sx_byte(board, offset) & mask) != badval) {
536 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 return 1;
538 }
539
Jiri Slaby15b611f2006-12-08 02:39:04 -0800540 for (i = 0; i < TIMEOUT_2; i++) {
541 if ((read_sx_byte(board, offset) & mask) != badval) {
542 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 return 1;
544 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800545 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547
Jiri Slaby15b611f2006-12-08 02:39:04 -0800548 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 return 0;
550}
551
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552/* 5.6.4 of 6210028 r2.3 */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800553static int sx_reset(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800555 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Jiri Slaby15b611f2006-12-08 02:39:04 -0800557 if (IS_SX_BOARD(board)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Jiri Slaby15b611f2006-12-08 02:39:04 -0800559 write_sx_byte(board, SX_CONFIG, 0);
560 write_sx_byte(board, SX_RESET, 1); /* Value doesn't matter */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
Jiri Slaby15b611f2006-12-08 02:39:04 -0800562 if (!sx_busy_wait_eq(board, SX_RESET_STATUS, 1, 0)) {
563 printk(KERN_INFO "sx: Card doesn't respond to "
564 "reset...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return 0;
566 }
567 } else if (IS_EISA_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800568 outb(board->irq << 4, board->eisa_base + 0xc02);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 } else if (IS_SI1_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800570 write_sx_byte(board, SI1_ISA_RESET, 0); /*value doesn't matter*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 } else {
572 /* Gory details of the SI/ISA board */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800573 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_SET);
574 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_CLEAR);
575 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_CLEAR);
576 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_CLEAR);
577 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_CLEAR);
578 write_sx_byte(board, SI2_ISA_IRQSET, SI2_ISA_IRQSET_CLEAR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 }
580
Jiri Slaby15b611f2006-12-08 02:39:04 -0800581 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 return 1;
583}
584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585/* This doesn't work on machines where "NULL" isn't 0 */
586/* If you have one of those, someone will need to write
587 the equivalent of this, which will amount to about 3 lines. I don't
588 want to complicate this right now. -- REW
589 (See, I do write comments every now and then :-) */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800590#define OFFSETOF(strct, elem) ((long)&(((struct strct *)NULL)->elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Jiri Slaby15b611f2006-12-08 02:39:04 -0800592#define CHAN_OFFSET(port,elem) (port->ch_base + OFFSETOF (_SXCHANNEL, elem))
593#define MODU_OFFSET(board,addr,elem) (addr + OFFSETOF (_SXMODULE, elem))
594#define BRD_OFFSET(board,elem) (OFFSETOF (_SXCARD, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596#define sx_write_channel_byte(port, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800597 write_sx_byte (port->board, CHAN_OFFSET (port, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
599#define sx_read_channel_byte(port, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800600 read_sx_byte (port->board, CHAN_OFFSET (port, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602#define sx_write_channel_word(port, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800603 write_sx_word (port->board, CHAN_OFFSET (port, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605#define sx_read_channel_word(port, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800606 read_sx_word (port->board, CHAN_OFFSET (port, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
608#define sx_write_module_byte(board, addr, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800609 write_sx_byte (board, MODU_OFFSET (board, addr, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
611#define sx_read_module_byte(board, addr, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800612 read_sx_byte (board, MODU_OFFSET (board, addr, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
614#define sx_write_module_word(board, addr, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800615 write_sx_word (board, MODU_OFFSET (board, addr, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617#define sx_read_module_word(board, addr, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800618 read_sx_word (board, MODU_OFFSET (board, addr, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
620#define sx_write_board_byte(board, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800621 write_sx_byte (board, BRD_OFFSET (board, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623#define sx_read_board_byte(board, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800624 read_sx_byte (board, BRD_OFFSET (board, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
626#define sx_write_board_word(board, elem, val) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800627 write_sx_word (board, BRD_OFFSET (board, elem), val)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
629#define sx_read_board_word(board, elem) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800630 read_sx_word (board, BRD_OFFSET (board, elem))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
Jiri Slaby15b611f2006-12-08 02:39:04 -0800632static int sx_start_board(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800634 if (IS_SX_BOARD(board)) {
635 write_sx_byte(board, SX_CONFIG, SX_CONF_BUSEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 } else if (IS_EISA_BOARD(board)) {
637 write_sx_byte(board, SI2_EISA_OFF, SI2_EISA_VAL);
Jiri Slaby15b611f2006-12-08 02:39:04 -0800638 outb((board->irq << 4) | 4, board->eisa_base + 0xc02);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 } else if (IS_SI1_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800640 write_sx_byte(board, SI1_ISA_RESET_CLEAR, 0);
641 write_sx_byte(board, SI1_ISA_INTCL, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 } else {
643 /* Don't bug me about the clear_set.
644 I haven't the foggiest idea what it's about -- REW */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800645 write_sx_byte(board, SI2_ISA_RESET, SI2_ISA_RESET_CLEAR);
646 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 return 1;
649}
650
651#define SX_IRQ_REG_VAL(board) \
Jiri Slaby15b611f2006-12-08 02:39:04 -0800652 ((board->flags & SX_ISA_BOARD) ? (board->irq << 4) : 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
654/* Note. The SX register is write-only. Therefore, we have to enable the
655 bus too. This is a no-op, if you don't mess with this driver... */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800656static int sx_start_interrupts(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657{
658
659 /* Don't call this with board->irq == 0 */
660
661 if (IS_SX_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800662 write_sx_byte(board, SX_CONFIG, SX_IRQ_REG_VAL(board) |
663 SX_CONF_BUSEN | SX_CONF_HOSTIRQ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 } else if (IS_EISA_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800665 inb(board->eisa_base + 0xc03);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 } else if (IS_SI1_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800667 write_sx_byte(board, SI1_ISA_INTCL, 0);
668 write_sx_byte(board, SI1_ISA_INTCL_CLEAR, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 } else {
670 switch (board->irq) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800671 case 11:
672 write_sx_byte(board, SI2_ISA_IRQ11, SI2_ISA_IRQ11_SET);
673 break;
674 case 12:
675 write_sx_byte(board, SI2_ISA_IRQ12, SI2_ISA_IRQ12_SET);
676 break;
677 case 15:
678 write_sx_byte(board, SI2_ISA_IRQ15, SI2_ISA_IRQ15_SET);
679 break;
680 default:
681 printk(KERN_INFO "sx: SI/XIO card doesn't support "
682 "interrupt %d.\n", board->irq);
683 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800685 write_sx_byte(board, SI2_ISA_INTCLEAR, SI2_ISA_INTCLEAR_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 }
687
688 return 1;
689}
690
Jiri Slaby15b611f2006-12-08 02:39:04 -0800691static int sx_send_command(struct sx_port *port,
692 int command, int mask, int newstat)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800694 func_enter2();
695 write_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat), command);
696 func_exit();
697 return sx_busy_wait_eq(port->board, CHAN_OFFSET(port, hi_hstat), mask,
698 newstat);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699}
700
Jiri Slaby15b611f2006-12-08 02:39:04 -0800701static char *mod_type_s(int module_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
703 switch (module_type) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800704 case TA4:
705 return "TA4";
706 case TA8:
707 return "TA8";
708 case TA4_ASIC:
709 return "TA4_ASIC";
710 case TA8_ASIC:
711 return "TA8_ASIC";
712 case MTA_CD1400:
713 return "MTA_CD1400";
714 case SXDC:
715 return "SXDC";
716 default:
717 return "Unknown/invalid";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718 }
719}
720
Jiri Slaby15b611f2006-12-08 02:39:04 -0800721static char *pan_type_s(int pan_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 switch (pan_type) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800724 case MOD_RS232DB25:
725 return "MOD_RS232DB25";
726 case MOD_RS232RJ45:
727 return "MOD_RS232RJ45";
728 case MOD_RS422DB25:
729 return "MOD_RS422DB25";
730 case MOD_PARALLEL:
731 return "MOD_PARALLEL";
732 case MOD_2_RS232DB25:
733 return "MOD_2_RS232DB25";
734 case MOD_2_RS232RJ45:
735 return "MOD_2_RS232RJ45";
736 case MOD_2_RS422DB25:
737 return "MOD_2_RS422DB25";
738 case MOD_RS232DB25MALE:
739 return "MOD_RS232DB25MALE";
740 case MOD_2_PARALLEL:
741 return "MOD_2_PARALLEL";
742 case MOD_BLANK:
743 return "empty";
744 default:
745 return "invalid";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 }
747}
748
Jiri Slaby15b611f2006-12-08 02:39:04 -0800749static int mod_compat_type(int module_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750{
751 return module_type >> 4;
752}
753
754static void sx_reconfigure_port(struct sx_port *port)
755{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800756 if (sx_read_channel_byte(port, hi_hstat) == HS_IDLE_OPEN) {
757 if (sx_send_command(port, HS_CONFIG, -1, HS_IDLE_OPEN) != 1) {
758 printk(KERN_WARNING "sx: Sent reconfigure command, but "
759 "card didn't react.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 }
761 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800762 sx_dprintk(SX_DEBUG_TERMIOS, "sx: Not sending reconfigure: "
763 "port isn't open (%02x).\n",
764 sx_read_channel_byte(port, hi_hstat));
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
Jiri Slaby15b611f2006-12-08 02:39:04 -0800768static void sx_setsignals(struct sx_port *port, int dtr, int rts)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 int t;
Jiri Slaby15b611f2006-12-08 02:39:04 -0800771 func_enter2();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772
Jiri Slaby15b611f2006-12-08 02:39:04 -0800773 t = sx_read_channel_byte(port, hi_op);
774 if (dtr >= 0)
775 t = dtr ? (t | OP_DTR) : (t & ~OP_DTR);
776 if (rts >= 0)
777 t = rts ? (t | OP_RTS) : (t & ~OP_RTS);
778 sx_write_channel_byte(port, hi_op, t);
779 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "setsignals: %d/%d\n", dtr, rts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Jiri Slaby15b611f2006-12-08 02:39:04 -0800781 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782}
783
Jiri Slaby15b611f2006-12-08 02:39:04 -0800784static int sx_getsignals(struct sx_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785{
Jiri Slaby15b611f2006-12-08 02:39:04 -0800786 int i_stat, o_stat;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
Jiri Slaby15b611f2006-12-08 02:39:04 -0800788 o_stat = sx_read_channel_byte(port, hi_op);
789 i_stat = sx_read_channel_byte(port, hi_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790
Jiri Slaby15b611f2006-12-08 02:39:04 -0800791 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "getsignals: %d/%d (%d/%d) "
792 "%02x/%02x\n",
793 (o_stat & OP_DTR) != 0, (o_stat & OP_RTS) != 0,
794 port->c_dcd, sx_get_CD(port),
795 sx_read_channel_byte(port, hi_ip),
796 sx_read_channel_byte(port, hi_state));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797
Jiri Slaby15b611f2006-12-08 02:39:04 -0800798 return (((o_stat & OP_DTR) ? TIOCM_DTR : 0) |
799 ((o_stat & OP_RTS) ? TIOCM_RTS : 0) |
800 ((i_stat & IP_CTS) ? TIOCM_CTS : 0) |
801 ((i_stat & IP_DCD) ? TIOCM_CAR : 0) |
802 ((i_stat & IP_DSR) ? TIOCM_DSR : 0) |
803 ((i_stat & IP_RI) ? TIOCM_RNG : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804}
805
Jiri Slaby15b611f2006-12-08 02:39:04 -0800806static void sx_set_baud(struct sx_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807{
808 int t;
809
810 if (port->board->ta_type == MOD_SXDC) {
811 switch (port->gs.baud) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800812 /* Save some typing work... */
813#define e(x) case x: t = BAUD_ ## x; break
814 e(50);
815 e(75);
816 e(110);
817 e(150);
818 e(200);
819 e(300);
820 e(600);
821 e(1200);
822 e(1800);
823 e(2000);
824 e(2400);
825 e(4800);
826 e(7200);
827 e(9600);
828 e(14400);
829 e(19200);
830 e(28800);
831 e(38400);
832 e(56000);
833 e(57600);
834 e(64000);
835 e(76800);
836 e(115200);
837 e(128000);
838 e(150000);
839 e(230400);
840 e(256000);
841 e(460800);
842 e(921600);
843 case 134:
844 t = BAUD_134_5;
845 break;
846 case 0:
847 t = -1;
848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 default:
850 /* Can I return "invalid"? */
851 t = BAUD_9600;
Jiri Slaby15b611f2006-12-08 02:39:04 -0800852 printk(KERN_INFO "sx: unsupported baud rate: %d.\n",
853 port->gs.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 break;
855 }
856#undef e
857 if (t > 0) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800858/* The baud rate is not set to 0, so we're enabeling DTR... -- REW */
859 sx_setsignals(port, 1, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 /* XXX This is not TA & MTA compatible */
Jiri Slaby15b611f2006-12-08 02:39:04 -0800861 sx_write_channel_byte(port, hi_csr, 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Jiri Slaby15b611f2006-12-08 02:39:04 -0800863 sx_write_channel_byte(port, hi_txbaud, t);
864 sx_write_channel_byte(port, hi_rxbaud, t);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800866 sx_setsignals(port, 0, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700867 }
868 } else {
869 switch (port->gs.baud) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800870#define e(x) case x: t = CSR_ ## x; break
871 e(75);
872 e(150);
873 e(300);
874 e(600);
875 e(1200);
876 e(2400);
877 e(4800);
878 e(1800);
879 e(9600);
880 e(19200);
881 e(57600);
882 e(38400);
883/* TA supports 110, but not 115200, MTA supports 115200, but not 110 */
884 case 110:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 if (port->board->ta_type == MOD_TA) {
886 t = CSR_110;
887 break;
888 } else {
889 t = CSR_9600;
Jiri Slaby15b611f2006-12-08 02:39:04 -0800890 printk(KERN_INFO "sx: Unsupported baud rate: "
891 "%d.\n", port->gs.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892 break;
893 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800894 case 115200:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895 if (port->board->ta_type == MOD_TA) {
896 t = CSR_9600;
Jiri Slaby15b611f2006-12-08 02:39:04 -0800897 printk(KERN_INFO "sx: Unsupported baud rate: "
898 "%d.\n", port->gs.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700899 break;
900 } else {
901 t = CSR_110;
902 break;
903 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800904 case 0:
905 t = -1;
906 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 default:
908 t = CSR_9600;
Jiri Slaby15b611f2006-12-08 02:39:04 -0800909 printk(KERN_INFO "sx: Unsupported baud rate: %d.\n",
910 port->gs.baud);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 break;
912 }
913#undef e
914 if (t >= 0) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800915 sx_setsignals(port, 1, -1);
916 sx_write_channel_byte(port, hi_csr, t * 0x11);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800918 sx_setsignals(port, 0, -1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 }
920 }
921}
922
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923/* Simon Allen's version of this routine was 225 lines long. 85 is a lot
924 better. -- REW */
925
Jiri Slaby15b611f2006-12-08 02:39:04 -0800926static int sx_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927{
928 struct sx_port *port = ptr;
929
930 func_enter2();
931
Alan Coxb5391e22008-07-16 21:55:20 +0100932 if (!port->gs.port.tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 return 0;
934
935 /* What is this doing here? -- REW
936 Ha! figured it out. It is to allow you to get DTR active again
937 if you've dropped it with stty 0. Moved to set_baud, where it
938 belongs (next to the drop dtr if baud == 0) -- REW */
939 /* sx_setsignals (port, 1, -1); */
940
Jiri Slaby15b611f2006-12-08 02:39:04 -0800941 sx_set_baud(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
Alan Coxb5391e22008-07-16 21:55:20 +0100943#define CFLAG port->gs.port.tty->termios->c_cflag
Jiri Slaby15b611f2006-12-08 02:39:04 -0800944 sx_write_channel_byte(port, hi_mr1,
Alan Coxb5391e22008-07-16 21:55:20 +0100945 (C_PARENB(port->gs.port.tty) ? MR1_WITH : MR1_NONE) |
946 (C_PARODD(port->gs.port.tty) ? MR1_ODD : MR1_EVEN) |
947 (C_CRTSCTS(port->gs.port.tty) ? MR1_RTS_RXFLOW : 0) |
Jiri Slaby15b611f2006-12-08 02:39:04 -0800948 (((CFLAG & CSIZE) == CS8) ? MR1_8_BITS : 0) |
949 (((CFLAG & CSIZE) == CS7) ? MR1_7_BITS : 0) |
950 (((CFLAG & CSIZE) == CS6) ? MR1_6_BITS : 0) |
951 (((CFLAG & CSIZE) == CS5) ? MR1_5_BITS : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Jiri Slaby15b611f2006-12-08 02:39:04 -0800953 sx_write_channel_byte(port, hi_mr2,
Alan Coxb5391e22008-07-16 21:55:20 +0100954 (C_CRTSCTS(port->gs.port.tty) ? MR2_CTS_TXFLOW : 0) |
955 (C_CSTOPB(port->gs.port.tty) ? MR2_2_STOP :
Jiri Slaby15b611f2006-12-08 02:39:04 -0800956 MR2_1_STOP));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957
958 switch (CFLAG & CSIZE) {
Jiri Slaby15b611f2006-12-08 02:39:04 -0800959 case CS8:
960 sx_write_channel_byte(port, hi_mask, 0xff);
961 break;
962 case CS7:
963 sx_write_channel_byte(port, hi_mask, 0x7f);
964 break;
965 case CS6:
966 sx_write_channel_byte(port, hi_mask, 0x3f);
967 break;
968 case CS5:
969 sx_write_channel_byte(port, hi_mask, 0x1f);
970 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971 default:
Andrew Morton32fb3ca2008-05-06 20:42:35 -0700972 printk(KERN_INFO "sx: Invalid wordsize: %u\n",
973 (unsigned int)CFLAG & CSIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 break;
975 }
976
Jiri Slaby15b611f2006-12-08 02:39:04 -0800977 sx_write_channel_byte(port, hi_prtcl,
Alan Coxb5391e22008-07-16 21:55:20 +0100978 (I_IXON(port->gs.port.tty) ? SP_TXEN : 0) |
979 (I_IXOFF(port->gs.port.tty) ? SP_RXEN : 0) |
980 (I_IXANY(port->gs.port.tty) ? SP_TANY : 0) | SP_DCEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Jiri Slaby15b611f2006-12-08 02:39:04 -0800982 sx_write_channel_byte(port, hi_break,
Alan Coxb5391e22008-07-16 21:55:20 +0100983 (I_IGNBRK(port->gs.port.tty) ? BR_IGN : 0 |
984 I_BRKINT(port->gs.port.tty) ? BR_INT : 0));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Alan Coxb5391e22008-07-16 21:55:20 +0100986 sx_write_channel_byte(port, hi_txon, START_CHAR(port->gs.port.tty));
987 sx_write_channel_byte(port, hi_rxon, START_CHAR(port->gs.port.tty));
988 sx_write_channel_byte(port, hi_txoff, STOP_CHAR(port->gs.port.tty));
989 sx_write_channel_byte(port, hi_rxoff, STOP_CHAR(port->gs.port.tty));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
991 sx_reconfigure_port(port);
992
993 /* Tell line discipline whether we will do input cooking */
Alan Coxb5391e22008-07-16 21:55:20 +0100994 if (I_OTHER(port->gs.port.tty)) {
995 clear_bit(TTY_HW_COOK_IN, &port->gs.port.tty->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996 } else {
Alan Coxb5391e22008-07-16 21:55:20 +0100997 set_bit(TTY_HW_COOK_IN, &port->gs.port.tty->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998 }
Jiri Slaby15b611f2006-12-08 02:39:04 -0800999 sx_dprintk(SX_DEBUG_TERMIOS, "iflags: %x(%d) ",
Alan Coxb5391e22008-07-16 21:55:20 +01001000 (unsigned int)port->gs.port.tty->termios->c_iflag,
1001 I_OTHER(port->gs.port.tty));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
1003/* Tell line discipline whether we will do output cooking.
1004 * If OPOST is set and no other output flags are set then we can do output
1005 * processing. Even if only *one* other flag in the O_OTHER group is set
1006 * we do cooking in software.
1007 */
Alan Coxb5391e22008-07-16 21:55:20 +01001008 if (O_OPOST(port->gs.port.tty) && !O_OTHER(port->gs.port.tty)) {
1009 set_bit(TTY_HW_COOK_OUT, &port->gs.port.tty->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 } else {
Alan Coxb5391e22008-07-16 21:55:20 +01001011 clear_bit(TTY_HW_COOK_OUT, &port->gs.port.tty->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001013 sx_dprintk(SX_DEBUG_TERMIOS, "oflags: %x(%d)\n",
Alan Coxb5391e22008-07-16 21:55:20 +01001014 (unsigned int)port->gs.port.tty->termios->c_oflag,
1015 O_OTHER(port->gs.port.tty));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 /* port->c_dcd = sx_get_CD (port); */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001017 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 return 0;
1019}
1020
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021/* ********************************************************************** *
1022 * the interrupt related routines *
1023 * ********************************************************************** */
1024
1025/* Note:
1026 Other drivers use the macro "MIN" to calculate how much to copy.
1027 This has the disadvantage that it will evaluate parts twice. That's
1028 expensive when it's IO (and the compiler cannot optimize those away!).
1029 Moreover, I'm not sure that you're race-free.
1030
1031 I assign a value, and then only allow the value to decrease. This
1032 is always safe. This makes the code a few lines longer, and you
1033 know I'm dead against that, but I think it is required in this
1034 case. */
1035
Jiri Slaby15b611f2006-12-08 02:39:04 -08001036static void sx_transmit_chars(struct sx_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037{
1038 int c;
1039 int tx_ip;
1040 int txroom;
1041
Jiri Slaby15b611f2006-12-08 02:39:04 -08001042 func_enter2();
1043 sx_dprintk(SX_DEBUG_TRANSMIT, "Port %p: transmit %d chars\n",
1044 port, port->gs.xmit_cnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Jiri Slaby15b611f2006-12-08 02:39:04 -08001046 if (test_and_set_bit(SX_PORT_TRANSMIT_LOCK, &port->locks)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 return;
1048 }
1049
1050 while (1) {
1051 c = port->gs.xmit_cnt;
1052
Jiri Slaby15b611f2006-12-08 02:39:04 -08001053 sx_dprintk(SX_DEBUG_TRANSMIT, "Copying %d ", c);
1054 tx_ip = sx_read_channel_byte(port, hi_txipos);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055
1056 /* Took me 5 minutes to deduce this formula.
1057 Luckily it is literally in the manual in section 6.5.4.3.5 */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001058 txroom = (sx_read_channel_byte(port, hi_txopos) - tx_ip - 1) &
1059 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060
1061 /* Don't copy more bytes than there is room for in the buffer */
1062 if (c > txroom)
1063 c = txroom;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001064 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, txroom);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001065
1066 /* Don't copy past the end of the hardware transmit buffer */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001067 if (c > 0x100 - tx_ip)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001068 c = 0x100 - tx_ip;
1069
Jiri Slaby15b611f2006-12-08 02:39:04 -08001070 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%d) ", c, 0x100 - tx_ip);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071
1072 /* Don't copy pas the end of the source buffer */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001073 if (c > SERIAL_XMIT_SIZE - port->gs.xmit_tail)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 c = SERIAL_XMIT_SIZE - port->gs.xmit_tail;
1075
Jiri Slaby15b611f2006-12-08 02:39:04 -08001076 sx_dprintk(SX_DEBUG_TRANSMIT, " %d(%ld) \n",
1077 c, SERIAL_XMIT_SIZE - port->gs.xmit_tail);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078
Jiri Slaby15b611f2006-12-08 02:39:04 -08001079 /* If for one reason or another, we can't copy more data, we're
1080 done! */
1081 if (c == 0)
1082 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Jiri Slaby15b611f2006-12-08 02:39:04 -08001084 memcpy_toio(port->board->base + CHAN_OFFSET(port, hi_txbuf) +
1085 tx_ip, port->gs.xmit_buf + port->gs.xmit_tail, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /* Update the pointer in the card */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001088 sx_write_channel_byte(port, hi_txipos, (tx_ip + c) & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001089
1090 /* Update the kernel buffer end */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001091 port->gs.xmit_tail = (port->gs.xmit_tail + c) &
1092 (SERIAL_XMIT_SIZE - 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 /* This one last. (this is essential)
Jiri Slaby15b611f2006-12-08 02:39:04 -08001095 It would allow others to start putting more data into the
1096 buffer! */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001097 port->gs.xmit_cnt -= c;
1098 }
1099
1100 if (port->gs.xmit_cnt == 0) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001101 sx_disable_tx_interrupts(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102 }
1103
Alan Coxb5391e22008-07-16 21:55:20 +01001104 if ((port->gs.xmit_cnt <= port->gs.wakeup_chars) && port->gs.port.tty) {
1105 tty_wakeup(port->gs.port.tty);
Jiri Slaby15b611f2006-12-08 02:39:04 -08001106 sx_dprintk(SX_DEBUG_TRANSMIT, "Waking up.... ldisc (%d)....\n",
1107 port->gs.wakeup_chars);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108 }
1109
Jiri Slaby15b611f2006-12-08 02:39:04 -08001110 clear_bit(SX_PORT_TRANSMIT_LOCK, &port->locks);
1111 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001112}
1113
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114/* Note the symmetry between receiving chars and transmitting them!
1115 Note: The kernel should have implemented both a receive buffer and
1116 a transmit buffer. */
1117
1118/* Inlined: Called only once. Remove the inline when you add another call */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001119static inline void sx_receive_chars(struct sx_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120{
1121 int c;
1122 int rx_op;
1123 struct tty_struct *tty;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001124 int copied = 0;
Alan Cox33f0f882006-01-09 20:54:13 -08001125 unsigned char *rp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126
Jiri Slaby15b611f2006-12-08 02:39:04 -08001127 func_enter2();
Alan Coxb5391e22008-07-16 21:55:20 +01001128 tty = port->gs.port.tty;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129 while (1) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001130 rx_op = sx_read_channel_byte(port, hi_rxopos);
1131 c = (sx_read_channel_byte(port, hi_rxipos) - rx_op) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Jiri Slaby15b611f2006-12-08 02:39:04 -08001133 sx_dprintk(SX_DEBUG_RECEIVE, "rxop=%d, c = %d.\n", rx_op, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
Marc Zyngierd904ffd2006-02-27 12:08:00 +01001135 /* Don't copy past the end of the hardware receive buffer */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001136 if (rx_op + c > 0x100)
1137 c = 0x100 - rx_op;
Marc Zyngierd904ffd2006-02-27 12:08:00 +01001138
Jiri Slaby15b611f2006-12-08 02:39:04 -08001139 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
Marc Zyngierd904ffd2006-02-27 12:08:00 +01001140
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141 /* Don't copy more bytes than there is room for in the buffer */
Alan Cox33f0f882006-01-09 20:54:13 -08001142
1143 c = tty_prepare_flip_string(tty, &rp, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144
Jiri Slaby15b611f2006-12-08 02:39:04 -08001145 sx_dprintk(SX_DEBUG_RECEIVE, "c = %d.\n", c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147 /* If for one reason or another, we can't copy more data, we're done! */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001148 if (c == 0)
1149 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Jiri Slaby15b611f2006-12-08 02:39:04 -08001151 sx_dprintk(SX_DEBUG_RECEIVE, "Copying over %d chars. First is "
1152 "%d at %lx\n", c, read_sx_byte(port->board,
1153 CHAN_OFFSET(port, hi_rxbuf) + rx_op),
1154 CHAN_OFFSET(port, hi_rxbuf));
1155 memcpy_fromio(rp, port->board->base +
1156 CHAN_OFFSET(port, hi_rxbuf) + rx_op, c);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 /* This one last. ( Not essential.)
Jiri Slaby15b611f2006-12-08 02:39:04 -08001159 It allows the card to start putting more data into the
1160 buffer!
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161 Update the pointer in the card */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001162 sx_write_channel_byte(port, hi_rxopos, (rx_op + c) & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163
1164 copied += c;
1165 }
1166 if (copied) {
1167 struct timeval tv;
1168
Jiri Slaby15b611f2006-12-08 02:39:04 -08001169 do_gettimeofday(&tv);
1170 sx_dprintk(SX_DEBUG_RECEIVE, "pushing flipq port %d (%3d "
1171 "chars): %d.%06d (%d/%d)\n", port->line,
1172 copied, (int)(tv.tv_sec % 60), (int)tv.tv_usec,
1173 tty->raw, tty->real_raw);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Jiri Slaby15b611f2006-12-08 02:39:04 -08001175 /* Tell the rest of the system the news. Great news. New
1176 characters! */
1177 tty_flip_buffer_push(tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 /* tty_schedule_flip (tty); */
1179 }
1180
Jiri Slaby15b611f2006-12-08 02:39:04 -08001181 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182}
1183
1184/* Inlined: it is called only once. Remove the inline if you add another
1185 call */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001186static inline void sx_check_modem_signals(struct sx_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187{
1188 int hi_state;
1189 int c_dcd;
1190
Jiri Slaby15b611f2006-12-08 02:39:04 -08001191 hi_state = sx_read_channel_byte(port, hi_state);
1192 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Checking modem signals (%d/%d)\n",
1193 port->c_dcd, sx_get_CD(port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194
1195 if (hi_state & ST_BREAK) {
1196 hi_state &= ~ST_BREAK;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001197 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a break.\n");
1198 sx_write_channel_byte(port, hi_state, hi_state);
1199 gs_got_break(&port->gs);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 }
1201 if (hi_state & ST_DCD) {
1202 hi_state &= ~ST_DCD;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001203 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "got a DCD change.\n");
1204 sx_write_channel_byte(port, hi_state, hi_state);
1205 c_dcd = sx_get_CD(port);
1206 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD is now %d\n", c_dcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 if (c_dcd != port->c_dcd) {
1208 port->c_dcd = c_dcd;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001209 if (sx_get_CD(port)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 /* DCD went UP */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001211 if ((sx_read_channel_byte(port, hi_hstat) !=
1212 HS_IDLE_CLOSED) &&
Alan Coxb5391e22008-07-16 21:55:20 +01001213 !(port->gs.port.tty->termios->
Jiri Slaby15b611f2006-12-08 02:39:04 -08001214 c_cflag & CLOCAL)) {
1215 /* Are we blocking in open? */
1216 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1217 "active, unblocking open\n");
Alan Coxb5391e22008-07-16 21:55:20 +01001218 wake_up_interruptible(&port->gs.port.
Jiri Slaby15b611f2006-12-08 02:39:04 -08001219 open_wait);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001220 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001221 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1222 "raised. Ignoring.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001223 }
1224 } else {
1225 /* DCD went down! */
Alan Coxb5391e22008-07-16 21:55:20 +01001226 if (!(port->gs.port.tty->termios->c_cflag & CLOCAL)){
Jiri Slaby15b611f2006-12-08 02:39:04 -08001227 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1228 "dropped. hanging up....\n");
Alan Coxb5391e22008-07-16 21:55:20 +01001229 tty_hangup(port->gs.port.tty);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001231 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "DCD "
1232 "dropped. ignoring.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233 }
1234 }
1235 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001236 sx_dprintk(SX_DEBUG_MODEMSIGNALS, "Hmmm. card told us "
1237 "DCD changed, but it didn't.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238 }
1239 }
1240}
1241
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242/* This is what an interrupt routine should look like.
1243 * Small, elegant, clear.
1244 */
1245
Jiri Slaby15b611f2006-12-08 02:39:04 -08001246static irqreturn_t sx_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
1248 struct sx_board *board = ptr;
1249 struct sx_port *port;
1250 int i;
1251
Jiri Slaby15b611f2006-12-08 02:39:04 -08001252 func_enter();
1253 sx_dprintk(SX_DEBUG_FLOW, "sx: enter sx_interrupt (%d/%d)\n", irq,
1254 board->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 /* AAargh! The order in which to do these things is essential and
1257 not trivial.
1258
1259 - Rate limit goes before "recursive". Otherwise a series of
Jiri Slaby15b611f2006-12-08 02:39:04 -08001260 recursive calls will hang the machine in the interrupt routine.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
1262 - hardware twiddling goes before "recursive". Otherwise when we
Jiri Slaby15b611f2006-12-08 02:39:04 -08001263 poll the card, and a recursive interrupt happens, we won't
1264 ack the card, so it might keep on interrupting us. (especially
1265 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 - Rate limit goes before hardware twiddling. Otherwise we won't
Jiri Slaby15b611f2006-12-08 02:39:04 -08001268 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
1270 - The "initialized" test goes after the hardware twiddling. Otherwise
Jiri Slaby15b611f2006-12-08 02:39:04 -08001271 the card will stick us in the interrupt routine again.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001272
1273 - The initialized test goes before recursive.
Jiri Slaby15b611f2006-12-08 02:39:04 -08001274 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276#ifdef IRQ_RATE_LIMIT
1277 /* Aaargh! I'm ashamed. This costs more lines-of-code than the
Jiri Slaby15b611f2006-12-08 02:39:04 -08001278 actual interrupt routine!. (Well, used to when I wrote that
1279 comment) */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280 {
1281 static int lastjif;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001282 static int nintr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
1284 if (lastjif == jiffies) {
1285 if (++nintr > IRQ_RATE_LIMIT) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001286 free_irq(board->irq, board);
1287 printk(KERN_ERR "sx: Too many interrupts. "
1288 "Turning off interrupt %d.\n",
1289 board->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 }
1291 } else {
1292 lastjif = jiffies;
1293 nintr = 0;
1294 }
1295 }
1296#endif
1297
Linus Torvalds1da177e2005-04-16 15:20:36 -07001298 if (board->irq == irq) {
1299 /* Tell the card we've noticed the interrupt. */
1300
Jiri Slaby15b611f2006-12-08 02:39:04 -08001301 sx_write_board_word(board, cc_int_pending, 0);
1302 if (IS_SX_BOARD(board)) {
1303 write_sx_byte(board, SX_RESET_IRQ, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 } else if (IS_EISA_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001305 inb(board->eisa_base + 0xc03);
1306 write_sx_word(board, 8, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001308 write_sx_byte(board, SI2_ISA_INTCLEAR,
1309 SI2_ISA_INTCLEAR_CLEAR);
1310 write_sx_byte(board, SI2_ISA_INTCLEAR,
1311 SI2_ISA_INTCLEAR_SET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313 }
1314
1315 if (!sx_initialized)
1316 return IRQ_HANDLED;
1317 if (!(board->flags & SX_BOARD_INITIALIZED))
1318 return IRQ_HANDLED;
1319
Jiri Slaby15b611f2006-12-08 02:39:04 -08001320 if (test_and_set_bit(SX_BOARD_INTR_LOCK, &board->locks)) {
1321 printk(KERN_ERR "Recursive interrupt! (%d)\n", board->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322 return IRQ_HANDLED;
1323 }
1324
Jiri Slaby15b611f2006-12-08 02:39:04 -08001325 for (i = 0; i < board->nports; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326 port = &board->ports[i];
Alan Coxb5391e22008-07-16 21:55:20 +01001327 if (port->gs.port.flags & GS_ACTIVE) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001328 if (sx_read_channel_byte(port, hi_state)) {
1329 sx_dprintk(SX_DEBUG_INTERRUPTS, "Port %d: "
1330 "modem signal change?... \n",i);
1331 sx_check_modem_signals(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332 }
1333 if (port->gs.xmit_cnt) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001334 sx_transmit_chars(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335 }
Alan Coxb5391e22008-07-16 21:55:20 +01001336 if (!(port->gs.port.flags & SX_RX_THROTTLE)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001337 sx_receive_chars(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 }
1339 }
1340 }
1341
Jiri Slaby15b611f2006-12-08 02:39:04 -08001342 clear_bit(SX_BOARD_INTR_LOCK, &board->locks);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Jiri Slaby15b611f2006-12-08 02:39:04 -08001344 sx_dprintk(SX_DEBUG_FLOW, "sx: exit sx_interrupt (%d/%d)\n", irq,
1345 board->irq);
1346 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001347 return IRQ_HANDLED;
1348}
1349
Jiri Slaby15b611f2006-12-08 02:39:04 -08001350static void sx_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351{
Jiri Slaby15b611f2006-12-08 02:39:04 -08001352 struct sx_board *board = (struct sx_board *)data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
Jiri Slaby15b611f2006-12-08 02:39:04 -08001354 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
Jiri Slaby15b611f2006-12-08 02:39:04 -08001356 sx_interrupt(0, board);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357
Jiri Slabyc9594642006-12-08 02:39:05 -08001358 mod_timer(&board->timer, jiffies + sx_poll);
Jiri Slaby15b611f2006-12-08 02:39:04 -08001359 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360}
1361
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362/* ********************************************************************** *
1363 * Here are the routines that actually *
1364 * interface with the generic_serial driver *
1365 * ********************************************************************** */
1366
1367/* Ehhm. I don't know how to fiddle with interrupts on the SX card. --REW */
1368/* Hmm. Ok I figured it out. You don't. */
1369
Jiri Slaby15b611f2006-12-08 02:39:04 -08001370static void sx_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001371{
Jiri Slaby15b611f2006-12-08 02:39:04 -08001372 struct sx_port *port = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 func_enter2();
1374
Alan Coxb5391e22008-07-16 21:55:20 +01001375 port->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
1377 func_exit();
1378}
1379
Jiri Slaby15b611f2006-12-08 02:39:04 -08001380static void sx_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001381{
Jiri Slaby15b611f2006-12-08 02:39:04 -08001382 struct sx_port *port = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 int data_in_buffer;
1384 func_enter2();
1385
1386 /* First transmit the characters that we're supposed to */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001387 sx_transmit_chars(port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388
1389 /* The sx card will never interrupt us if we don't fill the buffer
1390 past 25%. So we keep considering interrupts off if that's the case. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001391 data_in_buffer = (sx_read_channel_byte(port, hi_txipos) -
1392 sx_read_channel_byte(port, hi_txopos)) & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
1394 /* XXX Must be "HIGH_WATER" for SI card according to doc. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001395 if (data_in_buffer < LOW_WATER)
Alan Coxb5391e22008-07-16 21:55:20 +01001396 port->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397
1398 func_exit();
1399}
1400
Jiri Slaby15b611f2006-12-08 02:39:04 -08001401static void sx_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402{
1403 /* struct sx_port *port = ptr; */
1404 func_enter();
1405
1406 func_exit();
1407}
1408
Jiri Slaby15b611f2006-12-08 02:39:04 -08001409static void sx_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410{
1411 /* struct sx_port *port = ptr; */
1412 func_enter();
1413
1414 func_exit();
1415}
1416
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417/* Jeez. Isn't this simple? */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001418static int sx_get_CD(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419{
1420 struct sx_port *port = ptr;
1421 func_enter2();
1422
1423 func_exit();
Jiri Slaby15b611f2006-12-08 02:39:04 -08001424 return ((sx_read_channel_byte(port, hi_ip) & IP_DCD) != 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425}
1426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427/* Jeez. Isn't this simple? */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001428static int sx_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429{
1430 struct sx_port *port = ptr;
1431 func_enter2();
1432
1433 func_exit();
Jiri Slaby15b611f2006-12-08 02:39:04 -08001434 return ((sx_read_channel_byte(port, hi_txipos) -
1435 sx_read_channel_byte(port, hi_txopos)) & 0xff);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436}
1437
Jiri Slaby15b611f2006-12-08 02:39:04 -08001438static void sx_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439{
Jiri Slaby15b611f2006-12-08 02:39:04 -08001440 struct sx_port *port = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441
1442 func_enter();
1443
Alan Coxb5391e22008-07-16 21:55:20 +01001444 port->gs.port.flags &= ~GS_ACTIVE;
1445 if (port->gs.port.tty && (port->gs.port.tty->termios->c_cflag & HUPCL)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001446 sx_setsignals(port, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 sx_reconfigure_port(port);
1448 }
1449
1450 func_exit();
1451}
1452
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453/* ********************************************************************** *
1454 * Here are the routines that actually *
1455 * interface with the rest of the system *
1456 * ********************************************************************** */
1457
Jiri Slaby15b611f2006-12-08 02:39:04 -08001458static int sx_open(struct tty_struct *tty, struct file *filp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459{
1460 struct sx_port *port;
1461 int retval, line;
1462 unsigned long flags;
1463
1464 func_enter();
1465
1466 if (!sx_initialized) {
1467 return -EIO;
1468 }
1469
1470 line = tty->index;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001471 sx_dprintk(SX_DEBUG_OPEN, "%d: opening line %d. tty=%p ctty=%p, "
Pavel Emelyanovba25f9d2007-10-18 23:40:40 -07001472 "np=%d)\n", task_pid_nr(current), line, tty,
Jiri Slaby15b611f2006-12-08 02:39:04 -08001473 current->signal->tty, sx_nports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
1475 if ((line < 0) || (line >= SX_NPORTS) || (line >= sx_nports))
1476 return -ENODEV;
1477
Jiri Slaby15b611f2006-12-08 02:39:04 -08001478 port = &sx_ports[line];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 port->c_dcd = 0; /* Make sure that the first interrupt doesn't detect a
Jiri Slaby15b611f2006-12-08 02:39:04 -08001480 1 -> 0 transition. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Jiri Slaby15b611f2006-12-08 02:39:04 -08001482 sx_dprintk(SX_DEBUG_OPEN, "port = %p c_dcd = %d\n", port, port->c_dcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 spin_lock_irqsave(&port->gs.driver_lock, flags);
1485
1486 tty->driver_data = port;
Alan Coxb5391e22008-07-16 21:55:20 +01001487 port->gs.port.tty = tty;
1488 port->gs.port.count++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1490
Jiri Slaby15b611f2006-12-08 02:39:04 -08001491 sx_dprintk(SX_DEBUG_OPEN, "starting port\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
1493 /*
1494 * Start up serial port
1495 */
1496 retval = gs_init_port(&port->gs);
Jiri Slaby15b611f2006-12-08 02:39:04 -08001497 sx_dprintk(SX_DEBUG_OPEN, "done gs_init\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 if (retval) {
Alan Coxb5391e22008-07-16 21:55:20 +01001499 port->gs.port.count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 return retval;
1501 }
1502
Alan Coxb5391e22008-07-16 21:55:20 +01001503 port->gs.port.flags |= GS_ACTIVE;
1504 if (port->gs.port.count <= 1)
Jiri Slaby15b611f2006-12-08 02:39:04 -08001505 sx_setsignals(port, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507#if 0
1508 if (sx_debug & SX_DEBUG_OPEN)
Jiri Slaby15b611f2006-12-08 02:39:04 -08001509 my_hd(port, sizeof(*port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510#else
1511 if (sx_debug & SX_DEBUG_OPEN)
Jiri Slaby15b611f2006-12-08 02:39:04 -08001512 my_hd_io(port->board->base + port->ch_base, sizeof(*port));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513#endif
1514
Alan Coxb5391e22008-07-16 21:55:20 +01001515 if (port->gs.port.count <= 1) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001516 if (sx_send_command(port, HS_LOPEN, -1, HS_IDLE_OPEN) != 1) {
1517 printk(KERN_ERR "sx: Card didn't respond to LOPEN "
1518 "command.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 spin_lock_irqsave(&port->gs.driver_lock, flags);
Alan Coxb5391e22008-07-16 21:55:20 +01001520 port->gs.port.count--;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 spin_unlock_irqrestore(&port->gs.driver_lock, flags);
1522 return -EIO;
1523 }
1524 }
1525
1526 retval = gs_block_til_ready(port, filp);
Jiri Slaby15b611f2006-12-08 02:39:04 -08001527 sx_dprintk(SX_DEBUG_OPEN, "Block til ready returned %d. Count=%d\n",
Alan Coxb5391e22008-07-16 21:55:20 +01001528 retval, port->gs.port.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529
1530 if (retval) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001531/*
Alan Coxb5391e22008-07-16 21:55:20 +01001532 * Don't lower gs.port.count here because sx_close() will be called later
Jiri Slaby15b611f2006-12-08 02:39:04 -08001533 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534
1535 return retval;
1536 }
1537 /* tty->low_latency = 1; */
1538
Jiri Slaby15b611f2006-12-08 02:39:04 -08001539 port->c_dcd = sx_get_CD(port);
1540 sx_dprintk(SX_DEBUG_OPEN, "at open: cd=%d\n", port->c_dcd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541
1542 func_exit();
1543 return 0;
1544
1545}
1546
Jiri Slaby15b611f2006-12-08 02:39:04 -08001547static void sx_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548{
Jiri Slaby15b611f2006-12-08 02:39:04 -08001549 struct sx_port *port = ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 /* Give the port 5 seconds to close down. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001551 int to = 5 * HZ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Jiri Slaby15b611f2006-12-08 02:39:04 -08001553 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Jiri Slaby15b611f2006-12-08 02:39:04 -08001555 sx_setsignals(port, 0, 0);
1556 sx_reconfigure_port(port);
1557 sx_send_command(port, HS_CLOSE, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Jiri Slaby15b611f2006-12-08 02:39:04 -08001559 while (to-- && (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 if (msleep_interruptible(10))
1561 break;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001562 if (sx_read_channel_byte(port, hi_hstat) != HS_IDLE_CLOSED) {
1563 if (sx_send_command(port, HS_FORCE_CLOSED, -1, HS_IDLE_CLOSED)
1564 != 1) {
1565 printk(KERN_ERR "sx: sent the force_close command, but "
1566 "card didn't react\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567 } else
Jiri Slaby15b611f2006-12-08 02:39:04 -08001568 sx_dprintk(SX_DEBUG_CLOSE, "sent the force_close "
1569 "command.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 }
1571
Jiri Slaby15b611f2006-12-08 02:39:04 -08001572 sx_dprintk(SX_DEBUG_CLOSE, "waited %d jiffies for close. count=%d\n",
Alan Coxb5391e22008-07-16 21:55:20 +01001573 5 * HZ - to - 1, port->gs.port.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574
Alan Coxb5391e22008-07-16 21:55:20 +01001575 if (port->gs.port.count) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001576 sx_dprintk(SX_DEBUG_CLOSE, "WARNING port count:%d\n",
Alan Coxb5391e22008-07-16 21:55:20 +01001577 port->gs.port.count);
Jiri Slaby15b611f2006-12-08 02:39:04 -08001578 /*printk("%s SETTING port count to zero: %p count: %d\n",
Alan Coxb5391e22008-07-16 21:55:20 +01001579 __func__, port, port->gs.port.count);
1580 port->gs.port.count = 0;*/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 }
1582
Jiri Slaby15b611f2006-12-08 02:39:04 -08001583 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584}
1585
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586/* This is relatively thorough. But then again it is only 20 lines. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001587#define MARCHUP for (i = min; i < max; i++)
1588#define MARCHDOWN for (i = max - 1; i >= min; i--)
1589#define W0 write_sx_byte(board, i, 0x55)
1590#define W1 write_sx_byte(board, i, 0xaa)
1591#define R0 if (read_sx_byte(board, i) != 0x55) return 1
1592#define R1 if (read_sx_byte(board, i) != 0xaa) return 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594/* This memtest takes a human-noticable time. You normally only do it
1595 once a boot, so I guess that it is worth it. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001596static int do_memtest(struct sx_board *board, int min, int max)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001597{
1598 int i;
1599
1600 /* This is a marchb. Theoretically, marchb catches much more than
1601 simpler tests. In practise, the longer test just catches more
1602 intermittent errors. -- REW
1603 (For the theory behind memory testing see:
1604 Testing Semiconductor Memories by A.J. van de Goor.) */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001605 MARCHUP {
1606 W0;
1607 }
1608 MARCHUP {
1609 R0;
1610 W1;
1611 R1;
1612 W0;
1613 R0;
1614 W1;
1615 }
1616 MARCHUP {
1617 R1;
1618 W0;
1619 W1;
1620 }
1621 MARCHDOWN {
1622 R1;
1623 W0;
1624 W1;
1625 W0;
1626 }
1627 MARCHDOWN {
1628 R0;
1629 W1;
1630 W0;
1631 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632
1633 return 0;
1634}
1635
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636#undef MARCHUP
1637#undef MARCHDOWN
1638#undef W0
1639#undef W1
1640#undef R0
1641#undef R1
1642
Jiri Slaby15b611f2006-12-08 02:39:04 -08001643#define MARCHUP for (i = min; i < max; i += 2)
1644#define MARCHDOWN for (i = max - 1; i >= min; i -= 2)
1645#define W0 write_sx_word(board, i, 0x55aa)
1646#define W1 write_sx_word(board, i, 0xaa55)
1647#define R0 if (read_sx_word(board, i) != 0x55aa) return 1
1648#define R1 if (read_sx_word(board, i) != 0xaa55) return 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001649
1650#if 0
1651/* This memtest takes a human-noticable time. You normally only do it
1652 once a boot, so I guess that it is worth it. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001653static int do_memtest_w(struct sx_board *board, int min, int max)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
1655 int i;
1656
Jiri Slaby15b611f2006-12-08 02:39:04 -08001657 MARCHUP {
1658 W0;
1659 }
1660 MARCHUP {
1661 R0;
1662 W1;
1663 R1;
1664 W0;
1665 R0;
1666 W1;
1667 }
1668 MARCHUP {
1669 R1;
1670 W0;
1671 W1;
1672 }
1673 MARCHDOWN {
1674 R1;
1675 W0;
1676 W1;
1677 W0;
1678 }
1679 MARCHDOWN {
1680 R0;
1681 W1;
1682 W0;
1683 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
1685 return 0;
1686}
1687#endif
1688
Jiri Slaby15b611f2006-12-08 02:39:04 -08001689static int sx_fw_ioctl(struct inode *inode, struct file *filp,
1690 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691{
1692 int rc = 0;
1693 int __user *descr = (int __user *)arg;
1694 int i;
1695 static struct sx_board *board = NULL;
1696 int nbytes, offset;
1697 unsigned long data;
1698 char *tmp;
1699
1700 func_enter();
1701
Jiri Slaby15b611f2006-12-08 02:39:04 -08001702#if 0
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 /* Removed superuser check: Sysops can use the permissions on the device
1704 file to restrict access. Recommendation: Root only. (root.root 600) */
1705 if (!capable(CAP_SYS_ADMIN)) {
1706 return -EPERM;
1707 }
1708#endif
1709
Jiri Slaby15b611f2006-12-08 02:39:04 -08001710 sx_dprintk(SX_DEBUG_FIRMWARE, "IOCTL %x: %lx\n", cmd, arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
Jiri Slaby15b611f2006-12-08 02:39:04 -08001712 if (!board)
1713 board = &boards[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001714 if (board->flags & SX_BOARD_PRESENT) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001715 sx_dprintk(SX_DEBUG_FIRMWARE, "Board present! (%x)\n",
1716 board->flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001718 sx_dprintk(SX_DEBUG_FIRMWARE, "Board not present! (%x) all:",
1719 board->flags);
1720 for (i = 0; i < SX_NBOARDS; i++)
1721 sx_dprintk(SX_DEBUG_FIRMWARE, "<%x> ", boards[i].flags);
1722 sx_dprintk(SX_DEBUG_FIRMWARE, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 return -EIO;
1724 }
1725
1726 switch (cmd) {
1727 case SXIO_SET_BOARD:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001728 sx_dprintk(SX_DEBUG_FIRMWARE, "set board to %ld\n", arg);
1729 if (arg >= SX_NBOARDS)
1730 return -EIO;
1731 sx_dprintk(SX_DEBUG_FIRMWARE, "not out of range\n");
1732 if (!(boards[arg].flags & SX_BOARD_PRESENT))
1733 return -EIO;
1734 sx_dprintk(SX_DEBUG_FIRMWARE, ".. and present!\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 board = &boards[arg];
1736 break;
1737 case SXIO_GET_TYPE:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001738 rc = -ENOENT; /* If we manage to miss one, return error. */
1739 if (IS_SX_BOARD(board))
1740 rc = SX_TYPE_SX;
1741 if (IS_CF_BOARD(board))
1742 rc = SX_TYPE_CF;
1743 if (IS_SI_BOARD(board))
1744 rc = SX_TYPE_SI;
1745 if (IS_SI1_BOARD(board))
1746 rc = SX_TYPE_SI;
1747 if (IS_EISA_BOARD(board))
1748 rc = SX_TYPE_SI;
1749 sx_dprintk(SX_DEBUG_FIRMWARE, "returning type= %d\n", rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750 break;
1751 case SXIO_DO_RAMTEST:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001752 if (sx_initialized) /* Already initialized: better not ramtest the board. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 return -EPERM;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001754 if (IS_SX_BOARD(board)) {
1755 rc = do_memtest(board, 0, 0x7000);
1756 if (!rc)
1757 rc = do_memtest(board, 0, 0x7000);
1758 /*if (!rc) rc = do_memtest_w (board, 0, 0x7000); */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001760 rc = do_memtest(board, 0, 0x7ff8);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 /* if (!rc) rc = do_memtest_w (board, 0, 0x7ff8); */
1762 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001763 sx_dprintk(SX_DEBUG_FIRMWARE, "returning memtest result= %d\n",
1764 rc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 break;
1766 case SXIO_DOWNLOAD:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001767 if (sx_initialized) /* Already initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 return -EEXIST;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001769 if (!sx_reset(board))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770 return -EIO;
Jiri Slaby15b611f2006-12-08 02:39:04 -08001771 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Jiri Slaby15b611f2006-12-08 02:39:04 -08001773 tmp = kmalloc(SX_CHUNK_SIZE, GFP_USER);
1774 if (!tmp)
1775 return -ENOMEM;
1776 get_user(nbytes, descr++);
1777 get_user(offset, descr++);
1778 get_user(data, descr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 while (nbytes && data) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08001780 for (i = 0; i < nbytes; i += SX_CHUNK_SIZE) {
1781 if (copy_from_user(tmp, (char __user *)data + i,
1782 (i + SX_CHUNK_SIZE > nbytes) ?
1783 nbytes - i : SX_CHUNK_SIZE)) {
1784 kfree(tmp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 return -EFAULT;
1786 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001787 memcpy_toio(board->base2 + offset + i, tmp,
1788 (i + SX_CHUNK_SIZE > nbytes) ?
1789 nbytes - i : SX_CHUNK_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790 }
1791
Jiri Slaby15b611f2006-12-08 02:39:04 -08001792 get_user(nbytes, descr++);
1793 get_user(offset, descr++);
1794 get_user(data, descr++);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001796 kfree(tmp);
1797 sx_nports += sx_init_board(board);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 rc = sx_nports;
1799 break;
1800 case SXIO_INIT:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001801 if (sx_initialized) /* Already initialized */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 return -EEXIST;
1803 /* This is not allowed until all boards are initialized... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001804 for (i = 0; i < SX_NBOARDS; i++) {
1805 if ((boards[i].flags & SX_BOARD_PRESENT) &&
1806 !(boards[i].flags & SX_BOARD_INITIALIZED))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 return -EIO;
1808 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001809 for (i = 0; i < SX_NBOARDS; i++)
1810 if (!(boards[i].flags & SX_BOARD_PRESENT))
1811 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Jiri Slaby15b611f2006-12-08 02:39:04 -08001813 sx_dprintk(SX_DEBUG_FIRMWARE, "initing portstructs, %d boards, "
1814 "%d channels, first board: %d ports\n",
1815 i, sx_nports, boards[0].nports);
1816 rc = sx_init_portstructs(i, sx_nports);
1817 sx_init_drivers();
1818 if (rc >= 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 sx_initialized++;
1820 break;
1821 case SXIO_SETDEBUG:
1822 sx_debug = arg;
1823 break;
1824 case SXIO_GETDEBUG:
1825 rc = sx_debug;
1826 break;
1827 case SXIO_GETGSDEBUG:
1828 case SXIO_SETGSDEBUG:
1829 rc = -EINVAL;
1830 break;
1831 case SXIO_GETNPORTS:
1832 rc = sx_nports;
1833 break;
1834 default:
Jiri Slaby15b611f2006-12-08 02:39:04 -08001835 printk(KERN_WARNING "Unknown ioctl on firmware device (%x).\n",
1836 cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837 break;
1838 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08001839 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 return rc;
1841}
1842
Alan Cox9e989662008-07-22 11:18:03 +01001843static int sx_break(struct tty_struct *tty, int flag)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844{
1845 struct sx_port *port = tty->driver_data;
1846 int rv;
1847
Jiri Slaby15b611f2006-12-08 02:39:04 -08001848 func_enter();
Alan Cox341339e2008-04-30 00:53:24 -07001849 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Jiri Slaby15b611f2006-12-08 02:39:04 -08001851 if (flag)
1852 rv = sx_send_command(port, HS_START, -1, HS_IDLE_BREAK);
1853 else
1854 rv = sx_send_command(port, HS_STOP, -1, HS_IDLE_OPEN);
1855 if (rv != 1)
1856 printk(KERN_ERR "sx: couldn't send break (%x).\n",
1857 read_sx_byte(port->board, CHAN_OFFSET(port, hi_hstat)));
Alan Cox341339e2008-04-30 00:53:24 -07001858 unlock_kernel();
Jiri Slaby15b611f2006-12-08 02:39:04 -08001859 func_exit();
Alan Cox9e989662008-07-22 11:18:03 +01001860 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861}
1862
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863static int sx_tiocmget(struct tty_struct *tty, struct file *file)
1864{
1865 struct sx_port *port = tty->driver_data;
1866 return sx_getsignals(port);
1867}
1868
1869static int sx_tiocmset(struct tty_struct *tty, struct file *file,
Jiri Slaby15b611f2006-12-08 02:39:04 -08001870 unsigned int set, unsigned int clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871{
1872 struct sx_port *port = tty->driver_data;
1873 int rts = -1, dtr = -1;
1874
1875 if (set & TIOCM_RTS)
1876 rts = 1;
1877 if (set & TIOCM_DTR)
1878 dtr = 1;
1879 if (clear & TIOCM_RTS)
1880 rts = 0;
1881 if (clear & TIOCM_DTR)
1882 dtr = 0;
1883
1884 sx_setsignals(port, dtr, rts);
1885 sx_reconfigure_port(port);
1886 return 0;
1887}
1888
Jiri Slaby15b611f2006-12-08 02:39:04 -08001889static int sx_ioctl(struct tty_struct *tty, struct file *filp,
1890 unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891{
1892 int rc;
1893 struct sx_port *port = tty->driver_data;
1894 void __user *argp = (void __user *)arg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 /* func_enter2(); */
1897
1898 rc = 0;
Alan Cox341339e2008-04-30 00:53:24 -07001899 lock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 case TIOCGSERIAL:
1902 rc = gs_getserial(&port->gs, argp);
1903 break;
1904 case TIOCSSERIAL:
1905 rc = gs_setserial(&port->gs, argp);
1906 break;
1907 default:
1908 rc = -ENOIOCTLCMD;
1909 break;
1910 }
Alan Cox341339e2008-04-30 00:53:24 -07001911 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
1913 /* func_exit(); */
1914 return rc;
1915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917/* The throttle/unthrottle scheme for the Specialix card is different
1918 * from other drivers and deserves some explanation.
1919 * The Specialix hardware takes care of XON/XOFF
1920 * and CTS/RTS flow control itself. This means that all we have to
1921 * do when signalled by the upper tty layer to throttle/unthrottle is
1922 * to make a note of it here. When we come to read characters from the
1923 * rx buffers on the card (sx_receive_chars()) we look to see if the
1924 * upper layer can accept more (as noted here in sx_rx_throt[]).
1925 * If it can't we simply don't remove chars from the cards buffer.
1926 * When the tty layer can accept chars, we again note that here and when
1927 * sx_receive_chars() is called it will remove them from the cards buffer.
1928 * The card will notice that a ports buffer has drained below some low
1929 * water mark and will unflow control the line itself, using whatever
1930 * flow control scheme is in use for that port. -- Simon Allen
1931 */
1932
Jiri Slaby15b611f2006-12-08 02:39:04 -08001933static void sx_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934{
1935 struct sx_port *port = (struct sx_port *)tty->driver_data;
1936
1937 func_enter2();
1938 /* If the port is using any type of input flow
1939 * control then throttle the port.
1940 */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001941 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
Alan Coxb5391e22008-07-16 21:55:20 +01001942 port->gs.port.flags |= SX_RX_THROTTLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 }
1944 func_exit();
1945}
1946
Jiri Slaby15b611f2006-12-08 02:39:04 -08001947static void sx_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948{
1949 struct sx_port *port = (struct sx_port *)tty->driver_data;
1950
1951 func_enter2();
1952 /* Always unthrottle even if flow control is not enabled on
1953 * this port in case we disabled flow control while the port
1954 * was throttled
1955 */
Alan Coxb5391e22008-07-16 21:55:20 +01001956 port->gs.port.flags &= ~SX_RX_THROTTLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 func_exit();
1958 return;
1959}
1960
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961/* ********************************************************************** *
1962 * Here are the initialization routines. *
1963 * ********************************************************************** */
1964
Jiri Slaby15b611f2006-12-08 02:39:04 -08001965static int sx_init_board(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966{
1967 int addr;
1968 int chans;
1969 int type;
1970
1971 func_enter();
1972
1973 /* This is preceded by downloading the download code. */
1974
1975 board->flags |= SX_BOARD_INITIALIZED;
1976
Jiri Slaby15b611f2006-12-08 02:39:04 -08001977 if (read_sx_byte(board, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978 /* CF boards may need this. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001979 write_sx_byte(board, 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 /* This resets the processor again, to make sure it didn't do any
1982 foolish things while we were downloading the image */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001983 if (!sx_reset(board))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 return 0;
1985
Jiri Slaby15b611f2006-12-08 02:39:04 -08001986 sx_start_board(board);
1987 udelay(10);
1988 if (!sx_busy_wait_neq(board, 0, 0xff, 0)) {
1989 printk(KERN_ERR "sx: Ooops. Board won't initialize.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 return 0;
1991 }
1992
1993 /* Ok. So now the processor on the card is running. It gathered
1994 some info for us... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08001995 sx_dprintk(SX_DEBUG_INIT, "The sxcard structure:\n");
1996 if (sx_debug & SX_DEBUG_INIT)
1997 my_hd_io(board->base, 0x10);
1998 sx_dprintk(SX_DEBUG_INIT, "the first sx_module structure:\n");
1999 if (sx_debug & SX_DEBUG_INIT)
2000 my_hd_io(board->base + 0x80, 0x30);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001
Jiri Slaby15b611f2006-12-08 02:39:04 -08002002 sx_dprintk(SX_DEBUG_INIT, "init_status: %x, %dk memory, firmware "
2003 "V%x.%02x,\n",
2004 read_sx_byte(board, 0), read_sx_byte(board, 1),
2005 read_sx_byte(board, 5), read_sx_byte(board, 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
Jiri Slaby15b611f2006-12-08 02:39:04 -08002007 if (read_sx_byte(board, 0) == 0xff) {
2008 printk(KERN_INFO "sx: No modules found. Sorry.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 board->nports = 0;
2010 return 0;
2011 }
2012
2013 chans = 0;
2014
2015 if (IS_SX_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002016 sx_write_board_word(board, cc_int_count, sx_maxints);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 } else {
2018 if (sx_maxints)
Jiri Slaby15b611f2006-12-08 02:39:04 -08002019 sx_write_board_word(board, cc_int_count,
2020 SI_PROCESSOR_CLOCK / 8 / sx_maxints);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 }
2022
2023 /* grab the first module type... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002024 /* board->ta_type = mod_compat_type (read_sx_byte (board, 0x80 + 0x08)); */
2025 board->ta_type = mod_compat_type(sx_read_module_byte(board, 0x80,
2026 mc_chip));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
2028 /* XXX byteorder */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002029 for (addr = 0x80; addr != 0; addr = read_sx_word(board, addr) & 0x7fff){
2030 type = sx_read_module_byte(board, addr, mc_chip);
2031 sx_dprintk(SX_DEBUG_INIT, "Module at %x: %d channels\n",
2032 addr, read_sx_byte(board, addr + 2));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Jiri Slaby15b611f2006-12-08 02:39:04 -08002034 chans += sx_read_module_byte(board, addr, mc_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Jiri Slaby15b611f2006-12-08 02:39:04 -08002036 sx_dprintk(SX_DEBUG_INIT, "module is an %s, which has %s/%s "
2037 "panels\n",
2038 mod_type_s(type),
2039 pan_type_s(sx_read_module_byte(board, addr,
2040 mc_mods) & 0xf),
2041 pan_type_s(sx_read_module_byte(board, addr,
2042 mc_mods) >> 4));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
Jiri Slaby15b611f2006-12-08 02:39:04 -08002044 sx_dprintk(SX_DEBUG_INIT, "CD1400 versions: %x/%x, ASIC "
2045 "version: %x\n",
2046 sx_read_module_byte(board, addr, mc_rev1),
2047 sx_read_module_byte(board, addr, mc_rev2),
2048 sx_read_module_byte(board, addr, mc_mtaasic_rev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
2050 /* The following combinations are illegal: It should theoretically
2051 work, but timing problems make the bus HANG. */
2052
Jiri Slaby15b611f2006-12-08 02:39:04 -08002053 if (mod_compat_type(type) != board->ta_type) {
2054 printk(KERN_ERR "sx: This is an invalid "
2055 "configuration.\nDon't mix TA/MTA/SXDC on the "
2056 "same hostadapter.\n");
2057 chans = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 break;
2059 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002060 if ((IS_EISA_BOARD(board) ||
2061 IS_SI_BOARD(board)) &&
2062 (mod_compat_type(type) == 4)) {
2063 printk(KERN_ERR "sx: This is an invalid "
2064 "configuration.\nDon't use SXDCs on an SI/XIO "
2065 "adapter.\n");
2066 chans = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 break;
2068 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002069#if 0 /* Problem fixed: firmware 3.05 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 if (IS_SX_BOARD(board) && (type == TA8)) {
2071 /* There are some issues with the firmware and the DCD/RTS
2072 lines. It might work if you tie them together or something.
Jiri Slaby15b611f2006-12-08 02:39:04 -08002073 It might also work if you get a newer sx_firmware. Therefore
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 this is just a warning. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002075 printk(KERN_WARNING
2076 "sx: The SX host doesn't work too well "
2077 "with the TA8 adapters.\nSpecialix is working on it.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 }
2079#endif
2080 }
2081
2082 if (chans) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002083 if (board->irq > 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 /* fixed irq, probably PCI */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002085 if (sx_irqmask & (1 << board->irq)) { /* may we use this irq? */
2086 if (request_irq(board->irq, sx_interrupt,
2087 IRQF_SHARED | IRQF_DISABLED,
2088 "sx", board)) {
2089 printk(KERN_ERR "sx: Cannot allocate "
2090 "irq %d.\n", board->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 board->irq = 0;
2092 }
2093 } else
2094 board->irq = 0;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002095 } else if (board->irq < 0 && sx_irqmask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096 /* auto-allocate irq */
2097 int irqnr;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002098 int irqmask = sx_irqmask & (IS_SX_BOARD(board) ?
2099 SX_ISA_IRQ_MASK : SI2_ISA_IRQ_MASK);
2100 for (irqnr = 15; irqnr > 0; irqnr--)
2101 if (irqmask & (1 << irqnr))
2102 if (!request_irq(irqnr, sx_interrupt,
2103 IRQF_SHARED | IRQF_DISABLED,
2104 "sx", board))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 break;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002106 if (!irqnr)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 printk(KERN_ERR "sx: Cannot allocate IRQ.\n");
2108 board->irq = irqnr;
2109 } else
2110 board->irq = 0;
2111
2112 if (board->irq) {
2113 /* Found a valid interrupt, start up interrupts! */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002114 sx_dprintk(SX_DEBUG_INIT, "Using irq %d.\n",
2115 board->irq);
2116 sx_start_interrupts(board);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 board->poll = sx_slowpoll;
2118 board->flags |= SX_IRQ_ALLOCATED;
2119 } else {
2120 /* no irq: setup board for polled operation */
2121 board->poll = sx_poll;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002122 sx_dprintk(SX_DEBUG_INIT, "Using poll-interval %d.\n",
2123 board->poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 }
2125
Jiri Slaby15b611f2006-12-08 02:39:04 -08002126 /* The timer should be initialized anyway: That way we can
2127 safely del_timer it when the module is unloaded. */
Jiri Slabyc9594642006-12-08 02:39:05 -08002128 setup_timer(&board->timer, sx_pollfunc, (unsigned long)board);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
Jiri Slabyc9594642006-12-08 02:39:05 -08002130 if (board->poll)
2131 mod_timer(&board->timer, jiffies + board->poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 } else {
2133 board->irq = 0;
2134 }
2135
2136 board->nports = chans;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002137 sx_dprintk(SX_DEBUG_INIT, "returning %d ports.", board->nports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 func_exit();
2140 return chans;
2141}
2142
Jiri Slabycda52652006-12-08 02:39:00 -08002143static void __devinit printheader(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144{
2145 static int header_printed;
2146
2147 if (!header_printed) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002148 printk(KERN_INFO "Specialix SX driver "
2149 "(C) 1998/1999 R.E.Wolff@BitWizard.nl\n");
2150 printk(KERN_INFO "sx: version " __stringify(SX_VERSION) "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 header_printed = 1;
2152 }
2153}
2154
Jiri Slaby15b611f2006-12-08 02:39:04 -08002155static int __devinit probe_sx(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156{
2157 struct vpd_prom vpdp;
2158 char *p;
2159 int i;
2160
2161 func_enter();
2162
Jiri Slaby15b611f2006-12-08 02:39:04 -08002163 if (!IS_CF_BOARD(board)) {
2164 sx_dprintk(SX_DEBUG_PROBE, "Going to verify vpd prom at %p.\n",
2165 board->base + SX_VPD_ROM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 if (sx_debug & SX_DEBUG_PROBE)
2168 my_hd_io(board->base + SX_VPD_ROM, 0x40);
2169
Jiri Slaby15b611f2006-12-08 02:39:04 -08002170 p = (char *)&vpdp;
2171 for (i = 0; i < sizeof(struct vpd_prom); i++)
2172 *p++ = read_sx_byte(board, SX_VPD_ROM + i * 2);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002173
2174 if (sx_debug & SX_DEBUG_PROBE)
Jiri Slaby15b611f2006-12-08 02:39:04 -08002175 my_hd(&vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176
Jiri Slaby15b611f2006-12-08 02:39:04 -08002177 sx_dprintk(SX_DEBUG_PROBE, "checking identifier...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178
Jiri Slaby15b611f2006-12-08 02:39:04 -08002179 if (strncmp(vpdp.identifier, SX_VPD_IDENT_STRING, 16) != 0) {
2180 sx_dprintk(SX_DEBUG_PROBE, "Got non-SX identifier: "
2181 "'%s'\n", vpdp.identifier);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 return 0;
2183 }
2184 }
2185
Jiri Slaby15b611f2006-12-08 02:39:04 -08002186 printheader();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
Jiri Slaby15b611f2006-12-08 02:39:04 -08002188 if (!IS_CF_BOARD(board)) {
2189 printk(KERN_DEBUG "sx: Found an SX board at %lx\n",
2190 board->hw_base);
2191 printk(KERN_DEBUG "sx: hw_rev: %d, assembly level: %d, "
2192 "uniq ID:%08x, ",
2193 vpdp.hwrev, vpdp.hwass, vpdp.uniqid);
2194 printk("Manufactured: %d/%d\n", 1970 + vpdp.myear, vpdp.mweek);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
Jiri Slaby15b611f2006-12-08 02:39:04 -08002196 if ((((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) !=
2197 SX_PCI_UNIQUEID1) && (((vpdp.uniqid >> 24) &
2198 SX_UNIQUEID_MASK) != SX_ISA_UNIQUEID1)) {
2199 /* This might be a bit harsh. This was the primary
2200 reason the SX/ISA card didn't work at first... */
2201 printk(KERN_ERR "sx: Hmm. Not an SX/PCI or SX/ISA "
2202 "card. Sorry: giving up.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 return (0);
2204 }
2205
Jiri Slaby15b611f2006-12-08 02:39:04 -08002206 if (((vpdp.uniqid >> 24) & SX_UNIQUEID_MASK) ==
2207 SX_ISA_UNIQUEID1) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 if (((unsigned long)board->hw_base) & 0x8000) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002209 printk(KERN_WARNING "sx: Warning: There may be "
2210 "hardware problems with the card at "
2211 "%lx.\n", board->hw_base);
2212 printk(KERN_WARNING "sx: Read sx.txt for more "
2213 "info.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 }
2215 }
2216 }
2217
2218 board->nports = -1;
2219
2220 /* This resets the processor, and keeps it off the bus. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002221 if (!sx_reset(board))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002222 return 0;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002223 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 func_exit();
2226 return 1;
2227}
2228
Jiri Slaby927a6f92006-12-08 02:39:02 -08002229#if defined(CONFIG_ISA) || defined(CONFIG_EISA)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231/* Specialix probes for this card at 32k increments from 640k to 16M.
2232 I consider machines with less than 16M unlikely nowadays, so I'm
2233 not probing above 1Mb. Also, 0xa0000, 0xb0000, are taken by the VGA
2234 card. 0xe0000 and 0xf0000 are taken by the BIOS. That only leaves
2235 0xc0000, 0xc8000, 0xd0000 and 0xd8000 . */
2236
Jiri Slaby15b611f2006-12-08 02:39:04 -08002237static int __devinit probe_si(struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002238{
2239 int i;
2240
2241 func_enter();
Jiri Slaby15b611f2006-12-08 02:39:04 -08002242 sx_dprintk(SX_DEBUG_PROBE, "Going to verify SI signature hw %lx at "
2243 "%p.\n", board->hw_base, board->base + SI2_ISA_ID_BASE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244
2245 if (sx_debug & SX_DEBUG_PROBE)
2246 my_hd_io(board->base + SI2_ISA_ID_BASE, 0x8);
2247
2248 if (!IS_EISA_BOARD(board)) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002249 if (IS_SI1_BOARD(board)) {
2250 for (i = 0; i < 8; i++) {
2251 write_sx_byte(board, SI2_ISA_ID_BASE + 7 - i,i);
2252 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002253 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002254 for (i = 0; i < 8; i++) {
2255 if ((read_sx_byte(board, SI2_ISA_ID_BASE + 7 - i) & 7)
2256 != i) {
2257 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 return 0;
2259 }
2260 }
2261 }
2262
2263 /* Now we're pretty much convinced that there is an SI board here,
2264 but to prevent trouble, we'd better double check that we don't
2265 have an SI1 board when we're probing for an SI2 board.... */
2266
Jiri Slaby15b611f2006-12-08 02:39:04 -08002267 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2268 if (IS_SI1_BOARD(board)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269 /* This should be an SI1 board, which has this
2270 location writable... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002271 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
2272 func_exit();
2273 return 0;
Marc Zyngier04a3d312006-02-26 12:02:56 +01002274 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 } else {
2276 /* This should be an SI2 board, which has the bottom
2277 3 bits non-writable... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002278 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2279 func_exit();
2280 return 0;
Marc Zyngier04a3d312006-02-26 12:02:56 +01002281 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 }
2283
2284 /* Now we're pretty much convinced that there is an SI board here,
2285 but to prevent trouble, we'd better double check that we don't
2286 have an SI1 board when we're probing for an SI2 board.... */
2287
Jiri Slaby15b611f2006-12-08 02:39:04 -08002288 write_sx_byte(board, SI2_ISA_ID_BASE, 0x10);
2289 if (IS_SI1_BOARD(board)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 /* This should be an SI1 board, which has this
2291 location writable... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002292 if (read_sx_byte(board, SI2_ISA_ID_BASE) != 0x10) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 func_exit();
Jiri Slaby15b611f2006-12-08 02:39:04 -08002294 return 0;
Marc Zyngier04a3d312006-02-26 12:02:56 +01002295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 } else {
2297 /* This should be an SI2 board, which has the bottom
2298 3 bits non-writable... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002299 if (read_sx_byte(board, SI2_ISA_ID_BASE) == 0x10) {
2300 func_exit();
2301 return 0;
Marc Zyngier04a3d312006-02-26 12:02:56 +01002302 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303 }
2304
Jiri Slaby15b611f2006-12-08 02:39:04 -08002305 printheader();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306
Jiri Slaby15b611f2006-12-08 02:39:04 -08002307 printk(KERN_DEBUG "sx: Found an SI board at %lx\n", board->hw_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002308 /* Compared to the SX boards, it is a complete guess as to what
Jiri Slaby15b611f2006-12-08 02:39:04 -08002309 this card is up to... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002310
2311 board->nports = -1;
2312
2313 /* This resets the processor, and keeps it off the bus. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002314 if (!sx_reset(board))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002315 return 0;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002316 sx_dprintk(SX_DEBUG_INIT, "reset the board...\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 func_exit();
2319 return 1;
2320}
Jiri Slaby927a6f92006-12-08 02:39:02 -08002321#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322
Jeff Dikeb68e31d2006-10-02 02:17:18 -07002323static const struct tty_operations sx_ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 .break_ctl = sx_break,
Jiri Slaby15b611f2006-12-08 02:39:04 -08002325 .open = sx_open,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 .close = gs_close,
2327 .write = gs_write,
2328 .put_char = gs_put_char,
2329 .flush_chars = gs_flush_chars,
2330 .write_room = gs_write_room,
2331 .chars_in_buffer = gs_chars_in_buffer,
2332 .flush_buffer = gs_flush_buffer,
2333 .ioctl = sx_ioctl,
2334 .throttle = sx_throttle,
2335 .unthrottle = sx_unthrottle,
2336 .set_termios = gs_set_termios,
2337 .stop = gs_stop,
2338 .start = gs_start,
2339 .hangup = gs_hangup,
2340 .tiocmget = sx_tiocmget,
2341 .tiocmset = sx_tiocmset,
2342};
2343
2344static int sx_init_drivers(void)
2345{
2346 int error;
2347
2348 func_enter();
2349
2350 sx_driver = alloc_tty_driver(sx_nports);
2351 if (!sx_driver)
2352 return 1;
2353 sx_driver->owner = THIS_MODULE;
2354 sx_driver->driver_name = "specialix_sx";
2355 sx_driver->name = "ttyX";
2356 sx_driver->major = SX_NORMAL_MAJOR;
2357 sx_driver->type = TTY_DRIVER_TYPE_SERIAL;
2358 sx_driver->subtype = SERIAL_TYPE_NORMAL;
2359 sx_driver->init_termios = tty_std_termios;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002360 sx_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
Alan Cox606d0992006-12-08 02:38:45 -08002361 sx_driver->init_termios.c_ispeed = 9600;
2362 sx_driver->init_termios.c_ospeed = 9600;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 sx_driver->flags = TTY_DRIVER_REAL_RAW;
2364 tty_set_operations(sx_driver, &sx_ops);
2365
2366 if ((error = tty_register_driver(sx_driver))) {
2367 put_tty_driver(sx_driver);
2368 printk(KERN_ERR "sx: Couldn't register sx driver, error = %d\n",
Jiri Slaby15b611f2006-12-08 02:39:04 -08002369 error);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 return 1;
2371 }
2372 func_exit();
2373 return 0;
2374}
2375
Jiri Slaby15b611f2006-12-08 02:39:04 -08002376static int sx_init_portstructs(int nboards, int nports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377{
2378 struct sx_board *board;
2379 struct sx_port *port;
2380 int i, j;
2381 int addr, chans;
2382 int portno;
2383
2384 func_enter();
2385
2386 /* Many drivers statically allocate the maximum number of ports
Jiri Slaby15b611f2006-12-08 02:39:04 -08002387 There is no reason not to allocate them dynamically.
2388 Is there? -- REW */
Jiri Slaby4a7cb692006-12-08 02:38:59 -08002389 sx_ports = kcalloc(nports, sizeof(struct sx_port), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (!sx_ports)
2391 return -ENOMEM;
2392
2393 port = sx_ports;
2394 for (i = 0; i < nboards; i++) {
2395 board = &boards[i];
2396 board->ports = port;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002397 for (j = 0; j < boards[i].nports; j++) {
2398 sx_dprintk(SX_DEBUG_INIT, "initing port %d\n", j);
Alan Cox44b7d1b2008-07-16 21:57:18 +01002399 tty_port_init(&port->gs.port);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400 port->gs.magic = SX_MAGIC;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002401 port->gs.close_delay = HZ / 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 port->gs.closing_wait = 30 * HZ;
2403 port->board = board;
2404 port->gs.rd = &sx_real_driver;
2405#ifdef NEW_WRITE_LOCKING
Ingo Molnar81861d72006-03-23 03:00:44 -08002406 port->gs.port_write_mutex = MUTEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407#endif
Ingo Molnar34af9462006-06-27 02:53:55 -07002408 spin_lock_init(&port->gs.driver_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 /*
2410 * Initializing wait queue
2411 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 port++;
2413 }
2414 }
2415
2416 port = sx_ports;
2417 portno = 0;
2418 for (i = 0; i < nboards; i++) {
2419 board = &boards[i];
2420 board->port_base = portno;
2421 /* Possibly the configuration was rejected. */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002422 sx_dprintk(SX_DEBUG_PROBE, "Board has %d channels\n",
2423 board->nports);
2424 if (board->nports <= 0)
2425 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 /* XXX byteorder ?? */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002427 for (addr = 0x80; addr != 0;
2428 addr = read_sx_word(board, addr) & 0x7fff) {
2429 chans = sx_read_module_byte(board, addr, mc_type);
2430 sx_dprintk(SX_DEBUG_PROBE, "Module at %x: %d "
2431 "channels\n", addr, chans);
2432 sx_dprintk(SX_DEBUG_PROBE, "Port at");
2433 for (j = 0; j < chans; j++) {
2434 /* The "sx-way" is the way it SHOULD be done.
2435 That way in the future, the firmware may for
2436 example pack the structures a bit more
2437 efficient. Neil tells me it isn't going to
2438 happen anytime soon though. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 if (IS_SX_BOARD(board))
Jiri Slaby15b611f2006-12-08 02:39:04 -08002440 port->ch_base = sx_read_module_word(
2441 board, addr + j * 2,
2442 mc_chan_pointer);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 else
Jiri Slaby15b611f2006-12-08 02:39:04 -08002444 port->ch_base = addr + 0x100 + 0x300 *j;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445
Jiri Slaby15b611f2006-12-08 02:39:04 -08002446 sx_dprintk(SX_DEBUG_PROBE, " %x",
2447 port->ch_base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 port->line = portno++;
2449 port++;
2450 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002451 sx_dprintk(SX_DEBUG_PROBE, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 }
2453 /* This has to be done earlier. */
2454 /* board->flags |= SX_BOARD_INITIALIZED; */
2455 }
2456
2457 func_exit();
2458 return 0;
2459}
2460
Jiri Slaby18f813e2006-12-08 02:39:01 -08002461static unsigned int sx_find_free_board(void)
2462{
2463 unsigned int i;
2464
Jiri Slaby15b611f2006-12-08 02:39:04 -08002465 for (i = 0; i < SX_NBOARDS; i++)
Jiri Slaby18f813e2006-12-08 02:39:01 -08002466 if (!(boards[i].flags & SX_BOARD_PRESENT))
2467 break;
2468
2469 return i;
2470}
2471
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472static void __exit sx_release_drivers(void)
2473{
2474 func_enter();
2475 tty_unregister_driver(sx_driver);
2476 put_tty_driver(sx_driver);
2477 func_exit();
2478}
2479
Jiri Slaby39103492006-12-08 02:39:07 -08002480static void __devexit sx_remove_card(struct sx_board *board,
2481 struct pci_dev *pdev)
Jiri Slaby18f813e2006-12-08 02:39:01 -08002482{
2483 if (board->flags & SX_BOARD_INITIALIZED) {
2484 /* The board should stop messing with us. (actually I mean the
2485 interrupt) */
2486 sx_reset(board);
2487 if ((board->irq) && (board->flags & SX_IRQ_ALLOCATED))
2488 free_irq(board->irq, board);
2489
2490 /* It is safe/allowed to del_timer a non-active timer */
2491 del_timer(&board->timer);
Jiri Slaby30f42182006-12-08 02:39:08 -08002492 if (pdev) {
Jiri Slaby3468a332006-12-13 00:34:20 -08002493#ifdef CONFIG_PCI
Jiri Slaby39103492006-12-08 02:39:07 -08002494 pci_iounmap(pdev, board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002495 pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
Jiri Slaby3468a332006-12-13 00:34:20 -08002496#endif
Jiri Slaby30f42182006-12-08 02:39:08 -08002497 } else {
Jiri Slaby39103492006-12-08 02:39:07 -08002498 iounmap(board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002499 release_region(board->hw_base, board->hw_len);
2500 }
Jiri Slaby18f813e2006-12-08 02:39:01 -08002501
Jiri Slaby15b611f2006-12-08 02:39:04 -08002502 board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002503 }
2504}
2505
2506#ifdef CONFIG_EISA
2507
2508static int __devinit sx_eisa_probe(struct device *dev)
2509{
2510 struct eisa_device *edev = to_eisa_device(dev);
2511 struct sx_board *board;
2512 unsigned long eisa_slot = edev->base_addr;
2513 unsigned int i;
2514 int retval = -EIO;
2515
Jiri Slaby42f63842006-12-08 02:39:03 -08002516 mutex_lock(&sx_boards_lock);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002517 i = sx_find_free_board();
Jiri Slaby42f63842006-12-08 02:39:03 -08002518 if (i == SX_NBOARDS) {
2519 mutex_unlock(&sx_boards_lock);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002520 goto err;
Jiri Slaby42f63842006-12-08 02:39:03 -08002521 }
2522 board = &boards[i];
2523 board->flags |= SX_BOARD_PRESENT;
2524 mutex_unlock(&sx_boards_lock);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002525
2526 dev_info(dev, "XIO : Signature found in EISA slot %lu, "
Jiri Slaby15b611f2006-12-08 02:39:04 -08002527 "Product %d Rev %d (REPORT THIS TO LKLM)\n",
2528 eisa_slot >> 12,
2529 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 2),
2530 inb(eisa_slot + EISA_VENDOR_ID_OFFSET + 3));
Jiri Slaby18f813e2006-12-08 02:39:01 -08002531
Jiri Slaby18f813e2006-12-08 02:39:01 -08002532 board->eisa_base = eisa_slot;
2533 board->flags &= ~SX_BOARD_TYPE;
2534 board->flags |= SI_EISA_BOARD;
2535
2536 board->hw_base = ((inb(eisa_slot + 0xc01) << 8) +
Jiri Slaby15b611f2006-12-08 02:39:04 -08002537 inb(eisa_slot + 0xc00)) << 16;
Jiri Slaby30f42182006-12-08 02:39:08 -08002538 board->hw_len = SI2_EISA_WINDOW_LEN;
2539 if (!request_region(board->hw_base, board->hw_len, "sx")) {
2540 dev_err(dev, "can't request region\n");
2541 goto err_flag;
2542 }
Jiri Slaby18f813e2006-12-08 02:39:01 -08002543 board->base2 =
Alan Cox24cb2332008-04-30 00:54:19 -07002544 board->base = ioremap_nocache(board->hw_base, SI2_EISA_WINDOW_LEN);
Jiri Slaby30f42182006-12-08 02:39:08 -08002545 if (!board->base) {
2546 dev_err(dev, "can't remap memory\n");
2547 goto err_reg;
2548 }
Jiri Slaby18f813e2006-12-08 02:39:01 -08002549
2550 sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
2551 sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
2552 board->irq = inb(eisa_slot + 0xc02) >> 4;
2553 sx_dprintk(SX_DEBUG_PROBE, "IRQ: %d\n", board->irq);
2554
2555 if (!probe_si(board))
2556 goto err_unmap;
2557
2558 dev_set_drvdata(dev, board);
2559
2560 return 0;
2561err_unmap:
2562 iounmap(board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002563err_reg:
2564 release_region(board->hw_base, board->hw_len);
2565err_flag:
Jiri Slaby42f63842006-12-08 02:39:03 -08002566 board->flags &= ~SX_BOARD_PRESENT;
Jiri Slaby18f813e2006-12-08 02:39:01 -08002567err:
2568 return retval;
2569}
2570
2571static int __devexit sx_eisa_remove(struct device *dev)
2572{
2573 struct sx_board *board = dev_get_drvdata(dev);
2574
Jiri Slaby39103492006-12-08 02:39:07 -08002575 sx_remove_card(board, NULL);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002576
2577 return 0;
2578}
2579
2580static struct eisa_device_id sx_eisa_tbl[] = {
2581 { "SLX" },
2582 { "" }
2583};
Jiri Slaby15b611f2006-12-08 02:39:04 -08002584
Jiri Slaby18f813e2006-12-08 02:39:01 -08002585MODULE_DEVICE_TABLE(eisa, sx_eisa_tbl);
2586
2587static struct eisa_driver sx_eisadriver = {
2588 .id_table = sx_eisa_tbl,
2589 .driver = {
2590 .name = "sx",
2591 .probe = sx_eisa_probe,
2592 .remove = __devexit_p(sx_eisa_remove),
2593 }
2594};
2595
2596#endif
2597
Jiri Slaby3468a332006-12-13 00:34:20 -08002598#ifdef CONFIG_PCI
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 /********************************************************
2600 * Setting bit 17 in the CNTRL register of the PLX 9050 *
2601 * chip forces a retry on writes while a read is pending.*
2602 * This is to prevent the card locking up on Intel Xeon *
2603 * multiprocessor systems with the NX chipset. -- NV *
2604 ********************************************************/
2605
2606/* Newer cards are produced with this bit set from the configuration
2607 EEprom. As the bit is read/write for the CPU, we can fix it here,
2608 if we detect that it isn't set correctly. -- REW */
2609
Jiri Slabycda52652006-12-08 02:39:00 -08002610static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611{
2612 unsigned int hwbase;
2613 void __iomem *rebase;
2614 unsigned int t;
2615
Jiri Slaby15b611f2006-12-08 02:39:04 -08002616#define CNTRL_REG_OFFSET 0x50
2617#define CNTRL_REG_GOODVALUE 0x18260000
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618
2619 pci_read_config_dword(pdev, PCI_BASE_ADDRESS_0, &hwbase);
2620 hwbase &= PCI_BASE_ADDRESS_MEM_MASK;
Alan Cox24cb2332008-04-30 00:54:19 -07002621 rebase = ioremap_nocache(hwbase, 0x80);
Jiri Slaby15b611f2006-12-08 02:39:04 -08002622 t = readl(rebase + CNTRL_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 if (t != CNTRL_REG_GOODVALUE) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002624 printk(KERN_DEBUG "sx: performing cntrl reg fix: %08x -> "
2625 "%08x\n", t, CNTRL_REG_GOODVALUE);
2626 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 }
2628 iounmap(rebase);
2629}
Jiri Slaby3468a332006-12-13 00:34:20 -08002630#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631
Jiri Slaby5572e102006-12-08 02:38:58 -08002632static int __devinit sx_pci_probe(struct pci_dev *pdev,
Jiri Slaby15b611f2006-12-08 02:39:04 -08002633 const struct pci_device_id *ent)
Jiri Slaby5572e102006-12-08 02:38:58 -08002634{
Jiri Slaby3468a332006-12-13 00:34:20 -08002635#ifdef CONFIG_PCI
Jiri Slaby5572e102006-12-08 02:38:58 -08002636 struct sx_board *board;
Jiri Slaby39103492006-12-08 02:39:07 -08002637 unsigned int i, reg;
Jiri Slaby5572e102006-12-08 02:38:58 -08002638 int retval = -EIO;
2639
Jiri Slaby42f63842006-12-08 02:39:03 -08002640 mutex_lock(&sx_boards_lock);
Jiri Slaby18f813e2006-12-08 02:39:01 -08002641 i = sx_find_free_board();
Jiri Slaby42f63842006-12-08 02:39:03 -08002642 if (i == SX_NBOARDS) {
2643 mutex_unlock(&sx_boards_lock);
Jiri Slaby5572e102006-12-08 02:38:58 -08002644 goto err;
Jiri Slaby42f63842006-12-08 02:39:03 -08002645 }
2646 board = &boards[i];
2647 board->flags |= SX_BOARD_PRESENT;
2648 mutex_unlock(&sx_boards_lock);
Jiri Slaby5572e102006-12-08 02:38:58 -08002649
2650 retval = pci_enable_device(pdev);
2651 if (retval)
Jiri Slaby42f63842006-12-08 02:39:03 -08002652 goto err_flag;
Jiri Slaby5572e102006-12-08 02:38:58 -08002653
2654 board->flags &= ~SX_BOARD_TYPE;
2655 board->flags |= (pdev->subsystem_vendor == 0x200) ? SX_PCI_BOARD :
Jiri Slaby15b611f2006-12-08 02:39:04 -08002656 SX_CFPCI_BOARD;
Jiri Slaby5572e102006-12-08 02:38:58 -08002657
2658 /* CF boards use base address 3.... */
Jiri Slaby39103492006-12-08 02:39:07 -08002659 reg = IS_CF_BOARD(board) ? 3 : 2;
Jiri Slaby30f42182006-12-08 02:39:08 -08002660 retval = pci_request_region(pdev, reg, "sx");
2661 if (retval) {
2662 dev_err(&pdev->dev, "can't request region\n");
2663 goto err_flag;
2664 }
Jiri Slaby39103492006-12-08 02:39:07 -08002665 board->hw_base = pci_resource_start(pdev, reg);
Jiri Slaby5572e102006-12-08 02:38:58 -08002666 board->base2 =
Jiri Slaby39103492006-12-08 02:39:07 -08002667 board->base = pci_iomap(pdev, reg, WINDOW_LEN(board));
Jiri Slaby5572e102006-12-08 02:38:58 -08002668 if (!board->base) {
2669 dev_err(&pdev->dev, "ioremap failed\n");
Jiri Slaby30f42182006-12-08 02:39:08 -08002670 goto err_reg;
Jiri Slaby5572e102006-12-08 02:38:58 -08002671 }
2672
2673 /* Most of the stuff on the CF board is offset by 0x18000 .... */
Jiri Slaby15b611f2006-12-08 02:39:04 -08002674 if (IS_CF_BOARD(board))
Jiri Slaby5572e102006-12-08 02:38:58 -08002675 board->base += 0x18000;
2676
2677 board->irq = pdev->irq;
2678
2679 dev_info(&pdev->dev, "Got a specialix card: %p(%d) %x.\n", board->base,
Jiri Slaby15b611f2006-12-08 02:39:04 -08002680 board->irq, board->flags);
Jiri Slaby5572e102006-12-08 02:38:58 -08002681
2682 if (!probe_sx(board)) {
2683 retval = -EIO;
2684 goto err_unmap;
2685 }
2686
2687 fix_sx_pci(pdev, board);
2688
2689 pci_set_drvdata(pdev, board);
2690
2691 return 0;
2692err_unmap:
Jiri Slaby39103492006-12-08 02:39:07 -08002693 pci_iounmap(pdev, board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002694err_reg:
2695 pci_release_region(pdev, reg);
Jiri Slaby42f63842006-12-08 02:39:03 -08002696err_flag:
2697 board->flags &= ~SX_BOARD_PRESENT;
Jiri Slaby5572e102006-12-08 02:38:58 -08002698err:
2699 return retval;
Jiri Slaby3468a332006-12-13 00:34:20 -08002700#else
2701 return -ENODEV;
2702#endif
Jiri Slaby5572e102006-12-08 02:38:58 -08002703}
2704
2705static void __devexit sx_pci_remove(struct pci_dev *pdev)
2706{
2707 struct sx_board *board = pci_get_drvdata(pdev);
2708
Jiri Slaby39103492006-12-08 02:39:07 -08002709 sx_remove_card(board, pdev);
Jiri Slaby5572e102006-12-08 02:38:58 -08002710}
2711
2712/* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
2713 its because the standard requires it. So check for SUBVENDOR_ID. */
2714static struct pci_device_id sx_pci_tbl[] = {
2715 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
Jiri Slabyc14d4442007-07-10 17:22:25 -07002716 .subvendor = PCI_ANY_ID, .subdevice = 0x0200 },
Jiri Slaby5572e102006-12-08 02:38:58 -08002717 { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
Jiri Slabyc14d4442007-07-10 17:22:25 -07002718 .subvendor = PCI_ANY_ID, .subdevice = 0x0300 },
Jiri Slaby5572e102006-12-08 02:38:58 -08002719 { 0 }
2720};
Jiri Slaby15b611f2006-12-08 02:39:04 -08002721
Jiri Slaby5572e102006-12-08 02:38:58 -08002722MODULE_DEVICE_TABLE(pci, sx_pci_tbl);
2723
2724static struct pci_driver sx_pcidriver = {
2725 .name = "sx",
2726 .id_table = sx_pci_tbl,
2727 .probe = sx_pci_probe,
2728 .remove = __devexit_p(sx_pci_remove)
2729};
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730
Jiri Slaby15b611f2006-12-08 02:39:04 -08002731static int __init sx_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732{
Jiri Slaby18f813e2006-12-08 02:39:01 -08002733#ifdef CONFIG_EISA
2734 int retval1;
2735#endif
Jiri Slaby927a6f92006-12-08 02:39:02 -08002736#ifdef CONFIG_ISA
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 struct sx_board *board;
Jiri Slaby927a6f92006-12-08 02:39:02 -08002738 unsigned int i;
2739#endif
2740 unsigned int found = 0;
2741 int retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 func_enter();
Jiri Slaby15b611f2006-12-08 02:39:04 -08002744 sx_dprintk(SX_DEBUG_INIT, "Initing sx module... (sx_debug=%d)\n",
2745 sx_debug);
2746 if (abs((long)(&sx_debug) - sx_debug) < 0x10000) {
2747 printk(KERN_WARNING "sx: sx_debug is an address, instead of a "
2748 "value. Assuming -1.\n(%p)\n", &sx_debug);
2749 sx_debug = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 }
2751
2752 if (misc_register(&sx_fw_device) < 0) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002753 printk(KERN_ERR "SX: Unable to register firmware loader "
2754 "driver.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 return -EIO;
2756 }
Jiri Slaby927a6f92006-12-08 02:39:02 -08002757#ifdef CONFIG_ISA
Jiri Slaby15b611f2006-12-08 02:39:04 -08002758 for (i = 0; i < NR_SX_ADDRS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 board = &boards[found];
2760 board->hw_base = sx_probe_addrs[i];
Jiri Slaby30f42182006-12-08 02:39:08 -08002761 board->hw_len = SX_WINDOW_LEN;
2762 if (!request_region(board->hw_base, board->hw_len, "sx"))
2763 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 board->base2 =
Alan Cox24cb2332008-04-30 00:54:19 -07002765 board->base = ioremap_nocache(board->hw_base, board->hw_len);
Jiri Slaby30f42182006-12-08 02:39:08 -08002766 if (!board->base)
2767 goto err_sx_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 board->flags &= ~SX_BOARD_TYPE;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002769 board->flags |= SX_ISA_BOARD;
2770 board->irq = sx_irqmask ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771
Jiri Slaby15b611f2006-12-08 02:39:04 -08002772 if (probe_sx(board)) {
Jiri Slaby42f63842006-12-08 02:39:03 -08002773 board->flags |= SX_BOARD_PRESENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 found++;
2775 } else {
2776 iounmap(board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002777err_sx_reg:
2778 release_region(board->hw_base, board->hw_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 }
2780 }
2781
Jiri Slaby15b611f2006-12-08 02:39:04 -08002782 for (i = 0; i < NR_SI_ADDRS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 board = &boards[found];
2784 board->hw_base = si_probe_addrs[i];
Jiri Slaby30f42182006-12-08 02:39:08 -08002785 board->hw_len = SI2_ISA_WINDOW_LEN;
2786 if (!request_region(board->hw_base, board->hw_len, "sx"))
2787 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002788 board->base2 =
Alan Cox24cb2332008-04-30 00:54:19 -07002789 board->base = ioremap_nocache(board->hw_base, board->hw_len);
Jiri Slaby30f42182006-12-08 02:39:08 -08002790 if (!board->base)
2791 goto err_si_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 board->flags &= ~SX_BOARD_TYPE;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002793 board->flags |= SI_ISA_BOARD;
2794 board->irq = sx_irqmask ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795
Jiri Slaby15b611f2006-12-08 02:39:04 -08002796 if (probe_si(board)) {
Jiri Slaby42f63842006-12-08 02:39:03 -08002797 board->flags |= SX_BOARD_PRESENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 found++;
2799 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002800 iounmap(board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002801err_si_reg:
2802 release_region(board->hw_base, board->hw_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
2804 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002805 for (i = 0; i < NR_SI1_ADDRS; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 board = &boards[found];
2807 board->hw_base = si1_probe_addrs[i];
Jiri Slaby30f42182006-12-08 02:39:08 -08002808 board->hw_len = SI1_ISA_WINDOW_LEN;
2809 if (!request_region(board->hw_base, board->hw_len, "sx"))
2810 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 board->base2 =
Alan Cox24cb2332008-04-30 00:54:19 -07002812 board->base = ioremap_nocache(board->hw_base, board->hw_len);
Jiri Slaby30f42182006-12-08 02:39:08 -08002813 if (!board->base)
2814 goto err_si1_reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 board->flags &= ~SX_BOARD_TYPE;
Jiri Slaby15b611f2006-12-08 02:39:04 -08002816 board->flags |= SI1_ISA_BOARD;
2817 board->irq = sx_irqmask ? -1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
Jiri Slaby15b611f2006-12-08 02:39:04 -08002819 if (probe_si(board)) {
Jiri Slaby42f63842006-12-08 02:39:03 -08002820 board->flags |= SX_BOARD_PRESENT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 found++;
2822 } else {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002823 iounmap(board->base);
Jiri Slaby30f42182006-12-08 02:39:08 -08002824err_si1_reg:
2825 release_region(board->hw_base, board->hw_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826 }
2827 }
Jiri Slaby927a6f92006-12-08 02:39:02 -08002828#endif
Jiri Slaby18f813e2006-12-08 02:39:01 -08002829#ifdef CONFIG_EISA
2830 retval1 = eisa_driver_register(&sx_eisadriver);
2831#endif
Jiri Slaby5572e102006-12-08 02:38:58 -08002832 retval = pci_register_driver(&sx_pcidriver);
2833
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 if (found) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002835 printk(KERN_INFO "sx: total of %d boards detected.\n", found);
Jiri Slaby5572e102006-12-08 02:38:58 -08002836 retval = 0;
2837 } else if (retval) {
Jiri Slaby18f813e2006-12-08 02:39:01 -08002838#ifdef CONFIG_EISA
Jiri Slaby7eb99762006-12-08 02:39:06 -08002839 retval = retval1;
Jiri Slaby18f813e2006-12-08 02:39:01 -08002840 if (retval1)
2841#endif
Jiri Slaby15b611f2006-12-08 02:39:04 -08002842 misc_deregister(&sx_fw_device);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 }
2844
2845 func_exit();
Jiri Slaby5572e102006-12-08 02:38:58 -08002846 return retval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847}
2848
Jiri Slaby15b611f2006-12-08 02:39:04 -08002849static void __exit sx_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850{
Jiri Slaby15b611f2006-12-08 02:39:04 -08002851 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852
2853 func_enter();
Jiri Slaby18f813e2006-12-08 02:39:01 -08002854#ifdef CONFIG_EISA
2855 eisa_driver_unregister(&sx_eisadriver);
2856#endif
Jiri Slaby5572e102006-12-08 02:38:58 -08002857 pci_unregister_driver(&sx_pcidriver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858
Jiri Slaby55e70712006-12-08 02:39:03 -08002859 for (i = 0; i < SX_NBOARDS; i++)
Jiri Slaby39103492006-12-08 02:39:07 -08002860 sx_remove_card(&boards[i], NULL);
Jiri Slaby55e70712006-12-08 02:39:03 -08002861
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 if (misc_deregister(&sx_fw_device) < 0) {
Jiri Slaby15b611f2006-12-08 02:39:04 -08002863 printk(KERN_INFO "sx: couldn't deregister firmware loader "
2864 "device\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 }
Jiri Slaby15b611f2006-12-08 02:39:04 -08002866 sx_dprintk(SX_DEBUG_CLEANUP, "Cleaning up drivers (%d)\n",
2867 sx_initialized);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 if (sx_initialized)
Jiri Slaby15b611f2006-12-08 02:39:04 -08002869 sx_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870
Jiri Slaby15b611f2006-12-08 02:39:04 -08002871 kfree(sx_ports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 func_exit();
2873}
2874
2875module_init(sx_init);
2876module_exit(sx_exit);