Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1739598

[PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS clk parent

From Chen-Yu Tsai <wens@csie.org>
Newsgroups linux.kernel
Subject [PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS clk parent
Date 2017-09-26 09:10 +0200
Message-ID <utSag-1rM-57@gated-at.bofh.it> (permalink)
References <utSae-1rM-9@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Allwinner SoCs typically have two PLLs reserved for video related usage.
At the moment we only support using the first one to feed the HDMI
transmitter block's TMDS clock.

Let the HDMI encoder's TMDS clock go through all of its parents when
calculating possible clock rates. This allows usage of the second video
PLL as its parent.

Note that this does not handle conflicting pixel clocks. It is entirely
possible to have an LCD panel use one pixel clock rate, only to be
overridden by the HDMI transmitter's clock rate request when the second
display pipeline is enabled.

This should be handled by having all the clock drivers honor clock rate
ranges, and have the consumers use clk_set_rate_min/clk_set_rate_max.

Signed-off-by: Chen-Yu Tsai <wens@csie.org>
---
 drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c | 53 ++++++++++++++++-------------
 1 file changed, 29 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c
index 5cf2527bffc8..e8d4c311b80d 100644
--- a/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c
+++ b/drivers/gpu/drm/sun4i/sun4i_hdmi_tmds_clk.c
@@ -67,11 +67,11 @@ static unsigned long sun4i_tmds_calc_divider(unsigned long rate,
 static int sun4i_tmds_determine_rate(struct clk_hw *hw,
 				     struct clk_rate_request *req)
 {
-	struct clk_hw *parent;
+	struct clk_hw *parent = NULL;
 	unsigned long best_parent = 0;
 	unsigned long rate = req->rate;
 	int best_div = 1, best_half = 1;
-	int i, j;
+	int i, j, p;
 
 	/*
 	 * We only consider PLL3, since the TCON is very likely to be
@@ -79,32 +79,37 @@ static int sun4i_tmds_determine_rate(struct clk_hw *hw,
 	 * clock, so we should not need to do anything.
 	 */
 
-	parent = clk_hw_get_parent_by_index(hw, 0);
-	if (!parent)
-		return -EINVAL;
-
-	for (i = 1; i < 3; i++) {
-		for (j = 1; j < 16; j++) {
-			unsigned long ideal = rate * i * j;
-			unsigned long rounded;
-
-			rounded = clk_hw_round_rate(parent, ideal);
-
-			if (rounded == ideal) {
-				best_parent = rounded;
-				best_half = i;
-				best_div = j;
-				goto out;
-			}
-
-			if (abs(rate - rounded / i) <
-			    abs(rate - best_parent / best_div)) {
-				best_parent = rounded;
-				best_div = i;
+	for (p = 0; p < clk_hw_get_num_parents(hw); p++) {
+		parent = clk_hw_get_parent_by_index(hw, p);
+		if (!parent)
+			continue;
+
+		for (i = 1; i < 3; i++) {
+			for (j = 1; j < 16; j++) {
+				unsigned long ideal = rate * i * j;
+				unsigned long rounded;
+
+				rounded = clk_hw_round_rate(parent, ideal);
+
+				if (rounded == ideal) {
+					best_parent = rounded;
+					best_half = i;
+					best_div = j;
+					goto out;
+				}
+
+				if (abs(rate - rounded / i) <
+				    abs(rate - best_parent / best_div)) {
+					best_parent = rounded;
+					best_div = i;
+				}
 			}
 		}
 	}
 
+	if (!parent)
+		return -EINVAL;
+
 out:
 	req->rate = best_parent / best_half / best_div;
 	req->best_parent_rate = best_parent;
-- 
2.14.1

Back to linux.kernel | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

[PATCH v2 00/13] drm/sun4i: hdmi: Support HDMI controller on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 07/13] dt-bindings: display: sun4i: Add binding for A31 HDMI controller Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to avoid name collision Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to  avoid name collision Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 11:40 +0200
      Re: [PATCH v2 02/13] clk: sunxi-ng: sun6i: Rename HDMI DDC clock to  avoid name collision Chen-Yu Tsai <wens@csie.org> - 2017-09-27 05:50 +0200
  [PATCH v2 09/13] drm/sun4i: hdmi: Add support for controller hardware variants Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 09/13] drm/sun4i: hdmi: Add support for controller  hardware variants Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:10 +0200
  [PATCH v2 13/13] ARM: dts: sun6i: Enable HDMI support on some A31/A31s devices Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 08/13] regmap: add iopoll-like polling macro for regmap_field Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
  [PATCH v2 10/13] drm/sun4i: hdmi: Add A31 specific DDC register definitions Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 10/13] drm/sun4i: hdmi: Add A31 specific DDC register  definitions Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:10 +0200
  [PATCH v2 04/13] drm/sun4i: hdmi: Disable clks in bind function error path and unbind function Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 04/13] drm/sun4i: hdmi: Disable clks in bind function  error path and unbind function Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
  [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON output on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON  output on A31 Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
      Re: [PATCH v2 03/13] drm/sun4i: tcon: Add support for demuxing TCON  output on A31 Chen-Yu Tsai <wens@csie.org> - 2017-09-27 06:10 +0200
  [PATCH v2 05/13] drm/sun4i: hdmi: create a regmap for later use Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 05/13] drm/sun4i: hdmi: create a regmap for later use Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200
  [PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS clk parent Chen-Yu Tsai <wens@csie.org> - 2017-09-26 09:10 +0200
    Re: [PATCH v2 06/13] drm/sun4i: hdmi: Allow using second PLL as TMDS  clk parent Maxime Ripard <maxime.ripard@free-electrons.com> - 2017-09-26 12:00 +0200

csiph-web