Import 2.3.18pre1
[davej-history.git] / drivers / block / ide_modes.h
blobd8c8a714432082e5a6435f411f036ae7717c4606
1 #ifndef _IDE_MODES_H
2 #define _IDE_MODES_H
3 /*
4 * linux/drivers/block/ide_modes.h
6 * Copyright (C) 1996 Linus Torvalds, Igor Abramov, and Mark Lord
7 */
9 #include <linux/config.h>
12 * Shared data/functions for determining best PIO mode for an IDE drive.
13 * Most of this stuff originally lived in cmd640.c, and changes to the
14 * ide_pio_blacklist[] table should be made with EXTREME CAUTION to avoid
15 * breaking the fragile cmd640.c support.
18 #ifdef CONFIG_BLK_DEV_IDE_MODES
21 * Standard (generic) timings for PIO modes, from ATA2 specification.
22 * These timings are for access to the IDE data port register *only*.
23 * Some drives may specify a mode, while also specifying a different
24 * value for cycle_time (from drive identification data).
26 typedef struct ide_pio_timings_s {
27 int setup_time; /* Address setup (ns) minimum */
28 int active_time; /* Active pulse (ns) minimum */
29 int cycle_time; /* Cycle time (ns) minimum = (setup + active + recovery) */
30 } ide_pio_timings_t;
32 typedef struct ide_pio_data_s {
33 byte pio_mode;
34 byte use_iordy;
35 byte overridden;
36 byte blacklisted;
37 unsigned int cycle_time;
38 } ide_pio_data_t;
40 #ifndef _IDE_C
42 int ide_scan_pio_blacklist (char *model);
43 byte ide_get_best_pio_mode (ide_drive_t *drive, byte mode_wanted, byte max_mode, ide_pio_data_t *d);
44 extern const ide_pio_timings_t ide_pio_timings[6];
46 #else /* _IDE_C */
48 const ide_pio_timings_t ide_pio_timings[6] = {
49 { 70, 165, 600 }, /* PIO Mode 0 */
50 { 50, 125, 383 }, /* PIO Mode 1 */
51 { 30, 100, 240 }, /* PIO Mode 2 */
52 { 30, 80, 180 }, /* PIO Mode 3 with IORDY */
53 { 25, 70, 120 }, /* PIO Mode 4 with IORDY */
54 { 20, 50, 100 } /* PIO Mode 5 with IORDY (nonstandard) */
58 * Black list. Some drives incorrectly report their maximal PIO mode,
59 * at least in respect to CMD640. Here we keep info on some known drives.
61 static struct ide_pio_info {
62 const char *name;
63 int pio;
64 } ide_pio_blacklist [] = {
65 /* { "Conner Peripherals 1275MB - CFS1275A", 4 }, */
66 { "Conner Peripherals 540MB - CFS540A", 3 },
68 { "WDC AC2700", 3 },
69 { "WDC AC2540", 3 },
70 { "WDC AC2420", 3 },
71 { "WDC AC2340", 3 },
72 { "WDC AC2250", 0 },
73 { "WDC AC2200", 0 },
74 { "WDC AC21200", 4 },
75 { "WDC AC2120", 0 },
76 { "WDC AC2850", 3 },
77 { "WDC AC1270", 3 },
78 { "WDC AC1170", 1 },
79 { "WDC AC1210", 1 },
80 { "WDC AC280", 0 },
81 /* { "WDC AC21000", 4 }, */
82 { "WDC AC31000", 3 },
83 { "WDC AC31200", 3 },
84 /* { "WDC AC31600", 4 }, */
86 { "Maxtor 7131 AT", 1 },
87 { "Maxtor 7171 AT", 1 },
88 { "Maxtor 7213 AT", 1 },
89 { "Maxtor 7245 AT", 1 },
90 { "Maxtor 7345 AT", 1 },
91 { "Maxtor 7546 AT", 3 },
92 { "Maxtor 7540 AV", 3 },
94 { "SAMSUNG SHD-3121A", 1 },
95 { "SAMSUNG SHD-3122A", 1 },
96 { "SAMSUNG SHD-3172A", 1 },
98 /* { "ST51080A", 4 },
99 * { "ST51270A", 4 },
100 * { "ST31220A", 4 },
101 * { "ST31640A", 4 },
102 * { "ST32140A", 4 },
103 * { "ST3780A", 4 },
105 { "ST5660A", 3 },
106 { "ST3660A", 3 },
107 { "ST3630A", 3 },
108 { "ST3655A", 3 },
109 { "ST3391A", 3 },
110 { "ST3390A", 1 },
111 { "ST3600A", 1 },
112 { "ST3290A", 0 },
113 { "ST3144A", 0 },
114 { "ST3491A", 1 }, /* reports 3, should be 1 or 2 (depending on */
115 /* drive) according to Seagates FIND-ATA program */
117 { "QUANTUM ELS127A", 0 },
118 { "QUANTUM ELS170A", 0 },
119 { "QUANTUM LPS240A", 0 },
120 { "QUANTUM LPS210A", 3 },
121 { "QUANTUM LPS270A", 3 },
122 { "QUANTUM LPS365A", 3 },
123 { "QUANTUM LPS540A", 3 },
124 { "QUANTUM LIGHTNING 540A", 3 },
125 { "QUANTUM LIGHTNING 730A", 3 },
126 { "QUANTUM FIREBALL", 3 }, /* For models 540/640/1080/1280 */
127 /* 1080A works fine in mode4 with triton */
128 { NULL, 0 }
132 * This routine searches the ide_pio_blacklist for an entry
133 * matching the start/whole of the supplied model name.
135 * Returns -1 if no match found.
136 * Otherwise returns the recommended PIO mode from ide_pio_blacklist[].
138 int ide_scan_pio_blacklist (char *model)
140 struct ide_pio_info *p;
142 for (p = ide_pio_blacklist; p->name != NULL; p++) {
143 if (strncmp(p->name, model, strlen(p->name)) == 0)
144 return p->pio;
146 return -1;
150 * This routine returns the recommended PIO settings for a given drive,
151 * based on the drive->id information and the ide_pio_blacklist[].
152 * This is used by most chipset support modules when "auto-tuning".
156 * Drive PIO mode auto selection
158 byte ide_get_best_pio_mode (ide_drive_t *drive, byte mode_wanted, byte max_mode, ide_pio_data_t *d)
160 int pio_mode;
161 int cycle_time = 0;
162 int use_iordy = 0;
163 struct hd_driveid* id = drive->id;
164 int overridden = 0;
165 int blacklisted = 0;
167 if (mode_wanted != 255) {
168 pio_mode = mode_wanted;
169 } else if (!drive->id) {
170 pio_mode = 0;
171 } else if ((pio_mode = ide_scan_pio_blacklist(id->model)) != -1) {
172 overridden = 1;
173 blacklisted = 1;
174 use_iordy = (pio_mode > 2);
175 } else {
176 pio_mode = id->tPIO;
177 if (pio_mode > 2) { /* 2 is maximum allowed tPIO value */
178 pio_mode = 2;
179 overridden = 1;
181 if (id->field_valid & 2) { /* drive implements ATA2? */
182 if (id->capability & 8) { /* drive supports use_iordy? */
183 use_iordy = 1;
184 cycle_time = id->eide_pio_iordy;
185 if (id->eide_pio_modes & 7) {
186 overridden = 0;
187 if (id->eide_pio_modes & 4)
188 pio_mode = 5;
189 else if (id->eide_pio_modes & 2)
190 pio_mode = 4;
191 else
192 pio_mode = 3;
194 } else {
195 cycle_time = id->eide_pio;
200 * Conservative "downgrade" for all pre-ATA2 drives
202 if (pio_mode && pio_mode < 4) {
203 pio_mode--;
204 overridden = 1;
205 #if 0
206 use_iordy = (pio_mode > 2);
207 #endif
208 if (cycle_time && cycle_time < ide_pio_timings[pio_mode].cycle_time)
209 cycle_time = 0; /* use standard timing */
212 if (pio_mode > max_mode) {
213 pio_mode = max_mode;
214 cycle_time = 0;
216 if (d) {
217 d->pio_mode = pio_mode;
218 d->cycle_time = cycle_time ? cycle_time : ide_pio_timings[pio_mode].cycle_time;
219 d->use_iordy = use_iordy;
220 d->overridden = overridden;
221 d->blacklisted = blacklisted;
223 return pio_mode;
226 #endif /* _IDE_C */
227 #endif /* CONFIG_BLK_DEV_IDE_MODES */
228 #endif /* _IDE_MODES_H */