1/* 2 * OMAP interface clock support 3 * 4 * Copyright (C) 2013 Texas Instruments, Inc. 5 * 6 * Tero Kristo <t-kristo@ti.com> 7 * 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. 11 * 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. 16 */ 17 18#include <linux/clk-provider.h> 19#include <linux/slab.h> 20#include <linux/of.h> 21#include <linux/of_address.h> 22#include <linux/clk/ti.h> 23#include "clock.h" 24 25#undef pr_fmt 26#define pr_fmt(fmt) "%s: " fmt, __func__ 27 28static const struct clk_ops ti_interface_clk_ops = { 29 .init = &omap2_init_clk_clkdm, 30 .enable = &omap2_dflt_clk_enable, 31 .disable = &omap2_dflt_clk_disable, 32 .is_enabled = &omap2_dflt_clk_is_enabled, 33}; 34 35static struct clk *_register_interface(struct device_node *node, 36 const char *name, 37 const char *parent_name, 38 struct clk_omap_reg *reg, u8 bit_idx, 39 const struct clk_hw_omap_ops *ops) 40{ 41 struct clk_init_data init = { NULL }; 42 struct clk_hw_omap *clk_hw; 43 struct clk *clk; 44 45 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 46 if (!clk_hw) 47 return ERR_PTR(-ENOMEM); 48 49 clk_hw->hw.init = &init; 50 clk_hw->ops = ops; 51 memcpy(&clk_hw->enable_reg, reg, sizeof(*reg)); 52 clk_hw->enable_bit = bit_idx; 53 54 init.name = name; 55 init.ops = &ti_interface_clk_ops; 56 init.flags = 0; 57 58 init.num_parents = 1; 59 init.parent_names = &parent_name; 60 61 clk = of_ti_clk_register_omap_hw(node, &clk_hw->hw, name); 62 63 if (IS_ERR(clk)) 64 kfree(clk_hw); 65 66 return clk; 67} 68 69static void __init _of_ti_interface_clk_setup(struct device_node *node, 70 const struct clk_hw_omap_ops *ops) 71{ 72 struct clk *clk; 73 const char *parent_name; 74 struct clk_omap_reg reg; 75 u8 enable_bit = 0; 76 const char *name; 77 u32 val; 78 79 if (ti_clk_get_reg_addr(node, 0, ®)) 80 return; 81 82 if (!of_property_read_u32(node, "ti,bit-shift", &val)) 83 enable_bit = val; 84 85 parent_name = of_clk_get_parent_name(node, 0); 86 if (!parent_name) { 87 pr_err("%pOFn must have a parent\n", node); 88 return; 89 } 90 91 name = ti_dt_clk_name(node); 92 clk = _register_interface(node, name, parent_name, ®, 93 enable_bit, ops); 94 95 if (!IS_ERR(clk)) 96 of_clk_add_provider(node, of_clk_src_simple_get, clk); 97} 98 99static void __init of_ti_interface_clk_setup(struct device_node *node) 100{ 101 _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait); 102} 103CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock", 104 of_ti_interface_clk_setup); 105 106static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node) 107{ 108 _of_ti_interface_clk_setup(node, &clkhwops_iclk); 109} 110CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock", 111 of_ti_no_wait_interface_clk_setup); 112 113#ifdef CONFIG_ARCH_OMAP3 114static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node) 115{ 116 _of_ti_interface_clk_setup(node, 117 &clkhwops_omap3430es2_iclk_hsotgusb_wait); 118} 119CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock", 120 of_ti_hsotgusb_interface_clk_setup); 121 122static void __init of_ti_dss_interface_clk_setup(struct device_node *node) 123{ 124 _of_ti_interface_clk_setup(node, 125 &clkhwops_omap3430es2_iclk_dss_usbhost_wait); 126} 127CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock", 128 of_ti_dss_interface_clk_setup); 129 130static void __init of_ti_ssi_interface_clk_setup(struct device_node *node) 131{ 132 _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait); 133} 134CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock", 135 of_ti_ssi_interface_clk_setup); 136 137static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node) 138{ 139 _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait); 140} 141CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock", 142 of_ti_am35xx_interface_clk_setup); 143#endif 144 145#ifdef CONFIG_SOC_OMAP2430 146static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node) 147{ 148 _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait); 149} 150CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock", 151 of_ti_omap2430_interface_clk_setup); 152#endif 153