xref: /linux/arch/arm/mach-omap2/clock.h (revision 8111e01045c1b3ac6b5d3c2ee3b8dc562efdf3ae)
1543d9378SPaul Walmsley /*
2543d9378SPaul Walmsley  *  linux/arch/arm/mach-omap2/clock.h
3543d9378SPaul Walmsley  *
4d8a94458SPaul Walmsley  *  Copyright (C) 2005-2009 Texas Instruments, Inc.
5530e544fSPaul Walmsley  *  Copyright (C) 2004-2011 Nokia Corporation
6a16e9703STony Lindgren  *
7a16e9703STony Lindgren  *  Contacts:
8543d9378SPaul Walmsley  *  Richard Woodruff <r-woodruff2@ti.com>
9543d9378SPaul Walmsley  *  Paul Walmsley
10543d9378SPaul Walmsley  *
11543d9378SPaul Walmsley  * This program is free software; you can redistribute it and/or modify
12543d9378SPaul Walmsley  * it under the terms of the GNU General Public License version 2 as
13543d9378SPaul Walmsley  * published by the Free Software Foundation.
14543d9378SPaul Walmsley  */
15543d9378SPaul Walmsley 
16543d9378SPaul Walmsley #ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H
17543d9378SPaul Walmsley #define __ARCH_ARM_MACH_OMAP2_CLOCK_H
18543d9378SPaul Walmsley 
1912706c54SPaul Walmsley #include <linux/kernel.h>
20a135eaaeSPaul Walmsley #include <linux/list.h>
2112706c54SPaul Walmsley 
22e10dd62fSPaul Walmsley #include <linux/clkdev.h>
23f9ae32a7SMike Turquette #include <linux/clk-provider.h>
24f38b0dd6STero Kristo #include <linux/clk/ti.h>
25e10dd62fSPaul Walmsley 
26e10dd62fSPaul Walmsley struct omap_clk {
27e10dd62fSPaul Walmsley 	u16				cpu;
28e10dd62fSPaul Walmsley 	struct clk_lookup		lk;
29e10dd62fSPaul Walmsley };
30e10dd62fSPaul Walmsley 
3178e52e02SJ Keerthy #define CLK(dev, con, ck)		\
32e10dd62fSPaul Walmsley 	{				\
33e10dd62fSPaul Walmsley 		.lk = {			\
34e10dd62fSPaul Walmsley 			.dev_id = dev,	\
35e10dd62fSPaul Walmsley 			.con_id = con,	\
36e10dd62fSPaul Walmsley 			.clk = ck,	\
37e10dd62fSPaul Walmsley 		},			\
38e10dd62fSPaul Walmsley 	}
39e10dd62fSPaul Walmsley 
40b5a2366cSRajendra Nayak struct clockdomain;
41b5a2366cSRajendra Nayak 
428c725dcdSPaul Walmsley #define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name)	\
438c725dcdSPaul Walmsley 	static struct clk _name = {				\
448c725dcdSPaul Walmsley 		.name = #_name,					\
458c725dcdSPaul Walmsley 		.hw = &_name##_hw.hw,				\
468c725dcdSPaul Walmsley 		.parent_names = _parent_array_name,		\
478c725dcdSPaul Walmsley 		.num_parents = ARRAY_SIZE(_parent_array_name),	\
488c725dcdSPaul Walmsley 		.ops = &_clkops_name,				\
498c725dcdSPaul Walmsley 	};
508c725dcdSPaul Walmsley 
51601155b0SAfzal Mohammed #define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name,	\
52601155b0SAfzal Mohammed 				_clkops_name, _flags)		\
53601155b0SAfzal Mohammed 	static struct clk _name = {				\
54601155b0SAfzal Mohammed 		.name = #_name,					\
55601155b0SAfzal Mohammed 		.hw = &_name##_hw.hw,				\
56601155b0SAfzal Mohammed 		.parent_names = _parent_array_name,		\
57601155b0SAfzal Mohammed 		.num_parents = ARRAY_SIZE(_parent_array_name),	\
58601155b0SAfzal Mohammed 		.ops = &_clkops_name,				\
59601155b0SAfzal Mohammed 		.flags = _flags,				\
60601155b0SAfzal Mohammed 	};
61601155b0SAfzal Mohammed 
628c725dcdSPaul Walmsley #define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name)		\
638c725dcdSPaul Walmsley 	static struct clk_hw_omap _name##_hw = {		\
648c725dcdSPaul Walmsley 		.hw = {						\
658c725dcdSPaul Walmsley 			.clk = &_name,				\
668c725dcdSPaul Walmsley 		},						\
678c725dcdSPaul Walmsley 		.clkdm_name = _clkdm_name,			\
688c725dcdSPaul Walmsley 	};
698c725dcdSPaul Walmsley 
708c725dcdSPaul Walmsley #define DEFINE_CLK_OMAP_MUX(_name, _clkdm_name, _clksel,	\
718c725dcdSPaul Walmsley 			    _clksel_reg, _clksel_mask,		\
728c725dcdSPaul Walmsley 			    _parent_names, _ops)		\
738c725dcdSPaul Walmsley 	static struct clk _name;				\
748c725dcdSPaul Walmsley 	static struct clk_hw_omap _name##_hw = {		\
758c725dcdSPaul Walmsley 		.hw = {						\
768c725dcdSPaul Walmsley 			.clk = &_name,				\
778c725dcdSPaul Walmsley 		},						\
788c725dcdSPaul Walmsley 		.clksel		= _clksel,			\
798c725dcdSPaul Walmsley 		.clksel_reg	= _clksel_reg,			\
808c725dcdSPaul Walmsley 		.clksel_mask	= _clksel_mask,			\
818c725dcdSPaul Walmsley 		.clkdm_name	= _clkdm_name,			\
828c725dcdSPaul Walmsley 	};							\
838c725dcdSPaul Walmsley 	DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
848c725dcdSPaul Walmsley 
858c725dcdSPaul Walmsley #define DEFINE_CLK_OMAP_MUX_GATE(_name, _clkdm_name, _clksel,	\
868c725dcdSPaul Walmsley 				 _clksel_reg, _clksel_mask,	\
878c725dcdSPaul Walmsley 				 _enable_reg, _enable_bit,	\
888c725dcdSPaul Walmsley 				 _hwops, _parent_names, _ops)	\
898c725dcdSPaul Walmsley 	static struct clk _name;				\
908c725dcdSPaul Walmsley 	static struct clk_hw_omap _name##_hw = {		\
918c725dcdSPaul Walmsley 		.hw = {						\
928c725dcdSPaul Walmsley 			.clk = &_name,				\
938c725dcdSPaul Walmsley 		},						\
948c725dcdSPaul Walmsley 		.ops		= _hwops,			\
958c725dcdSPaul Walmsley 		.enable_reg	= _enable_reg,			\
968c725dcdSPaul Walmsley 		.enable_bit	= _enable_bit,			\
978c725dcdSPaul Walmsley 		.clksel		= _clksel,			\
988c725dcdSPaul Walmsley 		.clksel_reg	= _clksel_reg,			\
998c725dcdSPaul Walmsley 		.clksel_mask	= _clksel_mask,			\
1008c725dcdSPaul Walmsley 		.clkdm_name	= _clkdm_name,			\
1018c725dcdSPaul Walmsley 	};							\
1028c725dcdSPaul Walmsley 	DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
1038c725dcdSPaul Walmsley 
104a135eaaeSPaul Walmsley /* struct clksel_rate.flags possibilities */
105a135eaaeSPaul Walmsley #define RATE_IN_242X		(1 << 0)
106a135eaaeSPaul Walmsley #define RATE_IN_243X		(1 << 1)
107a135eaaeSPaul Walmsley #define RATE_IN_3430ES1		(1 << 2)	/* 3430ES1 rates only */
108a135eaaeSPaul Walmsley #define RATE_IN_3430ES2PLUS	(1 << 3)	/* 3430 ES >= 2 rates only */
109a135eaaeSPaul Walmsley #define RATE_IN_36XX		(1 << 4)
110a135eaaeSPaul Walmsley #define RATE_IN_4430		(1 << 5)
111a135eaaeSPaul Walmsley #define RATE_IN_TI816X		(1 << 6)
112a135eaaeSPaul Walmsley #define RATE_IN_4460		(1 << 7)
113a135eaaeSPaul Walmsley #define RATE_IN_AM33XX		(1 << 8)
114a135eaaeSPaul Walmsley #define RATE_IN_TI814X		(1 << 9)
115a135eaaeSPaul Walmsley 
116a135eaaeSPaul Walmsley #define RATE_IN_24XX		(RATE_IN_242X | RATE_IN_243X)
117a135eaaeSPaul Walmsley #define RATE_IN_34XX		(RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
118a135eaaeSPaul Walmsley #define RATE_IN_3XXX		(RATE_IN_34XX | RATE_IN_36XX)
119a135eaaeSPaul Walmsley #define RATE_IN_44XX		(RATE_IN_4430 | RATE_IN_4460)
120a135eaaeSPaul Walmsley 
121a135eaaeSPaul Walmsley /* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
122a135eaaeSPaul Walmsley #define RATE_IN_3430ES2PLUS_36XX	(RATE_IN_3430ES2PLUS | RATE_IN_36XX)
123a135eaaeSPaul Walmsley 
124a135eaaeSPaul Walmsley 
125a135eaaeSPaul Walmsley /**
126a135eaaeSPaul Walmsley  * struct clksel_rate - register bitfield values corresponding to clk divisors
127a135eaaeSPaul Walmsley  * @val: register bitfield value (shifted to bit 0)
128a135eaaeSPaul Walmsley  * @div: clock divisor corresponding to @val
129a135eaaeSPaul Walmsley  * @flags: (see "struct clksel_rate.flags possibilities" above)
130a135eaaeSPaul Walmsley  *
131a135eaaeSPaul Walmsley  * @val should match the value of a read from struct clk.clksel_reg
132a135eaaeSPaul Walmsley  * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
133a135eaaeSPaul Walmsley  *
134a135eaaeSPaul Walmsley  * @div is the divisor that should be applied to the parent clock's rate
135a135eaaeSPaul Walmsley  * to produce the current clock's rate.
136a135eaaeSPaul Walmsley  */
137a135eaaeSPaul Walmsley struct clksel_rate {
138a135eaaeSPaul Walmsley 	u32			val;
139a135eaaeSPaul Walmsley 	u8			div;
140a135eaaeSPaul Walmsley 	u16			flags;
141a135eaaeSPaul Walmsley };
142a135eaaeSPaul Walmsley 
143a135eaaeSPaul Walmsley /**
144a135eaaeSPaul Walmsley  * struct clksel - available parent clocks, and a pointer to their divisors
145a135eaaeSPaul Walmsley  * @parent: struct clk * to a possible parent clock
146a135eaaeSPaul Walmsley  * @rates: available divisors for this parent clock
147a135eaaeSPaul Walmsley  *
148a135eaaeSPaul Walmsley  * A struct clksel is always associated with one or more struct clks
149a135eaaeSPaul Walmsley  * and one or more struct clksel_rates.
150a135eaaeSPaul Walmsley  */
151a135eaaeSPaul Walmsley struct clksel {
152a135eaaeSPaul Walmsley 	struct clk		 *parent;
153a135eaaeSPaul Walmsley 	const struct clksel_rate *rates;
154a135eaaeSPaul Walmsley };
155a135eaaeSPaul Walmsley 
156b5a2366cSRajendra Nayak unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
157b5a2366cSRajendra Nayak 					unsigned long parent_rate);
158543d9378SPaul Walmsley 
159c0bf3132SRussell King /* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
160c0bf3132SRussell King #define CORE_CLK_SRC_32K		0x0
161c0bf3132SRussell King #define CORE_CLK_SRC_DPLL		0x1
162c0bf3132SRussell King #define CORE_CLK_SRC_DPLL_X2		0x2
163c0bf3132SRussell King 
164c0bf3132SRussell King /* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
165c0bf3132SRussell King #define OMAP2XXX_EN_DPLL_LPBYPASS		0x1
166c0bf3132SRussell King #define OMAP2XXX_EN_DPLL_FRBYPASS		0x2
167c0bf3132SRussell King #define OMAP2XXX_EN_DPLL_LOCKED			0x3
168c0bf3132SRussell King 
169c0bf3132SRussell King /* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
170c0bf3132SRussell King #define OMAP3XXX_EN_DPLL_LPBYPASS		0x5
171c0bf3132SRussell King #define OMAP3XXX_EN_DPLL_FRBYPASS		0x6
172c0bf3132SRussell King #define OMAP3XXX_EN_DPLL_LOCKED			0x7
173c0bf3132SRussell King 
17416975a79SRajendra Nayak /* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
17516975a79SRajendra Nayak #define OMAP4XXX_EN_DPLL_MNBYPASS		0x4
17616975a79SRajendra Nayak #define OMAP4XXX_EN_DPLL_LPBYPASS		0x5
17716975a79SRajendra Nayak #define OMAP4XXX_EN_DPLL_FRBYPASS		0x6
17816975a79SRajendra Nayak #define OMAP4XXX_EN_DPLL_LOCKED			0x7
17916975a79SRajendra Nayak 
18032cc0021SMike Turquette u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
18132cc0021SMike Turquette void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
18232cc0021SMike Turquette void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
18332cc0021SMike Turquette int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
18432cc0021SMike Turquette void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
18532cc0021SMike Turquette void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
186543d9378SPaul Walmsley 
18712706c54SPaul Walmsley void __init omap2_clk_disable_clkdm_control(void);
188435699dbSPaul Walmsley 
189435699dbSPaul Walmsley /* clkt_clksel.c public functions */
19032cc0021SMike Turquette u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
19132cc0021SMike Turquette 				unsigned long target_rate,
19232cc0021SMike Turquette 				u32 *new_div);
19332cc0021SMike Turquette u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
19432cc0021SMike Turquette unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
19532cc0021SMike Turquette long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
19632cc0021SMike Turquette 				unsigned long *parent_rate);
19732cc0021SMike Turquette int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
19832cc0021SMike Turquette 				unsigned long parent_rate);
19932cc0021SMike Turquette int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
200435699dbSPaul Walmsley 
201530e544fSPaul Walmsley /* clkt_iclk.c public functions */
202b4777a21SRajendra Nayak extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
203b4777a21SRajendra Nayak extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
204530e544fSPaul Walmsley 
20532cc0021SMike Turquette unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
206435699dbSPaul Walmsley 
20732cc0021SMike Turquette void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
20832cc0021SMike Turquette 				   void __iomem **other_reg,
20932cc0021SMike Turquette 				   u8 *other_bit);
21032cc0021SMike Turquette void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
21132cc0021SMike Turquette 				void __iomem **idlest_reg,
21232cc0021SMike Turquette 				u8 *idlest_bit, u8 *idlest_val);
21323fb8ba3SRajendra Nayak int omap2_clk_enable_autoidle_all(void);
214818b40e5STero Kristo int omap2_clk_allow_idle(struct clk *clk);
215818b40e5STero Kristo int omap2_clk_deny_idle(struct clk *clk);
2164d30e82cSPaul Walmsley int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
2174d30e82cSPaul Walmsley void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
2184d30e82cSPaul Walmsley 			       const char *core_ck_name,
2194d30e82cSPaul Walmsley 			       const char *mpu_ck_name);
220543d9378SPaul Walmsley 
2213ada6b10STero Kristo u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg);
2223ada6b10STero Kristo void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg);
2233ada6b10STero Kristo 
22499541195SAfzal Mohammed extern u16 cpu_mask;
225d8a94458SPaul Walmsley 
226*8111e010STero Kristo /*
227*8111e010STero Kristo  * Clock features setup. Used instead of CPU type checks.
228*8111e010STero Kristo  */
229*8111e010STero Kristo struct ti_clk_features {
230*8111e010STero Kristo 	u32 flags;
231*8111e010STero Kristo };
232*8111e010STero Kristo extern struct ti_clk_features ti_clk_features;
233*8111e010STero Kristo 
234b36ee724SRussell King extern const struct clkops clkops_omap2_dflt_wait;
2357c43d547SSantosh Shilimkar extern const struct clkops clkops_dummy;
236bc51da4eSRussell King extern const struct clkops clkops_omap2_dflt;
237b36ee724SRussell King 
23882e9bd58SPaul Walmsley extern struct clk_functions omap2_clk_functions;
23982e9bd58SPaul Walmsley 
240d8a94458SPaul Walmsley extern const struct clksel_rate gpt_32k_rates[];
241d8a94458SPaul Walmsley extern const struct clksel_rate gpt_sys_rates[];
242d8a94458SPaul Walmsley extern const struct clksel_rate gfx_l3_rates[];
24322411396SPaul Walmsley extern const struct clksel_rate dsp_ick_rates[];
244cb26867eSRajendra Nayak extern struct clk dummy_ck;
245543d9378SPaul Walmsley 
24632cc0021SMike Turquette extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
24732cc0021SMike Turquette extern const struct clk_hw_omap_ops clkhwops_wait;
248b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
249b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
250b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
251b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
252b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_apll54;
253b4777a21SRajendra Nayak extern const struct clk_hw_omap_ops clkhwops_apll96;
254657ebfadSPaul Walmsley 
255571efa0dSPaul Walmsley /* clksel_rate blocks shared between OMAP44xx and AM33xx */
256571efa0dSPaul Walmsley extern const struct clksel_rate div_1_0_rates[];
257cb26867eSRajendra Nayak extern const struct clksel_rate div3_1to4_rates[];
258571efa0dSPaul Walmsley extern const struct clksel_rate div_1_1_rates[];
259571efa0dSPaul Walmsley extern const struct clksel_rate div_1_2_rates[];
260571efa0dSPaul Walmsley extern const struct clksel_rate div_1_3_rates[];
261571efa0dSPaul Walmsley extern const struct clksel_rate div_1_4_rates[];
262571efa0dSPaul Walmsley extern const struct clksel_rate div31_1to31_rates[];
263571efa0dSPaul Walmsley 
2643ada6b10STero Kristo extern void __iomem *clk_memmaps[];
2653ada6b10STero Kristo 
266e30384abSVaibhav Hiremath extern int am33xx_clk_init(void);
267e30384abSVaibhav Hiremath 
26832cc0021SMike Turquette extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
26932cc0021SMike Turquette extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
27032cc0021SMike Turquette 
27178e52e02SJ Keerthy extern void omap_clocks_register(struct omap_clk *oclks, int cnt);
272*8111e010STero Kristo 
273*8111e010STero Kristo void __init ti_clk_init_features(void);
274543d9378SPaul Walmsley #endif
275