5a3c6d9b5a99a26a3076a6c33c35ce13b3817bc9
1 /*
2 * Texas Instruments OMAP Clock driver
3 *
4 * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com/
5 * Nishanth Menon <nm@ti.com>
6 * Tony Lindgren <tony@atomide.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 *
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
18 #include <linux/clkdev.h>
19 #include <linux/clk-provider.h>
20 #include <linux/kernel.h>
21 #include <linux/module.h>
22 #include <linux/of_device.h>
23 #include <linux/platform_device.h>
24 #include <linux/string.h>
26 static const struct of_device_id omap_clk_of_match[] = {
27 {.compatible = "ti,omap-clock",},
28 {},
29 };
31 /**
32 * omap_clk_src_get() - Get OMAP clock from node name when needed
33 * @clkspec: clkspec argument
34 * @data: unused
35 *
36 * REVISIT: We assume the following:
37 * 1. omap clock names end with _ck
38 * 2. omap clock names are under 32 characters in length
39 */
40 static struct clk *omap_clk_src_get(struct of_phandle_args *clkspec, void *data)
41 {
42 struct clk *clk;
43 char clk_name[32];
44 struct device_node *np = clkspec->np;
46 snprintf(clk_name, 32, "%s_ck", np->name);
47 clk = clk_get(NULL, clk_name);
48 if (IS_ERR(clk))
49 pr_err("%s: could not get clock %s(%ld)\n", __func__,
50 clk_name, PTR_ERR(clk));
52 return clk;
53 }
55 /**
56 * omap_clk_probe() - create link from DT definition to clock data
57 * @pdev: device node
58 *
59 * NOTE: we look up the clock lazily when the consumer driver does
60 * of_clk_get() and initialize a NULL clock here.
61 */
62 static int omap_clk_probe(struct platform_device *pdev)
63 {
64 int res;
65 struct device_node *np = pdev->dev.of_node;
67 /* This allows the driver to of_clk_get() */
68 res = of_clk_add_provider(np, omap_clk_src_get, NULL);
69 if (res)
70 dev_err(&pdev->dev, "could not add provider(%d)\n", res);
72 return res;
73 }
75 static struct platform_driver omap_clk_driver = {
76 .probe = omap_clk_probe,
77 .driver = {
78 .name = "omap_clk",
79 .of_match_table = of_match_ptr(omap_clk_of_match),
80 },
81 };
83 static int __init omap_clk_init(void)
84 {
85 return platform_driver_register(&omap_clk_driver);
86 }
87 arch_initcall(omap_clk_init);
89 MODULE_DESCRIPTION("OMAP Clock driver");
90 MODULE_AUTHOR("Texas Instruments Inc.");
91 MODULE_LICENSE("GPL v2");