intelhdmi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Intel HDMI codec support
  4. */
  5. #include <linux/init.h>
  6. #include <linux/slab.h>
  7. #include <linux/module.h>
  8. #include <sound/core.h>
  9. #include <sound/hdaudio.h>
  10. #include <sound/hda_i915.h>
  11. #include <sound/hda_codec.h>
  12. #include "hda_local.h"
  13. #include "hdmi_local.h"
  14. static bool enable_silent_stream =
  15. IS_ENABLED(CONFIG_SND_HDA_INTEL_HDMI_SILENT_STREAM);
  16. module_param(enable_silent_stream, bool, 0644);
  17. MODULE_PARM_DESC(enable_silent_stream, "Enable Silent Stream for HDMI devices");
  18. enum {
  19. MODEL_HSW,
  20. MODEL_GLK,
  21. MODEL_ICL,
  22. MODEL_TGL,
  23. MODEL_ADLP,
  24. MODEL_BYT,
  25. MODEL_CPT,
  26. };
  27. #define INTEL_GET_VENDOR_VERB 0xf81
  28. #define INTEL_SET_VENDOR_VERB 0x781
  29. #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
  30. #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
  31. static void intel_haswell_enable_all_pins(struct hda_codec *codec,
  32. bool update_tree)
  33. {
  34. unsigned int vendor_param;
  35. struct hdmi_spec *spec = codec->spec;
  36. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  37. INTEL_GET_VENDOR_VERB, 0);
  38. if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
  39. return;
  40. vendor_param |= INTEL_EN_ALL_PIN_CVTS;
  41. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  42. INTEL_SET_VENDOR_VERB, vendor_param);
  43. if (vendor_param == -1)
  44. return;
  45. if (update_tree)
  46. snd_hda_codec_update_widgets(codec);
  47. }
  48. static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
  49. {
  50. unsigned int vendor_param;
  51. struct hdmi_spec *spec = codec->spec;
  52. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  53. INTEL_GET_VENDOR_VERB, 0);
  54. if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
  55. return;
  56. /* enable DP1.2 mode */
  57. vendor_param |= INTEL_EN_DP12;
  58. snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
  59. snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
  60. INTEL_SET_VENDOR_VERB, vendor_param);
  61. }
  62. /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
  63. * Otherwise you may get severe h/w communication errors.
  64. */
  65. static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  66. unsigned int power_state)
  67. {
  68. /* check codec->spec: it can be called before the probe gets called */
  69. if (codec->spec) {
  70. if (power_state == AC_PWRST_D0) {
  71. intel_haswell_enable_all_pins(codec, false);
  72. intel_haswell_fixup_enable_dp12(codec);
  73. }
  74. }
  75. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
  76. snd_hda_codec_set_power_to_all(codec, fg, power_state);
  77. }
  78. /* There is a fixed mapping between audio pin node and display port.
  79. * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
  80. * Pin Widget 5 - PORT B (port = 1 in i915 driver)
  81. * Pin Widget 6 - PORT C (port = 2 in i915 driver)
  82. * Pin Widget 7 - PORT D (port = 3 in i915 driver)
  83. *
  84. * on VLV, ILK:
  85. * Pin Widget 4 - PORT B (port = 1 in i915 driver)
  86. * Pin Widget 5 - PORT C (port = 2 in i915 driver)
  87. * Pin Widget 6 - PORT D (port = 3 in i915 driver)
  88. */
  89. static int intel_base_nid(struct hda_codec *codec)
  90. {
  91. switch (codec->core.vendor_id) {
  92. case 0x80860054: /* ILK */
  93. case 0x80862804: /* ILK */
  94. case 0x80862882: /* VLV */
  95. return 4;
  96. default:
  97. return 5;
  98. }
  99. }
  100. static int intel_pin2port(void *audio_ptr, int pin_nid)
  101. {
  102. struct hda_codec *codec = audio_ptr;
  103. struct hdmi_spec *spec = codec->spec;
  104. int base_nid, i;
  105. if (!spec->port_num) {
  106. base_nid = intel_base_nid(codec);
  107. if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
  108. return -1;
  109. return pin_nid - base_nid + 1;
  110. }
  111. /*
  112. * looking for the pin number in the mapping table and return
  113. * the index which indicate the port number
  114. */
  115. for (i = 0; i < spec->port_num; i++) {
  116. if (pin_nid == spec->port_map[i])
  117. return i;
  118. }
  119. codec_info(codec, "Can't find the HDMI/DP port for pin NID 0x%x\n", pin_nid);
  120. return -1;
  121. }
  122. static int intel_port2pin(struct hda_codec *codec, int port)
  123. {
  124. struct hdmi_spec *spec = codec->spec;
  125. if (!spec->port_num) {
  126. /* we assume only from port-B to port-D */
  127. if (port < 1 || port > 3)
  128. return 0;
  129. return port + intel_base_nid(codec) - 1;
  130. }
  131. if (port < 0 || port >= spec->port_num)
  132. return 0;
  133. return spec->port_map[port];
  134. }
  135. static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
  136. {
  137. struct hda_codec *codec = audio_ptr;
  138. int pin_nid;
  139. int dev_id = pipe;
  140. pin_nid = intel_port2pin(codec, port);
  141. if (!pin_nid)
  142. return;
  143. /* skip notification during system suspend (but not in runtime PM);
  144. * the state will be updated at resume
  145. */
  146. if (codec->core.dev.power.power_state.event == PM_EVENT_SUSPEND)
  147. return;
  148. snd_hdac_i915_set_bclk(&codec->bus->core);
  149. snd_hda_hdmi_check_presence_and_report(codec, pin_nid, dev_id);
  150. }
  151. static const struct drm_audio_component_audio_ops intel_audio_ops = {
  152. .pin2port = intel_pin2port,
  153. .pin_eld_notify = intel_pin_eld_notify,
  154. };
  155. /* register i915 component pin_eld_notify callback */
  156. static void register_i915_notifier(struct hda_codec *codec)
  157. {
  158. struct hdmi_spec *spec = codec->spec;
  159. spec->use_acomp_notifier = true;
  160. spec->port2pin = intel_port2pin;
  161. snd_hda_hdmi_setup_drm_audio_ops(codec, &intel_audio_ops);
  162. snd_hdac_acomp_register_notifier(&codec->bus->core,
  163. &spec->drm_audio_ops);
  164. /* no need for forcible resume for jack check thanks to notifier */
  165. codec->relaxed_resume = 1;
  166. }
  167. #define I915_SILENT_RATE 48000
  168. #define I915_SILENT_CHANNELS 2
  169. #define I915_SILENT_FORMAT_BITS 16
  170. #define I915_SILENT_FMT_MASK 0xf
  171. static void silent_stream_enable_i915(struct hda_codec *codec,
  172. struct hdmi_spec_per_pin *per_pin)
  173. {
  174. unsigned int format;
  175. snd_hdac_sync_audio_rate(&codec->core, per_pin->pin_nid,
  176. per_pin->dev_id, I915_SILENT_RATE);
  177. /* trigger silent stream generation in hw */
  178. format = snd_hdac_stream_format(I915_SILENT_CHANNELS, I915_SILENT_FORMAT_BITS,
  179. I915_SILENT_RATE);
  180. snd_hda_codec_setup_stream(codec, per_pin->cvt_nid,
  181. I915_SILENT_FMT_MASK, I915_SILENT_FMT_MASK, format);
  182. usleep_range(100, 200);
  183. snd_hda_codec_setup_stream(codec, per_pin->cvt_nid, I915_SILENT_FMT_MASK, 0, format);
  184. per_pin->channels = I915_SILENT_CHANNELS;
  185. snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
  186. }
  187. static void silent_stream_set_kae(struct hda_codec *codec,
  188. struct hdmi_spec_per_pin *per_pin,
  189. bool enable)
  190. {
  191. unsigned int param;
  192. codec_dbg(codec, "HDMI: KAE %d cvt-NID=0x%x\n", enable, per_pin->cvt_nid);
  193. param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0, AC_VERB_GET_DIGI_CONVERT_1, 0);
  194. param = (param >> 16) & 0xff;
  195. if (enable)
  196. param |= AC_DIG3_KAE;
  197. else
  198. param &= ~AC_DIG3_KAE;
  199. snd_hda_codec_write(codec, per_pin->cvt_nid, 0, AC_VERB_SET_DIGI_CONVERT_3, param);
  200. }
  201. static void i915_set_silent_stream(struct hda_codec *codec,
  202. struct hdmi_spec_per_pin *per_pin,
  203. bool enable)
  204. {
  205. struct hdmi_spec *spec = codec->spec;
  206. switch (spec->silent_stream_type) {
  207. case SILENT_STREAM_KAE:
  208. if (enable) {
  209. silent_stream_enable_i915(codec, per_pin);
  210. silent_stream_set_kae(codec, per_pin, true);
  211. } else {
  212. silent_stream_set_kae(codec, per_pin, false);
  213. }
  214. break;
  215. case SILENT_STREAM_I915:
  216. if (enable) {
  217. silent_stream_enable_i915(codec, per_pin);
  218. snd_hda_power_up_pm(codec);
  219. } else {
  220. /* release ref taken in silent_stream_enable() */
  221. snd_hda_power_down_pm(codec);
  222. }
  223. break;
  224. default:
  225. break;
  226. }
  227. }
  228. static void haswell_verify_D0(struct hda_codec *codec,
  229. hda_nid_t cvt_nid, hda_nid_t nid)
  230. {
  231. int pwr;
  232. /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
  233. * thus pins could only choose converter 0 for use. Make sure the
  234. * converters are in correct power state
  235. */
  236. if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
  237. snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  238. if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
  239. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
  240. AC_PWRST_D0);
  241. msleep(40);
  242. pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
  243. pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
  244. codec_dbg(codec, "Haswell HDMI audio: Power for NID 0x%x is now D%d\n", nid, pwr);
  245. }
  246. }
  247. /* Assure the pin select the right convetor */
  248. static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
  249. struct hdmi_spec_per_pin *per_pin)
  250. {
  251. hda_nid_t pin_nid = per_pin->pin_nid;
  252. int mux_idx, curr;
  253. mux_idx = per_pin->mux_idx;
  254. curr = snd_hda_codec_read(codec, pin_nid, 0,
  255. AC_VERB_GET_CONNECT_SEL, 0);
  256. if (curr != mux_idx)
  257. snd_hda_codec_write_cache(codec, pin_nid, 0,
  258. AC_VERB_SET_CONNECT_SEL,
  259. mux_idx);
  260. }
  261. /* get the mux index for the converter of the pins
  262. * converter's mux index is the same for all pins on Intel platform
  263. */
  264. static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
  265. hda_nid_t cvt_nid)
  266. {
  267. int i;
  268. for (i = 0; i < spec->num_cvts; i++)
  269. if (spec->cvt_nids[i] == cvt_nid)
  270. return i;
  271. return -EINVAL;
  272. }
  273. /* Intel HDMI workaround to fix audio routing issue:
  274. * For some Intel display codecs, pins share the same connection list.
  275. * So a conveter can be selected by multiple pins and playback on any of these
  276. * pins will generate sound on the external display, because audio flows from
  277. * the same converter to the display pipeline. Also muting one pin may make
  278. * other pins have no sound output.
  279. * So this function assures that an assigned converter for a pin is not selected
  280. * by any other pins.
  281. */
  282. static void intel_not_share_assigned_cvt(struct hda_codec *codec,
  283. hda_nid_t pin_nid,
  284. int dev_id, int mux_idx)
  285. {
  286. struct hdmi_spec *spec = codec->spec;
  287. hda_nid_t nid;
  288. int cvt_idx, curr;
  289. struct hdmi_spec_per_cvt *per_cvt;
  290. struct hdmi_spec_per_pin *per_pin;
  291. int pin_idx;
  292. /* configure the pins connections */
  293. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  294. int dev_id_saved;
  295. int dev_num;
  296. per_pin = get_pin(spec, pin_idx);
  297. /*
  298. * pin not connected to monitor
  299. * no need to operate on it
  300. */
  301. if (!per_pin->pcm)
  302. continue;
  303. if ((per_pin->pin_nid == pin_nid) &&
  304. (per_pin->dev_id == dev_id))
  305. continue;
  306. /*
  307. * if per_pin->dev_id >= dev_num,
  308. * snd_hda_get_dev_select() will fail,
  309. * and the following operation is unpredictable.
  310. * So skip this situation.
  311. */
  312. dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
  313. if (per_pin->dev_id >= dev_num)
  314. continue;
  315. nid = per_pin->pin_nid;
  316. /*
  317. * Calling this function should not impact
  318. * on the device entry selection
  319. * So let's save the dev id for each pin,
  320. * and restore it when return
  321. */
  322. dev_id_saved = snd_hda_get_dev_select(codec, nid);
  323. snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
  324. curr = snd_hda_codec_read(codec, nid, 0,
  325. AC_VERB_GET_CONNECT_SEL, 0);
  326. if (curr != mux_idx) {
  327. snd_hda_set_dev_select(codec, nid, dev_id_saved);
  328. continue;
  329. }
  330. /* choose an unassigned converter. The conveters in the
  331. * connection list are in the same order as in the codec.
  332. */
  333. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  334. per_cvt = get_cvt(spec, cvt_idx);
  335. if (!per_cvt->assigned) {
  336. codec_dbg(codec,
  337. "choose cvt %d for pin NID 0x%x\n",
  338. cvt_idx, nid);
  339. snd_hda_codec_write_cache(codec, nid, 0,
  340. AC_VERB_SET_CONNECT_SEL,
  341. cvt_idx);
  342. break;
  343. }
  344. }
  345. snd_hda_set_dev_select(codec, nid, dev_id_saved);
  346. }
  347. }
  348. /* A wrapper of intel_not_share_asigned_cvt() */
  349. static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
  350. hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
  351. {
  352. int mux_idx;
  353. struct hdmi_spec *spec = codec->spec;
  354. /* On Intel platform, the mapping of converter nid to
  355. * mux index of the pins are always the same.
  356. * The pin nid may be 0, this means all pins will not
  357. * share the converter.
  358. */
  359. mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
  360. if (mux_idx >= 0)
  361. intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
  362. }
  363. /* setup_stream ops override for HSW+ */
  364. static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  365. hda_nid_t pin_nid, int dev_id, u32 stream_tag,
  366. int format)
  367. {
  368. struct hdmi_spec *spec = codec->spec;
  369. int pin_idx = pin_id_to_pin_index(codec, pin_nid, dev_id);
  370. struct hdmi_spec_per_pin *per_pin;
  371. int res;
  372. if (pin_idx < 0)
  373. per_pin = NULL;
  374. else
  375. per_pin = get_pin(spec, pin_idx);
  376. haswell_verify_D0(codec, cvt_nid, pin_nid);
  377. if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin && per_pin->silent_stream) {
  378. silent_stream_set_kae(codec, per_pin, false);
  379. /* wait for pending transfers in codec to clear */
  380. usleep_range(100, 200);
  381. }
  382. res = snd_hda_hdmi_setup_stream(codec, cvt_nid, pin_nid, dev_id,
  383. stream_tag, format);
  384. if (spec->silent_stream_type == SILENT_STREAM_KAE && per_pin && per_pin->silent_stream) {
  385. usleep_range(100, 200);
  386. silent_stream_set_kae(codec, per_pin, true);
  387. }
  388. return res;
  389. }
  390. /* pin_cvt_fixup ops override for HSW+ and VLV+ */
  391. static void i915_pin_cvt_fixup(struct hda_codec *codec,
  392. struct hdmi_spec_per_pin *per_pin,
  393. hda_nid_t cvt_nid)
  394. {
  395. if (per_pin) {
  396. haswell_verify_D0(codec, per_pin->cvt_nid, per_pin->pin_nid);
  397. snd_hda_set_dev_select(codec, per_pin->pin_nid,
  398. per_pin->dev_id);
  399. intel_verify_pin_cvt_connect(codec, per_pin);
  400. intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
  401. per_pin->dev_id, per_pin->mux_idx);
  402. } else {
  403. intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
  404. }
  405. }
  406. static int i915_hdmi_suspend(struct hda_codec *codec)
  407. {
  408. struct hdmi_spec *spec = codec->spec;
  409. bool silent_streams = false;
  410. int pin_idx, res;
  411. res = snd_hda_hdmi_generic_suspend(codec);
  412. if (spec->silent_stream_type != SILENT_STREAM_KAE)
  413. return res;
  414. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  415. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  416. if (per_pin->silent_stream) {
  417. silent_streams = true;
  418. break;
  419. }
  420. }
  421. if (silent_streams) {
  422. /*
  423. * stream-id should remain programmed when codec goes
  424. * to runtime suspend
  425. */
  426. codec->no_stream_clean_at_suspend = 1;
  427. /*
  428. * the system might go to S3, in which case keep-alive
  429. * must be reprogrammed upon resume
  430. */
  431. codec->forced_resume = 1;
  432. codec_dbg(codec, "HDMI: KAE active at suspend\n");
  433. } else {
  434. codec->no_stream_clean_at_suspend = 0;
  435. codec->forced_resume = 0;
  436. }
  437. return res;
  438. }
  439. static int i915_hdmi_resume(struct hda_codec *codec)
  440. {
  441. struct hdmi_spec *spec = codec->spec;
  442. int pin_idx, res;
  443. res = snd_hda_hdmi_generic_resume(codec);
  444. if (spec->silent_stream_type != SILENT_STREAM_KAE)
  445. return res;
  446. /* KAE not programmed at suspend, nothing to do here */
  447. if (!codec->no_stream_clean_at_suspend)
  448. return res;
  449. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  450. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  451. /*
  452. * If system was in suspend with monitor connected,
  453. * the codec setting may have been lost. Re-enable
  454. * keep-alive.
  455. */
  456. if (per_pin->silent_stream) {
  457. unsigned int param;
  458. param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
  459. AC_VERB_GET_CONV, 0);
  460. if (!param) {
  461. codec_dbg(codec, "HDMI: KAE: restore stream id\n");
  462. silent_stream_enable_i915(codec, per_pin);
  463. }
  464. param = snd_hda_codec_read(codec, per_pin->cvt_nid, 0,
  465. AC_VERB_GET_DIGI_CONVERT_1, 0);
  466. if (!(param & (AC_DIG3_KAE << 16))) {
  467. codec_dbg(codec, "HDMI: KAE: restore DIG3_KAE\n");
  468. silent_stream_set_kae(codec, per_pin, true);
  469. }
  470. }
  471. }
  472. return res;
  473. }
  474. /* precondition and allocation for Intel codecs */
  475. static int alloc_intel_hdmi(struct hda_codec *codec)
  476. {
  477. /* requires i915 binding */
  478. if (!codec->bus->core.audio_component) {
  479. codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
  480. /* set probe_id here to prevent generic fallback binding */
  481. codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
  482. return -ENODEV;
  483. }
  484. return snd_hda_hdmi_generic_alloc(codec);
  485. }
  486. /* parse and post-process for Intel codecs */
  487. static int parse_intel_hdmi(struct hda_codec *codec)
  488. {
  489. int err, retries = 3;
  490. do {
  491. err = snd_hda_hdmi_parse_codec(codec);
  492. } while (err < 0 && retries--);
  493. if (err < 0)
  494. return err;
  495. snd_hda_hdmi_generic_init_per_pins(codec);
  496. register_i915_notifier(codec);
  497. return 0;
  498. }
  499. /* Intel Haswell and onwards; audio component with eld notifier */
  500. static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid,
  501. const int *port_map, int port_num, int dev_num,
  502. bool send_silent_stream)
  503. {
  504. struct hdmi_spec *spec;
  505. spec = codec->spec;
  506. codec->dp_mst = true;
  507. spec->vendor_nid = vendor_nid;
  508. spec->port_map = port_map;
  509. spec->port_num = port_num;
  510. spec->intel_hsw_fixup = true;
  511. spec->dev_num = dev_num;
  512. intel_haswell_enable_all_pins(codec, true);
  513. intel_haswell_fixup_enable_dp12(codec);
  514. codec->display_power_control = 1;
  515. codec->depop_delay = 0;
  516. codec->auto_runtime_pm = 1;
  517. spec->ops.setup_stream = i915_hsw_setup_stream;
  518. spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
  519. spec->ops.silent_stream = i915_set_silent_stream;
  520. /*
  521. * Enable silent stream feature, if it is enabled via
  522. * module param or Kconfig option
  523. */
  524. if (send_silent_stream)
  525. spec->silent_stream_type = SILENT_STREAM_I915;
  526. return parse_intel_hdmi(codec);
  527. }
  528. static int probe_i915_hsw_hdmi(struct hda_codec *codec)
  529. {
  530. return intel_hsw_common_init(codec, 0x08, NULL, 0, 3,
  531. enable_silent_stream);
  532. }
  533. static int probe_i915_glk_hdmi(struct hda_codec *codec)
  534. {
  535. /*
  536. * Silent stream calls audio component .get_power() from
  537. * .pin_eld_notify(). On GLK this will deadlock in i915 due
  538. * to the audio vs. CDCLK workaround.
  539. */
  540. return intel_hsw_common_init(codec, 0x0b, NULL, 0, 3, false);
  541. }
  542. static int probe_i915_icl_hdmi(struct hda_codec *codec)
  543. {
  544. /*
  545. * pin to port mapping table where the value indicate the pin number and
  546. * the index indicate the port number.
  547. */
  548. static const int map[] = {0x0, 0x4, 0x6, 0x8, 0xa, 0xb};
  549. return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 3,
  550. enable_silent_stream);
  551. }
  552. static int probe_i915_tgl_hdmi(struct hda_codec *codec)
  553. {
  554. /*
  555. * pin to port mapping table where the value indicate the pin number and
  556. * the index indicate the port number.
  557. */
  558. static const int map[] = {0x4, 0x6, 0x8, 0xa, 0xb, 0xc, 0xd, 0xe, 0xf};
  559. return intel_hsw_common_init(codec, 0x02, map, ARRAY_SIZE(map), 4,
  560. enable_silent_stream);
  561. }
  562. static int probe_i915_adlp_hdmi(struct hda_codec *codec)
  563. {
  564. struct hdmi_spec *spec;
  565. int res;
  566. res = probe_i915_tgl_hdmi(codec);
  567. if (!res) {
  568. spec = codec->spec;
  569. if (spec->silent_stream_type)
  570. spec->silent_stream_type = SILENT_STREAM_KAE;
  571. }
  572. return res;
  573. }
  574. /* Intel Baytrail and Braswell; with eld notifier */
  575. static int probe_i915_byt_hdmi(struct hda_codec *codec)
  576. {
  577. struct hdmi_spec *spec;
  578. spec = codec->spec;
  579. /* For Valleyview/Cherryview, only the display codec is in the display
  580. * power well and can use link_power ops to request/release the power.
  581. */
  582. codec->display_power_control = 1;
  583. codec->depop_delay = 0;
  584. codec->auto_runtime_pm = 1;
  585. spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
  586. return parse_intel_hdmi(codec);
  587. }
  588. /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
  589. static int probe_i915_cpt_hdmi(struct hda_codec *codec)
  590. {
  591. return parse_intel_hdmi(codec);
  592. }
  593. /*
  594. * common driver probe
  595. */
  596. static int intelhdmi_probe(struct hda_codec *codec, const struct hda_device_id *id)
  597. {
  598. int err;
  599. err = alloc_intel_hdmi(codec);
  600. if (err < 0)
  601. return err;
  602. switch (id->driver_data) {
  603. case MODEL_HSW:
  604. err = probe_i915_hsw_hdmi(codec);
  605. break;
  606. case MODEL_GLK:
  607. err = probe_i915_glk_hdmi(codec);
  608. break;
  609. case MODEL_ICL:
  610. err = probe_i915_icl_hdmi(codec);
  611. break;
  612. case MODEL_TGL:
  613. err = probe_i915_tgl_hdmi(codec);
  614. break;
  615. case MODEL_ADLP:
  616. err = probe_i915_adlp_hdmi(codec);
  617. break;
  618. case MODEL_BYT:
  619. err = probe_i915_byt_hdmi(codec);
  620. break;
  621. case MODEL_CPT:
  622. err = probe_i915_cpt_hdmi(codec);
  623. break;
  624. default:
  625. err = -EINVAL;
  626. break;
  627. }
  628. if (err < 0) {
  629. snd_hda_hdmi_generic_spec_free(codec);
  630. return err;
  631. }
  632. return 0;
  633. }
  634. static const struct hda_codec_ops intelhdmi_codec_ops = {
  635. .probe = intelhdmi_probe,
  636. .remove = snd_hda_hdmi_generic_remove,
  637. .init = snd_hda_hdmi_generic_init,
  638. .build_pcms = snd_hda_hdmi_generic_build_pcms,
  639. .build_controls = snd_hda_hdmi_generic_build_controls,
  640. .unsol_event = snd_hda_hdmi_generic_unsol_event,
  641. .suspend = i915_hdmi_suspend,
  642. .resume = i915_hdmi_resume,
  643. .set_power_state = haswell_set_power_state,
  644. };
  645. /*
  646. * driver entries
  647. */
  648. static const struct hda_device_id snd_hda_id_intelhdmi[] = {
  649. HDA_CODEC_ID_MODEL(0x80860054, "IbexPeak HDMI", MODEL_CPT),
  650. HDA_CODEC_ID_MODEL(0x80862800, "Geminilake HDMI", MODEL_GLK),
  651. HDA_CODEC_ID_MODEL(0x80862804, "IbexPeak HDMI", MODEL_CPT),
  652. HDA_CODEC_ID_MODEL(0x80862805, "CougarPoint HDMI", MODEL_CPT),
  653. HDA_CODEC_ID_MODEL(0x80862806, "PantherPoint HDMI", MODEL_CPT),
  654. HDA_CODEC_ID_MODEL(0x80862807, "Haswell HDMI", MODEL_HSW),
  655. HDA_CODEC_ID_MODEL(0x80862808, "Broadwell HDMI", MODEL_HSW),
  656. HDA_CODEC_ID_MODEL(0x80862809, "Skylake HDMI", MODEL_HSW),
  657. HDA_CODEC_ID_MODEL(0x8086280a, "Broxton HDMI", MODEL_HSW),
  658. HDA_CODEC_ID_MODEL(0x8086280b, "Kabylake HDMI", MODEL_HSW),
  659. HDA_CODEC_ID_MODEL(0x8086280c, "Cannonlake HDMI", MODEL_GLK),
  660. HDA_CODEC_ID_MODEL(0x8086280d, "Geminilake HDMI", MODEL_GLK),
  661. HDA_CODEC_ID_MODEL(0x8086280f, "Icelake HDMI", MODEL_ICL),
  662. HDA_CODEC_ID_MODEL(0x80862812, "Tigerlake HDMI", MODEL_TGL),
  663. HDA_CODEC_ID_MODEL(0x80862814, "DG1 HDMI", MODEL_TGL),
  664. HDA_CODEC_ID_MODEL(0x80862815, "Alderlake HDMI", MODEL_TGL),
  665. HDA_CODEC_ID_MODEL(0x80862816, "Rocketlake HDMI", MODEL_TGL),
  666. HDA_CODEC_ID_MODEL(0x80862818, "Raptorlake HDMI", MODEL_TGL),
  667. HDA_CODEC_ID_MODEL(0x80862819, "DG2 HDMI", MODEL_TGL),
  668. HDA_CODEC_ID_MODEL(0x8086281a, "Jasperlake HDMI", MODEL_ICL),
  669. HDA_CODEC_ID_MODEL(0x8086281b, "Elkhartlake HDMI", MODEL_ICL),
  670. HDA_CODEC_ID_MODEL(0x8086281c, "Alderlake-P HDMI", MODEL_ADLP),
  671. HDA_CODEC_ID_MODEL(0x8086281d, "Meteor Lake HDMI", MODEL_ADLP),
  672. HDA_CODEC_ID_MODEL(0x8086281e, "Battlemage HDMI", MODEL_ADLP),
  673. HDA_CODEC_ID_MODEL(0x8086281f, "Raptor Lake P HDMI", MODEL_ADLP),
  674. HDA_CODEC_ID_MODEL(0x80862820, "Lunar Lake HDMI", MODEL_ADLP),
  675. HDA_CODEC_ID_MODEL(0x80862822, "Panther Lake HDMI", MODEL_ADLP),
  676. HDA_CODEC_ID_MODEL(0x80862823, "Wildcat Lake HDMI", MODEL_ADLP),
  677. HDA_CODEC_ID_MODEL(0x80862824, "Nova Lake HDMI", MODEL_ADLP),
  678. HDA_CODEC_ID_MODEL(0x80862882, "Valleyview2 HDMI", MODEL_BYT),
  679. HDA_CODEC_ID_MODEL(0x80862883, "Braswell HDMI", MODEL_BYT),
  680. {} /* terminator */
  681. };
  682. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_intelhdmi);
  683. MODULE_LICENSE("GPL");
  684. MODULE_DESCRIPTION("Intel HDMI HD-audio codec");
  685. MODULE_IMPORT_NS("SND_HDA_CODEC_HDMI");
  686. static struct hda_codec_driver intelhdmi_driver = {
  687. .id = snd_hda_id_intelhdmi,
  688. .ops = &intelhdmi_codec_ops,
  689. };
  690. module_hda_codec_driver(intelhdmi_driver);