Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 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> |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 24 | #include <linux/hdmi.h> |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 25 | #include <sound/pcm_params.h> |
| 26 | #include <sound/soc.h> |
| 27 | #include <sound/hdaudio_ext.h> |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 28 | #include <sound/hda_i915.h> |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 29 | #include "../../hda/local.h" |
| 30 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 31 | #define AMP_OUT_MUTE 0xb080 |
| 32 | #define AMP_OUT_UNMUTE 0xb000 |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 33 | #define PIN_OUT (AC_PINCTL_OUT_EN) |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 34 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 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 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 68 | static inline struct hdac_ext_device *to_hda_ext_device(struct device *dev) |
| 69 | { |
| 70 | struct hdac_device *hdac = container_of(dev, struct hdac_device, dev); |
| 71 | |
| 72 | return container_of(hdac, struct hdac_ext_device, hdac); |
| 73 | } |
| 74 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 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 | |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 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 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 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; |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 169 | int ret; |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 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 | |
Subhransu S. Prusty | a657f1d | 2015-11-10 18:42:09 +0530 | [diff] [blame] | 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 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 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); |
| 203 | dd->format = snd_hdac_calc_stream_format(params_rate(hparams), |
| 204 | params_channels(hparams), params_format(hparams), |
| 205 | 24, 0); |
| 206 | |
| 207 | snd_soc_dai_set_dma_data(dai, substream, (void *)dd); |
| 208 | |
| 209 | return 0; |
| 210 | } |
| 211 | |
| 212 | static int hdac_hdmi_playback_cleanup(struct snd_pcm_substream *substream, |
| 213 | struct snd_soc_dai *dai) |
| 214 | { |
| 215 | struct hdac_ext_device *edev = snd_soc_dai_get_drvdata(dai); |
| 216 | struct hdac_ext_dma_params *dd; |
| 217 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 218 | struct hdac_hdmi_dai_pin_map *dai_map; |
| 219 | |
| 220 | dai_map = &hdmi->dai_map[dai->id]; |
| 221 | |
| 222 | snd_hdac_codec_write(&edev->hdac, dai_map->cvt.nid, 0, |
| 223 | AC_VERB_SET_CHANNEL_STREAMID, 0); |
| 224 | snd_hdac_codec_write(&edev->hdac, dai_map->cvt.nid, 0, |
| 225 | AC_VERB_SET_STREAM_FORMAT, 0); |
| 226 | |
| 227 | dd = (struct hdac_ext_dma_params *)snd_soc_dai_get_dma_data(dai, substream); |
| 228 | snd_soc_dai_set_dma_data(dai, substream, NULL); |
| 229 | |
| 230 | kfree(dd); |
| 231 | |
| 232 | return 0; |
| 233 | } |
| 234 | |
| 235 | static int hdac_hdmi_pcm_open(struct snd_pcm_substream *substream, |
| 236 | struct snd_soc_dai *dai) |
| 237 | { |
| 238 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); |
| 239 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
| 240 | struct hdac_hdmi_dai_pin_map *dai_map; |
| 241 | int val; |
| 242 | |
| 243 | if (dai->id > 0) { |
| 244 | dev_err(&hdac->hdac.dev, "Only one dai supported as of now\n"); |
| 245 | return -ENODEV; |
| 246 | } |
| 247 | |
| 248 | dai_map = &hdmi->dai_map[dai->id]; |
| 249 | |
| 250 | val = snd_hdac_codec_read(&hdac->hdac, dai_map->pin.nid, 0, |
| 251 | AC_VERB_GET_PIN_SENSE, 0); |
| 252 | dev_info(&hdac->hdac.dev, "Val for AC_VERB_GET_PIN_SENSE: %x\n", val); |
| 253 | |
| 254 | if ((!(val & AC_PINSENSE_PRESENCE)) || (!(val & AC_PINSENSE_ELDV))) { |
| 255 | dev_err(&hdac->hdac.dev, "Monitor presence invalid with val: %x\n", val); |
| 256 | return -ENODEV; |
| 257 | } |
| 258 | |
| 259 | hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D0); |
| 260 | |
| 261 | snd_hdac_codec_write(&hdac->hdac, dai_map->pin.nid, 0, |
| 262 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); |
| 263 | |
| 264 | snd_pcm_hw_constraint_step(substream->runtime, 0, |
| 265 | SNDRV_PCM_HW_PARAM_CHANNELS, 2); |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream, |
| 271 | struct snd_soc_dai *dai) |
| 272 | { |
| 273 | struct hdac_ext_device *hdac = snd_soc_dai_get_drvdata(dai); |
| 274 | struct hdac_hdmi_priv *hdmi = hdac->private_data; |
| 275 | struct hdac_hdmi_dai_pin_map *dai_map; |
| 276 | |
| 277 | dai_map = &hdmi->dai_map[dai->id]; |
| 278 | |
| 279 | hdac_hdmi_set_power_state(hdac, dai_map, AC_PWRST_D3); |
| 280 | |
| 281 | snd_hdac_codec_write(&hdac->hdac, dai_map->pin.nid, 0, |
| 282 | AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE); |
| 283 | } |
| 284 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 285 | static int |
| 286 | hdac_hdmi_query_cvt_params(struct hdac_device *hdac, struct hdac_hdmi_cvt *cvt) |
| 287 | { |
| 288 | int err; |
| 289 | |
| 290 | /* Only stereo supported as of now */ |
| 291 | cvt->params.channels_min = cvt->params.channels_max = 2; |
| 292 | |
| 293 | err = snd_hdac_query_supported_pcm(hdac, cvt->nid, |
| 294 | &cvt->params.rates, |
| 295 | &cvt->params.formats, |
| 296 | &cvt->params.maxbps); |
| 297 | if (err < 0) |
| 298 | dev_err(&hdac->dev, |
| 299 | "Failed to query pcm params for nid %d: %d\n", |
| 300 | cvt->nid, err); |
| 301 | |
| 302 | return err; |
| 303 | } |
| 304 | |
| 305 | static int hdac_hdmi_query_pin_connlist(struct hdac_ext_device *hdac, |
| 306 | struct hdac_hdmi_pin *pin) |
| 307 | { |
| 308 | if (!(get_wcaps(&hdac->hdac, pin->nid) & AC_WCAP_CONN_LIST)) { |
| 309 | dev_warn(&hdac->hdac.dev, |
| 310 | "HDMI: pin %d wcaps %#x does not support connection list\n", |
| 311 | pin->nid, get_wcaps(&hdac->hdac, pin->nid)); |
| 312 | return -EINVAL; |
| 313 | } |
| 314 | |
| 315 | pin->num_mux_nids = snd_hdac_get_connections(&hdac->hdac, pin->nid, |
| 316 | pin->mux_nids, HDA_MAX_CONNECTIONS); |
| 317 | if (pin->num_mux_nids == 0) { |
| 318 | dev_err(&hdac->hdac.dev, "No connections found\n"); |
| 319 | return -ENODEV; |
| 320 | } |
| 321 | |
| 322 | return pin->num_mux_nids; |
| 323 | } |
| 324 | |
| 325 | static void hdac_hdmi_fill_widget_info(struct snd_soc_dapm_widget *w, |
| 326 | enum snd_soc_dapm_type id, |
| 327 | const char *wname, const char *stream) |
| 328 | { |
| 329 | w->id = id; |
| 330 | w->name = wname; |
| 331 | w->sname = stream; |
| 332 | w->reg = SND_SOC_NOPM; |
| 333 | w->shift = 0; |
| 334 | w->kcontrol_news = NULL; |
| 335 | w->num_kcontrols = 0; |
| 336 | w->priv = NULL; |
| 337 | } |
| 338 | |
| 339 | static void hdac_hdmi_fill_route(struct snd_soc_dapm_route *route, |
| 340 | const char *sink, const char *control, const char *src) |
| 341 | { |
| 342 | route->sink = sink; |
| 343 | route->source = src; |
| 344 | route->control = control; |
| 345 | route->connected = NULL; |
| 346 | } |
| 347 | |
| 348 | static void create_fill_widget_route_map(struct snd_soc_dapm_context *dapm, |
| 349 | struct hdac_hdmi_dai_pin_map *dai_map) |
| 350 | { |
| 351 | struct snd_soc_dapm_route route[1]; |
| 352 | struct snd_soc_dapm_widget widgets[2] = { {0} }; |
| 353 | |
| 354 | memset(&route, 0, sizeof(route)); |
| 355 | |
| 356 | hdac_hdmi_fill_widget_info(&widgets[0], snd_soc_dapm_output, |
| 357 | "hif1 Output", NULL); |
| 358 | hdac_hdmi_fill_widget_info(&widgets[1], snd_soc_dapm_aif_in, |
| 359 | "Coverter 1", "hif1"); |
| 360 | |
| 361 | hdac_hdmi_fill_route(&route[0], "hif1 Output", NULL, "Coverter 1"); |
| 362 | |
| 363 | snd_soc_dapm_new_controls(dapm, widgets, ARRAY_SIZE(widgets)); |
| 364 | snd_soc_dapm_add_routes(dapm, route, ARRAY_SIZE(route)); |
| 365 | } |
| 366 | |
| 367 | static int hdac_hdmi_init_dai_map(struct hdac_ext_device *edev, |
| 368 | struct hdac_hdmi_dai_pin_map *dai_map, |
| 369 | hda_nid_t pin_nid, hda_nid_t cvt_nid, int dai_id) |
| 370 | { |
| 371 | int ret; |
| 372 | |
| 373 | dai_map->dai_id = dai_id; |
| 374 | dai_map->pin.nid = pin_nid; |
| 375 | |
| 376 | ret = hdac_hdmi_query_pin_connlist(edev, &dai_map->pin); |
| 377 | if (ret < 0) { |
| 378 | dev_err(&edev->hdac.dev, |
| 379 | "Error querying connection list: %d\n", ret); |
| 380 | return ret; |
| 381 | } |
| 382 | |
| 383 | dai_map->cvt.nid = cvt_nid; |
| 384 | |
| 385 | /* Enable out path for this pin widget */ |
| 386 | snd_hdac_codec_write(&edev->hdac, pin_nid, 0, |
| 387 | AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT); |
| 388 | |
| 389 | /* Enable transmission */ |
| 390 | snd_hdac_codec_write(&edev->hdac, cvt_nid, 0, |
| 391 | AC_VERB_SET_DIGI_CONVERT_1, 1); |
| 392 | |
| 393 | /* Category Code (CC) to zero */ |
| 394 | snd_hdac_codec_write(&edev->hdac, cvt_nid, 0, |
| 395 | AC_VERB_SET_DIGI_CONVERT_2, 0); |
| 396 | |
| 397 | snd_hdac_codec_write(&edev->hdac, pin_nid, 0, |
| 398 | AC_VERB_SET_CONNECT_SEL, 0); |
| 399 | |
| 400 | return hdac_hdmi_query_cvt_params(&edev->hdac, &dai_map->cvt); |
| 401 | } |
| 402 | |
| 403 | /* |
| 404 | * Parse all nodes and store the cvt/pin nids in array |
| 405 | * Add one time initialization for pin and cvt widgets |
| 406 | */ |
| 407 | static int hdac_hdmi_parse_and_map_nid(struct hdac_ext_device *edev) |
| 408 | { |
| 409 | hda_nid_t nid; |
| 410 | int i; |
| 411 | struct hdac_device *hdac = &edev->hdac; |
| 412 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 413 | int cvt_nid = 0, pin_nid = 0; |
| 414 | |
| 415 | hdac->num_nodes = snd_hdac_get_sub_nodes(hdac, hdac->afg, &nid); |
| 416 | if (!nid || hdac->num_nodes < 0) { |
| 417 | dev_warn(&hdac->dev, "HDMI: failed to get afg sub nodes\n"); |
| 418 | return -EINVAL; |
| 419 | } |
| 420 | |
| 421 | hdac->start_nid = nid; |
| 422 | |
| 423 | for (i = 0; i < hdac->num_nodes; i++, nid++) { |
| 424 | unsigned int caps; |
| 425 | unsigned int type; |
| 426 | |
| 427 | caps = get_wcaps(hdac, nid); |
| 428 | type = get_wcaps_type(caps); |
| 429 | |
| 430 | if (!(caps & AC_WCAP_DIGITAL)) |
| 431 | continue; |
| 432 | |
| 433 | switch (type) { |
| 434 | |
| 435 | case AC_WID_AUD_OUT: |
| 436 | hdmi->cvt_nid[cvt_nid] = nid; |
| 437 | cvt_nid++; |
| 438 | break; |
| 439 | |
| 440 | case AC_WID_PIN: |
| 441 | hdmi->pin_nid[pin_nid] = nid; |
| 442 | pin_nid++; |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | |
| 447 | hdac->end_nid = nid; |
| 448 | |
| 449 | if (!pin_nid || !cvt_nid) |
| 450 | return -EIO; |
| 451 | |
| 452 | /* |
| 453 | * Currently on board only 1 pin and 1 converter is enabled for |
| 454 | * simplification, more will be added eventually |
| 455 | * So using fixed map for dai_id:pin:cvt |
| 456 | */ |
| 457 | return hdac_hdmi_init_dai_map(edev, &hdmi->dai_map[0], hdmi->pin_nid[0], |
| 458 | hdmi->cvt_nid[0], 0); |
| 459 | } |
| 460 | |
| 461 | static int hdmi_codec_probe(struct snd_soc_codec *codec) |
| 462 | { |
| 463 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
| 464 | struct hdac_hdmi_priv *hdmi = edev->private_data; |
| 465 | struct snd_soc_dapm_context *dapm = |
| 466 | snd_soc_component_get_dapm(&codec->component); |
| 467 | |
| 468 | edev->scodec = codec; |
| 469 | |
| 470 | create_fill_widget_route_map(dapm, &hdmi->dai_map[0]); |
| 471 | |
| 472 | /* Imp: Store the card pointer in hda_codec */ |
| 473 | edev->card = dapm->card->snd_card; |
| 474 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 475 | /* |
| 476 | * hdac_device core already sets the state to active and calls |
| 477 | * get_noresume. So enable runtime and set the device to suspend. |
| 478 | */ |
| 479 | pm_runtime_enable(&edev->hdac.dev); |
| 480 | pm_runtime_put(&edev->hdac.dev); |
| 481 | pm_runtime_suspend(&edev->hdac.dev); |
| 482 | |
| 483 | return 0; |
| 484 | } |
| 485 | |
| 486 | static int hdmi_codec_remove(struct snd_soc_codec *codec) |
| 487 | { |
| 488 | struct hdac_ext_device *edev = snd_soc_codec_get_drvdata(codec); |
| 489 | |
| 490 | pm_runtime_disable(&edev->hdac.dev); |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 491 | return 0; |
| 492 | } |
| 493 | |
| 494 | static struct snd_soc_codec_driver hdmi_hda_codec = { |
| 495 | .probe = hdmi_codec_probe, |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 496 | .remove = hdmi_codec_remove, |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 497 | .idle_bias_off = true, |
| 498 | }; |
| 499 | |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 500 | static struct snd_soc_dai_ops hdmi_dai_ops = { |
| 501 | .startup = hdac_hdmi_pcm_open, |
| 502 | .shutdown = hdac_hdmi_pcm_close, |
| 503 | .hw_params = hdac_hdmi_set_hw_params, |
| 504 | .prepare = hdac_hdmi_playback_prepare, |
| 505 | .hw_free = hdac_hdmi_playback_cleanup, |
| 506 | }; |
| 507 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 508 | static struct snd_soc_dai_driver hdmi_dais[] = { |
| 509 | { .name = "intel-hdmi-hif1", |
| 510 | .playback = { |
| 511 | .stream_name = "hif1", |
| 512 | .channels_min = 2, |
| 513 | .channels_max = 2, |
| 514 | .rates = SNDRV_PCM_RATE_32000 | |
| 515 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | |
| 516 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | |
| 517 | SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000, |
| 518 | .formats = SNDRV_PCM_FMTBIT_S16_LE | |
| 519 | SNDRV_PCM_FMTBIT_S20_3LE | |
| 520 | SNDRV_PCM_FMTBIT_S24_LE | |
| 521 | SNDRV_PCM_FMTBIT_S32_LE, |
| 522 | |
| 523 | }, |
Subhransu S. Prusty | b0362ad | 2015-11-10 18:42:08 +0530 | [diff] [blame] | 524 | .ops = &hdmi_dai_ops, |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 525 | }, |
| 526 | }; |
| 527 | |
| 528 | static int hdac_hdmi_dev_probe(struct hdac_ext_device *edev) |
| 529 | { |
| 530 | struct hdac_device *codec = &edev->hdac; |
| 531 | struct hdac_hdmi_priv *hdmi_priv; |
| 532 | int ret = 0; |
| 533 | |
| 534 | hdmi_priv = devm_kzalloc(&codec->dev, sizeof(*hdmi_priv), GFP_KERNEL); |
| 535 | if (hdmi_priv == NULL) |
| 536 | return -ENOMEM; |
| 537 | |
| 538 | edev->private_data = hdmi_priv; |
| 539 | |
| 540 | dev_set_drvdata(&codec->dev, edev); |
| 541 | |
| 542 | ret = hdac_hdmi_parse_and_map_nid(edev); |
| 543 | if (ret < 0) |
| 544 | return ret; |
| 545 | |
| 546 | /* ASoC specific initialization */ |
| 547 | return snd_soc_register_codec(&codec->dev, &hdmi_hda_codec, |
| 548 | hdmi_dais, ARRAY_SIZE(hdmi_dais)); |
| 549 | } |
| 550 | |
| 551 | static int hdac_hdmi_dev_remove(struct hdac_ext_device *edev) |
| 552 | { |
| 553 | snd_soc_unregister_codec(&edev->hdac.dev); |
| 554 | |
| 555 | return 0; |
| 556 | } |
| 557 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 558 | #ifdef CONFIG_PM |
| 559 | static int hdac_hdmi_runtime_suspend(struct device *dev) |
| 560 | { |
| 561 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
| 562 | struct hdac_device *hdac = &edev->hdac; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 563 | struct hdac_bus *bus = hdac->bus; |
| 564 | int err; |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 565 | |
| 566 | dev_dbg(dev, "Enter: %s\n", __func__); |
| 567 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 568 | /* controller may not have been initialized for the first time */ |
| 569 | if (!bus) |
| 570 | return 0; |
| 571 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 572 | /* Power down afg */ |
| 573 | if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D3)) |
| 574 | snd_hdac_codec_write(hdac, hdac->afg, 0, |
| 575 | AC_VERB_SET_POWER_STATE, AC_PWRST_D3); |
| 576 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 577 | err = snd_hdac_display_power(bus, false); |
| 578 | if (err < 0) { |
| 579 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); |
| 580 | return err; |
| 581 | } |
| 582 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 583 | return 0; |
| 584 | } |
| 585 | |
| 586 | static int hdac_hdmi_runtime_resume(struct device *dev) |
| 587 | { |
| 588 | struct hdac_ext_device *edev = to_hda_ext_device(dev); |
| 589 | struct hdac_device *hdac = &edev->hdac; |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 590 | struct hdac_bus *bus = hdac->bus; |
| 591 | int err; |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 592 | |
| 593 | dev_dbg(dev, "Enter: %s\n", __func__); |
| 594 | |
Subhransu S. Prusty | 07f083a | 2015-11-10 18:42:10 +0530 | [diff] [blame^] | 595 | /* controller may not have been initialized for the first time */ |
| 596 | if (!bus) |
| 597 | return 0; |
| 598 | |
| 599 | err = snd_hdac_display_power(bus, true); |
| 600 | if (err < 0) { |
| 601 | dev_err(bus->dev, "Cannot turn on display power on i915\n"); |
| 602 | return err; |
| 603 | } |
| 604 | |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 605 | /* Power up afg */ |
| 606 | if (!snd_hdac_check_power_state(hdac, hdac->afg, AC_PWRST_D0)) |
| 607 | snd_hdac_codec_write(hdac, hdac->afg, 0, |
| 608 | AC_VERB_SET_POWER_STATE, AC_PWRST_D0); |
| 609 | |
| 610 | return 0; |
| 611 | } |
| 612 | #else |
| 613 | #define hdac_hdmi_runtime_suspend NULL |
| 614 | #define hdac_hdmi_runtime_resume NULL |
| 615 | #endif |
| 616 | |
| 617 | static const struct dev_pm_ops hdac_hdmi_pm = { |
| 618 | SET_RUNTIME_PM_OPS(hdac_hdmi_runtime_suspend, hdac_hdmi_runtime_resume, NULL) |
| 619 | }; |
| 620 | |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 621 | static const struct hda_device_id hdmi_list[] = { |
| 622 | HDA_CODEC_EXT_ENTRY(0x80862809, 0x100000, "Skylake HDMI", 0), |
| 623 | {} |
| 624 | }; |
| 625 | |
| 626 | MODULE_DEVICE_TABLE(hdaudio, hdmi_list); |
| 627 | |
| 628 | static struct hdac_ext_driver hdmi_driver = { |
| 629 | . hdac = { |
| 630 | .driver = { |
| 631 | .name = "HDMI HDA Codec", |
Subhransu S. Prusty | e342ac0 | 2015-11-10 18:42:07 +0530 | [diff] [blame] | 632 | .pm = &hdac_hdmi_pm, |
Subhransu S. Prusty | 18382ea | 2015-11-10 18:42:06 +0530 | [diff] [blame] | 633 | }, |
| 634 | .id_table = hdmi_list, |
| 635 | }, |
| 636 | .probe = hdac_hdmi_dev_probe, |
| 637 | .remove = hdac_hdmi_dev_remove, |
| 638 | }; |
| 639 | |
| 640 | static int __init hdmi_init(void) |
| 641 | { |
| 642 | return snd_hda_ext_driver_register(&hdmi_driver); |
| 643 | } |
| 644 | |
| 645 | static void __exit hdmi_exit(void) |
| 646 | { |
| 647 | snd_hda_ext_driver_unregister(&hdmi_driver); |
| 648 | } |
| 649 | |
| 650 | module_init(hdmi_init); |
| 651 | module_exit(hdmi_exit); |
| 652 | |
| 653 | MODULE_LICENSE("GPL v2"); |
| 654 | MODULE_DESCRIPTION("HDMI HD codec"); |
| 655 | MODULE_AUTHOR("Samreen Nilofer<samreen.nilofer@intel.com>"); |
| 656 | MODULE_AUTHOR("Subhransu S. Prusty<subhransu.s.prusty@intel.com>"); |