Merge tag '4.4-scsi-mkp' into misc
[firefly-linux-kernel-4.4.55.git] / drivers / scsi / ufs / ufshcd.c
index 9065eb4516776749407731994d2b4541a5ba285a..85cd2564c15773f728e8bd6ae6fcde28867ab2bb 100644 (file)
@@ -271,10 +271,8 @@ static inline u32 ufshcd_get_intr_mask(struct ufs_hba *hba)
  */
 static inline u32 ufshcd_get_ufs_version(struct ufs_hba *hba)
 {
-       if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION) {
-               if (hba->vops && hba->vops->get_ufs_hci_version)
-                       return hba->vops->get_ufs_hci_version(hba);
-       }
+       if (hba->quirks & UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION)
+               return ufshcd_vops_get_ufs_hci_version(hba);
 
        return ufshcd_readl(hba, REG_UFS_VERSION);
 }
@@ -627,6 +625,7 @@ start:
 out:
        return rc;
 }
+EXPORT_SYMBOL_GPL(ufshcd_hold);
 
 static void ufshcd_gate_work(struct work_struct *work)
 {
@@ -714,6 +713,7 @@ void ufshcd_release(struct ufs_hba *hba)
        __ufshcd_release(hba);
        spin_unlock_irqrestore(hba->host->host_lock, flags);
 }
+EXPORT_SYMBOL_GPL(ufshcd_release);
 
 static ssize_t ufshcd_clkgate_delay_show(struct device *dev,
                struct device_attribute *attr, char *buf)
@@ -2473,9 +2473,8 @@ static int ufshcd_change_power_mode(struct ufs_hba *hba,
                dev_err(hba->dev,
                        "%s: power mode change failed %d\n", __func__, ret);
        } else {
-               if (hba->vops && hba->vops->pwr_change_notify)
-                       hba->vops->pwr_change_notify(hba,
-                               POST_CHANGE, NULL, pwr_mode);
+               ufshcd_vops_pwr_change_notify(hba, POST_CHANGE, NULL,
+                                                               pwr_mode);
 
                memcpy(&hba->pwr_info, pwr_mode,
                        sizeof(struct ufs_pa_layer_attr));
@@ -2495,10 +2494,10 @@ static int ufshcd_config_pwr_mode(struct ufs_hba *hba,
        struct ufs_pa_layer_attr final_params = { 0 };
        int ret;
 
-       if (hba->vops && hba->vops->pwr_change_notify)
-               hba->vops->pwr_change_notify(hba,
-                    PRE_CHANGE, desired_pwr_mode, &final_params);
-       else
+       ret = ufshcd_vops_pwr_change_notify(hba, PRE_CHANGE,
+                                       desired_pwr_mode, &final_params);
+
+       if (ret)
                memcpy(&final_params, desired_pwr_mode, sizeof(final_params));
 
        ret = ufshcd_change_power_mode(hba, &final_params);
@@ -2647,8 +2646,7 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)
        /* UniPro link is disabled at this point */
        ufshcd_set_link_off(hba);
 
-       if (hba->vops && hba->vops->hce_enable_notify)
-               hba->vops->hce_enable_notify(hba, PRE_CHANGE);
+       ufshcd_vops_hce_enable_notify(hba, PRE_CHANGE);
 
        /* start controller initialization sequence */
        ufshcd_hba_start(hba);
@@ -2681,8 +2679,7 @@ static int ufshcd_hba_enable(struct ufs_hba *hba)
        /* enable UIC related interrupts */
        ufshcd_enable_intr(hba, UFSHCD_UIC_MASK);
 
-       if (hba->vops && hba->vops->hce_enable_notify)
-               hba->vops->hce_enable_notify(hba, POST_CHANGE);
+       ufshcd_vops_hce_enable_notify(hba, POST_CHANGE);
 
        return 0;
 }
@@ -2735,8 +2732,7 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
        int retries = DME_LINKSTARTUP_RETRIES;
 
        do {
-               if (hba->vops && hba->vops->link_startup_notify)
-                       hba->vops->link_startup_notify(hba, PRE_CHANGE);
+               ufshcd_vops_link_startup_notify(hba, PRE_CHANGE);
 
                ret = ufshcd_dme_link_startup(hba);
 
@@ -2767,11 +2763,9 @@ static int ufshcd_link_startup(struct ufs_hba *hba)
        }
 
        /* Include any host controller configuration via UIC commands */
-       if (hba->vops && hba->vops->link_startup_notify) {
-               ret = hba->vops->link_startup_notify(hba, POST_CHANGE);
-               if (ret)
-                       goto out;
-       }
+       ret = ufshcd_vops_link_startup_notify(hba, POST_CHANGE);
+       if (ret)
+               goto out;
 
        ret = ufshcd_make_hba_operational(hba);
 out:
@@ -4577,8 +4571,7 @@ static int __ufshcd_setup_clocks(struct ufs_hba *hba, bool on,
                }
        }
 
-       if (hba->vops && hba->vops->setup_clocks)
-               ret = hba->vops->setup_clocks(hba, on);
+       ret = ufshcd_vops_setup_clocks(hba, on);
 out:
        if (ret) {
                list_for_each_entry(clki, head, list) {
@@ -4644,27 +4637,22 @@ static int ufshcd_variant_hba_init(struct ufs_hba *hba)
        if (!hba->vops)
                goto out;
 
-       if (hba->vops->init) {
-               err = hba->vops->init(hba);
-               if (err)
-                       goto out;
-       }
+       err = ufshcd_vops_init(hba);
+       if (err)
+               goto out;
 
-       if (hba->vops->setup_regulators) {
-               err = hba->vops->setup_regulators(hba, true);
-               if (err)
-                       goto out_exit;
-       }
+       err = ufshcd_vops_setup_regulators(hba, true);
+       if (err)
+               goto out_exit;
 
        goto out;
 
 out_exit:
-       if (hba->vops->exit)
-               hba->vops->exit(hba);
+       ufshcd_vops_exit(hba);
 out:
        if (err)
                dev_err(hba->dev, "%s: variant %s init failed err %d\n",
-                       __func__, hba->vops ? hba->vops->name : "", err);
+                       __func__, ufshcd_get_var_name(hba), err);
        return err;
 }
 
@@ -4673,14 +4661,11 @@ static void ufshcd_variant_hba_exit(struct ufs_hba *hba)
        if (!hba->vops)
                return;
 
-       if (hba->vops->setup_clocks)
-               hba->vops->setup_clocks(hba, false);
+       ufshcd_vops_setup_clocks(hba, false);
 
-       if (hba->vops->setup_regulators)
-               hba->vops->setup_regulators(hba, false);
+       ufshcd_vops_setup_regulators(hba, false);
 
-       if (hba->vops->exit)
-               hba->vops->exit(hba);
+       ufshcd_vops_exit(hba);
 }
 
 static int ufshcd_hba_init(struct ufs_hba *hba)
@@ -5057,17 +5042,13 @@ disable_clks:
         * vendor specific host controller register space call them before the
         * host clocks are ON.
         */
-       if (hba->vops && hba->vops->suspend) {
-               ret = hba->vops->suspend(hba, pm_op);
-               if (ret)
-                       goto set_link_active;
-       }
+       ret = ufshcd_vops_suspend(hba, pm_op);
+       if (ret)
+               goto set_link_active;
 
-       if (hba->vops && hba->vops->setup_clocks) {
-               ret = hba->vops->setup_clocks(hba, false);
-               if (ret)
-                       goto vops_resume;
-       }
+       ret = ufshcd_vops_setup_clocks(hba, false);
+       if (ret)
+               goto vops_resume;
 
        if (!ufshcd_is_link_active(hba))
                ufshcd_setup_clocks(hba, false);
@@ -5078,7 +5059,7 @@ disable_clks:
        hba->clk_gating.state = CLKS_OFF;
        /*
         * Disable the host irq as host controller as there won't be any
-        * host controller trasanction expected till resume.
+        * host controller transaction expected till resume.
         */
        ufshcd_disable_irq(hba);
        /* Put the host controller in low power mode if possible */
@@ -5086,8 +5067,7 @@ disable_clks:
        goto out;
 
 vops_resume:
-       if (hba->vops && hba->vops->resume)
-               hba->vops->resume(hba, pm_op);
+       ufshcd_vops_resume(hba, pm_op);
 set_link_active:
        ufshcd_vreg_set_hpm(hba);
        if (ufshcd_is_link_hibern8(hba) && !ufshcd_uic_hibern8_exit(hba))
@@ -5143,11 +5123,9 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
         * vendor specific host controller register space call them when the
         * host clocks are ON.
         */
-       if (hba->vops && hba->vops->resume) {
-               ret = hba->vops->resume(hba, pm_op);
-               if (ret)
-                       goto disable_vreg;
-       }
+       ret = ufshcd_vops_resume(hba, pm_op);
+       if (ret)
+               goto disable_vreg;
 
        if (ufshcd_is_link_hibern8(hba)) {
                ret = ufshcd_uic_hibern8_exit(hba);
@@ -5188,8 +5166,7 @@ static int ufshcd_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op)
 set_old_link_state:
        ufshcd_link_state_transition(hba, old_link_state, 0);
 vendor_suspend:
-       if (hba->vops && hba->vops->suspend)
-               hba->vops->suspend(hba, pm_op);
+       ufshcd_vops_suspend(hba, pm_op);
 disable_vreg:
        ufshcd_vreg_set_lpm(hba);
 disable_irq_and_vops_clks:
@@ -5371,6 +5348,16 @@ void ufshcd_remove(struct ufs_hba *hba)
 }
 EXPORT_SYMBOL_GPL(ufshcd_remove);
 
+/**
+ * ufshcd_dealloc_host - deallocate Host Bus Adapter (HBA)
+ * @hba: pointer to Host Bus Adapter (HBA)
+ */
+void ufshcd_dealloc_host(struct ufs_hba *hba)
+{
+       scsi_host_put(hba->host);
+}
+EXPORT_SYMBOL_GPL(ufshcd_dealloc_host);
+
 /**
  * ufshcd_set_dma_mask - Set dma mask based on the controller
  *                      addressing capability
@@ -5432,6 +5419,10 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
        if (!head || list_empty(head))
                goto out;
 
+       ret = ufshcd_vops_clk_scale_notify(hba, scale_up, PRE_CHANGE);
+       if (ret)
+               return ret;
+
        list_for_each_entry(clki, head, list) {
                if (!IS_ERR_OR_NULL(clki->clk)) {
                        if (scale_up && clki->max_freq) {
@@ -5462,8 +5453,9 @@ static int ufshcd_scale_clks(struct ufs_hba *hba, bool scale_up)
                dev_dbg(hba->dev, "%s: clk: %s, rate: %lu\n", __func__,
                                clki->name, clk_get_rate(clki->clk));
        }
-       if (hba->vops->clk_scale_notify)
-               hba->vops->clk_scale_notify(hba);
+
+       ret = ufshcd_vops_clk_scale_notify(hba, scale_up, POST_CHANGE);
+
 out:
        return ret;
 }