From patchwork Thu Aug 25 13:47:07 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 3678 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 6F51F23F22 for ; Thu, 25 Aug 2011 13:47:14 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 30827A188C7 for ; Thu, 25 Aug 2011 13:47:14 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id 11so2482455yxi.11 for ; Thu, 25 Aug 2011 06:47:14 -0700 (PDT) Received: by 10.150.236.12 with SMTP id j12mr932944ybh.212.1314280033944; Thu, 25 Aug 2011 06:47:13 -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.151.27.20 with SMTP id e20cs238191ybj; Thu, 25 Aug 2011 06:47:10 -0700 (PDT) Received: by 10.227.3.2 with SMTP id 2mr1582718wbl.4.1314280029602; Thu, 25 Aug 2011 06:47:09 -0700 (PDT) Received: from mtagate3.uk.ibm.com (mtagate3.uk.ibm.com [194.196.100.163]) by mx.google.com with ESMTPS id fz18si1608625wbb.0.2011.08.25.06.47.09 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Aug 2011 06:47:09 -0700 (PDT) Received-SPF: neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=194.196.100.163; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.163 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from d06nrmr1707.portsmouth.uk.ibm.com (d06nrmr1707.portsmouth.uk.ibm.com [9.149.39.225]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p7PDl8b7002779 for ; Thu, 25 Aug 2011 13:47:08 GMT Received: from d06av06.portsmouth.uk.ibm.com (d06av06.portsmouth.uk.ibm.com [9.149.37.217]) by d06nrmr1707.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7PDl8uU2420898 for ; Thu, 25 Aug 2011 14:47:08 +0100 Received: from d06av06.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7PDl8LE003352 for ; Thu, 25 Aug 2011 07:47:08 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av06.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p7PDl8f7003335; Thu, 25 Aug 2011 07:47:08 -0600 Received: from localhost.localdomain (sig-9-145-110-19.uk.ibm.com [9.145.110.19]) by smtp.lab.toulouse-stg.fr.ibm.com (Postfix) with ESMTP id A8A9221101F; Thu, 25 Aug 2011 15:47:07 +0200 (CEST) From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 7/7] display the gpio info Date: Thu, 25 Aug 2011 15:47:07 +0200 Message-Id: <1314280027-7547-7-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1314280027-7547-1-git-send-email-daniel.lezcano@linaro.org> References: <1314280027-7547-1-git-send-email-daniel.lezcano@linaro.org> Show in ncurses mode the gpio informations. Signed-off-by: Daniel Lezcano --- gpio.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 101 insertions(+), 29 deletions(-) diff --git a/gpio.c b/gpio.c index 562a11d..f7d2a10 100644 --- a/gpio.c +++ b/gpio.c @@ -57,33 +57,6 @@ static struct gpio_info *gpio_alloc(void) return gi; } -static int gpio_display(bool refresh) -{ - return 0; -} - -static int gpio_select(void) -{ - return 0; -} - -static int gpio_find(const char *name) -{ - return 0; -} - -static int gpio_selectf(void) -{ - return 0; -} - -static struct display_ops gpio_ops = { - .display = gpio_display, - .select = gpio_select, - .find = gpio_find, - .selectf = gpio_selectf, -}; - static int gpio_filter_cb(const char *name) { /* let's ignore some directories in order to avoid to be @@ -169,8 +142,21 @@ static int dump_gpio_cb(struct tree *t, void *data) t->depth > 1 ? " ": "", t->next ? "|" : " ") < 0) return -1; - printf("%s%s-- %s (active_low:%d)\n", - gpio->prefix, !t->next ? "`" : "", t->name, gpio->active_low); + printf("%s%s-- %s (", gpio->prefix, !t->next ? "`" : "", t->name); + + if (gpio->active_low != -1) + printf(" active_low:%d", gpio->active_low); + + if (gpio->value != -1) + printf(", value:%d", gpio->value); + + if (gpio->edge != -1) + printf(", edge:%d", gpio->edge); + + if (gpio->direction != -1) + printf(", direction:%d", gpio->direction); + + printf(" )\n"); return 0; } @@ -192,6 +178,92 @@ int gpio_dump(void) return ret; } +static char *gpio_line(struct tree *t) +{ + struct gpio_info *gpio = t->private; + char *gpioline; + + if (asprintf(&gpioline, "%-20s %-10d %-10d %-10d %-10d", t-> name, + gpio->value, gpio->active_low, gpio->edge, gpio->direction) < 0) + return NULL; + + return gpioline; +} + +static int _gpio_print_info_cb(struct tree *t, void *data) +{ + int *line = data; + char *buffer; + + /* we skip the root node of the tree */ + if (!t->parent) + return 0; + + buffer = gpio_line(t); + if (!buffer) + return -1; + + display_print_line(GPIO, *line, buffer, 0, t); + + (*line)++; + + free(buffer); + + return 0; +} + +static int gpio_print_info_cb(struct tree *t, void *data) +{ + /* we skip the root node of the tree */ + if (!t->parent) + return 0; + + return _gpio_print_info_cb(t, data); +} + +static int gpio_print_header(void) +{ + char *buf; + int ret; + + if (asprintf(&buf, "%-20s %-10s %-10s %-10s %-10s", + "Name", "Value", "Active_low", "Edge", "Direction") < 0) + return -1; + + ret = display_column_name(buf); + + free(buf); + + return ret; +} + +static int gpio_print_info(struct tree *tree) +{ + int ret, line = 0; + + display_reset_cursor(GPIO); + + gpio_print_header(); + + ret = tree_for_each(tree, gpio_print_info_cb, &line); + + display_refresh_pad(GPIO); + + return ret; +} + +static int gpio_display(bool refresh) +{ + if (refresh && read_gpio_info(gpio_tree)) + return -1; + + return gpio_print_info(gpio_tree); +} + +static struct display_ops gpio_ops = { + .display = gpio_display, +}; + /* * Initialize the gpio framework */