Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2009-2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #ifndef __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H |
| 15 | #define __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H |
| 16 | |
| 17 | #include <linux/spinlock.h> |
| 18 | #include "clock.h" |
| 19 | |
| 20 | /* |
| 21 | * Bit manipulation macros |
| 22 | */ |
| 23 | #define BM(msb, lsb) (((((uint32_t)-1) << (31-msb)) >> (31-msb+lsb)) << lsb) |
| 24 | #define BVAL(msb, lsb, val) (((val) << lsb) & BM(msb, lsb)) |
| 25 | |
| 26 | /* |
| 27 | * Halt/Status Checking Mode Macros |
| 28 | */ |
| 29 | #define HALT 0 /* Bit pol: 1 = halted */ |
| 30 | #define NOCHECK 1 /* No bit to check, do nothing */ |
| 31 | #define HALT_VOTED 2 /* Bit pol: 1 = halted; delay on disable */ |
| 32 | #define ENABLE 3 /* Bit pol: 1 = running */ |
| 33 | #define ENABLE_VOTED 4 /* Bit pol: 1 = running; delay on disable */ |
| 34 | #define DELAY 5 /* No bit to check, just delay */ |
| 35 | |
| 36 | /* |
| 37 | * Clock Definition Macros |
| 38 | */ |
| 39 | #define DEFINE_CLK_MEASURE(name) \ |
| 40 | struct clk name = { \ |
| 41 | .ops = &clk_ops_measure, \ |
| 42 | .dbg_name = #name, \ |
| 43 | CLK_INIT(name), \ |
| 44 | }; \ |
| 45 | |
| 46 | /* |
| 47 | * Generic frequency-definition structs and macros |
| 48 | */ |
| 49 | struct clk_freq_tbl { |
| 50 | const uint32_t freq_hz; |
| 51 | struct clk *src_clk; |
| 52 | const uint32_t md_val; |
| 53 | const uint32_t ns_val; |
| 54 | const uint32_t ctl_val; |
| 55 | uint32_t mnd_en_mask; |
| 56 | const unsigned sys_vdd; |
| 57 | void *const extra_freq_data; |
| 58 | }; |
| 59 | |
| 60 | /* Some clocks have two banks to avoid glitches when switching frequencies. |
| 61 | * The unused bank is programmed while running on the other bank, and |
| 62 | * switched to afterwards. The following two structs describe the banks. */ |
| 63 | struct bank_mask_info { |
| 64 | void *const md_reg; |
| 65 | const uint32_t ns_mask; |
| 66 | const uint32_t rst_mask; |
| 67 | const uint32_t mnd_en_mask; |
| 68 | const uint32_t mode_mask; |
| 69 | }; |
| 70 | |
| 71 | struct bank_masks { |
| 72 | const uint32_t bank_sel_mask; |
| 73 | const struct bank_mask_info bank0_mask; |
| 74 | const struct bank_mask_info bank1_mask; |
| 75 | }; |
| 76 | |
| 77 | #define F_RAW(f, sc, m_v, n_v, c_v, m_m, v, e) { \ |
| 78 | .freq_hz = f, \ |
| 79 | .src_clk = sc, \ |
| 80 | .md_val = m_v, \ |
| 81 | .ns_val = n_v, \ |
| 82 | .ctl_val = c_v, \ |
| 83 | .mnd_en_mask = m_m, \ |
| 84 | .sys_vdd = v, \ |
| 85 | .extra_freq_data = e, \ |
| 86 | } |
| 87 | #define FREQ_END (UINT_MAX-1) |
| 88 | #define F_END \ |
| 89 | { \ |
| 90 | .freq_hz = FREQ_END, \ |
| 91 | .sys_vdd = LOW, \ |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * struct branch - branch on/off |
| 96 | * @ctl_reg: clock control register |
| 97 | * @en_mask: ORed with @ctl_reg to enable the clock |
| 98 | * @halt_reg: halt register |
| 99 | * @halt_check: type of halt check to perform |
| 100 | * @halt_bit: ANDed with @halt_reg to test for clock halted |
| 101 | * @reset_reg: reset register |
| 102 | * @reset_mask: ORed with @reset_reg to reset the clock domain |
| 103 | */ |
| 104 | struct branch { |
| 105 | void __iomem *const ctl_reg; |
| 106 | const u32 en_mask; |
| 107 | |
| 108 | void __iomem *const halt_reg; |
| 109 | const u16 halt_check; |
| 110 | const u16 halt_bit; |
| 111 | |
| 112 | void __iomem *const reset_reg; |
| 113 | const u32 reset_mask; |
| 114 | }; |
| 115 | |
| 116 | int branch_reset(struct branch *clk, enum clk_reset_action action); |
| 117 | |
| 118 | /* |
| 119 | * Generic clock-definition struct and macros |
| 120 | */ |
| 121 | struct rcg_clk { |
| 122 | bool enabled; |
| 123 | void *const ns_reg; |
| 124 | void *const md_reg; |
| 125 | |
| 126 | const uint32_t root_en_mask; |
| 127 | uint32_t ns_mask; |
| 128 | const uint32_t ctl_mask; |
| 129 | struct bank_masks *const bank_masks; |
| 130 | |
| 131 | void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *); |
| 132 | struct clk_freq_tbl *const freq_tbl; |
| 133 | struct clk_freq_tbl *current_freq; |
| 134 | |
| 135 | struct clk *depends; |
| 136 | struct branch b; |
| 137 | struct clk c; |
| 138 | }; |
| 139 | |
| 140 | static inline struct rcg_clk *to_rcg_clk(struct clk *clk) |
| 141 | { |
| 142 | return container_of(clk, struct rcg_clk, c); |
| 143 | } |
| 144 | |
Matt Wagantall | 0625ea0 | 2011-07-13 18:51:56 -0700 | [diff] [blame] | 145 | int rcg_clk_enable(struct clk *clk); |
| 146 | void rcg_clk_disable(struct clk *clk); |
| 147 | void rcg_clk_auto_off(struct clk *clk); |
| 148 | int rcg_clk_set_rate(struct clk *clk, unsigned rate); |
| 149 | int rcg_clk_set_min_rate(struct clk *clk, unsigned rate); |
| 150 | int rcg_clk_set_max_rate(struct clk *clk, unsigned rate); |
| 151 | unsigned rcg_clk_get_rate(struct clk *clk); |
| 152 | int rcg_clk_list_rate(struct clk *clk, unsigned n); |
| 153 | int rcg_clk_is_enabled(struct clk *clk); |
| 154 | long rcg_clk_round_rate(struct clk *clk, unsigned rate); |
| 155 | struct clk *rcg_clk_get_parent(struct clk *c); |
| 156 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 157 | /* |
| 158 | * SYS_VDD voltage levels |
| 159 | */ |
| 160 | enum sys_vdd_level { |
| 161 | NONE, |
| 162 | LOW, |
| 163 | NOMINAL, |
| 164 | HIGH, |
| 165 | NUM_SYS_VDD_LEVELS |
| 166 | }; |
| 167 | |
| 168 | /** |
| 169 | * struct fixed_clk - fixed rate clock (used for crystal oscillators) |
| 170 | * @rate: output rate |
| 171 | * @c: clk |
| 172 | */ |
| 173 | struct fixed_clk { |
| 174 | unsigned long rate; |
| 175 | struct clk c; |
| 176 | }; |
| 177 | |
| 178 | static inline struct fixed_clk *to_fixed_clk(struct clk *clk) |
| 179 | { |
| 180 | return container_of(clk, struct fixed_clk, c); |
| 181 | } |
| 182 | |
| 183 | static inline unsigned fixed_clk_get_rate(struct clk *clk) |
| 184 | { |
| 185 | struct fixed_clk *f = to_fixed_clk(clk); |
| 186 | return f->rate; |
| 187 | } |
| 188 | |
| 189 | |
| 190 | /** |
| 191 | * struct pll_vote_clk - phase locked loop (HW voteable) |
| 192 | * @rate: output rate |
| 193 | * @en_reg: enable register |
| 194 | * @en_mask: ORed with @en_reg to enable the clock |
| 195 | * @status_reg: status register |
| 196 | * @parent: clock source |
| 197 | * @c: clk |
| 198 | */ |
| 199 | struct pll_vote_clk { |
| 200 | unsigned long rate; |
| 201 | |
| 202 | void __iomem *const en_reg; |
| 203 | const u32 en_mask; |
| 204 | |
| 205 | void __iomem *const status_reg; |
| 206 | |
| 207 | struct clk *parent; |
| 208 | struct clk c; |
| 209 | }; |
| 210 | |
| 211 | extern struct clk_ops clk_ops_pll_vote; |
| 212 | |
| 213 | static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *clk) |
| 214 | { |
| 215 | return container_of(clk, struct pll_vote_clk, c); |
| 216 | } |
| 217 | |
| 218 | /** |
| 219 | * struct pll_clk - phase locked loop |
| 220 | * @rate: output rate |
| 221 | * @mode_reg: enable register |
| 222 | * @parent: clock source |
| 223 | * @c: clk |
| 224 | */ |
| 225 | struct pll_clk { |
| 226 | unsigned long rate; |
| 227 | |
| 228 | void __iomem *const mode_reg; |
| 229 | |
| 230 | struct clk *parent; |
| 231 | struct clk c; |
| 232 | }; |
| 233 | |
| 234 | extern struct clk_ops clk_ops_pll; |
| 235 | |
| 236 | static inline struct pll_clk *to_pll_clk(struct clk *clk) |
| 237 | { |
| 238 | return container_of(clk, struct pll_clk, c); |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * struct branch_clk - branch |
| 243 | * @enabled: true if clock is on, false otherwise |
| 244 | * @b: branch |
| 245 | * @parent: clock source |
| 246 | * @c: clk |
| 247 | * |
| 248 | * An on/off switch with a rate derived from the parent. |
| 249 | */ |
| 250 | struct branch_clk { |
| 251 | bool enabled; |
| 252 | struct branch b; |
| 253 | struct clk *parent; |
Matt Wagantall | 2faaef0 | 2011-07-14 11:59:57 -0700 | [diff] [blame] | 254 | struct clk *depends; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 255 | struct clk c; |
| 256 | }; |
| 257 | |
| 258 | static inline struct branch_clk *to_branch_clk(struct clk *clk) |
| 259 | { |
| 260 | return container_of(clk, struct branch_clk, c); |
| 261 | } |
| 262 | |
| 263 | int branch_clk_enable(struct clk *clk); |
| 264 | void branch_clk_disable(struct clk *clk); |
| 265 | struct clk *branch_clk_get_parent(struct clk *clk); |
| 266 | int branch_clk_set_parent(struct clk *clk, struct clk *parent); |
| 267 | int branch_clk_is_enabled(struct clk *clk); |
| 268 | void branch_clk_auto_off(struct clk *clk); |
| 269 | int branch_clk_reset(struct clk *c, enum clk_reset_action action); |
| 270 | |
| 271 | /** |
| 272 | * struct measure_clk - for rate measurement debug use |
| 273 | * @sample_ticks: sample period in reference clock ticks |
| 274 | * @multiplier: measurement scale-up factor |
| 275 | * @divider: measurement scale-down factor |
| 276 | * @c: clk |
| 277 | */ |
| 278 | struct measure_clk { |
| 279 | u64 sample_ticks; |
| 280 | u32 multiplier; |
| 281 | u32 divider; |
| 282 | struct clk c; |
| 283 | }; |
| 284 | |
| 285 | extern struct clk_ops clk_ops_measure; |
| 286 | |
| 287 | static inline struct measure_clk *to_measure_clk(struct clk *clk) |
| 288 | { |
| 289 | return container_of(clk, struct measure_clk, c); |
| 290 | } |
| 291 | |
| 292 | /* |
| 293 | * Variables from clock-local driver |
| 294 | */ |
| 295 | extern spinlock_t local_clock_reg_lock; |
| 296 | extern struct clk_freq_tbl local_dummy_freq; |
| 297 | extern struct fixed_clk gnd_clk; |
| 298 | |
| 299 | /* |
| 300 | * Local-clock APIs |
| 301 | */ |
| 302 | int local_vote_sys_vdd(enum sys_vdd_level level); |
| 303 | int local_unvote_sys_vdd(enum sys_vdd_level level); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 304 | bool local_clk_is_local(struct clk *clk); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 305 | |
| 306 | /* |
| 307 | * Required SoC-specific functions, implemented for every supported SoC |
| 308 | */ |
| 309 | extern int (*soc_update_sys_vdd)(enum sys_vdd_level level); |
| 310 | |
| 311 | /* |
| 312 | * Generic set-rate implementations |
| 313 | */ |
| 314 | void set_rate_mnd(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 315 | void set_rate_nop(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 316 | void set_rate_mnd_8(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 317 | void set_rate_mnd_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 318 | void set_rate_div_banked(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 319 | |
| 320 | #endif /* __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_H */ |
| 321 | |