hpt366: init code rewrite
[deliverable/linux.git] / drivers / ide / pci / hpt366.c
CommitLineData
1da177e4 1/*
7b73ee05 2 * linux/drivers/ide/pci/hpt366.c Version 1.00 Jun 25, 2006
1da177e4
LT
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
836c0063 7 * Portions Copyright (C) 2005-2006 MontaVista Software, Inc.
1da177e4
LT
8 *
9 * Thanks to HighPoint Technologies for their assistance, and hardware.
10 * Special Thanks to Jon Burchmore in SanDiego for the deep pockets, his
11 * donation of an ABit BP6 mainboard, processor, and memory acellerated
12 * development and support.
13 *
b39b01ff 14 *
836c0063
SS
15 * HighPoint has its own drivers (open source except for the RAID part)
16 * available from http://www.highpoint-tech.com/BIOS%20+%20Driver/.
17 * This may be useful to anyone wanting to work on this driver, however do not
18 * trust them too much since the code tends to become less and less meaningful
19 * as the time passes... :-/
b39b01ff 20 *
1da177e4
LT
21 * Note that final HPT370 support was done by force extraction of GPL.
22 *
23 * - add function for getting/setting power status of drive
24 * - the HPT370's state machine can get confused. reset it before each dma
25 * xfer to prevent that from happening.
26 * - reset state engine whenever we get an error.
27 * - check for busmaster state at end of dma.
28 * - use new highpoint timings.
29 * - detect bus speed using highpoint register.
30 * - use pll if we don't have a clock table. added a 66MHz table that's
31 * just 2x the 33MHz table.
32 * - removed turnaround. NOTE: we never want to switch between pll and
33 * pci clocks as the chip can glitch in those cases. the highpoint
34 * approved workaround slows everything down too much to be useful. in
35 * addition, we would have to serialize access to each chip.
36 * Adrian Sun <a.sun@sun.com>
37 *
38 * add drive timings for 66MHz PCI bus,
39 * fix ATA Cable signal detection, fix incorrect /proc info
40 * add /proc display for per-drive PIO/DMA/UDMA mode and
41 * per-channel ATA-33/66 Cable detect.
42 * Duncan Laurie <void@sun.com>
43 *
44 * fixup /proc output for multiple controllers
45 * Tim Hockin <thockin@sun.com>
46 *
47 * On hpt366:
48 * Reset the hpt366 on error, reset on dma
49 * Fix disabling Fast Interrupt hpt366.
50 * Mike Waychison <crlf@sun.com>
51 *
52 * Added support for 372N clocking and clock switching. The 372N needs
53 * different clocks on read/write. This requires overloading rw_disk and
54 * other deeply crazy things. Thanks to <http://www.hoerstreich.de> for
55 * keeping me sane.
56 * Alan Cox <alan@redhat.com>
57 *
836c0063
SS
58 * - fix the clock turnaround code: it was writing to the wrong ports when
59 * called for the secondary channel, caching the current clock mode per-
60 * channel caused the cached register value to get out of sync with the
61 * actual one, the channels weren't serialized, the turnaround shouldn't
62 * be done on 66 MHz PCI bus
7b73ee05
SS
63 * - disable UltraATA/100 for HPT370 by default as the 33 MHz clock being used
64 * does not allow for this speed anyway
65 * - avoid touching disabled channels (e.g. HPT371/N are single channel chips,
66 * their primary channel is kind of virtual, it isn't tied to any pins)
471a0bda
SS
67 * - fix/remove bad/unused timing tables and use one set of tables for the whole
68 * HPT37x chip family; save space by introducing the separate transfer mode
69 * table in which the mode lookup is done
26c068da
SS
70 * - use f_CNT value saved by the HighPoint BIOS as reading it directly gives
71 * the wrong PCI frequency since DPLL has already been calibrated by BIOS
33b18a60
SS
72 * - fix the hotswap code: it caused RESET- to glitch when tristating the bus,
73 * and for HPT36x the obsolete HDIO_TRISTATE_HWIF handler was called instead
73d1dd93
SS
74 * - pass to init_chipset() handlers a copy of the IDE PCI device structure as
75 * they tamper with its fields
7b73ee05
SS
76 * - pass to the init_setup handlers a copy of the ide_pci_device_t structure
77 * since they may tamper with its fields
90778574
SS
78 * - prefix the driver startup messages with the real chip name
79 * - claim the extra 240 bytes of I/O space for all chips
e139b0b0 80 * - optimize the rate masking/filtering and the drive list lookup code
b4586715 81 * - use pci_get_slot() to get to the function 1 of HPT36x/374
7b73ee05
SS
82 * - cache offset of the channel's misc. control registers (MCRs) being used
83 * throughout the driver
84 * - only touch the relevant MCR when detecting the cable type on HPT374's
85 * function 1
abc4ad4c 86 * - rename all the register related variables consistently
7b73ee05
SS
87 * - move all the interrupt twiddling code from the speedproc handlers into
88 * init_hwif_hpt366(), also grouping all the DMA related code together there
89 * - merge two HPT37x speedproc handlers, fix the PIO timing register mask and
90 * separate the UltraDMA and MWDMA masks there to avoid changing PIO timings
91 * when setting an UltraDMA mode
92 * - fix hpt3xx_tune_drive() to set the PIO mode requested, not always select
93 * the best possible one
4bf63de2 94 * - clean up DMA timeout handling for HPT370
7b73ee05
SS
95 * - switch to using the enumeration type to differ between the numerous chip
96 * variants, matching PCI device/revision ID with the chip type early, at the
97 * init_setup stage
98 * - extend the hpt_info structure to hold the DPLL and PCI clock frequencies,
99 * stop duplicating it for each channel by storing the pointer in the pci_dev
100 * structure: first, at the init_setup stage, point it to a static "template"
101 * with only the chip type and its specific base DPLL frequency, the highest
102 * supported DMA mode, and the chip settings table pointer filled, then, at
103 * the init_chipset stage, allocate per-chip instance and fill it with the
104 * rest of the necessary information
105 * - get rid of the constant thresholds in the HPT37x PCI clock detection code,
106 * switch to calculating PCI clock frequency based on the chip's base DPLL
107 * frequency
108 * - switch to using the DPLL clock and enable UltraATA/133 mode by default on
109 * anything newer than HPT370/A
110 * - fold PCI clock detection and DPLL setup code into init_chipset_hpt366();
111 * unify HPT36x/37x timing setup code and the speedproc handlers by joining
112 * the register setting lists into the table indexed by the clock selected
113 * Sergei Shtylyov, <sshtylyov@ru.mvista.com> or <source@mvista.com>
1da177e4
LT
114 */
115
1da177e4
LT
116#include <linux/types.h>
117#include <linux/module.h>
118#include <linux/kernel.h>
119#include <linux/delay.h>
120#include <linux/timer.h>
121#include <linux/mm.h>
122#include <linux/ioport.h>
123#include <linux/blkdev.h>
124#include <linux/hdreg.h>
125
126#include <linux/interrupt.h>
127#include <linux/pci.h>
128#include <linux/init.h>
129#include <linux/ide.h>
130
131#include <asm/uaccess.h>
132#include <asm/io.h>
133#include <asm/irq.h>
134
135/* various tuning parameters */
136#define HPT_RESET_STATE_ENGINE
836c0063
SS
137#undef HPT_DELAY_INTERRUPT
138#define HPT_SERIALIZE_IO 0
1da177e4
LT
139
140static const char *quirk_drives[] = {
141 "QUANTUM FIREBALLlct08 08",
142 "QUANTUM FIREBALLP KA6.4",
143 "QUANTUM FIREBALLP LM20.4",
144 "QUANTUM FIREBALLP LM20.5",
145 NULL
146};
147
148static const char *bad_ata100_5[] = {
149 "IBM-DTLA-307075",
150 "IBM-DTLA-307060",
151 "IBM-DTLA-307045",
152 "IBM-DTLA-307030",
153 "IBM-DTLA-307020",
154 "IBM-DTLA-307015",
155 "IBM-DTLA-305040",
156 "IBM-DTLA-305030",
157 "IBM-DTLA-305020",
158 "IC35L010AVER07-0",
159 "IC35L020AVER07-0",
160 "IC35L030AVER07-0",
161 "IC35L040AVER07-0",
162 "IC35L060AVER07-0",
163 "WDC AC310200R",
164 NULL
165};
166
167static const char *bad_ata66_4[] = {
168 "IBM-DTLA-307075",
169 "IBM-DTLA-307060",
170 "IBM-DTLA-307045",
171 "IBM-DTLA-307030",
172 "IBM-DTLA-307020",
173 "IBM-DTLA-307015",
174 "IBM-DTLA-305040",
175 "IBM-DTLA-305030",
176 "IBM-DTLA-305020",
177 "IC35L010AVER07-0",
178 "IC35L020AVER07-0",
179 "IC35L030AVER07-0",
180 "IC35L040AVER07-0",
181 "IC35L060AVER07-0",
182 "WDC AC310200R",
183 NULL
184};
185
186static const char *bad_ata66_3[] = {
187 "WDC AC310200R",
188 NULL
189};
190
191static const char *bad_ata33[] = {
192 "Maxtor 92720U8", "Maxtor 92040U6", "Maxtor 91360U4", "Maxtor 91020U3", "Maxtor 90845U3", "Maxtor 90650U2",
193 "Maxtor 91360D8", "Maxtor 91190D7", "Maxtor 91020D6", "Maxtor 90845D5", "Maxtor 90680D4", "Maxtor 90510D3", "Maxtor 90340D2",
194 "Maxtor 91152D8", "Maxtor 91008D7", "Maxtor 90845D6", "Maxtor 90840D6", "Maxtor 90720D5", "Maxtor 90648D5", "Maxtor 90576D4",
195 "Maxtor 90510D4",
196 "Maxtor 90432D3", "Maxtor 90288D2", "Maxtor 90256D2",
197 "Maxtor 91000D8", "Maxtor 90910D8", "Maxtor 90875D7", "Maxtor 90840D7", "Maxtor 90750D6", "Maxtor 90625D5", "Maxtor 90500D4",
198 "Maxtor 91728D8", "Maxtor 91512D7", "Maxtor 91303D6", "Maxtor 91080D5", "Maxtor 90845D4", "Maxtor 90680D4", "Maxtor 90648D3", "Maxtor 90432D2",
199 NULL
200};
201
471a0bda
SS
202static u8 xfer_speeds[] = {
203 XFER_UDMA_6,
204 XFER_UDMA_5,
205 XFER_UDMA_4,
206 XFER_UDMA_3,
207 XFER_UDMA_2,
208 XFER_UDMA_1,
209 XFER_UDMA_0,
210
211 XFER_MW_DMA_2,
212 XFER_MW_DMA_1,
213 XFER_MW_DMA_0,
214
215 XFER_PIO_4,
216 XFER_PIO_3,
217 XFER_PIO_2,
218 XFER_PIO_1,
219 XFER_PIO_0
1da177e4
LT
220};
221
471a0bda
SS
222/* Key for bus clock timings
223 * 36x 37x
224 * bits bits
225 * 0:3 0:3 data_high_time. Inactive time of DIOW_/DIOR_ for PIO and MW DMA.
226 * cycles = value + 1
227 * 4:7 4:8 data_low_time. Active time of DIOW_/DIOR_ for PIO and MW DMA.
228 * cycles = value + 1
229 * 8:11 9:12 cmd_high_time. Inactive time of DIOW_/DIOR_ during task file
230 * register access.
231 * 12:15 13:17 cmd_low_time. Active time of DIOW_/DIOR_ during task file
232 * register access.
233 * 16:18 18:20 udma_cycle_time. Clock cycles for UDMA xfer.
234 * - 21 CLK frequency: 0=ATA clock, 1=dual ATA clock.
235 * 19:21 22:24 pre_high_time. Time to initialize the 1st cycle for PIO and
236 * MW DMA xfer.
237 * 22:24 25:27 cmd_pre_high_time. Time to initialize the 1st PIO cycle for
238 * task file register access.
239 * 28 28 UDMA enable.
240 * 29 29 DMA enable.
241 * 30 30 PIO MST enable. If set, the chip is in bus master mode during
242 * PIO xfer.
243 * 31 31 FIFO enable.
1da177e4 244 */
1da177e4 245
471a0bda
SS
246static u32 forty_base_hpt36x[] = {
247 /* XFER_UDMA_6 */ 0x900fd943,
248 /* XFER_UDMA_5 */ 0x900fd943,
249 /* XFER_UDMA_4 */ 0x900fd943,
250 /* XFER_UDMA_3 */ 0x900ad943,
251 /* XFER_UDMA_2 */ 0x900bd943,
252 /* XFER_UDMA_1 */ 0x9008d943,
253 /* XFER_UDMA_0 */ 0x9008d943,
254
255 /* XFER_MW_DMA_2 */ 0xa008d943,
256 /* XFER_MW_DMA_1 */ 0xa010d955,
257 /* XFER_MW_DMA_0 */ 0xa010d9fc,
258
259 /* XFER_PIO_4 */ 0xc008d963,
260 /* XFER_PIO_3 */ 0xc010d974,
261 /* XFER_PIO_2 */ 0xc010d997,
262 /* XFER_PIO_1 */ 0xc010d9c7,
263 /* XFER_PIO_0 */ 0xc018d9d9
1da177e4
LT
264};
265
471a0bda
SS
266static u32 thirty_three_base_hpt36x[] = {
267 /* XFER_UDMA_6 */ 0x90c9a731,
268 /* XFER_UDMA_5 */ 0x90c9a731,
269 /* XFER_UDMA_4 */ 0x90c9a731,
270 /* XFER_UDMA_3 */ 0x90cfa731,
271 /* XFER_UDMA_2 */ 0x90caa731,
272 /* XFER_UDMA_1 */ 0x90cba731,
273 /* XFER_UDMA_0 */ 0x90c8a731,
274
275 /* XFER_MW_DMA_2 */ 0xa0c8a731,
276 /* XFER_MW_DMA_1 */ 0xa0c8a732, /* 0xa0c8a733 */
277 /* XFER_MW_DMA_0 */ 0xa0c8a797,
278
279 /* XFER_PIO_4 */ 0xc0c8a731,
280 /* XFER_PIO_3 */ 0xc0c8a742,
281 /* XFER_PIO_2 */ 0xc0d0a753,
282 /* XFER_PIO_1 */ 0xc0d0a7a3, /* 0xc0d0a793 */
283 /* XFER_PIO_0 */ 0xc0d0a7aa /* 0xc0d0a7a7 */
1da177e4
LT
284};
285
471a0bda
SS
286static u32 twenty_five_base_hpt36x[] = {
287 /* XFER_UDMA_6 */ 0x90c98521,
288 /* XFER_UDMA_5 */ 0x90c98521,
289 /* XFER_UDMA_4 */ 0x90c98521,
290 /* XFER_UDMA_3 */ 0x90cf8521,
291 /* XFER_UDMA_2 */ 0x90cf8521,
292 /* XFER_UDMA_1 */ 0x90cb8521,
293 /* XFER_UDMA_0 */ 0x90cb8521,
294
295 /* XFER_MW_DMA_2 */ 0xa0ca8521,
296 /* XFER_MW_DMA_1 */ 0xa0ca8532,
297 /* XFER_MW_DMA_0 */ 0xa0ca8575,
298
299 /* XFER_PIO_4 */ 0xc0ca8521,
300 /* XFER_PIO_3 */ 0xc0ca8532,
301 /* XFER_PIO_2 */ 0xc0ca8542,
302 /* XFER_PIO_1 */ 0xc0d08572,
303 /* XFER_PIO_0 */ 0xc0d08585
1da177e4
LT
304};
305
471a0bda
SS
306static u32 thirty_three_base_hpt37x[] = {
307 /* XFER_UDMA_6 */ 0x12446231, /* 0x12646231 ?? */
308 /* XFER_UDMA_5 */ 0x12446231,
309 /* XFER_UDMA_4 */ 0x12446231,
310 /* XFER_UDMA_3 */ 0x126c6231,
311 /* XFER_UDMA_2 */ 0x12486231,
312 /* XFER_UDMA_1 */ 0x124c6233,
313 /* XFER_UDMA_0 */ 0x12506297,
314
315 /* XFER_MW_DMA_2 */ 0x22406c31,
316 /* XFER_MW_DMA_1 */ 0x22406c33,
317 /* XFER_MW_DMA_0 */ 0x22406c97,
318
319 /* XFER_PIO_4 */ 0x06414e31,
320 /* XFER_PIO_3 */ 0x06414e42,
321 /* XFER_PIO_2 */ 0x06414e53,
322 /* XFER_PIO_1 */ 0x06814e93,
323 /* XFER_PIO_0 */ 0x06814ea7
1da177e4
LT
324};
325
471a0bda
SS
326static u32 fifty_base_hpt37x[] = {
327 /* XFER_UDMA_6 */ 0x12848242,
328 /* XFER_UDMA_5 */ 0x12848242,
329 /* XFER_UDMA_4 */ 0x12ac8242,
330 /* XFER_UDMA_3 */ 0x128c8242,
331 /* XFER_UDMA_2 */ 0x120c8242,
332 /* XFER_UDMA_1 */ 0x12148254,
333 /* XFER_UDMA_0 */ 0x121882ea,
334
335 /* XFER_MW_DMA_2 */ 0x22808242,
336 /* XFER_MW_DMA_1 */ 0x22808254,
337 /* XFER_MW_DMA_0 */ 0x228082ea,
338
339 /* XFER_PIO_4 */ 0x0a81f442,
340 /* XFER_PIO_3 */ 0x0a81f443,
341 /* XFER_PIO_2 */ 0x0a81f454,
342 /* XFER_PIO_1 */ 0x0ac1f465,
343 /* XFER_PIO_0 */ 0x0ac1f48a
1da177e4
LT
344};
345
471a0bda
SS
346static u32 sixty_six_base_hpt37x[] = {
347 /* XFER_UDMA_6 */ 0x1c869c62,
348 /* XFER_UDMA_5 */ 0x1cae9c62, /* 0x1c8a9c62 */
349 /* XFER_UDMA_4 */ 0x1c8a9c62,
350 /* XFER_UDMA_3 */ 0x1c8e9c62,
351 /* XFER_UDMA_2 */ 0x1c929c62,
352 /* XFER_UDMA_1 */ 0x1c9a9c62,
353 /* XFER_UDMA_0 */ 0x1c829c62,
354
355 /* XFER_MW_DMA_2 */ 0x2c829c62,
356 /* XFER_MW_DMA_1 */ 0x2c829c66,
357 /* XFER_MW_DMA_0 */ 0x2c829d2e,
358
359 /* XFER_PIO_4 */ 0x0c829c62,
360 /* XFER_PIO_3 */ 0x0c829c84,
361 /* XFER_PIO_2 */ 0x0c829ca6,
362 /* XFER_PIO_1 */ 0x0d029d26,
363 /* XFER_PIO_0 */ 0x0d029d5e
1da177e4
LT
364};
365
1da177e4 366#define HPT366_DEBUG_DRIVE_INFO 0
7b73ee05
SS
367#define HPT374_ALLOW_ATA133_6 1
368#define HPT371_ALLOW_ATA133_6 1
369#define HPT302_ALLOW_ATA133_6 1
370#define HPT372_ALLOW_ATA133_6 1
e139b0b0 371#define HPT370_ALLOW_ATA100_5 0
1da177e4
LT
372#define HPT366_ALLOW_ATA66_4 1
373#define HPT366_ALLOW_ATA66_3 1
374#define HPT366_MAX_DEVS 8
375
7b73ee05
SS
376/* Supported ATA clock frequencies */
377enum ata_clock {
378 ATA_CLOCK_25MHZ,
379 ATA_CLOCK_33MHZ,
380 ATA_CLOCK_40MHZ,
381 ATA_CLOCK_50MHZ,
382 ATA_CLOCK_66MHZ,
383 NUM_ATA_CLOCKS
384};
1da177e4 385
b39b01ff 386/*
7b73ee05 387 * Hold all the HighPoint chip information in one place.
b39b01ff 388 */
1da177e4 389
7b73ee05
SS
390struct hpt_info {
391 u8 chip_type; /* Chip type */
b39b01ff 392 u8 max_mode; /* Speeds allowed */
7b73ee05
SS
393 u8 dpll_clk; /* DPLL clock in MHz */
394 u8 pci_clk; /* PCI clock in MHz */
395 u32 **settings; /* Chipset settings table */
b39b01ff
AC
396};
397
7b73ee05
SS
398/* Supported HighPoint chips */
399enum {
400 HPT36x,
401 HPT370,
402 HPT370A,
403 HPT374,
404 HPT372,
405 HPT372A,
406 HPT302,
407 HPT371,
408 HPT372N,
409 HPT302N,
410 HPT371N
411};
b39b01ff 412
7b73ee05
SS
413static u32 *hpt36x_settings[NUM_ATA_CLOCKS] = {
414 twenty_five_base_hpt36x,
415 thirty_three_base_hpt36x,
416 forty_base_hpt36x,
417 NULL,
418 NULL
419};
e139b0b0 420
7b73ee05
SS
421static u32 *hpt37x_settings[NUM_ATA_CLOCKS] = {
422 NULL,
423 thirty_three_base_hpt37x,
424 NULL,
425 fifty_base_hpt37x,
426 sixty_six_base_hpt37x
427};
1da177e4 428
7b73ee05
SS
429static struct hpt_info hpt36x __devinitdata = {
430 .chip_type = HPT36x,
431 .max_mode = (HPT366_ALLOW_ATA66_4 || HPT366_ALLOW_ATA66_3) ? 2 : 1,
432 .dpll_clk = 0, /* no DPLL */
433 .settings = hpt36x_settings
434};
435
436static struct hpt_info hpt370 __devinitdata = {
437 .chip_type = HPT370,
438 .max_mode = HPT370_ALLOW_ATA100_5 ? 3 : 2,
439 .dpll_clk = 48,
440 .settings = hpt37x_settings
441};
442
443static struct hpt_info hpt370a __devinitdata = {
444 .chip_type = HPT370A,
445 .max_mode = HPT370_ALLOW_ATA100_5 ? 3 : 2,
446 .dpll_clk = 48,
447 .settings = hpt37x_settings
448};
449
450static struct hpt_info hpt374 __devinitdata = {
451 .chip_type = HPT374,
452 .max_mode = HPT374_ALLOW_ATA133_6 ? 4 : 3,
453 .dpll_clk = 48,
454 .settings = hpt37x_settings
455};
456
457static struct hpt_info hpt372 __devinitdata = {
458 .chip_type = HPT372,
459 .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3,
460 .dpll_clk = 55,
461 .settings = hpt37x_settings
462};
463
464static struct hpt_info hpt372a __devinitdata = {
465 .chip_type = HPT372A,
466 .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3,
467 .dpll_clk = 66,
468 .settings = hpt37x_settings
469};
470
471static struct hpt_info hpt302 __devinitdata = {
472 .chip_type = HPT302,
473 .max_mode = HPT302_ALLOW_ATA133_6 ? 4 : 3,
474 .dpll_clk = 66,
475 .settings = hpt37x_settings
476};
477
478static struct hpt_info hpt371 __devinitdata = {
479 .chip_type = HPT371,
480 .max_mode = HPT371_ALLOW_ATA133_6 ? 4 : 3,
481 .dpll_clk = 66,
482 .settings = hpt37x_settings
483};
484
485static struct hpt_info hpt372n __devinitdata = {
486 .chip_type = HPT372N,
487 .max_mode = HPT372_ALLOW_ATA133_6 ? 4 : 3,
488 .dpll_clk = 77,
489 .settings = hpt37x_settings
490};
491
492static struct hpt_info hpt302n __devinitdata = {
493 .chip_type = HPT302N,
494 .max_mode = HPT302_ALLOW_ATA133_6 ? 4 : 3,
495 .dpll_clk = 77,
496};
497
498static struct hpt_info hpt371n __devinitdata = {
499 .chip_type = HPT371N,
500 .max_mode = HPT371_ALLOW_ATA133_6 ? 4 : 3,
501 .dpll_clk = 77,
502 .settings = hpt37x_settings
503};
1da177e4 504
e139b0b0
SS
505static int check_in_drive_list(ide_drive_t *drive, const char **list)
506{
507 struct hd_driveid *id = drive->id;
508
509 while (*list)
510 if (!strcmp(*list++,id->model))
511 return 1;
512 return 0;
513}
1da177e4 514
e139b0b0 515static u8 hpt3xx_ratemask(ide_drive_t *drive)
1da177e4 516{
7b73ee05 517 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
e139b0b0
SS
518 u8 mode = info->max_mode;
519
b39b01ff 520 if (!eighty_ninty_three(drive) && mode)
1da177e4
LT
521 mode = min(mode, (u8)1);
522 return mode;
523}
524
525/*
526 * Note for the future; the SATA hpt37x we must set
527 * either PIO or UDMA modes 0,4,5
528 */
529
e139b0b0 530static u8 hpt3xx_ratefilter(ide_drive_t *drive, u8 speed)
1da177e4 531{
7b73ee05
SS
532 struct hpt_info *info = pci_get_drvdata(HWIF(drive)->pci_dev);
533 u8 chip_type = info->chip_type;
1da177e4
LT
534 u8 mode = hpt3xx_ratemask(drive);
535
536 if (drive->media != ide_disk)
537 return min(speed, (u8)XFER_PIO_4);
538
e139b0b0 539 switch (mode) {
1da177e4 540 case 0x04:
7b73ee05 541 speed = min_t(u8, speed, XFER_UDMA_6);
1da177e4
LT
542 break;
543 case 0x03:
7b73ee05
SS
544 speed = min_t(u8, speed, XFER_UDMA_5);
545 if (chip_type >= HPT374)
1da177e4 546 break;
e139b0b0
SS
547 if (!check_in_drive_list(drive, bad_ata100_5))
548 goto check_bad_ata33;
549 /* fall thru */
1da177e4 550 case 0x02:
f36702b4 551 speed = min_t(u8, speed, XFER_UDMA_4);
7b73ee05
SS
552
553 /*
554 * CHECK ME, Does this need to be changed to HPT374 ??
555 */
556 if (chip_type >= HPT370)
e139b0b0
SS
557 goto check_bad_ata33;
558 if (HPT366_ALLOW_ATA66_4 &&
559 !check_in_drive_list(drive, bad_ata66_4))
560 goto check_bad_ata33;
561
f36702b4 562 speed = min_t(u8, speed, XFER_UDMA_3);
e139b0b0
SS
563 if (HPT366_ALLOW_ATA66_3 &&
564 !check_in_drive_list(drive, bad_ata66_3))
565 goto check_bad_ata33;
566 /* fall thru */
1da177e4 567 case 0x01:
f36702b4 568 speed = min_t(u8, speed, XFER_UDMA_2);
e139b0b0
SS
569
570 check_bad_ata33:
7b73ee05 571 if (chip_type >= HPT370A)
1da177e4 572 break;
e139b0b0
SS
573 if (!check_in_drive_list(drive, bad_ata33))
574 break;
575 /* fall thru */
1da177e4
LT
576 case 0x00:
577 default:
f36702b4 578 speed = min_t(u8, speed, XFER_MW_DMA_2);
1da177e4
LT
579 break;
580 }
581 return speed;
582}
583
7b73ee05 584static u32 get_speed_setting(u8 speed, struct hpt_info *info)
1da177e4 585{
471a0bda
SS
586 int i;
587
588 /*
589 * Lookup the transfer mode table to get the index into
590 * the timing table.
591 *
592 * NOTE: For XFER_PIO_SLOW, PIO mode 0 timings will be used.
593 */
594 for (i = 0; i < ARRAY_SIZE(xfer_speeds) - 1; i++)
595 if (xfer_speeds[i] == speed)
596 break;
7b73ee05
SS
597 /*
598 * NOTE: info->settings only points to the pointer
599 * to the list of the actual register values
600 */
601 return (*info->settings)[i];
1da177e4
LT
602}
603
604static int hpt36x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
605{
abc4ad4c
SS
606 ide_hwif_t *hwif = HWIF(drive);
607 struct pci_dev *dev = hwif->pci_dev;
7b73ee05 608 struct hpt_info *info = pci_get_drvdata(dev);
abc4ad4c
SS
609 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
610 u8 itr_addr = drive->dn ? 0x44 : 0x40;
7b73ee05
SS
611 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x30070000 :
612 (speed < XFER_UDMA_0 ? 0xc0070000 : 0xc03800ff);
613 u32 new_itr = get_speed_setting(speed, info);
26ccb802 614 u32 old_itr = 0;
b39b01ff 615
1da177e4 616 /*
abc4ad4c
SS
617 * Disable on-chip PIO FIFO/buffer (and PIO MST mode as well)
618 * to avoid problems handling I/O errors later
1da177e4 619 */
abc4ad4c
SS
620 pci_read_config_dword(dev, itr_addr, &old_itr);
621 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
622 new_itr &= ~0xc0000000;
1da177e4 623
abc4ad4c 624 pci_write_config_dword(dev, itr_addr, new_itr);
1da177e4
LT
625
626 return ide_config_drive_speed(drive, speed);
627}
628
26ccb802 629static int hpt37x_tune_chipset(ide_drive_t *drive, u8 xferspeed)
1da177e4 630{
abc4ad4c
SS
631 ide_hwif_t *hwif = HWIF(drive);
632 struct pci_dev *dev = hwif->pci_dev;
7b73ee05 633 struct hpt_info *info = pci_get_drvdata(dev);
abc4ad4c 634 u8 speed = hpt3xx_ratefilter(drive, xferspeed);
abc4ad4c 635 u8 itr_addr = 0x40 + (drive->dn * 4);
7b73ee05
SS
636 u32 itr_mask = speed < XFER_MW_DMA_0 ? 0x303c0000 :
637 (speed < XFER_UDMA_0 ? 0xc03c0000 : 0xc1c001ff);
638 u32 new_itr = get_speed_setting(speed, info);
26ccb802 639 u32 old_itr = 0;
1da177e4 640
abc4ad4c
SS
641 pci_read_config_dword(dev, itr_addr, &old_itr);
642 new_itr = (new_itr & ~itr_mask) | (old_itr & itr_mask);
1da177e4 643
b39b01ff 644 if (speed < XFER_MW_DMA_0)
abc4ad4c
SS
645 new_itr &= ~0x80000000; /* Disable on-chip PIO FIFO/buffer */
646 pci_write_config_dword(dev, itr_addr, new_itr);
1da177e4
LT
647
648 return ide_config_drive_speed(drive, speed);
649}
650
26ccb802 651static int hpt3xx_tune_chipset(ide_drive_t *drive, u8 speed)
1da177e4 652{
abc4ad4c 653 ide_hwif_t *hwif = HWIF(drive);
7b73ee05 654 struct hpt_info *info = pci_get_drvdata(hwif->pci_dev);
1da177e4 655
7b73ee05 656 if (info->chip_type >= HPT370)
26ccb802 657 return hpt37x_tune_chipset(drive, speed);
1da177e4
LT
658 else /* hpt368: hpt_minimum_revision(dev, 2) */
659 return hpt36x_tune_chipset(drive, speed);
660}
661
26ccb802 662static void hpt3xx_tune_drive(ide_drive_t *drive, u8 pio)
1da177e4 663{
26ccb802
SS
664 pio = ide_get_best_pio_mode(drive, pio, 4, NULL);
665 (void) hpt3xx_tune_chipset (drive, XFER_PIO_0 + pio);
1da177e4
LT
666}
667
668/*
669 * This allows the configuration of ide_pci chipset registers
670 * for cards that learn about the drive's UDMA, DMA, PIO capabilities
26ccb802 671 * after the drive is reported by the OS. Initially designed for
1da177e4
LT
672 * HPT366 UDMA chipset by HighPoint|Triones Technologies, Inc.
673 *
1da177e4 674 */
26ccb802 675static int config_chipset_for_dma(ide_drive_t *drive)
1da177e4
LT
676{
677 u8 speed = ide_dma_speed(drive, hpt3xx_ratemask(drive));
678
b39b01ff
AC
679 if (!speed)
680 return 0;
681
1da177e4
LT
682 (void) hpt3xx_tune_chipset(drive, speed);
683 return ide_dma_enable(drive);
684}
685
e139b0b0 686static int hpt3xx_quirkproc(ide_drive_t *drive)
1da177e4 687{
e139b0b0
SS
688 struct hd_driveid *id = drive->id;
689 const char **list = quirk_drives;
690
691 while (*list)
692 if (strstr(id->model, *list++))
693 return 1;
694 return 0;
1da177e4
LT
695}
696
26ccb802 697static void hpt3xx_intrproc(ide_drive_t *drive)
1da177e4 698{
abc4ad4c 699 ide_hwif_t *hwif = HWIF(drive);
1da177e4
LT
700
701 if (drive->quirk_list)
702 return;
703 /* drives in the quirk_list may not like intr setups/cleanups */
abc4ad4c 704 hwif->OUTB(drive->ctl | 2, IDE_CONTROL_REG);
1da177e4
LT
705}
706
26ccb802 707static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
1da177e4 708{
abc4ad4c
SS
709 ide_hwif_t *hwif = HWIF(drive);
710 struct pci_dev *dev = hwif->pci_dev;
7b73ee05 711 struct hpt_info *info = pci_get_drvdata(dev);
1da177e4
LT
712
713 if (drive->quirk_list) {
7b73ee05 714 if (info->chip_type >= HPT370) {
abc4ad4c
SS
715 u8 scr1 = 0;
716
717 pci_read_config_byte(dev, 0x5a, &scr1);
718 if (((scr1 & 0x10) >> 4) != mask) {
719 if (mask)
720 scr1 |= 0x10;
721 else
722 scr1 &= ~0x10;
723 pci_write_config_byte(dev, 0x5a, scr1);
724 }
1da177e4 725 } else {
abc4ad4c 726 if (mask)
b39b01ff 727 disable_irq(hwif->irq);
abc4ad4c
SS
728 else
729 enable_irq (hwif->irq);
1da177e4 730 }
abc4ad4c
SS
731 } else
732 hwif->OUTB(mask ? (drive->ctl | 2) : (drive->ctl & ~2),
733 IDE_CONTROL_REG);
1da177e4
LT
734}
735
26ccb802 736static int hpt366_config_drive_xfer_rate(ide_drive_t *drive)
1da177e4 737{
26ccb802 738 ide_hwif_t *hwif = HWIF(drive);
1da177e4
LT
739 struct hd_driveid *id = drive->id;
740
741 drive->init_speed = 0;
742
b39b01ff 743 if ((id->capability & 1) && drive->autodma) {
26ccb802
SS
744 if (ide_use_dma(drive) && config_chipset_for_dma(drive))
745 return hwif->ide_dma_on(drive);
1da177e4
LT
746
747 goto fast_ata_pio;
748
749 } else if ((id->capability & 8) || (id->field_valid & 2)) {
750fast_ata_pio:
26ccb802 751 hpt3xx_tune_drive(drive, 255);
1da177e4
LT
752 return hwif->ide_dma_off_quietly(drive);
753 }
754 /* IORDY not supported */
755 return 0;
756}
757
758/*
abc4ad4c 759 * This is specific to the HPT366 UDMA chipset
1da177e4
LT
760 * by HighPoint|Triones Technologies, Inc.
761 */
abc4ad4c 762static int hpt366_ide_dma_lostirq(ide_drive_t *drive)
1da177e4 763{
abc4ad4c
SS
764 struct pci_dev *dev = HWIF(drive)->pci_dev;
765 u8 mcr1 = 0, mcr3 = 0, scr1 = 0;
766
767 pci_read_config_byte(dev, 0x50, &mcr1);
768 pci_read_config_byte(dev, 0x52, &mcr3);
769 pci_read_config_byte(dev, 0x5a, &scr1);
770 printk("%s: (%s) mcr1=0x%02x, mcr3=0x%02x, scr1=0x%02x\n",
771 drive->name, __FUNCTION__, mcr1, mcr3, scr1);
772 if (scr1 & 0x10)
773 pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
1da177e4
LT
774 return __ide_dma_lostirq(drive);
775}
776
4bf63de2 777static void hpt370_clear_engine(ide_drive_t *drive)
1da177e4 778{
abc4ad4c
SS
779 ide_hwif_t *hwif = HWIF(drive);
780
781 pci_write_config_byte(hwif->pci_dev, hwif->select_data, 0x37);
1da177e4
LT
782 udelay(10);
783}
784
4bf63de2
SS
785static void hpt370_irq_timeout(ide_drive_t *drive)
786{
787 ide_hwif_t *hwif = HWIF(drive);
788 u16 bfifo = 0;
789 u8 dma_cmd;
790
791 pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo);
792 printk(KERN_DEBUG "%s: %d bytes in FIFO\n", drive->name, bfifo & 0x1ff);
793
794 /* get DMA command mode */
795 dma_cmd = hwif->INB(hwif->dma_command);
796 /* stop DMA */
797 hwif->OUTB(dma_cmd & ~0x1, hwif->dma_command);
798 hpt370_clear_engine(drive);
799}
800
1da177e4
LT
801static void hpt370_ide_dma_start(ide_drive_t *drive)
802{
803#ifdef HPT_RESET_STATE_ENGINE
804 hpt370_clear_engine(drive);
805#endif
806 ide_dma_start(drive);
807}
808
4bf63de2 809static int hpt370_ide_dma_end(ide_drive_t *drive)
1da177e4
LT
810{
811 ide_hwif_t *hwif = HWIF(drive);
4bf63de2 812 u8 dma_stat = hwif->INB(hwif->dma_status);
1da177e4
LT
813
814 if (dma_stat & 0x01) {
815 /* wait a little */
816 udelay(20);
817 dma_stat = hwif->INB(hwif->dma_status);
4bf63de2
SS
818 if (dma_stat & 0x01)
819 hpt370_irq_timeout(drive);
1da177e4 820 }
1da177e4
LT
821 return __ide_dma_end(drive);
822}
823
4bf63de2 824static int hpt370_ide_dma_timeout(ide_drive_t *drive)
1da177e4 825{
4bf63de2 826 hpt370_irq_timeout(drive);
1da177e4
LT
827 return __ide_dma_timeout(drive);
828}
829
1da177e4
LT
830/* returns 1 if DMA IRQ issued, 0 otherwise */
831static int hpt374_ide_dma_test_irq(ide_drive_t *drive)
832{
833 ide_hwif_t *hwif = HWIF(drive);
834 u16 bfifo = 0;
abc4ad4c 835 u8 dma_stat;
1da177e4 836
abc4ad4c 837 pci_read_config_word(hwif->pci_dev, hwif->select_data + 2, &bfifo);
1da177e4
LT
838 if (bfifo & 0x1FF) {
839// printk("%s: %d bytes in FIFO\n", drive->name, bfifo);
840 return 0;
841 }
842
843 dma_stat = hwif->INB(hwif->dma_status);
844 /* return 1 if INTR asserted */
abc4ad4c 845 if (dma_stat & 4)
1da177e4
LT
846 return 1;
847
848 if (!drive->waiting_for_dma)
849 printk(KERN_WARNING "%s: (%s) called while not waiting\n",
850 drive->name, __FUNCTION__);
851 return 0;
852}
853
abc4ad4c 854static int hpt374_ide_dma_end(ide_drive_t *drive)
1da177e4 855{
1da177e4 856 ide_hwif_t *hwif = HWIF(drive);
abc4ad4c
SS
857 struct pci_dev *dev = hwif->pci_dev;
858 u8 mcr = 0, mcr_addr = hwif->select_data;
859 u8 bwsr = 0, mask = hwif->channel ? 0x02 : 0x01;
860
861 pci_read_config_byte(dev, 0x6a, &bwsr);
862 pci_read_config_byte(dev, mcr_addr, &mcr);
863 if (bwsr & mask)
864 pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
1da177e4
LT
865 return __ide_dma_end(drive);
866}
867
868/**
836c0063
SS
869 * hpt3xxn_set_clock - perform clock switching dance
870 * @hwif: hwif to switch
871 * @mode: clocking mode (0x21 for write, 0x23 otherwise)
1da177e4 872 *
836c0063 873 * Switch the DPLL clock on the HPT3xxN devices. This is a right mess.
1da177e4 874 */
836c0063
SS
875
876static void hpt3xxn_set_clock(ide_hwif_t *hwif, u8 mode)
1da177e4 877{
7b73ee05 878 u8 scr2 = hwif->INB(hwif->dma_master + 0x7b);
836c0063
SS
879
880 if ((scr2 & 0x7f) == mode)
881 return;
882
1da177e4 883 /* Tristate the bus */
7b73ee05 884 hwif->OUTB(0x80, hwif->dma_master + 0x73);
836c0063
SS
885 hwif->OUTB(0x80, hwif->dma_master + 0x77);
886
1da177e4 887 /* Switch clock and reset channels */
836c0063
SS
888 hwif->OUTB(mode, hwif->dma_master + 0x7b);
889 hwif->OUTB(0xc0, hwif->dma_master + 0x79);
890
7b73ee05
SS
891 /*
892 * Reset the state machines.
893 * NOTE: avoid accidentally enabling the disabled channels.
894 */
895 hwif->OUTB(hwif->INB(hwif->dma_master + 0x70) | 0x32,
896 hwif->dma_master + 0x70);
897 hwif->OUTB(hwif->INB(hwif->dma_master + 0x74) | 0x32,
898 hwif->dma_master + 0x74);
836c0063 899
1da177e4 900 /* Complete reset */
836c0063
SS
901 hwif->OUTB(0x00, hwif->dma_master + 0x79);
902
1da177e4 903 /* Reconnect channels to bus */
7b73ee05 904 hwif->OUTB(0x00, hwif->dma_master + 0x73);
836c0063 905 hwif->OUTB(0x00, hwif->dma_master + 0x77);
1da177e4
LT
906}
907
908/**
836c0063 909 * hpt3xxn_rw_disk - prepare for I/O
1da177e4
LT
910 * @drive: drive for command
911 * @rq: block request structure
912 *
836c0063 913 * This is called when a disk I/O is issued to HPT3xxN.
1da177e4
LT
914 * We need it because of the clock switching.
915 */
916
836c0063 917static void hpt3xxn_rw_disk(ide_drive_t *drive, struct request *rq)
1da177e4 918{
7b73ee05 919 hpt3xxn_set_clock(HWIF(drive), rq_data_dir(rq) ? 0x23 : 0x21);
1da177e4
LT
920}
921
1da177e4 922/*
33b18a60 923 * Set/get power state for a drive.
abc4ad4c 924 * NOTE: affects both drives on each channel.
1da177e4 925 *
33b18a60 926 * When we turn the power back on, we need to re-initialize things.
1da177e4
LT
927 */
928#define TRISTATE_BIT 0x8000
33b18a60
SS
929
930static int hpt3xx_busproc(ide_drive_t *drive, int state)
1da177e4 931{
abc4ad4c 932 ide_hwif_t *hwif = HWIF(drive);
1da177e4 933 struct pci_dev *dev = hwif->pci_dev;
abc4ad4c
SS
934 u8 mcr_addr = hwif->select_data + 2;
935 u8 resetmask = hwif->channel ? 0x80 : 0x40;
936 u8 bsr2 = 0;
937 u16 mcr = 0;
1da177e4
LT
938
939 hwif->bus_state = state;
940
33b18a60 941 /* Grab the status. */
abc4ad4c
SS
942 pci_read_config_word(dev, mcr_addr, &mcr);
943 pci_read_config_byte(dev, 0x59, &bsr2);
1da177e4 944
33b18a60
SS
945 /*
946 * Set the state. We don't set it if we don't need to do so.
947 * Make sure that the drive knows that it has failed if it's off.
948 */
1da177e4
LT
949 switch (state) {
950 case BUSSTATE_ON:
abc4ad4c 951 if (!(bsr2 & resetmask))
1da177e4 952 return 0;
33b18a60
SS
953 hwif->drives[0].failures = hwif->drives[1].failures = 0;
954
abc4ad4c
SS
955 pci_write_config_byte(dev, 0x59, bsr2 & ~resetmask);
956 pci_write_config_word(dev, mcr_addr, mcr & ~TRISTATE_BIT);
33b18a60 957 return 0;
1da177e4 958 case BUSSTATE_OFF:
abc4ad4c 959 if ((bsr2 & resetmask) && !(mcr & TRISTATE_BIT))
1da177e4 960 return 0;
abc4ad4c 961 mcr &= ~TRISTATE_BIT;
1da177e4
LT
962 break;
963 case BUSSTATE_TRISTATE:
abc4ad4c 964 if ((bsr2 & resetmask) && (mcr & TRISTATE_BIT))
1da177e4 965 return 0;
abc4ad4c 966 mcr |= TRISTATE_BIT;
1da177e4 967 break;
33b18a60
SS
968 default:
969 return -EINVAL;
1da177e4 970 }
1da177e4 971
33b18a60
SS
972 hwif->drives[0].failures = hwif->drives[0].max_failures + 1;
973 hwif->drives[1].failures = hwif->drives[1].max_failures + 1;
974
abc4ad4c
SS
975 pci_write_config_word(dev, mcr_addr, mcr);
976 pci_write_config_byte(dev, 0x59, bsr2 | resetmask);
1da177e4
LT
977 return 0;
978}
979
7b73ee05
SS
980/**
981 * hpt37x_calibrate_dpll - calibrate the DPLL
982 * @dev: PCI device
983 *
984 * Perform a calibration cycle on the DPLL.
985 * Returns 1 if this succeeds
986 */
987static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f_high)
1da177e4 988{
7b73ee05
SS
989 u32 dpll = (f_high << 16) | f_low | 0x100;
990 u8 scr2;
991 int i;
b39b01ff 992
7b73ee05 993 pci_write_config_dword(dev, 0x5c, dpll);
b39b01ff 994
7b73ee05
SS
995 /* Wait for oscillator ready */
996 for(i = 0; i < 0x5000; ++i) {
997 udelay(50);
998 pci_read_config_byte(dev, 0x5b, &scr2);
999 if (scr2 & 0x80)
b39b01ff
AC
1000 break;
1001 }
7b73ee05
SS
1002 /* See if it stays ready (we'll just bail out if it's not yet) */
1003 for(i = 0; i < 0x1000; ++i) {
1004 pci_read_config_byte(dev, 0x5b, &scr2);
1005 /* DPLL destabilized? */
1006 if(!(scr2 & 0x80))
1007 return 0;
1008 }
1009 /* Turn off tuning, we have the DPLL set */
1010 pci_read_config_dword (dev, 0x5c, &dpll);
1011 pci_write_config_dword(dev, 0x5c, (dpll & ~0x100));
1012 return 1;
b39b01ff
AC
1013}
1014
7b73ee05 1015static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name)
b39b01ff 1016{
7b73ee05
SS
1017 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
1018 unsigned long io_base = pci_resource_start(dev, 4);
1019 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
1020 enum ata_clock clock;
1021
1022 if (info == NULL) {
1023 printk(KERN_ERR "%s: out of memory!\n", name);
1024 return -ENOMEM;
1025 }
1026
1da177e4 1027 /*
7b73ee05
SS
1028 * Copy everything from a static "template" structure
1029 * to just allocated per-chip hpt_info structure.
1da177e4 1030 */
7b73ee05 1031 *info = *(struct hpt_info *)pci_get_drvdata(dev);
1da177e4
LT
1032
1033 /*
7b73ee05
SS
1034 * FIXME: Not portable. Also, why do we enable the ROM in the first place?
1035 * We don't seem to be using it.
1da177e4 1036 */
7b73ee05
SS
1037 if (dev->resource[PCI_ROM_RESOURCE].start)
1038 pci_write_config_dword(dev, PCI_ROM_ADDRESS,
1039 dev->resource[PCI_ROM_RESOURCE].start | PCI_ROM_ADDRESS_ENABLE);
1040
1041 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
1042 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0x78);
1043 pci_write_config_byte(dev, PCI_MIN_GNT, 0x08);
1044 pci_write_config_byte(dev, PCI_MAX_LAT, 0x08);
26c068da 1045
1da177e4 1046 /*
7b73ee05 1047 * First, try to estimate the PCI clock frequency...
1da177e4 1048 */
7b73ee05
SS
1049 if (info->chip_type >= HPT370) {
1050 u8 scr1 = 0;
1051 u16 f_cnt = 0;
1052 u32 temp = 0;
1053
1054 /* Interrupt force enable. */
1055 pci_read_config_byte(dev, 0x5a, &scr1);
1056 if (scr1 & 0x10)
1057 pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
1058
1059 /*
1060 * HighPoint does this for HPT372A.
1061 * NOTE: This register is only writeable via I/O space.
1062 */
1063 if (info->chip_type == HPT372A)
1064 outb(0x0e, io_base + 0x9c);
1065
1066 /*
1067 * Default to PCI clock. Make sure MA15/16 are set to output
1068 * to prevent drives having problems with 40-pin cables.
1069 */
1070 pci_write_config_byte(dev, 0x5b, 0x23);
836c0063 1071
7b73ee05
SS
1072 /*
1073 * We'll have to read f_CNT value in order to determine
1074 * the PCI clock frequency according to the following ratio:
1075 *
1076 * f_CNT = Fpci * 192 / Fdpll
1077 *
1078 * First try reading the register in which the HighPoint BIOS
1079 * saves f_CNT value before reprogramming the DPLL from its
1080 * default setting (which differs for the various chips).
1081 * NOTE: This register is only accessible via I/O space.
1082 *
1083 * In case the signature check fails, we'll have to resort to
1084 * reading the f_CNT register itself in hopes that nobody has
1085 * touched the DPLL yet...
1086 */
1087 temp = inl(io_base + 0x90);
1088 if ((temp & 0xFFFFF000) != 0xABCDE000) {
1089 int i;
1090
1091 printk(KERN_WARNING "%s: no clock data saved by BIOS\n",
1092 name);
1093
1094 /* Calculate the average value of f_CNT. */
1095 for (temp = i = 0; i < 128; i++) {
1096 pci_read_config_word(dev, 0x78, &f_cnt);
1097 temp += f_cnt & 0x1ff;
1098 mdelay(1);
1099 }
1100 f_cnt = temp / 128;
1101 } else
1102 f_cnt = temp & 0x1ff;
1103
1104 dpll_clk = info->dpll_clk;
1105 pci_clk = (f_cnt * dpll_clk) / 192;
1106
1107 /* Clamp PCI clock to bands. */
1108 if (pci_clk < 40)
1109 pci_clk = 33;
1110 else if(pci_clk < 45)
1111 pci_clk = 40;
1112 else if(pci_clk < 55)
1113 pci_clk = 50;
1da177e4 1114 else
7b73ee05 1115 pci_clk = 66;
836c0063 1116
7b73ee05
SS
1117 printk(KERN_INFO "%s: DPLL base: %d MHz, f_CNT: %d, "
1118 "assuming %d MHz PCI\n", name, dpll_clk, f_cnt, pci_clk);
90778574 1119 } else {
7b73ee05
SS
1120 u32 itr1 = 0;
1121
1122 pci_read_config_dword(dev, 0x40, &itr1);
1123
1124 /* Detect PCI clock by looking at cmd_high_time. */
1125 switch((itr1 >> 8) & 0x07) {
1126 case 0x09:
1127 pci_clk = 40;
1128 case 0x05:
1129 pci_clk = 25;
1130 case 0x07:
1131 default:
1132 pci_clk = 33;
1da177e4
LT
1133 }
1134 }
836c0063 1135
7b73ee05
SS
1136 /* Let's assume we'll use PCI clock for the ATA clock... */
1137 switch (pci_clk) {
1138 case 25:
1139 clock = ATA_CLOCK_25MHZ;
1140 break;
1141 case 33:
1142 default:
1143 clock = ATA_CLOCK_33MHZ;
1144 break;
1145 case 40:
1146 clock = ATA_CLOCK_40MHZ;
1147 break;
1148 case 50:
1149 clock = ATA_CLOCK_50MHZ;
1150 break;
1151 case 66:
1152 clock = ATA_CLOCK_66MHZ;
1153 break;
1154 }
836c0063 1155
1da177e4 1156 /*
7b73ee05
SS
1157 * Only try the DPLL if we don't have a table for the PCI clock that
1158 * we are running at for HPT370/A, always use it for anything newer...
b39b01ff 1159 *
7b73ee05
SS
1160 * NOTE: Using the internal DPLL results in slow reads on 33 MHz PCI.
1161 * We also don't like using the DPLL because this causes glitches
1162 * on PRST-/SRST- when the state engine gets reset...
1da177e4 1163 */
7b73ee05
SS
1164 if (info->chip_type >= HPT374 || info->settings[clock] == NULL) {
1165 u16 f_low, delta = pci_clk < 50 ? 2 : 4;
1166 int adjust;
1167
1168 /*
1169 * Select 66 MHz DPLL clock only if UltraATA/133 mode is
1170 * supported/enabled, use 50 MHz DPLL clock otherwise...
1171 */
1172 if (info->max_mode == 0x04) {
1173 dpll_clk = 66;
1174 clock = ATA_CLOCK_66MHZ;
1175 } else if (dpll_clk) { /* HPT36x chips don't have DPLL */
1176 dpll_clk = 50;
1177 clock = ATA_CLOCK_50MHZ;
1178 }
b39b01ff 1179
7b73ee05
SS
1180 if (info->settings[clock] == NULL) {
1181 printk(KERN_ERR "%s: unknown bus timing!\n", name);
1182 kfree(info);
1183 return -EIO;
1da177e4 1184 }
1da177e4 1185
7b73ee05
SS
1186 /* Select the DPLL clock. */
1187 pci_write_config_byte(dev, 0x5b, 0x21);
1188
1189 /*
1190 * Adjust the DPLL based upon PCI clock, enable it,
1191 * and wait for stabilization...
1192 */
1193 f_low = (pci_clk * 48) / dpll_clk;
1194
1195 for (adjust = 0; adjust < 8; adjust++) {
1196 if(hpt37x_calibrate_dpll(dev, f_low, f_low + delta))
1197 break;
1198
1199 /*
1200 * See if it'll settle at a fractionally different clock
1201 */
1202 if (adjust & 1)
1203 f_low -= adjust >> 1;
1204 else
1205 f_low += adjust >> 1;
1206 }
1207 if (adjust == 8) {
1208 printk(KERN_ERR "%s: DPLL did not stabilize!\n", name);
1209 kfree(info);
1210 return -EIO;
1211 }
1212
1213 printk("%s: using %d MHz DPLL clock\n", name, dpll_clk);
1214 } else {
1215 /* Mark the fact that we're not using the DPLL. */
1216 dpll_clk = 0;
1217
1218 printk("%s: using %d MHz PCI clock\n", name, pci_clk);
1219 }
b39b01ff 1220
9ec4ff42 1221 /*
7b73ee05
SS
1222 * Advance the table pointer to a slot which points to the list
1223 * of the register values settings matching the clock being used.
9ec4ff42 1224 */
7b73ee05 1225 info->settings += clock;
1da177e4 1226
7b73ee05
SS
1227 /* Store the clock frequencies. */
1228 info->dpll_clk = dpll_clk;
1229 info->pci_clk = pci_clk;
1da177e4 1230
7b73ee05
SS
1231 /* Point to this chip's own instance of the hpt_info structure. */
1232 pci_set_drvdata(dev, info);
b39b01ff 1233
7b73ee05
SS
1234 if (info->chip_type >= HPT370) {
1235 u8 mcr1, mcr4;
1236
1237 /*
1238 * Reset the state engines.
1239 * NOTE: Avoid accidentally enabling the disabled channels.
1240 */
1241 pci_read_config_byte (dev, 0x50, &mcr1);
1242 pci_read_config_byte (dev, 0x54, &mcr4);
1243 pci_write_config_byte(dev, 0x50, (mcr1 | 0x32));
1244 pci_write_config_byte(dev, 0x54, (mcr4 | 0x32));
1245 udelay(100);
26ccb802 1246 }
1da177e4 1247
7b73ee05
SS
1248 /*
1249 * On HPT371N, if ATA clock is 66 MHz we must set bit 2 in
1250 * the MISC. register to stretch the UltraDMA Tss timing.
1251 * NOTE: This register is only writeable via I/O space.
1252 */
1253 if (info->chip_type == HPT371N && clock == ATA_CLOCK_66MHZ)
1254
1255 outb(inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
1256
1da177e4
LT
1257 return dev->irq;
1258}
1259
1260static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1261{
26ccb802 1262 struct pci_dev *dev = hwif->pci_dev;
7b73ee05 1263 struct hpt_info *info = pci_get_drvdata(dev);
836c0063 1264 int serialize = HPT_SERIALIZE_IO;
abc4ad4c 1265 u8 scr1 = 0, ata66 = (hwif->channel) ? 0x01 : 0x02;
7b73ee05 1266 u8 chip_type = info->chip_type;
26ccb802 1267 u8 new_mcr, old_mcr = 0;
abc4ad4c
SS
1268
1269 /* Cache the channel's MISC. control registers' offset */
1270 hwif->select_data = hwif->channel ? 0x54 : 0x50;
1271
1da177e4
LT
1272 hwif->tuneproc = &hpt3xx_tune_drive;
1273 hwif->speedproc = &hpt3xx_tune_chipset;
1274 hwif->quirkproc = &hpt3xx_quirkproc;
1275 hwif->intrproc = &hpt3xx_intrproc;
1276 hwif->maskproc = &hpt3xx_maskproc;
abc4ad4c
SS
1277 hwif->busproc = &hpt3xx_busproc;
1278
836c0063
SS
1279 /*
1280 * HPT3xxN chips have some complications:
1281 *
1282 * - on 33 MHz PCI we must clock switch
1283 * - on 66 MHz PCI we must NOT use the PCI clock
1284 */
7b73ee05 1285 if (chip_type >= HPT372N && info->dpll_clk && info->pci_clk < 66) {
836c0063
SS
1286 /*
1287 * Clock is shared between the channels,
1288 * so we'll have to serialize them... :-(
1289 */
1290 serialize = 1;
1291 hwif->rw_disk = &hpt3xxn_rw_disk;
1292 }
1da177e4 1293
26ccb802
SS
1294 /* Serialize access to this device if needed */
1295 if (serialize && hwif->mate)
1296 hwif->serialized = hwif->mate->serialized = 1;
1297
1298 /*
1299 * Disable the "fast interrupt" prediction. Don't hold off
1300 * on interrupts. (== 0x01 despite what the docs say)
1301 */
1302 pci_read_config_byte(dev, hwif->select_data + 1, &old_mcr);
1303
7b73ee05 1304 if (info->chip_type >= HPT374)
26ccb802 1305 new_mcr = old_mcr & ~0x07;
7b73ee05 1306 else if (info->chip_type >= HPT370) {
26ccb802
SS
1307 new_mcr = old_mcr;
1308 new_mcr &= ~0x02;
1309
1310#ifdef HPT_DELAY_INTERRUPT
1311 new_mcr &= ~0x01;
1312#else
1313 new_mcr |= 0x01;
1314#endif
1315 } else /* HPT366 and HPT368 */
1316 new_mcr = old_mcr & ~0x80;
1317
1318 if (new_mcr != old_mcr)
1319 pci_write_config_byte(dev, hwif->select_data + 1, new_mcr);
1320
1321 if (!hwif->dma_base) {
1322 hwif->drives[0].autotune = hwif->drives[1].autotune = 1;
1323 return;
1324 }
1325
1326 hwif->ultra_mask = 0x7f;
1327 hwif->mwdma_mask = 0x07;
1328
1da177e4
LT
1329 /*
1330 * The HPT37x uses the CBLID pins as outputs for MA15/MA16
abc4ad4c 1331 * address lines to access an external EEPROM. To read valid
1da177e4
LT
1332 * cable detect state the pins must be enabled as inputs.
1333 */
7b73ee05 1334 if (chip_type == HPT374 && (PCI_FUNC(dev->devfn) & 1)) {
1da177e4
LT
1335 /*
1336 * HPT374 PCI function 1
1337 * - set bit 15 of reg 0x52 to enable TCBLID as input
1338 * - set bit 15 of reg 0x56 to enable FCBLID as input
1339 */
abc4ad4c
SS
1340 u8 mcr_addr = hwif->select_data + 2;
1341 u16 mcr;
1342
1343 pci_read_config_word (dev, mcr_addr, &mcr);
1344 pci_write_config_word(dev, mcr_addr, (mcr | 0x8000));
1da177e4 1345 /* now read cable id register */
abc4ad4c
SS
1346 pci_read_config_byte (dev, 0x5a, &scr1);
1347 pci_write_config_word(dev, mcr_addr, mcr);
7b73ee05 1348 } else if (chip_type >= HPT370) {
1da177e4
LT
1349 /*
1350 * HPT370/372 and 374 pcifn 0
abc4ad4c 1351 * - clear bit 0 of reg 0x5b to enable P/SCBLID as inputs
1da177e4 1352 */
abc4ad4c 1353 u8 scr2 = 0;
1da177e4 1354
abc4ad4c
SS
1355 pci_read_config_byte (dev, 0x5b, &scr2);
1356 pci_write_config_byte(dev, 0x5b, (scr2 & ~1));
1357 /* now read cable id register */
1358 pci_read_config_byte (dev, 0x5a, &scr1);
1359 pci_write_config_byte(dev, 0x5b, scr2);
1360 } else
1361 pci_read_config_byte (dev, 0x5a, &scr1);
1da177e4 1362
26ccb802
SS
1363 if (!hwif->udma_four)
1364 hwif->udma_four = (scr1 & ata66) ? 0 : 1;
1da177e4 1365
26ccb802 1366 hwif->ide_dma_check = &hpt366_config_drive_xfer_rate;
1da177e4 1367
7b73ee05 1368 if (chip_type >= HPT374) {
26ccb802
SS
1369 hwif->ide_dma_test_irq = &hpt374_ide_dma_test_irq;
1370 hwif->ide_dma_end = &hpt374_ide_dma_end;
7b73ee05 1371 } else if (chip_type >= HPT370) {
26ccb802
SS
1372 hwif->dma_start = &hpt370_ide_dma_start;
1373 hwif->ide_dma_end = &hpt370_ide_dma_end;
1374 hwif->ide_dma_timeout = &hpt370_ide_dma_timeout;
26ccb802
SS
1375 } else
1376 hwif->ide_dma_lostirq = &hpt366_ide_dma_lostirq;
1da177e4
LT
1377
1378 if (!noautodma)
1379 hwif->autodma = 1;
26ccb802 1380 hwif->drives[0].autodma = hwif->drives[1].autodma = hwif->autodma;
1da177e4
LT
1381}
1382
1383static void __devinit init_dma_hpt366(ide_hwif_t *hwif, unsigned long dmabase)
1384{
26ccb802 1385 struct pci_dev *dev = hwif->pci_dev;
abc4ad4c
SS
1386 u8 masterdma = 0, slavedma = 0;
1387 u8 dma_new = 0, dma_old = 0;
1da177e4
LT
1388 unsigned long flags;
1389
1390 if (!dmabase)
1391 return;
1392
26ccb802 1393 dma_old = hwif->INB(dmabase + 2);
1da177e4
LT
1394
1395 local_irq_save(flags);
1396
1397 dma_new = dma_old;
abc4ad4c
SS
1398 pci_read_config_byte(dev, hwif->channel ? 0x4b : 0x43, &masterdma);
1399 pci_read_config_byte(dev, hwif->channel ? 0x4f : 0x47, &slavedma);
1da177e4
LT
1400
1401 if (masterdma & 0x30) dma_new |= 0x20;
abc4ad4c 1402 if ( slavedma & 0x30) dma_new |= 0x40;
1da177e4 1403 if (dma_new != dma_old)
abc4ad4c 1404 hwif->OUTB(dma_new, dmabase + 2);
1da177e4
LT
1405
1406 local_irq_restore(flags);
1407
1408 ide_setup_dma(hwif, dmabase, 8);
1409}
1410
1411static int __devinit init_setup_hpt374(struct pci_dev *dev, ide_pci_device_t *d)
1412{
b4586715 1413 struct pci_dev *dev2;
1da177e4
LT
1414
1415 if (PCI_FUNC(dev->devfn) & 1)
1416 return -ENODEV;
1417
7b73ee05
SS
1418 pci_set_drvdata(dev, &hpt374);
1419
b4586715
SS
1420 if ((dev2 = pci_get_slot(dev->bus, dev->devfn + 1)) != NULL) {
1421 int ret;
1422
7b73ee05
SS
1423 pci_set_drvdata(dev2, &hpt374);
1424
b4586715
SS
1425 if (dev2->irq != dev->irq) {
1426 /* FIXME: we need a core pci_set_interrupt() */
1427 dev2->irq = dev->irq;
1428 printk(KERN_WARNING "%s: PCI config space interrupt "
1429 "fixed.\n", d->name);
1da177e4 1430 }
b4586715
SS
1431 ret = ide_setup_pci_devices(dev, dev2, d);
1432 if (ret < 0)
1433 pci_dev_put(dev2);
1434 return ret;
1da177e4
LT
1435 }
1436 return ide_setup_pci_device(dev, d);
1437}
1438
90778574 1439static int __devinit init_setup_hpt372n(struct pci_dev *dev, ide_pci_device_t *d)
1da177e4 1440{
7b73ee05
SS
1441 pci_set_drvdata(dev, &hpt372n);
1442
1da177e4
LT
1443 return ide_setup_pci_device(dev, d);
1444}
1445
836c0063
SS
1446static int __devinit init_setup_hpt371(struct pci_dev *dev, ide_pci_device_t *d)
1447{
7b73ee05 1448 struct hpt_info *info;
90778574
SS
1449 u8 rev = 0, mcr1 = 0;
1450
1451 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
1452
7b73ee05 1453 if (rev > 1) {
90778574 1454 d->name = "HPT371N";
836c0063 1455
7b73ee05
SS
1456 info = &hpt371n;
1457 } else
1458 info = &hpt371;
1459
836c0063
SS
1460 /*
1461 * HPT371 chips physically have only one channel, the secondary one,
1462 * but the primary channel registers do exist! Go figure...
1463 * So, we manually disable the non-existing channel here
1464 * (if the BIOS hasn't done this already).
1465 */
1466 pci_read_config_byte(dev, 0x50, &mcr1);
1467 if (mcr1 & 0x04)
90778574
SS
1468 pci_write_config_byte(dev, 0x50, mcr1 & ~0x04);
1469
7b73ee05
SS
1470 pci_set_drvdata(dev, info);
1471
90778574
SS
1472 return ide_setup_pci_device(dev, d);
1473}
1474
1475static int __devinit init_setup_hpt372a(struct pci_dev *dev, ide_pci_device_t *d)
1476{
7b73ee05 1477 struct hpt_info *info;
90778574
SS
1478 u8 rev = 0;
1479
1480 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
1481
7b73ee05 1482 if (rev > 1) {
90778574
SS
1483 d->name = "HPT372N";
1484
7b73ee05
SS
1485 info = &hpt372n;
1486 } else
1487 info = &hpt372a;
1488 pci_set_drvdata(dev, info);
1489
90778574
SS
1490 return ide_setup_pci_device(dev, d);
1491}
1492
1493static int __devinit init_setup_hpt302(struct pci_dev *dev, ide_pci_device_t *d)
1494{
7b73ee05 1495 struct hpt_info *info;
90778574
SS
1496 u8 rev = 0;
1497
1498 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
1499
7b73ee05 1500 if (rev > 1) {
90778574 1501 d->name = "HPT302N";
836c0063 1502
7b73ee05
SS
1503 info = &hpt302n;
1504 } else
1505 info = &hpt302;
1506 pci_set_drvdata(dev, info);
1507
836c0063
SS
1508 return ide_setup_pci_device(dev, d);
1509}
1510
1da177e4
LT
1511static int __devinit init_setup_hpt366(struct pci_dev *dev, ide_pci_device_t *d)
1512{
b4586715
SS
1513 struct pci_dev *dev2;
1514 u8 rev = 0;
90778574
SS
1515 static char *chipset_names[] = { "HPT366", "HPT366", "HPT368",
1516 "HPT370", "HPT370A", "HPT372",
1517 "HPT372N" };
7b73ee05
SS
1518 static struct hpt_info *info[] = { &hpt36x, &hpt36x, &hpt36x,
1519 &hpt370, &hpt370a, &hpt372,
1520 &hpt372n };
1da177e4
LT
1521
1522 if (PCI_FUNC(dev->devfn) & 1)
1523 return -ENODEV;
1524
e139b0b0 1525 pci_read_config_byte(dev, PCI_REVISION_ID, &rev);
1da177e4 1526
90778574 1527 if (rev > 6)
e139b0b0 1528 rev = 6;
1da177e4 1529
90778574 1530 d->name = chipset_names[rev];
1da177e4 1531
7b73ee05
SS
1532 pci_set_drvdata(dev, info[rev]);
1533
90778574
SS
1534 if (rev > 2)
1535 goto init_single;
1da177e4
LT
1536
1537 d->channels = 1;
1538
b4586715
SS
1539 if ((dev2 = pci_get_slot(dev->bus, dev->devfn + 1)) != NULL) {
1540 u8 pin1 = 0, pin2 = 0;
1541 int ret;
1542
7b73ee05
SS
1543 pci_set_drvdata(dev2, info[rev]);
1544
b4586715
SS
1545 pci_read_config_byte(dev, PCI_INTERRUPT_PIN, &pin1);
1546 pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2);
1547 if (pin1 != pin2 && dev->irq == dev2->irq) {
1548 d->bootable = ON_BOARD;
1549 printk("%s: onboard version of chipset, pin1=%d pin2=%d\n",
1550 d->name, pin1, pin2);
1da177e4 1551 }
b4586715
SS
1552 ret = ide_setup_pci_devices(dev, dev2, d);
1553 if (ret < 0)
1554 pci_dev_put(dev2);
1555 return ret;
1da177e4
LT
1556 }
1557init_single:
1558 return ide_setup_pci_device(dev, d);
1559}
1560
1561static ide_pci_device_t hpt366_chipsets[] __devinitdata = {
1562 { /* 0 */
1563 .name = "HPT366",
1564 .init_setup = init_setup_hpt366,
1565 .init_chipset = init_chipset_hpt366,
1566 .init_hwif = init_hwif_hpt366,
1567 .init_dma = init_dma_hpt366,
1568 .channels = 2,
1569 .autodma = AUTODMA,
7b73ee05 1570 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4
LT
1571 .bootable = OFF_BOARD,
1572 .extra = 240
1573 },{ /* 1 */
1574 .name = "HPT372A",
90778574 1575 .init_setup = init_setup_hpt372a,
1da177e4
LT
1576 .init_chipset = init_chipset_hpt366,
1577 .init_hwif = init_hwif_hpt366,
1578 .init_dma = init_dma_hpt366,
1579 .channels = 2,
1580 .autodma = AUTODMA,
7b73ee05 1581 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4 1582 .bootable = OFF_BOARD,
90778574 1583 .extra = 240
1da177e4
LT
1584 },{ /* 2 */
1585 .name = "HPT302",
90778574 1586 .init_setup = init_setup_hpt302,
1da177e4
LT
1587 .init_chipset = init_chipset_hpt366,
1588 .init_hwif = init_hwif_hpt366,
1589 .init_dma = init_dma_hpt366,
1590 .channels = 2,
1591 .autodma = AUTODMA,
7b73ee05 1592 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4 1593 .bootable = OFF_BOARD,
90778574 1594 .extra = 240
1da177e4
LT
1595 },{ /* 3 */
1596 .name = "HPT371",
836c0063 1597 .init_setup = init_setup_hpt371,
1da177e4
LT
1598 .init_chipset = init_chipset_hpt366,
1599 .init_hwif = init_hwif_hpt366,
1600 .init_dma = init_dma_hpt366,
1601 .channels = 2,
1602 .autodma = AUTODMA,
836c0063 1603 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4 1604 .bootable = OFF_BOARD,
90778574 1605 .extra = 240
1da177e4
LT
1606 },{ /* 4 */
1607 .name = "HPT374",
1608 .init_setup = init_setup_hpt374,
1609 .init_chipset = init_chipset_hpt366,
1610 .init_hwif = init_hwif_hpt366,
1611 .init_dma = init_dma_hpt366,
1612 .channels = 2, /* 4 */
1613 .autodma = AUTODMA,
7b73ee05 1614 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4 1615 .bootable = OFF_BOARD,
90778574 1616 .extra = 240
1da177e4
LT
1617 },{ /* 5 */
1618 .name = "HPT372N",
90778574 1619 .init_setup = init_setup_hpt372n,
1da177e4
LT
1620 .init_chipset = init_chipset_hpt366,
1621 .init_hwif = init_hwif_hpt366,
1622 .init_dma = init_dma_hpt366,
1623 .channels = 2, /* 4 */
1624 .autodma = AUTODMA,
7b73ee05 1625 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1da177e4 1626 .bootable = OFF_BOARD,
90778574 1627 .extra = 240
1da177e4
LT
1628 }
1629};
1630
1631/**
1632 * hpt366_init_one - called when an HPT366 is found
1633 * @dev: the hpt366 device
1634 * @id: the matching pci id
1635 *
1636 * Called when the PCI registration layer (or the IDE initialization)
1637 * finds a device matching our IDE device tables.
73d1dd93
SS
1638 *
1639 * NOTE: since we'll have to modify some fields of the ide_pci_device_t
1640 * structure depending on the chip's revision, we'd better pass a local
1641 * copy down the call chain...
1da177e4 1642 */
1da177e4
LT
1643static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1644{
73d1dd93 1645 ide_pci_device_t d = hpt366_chipsets[id->driver_data];
1da177e4 1646
73d1dd93 1647 return d.init_setup(dev, &d);
1da177e4
LT
1648}
1649
1650static struct pci_device_id hpt366_pci_tbl[] = {
1651 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT366, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
1652 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1},
1653 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT302, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 2},
1654 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 3},
1655 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT374, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 4},
1656 { PCI_VENDOR_ID_TTI, PCI_DEVICE_ID_TTI_HPT372N, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 5},
1657 { 0, },
1658};
1659MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
1660
1661static struct pci_driver driver = {
1662 .name = "HPT366_IDE",
1663 .id_table = hpt366_pci_tbl,
1664 .probe = hpt366_init_one,
1665};
1666
82ab1eec 1667static int __init hpt366_ide_init(void)
1da177e4
LT
1668{
1669 return ide_pci_register_driver(&driver);
1670}
1671
1672module_init(hpt366_ide_init);
1673
1674MODULE_AUTHOR("Andre Hedrick");
1675MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");
1676MODULE_LICENSE("GPL");
This page took 0.425679 seconds and 5 git commands to generate.