diff mbox series

[14/21] drm: mxsfb: Enable vblank handling

Message ID 20200309195216.31042-15-laurent.pinchart@ideasonboard.com (mailing list archive)
State New, archived
Headers show
Series drm: mxsfb: Add i.MX7 support | expand

Commit Message

Laurent Pinchart March 9, 2020, 7:52 p.m. UTC
Enable vblank handling when the CRTC is turned on and disable it when it
is turned off. This requires moving vblank init after the KMS pipeline
initialisation, otherwise drm_vblank_init() gets called with 0 CRTCs.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
 drivers/gpu/drm/mxsfb/mxsfb_drv.c | 15 +++++++++------
 drivers/gpu/drm/mxsfb/mxsfb_kms.c |  6 +++++-
 2 files changed, 14 insertions(+), 7 deletions(-)

Comments

Stefan Agner March 23, 2020, 11:08 p.m. UTC | #1
On 2020-03-09 20:52, Laurent Pinchart wrote:
> Enable vblank handling when the CRTC is turned on and disable it when it
> is turned off. This requires moving vblank init after the KMS pipeline
> initialisation, otherwise drm_vblank_init() gets called with 0 CRTCs.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

With this patch applied I start to get system resets on my Colibri iMX7
test device during system boot shortly after initializing mxsfb. It
happens not on every boot, but rather often, I would say every second or
third. From what I can tell the interrupt handling should be safe, but
it seems that every now and then something races. Any idea what that
could be?

--
Stefan

> ---
>  drivers/gpu/drm/mxsfb/mxsfb_drv.c | 15 +++++++++------
>  drivers/gpu/drm/mxsfb/mxsfb_kms.c |  6 +++++-
>  2 files changed, 14 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> index e324bd2a63a5..72b4f6a947a4 100644
> --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
> @@ -160,12 +160,6 @@ static int mxsfb_load(struct drm_device *drm,
> unsigned long flags)
>  
>  	pm_runtime_enable(drm->dev);
>  
> -	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
> -	if (ret < 0) {
> -		dev_err(drm->dev, "Failed to initialise vblank\n");
> -		goto err_vblank;
> -	}
> -
>  	/* Modeset init */
>  	drm_mode_config_init(drm);
>  
> @@ -175,6 +169,15 @@ static int mxsfb_load(struct drm_device *drm,
> unsigned long flags)
>  		goto err_vblank;
>  	}
>  
> +	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
> +	if (ret < 0) {
> +		dev_err(drm->dev, "Failed to initialise vblank\n");
> +		goto err_vblank;
> +	}
> +
> +	/* Start with vertical blanking interrupt reporting disabled. */
> +	drm_crtc_vblank_off(&mxsfb->crtc);
> +
>  	ret = mxsfb_attach_bridge(mxsfb);
>  	if (ret) {
>  		dev_err(drm->dev, "Cannot connect bridge: %d\n", ret);
> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> index ac2696c8483d..640305fb1068 100644
> --- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> +++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
> @@ -322,8 +322,10 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>  	dma_addr_t paddr;
>  
>  	pm_runtime_get_sync(drm->dev);
> -
>  	mxsfb_enable_axi_clk(mxsfb);
> +
> +	drm_crtc_vblank_on(crtc);
> +
>  	mxsfb_crtc_mode_set_nofb(mxsfb);
>  
>  	/* Write cur_buf as well to avoid an initial corrupt frame */
> @@ -353,6 +355,8 @@ static void mxsfb_crtc_atomic_disable(struct drm_crtc *crtc,
>  	}
>  	spin_unlock_irq(&drm->event_lock);
>  
> +	drm_crtc_vblank_off(crtc);
> +
>  	mxsfb_disable_axi_clk(mxsfb);
>  	pm_runtime_put_sync(drm->dev);
>  }
Stefan Agner March 24, 2020, 10:37 a.m. UTC | #2
On 2020-03-24 00:08, Stefan Agner wrote:
> On 2020-03-09 20:52, Laurent Pinchart wrote:
>> Enable vblank handling when the CRTC is turned on and disable it when it
>> is turned off. This requires moving vblank init after the KMS pipeline
>> initialisation, otherwise drm_vblank_init() gets called with 0 CRTCs.
>>
>> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
> 
> With this patch applied I start to get system resets on my Colibri iMX7
> test device during system boot shortly after initializing mxsfb. It
> happens not on every boot, but rather often, I would say every second or
> third. From what I can tell the interrupt handling should be safe, but
> it seems that every now and then something races. Any idea what that
> could be?

Disregard this: It seems that my power supply was a bit too weak which
lead to the system reset every now and then. With enough juice, I run
now quite some boots with the complete patchset applied without seeing
any issues.

Sorry about that.

--
Stefan

> 
> --
> Stefan
> 
>> ---
>>  drivers/gpu/drm/mxsfb/mxsfb_drv.c | 15 +++++++++------
>>  drivers/gpu/drm/mxsfb/mxsfb_kms.c |  6 +++++-
>>  2 files changed, 14 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> index e324bd2a63a5..72b4f6a947a4 100644
>> --- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> +++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
>> @@ -160,12 +160,6 @@ static int mxsfb_load(struct drm_device *drm,
>> unsigned long flags)
>>
>>  	pm_runtime_enable(drm->dev);
>>
>> -	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
>> -	if (ret < 0) {
>> -		dev_err(drm->dev, "Failed to initialise vblank\n");
>> -		goto err_vblank;
>> -	}
>> -
>>  	/* Modeset init */
>>  	drm_mode_config_init(drm);
>>
>> @@ -175,6 +169,15 @@ static int mxsfb_load(struct drm_device *drm,
>> unsigned long flags)
>>  		goto err_vblank;
>>  	}
>>
>> +	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
>> +	if (ret < 0) {
>> +		dev_err(drm->dev, "Failed to initialise vblank\n");
>> +		goto err_vblank;
>> +	}
>> +
>> +	/* Start with vertical blanking interrupt reporting disabled. */
>> +	drm_crtc_vblank_off(&mxsfb->crtc);
>> +
>>  	ret = mxsfb_attach_bridge(mxsfb);
>>  	if (ret) {
>>  		dev_err(drm->dev, "Cannot connect bridge: %d\n", ret);
>> diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
>> b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
>> index ac2696c8483d..640305fb1068 100644
>> --- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
>> +++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
>> @@ -322,8 +322,10 @@ static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
>>  	dma_addr_t paddr;
>>
>>  	pm_runtime_get_sync(drm->dev);
>> -
>>  	mxsfb_enable_axi_clk(mxsfb);
>> +
>> +	drm_crtc_vblank_on(crtc);
>> +
>>  	mxsfb_crtc_mode_set_nofb(mxsfb);
>>
>>  	/* Write cur_buf as well to avoid an initial corrupt frame */
>> @@ -353,6 +355,8 @@ static void mxsfb_crtc_atomic_disable(struct drm_crtc *crtc,
>>  	}
>>  	spin_unlock_irq(&drm->event_lock);
>>
>> +	drm_crtc_vblank_off(crtc);
>> +
>>  	mxsfb_disable_axi_clk(mxsfb);
>>  	pm_runtime_put_sync(drm->dev);
>>  }
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mxsfb/mxsfb_drv.c b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
index e324bd2a63a5..72b4f6a947a4 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_drv.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_drv.c
@@ -160,12 +160,6 @@  static int mxsfb_load(struct drm_device *drm, unsigned long flags)
 
 	pm_runtime_enable(drm->dev);
 
-	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
-	if (ret < 0) {
-		dev_err(drm->dev, "Failed to initialise vblank\n");
-		goto err_vblank;
-	}
-
 	/* Modeset init */
 	drm_mode_config_init(drm);
 
@@ -175,6 +169,15 @@  static int mxsfb_load(struct drm_device *drm, unsigned long flags)
 		goto err_vblank;
 	}
 
+	ret = drm_vblank_init(drm, drm->mode_config.num_crtc);
+	if (ret < 0) {
+		dev_err(drm->dev, "Failed to initialise vblank\n");
+		goto err_vblank;
+	}
+
+	/* Start with vertical blanking interrupt reporting disabled. */
+	drm_crtc_vblank_off(&mxsfb->crtc);
+
 	ret = mxsfb_attach_bridge(mxsfb);
 	if (ret) {
 		dev_err(drm->dev, "Cannot connect bridge: %d\n", ret);
diff --git a/drivers/gpu/drm/mxsfb/mxsfb_kms.c b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
index ac2696c8483d..640305fb1068 100644
--- a/drivers/gpu/drm/mxsfb/mxsfb_kms.c
+++ b/drivers/gpu/drm/mxsfb/mxsfb_kms.c
@@ -322,8 +322,10 @@  static void mxsfb_crtc_atomic_enable(struct drm_crtc *crtc,
 	dma_addr_t paddr;
 
 	pm_runtime_get_sync(drm->dev);
-
 	mxsfb_enable_axi_clk(mxsfb);
+
+	drm_crtc_vblank_on(crtc);
+
 	mxsfb_crtc_mode_set_nofb(mxsfb);
 
 	/* Write cur_buf as well to avoid an initial corrupt frame */
@@ -353,6 +355,8 @@  static void mxsfb_crtc_atomic_disable(struct drm_crtc *crtc,
 	}
 	spin_unlock_irq(&drm->event_lock);
 
+	drm_crtc_vblank_off(crtc);
+
 	mxsfb_disable_axi_clk(mxsfb);
 	pm_runtime_put_sync(drm->dev);
 }