Signed-off-by: Jeff Garzik <jgarzik@xxxxxxxxxx>
---
drivers/ide/pci/sc1200.c | 76 +++++++++++++++++++++++++++++++---------------
1 files changed, 51 insertions(+), 25 deletions(-)
diff --git a/drivers/ide/pci/sc1200.c b/drivers/ide/pci/sc1200.c
index d2c8b55..17e58d6 100644
--- a/drivers/ide/pci/sc1200.c
+++ b/drivers/ide/pci/sc1200.c
@@ -41,6 +41,8 @@
#define PCI_CLK_66 0x02
#define PCI_CLK_33A 0x03
+#define SC1200_IFS 4
+
static unsigned short sc1200_get_pci_clock (void)
{
unsigned char chip_id, silicon_revision;
@@ -261,31 +263,32 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
}
#ifdef CONFIG_PM
-static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev)
-{
- int h;
-
- for (h = 0; h < MAX_HWIFS; h++) {
- ide_hwif_t *hwif = &ide_hwifs[h];
- if (prev) {
- if (hwif == prev)
- prev = NULL; // found previous, now look for next match
- } else {
- if (hwif && hwif->pci_dev == dev)
- return hwif; // found next match
- }
- }
- return NULL; // not found
-}
-
typedef struct sc1200_saved_state_s {
__u32 regs[4];
} sc1200_saved_state_t;
+static unsigned int pack_hwif_idx(u8 *idx)
+{
+ return (((unsigned int) idx[0]) << 0) |
+ (((unsigned int) idx[1]) << 8) |
+ (((unsigned int) idx[2]) << 16) |
+ (((unsigned int) idx[3]) << 24);
+}
+
+static ide_hwif_t *sc1200_hwif(struct pci_dev *pdev, unsigned int iface)
+{
+ unsigned int packed_hwifs, idx;
+
+ packed_hwifs = (unsigned long) pci_get_drvdata(pdev);
+ idx = (packed_hwifs >> (iface * 8)) & 0xff;
+
+ return (idx == 0xff) ? NULL : &ide_hwifs[idx];
+}
static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
{
- ide_hwif_t *hwif = NULL;
+ ide_hwif_t *hwif;
+ int i;
printk("SC1200: suspend(%u)\n", state.event);
@@ -295,9 +298,14 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
//
// Loop over all interfaces that are part of this PCI device:
//
- while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) {
+ for (i = 0; i < SC1200_IFS; i++) {
sc1200_saved_state_t *ss;
unsigned int basereg, r;
+
+ hwif = sc1200_hwif(dev, i);
+ if (!hwif)
+ continue;
+
//
// allocate a permanent save area, if not already allocated
//
@@ -310,7 +318,7 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
}
ss = (sc1200_saved_state_t *)hwif->config_data;
//
- // Save timing registers: this may be unnecessary if
+ // Save timing registers: this may be unnecessary if
// BIOS also does it
//
basereg = hwif->channel ? 0x50 : 0x40;