From patchwork Tue Oct 7 00:18:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 5040081 Return-Path: X-Original-To: patchwork-linux-acpi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 70F3CC11AC for ; Tue, 7 Oct 2014 00:00:13 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 874A220172 for ; Tue, 7 Oct 2014 00:00:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7689420166 for ; Tue, 7 Oct 2014 00:00:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752186AbaJFX7q (ORCPT ); Mon, 6 Oct 2014 19:59:46 -0400 Received: from v094114.home.net.pl ([79.96.170.134]:64420 "HELO v094114.home.net.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with SMTP id S1751290AbaJFX7o (ORCPT ); Mon, 6 Oct 2014 19:59:44 -0400 Received: from cmy248.neoplus.adsl.tpnet.pl [83.31.152.248] (HELO vostro.rjw.lan) by serwer1319399.home.pl [79.96.170.134] with SMTP (IdeaSmtpServer v0.80) id 52e52daa9074512c; Tue, 7 Oct 2014 01:59:43 +0200 From: "Rafael J. Wysocki" To: Linux Kernel Mailing List , Bryan Wu Cc: Greg Kroah-Hartman , Mika Westerberg , ACPI Devel Maling List , Aaron Lu , devicetree@vger.kernel.org, Linus Walleij , Alexandre Courbot , Dmitry Torokhov , Grant Likely , Arnd Bergmann , Darren Hart , Mark Rutland Subject: [PATCH 12/13] leds: leds-gpio: Make use of device property API Date: Tue, 07 Oct 2014 02:18:45 +0200 Message-ID: <1997643.hzLDnYTZoH@vostro.rjw.lan> User-Agent: KMail/4.11.5 (Linux/3.16.0-rc5+; KDE/4.11.5; x86_64; ; ) In-Reply-To: <2660541.BycO7TFnA2@vostro.rjw.lan> References: <2660541.BycO7TFnA2@vostro.rjw.lan> MIME-Version: 1.0 Sender: linux-acpi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY, URIBL_RHS_DOB 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 From: Rafael J. Wysocki Make use of device property API in this driver so that both OF and ACPI based system can use the same driver. This change contains material from Max Eliaser and Mika Westerberg. Signed-off-by: Mika Westerberg Signed-off-by: Rafael J. Wysocki Acked-by: Bryan Wu --- drivers/leds/leds-gpio.c | 67 +++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 37 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Index: linux-pm/drivers/leds/leds-gpio.c =================================================================== --- linux-pm.orig/drivers/leds/leds-gpio.c +++ linux-pm/drivers/leds/leds-gpio.c @@ -15,13 +15,11 @@ #include #include #include -#include -#include -#include #include #include #include #include +#include struct gpio_led_data { struct led_classdev cdev; @@ -171,40 +169,41 @@ static inline int sizeof_gpio_leds_priv( (sizeof(struct gpio_led_data) * num_leds); } -/* Code to create from OpenFirmware platform devices */ -#ifdef CONFIG_OF_GPIO -static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) +static struct gpio_leds_priv *gpio_leds_create(struct platform_device *pdev) { - struct device_node *np = pdev->dev.of_node, *child; + struct device *dev = &pdev->dev; struct gpio_leds_priv *priv; int count, ret; + void *child; - /* count LEDs in this device, so we know how much to allocate */ - count = of_get_available_child_count(np); + count = device_get_child_node_count(dev); if (!count) return ERR_PTR(-ENODEV); - for_each_available_child_of_node(np, child) - if (of_get_gpio(child, 0) == -EPROBE_DEFER) - return ERR_PTR(-EPROBE_DEFER); - - priv = devm_kzalloc(&pdev->dev, sizeof_gpio_leds_priv(count), - GFP_KERNEL); + priv = devm_kzalloc(dev, sizeof_gpio_leds_priv(count), GFP_KERNEL); if (!priv) return ERR_PTR(-ENOMEM); - for_each_available_child_of_node(np, child) { + device_for_each_child_node(dev, child) { struct gpio_led led = {}; - enum of_gpio_flags flags; - const char *state; + const char *state = NULL; + + led.gpiod = devm_get_named_gpiod_from_child(dev, child, + "gpios", 0); + if (IS_ERR(led.gpiod)) { + device_put_child_node(dev, child); + goto err; + } - led.gpio = of_get_gpio_flags(child, 0, &flags); - led.active_low = flags & OF_GPIO_ACTIVE_LOW; - led.name = of_get_property(child, "label", NULL) ? : child->name; - led.default_trigger = - of_get_property(child, "linux,default-trigger", NULL); - state = of_get_property(child, "default-state", NULL); - if (state) { + device_child_property_read_string(dev, child, + "label", &led.name); + device_child_property_read_string(dev, child, + "linux,default-trigger", + &led.default_trigger); + + if (!device_child_property_read_string(dev, child, + "linux,default_state", + &state)) { if (!strcmp(state, "keep")) led.default_state = LEDS_GPIO_DEFSTATE_KEEP; else if (!strcmp(state, "on")) @@ -213,13 +212,14 @@ static struct gpio_leds_priv *gpio_leds_ led.default_state = LEDS_GPIO_DEFSTATE_OFF; } - if (of_get_property(child, "retain-state-suspended", NULL)) + if (!device_get_child_property(dev, child, + "retain-state-suspended", NULL)) led.retain_state_suspended = 1; ret = create_gpio_led(&led, &priv->leds[priv->num_leds++], - &pdev->dev, NULL); + dev, NULL); if (ret < 0) { - of_node_put(child); + device_put_child_node(dev, child); goto err; } } @@ -238,13 +238,6 @@ static const struct of_device_id of_gpio }; MODULE_DEVICE_TABLE(of, of_gpio_leds_match); -#else /* CONFIG_OF_GPIO */ -static struct gpio_leds_priv *gpio_leds_create_of(struct platform_device *pdev) -{ - return ERR_PTR(-ENODEV); -} -#endif /* CONFIG_OF_GPIO */ - static int gpio_led_probe(struct platform_device *pdev) { @@ -273,7 +266,7 @@ static int gpio_led_probe(struct platfor } } } else { - priv = gpio_leds_create_of(pdev); + priv = gpio_leds_create(pdev); if (IS_ERR(priv)) return PTR_ERR(priv); } @@ -300,7 +293,7 @@ static struct platform_driver gpio_led_d .driver = { .name = "leds-gpio", .owner = THIS_MODULE, - .of_match_table = of_match_ptr(of_gpio_leds_match), + .of_match_table = of_gpio_leds_match, }, };