From patchwork Wed Jun 15 13:50:47 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1935 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id BF75324B35 for ; Wed, 15 Jun 2011 13:52:44 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 8ED40A186F5 for ; Wed, 15 Jun 2011 13:52:44 +0000 (UTC) Received: by mail-vw0-f52.google.com with SMTP id 16so416327vws.11 for ; Wed, 15 Jun 2011 06:52:44 -0700 (PDT) Received: by 10.52.175.197 with SMTP id cc5mr778578vdc.287.1308145964339; Wed, 15 Jun 2011 06:52:44 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs126641vdc; Wed, 15 Jun 2011 06:52:44 -0700 (PDT) Received: by 10.216.237.217 with SMTP id y67mr2178554weq.1.1308145962735; Wed, 15 Jun 2011 06:52:42 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id p14si1396337wbh.6.2011.06.15.06.52.42; Wed, 15 Jun 2011 06:52:42 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d28 with ME id wDsa1g00D1hMfSL03DshD9; Wed, 15 Jun 2011 15:52:42 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 13/22] Encapsulate the display (6) Date: Wed, 15 Jun 2011 15:50:47 +0200 Message-Id: <1308145856-6112-13-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> References: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> Let's create some ops to be registered by the pm blocks to the display. Signed-off-by: Daniel Lezcano --- clocks.c | 53 +++++++++++++++++++++++++++++++---------------------- display.c | 11 +++++++++++ display.h | 7 ++++++- regulator.c | 8 ++++++++ sensor.c | 8 ++++++++ 5 files changed, 64 insertions(+), 23 deletions(-) diff --git a/clocks.c b/clocks.c index db219d8..86ae948 100644 --- a/clocks.c +++ b/clocks.c @@ -26,6 +26,7 @@ #include #include "powerdebug.h" +#include "display.h" #include "clocks.h" #include "tree.h" #include "utils.h" @@ -306,28 +307,6 @@ int clock_toggle_expanded(void) } /* - * Initialize the clock framework - */ -int clock_init(void) -{ - char clk_dir_path[PATH_MAX]; - - if (locate_debugfs(clk_dir_path)) - return -1; - - sprintf(clk_dir_path, "%s/clock", clk_dir_path); - - if (access(clk_dir_path, F_OK)) - return -1; - - clock_tree = tree_load(clk_dir_path, NULL); - if (!clock_tree) - return -1; - - return fill_clock_tree(); -} - -/* * Read the clock information and fill the tree with the information * found in the files. Then print the result to the text based interface * Return 0 on success, < 0 otherwise @@ -366,3 +345,33 @@ int clock_dump(char *clk) return ret; } + +static struct display_ops clock_ops = { + .display = clock_display, + .select = clock_toggle_expanded, +}; + +/* + * Initialize the clock framework + */ +int clock_init(void) +{ + char clk_dir_path[PATH_MAX]; + + if (display_register(CLOCK, &clock_ops)) + return -1; + + if (locate_debugfs(clk_dir_path)) + return -1; + + sprintf(clk_dir_path, "%s/clock", clk_dir_path); + + if (access(clk_dir_path, F_OK)) + return -1; + + clock_tree = tree_load(clk_dir_path, NULL); + if (!clock_tree) + return -1; + + return fill_clock_tree(); +} diff --git a/display.c b/display.c index 384714b..d55d748 100644 --- a/display.c +++ b/display.c @@ -49,6 +49,7 @@ struct rowdata { struct windata { WINDOW *win; WINDOW *pad; + struct display_ops *ops; struct rowdata *rowdata; char *name; int nrdata; @@ -207,6 +208,16 @@ void print_sensor_header(void) show_header_footer(SENSOR); } +int display_register(int win, struct display_ops *ops) +{ + if (win < 0 || win >= TOTAL_FEATURE_WINS) + return -1; + + windata[win].ops = ops; + + return 0; +} + int display_next_panel(void) { current_win++; diff --git a/display.h b/display.h index 9c0e38a..1222b44 100644 --- a/display.h +++ b/display.h @@ -13,8 +13,13 @@ * - initial API and implementation *******************************************************************************/ -extern int display_init(int wdefault); +struct display_ops { + int (*display)(void); + int (*select)(void); +}; +extern int display_init(int wdefault); +extern int display_register(int win, struct display_ops *ops); extern int display_next_panel(void); extern int display_prev_panel(void); extern int display_next_line(void); diff --git a/regulator.c b/regulator.c index d4b41e1..4b9d36e 100644 --- a/regulator.c +++ b/regulator.c @@ -26,6 +26,7 @@ #include #include #include +#include "display.h" #include "powerdebug.h" #include "tree.h" #include "utils.h" @@ -209,8 +210,15 @@ static int fill_regulator_tree(void) return tree_for_each(reg_tree, fill_regulator_cb, NULL); } +static struct display_ops regulator_ops = { + .display = regulator_display, +}; + int regulator_init(void) { + if (display_register(REGULATOR, ®ulator_ops)) + return -1; + reg_tree = tree_load(SYSFS_REGULATOR, regulator_filter_cb); if (!reg_tree) return -1; diff --git a/sensor.c b/sensor.c index 9c97e72..db58137 100644 --- a/sensor.c +++ b/sensor.c @@ -23,6 +23,7 @@ #include #include "powerdebug.h" +#include "display.h" #include "sensor.h" #include "tree.h" #include "utils.h" @@ -249,8 +250,15 @@ int sensor_display(void) return ret; } +static struct display_ops sensor_ops = { + .display = sensor_display, +}; + int sensor_init(void) { + if (display_register(SENSOR, &sensor_ops)) + return -1; + sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb); if (!sensor_tree) return -1;