sc1200: remove pointless hwif lookup loop

Save PCI regs values for both IDE ports in one buffer, in order to eliminate
a needless and ugly loop across all hwifs, searching for our PCI device.

Partially based on the previous patch by Jeff Garzik.

Cc: Jeff Garzik <jeff@garzik.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarBartlomiej Zolnierkiewicz <bzolnier@gmail.com>
parent 866e2ec9
...@@ -260,66 +260,39 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio) ...@@ -260,66 +260,39 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
} }
#ifdef CONFIG_PM #ifdef CONFIG_PM
static ide_hwif_t *lookup_pci_dev (ide_hwif_t *prev, struct pci_dev *dev) struct sc1200_saved_state {
{ u32 regs[8];
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 int sc1200_suspend (struct pci_dev *dev, pm_message_t state) static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
{ {
ide_hwif_t *hwif = NULL;
printk("SC1200: suspend(%u)\n", state.event); printk("SC1200: suspend(%u)\n", state.event);
/*
* we only save state when going from full power to less
*/
if (state.event == PM_EVENT_ON) { if (state.event == PM_EVENT_ON) {
// we only save state when going from full power to less struct sc1200_saved_state *ss;
unsigned int r;
//
// Loop over all interfaces that are part of this PCI device: /*
// * allocate a permanent save area, if not already allocated
while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { */
sc1200_saved_state_t *ss; ss = (struct sc1200_saved_state *)pci_get_drvdata(dev);
unsigned int basereg, r; if (ss == NULL) {
// ss = kmalloc(sizeof(*ss), GFP_KERNEL);
// allocate a permanent save area, if not already allocated if (ss == NULL)
// return -ENOMEM;
ss = (sc1200_saved_state_t *)hwif->config_data; pci_set_drvdata(dev, ss);
if (ss == NULL) {
ss = kmalloc(sizeof(sc1200_saved_state_t), GFP_KERNEL);
if (ss == NULL)
return -ENOMEM;
hwif->config_data = (unsigned long)ss;
}
ss = (sc1200_saved_state_t *)hwif->config_data;
//
// Save timing registers: this may be unnecessary if
// BIOS also does it
//
basereg = hwif->channel ? 0x50 : 0x40;
for (r = 0; r < 4; ++r) {
pci_read_config_dword (hwif->pci_dev, basereg + (r<<2), &ss->regs[r]);
}
} }
}
/* You don't need to iterate over disks -- sysfs should have done that for you already */ /*
* save timing registers
* (this may be unnecessary if BIOS also does it)
*/
for (r = 0; r < 8; r++)
pci_read_config_dword(dev, 0x40 + r * 4, &ss->regs[r]);
}
pci_disable_device(dev); pci_disable_device(dev);
pci_set_power_state(dev, pci_choose_state(dev, state)); pci_set_power_state(dev, pci_choose_state(dev, state));
...@@ -328,30 +301,25 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state) ...@@ -328,30 +301,25 @@ static int sc1200_suspend (struct pci_dev *dev, pm_message_t state)
static int sc1200_resume (struct pci_dev *dev) static int sc1200_resume (struct pci_dev *dev)
{ {
ide_hwif_t *hwif = NULL; struct sc1200_saved_state *ss;
int i; unsigned int r;
int i;
i = pci_enable_device(dev); i = pci_enable_device(dev);
if (i) if (i)
return i; return i;
// ss = (struct sc1200_saved_state *)pci_get_drvdata(dev);
// loop over all interfaces that are part of this pci device:
// /*
while ((hwif = lookup_pci_dev(hwif, dev)) != NULL) { * restore timing registers
unsigned int basereg, r; * (this may be unnecessary if BIOS also does it)
sc1200_saved_state_t *ss = (sc1200_saved_state_t *)hwif->config_data; */
if (ss) {
// for (r = 0; r < 8; r++)
// Restore timing registers: this may be unnecessary if BIOS also does it pci_write_config_dword(dev, 0x40 + r * 4, ss->regs[r]);
//
basereg = hwif->channel ? 0x50 : 0x40;
if (ss != NULL) {
for (r = 0; r < 4; ++r) {
pci_write_config_dword(hwif->pci_dev, basereg + (r<<2), ss->regs[r]);
}
}
} }
return 0; return 0;
} }
#endif #endif
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment