From patchwork Thu Feb 14 13:42:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042187 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="B0Nug/r+"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czt3b5pz9rxp for ; Fri, 15 Feb 2019 00:43:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731324AbfBNNnh (ORCPT ); Thu, 14 Feb 2019 08:43:37 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52045 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390349AbfBNNnA (ORCPT ); Thu, 14 Feb 2019 08:43:00 -0500 Received: by mail-wm1-f67.google.com with SMTP id b11so6358456wmj.1 for ; Thu, 14 Feb 2019 05:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=AQxFI5IaDScBSYM2QiGDnhYF78mzPrJfNlrHBt3eAfM=; b=B0Nug/r+Q1ktchEW3T1m9wUXpJgBTvAM02A+j0HJOfNKcIQcHy7eIKmbmKYrcM1vti QOmv7AQG+eP1s9itAN0yk72AFnTT3G2Ye4MMjF3GClwGhckvMMMAMfFhtuW3KdVc1PiZ 9YcCiPBQKmQGbfdFR6UJdtOfeqmI6vCE0SVP8p5gPSElniElLTEpbobcoCI0iBrpmanV ckNWQ+BVvTdD/7pem4Fkzimesrtny/lUeKPdM7iXHAPGUUKN5GpbZxwx8cAmfXxQubE2 +5GtaQDt+88i5a1qS0HAHlxGTmGwH9/DCWsXyqAPjprqF4AhKHbkuzsCpb/rS90sQmLX qMGg== 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=AQxFI5IaDScBSYM2QiGDnhYF78mzPrJfNlrHBt3eAfM=; b=tSOyMi/eAdyaYqTtZJT1FfxcGMLapWnV+V9YIYuZrv5J8Sqvpz8CgNa0rF9CmOMqmn 2YurMZvD8ZP4gZ4nrIgC52HofCAHpXSF9A3FiQfBtmsj5MNkSA5UrLhvYydz0ee4tXCv oiBGnVKqLclEGTCqszks/Cq2YsT0aJUDOIWO3h0LwgmsBTmPOiSV+/5CEF2/WYjj8Uh3 JwgPk91kM4Paodeg6vxeeEGKkYlB7Rx/t8PccC/Zdv241Wh4Go2JUFQWbeowdz31pp8G rBvn9YDZAM2AgqXVD4mbUF6IzI6Hdm4e7rIebAffRSGX/8DEn8gEb6d6Lwrp7OIokquM kHQw== X-Gm-Message-State: AHQUAuZzX0EjeH5cPXBe6QciBR/Kq/eNZlz98fdDpSzGZVDJq+Etu6S2 y0iRihvCqgyrMY740qR2KlrMcg== X-Google-Smtp-Source: AHgI3IYAyCtoery/AKBJuvXqcbmB1685J/TSbgHq6YAUFUMbwGHyYEukArzL7PvcJIRkhV5Hv/bkCg== X-Received: by 2002:a1c:e1c4:: with SMTP id y187mr2916795wmg.50.1550151777005; Thu, 14 Feb 2019 05:42:57 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.42.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:42:56 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 1/7] irq/irq_sim: add a notifier chain Date: Thu, 14 Feb 2019 14:42:26 +0100 Message-Id: <20190214134232.3821-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Provide a helper allowing users to register a notifier block with a simulator. For now the only event we're notifying about is a change in type configuration. This is required by the gpio-mockup module which wants to track the state of GPIO lines and simulate rising and falling edge interrupts. Signed-off-by: Bartosz Golaszewski --- include/linux/irq_sim.h | 22 ++++++++++++++++++---- kernel/irq/irq_sim.c | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 4 deletions(-) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 4500d453a63e..e076693d0af7 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -8,12 +8,21 @@ #include #include +#include /* * Provides a framework for allocating simulated interrupts which can be * requested like normal irqs and enqueued from process context. */ +#define IRQ_SIM_TYPE_CHANGED 1 + +/* Passed to notifier callbacks when type changes. */ +struct irq_sim_irq_type { + unsigned int offset; + unsigned int type; +}; + struct irq_sim_work_ctx { struct irq_work work; unsigned long *pending; @@ -22,13 +31,16 @@ struct irq_sim_work_ctx { struct irq_sim_irq_ctx { int irqnum; bool enabled; + struct irq_sim *parent; + struct irq_sim_irq_type type; }; struct irq_sim { - struct irq_sim_work_ctx work_ctx; - int irq_base; - unsigned int irq_count; - struct irq_sim_irq_ctx *irqs; + struct irq_sim_work_ctx work_ctx; + int irq_base; + unsigned int irq_count; + struct irq_sim_irq_ctx *irqs; + struct atomic_notifier_head notifier; }; int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs); @@ -37,5 +49,7 @@ int devm_irq_sim_init(struct device *dev, struct irq_sim *sim, void irq_sim_fini(struct irq_sim *sim); void irq_sim_fire(struct irq_sim *sim, unsigned int offset); int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset); +int irq_sim_notifier_register(struct irq_sim *sim, + struct notifier_block *nb); #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 98a20e1594ce..a55641e78125 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -25,10 +25,34 @@ static void irq_sim_irqunmask(struct irq_data *data) irq_ctx->enabled = true; } +static int irq_sim_set_type(struct irq_data *data, unsigned int type) +{ + struct irq_sim_irq_ctx *irq_ctx = irq_data_get_irq_chip_data(data); + struct irq_sim *sim = irq_ctx->parent; + int rv; + + /* Only support rising and falling edge types. */ + if (type & ~IRQ_TYPE_EDGE_BOTH) + return -EINVAL; + + irq_ctx->type.type = type; + + rv = atomic_notifier_call_chain(&sim->notifier, + IRQ_SIM_TYPE_CHANGED, + &irq_ctx->type); + if (rv < 0) { + pr_err("%s: error calling the type notifier chain\n", __func__); + return rv; + } + + return 0; +} + static struct irq_chip irq_sim_irqchip = { .name = "irq_sim", .irq_mask = irq_sim_irqmask, .irq_unmask = irq_sim_irqunmask, + .irq_set_type = irq_sim_set_type, }; static void irq_sim_handle_irq(struct irq_work *work) @@ -83,7 +107,9 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) for (i = 0; i < num_irqs; i++) { sim->irqs[i].irqnum = sim->irq_base + i; + sim->irqs[i].parent = sim; sim->irqs[i].enabled = false; + sim->irqs[i].type.offset = i; irq_set_chip(sim->irq_base + i, &irq_sim_irqchip); irq_set_chip_data(sim->irq_base + i, &sim->irqs[i]); irq_set_handler(sim->irq_base + i, &handle_simple_irq); @@ -91,6 +117,7 @@ int irq_sim_init(struct irq_sim *sim, unsigned int num_irqs) IRQ_NOREQUEST | IRQ_NOAUTOEN, IRQ_NOPROBE); } + ATOMIC_INIT_NOTIFIER_HEAD(&sim->notifier); init_irq_work(&sim->work_ctx.work, irq_sim_handle_irq); sim->irq_count = num_irqs; @@ -180,3 +207,16 @@ int irq_sim_irqnum(struct irq_sim *sim, unsigned int offset) return sim->irqs[offset].irqnum; } EXPORT_SYMBOL_GPL(irq_sim_irqnum); + +/** + * irq_sim_notifier_register - Subscribe for interrupt simulator events. + * + * @sim: The interrupt simulator object. + * @nb: Notifier block. + */ +int irq_sim_notifier_register(struct irq_sim *sim, + struct notifier_block *nb) +{ + return atomic_notifier_chain_register(&sim->notifier, nb); +} +EXPORT_SYMBOL_GPL(irq_sim_notifier_register); From patchwork Thu Feb 14 13:42:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042186 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="jkd0PUwj"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czr4q1tz9sN1 for ; Fri, 15 Feb 2019 00:43:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2394864AbfBNNnZ (ORCPT ); Thu, 14 Feb 2019 08:43:25 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:52553 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394834AbfBNNnB (ORCPT ); Thu, 14 Feb 2019 08:43:01 -0500 Received: by mail-wm1-f67.google.com with SMTP id m1so6349527wml.2 for ; Thu, 14 Feb 2019 05:42:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3tT9dI2HnjqRSVUEzTyodAkGk3Ngn/N6QgaGevUjPNY=; b=jkd0PUwjOzPH4qsvwvqjF2fkDSxYBg/G06zCfYzsxOeYrQ0vQRJCssYxQcrL5QVNme kgTy6tUaGUmALn7WEY8m8cizyyz3JDSxiuQWXUppkR4+9Rzq7u77l7rG3WU086ifvA3G 1TupZ44wEFmp3wXNtU1d+Q3YOdZP00PMTv9R89PBdVlkRkalRXntZ3uEawetyFDA0pSQ zbeul3aBZUj6ubwnOC8N2uGGr91bc8qv0xlL4EvsgIvZpHlj76SJ74s4zva1khleqOu4 WVxF4Z9lvxXMrmNgTxfVDnQteIuyOnuHhWYlowPwnWydc5PlrOQe1zG3Fd9Y1+Y950xg Vg5A== 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=3tT9dI2HnjqRSVUEzTyodAkGk3Ngn/N6QgaGevUjPNY=; b=Wdujso/naPOwKwTb7cJj2YESYIthfqloK4ZRLl/8dtg/pJDzI8FnDhHttbrjRxC2r3 T1D/2gDcQaamswW9nwz6ve1GTvXWSuUpWu7gm0UnGjU16VDZKQI7UqVfAaw7TouJmHfo hx0aAHcGy9tVURR3btuT4OgQjNeXRmEBRuovHzRVlHj7sBZZCHrDafjY1QKJj7pGPHsY gFtQa2B9e67omycaeG+Otqhp4NS63iYEMGsbZ0i1iEZFoF9mt0DXWIuUtwTZu+RogDJP ulD8gXmZceEPXuAp+xEVCDNh4I/x6G3r30JSccsjMXkmzgYk2epU+2+HwrD+WBY9+YPZ 7iYQ== X-Gm-Message-State: AHQUAuZOeZgIiLuVO4804Wb/B+Ztz2Tx85LorAJd42IDnrsGxDU2tBeM Xpk9PDqN3+XFV6SuA1SX8+8Tbw== X-Google-Smtp-Source: AHgI3Ib/FDyR2aGbifEGhAcZlod8zSN17S2mMYzgY6Xhm3uv1LXS3FApCXtgH4jVlHK816Irx1eqLg== X-Received: by 2002:a1c:c904:: with SMTP id f4mr3001486wmb.42.1550151778163; Thu, 14 Feb 2019 05:42:58 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.42.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:42:57 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 2/7] gpio: mockup: add locking Date: Thu, 14 Feb 2019 14:42:27 +0100 Message-Id: <20190214134232.3821-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski While no user reported any race condition problems with gpio-mockup, let's be on the safe side and use a spinlock when performing any changes on the dummy chip structures. We're using a spinlock because a subsequent patch will register an irq_sim notifier which holds the irq_desc lock and if using a mutex we'd get the "HARDIRQ-safe -> HARDIRQ-unsafe" lockdep error. Suggested-by: Uwe Kleine-König Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 50 ++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 7 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 6a50f9f59c90..9697bf622284 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -54,6 +54,7 @@ struct gpio_mockup_chip { struct gpio_mockup_line_status *lines; struct irq_sim irqsim; struct dentry *dbg_dir; + spinlock_t lock; }; struct gpio_mockup_dbgfs_private { @@ -82,29 +83,53 @@ static int gpio_mockup_range_ngpio(unsigned int index) return gpio_mockup_ranges[index * 2 + 1]; } -static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +static int __gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); return chip->lines[offset].value; } -static void gpio_mockup_set(struct gpio_chip *gc, - unsigned int offset, int value) +static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int val; + + spin_lock(&chip->lock); + val = __gpio_mockup_get(gc, offset); + spin_unlock(&chip->lock); + + return val; +} + +static void __gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); chip->lines[offset].value = !!value; } +static void gpio_mockup_set(struct gpio_chip *gc, + unsigned int offset, int value) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + spin_lock(&chip->lock); + __gpio_mockup_set(gc, offset, value); + spin_unlock(&chip->lock); +} + static void gpio_mockup_set_multiple(struct gpio_chip *gc, unsigned long *mask, unsigned long *bits) { + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); unsigned int bit; + spin_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) - gpio_mockup_set(gc, bit, test_bit(bit, bits)); - + __gpio_mockup_set(gc, bit, test_bit(bit, bits)); + spin_unlock(&chip->lock); } static int gpio_mockup_dirout(struct gpio_chip *gc, @@ -112,8 +137,10 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - gpio_mockup_set(gc, offset, value); + spin_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; + __gpio_mockup_set(gc, offset, value); + spin_unlock(&chip->lock); return 0; } @@ -122,7 +149,9 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + spin_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN; + spin_unlock(&chip->lock); return 0; } @@ -130,8 +159,13 @@ static int gpio_mockup_dirin(struct gpio_chip *gc, unsigned int offset) static int gpio_mockup_get_direction(struct gpio_chip *gc, unsigned int offset) { struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + int direction; - return !chip->lines[offset].dir; + spin_lock(&chip->lock); + direction = !chip->lines[offset].dir; + spin_unlock(&chip->lock); + + return direction; } static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) @@ -283,6 +317,8 @@ static int gpio_mockup_probe(struct platform_device *pdev) return -ENOMEM; } + spin_lock_init(&chip->lock); + gc = &chip->gc; gc->base = base; gc->ngpio = ngpio; From patchwork Thu Feb 14 13:42:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042185 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="ApVZHJ0i"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czq3mxSz9sN9 for ; Fri, 15 Feb 2019 00:43:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438933AbfBNNnZ (ORCPT ); Thu, 14 Feb 2019 08:43:25 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:54818 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394847AbfBNNnB (ORCPT ); Thu, 14 Feb 2019 08:43:01 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so6341281wmh.4 for ; Thu, 14 Feb 2019 05:43:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=OHEGtWQDJDJbv5unGb3dQCc3YvaLBb+lnM8n1qgpdn4=; b=ApVZHJ0is3WajH6JNVEIGlqSMsRegARewDFyajfi6Nj49CdnbiLYXCCj8izWCHe4ag NvQIZxvajeaXPoKTXKTx/priLfDn1Ka4e0+KuKM4tnS5XuggibFBsSifokPwx9mTQrma uNk1s/WMdtNqM6B0U4JyIkOsezUcMTpHCpswLROYQOZYuw0zd06XQJdOt/ZfxMzqy1eH K/k/jgRLV+9PbAFhavIk5x5/nnrTRdLbKqobVjt2CoYZtvtURQMHSuwjGcVvHiB0aEPL tYcu/B8dqFdpz0w7b0wIftJ3eDowtTA498XcZFIkYwsyHeOVNcWo1W6+CRpgr+phrqLw nktg== 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=OHEGtWQDJDJbv5unGb3dQCc3YvaLBb+lnM8n1qgpdn4=; b=jg5qUJAQWMOFZ/WkTqqkbdH1Qn99EkRvwfPGXGySmoQPSKnHS6Z3zdv3ho/NIjlSKo OGfb5a/S1A6bwMftsJtRvP8/qNzQQPjfOLx+WxJc0oiQkoMUISYQFC/oCK18f1bHA5CT GKGHtSinBdfUXx0Ka0qd27RU7haM9bUTJVlHi8ItkRxRkKqgSXp2BVIc0u9QKpAnhUeI O1WUq392pgMng7Icl239pLtijaC1zcK085QYcidUWlMv1Oj/opt/Cu0S2IjN1hlDj2ih jS0k5lYcZhYqw3XxHkMMzVOWYXzCUwsBdSLhbjDUM9tpmbAt3siYbEgw7W/hgUahnq5C cY5w== X-Gm-Message-State: AHQUAuY5StYiL7B7P4uLjTHgn4emlUDoPAgCxKU+udCggvgJ5PG+rgM3 dq+udu5K6+i/+bXgiFg2gc0NuLWMXmc= X-Google-Smtp-Source: AHgI3IYTfleacXs1UGUNtBJRJ1stlx64NS8UYAJnGvcxDLXSq0rc9/g01caHzcubUwHubrhFfA7pCA== X-Received: by 2002:a1c:96ce:: with SMTP id y197mr2924926wmd.36.1550151779297; Thu, 14 Feb 2019 05:42:59 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.42.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:42:58 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 3/7] gpio: mockup: implement get_multiple() Date: Thu, 14 Feb 2019 14:42:28 +0100 Message-Id: <20190214134232.3821-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski We already support set_multiple(). Implement get_multiple() as well. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 9697bf622284..6deed33dbbef 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -102,6 +102,22 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) return val; } +static int gpio_mockup_get_multiple(struct gpio_chip *gc, + unsigned long *mask, unsigned long *bits) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + unsigned int bit, val; + + spin_lock(&chip->lock); + for_each_set_bit(bit, mask, gc->ngpio) { + val = __gpio_mockup_get(gc, bit); + __assign_bit(bit, bits, val); + } + spin_unlock(&chip->lock); + + return 0; +} + static void __gpio_mockup_set(struct gpio_chip *gc, unsigned int offset, int value) { @@ -327,6 +343,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->parent = dev; gc->get = gpio_mockup_get; gc->set = gpio_mockup_set; + gc->get_multiple = gpio_mockup_get_multiple; gc->set_multiple = gpio_mockup_set_multiple; gc->direction_output = gpio_mockup_dirout; gc->direction_input = gpio_mockup_dirin; From patchwork Thu Feb 14 13:42:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042184 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="sv75zeUZ"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czc74lSz9rxp for ; Fri, 15 Feb 2019 00:43:24 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436757AbfBNNnY (ORCPT ); Thu, 14 Feb 2019 08:43:24 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:52557 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2394864AbfBNNnC (ORCPT ); Thu, 14 Feb 2019 08:43:02 -0500 Received: by mail-wm1-f68.google.com with SMTP id m1so6349649wml.2 for ; Thu, 14 Feb 2019 05:43:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1nnfjvlRfLgBJ7Ayp1DnO3Th2WGXGDjW3+e0QMn8VLk=; b=sv75zeUZH9XenpuYZKa8BEPQoCatl7veeElc9xWqKoE2vSxBqRrJ0Vh8rHoLM5zlcf K3Ev1xdW91zbrODHWYugDa20fRrGWMxc3SvYy3jfnLs0w1ZXaS6YQnFRBkWIi1ZHZ9wH 3k63B7PAjU9j20LwSEDPiHc+Mfln9PcjrE7cgEV8/J4i/Ikb89K7mE/mqPB5AeKdfxA2 mg5jFTuOzQBCUThn7dfvhaUgLsd8Dvqsm+4Uwgu3cPhmOrQ6b0UGHYYIVrYaUGU1cf4C ABzWpInPMqbl5WBpGU7W5tWgoKIQTognZxHTBmODtVDJSRZJWzHkaA6AoOMFmxThamY8 fS6g== 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=1nnfjvlRfLgBJ7Ayp1DnO3Th2WGXGDjW3+e0QMn8VLk=; b=YGQ9Le9qfQwvDCX9uMTNpmLegekR+h3JfFngGP/xqeZf3c+ETdU/kYvZQFhjN2Xa1w GQLlf/KsldIwJCliBh3oGpd/YRUSMWH279ApUL64cPFQMSrYLnWCayF46oRxEgQ1qwvi Eop5KFnTUPZ2XiPvHd7563DYgFvBm0Y99ViUI71Hvw2xztDOJIbxI/nbScD0akbADgDi n7SrH5Vde5POKn2EMVys4dKMOHT9qQJ17PSfluCeQzSSVEjhoA8CE/1R5NVRahT4jbli 5daIewWRzd6xSy751ys1v5vSXMBr8kekroOYWn3v8TO63JICnNZPI5p4H6WNvH07te1k Lppw== X-Gm-Message-State: AHQUAuaunp25Nu0BwZdNcJQ22FKbjbIFIorjEvKMcSid7xHTYpJAYy10 Tgb7YKlh7J4NqOej5PUbNtoIAw== X-Google-Smtp-Source: AHgI3Iby8bmasBr4SX0XXWmV1sB4Y9JPWsPFyjxipnPTbS940m1IVV+0dqD4+4pRo38HVVIZ0DKUHA== X-Received: by 2002:a1c:44c3:: with SMTP id r186mr2837385wma.63.1550151780349; Thu, 14 Feb 2019 05:43:00 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.42.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:42:59 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 4/7] gpio: mockup: don't create the debugfs link named after the label Date: Thu, 14 Feb 2019 14:42:29 +0100 Message-Id: <20190214134232.3821-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski User-space tests no longer use it and we're breaking the interface anyway. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 6deed33dbbef..9d279d641374 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -234,7 +234,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, struct gpio_mockup_chip *chip) { struct gpio_mockup_dbgfs_private *priv; - struct dentry *evfile, *link; + struct dentry *evfile; struct gpio_chip *gc; const char *devname; char *name; @@ -247,10 +247,6 @@ static void gpio_mockup_debugfs_setup(struct device *dev, if (IS_ERR_OR_NULL(chip->dbg_dir)) goto err; - link = debugfs_create_symlink(gc->label, gpio_mockup_dbg_dir, devname); - if (IS_ERR_OR_NULL(link)) - goto err; - for (i = 0; i < gc->ngpio; i++) { name = devm_kasprintf(dev, GFP_KERNEL, "%d", i); if (!name) From patchwork Thu Feb 14 13:42:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042183 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="jllBMCP0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czb2bnhz9rxp for ; Fri, 15 Feb 2019 00:43:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436835AbfBNNnR (ORCPT ); Thu, 14 Feb 2019 08:43:17 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:33951 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436754AbfBNNnD (ORCPT ); Thu, 14 Feb 2019 08:43:03 -0500 Received: by mail-wm1-f66.google.com with SMTP id y185so4344196wmd.1 for ; Thu, 14 Feb 2019 05:43:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CGhY56a8nIJgDsb5sjnpobT0rUV/Z8DFoqhyFGaVyME=; b=jllBMCP0TADIBm7Wuko6SCPiDeehfvOlFElLa9wWSZScgE3T4ixwzHyjClpe3Me0Rw 1C/NUdtzisnHKlU6g7EZIaw59FigkSH0Y6wNsxUb5noYP1zV66tWMp88rZPTGkGS+F3T yPJovgqF6aaBf9iKpjFlad79bwHO2HhFUclfVhwzulQeL1F5J8nq5VG1Tz7SItwVOJzV NAvCx67SZcjhUU9tnGZHuk9sthQjta41uuPx0ZDBaIVm1EEIooi43l/wEUQWmK+Xzo0V Byuloqldo7hEmCVaUj6leNhVuAtIHIKjdF1wlaGwM/x7l09Prhtwl1qCfbT6u1KLoV5B KWhA== 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=CGhY56a8nIJgDsb5sjnpobT0rUV/Z8DFoqhyFGaVyME=; b=unMJtSr0wh5voIzXO/AucV8Lb8HV0vOw2TeoT+bpi+Rglm2tJlzmBV6/+ilqu8zDGg b8RztE4k5HV12TzC7IjsyzT1Kg7ECOPfCddn7DGA4AzF6wWcD3pFtxIdGCrLJ6l5bP+I hGkx/hcAWpm94IpUoOdtOnGdfF7wgChnimqjjek6oFz417B9uN07x+Sa3aR3TiaYxZq6 k61/eNsTEsO4W1rFZxJRatTwZXxalfSVsx3Vkcmwo2yI31+zPOzLkqC8Do9lG1myzQgy rA/eHJ7rQGrMkjcPIBQAyseG9XE/uzIIuhyPUAnApItBGS0WYw41pqlWD0ea+DQ83BFC 3OJA== X-Gm-Message-State: AHQUAuby0uScUD/gxZPxY7F/xkswUq53d8EE1vj/DuG+zvR8LCaGjg43 Kp3pSnRiySwSDM81HS25fSwwZQ== X-Google-Smtp-Source: AHgI3IYxydVGWTe48PLKcfoTF7puoaYTCPRQRFLXGw3NSJwUy2JJ9Y9U/sDP/UWhStAYW5QuDpgMBg== X-Received: by 2002:a7b:c04f:: with SMTP id u15mr2693391wmc.49.1550151781663; Thu, 14 Feb 2019 05:43:01 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.43.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:43:01 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 5/7] gpio: mockup: change the type of 'offset' to unsigned int Date: Thu, 14 Feb 2019 14:42:30 +0100 Message-Id: <20190214134232.3821-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski This field can never be negative. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 9d279d641374..4e7688348c0e 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -60,7 +60,7 @@ struct gpio_mockup_chip { struct gpio_mockup_dbgfs_private { struct gpio_mockup_chip *chip; struct gpio_desc *desc; - int offset; + unsigned int offset; }; static int gpio_mockup_ranges[GPIO_MOCKUP_MAX_RANGES]; From patchwork Thu Feb 14 13:42:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042182 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="RRiJ8WHY"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czW1cwbz9rxp for ; Fri, 15 Feb 2019 00:43:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2438902AbfBNNnG (ORCPT ); Thu, 14 Feb 2019 08:43:06 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:33943 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2436803AbfBNNnE (ORCPT ); Thu, 14 Feb 2019 08:43:04 -0500 Received: by mail-wr1-f68.google.com with SMTP id f14so6568020wrg.1 for ; Thu, 14 Feb 2019 05:43:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=GC+n/jTkiJeclZfnsvak2DYAHje9HHQVbgEzbwl1h8U=; b=RRiJ8WHYgIBmuVZgQb7X5VBCo2glq6x/hLColZh9Sah3akDsalph9pt9dkZQhZI/CE YJqkvrMoJTvcxI+PqVGsxLi88VHO3ks6iqemfJofNKR+UolMKAPLgT1+rGS44VUabf+j G7sFVhw1me+lqG2kxFoqGj2y0d7W9esRr7jLpyrTfFcxd8w9D8LqDFQpmqDdXHVwS5EB pkrnHus5cdQlrDwsUHYVIrKpYyGYCzaL/2U0Wblzoq1x/HbAy84w3WEGjcr6zRH+s9rs uuKn2z/727l2QnnULUu33OaZRES+AeT7kS2cnacstC5B/wfPhGjygZXsQRa9fLQ6QHCX S6/Q== 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=GC+n/jTkiJeclZfnsvak2DYAHje9HHQVbgEzbwl1h8U=; b=HGQV3vg/z4qI4TeYZRAFoPYSarFcAt8SApyNQ+CBx2gxjNBhCgmAM/tISVwCTu1MU/ gP/Zz0VzsmaBct52KTNHwqa7u6KwdM0FR7rYzdl+pON8B95WWveKopzXdhsWPpcIpd5S C0AmWsvE0DcMHkMhGt1mdSAvGVEeCVxCoD/f1pNKRsuaZ3FxlfoQ2ngezqtuiLM1r++2 kc3U+hBSfeecYN//Pkb/XVU/3KoHSUJTz50Gc0xUWgOlb3g/emHqdhm6wsskTJgZh+JF eoslpSenJU8qrs2OoMWDEDHkoTHOfGt1lnLTEF9Z05yCIf7G61JwYwS0H2wP4q23AqqS XtCQ== X-Gm-Message-State: AHQUAua3GcDeoMdEmcusxm9aFwnkJ3ezBI9VFbt7cCigsiMvbeVBhYhV JPnJO1FqwYrd/J0mt3UD3CRV7w== X-Google-Smtp-Source: AHgI3Iaurwk3D39LwZkjUBltMG84gw7qexsg7DrssKGMopEJcuhQKjmPOqE4YPgLH/M5YGBpYo0pdg== X-Received: by 2002:a5d:4fc5:: with SMTP id h5mr2859767wrw.84.1550151782812; Thu, 14 Feb 2019 05:43:02 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.43.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:43:02 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 6/7] gpio: mockup: change the signature of unlocked get/set helpers Date: Thu, 14 Feb 2019 14:42:31 +0100 Message-Id: <20190214134232.3821-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski The unlocked variants only get called from places where we already have the pointer to the underlying gpio_mockup_chip structure, so take it as parameter instead of struct gpio_chip. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index 4e7688348c0e..f1807afd44ba 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -83,10 +83,9 @@ static int gpio_mockup_range_ngpio(unsigned int index) return gpio_mockup_ranges[index * 2 + 1]; } -static int __gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) +static int __gpio_mockup_get(struct gpio_mockup_chip *chip, + unsigned int offset) { - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - return chip->lines[offset].value; } @@ -96,7 +95,7 @@ static int gpio_mockup_get(struct gpio_chip *gc, unsigned int offset) int val; spin_lock(&chip->lock); - val = __gpio_mockup_get(gc, offset); + val = __gpio_mockup_get(chip, offset); spin_unlock(&chip->lock); return val; @@ -110,7 +109,7 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc, spin_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) { - val = __gpio_mockup_get(gc, bit); + val = __gpio_mockup_get(chip, bit); __assign_bit(bit, bits, val); } spin_unlock(&chip->lock); @@ -118,11 +117,9 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc, return 0; } -static void __gpio_mockup_set(struct gpio_chip *gc, +static void __gpio_mockup_set(struct gpio_mockup_chip *chip, unsigned int offset, int value) { - struct gpio_mockup_chip *chip = gpiochip_get_data(gc); - chip->lines[offset].value = !!value; } @@ -132,7 +129,7 @@ static void gpio_mockup_set(struct gpio_chip *gc, struct gpio_mockup_chip *chip = gpiochip_get_data(gc); spin_lock(&chip->lock); - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); spin_unlock(&chip->lock); } @@ -144,7 +141,7 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc, spin_lock(&chip->lock); for_each_set_bit(bit, mask, gc->ngpio) - __gpio_mockup_set(gc, bit, test_bit(bit, bits)); + __gpio_mockup_set(chip, bit, test_bit(bit, bits)); spin_unlock(&chip->lock); } @@ -155,7 +152,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, spin_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); spin_unlock(&chip->lock); return 0; From patchwork Thu Feb 14 13:42:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1042181 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=none (p=none dis=none) header.from=bgdev.pl Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=bgdev-pl.20150623.gappssmtp.com header.i=@bgdev-pl.20150623.gappssmtp.com header.b="FAv5tfvG"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 440czV1STFz9sNC for ; Fri, 15 Feb 2019 00:43:18 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2436806AbfBNNnQ (ORCPT ); Thu, 14 Feb 2019 08:43:16 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:50809 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2438898AbfBNNnH (ORCPT ); Thu, 14 Feb 2019 08:43:07 -0500 Received: by mail-wm1-f66.google.com with SMTP id x7so6308675wmj.0 for ; Thu, 14 Feb 2019 05:43:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rv+yLrYM/s4baO00rTvbo7OidtPL3lmI0907Us/X+r4=; b=FAv5tfvGYZcf0Z4jqzD31m8Oj9VaqC2uicP8r/WgJaw8mtMqzXIorYA9+9YH+HjOUe d7sgUSP0sfTV0XVc3Vw9sU8Wqcp3fpmz+/mwpKCftd4exmLL6GslFcQmcntNzIqmZdR/ Gm5uPCO3oLk+hriljd2UIJJyslFh0CXnr8VpGf8ApLj2K/5TrBpVc1Fd831w/aWEZcnq c5RP3XkvIpplIdHZXYAel6bo41BBxzT3hYv8GWlM8iMH4nHwE4ZjG5b8JIncjVh4uVvm oUvF9U072HeWmpNRyr+HjUxbeema5ABlj2vMTtOmCQvkHtQreqlz3Ei25Hdew7yRsdf7 LQLw== 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=rv+yLrYM/s4baO00rTvbo7OidtPL3lmI0907Us/X+r4=; b=uZMLJBoaJP8e7/dKjKGvunjKw32MnklA4ZHlrWsZ+cWALQyXc/8pfSd/+p4aALfQB2 ETXAq0IeRSbs6+cURxOW2eNFe+QyhSTwKsdAc18mDnTJV+R+Q5hXSvJ6BsahdPZQbiop MEWnmQhd797xzFO+pwkAMbadHnUTzYlOSyWqHAIMugZLGT158O1hcVMLGcjFkkXQsA9k URXc/7xkMJkbzuRgb7i+NkBYwQJdooq1vMWaOTVbrs6ofclWLhQvkL3ttf2dQ4N/oYnA sCn6dzHhInzuAy8/HUhwrkyPO2D14SxNEzNdrURhS4Wa6XAhKTlKb1iebQ/xnYQijhhz bdXg== X-Gm-Message-State: AHQUAuabGXwUDI1RcxTkCpoi4+Vz34Zk3MeGn4RpiBJ/XU/Ar3D7vkuz ACRQMJLZ5jDbIkAXOueX0OZ7RQ== X-Google-Smtp-Source: AHgI3Ib6JPfbkLIkO+JIhk/QG9LSE7ejUUXN0haUjoXr/wMY/+MalVYO9u0pGxQDMBx2TeRRzVrRHA== X-Received: by 2002:a1c:7dd6:: with SMTP id y205mr2635033wmc.121.1550151783897; Thu, 14 Feb 2019 05:43:03 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id 62sm4963460wra.46.2019.02.14.05.43.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 05:43:03 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , Thomas Gleixner , Marc Zyngier , =?utf-8?q?Uwe_Kleine-K?= =?utf-8?b?w7ZuaWc=?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v4 7/7] gpio: mockup: rework debugfs interface Date: Thu, 14 Feb 2019 14:42:32 +0100 Message-Id: <20190214134232.3821-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190214134232.3821-1-brgl@bgdev.pl> References: <20190214134232.3821-1-brgl@bgdev.pl> MIME-Version: 1.0 Sender: linux-gpio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org From: Bartosz Golaszewski Modify the way the debugfs interface works in gpio-mockup. Introduce the concept of dummy pull config which will keep the mockup lines in known state. The pull values can be modified by writing to the debugfs files corresponding to lines. Lines in input mode always report the current pull value, lines in output mode change the line value but it will revert back to the one specified by current pull when released. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpio-mockup.c | 143 +++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index f1807afd44ba..f710df8ca737 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -47,6 +47,8 @@ enum { struct gpio_mockup_line_status { int dir; int value; + int pull; + int irq_type; }; struct gpio_mockup_chip { @@ -55,6 +57,7 @@ struct gpio_mockup_chip { struct irq_sim irqsim; struct dentry *dbg_dir; spinlock_t lock; + struct notifier_block nb; }; struct gpio_mockup_dbgfs_private { @@ -73,6 +76,11 @@ module_param_named(gpio_mockup_named_lines, static struct dentry *gpio_mockup_dbg_dir; +static struct gpio_mockup_chip *to_gpio_mockup_chip(struct notifier_block *nb) +{ + return container_of(nb, struct gpio_mockup_chip, nb); +} + static int gpio_mockup_range_base(unsigned int index) { return gpio_mockup_ranges[index * 2]; @@ -188,15 +196,72 @@ static int gpio_mockup_to_irq(struct gpio_chip *gc, unsigned int offset) return irq_sim_irqnum(&chip->irqsim, offset); } -static ssize_t gpio_mockup_event_write(struct file *file, - const char __user *usr_buf, - size_t size, loff_t *ppos) +static void gpio_mockup_free(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_mockup_chip *chip = gpiochip_get_data(gc); + + __gpio_mockup_set(chip, offset, chip->lines[offset].pull); +} + +static int gpio_mockup_irq_type_changed(struct notifier_block *nb, + unsigned long event, void *data) +{ + struct gpio_mockup_chip *chip = to_gpio_mockup_chip(nb); + struct irq_sim_irq_type *irq_type = data; + + if (event != IRQ_SIM_TYPE_CHANGED) + return NOTIFY_DONE; + + /* FIXME: add locking once we switch to spinlocks */ + chip->lines[irq_type->offset].irq_type = irq_type->type; + + return NOTIFY_OK; +} + +static ssize_t gpio_mockup_debugfs_read(struct file *file, + char __user *usr_buf, + size_t size, loff_t *ppos) +{ + struct gpio_mockup_dbgfs_private *priv; + struct gpio_mockup_chip *chip; + struct seq_file *sfile; + struct gpio_chip *gc; + char buf[3]; + int val, rv; + + if (*ppos != 0) + return 0; + + sfile = file->private_data; + priv = sfile->private; + chip = priv->chip; + gc = &chip->gc; + + val = gpio_mockup_get(gc, priv->offset); + snprintf(buf, sizeof(buf), "%d\n", val); + + rv = copy_to_user(usr_buf, buf, sizeof(buf)); + if (rv) + return rv; + + return sizeof(buf) - 1; +} + +static ssize_t gpio_mockup_debugfs_write(struct file *file, + const char __user *usr_buf, + size_t size, loff_t *ppos) { struct gpio_mockup_dbgfs_private *priv; struct gpio_mockup_chip *chip; struct seq_file *sfile; struct gpio_desc *desc; - int rv, val; + unsigned int irq_type; + struct gpio_chip *gc; + struct irq_sim *sim; + int rv, val, curr; + + if (*ppos != 0) + return -EINVAL; rv = kstrtoint_from_user(usr_buf, size, 0, &val); if (rv) @@ -206,24 +271,68 @@ static ssize_t gpio_mockup_event_write(struct file *file, sfile = file->private_data; priv = sfile->private; - desc = priv->desc; chip = priv->chip; + gc = &chip->gc; + desc = &gc->gpiodev->descs[priv->offset]; + sim = &chip->irqsim; + + spin_lock(&chip->lock); - gpiod_set_value_cansleep(desc, val); - irq_sim_fire(&chip->irqsim, priv->offset); + 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_type = chip->lines[priv->offset].irq_type; + if ((val == 1 && (irq_type & IRQ_TYPE_EDGE_RISING)) || + (val == 0 && (irq_type & IRQ_TYPE_EDGE_FALLING))) + irq_sim_fire(&chip->irqsim, 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; + spin_unlock(&chip->lock); return size; } -static int gpio_mockup_event_open(struct inode *inode, struct file *file) +static int gpio_mockup_debugfs_open(struct inode *inode, struct file *file) { return single_open(file, NULL, inode->i_private); } -static const struct file_operations gpio_mockup_event_ops = { +/* + * Each mockup chip is represented by a directory named after the chip's device + * name under /sys/kernel/debug/gpio-mockup/. Each line is represented by + * a file using the line's offset as the name under the chip's directory. + * + * Reading from the line's file yields the current *value*, writing to the + * line's file changes the current *pull*. Default pull for mockup lines is + * down. + * + * Examples: + * - when a line pulled down is requested in output mode and driven high, its + * value will return to 0 once it's released + * - when the line is requested in output mode and driven high, writing 0 to + * the corresponding debugfs file will change the pull to down but the + * reported value will still be 1 until the line is released + * - line requested in input mode always reports the same value as its pull + * configuration + * - when the line is requested in input mode and monitored for events, writing + * the same value to the debugfs file will be a noop, while writing the + * opposite value will generate a dummy interrupt with an appropriate edge + */ +static const struct file_operations gpio_mockup_debugfs_ops = { .owner = THIS_MODULE, - .open = gpio_mockup_event_open, - .write = gpio_mockup_event_write, + .open = gpio_mockup_debugfs_open, + .read = gpio_mockup_debugfs_read, + .write = gpio_mockup_debugfs_write, .llseek = no_llseek, }; @@ -258,7 +367,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, priv->desc = &gc->gpiodev->descs[i]; evfile = debugfs_create_file(name, 0200, chip->dbg_dir, priv, - &gpio_mockup_event_ops); + &gpio_mockup_debugfs_ops); if (IS_ERR_OR_NULL(evfile)) goto err; } @@ -266,7 +375,7 @@ static void gpio_mockup_debugfs_setup(struct device *dev, return; err: - dev_err(dev, "error creating debugfs event files\n"); + dev_err(dev, "error creating debugfs files\n"); } static int gpio_mockup_name_lines(struct device *dev, @@ -342,6 +451,7 @@ static int gpio_mockup_probe(struct platform_device *pdev) gc->direction_input = gpio_mockup_dirin; gc->get_direction = gpio_mockup_get_direction; gc->to_irq = gpio_mockup_to_irq; + gc->free = gpio_mockup_free; chip->lines = devm_kcalloc(dev, gc->ngpio, sizeof(*chip->lines), GFP_KERNEL); @@ -358,6 +468,11 @@ static int gpio_mockup_probe(struct platform_device *pdev) if (rv < 0) return rv; + chip->nb.notifier_call = gpio_mockup_irq_type_changed; + rv = irq_sim_notifier_register(&chip->irqsim, &chip->nb); + if (rv) + return rv; + rv = devm_gpiochip_add_data(dev, &chip->gc, chip); if (rv) return rv; @@ -415,7 +530,7 @@ static int __init gpio_mockup_init(void) return -EINVAL; } - gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup-event", NULL); + gpio_mockup_dbg_dir = debugfs_create_dir("gpio-mockup", NULL); if (IS_ERR_OR_NULL(gpio_mockup_dbg_dir)) gpio_mockup_err("error creating debugfs directory\n");