From: "Enrico Weigelt, metux IT consult" <info@metux.net>
To: linux-kernel@vger.kernel.org
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: [PATCH v4] input: keyboard: gpio_keys_polled: use gpio lookup table
Date: Thu, 12 Dec 2019 01:13:11 +0100 [thread overview]
Message-ID: <20191212001311.4268-1-info@metux.net> (raw)
From: Enrico Weigelt <info@metux.net>
Support the recently introduced gpio lookup tables for
attaching to gpio lines. So, harcoded gpio numbers aren't
needed anymore.
changes v4:
* completely rewritten in a much simpler way, now just adding
a third case (in the button probe loop), where neither oftree
nor raw gpio number exists.
changes v3:
* fix printf string in gpio_keys_polled_get_gpiod()
* fix unused variable 'error' in gpio_keys_polled_get_gpiod()
* fix uninitialized variable in gpio_keys_polled_get_gpiod_fwnode()
Cc: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org
Signed-off-by: Enrico Weigelt <info@metux.net>
---
drivers/input/keyboard/gpio_keys_polled.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/input/keyboard/gpio_keys_polled.c b/drivers/input/keyboard/gpio_keys_polled.c
index 6eb0a2f3f9de..9ef8c7dade27 100644
--- a/drivers/input/keyboard/gpio_keys_polled.c
+++ b/drivers/input/keyboard/gpio_keys_polled.c
@@ -307,7 +307,7 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
fwnode_handle_put(child);
return error;
}
- } else if (gpio_is_valid(button->gpio)) {
+ } else if ((button->gpio > 0) && gpio_is_valid(button->gpio)) {
/*
* Legacy GPIO number so request the GPIO here and
* convert it to descriptor.
@@ -333,6 +333,18 @@ static int gpio_keys_polled_probe(struct platform_device *pdev)
button->gpio);
return -EINVAL;
}
+ } else {
+ /* try via gpio lookup table */
+ bdata->gpiod = devm_gpiod_get_index(dev, NULL, i, GPIOF_IN);
+ if (IS_ERR(bdata->gpiod)) {
+ dev_err(dev,
+ "unable to get gpio for button %d: %ld\n",
+ i, PTR_ERR(bdata->gpiod));
+ return PTR_ERR(bdata->gpiod);
+ }
+
+ gpiod_set_consumer_name(bdata->gpiod,
+ button->desc ? : DRV_NAME);
}
bdata->last_state = -1;
--
2.11.0
reply other threads:[~2019-12-12 0:13 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20191212001311.4268-1-info@metux.net \
--to=info@metux.net \
--cc=dmitry.torokhov@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).