msm: camera: Enhance shared gpio support

Add shared pinctrl post init to suspend unused pinctrl,
and change actuator and ois module use cam_sensor_utils
interface instead of cam_utils interface.

Change-Id: I76746aee476886bf678b297a1c33ed0a23472499
Signed-off-by: Depeng Shao <depengs@codeaurora.org>
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.c
index d9ad87d..abfc190 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.c
@@ -17,36 +17,42 @@
 #include "cam_trace.h"
 #include "cam_res_mgr_api.h"
 
-static int32_t cam_actuator_vreg_control(
-	struct cam_actuator_ctrl_t *a_ctrl,
-	int config)
+int32_t cam_actuator_construct_default_power_setting(
+	struct cam_sensor_power_ctrl_t *power_info)
 {
-	int rc = 0, cnt;
-	struct cam_hw_soc_info  *soc_info;
+	int rc = 0;
 
-	soc_info = &a_ctrl->soc_info;
-	cnt = soc_info->num_rgltr;
+	power_info->power_setting_size = 1;
+	power_info->power_setting =
+		(struct cam_sensor_power_setting *)
+		kzalloc(sizeof(struct cam_sensor_power_setting),
+			GFP_KERNEL);
+	if (!power_info->power_setting)
+		return -ENOMEM;
 
-	if (!cnt)
-		return 0;
+	power_info->power_setting[0].seq_type = SENSOR_VAF;
+	power_info->power_setting[0].seq_val = CAM_VAF;
+	power_info->power_setting[0].config_val = 1;
 
-	if (cnt >= CAM_SOC_MAX_REGULATOR) {
-		CAM_ERR(CAM_ACTUATOR, "Regulators more than supported %d", cnt);
-		return -EINVAL;
+	power_info->power_down_setting_size = 1;
+	power_info->power_down_setting =
+		(struct cam_sensor_power_setting *)
+		kzalloc(sizeof(struct cam_sensor_power_setting),
+			GFP_KERNEL);
+	if (!power_info->power_down_setting) {
+		rc = -ENOMEM;
+		goto free_power_settings;
 	}
 
-	if (config) {
-		rc = cam_soc_util_request_platform_resource(soc_info,
-			NULL, NULL);
-		rc = cam_soc_util_enable_platform_resource(soc_info, false, 0,
-			false);
-	} else {
-		rc = cam_soc_util_disable_platform_resource(soc_info, false,
-			false);
-		rc = cam_soc_util_release_platform_resource(soc_info);
-	}
+	power_info->power_setting[0].seq_type = SENSOR_VAF;
+	power_info->power_setting[0].seq_val = CAM_VAF;
+	power_info->power_setting[0].config_val = 0;
 
 	return rc;
+
+free_power_settings:
+	kfree(power_info->power_setting);
+	return rc;
 }
 
 static int32_t cam_actuator_power_up(struct cam_actuator_ctrl_t *a_ctrl)
@@ -54,22 +60,41 @@
 	int rc = 0;
 	struct cam_hw_soc_info  *soc_info =
 		&a_ctrl->soc_info;
-	struct msm_camera_gpio_num_info *gpio_num_info = NULL;
+	struct cam_actuator_soc_private  *soc_private;
+	struct cam_sensor_power_ctrl_t *power_info;
 
-	rc = cam_actuator_vreg_control(a_ctrl, 1);
-	if (rc < 0) {
-		CAM_ERR(CAM_ACTUATOR, "Actuator Reg Failed %d", rc);
+	soc_private =
+		(struct cam_actuator_soc_private *)a_ctrl->soc_info.soc_private;
+	power_info = &soc_private->power_info;
+
+	/* Parse and fill vreg params for power up settings */
+	rc = msm_camera_fill_vreg_params(
+		&a_ctrl->soc_info,
+		power_info->power_setting,
+		power_info->power_setting_size);
+	if (rc) {
+		CAM_ERR(CAM_ACTUATOR,
+			"failed to fill vreg params for power up rc:%d", rc);
 		return rc;
 	}
 
-	gpio_num_info = a_ctrl->gpio_num_info;
+	/* Parse and fill vreg params for power down settings*/
+	rc = msm_camera_fill_vreg_params(
+		&a_ctrl->soc_info,
+		power_info->power_down_setting,
+		power_info->power_down_setting_size);
+	if (rc) {
+		CAM_ERR(CAM_ACTUATOR,
+			"failed to fill vreg params power down rc:%d", rc);
+		return rc;
+	}
 
-	if (soc_info->gpio_data &&
-		gpio_num_info &&
-		gpio_num_info->valid[SENSOR_VAF] == 1) {
-		cam_res_mgr_gpio_set_value(
-			gpio_num_info->gpio_num[SENSOR_VAF],
-			1);
+	power_info->dev = soc_info->dev;
+
+	rc = cam_sensor_core_power_up(power_info, soc_info);
+	if (rc) {
+		CAM_ERR(CAM_ACTUATOR, "failed in ois power up rc %d", rc);
+		return rc;
 	}
 
 	/* VREG needs some delay to power up */
@@ -85,24 +110,29 @@
 static int32_t cam_actuator_power_down(struct cam_actuator_ctrl_t *a_ctrl)
 {
 	int32_t rc = 0;
-	struct cam_hw_soc_info *soc_info =
-		&a_ctrl->soc_info;
-	struct msm_camera_gpio_num_info *gpio_num_info = NULL;
+	struct cam_sensor_power_ctrl_t *power_info;
+	struct cam_hw_soc_info *soc_info = &a_ctrl->soc_info;
+	struct cam_actuator_soc_private  *soc_private;
 
-	gpio_num_info = a_ctrl->gpio_num_info;
-
-	if (soc_info->gpio_data &&
-		gpio_num_info &&
-		gpio_num_info->valid[SENSOR_VAF] == 1) {
-
-		cam_res_mgr_gpio_set_value(
-			gpio_num_info->gpio_num[SENSOR_VAF],
-			GPIOF_OUT_INIT_LOW);
+	if (!a_ctrl) {
+		CAM_ERR(CAM_ACTUATOR, "failed: e_ctrl %pK", a_ctrl);
+		return -EINVAL;
 	}
 
-	rc = cam_actuator_vreg_control(a_ctrl, 0);
-	if (rc < 0)
-		CAM_ERR(CAM_ACTUATOR, "Disable Regulator Failed: %d", rc);
+	soc_private =
+		(struct cam_actuator_soc_private *)a_ctrl->soc_info.soc_private;
+	power_info = &soc_private->power_info;
+	soc_info = &a_ctrl->soc_info;
+
+	if (!power_info) {
+		CAM_ERR(CAM_ACTUATOR, "failed: power_info %pK", power_info);
+		return -EINVAL;
+	}
+	rc = msm_camera_power_down(power_info, soc_info);
+	if (rc) {
+		CAM_ERR(CAM_ACTUATOR, "power down the core is failed:%d", rc);
+		return rc;
+	}
 
 	camera_io_release(&a_ctrl->io_master_info);
 
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.h
index f24070e..c28d79d 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_core.h
@@ -16,6 +16,16 @@
 #include "cam_actuator_dev.h"
 
 /**
+ * @power_info: power setting info to control the power
+ *
+ * This API construct the default actuator power setting.
+ *
+ * @return Status of operation. Negative in case of error. Zero otherwise.
+ */
+int32_t cam_actuator_construct_default_power_setting(
+	struct cam_sensor_power_ctrl_t *power_info);
+
+/**
  * @apply: Req mgr structure for applying request
  *
  * This API applies the request that is mentioned
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.c
index 465f5e2..64acea7 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.c
@@ -140,9 +140,11 @@
 static int32_t cam_actuator_driver_i2c_probe(struct i2c_client *client,
 	const struct i2c_device_id *id)
 {
-	int32_t rc = 0, i = 0;
-	struct cam_actuator_ctrl_t *a_ctrl;
-	struct cam_hw_soc_info *soc_info = NULL;
+	int32_t                         rc = 0;
+	int32_t                         i = 0;
+	struct cam_actuator_ctrl_t      *a_ctrl;
+	struct cam_hw_soc_info          *soc_info = NULL;
+	struct cam_actuator_soc_private *soc_private = NULL;
 
 	if (client == NULL || id == NULL) {
 		CAM_ERR(CAM_ACTUATOR, "Invalid Args client: %pK id: %pK",
@@ -164,6 +166,14 @@
 
 	i2c_set_clientdata(client, a_ctrl);
 
+	soc_private = kzalloc(sizeof(struct cam_actuator_soc_private),
+		GFP_KERNEL);
+	if (!soc_private) {
+		rc = -ENOMEM;
+		goto free_ctrl;
+	}
+	a_ctrl->soc_info.soc_private = soc_private;
+
 	a_ctrl->io_master_info.client = client;
 	soc_info = &a_ctrl->soc_info;
 	soc_info->dev = &client->dev;
@@ -176,9 +186,20 @@
 		goto free_ctrl;
 	}
 
+	soc_private = (struct cam_actuator_soc_private *)(id->driver_data);
+	if (!soc_private) {
+		CAM_ERR(CAM_EEPROM, "board info NULL");
+		rc = -EINVAL;
+		goto free_ctrl;
+	}
+
 	rc = cam_actuator_init_subdev(a_ctrl);
 	if (rc)
-		goto free_ctrl;
+		goto free_soc;
+
+	if (soc_private->i2c_info.slave_addr != 0)
+		a_ctrl->io_master_info.client->addr =
+			soc_private->i2c_info.slave_addr;
 
 	a_ctrl->i2c_data.per_frame =
 		(struct i2c_settings_array *)
@@ -194,14 +215,6 @@
 	for (i = 0; i < MAX_PER_FRAME_ARRAY; i++)
 		INIT_LIST_HEAD(&(a_ctrl->i2c_data.per_frame[i].list_head));
 
-	rc = cam_soc_util_request_platform_resource(&a_ctrl->soc_info,
-		NULL, NULL);
-	if (rc < 0) {
-		CAM_ERR(CAM_ACTUATOR,
-			"Requesting Platform Resources failed rc %d", rc);
-		goto free_mem;
-	}
-
 	a_ctrl->bridge_intf.device_hdl = -1;
 	a_ctrl->bridge_intf.ops.get_dev_info =
 		cam_actuator_publish_dev_info;
@@ -212,6 +225,14 @@
 
 	v4l2_set_subdevdata(&(a_ctrl->v4l2_dev_str.sd), a_ctrl);
 
+	rc = cam_actuator_construct_default_power_setting(
+		&soc_private->power_info);
+	if (rc < 0) {
+		CAM_ERR(CAM_ACTUATOR,
+			"Construct default actuator power setting failed.");
+		goto free_mem;
+	}
+
 	a_ctrl->cam_act_state = CAM_ACTUATOR_INIT;
 
 	return rc;
@@ -219,6 +240,8 @@
 	kfree(a_ctrl->i2c_data.per_frame);
 unreg_subdev:
 	cam_unregister_subdev(&(a_ctrl->v4l2_dev_str));
+free_soc:
+	kfree(soc_private);
 free_ctrl:
 	kfree(a_ctrl);
 	return rc;
@@ -269,8 +292,10 @@
 static int32_t cam_actuator_driver_platform_probe(
 	struct platform_device *pdev)
 {
-	int32_t rc = 0, i = 0;
-	struct cam_actuator_ctrl_t *a_ctrl = NULL;
+	int32_t                         rc = 0;
+	int32_t                         i = 0;
+	struct cam_actuator_ctrl_t      *a_ctrl = NULL;
+	struct cam_actuator_soc_private *soc_private = NULL;
 
 	/* Create sensor control structure */
 	a_ctrl = devm_kzalloc(&pdev->dev,
@@ -287,15 +312,28 @@
 
 	a_ctrl->io_master_info.cci_client = kzalloc(sizeof(
 		struct cam_sensor_cci_client), GFP_KERNEL);
-	if (!(a_ctrl->io_master_info.cci_client))
-		return -ENOMEM;
+	if (!(a_ctrl->io_master_info.cci_client)) {
+		rc = -ENOMEM;
+		goto free_ctrl;
+	}
+
+	soc_private = kzalloc(sizeof(struct cam_actuator_soc_private),
+		GFP_KERNEL);
+	if (!soc_private) {
+		rc = -ENOMEM;
+		goto free_cci_client;
+	}
+	a_ctrl->soc_info.soc_private = soc_private;
+	soc_private->power_info.dev = &pdev->dev;
 
 	a_ctrl->i2c_data.per_frame =
 		(struct i2c_settings_array *)
 		kzalloc(sizeof(struct i2c_settings_array) *
 		MAX_PER_FRAME_ARRAY, GFP_KERNEL);
-	if (a_ctrl->i2c_data.per_frame == NULL)
-		return -ENOMEM;
+	if (a_ctrl->i2c_data.per_frame == NULL) {
+		rc = -ENOMEM;
+		goto free_soc;
+	}
 
 	INIT_LIST_HEAD(&(a_ctrl->i2c_data.init_settings.list_head));
 
@@ -305,7 +343,7 @@
 	rc = cam_actuator_parse_dt(a_ctrl, &(pdev->dev));
 	if (rc < 0) {
 		CAM_ERR(CAM_ACTUATOR, "Paring actuator dt failed rc %d", rc);
-		goto free_ctrl;
+		goto free_mem;
 	}
 
 	/* Fill platform device id*/
@@ -315,14 +353,6 @@
 	if (rc)
 		goto free_mem;
 
-	rc = cam_soc_util_request_platform_resource(&a_ctrl->soc_info,
-			NULL, NULL);
-	if (rc < 0) {
-		CAM_ERR(CAM_ACTUATOR,
-			"Requesting Platform Resources failed rc %d", rc);
-		goto unreg_subdev;
-	}
-
 	a_ctrl->bridge_intf.device_hdl = -1;
 	a_ctrl->bridge_intf.ops.get_dev_info =
 		cam_actuator_publish_dev_info;
@@ -336,11 +366,23 @@
 	platform_set_drvdata(pdev, a_ctrl);
 	v4l2_set_subdevdata(&a_ctrl->v4l2_dev_str.sd, a_ctrl);
 
+	rc = cam_actuator_construct_default_power_setting(
+		&soc_private->power_info);
+	if (rc < 0) {
+		CAM_ERR(CAM_ACTUATOR,
+			"Construct default actuator power setting failed.");
+		goto unreg_subdev;
+	}
+
 	return rc;
 unreg_subdev:
 	cam_unregister_subdev(&(a_ctrl->v4l2_dev_str));
 free_mem:
 	kfree(a_ctrl->i2c_data.per_frame);
+free_soc:
+	kfree(soc_private);
+free_cci_client:
+	kfree(a_ctrl->io_master_info.cci_client);
 free_ctrl:
 	devm_kfree(&pdev->dev, a_ctrl);
 	return rc;
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.h
index 144e161..8b8b1ef 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_dev.h
@@ -53,13 +53,28 @@
 	ACT_APPLY_SETTINGS_LATER,
 };
 
-enum cam_actator_state {
+enum cam_actuator_state {
 	CAM_ACTUATOR_INIT,
 	CAM_ACTUATOR_ACQUIRE,
 	CAM_ACTUATOR_START,
 };
 
 /**
+ * struct cam_actuator_i2c_info_t - I2C info
+ * @slave_addr      :   slave address
+ * @i2c_freq_mode   :   i2c frequency mode
+ */
+struct cam_actuator_i2c_info_t {
+	uint16_t slave_addr;
+	uint8_t i2c_freq_mode;
+};
+
+struct cam_actuator_soc_private {
+	struct cam_actuator_i2c_info_t i2c_info;
+	struct cam_sensor_power_ctrl_t power_info;
+};
+
+/**
  * struct intf_params
  * @device_hdl: Device Handle
  * @session_hdl: Session Handle
@@ -101,8 +116,7 @@
 	struct mutex actuator_mutex;
 	uint32_t id;
 	enum cam_actuator_apply_state_t setting_apply_state;
-	enum cam_actator_state cam_act_state;
-	struct msm_camera_gpio_num_info *gpio_num_info;
+	enum cam_actuator_state cam_act_state;
 	uint8_t cam_pinctrl_status;
 	struct cam_subdev v4l2_dev_str;
 	struct i2c_data_settings i2c_data;
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_soc.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_soc.c
index f47ec2f..55b7c72 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_soc.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_actuator/cam_actuator_soc.c
@@ -22,9 +22,12 @@
 int32_t cam_actuator_parse_dt(struct cam_actuator_ctrl_t *a_ctrl,
 	struct device *dev)
 {
-	int32_t                   rc = 0;
-	struct cam_hw_soc_info *soc_info = &a_ctrl->soc_info;
-	struct device_node *of_node = NULL;
+	int32_t                         rc = 0;
+	struct cam_hw_soc_info          *soc_info = &a_ctrl->soc_info;
+	struct cam_actuator_soc_private *soc_private =
+		(struct cam_actuator_soc_private *)a_ctrl->soc_info.soc_private;
+	struct cam_sensor_power_ctrl_t  *power_info = &soc_private->power_info;
+	struct device_node              *of_node = NULL;
 
 	/* Initialize mutex */
 	mutex_init(&(a_ctrl->actuator_mutex));
@@ -61,9 +64,8 @@
 	}
 
 	rc = cam_sensor_util_init_gpio_pin_tbl(soc_info,
-		&a_ctrl->gpio_num_info);
-
-	if ((rc < 0) || (!a_ctrl->gpio_num_info)) {
+		&power_info->gpio_num_info);
+	if ((rc < 0) || (!power_info->gpio_num_info)) {
 		CAM_ERR(CAM_ACTUATOR, "No/Error Actuator GPIOs");
 		return -EINVAL;
 	}
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.c
index 9053265..d825f5e 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.c
@@ -19,6 +19,45 @@
 #include "cam_debug_util.h"
 #include "cam_res_mgr_api.h"
 
+int32_t cam_ois_construct_default_power_setting(
+	struct cam_sensor_power_ctrl_t *power_info)
+{
+	int rc = 0;
+
+	power_info->power_setting_size = 1;
+	power_info->power_setting =
+		(struct cam_sensor_power_setting *)
+		kzalloc(sizeof(struct cam_sensor_power_setting),
+			GFP_KERNEL);
+	if (!power_info->power_setting)
+		return -ENOMEM;
+
+	power_info->power_setting[0].seq_type = SENSOR_VAF;
+	power_info->power_setting[0].seq_val = CAM_VAF;
+	power_info->power_setting[0].config_val = 1;
+
+	power_info->power_down_setting_size = 1;
+	power_info->power_down_setting =
+		(struct cam_sensor_power_setting *)
+		kzalloc(sizeof(struct cam_sensor_power_setting),
+			GFP_KERNEL);
+	if (!power_info->power_down_setting) {
+		rc = -ENOMEM;
+		goto free_power_settings;
+	}
+
+	power_info->power_setting[0].seq_type = SENSOR_VAF;
+	power_info->power_setting[0].seq_val = CAM_VAF;
+	power_info->power_setting[0].config_val = 0;
+
+	return rc;
+
+free_power_settings:
+	kfree(power_info->power_setting);
+	return rc;
+}
+
+
 /**
  * cam_ois_get_dev_handle - get device handle
  * @o_ctrl:     ctrl structure
@@ -61,58 +100,46 @@
 	return 0;
 }
 
-static int cam_ois_vreg_control(struct cam_ois_ctrl_t *o_ctrl,
-	int config)
-{
-	int rc = 0, cnt;
-	struct cam_hw_soc_info  *soc_info;
-
-	soc_info = &o_ctrl->soc_info;
-	cnt = soc_info->num_rgltr;
-
-	if (!cnt)
-		return 0;
-
-	if (cnt >= CAM_SOC_MAX_REGULATOR) {
-		CAM_ERR(CAM_OIS, "Regulators more than supported %d", cnt);
-		return -EINVAL;
-	}
-
-	if (config) {
-		rc = cam_soc_util_request_platform_resource(soc_info,
-			NULL, NULL);
-		rc = cam_soc_util_enable_platform_resource(soc_info, false, 0,
-			false);
-	} else {
-		rc = cam_soc_util_disable_platform_resource(soc_info, false,
-			false);
-		rc = cam_soc_util_release_platform_resource(soc_info);
-	}
-
-	return rc;
-}
-
 static int cam_ois_power_up(struct cam_ois_ctrl_t *o_ctrl)
 {
-	int rc = 0;
-	struct cam_hw_soc_info  *soc_info =
+	int                             rc = 0;
+	struct cam_hw_soc_info          *soc_info =
 		&o_ctrl->soc_info;
-	struct msm_camera_gpio_num_info *gpio_num_info = NULL;
+	struct cam_ois_soc_private *soc_private;
+	struct cam_sensor_power_ctrl_t  *power_info;
 
-	rc = cam_ois_vreg_control(o_ctrl, 1);
-	if (rc < 0) {
-		CAM_ERR(CAM_OIS, "OIS Reg Failed %d", rc);
+	soc_private =
+		(struct cam_ois_soc_private *)o_ctrl->soc_info.soc_private;
+	power_info = &soc_private->power_info;
+
+	/* Parse and fill vreg params for power up settings */
+	rc = msm_camera_fill_vreg_params(
+		&o_ctrl->soc_info,
+		power_info->power_setting,
+		power_info->power_setting_size);
+	if (rc) {
+		CAM_ERR(CAM_OIS,
+			"failed to fill vreg params for power up rc:%d", rc);
 		return rc;
 	}
 
-	gpio_num_info = o_ctrl->gpio_num_info;
+	/* Parse and fill vreg params for power down settings*/
+	rc = msm_camera_fill_vreg_params(
+		&o_ctrl->soc_info,
+		power_info->power_down_setting,
+		power_info->power_down_setting_size);
+	if (rc) {
+		CAM_ERR(CAM_OIS,
+			"failed to fill vreg params power down rc:%d", rc);
+		return rc;
+	}
 
-	if (soc_info->gpio_data &&
-		gpio_num_info &&
-		gpio_num_info->valid[SENSOR_VAF] == 1) {
-		cam_res_mgr_gpio_set_value(
-			gpio_num_info->gpio_num[SENSOR_VAF],
-			1);
+	power_info->dev = soc_info->dev;
+
+	rc = cam_sensor_core_power_up(power_info, soc_info);
+	if (rc) {
+		CAM_ERR(CAM_OIS, "failed in ois power up rc %d", rc);
+		return rc;
 	}
 
 	/* VREG needs some delay to power up */
@@ -127,25 +154,32 @@
 
 static int cam_ois_power_down(struct cam_ois_ctrl_t *o_ctrl)
 {
-	int32_t rc = 0;
-	struct cam_hw_soc_info *soc_info =
+	int32_t                         rc = 0;
+	struct cam_sensor_power_ctrl_t  *power_info;
+	struct cam_hw_soc_info          *soc_info =
 		&o_ctrl->soc_info;
-	struct msm_camera_gpio_num_info *gpio_num_info = NULL;
+	struct cam_ois_soc_private *soc_private;
 
-	gpio_num_info = o_ctrl->gpio_num_info;
-
-	if (soc_info->gpio_data &&
-		gpio_num_info &&
-		gpio_num_info->valid[SENSOR_VAF] == 1) {
-
-		cam_res_mgr_gpio_set_value(
-			gpio_num_info->gpio_num[SENSOR_VAF],
-			GPIOF_OUT_INIT_LOW);
+	if (!o_ctrl) {
+		CAM_ERR(CAM_OIS, "failed: o_ctrl %pK", o_ctrl);
+		return -EINVAL;
 	}
 
-	rc = cam_ois_vreg_control(o_ctrl, 0);
-	if (rc < 0)
-		CAM_ERR(CAM_OIS, "Disable regualtor Failed %d", rc);
+	soc_private =
+		(struct cam_ois_soc_private *)o_ctrl->soc_info.soc_private;
+	power_info = &soc_private->power_info;
+	soc_info = &o_ctrl->soc_info;
+
+	if (!power_info) {
+		CAM_ERR(CAM_OIS, "failed: power_info %pK", power_info);
+		return -EINVAL;
+	}
+
+	rc = msm_camera_power_down(power_info, soc_info);
+	if (rc) {
+		CAM_ERR(CAM_OIS, "power down the core is failed:%d", rc);
+		return rc;
+	}
 
 	camera_io_release(&o_ctrl->io_master_info);
 
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.h
index 6f81d09..516ac88 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_core.h
@@ -14,6 +14,17 @@
 
 #include "cam_ois_dev.h"
 
+/**
+ * @power_info: power setting info to control the power
+ *
+ * This API construct the default ois power setting.
+ *
+ * @return Status of operation. Negative in case of error. Zero otherwise.
+ */
+int32_t cam_ois_construct_default_power_setting(
+	struct cam_sensor_power_ctrl_t *power_info);
+
+
 int cam_ois_driver_cmd(struct cam_ois_ctrl_t *e_ctrl, void *arg);
 
 /**
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.c
index 2629180..97fede2 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.c
@@ -203,10 +203,21 @@
 	rc = cam_ois_init_subdev_param(o_ctrl);
 	if (rc)
 		goto octrl_free;
+
+	rc = cam_ois_construct_default_power_setting(
+		&soc_private->power_info);
+	if (rc < 0) {
+		CAM_ERR(CAM_OIS,
+			"Construct default ois power setting failed.");
+		goto unreg_subdev;
+	}
+
 	o_ctrl->cam_ois_state = CAM_OIS_INIT;
 
 	return rc;
 
+unreg_subdev:
+	cam_unregister_subdev(&(o_ctrl->v4l2_dev_str));
 octrl_free:
 	kfree(o_ctrl);
 probe_failure:
@@ -280,6 +291,14 @@
 	}
 	o_ctrl->bridge_intf.device_hdl = -1;
 
+	rc = cam_ois_construct_default_power_setting(
+		&soc_private->power_info);
+	if (rc < 0) {
+		CAM_ERR(CAM_OIS,
+			"Construct default ois power setting failed.");
+		goto unreg_subdev;
+	}
+
 	platform_set_drvdata(pdev, o_ctrl);
 	v4l2_set_subdevdata(&o_ctrl->v4l2_dev_str.sd, o_ctrl);
 
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.h
index 96166b4..80f1e84 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_ois/cam_ois_dev.h
@@ -93,7 +93,6 @@
  * @ois_mutex       :   ois mutex
  * @soc_info        :   ois soc related info
  * @io_master_info  :   Information about the communication master
- * @gpio_num_info   :   gpio info
  * @cci_i2c_master  :   I2C structure
  * @v4l2_dev_str    :   V4L2 device structure
  * @bridge_intf     :   bridge interface params
@@ -114,7 +113,6 @@
 	struct mutex ois_mutex;
 	struct cam_hw_soc_info soc_info;
 	struct camera_io_master io_master_info;
-	struct msm_camera_gpio_num_info *gpio_num_info;
 	enum cci_i2c_master_t cci_i2c_master;
 	struct cam_subdev v4l2_dev_str;
 	struct cam_ois_intf_params bridge_intf;
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr.c
index cbe36bd..949f902 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr.c
@@ -58,8 +58,14 @@
 	bool found = false;
 	struct cam_flash_res *flash_res;
 
-	if (!cam_res)
+	if (!cam_res) {
+		/*
+		 * If this driver not probed, then just register the
+		 * led trigger.
+		 */
+		led_trigger_register_simple(name, tp);
 		return;
+	}
 
 	mutex_lock(&cam_res->flash_res_lock);
 	list_for_each_entry(flash_res, &cam_res->flash_res_list, list) {
@@ -75,7 +81,7 @@
 	} else {
 		flash_res = kzalloc(sizeof(struct cam_flash_res), GFP_KERNEL);
 		if (!flash_res) {
-			CAM_ERR(CAM_SENSOR,
+			CAM_ERR(CAM_RES,
 				"Failed to malloc memory for flash_res:%s",
 				name);
 			*tp = NULL;
@@ -99,8 +105,14 @@
 	bool found = false;
 	struct cam_flash_res *flash_res;
 
-	if (!cam_res)
+	if (!cam_res) {
+		/*
+		 * If this driver not probed, then just unregister the
+		 * led trigger.
+		 */
+		led_trigger_unregister_simple(tp);
 		return;
+	}
 
 	mutex_lock(&cam_res->flash_res_lock);
 	list_for_each_entry(flash_res, &cam_res->flash_res_list, list) {
@@ -109,26 +121,30 @@
 			break;
 		}
 	}
-	mutex_unlock(&cam_res->flash_res_lock);
 
 	if (found) {
 		led_trigger_unregister_simple(tp);
-		mutex_lock(&cam_res->flash_res_lock);
 		list_del_init(&flash_res->list);
-		mutex_unlock(&cam_res->flash_res_lock);
 		kfree(flash_res);
 	}
+	mutex_unlock(&cam_res->flash_res_lock);
 }
 EXPORT_SYMBOL(cam_res_mgr_led_trigger_unregister);
 
 void cam_res_mgr_led_trigger_event(struct led_trigger *trig,
-			enum led_brightness brightness)
+	enum led_brightness brightness)
 {
 	bool found = false;
 	struct cam_flash_res *flash_res;
 
-	if (!cam_res)
+	if (!cam_res) {
+		/*
+		 * If this driver not probed, then just trigger
+		 * the led event.
+		 */
+		led_trigger_event(trig, brightness);
 		return;
+	}
 
 	mutex_lock(&cam_res->flash_res_lock);
 	list_for_each_entry(flash_res, &cam_res->flash_res_list, list) {
@@ -144,50 +160,60 @@
 }
 EXPORT_SYMBOL(cam_res_mgr_led_trigger_event);
 
-void cam_res_mgr_shared_pinctrl_init(void)
+int cam_res_mgr_shared_pinctrl_init(void)
 {
 	struct cam_soc_pinctrl_info *pinctrl_info;
 
-	if (!cam_res || !cam_res->shared_gpio_enabled)
-		return;
+	/*
+	 * We allow the cam_res is NULL or shared_gpio_enabled
+	 * is false, it means this driver no probed or doesn't
+	 * have shared gpio in this device.
+	 */
+	if (!cam_res || !cam_res->shared_gpio_enabled) {
+		CAM_DBG(CAM_RES, "Not support shared gpio.");
+		return 0;
+	}
 
-	if (cam_res->pstatus != PINCTRL_STATUS_PUT)
-		return;
+	if (cam_res->pstatus != PINCTRL_STATUS_PUT) {
+		CAM_DBG(CAM_RES, "The shared pinctrl already been got.");
+		return 0;
+	}
 
 	pinctrl_info = &cam_res->dt.pinctrl_info;
 
 	pinctrl_info->pinctrl =
 		devm_pinctrl_get(cam_res->dev);
 	if (IS_ERR_OR_NULL(pinctrl_info->pinctrl)) {
-		CAM_ERR(CAM_SENSOR, "Pinctrl not available");
+		CAM_ERR(CAM_RES, "Pinctrl not available");
 		cam_res->shared_gpio_enabled = false;
-		return;
+		return -EINVAL;
 	}
 
 	pinctrl_info->gpio_state_active =
 		pinctrl_lookup_state(pinctrl_info->pinctrl,
 			CAM_RES_MGR_DEFAULT);
 	if (IS_ERR_OR_NULL(pinctrl_info->gpio_state_active)) {
-		CAM_ERR(CAM_SENSOR,
+		CAM_ERR(CAM_RES,
 			"Failed to get the active state pinctrl handle");
 		cam_res->shared_gpio_enabled = false;
-		return;
-
+		return -EINVAL;
 	}
 
 	pinctrl_info->gpio_state_suspend =
 		pinctrl_lookup_state(pinctrl_info->pinctrl,
 			CAM_RES_MGR_SLEEP);
 	if (IS_ERR_OR_NULL(pinctrl_info->gpio_state_suspend)) {
-		CAM_ERR(CAM_SENSOR,
+		CAM_ERR(CAM_RES,
 			"Failed to get the active state pinctrl handle");
 		cam_res->shared_gpio_enabled = false;
-		return;
+		return -EINVAL;
 	}
 
 	mutex_lock(&cam_res->gpio_res_lock);
 	cam_res->pstatus = PINCTRL_STATUS_GOT;
 	mutex_unlock(&cam_res->gpio_res_lock);
+
+	return 0;
 }
 EXPORT_SYMBOL(cam_res_mgr_shared_pinctrl_init);
 
@@ -224,13 +250,19 @@
 {
 	struct cam_soc_pinctrl_info *pinctrl_info;
 
-	if (!cam_res || !cam_res->shared_gpio_enabled)
+	if (!cam_res || !cam_res->shared_gpio_enabled) {
+		CAM_DBG(CAM_RES, "Not support shared gpio.");
 		return;
+	}
 
 	mutex_lock(&cam_res->gpio_res_lock);
-	if (cam_res->pstatus == PINCTRL_STATUS_PUT ||
-		cam_res_mgr_shared_pinctrl_check_hold()) {
-		mutex_unlock(&cam_res->gpio_res_lock);
+	if (cam_res->pstatus == PINCTRL_STATUS_PUT) {
+		CAM_DBG(CAM_RES, "The shared pinctrl already been put");
+		return;
+	}
+
+	if (cam_res_mgr_shared_pinctrl_check_hold()) {
+		CAM_INFO(CAM_RES, "Need hold put this pinctrl");
 		return;
 	}
 
@@ -243,37 +275,78 @@
 }
 EXPORT_SYMBOL(cam_res_mgr_shared_pinctrl_put);
 
-void cam_res_mgr_shared_pinctrl_select_state(bool active)
+int cam_res_mgr_shared_pinctrl_select_state(bool active)
 {
+	int rc = 0;
 	struct cam_soc_pinctrl_info *pinctrl_info;
 
-	if (!cam_res || !cam_res->shared_gpio_enabled)
-		return;
+	if (!cam_res || !cam_res->shared_gpio_enabled) {
+		CAM_DBG(CAM_RES, "Not support shared gpio.");
+		return 0;
+	}
 
 	mutex_lock(&cam_res->gpio_res_lock);
 	if (cam_res->pstatus == PINCTRL_STATUS_PUT) {
+		CAM_DBG(CAM_RES, "The shared pinctrl alerady been put.!");
 		mutex_unlock(&cam_res->gpio_res_lock);
-		return;
+		return 0;
 	}
 
 	pinctrl_info = &cam_res->dt.pinctrl_info;
 
 	if (active && (cam_res->pstatus != PINCTRL_STATUS_ACTIVE)) {
-		pinctrl_select_state(pinctrl_info->pinctrl,
+		rc = pinctrl_select_state(pinctrl_info->pinctrl,
 			pinctrl_info->gpio_state_active);
 		cam_res->pstatus = PINCTRL_STATUS_ACTIVE;
 	} else if (!active &&
 		!cam_res_mgr_shared_pinctrl_check_hold()) {
-		pinctrl_select_state(pinctrl_info->pinctrl,
+		rc = pinctrl_select_state(pinctrl_info->pinctrl,
 			pinctrl_info->gpio_state_suspend);
 		cam_res->pstatus = PINCTRL_STATUS_SUSPEND;
 	}
 	mutex_unlock(&cam_res->gpio_res_lock);
+
+	return rc;
 }
 EXPORT_SYMBOL(cam_res_mgr_shared_pinctrl_select_state);
 
+int cam_res_mgr_shared_pinctrl_post_init(void)
+{
+	int ret = 0;
+	struct cam_soc_pinctrl_info *pinctrl_info;
+
+	if (!cam_res || !cam_res->shared_gpio_enabled) {
+		CAM_DBG(CAM_RES, "Not support shared gpio.");
+		return ret;
+	}
+
+	mutex_lock(&cam_res->gpio_res_lock);
+	if (cam_res->pstatus == PINCTRL_STATUS_PUT) {
+		CAM_DBG(CAM_RES, "The shared pinctrl alerady been put.!");
+		mutex_unlock(&cam_res->gpio_res_lock);
+		return ret;
+	}
+
+	pinctrl_info = &cam_res->dt.pinctrl_info;
+
+	/*
+	 * If no gpio resource in gpio_res_list, it means
+	 * this device don't have shared gpio
+	 */
+	if (list_empty(&cam_res->gpio_res_list)) {
+		ret = pinctrl_select_state(pinctrl_info->pinctrl,
+			pinctrl_info->gpio_state_suspend);
+		devm_pinctrl_put(pinctrl_info->pinctrl);
+		cam_res->pstatus = PINCTRL_STATUS_PUT;
+	}
+	mutex_unlock(&cam_res->gpio_res_lock);
+
+	return ret;
+}
+EXPORT_SYMBOL(cam_res_mgr_shared_pinctrl_post_init);
+
 static int cam_res_mgr_add_device(struct device *dev,
-			struct cam_gpio_res *gpio_res)
+	struct cam_gpio_res *gpio_res)
 {
 	struct cam_dev_res *dev_res = NULL;
 
@@ -333,7 +406,7 @@
 	if (!found) {
 		rc = gpio_request_one(gpio, flags, label);
 		if (rc) {
-			CAM_ERR(CAM_SENSOR, "gpio %d:%s request fails",
+			CAM_ERR(CAM_RES, "gpio %d:%s request fails",
 				gpio, label);
 			return rc;
 		}
@@ -349,12 +422,8 @@
 		cam_res_mgr_gpio_is_shared(gpio)) {
 
 		gpio_res = kzalloc(sizeof(struct cam_gpio_res), GFP_KERNEL);
-		if (!gpio_res) {
-			CAM_ERR(CAM_SENSOR,
-				"Failed to alloc gpio resource for gpio %d",
-				gpio);
+		if (!gpio_res)
 			return -ENOMEM;
-		}
 
 		gpio_res->gpio = gpio;
 		gpio_res->power_on_count = 0;
@@ -516,7 +585,11 @@
 
 	if (dt->num_shared_gpio > MAX_SHARED_GPIO_SIZE ||
 		dt->num_shared_gpio <= 0) {
-		CAM_ERR(CAM_SENSOR, "Invalid GPIO number %d. No shared gpio.",
+		/*
+		 * Not really an error, it means dtsi not configure
+		 * the shared gpio.
+		 */
+		CAM_DBG(CAM_RES, "Invalid GPIO number %d. No shared gpio.",
 			dt->num_shared_gpio);
 		return -EINVAL;
 	}
@@ -524,13 +597,13 @@
 	rc = of_property_read_u32_array(of_node, "shared-gpios",
 		dt->shared_gpio, dt->num_shared_gpio);
 	if (rc) {
-		CAM_ERR(CAM_SENSOR, "Get shared gpio array failed.");
+		CAM_ERR(CAM_RES, "Get shared gpio array failed.");
 		return -EINVAL;
 	}
 
 	dt->pinctrl_info.pinctrl = devm_pinctrl_get(dev);
 	if (IS_ERR_OR_NULL(dt->pinctrl_info.pinctrl)) {
-		CAM_ERR(CAM_SENSOR, "Pinctrl not available");
+		CAM_ERR(CAM_RES, "Pinctrl not available");
 		return -EINVAL;
 	}
 
@@ -542,7 +615,7 @@
 		pinctrl_lookup_state(dt->pinctrl_info.pinctrl,
 			CAM_RES_MGR_DEFAULT);
 	if (IS_ERR_OR_NULL(dt->pinctrl_info.gpio_state_active)) {
-		CAM_ERR(CAM_SENSOR,
+		CAM_ERR(CAM_RES,
 			"Failed to get the active state pinctrl handle");
 		return -EINVAL;
 	}
@@ -551,7 +624,7 @@
 		pinctrl_lookup_state(dt->pinctrl_info.pinctrl,
 			CAM_RES_MGR_SLEEP);
 	if (IS_ERR_OR_NULL(dt->pinctrl_info.gpio_state_suspend)) {
-		CAM_ERR(CAM_SENSOR,
+		CAM_ERR(CAM_RES,
 			"Failed to get the active state pinctrl handle");
 		return -EINVAL;
 	}
@@ -575,10 +648,10 @@
 
 	rc = cam_res_mgr_parse_dt(&pdev->dev);
 	if (rc) {
-		CAM_INFO(CAM_SENSOR, "Disable shared gpio support.");
+		CAM_INFO(CAM_RES, "Disable shared gpio support.");
 		cam_res->shared_gpio_enabled = false;
 	} else {
-		CAM_INFO(CAM_SENSOR, "Enable shared gpio support.");
+		CAM_INFO(CAM_RES, "Enable shared gpio support.");
 		cam_res->shared_gpio_enabled = true;
 	}
 
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_api.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_api.h
index 827073a..1c4c6c8 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_api.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_api.h
@@ -20,20 +20,20 @@
  *
  *  The newly registered led trigger is assigned to flash_res_list.
  *
- * @param name  : Pointer to int led trigger name
- * @param tp    : Save the returned led trigger
+ * @name  : Pointer to int led trigger name
+ * @tp    : Save the returned led trigger
  *
  * @return None
  */
 void cam_res_mgr_led_trigger_register(const char *name,
-		struct led_trigger **tp);
+	struct led_trigger **tp);
 
 /**
  * @brief: Unregister the led trigger
  *
  *  Free the flash_res if this led trigger isn't used by other device .
  *
- * @param tp : Pointer to the led trigger
+ * @tp : Pointer to the led trigger
  *
  * @return None
  */
@@ -42,13 +42,13 @@
 /**
  * @brief: Trigger the event to led core
  *
- * @param trig       : Pointer to the led trigger
- * @param brightness : The brightness need to fire
+ * @trig       : Pointer to the led trigger
+ * @brightness : The brightness need to fire
  *
  * @return None
  */
 void cam_res_mgr_led_trigger_event(struct led_trigger *trig,
-		enum led_brightness brightness);
+	enum led_brightness brightness);
 
 /**
  * @brief: Get the corresponding pinctrl of dev
@@ -57,15 +57,14 @@
  *
  * @return None
  */
-void cam_res_mgr_shared_pinctrl_init(void);
-
+int cam_res_mgr_shared_pinctrl_init(void);
 
 /**
  * @brief: Put the pinctrl
  *
  *  Put the shared pinctrl.
  *
- * @return None
+ * @return Status of operation. Negative in case of error. Zero otherwise.
  */
 void cam_res_mgr_shared_pinctrl_put(void);
 
@@ -75,12 +74,22 @@
  *  Active state can be selected directly, but need hold to suspend the
  *  pinctrl if the gpios in this pinctrl also held by other pinctrl.
  *
- * @param active   : The flag to indicate whether active or suspend
+ * @active   : The flag to indicate whether active or suspend
  * the shared pinctrl.
  *
- * @return None
+ * @return Status of operation. Negative in case of error. Zero otherwise.
  */
-void cam_res_mgr_shared_pinctrl_select_state(bool active);
+int cam_res_mgr_shared_pinctrl_select_state(bool active);
+
+/**
+ * @brief: Post init shared pinctrl
+ *
+ *  Post init to check if the device really has shared gpio,
+ *  suspend and put the pinctrl if not use shared gpio.
+ *
+ * @return Status of operation. Negative in case of error. Zero otherwise.
+ */
+int cam_res_mgr_shared_pinctrl_post_init(void);
 
 /**
  * @brief: Request a gpio
@@ -88,10 +97,10 @@
  *  Will alloc a gpio_res for the new gpio, other find the corresponding
  *  gpio_res.
  *
- * @param dev   : Pointer to the device
- * @param gpio  : The GPIO number
- * @param flags : GPIO configuration as specified by GPIOF_*
- * @param label : A literal description string of this GPIO
+ * @dev   : Pointer to the device
+ * @gpio  : The GPIO number
+ * @flags : GPIO configuration as specified by GPIOF_*
+ * @label : A literal description string of this GPIO
  *
  * @return Status of operation. Negative in case of error. Zero otherwise.
  */
@@ -103,22 +112,22 @@
  *
  *  Free the GPIOs and release corresponding gpio_res.
  *
- * @param dev   : Pointer to the device
- * @param gpio  : Array of the GPIO number
- * @param num   : The number of gpio
+ * @dev   : Pointer to the device
+ * @gpio  : Array of the GPIO number
+ * @num   : The number of gpio
  *
  * @return Status of operation. Negative in case of error. Zero otherwise.
  */
 void cam_res_mgr_gpio_free_arry(struct device *dev,
-		const struct gpio *array, size_t num);
+	const struct gpio *array, size_t num);
 
 /**
  * @brief: Set GPIO power level
  *
  *  Add ref count support for shared GPIOs.
  *
- * @param gpio   : The GPIO number
- * @param value  : The power level need to setup
+ * @gpio   : The GPIO number
+ * @value  : The power level need to setup
  *
  * @return Status of operation. Negative in case of error. Zero otherwise.
  * -EINVAL will be returned if the gpio can't be found in gpio_res_list.
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_private.h b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_private.h
index 0a384c3..4d46c8e 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_private.h
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_res_mgr/cam_res_mgr_private.h
@@ -67,8 +67,8 @@
  * @trigger        : Pointer to the flash trigger
  */
 struct cam_flash_res {
-	struct list_head list;
-	const char *name;
+	struct list_head   list;
+	const char         *name;
 	struct led_trigger *trigger;
 };
 
diff --git a/drivers/media/platform/msm/camera/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c b/drivers/media/platform/msm/camera/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c
index e233131..b3de092 100644
--- a/drivers/media/platform/msm/camera/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c
+++ b/drivers/media/platform/msm/camera/cam_sensor_module/cam_sensor_utils/cam_sensor_util.c
@@ -1159,7 +1159,7 @@
 
 	sensor_pctrl->pinctrl = devm_pinctrl_get(dev);
 	if (IS_ERR_OR_NULL(sensor_pctrl->pinctrl)) {
-		CAM_ERR(CAM_SENSOR, "Getting pinctrl handle failed");
+		CAM_DBG(CAM_SENSOR, "Getting pinctrl handle failed");
 		return -EINVAL;
 	}
 	sensor_pctrl->gpio_state_active =
@@ -1179,10 +1179,15 @@
 		return -EINVAL;
 	}
 
-	cam_res_mgr_shared_pinctrl_init();
+	if (cam_res_mgr_shared_pinctrl_init()) {
+		CAM_ERR(CAM_SENSOR,
+			"Failed to init shared pinctrl");
+		return -EINVAL;
+	}
 
 	return 0;
 }
+
 int msm_cam_sensor_handle_reg_gpio(int seq_type,
 	struct msm_camera_gpio_num_info *gpio_num_info, int val)
 {
@@ -1232,7 +1237,8 @@
 
 	ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev);
 	if (ret < 0) {
-		CAM_ERR(CAM_SENSOR, "Initialization of pinctrl failed");
+		/* Some sensor subdev no pinctrl. */
+		CAM_DBG(CAM_SENSOR, "Initialization of pinctrl failed");
 		ctrl->cam_pinctrl_status = 0;
 	} else {
 		ctrl->cam_pinctrl_status = 1;
@@ -1249,11 +1255,19 @@
 		if (ret)
 			CAM_ERR(CAM_SENSOR, "cannot set pin to active state");
 
-		cam_res_mgr_shared_pinctrl_select_state(true);
+		ret = cam_res_mgr_shared_pinctrl_select_state(true);
+		if (ret)
+			CAM_ERR(CAM_SENSOR,
+				"Cannot set shared pin to active state");
+
+		ret = cam_res_mgr_shared_pinctrl_post_init();
+		if (ret)
+			CAM_ERR(CAM_SENSOR,
+				"Failed to post init shared pinctrl");
 	}
 
 	for (index = 0; index < ctrl->power_setting_size; index++) {
-		CAM_DBG(CAM_SENSOR, "index: %d",  index);
+		CAM_DBG(CAM_SENSOR, "index: %d", index);
 		power_setting = &ctrl->power_setting[index];
 		CAM_DBG(CAM_SENSOR, "seq_type %d", power_setting->seq_type);
 
diff --git a/drivers/media/platform/msm/camera/cam_utils/cam_debug_util.h b/drivers/media/platform/msm/camera/cam_utils/cam_debug_util.h
index 9745d45..c0160c4 100644
--- a/drivers/media/platform/msm/camera/cam_utils/cam_debug_util.h
+++ b/drivers/media/platform/msm/camera/cam_utils/cam_debug_util.h
@@ -34,6 +34,7 @@
 #define CAM_HFI        (1 << 18)
 #define CAM_CTXT       (1 << 19)
 #define CAM_OIS        (1 << 20)
+#define CAM_RES        (1 << 21)
 
 #define STR_BUFFER_MAX_LENGTH  1024