ASoC: Improve machine driver selection based on quirk data
[sfrench/cifs-2.6.git] / sound / soc / intel / common / sst-match-acpi.c
index 1070f3ad23e50e1e495824ca13f8d7176ca0b05e..56d26f36a3cba16f25217b465cfe4704c674e3c9 100644 (file)
@@ -63,16 +63,33 @@ static acpi_status sst_acpi_mach_match(acpi_handle handle, u32 level,
        return AE_OK;
 }
 
+bool sst_acpi_check_hid(const u8 hid[ACPI_ID_LEN])
+{
+       acpi_status status;
+       bool found = false;
+
+       status = acpi_get_devices(hid, sst_acpi_mach_match, &found, NULL);
+
+       if (ACPI_FAILURE(status))
+               return false;
+
+       return found;
+}
+EXPORT_SYMBOL_GPL(sst_acpi_check_hid);
+
 struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
 {
        struct sst_acpi_mach *mach;
-       bool found = false;
 
-       for (mach = machines; mach->id[0]; mach++)
-               if (ACPI_SUCCESS(acpi_get_devices(mach->id,
-                                                 sst_acpi_mach_match,
-                                                 &found, NULL)) && found)
-                       return mach;
+       for (mach = machines; mach->id[0]; mach++) {
+               if (sst_acpi_check_hid(mach->id) == true) {
+                       if (mach->machine_quirk == NULL)
+                               return mach;
+
+                       if (mach->machine_quirk(mach) != NULL)
+                               return mach;
+               }
+       }
        return NULL;
 }
 EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
@@ -134,5 +151,23 @@ bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
 }
 EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid);
 
+struct sst_acpi_mach *sst_acpi_codec_list(void *arg)
+{
+       struct sst_acpi_mach *mach = arg;
+       struct sst_codecs *codec_list = (struct sst_codecs *) mach->quirk_data;
+       int i;
+
+       if (mach->quirk_data == NULL)
+               return mach;
+
+       for (i = 0; i < codec_list->num_codecs; i++) {
+               if (sst_acpi_check_hid(codec_list->codecs[i]) != true)
+                       return NULL;
+       }
+
+       return mach;
+}
+EXPORT_SYMBOL_GPL(sst_acpi_codec_list);
+
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("Intel Common ACPI Match module");