blob: 2f6deb734138e6752a5aefe785a77ab4f81479d3 [file] [log] [blame]
Amol Jadi29f95032012-06-22 12:52:54 -07001/*
2 * Copyright (c) 2012, Code Aurora Forum. All rights reserved.
3 *
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.
11 * * Neither the name of Code Aurora nor
12 * 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
32/*
33 * Bit manipulation macros
34 */
35#define BIT(n) (1 << (n))
36#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
61
62/* Branch Clock Bits */
63#define CBCR_BRANCH_ENABLE_BIT BIT(0)
64#define CBCR_BRANCH_OFF_BIT BIT(31)
Neeti Desaiac011272012-08-29 18:24:54 -070065#define BRANCH_CHECK_MASK BM(31, 28)
66#define BRANCH_ON_VAL BVAL(31, 28, 0x0)
67#define BRANCH_NOC_FSM_ON_VAL BVAL(31, 28, 0x2)
Amol Jadi29f95032012-06-22 12:52:54 -070068
69/* Root Clock Bits */
70#define CMD_UPDATE_BIT BIT(0)
71#define CMD_UPDATE_MASK 1
72
73#define CFG_SRC_DIV_OFFSET 0
74#define CFG_SRC_DIV_MASK (0x1F << CFG_SRC_DIV_OFFSET)
75
76#define CFG_SRC_SEL_OFFSET 8
77#define CFG_SRC_SEL_MASK (0x3 << CFG_SRC_SEL_OFFSET)
78
79#define CFG_MODE_DUAL_EDGE 0x2
80
81#define CFG_MODE_OFFSET 12
82#define CFG_MODE_MASK (0x3 << CFG_MODE_OFFSET)
83
84
85/*
86 * Generic frequency-definition structs and macros
87 */
88struct clk_freq_tbl {
89
90 const uint32_t freq_hz;
91 struct clk *src_clk;
92 const uint32_t div_src_val;
93
94 /* TODO: find out if sys_vdd is needed. */
95
96 const uint32_t m_val;
97 const uint32_t n_val; /* not_n_minus_m_val */
98 const uint32_t d_val; /* not_2d_val */
99};
100
101/* Fixed clock */
102struct fixed_clk {
103 struct clk c;
104};
105
106/* Branch clock */
107struct branch_clk {
108
109 uint32_t *const bcr_reg;
110 uint32_t *const cbcr_reg;
111
112 void (*set_rate)(struct branch_clk *, struct clk_freq_tbl *);
113
114 struct clk *parent;
115 struct clk c;
116
117 int has_sibling;
118 uint32_t cur_div;
119 uint32_t max_div;
120 uint32_t halt_check;
121};
122
123/* Root Clock */
124struct rcg_clk {
125
126 /* RCG registers for this clock */
127
128 uint32_t *const cmd_reg; /* Command reg */
129 uint32_t *const cfg_reg; /* Config reg */
130 uint32_t *const m_reg; /* m */
131 uint32_t *const n_reg; /* not (n-m) */
132 uint32_t *const d_reg; /* not (2d) */
133
134 /* set rate function for this clock */
135 void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *);
136
137 /* freq table */
138 struct clk_freq_tbl *const freq_tbl;
139 struct clk_freq_tbl *current_freq;
140
141 struct clk c;
142};
143
Neeti Desaiac011272012-08-29 18:24:54 -0700144/* Vote Clock */
145struct vote_clk {
146
147 uint32_t *const cbcr_reg;
148 uint32_t *const vote_reg;
149 uint32_t en_mask;
150
151 struct clk c;
152};
153
Amol Jadi29f95032012-06-22 12:52:54 -0700154static inline struct rcg_clk *to_rcg_clk(struct clk *clk)
155{
156 return container_of(clk, struct rcg_clk, c);
157}
158
159static inline struct branch_clk *to_branch_clk(struct clk *clk)
160{
161 return container_of(clk, struct branch_clk, c);
162}
163
Neeti Desaiac011272012-08-29 18:24:54 -0700164static inline struct vote_clk *to_local_vote_clk(struct clk *clk)
165{
166 return container_of(clk, struct vote_clk, c);
167}
168
Amol Jadi29f95032012-06-22 12:52:54 -0700169/* RCG clock functions */
170int clock_lib2_rcg_enable(struct clk *c);
171int clock_lib2_rcg_set_rate(struct clk *c, unsigned rate);
172void clock_lib2_rcg_set_rate_mnd(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
173void clock_lib2_rcg_set_rate_hid(struct rcg_clk *rclk, struct clk_freq_tbl *freq);
174
175/* CXO clock functions */
176int cxo_clk_enable(struct clk *clk);
177void cxo_clk_disable(struct clk *clk);
178
179/* Branch clock functions */
180int clock_lib2_branch_clk_enable(struct clk *clk);
181void clock_lib2_branch_clk_disable(struct clk *clk);
182int clock_lib2_branch_set_rate(struct clk *c, unsigned rate);
183
Neeti Desaiac011272012-08-29 18:24:54 -0700184/* Vote clock functions*/
185int clock_lib2_vote_clk_enable(struct clk *c);
186void clock_lib2_vote_clk_disable(struct clk *c);
Amol Jadi29f95032012-06-22 12:52:54 -0700187#endif