tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / common / mali_pm.c
1 /*
2  * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
3  * 
4  * This program is free software and is provided to you under the terms of the GNU General Public License version 2
5  * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
6  * 
7  * A copy of the licence is included with the program, and can also be obtained from Free Software
8  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
9  */
10
11 #include "mali_pm.h"
12 #include "mali_kernel_common.h"
13 #include "mali_osk.h"
14 #include "mali_gp_scheduler.h"
15 #include "mali_pp_scheduler.h"
16 #include "mali_scheduler.h"
17 #include "mali_kernel_utilization.h"
18 #include "mali_group.h"
19 #include "mali_pm_domain.h"
20 #include "mali_pmu.h"
21
22 static mali_bool mali_power_on = MALI_FALSE;
23
24 _mali_osk_errcode_t mali_pm_initialize(void)
25 {
26         _mali_osk_pm_dev_enable();
27         return _MALI_OSK_ERR_OK;
28 }
29
30 void mali_pm_terminate(void)
31 {
32         mali_pm_domain_terminate();
33         _mali_osk_pm_dev_disable();
34 }
35
36 /* Reset GPU after power up */
37 static void mali_pm_reset_gpu(void)
38 {
39         /* Reset all L2 caches */
40         mali_l2_cache_reset_all();
41
42         /* Reset all groups */
43         mali_scheduler_reset_all_groups();
44 }
45
46 void mali_pm_os_suspend(void)
47 {
48         MALI_DEBUG_PRINT(3, ("Mali PM: OS suspend\n"));
49         mali_gp_scheduler_suspend();
50         mali_pp_scheduler_suspend();
51         mali_utilization_suspend();
52 /* MALI_SEC */
53 #if !defined(CONFIG_PM_RUNTIME)
54         mali_group_power_off(MALI_TRUE);
55         mali_power_on = MALI_FALSE;
56 #endif
57 }
58
59 void mali_pm_os_resume(void)
60 {
61 #if !defined(CONFIG_PM_RUNTIME)
62         struct mali_pmu_core *pmu = mali_pmu_get_global_pmu_core();
63         mali_bool do_reset = MALI_FALSE;
64 #endif
65
66         MALI_DEBUG_PRINT(3, ("Mali PM: OS resume\n"));
67 /* MALI_SEC */
68 /******************************************************************
69  *
70  * <2013. 08. 23>
71  *  In Pegasus prime, PMU is not enabled(Power off) while
72  * system wake up(suspend -> resume).
73  *
74  * Because PMU power is off, GPU does not work.
75  * Therefore code is commented like below.
76  *
77  *****************************************************************/
78 #if !defined(CONFIG_PM_RUNTIME)
79         if (MALI_TRUE != mali_power_on)
80         {
81                 do_reset = MALI_TRUE;
82         }
83
84         if (NULL != pmu) {
85                 mali_pmu_reset(pmu);
86         }
87
88         mali_power_on = MALI_TRUE;
89         _mali_osk_write_mem_barrier();
90
91         if (do_reset) {
92                 mali_pm_reset_gpu();
93                 mali_group_power_on();
94         }
95 #endif
96         mali_gp_scheduler_resume();
97         mali_pp_scheduler_resume();
98 }
99
100 void mali_pm_runtime_suspend(void)
101 {
102         MALI_DEBUG_PRINT(3, ("Mali PM: Runtime suspend\n"));
103         mali_group_power_off(MALI_TRUE);
104         mali_power_on = MALI_FALSE;
105 }
106
107 void mali_pm_runtime_resume(void)
108 {
109         struct mali_pmu_core *pmu = mali_pmu_get_global_pmu_core();
110         mali_bool do_reset = MALI_FALSE;
111
112         MALI_DEBUG_PRINT(3, ("Mali PM: Runtime resume\n"));
113
114         if (MALI_TRUE != mali_power_on) {
115                 do_reset = MALI_TRUE;
116         }
117
118         if (NULL != pmu) {
119                 mali_pmu_reset(pmu);
120         }
121
122         mali_power_on = MALI_TRUE;
123         _mali_osk_write_mem_barrier();
124
125         if (do_reset) {
126                 mali_pm_reset_gpu();
127                 mali_group_power_on();
128         }
129 }
130
131 void mali_pm_set_power_is_on(void)
132 {
133         mali_power_on = MALI_TRUE;
134 }
135
136 mali_bool mali_pm_is_power_on(void)
137 {
138         return mali_power_on;
139 }