af58daddcf500595857ca01f08e2b4ae3561655b
[pandora-kernel.git] / arch / arm / plat-omap / omap-pm-noop.c
1 /*
2  * omap-pm-noop.c - OMAP power management interface - dummy version
3  *
4  * This code implements the OMAP power management interface to
5  * drivers, CPUIdle, CPUFreq, and DSP Bridge.  It is strictly for
6  * debug/demonstration use, as it does nothing but printk() whenever a
7  * function is called (when DEBUG is defined, below)
8  *
9  * Copyright (C) 2008-2009 Texas Instruments, Inc.
10  * Copyright (C) 2008-2009 Nokia Corporation
11  * Paul Walmsley
12  *
13  * Interface developed by (in alphabetical order):
14  * Karthik Dasu, Tony Lindgren, Rajendra Nayak, Sakari Poussa, Veeramanikandan
15  * Raju, Anand Sawant, Igor Stoppa, Paul Walmsley, Richard Woodruff
16  */
17
18 #undef DEBUG
19
20 #include <linux/init.h>
21 #include <linux/cpufreq.h>
22 #include <linux/device.h>
23 #include <linux/platform_device.h>
24
25 /* Interface documentation is in mach/omap-pm.h */
26 #include <plat/omap-pm.h>
27 #include <plat/omap_device.h>
28
29 /*
30  * Device-driver-originated constraints (via board-*.c files)
31  */
32
33 int omap_pm_set_max_mpu_wakeup_lat(struct device *dev, long t)
34 {
35         if (!dev || t < -1) {
36                 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
37                 return -EINVAL;
38         };
39
40         if (t == -1)
41                 pr_debug("OMAP PM: remove max MPU wakeup latency constraint: "
42                          "dev %s\n", dev_name(dev));
43         else
44                 pr_debug("OMAP PM: add max MPU wakeup latency constraint: "
45                          "dev %s, t = %ld usec\n", dev_name(dev), t);
46
47         /*
48          * For current Linux, this needs to map the MPU to a
49          * powerdomain, then go through the list of current max lat
50          * constraints on the MPU and find the smallest.  If
51          * the latency constraint has changed, the code should
52          * recompute the state to enter for the next powerdomain
53          * state.
54          *
55          * TI CDP code can call constraint_set here.
56          */
57
58         return 0;
59 }
60
61 int omap_pm_set_min_bus_tput(struct device *dev, u8 agent_id, unsigned long r)
62 {
63         if (!dev || (agent_id != OCP_INITIATOR_AGENT &&
64             agent_id != OCP_TARGET_AGENT)) {
65                 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
66                 return -EINVAL;
67         };
68
69         if (r == 0)
70                 pr_debug("OMAP PM: remove min bus tput constraint: "
71                          "dev %s for agent_id %d\n", dev_name(dev), agent_id);
72         else
73                 pr_debug("OMAP PM: add min bus tput constraint: "
74                          "dev %s for agent_id %d: rate %ld KiB\n",
75                          dev_name(dev), agent_id, r);
76
77         /*
78          * This code should model the interconnect and compute the
79          * required clock frequency, convert that to a VDD2 OPP ID, then
80          * set the VDD2 OPP appropriately.
81          *
82          * TI CDP code can call constraint_set here on the VDD2 OPP.
83          */
84
85         return 0;
86 }
87
88 int omap_pm_set_max_dev_wakeup_lat(struct device *req_dev, struct device *dev,
89                                    long t)
90 {
91         if (!req_dev || !dev || t < -1) {
92                 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
93                 return -EINVAL;
94         };
95
96         if (t == -1)
97                 pr_debug("OMAP PM: remove max device latency constraint: "
98                          "dev %s\n", dev_name(dev));
99         else
100                 pr_debug("OMAP PM: add max device latency constraint: "
101                          "dev %s, t = %ld usec\n", dev_name(dev), t);
102
103         /*
104          * For current Linux, this needs to map the device to a
105          * powerdomain, then go through the list of current max lat
106          * constraints on that powerdomain and find the smallest.  If
107          * the latency constraint has changed, the code should
108          * recompute the state to enter for the next powerdomain
109          * state.  Conceivably, this code should also determine
110          * whether to actually disable the device clocks or not,
111          * depending on how long it takes to re-enable the clocks.
112          *
113          * TI CDP code can call constraint_set here.
114          */
115
116         return 0;
117 }
118
119 int omap_pm_set_max_sdma_lat(struct device *dev, long t)
120 {
121         if (!dev || t < -1) {
122                 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
123                 return -EINVAL;
124         };
125
126         if (t == -1)
127                 pr_debug("OMAP PM: remove max DMA latency constraint: "
128                          "dev %s\n", dev_name(dev));
129         else
130                 pr_debug("OMAP PM: add max DMA latency constraint: "
131                          "dev %s, t = %ld usec\n", dev_name(dev), t);
132
133         /*
134          * For current Linux PM QOS params, this code should scan the
135          * list of maximum CPU and DMA latencies and select the
136          * smallest, then set cpu_dma_latency pm_qos_param
137          * accordingly.
138          *
139          * For future Linux PM QOS params, with separate CPU and DMA
140          * latency params, this code should just set the dma_latency param.
141          *
142          * TI CDP code can call constraint_set here.
143          */
144
145         return 0;
146 }
147
148 int omap_pm_set_min_clk_rate(struct device *dev, struct clk *c, long r)
149 {
150         if (!dev || !c || r < 0) {
151                 WARN(1, "OMAP PM: %s: invalid parameter(s)", __func__);
152                 return -EINVAL;
153         }
154
155         if (r == 0)
156                 pr_debug("OMAP PM: remove min clk rate constraint: "
157                          "dev %s\n", dev_name(dev));
158         else
159                 pr_debug("OMAP PM: add min clk rate constraint: "
160                          "dev %s, rate = %ld Hz\n", dev_name(dev), r);
161
162         /*
163          * Code in a real implementation should keep track of these
164          * constraints on the clock, and determine the highest minimum
165          * clock rate.  It should iterate over each OPP and determine
166          * whether the OPP will result in a clock rate that would
167          * satisfy this constraint (and any other PM constraint in effect
168          * at that time).  Once it finds the lowest-voltage OPP that
169          * meets those conditions, it should switch to it, or return
170          * an error if the code is not capable of doing so.
171          */
172
173         return 0;
174 }
175
176 /*
177  * DSP Bridge-specific constraints
178  */
179
180 const struct omap_opp *omap_pm_dsp_get_opp_table(void)
181 {
182         pr_debug("OMAP PM: DSP request for OPP table\n");
183
184         /*
185          * Return DSP frequency table here:  The final item in the
186          * array should have .rate = .opp_id = 0.
187          */
188
189         return NULL;
190 }
191
192 void omap_pm_dsp_set_min_opp(u8 opp_id)
193 {
194         if (opp_id == 0) {
195                 WARN_ON(1);
196                 return;
197         }
198
199         pr_debug("OMAP PM: DSP requests minimum VDD1 OPP to be %d\n", opp_id);
200
201         /*
202          *
203          * For l-o dev tree, our VDD1 clk is keyed on OPP ID, so we
204          * can just test to see which is higher, the CPU's desired OPP
205          * ID or the DSP's desired OPP ID, and use whichever is
206          * highest.
207          *
208          * In CDP12.14+, the VDD1 OPP custom clock that controls the DSP
209          * rate is keyed on MPU speed, not the OPP ID.  So we need to
210          * map the OPP ID to the MPU speed for use with clk_set_rate()
211          * if it is higher than the current OPP clock rate.
212          *
213          */
214 }
215
216
217 u8 omap_pm_dsp_get_opp(void)
218 {
219         pr_debug("OMAP PM: DSP requests current DSP OPP ID\n");
220
221         /*
222          * For l-o dev tree, call clk_get_rate() on VDD1 OPP clock
223          *
224          * CDP12.14+:
225          * Call clk_get_rate() on the OPP custom clock, map that to an
226          * OPP ID using the tables defined in board-*.c/chip-*.c files.
227          */
228
229         return 0;
230 }
231
232 /*
233  * CPUFreq-originated constraint
234  *
235  * In the future, this should be handled by custom OPP clocktype
236  * functions.
237  */
238
239 struct cpufreq_frequency_table **omap_pm_cpu_get_freq_table(void)
240 {
241         pr_debug("OMAP PM: CPUFreq request for frequency table\n");
242
243         /*
244          * Return CPUFreq frequency table here: loop over
245          * all VDD1 clkrates, pull out the mpu_ck frequencies, build
246          * table
247          */
248
249         return NULL;
250 }
251
252 void omap_pm_cpu_set_freq(unsigned long f)
253 {
254         if (f == 0) {
255                 WARN_ON(1);
256                 return;
257         }
258
259         pr_debug("OMAP PM: CPUFreq requests CPU frequency to be set to %lu\n",
260                  f);
261
262         /*
263          * For l-o dev tree, determine whether MPU freq or DSP OPP id
264          * freq is higher.  Find the OPP ID corresponding to the
265          * higher frequency.  Call clk_round_rate() and clk_set_rate()
266          * on the OPP custom clock.
267          *
268          * CDP should just be able to set the VDD1 OPP clock rate here.
269          */
270 }
271
272 unsigned long omap_pm_cpu_get_freq(void)
273 {
274         pr_debug("OMAP PM: CPUFreq requests current CPU frequency\n");
275
276         /*
277          * Call clk_get_rate() on the mpu_ck.
278          */
279
280         return 0;
281 }
282
283 /*
284  * Device context loss tracking
285  */
286
287 u32 omap_pm_get_dev_context_loss_count(struct device *dev)
288 {
289         struct platform_device *pdev = to_platform_device(dev);
290         u32 count;
291
292         if (WARN_ON(!dev))
293                 return 0;
294
295         count = omap_device_get_context_loss_count(pdev);
296         pr_debug("OMAP PM: context loss count for dev %s = %d\n",
297                  dev_name(dev), count);
298
299         return count;
300 }
301
302
303 /* Should be called before clk framework init */
304 int __init omap_pm_if_early_init(void)
305 {
306         return 0;
307 }
308
309 /* Must be called after clock framework is initialized */
310 int __init omap_pm_if_init(void)
311 {
312         return 0;
313 }
314
315 void omap_pm_if_exit(void)
316 {
317         /* Deallocate CPUFreq frequency table here */
318 }
319