aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpu/mali400/r3p2/mali/platform/pegasus-m400/exynos4.c
blob: bf83249b4b24e2be61cf0835a92dbfc844a2bafd (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
/* drivers/gpu/mali400/mali/platform/pegasus-m400/exynos4.c
 *
 * Copyright 2011 by S.LSI. Samsung Electronics Inc.
 * San#24, Nongseo-Dong, Giheung-Gu, Yongin, Korea
 *
 * Samsung SoC Mali400 DVFS driver
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software FoundatIon.
 */

/**
 * @file exynos4.c
 * Platform specific Mali driver functions for the exynos 4XXX based platforms
 */
#include <linux/platform_device.h>
#include <linux/version.h>
#include <linux/pm.h>
#include <linux/suspend.h>

#ifdef CONFIG_PM_RUNTIME
#include <linux/pm_runtime.h>
#endif

#ifdef CONFIG_MALI_DVFS
#include "mali_kernel_utilization.h"
#endif /* CONFIG_MALI_DVFS */

#include <linux/mali/mali_utgard.h>
#include "mali_kernel_common.h"
#include "mali_kernel_linux.h"
#include "mali_pm.h"

#include <plat/pd.h>

#include "exynos4_pmm.h"

#if defined(CONFIG_PM_RUNTIME)
/* We does not need PM NOTIFIER in r3p2 DDK */
//#define USE_PM_NOTIFIER
#endif

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
struct exynos_pm_domain;
extern struct exynos_pm_domain exynos4_pd_g3d;
void exynos_pm_add_dev_to_genpd(struct platform_device *pdev, struct exynos_pm_domain *pd);
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
extern struct platform_device exynos4_device_pd[];
#else
extern struct platform_device s5pv310_device_pd[];
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) */

static void mali_platform_device_release(struct device *device);

#if defined(CONFIG_PM_RUNTIME)
#if defined(USE_PM_NOTIFIER)
static int mali_os_suspend(struct device *device);
static int mali_os_resume(struct device *device);
static int mali_os_freeze(struct device *device);
static int mali_os_thaw(struct device *device);

static int mali_runtime_suspend(struct device *device);
static int mali_runtime_resume(struct device *device);
static int mali_runtime_idle(struct device *device);
#endif
#endif

#if defined(CONFIG_ARCH_S5PV310) && !defined(CONFIG_BOARD_HKDKC210)

/* This is for other SMDK boards */
#define MALI_BASE_IRQ 232

#else

/* This is for the Odroid boards */
#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0))
#define MALI_BASE_IRQ 182
#else
#define MALI_BASE_IRQ 150
#endif

#endif

#define MALI_GP_IRQ	   MALI_BASE_IRQ + 9
#define MALI_PP0_IRQ	  MALI_BASE_IRQ + 5
#define MALI_PP1_IRQ	  MALI_BASE_IRQ + 6
#define MALI_PP2_IRQ	  MALI_BASE_IRQ + 7
#define MALI_PP3_IRQ	  MALI_BASE_IRQ + 8
#define MALI_GP_MMU_IRQ   MALI_BASE_IRQ + 4
#define MALI_PP0_MMU_IRQ  MALI_BASE_IRQ + 0
#define MALI_PP1_MMU_IRQ  MALI_BASE_IRQ + 1
#define MALI_PP2_MMU_IRQ  MALI_BASE_IRQ + 2
#define MALI_PP3_MMU_IRQ  MALI_BASE_IRQ + 3

static struct resource mali_gpu_resources[] =
{
	MALI_GPU_RESOURCES_MALI400_MP4(0x13000000,
								   MALI_GP_IRQ, MALI_GP_MMU_IRQ,
								   MALI_PP0_IRQ, MALI_PP0_MMU_IRQ,
								   MALI_PP1_IRQ, MALI_PP1_MMU_IRQ,
								   MALI_PP2_IRQ, MALI_PP2_MMU_IRQ,
								   MALI_PP3_IRQ, MALI_PP3_MMU_IRQ)
};

#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
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
#endif /* CONFIG_PM_RUNTIME */

#if 0
static struct dev_pm_ops mali_gpu_device_type_pm_ops =
{
#ifndef CONFIG_PM_RUNTIME
	.suspend = mali_os_suspend,
	.resume = mali_os_resume,
#endif
	.freeze = mali_os_freeze,
	.thaw = mali_os_thaw,
#ifdef CONFIG_PM_RUNTIME
	.runtime_suspend = mali_runtime_suspend,
	.runtime_resume = mali_runtime_resume,
	.runtime_idle = mali_runtime_idle,
#endif
};
#endif

#if defined(USE_PM_NOTIFIER)
static struct device_type mali_gpu_device_device_type =
{
	.pm = &mali_gpu_device_type_pm_ops,
};
#endif

static struct platform_device mali_gpu_device =
{
	.name = "mali_dev", /* MALI_SEC MALI_GPU_NAME_UTGARD, */
	.id = 0,
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
	/* Set in mali_platform_device_register() for these kernels */
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0)
	.dev.parent = &exynos4_device_pd[PD_G3D].dev,
#else
	.dev.parent = &s5pv310_device_pd[PD_G3D].dev,
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3,0,0) */
	.dev.release = mali_platform_device_release,
#if 0
	/*
	 * We temporarily make use of a device type so that we can control the Mali power
	 * from within the mali.ko (since the default platform bus implementation will not do that).
	 * Ideally .dev.pm_domain should be used instead, as this is the new framework designed
	 * to control the power of devices.
	 */
	.dev.type = &mali_gpu_device_device_type, /* We should probably use the pm_domain instead of type on newer kernels */
#endif
};

static struct mali_gpu_device_data mali_gpu_data =
{
	.shared_mem_size = 256 * 1024 * 1024, /* 256MB */
	.fb_start = 0x40000000,
	.fb_size = 0xb1000000,
	.utilization_interval = 100, /* 100ms */
	.utilization_callback = mali_gpu_utilization_handler,
};

int mali_platform_device_register(void)
{
	int err;

	MALI_DEBUG_PRINT(4, ("mali_platform_device_register() called\n"));

#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,4,0)
	exynos_pm_add_dev_to_genpd(&mali_gpu_device, &exynos4_pd_g3d);
#endif

	/* Connect resources to the device */
	err = platform_device_add_resources(&mali_gpu_device, mali_gpu_resources, sizeof(mali_gpu_resources) / sizeof(mali_gpu_resources[0]));
	if (0 == err)
	{
		err = platform_device_add_data(&mali_gpu_device, &mali_gpu_data, sizeof(mali_gpu_data));
		if (0 == err)
		{
#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
			err = register_pm_notifier(&mali_pwr_notif_block);
			if (err)
			{
				goto plat_init_err;
			}
#endif
#endif /* CONFIG_PM_RUNTIME */

			/* Register the platform device */
			err = platform_device_register(&mali_gpu_device);
			if (0 == err)
			{
				mali_platform_init(&(mali_gpu_device.dev));

#ifdef CONFIG_PM_RUNTIME
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
				pm_runtime_set_autosuspend_delay(&(mali_gpu_device.dev), 1000);
				pm_runtime_use_autosuspend(&(mali_gpu_device.dev));
#endif
				pm_runtime_enable(&(mali_gpu_device.dev));
#endif

				return 0;
			}
		}

#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
plat_init_err:
		unregister_pm_notifier(&mali_pwr_notif_block);
#endif
#endif /* CONFIG_PM_RUNTIME */
		platform_device_unregister(&mali_gpu_device);
	}

	return err;
}

void mali_platform_device_unregister(void)
{
	MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n"));

#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
	unregister_pm_notifier(&mali_pwr_notif_block);
#endif
#endif /* CONFIG_PM_RUNTIME */

	mali_platform_deinit(&(mali_gpu_device.dev));

	platform_device_unregister(&mali_gpu_device);
}

static void mali_platform_device_release(struct device *device)
{
	MALI_DEBUG_PRINT(4, ("mali_platform_device_release() called\n"));
}

#ifdef CONFIG_PM_RUNTIME
#if defined(USE_PM_NOTIFIER)
static int mali_pwr_suspend_notifier(struct notifier_block *nb,unsigned long event,void* dummy)
{
	int err = 0;
	switch (event)
	{
		case PM_SUSPEND_PREPARE:
			mali_pm_os_suspend();
			err = mali_os_suspend(&(mali_platform_device->dev));
			break;

		case PM_POST_SUSPEND:
			err = mali_os_resume(&(mali_platform_device->dev));
			mali_pm_os_resume();
			break;
		default:
			break;
	}
	return err;
}

static int mali_os_suspend(struct device *device)
{
	int ret = 0;
	MALI_DEBUG_PRINT(4, ("mali_os_suspend() called\n"));

#ifdef CONFIG_MALI_DVFS
	mali_utilization_suspend();
#endif

	if (NULL != device &&
		NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->suspend)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->suspend(device);
	}

	mali_platform_power_mode_change(device, MALI_POWER_MODE_DEEP_SLEEP);

	return ret;
}

static int mali_os_resume(struct device *device)
{
	int ret = 0;

	MALI_DEBUG_PRINT(4, ("mali_os_resume() called\n"));
#ifdef CONFIG_REGULATOR
	mali_regulator_enable();
	g3d_power_domain_control(1);
#endif
	mali_platform_power_mode_change(device, MALI_POWER_MODE_ON);

	if (NULL != device &&
		NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->resume)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->resume(device);
	}

	return ret;
}

static int mali_os_freeze(struct device *device)
{
	int ret = 0;
	MALI_DEBUG_PRINT(4, ("mali_os_freeze() called\n"));

	if (NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->freeze)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->freeze(device);
	}

	return ret;
}

static int mali_os_thaw(struct device *device)
{
	int ret = 0;
	MALI_DEBUG_PRINT(4, ("mali_os_thaw() called\n"));

	if (NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->thaw)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->thaw(device);
	}

	return ret;
}

static int mali_runtime_suspend(struct device *device)
{
	int ret = 0;

	MALI_DEBUG_PRINT(4, ("mali_runtime_suspend() called\n"));
	if (NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->runtime_suspend)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->runtime_suspend(device);
	}

	mali_platform_power_mode_change(device, MALI_POWER_MODE_LIGHT_SLEEP);

	return ret;
}

static int mali_runtime_resume(struct device *device)
{
	int ret = 0;
	MALI_DEBUG_PRINT(4, ("mali_runtime_resume() called\n"));

	mali_platform_power_mode_change(device, MALI_POWER_MODE_ON);

	if (NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->runtime_resume)
	{
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->runtime_resume(device);
	}

	return ret;
}

static int mali_runtime_idle(struct device *device)
{
	MALI_DEBUG_PRINT(4, ("mali_runtime_idle() called\n"));
	if (NULL != device->driver &&
		NULL != device->driver->pm &&
		NULL != device->driver->pm->runtime_idle)
	{
		int ret = 0;
		/* Need to notify Mali driver about this event */
		ret = device->driver->pm->runtime_idle(device);
		if (0 != ret)
		{
			return ret;
		}
	}

	return 1;
}

#endif /* USE_PM_NOTIFIER */
#endif /* CONFIG_PM_RUNTIME */