forked from mirrors/linux
		
	media: ACPI / bus: Add acpi_dev_get_next_match_dev() and helper macro
To ensure we handle situations in which multiple sensors of the same model (and therefore _HID) are present in a system, we need to be able to iterate over devices matching a known _HID but unknown _UID and _HRV - add acpi_dev_get_next_match_dev() to accommodate that possibility and change acpi_dev_get_first_match_dev() to simply call the new function with a NULL starting point. Add an iterator macro for convenience. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Daniel Scally <djrscally@gmail.com> Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com> Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
This commit is contained in:
		
							parent
							
								
									06c8523312
								
							
						
					
					
						commit
						bf263f64e8
					
				
					 2 changed files with 38 additions and 9 deletions
				
			
		|  | @ -842,6 +842,36 @@ bool acpi_dev_present(const char *hid, const char *uid, s64 hrv) | |||
| } | ||||
| EXPORT_SYMBOL(acpi_dev_present); | ||||
| 
 | ||||
| /**
 | ||||
|  * acpi_dev_get_next_match_dev - Return the next match of ACPI device | ||||
|  * @adev: Pointer to the previous acpi_device matching this @hid, @uid and @hrv | ||||
|  * @hid: Hardware ID of the device. | ||||
|  * @uid: Unique ID of the device, pass NULL to not check _UID | ||||
|  * @hrv: Hardware Revision of the device, pass -1 to not check _HRV | ||||
|  * | ||||
|  * Return the next match of ACPI device if another matching device was present | ||||
|  * at the moment of invocation, or NULL otherwise. | ||||
|  * | ||||
|  * The caller is responsible to call put_device() on the returned device. | ||||
|  * | ||||
|  * See additional information in acpi_dev_present() as well. | ||||
|  */ | ||||
| struct acpi_device * | ||||
| acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv) | ||||
| { | ||||
| 	struct device *start = adev ? &adev->dev : NULL; | ||||
| 	struct acpi_dev_match_info match = {}; | ||||
| 	struct device *dev; | ||||
| 
 | ||||
| 	strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id)); | ||||
| 	match.uid = uid; | ||||
| 	match.hrv = hrv; | ||||
| 
 | ||||
| 	dev = bus_find_device(&acpi_bus_type, start, &match, acpi_dev_match_cb); | ||||
| 	return dev ? to_acpi_device(dev) : NULL; | ||||
| } | ||||
| EXPORT_SYMBOL(acpi_dev_get_next_match_dev); | ||||
| 
 | ||||
| /**
 | ||||
|  * acpi_dev_get_first_match_dev - Return the first match of ACPI device | ||||
|  * @hid: Hardware ID of the device. | ||||
|  | @ -858,15 +888,7 @@ EXPORT_SYMBOL(acpi_dev_present); | |||
| struct acpi_device * | ||||
| acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv) | ||||
| { | ||||
| 	struct acpi_dev_match_info match = {}; | ||||
| 	struct device *dev; | ||||
| 
 | ||||
| 	strlcpy(match.hid[0].id, hid, sizeof(match.hid[0].id)); | ||||
| 	match.uid = uid; | ||||
| 	match.hrv = hrv; | ||||
| 
 | ||||
| 	dev = bus_find_device(&acpi_bus_type, NULL, &match, acpi_dev_match_cb); | ||||
| 	return dev ? to_acpi_device(dev) : NULL; | ||||
| 	return acpi_dev_get_next_match_dev(NULL, hid, uid, hrv); | ||||
| } | ||||
| EXPORT_SYMBOL(acpi_dev_get_first_match_dev); | ||||
| 
 | ||||
|  |  | |||
|  | @ -683,9 +683,16 @@ static inline bool acpi_device_can_poweroff(struct acpi_device *adev) | |||
| 
 | ||||
| bool acpi_dev_hid_uid_match(struct acpi_device *adev, const char *hid2, const char *uid2); | ||||
| 
 | ||||
| struct acpi_device * | ||||
| acpi_dev_get_next_match_dev(struct acpi_device *adev, const char *hid, const char *uid, s64 hrv); | ||||
| struct acpi_device * | ||||
| acpi_dev_get_first_match_dev(const char *hid, const char *uid, s64 hrv); | ||||
| 
 | ||||
| #define for_each_acpi_dev_match(adev, hid, uid, hrv)			\ | ||||
| 	for (adev = acpi_dev_get_first_match_dev(hid, uid, hrv);	\ | ||||
| 	     adev;							\ | ||||
| 	     adev = acpi_dev_get_next_match_dev(adev, hid, uid, hrv)) | ||||
| 
 | ||||
| static inline void acpi_dev_put(struct acpi_device *adev) | ||||
| { | ||||
| 	put_device(&adev->dev); | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue
	
	 Daniel Scally
						Daniel Scally