GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / char / rio / rio_linux.c
blob2564f2079ef2012d68ce0178643604378f2aed23
2 /* rio_linux.c -- Linux driver for the Specialix RIO series cards.
5 * (C) 1999 R.E.Wolff@BitWizard.nl
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.
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.
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.
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.
28 * */
30 #include <linux/module.h>
31 #include <linux/kdev_t.h>
32 #include <asm/io.h>
33 #include <linux/kernel.h>
34 #include <linux/sched.h>
35 #include <linux/ioport.h>
36 #include <linux/interrupt.h>
37 #include <linux/errno.h>
38 #include <linux/tty.h>
39 #include <linux/tty_flip.h>
40 #include <linux/mm.h>
41 #include <linux/serial.h>
42 #include <linux/fcntl.h>
43 #include <linux/major.h>
44 #include <linux/delay.h>
45 #include <linux/pci.h>
46 #include <linux/slab.h>
47 #include <linux/smp_lock.h>
48 #include <linux/miscdevice.h>
49 #include <linux/init.h>
51 #include <linux/generic_serial.h>
52 #include <asm/uaccess.h>
54 #include "linux_compat.h"
55 #include "pkt.h"
56 #include "daemon.h"
57 #include "rio.h"
58 #include "riospace.h"
59 #include "cmdpkt.h"
60 #include "map.h"
61 #include "rup.h"
62 #include "port.h"
63 #include "riodrvr.h"
64 #include "rioinfo.h"
65 #include "func.h"
66 #include "errors.h"
67 #include "pci.h"
69 #include "parmmap.h"
70 #include "unixrup.h"
71 #include "board.h"
72 #include "host.h"
73 #include "phb.h"
74 #include "link.h"
75 #include "cmdblk.h"
76 #include "route.h"
77 #include "cirrus.h"
78 #include "rioioctl.h"
79 #include "param.h"
80 #include "protsts.h"
81 #include "rioboard.h"
84 #include "rio_linux.h"
86 /* I don't think that this driver can handle more than 512 ports on
87 one machine. Specialix specifies max 4 boards in one machine. I don't
88 know why. If you want to try anyway you'll have to increase the number
89 of boards in rio.h. You'll have to allocate more majors if you need
90 more than 512 ports.... */
92 #ifndef RIO_NORMAL_MAJOR0
93 /* This allows overriding on the compiler commandline, or in a "major.h"
94 include or something like that */
95 #define RIO_NORMAL_MAJOR0 154
96 #define RIO_NORMAL_MAJOR1 156
97 #endif
99 #ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
100 #define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
101 #endif
103 #ifndef RIO_WINDOW_LEN
104 #define RIO_WINDOW_LEN 0x10000
105 #endif
108 /* Configurable options:
109 (Don't be too sure that it'll work if you toggle them) */
111 /* Am I paranoid or not ? ;-) */
112 #undef RIO_PARANOIA_CHECK
115 /* 20 -> 2000 per second. The card should rate-limit interrupts at 1000
116 Hz, but it is user configurable. I don't recommend going above 1000
117 Hz. The interrupt ratelimit might trigger if the interrupt is
118 shared with a very active other device.
119 undef this if you want to disable the check....
121 #define IRQ_RATE_LIMIT 200
124 /* These constants are derived from SCO Source */
125 static struct Conf
126 RIOConf = {
127 /* locator */ "RIO Config here",
128 /* startuptime */ HZ * 2,
129 /* how long to wait for card to run */
130 /* slowcook */ 0,
131 /* TRUE -> always use line disc. */
132 /* intrpolltime */ 1,
133 /* The frequency of OUR polls */
134 /* breakinterval */ 25,
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 */
170 /* Function prototypes */
172 static void rio_disable_tx_interrupts(void *ptr);
173 static void rio_enable_tx_interrupts(void *ptr);
174 static void rio_disable_rx_interrupts(void *ptr);
175 static void rio_enable_rx_interrupts(void *ptr);
176 static int rio_carrier_raised(struct tty_port *port);
177 static void rio_shutdown_port(void *ptr);
178 static int rio_set_real_termios(void *ptr);
179 static void rio_hungup(void *ptr);
180 static void rio_close(void *ptr);
181 static int rio_chars_in_buffer(void *ptr);
182 static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
183 static int rio_init_drivers(void);
185 static void my_hd(void *addr, int len);
187 static struct tty_driver *rio_driver, *rio_driver2;
189 /* The name "p" is a bit non-descript. But that's what the rio-lynxos
190 sources use all over the place. */
191 struct rio_info *p;
193 int rio_debug;
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.
200 static int rio_poll = 1;
203 /* These are the only open spaces in my computer. Yours may have more
204 or less.... */
205 static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
207 #define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
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 */
213 static long rio_irqmask = -1;
215 MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
216 MODULE_DESCRIPTION("RIO driver");
217 MODULE_LICENSE("GPL");
218 module_param(rio_poll, int, 0);
219 module_param(rio_debug, int, 0644);
220 module_param(rio_irqmask, long, 0);
222 static struct real_driver rio_real_driver = {
223 rio_disable_tx_interrupts,
224 rio_enable_tx_interrupts,
225 rio_disable_rx_interrupts,
226 rio_enable_rx_interrupts,
227 rio_shutdown_port,
228 rio_set_real_termios,
229 rio_chars_in_buffer,
230 rio_close,
231 rio_hungup,
232 NULL
236 * Firmware loader driver specific routines
240 static const struct file_operations rio_fw_fops = {
241 .owner = THIS_MODULE,
242 .unlocked_ioctl = rio_fw_ioctl,
245 static struct miscdevice rio_fw_device = {
246 RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
253 #ifdef RIO_PARANOIA_CHECK
255 /* This doesn't work. Who's paranoid around here? Not me! */
257 static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
260 static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
261 static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
263 if (!port) {
264 printk(badinfo, name, routine);
265 return 1;
267 if (port->magic != RIO_MAGIC) {
268 printk(badmagic, name, routine);
269 return 1;
272 return 0;
274 #else
275 #define rio_paranoia_check(a,b,c) 0
276 #endif
279 #ifdef DEBUG
280 static void my_hd(void *ad, int len)
282 int i, j, ch;
283 unsigned char *addr = ad;
285 for (i = 0; i < len; i += 16) {
286 rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
287 for (j = 0; j < 16; j++) {
288 rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
290 for (j = 0; j < 16; j++) {
291 ch = addr[j + i];
292 rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
294 rio_dprintk(RIO_DEBUG_PARAM, "\n");
297 #else
298 #define my_hd(ad,len) do{/* nothing*/ } while (0)
299 #endif
302 /* Delay a number of jiffies, allowing a signal to interrupt */
303 int RIODelay(struct Port *PortP, int njiffies)
305 func_enter();
307 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
308 msleep_interruptible(jiffies_to_msecs(njiffies));
309 func_exit();
311 if (signal_pending(current))
312 return RIO_FAIL;
313 else
314 return !RIO_FAIL;
318 /* Delay a number of jiffies, disallowing a signal to interrupt */
319 int RIODelay_ni(struct Port *PortP, int njiffies)
321 func_enter();
323 rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
324 msleep(jiffies_to_msecs(njiffies));
325 func_exit();
326 return !RIO_FAIL;
329 void rio_copy_to_card(void *from, void __iomem *to, int len)
331 rio_copy_toio(to, from, len);
334 int rio_minor(struct tty_struct *tty)
336 return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
339 static int rio_set_real_termios(void *ptr)
341 return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
345 static void rio_reset_interrupt(struct Host *HostP)
347 func_enter();
349 switch (HostP->Type) {
350 case RIO_AT:
351 case RIO_MCA:
352 case RIO_PCI:
353 writeb(0xFF, &HostP->ResetInt);
356 func_exit();
360 static irqreturn_t rio_interrupt(int irq, void *ptr)
362 struct Host *HostP;
363 func_enter();
365 HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
366 rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
368 /* AAargh! The order in which to do these things is essential and
369 not trivial.
371 - hardware twiddling goes before "recursive". Otherwise when we
372 poll the card, and a recursive interrupt happens, we won't
373 ack the card, so it might keep on interrupting us. (especially
374 level sensitive interrupt systems like PCI).
376 - Rate limit goes before hardware twiddling. Otherwise we won't
377 catch a card that has gone bonkers.
379 - The "initialized" test goes after the hardware twiddling. Otherwise
380 the card will stick us in the interrupt routine again.
382 - The initialized test goes before recursive.
385 rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
386 if (HostP->Ivec == irq) {
387 /* Tell the card we've noticed the interrupt. */
388 rio_reset_interrupt(HostP);
391 if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
392 return IRQ_HANDLED;
394 if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
395 printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
396 return IRQ_HANDLED;
399 RIOServiceHost(p, HostP);
401 rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
403 clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
404 rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
405 func_exit();
406 return IRQ_HANDLED;
410 static void rio_pollfunc(unsigned long data)
412 func_enter();
414 rio_interrupt(0, &p->RIOHosts[data]);
415 mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
417 func_exit();
421 /* ********************************************************************** *
422 * Here are the routines that actually *
423 * interface with the generic_serial driver *
424 * ********************************************************************** */
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 */
429 static void rio_disable_tx_interrupts(void *ptr)
431 func_enter();
433 /* port->gs.port.flags &= ~GS_TX_INTEN; */
435 func_exit();
439 static void rio_enable_tx_interrupts(void *ptr)
441 struct Port *PortP = ptr;
442 /* int hn; */
444 func_enter();
446 /* hn = PortP->HostP - p->RIOHosts;
448 rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
449 rio_interrupt (-1,(void *) hn, NULL); */
451 RIOTxEnable((char *) PortP);
454 * In general we cannot count on "tx empty" interrupts, although
455 * the interrupt routine seems to be able to tell the difference.
457 PortP->gs.port.flags &= ~GS_TX_INTEN;
459 func_exit();
463 static void rio_disable_rx_interrupts(void *ptr)
465 func_enter();
466 func_exit();
469 static void rio_enable_rx_interrupts(void *ptr)
471 /* struct rio_port *port = ptr; */
472 func_enter();
473 func_exit();
477 /* Jeez. Isn't this simple? */
478 static int rio_carrier_raised(struct tty_port *port)
480 struct Port *PortP = container_of(port, struct Port, gs.port);
481 int rv;
483 func_enter();
484 rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
486 rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
488 func_exit();
489 return rv;
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... */
495 static int rio_chars_in_buffer(void *ptr)
497 func_enter();
499 func_exit();
500 return 0;
504 /* Nothing special here... */
505 static void rio_shutdown_port(void *ptr)
507 struct Port *PortP;
509 func_enter();
511 PortP = (struct Port *) ptr;
512 PortP->gs.port.tty = NULL;
513 func_exit();
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 */
524 static void rio_hungup(void *ptr)
526 struct Port *PortP;
528 func_enter();
530 PortP = (struct Port *) ptr;
531 PortP->gs.port.tty = NULL;
533 func_exit();
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;}
541 static void rio_close(void *ptr)
543 struct Port *PortP;
545 func_enter();
547 PortP = (struct Port *) ptr;
549 riotclose(ptr);
551 if (PortP->gs.port.count) {
552 printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
553 PortP->gs.port.count = 0;
556 PortP->gs.port.tty = NULL;
557 func_exit();
562 static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
564 int rc = 0;
565 func_enter();
567 /* The "dev" argument isn't used. */
568 lock_kernel();
569 rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
570 unlock_kernel();
572 func_exit();
573 return rc;
576 extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
578 static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
580 void __user *argp = (void __user *)arg;
581 int rc;
582 struct Port *PortP;
583 int ival;
585 func_enter();
587 PortP = (struct Port *) tty->driver_data;
589 rc = 0;
590 switch (cmd) {
591 case TIOCSSOFTCAR:
592 if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
593 tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
595 break;
596 case TIOCGSERIAL:
597 rc = -EFAULT;
598 if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
599 rc = gs_getserial(&PortP->gs, argp);
600 break;
601 case TCSBRK:
602 if (PortP->State & RIO_DELETED) {
603 rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
604 rc = -EIO;
605 } else {
606 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
607 RIO_FAIL) {
608 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
609 rc = -EIO;
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;
622 if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
623 arg ? arg * 100 : 250) == RIO_FAIL) {
624 rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
625 rc = -EIO;
628 break;
629 case TIOCSSERIAL:
630 rc = -EFAULT;
631 if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
632 rc = gs_setserial(&PortP->gs, argp);
633 break;
634 default:
635 rc = -ENOIOCTLCMD;
636 break;
638 func_exit();
639 return rc;
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
659 static void rio_throttle(struct tty_struct *tty)
661 struct Port *port = (struct Port *) tty->driver_data;
663 func_enter();
664 /* If the port is using any type of input flow
665 * control then throttle the port.
668 if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
669 port->State |= RIO_THROTTLE_RX;
672 func_exit();
676 static void rio_unthrottle(struct tty_struct *tty)
678 struct Port *port = (struct Port *) tty->driver_data;
680 func_enter();
681 /* Always unthrottle even if flow control is not enabled on
682 * this port in case we disabled flow control while the port
683 * was throttled
686 port->State &= ~RIO_THROTTLE_RX;
688 func_exit();
689 return;
696 /* ********************************************************************** *
697 * Here are the initialization routines. *
698 * ********************************************************************** */
701 static struct vpd_prom *get_VPD_PROM(struct Host *hp)
703 static struct vpd_prom vpdp;
704 char *p;
705 int i;
707 func_enter();
708 rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
710 p = (char *) &vpdp;
711 for (i = 0; i < sizeof(struct vpd_prom); i++)
712 *p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
713 /* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
715 /* Terminate the identifier string.
716 *** requires one extra byte in struct vpd_prom *** */
717 *p++ = 0;
719 if (rio_debug & RIO_DEBUG_PROBE)
720 my_hd((char *) &vpdp, 0x20);
722 func_exit();
724 return &vpdp;
727 static const struct tty_operations rio_ops = {
728 .open = riotopen,
729 .close = gs_close,
730 .write = gs_write,
731 .put_char = gs_put_char,
732 .flush_chars = gs_flush_chars,
733 .write_room = gs_write_room,
734 .chars_in_buffer = gs_chars_in_buffer,
735 .flush_buffer = gs_flush_buffer,
736 .ioctl = rio_ioctl,
737 .throttle = rio_throttle,
738 .unthrottle = rio_unthrottle,
739 .set_termios = gs_set_termios,
740 .stop = gs_stop,
741 .start = gs_start,
742 .hangup = gs_hangup,
745 static int rio_init_drivers(void)
747 int error = -ENOMEM;
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;
756 func_enter();
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);
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);
780 rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
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;
788 out3:
789 tty_unregister_driver(rio_driver);
790 out2:
791 put_tty_driver(rio_driver2);
792 out1:
793 put_tty_driver(rio_driver);
794 out:
795 printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
796 return 1;
799 static const struct tty_port_operations rio_port_ops = {
800 .carrier_raised = rio_carrier_raised,
803 static int rio_init_datastructures(void)
805 int i;
806 struct Port *port;
807 func_enter();
809 /* Many drivers statically allocate the maximum number of ports
810 There is no reason not to allocate them dynamically. Is there? -- REW */
811 /* However, the RIO driver allows users to configure their first
812 RTA as the ports numbered 504-511. We therefore need to allocate
813 the whole range. :-( -- REW */
815 #define RI_SZ sizeof(struct rio_info)
816 #define HOST_SZ sizeof(struct Host)
817 #define PORT_SZ sizeof(struct Port *)
818 #define TMIO_SZ sizeof(struct termios *)
819 rio_dprintk(RIO_DEBUG_INIT, "getting : %Zd %Zd %Zd %Zd %Zd bytes\n", RI_SZ, RIO_HOSTS * HOST_SZ, RIO_PORTS * PORT_SZ, RIO_PORTS * TMIO_SZ, RIO_PORTS * TMIO_SZ);
821 if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
822 goto free0;
823 if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
824 goto free1;
825 if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
826 goto free2;
827 p->RIOConf = RIOConf;
828 rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
830 for (i = 0; i < RIO_PORTS; i++) {
831 port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
832 if (!port) {
833 goto free6;
835 rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
836 tty_port_init(&port->gs.port);
837 port->gs.port.ops = &rio_port_ops;
838 port->PortNum = i;
839 port->gs.magic = RIO_MAGIC;
840 port->gs.close_delay = HZ / 2;
841 port->gs.closing_wait = 30 * HZ;
842 port->gs.rd = &rio_real_driver;
843 spin_lock_init(&port->portSem);
848 if (rio_debug & RIO_DEBUG_INIT) {
849 my_hd(&rio_real_driver, sizeof(rio_real_driver));
853 func_exit();
854 return 0;
856 free6:for (i--; i >= 0; i--)
857 kfree(p->RIOPortp[i]);
858 /*free5:
859 free4:
860 free3:*/ kfree(p->RIOPortp);
861 free2:kfree(p->RIOHosts);
862 free1:
863 rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
864 kfree(p);
865 free0:
866 return -ENOMEM;
869 static void __exit rio_release_drivers(void)
871 func_enter();
872 tty_unregister_driver(rio_driver2);
873 tty_unregister_driver(rio_driver);
874 put_tty_driver(rio_driver2);
875 put_tty_driver(rio_driver);
876 func_exit();
880 #ifdef CONFIG_PCI
881 /* This was written for SX, but applies to RIO too...
882 (including bugs....)
884 There is another bit besides Bit 17. Turning that bit off
885 (on boards shipped with the fix in the eeprom) results in a
886 hang on the next access to the card.
889 /********************************************************
890 * Setting bit 17 in the CNTRL register of the PLX 9050 *
891 * chip forces a retry on writes while a read is pending.*
892 * This is to prevent the card locking up on Intel Xeon *
893 * multiprocessor systems with the NX chipset. -- NV *
894 ********************************************************/
896 /* Newer cards are produced with this bit set from the configuration
897 EEprom. As the bit is read/write for the CPU, we can fix it here,
898 if we detect that it isn't set correctly. -- REW */
900 static void fix_rio_pci(struct pci_dev *pdev)
902 unsigned long hwbase;
903 unsigned char __iomem *rebase;
904 unsigned int t;
906 #define CNTRL_REG_OFFSET 0x50
907 #define CNTRL_REG_GOODVALUE 0x18260000
909 hwbase = pci_resource_start(pdev, 0);
910 rebase = ioremap(hwbase, 0x80);
911 t = readl(rebase + CNTRL_REG_OFFSET);
912 if (t != CNTRL_REG_GOODVALUE) {
913 printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
914 writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
916 iounmap(rebase);
918 #endif
921 static int __init rio_init(void)
923 int found = 0;
924 int i;
925 struct Host *hp;
926 int retval;
927 struct vpd_prom *vpdp;
928 int okboard;
930 #ifdef CONFIG_PCI
931 struct pci_dev *pdev = NULL;
932 unsigned short tshort;
933 #endif
935 func_enter();
936 rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
938 if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
939 printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
940 rio_debug = -1;
943 if (misc_register(&rio_fw_device) < 0) {
944 printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
945 return -EIO;
948 retval = rio_init_datastructures();
949 if (retval < 0) {
950 misc_deregister(&rio_fw_device);
951 return retval;
953 #ifdef CONFIG_PCI
954 /* First look for the JET devices: */
955 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
956 u32 tint;
958 if (pci_enable_device(pdev))
959 continue;
961 /* Specialix has a whole bunch of cards with
962 0x2000 as the device ID. They say its because
963 the standard requires it. Stupid standard. */
964 /* It seems that reading a word doesn't work reliably on 2.0.
965 Also, reading a non-aligned dword doesn't work. So we read the
966 whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
967 ourselves */
968 pci_read_config_dword(pdev, 0x2c, &tint);
969 tshort = (tint >> 16) & 0xffff;
970 rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
971 if (tshort != 0x0100) {
972 rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
973 continue;
975 rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
977 hp = &p->RIOHosts[p->RIONumHosts];
978 hp->PaddrP = pci_resource_start(pdev, 2);
979 hp->Ivec = pdev->irq;
980 if (((1 << hp->Ivec) & rio_irqmask) == 0)
981 hp->Ivec = 0;
982 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
983 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
984 hp->Type = RIO_PCI;
985 hp->Copy = rio_copy_to_card;
986 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
987 spin_lock_init(&hp->HostLock);
988 rio_reset_interrupt(hp);
989 rio_start_card_running(hp);
991 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
992 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
993 rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
994 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
995 p->RIOHosts[p->RIONumHosts].UniqueNum =
996 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
997 ((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);
998 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1000 fix_rio_pci(pdev);
1002 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1003 pci_dev_get(pdev);
1005 p->RIOLastPCISearch = 0;
1006 p->RIONumHosts++;
1007 found++;
1008 } else {
1009 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1010 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1014 /* Then look for the older PCI card.... : */
1016 /* These older PCI cards have problems (only byte-mode access is
1017 supported), which makes them a bit awkward to support.
1018 They also have problems sharing interrupts. Be careful.
1019 (The driver now refuses to share interrupts for these
1020 cards. This should be sufficient).
1023 /* Then look for the older RIO/PCI devices: */
1024 while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1025 if (pci_enable_device(pdev))
1026 continue;
1028 #ifdef CONFIG_RIO_OLDPCI
1029 hp = &p->RIOHosts[p->RIONumHosts];
1030 hp->PaddrP = pci_resource_start(pdev, 0);
1031 hp->Ivec = pdev->irq;
1032 if (((1 << hp->Ivec) & rio_irqmask) == 0)
1033 hp->Ivec = 0;
1034 hp->Ivec |= 0x8000; /* Mark as non-sharable */
1035 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1036 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1037 hp->Type = RIO_PCI;
1038 hp->Copy = rio_copy_to_card;
1039 hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1040 spin_lock_init(&hp->HostLock);
1042 rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1043 rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1045 rio_reset_interrupt(hp);
1046 rio_start_card_running(hp);
1047 rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1048 if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1049 writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1050 p->RIOHosts[p->RIONumHosts].UniqueNum =
1051 ((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1052 ((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);
1053 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1055 p->RIOHosts[p->RIONumHosts].pdev = pdev;
1056 pci_dev_get(pdev);
1058 p->RIOLastPCISearch = 0;
1059 p->RIONumHosts++;
1060 found++;
1061 } else {
1062 iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1063 p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1065 #else
1066 printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
1067 #endif
1069 #endif /* PCI */
1071 /* Now probe for ISA cards... */
1072 for (i = 0; i < NR_RIO_ADDRS; i++) {
1073 hp = &p->RIOHosts[p->RIONumHosts];
1074 hp->PaddrP = rio_probe_addrs[i];
1075 /* There was something about the IRQs of these cards. 'Forget what.--REW */
1076 hp->Ivec = 0;
1077 hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1078 hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1079 hp->Type = RIO_AT;
1080 hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1081 * -- YES! this is now a normal copy. Only the
1082 * old PCI card uses the special PCI copy.
1083 * Moreover, the ISA card will work with the
1084 * special PCI copy anyway. -- REW */
1085 hp->Mode = 0;
1086 spin_lock_init(&hp->HostLock);
1088 vpdp = get_VPD_PROM(hp);
1089 rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1090 okboard = 0;
1091 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)) {
1092 /* Board is present... */
1093 if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
1094 /* ... and feeling fine!!!! */
1095 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1096 if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1097 rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1098 okboard++;
1099 found++;
1103 if (!okboard) {
1104 iounmap(hp->Caddr);
1105 hp->Caddr = NULL;
1111 for (i = 0; i < p->RIONumHosts; i++) {
1112 hp = &p->RIOHosts[i];
1113 if (hp->Ivec) {
1114 int mode = IRQF_SHARED;
1115 if (hp->Ivec & 0x8000) {
1116 mode = 0;
1117 hp->Ivec &= 0x7fff;
1119 rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1120 retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1121 rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1122 if (retval) {
1123 printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1124 hp->Ivec = 0;
1126 rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1127 if (hp->Ivec != 0) {
1128 rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1129 hp->Mode |= RIO_PCI_INT_ENABLE;
1130 } else
1131 hp->Mode &= ~RIO_PCI_INT_ENABLE;
1132 rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1133 rio_start_card_running(hp);
1135 /* Init the timer "always" to make sure that it can safely be
1136 deleted when we unload... */
1138 setup_timer(&hp->timer, rio_pollfunc, i);
1139 if (!hp->Ivec) {
1140 rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1141 mod_timer(&hp->timer, jiffies + rio_poll);
1145 if (found) {
1146 rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1147 rio_init_drivers();
1148 } else {
1149 /* deregister the misc device we created earlier */
1150 misc_deregister(&rio_fw_device);
1153 func_exit();
1154 return found ? 0 : -EIO;
1158 static void __exit rio_exit(void)
1160 int i;
1161 struct Host *hp;
1163 func_enter();
1165 for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1166 RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1167 if (hp->Ivec) {
1168 free_irq(hp->Ivec, hp);
1169 rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1171 /* It is safe/allowed to del_timer a non-active timer */
1172 del_timer_sync(&hp->timer);
1173 if (hp->Caddr)
1174 iounmap(hp->Caddr);
1175 if (hp->Type == RIO_PCI)
1176 pci_dev_put(hp->pdev);
1179 if (misc_deregister(&rio_fw_device) < 0) {
1180 printk(KERN_INFO "rio: couldn't deregister control-device\n");
1184 rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1186 rio_release_drivers();
1188 /* Release dynamically allocated memory */
1189 kfree(p->RIOPortp);
1190 kfree(p->RIOHosts);
1191 kfree(p);
1193 func_exit();
1196 module_init(rio_init);
1197 module_exit(rio_exit);