Re: [PATCH 10/45] drm/msm/dp: move the pixel clock control to its own API

From: Dmitry Baryshkov
Date: Fri Dec 06 2024 - 04:11:42 EST


On Thu, Dec 05, 2024 at 08:31:41PM -0800, Abhinav Kumar wrote:
> Enable/Disable of DP pixel clock happens in multiple code paths
> leading to code duplication. Move it into individual helpers so that
> the helpers can be called wherever necessary.
>
> Signed-off-by: Abhinav Kumar <quic_abhinavk@xxxxxxxxxxx>
> ---
> drivers/gpu/drm/msm/dp/dp_ctrl.c | 76 ++++++++++++++++++++++------------------
> 1 file changed, 41 insertions(+), 35 deletions(-)
>
> diff --git a/drivers/gpu/drm/msm/dp/dp_ctrl.c b/drivers/gpu/drm/msm/dp/dp_ctrl.c
> index 0bed85b5c8e8133ffa8c74d5de22668905396d09..118f5ed83e464f9f27f813eb39624f9c3189f5ac 100644
> --- a/drivers/gpu/drm/msm/dp/dp_ctrl.c
> +++ b/drivers/gpu/drm/msm/dp/dp_ctrl.c
> @@ -1698,6 +1698,30 @@ static bool msm_dp_ctrl_send_phy_test_pattern(struct msm_dp_ctrl_private *ctrl)
> return success;
> }
>
> +static int msm_dp_ctrl_stream_clk_on(struct msm_dp_ctrl_private *ctrl, unsigned long pixel_rate)
> +{
> + int ret;
> +
> + ret = clk_set_rate(ctrl->pixel_clk, pixel_rate * 1000);
> + if (ret) {
> + DRM_ERROR("Failed to set pixel clock rate. ret=%d\n", ret);
> + return ret;
> + }
> +
> + if (ctrl->stream_clks_on) {
> + drm_dbg_dp(ctrl->drm_dev, "pixel clks already enabled\n");
> + } else {
> + ret = clk_prepare_enable(ctrl->pixel_clk);
> + if (ret) {
> + DRM_ERROR("Failed to start pixel clocks. ret=%d\n", ret);
> + return ret;
> + }
> + ctrl->stream_clks_on = true;
> + }
> +
> + return ret;
> +}
> +
> static int msm_dp_ctrl_process_phy_test_request(struct msm_dp_ctrl_private *ctrl,
> struct msm_dp_panel *msm_dp_panel)
> {
> @@ -1724,22 +1748,7 @@ static int msm_dp_ctrl_process_phy_test_request(struct msm_dp_ctrl_private *ctrl
> }
>
> pixel_rate = msm_dp_panel->msm_dp_mode.drm_mode.clock;
> - ret = clk_set_rate(ctrl->pixel_clk, pixel_rate * 1000);
> - if (ret) {
> - DRM_ERROR("Failed to set pixel clock rate. ret=%d\n", ret);
> - return ret;
> - }
> -
> - if (ctrl->stream_clks_on) {
> - drm_dbg_dp(ctrl->drm_dev, "pixel clks already enabled\n");
> - } else {
> - ret = clk_prepare_enable(ctrl->pixel_clk);
> - if (ret) {
> - DRM_ERROR("Failed to start pixel clocks. ret=%d\n", ret);
> - return ret;
> - }
> - ctrl->stream_clks_on = true;
> - }
> + ret = msm_dp_ctrl_stream_clk_on(ctrl, pixel_rate);
>
> msm_dp_ctrl_send_phy_test_pattern(ctrl);
>
> @@ -1999,21 +2008,10 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *
>
> drm_dbg_dp(ctrl->drm_dev, "pixel_rate=%lu\n", pixel_rate);
>
> - ret = clk_set_rate(ctrl->pixel_clk, pixel_rate * 1000);
> + ret = msm_dp_ctrl_stream_clk_on(ctrl, pixel_rate);
> if (ret) {
> - DRM_ERROR("Failed to set pixel clock rate. ret=%d\n", ret);
> - goto end;
> - }
> -
> - if (ctrl->stream_clks_on) {
> - drm_dbg_dp(ctrl->drm_dev, "pixel clks already enabled\n");
> - } else {
> - ret = clk_prepare_enable(ctrl->pixel_clk);
> - if (ret) {
> - DRM_ERROR("Failed to start pixel clocks. ret=%d\n", ret);
> - goto end;
> - }
> - ctrl->stream_clks_on = true;
> + DRM_ERROR("failed to enable stream pixel clk\n");
> + return ret;
> }
>
> /*
> @@ -2041,10 +2039,21 @@ int msm_dp_ctrl_on_stream(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *
> drm_dbg_dp(ctrl->drm_dev,
> "mainlink %s\n", mainlink_ready ? "READY" : "NOT READY");
>
> -end:
> return ret;
> }
>
> +static void msm_dp_ctrl_stream_clk_off(struct msm_dp_ctrl *msm_dp_ctrl)

At least this should come right after msm_dp_ctrl_stream_clk_on().

> +{
> + struct msm_dp_ctrl_private *ctrl;
> +
> + ctrl = container_of(msm_dp_ctrl, struct msm_dp_ctrl_private, msm_dp_ctrl);
> +
> + if (ctrl->stream_clks_on) {
> + clk_disable_unprepare(ctrl->pixel_clk);
> + ctrl->stream_clks_on = false;
> + }
> +}
> +
> void msm_dp_ctrl_clear_vsc_sdp_pkt(struct msm_dp_ctrl *msm_dp_ctrl, struct msm_dp_panel *dp_panel)
> {
> struct msm_dp_ctrl_private *ctrl;
> @@ -2115,10 +2124,7 @@ void msm_dp_ctrl_off(struct msm_dp_ctrl *msm_dp_ctrl)
>
> msm_dp_catalog_ctrl_reset(ctrl->catalog);
>
> - if (ctrl->stream_clks_on) {
> - clk_disable_unprepare(ctrl->pixel_clk);
> - ctrl->stream_clks_on = false;
> - }
> + msm_dp_ctrl_stream_clk_off(msm_dp_ctrl);
>
> dev_pm_opp_set_rate(ctrl->dev, 0);
> msm_dp_ctrl_link_clk_disable(&ctrl->msm_dp_ctrl);
>
> --
> 2.34.1
>

--
With best wishes
Dmitry