xref: /OK3568_Linux_fs/kernel/drivers/gpu/arm/mali400/mali/linux/mali_osk_pm.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1 /**
2  * Copyright (C) 2010-2017 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 #include "mali_kernel_linux.h"
19 #ifdef CONFIG_PM_RUNTIME
20 #include <linux/pm_runtime.h>
21 #endif /* CONFIG_PM_RUNTIME */
22 #include <linux/platform_device.h>
23 #include <linux/version.h>
24 #include "mali_osk.h"
25 #include "mali_kernel_common.h"
26 
27 /* Can NOT run in atomic context */
_mali_osk_pm_dev_ref_get_sync(void)28 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_sync(void)
29 {
30 #ifdef CONFIG_PM_RUNTIME
31 	int err;
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));
36 #endif
37 	if (0 > err) {
38 		MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get_sync() returned error code %d\n", err));
39 		return _MALI_OSK_ERR_FAULT;
40 	}
41 #endif
42 	return _MALI_OSK_ERR_OK;
43 }
44 
45 /* Can run in atomic context */
_mali_osk_pm_dev_ref_get_async(void)46 _mali_osk_errcode_t _mali_osk_pm_dev_ref_get_async(void)
47 {
48 #ifdef CONFIG_PM_RUNTIME
49 	int err;
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));
54 #endif
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;
58 	}
59 #endif
60 	return _MALI_OSK_ERR_OK;
61 }
62 
63 
64 /* Can run in atomic context */
_mali_osk_pm_dev_ref_put(void)65 void _mali_osk_pm_dev_ref_put(void)
66 {
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));
72 #else
73 	pm_runtime_put(&(mali_platform_device->dev));
74 #endif
75 #endif
76 }
77 
_mali_osk_pm_dev_barrier(void)78 void _mali_osk_pm_dev_barrier(void)
79 {
80 #ifdef CONFIG_PM_RUNTIME
81 	pm_runtime_barrier(&(mali_platform_device->dev));
82 #endif
83 }
84