2 * This confidential and proprietary software may be used only as
3 * authorised by a licensing agreement from ARM Limited
4 * (C) COPYRIGHT 2010-2014 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.
13 * Implementation of the callback functions from common power management
16 #include <linux/sched.h>
18 #ifdef CONFIG_PM_RUNTIME
19 #include <linux/pm_runtime.h>
20 #endif /* CONFIG_PM_RUNTIME */
21 #include <linux/platform_device.h>
22 #include <linux/version.h>
24 #include "mali_kernel_common.h"
25 #include "mali_kernel_linux.h"
27 static _mali_osk_atomic_t mali_pm_ref_count;
29 void _mali_osk_pm_dev_enable(void)
31 _mali_osk_atomic_init(&mali_pm_ref_count, 0);
34 void _mali_osk_pm_dev_disable(void)
36 _mali_osk_atomic_term(&mali_pm_ref_count);
39 /* Can NOT run in atomic context */
40 _mali_osk_errcode_t _mali_osk_pm_dev_ref_add(void)
42 #ifdef CONFIG_PM_RUNTIME
44 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
45 err = pm_runtime_get_sync(&(mali_platform_device->dev));
46 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
47 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
50 MALI_PRINT_ERROR(("Mali OSK PM: pm_runtime_get_sync() returned error code %d\n", err));
51 return _MALI_OSK_ERR_FAULT;
53 _mali_osk_atomic_inc(&mali_pm_ref_count);
54 MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
56 return _MALI_OSK_ERR_OK;
59 /* Can run in atomic context */
60 void _mali_osk_pm_dev_ref_dec(void)
62 #ifdef CONFIG_PM_RUNTIME
63 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
64 _mali_osk_atomic_dec(&mali_pm_ref_count);
65 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
66 pm_runtime_mark_last_busy(&(mali_platform_device->dev));
67 pm_runtime_put_autosuspend(&(mali_platform_device->dev));
69 pm_runtime_put(&(mali_platform_device->dev));
71 MALI_DEBUG_PRINT(4, ("Mali OSK PM: Power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
75 /* Can run in atomic context */
76 mali_bool _mali_osk_pm_dev_ref_add_no_power_on(void)
78 #ifdef CONFIG_PM_RUNTIME
80 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
81 pm_runtime_get_noresume(&(mali_platform_device->dev));
82 ref = _mali_osk_atomic_read(&mali_pm_ref_count);
83 MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref taken (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
84 return ref > 0 ? MALI_TRUE : MALI_FALSE;
90 /* Can run in atomic context */
91 void _mali_osk_pm_dev_ref_dec_no_power_on(void)
93 #ifdef CONFIG_PM_RUNTIME
94 MALI_DEBUG_ASSERT_POINTER(mali_platform_device);
95 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 37))
96 pm_runtime_put_autosuspend(&(mali_platform_device->dev));
98 pm_runtime_put(&(mali_platform_device->dev));
100 MALI_DEBUG_PRINT(4, ("Mali OSK PM: No-power ref released (%u)\n", _mali_osk_atomic_read(&mali_pm_ref_count)));
104 void _mali_osk_pm_dev_barrier(void)
106 #ifdef CONFIG_PM_RUNTIME
107 pm_runtime_barrier(&(mali_platform_device->dev));