From patchwork Thu Oct 13 04:28:01 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: 77606 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp47545qge; Wed, 12 Oct 2016 21:29:11 -0700 (PDT) X-Received: by 10.66.26.209 with SMTP id n17mr5810456pag.69.1476332951561; Wed, 12 Oct 2016 21:29:11 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id sn9si10393230pab.296.2016.10.12.21.29.11; Wed, 12 Oct 2016 21:29:11 -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 S1754650AbcJME3K (ORCPT + 4 others); Thu, 13 Oct 2016 00:29:10 -0400 Received: from mail-it0-f43.google.com ([209.85.214.43]:37044 "EHLO mail-it0-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754822AbcJME3J (ORCPT ); Thu, 13 Oct 2016 00:29:09 -0400 Received: by mail-it0-f43.google.com with SMTP id z65so73154319itc.0 for ; Wed, 12 Oct 2016 21:28:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=3F6+uYNueyxuUFJQdOAaXjsbztPoPDHBzin0Qp5nXjk=; b=N70YwrgNLt/vQeyGpaOlzlaZnYKD2k/lceR28PDViVU0ct4j8c0DhZtD3DeLvH/Buq dpDbm1eqFPHnx5zdOu9VuEObr5H4HwOMtiVYlzcFC0ObMSTB5/Esa7r8jWZStwPnuvy9 98jxVtE3l2hlrPRrz/GzQmLEps6SwogU4XfN4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=3F6+uYNueyxuUFJQdOAaXjsbztPoPDHBzin0Qp5nXjk=; b=ib3fF+bJLBbtjPkw7Ese8GAmG04sOoOUephq5YClXFOS04i4cjZKVyZDCdwzVnu3Q2 Jq56CWTgn4tj/GW+d5iXaInDQl7YDqUlfGRm7/4Q1kWQmNofCYlK12sggzT2pvgAcVXn 535tyEoNjrHIBuCwOIQEVukxoD8RHkLQaT4VLSr68H8lxacrHIibm+U1K9n+aVGAbE9r VI6xWUKkr1eibKecpwa7j8H2oGrek17QSiFkx8Rng2nvLZAw35uOOkEIN+SrFbWNGTer eFrnzZtOWmt7LtmqGdiTlgx/ivW8yYnQ/7L/XJ7ESfmGJl4IHAjn5AK/FF/pQDovetdl AKng== X-Gm-Message-State: AA6/9RnjJlNlR1RqpT91Qs+ROopnKMzHhC3H13c/eZ1FgDSgBviAphvhhMhhjgm2SXVF2kV9hgWB9kDw46xIKj9T X-Received: by 10.36.110.197 with SMTP id w188mr6044224itc.114.1476332881750; Wed, 12 Oct 2016 21:28:01 -0700 (PDT) MIME-Version: 1.0 Received: by 10.36.93.196 with HTTP; Wed, 12 Oct 2016 21:28:01 -0700 (PDT) In-Reply-To: <20160831094548.12574-3-bamvor.zhangjian@linaro.org> References: <20160831094548.12574-1-bamvor.zhangjian@linaro.org> <20160831094548.12574-3-bamvor.zhangjian@linaro.org> From: Bamvor Zhang Jian Date: Thu, 13 Oct 2016 12:28:01 +0800 Message-ID: Subject: Re: [PATCH v3 2/5] tools/gpio: re-work gpio hammer with gpio operations To: linux-gpio@vger.kernel.org Cc: Linus Walleij , Mark Brown , Bamvor Jian Zhang , Michael Welling Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Hi, Linus, Michael When I am writing the updated version of gpio-hammer.c(base on the gpio-util.c we discussed). I am thinking if the gpio line is aleady output, maybe the user do not want to update the value. But I found that I must update the default_values in struct gpiohandle_request if I want to set gpio as output. Because I could not set the gpio direction after the gpio line request. And I could not skip the default value in request. I am thinking if we need to deal with it. The first option is add another flag(e.g. GPIOHANDLE_REQUEST_UPDATE_VALUE) to indicate the update the value of gpio. This method break the current application which rely on setting the default_values through GPIOHANDLE_REQUEST_OUTPUT. Another way is allow user update the flag after request. It need to add flags to struct linehandle_state. is consistent with behavior of sysfs. But in the real senario, the user need to get the value by setting 0 to the flag in gpio request, then release and set GPIOHANDLE_REQUEST_OUTPUT with the value it get from previous request. It lead to the request twice for setting/ flipping value of gpio. Suggestion? Regards Bamvor On 31 August 2016 at 17:45, wrote: > From: Bamvor Jian Zhang > > Signed-off-by: Bamvor Jian Zhang > --- > 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 > #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; > } > > -- > 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/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 53ff25a..a6965a3 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -329,6 +329,7 @@ struct linehandle_state { const char *label; struct gpio_desc *descs[GPIOHANDLES_MAX]; u32 numdescs; + u32 flags; }; The easiest way seems set the gpio value to 0 in gpio-hammer.c which