This source file includes following definitions.
- hda_codec_load_module
- hda_codec_jack_wake_enable
- hda_codec_jack_check
- hda_codec_jack_wake_enable
- hda_codec_jack_check
- hda_codec_probe
- hda_codec_probe_bus
- hda_codec_i915_get
- hda_codec_i915_put
- hda_codec_i915_init
- hda_codec_i915_exit
1
2
3
4
5
6
7
8
9
10
11 #include <linux/module.h>
12 #include <sound/hdaudio_ext.h>
13 #include <sound/hda_register.h>
14 #include <sound/hda_codec.h>
15 #include <sound/hda_i915.h>
16 #include <sound/sof.h>
17 #include "../ops.h"
18 #include "hda.h"
19 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
20 #include "../../codecs/hdac_hda.h"
21 #endif
22
23 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
24 #define IDISP_VID_INTEL 0x80860000
25
26
27 static int hda_codec_load_module(struct hda_codec *codec)
28 {
29 #ifdef MODULE
30 char alias[MODULE_NAME_LEN];
31 const char *module = alias;
32
33 snd_hdac_codec_modalias(&codec->core, alias, sizeof(alias));
34 dev_dbg(&codec->core.dev, "loading codec module: %s\n", module);
35 request_module(module);
36 #endif
37 return device_attach(hda_codec_dev(codec));
38 }
39
40
41 void hda_codec_jack_wake_enable(struct snd_sof_dev *sdev)
42 {
43 struct hda_bus *hbus = sof_to_hbus(sdev);
44 struct hdac_bus *bus = sof_to_bus(sdev);
45 struct hda_codec *codec;
46 unsigned int mask = 0;
47
48 list_for_each_codec(codec, hbus)
49 if (codec->jacktbl.used)
50 mask |= BIT(codec->core.addr);
51
52 snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, mask);
53 }
54
55
56 void hda_codec_jack_check(struct snd_sof_dev *sdev)
57 {
58 struct hda_bus *hbus = sof_to_hbus(sdev);
59 struct hdac_bus *bus = sof_to_bus(sdev);
60 struct hda_codec *codec;
61
62
63 snd_hdac_chip_updatew(bus, WAKEEN, STATESTS_INT_MASK, 0);
64
65 list_for_each_codec(codec, hbus)
66
67
68
69
70 if (codec->jacktbl.used)
71 schedule_delayed_work(&codec->jackpoll_work,
72 codec->jackpoll_interval);
73 }
74 #else
75 void hda_codec_jack_wake_enable(struct snd_sof_dev *sdev) {}
76 void hda_codec_jack_check(struct snd_sof_dev *sdev) {}
77 #endif
78 EXPORT_SYMBOL(hda_codec_jack_wake_enable);
79 EXPORT_SYMBOL(hda_codec_jack_check);
80
81
82 static int hda_codec_probe(struct snd_sof_dev *sdev, int address)
83 {
84 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
85 struct hdac_hda_priv *hda_priv;
86 #endif
87 struct hda_bus *hbus = sof_to_hbus(sdev);
88 struct hdac_device *hdev;
89 u32 hda_cmd = (address << 28) | (AC_NODE_ROOT << 20) |
90 (AC_VERB_PARAMETERS << 8) | AC_PAR_VENDOR_ID;
91 u32 resp = -1;
92 int ret;
93
94 mutex_lock(&hbus->core.cmd_mutex);
95 snd_hdac_bus_send_cmd(&hbus->core, hda_cmd);
96 snd_hdac_bus_get_response(&hbus->core, address, &resp);
97 mutex_unlock(&hbus->core.cmd_mutex);
98 if (resp == -1)
99 return -EIO;
100 dev_dbg(sdev->dev, "HDA codec #%d probed OK: response: %x\n",
101 address, resp);
102
103 #if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA_AUDIO_CODEC)
104 hda_priv = devm_kzalloc(sdev->dev, sizeof(*hda_priv), GFP_KERNEL);
105 if (!hda_priv)
106 return -ENOMEM;
107
108 hda_priv->codec.bus = hbus;
109 hdev = &hda_priv->codec.core;
110
111 ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev);
112 if (ret < 0)
113 return ret;
114
115
116 if ((resp & 0xFFFF0000) != IDISP_VID_INTEL) {
117 hdev->type = HDA_DEV_LEGACY;
118 ret = hda_codec_load_module(&hda_priv->codec);
119
120
121
122
123 if (ret == 0)
124 ret = -ENOENT;
125 }
126
127 return ret;
128 #else
129 hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
130 if (!hdev)
131 return -ENOMEM;
132
133 ret = snd_hdac_ext_bus_device_init(&hbus->core, address, hdev);
134
135 return ret;
136 #endif
137 }
138
139
140 int hda_codec_probe_bus(struct snd_sof_dev *sdev)
141 {
142 struct hdac_bus *bus = sof_to_bus(sdev);
143 int i, ret;
144
145
146 for (i = 0; i < HDA_MAX_CODECS; i++) {
147
148 if (!(bus->codec_mask & (1 << i)))
149 continue;
150
151 ret = hda_codec_probe(sdev, i);
152 if (ret < 0) {
153 dev_err(bus->dev, "error: codec #%d probe error, ret: %d\n",
154 i, ret);
155 return ret;
156 }
157 }
158
159 return 0;
160 }
161 EXPORT_SYMBOL(hda_codec_probe_bus);
162
163 #if IS_ENABLED(CONFIG_SND_SOC_HDAC_HDMI)
164
165 void hda_codec_i915_get(struct snd_sof_dev *sdev)
166 {
167 struct hdac_bus *bus = sof_to_bus(sdev);
168
169 dev_dbg(bus->dev, "Turning i915 HDAC power on\n");
170 snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, true);
171 }
172 EXPORT_SYMBOL(hda_codec_i915_get);
173
174 void hda_codec_i915_put(struct snd_sof_dev *sdev)
175 {
176 struct hdac_bus *bus = sof_to_bus(sdev);
177
178 dev_dbg(bus->dev, "Turning i915 HDAC power off\n");
179 snd_hdac_display_power(bus, HDA_CODEC_IDX_CONTROLLER, false);
180 }
181 EXPORT_SYMBOL(hda_codec_i915_put);
182
183 int hda_codec_i915_init(struct snd_sof_dev *sdev)
184 {
185 struct hdac_bus *bus = sof_to_bus(sdev);
186 int ret;
187
188
189 ret = snd_hdac_i915_init(bus);
190 if (ret < 0)
191 return ret;
192
193 hda_codec_i915_get(sdev);
194
195 return 0;
196 }
197 EXPORT_SYMBOL(hda_codec_i915_init);
198
199 int hda_codec_i915_exit(struct snd_sof_dev *sdev)
200 {
201 struct hdac_bus *bus = sof_to_bus(sdev);
202 int ret;
203
204 hda_codec_i915_put(sdev);
205
206 ret = snd_hdac_i915_exit(bus);
207
208 return ret;
209 }
210 EXPORT_SYMBOL(hda_codec_i915_exit);
211
212 #endif
213
214 MODULE_LICENSE("Dual BSD/GPL");