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

Commit f3b03fa0 authored by Depeng Shao's avatar Depeng Shao
Browse files

msm: camera: Add shared clk support



Manage the shared clk's pinctrl in camera resource
manager module.
Some devices need to share same clk between sensor
and ois device, and these devices need to be opened
together in dual camera usecase, add shared clk
support for this situation.

Change-Id: I301ce19287b4cf10c5f04f2ebffe440bd96dd1e7
Signed-off-by: default avatarDepeng Shao <depengs@codeaurora.org>
parent 64711020
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -180,6 +180,9 @@ Optional properties:
  should contain phandle of respective ir-cut node
- qcom,special-support-sensors: if only some special sensors are supported
  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-cntl-level: says what all different cloc level node has.
- 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
  (in the same order).
- 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:

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

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

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

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

@@ -330,10 +339,12 @@ int cam_res_mgr_shared_pinctrl_post_init(void)
	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 no gpio resource in gpio_res_list, and
	 * 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,
			pinctrl_info->gpio_state_suspend);
		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);

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

	rc = cam_res_mgr_parse_dt(&pdev->dev);
	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_clk_ref_count = 0;
	cam_res->pstatus = PINCTRL_STATUS_PUT;

	INIT_LIST_HEAD(&cam_res->gpio_res_list);
+11 −0
Original line number 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);

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

	uint                  shared_clk_ref_count;

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

#endif /* __CAM_RES_MGR_PRIVATE_H__ */
+11 −0
Original line number Diff line number Diff line
@@ -1235,6 +1235,9 @@ int cam_sensor_core_power_up(struct cam_sensor_power_ctrl_t *ctrl,
		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);
	if (ret < 0) {
		/* 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);
		}
	}

	if (ctrl->cam_pinctrl_status) {
		ret = pinctrl_select_state(
				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);
		cam_res_mgr_shared_pinctrl_put();
	}

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

	ctrl->cam_pinctrl_status = 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();
	}

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

	ctrl->cam_pinctrl_status = 0;

	cam_sensor_util_request_gpio_table(soc_info, 0);
Loading