blob: 41eb5d1058462530d38bee93df651403591d18e5 [file] [log] [blame]
Tero Kristo3cd4a592013-08-21 19:39:15 +03001/*
2 * OMAP clockdomain support
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * Tero Kristo <t-kristo@ti.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 */
17
Stephen Boyd1b29e602015-06-19 15:00:46 -070018#include <linux/clk.h>
Tero Kristo3cd4a592013-08-21 19:39:15 +030019#include <linux/clk-provider.h>
20#include <linux/slab.h>
21#include <linux/of.h>
22#include <linux/of_address.h>
23#include <linux/clk/ti.h>
24
25#undef pr_fmt
26#define pr_fmt(fmt) "%s: " fmt, __func__
27
28static void __init of_ti_clockdomain_setup(struct device_node *node)
29{
30 struct clk *clk;
31 struct clk_hw *clk_hw;
32 const char *clkdm_name = node->name;
33 int i;
34 int num_clks;
35
Geert Uytterhoevenf71355b2015-05-29 11:25:47 +020036 num_clks = of_clk_get_parent_count(node);
Tero Kristo3cd4a592013-08-21 19:39:15 +030037
38 for (i = 0; i < num_clks; i++) {
39 clk = of_clk_get(node, i);
Sebastian Andrzej Siewior319f1272014-09-18 16:33:27 +020040 if (IS_ERR(clk)) {
41 pr_err("%s: Failed get %s' clock nr %d (%ld)\n",
42 __func__, node->full_name, i, PTR_ERR(clk));
43 continue;
44 }
Tero Kristo3cd4a592013-08-21 19:39:15 +030045 if (__clk_get_flags(clk) & CLK_IS_BASIC) {
46 pr_warn("can't setup clkdm for basic clk %s\n",
47 __clk_get_name(clk));
48 continue;
49 }
50 clk_hw = __clk_get_hw(clk);
51 to_clk_hw_omap(clk_hw)->clkdm_name = clkdm_name;
52 omap2_init_clk_clkdm(clk_hw);
53 }
54}
55
Fabian Frederickf3755732015-03-31 20:50:42 +020056static const struct of_device_id ti_clkdm_match_table[] __initconst = {
Tero Kristo3cd4a592013-08-21 19:39:15 +030057 { .compatible = "ti,clockdomain" },
58 { }
59};
60
61/**
62 * ti_dt_clockdomains_setup - setup device tree clockdomains
63 *
64 * Initializes clockdomain nodes for a SoC. This parses through all the
65 * nodes with compatible = "ti,clockdomain", and add the clockdomain
66 * info for all the clocks listed under these. This function shall be
67 * called after rest of the DT clock init has completed and all
68 * clock nodes have been registered.
69 */
70void __init ti_dt_clockdomains_setup(void)
71{
72 struct device_node *np;
73 for_each_matching_node(np, ti_clkdm_match_table) {
74 of_ti_clockdomain_setup(np);
75 }
76}