Skip to content

Commit aece27a

Browse files
samorris-lexhtejun
authored andcommitted
ata: ahci_platform: allow disabling of hotplug to save power
A number of resources remain powered to support hotplug. On platforms I've worked with, allowing the ahci_platform to suspend saves about 150mW. This patch enables rpm and allows the device to be auto-suspended through sysfs. Signed-off-by: Samuel Morris <samorris@lexmark.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent 332c42a commit aece27a

3 files changed

Lines changed: 76 additions & 19 deletions

File tree

‎drivers/ata/ahci_platform.c‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,13 @@ static int ahci_probe(struct platform_device *pdev)
6868
return rc;
6969
}
7070

71-
static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
72-
ahci_platform_resume);
71+
#ifdef CONFIG_PM_SLEEP
72+
static const struct dev_pm_ops ahci_pm_ops = {
73+
SET_SYSTEM_SLEEP_PM_OPS(ahci_platform_suspend, ahci_platform_resume)
74+
SET_RUNTIME_PM_OPS(ahci_platform_runtime_suspend,
75+
ahci_platform_runtime_resume, NULL)
76+
};
77+
#endif
7378

7479
static const struct of_device_id ahci_of_match[] = {
7580
{ .compatible = "generic-ahci", },
@@ -98,7 +103,9 @@ static struct platform_driver ahci_driver = {
98103
.name = DRV_NAME,
99104
.of_match_table = ahci_of_match,
100105
.acpi_match_table = ahci_acpi_match,
106+
#ifdef CONFIG_PM_SLEEP
101107
.pm = &ahci_pm_ops,
108+
#endif
102109
},
103110
};
104111
module_platform_driver(ahci_driver);

‎drivers/ata/libahci_platform.c‎

Lines changed: 65 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ static void ahci_platform_put_resources(struct device *dev, void *res)
257257
int c;
258258

259259
if (hpriv->got_runtime_pm) {
260-
pm_runtime_put_sync(dev);
260+
pm_runtime_allow(dev);
261261
pm_runtime_disable(dev);
262262
}
263263

@@ -475,8 +475,10 @@ struct ahci_host_priv *ahci_platform_get_resources(struct platform_device *pdev)
475475
if (rc == -EPROBE_DEFER)
476476
goto err_out;
477477
}
478+
479+
pm_runtime_set_active(dev);
478480
pm_runtime_enable(dev);
479-
pm_runtime_get_sync(dev);
481+
pm_runtime_forbid(dev);
480482
hpriv->got_runtime_pm = true;
481483

482484
devres_remove_group(dev, NULL);
@@ -705,6 +707,21 @@ int ahci_platform_resume_host(struct device *dev)
705707
}
706708
EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
707709

710+
static int _ahci_platform_suspend(struct device *dev)
711+
{
712+
struct ata_host *host = dev_get_drvdata(dev);
713+
struct ahci_host_priv *hpriv = host->private_data;
714+
int rc;
715+
716+
rc = ahci_platform_suspend_host(dev);
717+
if (rc)
718+
return rc;
719+
720+
ahci_platform_disable_resources(hpriv);
721+
722+
return 0;
723+
}
724+
708725
/**
709726
* ahci_platform_suspend - Suspend an ahci-platform device
710727
* @dev: the platform device to suspend
@@ -716,20 +733,45 @@ EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
716733
* 0 on success otherwise a negative error code
717734
*/
718735
int ahci_platform_suspend(struct device *dev)
736+
{
737+
return _ahci_platform_suspend(dev);
738+
}
739+
EXPORT_SYMBOL_GPL(ahci_platform_suspend);
740+
741+
/**
742+
* ahci_platform_runtime_suspend - Runtime suspend an ahci-platform device
743+
* @dev: the platform device to suspend
744+
*
745+
* This function suspends the host associated with the device, followed by
746+
* disabling all the resources of the device.
747+
*
748+
* RETURNS:
749+
* 0 on success otherwise a negative error code
750+
*/
751+
int ahci_platform_runtime_suspend(struct device *dev)
752+
{
753+
return _ahci_platform_suspend(dev);
754+
}
755+
EXPORT_SYMBOL_GPL(ahci_platform_runtime_suspend);
756+
757+
static int _ahci_platform_resume(struct device *dev)
719758
{
720759
struct ata_host *host = dev_get_drvdata(dev);
721760
struct ahci_host_priv *hpriv = host->private_data;
722761
int rc;
723762

724-
rc = ahci_platform_suspend_host(dev);
763+
rc = ahci_platform_enable_resources(hpriv);
725764
if (rc)
726765
return rc;
727766

728-
ahci_platform_disable_resources(hpriv);
767+
rc = ahci_platform_resume_host(dev);
768+
if (rc) {
769+
ahci_platform_disable_resources(hpriv);
770+
return rc;
771+
}
729772

730773
return 0;
731774
}
732-
EXPORT_SYMBOL_GPL(ahci_platform_suspend);
733775

734776
/**
735777
* ahci_platform_resume - Resume an ahci-platform device
@@ -743,31 +785,37 @@ EXPORT_SYMBOL_GPL(ahci_platform_suspend);
743785
*/
744786
int ahci_platform_resume(struct device *dev)
745787
{
746-
struct ata_host *host = dev_get_drvdata(dev);
747-
struct ahci_host_priv *hpriv = host->private_data;
748788
int rc;
749789

750-
rc = ahci_platform_enable_resources(hpriv);
790+
rc = _ahci_platform_resume(dev);
751791
if (rc)
752792
return rc;
753793

754-
rc = ahci_platform_resume_host(dev);
755-
if (rc)
756-
goto disable_resources;
757-
758794
/* We resumed so update PM runtime state */
759795
pm_runtime_disable(dev);
760796
pm_runtime_set_active(dev);
761797
pm_runtime_enable(dev);
762798

763799
return 0;
764-
765-
disable_resources:
766-
ahci_platform_disable_resources(hpriv);
767-
768-
return rc;
769800
}
770801
EXPORT_SYMBOL_GPL(ahci_platform_resume);
802+
803+
/**
804+
* ahci_platform_runtime_resume - Runtime resume an ahci-platform device
805+
* @dev: the platform device to resume
806+
*
807+
* This function enables all the resources of the device followed by
808+
* resuming the host associated with the device.
809+
*
810+
* RETURNS:
811+
* 0 on success otherwise a negative error code
812+
*/
813+
int ahci_platform_runtime_resume(struct device *dev)
814+
{
815+
return _ahci_platform_resume(dev);
816+
}
817+
EXPORT_SYMBOL_GPL(ahci_platform_runtime_resume);
818+
771819
#endif
772820

773821
MODULE_DESCRIPTION("AHCI SATA platform library");

‎include/linux/ahci_platform.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ int ahci_platform_suspend_host(struct device *dev);
4242
int ahci_platform_resume_host(struct device *dev);
4343
int ahci_platform_suspend(struct device *dev);
4444
int ahci_platform_resume(struct device *dev);
45+
int ahci_platform_runtime_suspend(struct device *dev);
46+
int ahci_platform_runtime_resume(struct device *dev);
4547

4648
#endif /* _AHCI_PLATFORM_H */

0 commit comments

Comments
 (0)