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