dvfs gets volt chngeing time for regulator
authorxxx <xxx@rock-chips.com>
Sat, 23 Feb 2013 03:11:42 +0000 (11:11 +0800)
committerxxx <xxx@rock-chips.com>
Sat, 23 Feb 2013 03:11:42 +0000 (11:11 +0800)
arch/arm/plat-rk/dvfs.c
arch/arm/plat-rk/include/plat/dvfs.h

index d93b69d45be5fb9a40875ac0ee56f2a9ccb05ac6..1b991997c1510b13f7947cc2455230ee5dbc0d36 100755 (executable)
@@ -43,6 +43,31 @@ static int dump_dbg_map(char *buf);
 \r
 \r
 /**************************************vd regulator functions***************************************/\r
+static void dvfs_volt_up_delay(struct vd_node *vd,int new_volt, int old_volt)\r
+{\r
+       int u_time;\r
+       if(new_volt<=old_volt)\r
+               return;\r
+       if(vd->volt_time_flag>0)        \r
+               u_time=regulator_set_voltage_time(vd->regulator,old_volt,new_volt);\r
+       else\r
+               u_time=-1;              \r
+       if(u_time<0)// regulator is not suported time,useing default time\r
+       {\r
+               DVFS_DBG("%s:vd %s is not suported getting delay time,so we use default\n",\r
+                               __FUNCTION__,vd->name);\r
+               u_time=((new_volt) - (old_volt)) >> 9;\r
+       }\r
+       DVFS_DBG("%s:vd %s volt %d to %d delay %d us\n",__FUNCTION__,vd->name,\r
+               old_volt,new_volt,u_time);\r
+       if (u_time >= 1000) {\r
+               mdelay(u_time / 1000);\r
+               udelay(u_time % 1000);\r
+               DVFS_ERR("regulator set vol delay is larger 1ms,old is %d,new is %d\n",old_volt,new_volt);\r
+       } else if (u_time) {\r
+               udelay(u_time);\r
+       }                       \r
+}\r
 int dvfs_regulator_set_voltage_readback(struct regulator *regulator, int min_uV, int max_uV)\r
 {\r
        int ret = 0, read_back = 0;\r
@@ -171,6 +196,50 @@ static void dvfs_table_round_volt(struct clk_node  *dvfs_clk)
        }\r
        mutex_unlock(&mutex);\r
 }\r
+void dvfs_vd_get_regulator_volt_time_info(struct vd_node *vd)\r
+{\r
+       if(vd->volt_time_flag<=0)// check regulator support get uping vol timer\r
+       {\r
+               vd->volt_time_flag=dvfs_regulator_set_voltage_time(vd->regulator,vd->cur_volt,vd->cur_volt+200*1000);\r
+               if(vd->volt_time_flag<0)\r
+               {\r
+                       DVFS_DBG("%s,vd %s volt_time is no support\n",__FUNCTION__,vd->name);\r
+               }\r
+               else\r
+               {\r
+                       DVFS_DBG("%s,vd %s volt_time is support,up 200mv need delay %d us\n",__FUNCTION__,vd->name,vd->volt_time_flag);\r
+\r
+               }       \r
+       }\r
+}\r
+\r
+void dvfs_vd_get_regulator_mode_info(struct vd_node *vd)\r
+{\r
+       //REGULATOR_MODE_FAST\r
+       if(vd->mode_flag<=0)// check regulator support get uping vol timer\r
+       {\r
+               vd->mode_flag=dvfs_regulator_get_mode(vd->regulator);\r
+               if(vd->mode_flag==REGULATOR_MODE_FAST||vd->mode_flag==REGULATOR_MODE_NORMAL\r
+                       ||vd->mode_flag==REGULATOR_MODE_IDLE||vd->mode_flag==REGULATOR_MODE_STANDBY)\r
+               {\r
+                       if(dvfs_regulator_set_mode(vd->regulator,vd->mode_flag)<0)\r
+                       {\r
+                               vd->mode_flag=0;// check again\r
+                       }\r
+                       \r
+               }\r
+               if(vd->mode_flag>0)\r
+               {\r
+                       DVFS_DBG("%s,vd %s mode(now is %d) support\n",__FUNCTION__,vd->name,vd->mode_flag);\r
+               }\r
+               else\r
+               {\r
+                       DVFS_DBG("%s,vd %s mode is not support now check\n",__FUNCTION__,vd->name);\r
+\r
+               }\r
+               \r
+       }\r
+}\r
 struct regulator *dvfs_get_regulator(char *regulator_name) \r
 {\r
        struct vd_node *vd;\r
@@ -519,6 +588,8 @@ int clk_enable_dvfs(struct clk *clk)
                                // DVFS_DBG("dvfs_regulator_get(%s)\n",dvfs_clk->vd->regulator_name);\r
                                clk_enable_dvfs_regulator_check(dvfs_clk->vd);\r
                                dvfs_get_vd_regulator_volt_list(dvfs_clk->vd);\r
+                               dvfs_vd_get_regulator_volt_time_info(dvfs_clk->vd);\r
+                               //dvfs_vd_get_regulator_mode_info(dvfs_clk->vd);\r
                        } else {\r
                                //dvfs_clk->vd->regulator = NULL;\r
                                dvfs_clk->enable_dvfs = 0;\r
@@ -626,7 +697,9 @@ int rk_regist_vd(struct vd_node *vd)
        list_add(&vd->node, &rk_dvfs_tree);\r
        INIT_LIST_HEAD(&vd->pd_list);\r
        INIT_LIST_HEAD(&vd->req_volt_list);\r
-\r
+       vd->mode_flag=0;\r
+       vd->volt_time_flag=0;\r
+       vd->n_voltages=0;\r
        mutex_unlock(&mutex);\r
        return 0;\r
 }\r
@@ -825,7 +898,8 @@ int dvfs_scale_volt(struct vd_node *vd_clk, struct vd_node *vd_dep,
                if (vd_clk->cur_volt != volt) {\r
                        DVFS_DBG("\t\t%s:%d->%d\n", vd_clk->name, vd_clk->cur_volt, volt);\r
                        ret = dvfs_regulator_set_voltage_readback(regulator, volt, volt);\r
-                       udelay(get_volt_up_delay(volt, volt_pre));\r
+                       //udelay(get_volt_up_delay(volt, volt_pre));\r
+                       dvfs_volt_up_delay(vd_clk,volt, volt_pre);\r
                        if (ret < 0) {\r
                                DVFS_ERR("%s %s set voltage up err ret = %d, Vnew = %d(was %d)mV\n",\r
                                                __func__, vd_clk->name, ret, volt_new, volt_old);\r
@@ -836,7 +910,8 @@ int dvfs_scale_volt(struct vd_node *vd_clk, struct vd_node *vd_dep,
                if (vd_dep->cur_volt != volt_dep) {\r
                        DVFS_DBG("\t\t%s:%d->%d\n", vd_dep->name, vd_dep->cur_volt, volt_dep);\r
                        ret = dvfs_regulator_set_voltage_readback(regulator_dep, volt_dep, volt_dep);\r
-                       udelay(get_volt_up_delay(volt_dep, volt_dep_pre));\r
+                       //udelay(get_volt_up_delay(volt_dep, volt_dep_pre));\r
+                       dvfs_volt_up_delay(vd_dep,volt_dep, volt_dep_pre);\r
                        if (ret < 0) {\r
                                DVFS_ERR("depend %s %s set voltage up err ret = %d, Vnew = %d(was %d)mV\n",\r
                                                __func__, vd_dep->name, ret, volt_dep_new, volt_dep_old);\r
@@ -887,7 +962,8 @@ int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new)
        DVFS_DBG("ENTER %s, volt=%d(old=%d)\n", __func__, volt_new, vd_clk->cur_volt);\r
        if (!IS_ERR_OR_NULL(vd_clk->regulator)) {\r
                ret = dvfs_regulator_set_voltage_readback(vd_clk->regulator, volt_new, volt_new);\r
-               udelay(get_volt_up_delay(volt_new, vd_clk->cur_volt));\r
+               //udelay(get_volt_up_delay(volt_new, vd_clk->cur_volt));\r
+               dvfs_volt_up_delay(vd_clk,volt_new, vd_clk->cur_volt);\r
                if (ret < 0) {\r
                        vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
                        DVFS_ERR("%s %s set voltage up err ret = %d, Vnew = %d(was %d)mV\n",\r
@@ -947,7 +1023,8 @@ int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int v
                if (vd_clk->cur_volt != volt_new_corrected) {\r
                        DVFS_DBG("%s:%d->%d\n", vd_clk->name, vd_clk->cur_volt, volt_new_corrected);\r
                        ret = dvfs_regulator_set_voltage_readback(regulator, volt_new_corrected, volt_new_corrected);\r
-                       udelay(get_volt_up_delay(volt_new_corrected, vd_clk->cur_volt));\r
+                       //udelay(get_volt_up_delay(volt_new_corrected, vd_clk->cur_volt));\r
+                       dvfs_volt_up_delay(vd_clk,volt_new_corrected, vd_clk->cur_volt);\r
                        if (ret < 0) {\r
                                DVFS_ERR("%s %s set voltage up err ret = %d, Vnew = %d(was %d)mV\n",\r
                                                __func__, vd_clk->name, ret, volt_new_corrected, vd_clk->cur_volt);\r
@@ -958,7 +1035,8 @@ int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int v
                if (vd_dep->cur_volt != volt_dep_new_corrected) {\r
                        DVFS_DBG("%s:%d->%d\n", vd_clk->name, vd_clk->cur_volt, volt_dep_new_corrected);\r
                        ret = dvfs_regulator_set_voltage_readback(regulator_dep, volt_dep_new_corrected, volt_dep_new_corrected);\r
-                       udelay(get_volt_up_delay(volt_dep_new_corrected, vd_dep->cur_volt));\r
+                       //udelay(get_volt_up_delay(volt_dep_new_corrected, vd_dep->cur_volt));\r
+                       dvfs_volt_up_delay(vd_dep,volt_dep_new_corrected, vd_dep->cur_volt);\r
                        if (ret < 0) {\r
                                DVFS_ERR("depend %s %s set voltage up err ret = %d, Vnew = %d(was %d)mV\n",\r
                                                __func__, vd_dep->name, ret, volt_dep_new_corrected, vd_dep->cur_volt);\r
index 2aa6a09b3bbf8badbda90832641ba78ce068537c..5278f910421865cf2dc96f0c8b5236648e565692 100755 (executable)
@@ -43,6 +43,8 @@ typedef int (*clk_dvfs_target_callback)(struct clk *clk, unsigned long rate,
 struct vd_node {\r
        char                    *name;\r
        char                    *regulator_name;\r
+       int                     volt_time_flag;// =0 ,is no initing checking ,>0 ,support,<0 not support\r
+       int                     mode_flag;// =0 ,is no initing checking ,>0 ,support,<0 not support\r
        int                     cur_volt;\r
        int                     volt_set_flag;\r
        struct regulator        *regulator;\r
@@ -171,6 +173,9 @@ struct dvfs_arm_table {
 #define dvfs_regulator_put(regu) regulator_put((regu))\r
 #define dvfs_regulator_set_voltage(regu,min_uV,max_uV) regulator_set_voltage((regu),(min_uV),(max_uV))\r
 #define dvfs_regulator_get_voltage(regu) regulator_get_voltage((regu))\r
+#define dvfs_regulator_set_voltage_time(regu, old_uV, new_uV) regulator_set_voltage_time((regu), (old_uV), (new_uV))\r
+#define dvfs_regulator_set_mode(regu, mode) regulator_set_mode((regu), (mode))\r
+#define dvfs_regulator_get_mode(regu) regulator_get_mode((regu))\r
 #define dvfs_regulator_list_voltage(regu,selector) regulator_list_voltage((regu),(selector))\r
 #define dvfs_regulator_count_voltages(regu) regulator_count_voltages((regu))\r
 \r