Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f6fad951 authored by Jeyaprakash Soundrapandian's avatar Jeyaprakash Soundrapandian Committed by Gerrit - the friendly Code Review server
Browse files

Merge "msm: camera: Add shared clk support" into dev/msm-4.9-camx

parents 9c32372e f3b03fa0
Loading
Loading
Loading
Loading
+10 −3
Original line number Original line Diff line number Diff line
@@ -180,6 +180,9 @@ Optional properties:
  should contain phandle of respective ir-cut node
  should contain phandle of respective ir-cut node
- qcom,special-support-sensors: if only some special sensors are supported
- qcom,special-support-sensors: if only some special sensors are supported
  on this board, add sensor name in this property.
  on this board, add sensor name in this property.
- use-shared-clk : It is booloean property. This property is required
  if the clk is shared clk between different sensor and ois, if this
  device need to be opened together.
- clock-rates: clock rate in Hz.
- clock-rates: clock rate in Hz.
- clock-cntl-level: says what all different cloc level node has.
- clock-cntl-level: says what all different cloc level node has.
- clock-cntl-support: Says whether clock control support is present or not
- clock-cntl-support: Says whether clock control support is present or not
@@ -248,6 +251,9 @@ Optional properties:
  required from the regulators mentioned in the regulator-names property
  required from the regulators mentioned in the regulator-names property
  (in the same order).
  (in the same order).
- cam_vaf-supply : should contain regulator from which ois voltage is supplied
- cam_vaf-supply : should contain regulator from which ois voltage is supplied
- use-shared-clk : It is booloean property. This property is required
  if the clk is shared clk between different sensor and ois, if this
  device need to be opened together.


Example:
Example:


@@ -354,8 +360,8 @@ qcom,cci@0xfda0c000 {
         status = "ok";
         status = "ok";
         shared-gpios = <18 19>;
         shared-gpios = <18 19>;
         pinctrl-names = "cam_res_mgr_default", "cam_res_mgr_suspend";
         pinctrl-names = "cam_res_mgr_default", "cam_res_mgr_suspend";
         pinctrl-0 = <&cam_res_mgr_active>;
         pinctrl-0 = <&cam_shared_clk_active &cam_res_mgr_active>;
         pinctrl-1 = <&cam_res_mgr_suspend>;
         pinctrl-1 = <&cam_shared_clk_suspend &cam_res_mgr_suspend>;
    };
    };


    qcom,cam-sensor@0 {
    qcom,cam-sensor@0 {
@@ -398,6 +404,7 @@ qcom,cci@0xfda0c000 {
         sensor-mode = <0>;
         sensor-mode = <0>;
         cci-master = <0>;
         cci-master = <0>;
         status = "ok";
         status = "ok";
         use-shared-clk;
         clocks = <&clock_mmss clk_mclk0_clk_src>,
         clocks = <&clock_mmss clk_mclk0_clk_src>,
               <&clock_mmss clk_camss_mclk0_clk>;
               <&clock_mmss clk_camss_mclk0_clk>;
         clock-names = "cam_src_clk", "cam_clk";
         clock-names = "cam_src_clk", "cam_clk";
+30 −3
Original line number Original line Diff line number Diff line
@@ -51,6 +51,10 @@ static void cam_res_mgr_free_res(void)
		kfree(flash_res);
		kfree(flash_res);
	}
	}
	mutex_unlock(&cam_res->flash_res_lock);
	mutex_unlock(&cam_res->flash_res_lock);

	mutex_lock(&cam_res->clk_res_lock);
	cam_res->shared_clk_ref_count = 0;
	mutex_unlock(&cam_res->clk_res_lock);
}
}


void cam_res_mgr_led_trigger_register(const char *name, struct led_trigger **tp)
void cam_res_mgr_led_trigger_register(const char *name, struct led_trigger **tp)
@@ -243,6 +247,9 @@ static bool cam_res_mgr_shared_pinctrl_check_hold(void)
		}
		}
	}
	}


	if (cam_res->shared_clk_ref_count > 1)
		hold = true;

	return hold;
	return hold;
}
}


@@ -258,11 +265,13 @@ void cam_res_mgr_shared_pinctrl_put(void)
	mutex_lock(&cam_res->gpio_res_lock);
	mutex_lock(&cam_res->gpio_res_lock);
	if (cam_res->pstatus == PINCTRL_STATUS_PUT) {
	if (cam_res->pstatus == PINCTRL_STATUS_PUT) {
		CAM_DBG(CAM_RES, "The shared pinctrl already been put");
		CAM_DBG(CAM_RES, "The shared pinctrl already been put");
		mutex_unlock(&cam_res->gpio_res_lock);
		return;
		return;
	}
	}


	if (cam_res_mgr_shared_pinctrl_check_hold()) {
	if (cam_res_mgr_shared_pinctrl_check_hold()) {
		CAM_INFO(CAM_RES, "Need hold put this pinctrl");
		CAM_INFO(CAM_RES, "Need hold put this pinctrl");
		mutex_unlock(&cam_res->gpio_res_lock);
		return;
		return;
	}
	}


@@ -330,10 +339,12 @@ int cam_res_mgr_shared_pinctrl_post_init(void)
	pinctrl_info = &cam_res->dt.pinctrl_info;
	pinctrl_info = &cam_res->dt.pinctrl_info;


	/*
	/*
	 * If no gpio resource in gpio_res_list, it means
	 * If no gpio resource in gpio_res_list, and
	 * this device don't have shared gpio
	 * no shared clk now, it means this device
	 * don't have shared gpio.
	 */
	 */
	if (list_empty(&cam_res->gpio_res_list)) {
	if (list_empty(&cam_res->gpio_res_list) &&
		cam_res->shared_clk_ref_count < 1) {
		ret = pinctrl_select_state(pinctrl_info->pinctrl,
		ret = pinctrl_select_state(pinctrl_info->pinctrl,
			pinctrl_info->gpio_state_suspend);
			pinctrl_info->gpio_state_suspend);
		devm_pinctrl_put(pinctrl_info->pinctrl);
		devm_pinctrl_put(pinctrl_info->pinctrl);
@@ -576,6 +587,20 @@ int cam_res_mgr_gpio_set_value(unsigned int gpio, int value)
}
}
EXPORT_SYMBOL(cam_res_mgr_gpio_set_value);
EXPORT_SYMBOL(cam_res_mgr_gpio_set_value);


void cam_res_mgr_shared_clk_config(bool value)
{
	if (!cam_res)
		return;

	mutex_lock(&cam_res->clk_res_lock);
	if (value)
		cam_res->shared_clk_ref_count++;
	else
		cam_res->shared_clk_ref_count--;
	mutex_unlock(&cam_res->clk_res_lock);
}
EXPORT_SYMBOL(cam_res_mgr_shared_clk_config);

static int cam_res_mgr_parse_dt(struct device *dev)
static int cam_res_mgr_parse_dt(struct device *dev)
{
{
	int rc = 0;
	int rc = 0;
@@ -649,6 +674,7 @@ static int cam_res_mgr_probe(struct platform_device *pdev)
	cam_res->dev = &pdev->dev;
	cam_res->dev = &pdev->dev;
	mutex_init(&cam_res->flash_res_lock);
	mutex_init(&cam_res->flash_res_lock);
	mutex_init(&cam_res->gpio_res_lock);
	mutex_init(&cam_res->gpio_res_lock);
	mutex_init(&cam_res->clk_res_lock);


	rc = cam_res_mgr_parse_dt(&pdev->dev);
	rc = cam_res_mgr_parse_dt(&pdev->dev);
	if (rc) {
	if (rc) {
@@ -659,6 +685,7 @@ static int cam_res_mgr_probe(struct platform_device *pdev)
		cam_res->shared_gpio_enabled = true;
		cam_res->shared_gpio_enabled = true;
	}
	}


	cam_res->shared_clk_ref_count = 0;
	cam_res->pstatus = PINCTRL_STATUS_PUT;
	cam_res->pstatus = PINCTRL_STATUS_PUT;


	INIT_LIST_HEAD(&cam_res->gpio_res_list);
	INIT_LIST_HEAD(&cam_res->gpio_res_list);
+11 −0
Original line number Original line Diff line number Diff line
@@ -134,4 +134,15 @@ void cam_res_mgr_gpio_free_arry(struct device *dev,
 */
 */
int cam_res_mgr_gpio_set_value(unsigned int gpio, int value);
int cam_res_mgr_gpio_set_value(unsigned int gpio, int value);


/**
 * @brief: Config the shared clk ref count
 *
 *  Config the shared clk ref count..
 *
 * @value   : get or put the shared clk.
 *
 * @return None
 */
void cam_res_mgr_shared_clk_config(bool value);

#endif /* __CAM_RES_MGR_API_H__ */
#endif /* __CAM_RES_MGR_API_H__ */
+4 −0
Original line number Original line Diff line number Diff line
@@ -96,6 +96,7 @@ struct cam_res_mgr_dt {
 * @flash_res_list      : List head of the flash resource
 * @flash_res_list      : List head of the flash resource
 * @gpio_res_lock       : GPIO resource lock
 * @gpio_res_lock       : GPIO resource lock
 * @flash_res_lock      : Flash resource lock
 * @flash_res_lock      : Flash resource lock
 * @clk_res_lock        : Clk resource lock
 */
 */
struct cam_res_mgr {
struct cam_res_mgr {
	struct device         *dev;
	struct device         *dev;
@@ -104,10 +105,13 @@ struct cam_res_mgr {
	bool                  shared_gpio_enabled;
	bool                  shared_gpio_enabled;
	enum pinctrl_status   pstatus;
	enum pinctrl_status   pstatus;


	uint                  shared_clk_ref_count;

	struct list_head      gpio_res_list;
	struct list_head      gpio_res_list;
	struct list_head      flash_res_list;
	struct list_head      flash_res_list;
	struct mutex          gpio_res_lock;
	struct mutex          gpio_res_lock;
	struct mutex          flash_res_lock;
	struct mutex          flash_res_lock;
	struct mutex          clk_res_lock;
};
};


#endif /* __CAM_RES_MGR_PRIVATE_H__ */
#endif /* __CAM_RES_MGR_PRIVATE_H__ */
+11 −0
Original line number Original line Diff line number Diff line
@@ -1235,6 +1235,9 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl,
		return -EINVAL;
		return -EINVAL;
	}
	}


	if (soc_info->use_shared_clk)
		cam_res_mgr_shared_clk_config(true);

	ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev);
	ret = msm_camera_pinctrl_init(&(ctrl->pinctrl_info), ctrl->dev);
	if (ret < 0) {
	if (ret < 0) {
		/* Some sensor subdev no pinctrl. */
		/* Some sensor subdev no pinctrl. */
@@ -1492,6 +1495,7 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl,
				(power_setting->delay * 1000) + 1000);
				(power_setting->delay * 1000) + 1000);
		}
		}
	}
	}

	if (ctrl->cam_pinctrl_status) {
	if (ctrl->cam_pinctrl_status) {
		ret = pinctrl_select_state(
		ret = pinctrl_select_state(
				ctrl->pinctrl_info.pinctrl,
				ctrl->pinctrl_info.pinctrl,
@@ -1502,6 +1506,10 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl,
		pinctrl_put(ctrl->pinctrl_info.pinctrl);
		pinctrl_put(ctrl->pinctrl_info.pinctrl);
		cam_res_mgr_shared_pinctrl_put();
		cam_res_mgr_shared_pinctrl_put();
	}
	}

	if (soc_info->use_shared_clk)
		cam_res_mgr_shared_clk_config(false);

	ctrl->cam_pinctrl_status = 0;
	ctrl->cam_pinctrl_status = 0;


	cam_sensor_util_request_gpio_table(soc_info, 0);
	cam_sensor_util_request_gpio_table(soc_info, 0);
@@ -1698,6 +1706,9 @@ int msm_camera_power_down(struct cam_sensor_power_ctrl_t *ctrl,
		cam_res_mgr_shared_pinctrl_put();
		cam_res_mgr_shared_pinctrl_put();
	}
	}


	if (soc_info->use_shared_clk)
		cam_res_mgr_shared_clk_config(false);

	ctrl->cam_pinctrl_status = 0;
	ctrl->cam_pinctrl_status = 0;


	cam_sensor_util_request_gpio_table(soc_info, 0);
	cam_sensor_util_request_gpio_table(soc_info, 0);
Loading