From patchwork Fri Oct 14 02:48:26 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhangjian \(Bamvor\)" X-Patchwork-Id: 77643 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp110827qge; Thu, 13 Oct 2016 19:45:37 -0700 (PDT) X-Received: by 10.99.3.69 with SMTP id 66mr12225497pgd.157.1476413137067; Thu, 13 Oct 2016 19:45:37 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id rf4si13963910pab.9.2016.10.13.19.45.36; Thu, 13 Oct 2016 19:45:37 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-gpio-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-gpio-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753507AbcJNCpf (ORCPT + 4 others); Thu, 13 Oct 2016 22:45:35 -0400 Received: from szxga02-in.huawei.com ([119.145.14.65]:18620 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753767AbcJNCpe (ORCPT ); Thu, 13 Oct 2016 22:45:34 -0400 Received: from 172.24.1.36 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.36]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DOS17072; Fri, 14 Oct 2016 10:45:12 +0800 (CST) Received: from linux696.huawei.com (10.110.52.23) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Fri, 14 Oct 2016 10:45:06 +0800 From: Bamvor Jian Zhang To: CC: , , , Subject: [PATCH v4 2/3] tools/gpio: re-work gpio hammer with gpio operations Date: Fri, 14 Oct 2016 10:48:26 +0800 Message-ID: <1476413307-1397-3-git-send-email-bamvor.zhangjian@huawei.com> X-Mailer: git-send-email 1.8.4.5 In-Reply-To: <1476413307-1397-1-git-send-email-bamvor.zhangjian@huawei.com> References: <1476413307-1397-1-git-send-email-bamvor.zhangjian@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.110.52.23] X-CFilter-Loop: Reflected Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bamvor Jian Zhang Signed-off-by: Bamvor Jian Zhang --- tools/gpio/gpio-hammer.c | 67 ++++++++++++------------------------------------ 1 file changed, 17 insertions(+), 50 deletions(-) -- 1.8.4.5 -- To unsubscribe from this list: send the line "unsubscribe linux-gpio" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/gpio/gpio-hammer.c b/tools/gpio/gpio-hammer.c index 37b3f14..f1eab58 100644 --- a/tools/gpio/gpio-hammer.c +++ b/tools/gpio/gpio-hammer.c @@ -23,54 +23,31 @@ #include #include #include +#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); + memset(&data.values, 0, sizeof(data.values)); + ret = gpiotools_request_linehandle(device_name, lines, nlines, + GPIOHANDLE_REQUEST_OUTPUT, &data, + "gpio-hammler"); if (ret < 0) - return -ENOMEM; + goto exit_error; + else + fd = ret; - 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); + ret = gpiotools_get_values(fd, &data); + if (ret < 0) goto exit_close_error; - } - /* Read initial states */ - ret = ioctl(req.fd, GPIOHANDLE_GET_LINE_VALUES_IOCTL, &data); - if (ret == -1) { - ret = -errno; - fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE " - "VALUES IOCTL (%d)\n", - ret); - goto exit_close_error; - } fprintf(stdout, "Hammer lines ["); for (i = 0; i < nlines; i++) { fprintf(stdout, "%d", lines[i]); @@ -92,23 +69,14 @@ 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; - fprintf(stderr, "Failed to issue GPIOHANDLE SET LINE " - "VALUES IOCTL (%d)\n", - ret); + ret = gpiotools_set_values(fd, &data); + if (ret < 0) 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; - fprintf(stderr, "Failed to issue GPIOHANDLE GET LINE " - "VALUES IOCTL (%d)\n", - ret); + ret = gpiotools_get_values(fd, &data); + if (ret < 0) goto exit_close_error; - } fprintf(stdout, "[%c] ", swirr[j]); j++; @@ -132,9 +100,8 @@ 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); + gpiotools_release_linehandle(fd); +exit_error: return ret; }