From patchwork Tue Feb 12 13:15:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040574 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="x27Blpuz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNVG02zQz9sMx for ; Wed, 13 Feb 2019 00:17:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729684AbfBLNQ3 (ORCPT ); Tue, 12 Feb 2019 08:16:29 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:55272 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729453AbfBLNQ2 (ORCPT ); Tue, 12 Feb 2019 08:16:28 -0500 Received: by mail-wm1-f67.google.com with SMTP id a62so2908728wmh.4 for ; Tue, 12 Feb 2019 05:16:27 -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=pIpW7RFEY2GMQsR5y2sFKJ0v7v9X66ceV9i2CkIDbaw=; b=x27BlpuzZLErXtZWnI2PfiNqVl4JZXqBfY4f5NQULwcZ/4F3B9KC9tMl2FJSo1caAY ZCikvpgGhsBo/1uU5d5TxkSDThNNGOaRkvSMgogLpYe5cSManNhZFt1Tx19OLx2afCBv 6z2SA1+8LFmvQhJV9rhwDRJ/gDQoVI3RRYMdpd9dMicT7/WQlStHQ0xqTO0FBojj//Pv 41RxL4viQjA2sXjEuUqyPrbuwrG4p3O6dm3hYhWuvWM6nOu99Ka4gOCFKUboq1iKIGLD nFe9m6egnQaRzSFoJXzfvdStnH7gVSo5vfrrRlcR14aQDdMDahCs1elGlsxiAFDfRSfN 1Zsg== 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=pIpW7RFEY2GMQsR5y2sFKJ0v7v9X66ceV9i2CkIDbaw=; b=ULgJA8QjwWCpmKjOxx9L0hgJknG3IwzU14jOw0jFbzHmRcv3bpiPgYVdHuuz4jNdfU Seu5CoUTJ7iChCYfXvJT8te2G1vdh4iMitw2icOR0MpfVgPPfgKnq/FwCjdMW6W1x02K lX9182Gjh1CTkUeN7nRnQeBJUabMN7ME5hYOk4zNociyY0XTTwqeZKmn9TmH6LOuE8VT fRUn+tgOUagaXUlHEjrJYn9kVByhJf46AiKutieEgupGEA7lpZyNg1oF4d1xKACad/9/ ayclU+tuQQrIpleXGQUJrQG/MiHXhOhqZv4AN+mA6i1obc0hjWfhLejFWl71gMbr1qWg vx/A== X-Gm-Message-State: AHQUAuYdFvs5CO1YnXDxNiaNtsKZvCz2HaHFJOdTUiW0DNHVMq99xWV5 /Y07k/7KVxszhZJm2qrrg6S4jw== X-Google-Smtp-Source: AHgI3IY3YQTnS0SNXpkItW4onZRWckiuwkyiQqg6Wa5GLVRTyW7BudZ4qq5wM1HvqYf9PNHR7NXP0g== X-Received: by 2002:a1c:f207:: with SMTP id s7mr2884154wmc.87.1549977386303; Tue, 12 Feb 2019 05:16:26 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.25 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:25 -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 v3 1/7] irq/irq_sim: provide irq_sim_get_type() Date: Tue, 12 Feb 2019 14:15:54 +0100 Message-Id: <20190212131600.18960-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 that allows users to retrieve the current irq type of dummy interrupts. Internally: store the type in the line context when the irq_set_type() callback is called. 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 | 2 ++ kernel/irq/irq_sim.c | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/include/linux/irq_sim.h b/include/linux/irq_sim.h index 4500d453a63e..c73be0a2c15c 100644 --- a/include/linux/irq_sim.h +++ b/include/linux/irq_sim.h @@ -22,6 +22,7 @@ struct irq_sim_work_ctx { struct irq_sim_irq_ctx { int irqnum; bool enabled; + int type; }; struct irq_sim { @@ -37,5 +38,6 @@ 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); +unsigned int irq_sim_get_type(struct irq_sim *sim, unsigned int offset); #endif /* _LINUX_IRQ_SIM_H */ diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 98a20e1594ce..74561a0dca65 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -25,10 +25,20 @@ 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); + + irq_ctx->type = type; + + 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) @@ -180,3 +190,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_get_type - Get the type configuration for a dummy interrupt. + * + * @sim: The interrupt simulator object. + * @offset: Offset of the simulated interrupt for which to retrieve + * the type. + */ +unsigned int irq_sim_get_type(struct irq_sim *sim, unsigned int offset) +{ + return sim->irqs[offset].type; +} +EXPORT_SYMBOL_GPL(irq_sim_get_type); From patchwork Tue Feb 12 13:15:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040575 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="x780J2pg"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNVG5lgTz9s4Z for ; Wed, 13 Feb 2019 00:17:10 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729661AbfBLNRJ (ORCPT ); Tue, 12 Feb 2019 08:17:09 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50531 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727312AbfBLNQ3 (ORCPT ); Tue, 12 Feb 2019 08:16:29 -0500 Received: by mail-wm1-f67.google.com with SMTP id x7so2903080wmj.0 for ; Tue, 12 Feb 2019 05:16:28 -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=KudoSL2eX7oA8yYhs/QJyb1yYcVSQLsZjpboPNVdhXI=; b=x780J2pgnSH3MCPhRODpXksDoTsMpVGDc9hCflmyDdsyhRO6lW8ITYpZ5SLLpzGPQr Aps3W4QQeNS/tXG0q1QrpaO4oAo5Y86vNLvOy/vvGuXadEiwB4ZHmL5PKEMTyDwfyIO5 Cjq7hv5NuL92qbOKQAuTk5aQLjStNJZttsRA6WXuibiTpaqSuOssF8gdPEM0boLtlyjI Ngd5GaB4noXvDI9X4cwI/ad0/WDr8daESeicXySkIPc8xAZWUHnDXggcDidmTXlXRvu9 Z11IGQE6IGNUtP4ot7FXEwe0RT3lrvxeWC47ka6DgUIgoJ37uYcEyi10EOGBJ9LhVD9/ dkEA== 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=KudoSL2eX7oA8yYhs/QJyb1yYcVSQLsZjpboPNVdhXI=; b=JumcUMel8RNIM72I77XJsxFnGhnnftKOILaT8jJHVh80d6F9neIXlRv1XGtmrKcz0D JPD596o59O/tc7KdoubvAYq86EeVpAbfiv/C53ckRhcXAebgsSVqs5QGzbdurZZmbuG/ Oe9GfjeG/vuXUPItnd2cK0iP9LdEcPEdJIsWxESbAQi5Y7xvMwO7DqGl8YcF/nDrN6yu NUgu9l6tT8OVDTqeMnuKKZGnsxdx4gAbvX16X1nw+ZxSgChwuT7Sctu5nwUm/AvvjHpJ e/p65kLIMrWWfOMH1jZylGCPZnL5GFWu3/FK5vMUMGk3140MSwFyKgXM3vjb961tCBmY GRoA== X-Gm-Message-State: AHQUAuY/tb5EwW7VWuk0Yta1A0Rl5jmx7B5uuCsfi6QgLt0ogh4yPEjt sU+ePW2eTapDdSU9sX+SUnBgBA== X-Google-Smtp-Source: AHgI3IY75La6dsQ/EdfJEDRk+ekOrHl7rzJRhQE8dDX7mfnqTjmedMFCl/DlP4Djc/RSyukfmxzqZw== X-Received: by 2002:a1c:9c0a:: with SMTP id f10mr2969541wme.73.1549977387350; Tue, 12 Feb 2019 05:16:27 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:26 -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 v3 2/7] gpio: mockup: add locking Date: Tue, 12 Feb 2019 14:15:55 +0100 Message-Id: <20190212131600.18960-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 mutex when performing any changes on the dummy chip structures. 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..b4c1de6acf74 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; + struct mutex 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; + + mutex_lock(&chip->lock); + val = __gpio_mockup_get(gc, offset); + mutex_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); + + mutex_lock(&chip->lock); + __gpio_mockup_set(gc, offset, value); + mutex_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; + mutex_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)); + mutex_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); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; + __gpio_mockup_set(gc, offset, value); + mutex_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); + mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_IN; + mutex_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; + mutex_lock(&chip->lock); + direction = !chip->lines[offset].dir; + mutex_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; } + mutex_init(&chip->lock); + gc = &chip->gc; gc->base = base; gc->ngpio = ngpio; From patchwork Tue Feb 12 13:15:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040569 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="WiMGI5N5"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNTc33W5z9s4Z for ; Wed, 13 Feb 2019 00:16:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729803AbfBLNQf (ORCPT ); Tue, 12 Feb 2019 08:16:35 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36142 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729781AbfBLNQe (ORCPT ); Tue, 12 Feb 2019 08:16:34 -0500 Received: by mail-wm1-f66.google.com with SMTP id j125so3006280wmj.1 for ; Tue, 12 Feb 2019 05:16:33 -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=1WGhX7lh3GClMJMpleuT6xjtmXeQaabY429BNB+za3s=; b=WiMGI5N5BHRyGyDI3JyZpi8tZbMC+IIoTFwOymQ2pD4PIx6nJqFH91qqi159XnxJl/ kfonsLFklu6igy56vst/VWOqR+UVGdVfGGbVSiljGcUfsllpbNVg7VXNOaFaSChT9xry 8VH3GowKYSFGFs+epU/yTY2DZmnG3NsWmn/84T+5ZJ3VOLrXh6LYzSFTVcmQSkwRRNmi exOuva1T4YR87KRLyShRShMouToiPeUueT2nXPMK5pMVxyYViF25PAeyLCPqu10rcoGp oDuwxqaIAehOIGtSrXEKLnH29w8mVPBK+EhpG8147AIvg/suI/tXn44fmTOX+bRhMzuy ycsQ== 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=1WGhX7lh3GClMJMpleuT6xjtmXeQaabY429BNB+za3s=; b=X0Etjd2FT9XrZojqPvpWu6zhSPp8LQ7IuV6inJEFMsPP+3MzRc62NbV24AKG7nzv21 qA8HfaL1mN6wLRhT9X1U8DsVuAsRrFHKT8HARcU+FWXh6ry81i1X2Sz/2gGa7dfx5bWP uHQKjEGzVWr7Q+XnEb1nVkstsSOv6tYTnicDzbK12mcS9OETX8Ihi4sDpsawYpP56Rqh SrhpSACBWwg/UzmtogLHNPxAXTTL2MVHdhVTzk2Jqi2qT38tmmLmVNbWXy+meJcwcXJO DV0glpLSVjgdAR9JoEEsmaXFUl5q45pIMyeL/RNIvEoOYJYU2UocG+E+m4zJt2e3X+tq 0SfA== X-Gm-Message-State: AHQUAuaUqZToR6uBtgDbWxFthE7bIrt9ubCi3ijC8m73JggfxGLX5yUv hP7h7AIdUmlli9PLauXkXHOzCA== X-Google-Smtp-Source: AHgI3Ibiu8kjqyTICtxueDiYC08RxBuJjmr7BIK00Vyz/r0mBobuiVeSfOAGuTef8Fu2r0+95ALwdg== X-Received: by 2002:a1c:6c01:: with SMTP id h1mr2845111wmc.113.1549977388373; Tue, 12 Feb 2019 05:16:28 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:27 -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 v3 3/7] gpio: mockup: implement get_multiple() Date: Tue, 12 Feb 2019 14:15:56 +0100 Message-Id: <20190212131600.18960-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 b4c1de6acf74..1c945c967f60 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; + + mutex_lock(&chip->lock); + for_each_set_bit(bit, mask, gc->ngpio) { + val = __gpio_mockup_get(gc, bit); + __assign_bit(bit, bits, val); + } + mutex_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 Tue Feb 12 13:15:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040573 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="X5hXNxnD"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNV82Vjdz9sMl for ; Wed, 13 Feb 2019 00:17:04 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729671AbfBLNRC (ORCPT ); Tue, 12 Feb 2019 08:17:02 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:36146 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729731AbfBLNQb (ORCPT ); Tue, 12 Feb 2019 08:16:31 -0500 Received: by mail-wm1-f68.google.com with SMTP id j125so3006346wmj.1 for ; Tue, 12 Feb 2019 05:16:30 -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=03DPhzkzBjEgdOWVhFdZb0AzmHi0UfZRp68bha7kwZI=; b=X5hXNxnDj50c74LOzFgWWBYtEXNZpCFHRbKByF8qVhS6QbBZCACrAFJEkMfrn2aDud mmo4BNVuiVVfwgi22bPUk3Yxi6F+xsTOnL/LeoT14ErbiJCznecYIofLU35gcftDuwNo /VjFg4hxQVOp8O/TvET67FLucznfVXj82JAKOHS6Tt55aV0XjnnjmJ5kz7vNLNfzdepz 9J3w1QI1uGj4h0hBr3l3xoWOHufRlv0fvnLkixBCrMUs4dTF6CerShDwa6YSFSD54XZ4 o9zlSY+mVbhQ4sg88YxlV7yLW3zCx/i1IaCX2lUjqYYgkIAR7sc4rEzfsLqVYMCki0zg zsQw== 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=03DPhzkzBjEgdOWVhFdZb0AzmHi0UfZRp68bha7kwZI=; b=j2Nffhy6ccA2Ym9aP/i1HD2ssvSMEN6emoqdmfIguYMmWCY2GpAK8MrVrpP/mzNx4d nTivNDuy4qMuZDBC1V80WZFKnRnj2wg2XL1Q0uHZYaf1q6Y33IKLgeOEwLxcljEwr7XI kJ4qY8+gwPrnNmUMDKK/kaD9IPJRKvZ93gDq7zw/QC8KL31dz7oMLaESiht/xW96pfxG kKHtkWWzjDepC0T+fI68GAJFmvQztCMF2bLp5ls8XjzMe/Hj4FBUsq09M1XLTkQObv1L mYVHsrw028JzahJP+jGlAwBMdeHJONaADqmC3sws1IWVE/9BNpAixalL3aDCPuTyXF/N cVXA== X-Gm-Message-State: AHQUAuaVibkdGrulOy7UQOkQhOLSQBMe0NVBz/5EwCs6Y2wxIJkXPl1g txcwnilIFUJAD6PalBUqgwBJpA== X-Google-Smtp-Source: AHgI3IaVVoe2st0QHha7U3zkiT37/graZaxT3zmucq+CW+VBQox08//RACgvFe4lbPLxwR5sFLsNzQ== X-Received: by 2002:a05:600c:2255:: with SMTP id a21mr3041889wmm.31.1549977389481; Tue, 12 Feb 2019 05:16:29 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:28 -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 v3 4/7] gpio: mockup: don't create the debugfs link named after the label Date: Tue, 12 Feb 2019 14:15:57 +0100 Message-Id: <20190212131600.18960-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 1c945c967f60..0317917a3678 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 Tue Feb 12 13:15:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040572 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="prLohWPz"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNTg741Gz9sN4 for ; Wed, 13 Feb 2019 00:16:39 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729792AbfBLNQh (ORCPT ); Tue, 12 Feb 2019 08:16:37 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36147 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729755AbfBLNQe (ORCPT ); Tue, 12 Feb 2019 08:16:34 -0500 Received: by mail-wm1-f66.google.com with SMTP id j125so3006432wmj.1 for ; Tue, 12 Feb 2019 05:16:31 -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=2krnFxmiomVyVDb/8h+/xtPx5s60ffpJQDYiPXgWEoY=; b=prLohWPzjO6r7oy/SqAxGyYcNu9nV9Ckew5tqyG8tffL0ODI5q59dasHbcZ+PSsRQl pPY76sfs0/D180MH1FR6jWJYSJZypTsJB0uL27Q4EoELbForT4U2jMhXZ5jVgIOmhNSK nx2v2bIMooJ935xBD2vmPgSa3UtA2xtMXQ/UfsKgkPX6QYNidIkjVTvSMwykxcf8nIWD T4qRm5yQ0tQ+cPAmVVucKVWYwEDikwVC8dS0zioqFrNmGHlelZIGOG3AyRaYt/zfja53 t0/jO3Wznd2g2gM4jlswDbCYKCt+sLwuOAsygDP6xFR/niVkvlEzswhl3VcUZbaFnTt6 h+eQ== 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=2krnFxmiomVyVDb/8h+/xtPx5s60ffpJQDYiPXgWEoY=; b=D/oFcIjjB9mtiGNmyGh/7AZQBth1Wp3Y4fpLKxh5COvMdX83VYxLbv7XVZQ7iyOKQv oaoOmhINCBQ6AUMiJOIrd9/MYKLBYFkCiciScy2At374nyyj6qQWg8J86+QyJSu/IKFY 4B0ypK2tiYsbMf+U7Y/EVrJ7OD+/2Vf1eYKZiiWWH9uqIQwjBEYuikAyWUbfffRxDwXj BdqkHXCWaQGu8p5RmKmv4pvvLArQnFGumwNq0dhHAP3cI9EfjROhTUvBPR626+36xDKD WqBctAbbDEgs8geKRuu8i/e1inObSZxel7rhb2wL8Qs92jpfMXND77DBWbEQgbSkHr4G soMw== X-Gm-Message-State: AHQUAuaKZF04Hh3sqG+ZIXycv7uTf4Juip28zjBW6helO3moGLUNXVXQ KYFnkP7JvYuPWd26b8NfmHgIOzDxBbw= X-Google-Smtp-Source: AHgI3IZ0FO5EXo2xkPmHpTih1JaNjzGXV4g53ldcf5K+gF22Re24JjofQdkHGq1HZbO0gwYe2r2rmQ== X-Received: by 2002:a1c:be04:: with SMTP id o4mr2830848wmf.19.1549977390893; Tue, 12 Feb 2019 05:16:30 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:30 -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 v3 5/7] gpio: mockup: change the type of 'offset' to unsigned int Date: Tue, 12 Feb 2019 14:15:58 +0100 Message-Id: <20190212131600.18960-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 0317917a3678..433adb3b4617 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 Tue Feb 12 13:15:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040570 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="N9TwKyfx"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNTd3XHvz9sN4 for ; Wed, 13 Feb 2019 00:16:37 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729781AbfBLNQf (ORCPT ); Tue, 12 Feb 2019 08:16:35 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36151 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729775AbfBLNQe (ORCPT ); Tue, 12 Feb 2019 08:16:34 -0500 Received: by mail-wm1-f66.google.com with SMTP id j125so3006518wmj.1 for ; Tue, 12 Feb 2019 05:16:32 -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=2P/9cB+jmoaw2Dnwldpp3xOYGEGj2ZimLHwmer8wLno=; b=N9TwKyfxR4kWTjYcgCqmgbbSUXyvW9k8NyGdGjt5L1rnZzRGcHCA8H7ReNjYztGMkC DS3tm71gbANaJofKpJXeL32aeXjNQxu/6FsDrTznFXobTRUaeywX1Lh5hmzDfYrVPSPn 11GWpfDOTy/IXjMOn1TppmzVecx5JTGMxs8zKKJTE543wyRRJB7kf20khvOhCh9ROjrL dY4zs1s/NaKZ6toTD/dRALa+FddeV9M1bsGyrztptLV+ObJ/v7Oq4b8eAhLM7IAcO+yY +xYxQx/1ZMya32Q7kN6gw0478Afg9QVmQspDxa8OUvLIdCOd5cW9m7LZj9PmKllGLWal i1yg== 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=2P/9cB+jmoaw2Dnwldpp3xOYGEGj2ZimLHwmer8wLno=; b=G1Or/OTfsvwiEv/VcpHnR4nUuloQX5+g7RRFC/G9td2ERBLg1ToO8eQ24vdKRU/vcv nrMX6GokAqrT13CxCAr+gKbT3iUGqrTsoWX+yUHp1PNOhKq4mSxOsnK2WwPo1carTk34 Z5cO0ZUPSR8mgIJP4oB0VUEJmYUQ68v+dV/nBMtv7QlonaDSH+aFLtQ17B1/AShZB8tK 3UIf/lGM+1M7sqFOnEtWH2TPlW1BvHRG97VqPl/PozB1In8J6+EZbF9krXvPdw53g+lv fM17DwSFo+d8X7ueKy1rZCJ7HMTymLUjY7aiW0njpbHbH6tI0xMDwIz1iTGQONapfySv Ubjw== X-Gm-Message-State: AHQUAubWVdLFOH4bHCKFXwkpr9/bnROfAKuk5TRrQckG9B7L8FZEOud+ 0HEC5xKQboDicdhYzC/pggTIlw== X-Google-Smtp-Source: AHgI3IbKcaAuGkqVqhdurCQDKWqdhEPZeudupZK7lofuateHP8vq9Sb7lUGbH3JDa1l9A8K3r7NRdg== X-Received: by 2002:a1c:2c6:: with SMTP id 189mr2817107wmc.21.1549977392171; Tue, 12 Feb 2019 05:16:32 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.30 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:31 -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 v3 6/7] gpio: mockup: change the signature of unlocked get/set helpers Date: Tue, 12 Feb 2019 14:15:59 +0100 Message-Id: <20190212131600.18960-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 433adb3b4617..c498b0fbbec8 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; mutex_lock(&chip->lock); - val = __gpio_mockup_get(gc, offset); + val = __gpio_mockup_get(chip, offset); mutex_unlock(&chip->lock); return val; @@ -110,7 +109,7 @@ static int gpio_mockup_get_multiple(struct gpio_chip *gc, mutex_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); } mutex_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); mutex_lock(&chip->lock); - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); mutex_unlock(&chip->lock); } @@ -144,7 +141,7 @@ static void gpio_mockup_set_multiple(struct gpio_chip *gc, mutex_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)); mutex_unlock(&chip->lock); } @@ -155,7 +152,7 @@ static int gpio_mockup_dirout(struct gpio_chip *gc, mutex_lock(&chip->lock); chip->lines[offset].dir = GPIO_MOCKUP_DIR_OUT; - __gpio_mockup_set(gc, offset, value); + __gpio_mockup_set(chip, offset, value); mutex_unlock(&chip->lock); return 0; From patchwork Tue Feb 12 13:16:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1040571 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="N28W6ROK"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 43zNTf4MbWz9s4Z for ; Wed, 13 Feb 2019 00:16:38 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729750AbfBLNQh (ORCPT ); Tue, 12 Feb 2019 08:16:37 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:39643 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729792AbfBLNQg (ORCPT ); Tue, 12 Feb 2019 08:16:36 -0500 Received: by mail-wm1-f65.google.com with SMTP id f16so2975686wmh.4 for ; Tue, 12 Feb 2019 05:16:34 -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=TR8fN5gyVX89LMryH+pTW41FkSfSn7wKIjkzZ06DSdM=; b=N28W6ROKxyftPph12R1t88YbjhjOBrlMgcPrG0FvMKCtBPC6Atv663h47CWzBQZSGb eRZlcduFp1rfLLGTQu1xyMazq4fhrvwjHZ96LwMTWqKab/CcrkLWfnKmI+L+jQpmcCnw o8p12MaRfdy0Q/Ew1a+q7FLC+Fm5soeFU0jxJBlhZqouvHZMYFBP414etfnBPWrcGKe6 KvOd7cBy5nWNn/zDWTwQ8GOt9X0YeeXMSPcOzvxgF7fLsrfDMn8teSRkYh7ezgghPfiS mLY+Rxnea9WEcYSMfv5VI5LLBUpGthvQRzTkYg0ToLFw8zM34ZBg02c+Zs7kEnlEKyjj ZWHQ== 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=TR8fN5gyVX89LMryH+pTW41FkSfSn7wKIjkzZ06DSdM=; b=V4j53d+4iF/Aht4Fu3mUR6krwRF8KucfS+cOTCn2aMNsavqc+/R/RrKHSidkXJbzQ+ y46aybzVkkpwst3R5z021//x9qjnGkTH/No2vbNSNhJ7qQtyxK6AWWIQjjwfX+9qu01g zDJJPf+xbVgNhtYvea0ObDBpQTrvVOCK0RFiQSNDiTkU1F+71lD8giZJG6csMvq4SrYN LCBf4lznYsLL19aFtWrdkrzjvap0BkuBEnJj7ySW8Y8te66vJe7cd+4qdr66z4oxm3Yh Cvu0GxZDUi/lmKE9sSBvlKoT1r66LmTVc+WzSnmLNvfAaw1Yq+1LXr0JvAezfdlOptiP Z0aA== X-Gm-Message-State: AHQUAuatLZgT9Pha1WfqGnMMckOBaCcAzsrbZb/lRPYLSLLanwMr+9y6 drHFrxjoyx792193khA1wkVydA== X-Google-Smtp-Source: AHgI3Ia5vFk+UnINmcrjOvhY3bm2GltlwWF7EI/KakoEYxQqWQlz2OKY2B9KGT8v49/Go9GiDm01UA== X-Received: by 2002:a1c:23c4:: with SMTP id j187mr2879130wmj.13.1549977393240; Tue, 12 Feb 2019 05:16:33 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-38-32.w90-86.abo.wanadoo.fr. [90.86.93.32]) by smtp.gmail.com with ESMTPSA id p6sm5478517wre.63.2019.02.12.05.16.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Feb 2019 05:16:32 -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 v3 7/7] gpio: mockup: rework debugfs interface Date: Tue, 12 Feb 2019 14:16:00 +0100 Message-Id: <20190212131600.18960-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190212131600.18960-1-brgl@bgdev.pl> References: <20190212131600.18960-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 | 116 ++++++++++++++++++++++++++++++++----- 1 file changed, 102 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c498b0fbbec8..6424bd710de5 100644 --- a/drivers/gpio/gpio-mockup.c +++ b/drivers/gpio/gpio-mockup.c @@ -47,6 +47,7 @@ enum { struct gpio_mockup_line_status { int dir; int value; + int pull; }; struct gpio_mockup_chip { @@ -188,15 +189,57 @@ 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 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 +249,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; + + mutex_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 = irq_sim_get_type(sim, priv->offset); + 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; + mutex_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 +345,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 +353,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 +429,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); @@ -415,7 +503,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");