Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 1 | /* |
Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012, The Linux Foundation. All rights reserved. |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 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 |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 38 | * @c: clock |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 39 | */ |
| 40 | struct pll_shared_clk { |
| 41 | unsigned int id; |
| 42 | void __iomem *const mode_reg; |
| 43 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 44 | void *const __iomem *base; |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 45 | }; |
| 46 | |
Matt Wagantall | ae05322 | 2012-05-14 19:42:07 -0700 | [diff] [blame] | 47 | extern struct clk_ops clk_ops_pll; |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 48 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 49 | 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] | 50 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 51 | return container_of(c, struct pll_shared_clk, c); |
Pankaj Kumar | 3912c98 | 2011-12-07 16:59:03 +0530 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | /** |
| 55 | * msm_shared_pll_control_init() - Initialize shared pll control structure |
| 56 | */ |
| 57 | void msm_shared_pll_control_init(void); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 58 | |
| 59 | /** |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 60 | * struct pll_freq_tbl - generic PLL frequency definition |
| 61 | * @freq_hz: pll frequency in hz |
| 62 | * @l_val: pll l value |
| 63 | * @m_val: pll m value |
| 64 | * @n_val: pll n value |
| 65 | * @post_div_val: pll post divider value |
| 66 | * @pre_div_val: pll pre-divider value |
| 67 | * @vco_val: pll vco value |
| 68 | */ |
| 69 | struct pll_freq_tbl { |
| 70 | const u32 freq_hz; |
| 71 | const u32 l_val; |
| 72 | const u32 m_val; |
| 73 | const u32 n_val; |
| 74 | const u32 post_div_val; |
| 75 | const u32 pre_div_val; |
| 76 | const u32 vco_val; |
| 77 | }; |
| 78 | |
| 79 | /** |
| 80 | * struct pll_config_masks - PLL config masks struct |
| 81 | * @post_div_mask: mask for post divider bits location |
| 82 | * @pre_div_mask: mask for pre-divider bits location |
| 83 | * @vco_mask: mask for vco bits location |
| 84 | * @mn_en_mask: ORed with pll config register to enable the mn counter |
| 85 | * @main_output_mask: ORed with pll config register to enable the main output |
| 86 | */ |
| 87 | struct pll_config_masks { |
| 88 | u32 post_div_mask; |
| 89 | u32 pre_div_mask; |
| 90 | u32 vco_mask; |
| 91 | u32 mn_en_mask; |
| 92 | u32 main_output_mask; |
| 93 | }; |
| 94 | |
| 95 | #define PLL_FREQ_END (UINT_MAX-1) |
| 96 | #define PLL_F_END { .freq_hz = PLL_FREQ_END } |
| 97 | |
| 98 | /** |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 99 | * struct pll_vote_clk - phase locked loop (HW voteable) |
| 100 | * @soft_vote: soft voting variable for multiple PLL software instances |
| 101 | * @soft_vote_mask: soft voting mask for multiple PLL software instances |
| 102 | * @en_reg: enable register |
| 103 | * @en_mask: ORed with @en_reg to enable the clock |
| 104 | * @status_mask: ANDed with @status_reg to determine if PLL is active. |
| 105 | * @status_reg: status register |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 106 | * @c: clock |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 107 | */ |
| 108 | struct pll_vote_clk { |
| 109 | u32 *soft_vote; |
| 110 | const u32 soft_vote_mask; |
| 111 | void __iomem *const en_reg; |
| 112 | const u32 en_mask; |
| 113 | void __iomem *const status_reg; |
| 114 | const u32 status_mask; |
| 115 | |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 116 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 117 | void *const __iomem *base; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | extern struct clk_ops clk_ops_pll_vote; |
Tianyi Gou | b0f74a9 | 2012-10-11 14:10:08 -0700 | [diff] [blame] | 121 | extern struct clk_ops clk_ops_pll_acpu_vote; |
| 122 | |
| 123 | /* Soft voting values */ |
| 124 | #define PLL_SOFT_VOTE_PRIMARY BIT(0) |
| 125 | #define PLL_SOFT_VOTE_ACPU BIT(1) |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 126 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 127 | 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] | 128 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 129 | return container_of(c, struct pll_vote_clk, c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /** |
| 133 | * struct pll_clk - phase locked loop |
| 134 | * @mode_reg: enable register |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 135 | * @l_reg: l value register |
| 136 | * @m_reg: m value register |
| 137 | * @n_reg: n value register |
| 138 | * @config_reg: configuration register, contains mn divider enable, pre divider, |
| 139 | * post divider and vco configuration. register name can be configure register |
| 140 | * or user_ctl register depending on targets |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 141 | * @status_reg: status register, contains the lock detection bit |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 142 | * @masks: masks used for settings in config_reg |
| 143 | * @freq_tbl: pll freq table |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 144 | * @c: clk |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 145 | * @base: pointer to base address of ioremapped registers. |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 146 | */ |
| 147 | struct pll_clk { |
| 148 | void __iomem *const mode_reg; |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 149 | void __iomem *const l_reg; |
| 150 | void __iomem *const m_reg; |
| 151 | void __iomem *const n_reg; |
| 152 | void __iomem *const config_reg; |
Vikram Mulukutla | aa3e011 | 2012-04-23 14:40:51 -0700 | [diff] [blame] | 153 | void __iomem *const status_reg; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 154 | |
Tianyi Gou | a836dd3 | 2012-09-14 10:21:10 -0700 | [diff] [blame] | 155 | struct pll_config_masks masks; |
| 156 | struct pll_freq_tbl *freq_tbl; |
| 157 | |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 158 | struct clk c; |
Vikram Mulukutla | 4d6caa8 | 2012-04-10 18:04:55 -0700 | [diff] [blame] | 159 | void *const __iomem *base; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | extern struct clk_ops clk_ops_local_pll; |
Patrick Daly | 7932314 | 2012-12-05 15:06:42 -0800 | [diff] [blame] | 163 | extern struct clk_ops clk_ops_sr2_pll; |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 164 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 165 | static inline struct pll_clk *to_pll_clk(struct clk *c) |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 166 | { |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 167 | return container_of(c, struct pll_clk, c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Matt Wagantall | f82f294 | 2012-01-27 13:56:13 -0800 | [diff] [blame] | 170 | int sr_pll_clk_enable(struct clk *c); |
Vikram Mulukutla | 6da35d3 | 2012-07-18 13:55:31 -0700 | [diff] [blame] | 171 | int sr_hpm_lp_pll_clk_enable(struct clk *c); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 172 | |
Vikram Mulukutla | 5b14672 | 2012-04-23 18:17:50 -0700 | [diff] [blame] | 173 | struct pll_config { |
| 174 | u32 l; |
| 175 | u32 m; |
| 176 | u32 n; |
| 177 | u32 vco_val; |
| 178 | u32 vco_mask; |
| 179 | u32 pre_div_val; |
| 180 | u32 pre_div_mask; |
| 181 | u32 post_div_val; |
| 182 | u32 post_div_mask; |
| 183 | u32 mn_ena_val; |
| 184 | u32 mn_ena_mask; |
| 185 | u32 main_output_val; |
| 186 | u32 main_output_mask; |
| 187 | }; |
| 188 | |
| 189 | struct pll_config_regs { |
| 190 | void __iomem *l_reg; |
| 191 | void __iomem *m_reg; |
| 192 | void __iomem *n_reg; |
| 193 | void __iomem *config_reg; |
| 194 | void __iomem *mode_reg; |
| 195 | void *const __iomem *base; |
| 196 | }; |
| 197 | |
Vikram Mulukutla | 6da35d3 | 2012-07-18 13:55:31 -0700 | [diff] [blame] | 198 | void configure_sr_pll(struct pll_config *config, struct pll_config_regs *regs, |
| 199 | u32 ena_fsm_mode); |
| 200 | void configure_sr_hpm_lp_pll(struct pll_config *config, |
| 201 | struct pll_config_regs *, u32 ena_fsm_mode); |
Vikram Mulukutla | 681d868 | 2012-03-09 23:56:20 -0800 | [diff] [blame] | 202 | #endif |