From patchwork Thu Sep 6 07:59:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 10589979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DC5826CB for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C199E2A3A5 for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4C642A4E9; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 45F2B2A4B5 for ; Thu, 6 Sep 2018 07:59:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728094AbeIFMdc (ORCPT ); Thu, 6 Sep 2018 08:33:32 -0400 Received: from mail-lj1-f196.google.com ([209.85.208.196]:34155 "EHLO mail-lj1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728109AbeIFMdb (ORCPT ); Thu, 6 Sep 2018 08:33:31 -0400 Received: by mail-lj1-f196.google.com with SMTP id f8-v6so8546752ljk.1 for ; Thu, 06 Sep 2018 00:59:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=g6txyK8o4x08RKCFZhnsAtEHfb0e8GRkllRjW843LzE=; b=hVP9S6Ko2zpWExobKJOwU+ctnG8ackVNZhXfYkz/H35rBNTQtaoHKcu6ebRpRuusei y4rCKd4wqrh0akFwfSK8cACDKYVK3zIkCg4pwIPsruiTBlwBcpn2SDgz8qvHWUIhODON TIDKEcCM3MCHgvt3baOouY5u8jQu339ucix/s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=g6txyK8o4x08RKCFZhnsAtEHfb0e8GRkllRjW843LzE=; b=rq4RCxtFWei1zWhiWR5nUGTBqABirRRbGvs0CJH7zJF26vtBKb9ZmzRT7ut6Ac3zQ7 lNqufcemGB8uj0pOhCNgRNHFo5ApzxJpC91vjnwofOMezM5WvSpfaMAfdb9dxilvSeoj aLV/jyObbP4BZ8ohIyyUnMQLH3fzJJ5qOX5f2pvHqXOkTuMbWs8Yzm7m3jgQxGh7kCiW tKldxsvM/m40IJXNTuhm9gnyPKKYu44qmieXIBNWfVch3srDYj8PmPJ1EAgOjhxSmsVg ZbOYCTP87Kt9fUPfCAWcpbAxrTHbnxlX1dAR6IVmnAcKZzpPG0VUsxdXH3Zp01ODE8ZE bZRQ== X-Gm-Message-State: APzg51AC0Kb8DneOUGw0eGgyh3Z9o/Al5Q8QUBAf3QJXrgO3BJ2G+pFN Vl5DI5edU6GI7p8e+gdEEprV6w== X-Google-Smtp-Source: ANB0VdYGyhczQ13O7u7FS2yt5gOgN4hgg6HVw607EJq183gzKdEN5kzNgaPcEQSe808RMAF67OzrSQ== X-Received: by 2002:a2e:712:: with SMTP id 18-v6mr1074946ljh.101.1536220758595; Thu, 06 Sep 2018 00:59:18 -0700 (PDT) Received: from localhost.bredbandsbolaget (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id f129-v6sm690869lff.37.2018.09.06.00.59.16 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 06 Sep 2018 00:59:17 -0700 (PDT) From: Linus Walleij To: Dmitry Torokhov , linux-input@vger.kernel.org, linux-gpio@vger.kernel.org Cc: Andy Shevchenko , "Rafael J . Wysocki" , Sakari Ailus , Linus Walleij Subject: [PATCH 2/3] Input: gpio_keys - always try fwnode first Date: Thu, 6 Sep 2018 09:59:01 +0200 Message-Id: <20180906075902.31240-3-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180906075902.31240-1-linus.walleij@linaro.org> References: <20180906075902.31240-1-linus.walleij@linaro.org> Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This makes the gpio_keys input driver try fwnode first when looking up GPIO descriptors, even if no fwnode was passed. With the changes to the gpiolib, if NULL us passed as fwnode, the gpiolib will attempt to look up the GPIO descriptor from the machine descriptor tables. Cc: Dmitry Torokhov Cc: Andy Shevchenko Cc: Rafael J. Wysocki Cc: Sakari Ailus Signed-off-by: Linus Walleij --- Dmitry: I'm looking for your ACK if you agree with this approach overall so I can apply this with the changes to gpiolib to the GPIO tree. --- drivers/input/keyboard/gpio_keys.c | 47 ++++++++++++++++++------------ 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index 492a971b95b5..eef2dcbc9185 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -499,25 +499,34 @@ static int gpio_keys_setup_key(struct platform_device *pdev, bdata->button = button; spin_lock_init(&bdata->lock); - if (child) { - bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, - child, - GPIOD_IN, - desc); - if (IS_ERR(bdata->gpiod)) { - error = PTR_ERR(bdata->gpiod); - if (error == -ENOENT) { - /* - * GPIO is optional, we may be dealing with - * purely interrupt-driven setup. - */ - bdata->gpiod = NULL; - } else { - if (error != -EPROBE_DEFER) - dev_err(dev, "failed to get gpio: %d\n", - error); - return error; - } + /* + * We try this first as it will find GPIOs even from board + * files if properly done. + */ + bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL, + child, + GPIOD_IN, + desc); + /* + * If we have a valid fwnode and this lookup fails, we need + * to give up. Otherwise we try to use the GPIO from the + * platform data. + */ + if (!IS_ERR(bdata->gpiod)) { + /* All is good */ + } else if (child) { + error = PTR_ERR(bdata->gpiod); + if (error == -ENOENT) { + /* + * GPIO is optional, we may be dealing with + * purely interrupt-driven setup. + */ + bdata->gpiod = NULL; + } else { + if (error != -EPROBE_DEFER) + dev_err(dev, "failed to get gpio: %d\n", + error); + return error; } } else if (gpio_is_valid(button->gpio)) { /*