Commit | Line | Data |
---|---|---|
18382ead SP |
1 | /* |
2 | * hdac_hdmi.c - ASoc HDA-HDMI codec driver for Intel platforms | |
3 | * | |
4 | * Copyright (C) 2014-2015 Intel Corp | |
5 | * Author: Samreen Nilofer <samreen.nilofer@intel.com> | |
6 | * Subhransu S. Prusty <subhransu.s.prusty@intel.com> | |
7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License as published by | |
11 | * the Free Software Foundation; version 2 of the License. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
19 | */ | |
20 | #include <linux/init.h> | |
21 | #include <linux/delay.h> | |
22 | #include <linux/module.h> | |
23 | #include <linux/pm_runtime.h> | |
a657f1d0 | 24 | #include <linux/hdmi.h> |
18382ead SP |
25 | #include <sound/pcm_params.h> |
26 | #include <sound/soc.h> | |
27 | #include <sound/hdaudio_ext.h> | |
07f083ab | 28 | #include <sound/hda_i915.h> |
18382ead SP |
29 | #include "../../hda/local.h" |
30 | ||
b0362adb SP |
31 | #define AMP_OUT_MUTE 0xb080 |
32 | #define AMP_OUT_UNMUTE 0xb000 | |
18382ead | 33 | #define PIN_OUT (AC_PINCTL_OUT_EN) |
b0362adb | 34 | |
18382ead SP |
35 | #define HDA_MAX_CONNECTIONS 32 |
36 | ||
37 | struct hdac_hdmi_cvt_params { | |
38 | unsigned int channels_min; | |
39 | unsigned int channels_max; | |
40 | u32 rates; | |
41 | u64 formats; | |
42 | unsigned int maxbps; | |
43 | }; | |
44 | ||
45 | struct hdac_hdmi_cvt { | |
46 | hda_nid_t nid; | |
47 | struct hdac_hdmi_cvt_params params; | |
48 | }; | |
49 | ||
50 | struct hdac_hdmi_pin { | |
51 | hda_nid_t nid; | |
52 | int num_mux_nids; | |
53 | hda_nid_t mux_nids[HDA_MAX_CONNECTIONS]; | |
54 | }; | |
55 | ||
56 | struct hdac_hdmi_dai_pin_map { | |
57 | int dai_id; | |
58 | struct hdac_hdmi_pin pin; | |
59 | struct hdac_hdmi_cvt cvt; | |
60 | }; | |
61 | ||
62 | struct hdac_hdmi_priv { | |
63 | hda_nid_t pin_nid[3]; | |
64 | hda_nid_t cvt_nid[3]; | |
65 | struct hdac_hdmi_dai_pin_map dai_map[3]; | |
66 | }; | |
67 | ||
e342ac08 SP |
68 | static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev) |
69 | { | |
51b2c425 | 70 | struct hdac_device *hdac = dev_to_hdac_dev(dev); |
e342ac08 | 71 | |
51b2c425 | 72 | return to_ehdac_device(hdac); |
e342ac08 SP |
73 | } |
74 | ||
b0362adb SP |
75 | static int hdac_hdmi_setup_stream(struct hdac_ext_device *hdac, |
76 | hda_nid_t cvt_nid, hda_nid_t pin_nid, | |
77 | u32 stream_tag, int format) | |
78 | { | |
79 | unsigned int val; | |
80 | ||
81 | dev_dbg(&hdac->hdac.dev, "cvt nid %d pnid %d stream %d format 0x%x\n", | |
82 | cvt_nid, pin_nid, stream_tag, format); | |
83 | ||
84 | val = (stream_tag << 4); | |
85 | ||
86 | snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0, | |
87 | AC_VERB_SET_CHANNEL_STREAMID, val); | |
88 | snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0, | |
89 | AC_VERB_SET_STREAM_FORMAT, format); | |
90 | ||
91 | return 0; | |
92 | } | |
93 | ||
a657f1d0 SP |
94 | static void |
95 | hdac_hdmi_set_dip_index(struct hdac_ext_device *hdac, hda_nid_t pin_nid, | |
96 | int packet_index, int byte_index) | |
97 | { | |
98 | int val; | |
99 | ||
100 | val = (packet_index << 5) | (byte_index & 0x1f); | |
101 | ||
102 | snd_hdac_codec_write(&hdac->hdac, pin_nid, 0, | |
103 | AC_VERB_SET_HDMI_DIP_INDEX, val); | |
104 | } | |
105 | ||
106 | static int hdac_hdmi_setup_audio_infoframe(struct hdac_ext_device *hdac, | |
107 | hda_nid_t cvt_nid, hda_nid_t pin_nid) | |
108 | { | |
109 | uint8_t buffer[HDMI_INFOFRAME_HEADER_SIZE + HDMI_AUDIO_INFOFRAME_SIZE]; | |
110 | struct hdmi_audio_infoframe frame; | |
111 | u8 *dip = (u8 *)&frame; | |
112 | int ret; | |
113 | int i; | |
114 | ||
115 | hdmi_audio_infoframe_init(&frame); | |
116 | ||
117 | /* Default stereo for now */ | |
118 | frame.channels = 2; | |
119 | ||
120 | /* setup channel count */ | |
121 | snd_hdac_codec_write(&hdac->hdac, cvt_nid, 0, | |
122 | AC_VERB_SET_CVT_CHAN_COUNT, frame.channels - 1); | |
123 | ||
124 | ret = hdmi_audio_infoframe_pack(&frame, buffer, sizeof(buffer)); | |
125 | if (ret < 0) | |
126 | return ret; | |
127 | ||
128 | /* stop infoframe transmission */ | |
129 | hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0); | |
130 | snd_hdac_codec_write(&hdac->hdac, pin_nid, 0, | |
131 | AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_DISABLE); | |
132 | ||
133 | ||
134 | /* Fill infoframe. Index auto-incremented */ | |
135 | hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0); | |
136 | for (i = 0; i < sizeof(frame); i++) | |
137 | snd_hdac_codec_write(&hdac->hdac, pin_nid, 0, | |
138 | AC_VERB_SET_HDMI_DIP_DATA, dip[i]); | |
139 | ||
140 | /* Start infoframe */ | |
141 | hdac_hdmi_set_dip_index(hdac, pin_nid, 0x0, 0x0); | |
142 | snd_hdac_codec_write(&hdac->hdac, pin_nid, 0, | |
143 | AC_VERB_SET_HDMI_DIP_XMIT, AC_DIPXMIT_BEST); | |
144 | ||
145 | return 0; | |
146 | } | |
147 | ||
b0362adb SP |
148 | static void hdac_hdmi_set_power_state(struct hdac_ext_device *edev, |
149 | struct hdac_hdmi_dai_pin_map *dai_map, unsigned int pwr_state) | |
150 | { | |
151 | /* Power up pin widget */ | |
152 | if (!snd_hdac_check_power_state(&edev->hdac, dai_map->pin.nid, pwr_state)) | |
153 | snd_hdac_codec_write(&edev->hdac, dai_map->pin.nid, 0, | |
154 | AC_VERB_SET_POWER_STATE, pwr_state); | |
155 | ||
156 | /* Power up converter */ | |
157 | if (!snd_hdac_check_power_state(&edev->hdac, dai_map->cvt.nid, pwr_state)) | |
158 | snd_hdac_codec_write(&edev->hdac, dai_map->cvt.nid, 0, | |
159 | AC_VERB_SET_POWER_STATE, pwr_state); | |
160 | } | |
161 | ||
162 | static int hdac_hdmi_playback_prepare(struct snd_pcm_substream *substream, | |
163 | struct snd_soc_dai *dai) | |
164 | { | |
165 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); | |
166 | struct hdac_hdmi_priv *hdmi = hdac->private_data; | |
167 | struct hdac_hdmi_dai_pin_map *dai_map; | |
168 | struct hdac_ext_dma_params *dd; | |
a657f1d0 | 169 | int ret; |
b0362adb SP |
170 | |
171 | if (dai->id > 0) { | |
172 | dev_err(&hdac->hdac.dev, "Only one dai supported as of now\n"); | |
173 | return -ENODEV; | |
174 | } | |
175 | ||
176 | dai_map = &hdmi->dai_map[dai->id]; | |
177 | ||
178 | dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream); | |
179 | dev_dbg(&hdac->hdac.dev, "stream tag from cpu dai %d format in cvt 0x%x\n", | |
180 | dd->stream_tag, dd->format); | |
181 | ||
a657f1d0 SP |
182 | ret = hdac_hdmi_setup_audio_infoframe(hdac, dai_map->cvt.nid, |
183 | dai_map->pin.nid); | |
184 | if (ret < 0) | |
185 | return ret; | |
186 | ||
b0362adb SP |
187 | return hdac_hdmi_setup_stream(hdac, dai_map->cvt.nid, dai_map->pin.nid, |
188 | dd->stream_tag, dd->format); | |
189 | } | |
190 | ||
191 | static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream, | |
192 | struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai) | |
193 | { | |
194 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); | |
195 | struct hdac_ext_dma_params *dd; | |
196 | ||
197 | if (dai->id > 0) { | |
198 | dev_err(&hdac->hdac.dev, "Only one dai supported as of now\n"); | |
199 | return -ENODEV; | |
200 | } | |
201 | ||
202 | dd = kzalloc(sizeof(*dd), GFP_KERNEL); | |
8d33ab24 SM |
203 | if (!dd) |
204 | return -ENOMEM; | |
b0362adb SP |
205 | dd->format = snd_hdac_calc_stream_format(params_rate(hparams), |
206 | params_channels(hparams), params_format(hparams), | |
207 | 24, 0); | |
208 | ||
209 | snd_soc_dai_set_dma_data(dai, substream, (void *)dd); | |
210 | ||
211 | return 0; | |
212 | } | |
213 | ||
214 | static int hdac_hdmi_playback_cleanup(struct snd_pcm_substream *substream, | |
215 | struct snd_soc_dai *dai) | |
216 | { | |
217 | struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai); | |
218 | struct hdac_ext_dma_params *dd; | |
219 | struct hdac_hdmi_priv *hdmi = edev->private_data; | |
220 | struct hdac_hdmi_dai_pin_map *dai_map; | |
221 | ||
222 | dai_map = &hdmi->dai_map[dai->id]; | |
223 | ||
224 | snd_hdac_codec_write(&edev->hdac, dai_map->cvt.nid, 0, | |
225 | AC_VERB_SET_CHANNEL_STREAMID, 0); | |
226 | snd_hdac_codec_write(&edev->hdac, dai_map->cvt.nid, 0, | |
227 | AC_VERB_SET_STREAM_FORMAT, 0); | |
228 | ||
229 | dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream); | |
230 | snd_soc_dai_set_dma_data(dai, substream, NULL); | |
231 | ||
232 | kfree(dd); | |
233 | ||
234 | return 0; | |
235 | } | |
236 | ||
237 | static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream, | |
238 | struct snd_soc_dai *dai) | |
239 | { | |
240 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); | |
241 | struct hdac_hdmi_priv *hdmi = hdac->private_data; | |
242 | struct hdac_hdmi_dai_pin_map *dai_map; | |
243 | int val; | |
244 | ||
245 | if (dai->id > 0) { | |
246 | dev_err(&hdac->hdac.dev, "Only one dai supported as of now\n"); | |
247 | return -ENODEV; | |
248 | } | |
249 | ||
250 | dai_map = &hdmi->dai_map[dai->id]; | |
251 | ||
252 | val = snd_hdac_codec_read(&hdac->hdac, dai_map->pin.nid, 0, | |
253 | AC_VERB_GET_PIN_SENSE, 0); | |
254 | dev_info(&hdac->hdac.dev, "Val for AC_VERB_GET_PIN_SENSE: %x\n", val); | |
255 | ||
256 | if ((!(val & AC_PINSENSE_PRESENCE)) || (!(val & AC_PINSENSE_ELDV))) { | |
257 | dev_err(&hdac->hdac.dev, "Monitor presence invalid with val: %x\n", val); | |
258 | return -ENODEV; | |
259 | } | |
260 | ||
261 | hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D0); | |
262 | ||
263 | snd_hdac_codec_write(&hdac->hdac, dai_map->pin.nid, 0, | |
264 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); | |
265 | ||
266 | snd_pcm_hw_constraint_step(substream->runtime, 0, | |
267 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); | |
268 | ||
269 | return 0; | |
270 | } | |
271 | ||
272 | static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream, | |
273 | struct snd_soc_dai *dai) | |
274 | { | |
275 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); | |
276 | struct hdac_hdmi_priv *hdmi = hdac->private_data; | |
277 | struct hdac_hdmi_dai_pin_map *dai_map; | |
278 | ||
279 | dai_map = &hdmi->dai_map[dai->id]; | |
280 | ||
281 | hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D3); | |
282 | ||
283 | snd_hdac_codec_write(&hdac->hdac, dai_map->pin.nid, 0, | |
284 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); | |
285 | } | |
286 | ||
18382ead SP |
287 | static int |
288 | hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt) | |
289 | { | |
290 | int err; | |
291 | ||
292 | /* Only stereo supported as of now */ | |
293 | cvt->params.channels_min = cvt->params.channels_max = 2; | |
294 | ||
295 | err = snd_hdac_query_supported_pcm(hdac, cvt->nid, | |
296 | &cvt->params.rates, | |
297 | &cvt->params.formats, | |
298 | &cvt->params.maxbps); | |
299 | if (err < 0) | |
300 | dev_err(&hdac->dev, | |
301 | "Failed to query pcm params for nid %d: %d\n", | |
302 | cvt->nid, err); | |
303 | ||
304 | return err; | |
305 | } | |
306 | ||
307 | static int hdac_hdmi_query_pin_connlist(struct hdac_ext_device *hdac, | |
308 | struct hdac_hdmi_pin *pin) | |
309 | { | |
310 | if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) { | |
311 | dev_warn(&hdac->hdac.dev, | |
312 | "HDMI: pin %d wcaps %#x does not support connection list\n", | |
313 | pin->nid, get_wcaps(&hdac->hdac, pin->nid)); | |
314 | return -EINVAL; | |
315 | } | |
316 | ||
317 | pin->num_mux_nids = snd_hdac_get_connections(&hdac->hdac, pin->nid, | |
318 | pin->mux_nids, HDA_MAX_CONNECTIONS); | |
53072460 SP |
319 | if (pin->num_mux_nids == 0) |
320 | dev_warn(&hdac->hdac.dev, "No connections found for pin: %d\n", | |
321 | pin->nid); | |
322 | ||
323 | dev_dbg(&hdac->hdac.dev, "num_mux_nids %d for pin: %d\n", | |
324 | pin->num_mux_nids, pin->nid); | |
18382ead SP |
325 | |
326 | return pin->num_mux_nids; | |
327 | } | |
328 | ||
329 | static void hdac_hdmi_fill_widget_info(struct snd_soc_dapm_widget *w, | |
330 | enum snd_soc_dapm_type id, | |
331 | const char *wname, const char *stream) | |
332 | { | |
333 | w->id = id; | |
334 | w->name = wname; | |
335 | w->sname = stream; | |
336 | w->reg = SND_SOC_NOPM; | |
337 | w->shift = 0; | |
338 | w->kcontrol_news = NULL; | |
339 | w->num_kcontrols = 0; | |
340 | w->priv = NULL; | |
341 | } | |
342 | ||
343 | static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route, | |
344 | const char *sink, const char *control, const char *src) | |
345 | { | |
346 | route->sink = sink; | |
347 | route->source = src; | |
348 | route->control = control; | |
349 | route->connected = NULL; | |
350 | } | |
351 | ||
352 | static void create_fill_widget_route_map(struct snd_soc_dapm_context *dapm, | |
353 | struct hdac_hdmi_dai_pin_map *dai_map) | |
354 | { | |
355 | struct snd_soc_dapm_route route[1]; | |
356 | struct snd_soc_dapm_widget widgets[2] = { {0} }; | |
357 | ||
358 | memset(&route, 0, sizeof(route)); | |
359 | ||
360 | hdac_hdmi_fill_widget_info(&widgets[0], snd_soc_dapm_output, | |
361 | "hif1 Output", NULL); | |
362 | hdac_hdmi_fill_widget_info(&widgets[1], snd_soc_dapm_aif_in, | |
363 | "Coverter 1", "hif1"); | |
364 | ||
365 | hdac_hdmi_fill_route(&route[0], "hif1 Output", NULL, "Coverter 1"); | |
366 | ||
367 | snd_soc_dapm_new_controls(dapm, widgets, ARRAY_SIZE(widgets)); | |
368 | snd_soc_dapm_add_routes(dapm, route, ARRAY_SIZE(route)); | |
369 | } | |
370 | ||
371 | static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev, | |
372 | struct hdac_hdmi_dai_pin_map *dai_map, | |
373 | hda_nid_t pin_nid, hda_nid_t cvt_nid, int dai_id) | |
374 | { | |
375 | int ret; | |
376 | ||
377 | dai_map->dai_id = dai_id; | |
378 | dai_map->pin.nid = pin_nid; | |
379 | ||
380 | ret = hdac_hdmi_query_pin_connlist(edev, &dai_map->pin); | |
381 | if (ret < 0) { | |
382 | dev_err(&edev->hdac.dev, | |
383 | "Error querying connection list: %d\n", ret); | |
384 | return ret; | |
385 | } | |
386 | ||
387 | dai_map->cvt.nid = cvt_nid; | |
388 | ||
389 | /* Enable out path for this pin widget */ | |
390 | snd_hdac_codec_write(&edev->hdac, pin_nid, 0, | |
391 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); | |
392 | ||
393 | /* Enable transmission */ | |
394 | snd_hdac_codec_write(&edev->hdac, cvt_nid, 0, | |
395 | AC_VERB_SET_DIGI_CONVERT_1, 1); | |
396 | ||
397 | /* Category Code (CC) to zero */ | |
398 | snd_hdac_codec_write(&edev->hdac, cvt_nid, 0, | |
399 | AC_VERB_SET_DIGI_CONVERT_2, 0); | |
400 | ||
401 | snd_hdac_codec_write(&edev->hdac, pin_nid, 0, | |
402 | AC_VERB_SET_CONNECT_SEL, 0); | |
403 | ||
404 | return hdac_hdmi_query_cvt_params(&edev->hdac, &dai_map->cvt); | |
405 | } | |
406 | ||
407 | /* | |
408 | * Parse all nodes and store the cvt/pin nids in array | |
409 | * Add one time initialization for pin and cvt widgets | |
410 | */ | |
411 | static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev) | |
412 | { | |
413 | hda_nid_t nid; | |
3c83ac23 | 414 | int i, num_nodes; |
18382ead SP |
415 | struct hdac_device *hdac = &edev->hdac; |
416 | struct hdac_hdmi_priv *hdmi = edev->private_data; | |
417 | int cvt_nid = 0, pin_nid = 0; | |
418 | ||
3c83ac23 | 419 | num_nodes = snd_hdac_get_sub_nodes(hdac, hdac->afg, &nid); |
541140d4 | 420 | if (!nid || num_nodes <= 0) { |
18382ead SP |
421 | dev_warn(&hdac->dev, "HDMI: failed to get afg sub nodes\n"); |
422 | return -EINVAL; | |
423 | } | |
424 | ||
3c83ac23 | 425 | hdac->num_nodes = num_nodes; |
18382ead SP |
426 | hdac->start_nid = nid; |
427 | ||
428 | for (i = 0; i < hdac->num_nodes; i++, nid++) { | |
429 | unsigned int caps; | |
430 | unsigned int type; | |
431 | ||
432 | caps = get_wcaps(hdac, nid); | |
433 | type = get_wcaps_type(caps); | |
434 | ||
435 | if (!(caps & AC_WCAP_DIGITAL)) | |
436 | continue; | |
437 | ||
438 | switch (type) { | |
439 | ||
440 | case AC_WID_AUD_OUT: | |
441 | hdmi->cvt_nid[cvt_nid] = nid; | |
442 | cvt_nid++; | |
443 | break; | |
444 | ||
445 | case AC_WID_PIN: | |
446 | hdmi->pin_nid[pin_nid] = nid; | |
447 | pin_nid++; | |
448 | break; | |
449 | } | |
450 | } | |
451 | ||
452 | hdac->end_nid = nid; | |
453 | ||
454 | if (!pin_nid || !cvt_nid) | |
455 | return -EIO; | |
456 | ||
457 | /* | |
458 | * Currently on board only 1 pin and 1 converter is enabled for | |
459 | * simplification, more will be added eventually | |
460 | * So using fixed map for dai_id:pin:cvt | |
461 | */ | |
462 | return hdac_hdmi_init_dai_map(edev, &hdmi->dai_map[0], hdmi->pin_nid[0], | |
463 | hdmi->cvt_nid[0], 0); | |
464 | } | |
465 | ||
466 | static int hdmi_codec_probe(struct snd_soc_codec *codec) | |
467 | { | |
468 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); | |
469 | struct hdac_hdmi_priv *hdmi = edev->private_data; | |
470 | struct snd_soc_dapm_context *dapm = | |
471 | snd_soc_component_get_dapm(&codec->component); | |
472 | ||
473 | edev->scodec = codec; | |
474 | ||
475 | create_fill_widget_route_map(dapm, &hdmi->dai_map[0]); | |
476 | ||
477 | /* Imp: Store the card pointer in hda_codec */ | |
478 | edev->card = dapm->card->snd_card; | |
479 | ||
e342ac08 SP |
480 | /* |
481 | * hdac_device core already sets the state to active and calls | |
482 | * get_noresume. So enable runtime and set the device to suspend. | |
483 | */ | |
484 | pm_runtime_enable(&edev->hdac.dev); | |
485 | pm_runtime_put(&edev->hdac.dev); | |
486 | pm_runtime_suspend(&edev->hdac.dev); | |
487 | ||
488 | return 0; | |
489 | } | |
490 | ||
491 | static int hdmi_codec_remove(struct snd_soc_codec *codec) | |
492 | { | |
493 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); | |
494 | ||
495 | pm_runtime_disable(&edev->hdac.dev); | |
18382ead SP |
496 | return 0; |
497 | } | |
498 | ||
499 | static struct snd_soc_codec_driver hdmi_hda_codec = { | |
500 | .probe = hdmi_codec_probe, | |
e342ac08 | 501 | .remove = hdmi_codec_remove, |
18382ead SP |
502 | .idle_bias_off = true, |
503 | }; | |
504 | ||
b0362adb SP |
505 | static struct snd_soc_dai_ops hdmi_dai_ops = { |
506 | .startup = hdac_hdmi_pcm_open, | |
507 | .shutdown = hdac_hdmi_pcm_close, | |
508 | .hw_params = hdac_hdmi_set_hw_params, | |
509 | .prepare = hdac_hdmi_playback_prepare, | |
510 | .hw_free = hdac_hdmi_playback_cleanup, | |
511 | }; | |
512 | ||
18382ead SP |
513 | static struct snd_soc_dai_driver hdmi_dais[] = { |
514 | { .name = "intel-hdmi-hif1", | |
515 | .playback = { | |
516 | .stream_name = "hif1", | |
517 | .channels_min = 2, | |
518 | .channels_max = 2, | |
519 | .rates = SNDRV_PCM_RATE_32000 | | |
520 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | | |
521 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | | |
522 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, | |
523 | .formats = SNDRV_PCM_FMTBIT_S16_LE | | |
524 | SNDRV_PCM_FMTBIT_S20_3LE | | |
525 | SNDRV_PCM_FMTBIT_S24_LE | | |
526 | SNDRV_PCM_FMTBIT_S32_LE, | |
527 | ||
528 | }, | |
b0362adb | 529 | .ops = &hdmi_dai_ops, |
18382ead SP |
530 | }, |
531 | }; | |
532 | ||
533 | static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev) | |
534 | { | |
535 | struct hdac_device *codec = &edev->hdac; | |
536 | struct hdac_hdmi_priv *hdmi_priv; | |
537 | int ret = 0; | |
538 | ||
539 | hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL); | |
540 | if (hdmi_priv == NULL) | |
541 | return -ENOMEM; | |
542 | ||
543 | edev->private_data = hdmi_priv; | |
544 | ||
545 | dev_set_drvdata(&codec->dev, edev); | |
546 | ||
547 | ret = hdac_hdmi_parse_and_map_nid(edev); | |
548 | if (ret < 0) | |
549 | return ret; | |
550 | ||
551 | /* ASoC specific initialization */ | |
552 | return snd_soc_register_codec(&codec->dev, &hdmi_hda_codec, | |
553 | hdmi_dais, ARRAY_SIZE(hdmi_dais)); | |
554 | } | |
555 | ||
556 | static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev) | |
557 | { | |
558 | snd_soc_unregister_codec(&edev->hdac.dev); | |
559 | ||
560 | return 0; | |
561 | } | |
562 | ||
e342ac08 SP |
563 | #ifdef CONFIG_PM |
564 | static int hdac_hdmi_runtime_suspend(struct device *dev) | |
565 | { | |
566 | struct hdac_ext_device *edev = to_hda_ext_device(dev); | |
567 | struct hdac_device *hdac = &edev->hdac; | |
07f083ab SP |
568 | struct hdac_bus *bus = hdac->bus; |
569 | int err; | |
e342ac08 SP |
570 | |
571 | dev_dbg(dev, "Enter: %s\n", __func__); | |
572 | ||
07f083ab SP |
573 | /* controller may not have been initialized for the first time */ |
574 | if (!bus) | |
575 | return 0; | |
576 | ||
e342ac08 SP |
577 | /* Power down afg */ |
578 | if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D3)) | |
579 | snd_hdac_codec_write(hdac, hdac->afg, 0, | |
580 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); | |
581 | ||
07f083ab SP |
582 | err = snd_hdac_display_power(bus, false); |
583 | if (err < 0) { | |
584 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); | |
585 | return err; | |
586 | } | |
587 | ||
e342ac08 SP |
588 | return 0; |
589 | } | |
590 | ||
591 | static int hdac_hdmi_runtime_resume(struct device *dev) | |
592 | { | |
593 | struct hdac_ext_device *edev = to_hda_ext_device(dev); | |
594 | struct hdac_device *hdac = &edev->hdac; | |
07f083ab SP |
595 | struct hdac_bus *bus = hdac->bus; |
596 | int err; | |
e342ac08 SP |
597 | |
598 | dev_dbg(dev, "Enter: %s\n", __func__); | |
599 | ||
07f083ab SP |
600 | /* controller may not have been initialized for the first time */ |
601 | if (!bus) | |
602 | return 0; | |
603 | ||
604 | err = snd_hdac_display_power(bus, true); | |
605 | if (err < 0) { | |
606 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); | |
607 | return err; | |
608 | } | |
609 | ||
e342ac08 SP |
610 | /* Power up afg */ |
611 | if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0)) | |
612 | snd_hdac_codec_write(hdac, hdac->afg, 0, | |
613 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); | |
614 | ||
615 | return 0; | |
616 | } | |
617 | #else | |
618 | #define hdac_hdmi_runtime_suspend NULL | |
619 | #define hdac_hdmi_runtime_resume NULL | |
620 | #endif | |
621 | ||
622 | static const struct dev_pm_ops hdac_hdmi_pm = { | |
623 | SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL) | |
624 | }; | |
625 | ||
18382ead SP |
626 | static const struct hda_device_id hdmi_list[] = { |
627 | HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0), | |
628 | {} | |
629 | }; | |
630 | ||
631 | MODULE_DEVICE_TABLE(hdaudio, hdmi_list); | |
632 | ||
633 | static struct hdac_ext_driver hdmi_driver = { | |
634 | . hdac = { | |
635 | .driver = { | |
636 | .name = "HDMI HDA Codec", | |
e342ac08 | 637 | .pm = &hdac_hdmi_pm, |
18382ead SP |
638 | }, |
639 | .id_table = hdmi_list, | |
640 | }, | |
641 | .probe = hdac_hdmi_dev_probe, | |
642 | .remove = hdac_hdmi_dev_remove, | |
643 | }; | |
644 | ||
645 | static int __init hdmi_init(void) | |
646 | { | |
647 | return snd_hda_ext_driver_register(&hdmi_driver); | |
648 | } | |
649 | ||
650 | static void __exit hdmi_exit(void) | |
651 | { | |
652 | snd_hda_ext_driver_unregister(&hdmi_driver); | |
653 | } | |
654 | ||
655 | module_init(hdmi_init); | |
656 | module_exit(hdmi_exit); | |
657 | ||
658 | MODULE_LICENSE("GPL v2"); | |
659 | MODULE_DESCRIPTION("HDMI HD codec"); | |
660 | MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>"); | |
661 | MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>"); |