2 * linux/drivers/block/ht6580.c Version 0.04 Mar 19, 1996
4 * Copyright (C) 1995-1996 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 * I reviewed some assembler source listings of htide drivers and found
16 * out how they setup those cycle time interfacing values, as they at Holtek
17 * call them. IDESETUP.COM that is supplied with the drivers figures out
18 * optimal values and fetches those values to drivers. I found out that
19 * they use IDE_SELECT_REG to fetch timings to the ide board right after
20 * interface switching. After that it was quite easy to add code to
23 * IDESETUP.COM gave me values 0x24, 0x45, 0xaa, 0xff that worked fine
24 * for hda and hdc. But hdb needed higher values to work, so I guess
25 * that sometimes it is necessary to give higher value than IDESETUP
26 * gives. [see cmd640.c for an extreme example of this. -ml]
28 * Perhaps I should explain something about these timing values:
29 * The higher nibble of value is the Recovery Time (rt) and the lower nibble
30 * of the value is the Active Time (at). Minimum value 2 is the fastest and
31 * the maximum value 15 is the slowest. Default values should be 15 for both.
32 * So 0x24 means 2 for rt and 4 for at. Each of the drives should have
33 * both values, and IDESETUP gives automatically rt=15 st=15 for CDROMs or
34 * similar. If value is too small there will be all sorts of failures.
36 * Port 0x3e6 bit 0x20 sets these timings on/off. If 0x20 bit is set
37 * these timings are disabled.
43 * There's something still missing from the initialization code, though.
44 * If I have booted to dos sometime after power on, I can get smaller
45 * timing values working. Perhaps I could soft-ice the initialization.
47 * -=- malafoss@snakemail.hut.fi -=- searching the marvels of universe -=-
50 #undef REALLY_SLOW_IO /* most systems can safely undef this */
52 #include <linux/types.h>
53 #include <linux/kernel.h>
54 #include <linux/delay.h>
55 #include <linux/timer.h>
57 #include <linux/ioport.h>
58 #include <linux/blkdev.h>
59 #include <linux/hdreg.h>
60 #include <linux/ide.h>
64 #include "ide_modes.h"
67 * This routine handles interface switching for the peculiar hardware design
68 * on the F.G.I./Holtek HT-6560B VLB IDE interface.
69 * The HT-6560B can only enable one IDE port at a time, and requires a
70 * silly sequence (below) whenever we switch between primary and secondary.
72 * This stuff is courtesy of malafoss@snakemail.hut.fi
73 * (or maf@nemesis.tky.hut.fi)
75 * At least one user has reported that this code can confuse the floppy
76 * controller and/or driver -- perhaps this should be changed to use
77 * a read-modify-write sequence, so as not to disturb other bits in the reg?
81 * The special i/o-port that HT-6560B uses to select interfaces:
83 #define HT_SELECT_PORT 0x3e6
86 * We don't know what all of the bits are for, but we *do* know about these:
87 * bit5 (0x20): "1" selects slower speed by disabling use of timing values
88 * bit0 (0x01): "1" selects second interface
90 static byte ht6560b_selects
[2][MAX_DRIVES
] = {{0x3c,0x3c}, {0x3d,0x3d}};
93 * VLB ht6560b Timing values:
95 * Timing byte consists of
96 * High nibble: Recovery Time (rt)
97 * The valid values range from 2 to 15. The default is 15.
99 * Low nibble: Active Time (at)
100 * The valid values range from 2 to 15. The default is 15.
102 * You can obtain optimized timing values by running Holtek IDESETUP.COM
103 * for DOS. DOS drivers get their timing values from command line, where
104 * the first value is the Recovery Time and the second value is the
105 * Active Time for each drive. Smaller value gives higher speed.
106 * In case of failures you should probably fall back to a higher value.
108 * Here's an example to make it clearer:
110 * DOS: DEVICE=C:\bin\HTIDE\HTIDE.SYS /D0=2,4 /D1=4,5 /D2=10,10 /D3=15,15
111 * Linux: byte ht6560b_timings [][] = {{0x24, 0x45}, {0xaa, 0xff}};
113 * Note: There are no ioctls to change these values directly,
114 * but settings can be approximated as PIO modes, using "hdparm":
116 * rc.local: hdparm -p3 /dev/hda -p2 /dev/hdb -p1 /dev/hdc -p0 /dev/hdd
119 static byte ht6560b_timings
[2][MAX_DRIVES
] = {{0xff,0xff}, {0xff,0xff}};
121 static byte pio_to_timings
[6] = {0xff, 0xaa, 0x45, 0x24, 0x13, 0x12};
124 * This routine is invoked from ide.c to prepare for access to a given drive.
126 static void ht6560b_selectproc (ide_drive_t
*drive
)
130 static byte current_select
= 0;
131 static byte current_timing
= 0;
132 byte select
= ht6560b_selects
[HWIF(drive
)->index
][drive
->select
.b
.unit
];
133 byte timing
= ht6560b_timings
[HWIF(drive
)->index
][drive
->select
.b
.unit
];
135 if (select
!= current_select
|| timing
!= current_timing
) {
136 current_select
= select
;
137 current_timing
= timing
;
138 __save_flags (flags
); /* local CPU only */
139 __cli(); /* local CPU only */
140 (void) inb(HT_SELECT_PORT
);
141 (void) inb(HT_SELECT_PORT
);
142 (void) inb(HT_SELECT_PORT
);
144 * Note: input bits are reversed to output bits!!
146 t
= inb(HT_SELECT_PORT
) ^ 0x3f;
148 t
|= (current_select
& 0x21);
149 outb(t
, HT_SELECT_PORT
);
151 * Set timing for this drive:
153 outb (timing
, IDE_SELECT_REG
);
154 (void) inb (IDE_STATUS_REG
);
155 __restore_flags (flags
); /* local CPU only */
157 printk("ht6560b: %s: select=%#x timing=%#x\n", drive
->name
, t
, timing
);
163 * Autodetection and initialization of ht6560b
165 int try_to_init_ht6560b(void)
170 /* Autodetect ht6560b */
171 if ((orig_value
=inb(HT_SELECT_PORT
)) == 0xff)
175 outb(0x00, HT_SELECT_PORT
);
176 if (!( (~inb(HT_SELECT_PORT
)) & 0x3f )) {
177 outb(orig_value
, HT_SELECT_PORT
);
181 outb(0x00, HT_SELECT_PORT
);
182 if ((~inb(HT_SELECT_PORT
))& 0x3f) {
183 outb(orig_value
, HT_SELECT_PORT
);
187 * Ht6560b autodetected:
188 * reverse input bits to output bits
189 * initialize bit1 to 0
191 outb((orig_value
^ 0x3f) & 0xfd, HT_SELECT_PORT
);
193 printk("\nht6560b: detected and initialized");
197 static void tune_ht6560b (ide_drive_t
*drive
, byte pio
)
199 unsigned int hwif
, unit
;
201 if (pio
== 255) { /* auto-tune */
202 if (drive
->media
!= ide_disk
)
203 pio
= 0; /* some CDROMs don't like fast modes (?) */
205 pio
= ide_get_best_pio_mode(drive
, pio
, 5, NULL
);
207 unit
= drive
->select
.b
.unit
;
208 hwif
= HWIF(drive
)->index
;
209 ht6560b_timings
[hwif
][unit
] = pio_to_timings
[pio
];
211 ht6560b_selects
[hwif
][unit
] |= 0x20;
213 ht6560b_selects
[hwif
][unit
] &= ~0x20;
216 void init_ht6560b (void)
218 if (check_region(HT_SELECT_PORT
,1)) {
219 printk("\nht6560b: PORT 0x3e6 ALREADY IN USE\n");
221 if (try_to_init_ht6560b()) {
222 request_region(HT_SELECT_PORT
, 1, ide_hwifs
[0].name
);
223 ide_hwifs
[0].chipset
= ide_ht6560b
;
224 ide_hwifs
[1].chipset
= ide_ht6560b
;
225 ide_hwifs
[0].selectproc
= &ht6560b_selectproc
;
226 ide_hwifs
[1].selectproc
= &ht6560b_selectproc
;
227 ide_hwifs
[0].tuneproc
= &tune_ht6560b
;
228 ide_hwifs
[1].tuneproc
= &tune_ht6560b
;
229 ide_hwifs
[0].serialized
= 1;
230 ide_hwifs
[1].serialized
= 1;
231 ide_hwifs
[0].mate
= &ide_hwifs
[1];
232 ide_hwifs
[1].mate
= &ide_hwifs
[0];
233 ide_hwifs
[1].channel
= 1;
235 printk("\nht6560b: not found\n");