1*4882a593Smuzhiyun /*
2*4882a593Smuzhiyun * TI Fixed Factor Clock
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Copyright (C) 2013 Texas Instruments, Inc.
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun * Tero Kristo <t-kristo@ti.com>
7*4882a593Smuzhiyun *
8*4882a593Smuzhiyun * This program is free software; you can redistribute it and/or modify
9*4882a593Smuzhiyun * it under the terms of the GNU General Public License version 2 as
10*4882a593Smuzhiyun * published by the Free Software Foundation.
11*4882a593Smuzhiyun *
12*4882a593Smuzhiyun * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13*4882a593Smuzhiyun * kind, whether express or implied; without even the implied warranty
14*4882a593Smuzhiyun * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15*4882a593Smuzhiyun * GNU General Public License for more details.
16*4882a593Smuzhiyun */
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun #include <linux/clk-provider.h>
19*4882a593Smuzhiyun #include <linux/slab.h>
20*4882a593Smuzhiyun #include <linux/err.h>
21*4882a593Smuzhiyun #include <linux/of.h>
22*4882a593Smuzhiyun #include <linux/of_address.h>
23*4882a593Smuzhiyun #include <linux/clk/ti.h>
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun #include "clock.h"
26*4882a593Smuzhiyun
27*4882a593Smuzhiyun #undef pr_fmt
28*4882a593Smuzhiyun #define pr_fmt(fmt) "%s: " fmt, __func__
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun /**
31*4882a593Smuzhiyun * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
32*4882a593Smuzhiyun * @node: device node for this clock
33*4882a593Smuzhiyun *
34*4882a593Smuzhiyun * Sets up a simple fixed factor clock based on device tree info.
35*4882a593Smuzhiyun */
of_ti_fixed_factor_clk_setup(struct device_node * node)36*4882a593Smuzhiyun static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
37*4882a593Smuzhiyun {
38*4882a593Smuzhiyun struct clk *clk;
39*4882a593Smuzhiyun const char *clk_name = node->name;
40*4882a593Smuzhiyun const char *parent_name;
41*4882a593Smuzhiyun u32 div, mult;
42*4882a593Smuzhiyun u32 flags = 0;
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun if (of_property_read_u32(node, "ti,clock-div", &div)) {
45*4882a593Smuzhiyun pr_err("%pOFn must have a clock-div property\n", node);
46*4882a593Smuzhiyun return;
47*4882a593Smuzhiyun }
48*4882a593Smuzhiyun
49*4882a593Smuzhiyun if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
50*4882a593Smuzhiyun pr_err("%pOFn must have a clock-mult property\n", node);
51*4882a593Smuzhiyun return;
52*4882a593Smuzhiyun }
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun if (of_property_read_bool(node, "ti,set-rate-parent"))
55*4882a593Smuzhiyun flags |= CLK_SET_RATE_PARENT;
56*4882a593Smuzhiyun
57*4882a593Smuzhiyun parent_name = of_clk_get_parent_name(node, 0);
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
60*4882a593Smuzhiyun mult, div);
61*4882a593Smuzhiyun
62*4882a593Smuzhiyun if (!IS_ERR(clk)) {
63*4882a593Smuzhiyun of_clk_add_provider(node, of_clk_src_simple_get, clk);
64*4882a593Smuzhiyun of_ti_clk_autoidle_setup(node);
65*4882a593Smuzhiyun ti_clk_add_alias(NULL, clk, clk_name);
66*4882a593Smuzhiyun }
67*4882a593Smuzhiyun }
68*4882a593Smuzhiyun CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
69*4882a593Smuzhiyun of_ti_fixed_factor_clk_setup);
70