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/config.h>
43 #include <linux/types.h>
44 #include <linux/kernel.h>
45 #include <linux/delay.h>
46 #include <linux/timer.h>
48 #include <linux/ioport.h>
49 #include <linux/blkdev.h>
50 #include <linux/hdreg.h>
51 #include <linux/ide.h>
52 #include <linux/init.h>
56 #ifdef CONFIG_BLK_DEV_HT6560B_MODULE
58 # include "ide_modes.h"
61 # include "ide_modes.h"
62 #endif /* CONFIG_BLK_DEV_HT6560B_MODULE */
64 /* #define DEBUG */ /* remove comments for DEBUG messages */
67 * The special i/o-port that HT-6560B uses to configuration:
68 * bit0 (0x01): "1" selects secondary interface
69 * bit2 (0x04): "1" enables FIFO function
70 * bit5 (0x20): "1" enables prefetched data read function (???)
72 * The special i/o-port that HT-6560A uses to configuration:
73 * bit0 (0x01): "1" selects secondary interface
74 * bit1 (0x02): "1" enables prefetched data read function
75 * bit2 (0x04): "0" enables multi-master system (?)
76 * bit3 (0x08): "1" 3 cycle time, "0" 2 cycle time (?)
78 #define HT_CONFIG_PORT 0x3e6
79 #define HT_CONFIG(drivea) (u8)(((drivea)->drive_data & 0xff00) >> 8)
81 * FIFO + PREFETCH (both a/b-model)
83 #define HT_CONFIG_DEFAULT 0x1c /* no prefetch */
84 /* #define HT_CONFIG_DEFAULT 0x3c */ /* with prefetch */
85 #define HT_SECONDARY_IF 0x01
86 #define HT_PREFETCH_MODE 0x20
89 * ht6560b Timing values:
91 * I reviewed some assembler source listings of htide drivers and found
92 * out how they setup those cycle time interfacing values, as they at Holtek
93 * call them. IDESETUP.COM that is supplied with the drivers figures out
94 * optimal values and fetches those values to drivers. I found out that
95 * they use IDE_SELECT_REG to fetch timings to the ide board right after
96 * interface switching. After that it was quite easy to add code to
99 * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine
100 * for hda and hdc. But hdb needed higher values to work, so I guess
101 * that sometimes it is necessary to give higher value than IDESETUP
102 * gives. [see cmd640.c for an extreme example of this. -ml]
104 * Perhaps I should explain something about these timing values:
105 * The higher nibble of value is the Recovery Time (rt) and the lower nibble
106 * of the value is the Active Time (at). Minimum value 2 is the fastest and
107 * the maximum value 15 is the slowest. Default values should be 15 for both.
108 * So 0x24 means 2 for rt and 4 for at. Each of the drives should have
109 * both values, and IDESETUP gives automatically rt=15 st=15 for CDROMs or
110 * similar. If value is too small there will be all sorts of failures.
112 * Timing byte consists of
113 * High nibble: Recovery Cycle Time (rt)
114 * The valid values range from 2 to 15. The default is 15.
116 * Low nibble: Active Cycle Time (at)
117 * The valid values range from 2 to 15. The default is 15.
119 * You can obtain optimized timing values by running Holtek IDESETUP.COM
120 * for DOS. DOS drivers get their timing values from command line, where
121 * the first value is the Recovery Time and the second value is the
122 * Active Time for each drive. Smaller value gives higher speed.
123 * In case of failures you should probably fall back to a higher value.
125 #define HT_TIMING(drivea) (u8)((drivea)->drive_data & 0x00ff)
126 #define HT_TIMING_DEFAULT 0xff
129 * This routine handles interface switching for the peculiar hardware design
130 * on the F.G.I./Holtek HT-6560B VLB IDE interface.
131 * The HT-6560B can only enable one IDE port at a time, and requires a
132 * silly sequence (below) whenever we switch between primary and secondary.
136 * This routine is invoked from ide.c to prepare for access to a given drive.
138 static void ht6560b_selectproc (ide_drive_t *drive)
141 static u8 current_select = 0;
142 static u8 current_timing = 0;
145 local_irq_save(flags);
147 select = HT_CONFIG(drive);
148 timing = HT_TIMING(drive);
150 if (select != current_select || timing != current_timing) {
151 current_select = select;
152 current_timing = timing;
153 if (drive->media != ide_disk || !drive->present)
154 select |= HT_PREFETCH_MODE;
155 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
156 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
157 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
158 (void) HWIF(drive)->INB(HT_CONFIG_PORT);
159 HWIF(drive)->OUTB(select, HT_CONFIG_PORT);
161 * Set timing for this drive:
163 HWIF(drive)->OUTB(timing, IDE_SELECT_REG);
164 (void) HWIF(drive)->INB(IDE_STATUS_REG);
166 printk("ht6560b: %s: select=%#x timing=%#x\n",
167 drive->name, select, timing);
170 local_irq_restore(flags);
174 * Autodetection and initialization of ht6560b
176 static int __init try_to_init_ht6560b(void)
181 /* Autodetect ht6560b */
182 if ((orig_value = inb(HT_CONFIG_PORT)) == 0xff)
186 outb(0x00, HT_CONFIG_PORT);
187 if (!( (~inb(HT_CONFIG_PORT)) & 0x3f )) {
188 outb(orig_value, HT_CONFIG_PORT);
192 outb(0x00, HT_CONFIG_PORT);
193 if ((~inb(HT_CONFIG_PORT))& 0x3f) {
194 outb(orig_value, HT_CONFIG_PORT);
198 * Ht6560b autodetected
200 outb(HT_CONFIG_DEFAULT, HT_CONFIG_PORT);
201 outb(HT_TIMING_DEFAULT, 0x1f6); /* IDE_SELECT_REG */
202 (void) inb(0x1f7); /* IDE_STATUS_REG */
204 printk("\nht6560b " HT6560B_VERSION
205 ": chipset detected and initialized"
207 " with debug enabled"
213 static u8 ht_pio2timings(ide_drive_t *drive, u8 pio)
215 int active_time, recovery_time;
216 int active_cycles, recovery_cycles;
218 int bus_speed = system_bus_clock();
221 pio = ide_get_best_pio_mode(drive, pio, 5, &d);
224 * Just like opti621.c we try to calculate the
225 * actual cycle time for recovery and activity
226 * according system bus speed.
228 active_time = ide_pio_timings[pio].active_time;
229 recovery_time = d.cycle_time
231 - ide_pio_timings[pio].setup_time;
233 * Cycle times should be Vesa bus cycles
235 active_cycles = (active_time * bus_speed + 999) / 1000;
236 recovery_cycles = (recovery_time * bus_speed + 999) / 1000;
238 * Upper and lower limits
240 if (active_cycles < 2) active_cycles = 2;
241 if (recovery_cycles < 2) recovery_cycles = 2;
242 if (active_cycles > 15) active_cycles = 15;
243 if (recovery_cycles > 15) recovery_cycles = 0; /* 0==16 */
246 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);
249 return (u8)((recovery_cycles << 4) | active_cycles);
253 printk("ht6560b: drive %s setting pio=0\n", drive->name);
256 return HT_TIMING_DEFAULT; /* default setting */
261 * Enable/Disable so called prefetch mode
263 static void ht_set_prefetch(ide_drive_t *drive, u8 state)
266 int t = HT_PREFETCH_MODE << 8;
268 spin_lock_irqsave(&io_request_lock, flags);
271 * Prefetch mode and unmask irq seems to conflict
274 drive->drive_data |= t; /* enable prefetch mode */
275 drive->no_unmask = 1;
278 drive->drive_data &= ~t; /* disable prefetch mode */
279 drive->no_unmask = 0;
282 spin_unlock_irqrestore(&io_request_lock, flags);
285 printk("ht6560b: drive %s prefetch mode %sabled\n", drive->name, (state ? "en" : "dis"));
289 static void tune_ht6560b (ide_drive_t *drive, u8 pio)
295 case 8: /* set prefetch off */
296 case 9: /* set prefetch on */
297 ht_set_prefetch(drive, pio & 1);
301 timing = ht_pio2timings(drive, pio);
303 spin_lock_irqsave(&io_request_lock, flags);
305 drive->drive_data &= 0xff00;
306 drive->drive_data |= timing;
308 spin_unlock_irqrestore(&io_request_lock, flags);
311 printk("ht6560b: drive %s tuned to pio mode %#x timing=%#x\n", drive->name, pio, timing);
315 void __init probe_ht6560b (void)
319 request_region(HT_CONFIG_PORT, 1, ide_hwifs[0].name);
320 ide_hwifs[0].chipset = ide_ht6560b;
321 ide_hwifs[1].chipset = ide_ht6560b;
322 ide_hwifs[0].selectproc = &ht6560b_selectproc;
323 ide_hwifs[1].selectproc = &ht6560b_selectproc;
324 ide_hwifs[0].tuneproc = &tune_ht6560b;
325 ide_hwifs[1].tuneproc = &tune_ht6560b;
326 ide_hwifs[0].serialized = 1; /* is this needed? */
327 ide_hwifs[1].serialized = 1; /* is this needed? */
328 ide_hwifs[0].mate = &ide_hwifs[1];
329 ide_hwifs[1].mate = &ide_hwifs[0];
330 ide_hwifs[1].channel = 1;
333 * Setting default configurations for drives
335 t = (HT_CONFIG_DEFAULT << 8);
336 t |= HT_TIMING_DEFAULT;
337 ide_hwifs[0].drives[0].drive_data = t;
338 ide_hwifs[0].drives[1].drive_data = t;
339 t |= (HT_SECONDARY_IF << 8);
340 ide_hwifs[1].drives[0].drive_data = t;
341 ide_hwifs[1].drives[1].drive_data = t;
343 #ifndef HWIF_PROBE_CLASSIC_METHOD
344 probe_hwif_init(&ide_hwifs[0]);
345 probe_hwif_init(&ide_hwifs[1]);
346 #endif /* HWIF_PROBE_CLASSIC_METHOD */
350 void __init ht6560b_release (void)
352 if (ide_hwifs[0].chipset != ide_ht6560b &&
353 ide_hwifs[1].chipset != ide_ht6560b)
356 ide_hwifs[0].chipset = ide_unknown;
357 ide_hwifs[1].chipset = ide_unknown;
358 ide_hwifs[0].tuneproc = NULL;
359 ide_hwifs[1].tuneproc = NULL;
360 ide_hwifs[0].selectproc = NULL;
361 ide_hwifs[1].selectproc = NULL;
362 ide_hwifs[0].serialized = 0;
363 ide_hwifs[1].serialized = 0;
364 ide_hwifs[0].mate = NULL;
365 ide_hwifs[1].mate = NULL;
367 ide_hwifs[0].drives[0].drive_data = 0;
368 ide_hwifs[0].drives[1].drive_data = 0;
369 ide_hwifs[1].drives[0].drive_data = 0;
370 ide_hwifs[1].drives[1].drive_data = 0;
371 release_region(HT_CONFIG_PORT, 1);
378 * called by ide.c when parsing command line
381 void __init init_ht6560b (void)
383 if (check_region(HT_CONFIG_PORT,1)) {
384 printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n",
388 if (!try_to_init_ht6560b()) {
389 printk(KERN_NOTICE "%s: HBA not found\n", __FUNCTION__);
397 MODULE_AUTHOR("See Local File");
398 MODULE_DESCRIPTION("HT-6560B EIDE-controller support");
399 MODULE_LICENSE("GPL");
401 int __init ht6560b_mod_init(void)
403 if (check_region(HT_CONFIG_PORT,1)) {
404 printk(KERN_NOTICE "%s: HT_CONFIG_PORT not found\n",
409 if (!try_to_init_ht6560b()) {
410 printk(KERN_NOTICE "%s: HBA not found\n", __FUNCTION__);
415 if (ide_hwifs[0].chipset != ide_ht6560b &&
416 ide_hwifs[1].chipset != ide_ht6560b) {
422 module_init(ht6560b_mod_init);
424 void __init ht6560b_mod_exit(void)
428 module_exit(ht6560b_mod_exit);