xref: /openbmc/linux/drivers/clk/ti/interface.c (revision e665f029a283aff4f36f0c5388f7c708be67470e)
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,
376c0afb50STero 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;
506c0afb50STero 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 
7006524fa4STero Kristo static void __init _of_ti_interface_clk_setup(struct device_node *node,
7106524fa4STero Kristo 					      const struct clk_hw_omap_ops *ops)
7206524fa4STero Kristo {
7306524fa4STero Kristo 	struct clk *clk;
7406524fa4STero Kristo 	const char *parent_name;
756c0afb50STero Kristo 	struct clk_omap_reg reg;
7606524fa4STero Kristo 	u8 enable_bit = 0;
7706524fa4STero Kristo 	u32 val;
7806524fa4STero Kristo 
796c0afb50STero Kristo 	if (ti_clk_get_reg_addr(node, 0, &reg))
8006524fa4STero Kristo 		return;
8106524fa4STero Kristo 
8206524fa4STero Kristo 	if (!of_property_read_u32(node, "ti,bit-shift", &val))
8306524fa4STero Kristo 		enable_bit = val;
8406524fa4STero Kristo 
8506524fa4STero Kristo 	parent_name = of_clk_get_parent_name(node, 0);
8606524fa4STero Kristo 	if (!parent_name) {
87*e665f029SRob Herring 		pr_err("%pOFn must have a parent\n", node);
8824582b34STero Kristo 		return;
8924582b34STero Kristo 	}
9024582b34STero Kristo 
916c0afb50STero Kristo 	clk = _register_interface(NULL, node->name, parent_name, &reg,
9206524fa4STero Kristo 				  enable_bit, ops);
9306524fa4STero Kristo 
9406524fa4STero Kristo 	if (!IS_ERR(clk))
9506524fa4STero Kristo 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
9624582b34STero Kristo }
9724582b34STero Kristo 
9824582b34STero Kristo static void __init of_ti_interface_clk_setup(struct device_node *node)
9924582b34STero Kristo {
10024582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
10124582b34STero Kristo }
10224582b34STero Kristo CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
10324582b34STero Kristo 	       of_ti_interface_clk_setup);
10424582b34STero Kristo 
10524582b34STero Kristo static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
10624582b34STero Kristo {
10724582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_iclk);
10824582b34STero Kristo }
10924582b34STero Kristo CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
11024582b34STero Kristo 	       of_ti_no_wait_interface_clk_setup);
11124582b34STero Kristo 
112de742570STero Kristo #ifdef CONFIG_ARCH_OMAP3
11324582b34STero Kristo static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
11424582b34STero Kristo {
11524582b34STero Kristo 	_of_ti_interface_clk_setup(node,
11624582b34STero Kristo 				   &clkhwops_omap3430es2_iclk_hsotgusb_wait);
11724582b34STero Kristo }
11824582b34STero Kristo CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
11924582b34STero Kristo 	       of_ti_hsotgusb_interface_clk_setup);
12024582b34STero Kristo 
12124582b34STero Kristo static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
12224582b34STero Kristo {
12324582b34STero Kristo 	_of_ti_interface_clk_setup(node,
12424582b34STero Kristo 				   &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
12524582b34STero Kristo }
12624582b34STero Kristo CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
12724582b34STero Kristo 	       of_ti_dss_interface_clk_setup);
12824582b34STero Kristo 
12924582b34STero Kristo static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
13024582b34STero Kristo {
13124582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
13224582b34STero Kristo }
13324582b34STero Kristo CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
13424582b34STero Kristo 	       of_ti_ssi_interface_clk_setup);
13524582b34STero Kristo 
13624582b34STero Kristo static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
13724582b34STero Kristo {
13824582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
13924582b34STero Kristo }
14024582b34STero Kristo CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
14124582b34STero Kristo 	       of_ti_am35xx_interface_clk_setup);
142de742570STero Kristo #endif
143de742570STero Kristo 
144de742570STero Kristo #ifdef CONFIG_SOC_OMAP2430
145de742570STero Kristo static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
146de742570STero Kristo {
147de742570STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
148de742570STero Kristo }
149de742570STero Kristo CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
150de742570STero Kristo 	       of_ti_omap2430_interface_clk_setup);
151de742570STero Kristo #endif
152