ddrfreq: add vop bandwidth freq table in dts, in order to support more boards
authorXiao Feng <xf@rock-chips.com>
Thu, 14 May 2015 07:45:31 +0000 (15:45 +0800)
committerXiao Feng <xf@rock-chips.com>
Wed, 20 May 2015 06:33:20 +0000 (14:33 +0800)
Signed-off-by: Xiao Feng <xf@rock-chips.com>
arch/arm/boot/dts/rk3288-p977.dts
arch/arm/boot/dts/rk3288-p977_8846.dts
arch/arm/boot/dts/rk3288-tb.dts
arch/arm/boot/dts/rk3288-tb_8846.dts
arch/arm/boot/dts/rk3288.dtsi
arch/arm/mach-rockchip/ddr_freq.c

index 3332f90de4a1cf156ba008564657940411d53ea5..a6072b0ad3bd37d8d3fa1d5ff38efba6d58e29f6 100755 (executable)
                SYS_STATUS_BOOST        324000
                SYS_STATUS_ISP          533000
                >;
+       bd-freq-table = <
+               /* bandwidth   freq */
+               5000           800000
+               3500           456000
+               2600           396000
+               2000           324000
+       >;
        auto-freq-table = <
                240000
                324000
index a7b2e452e93dce8bae80128f18b929c24fcaf47c..b092288ea96dd43fd028b813537e5380f1db7033 100755 (executable)
                SYS_STATUS_BOOST        324000
                SYS_STATUS_ISP          533000
                >;
+       bd-freq-table = <
+               /* bandwidth   freq */
+               5000           800000
+               3500           456000
+               2600           396000
+               2000           324000
+       >;
        auto-freq-table = <
                240000
                324000
index 9858154d3e1710ef9e77becb15a1d498d18224bf..74e89529c61de6c828acf77e0248972ac015ffd7 100755 (executable)
                SYS_STATUS_BOOST        324000
                SYS_STATUS_ISP          533000
                >;
+       bd-freq-table = <
+               /* bandwidth   freq */
+               5000           800000
+               3500           456000
+               2600           396000
+               2000           324000
+       >;
        auto-freq-table = <
                240000
                324000
index caeaaefff8b34cb0d5a5def0f173367c560aecf4..e32edd8dc1368d6636ee1d35d9cc4bcf7d502eb4 100755 (executable)
                SYS_STATUS_BOOST        324000
                SYS_STATUS_ISP          400000
                >;
+       bd-freq-table = <
+               /* bandwidth   freq */
+               5000           800000
+               3500           456000
+               2600           396000
+               2000           324000
+       >;
        auto-freq-table = <
                240000
                324000
index 55bd723853aac919a2334fbee22c328c25722651..990e7993c6985ca8022488c07aadeff0431549c9 100644 (file)
                                                300000 1200000
                                                400000 1200000
                                                >;
+                                       bd-freq-table = <
+                                               /* bandwidth   freq */
+                                               5000           800000
+                                               3500           456000
+                                               2600           396000
+                                               2000           324000
+                                               >;
                                        channel = <2>;
                                        status = "disabled";
                                };
index af94e8808d070f8c39f1cfae57e45d7c1f8c17e0..26a1c161921179b2e50905d008a30a9427e4e3c2 100644 (file)
@@ -54,6 +54,7 @@ static int auto_freq_table_size;
 static unsigned long vop_bandwidth_update_jiffies = 0, vop_bandwidth = 0;
 static int vop_bandwidth_update_flag = 0;
 static struct ddr_bw_info ddr_bw_ch0 = {0}, ddr_bw_ch1 = {0};
+static struct cpufreq_frequency_table *bd_freq_table;
 
 enum {
        DEBUG_DDR = 1U << 0,
@@ -204,23 +205,17 @@ static void ddrfreq_mode(bool auto_self_refresh, unsigned long target_rate, char
 
 unsigned long req_freq_by_vop(unsigned long bandwidth)
 {
+       unsigned int i = 0;
+
        if (time_after(jiffies, vop_bandwidth_update_jiffies +
                msecs_to_jiffies(down_rate_delay_ms)))
                return 0;
 
-       if (bandwidth >= 5000){
-               return 800000000;
-       }
-
-       if (bandwidth >= 3500) {
-               return 456000000;
-       }
-
-       if (bandwidth >= 2600) {
-               return 396000000;
-       }
-       if (bandwidth >= 2000) {
-               return 324000000;
+       if (bd_freq_table == NULL)
+               return 0;
+       for (i = 0; bd_freq_table[i].frequency != CPUFREQ_TABLE_END; i++) {
+               if (bandwidth >= bd_freq_table[i].index)
+                       return bd_freq_table[i].frequency * 1000;
        }
 
        return 0;
@@ -831,6 +826,40 @@ static struct notifier_block ddrfreq_system_status_notifier = {
                .notifier_call = ddrfreq_system_status_notifier_call,
 };
 
+static struct cpufreq_frequency_table
+       *of_get_bd_freq_table(struct device_node *np, const char *propname)
+{
+       struct cpufreq_frequency_table *freq_table = NULL;
+       const struct property *prop;
+       const __be32 *val;
+       int nr, i;
+
+       prop = of_find_property(np, propname, NULL);
+       if (!prop)
+               return NULL;
+       if (!prop->value)
+               return NULL;
+
+       nr = prop->length / sizeof(u32);
+       if (nr % 2) {
+               pr_err("%s: Invalid freq list\n", __func__);
+               return NULL;
+       }
+
+       freq_table = kzalloc(sizeof(*freq_table) * (nr/2 + 1), GFP_KERNEL);
+
+       val = prop->value;
+
+       for (i = 0; i < nr/2; i++) {
+               freq_table[i].index = be32_to_cpup(val++);
+               freq_table[i].frequency = be32_to_cpup(val++);
+       }
+
+       freq_table[i].index = 0;
+       freq_table[i].frequency = CPUFREQ_TABLE_END;
+
+       return freq_table;
+}
 
 int of_init_ddr_freq_table(void)
 {
@@ -907,6 +936,8 @@ int of_init_ddr_freq_table(void)
                nr -= 2;
        }
 
+       bd_freq_table = of_get_bd_freq_table(clk_ddr_dev_node, "bd-freq-table");
+
        return 0;
 }