OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [block/] [ht6560b.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1626 jcastillo
/*
2
 *  linux/drivers/block/ht6580.c       Version 0.04  Mar 19, 1996
3
 *
4
 *  Copyright (C) 1995-1996  Linus Torvalds & author (see below)
5
 */
6
 
7
/*
8
 *
9
 *  Version 0.01        Initial version hacked out of ide.c
10
 *
11
 *  Version 0.02        Added support for PIO modes, auto-tune
12
 *
13
 *  Version 0.03        Some cleanups
14
 *
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
21
 * ht6560b.c.
22
 *
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]
27
 *
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.
35
 *
36
 * Port 0x3e6 bit 0x20 sets these timings on/off. If 0x20 bit is set
37
 * these timings are disabled.
38
 *
39
 * Mikko Ala-Fossi
40
 *
41
 * More notes:
42
 *
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.
46
 *
47
 * -=- malafoss@snakemail.hut.fi -=- searching the marvels of universe -=-
48
 */
49
 
50
#undef REALLY_SLOW_IO           /* most systems can safely undef this */
51
 
52
#include <linux/types.h>
53
#include <linux/kernel.h>
54
#include <linux/delay.h>
55
#include <linux/timer.h>
56
#include <linux/mm.h>
57
#include <linux/ioport.h>
58
#include <linux/blkdev.h>
59
#include <linux/hdreg.h>
60
#include <asm/io.h>
61
#include "ide.h"
62
#include "ide_modes.h"
63
 
64
/*
65
 * This routine handles interface switching for the peculiar hardware design
66
 * on the F.G.I./Holtek HT-6560B VLB IDE interface.
67
 * The HT-6560B can only enable one IDE port at a time, and requires a
68
 * silly sequence (below) whenever we switch between primary and secondary.
69
 *
70
 * This stuff is courtesy of malafoss@snakemail.hut.fi
71
 *                          (or maf@nemesis.tky.hut.fi)
72
 *
73
 * At least one user has reported that this code can confuse the floppy
74
 * controller and/or driver -- perhaps this should be changed to use
75
 * a read-modify-write sequence, so as not to disturb other bits in the reg?
76
 */
77
 
78
/*
79
 * The special i/o-port that HT-6560B uses to select interfaces:
80
 */
81
#define HT_SELECT_PORT     0x3e6
82
 
83
/*
84
 * We don't know what all of the bits are for, but we *do* know about these:
85
 *      bit5 (0x20): "1" selects slower speed by disabling use of timing values
86
 *      bit0 (0x01): "1" selects second interface
87
 */
88
static byte ht6560b_selects [2][MAX_DRIVES] = {{0x3c,0x3c}, {0x3d,0x3d}};
89
 
90
/*
91
 * VLB ht6560b Timing values:
92
 *
93
 * Timing byte consists of
94
 *      High nibble:  Recovery Time  (rt)
95
 *           The valid values range from 2 to 15. The default is 15.
96
 *
97
 *      Low nibble:   Active Time    (at)
98
 *           The valid values range from 2 to 15. The default is 15.
99
 *
100
 * You can obtain optimized timing values by running Holtek IDESETUP.COM
101
 * for DOS. DOS drivers get their timing values from command line, where
102
 * the first value is the Recovery Time and the second value is the
103
 * Active Time for each drive. Smaller value gives higher speed.
104
 * In case of failures you should probably fall back to a higher value.
105
 *
106
 * Hopefully this example will make it clearer:
107
 *
108
 * DOS:    DEVICE=C:\bin\HTIDE\HTIDE.SYS /D0=2,4 /D1=4,5 /D2=10,10 /D3=15,15
109
 * Linux:  byte ht6560b_timings [][] = {{0x24, 0x45}, {0xaa, 0xff}};
110
 *
111
 * Note: There are no ioctls to change these values directly,
112
 * but settings can be approximated as PIO modes, using "hdparm":
113
 *
114
 * rc.local:  hdparm -p3 /dev/hda -p2 /dev/hdb -p1 /dev/hdc -p0 /dev/hdd
115
 */
116
 
117
static byte ht6560b_timings [2][MAX_DRIVES] = {{0xff,0xff}, {0xff,0xff}};
118
 
119
static byte pio_to_timings[6] = {0xff, 0xaa, 0x45, 0x24, 0x13, 0x12};
120
 
121
/*
122
 * This routine is invoked from ide.c to prepare for access to a given drive.
123
 */
124
static void ht6560b_selectproc (ide_drive_t *drive)
125
{
126
        byte t;
127
        unsigned long flags;
128
        static byte current_select = 0;
129
        static byte current_timing = 0;
130
        byte select = ht6560b_selects[HWIF(drive)->index][drive->select.b.unit];
131
        byte timing = ht6560b_timings[HWIF(drive)->index][drive->select.b.unit];
132
 
133
        if (select != current_select || timing != current_timing) {
134
                current_select = select;
135
                current_timing = timing;
136
                save_flags (flags);
137
                cli();
138
                (void) inb(HT_SELECT_PORT);
139
                (void) inb(HT_SELECT_PORT);
140
                (void) inb(HT_SELECT_PORT);
141
                /*
142
                 * Note: input bits are reversed to output bits!!
143
                 */
144
                t = inb(HT_SELECT_PORT) ^ 0x3f;
145
                t &= (~0x21);
146
                t |= (current_select & 0x21);
147
                outb(t, HT_SELECT_PORT);
148
                /*
149
                 * Set timing for this drive:
150
                 */
151
                outb (timing, IDE_SELECT_REG);
152
                (void) inb (IDE_STATUS_REG);
153
                restore_flags (flags);
154
#ifdef DEBUG
155
                printk("ht6560b: %s: select=%#x timing=%#x\n", drive->name, t, timing);
156
#endif
157
        }
158
        OUT_BYTE(drive->select.all,IDE_SELECT_REG);
159
}
160
 
161
/*
162
 * Autodetection and initialization of ht6560b
163
 */
164
int try_to_init_ht6560b(void)
165
{
166
        byte orig_value;
167
        int i;
168
 
169
        /* Autodetect ht6560b */
170
        if ((orig_value=inb(HT_SELECT_PORT)) == 0xff)
171
                return 0;
172
 
173
        for (i=3;i>0;i--) {
174
                outb(0x00, HT_SELECT_PORT);
175
                if (!( (~inb(HT_SELECT_PORT)) & 0x3f )) {
176
                          outb(orig_value, HT_SELECT_PORT);
177
                          return 0;
178
                }
179
        }
180
        outb(0x00, HT_SELECT_PORT);
181
        if ((~inb(HT_SELECT_PORT))& 0x3f) {
182
                outb(orig_value, HT_SELECT_PORT);
183
                return 0;
184
        }
185
        /*
186
         * Ht6560b autodetected:
187
         *     reverse input bits to output bits
188
         *     initialize bit1 to 0
189
         */
190
        outb((orig_value ^ 0x3f) & 0xfd, HT_SELECT_PORT);
191
 
192
        printk("\nht6560b: detected and initialized");
193
        return 1;
194
}
195
 
196
static void tune_ht6560b (ide_drive_t *drive, byte pio)
197
{
198
        unsigned int hwif, unit;
199
 
200
        if (pio == 255)  {      /* auto-tune */
201
                if (drive->media != ide_disk)
202
                        pio = 0; /* some cdroms don't like fast modes (?) */
203
                else
204
                        pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
205
        }
206
        unit = drive->select.b.unit;
207
        hwif = HWIF(drive)->index;
208
        ht6560b_timings[hwif][unit] = pio_to_timings[pio];
209
        if (pio == 0)
210
                ht6560b_selects[hwif][unit] |= 0x20;
211
        else
212
                ht6560b_selects[hwif][unit] &= ~0x20;
213
}
214
 
215
void init_ht6560b (void)
216
{
217
        if (check_region(HT_SELECT_PORT,1)) {
218
                printk("\nht6560b: PORT 0x3e6 ALREADY IN USE\n");
219
        } else {
220
                if (try_to_init_ht6560b()) {
221
                        request_region(HT_SELECT_PORT, 1, ide_hwifs[0].name);
222
                        ide_hwifs[0].chipset = ide_ht6560b;
223
                        ide_hwifs[1].chipset = ide_ht6560b;
224
                        ide_hwifs[0].selectproc = &ht6560b_selectproc;
225
                        ide_hwifs[1].selectproc = &ht6560b_selectproc;
226
                        ide_hwifs[0].tuneproc = &tune_ht6560b;
227
                        ide_hwifs[1].tuneproc = &tune_ht6560b;
228
                        ide_hwifs[0].serialized = 1;
229
                        ide_hwifs[1].serialized = 1;
230
                } else
231
                        printk("\nht6560b: not found\n");
232
        }
233
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.