blob: f02af98590c47685e7ecd8c7835da778cb4d6a9e [file] [log] [blame]
Matt Wagantalle9b715a2012-01-04 18:16:14 -08001/*
Matt Wagantall2dd3f972013-01-08 12:03:43 -08002 * Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Matt Wagantalle9b715a2012-01-04 18:16:14 -08003 *
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#ifndef __ARCH_ARM_MACH_MSM_ACPUCLOCK_KRAIT_H
15#define __ARCH_ARM_MACH_MSM_ACPUCLOCK_KRAIT_H
16
Matt Wagantall600ea502012-06-08 18:49:53 -070017#define L2(x) (x)
Matt Wagantalle9b715a2012-01-04 18:16:14 -080018#define BW_MBPS(_bw) \
19 { \
20 .vectors = (struct msm_bus_vectors[]){ \
21 {\
22 .src = MSM_BUS_MASTER_AMPSS_M0, \
23 .dst = MSM_BUS_SLAVE_EBI_CH0, \
Gagan Macb2372ae2012-08-20 19:24:32 -060024 .ib = (_bw) * 1000000ULL, \
Matt Wagantalle9b715a2012-01-04 18:16:14 -080025 }, \
26 { \
27 .src = MSM_BUS_MASTER_AMPSS_M1, \
28 .dst = MSM_BUS_SLAVE_EBI_CH0, \
Gagan Macb2372ae2012-08-20 19:24:32 -060029 .ib = (_bw) * 1000000ULL, \
Matt Wagantalle9b715a2012-01-04 18:16:14 -080030 }, \
31 }, \
32 .num_paths = 2, \
33 }
34
35/**
36 * src_id - Clock source IDs.
37 */
38enum src_id {
39 PLL_0 = 0,
40 HFPLL,
Matt Wagantall06e4a1f2012-06-07 18:38:13 -070041 PLL_8,
Matt Wagantall488bef32012-07-13 19:42:11 -070042 NUM_SRC_ID
Matt Wagantalle9b715a2012-01-04 18:16:14 -080043};
44
45/**
46 * enum pvs - IDs to distinguish between CPU frequency tables.
47 */
48enum pvs {
49 PVS_SLOW = 0,
Patrick Daly18d2d482012-08-24 14:22:06 -070050 PVS_NOMINAL = 1,
51 PVS_FAST = 3,
52 PVS_FASTER = 4,
Matt Wagantall19b8be52013-02-25 19:19:52 -080053 NUM_PVS = 8
Matt Wagantalle9b715a2012-01-04 18:16:14 -080054};
55
56/**
Patrick Daly18d2d482012-08-24 14:22:06 -070057 * The maximum number of speed bins.
58 */
59#define NUM_SPEED_BINS (16)
60
61/**
Matt Wagantalle9b715a2012-01-04 18:16:14 -080062 * enum scalables - IDs of frequency scalable hardware blocks.
63 */
64enum scalables {
65 CPU0 = 0,
66 CPU1,
67 CPU2,
68 CPU3,
69 L2,
Matt Wagantall488bef32012-07-13 19:42:11 -070070 MAX_SCALABLES
Matt Wagantalle9b715a2012-01-04 18:16:14 -080071};
72
73
74/**
75 * enum hfpll_vdd_level - IDs of HFPLL voltage levels.
76 */
77enum hfpll_vdd_levels {
78 HFPLL_VDD_NONE,
79 HFPLL_VDD_LOW,
80 HFPLL_VDD_NOM,
Matt Wagantall87465f52012-07-23 22:03:06 -070081 HFPLL_VDD_HIGH,
Matt Wagantalle9b715a2012-01-04 18:16:14 -080082 NUM_HFPLL_VDD
83};
84
85/**
86 * enum vregs - IDs of voltage regulators.
87 */
88enum vregs {
89 VREG_CORE,
90 VREG_MEM,
91 VREG_DIG,
92 VREG_HFPLL_A,
93 VREG_HFPLL_B,
94 NUM_VREG
95};
96
97/**
98 * struct vreg - Voltage regulator data.
99 * @name: Name of requlator.
100 * @max_vdd: Limit the maximum-settable voltage.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800101 * @reg: Regulator handle.
Matt Wagantall75473eb2012-05-31 15:23:22 -0700102 * @rpm_reg: RPM Regulator handle.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800103 * @cur_vdd: Last-set voltage in uV.
Matt Wagantall6d9c4162012-07-16 18:58:16 -0700104 * @cur_ua: Last-set current in uA.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800105 */
106struct vreg {
Matt Wagantall75473eb2012-05-31 15:23:22 -0700107 const char *name;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800108 const int max_vdd;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800109 struct regulator *reg;
Matt Wagantall75473eb2012-05-31 15:23:22 -0700110 struct rpm_regulator *rpm_reg;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800111 int cur_vdd;
Matt Wagantall6d9c4162012-07-16 18:58:16 -0700112 int cur_ua;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800113};
114
115/**
116 * struct core_speed - Clock tree and configuration parameters.
117 * @khz: Clock rate in KHz.
118 * @src: Clock source ID.
119 * @pri_src_sel: Input to select on the primary MUX.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800120 * @pll_l_val: HFPLL "L" value to be applied when an HFPLL source is selected.
121 */
122struct core_speed {
Matt Wagantall9c8cb6e2012-07-13 19:39:15 -0700123 unsigned long khz;
124 int src;
125 u32 pri_src_sel;
Matt Wagantall9c8cb6e2012-07-13 19:39:15 -0700126 u32 pll_l_val;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800127};
128
129/**
130 * struct l2_level - L2 clock rate and associated voltage and b/w requirements.
131 * @speed: L2 clock configuration.
132 * @vdd_dig: vdd_dig voltage in uV.
133 * @vdd_mem: vdd_mem voltage in uV.
134 * @bw_level: Bandwidth performance level number.
135 */
136struct l2_level {
137 const struct core_speed speed;
138 const int vdd_dig;
139 const int vdd_mem;
140 const unsigned int bw_level;
141};
142
143/**
144 * struct acpu_level - CPU clock rate and L2 rate and voltage requirements.
145 * @use_for_scaling: Flag indicating whether or not the level should be used.
146 * @speed: CPU clock configuration.
147 * @l2_level: L2 configuration to use.
148 * @vdd_core: CPU core voltage in uV.
Matt Wagantall6d9c4162012-07-16 18:58:16 -0700149 * @ua_core: CPU core current consumption in uA.
Stephen Boyda86214a2012-09-14 11:25:34 -0700150 * @avsdscr_setting: AVS DSCR configuration.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800151 */
152struct acpu_level {
153 const int use_for_scaling;
154 const struct core_speed speed;
Matt Wagantall2dd3f972013-01-08 12:03:43 -0800155 unsigned int l2_level;
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700156 int vdd_core;
Matt Wagantall6d9c4162012-07-16 18:58:16 -0700157 int ua_core;
Stephen Boyda86214a2012-09-14 11:25:34 -0700158 unsigned int avsdscr_setting;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800159};
160
161/**
162 * struct hfpll_data - Descriptive data of HFPLL hardware.
163 * @mode_offset: Mode register offset from base address.
164 * @l_offset: "L" value register offset from base address.
165 * @m_offset: "M" value register offset from base address.
166 * @n_offset: "N" value register offset from base address.
167 * @config_offset: Configuration register offset from base address.
168 * @config_val: Value to initialize the @config_offset register to.
Matt Wagantalla77b7f32012-07-18 16:32:01 -0700169 * @has_user_reg: Indicates the presence of an addition config register.
170 * @user_offset: User register offset from base address, if applicable.
171 * @user_val: Value to initialize the @user_offset register to.
172 * @user_vco_mask: Bit in the @user_offset to enable high-frequency VCO mode.
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700173 * @has_droop_ctl: Indicates the presence of a voltage droop controller.
Matt Wagantall9bd53962013-04-06 12:29:40 -0700174 * @has_lock_status: Indicates the presence of a lock status bit.
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700175 * @droop_offset: Droop controller register offset from base address.
176 * @droop_val: Value to initialize the @config_offset register to.
Matt Wagantall9bd53962013-04-06 12:29:40 -0700177 * @status_offset: PLL status register offset.
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700178 * @low_vdd_l_max: Maximum "L" value supported at HFPLL_VDD_LOW.
Matt Wagantall87465f52012-07-23 22:03:06 -0700179 * @nom_vdd_l_max: Maximum "L" value supported at HFPLL_VDD_NOM.
Matt Wagantalla77b7f32012-07-18 16:32:01 -0700180 * @low_vco_l_max: Maximum "L" value supported in low-frequency VCO mode.
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700181 * @vdd: voltage requirements for each VDD level for the L2 PLL.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800182 */
183struct hfpll_data {
184 const u32 mode_offset;
185 const u32 l_offset;
186 const u32 m_offset;
187 const u32 n_offset;
188 const u32 config_offset;
189 const u32 config_val;
Matt Wagantalla77b7f32012-07-18 16:32:01 -0700190 const bool has_user_reg;
191 const u32 user_offset;
192 const u32 user_val;
193 const u32 user_vco_mask;
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700194 const bool has_droop_ctl;
Matt Wagantall9bd53962013-04-06 12:29:40 -0700195 const bool has_lock_status;
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700196 const u32 droop_offset;
197 const u32 droop_val;
Matt Wagantall9bd53962013-04-06 12:29:40 -0700198 const u32 status_offset;
Patrick Daly18d2d482012-08-24 14:22:06 -0700199 u32 low_vdd_l_max;
200 u32 nom_vdd_l_max;
Matt Wagantalla77b7f32012-07-18 16:32:01 -0700201 const u32 low_vco_l_max;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800202 const int vdd[NUM_HFPLL_VDD];
203};
204
205/**
206 * struct scalable - Register locations and state associated with a scalable HW.
207 * @hfpll_phys_base: Physical base address of HFPLL register.
208 * @hfpll_base: Virtual base address of HFPLL registers.
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700209 * @aux_clk_sel_phys: Physical address of auxiliary MUX.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800210 * @aux_clk_sel: Auxiliary mux input to select at boot.
Matt Wagantall6cd5d752012-09-27 19:56:57 -0700211 * @sec_clk_sel: Secondary mux input to select at boot.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800212 * @l2cpmr_iaddr: Indirect address of the CPMR MUX/divider CP15 register.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800213 * @cur_speed: Pointer to currently-set speed.
214 * @l2_vote: L2 performance level vote associate with the current CPU speed.
215 * @vreg: Array of voltage regulators needed by the scalable.
Matt Wagantall754ee272012-06-18 13:40:26 -0700216 * @initialized: Flag set to true when per_cpu_init() has been called.
Stephen Boyda86214a2012-09-14 11:25:34 -0700217 * @avs_enabled: True if avs is enabled for the scalabale. False otherwise.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800218 */
219struct scalable {
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700220 const phys_addr_t hfpll_phys_base;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800221 void __iomem *hfpll_base;
Matt Wagantall06e4a1f2012-06-07 18:38:13 -0700222 const phys_addr_t aux_clk_sel_phys;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800223 const u32 aux_clk_sel;
Matt Wagantall6cd5d752012-09-27 19:56:57 -0700224 const u32 sec_clk_sel;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800225 const u32 l2cpmr_iaddr;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800226 const struct core_speed *cur_speed;
Matt Wagantall600ea502012-06-08 18:49:53 -0700227 unsigned int l2_vote;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800228 struct vreg vreg[NUM_VREG];
Matt Wagantall754ee272012-06-18 13:40:26 -0700229 bool initialized;
Stephen Boyda86214a2012-09-14 11:25:34 -0700230 bool avs_enabled;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800231};
232
233/**
Matt Wagantallf9a4d322013-01-14 18:01:24 -0800234 * struct bin_info - Hardware speed and voltage binning info.
235 * @speed_valid: @speed field is valid
236 * @pvs_valid: @pvs field is valid
237 * @speed: Speed bin ID
238 * @pvs: PVS bin ID
239 */
240struct bin_info {
241 bool speed_valid;
242 bool pvs_valid;
243 int speed;
244 int pvs;
245};
246
247/**
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700248 * struct pvs_table - CPU performance level table and size.
249 * @table: CPU performance level table
250 * @size: sizeof(@table)
Matt Wagantall9515bc22012-07-19 18:13:40 -0700251 * @boost_uv: Voltage boost amount
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700252 */
253struct pvs_table {
254 struct acpu_level *table;
255 size_t size;
Matt Wagantall9515bc22012-07-19 18:13:40 -0700256 int boost_uv;
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700257};
258
259/**
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800260 * struct acpuclk_krait_params - SoC specific driver parameters.
261 * @scalable: Array of scalables.
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700262 * @scalable_size: Size of @scalable.
263 * @hfpll_data: HFPLL configuration data.
Patrick Daly18d2d482012-08-24 14:22:06 -0700264 * @pvs_tables: 2D array of CPU frequency tables.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800265 * @l2_freq_tbl: L2 frequency table.
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700266 * @l2_freq_tbl_size: Size of @l2_freq_tbl.
Matt Wagantallee2b4372012-09-17 17:51:06 -0700267 * @pte_efuse_phys: Physical address of PTE EFUSE.
Matt Wagantallf9a4d322013-01-14 18:01:24 -0800268 * @get_bin_info: Function to populate bin_info from pte_efuse.
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700269 * @bus_scale: MSM bus driver parameters.
Matt Wagantallb7c231b2012-07-24 18:40:17 -0700270 * @stby_khz: KHz value corresponding to an always-on clock source.
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800271 */
272struct acpuclk_krait_params {
273 struct scalable *scalable;
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700274 size_t scalable_size;
275 struct hfpll_data *hfpll_data;
Patrick Daly18d2d482012-08-24 14:22:06 -0700276 struct pvs_table (*pvs_tables)[NUM_PVS];
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700277 struct l2_level *l2_freq_tbl;
278 size_t l2_freq_tbl_size;
Matt Wagantallee2b4372012-09-17 17:51:06 -0700279 phys_addr_t pte_efuse_phys;
Matt Wagantallf9a4d322013-01-14 18:01:24 -0800280 void (*get_bin_info)(void __iomem *base, struct bin_info *bin);
Matt Wagantall1f3762d2012-06-08 19:08:48 -0700281 struct msm_bus_scale_pdata *bus_scale;
Matt Wagantallb7c231b2012-07-24 18:40:17 -0700282 unsigned long stby_khz;
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800283};
284
285/**
Matt Wagantall488bef32012-07-13 19:42:11 -0700286 * struct drv_data - Driver state
287 * @acpu_freq_tbl: CPU frequency table.
288 * @l2_freq_tbl: L2 frequency table.
289 * @scalable: Array of scalables (CPUs and L2).
290 * @hfpll_data: High-frequency PLL data.
291 * @bus_perf_client: Bus driver client handle.
292 * @bus_scale: Bus driver scaling data.
293 * @boost_uv: Voltage boost amount
294 * @speed_bin: Speed bin ID.
295 * @pvs_bin: PVS bin ID.
296 * @dev: Device.
297 */
298struct drv_data {
299 struct acpu_level *acpu_freq_tbl;
300 const struct l2_level *l2_freq_tbl;
301 struct scalable *scalable;
302 struct hfpll_data *hfpll_data;
303 u32 bus_perf_client;
304 struct msm_bus_scale_pdata *bus_scale;
305 int boost_uv;
306 int speed_bin;
307 int pvs_bin;
308 struct device *dev;
309};
310
311/**
Patrick Daly037d4912012-08-28 13:36:31 -0700312 * struct acpuclk_platform_data - PMIC configuration data.
313 * @uses_pm8917: Boolean indicates presence of pm8917.
314 */
315struct acpuclk_platform_data {
316 bool uses_pm8917;
317};
318
319/**
Matt Wagantallf9a4d322013-01-14 18:01:24 -0800320 * get_krait_bin_format_a - Populate bin_info from a 'Format A' pte_efuse
321 */
322void __init get_krait_bin_format_a(void __iomem *base, struct bin_info *bin);
323
324/**
325 * get_krait_bin_format_b - Populate bin_info from a 'Format B' pte_efuse
326 */
327void __init get_krait_bin_format_b(void __iomem *base, struct bin_info *bin);
328
329/**
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800330 * acpuclk_krait_init - Initialize the Krait CPU clock driver give SoC params.
331 */
332extern int acpuclk_krait_init(struct device *dev,
333 const struct acpuclk_krait_params *params);
Matt Wagantall488bef32012-07-13 19:42:11 -0700334
335#ifdef CONFIG_DEBUG_FS
336/**
337 * acpuclk_krait_debug_init - Initialize debugfs interface.
338 */
339extern void __init acpuclk_krait_debug_init(struct drv_data *drv);
340#else
341static inline void acpuclk_krait_debug_init(void) { }
342#endif
343
Matt Wagantalle9b715a2012-01-04 18:16:14 -0800344#endif