blob: 0f100dc4e97f3383d46f5c2f1f8f5c6c37c8c533 [file] [log] [blame]
Paul Walmsley543d9372008-03-18 10:22:06 +02001/*
2 * linux/arch/arm/mach-omap2/clock.h
3 *
Paul Walmsleyd8a94452009-12-08 16:21:29 -07004 * Copyright (C) 2005-2009 Texas Instruments, Inc.
Paul Walmsley530e5442011-02-25 15:39:28 -07005 * Copyright (C) 2004-2011 Nokia Corporation
Tony Lindgrena16e9702008-03-18 11:56:39 +02006 *
7 * Contacts:
Paul Walmsley543d9372008-03-18 10:22:06 +02008 * Richard Woodruff <r-woodruff2@ti.com>
Paul Walmsley543d9372008-03-18 10:22:06 +02009 * Paul Walmsley
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
14 */
15
16#ifndef __ARCH_ARM_MACH_OMAP2_CLOCK_H
17#define __ARCH_ARM_MACH_OMAP2_CLOCK_H
18
Paul Walmsley12706c52011-07-10 05:57:06 -060019#include <linux/kernel.h>
Paul Walmsleya135eaa2012-09-27 10:33:34 -060020#include <linux/list.h>
Paul Walmsley12706c52011-07-10 05:57:06 -060021
Paul Walmsleye10dd622012-09-27 10:33:35 -060022#include <linux/clkdev.h>
Mike Turquettef9ae32a2012-11-07 13:14:47 -080023#include <linux/clk-provider.h>
Tero Kristof38b0dd2013-06-12 16:04:34 +030024#include <linux/clk/ti.h>
Paul Walmsleye10dd622012-09-27 10:33:35 -060025
26struct omap_clk {
27 u16 cpu;
28 struct clk_lookup lk;
29};
30
J Keerthy78e52e02013-03-18 09:57:39 -060031#define CLK(dev, con, ck) \
Paul Walmsleye10dd622012-09-27 10:33:35 -060032 { \
Paul Walmsleye10dd622012-09-27 10:33:35 -060033 .lk = { \
34 .dev_id = dev, \
35 .con_id = con, \
36 .clk = ck, \
37 }, \
38 }
39
Rajendra Nayakb5a23662012-11-10 16:58:40 -070040struct clockdomain;
Rajendra Nayakb5a23662012-11-10 16:58:40 -070041
Paul Walmsley8c725dc2012-09-16 10:45:54 -060042#define DEFINE_STRUCT_CLK(_name, _parent_array_name, _clkops_name) \
43 static struct clk _name = { \
44 .name = #_name, \
45 .hw = &_name##_hw.hw, \
46 .parent_names = _parent_array_name, \
47 .num_parents = ARRAY_SIZE(_parent_array_name), \
48 .ops = &_clkops_name, \
49 };
50
Afzal Mohammed601155b2013-01-23 17:12:05 +053051#define DEFINE_STRUCT_CLK_FLAGS(_name, _parent_array_name, \
52 _clkops_name, _flags) \
53 static struct clk _name = { \
54 .name = #_name, \
55 .hw = &_name##_hw.hw, \
56 .parent_names = _parent_array_name, \
57 .num_parents = ARRAY_SIZE(_parent_array_name), \
58 .ops = &_clkops_name, \
59 .flags = _flags, \
60 };
61
Paul Walmsley8c725dc2012-09-16 10:45:54 -060062#define DEFINE_STRUCT_CLK_HW_OMAP(_name, _clkdm_name) \
63 static struct clk_hw_omap _name##_hw = { \
64 .hw = { \
65 .clk = &_name, \
66 }, \
67 .clkdm_name = _clkdm_name, \
68 };
69
70#define DEFINE_CLK_OMAP_MUX(_name, _clkdm_name, _clksel, \
71 _clksel_reg, _clksel_mask, \
72 _parent_names, _ops) \
73 static struct clk _name; \
74 static struct clk_hw_omap _name##_hw = { \
75 .hw = { \
76 .clk = &_name, \
77 }, \
78 .clksel = _clksel, \
79 .clksel_reg = _clksel_reg, \
80 .clksel_mask = _clksel_mask, \
81 .clkdm_name = _clkdm_name, \
82 }; \
83 DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
84
85#define DEFINE_CLK_OMAP_MUX_GATE(_name, _clkdm_name, _clksel, \
86 _clksel_reg, _clksel_mask, \
87 _enable_reg, _enable_bit, \
88 _hwops, _parent_names, _ops) \
89 static struct clk _name; \
90 static struct clk_hw_omap _name##_hw = { \
91 .hw = { \
92 .clk = &_name, \
93 }, \
94 .ops = _hwops, \
95 .enable_reg = _enable_reg, \
96 .enable_bit = _enable_bit, \
97 .clksel = _clksel, \
98 .clksel_reg = _clksel_reg, \
99 .clksel_mask = _clksel_mask, \
100 .clkdm_name = _clkdm_name, \
101 }; \
102 DEFINE_STRUCT_CLK(_name, _parent_names, _ops);
103
Paul Walmsleya135eaa2012-09-27 10:33:34 -0600104/* struct clksel_rate.flags possibilities */
105#define RATE_IN_242X (1 << 0)
106#define RATE_IN_243X (1 << 1)
107#define RATE_IN_3430ES1 (1 << 2) /* 3430ES1 rates only */
108#define RATE_IN_3430ES2PLUS (1 << 3) /* 3430 ES >= 2 rates only */
109#define RATE_IN_36XX (1 << 4)
110#define RATE_IN_4430 (1 << 5)
111#define RATE_IN_TI816X (1 << 6)
112#define RATE_IN_4460 (1 << 7)
113#define RATE_IN_AM33XX (1 << 8)
114#define RATE_IN_TI814X (1 << 9)
115
116#define RATE_IN_24XX (RATE_IN_242X | RATE_IN_243X)
117#define RATE_IN_34XX (RATE_IN_3430ES1 | RATE_IN_3430ES2PLUS)
118#define RATE_IN_3XXX (RATE_IN_34XX | RATE_IN_36XX)
119#define RATE_IN_44XX (RATE_IN_4430 | RATE_IN_4460)
120
121/* RATE_IN_3430ES2PLUS_36XX includes 34xx/35xx with ES >=2, and all 36xx/37xx */
122#define RATE_IN_3430ES2PLUS_36XX (RATE_IN_3430ES2PLUS | RATE_IN_36XX)
123
124
125/**
126 * struct clksel_rate - register bitfield values corresponding to clk divisors
127 * @val: register bitfield value (shifted to bit 0)
128 * @div: clock divisor corresponding to @val
129 * @flags: (see "struct clksel_rate.flags possibilities" above)
130 *
131 * @val should match the value of a read from struct clk.clksel_reg
132 * AND'ed with struct clk.clksel_mask, shifted right to bit 0.
133 *
134 * @div is the divisor that should be applied to the parent clock's rate
135 * to produce the current clock's rate.
136 */
137struct clksel_rate {
138 u32 val;
139 u8 div;
140 u16 flags;
141};
142
143/**
144 * struct clksel - available parent clocks, and a pointer to their divisors
145 * @parent: struct clk * to a possible parent clock
146 * @rates: available divisors for this parent clock
147 *
148 * A struct clksel is always associated with one or more struct clks
149 * and one or more struct clksel_rates.
150 */
151struct clksel {
152 struct clk *parent;
153 const struct clksel_rate *rates;
154};
155
Rajendra Nayakb5a23662012-11-10 16:58:40 -0700156unsigned long omap_fixed_divisor_recalc(struct clk_hw *hw,
157 unsigned long parent_rate);
Paul Walmsley543d9372008-03-18 10:22:06 +0200158
Russell Kingc0bf3132009-02-19 13:29:22 +0000159/* CM_CLKSEL2_PLL.CORE_CLK_SRC bits (2XXX) */
160#define CORE_CLK_SRC_32K 0x0
161#define CORE_CLK_SRC_DPLL 0x1
162#define CORE_CLK_SRC_DPLL_X2 0x2
163
164/* OMAP2xxx CM_CLKEN_PLL.EN_DPLL bits - for omap2_get_dpll_rate() */
165#define OMAP2XXX_EN_DPLL_LPBYPASS 0x1
166#define OMAP2XXX_EN_DPLL_FRBYPASS 0x2
167#define OMAP2XXX_EN_DPLL_LOCKED 0x3
168
169/* OMAP3xxx CM_CLKEN_PLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
170#define OMAP3XXX_EN_DPLL_LPBYPASS 0x5
171#define OMAP3XXX_EN_DPLL_FRBYPASS 0x6
172#define OMAP3XXX_EN_DPLL_LOCKED 0x7
173
Rajendra Nayak16975a72009-12-08 18:47:16 -0700174/* OMAP4xxx CM_CLKMODE_DPLL*.EN_*_DPLL bits - for omap2_get_dpll_rate() */
175#define OMAP4XXX_EN_DPLL_MNBYPASS 0x4
176#define OMAP4XXX_EN_DPLL_LPBYPASS 0x5
177#define OMAP4XXX_EN_DPLL_FRBYPASS 0x6
178#define OMAP4XXX_EN_DPLL_LOCKED 0x7
179
Mike Turquette32cc0022012-11-10 16:58:41 -0700180u32 omap3_dpll_autoidle_read(struct clk_hw_omap *clk);
181void omap3_dpll_allow_idle(struct clk_hw_omap *clk);
182void omap3_dpll_deny_idle(struct clk_hw_omap *clk);
Mike Turquette32cc0022012-11-10 16:58:41 -0700183int omap4_dpllmx_gatectrl_read(struct clk_hw_omap *clk);
184void omap4_dpllmx_allow_gatectrl(struct clk_hw_omap *clk);
185void omap4_dpllmx_deny_gatectrl(struct clk_hw_omap *clk);
Paul Walmsley543d9372008-03-18 10:22:06 +0200186
Paul Walmsley12706c52011-07-10 05:57:06 -0600187void __init omap2_clk_disable_clkdm_control(void);
Paul Walmsley435699d2010-05-18 18:40:24 -0600188
189/* clkt_clksel.c public functions */
Mike Turquette32cc0022012-11-10 16:58:41 -0700190u32 omap2_clksel_round_rate_div(struct clk_hw_omap *clk,
191 unsigned long target_rate,
192 u32 *new_div);
193u8 omap2_clksel_find_parent_index(struct clk_hw *hw);
194unsigned long omap2_clksel_recalc(struct clk_hw *hw, unsigned long parent_rate);
195long omap2_clksel_round_rate(struct clk_hw *hw, unsigned long target_rate,
196 unsigned long *parent_rate);
197int omap2_clksel_set_rate(struct clk_hw *hw, unsigned long rate,
198 unsigned long parent_rate);
199int omap2_clksel_set_parent(struct clk_hw *hw, u8 field_val);
Paul Walmsley435699d2010-05-18 18:40:24 -0600200
Paul Walmsley530e5442011-02-25 15:39:28 -0700201/* clkt_iclk.c public functions */
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530202extern void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk);
203extern void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk);
Paul Walmsley530e5442011-02-25 15:39:28 -0700204
Mike Turquette32cc0022012-11-10 16:58:41 -0700205unsigned long omap2_get_dpll_rate(struct clk_hw_omap *clk);
Paul Walmsley435699d2010-05-18 18:40:24 -0600206
Mike Turquette32cc0022012-11-10 16:58:41 -0700207void omap2_clk_dflt_find_companion(struct clk_hw_omap *clk,
208 void __iomem **other_reg,
209 u8 *other_bit);
210void omap2_clk_dflt_find_idlest(struct clk_hw_omap *clk,
211 void __iomem **idlest_reg,
212 u8 *idlest_bit, u8 *idlest_val);
Rajendra Nayak23fb8ba2012-06-01 14:02:49 +0530213int omap2_clk_enable_autoidle_all(void);
Tero Kristo818b40e2013-10-11 19:15:32 +0300214int omap2_clk_allow_idle(struct clk *clk);
215int omap2_clk_deny_idle(struct clk *clk);
Paul Walmsley4d30e822010-02-22 22:09:36 -0700216int omap2_clk_switch_mpurate_at_boot(const char *mpurate_ck_name);
217void omap2_clk_print_new_rates(const char *hfclkin_ck_name,
218 const char *core_ck_name,
219 const char *mpu_ck_name);
Paul Walmsley543d9372008-03-18 10:22:06 +0200220
Tero Kristo3ada6b102013-10-22 11:47:08 +0300221u32 omap2_clk_readl(struct clk_hw_omap *clk, void __iomem *reg);
222void omap2_clk_writel(u32 val, struct clk_hw_omap *clk, void __iomem *reg);
223
Afzal Mohammed99541192011-12-13 10:46:43 -0800224extern u16 cpu_mask;
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700225
Tero Kristo8111e012014-07-02 11:47:39 +0300226/*
227 * Clock features setup. Used instead of CPU type checks.
228 */
229struct ti_clk_features {
230 u32 flags;
Tero Kristoa24886e2014-07-02 11:47:40 +0300231 long fint_min;
232 long fint_max;
233 long fint_band1_max;
234 long fint_band2_min;
Tero Kristo512d91c2014-07-02 11:47:42 +0300235 u8 dpll_bypass_vals;
Tero Kristo066edb22014-07-02 11:47:44 +0300236 u8 cm_idlest_val;
Tero Kristo8111e012014-07-02 11:47:39 +0300237};
Tero Kristo2337c5b2014-07-02 11:47:43 +0300238
239#define TI_CLK_DPLL_HAS_FREQSEL (1 << 0)
240
Tero Kristo8111e012014-07-02 11:47:39 +0300241extern struct ti_clk_features ti_clk_features;
242
Russell Kingb36ee722008-11-04 17:59:52 +0000243extern const struct clkops clkops_omap2_dflt_wait;
Santosh Shilimkar7c43d542010-02-22 22:09:40 -0700244extern const struct clkops clkops_dummy;
Russell Kingbc51da42008-11-04 18:59:32 +0000245extern const struct clkops clkops_omap2_dflt;
Russell Kingb36ee722008-11-04 17:59:52 +0000246
Paul Walmsley82e9bd52009-12-08 16:18:47 -0700247extern struct clk_functions omap2_clk_functions;
248
Paul Walmsleyd8a94452009-12-08 16:21:29 -0700249extern const struct clksel_rate gpt_32k_rates[];
250extern const struct clksel_rate gpt_sys_rates[];
251extern const struct clksel_rate gfx_l3_rates[];
Paul Walmsley22411392011-02-25 15:52:04 -0700252extern const struct clksel_rate dsp_ick_rates[];
Rajendra Nayakcb268672012-11-06 15:41:08 -0700253extern struct clk dummy_ck;
Paul Walmsley543d9372008-03-18 10:22:06 +0200254
Mike Turquette32cc0022012-11-10 16:58:41 -0700255extern const struct clk_hw_omap_ops clkhwops_iclk_wait;
256extern const struct clk_hw_omap_ops clkhwops_wait;
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530257extern const struct clk_hw_omap_ops clkhwops_omap3430es2_ssi_wait;
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530258extern const struct clk_hw_omap_ops clkhwops_omap3430es2_dss_usbhost_wait;
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530259extern const struct clk_hw_omap_ops clkhwops_omap3430es2_hsotgusb_wait;
260extern const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait;
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530261extern const struct clk_hw_omap_ops clkhwops_apll54;
262extern const struct clk_hw_omap_ops clkhwops_apll96;
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700263
Paul Walmsley571efa02012-05-29 15:26:40 +0530264/* clksel_rate blocks shared between OMAP44xx and AM33xx */
265extern const struct clksel_rate div_1_0_rates[];
Rajendra Nayakcb268672012-11-06 15:41:08 -0700266extern const struct clksel_rate div3_1to4_rates[];
Paul Walmsley571efa02012-05-29 15:26:40 +0530267extern const struct clksel_rate div_1_1_rates[];
268extern const struct clksel_rate div_1_2_rates[];
269extern const struct clksel_rate div_1_3_rates[];
270extern const struct clksel_rate div_1_4_rates[];
271extern const struct clksel_rate div31_1to31_rates[];
272
Tero Kristo3ada6b102013-10-22 11:47:08 +0300273extern void __iomem *clk_memmaps[];
274
Vaibhav Hiremathe30384a2012-05-29 15:26:41 +0530275extern int am33xx_clk_init(void);
276
Mike Turquette32cc0022012-11-10 16:58:41 -0700277extern int omap2_clkops_enable_clkdm(struct clk_hw *hw);
278extern void omap2_clkops_disable_clkdm(struct clk_hw *hw);
Mike Turquette32cc0022012-11-10 16:58:41 -0700279
J Keerthy78e52e02013-03-18 09:57:39 -0600280extern void omap_clocks_register(struct omap_clk *oclks, int cnt);
Tero Kristo8111e012014-07-02 11:47:39 +0300281
282void __init ti_clk_init_features(void);
Paul Walmsley543d9372008-03-18 10:22:06 +0200283#endif