From patchwork Wed Nov 21 10:14:09 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Christophe PLAGNIOL-VILLARD X-Patchwork-Id: 1779351 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-process-083081@patchwork2.kernel.org Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by patchwork2.kernel.org (Postfix) with ESMTP id 5B56CDF288 for ; Wed, 21 Nov 2012 10:18:31 +0000 (UTC) Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb7MG-0003gA-2C; Wed, 21 Nov 2012 10:16:40 +0000 Received: from 20.mo4.mail-out.ovh.net ([46.105.33.73] helo=mo4.mail-out.ovh.net) by merlin.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1Tb7Lr-0003UZ-El for linux-arm-kernel@lists.infradead.org; Wed, 21 Nov 2012 10:16:22 +0000 Received: from mail92.ha.ovh.net (b9.ovh.net [213.186.33.59]) by mo4.mail-out.ovh.net (Postfix) with SMTP id C45EA1054DD6 for ; Wed, 21 Nov 2012 11:23:58 +0100 (CET) Received: from b0.ovh.net (HELO queueout) (213.186.33.50) by b0.ovh.net with SMTP; 21 Nov 2012 12:16:11 +0200 Received: from ns32433.ovh.net (HELO localhost) (plagnioj%jcrosoft.com@213.251.161.87) by ns0.ovh.net with SMTP; 21 Nov 2012 12:16:07 +0200 From: Jean-Christophe PLAGNIOL-VILLARD To: linux-arm-kernel@lists.infradead.org X-Ovh-Mailout: 178.32.228.4 (mo4.mail-out.ovh.net) Subject: [PATCH 2/2] gpiolib-of: ad gpio-export support Date: Wed, 21 Nov 2012 11:14:09 +0100 Message-Id: <1353492849-29397-2-git-send-email-plagnioj@jcrosoft.com> X-Mailer: git-send-email 1.7.10 In-Reply-To: <1353492849-29397-1-git-send-email-plagnioj@jcrosoft.com> References: <20121121101259.GQ4398@game.jcrosoft.org> <1353492849-29397-1-git-send-email-plagnioj@jcrosoft.com> X-Ovh-Tracer-Id: 12242754113392389117 X-Ovh-Remote: 213.251.161.87 (ns32433.ovh.net) X-Ovh-Local: 213.186.33.20 (ns0.ovh.net) X-OVH-SPAMSTATE: OK X-OVH-SPAMSCORE: 0 X-OVH-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehgedrudeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeflvggrnhdqvehhrhhishhtohhphhgvucfrnfetiffpkffqnfdqggfknffnteftffcuoehplhgrghhnihhojhesjhgtrhhoshhofhhtrdgtohhmqeenucfjughrpefhvffufffkofgjfhestddtredtredttd X-Spam-Check: DONE|U 0.5/N X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrfeehgedrudeiucetufdoteggodetrfcurfhrohhfihhlvgemucfqggfjnecuuegrihhlohhuthemuceftddtnecunecuhfhrohhmpeflvggrnhdqvehhrhhishhtohhphhgvucfrnfetiffpkffqnfdqggfknffnteftffcuoehplhgrghhnihhojhesjhgtrhhoshhofhhtrdgtohhmqeenucfjughrpefhvffufffkofgjfhestddtredtredttd X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20121121_051615_992170_F8173BCA X-CRM114-Status: GOOD ( 18.99 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [46.105.33.73 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: devicetree-discuss@lists.ozlabs.org, Jean-Christophe PLAGNIOL-VILLARD X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This will allow to export gpios with or without names Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD --- Documentation/devicetree/bindings/gpio/gpio.txt | 60 ++++++++++++++++++++++ drivers/gpio/gpiolib-of.c | 61 +++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/Documentation/devicetree/bindings/gpio/gpio.txt b/Documentation/devicetree/bindings/gpio/gpio.txt index a336287..c2a9024 100644 --- a/Documentation/devicetree/bindings/gpio/gpio.txt +++ b/Documentation/devicetree/bindings/gpio/gpio.txt @@ -112,3 +112,63 @@ where, The pinctrl node must have "#gpio-range-cells" property to show number of arguments to pass with phandle from gpio controllers node. + +3) gpio-export +-------------- + +gpio-export will allow you to automatically export gpio + +required properties: +- compatible: Should be "gpio-export" + +in each child node will reprensent a gpio or if no name is specified +a list of gpio to export + +required properties: +- gpios: gpio to export + +optional properties: + - gpio-export,name: export name + - gpio-export,output: to set the as output with default value + if no present gpio as input + - pio-export,direction_may_change: boolean to allow the direction to be controllable + +Example: + + +gpio_export { + compatible = "gpio-export"; + #size-cells = <0>; + + in { + gpio-export,name = "in"; + gpios = <&pioC 20 0>; + }; + + out { + gpio-export,name = "out"; + gpio-export,output = <1>; + gpio-export,direction_may_change; + gpios = <&pioC 21 0>; + }; + + in_out { + gpio-export,name = "in_out"; + gpio-export,direction_may_change; + gpios = <&pioC 21 0>; + }; + + gpios_in { + gpios = <&pioB 0 0 + &pioB 3 0 + &pioC 4 0>; + gpio-export,direction_may_change; + }; + + gpios_out { + gpios = <&pioB 1 0 + &pioB 2 0 + &pioC 3 0>; + gpio-export,output = <1>; + }; +}; diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index a40cd84..0ab9be4 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -21,6 +21,8 @@ #include #include #include +#include +#include /* Private data structure for of_gpiochip_find_and_xlate */ struct gg_data { @@ -277,3 +279,62 @@ void of_gpiochip_remove(struct gpio_chip *chip) if (chip->of_node) of_node_put(chip->of_node); } + +static struct of_device_id gpio_export_ids[] = { + { .compatible = "gpio-export" }, + { /* sentinel */ } +}; + +static int __init of_gpio_export_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + struct device_node *cnp; + u32 val; + int nb = 0; + + for_each_child_of_node(np, cnp) { + const char *name = NULL; + int gpio; + bool dmc; + int max_gpio = 1; + int i; + + of_property_read_string(cnp, "gpio-export,name", &name); + + if (!name) + max_gpio = of_gpio_count(cnp); + + for (i = 0; i < max_gpio; i++) { + gpio = of_get_gpio(cnp, i); + if (devm_gpio_request(&pdev->dev, gpio, name ? name : of_node_full_name(np))) + continue; + + if (!of_property_read_u32(cnp, "gpio-export,output", &val)) + gpio_direction_output(gpio, val); + else + gpio_direction_input(gpio); + + dmc = of_property_read_bool(np, "gpio-export,direction_may_change"); + gpio_export_with_name(gpio, dmc, name); + nb++; + } + } + + dev_info(&pdev->dev, "%d gpio(s) exported\n", nb); + + return 0; +} + +static struct platform_driver gpio_export_driver = { + .driver = { + .name = "gpio-export", + .owner = THIS_MODULE, + .of_match_table = of_match_ptr(gpio_export_ids), + }, +}; + +static int __init of_gpio_export_init(void) +{ + return platform_driver_probe(&gpio_export_driver, of_gpio_export_probe); +} +device_initcall(of_gpio_export_init);