]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
ASoC: Intel: common: add ACPI package extraction utility
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Sun, 13 Nov 2016 00:07:44 +0000 (18:07 -0600)
committerMark Brown <broonie@kernel.org>
Sun, 13 Nov 2016 09:19:51 +0000 (09:19 +0000)
Add a new common routine to extract a package exposed by a
device indexed with the HID value. The functionality is
implemented without assumptions on the package type or
structure to allow for reuse. The caller is responsible for
defining the name and allocating structures to store the
results, ACPICA will complain in case of type mismatches
or buffer size issues.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/intel/common/sst-acpi.h
sound/soc/intel/common/sst-match-acpi.c

index 012742299dd532407b4d4859b89a74d09b262d0b..214e000667ae0a2725f951e0956a39dbc37d8f10 100644 (file)
 #include <linux/stddef.h>
 #include <linux/acpi.h>
 
-/* translation fron HID to I2C name, needed for DAI codec_name */
+struct sst_acpi_package_context {
+       char *name;           /* package name */
+       int length;           /* number of elements */
+       struct acpi_buffer *format;
+       struct acpi_buffer *state;
+       bool data_valid;
+};
+
 #if IS_ENABLED(CONFIG_ACPI)
+/* translation fron HID to I2C name, needed for DAI codec_name */
 const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN]);
+bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
+                                   struct sst_acpi_package_context *ctx);
 #else
 static inline const char *sst_acpi_find_name_from_hid(const u8 hid[ACPI_ID_LEN])
 {
        return NULL;
 }
+static inline bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
+                                          struct sst_acpi_package_context *ctx)
+{
+       return false;
+}
 #endif
 
 /* acpi match */
index 789843307a4950ad503d3cabda82300489d8e8d0..1070f3ad23e50e1e495824ca13f8d7176ca0b05e 100644 (file)
@@ -77,5 +77,62 @@ struct sst_acpi_mach *sst_acpi_find_machine(struct sst_acpi_mach *machines)
 }
 EXPORT_SYMBOL_GPL(sst_acpi_find_machine);
 
+static acpi_status sst_acpi_find_package(acpi_handle handle, u32 level,
+                                       void *context, void **ret)
+{
+       struct acpi_device *adev;
+       acpi_status status = AE_OK;
+       struct sst_acpi_package_context *pkg_ctx = context;
+
+       pkg_ctx->data_valid = false;
+
+       if (acpi_bus_get_device(handle, &adev))
+               return AE_OK;
+
+       if (adev->status.present && adev->status.functional) {
+               struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER, NULL};
+               union acpi_object  *myobj = NULL;
+
+               status = acpi_evaluate_object_typed(handle, pkg_ctx->name,
+                                               NULL, &buffer,
+                                               ACPI_TYPE_PACKAGE);
+               if (ACPI_FAILURE(status))
+                       return AE_OK;
+
+               myobj = buffer.pointer;
+               if (!myobj || myobj->package.count != pkg_ctx->length) {
+                       kfree(buffer.pointer);
+                       return AE_OK;
+               }
+
+               status = acpi_extract_package(myobj,
+                                       pkg_ctx->format, pkg_ctx->state);
+               if (ACPI_FAILURE(status)) {
+                       kfree(buffer.pointer);
+                       return AE_OK;
+               }
+
+               kfree(buffer.pointer);
+               pkg_ctx->data_valid = true;
+               return AE_CTRL_TERMINATE;
+       }
+
+       return AE_OK;
+}
+
+bool sst_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
+                               struct sst_acpi_package_context *ctx)
+{
+       acpi_status status;
+
+       status = acpi_get_devices(hid, sst_acpi_find_package, ctx, NULL);
+
+       if (ACPI_FAILURE(status) || !ctx->data_valid)
+               return false;
+
+       return true;
+}
+EXPORT_SYMBOL_GPL(sst_acpi_find_package_from_hid);
+
 MODULE_LICENSE("GPL v2");
 MODULE_DESCRIPTION("Intel Common ACPI Match module");