aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/pci/hpt366.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/pci/hpt366.c')
-rw-r--r--drivers/ide/pci/hpt366.c183
1 files changed, 89 insertions, 94 deletions
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c
index 1f1135ce7cd6..5271b246b88c 100644
--- a/drivers/ide/pci/hpt366.c
+++ b/drivers/ide/pci/hpt366.c
@@ -131,6 +131,8 @@
131#include <asm/uaccess.h> 131#include <asm/uaccess.h>
132#include <asm/io.h> 132#include <asm/io.h>
133 133
134#define DRV_NAME "hpt366"
135
134/* various tuning parameters */ 136/* various tuning parameters */
135#define HPT_RESET_STATE_ENGINE 137#define HPT_RESET_STATE_ENGINE
136#undef HPT_DELAY_INTERRUPT 138#undef HPT_DELAY_INTERRUPT
@@ -620,7 +622,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive)
620{ 622{
621 ide_hwif_t *hwif = HWIF(drive); 623 ide_hwif_t *hwif = HWIF(drive);
622 struct pci_dev *dev = to_pci_dev(hwif->dev); 624 struct pci_dev *dev = to_pci_dev(hwif->dev);
623 struct hpt_info *info = pci_get_drvdata(dev); 625 struct ide_host *host = pci_get_drvdata(dev);
626 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
624 u8 mask = hwif->ultra_mask; 627 u8 mask = hwif->ultra_mask;
625 628
626 switch (info->chip_type) { 629 switch (info->chip_type) {
@@ -660,7 +663,8 @@ static u8 hpt3xx_mdma_filter(ide_drive_t *drive)
660{ 663{
661 ide_hwif_t *hwif = HWIF(drive); 664 ide_hwif_t *hwif = HWIF(drive);
662 struct pci_dev *dev = to_pci_dev(hwif->dev); 665 struct pci_dev *dev = to_pci_dev(hwif->dev);
663 struct hpt_info *info = pci_get_drvdata(dev); 666 struct ide_host *host = pci_get_drvdata(dev);
667 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
664 668
665 switch (info->chip_type) { 669 switch (info->chip_type) {
666 case HPT372 : 670 case HPT372 :
@@ -694,8 +698,10 @@ static u32 get_speed_setting(u8 speed, struct hpt_info *info)
694 698
695static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) 699static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed)
696{ 700{
697 struct pci_dev *dev = to_pci_dev(drive->hwif->dev); 701 ide_hwif_t *hwif = drive->hwif;
698 struct hpt_info *info = pci_get_drvdata(dev); 702 struct pci_dev *dev = to_pci_dev(hwif->dev);
703 struct ide_host *host = pci_get_drvdata(dev);
704 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
699 struct hpt_timings *t = info->timings; 705 struct hpt_timings *t = info->timings;
700 u8 itr_addr = 0x40 + (drive->dn * 4); 706 u8 itr_addr = 0x40 + (drive->dn * 4);
701 u32 old_itr = 0; 707 u32 old_itr = 0;
@@ -738,7 +744,8 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask)
738{ 744{
739 ide_hwif_t *hwif = HWIF(drive); 745 ide_hwif_t *hwif = HWIF(drive);
740 struct pci_dev *dev = to_pci_dev(hwif->dev); 746 struct pci_dev *dev = to_pci_dev(hwif->dev);
741 struct hpt_info *info = pci_get_drvdata(dev); 747 struct ide_host *host = pci_get_drvdata(dev);
748 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
742 749
743 if (drive->quirk_list) { 750 if (drive->quirk_list) {
744 if (info->chip_type >= HPT370) { 751 if (info->chip_type >= HPT370) {
@@ -963,24 +970,16 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f
963 return 1; 970 return 1;
964} 971}
965 972
966static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) 973static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev)
967{ 974{
968 struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL);
969 unsigned long io_base = pci_resource_start(dev, 4); 975 unsigned long io_base = pci_resource_start(dev, 4);
976 struct ide_host *host = pci_get_drvdata(dev);
977 struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]);
978 const char *name = DRV_NAME;
970 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ 979 u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */
971 u8 chip_type; 980 u8 chip_type;
972 enum ata_clock clock; 981 enum ata_clock clock;
973 982
974 if (info == NULL) {
975 printk(KERN_ERR "%s: out of memory!\n", name);
976 return -ENOMEM;
977 }
978
979 /*
980 * Copy everything from a static "template" structure
981 * to just allocated per-chip hpt_info structure.
982 */
983 memcpy(info, pci_get_drvdata(dev), sizeof(struct hpt_info));
984 chip_type = info->chip_type; 983 chip_type = info->chip_type;
985 984
986 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); 985 pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4));
@@ -1048,8 +1047,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1048 if ((temp & 0xFFFFF000) != 0xABCDE000) { 1047 if ((temp & 0xFFFFF000) != 0xABCDE000) {
1049 int i; 1048 int i;
1050 1049
1051 printk(KERN_WARNING "%s: no clock data saved by BIOS\n", 1050 printk(KERN_WARNING "%s %s: no clock data saved by "
1052 name); 1051 "BIOS\n", name, pci_name(dev));
1053 1052
1054 /* Calculate the average value of f_CNT. */ 1053 /* Calculate the average value of f_CNT. */
1055 for (temp = i = 0; i < 128; i++) { 1054 for (temp = i = 0; i < 128; i++) {
@@ -1074,8 +1073,9 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1074 else 1073 else
1075 pci_clk = 66; 1074 pci_clk = 66;
1076 1075
1077 printk(KERN_INFO "%s: DPLL base: %d MHz, f_CNT: %d, " 1076 printk(KERN_INFO "%s %s: DPLL base: %d MHz, f_CNT: %d, "
1078 "assuming %d MHz PCI\n", name, dpll_clk, f_cnt, pci_clk); 1077 "assuming %d MHz PCI\n", name, pci_name(dev),
1078 dpll_clk, f_cnt, pci_clk);
1079 } else { 1079 } else {
1080 u32 itr1 = 0; 1080 u32 itr1 = 0;
1081 1081
@@ -1141,8 +1141,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1141 } 1141 }
1142 1142
1143 if (info->timings->clock_table[clock] == NULL) { 1143 if (info->timings->clock_table[clock] == NULL) {
1144 printk(KERN_ERR "%s: unknown bus timing!\n", name); 1144 printk(KERN_ERR "%s %s: unknown bus timing!\n",
1145 kfree(info); 1145 name, pci_name(dev));
1146 return -EIO; 1146 return -EIO;
1147 } 1147 }
1148 1148
@@ -1168,17 +1168,19 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1168 f_low += adjust >> 1; 1168 f_low += adjust >> 1;
1169 } 1169 }
1170 if (adjust == 8) { 1170 if (adjust == 8) {
1171 printk(KERN_ERR "%s: DPLL did not stabilize!\n", name); 1171 printk(KERN_ERR "%s %s: DPLL did not stabilize!\n",
1172 kfree(info); 1172 name, pci_name(dev));
1173 return -EIO; 1173 return -EIO;
1174 } 1174 }
1175 1175
1176 printk("%s: using %d MHz DPLL clock\n", name, dpll_clk); 1176 printk(KERN_INFO "%s %s: using %d MHz DPLL clock\n",
1177 name, pci_name(dev), dpll_clk);
1177 } else { 1178 } else {
1178 /* Mark the fact that we're not using the DPLL. */ 1179 /* Mark the fact that we're not using the DPLL. */
1179 dpll_clk = 0; 1180 dpll_clk = 0;
1180 1181
1181 printk("%s: using %d MHz PCI clock\n", name, pci_clk); 1182 printk(KERN_INFO "%s %s: using %d MHz PCI clock\n",
1183 name, pci_name(dev), pci_clk);
1182 } 1184 }
1183 1185
1184 /* Store the clock frequencies. */ 1186 /* Store the clock frequencies. */
@@ -1186,9 +1188,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1186 info->pci_clk = pci_clk; 1188 info->pci_clk = pci_clk;
1187 info->clock = clock; 1189 info->clock = clock;
1188 1190
1189 /* Point to this chip's own instance of the hpt_info structure. */
1190 pci_set_drvdata(dev, info);
1191
1192 if (chip_type >= HPT370) { 1191 if (chip_type >= HPT370) {
1193 u8 mcr1, mcr4; 1192 u8 mcr1, mcr4;
1194 1193
@@ -1218,7 +1217,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha
1218static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) 1217static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1219{ 1218{
1220 struct pci_dev *dev = to_pci_dev(hwif->dev); 1219 struct pci_dev *dev = to_pci_dev(hwif->dev);
1221 struct hpt_info *info = pci_get_drvdata(dev); 1220 struct ide_host *host = pci_get_drvdata(dev);
1221 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1222 u8 chip_type = info->chip_type; 1222 u8 chip_type = info->chip_type;
1223 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; 1223 u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02;
1224 1224
@@ -1262,7 +1262,8 @@ static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif)
1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) 1262static void __devinit init_hwif_hpt366(ide_hwif_t *hwif)
1263{ 1263{
1264 struct pci_dev *dev = to_pci_dev(hwif->dev); 1264 struct pci_dev *dev = to_pci_dev(hwif->dev);
1265 struct hpt_info *info = pci_get_drvdata(dev); 1265 struct ide_host *host = pci_get_drvdata(dev);
1266 struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]);
1266 int serialize = HPT_SERIALIZE_IO; 1267 int serialize = HPT_SERIALIZE_IO;
1267 u8 chip_type = info->chip_type; 1268 u8 chip_type = info->chip_type;
1268 u8 new_mcr, old_mcr = 0; 1269 u8 new_mcr, old_mcr = 0;
@@ -1364,7 +1365,8 @@ static void __devinit hpt374_init(struct pci_dev *dev, struct pci_dev *dev2)
1364 if (dev2->irq != dev->irq) { 1365 if (dev2->irq != dev->irq) {
1365 /* FIXME: we need a core pci_set_interrupt() */ 1366 /* FIXME: we need a core pci_set_interrupt() */
1366 dev2->irq = dev->irq; 1367 dev2->irq = dev->irq;
1367 printk(KERN_INFO "HPT374: PCI config space interrupt fixed\n"); 1368 printk(KERN_INFO DRV_NAME " %s: PCI config space interrupt "
1369 "fixed\n", pci_name(dev2));
1368 } 1370 }
1369} 1371}
1370 1372
@@ -1399,8 +1401,8 @@ static int __devinit hpt36x_init(struct pci_dev *dev, struct pci_dev *dev2)
1399 pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2); 1401 pci_read_config_byte(dev2, PCI_INTERRUPT_PIN, &pin2);
1400 1402
1401 if (pin1 != pin2 && dev->irq == dev2->irq) { 1403 if (pin1 != pin2 && dev->irq == dev2->irq) {
1402 printk(KERN_INFO "HPT36x: onboard version of chipset, " 1404 printk(KERN_INFO DRV_NAME " %s: onboard version of chipset, "
1403 "pin1=%d pin2=%d\n", pin1, pin2); 1405 "pin1=%d pin2=%d\n", pci_name(dev), pin1, pin2);
1404 return 1; 1406 return 1;
1405 } 1407 }
1406 1408
@@ -1455,8 +1457,8 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
1455}; 1457};
1456 1458
1457static const struct ide_port_info hpt366_chipsets[] __devinitdata = { 1459static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1458 { /* 0 */ 1460 { /* 0: HPT36x */
1459 .name = "HPT36x", 1461 .name = DRV_NAME,
1460 .init_chipset = init_chipset_hpt366, 1462 .init_chipset = init_chipset_hpt366,
1461 .init_hwif = init_hwif_hpt366, 1463 .init_hwif = init_hwif_hpt366,
1462 .init_dma = init_dma_hpt366, 1464 .init_dma = init_dma_hpt366,
@@ -1472,53 +1474,9 @@ static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1472 .host_flags = IDE_HFLAGS_HPT3XX | IDE_HFLAG_SINGLE, 1474 .host_flags = IDE_HFLAGS_HPT3XX | IDE_HFLAG_SINGLE,
1473 .pio_mask = ATA_PIO4, 1475 .pio_mask = ATA_PIO4,
1474 .mwdma_mask = ATA_MWDMA2, 1476 .mwdma_mask = ATA_MWDMA2,
1475 },{ /* 1 */ 1477 },
1476 .name = "HPT372A", 1478 { /* 1: HPT3xx */
1477 .init_chipset = init_chipset_hpt366, 1479 .name = DRV_NAME,
1478 .init_hwif = init_hwif_hpt366,
1479 .init_dma = init_dma_hpt366,
1480 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1481 .port_ops = &hpt3xx_port_ops,
1482 .dma_ops = &hpt37x_dma_ops,
1483 .host_flags = IDE_HFLAGS_HPT3XX,
1484 .pio_mask = ATA_PIO4,
1485 .mwdma_mask = ATA_MWDMA2,
1486 },{ /* 2 */
1487 .name = "HPT302",
1488 .init_chipset = init_chipset_hpt366,
1489 .init_hwif = init_hwif_hpt366,
1490 .init_dma = init_dma_hpt366,
1491 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1492 .port_ops = &hpt3xx_port_ops,
1493 .dma_ops = &hpt37x_dma_ops,
1494 .host_flags = IDE_HFLAGS_HPT3XX,
1495 .pio_mask = ATA_PIO4,
1496 .mwdma_mask = ATA_MWDMA2,
1497 },{ /* 3 */
1498 .name = "HPT371",
1499 .init_chipset = init_chipset_hpt366,
1500 .init_hwif = init_hwif_hpt366,
1501 .init_dma = init_dma_hpt366,
1502 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1503 .port_ops = &hpt3xx_port_ops,
1504 .dma_ops = &hpt37x_dma_ops,
1505 .host_flags = IDE_HFLAGS_HPT3XX,
1506 .pio_mask = ATA_PIO4,
1507 .mwdma_mask = ATA_MWDMA2,
1508 },{ /* 4 */
1509 .name = "HPT374",
1510 .init_chipset = init_chipset_hpt366,
1511 .init_hwif = init_hwif_hpt366,
1512 .init_dma = init_dma_hpt366,
1513 .enablebits = {{0x50,0x04,0x04}, {0x54,0x04,0x04}},
1514 .udma_mask = ATA_UDMA5,
1515 .port_ops = &hpt3xx_port_ops,
1516 .dma_ops = &hpt37x_dma_ops,
1517 .host_flags = IDE_HFLAGS_HPT3XX,
1518 .pio_mask = ATA_PIO4,
1519 .mwdma_mask = ATA_MWDMA2,
1520 },{ /* 5 */
1521 .name = "HPT372N",
1522 .init_chipset = init_chipset_hpt366, 1480 .init_chipset = init_chipset_hpt366,
1523 .init_hwif = init_hwif_hpt366, 1481 .init_hwif = init_hwif_hpt366,
1524 .init_dma = init_dma_hpt366, 1482 .init_dma = init_dma_hpt366,
@@ -1542,10 +1500,12 @@ static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
1542static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) 1500static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id)
1543{ 1501{
1544 const struct hpt_info *info = NULL; 1502 const struct hpt_info *info = NULL;
1503 struct hpt_info *dyn_info;
1545 struct pci_dev *dev2 = NULL; 1504 struct pci_dev *dev2 = NULL;
1546 struct ide_port_info d; 1505 struct ide_port_info d;
1547 u8 idx = id->driver_data; 1506 u8 idx = id->driver_data;
1548 u8 rev = dev->revision; 1507 u8 rev = dev->revision;
1508 int ret;
1549 1509
1550 if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1)) 1510 if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1))
1551 return -ENODEV; 1511 return -ENODEV;
@@ -1582,24 +1542,35 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic
1582 break; 1542 break;
1583 } 1543 }
1584 1544
1585 d = hpt366_chipsets[idx]; 1545 printk(KERN_INFO DRV_NAME ": %s chipset detected\n", info->chip_name);
1546
1547 d = hpt366_chipsets[min_t(u8, idx, 1)];
1586 1548
1587 d.name = info->chip_name;
1588 d.udma_mask = info->udma_mask; 1549 d.udma_mask = info->udma_mask;
1589 1550
1590 /* fixup ->dma_ops for HPT370/HPT370A */ 1551 /* fixup ->dma_ops for HPT370/HPT370A */
1591 if (info == &hpt370 || info == &hpt370a) 1552 if (info == &hpt370 || info == &hpt370a)
1592 d.dma_ops = &hpt370_dma_ops; 1553 d.dma_ops = &hpt370_dma_ops;
1593 1554
1594 pci_set_drvdata(dev, (void *)info);
1595
1596 if (info == &hpt36x || info == &hpt374) 1555 if (info == &hpt36x || info == &hpt374)
1597 dev2 = pci_get_slot(dev->bus, dev->devfn + 1); 1556 dev2 = pci_get_slot(dev->bus, dev->devfn + 1);
1598 1557
1599 if (dev2) { 1558 dyn_info = kzalloc(sizeof(*dyn_info) * (dev2 ? 2 : 1), GFP_KERNEL);
1600 int ret; 1559 if (dyn_info == NULL) {
1560 printk(KERN_ERR "%s %s: out of memory!\n",
1561 d.name, pci_name(dev));
1562 pci_dev_put(dev2);
1563 return -ENOMEM;
1564 }
1565
1566 /*
1567 * Copy everything from a static "template" structure
1568 * to just allocated per-chip hpt_info structure.
1569 */
1570 memcpy(dyn_info, info, sizeof(*dyn_info));
1601 1571
1602 pci_set_drvdata(dev2, (void *)info); 1572 if (dev2) {
1573 memcpy(dyn_info + 1, info, sizeof(*dyn_info));
1603 1574
1604 if (info == &hpt374) 1575 if (info == &hpt374)
1605 hpt374_init(dev, dev2); 1576 hpt374_init(dev, dev2);
@@ -1608,13 +1579,30 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic
1608 d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE; 1579 d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE;
1609 } 1580 }
1610 1581
1611 ret = ide_setup_pci_devices(dev, dev2, &d); 1582 ret = ide_pci_init_two(dev, dev2, &d, dyn_info);
1612 if (ret < 0) 1583 if (ret < 0) {
1613 pci_dev_put(dev2); 1584 pci_dev_put(dev2);
1585 kfree(dyn_info);
1586 }
1614 return ret; 1587 return ret;
1615 } 1588 }
1616 1589
1617 return ide_setup_pci_device(dev, &d); 1590 ret = ide_pci_init_one(dev, &d, dyn_info);
1591 if (ret < 0)
1592 kfree(dyn_info);
1593
1594 return ret;
1595}
1596
1597static void __devexit hpt366_remove(struct pci_dev *dev)
1598{
1599 struct ide_host *host = pci_get_drvdata(dev);
1600 struct ide_info *info = host->host_priv;
1601 struct pci_dev *dev2 = host->dev[1] ? to_pci_dev(host->dev[1]) : NULL;
1602
1603 ide_pci_remove(dev);
1604 pci_dev_put(dev2);
1605 kfree(info);
1618} 1606}
1619 1607
1620static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = { 1608static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
@@ -1632,6 +1620,7 @@ static struct pci_driver driver = {
1632 .name = "HPT366_IDE", 1620 .name = "HPT366_IDE",
1633 .id_table = hpt366_pci_tbl, 1621 .id_table = hpt366_pci_tbl,
1634 .probe = hpt366_init_one, 1622 .probe = hpt366_init_one,
1623 .remove = hpt366_remove,
1635}; 1624};
1636 1625
1637static int __init hpt366_ide_init(void) 1626static int __init hpt366_ide_init(void)
@@ -1639,7 +1628,13 @@ static int __init hpt366_ide_init(void)
1639 return ide_pci_register_driver(&driver); 1628 return ide_pci_register_driver(&driver);
1640} 1629}
1641 1630
1631static void __exit hpt366_ide_exit(void)
1632{
1633 pci_unregister_driver(&driver);
1634}
1635
1642module_init(hpt366_ide_init); 1636module_init(hpt366_ide_init);
1637module_exit(hpt366_ide_exit);
1643 1638
1644MODULE_AUTHOR("Andre Hedrick"); 1639MODULE_AUTHOR("Andre Hedrick");
1645MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE"); 1640MODULE_DESCRIPTION("PCI driver module for Highpoint HPT366 IDE");