mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH v4] iio: accel: adxl345: Add ACPI HID table
@ 2022-02-17  5:52 Kai-Heng Feng
       [not found] ` <CAHp75VfFGw3b_ZtQir0AfTfXfQ7fi_LKLsY-7ww=4+MMBR8BAQ@mail.gmail.com>
  0 siblings, 1 reply; 6+ messages in thread
From: Kai-Heng Feng @ 2022-02-17  5:52 UTC (permalink / raw)
  To: lars, Michael.Hennerich, jic23
  Cc: andy.shevchenko, Kai-Heng Feng, linux-iio, linux-kernel

x86 boards may use ACPI HID "ADS0345" for adxl345 device.

Analog replied:
"ADS034X is not a valid PNP ID. ADS0345 would be.
I'm not aware that this ID is already taken.
Feel free to submit a mainline Linux input mailing list patch."

So add an ACPI match table for that accordingly.

Since ACPI device may not match to any I2C ID, use the name and type
directly from ACPI ID table in absence of I2C ID.

Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Kai-Heng Feng <kai.heng.feng@canonical.com>
---
v4:
 - Drop "ADS0345:00" and use driver_date from ACPI table directly.

v3:
 - Convert the driver from input to iio.

v2:
 - Drop ACPI_PTR()
 - Drop redundant empty line and comma
 - Add info from vendor

 drivers/iio/accel/adxl345_i2c.c | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/accel/adxl345_i2c.c b/drivers/iio/accel/adxl345_i2c.c
index a431cba216e69..cdcc3ef1f1d33 100644
--- a/drivers/iio/accel/adxl345_i2c.c
+++ b/drivers/iio/accel/adxl345_i2c.c
@@ -22,20 +22,32 @@ static const struct regmap_config adxl345_i2c_regmap_config = {
 static int adxl345_i2c_probe(struct i2c_client *client,
 			     const struct i2c_device_id *id)
 {
+	struct device *dev = &client->dev;
+	const struct acpi_device_id *acpi_id;
+	enum adxl345_device_type type;
+	const char *name;
 	struct regmap *regmap;
 
-	if (!id)
-		return -ENODEV;
+	if (id) {
+		type = id->driver_data;
+		name = id->name;
+	} else {
+		acpi_id = acpi_match_device(dev->driver->acpi_match_table, dev);
+		if (acpi_id) {
+			type = acpi_id->driver_data;
+			name = acpi_id->id;
+		} else
+			return -ENODEV;
+	}
 
 	regmap = devm_regmap_init_i2c(client, &adxl345_i2c_regmap_config);
 	if (IS_ERR(regmap)) {
-		dev_err(&client->dev, "Error initializing i2c regmap: %ld\n",
+		dev_err(dev, "Error initializing i2c regmap: %ld\n",
 			PTR_ERR(regmap));
 		return PTR_ERR(regmap);
 	}
 
-	return adxl345_core_probe(&client->dev, regmap, id->driver_data,
-				  id->name);
+	return adxl345_core_probe(&client->dev, regmap, type, name);
 }
 
 static const struct i2c_device_id adxl345_i2c_id[] = {
@@ -54,10 +66,17 @@ static const struct of_device_id adxl345_of_match[] = {
 
 MODULE_DEVICE_TABLE(of, adxl345_of_match);
 
+static const struct acpi_device_id adxl345_acpi_match[] = {
+	{ "ADS0345", ADXL345 },
+	{ }
+};
+MODULE_DEVICE_TABLE(acpi, adxl345_acpi_match);
+
 static struct i2c_driver adxl345_i2c_driver = {
 	.driver = {
 		.name	= "adxl345_i2c",
 		.of_match_table = adxl345_of_match,
+		.acpi_match_table = adxl345_acpi_match,
 	},
 	.probe		= adxl345_i2c_probe,
 	.id_table	= adxl345_i2c_id,
-- 
2.34.1


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-02-19 17:37 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-17  5:52 [PATCH v4] iio: accel: adxl345: Add ACPI HID table Kai-Heng Feng
     [not found] ` <CAHp75VfFGw3b_ZtQir0AfTfXfQ7fi_LKLsY-7ww=4+MMBR8BAQ@mail.gmail.com>
2022-02-18  3:46   ` Kai-Heng Feng
2022-02-18  8:39     ` Andy Shevchenko
2022-02-18 12:10       ` Jonathan Cameron
2022-02-18 12:27         ` Andy Shevchenko
2022-02-19 17:44           ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®