Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2012, 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_2_H |
| 15 | #define __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_2_H |
| 16 | |
| 17 | #include <linux/spinlock.h> |
| 18 | #include "clock.h" |
| 19 | |
| 20 | /* |
| 21 | * Generic frequency-definition structs and macros |
| 22 | */ |
| 23 | |
| 24 | /** |
| 25 | * @freq_hz: output rate |
| 26 | * @src_clk: source clock for freq_hz |
| 27 | * @m_val: M value corresponding to freq_hz |
| 28 | * @n_val: N value corresponding to freq_hz |
| 29 | * @d_val: D value corresponding to freq_hz |
| 30 | * @div_src_val: Pre divider value and source selection mux index for freq_hz |
| 31 | * @sys_vdd: Voltage level required for freq_hz |
| 32 | */ |
| 33 | struct clk_freq_tbl { |
| 34 | unsigned long freq_hz; |
| 35 | struct clk *src_clk; |
| 36 | const u32 m_val; |
| 37 | const u32 n_val; |
| 38 | const u32 d_val; |
Vikram Mulukutla | fe0f5a5 | 2012-08-16 16:51:08 -0700 | [diff] [blame] | 39 | u32 div_src_val; |
Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 40 | const unsigned sys_vdd; |
| 41 | }; |
| 42 | |
| 43 | #define FREQ_END (UINT_MAX-1) |
| 44 | #define F_END { .freq_hz = FREQ_END } |
| 45 | |
| 46 | /* |
| 47 | * Generic clock-definition struct and macros |
| 48 | */ |
| 49 | /** |
| 50 | * struct rcg_clk - root clock generator |
| 51 | * @cmd_rcgr_reg: command register |
| 52 | * @set_rate: function to set frequency |
| 53 | * @freq_tbl: frequency table for this RCG |
| 54 | * @current_freq: current RCG frequency |
| 55 | * @c: generic clock data |
| 56 | * @base: pointer to base address of ioremapped registers. |
| 57 | */ |
| 58 | struct rcg_clk { |
| 59 | const u32 cmd_rcgr_reg; |
| 60 | |
| 61 | void (*set_rate)(struct rcg_clk *, struct clk_freq_tbl *); |
| 62 | |
| 63 | struct clk_freq_tbl *freq_tbl; |
| 64 | struct clk_freq_tbl *current_freq; |
| 65 | struct clk c; |
| 66 | |
| 67 | void *const __iomem *base; |
| 68 | }; |
| 69 | |
| 70 | static inline struct rcg_clk *to_rcg_clk(struct clk *clk) |
| 71 | { |
| 72 | return container_of(clk, struct rcg_clk, c); |
| 73 | } |
| 74 | |
| 75 | extern struct clk_freq_tbl rcg_dummy_freq; |
| 76 | |
| 77 | /** |
| 78 | * struct fixed_clk - fixed rate clock (used for crystal oscillators) |
| 79 | * @rate: output rate |
| 80 | * @c: clk |
| 81 | */ |
| 82 | struct fixed_clk { |
| 83 | struct clk c; |
| 84 | }; |
| 85 | |
| 86 | /** |
| 87 | * struct branch_clk - branch clock |
| 88 | * @set_rate: Set the frequency of this branch clock. |
| 89 | * @parent: clock source |
| 90 | * @c: clk |
| 91 | * @cbcr_reg: branch control register |
| 92 | * @bcr_reg: block reset register |
| 93 | * @has_sibling: true if other branches are derived from this branch's source |
| 94 | * @cur_div: current branch divider value |
| 95 | * @max_div: maximum branch divider value (if zero, no divider exists) |
| 96 | * @halt_check: halt checking type |
| 97 | * @base: pointer to base address of ioremapped registers. |
| 98 | */ |
| 99 | struct branch_clk { |
| 100 | void (*set_rate)(struct branch_clk *, struct clk_freq_tbl *); |
| 101 | struct clk *parent; |
| 102 | struct clk c; |
| 103 | const u32 cbcr_reg; |
| 104 | const u32 bcr_reg; |
| 105 | int has_sibling; |
| 106 | u32 cur_div; |
| 107 | const u32 max_div; |
| 108 | const u32 halt_check; |
| 109 | void *const __iomem *base; |
| 110 | }; |
| 111 | |
| 112 | static inline struct branch_clk *to_branch_clk(struct clk *clk) |
| 113 | { |
| 114 | return container_of(clk, struct branch_clk, c); |
| 115 | } |
| 116 | |
| 117 | /** |
| 118 | * struct local_vote_clk - Voteable branch clock |
| 119 | * @c: clk |
| 120 | * @cbcr_reg: branch control register |
| 121 | * @vote_reg: voting register |
| 122 | * @en_mask: enable mask |
| 123 | * @halt_check: halt checking type |
| 124 | * @base: pointer to base address of ioremapped registers. |
| 125 | * An on/off switch with a rate derived from the parent. |
| 126 | */ |
| 127 | struct local_vote_clk { |
| 128 | struct clk c; |
| 129 | const u32 cbcr_reg; |
| 130 | const u32 vote_reg; |
| 131 | const u32 bcr_reg; |
| 132 | const u32 en_mask; |
| 133 | const u32 halt_check; |
| 134 | void *const __iomem *base; |
| 135 | }; |
| 136 | |
| 137 | static inline struct local_vote_clk *to_local_vote_clk(struct clk *clk) |
| 138 | { |
| 139 | return container_of(clk, struct local_vote_clk, c); |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * struct measure_clk - for rate measurement debug use |
| 144 | * @sample_ticks: sample period in reference clock ticks |
| 145 | * @multiplier: measurement scale-up factor |
| 146 | * @divider: measurement scale-down factor |
| 147 | * @c: clk |
| 148 | */ |
| 149 | struct measure_clk { |
| 150 | u64 sample_ticks; |
| 151 | u32 multiplier; |
| 152 | u32 divider; |
| 153 | struct clk c; |
| 154 | }; |
| 155 | |
Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 156 | static inline struct measure_clk *to_measure_clk(struct clk *clk) |
| 157 | { |
| 158 | return container_of(clk, struct measure_clk, c); |
| 159 | } |
| 160 | |
| 161 | /* |
| 162 | * Generic set-rate implementations |
| 163 | */ |
| 164 | void set_rate_mnd(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 165 | void set_rate_hid(struct rcg_clk *clk, struct clk_freq_tbl *nf); |
| 166 | |
| 167 | /* |
| 168 | * Variables from the clock-local driver |
| 169 | */ |
| 170 | extern spinlock_t local_clock_reg_lock; |
| 171 | |
Matt Wagantall | edf2fad | 2012-08-06 16:11:46 -0700 | [diff] [blame] | 172 | extern struct clk_ops clk_ops_empty; |
Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 173 | extern struct clk_ops clk_ops_rcg; |
| 174 | extern struct clk_ops clk_ops_rcg_mnd; |
| 175 | extern struct clk_ops clk_ops_branch; |
| 176 | extern struct clk_ops clk_ops_vote; |
| 177 | |
Matt Wagantall | edf2fad | 2012-08-06 16:11:46 -0700 | [diff] [blame] | 178 | /* |
| 179 | * Clock definition macros |
| 180 | */ |
| 181 | #define DEFINE_CLK_MEASURE(name) \ |
| 182 | struct clk name = { \ |
| 183 | .ops = &clk_ops_empty, \ |
| 184 | .dbg_name = #name, \ |
| 185 | CLK_INIT(name), \ |
| 186 | }; \ |
| 187 | |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 188 | #endif /* __ARCH_ARM_MACH_MSM_CLOCK_LOCAL_2_H */ |
Vikram Mulukutla | 8810e34 | 2011-10-20 20:26:53 -0700 | [diff] [blame] | 189 | |