From f011bf085cd41ee40c2c8e530f801ac6cb6e00d0 Mon Sep 17 00:00:00 2001 From: Bernhard Kaindl Date: Wed, 6 Sep 2006 14:58:30 +0200 Subject: ohci1394: steps to implement suspend/resume I did a quick shot on what I described and the appended patch does the first thing needed for working suspend/resume in ohci1394 which is HW de- and re-initialisation. It works with suspend2disk on my Ricoh R5C552 IEEE 1394 Controller with the 2.6.17 kernel to the extent that if I call dvgrab --interactive after suspend2disk without unloading ohci1394, it does not lock up dvgrab with 100% CPU but properly connects to the camera, given that I first unplug and plug the camera after coming back from suspend. I guess that could be fixed by forcing a bus reset in the resume function. I cannot test suspend to RAM here at the moment and should follow the guidelines in Documentation/power/pci.txt also, so this is rather a quick report than a finished patch and there are some rough edges: However, with this patch, I have to unload at least some in-kernel users of ohci1394 like dv1394 or video1394 before suspending. Not doing that caused an Oops and a bad tasklet error, probably from not handling ISO tasklets during suspend/resume properly. Maybe these can be temporarily cleared or unregistered and re-registered for suspend/resume with help from the other layers or from the highlevel 1394 core, but I do not really know what these do. But this patch provides a useful base to start from and is already of much help for people which do not need dv1394 and video1394 or can unload them at least during suspend. I cannot test function with sbp2 at the moment, but raw1394 seems to work fine. Signed-off-by: Bernhard Kaindl Update 1: merge with previous two ohci1394 suspend/resume patches Update 2: version for application on top of Linux 2.6.19-rc4 Signed-off-by: Stefan Richter --- drivers/ieee1394/ohci1394.c | 92 ++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 14 deletions(-) (limited to 'drivers/ieee1394') diff --git a/drivers/ieee1394/ohci1394.c b/drivers/ieee1394/ohci1394.c index eae97d8dcf03..b98b9934b92d 100644 --- a/drivers/ieee1394/ohci1394.c +++ b/drivers/ieee1394/ohci1394.c @@ -3531,6 +3531,9 @@ static void ohci1394_pci_remove(struct pci_dev *pdev) #ifdef CONFIG_PM static int ohci1394_pci_resume (struct pci_dev *pdev) { + int err; + struct ti_ohci *ohci; + /* PowerMac resume code comes first */ #ifdef CONFIG_PPC_PMAC if (machine_is(powermac)) { @@ -3545,28 +3548,89 @@ static int ohci1394_pci_resume (struct pci_dev *pdev) pci_set_power_state(pdev, PCI_D0); pci_restore_state(pdev); - return pci_enable_device(pdev); + err = pci_enable_device(pdev); + if (err) + return err; + + ohci = pci_get_drvdata(pdev); + if (!ohci) + return -1; /* or which exit status to use? */ + + PRINT(KERN_DEBUG, "resume called"); + + /* The following lines are copied from ohci1394_pci_probe(): */ + + /* Start off with a soft reset, to clear everything to a sane + * state. */ + ohci_soft_reset(ohci); + + /* Now enable LPS, which we need in order to start accessing + * most of the registers. In fact, on some cards (ALI M5251), + * accessing registers in the SClk domain without LPS enabled + * will lock up the machine. Wait 50msec to make sure we have + * full link enabled. */ + reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_LPS); + + /* Disable and clear interrupts */ + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); + + mdelay(50); + + ohci_initialize(ohci); + + return 0; } static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) { int err; + struct ti_ohci *ohci; + + ohci = pci_get_drvdata(pdev); + if (!ohci) + return -1; /* Not sure if this is the correct return code */ + + PRINT(KERN_DEBUG, "suspend called"); + + /* clear the async DMA contexts and stop using the controller: */ + hpsb_bus_reset(ohci->host); + + /* The following calls are from ohci1394_pci_remove(): */ - printk(KERN_INFO "%s does not fully support suspend and resume yet\n", - OHCI1394_DRIVER_NAME); + /* Clear out BUS Options */ + reg_write(ohci, OHCI1394_ConfigROMhdr, 0); + reg_write(ohci, OHCI1394_BusOptions, + (reg_read(ohci, OHCI1394_BusOptions) & 0x0000f007) | + 0x00ff0000); + + /* Clear interrupt registers */ + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 0xffffffff); + reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 0xffffffff); + + /* Disable IRM Contender */ + set_phy_reg(ohci, 4, ~0xc0 & get_phy_reg(ohci, 4)); + + /* Clear link control register */ + reg_write(ohci, OHCI1394_LinkControlClear, 0xffffffff); + + /* Let all other nodes know to ignore us */ + ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT); + + /* This stops all DMA contexts, disables interrupts, + * and clears linkEnable and LPS: */ + ohci_soft_reset(ohci); err = pci_save_state(pdev); - if (err) { - printk(KERN_ERR "%s: pci_save_state failed with %d\n", - OHCI1394_DRIVER_NAME, err); - return err; - } + if (err) + goto out; err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); -#ifdef OHCI1394_DEBUG if (err) - printk(KERN_DEBUG "%s: pci_set_power_state failed with %d\n", - OHCI1394_DRIVER_NAME, err); -#endif /* OHCI1394_DEBUG */ + goto out; /* PowerMac suspend code comes last */ #ifdef CONFIG_PPC_PMAC @@ -3579,8 +3643,8 @@ static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); } #endif /* CONFIG_PPC_PMAC */ - - return 0; +out: + return err; } #endif /* CONFIG_PM */ -- cgit v1.2.3-58-ga151