124582b34STero Kristo /* 224582b34STero Kristo * OMAP interface clock support 324582b34STero Kristo * 424582b34STero Kristo * Copyright (C) 2013 Texas Instruments, Inc. 524582b34STero Kristo * 624582b34STero Kristo * Tero Kristo <t-kristo@ti.com> 724582b34STero Kristo * 824582b34STero Kristo * This program is free software; you can redistribute it and/or modify 924582b34STero Kristo * it under the terms of the GNU General Public License version 2 as 1024582b34STero Kristo * published by the Free Software Foundation. 1124582b34STero Kristo * 1224582b34STero Kristo * This program is distributed "as is" WITHOUT ANY WARRANTY of any 1324582b34STero Kristo * kind, whether express or implied; without even the implied warranty 1424582b34STero Kristo * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1524582b34STero Kristo * GNU General Public License for more details. 1624582b34STero Kristo */ 1724582b34STero Kristo 1824582b34STero Kristo #include <linux/clk-provider.h> 1924582b34STero Kristo #include <linux/slab.h> 2024582b34STero Kristo #include <linux/of.h> 2124582b34STero Kristo #include <linux/of_address.h> 2224582b34STero Kristo #include <linux/clk/ti.h> 2306524fa4STero Kristo #include "clock.h" 2424582b34STero Kristo 2524582b34STero Kristo #undef pr_fmt 2624582b34STero Kristo #define pr_fmt(fmt) "%s: " fmt, __func__ 2724582b34STero Kristo 2824582b34STero Kristo static const struct clk_ops ti_interface_clk_ops = { 2924582b34STero Kristo .init = &omap2_init_clk_clkdm, 3024582b34STero Kristo .enable = &omap2_dflt_clk_enable, 3124582b34STero Kristo .disable = &omap2_dflt_clk_disable, 3224582b34STero Kristo .is_enabled = &omap2_dflt_clk_is_enabled, 3324582b34STero Kristo }; 3424582b34STero Kristo 3506524fa4STero Kristo static struct clk *_register_interface(struct device *dev, const char *name, 3606524fa4STero Kristo const char *parent_name, 37*6c0afb50STero Kristo struct clk_omap_reg *reg, u8 bit_idx, 3824582b34STero Kristo const struct clk_hw_omap_ops *ops) 3924582b34STero Kristo { 4024582b34STero Kristo struct clk_init_data init = { NULL }; 4124582b34STero Kristo struct clk_hw_omap *clk_hw; 4206524fa4STero Kristo struct clk *clk; 4324582b34STero Kristo 4424582b34STero Kristo clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 4524582b34STero Kristo if (!clk_hw) 4606524fa4STero Kristo return ERR_PTR(-ENOMEM); 4724582b34STero Kristo 4824582b34STero Kristo clk_hw->hw.init = &init; 4924582b34STero Kristo clk_hw->ops = ops; 50*6c0afb50STero Kristo memcpy(&clk_hw->enable_reg, reg, sizeof(*reg)); 5106524fa4STero Kristo clk_hw->enable_bit = bit_idx; 5224582b34STero Kristo 5306524fa4STero Kristo init.name = name; 5424582b34STero Kristo init.ops = &ti_interface_clk_ops; 5524582b34STero Kristo init.flags = 0; 5624582b34STero Kristo 5724582b34STero Kristo init.num_parents = 1; 5824582b34STero Kristo init.parent_names = &parent_name; 5924582b34STero Kristo 601ae79c46STero Kristo clk = ti_clk_register(NULL, &clk_hw->hw, name); 6124582b34STero Kristo 6206524fa4STero Kristo if (IS_ERR(clk)) 6306524fa4STero Kristo kfree(clk_hw); 6406524fa4STero Kristo else 6598d8a60eSStephen Boyd omap2_init_clk_hw_omap_clocks(&clk_hw->hw); 6606524fa4STero Kristo 6706524fa4STero Kristo return clk; 6806524fa4STero Kristo } 6906524fa4STero Kristo 706793a30aSArnd Bergmann #if defined(CONFIG_ARCH_OMAP3) && defined(CONFIG_ATAGS) 7106524fa4STero Kristo struct clk *ti_clk_register_interface(struct ti_clk *setup) 7206524fa4STero Kristo { 7306524fa4STero Kristo const struct clk_hw_omap_ops *ops = &clkhwops_iclk_wait; 74*6c0afb50STero Kristo struct clk_omap_reg reg; 7506524fa4STero Kristo struct ti_clk_gate *gate; 7606524fa4STero Kristo 7706524fa4STero Kristo gate = setup->data; 78*6c0afb50STero Kristo reg.index = gate->module; 79*6c0afb50STero Kristo reg.offset = gate->reg; 80*6c0afb50STero Kristo reg.ptr = NULL; 8106524fa4STero Kristo 8206524fa4STero Kristo if (gate->flags & CLKF_NO_WAIT) 8306524fa4STero Kristo ops = &clkhwops_iclk; 8406524fa4STero Kristo 8506524fa4STero Kristo if (gate->flags & CLKF_HSOTGUSB) 8606524fa4STero Kristo ops = &clkhwops_omap3430es2_iclk_hsotgusb_wait; 8706524fa4STero Kristo 8806524fa4STero Kristo if (gate->flags & CLKF_DSS) 8906524fa4STero Kristo ops = &clkhwops_omap3430es2_iclk_dss_usbhost_wait; 9006524fa4STero Kristo 9106524fa4STero Kristo if (gate->flags & CLKF_SSI) 9206524fa4STero Kristo ops = &clkhwops_omap3430es2_iclk_ssi_wait; 9306524fa4STero Kristo 9406524fa4STero Kristo if (gate->flags & CLKF_AM35XX) 9506524fa4STero Kristo ops = &clkhwops_am35xx_ipss_wait; 9606524fa4STero Kristo 9706524fa4STero Kristo return _register_interface(NULL, setup->name, gate->parent, 98*6c0afb50STero Kristo ®, gate->bit_shift, ops); 9906524fa4STero Kristo } 1006793a30aSArnd Bergmann #endif 10106524fa4STero Kristo 10206524fa4STero Kristo static void __init _of_ti_interface_clk_setup(struct device_node *node, 10306524fa4STero Kristo const struct clk_hw_omap_ops *ops) 10406524fa4STero Kristo { 10506524fa4STero Kristo struct clk *clk; 10606524fa4STero Kristo const char *parent_name; 107*6c0afb50STero Kristo struct clk_omap_reg reg; 10806524fa4STero Kristo u8 enable_bit = 0; 10906524fa4STero Kristo u32 val; 11006524fa4STero Kristo 111*6c0afb50STero Kristo if (ti_clk_get_reg_addr(node, 0, ®)) 11206524fa4STero Kristo return; 11306524fa4STero Kristo 11406524fa4STero Kristo if (!of_property_read_u32(node, "ti,bit-shift", &val)) 11506524fa4STero Kristo enable_bit = val; 11606524fa4STero Kristo 11706524fa4STero Kristo parent_name = of_clk_get_parent_name(node, 0); 11806524fa4STero Kristo if (!parent_name) { 11906524fa4STero Kristo pr_err("%s must have a parent\n", node->name); 12024582b34STero Kristo return; 12124582b34STero Kristo } 12224582b34STero Kristo 123*6c0afb50STero Kristo clk = _register_interface(NULL, node->name, parent_name, ®, 12406524fa4STero Kristo enable_bit, ops); 12506524fa4STero Kristo 12606524fa4STero Kristo if (!IS_ERR(clk)) 12706524fa4STero Kristo of_clk_add_provider(node, of_clk_src_simple_get, clk); 12824582b34STero Kristo } 12924582b34STero Kristo 13024582b34STero Kristo static void __init of_ti_interface_clk_setup(struct device_node *node) 13124582b34STero Kristo { 13224582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait); 13324582b34STero Kristo } 13424582b34STero Kristo CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock", 13524582b34STero Kristo of_ti_interface_clk_setup); 13624582b34STero Kristo 13724582b34STero Kristo static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node) 13824582b34STero Kristo { 13924582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk); 14024582b34STero Kristo } 14124582b34STero Kristo CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock", 14224582b34STero Kristo of_ti_no_wait_interface_clk_setup); 14324582b34STero Kristo 144de742570STero Kristo #ifdef CONFIG_ARCH_OMAP3 14524582b34STero Kristo static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node) 14624582b34STero Kristo { 14724582b34STero Kristo _of_ti_interface_clk_setup(node, 14824582b34STero Kristo &clkhwops_omap3430es2_iclk_hsotgusb_wait); 14924582b34STero Kristo } 15024582b34STero Kristo CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock", 15124582b34STero Kristo of_ti_hsotgusb_interface_clk_setup); 15224582b34STero Kristo 15324582b34STero Kristo static void __init of_ti_dss_interface_clk_setup(struct device_node *node) 15424582b34STero Kristo { 15524582b34STero Kristo _of_ti_interface_clk_setup(node, 15624582b34STero Kristo &clkhwops_omap3430es2_iclk_dss_usbhost_wait); 15724582b34STero Kristo } 15824582b34STero Kristo CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock", 15924582b34STero Kristo of_ti_dss_interface_clk_setup); 16024582b34STero Kristo 16124582b34STero Kristo static void __init of_ti_ssi_interface_clk_setup(struct device_node *node) 16224582b34STero Kristo { 16324582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait); 16424582b34STero Kristo } 16524582b34STero Kristo CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock", 16624582b34STero Kristo of_ti_ssi_interface_clk_setup); 16724582b34STero Kristo 16824582b34STero Kristo static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node) 16924582b34STero Kristo { 17024582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait); 17124582b34STero Kristo } 17224582b34STero Kristo CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock", 17324582b34STero Kristo of_ti_am35xx_interface_clk_setup); 174de742570STero Kristo #endif 175de742570STero Kristo 176de742570STero Kristo #ifdef CONFIG_SOC_OMAP2430 177de742570STero Kristo static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node) 178de742570STero Kristo { 179de742570STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait); 180de742570STero Kristo } 181de742570STero Kristo CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock", 182de742570STero Kristo of_ti_omap2430_interface_clk_setup); 183de742570STero Kristo #endif 184