aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utils.c
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 /drivers/acpi/utils.c
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>
Diffstat (limited to 'drivers/acpi/utils.c')
-rw-r--r--drivers/acpi/utils.c41
1 files changed, 34 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.