Module Name:    src
Committed By:   bouyer
Date:           Mon Apr  2 20:55:49 UTC 2018

Modified Files:
        src/sys/arch/arm/sunxi: sunxi_ccu_display.c

Log Message:
- sunxi_ccu_lcdxch1_set_rate(): enable parent before calling
  sunxi_ccu_div_set_rate(). If it's not enabled get_rate() will return 0 and
  sunxi_ccu_div_set_rate() will fail.
- rework sunxi_ccu_lcdxch0_set_rate() to actually really select the best
  parent.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/arch/arm/sunxi/sunxi_ccu_display.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/arm/sunxi/sunxi_ccu_display.c
diff -u src/sys/arch/arm/sunxi/sunxi_ccu_display.c:1.1 src/sys/arch/arm/sunxi/sunxi_ccu_display.c:1.2
--- src/sys/arch/arm/sunxi/sunxi_ccu_display.c:1.1	Sun Apr  1 21:19:17 2018
+++ src/sys/arch/arm/sunxi/sunxi_ccu_display.c	Mon Apr  2 20:55:49 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_ccu_display.c,v 1.1 2018/04/01 21:19:17 bouyer Exp $ */
+/* $NetBSD: sunxi_ccu_display.c,v 1.2 2018/04/02 20:55:49 bouyer Exp $ */
 
 /*-
  * Copyright (c) 2018 Manuel Bouyer <bou...@antioche.eu.org>
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_display.c,v 1.1 2018/04/01 21:19:17 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_ccu_display.c,v 1.2 2018/04/02 20:55:49 bouyer Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -46,18 +46,32 @@ sunxi_ccu_lcdxch0_set_rate(struct sunxi_
 {
 	struct clk *clkp;
 	int error;
+	int diff, diff_x2;
+	int rate, rate_x2;
 
 	clkp = &pllclk->base;
-	error = clk_set_rate(clkp, new_rate);
-	if (error) {
+	rate = clk_round_rate(clkp, new_rate);
+	diff = abs(new_rate - rate);
+
+	rate_x2 = (clk_round_rate(clkp, new_rate / 2) * 2);
+	diff_x2 = abs(new_rate - rate_x2);
+
+	if (rate == 0 && rate_x2 == 0)
+		return ERANGE;
+
+	if (diff_x2 < diff) {
 		error = clk_set_rate(clkp, new_rate / 2);
-		if (error != 0)
-			return error;
-		clkp = &pllclk_x2->base;
+		KASSERT(error == 0);
+		error = clk_set_parent(&clk->base, &pllclk_x2->base);
+		KASSERT(error == 0);
+	} else {
+		error = clk_set_rate(clkp, new_rate);
+		KASSERT(error == 0);
+		error = clk_set_parent(&clk->base, clkp);
+		KASSERT(error == 0);
 	}
-	error = clk_set_parent(&clk->base, clkp);
-	KASSERT(error == 0);
-	return error;
+	(void)error;
+	return 0;
 }
 
 u_int
@@ -122,6 +136,8 @@ sunxi_ccu_lcdxch1_set_rate(struct sunxi_
 	KASSERT(error == 0);
 	error = clk_set_parent(&clk->base, clkp);
 	KASSERT(error == 0);
+	error = clk_enable(clkp);
+	KASSERT(error == 0);
 	error = sunxi_ccu_div_set_rate(sc, clk, new_rate);
 	KASSERT(error == 0);
 	return error;

Reply via email to