Optimize the code

With this patch the content of the debugfs file is readen only when the
'refresh' button is hit and at the init of powerdebug.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/clocks.c b/clocks.c
index 6943b70..0bd0a0e 100644
--- a/clocks.c
+++ b/clocks.c
@@ -262,6 +262,10 @@
 
 static int clock_print_info_cb(struct tree *t, void *data)
 {
+        /* we skip the root node of the tree */
+	if (!t->parent)
+		return 0;
+
         /* show the clock when *all* its parent is expanded */
 	if (tree_for_each_parent(t->parent, is_collapsed, NULL))
 		return 0;
@@ -315,9 +319,9 @@
  * found in the files. Then print the result to the text based interface
  * Return 0 on success, < 0 otherwise
  */
-static int clock_display(void)
+static int clock_display(bool refresh)
 {
-	if (read_clock_info(clock_tree))
+	if (refresh && read_clock_info(clock_tree))
 		return -1;
 
 	return clock_print_info(clock_tree);
@@ -334,13 +338,10 @@
 
 	for (i = 0; i < nr; i++) {
 
-		ret = read_clock_info(ptree[i]);
-		if (ret)
-			break;
-
 		ret = _clock_print_info_cb(ptree[i], &line);
 		if (ret)
 			break;
+
 	}
 
 	display_refresh_pad(CLOCK);
diff --git a/display.c b/display.c
index 38596b0..23a4172 100644
--- a/display.c
+++ b/display.c
@@ -111,14 +111,14 @@
 	return 0;
 }
 
-int display_refresh(int win)
+static int display_refresh(int win, bool read)
 {
 	/* we are trying to refresh a window which is not showed */
 	if (win != current_win)
 		return 0;
 
 	if (windata[win].ops && windata[win].ops->display)
-		return windata[win].ops->display();
+		return windata[win].ops->display(read);
 
 	return 0;
 }
@@ -391,13 +391,12 @@
 
 	case 'r':
 	case 'R':
-		/* refresh will be done after */
-		break;
+		return display_refresh(current_win, true);
 	default:
 		return 0;
 	}
 
-	display_refresh(current_win);
+	display_refresh(current_win, false);
 
 	return 0;
 }
@@ -416,7 +415,7 @@
 	if (display_show_footer(current_win, NULL))
 		return -1;
 
-	return display_refresh(current_win);
+	return display_refresh(current_win, false);
 }
 
 static int display_find_keystroke(int fd, void *data)
@@ -547,7 +546,7 @@
 	if (display_show_footer(wdefault, NULL))
 		return -1;
 
-	return display_refresh(wdefault);
+	return display_refresh(wdefault, true);
 }
 
 int display_column_name(const char *line)
diff --git a/display.h b/display.h
index 7fa5361..9e4e21a 100644
--- a/display.h
+++ b/display.h
@@ -16,7 +16,7 @@
 enum { CLOCK, REGULATOR, SENSOR };
 
 struct display_ops {
-	int (*display)(void);
+	int (*display)(bool refresh);
 	int (*select)(void);
 	int (*find)(const char *);
 	int (*selectf)(void);
@@ -31,5 +31,4 @@
 
 extern int display_init(int wdefault);
 extern int display_register(int win, struct display_ops *ops);
-extern int display_refresh(int win);
 extern int display_column_name(const char *line);
diff --git a/regulator.c b/regulator.c
index 97ab15b..849f906 100644
--- a/regulator.c
+++ b/regulator.c
@@ -156,7 +156,7 @@
 
 }
 
-static int regulator_display(void)
+static int regulator_display(bool refresh)
 {
 	int ret, line = 0;
 
diff --git a/sensor.c b/sensor.c
index 2a8f4bb..d63510e 100644
--- a/sensor.c
+++ b/sensor.c
@@ -250,7 +250,7 @@
 	return ret;
 }
 
-static int sensor_display(void)
+static int sensor_display(bool refresh)
 {
 	int ret, line = 0;