15a729246SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only
21f847c65STero Kristo /*
31f847c65STero Kristo * TI Fixed Factor Clock
41f847c65STero Kristo *
51f847c65STero Kristo * Copyright (C) 2013 Texas Instruments, Inc.
61f847c65STero Kristo *
71f847c65STero Kristo * Tero Kristo <t-kristo@ti.com>
81f847c65STero Kristo */
91f847c65STero Kristo
101f847c65STero Kristo #include <linux/clk-provider.h>
111f847c65STero Kristo #include <linux/slab.h>
121f847c65STero Kristo #include <linux/err.h>
131f847c65STero Kristo #include <linux/of.h>
141f847c65STero Kristo #include <linux/of_address.h>
151f847c65STero Kristo #include <linux/clk/ti.h>
161f847c65STero Kristo
17bf22bae7STero Kristo #include "clock.h"
18bf22bae7STero Kristo
191f847c65STero Kristo #undef pr_fmt
201f847c65STero Kristo #define pr_fmt(fmt) "%s: " fmt, __func__
211f847c65STero Kristo
221f847c65STero Kristo /**
231f847c65STero Kristo * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock
241f847c65STero Kristo * @node: device node for this clock
251f847c65STero Kristo *
261f847c65STero Kristo * Sets up a simple fixed factor clock based on device tree info.
271f847c65STero Kristo */
of_ti_fixed_factor_clk_setup(struct device_node * node)281f847c65STero Kristo static void __init of_ti_fixed_factor_clk_setup(struct device_node *node)
291f847c65STero Kristo {
301f847c65STero Kristo struct clk *clk;
31ed06099cSTony Lindgren const char *clk_name = ti_dt_clk_name(node);
321f847c65STero Kristo const char *parent_name;
331f847c65STero Kristo u32 div, mult;
341f847c65STero Kristo u32 flags = 0;
351f847c65STero Kristo
361f847c65STero Kristo if (of_property_read_u32(node, "ti,clock-div", &div)) {
37e665f029SRob Herring pr_err("%pOFn must have a clock-div property\n", node);
381f847c65STero Kristo return;
391f847c65STero Kristo }
401f847c65STero Kristo
411f847c65STero Kristo if (of_property_read_u32(node, "ti,clock-mult", &mult)) {
42e665f029SRob Herring pr_err("%pOFn must have a clock-mult property\n", node);
431f847c65STero Kristo return;
441f847c65STero Kristo }
451f847c65STero Kristo
461f847c65STero Kristo if (of_property_read_bool(node, "ti,set-rate-parent"))
471f847c65STero Kristo flags |= CLK_SET_RATE_PARENT;
481f847c65STero Kristo
491f847c65STero Kristo parent_name = of_clk_get_parent_name(node, 0);
501f847c65STero Kristo
511f847c65STero Kristo clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags,
521f847c65STero Kristo mult, div);
531f847c65STero Kristo
541f847c65STero Kristo if (!IS_ERR(clk)) {
551f847c65STero Kristo of_clk_add_provider(node, of_clk_src_simple_get, clk);
561f847c65STero Kristo of_ti_clk_autoidle_setup(node);
57*3400d546SDario Binacchi ti_clk_add_alias(clk, clk_name);
581f847c65STero Kristo }
591f847c65STero Kristo }
601f847c65STero Kristo CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock",
611f847c65STero Kristo of_ti_fixed_factor_clk_setup);
62