From patchwork Tue Feb 19 16:06:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044757 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="Lxqk8665"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lx21Q7wz9s21 for ; Wed, 20 Feb 2019 03:07:02 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729018AbfBSQHA (ORCPT ); Tue, 19 Feb 2019 11:07:00 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:39235 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728333AbfBSQG6 (ORCPT ); Tue, 19 Feb 2019 11:06:58 -0500 Received: by mail-wr1-f65.google.com with SMTP id l5so21501884wrw.6 for ; Tue, 19 Feb 2019 08:06: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=T/8pB33KMIJ5zXoSB9u9TfOpy7x+4rvO5Vd6nd9n/qY=; b=Lxqk8665bM0VzvGAQ62nwsFElvlMyPDJd627oEUO9Ezqk0SUdrdorFJizWOp4759m3 66tgLbF8MUYmGCXP7DNMEjcXNhFxIk+5v4EUQW7R0LQ7FVyWJXH6kV2kgvFcnymq1hDM gwTO2/18WStArOROg1MbvIl4UKNwaw5f8ML84/HvXixPRfoQfj3g9c+G4uJpqy1HsJnK 9KTpxG2q0lBohR+rvWa6rexsoVcr1sjKH4vCt0wGeS3PAex871DKKexM/jklKH8N8Ef4 jkS4tzr2QChPfZfxS3Ljl6ynwpJBG26+49Hqms+Fl+1UcFCgmA0f0IVRPl/89AvTby3G NwMA== 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=T/8pB33KMIJ5zXoSB9u9TfOpy7x+4rvO5Vd6nd9n/qY=; b=sPpwPupRcE9jvRbfxm01NWoAMwVW1EUF1Ap9WMOjbvp8or4++Tl5z2ir/rpL+PWD4q lsdyDAfB55Sm02FCAcz3ubEoTocj2mNeEpa8XQH9ckzrdzL4ZsgMV4WwRO2BQmGTypSj ZQLv6oqmlw1uTcxiSS4xKYnFsEj0yWvs1OOqwrwXntmI/sJgWV8BNr5NgCJjkxiHCCmm noeaKzPg2F339yoA8v8gHq8tq6mi8E/gDe2ioVplsFBLV8s3hwaIzWv6hiwxJfgvfn7Z UsyzIllVexFAJxygvzTrOn2SONrazye46Oy2vGJscoI+49i+veDOL+b2iU903oBdJ5Gk wEdw== X-Gm-Message-State: AHQUAuYmAZvLmD7ce/QVpm+c6coWmTmCT7YXrqsr8XC9EnX3L9qxZM/H LXQroDEUC9HpjX6fEMKtUe4c2UM9geE= X-Google-Smtp-Source: AHgI3IZBdUvC2jfzpcSkpdA7/RXbHqOvqiUkHCs3JINhn5uytsWY7FcAipkREv1DHgyu2igeeqwyGg== X-Received: by 2002:a5d:4710:: with SMTP id y16mr6977237wrq.305.1550592416959; Tue, 19 Feb 2019 08:06:56 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.06.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:06: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 v6 1/7] irq/irq_sim: add irq_set_type() callback Date: Tue, 19 Feb 2019 17:06:44 +0100 Message-Id: <20190219160650.9614-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 Implement the irq_set_type() callback and call irqd_set_trigger_type() internally so that users interested in the configured trigger type can later retrieve it using irqd_get_trigger_type(). We only support edge trigger types. Signed-off-by: Bartosz Golaszewski Acked-by: Marc Zyngier --- kernel/irq/irq_sim.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/kernel/irq/irq_sim.c b/kernel/irq/irq_sim.c index 98a20e1594ce..b992f88c5613 100644 --- a/kernel/irq/irq_sim.c +++ b/kernel/irq/irq_sim.c @@ -25,10 +25,22 @@ 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) +{ + /* We only support rising and falling edge trigger types. */ + if (type & ~IRQ_TYPE_EDGE_BOTH) + return -EINVAL; + + irqd_set_trigger_type(data, 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) From patchwork Tue Feb 19 16:06:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044763 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="ZXmSZc8Z"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lxZ2Hknz9sDL for ; Wed, 20 Feb 2019 03:07:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729053AbfBSQHB (ORCPT ); Tue, 19 Feb 2019 11:07:01 -0500 Received: from mail-wm1-f65.google.com ([209.85.128.65]:37900 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729010AbfBSQHB (ORCPT ); Tue, 19 Feb 2019 11:07:01 -0500 Received: by mail-wm1-f65.google.com with SMTP id v26so3375527wmh.3 for ; Tue, 19 Feb 2019 08:06:59 -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=ZXmSZc8ZBRyYpknUWf1ePL65IQi0O7h8xp3kpuc/+FhAIDjxuhEWmB50EhfdC3TKaD NrswTZsYvnhHGJpz+Alq90Vyy1LQQFccJRiTZaoEXjphzu9AWJ8yULiOxBqO4IRman5L ie9UvxYvO9Yl69zmHNCVsKQnFqeN0B9ahFhhE1HXoKjjIIBhzsn6h5jR5jHreZnbcfHT Vhx9ElWBhz57MmucR9vXeqAoGH8xXD0ciOQXJUicpnZRPRGe8JYShUz4c38LKRsdF7/o 5fodf7Aqu1qotFHw/MiJlrdMRPoHzTcJHED6Z1oxUznnqFgvopJymjffVNKW3GLEdqG1 InBQ== 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=q6bcl0av93QmRz5B4cH5a5SPlgImj736HKeftjYbXhZaMlbPi3QB5a1AvHMl6+ADow v4W042KMrTVe9Gd0vKOWxdLNmVlgsmlu07HdvJzPrwCZ2v6PTP8CABuuKkETke3jLhAE krvpRkXUdaiBbZ+32UmMv1vCWMuBTFur0c4dcAVuND1dO7+5E0m18nbGClZwFd8KfXLs VxnxByzA1XmNJgiez2JmJ6AVhPU9QvHXN5RRG8jgzeApGbmR+xISxlsPoaYvsePhwYNZ GLHaU5+RMHvDCKc5DTgV+v/WLlhwoxnW/h7kz4ALq+TESg88qNliHt/f2CUY7+bGZMJ/ p9gQ== X-Gm-Message-State: AHQUAuYEvdmnUtz7t7FiinIw1kHGeIYJWbpDNBYwZ/Y7OXsezn0rh5m5 QA7Ie+S4Wlap82/yENYnnZWTKA== X-Google-Smtp-Source: AHgI3IZBAO4WC1k0fn2wKEr4NL8X+sLa/jvuRc4ICoQLnw2y8bEpSSsrGJ7g2DPVF/J29v2fE10sEA== X-Received: by 2002:a1c:2d42:: with SMTP id t63mr3579161wmt.9.1550592418361; Tue, 19 Feb 2019 08:06:58 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.06.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:06: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 v6 2/7] gpio: mockup: add locking Date: Tue, 19 Feb 2019 17:06:45 +0100 Message-Id: <20190219160650.9614-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 19 16:06:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044759 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="qzbltHKX"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lx64Lz9z9sDX for ; Wed, 20 Feb 2019 03:07:06 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729091AbfBSQHE (ORCPT ); Tue, 19 Feb 2019 11:07:04 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40132 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727303AbfBSQHC (ORCPT ); Tue, 19 Feb 2019 11:07:02 -0500 Received: by mail-wr1-f66.google.com with SMTP id q1so22589537wrp.7 for ; Tue, 19 Feb 2019 08:07: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=1WGhX7lh3GClMJMpleuT6xjtmXeQaabY429BNB+za3s=; b=qzbltHKXWbDw/IvHCCnOWfsvc63Iy5VsInYiFsTPn8q9qmSHsobcWtechV/JWEryR4 aazjyrbVVJ+TqfvDjM+yKn+7anRUTTpPJW/gCXDgJz4pG5S0kZQUD9ubukXma1kGGnIF 3VjIPipTaxPw+Ecv7NJnubJIg7OgaQsOBEob0xgAA4j7IHDL+CB9tFUaJeny7Vhf9UV8 hrxAf4hJOX2R4DxiRzUIIJD2+nzJa0R3/do/oC8jrMjv8ZfcEFFRgrax04waUkaR0l+/ Ws9fdVulDZXFJVFsuBDBJf1b0sUDrUKx1S4RQHfSr8EK5DdDxaSvJXZrWK20qtII2PrO ncUg== 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=ddy3GiHK+Hq2VqxfJG9K5/Kz7MpYWnh/or9ZI2A3FvhV0GMpvhpeFGxvFP3/Uj/IyK ibgQz7VAS7yUG/+L8IeqtE4w5Ae1PS5rLVd+ufnsPsqg9/G+rgiENTReUnB5+zskjcf1 orYwAF4pxypD7iBG8dUz9RgIoc2mG8HkDuqg4ymr9uyeBEQ6/2WdGM7SNFLcYzNNbexY AX7D4/ogy2H8SWpZAWx7JzgCjnBQ2RsiKrgNb6x/k3CJNvRHGYg1rZqYDKRvd/mZdSWU saar3mq6TcnumE2cb6tZAgweb1gjJrXmDfFLj3uJOPBE2x/mNUdti2d1MZqirtyEWEzD RxWw== X-Gm-Message-State: AHQUAuZ8EaXDFEEexcAodwo9WguAduaw0osaDVNCb2nPjTTfZfIXdqrG FNpOYNo4WRW4dS34865/9tTpdiWR8LI= X-Google-Smtp-Source: AHgI3IZTzPFtEWcG/JMbQehUxXrSxPMfp50ZuFhnvMgOXrr/Nun1AJsPowYSY7OcgTXGoNouRezYSQ== X-Received: by 2002:adf:9083:: with SMTP id i3mr21182664wri.124.1550592419798; Tue, 19 Feb 2019 08:06:59 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.06.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:06: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 v6 3/7] gpio: mockup: implement get_multiple() Date: Tue, 19 Feb 2019 17:06:46 +0100 Message-Id: <20190219160650.9614-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 19 16:06:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044758 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="qlZ8eZ5O"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lx55sNDz9sDL for ; Wed, 20 Feb 2019 03:07:05 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729084AbfBSQHD (ORCPT ); Tue, 19 Feb 2019 11:07:03 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:50638 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbfBSQHC (ORCPT ); Tue, 19 Feb 2019 11:07:02 -0500 Received: by mail-wm1-f67.google.com with SMTP id x7so3410521wmj.0 for ; Tue, 19 Feb 2019 08:07: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=03DPhzkzBjEgdOWVhFdZb0AzmHi0UfZRp68bha7kwZI=; b=qlZ8eZ5OnPTUP3S7fsfm6Rz+FwI6kyN4SBm00r768z2nHTu5qAAQZjdsEmmiwMQHPU 8co+L58+8cb5KQk+Hnbu29h6/P32JxpQh7761v4tM/0xYhdRaZUwlBU6nDduNlaOyH3m 6eYMRxpqhJJ0ehucGhg10uj/NFIfWDuchrNoVa7wlIh0ek78J64WlXr89qgdpivG+hyj kmsvXOxRUQiwFMdYj9vkxVWhvnSWKqoHeYq8JRwc6cJgN7WAhaQpxwmC6r8VmqV5ogtA PvWfGXcGGxUbW58wR/Rkwid3DgBBF9zLPebfZavk6VgB1jIkBGuxIgPL0oCMDsETPRZu /53A== 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=oPfRrsXICKSiM0rv1iTSlyM4202KR4/1ZM/gBrSvvb8dv89pYX6l815CQ6XwNxSVIm YPOycG9EjnbgCwTKgUTYPHFni1WQteX6KgEQ4WPotSM7VEPFnK+QLKgeBsdDcir1gaBi hmvC3+fSGY1G7L0FetmdI0iEfpBEGI1Z5qUfc/kING6s3knKp1k4C6Ct3cfuaQAbkZJe 61pRxI+u07e2A6foSrAPnl5jgaeBTy4GI+McRYx+HBIbGnVVPfCq47ODp8idXhhZ5sVT KKm6WJG9pKtWw5HeYOmKovk2+beHLH8yW09TwXxMAL+WWuZxWK9PzNuwjORMnH1ccaMw oq4Q== X-Gm-Message-State: AHQUAuY76XBjgdZ4cARITP3FiKuj6RYfYmWLYjrDLtHxn2YdkbPh9Evt FqmJlGTryEMwWo71H+wBZK7iBg== X-Google-Smtp-Source: AHgI3IaAn8AYuHkTeR4leU5qH0d8Hbg2i3ONE9nCXv+dMrX92kHXx5kMvxa3aILYNf6dvM3BxaUfug== X-Received: by 2002:a1c:4884:: with SMTP id v126mr3483841wma.118.1550592420920; Tue, 19 Feb 2019 08:07:00 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.06.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:07:00 -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 v6 4/7] gpio: mockup: don't create the debugfs link named after the label Date: Tue, 19 Feb 2019 17:06:47 +0100 Message-Id: <20190219160650.9614-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 19 16:06:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044762 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="jpYfl8ul"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lxY0js8z9sDL for ; Wed, 20 Feb 2019 03:07:29 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728201AbfBSQHX (ORCPT ); Tue, 19 Feb 2019 11:07:23 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36967 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729068AbfBSQHD (ORCPT ); Tue, 19 Feb 2019 11:07:03 -0500 Received: by mail-wr1-f68.google.com with SMTP id c8so22589344wrs.4 for ; Tue, 19 Feb 2019 08:07: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=2krnFxmiomVyVDb/8h+/xtPx5s60ffpJQDYiPXgWEoY=; b=jpYfl8ulWndgrJ/cRqORQPOf82zZX4AJtKgIiXmammQZTopnQDCby/OkvHIum36uPe oChw+vyw2hjvUoGtGtajuqhtkin2RdgfZFbcaPvb3knOzX6+YA0cpsbYMUx465C4qkhR U0uURrdIoP9I2syzaNq7rKYhe7K+12CJfqEve/JPl8sC9kqtcO0nTLdaevCtKvRkApTL 5y3KFb7GwVliy3/naqCl/miOwh0XKJUphV2OVIbZWlzD47yKMdjRNebH1RGJNP79bL4j R7J6UZ/i2hfav102ih83D/4+MLRvANmmpS37SvjAKGZgt7ibvzEZDfN4Fgbdale2iwoc hiDQ== 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=pG2MRVysSfhnkF6+7JV482ya7dJzb/2n38UGK+qSwS7N2Tz/WzkAYOE4gSJkQGciQi FG0cqiTCKRDsEg2UJXQpM7q4Y3OqGw/IQcSeTsmVixW64j7PqmC7tlW/vsrAnTQrxt7y zayuXcwLyNDcQreHh+FMgPwbxX1i2bpskxOD6fNP6+cOxemt/EUuL5KnBSyQZQ1D+v+L 3irGW1kQwmy+6aleHY/2tSDuugrkblsZShvzr65ZtjTb6N9B0tkcuV65DZfI4gXjNkGB IXwhldEJsfhruX4KsShQfNrXnQb03m7V51lka2klZdKmmsQ0rLX6/r8Ig7IAJ/npNwH9 iAMg== X-Gm-Message-State: AHQUAuYZeoTdxAZ3VkTFcOuDUb7W5Co/DfL5xD5pSWIBoaesZIQpyXdm /kTyGSNdkh1re6djd0+10/K5Yg== X-Google-Smtp-Source: AHgI3IbHOvrVY47hMHGUmiBksXEmmtWN/2jO2eQ56Y/n5Pikmzc5XRU4AXR03Tr9sTncPJcydq7z1Q== X-Received: by 2002:a5d:4702:: with SMTP id y2mr23155016wrq.149.1550592422186; Tue, 19 Feb 2019 08:07:02 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.07.00 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:07: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 v6 5/7] gpio: mockup: change the type of 'offset' to unsigned int Date: Tue, 19 Feb 2019 17:06:48 +0100 Message-Id: <20190219160650.9614-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 19 16:06:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044761 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="JZ3Cdpf0"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lxR32pWz9s21 for ; Wed, 20 Feb 2019 03:07:23 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727061AbfBSQHV (ORCPT ); Tue, 19 Feb 2019 11:07:21 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:36970 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729035AbfBSQHF (ORCPT ); Tue, 19 Feb 2019 11:07:05 -0500 Received: by mail-wr1-f67.google.com with SMTP id c8so22589449wrs.4 for ; Tue, 19 Feb 2019 08:07: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=2P/9cB+jmoaw2Dnwldpp3xOYGEGj2ZimLHwmer8wLno=; b=JZ3Cdpf01v3f95tWFcyIm1PFjLLpFXqUbezFbWiNdrZav1XK9jmJd9vtle/LuBaTi6 +d5i3FCo3NhCPQdvxBANYKYjgRPvMwRJHeg5Yo18I6+cyoMWWD/KT5s+ibSjko0MCiho ffazSsnPstdgmv8H5a4ZTCVGkAaiTb1NBVaAdTypIJREED0IKBGQiEjPcOFe7KDbzdJ/ cnucl64didN0AWXGSYY6WVENAUlpEVMtGoXmMK4u0cuKma2vpEcTFQkk7+WsexMzMghD 389MKMl7yQGDsZfjOnDI5nVaWaggrzg0SLfmAUdmYbs2CcMy4ucEewOhsw0RMCnjcKTq Sotg== 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=kzCsO/NTYq6O00yk+PB6MfYEdG+q9vv5rET2IfBUiuSvgT4LWZWfWidvh+PW0e3UU8 FhVy6c1IsIlj9p5mf0YB6c47R9au6Ls2Xhn8VWxdlVY7K3ZBokG36h2YYSAqqvwmfNks F9LxPIrrFwgTjIatiiC7ghGO3oEojeikfOOFKSg6GbsCsT+zVjceld4htnM+b2fNrTIE 0wYAP/+QxGvGJX2ups6beQ9NccxTPaDrLBpO50th2kMN3BK2aQDQPd0nd0e+CUnk+/pn 4zW93Y1KJpzHfPS302wnVWns8wA7zhKXG9qvaHsawM76sjGSWMhlcfxOD+cxyBzUYU7U aLiQ== X-Gm-Message-State: AHQUAuYrf4hcougu1dCLwDfRBPF4+39H4TyLFpKIrBho9IuEDmITJ5R1 /GTuYrQDhGtScgoC4k/rWUdPVQ== X-Google-Smtp-Source: AHgI3IbHTkJfATmA1ixBS46x3h49PMwOuh2XTCmY4OQl1AwKcLpRC3yJnrF0EI4oSBcvR3oH3cEWTA== X-Received: by 2002:a5d:4710:: with SMTP id y16mr6977634wrq.305.1550592423407; Tue, 19 Feb 2019 08:07:03 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:07: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 v6 6/7] gpio: mockup: change the signature of unlocked get/set helpers Date: Tue, 19 Feb 2019 17:06:49 +0100 Message-Id: <20190219160650.9614-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 19 16:06:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1044760 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="WtU17fpF"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 443lxG75f4z9s21 for ; Wed, 20 Feb 2019 03:07:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729124AbfBSQHJ (ORCPT ); Tue, 19 Feb 2019 11:07:09 -0500 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36976 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729119AbfBSQHI (ORCPT ); Tue, 19 Feb 2019 11:07:08 -0500 Received: by mail-wr1-f66.google.com with SMTP id c8so22589608wrs.4 for ; Tue, 19 Feb 2019 08:07:06 -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=74S/ZZSWu6G0IEBZISG2HDi0WMyGHQlJBkHM4LFbqVk=; b=WtU17fpFVE3t1D3pSQy5s2wHZqW7lwdaK1QQ1rMmSHiEUbbX6yRl1Fe9Im17v1Si85 ZyBqFCU+kFJ3FQCJ/C6/To0XYd5KP3CZf3p0r9Ls+6J4SyIHwqfVdWLn8ETAD9lLaL5x HvFZJ+SExGZk682PfRdKrUnSnAZ3yv/Q2WIDq1xOr3CiJV5s8/EwkMOpl19FzDUSNkB5 0JnRc4Z5PMP03JaMweSuXb6kqQFCePfQpeqj5cOOmgQC3prNFOQf2wUS7CIK0W2Y2eBn 8Pzku8AHdiVrqjYR/OkoexR6+89rsxyjCrok7eN52F1ALLwZlbRteZoWSiMt2XngKnA+ rW2w== 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=74S/ZZSWu6G0IEBZISG2HDi0WMyGHQlJBkHM4LFbqVk=; b=Vo/lEJPxXpiImV2O68wN9AUlqvqpuMBHYuBClbMoSPQRiZqXuPyYQ9ZOuUsCabN7BM ILy1mM4W72c2sGSIvEfM8c3qbsYxB/5wk5dbw3E3s3SsmBZer8YtTZJYm7uuYjiQjU6A Ez5w49TnvG74kp1gGtEuYoG3sw6m/qzjDf1iz4ZChuHvwKZ44wZUElIvUDbXncxjNwrq VMpcZxaWTcYddcloDjAwJHkiJV9LysWgET5ZN5u8Ql2hEnG+4XkIszO0wFmWppb85ES0 9e5OIQy1Fiam4RuuJN9VzZWybQToQshBW6fe6o8m75Mhi0E2LsRDrUksxGCszXeqxvi0 wILQ== X-Gm-Message-State: AHQUAubQweXhdyzuWFNT78c7ERfXrH8GkHXPnLfkRr+ygxXIfDBINGNp FJRL6vNGE10KLDkgM4/fWngl9Q== X-Google-Smtp-Source: AHgI3IZsVzFDN0U2x0jNbiKO6sdHpyXlavuYozsq0RZuD74s+6SRhZWU+/6Ivl5kzoFAiKCjEJveBw== X-Received: by 2002:a5d:690d:: with SMTP id t13mr20409274wru.135.1550592425803; Tue, 19 Feb 2019 08:07:05 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:af:5b00:6d6c:8493:1ab5:dad7]) by smtp.gmail.com with ESMTPSA id h17sm12161381wrq.17.2019.02.19.08.07.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Feb 2019 08:07:05 -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 v6 7/7] gpio: mockup: rework debugfs interface Date: Tue, 19 Feb 2019 17:06:50 +0100 Message-Id: <20190219160650.9614-8-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190219160650.9614-1-brgl@bgdev.pl> References: <20190219160650.9614-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 | 117 ++++++++++++++++++++++++++++++++----- 1 file changed, 103 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-mockup.c b/drivers/gpio/gpio-mockup.c index c498b0fbbec8..154d959e8993 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,56 @@ 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; + int rv, val, curr, irq, irq_type; + struct gpio_mockup_chip *chip; + struct seq_file *sfile; struct gpio_desc *desc; - int rv, val; + struct gpio_chip *gc; + struct irq_sim *sim; + + if (*ppos != 0) + return -EINVAL; rv = kstrtoint_from_user(usr_buf, size, 0, &val); if (rv) @@ -206,24 +248,70 @@ 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); + + 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; - gpiod_set_value_cansleep(desc, val); - irq_sim_fire(&chip->irqsim, priv->offset); + 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); 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 +346,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 +354,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 +430,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 +504,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");