Skip to content

Commit 67dcf8a

Browse files
andy-shevrafaeljw
authored andcommitted
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>
1 parent b2cd1df commit 67dcf8a

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

drivers/acpi/utils.c

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -737,16 +737,17 @@ bool acpi_dev_found(const char *hid)
737737
}
738738
EXPORT_SYMBOL(acpi_dev_found);
739739

740-
struct acpi_dev_present_info {
740+
struct acpi_dev_match_info {
741+
const char *dev_name;
741742
struct acpi_device_id hid[2];
742743
const char *uid;
743744
s64 hrv;
744745
};
745746

746-
static int acpi_dev_present_cb(struct device *dev, void *data)
747+
static int acpi_dev_match_cb(struct device *dev, void *data)
747748
{
748749
struct acpi_device *adev = to_acpi_device(dev);
749-
struct acpi_dev_present_info *match = data;
750+
struct acpi_dev_match_info *match = data;
750751
unsigned long long hrv;
751752
acpi_status status;
752753

@@ -757,6 +758,8 @@ static int acpi_dev_present_cb(struct device *dev, void *data)
757758
strcmp(adev->pnp.unique_id, match->uid)))
758759
return 0;
759760

761+
match->dev_name = acpi_dev_name(adev);
762+
760763
if (match->hrv == -1)
761764
return 1;
762765

@@ -789,20 +792,44 @@ static int acpi_dev_present_cb(struct device *dev, void *data)
789792
*/
790793
bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
791794
{
792-
struct acpi_dev_present_info match = {};
795+
struct acpi_dev_match_info match = {};
793796
struct device *dev;
794797

795798
strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id));
796799
match.uid = uid;
797800
match.hrv = hrv;
798801

799-
dev = bus_find_device(&acpi_bus_type, NULL, &match,
800-
acpi_dev_present_cb);
801-
802+
dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb);
802803
return !!dev;
803804
}
804805
EXPORT_SYMBOL(acpi_dev_present);
805806

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+
*/
818+
const char *
819+
acpi_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+
}
831+
EXPORT_SYMBOL(acpi_dev_get_first_match_name);
832+
806833
/*
807834
* acpi_backlight= handling, this is done here rather then in video_detect.c
808835
* because __setup cannot be used in modules.

include/acpi/acpi_bus.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ acpi_evaluate_dsm_typed(acpi_handle handle, const guid_t *guid, u64 rev,
9191
bool acpi_dev_found(const char *hid);
9292
bool acpi_dev_present(const char *hid, const char *uid, s64 hrv);
9393

94+
const char *
95+
acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv);
96+
9497
#ifdef CONFIG_ACPI
9598

9699
#include <linux/proc_fs.h>

include/linux/acpi.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ static inline bool acpi_dev_present(const char *hid, const char *uid, s64 hrv)
640640
return false;
641641
}
642642

643+
static inline const char *
644+
acpi_dev_get_first_match_name(const char *hid, const char *uid, s64 hrv)
645+
{
646+
return NULL;
647+
}
648+
643649
static inline bool is_acpi_node(struct fwnode_handle *fwnode)
644650
{
645651
return false;

0 commit comments

Comments
 (0)