Merge to Fedora kernel-2.6.18-1.2224_FC5 patched with stable patch-2.6.18.1-vs2.0...
[linux-2.6.git] / drivers / ide / legacy / dtc2278.c
1 /*
2  *  linux/drivers/ide/legacy/dtc2278.c          Version 0.02    Feb 10, 1996
3  *
4  *  Copyright (C) 1996  Linus Torvalds & author (see below)
5  */
6
7 #undef REALLY_SLOW_IO           /* most systems can safely undef this */
8
9 #include <linux/module.h>
10 #include <linux/types.h>
11 #include <linux/kernel.h>
12 #include <linux/delay.h>
13 #include <linux/timer.h>
14 #include <linux/mm.h>
15 #include <linux/ioport.h>
16 #include <linux/blkdev.h>
17 #include <linux/hdreg.h>
18 #include <linux/ide.h>
19 #include <linux/init.h>
20
21 #include <asm/io.h>
22
23 /*
24  * Changing this #undef to #define may solve start up problems in some systems.
25  */
26 #undef ALWAYS_SET_DTC2278_PIO_MODE
27
28 /*
29  * From: andy@cercle.cts.com (Dyan Wile)
30  *
31  * Below is a patch for DTC-2278 - alike software-programmable controllers
32  * The code enables the secondary IDE controller and the PIO4 (3?) timings on
33  * the primary (EIDE). You may probably have to enable the 32-bit support to
34  * get the full speed. You better get the disk interrupts disabled ( hdparm -u0
35  * /dev/hd.. ) for the drives connected to the EIDE interface. (I get my
36  * filesystem  corrupted with -u1, but under heavy disk load only :-)
37  *
38  * This card is now forced to use the "serialize" feature,
39  * and irq-unmasking is disallowed.  If io_32bit is enabled,
40  * it must be done for BOTH drives on each interface.
41  *
42  * This code was written for the DTC2278E, but might work with any of these:
43  *
44  * DTC2278S has only a single IDE interface.
45  * DTC2278D has two IDE interfaces and is otherwise identical to the S version.
46  * DTC2278E also has serial ports and a printer port
47  * DTC2278EB: has onboard BIOS, and "works like a charm" -- Kent Bradford <kent@theory.caltech.edu>
48  *
49  * There may be a fourth controller type. The S and D versions use the
50  * Winbond chip, and I think the E version does also.
51  *
52  */
53
54 static void sub22 (char b, char c)
55 {
56         int i;
57
58         for(i = 0; i < 3; ++i) {
59                 inb(0x3f6);
60                 outb_p(b,0xb0);
61                 inb(0x3f6);
62                 outb_p(c,0xb4);
63                 inb(0x3f6);
64                 if(inb(0xb4) == c) {
65                         outb_p(7,0xb0);
66                         inb(0x3f6);
67                         return; /* success */
68                 }
69         }
70 }
71
72 static void tune_dtc2278 (ide_drive_t *drive, u8 pio)
73 {
74         unsigned long flags;
75
76         pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
77
78         if (pio >= 3) {
79                 spin_lock_irqsave(&ide_lock, flags);
80                 /*
81                  * This enables PIO mode4 (3?) on the first interface
82                  */
83                 sub22(1,0xc3);
84                 sub22(0,0xa0);
85                 spin_unlock_irqrestore(&ide_lock, flags);
86         } else {
87                 /* we don't know how to set it back again.. */
88         }
89
90         /*
91          * 32bit I/O has to be enabled for *both* drives at the same time.
92          */
93         drive->io_32bit = 1;
94         HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1;
95 }
96
97 static int __init probe_dtc2278(void)
98 {
99         unsigned long flags;
100         ide_hwif_t *hwif, *mate;
101
102         hwif = &ide_hwifs[0];
103         mate = &ide_hwifs[1];
104
105         if (hwif->chipset != ide_unknown || mate->chipset != ide_unknown)
106                 return 1;
107
108         local_irq_save(flags);
109         /*
110          * This enables the second interface
111          */
112         outb_p(4,0xb0);
113         inb(0x3f6);
114         outb_p(0x20,0xb4);
115         inb(0x3f6);
116 #ifdef ALWAYS_SET_DTC2278_PIO_MODE
117         /*
118          * This enables PIO mode4 (3?) on the first interface
119          * and may solve start-up problems for some people.
120          */
121         sub22(1,0xc3);
122         sub22(0,0xa0);
123 #endif
124         local_irq_restore(flags);
125
126         hwif->serialized = 1;
127         hwif->chipset = ide_dtc2278;
128         hwif->tuneproc = &tune_dtc2278;
129         hwif->drives[0].no_unmask = 1;
130         hwif->drives[1].no_unmask = 1;
131         hwif->mate = mate;
132
133         mate->serialized = 1;
134         mate->chipset = ide_dtc2278;
135         mate->drives[0].no_unmask = 1;
136         mate->drives[1].no_unmask = 1;
137         mate->mate = hwif;
138         mate->channel = 1;
139
140         probe_hwif_init(hwif);
141         probe_hwif_init(mate);
142
143         create_proc_ide_interfaces();
144
145         return 0;
146 }
147
148 /* Can be called directly from ide.c. */
149 int __init dtc2278_init(void)
150 {
151         if (probe_dtc2278()) {
152                 printk(KERN_ERR "dtc2278: ide interfaces already in use!\n");
153                 return -EBUSY;
154         }
155         return 0;
156 }
157
158 #ifdef MODULE
159 module_init(dtc2278_init);
160 #endif
161
162 MODULE_AUTHOR("See Local File");
163 MODULE_DESCRIPTION("support of DTC-2278 VLB IDE chipsets");
164 MODULE_LICENSE("GPL");