rk312x, mali_400: correct coding style in platform_dependent_part.
[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 #include <linux/platform_device.h>
12 #include <linux/version.h>
13 #include <linux/pm.h>
14 #ifdef CONFIG_PM_RUNTIME
15 #include <linux/pm_runtime.h>
16 #endif
17 #include <linux/workqueue.h>
18 #include <linux/dma-mapping.h>
19 #include <linux/rockchip/cpu.h>
20
21 #include <linux/mali/mali_utgard.h>
22 #include "mali_kernel_common.h"
23 #include "mali_platform.h"
24 #include "arm_core_scaling.h"
25
26 #ifdef CONFIG_PM_RUNTIME
27 static int mali_runtime_suspend(struct device *device)
28 {
29         int ret = 0;
30
31         MALI_DEBUG_PRINT(4, ("mali_runtime_suspend() called\n"));
32
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);
38         }
39
40         mali_platform_power_mode_change(MALI_POWER_MODE_LIGHT_SLEEP);
41
42         return ret;
43 }
44
45 static int mali_runtime_resume(struct device *device)
46 {
47         int ret = 0;
48
49         MALI_DEBUG_PRINT(4, ("mali_runtime_resume() called\n"));
50
51         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
52
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);
58         }
59
60         return ret;
61 }
62
63 static int mali_runtime_idle(struct device *device)
64 {
65         int ret = 0;
66
67         MALI_DEBUG_PRINT(4, ("mali_runtime_idle() called\n"));
68
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);
74                 if (0 != ret)
75                         return ret;
76         }
77
78         pm_runtime_suspend(device);
79
80         return 0;
81 }
82 #endif
83
84 static int mali_os_suspend(struct device *device)
85 {
86         int ret = 0;
87
88         MALI_DEBUG_PRINT(4, ("mali_os_suspend() called\n"));
89
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);
95         }
96
97         mali_platform_power_mode_change(MALI_POWER_MODE_DEEP_SLEEP);
98
99         return ret;
100 }
101
102 static int mali_os_resume(struct device *device)
103 {
104         int ret = 0;
105
106         MALI_DEBUG_PRINT(4, ("mali_os_resume() called\n"));
107
108         mali_platform_power_mode_change(MALI_POWER_MODE_ON);
109
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);
115         }
116
117         return ret;
118 }
119
120 static int mali_os_freeze(struct device *device)
121 {
122         int ret = 0;
123
124         MALI_DEBUG_PRINT(4, ("mali_os_freeze() called\n"));
125
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);
131         }
132
133         return ret;
134 }
135
136 static int mali_os_thaw(struct device *device)
137 {
138         int ret = 0;
139
140         MALI_DEBUG_PRINT(4, ("mali_os_thaw() called\n"));
141
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);
147         }
148
149         return ret;
150 }
151
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,
161 #endif
162 };
163
164 static const struct device_type mali_gpu_device_device_type = {
165         .pm = &mali_gpu_device_type_pm_ops,
166 };
167
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,
175 };
176
177 static void mali_platform_device_add_config(struct platform_device *pdev)
178 {
179         pdev->name = MALI_GPU_NAME_UTGARD,
180         pdev->id = 0;
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);
184 }
185
186 int mali_platform_device_init(struct platform_device *pdev)
187 {
188         int err = 0;
189         int num_pp_cores = 0;
190
191         MALI_DEBUG_PRINT(2, ("mali_platform_device_register() called\n"));
192
193         if (cpu_is_rk312x())
194                 num_pp_cores = 2;
195         else if (cpu_is_rk3036())
196                 num_pp_cores = 1;
197         else if (cpu_is_rk3188())
198                 num_pp_cores = 4;
199
200         mali_platform_device_add_config(pdev);
201
202         err = platform_device_add_data(pdev, &mali_gpu_data,
203                                        sizeof(mali_gpu_data));
204         if (err == 0) {
205                 err = mali_platform_init(pdev);
206                 if (err == 0) {
207 #ifdef CONFIG_PM_RUNTIME
208                         pm_runtime_set_autosuspend_delay(&(pdev->dev), 1000);
209                         pm_runtime_use_autosuspend(&(pdev->dev));
210                         pm_runtime_enable(&(pdev->dev));
211 #endif
212                         MALI_DEBUG_ASSERT(0 < num_pp_cores);
213                         mali_core_scaling_init(num_pp_cores);
214                         return 0;
215                 }
216         }
217
218         return err;
219 }
220
221 void mali_platform_device_deinit(struct platform_device *pdev)
222 {
223         MALI_DEBUG_PRINT(4, ("mali_platform_device_unregister() called\n"));
224
225         mali_platform_deinit(pdev);
226 }