2 * Copyright (C) 2011-2012 ARM Limited. All rights reserved.
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.
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.
13 * Implementation of the callback functions from common power management
16 #include <linux/sched.h>
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>
24 #include "mali_kernel_common.h"
25 #include "mali_kernel_linux.h"
27 static _mali_osk_atomic_t mali_pm_ref_count;
29 void _mali_osk_pm_dev_enable(void) /* @@@@ todo: change to init of some kind.. or change the way or where atomics are initialized? */
31 _mali_osk_atomic_init(&mali_pm_ref_count, 0);
34 void _mali_osk_pm_dev_disable(void) /* @@@@ todo: change to term of some kind */
36 _mali_osk_atomic_term(&mali_pm_ref_count);
39 /* Can NOT run in atomic context */
40 _mali_osk_errcode_t _mali_osk_pm_dev_ref_add(void)
42 #ifdef CONFIG_PM_RUNTIME
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));
51 MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get_sync() returned error code %d\n", err));
52 return _MALI_OSK_ERR_FAULT;
54 _mali_osk_atomic_inc(&mali_pm_ref_count);
55 MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
57 return _MALI_OSK_ERR_OK;
60 /* Can run in atomic context */
61 void _mali_osk_pm_dev_ref_dec(void)
63 #ifdef CONFIG_PM_RUNTIME
64 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
65 _mali_osk_atomic_dec(&mali_pm_ref_count);
66 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
67 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
68 pm_runtime_put_autosuspend(&(mali_platform_device->dev));
70 pm_runtime_put(&(mali_platform_device->dev));
72 MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
76 /* Can run in atomic context */
77 mali_bool _mali_osk_pm_dev_ref_add_no_power_on(void)
79 #ifdef CONFIG_PM_RUNTIME
81 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
82 pm_runtime_get_noresume(&(mali_platform_device->dev));
83 ref = _mali_osk_atomic_read(&mali_pm_ref_count);
84 MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
85 return ref > 0 ? MALI_TRUE : MALI_FALSE;
91 /* Can run in atomic context */
92 void _mali_osk_pm_dev_ref_dec_no_power_on(void)
94 #ifdef CONFIG_PM_RUNTIME
95 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
96 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
97 pm_runtime_put_autosuspend(&(mali_platform_device->dev));
99 pm_runtime_put(&(mali_platform_device->dev));
101 MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));