Linux IIO development
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
	Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	Marius Cristea <marius.cristea@microchip.com>,
	Trevor Gamblin <tgamblin@baylibre.com>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Jonathan Cameron <jic23@kernel.org>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Jean-Baptiste Maneyrol <jean-baptiste.maneyrol@tdk.com>
Subject: [PATCH v1 05/13] iio: acpi: Add iio_get_acpi_device_name_and_data() helper function
Date: Wed, 23 Oct 2024 18:17:28 +0300	[thread overview]
Message-ID: <20241023152145.3564943-6-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20241023152145.3564943-1-andriy.shevchenko@linux.intel.com>

A few drivers duplicate the code to retrieve ACPI device instance name.
Some of them want an associated driver data as well.

In order of deduplication introduce the common helper functions.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/iio/industrialio-acpi.c | 35 ++++++++++++++++++++++++++++++++-
 include/linux/iio/iio.h         | 10 ++++++++++
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/industrialio-acpi.c b/drivers/iio/industrialio-acpi.c
index 1e46908f9534..0003f6c67580 100644
--- a/drivers/iio/industrialio-acpi.c
+++ b/drivers/iio/industrialio-acpi.c
@@ -2,7 +2,8 @@
 /* IIO ACPI helper functions */
 
 #include <linux/acpi.h>
-#include <linux/dev_printk.h>
+#include <linux/device.h>
+#include <linux/export.h>
 #include <linux/iio/iio.h>
 #include <linux/sprintf.h>
 
@@ -87,3 +88,35 @@ bool iio_read_acpi_mount_matrix(struct device *dev,
 	return ret;
 }
 EXPORT_SYMBOL_GPL(iio_read_acpi_mount_matrix);
+
+/**
+ * iio_get_acpi_device_name_and_data() - Return ACPI device instance name and driver data
+ * @dev:		Device structure
+ * @data:		Optional pointer to return driver data
+ *
+ * When device was enumerated by ACPI ID matching, the user might
+ * want to set description for the physical chip. In such cases
+ * the ACPI device instance name might be used. This call may be
+ * performed to retrieve this information.
+ *
+ * Returns: ACPI device instance name or %NULL.
+ */
+const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data)
+{
+	const struct acpi_device_id *id;
+	acpi_handle handle;
+
+	handle = ACPI_HANDLE(dev);
+	if (!handle)
+		return NULL;
+
+	id = acpi_match_device(dev->driver->acpi_match_table, dev);
+	if (!id)
+		return NULL;
+
+	if (data)
+		*data = (const void *)id->driver_data;
+
+	return dev_name(dev);
+}
+EXPORT_SYMBOL_GPL(iio_get_acpi_device_name_and_data);
diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h
index 3a9b57187a95..445d6666a291 100644
--- a/include/linux/iio/iio.h
+++ b/include/linux/iio/iio.h
@@ -831,6 +831,7 @@ int iio_device_resume_triggering(struct iio_dev *indio_dev);
 bool iio_read_acpi_mount_matrix(struct device *dev,
 				struct iio_mount_matrix *orientation,
 				char *acpi_method);
+const char *iio_get_acpi_device_name_and_data(struct device *dev, const void **data);
 #else
 static inline bool iio_read_acpi_mount_matrix(struct device *dev,
 					      struct iio_mount_matrix *orientation,
@@ -838,7 +839,16 @@ static inline bool iio_read_acpi_mount_matrix(struct device *dev,
 {
 	return false;
 }
+static inline const char *
+iio_get_acpi_device_name_and_data(struct device *dev, const void **data)
+{
+	return NULL;
+}
 #endif
+static inline const char *iio_get_acpi_device_name(struct device *dev)
+{
+	return iio_get_acpi_device_name_and_data(dev, NULL);
+}
 
 /**
  * iio_get_current_scan_type - Get the current scan type for a channel
-- 
2.43.0.rc1.1336.g36b5255a03ac


  parent reply	other threads:[~2024-10-23 15:21 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-23 15:17 [PATCH v1 00/13] iio: Clean up acpi_match_device() use cases Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 01/13] iio: magnetometer: bmc150: Drop dead code from the driver Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 02/13] iio: adc: pac1934: Replace strange way of checking type of enumeration Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 03/13] iio: imu: inv_mpu6050: " Andy Shevchenko
2024-10-24 12:24   ` Jean-Baptiste Maneyrol
2024-10-23 15:17 ` [PATCH v1 04/13] iio: acpi: Improve iio_read_acpi_mount_matrix() Andy Shevchenko
2024-10-23 15:17 ` Andy Shevchenko [this message]
2024-10-23 15:17 ` [PATCH v1 06/13] iio: accel: mma9551: Replace custom implementation of iio_get_acpi_device_name() Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 07/13] iio: accel: mma9553: " Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 08/13] iio: gyro: bmg160: " Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 09/13] iio: light: isl29018: Replace a variant of iio_get_acpi_device_name_and_data() Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 10/13] iio: light: isl29018: drop ACPI_PTR() and CONFIG_ACPI guards Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 11/13] iio: light: ltr501: Drop most likely fake ACPI IDs Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 12/13] iio: light: ltr501: Add LTER0303 to the supported devices Andy Shevchenko
2024-10-23 15:17 ` [PATCH v1 13/13] iio: light: ltr501: Replace a variant of iio_get_acpi_device_name_and_data() Andy Shevchenko
2024-10-23 15:36 ` [PATCH v1 00/13] iio: Clean up acpi_match_device() use cases Hans de Goede
2024-10-24  7:52 ` Jonathan Cameron
2024-10-24  8:06   ` Andy Shevchenko

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=20241023152145.3564943-6-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=hdegoede@redhat.com \
    --cc=jean-baptiste.maneyrol@tdk.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marius.cristea@microchip.com \
    --cc=tgamblin@baylibre.com \
    /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