From patchwork Mon Jul 29 12:11:46 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sunshaojie X-Patchwork-Id: 18629 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ye0-f199.google.com (mail-ye0-f199.google.com [209.85.213.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 34D242486F for ; Mon, 29 Jul 2013 12:13:05 +0000 (UTC) Received: by mail-ye0-f199.google.com with SMTP id l12sf4235246yen.2 for ; Mon, 29 Jul 2013 05:13:04 -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=jkKcY+wNOImVlhHULfhgxi6MqbmREcbc8XO8bGUnr7U=; b=AwUiN7k6XcdshNVttw6YT9FtGM4gYr7PqIUyd3QBq7QaNudyu8qStze6EwhAoDkwHF vixYyiqxjaYZFU13cQHTNSABNWb+3GO6rw1I4k/hB1J7ExCqZh3gWUD60SiO7yqY7xBW VoZURxGOpLEQloGaYjAOEcv2k0bybUb/LtDaUxIS1+KRtazdZhQ0ZpO7bk6LQcUVEldC oA4oth+og/8Ob0/YcQlgGB7QAESc3gTGyy6br08PACqBZj74+4xg4xKzmVr3pImrdrSO h+NmlAv5RRY0rpcdmpOYEPdTCi2rjWb2Nng/YFqVWA+QDczSwMZe7YBwx3OftlD5feFq tZ0g== X-Received: by 10.58.207.75 with SMTP id lu11mr6419887vec.20.1375099984432; Mon, 29 Jul 2013 05:13:04 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.132.99 with SMTP id ot3ls1948047qeb.40.gmail; Mon, 29 Jul 2013 05:13:04 -0700 (PDT) X-Received: by 10.58.235.69 with SMTP id uk5mr25347223vec.17.1375099984310; Mon, 29 Jul 2013 05:13:04 -0700 (PDT) Received: from mail-ve0-f181.google.com (mail-ve0-f181.google.com [209.85.128.181]) by mx.google.com with ESMTPS id dq2si11110353vdc.115.2013.07.29.05.13.04 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 05:13:04 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.181 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.181; Received: by mail-ve0-f181.google.com with SMTP id jz10so2786417veb.40 for ; Mon, 29 Jul 2013 05:13:04 -0700 (PDT) X-Received: by 10.52.180.229 with SMTP id dr5mr1280276vdc.20.1375099984208; Mon, 29 Jul 2013 05:13:04 -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.221.11.8 with SMTP id pc8csp113099vcb; Mon, 29 Jul 2013 05:13:03 -0700 (PDT) X-Received: by 10.68.1.9 with SMTP id 9mr66916671pbi.128.1375099983198; Mon, 29 Jul 2013 05:13:03 -0700 (PDT) Received: from mail-pb0-f49.google.com (mail-pb0-f49.google.com [209.85.160.49]) by mx.google.com with ESMTPS id xx4si13167233pab.110.2013.07.29.05.13.02 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 05:13:03 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.160.49 is neither permitted nor denied by best guess record for domain of shaojie.sun@linaro.org) client-ip=209.85.160.49; Received: by mail-pb0-f49.google.com with SMTP id xb4so326509pbc.22 for ; Mon, 29 Jul 2013 05:13:02 -0700 (PDT) X-Received: by 10.68.96.133 with SMTP id ds5mr26935694pbb.169.1375099982556; Mon, 29 Jul 2013 05:13:02 -0700 (PDT) Received: from localhost.localdomain ([58.251.159.202]) by mx.google.com with ESMTPSA id fl2sm20468295pab.23.2013.07.29.05.12.49 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 29 Jul 2013 05:13:01 -0700 (PDT) From: Shaojie Sun To: sanjay.rawat@linaro.org Cc: private-pmwg@linaro.org, patches@linaro.org, sunshaojie@huawei.com, Shaojie Sun Subject: [PATCH] POWERDEBUG: Add modify gpio function in powerdebug tool. Date: Mon, 29 Jul 2013 20:11:46 +0800 Message-Id: <1375099906-12144-1-git-send-email-shaojie.sun@linaro.com> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQk1iHZFckR7yc5eHHiTsp+ypUxlQNSwkJMLsdmLIrCtH0BH7/oaxthjX90Jm/0prOohHZp0 X-Original-Sender: shaojie.sun@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.181 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: Shaojie Sun --- README | 8 +++++++- display.c | 18 ++++++++++++++++++ display.h | 1 + gpio.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ utils.c | 36 ++++++++++++++++++++++++++++++++++++ utils.h | 2 ++ 6 files changed, 109 insertions(+), 1 deletion(-) diff --git a/README b/README index fa997f6..3bf1659 100644 --- a/README +++ b/README @@ -7,4 +7,10 @@ information. Current version only displays regulator information and clock tree from debugfs. Support will be added for sensors later. - -- Amit Arora Fri, 08 Sep 2010 + -- Amit Arora Fri, 08 Sep 2010 + +Now we add gpio-change function for power consumption need. +When gpio is not in interrupt mode. use 'D' key to change gpio direction. +And when gpio direction is "out", use 'V' key to change gpio value. + + -- Shaojie Sun Mon, 29 Jul 2013 diff --git a/display.c b/display.c index 41a511d..c0afe03 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,13 @@ static int display_keystroke(int fd, void *data) display_select(); break; + case 'v': + case 'V': + 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 3ecc393..84f150f 100644 --- a/gpio.c +++ b/gpio.c @@ -264,8 +264,53 @@ 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': + /* Only change direction when gpio interrupt not set.*/ + if (!strstr(gpio->edge, "none")) + return 0; + + if (strstr(gpio->direction, "in")) + strcpy(gpio->direction, "out"); + else if (strstr(gpio->direction, "out")) + strcpy(gpio->direction, "in"); + file_write_value(t->path, "direction", "%s", &gpio->direction); + file_read_value(t->path, "direction", "%s", &gpio->direction); + + break; + + case 'V': + /* Only change value when gpio direction is out. */ + if (!strstr(gpio->edge, "none") + || !strstr(gpio->direction, "out")) + return 0; + + if (gpio->value) + file_write_value(t->path, "direction", "%s", &"low"); + else + file_write_value(t->path, "direction", "%s", &"high"); + file_read_value(t->path, "value", "%d", &gpio->value); + + 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..4d4b780 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, "w"); + 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