diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-07-24 16:53:15 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-07-24 16:53:15 -0400 |
commit | 74811f355f4f69a187fa74892dcf2a684b84ce99 (patch) | |
tree | 91c25f20b44c63894f9742b1c12336631c3b6f2e /drivers | |
parent | 60e57ed7c12917932a01d1679d92a7a8735afbce (diff) |
hpt366: convert to use ->host_priv
While at it:
* Allocate both struct hpt_info instances at once.
Cc: Sergei Shtylyov <sshtylyov@ru.mvista.com>
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ide/pci/hpt366.c | 72 |
1 files changed, 41 insertions, 31 deletions
diff --git a/drivers/ide/pci/hpt366.c b/drivers/ide/pci/hpt366.c index b23b7a278005..8f29571345a2 100644 --- a/drivers/ide/pci/hpt366.c +++ b/drivers/ide/pci/hpt366.c | |||
@@ -620,7 +620,8 @@ static u8 hpt3xx_udma_filter(ide_drive_t *drive) | |||
620 | { | 620 | { |
621 | ide_hwif_t *hwif = HWIF(drive); | 621 | ide_hwif_t *hwif = HWIF(drive); |
622 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 622 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
623 | struct hpt_info *info = pci_get_drvdata(dev); | 623 | struct ide_host *host = pci_get_drvdata(dev); |
624 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
624 | u8 mask = hwif->ultra_mask; | 625 | u8 mask = hwif->ultra_mask; |
625 | 626 | ||
626 | switch (info->chip_type) { | 627 | switch (info->chip_type) { |
@@ -660,7 +661,8 @@ static u8 hpt3xx_mdma_filter(ide_drive_t *drive) | |||
660 | { | 661 | { |
661 | ide_hwif_t *hwif = HWIF(drive); | 662 | ide_hwif_t *hwif = HWIF(drive); |
662 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 663 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
663 | struct hpt_info *info = pci_get_drvdata(dev); | 664 | struct ide_host *host = pci_get_drvdata(dev); |
665 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
664 | 666 | ||
665 | switch (info->chip_type) { | 667 | switch (info->chip_type) { |
666 | case HPT372 : | 668 | case HPT372 : |
@@ -694,8 +696,10 @@ static u32 get_speed_setting(u8 speed, struct hpt_info *info) | |||
694 | 696 | ||
695 | static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) | 697 | static void hpt3xx_set_mode(ide_drive_t *drive, const u8 speed) |
696 | { | 698 | { |
697 | struct pci_dev *dev = to_pci_dev(drive->hwif->dev); | 699 | ide_hwif_t *hwif = drive->hwif; |
698 | struct hpt_info *info = pci_get_drvdata(dev); | 700 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
701 | struct ide_host *host = pci_get_drvdata(dev); | ||
702 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
699 | struct hpt_timings *t = info->timings; | 703 | struct hpt_timings *t = info->timings; |
700 | u8 itr_addr = 0x40 + (drive->dn * 4); | 704 | u8 itr_addr = 0x40 + (drive->dn * 4); |
701 | u32 old_itr = 0; | 705 | u32 old_itr = 0; |
@@ -738,7 +742,8 @@ static void hpt3xx_maskproc(ide_drive_t *drive, int mask) | |||
738 | { | 742 | { |
739 | ide_hwif_t *hwif = HWIF(drive); | 743 | ide_hwif_t *hwif = HWIF(drive); |
740 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 744 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
741 | struct hpt_info *info = pci_get_drvdata(dev); | 745 | struct ide_host *host = pci_get_drvdata(dev); |
746 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
742 | 747 | ||
743 | if (drive->quirk_list) { | 748 | if (drive->quirk_list) { |
744 | if (info->chip_type >= HPT370) { | 749 | if (info->chip_type >= HPT370) { |
@@ -965,22 +970,13 @@ static int __devinit hpt37x_calibrate_dpll(struct pci_dev *dev, u16 f_low, u16 f | |||
965 | 970 | ||
966 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) | 971 | static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const char *name) |
967 | { | 972 | { |
968 | struct hpt_info *info = kmalloc(sizeof(struct hpt_info), GFP_KERNEL); | ||
969 | unsigned long io_base = pci_resource_start(dev, 4); | 973 | unsigned long io_base = pci_resource_start(dev, 4); |
974 | struct ide_host *host = pci_get_drvdata(dev); | ||
975 | struct hpt_info *info = host->host_priv + (&dev->dev == host->dev[1]); | ||
970 | u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ | 976 | u8 pci_clk, dpll_clk = 0; /* PCI and DPLL clock in MHz */ |
971 | u8 chip_type; | 977 | u8 chip_type; |
972 | enum ata_clock clock; | 978 | enum ata_clock clock; |
973 | 979 | ||
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; | 980 | chip_type = info->chip_type; |
985 | 981 | ||
986 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); | 982 | pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, (L1_CACHE_BYTES / 4)); |
@@ -1142,7 +1138,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha | |||
1142 | 1138 | ||
1143 | if (info->timings->clock_table[clock] == NULL) { | 1139 | if (info->timings->clock_table[clock] == NULL) { |
1144 | printk(KERN_ERR "%s: unknown bus timing!\n", name); | 1140 | printk(KERN_ERR "%s: unknown bus timing!\n", name); |
1145 | kfree(info); | ||
1146 | return -EIO; | 1141 | return -EIO; |
1147 | } | 1142 | } |
1148 | 1143 | ||
@@ -1169,7 +1164,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha | |||
1169 | } | 1164 | } |
1170 | if (adjust == 8) { | 1165 | if (adjust == 8) { |
1171 | printk(KERN_ERR "%s: DPLL did not stabilize!\n", name); | 1166 | printk(KERN_ERR "%s: DPLL did not stabilize!\n", name); |
1172 | kfree(info); | ||
1173 | return -EIO; | 1167 | return -EIO; |
1174 | } | 1168 | } |
1175 | 1169 | ||
@@ -1186,9 +1180,6 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha | |||
1186 | info->pci_clk = pci_clk; | 1180 | info->pci_clk = pci_clk; |
1187 | info->clock = clock; | 1181 | info->clock = clock; |
1188 | 1182 | ||
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) { | 1183 | if (chip_type >= HPT370) { |
1193 | u8 mcr1, mcr4; | 1184 | u8 mcr1, mcr4; |
1194 | 1185 | ||
@@ -1218,7 +1209,8 @@ static unsigned int __devinit init_chipset_hpt366(struct pci_dev *dev, const cha | |||
1218 | static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) | 1209 | static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) |
1219 | { | 1210 | { |
1220 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 1211 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1221 | struct hpt_info *info = pci_get_drvdata(dev); | 1212 | struct ide_host *host = pci_get_drvdata(dev); |
1213 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
1222 | u8 chip_type = info->chip_type; | 1214 | u8 chip_type = info->chip_type; |
1223 | u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; | 1215 | u8 scr1 = 0, ata66 = hwif->channel ? 0x01 : 0x02; |
1224 | 1216 | ||
@@ -1262,7 +1254,8 @@ static u8 __devinit hpt3xx_cable_detect(ide_hwif_t *hwif) | |||
1262 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) | 1254 | static void __devinit init_hwif_hpt366(ide_hwif_t *hwif) |
1263 | { | 1255 | { |
1264 | struct pci_dev *dev = to_pci_dev(hwif->dev); | 1256 | struct pci_dev *dev = to_pci_dev(hwif->dev); |
1265 | struct hpt_info *info = pci_get_drvdata(dev); | 1257 | struct ide_host *host = pci_get_drvdata(dev); |
1258 | struct hpt_info *info = host->host_priv + (hwif->dev == host->dev[1]); | ||
1266 | int serialize = HPT_SERIALIZE_IO; | 1259 | int serialize = HPT_SERIALIZE_IO; |
1267 | u8 chip_type = info->chip_type; | 1260 | u8 chip_type = info->chip_type; |
1268 | u8 new_mcr, old_mcr = 0; | 1261 | u8 new_mcr, old_mcr = 0; |
@@ -1542,10 +1535,12 @@ static const struct ide_port_info hpt366_chipsets[] __devinitdata = { | |||
1542 | static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) | 1535 | static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_device_id *id) |
1543 | { | 1536 | { |
1544 | const struct hpt_info *info = NULL; | 1537 | const struct hpt_info *info = NULL; |
1538 | struct hpt_info *dyn_info; | ||
1545 | struct pci_dev *dev2 = NULL; | 1539 | struct pci_dev *dev2 = NULL; |
1546 | struct ide_port_info d; | 1540 | struct ide_port_info d; |
1547 | u8 idx = id->driver_data; | 1541 | u8 idx = id->driver_data; |
1548 | u8 rev = dev->revision; | 1542 | u8 rev = dev->revision; |
1543 | int ret; | ||
1549 | 1544 | ||
1550 | if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1)) | 1545 | if ((idx == 0 || idx == 4) && (PCI_FUNC(dev->devfn) & 1)) |
1551 | return -ENODEV; | 1546 | return -ENODEV; |
@@ -1591,15 +1586,24 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic | |||
1591 | if (info == &hpt370 || info == &hpt370a) | 1586 | if (info == &hpt370 || info == &hpt370a) |
1592 | d.dma_ops = &hpt370_dma_ops; | 1587 | d.dma_ops = &hpt370_dma_ops; |
1593 | 1588 | ||
1594 | pci_set_drvdata(dev, (void *)info); | ||
1595 | |||
1596 | if (info == &hpt36x || info == &hpt374) | 1589 | if (info == &hpt36x || info == &hpt374) |
1597 | dev2 = pci_get_slot(dev->bus, dev->devfn + 1); | 1590 | dev2 = pci_get_slot(dev->bus, dev->devfn + 1); |
1598 | 1591 | ||
1599 | if (dev2) { | 1592 | dyn_info = kzalloc(sizeof(*dyn_info) * (dev2 ? 2 : 1), GFP_KERNEL); |
1600 | int ret; | 1593 | if (dyn_info == NULL) { |
1594 | printk(KERN_ERR "%s: out of memory!\n", d.name); | ||
1595 | pci_dev_put(dev2); | ||
1596 | return -ENOMEM; | ||
1597 | } | ||
1598 | |||
1599 | /* | ||
1600 | * Copy everything from a static "template" structure | ||
1601 | * to just allocated per-chip hpt_info structure. | ||
1602 | */ | ||
1603 | memcpy(dyn_info, info, sizeof(*dyn_info)); | ||
1601 | 1604 | ||
1602 | pci_set_drvdata(dev2, (void *)info); | 1605 | if (dev2) { |
1606 | memcpy(dyn_info + 1, info, sizeof(*dyn_info)); | ||
1603 | 1607 | ||
1604 | if (info == &hpt374) | 1608 | if (info == &hpt374) |
1605 | hpt374_init(dev, dev2); | 1609 | hpt374_init(dev, dev2); |
@@ -1608,13 +1612,19 @@ static int __devinit hpt366_init_one(struct pci_dev *dev, const struct pci_devic | |||
1608 | d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE; | 1612 | d.host_flags &= ~IDE_HFLAG_NON_BOOTABLE; |
1609 | } | 1613 | } |
1610 | 1614 | ||
1611 | ret = ide_pci_init_two(dev, dev2, &d, NULL); | 1615 | ret = ide_pci_init_two(dev, dev2, &d, dyn_info); |
1612 | if (ret < 0) | 1616 | if (ret < 0) { |
1613 | pci_dev_put(dev2); | 1617 | pci_dev_put(dev2); |
1618 | kfree(dyn_info); | ||
1619 | } | ||
1614 | return ret; | 1620 | return ret; |
1615 | } | 1621 | } |
1616 | 1622 | ||
1617 | return ide_pci_init_one(dev, &d, NULL); | 1623 | ret = ide_pci_init_one(dev, &d, dyn_info); |
1624 | if (ret < 0) | ||
1625 | kfree(dyn_info); | ||
1626 | |||
1627 | return ret; | ||
1618 | } | 1628 | } |
1619 | 1629 | ||
1620 | static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = { | 1630 | static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = { |