122 #include <linux/types.h>
123 #include <linux/module.h>
124 #include <linux/kernel.h>
128 #include <linux/pci.h>
131 #include <linux/slab.h>
133 #include <asm/uaccess.h>
136 #define DRV_NAME "hpt366"
139 #undef HPT_RESET_STATE_ENGINE
140 #undef HPT_DELAY_INTERRUPT
142 static const char *bad_ata100_5[] = {
161 static const char *bad_ata66_4[] = {
177 "MAXTOR STM3320620A",
181 static const char *bad_ata66_3[] = {
186 static const char *bad_ata33[] = {
187 "Maxtor 92720U8",
"Maxtor 92040U6",
"Maxtor 91360U4",
"Maxtor 91020U3",
"Maxtor 90845U3",
"Maxtor 90650U2",
188 "Maxtor 91360D8",
"Maxtor 91190D7",
"Maxtor 91020D6",
"Maxtor 90845D5",
"Maxtor 90680D4",
"Maxtor 90510D3",
"Maxtor 90340D2",
189 "Maxtor 91152D8",
"Maxtor 91008D7",
"Maxtor 90845D6",
"Maxtor 90840D6",
"Maxtor 90720D5",
"Maxtor 90648D5",
"Maxtor 90576D4",
191 "Maxtor 90432D3",
"Maxtor 90288D2",
"Maxtor 90256D2",
192 "Maxtor 91000D8",
"Maxtor 90910D8",
"Maxtor 90875D7",
"Maxtor 90840D7",
"Maxtor 90750D6",
"Maxtor 90625D5",
"Maxtor 90500D4",
193 "Maxtor 91728D8",
"Maxtor 91512D7",
"Maxtor 91303D6",
"Maxtor 91080D5",
"Maxtor 90845D4",
"Maxtor 90680D4",
"Maxtor 90648D3",
"Maxtor 90432D2",
197 static u8 xfer_speeds[] = {
241 static u32 forty_base_hpt36x[] = {
261 static u32 thirty_three_base_hpt36x[] = {
281 static u32 twenty_five_base_hpt36x[] = {
307 static u32 thirty_three_base_hpt37x[] = {
327 static u32 fifty_base_hpt37x[] = {
347 static u32 sixty_six_base_hpt37x[] = {
367 #define HPT371_ALLOW_ATA133_6 1
368 #define HPT302_ALLOW_ATA133_6 1
369 #define HPT372_ALLOW_ATA133_6 1
370 #define HPT370_ALLOW_ATA100_5 0
371 #define HPT366_ALLOW_ATA66_4 1
372 #define HPT366_ALLOW_ATA66_3 1
421 .pio_mask = 0xc1f8ffff,
422 .dma_mask = 0x303800ff,
423 .ultra_mask = 0x30070000,
434 .pio_mask = 0xcfc3ffff,
435 .dma_mask = 0x31c001ff,
436 .ultra_mask = 0x303c0000,
447 .chip_name =
"HPT36x",
454 static const struct hpt_info hpt370 __devinitconst = {
459 .timings = &hpt37x_timings
462 static const struct hpt_info hpt370a __devinitconst = {
467 .timings = &hpt37x_timings
470 static const struct hpt_info hpt374 __devinitconst = {
475 .timings = &hpt37x_timings
478 static const struct hpt_info hpt372 __devinitconst = {
483 .timings = &hpt37x_timings
486 static const struct hpt_info hpt372a __devinitconst = {
491 .timings = &hpt37x_timings
494 static const struct hpt_info hpt302 __devinitconst = {
499 .timings = &hpt37x_timings
502 static const struct hpt_info hpt371 __devinitconst = {
507 .timings = &hpt37x_timings
510 static const struct hpt_info hpt372n __devinitconst = {
515 .timings = &hpt37x_timings
518 static const struct hpt_info hpt302n __devinitconst = {
523 .timings = &hpt37x_timings
526 static const struct hpt_info hpt371n __devinitconst = {
531 .timings = &hpt37x_timings
549 return dev == host->
dev[1] ? info + 1 : info;
566 check_in_drive_list(drive, bad_ata66_4))
570 check_in_drive_list(drive, bad_ata66_3))
575 check_in_drive_list(drive, bad_ata100_5))
580 check_in_drive_list(drive, bad_ata100_5))
586 if (ata_id_is_sata(drive->
id))
593 return check_in_drive_list(drive, bad_ata33) ? 0x00 :
mask;
599 struct hpt_info *info = hpt3xx_get_info(hwif->
dev);
606 if (ata_id_is_sata(drive->
id))
614 static u32 get_speed_setting(
u8 speed,
struct hpt_info *info)
624 for (i = 0; i <
ARRAY_SIZE(xfer_speeds) - 1; i++)
625 if (xfer_speeds[i] == speed)
634 struct hpt_info *info = hpt3xx_get_info(hwif->
dev);
636 u8 itr_addr = 0x40 + (drive->
dn * 4);
639 u32 new_itr = get_speed_setting(speed, info);
644 pci_read_config_dword(dev, itr_addr, &old_itr);
645 new_itr = (old_itr & ~itr_mask) | (new_itr & itr_mask);
650 new_itr &= ~0xc0000000;
652 pci_write_config_dword(dev, itr_addr, new_itr);
658 hpt3xx_set_mode(hwif, drive);
661 static void hpt3xx_maskproc(
ide_drive_t *drive,
int mask)
665 struct hpt_info *info = hpt3xx_get_info(hwif->
dev);
673 pci_read_config_byte(dev, 0x5a, &scr1);
674 if (((scr1 & 0x10) >> 4) != mask) {
679 pci_write_config_byte(dev, 0x5a, scr1);
691 static void hpt366_dma_lost_irq(
ide_drive_t *drive)
694 u8 mcr1 = 0, mcr3 = 0, scr1 = 0;
696 pci_read_config_byte(dev, 0x50, &mcr1);
697 pci_read_config_byte(dev, 0x52, &mcr3);
698 pci_read_config_byte(dev, 0x5a, &scr1);
699 printk(
"%s: (%s) mcr1=0x%02x, mcr3=0x%02x, scr1=0x%02x\n",
700 drive->
name, __func__, mcr1, mcr3, scr1);
702 pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
706 static void hpt370_clear_engine(
ide_drive_t *drive)
711 pci_write_config_byte(dev, hwif->
select_data, 0x37);
722 pci_read_config_word(dev, hwif->
select_data + 2, &bfifo);
729 hpt370_clear_engine(drive);
734 #ifdef HPT_RESET_STATE_ENGINE
735 hpt370_clear_engine(drive);
749 if (dma_stat & ATA_DMA_ACTIVE)
750 hpt370_irq_timeout(drive);
763 pci_read_config_word(dev, hwif->
select_data + 2, &bfifo);
782 u8 bwsr = 0, mask = hwif->
channel ? 0x02 : 0x01;
784 pci_read_config_byte(dev, 0x6a, &bwsr);
785 pci_read_config_byte(dev, mcr_addr, &mcr);
787 pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
802 u8 scr2 =
inb(base + 0x6b);
804 if ((scr2 & 0x7f) == mode)
808 outb(0x80, base + 0x63);
809 outb(0x80, base + 0x67);
812 outb(mode, base + 0x6b);
813 outb(0xc0, base + 0x69);
819 outb(
inb(base + 0x60) | 0x32, base + 0x60);
820 outb(
inb(base + 0x64) | 0x32, base + 0x64);
823 outb(0x00, base + 0x69);
826 outb(0x00, base + 0x63);
827 outb(0x00, base + 0x67);
841 hpt3xxn_set_clock(drive->
hwif, rq_data_dir(rq) ? 0x21 : 0x23);
851 static int hpt37x_calibrate_dpll(
struct pci_dev *dev,
u16 f_low,
u16 f_high)
853 u32 dpll = (f_high << 16) | f_low | 0x100;
857 pci_write_config_dword(dev, 0x5c, dpll);
860 for(i = 0; i < 0x5000; ++
i) {
862 pci_read_config_byte(dev, 0x5b, &scr2);
867 for(i = 0; i < 0x1000; ++
i) {
868 pci_read_config_byte(dev, 0x5b, &scr2);
874 pci_read_config_dword (dev, 0x5c, &dpll);
875 pci_write_config_dword(dev, 0x5c, (dpll & ~0x100));
879 static void hpt3xx_disable_fast_irq(
struct pci_dev *dev,
u8 mcr_addr)
884 u8 new_mcr, old_mcr = 0;
890 pci_read_config_byte(dev, mcr_addr + 1, &old_mcr);
893 new_mcr = old_mcr & ~0x07;
894 else if (chip_type >=
HPT370) {
897 #ifdef HPT_DELAY_INTERRUPT
903 new_mcr = old_mcr & ~0x80;
905 if (new_mcr != old_mcr)
906 pci_write_config_byte(dev, mcr_addr + 1, new_mcr);
909 static int init_chipset_hpt366(
struct pci_dev *dev)
912 struct hpt_info *info = hpt3xx_get_info(&dev->
dev);
928 if (chip_type >=
HPT370) {
934 pci_read_config_byte(dev, 0x5a, &scr1);
936 pci_write_config_byte(dev, 0x5a, scr1 & ~0x10);
943 outb(0x0e, io_base + 0x9c);
949 pci_write_config_byte(dev, 0x5b, 0x23);
972 temp =
inl(io_base + 0x90);
975 temp =
inl(io_base + 0x90);
982 if ((temp & 0xFFFFF000) != 0xABCDE000) {
986 "BIOS\n", name, pci_name(dev));
989 for (temp = i = 0; i < 128; i++) {
990 pci_read_config_word(dev, 0x78, &f_cnt);
991 temp += f_cnt & 0x1ff;
996 f_cnt = temp & 0x1ff;
999 pci_clk = (f_cnt * dpll_clk) / 192;
1004 else if(pci_clk < 45)
1006 else if(pci_clk < 55)
1012 "assuming %d MHz PCI\n", name, pci_name(dev),
1013 dpll_clk, f_cnt, pci_clk);
1017 pci_read_config_dword(dev, 0x40, &itr1);
1020 switch((itr1 >> 8) & 0x07) {
1063 u16 f_low,
delta = pci_clk < 50 ? 2 : 4;
1073 }
else if (dpll_clk) {
1080 name, pci_name(dev));
1085 pci_write_config_byte(dev, 0x5b, 0x21);
1091 f_low = (pci_clk * 48) / dpll_clk;
1093 for (adjust = 0; adjust < 8; adjust++) {
1094 if(hpt37x_calibrate_dpll(dev, f_low, f_low + delta))
1101 f_low -= adjust >> 1;
1103 f_low += adjust >> 1;
1107 name, pci_name(dev));
1112 name, pci_name(dev), dpll_clk);
1118 name, pci_name(dev), pci_clk);
1126 if (chip_type >=
HPT370) {
1133 pci_read_config_byte (dev, 0x50, &mcr1);
1134 pci_read_config_byte (dev, 0x54, &mcr4);
1135 pci_write_config_byte(dev, 0x50, (mcr1 | 0x32));
1136 pci_write_config_byte(dev, 0x54, (mcr4 | 0x32));
1146 outb(
inb(io_base + 0x9c) | 0x04, io_base + 0x9c);
1148 hpt3xx_disable_fast_irq(dev, 0x50);
1149 hpt3xx_disable_fast_irq(dev, 0x54);
1157 struct hpt_info *info = hpt3xx_get_info(hwif->
dev);
1159 u8 scr1 = 0, ata66 = hwif->
channel ? 0x01 : 0x02;
1175 pci_read_config_word(dev, mcr_addr, &mcr);
1176 pci_write_config_word(dev, mcr_addr, mcr | 0x8000);
1179 pci_read_config_byte(dev, 0x5a, &scr1);
1180 pci_write_config_word(dev, mcr_addr, mcr);
1181 }
else if (chip_type >=
HPT370) {
1188 pci_read_config_byte(dev, 0x5b, &scr2);
1189 pci_write_config_byte(dev, 0x5b, scr2 & ~1);
1192 pci_read_config_byte(dev, 0x5a, &scr1);
1193 pci_write_config_byte(dev, 0x5b, scr2);
1195 pci_read_config_byte(dev, 0x5a, &scr1);
1202 struct hpt_info *info = hpt3xx_get_info(hwif->
dev);
1220 hwif->
rw_disk = &hpt3xxn_rw_disk;
1228 unsigned long flags, base = ide_pci_dma_base(hwif, d);
1229 u8 dma_old, dma_new, masterdma = 0, slavedma = 0;
1236 if (ide_pci_check_simplex(hwif, d) < 0)
1239 if (ide_pci_set_master(dev, d->
name) < 0)
1242 dma_old =
inb(base + 2);
1247 pci_read_config_byte(dev, hwif->
channel ? 0x4b : 0x43, &masterdma);
1248 pci_read_config_byte(dev, hwif->
channel ? 0x4f : 0x47, &slavedma);
1250 if (masterdma & 0x30) dma_new |= 0x20;
1251 if ( slavedma & 0x30) dma_new |= 0x40;
1252 if (dma_new != dma_old)
1253 outb(dma_new, base + 2);
1258 hwif->
name, base, base + 7);
1270 if (dev2->
irq != dev->
irq) {
1274 "fixed\n", pci_name(dev2));
1288 pci_read_config_byte(dev, 0x50, &mcr1);
1290 pci_write_config_byte(dev, 0x50, mcr1 & ~0x04);
1295 u8 mcr1 = 0, pin1 = 0, pin2 = 0;
1301 pci_read_config_byte(dev, 0x50, &mcr1);
1303 pci_write_config_byte(dev, 0x50, mcr1 | 0x30);
1308 if (pin1 != pin2 && dev->
irq == dev2->
irq) {
1310 "pin1=%d pin2=%d\n", pci_name(dev), pin1, pin2);
1317 #define IDE_HFLAGS_HPT3XX \
1318 (IDE_HFLAG_NO_ATAPI_DMA | \
1319 IDE_HFLAG_OFF_BOARD)
1322 .set_pio_mode = hpt3xx_set_pio_mode,
1323 .set_dma_mode = hpt3xx_set_mode,
1324 .maskproc = hpt3xx_maskproc,
1325 .mdma_filter = hpt3xx_mdma_filter,
1326 .udma_filter = hpt3xx_udma_filter,
1327 .cable_detect = hpt3xx_cable_detect,
1330 static const struct ide_dma_ops hpt37x_dma_ops = {
1334 .dma_end = hpt374_dma_end,
1335 .dma_test_irq = hpt374_dma_test_irq,
1341 static const struct ide_dma_ops hpt370_dma_ops = {
1344 .dma_start = hpt370_dma_start,
1345 .dma_end = hpt370_dma_end,
1349 .dma_clear = hpt370_irq_timeout,
1353 static const struct ide_dma_ops hpt36x_dma_ops = {
1359 .dma_lost_irq = hpt366_dma_lost_irq,
1364 static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
1367 .init_chipset = init_chipset_hpt366,
1368 .init_hwif = init_hwif_hpt366,
1369 .init_dma = init_dma_hpt366,
1376 .enablebits = {{0x50,0x10,0x10}, {0x54,0x04,0x04}},
1377 .port_ops = &hpt3xx_port_ops,
1378 .dma_ops = &hpt36x_dma_ops,
1385 .init_chipset = init_chipset_hpt366,
1386 .init_hwif = init_hwif_hpt366,
1387 .init_dma = init_dma_hpt366,
1388 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1389 .port_ops = &hpt3xx_port_ops,
1390 .dma_ops = &hpt37x_dma_ops,
1411 u8 idx =
id->driver_data;
1424 case 3: info = &hpt370;
break;
1425 case 4: info = &hpt370a;
break;
1426 case 5: info = &hpt372;
break;
1427 case 6: info = &hpt372n;
break;
1433 info = (rev > 1) ? &hpt372n : &hpt372a;
1436 info = (rev > 1) ? &hpt302n : &hpt302;
1440 info = (rev > 1) ? &hpt371n : &hpt371;
1452 d = hpt366_chipsets[
min_t(
u8, idx, 1)];
1457 if (info == &hpt370 || info == &hpt370a)
1460 if (info == &hpt36x || info == &hpt374)
1463 dyn_info = kzalloc(
sizeof(*dyn_info) * (dev2 ? 2 : 1),
GFP_KERNEL);
1464 if (dyn_info ==
NULL) {
1466 d.
name, pci_name(dev));
1475 memcpy(dyn_info, info,
sizeof(*dyn_info));
1478 memcpy(dyn_info + 1, info,
sizeof(*dyn_info));
1480 if (info == &hpt374)
1481 hpt374_init(dev, dev2);
1483 if (hpt36x_init(dev, dev2))
1504 struct ide_host *host = pci_get_drvdata(dev);
1505 struct ide_info *info = host->
host_priv;
1513 static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
1524 static struct pci_driver hpt366_pci_driver = {
1525 .name =
"HPT366_IDE",
1526 .id_table = hpt366_pci_tbl,
1527 .probe = hpt366_init_one,
1533 static int __init hpt366_ide_init(
void)
1538 static void __exit hpt366_ide_exit(
void)