mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Liu Ying <victor.liu@nxp.com>
To: Frank Li <Frank.li@nxp.com>
Cc: Philipp Zabel <p.zabel@pengutronix.de>,
	Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
	Maxime Ripard <mripard@kernel.org>,
	Thomas Zimmermann <tzimmermann@suse.de>,
	David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	Dmitry Baryshkov <lumag@kernel.org>,
	dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org,
	imx@lists.linux.dev, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 05/14] drm/imx: dc-crtc: Disable at boot
Date: Mon, 22 Sep 2025 11:42:21 +0800	[thread overview]
Message-ID: <18230ef9-09e1-48c8-aeee-d40d483e28b1@nxp.com> (raw)
In-Reply-To: <aM1w4URkELrmK7No@lizhi-Precision-Tower-5810>

On 09/19/2025, Frank Li wrote:
> On Fri, Jul 04, 2025 at 05:03:52PM +0800, Liu Ying wrote:
>> CRTC(s) could still be running after the DRM device is unplugged by
>> calling drm_dev_unplug(), because the CRTC disablement logic is
>> protected and bypassed by the drm_dev_enter()/drm_dev_exit() pair.
>> Hence, Pixel Engine's AXI clock use count(managed by Pixel Engine
>> driver's runtime PM) and pixel clock use count could be inbalanced
>> after removing and re-installing the driver module.  To fix this,
>> add a helper dc_crtc_disable_at_boot() and call it to properly
>> disable all CRTCs before advertising DRM device to user-space by
>> calling drm_dev_register().
>>
>> Fixes: 711a3b878366 ("drm/imx: Add i.MX8qxp Display Controller KMS")
>> Signed-off-by: Liu Ying <victor.liu@nxp.com>
>> ---
>>  drivers/gpu/drm/imx/dc/dc-crtc.c | 50 ++++++++++++++++++++++++++++++++++++----
>>  drivers/gpu/drm/imx/dc/dc-drv.c  |  5 ++++
>>  drivers/gpu/drm/imx/dc/dc-drv.h  |  3 +++
>>  3 files changed, 53 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/imx/dc/dc-crtc.c b/drivers/gpu/drm/imx/dc/dc-crtc.c
>> index 31d3a982deaf7a0390937285c9d5d00100323181..45a87df1ad6a8bd768aa5ed38d6f03f14052b3d7 100644
>> --- a/drivers/gpu/drm/imx/dc/dc-crtc.c
>> +++ b/drivers/gpu/drm/imx/dc/dc-crtc.c
>> @@ -293,6 +293,16 @@ dc_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state)
>>  	dc_crtc_queue_state_event(new_crtc_state);
>>  }
>>
>> +static inline void __dc_crtc_disable_fg(struct drm_crtc *crtc)
>> +{
>> +	struct dc_crtc *dc_crtc = to_dc_crtc(crtc);
>> +
>> +	enable_irq(dc_crtc->irq_dec_seqcomplete);
>> +	dc_fg_disable(dc_crtc->fg);
>> +	DC_CRTC_WAIT_FOR_COMPLETION_TIMEOUT(dec_seqcomplete_done);
>> +	disable_irq(dc_crtc->irq_dec_seqcomplete);
>> +}
>> +
>>  static void
>>  dc_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
>>  {
>> @@ -305,11 +315,7 @@ dc_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
>>  	if (!drm_dev_enter(crtc->dev, &idx))
>>  		goto out;
>>
>> -	enable_irq(dc_crtc->irq_dec_seqcomplete);
>> -	dc_fg_disable(dc_crtc->fg);
>> -	DC_CRTC_WAIT_FOR_COMPLETION_TIMEOUT(dec_seqcomplete_done);
>> -	disable_irq(dc_crtc->irq_dec_seqcomplete);
>> -
>> +	__dc_crtc_disable_fg(crtc);
>>  	dc_fg_disable_clock(dc_crtc->fg);
>>
>>  	/* request pixel engine power-off as plane is off too */
>> @@ -337,6 +343,40 @@ dc_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state)
>>  	spin_unlock_irq(&crtc->dev->event_lock);
>>  }
>>
>> +void dc_crtc_disable_at_boot(struct drm_crtc *crtc)
>> +{
>> +	struct dc_drm_device *dc_drm = to_dc_drm_device(crtc->dev);
>> +	struct dc_crtc *dc_crtc = to_dc_crtc(crtc);
>> +	int ret;
>> +
>> +	ret = pm_runtime_resume_and_get(dc_crtc->de->dev);
>> +	if (ret < 0) {
>> +		dc_crtc_err(crtc, "failed to get DC display engine RPM: %d\n",
>> +			    ret);
>> +		return;
>> +	}
>> +
>> +	if (!dc_fg_wait_for_frame_index_moving(dc_crtc->fg)) {
>> +		dc_crtc_dbg(crtc, "FrameGen frame index isn't moving\n");
>> +		goto out;
>> +	}
>> +
>> +	dc_crtc_dbg(crtc, "disabling at boot\n");
>> +	__dc_crtc_disable_fg(crtc);
>> +	dc_fg_disable_clock(dc_crtc->fg);
>> +
>> +	if (!dc_drm->pe_clk_axi_disabled) {
>> +		clk_disable_unprepare(dc_drm->pe->clk_axi);
>> +		dc_drm->pe_clk_axi_disabled = true;
>> +	}
> 
> look like dc_crtc_disable_at_boot() call by dc_drm_bind(), does it call
> twice without call unbind()? Most like other place paired function have
> not correct.

It could be called multiple times by bind() without calling unbind.  But
it's fine and by design.  As this function checks FrameGen frame index
moving before disabling CRTC(no moving with a disabled CRTC), CRTC is
actually disabled at most for one time no matter how many times bind()
is called without unbind().

> 
> Frank
> 
>> +
>> +out:
>> +	ret = pm_runtime_put(dc_crtc->de->dev);
>> +	if (ret < 0)
>> +		dc_crtc_err(crtc, "failed to put DC display engine RPM: %d\n",
>> +			    ret);
>> +}
>> +
>>  static bool dc_crtc_get_scanout_position(struct drm_crtc *crtc,
>>  					 bool in_vblank_irq,
>>  					 int *vpos, int *hpos,
>> diff --git a/drivers/gpu/drm/imx/dc/dc-drv.c b/drivers/gpu/drm/imx/dc/dc-drv.c
>> index 04f021d2d6cfc93972aa8d9073be24d347152602..f93766b6bfbfae8510db05278d104820ca0719c4 100644
>> --- a/drivers/gpu/drm/imx/dc/dc-drv.c
>> +++ b/drivers/gpu/drm/imx/dc/dc-drv.c
>> @@ -17,6 +17,7 @@
>>
>>  #include <drm/clients/drm_client_setup.h>
>>  #include <drm/drm_atomic_helper.h>
>> +#include <drm/drm_crtc.h>
>>  #include <drm/drm_drv.h>
>>  #include <drm/drm_fbdev_dma.h>
>>  #include <drm/drm_fourcc.h>
>> @@ -96,6 +97,7 @@ static int dc_drm_bind(struct device *dev)
>>  	struct dc_priv *priv = dev_get_drvdata(dev);
>>  	struct dc_drm_device *dc_drm;
>>  	struct drm_device *drm;
>> +	struct drm_crtc *crtc;
>>  	int ret;
>>
>>  	dc_drm = devm_drm_dev_alloc(dev, &dc_drm_driver, struct dc_drm_device,
>> @@ -118,6 +120,9 @@ static int dc_drm_bind(struct device *dev)
>>  	if (ret)
>>  		return ret;
>>
>> +	drm_for_each_crtc(crtc, drm)
>> +		dc_crtc_disable_at_boot(crtc);
>> +
>>  	ret = drm_dev_register(drm, 0);
>>  	if (ret) {
>>  		dev_err(dev, "failed to register drm device: %d\n", ret);
>> diff --git a/drivers/gpu/drm/imx/dc/dc-drv.h b/drivers/gpu/drm/imx/dc/dc-drv.h
>> index eb61b8c7626933adc7688f046139e2167665dad1..68e99ba7cedbca1b8bdc0d8ced7a610a1056bfc7 100644
>> --- a/drivers/gpu/drm/imx/dc/dc-drv.h
>> +++ b/drivers/gpu/drm/imx/dc/dc-drv.h
>> @@ -50,6 +50,8 @@ struct dc_drm_device {
>>  	struct dc_pe *pe;
>>  	/** @tc: tcon list */
>>  	struct dc_tc *tc[DC_DISPLAYS];
>> +	/** @pe_clk_axi_disabled: disablement flag at boot */
>> +	bool pe_clk_axi_disabled;
>>  };
>>
>>  struct dc_subdev_info {
>> @@ -96,6 +98,7 @@ static inline int dc_subdev_get_id(const struct dc_subdev_info *info,
>>  	return -EINVAL;
>>  }
>>
>> +void dc_crtc_disable_at_boot(struct drm_crtc *crtc);
>>  void dc_de_post_bind(struct dc_drm_device *dc_drm);
>>  void dc_pe_post_bind(struct dc_drm_device *dc_drm);
>>
>>
>> --
>> 2.34.1
>>


-- 
Regards,
Liu Ying

  reply	other threads:[~2025-09-22  3:41 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-07-04  9:03 [PATCH 00/14] drm/imx: dc: Use prefetch engine Liu Ying
2025-07-04  9:03 ` [PATCH 01/14] dt-bindings: display: imx: Add i.MX8qxp/qm PRG binding Liu Ying
2025-07-04  9:03 ` [PATCH 02/14] dt-bindings: display: imx: Add i.MX8qxp/qm DPR channel binding Liu Ying
2025-07-04  9:03 ` [PATCH 03/14] MAINTAINERS: Add i.MX8qxp prefetch engine DT binding files Liu Ying
2025-09-19 14:53   ` Frank Li
2025-07-04  9:03 ` [PATCH 04/14] drm/imx: dc-fu: Fix dimensions Liu Ying
2025-07-04 11:29   ` Alexander Stein
2025-09-19 14:54   ` Frank Li
2025-07-04  9:03 ` [PATCH 05/14] drm/imx: dc-crtc: Disable at boot Liu Ying
2025-09-19 15:04   ` Frank Li
2025-09-22  3:42     ` Liu Ying [this message]
2025-07-04  9:03 ` [PATCH 06/14] drm/imx: dc: Add PRG support Liu Ying
2025-09-19 15:09   ` Frank Li
2025-07-04  9:03 ` [PATCH 07/14] drm/imx: dc: Add DPR channel support Liu Ying
2025-09-19 15:15   ` Frank Li
2025-09-22  3:44     ` Liu Ying
2025-07-04  9:03 ` [PATCH 08/14] drm/imx: dc: Use TCON operation mode Liu Ying
2025-09-19 15:24   ` Frank Li
2025-09-22  3:48     ` Liu Ying
2025-09-22 15:00       ` Frank Li
2025-07-04  9:03 ` [PATCH 09/14] drm/imx: dc-ed: Support getting source selection Liu Ying
2025-09-19 15:25   ` Frank Li
2025-07-04  9:03 ` [PATCH 10/14] drm/imx: dc-lb: Support getting secondary input selection Liu Ying
2025-09-19 15:26   ` [PATCH 10/14] drm/imx: dc-lb: Support getting secondary input selectio Frank Li
2025-07-04  9:03 ` [PATCH 11/14] drm/imx: dc-ed: Drop initial source selection Liu Ying
2025-09-19 15:27   ` Frank Li
2025-07-04  9:03 ` [PATCH 12/14] drm/imx: dc-lb: Drop initial primary and secondary input selections Liu Ying
2025-09-19 15:30   ` Frank Li
2025-07-04  9:04 ` [PATCH 13/14] drm/imx: dc-fu: Get DPR channel Liu Ying
2025-09-19 15:31   ` Frank Li
2025-07-04  9:04 ` [PATCH 14/14] drm/imx: dc: Use prefetch engine Liu Ying
2025-09-19 15:41   ` Frank Li
2025-09-22  3:55     ` Liu Ying
2025-08-12  8:29 ` [PATCH 00/14] " Liu Ying
2025-09-19  9:20   ` Liu Ying

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=18230ef9-09e1-48c8-aeee-d40d483e28b1@nxp.com \
    --to=victor.liu@nxp.com \
    --cc=Frank.li@nxp.com \
    --cc=airlied@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=festevam@gmail.com \
    --cc=imx@lists.linux.dev \
    --cc=kernel@pengutronix.de \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lumag@kernel.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®