Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

clk: fixed-factor: add optional accuracy support

Fixed factor clock reports the parent clock accuracy. Add flags and acc
fields to `struct clk_fixed_factor` to support setting a fixed
accuracy. The default if no flag is set is not changed: use the parent
clock accuracy.

Signed-off-by: Théo Lebrun <theo.lebrun@bootlin.com>
Link: https://lore.kernel.org/r/20240221-mbly-clk-v7-1-31d4ce3630c3@bootlin.com
Signed-off-by: Stephen Boyd <sboyd@kernel.org>

authored by

Théo Lebrun and committed by
Stephen Boyd
ff773fd2 6613476e

+32 -8
+21 -7
drivers/clk/clk-fixed-factor.c
··· 57 57 return 0; 58 58 } 59 59 60 + static unsigned long clk_factor_recalc_accuracy(struct clk_hw *hw, 61 + unsigned long parent_accuracy) 62 + { 63 + struct clk_fixed_factor *fix = to_clk_fixed_factor(hw); 64 + 65 + if (fix->flags & CLK_FIXED_FACTOR_FIXED_ACCURACY) 66 + return fix->acc; 67 + 68 + return parent_accuracy; 69 + } 70 + 60 71 const struct clk_ops clk_fixed_factor_ops = { 61 72 .round_rate = clk_factor_round_rate, 62 73 .set_rate = clk_factor_set_rate, 63 74 .recalc_rate = clk_factor_recalc_rate, 75 + .recalc_accuracy = clk_factor_recalc_accuracy, 64 76 }; 65 77 EXPORT_SYMBOL_GPL(clk_fixed_factor_ops); 66 78 ··· 93 81 const char *name, const char *parent_name, 94 82 const struct clk_hw *parent_hw, int index, 95 83 unsigned long flags, unsigned int mult, unsigned int div, 96 - bool devm) 84 + unsigned long acc, unsigned int fixflags, bool devm) 97 85 { 98 86 struct clk_fixed_factor *fix; 99 87 struct clk_init_data init = { }; ··· 117 105 fix->mult = mult; 118 106 fix->div = div; 119 107 fix->hw.init = &init; 108 + fix->acc = acc; 109 + fix->flags = fixflags; 120 110 121 111 init.name = name; 122 112 init.ops = &clk_fixed_factor_ops; ··· 166 152 unsigned int mult, unsigned int div) 167 153 { 168 154 return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, index, 169 - flags, mult, div, true); 155 + flags, mult, div, 0, 0, true); 170 156 } 171 157 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index); 172 158 ··· 188 174 unsigned long flags, unsigned int mult, unsigned int div) 189 175 { 190 176 return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw, 191 - -1, flags, mult, div, true); 177 + -1, flags, mult, div, 0, 0, true); 192 178 } 193 179 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw); 194 180 ··· 198 184 { 199 185 return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, 200 186 parent_hw, -1, flags, mult, div, 201 - false); 187 + 0, 0, false); 202 188 } 203 189 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw); 204 190 ··· 207 193 unsigned int mult, unsigned int div) 208 194 { 209 195 return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, 210 - flags, mult, div, false); 196 + flags, mult, div, 0, 0, false); 211 197 } 212 198 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor); 213 199 ··· 254 240 unsigned int mult, unsigned int div) 255 241 { 256 242 return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, 257 - flags, mult, div, true); 243 + flags, mult, div, 0, 0, true); 258 244 } 259 245 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor); 260 246 ··· 281 267 of_property_read_string(node, "clock-output-names", &clk_name); 282 268 283 269 hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0, 284 - 0, mult, div, false); 270 + 0, mult, div, 0, 0, false); 285 271 if (IS_ERR(hw)) { 286 272 /* 287 273 * Clear OF_POPULATED flag so that clock registration can be
+11 -1
include/linux/clk-provider.h
··· 1084 1084 * @hw: handle between common and hardware-specific interfaces 1085 1085 * @mult: multiplier 1086 1086 * @div: divider 1087 + * @acc: fixed accuracy in ppb 1088 + * @flags: behavior modifying flags 1087 1089 * 1088 1090 * Clock with a fixed multiplier and divider. The output frequency is the 1089 1091 * parent clock rate divided by div and multiplied by mult. 1090 - * Implements .recalc_rate, .set_rate and .round_rate 1092 + * Implements .recalc_rate, .set_rate, .round_rate and .recalc_accuracy 1093 + * 1094 + * Flags: 1095 + * * CLK_FIXED_FACTOR_FIXED_ACCURACY - Use the value in @acc instead of the 1096 + * parent clk accuracy. 1091 1097 */ 1092 1098 1093 1099 struct clk_fixed_factor { 1094 1100 struct clk_hw hw; 1095 1101 unsigned int mult; 1096 1102 unsigned int div; 1103 + unsigned long acc; 1104 + unsigned int flags; 1097 1105 }; 1106 + 1107 + #define CLK_FIXED_FACTOR_FIXED_ACCURACY BIT(0) 1098 1108 1099 1109 #define to_clk_fixed_factor(_hw) container_of(_hw, struct clk_fixed_factor, hw) 1100 1110