blob: 3f7b26540be86d01ad5d7d2a93884a445290ff84 [file] [log] [blame]
Tero Kristoc82f8952014-12-16 18:20:46 +02001/*
2 * TI Clock driver internal definitions
3 *
4 * Copyright (C) 2014 Texas Instruments, Inc
5 * Tero Kristo (t-kristo@ti.com)
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation version 2.
10 *
11 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
12 * kind, whether express or implied; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16#ifndef __DRIVERS_CLK_TI_CLOCK__
17#define __DRIVERS_CLK_TI_CLOCK__
18
Tero Kristo6dbde942017-02-09 14:45:45 +020019struct clk_omap_divider {
20 struct clk_hw hw;
Tero Kristo6c0afb52017-02-09 11:24:37 +020021 struct clk_omap_reg reg;
Tero Kristo6dbde942017-02-09 14:45:45 +020022 u8 shift;
23 u8 width;
24 u8 flags;
25 const struct clk_div_table *table;
26};
27
28#define to_clk_omap_divider(_hw) container_of(_hw, struct clk_omap_divider, hw)
29
Tero Kristod83bc5b2017-02-09 14:40:40 +020030struct clk_omap_mux {
31 struct clk_hw hw;
Tero Kristo6c0afb52017-02-09 11:24:37 +020032 struct clk_omap_reg reg;
Tero Kristod83bc5b2017-02-09 14:40:40 +020033 u32 *table;
34 u32 mask;
35 u8 shift;
36 u8 flags;
37};
38
39#define to_clk_omap_mux(_hw) container_of(_hw, struct clk_omap_mux, hw)
40
Tero Kristoc82f8952014-12-16 18:20:46 +020041enum {
42 TI_CLK_FIXED,
43 TI_CLK_MUX,
44 TI_CLK_DIVIDER,
45 TI_CLK_COMPOSITE,
46 TI_CLK_FIXED_FACTOR,
47 TI_CLK_GATE,
48 TI_CLK_DPLL,
49};
50
51/* Global flags */
52#define CLKF_INDEX_POWER_OF_TWO (1 << 0)
53#define CLKF_INDEX_STARTS_AT_ONE (1 << 1)
54#define CLKF_SET_RATE_PARENT (1 << 2)
55#define CLKF_OMAP3 (1 << 3)
56#define CLKF_AM35XX (1 << 4)
57
58/* Gate flags */
59#define CLKF_SET_BIT_TO_DISABLE (1 << 5)
60#define CLKF_INTERFACE (1 << 6)
61#define CLKF_SSI (1 << 7)
62#define CLKF_DSS (1 << 8)
63#define CLKF_HSOTGUSB (1 << 9)
64#define CLKF_WAIT (1 << 10)
65#define CLKF_NO_WAIT (1 << 11)
66#define CLKF_HSDIV (1 << 12)
67#define CLKF_CLKDM (1 << 13)
68
69/* DPLL flags */
70#define CLKF_LOW_POWER_STOP (1 << 5)
71#define CLKF_LOCK (1 << 6)
72#define CLKF_LOW_POWER_BYPASS (1 << 7)
73#define CLKF_PER (1 << 8)
74#define CLKF_CORE (1 << 9)
75#define CLKF_J_TYPE (1 << 10)
76
77#define CLK(dev, con, ck) \
78 { \
79 .lk = { \
80 .dev_id = dev, \
81 .con_id = con, \
82 }, \
83 .clk = ck, \
84 }
85
86struct ti_clk {
87 const char *name;
88 const char *clkdm_name;
89 int type;
90 void *data;
91 struct ti_clk *patch;
92 struct clk *clk;
93};
94
95struct ti_clk_alias {
96 struct ti_clk *clk;
97 struct clk_lookup lk;
98 struct list_head link;
99};
100
101struct ti_clk_fixed {
102 u32 frequency;
103 u16 flags;
104};
105
106struct ti_clk_mux {
107 u8 bit_shift;
108 int num_parents;
109 u16 reg;
110 u8 module;
Tero Kristoce382d42016-10-05 15:37:02 +0300111 const char * const *parents;
Tero Kristoc82f8952014-12-16 18:20:46 +0200112 u16 flags;
113};
114
115struct ti_clk_divider {
116 const char *parent;
117 u8 bit_shift;
118 u16 max_div;
119 u16 reg;
120 u8 module;
121 int *dividers;
122 int num_dividers;
123 u16 flags;
124};
125
126struct ti_clk_fixed_factor {
127 const char *parent;
128 u16 div;
129 u16 mult;
130 u16 flags;
131};
132
133struct ti_clk_gate {
134 const char *parent;
135 u8 bit_shift;
136 u16 reg;
137 u8 module;
138 u16 flags;
139};
140
141struct ti_clk_composite {
142 struct ti_clk_divider *divider;
143 struct ti_clk_mux *mux;
144 struct ti_clk_gate *gate;
145 u16 flags;
146};
147
148struct ti_clk_clkdm_gate {
149 const char *parent;
150 u16 flags;
151};
152
153struct ti_clk_dpll {
154 int num_parents;
155 u16 control_reg;
156 u16 idlest_reg;
157 u16 autoidle_reg;
158 u16 mult_div1_reg;
159 u8 module;
160 const char **parents;
161 u16 flags;
162 u8 modes;
163 u32 mult_mask;
164 u32 div1_mask;
165 u32 enable_mask;
166 u32 autoidle_mask;
167 u32 freqsel_mask;
168 u32 idlest_mask;
169 u32 dco_mask;
170 u32 sddiv_mask;
171 u16 max_multiplier;
172 u16 max_divider;
Tero Kristoed405a22015-01-29 22:24:28 +0200173 u8 min_divider;
Tero Kristoc82f8952014-12-16 18:20:46 +0200174 u8 auto_recal_bit;
175 u8 recal_en_bit;
176 u8 recal_st_bit;
177};
178
Tero Kristoa3314e92015-03-04 21:02:05 +0200179/* Composite clock component types */
180enum {
181 CLK_COMPONENT_TYPE_GATE = 0,
182 CLK_COMPONENT_TYPE_DIVIDER,
183 CLK_COMPONENT_TYPE_MUX,
184 CLK_COMPONENT_TYPE_MAX,
185};
186
187/**
188 * struct ti_dt_clk - OMAP DT clock alias declarations
189 * @lk: clock lookup definition
190 * @node_name: clock DT node to map to
191 */
192struct ti_dt_clk {
193 struct clk_lookup lk;
194 char *node_name;
195};
196
197#define DT_CLK(dev, con, name) \
198 { \
199 .lk = { \
200 .dev_id = dev, \
201 .con_id = con, \
202 }, \
203 .node_name = name, \
204 }
205
206typedef void (*ti_of_clk_init_cb_t)(struct clk_hw *, struct device_node *);
207
Tero Kristof1876162014-12-16 18:20:48 +0200208struct clk *ti_clk_register_gate(struct ti_clk *setup);
Tero Kristo06524fa2014-12-16 18:20:49 +0200209struct clk *ti_clk_register_interface(struct ti_clk *setup);
Tero Kristo7c18a652014-12-16 18:20:47 +0200210struct clk *ti_clk_register_mux(struct ti_clk *setup);
Tero Kristod96f7742014-12-16 18:20:50 +0200211struct clk *ti_clk_register_divider(struct ti_clk *setup);
Tero Kristob26bcf92014-12-16 18:20:52 +0200212struct clk *ti_clk_register_composite(struct ti_clk *setup);
Tero Kristoed405a22015-01-29 22:24:28 +0200213struct clk *ti_clk_register_dpll(struct ti_clk *setup);
Tero Kristo21f0bf22016-09-29 12:00:57 +0300214struct clk *ti_clk_register(struct device *dev, struct clk_hw *hw,
215 const char *con);
216int ti_clk_add_alias(struct device *dev, struct clk *clk, const char *con);
Tero Kristoc17435c2016-09-29 12:05:00 +0300217void ti_clk_add_aliases(void);
Tero Kristo7c18a652014-12-16 18:20:47 +0200218
Tero Kristod96f7742014-12-16 18:20:50 +0200219struct clk_hw *ti_clk_build_component_div(struct ti_clk_divider *setup);
Tero Kristof1876162014-12-16 18:20:48 +0200220struct clk_hw *ti_clk_build_component_gate(struct ti_clk_gate *setup);
Tero Kristo7c18a652014-12-16 18:20:47 +0200221struct clk_hw *ti_clk_build_component_mux(struct ti_clk_mux *setup);
222
Tero Kristo4f6be562017-02-09 14:46:53 +0200223int ti_clk_parse_divider_data(int *div_table, int num_dividers, int max_div,
224 u8 flags, u8 *width,
225 const struct clk_div_table **table);
226
Tero Kristoc82f8952014-12-16 18:20:46 +0200227void ti_clk_patch_legacy_clks(struct ti_clk **patch);
228struct clk *ti_clk_register_clk(struct ti_clk *setup);
229int ti_clk_register_legacy_clks(struct ti_clk_alias *clks);
230
Tero Kristo6c0afb52017-02-09 11:24:37 +0200231int ti_clk_get_reg_addr(struct device_node *node, int index,
232 struct clk_omap_reg *reg);
Tero Kristoa3314e92015-03-04 21:02:05 +0200233void ti_dt_clocks_register(struct ti_dt_clk *oclks);
234int ti_clk_retry_init(struct device_node *node, struct clk_hw *hw,
235 ti_of_clk_init_cb_t func);
236int ti_clk_add_component(struct device_node *node, struct clk_hw *hw, int type);
237
Stephen Boyda53ad8e2015-07-30 17:20:57 -0700238void omap2_init_clk_hw_omap_clocks(struct clk_hw *hw);
Tero Kristobf22bae2015-03-02 19:06:54 +0200239int of_ti_clk_autoidle_setup(struct device_node *node);
Tero Kristoa5aa8a62015-03-03 10:51:01 +0200240void omap2_clk_enable_init_clocks(const char **clk_names, u8 num_clocks);
Tero Kristobf22bae2015-03-02 19:06:54 +0200241
Tero Kristo0565fb12015-03-03 13:27:48 +0200242extern const struct clk_hw_omap_ops clkhwops_omap3_dpll;
Tero Kristo59245ce2015-03-02 11:07:35 +0200243extern const struct clk_hw_omap_ops clkhwops_omap4_dpllmx;
Tero Kristo9f37e902015-03-03 15:28:53 +0200244extern const struct clk_hw_omap_ops clkhwops_wait;
Tero Kristoef14db02015-03-02 14:33:54 +0200245extern const struct clk_hw_omap_ops clkhwops_iclk;
246extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
Tero Kristod5a04dd2015-03-03 16:08:42 +0200247extern const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait;
Tero Kristof2671d52015-03-03 17:28:12 +0200248extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
249extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_hsotgusb_wait;
250extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_dss_usbhost_wait;
251extern const struct clk_hw_omap_ops clkhwops_omap3430es2_iclk_ssi_wait;
Tero Kristoc9a58b02015-03-03 21:19:25 +0200252extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
253extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait;
Tero Kristo59245ce2015-03-02 11:07:35 +0200254
Tero Kristoa3314e92015-03-04 21:02:05 +0200255extern const struct clk_ops ti_clk_divider_ops;
256extern const struct clk_ops ti_clk_mux_ops;
Tero Kristo9a00fa62017-02-09 11:10:19 +0200257extern const struct clk_ops omap_gate_clk_ops;
Tero Kristoa3314e92015-03-04 21:02:05 +0200258
Tero Kristo2e1a2942016-09-30 14:13:38 +0300259void omap2_init_clk_clkdm(struct clk_hw *hw);
Tero Kristobd86cfd2015-03-03 16:22:50 +0200260int omap2_clkops_enable_clkdm(struct clk_hw *hw);
261void omap2_clkops_disable_clkdm(struct clk_hw *hw);
262
Tero Kristo9f37e902015-03-03 15:28:53 +0200263int omap2_dflt_clk_enable(struct clk_hw *hw);
264void omap2_dflt_clk_disable(struct clk_hw *hw);
265int omap2_dflt_clk_is_enabled(struct clk_hw *hw);
Tero Kristoa3314e92015-03-04 21:02:05 +0200266void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
Tero Kristo6c0afb52017-02-09 11:24:37 +0200267 struct clk_omap_reg *other_reg,
Tero Kristoa3314e92015-03-04 21:02:05 +0200268 u8 *other_bit);
269void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
Tero Kristo6c0afb52017-02-09 11:24:37 +0200270 struct clk_omap_reg *idlest_reg,
Tero Kristoa3314e92015-03-04 21:02:05 +0200271 u8 *idlest_bit, u8 *idlest_val);
272
273void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
274void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
Tero Kristo9f37e902015-03-03 15:28:53 +0200275
Tero Kristob138b022015-03-02 09:57:28 +0200276u8 omap2_init_dpll_parent(struct clk_hw *hw);
Tero Kristo0565fb12015-03-03 13:27:48 +0200277int omap3_noncore_dpll_enable(struct clk_hw *hw);
278void omap3_noncore_dpll_disable(struct clk_hw *hw);
279int omap3_noncore_dpll_set_parent(struct clk_hw *hw, u8 index);
280int omap3_noncore_dpll_set_rate(struct clk_hw *hw, unsigned long rate,
281 unsigned long parent_rate);
282int omap3_noncore_dpll_set_rate_and_parent(struct clk_hw *hw,
283 unsigned long rate,
284 unsigned long parent_rate,
285 u8 index);
Stephen Boyd4d341052015-07-28 11:58:26 -0700286int omap3_noncore_dpll_determine_rate(struct clk_hw *hw,
287 struct clk_rate_request *req);
Tero Kristo0565fb12015-03-03 13:27:48 +0200288long omap2_dpll_round_rate(struct clk_hw *hw, unsigned long target_rate,
289 unsigned long *parent_rate);
290unsigned long omap3_clkoutx2_recalc(struct clk_hw *hw,
291 unsigned long parent_rate);
292
Richard Watts035cd482016-12-02 23:14:38 +0200293/*
294 * OMAP3_DPLL5_FREQ_FOR_USBHOST: USBHOST and USBTLL are the only clocks
295 * that are sourced by DPLL5, and both of these require this clock
296 * to be at 120 MHz for proper operation.
297 */
298#define OMAP3_DPLL5_FREQ_FOR_USBHOST 120000000
299
Tero Kristo0565fb12015-03-03 13:27:48 +0200300unsigned long omap3_dpll_recalc(struct clk_hw *hw, unsigned long parent_rate);
301int omap3_dpll4_set_rate(struct clk_hw *clk, unsigned long rate,
302 unsigned long parent_rate);
303int omap3_dpll4_set_rate_and_parent(struct clk_hw *hw, unsigned long rate,
304 unsigned long parent_rate, u8 index);
Richard Watts035cd482016-12-02 23:14:38 +0200305int omap3_dpll5_set_rate(struct clk_hw *hw, unsigned long rate,
306 unsigned long parent_rate);
Tero Kristo0565fb12015-03-03 13:27:48 +0200307void omap3_clk_lock_dpll5(void);
Tero Kristob138b022015-03-02 09:57:28 +0200308
Tero Kristo59245ce2015-03-02 11:07:35 +0200309unsigned long omap4_dpll_regm4xen_recalc(struct clk_hw *hw,
310 unsigned long parent_rate);
311long omap4_dpll_regm4xen_round_rate(struct clk_hw *hw,
312 unsigned long target_rate,
313 unsigned long *parent_rate);
Stephen Boyd4d341052015-07-28 11:58:26 -0700314int omap4_dpll_regm4xen_determine_rate(struct clk_hw *hw,
315 struct clk_rate_request *req);
Tero Kristo59245ce2015-03-02 11:07:35 +0200316
Tero Kristoe9e63082015-04-27 21:55:42 +0300317extern struct ti_clk_ll_ops *ti_clk_ll_ops;
318
Tero Kristoc82f8952014-12-16 18:20:46 +0200319#endif