11f847c65STero Kristo /* 21f847c65STero Kristo * TI Fixed Factor Clock 31f847c65STero Kristo * 41f847c65STero Kristo * Copyright (C) 2013 Texas Instruments, Inc. 51f847c65STero Kristo * 61f847c65STero Kristo * Tero Kristo <t-kristo@ti.com> 71f847c65STero Kristo * 81f847c65STero Kristo * This program is free software; you can redistribute it and/or modify 91f847c65STero Kristo * it under the terms of the GNU General Public License version 2 as 101f847c65STero Kristo * published by the Free Software Foundation. 111f847c65STero Kristo * 121f847c65STero Kristo * This program is distributed "as is" WITHOUT ANY WARRANTY of any 131f847c65STero Kristo * kind, whether express or implied; without even the implied warranty 141f847c65STero Kristo * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 151f847c65STero Kristo * GNU General Public License for more details. 161f847c65STero Kristo */ 171f847c65STero Kristo 181f847c65STero Kristo #include <linux/clk-provider.h> 191f847c65STero Kristo #include <linux/slab.h> 201f847c65STero Kristo #include <linux/err.h> 211f847c65STero Kristo #include <linux/of.h> 221f847c65STero Kristo #include <linux/of_address.h> 231f847c65STero Kristo #include <linux/clk/ti.h> 241f847c65STero Kristo 25bf22bae7STero Kristo #include "clock.h" 26bf22bae7STero Kristo 271f847c65STero Kristo #undef pr_fmt 281f847c65STero Kristo #define pr_fmt(fmt) "%s: " fmt, __func__ 291f847c65STero Kristo 301f847c65STero Kristo /** 311f847c65STero Kristo * of_ti_fixed_factor_clk_setup - Setup function for TI fixed factor clock 321f847c65STero Kristo * @node: device node for this clock 331f847c65STero Kristo * 341f847c65STero Kristo * Sets up a simple fixed factor clock based on device tree info. 351f847c65STero Kristo */ 361f847c65STero Kristo static void __init of_ti_fixed_factor_clk_setup(struct device_node *node) 371f847c65STero Kristo { 381f847c65STero Kristo struct clk *clk; 391f847c65STero Kristo const char *clk_name = node->name; 401f847c65STero Kristo const char *parent_name; 411f847c65STero Kristo u32 div, mult; 421f847c65STero Kristo u32 flags = 0; 431f847c65STero Kristo 441f847c65STero Kristo if (of_property_read_u32(node, "ti,clock-div", &div)) { 45*e665f029SRob Herring pr_err("%pOFn must have a clock-div property\n", node); 461f847c65STero Kristo return; 471f847c65STero Kristo } 481f847c65STero Kristo 491f847c65STero Kristo if (of_property_read_u32(node, "ti,clock-mult", &mult)) { 50*e665f029SRob Herring pr_err("%pOFn must have a clock-mult property\n", node); 511f847c65STero Kristo return; 521f847c65STero Kristo } 531f847c65STero Kristo 541f847c65STero Kristo if (of_property_read_bool(node, "ti,set-rate-parent")) 551f847c65STero Kristo flags |= CLK_SET_RATE_PARENT; 561f847c65STero Kristo 571f847c65STero Kristo parent_name = of_clk_get_parent_name(node, 0); 581f847c65STero Kristo 591f847c65STero Kristo clk = clk_register_fixed_factor(NULL, clk_name, parent_name, flags, 601f847c65STero Kristo mult, div); 611f847c65STero Kristo 621f847c65STero Kristo if (!IS_ERR(clk)) { 631f847c65STero Kristo of_clk_add_provider(node, of_clk_src_simple_get, clk); 641f847c65STero Kristo of_ti_clk_autoidle_setup(node); 651ae79c46STero Kristo ti_clk_add_alias(NULL, clk, clk_name); 661f847c65STero Kristo } 671f847c65STero Kristo } 681f847c65STero Kristo CLK_OF_DECLARE(ti_fixed_factor_clk, "ti,fixed-factor-clock", 691f847c65STero Kristo of_ti_fixed_factor_clk_setup); 70