Lines Matching full:hba

47 static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba,
55 static void ufs_qcom_dump_regs_wrapper(struct ufs_hba *hba, int offset, int len, in ufs_qcom_dump_regs_wrapper() argument
58 ufshcd_dump_regs(hba, offset, len * 4, prefix); in ufs_qcom_dump_regs_wrapper()
114 struct device *dev = host->hba->dev; in ufs_qcom_enable_lane_clks()
155 struct device *dev = host->hba->dev; in ufs_qcom_init_lane_clks()
171 if (host->hba->lanes_per_direction > 1) { in ufs_qcom_init_lane_clks()
184 static int ufs_qcom_check_hibern8(struct ufs_hba *hba) in ufs_qcom_check_hibern8() argument
191 err = ufshcd_dme_get(hba, in ufs_qcom_check_hibern8()
207 err = ufshcd_dme_get(hba, in ufs_qcom_check_hibern8()
213 dev_err(hba->dev, "%s: unable to get TX_FSM_STATE, err %d\n", in ufs_qcom_check_hibern8()
217 dev_err(hba->dev, "%s: invalid TX_FSM_STATE = %d\n", in ufs_qcom_check_hibern8()
226 ufshcd_rmwl(host->hba, QUNIPRO_SEL, in ufs_qcom_select_unipro_mode()
236 static int ufs_qcom_host_reset(struct ufs_hba *hba) in ufs_qcom_host_reset() argument
239 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_host_reset()
243 dev_warn(hba->dev, "%s: reset control not set\n", __func__); in ufs_qcom_host_reset()
247 reenable_intr = hba->is_irq_enabled; in ufs_qcom_host_reset()
248 disable_irq(hba->irq); in ufs_qcom_host_reset()
249 hba->is_irq_enabled = false; in ufs_qcom_host_reset()
253 dev_err(hba->dev, "%s: core_reset assert failed, err = %d\n", in ufs_qcom_host_reset()
267 dev_err(hba->dev, "%s: core_reset deassert failed, err = %d\n", in ufs_qcom_host_reset()
273 enable_irq(hba->irq); in ufs_qcom_host_reset()
274 hba->is_irq_enabled = true; in ufs_qcom_host_reset()
281 static int ufs_qcom_power_up_sequence(struct ufs_hba *hba) in ufs_qcom_power_up_sequence() argument
283 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_power_up_sequence()
289 ret = ufs_qcom_host_reset(hba); in ufs_qcom_power_up_sequence()
291 dev_warn(hba->dev, "%s: host reset returned %d\n", in ufs_qcom_power_up_sequence()
300 dev_err(hba->dev, "%s: phy init failed, ret = %d\n", in ufs_qcom_power_up_sequence()
308 dev_err(hba->dev, "%s: phy power on failed, ret = %d\n", in ufs_qcom_power_up_sequence()
331 static void ufs_qcom_enable_hw_clk_gating(struct ufs_hba *hba) in ufs_qcom_enable_hw_clk_gating() argument
333 ufshcd_writel(hba, in ufs_qcom_enable_hw_clk_gating()
334 ufshcd_readl(hba, REG_UFS_CFG2) | REG_UFS_CFG2_CGC_EN_ALL, in ufs_qcom_enable_hw_clk_gating()
341 static int ufs_qcom_hce_enable_notify(struct ufs_hba *hba, in ufs_qcom_hce_enable_notify() argument
344 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_hce_enable_notify()
349 ufs_qcom_power_up_sequence(hba); in ufs_qcom_hce_enable_notify()
359 err = ufs_qcom_check_hibern8(hba); in ufs_qcom_hce_enable_notify()
360 ufs_qcom_enable_hw_clk_gating(hba); in ufs_qcom_hce_enable_notify()
364 dev_err(hba->dev, "%s: invalid status %d\n", __func__, status); in ufs_qcom_hce_enable_notify()
374 static int ufs_qcom_cfg_timers(struct ufs_hba *hba, u32 gear, in ufs_qcom_cfg_timers() argument
378 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_cfg_timers()
411 if (ufs_qcom_cap_qunipro(host) && !ufshcd_is_intr_aggr_allowed(hba)) in ufs_qcom_cfg_timers()
415 dev_err(hba->dev, "%s: invalid gear = %d\n", __func__, gear); in ufs_qcom_cfg_timers()
419 list_for_each_entry(clki, &hba->clk_list_head, list) { in ufs_qcom_cfg_timers()
429 if (ufshcd_readl(hba, REG_UFS_SYS1CLK_1US) != core_clk_cycles_per_us) { in ufs_qcom_cfg_timers()
430 ufshcd_writel(hba, core_clk_cycles_per_us, REG_UFS_SYS1CLK_1US); in ufs_qcom_cfg_timers()
450 dev_err(hba->dev, in ufs_qcom_cfg_timers()
459 dev_err(hba->dev, in ufs_qcom_cfg_timers()
467 dev_err(hba->dev, "%s: invalid rate = %d\n", in ufs_qcom_cfg_timers()
475 dev_err(hba->dev, in ufs_qcom_cfg_timers()
485 dev_err(hba->dev, "%s: invalid mode = %d\n", __func__, hs); in ufs_qcom_cfg_timers()
489 if (ufshcd_readl(hba, REG_UFS_TX_SYMBOL_CLK_NS_US) != in ufs_qcom_cfg_timers()
492 ufshcd_writel(hba, core_clk_period_in_ns | tx_clk_cycles_per_us, in ufs_qcom_cfg_timers()
502 ufshcd_writel(hba, ((core_clk_rate / MSEC_PER_SEC) * 100), in ufs_qcom_cfg_timers()
518 static int ufs_qcom_link_startup_notify(struct ufs_hba *hba, in ufs_qcom_link_startup_notify() argument
522 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_link_startup_notify()
526 if (ufs_qcom_cfg_timers(hba, UFS_PWM_G1, SLOWAUTO_MODE, in ufs_qcom_link_startup_notify()
528 dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n", in ufs_qcom_link_startup_notify()
539 err = ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, in ufs_qcom_link_startup_notify()
549 if (ufshcd_get_local_unipro_ver(hba) != UFS_UNIPRO_VER_1_41) in ufs_qcom_link_startup_notify()
550 err = ufshcd_disable_host_tx_lcc(hba); in ufs_qcom_link_startup_notify()
561 static void ufs_qcom_device_reset_ctrl(struct ufs_hba *hba, bool asserted) in ufs_qcom_device_reset_ctrl() argument
563 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_device_reset_ctrl()
572 static int ufs_qcom_suspend(struct ufs_hba *hba, enum ufs_pm_op pm_op, in ufs_qcom_suspend() argument
575 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_suspend()
581 if (ufs_qcom_is_link_off(hba)) { in ufs_qcom_suspend()
591 ufs_qcom_device_reset_ctrl(hba, true); in ufs_qcom_suspend()
593 } else if (!ufs_qcom_is_link_active(hba)) { in ufs_qcom_suspend()
600 static int ufs_qcom_resume(struct ufs_hba *hba, enum ufs_pm_op pm_op) in ufs_qcom_resume() argument
602 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_resume()
606 if (ufs_qcom_is_link_off(hba)) { in ufs_qcom_resume()
609 dev_err(hba->dev, "%s: failed PHY power on: %d\n", in ufs_qcom_resume()
618 } else if (!ufs_qcom_is_link_active(hba)) { in ufs_qcom_resume()
647 gating_wait = host->hba->dev_info.clk_gating_wait_us; in ufs_qcom_dev_ref_clk_ctrl()
683 static int ufs_qcom_pwr_change_notify(struct ufs_hba *hba, in ufs_qcom_pwr_change_notify() argument
688 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_pwr_change_notify()
727 if (!ufshcd_is_hs_mode(&hba->pwr_info) && in ufs_qcom_pwr_change_notify()
732 ufshcd_dme_configure_adapt(hba, in ufs_qcom_pwr_change_notify()
738 if (ufs_qcom_cfg_timers(hba, dev_req_params->gear_rx, in ufs_qcom_pwr_change_notify()
741 dev_err(hba->dev, "%s: ufs_qcom_cfg_timers() failed\n", in ufs_qcom_pwr_change_notify()
756 if (ufshcd_is_hs_mode(&hba->pwr_info) && in ufs_qcom_pwr_change_notify()
768 static int ufs_qcom_quirk_host_pa_saveconfigtime(struct ufs_hba *hba) in ufs_qcom_quirk_host_pa_saveconfigtime() argument
773 err = ufshcd_dme_get(hba, UIC_ARG_MIB(PA_VS_CONFIG_REG1), in ufs_qcom_quirk_host_pa_saveconfigtime()
779 err = ufshcd_dme_set(hba, UIC_ARG_MIB(PA_VS_CONFIG_REG1), in ufs_qcom_quirk_host_pa_saveconfigtime()
786 static int ufs_qcom_apply_dev_quirks(struct ufs_hba *hba) in ufs_qcom_apply_dev_quirks() argument
790 if (hba->dev_quirks & UFS_DEVICE_QUIRK_HOST_PA_SAVECONFIGTIME) in ufs_qcom_apply_dev_quirks()
791 err = ufs_qcom_quirk_host_pa_saveconfigtime(hba); in ufs_qcom_apply_dev_quirks()
793 if (hba->dev_info.wmanufacturerid == UFS_VENDOR_WDC) in ufs_qcom_apply_dev_quirks()
794 hba->dev_quirks |= UFS_DEVICE_QUIRK_HOST_PA_TACTIVATE; in ufs_qcom_apply_dev_quirks()
799 static u32 ufs_qcom_get_ufs_hci_version(struct ufs_hba *hba) in ufs_qcom_get_ufs_hci_version() argument
801 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_get_ufs_hci_version()
811 * @hba: host controller instance
818 static void ufs_qcom_advertise_quirks(struct ufs_hba *hba) in ufs_qcom_advertise_quirks() argument
820 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_advertise_quirks()
823 hba->quirks |= UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS in ufs_qcom_advertise_quirks()
828 hba->quirks |= UFSHCD_QUIRK_BROKEN_INTR_AGGR; in ufs_qcom_advertise_quirks()
830 hba->quirks |= UFSHCD_QUIRK_BROKEN_LCC; in ufs_qcom_advertise_quirks()
834 hba->quirks |= UFSHCD_QUIRK_BROKEN_UFS_HCI_VERSION; in ufs_qcom_advertise_quirks()
838 hba->quirks |= (UFSHCD_QUIRK_DELAY_BEFORE_DME_CMDS in ufs_qcom_advertise_quirks()
844 static void ufs_qcom_set_caps(struct ufs_hba *hba) in ufs_qcom_set_caps() argument
846 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_set_caps()
848 hba->caps |= UFSHCD_CAP_CLK_GATING | UFSHCD_CAP_HIBERN8_WITH_CLK_GATING; in ufs_qcom_set_caps()
849 hba->caps |= UFSHCD_CAP_CLK_SCALING | UFSHCD_CAP_WB_WITH_CLK_SCALING; in ufs_qcom_set_caps()
850 hba->caps |= UFSHCD_CAP_AUTO_BKOPS_SUSPEND; in ufs_qcom_set_caps()
851 hba->caps |= UFSHCD_CAP_WB_EN; in ufs_qcom_set_caps()
852 hba->caps |= UFSHCD_CAP_CRYPTO; in ufs_qcom_set_caps()
853 hba->caps |= UFSHCD_CAP_AGGR_POWER_COLLAPSE; in ufs_qcom_set_caps()
854 hba->caps |= UFSHCD_CAP_RPM_AUTOSUSPEND; in ufs_qcom_set_caps()
864 * @hba: host controller instance
870 static int ufs_qcom_setup_clocks(struct ufs_hba *hba, bool on, in ufs_qcom_setup_clocks() argument
873 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_setup_clocks()
886 if (!ufs_qcom_is_link_active(hba)) { in ufs_qcom_setup_clocks()
895 if (ufshcd_is_hs_mode(&hba->pwr_info)) in ufs_qcom_setup_clocks()
911 ufs_qcom_assert_reset(host->hba); in ufs_qcom_reset_assert()
924 ufs_qcom_deassert_reset(host->hba); in ufs_qcom_reset_deassert()
941 * @hba: host controller instance
949 static int ufs_qcom_init(struct ufs_hba *hba) in ufs_qcom_init() argument
952 struct device *dev = hba->dev; in ufs_qcom_init()
965 /* Make a two way bind between the qcom host and the hba */ in ufs_qcom_init()
966 host->hba = hba; in ufs_qcom_init()
967 ufshcd_set_variant(hba, host); in ufs_qcom_init()
970 host->core_reset = devm_reset_control_get_optional(hba->dev, "rst"); in ufs_qcom_init()
1005 ufs_qcom_get_controller_revision(hba, &host->hw_ver.major, in ufs_qcom_init()
1013 host->dev_ref_clk_ctrl_mmio = hba->mmio_base + REG_UFS_CFG1; in ufs_qcom_init()
1028 list_for_each_entry(clki, &hba->clk_list_head, list) { in ufs_qcom_init()
1037 ufs_qcom_set_caps(hba); in ufs_qcom_init()
1038 ufs_qcom_advertise_quirks(hba); in ufs_qcom_init()
1044 ufs_qcom_setup_clocks(hba, true, POST_CHANGE); in ufs_qcom_init()
1046 if (hba->dev->id < MAX_UFS_QCOM_HOSTS) in ufs_qcom_init()
1047 ufs_qcom_hosts[hba->dev->id] = host; in ufs_qcom_init()
1061 ufshcd_set_variant(hba, NULL); in ufs_qcom_init()
1066 static void ufs_qcom_exit(struct ufs_hba *hba) in ufs_qcom_exit() argument
1068 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_exit()
1075 static int ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(struct ufs_hba *hba, in ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div() argument
1084 err = ufshcd_dme_get(hba, in ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div()
1096 err = ufshcd_dme_set(hba, in ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div()
1103 static int ufs_qcom_clk_scale_up_pre_change(struct ufs_hba *hba) in ufs_qcom_clk_scale_up_pre_change() argument
1109 static int ufs_qcom_clk_scale_up_post_change(struct ufs_hba *hba) in ufs_qcom_clk_scale_up_post_change() argument
1111 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_clk_scale_up_post_change()
1117 return ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, 150); in ufs_qcom_clk_scale_up_post_change()
1120 static int ufs_qcom_clk_scale_down_pre_change(struct ufs_hba *hba) in ufs_qcom_clk_scale_down_pre_change() argument
1122 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_clk_scale_down_pre_change()
1129 err = ufshcd_dme_get(hba, in ufs_qcom_clk_scale_down_pre_change()
1137 err = ufshcd_dme_set(hba, in ufs_qcom_clk_scale_down_pre_change()
1145 static int ufs_qcom_clk_scale_down_post_change(struct ufs_hba *hba) in ufs_qcom_clk_scale_down_post_change() argument
1147 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_clk_scale_down_post_change()
1153 return ufs_qcom_set_dme_vs_core_clk_ctrl_clear_div(hba, 75); in ufs_qcom_clk_scale_down_post_change()
1156 static int ufs_qcom_clk_scale_notify(struct ufs_hba *hba, in ufs_qcom_clk_scale_notify() argument
1159 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_clk_scale_notify()
1164 err = ufshcd_uic_hibern8_enter(hba); in ufs_qcom_clk_scale_notify()
1168 err = ufs_qcom_clk_scale_up_pre_change(hba); in ufs_qcom_clk_scale_notify()
1170 err = ufs_qcom_clk_scale_down_pre_change(hba); in ufs_qcom_clk_scale_notify()
1172 ufshcd_uic_hibern8_exit(hba); in ufs_qcom_clk_scale_notify()
1176 err = ufs_qcom_clk_scale_up_post_change(hba); in ufs_qcom_clk_scale_notify()
1178 err = ufs_qcom_clk_scale_down_post_change(hba); in ufs_qcom_clk_scale_notify()
1182 ufshcd_uic_hibern8_exit(hba); in ufs_qcom_clk_scale_notify()
1186 ufs_qcom_cfg_timers(hba, in ufs_qcom_clk_scale_notify()
1191 ufshcd_uic_hibern8_exit(hba); in ufs_qcom_clk_scale_notify()
1198 static void ufs_qcom_print_hw_debug_reg_all(struct ufs_hba *hba, in ufs_qcom_print_hw_debug_reg_all() argument
1199 void *priv, void (*print_fn)(struct ufs_hba *hba, in ufs_qcom_print_hw_debug_reg_all() argument
1205 if (unlikely(!hba)) { in ufs_qcom_print_hw_debug_reg_all()
1206 pr_err("%s: hba is NULL\n", __func__); in ufs_qcom_print_hw_debug_reg_all()
1210 dev_err(hba->dev, "%s: print_fn is NULL\n", __func__); in ufs_qcom_print_hw_debug_reg_all()
1214 host = ufshcd_get_variant(hba); in ufs_qcom_print_hw_debug_reg_all()
1219 print_fn(hba, reg, 44, "UFS_UFS_DBG_RD_REG_OCSC ", priv); in ufs_qcom_print_hw_debug_reg_all()
1221 reg = ufshcd_readl(hba, REG_UFS_CFG1); in ufs_qcom_print_hw_debug_reg_all()
1223 ufshcd_writel(hba, reg, REG_UFS_CFG1); in ufs_qcom_print_hw_debug_reg_all()
1226 print_fn(hba, reg, 32, "UFS_UFS_DBG_RD_EDTL_RAM ", priv); in ufs_qcom_print_hw_debug_reg_all()
1229 print_fn(hba, reg, 128, "UFS_UFS_DBG_RD_DESC_RAM ", priv); in ufs_qcom_print_hw_debug_reg_all()
1232 print_fn(hba, reg, 64, "UFS_UFS_DBG_RD_PRDT_RAM ", priv); in ufs_qcom_print_hw_debug_reg_all()
1235 ufshcd_rmwl(hba, UTP_DBG_RAMS_EN, 0, REG_UFS_CFG1); in ufs_qcom_print_hw_debug_reg_all()
1238 print_fn(hba, reg, 4, "UFS_DBG_RD_REG_UAWM ", priv); in ufs_qcom_print_hw_debug_reg_all()
1241 print_fn(hba, reg, 4, "UFS_DBG_RD_REG_UARM ", priv); in ufs_qcom_print_hw_debug_reg_all()
1244 print_fn(hba, reg, 48, "UFS_DBG_RD_REG_TXUC ", priv); in ufs_qcom_print_hw_debug_reg_all()
1247 print_fn(hba, reg, 27, "UFS_DBG_RD_REG_RXUC ", priv); in ufs_qcom_print_hw_debug_reg_all()
1250 print_fn(hba, reg, 19, "UFS_DBG_RD_REG_DFC ", priv); in ufs_qcom_print_hw_debug_reg_all()
1253 print_fn(hba, reg, 34, "UFS_DBG_RD_REG_TRLUT ", priv); in ufs_qcom_print_hw_debug_reg_all()
1256 print_fn(hba, reg, 9, "UFS_DBG_RD_REG_TMRLUT ", priv); in ufs_qcom_print_hw_debug_reg_all()
1262 ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN, in ufs_qcom_enable_test_bus()
1264 ufshcd_rmwl(host->hba, TEST_BUS_EN, TEST_BUS_EN, REG_UFS_CFG1); in ufs_qcom_enable_test_bus()
1266 ufshcd_rmwl(host->hba, UFS_REG_TEST_BUS_EN, 0, REG_UFS_CFG1); in ufs_qcom_enable_test_bus()
1267 ufshcd_rmwl(host->hba, TEST_BUS_EN, 0, REG_UFS_CFG1); in ufs_qcom_enable_test_bus()
1281 dev_err(host->hba->dev, in ufs_qcom_testbus_cfg_is_ok()
1359 ufshcd_rmwl(host->hba, TEST_BUS_SEL, in ufs_qcom_testbus_config()
1362 ufshcd_rmwl(host->hba, mask, in ufs_qcom_testbus_config()
1375 static void ufs_qcom_dump_dbg_regs(struct ufs_hba *hba) in ufs_qcom_dump_dbg_regs() argument
1377 ufshcd_dump_regs(hba, REG_UFS_SYS1CLK_1US, 16 * 4, in ufs_qcom_dump_dbg_regs()
1380 ufs_qcom_print_hw_debug_reg_all(hba, NULL, ufs_qcom_dump_regs_wrapper); in ufs_qcom_dump_dbg_regs()
1385 * @hba: per-adapter instance
1389 static int ufs_qcom_device_reset(struct ufs_hba *hba) in ufs_qcom_device_reset() argument
1391 struct ufs_qcom_host *host = ufshcd_get_variant(hba); in ufs_qcom_device_reset()
1401 ufs_qcom_device_reset_ctrl(hba, true); in ufs_qcom_device_reset()
1404 ufs_qcom_device_reset_ctrl(hba, false); in ufs_qcom_device_reset()
1411 static void ufs_qcom_config_scaling_param(struct ufs_hba *hba, in ufs_qcom_config_scaling_param() argument
1420 static void ufs_qcom_config_scaling_param(struct ufs_hba *hba, in ufs_qcom_config_scaling_param() argument
1479 struct ufs_hba *hba = platform_get_drvdata(pdev); in ufs_qcom_remove() local
1482 ufshcd_remove(hba); in ufs_qcom_remove()