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