2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2009-2010, 2012 ARM Limited
6 * The entire notice above must be reproduced on all authorised
7 * copies and copies may only be made to the extent permitted
8 * by a licensing agreement from ARM Limited.
11 #include <linux/platform_device.h>
12 #include <linux/version.h>
14 #ifdef CONFIG_PM_RUNTIME
15 #include <linux/pm_runtime.h>
17 #include <linux/workqueue.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/rockchip/cpu.h>
21 #include <linux/mali/mali_utgard.h>
22 #include "mali_kernel_common.h"
23 #include "mali_platform.h"
24 #include "arm_core_scaling.h"
26 #ifdef CONFIG_PM_RUNTIME
27 static int mali_runtime_suspend(struct device *device)
31 MALI_DEBUG_PRINT(4, ("mali_runtime_suspend() called\n"));
33 if (NULL != device->driver &&
34 NULL != device->driver->pm &&
35 NULL != device->driver->pm->runtime_suspend) {
36 /* Need to notify Mali driver about this event */
37 ret = device->driver->pm->runtime_suspend(device);
40 mali_platform_power_mode_change(MALI_POWER_MODE_LIGHT_SLEEP);
45 static int mali_runtime_resume(struct device *device)
49 MALI_DEBUG_PRINT(4, ("mali_runtime_resume() called\n"));
51 mali_platform_power_mode_change(MALI_POWER_MODE_ON);
53 if (NULL != device->driver &&
54 NULL != device->driver->pm &&
55 NULL != device->driver->pm->runtime_resume) {
56 /* Need to notify Mali driver about this event */
57 ret = device->driver->pm->runtime_resume(device);
63 static int mali_runtime_idle(struct device *device)
67 MALI_DEBUG_PRINT(4, ("mali_runtime_idle() called\n"));
69 if (NULL != device->driver &&
70 NULL != device->driver->pm &&
71 NULL != device->driver->pm->runtime_idle) {
72 /* Need to notify Mali driver about this event */
73 ret = device->driver->pm->runtime_idle(device);
78 pm_runtime_suspend(device);
84 static int mali_os_suspend(struct device *device)
88 MALI_DEBUG_PRINT(4, ("mali_os_suspend() called\n"));
90 if (NULL != device->driver &&
91 NULL != device->driver->pm &&
92 NULL != device->driver->pm->suspend) {
93 /* Need to notify Mali driver about this event */
94 ret = device->driver->pm->suspend(device);
97 mali_platform_power_mode_change(MALI_POWER_MODE_DEEP_SLEEP);
102 static int mali_os_resume(struct device *device)
106 MALI_DEBUG_PRINT(4, ("mali_os_resume() called\n"));
108 mali_platform_power_mode_change(MALI_POWER_MODE_ON);
110 if (NULL != device->driver &&
111 NULL != device->driver->pm &&
112 NULL != device->driver->pm->resume) {
113 /* Need to notify Mali driver about this event */
114 ret = device->driver->pm->resume(device);
120 static int mali_os_freeze(struct device *device)
124 MALI_DEBUG_PRINT(4, ("mali_os_freeze() called\n"));
126 if (NULL != device->driver &&
127 NULL != device->driver->pm &&
128 NULL != device->driver->pm->freeze) {
129 /* Need to notify Mali driver about this event */
130 ret = device->driver->pm->freeze(device);
136 static int mali_os_thaw(struct device *device)
140 MALI_DEBUG_PRINT(4, ("mali_os_thaw() called\n"));
142 if (NULL != device->driver &&
143 NULL != device->driver->pm &&
144 NULL != device->driver->pm->thaw) {
145 /* Need to notify Mali driver about this event */
146 ret = device->driver->pm->thaw(device);
152 static const struct dev_pm_ops mali_gpu_device_type_pm_ops = {
153 .suspend = mali_os_suspend,
154 .resume = mali_os_resume,
155 .freeze = mali_os_freeze,
156 .thaw = mali_os_thaw,
157 #ifdef CONFIG_PM_RUNTIME
158 .runtime_suspend = mali_runtime_suspend,
159 .runtime_resume = mali_runtime_resume,
160 .runtime_idle = mali_runtime_idle,
164 static const struct device_type mali_gpu_device_device_type = {
165 .pm = &mali_gpu_device_type_pm_ops,
168 static const struct mali_gpu_device_data mali_gpu_data = {
169 .shared_mem_size = 1024 * 1024 * 1024, /* 1GB */
170 .fb_start = 0x40000000,
171 .fb_size = 0xb1000000,
172 .max_job_runtime = 60000, /* 60 seconds */
173 /* .utilization_interval = 0, */ /* 0ms */
174 .utilization_callback = mali_gpu_utilization_handler,
177 static void mali_platform_device_add_config(struct platform_device *pdev)
179 pdev->name = MALI_GPU_NAME_UTGARD,
181 pdev->dev.type = &mali_gpu_device_device_type;
182 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask,
183 pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
186 int mali_platform_device_init(struct platform_device *pdev)
189 int num_pp_cores = 0;
191 MALI_DEBUG_PRINT(2, ("mali_platform_device_register() called\n"));
195 else if (cpu_is_rk3036())
197 else if (cpu_is_rk3188())
199 else if (cpu_is_rk3228())
202 mali_platform_device_add_config(pdev);
204 err = platform_device_add_data(pdev, &mali_gpu_data,
205 sizeof(mali_gpu_data));
207 err = mali_platform_init(pdev);
209 #ifdef CONFIG_PM_RUNTIME
210 pm_runtime_set_autosuspend_delay(&(pdev->dev), 1000);
211 pm_runtime_use_autosuspend(&(pdev->dev));
212 pm_runtime_enable(&(pdev->dev));
214 MALI_DEBUG_ASSERT(0 < num_pp_cores);
215 mali_core_scaling_init(num_pp_cores);
223 void mali_platform_device_deinit(struct platform_device *pdev)
225 MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n"));
227 mali_platform_deinit(pdev);