[v5,1/6] drm/vc4: Avoid using vrefresh==0 mode in DSI htotal math.
diff mbox

Message ID 20170718210510.12229-1-eric@anholt.net
State New
Headers show

Commit Message

Eric Anholt July 18, 2017, 9:05 p.m. UTC
The incoming mode might have a missing vrefresh field if it came from
drmModeSetCrtc(), which the kernel is supposed to calculate using
drm_mode_vrefresh().  We could either use that or the adjusted_mode's
original vrefresh value.

However, we can maintain a more exact vrefresh value (not just the
integer approximation), by scaling by the ratio of our clocks.

v2: Use math suggested by Andrzej Hajda instead.

Signed-off-by: Eric Anholt <eric@anholt.net>
---
 drivers/gpu/drm/vc4/vc4_dsi.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Boris BREZILLON Aug. 4, 2017, 8:53 a.m. UTC | #1
On Tue, 18 Jul 2017 14:05:05 -0700
Eric Anholt <eric@anholt.net> wrote:

> The incoming mode might have a missing vrefresh field if it came from
> drmModeSetCrtc(), which the kernel is supposed to calculate using
> drm_mode_vrefresh().  We could either use that or the adjusted_mode's
> original vrefresh value.
> 
> However, we can maintain a more exact vrefresh value (not just the
> integer approximation), by scaling by the ratio of our clocks.
> 
> v2: Use math suggested by Andrzej Hajda instead.
> 
> Signed-off-by: Eric Anholt <eric@anholt.net>
> ---
>  drivers/gpu/drm/vc4/vc4_dsi.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> index 629d372633e6..57213f4e3c72 100644
> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> @@ -866,7 +866,8 @@ static bool vc4_dsi_encoder_mode_fixup(struct drm_encoder *encoder,
>  	adjusted_mode->clock = pixel_clock_hz / 1000 + 1;
>  
>  	/* Given the new pixel clock, adjust HFP to keep vrefresh the same. */
> -	adjusted_mode->htotal = pixel_clock_hz / (mode->vrefresh * mode->vtotal);
> +	adjusted_mode->htotal = (pixel_clock_hz / 1000 * mode->htotal /
> +				 mode->clock);

Hm, I'm not sure I understand this. Shouldn't we have something like:

	adjusted_mode->htotal = (adjusted_mode->clock * mode->htotal) /
				mode->clock;

Is there a reason for doing '+ 1' when you calculate the adjusted
pixel clock rate but not here?

>  	adjusted_mode->hsync_end += adjusted_mode->htotal - mode->htotal;
>  	adjusted_mode->hsync_start += adjusted_mode->htotal - mode->htotal;
>
Eric Anholt Aug. 4, 2017, 9:15 p.m. UTC | #2
Boris Brezillon <boris.brezillon@free-electrons.com> writes:

> On Tue, 18 Jul 2017 14:05:05 -0700
> Eric Anholt <eric@anholt.net> wrote:
>
>> The incoming mode might have a missing vrefresh field if it came from
>> drmModeSetCrtc(), which the kernel is supposed to calculate using
>> drm_mode_vrefresh().  We could either use that or the adjusted_mode's
>> original vrefresh value.
>> 
>> However, we can maintain a more exact vrefresh value (not just the
>> integer approximation), by scaling by the ratio of our clocks.
>> 
>> v2: Use math suggested by Andrzej Hajda instead.
>> 
>> Signed-off-by: Eric Anholt <eric@anholt.net>
>> ---
>>  drivers/gpu/drm/vc4/vc4_dsi.c | 3 ++-
>>  1 file changed, 2 insertions(+), 1 deletion(-)
>> 
>> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
>> index 629d372633e6..57213f4e3c72 100644
>> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
>> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
>> @@ -866,7 +866,8 @@ static bool vc4_dsi_encoder_mode_fixup(struct drm_encoder *encoder,
>>  	adjusted_mode->clock = pixel_clock_hz / 1000 + 1;
>>  
>>  	/* Given the new pixel clock, adjust HFP to keep vrefresh the same. */
>> -	adjusted_mode->htotal = pixel_clock_hz / (mode->vrefresh * mode->vtotal);
>> +	adjusted_mode->htotal = (pixel_clock_hz / 1000 * mode->htotal /
>> +				 mode->clock);
>
> Hm, I'm not sure I understand this. Shouldn't we have something like:
>
> 	adjusted_mode->htotal = (adjusted_mode->clock * mode->htotal) /
> 				mode->clock;
>
> Is there a reason for doing '+ 1' when you calculate the adjusted
> pixel clock rate but not here?

We're actually expecting to get within epsilon of pixel_clock_hz, but we
have to bump our clk_set_rate() to a higher value because the clock
driver will give you a bad divider if you ask for anything less than the
rate it can provide.

How about I don't increment the adjusted_mode->clock (since it'll be
userspace visible I think), and instead move that and the "Round up"
comment to the clk_set_rate()?
Boris BREZILLON Aug. 9, 2017, 2:42 p.m. UTC | #3
Le Fri, 04 Aug 2017 14:15:56 -0700,
Eric Anholt <eric@anholt.net> a écrit :

> Boris Brezillon <boris.brezillon@free-electrons.com> writes:
> 
> > On Tue, 18 Jul 2017 14:05:05 -0700
> > Eric Anholt <eric@anholt.net> wrote:
> >  
> >> The incoming mode might have a missing vrefresh field if it came from
> >> drmModeSetCrtc(), which the kernel is supposed to calculate using
> >> drm_mode_vrefresh().  We could either use that or the adjusted_mode's
> >> original vrefresh value.
> >> 
> >> However, we can maintain a more exact vrefresh value (not just the
> >> integer approximation), by scaling by the ratio of our clocks.
> >> 
> >> v2: Use math suggested by Andrzej Hajda instead.
> >> 
> >> Signed-off-by: Eric Anholt <eric@anholt.net>
> >> ---
> >>  drivers/gpu/drm/vc4/vc4_dsi.c | 3 ++-
> >>  1 file changed, 2 insertions(+), 1 deletion(-)
> >> 
> >> diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
> >> index 629d372633e6..57213f4e3c72 100644
> >> --- a/drivers/gpu/drm/vc4/vc4_dsi.c
> >> +++ b/drivers/gpu/drm/vc4/vc4_dsi.c
> >> @@ -866,7 +866,8 @@ static bool vc4_dsi_encoder_mode_fixup(struct drm_encoder *encoder,
> >>  	adjusted_mode->clock = pixel_clock_hz / 1000 + 1;
> >>  
> >>  	/* Given the new pixel clock, adjust HFP to keep vrefresh the same. */
> >> -	adjusted_mode->htotal = pixel_clock_hz / (mode->vrefresh * mode->vtotal);
> >> +	adjusted_mode->htotal = (pixel_clock_hz / 1000 * mode->htotal /
> >> +				 mode->clock);  
> >
> > Hm, I'm not sure I understand this. Shouldn't we have something like:
> >
> > 	adjusted_mode->htotal = (adjusted_mode->clock * mode->htotal) /
> > 				mode->clock;
> >
> > Is there a reason for doing '+ 1' when you calculate the adjusted
> > pixel clock rate but not here?  
> 
> We're actually expecting to get within epsilon of pixel_clock_hz, but we
> have to bump our clk_set_rate() to a higher value because the clock
> driver will give you a bad divider if you ask for anything less than the
> rate it can provide.
> 
> How about I don't increment the adjusted_mode->clock (since it'll be
> userspace visible I think), and instead move that and the "Round up"
> comment to the clk_set_rate()?

Sounds good.

Patch
diff mbox

diff --git a/drivers/gpu/drm/vc4/vc4_dsi.c b/drivers/gpu/drm/vc4/vc4_dsi.c
index 629d372633e6..57213f4e3c72 100644
--- a/drivers/gpu/drm/vc4/vc4_dsi.c
+++ b/drivers/gpu/drm/vc4/vc4_dsi.c
@@ -866,7 +866,8 @@  static bool vc4_dsi_encoder_mode_fixup(struct drm_encoder *encoder,
 	adjusted_mode->clock = pixel_clock_hz / 1000 + 1;
 
 	/* Given the new pixel clock, adjust HFP to keep vrefresh the same. */
-	adjusted_mode->htotal = pixel_clock_hz / (mode->vrefresh * mode->vtotal);
+	adjusted_mode->htotal = (pixel_clock_hz / 1000 * mode->htotal /
+				 mode->clock);
 	adjusted_mode->hsync_end += adjusted_mode->htotal - mode->htotal;
 	adjusted_mode->hsync_start += adjusted_mode->htotal - mode->htotal;