blob: ce81da5b2da9a20079cf46fe64eddcac546b1474 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 * */
29
30#include <linux/module.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#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
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include "linux_compat.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070054#include "pkt.h"
55#include "daemon.h"
56#include "rio.h"
57#include "riospace.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070058#include "cmdpkt.h"
59#include "map.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070060#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"
Linus Torvalds1da177e2005-04-16 15:20:36 -070072#include "phb.h"
73#include "link.h"
74#include "cmdblk.h"
75#include "route.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070076#include "cirrus.h"
77#include "rioioctl.h"
78#include "param.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070079#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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800102#ifndef RIO_WINDOW_LEN
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103#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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
123/* These constants are derived from SCO Source */
124static struct Conf
Andrew Morton8d8706e2006-01-11 12:17:49 -0800125 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165};
166
167
168
169
170/* Function prototypes */
171
Andrew Morton8d8706e2006-01-11 12:17:49 -0800172static 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);
Alan Cox31f35932009-01-02 13:45:05 +0000176static int rio_carrier_raised(struct tty_port *port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800177static 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);
Alan Coxf6759fd2008-07-25 01:48:14 -0700182static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183static int rio_init_drivers(void);
184
Andrew Morton8d8706e2006-01-11 12:17:49 -0800185static void my_hd(void *addr, int len);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
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.... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800205static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Tobias Klauserfe971072006-01-09 20:54:02 -0800207#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
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 */
Adrian Bunk408b6642005-05-01 08:59:29 -0700213static long rio_irqmask = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
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 = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800223 rio_disable_tx_interrupts,
224 rio_enable_tx_interrupts,
225 rio_disable_rx_interrupts,
226 rio_enable_rx_interrupts,
Andrew Morton8d8706e2006-01-11 12:17:49 -0800227 rio_shutdown_port,
228 rio_set_real_termios,
229 rio_chars_in_buffer,
230 rio_close,
231 rio_hungup,
232 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233};
234
235/*
236 * Firmware loader driver specific routines
237 *
238 */
239
Arjan van de Ven62322d22006-07-03 00:24:21 -0700240static const struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800241 .owner = THIS_MODULE,
Alan Coxf6759fd2008-07-25 01:48:14 -0700242 .unlocked_ioctl = rio_fw_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243};
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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800257static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258{
259
Andrew Morton8d8706e2006-01-11 12:17:49 -0800260 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";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
Andrew Morton8d8706e2006-01-11 12:17:49 -0800263 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273}
274#else
275#define rio_paranoia_check(a,b,c) 0
276#endif
277
278
279#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800280static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800282 int i, j, ch;
283 unsigned char *addr = ad;
284
285 for (i = 0; i < len; i += 16) {
Alan Cox00d83a52006-03-24 03:18:28 -0800286 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800287 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296}
297#else
298#define my_hd(ad,len) do{/* nothing*/ } while (0)
299#endif
300
301
Andrew Morton8d8706e2006-01-11 12:17:49 -0800302/* Delay a number of jiffies, allowing a signal to interrupt */
303int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800305 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306
Andrew Morton8d8706e2006-01-11 12:17:49 -0800307 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
308 msleep_interruptible(jiffies_to_msecs(njiffies));
309 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310
Andrew Morton8d8706e2006-01-11 12:17:49 -0800311 if (signal_pending(current))
312 return RIO_FAIL;
313 else
314 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315}
316
317
Andrew Morton8d8706e2006-01-11 12:17:49 -0800318/* Delay a number of jiffies, disallowing a signal to interrupt */
319int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800321 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Andrew Morton8d8706e2006-01-11 12:17:49 -0800323 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
324 msleep(jiffies_to_msecs(njiffies));
325 func_exit();
326 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327}
328
Al Viro38d0d002006-05-27 00:15:09 -0400329void rio_copy_to_card(void *from, void __iomem *to, int len)
Alan Cox00d83a52006-03-24 03:18:28 -0800330{
Al Viroae5b28a2006-05-27 01:48:08 -0400331 rio_copy_toio(to, from, len);
Alan Cox00d83a52006-03-24 03:18:28 -0800332}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333
334int rio_minor(struct tty_struct *tty)
335{
Roel Kluin1f854492009-04-06 17:35:34 +0100336 return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337}
338
Andrew Morton8d8706e2006-01-11 12:17:49 -0800339static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340{
Jiri Slabyd6f63412008-04-30 00:53:57 -0700341 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342}
343
344
Andrew Morton8d8706e2006-01-11 12:17:49 -0800345static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800347 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
Andrew Morton8d8706e2006-01-11 12:17:49 -0800349 switch (HostP->Type) {
350 case RIO_AT:
351 case RIO_MCA:
352 case RIO_PCI:
Alan Cox00d83a52006-03-24 03:18:28 -0800353 writeb(0xFF, &HostP->ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355
Andrew Morton8d8706e2006-01-11 12:17:49 -0800356 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357}
358
359
David Howells7d12e782006-10-05 14:55:46 +0100360static irqreturn_t rio_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800362 struct Host *HostP;
363 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400365 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800366 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367
Andrew Morton8d8706e2006-01-11 12:17:49 -0800368 /* AAargh! The order in which to do these things is essential and
369 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Andrew Morton8d8706e2006-01-11 12:17:49 -0800371 - 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).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Andrew Morton8d8706e2006-01-11 12:17:49 -0800376 - Rate limit goes before hardware twiddling. Otherwise we won't
377 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Andrew Morton8d8706e2006-01-11 12:17:49 -0800379 - 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384
Andrew Morton8d8706e2006-01-11 12:17:49 -0800385 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Andrew Morton8d8706e2006-01-11 12:17:49 -0800391 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
392 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Andrew Morton8d8706e2006-01-11 12:17:49 -0800394 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800395 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800396 return IRQ_HANDLED;
397 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400399 RIOServiceHost(p, HostP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Alan Cox00d83a52006-03-24 03:18:28 -0800401 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Andrew Morton8d8706e2006-01-11 12:17:49 -0800403 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407}
408
409
Andrew Morton8d8706e2006-01-11 12:17:49 -0800410static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800412 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413
David Howells7d12e782006-10-05 14:55:46 +0100414 rio_interrupt(0, &p->RIOHosts[data]);
Jiri Slaby40565f12007-02-12 00:52:31 -0800415 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416
Andrew Morton8d8706e2006-01-11 12:17:49 -0800417 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418}
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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800429static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800431 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432
Alan Coxb5391e22008-07-16 21:55:20 +0100433 /* port->gs.port.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Andrew Morton8d8706e2006-01-11 12:17:49 -0800435 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436}
437
438
Andrew Morton8d8706e2006-01-11 12:17:49 -0800439static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800441 struct Port *PortP = ptr;
442 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443
Andrew Morton8d8706e2006-01-11 12:17:49 -0800444 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Andrew Morton8d8706e2006-01-11 12:17:49 -0800446 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
Andrew Morton8d8706e2006-01-11 12:17:49 -0800448 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
449 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
Andrew Morton8d8706e2006-01-11 12:17:49 -0800451 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Andrew Morton8d8706e2006-01-11 12:17:49 -0800453 /*
454 * In general we cannot count on "tx empty" interrupts, although
455 * the interrupt routine seems to be able to tell the difference.
456 */
Alan Coxb5391e22008-07-16 21:55:20 +0100457 PortP->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Andrew Morton8d8706e2006-01-11 12:17:49 -0800459 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460}
461
462
Andrew Morton8d8706e2006-01-11 12:17:49 -0800463static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800465 func_enter();
466 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467}
468
Andrew Morton8d8706e2006-01-11 12:17:49 -0800469static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800471 /* struct rio_port *port = ptr; */
472 func_enter();
473 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474}
475
476
477/* Jeez. Isn't this simple? */
Alan Cox31f35932009-01-02 13:45:05 +0000478static int rio_carrier_raised(struct tty_port *port)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Alan Cox31f35932009-01-02 13:45:05 +0000480 struct Port *PortP = container_of(port, struct Port, gs.port);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800481 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Andrew Morton8d8706e2006-01-11 12:17:49 -0800483 func_enter();
Jiri Slabyd6f63412008-04-30 00:53:57 -0700484 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485
Andrew Morton8d8706e2006-01-11 12:17:49 -0800486 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
487
488 func_exit();
489 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
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... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800495static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800497 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Andrew Morton8d8706e2006-01-11 12:17:49 -0800499 func_exit();
500 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501}
502
503
504/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800505static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800507 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
Andrew Morton8d8706e2006-01-11 12:17:49 -0800509 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Andrew Morton8d8706e2006-01-11 12:17:49 -0800511 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100512 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800513 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514}
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 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800524static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800526 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
Andrew Morton8d8706e2006-01-11 12:17:49 -0800528 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529
Andrew Morton8d8706e2006-01-11 12:17:49 -0800530 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100531 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800532
533 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534}
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 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800541static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800543 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Andrew Morton8d8706e2006-01-11 12:17:49 -0800545 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Andrew Morton8d8706e2006-01-11 12:17:49 -0800547 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Andrew Morton8d8706e2006-01-11 12:17:49 -0800549 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
Alan Coxb5391e22008-07-16 21:55:20 +0100551 if (PortP->gs.port.count) {
552 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
553 PortP->gs.port.count = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Alan Coxb5391e22008-07-16 21:55:20 +0100556 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800557 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
560
561
Alan Coxf6759fd2008-07-25 01:48:14 -0700562static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800564 int rc = 0;
565 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Andrew Morton8d8706e2006-01-11 12:17:49 -0800567 /* The "dev" argument isn't used. */
Alan Coxf6759fd2008-07-25 01:48:14 -0700568 lock_kernel();
Al Virod886cb52006-05-27 00:08:25 -0400569 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
Alan Coxf6759fd2008-07-25 01:48:14 -0700570 unlock_kernel();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571
Andrew Morton8d8706e2006-01-11 12:17:49 -0800572 func_exit();
573 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574}
575
Andrew Morton8d8706e2006-01-11 12:17:49 -0800576extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Andrew Morton8d8706e2006-01-11 12:17:49 -0800578static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579{
Al Virod886cb52006-05-27 00:08:25 -0400580 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800581 int rc;
582 struct Port *PortP;
583 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Andrew Morton8d8706e2006-01-11 12:17:49 -0800585 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
Andrew Morton8d8706e2006-01-11 12:17:49 -0800587 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588
Andrew Morton8d8706e2006-01-11 12:17:49 -0800589 rc = 0;
590 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800591 case TIOCSSOFTCAR:
Al Virod886cb52006-05-27 00:08:25 -0400592 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800593 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
594 }
595 break;
596 case TIOCGSERIAL:
597 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400598 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
599 rc = gs_getserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800600 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 {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700606 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
607 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800608 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;
Jiri Slabyd6f63412008-04-30 00:53:57 -0700622 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
623 arg ? arg * 100 : 250) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800624 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
625 rc = -EIO;
626 }
627 }
628 break;
629 case TIOCSSERIAL:
630 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400631 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
632 rc = gs_setserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800634 default:
635 rc = -ENOIOCTLCMD;
636 break;
637 }
638 func_exit();
639 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640}
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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800659static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800661 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
Andrew Morton8d8706e2006-01-11 12:17:49 -0800663 func_enter();
664 /* If the port is using any type of input flow
665 * control then throttle the port.
666 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667
Andrew Morton8d8706e2006-01-11 12:17:49 -0800668 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
669 port->State |= RIO_THROTTLE_RX;
670 }
671
672 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673}
674
675
Andrew Morton8d8706e2006-01-11 12:17:49 -0800676static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800678 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
Andrew Morton8d8706e2006-01-11 12:17:49 -0800680 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 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
Andrew Morton8d8706e2006-01-11 12:17:49 -0800686 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
Andrew Morton8d8706e2006-01-11 12:17:49 -0800688 func_exit();
689 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690}
691
692
693
694
695
696/* ********************************************************************** *
697 * Here are the initialization routines. *
698 * ********************************************************************** */
699
700
Andrew Morton8d8706e2006-01-11 12:17:49 -0800701static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800703 static struct vpd_prom vpdp;
704 char *p;
705 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706
Andrew Morton8d8706e2006-01-11 12:17:49 -0800707 func_enter();
708 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700709
Andrew Morton8d8706e2006-01-11 12:17:49 -0800710 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); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
Andrew Morton8d8706e2006-01-11 12:17:49 -0800715 /* Terminate the identifier string.
716 *** requires one extra byte in struct vpd_prom *** */
717 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700718
Andrew Morton8d8706e2006-01-11 12:17:49 -0800719 if (rio_debug & RIO_DEBUG_PROBE)
720 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Andrew Morton8d8706e2006-01-11 12:17:49 -0800722 func_exit();
723
724 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725}
726
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700727static const struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800728 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 .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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800780 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700781
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;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800788 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800790 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800792 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800794 out:
795 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 return 1;
797}
798
Alan Cox31f35932009-01-02 13:45:05 +0000799static const struct tty_port_operations rio_port_ops = {
800 .carrier_raised = rio_carrier_raised,
801};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Andrew Morton8d8706e2006-01-11 12:17:49 -0800803static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800805 int i;
806 struct Port *port;
807 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809 /* 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
Linus Torvalds1da177e2005-04-16 15:20:36 -0700815#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 *)
Alan Cox00d83a52006-03-24 03:18:28 -0800819 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);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800820
Alan Coxd0c98732009-01-02 13:45:12 +0000821 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800822 goto free0;
Alan Coxd0c98732009-01-02 13:45:12 +0000823 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800824 goto free1;
Alan Coxd0c98732009-01-02 13:45:12 +0000825 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
Andrew Morton8d8706e2006-01-11 12:17:49 -0800826 goto free2;
827 p->RIOConf = RIOConf;
828 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800831 for (i = 0; i < RIO_PORTS; i++) {
Alan Coxd0c98732009-01-02 13:45:12 +0000832 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800833 if (!port) {
834 goto free6;
835 }
836 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
Alan Cox31f35932009-01-02 13:45:05 +0000837 tty_port_init(&port->gs.port);
838 port->gs.port.ops = &rio_port_ops;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800839 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);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800847 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848#endif
849
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851
Andrew Morton8d8706e2006-01-11 12:17:49 -0800852 if (rio_debug & RIO_DEBUG_INIT) {
853 my_hd(&rio_real_driver, sizeof(rio_real_driver));
854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856
857 func_exit();
858 return 0;
859
860 free6:for (i--; i >= 0; i--)
861 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862/*free5:
863 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800864 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871}
872
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800875 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();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881}
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.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800891 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
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
Andrew Morton8d8706e2006-01-11 12:17:49 -0800904static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905{
Alan Cox00d83a52006-03-24 03:18:28 -0800906 unsigned long hwbase;
Al Virod886cb52006-05-27 00:08:25 -0400907 unsigned char __iomem *rebase;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800908 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910#define CNTRL_REG_OFFSET 0x50
911#define CNTRL_REG_GOODVALUE 0x18260000
912
Alan Cox00d83a52006-03-24 03:18:28 -0800913 hwbase = pci_resource_start(pdev, 0);
914 rebase = ioremap(hwbase, 0x80);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800915 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 }
Alan Cox00d83a52006-03-24 03:18:28 -0800920 iounmap(rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921}
922#endif
923
924
Andrew Morton8d8706e2006-01-11 12:17:49 -0800925static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800927 int found = 0;
928 int i;
929 struct Host *hp;
930 int retval;
931 struct vpd_prom *vpdp;
932 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
934#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800935 struct pci_dev *pdev = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800936 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937#endif
938
Andrew Morton8d8706e2006-01-11 12:17:49 -0800939 func_enter();
940 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
Andrew Morton8d8706e2006-01-11 12:17:49 -0800942 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
Andrew Morton8d8706e2006-01-11 12:17:49 -0800947 if (misc_register(&rio_fw_device) < 0) {
948 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
949 return -EIO;
950 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
Andrew Morton8d8706e2006-01-11 12:17:49 -0800952 retval = rio_init_datastructures();
953 if (retval < 0) {
954 misc_deregister(&rio_fw_device);
955 return retval;
956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800958 /* First look for the JET devices: */
959 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
Alan Cox554b7c82006-03-24 03:18:32 -0800960 u32 tint;
961
Andrew Morton8d8706e2006-01-11 12:17:49 -0800962 if (pci_enable_device(pdev))
963 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
Andrew Morton8d8706e2006-01-11 12:17:49 -0800965 /* 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 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800972 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");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Andrew Morton8d8706e2006-01-11 12:17:49 -0800981 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -0800982 hp->PaddrP = pci_resource_start(pdev, 2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800983 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);
Al Virod886cb52006-05-27 00:08:25 -0400987 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800988 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -0800989 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800990 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
991 spin_lock_init(&hp->HostLock);
992 rio_reset_interrupt(hp);
993 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994
Andrew Morton8d8706e2006-01-11 12:17:49 -0800995 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
Alan Cox554b7c82006-03-24 03:18:32 -0800996 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800997 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
Alan Cox00d83a52006-03-24 03:18:28 -0800998 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800999 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001000 ((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);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001002 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Andrew Morton8d8706e2006-01-11 12:17:49 -08001004 fix_rio_pci(pdev);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001005
1006 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1007 pci_dev_get(pdev);
1008
Alan Cox554b7c82006-03-24 03:18:32 -08001009 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001010 p->RIONumHosts++;
1011 found++;
1012 } else {
Al Virod886cb52006-05-27 00:08:25 -04001013 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001014 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001015 }
1016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
Andrew Morton8d8706e2006-01-11 12:17:49 -08001018 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031
1032#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001033 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -08001034 hp->PaddrP = pci_resource_start(pdev, 0);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001035 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);
Al Virod886cb52006-05-27 00:08:25 -04001040 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001041 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001042 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001043 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1044 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045
Andrew Morton8d8706e2006-01-11 12:17:49 -08001046 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1047 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Andrew Morton8d8706e2006-01-11 12:17:49 -08001049 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);
Alan Cox554b7c82006-03-24 03:18:32 -08001052 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Alan Cox00d83a52006-03-24 03:18:28 -08001053 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001054 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001055 ((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);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001057 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058
Jiri Slaby86fbf142006-10-21 10:24:01 -07001059 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1060 pci_dev_get(pdev);
1061
Alan Cox554b7c82006-03-24 03:18:32 -08001062 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001063 p->RIONumHosts++;
1064 found++;
1065 } else {
Al Virod886cb52006-05-27 00:08:25 -04001066 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001067 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001070 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001071#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001072 }
1073#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Morton8d8706e2006-01-11 12:17:49 -08001075 /* 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);
Al Virod886cb52006-05-27 00:08:25 -04001082 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001083 hp->Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -08001084 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1085 * -- YES! this is now a normal copy. Only the
Andrew Morton8d8706e2006-01-11 12:17:49 -08001086 * 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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
Andrew Morton8d8706e2006-01-11 12:17:49 -08001092 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... */
Alan Cox554b7c82006-03-24 03:18:32 -08001097 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001098 /* ... 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106
Amol Lad86842652006-12-06 20:35:19 -08001107 if (!okboard) {
Al Virod886cb52006-05-27 00:08:25 -04001108 iounmap(hp->Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001109 hp->Caddr = NULL;
1110 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001111 }
1112 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001113
1114
Andrew Morton8d8706e2006-01-11 12:17:49 -08001115 for (i = 0; i < p->RIONumHosts; i++) {
1116 hp = &p->RIOHosts[i];
1117 if (hp->Ivec) {
Thomas Gleixner5d8c8a22006-07-01 19:29:41 -07001118 int mode = IRQF_SHARED;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001119 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
Willy Tarreau88dacbe2007-02-17 18:57:09 +01001135 hp->Mode &= ~RIO_PCI_INT_ENABLE;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001136 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... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141
Jiri Slaby40565f12007-02-12 00:52:31 -08001142 setup_timer(&hp->timer, rio_pollfunc, i);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001143 if (!hp->Ivec) {
1144 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
Jiri Slaby40565f12007-02-12 00:52:31 -08001145 mod_timer(&hp->timer, jiffies + rio_poll);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001146 }
1147 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001148
Andrew Morton8d8706e2006-01-11 12:17:49 -08001149 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 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
Andrew Morton8d8706e2006-01-11 12:17:49 -08001157 func_exit();
1158 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001159}
1160
1161
Andrew Morton8d8706e2006-01-11 12:17:49 -08001162static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001164 int i;
1165 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Andrew Morton8d8706e2006-01-11 12:17:49 -08001167 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168
Andrew Morton8d8706e2006-01-11 12:17:49 -08001169 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 */
Jiri Slaby40565f12007-02-12 00:52:31 -08001176 del_timer_sync(&hp->timer);
Amol Lad86842652006-12-06 20:35:19 -08001177 if (hp->Caddr)
1178 iounmap(hp->Caddr);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001179 if (hp->Type == RIO_PCI)
1180 pci_dev_put(hp->pdev);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001181 }
1182
1183 if (misc_deregister(&rio_fw_device) < 0) {
1184 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186
1187
Andrew Morton8d8706e2006-01-11 12:17:49 -08001188 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189
Andrew Morton8d8706e2006-01-11 12:17:49 -08001190 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191
Andrew Morton8d8706e2006-01-11 12:17:49 -08001192 /* Release dynamically allocated memory */
1193 kfree(p->RIOPortp);
1194 kfree(p->RIOHosts);
1195 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196
Andrew Morton8d8706e2006-01-11 12:17:49 -08001197 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198}
1199
1200module_init(rio_init);
1201module_exit(rio_exit);