From patchwork Fri Feb 19 10:16:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geert Uytterhoeven X-Patchwork-Id: 8359221 Return-Path: X-Original-To: patchwork-linux-input@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 53A5A9F727 for ; Fri, 19 Feb 2016 10:16:38 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4EB2C20416 for ; Fri, 19 Feb 2016 10:16:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 44837203F7 for ; Fri, 19 Feb 2016 10:16:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2992556AbcBSKQe (ORCPT ); Fri, 19 Feb 2016 05:16:34 -0500 Received: from baptiste.telenet-ops.be ([195.130.132.51]:54273 "EHLO baptiste.telenet-ops.be" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2992561AbcBSKQ1 (ORCPT ); Fri, 19 Feb 2016 05:16:27 -0500 Received: from ayla.of.borg ([84.195.106.123]) by baptiste.telenet-ops.be with bizsmtp id LAGN1s00L2fm56U01AGNDa; Fri, 19 Feb 2016 11:16:23 +0100 Received: from ramsan.of.borg ([192.168.97.29] helo=ramsan) by ayla.of.borg with esmtp (Exim 4.82) (envelope-from ) id 1aWi6o-0002X8-F4; Fri, 19 Feb 2016 11:16:22 +0100 Received: from geert by ramsan with local (Exim 4.82) (envelope-from ) id 1aWi6q-0001lb-0v; Fri, 19 Feb 2016 11:16:24 +0100 From: Geert Uytterhoeven To: Dmitry Torokhov , Aaron Lu , Mika Westerberg , "Rafael J. Wysocki" Cc: Vincent Pelletier , Linus Walleij , Alexandre Courbot , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org, Geert Uytterhoeven Subject: [PATCH 3/3] input: gpio_keys: Make use of the device property API Date: Fri, 19 Feb 2016 11:16:22 +0100 Message-Id: <1455876982-6743-4-git-send-email-geert+renesas@glider.be> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455876982-6743-1-git-send-email-geert+renesas@glider.be> References: <1455876982-6743-1-git-send-email-geert+renesas@glider.be> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham 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 Make use of the device property API in this driver so that both OF based systems and ACPI based systems can use this driver. Based on commits b26d4e2283b6d9b6 ("input: gpio_keys_polled: Make use of device property API"), 99b4ffbd84ea4191 ("Input: gpio_keys[_polled] - change name of wakeup property"), and 1feb57a245a4910b ("gpio: add parameter to allow the use named gpios"). Signed-off-by: Geert Uytterhoeven --- Tested with DT only. --- drivers/input/keyboard/gpio_keys.c | 77 +++++++++++++++----------------------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index b6262d94aff19f70..5764308e3b26314a 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -27,9 +27,6 @@ #include #include #include -#include -#include -#include #include struct gpio_button_data { @@ -625,26 +622,20 @@ static void gpio_keys_close(struct input_dev *input) * Handlers for alternative sources of platform_data */ -#ifdef CONFIG_OF /* - * Translate OpenFirmware node properties into platform_data + * Translate properties into platform_data */ static struct gpio_keys_platform_data * gpio_keys_get_devtree_pdata(struct platform_device *pdev) { struct device *dev = &pdev->dev; - struct device_node *node, *pp; struct gpio_keys_platform_data *pdata; struct gpio_keys_button *button; + struct fwnode_handle *child; int error; int nbuttons; - int i; - - node = dev->of_node; - if (!node) - return ERR_PTR(-ENODEV); - nbuttons = of_get_available_child_count(node); + nbuttons = device_get_child_node_count(dev); if (nbuttons == 0) return ERR_PTR(-ENODEV); @@ -655,32 +646,29 @@ gpio_keys_get_devtree_pdata(struct platform_device *pdev) return ERR_PTR(-ENOMEM); pdata->buttons = (struct gpio_keys_button *)(pdata + 1); - pdata->nbuttons = nbuttons; - - pdata->rep = !!of_get_property(node, "autorepeat", NULL); - of_property_read_string(node, "label", &pdata->name); + pdata->rep = device_property_present(dev, "autorepeat"); + device_property_read_string(dev, "label", &pdata->name); - i = 0; - for_each_available_child_of_node(node, pp) { - enum of_gpio_flags flags; + device_for_each_child_node(dev, child) { + struct gpio_desc *desc; - button = &pdata->buttons[i++]; - - button->gpio = of_get_gpio_flags(pp, 0, &flags); - if (button->gpio < 0) { - error = button->gpio; + desc = devm_get_gpiod_from_child(dev, NULL, child); + if (IS_ERR(desc)) { + error = PTR_ERR(desc); if (error != -ENOENT) { if (error != -EPROBE_DEFER) dev_err(dev, "Failed to get gpio flags, error: %d\n", error); + fwnode_handle_put(child); return ERR_PTR(error); } - } else { - button->active_low = flags & OF_GPIO_ACTIVE_LOW; } + button = &pdata->buttons[pdata->nbuttons++]; + button->gpiod = desc; + button->irq = platform_get_irq(pdev, 0); if (!gpio_is_valid(button->gpio) && button->irq < 0) { @@ -688,24 +676,29 @@ gpio_keys_get_devtree_pdata(struct platform_device *pdev) return ERR_PTR(-EINVAL); } - if (of_property_read_u32(pp, "linux,code", &button->code)) { - dev_err(dev, "Button without keycode: 0x%x\n", - button->gpio); + if (fwnode_property_read_u32(child, "linux,code", + &button->code)) { + dev_err(dev, "Button without keycode: %d\n", + pdata->nbuttons - 1); + fwnode_handle_put(child); return ERR_PTR(-EINVAL); } - button->desc = of_get_property(pp, "label", NULL); + fwnode_property_read_string(child, "label", &button->desc); - if (of_property_read_u32(pp, "linux,input-type", &button->type)) + if (fwnode_property_read_u32(child, "linux,input-type", + &button->type)) button->type = EV_KEY; - button->wakeup = of_property_read_bool(pp, "wakeup-source") || - /* legacy name */ - of_property_read_bool(pp, "gpio-key,wakeup"); + button->wakeup = + fwnode_property_read_bool(child, "wakeup-source") || + /* legacy name */ + fwnode_property_read_bool(child, "gpio-key,wakeup"); - button->can_disable = !!of_get_property(pp, "linux,can-disable", NULL); + button->can_disable = + fwnode_property_present(child, "linux,can-disable"); - if (of_property_read_u32(pp, "debounce-interval", + if (fwnode_property_read_u32(child, "debounce-interval", &button->debounce_interval)) button->debounce_interval = 5; } @@ -722,16 +715,6 @@ static const struct of_device_id gpio_keys_of_match[] = { }; MODULE_DEVICE_TABLE(of, gpio_keys_of_match); -#else - -static inline struct gpio_keys_platform_data * -gpio_keys_get_devtree_pdata(struct platform_device *pdev) -{ - return ERR_PTR(-ENODEV); -} - -#endif - static int gpio_keys_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -887,7 +870,7 @@ static struct platform_driver gpio_keys_device_driver = { .driver = { .name = "gpio-keys", .pm = &gpio_keys_pm_ops, - .of_match_table = of_match_ptr(gpio_keys_of_match), + .of_match_table = gpio_keys_of_match, } };