blob: d71cd9b5de467de3721c584ff97cb1ee6ae45014 [file] [log] [blame]
Tero Kristo24582b32013-07-15 13:14:20 +03001/*
2 * OMAP interface clock support
3 *
4 * Copyright (C) 2013 Texas Instruments, Inc.
5 *
6 * Tero Kristo <t-kristo@ti.com>
7 *
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.
11 *
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.
16 */
17
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>
Tero Kristo06524fa2014-12-16 18:20:49 +020023#include "clock.h"
Tero Kristo24582b32013-07-15 13:14:20 +030024
25#undef pr_fmt
26#define pr_fmt(fmt) "%s: " fmt, __func__
27
28static 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,
33};
34
Tero Kristo06524fa2014-12-16 18:20:49 +020035static struct clk *_register_interface(struct device *dev, const char *name,
36 const char *parent_name,
37 void __iomem *reg, u8 bit_idx,
38 const struct clk_hw_omap_ops *ops)
Tero Kristo24582b32013-07-15 13:14:20 +030039{
Tero Kristo24582b32013-07-15 13:14:20 +030040 struct clk_init_data init = { NULL };
41 struct clk_hw_omap *clk_hw;
Tero Kristo06524fa2014-12-16 18:20:49 +020042 struct clk *clk;
Tero Kristo24582b32013-07-15 13:14:20 +030043
44 clk_hw = kzalloc(sizeof(*clk_hw), GFP_KERNEL);
45 if (!clk_hw)
Tero Kristo06524fa2014-12-16 18:20:49 +020046 return ERR_PTR(-ENOMEM);
Tero Kristo24582b32013-07-15 13:14:20 +030047
48 clk_hw->hw.init = &init;
49 clk_hw->ops = ops;
50 clk_hw->flags = MEMMAP_ADDRESSING;
Tero Kristo06524fa2014-12-16 18:20:49 +020051 clk_hw->enable_reg = reg;
52 clk_hw->enable_bit = bit_idx;
Tero Kristo24582b32013-07-15 13:14:20 +030053
Tero Kristo06524fa2014-12-16 18:20:49 +020054 init.name = name;
Tero Kristo24582b32013-07-15 13:14:20 +030055 init.ops = &ti_interface_clk_ops;
56 init.flags = 0;
57
Tero Kristo24582b32013-07-15 13:14:20 +030058 init.num_parents = 1;
59 init.parent_names = &parent_name;
60
61 clk = clk_register(NULL, &clk_hw->hw);
62
Tero Kristo06524fa2014-12-16 18:20:49 +020063 if (IS_ERR(clk))
64 kfree(clk_hw);
65 else
Tero Kristo24582b32013-07-15 13:14:20 +030066 omap2_init_clk_hw_omap_clocks(clk);
Tero Kristo06524fa2014-12-16 18:20:49 +020067
68 return clk;
69}
70
71struct clk *ti_clk_register_interface(struct ti_clk *setup)
72{
73 const struct clk_hw_omap_ops *ops = &clkhwops_iclk_wait;
74 u32 reg;
75 struct clk_omap_reg *reg_setup;
76 struct ti_clk_gate *gate;
77
78 gate = setup->data;
79 reg_setup = (struct clk_omap_reg *)&reg;
80 reg_setup->index = gate->module;
81 reg_setup->offset = gate->reg;
82
83 if (gate->flags & CLKF_NO_WAIT)
84 ops = &clkhwops_iclk;
85
86 if (gate->flags & CLKF_HSOTGUSB)
87 ops = &clkhwops_omap3430es2_iclk_hsotgusb_wait;
88
89 if (gate->flags & CLKF_DSS)
90 ops = &clkhwops_omap3430es2_iclk_dss_usbhost_wait;
91
92 if (gate->flags & CLKF_SSI)
93 ops = &clkhwops_omap3430es2_iclk_ssi_wait;
94
95 if (gate->flags & CLKF_AM35XX)
96 ops = &clkhwops_am35xx_ipss_wait;
97
98 return _register_interface(NULL, setup->name, gate->parent,
99 (void __iomem *)reg, gate->bit_shift, ops);
100}
101
102static void __init _of_ti_interface_clk_setup(struct device_node *node,
103 const struct clk_hw_omap_ops *ops)
104{
105 struct clk *clk;
106 const char *parent_name;
107 void __iomem *reg;
108 u8 enable_bit = 0;
109 u32 val;
110
111 reg = ti_clk_get_reg_addr(node, 0);
112 if (!reg)
113 return;
114
115 if (!of_property_read_u32(node, "ti,bit-shift", &val))
116 enable_bit = val;
117
118 parent_name = of_clk_get_parent_name(node, 0);
119 if (!parent_name) {
120 pr_err("%s must have a parent\n", node->name);
Tero Kristo24582b32013-07-15 13:14:20 +0300121 return;
122 }
123
Tero Kristo06524fa2014-12-16 18:20:49 +0200124 clk = _register_interface(NULL, node->name, parent_name, reg,
125 enable_bit, ops);
126
127 if (!IS_ERR(clk))
128 of_clk_add_provider(node, of_clk_src_simple_get, clk);
Tero Kristo24582b32013-07-15 13:14:20 +0300129}
130
131static void __init of_ti_interface_clk_setup(struct device_node *node)
132{
133 _of_ti_interface_clk_setup(node, &clkhwops_iclk_wait);
134}
135CLK_OF_DECLARE(ti_interface_clk, "ti,omap3-interface-clock",
136 of_ti_interface_clk_setup);
137
138static void __init of_ti_no_wait_interface_clk_setup(struct device_node *node)
139{
140 _of_ti_interface_clk_setup(node, &clkhwops_iclk);
141}
142CLK_OF_DECLARE(ti_no_wait_interface_clk, "ti,omap3-no-wait-interface-clock",
143 of_ti_no_wait_interface_clk_setup);
144
Tero Kristode742572014-02-25 19:16:07 +0200145#ifdef CONFIG_ARCH_OMAP3
Tero Kristo24582b32013-07-15 13:14:20 +0300146static void __init of_ti_hsotgusb_interface_clk_setup(struct device_node *node)
147{
148 _of_ti_interface_clk_setup(node,
149 &clkhwops_omap3430es2_iclk_hsotgusb_wait);
150}
151CLK_OF_DECLARE(ti_hsotgusb_interface_clk, "ti,omap3-hsotgusb-interface-clock",
152 of_ti_hsotgusb_interface_clk_setup);
153
154static void __init of_ti_dss_interface_clk_setup(struct device_node *node)
155{
156 _of_ti_interface_clk_setup(node,
157 &clkhwops_omap3430es2_iclk_dss_usbhost_wait);
158}
159CLK_OF_DECLARE(ti_dss_interface_clk, "ti,omap3-dss-interface-clock",
160 of_ti_dss_interface_clk_setup);
161
162static void __init of_ti_ssi_interface_clk_setup(struct device_node *node)
163{
164 _of_ti_interface_clk_setup(node, &clkhwops_omap3430es2_iclk_ssi_wait);
165}
166CLK_OF_DECLARE(ti_ssi_interface_clk, "ti,omap3-ssi-interface-clock",
167 of_ti_ssi_interface_clk_setup);
168
169static void __init of_ti_am35xx_interface_clk_setup(struct device_node *node)
170{
171 _of_ti_interface_clk_setup(node, &clkhwops_am35xx_ipss_wait);
172}
173CLK_OF_DECLARE(ti_am35xx_interface_clk, "ti,am35xx-interface-clock",
174 of_ti_am35xx_interface_clk_setup);
Tero Kristode742572014-02-25 19:16:07 +0200175#endif
176
177#ifdef CONFIG_SOC_OMAP2430
178static void __init of_ti_omap2430_interface_clk_setup(struct device_node *node)
179{
180 _of_ti_interface_clk_setup(node, &clkhwops_omap2430_i2chs_wait);
181}
182CLK_OF_DECLARE(ti_omap2430_interface_clk, "ti,omap2430-interface-clock",
183 of_ti_omap2430_interface_clk_setup);
184#endif