blob: fd9ec145fb66216817ab5131d9cdf0e1ba7eb64f [file] [log] [blame]
Pankaj Kumar32ce1ea2012-04-04 20:29:29 +05301/*
Duy Truonge833aca2013-02-12 13:35:08 -08002 * Copyright (c) 2012, The Linux Foundation. All rights reserved.
Pankaj Kumar32ce1ea2012-04-04 20:29:29 +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
15#ifndef __ARCH_ARM_MACH_MSM_CPR_H
16#define __ARCH_ARM_MACH_MSM_CPR_H
17
18/* Register Offsets for RBCPR */
19
20/* RBCPR Gate Count and Target Registers */
21#define RBCPR_GCNT_TARGET(n) (0x60 + 4 * n)
22
23/* RBCPR Timer Control */
24#define RBCPR_TIMER_INTERVAL 0x44
25#define RBIF_TIMER_ADJUST 0x4C
26
27/* RBCPR Config Register */
28#define RBIF_LIMIT 0x48
29#define RBCPR_STEP_QUOT 0X80
30#define RBCPR_CTL 0x90
31#define RBIF_SW_VLEVEL 0x94
32#define RBIF_CONT_ACK_CMD 0x98
33#define RBIF_CONT_NACK_CMD 0x9C
34
35/* RBCPR Result status Register */
36#define RBCPR_RESULT_0 0xA0
37#define RBCPR_RESULT_1 0xA4
38#define RBCPR_QUOT_AVG 0x118
39
40/* RBCPR DEBUG Register */
41#define RBCPR_DEBUG1 0x120
42
43/* RBCPR Interrupt Control Register */
44#define RBIF_IRQ_EN(n) (0x100 + 4 * n)
45#define RBIF_IRQ_CLEAR 0x110
46#define RBIF_IRQ_STATUS 0x114
47
48/* Bit Mask Values */
49#define GCNT_M 0x003FF000
50#define TARGET_M 0x00000FFF
51#define SW_VLEVEL_M 0x0000003F
52#define UP_FLAG_M 0x00000010
53#define DOWN_FLAG_M 0x00000004
54#define CEILING_M 0x00000FC0
55#define FLOOR_M 0x0000003F
56#define LOOP_EN_M 0x00000001
57#define TIMER_M 0x00000008
58#define SW_AUTO_CONT_ACK_EN_M 0x00000020
59#define SW_AUTO_CONT_NACK_DN_EN_M 0x00000040
60#define HW_TO_PMIC_EN_M BIT(4)
61#define BUSY_M BIT(19)
62#define QUOT_SLOW_M 0x00FFF000
63#define UP_THRESHOLD_M 0x0F000000
64#define DN_THRESHOLD_M 0xF0000000
65
66/* Bit Values */
67#define ENABLE_CPR BIT(0)
68#define DISABLE_CPR 0x0
69#define ENABLE_TIMER BIT(3)
70#define DISABLE_TIMER 0x0
71#define SW_MODE 0x0
72#define SW_AUTO_CONT_ACK_EN BIT(5)
73#define SW_AUTO_CONT_NACK_DN_EN BIT(6)
74
75/* Test values for RBCPR RUMI Testing */
76#define GNT_CNT 0xC0
77#define TARGET 0xEFF
78
79#define CEILING_V 0x30
80#define FLOOR_V 0x15
81
82#define SW_LEVEL 0x20
83
84/* Interrupt Mask for All interrupt flags */
85#define INT_MASK (MIN_INT | DOWN_INT | MID_INT | UP_INT | MAX_INT)
86
87/* Number of oscilator in each sensor */
88#define NUM_OSC 8
89
90#define CPR_MODE 2
91
92/**
93 * enum cpr_mode - Modes in which cpr is used
94 */
95enum cpr_mode {
96 NORMAL_MODE = 0,
97 TURBO_MODE,
98 SVS_MODE,
99};
100
101/**
102 * enum cpr_action - Cpr actions to be taken
103 */
104enum cpr_action {
105 DOWN = 0,
106 UP,
107};
108
109/**
110 * enum cpr_interrupt
111 */
112enum cpr_interrupt {
113 DONE_INT = BIT(0),
114 MIN_INT = BIT(1),
115 DOWN_INT = BIT(2),
116 MID_INT = BIT(3),
117 UP_INT = BIT(4),
118 MAX_INT = BIT(5),
119};
120
121/**
122 * struct msm_vp_data - structure for VP configuration
123 * @min_volt_mV: minimum milivolt level for VP
124 * @max_volt_mV: maximum milivolt level for VP
125 * @default_volt_mV: default milivolt for VP
126 * @step_size_mV: step size of voltage
127 */
128struct msm_cpr_vp_data {
129 int min_volt;
130 int max_volt;
131 int default_volt;
132 int step_size;
133};
134
135/**
136 * struct msm_cpr_osc - Data for CPR ring oscillator
137 * @gcnt: gate count value for the oscillator
138 * @target_count: target value for ring oscillator
139 */
140struct msm_cpr_osc {
141 int gcnt;
142 uint32_t target_count;
143};
144
145/**
146 * struct msm_cpr_mode - Data for CPR modes of operation
147 * @msm_cpr_osc: structure for oscillator data
148 * @ring_osc: ring oscillator of the sensor
149 * @tgt_volt_offset: inital voltage offset from default value
150 * @step_quot: step Quot for CPR calcuation
151 */
152struct msm_cpr_mode {
153 struct msm_cpr_osc ring_osc_data[NUM_OSC];
154 int ring_osc;
155 int32_t tgt_volt_offset;
156 uint32_t step_quot;
157 uint32_t Vmax;
158 uint32_t Vmin;
159 uint32_t calibrated_mV;
160};
161
162/**
163 * struct msm_cpr_config - Platform data for CPR configuration
164 * @ref_clk_khz: clock value of CPR in KHz
165 * @delay_us: timer delay in micro second
166 * @irq_line: irq line to be use (0 or 1 or 2)
167 * @msm_cpr_mode: structure for CPR mode data
168 */
169struct msm_cpr_config {
170 unsigned long ref_clk_khz;
171 unsigned long delay_us;
172 int irq_line;
173 struct msm_cpr_mode *cpr_mode_data;
174 int min_down_step;
175 uint32_t tgt_count_div_N; /* Target Cnt(Nom) = Target Cnt(Turbo) / N */
176 uint32_t floor;
177 uint32_t ceiling;
178 uint32_t sw_vlevel;
179 uint32_t up_threshold;
180 uint32_t dn_threshold;
181 uint32_t up_margin;
182 uint32_t dn_margin;
183 uint32_t nom_freq_limit;
184 struct msm_cpr_vp_data *vp_data;
185};
186
187/**
188* struct msm_cpr_config - CPR Registers
189*/
190struct msm_cpr_reg {
191 uint32_t rbif_timer_interval;
192 uint32_t rbif_int_en;
193 uint32_t rbif_limit;
194 uint32_t rbif_timer_adjust;
195 uint32_t rbcpr_gcnt_target;
196 uint32_t rbcpr_step_quot;
197 uint32_t rbif_sw_level;
198 uint32_t rbcpr_ctl;
199};
200
201#if defined(CONFIG_MSM_CPR) || defined(CONFIG_MSM_CPR_MODULE)
202/* msm_cpr_pm_resume: Used by Power Manager for Idle Power Collapse */
203void msm_cpr_pm_resume(void);
204/* msm_cpr_pm_suspend: Used by Power Manager for Idle Power Collapse */
205void msm_cpr_pm_suspend(void);
206/* msm_cpr_enable: Used by Power Manager for GDFS */
207void msm_cpr_enable(void);
208/* msm_cpr_disable: Used by Power Manager for GDFS */
209void msm_cpr_disable(void);
210#else
211/* msm_cpr_pm_resume: Used by Power Manager for Idle Power Collapse */
212void msm_cpr_pm_resume(void) { }
213/* msm_cpr_pm_suspend: Used by Power Manager for Idle Power Collapse */
214void msm_cpr_pm_suspend(void) { }
215/* msm_cpr_enable: Used by Power Manager for GDFS */
216void msm_cpr_enable(void) { }
217/* msm_cpr_disable: Used by Power Manager for GDFS */
218void msm_cpr_disable(void) { }
219#endif
220
221#ifdef CONFIG_DEBUG_FS
222int msm_cpr_debug_init(void *);
223#else
224static inline int msm_cpr_debug_init(void *) { return 0; }
225#endif
226#endif /* __ARCH_ARM_MACH_MSM_CPR_H */