1212 * any later version.
1313 */
1414
15+ #include <linux/clk.h>
1516#include <linux/kernel.h>
1617#include <linux/gfp.h>
1718#include <linux/module.h>
@@ -118,6 +119,17 @@ static int __init ahci_probe(struct platform_device *pdev)
118119 return - ENOMEM ;
119120 }
120121
122+ hpriv -> clk = clk_get (dev , NULL );
123+ if (IS_ERR (hpriv -> clk )) {
124+ dev_err (dev , "can't get clock\n" );
125+ } else {
126+ rc = clk_prepare_enable (hpriv -> clk );
127+ if (rc ) {
128+ dev_err (dev , "clock prepare enable failed" );
129+ goto free_clk ;
130+ }
131+ }
132+
121133 /*
122134 * Some platforms might need to prepare for mmio region access,
123135 * which could be done in the following init call. So, the mmio
@@ -127,7 +139,7 @@ static int __init ahci_probe(struct platform_device *pdev)
127139 if (pdata && pdata -> init ) {
128140 rc = pdata -> init (dev , hpriv -> mmio );
129141 if (rc )
130- return rc ;
142+ goto disable_unprepare_clk ;
131143 }
132144
133145 ahci_save_initial_config (dev , hpriv ,
@@ -153,7 +165,7 @@ static int __init ahci_probe(struct platform_device *pdev)
153165 host = ata_host_alloc_pinfo (dev , ppi , n_ports );
154166 if (!host ) {
155167 rc = - ENOMEM ;
156- goto err0 ;
168+ goto pdata_exit ;
157169 }
158170
159171 host -> private_data = hpriv ;
@@ -183,20 +195,26 @@ static int __init ahci_probe(struct platform_device *pdev)
183195
184196 rc = ahci_reset_controller (host );
185197 if (rc )
186- goto err0 ;
198+ goto pdata_exit ;
187199
188200 ahci_init_controller (host );
189201 ahci_print_info (host , "platform" );
190202
191203 rc = ata_host_activate (host , irq , ahci_interrupt , IRQF_SHARED ,
192204 & ahci_platform_sht );
193205 if (rc )
194- goto err0 ;
206+ goto pdata_exit ;
195207
196208 return 0 ;
197- err0 :
209+ pdata_exit :
198210 if (pdata && pdata -> exit )
199211 pdata -> exit (dev );
212+ disable_unprepare_clk :
213+ if (!IS_ERR (hpriv -> clk ))
214+ clk_disable_unprepare (hpriv -> clk );
215+ free_clk :
216+ if (!IS_ERR (hpriv -> clk ))
217+ clk_put (hpriv -> clk );
200218 return rc ;
201219}
202220
@@ -205,12 +223,18 @@ static int __devexit ahci_remove(struct platform_device *pdev)
205223 struct device * dev = & pdev -> dev ;
206224 struct ahci_platform_data * pdata = dev_get_platdata (dev );
207225 struct ata_host * host = dev_get_drvdata (dev );
226+ struct ahci_host_priv * hpriv = host -> private_data ;
208227
209228 ata_host_detach (host );
210229
211230 if (pdata && pdata -> exit )
212231 pdata -> exit (dev );
213232
233+ if (!IS_ERR (hpriv -> clk )) {
234+ clk_disable_unprepare (hpriv -> clk );
235+ clk_put (hpriv -> clk );
236+ }
237+
214238 return 0 ;
215239}
216240
@@ -245,32 +269,51 @@ static int ahci_suspend(struct device *dev)
245269
246270 if (pdata && pdata -> suspend )
247271 return pdata -> suspend (dev );
272+
273+ if (!IS_ERR (hpriv -> clk ))
274+ clk_disable_unprepare (hpriv -> clk );
275+
248276 return 0 ;
249277}
250278
251279static int ahci_resume (struct device * dev )
252280{
253281 struct ahci_platform_data * pdata = dev_get_platdata (dev );
254282 struct ata_host * host = dev_get_drvdata (dev );
283+ struct ahci_host_priv * hpriv = host -> private_data ;
255284 int rc ;
256285
286+ if (!IS_ERR (hpriv -> clk )) {
287+ rc = clk_prepare_enable (hpriv -> clk );
288+ if (rc ) {
289+ dev_err (dev , "clock prepare enable failed" );
290+ return rc ;
291+ }
292+ }
293+
257294 if (pdata && pdata -> resume ) {
258295 rc = pdata -> resume (dev );
259296 if (rc )
260- return rc ;
297+ goto disable_unprepare_clk ;
261298 }
262299
263300 if (dev -> power .power_state .event == PM_EVENT_SUSPEND ) {
264301 rc = ahci_reset_controller (host );
265302 if (rc )
266- return rc ;
303+ goto disable_unprepare_clk ;
267304
268305 ahci_init_controller (host );
269306 }
270307
271308 ata_host_resume (host );
272309
273310 return 0 ;
311+
312+ disable_unprepare_clk :
313+ if (!IS_ERR (hpriv -> clk ))
314+ clk_disable_unprepare (hpriv -> clk );
315+
316+ return rc ;
274317}
275318#endif
276319
0 commit comments