diff mbox

[POWERDEBUG,2/2] The clock rates that are reported are incorrect

Message ID 1377078565-22920-1-git-send-email-shaojie.sun@linaro.com
State New
Headers show

Commit Message

sunshaojie Aug. 21, 2013, 9:49 a.m. UTC
1. check clock rate is reported by hexadecimal or decimal.
2. clock rate is reported with interger instead of radix point,
for example 1.1GHz must be shown in 1100MHz.

Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
---
 clocks.c |   44 ++++++++++++++++++++++++++++++++++----------
 1 file changed, 34 insertions(+), 10 deletions(-)
diff mbox

Patch

diff --git a/clocks.c b/clocks.c
index 203411a..b069547 100644
--- a/clocks.c
+++ b/clocks.c
@@ -78,27 +78,51 @@  static struct clock_info *clock_alloc(void)
 	return ci;
 }
 
+static inline bool is_hex_clock(uint rate)
+{
+	return rate%10;
+}
+
 static inline const char *clock_rate(uint *rate)
 {
-	uint r;
+	uint r, mod;
+	bool is_hex = is_hex_clock(*rate);
 
         /* GHZ */
-        r = *rate >> 30;
-        if (r) {
-                *rate = r;
-                return "GHZ";
-        }
+	if (is_hex) {
+		r = *rate >> 30;
+		mod = *rate&((1<<30)-1);
+	} else {
+		r = *rate / 1000000000;
+		mod = *rate % 1000000000;
+	}
+	if (r && !mod) {
+		*rate = r;
+		return "GHZ";
+	}
 
         /* MHZ */
-        r = *rate >> 20;
-        if (r) {
+	if (is_hex) {
+		r = *rate >> 20;
+		mod = *rate&((1<<20)-1);
+	} else {
+		r = *rate / 1000000;
+		mod = *rate % 1000000;
+	}
+	if (r && !mod) {
                 *rate = r;
                 return "MHZ";
         }
 
         /* KHZ */
-        r = *rate >> 10;
-        if (r) {
+	if (is_hex) {
+		r = *rate >> 10;
+		mod = *rate&((1<<10)-1);
+	} else {
+		r = *rate / 1000;
+		mod = *rate % 1000;
+	}
+	if (r && !mod) {
                 *rate = r;
                 return "KHZ";
         }