From patchwork Thu Aug 25 13:47:04 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 3676 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 15B8723FA2 for ; Thu, 25 Aug 2011 13:47:09 +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 DBEB7A18903 for ; Thu, 25 Aug 2011 13:47:08 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id 11so2482455yxi.11 for ; Thu, 25 Aug 2011 06:47:08 -0700 (PDT) Received: by 10.150.166.7 with SMTP id o7mr959383ybe.98.1314280028619; Thu, 25 Aug 2011 06:47:08 -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 e20cs238189ybj; Thu, 25 Aug 2011 06:47:08 -0700 (PDT) Received: by 10.227.57.68 with SMTP id b4mr1501652wbh.82.1314280026186; Thu, 25 Aug 2011 06:47:06 -0700 (PDT) Received: from mtagate3.uk.ibm.com (mtagate3.uk.ibm.com [194.196.100.163]) by mx.google.com with ESMTPS id fn13si1583050wbb.80.2011.08.25.06.47.05 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 25 Aug 2011 06:47:06 -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 d06nrmr1307.portsmouth.uk.ibm.com (d06nrmr1307.portsmouth.uk.ibm.com [9.149.38.129]) by mtagate3.uk.ibm.com (8.13.1/8.13.1) with ESMTP id p7PDl5WL002728 for ; Thu, 25 Aug 2011 13:47:05 GMT Received: from d06av08.portsmouth.uk.ibm.com (d06av08.portsmouth.uk.ibm.com [9.149.37.249]) by d06nrmr1307.portsmouth.uk.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id p7PDl58d2531582 for ; Thu, 25 Aug 2011 14:47:05 +0100 Received: from d06av08.portsmouth.uk.ibm.com (loopback [127.0.0.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id p7PDl514012456 for ; Thu, 25 Aug 2011 14:47:05 +0100 Received: from smtp.lab.toulouse-stg.fr.ibm.com (srv01.lab.toulouse-stg.fr.ibm.com [9.101.4.1]) by d06av08.portsmouth.uk.ibm.com (8.14.4/8.13.1/NCO v10.0 AVin) with ESMTP id p7PDl48U012444; Thu, 25 Aug 2011 14:47:04 +0100 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 CFA7A21101F; Thu, 25 Aug 2011 15:47:03 +0200 (CEST) From: Daniel Lezcano To: linaro-dev@lists.linaro.org Subject: [powerdebug 4/7] read the content of the files Date: Thu, 25 Aug 2011 15:47:04 +0200 Message-Id: <1314280027-7547-4-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 have the directory structure, we can address the different files and read their content in order to store them in the tree nodes. Signed-off-by: Daniel Lezcano --- gpio.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 70 insertions(+), 4 deletions(-) diff --git a/gpio.c b/gpio.c index fc60d00..8e7499d 100644 --- a/gpio.c +++ b/gpio.c @@ -33,8 +33,27 @@ #define SYSFS_GPIO "/sys/class/gpio" +struct gpio_info { + bool expanded; + int active_low; + int value; + int direction; + int edge; +} *gpios_info; + static struct tree *gpio_tree = NULL; +static struct gpio_info *gpio_alloc(void) +{ + struct gpio_info *gi; + + gi = malloc(sizeof(*gi)); + if (gi) + memset(gi, 0, sizeof(*gi)); + + return gi; +} + static int gpio_display(bool refresh) { return 0; @@ -62,24 +81,71 @@ static struct display_ops gpio_ops = { .selectf = gpio_selectf, }; +static int gpio_filter_cb(const char *name) +{ + /* let's ignore some directories in order to avoid to be + * pulled inside the sysfs circular symlinks mess/hell + * (choose the word which fit better) + */ + if (!strcmp(name, "device")) + return 1; + + if (!strcmp(name, "subsystem")) + return 1; + + if (!strcmp(name, "driver")) + return 1; + + /* we want to ignore the gpio chips */ + if (strstr(name, "chip")) + return 1; + + /* we are not interested by the power value */ + if (!strcmp(name, "power")) + return 1; + + return 0; +} + static inline int read_gpio_cb(struct tree *t, void *data) { + struct gpio_info *gpio = t->private; + + file_read_value(t->path, "active_low", "%d", &gpio->active_low); + file_read_value(t->path, "value", "%d", &gpio->value); + file_read_value(t->path, "edge", "%d", &gpio->edge); + file_read_value(t->path, "direction", "%d", &gpio->direction); + return 0; } static int read_gpio_info(struct tree *tree) { - return 0; + return tree_for_each(tree, read_gpio_cb, NULL); } static int fill_gpio_cb(struct tree *t, void *data) { - return 0; + struct gpio_info *gpio; + + gpio = gpio_alloc(); + if (!gpio) + return -1; + t->private = gpio; + + /* we skip the root node but we set it expanded for its children */ + if (!t->parent) { + gpio->expanded = true; + return 0; + } + + return read_gpio_cb(t, data); + } static int fill_gpio_tree(void) { - return 0; + return tree_for_each(gpio_tree, fill_gpio_cb, NULL); } int gpio_dump(void) @@ -92,7 +158,7 @@ int gpio_dump(void) */ int gpio_init(void) { - gpio_tree = tree_load(SYSFS_GPIO, NULL, false); + gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false); if (!gpio_tree) return -1;