Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 1 | /* |
Siddhartha Agrawal | acdaf5b | 2013-01-22 18:14:53 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, Linux Foundation. All rights reserved. |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 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. |
Siddhartha Agrawal | acdaf5b | 2013-01-22 18:14:53 -0800 | [diff] [blame] | 11 | * * Neither the name of Linux Foundation nor |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 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 | |
Deepa Dinamani | abe2e07 | 2013-08-15 16:44:48 -0700 | [diff] [blame] | 32 | #include <bits.h> |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 33 | /* |
| 34 | * Bit manipulation macros |
| 35 | */ |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 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 Desai | ddc771b | 2012-08-28 18:17:04 -0700 | [diff] [blame] | 55 | .n_val = ~((n)-(m)) * !!(n), \ |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 56 | .d_val = ~(n),\ |
| 57 | .div_src_val = BVAL(4, 0, (int)(2*(div) - 1)) \ |
| 58 | | BVAL(10, 8, s##_source_val), \ |
| 59 | } |
| 60 | |
Siddhartha Agrawal | acdaf5b | 2013-01-22 18:14:53 -0800 | [diff] [blame] | 61 | /* 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 Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 72 | |
Asaf Penso | ba57262 | 2013-04-28 18:07:12 +0300 | [diff] [blame] | 73 | #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 Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 83 | /* Branch Clock Bits */ |
| 84 | #define CBCR_BRANCH_ENABLE_BIT BIT(0) |
| 85 | #define CBCR_BRANCH_OFF_BIT BIT(31) |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 86 | #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 Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 89 | |
| 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 | */ |
| 109 | struct 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 */ |
| 123 | struct fixed_clk { |
| 124 | struct clk c; |
| 125 | }; |
| 126 | |
| 127 | /* Branch clock */ |
| 128 | struct 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 */ |
| 145 | struct 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 Kadabi | 9dd522f | 2013-10-10 12:30:10 -0700 | [diff] [blame^] | 159 | struct clk_freq_tbl *freq_tbl; |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 160 | struct clk_freq_tbl *current_freq; |
| 161 | |
| 162 | struct clk c; |
| 163 | }; |
| 164 | |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 165 | /* Vote Clock */ |
| 166 | struct 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 Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 175 | static inline struct rcg_clk *to_rcg_clk(struct clk *clk) |
| 176 | { |
| 177 | return container_of(clk, struct rcg_clk, c); |
| 178 | } |
| 179 | |
| 180 | static inline struct branch_clk *to_branch_clk(struct clk *clk) |
| 181 | { |
| 182 | return container_of(clk, struct branch_clk, c); |
| 183 | } |
| 184 | |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 185 | static inline struct vote_clk *to_local_vote_clk(struct clk *clk) |
| 186 | { |
| 187 | return container_of(clk, struct vote_clk, c); |
| 188 | } |
| 189 | |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 190 | /* RCG clock functions */ |
| 191 | int clock_lib2_rcg_enable(struct clk *c); |
| 192 | int clock_lib2_rcg_set_rate(struct clk *c, unsigned rate); |
| 193 | void clock_lib2_rcg_set_rate_mnd(struct rcg_clk *rclk, struct clk_freq_tbl *freq); |
| 194 | void clock_lib2_rcg_set_rate_hid(struct rcg_clk *rclk, struct clk_freq_tbl *freq); |
| 195 | |
| 196 | /* CXO clock functions */ |
| 197 | int cxo_clk_enable(struct clk *clk); |
| 198 | void cxo_clk_disable(struct clk *clk); |
| 199 | |
| 200 | /* Branch clock functions */ |
| 201 | int clock_lib2_branch_clk_enable(struct clk *clk); |
| 202 | void clock_lib2_branch_clk_disable(struct clk *clk); |
| 203 | int clock_lib2_branch_set_rate(struct clk *c, unsigned rate); |
| 204 | |
Neeti Desai | ac01127 | 2012-08-29 18:24:54 -0700 | [diff] [blame] | 205 | /* Vote clock functions*/ |
| 206 | int clock_lib2_vote_clk_enable(struct clk *c); |
| 207 | void clock_lib2_vote_clk_disable(struct clk *c); |
Amol Jadi | 29f9503 | 2012-06-22 12:52:54 -0700 | [diff] [blame] | 208 | #endif |