git: 7726c0ce98db - main - aw_clk: Add a flag to only search the given value of a factor

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 12 Nov 2026 09:51:31 UTC
The branch main has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=7726c0ce98db53011d1d2066a36643aaab2a4782

commit 7726c0ce98db53011d1d2066a36643aaab2a4782
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2026-11-10 15:55:26 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2026-11-12 09:47:30 +0000

    aw_clk: Add a flag to only search the given value of a factor
    
    Some factors have to be read from the register, as the firmware or the
    reset value can leave them set, but must not be changed when looking for
    a rate.  AW_CLK_FACTOR_FIXED cannot be used as it does not read the
    register.
    
    Add AW_CLK_FACTOR_SEARCH_VALUE: the factor is decoded from the register
    as usual but the search only tries its value, so the factor is set to
    this value when the rate is changed.
    
    Tested on: H6
---
 sys/dev/clk/allwinner/aw_clk.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/sys/dev/clk/allwinner/aw_clk.h b/sys/dev/clk/allwinner/aw_clk.h
index d8d6ecd09fd3..dc4068d3351a 100644
--- a/sys/dev/clk/allwinner/aw_clk.h
+++ b/sys/dev/clk/allwinner/aw_clk.h
@@ -76,12 +76,14 @@ struct aw_clk_init {
 #define	AW_CLK_FACTOR_ZERO_IS_ONE	0x0010
 #define	AW_CLK_FACTOR_MIN_VALUE		0x0020
 #define	AW_CLK_FACTOR_MAX_VALUE		0x0040
+#define	AW_CLK_FACTOR_SEARCH_VALUE	0x0080
 
 struct aw_clk_factor {
 	uint32_t	shift;		/* Shift bits for the factor */
 	uint32_t	mask;		/* Mask to get the factor, will be override by the clk methods */
 	uint32_t	width;		/* Number of bits for the factor */
-	uint32_t	value;		/* Fixed value, depends on AW_CLK_FACTOR_FIXED */
+	uint32_t	value;		/* Fixed value, depends on AW_CLK_FACTOR_FIXED
+				 * or AW_CLK_FACTOR_SEARCH_VALUE */
 
 	uint32_t	cond_shift;
 	uint32_t	cond_mask;
@@ -169,7 +171,8 @@ aw_clk_factor_get_max(struct aw_clk_factor *factor)
 {
 	uint32_t max;
 
-	if (factor->flags & AW_CLK_FACTOR_FIXED)
+	if (factor->flags &
+	    (AW_CLK_FACTOR_FIXED | AW_CLK_FACTOR_SEARCH_VALUE))
 		max = factor->value;
 	else if (factor->flags & AW_CLK_FACTOR_POWER_OF_TWO)
 		max = 1 << ((1 << factor->width) - 1);
@@ -185,7 +188,8 @@ aw_clk_factor_get_min(struct aw_clk_factor *factor)
 {
 	uint32_t min;
 
-	if (factor->flags & AW_CLK_FACTOR_FIXED)
+	if (factor->flags &
+	    (AW_CLK_FACTOR_FIXED | AW_CLK_FACTOR_SEARCH_VALUE))
 		min = factor->value;
 	else if (factor->flags & AW_CLK_FACTOR_ZERO_BASED)
 		min = 0;