Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp545982ybz; Wed, 29 Apr 2020 05:08:49 -0700 (PDT) X-Google-Smtp-Source: APiQypK0vBQh+xQYXQGF/Y7kJhFQVLMftDPSjXICnspJXvyaxxAHGNLect0ngeahKITO1aA9V5y/ X-Received: by 2002:a17:906:4310:: with SMTP id j16mr2392582ejm.102.1588162129636; Wed, 29 Apr 2020 05:08:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588162129; cv=none; d=google.com; s=arc-20160816; b=uKz2gKEIdSF57d18mBumngImxFT6HZwYSHJwtwlAm++dtTI7/SBL537CutzLge8vSv VBRvU6fh5+tBm7oZZpn8SrmYxkiVsylC3yNxWWYBV7I9XRA+3nCYotYJ7sJwjqPpZ2F4 nbKS1J8TdS4pVXFa6vCf9mQXyLKCEYlDKiSwMQerW5a76cWl2DWPoZeCpG64gZ7oHhwo tg3TGgm5CDCmJ0NiyzTe4HfTi/hy4Gzx7/xI0s33ySmPOT6RuhJffWy6086b/eu7Gaqd zF/McNh2TahXDQIrr63Jyj+ncTwuzEIKM2GZ3d0AonGVf5HgQ6F8Wq+K7Erx1nDHjv6Q /dsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=TIqAcmi3CCZVVh/ji2pLzKpj1uM3+1gSxtRQTFT+Ouk=; b=a5FL/2wbggDsWsgDRHMeWLej6rtmy9w0V/7SVhB0aglAaEGQCO2m3cbR6vRFvMCRBt yB4HubQAapu3UqsigRU4xguD86imRGQh4/Ylj1nkaTZLoKybALPm0rJRObeYP2OhD2X3 +MlTvWFbkKn8h7WzF7nGIJRTFdURuH9LMae+E23H9npsNXzTtxwdELjhngSEOq5mvLNc 9TNK81ZweRkSR5huFyLPWaMqKYZtMGY19R92QohZ8bkV4YtvYAIGBYwy8HuEfMwtCHYA 0Sibca7oPZA545+w4HycMb2YUYz1yua+88IxM3V/mW3KHbsc3Wa8Y2/z6Z7nL3eDfw/I 9siA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Tp+w2+Fr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t16si3689469eju.94.2020.04.29.05.08.25; Wed, 29 Apr 2020 05:08:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20150623.gappssmtp.com header.s=20150623 header.b=Tp+w2+Fr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726839AbgD2MGt (ORCPT + 99 others); Wed, 29 Apr 2020 08:06:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38802 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726617AbgD2MGt (ORCPT ); Wed, 29 Apr 2020 08:06:49 -0400 Received: from mail-il1-x144.google.com (mail-il1-x144.google.com [IPv6:2607:f8b0:4864:20::144]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8DA50C03C1AD for ; Wed, 29 Apr 2020 05:06:47 -0700 (PDT) Received: by mail-il1-x144.google.com with SMTP id q10so2180463ile.0 for ; Wed, 29 Apr 2020 05:06:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=TIqAcmi3CCZVVh/ji2pLzKpj1uM3+1gSxtRQTFT+Ouk=; b=Tp+w2+FrdLCJUimSTjGqniD+POTP8Os4cX486cB0qDkka4hhqdPfOJWY9YoDvPAQFe XkDm5r9ZM7a6Lq8zxoyMgXVbk30i01oBPgeqLUAwUnLZDeJXBwfQKmdWCyfHpCldLYFv 54scgDOznbzd7zvIAWzX+KvmvjR69fm7Nm5V08kbuLqN2feqwyXft7lhaKXA2CY2Bdbl vj/PKmeRtaHJbMsByKL+nWzKh+lXkf8A0kuJRO6QySs9q/lihh4q5QdGxcOtgx5ukFEP l/x3lBQZusexGrwS9IHzA1+DdxAFhPAxx2kXz7sIHleBDojf/s7/z5mNRLDxsL3rJUkJ tL6Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=TIqAcmi3CCZVVh/ji2pLzKpj1uM3+1gSxtRQTFT+Ouk=; b=Bscaol64lR/pRK8+1lRCZrrJt9EKD5BWqBoUcTo3fHkKmYhfRbGTA9t2xkKE0qOfQ7 nwb/YEsvl4jZmkajSv3TBC2nlLVDmJcf4cLS4at9SqxWDlMgFVnUehBtDx7H9nuUT7Lm XkZ9kf75oJD6pWsfSsl047FySLWzYvEnseFXX2jCGxZ9KSPp7skzev2zc084vdYjfwgL NJdrPZADClnsFDuW16Q8pSCV9DdKmR3leNTMPk0mP+c2bfXI53b3wWvRASRvUyicKf2l OrvQGmVpLLDri0/1ytQP6XQ3vygKrBg8iM/MkHlL11syYlS8iHqT86yOZ2gZcxLF2D54 FH+g== X-Gm-Message-State: AGi0Pua7QoQgbsIZYvwpKUQeyRfISy5SJeE53W361N1hdWBy48Px3vyT PoeFuyymokY1+jrS5rIRgansKEWcvgRskNpKHxTEVg== X-Received: by 2002:a92:cac7:: with SMTP id m7mr31904269ilq.6.1588162006553; Wed, 29 Apr 2020 05:06:46 -0700 (PDT) MIME-Version: 1.0 References: <20200419001858.105281-1-hector.bujanda@digi.com> In-Reply-To: <20200419001858.105281-1-hector.bujanda@digi.com> From: Bartosz Golaszewski Date: Wed, 29 Apr 2020 14:06:35 +0200 Message-ID: Subject: Re: [PATCH] gpiolib: add GPIO_SET_DEBOUNCE_IOCTL To: Hector Bujanda Cc: Linus Walleij , "open list:GPIO SUBSYSTEM" , Linux Kernel Mailing List , Kent Gibson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org niedz., 19 kwi 2020 o 02:19 Hector Bujanda napisa= =C5=82(a): > > This allows calling gpiod_set_debounce function through char device ioctl= . > > Signed-off-by: Hector Bujanda > --- Hi Hector, please keep in mind to Cc me on GPIO patches - especially when touching uAPI. For uAPI you can also Cc Kent Gibson for a second opinion. > drivers/gpio/gpiolib.c | 12 ++++++++++++ > include/uapi/linux/gpio.h | 12 ++++++++++++ > 2 files changed, 24 insertions(+) > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > index 70f0dedca59f..c959c2962f15 100644 > --- a/drivers/gpio/gpiolib.c > +++ b/drivers/gpio/gpiolib.c > @@ -1073,6 +1073,18 @@ static long gpio_ioctl(struct file *filp, unsigned= int cmd, unsigned long arg) > if (copy_to_user(ip, &lineinfo, sizeof(lineinfo))) > return -EFAULT; > return 0; > + } else if (cmd =3D=3D GPIO_SET_DEBOUNCE_IOCTL) { > + struct gpioline_debounce linedebounce; > + struct gpio_desc *desc; > + > + if (copy_from_user(&linedebounce, ip, sizeof(linedebounce= ))) > + return -EFAULT; > + if (linedebounce.line_offset >=3D gdev->ngpio) > + return -EINVAL; > + > + desc =3D &gdev->descs[linedebounce.line_offset]; > + > + return gpiod_set_debounce(desc, linedebounce.debounce_use= c); As Linus pointed out: adding a new ioctl() for this is out of question - especially if this new ioctl() would be called on the chip file descriptor. Modifying any config settings can only happen on lines previously requested too in user-space. > } else if (cmd =3D=3D GPIO_GET_LINEHANDLE_IOCTL) { > return linehandle_create(gdev, ip); > } else if (cmd =3D=3D GPIO_GET_LINEEVENT_IOCTL) { > diff --git a/include/uapi/linux/gpio.h b/include/uapi/linux/gpio.h > index 1bf6e6df084b..4b092990d4c8 100644 > --- a/include/uapi/linux/gpio.h > +++ b/include/uapi/linux/gpio.h > @@ -53,6 +53,17 @@ struct gpioline_info { > char consumer[32]; > }; > > +/** > + * struct gpioline_debounce - GPIO line debounce > + * @line_offset: the local offset on this GPIO device, fill this in when > + * requesting the line information from the kernel > + * @debounce_usec: debounce in uSeconds to set for this line > + */ > +struct gpioline_debounce { > + __u32 line_offset; > + __u32 debounce_usec; > +}; > + > /* Maximum number of requested handles */ > #define GPIOHANDLES_MAX 64 > > @@ -154,5 +165,6 @@ struct gpioevent_data { > #define GPIO_GET_LINEINFO_IOCTL _IOWR(0xB4, 0x02, struct gpioline_info) > #define GPIO_GET_LINEHANDLE_IOCTL _IOWR(0xB4, 0x03, struct gpiohandle_re= quest) > #define GPIO_GET_LINEEVENT_IOCTL _IOWR(0xB4, 0x04, struct gpioevent_requ= est) > +#define GPIO_SET_DEBOUNCE_IOCTL _IOW(0xB4, 0x05, struct gpioline_debounc= e) > > #endif /* _UAPI_GPIO_H_ */ > -- > 2.17.1 > I understand the need to set debounce time to make line events reliable. As I see it: there'll be a couple steps to add this. First: this information (debounce setting) isn't exported to user-space in any way yet. While we can't extend the gpioline_info structure because there's no padding for future use (unfortunately :( ) we should at least have a flag coming after GPIOHANDLE_REQUEST_BIAS_DISABLE that would indicate to user-space that the line is debounced at all e.g. GPIOHANDLE_REQUEST_DEBOUNCED. At the same time as the above: the line state change notifier chain must be called from gpiod_set_debounce() - in the end: if we export this information to the user-space, we also need to notify it when it changes. Next: the SET_CONFIG ioctl() should be extended to work with lineevent file descriptors too (of course - not all options would make sense here and they'd need to be properly filtered). Finally: we can extend the gpiohandle_config structure with a field containing the debounce time which would be read by the kernel if the debounce flag is set in gpiohandle_config.flags. Does this make sense? Bart