blob: 105cfe63aebca346df4b53c08d8fb3b654dbc51d [file] [log] [blame]
Priyanka Mathur3abfd442013-01-11 12:58:51 -08001/* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
Girish Mahadevan40abbe12012-04-25 14:58:13 -06002 *
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.
Girish Mahadevan40abbe12012-04-25 14:58:13 -060011 */
12
13#ifndef __ARCH_ARM_MACH_MSM_LPM_RESOURCES_H
14#define __ARCH_ARM_MACH_MSM_LPM_RESOURCES_H
15
16#include "pm.h"
Priyanka Mathur3abfd442013-01-11 12:58:51 -080017#include "test-lpm.h"
Girish Mahadevan40abbe12012-04-25 14:58:13 -060018
19enum {
Archana Sathyakumare6a35102013-01-31 16:18:49 -070020 MSM_LPM_PXO_OFF,
21 MSM_LPM_PXO_ON
Girish Mahadevan40abbe12012-04-25 14:58:13 -060022};
23
24enum {
Archana Sathyakumare6a35102013-01-31 16:18:49 -070025 MSM_LPM_L2_CACHE_HSFS_OPEN,
26 MSM_LPM_L2_CACHE_GDHS,
27 MSM_LPM_L2_CACHE_RETENTION,
28 MSM_LPM_L2_CACHE_ACTIVE,
Girish Mahadevan40abbe12012-04-25 14:58:13 -060029};
30
31struct msm_rpmrs_limits {
32 uint32_t pxo;
33 uint32_t l2_cache;
34 uint32_t vdd_mem_upper_bound;
35 uint32_t vdd_mem_lower_bound;
36 uint32_t vdd_dig_upper_bound;
37 uint32_t vdd_dig_lower_bound;
Mahesh Sivasubramanianb71ce092013-01-08 13:44:23 -070038 bool irqs_detectable;
39 bool gpio_detectable;
Girish Mahadevan40abbe12012-04-25 14:58:13 -060040
41 uint32_t latency_us[NR_CPUS];
42 uint32_t power[NR_CPUS];
43};
44
45struct msm_rpmrs_level {
46 enum msm_pm_sleep_mode sleep_mode;
47 struct msm_rpmrs_limits rs_limits;
48 bool available;
49 uint32_t latency_us;
50 uint32_t steady_state_power;
51 uint32_t energy_overhead;
52 uint32_t time_overhead_us;
53};
54
Priyanka Mathur3abfd442013-01-11 12:58:51 -080055enum {
56 MSM_LPM_STATE_ENTER = 0,
57 MSM_LPM_STATE_EXIT = 1,
58};
59
60#define MSM_PM(field) MSM_LPM_##field
61
62/**
63 * msm_pm_get_pxo() - get the limits for pxo
64 * @limits: pointer to the msm_rpmrs_limits structure
65 *
66 * This function gets the limits to the resource pxo on
67 * 8974
68 */
69
70uint32_t msm_pm_get_pxo(struct msm_rpmrs_limits *limits);
71
72/**
73 * msm_pm_get_l2_cache() - get the limits for l2 cache
74 * @limits: pointer to the msm_rpmrs_limits structure
75 *
76 * This function gets the limits to the resource l2 cache
77 * on 8974
78 */
79
80uint32_t msm_pm_get_l2_cache(struct msm_rpmrs_limits *limits);
81
82/**
83 * msm_pm_get_vdd_mem() - get the limits for pxo
84 * @limits: pointer to the msm_rpmrs_limits structure
85 *
86 * This function gets the limits to the resource vdd mem
87 * on 8974
88 */
89
90uint32_t msm_pm_get_vdd_mem(struct msm_rpmrs_limits *limits);
91
92/**
93 * msm_pm_get_vdd_dig() - get the limits for vdd dig
94 * @limits: pointer to the msm_rpmrs_limits structure
95 *
96 * This function gets the limits to the resource on 8974
97 */
98
99uint32_t msm_pm_get_vdd_dig(struct msm_rpmrs_limits *limits);
100
101/**
Archana Sathyakumare6a35102013-01-31 16:18:49 -0700102 * msm_lpm_get_xo_value() - get the enum value for xo
103 * @node pointer to the device node
104 * @key pxo property key
105 * @xo_val xo enum value
106 */
107int msm_lpm_get_xo_value(struct device_node *node,
108 char *key, uint32_t *xo_val);
109
110/**
111 * msm_lpm_get_l2_cache_value() - get the enum value for l2 cache
112 * @node pointer to the device node
113 * @key l2 cache property key
114 * @l2_val l2 mode enum value
115 */
116int msm_lpm_get_l2_cache_value(struct device_node *node,
117 char *key, uint32_t *l2_val);
118
119/**
Priyanka Mathur3abfd442013-01-11 12:58:51 -0800120 * struct msm_lpm_sleep_data - abstraction to get sleep data
121 * @limits: pointer to the msm_rpmrs_limits structure
122 * @kernel_sleep: kernel sleep time as decided by the power calculation
123 * algorithm
124 *
125 * This structure is an abstraction to get the limits and kernel sleep time
126 * during enter sleep.
127 */
128
129struct msm_lpm_sleep_data {
130 struct msm_rpmrs_limits *limits;
131 uint32_t kernel_sleep;
132};
133
134/**
135 * msm_lpm_register_notifier() - register for notifications
136 * @cpu: cpu to debug
137 * @level_iter: low power level index to debug
138 * @nb: notifier block to callback on notifications
139 * @is_latency_measure: is it latency measure
140 *
141 * This function sets the permitted level to the index of the
142 * level under test and registers notifier for callback.
143 */
144
145int msm_lpm_register_notifier(int cpu, int level_iter,
146 struct notifier_block *nb, bool is_latency_measure);
147
148/**
149 * msm_lpm_unregister_notifier() - unregister from notifications
150 * @cpu: cpu to debug
151 * @nb: notifier block to callback on notifications
152 *
153 * This function sets the permitted level to a value one more than
154 * available levels count which indicates that all levels are
155 * permitted and it also unregisters notifier for callback.
156 */
157
158int msm_lpm_unregister_notifier(int cpu, struct notifier_block *nb);
159
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600160#ifdef CONFIG_MSM_RPM_SMD
161
162/**
163 * msm_lpm_level_beyond_limit() - Check if the resources in a low power level
164 * is beyond the limits of the driver votes received for those resources.This
165 * function is used by lpm_levels to eliminate any low power level that cannot
166 * be entered.
167 *
168 * @limits: pointer to the resource limits of a low power level.
169 *
170 * returns true if the resource limits are beyond driver resource votes.
171 * false otherwise.
172 */
173bool msm_lpm_level_beyond_limit(struct msm_rpmrs_limits *limits);
174
175/**
176 * msm_lpmrs_enter_sleep() - Enter sleep flushes the sleep votes of low power
177 * resources to the RPM driver, also configure the MPM if needed depending
178 * on the low power mode being entered. L2 low power mode is also set in
179 * this function.
180
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600181 * @sclk_count: wakeup counter for RPM.
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600182 * @limits: pointer to the resource limits of the low power mode being entered.
183 * @from_idle: bool to determine if this call being made as a part of
184 * idle power collapse.
185 * @notify_rpm: bool that informs if this is an RPM notified power collapse.
186 *
187 * returns 0 on success.
188 */
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600189int msm_lpmrs_enter_sleep(uint32_t sclk_count, struct msm_rpmrs_limits *limits,
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600190 bool from_idle, bool notify_rpm);
191
192/**
193 * msm_lpmrs_exit_sleep() - Exit sleep, reset the MPM and L2 mode.
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600194 * @ limits: pointer to resource limits of the most recent low power mode.
195 * @from_idle: bool to determine if this call being made as a part of
196 * idle power collapse.
197 * @notify_rpm: bool that informs if this is an RPM notified power collapse.
Girish Mahadevana9964a52012-06-29 10:14:09 -0600198 * @collapsed: bool that informs if the Krait was power collapsed.
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600199 */
Girish Mahadevana9964a52012-06-29 10:14:09 -0600200void msm_lpmrs_exit_sleep(struct msm_rpmrs_limits *limits,
201 bool from_idle, bool notify_rpm, bool collapsed);
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600202/**
203 * msm_lpmrs_module_init() - Init function that parses the device tree to
204 * get the low power resource attributes and registers with RPM driver for
205 * callback notification.
206 *
207 * returns 0 on success.
208 */
209int __init msm_lpmrs_module_init(void);
210
211#else
212static inline bool msm_lpm_level_beyond_limit(struct msm_rpmrs_limits *limits)
213{
214 return true;
215}
216
Mahesh Sivasubramanian2efbc352012-07-18 14:15:44 -0600217static inline int msm_lpmrs_enter_sleep(uint32_t sclk_count,
218 struct msm_rpmrs_limits *limits, bool from_idle, bool notify_rpm)
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600219{
220 return 0;
221}
222
Girish Mahadevana9964a52012-06-29 10:14:09 -0600223static inline void msm_lpmrs_exit_sleep(struct msm_rpmrs_limits *limits,
224 bool from_idle, bool notify_rpm, bool collapsed)
Girish Mahadevan40abbe12012-04-25 14:58:13 -0600225{
226 return;
227}
228
229static inline int __init msm_lpmrs_module_init(void)
230{
231 return 0;
232}
233#endif /* CONFIG_MSM_RPM_SMD */
234
235#endif