dri-devel Archive mirror
 help / color / mirror / Atom feed
* [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames)
@ 2024-03-04  7:29 Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate Frank Oltmanns
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns, stable, Diego Roversi

On some pinephones the video output sometimes freezes (flips between two
frames) [1]. It seems to be that the reason for this behaviour is that
PLL-MIPI is outside its limits, and the GPU is not running at a fixed
rate.

In this patch series I propose the following changes:
  1. sunxi-ng: Adhere to the following constraints given in the
     Allwinner A64 Manual regarding PLL-MIPI:
      * M/N <= 3
      * (PLL_VIDEO0)/M >= 24MHz
      * 500MHz <= clockrate <= 1400MHz

  2. Remove two operating points from the A64 DTS OPPs, so that the GPU
     runs at a fixed rate of 432 MHz.

Note, that when pinning the GPU to 432 MHz the issue [1] completely
disappears for me. I've searched the BSP and could not find any
indication that supports the idea of having the three OPPs. The only
frequency I found in the BPSs for A64 is 432 MHz, which has also proven
stable for me.

Another bigger change compared to the previous version is that I've
removed the patch to adapt the XBD599 panel's timings to Allwinner A64's
PLL-MIPI new constraints from this series. Mainly, because I'm currently
evaluationg other options that may or may not work. (It may work at
least until HDMI support is upstreamed.) I'll probably resend the patch
at a later point in time.

I very much appreciate your feedback!

[1] https://gitlab.com/postmarketOS/pmaports/-/issues/805

Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
Changes in v3:
- dts: Pin GPU to 432 MHz.
- nkm and a64: Move minimum and maximum rate handling to the common part
  of the sunxi-ng driver.
- Removed st7703 patch from series.
- Link to v2: https://lore.kernel.org/r/20240205-pinephone-pll-fixes-v2-0-96a46a2d8c9b@oltmanns.dev

Changes in v2:
- dts: Increase minimum GPU frequency to 192 MHz.
- nkm and a64: Add minimum and maximum rate for PLL-MIPI.
- nkm: Use the same approach for skipping invalid rates in
  ccu_nkm_find_best() as in ccu_nkm_find_best_with_parent_adj().
- nkm: Improve names for ratio struct members and hence get rid of
  describing comments.
- nkm and a64: Correct description in the commit messages: M/N <= 3
- Remove patches for nm as they were not needed.
- st7703: Rework the commit message to cover more background for the
  change.
- Link to v1: https://lore.kernel.org/r/20231218-pinephone-pll-fixes-v1-0-e238b6ed6dc1@oltmanns.dev

---
Frank Oltmanns (5):
      clk: sunxi-ng: common: Support minimum and maximum rate
      clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI
      clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate
      clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m ratio and parent rate
      arm64: dts: allwinner: a64: Run GPU at 432 MHz

 arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi |  8 --------
 drivers/clk/sunxi-ng/ccu-sun50i-a64.c         | 14 +++++++++-----
 drivers/clk/sunxi-ng/ccu_common.c             | 15 +++++++++++++++
 drivers/clk/sunxi-ng/ccu_common.h             |  3 +++
 drivers/clk/sunxi-ng/ccu_nkm.c                | 21 +++++++++++++++++++++
 drivers/clk/sunxi-ng/ccu_nkm.h                |  2 ++
 6 files changed, 50 insertions(+), 13 deletions(-)
---
base-commit: 216c1282dde38ca87ebdf1ccacee5a0682901574
change-id: 20231218-pinephone-pll-fixes-0ccdfde273e4

Best regards,
-- 
Frank Oltmanns <frank@oltmanns.dev>


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

* [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate
  2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
@ 2024-03-04  7:29 ` Frank Oltmanns
  2024-03-04 10:06   ` Maxime Ripard
  2024-03-04  7:29 ` [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI Frank Oltmanns
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns, stable

The Allwinner SoC's typically have an upper and lower limit for their
clocks' rates. Up until now, support for that has been implemented
separately for each clock type.

Implement that functionality in the sunxi-ng's common part making use of
the CCF rate liming capabilities, so that it is available for all clock
types.

Suggested-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
Cc: stable@vger.kernel.org
---
 drivers/clk/sunxi-ng/ccu_common.c | 15 +++++++++++++++
 drivers/clk/sunxi-ng/ccu_common.h |  3 +++
 2 files changed, 18 insertions(+)

diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
index 8babce55302f..2152063eee16 100644
--- a/drivers/clk/sunxi-ng/ccu_common.c
+++ b/drivers/clk/sunxi-ng/ccu_common.c
@@ -44,6 +44,12 @@ bool ccu_is_better_rate(struct ccu_common *common,
 			unsigned long current_rate,
 			unsigned long best_rate)
 {
+	if (common->max_rate && current_rate > common->max_rate)
+		return false;
+
+	if (common->min_rate && current_rate < common->min_rate)
+		return false;
+
 	if (common->features & CCU_FEATURE_CLOSEST_RATE)
 		return abs(current_rate - target_rate) < abs(best_rate - target_rate);
 
@@ -122,7 +128,10 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
 
 	for (i = 0; i < desc->hw_clks->num ; i++) {
 		struct clk_hw *hw = desc->hw_clks->hws[i];
+		struct ccu_common *common = hw_to_ccu_common(hw);
 		const char *name;
+		unsigned long min_rate = 0;
+		unsigned long max_rate = ULONG_MAX;
 
 		if (!hw)
 			continue;
@@ -136,6 +145,12 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
 			pr_err("Couldn't register clock %d - %s\n", i, name);
 			goto err_clk_unreg;
 		}
+
+		if (common->min_rate)
+			min_rate = common->min_rate;
+		if (common->max_rate)
+			max_rate = common->max_rate;
+		clk_hw_set_rate_range(hw, min_rate, max_rate);
 	}
 
 	ret = of_clk_add_hw_provider(node, of_clk_hw_onecell_get,
diff --git a/drivers/clk/sunxi-ng/ccu_common.h b/drivers/clk/sunxi-ng/ccu_common.h
index 942a72c09437..329734f8cf42 100644
--- a/drivers/clk/sunxi-ng/ccu_common.h
+++ b/drivers/clk/sunxi-ng/ccu_common.h
@@ -31,6 +31,9 @@ struct ccu_common {
 	u16		lock_reg;
 	u32		prediv;
 
+	unsigned long	min_rate;
+	unsigned long	max_rate;
+
 	unsigned long	features;
 	spinlock_t	*lock;
 	struct clk_hw	hw;

-- 
2.44.0


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

* [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI
  2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate Frank Oltmanns
@ 2024-03-04  7:29 ` Frank Oltmanns
  2024-03-04 10:06   ` Maxime Ripard
  2024-03-04  7:29 ` [PATCH v3 3/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Frank Oltmanns
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns, Diego Roversi, stable

When the Allwinner A64's TCON0 searches the ideal rate for the connected
panel, it may happen that it requests a rate from its parent PLL-MIPI
which PLL-MIPI does not support.

This happens for example on the Olimex TERES-I laptop where TCON0
requests PLL-MIPI to change to a rate of several GHz which causes the
panel to stay blank. It also happens on the pinephone where a rate of
less than 500 MHz is requested which causes instabilities on some
phones.

Set the minimum and maximum rate of Allwinner A64's PLL-MIPI according
to the Allwinner User Manual.

Fixes: ca1170b69968 ("clk: sunxi-ng: a64: force select PLL_MIPI in TCON0 mux")
Reported-by: Diego Roversi <diegor@tiscali.it>
Closes: https://groups.google.com/g/linux-sunxi/c/Rh-Uqqa66bw
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
Tested-by: Diego Roversi <diegor@tiscali.it>
Cc: stable@vger.kernel.org
---
 drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
index 8951ffc14ff5..6a4b2b9ef30a 100644
--- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
+++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
@@ -182,6 +182,8 @@ static struct ccu_nkm pll_mipi_clk = {
 					      &ccu_nkm_ops,
 					      CLK_SET_RATE_UNGATE | CLK_SET_RATE_PARENT),
 		.features	= CCU_FEATURE_CLOSEST_RATE,
+		.min_rate	= 500000000,
+		.max_rate	= 1400000000,
 	},
 };
 

-- 
2.44.0


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

* [PATCH v3 3/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate
  2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI Frank Oltmanns
@ 2024-03-04  7:29 ` Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 4/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m " Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz Frank Oltmanns
  4 siblings, 0 replies; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns

The Allwinner A64 manual lists the following constraints for the
PLL-MIPI clock:
 - M/N <= 3
 - (PLL_VIDEO0)/M >= 24MHz

The PLL-MIPI clock is implemented as ccu_nkm. Therefore, add support for
these constraints.

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
 drivers/clk/sunxi-ng/ccu_nkm.c | 21 +++++++++++++++++++++
 drivers/clk/sunxi-ng/ccu_nkm.h |  2 ++
 2 files changed, 23 insertions(+)

diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c
index 853f84398e2b..1168d894d636 100644
--- a/drivers/clk/sunxi-ng/ccu_nkm.c
+++ b/drivers/clk/sunxi-ng/ccu_nkm.c
@@ -16,6 +16,20 @@ struct _ccu_nkm {
 	unsigned long	m, min_m, max_m;
 };
 
+static bool ccu_nkm_is_valid_rate(struct ccu_common *common, unsigned long parent,
+				  unsigned long n, unsigned long m)
+{
+	struct ccu_nkm *nkm = container_of(common, struct ccu_nkm, common);
+
+	if (nkm->max_m_n_ratio && (m > nkm->max_m_n_ratio * n))
+		return false;
+
+	if (nkm->min_parent_m_ratio && (parent < nkm->min_parent_m_ratio * m))
+		return false;
+
+	return true;
+}
+
 static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common,
 						       struct clk_hw *parent_hw,
 						       unsigned long *parent, unsigned long rate,
@@ -31,6 +45,10 @@ static unsigned long ccu_nkm_find_best_with_parent_adj(struct ccu_common *common
 				unsigned long tmp_rate, tmp_parent;
 
 				tmp_parent = clk_hw_round_rate(parent_hw, rate * _m / (_n * _k));
+
+				if (!ccu_nkm_is_valid_rate(common, tmp_parent, _n, _m))
+					continue;
+
 				tmp_rate = tmp_parent * _n * _k / _m;
 
 				if (ccu_is_better_rate(common, rate, tmp_rate, best_rate) ||
@@ -64,6 +82,9 @@ static unsigned long ccu_nkm_find_best(unsigned long parent, unsigned long rate,
 	for (_k = nkm->min_k; _k <= nkm->max_k; _k++) {
 		for (_n = nkm->min_n; _n <= nkm->max_n; _n++) {
 			for (_m = nkm->min_m; _m <= nkm->max_m; _m++) {
+				if (!ccu_nkm_is_valid_rate(common, parent, _n, _m))
+					continue;
+
 				unsigned long tmp_rate;
 
 				tmp_rate = parent * _n * _k / _m;
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.h b/drivers/clk/sunxi-ng/ccu_nkm.h
index 6601defb3f38..c409212ee40e 100644
--- a/drivers/clk/sunxi-ng/ccu_nkm.h
+++ b/drivers/clk/sunxi-ng/ccu_nkm.h
@@ -27,6 +27,8 @@ struct ccu_nkm {
 	struct ccu_mux_internal	mux;
 
 	unsigned int		fixed_post_div;
+	unsigned long		max_m_n_ratio;
+	unsigned long		min_parent_m_ratio;
 
 	struct ccu_common	common;
 };

-- 
2.44.0


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

* [PATCH v3 4/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m ratio and parent rate
  2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
                   ` (2 preceding siblings ...)
  2024-03-04  7:29 ` [PATCH v3 3/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Frank Oltmanns
@ 2024-03-04  7:29 ` Frank Oltmanns
  2024-03-04  7:29 ` [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz Frank Oltmanns
  4 siblings, 0 replies; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns

The Allwinner A64 manual lists the following constraints for the
PLL-MIPI clock:
 - M/N <= 3
 - (PLL_VIDEO0)/M >= 24MHz

Use these constraints.

Reviewed-by: Jernej Skrabec <jernej.skrabec@gmail.com>
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
 drivers/clk/sunxi-ng/ccu-sun50i-a64.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
index 6a4b2b9ef30a..07796c79a23e 100644
--- a/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
+++ b/drivers/clk/sunxi-ng/ccu-sun50i-a64.c
@@ -171,11 +171,13 @@ static struct ccu_nkm pll_mipi_clk = {
 	 * user manual, and by experiments the PLL doesn't work without
 	 * these bits toggled.
 	 */
-	.enable		= BIT(31) | BIT(23) | BIT(22),
-	.lock		= BIT(28),
-	.n		= _SUNXI_CCU_MULT(8, 4),
-	.k		= _SUNXI_CCU_MULT_MIN(4, 2, 2),
-	.m		= _SUNXI_CCU_DIV(0, 4),
+	.enable			= BIT(31) | BIT(23) | BIT(22),
+	.lock			= BIT(28),
+	.n			= _SUNXI_CCU_MULT(8, 4),
+	.k			= _SUNXI_CCU_MULT_MIN(4, 2, 2),
+	.m			= _SUNXI_CCU_DIV(0, 4),
+	.max_m_n_ratio		= 3,
+	.min_parent_m_ratio	= 24000000,
 	.common		= {
 		.reg		= 0x040,
 		.hw.init	= CLK_HW_INIT("pll-mipi", "pll-video0",

-- 
2.44.0


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

* [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz
  2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
                   ` (3 preceding siblings ...)
  2024-03-04  7:29 ` [PATCH v3 4/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m " Frank Oltmanns
@ 2024-03-04  7:29 ` Frank Oltmanns
  2024-03-06 15:04   ` Erico Nunes
  4 siblings, 1 reply; 9+ messages in thread
From: Frank Oltmanns @ 2024-03-04  7:29 UTC (permalink / raw
  To: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley
  Cc: linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, Frank Oltmanns

The Allwinner A64's GPU has currently three operating points. However,
the BSP runs the GPU fixed at 432 MHz. In addition, at least one of the
devices using that SoC - the pinephone - shows unstabilities (see link)
that can be circumvented by running the GPU at a fixed rate.

Therefore, remove the other two operating points from the GPU OPP table,
so that the GPU runs at a fixed rate of 432 MHz.

Link: https://gitlab.com/postmarketOS/pmaports/-/issues/805
Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
---
 arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi | 8 --------
 1 file changed, 8 deletions(-)

diff --git a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
index 57ac18738c99..c810380aab6d 100644
--- a/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
+++ b/arch/arm64/boot/dts/allwinner/sun50i-a64.dtsi
@@ -107,14 +107,6 @@ de: display-engine {
 	gpu_opp_table: opp-table-gpu {
 		compatible = "operating-points-v2";
 
-		opp-120000000 {
-			opp-hz = /bits/ 64 <120000000>;
-		};
-
-		opp-312000000 {
-			opp-hz = /bits/ 64 <312000000>;
-		};
-
 		opp-432000000 {
 			opp-hz = /bits/ 64 <432000000>;
 		};

-- 
2.44.0


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

* Re: [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate
  2024-03-04  7:29 ` [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate Frank Oltmanns
@ 2024-03-04 10:06   ` Maxime Ripard
  0 siblings, 0 replies; 9+ messages in thread
From: Maxime Ripard @ 2024-03-04 10:06 UTC (permalink / raw
  To: Frank Oltmanns
  Cc: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Thomas Zimmermann, David Airlie, Daniel Vetter,
	Rob Herring, Krzysztof Kozlowski, Conor Dooley, linux-clk,
	linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree, stable

[-- Attachment #1: Type: text/plain, Size: 2389 bytes --]

On Mon, Mar 04, 2024 at 08:29:17AM +0100, Frank Oltmanns wrote:
> The Allwinner SoC's typically have an upper and lower limit for their
> clocks' rates. Up until now, support for that has been implemented
> separately for each clock type.
> 
> Implement that functionality in the sunxi-ng's common part making use of
> the CCF rate liming capabilities, so that it is available for all clock
> types.
> 
> Suggested-by: Maxime Ripard <mripard@kernel.org>
> Signed-off-by: Frank Oltmanns <frank@oltmanns.dev>
> Cc: stable@vger.kernel.org
> ---
>  drivers/clk/sunxi-ng/ccu_common.c | 15 +++++++++++++++
>  drivers/clk/sunxi-ng/ccu_common.h |  3 +++
>  2 files changed, 18 insertions(+)
> 
> diff --git a/drivers/clk/sunxi-ng/ccu_common.c b/drivers/clk/sunxi-ng/ccu_common.c
> index 8babce55302f..2152063eee16 100644
> --- a/drivers/clk/sunxi-ng/ccu_common.c
> +++ b/drivers/clk/sunxi-ng/ccu_common.c
> @@ -44,6 +44,12 @@ bool ccu_is_better_rate(struct ccu_common *common,
>  			unsigned long current_rate,
>  			unsigned long best_rate)
>  {
> +	if (common->max_rate && current_rate > common->max_rate)
> +		return false;
> +
> +	if (common->min_rate && current_rate < common->min_rate)
> +		return false;
> +

We should use clk_hw_get_rate_range() here, there might be some
additional constraints to the rate range than the hardware ones (ie,
calls to clk_set_rate_range()).

>  	if (common->features & CCU_FEATURE_CLOSEST_RATE)
>  		return abs(current_rate - target_rate) < abs(best_rate - target_rate);
>  
> @@ -122,7 +128,10 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
>  
>  	for (i = 0; i < desc->hw_clks->num ; i++) {
>  		struct clk_hw *hw = desc->hw_clks->hws[i];
> +		struct ccu_common *common = hw_to_ccu_common(hw);
>  		const char *name;
> +		unsigned long min_rate = 0;
> +		unsigned long max_rate = ULONG_MAX;
>  
>  		if (!hw)
>  			continue;
> @@ -136,6 +145,12 @@ static int sunxi_ccu_probe(struct sunxi_ccu *ccu, struct device *dev,
>  			pr_err("Couldn't register clock %d - %s\n", i, name);
>  			goto err_clk_unreg;
>  		}
> +
> +		if (common->min_rate)
> +			min_rate = common->min_rate;
> +		if (common->max_rate)
> +			max_rate = common->max_rate;

max_rate should always be set to ULONG_MAX. I would drop the tests for
both here, and warn if max_rate is set to 0.

Maxime

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 228 bytes --]

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

* Re: [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI
  2024-03-04  7:29 ` [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI Frank Oltmanns
@ 2024-03-04 10:06   ` Maxime Ripard
  0 siblings, 0 replies; 9+ messages in thread
From: Maxime Ripard @ 2024-03-04 10:06 UTC (permalink / raw
  To: Frank Oltmanns
  Cc: devicetree, dri-devel, linux-arm-kernel, linux-clk, linux-kernel,
	linux-sunxi, stable, Chen-Yu Tsai, Conor Dooley, Daniel Vetter,
	David Airlie, Diego Roversi, Guido Günther, Jernej Skrabec,
	Jessica Zhang, Krzysztof Kozlowski, Maarten Lankhorst,
	Maxime Ripard, Michael Turquette, Neil Armstrong, Ondrej Jirman,
	Purism Kernel Team, Rob Herring, Sam Ravnborg, Samuel Holland,
	Stephen Boyd, Thomas Zimmermann

On Mon, 4 Mar 2024 08:29:18 +0100, Frank Oltmanns wrote:
> When the Allwinner A64's TCON0 searches the ideal rate for the connected
> panel, it may happen that it requests a rate from its parent PLL-MIPI
> which PLL-MIPI does not support.
> 
> This happens for example on the Olimex TERES-I laptop where TCON0
> 
> [ ... ]

Reviewed-by: Maxime Ripard <mripard@kernel.org>

Thanks!
Maxime

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

* Re: [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz
  2024-03-04  7:29 ` [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz Frank Oltmanns
@ 2024-03-06 15:04   ` Erico Nunes
  0 siblings, 0 replies; 9+ messages in thread
From: Erico Nunes @ 2024-03-06 15:04 UTC (permalink / raw
  To: Frank Oltmanns
  Cc: Michael Turquette, Stephen Boyd, Chen-Yu Tsai, Jernej Skrabec,
	Samuel Holland, Guido Günther, Purism Kernel Team,
	Ondrej Jirman, Neil Armstrong, Jessica Zhang, Sam Ravnborg,
	Maarten Lankhorst, Maxime Ripard, Thomas Zimmermann, David Airlie,
	Daniel Vetter, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	linux-clk, linux-arm-kernel, linux-sunxi, linux-kernel, dri-devel,
	devicetree

On Mon, Mar 4, 2024 at 6:01 PM Frank Oltmanns <frank@oltmanns.dev> wrote:
>
> The Allwinner A64's GPU has currently three operating points. However,
> the BSP runs the GPU fixed at 432 MHz. In addition, at least one of the
> devices using that SoC - the pinephone - shows unstabilities (see link)
> that can be circumvented by running the GPU at a fixed rate.
>
> Therefore, remove the other two operating points from the GPU OPP table,
> so that the GPU runs at a fixed rate of 432 MHz.

In addition to all of this, the A64 user manual does say explicitly
that "dynamic frequency scaling is not supported" on PLL_GPU. So I
think this is really needed for a reliable GPU experience on A64.

Acked-by: Erico Nunes <nunes.erico@gmail.com>

Thanks

Erico

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

end of thread, other threads:[~2024-03-06 15:05 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-03-04  7:29 [PATCH v3 0/5] Pinephone video out fixes (flipping between two frames) Frank Oltmanns
2024-03-04  7:29 ` [PATCH v3 1/5] clk: sunxi-ng: common: Support minimum and maximum rate Frank Oltmanns
2024-03-04 10:06   ` Maxime Ripard
2024-03-04  7:29 ` [PATCH v3 2/5] clk: sunxi-ng: a64: Set minimum and maximum rate for PLL-MIPI Frank Oltmanns
2024-03-04 10:06   ` Maxime Ripard
2024-03-04  7:29 ` [PATCH v3 3/5] clk: sunxi-ng: nkm: Support constraints on m/n ratio and parent rate Frank Oltmanns
2024-03-04  7:29 ` [PATCH v3 4/5] clk: sunxi-ng: a64: Add constraints on PLL-MIPI's n/m " Frank Oltmanns
2024-03-04  7:29 ` [PATCH v3 5/5] arm64: dts: allwinner: a64: Run GPU at 432 MHz Frank Oltmanns
2024-03-06 15:04   ` Erico Nunes

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).