1*24582b34STero Kristo /* 2*24582b34STero Kristo * OMAP interface clock support 3*24582b34STero Kristo * 4*24582b34STero Kristo * Copyright (C) 2013 Texas Instruments, Inc. 5*24582b34STero Kristo * 6*24582b34STero Kristo * Tero Kristo <t-kristo@ti.com> 7*24582b34STero Kristo * 8*24582b34STero Kristo * This program is free software; you can redistribute it and/or modify 9*24582b34STero Kristo * it under the terms of the GNU General Public License version 2 as 10*24582b34STero Kristo * published by the Free Software Foundation. 11*24582b34STero Kristo * 12*24582b34STero Kristo * This program is distributed "as is" WITHOUT ANY WARRANTY of any 13*24582b34STero Kristo * kind, whether express or implied; without even the implied warranty 14*24582b34STero Kristo * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*24582b34STero Kristo * GNU General Public License for more details. 16*24582b34STero Kristo */ 17*24582b34STero Kristo 18*24582b34STero Kristo #include <linux/clk-provider.h> 19*24582b34STero Kristo #include <linux/slab.h> 20*24582b34STero Kristo #include <linux/of.h> 21*24582b34STero Kristo #include <linux/of_address.h> 22*24582b34STero Kristo #include <linux/clk/ti.h> 23*24582b34STero Kristo 24*24582b34STero Kristo #undef pr_fmt 25*24582b34STero Kristo #define pr_fmt(fmt) "%s: " fmt, __func__ 26*24582b34STero Kristo 27*24582b34STero Kristo static const struct clk_ops ti_interface_clk_ops = { 28*24582b34STero Kristo .init = &omap2_init_clk_clkdm, 29*24582b34STero Kristo .enable = &omap2_dflt_clk_enable, 30*24582b34STero Kristo .disable = &omap2_dflt_clk_disable, 31*24582b34STero Kristo .is_enabled = &omap2_dflt_clk_is_enabled, 32*24582b34STero Kristo }; 33*24582b34STero Kristo 34*24582b34STero Kristo static void __init _of_ti_interface_clk_setup(struct device_node *node, 35*24582b34STero Kristo const struct clk_hw_omap_ops *ops) 36*24582b34STero Kristo { 37*24582b34STero Kristo struct clk *clk; 38*24582b34STero Kristo struct clk_init_data init = { NULL }; 39*24582b34STero Kristo struct clk_hw_omap *clk_hw; 40*24582b34STero Kristo const char *parent_name; 41*24582b34STero Kristo u32 val; 42*24582b34STero Kristo 43*24582b34STero Kristo clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 44*24582b34STero Kristo if (!clk_hw) 45*24582b34STero Kristo return; 46*24582b34STero Kristo 47*24582b34STero Kristo clk_hw->hw.init = &init; 48*24582b34STero Kristo clk_hw->ops = ops; 49*24582b34STero Kristo clk_hw->flags = MEMMAP_ADDRESSING; 50*24582b34STero Kristo 51*24582b34STero Kristo clk_hw->enable_reg = ti_clk_get_reg_addr(node, 0); 52*24582b34STero Kristo if (!clk_hw->enable_reg) 53*24582b34STero Kristo goto cleanup; 54*24582b34STero Kristo 55*24582b34STero Kristo if (!of_property_read_u32(node, "ti,bit-shift", &val)) 56*24582b34STero Kristo clk_hw->enable_bit = val; 57*24582b34STero Kristo 58*24582b34STero Kristo init.name = node->name; 59*24582b34STero Kristo init.ops = &ti_interface_clk_ops; 60*24582b34STero Kristo init.flags = 0; 61*24582b34STero Kristo 62*24582b34STero Kristo parent_name = of_clk_get_parent_name(node, 0); 63*24582b34STero Kristo if (!parent_name) { 64*24582b34STero Kristo pr_err("%s must have a parent\n", node->name); 65*24582b34STero Kristo goto cleanup; 66*24582b34STero Kristo } 67*24582b34STero Kristo 68*24582b34STero Kristo init.num_parents = 1; 69*24582b34STero Kristo init.parent_names = &parent_name; 70*24582b34STero Kristo 71*24582b34STero Kristo clk = clk_register(NULL, &clk_hw->hw); 72*24582b34STero Kristo 73*24582b34STero Kristo if (!IS_ERR(clk)) { 74*24582b34STero Kristo of_clk_add_provider(node, of_clk_src_simple_get, clk); 75*24582b34STero Kristo omap2_init_clk_hw_omap_clocks(clk); 76*24582b34STero Kristo return; 77*24582b34STero Kristo } 78*24582b34STero Kristo 79*24582b34STero Kristo cleanup: 80*24582b34STero Kristo kfree(clk_hw); 81*24582b34STero Kristo } 82*24582b34STero Kristo 83*24582b34STero Kristo static void __init of_ti_interface_clk_setup(struct device_node *node) 84*24582b34STero Kristo { 85*24582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait); 86*24582b34STero Kristo } 87*24582b34STero Kristo CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock", 88*24582b34STero Kristo of_ti_interface_clk_setup); 89*24582b34STero Kristo 90*24582b34STero Kristo static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node) 91*24582b34STero Kristo { 92*24582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk); 93*24582b34STero Kristo } 94*24582b34STero Kristo CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock", 95*24582b34STero Kristo of_ti_no_wait_interface_clk_setup); 96*24582b34STero Kristo 97*24582b34STero Kristo static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node) 98*24582b34STero Kristo { 99*24582b34STero Kristo _of_ti_interface_clk_setup(node, 100*24582b34STero Kristo &clkhwops_omap3430es2_iclk_hsotgusb_wait); 101*24582b34STero Kristo } 102*24582b34STero Kristo CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock", 103*24582b34STero Kristo of_ti_hsotgusb_interface_clk_setup); 104*24582b34STero Kristo 105*24582b34STero Kristo static void __init of_ti_dss_interface_clk_setup(struct device_node *node) 106*24582b34STero Kristo { 107*24582b34STero Kristo _of_ti_interface_clk_setup(node, 108*24582b34STero Kristo &clkhwops_omap3430es2_iclk_dss_usbhost_wait); 109*24582b34STero Kristo } 110*24582b34STero Kristo CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock", 111*24582b34STero Kristo of_ti_dss_interface_clk_setup); 112*24582b34STero Kristo 113*24582b34STero Kristo static void __init of_ti_ssi_interface_clk_setup(struct device_node *node) 114*24582b34STero Kristo { 115*24582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait); 116*24582b34STero Kristo } 117*24582b34STero Kristo CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock", 118*24582b34STero Kristo of_ti_ssi_interface_clk_setup); 119*24582b34STero Kristo 120*24582b34STero Kristo static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node) 121*24582b34STero Kristo { 122*24582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait); 123*24582b34STero Kristo } 124*24582b34STero Kristo CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock", 125*24582b34STero Kristo of_ti_am35xx_interface_clk_setup); 126