From patchwork Thu Aug 25 13:47:05 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 3677 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 0965B23F22 for ; Thu, 25 Aug 2011 13:47:10 +0000 (UTC) Received: from mail-gx0-f180.google.com (mail-gx0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id CF56DA188C7 for ; Thu, 25 Aug 2011 13:47:09 +0000 (UTC) Received: by gxk10 with SMTP id 10so2494652gxk.11 for ; Thu, 25 Aug 2011 06:47:09 -0700 (PDT) Received: by 10.150.229.16 with SMTP id b16mr1030006ybh.155.1314280029274; Thu, 25 Aug 2011 06:47:09 -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 e20cs238190ybj; Thu, 25 Aug 2011 06:47:08 -0700 (PDT) Received: by 10.216.187.145 with SMTP id y17mr5703203wem.70.1314280027113; Thu, 25 Aug 2011 06:47:07 -0700 (PDT) Received: from mtagate2.uk.ibm.com (mtagate2.uk.ibm.com [194.196.100.162]) by mx.google.com with ESMTPS id k14si1599126wed.32.2011.08.25.06.47.06 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Aug 2011 06:47:07 -0700 (PDT) Received-SPF: neutral (google.com: 194.196.100.162 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=194.196.100.162; Authentication-Results: mx.google.com; spf=neutral (google.com: 194.196.100.162 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate2.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p7PDl6mB020758 for ; Thu, 25 Aug 2011 13:47:06 GMT Received: from d06av02.portsmouth.uk.ibm.com (d06av02.portsmouth.uk.ibm.com [9.149.37.228]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7PDl6VG2531334 for ; Thu, 25 Aug 2011 14:47:06 +0100 Received: from d06av02.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7PDl6hh024481 for ; Thu, 25 Aug 2011 07:47:06 -0600 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av02.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p7PDl5jO024468; Thu, 25 Aug 2011 07:47:06 -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 2674C21101F; Thu, 25 Aug 2011 15:47:04 +0200 (CEST) From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 5/7] dump the gpio informations Date: Thu, 25 Aug 2011 15:47:05 +0200 Message-Id: <1314280027-7547-5-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> Now we dump the output to the stdout. Signed-off-by: Daniel Lezcano --- gpio.c | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 42 insertions(+), 3 deletions(-) diff --git a/gpio.c b/gpio.c index 8e7499d..562a11d 100644 --- a/gpio.c +++ b/gpio.c @@ -39,6 +39,7 @@ struct gpio_info { int value; int direction; int edge; + char *prefix; } *gpios_info; static struct tree *gpio_tree = NULL; @@ -48,8 +49,10 @@ static struct gpio_info *gpio_alloc(void) struct gpio_info *gi; gi = malloc(sizeof(*gi)); - if (gi) - memset(gi, 0, sizeof(*gi)); + if (gi) { + memset(gi, -1, sizeof(*gi)); + gi->prefix = NULL; + } return gi; } @@ -148,11 +151,47 @@ static int fill_gpio_tree(void) return tree_for_each(gpio_tree, fill_gpio_cb, NULL); } -int gpio_dump(void) +static int dump_gpio_cb(struct tree *t, void *data) { + struct gpio_info *gpio = t->private; + struct gpio_info *pgpio; + + if (!t->parent) { + printf("/\n"); + gpio->prefix = ""; + return 0; + } + + pgpio = t->parent->private; + + if (!gpio->prefix) + if (asprintf(&gpio->prefix, "%s%s%s", pgpio->prefix, + 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); + return 0; } +int dump_gpio_info(void) +{ + return tree_for_each(gpio_tree, dump_gpio_cb, NULL); +} + +int gpio_dump(void) +{ + int ret; + + printf("\nGpio Tree :\n"); + printf("***********\n"); + ret = dump_gpio_info(); + printf("\n\n"); + + return ret; +} + /* * Initialize the gpio framework */