clk: Tag basic clk types with SPDX
[sfrench/cifs-2.6.git] / drivers / clk / clk-fixed-rate.c
index 2edb39342a02a8d6397c9f9cef9ccdcd95f6e656..00ef4f5e53fe247d946100efcfe5ee93d12fa642 100644 (file)
@@ -1,11 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2010-2011 Canonical Ltd <jeremy.kerr@canonical.com>
  * Copyright (C) 2011-2012 Mike Turquette, Linaro Ltd <mturquette@linaro.org>
  *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
  * Fixed rate clock implementation
  */
 
@@ -15,6 +12,7 @@
 #include <linux/io.h>
 #include <linux/err.h>
 #include <linux/of.h>
+#include <linux/platform_device.h>
 
 /*
  * DOC: basic fixed-rate clock that cannot gate
@@ -157,18 +155,16 @@ void clk_hw_unregister_fixed_rate(struct clk_hw *hw)
 EXPORT_SYMBOL_GPL(clk_hw_unregister_fixed_rate);
 
 #ifdef CONFIG_OF
-/**
- * of_fixed_clk_setup() - Setup function for simple fixed rate clock
- */
-void of_fixed_clk_setup(struct device_node *node)
+static struct clk *_of_fixed_clk_setup(struct device_node *node)
 {
        struct clk *clk;
        const char *clk_name = node->name;
        u32 rate;
        u32 accuracy = 0;
+       int ret;
 
        if (of_property_read_u32(node, "clock-frequency", &rate))
-               return;
+               return ERR_PTR(-EIO);
 
        of_property_read_u32(node, "clock-accuracy", &accuracy);
 
@@ -176,9 +172,67 @@ void of_fixed_clk_setup(struct device_node *node)
 
        clk = clk_register_fixed_rate_with_accuracy(NULL, clk_name, NULL,
                                                    0, rate, accuracy);
-       if (!IS_ERR(clk))
-               of_clk_add_provider(node, of_clk_src_simple_get, clk);
+       if (IS_ERR(clk))
+               return clk;
+
+       ret = of_clk_add_provider(node, of_clk_src_simple_get, clk);
+       if (ret) {
+               clk_unregister(clk);
+               return ERR_PTR(ret);
+       }
+
+       return clk;
+}
+
+/**
+ * of_fixed_clk_setup() - Setup function for simple fixed rate clock
+ */
+void __init of_fixed_clk_setup(struct device_node *node)
+{
+       _of_fixed_clk_setup(node);
 }
-EXPORT_SYMBOL_GPL(of_fixed_clk_setup);
 CLK_OF_DECLARE(fixed_clk, "fixed-clock", of_fixed_clk_setup);
+
+static int of_fixed_clk_remove(struct platform_device *pdev)
+{
+       struct clk *clk = platform_get_drvdata(pdev);
+
+       of_clk_del_provider(pdev->dev.of_node);
+       clk_unregister_fixed_rate(clk);
+
+       return 0;
+}
+
+static int of_fixed_clk_probe(struct platform_device *pdev)
+{
+       struct clk *clk;
+
+       /*
+        * This function is not executed when of_fixed_clk_setup
+        * succeeded.
+        */
+       clk = _of_fixed_clk_setup(pdev->dev.of_node);
+       if (IS_ERR(clk))
+               return PTR_ERR(clk);
+
+       platform_set_drvdata(pdev, clk);
+
+       return 0;
+}
+
+static const struct of_device_id of_fixed_clk_ids[] = {
+       { .compatible = "fixed-clock" },
+       { }
+};
+MODULE_DEVICE_TABLE(of, of_fixed_clk_ids);
+
+static struct platform_driver of_fixed_clk_driver = {
+       .driver = {
+               .name = "of_fixed_clk",
+               .of_match_table = of_fixed_clk_ids,
+       },
+       .probe = of_fixed_clk_probe,
+       .remove = of_fixed_clk_remove,
+};
+builtin_platform_driver(of_fixed_clk_driver);
 #endif