Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <bk@fsfe.org>

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 <stefanr@s5r6.in-berlin.de>

authored by

Bernhard Kaindl and committed by
Stefan Richter
f011bf08 f9edc4f5

+79 -15
+79 -15
drivers/ieee1394/ohci1394.c
··· 3531 3531 #ifdef CONFIG_PM 3532 3532 static int ohci1394_pci_resume (struct pci_dev *pdev) 3533 3533 { 3534 + int err; 3535 + struct ti_ohci *ohci; 3536 + 3534 3537 /* PowerMac resume code comes first */ 3535 3538 #ifdef CONFIG_PPC_PMAC 3536 3539 if (machine_is(powermac)) { ··· 3548 3545 3549 3546 pci_set_power_state(pdev, PCI_D0); 3550 3547 pci_restore_state(pdev); 3551 - return pci_enable_device(pdev); 3548 + err = pci_enable_device(pdev); 3549 + if (err) 3550 + return err; 3551 + 3552 + ohci = pci_get_drvdata(pdev); 3553 + if (!ohci) 3554 + return -1; /* or which exit status to use? */ 3555 + 3556 + PRINT(KERN_DEBUG, "resume called"); 3557 + 3558 + /* The following lines are copied from ohci1394_pci_probe(): */ 3559 + 3560 + /* Start off with a soft reset, to clear everything to a sane 3561 + * state. */ 3562 + ohci_soft_reset(ohci); 3563 + 3564 + /* Now enable LPS, which we need in order to start accessing 3565 + * most of the registers. In fact, on some cards (ALI M5251), 3566 + * accessing registers in the SClk domain without LPS enabled 3567 + * will lock up the machine. Wait 50msec to make sure we have 3568 + * full link enabled. */ 3569 + reg_write(ohci, OHCI1394_HCControlSet, OHCI1394_HCControl_LPS); 3570 + 3571 + /* Disable and clear interrupts */ 3572 + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); 3573 + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); 3574 + 3575 + mdelay(50); 3576 + 3577 + ohci_initialize(ohci); 3578 + 3579 + return 0; 3552 3580 } 3553 3581 3554 3582 static int ohci1394_pci_suspend (struct pci_dev *pdev, pm_message_t state) 3555 3583 { 3556 3584 int err; 3585 + struct ti_ohci *ohci; 3557 3586 3558 - printk(KERN_INFO "%s does not fully support suspend and resume yet\n", 3559 - OHCI1394_DRIVER_NAME); 3587 + ohci = pci_get_drvdata(pdev); 3588 + if (!ohci) 3589 + return -1; /* Not sure if this is the correct return code */ 3590 + 3591 + PRINT(KERN_DEBUG, "suspend called"); 3592 + 3593 + /* clear the async DMA contexts and stop using the controller: */ 3594 + hpsb_bus_reset(ohci->host); 3595 + 3596 + /* The following calls are from ohci1394_pci_remove(): */ 3597 + 3598 + /* Clear out BUS Options */ 3599 + reg_write(ohci, OHCI1394_ConfigROMhdr, 0); 3600 + reg_write(ohci, OHCI1394_BusOptions, 3601 + (reg_read(ohci, OHCI1394_BusOptions) & 0x0000f007) | 3602 + 0x00ff0000); 3603 + 3604 + /* Clear interrupt registers */ 3605 + reg_write(ohci, OHCI1394_IntMaskClear, 0xffffffff); 3606 + reg_write(ohci, OHCI1394_IntEventClear, 0xffffffff); 3607 + reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, 0xffffffff); 3608 + reg_write(ohci, OHCI1394_IsoXmitIntEventClear, 0xffffffff); 3609 + reg_write(ohci, OHCI1394_IsoRecvIntMaskClear, 0xffffffff); 3610 + reg_write(ohci, OHCI1394_IsoRecvIntEventClear, 0xffffffff); 3611 + 3612 + /* Disable IRM Contender */ 3613 + set_phy_reg(ohci, 4, ~0xc0 & get_phy_reg(ohci, 4)); 3614 + 3615 + /* Clear link control register */ 3616 + reg_write(ohci, OHCI1394_LinkControlClear, 0xffffffff); 3617 + 3618 + /* Let all other nodes know to ignore us */ 3619 + ohci_devctl(ohci->host, RESET_BUS, LONG_RESET_NO_FORCE_ROOT); 3620 + 3621 + /* This stops all DMA contexts, disables interrupts, 3622 + * and clears linkEnable and LPS: */ 3623 + ohci_soft_reset(ohci); 3560 3624 3561 3625 err = pci_save_state(pdev); 3562 - if (err) { 3563 - printk(KERN_ERR "%s: pci_save_state failed with %d\n", 3564 - OHCI1394_DRIVER_NAME, err); 3565 - return err; 3566 - } 3567 - err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); 3568 - #ifdef OHCI1394_DEBUG 3569 3626 if (err) 3570 - printk(KERN_DEBUG "%s: pci_set_power_state failed with %d\n", 3571 - OHCI1394_DRIVER_NAME, err); 3572 - #endif /* OHCI1394_DEBUG */ 3627 + goto out; 3628 + err = pci_set_power_state(pdev, pci_choose_state(pdev, state)); 3629 + if (err) 3630 + goto out; 3573 3631 3574 3632 /* PowerMac suspend code comes last */ 3575 3633 #ifdef CONFIG_PPC_PMAC ··· 3643 3579 pmac_call_feature(PMAC_FTR_1394_ENABLE, of_node, 0, 0); 3644 3580 } 3645 3581 #endif /* CONFIG_PPC_PMAC */ 3646 - 3647 - return 0; 3582 + out: 3583 + return err; 3648 3584 } 3649 3585 #endif /* CONFIG_PM */ 3650 3586