9a9cb074e8fdc6df2c18b6fda4d330f91aba43de
[15.05/openwrt.git] / target / linux / ipq806x / patches / 0115-ahci-platform-Library-ise-suspend-resume-functionali.patch
1 From 8121ed9c7ea2d56f5e0a98c2db396214f85d7485 Mon Sep 17 00:00:00 2001
2 From: Hans de Goede <hdegoede@redhat.com>
3 Date: Sat, 22 Feb 2014 16:53:35 +0100
4 Subject: [PATCH 115/182] ahci-platform: "Library-ise" suspend / resume
5  functionality
6
7 Split suspend / resume code into host suspend / resume functionality and
8 resource enable / disabling phases, and export the new suspend_ / resume_host
9 functions.
10
11 tj: Minor comment formatting updates.
12
13 Signed-off-by: Hans de Goede <hdegoede@redhat.com>
14 Signed-off-by: Tejun Heo <tj@kernel.org>
15 ---
16  drivers/ata/ahci_platform.c   |   97 ++++++++++++++++++++++++++++++++++-------
17  include/linux/ahci_platform.h |    5 +++
18  2 files changed, 87 insertions(+), 15 deletions(-)
19
20 diff --git a/drivers/ata/ahci_platform.c b/drivers/ata/ahci_platform.c
21 index 19e9eaa..01f7bbe 100644
22 --- a/drivers/ata/ahci_platform.c
23 +++ b/drivers/ata/ahci_platform.c
24 @@ -432,14 +432,23 @@ static void ahci_host_stop(struct ata_host *host)
25  }
26  
27  #ifdef CONFIG_PM_SLEEP
28 -static int ahci_suspend(struct device *dev)
29 +/**
30 + * ahci_platform_suspend_host - Suspend an ahci-platform host
31 + * @dev: device pointer for the host
32 + *
33 + * This function does all the usual steps needed to suspend an
34 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
35 + * must be disabled after calling this.
36 + *
37 + * RETURNS:
38 + * 0 on success otherwise a negative error code
39 + */
40 +int ahci_platform_suspend_host(struct device *dev)
41  {
42 -       struct ahci_platform_data *pdata = dev_get_platdata(dev);
43         struct ata_host *host = dev_get_drvdata(dev);
44         struct ahci_host_priv *hpriv = host->private_data;
45         void __iomem *mmio = hpriv->mmio;
46         u32 ctl;
47 -       int rc;
48  
49         if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
50                 dev_err(dev, "firmware update required for suspend/resume\n");
51 @@ -456,7 +465,58 @@ static int ahci_suspend(struct device *dev)
52         writel(ctl, mmio + HOST_CTL);
53         readl(mmio + HOST_CTL); /* flush */
54  
55 -       rc = ata_host_suspend(host, PMSG_SUSPEND);
56 +       return ata_host_suspend(host, PMSG_SUSPEND);
57 +}
58 +EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
59 +
60 +/**
61 + * ahci_platform_resume_host - Resume an ahci-platform host
62 + * @dev: device pointer for the host
63 + *
64 + * This function does all the usual steps needed to resume an ahci-platform
65 + * host, note any necessary resources (ie clks, phy, etc.)  must be
66 + * initialized / enabled before calling this.
67 + *
68 + * RETURNS:
69 + * 0 on success otherwise a negative error code
70 + */
71 +int ahci_platform_resume_host(struct device *dev)
72 +{
73 +       struct ata_host *host = dev_get_drvdata(dev);
74 +       int rc;
75 +
76 +       if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
77 +               rc = ahci_reset_controller(host);
78 +               if (rc)
79 +                       return rc;
80 +
81 +               ahci_init_controller(host);
82 +       }
83 +
84 +       ata_host_resume(host);
85 +
86 +       return 0;
87 +}
88 +EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
89 +
90 +/**
91 + * ahci_platform_suspend - Suspend an ahci-platform device
92 + * @dev: the platform device to suspend
93 + *
94 + * This function suspends the host associated with the device, followed by
95 + * disabling all the resources of the device.
96 + *
97 + * RETURNS:
98 + * 0 on success otherwise a negative error code
99 + */
100 +int ahci_platform_suspend(struct device *dev)
101 +{
102 +       struct ahci_platform_data *pdata = dev_get_platdata(dev);
103 +       struct ata_host *host = dev_get_drvdata(dev);
104 +       struct ahci_host_priv *hpriv = host->private_data;
105 +       int rc;
106 +
107 +       rc = ahci_platform_suspend_host(dev);
108         if (rc)
109                 return rc;
110  
111 @@ -467,8 +527,19 @@ static int ahci_suspend(struct device *dev)
112  
113         return 0;
114  }
115 +EXPORT_SYMBOL_GPL(ahci_platform_suspend);
116  
117 -static int ahci_resume(struct device *dev)
118 +/**
119 + * ahci_platform_resume - Resume an ahci-platform device
120 + * @dev: the platform device to resume
121 + *
122 + * This function enables all the resources of the device followed by
123 + * resuming the host associated with the device.
124 + *
125 + * RETURNS:
126 + * 0 on success otherwise a negative error code
127 + */
128 +int ahci_platform_resume(struct device *dev)
129  {
130         struct ahci_platform_data *pdata = dev_get_platdata(dev);
131         struct ata_host *host = dev_get_drvdata(dev);
132 @@ -485,15 +556,9 @@ static int ahci_resume(struct device *dev)
133                         goto disable_resources;
134         }
135  
136 -       if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
137 -               rc = ahci_reset_controller(host);
138 -               if (rc)
139 -                       goto disable_resources;
140 -
141 -               ahci_init_controller(host);
142 -       }
143 -
144 -       ata_host_resume(host);
145 +       rc = ahci_platform_resume_host(dev);
146 +       if (rc)
147 +               goto disable_resources;
148  
149         return 0;
150  
151 @@ -502,9 +567,11 @@ disable_resources:
152  
153         return rc;
154  }
155 +EXPORT_SYMBOL_GPL(ahci_platform_resume);
156  #endif
157  
158 -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
159 +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
160 +                        ahci_platform_resume);
161  
162  static const struct of_device_id ahci_of_match[] = {
163         { .compatible = "snps,spear-ahci", },
164 diff --git a/include/linux/ahci_platform.h b/include/linux/ahci_platform.h
165 index b80c51c..542f268 100644
166 --- a/include/linux/ahci_platform.h
167 +++ b/include/linux/ahci_platform.h
168 @@ -50,4 +50,9 @@ int ahci_platform_init_host(struct platform_device *pdev,
169                             unsigned int force_port_map,
170                             unsigned int mask_port_map);
171  
172 +int ahci_platform_suspend_host(struct device *dev);
173 +int ahci_platform_resume_host(struct device *dev);
174 +int ahci_platform_suspend(struct device *dev);
175 +int ahci_platform_resume(struct device *dev);
176 +
177  #endif /* _AHCI_PLATFORM_H */
178 -- 
179 1.7.10.4
180