From patchwork Wed Jul 17 08:25:14 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sunshaojie X-Patchwork-Id: 18398 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-gg0-f197.google.com (mail-gg0-f197.google.com [209.85.161.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2D6D225B8B for ; Wed, 17 Jul 2013 08:25:27 +0000 (UTC) Received: by mail-gg0-f197.google.com with SMTP id x14sf2068678ggx.0 for ; Wed, 17 Jul 2013 01:25:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=/7wl2oeJIt6jeNDbfaRMPou52MlgiQstWJYzM8fvSfw=; b=HmpAO9cWOlMH5iwGmSWYxob38JBSHRFP5gtfb7ItLxfVDvFntZPNAY5g84NVNDFjSH kWjXjPKXc0sZngjux/5OnB7+l58PXyOmcyVT+ZVGS/xEidnHGoqldmXqAb2ak0RMsed4 IIbe87pWJX5Px6HJHQN5v2Na2PPfOpMP9MGCYGbaO9hQLgpZp0V4xlrfpe6CUT2HoRJA KXYbci1jhsCkh0x4iJxCB/ULvkx0E9YZ+kyhJ4Yy+PavLXOWg9d11Aa2IwR2bT6JZzLJ rhRtHPH/9npXiwCY5Wr6XsU+2R14c1W7aBXggD31blFaJp42rFBGILLqL1NJOeo8t8to EUZg== X-Received: by 10.236.54.8 with SMTP id h8mr3268580yhc.11.1374049526938; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.12.111 with SMTP id x15ls875129qeb.58.gmail; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) X-Received: by 10.52.18.239 with SMTP id z15mr1407509vdd.109.1374049526836; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) Received: from mail-vc0-f170.google.com (mail-vc0-f170.google.com [209.85.220.170]) by mx.google.com with ESMTPS id l5si578687vca.14.2013.07.17.01.25.26 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Jul 2013 01:25:26 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.170; Received: by mail-vc0-f170.google.com with SMTP id hf12so1158215vcb.1 for ; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) X-Received: by 10.52.178.227 with SMTP id db3mr1459433vdc.20.1374049526750; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.149.77 with SMTP id s13csp160841vcv; Wed, 17 Jul 2013 01:25:26 -0700 (PDT) X-Received: by 10.68.219.194 with SMTP id pq2mr5639497pbc.151.1374049525751; Wed, 17 Jul 2013 01:25:25 -0700 (PDT) Received: from mail-pd0-f182.google.com (mail-pd0-f182.google.com [209.85.192.182]) by mx.google.com with ESMTPS id sr9si4276181pab.9.2013.07.17.01.25.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Jul 2013 01:25:25 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.192.182 is neither permitted nor denied by best guess record for domain of shaojie.sun@linaro.org) client-ip=209.85.192.182; Received: by mail-pd0-f182.google.com with SMTP id r10so1593257pdi.41 for ; Wed, 17 Jul 2013 01:25:25 -0700 (PDT) X-Received: by 10.68.213.135 with SMTP id ns7mr5763915pbc.5.1374049525161; Wed, 17 Jul 2013 01:25:25 -0700 (PDT) Received: from localhost.localdomain ([58.251.159.202]) by mx.google.com with ESMTPSA id tr10sm6516030pbc.22.2013.07.17.01.25.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 17 Jul 2013 01:25:24 -0700 (PDT) From: sunshaojie To: sanjay.rawat@linaro.org Cc: patches@linaro.org, private-pmwg@linaro.org, sunshaojie Subject: [PATCH 3/3] POWERDEBUG: Add modify gpio function in powerdebug tool. Date: Wed, 17 Jul 2013 16:25:14 +0800 Message-Id: <1374049514-4039-1-git-send-email-shaojie.sun@linaro.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQnjVcM5lMb7tGkAXzieor7jdVl2PWFS1vK1kykLxOPuZWTpnXollZDeO+/MQkvfu9dmFGLs X-Original-Sender: shaojie.sun@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.220.170 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , For power consumption test, we can change gpio direction and value and check that power consumption is falled or not. use 'D' key to change gpio direction. And when gpio direction is "out", use 'V' key to change gpio value. Signed-off-by: sunshaojie --- display.c | 22 ++++++++++++++++++++++ display.h | 1 + gpio.c | 43 +++++++++++++++++++++++++++++++++++++++++++ utils.c | 36 ++++++++++++++++++++++++++++++++++++ utils.h | 2 ++ 5 files changed, 104 insertions(+) diff --git a/display.c b/display.c index 41a511d..748cc1b 100644 --- a/display.c +++ b/display.c @@ -164,6 +164,17 @@ static int display_select(void) return 0; } +static int display_change(int keyvalue) +{ + if (!(windata[current_win].nrdata)) + return 0; + + if (windata[current_win].ops && windata[current_win].ops->change) + return windata[current_win].ops->change(keyvalue); + + return 0; +} + static int display_next_panel(void) { size_t array_size = sizeof(windata) / sizeof(windata[0]); @@ -406,6 +417,17 @@ static int display_keystroke(int fd, void *data) display_select(); break; + case 'v': + case 'V': + case 'a': + case 'A': + case 'e': + case 'E': + case 'd': + case 'D': + display_change(toupper(keystroke)); + break; + case EOF: case 'q': case 'Q': diff --git a/display.h b/display.h index 6362a48..b28d26e 100644 --- a/display.h +++ b/display.h @@ -20,6 +20,7 @@ struct display_ops { int (*select)(void); int (*find)(const char *); int (*selectf)(void); + int (*change)(int keyvalue); }; extern int display_print_line(int window, int line, char *str, diff --git a/gpio.c b/gpio.c index 9501e42..248ee2a 100644 --- a/gpio.c +++ b/gpio.c @@ -262,8 +262,51 @@ static int gpio_display(bool refresh) return gpio_print_info(gpio_tree); } +static int gpio_change(int keyvalue) +{ + struct tree *t = display_get_row_data(GPIO); + struct gpio_info *gpio = t->private; + + if (!t || !gpio) + return -1; + + switch (keyvalue) { + case 'D': + if (strstr(gpio->direction, "in")) + sprintf(gpio->direction, "out"); + else if (strstr(gpio->direction, "out")) + sprintf(gpio->direction, "in"); + file_write_value(t->path, "direction", "%s", &gpio->direction); + break; + + case 'V': + if (strstr(gpio->direction, "out")) { + gpio->value = !gpio->value; + file_write_value(t->path, "value", "%d", &gpio->value); + } + break; + +/* It is not good choise to change gpio irq status from userspace. */ +/* + case 'A': + gpio->active_low = !gpio->active_low; + file_write_value(t->path, "active_low", "%d", &gpio->active_low); + break; + + case 'E': + file_write_value(t->path, "edge", "%s", &gpio->edge); + break; +*/ + default: + return -1; + } + + return 0; +} + static struct display_ops gpio_ops = { .display = gpio_display, + .change = gpio_change, }; /* diff --git a/utils.c b/utils.c index e47c58e..5423c49 100644 --- a/utils.c +++ b/utils.c @@ -53,3 +53,39 @@ out_free: free(rpath); return ret; } + +/* + * This functions is a helper to write a specific file content and store + * the content inside a variable pointer passed as parameter, the format + * parameter gives the variable type to be write to the file. + * + * @path : directory path containing the file + * @name : name of the file to be read + * @format : the format of the format + * @value : a pointer to a variable to store the content of the file + * Returns 0 on success, -1 otherwise + */ +int file_write_value(const char *path, const char *name, + const char *format, void *value) +{ + FILE *file; + char *rpath; + int ret; + + ret = asprintf(&rpath, "%s/%s", path, name); + if (ret < 0) + return ret; + + file = fopen(rpath, "wr"); + if (!file) { + ret = -1; + goto out_free; + } + + ret = fprintf(file, format, value) < 0 ? -1 : 0; + + fclose(file); +out_free: + free(rpath); + return ret; +} diff --git a/utils.h b/utils.h index d4ac65a..73159b9 100644 --- a/utils.h +++ b/utils.h @@ -17,6 +17,8 @@ extern int file_read_value(const char *path, const char *name, const char *format, void *value); +extern int file_write_value(const char *path, const char *name, + const char *format, void *value); #endif