blob: e808c8746eb3d4901e07a8672543d3e33de68eee [file] [log] [blame]
Amol Jadi29f95032012-06-22 12:52:54 -07001/*
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -08002 * Copyright (c) 2012-2013, 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
Siddhartha Agrawalacdaf5b2013-01-22 18:14:53 -080061/* F_MM(frequency, source, div, m, n) */
62#define F_MM(f, s, div, m, n) \
63 { \
64 .freq_hz = (f), \
65 .src_clk = &s##_clk_src.c, \
66 .m_val = (m), \
67 .n_val = ~((n)-(m)) * !!(n), \
68 .d_val = ~(n),\
69 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
70 | BVAL(10, 8, s##_mm_source_val), \
71 }
Amol Jadi29f95032012-06-22 12:52:54 -070072
Asaf Pensoba572622013-04-28 18:07:12 +030073#define F_MDSS(f, s, div, m, n) \
74 { \
75 .freq_hz = (f), \
76 .m_val = (m), \
77 .n_val = ~((n)-(m)) * !!(n), \
78 .d_val = ~(n),\
79 .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \
80 | BVAL(10, 8, s##_mm_source_val), \
81 }
82
Amol Jadi29f95032012-06-22 12:52:54 -070083/* Branch Clock Bits */
84#define CBCR_BRANCH_ENABLE_BIT BIT(0)
85#define CBCR_BRANCH_OFF_BIT BIT(31)
Neeti Desaiac011272012-08-29 18:24:54 -070086#define BRANCH_CHECK_MASK BM(31, 28)
87#define BRANCH_ON_VAL BVAL(31, 28, 0x0)
88#define BRANCH_NOC_FSM_ON_VAL BVAL(31, 28, 0x2)
Amol Jadi29f95032012-06-22 12:52:54 -070089
90/* Root Clock Bits */
91#define CMD_UPDATE_BIT BIT(0)
92#define CMD_UPDATE_MASK 1
93
94#define CFG_SRC_DIV_OFFSET 0
95#define CFG_SRC_DIV_MASK (0x1F << CFG_SRC_DIV_OFFSET)
96
97#define CFG_SRC_SEL_OFFSET 8
98#define CFG_SRC_SEL_MASK (0x3 << CFG_SRC_SEL_OFFSET)
99
100#define CFG_MODE_DUAL_EDGE 0x2
101
102#define CFG_MODE_OFFSET 12
103#define CFG_MODE_MASK (0x3 << CFG_MODE_OFFSET)
104
105
106/*
107 * Generic frequency-definition structs and macros
108 */
109struct clk_freq_tbl {
110
111 const uint32_t freq_hz;
112 struct clk *src_clk;
113 const uint32_t div_src_val;
114
115 /* TODO: find out if sys_vdd is needed. */
116
117 const uint32_t m_val;
118 const uint32_t n_val; /* not_n_minus_m_val */
119 const uint32_t d_val; /* not_2d_val */
120};
121
122/* Fixed clock */
123struct fixed_clk {
124 struct clk c;
125};
126
127/* Branch clock */
128struct branch_clk {
129
130 uint32_t *const bcr_reg;
131 uint32_t *const cbcr_reg;
132
133 void (*set_rate)(struct branch_clk *, struct clk_freq_tbl *);
134
135 struct clk *parent;
136 struct clk c;
137
138 int has_sibling;
139 uint32_t cur_div;
140 uint32_t max_div;
141 uint32_t halt_check;
142};
143
144/* Root Clock */
145struct rcg_clk {
146
147 /* RCG registers for this clock */
148
149 uint32_t *const cmd_reg; /* Command reg */
150 uint32_t *const cfg_reg; /* Config reg */
151 uint32_t *const m_reg; /* m */
152 uint32_t *const n_reg; /* not (n-m) */
153 uint32_t *const d_reg; /* not (2d) */
154
155 /* set rate function for this clock */
156 void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *);
157
158 /* freq table */
Channagoud Kadabi9dd522f2013-10-10 12:30:10 -0700159 struct clk_freq_tbl *freq_tbl;
Amol Jadi29f95032012-06-22 12:52:54 -0700160 struct clk_freq_tbl *current_freq;
161
162 struct clk c;
163};
164
Neeti Desaiac011272012-08-29 18:24:54 -0700165/* Vote Clock */
166struct vote_clk {
167
168 uint32_t *const cbcr_reg;
169 uint32_t *const vote_reg;
170 uint32_t en_mask;
171
172 struct clk c;
173};
174
Amol Jadi29f95032012-06-22 12:52:54 -0700175static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
176{
177 return container_of(clk, struct rcg_clk, c);
178}
179
180static inline struct branch_clk *to_branch_clk(struct clk *clk)
181{
182 return container_of(clk, struct branch_clk, c);
183}
184
Neeti Desaiac011272012-08-29 18:24:54 -0700185static inline struct vote_clk *to_local_vote_clk(struct clk *clk)
186{
187 return container_of(clk, struct vote_clk, c);
188}
189
Amol Jadi29f95032012-06-22 12:52:54 -0700190/* RCG clock functions */
191int clock_lib2_rcg_enable(struct clk *c);
192int clock_lib2_rcg_set_rate(struct clk *c, unsigned rate);
193void clock_lib2_rcg_set_rate_mnd(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
194void clock_lib2_rcg_set_rate_hid(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
195
196/* CXO clock functions */
197int cxo_clk_enable(struct clk *clk);
198void cxo_clk_disable(struct clk *clk);
199
200/* Branch clock functions */
201int clock_lib2_branch_clk_enable(struct clk *clk);
202void clock_lib2_branch_clk_disable(struct clk *clk);
203int clock_lib2_branch_set_rate(struct clk *c, unsigned rate);
204
Neeti Desaiac011272012-08-29 18:24:54 -0700205/* Vote clock functions*/
206int clock_lib2_vote_clk_enable(struct clk *c);
207void clock_lib2_vote_clk_disable(struct clk *c);
Amol Jadi29f95032012-06-22 12:52:54 -0700208#endif