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