summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2018-01-05 11:09:33 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2018-01-09 18:41:43 -0500
commit67dcf8a3e06582cb6b02952335b5612beb97889f (patch)
tree3f4eaa7009cdf208646d0d7362ec8773c1ba6bf6
parentb2cd1df66037e7c4697c7e40496bf7e4a5e16a2d (diff)
ACPI: utils: Introduce acpi_dev_get_first_match_name()
Sometimes the user wants to have device name of the match rather than just checking if device present or not. To make life easier for such users introduce acpi_dev_get_first_match_name() helper based on code for acpi_dev_present(). For example, GPIO driver for Intel Merrifield needs to know the device name of pin control to be able to apply GPIO mapping table to the proper device. To be more consistent with the purpose rename struct acpi_dev_present_info -> struct acpi_dev_match_info acpi_dev_present_cb() -> acpi_dev_match_cb() in the utils.c file. Tested-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/utils.c41
-rw-r--r--include/acpi/acpi_bus.h3
-rw-r--r--include/linux/acpi.h6
3 files changed, 43 insertions, 7 deletions
diff --git a/drivers/acpi/utils.c b/drivers/acpi/utils.c
index 9d49a1acebe3..78db97687f26 100644
--- a/drivers/acpi/utils.c
+++ b/drivers/acpi/utils.c
@@ -737,16 +737,17 @@ bool acpi_dev_found(const char *hid)
737} 737}
738EXPORT_SYMBOL(acpi_dev_found); 738EXPORT_SYMBOL(acpi_dev_found);
739 739
740struct acpi_dev_present_info { 740struct acpi_dev_match_info {
741 const char *dev_name;
741 struct acpi_device_id hid[2]; 742 struct acpi_device_id hid[2];
742 const char *uid; 743 const char *uid;
743 s64 hrv; 744 s64 hrv;
744}; 745};
745 746
746static int acpi_dev_present_cb(struct device *dev, void *data) 747static int acpi_dev_match_cb(struct device *dev, void *data)
747{ 748{
748 struct acpi_device *adev = to_acpi_device(dev); 749 struct acpi_device *adev = to_acpi_device(dev);
749 struct acpi_dev_present_info *match = data; 750 struct acpi_dev_match_info *match = data;
750 unsigned long long hrv; 751 unsigned long long hrv;
751 acpi_status status; 752 acpi_status status;
752 753
@@ -757,6 +758,8 @@ static int acpi_dev_present_cb(struct device *dev, void *data)
757 strcmp(adev->pnp.unique_id, match->uid))) 758 strcmp(adev->pnp.unique_id, match->uid)))
758 return 0; 759 return 0;
759 760
761 match->dev_name = acpi_dev_name(adev);
762
760 if (match->hrv == -1) 763 if (match->hrv == -1)
761 return 1; 764 return 1;
762 765
@@ -789,20 +792,44 @@ static int acpi_dev_present_cb(struct device *dev, void *data)
789 */ 792 */
790bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) 793bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
791{ 794{
792 struct acpi_dev_present_info match = {}; 795 struct acpi_dev_match_info match = {};
793 struct device *dev; 796 struct device *dev;
794 797
795 strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id)); 798 strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
796 match.uid = uid; 799 match.uid = uid;
797 match.hrv = hrv; 800 match.hrv = hrv;
798 801
799 dev = bus_find_device(&acpi_bus_type, NULL, &match, 802 dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
800 acpi_dev_present_cb);
801
802 return !!dev; 803 return !!dev;
803} 804}
804EXPORT_SYMBOL(acpi_dev_present); 805EXPORT_SYMBOL(acpi_dev_present);
805 806
807/**
808 * acpi_dev_get_first_match_name - Return name of first match of ACPI device
809 * @hid: Hardware ID of the device.
810 * @uid: Unique ID of the device, pass NULL to not check _UID
811 * @hrv: Hardware Revision of the device, pass -1 to not check _HRV
812 *
813 * Return device name if a matching device was present
814 * at the moment of invocation, or NULL otherwise.
815 *
816 * See additional information in acpi_dev_present() as well.
817 */
818const char *
819acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
820{
821 struct acpi_dev_match_info match = {};
822 struct device *dev;
823
824 strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
825 match.uid = uid;
826 match.hrv = hrv;
827
828 dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
829 return dev ? match.dev_name : NULL;
830}
831EXPORT_SYMBOL(acpi_dev_get_first_match_name);
832
806/* 833/*
807 * acpi_backlight= handling, this is done here rather then in video_detect.c 834 * acpi_backlight= handling, this is done here rather then in video_detect.c
808 * because __setup cannot be used in modules. 835 * because __setup cannot be used in modules.
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 79287629c888..c9608b0b80c6 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -91,6 +91,9 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
91bool acpi_dev_found(const char *hid); 91bool acpi_dev_found(const char *hid);
92bool acpi_dev_present(const char *hid, const char *uid, s64 hrv); 92bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
93 93
94const char *
95acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);
96
94#ifdef CONFIG_ACPI 97#ifdef CONFIG_ACPI
95 98
96#include <linux/proc_fs.h> 99#include <linux/proc_fs.h>
diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index dc1ebfeeb5ec..d918f1ea84e6 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -640,6 +640,12 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
640 return false; 640 return false;
641} 641}
642 642
643static inline const char *
644acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
645{
646 return NULL;
647}
648
643static inline bool is_acpi_node(struct fwnode_handle *fwnode) 649static inline bool is_acpi_node(struct fwnode_handle *fwnode)
644{ 650{
645 return false; 651 return false;