blob: c4addb2072f4214d4adfd4bd3e26c3fcbdb29df6 [file] [log] [blame]
Pankaj Kumar3912c982011-12-07 16:59:03 +05301/*
Duy Truong790f06d2013-02-13 16:38:12 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Pankaj Kumar3912c982011-12-07 16:59:03 +05303 *
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
Matt Wagantallf82f2942012-01-27 13:56:13 -080038 * @c: clock
Pankaj Kumar3912c982011-12-07 16:59:03 +053039 */
40struct pll_shared_clk {
41 unsigned int id;
42 void __iomem *const mode_reg;
43 struct clk c;
Vikram Mulukutla4d6caa82012-04-10 18:04:55 -070044 void *const __iomem *base;
Pankaj Kumar3912c982011-12-07 16:59:03 +053045};
46
Matt Wagantallae053222012-05-14 19:42:07 -070047extern struct clk_ops clk_ops_pll;
Pankaj Kumar3912c982011-12-07 16:59:03 +053048
Matt Wagantallf82f2942012-01-27 13:56:13 -080049static inline struct pll_shared_clk *to_pll_shared_clk(struct clk *c)
Pankaj Kumar3912c982011-12-07 16:59:03 +053050{
Matt Wagantallf82f2942012-01-27 13:56:13 -080051 return container_of(c, struct pll_shared_clk, c);
Pankaj Kumar3912c982011-12-07 16:59:03 +053052}
53
54/**
55 * msm_shared_pll_control_init() - Initialize shared pll control structure
56 */
57void msm_shared_pll_control_init(void);
Vikram Mulukutla681d8682012-03-09 23:56:20 -080058
59/**
Tianyi Goua836dd32012-09-14 10:21:10 -070060 * 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 */
69struct 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 */
87struct 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 Mulukutla681d8682012-03-09 23:56:20 -080099 * 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 Wagantallf82f2942012-01-27 13:56:13 -0800106 * @c: clock
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800107 */
108struct 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 Mulukutla681d8682012-03-09 23:56:20 -0800116 struct clk c;
Vikram Mulukutla4d6caa82012-04-10 18:04:55 -0700117 void *const __iomem *base;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800118};
119
120extern struct clk_ops clk_ops_pll_vote;
Tianyi Goub0f74a92012-10-11 14:10:08 -0700121extern 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 Mulukutla681d8682012-03-09 23:56:20 -0800126
Matt Wagantallf82f2942012-01-27 13:56:13 -0800127static inline struct pll_vote_clk *to_pll_vote_clk(struct clk *c)
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800128{
Matt Wagantallf82f2942012-01-27 13:56:13 -0800129 return container_of(c, struct pll_vote_clk, c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800130}
131
132/**
133 * struct pll_clk - phase locked loop
134 * @mode_reg: enable register
Tianyi Goua836dd32012-09-14 10:21:10 -0700135 * @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 Mulukutlaaa3e0112012-04-23 14:40:51 -0700141 * @status_reg: status register, contains the lock detection bit
Tianyi Goua836dd32012-09-14 10:21:10 -0700142 * @masks: masks used for settings in config_reg
143 * @freq_tbl: pll freq table
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800144 * @c: clk
Vikram Mulukutlaaa3e0112012-04-23 14:40:51 -0700145 * @base: pointer to base address of ioremapped registers.
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800146 */
147struct pll_clk {
148 void __iomem *const mode_reg;
Tianyi Goua836dd32012-09-14 10:21:10 -0700149 void __iomem *const l_reg;
150 void __iomem *const m_reg;
151 void __iomem *const n_reg;
152 void __iomem *const config_reg;
Vikram Mulukutlaaa3e0112012-04-23 14:40:51 -0700153 void __iomem *const status_reg;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800154
Tianyi Goua836dd32012-09-14 10:21:10 -0700155 struct pll_config_masks masks;
156 struct pll_freq_tbl *freq_tbl;
157
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800158 struct clk c;
Vikram Mulukutla4d6caa82012-04-10 18:04:55 -0700159 void *const __iomem *base;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800160};
161
162extern struct clk_ops clk_ops_local_pll;
Patrick Daly79323142012-12-05 15:06:42 -0800163extern struct clk_ops clk_ops_sr2_pll;
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800164
Matt Wagantallf82f2942012-01-27 13:56:13 -0800165static inline struct pll_clk *to_pll_clk(struct clk *c)
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800166{
Matt Wagantallf82f2942012-01-27 13:56:13 -0800167 return container_of(c, struct pll_clk, c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800168}
169
Matt Wagantallf82f2942012-01-27 13:56:13 -0800170int sr_pll_clk_enable(struct clk *c);
Vikram Mulukutla6da35d32012-07-18 13:55:31 -0700171int sr_hpm_lp_pll_clk_enable(struct clk *c);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800172
Vikram Mulukutla5b146722012-04-23 18:17:50 -0700173struct 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
189struct 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 Mulukutla6da35d32012-07-18 13:55:31 -0700198void configure_sr_pll(struct pll_config *config, struct pll_config_regs *regs,
199 u32 ena_fsm_mode);
200void configure_sr_hpm_lp_pll(struct pll_config *config,
201 struct pll_config_regs *, u32 ena_fsm_mode);
Vikram Mulukutla681d8682012-03-09 23:56:20 -0800202#endif