@@ -85,6 +85,7 @@ enum board_ids {
85
85
};
86
86
87
87
static int ahci_init_one (struct pci_dev * pdev , const struct pci_device_id * ent );
88
+ static void ahci_remove_one (struct pci_dev * dev );
88
89
static int ahci_vt8251_hardreset (struct ata_link * link , unsigned int * class ,
89
90
unsigned long deadline );
90
91
static int ahci_avn_hardreset (struct ata_link * link , unsigned int * class ,
@@ -93,10 +94,14 @@ static void ahci_mcp89_apple_enable(struct pci_dev *pdev);
93
94
static bool is_mcp89_apple (struct pci_dev * pdev );
94
95
static int ahci_p5wdh_hardreset (struct ata_link * link , unsigned int * class ,
95
96
unsigned long deadline );
97
+ #ifdef CONFIG_PM
98
+ static int ahci_pci_device_runtime_suspend (struct device * dev );
99
+ static int ahci_pci_device_runtime_resume (struct device * dev );
96
100
#ifdef CONFIG_PM_SLEEP
97
101
static int ahci_pci_device_suspend (struct device * dev );
98
102
static int ahci_pci_device_resume (struct device * dev );
99
103
#endif
104
+ #endif /* CONFIG_PM */
100
105
101
106
static struct scsi_host_template ahci_sht = {
102
107
AHCI_SHT ("ahci" ),
@@ -559,13 +564,15 @@ static const struct pci_device_id ahci_pci_tbl[] = {
559
564
560
565
static const struct dev_pm_ops ahci_pci_pm_ops = {
561
566
SET_SYSTEM_SLEEP_PM_OPS (ahci_pci_device_suspend , ahci_pci_device_resume )
567
+ SET_RUNTIME_PM_OPS (ahci_pci_device_runtime_suspend ,
568
+ ahci_pci_device_runtime_resume , NULL )
562
569
};
563
570
564
571
static struct pci_driver ahci_pci_driver = {
565
572
.name = DRV_NAME ,
566
573
.id_table = ahci_pci_tbl ,
567
574
.probe = ahci_init_one ,
568
- .remove = ata_pci_remove_one ,
575
+ .remove = ahci_remove_one ,
569
576
.driver = {
570
577
.pm = & ahci_pci_pm_ops ,
571
578
},
@@ -796,21 +803,13 @@ static int ahci_avn_hardreset(struct ata_link *link, unsigned int *class,
796
803
}
797
804
798
805
799
- #ifdef CONFIG_PM_SLEEP
800
- static int ahci_pci_device_suspend (struct device * dev )
806
+ #ifdef CONFIG_PM
807
+ static void ahci_pci_disable_interrupts (struct ata_host * host )
801
808
{
802
- struct pci_dev * pdev = to_pci_dev (dev );
803
- struct ata_host * host = pci_get_drvdata (pdev );
804
809
struct ahci_host_priv * hpriv = host -> private_data ;
805
810
void __iomem * mmio = hpriv -> mmio ;
806
811
u32 ctl ;
807
812
808
- if (hpriv -> flags & AHCI_HFLAG_NO_SUSPEND ) {
809
- dev_err (& pdev -> dev ,
810
- "BIOS update required for suspend/resume\n" );
811
- return - EIO ;
812
- }
813
-
814
813
/* AHCI spec rev1.1 section 8.3.3:
815
814
* Software must disable interrupts prior to requesting a
816
815
* transition of the HBA to D3 state.
@@ -819,7 +818,44 @@ static int ahci_pci_device_suspend(struct device *dev)
819
818
ctl &= ~HOST_IRQ_EN ;
820
819
writel (ctl , mmio + HOST_CTL );
821
820
readl (mmio + HOST_CTL ); /* flush */
821
+ }
822
+
823
+ static int ahci_pci_device_runtime_suspend (struct device * dev )
824
+ {
825
+ struct pci_dev * pdev = to_pci_dev (dev );
826
+ struct ata_host * host = pci_get_drvdata (pdev );
822
827
828
+ ahci_pci_disable_interrupts (host );
829
+ return 0 ;
830
+ }
831
+
832
+ static int ahci_pci_device_runtime_resume (struct device * dev )
833
+ {
834
+ struct pci_dev * pdev = to_pci_dev (dev );
835
+ struct ata_host * host = pci_get_drvdata (pdev );
836
+ int rc ;
837
+
838
+ rc = ahci_pci_reset_controller (host );
839
+ if (rc )
840
+ return rc ;
841
+ ahci_pci_init_controller (host );
842
+ return 0 ;
843
+ }
844
+
845
+ #ifdef CONFIG_PM_SLEEP
846
+ static int ahci_pci_device_suspend (struct device * dev )
847
+ {
848
+ struct pci_dev * pdev = to_pci_dev (dev );
849
+ struct ata_host * host = pci_get_drvdata (pdev );
850
+ struct ahci_host_priv * hpriv = host -> private_data ;
851
+
852
+ if (hpriv -> flags & AHCI_HFLAG_NO_SUSPEND ) {
853
+ dev_err (& pdev -> dev ,
854
+ "BIOS update required for suspend/resume\n" );
855
+ return - EIO ;
856
+ }
857
+
858
+ ahci_pci_disable_interrupts (host );
823
859
return ata_host_suspend (host , PMSG_SUSPEND );
824
860
}
825
861
@@ -847,6 +883,8 @@ static int ahci_pci_device_resume(struct device *dev)
847
883
}
848
884
#endif
849
885
886
+ #endif /* CONFIG_PM */
887
+
850
888
static int ahci_configure_dma_masks (struct pci_dev * pdev , int using_dac )
851
889
{
852
890
int rc ;
@@ -1666,7 +1704,18 @@ static int ahci_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
1666
1704
1667
1705
pci_set_master (pdev );
1668
1706
1669
- return ahci_host_activate (host , & ahci_sht );
1707
+ rc = ahci_host_activate (host , & ahci_sht );
1708
+ if (rc )
1709
+ return rc ;
1710
+
1711
+ pm_runtime_put_noidle (& pdev -> dev );
1712
+ return 0 ;
1713
+ }
1714
+
1715
+ static void ahci_remove_one (struct pci_dev * pdev )
1716
+ {
1717
+ pm_runtime_get_noresume (& pdev -> dev );
1718
+ ata_pci_remove_one (pdev );
1670
1719
}
1671
1720
1672
1721
module_pci_driver (ahci_pci_driver );
0 commit comments