From patchwork Sun Oct 20 14:42:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kent Gibson X-Patchwork-Id: 1180018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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="JhvBF/KN"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 46x2bH55CWz9sP7 for ; Mon, 21 Oct 2019 01:44:11 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726467AbfJTOoL (ORCPT ); Sun, 20 Oct 2019 10:44:11 -0400 Received: from mail-pl1-f195.google.com ([209.85.214.195]:35085 "EHLO mail-pl1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726436AbfJTOoL (ORCPT ); Sun, 20 Oct 2019 10:44:11 -0400 Received: by mail-pl1-f195.google.com with SMTP id c3so5260410plo.2 for ; Sun, 20 Oct 2019 07:44:10 -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=A6b82n7MUWxHzx+AzZMEM+L1v6xK9yp8dfu2YPOidn0=; b=JhvBF/KNyXCyP3HkXeLPmzZ2V1RgkZRUB+Xd9s1+NNZoGSp0rxLNA1pp7KBS40roAa xPjnnn2vbI4g1VKMp+24QhQ1Vsho7Vg8bl1mnvCiIHHFoWRFqP0Gm75FkvBkwUrU86YW 063qLZyGIvVGJgFFOmK/Som1DP8LId3wzJ+/mWHWL36knZy5b6lctTc2bsy2gnDrBs6V 5cS/hCmHYszEmaN+sH1mopRasp7EMxdvTlefNarba9WauCw09LJ8NJ8aDse31zj3lkWD sdIM1Lq22XoCq2q1D9Y9fQNcgy4cVNgvmoLMNHBqiV796jf87NuIf2p2yzVINNGYRGrR J37w== 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=A6b82n7MUWxHzx+AzZMEM+L1v6xK9yp8dfu2YPOidn0=; b=I8JeImTeZ6cuVYWLfpv5arqh88LEwx+oCepc6rEsLCzAh9DpVOpkm3ca6daZB4p7Qi K6fvDVluV15q7NIrqy+tEk1AljYl2wVV8K4yJ97bqKcVtotEsk+ao1ff6nDWzfCG9Ymp SO10MYaF1t2059TER0arTeZnbVmj5Vv+TaOZ6zsimhk68AP6zdBCwmRH99xkQ/aiTWH8 cIgZIDhj5PZch2FqEupuO5icGiJGieew57XmqiEhCMDZ+4Wyl6I+/JRUG+m76NyeW4g9 CPyfEC/7UZoCW9Ax8b0weOpCdVk/WIdGkd0PXUTNBvSiggephUVdU+eUnR5rVxUP/xa4 fSJw== X-Gm-Message-State: APjAAAUk5UCb88DfBPcnTU9x45KxwSJsHzo3iEC0PeUYFThjQJG7m1AT HQSocmlft0xaeoSzSr8qZoC+xWWjHpHL9g== X-Google-Smtp-Source: APXvYqyzCiatZ/AZSEvd/PKtxjSNXBBAeQsd7UBaehxnEF8cS7i7Pm8mmVNAyDngmq+1ff5RBGLRPA== X-Received: by 2002:a17:902:54f:: with SMTP id 73mr19419453plf.329.1571582649882; Sun, 20 Oct 2019 07:44:09 -0700 (PDT) Received: from sol.lan (220-235-109-115.dyn.iinet.net.au. [220.235.109.115]) by smtp.gmail.com with ESMTPSA id w14sm14671842pge.56.2019.10.20.07.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 20 Oct 2019 07:44:09 -0700 (PDT) From: Kent Gibson To: linux-gpio@vger.kernel.org, bgolaszewski@baylibre.com, linus.walleij@linaro.org, bamv2005@gmail.com Cc: drew@pdp7.com, Kent Gibson Subject: [PATCH v3 3/5] gpio: mockup: add set_config to support pull up/down Date: Sun, 20 Oct 2019 22:42:36 +0800 Message-Id: <20191020144238.14080-4-warthog618@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191020144238.14080-1-warthog618@gmail.com> References: <20191020144238.14080-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..c28219962ae2 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;