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

clk: fixed-factor: add fwname-based constructor functions

Add four functions to register clk_hw based on the fw_name field in
clk_parent_data, ie the value in the DT property `clock-names`.

There are variants for devm or not and passing an accuracy or not
passing one:

- clk_hw_register_fixed_factor_fwname
- clk_hw_register_fixed_factor_with_accuracy_fwname
- devm_clk_hw_register_fixed_factor_fwname
- devm_clk_hw_register_fixed_factor_with_accuracy_fwname

The `struct clk_parent_data` init is extracted from
__clk_hw_register_fixed_factor to each calling function. It is required
to allow each function to pass whatever field they want, not only index.

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

authored by

Théo Lebrun and committed by
Stephen Boyd
ae156a36 ff773fd2

+85 -14
+71 -14
drivers/clk/clk-fixed-factor.c
··· 91 91 static struct clk_hw * 92 92 __clk_hw_register_fixed_factor(struct device *dev, struct device_node *np, 93 93 const char *name, const char *parent_name, 94 - const struct clk_hw *parent_hw, int index, 94 + const struct clk_hw *parent_hw, const struct clk_parent_data *pdata, 95 95 unsigned long flags, unsigned int mult, unsigned int div, 96 96 unsigned long acc, unsigned int fixflags, bool devm) 97 97 { 98 98 struct clk_fixed_factor *fix; 99 99 struct clk_init_data init = { }; 100 - struct clk_parent_data pdata = { .index = index }; 101 100 struct clk_hw *hw; 102 101 int ret; 103 102 ··· 127 128 else if (parent_hw) 128 129 init.parent_hws = &parent_hw; 129 130 else 130 - init.parent_data = &pdata; 131 + init.parent_data = pdata; 131 132 init.num_parents = 1; 132 133 133 134 hw = &fix->hw; ··· 164 165 const char *name, unsigned int index, unsigned long flags, 165 166 unsigned int mult, unsigned int div) 166 167 { 167 - return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, index, 168 + const struct clk_parent_data pdata = { .index = index }; 169 + 170 + return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, NULL, &pdata, 168 171 flags, mult, div, 0, 0, true); 169 172 } 170 173 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_index); ··· 188 187 const char *name, const struct clk_hw *parent_hw, 189 188 unsigned long flags, unsigned int mult, unsigned int div) 190 189 { 190 + const struct clk_parent_data pdata = { .index = -1 }; 191 + 191 192 return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw, 192 - -1, flags, mult, div, 0, 0, true); 193 + &pdata, flags, mult, div, 0, 0, true); 193 194 } 194 195 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_parent_hw); 195 196 ··· 199 196 const char *name, const struct clk_hw *parent_hw, 200 197 unsigned long flags, unsigned int mult, unsigned int div) 201 198 { 202 - return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, 203 - parent_hw, -1, flags, mult, div, 204 - 0, 0, false); 199 + const struct clk_parent_data pdata = { .index = -1 }; 200 + 201 + return __clk_hw_register_fixed_factor(dev, NULL, name, NULL, parent_hw, 202 + &pdata, flags, mult, div, 0, 0, false); 205 203 } 206 204 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_parent_hw); 207 205 ··· 210 206 const char *name, const char *parent_name, unsigned long flags, 211 207 unsigned int mult, unsigned int div) 212 208 { 213 - return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, 214 - flags, mult, div, 0, 0, false); 209 + const struct clk_parent_data pdata = { .index = -1 }; 210 + 211 + return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, 212 + &pdata, flags, mult, div, 0, 0, false); 215 213 } 216 214 EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor); 215 + 216 + struct clk_hw *clk_hw_register_fixed_factor_fwname(struct device *dev, 217 + struct device_node *np, const char *name, const char *fw_name, 218 + unsigned long flags, unsigned int mult, unsigned int div) 219 + { 220 + const struct clk_parent_data pdata = { .index = -1, .fw_name = fw_name }; 221 + 222 + return __clk_hw_register_fixed_factor(dev, np, name, NULL, NULL, 223 + &pdata, flags, mult, div, 0, 0, false); 224 + } 225 + EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_fwname); 226 + 227 + struct clk_hw *clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev, 228 + struct device_node *np, const char *name, const char *fw_name, 229 + unsigned long flags, unsigned int mult, unsigned int div, 230 + unsigned long acc) 231 + { 232 + const struct clk_parent_data pdata = { .index = -1, .fw_name = fw_name }; 233 + 234 + return __clk_hw_register_fixed_factor(dev, np, name, NULL, NULL, 235 + &pdata, flags, mult, div, acc, 236 + CLK_FIXED_FACTOR_FIXED_ACCURACY, false); 237 + } 238 + EXPORT_SYMBOL_GPL(clk_hw_register_fixed_factor_with_accuracy_fwname); 217 239 218 240 struct clk *clk_register_fixed_factor(struct device *dev, const char *name, 219 241 const char *parent_name, unsigned long flags, ··· 283 253 const char *name, const char *parent_name, unsigned long flags, 284 254 unsigned int mult, unsigned int div) 285 255 { 286 - return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, -1, 287 - flags, mult, div, 0, 0, true); 256 + const struct clk_parent_data pdata = { .index = -1 }; 257 + 258 + return __clk_hw_register_fixed_factor(dev, NULL, name, parent_name, NULL, 259 + &pdata, flags, mult, div, 0, 0, true); 288 260 } 289 261 EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor); 262 + 263 + struct clk_hw *devm_clk_hw_register_fixed_factor_fwname(struct device *dev, 264 + struct device_node *np, const char *name, const char *fw_name, 265 + unsigned long flags, unsigned int mult, unsigned int div) 266 + { 267 + const struct clk_parent_data pdata = { .index = -1, .fw_name = fw_name }; 268 + 269 + return __clk_hw_register_fixed_factor(dev, np, name, NULL, NULL, 270 + &pdata, flags, mult, div, 0, 0, true); 271 + } 272 + EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_fwname); 273 + 274 + struct clk_hw *devm_clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev, 275 + struct device_node *np, const char *name, const char *fw_name, 276 + unsigned long flags, unsigned int mult, unsigned int div, 277 + unsigned long acc) 278 + { 279 + const struct clk_parent_data pdata = { .index = -1, .fw_name = fw_name }; 280 + 281 + return __clk_hw_register_fixed_factor(dev, np, name, NULL, NULL, 282 + &pdata, flags, mult, div, acc, 283 + CLK_FIXED_FACTOR_FIXED_ACCURACY, true); 284 + } 285 + EXPORT_SYMBOL_GPL(devm_clk_hw_register_fixed_factor_with_accuracy_fwname); 290 286 291 287 #ifdef CONFIG_OF 292 288 static struct clk_hw *_of_fixed_factor_clk_setup(struct device_node *node) 293 289 { 294 290 struct clk_hw *hw; 295 291 const char *clk_name = node->name; 292 + const struct clk_parent_data pdata = { .index = 0 }; 296 293 u32 div, mult; 297 294 int ret; 298 295 ··· 337 280 338 281 of_property_read_string(node, "clock-output-names", &clk_name); 339 282 340 - hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 0, 341 - 0, mult, div, 0, 0, false); 283 + hw = __clk_hw_register_fixed_factor(NULL, node, clk_name, NULL, NULL, 284 + &pdata, 0, mult, div, 0, 0, false); 342 285 if (IS_ERR(hw)) { 343 286 /* 344 287 * Clear OF_POPULATED flag so that clock registration can be
+14
include/linux/clk-provider.h
··· 1116 1116 struct clk_hw *clk_hw_register_fixed_factor(struct device *dev, 1117 1117 const char *name, const char *parent_name, unsigned long flags, 1118 1118 unsigned int mult, unsigned int div); 1119 + struct clk_hw *clk_hw_register_fixed_factor_fwname(struct device *dev, 1120 + struct device_node *np, const char *name, const char *fw_name, 1121 + unsigned long flags, unsigned int mult, unsigned int div); 1122 + struct clk_hw *clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev, 1123 + struct device_node *np, const char *name, const char *fw_name, 1124 + unsigned long flags, unsigned int mult, unsigned int div, 1125 + unsigned long acc); 1119 1126 void clk_hw_unregister_fixed_factor(struct clk_hw *hw); 1120 1127 struct clk_hw *devm_clk_hw_register_fixed_factor(struct device *dev, 1121 1128 const char *name, const char *parent_name, unsigned long flags, 1122 1129 unsigned int mult, unsigned int div); 1130 + struct clk_hw *devm_clk_hw_register_fixed_factor_fwname(struct device *dev, 1131 + struct device_node *np, const char *name, const char *fw_name, 1132 + unsigned long flags, unsigned int mult, unsigned int div); 1133 + struct clk_hw *devm_clk_hw_register_fixed_factor_with_accuracy_fwname(struct device *dev, 1134 + struct device_node *np, const char *name, const char *fw_name, 1135 + unsigned long flags, unsigned int mult, unsigned int div, 1136 + unsigned long acc); 1123 1137 struct clk_hw *devm_clk_hw_register_fixed_factor_index(struct device *dev, 1124 1138 const char *name, unsigned int index, unsigned long flags, 1125 1139 unsigned int mult, unsigned int div);