linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexandru Ardelean <alexandru.ardelean@analog.com>
To: <linux-input@vger.kernel.org>, <linux-kernel@vger.kernel.org>,
	<devicetree@vger.kernel.org>
Cc: <lars@metafoo.de>, <dmitry.torokhov@gmail.com>,
	<robh+dt@kernel.org>,
	Alexandru Ardelean <alexandru.ardelean@analog.com>
Subject: [PATCH v3 3/4] Input: adp5589-keys - add basic devicetree support
Date: Fri, 27 Nov 2020 13:14:19 +0200	[thread overview]
Message-ID: <20201127111420.96500-3-alexandru.ardelean@analog.com> (raw)
In-Reply-To: <20201127111420.96500-1-alexandru.ardelean@analog.com>

From: Lars-Peter Clausen <lars@metafoo.de>

Add very basic devicetree suppport to the adp5589 allowing the device to be
registered from devicetree and ACPI via PRP0001.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com>
---
 drivers/input/keyboard/adp5589-keys.c | 30 ++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/input/keyboard/adp5589-keys.c b/drivers/input/keyboard/adp5589-keys.c
index 6cb93ee3b97c..8ff18ff18b75 100644
--- a/drivers/input/keyboard/adp5589-keys.c
+++ b/drivers/input/keyboard/adp5589-keys.c
@@ -986,9 +986,25 @@ static void adp5589_clear_config(void *data)
 	adp5589_write(client, kpad->var->reg(ADP5589_GENERAL_CFG), 0);
 }
 
+static const struct adp5589_chip_info *adp5589_get_chip_info(struct device *dev,
+							     const struct i2c_device_id *id)
+{
+	const struct adp5589_chip_info *info;
+
+	info = device_get_match_data(dev);
+	if (info)
+		return info;
+
+	if (id)
+		return &adp5589_chip_info_tbl[id->driver_data];
+
+	return NULL;
+}
+
 static int adp5589_probe(struct i2c_client *client,
 			 const struct i2c_device_id *id)
 {
+	const struct adp5589_chip_info *info;
 	struct adp5589_kpad *kpad;
 	const struct adp5589_kpad_platform_data *pdata =
 		adp5589_kpad_pdata_get(&client->dev);
@@ -1001,13 +1017,17 @@ static int adp5589_probe(struct i2c_client *client,
 		return -EIO;
 	}
 
+	info = adp5589_get_chip_info(&client->dev, id);
+	if (!info)
+		return -ENODEV;
+
 	kpad = devm_kzalloc(&client->dev, sizeof(*kpad), GFP_KERNEL);
 	if (!kpad)
 		return -ENOMEM;
 
 	kpad->client = client;
 
-	kpad->info = &adp5589_chip_info_tbl[id->driver_data];
+	kpad->info = info;
 	kpad->var = kpad->info->constants;
 
 	error = devm_add_action_or_reset(&client->dev, adp5589_clear_config,
@@ -1078,6 +1098,13 @@ static int __maybe_unused adp5589_resume(struct device *dev)
 
 static SIMPLE_DEV_PM_OPS(adp5589_dev_pm_ops, adp5589_suspend, adp5589_resume);
 
+static const struct of_device_id adp5589_of_match[] = {
+	{ .compatible = "adi,adp5585", .data = &adp5589_chip_info_tbl[ADP5585_01] },
+	{ .compatible = "adi,adp5585-02", .data = &adp5589_chip_info_tbl[ADP5585_02] },
+	{ .compatible = "adi,adp5589", .data = &adp5589_chip_info_tbl[ADP5589] },
+	{}
+};
+
 static const struct i2c_device_id adp5589_id[] = {
 	{"adp5589-keys", ADP5589},
 	{"adp5585-keys", ADP5585_01},
@@ -1091,6 +1118,7 @@ static struct i2c_driver adp5589_driver = {
 	.driver = {
 		.name = KBUILD_MODNAME,
 		.pm = &adp5589_dev_pm_ops,
+		.of_match_table = adp5589_of_match,
 	},
 	.probe = adp5589_probe,
 	.id_table = adp5589_id,
-- 
2.27.0


  parent reply	other threads:[~2020-11-27 11:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-27 11:14 [PATCH v3 1/4] Input: adp5589-keys - add default platform data Alexandru Ardelean
2020-11-27 11:14 ` [PATCH v3 2/4] Input: adp5589-keys - wrap device probing into chip info struct Alexandru Ardelean
2020-11-27 11:14 ` Alexandru Ardelean [this message]
2020-11-27 11:14 ` [PATCH v3 4/4] dt-bindings: add ADP5585/ADP5589 entries to trivial-devices Alexandru Ardelean
2020-12-08 18:13   ` Rob Herring
2020-12-09  7:01 ` [PATCH v3 1/4] Input: adp5589-keys - add default platform data Ardelean, Alexandru
2020-12-10  7:20 ` Dmitry Torokhov

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=20201127111420.96500-3-alexandru.ardelean@analog.com \
    --to=alexandru.ardelean@analog.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=lars@metafoo.de \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@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).