From 801c70b2c1001ddd2acc6a64f33b2749dbbf7fa9 Mon Sep 17 00:00:00 2001 From: Loren HUANG Date: Mon, 14 Jan 2013 16:53:12 +0800 Subject: [PATCH] ENGR00240988-10 Add runtime pm function call in gpu driver Cherry-pick from imx_3.5.7 branch. -Add runtime pm function. -Set bus frequency to high when gpu power is on. Signed-off-by: Loren HUANG Acked-by: Lily Zhang --- .../os/linux/kernel/gc_hal_kernel_device.c | 8 +++++- .../os/linux/kernel/gc_hal_kernel_device.h | 2 ++ .../os/linux/kernel/gc_hal_kernel_driver.c | 26 +++++++++++++++++-- .../hal/os/linux/kernel/gc_hal_kernel_os.c | 19 +++++++++++--- 4 files changed, 48 insertions(+), 7 deletions(-) diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.c b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.c index a5eed3539a6e..b3b28ec29cfb 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.c +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.c @@ -28,6 +28,7 @@ #include #include #include +#include #define _GC_OBJ_ZONE gcvZONE_DEVICE @@ -359,9 +360,14 @@ gckGALDEVICE_Construct( gckDebugFileSystemSetCurrentNode(device->dbgnode); } } +#ifdef CONFIG_PM + /*Init runtime pm for gpu*/ + pm_runtime_enable(pdev); + device->pmdev = pdev; +#endif + #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) device->gpu_regulator =(struct regulator*)0xffffffff ; - #else /*get gpu regulator*/ device->gpu_regulator = regulator_get(pdev, "cpu_vddgpu"); diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.h b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.h index 1635ff690db7..f990adf9c2fd 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.h +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_device.h @@ -93,6 +93,8 @@ typedef struct _gckGALDEVICE /*Power management.*/ struct regulator *gpu_regulator; + /*Run time pm*/ + struct device *pmdev; } * gckGALDEVICE; diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_driver.c b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_driver.c index 4da49fe3c7b0..7586bca52095 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_driver.c +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_driver.c @@ -43,9 +43,10 @@ #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) #include +#else +#include +#include #endif - - /* Zone used for header/footer. */ #define _GC_OBJ_ZONE gcvZONE_DRIVER @@ -1164,6 +1165,24 @@ static const struct of_device_id mxs_gpu_dt_ids[] = { {/* sentinel */} }; MODULE_DEVICE_TABLE(of, mxs_gpu_dt_ids); + +#ifdef CONFIG_PM +int gpu_runtime_suspend(struct device *dev) +{ + release_bus_freq(BUS_FREQ_HIGH); + return 0; +} + +int gpu_runtime_resume(struct device *dev) +{ + request_bus_freq(BUS_FREQ_HIGH); + return 0; +} + +static const struct dev_pm_ops gpu_pm_ops = { + SET_RUNTIME_PM_OPS(gpu_runtime_suspend, gpu_runtime_resume, NULL) +}; +#endif #endif static struct platform_driver gpu_driver = { @@ -1177,6 +1196,9 @@ static struct platform_driver gpu_driver = { .name = DEVICE_NAME, #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) .of_match_table = mxs_gpu_dt_ids, +#if CONFIG_PM + .pm = &gpu_pm_ops, +#endif #endif } }; diff --git a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c index e9e4e07106a6..cb6d3ea2c16f 100644 --- a/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c +++ b/drivers/mxc/gpu-viv/hal/os/linux/kernel/gc_hal_kernel_os.c @@ -39,6 +39,7 @@ #include #endif #include +#include #define _GC_OBJ_ZONE gcvZONE_OS @@ -6738,9 +6739,14 @@ gckOS_SetGPUPower( } #endif } - if((Power == gcvTRUE) && (oldPowerState == gcvFALSE) && - !IS_ERR(Os->device->gpu_regulator)) + if((Power == gcvTRUE) && (oldPowerState == gcvFALSE)) + { + if(!IS_ERR(Os->device->gpu_regulator)) regulator_enable(Os->device->gpu_regulator); +#ifdef CONFIG_PM + pm_runtime_get_sync(Os->device->pmdev); +#endif + } #if LINUX_VERSION_CODE < KERNEL_VERSION(3,5,0) if (Clock == gcvTRUE) { @@ -6843,9 +6849,14 @@ gckOS_SetGPUPower( } } #endif - if((Power == gcvFALSE) && (oldPowerState == gcvTRUE) && - !IS_ERR(Os->device->gpu_regulator)) + if((Power == gcvFALSE) && (oldPowerState == gcvTRUE)) + { +#ifdef CONFIG_PM + pm_runtime_put_sync(Os->device->pmdev); +#endif + if(!IS_ERR(Os->device->gpu_regulator)) regulator_disable(Os->device->gpu_regulator); + } /* TODO: Put your code here. */ gcmkFOOTER_NO(); return gcvSTATUS_OK; -- 2.39.5