blob: 602304437dee96fdaee3502ce12d5a53b17cc3be [file] [log] [blame]
Amol Jadi29f95032012-06-22 12:52:54 -07001/*
Channagoud Kadabidd7cb382015-03-23 23:30:25 -07002 * Copyright (c) 2012-2015, Linux Foundation. All rights reserved.
Amol Jadi29f95032012-06-22 12:52:54 -07003 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above copyright
9 * notice, this list of conditions and the following disclaimer in the
10 * documentation and/or other materials provided with the distribution.
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -080011 * * Neither the name of Linux Foundation nor
Amol Jadi29f95032012-06-22 12:52:54 -070012 * the names of its contributors may be used to endorse or promote
13 * products derived from this software without specific prior written
14 * permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
23 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
26 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#ifndef __CLOCK_LIB2_H
30#define __CLOCK_LIB2_H
31
Deepa Dinamaniabe2e072013-08-15 16:44:48 -070032#include <bits.h>
Amol Jadi29f95032012-06-22 12:52:54 -070033/*
34 * Bit manipulation macros
35 */
Amol Jadi29f95032012-06-22 12:52:54 -070036#define BM(msb, lsb) (((((uint32_t)-1) << (31-msb)) >> (31-msb+lsb)) << lsb)
37#define BVAL(msb, lsb, val) (((val) << lsb) & BM(msb, lsb))
38
39#define container_of(ptr, type, member) \
40 ((type *)((addr_t)(ptr) - offsetof(type, member)))
41
42/* Frequency Macros */
43#define FREQ_END (UINT_MAX-1)
44#define F_END \
45 { \
46 .freq_hz = FREQ_END, \
47 }
48
49/* F(frequency, source, div, m, n) */
50#define F(f, s, div, m, n) \
51 { \
52 .freq_hz = (f), \
53 .src_clk = &s##_clk_src.c, \
54 .m_val = (m), \
Neeti Desaiddc771b2012-08-28 18:17:04 -070055 .n_val = ~((n)-(m)) * !!(n), \
Amol Jadi29f95032012-06-22 12:52:54 -070056 .d_val = ~(n),\
57 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
58 | BVAL(10, 8, s##_source_val), \
59 }
60
Channagoud Kadabi1dd9baf2014-02-04 16:06:11 -080061/* F(frequency, source, div, m, n) */
62#define F_EXT_SRC(f, s, div, m, n) \
63 { \
64 .freq_hz = (f), \
65 .m_val = (m), \
66 .n_val = ~((n)-(m)) * !!(n), \
67 .d_val = ~(n),\
68 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
69 | BVAL(10, 8, s##_source_val), \
70 }
71
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -080072/* F_MM(frequency, source, div, m, n) */
73#define F_MM(f, s, div, m, n) \
74 { \
75 .freq_hz = (f), \
76 .src_clk = &s##_clk_src.c, \
77 .m_val = (m), \
78 .n_val = ~((n)-(m)) * !!(n), \
79 .d_val = ~(n),\
80 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
81 | BVAL(10, 8, s##_mm_source_val), \
82 }
Amol Jadi29f95032012-06-22 12:52:54 -070083
Asaf Pensoba572622013-04-28 18:07:12 +030084#define F_MDSS(f, s, div, m, n) \
85 { \
86 .freq_hz = (f), \
87 .m_val = (m), \
88 .n_val = ~((n)-(m)) * !!(n), \
89 .d_val = ~(n),\
90 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
91 | BVAL(10, 8, s##_mm_source_val), \
92 }
93
Amol Jadi29f95032012-06-22 12:52:54 -070094/* Branch Clock Bits */
95#define CBCR_BRANCH_ENABLE_BIT BIT(0)
96#define CBCR_BRANCH_OFF_BIT BIT(31)
Neeti Desaiac011272012-08-29 18:24:54 -070097#define BRANCH_CHECK_MASK BM(31, 28)
98#define BRANCH_ON_VAL BVAL(31, 28, 0x0)
99#define BRANCH_NOC_FSM_ON_VAL BVAL(31, 28, 0x2)
Amol Jadi29f95032012-06-22 12:52:54 -0700100
101/* Root Clock Bits */
102#define CMD_UPDATE_BIT BIT(0)
103#define CMD_UPDATE_MASK 1
104
105#define CFG_SRC_DIV_OFFSET 0
106#define CFG_SRC_DIV_MASK (0x1F << CFG_SRC_DIV_OFFSET)
107
108#define CFG_SRC_SEL_OFFSET 8
Channagoud Kadabib4275f12015-08-15 13:06:47 -0700109#define CFG_SRC_SEL_MASK (0x7 << CFG_SRC_SEL_OFFSET)
Amol Jadi29f95032012-06-22 12:52:54 -0700110
111#define CFG_MODE_DUAL_EDGE 0x2
112
113#define CFG_MODE_OFFSET 12
114#define CFG_MODE_MASK (0x3 << CFG_MODE_OFFSET)
115
116
117/*
118 * Generic frequency-definition structs and macros
119 */
120struct clk_freq_tbl {
121
122 const uint32_t freq_hz;
123 struct clk *src_clk;
124 const uint32_t div_src_val;
125
126 /* TODO: find out if sys_vdd is needed. */
127
128 const uint32_t m_val;
129 const uint32_t n_val; /* not_n_minus_m_val */
130 const uint32_t d_val; /* not_2d_val */
131};
132
133/* Fixed clock */
134struct fixed_clk {
135 struct clk c;
136};
137
138/* Branch clock */
139struct branch_clk {
140
141 uint32_t *const bcr_reg;
142 uint32_t *const cbcr_reg;
143
144 void (*set_rate)(struct branch_clk *, struct clk_freq_tbl *);
145
146 struct clk *parent;
147 struct clk c;
148
149 int has_sibling;
150 uint32_t cur_div;
151 uint32_t max_div;
152 uint32_t halt_check;
Channagoud Kadabidd7cb382015-03-23 23:30:25 -0700153 bool no_halt_check_on_disable;
Amol Jadi29f95032012-06-22 12:52:54 -0700154};
155
156/* Root Clock */
157struct rcg_clk {
158
159 /* RCG registers for this clock */
160
161 uint32_t *const cmd_reg; /* Command reg */
162 uint32_t *const cfg_reg; /* Config reg */
163 uint32_t *const m_reg; /* m */
164 uint32_t *const n_reg; /* not (n-m) */
165 uint32_t *const d_reg; /* not (2d) */
166
167 /* set rate function for this clock */
168 void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *);
169
170 /* freq table */
Channagoud Kadabi9dd522f2013-10-10 12:30:10 -0700171 struct clk_freq_tbl *freq_tbl;
Amol Jadi29f95032012-06-22 12:52:54 -0700172 struct clk_freq_tbl *current_freq;
173
174 struct clk c;
175};
176
Neeti Desaiac011272012-08-29 18:24:54 -0700177/* Vote Clock */
178struct vote_clk {
179
180 uint32_t *const cbcr_reg;
181 uint32_t *const vote_reg;
182 uint32_t en_mask;
183
184 struct clk c;
185};
186
Channagoud Kadabif32341c2014-04-03 15:34:04 -0700187struct reset_clk {
188 uint32_t bcr_reg;
189 struct clk c;
190};
191
192static inline struct reset_clk *to_reset_clk(struct clk *clk)
193{
194 return container_of(clk, struct reset_clk, c);
195}
196
Amol Jadi29f95032012-06-22 12:52:54 -0700197static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
198{
199 return container_of(clk, struct rcg_clk, c);
200}
201
202static inline struct branch_clk *to_branch_clk(struct clk *clk)
203{
204 return container_of(clk, struct branch_clk, c);
205}
206
Neeti Desaiac011272012-08-29 18:24:54 -0700207static inline struct vote_clk *to_local_vote_clk(struct clk *clk)
208{
209 return container_of(clk, struct vote_clk, c);
210}
211
Amol Jadi29f95032012-06-22 12:52:54 -0700212/* RCG clock functions */
213int clock_lib2_rcg_enable(struct clk *c);
214int clock_lib2_rcg_set_rate(struct clk *c, unsigned rate);
215void clock_lib2_rcg_set_rate_mnd(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
216void clock_lib2_rcg_set_rate_hid(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
217
218/* CXO clock functions */
219int cxo_clk_enable(struct clk *clk);
220void cxo_clk_disable(struct clk *clk);
221
222/* Branch clock functions */
223int clock_lib2_branch_clk_enable(struct clk *clk);
224void clock_lib2_branch_clk_disable(struct clk *clk);
225int clock_lib2_branch_set_rate(struct clk *c, unsigned rate);
226
Neeti Desaiac011272012-08-29 18:24:54 -0700227/* Vote clock functions*/
228int clock_lib2_vote_clk_enable(struct clk *c);
229void clock_lib2_vote_clk_disable(struct clk *c);
Channagoud Kadabif32341c2014-04-03 15:34:04 -0700230/* clock reset function */
231int clock_lib2_reset_clk_reset(struct clk *c, enum clk_reset_action action);
232int clock_lib2_branch_clk_reset(struct clk *c, enum clk_reset_action action);
Amol Jadi29f95032012-06-22 12:52:54 -0700233#endif