From: bamvor.zhangjian@linaro.org
To: linux-gpio@vger.kernel.org
Cc: linus.walleij@linaro.org, broonie@kernel.org,
Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Subject: [PATCH v3 2/5] tools/gpio: re-work gpio hammer with gpio operations
Date: Wed, 31 Aug 2016 11:45:45 +0200 [thread overview]
Message-ID: <20160831094548.12574-3-bamvor.zhangjian@linaro.org> (raw)
In-Reply-To: <20160831094548.12574-1-bamvor.zhangjian@linaro.org>
From: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
Signed-off-by: Bamvor Jian Zhang <bamvor.zhangjian@linaro.org>
---
tools/gpio/gpio-hammer.c | 52 ++++++++++--------------------------------------
1 file changed, 10 insertions(+), 42 deletions(-)
diff --git a/tools/gpio/gpio-hammer.c b/tools/gpio/gpio-hammer.c
index 37b3f14..14dd20c 100644
--- a/tools/gpio/gpio-hammer.c
+++ b/tools/gpio/gpio-hammer.c
@@ -23,49 +23,20 @@
#include <getopt.h>
#include <sys/ioctl.h>
#include <linux/gpio.h>
+#include "gpio-utils.h"
int hammer_device(const char *device_name, unsigned int *lines, int nlines,
unsigned int loops)
{
- struct gpiohandle_request req;
struct gpiohandle_data data;
- char *chrdev_name;
char swirr[] = "-\\|/";
- int fd;
int ret;
int i, j;
unsigned int iteration = 0;
- ret = asprintf(&chrdev_name, "/dev/%s", device_name);
- if (ret < 0)
- return -ENOMEM;
-
- fd = open(chrdev_name, 0);
- if (fd == -1) {
- ret = -errno;
- fprintf(stderr, "Failed to open %s\n", chrdev_name);
- goto exit_close_error;
- }
-
- /* Request lines as output */
- for (i = 0; i < nlines; i++)
- req.lineoffsets[i] = lines[i];
- req.flags = GPIOHANDLE_REQUEST_OUTPUT; /* Request as output */
- strcpy(req.consumer_label, "gpio-hammer");
- req.lines = nlines;
- ret = ioctl(fd, GPIO_GET_LINEHANDLE_IOCTL, &req);
- if (ret == -1) {
- ret = -errno;
- fprintf(stderr, "Failed to issue GET LINEHANDLE "
- "IOCTL (%d)\n",
- ret);
- goto exit_close_error;
- }
-
- /* Read initial states */
- ret = ioctl(req.fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data);
- if (ret == -1) {
- ret = -errno;
+ /* Do not set input or output to avoid change direction or value */
+ ret = gpio_gets(device_name, lines, nlines, 0, &data);
+ if (ret < 0) {
fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE "
"VALUES IOCTL (%d)\n",
ret);
@@ -92,18 +63,18 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
for (i = 0; i < nlines; i++)
data.values[i] = !data.values[i];
- ret = ioctl(req.fd, GPIOHANDLE_SET_LINE_VALUES_IOCTL, &data);
- if (ret == -1) {
- ret = -errno;
+ ret = gpio_sets(device_name, lines, nlines,
+ GPIOHANDLE_REQUEST_OUTPUT, &data);
+ if (ret < 0) {
fprintf(stderr, "Failed to issue GPIOHANDLE SET LINE "
"VALUES IOCTL (%d)\n",
ret);
goto exit_close_error;
}
/* Re-read values to get status */
- ret = ioctl(req.fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data);
- if (ret == -1) {
- ret = -errno;
+ ret = gpio_gets(device_name, lines, nlines,
+ GPIOHANDLE_REQUEST_OUTPUT, &data);
+ if (ret < 0) {
fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE "
"VALUES IOCTL (%d)\n",
ret);
@@ -132,9 +103,6 @@ int hammer_device(const char *device_name, unsigned int *lines, int nlines,
ret = 0;
exit_close_error:
- if (close(fd) == -1)
- perror("Failed to close GPIO character device file");
- free(chrdev_name);
return ret;
}
--
1.8.4.5
next prev parent reply other threads:[~2016-08-31 9:46 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-31 9:45 [PATCH v3 0/5] Add gpio test framework bamvor.zhangjian
2016-08-31 9:45 ` [PATCH v3 1/5] tools/gpio: add gpio basic opereations bamvor.zhangjian
2016-09-26 19:37 ` Linus Walleij
2016-09-28 19:16 ` Michael Welling
2016-09-28 21:35 ` Bamvor Zhang Jian
2016-09-28 22:12 ` Michael Welling
2016-08-31 9:45 ` bamvor.zhangjian [this message]
2016-10-13 4:28 ` [PATCH v3 2/5] tools/gpio: re-work gpio hammer with gpio operations Bamvor Zhang Jian
2016-08-31 9:45 ` [PATCH v3 3/5] gpio/mockup: add virtual gpio device bamvor.zhangjian
2016-09-26 18:48 ` Linus Walleij
2016-08-31 9:45 ` [PATCH v3 4/5] selftest/gpio: add gpio test case bamvor.zhangjian
2016-08-31 9:45 ` [PATCH v3 5/5] gpio: MAINTAINERS: Add an entry for GPIO mockup driver bamvor.zhangjian
2016-09-26 18:50 ` Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160831094548.12574-3-bamvor.zhangjian@linaro.org \
--to=bamvor.zhangjian@linaro.org \
--cc=broonie@kernel.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).