1 #include <linux/platform_device.h>
2 #include <linux/version.h>
4 #ifdef CONFIG_PM_RUNTIME
5 #include <linux/pm_runtime.h>
8 #include <linux/mali/mali_utgard.h>
9 #include "mali_kernel_common.h"
10 #include <linux/dma-mapping.h>
11 #include <mach/mt_irq.h>
12 #include "arm_core_scaling.h"
13 #include "platform_pmm.h"
16 #include "mt_reg_base.h"
18 static void mali_platform_device_release(struct device
*device
);
19 static int mali_pm_suspend(struct device
*device
);
20 static int mali_pm_resume(struct device
*device
);
23 static struct mali_gpu_device_data mali_gpu_data
=
26 .shared_mem_size
= 1024 * 1024 * 1024, /* 1GB */
27 // Framebuffer physical address, only for validation usage
28 .fb_start
= 0x80000000,
29 .fb_size
= 0x80000000,
31 .utilization_interval
= 200, /* ms */
32 .utilization_callback
= mali_pmm_utilization_handler
, /*<utilization function>,*/
35 static struct resource mali_gpu_resources
[] =
37 MALI_GPU_RESOURCES_MALI450_MP4(
38 IO_VIRT_TO_PHYS(MALI_BASE
),
53 static struct resource mali_gpu_resources_MP3
[] =
55 MALI_GPU_RESOURCES_MALI450_MP3(
56 IO_VIRT_TO_PHYS(MALI_BASE
),
70 static struct resource mali_gpu_resources_MP2
[] =
72 MALI_GPU_RESOURCES_MALI450_MP2(
73 IO_VIRT_TO_PHYS(MALI_BASE
),
85 static struct dev_pm_ops mali_gpu_device_type_pm_ops
=
87 .suspend
= mali_pm_suspend
,
88 .resume
= mali_pm_resume
,
89 .freeze
= mali_pm_suspend
,
90 .thaw
= mali_pm_resume
,
91 .restore
= mali_pm_resume
,
93 #ifdef CONFIG_PM_RUNTIME
94 .runtime_suspend
= mali_runtime_suspend
,
95 .runtime_resume
= mali_runtime_resume
,
96 .runtime_idle
= mali_runtime_idle
,
100 static struct device_type mali_gpu_device_device_type
=
102 .pm
= &mali_gpu_device_type_pm_ops
,
106 static struct platform_device mali_gpu_device
=
108 .name
= MALI_GPU_NAME_UTGARD
,
110 .num_resources
= ARRAY_SIZE(mali_gpu_resources
),
111 .resource
= (struct resource
*)&mali_gpu_resources
,
112 .dev
.platform_data
= &mali_gpu_data
,
113 .dev
.release
= mali_platform_device_release
,
114 .dev
.coherent_dma_mask
= DMA_BIT_MASK(32),
115 /// Ideally .dev.pm_domain should be used instead, as this is the new framework designed
116 /// to control the power of devices.
117 .dev
.type
= &mali_gpu_device_device_type
/// We should probably use the pm_domain instead of type on newer kernels
121 extern u32
get_devinfo_with_index(u32 index
);
123 static u32
get_devinfo() {
124 /*TODO: replace this with get_devinfo_with_index*/
125 return *(volatile u32
*)0xf0206174;
127 static u32
get_gpuinfo() {
128 /*TODO: replace this with get_devinfo_with_index*/
129 return *(volatile u32
*)0xf0206040;
132 #define MALI_REASSIGN_RESOURCE(device, X) \
134 device->resource = (struct resource *)&(X);\
135 device->num_resources = ARRAY_SIZE((X));\
138 static void update_dev_info(struct platform_device
* device
) {
139 u32 info
= get_devinfo();
140 MALI_DEBUG_PRINT(1, ("devinfo %#x\n", info
));
142 /*if(0x0 == (info & (0x1 << 31))) { t or b*/
144 u32 gpuinfo
= get_gpuinfo();
145 MALI_DEBUG_PRINT(1, ("gpuinfo %#x\n", gpuinfo
));
146 u32 pp
= (gpuinfo
& 0x60000) >> 17;
148 MALI_DEBUG_PRINT(1, ("Found devinfo of MP3 %s\n", __FUNCTION__
));
149 MALI_REASSIGN_RESOURCE(device
, mali_gpu_resources_MP3
);
150 } else if(pp
== 0x2 || pp
== 0x3) {
151 MALI_DEBUG_PRINT(1, ("Found devinfo of MP2 %s, %d\n", __FUNCTION__
, pp
));
152 MALI_REASSIGN_RESOURCE(device
, mali_gpu_resources_MP2
);
154 #ifdef MTK_NR_MALI_PP
155 #if (MTK_NR_MALI_PP == 3)
156 MALI_DEBUG_PRINT(1, ("Mali MP3 %s (MTK_NR_MALI_PP)\n", __FUNCTION__
));
157 MALI_REASSIGN_RESOURCE(device
, mali_gpu_resources_MP3
);
158 #elif (MTK_NR_MALI_PP == 2)
159 MALI_DEBUG_PRINT(1, ("Mali MP2 %s (MTK_NR_MALI_PP)\n", __FUNCTION__
));
160 MALI_REASSIGN_RESOURCE(device
, mali_gpu_resources_MP2
);
162 MALI_DEBUG_PRINT(1, ("Default MP4 %s, ignore cfg: %d\n", __FUNCTION__
, MTK_NR_MALI_PP
));
165 MALI_DEBUG_PRINT(1, ("Default MP4 %s\n", __FUNCTION__
));
171 extern unsigned int get_max_DRAM_size (void);
172 int mali_platform_device_register(void)
175 int num_pp_cores
= 4; //TODO: Need specify if we are using diff config
176 MALI_DEBUG_PRINT(1, ("%s\n", __FUNCTION__
));
177 mali_gpu_data
.shared_mem_size
= get_max_DRAM_size();
179 update_dev_info(&mali_gpu_device
);
181 err
= platform_device_register(&mali_gpu_device
);
187 #ifdef CONFIG_PM_RUNTIME
188 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,37))
189 pm_runtime_set_autosuspend_delay(&(mali_gpu_device
.dev
), 1000);
190 pm_runtime_use_autosuspend(&(mali_gpu_device
.dev
));
192 pm_runtime_enable(&(mali_gpu_device
.dev
));
195 #if defined(__MALI_CORE_SCALING_ENABLE__)
196 mali_core_scaling_init(num_pp_cores
);
201 MALI_DEBUG_PRINT(1, ("%s err=%d\n",__FUNCTION__
, err
));
203 platform_device_unregister(&mali_gpu_device
);
208 void mali_platform_device_unregister(void)
210 MALI_DEBUG_PRINT(1, ("%s\n", __FUNCTION__
));
212 #if defined(__MALI_CORE_SCALING_ENABLE__)
213 mali_core_scaling_term();
218 platform_device_unregister(&mali_gpu_device
);
221 static void mali_platform_device_release(struct device
*device
)
223 MALI_DEBUG_PRINT(1, ("%s\n", __FUNCTION__
));
226 static int mali_pm_suspend(struct device
*device
)
230 MALI_DEBUG_PRINT(1, ("Mali PM:%s\n", __FUNCTION__
));
232 if (NULL
!= device
->driver
&&
233 NULL
!= device
->driver
->pm
&&
234 NULL
!= device
->driver
->pm
->suspend
)
236 /* Need to notify Mali driver about this event */
237 ret
= device
->driver
->pm
->suspend(device
);
240 _mali_osk_pm_delete_callback_timer();
241 mali_platform_power_mode_change(MALI_POWER_MODE_DEEP_SLEEP
);
246 static int mali_pm_resume(struct device
*device
)
250 MALI_DEBUG_PRINT(1, ("Mali PM: %s\n", __FUNCTION__
));
252 mali_platform_power_mode_change(MALI_POWER_MODE_ON
);
254 if (NULL
!= device
->driver
&&
255 NULL
!= device
->driver
->pm
&&
256 NULL
!= device
->driver
->pm
->resume
)
258 /* Need to notify Mali driver about this event */
259 ret
= device
->driver
->pm
->resume(device
);
267 #if 0//because not used
268 static int mali_pm_freeze(struct device
*device
)
272 MALI_DEBUG_PRINT(1, ("Mali PM: %s\n", __FUNCTION__
));
274 if (NULL
!= device
->driver
&&
275 NULL
!= device
->driver
->pm
&&
276 NULL
!= device
->driver
->pm
->freeze
)
278 /* Need to notify Mali driver about this event */
279 ret
= device
->driver
->pm
->freeze(device
);
285 static int mali_pm_thaw(struct device
*device
)
289 MALI_DEBUG_PRINT(1, ("Mali PM: %s\n", __FUNCTION__
));
291 if (NULL
!= device
->driver
&&
292 NULL
!= device
->driver
->pm
&&
293 NULL
!= device
->driver
->pm
->thaw
)
295 /* Need to notify Mali driver about this event */
296 ret
= device
->driver
->pm
->thaw(device
);
303 #ifdef CONFIG_PM_RUNTIME
304 static int mali_runtime_suspend(struct device
*device
)
308 MALI_DEBUG_PRINT(4, ("mali_runtime_suspend() called\n"));
310 if (NULL
!= device
->driver
&&
311 NULL
!= device
->driver
->pm
&&
312 NULL
!= device
->driver
->pm
->runtime_suspend
)
314 /* Need to notify Mali driver about this event */
315 ret
= device
->driver
->pm
->runtime_suspend(device
);
318 mali_platform_power_mode_change(MALI_POWER_MODE_LIGHT_SLEEP
);
323 static int mali_runtime_resume(struct device
*device
)
327 MALI_DEBUG_PRINT(4, ("mali_runtime_resume() called\n"));
329 mali_platform_power_mode_change(MALI_POWER_MODE_ON
);
331 if (NULL
!= device
->driver
&&
332 NULL
!= device
->driver
->pm
&&
333 NULL
!= device
->driver
->pm
->runtime_resume
)
335 /* Need to notify Mali driver about this event */
336 ret
= device
->driver
->pm
->runtime_resume(device
);
342 static int mali_runtime_idle(struct device
*device
)
344 MALI_DEBUG_PRINT(4, ("mali_runtime_idle() called\n"));
346 if (NULL
!= device
->driver
&&
347 NULL
!= device
->driver
->pm
&&
348 NULL
!= device
->driver
->pm
->runtime_idle
)
350 /* Need to notify Mali driver about this event */
351 int ret
= device
->driver
->pm
->runtime_idle(device
);
358 pm_runtime_suspend(device
);
362 #endif /// CONFIG_PM_RUNTIME