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,
30
#include <linux/module.h>
31
#include <linux/kdev_t.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>
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/mutex.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"
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
99
#ifndef PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8
100
#define PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8 0x2000
103
#ifndef RIO_WINDOW_LEN
104
#define RIO_WINDOW_LEN 0x10000
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 DEFINE_MUTEX(rio_fw_mutex);
128
/* locator */ "RIO Config here",
129
/* startuptime */ HZ * 2,
130
/* how long to wait for card to run */
132
/* TRUE -> always use line disc. */
133
/* intrpolltime */ 1,
134
/* The frequency of OUR polls */
135
/* breakinterval */ 25,
136
/* x10 mS XXX: units seem to be 1ms not 10! -- REW */
139
/* RtaLoadBase */ 0x7000,
140
/* HostLoadBase */ 0x7C00,
142
/* number of Xprint hits per second */
144
/* Xprint characters per second */
146
/* start Xprint for a wyse 60 */
148
/* end Xprint for a wyse 60 */
150
/* highest Xprint speed */
152
/* slowest Xprint speed */
154
/* non-zero for mega fast boots */
155
/* First Addr */ 0x0A0000,
156
/* First address to look at */
157
/* Last Addr */ 0xFF0000,
158
/* Last address looked at */
159
/* BufferSize */ 1024,
160
/* Bytes per port of buffering */
162
/* how much data left before wakeup */
164
/* how wide is the console? */
166
/* how long a close command may take */
172
/* Function prototypes */
174
static void rio_disable_tx_interrupts(void *ptr);
175
static void rio_enable_tx_interrupts(void *ptr);
176
static void rio_disable_rx_interrupts(void *ptr);
177
static void rio_enable_rx_interrupts(void *ptr);
178
static int rio_carrier_raised(struct tty_port *port);
179
static void rio_shutdown_port(void *ptr);
180
static int rio_set_real_termios(void *ptr);
181
static void rio_hungup(void *ptr);
182
static void rio_close(void *ptr);
183
static int rio_chars_in_buffer(void *ptr);
184
static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg);
185
static int rio_init_drivers(void);
187
static void my_hd(void *addr, int len);
189
static struct tty_driver *rio_driver, *rio_driver2;
191
/* The name "p" is a bit non-descript. But that's what the rio-lynxos
192
sources use all over the place. */
198
/* You can have the driver poll your card.
199
- Set rio_poll to 1 to poll every timer tick (10ms on Intel).
200
This is used when the card cannot use an interrupt for some reason.
202
static int rio_poll = 1;
205
/* These are the only open spaces in my computer. Yours may have more
207
static int rio_probe_addrs[] = { 0xc0000, 0xd0000, 0xe0000 };
209
#define NR_RIO_ADDRS ARRAY_SIZE(rio_probe_addrs)
212
/* Set the mask to all-ones. This alas, only supports 32 interrupts.
213
Some architectures may need more. -- Changed to LONG to
214
support up to 64 bits on 64bit architectures. -- REW 20/06/99 */
215
static long rio_irqmask = -1;
217
MODULE_AUTHOR("Rogier Wolff <R.E.Wolff@bitwizard.nl>, Patrick van de Lageweg <patrick@bitwizard.nl>");
218
MODULE_DESCRIPTION("RIO driver");
219
MODULE_LICENSE("GPL");
220
module_param(rio_poll, int, 0);
221
module_param(rio_debug, int, 0644);
222
module_param(rio_irqmask, long, 0);
224
static struct real_driver rio_real_driver = {
225
rio_disable_tx_interrupts,
226
rio_enable_tx_interrupts,
227
rio_disable_rx_interrupts,
228
rio_enable_rx_interrupts,
230
rio_set_real_termios,
238
* Firmware loader driver specific routines
242
static const struct file_operations rio_fw_fops = {
243
.owner = THIS_MODULE,
244
.unlocked_ioctl = rio_fw_ioctl,
245
.llseek = noop_llseek,
248
static struct miscdevice rio_fw_device = {
249
RIOCTL_MISC_MINOR, "rioctl", &rio_fw_fops
256
#ifdef RIO_PARANOIA_CHECK
258
/* This doesn't work. Who's paranoid around here? Not me! */
260
static inline int rio_paranoia_check(struct rio_port const *port, char *name, const char *routine)
263
static const char *badmagic = KERN_ERR "rio: Warning: bad rio port magic number for device %s in %s\n";
264
static const char *badinfo = KERN_ERR "rio: Warning: null rio port for device %s in %s\n";
267
printk(badinfo, name, routine);
270
if (port->magic != RIO_MAGIC) {
271
printk(badmagic, name, routine);
278
#define rio_paranoia_check(a,b,c) 0
283
static void my_hd(void *ad, int len)
286
unsigned char *addr = ad;
288
for (i = 0; i < len; i += 16) {
289
rio_dprintk(RIO_DEBUG_PARAM, "%08lx ", (unsigned long) addr + i);
290
for (j = 0; j < 16; j++) {
291
rio_dprintk(RIO_DEBUG_PARAM, "%02x %s", addr[j + i], (j == 7) ? " " : "");
293
for (j = 0; j < 16; j++) {
295
rio_dprintk(RIO_DEBUG_PARAM, "%c", (ch < 0x20) ? '.' : ((ch > 0x7f) ? '.' : ch));
297
rio_dprintk(RIO_DEBUG_PARAM, "\n");
301
#define my_hd(ad,len) do{/* nothing*/ } while (0)
305
/* Delay a number of jiffies, allowing a signal to interrupt */
306
int RIODelay(struct Port *PortP, int njiffies)
310
rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies\n", njiffies);
311
msleep_interruptible(jiffies_to_msecs(njiffies));
314
if (signal_pending(current))
321
/* Delay a number of jiffies, disallowing a signal to interrupt */
322
int RIODelay_ni(struct Port *PortP, int njiffies)
326
rio_dprintk(RIO_DEBUG_DELAY, "delaying %d jiffies (ni)\n", njiffies);
327
msleep(jiffies_to_msecs(njiffies));
332
void rio_copy_to_card(void *from, void __iomem *to, int len)
334
rio_copy_toio(to, from, len);
337
int rio_minor(struct tty_struct *tty)
339
return tty->index + ((tty->driver == rio_driver) ? 0 : 256);
342
static int rio_set_real_termios(void *ptr)
344
return RIOParam((struct Port *) ptr, RIOC_CONFIG, 1, 1);
348
static void rio_reset_interrupt(struct Host *HostP)
352
switch (HostP->Type) {
356
writeb(0xFF, &HostP->ResetInt);
363
static irqreturn_t rio_interrupt(int irq, void *ptr)
368
HostP = ptr; /* &p->RIOHosts[(long)ptr]; */
369
rio_dprintk(RIO_DEBUG_IFLOW, "rio: enter rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
371
/* AAargh! The order in which to do these things is essential and
374
- hardware twiddling goes before "recursive". Otherwise when we
375
poll the card, and a recursive interrupt happens, we won't
376
ack the card, so it might keep on interrupting us. (especially
377
level sensitive interrupt systems like PCI).
379
- Rate limit goes before hardware twiddling. Otherwise we won't
380
catch a card that has gone bonkers.
382
- The "initialized" test goes after the hardware twiddling. Otherwise
383
the card will stick us in the interrupt routine again.
385
- The initialized test goes before recursive.
388
rio_dprintk(RIO_DEBUG_IFLOW, "rio: We've have noticed the interrupt\n");
389
if (HostP->Ivec == irq) {
390
/* Tell the card we've noticed the interrupt. */
391
rio_reset_interrupt(HostP);
394
if ((HostP->Flags & RUN_STATE) != RC_RUNNING)
397
if (test_and_set_bit(RIO_BOARD_INTR_LOCK, &HostP->locks)) {
398
printk(KERN_ERR "Recursive interrupt! (host %p/irq%d)\n", ptr, HostP->Ivec);
402
RIOServiceHost(p, HostP);
404
rio_dprintk(RIO_DEBUG_IFLOW, "riointr() doing host %p type %d\n", ptr, HostP->Type);
406
clear_bit(RIO_BOARD_INTR_LOCK, &HostP->locks);
407
rio_dprintk(RIO_DEBUG_IFLOW, "rio: exit rio_interrupt (%d/%d)\n", irq, HostP->Ivec);
413
static void rio_pollfunc(unsigned long data)
417
rio_interrupt(0, &p->RIOHosts[data]);
418
mod_timer(&p->RIOHosts[data].timer, jiffies + rio_poll);
424
/* ********************************************************************** *
425
* Here are the routines that actually *
426
* interface with the generic_serial driver *
427
* ********************************************************************** */
429
/* Ehhm. I don't know how to fiddle with interrupts on the Specialix
430
cards. .... Hmm. Ok I figured it out. You don't. -- REW */
432
static void rio_disable_tx_interrupts(void *ptr)
436
/* port->gs.port.flags &= ~GS_TX_INTEN; */
442
static void rio_enable_tx_interrupts(void *ptr)
444
struct Port *PortP = ptr;
449
/* hn = PortP->HostP - p->RIOHosts;
451
rio_dprintk (RIO_DEBUG_TTY, "Pushing host %d\n", hn);
452
rio_interrupt (-1,(void *) hn, NULL); */
454
RIOTxEnable((char *) PortP);
457
* In general we cannot count on "tx empty" interrupts, although
458
* the interrupt routine seems to be able to tell the difference.
460
PortP->gs.port.flags &= ~GS_TX_INTEN;
466
static void rio_disable_rx_interrupts(void *ptr)
472
static void rio_enable_rx_interrupts(void *ptr)
474
/* struct rio_port *port = ptr; */
480
/* Jeez. Isn't this simple? */
481
static int rio_carrier_raised(struct tty_port *port)
483
struct Port *PortP = container_of(port, struct Port, gs.port);
487
rv = (PortP->ModemState & RIOC_MSVR1_CD) != 0;
489
rio_dprintk(RIO_DEBUG_INIT, "Getting CD status: %d\n", rv);
496
/* Jeez. Isn't this simple? Actually, we can sync with the actual port
497
by just pushing stuff into the queue going to the port... */
498
static int rio_chars_in_buffer(void *ptr)
507
/* Nothing special here... */
508
static void rio_shutdown_port(void *ptr)
514
PortP = (struct Port *) ptr;
515
PortP->gs.port.tty = NULL;
520
/* I haven't the foggiest why the decrement use count has to happen
521
here. The whole linux serial drivers stuff needs to be redesigned.
522
My guess is that this is a hack to minimize the impact of a bug
523
elsewhere. Thinking about it some more. (try it sometime) Try
524
running minicom on a serial port that is driven by a modularized
525
driver. Have the modem hangup. Then remove the driver module. Then
526
exit minicom. I expect an "oops". -- REW */
527
static void rio_hungup(void *ptr)
533
PortP = (struct Port *) ptr;
534
PortP->gs.port.tty = NULL;
540
/* The standard serial_close would become shorter if you'd wrap it like
542
rs_close (...){save_flags;cli;real_close();dec_use_count;restore_flags;}
544
static void rio_close(void *ptr)
550
PortP = (struct Port *) ptr;
554
if (PortP->gs.port.count) {
555
printk(KERN_ERR "WARNING port count:%d\n", PortP->gs.port.count);
556
PortP->gs.port.count = 0;
559
PortP->gs.port.tty = NULL;
565
static long rio_fw_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
570
/* The "dev" argument isn't used. */
571
mutex_lock(&rio_fw_mutex);
572
rc = riocontrol(p, 0, cmd, arg, capable(CAP_SYS_ADMIN));
573
mutex_unlock(&rio_fw_mutex);
579
extern int RIOShortCommand(struct rio_info *p, struct Port *PortP, int command, int len, int arg);
581
static int rio_ioctl(struct tty_struct *tty, struct file *filp, unsigned int cmd, unsigned long arg)
583
void __user *argp = (void __user *)arg;
590
PortP = (struct Port *) tty->driver_data;
595
if ((rc = get_user(ival, (unsigned __user *) argp)) == 0) {
596
tty->termios->c_cflag = (tty->termios->c_cflag & ~CLOCAL) | (ival ? CLOCAL : 0);
601
if (access_ok(VERIFY_WRITE, argp, sizeof(struct serial_struct)))
602
rc = gs_getserial(&PortP->gs, argp);
605
if (PortP->State & RIO_DELETED) {
606
rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
609
if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2, 250) ==
611
rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
617
if (PortP->State & RIO_DELETED) {
618
rio_dprintk(RIO_DEBUG_TTY, "BREAK on deleted RTA\n");
622
l = arg ? arg * 100 : 250;
625
if (RIOShortCommand(p, PortP, RIOC_SBREAK, 2,
626
arg ? arg * 100 : 250) == RIO_FAIL) {
627
rio_dprintk(RIO_DEBUG_INTR, "SBREAK RIOShortCommand failed\n");
634
if (access_ok(VERIFY_READ, argp, sizeof(struct serial_struct)))
635
rc = gs_setserial(&PortP->gs, argp);
646
/* The throttle/unthrottle scheme for the Specialix card is different
647
* from other drivers and deserves some explanation.
648
* The Specialix hardware takes care of XON/XOFF
649
* and CTS/RTS flow control itself. This means that all we have to
650
* do when signalled by the upper tty layer to throttle/unthrottle is
651
* to make a note of it here. When we come to read characters from the
652
* rx buffers on the card (rio_receive_chars()) we look to see if the
653
* upper layer can accept more (as noted here in rio_rx_throt[]).
654
* If it can't we simply don't remove chars from the cards buffer.
655
* When the tty layer can accept chars, we again note that here and when
656
* rio_receive_chars() is called it will remove them from the cards buffer.
657
* The card will notice that a ports buffer has drained below some low
658
* water mark and will unflow control the line itself, using whatever
659
* flow control scheme is in use for that port. -- Simon Allen
662
static void rio_throttle(struct tty_struct *tty)
664
struct Port *port = (struct Port *) tty->driver_data;
667
/* If the port is using any type of input flow
668
* control then throttle the port.
671
if ((tty->termios->c_cflag & CRTSCTS) || (I_IXOFF(tty))) {
672
port->State |= RIO_THROTTLE_RX;
679
static void rio_unthrottle(struct tty_struct *tty)
681
struct Port *port = (struct Port *) tty->driver_data;
684
/* Always unthrottle even if flow control is not enabled on
685
* this port in case we disabled flow control while the port
689
port->State &= ~RIO_THROTTLE_RX;
699
/* ********************************************************************** *
700
* Here are the initialization routines. *
701
* ********************************************************************** */
704
static struct vpd_prom *get_VPD_PROM(struct Host *hp)
706
static struct vpd_prom vpdp;
711
rio_dprintk(RIO_DEBUG_PROBE, "Going to verify vpd prom at %p.\n", hp->Caddr + RIO_VPD_ROM);
714
for (i = 0; i < sizeof(struct vpd_prom); i++)
715
*p++ = readb(hp->Caddr + RIO_VPD_ROM + i * 2);
716
/* read_rio_byte (hp, RIO_VPD_ROM + i*2); */
718
/* Terminate the identifier string.
719
*** requires one extra byte in struct vpd_prom *** */
722
if (rio_debug & RIO_DEBUG_PROBE)
723
my_hd((char *) &vpdp, 0x20);
730
static const struct tty_operations rio_ops = {
734
.put_char = gs_put_char,
735
.flush_chars = gs_flush_chars,
736
.write_room = gs_write_room,
737
.chars_in_buffer = gs_chars_in_buffer,
738
.flush_buffer = gs_flush_buffer,
740
.throttle = rio_throttle,
741
.unthrottle = rio_unthrottle,
742
.set_termios = gs_set_termios,
748
static int rio_init_drivers(void)
752
rio_driver = alloc_tty_driver(256);
755
rio_driver2 = alloc_tty_driver(256);
761
rio_driver->owner = THIS_MODULE;
762
rio_driver->driver_name = "specialix_rio";
763
rio_driver->name = "ttySR";
764
rio_driver->major = RIO_NORMAL_MAJOR0;
765
rio_driver->type = TTY_DRIVER_TYPE_SERIAL;
766
rio_driver->subtype = SERIAL_TYPE_NORMAL;
767
rio_driver->init_termios = tty_std_termios;
768
rio_driver->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
769
rio_driver->flags = TTY_DRIVER_REAL_RAW;
770
tty_set_operations(rio_driver, &rio_ops);
772
rio_driver2->owner = THIS_MODULE;
773
rio_driver2->driver_name = "specialix_rio";
774
rio_driver2->name = "ttySR";
775
rio_driver2->major = RIO_NORMAL_MAJOR1;
776
rio_driver2->type = TTY_DRIVER_TYPE_SERIAL;
777
rio_driver2->subtype = SERIAL_TYPE_NORMAL;
778
rio_driver2->init_termios = tty_std_termios;
779
rio_driver2->init_termios.c_cflag = B9600 | CS8 | CREAD | HUPCL | CLOCAL;
780
rio_driver2->flags = TTY_DRIVER_REAL_RAW;
781
tty_set_operations(rio_driver2, &rio_ops);
783
rio_dprintk(RIO_DEBUG_INIT, "set_termios = %p\n", gs_set_termios);
785
if ((error = tty_register_driver(rio_driver)))
787
if ((error = tty_register_driver(rio_driver2)))
792
tty_unregister_driver(rio_driver);
794
put_tty_driver(rio_driver2);
796
put_tty_driver(rio_driver);
798
printk(KERN_ERR "rio: Couldn't register a rio driver, error = %d\n", error);
802
static const struct tty_port_operations rio_port_ops = {
803
.carrier_raised = rio_carrier_raised,
806
static int rio_init_datastructures(void)
812
/* Many drivers statically allocate the maximum number of ports
813
There is no reason not to allocate them dynamically. Is there? -- REW */
814
/* However, the RIO driver allows users to configure their first
815
RTA as the ports numbered 504-511. We therefore need to allocate
816
the whole range. :-( -- REW */
818
#define RI_SZ sizeof(struct rio_info)
819
#define HOST_SZ sizeof(struct Host)
820
#define PORT_SZ sizeof(struct Port *)
821
#define TMIO_SZ sizeof(struct termios *)
822
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);
824
if (!(p = kzalloc(RI_SZ, GFP_KERNEL)))
826
if (!(p->RIOHosts = kzalloc(RIO_HOSTS * HOST_SZ, GFP_KERNEL)))
828
if (!(p->RIOPortp = kzalloc(RIO_PORTS * PORT_SZ, GFP_KERNEL)))
830
p->RIOConf = RIOConf;
831
rio_dprintk(RIO_DEBUG_INIT, "Got : %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
834
for (i = 0; i < RIO_PORTS; i++) {
835
port = p->RIOPortp[i] = kzalloc(sizeof(struct Port), GFP_KERNEL);
839
rio_dprintk(RIO_DEBUG_INIT, "initing port %d (%d)\n", i, port->Mapped);
840
tty_port_init(&port->gs.port);
841
port->gs.port.ops = &rio_port_ops;
843
port->gs.magic = RIO_MAGIC;
844
port->gs.close_delay = HZ / 2;
845
port->gs.closing_wait = 30 * HZ;
846
port->gs.rd = &rio_real_driver;
847
spin_lock_init(&port->portSem);
850
/* We could postpone initializing them to when they are configured. */
855
if (rio_debug & RIO_DEBUG_INIT) {
856
my_hd(&rio_real_driver, sizeof(rio_real_driver));
863
free6:for (i--; i >= 0; i--)
864
kfree(p->RIOPortp[i]);
867
free3:*/ kfree(p->RIOPortp);
868
free2:kfree(p->RIOHosts);
870
rio_dprintk(RIO_DEBUG_INIT, "Not enough memory! %p %p %p\n", p, p->RIOHosts, p->RIOPortp);
876
static void __exit rio_release_drivers(void)
879
tty_unregister_driver(rio_driver2);
880
tty_unregister_driver(rio_driver);
881
put_tty_driver(rio_driver2);
882
put_tty_driver(rio_driver);
888
/* This was written for SX, but applies to RIO too...
891
There is another bit besides Bit 17. Turning that bit off
892
(on boards shipped with the fix in the eeprom) results in a
893
hang on the next access to the card.
896
/********************************************************
897
* Setting bit 17 in the CNTRL register of the PLX 9050 *
898
* chip forces a retry on writes while a read is pending.*
899
* This is to prevent the card locking up on Intel Xeon *
900
* multiprocessor systems with the NX chipset. -- NV *
901
********************************************************/
903
/* Newer cards are produced with this bit set from the configuration
904
EEprom. As the bit is read/write for the CPU, we can fix it here,
905
if we detect that it isn't set correctly. -- REW */
907
static void fix_rio_pci(struct pci_dev *pdev)
909
unsigned long hwbase;
910
unsigned char __iomem *rebase;
913
#define CNTRL_REG_OFFSET 0x50
914
#define CNTRL_REG_GOODVALUE 0x18260000
916
hwbase = pci_resource_start(pdev, 0);
917
rebase = ioremap(hwbase, 0x80);
918
t = readl(rebase + CNTRL_REG_OFFSET);
919
if (t != CNTRL_REG_GOODVALUE) {
920
printk(KERN_DEBUG "rio: performing cntrl reg fix: %08x -> %08x\n", t, CNTRL_REG_GOODVALUE);
921
writel(CNTRL_REG_GOODVALUE, rebase + CNTRL_REG_OFFSET);
928
static int __init rio_init(void)
934
struct vpd_prom *vpdp;
938
struct pci_dev *pdev = NULL;
939
unsigned short tshort;
943
rio_dprintk(RIO_DEBUG_INIT, "Initing rio module... (rio_debug=%d)\n", rio_debug);
945
if (abs((long) (&rio_debug) - rio_debug) < 0x10000) {
946
printk(KERN_WARNING "rio: rio_debug is an address, instead of a value. " "Assuming -1. Was %x/%p.\n", rio_debug, &rio_debug);
950
if (misc_register(&rio_fw_device) < 0) {
951
printk(KERN_ERR "RIO: Unable to register firmware loader driver.\n");
955
retval = rio_init_datastructures();
957
misc_deregister(&rio_fw_device);
961
/* First look for the JET devices: */
962
while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8, pdev))) {
965
if (pci_enable_device(pdev))
968
/* Specialix has a whole bunch of cards with
969
0x2000 as the device ID. They say its because
970
the standard requires it. Stupid standard. */
971
/* It seems that reading a word doesn't work reliably on 2.0.
972
Also, reading a non-aligned dword doesn't work. So we read the
973
whole dword at 0x2c and extract the word at 0x2e (SUBSYSTEM_ID)
975
pci_read_config_dword(pdev, 0x2c, &tint);
976
tshort = (tint >> 16) & 0xffff;
977
rio_dprintk(RIO_DEBUG_PROBE, "Got a specialix card: %x.\n", tint);
978
if (tshort != 0x0100) {
979
rio_dprintk(RIO_DEBUG_PROBE, "But it's not a RIO card (%d)...\n", tshort);
982
rio_dprintk(RIO_DEBUG_PROBE, "cp1\n");
984
hp = &p->RIOHosts[p->RIONumHosts];
985
hp->PaddrP = pci_resource_start(pdev, 2);
986
hp->Ivec = pdev->irq;
987
if (((1 << hp->Ivec) & rio_irqmask) == 0)
989
hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
990
hp->CardP = (struct DpRam __iomem *) hp->Caddr;
992
hp->Copy = rio_copy_to_card;
993
hp->Mode = RIO_PCI_BOOT_FROM_RAM;
994
spin_lock_init(&hp->HostLock);
995
rio_reset_interrupt(hp);
996
rio_start_card_running(hp);
998
rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
999
if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1000
rio_dprintk(RIO_DEBUG_INIT, "Done RIOBoardTest\n");
1001
writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1002
p->RIOHosts[p->RIONumHosts].UniqueNum =
1003
((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1004
((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);
1005
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1009
p->RIOHosts[p->RIONumHosts].pdev = pdev;
1012
p->RIOLastPCISearch = 0;
1016
iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1017
p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1021
/* Then look for the older PCI card.... : */
1023
/* These older PCI cards have problems (only byte-mode access is
1024
supported), which makes them a bit awkward to support.
1025
They also have problems sharing interrupts. Be careful.
1026
(The driver now refuses to share interrupts for these
1027
cards. This should be sufficient).
1030
/* Then look for the older RIO/PCI devices: */
1031
while ((pdev = pci_get_device(PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_RIO, pdev))) {
1032
if (pci_enable_device(pdev))
1035
#ifdef CONFIG_RIO_OLDPCI
1036
hp = &p->RIOHosts[p->RIONumHosts];
1037
hp->PaddrP = pci_resource_start(pdev, 0);
1038
hp->Ivec = pdev->irq;
1039
if (((1 << hp->Ivec) & rio_irqmask) == 0)
1041
hp->Ivec |= 0x8000; /* Mark as non-sharable */
1042
hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1043
hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1045
hp->Copy = rio_copy_to_card;
1046
hp->Mode = RIO_PCI_BOOT_FROM_RAM;
1047
spin_lock_init(&hp->HostLock);
1049
rio_dprintk(RIO_DEBUG_PROBE, "Ivec: %x\n", hp->Ivec);
1050
rio_dprintk(RIO_DEBUG_PROBE, "Mode: %x\n", hp->Mode);
1052
rio_reset_interrupt(hp);
1053
rio_start_card_running(hp);
1054
rio_dprintk(RIO_DEBUG_PROBE, "Going to test it (%p/%p).\n", (void *) p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr);
1055
if (RIOBoardTest(p->RIOHosts[p->RIONumHosts].PaddrP, p->RIOHosts[p->RIONumHosts].Caddr, RIO_PCI, 0) == 0) {
1056
writeb(0xFF, &p->RIOHosts[p->RIONumHosts].ResetInt);
1057
p->RIOHosts[p->RIONumHosts].UniqueNum =
1058
((readb(&p->RIOHosts[p->RIONumHosts].Unique[0]) & 0xFF) << 0) |
1059
((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);
1060
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1062
p->RIOHosts[p->RIONumHosts].pdev = pdev;
1065
p->RIOLastPCISearch = 0;
1069
iounmap(p->RIOHosts[p->RIONumHosts].Caddr);
1070
p->RIOHosts[p->RIONumHosts].Caddr = NULL;
1073
printk(KERN_ERR "Found an older RIO PCI card, but the driver is not " "compiled to support it.\n");
1078
/* Now probe for ISA cards... */
1079
for (i = 0; i < NR_RIO_ADDRS; i++) {
1080
hp = &p->RIOHosts[p->RIONumHosts];
1081
hp->PaddrP = rio_probe_addrs[i];
1082
/* There was something about the IRQs of these cards. 'Forget what.--REW */
1084
hp->Caddr = ioremap(p->RIOHosts[p->RIONumHosts].PaddrP, RIO_WINDOW_LEN);
1085
hp->CardP = (struct DpRam __iomem *) hp->Caddr;
1087
hp->Copy = rio_copy_to_card; /* AT card PCI???? - PVDL
1088
* -- YES! this is now a normal copy. Only the
1089
* old PCI card uses the special PCI copy.
1090
* Moreover, the ISA card will work with the
1091
* special PCI copy anyway. -- REW */
1093
spin_lock_init(&hp->HostLock);
1095
vpdp = get_VPD_PROM(hp);
1096
rio_dprintk(RIO_DEBUG_PROBE, "Got VPD ROM\n");
1098
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)) {
1099
/* Board is present... */
1100
if (RIOBoardTest(hp->PaddrP, hp->Caddr, RIO_AT, 0) == 0) {
1101
/* ... and feeling fine!!!! */
1102
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, uniqid = %x.\n", p->RIOHosts[p->RIONumHosts].UniqueNum);
1103
if (RIOAssignAT(p, hp->PaddrP, hp->Caddr, 0)) {
1104
rio_dprintk(RIO_DEBUG_PROBE, "Hmm Tested ok, host%d uniqid = %x.\n", p->RIONumHosts, p->RIOHosts[p->RIONumHosts - 1].UniqueNum);
1118
for (i = 0; i < p->RIONumHosts; i++) {
1119
hp = &p->RIOHosts[i];
1121
int mode = IRQF_SHARED;
1122
if (hp->Ivec & 0x8000) {
1126
rio_dprintk(RIO_DEBUG_INIT, "Requesting interrupt hp: %p rio_interrupt: %d Mode: %x\n", hp, hp->Ivec, hp->Mode);
1127
retval = request_irq(hp->Ivec, rio_interrupt, mode, "rio", hp);
1128
rio_dprintk(RIO_DEBUG_INIT, "Return value from request_irq: %d\n", retval);
1130
printk(KERN_ERR "rio: Cannot allocate irq %d.\n", hp->Ivec);
1133
rio_dprintk(RIO_DEBUG_INIT, "Got irq %d.\n", hp->Ivec);
1134
if (hp->Ivec != 0) {
1135
rio_dprintk(RIO_DEBUG_INIT, "Enabling interrupts on rio card.\n");
1136
hp->Mode |= RIO_PCI_INT_ENABLE;
1138
hp->Mode &= ~RIO_PCI_INT_ENABLE;
1139
rio_dprintk(RIO_DEBUG_INIT, "New Mode: %x\n", hp->Mode);
1140
rio_start_card_running(hp);
1142
/* Init the timer "always" to make sure that it can safely be
1143
deleted when we unload... */
1145
setup_timer(&hp->timer, rio_pollfunc, i);
1147
rio_dprintk(RIO_DEBUG_INIT, "Starting polling at %dj intervals.\n", rio_poll);
1148
mod_timer(&hp->timer, jiffies + rio_poll);
1153
rio_dprintk(RIO_DEBUG_INIT, "rio: total of %d boards detected.\n", found);
1156
/* deregister the misc device we created earlier */
1157
misc_deregister(&rio_fw_device);
1161
return found ? 0 : -EIO;
1165
static void __exit rio_exit(void)
1172
for (i = 0, hp = p->RIOHosts; i < p->RIONumHosts; i++, hp++) {
1173
RIOHostReset(hp->Type, hp->CardP, hp->Slot);
1175
free_irq(hp->Ivec, hp);
1176
rio_dprintk(RIO_DEBUG_INIT, "freed irq %d.\n", hp->Ivec);
1178
/* It is safe/allowed to del_timer a non-active timer */
1179
del_timer_sync(&hp->timer);
1182
if (hp->Type == RIO_PCI)
1183
pci_dev_put(hp->pdev);
1186
if (misc_deregister(&rio_fw_device) < 0) {
1187
printk(KERN_INFO "rio: couldn't deregister control-device\n");
1191
rio_dprintk(RIO_DEBUG_CLEANUP, "Cleaning up drivers\n");
1193
rio_release_drivers();
1195
/* Release dynamically allocated memory */
1203
module_init(rio_init);
1204
module_exit(rio_exit);