xref: /openbmc/linux/drivers/clk/ti/interface.c (revision 9221b289)
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * OMAP interface clock support
4  *
5  * Copyright (C) 2013 Texas Instruments, Inc.
6  *
7  * Tero Kristo <t-kristo@ti.com>
8  */
9 
10 #include <linux/clk-provider.h>
11 #include <linux/slab.h>
12 #include <linux/of.h>
13 #include <linux/of_address.h>
14 #include <linux/clk/ti.h>
15 #include "clock.h"
16 
17 #undef pr_fmt
18 #define pr_fmt(fmt) "%s: " fmt, __func__
19 
20 static const struct clk_ops ti_interface_clk_ops = {
21 	.init		= &omap2_init_clk_clkdm,
22 	.enable		= &omap2_dflt_clk_enable,
23 	.disable	= &omap2_dflt_clk_disable,
24 	.is_enabled	= &omap2_dflt_clk_is_enabled,
25 };
26 
27 static struct clk *_register_interface(struct device *dev, const char *name,
28 				       const char *parent_name,
29 				       struct clk_omap_reg *reg, u8 bit_idx,
30 				       const struct clk_hw_omap_ops *ops)
31 {
32 	struct clk_init_data init = { NULL };
33 	struct clk_hw_omap *clk_hw;
34 	struct clk *clk;
35 
36 	clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
37 	if (!clk_hw)
38 		return ERR_PTR(-ENOMEM);
39 
40 	clk_hw->hw.init = &init;
41 	clk_hw->ops = ops;
42 	memcpy(&clk_hw->enable_reg, reg, sizeof(*reg));
43 	clk_hw->enable_bit = bit_idx;
44 
45 	init.name = name;
46 	init.ops = &ti_interface_clk_ops;
47 	init.flags = 0;
48 
49 	init.num_parents = 1;
50 	init.parent_names = &parent_name;
51 
52 	clk = ti_clk_register_omap_hw(NULL, &clk_hw->hw, name);
53 
54 	if (IS_ERR(clk))
55 		kfree(clk_hw);
56 
57 	return clk;
58 }
59 
60 static void __init _of_ti_interface_clk_setup(struct device_node *node,
61 					      const struct clk_hw_omap_ops *ops)
62 {
63 	struct clk *clk;
64 	const char *parent_name;
65 	struct clk_omap_reg reg;
66 	u8 enable_bit = 0;
67 	const char *name;
68 	u32 val;
69 
70 	if (ti_clk_get_reg_addr(node, 0, &reg))
71 		return;
72 
73 	if (!of_property_read_u32(node, "ti,bit-shift", &val))
74 		enable_bit = val;
75 
76 	parent_name = of_clk_get_parent_name(node, 0);
77 	if (!parent_name) {
78 		pr_err("%pOFn must have a parent\n", node);
79 		return;
80 	}
81 
82 	name = ti_dt_clk_name(node);
83 	clk = _register_interface(NULL, name, parent_name, &reg,
84 				  enable_bit, ops);
85 
86 	if (!IS_ERR(clk))
87 		of_clk_add_provider(node, of_clk_src_simple_get, clk);
88 }
89 
90 static void __init of_ti_interface_clk_setup(struct device_node *node)
91 {
92 	_of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
93 }
94 CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
95 	       of_ti_interface_clk_setup);
96 
97 static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
98 {
99 	_of_ti_interface_clk_setup(node, &clkhwops_iclk);
100 }
101 CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
102 	       of_ti_no_wait_interface_clk_setup);
103 
104 #ifdef CONFIG_ARCH_OMAP3
105 static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
106 {
107 	_of_ti_interface_clk_setup(node,
108 				   &clkhwops_omap3430es2_iclk_hsotgusb_wait);
109 }
110 CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
111 	       of_ti_hsotgusb_interface_clk_setup);
112 
113 static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
114 {
115 	_of_ti_interface_clk_setup(node,
116 				   &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
117 }
118 CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
119 	       of_ti_dss_interface_clk_setup);
120 
121 static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
122 {
123 	_of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
124 }
125 CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
126 	       of_ti_ssi_interface_clk_setup);
127 
128 static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
129 {
130 	_of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
131 }
132 CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
133 	       of_ti_am35xx_interface_clk_setup);
134 #endif
135 
136 #ifdef CONFIG_SOC_OMAP2430
137 static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
138 {
139 	_of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
140 }
141 CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
142 	       of_ti_omap2430_interface_clk_setup);
143 #endif
144