From patchwork Fri Oct 11 15:46:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1175322 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FlY8Uu1x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46qXR53cYLz9sNx for ; Sat, 12 Oct 2019 02:48:01 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728213AbfJKPsB (ORCPT ); Fri, 11 Oct 2019 11:48:01 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:39342 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfJKPsB (ORCPT ); Fri, 11 Oct 2019 11:48:01 -0400 Received: by mail-pf1-f193.google.com with SMTP id v4so6331842pff.6 for ; Fri, 11 Oct 2019 08:48:00 -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=H8pWxllBl/HRU6dwk3RzvMewJ/lSEodvQ4T55bbhvxc=; b=FlY8Uu1xwdiAw2UR5YPjvulppFqfYvGkJgMrbjruIRl6xsz4ga7TTDmYKAVVnuz2In Z5PPiBdzmLdztmiM3Y6Yz2ZM7EhQdGrWMPe2WL3A2I5rF5Ws/fO/EMHpZcytqUq6ye8x lOxLUkGP4VFo7eeqsY/n5GLYqQAB4tGdtN54lnEbAo8N71T/rSXWBrbA6k2xsSL/Pl4n y9UCcaaEfXQ4eCQs5zkzt4hn6hofZFJ2Q0GXA52jTbm6wzQGqyShXQ6QexEXbcvvo2qn PAfL3LLCPKCYLidzvXoJl0CusrbiEsmpMK6Vpob4askad0RJNWmYyvuQzwNbVkC7pc4Z dfQw== 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=H8pWxllBl/HRU6dwk3RzvMewJ/lSEodvQ4T55bbhvxc=; b=mZlyAaBGJVNjzxrmXXort8DsmAs6HiBDpkuadlYjPRHXlYQijWO6VnsqHrR2pe8Z09 NW11a35rCsR/83yIkDLlPsN3zcgD3FrJHxZk2WDBl5WiGVauP5kBnq60jZ51/7LCYdrX NP8HuJNME7jLzeOdJEMkS1CFzS/ghgd7CxI+DkZU3N9LGRaAN2SdZV9w7JD+UaOpMMwW owwRrtT86nhnsgIZB9RgXaZ0ehrute5NCWAuaN5Fp3qgnDle9MCWurO+/hTYLaNC+I52 Z41/r9vMtahBI4VjU6jQlzJk1IceXDF2tM/6J07ERokrEXi7dn5LYa94fmMbI0nYQkTW aSzw== X-Gm-Message-State: APjAAAXX9Oh3WTannJSOB0Q6lpYinJ0iot48Y8BKmLCHooxe8rbHiui4 Ee0aFU3+MyQ2C5IbMXaosx0emMDNCXSV9A== X-Google-Smtp-Source: APXvYqwLHJ8wp6/wb+9LIXH+gmYBt3uC/VSqP0kMUl507SahYcgfv7UT7mQSunOhYY3BO5nMgPQtxg== X-Received: by 2002:a63:1b0d:: with SMTP id b13mr17560328pgb.312.1570808879854; Fri, 11 Oct 2019 08:47:59 -0700 (PDT) Received: from sol.lan (220-235-84-126.dyn.iinet.net.au. [220.235.84.126]) by smtp.gmail.com with ESMTPSA id v28sm13755404pgn.17.2019.10.11.08.47.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 08:47:59 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH 1/5] gpiolib: add support for pull up/down to lineevent_create Date: Fri, 11 Oct 2019 23:46:46 +0800 Message-Id: <20191011154650.1749-2-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011154650.1749-1-warthog618@gmail.com> References: <20191011154650.1749-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 This patch adds support for pull up/down to lineevent_create. Use cases include receiving asynchronous presses from a push button without an external pull up/down. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 994e5d71375d..0912a00b2960 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -920,8 +920,20 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) /* This is just wrong: we don't look for events on output lines */ if ((lflags & GPIOHANDLE_REQUEST_OUTPUT) || (lflags & GPIOHANDLE_REQUEST_OPEN_DRAIN) || - (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE) || - (lflags & GPIOHANDLE_REQUEST_PULL_UP) || + (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE)) + return -EINVAL; + + /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ + if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && + ((lflags & GPIOHANDLE_REQUEST_PULL_UP) || + (lflags & GPIOHANDLE_REQUEST_PULL_DOWN))) + return -EINVAL; + + /* + * Do not allow both pull-up and pull-down flags to be set as they + * are contradictory. + */ + if ((lflags & GPIOHANDLE_REQUEST_PULL_UP) && (lflags & GPIOHANDLE_REQUEST_PULL_DOWN)) return -EINVAL; @@ -951,6 +963,10 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) if (lflags & GPIOHANDLE_REQUEST_ACTIVE_LOW) set_bit(FLAG_ACTIVE_LOW, &desc->flags); + if (lflags & GPIOHANDLE_REQUEST_PULL_DOWN) + set_bit(FLAG_PULL_DOWN, &desc->flags); + if (lflags & GPIOHANDLE_REQUEST_PULL_UP) + set_bit(FLAG_PULL_UP, &desc->flags); ret = gpiod_direction_input(desc); if (ret) From patchwork Fri Oct 11 15:46:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1175323 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="bPGYJob1"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46qXR95ryKz9sNx for ; Sat, 12 Oct 2019 02:48:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728218AbfJKPsF (ORCPT ); Fri, 11 Oct 2019 11:48:05 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:40825 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfJKPsF (ORCPT ); Fri, 11 Oct 2019 11:48:05 -0400 Received: by mail-pf1-f195.google.com with SMTP id x127so6327882pfb.7 for ; Fri, 11 Oct 2019 08:48: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=9yM+7slsNLJm2jMU2/8cO8XX3jrRvDxcj2OR+Xd2zxk=; b=bPGYJob19nzCHOkRZiZw9lcnOYM/32jUdDRTmXqH5wREigpO5PXAzVSfZxl4KA9JVf A9fC33Cisw43YoA1gHD+4uVBWRN5LWRUuotkz29b0SOTlFL2ur24hd+BNb5ldklEn5UB BcS+m6CyL5ewnKCpSpzoHBT9fXQOByBTosnG6N9yfAsCAiDE/mOIXeHbKrr65xyXHHCb UJIHHyO7pXi9pBM5DpFzwjaar1opY7vRllB9+kICMLqxI7L3lAAunTSoXCQEEDApA3jV k5WDlBjuFqSZyuBSc7rW/zwL0sAob/Gv05pqqyFR4vyNAxb3ra45Tyntu22qAT+F2zX/ jdNg== 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=9yM+7slsNLJm2jMU2/8cO8XX3jrRvDxcj2OR+Xd2zxk=; b=RI3Qr6pTwmPV/C07RSb0hBEnevNJFEpeGHUVVSYtEbMiSzY7bi77i1XVRU0E6uJKPd WNkcuYGftZVX8Fi4uAhG8vWPjR/S8XtKBJiBvf7Pg1E3OQh63z9kexC4G+pfbHLhRiQB zkUSHlCooFiwOOCGaO2U0kUi+4tL/9vwFUF5FuTmVN0FzS/YW4A6GpdInM0b510fJ8Mh GZQAFS1DunsNPdi4n9rcdPFrnOsZ+gk8teM9GlUFvShTSzgVNF2kM29CcC7Ap6IUshyZ CiPfAIhvLjRjXTFfrVIb/2lOU3KQXN/h2+rGFI8BbrEyZOxRVRz3gBhZKGr7ABnSXlvr Y6og== X-Gm-Message-State: APjAAAVw3xFb4Y+aMo7CqQ2iCOXQl9AqlaWVuWgeYBFhEFdsvioxLUU3 B8jyhTDcVKBVVZK4fBOgJT9BSzUh6vgKtw== X-Google-Smtp-Source: APXvYqycSvph7wuyWgaxY/gNqi5FEA75xzA7NELOcvDYdiYaiAA4j8bXvfnD1/bK5WsNvqu1mnZXHg== X-Received: by 2002:a17:90a:8085:: with SMTP id c5mr6277402pjn.60.1570808883452; Fri, 11 Oct 2019 08:48:03 -0700 (PDT) Received: from sol.lan (220-235-84-126.dyn.iinet.net.au. [220.235.84.126]) by smtp.gmail.com with ESMTPSA id v28sm13755404pgn.17.2019.10.11.08.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 08:48:02 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH 2/5] gpio: mockup: add set_config to support pull up/down Date: Fri, 11 Oct 2019 23:46:47 +0800 Message-Id: <20191011154650.1749-3-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011154650.1749-1-warthog618@gmail.com> References: <20191011154650.1749-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 This patch adds support for the pull up/down state set via gpiolib line requests to be reflected in the state of the mockup. Use case is for testing of the GPIO uAPI, specifically the pull up/down flags. Signed-off-by: Kent Gibson --- drivers/gpio/gpio-mockup.c | 94 ++++++++++++++++++++++++-------------- 1 file changed, 60 insertions(+), 34 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 213aedc97dc2..493077229677 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -146,6 +146,61 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc, mutex_unlock(&chip->lock); } +static int gpio_mockup_apply_pull(struct gpio_mockup_chip *chip, + unsigned int offset, int value) +{ + struct gpio_desc *desc; + struct gpio_chip *gc; + struct irq_sim *sim; + int curr, irq, irq_type; + + gc = &chip->gc; + desc = &gc->gpiodev->descs[offset]; + sim = &chip->irqsim; + + mutex_lock(&chip->lock); + + if (test_bit(FLAG_REQUESTED, &desc->flags) && + !test_bit(FLAG_IS_OUT, &desc->flags)) { + curr = __gpio_mockup_get(chip, offset); + if (curr == value) + goto out; + + irq = irq_sim_irqnum(sim, offset); + irq_type = irq_get_trigger_type(irq); + + if ((value == 1 && (irq_type & IRQ_TYPE_EDGE_RISING)) || + (value == 0 && (irq_type & IRQ_TYPE_EDGE_FALLING))) + irq_sim_fire(sim, offset); + } + + /* Change the value unless we're actively driving the line. */ + if (!test_bit(FLAG_REQUESTED, &desc->flags) || + !test_bit(FLAG_IS_OUT, &desc->flags)) + __gpio_mockup_set(chip, offset, value); + +out: + chip->lines[offset].pull = value; + mutex_unlock(&chip->lock); + return 0; +} + +static int gpio_mockup_set_config(struct gpio_chip *gc, + unsigned int offset, unsigned long config) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + switch (pinconf_to_config_param(config)) { + case PIN_CONFIG_BIAS_PULL_UP: + return gpio_mockup_apply_pull(chip, offset, 1); + case PIN_CONFIG_BIAS_PULL_DOWN: + return gpio_mockup_apply_pull(chip, offset, 0); + default: + break; + } + return -ENOTSUPP; +} + static int gpio_mockup_dirout(struct gpio_chip *gc, unsigned int offset, int value) { @@ -226,12 +281,8 @@ static ssize_t gpio_mockup_debugfs_write(struct file *file, size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; - int rv, val, curr, irq, irq_type; - struct gpio_mockup_chip *chip; + int rv, val; struct seq_file *sfile; - struct gpio_desc *desc; - struct gpio_chip *gc; - struct irq_sim *sim; if (*ppos != 0) return -EINVAL; @@ -244,35 +295,9 @@ static ssize_t gpio_mockup_debugfs_write(struct file *file, sfile = file->private_data; priv = sfile->private; - chip = priv->chip; - gc = &chip->gc; - desc = &gc->gpiodev->descs[priv->offset]; - sim = &chip->irqsim; - - mutex_lock(&chip->lock); - - if (test_bit(FLAG_REQUESTED, &desc->flags) && - !test_bit(FLAG_IS_OUT, &desc->flags)) { - curr = __gpio_mockup_get(chip, priv->offset); - if (curr == val) - goto out; - - irq = irq_sim_irqnum(sim, priv->offset); - irq_type = irq_get_trigger_type(irq); - - if ((val == 1 && (irq_type & IRQ_TYPE_EDGE_RISING)) || - (val == 0 && (irq_type & IRQ_TYPE_EDGE_FALLING))) - irq_sim_fire(sim, priv->offset); - } - - /* Change the value unless we're actively driving the line. */ - if (!test_bit(FLAG_REQUESTED, &desc->flags) || - !test_bit(FLAG_IS_OUT, &desc->flags)) - __gpio_mockup_set(chip, priv->offset, val); - -out: - chip->lines[priv->offset].pull = val; - mutex_unlock(&chip->lock); + rv = gpio_mockup_apply_pull(priv->chip, priv->offset, val); + if (rv) + return rv; return size; } @@ -418,6 +443,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->direction_output = gpio_mockup_dirout; gc->direction_input = gpio_mockup_dirin; gc->get_direction = gpio_mockup_get_direction; + gc->set_config = gpio_mockup_set_config; gc->to_irq = gpio_mockup_to_irq; gc->free = gpio_mockup_free; From patchwork Fri Oct 11 15:46:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1175324 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jnlARvAs"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46qXRD3GsYz9sNx for ; Sat, 12 Oct 2019 02:48:08 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728220AbfJKPsI (ORCPT ); Fri, 11 Oct 2019 11:48:08 -0400 Received: from mail-pf1-f194.google.com ([209.85.210.194]:32914 "EHLO mail-pf1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfJKPsH (ORCPT ); Fri, 11 Oct 2019 11:48:07 -0400 Received: by mail-pf1-f194.google.com with SMTP id q10so6343156pfl.0 for ; Fri, 11 Oct 2019 08:48:07 -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=8dslRAjltFEQ38TKy6sGKan1JS7Yvgm4Z9fGKBQoELg=; b=jnlARvAsn/TOSX7if0HMLqp4aaeRmNfCmkagBtl1ICKTPOtfUGvdXJtCgE2a7wBeZN glJCATcDhsf5QMmO330NnRT0T/agPdd45V8IERy8rU/tprjoBPJYRcymr3VZ99ouwBP4 Jc8WhtnkTZsHxbo4jUKKoF/0N0Lt0AujR4Y1h4K2acfX/UaiDgkjnMr5zpzpiMILQeuk UQD2DU08lm8dYvUrJKmY82zbKeifPaEllO76SOzrx1CQIMDrehvJpvaV9xHHtmtGnQWL 0DUN0BvS2oAWvh3BXPaXRG/i6xgparA+u6YYkCpA06llznAVgZ6F1GXUbiHSIKkV19Js FzXA== 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=8dslRAjltFEQ38TKy6sGKan1JS7Yvgm4Z9fGKBQoELg=; b=KK00W2aC2YgIT5aw0r+L/gHXwdVJKvIhmYukNkEMnr1s4bYgxSiUHEHgWZRxx43Z1w 8PPjUB2aNTbU0s4eVHxr/XecDJBIpfjODq4pLoAz4DoOt+ZTYJ4J2iBey3Vtt0esJmSl c5Q/CVCGdDBC2LXD+yegF3OBtW8y0Z+B0OoApE/p/0UF0wqvXWC9uPFYUD/u7BJtUBKT 795KiR4HBm2WY8B1c5mL8N127nVCzRKsujAM2Npbvf4sm7zI+KdvoCwuVHws4FZYwRkF BMGhXSBrwz0lEdDZ+0k26fO8rGoK8nxf8/sosnYzzWyPhWGT3ugAcSmvXHwlmy1s5gGu cuyw== X-Gm-Message-State: APjAAAU6m186RPJ3HGf7YQ95ssg8vsTuRDKn1Wy+gEWXMR2SadJR1Yn7 DHk1ggrS97ml6iX5zQg6VkG+zMbFqDgp4w== X-Google-Smtp-Source: APXvYqwzIcAMf9Z7QGgX6X94Vc4sg5panbdXlTX+D3IoRLtDau4s0DRz9iWADPzSxref8A92Bisy9Q== X-Received: by 2002:aa7:9e88:: with SMTP id p8mr17680901pfq.10.1570808886880; Fri, 11 Oct 2019 08:48:06 -0700 (PDT) Received: from sol.lan (220-235-84-126.dyn.iinet.net.au. [220.235.84.126]) by smtp.gmail.com with ESMTPSA id v28sm13755404pgn.17.2019.10.11.08.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 08:48:06 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH 3/5] gpiolib: pull requires explicit input mode Date: Fri, 11 Oct 2019 23:46:48 +0800 Message-Id: <20191011154650.1749-4-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011154650.1749-1-warthog618@gmail.com> References: <20191011154650.1749-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 This patch prevents pull up/down flags being applied to as-is line requests, which should be left as-is, and for output mode for which setting pulls is not currently supported. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0912a00b2960..a634c340920b 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -559,6 +559,12 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))) return -EINVAL; + /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ + if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && + ((lflags & GPIOHANDLE_REQUEST_PULL_UP) || + (lflags & GPIOHANDLE_REQUEST_PULL_DOWN))) + return -EINVAL; + lh = kzalloc(sizeof(*lh), GFP_KERNEL); if (!lh) return -ENOMEM; From patchwork Fri Oct 11 15:46:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1175325 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="N9oVEriv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46qXRJ1Cx1z9sNx for ; Sat, 12 Oct 2019 02:48:12 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727149AbfJKPsL (ORCPT ); Fri, 11 Oct 2019 11:48:11 -0400 Received: from mail-pg1-f196.google.com ([209.85.215.196]:35040 "EHLO mail-pg1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfJKPsL (ORCPT ); Fri, 11 Oct 2019 11:48:11 -0400 Received: by mail-pg1-f196.google.com with SMTP id p30so6031985pgl.2 for ; Fri, 11 Oct 2019 08:48:11 -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=ZcjYRpVw4R8UENGGJg84/VG0LG+CbDrj8hDlfV/ZeLg=; b=N9oVErivwsFdZ+MtncgVtbCUu5GxnhfPGy8F8cypNalOeFThMZK/cQZAYddEFTEIQM CFsFoRbVVwKlgLSFt8Xx3gT9dRo76mTP+UEDUOCf1FPXdh9vst7jy1IT6zyzWNdaV5hF jKa1P5DnQNt/PNM9ykU+xqpUhFpwCEP9j86wTHL4lOtJg7usvsWlvARmYmNea7uAehxN u5wLn3fYztSsBn9n7Zs9KqzWSAxnd/5Uzn0WamA4AoiOEKUK8AJXuaXrcjeSp3HsrvO6 2e9TnR4Y6yT/SnRGa/wq1vRNN04wjhAS7sedZI7K0sUezyoq48Bh3c0m5gNH93JfFBHo MYAw== 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=ZcjYRpVw4R8UENGGJg84/VG0LG+CbDrj8hDlfV/ZeLg=; b=si5RbaQYFsjZ8bXnpUd4wsGxTuXuDNNCQ+5B5vnf1qCaUCQ+9bn/GuYzmwPPbO+Aze NEVzPhu55ocG3iMpApneDSRMs0ZxLdDllBbg1xh4dmKmIWmA/x2XmSBAQK6qd03HF/0f nc25E+hpFT017q0da3GdCKmiWWCOj+Er02E6RYOYSsniVFUpl3PnFTc5ADxD8j5vu1IX QaUJcGMC6fZoi/ttZOssTBNhxa5LJ/52VNdL+qeYgVFKBPSl0FTEVhzNzaDH1ksQYzmv Xzd7M2/D/3sKg8xrXJeFZV4u7t84Bda9ewREZDumTWQIuEejUF/0mrKFBhHoXQMYsVft JHSw== X-Gm-Message-State: APjAAAU+DZ16uZMwLP0Afr1xpvYQduyuUmEAvm1yHG89SujODBjPQDKG iNPN9U2ks/pbvY+8xvazpvaC7Q5pkMGi/g== X-Google-Smtp-Source: APXvYqyXph+MBZ8x4HT23ZNXOiV5NfPax3IsMchjTe4x1aHr1WC9AIoCJ5DqkM1Q9sdI6XD3fjyo5w== X-Received: by 2002:a17:90a:de02:: with SMTP id m2mr18327133pjv.21.1570808890373; Fri, 11 Oct 2019 08:48:10 -0700 (PDT) Received: from sol.lan (220-235-84-126.dyn.iinet.net.au. [220.235.84.126]) by smtp.gmail.com with ESMTPSA id v28sm13755404pgn.17.2019.10.11.08.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 08:48:09 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH 4/5] gpiolib: disable bias on inputs when pull up/down are both set Date: Fri, 11 Oct 2019 23:46:49 +0800 Message-Id: <20191011154650.1749-5-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011154650.1749-1-warthog618@gmail.com> References: <20191011154650.1749-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 This patch allows pull up/down bias to be disabled, allowing the line to float or to be biased only by external circuitry. Use case is for where the bias has been applied previously, either by default or by the user, but that setting may conflict with the current use of the line. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index a634c340920b..f0665ea396cd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -539,11 +539,6 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) (lflags & GPIOHANDLE_REQUEST_OUTPUT)) return -EINVAL; - /* Same with pull-up and pull-down. */ - if ((lflags & GPIOHANDLE_REQUEST_PULL_UP) && - (lflags & GPIOHANDLE_REQUEST_PULL_DOWN)) - return -EINVAL; - /* * Do not allow OPEN_SOURCE & OPEN_DRAIN flags in a single request. If * the hardware actually supports enabling both at the same time the @@ -935,14 +930,6 @@ static int lineevent_create(struct gpio_device *gdev, void __user *ip) (lflags & GPIOHANDLE_REQUEST_PULL_DOWN))) return -EINVAL; - /* - * Do not allow both pull-up and pull-down flags to be set as they - * are contradictory. - */ - if ((lflags & GPIOHANDLE_REQUEST_PULL_UP) && - (lflags & GPIOHANDLE_REQUEST_PULL_DOWN)) - return -EINVAL; - le = kzalloc(sizeof(*le), GFP_KERNEL); if (!le) return -ENOMEM; @@ -2931,6 +2918,7 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned offset, unsigned arg; switch (mode) { + case PIN_CONFIG_BIAS_DISABLE: case PIN_CONFIG_BIAS_PULL_DOWN: case PIN_CONFIG_BIAS_PULL_UP: arg = 1; @@ -2991,7 +2979,11 @@ int gpiod_direction_input(struct gpio_desc *desc) if (ret == 0) clear_bit(FLAG_IS_OUT, &desc->flags); - if (test_bit(FLAG_PULL_UP, &desc->flags)) + if (test_bit(FLAG_PULL_UP, &desc->flags) && + test_bit(FLAG_PULL_DOWN, &desc->flags)) + gpio_set_config(chip, gpio_chip_hwgpio(desc), + PIN_CONFIG_BIAS_DISABLE); + else if (test_bit(FLAG_PULL_UP, &desc->flags)) gpio_set_config(chip, gpio_chip_hwgpio(desc), PIN_CONFIG_BIAS_PULL_UP); else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) @@ -4462,7 +4454,7 @@ int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, if (lflags & GPIO_PULL_UP) set_bit(FLAG_PULL_UP, &desc->flags); - else if (lflags & GPIO_PULL_DOWN) + if (lflags & GPIO_PULL_DOWN) set_bit(FLAG_PULL_DOWN, &desc->flags); ret = gpiod_set_transitory(desc, (lflags & GPIO_TRANSITORY)); From patchwork Fri Oct 11 15:46:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1175326 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-gpio-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZIHehPcM"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46qXRM3yQlz9sNx for ; Sat, 12 Oct 2019 02:48:15 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727812AbfJKPsP (ORCPT ); Fri, 11 Oct 2019 11:48:15 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:36579 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726521AbfJKPsP (ORCPT ); Fri, 11 Oct 2019 11:48:15 -0400 Received: by mail-pg1-f193.google.com with SMTP id 23so6034687pgk.3 for ; Fri, 11 Oct 2019 08:48: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=0bswD5djDX5qSZz0CkJ8QmEvt8BM+UaLc2rx/9lbfB8=; b=ZIHehPcMG9EoNwmGgphOK8Bx8D8JSPbgUCDMBIRRu96xbSuL9Mz4Iii6tEqAbq8IHh I4t23nobZ9TuJeUQoEQ/8BKUjyZ1hJYeTX7BYrqHEFnHnsfiz10iewPgWkZ+FGvaF2cF SCYX4tjsuuOc3ci9V0nk/uzdw+c34LMOpS6sqdBiI4ApRyMIoRP0dCPZBsyJHlXdc8RK Y70Usi6+Fg4pRy5y4+ClUVrufhAkJ2RW8UTjCLTx+N0yfD/v0NudqThofyqs+ZLJho5K pop3Dgxa/w5UwygcxiOrdep0QcEdROMdDnrHSA8eArFlsnQqdI/R5ljxBPdJnAuqkOD+ L3Gw== 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=0bswD5djDX5qSZz0CkJ8QmEvt8BM+UaLc2rx/9lbfB8=; b=MNG8pSnekR7oxaQFX90VvO47VhmmcB4LyFLhF5el2L9e/Si4OMsz71F/y1fNxD/Tec I/3A+2a8AcOZgBstkHIYSXXgHJa0JAMglWLs2Y/A3Rl51jXNskK+l1HzgkI/CfsSXdW3 FKycqYZePF4I+IV5G/SRvh8XOvgBxNDDKhiRvM7bteEsm6HcB7n4FqfcnY46vFu6oTN6 lqzF4CscgyX1lgAKl4B7vlbjwOStrdCBdbuLoLDQQjJIqNAaD+TO3OTULdTYQ6AF9NEe CF9t0eySXhofQkMVVOI2K+wnU4pOLTu/8VWKWASC6xaYjO5PsrBEa1a4gh4qx0rgEuHN bXZw== X-Gm-Message-State: APjAAAX5VjMKRbyzhBXGud30l479DfJfmL8a4EKqFnss6ge4E7h0gluG 3O0vCVneoQQnBpvjro3vQuu1PcmwWr8wJA== X-Google-Smtp-Source: APXvYqw7eZXNOZOq60IuTlLqnlPPY8NZhWfWpSHQnSdhAiZ4mD+cw+phbwOlUtfvwmuxbEoI8Bcr9g== X-Received: by 2002:a17:90b:f09:: with SMTP id br9mr3084547pjb.107.1570808893846; Fri, 11 Oct 2019 08:48:13 -0700 (PDT) Received: from sol.lan (220-235-84-126.dyn.iinet.net.au. [220.235.84.126]) by smtp.gmail.com with ESMTPSA id v28sm13755404pgn.17.2019.10.11.08.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Oct 2019 08:48:13 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, brgl@bgdev.pl, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH 5/5] gpiolib: allow pull up/down on outputs Date: Fri, 11 Oct 2019 23:46:50 +0800 Message-Id: <20191011154650.1749-6-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191011154650.1749-1-warthog618@gmail.com> References: <20191011154650.1749-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 This patch allows pull up/down bias to be set on outputs. Use case is for open source or open drain applications where internal pull up/down may conflict with external biasing. Signed-off-by: Kent Gibson --- drivers/gpio/gpiolib.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f0665ea396cd..38ead7a87d44 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -554,8 +554,9 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) (lflags & GPIOHANDLE_REQUEST_OPEN_SOURCE))) return -EINVAL; - /* PULL_UP and PULL_DOWN flags only make sense for input mode. */ - if (!(lflags & GPIOHANDLE_REQUEST_INPUT) && + /* PULL_UP and PULL_DOWN flags only allowed for input or output mode. */ + if (!((lflags & GPIOHANDLE_REQUEST_INPUT) || + (lflags & GPIOHANDLE_REQUEST_OUTPUT)) && ((lflags & GPIOHANDLE_REQUEST_PULL_UP) || (lflags & GPIOHANDLE_REQUEST_PULL_DOWN))) return -EINVAL; @@ -2932,6 +2933,24 @@ static int gpio_set_config(struct gpio_chip *gc, unsigned offset, return gc->set_config ? gc->set_config(gc, offset, config) : -ENOTSUPP; } +static int gpio_set_bias(struct gpio_chip *chip, struct gpio_desc *desc) +{ + int bias = 0; + + if (test_bit(FLAG_PULL_UP, &desc->flags) && + test_bit(FLAG_PULL_DOWN, &desc->flags)) + bias = PIN_CONFIG_BIAS_DISABLE; + else if (test_bit(FLAG_PULL_UP, &desc->flags)) + bias = PIN_CONFIG_BIAS_PULL_UP; + else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) + bias = PIN_CONFIG_BIAS_PULL_DOWN; + + if (bias) + return gpio_set_config(chip, gpio_chip_hwgpio(desc), bias); + + return 0; +} + /** * gpiod_direction_input - set the GPIO direction to input * @desc: GPIO to set to input @@ -2979,16 +2998,7 @@ int gpiod_direction_input(struct gpio_desc *desc) if (ret == 0) clear_bit(FLAG_IS_OUT, &desc->flags); - if (test_bit(FLAG_PULL_UP, &desc->flags) && - test_bit(FLAG_PULL_DOWN, &desc->flags)) - gpio_set_config(chip, gpio_chip_hwgpio(desc), - PIN_CONFIG_BIAS_DISABLE); - else if (test_bit(FLAG_PULL_UP, &desc->flags)) - gpio_set_config(chip, gpio_chip_hwgpio(desc), - PIN_CONFIG_BIAS_PULL_UP); - else if (test_bit(FLAG_PULL_DOWN, &desc->flags)) - gpio_set_config(chip, gpio_chip_hwgpio(desc), - PIN_CONFIG_BIAS_PULL_DOWN); + gpio_set_bias(chip, desc); trace_gpio_direction(desc_to_gpio(desc), 1, ret); @@ -3114,6 +3124,7 @@ int gpiod_direction_output(struct gpio_desc *desc, int value) } set_output_value: + gpio_set_bias(gc, desc); return gpiod_direction_output_raw_commit(desc, value); } EXPORT_SYMBOL_GPL(gpiod_direction_output);