4 * Copyright (C) 2013 Texas Instruments, Inc.
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.
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.
18 #include <linux/clk-provider.h>
19 #include <linux/clkdev.h>
20 #include <linux/clk/ti.h>
22 #include <linux/of_address.h>
23 #include <linux/list.h>
26 #define pr_fmt(fmt) "%s: " fmt, __func__
28 struct ti_clk_ll_ops *ti_clk_ll_ops;
29 static struct device_node *clocks_node_ptr[CLK_MAX_MEMMAPS];
32 * ti_dt_clocks_register - register DT alias clocks during boot
33 * @oclks: list of clocks to register
35 * Register alias or non-standard DT clock entries during boot. By
36 * default, DT clocks are found based on their node name. If any
37 * additional con-id / dev-id -> clock mapping is required, use this
38 * function to list these.
40 void __init ti_dt_clocks_register(struct ti_dt_clk oclks[])
43 struct device_node *node;
45 struct of_phandle_args clkspec;
47 for (c = oclks; c->node_name != NULL; c++) {
48 node = of_find_node_by_name(NULL, c->node_name);
50 clk = of_clk_get_from_provider(&clkspec);
56 pr_warn("failed to lookup clock node %s\n",
62 struct clk_init_item {
63 struct device_node *node;
65 ti_of_clk_init_cb_t func;
66 struct list_head link;
69 static LIST_HEAD(retry_list);
72 * ti_clk_retry_init - retries a failed clock init at later phase
73 * @node: device not for the clock
74 * @hw: partially initialized clk_hw struct for the clock
75 * @func: init function to be called for the clock
77 * Adds a failed clock init to the retry list. The retry list is parsed
78 * once all the other clocks have been initialized.
80 int __init ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
81 ti_of_clk_init_cb_t func)
83 struct clk_init_item *retry;
85 pr_debug("%s: adding to retry list...\n", node->name);
86 retry = kzalloc(sizeof(*retry), GFP_KERNEL);
93 list_add(&retry->link, &retry_list);
99 * ti_clk_get_reg_addr - get register address for a clock register
100 * @node: device node for the clock
101 * @index: register index from the clock node
103 * Builds clock register address from device tree information. This
104 * is a struct of type clk_omap_reg.
106 void __iomem *ti_clk_get_reg_addr(struct device_node *node, int index)
108 struct clk_omap_reg *reg;
113 reg = (struct clk_omap_reg *)&tmp;
115 for (i = 0; i < CLK_MAX_MEMMAPS; i++) {
116 if (clocks_node_ptr[i] == node->parent)
120 if (i == CLK_MAX_MEMMAPS) {
121 pr_err("clk-provider not found for %s!\n", node->name);
127 if (of_property_read_u32_index(node, "reg", index, &val)) {
128 pr_err("%s must have reg[%d]!\n", node->name, index);
134 return (void __iomem *)tmp;
138 * ti_dt_clk_init_provider - init master clock provider
139 * @parent: master node
140 * @index: internal index for clk_reg_ops
142 * Initializes a master clock IP block. This basically sets up the
143 * mapping from clocks node to the memory map index. All the clocks
144 * are then initialized through the common of_clk_init call, and the
145 * clocks will access their memory maps based on the node layout.
147 void ti_dt_clk_init_provider(struct device_node *parent, int index)
149 struct device_node *clocks;
151 /* get clocks for this parent */
152 clocks = of_get_child_by_name(parent, "clocks");
154 pr_err("%s missing 'clocks' child node.\n", parent->name);
158 /* add clocks node info */
159 clocks_node_ptr[index] = clocks;
163 * ti_dt_clk_init_retry_clks - init clocks from the retry list
165 * Initializes any clocks that have failed to initialize before,
166 * reasons being missing parent node(s) during earlier init. This
167 * typically happens only for DPLLs which need to have both of their
168 * parent clocks ready during init.
170 void ti_dt_clk_init_retry_clks(void)
172 struct clk_init_item *retry;
173 struct clk_init_item *tmp;
176 while (!list_empty(&retry_list) && retries) {
177 list_for_each_entry_safe(retry, tmp, &retry_list, link) {
178 pr_debug("retry-init: %s\n", retry->node->name);
179 retry->func(retry->hw, retry->node);
180 list_del(&retry->link);