Merge tag 'block-5.11-2021-01-10' of git://git.kernel.dk/linux-block
[linux/fpc-iii.git] / drivers / clk / ti / interface.c
blob83e34429d3b10b627a31f979b9bd31627bebdcd8
1 /*
2 * OMAP interface clock support
4 * Copyright (C) 2013 Texas Instruments, Inc.
6 * Tero Kristo <t-kristo@ti.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
13 * kind, whether express or implied; without even the implied warranty
14 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/clk-provider.h>
19 #include <linux/slab.h>
20 #include <linux/of.h>
21 #include <linux/of_address.h>
22 #include <linux/clk/ti.h>
23 #include "clock.h"
25 #undef pr_fmt
26 #define pr_fmt(fmt) "%s: " fmt, __func__
28 static const struct clk_ops ti_interface_clk_ops = {
29 .init = &omap2_init_clk_clkdm,
30 .enable = &omap2_dflt_clk_enable,
31 .disable = &omap2_dflt_clk_disable,
32 .is_enabled = &omap2_dflt_clk_is_enabled,
35 static struct clk *_register_interface(struct device *dev, const char *name,
36 const char *parent_name,
37 struct clk_omap_reg *reg, u8 bit_idx,
38 const struct clk_hw_omap_ops *ops)
40 struct clk_init_data init = { NULL };
41 struct clk_hw_omap *clk_hw;
42 struct clk *clk;
44 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
45 if (!clk_hw)
46 return ERR_PTR(-ENOMEM);
48 clk_hw->hw.init = &init;
49 clk_hw->ops = ops;
50 memcpy(&clk_hw->enable_reg, reg, sizeof(*reg));
51 clk_hw->enable_bit = bit_idx;
53 init.name = name;
54 init.ops = &ti_interface_clk_ops;
55 init.flags = 0;
57 init.num_parents = 1;
58 init.parent_names = &parent_name;
60 clk = ti_clk_register_omap_hw(NULL, &clk_hw->hw, name);
62 if (IS_ERR(clk))
63 kfree(clk_hw);
65 return clk;
68 static void __init _of_ti_interface_clk_setup(struct device_node *node,
69 const struct clk_hw_omap_ops *ops)
71 struct clk *clk;
72 const char *parent_name;
73 struct clk_omap_reg reg;
74 u8 enable_bit = 0;
75 u32 val;
77 if (ti_clk_get_reg_addr(node, 0, &reg))
78 return;
80 if (!of_property_read_u32(node, "ti,bit-shift", &val))
81 enable_bit = val;
83 parent_name = of_clk_get_parent_name(node, 0);
84 if (!parent_name) {
85 pr_err("%pOFn must have a parent\n", node);
86 return;
89 clk = _register_interface(NULL, node->name, parent_name, &reg,
90 enable_bit, ops);
92 if (!IS_ERR(clk))
93 of_clk_add_provider(node, of_clk_src_simple_get, clk);
96 static void __init of_ti_interface_clk_setup(struct device_node *node)
98 _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
100 CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
101 of_ti_interface_clk_setup);
103 static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
105 _of_ti_interface_clk_setup(node, &clkhwops_iclk);
107 CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
108 of_ti_no_wait_interface_clk_setup);
110 #ifdef CONFIG_ARCH_OMAP3
111 static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
113 _of_ti_interface_clk_setup(node,
114 &clkhwops_omap3430es2_iclk_hsotgusb_wait);
116 CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
117 of_ti_hsotgusb_interface_clk_setup);
119 static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
121 _of_ti_interface_clk_setup(node,
122 &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
124 CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
125 of_ti_dss_interface_clk_setup);
127 static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
129 _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
131 CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
132 of_ti_ssi_interface_clk_setup);
134 static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
136 _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
138 CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
139 of_ti_am35xx_interface_clk_setup);
140 #endif
142 #ifdef CONFIG_SOC_OMAP2430
143 static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
145 _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
147 CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
148 of_ti_omap2430_interface_clk_setup);
149 #endif