From patchwork Wed Jun 17 13:42:18 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tomeu Vizoso X-Patchwork-Id: 6626261 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DDCBA9F326 for ; Wed, 17 Jun 2015 13:49:15 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1321D205E6 for ; Wed, 17 Jun 2015 13:49:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3977D204AD for ; Wed, 17 Jun 2015 13:49:13 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Dfc-00063a-Cn; Wed, 17 Jun 2015 13:46:24 +0000 Received: from mail-wi0-x232.google.com ([2a00:1450:400c:c05::232]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Z5Dcq-0002gq-6V for linux-arm-kernel@lists.infradead.org; Wed, 17 Jun 2015 13:43:33 +0000 Received: by wicnd19 with SMTP id nd19so29542140wic.1 for ; Wed, 17 Jun 2015 06:43:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Yp9gmDobdFIPxYBFQeKxkMpJTTIbGGZ92m3iytj/wjc=; b=LGdyTm10D4FPbN4+bsZHcSAevgwnMpPyeCov9T+aYQrUKUAztWn5Txdz2K+w83jSLw o8t4eYRfgKoSy0kqEtCXPun5PJ2aEkyizJtDMvQW9YUgfilUfQa7qVjwF5Ws+OcvgvG8 VAfPkKqhiV/5+zn20CO4sd1amCuPWRa1qV0h055JL7FlD3sKzIC0TlEuOtcKB5wVTBh7 V4mrwbexiSeGWaVNQJYiztcS6PsnISXdAE5iqfydYRbhZTw3kXfsKNxN37F2jlPhERpb QSrb/yVR2eS6TVyNNqa54pKtPRfulJCMhVxpDBbRiIyiH6So9yEfvxV8pQYhb3ZJxUOb 59lw== X-Received: by 10.180.73.236 with SMTP id o12mr54704119wiv.56.1434548590310; Wed, 17 Jun 2015 06:43:10 -0700 (PDT) Received: from cizrna.lan ([109.72.12.132]) by mx.google.com with ESMTPSA id v3sm6920361wja.31.2015.06.17.06.43.08 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jun 2015 06:43:09 -0700 (PDT) From: Tomeu Vizoso To: linux-arm-kernel@lists.infradead.org Subject: [PATCH 08/13] gpio: sysfs: implement class.get_dependencies() Date: Wed, 17 Jun 2015 15:42:18 +0200 Message-Id: <1434548543-22949-9-git-send-email-tomeu.vizoso@collabora.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> References: <1434548543-22949-1-git-send-email-tomeu.vizoso@collabora.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150617_064332_518322_89DA7772 X-CRM114-Status: GOOD ( 13.49 ) X-Spam-Score: -0.7 (/) Cc: Mark Rutland , Krzysztof Kozlowski , Linus Walleij , Andrzej Hajda , Thierry Reding , Lv Zheng , Alexander Holler , Alexandre Courbot , Russell King , Pawel Moll , Stephen Warren , Robert Moore , Grant Likely , Len Brown , Arnd Bergmann , Ian Campbell , Rob Herring , =?UTF-8?q?Terje=20Bergstr=C3=B6m?= , Tomeu Vizoso , Greg Kroah-Hartman , Dmitry Torokhov , "Rafael J. Wysocki" , linux-kernel@vger.kernel.org, Mark Brown , Kumar Gala , Javier Martinez Canillas X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP So the GPIO subsystem can be queried about the dependencies of nodes that consume GPIOs, as specified in bindings/gpio/gpio.txt. Signed-off-by: Tomeu Vizoso --- drivers/gpio/gpiolib-sysfs.c | 81 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/drivers/gpio/gpiolib-sysfs.c b/drivers/gpio/gpiolib-sysfs.c index b57ed8e..d0a7fb1 100644 --- a/drivers/gpio/gpiolib-sysfs.c +++ b/drivers/gpio/gpiolib-sysfs.c @@ -7,6 +7,7 @@ #include #include #include +#include #include "gpiolib.h" @@ -515,6 +516,85 @@ done: return status ? : len; } +static bool strends(const char *str, const char *postfix) +{ + if (strlen(str) < strlen(postfix)) + return false; + + return strcmp(str + strlen(str) - strlen(postfix), postfix) == 0; +} + +static void add_dependency(struct fwnode_handle *fwnode, + struct list_head *list) +{ + struct fwnode_dependency *dep; + + dep = kzalloc(sizeof(*dep), GFP_KERNEL); + if (!dep) + return; + + INIT_LIST_HEAD(&dep->dependency); + dep->fwnode = fwnode; + + list_add_tail(&dep->dependency, list); +} + +struct list_head *gpio_get_dependencies(struct fwnode_handle *fwnode) +{ + struct device_node *np = of_node(fwnode); + struct list_head *list = NULL; + struct property *pp; + struct of_phandle_args pspec; + int count, i, ret; + + if (!is_of_node(fwnode)) + return NULL; + + np = of_node(fwnode); + if (!np) + return NULL; + + list = kzalloc(sizeof(*list), GFP_KERNEL); + if (!list) + return NULL; + + INIT_LIST_HEAD(list); + + for_each_property_of_node(np, pp) { + if (strcmp(pp->name, "gpio") && + !strends(pp->name, "-gpios") && + !strends(pp->name, "-gpio")) + continue; + + count = of_count_phandle_with_args(np, pp->name, + "#gpio-cells"); + for (i = 0; i < count; i++) { + ret = of_parse_phandle_with_args(np, pp->name, + "#gpio-cells", i, + &pspec); + if (ret || !pspec.np) + continue; + + add_dependency(&pspec.np->fwnode, list); + + of_node_put(pspec.np); + } + } + + for (i = 0;; i++) { + ret = of_parse_phandle_with_fixed_args(np, "gpio-ranges", 3, + i, &pspec); + if (ret) + break; + + add_dependency(&pspec.np->fwnode, list); + + of_node_put(pspec.np); + } + + return list; +} + static struct class_attribute gpio_class_attrs[] = { __ATTR(export, 0200, NULL, export_store), __ATTR(unexport, 0200, NULL, unexport_store), @@ -526,6 +606,7 @@ static struct class gpio_class = { .owner = THIS_MODULE, .class_attrs = gpio_class_attrs, + .get_dependencies = gpio_get_dependencies, };