update atp870u driver to 0.78 from D-Link source
[linux-2.4.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/config.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13 #include <linux/delay.h>
14 #include <linux/timer.h>
15 #include <linux/mm.h>
16 #include <linux/ioport.h>
17 #include <linux/blkdev.h>
18 #include <linux/hdreg.h>
19 #include <linux/ide.h>
20 #include <linux/init.h>
21
22 #include <asm/io.h>
23
24 #ifdef CONFIG_BLK_DEV_DTC2278_MODULE
25 # define _IDE_C
26 # include "ide_modes.h"
27 # undef _IDE_C
28 #else
29 # include "ide_modes.h"
30 #endif /* CONFIG_BLK_DEV_DTC2278_MODULE */
31
32 /*
33  * Changing this #undef to #define may solve start up problems in some systems.
34  */
35 #undef ALWAYS_SET_DTC2278_PIO_MODE
36
37 /*
38  * From: andy@cercle.cts.com (Dyan Wile)
39  *
40  * Below is a patch for DTC-2278 - alike software-programmable controllers
41  * The code enables the secondary IDE controller and the PIO4 (3?) timings on
42  * the primary (EIDE). You may probably have to enable the 32-bit support to
43  * get the full speed. You better get the disk interrupts disabled ( hdparm -u0
44  * /dev/hd.. ) for the drives connected to the EIDE interface. (I get my
45  * filesystem  corrupted with -u1, but under heavy disk load only :-)
46  *
47  * This card is now forced to use the "serialize" feature,
48  * and irq-unmasking is disallowed.  If io_32bit is enabled,
49  * it must be done for BOTH drives on each interface.
50  *
51  * This code was written for the DTC2278E, but might work with any of these:
52  *
53  * DTC2278S has only a single IDE interface.
54  * DTC2278D has two IDE interfaces and is otherwise identical to the S version.
55  * DTC2278E also has serial ports and a printer port
56  * DTC2278EB: has onboard BIOS, and "works like a charm" -- Kent Bradford <kent@theory.caltech.edu>
57  *
58  * There may be a fourth controller type. The S and D versions use the
59  * Winbond chip, and I think the E version does also.
60  *
61  */
62
63 static void sub22 (char b, char c)
64 {
65         int i;
66
67         for(i = 0; i < 3; ++i) {
68                 inb(0x3f6);
69                 outb_p(b,0xb0);
70                 inb(0x3f6);
71                 outb_p(c,0xb4);
72                 inb(0x3f6);
73                 if(inb(0xb4) == c) {
74                         outb_p(7,0xb0);
75                         inb(0x3f6);
76                         return; /* success */
77                 }
78         }
79 }
80
81 static void tune_dtc2278 (ide_drive_t *drive, u8 pio)
82 {
83         unsigned long flags;
84
85         pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
86
87         if (pio >= 3) {
88                 spin_lock_irqsave(&io_request_lock, flags);
89                 /*
90                  * This enables PIO mode4 (3?) on the first interface
91                  */
92                 sub22(1,0xc3);
93                 sub22(0,0xa0);
94                 spin_unlock_irqrestore(&io_request_lock, flags);
95         } else {
96                 /* we don't know how to set it back again.. */
97         }
98
99         /*
100          * 32bit I/O has to be enabled for *both* drives at the same time.
101          */
102         drive->io_32bit = 1;
103         HWIF(drive)->drives[!drive->select.b.unit].io_32bit = 1;
104 }
105
106 void __init probe_dtc2278 (void)
107 {
108         unsigned long flags;
109
110         local_irq_save(flags);
111         /*
112          * This enables the second interface
113          */
114         outb_p(4,0xb0);
115         inb(0x3f6);
116         outb_p(0x20,0xb4);
117         inb(0x3f6);
118 #ifdef ALWAYS_SET_DTC2278_PIO_MODE
119         /*
120          * This enables PIO mode4 (3?) on the first interface
121          * and may solve start-up problems for some people.
122          */
123         sub22(1,0xc3);
124         sub22(0,0xa0);
125 #endif
126         local_irq_restore(flags);
127
128         ide_hwifs[0].serialized = 1;
129         ide_hwifs[1].serialized = 1;
130         ide_hwifs[0].chipset = ide_dtc2278;
131         ide_hwifs[1].chipset = ide_dtc2278;
132         ide_hwifs[0].tuneproc = &tune_dtc2278;
133         ide_hwifs[0].drives[0].no_unmask = 1;
134         ide_hwifs[0].drives[1].no_unmask = 1;
135         ide_hwifs[1].drives[0].no_unmask = 1;
136         ide_hwifs[1].drives[1].no_unmask = 1;
137         ide_hwifs[0].mate = &ide_hwifs[1];
138         ide_hwifs[1].mate = &ide_hwifs[0];
139         ide_hwifs[1].channel = 1;
140
141 #ifndef HWIF_PROBE_CLASSIC_METHOD
142         probe_hwif_init(&ide_hwifs[0]);
143         probe_hwif_init(&ide_hwifs[1]);
144 #endif /* HWIF_PROBE_CLASSIC_METHOD */
145
146 }
147
148 void __init dtc2278_release (void)
149 {
150         if (ide_hwifs[0].chipset != ide_dtc2278 &&
151             ide_hwifs[1].chipset != ide_dtc2278)
152                 return;
153
154         ide_hwifs[0].serialized = 0;
155         ide_hwifs[1].serialized = 0;
156         ide_hwifs[0].chipset = ide_unknown;
157         ide_hwifs[1].chipset = ide_unknown;
158         ide_hwifs[0].tuneproc = NULL;
159         ide_hwifs[0].drives[0].no_unmask = 0;
160         ide_hwifs[0].drives[1].no_unmask = 0;
161         ide_hwifs[1].drives[0].no_unmask = 0;
162         ide_hwifs[1].drives[1].no_unmask = 0;
163         ide_hwifs[0].mate = NULL;
164         ide_hwifs[1].mate = NULL;
165 }
166
167 #ifndef MODULE
168 /*
169  * init_dtc2278:
170  *
171  * called by ide.c when parsing command line
172  */
173
174 void __init init_dtc2278 (void)
175 {
176         probe_dtc2278();
177 }
178
179 #else
180
181 MODULE_AUTHOR("See Local File");
182 MODULE_DESCRIPTION("support of DTC-2278 VLB IDE chipsets");
183 MODULE_LICENSE("GPL");
184
185 int __init dtc2278_mod_init(void)
186 {
187         probe_dtc2278();
188         if (ide_hwifs[0].chipset != ide_dtc2278 &&
189             ide_hwifs[1].chipset != ide_dtc2278) {
190                 dtc2278_release();
191                 return -ENODEV;
192         }
193         return 0;
194 }
195 module_init(dtc2278_mod_init);
196
197 void __init dtc2278_mod_exit(void)
198 {
199         dtc2278_release();
200 }
201 module_exit(dtc2278_mod_exit);
202 #endif
203