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> 2324582b34STero Kristo 2424582b34STero Kristo #undef pr_fmt 2524582b34STero Kristo #define pr_fmt(fmt) "%s: " fmt, __func__ 2624582b34STero Kristo 2724582b34STero Kristo static const struct clk_ops ti_interface_clk_ops = { 2824582b34STero Kristo .init = &omap2_init_clk_clkdm, 2924582b34STero Kristo .enable = &omap2_dflt_clk_enable, 3024582b34STero Kristo .disable = &omap2_dflt_clk_disable, 3124582b34STero Kristo .is_enabled = &omap2_dflt_clk_is_enabled, 3224582b34STero Kristo }; 3324582b34STero Kristo 3424582b34STero Kristo static void __init _of_ti_interface_clk_setup(struct device_node *node, 3524582b34STero Kristo const struct clk_hw_omap_ops *ops) 3624582b34STero Kristo { 3724582b34STero Kristo struct clk *clk; 3824582b34STero Kristo struct clk_init_data init = { NULL }; 3924582b34STero Kristo struct clk_hw_omap *clk_hw; 4024582b34STero Kristo const char *parent_name; 4124582b34STero Kristo u32 val; 4224582b34STero Kristo 4324582b34STero Kristo clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL); 4424582b34STero Kristo if (!clk_hw) 4524582b34STero Kristo return; 4624582b34STero Kristo 4724582b34STero Kristo clk_hw->hw.init = &init; 4824582b34STero Kristo clk_hw->ops = ops; 4924582b34STero Kristo clk_hw->flags = MEMMAP_ADDRESSING; 5024582b34STero Kristo 5124582b34STero Kristo clk_hw->enable_reg = ti_clk_get_reg_addr(node, 0); 5224582b34STero Kristo if (!clk_hw->enable_reg) 5324582b34STero Kristo goto cleanup; 5424582b34STero Kristo 5524582b34STero Kristo if (!of_property_read_u32(node, "ti,bit-shift", &val)) 5624582b34STero Kristo clk_hw->enable_bit = val; 5724582b34STero Kristo 5824582b34STero Kristo init.name = node->name; 5924582b34STero Kristo init.ops = &ti_interface_clk_ops; 6024582b34STero Kristo init.flags = 0; 6124582b34STero Kristo 6224582b34STero Kristo parent_name = of_clk_get_parent_name(node, 0); 6324582b34STero Kristo if (!parent_name) { 6424582b34STero Kristo pr_err("%s must have a parent\n", node->name); 6524582b34STero Kristo goto cleanup; 6624582b34STero Kristo } 6724582b34STero Kristo 6824582b34STero Kristo init.num_parents = 1; 6924582b34STero Kristo init.parent_names = &parent_name; 7024582b34STero Kristo 7124582b34STero Kristo clk = clk_register(NULL, &clk_hw->hw); 7224582b34STero Kristo 7324582b34STero Kristo if (!IS_ERR(clk)) { 7424582b34STero Kristo of_clk_add_provider(node, of_clk_src_simple_get, clk); 7524582b34STero Kristo omap2_init_clk_hw_omap_clocks(clk); 7624582b34STero Kristo return; 7724582b34STero Kristo } 7824582b34STero Kristo 7924582b34STero Kristo cleanup: 8024582b34STero Kristo kfree(clk_hw); 8124582b34STero Kristo } 8224582b34STero Kristo 8324582b34STero Kristo static void __init of_ti_interface_clk_setup(struct device_node *node) 8424582b34STero Kristo { 8524582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait); 8624582b34STero Kristo } 8724582b34STero Kristo CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock", 8824582b34STero Kristo of_ti_interface_clk_setup); 8924582b34STero Kristo 9024582b34STero Kristo static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node) 9124582b34STero Kristo { 9224582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_iclk); 9324582b34STero Kristo } 9424582b34STero Kristo CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock", 9524582b34STero Kristo of_ti_no_wait_interface_clk_setup); 9624582b34STero Kristo 97*de742570STero Kristo #ifdef CONFIG_ARCH_OMAP3 9824582b34STero Kristo static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node) 9924582b34STero Kristo { 10024582b34STero Kristo _of_ti_interface_clk_setup(node, 10124582b34STero Kristo &clkhwops_omap3430es2_iclk_hsotgusb_wait); 10224582b34STero Kristo } 10324582b34STero Kristo CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock", 10424582b34STero Kristo of_ti_hsotgusb_interface_clk_setup); 10524582b34STero Kristo 10624582b34STero Kristo static void __init of_ti_dss_interface_clk_setup(struct device_node *node) 10724582b34STero Kristo { 10824582b34STero Kristo _of_ti_interface_clk_setup(node, 10924582b34STero Kristo &clkhwops_omap3430es2_iclk_dss_usbhost_wait); 11024582b34STero Kristo } 11124582b34STero Kristo CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock", 11224582b34STero Kristo of_ti_dss_interface_clk_setup); 11324582b34STero Kristo 11424582b34STero Kristo static void __init of_ti_ssi_interface_clk_setup(struct device_node *node) 11524582b34STero Kristo { 11624582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait); 11724582b34STero Kristo } 11824582b34STero Kristo CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock", 11924582b34STero Kristo of_ti_ssi_interface_clk_setup); 12024582b34STero Kristo 12124582b34STero Kristo static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node) 12224582b34STero Kristo { 12324582b34STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait); 12424582b34STero Kristo } 12524582b34STero Kristo CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock", 12624582b34STero Kristo of_ti_am35xx_interface_clk_setup); 127*de742570STero Kristo #endif 128*de742570STero Kristo 129*de742570STero Kristo #ifdef CONFIG_SOC_OMAP2430 130*de742570STero Kristo static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node) 131*de742570STero Kristo { 132*de742570STero Kristo _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait); 133*de742570STero Kristo } 134*de742570STero Kristo CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock", 135*de742570STero Kristo of_ti_omap2430_interface_clk_setup); 136*de742570STero Kristo #endif 137