aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/samsung/mali/linux/mali_kernel_pm.c
blob: 4639d5500be2569a64961f26580399d53a3fc60d (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
/**
 * 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_kernel_pm.c
 * Linux Power Management integration
 */

#include <linux/sched.h>
#include <linux/platform_device.h>
#include <linux/version.h>
#include <asm/current.h>
#include <linux/suspend.h>
#include <linux/module.h>
#ifdef CONFIG_PM_RUNTIME
#include <linux/pm_runtime.h>
#endif
#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_pm.h"
#include "mali_platform.h"

#if ! MALI_LICENSE_IS_GPL
#undef CONFIG_PM_RUNTIME
#endif

#if MALI_PMM_RUNTIME_JOB_CONTROL_ON
extern void set_mali_parent_power_domain(struct platform_device* dev);
#endif /* MALI_PMM_RUNTIME_JOB_CONTROL_ON */
static int mali_probe(struct platform_device *pdev);
static int mali_remove(struct platform_device *pdev);

#ifdef CONFIG_PM_RUNTIME
static int mali_runtime_suspend(struct device *dev);
static int mali_runtime_resume(struct device *dev);
#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
static int mali_os_suspend(struct platform_device *pdev, pm_message_t state);
static int mali_os_resume(struct platform_device *pdev);
#else
static int mali_os_suspend(struct device *dev);
static int mali_os_resume(struct device *dev);
#endif


#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
static const struct dev_pm_ops mali_dev_pm_ops =
{
#ifdef CONFIG_PM_RUNTIME
	.runtime_suspend = mali_runtime_suspend,
	.runtime_resume = mali_runtime_resume,
	.runtime_idle = NULL,
#else
	.suspend = mali_os_suspend,
	.resume = mali_os_resume,
#endif
	.freeze = mali_os_suspend,
	.poweroff = mali_os_suspend,
	.thaw = mali_os_resume,
	.restore = mali_os_resume,
};
#elif (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
struct pm_ext_ops mali_ext_pm_operations =
{
	.base =
	{
		.freeze = mali_os_suspend,
		.thaw =   mali_os_resume,
		.poweroff = mali_os_suspend,
		.restore = mali_os_resume,
	},
};
#endif


static struct platform_driver mali_plat_driver =
{
	.probe  = mali_probe,
	.remove = mali_remove,
#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))
	.suspend = mali_os_suspend,
	.resume  = mali_os_resume,
	.pm = &mali_ext_pm_operations,
#endif

	.driver =
	{
		.name   = "mali_dev",
		.owner  = THIS_MODULE,
#if MALI_LICENSE_IS_GPL
		.bus = &platform_bus_type,
#endif
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29))
		.pm = &mali_dev_pm_ops,
#endif
	},
};

#ifdef CONFIG_PM_RUNTIME
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy);

static struct notifier_block mali_pwr_notif_block =
{
	.notifier_call = mali_pwr_suspend_notifier
};
#endif

/** This function is called when platform device is unregistered. This function
 * is necessary when the platform device is unregistered.
 */
static void _mali_release_pm(struct device *device)
{
}
struct platform_device mali_gpu_device =
{
	.name = "mali_dev",
	.id = 0,
	.dev.release = _mali_release_pm
};

/** This function is called when the device is probed */
static int mali_probe(struct platform_device *pdev)
{
	return 0;
}

static int mali_remove(struct platform_device *pdev)
{
#ifdef CONFIG_PM_RUNTIME
	pm_runtime_disable(&pdev->dev);
#endif
	return 0;
}

#ifdef CONFIG_PM_RUNTIME
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy)
{
	switch (event)
	{
		case PM_SUSPEND_PREPARE:
			MALI_DEBUG_PRINT(2, ("mali_pwr_suspend_notifier(PM_SUSPEND_PREPARE) called\n"));
			mali_pm_os_suspend();
			break;
		case PM_POST_SUSPEND:
			MALI_DEBUG_PRINT(2, ("mali_pwr_suspend_notifier(PM_SUSPEND_PREPARE) called\n"));
			mali_pm_os_resume();
			break;
		default:
			break;
	}
	return 0;
}
#endif


#ifdef CONFIG_PM_RUNTIME

static int mali_runtime_suspend(struct device *dev)
{
	MALI_DEBUG_PRINT(3, ("mali_runtime_suspend() called\n"));
	mali_pm_runtime_suspend();
	return 0; /* all ok */
}

static int mali_runtime_resume(struct device *dev)
{
	MALI_DEBUG_PRINT(3, ("mali_runtime_resume() called\n"));
	mali_pm_runtime_resume();
	return 0; /* all ok */
}

#endif

#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29))

static int mali_os_suspend(struct platform_device *pdev, pm_message_t state)
{
	MALI_DEBUG_PRINT(3, ("mali_os_suspend(old) called\n"));
	mali_pm_os_suspend();
	return 0; /* all ok */
}

static int mali_os_resume(struct platform_device *pdev)
{
	MALI_DEBUG_PRINT(3, ("mali_os_resume(old) called\n"));
	mali_pm_os_resume();
	return 0; /* all ok */
}

#else

static int mali_os_suspend(struct device *dev)
{
	MALI_DEBUG_PRINT(3, ("mali_os_suspend(new) called\n"));
	mali_pm_os_suspend();
	return 0; /* all ok */
}

static int mali_os_resume(struct device *dev)
{
	MALI_DEBUG_PRINT(3, ("mali_os_resume(new) called\n"));
	mali_pm_os_resume();
	return 0; /* all ok */
}

#endif

/** This function is called when Mali GPU device is initialized
 */
int _mali_dev_platform_register(void)
{
	int err;

#ifdef CONFIG_PM_RUNTIME
	set_mali_parent_power_domain((void *)&mali_gpu_device);
#endif

#ifdef CONFIG_PM_RUNTIME
	err = register_pm_notifier(&mali_pwr_notif_block);
	if (err)
	{
		return err;
	}
#endif

#if MALI_LICENSE_IS_GPL
	err = platform_device_register(&mali_gpu_device);
	if (!err) 
	{
		err = platform_driver_register(&mali_plat_driver);
		if (err)
		{
#ifdef CONFIG_PM_RUNTIME
			unregister_pm_notifier(&mali_pwr_notif_block);
#endif
			platform_device_unregister(&mali_gpu_device);
		}
	}
#endif

	return err;
}

/** This function is called when Mali GPU device is unloaded
 */
void _mali_dev_platform_unregister(void)
{
#ifdef CONFIG_PM_RUNTIME
	unregister_pm_notifier(&mali_pwr_notif_block);
#endif

#if MALI_LICENSE_IS_GPL
	platform_driver_unregister(&mali_plat_driver);
	platform_device_unregister(&mali_gpu_device);
#endif
}