From patchwork Wed Aug 31 09:45:45 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bamvor Zhang Jian X-Patchwork-Id: 75060 Delivered-To: patch@linaro.org Received: by 10.140.29.52 with SMTP id a49csp238885qga; Wed, 31 Aug 2016 02:46:14 -0700 (PDT) X-Received: by 10.66.76.38 with SMTP id h6mr15029304paw.79.1472636773084; Wed, 31 Aug 2016 02:46:13 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y186si50121640pfb.59.2016.08.31.02.46.12; Wed, 31 Aug 2016 02:46:13 -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; dkim=neutral (body hash did not verify) header.i=@linaro.org; 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; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932796AbcHaJqM (ORCPT + 4 others); Wed, 31 Aug 2016 05:46:12 -0400 Received: from mail-pf0-f182.google.com ([209.85.192.182]:36020 "EHLO mail-pf0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932779AbcHaJqL (ORCPT ); Wed, 31 Aug 2016 05:46:11 -0400 Received: by mail-pf0-f182.google.com with SMTP id h186so17865472pfg.3 for ; Wed, 31 Aug 2016 02:46:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OrbWDjn13YNYLUtBkASFpVhTgCEPs91l52FytuuygQY=; b=T0F/4I7ngzNLaDJ2/Cz1RxqB6Jg+GxH6bTC5MR27sjUxaN8IeTr0/T5/3QnMrKHt82 MKDTop/9S1P9koPd170C8N35j5RA5q79Db1Hbna9rUJkHknBm0X+Of3Kdq3KBNx/tkT+ ITnLwsvjS0DzGkN6v2RilWFmUfI4Whr76aRjA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OrbWDjn13YNYLUtBkASFpVhTgCEPs91l52FytuuygQY=; b=Njsyru5p0QbxJAZKUzQO/dOCDi4AiPHL7zik4anAC8eoBAmRLxa7rmNqc3WonyLsk3 yXT2gO2ftVvHTVe2UvzUWT00oDx0DM1XA2ahpviXAIXcPT5IWMCjmvA2udhMXnGFUhcJ pGKPSKKgfyADnj8CXnkKfGR2xXjtByspML/GkkgyJaJJp7ahTaJn8qtXzYGY0ufkRKZp hpnhKSr3fNiO0rQhtulHuGeDr59dXpq/Rdh13+5lD4ubxgAkeHGY4zqdSWDIxRcG6eFv VVAqBdzJfrOHu2OljJIHgJ9zUq7/qrui6ebtu805zpYN98DQ+CEMgdngFMKytJoCtVa8 7LIg== X-Gm-Message-State: AE9vXwOjDyRUTPID9nH3Wdc9D+KfsuHuBPEuxvYEeal4Rfr8xtsdr8uPM0va5vDDtdhnOAkb X-Received: by 10.98.102.79 with SMTP id a76mr15165504pfc.75.1472636771121; Wed, 31 Aug 2016 02:46:11 -0700 (PDT) Received: from localhost.localdomain ([122.96.104.20]) by smtp.gmail.com with ESMTPSA id s23sm63634289pfd.23.2016.08.31.02.46.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 31 Aug 2016 02:46:10 -0700 (PDT) From: bamvor.zhangjian@linaro.org To: linux-gpio@vger.kernel.org Cc: linus.walleij@linaro.org, broonie@kernel.org, Bamvor Jian Zhang Subject: [PATCH v3 2/5] tools/gpio: re-work gpio hammer with gpio operations Date: Wed, 31 Aug 2016 11:45:45 +0200 Message-Id: <20160831094548.12574-3-bamvor.zhangjian@linaro.org> X-Mailer: git-send-email 2.8.4 In-Reply-To: <20160831094548.12574-1-bamvor.zhangjian@linaro.org> References: <20160831094548.12574-1-bamvor.zhangjian@linaro.org> 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 | 52 ++++++++++-------------------------------------- 1 file changed, 10 insertions(+), 42 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..14dd20c 100644 --- a/tools/gpio/gpio-hammer.c +++ b/tools/gpio/gpio-hammer.c @@ -23,49 +23,20 @@ #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); - 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; }