* any later version.
  */
 
+#include <linux/clk.h>
 #include <linux/kernel.h>
 #include <linux/gfp.h>
 #include <linux/module.h>
                return -ENOMEM;
        }
 
+       hpriv->clk = clk_get(dev, NULL);
+       if (IS_ERR(hpriv->clk)) {
+               dev_err(dev, "can't get clock\n");
+       } else {
+               rc = clk_prepare_enable(hpriv->clk);
+               if (rc) {
+                       dev_err(dev, "clock prepare enable failed");
+                       goto free_clk;
+               }
+       }
+
        /*
         * Some platforms might need to prepare for mmio region access,
         * which could be done in the following init call. So, the mmio
        if (pdata && pdata->init) {
                rc = pdata->init(dev, hpriv->mmio);
                if (rc)
-                       return rc;
+                       goto disable_unprepare_clk;
        }
 
        ahci_save_initial_config(dev, hpriv,
        host = ata_host_alloc_pinfo(dev, ppi, n_ports);
        if (!host) {
                rc = -ENOMEM;
-               goto err0;
+               goto pdata_exit;
        }
 
        host->private_data = hpriv;
 
        rc = ahci_reset_controller(host);
        if (rc)
-               goto err0;
+               goto pdata_exit;
 
        ahci_init_controller(host);
        ahci_print_info(host, "platform");
        rc = ata_host_activate(host, irq, ahci_interrupt, IRQF_SHARED,
                               &ahci_platform_sht);
        if (rc)
-               goto err0;
+               goto pdata_exit;
 
        return 0;
-err0:
+pdata_exit:
        if (pdata && pdata->exit)
                pdata->exit(dev);
+disable_unprepare_clk:
+       if (!IS_ERR(hpriv->clk))
+               clk_disable_unprepare(hpriv->clk);
+free_clk:
+       if (!IS_ERR(hpriv->clk))
+               clk_put(hpriv->clk);
        return rc;
 }
 
        struct device *dev = &pdev->dev;
        struct ahci_platform_data *pdata = dev_get_platdata(dev);
        struct ata_host *host = dev_get_drvdata(dev);
+       struct ahci_host_priv *hpriv = host->private_data;
 
        ata_host_detach(host);
 
        if (pdata && pdata->exit)
                pdata->exit(dev);
 
+       if (!IS_ERR(hpriv->clk)) {
+               clk_disable_unprepare(hpriv->clk);
+               clk_put(hpriv->clk);
+       }
+
        return 0;
 }
 
 
        if (pdata && pdata->suspend)
                return pdata->suspend(dev);
+
+       if (!IS_ERR(hpriv->clk))
+               clk_disable_unprepare(hpriv->clk);
+
        return 0;
 }
 
 {
        struct ahci_platform_data *pdata = dev_get_platdata(dev);
        struct ata_host *host = dev_get_drvdata(dev);
+       struct ahci_host_priv *hpriv = host->private_data;
        int rc;
 
+       if (!IS_ERR(hpriv->clk)) {
+               rc = clk_prepare_enable(hpriv->clk);
+               if (rc) {
+                       dev_err(dev, "clock prepare enable failed");
+                       return rc;
+               }
+       }
+
        if (pdata && pdata->resume) {
                rc = pdata->resume(dev);
                if (rc)
-                       return rc;
+                       goto disable_unprepare_clk;
        }
 
        if (dev->power.power_state.event == PM_EVENT_SUSPEND) {
                rc = ahci_reset_controller(host);
                if (rc)
-                       return rc;
+                       goto disable_unprepare_clk;
 
                ahci_init_controller(host);
        }
        ata_host_resume(host);
 
        return 0;
+
+disable_unprepare_clk:
+       if (!IS_ERR(hpriv->clk))
+               clk_disable_unprepare(hpriv->clk);
+
+       return rc;
 }
 #endif