]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/commitdiff
arm: tegra: mc: Fix EMC BW computation code
authorAlex Waterman <alexw@nvidia.com>
Thu, 13 Nov 2014 19:23:04 +0000 (11:23 -0800)
committerJon Mayo <jmayo@nvidia.com>
Tue, 18 Nov 2014 18:28:57 +0000 (10:28 -0800)
This patch clarifies and generalizes the EMC BW and frequency
computation code. Firstly it changes the arguments to unsigned longs
so that more than 4GBps of BW can be passed in bytes/s. Secondly
it renames some of the function variables to be generic. These functions
will work for any {Hz, KHz, MHz} and {B, KB, MB} per second passed.

Bug 1576403

Change-Id: Ie9d25eacfeab0fa01293989c883507fe79b5a474
Signed-off-by: Alex Waterman <alexw@nvidia.com>
Reviewed-on: http://git-master/r/602986
Reviewed-by: Automatic_Commit_Validation_User
GVS: Gerrit_Virtual_Submit
Reviewed-by: Jon Mayo <jmayo@nvidia.com>
Tested-by: Jon Mayo <jmayo@nvidia.com>
drivers/platform/tegra/include/tegra/mc.h
drivers/platform/tegra/mc/mc.c

index d9d67b1a181563746163afb2a6d0ed4cb5cb9f55..eccfe2e3d4a78e1bce6136c2f4ba4c8a15c0e7f0 100644 (file)
@@ -132,8 +132,8 @@ static inline int tegra_mc_get_effective_bytes_width(void)
 #endif
 }
 
-unsigned int tegra_emc_bw_to_freq_req(unsigned int bw_kbps);
-unsigned int tegra_emc_freq_req_to_bw(unsigned int freq_kbps);
+unsigned long tegra_emc_bw_to_freq_req(unsigned long bw);
+unsigned long tegra_emc_freq_req_to_bw(unsigned long freq);
 #if defined(CONFIG_ARCH_TEGRA_12x_SOC)
 void         tegra12_mc_latency_allowance_save(u32 **pctx);
 void         tegra12_mc_latency_allowance_restore(u32 **pctx);
index e0343382836e3ff507f9c29b74bac6048a92ba17..0d7528e28ae453c8c75265e654a86e561fc29da3 100644 (file)
@@ -188,34 +188,43 @@ int tegra_mc_get_tiled_memory_bandwidth_multiplier(void)
                return 1;
 }
 
-/* API to get EMC freq to be requested, for Bandwidth.
- * bw_kbps: BandWidth passed is in KBps.
- * returns freq in KHz
+/*
+ * API to convert BW in bytes/s to clock frequency.
+ *
+ * bw: Bandwidth to convert. It can be in any unit - the resulting frequency
+ *     will be in the same unit as passed. E.g KBps leads to KHz.
  */
-unsigned int tegra_emc_bw_to_freq_req(unsigned int bw_kbps)
+unsigned long tegra_emc_bw_to_freq_req(unsigned long bw)
 {
-       unsigned int freq;
        unsigned int bytes_per_emc_clk;
 
        bytes_per_emc_clk = tegra_mc_get_effective_bytes_width() * 2;
-       freq = (bw_kbps + bytes_per_emc_clk - 1) / bytes_per_emc_clk *
-               CONFIG_TEGRA_EMC_TO_DDR_CLOCK;
-       return freq;
+
+       /*
+        * Round to the nearest Hz, KHz, etc. This is so that the value
+        * returned by this function will always be >= to the number of
+        * clock cycles required to satisfy the passed BW.
+        */
+       return (bw + bytes_per_emc_clk - 1) / bytes_per_emc_clk;
 }
 EXPORT_SYMBOL_GPL(tegra_emc_bw_to_freq_req);
 
-/* API to get EMC bandwidth, for freq that can be requested.
- * freq_khz: Frequency passed is in KHz.
- * returns bandwidth in KBps
+/*
+ * API to convert EMC clock frequency into theoretical available BW. This
+ * does not account for a realistic utilization of the EMC bus. That is the
+ * various overheads (refresh, bank commands, etc) that a real system sees
+ * are not computed.
+ *
+ * freq: Frequency to convert. Like tegra_emc_bw_to_freq_req() it will work
+ *       on any passed order of ten. The result will be on the same order.
  */
-unsigned int tegra_emc_freq_req_to_bw(unsigned int freq_khz)
+unsigned long tegra_emc_freq_req_to_bw(unsigned long freq)
 {
-       unsigned int bw;
        unsigned int bytes_per_emc_clk;
 
        bytes_per_emc_clk = tegra_mc_get_effective_bytes_width() * 2;
-       bw = freq_khz * bytes_per_emc_clk / CONFIG_TEGRA_EMC_TO_DDR_CLOCK;
-       return bw;
+
+       return freq * bytes_per_emc_clk;
 }
 EXPORT_SYMBOL_GPL(tegra_emc_freq_req_to_bw);