Browse Source

Merge "msm: camera: common: Add common wait and poll interface" into camera-kernel.lnx.5.0

Savita Patted 4 năm trước cách đây
mục cha
commit
72d6f26c7a
26 tập tin đã thay đổi với 261 bổ sung116 xóa
  1. 12 8
      drivers/cam_cdm/cam_cdm_hw_core.c
  2. 8 5
      drivers/cam_fd/fd_hw_mgr/fd_hw/cam_fd_hw_core.c
  3. 12 11
      drivers/cam_icp/hfi.c
  4. 7 3
      drivers/cam_icp/icp_hw/a5_hw/a5_core.c
  5. 24 15
      drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c
  6. 5 3
      drivers/cam_icp/icp_hw/lx7_hw/lx7_core.c
  7. 3 3
      drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c
  8. 3 3
      drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c
  9. 13 8
      drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c
  10. 2 1
      drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c
  11. 5 3
      drivers/cam_isp/isp_hw_mgr/isp_hw/ppi_hw/cam_csid_ppi_core.c
  12. 22 14
      drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_csid_hw/cam_tfe_csid_core.c
  13. 4 2
      drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c
  14. 3 1
      drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c
  15. 8 5
      drivers/cam_jpeg/jpeg_hw/jpeg_dma_hw/jpeg_dma_core.c
  16. 8 5
      drivers/cam_jpeg/jpeg_hw/jpeg_enc_hw/jpeg_enc_core.c
  17. 3 3
      drivers/cam_lrme/lrme_hw_mgr/lrme_hw/cam_lrme_hw_core.c
  18. 3 2
      drivers/cam_ope/ope_hw_mgr/ope_hw/bus_rd/ope_bus_rd.c
  19. 4 3
      drivers/cam_ope/ope_hw_mgr/ope_hw/top/ope_top.c
  20. 3 2
      drivers/cam_req_mgr/cam_req_mgr_core.c
  21. 8 8
      drivers/cam_sensor_module/cam_cci/cam_cci_core.c
  22. 2 1
      drivers/cam_sensor_module/cam_cci/cam_cci_dev.h
  23. 2 2
      drivers/cam_sensor_module/cam_cci/cam_cci_soc.c
  24. 2 2
      drivers/cam_sync/cam_sync.c
  25. 57 2
      drivers/cam_utils/cam_common_util.c
  26. 38 1
      drivers/cam_utils/cam_common_util.h

+ 12 - 8
drivers/cam_cdm/cam_cdm_hw_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/delay.h>
@@ -26,6 +26,7 @@
 #include "camera_main.h"
 #include "cam_trace.h"
 #include "cam_req_mgr_workq.h"
+#include "cam_common_util.h"
 
 #define CAM_CDM_BL_FIFO_WAIT_TIMEOUT 2000
 #define CAM_CDM_DBG_GEN_IRQ_USR_DATA 0xff
@@ -688,7 +689,7 @@ int cam_hw_cdm_wait_for_bl_fifo(
 				CAM_ERR(CAM_CDM, "Enable BL done irq failed");
 				break;
 			}
-			time_left = wait_for_completion_timeout(
+			time_left = cam_common_wait_for_completion_timeout(
 				&core->bl_fifo[fifo_idx].bl_complete,
 				msecs_to_jiffies(
 				CAM_CDM_BL_FIFO_WAIT_TIMEOUT));
@@ -1727,8 +1728,9 @@ int cam_hw_cdm_reset_hw(struct cam_hw_info *cdm_hw, uint32_t handle)
 
 	CAM_DBG(CAM_CDM, "Waiting for %s%u HW reset done",
 		soc_info->label_name, soc_info->index);
-	time_left = wait_for_completion_timeout(&cdm_core->reset_complete,
-		msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
+	time_left = cam_common_wait_for_completion_timeout(
+			&cdm_core->reset_complete,
+			msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
 
 	if (time_left <= 0) {
 		rc = -ETIMEDOUT;
@@ -1829,8 +1831,9 @@ int cam_hw_cdm_handle_error_info(
 	}
 
 	CAM_DBG(CAM_CDM, "Waiting for CDM HW resetdone");
-	time_left = wait_for_completion_timeout(&cdm_core->reset_complete,
-		msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
+	time_left = cam_common_wait_for_completion_timeout(
+			&cdm_core->reset_complete,
+			msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
 
 	if (time_left <= 0) {
 		rc = -ETIMEDOUT;
@@ -2131,8 +2134,9 @@ int cam_hw_cdm_deinit(void *hw_priv,
 
 	CAM_DBG(CAM_CDM, "Waiting for %s%u HW reset done",
 		soc_info->label_name, soc_info->index);
-	time_left = wait_for_completion_timeout(&cdm_core->reset_complete,
-		msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
+	time_left = cam_common_wait_for_completion_timeout(
+			&cdm_core->reset_complete,
+			msecs_to_jiffies(CAM_CDM_HW_RESET_TIMEOUT));
 
 	if (time_left <= 0) {
 		rc = -ETIMEDOUT;

+ 8 - 5
drivers/cam_fd/fd_hw_mgr/fd_hw/cam_fd_hw_core.c

@@ -1,11 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include "cam_fd_hw_core.h"
 #include "cam_fd_hw_soc.h"
 #include "cam_trace.h"
+#include "cam_common_util.h"
 
 #define CAM_FD_REG_VAL_PAIR_SIZE 256
 
@@ -117,8 +118,9 @@ static int cam_fd_hw_util_fdwrapper_sync_reset(struct cam_hw_info *fd_hw)
 	cam_fd_soc_register_write(soc_info, CAM_FD_REG_WRAPPER,
 		hw_static_info->wrapper_regs.sw_reset, 0x1);
 
-	time_left = wait_for_completion_timeout(&fd_core->reset_complete,
-		msecs_to_jiffies(CAM_FD_HW_HALT_RESET_TIMEOUT));
+	time_left = cam_common_wait_for_completion_timeout(
+			&fd_core->reset_complete,
+			msecs_to_jiffies(CAM_FD_HW_HALT_RESET_TIMEOUT));
 	if (time_left <= 0)
 		CAM_WARN(CAM_FD, "HW reset timeout time_left=%ld", time_left);
 
@@ -147,8 +149,9 @@ static int cam_fd_hw_util_fdwrapper_halt(struct cam_hw_info *fd_hw)
 	cam_fd_soc_register_write(soc_info, CAM_FD_REG_WRAPPER,
 		hw_static_info->wrapper_regs.hw_stop, 0x1);
 
-	time_left = wait_for_completion_timeout(&fd_core->halt_complete,
-		msecs_to_jiffies(CAM_FD_HW_HALT_RESET_TIMEOUT));
+	time_left = cam_common_wait_for_completion_timeout(
+			&fd_core->halt_complete,
+			msecs_to_jiffies(CAM_FD_HW_HALT_RESET_TIMEOUT));
 	if (time_left <= 0)
 		CAM_WARN(CAM_FD, "HW halt timeout time_left=%ld", time_left);
 

+ 12 - 11
drivers/cam_icp/hfi.c

@@ -602,12 +602,13 @@ int cam_hfi_resume(struct hfi_mem_info *hfi_mem)
 		return -EINVAL;
 	}
 
-	if (readl_poll_timeout(icp_base + HFI_REG_ICP_HOST_INIT_RESPONSE,
-			       status, status == ICP_INIT_RESP_SUCCESS,
-			       HFI_POLL_DELAY_US, HFI_POLL_TIMEOUT_US)) {
-		CAM_ERR(CAM_HFI, "response poll timed out: status=0x%08x",
-			status);
-		return -ETIMEDOUT;
+	if (cam_common_read_poll_timeout(icp_base +
+		    HFI_REG_ICP_HOST_INIT_RESPONSE,
+		    HFI_POLL_DELAY_US, HFI_POLL_TIMEOUT_US,
+		    0x1, ICP_INIT_RESP_SUCCESS, &status)) {
+	    CAM_ERR(CAM_HFI, "response poll timed out: status=0x%08x",
+		    status);
+	    return -ETIMEDOUT;
 	}
 
 	hfi_irq_enable(g_hfi);
@@ -873,11 +874,11 @@ int cam_hfi_init(struct hfi_mem_info *hfi_mem, const struct hfi_ops *hfi_ops,
 		hfi_mem->qtbl.iova, hfi_mem->qtbl.len,
 		hfi_mem->sfr_buf.iova, hfi_mem->sfr_buf.len);
 
-	if (readl_poll_timeout(icp_base + HFI_REG_ICP_HOST_INIT_RESPONSE,
-			status, status == ICP_INIT_RESP_SUCCESS,
-			HFI_POLL_DELAY_US, HFI_POLL_TIMEOUT_US)) {
-		CAM_ERR(CAM_HFI,
-			"response poll timed out: status=0x%08x",
+	if (cam_common_read_poll_timeout(icp_base +
+		    HFI_REG_ICP_HOST_INIT_RESPONSE,
+		    HFI_POLL_DELAY_US, HFI_POLL_TIMEOUT_US,
+		    0x1, ICP_INIT_RESP_SUCCESS, &status)) {
+		CAM_ERR(CAM_HFI, "response poll timed out: status=0x%08x",
 			status);
 		rc = -ETIMEDOUT;
 		goto regions_fail;

+ 7 - 3
drivers/cam_icp/icp_hw/a5_hw/a5_core.c

@@ -27,6 +27,7 @@
 #include "cam_cpas_api.h"
 #include "cam_debug_util.h"
 #include "cam_icp_utils.h"
+#include "cam_common_util.h"
 
 #define PC_POLL_DELAY_US 100
 #define PC_POLL_TIMEOUT_US 10000
@@ -333,9 +334,12 @@ static int cam_a5_power_collapse(struct cam_hw_info *a5_info)
 	 * and Host can then proceed. No interrupt is expected
 	 * from FW at this time.
 	 */
-	if (readl_poll_timeout(base + ICP_SIERRA_A5_CSR_A5_STATUS,
-				status, status & A5_CSR_A5_STANDBYWFI,
-				PC_POLL_DELAY_US, PC_POLL_TIMEOUT_US)) {
+
+	if (cam_common_read_poll_timeout(base +
+		    ICP_SIERRA_A5_CSR_A5_STATUS,
+		    PC_POLL_DELAY_US, PC_POLL_TIMEOUT_US,
+		    A5_CSR_A5_STANDBYWFI,
+		    A5_CSR_A5_STANDBYWFI, &status)) {
 		CAM_ERR(CAM_ICP, "WFI poll timed out: status=0x%08x", status);
 		return -ETIMEDOUT;
 	}

+ 24 - 15
drivers/cam_icp/icp_hw/icp_hw_mgr/cam_icp_hw_mgr.c

@@ -3179,8 +3179,9 @@ static int cam_icp_mgr_send_pc_prep(struct cam_icp_hw_mgr *hw_mgr)
 		return rc;
 
 	CAM_DBG(CAM_ICP, "Wait for PC_PREP_DONE Message\n");
-	rem_jiffies = wait_for_completion_timeout(&icp_hw_mgr.icp_complete,
-		msecs_to_jiffies((timeout)));
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&icp_hw_mgr.icp_complete,
+			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;
 		CAM_ERR(CAM_ICP, "PC_PREP response timed out %d\n", rc);
@@ -3512,7 +3513,7 @@ static int cam_icp_retry_wait_for_abort(
 	CAM_WARN(CAM_ICP, "FW timeout in abort ctx: %u retry_left: %d",
 		ctx_data->ctx_id, retry_cnt);
 	while (retry_cnt > 0) {
-		rem_jiffies = wait_for_completion_timeout(
+		rem_jiffies = cam_common_wait_for_completion_timeout(
 			&ctx_data->wait_complete,
 			msecs_to_jiffies((timeout)));
 		if (!rem_jiffies) {
@@ -3624,7 +3625,8 @@ static int cam_icp_mgr_abort_handle(
 	}
 	CAM_DBG(CAM_ICP, "fw_handle = %x ctx_data = %pK",
 		ctx_data->fw_handle, ctx_data);
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
 			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = cam_icp_retry_wait_for_abort(ctx_data);
@@ -3682,7 +3684,8 @@ static int cam_icp_mgr_destroy_handle(
 	}
 	CAM_DBG(CAM_ICP, "fw_handle = %x ctx_data = %pK",
 		ctx_data->fw_handle, ctx_data);
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
 			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;
@@ -3952,8 +3955,9 @@ static int cam_icp_mgr_send_fw_init(struct cam_icp_hw_mgr *hw_mgr)
 	if (rc)
 		return rc;
 
-	rem_jiffies = wait_for_completion_timeout(&icp_hw_mgr.icp_complete,
-		msecs_to_jiffies((timeout)));
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&icp_hw_mgr.icp_complete,
+			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;
 		CAM_ERR(CAM_ICP, "FW response timed out %d", rc);
@@ -4218,8 +4222,9 @@ static int cam_icp_mgr_send_config_io(struct cam_icp_hw_ctx_data *ctx_data,
 		return rc;
 	}
 
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
-		msecs_to_jiffies((timeout)));
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
+			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		/* send specific error for io config failure */
 		rc = -EREMOTEIO;
@@ -4675,8 +4680,9 @@ static int cam_icp_process_stream_settings(
 	CAM_DBG(CAM_ICP, "Sent FW %s cmd",
 		map_unmap ? "Map" : "Unmap");
 
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
-		msecs_to_jiffies((timeout)));
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
+			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;
 		CAM_ERR(CAM_ICP, "FW response timed out %d", rc);
@@ -5392,8 +5398,9 @@ static int cam_icp_mgr_enqueue_abort(
 	cam_req_mgr_workq_enqueue_task(task, &icp_hw_mgr,
 		CRM_TASK_PRIORITY_0);
 
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
-		msecs_to_jiffies((timeout)));
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
+			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = cam_icp_retry_wait_for_abort(ctx_data);
 		if (rc) {
@@ -5673,7 +5680,8 @@ static int cam_icp_mgr_create_handle(uint32_t dev_type,
 	if (rc)
 		return rc;
 
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
 			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;
@@ -5720,7 +5728,8 @@ static int cam_icp_mgr_send_ping(struct cam_icp_hw_ctx_data *ctx_data)
 	if (rc)
 		return rc;
 
-	rem_jiffies = wait_for_completion_timeout(&ctx_data->wait_complete,
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&ctx_data->wait_complete,
 			msecs_to_jiffies((timeout)));
 	if (!rem_jiffies) {
 		rc = -ETIMEDOUT;

+ 5 - 3
drivers/cam_icp/icp_hw/lx7_hw/lx7_core.c

@@ -19,6 +19,7 @@
 #include "lx7_core.h"
 #include "lx7_reg.h"
 #include "lx7_soc.h"
+#include "cam_common_util.h"
 
 #define TZ_STATE_SUSPEND 0
 #define TZ_STATE_RESUME  1
@@ -344,9 +345,10 @@ static int __cam_lx7_power_collapse(struct cam_hw_info *lx7_info)
 	 * and Host can then proceed. No interrupt is expected
 	 * from FW at this time.
 	 */
-	if (readl_poll_timeout(base + ICP_LX7_SYS_STATUS,
-				status, status & ICP_LX7_STANDBYWFI,
-				PC_POLL_DELAY_US, PC_POLL_TIMEOUT_US)) {
+	if (cam_common_read_poll_timeout(base + ICP_LX7_SYS_STATUS,
+		PC_POLL_DELAY_US, PC_POLL_TIMEOUT_US,
+		ICP_LX7_STANDBYWFI, ICP_LX7_STANDBYWFI,
+		&status)) {
 		CAM_ERR(CAM_ICP, "WFI poll timed out: status=0x%08x", status);
 		return -ETIMEDOUT;
 	}

+ 3 - 3
drivers/cam_isp/isp_hw_mgr/cam_ife_hw_mgr.c

@@ -5543,7 +5543,7 @@ static int cam_ife_mgr_config_hw(void *hw_mgr_priv,
 
 		if (cfg->init_packet || hw_update_data->mup_en ||
 			(ctx->ctx_config & CAM_IFE_CTX_CFG_SW_SYNC_ON)) {
-			rem_jiffies = wait_for_completion_timeout(
+			rem_jiffies = cam_common_wait_for_completion_timeout(
 				&ctx->config_done_complete,
 				msecs_to_jiffies(60));
 			if (rem_jiffies == 0) {
@@ -5804,7 +5804,7 @@ static int cam_ife_mgr_stop_hw(void *hw_mgr_priv, void *stop_hw_args)
 		sizeof(struct cam_sfe_scratch_buf_cfg));
 	cam_ife_mgr_pause_hw(ctx);
 
-	rem_jiffies = wait_for_completion_timeout(
+	rem_jiffies = cam_common_wait_for_completion_timeout(
 		&ctx->config_done_complete,
 		msecs_to_jiffies(10));
 	if (rem_jiffies == 0)
@@ -9764,7 +9764,7 @@ static int cam_ife_mgr_cmd(void *hw_mgr_priv, void *cmd_args)
 		if (ctx->last_dump_flush_req_id == ctx->applied_req_id)
 			return 0;
 
-		rem_jiffies = wait_for_completion_timeout(
+		rem_jiffies = cam_common_wait_for_completion_timeout(
 			&ctx->config_done_complete, msecs_to_jiffies(30));
 		if (rem_jiffies == 0)
 			CAM_ERR(CAM_ISP,

+ 3 - 3
drivers/cam_isp/isp_hw_mgr/cam_tfe_hw_mgr.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/slab.h>
@@ -2613,7 +2613,7 @@ static int cam_tfe_mgr_config_hw(void *hw_mgr_priv,
 		goto end;
 
 	for (i = 0; i < CAM_TFE_HW_CONFIG_WAIT_MAX_TRY; i++) {
-		rc = wait_for_completion_timeout(
+		rc = cam_common_wait_for_completion_timeout(
 			&ctx->config_done_complete,
 			msecs_to_jiffies(
 			CAM_TFE_HW_CONFIG_TIMEOUT));
@@ -2873,7 +2873,7 @@ static int cam_tfe_mgr_stop_hw(void *hw_mgr_priv, void *stop_hw_args)
 
 	cam_tfe_mgr_pause_hw(ctx);
 
-	wait_for_completion_timeout(&ctx->config_done_complete,
+	cam_common_wait_for_completion_timeout(&ctx->config_done_complete,
 		msecs_to_jiffies(5));
 
 	if (ctx->is_tpg)

+ 13 - 8
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver1.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2020-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/iopoll.h>
@@ -20,6 +20,7 @@
 #include "cam_cpas_api.h"
 #include "cam_isp_hw_mgr_intf.h"
 #include "cam_tasklet_util.h"
+#include "cam_common_util.h"
 
 #define IFE_CSID_TIMEOUT                               1000
 
@@ -440,7 +441,7 @@ static int cam_ife_csid_ver1_hw_reset(
 	spin_unlock_irqrestore(&csid_hw->hw_info->hw_lock, flags);
 	CAM_DBG(CAM_ISP, "CSID reset start");
 
-	rem_jiffies = wait_for_completion_timeout(
+	rem_jiffies = cam_common_wait_for_completion_timeout(
 			&csid_hw->irq_complete[CAM_IFE_CSID_IRQ_REG_TOP],
 			msecs_to_jiffies(CAM_IFE_CSID_RESET_TIMEOUT_MS));
 
@@ -516,7 +517,7 @@ static int cam_ife_csid_ver1_sw_reset(
 	CAM_DBG(CAM_ISP, "CSID[%d] top reset start",
 		csid_hw->hw_intf->hw_idx);
 
-	rem_jiffies = wait_for_completion_timeout(
+	rem_jiffies = cam_common_wait_for_completion_timeout(
 			&csid_hw->irq_complete[CAM_IFE_CSID_IRQ_REG_TOP],
 			msecs_to_jiffies(CAM_IFE_CSID_RESET_TIMEOUT_MS));
 
@@ -651,7 +652,7 @@ static int cam_ife_csid_path_reset(
 	irq_reg = cam_ife_csid_convert_res_to_irq_reg(res->res_id);
 	reinit_completion(&csid_hw->irq_complete[irq_reg]);
 
-	rem_jiffies = wait_for_completion_timeout(
+	rem_jiffies = cam_common_wait_for_completion_timeout(
 			&csid_hw->irq_complete[irq_reg],
 			msecs_to_jiffies(IFE_CSID_TIMEOUT));
 
@@ -3060,16 +3061,20 @@ static int cam_ife_csid_poll_stop_status(
 		CAM_DBG(CAM_ISP, "start polling CSID:%d res_id:%d",
 			csid_hw->hw_intf->hw_idx, res_id);
 
-		rc = readl_poll_timeout(soc_info->reg_map[0].mem_base +
-			status_addr, val, (val & 0x1) == 0x1,
-				CAM_IFE_CSID_TIMEOUT_SLEEP_US,
-				CAM_IFE_CSID_TIMEOUT_ALL_US);
+		rc = cam_common_read_poll_timeout(
+			    soc_info->reg_map[0].mem_base +
+			    status_addr,
+			    CAM_IFE_CSID_TIMEOUT_SLEEP_US,
+			    CAM_IFE_CSID_TIMEOUT_ALL_US,
+			    0x1, 0x1, &val);
+
 		if (rc < 0) {
 			CAM_ERR(CAM_ISP, "CSID:%d res:%d halt failed rc %d",
 				csid_hw->hw_intf->hw_idx, res_id, rc);
 			rc = -ETIMEDOUT;
 			break;
 		}
+
 		CAM_DBG(CAM_ISP, "End polling CSID:%d res_id:%d",
 			csid_hw->hw_intf->hw_idx, res_id);
 	}

+ 2 - 1
drivers/cam_isp/isp_hw_mgr/isp_hw/ife_csid_hw/cam_ife_csid_hw_ver2.c

@@ -22,6 +22,7 @@
 #include "cam_irq_controller.h"
 #include "cam_tasklet_util.h"
 #include "cam_cdm_util.h"
+#include "cam_common_util.h"
 
 
 /* CSIPHY TPG VC/DT values */
@@ -1175,7 +1176,7 @@ static int cam_ife_csid_ver2_wait_for_reset(
 	unsigned long rem_jiffies = 0;
 	int rc = 0;
 
-	rem_jiffies = wait_for_completion_timeout(
+	rem_jiffies = cam_common_wait_for_completion_timeout(
 		&csid_hw->irq_complete[CAM_IFE_CSID_IRQ_REG_TOP],
 		msecs_to_jiffies(CAM_IFE_CSID_RESET_TIMEOUT_MS));
 

+ 5 - 3
drivers/cam_isp/isp_hw_mgr/isp_hw/ppi_hw/cam_csid_ppi_core.c

@@ -12,6 +12,7 @@
 #include "cam_soc_util.h"
 #include "cam_debug_util.h"
 #include "cam_io_util.h"
+#include "cam_common_util.h"
 
 static int cam_csid_ppi_reset(struct cam_csid_ppi_hw *ppi_hw)
 {
@@ -34,9 +35,10 @@ static int cam_csid_ppi_reset(struct cam_csid_ppi_hw *ppi_hw)
 	cam_io_w_mb(PPI_IRQ_CMD_SET, soc_info->reg_map[0].mem_base +
 		ppi_reg->ppi_irq_cmd_addr);
 
-	rc = readl_poll_timeout(soc_info->reg_map[0].mem_base +
-		ppi_reg->ppi_irq_status_addr, status,
-		(status & 0x1) == 0x1, 1000, 500000);
+	rc = cam_common_read_poll_timeout(soc_info->reg_map[0].mem_base +
+		ppi_reg->ppi_irq_status_addr,
+		1000, 500000, 0x1, 0x1, &status);
+
 	CAM_DBG(CAM_ISP, "PPI:%d reset status %d", ppi_hw->hw_intf->hw_idx,
 		status);
 	if (rc < 0) {

+ 22 - 14
drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_csid_hw/cam_tfe_csid_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/iopoll.h>
@@ -19,6 +19,7 @@
 #include "cam_isp_hw_mgr_intf.h"
 #include "cam_subdev.h"
 #include "cam_tasklet_util.h"
+#include "cam_common_util.h"
 
 /* Timeout value in msec */
 #define TFE_CSID_TIMEOUT                               1000
@@ -309,10 +310,11 @@ static int cam_tfe_csid_global_reset(struct cam_tfe_csid_hw *csid_hw)
 		soc_info->reg_map[0].mem_base +
 		csid_reg->cmn_reg->csid_rst_strobes_addr);
 
-	rc = readl_poll_timeout(soc_info->reg_map[0].mem_base +
+	rc = cam_common_read_poll_timeout(soc_info->reg_map[0].mem_base +
 		csid_reg->cmn_reg->csid_top_irq_status_addr,
-			status, (status & 0x1) == 0x1,
-		CAM_TFE_CSID_TIMEOUT_SLEEP_US, CAM_TFE_CSID_TIMEOUT_ALL_US);
+		CAM_TFE_CSID_TIMEOUT_SLEEP_US, CAM_TFE_CSID_TIMEOUT_ALL_US,
+		0x1, 0x1, &status);
+
 	if (rc < 0) {
 		CAM_ERR(CAM_ISP, "CSID:%d csid_reset fail rc = %d",
 			  csid_hw->hw_intf->hw_idx, rc);
@@ -329,8 +331,9 @@ static int cam_tfe_csid_global_reset(struct cam_tfe_csid_hw *csid_hw)
 		soc_info->reg_map[0].mem_base +
 		csid_reg->cmn_reg->csid_rst_strobes_addr);
 
-	rc = wait_for_completion_timeout(&csid_hw->csid_top_complete,
-		msecs_to_jiffies(TFE_CSID_TIMEOUT));
+	rc = cam_common_wait_for_completion_timeout(
+			&csid_hw->csid_top_complete,
+			msecs_to_jiffies(TFE_CSID_TIMEOUT));
 	if (rc <= 0) {
 		CAM_ERR(CAM_ISP, "CSID:%d soft reg reset fail rc = %d",
 			 csid_hw->hw_intf->hw_idx, rc);
@@ -429,7 +432,7 @@ static int cam_tfe_csid_path_reset(struct cam_tfe_csid_hw *csid_hw,
 	cam_io_w_mb(reset_strb_val, soc_info->reg_map[0].mem_base +
 				reset_strb_addr);
 
-	rc = wait_for_completion_timeout(complete,
+	rc = cam_common_wait_for_completion_timeout(complete,
 		msecs_to_jiffies(TFE_CSID_TIMEOUT));
 	if (rc <= 0) {
 		CAM_ERR(CAM_ISP, "CSID:%d Res id %d fail rc = %d",
@@ -1651,10 +1654,13 @@ static int cam_tfe_csid_poll_stop_status(
 		CAM_DBG(CAM_ISP, "start polling CSID:%d res_id:%d",
 			csid_hw->hw_intf->hw_idx, res_id);
 
-		rc = readl_poll_timeout(soc_info->reg_map[0].mem_base +
-			csid_status_addr, val, (val & 0x1) == 0x1,
-				CAM_TFE_CSID_TIMEOUT_SLEEP_US,
-				CAM_TFE_CSID_TIMEOUT_ALL_US);
+		rc = cam_common_read_poll_timeout(
+			    soc_info->reg_map[0].mem_base +
+			    csid_status_addr,
+			    CAM_TFE_CSID_TIMEOUT_SLEEP_US,
+			    CAM_TFE_CSID_TIMEOUT_ALL_US,
+			    0x1, 0x1, &val);
+
 		if (rc < 0) {
 			CAM_ERR(CAM_ISP, "CSID:%d res:%d halt failed rc %d",
 				csid_hw->hw_intf->hw_idx, res_id, rc);
@@ -1992,10 +1998,12 @@ static int cam_tfe_csid_reset_retain_sw_reg(
 	cam_io_w_mb(csid_reg->cmn_reg->csid_rst_stb,
 		soc_info->reg_map[0].mem_base +
 		csid_reg->cmn_reg->csid_rst_strobes_addr);
-	rc = readl_poll_timeout(soc_info->reg_map[0].mem_base +
+
+	rc = cam_common_read_poll_timeout(soc_info->reg_map[0].mem_base +
 		csid_reg->cmn_reg->csid_top_irq_status_addr,
-			status, (status & 0x1) == 0x1,
-		CAM_TFE_CSID_TIMEOUT_SLEEP_US, CAM_TFE_CSID_TIMEOUT_ALL_US);
+		CAM_TFE_CSID_TIMEOUT_SLEEP_US, CAM_TFE_CSID_TIMEOUT_ALL_US,
+		0x1, 0x1, &status);
+
 	if (rc < 0) {
 		CAM_ERR(CAM_ISP, "CSID:%d csid_reset fail rc = %d",
 			  csid_hw->hw_intf->hw_idx, rc);

+ 4 - 2
drivers/cam_isp/isp_hw_mgr/isp_hw/tfe_hw/cam_tfe_core.c

@@ -19,6 +19,7 @@
 #include "cam_debug_util.h"
 #include "cam_cpas_api.h"
 #include "cam_compat.h"
+#include "cam_common_util.h"
 
 static const char drv_name[] = "tfe";
 
@@ -2517,8 +2518,9 @@ int cam_tfe_reset(void *hw_priv, void *reset_core_args, uint32_t arg_size)
 	CAM_DBG(CAM_ISP, "TFE:%d waiting for tfe reset complete",
 		core_info->core_index);
 	/* Wait for Completion or Timeout of 100ms */
-	rc = wait_for_completion_timeout(&core_info->reset_complete,
-		msecs_to_jiffies(100));
+	rc = cam_common_wait_for_completion_timeout(
+			&core_info->reset_complete,
+			msecs_to_jiffies(100));
 	if (rc <= 0) {
 		CAM_ERR(CAM_ISP, "TFE:%d Error Reset Timeout",
 			core_info->core_index);

+ 3 - 1
drivers/cam_isp/isp_hw_mgr/isp_hw/vfe_hw/cam_vfe_core.c

@@ -17,6 +17,7 @@
 #include "cam_ife_hw_mgr.h"
 #include "cam_debug_util.h"
 #include "cam_cpas_api.h"
+#include "cam_common_util.h"
 
 static const char drv_name[] = "vfe";
 
@@ -268,7 +269,8 @@ int cam_vfe_reset(void *hw_priv, void *reset_core_args, uint32_t arg_size)
 		reset_core_args, arg_size);
 
 	/* Wait for Completion or Timeout of 500ms */
-	rc = wait_for_completion_timeout(&vfe_hw->hw_complete, 500);
+	rc = cam_common_wait_for_completion_timeout(
+			&vfe_hw->hw_complete, 500);
 
 	if (!rc)
 		CAM_ERR(CAM_ISP, "Reset Timeout");

+ 8 - 5
drivers/cam_jpeg/jpeg_hw/jpeg_dma_hw/jpeg_dma_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/of.h>
@@ -22,6 +22,7 @@
 #include "cam_jpeg_hw_mgr_intf.h"
 #include "cam_cpas_api.h"
 #include "cam_debug_util.h"
+#include "cam_common_util.h"
 
 #define CAM_JPEG_HW_IRQ_IS_FRAME_DONE(jpeg_irq_status, hi) \
 	((jpeg_irq_status) & (hi)->int_status.framedone)
@@ -280,8 +281,9 @@ int cam_jpeg_dma_reset_hw(void *data,
 	cam_io_w_mb(hw_info->reg_val.reset_cmd,
 		mem_base + hw_info->reg_offset.reset_cmd);
 
-	rem_jiffies = wait_for_completion_timeout(&jpeg_dma_dev->hw_complete,
-		CAM_JPEG_DMA_RESET_TIMEOUT);
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&jpeg_dma_dev->hw_complete,
+			CAM_JPEG_DMA_RESET_TIMEOUT);
 	if (!rem_jiffies) {
 		CAM_ERR(CAM_JPEG, "dma error Reset Timeout");
 		core_info->core_state = CAM_JPEG_DMA_CORE_NOT_READY;
@@ -361,8 +363,9 @@ int cam_jpeg_dma_stop_hw(void *data,
 	cam_io_w_mb(hw_info->reg_val.hw_cmd_stop,
 		mem_base + hw_info->reg_offset.hw_cmd);
 
-	rem_jiffies = wait_for_completion_timeout(&jpeg_dma_dev->hw_complete,
-		CAM_JPEG_DMA_RESET_TIMEOUT);
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&jpeg_dma_dev->hw_complete,
+			CAM_JPEG_DMA_RESET_TIMEOUT);
 	if (!rem_jiffies) {
 		CAM_ERR(CAM_JPEG, "error Reset Timeout");
 		core_info->core_state = CAM_JPEG_DMA_CORE_NOT_READY;

+ 8 - 5
drivers/cam_jpeg/jpeg_hw/jpeg_enc_hw/jpeg_enc_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/of.h>
@@ -22,6 +22,7 @@
 #include "cam_jpeg_hw_mgr_intf.h"
 #include "cam_cpas_api.h"
 #include "cam_debug_util.h"
+#include "cam_common_util.h"
 
 #define CAM_JPEG_HW_IRQ_IS_FRAME_DONE(jpeg_irq_status, hi) \
 	((jpeg_irq_status) & (hi)->int_status.framedone)
@@ -313,8 +314,9 @@ int cam_jpeg_enc_reset_hw(void *data,
 	cam_io_w_mb(hw_info->reg_val.reset_cmd,
 		mem_base + hw_info->reg_offset.reset_cmd);
 
-	rem_jiffies = wait_for_completion_timeout(&jpeg_enc_dev->hw_complete,
-		CAM_JPEG_ENC_RESET_TIMEOUT);
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&jpeg_enc_dev->hw_complete,
+			CAM_JPEG_ENC_RESET_TIMEOUT);
 	if (!rem_jiffies) {
 		CAM_ERR(CAM_JPEG, "error Reset Timeout");
 		core_info->core_state = CAM_JPEG_ENC_CORE_NOT_READY;
@@ -408,8 +410,9 @@ int cam_jpeg_enc_stop_hw(void *data,
 	cam_io_w_mb(hw_info->reg_val.hw_cmd_stop,
 		mem_base + hw_info->reg_offset.hw_cmd);
 
-	rem_jiffies = wait_for_completion_timeout(&jpeg_enc_dev->hw_complete,
-		CAM_JPEG_ENC_RESET_TIMEOUT);
+	rem_jiffies = cam_common_wait_for_completion_timeout(
+			&jpeg_enc_dev->hw_complete,
+			CAM_JPEG_ENC_RESET_TIMEOUT);
 	if (!rem_jiffies) {
 		CAM_ERR(CAM_JPEG, "error Reset Timeout");
 		core_info->core_state = CAM_JPEG_ENC_CORE_NOT_READY;

+ 3 - 3
drivers/cam_lrme/lrme_hw_mgr/lrme_hw/cam_lrme_hw_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/timer.h>
@@ -461,7 +461,7 @@ static int cam_lrme_hw_util_reset(struct cam_hw_info *lrme_hw,
 		reinit_completion(&lrme_core->reset_complete);
 		cam_io_w_mb(0x1, soc_info->reg_map[0].mem_base +
 			hw_info->titan_reg.top_rst_cmd);
-		time_left = wait_for_completion_timeout(
+		time_left = cam_common_wait_for_completion_timeout(
 			&lrme_core->reset_complete,
 			msecs_to_jiffies(CAM_LRME_HW_RESET_TIMEOUT));
 		if (time_left <= 0) {
@@ -479,7 +479,7 @@ static int cam_lrme_hw_util_reset(struct cam_hw_info *lrme_hw,
 		reinit_completion(&lrme_core->reset_complete);
 		cam_io_w_mb(0x2, soc_info->reg_map[0].mem_base +
 			hw_info->titan_reg.top_rst_cmd);
-		time_left = wait_for_completion_timeout(
+		time_left = cam_common_wait_for_completion_timeout(
 			&lrme_core->reset_complete,
 			msecs_to_jiffies(CAM_LRME_HW_RESET_TIMEOUT));
 		if (time_left <= 0) {

+ 3 - 2
drivers/cam_ope/ope_hw_mgr/ope_hw/bus_rd/ope_bus_rd.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/of.h>
@@ -26,6 +26,7 @@
 #include "ope_hw.h"
 #include "ope_dev_intf.h"
 #include "ope_bus_rd.h"
+#include "cam_common_util.h"
 
 static struct ope_bus_rd *bus_rd;
 
@@ -692,7 +693,7 @@ static int cam_ope_bus_rd_init(struct ope_hw *ope_hw_info,
 	cam_io_w_mb(bus_rd_reg_val->sw_reset,
 		ope_hw_info->bus_rd_reg->base + bus_rd_reg->sw_reset);
 
-	rc = wait_for_completion_timeout(
+	rc = cam_common_wait_for_completion_timeout(
 		&bus_rd->reset_complete, msecs_to_jiffies(30000));
 
 	if (!rc || rc < 0) {

+ 4 - 3
drivers/cam_ope/ope_hw_mgr/ope_hw/top/ope_top.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/of.h>
@@ -26,6 +26,7 @@
 #include "ope_hw.h"
 #include "ope_dev_intf.h"
 #include "ope_top.h"
+#include "cam_common_util.h"
 
 static struct ope_top ope_top_info;
 
@@ -79,7 +80,7 @@ static int cam_ope_top_reset(struct ope_hw *ope_hw_info,
 	cam_io_w_mb(top_reg_val->sw_reset_cmd,
 		ope_hw_info->top_reg->base + top_reg->reset_cmd);
 
-	rc = wait_for_completion_timeout(
+	rc = cam_common_wait_for_completion_timeout(
 			&ope_top_info.reset_complete,
 			msecs_to_jiffies(60));
 
@@ -184,7 +185,7 @@ static int cam_ope_top_init(struct ope_hw *ope_hw_info,
 	cam_io_w_mb(top_reg_val->sw_reset_cmd,
 		ope_hw_info->top_reg->base + top_reg->reset_cmd);
 
-	rc = wait_for_completion_timeout(
+	rc = cam_common_wait_for_completion_timeout(
 			&ope_top_info.reset_complete,
 			msecs_to_jiffies(60));
 

+ 3 - 2
drivers/cam_req_mgr/cam_req_mgr_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2016-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -16,6 +16,7 @@
 #include "cam_debug_util.h"
 #include "cam_req_mgr_dev.h"
 #include "cam_req_mgr_debug.h"
+#include "cam_common_util.h"
 
 static struct cam_req_mgr_core_device *g_crm_core_dev;
 static struct cam_req_mgr_core_link g_links[MAXIMUM_LINKS_PER_SESSION];
@@ -4237,7 +4238,7 @@ int cam_req_mgr_flush_requests(
 	rc = cam_req_mgr_workq_enqueue_task(task, link, CRM_TASK_PRIORITY_0);
 
 	/* Blocking call */
-	rc = wait_for_completion_timeout(
+	rc = cam_common_wait_for_completion_timeout(
 		&link->workq_comp,
 		msecs_to_jiffies(CAM_REQ_MGR_SCHED_REQ_TIMEOUT));
 end:

+ 8 - 8
drivers/cam_sensor_module/cam_cci/cam_cci_core.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/module.h>
@@ -46,7 +46,7 @@ static void cam_cci_flush_queue(struct cci_device *cci_dev,
 	if (!cci_dev->cci_master_info[master].status)
 		reinit_completion(&cci_dev->cci_master_info[master]
 			.reset_complete);
-	if (!wait_for_completion_timeout(
+	if (!cam_common_wait_for_completion_timeout(
 		&cci_dev->cci_master_info[master].reset_complete,
 		CCI_TIMEOUT)) {
 		CAM_DBG(CAM_CCI,
@@ -66,7 +66,7 @@ static void cam_cci_flush_queue(struct cci_device *cci_dev,
 				base + CCI_RESET_CMD_ADDR);
 
 		/* wait for reset done irq */
-		if (!wait_for_completion_timeout(
+		if (!cam_common_wait_for_completion_timeout(
 			&cci_dev->cci_master_info[master].reset_complete,
 			CCI_TIMEOUT)) {
 			rc = -EINVAL;
@@ -127,7 +127,7 @@ static int32_t cam_cci_validate_queue(struct cci_device *cci_dev,
 		atomic_set(&cci_dev->cci_master_info[master].q_free[queue], 1);
 		spin_unlock_irqrestore(
 			&cci_dev->cci_master_info[master].lock_q[queue], flags);
-		if (!wait_for_completion_timeout(
+		if (!cam_common_wait_for_completion_timeout(
 			&cci_dev->cci_master_info[master].report_q[queue],
 			CCI_TIMEOUT)) {
 			CAM_ERR(CAM_CCI,
@@ -270,7 +270,7 @@ static uint32_t cam_cci_wait(struct cci_device *cci_dev,
 		return -EINVAL;
 	}
 
-	if (!wait_for_completion_timeout(
+	if (!cam_common_wait_for_completion_timeout(
 		&cci_dev->cci_master_info[master].report_q[queue],
 		CCI_TIMEOUT)) {
 		cam_cci_dump_registers(cci_dev, master, queue);
@@ -1085,7 +1085,7 @@ static int32_t cam_cci_burst_read(struct v4l2_subdev *sd,
 	CAM_DBG(CAM_CCI, "waiting for threshold [exp_words %d]", exp_words);
 
 	while (total_read_words != exp_words) {
-		rem_jiffies = wait_for_completion_timeout(
+		rem_jiffies = cam_common_wait_for_completion_timeout(
 			&cci_dev->cci_master_info[master].th_complete,
 			CCI_TIMEOUT);
 		if (!rem_jiffies) {
@@ -1174,7 +1174,7 @@ static int32_t cam_cci_burst_read(struct v4l2_subdev *sd,
 		    * wait is to compensate for the complete invoked for
 		    * RD_DONE exclusively.
 		    */
-			rem_jiffies = wait_for_completion_timeout(
+			rem_jiffies = cam_common_wait_for_completion_timeout(
 			&cci_dev->cci_master_info[master].rd_done,
 			CCI_TIMEOUT);
 			if (!rem_jiffies) {
@@ -1355,7 +1355,7 @@ static int32_t cam_cci_read(struct v4l2_subdev *sd,
 	CAM_DBG(CAM_CCI, "exp_words to be read: %d",
 		((read_cfg->num_byte / 4) + 1));
 
-	if (!wait_for_completion_timeout(
+	if (!cam_common_wait_for_completion_timeout(
 		&cci_dev->cci_master_info[master].rd_done, CCI_TIMEOUT)) {
 		cam_cci_dump_registers(cci_dev, master, queue);
 

+ 2 - 1
drivers/cam_sensor_module/cam_cci/cam_cci_dev.h

@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #ifndef _CAM_CCI_DEV_H_
@@ -32,6 +32,7 @@
 #include "cam_soc_util.h"
 #include "cam_debug_util.h"
 #include "cam_req_mgr_workq.h"
+#include "cam_common_util.h"
 
 #define CCI_I2C_QUEUE_0_SIZE 128
 #define CCI_I2C_QUEUE_1_SIZE 32

+ 2 - 2
drivers/cam_sensor_module/cam_cci/cam_cci_soc.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include "cam_cci_dev.h"
@@ -49,7 +49,7 @@ static int cam_cci_init_master(struct cci_device *cci_dev,
 				CCI_M0_RESET_RMSK : CCI_M1_RESET_RMSK,
 				base + CCI_RESET_CMD_ADDR);
 		}
-		if (!wait_for_completion_timeout(
+		if (!cam_common_wait_for_completion_timeout(
 			&cci_dev->cci_master_info[master].reset_complete,
 			CCI_TIMEOUT)) {
 			CAM_ERR(CAM_CCI,

+ 2 - 2
drivers/cam_sync/cam_sync.c

@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/init.h>
@@ -432,7 +432,7 @@ int cam_sync_wait(int32_t sync_obj, uint64_t timeout_ms)
 		return -EINVAL;
 	}
 
-	timeleft = wait_for_completion_timeout(&row->signaled,
+	timeleft = cam_common_wait_for_completion_timeout(&row->signaled,
 		msecs_to_jiffies(timeout_ms));
 
 	if (!timeleft) {

+ 57 - 2
drivers/cam_utils/cam_common_util.c

@@ -1,15 +1,21 @@
 // SPDX-License-Identifier: GPL-2.0-only
 /*
- * Copyright (c) 2017-2019, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #include <linux/string.h>
 #include <linux/types.h>
 #include <linux/slab.h>
-
+#include <linux/completion.h>
+#include <linux/module.h>
+#include <linux/iopoll.h>
+#include <linux/moduleparam.h>
 #include "cam_common_util.h"
 #include "cam_debug_util.h"
 
+static uint timeout_multiplier = 1;
+module_param(timeout_multiplier, uint, 0644);
+
 int cam_common_util_get_string_index(const char **strings,
 	uint32_t num_strings, const char *matching_string, uint32_t *index)
 {
@@ -48,3 +54,52 @@ uint32_t cam_common_util_remove_duplicate_arr(int32_t *arr, uint32_t num)
 
 	return wr_idx;
 }
+
+unsigned long cam_common_wait_for_completion_timeout(
+	struct completion   *complete,
+	unsigned long        timeout_jiffies)
+{
+	unsigned long wait_jiffies;
+	unsigned long rem_jiffies;
+
+	if (!complete) {
+		CAM_ERR(CAM_UTIL, "Null complete pointer");
+		return 0;
+	}
+
+	if (timeout_multiplier < 1)
+		timeout_multiplier = 1;
+
+	wait_jiffies = timeout_jiffies * timeout_multiplier;
+	rem_jiffies = wait_for_completion_timeout(
+			complete, wait_jiffies);
+
+	return rem_jiffies;
+}
+
+int cam_common_read_poll_timeout(
+	void __iomem        *addr,
+	unsigned long        delay,
+	unsigned long        timeout,
+	uint32_t             mask,
+	uint32_t             check_val,
+	uint32_t            *status)
+{
+	unsigned long wait_time_us;
+	int rc = -EINVAL;
+
+	if (!addr || !status) {
+		CAM_ERR(CAM_UTIL, "Invalid param addr: %pK status: %pK",
+			addr, status);
+		return rc;
+	}
+
+	if (timeout_multiplier < 1)
+		timeout_multiplier = 1;
+
+	wait_time_us = timeout * timeout_multiplier;
+	rc = readl_poll_timeout(addr,
+		*status, (*status & mask) == check_val, delay, wait_time_us);
+
+	return rc;
+}

+ 38 - 1
drivers/cam_utils/cam_common_util.h

@@ -1,6 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-only */
 /*
- * Copyright (c) 2017-2020, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2017-2021, The Linux Foundation. All rights reserved.
  */
 
 #ifndef _CAM_COMMON_UTIL_H_
@@ -64,4 +64,41 @@ int cam_common_util_get_string_index(const char **strings,
 uint32_t cam_common_util_remove_duplicate_arr(int32_t *array,
 	uint32_t num);
 
+/**
+ * cam_common_wait_for_completion_timeout()
+ *
+ * @brief                  common interface to implement wait for completion
+ *                         for slow environment like presil, single debug
+ *                         timeout variable can take care
+ *
+ * @complete:              Pointer to the first integer of array
+ * @timeout_jiffies:       Timeout value in jiffie
+ *
+ * @return:                Remaining jiffies, non-zero for success, zero
+ *                         in case of failure
+ */
+unsigned long cam_common_wait_for_completion_timeout(
+	struct completion   *complete,
+	unsigned long        timeout_jiffies);
+/**
+ * cam_common_read_poll_timeout()
+ *
+ * @brief                  common interface to read poll timeout
+ *
+ * @addr:                  Address of IO register
+ * @delay:                 Delay interval of poll
+ * @timeout:               Timeout for poll
+ * @mask:                  Mask to be checked
+ * @check_val:             Value to be compared to break poll
+ * @status:                Status of register of IO
+ *
+ * @return:                0 if success and negative if fail
+ * */
+int cam_common_read_poll_timeout(
+	void __iomem        *addr,
+	unsigned long        delay,
+	unsigned long        timeout,
+	uint32_t             mask,
+	uint32_t             check_val,
+	uint32_t            *status);
 #endif /* _CAM_COMMON_UTIL_H_ */