2 * Copyright (C) 2010-2015 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 /* Can NOT run in atomic context */
28 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_sync(void)
30 #ifdef CONFIG_PM_RUNTIME
32 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
33 err = pm_runtime_get_sync(&(mali_platform_device->dev));
34 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
35 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
38 MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get_sync() returned error code %d\n", err));
39 return _MALI_OSK_ERR_FAULT;
42 return _MALI_OSK_ERR_OK;
45 /* Can run in atomic context */
46 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_async(void)
48 #ifdef CONFIG_PM_RUNTIME
50 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
51 err = pm_runtime_get(&(mali_platform_device->dev));
52 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
53 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
55 if (0 > err && -EINPROGRESS != err) {
56 MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get() returned error code %d\n", err));
57 return _MALI_OSK_ERR_FAULT;
60 return _MALI_OSK_ERR_OK;
64 /* Can run in atomic context */
65 void _mali_osk_pm_dev_ref_put(void)
67 #ifdef CONFIG_PM_RUNTIME
68 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
69 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
70 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
71 pm_runtime_put_autosuspend(&(mali_platform_device->dev));
73 pm_runtime_put(&(mali_platform_device->dev));
78 void _mali_osk_pm_dev_barrier(void)
80 #ifdef CONFIG_PM_RUNTIME
81 pm_runtime_barrier(&(mali_platform_device->dev));