au1000: revert 43626 due to syntax errors
[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 --- a/drivers/ata/ahci_platform.c
21 +++ b/drivers/ata/ahci_platform.c
22 @@ -432,14 +432,23 @@ static void ahci_host_stop(struct ata_ho
23  }
24  
25  #ifdef CONFIG_PM_SLEEP
26 -static int ahci_suspend(struct device *dev)
27 +/**
28 + * ahci_platform_suspend_host - Suspend an ahci-platform host
29 + * @dev: device pointer for the host
30 + *
31 + * This function does all the usual steps needed to suspend an
32 + * ahci-platform host, note any necessary resources (ie clks, phy, etc.)
33 + * must be disabled after calling this.
34 + *
35 + * RETURNS:
36 + * 0 on success otherwise a negative error code
37 + */
38 +int ahci_platform_suspend_host(struct device *dev)
39  {
40 -       struct ahci_platform_data *pdata = dev_get_platdata(dev);
41         struct ata_host *host = dev_get_drvdata(dev);
42         struct ahci_host_priv *hpriv = host->private_data;
43         void __iomem *mmio = hpriv->mmio;
44         u32 ctl;
45 -       int rc;
46  
47         if (hpriv->flags & AHCI_HFLAG_NO_SUSPEND) {
48                 dev_err(dev, "firmware update required for suspend/resume\n");
49 @@ -456,7 +465,58 @@ static int ahci_suspend(struct device *d
50         writel(ctl, mmio + HOST_CTL);
51         readl(mmio + HOST_CTL); /* flush */
52  
53 -       rc = ata_host_suspend(host, PMSG_SUSPEND);
54 +       return ata_host_suspend(host, PMSG_SUSPEND);
55 +}
56 +EXPORT_SYMBOL_GPL(ahci_platform_suspend_host);
57 +
58 +/**
59 + * ahci_platform_resume_host - Resume an ahci-platform host
60 + * @dev: device pointer for the host
61 + *
62 + * This function does all the usual steps needed to resume an ahci-platform
63 + * host, note any necessary resources (ie clks, phy, etc.)  must be
64 + * initialized / enabled before calling this.
65 + *
66 + * RETURNS:
67 + * 0 on success otherwise a negative error code
68 + */
69 +int ahci_platform_resume_host(struct device *dev)
70 +{
71 +       struct ata_host *host = dev_get_drvdata(dev);
72 +       int rc;
73 +
74 +       if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
75 +               rc = ahci_reset_controller(host);
76 +               if (rc)
77 +                       return rc;
78 +
79 +               ahci_init_controller(host);
80 +       }
81 +
82 +       ata_host_resume(host);
83 +
84 +       return 0;
85 +}
86 +EXPORT_SYMBOL_GPL(ahci_platform_resume_host);
87 +
88 +/**
89 + * ahci_platform_suspend - Suspend an ahci-platform device
90 + * @dev: the platform device to suspend
91 + *
92 + * This function suspends the host associated with the device, followed by
93 + * disabling all the resources of the device.
94 + *
95 + * RETURNS:
96 + * 0 on success otherwise a negative error code
97 + */
98 +int ahci_platform_suspend(struct device *dev)
99 +{
100 +       struct ahci_platform_data *pdata = dev_get_platdata(dev);
101 +       struct ata_host *host = dev_get_drvdata(dev);
102 +       struct ahci_host_priv *hpriv = host->private_data;
103 +       int rc;
104 +
105 +       rc = ahci_platform_suspend_host(dev);
106         if (rc)
107                 return rc;
108  
109 @@ -467,8 +527,19 @@ static int ahci_suspend(struct device *d
110  
111         return 0;
112  }
113 +EXPORT_SYMBOL_GPL(ahci_platform_suspend);
114  
115 -static int ahci_resume(struct device *dev)
116 +/**
117 + * ahci_platform_resume - Resume an ahci-platform device
118 + * @dev: the platform device to resume
119 + *
120 + * This function enables all the resources of the device followed by
121 + * resuming the host associated with the device.
122 + *
123 + * RETURNS:
124 + * 0 on success otherwise a negative error code
125 + */
126 +int ahci_platform_resume(struct device *dev)
127  {
128         struct ahci_platform_data *pdata = dev_get_platdata(dev);
129         struct ata_host *host = dev_get_drvdata(dev);
130 @@ -485,15 +556,9 @@ static int ahci_resume(struct device *de
131                         goto disable_resources;
132         }
133  
134 -       if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
135 -               rc = ahci_reset_controller(host);
136 -               if (rc)
137 -                       goto disable_resources;
138 -
139 -               ahci_init_controller(host);
140 -       }
141 -
142 -       ata_host_resume(host);
143 +       rc = ahci_platform_resume_host(dev);
144 +       if (rc)
145 +               goto disable_resources;
146  
147         return 0;
148  
149 @@ -502,9 +567,11 @@ disable_resources:
150  
151         return rc;
152  }
153 +EXPORT_SYMBOL_GPL(ahci_platform_resume);
154  #endif
155  
156 -static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_suspend, ahci_resume);
157 +static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend,
158 +                        ahci_platform_resume);
159  
160  static const struct of_device_id ahci_of_match[] = {
161         { .compatible = "snps,spear-ahci", },
162 --- a/include/linux/ahci_platform.h
163 +++ b/include/linux/ahci_platform.h
164 @@ -50,4 +50,9 @@ int ahci_platform_init_host(struct platf
165                             unsigned int force_port_map,
166                             unsigned int mask_port_map);
167  
168 +int ahci_platform_suspend_host(struct device *dev);
169 +int ahci_platform_resume_host(struct device *dev);
170 +int ahci_platform_suspend(struct device *dev);
171 +int ahci_platform_resume(struct device *dev);
172 +
173  #endif /* _AHCI_PLATFORM_H */