Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU General Public License version 2 and |
| 6 | * only version 2 as published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it will be useful, |
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | * GNU General Public License for more details. |
| 12 | * |
| 13 | */ |
| 14 | |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 15 | #ifndef __ARCH_ARM_MACH_MSM_CLOCK_PLL_H |
| 16 | #define __ARCH_ARM_MACH_MSM_CLOCK_PLL_H |
| 17 | |
Matt Wagantall | 33d01f5 | 2012-02-23 23:27:44 -0800 | [diff] [blame] | 18 | #include <mach/clk-provider.h> |
| 19 | |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 20 | /** |
| 21 | * enum - For PLL IDs |
| 22 | */ |
| 23 | enum { |
| 24 | PLL_TCXO = -1, |
| 25 | PLL_0 = 0, |
| 26 | PLL_1, |
| 27 | PLL_2, |
| 28 | PLL_3, |
| 29 | PLL_4, |
| 30 | PLL_END, |
| 31 | }; |
| 32 | |
| 33 | /** |
| 34 | * struct pll_shared_clk - PLL shared with other processors without |
| 35 | * any HW voting |
| 36 | * @id: PLL ID |
| 37 | * @mode_reg: enable register |
| 38 | * @parent: clock source |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 39 | * @c: clock |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 40 | */ |
| 41 | struct pll_shared_clk { |
| 42 | unsigned int id; |
| 43 | void __iomem *const mode_reg; |
| 44 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 45 | void *const __iomem *base; |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 46 | }; |
| 47 | |
Matt Wagantall | ae05322 | 2012-05-14 19:42:07 -0700 | [diff] [blame] | 48 | extern struct clk_ops clk_ops_pll; |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 49 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 50 | static inline struct pll_shared_clk *to_pll_shared_clk(struct clk *c) |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 51 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 52 | return container_of(c, struct pll_shared_clk, c); |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | /** |
| 56 | * msm_shared_pll_control_init() - Initialize shared pll control structure |
| 57 | */ |
| 58 | void msm_shared_pll_control_init(void); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 59 | |
| 60 | /** |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 61 | * struct pll_freq_tbl - generic PLL frequency definition |
| 62 | * @freq_hz: pll frequency in hz |
| 63 | * @l_val: pll l value |
| 64 | * @m_val: pll m value |
| 65 | * @n_val: pll n value |
| 66 | * @post_div_val: pll post divider value |
| 67 | * @pre_div_val: pll pre-divider value |
| 68 | * @vco_val: pll vco value |
| 69 | */ |
| 70 | struct pll_freq_tbl { |
| 71 | const u32 freq_hz; |
| 72 | const u32 l_val; |
| 73 | const u32 m_val; |
| 74 | const u32 n_val; |
| 75 | const u32 post_div_val; |
| 76 | const u32 pre_div_val; |
| 77 | const u32 vco_val; |
| 78 | }; |
| 79 | |
| 80 | /** |
| 81 | * struct pll_config_masks - PLL config masks struct |
| 82 | * @post_div_mask: mask for post divider bits location |
| 83 | * @pre_div_mask: mask for pre-divider bits location |
| 84 | * @vco_mask: mask for vco bits location |
| 85 | * @mn_en_mask: ORed with pll config register to enable the mn counter |
| 86 | * @main_output_mask: ORed with pll config register to enable the main output |
| 87 | */ |
| 88 | struct pll_config_masks { |
| 89 | u32 post_div_mask; |
| 90 | u32 pre_div_mask; |
| 91 | u32 vco_mask; |
| 92 | u32 mn_en_mask; |
| 93 | u32 main_output_mask; |
| 94 | }; |
| 95 | |
| 96 | #define PLL_FREQ_END (UINT_MAX-1) |
| 97 | #define PLL_F_END { .freq_hz = PLL_FREQ_END } |
| 98 | |
| 99 | /** |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 100 | * struct pll_vote_clk - phase locked loop (HW voteable) |
| 101 | * @soft_vote: soft voting variable for multiple PLL software instances |
| 102 | * @soft_vote_mask: soft voting mask for multiple PLL software instances |
| 103 | * @en_reg: enable register |
| 104 | * @en_mask: ORed with @en_reg to enable the clock |
| 105 | * @status_mask: ANDed with @status_reg to determine if PLL is active. |
| 106 | * @status_reg: status register |
| 107 | * @parent: clock source |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 108 | * @c: clock |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 109 | */ |
| 110 | struct pll_vote_clk { |
| 111 | u32 *soft_vote; |
| 112 | const u32 soft_vote_mask; |
| 113 | void __iomem *const en_reg; |
| 114 | const u32 en_mask; |
| 115 | void __iomem *const status_reg; |
| 116 | const u32 status_mask; |
| 117 | |
| 118 | struct clk *parent; |
| 119 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 120 | void *const __iomem *base; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
| 123 | extern struct clk_ops clk_ops_pll_vote; |
Tianyi Gou | b0f74a9 | 2012-10-11 14:10:08 -0700 | [diff] [blame] | 124 | extern struct clk_ops clk_ops_pll_acpu_vote; |
| 125 | |
| 126 | /* Soft voting values */ |
| 127 | #define PLL_SOFT_VOTE_PRIMARY BIT(0) |
| 128 | #define PLL_SOFT_VOTE_ACPU BIT(1) |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 129 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 130 | static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *c) |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 131 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 132 | return container_of(c, struct pll_vote_clk, c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /** |
| 136 | * struct pll_clk - phase locked loop |
| 137 | * @mode_reg: enable register |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 138 | * @l_reg: l value register |
| 139 | * @m_reg: m value register |
| 140 | * @n_reg: n value register |
| 141 | * @config_reg: configuration register, contains mn divider enable, pre divider, |
| 142 | * post divider and vco configuration. register name can be configure register |
| 143 | * or user_ctl register depending on targets |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 144 | * @status_reg: status register, contains the lock detection bit |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 145 | * @masks: masks used for settings in config_reg |
| 146 | * @freq_tbl: pll freq table |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 147 | * @parent: clock source |
| 148 | * @c: clk |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 149 | * @base: pointer to base address of ioremapped registers. |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 150 | */ |
| 151 | struct pll_clk { |
| 152 | void __iomem *const mode_reg; |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 153 | void __iomem *const l_reg; |
| 154 | void __iomem *const m_reg; |
| 155 | void __iomem *const n_reg; |
| 156 | void __iomem *const config_reg; |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 157 | void __iomem *const status_reg; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 158 | |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 159 | struct pll_config_masks masks; |
| 160 | struct pll_freq_tbl *freq_tbl; |
| 161 | |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 162 | struct clk *parent; |
| 163 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 164 | void *const __iomem *base; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | extern struct clk_ops clk_ops_local_pll; |
| 168 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 169 | static inline struct pll_clk *to_pll_clk(struct clk *c) |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 170 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 171 | return container_of(c, struct pll_clk, c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 172 | } |
| 173 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 174 | int sr_pll_clk_enable(struct clk *c); |
Vikram Mulukutla | 6da35d3 | 2012-07-18 13:55:31 -0700 | [diff] [blame] | 175 | int sr_hpm_lp_pll_clk_enable(struct clk *c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 176 | |
Vikram Mulukutla | 5b14672 | 2012-04-23 18:17:50 -0700 | [diff] [blame] | 177 | struct pll_config { |
| 178 | u32 l; |
| 179 | u32 m; |
| 180 | u32 n; |
| 181 | u32 vco_val; |
| 182 | u32 vco_mask; |
| 183 | u32 pre_div_val; |
| 184 | u32 pre_div_mask; |
| 185 | u32 post_div_val; |
| 186 | u32 post_div_mask; |
| 187 | u32 mn_ena_val; |
| 188 | u32 mn_ena_mask; |
| 189 | u32 main_output_val; |
| 190 | u32 main_output_mask; |
| 191 | }; |
| 192 | |
| 193 | struct pll_config_regs { |
| 194 | void __iomem *l_reg; |
| 195 | void __iomem *m_reg; |
| 196 | void __iomem *n_reg; |
| 197 | void __iomem *config_reg; |
| 198 | void __iomem *mode_reg; |
| 199 | void *const __iomem *base; |
| 200 | }; |
| 201 | |
Vikram Mulukutla | 6da35d3 | 2012-07-18 13:55:31 -0700 | [diff] [blame] | 202 | void configure_sr_pll(struct pll_config *config, struct pll_config_regs *regs, |
| 203 | u32 ena_fsm_mode); |
| 204 | void configure_sr_hpm_lp_pll(struct pll_config *config, |
| 205 | struct pll_config_regs *, u32 ena_fsm_mode); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 206 | #endif |