e8c607e59af966838440f375af29adb0ddb93bca
[firefly-linux-kernel-4.4.55.git] / drivers / gpu / arm / mali400 / mali / platform / rk30 / rk3066.c
1 /*
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
5  * ALL RIGHTS RESERVED
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.
9  */
10
11
12 /**
13  * @file rk3066.c
14  * 实现 rk30_platform 中的 platform_specific_strategy_callbacks,
15  * 实际上也是 platform_dependent_part 的顶层.
16  *
17  * mali_device_driver(mdd) 包含两部分 :
18  *      .DP : platform_dependent_part :
19  *              依赖 platform 部分,
20  *              源码在 <mdd_src_dir>/mali/platform/<platform_name> 目录下.
21  *      .DP : common_parts : ARM 实现的通用的部分.
22  */
23
24 #define ENABLE_DEBUG_LOG
25 #include "custom_log.h"
26
27 #include <linux/platform_device.h>
28 #include <linux/version.h>
29 #include <linux/pm.h>
30 #ifdef CONFIG_PM_RUNTIME
31 #include <linux/pm_runtime.h>
32 #endif
33 #include <linux/workqueue.h>
34 #include <linux/dma-mapping.h>
35 #include <linux/pm_runtime.h>
36 #include <linux/rockchip/cpu.h>
37
38 #include <linux/mali/mali_utgard.h>
39 #include "mali_kernel_common.h"
40 #include "mali_platform.h"
41 #include "arm_core_scaling.h"
42
43 #ifdef CONFIG_PM_RUNTIME
44 static int mali_runtime_suspend(struct device *device)
45 {
46         int ret = 0;
47
48         MALI_DEBUG_PRINT(4, ("mali_runtime_suspend() called\n"));
49
50         if (NULL != device->driver &&
51             NULL != device->driver->pm &&
52             NULL != device->driver->pm->runtime_suspend) {
53                 /* Need to notify Mali driver about this event */
54                 ret = device->driver->pm->runtime_suspend(device);
55         }
56
57         mali_platform_power_mode_change(MALI_POWER_MODE_LIGHT_SLEEP);
58
59         return ret;
60 }
61
62 static int mali_runtime_resume(struct device *device)
63 {
64         int ret = 0;
65
66         MALI_DEBUG_PRINT(4, ("mali_runtime_resume() called\n"));
67
68         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
69
70         if (NULL != device->driver &&
71             NULL != device->driver->pm &&
72             NULL != device->driver->pm->runtime_resume) {
73                 /* Need to notify Mali driver about this event */
74                 ret = device->driver->pm->runtime_resume(device);
75         }
76
77         return ret;
78 }
79
80 static int mali_runtime_idle(struct device *device)
81 {
82         int ret = 0;
83
84         MALI_DEBUG_PRINT(4, ("mali_runtime_idle() called\n"));
85
86         if (NULL != device->driver &&
87             NULL != device->driver->pm &&
88             NULL != device->driver->pm->runtime_idle) {
89                 /* Need to notify Mali driver about this event */
90                 ret = device->driver->pm->runtime_idle(device);
91                 if (0 != ret)
92                         return ret;
93         }
94
95         pm_runtime_suspend(device);
96
97         return 0;
98 }
99 #endif
100
101 static int mali_os_suspend(struct device *device)
102 {
103         int ret = 0;
104
105         MALI_DEBUG_PRINT(4, ("mali_os_suspend() called\n"));
106
107         if (NULL != device->driver &&
108             NULL != device->driver->pm &&
109             NULL != device->driver->pm->suspend) {
110                 /* Need to notify Mali driver about this event */
111                 ret = device->driver->pm->suspend(device);
112         }
113
114         mali_platform_power_mode_change(MALI_POWER_MODE_DEEP_SLEEP);
115
116         return ret;
117 }
118
119 static int mali_os_resume(struct device *device)
120 {
121         int ret = 0;
122
123         MALI_DEBUG_PRINT(4, ("mali_os_resume() called\n"));
124
125         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
126
127         if (NULL != device->driver &&
128             NULL != device->driver->pm &&
129             NULL != device->driver->pm->resume) {
130                 /* Need to notify Mali driver about this event */
131                 ret = device->driver->pm->resume(device);
132         }
133
134         return ret;
135 }
136
137 static int mali_os_freeze(struct device *device)
138 {
139         int ret = 0;
140
141         MALI_DEBUG_PRINT(4, ("mali_os_freeze() called\n"));
142
143         if (NULL != device->driver &&
144             NULL != device->driver->pm &&
145             NULL != device->driver->pm->freeze) {
146                 /* Need to notify Mali driver about this event */
147                 ret = device->driver->pm->freeze(device);
148         }
149
150         return ret;
151 }
152
153 static int mali_os_thaw(struct device *device)
154 {
155         int ret = 0;
156
157         MALI_DEBUG_PRINT(4, ("mali_os_thaw() called\n"));
158
159         if (NULL != device->driver &&
160             NULL != device->driver->pm &&
161             NULL != device->driver->pm->thaw) {
162                 /* Need to notify Mali driver about this event */
163                 ret = device->driver->pm->thaw(device);
164         }
165
166         return ret;
167 }
168
169 static const struct dev_pm_ops mali_gpu_device_type_pm_ops = {
170         .suspend = mali_os_suspend,
171         .resume = mali_os_resume,
172         .freeze = mali_os_freeze,
173         .thaw = mali_os_thaw,
174 #ifdef CONFIG_PM_RUNTIME
175         .runtime_suspend = mali_runtime_suspend,
176         .runtime_resume = mali_runtime_resume,
177         .runtime_idle = mali_runtime_idle,
178 #endif
179 };
180
181 static const struct device_type mali_gpu_device_device_type = {
182         .pm = &mali_gpu_device_type_pm_ops,
183 };
184
185 /**
186  * platform_specific_data_of_platform_device_of_mali_gpu.
187  *
188  * 类型 'struct mali_gpu_device_data' 由 common_part 定义,
189  * 实例也将被 common_part 引用,
190  * 比如通知 mali_utilization_event 等.
191  */
192 static const struct mali_gpu_device_data mali_gpu_data = {
193         .shared_mem_size = 1024 * 1024 * 1024, /* 1GB */
194         .fb_start = 0x40000000,
195         .fb_size = 0xb1000000,
196         .max_job_runtime = 100, /* 100 ms */
197         /* .utilization_interval = 0, */ /* 0ms */
198         .utilization_callback = mali_gpu_utilization_handler,
199 };
200
201 static void mali_platform_device_add_config(struct platform_device *pdev)
202 {
203         pdev->name = MALI_GPU_NAME_UTGARD,
204         pdev->id = 0;
205         pdev->dev.type = &mali_gpu_device_device_type;
206         pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask,
207         pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
208 }
209
210 /*---------------------------------------------------------------------------*/
211
212 /**
213  * 将被 common_part 回调的, 对 platform_device_of_mali_gpu 初始化的策略回调实现.
214  *
215  * .DP : platform_specific_strategy_callbacks_called_by_common_part,
216  *       platform_specific_strategy_callbacks :
217  *              被 common_part 调用的 平台相关的策略回调.
218  */
219 int mali_platform_device_init(struct platform_device *pdev)
220 {
221 // error
222         int err = 0;
223         int num_pp_cores = 0;
224
225         D("mali_platform_device_register() called\n");
226
227         /*
228         if (cpu_is_rk312x())
229                 num_pp_cores = 2;
230         else if (cpu_is_rk3036())
231         */
232                 num_pp_cores = 1;
233         /*
234         else if (cpu_is_rk3188())
235                 num_pp_cores = 4;
236         else if (cpu_is_rk3228())
237                 num_pp_cores = 2;
238         */
239
240         D("to add config.");
241         mali_platform_device_add_config(pdev);
242
243         D("to add data to platform_device..");
244         /* 将 platform_specific_data 添加到 platform_device_of_mali_gpu.
245          * 这里的 platform_specific_data 的类型由 common_part 定义. */
246         err = platform_device_add_data(pdev, &mali_gpu_data,
247                                        sizeof(mali_gpu_data));
248         if (err == 0) {
249                 D("to init internal_platform_specific_code.");
250                 /* .KP : 初始化 platform_device_of_mali_gpu 中,
251                  * 仅和 platform_dependent_part 相关的部分. */
252                 err = mali_platform_init(pdev);
253                 if (err == 0) {
254 #ifdef CONFIG_PM_RUNTIME
255                         pm_runtime_set_autosuspend_delay(&(pdev->dev), 1000);
256                         pm_runtime_use_autosuspend(&(pdev->dev));
257                         pm_runtime_enable(&(pdev->dev));
258 #endif
259                         MALI_DEBUG_ASSERT(0 < num_pp_cores);
260                         mali_core_scaling_init(num_pp_cores);
261                         return 0;
262                 }
263         }
264
265         return err;
266 }
267
268 /**
269  * 将被 common_part 回调的, 对 platform_device_of_mali_gpu 终止化的策略回调实现.
270  */
271 void mali_platform_device_deinit(struct platform_device *pdev)
272 {
273         MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n"));
274
275         mali_platform_deinit(pdev);
276 }