mov dvfs global fun to rk plat
authorxxx <xxx@rock-chips.com>
Mon, 21 Jan 2013 09:53:00 +0000 (17:53 +0800)
committerxxx <xxx@rock-chips.com>
Mon, 21 Jan 2013 09:55:09 +0000 (17:55 +0800)
arch/arm/mach-rk2928/clock_data.c [changed mode: 0644->0755]
arch/arm/mach-rk2928/dvfs.c
arch/arm/mach-rk30/clock_data-rk3066b.c
arch/arm/mach-rk30/clock_data.c [changed mode: 0755->0644]
arch/arm/mach-rk30/dvfs.c
arch/arm/plat-rk/Makefile [changed mode: 0644->0755]
arch/arm/plat-rk/dvfs.c [new file with mode: 0755]
arch/arm/plat-rk/include/plat/dvfs.h [changed mode: 0644->0755]

old mode 100644 (file)
new mode 100755 (executable)
index 346ad8f..1b6ebce
@@ -2728,11 +2728,11 @@ void __init _rk2928_clock_data_init(unsigned long gpll,unsigned long cpll,int fl
        CLKDATA_DBG("%s clks init finish\n", __func__);
 }
 
-
+int rk292x_dvfs_init(void);
 void __init rk2928_clock_data_init(unsigned long gpll,unsigned long cpll,u32 flags)
 {
        printk("%s version:     2012-8-14\n", __func__);
        _rk2928_clock_data_init(gpll,cpll,flags);
-       rk30_dvfs_init();
+       rk292x_dvfs_init();
 }
 
index e8d086ddf102852f8c366c2ae504ae794c32f2d9..046118ba7831eff5a602eb894a45cc561c314f54 100755 (executable)
 #include <linux/io.h>\r
 #include <linux/hrtimer.h>\r
 \r
-#if 1\r
-#define DVFS_DBG(fmt, args...) {while(0);}\r
-#else\r
-#define DVFS_DBG(fmt, args...) printk(KERN_DEBUG "DVFS DBG:\t"fmt, ##args)\r
-#endif\r
-\r
-#define DVFS_SET_VOLT_FAILURE  1\r
-#define DVFS_SET_VOLT_SUCCESS  0\r
-\r
-#define DVFS_ERR(fmt, args...) printk(KERN_ERR "DVFS ERR:\t"fmt, ##args)\r
-#define DVFS_LOG(fmt, args...) printk(KERN_DEBUG "DVFS LOG:\t"fmt, ##args)\r
-\r
-#define dvfs_regulator_get(dev,id) regulator_get((dev),(id))\r
-#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
-\r
-#define dvfs_clk_get(a,b) clk_get((a),(b))\r
-#define dvfs_clk_get_rate_kz(a) (clk_get_rate((a))/1000)\r
-#define dvfs_clk_set_rate(a,b) clk_set_rate((a),(b))\r
-#define dvfs_clk_enable(a) clk_enable((a))\r
-#define dvfs_clk_disable(a) clk_disable((a))\r
-\r
-#define DVFS_MHZ (1000*1000)\r
-#define DVFS_KHZ (1000)\r
-\r
-#define DVFS_V (1000*1000)\r
-#define DVFS_MV (1000)\r
-\r
-static LIST_HEAD(rk_dvfs_tree);\r
-static DEFINE_MUTEX(mutex);\r
-static DEFINE_MUTEX(rk_dvfs_mutex);\r
-\r
-static int dump_dbg_map(char* buf);\r
-\r
-#define PD_ON  1\r
-#define PD_OFF 0\r
-\r
-#define get_volt_up_delay(new_volt, old_volt)  \\r
-       ((new_volt) > (old_volt) ? (((new_volt) - (old_volt)) >> 9) : 0)\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
-       ret = dvfs_regulator_set_voltage(regulator, max_uV, max_uV);\r
-       if (ret < 0) {\r
-               DVFS_ERR("%s now read back to check voltage\n", __func__);\r
-\r
-               /* read back to judge if it is already effect */\r
-               mdelay(2);\r
-               read_back = dvfs_regulator_get_voltage(regulator); \r
-               if (read_back == max_uV) {\r
-                       DVFS_ERR("%s set ERROR but already effected, volt=%d\n", __func__, read_back);\r
-                       ret = 0;\r
-               } else {\r
-                       DVFS_ERR("%s set ERROR AND NOT effected, volt=%d\n", __func__, read_back);\r
-               }\r
-       }\r
-       return ret;\r
-}\r
-\r
-struct regulator* dvfs_get_regulator(char *regulator_name)\r
-{\r
-       struct vd_node *vd;\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (strcmp(regulator_name, vd->regulator_name) == 0) {\r
-                       return vd->regulator;\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-\r
-int dvfs_clk_enable_limit(struct clk *clk, unsigned int min_rate, unsigned max_rate)\r
-{\r
-       struct clk_node* dvfs_clk;\r
-       u32 rate = 0;\r
-       dvfs_clk = clk->dvfs_info;\r
-\r
-       dvfs_clk->freq_limit_en = 1;\r
-       dvfs_clk->min_rate = min_rate;\r
-       dvfs_clk->max_rate = max_rate;\r
-       \r
-       rate = clk_get_rate(clk);\r
-       if (rate < min_rate) \r
-               dvfs_clk_set_rate(clk, min_rate);\r
-       else if (rate > max_rate)\r
-               dvfs_clk_set_rate(clk, max_rate);\r
-       return 0;\r
-}\r
-\r
-int dvfs_clk_disable_limit(struct clk *clk)\r
-{\r
-       struct clk_node* dvfs_clk;\r
-       dvfs_clk = clk->dvfs_info;\r
-       \r
-       dvfs_clk->freq_limit_en = 0;\r
-       \r
-       return 0;\r
-}\r
-\r
-int is_support_dvfs(struct clk_node *dvfs_info)\r
-{\r
-       return (dvfs_info->vd && dvfs_info->vd->vd_dvfs_target && dvfs_info->enable_dvfs);\r
-}\r
-\r
-int dvfs_set_rate(struct clk *clk, unsigned long rate)\r
-{\r
-       int ret = 0;\r
-       struct vd_node *vd;\r
-       DVFS_DBG("%s(%s(%lu))\n", __func__, clk->name, rate);\r
-       if (!clk->dvfs_info) {\r
-               DVFS_ERR("%s :This clk do not support dvfs!\n", __func__);\r
-               ret = -1;\r
-       } else {\r
-               vd = clk->dvfs_info->vd;\r
-               // mutex_lock(&vd->dvfs_mutex);\r
-               mutex_lock(&rk_dvfs_mutex);\r
-               ret = vd->vd_dvfs_target(clk, rate);\r
-               mutex_unlock(&rk_dvfs_mutex);\r
-               // mutex_unlock(&vd->dvfs_mutex);\r
-       }\r
-       DVFS_DBG("%s(%s(%lu)),is end\n", __func__, clk->name, rate);\r
-       return ret;\r
-}\r
-\r
-static int dvfs_clk_get_ref_volt_depend(struct depend_list *depend, int rate_khz,\r
-               struct cpufreq_frequency_table *clk_fv)\r
-{\r
-       int i = 0;\r
-       if (rate_khz == 0 || !depend || !depend->dep_table) {\r
-               return -1;\r
-       }\r
-       clk_fv->frequency = rate_khz;\r
-       clk_fv->index = 0;\r
-\r
-       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-               if (depend->dep_table[i].frequency >= rate_khz) {\r
-                       clk_fv->frequency = depend->dep_table[i].frequency;\r
-                       clk_fv->index = depend->dep_table[i].index;\r
-                       return 0;\r
-               }\r
-       }\r
-       clk_fv->frequency = 0;\r
-       clk_fv->index = 0;\r
-       return -1;\r
-}\r
-static int dvfs_clk_get_ref_volt(struct clk_node *dvfs_clk, int rate_khz,\r
-               struct cpufreq_frequency_table *clk_fv)\r
-{\r
-       int i = 0;\r
-       if (rate_khz == 0 || !dvfs_clk || !dvfs_clk->dvfs_table) {\r
-               /* since no need */\r
-               return -1;\r
-       }\r
-       clk_fv->frequency = rate_khz;\r
-       clk_fv->index = 0;\r
-\r
-       for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-               if (dvfs_clk->dvfs_table[i].frequency >= rate_khz) {\r
-                       clk_fv->frequency = dvfs_clk->dvfs_table[i].frequency;\r
-                       clk_fv->index = dvfs_clk->dvfs_table[i].index;\r
-                       // DVFS_DBG("%s,%s rate=%ukhz(vol=%d)\n",__func__,dvfs_clk->name, \r
-                       // clk_fv->frequency, clk_fv->index);\r
-                       return 0;\r
-               }\r
-       }\r
-       clk_fv->frequency = 0;\r
-       clk_fv->index = 0;\r
-       // DVFS_DBG("%s get corresponding voltage error! out of bound\n", dvfs_clk->name);\r
-       return -1;\r
-}\r
-\r
-static int dvfs_pd_get_newvolt_byclk(struct pd_node *pd, struct clk_node *dvfs_clk)\r
-{\r
-       struct clk_list *child;\r
-       int volt_max = 0;\r
-\r
-       if (!pd || !dvfs_clk)\r
-               return 0;\r
-\r
-       if (dvfs_clk->set_volt >= pd->cur_volt) {\r
-               return dvfs_clk->set_volt;\r
-       }\r
-\r
-       list_for_each_entry(child, &pd->clk_list, node) {\r
-               // DVFS_DBG("%s ,pd(%s),dvfs(%s),volt(%u)\n",__func__,pd->name,\r
-               // dvfs_clk->name,dvfs_clk->set_volt);\r
-               volt_max = max(volt_max, child->dvfs_clk->set_volt);\r
-       }\r
-       return volt_max;\r
-}\r
-\r
-void dvfs_update_clk_pds_volt(struct clk_node *dvfs_clk)\r
-{\r
-       struct pd_node   *pd;\r
-       int i;\r
-       if (!dvfs_clk)\r
-               return;\r
-       for (i = 0; (dvfs_clk->pds[i].pd != NULL); i++) {\r
-               pd = dvfs_clk->pds[i].pd;\r
-               // DVFS_DBG("%s dvfs(%s),pd(%s)\n",__func__,dvfs_clk->name,pd->name);\r
-               pd->cur_volt = dvfs_pd_get_newvolt_byclk(pd, dvfs_clk);\r
-       }\r
-}\r
-\r
-static int dvfs_vd_get_newvolt_bypd(struct vd_node *vd)\r
-{\r
-       struct pd_node          *pd;\r
-       struct depend_list      *depend;\r
-       int     volt_max_vd = 0;\r
-       list_for_each_entry(pd, &vd->pd_list, node) {\r
-               // DVFS_DBG("%s pd(%s,%u)\n",__func__,pd->name,pd->cur_volt);\r
-               volt_max_vd = max(volt_max_vd, pd->cur_volt);\r
-       }\r
-\r
-       /* some clks depend on this voltage domain */\r
-       if (!list_empty(&vd->req_volt_list)) {\r
-               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
-                       volt_max_vd = max(volt_max_vd, depend->req_volt);\r
-               }\r
-       }\r
-       return volt_max_vd;\r
-}\r
-\r
-static int dvfs_vd_get_newvolt_byclk(struct clk_node *dvfs_clk)\r
-{\r
-       if (!dvfs_clk)\r
-               return -1;\r
-       dvfs_update_clk_pds_volt(dvfs_clk);\r
-       return  dvfs_vd_get_newvolt_bypd(dvfs_clk->vd);\r
-}\r
-\r
-void dvfs_clk_register_set_rate_callback(struct clk *clk, clk_dvfs_target_callback clk_dvfs_target)\r
-{\r
-       struct clk_node *dvfs_clk = clk_get_dvfs_info(clk);\r
-       if (IS_ERR_OR_NULL(dvfs_clk)){\r
-               DVFS_ERR("%s %s get dvfs_clk err\n", __func__, clk->name);\r
-               return ;\r
-       }\r
-       dvfs_clk->clk_dvfs_target = clk_dvfs_target;\r
-}\r
-\r
-struct cpufreq_frequency_table *dvfs_get_freq_volt_table(struct clk *clk) \r
-{\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       struct cpufreq_frequency_table *table;\r
-       if (!info || !info->dvfs_table) {\r
-               return NULL;\r
-       }\r
-       mutex_lock(&mutex);\r
-       table = info->dvfs_table;\r
-       mutex_unlock(&mutex);\r
-       return table;\r
-}\r
-\r
-int dvfs_set_freq_volt_table(struct clk *clk, struct cpufreq_frequency_table *table)\r
-{\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       if (!table || !info)\r
-               return -1;\r
-\r
-       mutex_lock(&mutex);\r
-       info->dvfs_table = table;\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-int dvfs_set_depend_table(struct clk *clk, char *vd_name, struct cpufreq_frequency_table *table)\r
-{\r
-       struct vd_node          *vd;\r
-       struct depend_list      *depend;\r
-       struct clk_node         *info;\r
-\r
-       info = clk_get_dvfs_info(clk);\r
-       if (!table || !info || !vd_name) {\r
-               DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! table or info or name empty\n", __func__);\r
-               return -1;\r
-       }\r
-       \r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (0 == strcmp(vd->name, vd_name)) {\r
-                       DVFS_DBG("FOUND A MATCH\n");\r
-                       mutex_lock(&mutex);\r
-                       list_for_each_entry(depend, &info->depend_list, node2clk) {\r
-                               if (vd == depend->dep_vd && info == depend->dvfs_clk) {\r
-                                       depend->dep_table = table;\r
-                                       break;\r
-                               }\r
-                       }\r
-                       mutex_unlock(&mutex);\r
-                       return 0;\r
-               }\r
-       }\r
-       DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! can not find vd:%s\n", __func__, vd_name);\r
-\r
-       return 0;\r
-}\r
-\r
-int dvfs_set_arm_logic_volt(struct dvfs_arm_table *dvfs_cpu_logic_table, \r
-               struct cpufreq_frequency_table *cpu_dvfs_table,\r
-               struct cpufreq_frequency_table *dep_cpu2core_table)\r
-{\r
-       int i = 0;\r
-       for (i = 0; dvfs_cpu_logic_table[i].frequency != CPUFREQ_TABLE_END; i++) {\r
-               cpu_dvfs_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
-               cpu_dvfs_table[i].index = dvfs_cpu_logic_table[i].cpu_volt;\r
-\r
-               dep_cpu2core_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
-               dep_cpu2core_table[i].index = dvfs_cpu_logic_table[i].logic_volt;\r
-       }\r
-\r
-       cpu_dvfs_table[i].frequency = CPUFREQ_TABLE_END;\r
-       dep_cpu2core_table[i].frequency = CPUFREQ_TABLE_END;\r
-\r
-       dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), cpu_dvfs_table);\r
-       dvfs_set_depend_table(clk_get(NULL, "cpu"), "vd_core", dep_cpu2core_table);\r
-       return 0;\r
-}\r
-\r
-int clk_enable_dvfs(struct clk *clk)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       struct cpufreq_frequency_table clk_fv;\r
-       if (!clk) {\r
-               DVFS_ERR("clk enable dvfs error\n");\r
-               return -1;\r
-       }\r
-       dvfs_clk = clk_get_dvfs_info(clk);\r
-       if (!dvfs_clk || !dvfs_clk->vd) {\r
-               DVFS_ERR("%s clk(%s) not support dvfs!\n", __func__, clk->name);\r
-               return -1;\r
-       }\r
-       if (dvfs_clk->enable_dvfs == 0) {\r
-\r
-               if (IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
-                       //regulator = NULL;\r
-                       if (dvfs_clk->vd->regulator_name)\r
-                               dvfs_clk->vd->regulator = dvfs_regulator_get(NULL, dvfs_clk->vd->regulator_name);\r
-                       if (!IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
-                               // DVFS_DBG("dvfs_regulator_get(%s)\n",dvfs_clk->vd->regulator_name);\r
-                               dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
-                       } else {\r
-                               //dvfs_clk->vd->regulator = NULL;\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               DVFS_ERR("%s can't get regulator in %s\n", dvfs_clk->name, __func__);\r
-                               return -1;\r
-                       }\r
-               } else {\r
-                       dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
-                       // DVFS_DBG("%s(%s) vd volt=%u\n",__func__,dvfs_clk->name,dvfs_clk->vd->cur_volt);\r
-               }\r
-\r
-               dvfs_clk->set_freq = dvfs_clk_get_rate_kz(clk);\r
-               // DVFS_DBG("%s ,%s get freq%u!\n",__func__,dvfs_clk->name,dvfs_clk->set_freq);\r
-               \r
-               if (dvfs_clk_get_ref_volt(dvfs_clk, dvfs_clk->set_freq, &clk_fv)) {\r
-                       if (dvfs_clk->dvfs_table[0].frequency == CPUFREQ_TABLE_END) {\r
-                               DVFS_ERR("%s table empty\n", __func__);\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               return -1;\r
-                       } else {\r
-                               DVFS_ERR("WARNING: %s table all value are smaller than default, use default, just enable dvfs\n", __func__);\r
-                               dvfs_clk->enable_dvfs++;\r
-                               return 0;\r
-                       }\r
-               }\r
-\r
-               dvfs_clk->set_volt = clk_fv.index;\r
-               // DVFS_DBG("%s,%s,freq%u(ref vol %u)\n",__func__,dvfs_clk->name,\r
-               //       dvfs_clk->set_freq,dvfs_clk->set_volt);\r
-#if 0\r
-               if (dvfs_clk->dvfs_nb) {\r
-                       // must unregister when clk disable\r
-                       rk30_clk_notifier_register(clk, dvfs_clk->dvfs_nb);\r
-               }\r
-#endif\r
-               dvfs_vd_get_newvolt_byclk(dvfs_clk);\r
-               if(dvfs_clk->vd->cur_volt<dvfs_clk->set_volt) {\r
-                       int ret;\r
-                       mutex_lock(&rk_dvfs_mutex);\r
-                       ret = dvfs_regulator_set_voltage_readback(dvfs_clk->vd->regulator, \r
-                                       dvfs_clk->set_volt, dvfs_clk->set_volt);\r
-                       if (ret < 0) {\r
-                               dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               DVFS_ERR("dvfs enable clk %s,set volt error \n", dvfs_clk->name);\r
-                               mutex_unlock(&rk_dvfs_mutex);\r
-                               return -1;\r
-                       }\r
-                       dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-                       mutex_unlock(&rk_dvfs_mutex);\r
-               }\r
-               dvfs_clk->enable_dvfs++;\r
-       } else {\r
-               DVFS_ERR("dvfs already enable clk enable = %d!\n", dvfs_clk->enable_dvfs);\r
-               dvfs_clk->enable_dvfs++;\r
-       }\r
-       return 0;\r
-}\r
-\r
-int clk_disable_dvfs(struct clk *clk)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       dvfs_clk = clk->dvfs_info;\r
-       if (!dvfs_clk->enable_dvfs) {\r
-               DVFS_DBG("clk is already closed!\n");\r
-               return -1;\r
-       } else {\r
-               dvfs_clk->enable_dvfs--;\r
-               if (0 == dvfs_clk->enable_dvfs) {\r
-                       DVFS_ERR("clk closed!\n");\r
-#if 0\r
-                       clk_notifier_unregister(clk, dvfs_clk->dvfs_nb);\r
-                       DVFS_DBG("clk unregister nb!\n");\r
-#endif\r
-               }\r
-       }\r
-       return 0;\r
-}\r
-\r
 static int rk_dvfs_clk_notifier_event(struct notifier_block *this,\r
                unsigned long event, void *ptr)\r
 {\r
@@ -497,516 +77,10 @@ static struct notifier_block rk_dvfs_clk_notifier = {
        .notifier_call = rk_dvfs_clk_notifier_event,\r
 };\r
 \r
-static struct clk_node *dvfs_get_dvfs_clk_byname(char *name)\r
-{\r
-       struct vd_node *vd;\r
-       struct pd_node *pd;\r
-       struct clk_list *child;\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               list_for_each_entry(pd, &vd->pd_list, node) {\r
-                       list_for_each_entry(child, &pd->clk_list, node) {\r
-                               if (0 == strcmp(child->dvfs_clk->name, name)) {\r
-                                       return child->dvfs_clk;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-static int rk_regist_vd(struct vd_node *vd)\r
-{\r
-       if (!vd)\r
-               return -1;\r
-       mutex_lock(&mutex);\r
-       //mutex_init(&vd->dvfs_mutex);\r
-       list_add(&vd->node, &rk_dvfs_tree);\r
-       INIT_LIST_HEAD(&vd->pd_list);\r
-       INIT_LIST_HEAD(&vd->req_volt_list);\r
-\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_pd(struct pd_node_lookup *pd_lookup)\r
-{\r
-       struct vd_node  *vd;\r
-       struct pd_node  *pd;\r
-\r
-       mutex_lock(&mutex);\r
-       pd = pd_lookup->pd;\r
-\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (vd == pd->vd) {\r
-                       list_add(&pd->node, &vd->pd_list);\r
-                       INIT_LIST_HEAD(&pd->clk_list);\r
-                       break;\r
-               }\r
-       }\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_clk(struct clk_node *dvfs_clk)\r
-{\r
-       struct pd_node  *pd;\r
-       struct clk_list *child;\r
-       struct clk      *clk;\r
-       int i = 0;\r
-\r
-       if (!dvfs_clk)\r
-               return -1;\r
-\r
-       if (!dvfs_clk->pds)\r
-               return -1;\r
-       mutex_lock(&mutex);\r
-       dvfs_clk->enable_dvfs = 0;\r
-       dvfs_clk->vd = dvfs_clk->pds[0].pd->vd;\r
-       for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
-               child = &(dvfs_clk->pds[i].clk_list);\r
-               child->dvfs_clk = dvfs_clk;\r
-               pd = dvfs_clk->pds[i].pd;\r
-               list_add(&child->node, &pd->clk_list);\r
-       }\r
-       clk = dvfs_clk_get(NULL, dvfs_clk->name);\r
-       dvfs_clk->clk = clk;\r
-       clk_register_dvfs(dvfs_clk, clk);\r
-       INIT_LIST_HEAD(&dvfs_clk->depend_list);\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_depends(struct depend_lookup *dep_node)\r
-{\r
-       struct depend_list      *depend_list;\r
-       struct clk_node         *dvfs_clk;\r
-\r
-       if (!dep_node) {\r
-               DVFS_ERR("%s : DVFS BAD depend node!\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       if (!dep_node->clk_name || !dep_node->dep_vd) {\r
-               DVFS_ERR("%s : DVFS BAD depend members!\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       depend_list = &dep_node->dep_list;\r
-       dvfs_clk = dvfs_get_dvfs_clk_byname(dep_node->clk_name);\r
-\r
-       mutex_lock(&mutex);\r
-\r
-       depend_list->dvfs_clk = dvfs_clk;\r
-       depend_list->dep_vd = dep_node->dep_vd;\r
-       depend_list->dep_table = dep_node->dep_table;\r
-\r
-       list_add(&depend_list->node2clk, &dvfs_clk->depend_list);\r
-       list_add(&depend_list->node2vd, &depend_list->dep_vd->req_volt_list);\r
-\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-#if 0\r
-static int dvfs_set_depend_pre(struct clk_node *dvfs_clk, unsigned long rate_old, unsigned long rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table  clk_fv;\r
-       int ret = -1;\r
-       int volt = 0;\r
-       struct regulator *regulator;\r
-\r
-       if (rate_old >= rate_new) {\r
-               return 0;\r
-       }\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s LOGIC DVFS CAN NOT GET REF VOLT!, frequency too large!\n", __func__);\r
-                       return -1;\r
-               }\r
-\r
-               if (!depend->dep_vd->regulator) {\r
-                       DVFS_DBG("%s regulator empty\n", __func__);\r
-                       regulator = dvfs_regulator_get(NULL, depend->dep_vd->regulator_name);\r
-                       if (!regulator) {\r
-                               DVFS_ERR("%s get regulator err\n", __func__);\r
-                               return -1;\r
-                       }\r
-\r
-                       depend->dep_vd->regulator = regulator;\r
-               }\r
-               if (IS_ERR_OR_NULL(depend->dep_vd->regulator)) {\r
-                       DVFS_ERR("%s vd's(%s) regulator not NULL but error\n", __func__, depend->dep_vd->name);\r
-                       return -1;\r
-               }\r
 \r
-               if (clk_fv.index == dvfs_regulator_get_voltage(depend->dep_vd->regulator)) {\r
-                       depend->req_volt = clk_fv.index;\r
-                       DVFS_DBG("%s same voltage\n", __func__);\r
-                       return 0;\r
-               }\r
-\r
-               depend->req_volt = clk_fv.index;\r
-               volt = dvfs_vd_get_newvolt_bypd(depend->dep_vd);\r
-               DVFS_DBG("%s setting voltage = %d\n", __func__, volt);\r
-               ret = dvfs_regulator_set_voltage_readback(depend->dep_vd->regulator, volt, volt);\r
-               if (0 != ret) {\r
-                       DVFS_ERR("%s set voltage = %d ERROR, ret = %d\n", __func__, volt, ret);\r
-                       return -1;\r
-               }\r
-               udelay(200);\r
-               DVFS_DBG("%s set voltage = %d OK, ret = %d\n", __func__, volt, ret);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s err, ret = %d\n", __func__, ret);\r
-                       return -1;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-static int dvfs_set_depend_post(struct clk_node *dvfs_clk, unsigned long rate_old, unsigned long rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table  clk_fv;\r
-       int ret = -1;\r
-       int volt = 0;\r
-       struct regulator *regulator;\r
-\r
-       if (rate_old <= rate_new) \r
-               return 0;\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s LOGIC DVFS CAN NOT GET REF VOLT!, frequency too large!\n", __func__);\r
-                       return -1;\r
-               }\r
-\r
-               if (!depend->dep_vd->regulator) {\r
-                       DVFS_DBG("%s regulator empty\n", __func__);\r
-                       regulator = dvfs_regulator_get(NULL, depend->dep_vd->regulator_name);\r
-                       if (!regulator) {\r
-                               DVFS_ERR("%s get regulator err\n", __func__);\r
-                               return -1;\r
-                       }\r
-\r
-                       depend->dep_vd->regulator = regulator;\r
-               }\r
-               if (IS_ERR_OR_NULL(depend->dep_vd->regulator)) {\r
-                       DVFS_ERR("%s vd's(%s) regulator not NULL but error\n", __func__, depend->dep_vd->name);\r
-                       return -1;\r
-               }\r
-\r
-               if (clk_fv.index == dvfs_regulator_get_voltage(depend->dep_vd->regulator)) {\r
-                       depend->req_volt = clk_fv.index;\r
-                       DVFS_DBG("%s same voltage\n", __func__);\r
-                       return 0;\r
-               }\r
-\r
-               depend->req_volt = clk_fv.index;\r
-               volt = dvfs_vd_get_newvolt_bypd(depend->dep_vd);\r
-               DVFS_DBG("%s setting voltage = %d\n", __func__, volt);\r
-               ret = dvfs_regulator_set_voltage_readback(depend->dep_vd->regulator, volt, volt);\r
-               if (0 != ret) {\r
-                       DVFS_ERR("%s set voltage = %d ERROR, ret = %d\n", __func__, volt, ret);\r
-                       return -1;\r
-               }\r
-               udelay(200);\r
-               DVFS_DBG("%s set voltage = %d OK, ret = %d\n", __func__, volt, ret);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s err, ret = %d\n", __func__, ret);\r
-                       return -1;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-#endif\r
-\r
-#define ARM_HIGHER_LOGIC       (150 * 1000)\r
-#define LOGIC_HIGHER_ARM       (100 * 1000)\r
-\r
-int check_volt_correct(int volt_old, int *volt_new, int volt_dep_old, int *volt_dep_new, \r
-               int clk_biger_than_dep, int dep_biger_than_clk)\r
-{\r
-       int up_boundary = 0, low_boundary = 0;\r
-       DVFS_DBG("%d %d\n", clk_biger_than_dep, dep_biger_than_clk);\r
-       up_boundary = volt_old + dep_biger_than_clk;\r
-       low_boundary = volt_old - clk_biger_than_dep;\r
-       \r
-       if (volt_dep_old < low_boundary || volt_dep_old > up_boundary) {\r
-               DVFS_ERR("%s current volt out of bondary volt=%d(old=%d), volt_dep=%d(dep_old=%d), up_bnd=%d(dn=%d)\n",\r
-                               __func__, *volt_new, volt_old, *volt_dep_new, volt_dep_old, up_boundary, low_boundary);\r
-               return -1;\r
-       }\r
-       \r
-       up_boundary = *volt_new + dep_biger_than_clk;\r
-       low_boundary = *volt_new - clk_biger_than_dep;\r
-       \r
-       if (*volt_dep_new < low_boundary || *volt_dep_new > up_boundary) {\r
-\r
-               if (*volt_dep_new < low_boundary) {\r
-                       *volt_dep_new = low_boundary;\r
-                       \r
-               } else if (*volt_dep_new > up_boundary) {\r
-                       *volt_new = *volt_dep_new - dep_biger_than_clk;\r
-               }\r
-               DVFS_LOG("%s target volt out of bondary volt=%d(old=%d), volt_dep=%d(dep_old=%d), up_bnd=%d(dn=%d)\n",\r
-                               __func__, *volt_new, volt_old, *volt_dep_new, volt_dep_old, up_boundary, low_boundary);         \r
-               return 0;\r
-       }\r
-       return 0;\r
-\r
-}\r
-int dvfs_scale_volt(struct vd_node *vd_clk, struct vd_node *vd_dep, \r
-               int volt_old, int volt_new, int volt_dep_old, int volt_dep_new, int clk_biger_than_dep, int dep_biger_than_clk)\r
-{\r
-       struct regulator *regulator, *regulator_dep;\r
-       int volt = 0, volt_dep = 0, step = 0, step_dep = 0;\r
-       int volt_pre = 0, volt_dep_pre = 0;\r
-       int ret = 0;\r
-\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d), volt_dep=%d(dep_old=%d)\n", __func__, volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       regulator = vd_clk->regulator;\r
-       regulator_dep = vd_dep->regulator;\r
-\r
-       if (IS_ERR_OR_NULL(regulator) || IS_ERR(regulator_dep)) {       \r
-               DVFS_ERR("%s dvfs_clk->vd->regulator or depend->dep_vd->regulator == NULL\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       volt = volt_old;\r
-       volt_dep = volt_dep_old;\r
-\r
-       step = volt_new - volt_old > 0 ? 1 : (-1);\r
-       step_dep = volt_dep_new - volt_dep_old > 0 ? 1 : (-1);\r
-\r
-       DVFS_DBG("step=%d step_dep=%d %d\n", step, step_dep, step * step_dep);\r
-\r
-       DVFS_DBG("Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n",\r
-                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       do {\r
-               volt_pre = volt;\r
-               volt_dep_pre = volt_dep;\r
-               if (step * step_dep < 0) {\r
-                       // target is between volt_old and volt_dep_old, just\r
-                       // need one step\r
-                       DVFS_DBG("step * step_dep < 0\n");\r
-                       volt = volt_new;\r
-                       volt_dep = volt_dep_new;\r
-               \r
-               } else if (step > 0) {\r
-                       // up voltage\r
-                       DVFS_DBG("step > 0\n");\r
-\r
-                       if (volt > volt_dep) {\r
-                               if (volt_dep == volt_dep_new) {\r
-                                       volt = volt_dep + clk_biger_than_dep;\r
-                               } else {\r
-                                       volt_dep = volt + dep_biger_than_clk;\r
-                               }\r
-                       } else {\r
-                               if (volt == volt_new) {\r
-                                       volt_dep = volt + dep_biger_than_clk;\r
-                               } else {\r
-                                       volt = volt_dep + clk_biger_than_dep;\r
-                               }\r
-                       }\r
-                       volt = volt > volt_new ? volt_new : volt;\r
-                       volt_dep = volt_dep > volt_dep_new ? volt_dep_new : volt_dep;\r
-\r
-               } else if (step < 0) {\r
-                       // down voltage\r
-                       DVFS_DBG("step < 0\n");\r
-                       if (volt > volt_dep) {\r
-                               if (volt == volt_new) {\r
-                                       volt_dep = volt - clk_biger_than_dep;\r
-                               } else {\r
-                                       volt = volt_dep - dep_biger_than_clk;\r
-                               }\r
-                       } else {\r
-                               if (volt_dep == volt_dep_new) {\r
-                                       volt = volt_dep - dep_biger_than_clk;\r
-                               } else {\r
-                                       volt_dep = volt - clk_biger_than_dep;\r
-                               }\r
-                       }\r
-                       volt = volt < volt_new ? volt_new : volt;\r
-                       volt_dep = volt_dep < volt_dep_new ? volt_dep_new : volt_dep;\r
-\r
-               } else {\r
-                       DVFS_ERR("Oops, some bugs here:Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n", \r
-                                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-                       goto fail;\r
-               }\r
-\r
-               DVFS_DBG("\t\tNOW:Volt=%d, volt_dep=%d\n", volt, volt_dep);\r
-\r
-               if (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
-                       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
-                               goto fail;\r
-                       }\r
-                       vd_clk->cur_volt = volt;\r
-               }\r
-\r
-               if (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
-                       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
-                               goto fail;\r
-                       }\r
-                       vd_dep->cur_volt = volt_dep;\r
-               }\r
-\r
-       } while (volt != volt_new || volt_dep!= volt_dep_new);\r
-       \r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       vd_clk->cur_volt = volt_new;\r
-       \r
-       return 0;\r
-fail:\r
-       DVFS_ERR("+++++++++++++++++FAIL AREA\n");       \r
-       vd_clk->cur_volt = volt_old;\r
-       vd_dep->cur_volt = volt_dep_old;\r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-       ret = dvfs_regulator_set_voltage_readback(regulator, volt_old, volt_old);\r
-       if (ret < 0) {\r
-               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n", \r
-                               __func__, vd_clk->name, ret, volt_new, volt_old);\r
-       }\r
-       \r
-       ret = dvfs_regulator_set_voltage_readback(regulator_dep, volt_dep_old, volt_dep_old);\r
-       if (ret < 0) {\r
-               vd_dep->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n", \r
-                               __func__, vd_dep->name, ret, volt_dep_new, volt_dep_old);\r
-       }\r
-\r
-       return -1;\r
-}\r
-\r
-int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new)\r
-{\r
-       int ret = 0;\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d)\n", __func__, volt_new, vd_clk->cur_volt);\r
-       if (IS_ERR_OR_NULL(vd_clk)) {\r
-               DVFS_ERR("%s vd_node error\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       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
-               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
-                                       __func__, vd_clk->name, ret, volt_new, vd_clk->cur_volt);\r
-                       return -1;\r
-               }\r
-\r
-       } else {\r
-               DVFS_ERR("%s up volt dvfs_clk->vd->regulator == NULL\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       vd_clk->cur_volt = volt_new;\r
-\r
-       return 0;\r
-\r
-}\r
-\r
-int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int volt_new, int volt_dep_new, \r
-               int clk_biger_than_dep, int dep_biger_than_clk)\r
-\r
-{\r
-       int ret = 0;\r
-       int volt_old = 0, volt_dep_old = 0;\r
-\r
-       volt_old = vd_clk->cur_volt;\r
-       volt_dep_old = vd_dep->cur_volt;\r
-\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d) vd_dep=%d(dep_old=%d)\n", __func__, \r
-                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-\r
-       if (check_volt_correct(volt_old, &volt_new, volt_dep_old, &volt_dep_new, \r
-                               clk_biger_than_dep, dep_biger_than_clk) < 0) {\r
-               DVFS_ERR("CURRENT VOLT INCORRECT, VD=%s, VD_DEP=%s\n", vd_clk->name, vd_dep->name);\r
-               return -1;\r
-       }\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d), volt_dep=%d(dep_old=%d)\n", __func__, \r
-                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       ret = dvfs_scale_volt(vd_clk, vd_dep, volt_old, volt_new, volt_dep_old, volt_dep_new, \r
-                       clk_biger_than_dep, dep_biger_than_clk);\r
-       if (ret < 0) {\r
-               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("set volt error\n");\r
-               return -1;\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int dvfs_reset_volt(struct vd_node *dvfs_vd)\r
-{      \r
-       int flag_set_volt_correct = 0;\r
-       if (!IS_ERR_OR_NULL(dvfs_vd->regulator))\r
-               flag_set_volt_correct = dvfs_regulator_get_voltage(dvfs_vd->regulator);\r
-       else {\r
-               DVFS_ERR("dvfs regulator is ERROR\n");\r
-               return -1;\r
-       }\r
-       if (flag_set_volt_correct <= 0) {\r
-               DVFS_ERR("%s (clk:%s), try to reload arm_volt error %d!!! stop scaling\n", \r
-                               __func__, dvfs_vd->name, flag_set_volt_correct);\r
-               return -1;\r
-       }\r
-       dvfs_vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       DVFS_ERR("%s (clk:%s), try to reload arm_volt! arm_volt_correct = %d\n", \r
-                       __func__, dvfs_vd->name, flag_set_volt_correct);\r
-\r
-       /* Reset vd's voltage */\r
-       dvfs_vd->cur_volt = flag_set_volt_correct;\r
-\r
-       return dvfs_vd->cur_volt;\r
-}\r
-\r
-int dvfs_get_depend_volt(struct clk_node *dvfs_clk, struct vd_node *dvfs_vd_dep, int rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table clk_fv_dep;\r
-       int ret = 0;\r
-\r
-       DVFS_DBG("ENTER %s, rate_new=%d\n", __func__, rate_new);\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               DVFS_DBG("--round depend clk:%s(depend:%s)\n", depend->dvfs_clk->name, depend->dep_vd->name);\r
-               // this place just consider ONE depend voltage domain,\r
-               // multi-depends must have some differece\r
-               clk_fv_dep.index = 0;\r
-               if (depend->dep_vd == dvfs_vd_dep) {\r
-                       ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv_dep);\r
-                       if (ret < 0) {\r
-                               DVFS_ERR("%s get dvfs_ref_volt_depend error\n", __func__);\r
-                               return -1;\r
-                       }\r
-                       depend->req_volt = clk_fv_dep.index;\r
-                       return depend->req_volt;\r
-               }\r
-       }\r
-\r
-       DVFS_ERR("%s can not find vd node %s\n", __func__, dvfs_vd_dep->name);\r
-       return -1;\r
-}\r
 static struct clk_node *dvfs_clk_cpu;\r
 static struct vd_node vd_core;\r
-int dvfs_target_cpu(struct clk *clk, unsigned long rate_hz)\r
+static int dvfs_target_cpu(struct clk *clk, unsigned long rate_hz)\r
 {\r
        struct clk_node *dvfs_clk;\r
        int volt_new = 0, volt_dep_new = 0, clk_volt_store = 0;\r
@@ -1134,7 +208,7 @@ out:
        return -1;\r
 }\r
 \r
-int dvfs_target_core(struct clk *clk, unsigned long rate_hz)\r
+static int dvfs_target_core(struct clk *clk, unsigned long rate_hz)\r
 {\r
        struct clk_node *dvfs_clk;\r
        int volt_new = 0, volt_dep_new = 0, clk_volt_store = 0;\r
@@ -1454,7 +528,10 @@ static struct depend_lookup rk30_depends[] = {
        //RK_DEPPENDS("gpu", &vd_cpu, NULL),\r
 };\r
 \r
-int rk30_dvfs_init(void)\r
+\r
+static struct avs_ctr_st rk292x_avs_ctr;\r
+\r
+int rk292x_dvfs_init(void)\r
 {\r
        int i = 0;\r
        for (i = 0; i < ARRAY_SIZE(rk30_vds); i++) {\r
@@ -1470,73 +547,21 @@ int rk30_dvfs_init(void)
                rk_regist_depends(&rk30_depends[i]);\r
        }\r
        dvfs_clk_cpu = dvfs_get_dvfs_clk_byname("cpu");\r
+       avs_board_init(&rk292x_avs_ctr);\r
        return 0;\r
 }\r
 \r
-/*******************************AVS AREA****************************************/\r
-/*\r
- * To use AVS function, you must call avs_init in machine_rk30_board_init(void)(board-rk30-sdk.c)\r
- * And then call(vdd_log):\r
- *     regulator_set_voltage(dcdc, 1100000, 1100000);\r
- *     avs_init_val_get(1,1100000,"wm8326 init");\r
- *     udelay(600);\r
- *     avs_set_scal_val(AVS_BASE);\r
- * in wm831x_post_init(board-rk30-sdk-wm8326.c)\r
- * AVS_BASE can use 172\r
- */\r
 \r
-static int avs_scale_volt = 0;\r
-static int avs_get_scal_val(int vol);\r
 \r
-int dvfs_avs_scale_table(struct clk *clk, char *depend_vd_name)\r
-{\r
-       /* if depend_vd_name == NULL scale clk table\r
-        * else scale clk's depend table, named depend_vd_name\r
-        * */\r
-       struct vd_node          *vd;\r
-       struct depend_list      *depend;\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       struct cpufreq_frequency_table  *table = NULL;\r
-       int i;\r
-\r
-       if (NULL == depend_vd_name) {\r
-               table = info->dvfs_table;\r
-       } else {\r
-               list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-                       if (0 == strcmp(vd->name, depend_vd_name)) {\r
-                               DVFS_DBG("%s FOUND A MATCH vd\n", __func__);\r
-                               mutex_lock(&mutex);\r
-                               list_for_each_entry(depend, &info->depend_list, node2clk) {\r
-                                       if (vd == depend->dep_vd && info == depend->dvfs_clk) {\r
-                                               DVFS_DBG("%s FOUND A MATCH table\n", __func__);\r
-                                               table = depend->dep_table;\r
-                                               break;\r
-                                       }\r
-                               }\r
-                               mutex_unlock(&mutex);\r
-                       }\r
-               }\r
-       }\r
 \r
-       if (table == NULL) {\r
-               DVFS_ERR("%s can not find match table\n", __func__);\r
-               return -1;\r
-       }\r
-       if (avs_scale_volt != 0) {\r
-               DVFS_DBG("AVS scale %s, depend name = %s, voltage = %d\n",\r
-                               info->name, depend_vd_name, avs_scale_volt);\r
-               for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {\r
-                       table[i].index = avs_get_scal_val(table[i].index);\r
-               }\r
-       }\r
-       return 0;\r
-}\r
 \r
-static void __iomem *rk30_nandc_base;\r
+/******************************rk292x avs**************************************************/\r
+#if 0//def CONFIG_ARCH_RK2928\r
 \r
-#define nandc_readl(offset)    readl_relaxed(rk30_nandc_base + offset)\r
-#define nandc_writel(v, offset) do { writel_relaxed(v, rk30_nandc_base + offset); dsb(); } while (0)\r
-static u8 rk30_get_avs_val(void)\r
+static void __iomem *rk292x_nandc_base;\r
+#define nandc_readl(offset)    readl_relaxed(rk292x_nandc_base + offset)\r
+#define nandc_writel(v, offset) do { writel_relaxed(v, rk292x_nandc_base + offset); dsb(); } while (0)\r
+static u8 rk292x_get_avs_val(void)\r
 {\r
        u32 nanc_save_reg[4];\r
        unsigned long flags;\r
@@ -1573,410 +598,15 @@ static u8 rk30_get_avs_val(void)
        return (u8)paramet;\r
 \r
 }\r
-#define init_avs_times 10\r
-#define init_avs_st_num 5\r
-\r
-struct init_avs_st {\r
-       int is_set;\r
-       u8 paramet[init_avs_times];\r
-       int vol;\r
-       char *s;\r
-};\r
-\r
-static struct init_avs_st init_avs_paramet[init_avs_st_num];\r
-\r
-void avs_init_val_get(int index, int vol, char *s)\r
-{\r
-       int i;\r
-       if(index >= init_avs_times)\r
-               return;\r
-       init_avs_paramet[index].vol = vol;\r
-       init_avs_paramet[index].s = s;\r
-       init_avs_paramet[index].is_set++;\r
-       for(i = 0; i < init_avs_times; i++) {\r
-               init_avs_paramet[index].paramet[i] = rk30_get_avs_val();\r
-               mdelay(1);\r
-       }\r
-}\r
 \r
-void avs_init(void)\r
+void rk292x_avs_init(void)\r
 {\r
-       memset(&init_avs_paramet[0].is_set, 0, sizeof(init_avs_paramet));\r
-       rk30_nandc_base = ioremap(RK2928_NANDC_PHYS, RK2928_NANDC_SIZE);\r
+       rk292x_nandc_base = ioremap(RK2928_NANDC_PHYS, RK2928_NANDC_SIZE);\r
        //avs_init_val_get(0,1150000,"board_init");\r
 }\r
 \r
-#define VOL_DYN_STEP (12500)  //mv\r
-#define AVS_VAL_PER_STEP (4)  //mv\r
-\r
-static u8 avs_init_get_min_val(void)\r
-{\r
-       int i, j;\r
-       u8 min_avs = 0xff;\r
-       for(i = 0; i < init_avs_st_num; i++) {\r
-               if(init_avs_paramet[i].is_set && init_avs_paramet[i].vol == (1100 * 1000)) {\r
-                       for(j = 0; j < init_avs_times; j++)\r
-                               min_avs = (u8)min(min_avs, init_avs_paramet[i].paramet[j]);\r
-               }\r
-\r
-       }\r
-       return min_avs;\r
-}\r
-\r
-static int avs_get_scal_val(int vol)\r
-{\r
-       vol += avs_scale_volt;\r
-       if(vol < 1000 * 1000)\r
-               vol = 1000 * 1000;\r
-       if(vol > 1400 * 1000)\r
-               vol = 1400 * 1000;\r
-       return vol;\r
-}\r
-#if 0\r
-u8 avs_test_date[] = {172, 175, 176, 179, 171, 168, 165, 162, 199, 0};\r
-u8 avs_test_date_cunt = 0;\r
-#endif\r
-int avs_set_scal_val(u8 avs_base)\r
-{\r
-       u8 avs_test = avs_init_get_min_val();\r
-       s8 step = 0;\r
-\r
-       if (avs_base < avs_test) {\r
-               DVFS_DBG("AVS down voltage, ignore\n");\r
-               return 0;\r
-       }\r
-       step = (avs_base - avs_test) / AVS_VAL_PER_STEP;\r
-       step = (avs_base > avs_test) ? (step + 1) : step;\r
-       if (step > 2)\r
-               step += 1;\r
-       avs_scale_volt = (step) * (VOL_DYN_STEP);\r
-\r
-       DVFS_DBG("avs_set_scal_val test=%d,base=%d,step=%d,scale_vol=%d\n",\r
-                       avs_test, avs_base, step, avs_scale_volt);\r
-       return 0;\r
-}\r
-\r
-/*************************interface to get avs value and dvfs tree*************************/\r
-#define USE_NORMAL_TIME\r
-#ifdef USE_NORMAL_TIME\r
-static struct timer_list avs_timer;\r
-#else\r
-static struct hrtimer dvfs_hrtimer;\r
-#endif\r
-\r
-static u32 avs_dyn_start = 0;\r
-static u32 avs_dyn_data_cnt;\r
-static u8 *avs_dyn_data = NULL;\r
-static u32 show_line_cnt = 0;\r
-static u8 dly_min;\r
-static u8 dly_max;\r
-\r
-#define val_per_line (30)\r
-#define line_pre_show (30)\r
-#define avs_dyn_data_num (3*1000*1000)\r
-\r
-static u32 print_avs_init(char *buf)\r
-{\r
-       char *s = buf;\r
-       int i, j;\r
-\r
-       for(j = 0; j < init_avs_st_num; j++) {\r
-               if(init_avs_paramet[j].vol <= 0)\r
-                       continue;\r
-               s += sprintf(s, "%s ,vol=%d,paramet following\n", \r
-                               init_avs_paramet[j].s, init_avs_paramet[j].vol);\r
-               for(i = 0; i < init_avs_times; i++) {\r
-                       s += sprintf(s, "%d ", init_avs_paramet[j].paramet[i]);\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-       }\r
-       return (s - buf);\r
-}\r
-\r
-static ssize_t avs_init_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return print_avs_init(buf);\r
-}\r
-\r
-static ssize_t avs_init_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-\r
-       return n;\r
-}\r
-static ssize_t avs_now_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return sprintf(buf, "%d\n", rk30_get_avs_val());\r
-}\r
-\r
-static ssize_t avs_now_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       return n;\r
-}\r
-static ssize_t avs_dyn_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       char *s = buf;\r
-       u32 i;\r
-\r
-       if(avs_dyn_data==NULL)\r
-               return (s - buf);\r
-               \r
-       if(avs_dyn_start) {\r
-               int start_cnt;\r
-               int end_cnt;\r
-               end_cnt = (avs_dyn_data_cnt ? (avs_dyn_data_cnt - 1) : 0);\r
-               if(end_cnt > (line_pre_show * val_per_line))\r
-                       start_cnt = end_cnt - (line_pre_show * val_per_line);\r
-               else\r
-                       start_cnt = 0;\r
-\r
-               dly_min = avs_dyn_data[start_cnt];\r
-               dly_max = avs_dyn_data[start_cnt];\r
-\r
-               //s += sprintf(s,"data start=%d\n",i);\r
-               for(i = start_cnt; i <= end_cnt;) {\r
-                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
-                       dly_min = min(dly_min, avs_dyn_data[i]);\r
-                       dly_max = max(dly_max, avs_dyn_data[i]);\r
-                       i++;\r
-                       if(!(i % val_per_line)) {\r
-                               s += sprintf(s, "\n");\r
-                       } else\r
-                               s += sprintf(s, " ");\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-\r
-               s += sprintf(s, "new data is from=%d to %d\n", start_cnt, end_cnt);\r
-               //s += sprintf(s,"\n max=%d,min=%d,totolcnt=%d,line=%d\n",dly_max,dly_min,avs_dyn_data_cnt,show_line_cnt);\r
-\r
-\r
-       } else {\r
-               if(show_line_cnt == 0) {\r
-                       dly_min = avs_dyn_data[0];\r
-                       dly_max = avs_dyn_data[0];\r
-               }\r
-\r
-\r
-               for(i = show_line_cnt * (line_pre_show * val_per_line); i < avs_dyn_data_cnt;) {\r
-                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
-                       dly_min = min(dly_min, avs_dyn_data[i]);\r
-                       dly_max = max(dly_max, avs_dyn_data[i]);\r
-                       i++;\r
-                       if(!(i % val_per_line)) {\r
-                               s += sprintf(s, "\n");\r
-                       } else\r
-                               s += sprintf(s, " ");\r
-                       if(i >= ((show_line_cnt + 1)*line_pre_show * val_per_line))\r
-                               break;\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-\r
-               s += sprintf(s, "max=%d,min=%d,totolcnt=%d,line=%d\n", \r
-                               dly_max, dly_min, avs_dyn_data_cnt, show_line_cnt);\r
-               show_line_cnt++;\r
-               if(((show_line_cnt * line_pre_show)*val_per_line) >= avs_dyn_data_cnt) {\r
-\r
-                       show_line_cnt = 0;\r
-\r
-                       s += sprintf(s, "data is over\n");\r
-               }\r
-       }\r
-       return (s - buf);\r
-}\r
-\r
-static ssize_t avs_dyn_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       const char *pbuf;\r
-\r
-       if((strncmp(buf, "start", strlen("start")) == 0)) {\r
-               if(avs_dyn_data==NULL)  \r
-                       avs_dyn_data = kmalloc(avs_dyn_data_num, GFP_KERNEL);\r
-               if(avs_dyn_data==NULL)\r
-                       return n;\r
-               \r
-               pbuf = &buf[strlen("start")];\r
-               avs_dyn_data_cnt = 0;\r
-               show_line_cnt = 0;\r
-               if(avs_dyn_data) {\r
-#ifdef USE_NORMAL_TIME\r
-                       mod_timer(&avs_timer, jiffies + msecs_to_jiffies(5));\r
-#else\r
-                       hrtimer_start(&dvfs_hrtimer, ktime_set(0, 5 * 1000 * 1000), HRTIMER_MODE_REL);\r
-#endif\r
-                       avs_dyn_start = 1;\r
-               }\r
-               //sscanf(pbuf, "%d %d", &number, &voltage);\r
-               //DVFS_DBG("---------ldo %d %d\n", number, voltage);\r
-\r
-       } else if((strncmp(buf, "stop", strlen("stop")) == 0)) {\r
-               pbuf = &buf[strlen("stop")];\r
-               avs_dyn_start = 0;\r
-               show_line_cnt = 0;\r
-               //sscanf(pbuf, "%d %d", &number, &voltage);\r
-               //DVFS_DBG("---------dcdc %d %d\n", number, voltage);\r
-       }\r
-\r
-\r
-\r
-       return n;\r
-}\r
-\r
-static ssize_t dvfs_tree_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       return n;\r
-}\r
-static ssize_t dvfs_tree_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return dump_dbg_map(buf);\r
-\r
-}\r
-\r
-static void avs_timer_fn(unsigned long data)\r
-{\r
-       int i;\r
-       for(i = 0; i < 1; i++) {\r
-               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
-                       return;\r
-               avs_dyn_data[avs_dyn_data_cnt] = rk30_get_avs_val();\r
-               avs_dyn_data_cnt++;\r
-       }\r
-       if(avs_dyn_start)\r
-               mod_timer(&avs_timer, jiffies + msecs_to_jiffies(10));\r
-}\r
-#if 0\r
-struct hrtimer dvfs_hrtimer;\r
-static enum hrtimer_restart dvfs_hrtimer_timer_func(struct hrtimer *timer)\r
-{\r
-       int i;\r
-       for(i = 0; i < 1; i++) {\r
-               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
-                       return HRTIMER_NORESTART;\r
-               avs_dyn_data[avs_dyn_data_cnt] = rk30_get_avs_val();\r
-               avs_dyn_data_cnt++;\r
-       }\r
-       if(avs_dyn_start)\r
-               hrtimer_start(timer, ktime_set(0, 1 * 1000 * 1000), HRTIMER_MODE_REL);\r
-\r
-}\r
-#endif\r
-/*********************************************************************************/\r
-static struct kobject *dvfs_kobj;\r
-struct dvfs_attribute {\r
-       struct attribute        attr;\r
-       ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,\r
-                       char *buf);\r
-       ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,\r
-                       const char *buf, size_t n);\r
+static struct avs_ctr_st rk292x_avs_ctr = {\r
+       .avs_init               =rk292x_avs_init,\r
+       .avs_get_val    = rk292x_get_avs_val,\r
 };\r
-\r
-static struct dvfs_attribute dvfs_attrs[] = {\r
-       /*     node_name        permision               show_func       store_func */\r
-#ifdef CONFIG_RK_CLOCK_PROC\r
-       __ATTR(dvfs_tree,       S_IRUGO | S_IWUSR,      dvfs_tree_show, dvfs_tree_store),\r
-       //__ATTR(avs_init,      S_IRUGO | S_IWUSR,      avs_init_show,  avs_init_store),\r
-       //__ATTR(avs_dyn,               S_IRUGO | S_IWUSR,      avs_dyn_show,   avs_dyn_store),\r
-       //__ATTR(avs_now,               S_IRUGO | S_IWUSR,      avs_now_show,   avs_now_store),\r
 #endif\r
-};\r
-\r
-static int __init dvfs_init(void)\r
-{\r
-       int i, ret = 0;\r
-#ifdef USE_NORMAL_TIME\r
-       init_timer(&avs_timer);\r
-       //avs_timer.expires = jiffies+msecs_to_jiffies(1);\r
-       avs_timer.function = avs_timer_fn;\r
-       //mod_timer(&avs_timer,jiffies+msecs_to_jiffies(1));\r
-#else\r
-       hrtimer_init(&dvfs_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);\r
-       dvfs_hrtimer.function = dvfs_hrtimer_timer_func;\r
-       //hrtimer_start(&dvfs_hrtimer,ktime_set(0, 5*1000*1000),HRTIMER_MODE_REL);\r
-#endif\r
-\r
-\r
-       dvfs_kobj = kobject_create_and_add("dvfs", NULL);\r
-       if (!dvfs_kobj)\r
-               return -ENOMEM;\r
-       for (i = 0; i < ARRAY_SIZE(dvfs_attrs); i++) {\r
-               ret = sysfs_create_file(dvfs_kobj, &dvfs_attrs[i].attr);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("create index %d error\n", i);\r
-                       return ret;\r
-               }\r
-       }\r
-\r
-       return ret;\r
-}\r
-subsys_initcall(dvfs_init);\r
-\r
-/**\r
- * dump_dbg_map() : Draw all informations of dvfs while debug\r
- */\r
-static int dump_dbg_map(char *buf)\r
-{\r
-       int i;\r
-       struct vd_node  *vd;\r
-       struct pd_node  *pd, *clkparent;\r
-       struct clk_list *child;\r
-       struct clk_node *dvfs_clk;\r
-       struct depend_list *depend;\r
-       char* s = buf;\r
-       \r
-       s += sprintf(s, "-------------DVFS TREE-----------\n\n\n");\r
-       s += sprintf(s, "RK30 DVFS TREE:\n");\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               s += sprintf(s, "|\n|- voltage domain:%s\n", vd->name);\r
-               s += sprintf(s, "|- current voltage:%d\n", vd->cur_volt);\r
-               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
-                       s += sprintf(s, "|- request voltage:%d, clk:%s\n", depend->req_volt, depend->dvfs_clk->name);\r
-               }\r
-\r
-               list_for_each_entry(pd, &vd->pd_list, node) {\r
-                       s += sprintf(s, "|  |\n|  |- power domain:%s, status = %s, current volt = %d\n",\r
-                                       pd->name, (pd->pd_status == PD_ON) ? "ON" : "OFF", pd->cur_volt);\r
-\r
-                       list_for_each_entry(child, &pd->clk_list, node) {\r
-                               dvfs_clk = child->dvfs_clk;\r
-                               s += sprintf(s, "|  |  |\n|  |  |- clock: %s current: rate %d, volt = %d, enable_dvfs = %s\n",\r
-                                               dvfs_clk->name, dvfs_clk->set_freq, dvfs_clk->set_volt, \r
-                                               dvfs_clk->enable_dvfs == 0 ? "DISABLE" : "ENABLE");\r
-                               for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
-                                       clkparent = dvfs_clk->pds[i].pd;\r
-                                       s += sprintf(s, "|  |  |  |- clock parents: %s, vd_parent = %s\n", \r
-                                                       clkparent->name, clkparent->vd->name);\r
-                               }\r
-\r
-                               for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-                                       s += sprintf(s, "|  |  |  |- freq = %d, volt = %d\n", \r
-                                                       dvfs_clk->dvfs_table[i].frequency, \r
-                                                       dvfs_clk->dvfs_table[i].index);\r
-\r
-                               }\r
-\r
-                               list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-                                       s += sprintf(s, "|  |  |  |  |- DEPEND VD: %s\n", depend->dep_vd->name); \r
-                                       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-                                               s += sprintf(s, "|  |  |  |  |- freq = %d, req_volt = %d\n", \r
-                                                               depend->dep_table[i].frequency, \r
-\r
-                                                               depend->dep_table[i].index);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       s += sprintf(s, "-------------DVFS TREE END------------\n");\r
-       return s - buf;\r
-}\r
-\r
-\r
index 38c5812d684c51b110442caaba6c41c86ac27e7f..f1a1f55d43be564b8612b6ce2947dfbd699d423b 100644 (file)
@@ -3199,6 +3199,7 @@ void __init _rk30_clock_data_init(unsigned long gpll, unsigned long cpll, int fl
 
 }
 
+int rk30_dvfs_init(void);
 void __init rk30_clock_data_init(unsigned long gpll, unsigned long cpll, u32 flags)
 {
        _rk30_clock_data_init(gpll, cpll, flags);
old mode 100755 (executable)
new mode 100644 (file)
index 0148e03..76432c8
@@ -3422,6 +3422,7 @@ void __init _rk30_clock_data_init(unsigned long gpll,unsigned long cpll,int flag
        //cru_writel(0x07000000,CRU_MISC_CON);
        
 }
+int rk30_dvfs_init(void);
 
 void __init rk30_clock_data_init(unsigned long gpll,unsigned long cpll,u32 flags)
 {
index bafda02d6f6775cf44d96c0daba9e5d0caa1a4f8..e614f3fe0caa816b4d51ed62459f9b34391c3407 100644 (file)
 #include <linux/io.h>\r
 #include <linux/hrtimer.h>\r
 \r
-#if 0\r
-#define DVFS_DBG(fmt, args...) printk(KERN_DEBUG "DVFS DBG:\t"fmt, ##args)\r
-#else\r
-#define DVFS_DBG(fmt, args...) {while(0);}\r
-#endif\r
-\r
-#define DVFS_SET_VOLT_FAILURE  1\r
-#define DVFS_SET_VOLT_SUCCESS  0\r
-\r
-#define DVFS_ERR(fmt, args...) printk(KERN_ERR "DVFS ERR:\t"fmt, ##args)\r
-#define DVFS_LOG(fmt, args...) printk(KERN_DEBUG "DVFS LOG:\t"fmt, ##args)\r
-\r
-#define dvfs_regulator_get(dev,id) regulator_get((dev),(id))\r
-#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
-\r
-#define dvfs_clk_get(a,b) clk_get((a),(b))\r
-#define dvfs_clk_get_rate_kz(a) (clk_get_rate((a))/1000)\r
-#define dvfs_clk_set_rate(a,b) clk_set_rate((a),(b))\r
-#define dvfs_clk_enable(a) clk_enable((a))\r
-#define dvfs_clk_disable(a) clk_disable((a))\r
-\r
-#define DVFS_MHZ (1000*1000)\r
-#define DVFS_KHZ (1000)\r
-\r
-#define DVFS_V (1000*1000)\r
-#define DVFS_MV (1000)\r
-\r
-static LIST_HEAD(rk_dvfs_tree);\r
-static DEFINE_MUTEX(mutex);\r
-static DEFINE_MUTEX(rk_dvfs_mutex);\r
-\r
-static int dump_dbg_map(char *buf);\r
-\r
-#define PD_ON  1\r
-#define PD_OFF 0\r
-\r
-#define get_volt_up_delay(new_volt, old_volt)  \\r
-       ((new_volt) > (old_volt) ? (((new_volt) - (old_volt)) >> 9) : 0)\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
-       ret = dvfs_regulator_set_voltage(regulator, max_uV, max_uV);\r
-       if (ret < 0) {\r
-               DVFS_ERR("%s now read back to check voltage\n", __func__);\r
-\r
-               /* read back to judge if it is already effect */\r
-               mdelay(2);\r
-               read_back = dvfs_regulator_get_voltage(regulator);\r
-               if (read_back == max_uV) {\r
-                       DVFS_ERR("%s set ERROR but already effected, volt=%d\n", __func__, read_back);\r
-                       ret = 0;\r
-               } else {\r
-                       DVFS_ERR("%s set ERROR AND NOT effected, volt=%d\n", __func__, read_back);\r
-               }\r
-       }\r
-       return ret;\r
-}\r
-\r
-struct regulator *dvfs_get_regulator(char *regulator_name) \r
-{\r
-       struct vd_node *vd;\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (strcmp(regulator_name, vd->regulator_name) == 0) {\r
-                       return vd->regulator;\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-\r
-int dvfs_clk_enable_limit(struct clk *clk, unsigned int min_rate, unsigned max_rate)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       u32 rate = 0;\r
-       dvfs_clk = clk->dvfs_info;\r
-\r
-       dvfs_clk->freq_limit_en = 1;\r
-       dvfs_clk->min_rate = min_rate;\r
-       dvfs_clk->max_rate = max_rate;\r
-\r
-       rate = clk_get_rate(clk);\r
-       if (rate < min_rate)\r
-               dvfs_clk_set_rate(clk, min_rate);\r
-       else if (rate > max_rate)\r
-               dvfs_clk_set_rate(clk, max_rate);\r
-       return 0;\r
-}\r
-\r
-int dvfs_clk_disable_limit(struct clk *clk)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       dvfs_clk = clk->dvfs_info;\r
-\r
-       dvfs_clk->freq_limit_en = 0;\r
-\r
-       return 0;\r
-}\r
-\r
-int is_support_dvfs(struct clk_node *dvfs_info)\r
-{\r
-       return (dvfs_info->vd && dvfs_info->vd->vd_dvfs_target && dvfs_info->enable_dvfs);\r
-}\r
-\r
-int dvfs_set_rate(struct clk *clk, unsigned long rate)\r
-{\r
-       int ret = 0;\r
-       struct vd_node *vd;\r
-       DVFS_DBG("%s(%s(%lu))\n", __func__, clk->name, rate);\r
-       if (!clk->dvfs_info) {\r
-               DVFS_ERR("%s :This clk do not support dvfs!\n", __func__);\r
-               ret = -1;\r
-       } else {\r
-               vd = clk->dvfs_info->vd;\r
-               // mutex_lock(&vd->dvfs_mutex);\r
-               mutex_lock(&rk_dvfs_mutex);\r
-               ret = vd->vd_dvfs_target(clk, rate);\r
-               mutex_unlock(&rk_dvfs_mutex);\r
-               // mutex_unlock(&vd->dvfs_mutex);\r
-       }\r
-       DVFS_DBG("%s(%s(%lu)),is end\n", __func__, clk->name, rate);\r
-       return ret;\r
-}\r
-\r
-static int dvfs_clk_get_ref_volt_depend(struct depend_list *depend, int rate_khz,\r
-               struct cpufreq_frequency_table *clk_fv)\r
-{\r
-       int i = 0;\r
-       if (rate_khz == 0 || !depend || !depend->dep_table) {\r
-               return -1;\r
-       }\r
-       clk_fv->frequency = rate_khz;\r
-       clk_fv->index = 0;\r
-\r
-       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-               if (depend->dep_table[i].frequency >= rate_khz) {\r
-                       clk_fv->frequency = depend->dep_table[i].frequency;\r
-                       clk_fv->index = depend->dep_table[i].index;\r
-                       return 0;\r
-               }\r
-       }\r
-       clk_fv->frequency = 0;\r
-       clk_fv->index = 0;\r
-       return -1;\r
-}\r
-static int dvfs_clk_get_ref_volt(struct clk_node *dvfs_clk, int rate_khz,\r
-               struct cpufreq_frequency_table *clk_fv)\r
-{\r
-       int i = 0;\r
-       if (rate_khz == 0 || !dvfs_clk || !dvfs_clk->dvfs_table) {\r
-               /* since no need */\r
-               return -1;\r
-       }\r
-       clk_fv->frequency = rate_khz;\r
-       clk_fv->index = 0;\r
-\r
-       for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-               if (dvfs_clk->dvfs_table[i].frequency >= rate_khz) {\r
-                       clk_fv->frequency = dvfs_clk->dvfs_table[i].frequency;\r
-                       clk_fv->index = dvfs_clk->dvfs_table[i].index;\r
-                       // DVFS_DBG("%s,%s rate=%ukhz(vol=%d)\n",__func__,dvfs_clk->name,\r
-                       // clk_fv->frequency, clk_fv->index);\r
-                       return 0;\r
-               }\r
-       }\r
-       clk_fv->frequency = 0;\r
-       clk_fv->index = 0;\r
-       // DVFS_DBG("%s get corresponding voltage error! out of bound\n", dvfs_clk->name);\r
-       return -1;\r
-}\r
-\r
-static int dvfs_pd_get_newvolt_byclk(struct pd_node *pd, struct clk_node *dvfs_clk)\r
-{\r
-       struct clk_list *child;\r
-       int volt_max = 0;\r
-\r
-       if (!pd || !dvfs_clk)\r
-               return 0;\r
-\r
-       if (dvfs_clk->set_volt >= pd->cur_volt) {\r
-               return dvfs_clk->set_volt;\r
-       }\r
-\r
-       list_for_each_entry(child, &pd->clk_list, node) {\r
-               // DVFS_DBG("%s ,pd(%s),dvfs(%s),volt(%u)\n",__func__,pd->name,\r
-               // dvfs_clk->name,dvfs_clk->set_volt);\r
-               volt_max = max(volt_max, child->dvfs_clk->set_volt);\r
-       }\r
-       return volt_max;\r
-}\r
-\r
-void dvfs_update_clk_pds_volt(struct clk_node *dvfs_clk)\r
-{\r
-       struct pd_node   *pd;\r
-       int i;\r
-       if (!dvfs_clk)\r
-               return;\r
-       for (i = 0; (dvfs_clk->pds[i].pd != NULL); i++) {\r
-               pd = dvfs_clk->pds[i].pd;\r
-               // DVFS_DBG("%s dvfs(%s),pd(%s)\n",__func__,dvfs_clk->name,pd->name);\r
-               pd->cur_volt = dvfs_pd_get_newvolt_byclk(pd, dvfs_clk);\r
-       }\r
-}\r
-\r
-static int dvfs_vd_get_newvolt_bypd(struct vd_node *vd)\r
-{\r
-       struct pd_node          *pd;\r
-       struct depend_list      *depend;\r
-       int     volt_max_vd = 0;\r
-       list_for_each_entry(pd, &vd->pd_list, node) {\r
-               // DVFS_DBG("%s pd(%s,%u)\n",__func__,pd->name,pd->cur_volt);\r
-               volt_max_vd = max(volt_max_vd, pd->cur_volt);\r
-       }\r
-\r
-       /* some clks depend on this voltage domain */\r
-       if (!list_empty(&vd->req_volt_list)) {\r
-               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
-                       volt_max_vd = max(volt_max_vd, depend->req_volt);\r
-               }\r
-       }\r
-       return volt_max_vd;\r
-}\r
-\r
-static int dvfs_vd_get_newvolt_byclk(struct clk_node *dvfs_clk)\r
-{\r
-       if (!dvfs_clk)\r
-               return -1;\r
-       dvfs_update_clk_pds_volt(dvfs_clk);\r
-       return  dvfs_vd_get_newvolt_bypd(dvfs_clk->vd);\r
-}\r
-\r
-void dvfs_clk_register_set_rate_callback(struct clk *clk, clk_dvfs_target_callback clk_dvfs_target)\r
-{\r
-       struct clk_node *dvfs_clk = clk_get_dvfs_info(clk);\r
-       if (IS_ERR_OR_NULL(dvfs_clk)) {\r
-               DVFS_ERR("%s %s get dvfs_clk err\n", __func__, clk->name);\r
-               return ;\r
-       }\r
-       dvfs_clk->clk_dvfs_target = clk_dvfs_target;\r
-}\r
-\r
-struct cpufreq_frequency_table *dvfs_get_freq_volt_table(struct clk *clk) \r
-{\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       struct cpufreq_frequency_table *table;\r
-       if (!info || !info->dvfs_table) {\r
-               return NULL;\r
-       }\r
-       mutex_lock(&mutex);\r
-       table = info->dvfs_table;\r
-       mutex_unlock(&mutex);\r
-       return table;\r
-}\r
-\r
-int dvfs_set_freq_volt_table(struct clk *clk, struct cpufreq_frequency_table *table)\r
-{\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       if (!table || !info)\r
-               return -1;\r
-\r
-       mutex_lock(&mutex);\r
-       info->dvfs_table = table;\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-int dvfs_set_depend_table(struct clk *clk, char *vd_name, struct cpufreq_frequency_table *table)\r
-{\r
-       struct vd_node          *vd;\r
-       struct depend_list      *depend;\r
-       struct clk_node         *info;\r
-\r
-       info = clk_get_dvfs_info(clk);\r
-       if (!table || !info || !vd_name) {\r
-               DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! table or info or name empty\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (0 == strcmp(vd->name, vd_name)) {\r
-                       DVFS_DBG("FOUND A MATCH\n");\r
-                       mutex_lock(&mutex);\r
-                       list_for_each_entry(depend, &info->depend_list, node2clk) {\r
-                               if (vd == depend->dep_vd && info == depend->dvfs_clk) {\r
-                                       depend->dep_table = table;\r
-                                       break;\r
-                               }\r
-                       }\r
-                       mutex_unlock(&mutex);\r
-                       return 0;\r
-               }\r
-       }\r
-       DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! can not find vd:%s\n", __func__, vd_name);\r
-\r
-       return 0;\r
-}\r
-\r
-int dvfs_set_arm_logic_volt(struct dvfs_arm_table *dvfs_cpu_logic_table,\r
-               struct cpufreq_frequency_table *cpu_dvfs_table,\r
-               struct cpufreq_frequency_table *dep_cpu2core_table)\r
-{\r
-       int i = 0;\r
-       for (i = 0; dvfs_cpu_logic_table[i].frequency != CPUFREQ_TABLE_END; i++) {\r
-               cpu_dvfs_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
-               cpu_dvfs_table[i].index = dvfs_cpu_logic_table[i].cpu_volt;\r
-\r
-               dep_cpu2core_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
-               dep_cpu2core_table[i].index = dvfs_cpu_logic_table[i].logic_volt;\r
-       }\r
-\r
-       cpu_dvfs_table[i].frequency = CPUFREQ_TABLE_END;\r
-       dep_cpu2core_table[i].frequency = CPUFREQ_TABLE_END;\r
-\r
-       dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), cpu_dvfs_table);\r
-       dvfs_set_depend_table(clk_get(NULL, "cpu"), "vd_core", dep_cpu2core_table);\r
-       return 0;\r
-}\r
-\r
-int clk_enable_dvfs(struct clk *clk)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       struct cpufreq_frequency_table clk_fv;\r
-       if (!clk) {\r
-               DVFS_ERR("clk enable dvfs error\n");\r
-               return -1;\r
-       }\r
-       dvfs_clk = clk_get_dvfs_info(clk);\r
-       if (!dvfs_clk || !dvfs_clk->vd) {\r
-               DVFS_ERR("%s clk(%s) not support dvfs!\n", __func__, clk->name);\r
-               return -1;\r
-       }\r
-       if (dvfs_clk->enable_dvfs == 0) {\r
-\r
-               if (IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
-                       //regulator = NULL;\r
-                       if (dvfs_clk->vd->regulator_name)\r
-                               dvfs_clk->vd->regulator = dvfs_regulator_get(NULL, dvfs_clk->vd->regulator_name);\r
-                       if (!IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
-                               // DVFS_DBG("dvfs_regulator_get(%s)\n",dvfs_clk->vd->regulator_name);\r
-                               dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
-                       } else {\r
-                               //dvfs_clk->vd->regulator = NULL;\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               DVFS_ERR("%s can't get regulator in %s\n", dvfs_clk->name, __func__);\r
-                               return -1;\r
-                       }\r
-               } else {\r
-                       dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
-                       // DVFS_DBG("%s(%s) vd volt=%u\n",__func__,dvfs_clk->name,dvfs_clk->vd->cur_volt);\r
-               }\r
-\r
-               dvfs_clk->set_freq = dvfs_clk_get_rate_kz(clk);\r
-               // DVFS_DBG("%s ,%s get freq%u!\n",__func__,dvfs_clk->name,dvfs_clk->set_freq);\r
-\r
-               if (dvfs_clk_get_ref_volt(dvfs_clk, dvfs_clk->set_freq, &clk_fv)) {\r
-                       if (dvfs_clk->dvfs_table[0].frequency == CPUFREQ_TABLE_END) {\r
-                               DVFS_ERR("%s table empty\n", __func__);\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               return -1;\r
-                       } else {\r
-                               DVFS_ERR("WARNING: %s table all value are smaller than default, use default, just enable dvfs\n", __func__);\r
-                               dvfs_clk->enable_dvfs++;\r
-                               return 0;\r
-                       }\r
-               }\r
-\r
-               dvfs_clk->set_volt = clk_fv.index;\r
-               // DVFS_DBG("%s,%s,freq%u(ref vol %u)\n",__func__,dvfs_clk->name,\r
-               //       dvfs_clk->set_freq,dvfs_clk->set_volt);\r
-#if 0\r
-               if (dvfs_clk->dvfs_nb) {\r
-                       // must unregister when clk disable\r
-                       clk_notifier_register(clk, dvfs_clk->dvfs_nb);\r
-               }\r
-#endif\r
-               dvfs_vd_get_newvolt_byclk(dvfs_clk);\r
-#if 0\r
-               if(dvfs_clk->vd->cur_volt < dvfs_clk->set_volt) {\r
-                       int ret;\r
-                       mutex_lock(&rk_dvfs_mutex);\r
-                       ret = dvfs_regulator_set_voltage_readback(dvfs_clk->vd->regulator, dvfs_clk->set_volt, dvfs_clk->set_volt);\r
-                       if (ret < 0) {\r
-                               dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-                               dvfs_clk->enable_dvfs = 0;\r
-                               DVFS_ERR("dvfs enable clk %s,set volt error \n", dvfs_clk->name);\r
-                               mutex_unlock(&rk_dvfs_mutex);\r
-                               return -1;\r
-                       }\r
-                       dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-                       mutex_unlock(&rk_dvfs_mutex);\r
-               }\r
-#endif\r
-               dvfs_clk->enable_dvfs++;\r
-       } else {\r
-               DVFS_ERR("dvfs already enable clk enable = %d!\n", dvfs_clk->enable_dvfs);\r
-               dvfs_clk->enable_dvfs++;\r
-       }\r
-       return 0;\r
-}\r
-\r
-int clk_disable_dvfs(struct clk *clk)\r
-{\r
-       struct clk_node *dvfs_clk;\r
-       dvfs_clk = clk->dvfs_info;\r
-       if (!dvfs_clk->enable_dvfs) {\r
-               DVFS_DBG("clk is already closed!\n");\r
-               return -1;\r
-       } else {\r
-               dvfs_clk->enable_dvfs--;\r
-               if (0 == dvfs_clk->enable_dvfs) {\r
-                       DVFS_ERR("clk closed!\n");\r
-#if 0\r
-                       clk_notifier_unregister(clk, dvfs_clk->dvfs_nb);\r
-                       DVFS_DBG("clk unregister nb!\n");\r
-#endif\r
-               }\r
-       }\r
-       return 0;\r
-}\r
-\r
 static int rk_dvfs_clk_notifier_event(struct notifier_block *this,\r
                unsigned long event, void *ptr)\r
 {\r
@@ -497,232 +76,6 @@ static int rk_dvfs_clk_notifier_event(struct notifier_block *this,
 static struct notifier_block rk_dvfs_clk_notifier = {\r
        .notifier_call = rk_dvfs_clk_notifier_event,\r
 };\r
-\r
-static struct clk_node *dvfs_get_dvfs_clk_byname(char *name) \r
-{\r
-       struct vd_node *vd;\r
-       struct pd_node *pd;\r
-       struct clk_list *child;\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               list_for_each_entry(pd, &vd->pd_list, node) {\r
-                       list_for_each_entry(child, &pd->clk_list, node) {\r
-                               if (0 == strcmp(child->dvfs_clk->name, name)) {\r
-                                       return child->dvfs_clk;\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       return NULL;\r
-}\r
-static int rk_regist_vd(struct vd_node *vd)\r
-{\r
-       if (!vd)\r
-               return -1;\r
-       mutex_lock(&mutex);\r
-       //mutex_init(&vd->dvfs_mutex);\r
-       list_add(&vd->node, &rk_dvfs_tree);\r
-       INIT_LIST_HEAD(&vd->pd_list);\r
-       INIT_LIST_HEAD(&vd->req_volt_list);\r
-\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_pd(struct pd_node_lookup *pd_lookup)\r
-{\r
-       struct vd_node  *vd;\r
-       struct pd_node  *pd;\r
-\r
-       mutex_lock(&mutex);\r
-       pd = pd_lookup->pd;\r
-\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               if (vd == pd->vd) {\r
-                       list_add(&pd->node, &vd->pd_list);\r
-                       INIT_LIST_HEAD(&pd->clk_list);\r
-                       break;\r
-               }\r
-       }\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_clk(struct clk_node *dvfs_clk)\r
-{\r
-       struct pd_node  *pd;\r
-       struct clk_list *child;\r
-       struct clk      *clk;\r
-       int i = 0;\r
-\r
-       if (!dvfs_clk)\r
-               return -1;\r
-\r
-       if (!dvfs_clk->pds)\r
-               return -1;\r
-       mutex_lock(&mutex);\r
-       dvfs_clk->enable_dvfs = 0;\r
-       dvfs_clk->vd = dvfs_clk->pds[0].pd->vd;\r
-       for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
-               child = &(dvfs_clk->pds[i].clk_list);\r
-               child->dvfs_clk = dvfs_clk;\r
-               pd = dvfs_clk->pds[i].pd;\r
-               list_add(&child->node, &pd->clk_list);\r
-       }\r
-       clk = dvfs_clk_get(NULL, dvfs_clk->name);\r
-       dvfs_clk->clk = clk;\r
-       clk_register_dvfs(dvfs_clk, clk);\r
-       INIT_LIST_HEAD(&dvfs_clk->depend_list);\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-\r
-static int rk_regist_depends(struct depend_lookup *dep_node)\r
-{\r
-       struct depend_list      *depend_list;\r
-       struct clk_node         *dvfs_clk;\r
-\r
-       if (!dep_node) {\r
-               DVFS_ERR("%s : DVFS BAD depend node!\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       if (!dep_node->clk_name || !dep_node->dep_vd) {\r
-               DVFS_ERR("%s : DVFS BAD depend members!\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       depend_list = &dep_node->dep_list;\r
-       dvfs_clk = dvfs_get_dvfs_clk_byname(dep_node->clk_name);\r
-\r
-       mutex_lock(&mutex);\r
-\r
-       depend_list->dvfs_clk = dvfs_clk;\r
-       depend_list->dep_vd = dep_node->dep_vd;\r
-       depend_list->dep_table = dep_node->dep_table;\r
-\r
-       list_add(&depend_list->node2clk, &dvfs_clk->depend_list);\r
-       list_add(&depend_list->node2vd, &depend_list->dep_vd->req_volt_list);\r
-\r
-       mutex_unlock(&mutex);\r
-       return 0;\r
-}\r
-#if 0\r
-static int dvfs_set_depend_pre(struct clk_node *dvfs_clk, unsigned long rate_old, unsigned long rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table  clk_fv;\r
-       int ret = -1;\r
-       int volt = 0;\r
-       struct regulator *regulator;\r
-\r
-       if (rate_old >= rate_new) {\r
-               return 0;\r
-       }\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s LOGIC DVFS CAN NOT GET REF VOLT!, frequency too large!\n", __func__);\r
-                       return -1;\r
-               }\r
-\r
-               if (!depend->dep_vd->regulator) {\r
-                       DVFS_DBG("%s regulator empty\n", __func__);\r
-                       regulator = dvfs_regulator_get(NULL, depend->dep_vd->regulator_name);\r
-                       if (!regulator) {\r
-                               DVFS_ERR("%s get regulator err\n", __func__);\r
-                               return -1;\r
-                       }\r
-\r
-                       depend->dep_vd->regulator = regulator;\r
-               }\r
-               if (IS_ERR_OR_NULL(depend->dep_vd->regulator)) {\r
-                       DVFS_ERR("%s vd's(%s) regulator not NULL but error\n", __func__, depend->dep_vd->name);\r
-                       return -1;\r
-               }\r
-\r
-               if (clk_fv.index == dvfs_regulator_get_voltage(depend->dep_vd->regulator)) {\r
-                       depend->req_volt = clk_fv.index;\r
-                       DVFS_DBG("%s same voltage\n", __func__);\r
-                       return 0;\r
-               }\r
-\r
-               depend->req_volt = clk_fv.index;\r
-               volt = dvfs_vd_get_newvolt_bypd(depend->dep_vd);\r
-               DVFS_DBG("%s setting voltage = %d\n", __func__, volt);\r
-               ret = dvfs_regulator_set_voltage_readback(depend->dep_vd->regulator, volt, volt);\r
-               if (0 != ret) {\r
-                       DVFS_ERR("%s set voltage = %d ERROR, ret = %d\n", __func__, volt, ret);\r
-                       return -1;\r
-               }\r
-               udelay(200);\r
-               DVFS_DBG("%s set voltage = %d OK, ret = %d\n", __func__, volt, ret);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s err, ret = %d\n", __func__, ret);\r
-                       return -1;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-static int dvfs_set_depend_post(struct clk_node *dvfs_clk, unsigned long rate_old, unsigned long rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table  clk_fv;\r
-       int ret = -1;\r
-       int volt = 0;\r
-       struct regulator *regulator;\r
-\r
-       if (rate_old <= rate_new)\r
-               return 0;\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s LOGIC DVFS CAN NOT GET REF VOLT!, frequency too large!\n", __func__);\r
-                       return -1;\r
-               }\r
-\r
-               if (!depend->dep_vd->regulator) {\r
-                       DVFS_DBG("%s regulator empty\n", __func__);\r
-                       regulator = dvfs_regulator_get(NULL, depend->dep_vd->regulator_name);\r
-                       if (!regulator) {\r
-                               DVFS_ERR("%s get regulator err\n", __func__);\r
-                               return -1;\r
-                       }\r
-\r
-                       depend->dep_vd->regulator = regulator;\r
-               }\r
-               if (IS_ERR_OR_NULL(depend->dep_vd->regulator)) {\r
-                       DVFS_ERR("%s vd's(%s) regulator not NULL but error\n", __func__, depend->dep_vd->name);\r
-                       return -1;\r
-               }\r
-\r
-               if (clk_fv.index == dvfs_regulator_get_voltage(depend->dep_vd->regulator)) {\r
-                       depend->req_volt = clk_fv.index;\r
-                       DVFS_DBG("%s same voltage\n", __func__);\r
-                       return 0;\r
-               }\r
-\r
-               depend->req_volt = clk_fv.index;\r
-               volt = dvfs_vd_get_newvolt_bypd(depend->dep_vd);\r
-               DVFS_DBG("%s setting voltage = %d\n", __func__, volt);\r
-               ret = dvfs_regulator_set_voltage_readback(depend->dep_vd->regulator, volt, volt);\r
-               if (0 != ret) {\r
-                       DVFS_ERR("%s set voltage = %d ERROR, ret = %d\n", __func__, volt, ret);\r
-                       return -1;\r
-               }\r
-               udelay(200);\r
-               DVFS_DBG("%s set voltage = %d OK, ret = %d\n", __func__, volt, ret);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("%s err, ret = %d\n", __func__, ret);\r
-                       return -1;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-#endif\r
-\r
 #ifdef CONFIG_ARCH_RK3066B\r
 static int g_arm_high_logic = 50 * 1000;\r
 static int g_logic_high_arm = 100 * 1000;\r
@@ -731,306 +84,6 @@ static int g_arm_high_logic = 150 * 1000;
 static int g_logic_high_arm = 100 * 1000;\r
 #endif\r
 \r
-int correct_volt(int *volt_clk, int *volt_dep, int clk_biger_than_dep, int dep_biger_than_clk)\r
-{\r
-       int up_boundary = 0, low_boundary = 0;\r
-\r
-       up_boundary = *volt_clk + dep_biger_than_clk;\r
-       low_boundary = *volt_clk - clk_biger_than_dep;\r
-\r
-       if (*volt_dep < low_boundary || *volt_dep > up_boundary) {\r
-\r
-               if (*volt_dep < low_boundary) {\r
-                       *volt_dep = low_boundary;\r
-\r
-               } else if (*volt_dep > up_boundary) {\r
-                       *volt_clk = *volt_dep - dep_biger_than_clk;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int dvfs_scale_volt(struct vd_node *vd_clk, struct vd_node *vd_dep,\r
-               int volt_old, int volt_new, int volt_dep_old, int volt_dep_new, int clk_biger_than_dep, int dep_biger_than_clk)\r
-{\r
-       struct regulator *regulator, *regulator_dep;\r
-       int volt = 0, volt_dep = 0, step = 0, step_dep = 0;\r
-       int volt_pre = 0, volt_dep_pre = 0;\r
-       int ret = 0;\r
-\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d), volt_dep=%d(dep_old=%d)\n", __func__, volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       regulator = vd_clk->regulator;\r
-       regulator_dep = vd_dep->regulator;\r
-\r
-       if (IS_ERR_OR_NULL(regulator) || IS_ERR(regulator_dep)) {\r
-               DVFS_ERR("%s dvfs_clk->vd->regulator or depend->dep_vd->regulator == NULL\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       volt = volt_old;\r
-       volt_dep = volt_dep_old;\r
-\r
-       step = volt_new - volt_old > 0 ? 1 : (-1);\r
-       step_dep = volt_dep_new - volt_dep_old > 0 ? 1 : (-1);\r
-\r
-       DVFS_DBG("step=%d step_dep=%d %d\n", step, step_dep, step * step_dep);\r
-\r
-       DVFS_DBG("Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n",\r
-                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       do {\r
-               volt_pre = volt;\r
-               volt_dep_pre = volt_dep;\r
-               if (step * step_dep < 0) {\r
-                       // target is between volt_old and volt_dep_old, just\r
-                       // need one step\r
-                       DVFS_DBG("step * step_dep < 0\n");\r
-                       volt = volt_new;\r
-                       volt_dep = volt_dep_new;\r
-\r
-               } else if (step > 0) {\r
-                       // up voltage\r
-                       DVFS_DBG("step > 0\n");\r
-\r
-                       if (volt > volt_dep) {\r
-                               if (volt_dep == volt_dep_new) {\r
-                                       volt = volt_dep + clk_biger_than_dep;\r
-                               } else {\r
-                                       volt_dep = volt + dep_biger_than_clk;\r
-                               }\r
-                       } else {\r
-                               if (volt == volt_new) {\r
-                                       volt_dep = volt + dep_biger_than_clk;\r
-                               } else {\r
-                                       volt = volt_dep + clk_biger_than_dep;\r
-                               }\r
-                       }\r
-                       volt = volt > volt_new ? volt_new : volt;\r
-                       volt_dep = volt_dep > volt_dep_new ? volt_dep_new : volt_dep;\r
-\r
-               } else if (step < 0) {\r
-                       // down voltage\r
-                       DVFS_DBG("step < 0\n");\r
-                       if (volt > volt_dep) {\r
-                               if (volt == volt_new) {\r
-                                       volt_dep = volt - clk_biger_than_dep;\r
-                               } else {\r
-                                       volt = volt_dep - dep_biger_than_clk;\r
-                               }\r
-                       } else {\r
-                               if (volt_dep == volt_dep_new) {\r
-                                       volt = volt_dep - dep_biger_than_clk;\r
-                               } else {\r
-                                       volt_dep = volt - clk_biger_than_dep;\r
-                               }\r
-                       }\r
-                       volt = volt < volt_new ? volt_new : volt;\r
-                       volt_dep = volt_dep < volt_dep_new ? volt_dep_new : volt_dep;\r
-\r
-               } else {\r
-                       DVFS_ERR("Oops, some bugs here:Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n",\r
-                                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-                       goto fail;\r
-               }\r
-\r
-               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
-                       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
-                               goto fail;\r
-                       }\r
-                       vd_clk->cur_volt = volt;\r
-               }\r
-               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
-                       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
-                               goto fail;\r
-                       }\r
-                       vd_dep->cur_volt = volt_dep;\r
-               }\r
-\r
-               DVFS_DBG("\t\tNOW:Volt=%d, volt_dep=%d\n", volt, volt_dep);\r
-\r
-       } while (volt != volt_new || volt_dep != volt_dep_new);\r
-\r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       vd_clk->cur_volt = volt_new;\r
-\r
-       return 0;\r
-fail:\r
-       DVFS_ERR("+++++++++++++++++FAIL AREA\n");\r
-       vd_clk->cur_volt = volt_old;\r
-       vd_dep->cur_volt = volt_dep_old;\r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-       ret = dvfs_regulator_set_voltage_readback(regulator, volt_old, volt_old);\r
-       if (ret < 0) {\r
-               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n",\r
-                               __func__, vd_clk->name, ret, volt_new, volt_old);\r
-       }\r
-\r
-       ret = dvfs_regulator_set_voltage_readback(regulator_dep, volt_dep_old, volt_dep_old);\r
-       if (ret < 0) {\r
-               vd_dep->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n",\r
-                               __func__, vd_dep->name, ret, volt_dep_new, volt_dep_old);\r
-       }\r
-\r
-       return -1;\r
-}\r
-\r
-int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new)\r
-{\r
-       int ret = 0;\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d)\n", __func__, volt_new, vd_clk->cur_volt);\r
-       if (IS_ERR_OR_NULL(vd_clk)) {\r
-               DVFS_ERR("%s vd_node error\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       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
-               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
-                                       __func__, vd_clk->name, ret, volt_new, vd_clk->cur_volt);\r
-                       return -1;\r
-               }\r
-\r
-       } else {\r
-               DVFS_ERR("%s up volt dvfs_clk->vd->regulator == NULL\n", __func__);\r
-               return -1;\r
-       }\r
-\r
-       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       vd_clk->cur_volt = volt_new;\r
-\r
-       return 0;\r
-\r
-}\r
-\r
-int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int volt_new, int volt_dep_new,\r
-               int cur_clk_biger_than_dep, int cur_dep_biger_than_clk, int new_clk_biger_than_dep, int new_dep_biger_than_clk)\r
-{\r
-\r
-       struct regulator *regulator, *regulator_dep;\r
-       int volt_new_corrected = 0, volt_dep_new_corrected = 0;\r
-       int volt_old = 0, volt_dep_old = 0;\r
-       int ret = 0;\r
-\r
-       volt_old = vd_clk->cur_volt;\r
-       volt_dep_old = vd_dep->cur_volt;\r
-\r
-       DVFS_DBG("ENTER %s, volt=%d(old=%d) vd_dep=%d(dep_old=%d)\n", __func__,\r
-                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
-       DVFS_DBG("ENTER %s, VOLT_DIFF: clk_cur=%d(clk_new=%d) dep_cur=%d(dep_new=%d)\n", __func__,\r
-                       cur_clk_biger_than_dep, new_clk_biger_than_dep, \r
-                       cur_dep_biger_than_clk, new_dep_biger_than_clk);\r
-\r
-       volt_new_corrected = volt_new;\r
-       volt_dep_new_corrected = volt_dep_new;\r
-       correct_volt(&volt_new_corrected, &volt_dep_new_corrected, cur_clk_biger_than_dep, cur_dep_biger_than_clk);\r
-       ret = dvfs_scale_volt(vd_clk, vd_dep, volt_old, volt_new_corrected, volt_dep_old, volt_dep_new_corrected,\r
-                       cur_clk_biger_than_dep, cur_dep_biger_than_clk);\r
-       if (ret < 0) {\r
-               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
-               DVFS_ERR("set volt error\n");\r
-               return -1;\r
-       }\r
-\r
-       if (cur_clk_biger_than_dep != new_clk_biger_than_dep || cur_dep_biger_than_clk != new_dep_biger_than_clk) {\r
-               regulator = vd_clk->regulator;\r
-               regulator_dep = vd_dep->regulator;\r
-\r
-               volt_new_corrected = volt_new;\r
-               volt_dep_new_corrected = volt_dep_new;\r
-               correct_volt(&volt_new_corrected, &volt_dep_new_corrected, new_clk_biger_than_dep, new_dep_biger_than_clk);\r
-\r
-               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
-                       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
-                               return -1;\r
-                       }\r
-                       vd_clk->cur_volt = volt_new_corrected;\r
-               }\r
-               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
-                       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
-                               return -1;\r
-                       }\r
-                       vd_dep->cur_volt = volt_dep_new_corrected;\r
-               }\r
-       }\r
-\r
-       return 0;\r
-}\r
-\r
-int dvfs_reset_volt(struct vd_node *dvfs_vd)\r
-{\r
-       int flag_set_volt_correct = 0;\r
-       if (!IS_ERR_OR_NULL(dvfs_vd->regulator))\r
-               flag_set_volt_correct = dvfs_regulator_get_voltage(dvfs_vd->regulator);\r
-       else {\r
-               DVFS_ERR("dvfs regulator is ERROR\n");\r
-               return -1;\r
-       }\r
-       if (flag_set_volt_correct <= 0) {\r
-               DVFS_ERR("%s (clk:%s), try to reload arm_volt error %d!!! stop scaling\n",\r
-                               __func__, dvfs_vd->name, flag_set_volt_correct);\r
-               return -1;\r
-       }\r
-       dvfs_vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
-       DVFS_ERR("%s (clk:%s), try to reload arm_volt! arm_volt_correct = %d\n",\r
-                       __func__, dvfs_vd->name, flag_set_volt_correct);\r
-\r
-       /* Reset vd's voltage */\r
-       dvfs_vd->cur_volt = flag_set_volt_correct;\r
-\r
-       return dvfs_vd->cur_volt;\r
-}\r
-\r
-int dvfs_get_depend_volt(struct clk_node *dvfs_clk, struct vd_node *dvfs_vd_dep, int rate_new)\r
-{\r
-       struct depend_list      *depend;\r
-       struct cpufreq_frequency_table clk_fv_dep;\r
-       int ret = 0;\r
-\r
-       DVFS_DBG("ENTER %s, rate_new=%d\n", __func__, rate_new);\r
-       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-               DVFS_DBG("--round depend clk:%s(depend:%s)\n", depend->dvfs_clk->name, depend->dep_vd->name);\r
-               // this place just consider ONE depend voltage domain,\r
-               // multi-depends must have some differece\r
-               clk_fv_dep.index = 0;\r
-               if (depend->dep_vd == dvfs_vd_dep) {\r
-                       ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv_dep);\r
-                       if (ret < 0) {\r
-                               DVFS_ERR("%s get dvfs_ref_volt_depend error\n", __func__);\r
-                               return -1;\r
-                       }\r
-                       depend->req_volt = clk_fv_dep.index;\r
-                       return depend->req_volt;\r
-               }\r
-       }\r
-\r
-       DVFS_ERR("%s can not find vd node %s\n", __func__, dvfs_vd_dep->name);\r
-       return -1;\r
-}\r
 \r
 #ifdef CONFIG_SOC_RK3168\r
 static struct cpufreq_frequency_table arm_high_logic_table[] = {\r
@@ -1292,7 +345,6 @@ int dvfs_target_core(struct clk *clk, unsigned long rate_hz)
        if (dvfs_clk->clk_dvfs_target) {\r
                ret = dvfs_clk->clk_dvfs_target(clk, rate_new, clk_set_rate_locked);\r
        } else {\r
-\r
                ret = clk_set_rate_locked(clk, rate_new);\r
        }\r
 \r
@@ -1522,6 +574,7 @@ static struct depend_lookup rk30_depends[] = {
        //RK_DEPPENDS("gpu", &vd_cpu, NULL),\r
        //RK_DEPPENDS("gpu", &vd_cpu, NULL),\r
 };\r
+static struct avs_ctr_st rk30_avs_ctr;\r
 \r
 int rk30_dvfs_init(void)\r
 {\r
@@ -1539,69 +592,18 @@ int rk30_dvfs_init(void)
                rk_regist_depends(&rk30_depends[i]);\r
        }\r
        dvfs_clk_cpu = dvfs_get_dvfs_clk_byname("cpu");\r
+       avs_board_init(&rk30_avs_ctr);\r
+       printk("rk30_dvfs_init\n");\r
        return 0;\r
 }\r
 \r
-/*******************************AVS AREA****************************************/\r
-/*\r
- * To use AVS function, you must call avs_init in machine_rk30_board_init(void)(board-rk30-sdk.c)\r
- * And then call(vdd_log):\r
- *     regulator_set_voltage(dcdc, 1100000, 1100000);\r
- *     avs_init_val_get(1,1100000,"wm8326 init");\r
- *     udelay(600);\r
- *     avs_set_scal_val(AVS_BASE);\r
- * in wm831x_post_init(board-rk30-sdk-wm8326.c)\r
- * AVS_BASE can use 172\r
- */\r
 \r
-static int avs_scale_volt = 0;\r
-static int avs_get_scal_val(int vol);\r
 \r
-int dvfs_avs_scale_table(struct clk *clk, char *depend_vd_name)\r
-{\r
-       /* if depend_vd_name == NULL scale clk table\r
-        * else scale clk's depend table, named depend_vd_name\r
-        * */\r
-       struct vd_node          *vd;\r
-       struct depend_list      *depend;\r
-       struct clk_node *info = clk_get_dvfs_info(clk);\r
-       struct cpufreq_frequency_table  *table = NULL;\r
-       int i;\r
-\r
-       if (NULL == depend_vd_name) {\r
-               table = info->dvfs_table;\r
-       } else {\r
-               list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-                       if (0 == strcmp(vd->name, depend_vd_name)) {\r
-                               DVFS_DBG("%s FOUND A MATCH vd\n", __func__);\r
-                               mutex_lock(&mutex);\r
-                               list_for_each_entry(depend, &info->depend_list, node2clk) {\r
-                                       if (vd == depend->dep_vd && info == depend->dvfs_clk) {\r
-                                               DVFS_DBG("%s FOUND A MATCH table\n", __func__);\r
-                                               table = depend->dep_table;\r
-                                               break;\r
-                                       }\r
-                               }\r
-                               mutex_unlock(&mutex);\r
-                       }\r
-               }\r
-       }\r
+/******************************rk30 avs**************************************************/\r
 \r
-       if (table == NULL) {\r
-               DVFS_ERR("%s can not find match table\n", __func__);\r
-               return -1;\r
-       }\r
-       if (avs_scale_volt != 0) {\r
-               DVFS_DBG("AVS scale %s, depend name = %s, voltage = %d\n",\r
-                               info->name, depend_vd_name, avs_scale_volt);\r
-               for (i = 0; table[i].frequency != CPUFREQ_TABLE_END; i++) {\r
-                       table[i].index = avs_get_scal_val(table[i].index);\r
-               }\r
-       }\r
-       return 0;\r
-}\r
+#ifdef CONFIG_ARCH_RK3066B\r
 \r
-static void __iomem *rk30_nandc_base;\r
+static void __iomem *rk30_nandc_base=NULL;\r
 \r
 #define nandc_readl(offset)    readl_relaxed(rk30_nandc_base + offset)\r
 #define nandc_writel(v, offset) do { writel_relaxed(v, rk30_nandc_base + offset); dsb(); } while (0)\r
@@ -1611,6 +613,9 @@ static u8 rk30_get_avs_val(void)
        unsigned long flags;\r
        u32 paramet = 0;\r
        u32 count = 100;\r
+       if(rk30_nandc_base==NULL)       \r
+               return 0;\r
+               \r
        preempt_disable();\r
        local_irq_save(flags);\r
 \r
@@ -1622,7 +627,7 @@ static u8 rk30_get_avs_val(void)
        nandc_writel(nanc_save_reg[0] | 0x1 << 14, 0);\r
        nandc_writel(0x5, 0x130);\r
 \r
-       nandc_writel(7, 0x158);\r
+       nandc_writel(3, 0x158);\r
        nandc_writel(1, 0x134);\r
 \r
        while(count--) {\r
@@ -1642,409 +647,15 @@ static u8 rk30_get_avs_val(void)
        return (u8)paramet;\r
 \r
 }\r
-#define init_avs_times 10\r
-#define init_avs_st_num 5\r
-\r
-struct init_avs_st {\r
-       int is_set;\r
-       u8 paramet[init_avs_times];\r
-       int vol;\r
-       char *s;\r
-};\r
 \r
-static struct init_avs_st init_avs_paramet[init_avs_st_num];\r
-\r
-void avs_init_val_get(int index, int vol, char *s)\r
+void rk30_avs_init(void)\r
 {\r
-       int i;\r
-       if(index >= init_avs_times)\r
-               return;\r
-       init_avs_paramet[index].vol = vol;\r
-       init_avs_paramet[index].s = s;\r
-       init_avs_paramet[index].is_set++;\r
-       for(i = 0; i < init_avs_times; i++) {\r
-               init_avs_paramet[index].paramet[i] = rk30_get_avs_val();\r
-               mdelay(1);\r
-       }\r
-}\r
-\r
-void avs_init(void)\r
-{\r
-       memset(&init_avs_paramet[0].is_set, 0, sizeof(init_avs_paramet));\r
        rk30_nandc_base = ioremap(RK30_NANDC_PHYS, RK30_NANDC_SIZE);\r
-       //avs_init_val_get(0,1150000,"board_init");\r
-}\r
-\r
-#define VOL_DYN_STEP (12500)  //mv\r
-#define AVS_VAL_PER_STEP (4)  //mv\r
-\r
-static u8 avs_init_get_min_val(void)\r
-{\r
-       int i, j;\r
-       u8 min_avs = 0xff;\r
-       for(i = 0; i < init_avs_st_num; i++) {\r
-               if(init_avs_paramet[i].is_set && init_avs_paramet[i].vol == (1100 * 1000)) {\r
-                       for(j = 0; j < init_avs_times; j++)\r
-                               min_avs = (u8)min(min_avs, init_avs_paramet[i].paramet[j]);\r
-               }\r
-\r
-       }\r
-       return min_avs;\r
-}\r
-\r
-static int avs_get_scal_val(int vol)\r
-{\r
-       vol += avs_scale_volt;\r
-       if(vol < 1000 * 1000)\r
-               vol = 1000 * 1000;\r
-       if(vol > 1400 * 1000)\r
-               vol = 1400 * 1000;\r
-       return vol;\r
 }\r
-#if 0\r
-u8 avs_test_date[] = {172, 175, 176, 179, 171, 168, 165, 162, 199, 0};\r
-u8 avs_test_date_cunt = 0;\r
-#endif\r
-int avs_set_scal_val(u8 avs_base)\r
-{\r
-       u8 avs_test = avs_init_get_min_val();\r
-       s8 step = 0;\r
-\r
-       if (avs_base < avs_test) {\r
-               DVFS_DBG("AVS down voltage, ignore\n");\r
-               return 0;\r
-       }\r
-       step = (avs_base - avs_test) / AVS_VAL_PER_STEP;\r
-       step = (avs_base > avs_test) ? (step + 1) : step;\r
-       if (step > 2)\r
-               step += 1;\r
-       avs_scale_volt = (step) * (VOL_DYN_STEP);\r
-\r
-       DVFS_DBG("avs_set_scal_val test=%d,base=%d,step=%d,scale_vol=%d\n",\r
-                       avs_test, avs_base, step, avs_scale_volt);\r
-       return 0;\r
-}\r
-\r
-/*************************interface to get avs value and dvfs tree*************************/\r
-#define USE_NORMAL_TIME\r
-#ifdef USE_NORMAL_TIME\r
-static struct timer_list avs_timer;\r
-#else\r
-static struct hrtimer dvfs_hrtimer;\r
-#endif\r
-\r
-static u32 avs_dyn_start = 0;\r
-static u32 avs_dyn_data_cnt;\r
-static u8 *avs_dyn_data = NULL;\r
-static u32 show_line_cnt = 0;\r
-static u8 dly_min;\r
-static u8 dly_max;\r
-\r
-#define val_per_line (30)\r
-#define line_pre_show (30)\r
-#define avs_dyn_data_num (3*1000*1000)\r
-\r
-static u32 print_avs_init(char *buf)\r
-{\r
-       char *s = buf;\r
-       int i, j;\r
-\r
-       for(j = 0; j < init_avs_st_num; j++) {\r
-               if(init_avs_paramet[j].vol <= 0)\r
-                       continue;\r
-               s += sprintf(s, "%s ,vol=%d,paramet following\n",\r
-                               init_avs_paramet[j].s, init_avs_paramet[j].vol);\r
-               for(i = 0; i < init_avs_times; i++) {\r
-                       s += sprintf(s, "%d ", init_avs_paramet[j].paramet[i]);\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-       }\r
-       return (s - buf);\r
-}\r
-\r
-static ssize_t avs_init_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return print_avs_init(buf);\r
-}\r
-\r
-static ssize_t avs_init_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-\r
-       return n;\r
-}\r
-static ssize_t avs_now_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return sprintf(buf, "%d\n", rk30_get_avs_val());\r
-}\r
-\r
-static ssize_t avs_now_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       return n;\r
-}\r
-static ssize_t avs_dyn_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       char *s = buf;\r
-       u32 i;\r
-\r
-       if(avs_dyn_data == NULL)\r
-               return (s - buf);\r
-\r
-       if(avs_dyn_start) {\r
-               int start_cnt;\r
-               int end_cnt;\r
-               end_cnt = (avs_dyn_data_cnt ? (avs_dyn_data_cnt - 1) : 0);\r
-               if(end_cnt > (line_pre_show * val_per_line))\r
-                       start_cnt = end_cnt - (line_pre_show * val_per_line);\r
-               else\r
-                       start_cnt = 0;\r
-\r
-               dly_min = avs_dyn_data[start_cnt];\r
-               dly_max = avs_dyn_data[start_cnt];\r
-\r
-               //s += sprintf(s,"data start=%d\n",i);\r
-               for(i = start_cnt; i <= end_cnt;) {\r
-                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
-                       dly_min = min(dly_min, avs_dyn_data[i]);\r
-                       dly_max = max(dly_max, avs_dyn_data[i]);\r
-                       i++;\r
-                       if(!(i % val_per_line)) {\r
-                               s += sprintf(s, "\n");\r
-                       } else\r
-                               s += sprintf(s, " ");\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-\r
-               s += sprintf(s, "new data is from=%d to %d\n", start_cnt, end_cnt);\r
-               //s += sprintf(s,"\n max=%d,min=%d,totolcnt=%d,line=%d\n",dly_max,dly_min,avs_dyn_data_cnt,show_line_cnt);\r
-\r
-\r
-       } else {\r
-               if(show_line_cnt == 0) {\r
-                       dly_min = avs_dyn_data[0];\r
-                       dly_max = avs_dyn_data[0];\r
-               }\r
-\r
-\r
-               for(i = show_line_cnt * (line_pre_show * val_per_line); i < avs_dyn_data_cnt;) {\r
-                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
-                       dly_min = min(dly_min, avs_dyn_data[i]);\r
-                       dly_max = max(dly_max, avs_dyn_data[i]);\r
-                       i++;\r
-                       if(!(i % val_per_line)) {\r
-                               s += sprintf(s, "\n");\r
-                       } else\r
-                               s += sprintf(s, " ");\r
-                       if(i >= ((show_line_cnt + 1)*line_pre_show * val_per_line))\r
-                               break;\r
-               }\r
-\r
-               s += sprintf(s, "\n");\r
-\r
-               s += sprintf(s, "max=%d,min=%d,totolcnt=%d,line=%d\n",\r
-                               dly_max, dly_min, avs_dyn_data_cnt, show_line_cnt);\r
-               show_line_cnt++;\r
-               if(((show_line_cnt * line_pre_show)*val_per_line) >= avs_dyn_data_cnt) {\r
-\r
-                       show_line_cnt = 0;\r
-\r
-                       s += sprintf(s, "data is over\n");\r
-               }\r
-       }\r
-       return (s - buf);\r
-}\r
-\r
-static ssize_t avs_dyn_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       const char *pbuf;\r
-\r
-       if((strncmp(buf, "start", strlen("start")) == 0)) {\r
-               if(avs_dyn_data == NULL)\r
-                       avs_dyn_data = kmalloc(avs_dyn_data_num, GFP_KERNEL);\r
-               if(avs_dyn_data == NULL)\r
-                       return n;\r
-\r
-               pbuf = &buf[strlen("start")];\r
-               avs_dyn_data_cnt = 0;\r
-               show_line_cnt = 0;\r
-               if(avs_dyn_data) {\r
-#ifdef USE_NORMAL_TIME\r
-                       mod_timer(&avs_timer, jiffies + msecs_to_jiffies(5));\r
-#else\r
-                       hrtimer_start(&dvfs_hrtimer, ktime_set(0, 5 * 1000 * 1000), HRTIMER_MODE_REL);\r
-#endif\r
-                       avs_dyn_start = 1;\r
-               }\r
-               //sscanf(pbuf, "%d %d", &number, &voltage);\r
-               //DVFS_DBG("---------ldo %d %d\n", number, voltage);\r
-\r
-       } else if((strncmp(buf, "stop", strlen("stop")) == 0)) {\r
-               pbuf = &buf[strlen("stop")];\r
-               avs_dyn_start = 0;\r
-               show_line_cnt = 0;\r
-               //sscanf(pbuf, "%d %d", &number, &voltage);\r
-               //DVFS_DBG("---------dcdc %d %d\n", number, voltage);\r
-       }\r
-\r
-\r
-\r
-       return n;\r
-}\r
-\r
-static ssize_t dvfs_tree_store(struct kobject *kobj, struct kobj_attribute *attr,\r
-               const char *buf, size_t n)\r
-{\r
-       return n;\r
-}\r
-static ssize_t dvfs_tree_show(struct kobject *kobj, struct kobj_attribute *attr,\r
-               char *buf)\r
-{\r
-       return dump_dbg_map(buf);\r
-\r
-}\r
-\r
-static void avs_timer_fn(unsigned long data)\r
-{\r
-       int i;\r
-       for(i = 0; i < 1; i++) {\r
-               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
-                       return;\r
-               avs_dyn_data[avs_dyn_data_cnt] = rk30_get_avs_val();\r
-               avs_dyn_data_cnt++;\r
-       }\r
-       if(avs_dyn_start)\r
-               mod_timer(&avs_timer, jiffies + msecs_to_jiffies(10));\r
-}\r
-#if 0\r
-struct hrtimer dvfs_hrtimer;\r
-static enum hrtimer_restart dvfs_hrtimer_timer_func(struct hrtimer *timer)\r
-{\r
-       int i;\r
-       for(i = 0; i < 1; i++) {\r
-               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
-                       return HRTIMER_NORESTART;\r
-               avs_dyn_data[avs_dyn_data_cnt] = rk30_get_avs_val();\r
-               avs_dyn_data_cnt++;\r
-       }\r
-       if(avs_dyn_start)\r
-               hrtimer_start(timer, ktime_set(0, 1 * 1000 * 1000), HRTIMER_MODE_REL);\r
-\r
-}\r
-#endif\r
-/*********************************************************************************/\r
-static struct kobject *dvfs_kobj;\r
-struct dvfs_attribute {\r
-       struct attribute        attr;\r
-       ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,\r
-                       char *buf);\r
-       ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,\r
-                       const char *buf, size_t n);\r
+static struct avs_ctr_st rk30_avs_ctr= {\r
+       .avs_init               =rk30_avs_init,\r
+       .avs_get_val    = rk30_get_avs_val,\r
 };\r
-\r
-static struct dvfs_attribute dvfs_attrs[] = {\r
-       /*     node_name        permision               show_func       store_func */\r
-#ifdef CONFIG_RK_CLOCK_PROC\r
-       __ATTR(dvfs_tree,       S_IRUGO | S_IWUSR,      dvfs_tree_show, dvfs_tree_store),\r
-       //__ATTR(avs_init,      S_IRUGO | S_IWUSR,      avs_init_show,  avs_init_store),\r
-       //__ATTR(avs_dyn,               S_IRUGO | S_IWUSR,      avs_dyn_show,   avs_dyn_store),\r
-       //__ATTR(avs_now,               S_IRUGO | S_IWUSR,      avs_now_show,   avs_now_store),\r
 #endif\r
-};\r
-\r
-static int __init dvfs_init(void)\r
-{\r
-       int i, ret = 0;\r
-#ifdef USE_NORMAL_TIME\r
-       init_timer(&avs_timer);\r
-       //avs_timer.expires = jiffies+msecs_to_jiffies(1);\r
-       avs_timer.function = avs_timer_fn;\r
-       //mod_timer(&avs_timer,jiffies+msecs_to_jiffies(1));\r
-#else\r
-       hrtimer_init(&dvfs_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);\r
-       dvfs_hrtimer.function = dvfs_hrtimer_timer_func;\r
-       //hrtimer_start(&dvfs_hrtimer,ktime_set(0, 5*1000*1000),HRTIMER_MODE_REL);\r
-#endif\r
-\r
-       dvfs_kobj = kobject_create_and_add("dvfs", NULL);\r
-       if (!dvfs_kobj)\r
-               return -ENOMEM;\r
-       for (i = 0; i < ARRAY_SIZE(dvfs_attrs); i++) {\r
-               ret = sysfs_create_file(dvfs_kobj, &dvfs_attrs[i].attr);\r
-               if (ret != 0) {\r
-                       DVFS_ERR("create index %d error\n", i);\r
-                       return ret;\r
-               }\r
-       }\r
-\r
-       return ret;\r
-}\r
-subsys_initcall(dvfs_init);\r
-\r
-/**\r
- * dump_dbg_map() : Draw all informations of dvfs while debug\r
- */\r
-static int dump_dbg_map(char *buf)\r
-{\r
-       int i;\r
-       struct vd_node  *vd;\r
-       struct pd_node  *pd, *clkparent;\r
-       struct clk_list *child;\r
-       struct clk_node *dvfs_clk;\r
-       struct depend_list *depend;\r
-       char *s = buf;\r
-\r
-       s += sprintf(s, "-------------DVFS TREE-----------\n\n\n");\r
-       s += sprintf(s, "RK30 DVFS TREE:\n");\r
-       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
-               s += sprintf(s, "|\n|- voltage domain:%s\n", vd->name);\r
-               s += sprintf(s, "|- current voltage:%d\n", vd->cur_volt);\r
-               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
-                       s += sprintf(s, "|- request voltage:%d, clk:%s\n", depend->req_volt, depend->dvfs_clk->name);\r
-               }\r
-\r
-               list_for_each_entry(pd, &vd->pd_list, node) {\r
-                       s += sprintf(s, "|  |\n|  |- power domain:%s, status = %s, current volt = %d\n",\r
-                                       pd->name, (pd->pd_status == PD_ON) ? "ON" : "OFF", pd->cur_volt);\r
-\r
-                       list_for_each_entry(child, &pd->clk_list, node) {\r
-                               dvfs_clk = child->dvfs_clk;\r
-                               s += sprintf(s, "|  |  |\n|  |  |- clock: %s current: rate %d, volt = %d, enable_dvfs = %s\n",\r
-                                               dvfs_clk->name, dvfs_clk->set_freq, dvfs_clk->set_volt,\r
-                                               dvfs_clk->enable_dvfs == 0 ? "DISABLE" : "ENABLE");\r
-                               for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
-                                       clkparent = dvfs_clk->pds[i].pd;\r
-                                       s += sprintf(s, "|  |  |  |- clock parents: %s, vd_parent = %s\n",\r
-                                                       clkparent->name, clkparent->vd->name);\r
-                               }\r
-\r
-                               for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-                                       s += sprintf(s, "|  |  |  |- freq = %d, volt = %d\n",\r
-                                                       dvfs_clk->dvfs_table[i].frequency,\r
-                                                       dvfs_clk->dvfs_table[i].index);\r
-\r
-                               }\r
-\r
-                               list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
-                                       s += sprintf(s, "|  |  |  |  |- DEPEND VD: %s\n", depend->dep_vd->name);\r
-                                       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
-                                               s += sprintf(s, "|  |  |  |  |- freq = %d, req_volt = %d\n",\r
-                                                               depend->dep_table[i].frequency,\r
-\r
-                                                               depend->dep_table[i].index);\r
-                                       }\r
-                               }\r
-                       }\r
-               }\r
-       }\r
-       s += sprintf(s, "-------------DVFS TREE END------------\n");\r
-       return s - buf;\r
-}\r
 \r
 \r
old mode 100644 (file)
new mode 100755 (executable)
index c94e185..0ef29c2
@@ -14,5 +14,6 @@ obj-y += iomux.o
 CFLAGS_sram.o += -mthumb
 obj-$(CONFIG_DDR_TEST) += memtester.o ddr_test.o
 obj-$(CONFIG_DDR_FREQ) += ddr_freq.o
+obj-$(CONFIG_DVFS) += dvfs.o
 obj-y += pwm.o
 obj-$(CONFIG_RK_TIMER) += rk_timer.o
diff --git a/arch/arm/plat-rk/dvfs.c b/arch/arm/plat-rk/dvfs.c
new file mode 100755 (executable)
index 0000000..36e8332
--- /dev/null
@@ -0,0 +1,1221 @@
+/* arch/arm/mach-rk30/rk30_dvfs.c\r
+ *\r
+ * Copyright (C) 2012 ROCKCHIP, Inc.\r
+ *\r
+ * This software is licensed under the terms of the GNU General Public\r
+ * License version 2, as published by the Free Software Foundation, and\r
+ * may be copied, distributed, and modified under those terms.\r
+ *\r
+ * This program is distributed in the hope that it will be useful,\r
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+ * GNU General Public License for more details.\r
+ *\r
+ */\r
+\r
+#include <linux/kernel.h>\r
+#include <linux/err.h>\r
+#include <linux/spinlock.h>\r
+#include <linux/list.h>\r
+#include <linux/slab.h>\r
+#include <linux/clk.h>\r
+#include <linux/cpufreq.h>\r
+#include <mach/dvfs.h>\r
+#include <mach/clock.h>\r
+#include <linux/regulator/consumer.h>\r
+#include <linux/delay.h>\r
+#include <linux/io.h>\r
+#include <linux/hrtimer.h>\r
+\r
+\r
+static LIST_HEAD(rk_dvfs_tree);\r
+static DEFINE_MUTEX(mutex);\r
+static DEFINE_MUTEX(rk_dvfs_mutex);\r
+\r
+static int dump_dbg_map(char *buf);\r
+\r
+#define PD_ON  1\r
+#define PD_OFF 0\r
+\r
+#define get_volt_up_delay(new_volt, old_volt)  \\r
+       ((new_volt) > (old_volt) ? (((new_volt) - (old_volt)) >> 9) : 0)\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
+       ret = dvfs_regulator_set_voltage(regulator, max_uV, max_uV);\r
+       if (ret < 0) {\r
+               DVFS_ERR("%s now read back to check voltage\n", __func__);\r
+\r
+               /* read back to judge if it is already effect */\r
+               mdelay(2);\r
+               read_back = dvfs_regulator_get_voltage(regulator);\r
+               if (read_back == max_uV) {\r
+                       DVFS_ERR("%s set ERROR but already effected, volt=%d\n", __func__, read_back);\r
+                       ret = 0;\r
+               } else {\r
+                       DVFS_ERR("%s set ERROR AND NOT effected, volt=%d\n", __func__, read_back);\r
+               }\r
+       }\r
+       return ret;\r
+}\r
+\r
+struct regulator *dvfs_get_regulator(char *regulator_name) \r
+{\r
+       struct vd_node *vd;\r
+       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
+               if (strcmp(regulator_name, vd->regulator_name) == 0) {\r
+                       return vd->regulator;\r
+               }\r
+       }\r
+       return NULL;\r
+}\r
+\r
+int dvfs_clk_enable_limit(struct clk *clk, unsigned int min_rate, unsigned max_rate)\r
+{\r
+       struct clk_node *dvfs_clk;\r
+       u32 rate = 0;\r
+       dvfs_clk = clk->dvfs_info;\r
+\r
+       dvfs_clk->freq_limit_en = 1;\r
+       dvfs_clk->min_rate = min_rate;\r
+       dvfs_clk->max_rate = max_rate;\r
+\r
+       rate = clk_get_rate(clk);\r
+       if (rate < min_rate)\r
+               dvfs_clk_set_rate(clk, min_rate);\r
+       else if (rate > max_rate)\r
+               dvfs_clk_set_rate(clk, max_rate);\r
+       return 0;\r
+}\r
+\r
+int dvfs_clk_disable_limit(struct clk *clk)\r
+{\r
+       struct clk_node *dvfs_clk;\r
+       dvfs_clk = clk->dvfs_info;\r
+\r
+       dvfs_clk->freq_limit_en = 0;\r
+\r
+       return 0;\r
+}\r
+\r
+int is_support_dvfs(struct clk_node *dvfs_info)\r
+{\r
+       return (dvfs_info->vd && dvfs_info->vd->vd_dvfs_target && dvfs_info->enable_dvfs);\r
+}\r
+\r
+int dvfs_set_rate(struct clk *clk, unsigned long rate)\r
+{\r
+       int ret = 0;\r
+       struct vd_node *vd;\r
+       DVFS_DBG("%s(%s(%lu))\n", __func__, clk->name, rate);\r
+       if (!clk->dvfs_info) {\r
+               DVFS_ERR("%s :This clk do not support dvfs!\n", __func__);\r
+               ret = -1;\r
+       } else {\r
+               vd = clk->dvfs_info->vd;\r
+               // mutex_lock(&vd->dvfs_mutex);\r
+               mutex_lock(&rk_dvfs_mutex);\r
+               ret = vd->vd_dvfs_target(clk, rate);\r
+               mutex_unlock(&rk_dvfs_mutex);\r
+               // mutex_unlock(&vd->dvfs_mutex);\r
+       }\r
+       DVFS_DBG("%s(%s(%lu)),is end\n", __func__, clk->name, rate);\r
+       return ret;\r
+}\r
+\r
+static int dvfs_clk_get_ref_volt_depend(struct depend_list *depend, int rate_khz,\r
+               struct cpufreq_frequency_table *clk_fv)\r
+{\r
+       int i = 0;\r
+       if (rate_khz == 0 || !depend || !depend->dep_table) {\r
+               return -1;\r
+       }\r
+       clk_fv->frequency = rate_khz;\r
+       clk_fv->index = 0;\r
+\r
+       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
+               if (depend->dep_table[i].frequency >= rate_khz) {\r
+                       clk_fv->frequency = depend->dep_table[i].frequency;\r
+                       clk_fv->index = depend->dep_table[i].index;\r
+                       return 0;\r
+               }\r
+       }\r
+       clk_fv->frequency = 0;\r
+       clk_fv->index = 0;\r
+       return -1;\r
+}\r
+int dvfs_clk_get_ref_volt(struct clk_node *dvfs_clk, int rate_khz,\r
+               struct cpufreq_frequency_table *clk_fv)\r
+{\r
+       int i = 0;\r
+       if (rate_khz == 0 || !dvfs_clk || !dvfs_clk->dvfs_table) {\r
+               /* since no need */\r
+               return -1;\r
+       }\r
+       clk_fv->frequency = rate_khz;\r
+       clk_fv->index = 0;\r
+\r
+       for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
+               if (dvfs_clk->dvfs_table[i].frequency >= rate_khz) {\r
+                       clk_fv->frequency = dvfs_clk->dvfs_table[i].frequency;\r
+                       clk_fv->index = dvfs_clk->dvfs_table[i].index;\r
+                       // DVFS_DBG("%s,%s rate=%ukhz(vol=%d)\n",__func__,dvfs_clk->name,\r
+                       // clk_fv->frequency, clk_fv->index);\r
+                       return 0;\r
+               }\r
+       }\r
+       clk_fv->frequency = 0;\r
+       clk_fv->index = 0;\r
+       // DVFS_DBG("%s get corresponding voltage error! out of bound\n", dvfs_clk->name);\r
+       return -1;\r
+}\r
+\r
+static int dvfs_pd_get_newvolt_byclk(struct pd_node *pd, struct clk_node *dvfs_clk)\r
+{\r
+       struct clk_list *child;\r
+       int volt_max = 0;\r
+\r
+       if (!pd || !dvfs_clk)\r
+               return 0;\r
+\r
+       if (dvfs_clk->set_volt >= pd->cur_volt) {\r
+               return dvfs_clk->set_volt;\r
+       }\r
+\r
+       list_for_each_entry(child, &pd->clk_list, node) {\r
+               // DVFS_DBG("%s ,pd(%s),dvfs(%s),volt(%u)\n",__func__,pd->name,\r
+               // dvfs_clk->name,dvfs_clk->set_volt);\r
+               volt_max = max(volt_max, child->dvfs_clk->set_volt);\r
+       }\r
+       return volt_max;\r
+}\r
+\r
+void dvfs_update_clk_pds_volt(struct clk_node *dvfs_clk)\r
+{\r
+       struct pd_node   *pd;\r
+       int i;\r
+       if (!dvfs_clk)\r
+               return;\r
+       for (i = 0; (dvfs_clk->pds[i].pd != NULL); i++) {\r
+               pd = dvfs_clk->pds[i].pd;\r
+               // DVFS_DBG("%s dvfs(%s),pd(%s)\n",__func__,dvfs_clk->name,pd->name);\r
+               pd->cur_volt = dvfs_pd_get_newvolt_byclk(pd, dvfs_clk);\r
+       }\r
+}\r
+\r
+int dvfs_vd_get_newvolt_bypd(struct vd_node *vd)\r
+{\r
+       struct pd_node          *pd;\r
+       struct depend_list      *depend;\r
+       int     volt_max_vd = 0;\r
+       list_for_each_entry(pd, &vd->pd_list, node) {\r
+               // DVFS_DBG("%s pd(%s,%u)\n",__func__,pd->name,pd->cur_volt);\r
+               volt_max_vd = max(volt_max_vd, pd->cur_volt);\r
+       }\r
+\r
+       /* some clks depend on this voltage domain */\r
+       if (!list_empty(&vd->req_volt_list)) {\r
+               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
+                       volt_max_vd = max(volt_max_vd, depend->req_volt);\r
+               }\r
+       }\r
+       return volt_max_vd;\r
+}\r
+\r
+int dvfs_vd_get_newvolt_byclk(struct clk_node *dvfs_clk)\r
+{\r
+       if (!dvfs_clk)\r
+               return -1;\r
+       dvfs_update_clk_pds_volt(dvfs_clk);\r
+       return  dvfs_vd_get_newvolt_bypd(dvfs_clk->vd);\r
+}\r
+\r
+void dvfs_clk_register_set_rate_callback(struct clk *clk, clk_dvfs_target_callback clk_dvfs_target)\r
+{\r
+       struct clk_node *dvfs_clk = clk_get_dvfs_info(clk);\r
+       if (IS_ERR_OR_NULL(dvfs_clk)) {\r
+               DVFS_ERR("%s %s get dvfs_clk err\n", __func__, clk->name);\r
+               return ;\r
+       }\r
+       dvfs_clk->clk_dvfs_target = clk_dvfs_target;\r
+}\r
+\r
+struct cpufreq_frequency_table *dvfs_get_freq_volt_table(struct clk *clk) \r
+{\r
+       struct clk_node *info = clk_get_dvfs_info(clk);\r
+       struct cpufreq_frequency_table *table;\r
+       if (!info || !info->dvfs_table) {\r
+               return NULL;\r
+       }\r
+       mutex_lock(&mutex);\r
+       table = info->dvfs_table;\r
+       mutex_unlock(&mutex);\r
+       return table;\r
+}\r
+\r
+int dvfs_set_freq_volt_table(struct clk *clk, struct cpufreq_frequency_table *table)\r
+{\r
+       struct clk_node *info = clk_get_dvfs_info(clk);\r
+       if (!table || !info)\r
+               return -1;\r
+\r
+       mutex_lock(&mutex);\r
+       info->dvfs_table = table;\r
+       mutex_unlock(&mutex);\r
+       return 0;\r
+}\r
+\r
+int dvfs_set_depend_table(struct clk *clk, char *vd_name, struct cpufreq_frequency_table *table)\r
+{\r
+       struct vd_node          *vd;\r
+       struct depend_list      *depend;\r
+       struct clk_node         *info;\r
+\r
+       info = clk_get_dvfs_info(clk);\r
+       if (!table || !info || !vd_name) {\r
+               DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! table or info or name empty\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
+               if (0 == strcmp(vd->name, vd_name)) {\r
+                       DVFS_DBG("FOUND A MATCH\n");\r
+                       mutex_lock(&mutex);\r
+                       list_for_each_entry(depend, &info->depend_list, node2clk) {\r
+                               if (vd == depend->dep_vd && info == depend->dvfs_clk) {\r
+                                       depend->dep_table = table;\r
+                                       break;\r
+                               }\r
+                       }\r
+                       mutex_unlock(&mutex);\r
+                       return 0;\r
+               }\r
+       }\r
+       DVFS_ERR("%s :DVFS SET DEPEND TABLE ERROR! can not find vd:%s\n", __func__, vd_name);\r
+\r
+       return 0;\r
+}\r
+\r
+int dvfs_set_arm_logic_volt(struct dvfs_arm_table *dvfs_cpu_logic_table,\r
+               struct cpufreq_frequency_table *cpu_dvfs_table,\r
+               struct cpufreq_frequency_table *dep_cpu2core_table)\r
+{\r
+       int i = 0;\r
+       for (i = 0; dvfs_cpu_logic_table[i].frequency != CPUFREQ_TABLE_END; i++) {\r
+               cpu_dvfs_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
+               cpu_dvfs_table[i].index = dvfs_cpu_logic_table[i].cpu_volt;\r
+\r
+               dep_cpu2core_table[i].frequency = dvfs_cpu_logic_table[i].frequency;\r
+               dep_cpu2core_table[i].index = dvfs_cpu_logic_table[i].logic_volt;\r
+       }\r
+\r
+       cpu_dvfs_table[i].frequency = CPUFREQ_TABLE_END;\r
+       dep_cpu2core_table[i].frequency = CPUFREQ_TABLE_END;\r
+\r
+       dvfs_set_freq_volt_table(clk_get(NULL, "cpu"), cpu_dvfs_table);\r
+       dvfs_set_depend_table(clk_get(NULL, "cpu"), "vd_core", dep_cpu2core_table);\r
+       return 0;\r
+}\r
+\r
+int clk_enable_dvfs(struct clk *clk)\r
+{\r
+       struct clk_node *dvfs_clk;\r
+       struct cpufreq_frequency_table clk_fv;\r
+       if (!clk) {\r
+               DVFS_ERR("clk enable dvfs error\n");\r
+               return -1;\r
+       }\r
+       dvfs_clk = clk_get_dvfs_info(clk);\r
+       if (!dvfs_clk || !dvfs_clk->vd) {\r
+               DVFS_ERR("%s clk(%s) not support dvfs!\n", __func__, clk->name);\r
+               return -1;\r
+       }\r
+       if (dvfs_clk->enable_dvfs == 0) {\r
+\r
+               if (IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
+                       //regulator = NULL;\r
+                       if (dvfs_clk->vd->regulator_name)\r
+                               dvfs_clk->vd->regulator = dvfs_regulator_get(NULL, dvfs_clk->vd->regulator_name);\r
+                       if (!IS_ERR_OR_NULL(dvfs_clk->vd->regulator)) {\r
+                               // DVFS_DBG("dvfs_regulator_get(%s)\n",dvfs_clk->vd->regulator_name);\r
+                               dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
+                       } else {\r
+                               //dvfs_clk->vd->regulator = NULL;\r
+                               dvfs_clk->enable_dvfs = 0;\r
+                               DVFS_ERR("%s can't get regulator in %s\n", dvfs_clk->name, __func__);\r
+                               return -1;\r
+                       }\r
+               } else {\r
+                       dvfs_clk->vd->cur_volt = dvfs_regulator_get_voltage(dvfs_clk->vd->regulator);\r
+                       // DVFS_DBG("%s(%s) vd volt=%u\n",__func__,dvfs_clk->name,dvfs_clk->vd->cur_volt);\r
+               }\r
+\r
+               dvfs_clk->set_freq = dvfs_clk_get_rate_kz(clk);\r
+               // DVFS_DBG("%s ,%s get freq%u!\n",__func__,dvfs_clk->name,dvfs_clk->set_freq);\r
+\r
+               if (dvfs_clk_get_ref_volt(dvfs_clk, dvfs_clk->set_freq, &clk_fv)) {\r
+                       if (dvfs_clk->dvfs_table[0].frequency == CPUFREQ_TABLE_END) {\r
+                               DVFS_ERR("%s table empty\n", __func__);\r
+                               dvfs_clk->enable_dvfs = 0;\r
+                               return -1;\r
+                       } else {\r
+                               DVFS_ERR("WARNING: %s table all value are smaller than default, use default, just enable dvfs\n", __func__);\r
+                               dvfs_clk->enable_dvfs++;\r
+                               return 0;\r
+                       }\r
+               }\r
+\r
+               dvfs_clk->set_volt = clk_fv.index;\r
+               // DVFS_DBG("%s,%s,freq%u(ref vol %u)\n",__func__,dvfs_clk->name,\r
+               //       dvfs_clk->set_freq,dvfs_clk->set_volt);\r
+#if 0\r
+               if (dvfs_clk->dvfs_nb) {\r
+                       // must unregister when clk disable\r
+                       clk_notifier_register(clk, dvfs_clk->dvfs_nb);\r
+               }\r
+#endif\r
+               dvfs_vd_get_newvolt_byclk(dvfs_clk);\r
+#if 0\r
+               if(dvfs_clk->vd->cur_volt < dvfs_clk->set_volt) {\r
+                       int ret;\r
+                       mutex_lock(&rk_dvfs_mutex);\r
+                       ret = dvfs_regulator_set_voltage_readback(dvfs_clk->vd->regulator, dvfs_clk->set_volt, dvfs_clk->set_volt);\r
+                       if (ret < 0) {\r
+                               dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
+                               dvfs_clk->enable_dvfs = 0;\r
+                               DVFS_ERR("dvfs enable clk %s,set volt error \n", dvfs_clk->name);\r
+                               mutex_unlock(&rk_dvfs_mutex);\r
+                               return -1;\r
+                       }\r
+                       dvfs_clk->vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
+                       mutex_unlock(&rk_dvfs_mutex);\r
+               }\r
+#endif\r
+               dvfs_clk->enable_dvfs++;\r
+       } else {\r
+               DVFS_ERR("dvfs already enable clk enable = %d!\n", dvfs_clk->enable_dvfs);\r
+               dvfs_clk->enable_dvfs++;\r
+       }\r
+       return 0;\r
+}\r
+\r
+int clk_disable_dvfs(struct clk *clk)\r
+{\r
+       struct clk_node *dvfs_clk;\r
+       dvfs_clk = clk->dvfs_info;\r
+       if (!dvfs_clk->enable_dvfs) {\r
+               DVFS_DBG("clk is already closed!\n");\r
+               return -1;\r
+       } else {\r
+               dvfs_clk->enable_dvfs--;\r
+               if (0 == dvfs_clk->enable_dvfs) {\r
+                       DVFS_ERR("clk closed!\n");\r
+#if 0\r
+                       clk_notifier_unregister(clk, dvfs_clk->dvfs_nb);\r
+                       DVFS_DBG("clk unregister nb!\n");\r
+#endif\r
+               }\r
+       }\r
+       return 0;\r
+}\r
+struct clk_node *dvfs_get_dvfs_clk_byname(char *name) \r
+{\r
+       struct vd_node *vd;\r
+       struct pd_node *pd;\r
+       struct clk_list *child;\r
+       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
+               list_for_each_entry(pd, &vd->pd_list, node) {\r
+                       list_for_each_entry(child, &pd->clk_list, node) {\r
+                               if (0 == strcmp(child->dvfs_clk->name, name)) {\r
+                                       return child->dvfs_clk;\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       return NULL;\r
+}\r
+int rk_regist_vd(struct vd_node *vd)\r
+{\r
+       if (!vd)\r
+               return -1;\r
+       mutex_lock(&mutex);\r
+       //mutex_init(&vd->dvfs_mutex);\r
+       list_add(&vd->node, &rk_dvfs_tree);\r
+       INIT_LIST_HEAD(&vd->pd_list);\r
+       INIT_LIST_HEAD(&vd->req_volt_list);\r
+\r
+       mutex_unlock(&mutex);\r
+       return 0;\r
+}\r
+\r
+int rk_regist_pd(struct pd_node_lookup *pd_lookup)\r
+{\r
+       struct vd_node  *vd;\r
+       struct pd_node  *pd;\r
+\r
+       mutex_lock(&mutex);\r
+       pd = pd_lookup->pd;\r
+\r
+       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
+               if (vd == pd->vd) {\r
+                       list_add(&pd->node, &vd->pd_list);\r
+                       INIT_LIST_HEAD(&pd->clk_list);\r
+                       break;\r
+               }\r
+       }\r
+       mutex_unlock(&mutex);\r
+       return 0;\r
+}\r
+\r
+int rk_regist_clk(struct clk_node *dvfs_clk)\r
+{\r
+       struct pd_node  *pd;\r
+       struct clk_list *child;\r
+       struct clk      *clk;\r
+       int i = 0;\r
+\r
+       if (!dvfs_clk)\r
+               return -1;\r
+\r
+       if (!dvfs_clk->pds)\r
+               return -1;\r
+       mutex_lock(&mutex);\r
+       dvfs_clk->enable_dvfs = 0;\r
+       dvfs_clk->vd = dvfs_clk->pds[0].pd->vd;\r
+       for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
+               child = &(dvfs_clk->pds[i].clk_list);\r
+               child->dvfs_clk = dvfs_clk;\r
+               pd = dvfs_clk->pds[i].pd;\r
+               list_add(&child->node, &pd->clk_list);\r
+       }\r
+       clk = dvfs_clk_get(NULL, dvfs_clk->name);\r
+       dvfs_clk->clk = clk;\r
+       clk_register_dvfs(dvfs_clk, clk);\r
+       INIT_LIST_HEAD(&dvfs_clk->depend_list);\r
+       mutex_unlock(&mutex);\r
+       return 0;\r
+}\r
+\r
+int rk_regist_depends(struct depend_lookup *dep_node)\r
+{\r
+       struct depend_list      *depend_list;\r
+       struct clk_node         *dvfs_clk;\r
+\r
+       if (!dep_node) {\r
+               DVFS_ERR("%s : DVFS BAD depend node!\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       if (!dep_node->clk_name || !dep_node->dep_vd) {\r
+               DVFS_ERR("%s : DVFS BAD depend members!\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       depend_list = &dep_node->dep_list;\r
+       dvfs_clk = dvfs_get_dvfs_clk_byname(dep_node->clk_name);\r
+\r
+       mutex_lock(&mutex);\r
+\r
+       depend_list->dvfs_clk = dvfs_clk;\r
+       depend_list->dep_vd = dep_node->dep_vd;\r
+       depend_list->dep_table = dep_node->dep_table;\r
+\r
+       list_add(&depend_list->node2clk, &dvfs_clk->depend_list);\r
+       list_add(&depend_list->node2vd, &depend_list->dep_vd->req_volt_list);\r
+\r
+       mutex_unlock(&mutex);\r
+       return 0;\r
+}\r
+\r
+int correct_volt(int *volt_clk, int *volt_dep, int clk_biger_than_dep, int dep_biger_than_clk)\r
+{\r
+       int up_boundary = 0, low_boundary = 0;\r
+\r
+       up_boundary = *volt_clk + dep_biger_than_clk;\r
+       low_boundary = *volt_clk - clk_biger_than_dep;\r
+\r
+       if (*volt_dep < low_boundary || *volt_dep > up_boundary) {\r
+\r
+               if (*volt_dep < low_boundary) {\r
+                       *volt_dep = low_boundary;\r
+\r
+               } else if (*volt_dep > up_boundary) {\r
+                       *volt_clk = *volt_dep - dep_biger_than_clk;\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int dvfs_scale_volt(struct vd_node *vd_clk, struct vd_node *vd_dep,\r
+               int volt_old, int volt_new, int volt_dep_old, int volt_dep_new, int clk_biger_than_dep, int dep_biger_than_clk)\r
+{\r
+       struct regulator *regulator, *regulator_dep;\r
+       int volt = 0, volt_dep = 0, step = 0, step_dep = 0;\r
+       int volt_pre = 0, volt_dep_pre = 0;\r
+       int ret = 0;\r
+\r
+       DVFS_DBG("ENTER %s, volt=%d(old=%d), volt_dep=%d(dep_old=%d)\n", __func__, volt_new, volt_old, volt_dep_new, volt_dep_old);\r
+       regulator = vd_clk->regulator;\r
+       regulator_dep = vd_dep->regulator;\r
+\r
+       if (IS_ERR_OR_NULL(regulator) || IS_ERR(regulator_dep)) {\r
+               DVFS_ERR("%s dvfs_clk->vd->regulator or depend->dep_vd->regulator == NULL\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       volt = volt_old;\r
+       volt_dep = volt_dep_old;\r
+\r
+       step = volt_new - volt_old > 0 ? 1 : (-1);\r
+       step_dep = volt_dep_new - volt_dep_old > 0 ? 1 : (-1);\r
+\r
+       DVFS_DBG("step=%d step_dep=%d %d\n", step, step_dep, step * step_dep);\r
+\r
+       DVFS_DBG("Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n",\r
+                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
+       do {\r
+               volt_pre = volt;\r
+               volt_dep_pre = volt_dep;\r
+               if (step * step_dep < 0) {\r
+                       // target is between volt_old and volt_dep_old, just\r
+                       // need one step\r
+                       DVFS_DBG("step * step_dep < 0\n");\r
+                       volt = volt_new;\r
+                       volt_dep = volt_dep_new;\r
+\r
+               } else if (step > 0) {\r
+                       // up voltage\r
+                       DVFS_DBG("step > 0\n");\r
+\r
+                       if (volt > volt_dep) {\r
+                               if (volt_dep == volt_dep_new) {\r
+                                       volt = volt_dep + clk_biger_than_dep;\r
+                               } else {\r
+                                       volt_dep = volt + dep_biger_than_clk;\r
+                               }\r
+                       } else {\r
+                               if (volt == volt_new) {\r
+                                       volt_dep = volt + dep_biger_than_clk;\r
+                               } else {\r
+                                       volt = volt_dep + clk_biger_than_dep;\r
+                               }\r
+                       }\r
+                       volt = volt > volt_new ? volt_new : volt;\r
+                       volt_dep = volt_dep > volt_dep_new ? volt_dep_new : volt_dep;\r
+\r
+               } else if (step < 0) {\r
+                       // down voltage\r
+                       DVFS_DBG("step < 0\n");\r
+                       if (volt > volt_dep) {\r
+                               if (volt == volt_new) {\r
+                                       volt_dep = volt - clk_biger_than_dep;\r
+                               } else {\r
+                                       volt = volt_dep - dep_biger_than_clk;\r
+                               }\r
+                       } else {\r
+                               if (volt_dep == volt_dep_new) {\r
+                                       volt = volt_dep - dep_biger_than_clk;\r
+                               } else {\r
+                                       volt_dep = volt - clk_biger_than_dep;\r
+                               }\r
+                       }\r
+                       volt = volt < volt_new ? volt_new : volt;\r
+                       volt_dep = volt_dep < volt_dep_new ? volt_dep_new : volt_dep;\r
+\r
+               } else {\r
+                       DVFS_ERR("Oops, some bugs here:Volt_new=%d(old=%d), volt_dep_new=%d(dep_old=%d)\n",\r
+                                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
+                       goto fail;\r
+               }\r
+\r
+               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
+                       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
+                               goto fail;\r
+                       }\r
+                       vd_clk->cur_volt = volt;\r
+               }\r
+               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
+                       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
+                               goto fail;\r
+                       }\r
+                       vd_dep->cur_volt = volt_dep;\r
+               }\r
+\r
+               DVFS_DBG("\t\tNOW:Volt=%d, volt_dep=%d\n", volt, volt_dep);\r
+\r
+       } while (volt != volt_new || volt_dep != volt_dep_new);\r
+\r
+       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
+       vd_clk->cur_volt = volt_new;\r
+\r
+       return 0;\r
+fail:\r
+       DVFS_ERR("+++++++++++++++++FAIL AREA\n");\r
+       vd_clk->cur_volt = volt_old;\r
+       vd_dep->cur_volt = volt_dep_old;\r
+       vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
+       ret = dvfs_regulator_set_voltage_readback(regulator, volt_old, volt_old);\r
+       if (ret < 0) {\r
+               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
+               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n",\r
+                               __func__, vd_clk->name, ret, volt_new, volt_old);\r
+       }\r
+\r
+       ret = dvfs_regulator_set_voltage_readback(regulator_dep, volt_dep_old, volt_dep_old);\r
+       if (ret < 0) {\r
+               vd_dep->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
+               DVFS_ERR("%s %s set callback voltage err ret = %d, Vnew = %d(was %d)mV\n",\r
+                               __func__, vd_dep->name, ret, volt_dep_new, volt_dep_old);\r
+       }\r
+\r
+       return -1;\r
+}\r
+\r
+int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new)\r
+{\r
+       int ret = 0;\r
+       DVFS_DBG("ENTER %s, volt=%d(old=%d)\n", __func__, volt_new, vd_clk->cur_volt);\r
+       if (IS_ERR_OR_NULL(vd_clk)) {\r
+               DVFS_ERR("%s vd_node error\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       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
+               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
+                                       __func__, vd_clk->name, ret, volt_new, vd_clk->cur_volt);\r
+                       return -1;\r
+               }\r
+\r
+       } else {\r
+               DVFS_ERR("%s up volt dvfs_clk->vd->regulator == NULL\n", __func__);\r
+               return -1;\r
+       }\r
+\r
+       vd_clk->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
+       vd_clk->cur_volt = volt_new;\r
+\r
+       return 0;\r
+\r
+}\r
+\r
+int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int volt_new, int volt_dep_new,\r
+               int cur_clk_biger_than_dep, int cur_dep_biger_than_clk, int new_clk_biger_than_dep, int new_dep_biger_than_clk)\r
+{\r
+\r
+       struct regulator *regulator, *regulator_dep;\r
+       int volt_new_corrected = 0, volt_dep_new_corrected = 0;\r
+       int volt_old = 0, volt_dep_old = 0;\r
+       int ret = 0;\r
+\r
+       volt_old = vd_clk->cur_volt;\r
+       volt_dep_old = vd_dep->cur_volt;\r
+\r
+       DVFS_DBG("ENTER %s, volt=%d(old=%d) vd_dep=%d(dep_old=%d)\n", __func__,\r
+                       volt_new, volt_old, volt_dep_new, volt_dep_old);\r
+       DVFS_DBG("ENTER %s, VOLT_DIFF: clk_cur=%d(clk_new=%d) dep_cur=%d(dep_new=%d)\n", __func__,\r
+                       cur_clk_biger_than_dep, new_clk_biger_than_dep, \r
+                       cur_dep_biger_than_clk, new_dep_biger_than_clk);\r
+\r
+       volt_new_corrected = volt_new;\r
+       volt_dep_new_corrected = volt_dep_new;\r
+       correct_volt(&volt_new_corrected, &volt_dep_new_corrected, cur_clk_biger_than_dep, cur_dep_biger_than_clk);\r
+       ret = dvfs_scale_volt(vd_clk, vd_dep, volt_old, volt_new_corrected, volt_dep_old, volt_dep_new_corrected,\r
+                       cur_clk_biger_than_dep, cur_dep_biger_than_clk);\r
+       if (ret < 0) {\r
+               vd_clk->volt_set_flag = DVFS_SET_VOLT_FAILURE;\r
+               DVFS_ERR("set volt error\n");\r
+               return -1;\r
+       }\r
+\r
+       if (cur_clk_biger_than_dep != new_clk_biger_than_dep || cur_dep_biger_than_clk != new_dep_biger_than_clk) {\r
+               regulator = vd_clk->regulator;\r
+               regulator_dep = vd_dep->regulator;\r
+\r
+               volt_new_corrected = volt_new;\r
+               volt_dep_new_corrected = volt_dep_new;\r
+               correct_volt(&volt_new_corrected, &volt_dep_new_corrected, new_clk_biger_than_dep, new_dep_biger_than_clk);\r
+\r
+               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
+                       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
+                               return -1;\r
+                       }\r
+                       vd_clk->cur_volt = volt_new_corrected;\r
+               }\r
+               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
+                       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
+                               return -1;\r
+                       }\r
+                       vd_dep->cur_volt = volt_dep_new_corrected;\r
+               }\r
+       }\r
+\r
+       return 0;\r
+}\r
+\r
+int dvfs_reset_volt(struct vd_node *dvfs_vd)\r
+{\r
+       int flag_set_volt_correct = 0;\r
+       if (!IS_ERR_OR_NULL(dvfs_vd->regulator))\r
+               flag_set_volt_correct = dvfs_regulator_get_voltage(dvfs_vd->regulator);\r
+       else {\r
+               DVFS_ERR("dvfs regulator is ERROR\n");\r
+               return -1;\r
+       }\r
+       if (flag_set_volt_correct <= 0) {\r
+               DVFS_ERR("%s (clk:%s), try to reload arm_volt error %d!!! stop scaling\n",\r
+                               __func__, dvfs_vd->name, flag_set_volt_correct);\r
+               return -1;\r
+       }\r
+       dvfs_vd->volt_set_flag = DVFS_SET_VOLT_SUCCESS;\r
+       DVFS_ERR("%s (clk:%s), try to reload arm_volt! arm_volt_correct = %d\n",\r
+                       __func__, dvfs_vd->name, flag_set_volt_correct);\r
+\r
+       /* Reset vd's voltage */\r
+       dvfs_vd->cur_volt = flag_set_volt_correct;\r
+\r
+       return dvfs_vd->cur_volt;\r
+}\r
+\r
+int dvfs_get_depend_volt(struct clk_node *dvfs_clk, struct vd_node *dvfs_vd_dep, int rate_new)\r
+{\r
+       struct depend_list      *depend;\r
+       struct cpufreq_frequency_table clk_fv_dep;\r
+       int ret = 0;\r
+\r
+       DVFS_DBG("ENTER %s, rate_new=%d\n", __func__, rate_new);\r
+       list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
+               DVFS_DBG("--round depend clk:%s(depend:%s)\n", depend->dvfs_clk->name, depend->dep_vd->name);\r
+               // this place just consider ONE depend voltage domain,\r
+               // multi-depends must have some differece\r
+               clk_fv_dep.index = 0;\r
+               if (depend->dep_vd == dvfs_vd_dep) {\r
+                       ret = dvfs_clk_get_ref_volt_depend(depend, rate_new / 1000, &clk_fv_dep);\r
+                       if (ret < 0) {\r
+                               DVFS_ERR("%s get dvfs_ref_volt_depend error\n", __func__);\r
+                               return -1;\r
+                       }\r
+                       depend->req_volt = clk_fv_dep.index;\r
+                       return depend->req_volt;\r
+               }\r
+       }\r
+\r
+       DVFS_ERR("%s can not find vd node %s\n", __func__, dvfs_vd_dep->name);\r
+       return -1;\r
+}\r
+\r
+/**\r
+ * dump_dbg_map() : Draw all informations of dvfs while debug\r
+ */\r
+static int dump_dbg_map(char *buf)\r
+{\r
+       int i;\r
+       struct vd_node  *vd;\r
+       struct pd_node  *pd, *clkparent;\r
+       struct clk_list *child;\r
+       struct clk_node *dvfs_clk;\r
+       struct depend_list *depend;\r
+       char *s = buf;\r
+       mutex_lock(&rk_dvfs_mutex);\r
+\r
+       printk( "-------------DVFS TREE-----------\n\n\n");\r
+       printk( "DVFS TREE:\n");\r
+       list_for_each_entry(vd, &rk_dvfs_tree, node) {\r
+               printk( "|\n|- voltage domain:%s\n", vd->name);\r
+               printk( "|- current voltage:%d\n", vd->cur_volt);\r
+               list_for_each_entry(depend, &vd->req_volt_list, node2vd) {\r
+                       printk( "|- request voltage:%d, clk:%s\n", depend->req_volt, depend->dvfs_clk->name);\r
+               }\r
+\r
+               list_for_each_entry(pd, &vd->pd_list, node) {\r
+                       printk( "|  |\n|  |- power domain:%s, status = %s, current volt = %d\n",\r
+                                       pd->name, (pd->pd_status == PD_ON) ? "ON" : "OFF", pd->cur_volt);\r
+\r
+                       list_for_each_entry(child, &pd->clk_list, node) {\r
+                               dvfs_clk = child->dvfs_clk;\r
+                               printk( "|  |  |\n|  |  |- clock: %s current: rate %d, volt = %d, enable_dvfs = %s\n",\r
+                                               dvfs_clk->name, dvfs_clk->set_freq, dvfs_clk->set_volt,\r
+                                               dvfs_clk->enable_dvfs == 0 ? "DISABLE" : "ENABLE");\r
+                               for (i = 0; dvfs_clk->pds[i].pd != NULL; i++) {\r
+                                       clkparent = dvfs_clk->pds[i].pd;\r
+                                       printk( "|  |  |  |- clock parents: %s, vd_parent = %s\n",\r
+                                                       clkparent->name, clkparent->vd->name);\r
+                               }\r
+\r
+                               for (i = 0; (dvfs_clk->dvfs_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
+                                       printk( "|  |  |  |- freq = %d, volt = %d\n",\r
+                                                       dvfs_clk->dvfs_table[i].frequency,\r
+                                                       dvfs_clk->dvfs_table[i].index);\r
+\r
+                               }\r
+\r
+                               list_for_each_entry(depend, &dvfs_clk->depend_list, node2clk) {\r
+                                       printk( "|  |  |  |  |- DEPEND VD: %s\n", depend->dep_vd->name);\r
+                                       for (i = 0; (depend->dep_table[i].frequency != CPUFREQ_TABLE_END); i++) {\r
+                                               printk( "|  |  |  |  |- freq = %d, req_volt = %d\n",\r
+                                                               depend->dep_table[i].frequency,\r
+\r
+                                                               depend->dep_table[i].index);\r
+                                       }\r
+                               }\r
+                       }\r
+               }\r
+       }\r
+       printk( "-------------DVFS TREE END------------\n");\r
+       \r
+       mutex_unlock(&rk_dvfs_mutex);\r
+       return s - buf;\r
+}\r
+/*******************************AVS AREA****************************************/\r
+/*\r
+ * To use AVS function, you must call avs_init in machine_rk30_board_init(void)(board-rk30-sdk.c)\r
+ * And then call(vdd_log):\r
+ *     regulator_set_voltage(dcdc, 1100000, 1100000);\r
+ *     avs_init_val_get(1,1100000,"wm8326 init");\r
+ *     udelay(600);\r
+ *     avs_set_scal_val(AVS_BASE);\r
+ * in wm831x_post_init(board-rk30-sdk-wm8326.c)\r
+ * AVS_BASE can use 172\r
+ */\r
+\r
+static struct avs_ctr_st *avs_ctr_data=NULL;\r
+#define init_avs_times 10\r
+#define init_avs_st_num 5\r
+\r
+struct init_avs_st {\r
+       int is_set;\r
+       u8 paramet[init_avs_times];\r
+       int vol;\r
+       char *s;\r
+};\r
+\r
+static struct init_avs_st init_avs_paramet[init_avs_st_num];\r
+\r
+void avs_board_init(struct avs_ctr_st *data)\r
+{\r
+       \r
+       avs_ctr_data=data;\r
+}\r
+void avs_init(void)\r
+{\r
+       memset(&init_avs_paramet[0].is_set, 0, sizeof(init_avs_paramet));\r
+       if(avs_ctr_data&&avs_ctr_data->avs_init)\r
+               avs_ctr_data->avs_init();\r
+       avs_init_val_get(0,1150000,"board_init");\r
+}\r
+static u8 rk_get_avs_val(void)\r
+{\r
+       \r
+       if(avs_ctr_data&&avs_ctr_data->avs_get_val)\r
+       {       \r
+               return avs_ctr_data->avs_get_val();\r
+       }\r
+       return 0;\r
+\r
+}\r
+/******************************int val get**************************************/\r
+void avs_init_val_get(int index, int vol, char *s)\r
+{\r
+       int i;\r
+       if(index >= init_avs_times)\r
+               return;\r
+       init_avs_paramet[index].vol = vol;\r
+       init_avs_paramet[index].s = s;\r
+       init_avs_paramet[index].is_set++;\r
+       for(i = 0; i < init_avs_times; i++) {\r
+               init_avs_paramet[index].paramet[i] = rk_get_avs_val();\r
+               mdelay(1);\r
+       }\r
+}\r
+int avs_set_scal_val(u8 avs_base)\r
+{\r
+\r
+}\r
+\r
+/*************************interface to get avs value and dvfs tree*************************/\r
+#define USE_NORMAL_TIME\r
+#ifdef USE_NORMAL_TIME\r
+static struct timer_list avs_timer;\r
+#else\r
+static struct hrtimer dvfs_hrtimer;\r
+#endif\r
+\r
+static u32 avs_dyn_start = 0;\r
+static u32 avs_dyn_data_cnt;\r
+static u8 *avs_dyn_data = NULL;\r
+static u32 show_line_cnt = 0;\r
+static u8 dly_min;\r
+static u8 dly_max;\r
+\r
+#define val_per_line (30)\r
+#define line_pre_show (30)\r
+#define avs_dyn_data_num (3*1000*1000)\r
+\r
+static u32 print_avs_init(char *buf)\r
+{\r
+       char *s = buf;\r
+       int i, j;\r
+\r
+       for(j = 0; j < init_avs_st_num; j++) {\r
+               if(init_avs_paramet[j].vol <= 0)\r
+                       continue;\r
+               s += sprintf(s, "%s ,vol=%d,paramet following\n",\r
+                               init_avs_paramet[j].s, init_avs_paramet[j].vol);\r
+               for(i = 0; i < init_avs_times; i++) {\r
+                       s += sprintf(s, "%d ", init_avs_paramet[j].paramet[i]);\r
+               }\r
+\r
+               s += sprintf(s, "\n");\r
+       }\r
+       return (s - buf);\r
+}\r
+\r
+static ssize_t avs_init_show(struct kobject *kobj, struct kobj_attribute *attr,\r
+               char *buf)\r
+{\r
+       return print_avs_init(buf);\r
+}\r
+\r
+static ssize_t avs_init_store(struct kobject *kobj, struct kobj_attribute *attr,\r
+               const char *buf, size_t n)\r
+{\r
+\r
+       return n;\r
+}\r
+static ssize_t avs_now_show(struct kobject *kobj, struct kobj_attribute *attr,\r
+               char *buf)\r
+{\r
+       return sprintf(buf, "%d\n", rk_get_avs_val());\r
+}\r
+\r
+static ssize_t avs_now_store(struct kobject *kobj, struct kobj_attribute *attr,\r
+               const char *buf, size_t n)\r
+{\r
+       return n;\r
+}\r
+static ssize_t avs_dyn_show(struct kobject *kobj, struct kobj_attribute *attr,\r
+               char *buf)\r
+{\r
+       char *s = buf;\r
+       u32 i;\r
+\r
+       if(avs_dyn_data == NULL)\r
+               return (s - buf);\r
+\r
+       if(avs_dyn_start) {\r
+               int start_cnt;\r
+               int end_cnt;\r
+               end_cnt = (avs_dyn_data_cnt ? (avs_dyn_data_cnt - 1) : 0);\r
+               if(end_cnt > (line_pre_show * val_per_line))\r
+                       start_cnt = end_cnt - (line_pre_show * val_per_line);\r
+               else\r
+                       start_cnt = 0;\r
+\r
+               dly_min = avs_dyn_data[start_cnt];\r
+               dly_max = avs_dyn_data[start_cnt];\r
+\r
+               //s += sprintf(s,"data start=%d\n",i);\r
+               for(i = start_cnt; i <= end_cnt;) {\r
+                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
+                       dly_min = min(dly_min, avs_dyn_data[i]);\r
+                       dly_max = max(dly_max, avs_dyn_data[i]);\r
+                       i++;\r
+                       if(!(i % val_per_line)) {\r
+                               s += sprintf(s, "\n");\r
+                       } else\r
+                               s += sprintf(s, " ");\r
+               }\r
+\r
+               s += sprintf(s, "\n");\r
+\r
+               s += sprintf(s, "new data is from=%d to %d\n", start_cnt, end_cnt);\r
+               //s += sprintf(s,"\n max=%d,min=%d,totolcnt=%d,line=%d\n",dly_max,dly_min,avs_dyn_data_cnt,show_line_cnt);\r
+\r
+\r
+       } else {\r
+               if(show_line_cnt == 0) {\r
+                       dly_min = avs_dyn_data[0];\r
+                       dly_max = avs_dyn_data[0];\r
+               }\r
+\r
+\r
+               for(i = show_line_cnt * (line_pre_show * val_per_line); i < avs_dyn_data_cnt;) {\r
+                       s += sprintf(s, "%d", avs_dyn_data[i]);\r
+                       dly_min = min(dly_min, avs_dyn_data[i]);\r
+                       dly_max = max(dly_max, avs_dyn_data[i]);\r
+                       i++;\r
+                       if(!(i % val_per_line)) {\r
+                               s += sprintf(s, "\n");\r
+                       } else\r
+                               s += sprintf(s, " ");\r
+                       if(i >= ((show_line_cnt + 1)*line_pre_show * val_per_line))\r
+                               break;\r
+               }\r
+\r
+               s += sprintf(s, "\n");\r
+\r
+               s += sprintf(s, "max=%d,min=%d,totolcnt=%d,line=%d\n",\r
+                               dly_max, dly_min, avs_dyn_data_cnt, show_line_cnt);\r
+               show_line_cnt++;\r
+               if(((show_line_cnt * line_pre_show)*val_per_line) >= avs_dyn_data_cnt) {\r
+\r
+                       show_line_cnt = 0;\r
+\r
+                       s += sprintf(s, "data is over\n");\r
+               }\r
+       }\r
+       return (s - buf);\r
+}\r
+\r
+static ssize_t avs_dyn_store(struct kobject *kobj, struct kobj_attribute *attr,\r
+               const char *buf, size_t n)\r
+{\r
+       const char *pbuf;\r
+\r
+       if((strncmp(buf, "start", strlen("start")) == 0)) {\r
+               if(avs_dyn_data == NULL)\r
+                       avs_dyn_data = kmalloc(avs_dyn_data_num, GFP_KERNEL);\r
+               if(avs_dyn_data == NULL)\r
+                       return n;\r
+\r
+               pbuf = &buf[strlen("start")];\r
+               avs_dyn_data_cnt = 0;\r
+               show_line_cnt = 0;\r
+               if(avs_dyn_data) {\r
+#ifdef USE_NORMAL_TIME\r
+                       mod_timer(&avs_timer, jiffies + msecs_to_jiffies(5));\r
+#else\r
+                       hrtimer_start(&dvfs_hrtimer, ktime_set(0, 5 * 1000 * 1000), HRTIMER_MODE_REL);\r
+#endif\r
+                       avs_dyn_start = 1;\r
+               }\r
+               //sscanf(pbuf, "%d %d", &number, &voltage);\r
+               //DVFS_DBG("---------ldo %d %d\n", number, voltage);\r
+\r
+       } else if((strncmp(buf, "stop", strlen("stop")) == 0)) {\r
+               pbuf = &buf[strlen("stop")];\r
+               avs_dyn_start = 0;\r
+               show_line_cnt = 0;\r
+               //sscanf(pbuf, "%d %d", &number, &voltage);\r
+               //DVFS_DBG("---------dcdc %d %d\n", number, voltage);\r
+       }\r
+\r
+\r
+\r
+       return n;\r
+}\r
+\r
+static ssize_t dvfs_tree_store(struct kobject *kobj, struct kobj_attribute *attr,\r
+               const char *buf, size_t n)\r
+{\r
+       return n;\r
+}\r
+static ssize_t dvfs_tree_show(struct kobject *kobj, struct kobj_attribute *attr,\r
+               char *buf)\r
+{\r
+       return dump_dbg_map(buf);\r
+\r
+}\r
+\r
+static void avs_timer_fn(unsigned long data)\r
+{\r
+       int i;\r
+       for(i = 0; i < 1; i++) {\r
+               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
+                       return;\r
+               avs_dyn_data[avs_dyn_data_cnt] = rk_get_avs_val();\r
+               avs_dyn_data_cnt++;\r
+       }\r
+       if(avs_dyn_start)\r
+               mod_timer(&avs_timer, jiffies + msecs_to_jiffies(10));\r
+}\r
+#if 0\r
+struct hrtimer dvfs_hrtimer;\r
+static enum hrtimer_restart dvfs_hrtimer_timer_func(struct hrtimer *timer)\r
+{\r
+       int i;\r
+       for(i = 0; i < 1; i++) {\r
+               if(avs_dyn_data_cnt >= avs_dyn_data_num)\r
+                       return HRTIMER_NORESTART;\r
+               avs_dyn_data[avs_dyn_data_cnt] = rk_get_avs_val();\r
+               avs_dyn_data_cnt++;\r
+       }\r
+       if(avs_dyn_start)\r
+               hrtimer_start(timer, ktime_set(0, 1 * 1000 * 1000), HRTIMER_MODE_REL);\r
+\r
+}\r
+#endif\r
+/*********************************************************************************/\r
+static struct kobject *dvfs_kobj;\r
+struct dvfs_attribute {\r
+       struct attribute        attr;\r
+       ssize_t (*show)(struct kobject *kobj, struct kobj_attribute *attr,\r
+                       char *buf);\r
+       ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,\r
+                       const char *buf, size_t n);\r
+};\r
+\r
+static struct dvfs_attribute dvfs_attrs[] = {\r
+       /*     node_name        permision               show_func       store_func */\r
+#ifdef CONFIG_RK_CLOCK_PROC\r
+       __ATTR(dvfs_tree,       S_IRUGO | S_IWUSR,      dvfs_tree_show, dvfs_tree_store),\r
+       __ATTR(avs_init,        S_IRUGO | S_IWUSR,      avs_init_show,  avs_init_store),\r
+       //__ATTR(avs_dyn,               S_IRUGO | S_IWUSR,      avs_dyn_show,   avs_dyn_store),\r
+       __ATTR(avs_now,         S_IRUGO | S_IWUSR,      avs_now_show,   avs_now_store),\r
+#endif\r
+};\r
+\r
+static int __init dvfs_init(void)\r
+{\r
+       int i, ret = 0;\r
+#ifdef USE_NORMAL_TIME\r
+       init_timer(&avs_timer);\r
+       //avs_timer.expires = jiffies+msecs_to_jiffies(1);\r
+       avs_timer.function = avs_timer_fn;\r
+       //mod_timer(&avs_timer,jiffies+msecs_to_jiffies(1));\r
+#else\r
+       hrtimer_init(&dvfs_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);\r
+       dvfs_hrtimer.function = dvfs_hrtimer_timer_func;\r
+       //hrtimer_start(&dvfs_hrtimer,ktime_set(0, 5*1000*1000),HRTIMER_MODE_REL);\r
+#endif\r
+\r
+       dvfs_kobj = kobject_create_and_add("dvfs", NULL);\r
+       if (!dvfs_kobj)\r
+               return -ENOMEM;\r
+       for (i = 0; i < ARRAY_SIZE(dvfs_attrs); i++) {\r
+               ret = sysfs_create_file(dvfs_kobj, &dvfs_attrs[i].attr);\r
+               if (ret != 0) {\r
+                       DVFS_ERR("create index %d error\n", i);\r
+                       return ret;\r
+               }\r
+       }\r
+\r
+       return ret;\r
+}\r
+subsys_initcall(dvfs_init);\r
old mode 100644 (file)
new mode 100755 (executable)
index 59ec37d..2512a49
@@ -140,8 +140,70 @@ struct dvfs_arm_table {
        unsigned int    logic_volt;\r
 };\r
 \r
+\r
+#define DVFS_MHZ (1000*1000)\r
+#define DVFS_KHZ (1000)\r
+\r
+#define DVFS_V (1000*1000)\r
+#define DVFS_MV (1000)\r
+#if 0\r
+#define DVFS_DBG(fmt, args...) printk(KERN_DEBUG "DVFS DBG:\t"fmt, ##args)\r
+#else\r
+#define DVFS_DBG(fmt, args...) {while(0);}\r
+#endif\r
+\r
+#define DVFS_ERR(fmt, args...) printk(KERN_ERR "DVFS ERR:\t"fmt, ##args)\r
+#define DVFS_LOG(fmt, args...) printk(KERN_DEBUG "DVFS LOG:\t"fmt, ##args)\r
+\r
+\r
+#define DVFS_SET_VOLT_FAILURE  1\r
+#define DVFS_SET_VOLT_SUCCESS  0\r
+\r
+\r
+#define dvfs_regulator_get(dev,id) regulator_get((dev),(id))\r
+#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
+\r
+#define dvfs_clk_get(a,b) clk_get((a),(b))\r
+#define dvfs_clk_get_rate_kz(a) (clk_get_rate((a))/1000)\r
+#define dvfs_clk_set_rate(a,b) clk_set_rate((a),(b))\r
+#define dvfs_clk_enable(a) clk_enable((a))\r
+#define dvfs_clk_disable(a) clk_disable((a))\r
+\r
+\r
+\r
+\r
+typedef void (*avs_init_fn)(void);\r
+typedef u8 (*avs_get_val_fn)(void);\r
+struct avs_ctr_st {\r
+       avs_init_fn             avs_init;\r
+       avs_get_val_fn          avs_get_val;\r
+};\r
+\r
+\r
+\r
+\r
 #ifdef CONFIG_DVFS\r
-int rk30_dvfs_init(void);\r
+/***********************************************************************************/\r
+int dvfs_clk_get_ref_volt(struct clk_node *dvfs_clk, int rate_khz,\r
+               struct cpufreq_frequency_table *clk_fv);\r
+struct clk_node *clk_get_dvfs_info(struct clk *clk);\r
+int dvfs_reset_volt(struct vd_node *dvfs_vd);\r
+int dvfs_vd_get_newvolt_byclk(struct clk_node *dvfs_clk);\r
+int dvfs_get_depend_volt(struct clk_node *dvfs_clk, struct vd_node *dvfs_vd_dep, int rate_new);\r
+int dvfs_vd_get_newvolt_bypd(struct vd_node *vd);\r
+int dvfs_scale_volt_bystep(struct vd_node *vd_clk, struct vd_node *vd_dep, int volt_new, int volt_dep_new,\r
+               int cur_clk_biger_than_dep, int cur_dep_biger_than_clk, int new_clk_biger_than_dep, int new_dep_biger_than_clk);\r
+int rk_regist_vd(struct vd_node *vd);\r
+int rk_regist_pd(struct pd_node_lookup *pd_lookup);\r
+int rk_regist_clk(struct clk_node *dvfs_clk);\r
+int rk_regist_depends(struct depend_lookup *dep_node);\r
+struct clk_node *dvfs_get_dvfs_clk_byname(char *name) ;\r
+\r
+\r
+/******************************************************************************/\r
+\r
 int is_support_dvfs(struct clk_node *dvfs_info);\r
 int dvfs_set_rate(struct clk *clk, unsigned long rate);\r
 int clk_enable_dvfs(struct clk *clk);\r
@@ -154,13 +216,14 @@ int dvfs_set_arm_logic_volt(struct dvfs_arm_table *dvfs_cpu_logic_table, struct
 struct regulator* dvfs_get_regulator(char *regulator_name);\r
 int dvfs_clk_enable_limit(struct clk *clk, unsigned int min_rate, unsigned max_rate);\r
 int dvfs_clk_disable_limit(struct clk *clk);\r
+int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new);\r
 \r
 void avs_init(void);\r
 void avs_init_val_get(int index,int vol,char *s);\r
 int avs_set_scal_val(u8 avs_base);\r
-int dvfs_avs_scale_table(struct clk* clk, char* depend_vd_name);\r
+void avs_board_init(struct avs_ctr_st *data);\r
+\r
 #else\r
-static inline int rk30_dvfs_init(void) { return 0; }\r
 static inline int is_support_dvfs(struct clk_node *dvfs_info) { return 0; }\r
 static inline int dvfs_set_rate(struct clk *clk, unsigned long rate) { return 0; }\r
 static inline int clk_enable_dvfs(struct clk *clk) { return 0; }\r
@@ -173,11 +236,12 @@ static inline int dvfs_set_arm_logic_volt(struct dvfs_arm_table *dvfs_cpu_logic_
 static inline struct regulator* dvfs_get_regulator(char *regulator_name){ return NULL; }\r
 static inline int dvfs_clk_enable_limit(struct clk *clk, unsigned int min_rate, unsigned max_rate){ return 0; }\r
 static inline int dvfs_clk_disable_limit(struct clk *clk){ return 0; };\r
+int dvfs_scale_volt_direct(struct vd_node *vd_clk, int volt_new){};\r
 \r
 static inline void avs_init(void){};\r
 static inline void avs_init_val_get(int index, int vol, char *s){};\r
 static inline int avs_set_scal_val(u8 avs_base){ return 0; };\r
-static inline int dvfs_avs_scale_table(struct clk* clk, char* depend_vd_name){ return 0; };\r
+void avs_board_init(struct avs_ctr_st *data){};\r
 #endif\r
 \r
 #endif\r