aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/samsung/mali/linux/mali_osk_pm.c
blob: 491a6038dd448e251ced3f1523c6be30801e3186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/**
 * Copyright (C) 2010-2012 ARM Limited. All rights reserved.
 * 
 * This program is free software and is provided to you under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation, and any use by you of this program is subject to the terms of such GNU licence.
 * 
 * A copy of the licence is included with the program, and can also be obtained from Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

/**
 * @file mali_osk_pm.c
 * Implementation of the callback functions from common power management
 */

#include <linux/sched.h>

#ifdef CONFIG_PM_RUNTIME
#include <linux/pm_runtime.h>
#endif /* CONFIG_PM_RUNTIME */
#include <linux/platform_device.h>
#include "mali_platform.h"
#include "mali_osk.h"
#include "mali_uk_types.h"
#include "mali_kernel_common.h"
#include "mali_kernel_license.h"
#include "mali_linux_pm.h"
#include "mali_kernel_license.h"

#if ! MALI_LICENSE_IS_GPL
#undef CONFIG_PM_RUNTIME
#endif

extern struct platform_device mali_gpu_device;

#ifdef CONFIG_PM_RUNTIME
static mali_bool have_runtime_reference = MALI_FALSE;
#endif

void _mali_osk_pm_dev_enable(void)
{
#ifdef CONFIG_PM_RUNTIME
	pm_runtime_enable(&(mali_gpu_device.dev));
#endif
}

/* NB: Function is not thread safe */
_mali_osk_errcode_t _mali_osk_pm_dev_idle(void)
{
#ifdef CONFIG_PM_RUNTIME
	if (MALI_TRUE == have_runtime_reference)
	{
		int err;
		err = pm_runtime_put_sync(&(mali_gpu_device.dev));	
		if (0 > err)
		{
			MALI_PRINT_ERROR(("OSK PM: pm_runtime_put_sync() returned error code %d\n", err));	
			return _MALI_OSK_ERR_FAULT;
		}
		have_runtime_reference = MALI_FALSE;
	}
#endif
	return _MALI_OSK_ERR_OK;
}

/* NB: Function is not thread safe */
_mali_osk_errcode_t _mali_osk_pm_dev_activate(void)
{
#ifdef CONFIG_PM_RUNTIME
	if (MALI_TRUE != have_runtime_reference)
	{
		int err;
		err = pm_runtime_get_sync(&(mali_gpu_device.dev));
		if (0 > err)
		{
			MALI_PRINT_ERROR(("OSK PM: pm_runtime_get_sync() returned error code %d\n", err));	
			return _MALI_OSK_ERR_FAULT;
		}
		have_runtime_reference = MALI_TRUE;
	}
#endif
	return _MALI_OSK_ERR_OK;
}