diff mbox series

[01/12] drm: Nuke mode->hsync

Message ID 20200219203544.31013-2-ville.syrjala@linux.intel.com (mailing list archive)
State New, archived
Headers show
Series drm: Put drm_display_mode on diet | expand

Commit Message

Ville Syrjälä Feb. 19, 2020, 8:35 p.m. UTC
From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Let's just calculate the hsync rate on demand. No point in wasting
space storing it and risking the cached value getting out of sync
with reality.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_modes.c                  | 14 ++------------
 drivers/gpu/drm/i915/display/intel_display.c |  1 -
 include/drm/drm_modes.h                      | 10 ----------
 3 files changed, 2 insertions(+), 23 deletions(-)

Comments

Emil Velikov Feb. 20, 2020, 10:55 a.m. UTC | #1
On Wed, 19 Feb 2020 at 20:35, Ville Syrjala
<ville.syrjala@linux.intel.com> wrote:
>
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>
> Let's just calculate the hsync rate on demand. No point in wasting
> space storing it and risking the cached value getting out of sync
> with reality.
>
> Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> ---
>  drivers/gpu/drm/drm_modes.c                  | 14 ++------------
>  drivers/gpu/drm/i915/display/intel_display.c |  1 -
>  include/drm/drm_modes.h                      | 10 ----------
>  3 files changed, 2 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> index d4d64518e11b..fe7e872a6239 100644
> --- a/drivers/gpu/drm/drm_modes.c
> +++ b/drivers/gpu/drm/drm_modes.c
> @@ -752,24 +752,14 @@ EXPORT_SYMBOL(drm_mode_set_name);
>   * @mode: mode
>   *
>   * Returns:
> - * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
> - * value first if it is not yet set.
> + * @modes's hsync rate in kHz, rounded to the nearest integer
>   */
>  int drm_mode_hsync(const struct drm_display_mode *mode)
>  {
> -       unsigned int calc_val;
> -
> -       if (mode->hsync)
> -               return mode->hsync;
> -
>         if (mode->htotal <= 0)
>                 return 0;
>
> -       calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
> -       calc_val += 500;                                /* round to 1000Hz */
> -       calc_val /= 1000;                               /* truncate to kHz */
> -
> -       return calc_val;
> +       return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
>  }
>  EXPORT_SYMBOL(drm_mode_hsync);
>
> diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> index ee7d54ccd3e6..fab914819489 100644
> --- a/drivers/gpu/drm/i915/display/intel_display.c
> +++ b/drivers/gpu/drm/i915/display/intel_display.c
> @@ -8867,7 +8867,6 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode,
>
>         mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
>
> -       mode->hsync = drm_mode_hsync(mode);

With this gone, we could make drm_mode_hsync() internal and move it to
drm_foo_internal.h.
Making it obvious that drivers, should be copy/pasting it.

Regardless, the patch is:
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>

-Emil
Ville Syrjälä Feb. 21, 2020, 4:04 p.m. UTC | #2
On Thu, Feb 20, 2020 at 10:55:18AM +0000, Emil Velikov wrote:
> On Wed, 19 Feb 2020 at 20:35, Ville Syrjala
> <ville.syrjala@linux.intel.com> wrote:
> >
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >
> > Let's just calculate the hsync rate on demand. No point in wasting
> > space storing it and risking the cached value getting out of sync
> > with reality.
> >
> > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > ---
> >  drivers/gpu/drm/drm_modes.c                  | 14 ++------------
> >  drivers/gpu/drm/i915/display/intel_display.c |  1 -
> >  include/drm/drm_modes.h                      | 10 ----------
> >  3 files changed, 2 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> > index d4d64518e11b..fe7e872a6239 100644
> > --- a/drivers/gpu/drm/drm_modes.c
> > +++ b/drivers/gpu/drm/drm_modes.c
> > @@ -752,24 +752,14 @@ EXPORT_SYMBOL(drm_mode_set_name);
> >   * @mode: mode
> >   *
> >   * Returns:
> > - * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
> > - * value first if it is not yet set.
> > + * @modes's hsync rate in kHz, rounded to the nearest integer
> >   */
> >  int drm_mode_hsync(const struct drm_display_mode *mode)
> >  {
> > -       unsigned int calc_val;
> > -
> > -       if (mode->hsync)
> > -               return mode->hsync;
> > -
> >         if (mode->htotal <= 0)
> >                 return 0;
> >
> > -       calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
> > -       calc_val += 500;                                /* round to 1000Hz */
> > -       calc_val /= 1000;                               /* truncate to kHz */
> > -
> > -       return calc_val;
> > +       return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
> >  }
> >  EXPORT_SYMBOL(drm_mode_hsync);
> >
> > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> > index ee7d54ccd3e6..fab914819489 100644
> > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > @@ -8867,7 +8867,6 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode,
> >
> >         mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
> >
> > -       mode->hsync = drm_mode_hsync(mode);
> 
> With this gone, we could make drm_mode_hsync() internal and move it to
> drm_foo_internal.h.
> Making it obvious that drivers, should be copy/pasting it.

Hmm. Looks like drm_edid.c is the only user left actually. Should
probably just move it there and make it static.

> 
> Regardless, the patch is:
> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
> 
> -Emil
Emil Velikov Feb. 21, 2020, 4:55 p.m. UTC | #3
On Fri, 21 Feb 2020 at 16:04, Ville Syrjälä
<ville.syrjala@linux.intel.com> wrote:
>
> On Thu, Feb 20, 2020 at 10:55:18AM +0000, Emil Velikov wrote:
> > On Wed, 19 Feb 2020 at 20:35, Ville Syrjala
> > <ville.syrjala@linux.intel.com> wrote:
> > >
> > > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > >
> > > Let's just calculate the hsync rate on demand. No point in wasting
> > > space storing it and risking the cached value getting out of sync
> > > with reality.
> > >
> > > Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > > ---
> > >  drivers/gpu/drm/drm_modes.c                  | 14 ++------------
> > >  drivers/gpu/drm/i915/display/intel_display.c |  1 -
> > >  include/drm/drm_modes.h                      | 10 ----------
> > >  3 files changed, 2 insertions(+), 23 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
> > > index d4d64518e11b..fe7e872a6239 100644
> > > --- a/drivers/gpu/drm/drm_modes.c
> > > +++ b/drivers/gpu/drm/drm_modes.c
> > > @@ -752,24 +752,14 @@ EXPORT_SYMBOL(drm_mode_set_name);
> > >   * @mode: mode
> > >   *
> > >   * Returns:
> > > - * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
> > > - * value first if it is not yet set.
> > > + * @modes's hsync rate in kHz, rounded to the nearest integer
> > >   */
> > >  int drm_mode_hsync(const struct drm_display_mode *mode)
> > >  {
> > > -       unsigned int calc_val;
> > > -
> > > -       if (mode->hsync)
> > > -               return mode->hsync;
> > > -
> > >         if (mode->htotal <= 0)
> > >                 return 0;
> > >
> > > -       calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
> > > -       calc_val += 500;                                /* round to 1000Hz */
> > > -       calc_val /= 1000;                               /* truncate to kHz */
> > > -
> > > -       return calc_val;
> > > +       return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
> > >  }
> > >  EXPORT_SYMBOL(drm_mode_hsync);
> > >
> > > diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
> > > index ee7d54ccd3e6..fab914819489 100644
> > > --- a/drivers/gpu/drm/i915/display/intel_display.c
> > > +++ b/drivers/gpu/drm/i915/display/intel_display.c
> > > @@ -8867,7 +8867,6 @@ void intel_mode_from_pipe_config(struct drm_display_mode *mode,
> > >
> > >         mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
> > >
> > > -       mode->hsync = drm_mode_hsync(mode);
> >
> > With this gone, we could make drm_mode_hsync() internal and move it to
> > drm_foo_internal.h.
> > Making it obvious that drivers, should be copy/pasting it.
>
> Hmm. Looks like drm_edid.c is the only user left actually. Should
> probably just move it there and make it static.
>
That also works. Feel free to make that a follow-up patch if you prefer.

-Emil
diff mbox series

Patch

diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c
index d4d64518e11b..fe7e872a6239 100644
--- a/drivers/gpu/drm/drm_modes.c
+++ b/drivers/gpu/drm/drm_modes.c
@@ -752,24 +752,14 @@  EXPORT_SYMBOL(drm_mode_set_name);
  * @mode: mode
  *
  * Returns:
- * @modes's hsync rate in kHz, rounded to the nearest integer. Calculates the
- * value first if it is not yet set.
+ * @modes's hsync rate in kHz, rounded to the nearest integer
  */
 int drm_mode_hsync(const struct drm_display_mode *mode)
 {
-	unsigned int calc_val;
-
-	if (mode->hsync)
-		return mode->hsync;
-
 	if (mode->htotal <= 0)
 		return 0;
 
-	calc_val = (mode->clock * 1000) / mode->htotal; /* hsync in Hz */
-	calc_val += 500;				/* round to 1000Hz */
-	calc_val /= 1000;				/* truncate to kHz */
-
-	return calc_val;
+	return DIV_ROUND_CLOSEST(mode->clock, mode->htotal);
 }
 EXPORT_SYMBOL(drm_mode_hsync);
 
diff --git a/drivers/gpu/drm/i915/display/intel_display.c b/drivers/gpu/drm/i915/display/intel_display.c
index ee7d54ccd3e6..fab914819489 100644
--- a/drivers/gpu/drm/i915/display/intel_display.c
+++ b/drivers/gpu/drm/i915/display/intel_display.c
@@ -8867,7 +8867,6 @@  void intel_mode_from_pipe_config(struct drm_display_mode *mode,
 
 	mode->clock = pipe_config->hw.adjusted_mode.crtc_clock;
 
-	mode->hsync = drm_mode_hsync(mode);
 	mode->vrefresh = drm_mode_vrefresh(mode);
 	drm_mode_set_name(mode);
 }
diff --git a/include/drm/drm_modes.h b/include/drm/drm_modes.h
index 99134d4f35eb..7dab7f172431 100644
--- a/include/drm/drm_modes.h
+++ b/include/drm/drm_modes.h
@@ -390,16 +390,6 @@  struct drm_display_mode {
 	 */
 	int vrefresh;
 
-	/**
-	 * @hsync:
-	 *
-	 * Horizontal refresh rate, for debug output in human readable form. Not
-	 * used in a functional way.
-	 *
-	 * This value is in kHz.
-	 */
-	int hsync;
-
 	/**
 	 * @picture_aspect_ratio:
 	 *