- unsigned long flags;
- static IMG_UINT32 temp_tmp;
- IMG_UINT32 fps = 0;
- IMG_UINT32 fps_limit;
- IMG_UINT32 policy;
- IMG_INT32 absload;
- IMG_INT32 new_index;
- struct rk_context *platform;
-
- platform = dev_get_drvdata(&gpsPVRLDMDev->dev);
-
- mutex_lock(&rgx_enable_clock_lock);
-
- if (!rk33_dvfs_get_enable_status())
- {
- mutex_unlock(&rgx_enable_clock_lock);
- return;
- }
-
- fps = rk_get_real_fps(0);
-
- platform->temperature_time++;
- /*
- temp_tmp += rockchip_tsadc_get_temp(2);
- */
- if (platform->temperature_time >= gpu_temp_statis_time)
- {
- platform->temperature_time = 0;
- platform->temperature = temp_tmp / gpu_temp_statis_time;
- temp_tmp = 0;
- /*pr_info("platform->temperature = %d\n",platform->temperature);*/
- }
-
- spin_lock_irqsave(&rgx_dvfs_spinlock, flags);
-
- platform->abs_load[0] = platform->abs_load[1];
- platform->abs_load[1] = platform->abs_load[2];
- platform->abs_load[2] = platform->abs_load[3];
- platform->abs_load[3] = (platform->utilisation * rgx_dvfs_infotbl[platform->freq_level].clock * rgx_dvfs_infotbl[platform->freq_level].coef) / 100;
- absload = (platform->abs_load[3] * 4 + platform->abs_load[2] * 3 + platform->abs_load[1] * 2 + platform->abs_load[0]);
-
- /*
- policy = rockchip_pm_get_policy();
- */
- policy = ROCKCHIP_PM_POLICY_NORMAL;
-
- if (ROCKCHIP_PM_POLICY_PERFORMANCE == policy)
- {
- platform->freq_level = RGX_DVFS_STEP - 1; /*Highest level when performance mode*/
- }
- else if (platform->fix_freq > 0)
- {
- platform->freq_level = rk33_dvfs_get_level(platform->fix_freq);
-
- if (platform->debug_level == DBG_HIGH)
- printk("fix clock=%d\n", platform->fix_freq);
- }
- else
- {
- fps_limit = (ROCKCHIP_PM_POLICY_NORMAL == policy) ? LIMIT_FPS : LIMIT_FPS_POWER_SAVE;
- /*
- printk("policy : %d , fps_limit = %d\n",policy,fps_limit);
- */
-
-
- /*give priority to temperature unless in performance mode */
- if (platform->temperature > gpu_temp_limit)
- {
- if (platform->freq_level > 0)
- platform->freq_level--;
-
- if (gpu_temp_statis_time > 1)
- platform->temperature = 0;
- }
- else if (absload == 0 || platform->gpu_active == IMG_FALSE)
- {
- platform->freq_level = 0;
- }
- else if ((platform->freq_level < RGX_DVFS_STEP - 1) && fps < fps_limit)
- {
- //freq_hint=0 or freq_hint>sRK30_DVFS.u8FreqNums, select freq automatically, find the right index
- for (new_index = 0; new_index < RGX_DVFS_STEP; new_index++)
- {
- if (absload <= (rgx_dvfs_infotbl[new_index].clock*rgx_dvfs_infotbl[new_index].coef*9))
- {
- if (platform->debug_level == DBG_HIGH)
- printk("absload=%d,cur_coef[%d]=%d\n", absload, new_index, rgx_dvfs_infotbl[new_index].clock*rgx_dvfs_infotbl[new_index].coef*9);
- break;
- }
- }
-
- //ensure the new_index in the reasonable range
- if (new_index >= RGX_DVFS_STEP)
- {
- new_index = RGX_DVFS_STEP - 1;
- }
-
- //if fps>=50, should not run at the higher frequency
- if (new_index > platform->freq_level && fps >= fps_limit)
- {
- new_index = platform->freq_level;
- }
- //if running at highest frequency & fps>53 & absload<90%, try to run at a lower frequency
- else if (platform->freq_level == RGX_DVFS_STEP - 1 && fps > 53 && absload <= (rgx_dvfs_infotbl[new_index].clock*rgx_dvfs_infotbl[new_index].coef*9))
- {
- new_index = platform->freq_level - 1;
- }
- if (platform->debug_level == DBG_HIGH)
- printk("absload=%d,freq_level=%d,freq=%dM\n", absload, new_index, rgx_dvfs_infotbl[new_index].clock);
-
- platform->freq_level = new_index;
- }
- }
+ unsigned long flags;
+ static IMG_UINT32 temp_tmp;
+ IMG_UINT32 fps = 0;
+ IMG_UINT32 fps_limit;
+ IMG_UINT32 policy;
+ IMG_INT32 absload;
+ IMG_INT32 new_index;
+ struct rk_context *platform;
+
+ platform = dev_get_drvdata(&gpsPVRLDMDev->dev);
+
+ mutex_lock(&rgx_enable_clock_lock);
+
+ if (!rk33_dvfs_get_enable_status()) {
+ mutex_unlock(&rgx_enable_clock_lock);
+ return;
+ }
+
+ fps = rk_get_real_fps(0);
+
+ platform->temperature_time++;
+ /*
+ temp_tmp += rockchip_tsadc_get_temp(2);
+ */
+ if (platform->temperature_time >= gpu_temp_statis_time) {
+ platform->temperature_time = 0;
+ platform->temperature = temp_tmp / gpu_temp_statis_time;
+ temp_tmp = 0;
+ /*pr_info("platform->temperature = %d\n",platform->temperature); */
+ }
+
+ spin_lock_irqsave(&rgx_dvfs_spinlock, flags);
+
+ platform->abs_load[0] = platform->abs_load[1];
+ platform->abs_load[1] = platform->abs_load[2];
+ platform->abs_load[2] = platform->abs_load[3];
+ platform->abs_load[3] =
+ (platform->utilisation *
+ rgx_dvfs_infotbl[platform->freq_level].clock *
+ rgx_dvfs_infotbl[platform->freq_level].coef) / 100;
+ absload =
+ (platform->abs_load[3] * 4 + platform->abs_load[2] * 3 +
+ platform->abs_load[1] * 2 + platform->abs_load[0]);
+
+ /*
+ policy = rockchip_pm_get_policy();
+ */
+ policy = ROCKCHIP_PM_POLICY_NORMAL;
+
+ if (ROCKCHIP_PM_POLICY_PERFORMANCE == policy) {
+ platform->freq_level = RGX_DVFS_STEP - 1; /*Highest level when performance mode */
+ } else if (platform->fix_freq > 0) {
+ platform->freq_level = rk33_dvfs_get_level(platform->fix_freq);
+
+ if (platform->debug_level == DBG_HIGH)
+ printk("fix clock=%d\n", platform->fix_freq);
+ } else {
+ fps_limit =
+ (ROCKCHIP_PM_POLICY_NORMAL ==
+ policy) ? LIMIT_FPS : LIMIT_FPS_POWER_SAVE;
+ /*
+ printk("policy : %d , fps_limit = %d\n",policy,fps_limit);
+ */
+
+ /*give priority to temperature unless in performance mode */
+ if (platform->temperature > gpu_temp_limit) {
+ if (platform->freq_level > 0)
+ platform->freq_level--;
+
+ if (gpu_temp_statis_time > 1)
+ platform->temperature = 0;
+ } else if (absload == 0 || platform->gpu_active == IMG_FALSE) {
+ platform->freq_level = 0;
+ } else if ((platform->freq_level < RGX_DVFS_STEP - 1)
+ && fps < fps_limit) {
+ //freq_hint=0 or freq_hint>sRK30_DVFS.u8FreqNums, select freq automatically, find the right index
+ for (new_index = 0; new_index < RGX_DVFS_STEP;
+ new_index++) {
+ if (absload <=
+ (rgx_dvfs_infotbl[new_index].clock *
+ rgx_dvfs_infotbl[new_index].coef * 9)) {
+ if (platform->debug_level == DBG_HIGH)
+ printk
+ ("absload=%d,cur_coef[%d]=%d\n",
+ absload, new_index,
+ rgx_dvfs_infotbl
+ [new_index].clock *
+ rgx_dvfs_infotbl
+ [new_index].coef * 9);
+ break;
+ }
+ }
+
+ //ensure the new_index in the reasonable range
+ if (new_index >= RGX_DVFS_STEP) {
+ new_index = RGX_DVFS_STEP - 1;
+ }
+ //if fps>=50, should not run at the higher frequency
+ if (new_index > platform->freq_level
+ && fps >= fps_limit) {
+ new_index = platform->freq_level;
+ }
+ //if running at highest frequency & fps>53 & absload<90%, try to run at a lower frequency
+ else if (platform->freq_level == RGX_DVFS_STEP - 1
+ && fps > 53
+ && absload <=
+ (rgx_dvfs_infotbl[new_index].clock *
+ rgx_dvfs_infotbl[new_index].coef * 9)) {
+ new_index = platform->freq_level - 1;
+ }
+ if (platform->debug_level == DBG_HIGH)
+ printk("absload=%d,freq_level=%d,freq=%dM\n",
+ absload, new_index,
+ rgx_dvfs_infotbl[new_index].clock);
+
+ platform->freq_level = new_index;
+ }
+ }