From nobody Fri Apr 19 10:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568213507; cv=none; d=zoho.com; s=zohoarc; b=PRAMFIfqj/XrwnisZl8fFt7qOJdUFEh15QLVYNY5S0KPR2pzw+40XGmhJAWsAeNfgQ2iHGBw+rdx9jTXku+fR/I3lkMsOg4/vNiPlUsgcD+XEbNW7r5Kt7Tp3aJ/ntCVrk8hulEi/USSbtSZqa2EqBtSMZA62+7Zt73V0rC5x9g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568213507; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=uQsDAqCxz/7ZQ5HzjKMUBJv01D1hRJ7oeWbG8Rrf8F8=; b=lMTDwjwNiNt+jq81hVMINQxNCjCcIRFgdHLSJc6qNE4RFSajgfDhOR0sv4GxD8i9hHe3+gIFjfMy49MiMUdmnXpyQ8Zo/vmubQ8nfSEkba94Y1KP30YC8RDyjfLMsddmn7SY9dTtqMIMLplIxfN5WN+Jmu0A8MyeGWFaJUtBk5o= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156821350733981.34031085013135; Wed, 11 Sep 2019 07:51:47 -0700 (PDT) Received: from localhost ([::1]:51922 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83yD-0007VT-3I for importer@patchew.org; Wed, 11 Sep 2019 10:51:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44715) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83m7-00038r-E8 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i83m6-0001x0-Bp for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:15 -0400 Received: from baptiste.telenet-ops.be ([2a02:1800:120:4::f00:13]:60958) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i83m6-0001vE-5J for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:14 -0400 Received: from ramsan ([84.194.98.4]) by baptiste.telenet-ops.be with bizsmtp id 0Ef42100805gfCL01Ef4TC; Wed, 11 Sep 2019 16:39:10 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1i83lv-0006T3-Tj; Wed, 11 Sep 2019 16:39:03 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1i83lv-0003P0-SI; Wed, 11 Sep 2019 16:39:03 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Date: Wed, 11 Sep 2019 16:38:54 +0200 Message-Id: <20190911143858.13024-2-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190911143858.13024-1-geert+renesas@glider.be> References: <20190911143858.13024-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:120:4::f00:13 Subject: [Qemu-devel] [PATCH/RFC v2 1/5] gpio: Export gpiod_{request, free}() to modular GPIO code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Graf , Paolo Bonzini , Harish Jenny K N , Phil Reid Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Export the gpiod_request() and gpiod_free() symbols, so modular GPIO library code can make use of these functions. Signed-off-by: Geert Uytterhoeven --- ERROR: "gpiod_free" [drivers/gpio/gpiolib-fwd.ko] undefined! ERROR: "gpiod_request" [drivers/gpio/gpiolib-fwd.ko] undefined! Alternatives: - Force gpiolib-fwd builtin, - Call gpio_{,request,free}(desc_to_gpio(...)) instead, as the legacy functions are exported, - Call gpiod_put() instead of gpiod_free(), as the former is a simple exported wrapper around the latter. Unfortunately there's no such alternative for gpiod_request(). --- drivers/gpio/gpiolib.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index f1c1b5d4b00b40a7..dbecf266be5a5a2a 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -2733,6 +2733,7 @@ int gpiod_request(struct gpio_desc *desc, const char = *label) =20 return ret; } +EXPORT_SYMBOL_GPL(gpiod_request); =20 static bool gpiod_free_commit(struct gpio_desc *desc) { @@ -2777,6 +2778,7 @@ void gpiod_free(struct gpio_desc *desc) WARN_ON(extra_checks); } } +EXPORT_SYMBOL_GPL(gpiod_free); =20 /** * gpiochip_is_requested - return string iff signal was requested --=20 2.17.1 From nobody Fri Apr 19 10:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568212893; cv=none; d=zoho.com; s=zohoarc; b=lSZ1RKMoHQl8TCe/+ukeI/VzlpTJjgvD6XI7gZEhgwZNABeoTzU3FlnFlHpo7ZAnxx06P2uDsz/JHep0ZXQlfCdn54TTuA6r486hO7uALKdi3fysQsWQOhVyfRKsxpXfrRbJcwAUOlkg/K+YZXtzeDaGAGWi5pXrNa4QeeEQXek= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568212893; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2nC0PTwmNgH1lAAuSUt+fObMuI1YnrRZA0oWhw/Xx/E=; b=DGWYOHvMw6nLZiWlz+9cy6NuVjhsyYmT/u9NAXtDHjR/KO35gPMGwkQwKEpzj3mZyxWobfm/noHia1Id0TLATjyJAG8JfnrcFRd9/HYj/r92GtY+nHoUZW826U9liqX9f52LRuUT1qwipHPYg+JxscXbGnWZVPu4xqoyOXPPA1Y= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568212893188436.7871566506278; Wed, 11 Sep 2019 07:41:33 -0700 (PDT) Received: from localhost ([::1]:51782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83oG-0005jB-Ec for importer@patchew.org; Wed, 11 Sep 2019 10:41:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44714) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83m7-00038P-E3 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i83m6-0001x6-CJ for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:15 -0400 Received: from andre.telenet-ops.be ([2a02:1800:120:4::f00:15]:41636) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i83m6-0001vG-5J for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:14 -0400 Received: from ramsan ([84.194.98.4]) by andre.telenet-ops.be with bizsmtp id 0Ef42100205gfCL01Ef4fw; Wed, 11 Sep 2019 16:39:10 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1i83lv-0006T4-UL; Wed, 11 Sep 2019 16:39:03 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1i83lv-0003P8-T2; Wed, 11 Sep 2019 16:39:03 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Date: Wed, 11 Sep 2019 16:38:55 +0200 Message-Id: <20190911143858.13024-3-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190911143858.13024-1-geert+renesas@glider.be> References: <20190911143858.13024-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:120:4::f00:15 Subject: [Qemu-devel] [PATCH/RFC v2 2/5] gpio: Export gpiochip_get_desc() to modular GPIO code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Graf , Paolo Bonzini , Harish Jenny K N , Phil Reid Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Export the gpiochip_get_desc() symbol, so modular GPIO driver can make use of this function again. This is a partial revert of commit 1bd6b601fe196b6f ("gpio: make gpiochip_get_desc() gpiolib-private"). Signed-off-by: Geert Uytterhoeven --- ERROR: "gpiochip_get_desc" [drivers/gpio/gpio-aggregator.ko] undefined! --- drivers/gpio/gpiolib.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index dbecf266be5a5a2a..c2cf01fb72a9de87 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -95,6 +95,7 @@ static inline void desc_set_label(struct gpio_desc *d, co= nst char *label) { d->label =3D label; } +EXPORT_SYMBOL_GPL(gpiochip_get_desc); =20 /** * gpio_to_desc - Convert a GPIO number to its descriptor --=20 2.17.1 From nobody Fri Apr 19 10:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568213110; cv=none; d=zoho.com; s=zohoarc; b=GSmf73UuC9Rc0EIbSmzFOwq61TFG7sKVxxH59pejeXG3E8KO+HxJXfTCSVQGeUj/C7TeUiR1cinOYrQ6Vkr4sYdTAIJ17wjpIaYSxp2W+C7mOUa9jTjLC9WP0jQJTpR4SmbPeVgetladnz/N5cnML73Ss65ADutQH9zy68NUQWg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568213110; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=VFFtO6xTOturoCF9LlarmLUAd8KWSqoxEu8UUxEoR18=; b=SV+vhsuS6oKt9fU6HlZuAknxfxCsaZEyIaSjfTQ1ogB02KPa9zAi3cLQ3zinu9jLfgi2wJNirmXmbyuPa3ukFLwKhJxcYPh2B4/R2E4mnfZT8W9zYfkacmtEU65eF1KR9YPdgZKguqWJzDY48G3viiKPPXpm2cUGwIS+aENsUOU= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 156821311060187.21508925406806; Wed, 11 Sep 2019 07:45:10 -0700 (PDT) Received: from localhost ([::1]:51822 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83ro-00014c-R9 for importer@patchew.org; Wed, 11 Sep 2019 10:45:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44719) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83m7-000396-Ix for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:16 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i83m6-0001xB-Ck for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:15 -0400 Received: from laurent.telenet-ops.be ([2a02:1800:110:4::f00:19]:53992) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i83m6-0001vO-6I for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:14 -0400 Received: from ramsan ([84.194.98.4]) by laurent.telenet-ops.be with bizsmtp id 0Ef42100205gfCL01Ef4Ro; Wed, 11 Sep 2019 16:39:10 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1i83lv-0006T7-V5; Wed, 11 Sep 2019 16:39:03 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1i83lv-0003PC-Tp; Wed, 11 Sep 2019 16:39:03 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Date: Wed, 11 Sep 2019 16:38:56 +0200 Message-Id: <20190911143858.13024-4-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190911143858.13024-1-geert+renesas@glider.be> References: <20190911143858.13024-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:110:4::f00:19 Subject: [Qemu-devel] [PATCH/RFC v2 3/5] gpio: Export gpio_name_to_desc() to modular GPIO code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Graf , Paolo Bonzini , Harish Jenny K N , Phil Reid Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Make gpio_name_to_desc() global, and export its symbol, so modular GPIO driver can make use of this function. This will be used by the GPIO Aggregator. Signed-off-by: Geert Uytterhoeven --- drivers/gpio/gpiolib.c | 3 ++- drivers/gpio/gpiolib.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index c2cf01fb72a9de87..c0caafd111e6ff51 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -288,7 +288,7 @@ static int gpiodev_add_to_list(struct gpio_device *gdev) /* * Convert a GPIO name to its descriptor */ -static struct gpio_desc *gpio_name_to_desc(const char * const name) +struct gpio_desc *gpio_name_to_desc(const char * const name) { struct gpio_device *gdev; unsigned long flags; @@ -315,6 +315,7 @@ static struct gpio_desc *gpio_name_to_desc(const char *= const name) =20 return NULL; } +EXPORT_SYMBOL_GPL(gpio_name_to_desc); =20 /* * Takes the names from gc->names and checks if they are all unique. If th= ey diff --git a/drivers/gpio/gpiolib.h b/drivers/gpio/gpiolib.h index b8b10a409c7b9c65..240d2868a3024b52 100644 --- a/drivers/gpio/gpiolib.h +++ b/drivers/gpio/gpiolib.h @@ -117,6 +117,7 @@ struct gpio_desc { const char *name; }; =20 +struct gpio_desc *gpio_name_to_desc(const char * const name); int gpiod_request(struct gpio_desc *desc, const char *label); void gpiod_free(struct gpio_desc *desc); int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, --=20 2.17.1 From nobody Fri Apr 19 10:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568213862; cv=none; d=zoho.com; s=zohoarc; b=VAgafQK8l4XD1udJKQDIsL5HD8MBEyOBnK0+eCkbFTZXdkbKJFI88/uwyfmP1bDkhKsQeAndvh2l+xSTFf1Pirlge2XTuzmz6iUn2oYak2u+g27uPHGtDv2ohOIFlrdQtiFNURp4iVrzz1qttltmkvaRoZfUo9p60t8eiOTO6xc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568213862; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=2hRjlKBAnSFevLOC15oJR5e4UXEicppOGaPjrHn8us4=; b=kGYIcjMI6/ovxJ2Q5/AkfFGBZM3geXWBflQ8fzqkehUiVUYDn4y0P6qCk54ongiRpvFFQYAe/n0W2p7GCJetCZmUZ4n+/lOpv64FdWbazkuaR8f2+pgs5V1db8ztInQJ11unMeaOHF6KmFaF5zGn4GdJ9zFCTpnmbvF35WF0L68= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568213862684693.8489478976057; Wed, 11 Sep 2019 07:57:42 -0700 (PDT) Received: from localhost ([::1]:52024 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i843w-0005WD-Ch for importer@patchew.org; Wed, 11 Sep 2019 10:57:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44745) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83m8-0003CV-Kg for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i83m6-0001xW-PO for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:16 -0400 Received: from michel.telenet-ops.be ([2a02:1800:110:4::f00:18]:46362) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i83m6-0001vF-G9 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:14 -0400 Received: from ramsan ([84.194.98.4]) by michel.telenet-ops.be with bizsmtp id 0Ef42100305gfCL06Ef4Rm; Wed, 11 Sep 2019 16:39:10 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1i83lv-0006TA-Vs; Wed, 11 Sep 2019 16:39:03 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1i83lv-0003PF-UY; Wed, 11 Sep 2019 16:39:03 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Date: Wed, 11 Sep 2019 16:38:57 +0200 Message-Id: <20190911143858.13024-5-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190911143858.13024-1-geert+renesas@glider.be> References: <20190911143858.13024-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:110:4::f00:18 Subject: [Qemu-devel] [PATCH/RFC v2 4/5] gpio: Add GPIO Forwarder Helper X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Graf , Paolo Bonzini , Harish Jenny K N , Phil Reid Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Add a helper for creating GPIO chips that merely forward all operations to other GPIOs. This will be used by the GPIO Aggregator. Signed-off-by: Geert Uytterhoeven --- I expect this can be used by the GPIO inverter, too, after adding an "invert" flag, or a filter function that checks which offsets need inversion. --- drivers/gpio/Kconfig | 3 + drivers/gpio/Makefile | 1 + drivers/gpio/gpiolib-fwd.c | 272 +++++++++++++++++++++++++++++++++++++ drivers/gpio/gpiolib-fwd.h | 16 +++ 4 files changed, 292 insertions(+) create mode 100644 drivers/gpio/gpiolib-fwd.c create mode 100644 drivers/gpio/gpiolib-fwd.h diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 38e096e6925fa65d..29d3ce8debcca1f6 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -47,6 +47,9 @@ config GPIOLIB_IRQCHIP select IRQ_DOMAIN bool =20 +config GPIOLIB_FWD + tristate + config DEBUG_GPIO bool "Debug GPIO calls" depends on DEBUG_KERNEL diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index d2fd19c15bae3fba..8a0e685c92b69855 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_GPIOLIB) +=3D gpiolib-devprop.o obj-$(CONFIG_OF_GPIO) +=3D gpiolib-of.o obj-$(CONFIG_GPIO_SYSFS) +=3D gpiolib-sysfs.o obj-$(CONFIG_GPIO_ACPI) +=3D gpiolib-acpi.o +obj-$(CONFIG_GPIOLIB_FWD) +=3D gpiolib-fwd.o =20 # Device drivers. Generally keep list sorted alphabetically obj-$(CONFIG_GPIO_GENERIC) +=3D gpio-generic.o diff --git a/drivers/gpio/gpiolib-fwd.c b/drivers/gpio/gpiolib-fwd.c new file mode 100644 index 0000000000000000..28dac8c60a981337 --- /dev/null +++ b/drivers/gpio/gpiolib-fwd.c @@ -0,0 +1,272 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// GPIO Forwarder Helper +// +// Copyright (C) 2019 Glider bvba + +#include +#include +#include +#include +#include +#include +#include + +#include "gpiolib.h" +#include "gpiolib-fwd.h" + +struct gpiochip_fwd { + struct gpio_chip chip; + struct gpio_desc **descs; + union { + struct mutex mlock; /* protects tmp[] if can_sleep */ + spinlock_t slock; /* protects tmp[] if !can_sleep */ + }; + unsigned long tmp[]; /* values and descs for multiple ops */ +}; + +static int gpio_fwd_get_direction(struct gpio_chip *chip, unsigned int off= set) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + return gpiod_get_direction(fwd->descs[offset]); +} + +static int gpio_fwd_direction_input(struct gpio_chip *chip, unsigned int o= ffset) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + return gpiod_direction_input(fwd->descs[offset]); +} + +static int gpio_fwd_direction_output(struct gpio_chip *chip, + unsigned int offset, int value) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + return gpiod_direction_output(fwd->descs[offset], value); +} + +static int gpio_fwd_get(struct gpio_chip *chip, unsigned int offset) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + return gpiod_get_value(fwd->descs[offset]); +} + +static int gpio_fwd_get_multiple(struct gpio_chip *chip, unsigned long *ma= sk, + unsigned long *bits) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + unsigned long *values, flags; + struct gpio_desc **descs; + unsigned int i, j =3D 0; + int error; + + if (chip->can_sleep) + mutex_lock(&fwd->mlock); + else + spin_lock_irqsave(&fwd->slock, flags); + + values =3D &fwd->tmp[0]; + bitmap_clear(values, 0, fwd->chip.ngpio); + descs =3D (void *)&fwd->tmp[BITS_TO_LONGS(fwd->chip.ngpio)]; + + for_each_set_bit(i, mask, fwd->chip.ngpio) + descs[j++] =3D fwd->descs[i]; + + error =3D gpiod_get_array_value(j, descs, NULL, values); + if (!error) { + j =3D 0; + for_each_set_bit(i, mask, fwd->chip.ngpio) + __assign_bit(i, bits, test_bit(j++, values)); + } + + if (chip->can_sleep) + mutex_unlock(&fwd->mlock); + else + spin_unlock_irqrestore(&fwd->slock, flags); + + return error; +} + +static void gpio_fwd_set(struct gpio_chip *chip, unsigned int offset, int = value) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + gpiod_set_value(fwd->descs[offset], value); +} + +static void gpio_fwd_set_multiple(struct gpio_chip *chip, unsigned long *m= ask, + unsigned long *bits) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + unsigned long *values, flags; + struct gpio_desc **descs; + unsigned int i, j =3D 0; + + if (chip->can_sleep) + mutex_lock(&fwd->mlock); + else + spin_lock_irqsave(&fwd->slock, flags); + + values =3D &fwd->tmp[0]; + descs =3D (void *)&fwd->tmp[BITS_TO_LONGS(fwd->chip.ngpio)]; + + for_each_set_bit(i, mask, fwd->chip.ngpio) { + __assign_bit(j, values, test_bit(i, bits)); + descs[j++] =3D fwd->descs[i]; + } + + gpiod_set_array_value(j, descs, NULL, values); + + if (chip->can_sleep) + mutex_unlock(&fwd->mlock); + else + spin_unlock_irqrestore(&fwd->slock, flags); +} + +static int gpio_fwd_set_config(struct gpio_chip *chip, unsigned int offset, + unsigned long config) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + + chip =3D fwd->descs[offset]->gdev->chip; + if (chip->set_config) + return chip->set_config(chip, offset, config); + + return -ENOTSUPP; +} + +static int gpio_fwd_init_valid_mask(struct gpio_chip *chip, + unsigned long *valid_mask, + unsigned int ngpios) +{ + struct gpiochip_fwd *fwd =3D gpiochip_get_data(chip); + unsigned int i; + + for (i =3D 0; i < ngpios; i++) { + if (!gpiochip_line_is_valid(fwd->descs[i]->gdev->chip, + gpio_chip_hwgpio(fwd->descs[i]))) + clear_bit(i, valid_mask); + } + + return 0; +} + +/** + * gpiochip_fwd_create() - Create a new GPIO forwarder + * @label: Name of the forwarder + * @parent: Optional parent device pointer + * @ngpios: Number of GPIOs in the forwarder. + * @descs: Array containing the GPIO descriptors to forward to. + * This array must contain @ngpios entries, and must not be deallo= cated + * before the forwarder has been destroyed again. + * + * This function creates a new gpiochip, which forwards all GPIO operation= s to + * the passed GPIO descriptors. + * + * Return: An opaque object pointer, or an ERR_PTR()-encoded negative error + * code on failure. + */ +struct gpiochip_fwd *gpiochip_fwd_create(const char *label, + struct device *parent, + unsigned int ngpios, + struct gpio_desc *descs[]) +{ + struct gpiochip_fwd *fwd; + struct gpio_chip *chip; + unsigned int i; + int error; + + fwd =3D kzalloc(struct_size(fwd, tmp, BITS_TO_LONGS(ngpios) + ngpios), + GFP_KERNEL); + if (!fwd) + return ERR_PTR(-ENOMEM); + + chip =3D &fwd->chip; + + for (i =3D 0; i < ngpios; i++) { + pr_debug("%s: gpio %u =3D> gpio-%d (%s)\n", label, i, + desc_to_gpio(descs[i]), descs[i]->label ? : "?"); + + error =3D gpiod_request(descs[i], label); + if (error) { + gpiod_err(descs[i], "%s: Cannot request GPIO: %d\n", + label, error); + goto free; + } + + if (gpiod_cansleep(descs[i])) + chip->can_sleep =3D true; + if (descs[i]->gdev->chip->set_config) + chip->set_config =3D gpio_fwd_set_config; + if (descs[i]->gdev->chip->init_valid_mask) + chip->init_valid_mask =3D gpio_fwd_init_valid_mask; + } + + chip->label =3D label; + chip->parent =3D parent; + chip->owner =3D THIS_MODULE; + chip->get_direction =3D gpio_fwd_get_direction; + chip->direction_input =3D gpio_fwd_direction_input; + chip->direction_output =3D gpio_fwd_direction_output; + chip->get =3D gpio_fwd_get; + chip->get_multiple =3D gpio_fwd_get_multiple; + chip->set =3D gpio_fwd_set; + chip->set_multiple =3D gpio_fwd_set_multiple; + chip->base =3D -1; + chip->ngpio =3D ngpios; + fwd->descs =3D descs; + + if (chip->can_sleep) + mutex_init(&fwd->mlock); + else + spin_lock_init(&fwd->slock); + + error =3D gpiochip_add_data(chip, fwd); + if (error) + goto free; + + return fwd; + +free: + while (i-- > 0) + gpiod_free(descs[i]); + + kfree(fwd); + + return ERR_PTR(error); +} +EXPORT_SYMBOL_GPL(gpiochip_fwd_create); + +/** + * gpiochip_fwd_destroy() - Destroy a new GPIO forwarder + * @fwd: Opaque object pointer, as returned by gpiochip_fwd_create() + * + * This function destroys GPIO forwarder gpiochip, previously created by + * gpiochip_fwd_create(). + + * Return: Zero. + */ +int gpiochip_fwd_destroy(struct gpiochip_fwd *fwd) +{ + unsigned int i; + + if (IS_ERR_OR_NULL(fwd)) + return 0; + + gpiochip_remove(&fwd->chip); + + for (i =3D 0; i < fwd->chip.ngpio; i++) + gpiod_free(fwd->descs[i]); + + kfree(fwd); + + return 0; +} +EXPORT_SYMBOL_GPL(gpiochip_fwd_destroy); + +MODULE_AUTHOR("Geert Uytterhoeven "); +MODULE_DESCRIPTION("GPIO Forwarder Helper"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/gpio/gpiolib-fwd.h b/drivers/gpio/gpiolib-fwd.h new file mode 100644 index 0000000000000000..68d299afc6883a9c --- /dev/null +++ b/drivers/gpio/gpiolib-fwd.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * GPIO Forwarder Helper + * + * Copyright (C) 2019 Glider bvba + */ + +struct device; +struct gpio_desc; +struct gpiochip_fwd; + +struct gpiochip_fwd *gpiochip_fwd_create(const char *label, + struct device *parent, + unsigned int ngpios, + struct gpio_desc *descs[]); +int gpiochip_fwd_destroy(struct gpiochip_fwd *fwd); --=20 2.17.1 From nobody Fri Apr 19 10:09:27 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org ARC-Seal: i=1; a=rsa-sha256; t=1568212931; cv=none; d=zoho.com; s=zohoarc; b=f/NvpA0FxHDiBSBF4sdadJmrnAtBDXle0O48CEUJZoobbq8WdJbSNhEi11OPpmhoAhObybtNgJ4mbKFoXoQWtZRUe63+ZFgADXDApWo75mw241aXzZqwnyi75xsDvKtgcY1EtVOPbFzkeAQ33yno/o0f7giWooud1F4CjmGO4b4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1568212931; h=Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=IjO7F4WuGrkVPc9TE4Ut6W3S5XdTEnhLEQMAt8sTj7o=; b=aW4d4rYyYovlswKTg9GYbYiHpKH+g9+SmssIEx5l23vojt+YoPSpWTCzCbW2yCh2Kzx+Xi/in4Vr9E+mCmsoKKgJN4Dt2aVpobcM6nXvvl5MmE9O5Z7WP44Wozv5yeragqOCuWA7VlHLdNWX5kKSK2BNABAmSbkBtoc2SXgjVfY= ARC-Authentication-Results: i=1; mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1568212931506603.5445931473957; Wed, 11 Sep 2019 07:42:11 -0700 (PDT) Received: from localhost ([::1]:51790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83ov-0006q4-Bf for importer@patchew.org; Wed, 11 Sep 2019 10:42:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44748) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i83m8-0003DM-Th for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:18 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i83m6-0001xk-R2 for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:16 -0400 Received: from xavier.telenet-ops.be ([2a02:1800:120:4::f00:14]:49474) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i83m6-0001vH-FJ for qemu-devel@nongnu.org; Wed, 11 Sep 2019 10:39:14 -0400 Received: from ramsan ([84.194.98.4]) by xavier.telenet-ops.be with bizsmtp id 0Ef42100405gfCL01Ef4Mv; Wed, 11 Sep 2019 16:39:10 +0200 Received: from rox.of.borg ([192.168.97.57]) by ramsan with esmtp (Exim 4.90_1) (envelope-from ) id 1i83lw-0006TC-16; Wed, 11 Sep 2019 16:39:04 +0200 Received: from geert by rox.of.borg with local (Exim 4.90_1) (envelope-from ) id 1i83lv-0003PI-VI; Wed, 11 Sep 2019 16:39:03 +0200 From: Geert Uytterhoeven To: Linus Walleij , Bartosz Golaszewski Date: Wed, 11 Sep 2019 16:38:58 +0200 Message-Id: <20190911143858.13024-6-geert+renesas@glider.be> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190911143858.13024-1-geert+renesas@glider.be> References: <20190911143858.13024-1-geert+renesas@glider.be> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 2a02:1800:120:4::f00:14 Subject: [Qemu-devel] [PATCH/RFC v2 5/5] gpio: Add GPIO Aggregator Driver X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Maydell , qemu-devel@nongnu.org, Geert Uytterhoeven , Marc Zyngier , Magnus Damm , Christoffer Dall , linux-kernel@vger.kernel.org, linux-renesas-soc@vger.kernel.org, linux-gpio@vger.kernel.org, Alexander Graf , Paolo Bonzini , Harish Jenny K N , Phil Reid Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" GPIO controllers are exported to userspace using /dev/gpiochip* character devices. Access control to these devices is provided by standard UNIX file system permissions, on an all-or-nothing basis: either a GPIO controller is accessible for a user, or it is not. Currently no mechanism exists to control access to individual GPIOs. Hence add a GPIO driver to aggregate existing GPIOs, and expose them as a new gpiochip. This is useful for implementing access control, and assigning a set of GPIOs to a specific user. Furthermore, this simplifies and hardens exporting GPIOs to a virtual machine, as the VM can just grab the full GPIO controller, and no longer needs to care about which GPIOs to grab and which not, reducing the attack surface. Aggregated GPIO controllers are instantiated by writing to the "new_device" attribute file in sysfs: $ echo [] [ ] ... > /sys/bus/platform/drivers/gpio-aggregator/new_device Where is a GPIO line name, is a GPIO chip label or name, and is a comma-separated list of GPIO offsets and/or GPIO offset ranges. Likewise, aggregated GPIO controllers can be destroyed after use: $ echo gpio-aggregator. \ > /sys/bus/platform/drivers/gpio-aggregator/delete_device Signed-off-by: Geert Uytterhoeven --- v2: - Add missing initialization of i in gpio_virt_agg_probe(), - Update for removed .need_valid_mask field and changed .init_valid_mask() signature, - Drop "virtual", rename to gpio-aggregator, - Drop bogus FIXME related to gpiod_set_transitory() expectations, - Use new GPIO Forwarder Helper, - Lift limit on the maximum number of GPIOs, - Improve parsing: - add support for specifying GPIOs by line name, - add support for specifying GPIO chips by ID, - add support for GPIO offset ranges, - names and offset specifiers must be separated by whitespace, - GPIO offsets must separated by spaces, - Use str_has_prefix() and kstrtouint(). I didn't use argv_split(), as it doesn't support quoted strings yet, and GPIO line names can contain spaces. Perhaps I should enhance argv_split() first, and use that? --- drivers/gpio/Kconfig | 9 + drivers/gpio/Makefile | 1 + drivers/gpio/gpio-aggregator.c | 333 +++++++++++++++++++++++++++++++++ 3 files changed, 343 insertions(+) create mode 100644 drivers/gpio/gpio-aggregator.c diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index 29d3ce8debcca1f6..058aa68fd7015e7c 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1483,6 +1483,15 @@ config GPIO_VIPERBOARD =20 endmenu =20 +config GPIO_AGGREGATOR + tristate "GPIO Aggregator" + select GPIOLIB_FWD + help + This enabled the GPIO Aggregator, which provides a way to aggregate + existing GPIOs into a new GPIO device. + This is useful for assigning a collection of GPIOs to a user, or + exported them to a virtual machine. + config GPIO_MOCKUP tristate "GPIO Testing Driver" select IRQ_SIM diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index 8a0e685c92b69855..2ec9128bcfefa40a 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_GPIO_74XX_MMIO) +=3D gpio-74xx-mmio.o obj-$(CONFIG_GPIO_ADNP) +=3D gpio-adnp.o obj-$(CONFIG_GPIO_ADP5520) +=3D gpio-adp5520.o obj-$(CONFIG_GPIO_ADP5588) +=3D gpio-adp5588.o +obj-$(CONFIG_GPIO_AGGREGATOR) +=3D gpio-aggregator.o obj-$(CONFIG_GPIO_ALTERA_A10SR) +=3D gpio-altera-a10sr.o obj-$(CONFIG_GPIO_ALTERA) +=3D gpio-altera.o obj-$(CONFIG_GPIO_AMD8111) +=3D gpio-amd8111.o diff --git a/drivers/gpio/gpio-aggregator.c b/drivers/gpio/gpio-aggregator.c new file mode 100644 index 0000000000000000..42485735bd823e02 --- /dev/null +++ b/drivers/gpio/gpio-aggregator.c @@ -0,0 +1,333 @@ +// SPDX-License-Identifier: GPL-2.0-only +// +// GPIO Aggregator +// +// Copyright (C) 2019 Glider bvba + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "gpiolib.h" +#include "gpiolib-fwd.h" + +#define DRV_NAME "gpio-aggregator" + +struct gpio_aggregator { + struct platform_device *pdev; +}; + +static DEFINE_MUTEX(gpio_aggregator_lock); /* protects idr */ +static DEFINE_IDR(gpio_aggregator_idr); + +static int gpiochip_match_label(struct gpio_chip *chip, void *data) +{ + return !strcmp(chip->label, data); +} + +static struct gpio_chip *gpiochip_find_by_label(const char *label) +{ + return gpiochip_find((void *)label, gpiochip_match_label); +} + +static int gpiochip_match_id(struct gpio_chip *chip, void *data) +{ + unsigned int id =3D (uintptr_t)data; + + return id =3D=3D chip->base || id =3D=3D chip->gpiodev->id; +} + +static struct gpio_chip *gpiochip_find_by_id(const char *id) +{ + unsigned int x; + + if (!str_has_prefix(id, "gpiochip")) + return NULL; + + if (kstrtouint(id + strlen("gpiochip"), 10, &x)) + return NULL; + + return gpiochip_find((void *)(uintptr_t)x, gpiochip_match_id); +} + +static ssize_t new_device_store(struct device_driver *driver, const char *= buf, + size_t count) +{ + struct platform_device *pdev; + struct gpio_aggregator *aggr; + int res, id; + + aggr =3D kzalloc(sizeof(*aggr), GFP_KERNEL); + if (!aggr) + return -ENOMEM; + + mutex_lock(&gpio_aggregator_lock); + id =3D idr_alloc(&gpio_aggregator_idr, aggr, 0, 0, GFP_KERNEL); + mutex_unlock(&gpio_aggregator_lock); + + if (id < 0) { + res =3D id; + goto free_ga; + } + + /* kernfs guarantees string termination, so count + 1 is safe */ + pdev =3D platform_device_register_data(NULL, DRV_NAME, id, buf, + count + 1); + if (IS_ERR(pdev)) { + res =3D PTR_ERR(pdev); + goto remove_idr; + } + + aggr->pdev =3D pdev; + return count; + +remove_idr: + mutex_lock(&gpio_aggregator_lock); + idr_remove(&gpio_aggregator_idr, id); + mutex_unlock(&gpio_aggregator_lock); +free_ga: + kfree(aggr); + return res; +} + +static DRIVER_ATTR_WO(new_device); + +static ssize_t delete_device_store(struct device_driver *driver, + const char *buf, size_t count) +{ + struct gpio_aggregator *aggr; + unsigned int id; + int error; + + if (!str_has_prefix(buf, DRV_NAME ".")) + return -EINVAL; + + error =3D kstrtouint(buf + strlen(DRV_NAME "."), 10, &id); + if (error) + return error; + + mutex_lock(&gpio_aggregator_lock); + aggr =3D idr_remove(&gpio_aggregator_idr, id); + mutex_unlock(&gpio_aggregator_lock); + if (!aggr) + return -ENOENT; + + platform_device_unregister(aggr->pdev); + kfree(aggr); + return count; +} +static DRIVER_ATTR_WO(delete_device); + +static struct attribute *gpio_aggregator_attrs[] =3D { + &driver_attr_new_device.attr, + &driver_attr_delete_device.attr, + NULL, +}; +ATTRIBUTE_GROUPS(gpio_aggregator); + +static char *get_arg(struct device *dev, const char **args) +{ + const char *start =3D *args, *end; + char *arg; + + if (*start =3D=3D '"') { + /* Quoted arg */ + end =3D strchr(++start, '"'); + if (!end) + return ERR_PTR(-EINVAL); + + arg =3D devm_kasprintf(dev, GFP_KERNEL, "%.*s", + (int)(end++ - start), start); + } else { + /* Unquoted arg */ + for (end =3D start; *end && !isspace(*end); end++) ; + + if (end =3D=3D start) + return ERR_PTR(-ENOENT); + + arg =3D devm_kasprintf(dev, GFP_KERNEL, "%.*s", + (int)(end - start), start); + } + if (!arg) + return ERR_PTR(-ENOMEM); + + while (isspace(*end)) + end++; + + *args =3D end; + return arg; +} + +static int add_gpio(struct device *dev, struct gpio_desc ***descs, + unsigned int *n, struct gpio_desc *desc) +{ + struct gpio_desc **new_descs; + + new_descs =3D devm_kmalloc_array(dev, *n + 1, sizeof(desc), GFP_KERNEL); + if (!new_descs) + return -ENOMEM; + + if (*descs) { + memcpy(new_descs, *descs, *n * sizeof(desc)); + devm_kfree(dev, *descs); + } + + new_descs[(*n)++] =3D desc; + *descs =3D new_descs; + return 0; +} + +static int gpio_aggregator_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + char *name, *offsets, *first, *last, *next; + const char *args =3D dev_get_platdata(dev); + struct gpio_desc **descs =3D NULL, *desc; + unsigned int a, b, i, n =3D 0; + struct gpiochip_fwd *fwd; + struct gpio_chip *chip; + int error; + + while (isspace(*args)) + args++; + + while (*args) { + name =3D get_arg(dev, &args); + if (IS_ERR(name)) { + dev_err(dev, "Cannot get GPIO specifier: %ld\n", + PTR_ERR(name)); + return PTR_ERR(name); + } + + desc =3D gpio_name_to_desc(name); + if (desc) { + /* Named GPIO line */ + error =3D add_gpio(dev, &descs, &n, desc); + if (error) + return error; + + devm_kfree(dev, name); + continue; + } + + /* GPIO chip + offsets */ + chip =3D gpiochip_find_by_label(name); + if (!chip) + chip =3D gpiochip_find_by_id(name); + if (!chip) { + dev_err(dev, "Cannot find gpiochip %s\n", name); + return -EINVAL; + } + + offsets =3D get_arg(dev, &args); + if (IS_ERR(offsets)) { + dev_err(dev, "Cannot get GPIO offsets: %ld\n", + PTR_ERR(offsets)); + return PTR_ERR(offsets); + } + + for (first =3D offsets; *first; first =3D next) { + next =3D strchrnul(first, ','); + if (*next) + *next++ =3D '\0'; + + last =3D strchr(first, '-'); + if (last) + *last++ =3D '\0'; + + if (kstrtouint(first, 10, &a)) { + dev_err(dev, "Cannot parse gpio index %s\n", + first); + return -EINVAL; + } + + if (!last) { + b =3D a; + } else if (kstrtouint(last, 10, &b)) { + dev_err(dev, "Cannot parse gpio index %s\n", + last); + return -EINVAL; + } + + for (i =3D a; i <=3D b; i++) { + desc =3D gpiochip_get_desc(chip, i); + if (IS_ERR(desc)) { + dev_err(dev, + "Cannot get GPIO %s/%u: %ld\n", + name, i, PTR_ERR(desc)); + return PTR_ERR(desc); + } + + error =3D add_gpio(dev, &descs, &n, desc); + if (error) + return error; + } + } + + devm_kfree(dev, offsets); + devm_kfree(dev, name); + } + + if (!descs) { + dev_err(dev, "No GPIOs specified\n"); + return -EINVAL; + } + + fwd =3D gpiochip_fwd_create(dev_name(dev), dev, n, descs); + if (IS_ERR(fwd)) + return PTR_ERR(fwd); + + platform_set_drvdata(pdev, fwd); + return 0; +} + +static int gpio_aggregator_remove(struct platform_device *pdev) +{ + struct gpiochip_fwd *fwd =3D platform_get_drvdata(pdev); + + return gpiochip_fwd_destroy(fwd); +} + +static struct platform_driver gpio_aggregator_driver =3D { + .probe =3D gpio_aggregator_probe, + .remove =3D gpio_aggregator_remove, + .driver =3D { + .name =3D DRV_NAME, + .groups =3D gpio_aggregator_groups, + }, +}; + +static int __init gpio_aggregator_init(void) +{ + return platform_driver_register(&gpio_aggregator_driver); +} +module_init(gpio_aggregator_init); + +static int __exit gpio_aggregator_idr_remove(int id, void *p, void *data) +{ + struct gpio_aggregator *aggr =3D p; + + platform_device_unregister(aggr->pdev); + kfree(aggr); + return 0; +} + +static void __exit gpio_aggregator_exit(void) +{ + mutex_lock(&gpio_aggregator_lock); + idr_for_each(&gpio_aggregator_idr, gpio_aggregator_idr_remove, NULL); + idr_destroy(&gpio_aggregator_idr); + mutex_unlock(&gpio_aggregator_lock); + + platform_driver_unregister(&gpio_aggregator_driver); +} +module_exit(gpio_aggregator_exit); + +MODULE_AUTHOR("Geert Uytterhoeven "); +MODULE_DESCRIPTION("GPIO Aggregator"); +MODULE_LICENSE("GPL v2"); --=20 2.17.1