aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan O'Donovan <dan@emutex.com>2017-02-05 11:30:12 -0500
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>2017-02-07 07:31:50 -0500
commit51ede5d9668f14d57ea6ba6eaa1b11d5b8ed2780 (patch)
tree452ab27ba30ad0217ad3ae0af3d0e1eee1ea170c
parentd5adbfcd5f7bcc6fa58a41c5c5ada0e5c826ce2c (diff)
ACPI / bus: Introduce acpi_of_modalias() equiv of of_modalias_node()
When using devicetree stuff like i2c_client.name or spi_device.modalias is initialized to the first DT compatible id with the vendor prefix stripped. Since some drivers rely on this try to replicate it when using ACPI with DT ids. Signed-off-by: Dan O'Donovan <dan@emutex.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
-rw-r--r--drivers/acpi/bus.c42
-rw-r--r--include/acpi/acpi_bus.h2
2 files changed, 44 insertions, 0 deletions
diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c
index 95855cb9d6fb..80cb5eb75b63 100644
--- a/drivers/acpi/bus.c
+++ b/drivers/acpi/bus.c
@@ -677,6 +677,48 @@ static bool acpi_of_match_device(struct acpi_device *adev,
677 return false; 677 return false;
678} 678}
679 679
680static bool acpi_of_modalias(struct acpi_device *adev,
681 char *modalias, size_t len)
682{
683 const union acpi_object *of_compatible;
684 const union acpi_object *obj;
685 const char *str, *chr;
686
687 of_compatible = adev->data.of_compatible;
688 if (!of_compatible)
689 return false;
690
691 if (of_compatible->type == ACPI_TYPE_PACKAGE)
692 obj = of_compatible->package.elements;
693 else /* Must be ACPI_TYPE_STRING. */
694 obj = of_compatible;
695
696 str = obj->string.pointer;
697 chr = strchr(str, ',');
698 strlcpy(modalias, chr ? chr + 1 : str, len);
699
700 return true;
701}
702
703/**
704 * acpi_set_modalias - Set modalias using "compatible" property or supplied ID
705 * @adev: ACPI device object to match
706 * @default_id: ID string to use as default if no compatible string found
707 * @modalias: Pointer to buffer that modalias value will be copied into
708 * @len: Length of modalias buffer
709 *
710 * This is a counterpart of of_modalias_node() for struct acpi_device objects.
711 * If there is a compatible string for @adev, it will be copied to @modalias
712 * with the vendor prefix stripped; otherwise, @default_id will be used.
713 */
714void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
715 char *modalias, size_t len)
716{
717 if (!acpi_of_modalias(adev, modalias, len))
718 strlcpy(modalias, default_id, len);
719}
720EXPORT_SYMBOL_GPL(acpi_set_modalias);
721
680static bool __acpi_match_device_cls(const struct acpi_device_id *id, 722static bool __acpi_match_device_cls(const struct acpi_device_id *id,
681 struct acpi_hardware_id *hwid) 723 struct acpi_hardware_id *hwid)
682{ 724{
diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
index 4242c31ffaee..ef0ae8aaa567 100644
--- a/include/acpi/acpi_bus.h
+++ b/include/acpi/acpi_bus.h
@@ -522,6 +522,8 @@ void acpi_bus_trim(struct acpi_device *start);
522acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd); 522acpi_status acpi_bus_get_ejd(acpi_handle handle, acpi_handle * ejd);
523int acpi_match_device_ids(struct acpi_device *device, 523int acpi_match_device_ids(struct acpi_device *device,
524 const struct acpi_device_id *ids); 524 const struct acpi_device_id *ids);
525void acpi_set_modalias(struct acpi_device *adev, const char *default_id,
526 char *modalias, size_t len);
525int acpi_create_dir(struct acpi_device *); 527int acpi_create_dir(struct acpi_device *);
526void acpi_remove_dir(struct acpi_device *); 528void acpi_remove_dir(struct acpi_device *);
527 529