1 |
1275 |
phoenix |
/*
|
2 |
|
|
* linux/drivers/ide/pci/hpt366.c Version 0.36 April 25, 2003
|
3 |
|
|
*
|
4 |
|
|
* Copyright (C) 1999-2003 Andre Hedrick <andre@linux-ide.org>
|
5 |
|
|
* Portions Copyright (C) 2001 Sun Microsystems, Inc.
|
6 |
|
|
* Portions Copyright (C) 2003 Red Hat Inc
|
7 |
|
|
*
|
8 |
|
|
* Thanks to HighPoint Technologies for their assistance, and hardware.
|
9 |
|
|
* Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
|
10 |
|
|
* donation of an ABit BP6 mainboard, processor, and memory acellerated
|
11 |
|
|
* development and support.
|
12 |
|
|
*
|
13 |
|
|
* Highpoint have their own driver (source except for the raid part)
|
14 |
|
|
* available from http://www.highpoint-tech.com/hpt3xx-opensource-v131.tgz
|
15 |
|
|
* This may be useful to anyone wanting to work on the mainstream hpt IDE.
|
16 |
|
|
*
|
17 |
|
|
* Note that final HPT370 support was done by force extraction of GPL.
|
18 |
|
|
*
|
19 |
|
|
* - add function for getting/setting power status of drive
|
20 |
|
|
* - the HPT370's state machine can get confused. reset it before each dma
|
21 |
|
|
* xfer to prevent that from happening.
|
22 |
|
|
* - reset state engine whenever we get an error.
|
23 |
|
|
* - check for busmaster state at end of dma.
|
24 |
|
|
* - use new highpoint timings.
|
25 |
|
|
* - detect bus speed using highpoint register.
|
26 |
|
|
* - use pll if we don't have a clock table. added a 66MHz table that's
|
27 |
|
|
* just 2x the 33MHz table.
|
28 |
|
|
* - removed turnaround. NOTE: we never want to switch between pll and
|
29 |
|
|
* pci clocks as the chip can glitch in those cases. the highpoint
|
30 |
|
|
* approved workaround slows everything down too much to be useful. in
|
31 |
|
|
* addition, we would have to serialize access to each chip.
|
32 |
|
|
* Adrian Sun <a.sun@sun.com>
|
33 |
|
|
*
|
34 |
|
|
* add drive timings for 66MHz PCI bus,
|
35 |
|
|
* fix ATA Cable signal detection, fix incorrect /proc info
|
36 |
|
|
* add /proc display for per-drive PIO/DMA/UDMA mode and
|
37 |
|
|
* per-channel ATA-33/66 Cable detect.
|
38 |
|
|
* Duncan Laurie <void@sun.com>
|
39 |
|
|
*
|
40 |
|
|
* fixup /proc output for multiple controllers
|
41 |
|
|
* Tim Hockin <thockin@sun.com>
|
42 |
|
|
*
|
43 |
|
|
* On hpt366:
|
44 |
|
|
* Reset the hpt366 on error, reset on dma
|
45 |
|
|
* Fix disabling Fast Interrupt hpt366.
|
46 |
|
|
* Mike Waychison <crlf@sun.com>
|
47 |
|
|
*
|
48 |
|
|
* Added support for 372N clocking and clock switching. The 372N needs
|
49 |
|
|
* different clocks on read/write. This requires overloading rw_disk and
|
50 |
|
|
* other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
|
51 |
|
|
* keeping me sane.
|
52 |
|
|
* Alan Cox <alan@redhat.com>
|
53 |
|
|
*
|
54 |
|
|
*/
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
#include <linux/config.h>
|
58 |
|
|
#include <linux/types.h>
|
59 |
|
|
#include <linux/module.h>
|
60 |
|
|
#include <linux/kernel.h>
|
61 |
|
|
#include <linux/delay.h>
|
62 |
|
|
#include <linux/timer.h>
|
63 |
|
|
#include <linux/mm.h>
|
64 |
|
|
#include <linux/ioport.h>
|
65 |
|
|
#include <linux/blkdev.h>
|
66 |
|
|
#include <linux/hdreg.h>
|
67 |
|
|
|
68 |
|
|
#include <linux/interrupt.h>
|
69 |
|
|
#include <linux/pci.h>
|
70 |
|
|
#include <linux/init.h>
|
71 |
|
|
#include <linux/ide.h>
|
72 |
|
|
|
73 |
|
|
#include <asm/uaccess.h>
|
74 |
|
|
#include <asm/io.h>
|
75 |
|
|
#include <asm/irq.h>
|
76 |
|
|
|
77 |
|
|
#include "ide_modes.h"
|
78 |
|
|
#include "hpt366.h"
|
79 |
|
|
|
80 |
|
|
#if defined(DISPLAY_HPT366_TIMINGS) && defined(CONFIG_PROC_FS)
|
81 |
|
|
#include <linux/stat.h>
|
82 |
|
|
#include <linux/proc_fs.h>
|
83 |
|
|
#endif /* defined(DISPLAY_HPT366_TIMINGS) && defined(CONFIG_PROC_FS) */
|
84 |
|
|
|
85 |
|
|
static unsigned int hpt_revision(struct pci_dev *dev);
|
86 |
|
|
static unsigned int hpt_minimum_revision(struct pci_dev *dev, int revision);
|
87 |
|
|
|
88 |
|
|
#if defined(DISPLAY_HPT366_TIMINGS) && defined(CONFIG_PROC_FS)
|
89 |
|
|
|
90 |
|
|
static u8 hpt366_proc = 0;
|
91 |
|
|
static struct pci_dev *hpt_devs[HPT366_MAX_DEVS];
|
92 |
|
|
static int n_hpt_devs;
|
93 |
|
|
|
94 |
|
|
static int hpt366_get_info (char *buffer, char **addr, off_t offset, int count)
|
95 |
|
|
{
|
96 |
|
|
char *p = buffer;
|
97 |
|
|
char *chipset_nums[] = {"366", "366", "368",
|
98 |
|
|
"370", "370A", "372",
|
99 |
|
|
"302", "371", "374" };
|
100 |
|
|
int i;
|
101 |
|
|
|
102 |
|
|
p += sprintf(p, "\n "
|
103 |
|
|
"HighPoint HPT366/368/370/372/374\n");
|
104 |
|
|
for (i = 0; i < n_hpt_devs; i++) {
|
105 |
|
|
struct pci_dev *dev = hpt_devs[i];
|
106 |
|
|
unsigned long iobase = dev->resource[4].start;
|
107 |
|
|
u32 class_rev = hpt_revision(dev);
|
108 |
|
|
u8 c0, c1;
|
109 |
|
|
|
110 |
|
|
p += sprintf(p, "\nController: %d\n", i);
|
111 |
|
|
if(class_rev < 9)
|
112 |
|
|
p += sprintf(p, "Chipset: HPT%s\n", chipset_nums[class_rev]);
|
113 |
|
|
else
|
114 |
|
|
p += sprintf(p, "Chipset: HPT revision %d\n", class_rev);
|
115 |
|
|
p += sprintf(p, "--------------- Primary Channel "
|
116 |
|
|
"--------------- Secondary Channel "
|
117 |
|
|
"--------------\n");
|
118 |
|
|
|
119 |
|
|
/* get the bus master status registers */
|
120 |
|
|
c0 = inb(iobase + 0x2);
|
121 |
|
|
c1 = inb(iobase + 0xa);
|
122 |
|
|
p += sprintf(p, "Enabled: %s"
|
123 |
|
|
" %s\n",
|
124 |
|
|
(c0 & 0x80) ? "no" : "yes",
|
125 |
|
|
(c1 & 0x80) ? "no" : "yes");
|
126 |
|
|
|
127 |
|
|
if (hpt_minimum_revision(dev, 3)) {
|
128 |
|
|
u8 cbl;
|
129 |
|
|
cbl = inb(iobase + 0x7b);
|
130 |
|
|
outb(cbl | 1, iobase + 0x7b);
|
131 |
|
|
outb(cbl & ~1, iobase + 0x7b);
|
132 |
|
|
cbl = inb(iobase + 0x7a);
|
133 |
|
|
p += sprintf(p, "Cable: ATA-%d"
|
134 |
|
|
" ATA-%d\n",
|
135 |
|
|
(cbl & 0x02) ? 33 : 66,
|
136 |
|
|
(cbl & 0x01) ? 33 : 66);
|
137 |
|
|
p += sprintf(p, "\n");
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
p += sprintf(p, "--------------- drive0 --------- drive1 "
|
141 |
|
|
"------- drive0 ---------- drive1 -------\n");
|
142 |
|
|
p += sprintf(p, "DMA capable: %s %s"
|
143 |
|
|
" %s %s\n",
|
144 |
|
|
(c0 & 0x20) ? "yes" : "no ",
|
145 |
|
|
(c0 & 0x40) ? "yes" : "no ",
|
146 |
|
|
(c1 & 0x20) ? "yes" : "no ",
|
147 |
|
|
(c1 & 0x40) ? "yes" : "no ");
|
148 |
|
|
|
149 |
|
|
{
|
150 |
|
|
u8 c2, c3;
|
151 |
|
|
/* older revs don't have these registers mapped
|
152 |
|
|
* into io space */
|
153 |
|
|
pci_read_config_byte(dev, 0x43, &c0);
|
154 |
|
|
pci_read_config_byte(dev, 0x47, &c1);
|
155 |
|
|
pci_read_config_byte(dev, 0x4b, &c2);
|
156 |
|
|
pci_read_config_byte(dev, 0x4f, &c3);
|
157 |
|
|
|
158 |
|
|
p += sprintf(p, "Mode: %s %s"
|
159 |
|
|
" %s %s\n",
|
160 |
|
|
(c0 & 0x10) ? "UDMA" : (c0 & 0x20) ? "DMA " :
|
161 |
|
|
(c0 & 0x80) ? "PIO " : "off ",
|
162 |
|
|
(c1 & 0x10) ? "UDMA" : (c1 & 0x20) ? "DMA " :
|
163 |
|
|
(c1 & 0x80) ? "PIO " : "off ",
|
164 |
|
|
(c2 & 0x10) ? "UDMA" : (c2 & 0x20) ? "DMA " :
|
165 |
|
|
(c2 & 0x80) ? "PIO " : "off ",
|
166 |
|
|
(c3 & 0x10) ? "UDMA" : (c3 & 0x20) ? "DMA " :
|
167 |
|
|
(c3 & 0x80) ? "PIO " : "off ");
|
168 |
|
|
}
|
169 |
|
|
}
|
170 |
|
|
p += sprintf(p, "\n");
|
171 |
|
|
|
172 |
|
|
return p-buffer;/* => must be less than 4k! */
|
173 |
|
|
}
|
174 |
|
|
#endif /* defined(DISPLAY_HPT366_TIMINGS) && defined(CONFIG_PROC_FS) */
|
175 |
|
|
|
176 |
|
|
/*
|
177 |
|
|
* This wants fixing so that we do everything not by classrev
|
178 |
|
|
* (which breaks on the newest chips) but by creating an
|
179 |
|
|
* enumeration of chip variants and using that
|
180 |
|
|
*/
|
181 |
|
|
|
182 |
|
|
|
183 |
|
|
static u32 hpt_revision (struct pci_dev *dev)
|
184 |
|
|
{
|
185 |
|
|
u32 class_rev;
|
186 |
|
|
pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
|
187 |
|
|
class_rev &= 0xff;
|
188 |
|
|
|
189 |
|
|
switch(dev->device) {
|
190 |
|
|
/* Remap new 372N onto 372 */
|
191 |
|
|
case PCI_DEVICE_ID_TTI_HPT372N:
|
192 |
|
|
class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
|
193 |
|
|
case PCI_DEVICE_ID_TTI_HPT374:
|
194 |
|
|
class_rev = PCI_DEVICE_ID_TTI_HPT374; break;
|
195 |
|
|
case PCI_DEVICE_ID_TTI_HPT371:
|
196 |
|
|
class_rev = PCI_DEVICE_ID_TTI_HPT371; break;
|
197 |
|
|
case PCI_DEVICE_ID_TTI_HPT302:
|
198 |
|
|
class_rev = PCI_DEVICE_ID_TTI_HPT302; break;
|
199 |
|
|
case PCI_DEVICE_ID_TTI_HPT372:
|
200 |
|
|
class_rev = PCI_DEVICE_ID_TTI_HPT372; break;
|
201 |
|
|
default:
|
202 |
|
|
break;
|
203 |
|
|
}
|
204 |
|
|
return class_rev;
|
205 |
|
|
}
|
206 |
|
|
|
207 |
|
|
static u32 hpt_minimum_revision (struct pci_dev *dev, int revision)
|
208 |
|
|
{
|
209 |
|
|
unsigned int class_rev = hpt_revision(dev);
|
210 |
|
|
revision--;
|
211 |
|
|
return ((int) (class_rev > revision) ? 1 : 0);
|
212 |
|
|
}
|
213 |
|
|
|
214 |
|
|
static int check_in_drive_lists(ide_drive_t *drive, const char **list);
|
215 |
|
|
|
216 |
|
|
static u8 hpt3xx_ratemask (ide_drive_t *drive)
|
217 |
|
|
{
|
218 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
219 |
|
|
u8 mode = 0;
|
220 |
|
|
|
221 |
|
|
if (hpt_minimum_revision(dev, 8)) { /* HPT374 */
|
222 |
|
|
mode = (HPT374_ALLOW_ATA133_6) ? 4 : 3;
|
223 |
|
|
} else if (hpt_minimum_revision(dev, 7)) { /* HPT371 */
|
224 |
|
|
mode = (HPT371_ALLOW_ATA133_6) ? 4 : 3;
|
225 |
|
|
} else if (hpt_minimum_revision(dev, 6)) { /* HPT302 */
|
226 |
|
|
mode = (HPT302_ALLOW_ATA133_6) ? 4 : 3;
|
227 |
|
|
} else if (hpt_minimum_revision(dev, 5)) { /* HPT372 */
|
228 |
|
|
mode = (HPT372_ALLOW_ATA133_6) ? 4 : 3;
|
229 |
|
|
} else if (hpt_minimum_revision(dev, 4)) { /* HPT370A */
|
230 |
|
|
mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
|
231 |
|
|
} else if (hpt_minimum_revision(dev, 3)) { /* HPT370 */
|
232 |
|
|
mode = (HPT370_ALLOW_ATA100_5) ? 3 : 2;
|
233 |
|
|
mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : mode;
|
234 |
|
|
} else { /* HPT366 and HPT368 */
|
235 |
|
|
mode = (check_in_drive_lists(drive, bad_ata33)) ? 0 : 2;
|
236 |
|
|
}
|
237 |
|
|
if (!eighty_ninty_three(drive) && (mode))
|
238 |
|
|
mode = min(mode, (u8)1);
|
239 |
|
|
return mode;
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
/*
|
243 |
|
|
* Note for the future; the SATA hpt37x we must set
|
244 |
|
|
* either PIO or UDMA modes 0,4,5
|
245 |
|
|
*/
|
246 |
|
|
|
247 |
|
|
static u8 hpt3xx_ratefilter (ide_drive_t *drive, u8 speed)
|
248 |
|
|
{
|
249 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
250 |
|
|
u8 mode = hpt3xx_ratemask(drive);
|
251 |
|
|
|
252 |
|
|
if (drive->media != ide_disk)
|
253 |
|
|
return min(speed, (u8)XFER_PIO_4);
|
254 |
|
|
|
255 |
|
|
switch(mode) {
|
256 |
|
|
case 0x04:
|
257 |
|
|
speed = min(speed, (u8)XFER_UDMA_6);
|
258 |
|
|
break;
|
259 |
|
|
case 0x03:
|
260 |
|
|
speed = min(speed, (u8)XFER_UDMA_5);
|
261 |
|
|
if (hpt_minimum_revision(dev, 5))
|
262 |
|
|
break;
|
263 |
|
|
if (check_in_drive_lists(drive, bad_ata100_5))
|
264 |
|
|
speed = min(speed, (u8)XFER_UDMA_4);
|
265 |
|
|
break;
|
266 |
|
|
case 0x02:
|
267 |
|
|
speed = min(speed, (u8)XFER_UDMA_4);
|
268 |
|
|
/*
|
269 |
|
|
* CHECK ME, Does this need to be set to 5 ??
|
270 |
|
|
*/
|
271 |
|
|
if (hpt_minimum_revision(dev, 3))
|
272 |
|
|
break;
|
273 |
|
|
if ((check_in_drive_lists(drive, bad_ata66_4)) ||
|
274 |
|
|
(!(HPT366_ALLOW_ATA66_4)))
|
275 |
|
|
speed = min(speed, (u8)XFER_UDMA_3);
|
276 |
|
|
if ((check_in_drive_lists(drive, bad_ata66_3)) ||
|
277 |
|
|
(!(HPT366_ALLOW_ATA66_3)))
|
278 |
|
|
speed = min(speed, (u8)XFER_UDMA_2);
|
279 |
|
|
break;
|
280 |
|
|
case 0x01:
|
281 |
|
|
speed = min(speed, (u8)XFER_UDMA_2);
|
282 |
|
|
/*
|
283 |
|
|
* CHECK ME, Does this need to be set to 5 ??
|
284 |
|
|
*/
|
285 |
|
|
if (hpt_minimum_revision(dev, 3))
|
286 |
|
|
break;
|
287 |
|
|
if (check_in_drive_lists(drive, bad_ata33))
|
288 |
|
|
speed = min(speed, (u8)XFER_MW_DMA_2);
|
289 |
|
|
break;
|
290 |
|
|
case 0x00:
|
291 |
|
|
default:
|
292 |
|
|
speed = min(speed, (u8)XFER_MW_DMA_2);
|
293 |
|
|
break;
|
294 |
|
|
}
|
295 |
|
|
return speed;
|
296 |
|
|
}
|
297 |
|
|
|
298 |
|
|
static int check_in_drive_lists (ide_drive_t *drive, const char **list)
|
299 |
|
|
{
|
300 |
|
|
struct hd_driveid *id = drive->id;
|
301 |
|
|
|
302 |
|
|
if (quirk_drives == list) {
|
303 |
|
|
while (*list)
|
304 |
|
|
if (strstr(id->model, *list++))
|
305 |
|
|
return 1;
|
306 |
|
|
} else {
|
307 |
|
|
while (*list)
|
308 |
|
|
if (!strcmp(*list++,id->model))
|
309 |
|
|
return 1;
|
310 |
|
|
}
|
311 |
|
|
return 0;
|
312 |
|
|
}
|
313 |
|
|
|
314 |
|
|
static unsigned int pci_bus_clock_list (u8 speed, struct chipset_bus_clock_list_entry * chipset_table)
|
315 |
|
|
{
|
316 |
|
|
for ( ; chipset_table->xfer_speed ; chipset_table++)
|
317 |
|
|
if (chipset_table->xfer_speed == speed)
|
318 |
|
|
return chipset_table->chipset_settings;
|
319 |
|
|
return chipset_table->chipset_settings;
|
320 |
|
|
}
|
321 |
|
|
|
322 |
|
|
static void hpt366_tune_chipset (ide_drive_t *drive, u8 xferspeed)
|
323 |
|
|
{
|
324 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
325 |
|
|
u8 speed = hpt3xx_ratefilter(drive, xferspeed);
|
326 |
|
|
// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed);
|
327 |
|
|
u8 regtime = (drive->select.b.unit & 0x01) ? 0x44 : 0x40;
|
328 |
|
|
u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
|
329 |
|
|
u8 drive_fast = 0;
|
330 |
|
|
u32 reg1 = 0, reg2 = 0;
|
331 |
|
|
|
332 |
|
|
/*
|
333 |
|
|
* Disable the "fast interrupt" prediction.
|
334 |
|
|
*/
|
335 |
|
|
pci_read_config_byte(dev, regfast, &drive_fast);
|
336 |
|
|
#if 0
|
337 |
|
|
if (drive_fast & 0x02)
|
338 |
|
|
pci_write_config_byte(dev, regfast, drive_fast & ~0x20);
|
339 |
|
|
#else
|
340 |
|
|
if (drive_fast & 0x80)
|
341 |
|
|
pci_write_config_byte(dev, regfast, drive_fast & ~0x80);
|
342 |
|
|
#endif
|
343 |
|
|
|
344 |
|
|
reg2 = pci_bus_clock_list(speed,
|
345 |
|
|
(struct chipset_bus_clock_list_entry *) pci_get_drvdata(dev));
|
346 |
|
|
/*
|
347 |
|
|
* Disable on-chip PIO FIFO/buffer
|
348 |
|
|
* (to avoid problems handling I/O errors later)
|
349 |
|
|
*/
|
350 |
|
|
pci_read_config_dword(dev, regtime, ®1);
|
351 |
|
|
if (speed >= XFER_MW_DMA_0) {
|
352 |
|
|
reg2 = (reg2 & ~0xc0000000) | (reg1 & 0xc0000000);
|
353 |
|
|
} else {
|
354 |
|
|
reg2 = (reg2 & ~0x30070000) | (reg1 & 0x30070000);
|
355 |
|
|
}
|
356 |
|
|
reg2 &= ~0x80000000;
|
357 |
|
|
|
358 |
|
|
pci_write_config_dword(dev, regtime, reg2);
|
359 |
|
|
}
|
360 |
|
|
|
361 |
|
|
static void hpt368_tune_chipset (ide_drive_t *drive, u8 speed)
|
362 |
|
|
{
|
363 |
|
|
hpt366_tune_chipset(drive, speed);
|
364 |
|
|
}
|
365 |
|
|
|
366 |
|
|
static void hpt370_tune_chipset (ide_drive_t *drive, u8 xferspeed)
|
367 |
|
|
{
|
368 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
369 |
|
|
u8 speed = hpt3xx_ratefilter(drive, xferspeed);
|
370 |
|
|
// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed);
|
371 |
|
|
u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
|
372 |
|
|
u8 drive_pci = 0x40 + (drive->dn * 4);
|
373 |
|
|
u8 new_fast = 0, drive_fast = 0;
|
374 |
|
|
u32 list_conf = 0, drive_conf = 0;
|
375 |
|
|
u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
|
376 |
|
|
|
377 |
|
|
/*
|
378 |
|
|
* Disable the "fast interrupt" prediction.
|
379 |
|
|
* don't holdoff on interrupts. (== 0x01 despite what the docs say)
|
380 |
|
|
*/
|
381 |
|
|
pci_read_config_byte(dev, regfast, &drive_fast);
|
382 |
|
|
new_fast = drive_fast;
|
383 |
|
|
if (new_fast & 0x02)
|
384 |
|
|
new_fast &= ~0x02;
|
385 |
|
|
|
386 |
|
|
#ifdef HPT_DELAY_INTERRUPT
|
387 |
|
|
if (new_fast & 0x01)
|
388 |
|
|
new_fast &= ~0x01;
|
389 |
|
|
#else
|
390 |
|
|
if ((new_fast & 0x01) == 0)
|
391 |
|
|
new_fast |= 0x01;
|
392 |
|
|
#endif
|
393 |
|
|
if (new_fast != drive_fast)
|
394 |
|
|
pci_write_config_byte(dev, regfast, new_fast);
|
395 |
|
|
|
396 |
|
|
list_conf = pci_bus_clock_list(speed,
|
397 |
|
|
(struct chipset_bus_clock_list_entry *)
|
398 |
|
|
pci_get_drvdata(dev));
|
399 |
|
|
|
400 |
|
|
pci_read_config_dword(dev, drive_pci, &drive_conf);
|
401 |
|
|
list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
|
402 |
|
|
|
403 |
|
|
if (speed < XFER_MW_DMA_0) {
|
404 |
|
|
list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
pci_write_config_dword(dev, drive_pci, list_conf);
|
408 |
|
|
}
|
409 |
|
|
|
410 |
|
|
static void hpt372_tune_chipset (ide_drive_t *drive, u8 xferspeed)
|
411 |
|
|
{
|
412 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
413 |
|
|
u8 speed = hpt3xx_ratefilter(drive, xferspeed);
|
414 |
|
|
// u8 speed = ide_rate_filter(hpt3xx_ratemask(drive), xferspeed);
|
415 |
|
|
u8 regfast = (HWIF(drive)->channel) ? 0x55 : 0x51;
|
416 |
|
|
u8 drive_fast = 0, drive_pci = 0x40 + (drive->dn * 4);
|
417 |
|
|
u32 list_conf = 0, drive_conf = 0;
|
418 |
|
|
u32 conf_mask = (speed >= XFER_MW_DMA_0) ? 0xc0000000 : 0x30070000;
|
419 |
|
|
/*
|
420 |
|
|
* Disable the "fast interrupt" prediction.
|
421 |
|
|
* don't holdoff on interrupts. (== 0x01 despite what the docs say)
|
422 |
|
|
*/
|
423 |
|
|
pci_read_config_byte(dev, regfast, &drive_fast);
|
424 |
|
|
drive_fast &= ~0x07;
|
425 |
|
|
pci_write_config_byte(dev, regfast, drive_fast);
|
426 |
|
|
|
427 |
|
|
list_conf = pci_bus_clock_list(speed,
|
428 |
|
|
(struct chipset_bus_clock_list_entry *)
|
429 |
|
|
pci_get_drvdata(dev));
|
430 |
|
|
pci_read_config_dword(dev, drive_pci, &drive_conf);
|
431 |
|
|
list_conf = (list_conf & ~conf_mask) | (drive_conf & conf_mask);
|
432 |
|
|
if (speed < XFER_MW_DMA_0)
|
433 |
|
|
list_conf &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
|
434 |
|
|
pci_write_config_dword(dev, drive_pci, list_conf);
|
435 |
|
|
}
|
436 |
|
|
|
437 |
|
|
static void hpt374_tune_chipset (ide_drive_t *drive, u8 speed)
|
438 |
|
|
{
|
439 |
|
|
hpt372_tune_chipset(drive, speed);
|
440 |
|
|
}
|
441 |
|
|
|
442 |
|
|
static int hpt3xx_tune_chipset (ide_drive_t *drive, u8 speed)
|
443 |
|
|
{
|
444 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
445 |
|
|
|
446 |
|
|
if (hpt_minimum_revision(dev, 8))
|
447 |
|
|
hpt374_tune_chipset(drive, speed);
|
448 |
|
|
#if 0
|
449 |
|
|
else if (hpt_minimum_revision(dev, 7))
|
450 |
|
|
hpt371_tune_chipset(drive, speed);
|
451 |
|
|
else if (hpt_minimum_revision(dev, 6))
|
452 |
|
|
hpt302_tune_chipset(drive, speed);
|
453 |
|
|
#endif
|
454 |
|
|
else if (hpt_minimum_revision(dev, 5))
|
455 |
|
|
hpt372_tune_chipset(drive, speed);
|
456 |
|
|
else if (hpt_minimum_revision(dev, 3))
|
457 |
|
|
hpt370_tune_chipset(drive, speed);
|
458 |
|
|
else if (hpt_minimum_revision(dev, 2))
|
459 |
|
|
hpt368_tune_chipset(drive, speed);
|
460 |
|
|
else
|
461 |
|
|
hpt366_tune_chipset(drive, speed);
|
462 |
|
|
|
463 |
|
|
return ((int) ide_config_drive_speed(drive, speed));
|
464 |
|
|
}
|
465 |
|
|
|
466 |
|
|
static void hpt3xx_tune_drive (ide_drive_t *drive, u8 pio)
|
467 |
|
|
{
|
468 |
|
|
pio = ide_get_best_pio_mode(drive, pio, 5, NULL);
|
469 |
|
|
(void) hpt3xx_tune_chipset(drive, (XFER_PIO_0 + pio));
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
/*
|
473 |
|
|
* This allows the configuration of ide_pci chipset registers
|
474 |
|
|
* for cards that learn about the drive's UDMA, DMA, PIO capabilities
|
475 |
|
|
* after the drive is reported by the OS. Initally for designed for
|
476 |
|
|
* HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
|
477 |
|
|
*
|
478 |
|
|
* check_in_drive_lists(drive, bad_ata66_4)
|
479 |
|
|
* check_in_drive_lists(drive, bad_ata66_3)
|
480 |
|
|
* check_in_drive_lists(drive, bad_ata33)
|
481 |
|
|
*
|
482 |
|
|
*/
|
483 |
|
|
static int config_chipset_for_dma (ide_drive_t *drive)
|
484 |
|
|
{
|
485 |
|
|
u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
|
486 |
|
|
|
487 |
|
|
if (!speed)
|
488 |
|
|
return 0;
|
489 |
|
|
|
490 |
|
|
if (pci_get_drvdata(HWIF(drive)->pci_dev) == NULL)
|
491 |
|
|
return 0;
|
492 |
|
|
|
493 |
|
|
(void) hpt3xx_tune_chipset(drive, speed);
|
494 |
|
|
return ide_dma_enable(drive);
|
495 |
|
|
}
|
496 |
|
|
|
497 |
|
|
static int hpt3xx_quirkproc (ide_drive_t *drive)
|
498 |
|
|
{
|
499 |
|
|
return ((int) check_in_drive_lists(drive, quirk_drives));
|
500 |
|
|
}
|
501 |
|
|
|
502 |
|
|
static void hpt3xx_intrproc (ide_drive_t *drive)
|
503 |
|
|
{
|
504 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
505 |
|
|
|
506 |
|
|
if (drive->quirk_list)
|
507 |
|
|
return;
|
508 |
|
|
/* drives in the quirk_list may not like intr setups/cleanups */
|
509 |
|
|
hwif->OUTB(drive->ctl|2, IDE_CONTROL_REG);
|
510 |
|
|
}
|
511 |
|
|
|
512 |
|
|
static void hpt3xx_maskproc (ide_drive_t *drive, int mask)
|
513 |
|
|
{
|
514 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
515 |
|
|
|
516 |
|
|
if (drive->quirk_list) {
|
517 |
|
|
if (hpt_minimum_revision(dev,3)) {
|
518 |
|
|
u8 reg5a = 0;
|
519 |
|
|
pci_read_config_byte(dev, 0x5a, ®5a);
|
520 |
|
|
if (((reg5a & 0x10) >> 4) != mask)
|
521 |
|
|
pci_write_config_byte(dev, 0x5a, mask ? (reg5a | 0x10) : (reg5a & ~0x10));
|
522 |
|
|
} else {
|
523 |
|
|
if (mask) {
|
524 |
|
|
disable_irq(HWIF(drive)->irq);
|
525 |
|
|
} else {
|
526 |
|
|
enable_irq(HWIF(drive)->irq);
|
527 |
|
|
}
|
528 |
|
|
}
|
529 |
|
|
} else {
|
530 |
|
|
if (IDE_CONTROL_REG)
|
531 |
|
|
HWIF(drive)->OUTB(mask ? (drive->ctl | 2) :
|
532 |
|
|
(drive->ctl & ~2),
|
533 |
|
|
IDE_CONTROL_REG);
|
534 |
|
|
}
|
535 |
|
|
}
|
536 |
|
|
|
537 |
|
|
static int hpt366_config_drive_xfer_rate (ide_drive_t *drive)
|
538 |
|
|
{
|
539 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
540 |
|
|
struct hd_driveid *id = drive->id;
|
541 |
|
|
|
542 |
|
|
drive->init_speed = 0;
|
543 |
|
|
|
544 |
|
|
if ((id->capability & 1) && drive->autodma) {
|
545 |
|
|
/* Consult the list of known "bad" drives */
|
546 |
|
|
if (hwif->ide_dma_bad_drive(drive))
|
547 |
|
|
goto fast_ata_pio;
|
548 |
|
|
if (id->field_valid & 4) {
|
549 |
|
|
if (id->dma_ultra & hwif->ultra_mask) {
|
550 |
|
|
/* Force if Capable UltraDMA */
|
551 |
|
|
int dma = config_chipset_for_dma(drive);
|
552 |
|
|
if ((id->field_valid & 2) && !dma)
|
553 |
|
|
goto try_dma_modes;
|
554 |
|
|
}
|
555 |
|
|
} else if (id->field_valid & 2) {
|
556 |
|
|
try_dma_modes:
|
557 |
|
|
if (id->dma_mword & hwif->mwdma_mask) {
|
558 |
|
|
/* Force if Capable regular DMA modes */
|
559 |
|
|
if (!config_chipset_for_dma(drive))
|
560 |
|
|
goto no_dma_set;
|
561 |
|
|
}
|
562 |
|
|
} else if (hwif->ide_dma_good_drive(drive) &&
|
563 |
|
|
(id->eide_dma_time < 150)) {
|
564 |
|
|
/* Consult the list of known "good" drives */
|
565 |
|
|
if (!config_chipset_for_dma(drive))
|
566 |
|
|
goto no_dma_set;
|
567 |
|
|
} else {
|
568 |
|
|
goto fast_ata_pio;
|
569 |
|
|
}
|
570 |
|
|
} else if ((id->capability & 8) || (id->field_valid & 2)) {
|
571 |
|
|
fast_ata_pio:
|
572 |
|
|
no_dma_set:
|
573 |
|
|
hpt3xx_tune_drive(drive, 5);
|
574 |
|
|
return hwif->ide_dma_off_quietly(drive);
|
575 |
|
|
}
|
576 |
|
|
return hwif->ide_dma_on(drive);
|
577 |
|
|
}
|
578 |
|
|
|
579 |
|
|
/*
|
580 |
|
|
* This is specific to the HPT366 UDMA bios chipset
|
581 |
|
|
* by HighPoint|Triones Technologies, Inc.
|
582 |
|
|
*/
|
583 |
|
|
static int hpt366_ide_dma_lostirq (ide_drive_t *drive)
|
584 |
|
|
{
|
585 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
586 |
|
|
u8 reg50h = 0, reg52h = 0, reg5ah = 0;
|
587 |
|
|
|
588 |
|
|
pci_read_config_byte(dev, 0x50, ®50h);
|
589 |
|
|
pci_read_config_byte(dev, 0x52, ®52h);
|
590 |
|
|
pci_read_config_byte(dev, 0x5a, ®5ah);
|
591 |
|
|
printk("%s: (%s) reg50h=0x%02x, reg52h=0x%02x, reg5ah=0x%02x\n",
|
592 |
|
|
drive->name, __FUNCTION__, reg50h, reg52h, reg5ah);
|
593 |
|
|
if (reg5ah & 0x10)
|
594 |
|
|
pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
|
595 |
|
|
#if 0
|
596 |
|
|
/* how about we flush and reset, mmmkay? */
|
597 |
|
|
pci_write_config_byte(dev, 0x51, 0x1F);
|
598 |
|
|
/* fall through to a reset */
|
599 |
|
|
case ide_dma_begin:
|
600 |
|
|
case ide_dma_end:
|
601 |
|
|
/* reset the chips state over and over.. */
|
602 |
|
|
pci_write_config_byte(dev, 0x51, 0x13);
|
603 |
|
|
#endif
|
604 |
|
|
return __ide_dma_lostirq(drive);
|
605 |
|
|
}
|
606 |
|
|
|
607 |
|
|
static void hpt370_clear_engine (ide_drive_t *drive)
|
608 |
|
|
{
|
609 |
|
|
u8 regstate = HWIF(drive)->channel ? 0x54 : 0x50;
|
610 |
|
|
pci_write_config_byte(HWIF(drive)->pci_dev, regstate, 0x37);
|
611 |
|
|
udelay(10);
|
612 |
|
|
}
|
613 |
|
|
|
614 |
|
|
static int hpt370_ide_dma_begin (ide_drive_t *drive)
|
615 |
|
|
{
|
616 |
|
|
#ifdef HPT_RESET_STATE_ENGINE
|
617 |
|
|
hpt370_clear_engine(drive);
|
618 |
|
|
#endif
|
619 |
|
|
return __ide_dma_begin(drive);
|
620 |
|
|
}
|
621 |
|
|
|
622 |
|
|
static int hpt370_ide_dma_end (ide_drive_t *drive)
|
623 |
|
|
{
|
624 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
625 |
|
|
u8 dma_stat = hwif->INB(hwif->dma_status);
|
626 |
|
|
|
627 |
|
|
if (dma_stat & 0x01) {
|
628 |
|
|
/* wait a little */
|
629 |
|
|
udelay(20);
|
630 |
|
|
dma_stat = hwif->INB(hwif->dma_status);
|
631 |
|
|
}
|
632 |
|
|
if ((dma_stat & 0x01) != 0)
|
633 |
|
|
/* fallthrough */
|
634 |
|
|
(void) HWIF(drive)->ide_dma_timeout(drive);
|
635 |
|
|
|
636 |
|
|
return __ide_dma_end(drive);
|
637 |
|
|
}
|
638 |
|
|
|
639 |
|
|
static void hpt370_lostirq_timeout (ide_drive_t *drive)
|
640 |
|
|
{
|
641 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
642 |
|
|
u8 bfifo = 0, reginfo = hwif->channel ? 0x56 : 0x52;
|
643 |
|
|
u8 dma_stat = 0, dma_cmd = 0;
|
644 |
|
|
|
645 |
|
|
pci_read_config_byte(HWIF(drive)->pci_dev, reginfo, &bfifo);
|
646 |
|
|
printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
|
647 |
|
|
hpt370_clear_engine(drive);
|
648 |
|
|
/* get dma command mode */
|
649 |
|
|
dma_cmd = hwif->INB(hwif->dma_command);
|
650 |
|
|
/* stop dma */
|
651 |
|
|
hwif->OUTB(dma_cmd & ~0x1, hwif->dma_command);
|
652 |
|
|
dma_stat = hwif->INB(hwif->dma_status);
|
653 |
|
|
/* clear errors */
|
654 |
|
|
hwif->OUTB(dma_stat | 0x6, hwif->dma_status);
|
655 |
|
|
}
|
656 |
|
|
|
657 |
|
|
static int hpt370_ide_dma_timeout (ide_drive_t *drive)
|
658 |
|
|
{
|
659 |
|
|
hpt370_lostirq_timeout(drive);
|
660 |
|
|
hpt370_clear_engine(drive);
|
661 |
|
|
return __ide_dma_timeout(drive);
|
662 |
|
|
}
|
663 |
|
|
|
664 |
|
|
static int hpt370_ide_dma_lostirq (ide_drive_t *drive)
|
665 |
|
|
{
|
666 |
|
|
hpt370_lostirq_timeout(drive);
|
667 |
|
|
hpt370_clear_engine(drive);
|
668 |
|
|
return __ide_dma_lostirq(drive);
|
669 |
|
|
}
|
670 |
|
|
|
671 |
|
|
/* returns 1 if DMA IRQ issued, 0 otherwise */
|
672 |
|
|
static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
|
673 |
|
|
{
|
674 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
675 |
|
|
u16 bfifo = 0;
|
676 |
|
|
u8 reginfo = hwif->channel ? 0x56 : 0x52;
|
677 |
|
|
u8 dma_stat;
|
678 |
|
|
|
679 |
|
|
pci_read_config_word(hwif->pci_dev, reginfo, &bfifo);
|
680 |
|
|
if (bfifo & 0x1FF) {
|
681 |
|
|
// printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
|
682 |
|
|
return 0;
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
dma_stat = hwif->INB(hwif->dma_status);
|
686 |
|
|
/* return 1 if INTR asserted */
|
687 |
|
|
if ((dma_stat & 4) == 4)
|
688 |
|
|
return 1;
|
689 |
|
|
|
690 |
|
|
if (!drive->waiting_for_dma)
|
691 |
|
|
printk(KERN_WARNING "%s: (%s) called while not waiting\n",
|
692 |
|
|
drive->name, __FUNCTION__);
|
693 |
|
|
return 0;
|
694 |
|
|
}
|
695 |
|
|
|
696 |
|
|
static int hpt374_ide_dma_end (ide_drive_t *drive)
|
697 |
|
|
{
|
698 |
|
|
struct pci_dev *dev = HWIF(drive)->pci_dev;
|
699 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
700 |
|
|
u8 msc_stat = 0, mscreg = hwif->channel ? 0x54 : 0x50;
|
701 |
|
|
u8 bwsr_stat = 0, bwsr_mask = hwif->channel ? 0x02 : 0x01;
|
702 |
|
|
|
703 |
|
|
pci_read_config_byte(dev, 0x6a, &bwsr_stat);
|
704 |
|
|
pci_read_config_byte(dev, mscreg, &msc_stat);
|
705 |
|
|
if ((bwsr_stat & bwsr_mask) == bwsr_mask)
|
706 |
|
|
pci_write_config_byte(dev, mscreg, msc_stat|0x30);
|
707 |
|
|
return __ide_dma_end(drive);
|
708 |
|
|
}
|
709 |
|
|
|
710 |
|
|
/**
|
711 |
|
|
* hpt372n_set_clock - perform clock switching dance
|
712 |
|
|
* @drive: Drive to switch
|
713 |
|
|
* @mode: Switching mode (0x21 for write, 0x23 otherwise)
|
714 |
|
|
*
|
715 |
|
|
* Switch the DPLL clock on the HPT372N devices. This is a
|
716 |
|
|
* right mess.
|
717 |
|
|
*/
|
718 |
|
|
|
719 |
|
|
static void hpt372n_set_clock(ide_drive_t *drive, int mode)
|
720 |
|
|
{
|
721 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
722 |
|
|
|
723 |
|
|
/* FIXME: should we check for DMA active and BUG() */
|
724 |
|
|
/* Tristate the bus */
|
725 |
|
|
outb(0x80, hwif->dma_base+0x73);
|
726 |
|
|
outb(0x80, hwif->dma_base+0x77);
|
727 |
|
|
|
728 |
|
|
/* Switch clock and reset channels */
|
729 |
|
|
outb(mode, hwif->dma_base+0x7B);
|
730 |
|
|
outb(0xC0, hwif->dma_base+0x79);
|
731 |
|
|
|
732 |
|
|
/* Reset state machines */
|
733 |
|
|
outb(0x37, hwif->dma_base+0x70);
|
734 |
|
|
outb(0x37, hwif->dma_base+0x74);
|
735 |
|
|
|
736 |
|
|
/* Complete reset */
|
737 |
|
|
outb(0x00, hwif->dma_base+0x79);
|
738 |
|
|
|
739 |
|
|
/* Reconnect channels to bus */
|
740 |
|
|
outb(0x00, hwif->dma_base+0x73);
|
741 |
|
|
outb(0x00, hwif->dma_base+0x79);
|
742 |
|
|
}
|
743 |
|
|
|
744 |
|
|
/**
|
745 |
|
|
* hpt372n_rw_disk - wrapper for I/O
|
746 |
|
|
* @drive: drive for command
|
747 |
|
|
* @rq: block request structure
|
748 |
|
|
* @block: block number
|
749 |
|
|
*
|
750 |
|
|
* This is called when a disk I/O is issued to the 372N instead
|
751 |
|
|
* of the default functionality. We need it because of the clock
|
752 |
|
|
* switching
|
753 |
|
|
*
|
754 |
|
|
*/
|
755 |
|
|
|
756 |
|
|
static ide_startstop_t hpt372n_rw_disk(ide_drive_t *drive, struct request *rq, unsigned long block)
|
757 |
|
|
{
|
758 |
|
|
int wantclock;
|
759 |
|
|
|
760 |
|
|
if(rq_data_dir(rq) == READ)
|
761 |
|
|
wantclock = 0x21;
|
762 |
|
|
else
|
763 |
|
|
wantclock = 0x23;
|
764 |
|
|
|
765 |
|
|
if(HWIF(drive)->config_data != wantclock)
|
766 |
|
|
{
|
767 |
|
|
hpt372n_set_clock(drive, wantclock);
|
768 |
|
|
HWIF(drive)->config_data = wantclock;
|
769 |
|
|
}
|
770 |
|
|
return __ide_do_rw_disk(drive, rq, block);
|
771 |
|
|
}
|
772 |
|
|
|
773 |
|
|
/*
|
774 |
|
|
* Since SUN Cobalt is attempting to do this operation, I should disclose
|
775 |
|
|
* this has been a long time ago Thu Jul 27 16:40:57 2000 was the patch date
|
776 |
|
|
* HOTSWAP ATA Infrastructure.
|
777 |
|
|
*/
|
778 |
|
|
|
779 |
|
|
static void hpt3xx_reset (ide_drive_t *drive)
|
780 |
|
|
{
|
781 |
|
|
#if 0
|
782 |
|
|
unsigned long high_16 = pci_resource_start(HWIF(drive)->pci_dev, 4);
|
783 |
|
|
u8 reset = (HWIF(drive)->channel) ? 0x80 : 0x40;
|
784 |
|
|
u8 reg59h = 0;
|
785 |
|
|
|
786 |
|
|
pci_read_config_byte(HWIF(drive)->pci_dev, 0x59, ®59h);
|
787 |
|
|
pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h|reset);
|
788 |
|
|
pci_write_config_byte(HWIF(drive)->pci_dev, 0x59, reg59h);
|
789 |
|
|
#endif
|
790 |
|
|
}
|
791 |
|
|
|
792 |
|
|
static int hpt3xx_tristate (ide_drive_t * drive, int state)
|
793 |
|
|
{
|
794 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
795 |
|
|
struct pci_dev *dev = hwif->pci_dev;
|
796 |
|
|
u8 reg59h = 0, reset = (hwif->channel) ? 0x80 : 0x40;
|
797 |
|
|
u8 regXXh = 0, state_reg= (hwif->channel) ? 0x57 : 0x53;
|
798 |
|
|
|
799 |
|
|
if (!hwif)
|
800 |
|
|
return -EINVAL;
|
801 |
|
|
|
802 |
|
|
// hwif->bus_state = state;
|
803 |
|
|
|
804 |
|
|
pci_read_config_byte(dev, 0x59, ®59h);
|
805 |
|
|
pci_read_config_byte(dev, state_reg, ®XXh);
|
806 |
|
|
|
807 |
|
|
switch(state)
|
808 |
|
|
{
|
809 |
|
|
case BUSSTATE_ON:
|
810 |
|
|
(void) ide_do_reset(drive);
|
811 |
|
|
pci_write_config_byte(dev, state_reg, regXXh|0x80);
|
812 |
|
|
pci_write_config_byte(dev, 0x59, reg59h|reset);
|
813 |
|
|
break;
|
814 |
|
|
case BUSSTATE_OFF:
|
815 |
|
|
pci_write_config_byte(dev, 0x59, reg59h & ~(reset));
|
816 |
|
|
pci_write_config_byte(dev, state_reg, regXXh & ~(0x80));
|
817 |
|
|
(void) ide_do_reset(drive);
|
818 |
|
|
break;
|
819 |
|
|
default:
|
820 |
|
|
return -EINVAL;
|
821 |
|
|
}
|
822 |
|
|
return 0;
|
823 |
|
|
}
|
824 |
|
|
|
825 |
|
|
/*
|
826 |
|
|
* set/get power state for a drive.
|
827 |
|
|
* turning the power off does the following things:
|
828 |
|
|
* 1) soft-reset the drive
|
829 |
|
|
* 2) tri-states the ide bus
|
830 |
|
|
*
|
831 |
|
|
* when we turn things back on, we need to re-initialize things.
|
832 |
|
|
*/
|
833 |
|
|
#define TRISTATE_BIT 0x8000
|
834 |
|
|
static int hpt370_busproc(ide_drive_t * drive, int state)
|
835 |
|
|
{
|
836 |
|
|
ide_hwif_t *hwif = HWIF(drive);
|
837 |
|
|
struct pci_dev *dev = hwif->pci_dev;
|
838 |
|
|
u8 tristate = 0, resetmask = 0, bus_reg = 0;
|
839 |
|
|
u16 tri_reg;
|
840 |
|
|
|
841 |
|
|
if (!hwif)
|
842 |
|
|
return -EINVAL;
|
843 |
|
|
|
844 |
|
|
hwif->bus_state = state;
|
845 |
|
|
|
846 |
|
|
if (hwif->channel) {
|
847 |
|
|
/* secondary channel */
|
848 |
|
|
tristate = 0x56;
|
849 |
|
|
resetmask = 0x80;
|
850 |
|
|
} else {
|
851 |
|
|
/* primary channel */
|
852 |
|
|
tristate = 0x52;
|
853 |
|
|
resetmask = 0x40;
|
854 |
|
|
}
|
855 |
|
|
|
856 |
|
|
/* grab status */
|
857 |
|
|
pci_read_config_word(dev, tristate, &tri_reg);
|
858 |
|
|
pci_read_config_byte(dev, 0x59, &bus_reg);
|
859 |
|
|
|
860 |
|
|
/* set the state. we don't set it if we don't need to do so.
|
861 |
|
|
* make sure that the drive knows that it has failed if it's off */
|
862 |
|
|
switch (state) {
|
863 |
|
|
case BUSSTATE_ON:
|
864 |
|
|
hwif->drives[0].failures = 0;
|
865 |
|
|
hwif->drives[1].failures = 0;
|
866 |
|
|
if ((bus_reg & resetmask) == 0)
|
867 |
|
|
return 0;
|
868 |
|
|
tri_reg &= ~TRISTATE_BIT;
|
869 |
|
|
bus_reg &= ~resetmask;
|
870 |
|
|
break;
|
871 |
|
|
case BUSSTATE_OFF:
|
872 |
|
|
hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
|
873 |
|
|
hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
|
874 |
|
|
if ((tri_reg & TRISTATE_BIT) == 0 && (bus_reg & resetmask))
|
875 |
|
|
return 0;
|
876 |
|
|
tri_reg &= ~TRISTATE_BIT;
|
877 |
|
|
bus_reg |= resetmask;
|
878 |
|
|
break;
|
879 |
|
|
case BUSSTATE_TRISTATE:
|
880 |
|
|
hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
|
881 |
|
|
hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
|
882 |
|
|
if ((tri_reg & TRISTATE_BIT) && (bus_reg & resetmask))
|
883 |
|
|
return 0;
|
884 |
|
|
tri_reg |= TRISTATE_BIT;
|
885 |
|
|
bus_reg |= resetmask;
|
886 |
|
|
break;
|
887 |
|
|
default:
|
888 |
|
|
return -EINVAL;
|
889 |
|
|
}
|
890 |
|
|
pci_write_config_byte(dev, 0x59, bus_reg);
|
891 |
|
|
pci_write_config_word(dev, tristate, tri_reg);
|
892 |
|
|
|
893 |
|
|
return 0;
|
894 |
|
|
}
|
895 |
|
|
|
896 |
|
|
static int __init init_hpt37x(struct pci_dev *dev)
|
897 |
|
|
{
|
898 |
|
|
int adjust, i;
|
899 |
|
|
u16 freq;
|
900 |
|
|
u32 pll;
|
901 |
|
|
u8 reg5bh;
|
902 |
|
|
u8 reg5ah;
|
903 |
|
|
unsigned long dmabase = pci_resource_start(dev, 4);
|
904 |
|
|
u8 did, rid;
|
905 |
|
|
int is_372n = 0;
|
906 |
|
|
#if 1
|
907 |
|
|
pci_read_config_byte(dev, 0x5a, ®5ah);
|
908 |
|
|
/* interrupt force enable */
|
909 |
|
|
pci_write_config_byte(dev, 0x5a, (reg5ah & ~0x10));
|
910 |
|
|
#endif
|
911 |
|
|
|
912 |
|
|
if(dmabase)
|
913 |
|
|
{
|
914 |
|
|
did = inb(dmabase + 0x22);
|
915 |
|
|
rid = inb(dmabase + 0x28);
|
916 |
|
|
|
917 |
|
|
if((did == 4 && rid == 6) || (did == 5 && rid > 1))
|
918 |
|
|
is_372n = 1;
|
919 |
|
|
}
|
920 |
|
|
|
921 |
|
|
/*
|
922 |
|
|
* default to pci clock. make sure MA15/16 are set to output
|
923 |
|
|
* to prevent drives having problems with 40-pin cables. Needed
|
924 |
|
|
* for some drives such as IBM-DTLA which will not enter ready
|
925 |
|
|
* state on reset when PDIAG is a input.
|
926 |
|
|
*
|
927 |
|
|
* ToDo: should we set 0x21 when using PLL mode ?
|
928 |
|
|
*/
|
929 |
|
|
pci_write_config_byte(dev, 0x5b, 0x23);
|
930 |
|
|
|
931 |
|
|
/*
|
932 |
|
|
* set up the PLL. we need to adjust it so that it's stable.
|
933 |
|
|
* freq = Tpll * 192 / Tpci
|
934 |
|
|
*
|
935 |
|
|
* Todo. For non x86 should probably check the dword is
|
936 |
|
|
* set to 0xABCDExxx indicating the BIOS saved f_CNT
|
937 |
|
|
*/
|
938 |
|
|
pci_read_config_word(dev, 0x78, &freq);
|
939 |
|
|
freq &= 0x1FF;
|
940 |
|
|
|
941 |
|
|
/*
|
942 |
|
|
* The 372N uses different PCI clock information and has
|
943 |
|
|
* some other complications
|
944 |
|
|
* On PCI33 timing we must clock switch
|
945 |
|
|
* On PCI66 timing we must NOT use the PCI clock
|
946 |
|
|
*
|
947 |
|
|
* Currently we always set up the PLL for the 372N
|
948 |
|
|
*/
|
949 |
|
|
|
950 |
|
|
pci_set_drvdata(dev, NULL);
|
951 |
|
|
|
952 |
|
|
if(is_372n)
|
953 |
|
|
{
|
954 |
|
|
printk(KERN_INFO "hpt: HPT372N detected, using 372N timing.\n");
|
955 |
|
|
if(freq < 0x55)
|
956 |
|
|
pll = F_LOW_PCI_33;
|
957 |
|
|
else if(freq < 0x70)
|
958 |
|
|
pll = F_LOW_PCI_40;
|
959 |
|
|
else if(freq < 0x7F)
|
960 |
|
|
pll = F_LOW_PCI_50;
|
961 |
|
|
else
|
962 |
|
|
pll = F_LOW_PCI_66;
|
963 |
|
|
|
964 |
|
|
printk(KERN_INFO "FREQ: %d PLL: %d\n", freq, pll);
|
965 |
|
|
|
966 |
|
|
/* We always use the pll not the PCI clock on 372N */
|
967 |
|
|
}
|
968 |
|
|
else
|
969 |
|
|
{
|
970 |
|
|
if(freq < 0x9C)
|
971 |
|
|
pll = F_LOW_PCI_33;
|
972 |
|
|
else if(freq < 0xb0)
|
973 |
|
|
pll = F_LOW_PCI_40;
|
974 |
|
|
else if(freq <0xc8)
|
975 |
|
|
pll = F_LOW_PCI_50;
|
976 |
|
|
else
|
977 |
|
|
pll = F_LOW_PCI_66;
|
978 |
|
|
|
979 |
|
|
if (pll == F_LOW_PCI_33) {
|
980 |
|
|
if (hpt_minimum_revision(dev,8))
|
981 |
|
|
pci_set_drvdata(dev, (void *) thirty_three_base_hpt374);
|
982 |
|
|
else if (hpt_minimum_revision(dev,5))
|
983 |
|
|
pci_set_drvdata(dev, (void *) thirty_three_base_hpt372);
|
984 |
|
|
else if (hpt_minimum_revision(dev,4))
|
985 |
|
|
pci_set_drvdata(dev, (void *) thirty_three_base_hpt370a);
|
986 |
|
|
else
|
987 |
|
|
pci_set_drvdata(dev, (void *) thirty_three_base_hpt370);
|
988 |
|
|
printk("HPT37X: using 33MHz PCI clock\n");
|
989 |
|
|
} else if (pll == F_LOW_PCI_40) {
|
990 |
|
|
/* Unsupported */
|
991 |
|
|
} else if (pll == F_LOW_PCI_50) {
|
992 |
|
|
if (hpt_minimum_revision(dev,8))
|
993 |
|
|
pci_set_drvdata(dev, NULL);
|
994 |
|
|
else if (hpt_minimum_revision(dev,5))
|
995 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt372);
|
996 |
|
|
else if (hpt_minimum_revision(dev,4))
|
997 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt370a);
|
998 |
|
|
else
|
999 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt370a);
|
1000 |
|
|
printk("HPT37X: using 50MHz PCI clock\n");
|
1001 |
|
|
} else {
|
1002 |
|
|
if (hpt_minimum_revision(dev,8))
|
1003 |
|
|
{
|
1004 |
|
|
printk(KERN_ERR "HPT37x: 66MHz timings are not supported.\n");
|
1005 |
|
|
}
|
1006 |
|
|
else if (hpt_minimum_revision(dev,5))
|
1007 |
|
|
pci_set_drvdata(dev, (void *) sixty_six_base_hpt372);
|
1008 |
|
|
else if (hpt_minimum_revision(dev,4))
|
1009 |
|
|
pci_set_drvdata(dev, (void *) sixty_six_base_hpt370a);
|
1010 |
|
|
else
|
1011 |
|
|
pci_set_drvdata(dev, (void *) sixty_six_base_hpt370);
|
1012 |
|
|
printk("HPT37X: using 66MHz PCI clock\n");
|
1013 |
|
|
}
|
1014 |
|
|
}
|
1015 |
|
|
|
1016 |
|
|
/*
|
1017 |
|
|
* only try the pll if we don't have a table for the clock
|
1018 |
|
|
* speed that we're running at. NOTE: the internal PLL will
|
1019 |
|
|
* result in slow reads when using a 33MHz PCI clock. we also
|
1020 |
|
|
* don't like to use the PLL because it will cause glitches
|
1021 |
|
|
* on PRST/SRST when the HPT state engine gets reset.
|
1022 |
|
|
*
|
1023 |
|
|
* ToDo: Use 66MHz PLL when ATA133 devices are present on a
|
1024 |
|
|
* 372 device so we can get ATA133 support
|
1025 |
|
|
*/
|
1026 |
|
|
if (pci_get_drvdata(dev))
|
1027 |
|
|
goto init_hpt37X_done;
|
1028 |
|
|
|
1029 |
|
|
if (hpt_minimum_revision(dev,8))
|
1030 |
|
|
{
|
1031 |
|
|
printk(KERN_ERR "HPT374: Only 33MHz PCI timings are supported.\n");
|
1032 |
|
|
return -EOPNOTSUPP;
|
1033 |
|
|
}
|
1034 |
|
|
/*
|
1035 |
|
|
* adjust PLL based upon PCI clock, enable it, and wait for
|
1036 |
|
|
* stabilization.
|
1037 |
|
|
*/
|
1038 |
|
|
adjust = 0;
|
1039 |
|
|
freq = (pll < F_LOW_PCI_50) ? 2 : 4;
|
1040 |
|
|
while (adjust++ < 6) {
|
1041 |
|
|
pci_write_config_dword(dev, 0x5c, (freq + pll) << 16 |
|
1042 |
|
|
pll | 0x100);
|
1043 |
|
|
|
1044 |
|
|
/* wait for clock stabilization */
|
1045 |
|
|
for (i = 0; i < 0x50000; i++) {
|
1046 |
|
|
pci_read_config_byte(dev, 0x5b, ®5bh);
|
1047 |
|
|
if (reg5bh & 0x80) {
|
1048 |
|
|
/* spin looking for the clock to destabilize */
|
1049 |
|
|
for (i = 0; i < 0x1000; ++i) {
|
1050 |
|
|
pci_read_config_byte(dev, 0x5b,
|
1051 |
|
|
®5bh);
|
1052 |
|
|
if ((reg5bh & 0x80) == 0)
|
1053 |
|
|
goto pll_recal;
|
1054 |
|
|
}
|
1055 |
|
|
pci_read_config_dword(dev, 0x5c, &pll);
|
1056 |
|
|
pci_write_config_dword(dev, 0x5c,
|
1057 |
|
|
pll & ~0x100);
|
1058 |
|
|
pci_write_config_byte(dev, 0x5b, 0x21);
|
1059 |
|
|
if (hpt_minimum_revision(dev,5))
|
1060 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt372);
|
1061 |
|
|
else if (hpt_minimum_revision(dev,4))
|
1062 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt370a);
|
1063 |
|
|
else
|
1064 |
|
|
pci_set_drvdata(dev, (void *) fifty_base_hpt370a);
|
1065 |
|
|
printk("HPT37X: using 50MHz internal PLL\n");
|
1066 |
|
|
goto init_hpt37X_done;
|
1067 |
|
|
}
|
1068 |
|
|
}
|
1069 |
|
|
pll_recal:
|
1070 |
|
|
if (adjust & 1)
|
1071 |
|
|
pll -= (adjust >> 1);
|
1072 |
|
|
else
|
1073 |
|
|
pll += (adjust >> 1);
|
1074 |
|
|
}
|
1075 |
|
|
|
1076 |
|
|
init_hpt37X_done:
|
1077 |
|
|
/* reset state engine */
|
1078 |
|
|
pci_write_config_byte(dev, 0x50, 0x37);
|
1079 |
|
|
pci_write_config_byte(dev, 0x54, 0x37);
|
1080 |
|
|
udelay(100);
|
1081 |
|
|
return 0;
|
1082 |
|
|
}
|
1083 |
|
|
|
1084 |
|
|
static int __init init_hpt366 (struct pci_dev *dev)
|
1085 |
|
|
{
|
1086 |
|
|
u32 reg1 = 0;
|
1087 |
|
|
u8 drive_fast = 0;
|
1088 |
|
|
|
1089 |
|
|
/*
|
1090 |
|
|
* Disable the "fast interrupt" prediction.
|
1091 |
|
|
*/
|
1092 |
|
|
pci_read_config_byte(dev, 0x51, &drive_fast);
|
1093 |
|
|
if (drive_fast & 0x80)
|
1094 |
|
|
pci_write_config_byte(dev, 0x51, drive_fast & ~0x80);
|
1095 |
|
|
pci_read_config_dword(dev, 0x40, ®1);
|
1096 |
|
|
|
1097 |
|
|
/* detect bus speed by looking at control reg timing: */
|
1098 |
|
|
switch((reg1 >> 8) & 7) {
|
1099 |
|
|
case 5:
|
1100 |
|
|
pci_set_drvdata(dev, (void *) forty_base_hpt366);
|
1101 |
|
|
break;
|
1102 |
|
|
case 9:
|
1103 |
|
|
pci_set_drvdata(dev, (void *) twenty_five_base_hpt366);
|
1104 |
|
|
break;
|
1105 |
|
|
case 7:
|
1106 |
|
|
default:
|
1107 |
|
|
pci_set_drvdata(dev, (void *) thirty_three_base_hpt366);
|
1108 |
|
|
break;
|
1109 |
|
|
}
|
1110 |
|
|
|
1111 |
|
|
if (!pci_get_drvdata(dev))
|
1112 |
|
|
{
|
1113 |
|
|
printk(KERN_ERR "hpt366: unknown bus timing.\n");
|
1114 |
|
|
pci_set_drvdata(dev, NULL);
|
1115 |
|
|
}
|
1116 |
|
|
return 0;
|
1117 |
|
|
}
|
1118 |
|
|
|
1119 |
|
|
static unsigned int __init init_chipset_hpt366 (struct pci_dev *dev, const char *name)
|
1120 |
|
|
{
|
1121 |
|
|
int ret = 0;
|
1122 |
|
|
u8 test = 0;
|
1123 |
|
|
|
1124 |
|
|
if (dev->resource[PCI_ROM_RESOURCE].start)
|
1125 |
|
|
pci_write_config_byte(dev, PCI_ROM_ADDRESS,
|
1126 |
|
|
dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
|
1127 |
|
|
|
1128 |
|
|
pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &test);
|
1129 |
|
|
if (test != (L1_CACHE_BYTES / 4))
|
1130 |
|
|
pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE,
|
1131 |
|
|
(L1_CACHE_BYTES / 4));
|
1132 |
|
|
|
1133 |
|
|
pci_read_config_byte(dev, PCI_LATENCY_TIMER, &test);
|
1134 |
|
|
if (test != 0x78)
|
1135 |
|
|
pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
|
1136 |
|
|
|
1137 |
|
|
pci_read_config_byte(dev, PCI_MIN_GNT, &test);
|
1138 |
|
|
if (test != 0x08)
|
1139 |
|
|
pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
|
1140 |
|
|
|
1141 |
|
|
pci_read_config_byte(dev, PCI_MAX_LAT, &test);
|
1142 |
|
|
if (test != 0x08)
|
1143 |
|
|
pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
|
1144 |
|
|
|
1145 |
|
|
if (hpt_minimum_revision(dev, 3)) {
|
1146 |
|
|
ret = init_hpt37x(dev);
|
1147 |
|
|
} else {
|
1148 |
|
|
ret =init_hpt366(dev);
|
1149 |
|
|
}
|
1150 |
|
|
if (ret)
|
1151 |
|
|
return ret;
|
1152 |
|
|
|
1153 |
|
|
#if defined(DISPLAY_HPT366_TIMINGS) && defined(CONFIG_PROC_FS)
|
1154 |
|
|
hpt_devs[n_hpt_devs++] = dev;
|
1155 |
|
|
|
1156 |
|
|
if (!hpt366_proc) {
|
1157 |
|
|
hpt366_proc = 1;
|
1158 |
|
|
ide_pci_register_host_proc(&hpt366_procs[0]);
|
1159 |
|
|
}
|
1160 |
|
|
#endif /* DISPLAY_HPT366_TIMINGS && CONFIG_PROC_FS */
|
1161 |
|
|
|
1162 |
|
|
return dev->irq;
|
1163 |
|
|
}
|
1164 |
|
|
|
1165 |
|
|
static void __init init_hwif_hpt366 (ide_hwif_t *hwif)
|
1166 |
|
|
{
|
1167 |
|
|
struct pci_dev *dev = hwif->pci_dev;
|
1168 |
|
|
u8 ata66 = 0, regmask = (hwif->channel) ? 0x01 : 0x02;
|
1169 |
|
|
u8 did, rid;
|
1170 |
|
|
unsigned long dmabase = hwif->dma_base;
|
1171 |
|
|
int is_372n = 0;
|
1172 |
|
|
|
1173 |
|
|
if(dmabase)
|
1174 |
|
|
{
|
1175 |
|
|
did = inb(dmabase + 0x22);
|
1176 |
|
|
rid = inb(dmabase + 0x28);
|
1177 |
|
|
|
1178 |
|
|
if((did == 4 && rid == 6) || (did == 5 && rid > 1))
|
1179 |
|
|
is_372n = 1;
|
1180 |
|
|
}
|
1181 |
|
|
|
1182 |
|
|
if(is_372n)
|
1183 |
|
|
printk(KERN_ERR "HPT372N support is EXPERIMENTAL ONLY.\n");
|
1184 |
|
|
|
1185 |
|
|
hwif->tuneproc = &hpt3xx_tune_drive;
|
1186 |
|
|
hwif->speedproc = &hpt3xx_tune_chipset;
|
1187 |
|
|
hwif->quirkproc = &hpt3xx_quirkproc;
|
1188 |
|
|
hwif->intrproc = &hpt3xx_intrproc;
|
1189 |
|
|
hwif->maskproc = &hpt3xx_maskproc;
|
1190 |
|
|
|
1191 |
|
|
if(is_372n)
|
1192 |
|
|
hwif->rw_disk = &hpt372n_rw_disk;
|
1193 |
|
|
|
1194 |
|
|
/*
|
1195 |
|
|
* The HPT37x uses the CBLID pins as outputs for MA15/MA16
|
1196 |
|
|
* address lines to access an external eeprom. To read valid
|
1197 |
|
|
* cable detect state the pins must be enabled as inputs.
|
1198 |
|
|
*/
|
1199 |
|
|
if (hpt_minimum_revision(dev, 8) && PCI_FUNC(dev->devfn) & 1) {
|
1200 |
|
|
/*
|
1201 |
|
|
* HPT374 PCI function 1
|
1202 |
|
|
* - set bit 15 of reg 0x52 to enable TCBLID as input
|
1203 |
|
|
* - set bit 15 of reg 0x56 to enable FCBLID as input
|
1204 |
|
|
*/
|
1205 |
|
|
u16 mcr3, mcr6;
|
1206 |
|
|
pci_read_config_word(dev, 0x52, &mcr3);
|
1207 |
|
|
pci_read_config_word(dev, 0x56, &mcr6);
|
1208 |
|
|
pci_write_config_word(dev, 0x52, mcr3 | 0x8000);
|
1209 |
|
|
pci_write_config_word(dev, 0x56, mcr6 | 0x8000);
|
1210 |
|
|
/* now read cable id register */
|
1211 |
|
|
pci_read_config_byte(dev, 0x5a, &ata66);
|
1212 |
|
|
pci_write_config_word(dev, 0x52, mcr3);
|
1213 |
|
|
pci_write_config_word(dev, 0x56, mcr6);
|
1214 |
|
|
} else if (hpt_minimum_revision(dev, 3)) {
|
1215 |
|
|
/*
|
1216 |
|
|
* HPT370/372 and 374 pcifn 0
|
1217 |
|
|
* - clear bit 0 of 0x5b to enable P/SCBLID as inputs
|
1218 |
|
|
*/
|
1219 |
|
|
u8 scr2;
|
1220 |
|
|
pci_read_config_byte(dev, 0x5b, &scr2);
|
1221 |
|
|
pci_write_config_byte(dev, 0x5b, scr2 & ~1);
|
1222 |
|
|
/* now read cable id register */
|
1223 |
|
|
pci_read_config_byte(dev, 0x5a, &ata66);
|
1224 |
|
|
pci_write_config_byte(dev, 0x5b, scr2);
|
1225 |
|
|
} else {
|
1226 |
|
|
pci_read_config_byte(dev, 0x5a, &ata66);
|
1227 |
|
|
}
|
1228 |
|
|
|
1229 |
|
|
#ifdef DEBUG
|
1230 |
|
|
printk("HPT366: reg5ah=0x%02x ATA-%s Cable Port%d\n",
|
1231 |
|
|
ata66, (ata66 & regmask) ? "33" : "66",
|
1232 |
|
|
PCI_FUNC(hwif->pci_dev->devfn));
|
1233 |
|
|
#endif /* DEBUG */
|
1234 |
|
|
|
1235 |
|
|
#ifdef HPT_SERIALIZE_IO
|
1236 |
|
|
/* serialize access to this device */
|
1237 |
|
|
if (hwif->mate)
|
1238 |
|
|
hwif->serialized = hwif->mate->serialized = 1;
|
1239 |
|
|
#endif
|
1240 |
|
|
|
1241 |
|
|
if (hpt_minimum_revision(dev,3)) {
|
1242 |
|
|
u8 reg5ah = 0;
|
1243 |
|
|
pci_write_config_byte(dev, 0x5a, reg5ah & ~0x10);
|
1244 |
|
|
/*
|
1245 |
|
|
* set up ioctl for power status.
|
1246 |
|
|
* note: power affects both
|
1247 |
|
|
* drives on each channel
|
1248 |
|
|
*/
|
1249 |
|
|
hwif->resetproc = &hpt3xx_reset;
|
1250 |
|
|
hwif->busproc = &hpt370_busproc;
|
1251 |
|
|
// hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
|
1252 |
|
|
} else if (hpt_minimum_revision(dev,2)) {
|
1253 |
|
|
hwif->resetproc = &hpt3xx_reset;
|
1254 |
|
|
hwif->busproc = &hpt3xx_tristate;
|
1255 |
|
|
} else {
|
1256 |
|
|
hwif->resetproc = &hpt3xx_reset;
|
1257 |
|
|
hwif->busproc = &hpt3xx_tristate;
|
1258 |
|
|
}
|
1259 |
|
|
|
1260 |
|
|
if (!hwif->dma_base) {
|
1261 |
|
|
hwif->drives[0].autotune = 1;
|
1262 |
|
|
hwif->drives[1].autotune = 1;
|
1263 |
|
|
return;
|
1264 |
|
|
}
|
1265 |
|
|
|
1266 |
|
|
hwif->ultra_mask = 0x7f;
|
1267 |
|
|
hwif->mwdma_mask = 0x07;
|
1268 |
|
|
|
1269 |
|
|
if (!(hwif->udma_four))
|
1270 |
|
|
hwif->udma_four = ((ata66 & regmask) ? 0 : 1);
|
1271 |
|
|
hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
|
1272 |
|
|
|
1273 |
|
|
if (hpt_minimum_revision(dev,8)) {
|
1274 |
|
|
hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
|
1275 |
|
|
hwif->ide_dma_end = &hpt374_ide_dma_end;
|
1276 |
|
|
} else if (hpt_minimum_revision(dev,5)) {
|
1277 |
|
|
hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
|
1278 |
|
|
hwif->ide_dma_end = &hpt374_ide_dma_end;
|
1279 |
|
|
} else if (hpt_minimum_revision(dev,3)) {
|
1280 |
|
|
hwif->ide_dma_begin = &hpt370_ide_dma_begin;
|
1281 |
|
|
hwif->ide_dma_end = &hpt370_ide_dma_end;
|
1282 |
|
|
hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
|
1283 |
|
|
hwif->ide_dma_lostirq = &hpt370_ide_dma_lostirq;
|
1284 |
|
|
} else if (hpt_minimum_revision(dev,2))
|
1285 |
|
|
hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
|
1286 |
|
|
else
|
1287 |
|
|
hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
|
1288 |
|
|
|
1289 |
|
|
if (!noautodma)
|
1290 |
|
|
hwif->autodma = 1;
|
1291 |
|
|
hwif->drives[0].autodma = hwif->autodma;
|
1292 |
|
|
hwif->drives[1].autodma = hwif->autodma;
|
1293 |
|
|
}
|
1294 |
|
|
|
1295 |
|
|
static void __init init_dma_hpt366 (ide_hwif_t *hwif, unsigned long dmabase)
|
1296 |
|
|
{
|
1297 |
|
|
u8 masterdma = 0, slavedma = 0;
|
1298 |
|
|
u8 dma_new = 0, dma_old = 0;
|
1299 |
|
|
u8 primary = hwif->channel ? 0x4b : 0x43;
|
1300 |
|
|
u8 secondary = hwif->channel ? 0x4f : 0x47;
|
1301 |
|
|
unsigned long flags;
|
1302 |
|
|
|
1303 |
|
|
if (!dmabase)
|
1304 |
|
|
return;
|
1305 |
|
|
|
1306 |
|
|
if(pci_get_drvdata(hwif->pci_dev) == NULL)
|
1307 |
|
|
{
|
1308 |
|
|
printk(KERN_WARNING "hpt: no known IDE timings, disabling DMA.\n");
|
1309 |
|
|
return;
|
1310 |
|
|
}
|
1311 |
|
|
|
1312 |
|
|
dma_old = hwif->INB(dmabase+2);
|
1313 |
|
|
|
1314 |
|
|
local_irq_save(flags);
|
1315 |
|
|
|
1316 |
|
|
dma_new = dma_old;
|
1317 |
|
|
pci_read_config_byte(hwif->pci_dev, primary, &masterdma);
|
1318 |
|
|
pci_read_config_byte(hwif->pci_dev, secondary, &slavedma);
|
1319 |
|
|
|
1320 |
|
|
if (masterdma & 0x30) dma_new |= 0x20;
|
1321 |
|
|
if (slavedma & 0x30) dma_new |= 0x40;
|
1322 |
|
|
if (dma_new != dma_old)
|
1323 |
|
|
hwif->OUTB(dma_new, dmabase+2);
|
1324 |
|
|
|
1325 |
|
|
local_irq_restore(flags);
|
1326 |
|
|
|
1327 |
|
|
ide_setup_dma(hwif, dmabase, 8);
|
1328 |
|
|
}
|
1329 |
|
|
|
1330 |
|
|
extern void ide_setup_pci_device(struct pci_dev *, ide_pci_device_t *);
|
1331 |
|
|
extern void ide_setup_pci_devices(struct pci_dev *, struct pci_dev *, ide_pci_device_t *);
|
1332 |
|
|
|
1333 |
|
|
static void __init init_setup_hpt374 (struct pci_dev *dev, ide_pci_device_t *d)
|
1334 |
|
|
{
|
1335 |
|
|
struct pci_dev *findev = NULL;
|
1336 |
|
|
|
1337 |
|
|
if (PCI_FUNC(dev->devfn) & 1)
|
1338 |
|
|
return;
|
1339 |
|
|
|
1340 |
|
|
pci_for_each_dev(findev) {
|
1341 |
|
|
if ((findev->vendor == dev->vendor) &&
|
1342 |
|
|
(findev->device == dev->device) &&
|
1343 |
|
|
((findev->devfn - dev->devfn) == 1) &&
|
1344 |
|
|
(PCI_FUNC(findev->devfn) & 1)) {
|
1345 |
|
|
u8 irq = 0, irq2 = 0;
|
1346 |
|
|
pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
|
1347 |
|
|
pci_read_config_byte(findev, PCI_INTERRUPT_LINE, &irq2);
|
1348 |
|
|
if (irq != irq2) {
|
1349 |
|
|
pci_write_config_byte(findev,
|
1350 |
|
|
PCI_INTERRUPT_LINE, irq);
|
1351 |
|
|
findev->irq = dev->irq;
|
1352 |
|
|
printk("%s: pci-config space interrupt "
|
1353 |
|
|
"fixed.\n", d->name);
|
1354 |
|
|
}
|
1355 |
|
|
ide_setup_pci_devices(dev, findev, d);
|
1356 |
|
|
return;
|
1357 |
|
|
}
|
1358 |
|
|
}
|
1359 |
|
|
ide_setup_pci_device(dev, d);
|
1360 |
|
|
}
|
1361 |
|
|
|
1362 |
|
|
static void __init init_setup_hpt37x (struct pci_dev *dev, ide_pci_device_t *d)
|
1363 |
|
|
{
|
1364 |
|
|
ide_setup_pci_device(dev, d);
|
1365 |
|
|
}
|
1366 |
|
|
|
1367 |
|
|
static void __init init_setup_hpt366 (struct pci_dev *dev, ide_pci_device_t *d)
|
1368 |
|
|
{
|
1369 |
|
|
struct pci_dev *findev = NULL;
|
1370 |
|
|
u8 pin1 = 0, pin2 = 0;
|
1371 |
|
|
unsigned int class_rev;
|
1372 |
|
|
static char *chipset_names[] = {"HPT366", "HPT366", "HPT368",
|
1373 |
|
|
"HPT370", "HPT370A", "HPT372"};
|
1374 |
|
|
|
1375 |
|
|
if (PCI_FUNC(dev->devfn) & 1)
|
1376 |
|
|
return;
|
1377 |
|
|
|
1378 |
|
|
pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
|
1379 |
|
|
class_rev &= 0xff;
|
1380 |
|
|
|
1381 |
|
|
/* New ident 372N reports revision 1. We could do the
|
1382 |
|
|
io port based type identification instead perhaps (DID, RID) */
|
1383 |
|
|
|
1384 |
|
|
if(d->device == PCI_DEVICE_ID_TTI_HPT372N)
|
1385 |
|
|
class_rev = 5;
|
1386 |
|
|
|
1387 |
|
|
if(class_rev < 6)
|
1388 |
|
|
d->name = chipset_names[class_rev];
|
1389 |
|
|
|
1390 |
|
|
switch(class_rev) {
|
1391 |
|
|
case 5:
|
1392 |
|
|
case 4:
|
1393 |
|
|
case 3: ide_setup_pci_device(dev, d);
|
1394 |
|
|
return;
|
1395 |
|
|
default: break;
|
1396 |
|
|
}
|
1397 |
|
|
|
1398 |
|
|
d->channels = 1;
|
1399 |
|
|
|
1400 |
|
|
pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
|
1401 |
|
|
pci_for_each_dev(findev) {
|
1402 |
|
|
if ((findev->vendor == dev->vendor) &&
|
1403 |
|
|
(findev->device == dev->device) &&
|
1404 |
|
|
((findev->devfn - dev->devfn) == 1) &&
|
1405 |
|
|
(PCI_FUNC(findev->devfn) & 1)) {
|
1406 |
|
|
pci_read_config_byte(findev, PCI_INTERRUPT_PIN, &pin2);
|
1407 |
|
|
if ((pin1 != pin2) && (dev->irq == findev->irq)) {
|
1408 |
|
|
d->bootable = ON_BOARD;
|
1409 |
|
|
printk("%s: onboard version of chipset, "
|
1410 |
|
|
"pin1=%d pin2=%d\n", d->name,
|
1411 |
|
|
pin1, pin2);
|
1412 |
|
|
}
|
1413 |
|
|
ide_setup_pci_devices(dev, findev, d);
|
1414 |
|
|
return;
|
1415 |
|
|
}
|
1416 |
|
|
}
|
1417 |
|
|
ide_setup_pci_device(dev, d);
|
1418 |
|
|
}
|
1419 |
|
|
|
1420 |
|
|
|
1421 |
|
|
/**
|
1422 |
|
|
* hpt366_init_one - called when an HPT366 is found
|
1423 |
|
|
* @dev: the hpt366 device
|
1424 |
|
|
* @id: the matching pci id
|
1425 |
|
|
*
|
1426 |
|
|
* Called when the PCI registration layer (or the IDE initialization)
|
1427 |
|
|
* finds a device matching our IDE device tables.
|
1428 |
|
|
*/
|
1429 |
|
|
|
1430 |
|
|
static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
|
1431 |
|
|
{
|
1432 |
|
|
ide_pci_device_t *d = &hpt366_chipsets[id->driver_data];
|
1433 |
|
|
|
1434 |
|
|
if (dev->device != d->device)
|
1435 |
|
|
BUG();
|
1436 |
|
|
d->init_setup(dev, d);
|
1437 |
|
|
MOD_INC_USE_COUNT;
|
1438 |
|
|
return 0;
|
1439 |
|
|
}
|
1440 |
|
|
|
1441 |
|
|
static struct pci_device_id hpt366_pci_tbl[] __devinitdata = {
|
1442 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
|
1443 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
|
1444 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
|
1445 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
|
1446 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
|
1447 |
|
|
{ PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
|
1448 |
|
|
{ 0, },
|
1449 |
|
|
};
|
1450 |
|
|
|
1451 |
|
|
static struct pci_driver driver = {
|
1452 |
|
|
.name = "HPT366 IDE",
|
1453 |
|
|
.id_table = hpt366_pci_tbl,
|
1454 |
|
|
.probe = hpt366_init_one,
|
1455 |
|
|
};
|
1456 |
|
|
|
1457 |
|
|
static int hpt366_ide_init(void)
|
1458 |
|
|
{
|
1459 |
|
|
return ide_pci_register_driver(&driver);
|
1460 |
|
|
}
|
1461 |
|
|
|
1462 |
|
|
static void hpt366_ide_exit(void)
|
1463 |
|
|
{
|
1464 |
|
|
ide_pci_unregister_driver(&driver);
|
1465 |
|
|
}
|
1466 |
|
|
|
1467 |
|
|
module_init(hpt366_ide_init);
|
1468 |
|
|
module_exit(hpt366_ide_exit);
|
1469 |
|
|
|
1470 |
|
|
MODULE_AUTHOR("Andre Hedrick");
|
1471 |
|
|
MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
|
1472 |
|
|
MODULE_LICENSE("GPL");
|
1473 |
|
|
|
1474 |
|
|
EXPORT_NO_SYMBOLS;
|