gpu: pvr: round the SGX fclock rate to the nearest supported
authorImre Deak <imre.deak@nokia.com>
Tue, 20 Apr 2010 12:00:39 +0000 (15:00 +0300)
committerGrazvydas Ignotas <notasas@gmail.com>
Sun, 20 May 2012 18:09:41 +0000 (21:09 +0300)
This is needed since clk_set_rate accepts only exact values.

Signed-off-by: Imre Deak <imre.deak@nokia.com>
pvr/sysutils.c

index 874692d..0f803d0 100644 (file)
@@ -457,6 +457,7 @@ static enum PVRSRV_ERROR InitSgxClocks(struct SYS_DATA *psSysData)
        struct SYS_SPECIFIC_DATA *psSysSpecData = psSysData->pvSysSpecificData;
        struct clk *psCLK;
        struct clk *core_ck = NULL;
+       unsigned long rate;
        int r;
 
        psCLK = clk_get(NULL, "sgx_fck");
@@ -478,17 +479,18 @@ static enum PVRSRV_ERROR InitSgxClocks(struct SYS_DATA *psSysData)
        }
        clk_put(core_ck);
 
-       r = clk_set_rate(psSysSpecData->psSGX_FCK,
-                        sgx_get_max_freq());
+       /* +1 to account for rounding errors */
+       rate = clk_round_rate(psSysSpecData->psSGX_FCK, sgx_get_max_freq() + 1);
+       r = clk_set_rate(psSysSpecData->psSGX_FCK, rate);
        if (r < 0) {
-               unsigned long rate;
-
                rate = clk_get_rate(psSysSpecData->psSGX_FCK);
                rate /= 1000000;
                pr_warning("error %d when setting SGX fclk to %luMHz, "
                           "falling back to %luMHz\n",
                           r, sgx_get_max_freq() / 1000000, rate);
-       }
+       } else {
+               pr_info("SGX clock rate %lu MHz\n", rate / 1000000);
+       };
 
        RegisterConstraintNotifications(psSysSpecData);
        return PVRSRV_OK;