tizen 2.4 release
[kernel/linux-3.0.git] / drivers / gpu / arm / mali400 / r4p0_rel0 / linux / mali_osk_pm.c
1 /**
2  * Copyright (C) 2010-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 /**
12  * @file mali_osk_pm.c
13  * Implementation of the callback functions from common power management
14  */
15
16 #include <linux/sched.h>
17
18 #ifdef CONFIG_PM_RUNTIME
19 #include <linux/pm_runtime.h>
20 #endif /* CONFIG_PM_RUNTIME */
21 #include <linux/platform_device.h>
22 #include <linux/version.h>
23 #include "mali_osk.h"
24 #include "mali_kernel_common.h"
25 #include "mali_kernel_linux.h"
26
27 static _mali_osk_atomic_t mali_pm_ref_count;
28
29 void _mali_osk_pm_dev_enable(void)
30 {
31         _mali_osk_atomic_init(&mali_pm_ref_count, 0);
32 }
33
34 void _mali_osk_pm_dev_disable(void)
35 {
36         _mali_osk_atomic_term(&mali_pm_ref_count);
37 }
38
39 /* Can NOT run in atomic context */
40 _mali_osk_errcode_t _mali_osk_pm_dev_ref_add(void)
41 {
42 #ifdef CONFIG_PM_RUNTIME
43         int err;
44         MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
45         err = pm_runtime_get_sync(&(mali_platform_device->dev));
46 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
47         pm_runtime_mark_last_busy(&(mali_platform_device->dev));
48 #endif
49         if (0 > err) {
50                 MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get_sync() returned error code %d\n", err));
51                 return _MALI_OSK_ERR_FAULT;
52         }
53         _mali_osk_atomic_inc(&mali_pm_ref_count);
54         MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
55 #endif
56         return _MALI_OSK_ERR_OK;
57 }
58
59 /* Can run in atomic context */
60 void _mali_osk_pm_dev_ref_dec(void)
61 {
62 #ifdef CONFIG_PM_RUNTIME
63         MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
64         _mali_osk_atomic_dec(&mali_pm_ref_count);
65 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
66         pm_runtime_mark_last_busy(&(mali_platform_device->dev));
67         pm_runtime_put_autosuspend(&(mali_platform_device->dev));
68 #else
69         pm_runtime_put(&(mali_platform_device->dev));
70 #endif
71         MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
72 #endif
73 }
74
75 /* Can run in atomic context */
76 mali_bool _mali_osk_pm_dev_ref_add_no_power_on(void)
77 {
78 #ifdef CONFIG_PM_RUNTIME
79         u32 ref;
80         MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
81         pm_runtime_get_noresume(&(mali_platform_device->dev));
82         ref = _mali_osk_atomic_read(&mali_pm_ref_count);
83         MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
84         return ref > 0 ? MALI_TRUE : MALI_FALSE;
85 #else
86         return MALI_TRUE;
87 #endif
88 }
89
90 /* Can run in atomic context */
91 void _mali_osk_pm_dev_ref_dec_no_power_on(void)
92 {
93 #ifdef CONFIG_PM_RUNTIME
94         MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
95 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
96         pm_runtime_put_autosuspend(&(mali_platform_device->dev));
97 #else
98         pm_runtime_put(&(mali_platform_device->dev));
99 #endif
100         MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
101 #endif
102 }
103
104 void _mali_osk_pm_dev_barrier(void)
105 {
106 #ifdef CONFIG_PM_RUNTIME
107         pm_runtime_barrier(&(mali_platform_device->dev));
108 #endif
109 }