Blame view

sound/soc/soc-acpi.c 2.53 KB
7730bb13c   Kuninori Morimoto   ASoC: soc-acpi: c...
1
2
3
4
5
  // SPDX-License-Identifier: GPL-2.0
  //
  // soc-apci.c - support for ACPI enumeration.
  //
  // Copyright (c) 2013-15, Intel Corporation.
95f098014   Vinod Koul   ASoC: Intel: Move...
6

261e90829   Paul Gortmaker   ASoC: soc-acpi: f...
7
8
  #include <linux/export.h>
  #include <linux/module.h>
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
9
  #include <sound/soc-acpi.h>
95f098014   Vinod Koul   ASoC: Intel: Move...
10

7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
11
12
  struct snd_soc_acpi_mach *
  snd_soc_acpi_find_machine(struct snd_soc_acpi_mach *machines)
95f098014   Vinod Koul   ASoC: Intel: Move...
13
  {
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
14
  	struct snd_soc_acpi_mach *mach;
a3e620f84   Keyon Jie   ASoC: acpi: fix: ...
15
  	struct snd_soc_acpi_mach *mach_alt;
95f098014   Vinod Koul   ASoC: Intel: Move...
16

7827d6694   Naveen M   ASoC: Move quirk ...
17
  	for (mach = machines; mach->id[0]; mach++) {
0d5ea120a   Jeremy Cline   ASoC: Replace snd...
18
  		if (acpi_dev_present(mach->id, NULL, -1)) {
a3e620f84   Keyon Jie   ASoC: acpi: fix: ...
19
20
21
22
23
24
  			if (mach->machine_quirk) {
  				mach_alt = mach->machine_quirk(mach);
  				if (!mach_alt)
  					continue; /* not full match, ignore */
  				mach = mach_alt;
  			}
5c256045b   Pierre-Louis Bossart   ASoC: acpi: fix m...
25
  			return mach;
7827d6694   Naveen M   ASoC: Move quirk ...
26
27
  		}
  	}
95f098014   Vinod Koul   ASoC: Intel: Move...
28
29
  	return NULL;
  }
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
30
  EXPORT_SYMBOL_GPL(snd_soc_acpi_find_machine);
8ceffd229   Vinod Koul   ASoC: Intel: Add ...
31

7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
32
33
  static acpi_status snd_soc_acpi_find_package(acpi_handle handle, u32 level,
  					     void *context, void **ret)
342189476   Pierre-Louis Bossart   ASoC: Intel: comm...
34
35
36
  {
  	struct acpi_device *adev;
  	acpi_status status = AE_OK;
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
37
  	struct snd_soc_acpi_package_context *pkg_ctx = context;
342189476   Pierre-Louis Bossart   ASoC: Intel: comm...
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
  
  	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;
  }
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
74
75
  bool snd_soc_acpi_find_package_from_hid(const u8 hid[ACPI_ID_LEN],
  				struct snd_soc_acpi_package_context *ctx)
342189476   Pierre-Louis Bossart   ASoC: Intel: comm...
76
77
  {
  	acpi_status status;
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
78
  	status = acpi_get_devices(hid, snd_soc_acpi_find_package, ctx, NULL);
342189476   Pierre-Louis Bossart   ASoC: Intel: comm...
79
80
81
82
83
84
  
  	if (ACPI_FAILURE(status) || !ctx->data_valid)
  		return false;
  
  	return true;
  }
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
85
  EXPORT_SYMBOL_GPL(snd_soc_acpi_find_package_from_hid);
342189476   Pierre-Louis Bossart   ASoC: Intel: comm...
86

7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
87
  struct snd_soc_acpi_mach *snd_soc_acpi_codec_list(void *arg)
54746dabf   Naveen M   ASoC: Improve mac...
88
  {
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
89
90
91
  	struct snd_soc_acpi_mach *mach = arg;
  	struct snd_soc_acpi_codecs *codec_list =
  		(struct snd_soc_acpi_codecs *) mach->quirk_data;
54746dabf   Naveen M   ASoC: Improve mac...
92
93
94
95
96
97
  	int i;
  
  	if (mach->quirk_data == NULL)
  		return mach;
  
  	for (i = 0; i < codec_list->num_codecs; i++) {
0d5ea120a   Jeremy Cline   ASoC: Replace snd...
98
  		if (!acpi_dev_present(codec_list->codecs[i], NULL, -1))
54746dabf   Naveen M   ASoC: Improve mac...
99
100
101
102
103
  			return NULL;
  	}
  
  	return mach;
  }
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
104
  EXPORT_SYMBOL_GPL(snd_soc_acpi_codec_list);
54746dabf   Naveen M   ASoC: Improve mac...
105

8ceffd229   Vinod Koul   ASoC: Intel: Add ...
106
  MODULE_LICENSE("GPL v2");
7feb2f786   Pierre-Louis Bossart   ASoC: move ACPI c...
107
  MODULE_DESCRIPTION("ALSA SoC ACPI module");