Merge branch 'master' of git://git.infradead.org/users/dedekind/mtd-tests-2.6
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / char / rio / rio_linux.c
CommitLineData
1da177e4
LT
1
2/* rio_linux.c -- Linux driver for the Specialix RIO series cards.
3 *
4 *
5 * (C) 1999 R.E.Wolff@BitWizard.nl
6 *
7 * Specialix pays for the development and support of this driver.
8 * Please DO contact support@specialix.co.uk if you require
9 * support. But please read the documentation (rio.txt) first.
10 *
11 *
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License as
15 * published by the Free Software Foundation; either version 2 of
16 * the License, or (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be
19 * useful, but WITHOUT ANY WARRANTY; without even the implied
20 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
21 * PURPOSE. See the GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public
24 * License along with this program; if not, write to the Free
25 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
26 * USA.
27 *
1da177e4
LT
28 * */
29
30#include <linux/module.h>
1da177e4
LT
31#include <linux/kdev_t.h>
32#include <asm/io.h>
33#include <linux/kernel.h>
34#include <linux/sched.h>
35#include <linux/ioport.h>
36#include <linux/interrupt.h>
37#include <linux/errno.h>
38#include <linux/tty.h>
39#include <linux/tty_flip.h>
40#include <linux/mm.h>
41#include <linux/serial.h>
42#include <linux/fcntl.h>
43#include <linux/major.h>
44#include <linux/delay.h>
45#include <linux/pci.h>
46#include <linux/slab.h>
47#include <linux/miscdevice.h>
48#include <linux/init.h>
49
50#include <linux/generic_serial.h>
51#include <asm/uaccess.h>
52
1da177e4 53#include "linux_compat.h"
1da177e4
LT
54#include "pkt.h"
55#include "daemon.h"
56#include "rio.h"
57#include "riospace.h"
1da177e4
LT
58#include "cmdpkt.h"
59#include "map.h"
1da177e4
LT
60#include "rup.h"
61#include "port.h"
62#include "riodrvr.h"
63#include "rioinfo.h"
64#include "func.h"
65#include "errors.h"
66#include "pci.h"
67
68#include "parmmap.h"
69#include "unixrup.h"
70#include "board.h"
71#include "host.h"
1da177e4
LT
72#include "phb.h"
73#include "link.h"
74#include "cmdblk.h"
75#include "route.h"
1da177e4
LT
76#include "cirrus.h"
77#include "rioioctl.h"
78#include "param.h"
1da177e4
LT
79#include "protsts.h"
80#include "rioboard.h"
81
82
83#include "rio_linux.h"
84
85/* I don't think that this driver can handle more than 512 ports on
86one machine. Specialix specifies max 4 boards in one machine. I don't
87know why. If you want to try anyway you'll have to increase the number
88of boards in rio.h. You'll have to allocate more majors if you need
89more than 512 ports.... */
90
91#ifndef RIO_NORMAL_MAJOR0
92/* This allows overriding on the compiler commandline, or in a "major.h"
93 include or something like that */
94#define RIO_NORMAL_MAJOR0 154
95#define RIO_NORMAL_MAJOR1 156
96#endif
97
98#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
99#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
100#endif
101
8d8706e2 102#ifndef RIO_WINDOW_LEN
1da177e4
LT
103#define RIO_WINDOW_LEN 0x10000
104#endif
105
106
107/* Configurable options:
108 (Don't be too sure that it'll work if you toggle them) */
109
110/* Am I paranoid or not ? ;-) */
111#undef RIO_PARANOIA_CHECK
112
113
114/* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
115 Hz, but it is user configurable. I don't recommend going above 1000
116 Hz. The interrupt ratelimit might trigger if the interrupt is
117 shared with a very active other device.
118 undef this if you want to disable the check....
119*/
120#define IRQ_RATE_LIMIT 200
121
1da177e4
LT
122
123/* These constants are derived from SCO Source */
124static struct Conf
8d8706e2
AM
125 RIOConf = {
126 /* locator */ "RIO Config here",
127 /* startuptime */ HZ * 2,
128 /* how long to wait for card to run */
129 /* slowcook */ 0,
130 /* TRUE -> always use line disc. */
131 /* intrpolltime */ 1,
132 /* The frequency of OUR polls */
133 /* breakinterval */ 25,
134 /* x10 mS XXX: units seem to be 1ms not 10! -- REW */
135 /* timer */ 10,
136 /* mS */
137 /* RtaLoadBase */ 0x7000,
138 /* HostLoadBase */ 0x7C00,
139 /* XpHz */ 5,
140 /* number of Xprint hits per second */
141 /* XpCps */ 120,
142 /* Xprint characters per second */
143 /* XpOn */ "\033d#",
144 /* start Xprint for a wyse 60 */
145 /* XpOff */ "\024",
146 /* end Xprint for a wyse 60 */
147 /* MaxXpCps */ 2000,
148 /* highest Xprint speed */
149 /* MinXpCps */ 10,
150 /* slowest Xprint speed */
151 /* SpinCmds */ 1,
152 /* non-zero for mega fast boots */
153 /* First Addr */ 0x0A0000,
154 /* First address to look at */
155 /* Last Addr */ 0xFF0000,
156 /* Last address looked at */
157 /* BufferSize */ 1024,
158 /* Bytes per port of buffering */
159 /* LowWater */ 256,
160 /* how much data left before wakeup */
161 /* LineLength */ 80,
162 /* how wide is the console? */
163 /* CmdTimeout */ HZ,
164 /* how long a close command may take */
1da177e4
LT
165};
166
167
168
169
170/* Function prototypes */
171
8d8706e2
AM
172static void rio_disable_tx_interrupts(void *ptr);
173static void rio_enable_tx_interrupts(void *ptr);
174static void rio_disable_rx_interrupts(void *ptr);
175static void rio_enable_rx_interrupts(void *ptr);
31f35939 176static int rio_carrier_raised(struct tty_port *port);
8d8706e2
AM
177static void rio_shutdown_port(void *ptr);
178static int rio_set_real_termios(void *ptr);
179static void rio_hungup(void *ptr);
180static void rio_close(void *ptr);
181static int rio_chars_in_buffer(void *ptr);
f6759fdc 182static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
1da177e4
LT
183static int rio_init_drivers(void);
184
8d8706e2 185static void my_hd(void *addr, int len);
1da177e4
LT
186
187static struct tty_driver *rio_driver, *rio_driver2;
188
189/* The name "p" is a bit non-descript. But that's what the rio-lynxos
190sources use all over the place. */
191struct rio_info *p;
192
193int rio_debug;
194
195
196/* You can have the driver poll your card.
197 - Set rio_poll to 1 to poll every timer tick (10ms on Intel).
198 This is used when the card cannot use an interrupt for some reason.
199*/
200static int rio_poll = 1;
201
202
203/* These are the only open spaces in my computer. Yours may have more
204 or less.... */
8d8706e2 205static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
1da177e4 206
fe971071 207#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
1da177e4
LT
208
209
210/* Set the mask to all-ones. This alas, only supports 32 interrupts.
211 Some architectures may need more. -- Changed to LONG to
212 support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
408b664a 213static long rio_irqmask = -1;
1da177e4
LT
214
215MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
216MODULE_DESCRIPTION("RIO driver");
217MODULE_LICENSE("GPL");
218module_param(rio_poll, int, 0);
219module_param(rio_debug, int, 0644);
220module_param(rio_irqmask, long, 0);
221
222static struct real_driver rio_real_driver = {
8d8706e2
AM
223 rio_disable_tx_interrupts,
224 rio_enable_tx_interrupts,
225 rio_disable_rx_interrupts,
226 rio_enable_rx_interrupts,
8d8706e2
AM
227 rio_shutdown_port,
228 rio_set_real_termios,
229 rio_chars_in_buffer,
230 rio_close,
231 rio_hungup,
232 NULL
1da177e4
LT
233};
234
235/*
236 * Firmware loader driver specific routines
237 *
238 */
239
62322d25 240static const struct file_operations rio_fw_fops = {
8d8706e2 241 .owner = THIS_MODULE,
f6759fdc 242 .unlocked_ioctl = rio_fw_ioctl,
1da177e4
LT
243};
244
245static struct miscdevice rio_fw_device = {
246 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
247};
248
249
250
251
252
253#ifdef RIO_PARANOIA_CHECK
254
255/* This doesn't work. Who's paranoid around here? Not me! */
256
8d8706e2 257static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
1da177e4
LT
258{
259
8d8706e2
AM
260 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
261 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
262
263 if (!port) {
264 printk(badinfo, name, routine);
265 return 1;
266 }
267 if (port->magic != RIO_MAGIC) {
268 printk(badmagic, name, routine);
269 return 1;
270 }
271
272 return 0;
1da177e4
LT
273}
274#else
275#define rio_paranoia_check(a,b,c) 0
276#endif
277
278
279#ifdef DEBUG
8d8706e2 280static void my_hd(void *ad, int len)
1da177e4 281{
8d8706e2
AM
282 int i, j, ch;
283 unsigned char *addr = ad;
284
285 for (i = 0; i < len; i += 16) {
00d83a54 286 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
8d8706e2
AM
287 for (j = 0; j < 16; j++) {
288 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
289 }
290 for (j = 0; j < 16; j++) {
291 ch = addr[j + i];
292 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
293 }
294 rio_dprintk(RIO_DEBUG_PARAM, "\n");
295 }
1da177e4
LT
296}
297#else
298#define my_hd(ad,len) do{/* nothing*/ } while (0)
299#endif
300
301
8d8706e2
AM
302/* Delay a number of jiffies, allowing a signal to interrupt */
303int RIODelay(struct Port *PortP, int njiffies)
1da177e4 304{
8d8706e2 305 func_enter();
1da177e4 306
8d8706e2
AM
307 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
308 msleep_interruptible(jiffies_to_msecs(njiffies));
309 func_exit();
1da177e4 310
8d8706e2
AM
311 if (signal_pending(current))
312 return RIO_FAIL;
313 else
314 return !RIO_FAIL;
1da177e4
LT
315}
316
317
8d8706e2
AM
318/* Delay a number of jiffies, disallowing a signal to interrupt */
319int RIODelay_ni(struct Port *PortP, int njiffies)
1da177e4 320{
8d8706e2 321 func_enter();
1da177e4 322
8d8706e2
AM
323 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
324 msleep(jiffies_to_msecs(njiffies));
325 func_exit();
326 return !RIO_FAIL;
1da177e4
LT
327}
328
38d0d001 329void rio_copy_to_card(void *from, void __iomem *to, int len)
00d83a54 330{
ae5b28a5 331 rio_copy_toio(to, from, len);
00d83a54 332}
1da177e4
LT
333
334int rio_minor(struct tty_struct *tty)
335{
336 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
337}
338
8d8706e2 339static int rio_set_real_termios(void *ptr)
1da177e4 340{
d6f6341a 341 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
1da177e4
LT
342}
343
344
8d8706e2 345static void rio_reset_interrupt(struct Host *HostP)
1da177e4 346{
8d8706e2 347 func_enter();
1da177e4 348
8d8706e2
AM
349 switch (HostP->Type) {
350 case RIO_AT:
351 case RIO_MCA:
352 case RIO_PCI:
00d83a54 353 writeb(0xFF, &HostP->ResetInt);
8d8706e2 354 }
1da177e4 355
8d8706e2 356 func_exit();
1da177e4
LT
357}
358
359
7d12e780 360static irqreturn_t rio_interrupt(int irq, void *ptr)
1da177e4 361{
8d8706e2
AM
362 struct Host *HostP;
363 func_enter();
1da177e4 364
c7bec5ab 365 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
8d8706e2 366 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
1da177e4 367
8d8706e2
AM
368 /* AAargh! The order in which to do these things is essential and
369 not trivial.
1da177e4 370
8d8706e2
AM
371 - hardware twiddling goes before "recursive". Otherwise when we
372 poll the card, and a recursive interrupt happens, we won't
373 ack the card, so it might keep on interrupting us. (especially
374 level sensitive interrupt systems like PCI).
1da177e4 375
8d8706e2
AM
376 - Rate limit goes before hardware twiddling. Otherwise we won't
377 catch a card that has gone bonkers.
1da177e4 378
8d8706e2
AM
379 - The "initialized" test goes after the hardware twiddling. Otherwise
380 the card will stick us in the interrupt routine again.
381
382 - The initialized test goes before recursive.
383 */
1da177e4 384
8d8706e2
AM
385 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
386 if (HostP->Ivec == irq) {
387 /* Tell the card we've noticed the interrupt. */
388 rio_reset_interrupt(HostP);
389 }
390
391 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
392 return IRQ_HANDLED;
393
394 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
00d83a54 395 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
8d8706e2
AM
396 return IRQ_HANDLED;
397 }
398
c7bec5ab 399 RIOServiceHost(p, HostP);
8d8706e2 400
00d83a54 401 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
8d8706e2
AM
402
403 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
404 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
405 func_exit();
406 return IRQ_HANDLED;
1da177e4
LT
407}
408
409
8d8706e2 410static void rio_pollfunc(unsigned long data)
1da177e4 411{
8d8706e2 412 func_enter();
1da177e4 413
7d12e780 414 rio_interrupt(0, &p->RIOHosts[data]);
40565f19 415 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
1da177e4 416
8d8706e2 417 func_exit();
1da177e4
LT
418}
419
420
421/* ********************************************************************** *
422 * Here are the routines that actually *
423 * interface with the generic_serial driver *
424 * ********************************************************************** */
425
426/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
427 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
428
8d8706e2 429static void rio_disable_tx_interrupts(void *ptr)
1da177e4 430{
8d8706e2 431 func_enter();
1da177e4 432
b5391e29 433 /* port->gs.port.flags &= ~GS_TX_INTEN; */
1da177e4 434
8d8706e2 435 func_exit();
1da177e4
LT
436}
437
438
8d8706e2 439static void rio_enable_tx_interrupts(void *ptr)
1da177e4 440{
8d8706e2
AM
441 struct Port *PortP = ptr;
442 /* int hn; */
1da177e4 443
8d8706e2 444 func_enter();
1da177e4 445
8d8706e2 446 /* hn = PortP->HostP - p->RIOHosts;
1da177e4 447
8d8706e2
AM
448 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
449 rio_interrupt (-1,(void *) hn, NULL); */
1da177e4 450
8d8706e2 451 RIOTxEnable((char *) PortP);
1da177e4 452
8d8706e2
AM
453 /*
454 * In general we cannot count on "tx empty" interrupts, although
455 * the interrupt routine seems to be able to tell the difference.
456 */
b5391e29 457 PortP->gs.port.flags &= ~GS_TX_INTEN;
1da177e4 458
8d8706e2 459 func_exit();
1da177e4
LT
460}
461
462
8d8706e2 463static void rio_disable_rx_interrupts(void *ptr)
1da177e4 464{
8d8706e2
AM
465 func_enter();
466 func_exit();
1da177e4
LT
467}
468
8d8706e2 469static void rio_enable_rx_interrupts(void *ptr)
1da177e4 470{
8d8706e2
AM
471 /* struct rio_port *port = ptr; */
472 func_enter();
473 func_exit();
1da177e4
LT
474}
475
476
477/* Jeez. Isn't this simple? */
31f35939 478static int rio_carrier_raised(struct tty_port *port)
1da177e4 479{
31f35939 480 struct Port *PortP = container_of(port, struct Port, gs.port);
8d8706e2
AM
481 int rv;
482
483 func_enter();
d6f6341a 484 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
1da177e4 485
8d8706e2 486 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
1da177e4 487
8d8706e2
AM
488 func_exit();
489 return rv;
1da177e4
LT
490}
491
492
493/* Jeez. Isn't this simple? Actually, we can sync with the actual port
494 by just pushing stuff into the queue going to the port... */
8d8706e2 495static int rio_chars_in_buffer(void *ptr)
1da177e4 496{
8d8706e2 497 func_enter();
1da177e4 498
8d8706e2
AM
499 func_exit();
500 return 0;
1da177e4
LT
501}
502
503
504/* Nothing special here... */
8d8706e2 505static void rio_shutdown_port(void *ptr)
1da177e4 506{
8d8706e2 507 struct Port *PortP;
1da177e4 508
8d8706e2 509 func_enter();
1da177e4 510
8d8706e2 511 PortP = (struct Port *) ptr;
b5391e29 512 PortP->gs.port.tty = NULL;
8d8706e2 513 func_exit();
1da177e4
LT
514}
515
516
517/* I haven't the foggiest why the decrement use count has to happen
518 here. The whole linux serial drivers stuff needs to be redesigned.
519 My guess is that this is a hack to minimize the impact of a bug
520 elsewhere. Thinking about it some more. (try it sometime) Try
521 running minicom on a serial port that is driven by a modularized
522 driver. Have the modem hangup. Then remove the driver module. Then
523 exit minicom. I expect an "oops". -- REW */
8d8706e2 524static void rio_hungup(void *ptr)
1da177e4 525{
8d8706e2
AM
526 struct Port *PortP;
527
528 func_enter();
1da177e4 529
8d8706e2 530 PortP = (struct Port *) ptr;
b5391e29 531 PortP->gs.port.tty = NULL;
1da177e4 532
8d8706e2 533 func_exit();
1da177e4
LT
534}
535
536
537/* The standard serial_close would become shorter if you'd wrap it like
538 this.
539 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
540 */
8d8706e2 541static void rio_close(void *ptr)
1da177e4 542{
8d8706e2 543 struct Port *PortP;
1da177e4 544
8d8706e2 545 func_enter();
1da177e4 546
8d8706e2 547 PortP = (struct Port *) ptr;
1da177e4 548
8d8706e2 549 riotclose(ptr);
1da177e4 550
b5391e29
AC
551 if (PortP->gs.port.count) {
552 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
553 PortP->gs.port.count = 0;
8d8706e2 554 }
1da177e4 555
b5391e29 556 PortP->gs.port.tty = NULL;
8d8706e2 557 func_exit();
1da177e4
LT
558}
559
560
561
f6759fdc 562static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1da177e4 563{
8d8706e2
AM
564 int rc = 0;
565 func_enter();
1da177e4 566
8d8706e2 567 /* The "dev" argument isn't used. */
f6759fdc 568 lock_kernel();
d886cb58 569 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
f6759fdc 570 unlock_kernel();
1da177e4 571
8d8706e2
AM
572 func_exit();
573 return rc;
1da177e4
LT
574}
575
8d8706e2 576extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
1da177e4 577
8d8706e2 578static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
1da177e4 579{
d886cb58 580 void __user *argp = (void __user *)arg;
8d8706e2
AM
581 int rc;
582 struct Port *PortP;
583 int ival;
1da177e4 584
8d8706e2 585 func_enter();
1da177e4 586
8d8706e2 587 PortP = (struct Port *) tty->driver_data;
1da177e4 588
8d8706e2
AM
589 rc = 0;
590 switch (cmd) {
8d8706e2 591 case TIOCSSOFTCAR:
d886cb58 592 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
8d8706e2
AM
593 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
594 }
595 break;
596 case TIOCGSERIAL:
597 rc = -EFAULT;
d886cb58
AV
598 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
599 rc = gs_getserial(&PortP->gs, argp);
8d8706e2
AM
600 break;
601 case TCSBRK:
602 if (PortP->State & RIO_DELETED) {
603 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
604 rc = -EIO;
605 } else {
d6f6341a
JS
606 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
607 RIO_FAIL) {
8d8706e2
AM
608 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
609 rc = -EIO;
610 }
611 }
612 break;
613 case TCSBRKP:
614 if (PortP->State & RIO_DELETED) {
615 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
616 rc = -EIO;
617 } else {
618 int l;
619 l = arg ? arg * 100 : 250;
620 if (l > 255)
621 l = 255;
d6f6341a
JS
622 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
623 arg ? arg * 100 : 250) == RIO_FAIL) {
8d8706e2
AM
624 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
625 rc = -EIO;
626 }
627 }
628 break;
629 case TIOCSSERIAL:
630 rc = -EFAULT;
d886cb58
AV
631 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
632 rc = gs_setserial(&PortP->gs, argp);
8d8706e2 633 break;
8d8706e2
AM
634 default:
635 rc = -ENOIOCTLCMD;
636 break;
637 }
638 func_exit();
639 return rc;
1da177e4
LT
640}
641
642
643/* The throttle/unthrottle scheme for the Specialix card is different
644 * from other drivers and deserves some explanation.
645 * The Specialix hardware takes care of XON/XOFF
646 * and CTS/RTS flow control itself. This means that all we have to
647 * do when signalled by the upper tty layer to throttle/unthrottle is
648 * to make a note of it here. When we come to read characters from the
649 * rx buffers on the card (rio_receive_chars()) we look to see if the
650 * upper layer can accept more (as noted here in rio_rx_throt[]).
651 * If it can't we simply don't remove chars from the cards buffer.
652 * When the tty layer can accept chars, we again note that here and when
653 * rio_receive_chars() is called it will remove them from the cards buffer.
654 * The card will notice that a ports buffer has drained below some low
655 * water mark and will unflow control the line itself, using whatever
656 * flow control scheme is in use for that port. -- Simon Allen
657 */
658
8d8706e2 659static void rio_throttle(struct tty_struct *tty)
1da177e4 660{
8d8706e2
AM
661 struct Port *port = (struct Port *) tty->driver_data;
662
663 func_enter();
664 /* If the port is using any type of input flow
665 * control then throttle the port.
666 */
667
668 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
669 port->State |= RIO_THROTTLE_RX;
670 }
671
672 func_exit();
1da177e4
LT
673}
674
675
8d8706e2 676static void rio_unthrottle(struct tty_struct *tty)
1da177e4 677{
8d8706e2 678 struct Port *port = (struct Port *) tty->driver_data;
1da177e4 679
8d8706e2
AM
680 func_enter();
681 /* Always unthrottle even if flow control is not enabled on
682 * this port in case we disabled flow control while the port
683 * was throttled
684 */
1da177e4 685
8d8706e2 686 port->State &= ~RIO_THROTTLE_RX;
1da177e4 687
8d8706e2
AM
688 func_exit();
689 return;
1da177e4
LT
690}
691
692
693
694
695
696/* ********************************************************************** *
697 * Here are the initialization routines. *
698 * ********************************************************************** */
699
700
8d8706e2 701static struct vpd_prom *get_VPD_PROM(struct Host *hp)
1da177e4 702{
8d8706e2
AM
703 static struct vpd_prom vpdp;
704 char *p;
705 int i;
706
707 func_enter();
708 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
1da177e4 709
8d8706e2
AM
710 p = (char *) &vpdp;
711 for (i = 0; i < sizeof(struct vpd_prom); i++)
712 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
713 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
1da177e4 714
8d8706e2
AM
715 /* Terminate the identifier string.
716 *** requires one extra byte in struct vpd_prom *** */
717 *p++ = 0;
1da177e4 718
8d8706e2
AM
719 if (rio_debug & RIO_DEBUG_PROBE)
720 my_hd((char *) &vpdp, 0x20);
1da177e4 721
8d8706e2 722 func_exit();
1da177e4 723
8d8706e2 724 return &vpdp;
1da177e4
LT
725}
726
b68e31d0 727static const struct tty_operations rio_ops = {
8d8706e2 728 .open = riotopen,
1da177e4
LT
729 .close = gs_close,
730 .write = gs_write,
731 .put_char = gs_put_char,
732 .flush_chars = gs_flush_chars,
733 .write_room = gs_write_room,
734 .chars_in_buffer = gs_chars_in_buffer,
735 .flush_buffer = gs_flush_buffer,
736 .ioctl = rio_ioctl,
737 .throttle = rio_throttle,
738 .unthrottle = rio_unthrottle,
739 .set_termios = gs_set_termios,
740 .stop = gs_stop,
741 .start = gs_start,
742 .hangup = gs_hangup,
743};
744
745static int rio_init_drivers(void)
746{
747 int error = -ENOMEM;
748
749 rio_driver = alloc_tty_driver(256);
750 if (!rio_driver)
751 goto out;
752 rio_driver2 = alloc_tty_driver(256);
753 if (!rio_driver2)
754 goto out1;
755
756 func_enter();
757
758 rio_driver->owner = THIS_MODULE;
759 rio_driver->driver_name = "specialix_rio";
760 rio_driver->name = "ttySR";
761 rio_driver->major = RIO_NORMAL_MAJOR0;
762 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
763 rio_driver->subtype = SERIAL_TYPE_NORMAL;
764 rio_driver->init_termios = tty_std_termios;
765 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
766 rio_driver->flags = TTY_DRIVER_REAL_RAW;
767 tty_set_operations(rio_driver, &rio_ops);
768
769 rio_driver2->owner = THIS_MODULE;
770 rio_driver2->driver_name = "specialix_rio";
771 rio_driver2->name = "ttySR";
772 rio_driver2->major = RIO_NORMAL_MAJOR1;
773 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
774 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
775 rio_driver2->init_termios = tty_std_termios;
776 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
777 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
778 tty_set_operations(rio_driver2, &rio_ops);
779
8d8706e2 780 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
1da177e4
LT
781
782 if ((error = tty_register_driver(rio_driver)))
783 goto out2;
784 if ((error = tty_register_driver(rio_driver2)))
785 goto out3;
786 func_exit();
787 return 0;
8d8706e2 788 out3:
1da177e4 789 tty_unregister_driver(rio_driver);
8d8706e2 790 out2:
1da177e4 791 put_tty_driver(rio_driver2);
8d8706e2 792 out1:
1da177e4 793 put_tty_driver(rio_driver);
8d8706e2
AM
794 out:
795 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
1da177e4
LT
796 return 1;
797}
798
31f35939
AC
799static const struct tty_port_operations rio_port_ops = {
800 .carrier_raised = rio_carrier_raised,
801};
1da177e4 802
8d8706e2 803static int rio_init_datastructures(void)
1da177e4 804{
8d8706e2
AM
805 int i;
806 struct Port *port;
807 func_enter();
808
809 /* Many drivers statically allocate the maximum number of ports
810 There is no reason not to allocate them dynamically. Is there? -- REW */
811 /* However, the RIO driver allows users to configure their first
812 RTA as the ports numbered 504-511. We therefore need to allocate
813 the whole range. :-( -- REW */
814
1da177e4
LT
815#define RI_SZ sizeof(struct rio_info)
816#define HOST_SZ sizeof(struct Host)
817#define PORT_SZ sizeof(struct Port *)
818#define TMIO_SZ sizeof(struct termios *)
00d83a54 819 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
8d8706e2 820
d0c9873a 821 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
8d8706e2 822 goto free0;
d0c9873a 823 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
8d8706e2 824 goto free1;
d0c9873a 825 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
8d8706e2
AM
826 goto free2;
827 p->RIOConf = RIOConf;
828 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
1da177e4
LT
829
830#if 1
8d8706e2 831 for (i = 0; i < RIO_PORTS; i++) {
d0c9873a 832 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
8d8706e2
AM
833 if (!port) {
834 goto free6;
835 }
836 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
31f35939
AC
837 tty_port_init(&port->gs.port);
838 port->gs.port.ops = &rio_port_ops;
8d8706e2
AM
839 port->PortNum = i;
840 port->gs.magic = RIO_MAGIC;
841 port->gs.close_delay = HZ / 2;
842 port->gs.closing_wait = 30 * HZ;
843 port->gs.rd = &rio_real_driver;
844 spin_lock_init(&port->portSem);
8d8706e2 845 }
1da177e4 846#else
8d8706e2 847 /* We could postpone initializing them to when they are configured. */
1da177e4
LT
848#endif
849
850
1da177e4 851
8d8706e2
AM
852 if (rio_debug & RIO_DEBUG_INIT) {
853 my_hd(&rio_real_driver, sizeof(rio_real_driver));
854 }
855
1da177e4 856
8d8706e2
AM
857 func_exit();
858 return 0;
859
860 free6:for (i--; i >= 0; i--)
861 kfree(p->RIOPortp[i]);
1da177e4
LT
862/*free5:
863 free4:
8d8706e2
AM
864 free3:*/ kfree(p->RIOPortp);
865 free2:kfree(p->RIOHosts);
866 free1:
867 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
868 kfree(p);
869 free0:
870 return -ENOMEM;
1da177e4
LT
871}
872
8d8706e2 873static void __exit rio_release_drivers(void)
1da177e4 874{
8d8706e2
AM
875 func_enter();
876 tty_unregister_driver(rio_driver2);
877 tty_unregister_driver(rio_driver);
878 put_tty_driver(rio_driver2);
879 put_tty_driver(rio_driver);
880 func_exit();
1da177e4
LT
881}
882
883
884#ifdef CONFIG_PCI
885 /* This was written for SX, but applies to RIO too...
886 (including bugs....)
887
888 There is another bit besides Bit 17. Turning that bit off
889 (on boards shipped with the fix in the eeprom) results in a
890 hang on the next access to the card.
8d8706e2 891 */
1da177e4
LT
892
893 /********************************************************
894 * Setting bit 17 in the CNTRL register of the PLX 9050 *
895 * chip forces a retry on writes while a read is pending.*
896 * This is to prevent the card locking up on Intel Xeon *
897 * multiprocessor systems with the NX chipset. -- NV *
898 ********************************************************/
899
900/* Newer cards are produced with this bit set from the configuration
901 EEprom. As the bit is read/write for the CPU, we can fix it here,
902 if we detect that it isn't set correctly. -- REW */
903
8d8706e2 904static void fix_rio_pci(struct pci_dev *pdev)
1da177e4 905{
00d83a54 906 unsigned long hwbase;
d886cb58 907 unsigned char __iomem *rebase;
8d8706e2 908 unsigned int t;
1da177e4
LT
909
910#define CNTRL_REG_OFFSET 0x50
911#define CNTRL_REG_GOODVALUE 0x18260000
912
00d83a54
AC
913 hwbase = pci_resource_start(pdev, 0);
914 rebase = ioremap(hwbase, 0x80);
8d8706e2
AM
915 t = readl(rebase + CNTRL_REG_OFFSET);
916 if (t != CNTRL_REG_GOODVALUE) {
917 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
918 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
919 }
00d83a54 920 iounmap(rebase);
1da177e4
LT
921}
922#endif
923
924
8d8706e2 925static int __init rio_init(void)
1da177e4 926{
8d8706e2
AM
927 int found = 0;
928 int i;
929 struct Host *hp;
930 int retval;
931 struct vpd_prom *vpdp;
932 int okboard;
1da177e4
LT
933
934#ifdef CONFIG_PCI
8d8706e2 935 struct pci_dev *pdev = NULL;
8d8706e2 936 unsigned short tshort;
1da177e4
LT
937#endif
938
8d8706e2
AM
939 func_enter();
940 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
941
942 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
943 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
944 rio_debug = -1;
945 }
946
947 if (misc_register(&rio_fw_device) < 0) {
948 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
949 return -EIO;
950 }
951
952 retval = rio_init_datastructures();
953 if (retval < 0) {
954 misc_deregister(&rio_fw_device);
955 return retval;
956 }
1da177e4 957#ifdef CONFIG_PCI
8d8706e2
AM
958 /* First look for the JET devices: */
959 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
554b7c80
AC
960 u32 tint;
961
8d8706e2
AM
962 if (pci_enable_device(pdev))
963 continue;
964
965 /* Specialix has a whole bunch of cards with
966 0x2000 as the device ID. They say its because
967 the standard requires it. Stupid standard. */
968 /* It seems that reading a word doesn't work reliably on 2.0.
969 Also, reading a non-aligned dword doesn't work. So we read the
970 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
971 ourselves */
8d8706e2
AM
972 pci_read_config_dword(pdev, 0x2c, &tint);
973 tshort = (tint >> 16) & 0xffff;
974 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
975 if (tshort != 0x0100) {
976 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
977 continue;
978 }
979 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
980
8d8706e2 981 hp = &p->RIOHosts[p->RIONumHosts];
554b7c80 982 hp->PaddrP = pci_resource_start(pdev, 2);
8d8706e2
AM
983 hp->Ivec = pdev->irq;
984 if (((1 << hp->Ivec) & rio_irqmask) == 0)
985 hp->Ivec = 0;
986 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
d886cb58 987 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
8d8706e2 988 hp->Type = RIO_PCI;
00d83a54 989 hp->Copy = rio_copy_to_card;
8d8706e2
AM
990 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
991 spin_lock_init(&hp->HostLock);
992 rio_reset_interrupt(hp);
993 rio_start_card_running(hp);
994
995 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
554b7c80 996 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
8d8706e2 997 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
00d83a54 998 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
8d8706e2 999 p->RIOHosts[p->RIONumHosts].UniqueNum =
00d83a54
AC
1000 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1001 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
8d8706e2
AM
1002 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1003
1004 fix_rio_pci(pdev);
86fbf148
JS
1005
1006 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1007 pci_dev_get(pdev);
1008
554b7c80 1009 p->RIOLastPCISearch = 0;
8d8706e2
AM
1010 p->RIONumHosts++;
1011 found++;
1012 } else {
d886cb58 1013 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
86842654 1014 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
8d8706e2
AM
1015 }
1016 }
1017
1018 /* Then look for the older PCI card.... : */
1019
1020 /* These older PCI cards have problems (only byte-mode access is
1021 supported), which makes them a bit awkward to support.
1022 They also have problems sharing interrupts. Be careful.
1023 (The driver now refuses to share interrupts for these
1024 cards. This should be sufficient).
1025 */
1026
1027 /* Then look for the older RIO/PCI devices: */
1028 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1029 if (pci_enable_device(pdev))
1030 continue;
1da177e4
LT
1031
1032#ifdef CONFIG_RIO_OLDPCI
8d8706e2 1033 hp = &p->RIOHosts[p->RIONumHosts];
554b7c80 1034 hp->PaddrP = pci_resource_start(pdev, 0);
8d8706e2
AM
1035 hp->Ivec = pdev->irq;
1036 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1037 hp->Ivec = 0;
1038 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1039 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
d886cb58 1040 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
8d8706e2 1041 hp->Type = RIO_PCI;
00d83a54 1042 hp->Copy = rio_copy_to_card;
8d8706e2
AM
1043 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1044 spin_lock_init(&hp->HostLock);
1045
1046 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1047 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1048
1049 rio_reset_interrupt(hp);
1050 rio_start_card_running(hp);
1051 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
554b7c80 1052 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
00d83a54 1053 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
8d8706e2 1054 p->RIOHosts[p->RIONumHosts].UniqueNum =
00d83a54
AC
1055 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1056 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[1]) & 0xFF) << 8) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[2]) & 0xFF) << 16) | ((readb(&p->RIOHosts[p->RIONumHosts].Unique[3]) & 0xFF) << 24);
8d8706e2
AM
1057 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1058
86fbf148
JS
1059 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1060 pci_dev_get(pdev);
1061
554b7c80 1062 p->RIOLastPCISearch = 0;
8d8706e2
AM
1063 p->RIONumHosts++;
1064 found++;
1065 } else {
d886cb58 1066 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
86842654 1067 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
8d8706e2 1068 }
1da177e4 1069#else
8d8706e2 1070 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
1da177e4 1071#endif
8d8706e2
AM
1072 }
1073#endif /* PCI */
1074
1075 /* Now probe for ISA cards... */
1076 for (i = 0; i < NR_RIO_ADDRS; i++) {
1077 hp = &p->RIOHosts[p->RIONumHosts];
1078 hp->PaddrP = rio_probe_addrs[i];
1079 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1080 hp->Ivec = 0;
1081 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
d886cb58 1082 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
8d8706e2 1083 hp->Type = RIO_AT;
00d83a54
AC
1084 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1085 * -- YES! this is now a normal copy. Only the
8d8706e2
AM
1086 * old PCI card uses the special PCI copy.
1087 * Moreover, the ISA card will work with the
1088 * special PCI copy anyway. -- REW */
1089 hp->Mode = 0;
1090 spin_lock_init(&hp->HostLock);
1091
1092 vpdp = get_VPD_PROM(hp);
1093 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1094 okboard = 0;
1095 if ((strncmp(vpdp->identifier, RIO_ISA_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA2_IDENT, 16) == 0) || (strncmp(vpdp->identifier, RIO_ISA3_IDENT, 16) == 0)) {
1096 /* Board is present... */
554b7c80 1097 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
8d8706e2
AM
1098 /* ... and feeling fine!!!! */
1099 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1100 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1101 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1102 okboard++;
1103 found++;
1104 }
1105 }
1106
86842654 1107 if (!okboard) {
d886cb58 1108 iounmap(hp->Caddr);
86842654
AL
1109 hp->Caddr = NULL;
1110 }
8d8706e2
AM
1111 }
1112 }
1113
1114
1115 for (i = 0; i < p->RIONumHosts; i++) {
1116 hp = &p->RIOHosts[i];
1117 if (hp->Ivec) {
5d8c8a2e 1118 int mode = IRQF_SHARED;
8d8706e2
AM
1119 if (hp->Ivec & 0x8000) {
1120 mode = 0;
1121 hp->Ivec &= 0x7fff;
1122 }
1123 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1124 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1125 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1126 if (retval) {
1127 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1128 hp->Ivec = 0;
1129 }
1130 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1131 if (hp->Ivec != 0) {
1132 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1133 hp->Mode |= RIO_PCI_INT_ENABLE;
1134 } else
88dacbe9 1135 hp->Mode &= ~RIO_PCI_INT_ENABLE;
8d8706e2
AM
1136 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1137 rio_start_card_running(hp);
1138 }
1139 /* Init the timer "always" to make sure that it can safely be
1140 deleted when we unload... */
1141
40565f19 1142 setup_timer(&hp->timer, rio_pollfunc, i);
8d8706e2
AM
1143 if (!hp->Ivec) {
1144 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
40565f19 1145 mod_timer(&hp->timer, jiffies + rio_poll);
8d8706e2
AM
1146 }
1147 }
1148
1149 if (found) {
1150 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1151 rio_init_drivers();
1152 } else {
1153 /* deregister the misc device we created earlier */
1154 misc_deregister(&rio_fw_device);
1155 }
1156
1157 func_exit();
1158 return found ? 0 : -EIO;
1da177e4
LT
1159}
1160
1161
8d8706e2 1162static void __exit rio_exit(void)
1da177e4 1163{
8d8706e2
AM
1164 int i;
1165 struct Host *hp;
1166
1167 func_enter();
1da177e4 1168
8d8706e2
AM
1169 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1170 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1171 if (hp->Ivec) {
1172 free_irq(hp->Ivec, hp);
1173 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1174 }
1175 /* It is safe/allowed to del_timer a non-active timer */
40565f19 1176 del_timer_sync(&hp->timer);
86842654
AL
1177 if (hp->Caddr)
1178 iounmap(hp->Caddr);
86fbf148
JS
1179 if (hp->Type == RIO_PCI)
1180 pci_dev_put(hp->pdev);
8d8706e2 1181 }
1da177e4 1182
8d8706e2
AM
1183 if (misc_deregister(&rio_fw_device) < 0) {
1184 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1185 }
1da177e4
LT
1186
1187
8d8706e2 1188 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1da177e4 1189
8d8706e2 1190 rio_release_drivers();
1da177e4 1191
8d8706e2
AM
1192 /* Release dynamically allocated memory */
1193 kfree(p->RIOPortp);
1194 kfree(p->RIOHosts);
1195 kfree(p);
1da177e4 1196
8d8706e2 1197 func_exit();
1da177e4
LT
1198}
1199
1200module_init(rio_init);
1201module_exit(rio_exit);