Skip to content

Commit 648cb6f

Browse files
jwrdegoedehtejun
authored andcommitted
ahci-platform: "Library-ise" suspend / resume functionality
Split suspend / resume code into host suspend / resume functionality and resource enable / disabling phases, and export the new suspend_ / resume_host functions. tj: Minor comment formatting updates. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 23b07d4 commit 648cb6f

2 files changed

Lines changed: 87 additions & 15 deletions

File tree

‎drivers/ata/ahci_platform.c‎

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,23 @@ static void ahci_host_stop(struct ata_host *host)
432432
}
433433

434434
#ifdef CONFIG_PM_SLEEP
435-
static int ahci_suspend(struct device *dev)
435+
/**
436+
* ahci_platform_suspend_host - Suspend an ahci-platform host
437+
* @dev: device pointer for the host
438+
*
439+
* This function does all the usual steps needed to suspend an
440+
* ahci-platform host, note any necessary resources (ie clks, phy, etc.)
441+
* must be disabled after calling this.
442+
*
443+
* RETURNS:
444+
* 0 on success otherwise a negative error code
445+
*/
446+
int ahci_platform_suspend_host(struct device *dev)
436447
{
437-
struct ahci_platform_data *pdata = dev_get_platdata(dev);
438448
struct ata_host *host = dev_get_drvdata(dev);
439449
struct ahci_host_priv *hpriv = host->private_data;
440450
void __iomem *mmio = hpriv->mmio;
441451
u32 ctl;
442-
int rc;
443452

444453
if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
445454
dev_err(dev, "firmware update required for suspend/resume\n");
@@ -456,7 +465,58 @@ static int ahci_suspend(struct device *dev)
456465
writel(ctl, mmio + HOST_CTL);
457466
readl(mmio + HOST_CTL); /* flush */
458467

459-
rc = ata_host_suspend(host, PMSG_SUSPEND);
468+
return ata_host_suspend(host, PMSG_SUSPEND);
469+
}
470+
EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
471+
472+
/**
473+
* ahci_platform_resume_host - Resume an ahci-platform host
474+
* @dev: device pointer for the host
475+
*
476+
* This function does all the usual steps needed to resume an ahci-platform
477+
* host, note any necessary resources (ie clks, phy, etc.) must be
478+
* initialized / enabled before calling this.
479+
*
480+
* RETURNS:
481+
* 0 on success otherwise a negative error code
482+
*/
483+
int ahci_platform_resume_host(struct device *dev)
484+
{
485+
struct ata_host *host = dev_get_drvdata(dev);
486+
int rc;
487+
488+
if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
489+
rc = ahci_reset_controller(host);
490+
if (rc)
491+
return rc;
492+
493+
ahci_init_controller(host);
494+
}
495+
496+
ata_host_resume(host);
497+
498+
return 0;
499+
}
500+
EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
501+
502+
/**
503+
* ahci_platform_suspend - Suspend an ahci-platform device
504+
* @dev: the platform device to suspend
505+
*
506+
* This function suspends the host associated with the device, followed by
507+
* disabling all the resources of the device.
508+
*
509+
* RETURNS:
510+
* 0 on success otherwise a negative error code
511+
*/
512+
int ahci_platform_suspend(struct device *dev)
513+
{
514+
struct ahci_platform_data *pdata = dev_get_platdata(dev);
515+
struct ata_host *host = dev_get_drvdata(dev);
516+
struct ahci_host_priv *hpriv = host->private_data;
517+
int rc;
518+
519+
rc = ahci_platform_suspend_host(dev);
460520
if (rc)
461521
return rc;
462522

@@ -467,8 +527,19 @@ static int ahci_suspend(struct device *dev)
467527

468528
return 0;
469529
}
530+
EXPORT_SYMBOL_GPL(ahci_platform_suspend);
470531

471-
static int ahci_resume(struct device *dev)
532+
/**
533+
* ahci_platform_resume - Resume an ahci-platform device
534+
* @dev: the platform device to resume
535+
*
536+
* This function enables all the resources of the device followed by
537+
* resuming the host associated with the device.
538+
*
539+
* RETURNS:
540+
* 0 on success otherwise a negative error code
541+
*/
542+
int ahci_platform_resume(struct device *dev)
472543
{
473544
struct ahci_platform_data *pdata = dev_get_platdata(dev);
474545
struct ata_host *host = dev_get_drvdata(dev);
@@ -485,15 +556,9 @@ static int ahci_resume(struct device *dev)
485556
goto disable_resources;
486557
}
487558

488-
if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
489-
rc = ahci_reset_controller(host);
490-
if (rc)
491-
goto disable_resources;
492-
493-
ahci_init_controller(host);
494-
}
495-
496-
ata_host_resume(host);
559+
rc = ahci_platform_resume_host(dev);
560+
if (rc)
561+
goto disable_resources;
497562

498563
return 0;
499564

@@ -502,9 +567,11 @@ static int ahci_resume(struct device *dev)
502567

503568
return rc;
504569
}
570+
EXPORT_SYMBOL_GPL(ahci_platform_resume);
505571
#endif
506572

507-
static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
573+
static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
574+
ahci_platform_resume);
508575

509576
static const struct of_device_id ahci_of_match[] = {
510577
{ .compatible = "snps,spear-ahci", },

‎include/linux/ahci_platform.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,9 @@ int ahci_platform_init_host(struct platform_device *pdev,
5050
unsigned int force_port_map,
5151
unsigned int mask_port_map);
5252

53+
int ahci_platform_suspend_host(struct device *dev);
54+
int ahci_platform_resume_host(struct device *dev);
55+
int ahci_platform_suspend(struct device *dev);
56+
int ahci_platform_resume(struct device *dev);
57+
5358
#endif /* _AHCI_PLATFORM_H */

0 commit comments

Comments
 (0)