blob: 0cdfee152916ffb7bab395049ca69fe47baea8ab [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);
176static int rio_get_CD(void *ptr);
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);
182static int rio_fw_ioctl(struct inode *inode, 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,
227 rio_get_CD,
228 rio_shutdown_port,
229 rio_set_real_termios,
230 rio_chars_in_buffer,
231 rio_close,
232 rio_hungup,
233 NULL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234};
235
236/*
237 * Firmware loader driver specific routines
238 *
239 */
240
Arjan van de Ven62322d22006-07-03 00:24:21 -0700241static const struct file_operations rio_fw_fops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800242 .owner = THIS_MODULE,
243 .ioctl = rio_fw_ioctl,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244};
245
246static struct miscdevice rio_fw_device = {
247 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
248};
249
250
251
252
253
254#ifdef RIO_PARANOIA_CHECK
255
256/* This doesn't work. Who's paranoid around here? Not me! */
257
Andrew Morton8d8706e2006-01-11 12:17:49 -0800258static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259{
260
Andrew Morton8d8706e2006-01-11 12:17:49 -0800261 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
262 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Andrew Morton8d8706e2006-01-11 12:17:49 -0800264 if (!port) {
265 printk(badinfo, name, routine);
266 return 1;
267 }
268 if (port->magic != RIO_MAGIC) {
269 printk(badmagic, name, routine);
270 return 1;
271 }
272
273 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274}
275#else
276#define rio_paranoia_check(a,b,c) 0
277#endif
278
279
280#ifdef DEBUG
Andrew Morton8d8706e2006-01-11 12:17:49 -0800281static void my_hd(void *ad, int len)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800283 int i, j, ch;
284 unsigned char *addr = ad;
285
286 for (i = 0; i < len; i += 16) {
Alan Cox00d83a52006-03-24 03:18:28 -0800287 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800288 for (j = 0; j < 16; j++) {
289 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
290 }
291 for (j = 0; j < 16; j++) {
292 ch = addr[j + i];
293 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
294 }
295 rio_dprintk(RIO_DEBUG_PARAM, "\n");
296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297}
298#else
299#define my_hd(ad,len) do{/* nothing*/ } while (0)
300#endif
301
302
Andrew Morton8d8706e2006-01-11 12:17:49 -0800303/* Delay a number of jiffies, allowing a signal to interrupt */
304int RIODelay(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800306 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Andrew Morton8d8706e2006-01-11 12:17:49 -0800308 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
309 msleep_interruptible(jiffies_to_msecs(njiffies));
310 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311
Andrew Morton8d8706e2006-01-11 12:17:49 -0800312 if (signal_pending(current))
313 return RIO_FAIL;
314 else
315 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316}
317
318
Andrew Morton8d8706e2006-01-11 12:17:49 -0800319/* Delay a number of jiffies, disallowing a signal to interrupt */
320int RIODelay_ni(struct Port *PortP, int njiffies)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800322 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
Andrew Morton8d8706e2006-01-11 12:17:49 -0800324 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
325 msleep(jiffies_to_msecs(njiffies));
326 func_exit();
327 return !RIO_FAIL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328}
329
Al Viro38d0d002006-05-27 00:15:09 -0400330void rio_copy_to_card(void *from, void __iomem *to, int len)
Alan Cox00d83a52006-03-24 03:18:28 -0800331{
Al Viroae5b28a2006-05-27 01:48:08 -0400332 rio_copy_toio(to, from, len);
Alan Cox00d83a52006-03-24 03:18:28 -0800333}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335int rio_minor(struct tty_struct *tty)
336{
337 return tty->index + (tty->driver == rio_driver) ? 0 : 256;
338}
339
Andrew Morton8d8706e2006-01-11 12:17:49 -0800340static int rio_set_real_termios(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341{
Jiri Slabyd6f63412008-04-30 00:53:57 -0700342 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343}
344
345
Andrew Morton8d8706e2006-01-11 12:17:49 -0800346static void rio_reset_interrupt(struct Host *HostP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800348 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Andrew Morton8d8706e2006-01-11 12:17:49 -0800350 switch (HostP->Type) {
351 case RIO_AT:
352 case RIO_MCA:
353 case RIO_PCI:
Alan Cox00d83a52006-03-24 03:18:28 -0800354 writeb(0xFF, &HostP->ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Andrew Morton8d8706e2006-01-11 12:17:49 -0800357 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358}
359
360
David Howells7d12e782006-10-05 14:55:46 +0100361static irqreturn_t rio_interrupt(int irq, void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800363 struct Host *HostP;
364 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400366 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800367 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Andrew Morton8d8706e2006-01-11 12:17:49 -0800369 /* AAargh! The order in which to do these things is essential and
370 not trivial.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Andrew Morton8d8706e2006-01-11 12:17:49 -0800372 - hardware twiddling goes before "recursive". Otherwise when we
373 poll the card, and a recursive interrupt happens, we won't
374 ack the card, so it might keep on interrupting us. (especially
375 level sensitive interrupt systems like PCI).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Andrew Morton8d8706e2006-01-11 12:17:49 -0800377 - Rate limit goes before hardware twiddling. Otherwise we won't
378 catch a card that has gone bonkers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
Andrew Morton8d8706e2006-01-11 12:17:49 -0800380 - The "initialized" test goes after the hardware twiddling. Otherwise
381 the card will stick us in the interrupt routine again.
382
383 - The initialized test goes before recursive.
384 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Andrew Morton8d8706e2006-01-11 12:17:49 -0800386 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
387 if (HostP->Ivec == irq) {
388 /* Tell the card we've noticed the interrupt. */
389 rio_reset_interrupt(HostP);
390 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700391
Andrew Morton8d8706e2006-01-11 12:17:49 -0800392 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
393 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Andrew Morton8d8706e2006-01-11 12:17:49 -0800395 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
Alan Cox00d83a52006-03-24 03:18:28 -0800396 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800397 return IRQ_HANDLED;
398 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Jeff Garzikc7bec5a2006-10-06 15:00:58 -0400400 RIOServiceHost(p, HostP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Alan Cox00d83a52006-03-24 03:18:28 -0800402 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Andrew Morton8d8706e2006-01-11 12:17:49 -0800404 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
405 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
406 func_exit();
407 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408}
409
410
Andrew Morton8d8706e2006-01-11 12:17:49 -0800411static void rio_pollfunc(unsigned long data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800413 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414
David Howells7d12e782006-10-05 14:55:46 +0100415 rio_interrupt(0, &p->RIOHosts[data]);
Jiri Slaby40565f12007-02-12 00:52:31 -0800416 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417
Andrew Morton8d8706e2006-01-11 12:17:49 -0800418 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700419}
420
421
422/* ********************************************************************** *
423 * Here are the routines that actually *
424 * interface with the generic_serial driver *
425 * ********************************************************************** */
426
427/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
428 cards. .... Hmm. Ok I figured it out. You don't. -- REW */
429
Andrew Morton8d8706e2006-01-11 12:17:49 -0800430static void rio_disable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800432 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Alan Coxb5391e22008-07-16 21:55:20 +0100434 /* port->gs.port.flags &= ~GS_TX_INTEN; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Andrew Morton8d8706e2006-01-11 12:17:49 -0800436 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437}
438
439
Andrew Morton8d8706e2006-01-11 12:17:49 -0800440static void rio_enable_tx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800442 struct Port *PortP = ptr;
443 /* int hn; */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Andrew Morton8d8706e2006-01-11 12:17:49 -0800445 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
Andrew Morton8d8706e2006-01-11 12:17:49 -0800447 /* hn = PortP->HostP - p->RIOHosts;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Andrew Morton8d8706e2006-01-11 12:17:49 -0800449 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
450 rio_interrupt (-1,(void *) hn, NULL); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
Andrew Morton8d8706e2006-01-11 12:17:49 -0800452 RIOTxEnable((char *) PortP);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Andrew Morton8d8706e2006-01-11 12:17:49 -0800454 /*
455 * In general we cannot count on "tx empty" interrupts, although
456 * the interrupt routine seems to be able to tell the difference.
457 */
Alan Coxb5391e22008-07-16 21:55:20 +0100458 PortP->gs.port.flags &= ~GS_TX_INTEN;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
Andrew Morton8d8706e2006-01-11 12:17:49 -0800460 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461}
462
463
Andrew Morton8d8706e2006-01-11 12:17:49 -0800464static void rio_disable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800466 func_enter();
467 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468}
469
Andrew Morton8d8706e2006-01-11 12:17:49 -0800470static void rio_enable_rx_interrupts(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800472 /* struct rio_port *port = ptr; */
473 func_enter();
474 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475}
476
477
478/* Jeez. Isn't this simple? */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800479static int rio_get_CD(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800481 struct Port *PortP = ptr;
482 int rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Andrew Morton8d8706e2006-01-11 12:17:49 -0800484 func_enter();
Jiri Slabyd6f63412008-04-30 00:53:57 -0700485 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
Andrew Morton8d8706e2006-01-11 12:17:49 -0800487 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
488
489 func_exit();
490 return rv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491}
492
493
494/* Jeez. Isn't this simple? Actually, we can sync with the actual port
495 by just pushing stuff into the queue going to the port... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800496static int rio_chars_in_buffer(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800498 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Andrew Morton8d8706e2006-01-11 12:17:49 -0800500 func_exit();
501 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
503
504
505/* Nothing special here... */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800506static void rio_shutdown_port(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800508 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
Andrew Morton8d8706e2006-01-11 12:17:49 -0800510 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
Andrew Morton8d8706e2006-01-11 12:17:49 -0800512 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100513 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800514 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515}
516
517
518/* I haven't the foggiest why the decrement use count has to happen
519 here. The whole linux serial drivers stuff needs to be redesigned.
520 My guess is that this is a hack to minimize the impact of a bug
521 elsewhere. Thinking about it some more. (try it sometime) Try
522 running minicom on a serial port that is driven by a modularized
523 driver. Have the modem hangup. Then remove the driver module. Then
524 exit minicom. I expect an "oops". -- REW */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800525static void rio_hungup(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800527 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528
Andrew Morton8d8706e2006-01-11 12:17:49 -0800529 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530
Andrew Morton8d8706e2006-01-11 12:17:49 -0800531 PortP = (struct Port *) ptr;
Alan Coxb5391e22008-07-16 21:55:20 +0100532 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800533
534 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535}
536
537
538/* The standard serial_close would become shorter if you'd wrap it like
539 this.
540 rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
541 */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800542static void rio_close(void *ptr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800544 struct Port *PortP;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545
Andrew Morton8d8706e2006-01-11 12:17:49 -0800546 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Andrew Morton8d8706e2006-01-11 12:17:49 -0800548 PortP = (struct Port *) ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549
Andrew Morton8d8706e2006-01-11 12:17:49 -0800550 riotclose(ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Alan Coxb5391e22008-07-16 21:55:20 +0100552 if (PortP->gs.port.count) {
553 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
554 PortP->gs.port.count = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800555 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
Alan Coxb5391e22008-07-16 21:55:20 +0100557 PortP->gs.port.tty = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800558 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559}
560
561
562
Andrew Morton8d8706e2006-01-11 12:17:49 -0800563static int rio_fw_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800565 int rc = 0;
566 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
Andrew Morton8d8706e2006-01-11 12:17:49 -0800568 /* The "dev" argument isn't used. */
Al Virod886cb52006-05-27 00:08:25 -0400569 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
Andrew Morton8d8706e2006-01-11 12:17:49 -0800571 func_exit();
572 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573}
574
Andrew Morton8d8706e2006-01-11 12:17:49 -0800575extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576
Andrew Morton8d8706e2006-01-11 12:17:49 -0800577static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
Al Virod886cb52006-05-27 00:08:25 -0400579 void __user *argp = (void __user *)arg;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800580 int rc;
581 struct Port *PortP;
582 int ival;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Andrew Morton8d8706e2006-01-11 12:17:49 -0800584 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Andrew Morton8d8706e2006-01-11 12:17:49 -0800586 PortP = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Andrew Morton8d8706e2006-01-11 12:17:49 -0800588 rc = 0;
589 switch (cmd) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800590 case TIOCSSOFTCAR:
Al Virod886cb52006-05-27 00:08:25 -0400591 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800592 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
593 }
594 break;
595 case TIOCGSERIAL:
596 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400597 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
598 rc = gs_getserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800599 break;
600 case TCSBRK:
601 if (PortP->State & RIO_DELETED) {
602 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
603 rc = -EIO;
604 } else {
Jiri Slabyd6f63412008-04-30 00:53:57 -0700605 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
606 RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800607 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
608 rc = -EIO;
609 }
610 }
611 break;
612 case TCSBRKP:
613 if (PortP->State & RIO_DELETED) {
614 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
615 rc = -EIO;
616 } else {
617 int l;
618 l = arg ? arg * 100 : 250;
619 if (l > 255)
620 l = 255;
Jiri Slabyd6f63412008-04-30 00:53:57 -0700621 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
622 arg ? arg * 100 : 250) == RIO_FAIL) {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800623 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
624 rc = -EIO;
625 }
626 }
627 break;
628 case TIOCSSERIAL:
629 rc = -EFAULT;
Al Virod886cb52006-05-27 00:08:25 -0400630 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
631 rc = gs_setserial(&PortP->gs, argp);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800632 break;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800633 default:
634 rc = -ENOIOCTLCMD;
635 break;
636 }
637 func_exit();
638 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639}
640
641
642/* The throttle/unthrottle scheme for the Specialix card is different
643 * from other drivers and deserves some explanation.
644 * The Specialix hardware takes care of XON/XOFF
645 * and CTS/RTS flow control itself. This means that all we have to
646 * do when signalled by the upper tty layer to throttle/unthrottle is
647 * to make a note of it here. When we come to read characters from the
648 * rx buffers on the card (rio_receive_chars()) we look to see if the
649 * upper layer can accept more (as noted here in rio_rx_throt[]).
650 * If it can't we simply don't remove chars from the cards buffer.
651 * When the tty layer can accept chars, we again note that here and when
652 * rio_receive_chars() is called it will remove them from the cards buffer.
653 * The card will notice that a ports buffer has drained below some low
654 * water mark and will unflow control the line itself, using whatever
655 * flow control scheme is in use for that port. -- Simon Allen
656 */
657
Andrew Morton8d8706e2006-01-11 12:17:49 -0800658static void rio_throttle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800660 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Andrew Morton8d8706e2006-01-11 12:17:49 -0800662 func_enter();
663 /* If the port is using any type of input flow
664 * control then throttle the port.
665 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Andrew Morton8d8706e2006-01-11 12:17:49 -0800667 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
668 port->State |= RIO_THROTTLE_RX;
669 }
670
671 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700672}
673
674
Andrew Morton8d8706e2006-01-11 12:17:49 -0800675static void rio_unthrottle(struct tty_struct *tty)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800677 struct Port *port = (struct Port *) tty->driver_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
Andrew Morton8d8706e2006-01-11 12:17:49 -0800679 func_enter();
680 /* Always unthrottle even if flow control is not enabled on
681 * this port in case we disabled flow control while the port
682 * was throttled
683 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Andrew Morton8d8706e2006-01-11 12:17:49 -0800685 port->State &= ~RIO_THROTTLE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Andrew Morton8d8706e2006-01-11 12:17:49 -0800687 func_exit();
688 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691
692
693
694
695/* ********************************************************************** *
696 * Here are the initialization routines. *
697 * ********************************************************************** */
698
699
Andrew Morton8d8706e2006-01-11 12:17:49 -0800700static struct vpd_prom *get_VPD_PROM(struct Host *hp)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800702 static struct vpd_prom vpdp;
703 char *p;
704 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705
Andrew Morton8d8706e2006-01-11 12:17:49 -0800706 func_enter();
707 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 -0700708
Andrew Morton8d8706e2006-01-11 12:17:49 -0800709 p = (char *) &vpdp;
710 for (i = 0; i < sizeof(struct vpd_prom); i++)
711 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
712 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Andrew Morton8d8706e2006-01-11 12:17:49 -0800714 /* Terminate the identifier string.
715 *** requires one extra byte in struct vpd_prom *** */
716 *p++ = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717
Andrew Morton8d8706e2006-01-11 12:17:49 -0800718 if (rio_debug & RIO_DEBUG_PROBE)
719 my_hd((char *) &vpdp, 0x20);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720
Andrew Morton8d8706e2006-01-11 12:17:49 -0800721 func_exit();
722
723 return &vpdp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724}
725
Jeff Dikeb68e31d2006-10-02 02:17:18 -0700726static const struct tty_operations rio_ops = {
Andrew Morton8d8706e2006-01-11 12:17:49 -0800727 .open = riotopen,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 .close = gs_close,
729 .write = gs_write,
730 .put_char = gs_put_char,
731 .flush_chars = gs_flush_chars,
732 .write_room = gs_write_room,
733 .chars_in_buffer = gs_chars_in_buffer,
734 .flush_buffer = gs_flush_buffer,
735 .ioctl = rio_ioctl,
736 .throttle = rio_throttle,
737 .unthrottle = rio_unthrottle,
738 .set_termios = gs_set_termios,
739 .stop = gs_stop,
740 .start = gs_start,
741 .hangup = gs_hangup,
742};
743
744static int rio_init_drivers(void)
745{
746 int error = -ENOMEM;
747
748 rio_driver = alloc_tty_driver(256);
749 if (!rio_driver)
750 goto out;
751 rio_driver2 = alloc_tty_driver(256);
752 if (!rio_driver2)
753 goto out1;
754
755 func_enter();
756
757 rio_driver->owner = THIS_MODULE;
758 rio_driver->driver_name = "specialix_rio";
759 rio_driver->name = "ttySR";
760 rio_driver->major = RIO_NORMAL_MAJOR0;
761 rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
762 rio_driver->subtype = SERIAL_TYPE_NORMAL;
763 rio_driver->init_termios = tty_std_termios;
764 rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
765 rio_driver->flags = TTY_DRIVER_REAL_RAW;
766 tty_set_operations(rio_driver, &rio_ops);
767
768 rio_driver2->owner = THIS_MODULE;
769 rio_driver2->driver_name = "specialix_rio";
770 rio_driver2->name = "ttySR";
771 rio_driver2->major = RIO_NORMAL_MAJOR1;
772 rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
773 rio_driver2->subtype = SERIAL_TYPE_NORMAL;
774 rio_driver2->init_termios = tty_std_termios;
775 rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
776 rio_driver2->flags = TTY_DRIVER_REAL_RAW;
777 tty_set_operations(rio_driver2, &rio_ops);
778
Andrew Morton8d8706e2006-01-11 12:17:49 -0800779 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
781 if ((error = tty_register_driver(rio_driver)))
782 goto out2;
783 if ((error = tty_register_driver(rio_driver2)))
784 goto out3;
785 func_exit();
786 return 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800787 out3:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 tty_unregister_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800789 out2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 put_tty_driver(rio_driver2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800791 out1:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792 put_tty_driver(rio_driver);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800793 out:
794 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 return 1;
796}
797
798
Andrew Morton8d8706e2006-01-11 12:17:49 -0800799static void *ckmalloc(int size)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800801 void *p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802
Yoann Padioleaudd00cc42007-07-19 01:49:03 -0700803 p = kzalloc(size, GFP_KERNEL);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800804 return p;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805}
806
807
808
Andrew Morton8d8706e2006-01-11 12:17:49 -0800809static int rio_init_datastructures(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700810{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800811 int i;
812 struct Port *port;
813 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Andrew Morton8d8706e2006-01-11 12:17:49 -0800815 /* Many drivers statically allocate the maximum number of ports
816 There is no reason not to allocate them dynamically. Is there? -- REW */
817 /* However, the RIO driver allows users to configure their first
818 RTA as the ports numbered 504-511. We therefore need to allocate
819 the whole range. :-( -- REW */
820
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821#define RI_SZ sizeof(struct rio_info)
822#define HOST_SZ sizeof(struct Host)
823#define PORT_SZ sizeof(struct Port *)
824#define TMIO_SZ sizeof(struct termios *)
Alan Cox00d83a52006-03-24 03:18:28 -0800825 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 -0800826
827 if (!(p = ckmalloc(RI_SZ)))
828 goto free0;
829 if (!(p->RIOHosts = ckmalloc(RIO_HOSTS * HOST_SZ)))
830 goto free1;
831 if (!(p->RIOPortp = ckmalloc(RIO_PORTS * PORT_SZ)))
832 goto free2;
833 p->RIOConf = RIOConf;
834 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835
836#if 1
Andrew Morton8d8706e2006-01-11 12:17:49 -0800837 for (i = 0; i < RIO_PORTS; i++) {
838 port = p->RIOPortp[i] = ckmalloc(sizeof(struct Port));
839 if (!port) {
840 goto free6;
841 }
842 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
843 port->PortNum = i;
844 port->gs.magic = RIO_MAGIC;
845 port->gs.close_delay = HZ / 2;
846 port->gs.closing_wait = 30 * HZ;
847 port->gs.rd = &rio_real_driver;
848 spin_lock_init(&port->portSem);
849 /*
850 * Initializing wait queue
851 */
Alan Coxb5391e22008-07-16 21:55:20 +0100852 init_waitqueue_head(&port->gs.port.open_wait);
853 init_waitqueue_head(&port->gs.port.close_wait);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855#else
Andrew Morton8d8706e2006-01-11 12:17:49 -0800856 /* We could postpone initializing them to when they are configured. */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857#endif
858
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Andrew Morton8d8706e2006-01-11 12:17:49 -0800861 if (rio_debug & RIO_DEBUG_INIT) {
862 my_hd(&rio_real_driver, sizeof(rio_real_driver));
863 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
Andrew Morton8d8706e2006-01-11 12:17:49 -0800865
866 func_exit();
867 return 0;
868
869 free6:for (i--; i >= 0; i--)
870 kfree(p->RIOPortp[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*free5:
872 free4:
Andrew Morton8d8706e2006-01-11 12:17:49 -0800873 free3:*/ kfree(p->RIOPortp);
874 free2:kfree(p->RIOHosts);
875 free1:
876 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
877 kfree(p);
878 free0:
879 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880}
881
Andrew Morton8d8706e2006-01-11 12:17:49 -0800882static void __exit rio_release_drivers(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800884 func_enter();
885 tty_unregister_driver(rio_driver2);
886 tty_unregister_driver(rio_driver);
887 put_tty_driver(rio_driver2);
888 put_tty_driver(rio_driver);
889 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890}
891
892
893#ifdef CONFIG_PCI
894 /* This was written for SX, but applies to RIO too...
895 (including bugs....)
896
897 There is another bit besides Bit 17. Turning that bit off
898 (on boards shipped with the fix in the eeprom) results in a
899 hang on the next access to the card.
Andrew Morton8d8706e2006-01-11 12:17:49 -0800900 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
902 /********************************************************
903 * Setting bit 17 in the CNTRL register of the PLX 9050 *
904 * chip forces a retry on writes while a read is pending.*
905 * This is to prevent the card locking up on Intel Xeon *
906 * multiprocessor systems with the NX chipset. -- NV *
907 ********************************************************/
908
909/* Newer cards are produced with this bit set from the configuration
910 EEprom. As the bit is read/write for the CPU, we can fix it here,
911 if we detect that it isn't set correctly. -- REW */
912
Andrew Morton8d8706e2006-01-11 12:17:49 -0800913static void fix_rio_pci(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914{
Alan Cox00d83a52006-03-24 03:18:28 -0800915 unsigned long hwbase;
Al Virod886cb52006-05-27 00:08:25 -0400916 unsigned char __iomem *rebase;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800917 unsigned int t;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919#define CNTRL_REG_OFFSET 0x50
920#define CNTRL_REG_GOODVALUE 0x18260000
921
Alan Cox00d83a52006-03-24 03:18:28 -0800922 hwbase = pci_resource_start(pdev, 0);
923 rebase = ioremap(hwbase, 0x80);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800924 t = readl(rebase + CNTRL_REG_OFFSET);
925 if (t != CNTRL_REG_GOODVALUE) {
926 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
927 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
928 }
Alan Cox00d83a52006-03-24 03:18:28 -0800929 iounmap(rebase);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930}
931#endif
932
933
Andrew Morton8d8706e2006-01-11 12:17:49 -0800934static int __init rio_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935{
Andrew Morton8d8706e2006-01-11 12:17:49 -0800936 int found = 0;
937 int i;
938 struct Host *hp;
939 int retval;
940 struct vpd_prom *vpdp;
941 int okboard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800944 struct pci_dev *pdev = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800945 unsigned short tshort;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946#endif
947
Andrew Morton8d8706e2006-01-11 12:17:49 -0800948 func_enter();
949 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Andrew Morton8d8706e2006-01-11 12:17:49 -0800951 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
952 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
953 rio_debug = -1;
954 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955
Andrew Morton8d8706e2006-01-11 12:17:49 -0800956 if (misc_register(&rio_fw_device) < 0) {
957 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
958 return -EIO;
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
Andrew Morton8d8706e2006-01-11 12:17:49 -0800961 retval = rio_init_datastructures();
962 if (retval < 0) {
963 misc_deregister(&rio_fw_device);
964 return retval;
965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966#ifdef CONFIG_PCI
Andrew Morton8d8706e2006-01-11 12:17:49 -0800967 /* First look for the JET devices: */
968 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
Alan Cox554b7c82006-03-24 03:18:32 -0800969 u32 tint;
970
Andrew Morton8d8706e2006-01-11 12:17:49 -0800971 if (pci_enable_device(pdev))
972 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Andrew Morton8d8706e2006-01-11 12:17:49 -0800974 /* Specialix has a whole bunch of cards with
975 0x2000 as the device ID. They say its because
976 the standard requires it. Stupid standard. */
977 /* It seems that reading a word doesn't work reliably on 2.0.
978 Also, reading a non-aligned dword doesn't work. So we read the
979 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
980 ourselves */
Andrew Morton8d8706e2006-01-11 12:17:49 -0800981 pci_read_config_dword(pdev, 0x2c, &tint);
982 tshort = (tint >> 16) & 0xffff;
983 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
984 if (tshort != 0x0100) {
985 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
986 continue;
987 }
988 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989
Andrew Morton8d8706e2006-01-11 12:17:49 -0800990 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -0800991 hp->PaddrP = pci_resource_start(pdev, 2);
Andrew Morton8d8706e2006-01-11 12:17:49 -0800992 hp->Ivec = pdev->irq;
993 if (((1 << hp->Ivec) & rio_irqmask) == 0)
994 hp->Ivec = 0;
995 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -0400996 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800997 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -0800998 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -0800999 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1000 spin_lock_init(&hp->HostLock);
1001 rio_reset_interrupt(hp);
1002 rio_start_card_running(hp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Andrew Morton8d8706e2006-01-11 12:17:49 -08001004 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 -08001005 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001006 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
Alan Cox00d83a52006-03-24 03:18:28 -08001007 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001008 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001009 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1010 ((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 -08001011 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
Andrew Morton8d8706e2006-01-11 12:17:49 -08001013 fix_rio_pci(pdev);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001014
1015 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1016 pci_dev_get(pdev);
1017
Alan Cox554b7c82006-03-24 03:18:32 -08001018 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001019 p->RIONumHosts++;
1020 found++;
1021 } else {
Al Virod886cb52006-05-27 00:08:25 -04001022 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001023 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001024 }
1025 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026
Andrew Morton8d8706e2006-01-11 12:17:49 -08001027 /* Then look for the older PCI card.... : */
1028
1029 /* These older PCI cards have problems (only byte-mode access is
1030 supported), which makes them a bit awkward to support.
1031 They also have problems sharing interrupts. Be careful.
1032 (The driver now refuses to share interrupts for these
1033 cards. This should be sufficient).
1034 */
1035
1036 /* Then look for the older RIO/PCI devices: */
1037 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1038 if (pci_enable_device(pdev))
1039 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041#ifdef CONFIG_RIO_OLDPCI
Andrew Morton8d8706e2006-01-11 12:17:49 -08001042 hp = &p->RIOHosts[p->RIONumHosts];
Alan Cox554b7c82006-03-24 03:18:32 -08001043 hp->PaddrP = pci_resource_start(pdev, 0);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001044 hp->Ivec = pdev->irq;
1045 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1046 hp->Ivec = 0;
1047 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1048 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001049 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001050 hp->Type = RIO_PCI;
Alan Cox00d83a52006-03-24 03:18:28 -08001051 hp->Copy = rio_copy_to_card;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001052 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1053 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054
Andrew Morton8d8706e2006-01-11 12:17:49 -08001055 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1056 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
Andrew Morton8d8706e2006-01-11 12:17:49 -08001058 rio_reset_interrupt(hp);
1059 rio_start_card_running(hp);
1060 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 -08001061 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
Alan Cox00d83a52006-03-24 03:18:28 -08001062 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001063 p->RIOHosts[p->RIONumHosts].UniqueNum =
Alan Cox00d83a52006-03-24 03:18:28 -08001064 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1065 ((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 -08001066 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
Jiri Slaby86fbf142006-10-21 10:24:01 -07001068 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1069 pci_dev_get(pdev);
1070
Alan Cox554b7c82006-03-24 03:18:32 -08001071 p->RIOLastPCISearch = 0;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001072 p->RIONumHosts++;
1073 found++;
1074 } else {
Al Virod886cb52006-05-27 00:08:25 -04001075 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001076 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001077 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078#else
Andrew Morton8d8706e2006-01-11 12:17:49 -08001079 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 -07001080#endif
Andrew Morton8d8706e2006-01-11 12:17:49 -08001081 }
1082#endif /* PCI */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083
Andrew Morton8d8706e2006-01-11 12:17:49 -08001084 /* Now probe for ISA cards... */
1085 for (i = 0; i < NR_RIO_ADDRS; i++) {
1086 hp = &p->RIOHosts[p->RIONumHosts];
1087 hp->PaddrP = rio_probe_addrs[i];
1088 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1089 hp->Ivec = 0;
1090 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
Al Virod886cb52006-05-27 00:08:25 -04001091 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001092 hp->Type = RIO_AT;
Alan Cox00d83a52006-03-24 03:18:28 -08001093 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1094 * -- YES! this is now a normal copy. Only the
Andrew Morton8d8706e2006-01-11 12:17:49 -08001095 * old PCI card uses the special PCI copy.
1096 * Moreover, the ISA card will work with the
1097 * special PCI copy anyway. -- REW */
1098 hp->Mode = 0;
1099 spin_lock_init(&hp->HostLock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100
Andrew Morton8d8706e2006-01-11 12:17:49 -08001101 vpdp = get_VPD_PROM(hp);
1102 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1103 okboard = 0;
1104 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)) {
1105 /* Board is present... */
Alan Cox554b7c82006-03-24 03:18:32 -08001106 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
Andrew Morton8d8706e2006-01-11 12:17:49 -08001107 /* ... and feeling fine!!!! */
1108 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1109 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1110 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1111 okboard++;
1112 found++;
1113 }
1114 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115
Amol Lad86842652006-12-06 20:35:19 -08001116 if (!okboard) {
Al Virod886cb52006-05-27 00:08:25 -04001117 iounmap(hp->Caddr);
Amol Lad86842652006-12-06 20:35:19 -08001118 hp->Caddr = NULL;
1119 }
Andrew Morton8d8706e2006-01-11 12:17:49 -08001120 }
1121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123
Andrew Morton8d8706e2006-01-11 12:17:49 -08001124 for (i = 0; i < p->RIONumHosts; i++) {
1125 hp = &p->RIOHosts[i];
1126 if (hp->Ivec) {
Thomas Gleixner5d8c8a22006-07-01 19:29:41 -07001127 int mode = IRQF_SHARED;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001128 if (hp->Ivec & 0x8000) {
1129 mode = 0;
1130 hp->Ivec &= 0x7fff;
1131 }
1132 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1133 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1134 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1135 if (retval) {
1136 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1137 hp->Ivec = 0;
1138 }
1139 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1140 if (hp->Ivec != 0) {
1141 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1142 hp->Mode |= RIO_PCI_INT_ENABLE;
1143 } else
Willy Tarreau88dacbe2007-02-17 18:57:09 +01001144 hp->Mode &= ~RIO_PCI_INT_ENABLE;
Andrew Morton8d8706e2006-01-11 12:17:49 -08001145 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1146 rio_start_card_running(hp);
1147 }
1148 /* Init the timer "always" to make sure that it can safely be
1149 deleted when we unload... */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
Jiri Slaby40565f12007-02-12 00:52:31 -08001151 setup_timer(&hp->timer, rio_pollfunc, i);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001152 if (!hp->Ivec) {
1153 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
Jiri Slaby40565f12007-02-12 00:52:31 -08001154 mod_timer(&hp->timer, jiffies + rio_poll);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001155 }
1156 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
Andrew Morton8d8706e2006-01-11 12:17:49 -08001158 if (found) {
1159 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1160 rio_init_drivers();
1161 } else {
1162 /* deregister the misc device we created earlier */
1163 misc_deregister(&rio_fw_device);
1164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165
Andrew Morton8d8706e2006-01-11 12:17:49 -08001166 func_exit();
1167 return found ? 0 : -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168}
1169
1170
Andrew Morton8d8706e2006-01-11 12:17:49 -08001171static void __exit rio_exit(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Andrew Morton8d8706e2006-01-11 12:17:49 -08001173 int i;
1174 struct Host *hp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Andrew Morton8d8706e2006-01-11 12:17:49 -08001176 func_enter();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Andrew Morton8d8706e2006-01-11 12:17:49 -08001178 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1179 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1180 if (hp->Ivec) {
1181 free_irq(hp->Ivec, hp);
1182 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1183 }
1184 /* It is safe/allowed to del_timer a non-active timer */
Jiri Slaby40565f12007-02-12 00:52:31 -08001185 del_timer_sync(&hp->timer);
Amol Lad86842652006-12-06 20:35:19 -08001186 if (hp->Caddr)
1187 iounmap(hp->Caddr);
Jiri Slaby86fbf142006-10-21 10:24:01 -07001188 if (hp->Type == RIO_PCI)
1189 pci_dev_put(hp->pdev);
Andrew Morton8d8706e2006-01-11 12:17:49 -08001190 }
1191
1192 if (misc_deregister(&rio_fw_device) < 0) {
1193 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1194 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196
Andrew Morton8d8706e2006-01-11 12:17:49 -08001197 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
Andrew Morton8d8706e2006-01-11 12:17:49 -08001199 rio_release_drivers();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200
Andrew Morton8d8706e2006-01-11 12:17:49 -08001201 /* Release dynamically allocated memory */
1202 kfree(p->RIOPortp);
1203 kfree(p->RIOHosts);
1204 kfree(p);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205
Andrew Morton8d8706e2006-01-11 12:17:49 -08001206 func_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207}
1208
1209module_init(rio_init);
1210module_exit(rio_exit);