From patchwork Tue Jun 23 04:00:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206707 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31CACC433E0 for ; Tue, 23 Jun 2020 04:01:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0C44220771 for ; Tue, 23 Jun 2020 04:01:50 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BsK5D7gt" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726963AbgFWEBt (ORCPT ); Tue, 23 Jun 2020 00:01:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWEBt (ORCPT ); Tue, 23 Jun 2020 00:01:49 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E64B2C061573; Mon, 22 Jun 2020 21:01:47 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id b16so9436447pfi.13; Mon, 22 Jun 2020 21:01:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p1/q8MRSUJLItYrr+zmUyqWqShRkPABeF0cerkoW7Mc=; b=BsK5D7gt1DKDoyIH2ftv6oNnlv+dMAvHEkVqTMUWYeqXDxyZM96si0lgn+mnHniSdm u5hETPB5cjJ7HI2rbjBcDe1XVZbW+EOd7HdL/VwJaSxdrLBV1zBgap0MZWUpRTs/7KhT smyGwI6eONvnRetwiT7E/mf2Lm5O/qlLQyvvSZBUPeJu4ZRp8sdBA0fFR3WFhTDx8L+t J2j1bYs3bUu/qusMXYwz2qq+YEyhOVZrvGzBxCOy00iXnqZev3N//5IvyJVjaCQ/rhDR NMCrMZEMyRz9I41AYC/YKzlyQMczxNc+Nr/g5dO6PxDP4hoNyusj1XYEep5oW2jfvfjK Mq4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p1/q8MRSUJLItYrr+zmUyqWqShRkPABeF0cerkoW7Mc=; b=TtKO0AW+GNfC8qmOiEudh2n/8DU/OD9tyFYUPmJfjiNG+PYTPQj8qpKy4MSTL1Y+UE RxzP2X11QtYpoS1zfKmbgGEjlLcYeotuvVdRKdw9+gEmvWOfqUgMwAX3Eo9kGHRX1dgw X8qRSZuirLMKT9A7W3cXriIi+fINlnMOslHrro9C6K+nHIuM5k2JwWsDLJBZA2yYqNuy WG6S2dZ8tpx2U5XImwGo+KjQr2LNXZ0DHJGBxPFZI955/E2V9VZjvcmt+yTWih5L5XA2 ruVgh3rygsejpwrZAPmGgv0wrg281iOsQRE6ajpM9IbY8OY75RJdohrWdllrwBm74ISM q+HQ== X-Gm-Message-State: AOAM53385SmCA4rWa0Fs4jNLYbzoLdiUROtJi3jl349vSLqo5cYrCkVC mHUKX/Q/dKvbd1aUd5hefmAl3A2x6iQ= X-Google-Smtp-Source: ABdhPJzf2ywv9cZJX6eqgHYV5iprYhHP4fEhfWOef7c1wSlmR+xYZ1MD6MPJnHYZjsizHENa+nFJ1g== X-Received: by 2002:a63:d208:: with SMTP id a8mr15312328pgg.351.1592884907055; Mon, 22 Jun 2020 21:01:47 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:01:46 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 01/22] gpiolib: move gpiolib-sysfs function declarations into their own header Date: Tue, 23 Jun 2020 12:00:46 +0800 Message-Id: <20200623040107.22270-2-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Move gpiolib-sysfs function declarations into their own header. These functions are in gpiolib-sysfs.c, and are only required by gpiolib.c, and so should be in a module header, not giolib.h. This brings gpiolib-sysfs into line with gpiolib-cdev, and is another step towards removing the sysfs inferface. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-sysfs.c | 1 + drivers/gpio/gpiolib-sysfs.h | 24 ++++++++++++++++++++++++ drivers/gpio/gpiolib.c | 1 + drivers/gpio/gpiolib.h | 18 ------------------ 4 files changed, 26 insertions(+), 18 deletions(-) create mode 100644 drivers/gpio/gpiolib-sysfs.h diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index 23e3d335cd54..18f94be1b458 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -11,6 +11,7 @@ #include #include "gpiolib.h" +#include "gpiolib-sysfs.h" #define GPIO_IRQF_TRIGGER_FALLING BIT(0) #define GPIO_IRQF_TRIGGER_RISING BIT(1) diff --git a/drivers/gpio/gpiolib-sysfs.h b/drivers/gpio/gpiolib-sysfs.h new file mode 100644 index 000000000000..ddd0e503f8eb --- /dev/null +++ b/drivers/gpio/gpiolib-sysfs.h @@ -0,0 +1,24 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef GPIOLIB_SYSFS_H +#define GPIOLIB_SYSFS_H + +#ifdef CONFIG_GPIO_SYSFS + +int gpiochip_sysfs_register(struct gpio_device *gdev); +void gpiochip_sysfs_unregister(struct gpio_device *gdev); + +#else + +static inline int gpiochip_sysfs_register(struct gpio_device *gdev) +{ + return 0; +} + +static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev) +{ +} + +#endif /* CONFIG_GPIO_SYSFS */ + +#endif /* GPIOLIB_SYSFS_H */ diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4abd751314a5..517c99ddf6c8 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -26,6 +26,7 @@ #include "gpiolib-of.h" #include "gpiolib-acpi.h" #include "gpiolib-cdev.h" +#include "gpiolib-sysfs.h" #define CREATE_TRACE_POINTS #include diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 9ed242316414..2dee4e1e12dc 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -175,22 +175,4 @@ static inline int gpio_chip_hwgpio(const struct gpio_desc *desc) #define chip_dbg(gc, fmt, ...) \ dev_dbg(&gc->gpiodev->dev, "(%s): " fmt, gc->label, ##__VA_ARGS__) -#ifdef CONFIG_GPIO_SYSFS - -int gpiochip_sysfs_register(struct gpio_device *gdev); -void gpiochip_sysfs_unregister(struct gpio_device *gdev); - -#else - -static inline int gpiochip_sysfs_register(struct gpio_device *gdev) -{ - return 0; -} - -static inline void gpiochip_sysfs_unregister(struct gpio_device *gdev) -{ -} - -#endif /* CONFIG_GPIO_SYSFS */ - #endif /* GPIOLIB_H */ From patchwork Tue Jun 23 04:00:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206706 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB9AAC433E0 for ; Tue, 23 Jun 2020 04:02:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90AC720771 for ; Tue, 23 Jun 2020 04:02:02 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U2W84ThB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731977AbgFWECC (ORCPT ); Tue, 23 Jun 2020 00:02:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWECB (ORCPT ); Tue, 23 Jun 2020 00:02:01 -0400 Received: from mail-pj1-x1044.google.com (mail-pj1-x1044.google.com [IPv6:2607:f8b0:4864:20::1044]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83CC2C061573; Mon, 22 Jun 2020 21:02:01 -0700 (PDT) Received: by mail-pj1-x1044.google.com with SMTP id ga6so910797pjb.1; Mon, 22 Jun 2020 21:02:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0FgTxUzz+w3uq8vispnW3M0gHTXLq8lEJYcL3RfDb/M=; b=U2W84ThBLBxe5recJA4ic4JY6zgQXz7I9Jb/txRHXcZUJOEUpK7F303nniNfIP/g24 zbiYX+C/FKZBZku4kqk2hOsRJ3uSH7EQGBIQX7qxybTRvnWlb6WZ8OwZ5NqqRQ+l6YCs +4ZkldRuiWEmxvus9wdlw88wocZwruWEYrh4NhQmzAPlP1qm4IUx0whFMVirqJ3aCw4J eg24k9JjovCT/8BKlPKzdijXdUVmcmIXipxXhkqVzNec12gO1DrQzEOBIoaRvZEFz/PR /mDk5cz+SAxdsXNwSHuJl3WeSNTCFmklFePscK1K3HTYQevvKdutExqFzBt12T3o0HU3 AeYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0FgTxUzz+w3uq8vispnW3M0gHTXLq8lEJYcL3RfDb/M=; b=K/OD/9nFPgKad6h/ToRO1RyDtDmGvoCq80trHmjsQOt75OGvf3QSum1Q3n8GGYPU7g ue/V54uEmqfRkRxjmL56DLdU3d5sHYaEUj1KEUoPIB/IyTnn+QG+xf57he/sPmUVn+au 6rChml/rDUu4KskbWarA8fXSmFD7wLD1N6H4aqtyhJeG6gcsxrNwrOjcdPZCS2SHSAWn rbEu8jjNmbANnkcSFbs0HSQbXZLUc6hy8r4lN9qk5/pHh/gBPp+Hb2UTfHeUr80EupQh 8mQQ5kaplSR37XwrJoFINWE+QnlYV7QmB6f/pbqaNtPD666Hh41yXSd6pO5PDCiOiE6o XqcQ== X-Gm-Message-State: AOAM531fBjL10jMgSE3jsbvs3bez9tJdXfimp3mZGg2Le3MvK8nIiZUI bi/wZzDILFBrOcBjHVI9hptOhf7DIz0= X-Google-Smtp-Source: ABdhPJzeDLPeuRLzK/5qPKN53/vQOosTI09Re4Jw6xFC3K5qsQ4ZpYTyAWQysiiYJBK16ev6/2K3Ww== X-Received: by 2002:a17:90a:fd87:: with SMTP id cx7mr21074054pjb.62.1592884920503; Mon, 22 Jun 2020 21:02:00 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.01.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:01:59 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 03/22] gpiolib: cdev: minor indentation fixes Date: Tue, 23 Jun 2020 12:00:48 +0800 Message-Id: <20200623040107.22270-4-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Make indentation consistent with other use to improve readability. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 55a9b7b44304..889ed2dc9e58 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -98,7 +98,7 @@ static int linehandle_validate_flags(u32 flags) /* Only one bias flag can be set. */ if (((flags & GPIOHANDLE_REQUEST_BIAS_DISABLE) && (flags & (GPIOHANDLE_REQUEST_BIAS_PULL_DOWN | - GPIOHANDLE_REQUEST_BIAS_PULL_UP))) || + GPIOHANDLE_REQUEST_BIAS_PULL_UP))) || ((flags & GPIOHANDLE_REQUEST_BIAS_PULL_DOWN) && (flags & GPIOHANDLE_REQUEST_BIAS_PULL_UP))) return -EINVAL; @@ -212,11 +212,11 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, /* Reuse the array setting function */ return gpiod_set_array_value_complex(false, - true, - lh->numdescs, - lh->descs, - NULL, - vals); + true, + lh->numdescs, + lh->descs, + NULL, + vals); } else if (cmd == GPIOHANDLE_SET_CONFIG_IOCTL) { return linehandle_set_config(lh, ip); } @@ -225,7 +225,7 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, #ifdef CONFIG_COMPAT static long linehandle_ioctl_compat(struct file *filep, unsigned int cmd, - unsigned long arg) + unsigned long arg) { return linehandle_ioctl(filep, cmd, (unsigned long)compat_ptr(arg)); } @@ -428,7 +428,7 @@ struct lineevent_state { GPIOEVENT_REQUEST_FALLING_EDGE) static __poll_t lineevent_poll(struct file *filep, - struct poll_table_struct *wait) + struct poll_table_struct *wait) { struct lineevent_state *le = filep->private_data; __poll_t events = 0; @@ -720,11 +720,11 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) /* Request a thread to read the events */ ret = request_threaded_irq(le->irq, - lineevent_irq_handler, - lineevent_irq_thread, - irqflags, - le->label, - le); + lineevent_irq_handler, + lineevent_irq_thread, + irqflags, + le->label, + le); if (ret) goto out_free_desc; @@ -1052,7 +1052,7 @@ static ssize_t lineinfo_watch_read(struct file *filep, char __user *buf, static int gpio_chrdev_open(struct inode *inode, struct file *filp) { struct gpio_device *gdev = container_of(inode->i_cdev, - struct gpio_device, chrdev); + struct gpio_device, chrdev); struct gpio_chardev_data *priv; int ret = -ENOMEM; From patchwork Tue Jun 23 04:00:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206705 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6155CC433E1 for ; Tue, 23 Jun 2020 04:02:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3796D207BC for ; Tue, 23 Jun 2020 04:02:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="s+sq0iV/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732059AbgFWECN (ORCPT ); Tue, 23 Jun 2020 00:02:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWECM (ORCPT ); Tue, 23 Jun 2020 00:02:12 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DED9C061573; Mon, 22 Jun 2020 21:02:12 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id h95so958823pje.4; Mon, 22 Jun 2020 21:02:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i8zhdctiZjWNhC59KOSnhC2O0eynxpTLLMagiHeOKl0=; b=s+sq0iV/dgi4bkDc3ee6DQ59A/BJnaCe2GarZs9OeaVDK+akfDBRGR0Ukgr0+6OGUu nFi9RYKm2QNkZZlpQgg8KLWIrmgsD56EHIWmsbLU9C1fggbn0GxvECr8tBGeS0oqiiCN p5nm3cojPhPI7hfOgJ6YiB4bqcK8zzEhN/eEo2h1OvB59REvPgID3qCTHCb3WX6PK8ph SDfs9iFZu1pG5xxPuSVoHi85c6u3Lo+OOykUU0jdDkFAXV13zPr+HZaQXMuw/diykeUo JyczitS+mmKu8m+g8PQmBK5w5Od5MzZ9X1xGlDdhzRY+4o6+xKKvEiLh8MGHqPP8FKXA HFZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i8zhdctiZjWNhC59KOSnhC2O0eynxpTLLMagiHeOKl0=; b=fKFcTxHEvytckrIkzGJveWhWErwuHW2++heFtzAoLmyArykDxgDnKZ1BgHeG/5+ifo Q5uLiTzztpi4KnN5x7bk7d8NX8BHcPC3PMsSW6EwkLURg2zRG6RplRR1QXTdeFqQNLiF mKPW4457ppebaebLaJiCAhCREtP3FvzdmwvBGaGqmHRM6hizkUTGn06oNKG+lkG4vqF5 2WJ9+tUxsOt8E6IMigRtGLqnwOo5L38bjExgw4jukTBAhxhleuWELAkhsMnULpuTU74x hEglOeG6UvRHfTfBI9K6730CKCrwJVvDEwog1HbpYJvho5xDXv1HOID5W7dpCCueefvu FKnQ== X-Gm-Message-State: AOAM5318U1Yq/G5/6i+b4amkY5BbFZTwA50pjInyaM6AGZfT6/6MwfJ9 2e3VCUuLwyy3V/iffHNfk2sNjPqSVrI= X-Google-Smtp-Source: ABdhPJzkpbQrCQBUfQ57Ima0NM2NFEbu/g2JH4CCNsz2jHrAbuKtC/9fP3kd1y9nas82mIoBR+Ym0Q== X-Received: by 2002:a17:902:bc82:: with SMTP id bb2mr21648148plb.225.1592884931586; Mon, 22 Jun 2020 21:02:11 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:02:10 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 05/22] gpiolib: cdev: rename 'filep' and 'filp' to 'file' to be consistent with other use Date: Tue, 23 Jun 2020 12:00:50 +0800 Message-Id: <20200623040107.22270-6-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Rename 'filep' and 'filp' to 'file' to be consistent with other use and improve readability. Signed-off-by: Kent Gibson --- The code was using both "filep" and "filp" and I flip flopped between which one to change to until looking at code elsewhere in the kernel where "struct file *file" is the most common and so going with that. drivers/gpio/gpiolib-cdev.c | 70 ++++++++++++++++++------------------- 1 file changed, 35 insertions(+), 35 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index e64613b8d0ba..0d3a799e09ae 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -164,10 +164,10 @@ static long linehandle_set_config(struct linehandle_state *lh, return 0; } -static long linehandle_ioctl(struct file *filep, unsigned int cmd, +static long linehandle_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct linehandle_state *lh = filep->private_data; + struct linehandle_state *lh = file->private_data; void __user *ip = (void __user *)arg; struct gpiohandle_data ghd; DECLARE_BITMAP(vals, GPIOHANDLES_MAX); @@ -221,16 +221,16 @@ static long linehandle_ioctl(struct file *filep, unsigned int cmd, } #ifdef CONFIG_COMPAT -static long linehandle_ioctl_compat(struct file *filep, unsigned int cmd, +static long linehandle_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { - return linehandle_ioctl(filep, cmd, (unsigned long)compat_ptr(arg)); + return linehandle_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } #endif -static int linehandle_release(struct inode *inode, struct file *filep) +static int linehandle_release(struct inode *inode, struct file *file) { - struct linehandle_state *lh = filep->private_data; + struct linehandle_state *lh = file->private_data; struct gpio_device *gdev = lh->gdev; int i; @@ -412,13 +412,13 @@ struct lineevent_state { (GPIOEVENT_REQUEST_RISING_EDGE | \ GPIOEVENT_REQUEST_FALLING_EDGE) -static __poll_t lineevent_poll(struct file *filep, +static __poll_t lineevent_poll(struct file *file, struct poll_table_struct *wait) { - struct lineevent_state *le = filep->private_data; + struct lineevent_state *le = file->private_data; __poll_t events = 0; - poll_wait(filep, &le->wait, wait); + poll_wait(file, &le->wait, wait); if (!kfifo_is_empty_spinlocked_noirqsave(&le->events, &le->wait.lock)) events = EPOLLIN | EPOLLRDNORM; @@ -427,12 +427,12 @@ static __poll_t lineevent_poll(struct file *filep, } -static ssize_t lineevent_read(struct file *filep, +static ssize_t lineevent_read(struct file *file, char __user *buf, size_t count, loff_t *f_ps) { - struct lineevent_state *le = filep->private_data; + struct lineevent_state *le = file->private_data; struct gpioevent_data ge; ssize_t bytes_read = 0; int ret; @@ -448,7 +448,7 @@ static ssize_t lineevent_read(struct file *filep, return bytes_read; } - if (filep->f_flags & O_NONBLOCK) { + if (file->f_flags & O_NONBLOCK) { spin_unlock(&le->wait.lock); return -EAGAIN; } @@ -481,9 +481,9 @@ static ssize_t lineevent_read(struct file *filep, return bytes_read; } -static int lineevent_release(struct inode *inode, struct file *filep) +static int lineevent_release(struct inode *inode, struct file *file) { - struct lineevent_state *le = filep->private_data; + struct lineevent_state *le = file->private_data; struct gpio_device *gdev = le->gdev; free_irq(le->irq, le); @@ -494,10 +494,10 @@ static int lineevent_release(struct inode *inode, struct file *filep) return 0; } -static long lineevent_ioctl(struct file *filep, unsigned int cmd, +static long lineevent_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct lineevent_state *le = filep->private_data; + struct lineevent_state *le = file->private_data; void __user *ip = (void __user *)arg; struct gpiohandle_data ghd; @@ -524,10 +524,10 @@ static long lineevent_ioctl(struct file *filep, unsigned int cmd, } #ifdef CONFIG_COMPAT -static long lineevent_ioctl_compat(struct file *filep, unsigned int cmd, +static long lineevent_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { - return lineevent_ioctl(filep, cmd, (unsigned long)compat_ptr(arg)); + return lineevent_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } #endif @@ -826,9 +826,9 @@ struct gpio_chardev_data { /* * gpio_ioctl() - ioctl handler for the GPIO chardev */ -static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct gpio_chardev_data *priv = filp->private_data; + struct gpio_chardev_data *priv = file->private_data; struct gpio_device *gdev = priv->gdev; struct gpio_chip *gc = gdev->chip; void __user *ip = (void __user *)arg; @@ -919,10 +919,10 @@ static long gpio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } #ifdef CONFIG_COMPAT -static long gpio_ioctl_compat(struct file *filp, unsigned int cmd, +static long gpio_ioctl_compat(struct file *file, unsigned int cmd, unsigned long arg) { - return gpio_ioctl(filp, cmd, (unsigned long)compat_ptr(arg)); + return gpio_ioctl(file, cmd, (unsigned long)compat_ptr(arg)); } #endif @@ -958,13 +958,13 @@ static int lineinfo_changed_notify(struct notifier_block *nb, return NOTIFY_OK; } -static __poll_t lineinfo_watch_poll(struct file *filep, +static __poll_t lineinfo_watch_poll(struct file *file, struct poll_table_struct *pollt) { - struct gpio_chardev_data *priv = filep->private_data; + struct gpio_chardev_data *priv = file->private_data; __poll_t events = 0; - poll_wait(filep, &priv->wait, pollt); + poll_wait(file, &priv->wait, pollt); if (!kfifo_is_empty_spinlocked_noirqsave(&priv->events, &priv->wait.lock)) @@ -973,10 +973,10 @@ static __poll_t lineinfo_watch_poll(struct file *filep, return events; } -static ssize_t lineinfo_watch_read(struct file *filep, char __user *buf, +static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, size_t count, loff_t *off) { - struct gpio_chardev_data *priv = filep->private_data; + struct gpio_chardev_data *priv = file->private_data; struct gpioline_info_changed event; ssize_t bytes_read = 0; int ret; @@ -992,7 +992,7 @@ static ssize_t lineinfo_watch_read(struct file *filep, char __user *buf, return bytes_read; } - if (filep->f_flags & O_NONBLOCK) { + if (file->f_flags & O_NONBLOCK) { spin_unlock(&priv->wait.lock); return -EAGAIN; } @@ -1024,10 +1024,10 @@ static ssize_t lineinfo_watch_read(struct file *filep, char __user *buf, /** * gpio_chrdev_open() - open the chardev for ioctl operations * @inode: inode for this chardev - * @filp: file struct for storing private data + * @file: file struct for storing private data * Returns 0 on success */ -static int gpio_chrdev_open(struct inode *inode, struct file *filp) +static int gpio_chrdev_open(struct inode *inode, struct file *file) { struct gpio_device *gdev = container_of(inode->i_cdev, struct gpio_device, chrdev); @@ -1057,9 +1057,9 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp) goto out_free_bitmap; get_device(&gdev->dev); - filp->private_data = priv; + file->private_data = priv; - ret = nonseekable_open(inode, filp); + ret = nonseekable_open(inode, file); if (ret) goto out_unregister_notifier; @@ -1078,12 +1078,12 @@ static int gpio_chrdev_open(struct inode *inode, struct file *filp) /** * gpio_chrdev_release() - close chardev after ioctl operations * @inode: inode for this chardev - * @filp: file struct for storing private data + * @file: file struct for storing private data * Returns 0 on success */ -static int gpio_chrdev_release(struct inode *inode, struct file *filp) +static int gpio_chrdev_release(struct inode *inode, struct file *file) { - struct gpio_chardev_data *priv = filp->private_data; + struct gpio_chardev_data *priv = file->private_data; struct gpio_device *gdev = priv->gdev; bitmap_free(priv->watched_lines); From patchwork Tue Jun 23 04:00:52 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B30BC433E0 for ; Tue, 23 Jun 2020 04:02:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1720920771 for ; Tue, 23 Jun 2020 04:02:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lX0q9/G7" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732107AbgFWECZ (ORCPT ); Tue, 23 Jun 2020 00:02:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWECY (ORCPT ); Tue, 23 Jun 2020 00:02:24 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD44BC061573; Mon, 22 Jun 2020 21:02:23 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id 35so8570386ple.0; Mon, 22 Jun 2020 21:02:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bC9ynXd4F/s6hkCty4NlJ0fUEOgHX2qzuPDIPZLMBAM=; b=lX0q9/G7P57n76scvPKm16pAXRU989y9yxg/302JoL5I+xc1czMEHkY7NJuaQJc3O8 nzesxpfEg8IAl42rlpHSvjDtnGWkGxTbGFO13aDsBrLIILUHAGzVUtQ2Jiv+DKiDJGsY HHJrBCbmC4ITjFw4nfSLaZGKCSmeyYjMWv5O23RG9JVsgdVlSr5aQYzEFxDbgeH+GNkx l+3GqF6ENTDVm1Fo71mqlQ06XGTyxWKTF82T3dRiLUeO1z9rFfhWDOPLHe7+s3MlcSX9 KfbnpByFpwawWld0mg9Sa8SB0wNP1GpXsiPjCV+iQ38V+aLNDbleJ/ZhC0v6a50+BaHZ c5Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=bC9ynXd4F/s6hkCty4NlJ0fUEOgHX2qzuPDIPZLMBAM=; b=Eoqjn+xlymSCOQjW//grBdD3r7KxS/u7J/OTfYPIJJvpNbmaZhe9Z70tec7hbf0J+N ldQWPleaFbWmmyZXue+J5ejV+lnoqYXaN8Q49vhRGChwvCCPT+EogrOnbi9ZXn8iCrNV OjpEJsYn4DBihbMiRDStvpJ4yHKmR39BswHkHgsLm2VzJGJbgyJU+dBpatQcLHM/TnS0 1kP38x1YrkhJOFyoByqV9fmaU+z1e4dXEVj1cSVMpTp+VkQ/31RiM94yrztUm2ZAywBB XWlDX1lrPsHiOnvdmFFlweCZj59Z8i2Vuh6vVv9psBsm11HpO4L5hkEO5fYgxNrwvHw/ RYBQ== X-Gm-Message-State: AOAM531Kl5JV5dLpDDTQolS9rD30oXzQ+MVoztonzFFubj6VEZxE3i5Q 1E0pEQpsa35kEgDhyV5B8Bo0KCFDxjs= X-Google-Smtp-Source: ABdhPJwuBsimsEDAM0kN1xoKk2e3IJbQmSvvCwoZGzBsg4I7b3+HKOxTYB47LNPlLGeZycaC4tRunw== X-Received: by 2002:a17:90a:df11:: with SMTP id gp17mr725282pjb.188.1592884942911; Mon, 22 Jun 2020 21:02:22 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.02.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:02:22 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 07/22] gpiolib: cdev: remove pointless decrement of i Date: Tue, 23 Jun 2020 12:00:52 +0800 Message-Id: <20200623040107.22270-8-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Remove pointless decrement of variable, and associated comment. While i is used subsequently, it is re-initialized so this decrement serves no purpose. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index b39e7ef8c0d4..d50339ef6f05 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -331,8 +331,6 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) dev_dbg(&gdev->dev, "registered chardev handle for line %d\n", offset); } - /* Let i point at the last handle */ - i--; lh->num_descs = handlereq.lines; fd = get_unused_fd_flags(O_RDONLY | O_CLOEXEC); From patchwork Tue Jun 23 04:00:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206703 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C46E9C433DF for ; Tue, 23 Jun 2020 04:02:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B1E020771 for ; Tue, 23 Jun 2020 04:02:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W0YsMx4C" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732150AbgFWECf (ORCPT ); Tue, 23 Jun 2020 00:02:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWECe (ORCPT ); Tue, 23 Jun 2020 00:02:34 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37480C061573; Mon, 22 Jun 2020 21:02:34 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id cm23so911145pjb.5; Mon, 22 Jun 2020 21:02:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LqoHGw9AEr8BsRttpXKzXntPiww4DtH340vCNhdtdPA=; b=W0YsMx4Ctpkab0DRzxUXRRVIY1RkgDkP5OoqTj4BlY77Z8GVA3y7cdKXlccwj6Pfkm Pi40S51YUYLL5arJXUGcuKva8p47sJMEQc8/8do03PQNov7CRMJLOiwyo0Lsp/kOB6E3 vW36uWFEsgtoTwDMvdZ3teH4j+U3CJ3JSnbTEGzrCqVYo6G3fCsYQaOwGOJiIRAoiwo0 vaNIan77MVnXvt5oipEAbcKDYDn3E6cvmOV7Vvx2YEb3i3xjkO4KcG8bY7oQROmPCY1c kG5tZwhjRu4bxWS2FPWCbwLUKa4sSN5ZQ7OXjeKtQPXpdqL7Pv4lAk5NuyrYvx0Zf7wI uacA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LqoHGw9AEr8BsRttpXKzXntPiww4DtH340vCNhdtdPA=; b=VUVJU//KjFVd24QD2HIkln5KQJpxLaCW09UdOawrIwtuQiJyuSspKvoqyft6IKr8bl eim/B74ADCw4Llxhzh05gE6bdnaD0avhWaYw8HcSSH99/6TvYkhDoXzne8O0E0Imm/J5 wMXkBXiAb85miMf6wLSfgo0fcrApTufg0x1m8YvEwuzdBfDy+UffHAkqCY9JYvb/pXDC +ktYBFt74UFq6qoil4HsQ3O823oDxAGYzgVlGwUe7lY8+pUJH62un6U9MNbV6hL1wuaC uK4PPbTF02CuVytOW04ooiTylaaGpnwSVE3oQzmFsp7bRrVg3Hz5I1EVgjtIbEuvmFB5 zoKg== X-Gm-Message-State: AOAM532OHdUdihY66x0PJ+v+HZ1SNEf0PfTOWGY0Js9vx7UEzuruiT1g XtG3HyHiZjdoFZ1+ye4qp1G4kR1caLc= X-Google-Smtp-Source: ABdhPJxpuUOmBahnAb/6/luKkrs3opwmJRABEYRF5jqMPsgNNM9FxQq/YtyT09SjPyVgaUgbwD49+A== X-Received: by 2002:a17:90a:e288:: with SMTP id d8mr22548179pjz.173.1592884953203; Mon, 22 Jun 2020 21:02:33 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.02.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:02:32 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 09/22] gpiolib: cdev: rename priv to gcdev Date: Tue, 23 Jun 2020 12:00:54 +0800 Message-Id: <20200623040107.22270-10-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Rename priv to gcdev to improve readability. The name "priv" indicates that the object is pointed to by file->private_data, not what the object is actually is. It is always used to point to a struct gpio_chardev_data so renaming it to gcdev seemed as good as anything, and certainly clearer than "priv". Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 90 ++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 1e8e0a0a9b51..5f5b715ed7f7 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -828,8 +828,8 @@ struct gpio_chardev_data { */ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { - struct gpio_chardev_data *priv = file->private_data; - struct gpio_device *gdev = priv->gdev; + struct gpio_chardev_data *gcdev = file->private_data; + struct gpio_device *gdev = gcdev->gdev; struct gpio_chip *gc = gdev->chip; void __user *ip = (void __user *)arg; struct gpio_desc *desc; @@ -889,7 +889,7 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) hwgpio = gpio_chip_hwgpio(desc); - if (test_bit(hwgpio, priv->watched_lines)) + if (test_bit(hwgpio, gcdev->watched_lines)) return -EBUSY; gpio_desc_to_lineinfo(desc, &lineinfo); @@ -897,7 +897,7 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) return -EFAULT; - set_bit(hwgpio, priv->watched_lines); + set_bit(hwgpio, gcdev->watched_lines); return 0; } else if (cmd == GPIO_GET_LINEINFO_UNWATCH_IOCTL) { if (copy_from_user(&offset, ip, sizeof(offset))) @@ -909,10 +909,10 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) hwgpio = gpio_chip_hwgpio(desc); - if (!test_bit(hwgpio, priv->watched_lines)) + if (!test_bit(hwgpio, gcdev->watched_lines)) return -EBUSY; - clear_bit(hwgpio, priv->watched_lines); + clear_bit(hwgpio, gcdev->watched_lines); return 0; } return -EINVAL; @@ -935,12 +935,12 @@ to_gpio_chardev_data(struct notifier_block *nb) static int lineinfo_changed_notify(struct notifier_block *nb, unsigned long action, void *data) { - struct gpio_chardev_data *priv = to_gpio_chardev_data(nb); + struct gpio_chardev_data *gcdev = to_gpio_chardev_data(nb); struct gpioline_info_changed chg; struct gpio_desc *desc = data; int ret; - if (!test_bit(gpio_chip_hwgpio(desc), priv->watched_lines)) + if (!test_bit(gpio_chip_hwgpio(desc), gcdev->watched_lines)) return NOTIFY_DONE; memset(&chg, 0, sizeof(chg)); @@ -949,9 +949,9 @@ static int lineinfo_changed_notify(struct notifier_block *nb, chg.timestamp = ktime_get_ns(); gpio_desc_to_lineinfo(desc, &chg.info); - ret = kfifo_in_spinlocked(&priv->events, &chg, 1, &priv->wait.lock); + ret = kfifo_in_spinlocked(&gcdev->events, &chg, 1, &gcdev->wait.lock); if (ret) - wake_up_poll(&priv->wait, EPOLLIN); + wake_up_poll(&gcdev->wait, EPOLLIN); else pr_debug_ratelimited("lineinfo event FIFO is full - event dropped\n"); @@ -961,13 +961,13 @@ static int lineinfo_changed_notify(struct notifier_block *nb, static __poll_t lineinfo_watch_poll(struct file *file, struct poll_table_struct *pollt) { - struct gpio_chardev_data *priv = file->private_data; + struct gpio_chardev_data *gcdev = file->private_data; __poll_t events = 0; - poll_wait(file, &priv->wait, pollt); + poll_wait(file, &gcdev->wait, pollt); - if (!kfifo_is_empty_spinlocked_noirqsave(&priv->events, - &priv->wait.lock)) + if (!kfifo_is_empty_spinlocked_noirqsave(&gcdev->events, + &gcdev->wait.lock)) events = EPOLLIN | EPOLLRDNORM; return events; @@ -976,7 +976,7 @@ static __poll_t lineinfo_watch_poll(struct file *file, static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, size_t count, loff_t *off) { - struct gpio_chardev_data *priv = file->private_data; + struct gpio_chardev_data *gcdev = file->private_data; struct gpioline_info_changed event; ssize_t bytes_read = 0; int ret; @@ -985,28 +985,28 @@ static ssize_t lineinfo_watch_read(struct file *file, char __user *buf, return -EINVAL; do { - spin_lock(&priv->wait.lock); - if (kfifo_is_empty(&priv->events)) { + spin_lock(&gcdev->wait.lock); + if (kfifo_is_empty(&gcdev->events)) { if (bytes_read) { - spin_unlock(&priv->wait.lock); + spin_unlock(&gcdev->wait.lock); return bytes_read; } if (file->f_flags & O_NONBLOCK) { - spin_unlock(&priv->wait.lock); + spin_unlock(&gcdev->wait.lock); return -EAGAIN; } - ret = wait_event_interruptible_locked(priv->wait, - !kfifo_is_empty(&priv->events)); + ret = wait_event_interruptible_locked(gcdev->wait, + !kfifo_is_empty(&gcdev->events)); if (ret) { - spin_unlock(&priv->wait.lock); + spin_unlock(&gcdev->wait.lock); return ret; } } - ret = kfifo_out(&priv->events, &event, 1); - spin_unlock(&priv->wait.lock); + ret = kfifo_out(&gcdev->events, &event, 1); + spin_unlock(&gcdev->wait.lock); if (ret != 1) { ret = -EIO; break; @@ -1031,33 +1031,33 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) { struct gpio_device *gdev = container_of(inode->i_cdev, struct gpio_device, chrdev); - struct gpio_chardev_data *priv; + struct gpio_chardev_data *gcdev; int ret = -ENOMEM; /* Fail on open if the backing gpiochip is gone */ if (!gdev->chip) return -ENODEV; - priv = kzalloc(sizeof(*priv), GFP_KERNEL); - if (!priv) + gcdev = kzalloc(sizeof(*gcdev), GFP_KERNEL); + if (!gcdev) return -ENOMEM; - priv->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL); - if (!priv->watched_lines) - goto out_free_priv; + gcdev->watched_lines = bitmap_zalloc(gdev->chip->ngpio, GFP_KERNEL); + if (!gcdev->watched_lines) + goto out_free_gcdev; - init_waitqueue_head(&priv->wait); - INIT_KFIFO(priv->events); - priv->gdev = gdev; + init_waitqueue_head(&gcdev->wait); + INIT_KFIFO(gcdev->events); + gcdev->gdev = gdev; - priv->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify; + gcdev->lineinfo_changed_nb.notifier_call = lineinfo_changed_notify; ret = atomic_notifier_chain_register(&gdev->notifier, - &priv->lineinfo_changed_nb); + &gcdev->lineinfo_changed_nb); if (ret) goto out_free_bitmap; get_device(&gdev->dev); - file->private_data = priv; + file->private_data = gcdev; ret = nonseekable_open(inode, file); if (ret) @@ -1067,11 +1067,11 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) out_unregister_notifier: atomic_notifier_chain_unregister(&gdev->notifier, - &priv->lineinfo_changed_nb); + &gcdev->lineinfo_changed_nb); out_free_bitmap: - bitmap_free(priv->watched_lines); -out_free_priv: - kfree(priv); + bitmap_free(gcdev->watched_lines); +out_free_gcdev: + kfree(gcdev); return ret; } @@ -1083,14 +1083,14 @@ static int gpio_chrdev_open(struct inode *inode, struct file *file) */ static int gpio_chrdev_release(struct inode *inode, struct file *file) { - struct gpio_chardev_data *priv = file->private_data; - struct gpio_device *gdev = priv->gdev; + struct gpio_chardev_data *gcdev = file->private_data; + struct gpio_device *gdev = gcdev->gdev; - bitmap_free(priv->watched_lines); + bitmap_free(gcdev->watched_lines); atomic_notifier_chain_unregister(&gdev->notifier, - &priv->lineinfo_changed_nb); + &gcdev->lineinfo_changed_nb); put_device(&gdev->dev); - kfree(priv); + kfree(gcdev); return 0; } From patchwork Tue Jun 23 04:00:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206702 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6764DC433E0 for ; Tue, 23 Jun 2020 04:02:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3DB1520771 for ; Tue, 23 Jun 2020 04:02:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fstrr9mr" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732195AbgFWECq (ORCPT ); Tue, 23 Jun 2020 00:02:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42230 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWECp (ORCPT ); Tue, 23 Jun 2020 00:02:45 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AAEAC061573; Mon, 22 Jun 2020 21:02:44 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id x207so9466820pfc.5; Mon, 22 Jun 2020 21:02:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nzaq3qZVu2Gim6Ue9JBZzYGe5RkH/apAgxYfSIfcbgo=; b=Fstrr9mriVf+g2keRIPob2sQ05/tmZT3gNrFb4/ar5aOG9cMCDq3hReGwRA8YwIoTC EAynf0T+tdO8SZ7sb1zKqMwUKvizG9Rmb0ikr1bQ0xkG6mnoRCD2YS7RwvDupA5anbgi UKrIrblsLfFFDllhS0NLw1P59qDz4jC+Y3NaKpG9DBVQUZahlqHm9GvLqG3q6mpXuee5 FRPCpCQnqhXkpEuDX8Z5k+6bsvhmUwjYulV2JNDwp0cmWgt+VKNLg8/ENeQLjvPFYN7L psasveyNfCjiuaJ5F07jH0a5rvpDTK74bYkc7Q2gayteX17gEGePiu1lwhFMIGNVVYhv l3ig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nzaq3qZVu2Gim6Ue9JBZzYGe5RkH/apAgxYfSIfcbgo=; b=HQdKntoEe9i92urLm2Aq2FC/ojQlQ/42vID5Zhp8L8/adEaZ5aX6XLAsJsxzZmqWPb PSopJRoCKMCKbXCUKZvO3D9Ej4vZqBnR1jN3qFvUMz8wyvQna/yQzVoKvU2hi5UkDHTI 6trUSxpD5vuNZE6wzjmHV9ZpDUiF3NgM11sMUIrskczXQj+9Y5dl4oQYTnv6n8x+nY2n iz9EHM2/nW5CjqcJWmbeJ9G/2pd+OFC0MS6dAcWPxsFsOEsLYKpuzE1XzzDuU0zGKVLp xyaZ7jL36FO6maQXGCsyrWaBgN8Q8H1HNBR7lUGFUMuTZdCgEQj1KT+GCRLzDCwTVdBW QTXw== X-Gm-Message-State: AOAM531F0kwpRj7txUJfAYqN50bm0Te8JuCpsmHXqmqjfEKPKUSD0r9Z NYK5HHvjZY20v8cbY4fVKjZwaDNGJyg= X-Google-Smtp-Source: ABdhPJwhW68x8f2vgSxdGhNtv5Baqw5YoqFE8D92KDC2M6rlLYB0laLS+UeRBoZRiFSC1nzGaCZLVQ== X-Received: by 2002:a63:4f1b:: with SMTP id d27mr15221665pgb.389.1592884963500; Mon, 22 Jun 2020 21:02:43 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.02.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:02:42 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 11/22] gpiolib: cdev: remove recalculation of offset Date: Tue, 23 Jun 2020 12:00:56 +0800 Message-Id: <20200623040107.22270-12-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Remove recalculation of offset from desc, where desc itself was calculated from offset. There is no benefit from for the desc -> hwgpio conversion in this context. The only implicit benefit of the offset -> desc -> hwgpio is the range check in the offset -> desc, but where desc is required you still get that, and where desc isn't required it is simpler to perform the range check directly. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index a727709b24a9..b6878fc87dfc 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -834,7 +834,6 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) void __user *ip = (void __user *)arg; struct gpio_desc *desc; __u32 offset; - int hwgpio; /* We fail any subsequent ioctl():s when the chip is gone */ if (!gc) @@ -862,12 +861,11 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) return -EFAULT; + /* this doubles as a range check on line_offset */ desc = gpiochip_get_desc(gc, lineinfo.line_offset); if (IS_ERR(desc)) return PTR_ERR(desc); - hwgpio = gpio_chip_hwgpio(desc); - gpio_desc_to_lineinfo(desc, &lineinfo); if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) @@ -883,13 +881,12 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_from_user(&lineinfo, ip, sizeof(lineinfo))) return -EFAULT; + /* this doubles as a range check on line_offset */ desc = gpiochip_get_desc(gc, lineinfo.line_offset); if (IS_ERR(desc)) return PTR_ERR(desc); - hwgpio = gpio_chip_hwgpio(desc); - - if (test_and_set_bit(hwgpio, gcdev->watched_lines)) + if (test_and_set_bit(lineinfo.line_offset, gcdev->watched_lines)) return -EBUSY; gpio_desc_to_lineinfo(desc, &lineinfo); @@ -902,13 +899,10 @@ static long gpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg) if (copy_from_user(&offset, ip, sizeof(offset))) return -EFAULT; - desc = gpiochip_get_desc(gc, offset); - if (IS_ERR(desc)) - return PTR_ERR(desc); - - hwgpio = gpio_chip_hwgpio(desc); + if (offset >= gcdev->gdev->ngpio) + return -EINVAL; - if (!test_and_clear_bit(hwgpio, gcdev->watched_lines)) + if (!test_and_clear_bit(offset, gcdev->watched_lines)) return -EBUSY; return 0; From patchwork Tue Jun 23 04:00:58 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206701 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CE7DC433DF for ; Tue, 23 Jun 2020 04:02:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DB58920771 for ; Tue, 23 Jun 2020 04:02:57 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="U3WFDIBb" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732220AbgFWEC5 (ORCPT ); Tue, 23 Jun 2020 00:02:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42266 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWEC4 (ORCPT ); Tue, 23 Jun 2020 00:02:56 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EC77C061573; Mon, 22 Jun 2020 21:02:55 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id e8so4024096pgc.5; Mon, 22 Jun 2020 21:02:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2AZsp8B5EAOcfJRQD3uK7WPYxA3PQSyoF4tFq5kvAXw=; b=U3WFDIBbjXqFOrETuTX7ceOVXTxK8CWwu0iSBAetFziHgOP8CHV18qo9H+pTQjKFh2 PCyNxaOA93gt5UUpG9GLSfrnuS/O3uwDyb21aE91TIK1+Z/1gsJdNYa40VX+73fU7Ro0 8KbmRx4AJieIMlJez8RnHFQsHDgXNnE4vvuz7uD+08BJxrKLo2tKt88rJpQqSyKsV1sp D7DQmfWC6S2qvQ5TUmPsRLxZRdnE5GOeR4uqtDgg1HNHGaHXvKIhKSu+CZ78mei9BJ6I bqBg/pXF9kR3q2F1PSLQc3bGsNnB/NXe0k5JDbVfdg69e/ceuzMq7F3v2tGNf4loAC8w 4XVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2AZsp8B5EAOcfJRQD3uK7WPYxA3PQSyoF4tFq5kvAXw=; b=qZSiG03C3s2E8oqHUl65CD+rWA5Q5YV4R3mZBtCv0KIfvrLQjMXReL/fU2bp1pvfL9 4IYH4u8vD7TudjSp4oB/CE3V990/3FPNE+1Ske9M7hUPCuAwS0CKLLi0jkNlYT5aQTvE Mf0kDphEH45DLrJkemXY2dOb8u20rWkPtOiLfqoFKVvwc1NaJU94Au2SzeFbJikZ7CMg M7xRZ+T2rzNxny3WZiLnwr+ChuALwZe+zE5FDI6heQ6QUAONShs7u7qe436l+S7RoC10 tP9iDefgsRdqj8kHBHJAqkkxwlQkZXk2gg9rw4XQfblbGQAYS7o6CgXvkcAKmQS+Ixp0 boYw== X-Gm-Message-State: AOAM531LqlkrBYgmI9lW12xsx1lyEYyiHhbNkDBxFNlPvQIa9uc21SRo 6SdwjHygaPKhtKD9j6rVc2V887qX90M= X-Google-Smtp-Source: ABdhPJwu5I6KD8Wd2eDOoth8T5uB/L2Vt5xF6O14xQAkeYYWaKaADkqcDhLGae5keZpVx2JWvQR/xQ== X-Received: by 2002:a63:ec44:: with SMTP id r4mr15669063pgj.11.1592884973973; Mon, 22 Jun 2020 21:02:53 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:02:53 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 13/22] gpio: uapi: define uAPI V2 Date: Tue, 23 Jun 2020 12:00:58 +0800 Message-Id: <20200623040107.22270-14-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a new version of the uAPI to address existing 32/64bit alignment issues, add support for debounce and event sequence numbers, and provide some future proofing by adding padding reserved for future use. The alignment issue relates to the gpioevent_data, which packs to different sizes on 32bit and 64bit platforms. That creates problems for 32bit apps running on 64bit kernels. The patch addresses that particular issue, and the problem more generally, by adding pad fields that explicitly pad structs out to 64bit boundaries, so they will pack to the same size now, and even if some of the reserved padding is used for __u64 fields in the future. The lack of future proofing in V1 makes it impossible to, for example, add the debounce feature that is included in v2. The future proofing is addressed by providing reserved padding in all structs for future features. Specifically, the line request, config, info, info_changed and event structs receive updated versions, and the first three new ioctls. Signed-off-by: Kent Gibson --- I haven't added any padding to gpiochip_info, as I haven't seen any calls for new features for the corresponding ioctl, but I'm open to updating that as well. As the majority of the structs and ioctls were being replaced, it seemed opportune to rework some of the other aspects of the uAPI. Firstly, I've reworked the flags field throughout. V1 has three different flags fields, each with their own separate bit definitions. In V2 that is collapsed to one. Further, the bits of the V2 flags field are used as feature enable flags, with any other necessary configuration fields encoded separately. This is simpler and clearer, while also providing a foundation for adding features in the future. I've also merged the handle and event requests into a single request, the line request, as the two requests where mostly the same, other than the edge detection provided by event requests. As a byproduct, the V2 uAPI allows for multiple lines producing edge events on the same line handle. This is a new capability as V1 only supports a single line in an event request. This means there are now only two types of file handle to be concerned with, the chip and the line, and it is clearer which ioctls apply to which type of handle. There is also some minor renaming of fields for consistency compared to their V1 counterparts, e.g. offset rather than lineoffset or line_offset, and consumer rather than consumer_label. Additionally, V1 GPIOHANDLES_MAX becomes GPIOLINES_MAX in V2 for clarity, and the gpiohandle_data __u8 array becomes a bitmap gpioline_values. The V2 uAPI is mostly just a reorganisation of V1, so userspace code, particularly libgpiod, should easily port to it. The padding sizes have been carried over from the RFC version, although the seqnos added to the gpioline_event alone would've used the all of the padding for that struct, had they not been added here. So I'm moderatly concerned that those values are too small due to a lack of imagination on may part and should be increased to decrease the probability of running out of space in the padding and requiring creative solutions or even a V3. Changes since the RFC: - document the constraints on array sizes to maintain 32/64 alignment - add sequence numbers to gpioline_event - use bitmap for values instead of array of __u8 - gpioline_info_v2 contains gpioline_config instead of its composite fields - provide constants for all array sizes, especially padding - renamed "GPIOLINE_FLAG_V2_KERNEL" to "GPIOLINE_FLAG_V2_USED" - renamed "default_values" to "values" - made gpioline_direction zero based - document clock used in gpioline_event timestamp - add event_buffer_size to gpioline_request include/uapi/linux/gpio.h | 237 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 230 insertions(+), 7 deletions(-) diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h index 4e1139ab25bc..e4ed6f79e332 100644 --- a/include/uapi/linux/gpio.h +++ b/include/uapi/linux/gpio.h @@ -11,11 +11,14 @@ #ifndef _UAPI_GPIO_H_ #define _UAPI_GPIO_H_ +#include #include #include /* * The maximum size of name and label arrays. + * + * Must be a multiple of 8 to ensure 32/64bit alignment of structs. */ #define GPIO_MAX_NAME_SIZE 32 @@ -32,6 +35,211 @@ struct gpiochip_info { __u32 lines; }; +/* + * Maximum number of requested lines. + * + * Must be a multiple of 8 to ensure 32/64bit alignment of structs. + */ +#define GPIOLINES_MAX 64 + +/* the number of __u64 required for a bitmap for GPIOLINES_MAX lines */ +#define GPIOLINES_BITMAP_SIZE __KERNEL_DIV_ROUND_UP(GPIOLINES_MAX, 64) + +enum gpioline_direction { + GPIOLINE_DIRECTION_INPUT = 0, + GPIOLINE_DIRECTION_OUTPUT = 1, +}; + +enum gpioline_drive { + GPIOLINE_DRIVE_PUSH_PULL = 0, + GPIOLINE_DRIVE_OPEN_DRAIN = 1, + GPIOLINE_DRIVE_OPEN_SOURCE = 2, +}; + +enum gpioline_bias { + GPIOLINE_BIAS_DISABLED = 0, + GPIOLINE_BIAS_PULL_UP = 1, + GPIOLINE_BIAS_PULL_DOWN = 2, +}; + +enum gpioline_edge { + GPIOLINE_EDGE_NONE = 0, + GPIOLINE_EDGE_RISING = 1, + GPIOLINE_EDGE_FALLING = 2, + GPIOLINE_EDGE_BOTH = 3, +}; + +/* Line flags - V2 */ +#define GPIOLINE_FLAG_V2_USED (1UL << 0) /* line is not available for request */ +#define GPIOLINE_FLAG_V2_ACTIVE_LOW (1UL << 1) +#define GPIOLINE_FLAG_V2_DIRECTION (1UL << 2) +#define GPIOLINE_FLAG_V2_DRIVE (1UL << 3) +#define GPIOLINE_FLAG_V2_BIAS (1UL << 4) +#define GPIOLINE_FLAG_V2_EDGE_DETECTION (1UL << 5) +#define GPIOLINE_FLAG_V2_DEBOUNCE (1UL << 6) + +/* + * Struct padding sizes. + * + * These are sized to pad structs to 64bit boundaries. + * To maintain 32/64bit alignment, any arbitrary change must be even, as + * the pad elements are __u32. + */ +#define GPIOLINE_CONFIG_PAD_SIZE 7 +#define GPIOLINE_REQUEST_PAD_SIZE 5 +#define GPIOLINE_INFO_V2_PAD_SIZE 5 +#define GPIOLINE_INFO_CHANGED_V2_PAD_SIZE 5 +#define GPIOLINE_EVENT_PAD_SIZE 2 + +/** + * struct gpioline_values - Values of GPIO lines + * @bitmap: a bitmap containing the value of the lines, set to 1 for active + * and 0 for inactive. Note that this is the logical value, which will be + * the opposite of the physical value if GPIOLINE_FLAG_V2_ACTIVE_LOW is + * set in flags. + */ +struct gpioline_values { + __u64 bitmap[GPIOLINES_BITMAP_SIZE]; +}; + +/** + * struct gpioline_config - Configuration for GPIO lines + * @values: if the direction is GPIOLINE_DIRECTION_OUTPUT, the values that + * the lines will be set to. This field is write-only and is zeroed when + * returned within struct gpioline_info. + * @flags: flags for the GPIO lines, such as GPIOLINE_FLAG_V2_ACTIVE_LOW, + * GPIOLINE_FLAG_V2_DIRECTION etc, OR:ed together + * @direction: if GPIOLINE_FLAG_V2_DIRECTION is set in flags, the desired + * direction for the requested lines, with a value from enum + * gpioline_direction + * @drive: if GPIOLINE_FLAG_V2_DRIVE is set in flags, the desired drive for + * the requested lines, with a value from enum gpioline_drive + * @bias: if GPIOLINE_FLAG_V2_BIAS is set in flags, the desired bias for + * the requested lines, with a value from enum gpioline_bias + * @edge_detection: if GPIOLINE_FLAG_V2_EDGE_DETECTION is set in flags, the + * desired edge_detection for the requested lines, with a value from enum + * gpioline_edge + * @debounce_period: if GPIOLINE_FLAG_V2_DEBOUNCE is set in flags, the + * desired debounce period for the requested lines, in microseconds + * @padding: reserved for future use and must be zero filled + */ +struct gpioline_config { + struct gpioline_values values; + __u32 flags; + /* Note that the following four fields are equivalent to a single u32. */ + __u8 direction; + __u8 drive; + __u8 bias; + __u8 edge_detection; + __u32 debounce_period; + __u32 padding[GPIOLINE_CONFIG_PAD_SIZE]; /* for future use */ +}; + +/** + * struct gpioline_request - Information about a request for GPIO lines + * @offsets: an array of desired lines, specified by offset index for the + * associated GPIO device + * @consumer: a desired consumer label for the selected GPIO lines such as + * "my-bitbanged-relay" + * @config: requested configuration for the requested lines. Note that even + * if multiple lines are requested, the same configuration must be + * applicable to all of them. If you want lines with individual + * configuration, request them one by one. It is possible to select a batch + * of input or output lines, but they must all have the same configuration, + * i.e. all inputs or all outputs, all active low etc + * @num_lines: number of lines requested in this request, i.e. the number + * of valid fields in the GPIOLINES_MAX sized arrays, set to 1 to request a + * single line + * @event_buffer_size: a suggested minimum number of line events that the + * kernel should buffer. This is only relevant if edge_detection is + * enabled. Note that this is only a suggested value and the kernel may + * allocate a larger buffer or cap the size of the buffer. If this field is + * zero then the buffer size defaults to a minimum of num_lines*16. + * @padding: reserved for future use and must be zero filled + * @fd: if successful this field will contain a valid anonymous file handle + * after a GPIO_GET_LINE_IOCTL operation, zero or negative value means + * error + */ +struct gpioline_request { + __u32 offsets[GPIOLINES_MAX]; + char consumer[GPIO_MAX_NAME_SIZE]; + struct gpioline_config config; + __u32 num_lines; + __u32 event_buffer_size; + __u32 padding[GPIOLINE_REQUEST_PAD_SIZE]; /* for future use */ + __s32 fd; +}; + +/** + * struct gpioline_info_v2 - Information about a certain GPIO line + * @name: the name of this GPIO line, such as the output pin of the line on + * the chip, a rail or a pin header name on a board, as specified by the + * gpio chip, may be empty + * @consumer: a functional name for the consumer of this GPIO line as set + * by whatever is using it, will be empty if there is no current user but + * may also be empty if the consumer doesn't set this up + * @config: the configuration of the line. Note that the values field is + * always zeroed - the line must be requested to read the values. + * @offset: the local offset on this GPIO device, fill this in when + * requesting the line information from the kernel + * @padding: reserved for future use + */ +struct gpioline_info_v2 { + char name[GPIO_MAX_NAME_SIZE]; + char consumer[GPIO_MAX_NAME_SIZE]; + struct gpioline_config config; + __u32 offset; + __u32 padding[GPIOLINE_INFO_V2_PAD_SIZE]; /* for future use */ +}; + +/** + * struct gpioline_info_changed_v2 - Information about a change in status + * of a GPIO line + * @info: updated line information + * @timestamp: estimate of time of status change occurrence, in nanoseconds + * and GPIOLINE_CHANGED_CONFIG + * @event_type: one of GPIOLINE_CHANGED_REQUESTED, GPIOLINE_CHANGED_RELEASED + * @padding: reserved for future use + */ +struct gpioline_info_changed_v2 { + struct gpioline_info_v2 info; + __u64 timestamp; + __u32 event_type; + __u32 padding[GPIOLINE_INFO_CHANGED_V2_PAD_SIZE]; /* for future use */ +}; + +enum gpioline_event_id { + GPIOLINE_EVENT_RISING_EDGE = 1, + GPIOLINE_EVENT_FALLING_EDGE = 2, +}; + +/** + * struct gpioline_event - The actual event being pushed to userspace + * @timestamp: best estimate of time of event occurrence, in nanoseconds. + * The timestamp is read from CLOCK_MONOTONIC and is intended to allow the + * accurate measurement of the time between events. It does not provide + * the wall-clock time. + * @id: event identifier with value from enum gpioline_event_id + * @offset: the offset of the line that triggered the event + * @seqno: the sequence number for this event in the sequence of events for + * all the lines in this line request + * @line_seqno: the sequence number for this event in the sequence of + * events on this particular line + * @padding: reserved for future use + */ +struct gpioline_event { + __u64 timestamp; + __u32 id; + __u32 offset; + __u32 seqno; + __u32 line_seqno; + __u32 padding[GPIOLINE_EVENT_PAD_SIZE]; /* for future use */ +}; + +/* + * ABI V1 + */ + /* Informational flags */ #define GPIOLINE_FLAG_KERNEL (1UL << 0) /* Line used by the kernel */ #define GPIOLINE_FLAG_IS_OUT (1UL << 1) @@ -149,8 +357,6 @@ struct gpiohandle_config { __u32 padding[4]; /* padding for future use */ }; -#define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0a, struct gpiohandle_config) - /** * struct gpiohandle_data - Information of values on a GPIO handle * @values: when getting the state of lines this contains the current @@ -161,9 +367,6 @@ struct gpiohandle_data { __u8 values[GPIOHANDLES_MAX]; }; -#define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) -#define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) - /* Eventrequest flags */ #define GPIOEVENT_REQUEST_RISING_EDGE (1UL << 0) #define GPIOEVENT_REQUEST_FALLING_EDGE (1UL << 1) @@ -207,11 +410,31 @@ struct gpioevent_data { __u32 id; }; +/* + * V1 and V2 ioctl()s + */ #define GPIO_GET_CHIPINFO_IOCTL _IOR(0xB4, 0x01, struct gpiochip_info) +#define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0C, __u32) + +/* + * V2 ioctl()s + */ +#define GPIO_GET_LINEINFO_V2_IOCTL _IOWR(0xB4, 0x05, struct gpioline_info_v2) +#define GPIO_GET_LINEINFO_WATCH_V2_IOCTL _IOWR(0xB4, 0x06, struct gpioline_info_v2) +#define GPIO_GET_LINE_IOCTL _IOWR(0xB4, 0x07, struct gpioline_request) +#define GPIOLINE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0D, struct gpioline_config) +#define GPIOLINE_GET_VALUES_IOCTL _IOWR(0xB4, 0x0E, struct gpioline_values) +#define GPIOLINE_SET_VALUES_IOCTL _IOWR(0xB4, 0x0F, struct gpioline_values) + +/* + * V1 ioctl()s + */ #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) -#define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0b, struct gpioline_info) -#define GPIO_GET_LINEINFO_UNWATCH_IOCTL _IOWR(0xB4, 0x0c, __u32) #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_request) #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_request) +#define GPIOHANDLE_GET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x08, struct gpiohandle_data) +#define GPIOHANDLE_SET_LINE_VALUES_IOCTL _IOWR(0xB4, 0x09, struct gpiohandle_data) +#define GPIOHANDLE_SET_CONFIG_IOCTL _IOWR(0xB4, 0x0A, struct gpiohandle_config) +#define GPIO_GET_LINEINFO_WATCH_IOCTL _IOWR(0xB4, 0x0B, struct gpioline_info) #endif /* _UAPI_GPIO_H_ */ From patchwork Tue Jun 23 04:01:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206700 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 486B0C433E0 for ; Tue, 23 Jun 2020 04:03:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25BA320780 for ; Tue, 23 Jun 2020 04:03:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="e84N9oOB" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732263AbgFWEDG (ORCPT ); Tue, 23 Jun 2020 00:03:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42294 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726429AbgFWEDF (ORCPT ); Tue, 23 Jun 2020 00:03:05 -0400 Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF033C061573; Mon, 22 Jun 2020 21:03:04 -0700 (PDT) Received: by mail-pg1-x543.google.com with SMTP id e9so9248079pgo.9; Mon, 22 Jun 2020 21:03:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tbZllv0rRwEivahkEluEWQ/Pj7zSjYlN1BX1CxBYQQM=; b=e84N9oOBnqb+4n4u59arGHa3p5I4/5W2OsPXIT+5Jot8ldKYCJUc2hjt//QncEU8j0 VXkbaxb7ovUDL+wKvzDgvg18ZShJjNqaW5/rs6W7pWV15WamI2WEJNYcXtlBgI1OFmeg BNoH/yEnuY7quRhYDbtsKlaqnt+L/zMO2+1pls1w7P4Y6fB+5YICAIQDZ1Hzj/PeZD7M LphCSLN4azyz7GGYHSGeSdXi9lH8jtZpQz0Ls1VbI1E7zn75RpqUrNE6wV//jI7fUTse cS6FZ8ELqF8y1PLEK+e6Pe0xvo/myOvZZ41yCov6+HxAndZafpiI4qZSbXJafdr5AYdJ 4CIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=tbZllv0rRwEivahkEluEWQ/Pj7zSjYlN1BX1CxBYQQM=; b=QSCqiq6lcvyexhlM4HeuL9fF/DCKj8aMqh2B6TnUUp/4xfG0uW8/EAjwstaCwp3bkx m502ONz/7Dyf5DvWm5S8d1TKwrUByF7/Z/kepWTq7PiXETG9qBA0FxMDlbwDbOi1srvQ d3ggWnI967RW55ednqKTwcQynDH2juWiS6aDRoypiwdmrfNrQMjvlG57MM1aw51OYEE2 reZrSSa+anfKL2dYazpTGwlgPPaIk7RiPkBz/WA2rAkqwya9EIvXKpqGiuYlwUIxExJH GKBbjXXZx/qnVO0ySIVzPXIAIRPUtWvPEbSz/G/i7qDy9gfesqnoVIOWA0bBRnQ0RYbw QBGw== X-Gm-Message-State: AOAM531JNDRh1FKGdmMp/DZG13XYcQaYxO3A8hsFmfCAggBcPxg5y9GK XR4+FLf2rpoQho3ea8BQ6F7eL0RIeMM= X-Google-Smtp-Source: ABdhPJwggx/avAGtNm8/B4ywLETEDIJs4dCQ5hU/6NyEotJx4VlaX3B03YznA2bZJi3xWc/l7M6uww== X-Received: by 2002:aa7:8a51:: with SMTP id n17mr724558pfa.89.1592884983553; Mon, 22 Jun 2020 21:03:03 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.03.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:03:02 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 15/22] gpiolib: add build option for CDEV V1 ABI Date: Tue, 23 Jun 2020 12:01:00 +0800 Message-Id: <20200623040107.22270-16-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add a build option to allow the removal of the CDEV v1 ABI. Suggested-by: Bartosz Golaszewski Signed-off-by: Kent Gibson --- This patch is before the V2 implementation, and is non-functional until that patch, as some parts of that patch would be written slightly differently if removing V1 was not considered. Adding this patch after that would necessitate revisiting the V2 changes, so this ordering results in two simpler patches. drivers/gpio/Kconfig | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index affc1524bc2c..b966a7dc1c9a 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -81,6 +81,18 @@ config GPIO_CDEV If unsure, say Y. +config GPIO_CDEV_V1 + bool "Support GPIO ABI Version 1" + default y + depends on GPIO_CDEV + help + Say Y here to support version 1 of the GPIO CDEV ABI. + + This ABI version is deprecated and will be removed in the future. + Please use the latest ABI for new developments. + + If unsure, say Y. + config GPIO_GENERIC depends on HAS_IOMEM # Only for IOMEM drivers tristate From patchwork Tue Jun 23 04:01:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206699 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB5E8C433E0 for ; Tue, 23 Jun 2020 04:03:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 96856207BC for ; Tue, 23 Jun 2020 04:03:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="QMxmJuYD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732344AbgFWEDW (ORCPT ); Tue, 23 Jun 2020 00:03:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732320AbgFWEDP (ORCPT ); Tue, 23 Jun 2020 00:03:15 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AFD0C061573; Mon, 22 Jun 2020 21:03:14 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id b7so646056pju.0; Mon, 22 Jun 2020 21:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gIH44XP+3+d8u/o5onM5jscJ417kAbas5Jl16ovp4QI=; b=QMxmJuYDSsMGB3THi0GFjsWzTVsTtKNeQWjpu++s0JBZgTJw/d9Z0lRU3ljYQjn5Hs 08t5p8tjLUQvSV9s4enh2kw6ex9rvCfKwyXyzEnxHmti3gsye2etzlNYyAaAcVhOw+iu tpKfQsXSZOQnWWlw/WxtOr6VI6i9yb2CfXW+nTnZJKfRiWSo2/i6u1pLvQWRhkUHDPRp 10FXo2Ms2sqVIUI/W0WTMwwmdi/6lZAuzS5ccLslonZInG716q9FPSLSHZLcLOHl5xHd iQnuzSEonnFrGbwOjuGPL3+ysZwnKqwkFyus8RNepnYWwAp0xsg8Na5FtgS6jePCHJrF hIjQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gIH44XP+3+d8u/o5onM5jscJ417kAbas5Jl16ovp4QI=; b=lEAADc/LMFgY4MKn3UVXtlehKQSBirBxtIAvO6ejfWSXP0Yf7wcH/InJjXoU2F+HEV FzF8IECnjyViLqn0V4GCs4fvxzyfYlg+4+HRpCbui/PyA3TFthNrOKEKp61ISLTOKDLp p9NiqVMmMwRIFJncCZteIC4/O1vcTDyTBehwXH/CMNVIST81JzPG0ltFmnWGTsXupCnO iBzxggLED3Y6sW/yeKpF8s+/cgaDOhH/nXTBGGf4k8SLJYPO6QmH0kFrZTP4+gwau3SN zEx6EYCguco5k2CSlzHxhmuqOYy2/VdBnQCLeZG/9UpNw4NlTfDN6y49YXvK2WMY13Kf TrCw== X-Gm-Message-State: AOAM533fK+4lUAQRgrU6twSsJT1y3KXqoCS9jjFcpIMnN1PHtbHuk4VI rKKzH3tibRYuaPY2nqaJXL6KfksVfss= X-Google-Smtp-Source: ABdhPJyGwaSdjarOKsLbDjq6OvTWMzjLgHBCihVIyMjePQDTnc7tAGJ3lTxKgumy0S5EiUEDeKqNHw== X-Received: by 2002:a17:90a:5c85:: with SMTP id r5mr21583673pji.40.1592884993354; Mon, 22 Jun 2020 21:03:13 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.03.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:03:12 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 17/22] gpiolib: cdev: report edge detection in lineinfo Date: Tue, 23 Jun 2020 12:01:02 +0800 Message-Id: <20200623040107.22270-18-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Report the state of edge detection for a line in the gpioline_info_v2 returned by GPIO_GET_LINEINFO_V2_IOCTL, and indirectly for lines watched by GPIO_GET_LINEINFO_WATCH_V2_IOCTL. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib-cdev.c | 14 ++++++++++++++ drivers/gpio/gpiolib.c | 2 ++ drivers/gpio/gpiolib.h | 2 ++ 3 files changed, 18 insertions(+) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index d4a22d78953f..7ba0929b2741 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -566,6 +566,12 @@ static void edge_detector_stop(struct edge_detector *edet) static int edge_detector_setup(struct edge_detector *edet, struct gpioline_config *lc) { + struct gpio_desc *desc = edge_detector_desc(edet); + + if (lc->edge_detection & GPIOLINE_EDGE_RISING) + set_bit(FLAG_EDGE_RISING, &desc->flags); + if (lc->edge_detection & GPIOLINE_EDGE_FALLING) + set_bit(FLAG_EDGE_FALLING, &desc->flags); if (lc->edge_detection) return edge_detector_start(edet); return 0; @@ -1574,6 +1580,14 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, } lc->edge_detection = 0; + if (test_bit(FLAG_EDGE_RISING, &desc->flags)) { + lc->flags |= GPIOLINE_FLAG_V2_EDGE_DETECTION; + lc->edge_detection |= GPIOLINE_EDGE_RISING; + } + if (test_bit(FLAG_EDGE_FALLING, &desc->flags)) { + lc->flags |= GPIOLINE_FLAG_V2_EDGE_DETECTION; + lc->edge_detection |= GPIOLINE_EDGE_FALLING; + } spin_unlock_irqrestore(&gpio_lock, flags); } diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 517c99ddf6c8..a5f2795e17b7 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2041,6 +2041,8 @@ static bool gpiod_free_commit(struct gpio_desc *desc) clear_bit(FLAG_PULL_UP, &desc->flags); clear_bit(FLAG_PULL_DOWN, &desc->flags); clear_bit(FLAG_BIAS_DISABLE, &desc->flags); + clear_bit(FLAG_EDGE_RISING, &desc->flags); + clear_bit(FLAG_EDGE_FALLING, &desc->flags); clear_bit(FLAG_IS_HOGGED, &desc->flags); #ifdef CONFIG_OF_DYNAMIC desc->hog = NULL; diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 2dee4e1e12dc..1dc6d2b191af 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -114,6 +114,8 @@ struct gpio_desc { #define FLAG_PULL_UP 13 /* GPIO has pull up enabled */ #define FLAG_PULL_DOWN 14 /* GPIO has pull down enabled */ #define FLAG_BIAS_DISABLE 15 /* GPIO has pull disabled */ +#define FLAG_EDGE_RISING 16 /* GPIO CDEV detects rising edge events */ +#define FLAG_EDGE_FALLING 17 /* GPIO CDEV detects falling edge events */ /* Connection label */ const char *label; From patchwork Tue Jun 23 04:01:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206697 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5533BC433E0 for ; Tue, 23 Jun 2020 04:03:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FB6620780 for ; Tue, 23 Jun 2020 04:03:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="VkLy13ZN" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732402AbgFWEDc (ORCPT ); Tue, 23 Jun 2020 00:03:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732284AbgFWEDU (ORCPT ); Tue, 23 Jun 2020 00:03:20 -0400 Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3ED24C061573; Mon, 22 Jun 2020 21:03:19 -0700 (PDT) Received: by mail-pj1-x1041.google.com with SMTP id u14so909724pjj.2; Mon, 22 Jun 2020 21:03:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=fYd2xDtZ/gT4nGQ+DH72waIo+BDMGiUqgjNK04Ollrc=; b=VkLy13ZN5KCoSgqz+wCZ40imjpv4DgE7vh9qJkSQ10VFPKln0gbsyTFg9SPvrYWr8R Ie4vbfxSDyxH2+0nimG3MC41uAoAyYGaxwpJJw+i1BITorQ54cHtjNB0LO1LC4igk8qu oE4UMtGJIFtYLwxVamb3RRZ6lFobYKreT55dpJLMg02rUcw0JOsGEUy8uJF6nLu1Cs7f UaLN5PA69QcZbVggpkSbEWyEdkieMELIYJdvcV1gTTntq2y2eN7A9NAeQ/8n5yyvkGjs Dx8615eMDTIx0OiB9I+kToRTU8DNJTh530tundjKDNq2vCHyyExIt41cJfkJTKtinO3+ Ll1g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fYd2xDtZ/gT4nGQ+DH72waIo+BDMGiUqgjNK04Ollrc=; b=ME2yqPa+4ELowXWdjWCWevaWZ7pBd2EUBVake9Mp0hyyNuqt5j01R12Axmjd7My8JA xmEE2Fvvvdto5NB7BxUiRGwayxz5cdCrTniVTq6zmXj3dJxKy8Ra4GnAtv/c7blmihL+ 2mEFIBbBUkT5JiLLoy8cG8VXbfHikUHStZxt9f3pTfzumhgTFGK0K8w/QUUTQHbhV+yT vwGWDXcr5lZ5dYjHVg1df3BYx0nBoOpweo2AsyxfdJmfGunz/iczXNreh5cr++CdW8Zk 09ruydv01ZleZMMt4/4VDsI6U/yC188zfx+Rju1TOj96i1CrT8Gen+bFhlqhQufI1Shj EPug== X-Gm-Message-State: AOAM533QoEc6gdm/Bwid8ym1U/y5HatPNhvcTya9lc7G2w3y/UPgbfLR h2V8YyL9RI1dhaLlxZaszFxJ7gD4Pqc= X-Google-Smtp-Source: ABdhPJwino7TIgvkhsCvizFenLg+ibt1OpX4kaCGwm2m5v9xLjXkMkWAIOmygzbh2MkyKoF0cxW8bg== X-Received: by 2002:a17:902:a40c:: with SMTP id p12mr15361233plq.150.1592884998166; Mon, 22 Jun 2020 21:03:18 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.03.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:03:17 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 18/22] gpiolib: cdev: support setting debounce Date: Tue, 23 Jun 2020 12:01:03 +0800 Message-Id: <20200623040107.22270-19-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for setting debounce on a line via the GPIO uAPI. Where debounce is not supported by hardware, a software debounce is provided. Signed-off-by: Kent Gibson --- The implementation of the software debouncer waits for the line to be stable for the debounce period before determining if a level change, and a corresponding edge event, has occurred. This provides maximum protection against glitches, but also introduces a debounce_period latency to edge events. The software debouncer is integrated with the edge detection as it utilises the line interrupt, and integration is simpler than getting the two to interwork. Where software debounce AND edge detection is required, the debouncer provides both. Due to the tight integration between the debouncer and edge detection, and to avoid particular corner cases, it is not allowed to alter the debounce value if edge detection is enabled. Shanging the debounce with edge detection enabled is a very unlikely use case, so it is preferable to disallow it rather than complicate the code to allow it. Should the user wish to alter the debounce value in such cases they will need to release and re-aquire the line. drivers/gpio/gpiolib-cdev.c | 212 +++++++++++++++++++++++++++++++++++- drivers/gpio/gpiolib.h | 4 + 2 files changed, 214 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c index 7ba0929b2741..81c2fc4f0e49 100644 --- a/drivers/gpio/gpiolib-cdev.c +++ b/drivers/gpio/gpiolib-cdev.c @@ -394,6 +394,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) * for the corresponding line request. Ths is drawn from the @line. * @line_seqno: the seqno for the current edge event in the sequence of * events for this line. + * @sw_debounced: flag indicating if the software debouncer is active + * @work: the worker that implements software debouncing + * @level: the current debounced physical level of the line */ struct edge_detector { struct line *line; @@ -404,7 +407,15 @@ struct edge_detector { */ u64 timestamp; u32 seqno; + /* + * line_seqno is used by either edge_irq_thread or debounce_work_func + * which are themselves mutually exclusive. + */ u32 line_seqno; + /* debouncer specific fields */ + atomic_t sw_debounced; + struct delayed_work work; + atomic_t level; }; /** @@ -524,6 +535,10 @@ static int edge_detector_start(struct edge_detector *edet) int ret, irq, irqflags = 0; struct gpio_desc *desc; + if (atomic_read(&edet->sw_debounced)) + /* debouncer is setup and will provide edge detection */ + return 0; + desc = edge_detector_desc(edet); irq = gpiod_to_irq(desc); @@ -555,23 +570,192 @@ static int edge_detector_start(struct edge_detector *edet) return 0; } +/* + * returns the current debounced value, or -1 if the debouncer is inactive. + */ +static int debounced_value(struct edge_detector *edet) +{ + int value; + + if (!atomic_read(&edet->sw_debounced)) + return -1; + + /* + * minor race - debouncer may be stopped here, so edge_detector_stop + * must leave the value unchanged so the following will read the level + * from when the debouncer was last running. + */ + value = atomic_read(&edet->level); + + if (test_bit(FLAG_ACTIVE_LOW, &edge_detector_desc(edet)->flags)) + value = !value; + + return value; +} + +static irqreturn_t debounce_irq_handler(int irq, void *p) +{ + struct edge_detector *edet = p; + struct gpio_desc *desc = edge_detector_desc(edet); + + mod_delayed_work(system_wq, + &edet->work, + usecs_to_jiffies(atomic_read(&desc->debounce_period))); + + return IRQ_HANDLED; +} + +static void debounce_work_func(struct work_struct *work) +{ + struct gpioline_event le; + int ret, level, oldlevel; + struct edge_detector *edet = + container_of(work, struct edge_detector, work.work); + struct gpio_desc *desc = edge_detector_desc(edet); + struct line *line; + + level = gpiod_get_raw_value_cansleep(desc); + if (level < 0) { + pr_debug_ratelimited("debouncer failed to read line value\n"); + return; + } + + oldlevel = atomic_xchg(&edet->level, level); + if (oldlevel == level) + return; + + /* -- edge detection -- */ + line = edet->line; + if (line->edge_detection == GPIOLINE_EDGE_NONE) + return; + + /* switch from physical level to logical - if they differ */ + if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) + level = !level; + + /* ignore edges that are not being monitored */ + if (((line->edge_detection == GPIOLINE_EDGE_RISING) && (level == 0)) || + ((line->edge_detection == GPIOLINE_EDGE_FALLING) && (level == 1))) + return; + + /* Do not leak kernel stack to userspace */ + memset(&le, 0, sizeof(le)); + + le.timestamp = ktime_get_ns(); + le.offset = gpio_chip_hwgpio(desc); + edet->line_seqno++; + le.line_seqno = edet->line_seqno; + le.seqno = (line->num_descs == 1) ? + le.line_seqno : atomic_inc_return(&line->seqno); + + if (level) + /* Emit low-to-high event */ + le.id = GPIOLINE_EVENT_RISING_EDGE; + else + /* Emit high-to-low event */ + le.id = GPIOLINE_EVENT_FALLING_EDGE; + + ret = kfifo_in_spinlocked_noirqsave(&line->events, &le, + 1, &line->wait.lock); + if (ret) + wake_up_poll(&line->wait, EPOLLIN); + else + pr_debug_ratelimited("event FIFO is full - event dropped\n"); +} + +static int debounce_setup(struct edge_detector *edet, + unsigned int debounce_period) +{ + int ret, level, irq, irqflags; + struct gpio_desc *desc = edge_detector_desc(edet); + + /* try hardware */ + ret = gpiod_set_debounce(desc, debounce_period); + if (!ret) { + atomic_set(&desc->debounce_period, debounce_period); + return ret; + } + if (ret != -ENOTSUPP) + return ret; + + if (debounce_period) { + /* setup software debounce */ + level = gpiod_get_raw_value_cansleep(desc); + if (level < 0) + return level; + + irq = gpiod_to_irq(desc); + if (irq <= 0) + return -ENODEV; + + atomic_set(&edet->level, level); + edet->line_seqno = 0; + irqflags = IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING; + ret = request_irq(irq, + debounce_irq_handler, + irqflags, + edet->line->label, + edet); + if (ret) + return ret; + + atomic_set(&edet->sw_debounced, 1); + edet->irq = irq; + } + atomic_set(&desc->debounce_period, debounce_period); + return 0; +} + static void edge_detector_stop(struct edge_detector *edet) { + struct gpio_desc *desc = edge_detector_desc(edet); + if (edet->irq) { free_irq(edet->irq, edet); edet->irq = 0; } + + cancel_delayed_work_sync(&edet->work); + atomic_set(&edet->sw_debounced, 0); + /* do not change edet->level - see comment in debounced_value */ + + if (desc) + atomic_set(&desc->debounce_period, 0); +} + +static int debounce_update(struct edge_detector *edet, + unsigned int debounce_period) +{ + struct gpio_desc *desc = edge_detector_desc(edet); + + if (atomic_read(&desc->debounce_period) == debounce_period) + return 0; + + if (!atomic_read(&edet->sw_debounced)) + return debounce_setup(edet, debounce_period); + + if (!debounce_period) + edge_detector_stop(edet); + else + atomic_set(&desc->debounce_period, debounce_period); + return 0; } static int edge_detector_setup(struct edge_detector *edet, struct gpioline_config *lc) { struct gpio_desc *desc = edge_detector_desc(edet); + int ret; if (lc->edge_detection & GPIOLINE_EDGE_RISING) set_bit(FLAG_EDGE_RISING, &desc->flags); if (lc->edge_detection & GPIOLINE_EDGE_FALLING) set_bit(FLAG_EDGE_FALLING, &desc->flags); + if (lc->flags & GPIOLINE_FLAG_V2_DEBOUNCE) { + ret = debounce_setup(edet, lc->debounce_period); + if (ret) + return ret; + } if (lc->edge_detection) return edge_detector_start(edet); return 0; @@ -703,6 +887,10 @@ static long line_set_config_locked(struct line *line, if (test_bit(FLAG_ACTIVE_LOW, &desc->flags) != ((lc->flags & GPIOLINE_FLAG_V2_ACTIVE_LOW) != 0)) return -EINVAL; + + /* disallow debounce changes */ + if (atomic_read(&desc->debounce_period) != lc->debounce_period) + return -EINVAL; } vals = (unsigned long *)lc->values.bitmap; @@ -718,6 +906,7 @@ static long line_set_config_locked(struct line *line, if (lc->direction == GPIOLINE_DIRECTION_OUTPUT) { int val = test_bit(i, vals); + edge_detector_stop(&line->edets[i]); ret = gpiod_direction_output(desc, val); if (ret) return ret; @@ -725,6 +914,12 @@ static long line_set_config_locked(struct line *line, ret = gpiod_direction_input(desc); if (ret) return ret; + if (lc->flags & GPIOLINE_FLAG_V2_DEBOUNCE) { + ret = debounce_update(&line->edets[i], + lc->debounce_period); + if (ret) + return ret; + } } } @@ -762,7 +957,7 @@ static long line_ioctl(struct file *file, unsigned int cmd, void __user *ip = (void __user *)arg; struct gpioline_values glv; unsigned long *vals = (unsigned long *)glv.bitmap; - int ret; + int ret, i, value; if (cmd == GPIOLINE_GET_VALUES_IOCTL) { /* NOTE: It's ok to read values of output lines. */ @@ -776,6 +971,12 @@ static long line_ioctl(struct file *file, unsigned int cmd, if (ret) return ret; + for (i = 0; i < line->num_descs; i++) { + value = debounced_value(&line->edets[i]); + if (value >= 0) + assign_bit(i, vals, value); + } + if (copy_to_user(ip, &glv, sizeof(glv))) return -EFAULT; @@ -954,8 +1155,11 @@ static int line_create(struct gpio_device *gdev, void __user *ip) if (!line->edets) return -ENOMEM; - for (i = 0; i < linereq.num_lines; i++) + for (i = 0; i < linereq.num_lines; i++) { line->edets[i].line = line; + atomic_set(&line->edets[i].sw_debounced, 0); + INIT_DELAYED_WORK(&line->edets[i].work, debounce_work_func); + } line->gdev = gdev; get_device(&gdev->dev); @@ -1589,6 +1793,10 @@ static void gpio_desc_to_lineinfo(struct gpio_desc *desc, lc->edge_detection |= GPIOLINE_EDGE_FALLING; } + lc->debounce_period = atomic_read(&desc->debounce_period); + if (lc->debounce_period) + lc->flags |= GPIOLINE_FLAG_V2_DEBOUNCE; + spin_unlock_irqrestore(&gpio_lock, flags); } diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index 1dc6d2b191af..02a46af0c69f 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -124,6 +124,10 @@ struct gpio_desc { #ifdef CONFIG_OF_DYNAMIC struct device_node *hog; #endif +#ifdef CONFIG_GPIO_CDEV + /* debounce period in microseconds */ + atomic_t debounce_period; +#endif }; int gpiod_request(struct gpio_desc *desc, const char *label); From patchwork Tue Jun 23 04:01:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 206698 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.1 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 99FBCC433E0 for ; Tue, 23 Jun 2020 04:03:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7893F20771 for ; Tue, 23 Jun 2020 04:03:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="W+zyW+cG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732351AbgFWEDe (ORCPT ); Tue, 23 Jun 2020 00:03:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42380 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732407AbgFWEDd (ORCPT ); Tue, 23 Jun 2020 00:03:33 -0400 Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E6E1C061573; Mon, 22 Jun 2020 21:03:33 -0700 (PDT) Received: by mail-pg1-x542.google.com with SMTP id p3so6572895pgh.3; Mon, 22 Jun 2020 21:03:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+tTmPQpunlSSbQK0Pbq+5tZ7Bo8k9MZ8zGXj11uq1g8=; b=W+zyW+cG1VvApwhl64/raneJjBUL+tYXKS9S6IdEmJtu3zVoyBU1N3B7Ysh4+e5Lxs yFjzrPnpGewZDLHupG1XmgCCfiULOjNf7rn3JurZ07ZaS2AGrfnUMDqtX5EM4L4rONB4 09Zy1092ZyJ6hW/EIJZ1HMXJbAxphKntkfnBqvcWgNqNyDhwUIJRZYN4aKiYuA7K2w0g bvUtr+5dXAfuNTIPqfWvbyOYcRlnJL3b383f855IJMWZw+VyXJ2Fcxy3nwsAceYB+8dS AheD5b3GKsgwaoy0KgaXGV0k2oWU/+uE1pFvaEJUv12+8LzK/SiKnRpBqpeYXjrATnam +c6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+tTmPQpunlSSbQK0Pbq+5tZ7Bo8k9MZ8zGXj11uq1g8=; b=ZDz6JS594HXmnZjqvReJYVkpnK8houaP4tf/xDY29T2Kda2dng7FyIwYDwTRogqs29 pr6uGN6yZLqoLGL6rygySRvGeGLzT59XjXIE9SDtuJcgacule7BgoDZoonkYIOylI86W tjQaSrvReu5GIaP7a1NrUaNUX/hb6bb0iTkVsm+2l5+cEDppPac3Um23v1wld2d2wtZi JRa5cu2huBzPfvchE4vrsIzCIl/eo42zZAUIbFo4BNsSLeZ/NdKHspNCQHUO5qXH53eA 5v+DjXG8FqluQxgu0mJpxuy6m6mQPaxdPenFJra1z3SXslJaiWkXckkuJbdoPzLlF1w1 u9vQ== X-Gm-Message-State: AOAM531fgBze3V0mhDvr2oVyWqEsbtsfvUdAe2B6okzJWCEezjrJtzLP Rjz5zzVP0fUHzY/BmnL2K1ank4llDZE= X-Google-Smtp-Source: ABdhPJwf2KKQ/2r78LLFpFtpaXxhAQqRcwNvV4WHmgpvmvPmkMakJbOiMK0CaEWk4IVrmz18L4q38Q== X-Received: by 2002:a63:214d:: with SMTP id s13mr14987506pgm.277.1592885012642; Mon, 22 Jun 2020 21:03:32 -0700 (PDT) Received: from sol.lan (220-235-126-59.dyn.iinet.net.au. [220.235.126.59]) by smtp.gmail.com with ESMTPSA id n64sm12442315pga.38.2020.06.22.21.03.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Jun 2020 21:03:32 -0700 (PDT) From: Kent Gibson To: linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org Cc: Kent Gibson Subject: [PATCH 21/22] tools: gpio: add debounce support to gpio-event-mon Date: Tue, 23 Jun 2020 12:01:06 +0800 Message-Id: <20200623040107.22270-22-warthog618@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200623040107.22270-1-warthog618@gmail.com> References: <20200623040107.22270-1-warthog618@gmail.com> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Add support for debouncing monitored lines to gpio-event-mon. Signed-off-by: Kent Gibson --- tools/gpio/gpio-event-mon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/tools/gpio/gpio-event-mon.c b/tools/gpio/gpio-event-mon.c index d8d692f67b9e..ec90e44389dc 100644 --- a/tools/gpio/gpio-event-mon.c +++ b/tools/gpio/gpio-event-mon.c @@ -129,11 +129,12 @@ void print_usage(void) " -s Set line as open source\n" " -r Listen for rising edges\n" " -f Listen for falling edges\n" + " -b Debounce the line with period n microseconds\n" " [-c ] Do loops (optional, infinite loop if not stated)\n" " -? This helptext\n" "\n" "Example:\n" - "gpio-event-mon -n gpiochip0 -o 4 -r -f\n" + "gpio-event-mon -n gpiochip0 -o 4 -r -f -b 10000\n" ); } @@ -148,7 +149,7 @@ int main(int argc, char **argv) memset(&config, 0, sizeof(config)); config.flags = GPIOLINE_FLAG_V2_DIRECTION | GPIOLINE_FLAG_V2_EDGE_DETECTION; config.direction = GPIOLINE_DIRECTION_INPUT; - while ((c = getopt(argc, argv, "c:n:o:dsrf?")) != -1) { + while ((c = getopt(argc, argv, "c:n:o:b:dsrf?")) != -1) { switch (c) { case 'c': loops = strtoul(optarg, NULL, 10); @@ -159,6 +160,10 @@ int main(int argc, char **argv) case 'o': line = strtoul(optarg, NULL, 10); break; + case 'b': + config.flags |= GPIOLINE_FLAG_V2_DEBOUNCE; + config.debounce_period = strtoul(optarg, NULL, 10); + break; case 'd': config.flags |= GPIOLINE_FLAG_V2_DRIVE; config.drive = GPIOLINE_DRIVE_OPEN_DRAIN;