tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / mali / 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
20 static mali_bool mali_power_on = MALI_FALSE;
21
22 _mali_osk_errcode_t mali_pm_initialize(void)
23 {
24         _mali_osk_pm_dev_enable();
25         return _MALI_OSK_ERR_OK;
26 }
27
28 void mali_pm_terminate(void)
29 {
30         _mali_osk_pm_dev_disable();
31 }
32
33 void mali_pm_core_event(enum mali_core_event core_event)
34 {
35         MALI_DEBUG_ASSERT(MALI_CORE_EVENT_GP_START == core_event ||
36                           MALI_CORE_EVENT_PP_START == core_event ||
37                           MALI_CORE_EVENT_GP_STOP  == core_event ||
38                           MALI_CORE_EVENT_PP_STOP  == core_event);
39
40         if (MALI_CORE_EVENT_GP_START == core_event || MALI_CORE_EVENT_PP_START == core_event)
41         {
42                 _mali_osk_pm_dev_ref_add();
43                 if (mali_utilization_enabled())
44                 {
45                         mali_utilization_core_start(_mali_osk_time_get_ns());
46                 }
47         }
48         else
49         {
50                 _mali_osk_pm_dev_ref_dec();
51                 if (mali_utilization_enabled())
52                 {
53                         mali_utilization_core_end(_mali_osk_time_get_ns());
54                 }
55         }
56 }
57
58 /* Reset GPU after power up */
59 static void mali_pm_reset_gpu(void)
60 {
61         /* Reset all L2 caches */
62         mali_l2_cache_reset_all();
63
64         /* Reset all groups */
65         mali_scheduler_reset_all_groups();
66 }
67
68 void mali_pm_os_suspend(void)
69 {
70         MALI_DEBUG_PRINT(3, ("Mali PM: OS suspend\n"));
71         mali_gp_scheduler_suspend();
72         mali_pp_scheduler_suspend();
73         mali_group_power_off();
74         mali_power_on = MALI_FALSE;
75 }
76
77 void mali_pm_os_resume(void)
78 {
79         MALI_DEBUG_PRINT(3, ("Mali PM: OS resume\n"));
80         if (MALI_TRUE != mali_power_on)
81         {
82                 mali_pm_reset_gpu();
83                 mali_group_power_on();
84         }
85         mali_gp_scheduler_resume();
86         mali_pp_scheduler_resume();
87         mali_power_on = MALI_TRUE;
88 }
89
90 void mali_pm_runtime_suspend(void)
91 {
92         MALI_DEBUG_PRINT(3, ("Mali PM: Runtime suspend\n"));
93         mali_group_power_off();
94         mali_power_on = MALI_FALSE;
95 }
96
97 void mali_pm_runtime_resume(void)
98 {
99         MALI_DEBUG_PRINT(3, ("Mali PM: Runtime resume\n"));
100         if (MALI_TRUE != mali_power_on)
101         {
102                 mali_pm_reset_gpu();
103                 mali_group_power_on();
104         }
105         mali_power_on = MALI_TRUE;
106 }