blob: 0a180fb5689e85888e2bf0bad9945d43d1722bac [file] [log] [blame]
Priyanka Mathurf198a162012-12-05 19:05:00 -08001/* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 */
13
14#ifndef __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H
15#define __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H
16
17#include <mach/rpm.h>
Priyanka Mathurf198a162012-12-05 19:05:00 -080018#include <linux/notifier.h>
Matt Wagantall7cca4642012-02-01 16:43:24 -080019#include "pm.h"
Priyanka Mathurf198a162012-12-05 19:05:00 -080020#include "test-lpm.h"
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021
Praveen Chidambaram78499012011-11-01 17:15:17 -060022enum {
23 MSM_RPMRS_ID_PXO_CLK = 0,
24 MSM_RPMRS_ID_L2_CACHE_CTL = 1,
25 MSM_RPMRS_ID_VDD_DIG_0 = 2,
26 MSM_RPMRS_ID_VDD_DIG_1 = 3,
27 MSM_RPMRS_ID_VDD_MEM_0 = 4,
28 MSM_RPMRS_ID_VDD_MEM_1 = 5,
29 MSM_RPMRS_ID_RPM_CTL = 6,
30 MSM_RPMRS_ID_LAST,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031};
32
33enum {
34 MSM_RPMRS_PXO_OFF = 0,
35 MSM_RPMRS_PXO_ON = 1,
36};
37
38enum {
39 MSM_RPMRS_L2_CACHE_HSFS_OPEN = 0,
40 MSM_RPMRS_L2_CACHE_GDHS = 1,
41 MSM_RPMRS_L2_CACHE_RETENTION = 2,
42 MSM_RPMRS_L2_CACHE_ACTIVE = 3,
43};
44
Praveen Chidambaram9dfa8712011-09-14 16:25:01 -060045enum {
46 MSM_RPMRS_MASK_RPM_CTL_CPU_HALT = 1,
47 MSM_RPMRS_MASK_RPM_CTL_MULTI_TIER = 2,
48};
49
Praveen Chidambaram78499012011-11-01 17:15:17 -060050enum {
51 MSM_RPMRS_VDD_MEM_RET_LOW = 0,
52 MSM_RPMRS_VDD_MEM_RET_HIGH = 1,
53 MSM_RPMRS_VDD_MEM_ACTIVE = 2,
54 MSM_RPMRS_VDD_MEM_MAX = 3,
55 MSM_RPMRS_VDD_MEM_LAST,
56};
57
58enum {
59 MSM_RPMRS_VDD_DIG_RET_LOW = 0,
60 MSM_RPMRS_VDD_DIG_RET_HIGH = 1,
61 MSM_RPMRS_VDD_DIG_ACTIVE = 2,
62 MSM_RPMRS_VDD_DIG_MAX = 3,
63 MSM_RPMRS_VDD_DIG_LAST,
64};
65
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066#define MSM_RPMRS_LIMITS(_pxo, _l2, _vdd_upper_b, _vdd) { \
67 MSM_RPMRS_PXO_##_pxo, \
68 MSM_RPMRS_L2_CACHE_##_l2, \
69 MSM_RPMRS_VDD_MEM_##_vdd_upper_b, \
70 MSM_RPMRS_VDD_MEM_##_vdd, \
71 MSM_RPMRS_VDD_DIG_##_vdd_upper_b, \
72 MSM_RPMRS_VDD_DIG_##_vdd, \
73 {0}, {0}, \
74}
75
Praveen Chidambaram78499012011-11-01 17:15:17 -060076struct msm_rpmrs_limits {
77 uint32_t pxo;
78 uint32_t l2_cache;
79 uint32_t vdd_mem_upper_bound;
80 uint32_t vdd_mem;
81 uint32_t vdd_dig_upper_bound;
82 uint32_t vdd_dig;
83
84 uint32_t latency_us[NR_CPUS];
85 uint32_t power[NR_CPUS];
86};
87
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088struct msm_rpmrs_level {
89 enum msm_pm_sleep_mode sleep_mode;
90 struct msm_rpmrs_limits rs_limits;
91 bool available;
92 uint32_t latency_us;
93 uint32_t steady_state_power;
94 uint32_t energy_overhead;
95 uint32_t time_overhead_us;
96};
97
Praveen Chidambaram78499012011-11-01 17:15:17 -060098struct msm_rpmrs_platform_data {
99 struct msm_rpmrs_level *levels;
100 unsigned int num_levels;
101 unsigned int vdd_mem_levels[MSM_RPMRS_VDD_MEM_LAST];
102 unsigned int vdd_dig_levels[MSM_RPMRS_VDD_DIG_LAST];
103 unsigned int vdd_mask;
104 unsigned int rpmrs_target_id[MSM_RPMRS_ID_LAST];
105};
106
Priyanka Mathurf198a162012-12-05 19:05:00 -0800107enum {
108 MSM_LPM_STATE_ENTER = 0,
109 MSM_LPM_STATE_EXIT = 1,
110};
111
112/**
113 * struct msm_lpm_sleep_data - abstraction to get sleep data
114 * @limits: pointer to the msm_rpmrs_limits structure
115 * @kernel_sleep: kernel sleep time as decided by the power calculation
116 * algorithm
117 *
118 * This structure is an abstraction to get the limits and kernel sleep time
119 * during enter sleep.
120 */
121
122struct msm_lpm_sleep_data {
123 struct msm_rpmrs_limits *limits;
124 uint32_t kernel_sleep;
125};
126
127#define MSM_PM(field) MSM_RPMRS_##field
128
129/**
130 * msm_pm_get_pxo() - get the limits for pxo
131 * @limits: pointer to the msm_rpmrs_limits structure
132 *
133 * This function gets the limits to the resource pxo on
134 * 8960
135 */
136
137uint32_t msm_pm_get_pxo(struct msm_rpmrs_limits *limits);
138
139/**
140 * msm_pm_get_l2_cache() - get the limits for l2 cache
141 * @limits: pointer to the msm_rpmrs_limits structure
142 *
143 * This function gets the limits to the resource l2 cache
144 * on 8960
145 */
146
147uint32_t msm_pm_get_l2_cache(struct msm_rpmrs_limits *limits);
148
149/**
150 * msm_pm_get_vdd_mem() - get the limits for pxo
151 * @limits: pointer to the msm_rpmrs_limits structure
152 *
153 * This function gets the limits to the resource vdd mem
154 * on 8960
155 */
156
157uint32_t msm_pm_get_vdd_mem(struct msm_rpmrs_limits *limits);
158
159/**
160 * msm_pm_get_vdd_dig() - get the limits for vdd dig
161 * @limits: pointer to the msm_rpmrs_limits structure
162 *
163 * This function gets the limits to the resource vdd dig
164 * on 8960
165 */
166
167uint32_t msm_pm_get_vdd_dig(struct msm_rpmrs_limits *limits);
168
169/**
170 * msm_lpm_register_notifier() - register for notifications
171 * @cpu: cpu to debug
172 * @level_iter: low power level index to debug
173 * @nb: notifier block to callback on notifications
174 * @is_latency_measure: is it latency measure
175 *
176 * This function sets the permitted level to the index of the
177 * level under test and registers notifier for callback.
178 */
179
180int msm_lpm_register_notifier(int cpu, int level_iter,
181 struct notifier_block *nb, bool is_latency_measure);
182
183/**
184 * msm_lpm_unregister_notifier() - unregister from notifications
185 * @cpu: cpu to debug
186 * @nb: notifier block to callback on notifications
187 *
188 * This function sets the permitted level to a value one more than
189 * available levels count which indicates that all levels are
190 * permitted and it also unregisters notifier for callback.
191 */
192
193int msm_lpm_unregister_notifier(int cpu, struct notifier_block *nb);
194
Vikram Mulukutlabe97fbe2012-05-16 21:36:33 -0700195#if defined(CONFIG_MSM_RPM)
196
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700197int msm_rpmrs_set(int ctx, struct msm_rpm_iv_pair *req, int count);
198int msm_rpmrs_set_noirq(int ctx, struct msm_rpm_iv_pair *req, int count);
Praveen Chidambaram9dfa8712011-09-14 16:25:01 -0600199int msm_rpmrs_set_bits_noirq(int ctx, struct msm_rpm_iv_pair *req, int count,
200 int *mask);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201
202static inline int msm_rpmrs_set_nosleep(
203 int ctx, struct msm_rpm_iv_pair *req, int count)
204{
205 unsigned long flags;
206 int rc;
207
208 local_irq_save(flags);
209 rc = msm_rpmrs_set_noirq(ctx, req, count);
210 local_irq_restore(flags);
211
212 return rc;
213}
214
215int msm_rpmrs_clear(int ctx, struct msm_rpm_iv_pair *req, int count);
216int msm_rpmrs_clear_noirq(int ctx, struct msm_rpm_iv_pair *req, int count);
217
218static inline int msm_rpmrs_clear_nosleep(
219 int ctx, struct msm_rpm_iv_pair *req, int count)
220{
221 unsigned long flags;
222 int rc;
223
224 local_irq_save(flags);
225 rc = msm_rpmrs_clear_noirq(ctx, req, count);
226 local_irq_restore(flags);
227
228 return rc;
229}
230
231void msm_rpmrs_show_resources(void);
Praveen Chidambaram78499012011-11-01 17:15:17 -0600232int msm_rpmrs_levels_init(struct msm_rpmrs_platform_data *data);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700233
Vikram Mulukutlabe97fbe2012-05-16 21:36:33 -0700234#else
235
236static inline int msm_rpmrs_set(int ctx, struct msm_rpm_iv_pair *req,
237 int count)
238{
239 return -ENODEV;
240}
241
242static inline int msm_rpmrs_set_noirq(int ctx, struct msm_rpm_iv_pair *req,
243 int count)
244{
245 return -ENODEV;
246}
247
248static inline int msm_rpmrs_set_bits_noirq(int ctx, struct msm_rpm_iv_pair *req,
249 int count, int *mask)
250{
251 return -ENODEV;
252}
253
254static inline int msm_rpmrs_set_nosleep(
255 int ctx, struct msm_rpm_iv_pair *req, int count)
256{
257 return -ENODEV;
258}
259
260static inline int msm_rpmrs_clear(int ctx, struct msm_rpm_iv_pair *req,
261 int count)
262{
263 return -ENODEV;
264}
265
266static inline int msm_rpmrs_clear_noirq(int ctx, struct msm_rpm_iv_pair *req,
267 int count)
268{
269 return -ENODEV;
270}
271
272static inline int msm_rpmrs_clear_nosleep(
273 int ctx, struct msm_rpm_iv_pair *req, int count)
274{
275 return -ENODEV;
276}
277
278static inline struct msm_rpmrs_limits *msm_rpmrs_lowest_limits(
279 bool from_idle, enum msm_pm_sleep_mode sleep_mode, uint32_t latency_us,
280 uint32_t sleep_us)
281{
282 return NULL;
283}
284
285static inline int msm_rpmrs_enter_sleep(uint32_t sclk_count,
286 struct msm_rpmrs_limits *limits, bool from_idle, bool notify_rpm)
287{
288 return -ENODEV;
289}
290
291static inline void msm_rpmrs_exit_sleep(struct msm_rpmrs_limits *limits,
292 bool from_idle, bool notify_rpm, bool collapsed)
293{
294 return;
295}
296
297static inline int msm_rpmrs_levels_init(struct msm_rpmrs_platform_data *data)
298{
299 return -ENODEV;
300}
301
302#endif /* CONFIG_MSM_RPM */
303
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700304#endif /* __ARCH_ARM_MACH_MSM_RPM_RESOURCES_H */