blob: 33b35a843ff05e017749fd8189191d0ef04b1382 [file] [log] [blame]
Pankaj Kumar3912c982011-12-07 16:59:03 +05301/*
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 Mulukutla681d8682012-03-09 23:56:20 -080015#ifndef __ARCH_ARM_MACH_MSM_CLOCK_PLL_H
16#define __ARCH_ARM_MACH_MSM_CLOCK_PLL_H
17
Matt Wagantall33d01f52012-02-23 23:27:44 -080018#include <mach/clk-provider.h>
19
Pankaj Kumar3912c982011-12-07 16:59:03 +053020/**
21 * enum - For PLL IDs
22 */
23enum {
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 Wagantallf82f2942012-01-27 13:56:13 -080039 * @c: clock
Pankaj Kumar3912c982011-12-07 16:59:03 +053040 */
41struct pll_shared_clk {
42 unsigned int id;
43 void __iomem *const mode_reg;
44 struct clk c;
Vikram Mulukutla4d6caa82012-04-10 18:04:55 -070045 void *const __iomem *base;
Pankaj Kumar3912c982011-12-07 16:59:03 +053046};
47
Matt Wagantallae053222012-05-14 19:42:07 -070048extern struct clk_ops clk_ops_pll;
Pankaj Kumar3912c982011-12-07 16:59:03 +053049
Matt Wagantallf82f2942012-01-27 13:56:13 -080050static inline struct pll_shared_clk *to_pll_shared_clk(struct clk *c)
Pankaj Kumar3912c982011-12-07 16:59:03 +053051{
Matt Wagantallf82f2942012-01-27 13:56:13 -080052 return container_of(c, struct pll_shared_clk, c);
Pankaj Kumar3912c982011-12-07 16:59:03 +053053}
54
55/**
56 * msm_shared_pll_control_init() - Initialize shared pll control structure
57 */
58void msm_shared_pll_control_init(void);
Vikram Mulukutla681d8682012-03-09 23:56:20 -080059
60/**
Tianyi Goua836dd32012-09-14 10:21:10 -070061 * 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 */
70struct 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 */
88struct 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 Mulukutla681d8682012-03-09 23:56:20 -0800100 * 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 Wagantallf82f2942012-01-27 13:56:13 -0800108 * @c: clock
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800109 */
110struct 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 Mulukutla4d6caa82012-04-10 18:04:55 -0700120 void *const __iomem *base;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800121};
122
123extern struct clk_ops clk_ops_pll_vote;
Tianyi Goub0f74a92012-10-11 14:10:08 -0700124extern 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 Mulukutla681d8682012-03-09 23:56:20 -0800129
Matt Wagantallf82f2942012-01-27 13:56:13 -0800130static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *c)
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800131{
Matt Wagantallf82f2942012-01-27 13:56:13 -0800132 return container_of(c, struct pll_vote_clk, c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800133}
134
135/**
136 * struct pll_clk - phase locked loop
137 * @mode_reg: enable register
Tianyi Goua836dd32012-09-14 10:21:10 -0700138 * @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 Mulukutlaaa3e0112012-04-23 14:40:51 -0700144 * @status_reg: status register, contains the lock detection bit
Tianyi Goua836dd32012-09-14 10:21:10 -0700145 * @masks: masks used for settings in config_reg
146 * @freq_tbl: pll freq table
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800147 * @parent: clock source
148 * @c: clk
Vikram Mulukutlaaa3e0112012-04-23 14:40:51 -0700149 * @base: pointer to base address of ioremapped registers.
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800150 */
151struct pll_clk {
152 void __iomem *const mode_reg;
Tianyi Goua836dd32012-09-14 10:21:10 -0700153 void __iomem *const l_reg;
154 void __iomem *const m_reg;
155 void __iomem *const n_reg;
156 void __iomem *const config_reg;
Vikram Mulukutlaaa3e0112012-04-23 14:40:51 -0700157 void __iomem *const status_reg;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800158
Tianyi Goua836dd32012-09-14 10:21:10 -0700159 struct pll_config_masks masks;
160 struct pll_freq_tbl *freq_tbl;
161
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800162 struct clk *parent;
163 struct clk c;
Vikram Mulukutla4d6caa82012-04-10 18:04:55 -0700164 void *const __iomem *base;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800165};
166
167extern struct clk_ops clk_ops_local_pll;
168
Matt Wagantallf82f2942012-01-27 13:56:13 -0800169static inline struct pll_clk *to_pll_clk(struct clk *c)
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800170{
Matt Wagantallf82f2942012-01-27 13:56:13 -0800171 return container_of(c, struct pll_clk, c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800172}
173
Matt Wagantallf82f2942012-01-27 13:56:13 -0800174int sr_pll_clk_enable(struct clk *c);
Vikram Mulukutla6da35d32012-07-18 13:55:31 -0700175int sr_hpm_lp_pll_clk_enable(struct clk *c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800176
Vikram Mulukutla5b146722012-04-23 18:17:50 -0700177struct 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
193struct 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 Mulukutla6da35d32012-07-18 13:55:31 -0700202void configure_sr_pll(struct pll_config *config, struct pll_config_regs *regs,
203 u32 ena_fsm_mode);
204void configure_sr_hpm_lp_pll(struct pll_config *config,
205 struct pll_config_regs *, u32 ena_fsm_mode);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800206#endif