2 * linux/drivers/ide/legacy/ht6560b.c Version 0.07 Feb 1, 2000
4 * Copyright (C) 1995-2000 Linus Torvalds & author (see below)
9 * Version 0.01 Initial version hacked out of ide.c
11 * Version 0.02 Added support for PIO modes, auto-tune
13 * Version 0.03 Some cleanups
15 * Version 0.05 PIO mode cycle timings auto-tune using bus-speed
17 * Version 0.06 Prefetch mode now defaults no OFF. To set
18 * prefetch mode OFF/ON use "hdparm -p8/-p9".
19 * Unmask irq is disabled when prefetch mode
22 * Version 0.07 Trying to fix CD-ROM detection problem.
23 * "Prefetch" mode bit OFF for ide disks and
24 * ON for anything else.
27 * HT-6560B EIDE-controller support
28 * To activate controller support use kernel parameter "ide0=ht6560b".
29 * Use hdparm utility to enable PIO mode support.
31 * Author: Mikko Ala-Fossi <maf@iki.fi>
32 * Jan Evert van Grootheest <janevert@iae.nl>
34 * Try: http://www.maf.iki.fi/~maf/ht6560b/
37 #define HT6560B_VERSION "v0.07"
39 #undef REALLY_SLOW_IO /* most systems can safely undef this */
41 #include <linux/module.h>
42 #include <linux/types.h>
43 #include <linux/kernel.h>
44 #include <linux/delay.h>
45 #include <linux/timer.h>
47 #include <linux/ioport.h>
48 #include <linux/blkdev.h>
49 #include <linux/hdreg.h>
50 #include <linux/ide.h>
51 #include <linux/init.h>
55 /* #define DEBUG */ /* remove comments for DEBUG messages */
58 * The special i/o-port that HT-6560B uses to configuration:
59 * bit0 (0x01): "1" selects secondary interface
60 * bit2 (0x04): "1" enables FIFO function
61 * bit5 (0x20): "1" enables prefetched data read function (???)
63 * The special i/o-port that HT-6560A uses to configuration:
64 * bit0 (0x01): "1" selects secondary interface
65 * bit1 (0x02): "1" enables prefetched data read function
66 * bit2 (0x04): "0" enables multi-master system (?)
67 * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?)
69 #define HT_CONFIG_PORT 0x3e6
70 #define HT_CONFIG(drivea) (u8)(((drivea)->drive_data & 0xff00) >> 8)
72 * FIFO + PREFETCH (both a/b-model)
74 #define HT_CONFIG_DEFAULT 0x1c /* no prefetch */
75 /* #define HT_CONFIG_DEFAULT 0x3c */ /* with prefetch */
76 #define HT_SECONDARY_IF 0x01
77 #define HT_PREFETCH_MODE 0x20
80 * ht6560b Timing values:
82 * I reviewed some assembler source listings of htide drivers and found
83 * out how they setup those cycle time interfacing values, as they at Holtek
84 * call them. IDESETUP.COM that is supplied with the drivers figures out
85 * optimal values and fetches those values to drivers. I found out that
86 * they use IDE_SELECT_REG to fetch timings to the ide board right after
87 * interface switching. After that it was quite easy to add code to
90 * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine
91 * for hda and hdc. But hdb needed higher values to work, so I guess
92 * that sometimes it is necessary to give higher value than IDESETUP
93 * gives. [see cmd640.c for an extreme example of this. -ml]
95 * Perhaps I should explain something about these timing values:
96 * The higher nibble of value is the Recovery Time (rt) and the lower nibble
97 * of the value is the Active Time (at). Minimum value 2 is the fastest and
98 * the maximum value 15 is the slowest. Default values should be 15 for both.
99 * So 0x24 means 2 for rt and 4 for at. Each of the drives should have
100 * both values, and IDESETUP gives automatically rt=15 st=15 for CDROMs or
101 * similar. If value is too small there will be all sorts of failures.
103 * Timing byte consists of
104 * High nibble: Recovery Cycle Time (rt)
105 * The valid values range from 2 to 15. The default is 15.
107 * Low nibble: Active Cycle Time (at)
108 * The valid values range from 2 to 15. The default is 15.
110 * You can obtain optimized timing values by running Holtek IDESETUP.COM
111 * for DOS. DOS drivers get their timing values from command line, where
112 * the first value is the Recovery Time and the second value is the
113 * Active Time for each drive. Smaller value gives higher speed.
114 * In case of failures you should probably fall back to a higher value.
116 #define HT_TIMING(drivea) (u8)((drivea)->drive_data & 0x00ff)
117 #define HT_TIMING_DEFAULT 0xff
120 * This routine handles interface switching for the peculiar hardware design
121 * on the F.G.I./Holtek HT-6560B VLB IDE interface.
122 * The HT-6560B can only enable one IDE port at a time, and requires a
123 * silly sequence (below) whenever we switch between primary and secondary.
127 * This routine is invoked from ide.c to prepare for access to a given drive.
129 static void ht6560b_selectproc (ide_drive_t *drive)
132 static u8 current_select = 0;
133 static u8 current_timing = 0;
136 local_irq_save(flags);
138 select = HT_CONFIG(drive);
139 timing = HT_TIMING(drive);
141 if (select != current_select || timing != current_timing) {
142 current_select = select;
143 current_timing = timing;
144 if (drive->media != ide_disk || !drive->present)
145 select |= HT_PREFETCH_MODE;
146 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
147 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
148 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
149 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
150 HWIF(drive)->OUTB(select, HT_CONFIG_PORT);
152 * Set timing for this drive:
154 HWIF(drive)->OUTB(timing, IDE_SELECT_REG);
155 (void) HWIF(drive)->INB(IDE_STATUS_REG);
157 printk("ht6560b: %s: select=%#x timing=%#x\n",
158 drive->name, select, timing);
161 local_irq_restore(flags);
165 * Autodetection and initialization of ht6560b
167 static int __init try_to_init_ht6560b(void)
172 /* Autodetect ht6560b */
173 if ((orig_value = inb(HT_CONFIG_PORT)) == 0xff)
177 outb(0x00, HT_CONFIG_PORT);
178 if (!( (~inb(HT_CONFIG_PORT)) & 0x3f )) {
179 outb(orig_value, HT_CONFIG_PORT);
183 outb(0x00, HT_CONFIG_PORT);
184 if ((~inb(HT_CONFIG_PORT))& 0x3f) {
185 outb(orig_value, HT_CONFIG_PORT);
189 * Ht6560b autodetected
191 outb(HT_CONFIG_DEFAULT, HT_CONFIG_PORT);
192 outb(HT_TIMING_DEFAULT, 0x1f6); /* IDE_SELECT_REG */
193 (void) inb(0x1f7); /* IDE_STATUS_REG */
195 printk("\nht6560b " HT6560B_VERSION
196 ": chipset detected and initialized"
198 " with debug enabled"
204 static u8 ht_pio2timings(ide_drive_t *drive, u8 pio)
206 int active_time, recovery_time;
207 int active_cycles, recovery_cycles;
209 int bus_speed = system_bus_clock();
212 pio = ide_get_best_pio_mode(drive, pio, 5, &d);
215 * Just like opti621.c we try to calculate the
216 * actual cycle time for recovery and activity
217 * according system bus speed.
219 active_time = ide_pio_timings[pio].active_time;
220 recovery_time = d.cycle_time
222 - ide_pio_timings[pio].setup_time;
224 * Cycle times should be Vesa bus cycles
226 active_cycles = (active_time * bus_speed + 999) / 1000;
227 recovery_cycles = (recovery_time * bus_speed + 999) / 1000;
229 * Upper and lower limits
231 if (active_cycles < 2) active_cycles = 2;
232 if (recovery_cycles < 2) recovery_cycles = 2;
233 if (active_cycles > 15) active_cycles = 15;
234 if (recovery_cycles > 15) recovery_cycles = 0; /* 0==16 */
237 printk("ht6560b: drive %s setting pio=%d recovery=%d (%dns) active=%d (%dns)\n", drive->name, pio, recovery_cycles, recovery_time, active_cycles, active_time);
240 return (u8)((recovery_cycles << 4) | active_cycles);
244 printk("ht6560b: drive %s setting pio=0\n", drive->name);
247 return HT_TIMING_DEFAULT; /* default setting */
252 * Enable/Disable so called prefetch mode
254 static void ht_set_prefetch(ide_drive_t *drive, u8 state)
257 int t = HT_PREFETCH_MODE << 8;
259 spin_lock_irqsave(&ide_lock, flags);
262 * Prefetch mode and unmask irq seems to conflict
265 drive->drive_data |= t; /* enable prefetch mode */
266 drive->no_unmask = 1;
269 drive->drive_data &= ~t; /* disable prefetch mode */
270 drive->no_unmask = 0;
273 spin_unlock_irqrestore(&ide_lock, flags);
276 printk("ht6560b: drive %s prefetch mode %sabled\n", drive->name, (state ? "en" : "dis"));
280 static void tune_ht6560b (ide_drive_t *drive, u8 pio)
286 case 8: /* set prefetch off */
287 case 9: /* set prefetch on */
288 ht_set_prefetch(drive, pio & 1);
292 timing = ht_pio2timings(drive, pio);
294 spin_lock_irqsave(&ide_lock, flags);
296 drive->drive_data &= 0xff00;
297 drive->drive_data |= timing;
299 spin_unlock_irqrestore(&ide_lock, flags);
302 printk("ht6560b: drive %s tuned to pio mode %#x timing=%#x\n", drive->name, pio, timing);
306 /* Can be called directly from ide.c. */
307 int __init ht6560b_init(void)
309 ide_hwif_t *hwif, *mate;
312 hwif = &ide_hwifs[0];
313 mate = &ide_hwifs[1];
315 if (!request_region(HT_CONFIG_PORT, 1, hwif->name)) {
316 printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n",
321 if (!try_to_init_ht6560b()) {
322 printk(KERN_NOTICE "%s: HBA not found\n", __FUNCTION__);
326 hwif->chipset = ide_ht6560b;
327 hwif->selectproc = &ht6560b_selectproc;
328 hwif->tuneproc = &tune_ht6560b;
329 hwif->serialized = 1; /* is this needed? */
332 mate->chipset = ide_ht6560b;
333 mate->selectproc = &ht6560b_selectproc;
334 mate->tuneproc = &tune_ht6560b;
335 mate->serialized = 1; /* is this needed? */
340 * Setting default configurations for drives
342 t = (HT_CONFIG_DEFAULT << 8);
343 t |= HT_TIMING_DEFAULT;
344 hwif->drives[0].drive_data = t;
345 hwif->drives[1].drive_data = t;
347 t |= (HT_SECONDARY_IF << 8);
348 mate->drives[0].drive_data = t;
349 mate->drives[1].drive_data = t;
351 probe_hwif_init(hwif);
352 probe_hwif_init(mate);
354 create_proc_ide_interfaces();
359 release_region(HT_CONFIG_PORT, 1);
364 module_init(ht6560b_init);
367 MODULE_AUTHOR("See Local File");
368 MODULE_DESCRIPTION("HT-6560B EIDE-controller support");
369 MODULE_LICENSE("GPL");