1 // SPDX-License-Identifier: GPL-2.0
4 * Memory Mapped IO Fixed clock driver
6 * Copyright (C) 2018 Cadence Design Systems, Inc.
9 * Jan Kotas <jank@cadence.com>
12 #include <linux/clk-provider.h>
13 #include <linux/of_address.h>
14 #include <linux/module.h>
15 #include <linux/platform_device.h>
17 static struct clk_hw *fixed_mmio_clk_setup(struct device_node *node)
20 const char *clk_name = node->name;
25 base = of_iomap(node, 0);
27 pr_err("%pOFn: failed to map address\n", node);
33 of_property_read_string(node, "clock-output-names", &clk_name);
35 clk = clk_hw_register_fixed_rate(NULL, clk_name, NULL, 0, freq);
37 pr_err("%pOFn: failed to register fixed rate clock\n", node);
41 ret = of_clk_add_hw_provider(node, of_clk_hw_simple_get, clk);
43 pr_err("%pOFn: failed to add clock provider\n", node);
44 clk_hw_unregister(clk);
51 static void __init of_fixed_mmio_clk_setup(struct device_node *node)
53 fixed_mmio_clk_setup(node);
55 CLK_OF_DECLARE(fixed_mmio_clk, "fixed-mmio-clock", of_fixed_mmio_clk_setup);
58 * This is not executed when of_fixed_mmio_clk_setup succeeded.
60 static int of_fixed_mmio_clk_probe(struct platform_device *pdev)
64 clk = fixed_mmio_clk_setup(pdev->dev.of_node);
68 platform_set_drvdata(pdev, clk);
73 static int of_fixed_mmio_clk_remove(struct platform_device *pdev)
75 struct clk_hw *clk = platform_get_drvdata(pdev);
77 of_clk_del_provider(pdev->dev.of_node);
78 clk_hw_unregister_fixed_rate(clk);
83 static const struct of_device_id of_fixed_mmio_clk_ids[] = {
84 { .compatible = "fixed-mmio-clock" },
87 MODULE_DEVICE_TABLE(of, of_fixed_mmio_clk_ids);
89 static struct platform_driver of_fixed_mmio_clk_driver = {
91 .name = "of_fixed_mmio_clk",
92 .of_match_table = of_fixed_mmio_clk_ids,
94 .probe = of_fixed_mmio_clk_probe,
95 .remove = of_fixed_mmio_clk_remove,
97 module_platform_driver(of_fixed_mmio_clk_driver);
99 MODULE_AUTHOR("Jan Kotas <jank@cadence.com>");
100 MODULE_DESCRIPTION("Memory Mapped IO Fixed clock driver");
101 MODULE_LICENSE("GPL v2");