xref: /openbmc/linux/drivers/clk/ti/interface.c (revision 06524fa4289797deb9a66c1a3e681052eed0d83d)
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>
23*06524fa4STero 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 
35*06524fa4STero Kristo static struct clk *_register_interface(struct device *dev, const char *name,
36*06524fa4STero Kristo 				       const char *parent_name,
37*06524fa4STero Kristo 				       void __iomem *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;
42*06524fa4STero Kristo 	struct clk *clk;
4324582b34STero Kristo 
4424582b34STero Kristo 	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
4524582b34STero Kristo 	if (!clk_hw)
46*06524fa4STero Kristo 		return ERR_PTR(-ENOMEM);
4724582b34STero Kristo 
4824582b34STero Kristo 	clk_hw->hw.init = &init;
4924582b34STero Kristo 	clk_hw->ops = ops;
5024582b34STero Kristo 	clk_hw->flags = MEMMAP_ADDRESSING;
51*06524fa4STero Kristo 	clk_hw->enable_reg = reg;
52*06524fa4STero Kristo 	clk_hw->enable_bit = bit_idx;
5324582b34STero Kristo 
54*06524fa4STero Kristo 	init.name = name;
5524582b34STero Kristo 	init.ops = &ti_interface_clk_ops;
5624582b34STero Kristo 	init.flags = 0;
5724582b34STero Kristo 
5824582b34STero Kristo 	init.num_parents = 1;
5924582b34STero Kristo 	init.parent_names = &parent_name;
6024582b34STero Kristo 
6124582b34STero Kristo 	clk = clk_register(NULL, &clk_hw->hw);
6224582b34STero Kristo 
63*06524fa4STero Kristo 	if (IS_ERR(clk))
64*06524fa4STero Kristo 		kfree(clk_hw);
65*06524fa4STero Kristo 	else
6624582b34STero Kristo 		omap2_init_clk_hw_omap_clocks(clk);
67*06524fa4STero Kristo 
68*06524fa4STero Kristo 	return clk;
69*06524fa4STero Kristo }
70*06524fa4STero Kristo 
71*06524fa4STero Kristo struct clk *ti_clk_register_interface(struct ti_clk *setup)
72*06524fa4STero Kristo {
73*06524fa4STero Kristo 	const struct clk_hw_omap_ops *ops = &clkhwops_iclk_wait;
74*06524fa4STero Kristo 	u32 reg;
75*06524fa4STero Kristo 	struct clk_omap_reg *reg_setup;
76*06524fa4STero Kristo 	struct ti_clk_gate *gate;
77*06524fa4STero Kristo 
78*06524fa4STero Kristo 	gate = setup->data;
79*06524fa4STero Kristo 	reg_setup = (struct clk_omap_reg *)&reg;
80*06524fa4STero Kristo 	reg_setup->index = gate->module;
81*06524fa4STero Kristo 	reg_setup->offset = gate->reg;
82*06524fa4STero Kristo 
83*06524fa4STero Kristo 	if (gate->flags & CLKF_NO_WAIT)
84*06524fa4STero Kristo 		ops = &clkhwops_iclk;
85*06524fa4STero Kristo 
86*06524fa4STero Kristo 	if (gate->flags & CLKF_HSOTGUSB)
87*06524fa4STero Kristo 		ops = &clkhwops_omap3430es2_iclk_hsotgusb_wait;
88*06524fa4STero Kristo 
89*06524fa4STero Kristo 	if (gate->flags & CLKF_DSS)
90*06524fa4STero Kristo 		ops = &clkhwops_omap3430es2_iclk_dss_usbhost_wait;
91*06524fa4STero Kristo 
92*06524fa4STero Kristo 	if (gate->flags & CLKF_SSI)
93*06524fa4STero Kristo 		ops = &clkhwops_omap3430es2_iclk_ssi_wait;
94*06524fa4STero Kristo 
95*06524fa4STero Kristo 	if (gate->flags & CLKF_AM35XX)
96*06524fa4STero Kristo 		ops = &clkhwops_am35xx_ipss_wait;
97*06524fa4STero Kristo 
98*06524fa4STero Kristo 	return _register_interface(NULL, setup->name, gate->parent,
99*06524fa4STero Kristo 				   (void __iomem *)reg, gate->bit_shift, ops);
100*06524fa4STero Kristo }
101*06524fa4STero Kristo 
102*06524fa4STero Kristo static void __init _of_ti_interface_clk_setup(struct device_node *node,
103*06524fa4STero Kristo 					      const struct clk_hw_omap_ops *ops)
104*06524fa4STero Kristo {
105*06524fa4STero Kristo 	struct clk *clk;
106*06524fa4STero Kristo 	const char *parent_name;
107*06524fa4STero Kristo 	void __iomem *reg;
108*06524fa4STero Kristo 	u8 enable_bit = 0;
109*06524fa4STero Kristo 	u32 val;
110*06524fa4STero Kristo 
111*06524fa4STero Kristo 	reg = ti_clk_get_reg_addr(node, 0);
112*06524fa4STero Kristo 	if (!reg)
113*06524fa4STero Kristo 		return;
114*06524fa4STero Kristo 
115*06524fa4STero Kristo 	if (!of_property_read_u32(node, "ti,bit-shift", &val))
116*06524fa4STero Kristo 		enable_bit = val;
117*06524fa4STero Kristo 
118*06524fa4STero Kristo 	parent_name = of_clk_get_parent_name(node, 0);
119*06524fa4STero Kristo 	if (!parent_name) {
120*06524fa4STero Kristo 		pr_err("%s must have a parent\n", node->name);
12124582b34STero Kristo 		return;
12224582b34STero Kristo 	}
12324582b34STero Kristo 
124*06524fa4STero Kristo 	clk = _register_interface(NULL, node->name, parent_name, reg,
125*06524fa4STero Kristo 				  enable_bit, ops);
126*06524fa4STero Kristo 
127*06524fa4STero Kristo 	if (!IS_ERR(clk))
128*06524fa4STero Kristo 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
12924582b34STero Kristo }
13024582b34STero Kristo 
13124582b34STero Kristo static void __init of_ti_interface_clk_setup(struct device_node *node)
13224582b34STero Kristo {
13324582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
13424582b34STero Kristo }
13524582b34STero Kristo CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
13624582b34STero Kristo 	       of_ti_interface_clk_setup);
13724582b34STero Kristo 
13824582b34STero Kristo static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
13924582b34STero Kristo {
14024582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_iclk);
14124582b34STero Kristo }
14224582b34STero Kristo CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
14324582b34STero Kristo 	       of_ti_no_wait_interface_clk_setup);
14424582b34STero Kristo 
145de742570STero Kristo #ifdef CONFIG_ARCH_OMAP3
14624582b34STero Kristo static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
14724582b34STero Kristo {
14824582b34STero Kristo 	_of_ti_interface_clk_setup(node,
14924582b34STero Kristo 				   &clkhwops_omap3430es2_iclk_hsotgusb_wait);
15024582b34STero Kristo }
15124582b34STero Kristo CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
15224582b34STero Kristo 	       of_ti_hsotgusb_interface_clk_setup);
15324582b34STero Kristo 
15424582b34STero Kristo static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
15524582b34STero Kristo {
15624582b34STero Kristo 	_of_ti_interface_clk_setup(node,
15724582b34STero Kristo 				   &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
15824582b34STero Kristo }
15924582b34STero Kristo CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
16024582b34STero Kristo 	       of_ti_dss_interface_clk_setup);
16124582b34STero Kristo 
16224582b34STero Kristo static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
16324582b34STero Kristo {
16424582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
16524582b34STero Kristo }
16624582b34STero Kristo CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
16724582b34STero Kristo 	       of_ti_ssi_interface_clk_setup);
16824582b34STero Kristo 
16924582b34STero Kristo static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
17024582b34STero Kristo {
17124582b34STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
17224582b34STero Kristo }
17324582b34STero Kristo CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
17424582b34STero Kristo 	       of_ti_am35xx_interface_clk_setup);
175de742570STero Kristo #endif
176de742570STero Kristo 
177de742570STero Kristo #ifdef CONFIG_SOC_OMAP2430
178de742570STero Kristo static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
179de742570STero Kristo {
180de742570STero Kristo 	_of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
181de742570STero Kristo }
182de742570STero Kristo CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
183de742570STero Kristo 	       of_ti_omap2430_interface_clk_setup);
184de742570STero Kristo #endif
185