All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
@ 2015-10-08  8:43 ville.syrjala
  2015-10-08  8:43 ` [PATCH 2/3] drm/edid: Round to closest when computing the CEA/HDMI alternate clock ville.syrjala
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: ville.syrjala @ 2015-10-08  8:43 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

EDID detailed timings have a resolution of 10kHz for the pixel clock, so
they can't represent certain CEA/HDMI modes accurately. If we see a mode
coming in via detailed timings which otherwise matches one of the
CEA/HDMI modes except the clock is just a bit off, let's assume that the
intention was for that mode to be one of the CEA/HDMI modes and go ahead
and fix up the clock to match the CEA/HDMI spec exactly (well, as close
as we can get with the 1 kHz resolution we use).

This should help code that's looking for an exact clock match (eg. i915
audio N/CTS setup).

Cc: Adam Jackson <ajax@redhat.com>
Cc: Clint Taylor <clinton.a.taylor@intel.com>
Cc: Libin Yang <libin.yang@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_edid.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index d895556..977915c 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2418,6 +2418,8 @@ add_cvt_modes(struct drm_connector *connector, struct edid *edid)
 	return closure.modes;
 }
 
+static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode);
+
 static void
 do_detailed_mode(struct detailed_timing *timing, void *c)
 {
@@ -2434,6 +2436,13 @@ do_detailed_mode(struct detailed_timing *timing, void *c)
 		if (closure->preferred)
 			newmode->type |= DRM_MODE_TYPE_PREFERRED;
 
+		/*
+		 * Detailed modes are limited to 10kHz pixel clock resolution,
+		 * so fix up anything that looks like CEA/HDMI mode, but the clock
+		 * is just slightly off.
+		 */
+		fixup_detailed_cea_mode_clock(newmode);
+
 		drm_mode_probed_add(closure->connector, newmode);
 		closure->modes++;
 		closure->preferred = 0;
@@ -3103,6 +3112,45 @@ add_cea_modes(struct drm_connector *connector, struct edid *edid)
 	return modes;
 }
 
+static void fixup_detailed_cea_mode_clock(struct drm_display_mode *mode)
+{
+	const struct drm_display_mode *cea_mode;
+	int clock1, clock2, clock;
+	u8 mode_idx;
+	const char *type;
+
+	mode_idx = drm_match_cea_mode(mode) - 1;
+	if (mode_idx < ARRAY_SIZE(edid_cea_modes)) {
+		type = "CEA";
+		cea_mode = &edid_cea_modes[mode_idx];
+		clock1 = cea_mode->clock;
+		clock2 = cea_mode_alternate_clock(cea_mode);
+	} else {
+		mode_idx = drm_match_hdmi_mode(mode) - 1;
+		if (mode_idx < ARRAY_SIZE(edid_4k_modes)) {
+			type = "HDMI";
+			cea_mode = &edid_4k_modes[mode_idx];
+			clock1 = cea_mode->clock;
+			clock2 = hdmi_mode_alternate_clock(cea_mode);
+		} else {
+			return;
+		}
+	}
+
+	/* pick whichever is closest */
+	if (abs(mode->clock - clock1) < abs(mode->clock - clock2))
+		clock = clock1;
+	else
+		clock = clock2;
+
+	if (mode->clock == clock)
+		return;
+
+	DRM_DEBUG("detailed mode matches %s VIC %d, adjusting clock %d -> %d\n",
+		  type, mode_idx + 1, mode->clock, clock);
+	mode->clock = clock;
+}
+
 static void
 parse_hdmi_vsdb(struct drm_connector *connector, const u8 *db)
 {
-- 
2.4.9

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/3] drm/edid: Round to closest when computing the CEA/HDMI alternate clock
  2015-10-08  8:43 [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings ville.syrjala
@ 2015-10-08  8:43 ` ville.syrjala
  2015-10-08  8:43 ` [PATCH 3/3] drm/i915: Use round to closest when computing the CEA 1.001 pixel clocks ville.syrjala
  2015-10-08 16:22 ` [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings Adam Jackson
  2 siblings, 0 replies; 8+ messages in thread
From: ville.syrjala @ 2015-10-08  8:43 UTC (permalink / raw)
  To: dri-devel; +Cc: Libin Yang, intel-gfx

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

Rounding to the closest kHz seems like the better option that round
down or up when computing the alternate clock for CEA/HDMI modes.
It'll give us a slightly more accurate clock in some cases.

Not sure why I went for the down+up approach originally. Perhaps
I was thinking we can go back and forth betwen the two frequencies
without introducing errors, but round to closest still maintains
that property.

Cc: Adam Jackson <ajax@redhat.com>
Cc: Clint Taylor <clinton.a.taylor@intel.com>
Cc: Libin Yang <libin.yang@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/drm_edid.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c
index 977915c..d5d2c03 100644
--- a/drivers/gpu/drm/drm_edid.c
+++ b/drivers/gpu/drm/drm_edid.c
@@ -2538,9 +2538,9 @@ cea_mode_alternate_clock(const struct drm_display_mode *cea_mode)
 	 * and the 60Hz variant otherwise.
 	 */
 	if (cea_mode->vdisplay == 240 || cea_mode->vdisplay == 480)
-		clock = clock * 1001 / 1000;
+		clock = DIV_ROUND_CLOSEST(clock * 1001, 1000);
 	else
-		clock = DIV_ROUND_UP(clock * 1000, 1001);
+		clock = DIV_ROUND_CLOSEST(clock * 1000, 1001);
 
 	return clock;
 }
-- 
2.4.9

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/3] drm/i915: Use round to closest when computing the CEA 1.001 pixel clocks
  2015-10-08  8:43 [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings ville.syrjala
  2015-10-08  8:43 ` [PATCH 2/3] drm/edid: Round to closest when computing the CEA/HDMI alternate clock ville.syrjala
@ 2015-10-08  8:43 ` ville.syrjala
  2015-10-08 16:22 ` [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings Adam Jackson
  2 siblings, 0 replies; 8+ messages in thread
From: ville.syrjala @ 2015-10-08  8:43 UTC (permalink / raw)
  To: dri-devel; +Cc: intel-gfx

From: Ville Syrjälä <ville.syrjala@linux.intel.com>

drm_edid.c now computes the alternate CEA clocks using
DIV_ROUND_CLOSEST(), so follow suit in the N/CTS setup to make sure we
pick the right setting for the mode.

Unfortunately we can't actually use DIV_ROUND_CLOSEST() here due to the
({}) construct used, so just stick in raw numbers instead.

Cc: Clint Taylor <clinton.a.taylor@intel.com>
Cc: Libin Yang <libin.yang@intel.com>
Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
---
 drivers/gpu/drm/i915/intel_audio.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_audio.c b/drivers/gpu/drm/i915/intel_audio.c
index 56c2f54..4dccd9b 100644
--- a/drivers/gpu/drm/i915/intel_audio.c
+++ b/drivers/gpu/drm/i915/intel_audio.c
@@ -61,21 +61,21 @@ static const struct {
 	int clock;
 	u32 config;
 } hdmi_audio_clock[] = {
-	{ DIV_ROUND_UP(25200 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
+	{ 25175, AUD_CONFIG_PIXEL_CLOCK_HDMI_25175 },
 	{ 25200, AUD_CONFIG_PIXEL_CLOCK_HDMI_25200 }, /* default per bspec */
 	{ 27000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27000 },
-	{ 27000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
+	{ 27027, AUD_CONFIG_PIXEL_CLOCK_HDMI_27027 },
 	{ 54000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54000 },
-	{ 54000 * 1001 / 1000, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
-	{ DIV_ROUND_UP(74250 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
+	{ 54054, AUD_CONFIG_PIXEL_CLOCK_HDMI_54054 },
+	{ 74176, AUD_CONFIG_PIXEL_CLOCK_HDMI_74176 },
 	{ 74250, AUD_CONFIG_PIXEL_CLOCK_HDMI_74250 },
-	{ DIV_ROUND_UP(148500 * 1000, 1001), AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
+	{ 148352, AUD_CONFIG_PIXEL_CLOCK_HDMI_148352 },
 	{ 148500, AUD_CONFIG_PIXEL_CLOCK_HDMI_148500 },
 };
 
 /* HDMI N/CTS table */
 #define TMDS_297M 297000
-#define TMDS_296M DIV_ROUND_UP(297000 * 1000, 1001)
+#define TMDS_296M 296703
 static const struct {
 	int sample_rate;
 	int clock;
-- 
2.4.9

_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
  2015-10-08  8:43 [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings ville.syrjala
  2015-10-08  8:43 ` [PATCH 2/3] drm/edid: Round to closest when computing the CEA/HDMI alternate clock ville.syrjala
  2015-10-08  8:43 ` [PATCH 3/3] drm/i915: Use round to closest when computing the CEA 1.001 pixel clocks ville.syrjala
@ 2015-10-08 16:22 ` Adam Jackson
  2015-10-08 16:55   ` Daniel Vetter
  2 siblings, 1 reply; 8+ messages in thread
From: Adam Jackson @ 2015-10-08 16:22 UTC (permalink / raw)
  To: ville.syrjala, dri-devel; +Cc: Libin Yang, intel-gfx

On Thu, 2015-10-08 at 11:43 +0300, ville.syrjala@linux.intel.com wrote:
> From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> 
> EDID detailed timings have a resolution of 10kHz for the pixel clock, so
> they can't represent certain CEA/HDMI modes accurately. If we see a mode
> coming in via detailed timings which otherwise matches one of the
> CEA/HDMI modes except the clock is just a bit off, let's assume that the
> intention was for that mode to be one of the CEA/HDMI modes and go ahead
> and fix up the clock to match the CEA/HDMI spec exactly (well, as close
> as we can get with the 1 kHz resolution we use).
> 
> This should help code that's looking for an exact clock match (eg. i915
> audio N/CTS setup).

Looks like a sane set of changes.  Series is:

Reviewed-by: Adam Jackson <ajax@redhat.com>

- ajax
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
  2015-10-08 16:22 ` [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings Adam Jackson
@ 2015-10-08 16:55   ` Daniel Vetter
  2015-10-09 10:54     ` Jani Nikula
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2015-10-08 16:55 UTC (permalink / raw)
  To: Adam Jackson; +Cc: intel-gfx, dri-devel

On Thu, Oct 08, 2015 at 12:22:31PM -0400, Adam Jackson wrote:
> On Thu, 2015-10-08 at 11:43 +0300, ville.syrjala@linux.intel.com wrote:
> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> > 
> > EDID detailed timings have a resolution of 10kHz for the pixel clock, so
> > they can't represent certain CEA/HDMI modes accurately. If we see a mode
> > coming in via detailed timings which otherwise matches one of the
> > CEA/HDMI modes except the clock is just a bit off, let's assume that the
> > intention was for that mode to be one of the CEA/HDMI modes and go ahead
> > and fix up the clock to match the CEA/HDMI spec exactly (well, as close
> > as we can get with the 1 kHz resolution we use).
> > 
> > This should help code that's looking for an exact clock match (eg. i915
> > audio N/CTS setup).
> 
> Looks like a sane set of changes.  Series is:
> 
> Reviewed-by: Adam Jackson <ajax@redhat.com>

Merged the first two patches to drm-misc (the later one has conflicts with
the lack of drm-intel-next, so can pull it in only after a rebase).

Thanks, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
  2015-10-08 16:55   ` Daniel Vetter
@ 2015-10-09 10:54     ` Jani Nikula
  2015-10-19 15:56       ` [Intel-gfx] " Daniel Vetter
  0 siblings, 1 reply; 8+ messages in thread
From: Jani Nikula @ 2015-10-09 10:54 UTC (permalink / raw)
  To: Daniel Vetter, Adam Jackson; +Cc: intel-gfx, dri-devel

On Thu, 08 Oct 2015, Daniel Vetter <daniel@ffwll.ch> wrote:
> On Thu, Oct 08, 2015 at 12:22:31PM -0400, Adam Jackson wrote:
>> On Thu, 2015-10-08 at 11:43 +0300, ville.syrjala@linux.intel.com wrote:
>> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> > 
>> > EDID detailed timings have a resolution of 10kHz for the pixel clock, so
>> > they can't represent certain CEA/HDMI modes accurately. If we see a mode
>> > coming in via detailed timings which otherwise matches one of the
>> > CEA/HDMI modes except the clock is just a bit off, let's assume that the
>> > intention was for that mode to be one of the CEA/HDMI modes and go ahead
>> > and fix up the clock to match the CEA/HDMI spec exactly (well, as close
>> > as we can get with the 1 kHz resolution we use).
>> > 
>> > This should help code that's looking for an exact clock match (eg. i915
>> > audio N/CTS setup).
>> 
>> Looks like a sane set of changes.  Series is:
>> 
>> Reviewed-by: Adam Jackson <ajax@redhat.com>
>
> Merged the first two patches to drm-misc (the later one has conflicts with
> the lack of drm-intel-next, so can pull it in only after a rebase).

This is needed in v4.3.

BR,
Jani.

>
> Thanks, Daniel
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [Intel-gfx] [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
  2015-10-09 10:54     ` Jani Nikula
@ 2015-10-19 15:56       ` Daniel Vetter
  2015-10-20  6:31         ` Jani Nikula
  0 siblings, 1 reply; 8+ messages in thread
From: Daniel Vetter @ 2015-10-19 15:56 UTC (permalink / raw)
  To: Jani Nikula; +Cc: intel-gfx, dri-devel

On Fri, Oct 09, 2015 at 01:54:58PM +0300, Jani Nikula wrote:
> On Thu, 08 Oct 2015, Daniel Vetter <daniel@ffwll.ch> wrote:
> > On Thu, Oct 08, 2015 at 12:22:31PM -0400, Adam Jackson wrote:
> >> On Thu, 2015-10-08 at 11:43 +0300, ville.syrjala@linux.intel.com wrote:
> >> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
> >> > 
> >> > EDID detailed timings have a resolution of 10kHz for the pixel clock, so
> >> > they can't represent certain CEA/HDMI modes accurately. If we see a mode
> >> > coming in via detailed timings which otherwise matches one of the
> >> > CEA/HDMI modes except the clock is just a bit off, let's assume that the
> >> > intention was for that mode to be one of the CEA/HDMI modes and go ahead
> >> > and fix up the clock to match the CEA/HDMI spec exactly (well, as close
> >> > as we can get with the 1 kHz resolution we use).
> >> > 
> >> > This should help code that's looking for an exact clock match (eg. i915
> >> > audio N/CTS setup).
> >> 
> >> Looks like a sane set of changes.  Series is:
> >> 
> >> Reviewed-by: Adam Jackson <ajax@redhat.com>
> >
> > Merged the first two patches to drm-misc (the later one has conflicts with
> > the lack of drm-intel-next, so can pull it in only after a rebase).
> 
> This is needed in v4.3.

Ok, after first dropping them I now reapplied them again for 4.4.
Hopefully we're converging on this here now wrt maintainer fumbles ;-)

Thanks, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings
  2015-10-19 15:56       ` [Intel-gfx] " Daniel Vetter
@ 2015-10-20  6:31         ` Jani Nikula
  0 siblings, 0 replies; 8+ messages in thread
From: Jani Nikula @ 2015-10-20  6:31 UTC (permalink / raw)
  To: Daniel Vetter; +Cc: intel-gfx, dri-devel

On Mon, 19 Oct 2015, Daniel Vetter <daniel@ffwll.ch> wrote:
> On Fri, Oct 09, 2015 at 01:54:58PM +0300, Jani Nikula wrote:
>> On Thu, 08 Oct 2015, Daniel Vetter <daniel@ffwll.ch> wrote:
>> > On Thu, Oct 08, 2015 at 12:22:31PM -0400, Adam Jackson wrote:
>> >> On Thu, 2015-10-08 at 11:43 +0300, ville.syrjala@linux.intel.com wrote:
>> >> > From: Ville Syrjälä <ville.syrjala@linux.intel.com>
>> >> > 
>> >> > EDID detailed timings have a resolution of 10kHz for the pixel clock, so
>> >> > they can't represent certain CEA/HDMI modes accurately. If we see a mode
>> >> > coming in via detailed timings which otherwise matches one of the
>> >> > CEA/HDMI modes except the clock is just a bit off, let's assume that the
>> >> > intention was for that mode to be one of the CEA/HDMI modes and go ahead
>> >> > and fix up the clock to match the CEA/HDMI spec exactly (well, as close
>> >> > as we can get with the 1 kHz resolution we use).
>> >> > 
>> >> > This should help code that's looking for an exact clock match (eg. i915
>> >> > audio N/CTS setup).
>> >> 
>> >> Looks like a sane set of changes.  Series is:
>> >> 
>> >> Reviewed-by: Adam Jackson <ajax@redhat.com>
>> >
>> > Merged the first two patches to drm-misc (the later one has conflicts with
>> > the lack of drm-intel-next, so can pull it in only after a rebase).
>> 
>> This is needed in v4.3.
>
> Ok, after first dropping them I now reapplied them again for 4.4.
> Hopefully we're converging on this here now wrt maintainer fumbles ;-)

Yeah, apologies, my bad. I thought we needed them to fix an issue in our
4k HDMI audio, but we haven't introduced the issue to v4.3 yet.

BR,
Jani.


>
> Thanks, Daniel
> -- 
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch

-- 
Jani Nikula, Intel Open Source Technology Center
_______________________________________________
Intel-gfx mailing list
Intel-gfx@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2015-10-20  6:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-08  8:43 [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings ville.syrjala
2015-10-08  8:43 ` [PATCH 2/3] drm/edid: Round to closest when computing the CEA/HDMI alternate clock ville.syrjala
2015-10-08  8:43 ` [PATCH 3/3] drm/i915: Use round to closest when computing the CEA 1.001 pixel clocks ville.syrjala
2015-10-08 16:22 ` [PATCH 1/3] drm/edid: Fix up clock for CEA/HDMI modes specified via detailed timings Adam Jackson
2015-10-08 16:55   ` Daniel Vetter
2015-10-09 10:54     ` Jani Nikula
2015-10-19 15:56       ` [Intel-gfx] " Daniel Vetter
2015-10-20  6:31         ` Jani Nikula

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.