From patchwork Mon Feb 18 09:47:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1043845 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="q8v3Icf2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zb00cCbz9s3x for ; Mon, 18 Feb 2019 20:48:44 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729812AbfBRJsM (ORCPT ); Mon, 18 Feb 2019 04:48:12 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:39093 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729803AbfBRJsL (ORCPT ); Mon, 18 Feb 2019 04:48:11 -0500 Received: by mail-wr1-f67.google.com with SMTP id l5so16490232wrw.6 for ; Mon, 18 Feb 2019 01:48:10 -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=q8v3Icf2S/3s2u9PlPJFISnLL8NSoDo+DeCRekLelNf5F+dK76nBXhbFVa1wMCgdm0 lpkKcgqzW8+ROvwzv0R6VdNGvteUhPRfGt9OFr7FSuLyZxurW+I5MBPTmH2Czkq4y/Bf lAbSeuJoR/I+ghSdXrqhPMwE10RuNDbFtfMMcrgZdHT433bWBcgYevXIJS8vseMVjcAV dez3g4OO6D5bHM8CAKBcHZ/P6gc0iiaopeKjvS94yX5xn+jwk6SJuAHTlE1Se3LGbKWD nEfMs0v/N+J3mouvHlPIw7/+qRuYKfYlecGD0cLPlz9nY6x0Sm5MSYywezuPVppduRa/ SoRg== 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=PpnBWdyNU1hW/7TeUc1I1flL2WQuhL0MMuaMC54xQtSte62H6CMyG63bIOQ6CZ8p5Y MC3PZKu+FDQ0C1rn4GjsETlFHxjcqSfhGSJgNSP3XkhhRawcT3d6iaHweCQyhOPa4QmI xlLBZOBwlbnCjEi6OVt8iOALBjZYiJCWKKidVYbCKoyMbuYcrK0EtEF9AeG9p3OWg3+a uKATNHdICtfhETzfmsIf5j5MquDpPjGWC+IZYyFjxIlU29vGhloIxNQUQTTkn/885B/S 10lEmNv7lnwcez2Ck/FxpnLNbpNEGC09jmD9UWlXSTh+xkR47jkc1ZIJ7qQ3C626DFWw 9x3Q== X-Gm-Message-State: AHQUAuavAzaBw3H4HcVE6LQmG+0TUifxSYVQZ+Df5rP53E8wUFZCHc7d Ih/tUNXyF+fRCf59qLRx3qqM7w== X-Google-Smtp-Source: AHgI3IZGjsMtZAoYkMR31buxsyE/u9bYl0ar+8A03cBDm7Zed31ZV5wBsW/ApeDXmuRYHKAuYxrhng== X-Received: by 2002:adf:e8c7:: with SMTP id k7mr16418119wrn.298.1550483289601; Mon, 18 Feb 2019 01:48:09 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:08 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/6] gpio: mockup: add locking Date: Mon, 18 Feb 2019 10:47:54 +0100 Message-Id: <20190218094759.14545-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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 Mon Feb 18 09:47:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 1043844 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="fI3dk0Lo"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zZy6hQ9z9s3x for ; Mon, 18 Feb 2019 20:48:42 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729816AbfBRJsN (ORCPT ); Mon, 18 Feb 2019 04:48:13 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:41242 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729806AbfBRJsM (ORCPT ); Mon, 18 Feb 2019 04:48:12 -0500 Received: by mail-wr1-f68.google.com with SMTP id n2so5414999wrw.8 for ; Mon, 18 Feb 2019 01:48:11 -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=fI3dk0Lob3xVbOYh7vzW0vq9bEuK/+s1OUeeKYrnDIb8Sgsp9YpQrICs0mJxhrKsRh VxpHD2W4zSc+qoHMMmxRKF6gLs+SyDiHsEte789h4JoKxLv4EY4zaB12KAWkVC6YT7RR lxduIXKNh87hMY/7D/j/piiIab1ZHkXFNhbLTUDeu3W465x57tWv9zAWtBxgGtF95hYn 2oEEQu5zPVVK3hpF2pi+rMmBz5b9GEnS8gQr1d5zxrN3dVsn40z3it9cDre1eE6M3WcH xHBi0bkwLEnMHeUCy/VD9Eiv/1ZS7F8ujBKlQS6HBRASz1Jws4nEY1pfy+zcyyGSm7GP V7fQ== 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=DJdBI91abZVR6v+VnEawNDq/Z8DUwsfdyF4o0yLR15peHVUIQB4KVTienrhvRZk0R1 Ri64WaSqbaaSt92oN0355nnpDoNMb0F6HwU7C5bwFS7vYU9pdALUdn4Y4fKAF6086aO2 QLA7+HK7fYDMR+OxdkJpo70/FapJ3f8iCmhiZMc2hHvFfsIe3jX+dsJu7PjRReU6tfLz NfccMEdp3edbd/FnejE0qxJcLjnncmm+RGw3S5FUL/iwRuMMFIePnUyw1repjdF2gtU8 5Q1dffhMzPhPtv7quxr8PvOp9fmxYurE4amnxVxBnGja4oe6ye3XhTJ8ODbWRXRr2VJ7 FbYg== X-Gm-Message-State: AHQUAuY0bItvC5sxWvwwMctDLukTCmwaub7xEfVrOKf3aAdtdlLIkdvw C6IrNQRg69oaWw1rZLAlQeW5LQ== X-Google-Smtp-Source: AHgI3Ib8PfbRy3qztrVKCsYCt4fFN0/vUhm8E2E56/IzjtVA6L6aAC8Kn/MgRGuiUmtSVKfRCn8nLw== X-Received: by 2002:a5d:44c3:: with SMTP id z3mr15470004wrr.329.1550483290596; Mon, 18 Feb 2019 01:48:10 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:09 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/6] gpio: mockup: implement get_multiple() Date: Mon, 18 Feb 2019 10:47:55 +0100 Message-Id: <20190218094759.14545-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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 Mon Feb 18 09:47: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: 1043843 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="avOMrMbu"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zZq12m6z9rxp for ; Mon, 18 Feb 2019 20:48:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729831AbfBRJsO (ORCPT ); Mon, 18 Feb 2019 04:48:14 -0500 Received: from mail-wm1-f66.google.com ([209.85.128.66]:36131 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729809AbfBRJsN (ORCPT ); Mon, 18 Feb 2019 04:48:13 -0500 Received: by mail-wm1-f66.google.com with SMTP id j125so16379363wmj.1 for ; Mon, 18 Feb 2019 01:48:12 -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=avOMrMbuCc3zQ5yDGbQl755sCnzSjr5XiNqHgwx6XCW0pzYOzowMFYmayABTwkORDq 5c9TYUFiU/TddqQzc0CT7yrOKB/vsOckRfqjdOGexyjPucMMOFrqpiia3i7yu0ireEkI hs751FnCfK9qcjW1ZXGLCCWTjN0Md5ti2jCBD81L7nzsz7cK/oA/smZijQhB9P4od7nf E+XUOPuv2GyllGKixDC3y/yMLyyjY+ULSsZBESZfvDIVV1ux5zY3805YMZuNDvxDNCIy WVvICf4k2qw7rvUrov1eeZw3zQEEZTDVKxad9pL9qBzMlb3LOlZ81gp5ZVogkgU42wBi JPJg== 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=CS2vMzTWFM4i74hdXTvQfW4U4igdXg4GyAmFKWrepJLKefBk8EQmlSStMMZxO8/gom sGoi8yv3+qWfO7QbQQfB+1OKUje5DedyW0zNCK46f7hfFQkVOqGEcgTNhr7bVV/qBWyh poQUfcLERrG3sf5GCYYZa2nNJ+Eo5qk2q9MBKk8hEnCGQzgz/K3Fx/ZSv0cyZUDlFzXF bpUSUcKe1VRsVAIJ6KQ5WI5odw1P3X6gaFG6jZMMDsklqW9pgF4myNRyNwCpREHYpq0V WAZxheHSOuQ2D/AW4gp4OLDxWufEU9n5COT2guQbfgLMH3GuIooiuE2u0/TFqo6yV83f 5SYw== X-Gm-Message-State: AHQUAuaRY3Okist/ggkqUpDim9vFTT7vGUtG9oUnM5jCpwG9AMXigiIh Peb7vTo5Ru988t7IG3LUUDSa9g== X-Google-Smtp-Source: AHgI3IYcHiIuh+bvyHmYlW6gWqYQfsUNbq/NiDtO2C+vl2Sy9ORdFCGgzqkrJA0ci3oCqKAO+slm0A== X-Received: by 2002:a1c:7312:: with SMTP id d18mr15432479wmb.10.1550483292067; Mon, 18 Feb 2019 01:48:12 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:10 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/6] gpio: mockup: don't create the debugfs link named after the label Date: Mon, 18 Feb 2019 10:47:56 +0100 Message-Id: <20190218094759.14545-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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 Mon Feb 18 09:47: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: 1043842 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="jPDMpttv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zZn4ySvz9sLw for ; Mon, 18 Feb 2019 20:48:33 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729792AbfBRJsc (ORCPT ); Mon, 18 Feb 2019 04:48:32 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:35329 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729832AbfBRJsP (ORCPT ); Mon, 18 Feb 2019 04:48:15 -0500 Received: by mail-wm1-f67.google.com with SMTP id y15so1708446wma.0 for ; Mon, 18 Feb 2019 01:48:14 -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=jPDMpttvnTfhSuKSdO2j+xPSSP5WsaqSthB4QBgzlsLk1nxcuQZNcwYzpsmCZdd6+Z R364lce/9znpsJepREEUT6nH/BFPC58dJZKgJOATVz3OXuTJORS7fVbZ+HpGFMCYOo/4 M5Umq65Lj3tk8pLiPMQJRB4r50DdsqugUUbGsuffDF4Wh7/696CYDwxw4Ow/AV8MCNHm R+aFlpphXDHJAtYryIPPsbkkx6NgIesHSKGXqpJDmlrAgOASV08WHBVJbeLWJf+nubSZ JtCguR239gcLyIMJTi3Rkgpp93yAmTzH9+GbjhDFJtvtb5/3Mea39rxbFRNGoVuWobnS 38/A== 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=i5eB8+Ow52aduZWwdF87aSqxpWvPLAN5D8VX7hqYR4sEY7qhib2TlrvE28ybZig+BV /Nh2keZzKFLxPwbiKxnnmITYRqKSetDQCT1l8XHGjAmmaoqib9Z9X/SnqiBHOISCaw/i bZubbxkpeNk9pbhFzCLMxAFknoGftvnDUM9vU61H3TQFkzhmomlWRnz+pgaHnDSVziaD y60SaI1+ayxMP4vIOKrEcCpDrI0X90LEM4z69FnzP8GoxLBWn2O3pWpfnphNwMMZNJmc 7kZvc+fRCMgqSSwCDglJymmyF+RcVuPsdd96cyP0ipvIsWnodeChd10cOLUTWMzRrhs5 BkCQ== X-Gm-Message-State: AHQUAuYASO4A3LjDUQ7B+XhEUcCqMccN9IxYn22bCq9ODWGU4J5OZ19n z3DCfIWj6ANosmJ4BpLj8krYIQ== X-Google-Smtp-Source: AHgI3IbwYyGNGnQC8Q2qq3FWGA0aoppGWlDfW+n1rFcWlveqoMXANZPBoKl8Q328YKzCUgEjXj/GLA== X-Received: by 2002:a1c:7a1a:: with SMTP id v26mr3224765wmc.129.1550483293586; Mon, 18 Feb 2019 01:48:13 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.12 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:12 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 4/6] gpio: mockup: change the type of 'offset' to unsigned int Date: Mon, 18 Feb 2019 10:47:57 +0100 Message-Id: <20190218094759.14545-5-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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 Mon Feb 18 09:47: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: 1043841 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="DErqkuk3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zZm3Bhnz9rxp for ; Mon, 18 Feb 2019 20:48:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729369AbfBRJs0 (ORCPT ); Mon, 18 Feb 2019 04:48:26 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54545 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729846AbfBRJsQ (ORCPT ); Mon, 18 Feb 2019 04:48:16 -0500 Received: by mail-wm1-f68.google.com with SMTP id a62so16666800wmh.4 for ; Mon, 18 Feb 2019 01:48:15 -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=DErqkuk3xdQVZDsUPP1dxxzv9VqBmngBn8CejR4EYPe0Cq26UVpyxmkwTbCHC16LLI 8YjYJMrnK6RDDFxZ3HuyTrSX+I9hpIkj8tPvYj/n9nbrdYY6Jbwn1AMGTVJHqBOq3qm6 p0J+sDVrSBGIWfBygl339MohJMeBWfDPnjtf6Us+OmZ+4/dsn3AN1yofZjY+E69/DRtU Pr46/bJZvQdJftfJUvzHOvOvRH3Jc69vxCCSIUd1GuOqmZElFJ0HVv/Act6p2szk2Blv STLw1seBFRCZLlU7UdPDuhGu1ksn5vQXhRR1ACRFoyMPbqkRS0/fURtJP+BNhmup1qUH vUNQ== 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=ABJIkFc0dP7AYzpN/lniOA7vk4wYlUHspidef5S452/tPhqR5ybVAjGDKlnbV5FSfG tZ8+L3bxyvlpAQ3kZa1cBL6kETolsqf9Qqgijc2Ut07Hd3UmuEG2MrzwFMddj/Uwu585 XrwkyPBUQ1GFqQjAhUxx7Q/iAZRHnRh8fFTtFatBnTDPbWmwoRCzWI3/thSAdiBReoKq ij5hgSjRxLNU0WjIpnIjTlDuh7K2n8yIvDr8MtiZpvguWHmmBsebbZLEQbEQwyHhpdPP Pg2dUOzE1Z8//9J7Gxj2rOsoX3AbjPLiKWPSIwWL+qxs9vbsgbZepzz4xo36KYqwCs4m vDLQ== X-Gm-Message-State: AHQUAuYxJ7fXX/mCk/BzjDF/Mb2TM91pK32k6kmT1zGRhn1aPjtV8dkE Ka3hmbXCXxRg1GC2PPueW4qCcA== X-Google-Smtp-Source: AHgI3IZUq3zEabJVasui2IYO9qJ9KpRi6xpGEae/vhxMr/4EkPJOUzrJolAdX0X3tCn9td3Y1JNLAw== X-Received: by 2002:a7b:c764:: with SMTP id x4mr14518334wmk.47.1550483294579; Mon, 18 Feb 2019 01:48:14 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:13 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 5/6] gpio: mockup: change the signature of unlocked get/set helpers Date: Mon, 18 Feb 2019 10:47:58 +0100 Message-Id: <20190218094759.14545-6-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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 Mon Feb 18 09:47: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: 1043840 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="E7HARg7x"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 442zZd1f0vz9sML for ; Mon, 18 Feb 2019 20:48:25 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729370AbfBRJsS (ORCPT ); Mon, 18 Feb 2019 04:48:18 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:40469 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729857AbfBRJsS (ORCPT ); Mon, 18 Feb 2019 04:48:18 -0500 Received: by mail-wm1-f67.google.com with SMTP id t15so8247129wmi.5 for ; Mon, 18 Feb 2019 01:48:16 -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=qNa1+Y3e29LgXf9Sg+UQJ7nxkfwnmvmk8nMAATc6xHA=; b=E7HARg7xiDrenHJX9EVYcHx986a4+dE7vlP74ETAyIE8bdZ2lEa+kRu9Y8kfHfACFY WvYaKoYH6Pl29gd/T6NT8yyTb8yXlpPPk8TT3J7xcVnRlxRNLgzDScR/Olv1sGOak9KM xctSrNI/ywmDZ7E22ImuxGJbCHoch7iJiRxJZxIhNLnrRv5iPK5mUhPjqNm460WarhZU 2MZ1j57LNiK5C8tH1UBSyzKAqBITSYz9BHWS6WRtg8J0863WDmdbIrCfPSfpN8JUNeWK JslsCwJXN6wq09vA6Y64ldX6QRV6KO4cfJWsfYxlGlQMGeP3qUGuo/3M9hvW2DFHDEJI pWmg== 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=qNa1+Y3e29LgXf9Sg+UQJ7nxkfwnmvmk8nMAATc6xHA=; b=Hsm4Z/gkjag8OusrKWp7H+Jy0IF6ao1iBtMGXFEa8m/e/bevkXOJKtGWzMzxov/Kke STVLHvdxJnp/+TMEQAor0q34W3YWjy+GnB60qMpiT0p+CCZnNyHte76K+nXA6MwsxNCi swIi0qS7vj291UGjmj8rGYZDq7Buir1N5b1+LAZLgOsZoDcLTYgH/3TYBea6WBcqz4g6 UfwcrT2SDFTK4ZcO09FqaNxmaGF6PhapODkjxZI2116nLJA3tuFH3WB3HuUGy3656SKe gJGn5/pgtPM2GY8a5LItFhyva/KUMiM6nW9iHl7TIA777olDmh5YJkdX/0EYFnUgEcFl d9MA== X-Gm-Message-State: AHQUAua4e0hd1kwMD1piF4yLhDvO2qwjNVEa9+vh+3NB/LQA9kZV4QN5 RtXsAAx433q3e3R6t9fDJQ64Xw== X-Google-Smtp-Source: AHgI3IY/FeRocp7ctvq7eqRCVMpA58GnSJMcF++yGrO7jH2xBH1isgztIY4h8Pb6RuIqAJanXSeGTw== X-Received: by 2002:a1c:1c4:: with SMTP id 187mr16134318wmb.6.1550483295609; Mon, 18 Feb 2019 01:48:15 -0800 (PST) Received: from localhost.localdomain (aputeaux-684-1-7-43.w90-86.abo.wanadoo.fr. [90.86.124.43]) by smtp.gmail.com with ESMTPSA id u15sm17582974wmu.17.2019.02.18.01.48.14 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 01:48:14 -0800 (PST) From: Bartosz Golaszewski To: Linus Walleij , =?utf-8?q?Uwe_Kleine-K=C3=B6?= =?utf-8?q?nig?= Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 6/6] gpio: mockup: rework debugfs interface Date: Mon, 18 Feb 2019 10:47:59 +0100 Message-Id: <20190218094759.14545-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218094759.14545-1-brgl@bgdev.pl> References: <20190218094759.14545-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..72f5c07c4219 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; struct gpio_mockup_chip *chip; struct seq_file *sfile; struct gpio_desc *desc; - int rv, val; + 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 +248,69 @@ 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; + + /* + * FIXME: fire edge interrupts according to the type + * configuration once irq_sim supports this. + */ + irq_sim_fire(&chip->irqsim, priv->offset); + } - gpiod_set_value_cansleep(desc, val); - 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");