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

clk: fixed-rate: Convert into a module platform driver

Adds support for fixed-rate clock providers which have not been
enabled via of_clk_init().

This is required by Device trees overlays that introduce clocks
providers.

Signed-off-by: Ricardo Ribalda Delgado <ricardo.ribalda@gmail.com>
[sboyd@codeaurora.org: Make new private function static, don't
check clk for NULL when unregistering in driver remove]
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>

authored by

Ricardo Ribalda Delgado and committed by
Stephen Boyd
435779fe 971451b3

+64 -7
+64 -7
drivers/clk/clk-fixed-rate.c
··· 15 15 #include <linux/io.h> 16 16 #include <linux/err.h> 17 17 #include <linux/of.h> 18 + #include <linux/platform_device.h> 18 19 19 20 /* 20 21 * DOC: basic fixed-rate clock that cannot gate ··· 158 157 EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_rate); 159 158 160 159 #ifdef CONFIG_OF 161 - /** 162 - * of_fixed_clk_setup() - Setup function for simple fixed rate clock 163 - */ 164 - void of_fixed_clk_setup(struct device_node *node) 160 + static struct clk *_of_fixed_clk_setup(struct device_node *node) 165 161 { 166 162 struct clk *clk; 167 163 const char *clk_name = node->name; 168 164 u32 rate; 169 165 u32 accuracy = 0; 166 + int ret; 170 167 171 168 if (of_property_read_u32(node, "clock-frequency", &rate)) 172 - return; 169 + return ERR_PTR(-EIO); 173 170 174 171 of_property_read_u32(node, "clock-accuracy", &accuracy); 175 172 ··· 175 176 176 177 clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL, 177 178 0, rate, accuracy); 178 - if (!IS_ERR(clk)) 179 - of_clk_add_provider(node, of_clk_src_simple_get, clk); 179 + if (IS_ERR(clk)) 180 + return clk; 181 + 182 + ret = of_clk_add_provider(node, of_clk_src_simple_get, clk); 183 + if (ret) { 184 + clk_unregister(clk); 185 + return ERR_PTR(ret); 186 + } 187 + 188 + return clk; 189 + } 190 + 191 + /** 192 + * of_fixed_clk_setup() - Setup function for simple fixed rate clock 193 + */ 194 + void of_fixed_clk_setup(struct device_node *node) 195 + { 196 + _of_fixed_clk_setup(node); 180 197 } 181 198 EXPORT_SYMBOL_GPL(of_fixed_clk_setup); 182 199 CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup); 200 + 201 + static int of_fixed_clk_remove(struct platform_device *pdev) 202 + { 203 + struct clk *clk = platform_get_drvdata(pdev); 204 + 205 + clk_unregister_fixed_rate(clk); 206 + 207 + return 0; 208 + } 209 + 210 + static int of_fixed_clk_probe(struct platform_device *pdev) 211 + { 212 + struct clk *clk; 213 + 214 + /* 215 + * This function is not executed when of_fixed_clk_setup 216 + * succeeded. 217 + */ 218 + clk = _of_fixed_clk_setup(pdev->dev.of_node); 219 + if (IS_ERR(clk)) 220 + return PTR_ERR(clk); 221 + 222 + platform_set_drvdata(pdev, clk); 223 + 224 + return 0; 225 + } 226 + 227 + static const struct of_device_id of_fixed_clk_ids[] = { 228 + { .compatible = "fixed-clock" }, 229 + { } 230 + }; 231 + MODULE_DEVICE_TABLE(of, of_fixed_clk_ids); 232 + 233 + static struct platform_driver of_fixed_clk_driver = { 234 + .driver = { 235 + .name = "of_fixed_clk", 236 + .of_match_table = of_fixed_clk_ids, 237 + }, 238 + .probe = of_fixed_clk_probe, 239 + .remove = of_fixed_clk_remove, 240 + }; 241 + builtin_platform_driver(of_fixed_clk_driver); 183 242 #endif