PageRenderTime 1303ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/sound/pci/hda/patch_hdmi.c

https://github.com/Mengqi/linux-2.6
C | 1799 lines | 1291 code | 276 blank | 232 comment | 141 complexity | 73a9808dd5b86171deac09c5bc1f22d1 MD5 | raw file
  1. /*
  2. *
  3. * patch_hdmi.c - routines for HDMI/DisplayPort codecs
  4. *
  5. * Copyright(c) 2008-2010 Intel Corporation. All rights reserved.
  6. * Copyright (c) 2006 ATI Technologies Inc.
  7. * Copyright (c) 2008 NVIDIA Corp. All rights reserved.
  8. * Copyright (c) 2008 Wei Ni <wni@nvidia.com>
  9. *
  10. * Authors:
  11. * Wu Fengguang <wfg@linux.intel.com>
  12. *
  13. * Maintained by:
  14. * Wu Fengguang <wfg@linux.intel.com>
  15. *
  16. * This program is free software; you can redistribute it and/or modify it
  17. * under the terms of the GNU General Public License as published by the Free
  18. * Software Foundation; either version 2 of the License, or (at your option)
  19. * any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful, but
  22. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  23. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  24. * for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software Foundation,
  28. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  29. */
  30. #include <linux/init.h>
  31. #include <linux/delay.h>
  32. #include <linux/slab.h>
  33. #include <linux/moduleparam.h>
  34. #include <sound/core.h>
  35. #include <sound/jack.h>
  36. #include "hda_codec.h"
  37. #include "hda_local.h"
  38. static bool static_hdmi_pcm;
  39. module_param(static_hdmi_pcm, bool, 0644);
  40. MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
  41. /*
  42. * The HDMI/DisplayPort configuration can be highly dynamic. A graphics device
  43. * could support N independent pipes, each of them can be connected to one or
  44. * more ports (DVI, HDMI or DisplayPort).
  45. *
  46. * The HDA correspondence of pipes/ports are converter/pin nodes.
  47. */
  48. #define MAX_HDMI_CVTS 4
  49. #define MAX_HDMI_PINS 4
  50. struct hdmi_spec_per_cvt {
  51. hda_nid_t cvt_nid;
  52. int assigned;
  53. unsigned int channels_min;
  54. unsigned int channels_max;
  55. u32 rates;
  56. u64 formats;
  57. unsigned int maxbps;
  58. };
  59. struct hdmi_spec_per_pin {
  60. hda_nid_t pin_nid;
  61. int num_mux_nids;
  62. hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
  63. struct hdmi_eld sink_eld;
  64. };
  65. struct hdmi_spec {
  66. int num_cvts;
  67. struct hdmi_spec_per_cvt cvts[MAX_HDMI_CVTS];
  68. int num_pins;
  69. struct hdmi_spec_per_pin pins[MAX_HDMI_PINS];
  70. struct hda_pcm pcm_rec[MAX_HDMI_PINS];
  71. /*
  72. * Non-generic ATI/NVIDIA specific
  73. */
  74. struct hda_multi_out multiout;
  75. const struct hda_pcm_stream *pcm_playback;
  76. };
  77. struct hdmi_audio_infoframe {
  78. u8 type; /* 0x84 */
  79. u8 ver; /* 0x01 */
  80. u8 len; /* 0x0a */
  81. u8 checksum;
  82. u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
  83. u8 SS01_SF24;
  84. u8 CXT04;
  85. u8 CA;
  86. u8 LFEPBL01_LSV36_DM_INH7;
  87. };
  88. struct dp_audio_infoframe {
  89. u8 type; /* 0x84 */
  90. u8 len; /* 0x1b */
  91. u8 ver; /* 0x11 << 2 */
  92. u8 CC02_CT47; /* match with HDMI infoframe from this on */
  93. u8 SS01_SF24;
  94. u8 CXT04;
  95. u8 CA;
  96. u8 LFEPBL01_LSV36_DM_INH7;
  97. };
  98. union audio_infoframe {
  99. struct hdmi_audio_infoframe hdmi;
  100. struct dp_audio_infoframe dp;
  101. u8 bytes[0];
  102. };
  103. /*
  104. * CEA speaker placement:
  105. *
  106. * FLH FCH FRH
  107. * FLW FL FLC FC FRC FR FRW
  108. *
  109. * LFE
  110. * TC
  111. *
  112. * RL RLC RC RRC RR
  113. *
  114. * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
  115. * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
  116. */
  117. enum cea_speaker_placement {
  118. FL = (1 << 0), /* Front Left */
  119. FC = (1 << 1), /* Front Center */
  120. FR = (1 << 2), /* Front Right */
  121. FLC = (1 << 3), /* Front Left Center */
  122. FRC = (1 << 4), /* Front Right Center */
  123. RL = (1 << 5), /* Rear Left */
  124. RC = (1 << 6), /* Rear Center */
  125. RR = (1 << 7), /* Rear Right */
  126. RLC = (1 << 8), /* Rear Left Center */
  127. RRC = (1 << 9), /* Rear Right Center */
  128. LFE = (1 << 10), /* Low Frequency Effect */
  129. FLW = (1 << 11), /* Front Left Wide */
  130. FRW = (1 << 12), /* Front Right Wide */
  131. FLH = (1 << 13), /* Front Left High */
  132. FCH = (1 << 14), /* Front Center High */
  133. FRH = (1 << 15), /* Front Right High */
  134. TC = (1 << 16), /* Top Center */
  135. };
  136. /*
  137. * ELD SA bits in the CEA Speaker Allocation data block
  138. */
  139. static int eld_speaker_allocation_bits[] = {
  140. [0] = FL | FR,
  141. [1] = LFE,
  142. [2] = FC,
  143. [3] = RL | RR,
  144. [4] = RC,
  145. [5] = FLC | FRC,
  146. [6] = RLC | RRC,
  147. /* the following are not defined in ELD yet */
  148. [7] = FLW | FRW,
  149. [8] = FLH | FRH,
  150. [9] = TC,
  151. [10] = FCH,
  152. };
  153. struct cea_channel_speaker_allocation {
  154. int ca_index;
  155. int speakers[8];
  156. /* derived values, just for convenience */
  157. int channels;
  158. int spk_mask;
  159. };
  160. /*
  161. * ALSA sequence is:
  162. *
  163. * surround40 surround41 surround50 surround51 surround71
  164. * ch0 front left = = = =
  165. * ch1 front right = = = =
  166. * ch2 rear left = = = =
  167. * ch3 rear right = = = =
  168. * ch4 LFE center center center
  169. * ch5 LFE LFE
  170. * ch6 side left
  171. * ch7 side right
  172. *
  173. * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
  174. */
  175. static int hdmi_channel_mapping[0x32][8] = {
  176. /* stereo */
  177. [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
  178. /* 2.1 */
  179. [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
  180. /* Dolby Surround */
  181. [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
  182. /* surround40 */
  183. [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
  184. /* 4ch */
  185. [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
  186. /* surround41 */
  187. [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
  188. /* surround50 */
  189. [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
  190. /* surround51 */
  191. [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
  192. /* 7.1 */
  193. [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
  194. };
  195. /*
  196. * This is an ordered list!
  197. *
  198. * The preceding ones have better chances to be selected by
  199. * hdmi_channel_allocation().
  200. */
  201. static struct cea_channel_speaker_allocation channel_allocations[] = {
  202. /* channel: 7 6 5 4 3 2 1 0 */
  203. { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
  204. /* 2.1 */
  205. { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
  206. /* Dolby Surround */
  207. { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
  208. /* surround40 */
  209. { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
  210. /* surround41 */
  211. { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
  212. /* surround50 */
  213. { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
  214. /* surround51 */
  215. { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
  216. /* 6.1 */
  217. { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
  218. /* surround71 */
  219. { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
  220. { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
  221. { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
  222. { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
  223. { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
  224. { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
  225. { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
  226. { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
  227. { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
  228. { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
  229. { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
  230. { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
  231. { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
  232. { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
  233. { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
  234. { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
  235. { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
  236. { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
  237. { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
  238. { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
  239. { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
  240. { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
  241. { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
  242. { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
  243. { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
  244. { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
  245. { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
  246. { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
  247. { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
  248. { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
  249. { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
  250. { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
  251. { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
  252. { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
  253. { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
  254. { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
  255. { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
  256. { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
  257. { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
  258. { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
  259. { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
  260. { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
  261. };
  262. /*
  263. * HDMI routines
  264. */
  265. static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
  266. {
  267. int pin_idx;
  268. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
  269. if (spec->pins[pin_idx].pin_nid == pin_nid)
  270. return pin_idx;
  271. snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
  272. return -EINVAL;
  273. }
  274. static int hinfo_to_pin_index(struct hdmi_spec *spec,
  275. struct hda_pcm_stream *hinfo)
  276. {
  277. int pin_idx;
  278. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
  279. if (&spec->pcm_rec[pin_idx].stream[0] == hinfo)
  280. return pin_idx;
  281. snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
  282. return -EINVAL;
  283. }
  284. static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
  285. {
  286. int cvt_idx;
  287. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
  288. if (spec->cvts[cvt_idx].cvt_nid == cvt_nid)
  289. return cvt_idx;
  290. snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
  291. return -EINVAL;
  292. }
  293. #ifdef BE_PARANOID
  294. static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  295. int *packet_index, int *byte_index)
  296. {
  297. int val;
  298. val = snd_hda_codec_read(codec, pin_nid, 0,
  299. AC_VERB_GET_HDMI_DIP_INDEX, 0);
  300. *packet_index = val >> 5;
  301. *byte_index = val & 0x1f;
  302. }
  303. #endif
  304. static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  305. int packet_index, int byte_index)
  306. {
  307. int val;
  308. val = (packet_index << 5) | (byte_index & 0x1f);
  309. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
  310. }
  311. static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
  312. unsigned char val)
  313. {
  314. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
  315. }
  316. static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  317. {
  318. /* Unmute */
  319. if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
  320. snd_hda_codec_write(codec, pin_nid, 0,
  321. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  322. /* Disable pin out until stream is active*/
  323. snd_hda_codec_write(codec, pin_nid, 0,
  324. AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
  325. }
  326. static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
  327. {
  328. return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
  329. AC_VERB_GET_CVT_CHAN_COUNT, 0);
  330. }
  331. static void hdmi_set_channel_count(struct hda_codec *codec,
  332. hda_nid_t cvt_nid, int chs)
  333. {
  334. if (chs != hdmi_get_channel_count(codec, cvt_nid))
  335. snd_hda_codec_write(codec, cvt_nid, 0,
  336. AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
  337. }
  338. /*
  339. * Channel mapping routines
  340. */
  341. /*
  342. * Compute derived values in channel_allocations[].
  343. */
  344. static void init_channel_allocations(void)
  345. {
  346. int i, j;
  347. struct cea_channel_speaker_allocation *p;
  348. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  349. p = channel_allocations + i;
  350. p->channels = 0;
  351. p->spk_mask = 0;
  352. for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
  353. if (p->speakers[j]) {
  354. p->channels++;
  355. p->spk_mask |= p->speakers[j];
  356. }
  357. }
  358. }
  359. /*
  360. * The transformation takes two steps:
  361. *
  362. * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
  363. * spk_mask => (channel_allocations[]) => ai->CA
  364. *
  365. * TODO: it could select the wrong CA from multiple candidates.
  366. */
  367. static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
  368. {
  369. int i;
  370. int ca = 0;
  371. int spk_mask = 0;
  372. char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
  373. /*
  374. * CA defaults to 0 for basic stereo audio
  375. */
  376. if (channels <= 2)
  377. return 0;
  378. /*
  379. * expand ELD's speaker allocation mask
  380. *
  381. * ELD tells the speaker mask in a compact(paired) form,
  382. * expand ELD's notions to match the ones used by Audio InfoFrame.
  383. */
  384. for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
  385. if (eld->spk_alloc & (1 << i))
  386. spk_mask |= eld_speaker_allocation_bits[i];
  387. }
  388. /* search for the first working match in the CA table */
  389. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  390. if (channels == channel_allocations[i].channels &&
  391. (spk_mask & channel_allocations[i].spk_mask) ==
  392. channel_allocations[i].spk_mask) {
  393. ca = channel_allocations[i].ca_index;
  394. break;
  395. }
  396. }
  397. snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
  398. snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
  399. ca, channels, buf);
  400. return ca;
  401. }
  402. static void hdmi_debug_channel_mapping(struct hda_codec *codec,
  403. hda_nid_t pin_nid)
  404. {
  405. #ifdef CONFIG_SND_DEBUG_VERBOSE
  406. int i;
  407. int slot;
  408. for (i = 0; i < 8; i++) {
  409. slot = snd_hda_codec_read(codec, pin_nid, 0,
  410. AC_VERB_GET_HDMI_CHAN_SLOT, i);
  411. printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
  412. slot >> 4, slot & 0xf);
  413. }
  414. #endif
  415. }
  416. static void hdmi_setup_channel_mapping(struct hda_codec *codec,
  417. hda_nid_t pin_nid,
  418. int ca)
  419. {
  420. int i;
  421. int err;
  422. if (hdmi_channel_mapping[ca][1] == 0) {
  423. for (i = 0; i < channel_allocations[ca].channels; i++)
  424. hdmi_channel_mapping[ca][i] = i | (i << 4);
  425. for (; i < 8; i++)
  426. hdmi_channel_mapping[ca][i] = 0xf | (i << 4);
  427. }
  428. for (i = 0; i < 8; i++) {
  429. err = snd_hda_codec_write(codec, pin_nid, 0,
  430. AC_VERB_SET_HDMI_CHAN_SLOT,
  431. hdmi_channel_mapping[ca][i]);
  432. if (err) {
  433. snd_printdd(KERN_NOTICE
  434. "HDMI: channel mapping failed\n");
  435. break;
  436. }
  437. }
  438. hdmi_debug_channel_mapping(codec, pin_nid);
  439. }
  440. /*
  441. * Audio InfoFrame routines
  442. */
  443. /*
  444. * Enable Audio InfoFrame Transmission
  445. */
  446. static void hdmi_start_infoframe_trans(struct hda_codec *codec,
  447. hda_nid_t pin_nid)
  448. {
  449. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  450. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  451. AC_DIPXMIT_BEST);
  452. }
  453. /*
  454. * Disable Audio InfoFrame Transmission
  455. */
  456. static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
  457. hda_nid_t pin_nid)
  458. {
  459. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  460. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  461. AC_DIPXMIT_DISABLE);
  462. }
  463. static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
  464. {
  465. #ifdef CONFIG_SND_DEBUG_VERBOSE
  466. int i;
  467. int size;
  468. size = snd_hdmi_get_eld_size(codec, pin_nid);
  469. printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
  470. for (i = 0; i < 8; i++) {
  471. size = snd_hda_codec_read(codec, pin_nid, 0,
  472. AC_VERB_GET_HDMI_DIP_SIZE, i);
  473. printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
  474. }
  475. #endif
  476. }
  477. static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
  478. {
  479. #ifdef BE_PARANOID
  480. int i, j;
  481. int size;
  482. int pi, bi;
  483. for (i = 0; i < 8; i++) {
  484. size = snd_hda_codec_read(codec, pin_nid, 0,
  485. AC_VERB_GET_HDMI_DIP_SIZE, i);
  486. if (size == 0)
  487. continue;
  488. hdmi_set_dip_index(codec, pin_nid, i, 0x0);
  489. for (j = 1; j < 1000; j++) {
  490. hdmi_write_dip_byte(codec, pin_nid, 0x0);
  491. hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
  492. if (pi != i)
  493. snd_printd(KERN_INFO "dip index %d: %d != %d\n",
  494. bi, pi, i);
  495. if (bi == 0) /* byte index wrapped around */
  496. break;
  497. }
  498. snd_printd(KERN_INFO
  499. "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
  500. i, size, j);
  501. }
  502. #endif
  503. }
  504. static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
  505. {
  506. u8 *bytes = (u8 *)hdmi_ai;
  507. u8 sum = 0;
  508. int i;
  509. hdmi_ai->checksum = 0;
  510. for (i = 0; i < sizeof(*hdmi_ai); i++)
  511. sum += bytes[i];
  512. hdmi_ai->checksum = -sum;
  513. }
  514. static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
  515. hda_nid_t pin_nid,
  516. u8 *dip, int size)
  517. {
  518. int i;
  519. hdmi_debug_dip_size(codec, pin_nid);
  520. hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
  521. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  522. for (i = 0; i < size; i++)
  523. hdmi_write_dip_byte(codec, pin_nid, dip[i]);
  524. }
  525. static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
  526. u8 *dip, int size)
  527. {
  528. u8 val;
  529. int i;
  530. if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
  531. != AC_DIPXMIT_BEST)
  532. return false;
  533. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  534. for (i = 0; i < size; i++) {
  535. val = snd_hda_codec_read(codec, pin_nid, 0,
  536. AC_VERB_GET_HDMI_DIP_DATA, 0);
  537. if (val != dip[i])
  538. return false;
  539. }
  540. return true;
  541. }
  542. static void hdmi_setup_audio_infoframe(struct hda_codec *codec, int pin_idx,
  543. struct snd_pcm_substream *substream)
  544. {
  545. struct hdmi_spec *spec = codec->spec;
  546. struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
  547. hda_nid_t pin_nid = per_pin->pin_nid;
  548. int channels = substream->runtime->channels;
  549. struct hdmi_eld *eld;
  550. int ca;
  551. union audio_infoframe ai;
  552. eld = &spec->pins[pin_idx].sink_eld;
  553. if (!eld->monitor_present)
  554. return;
  555. ca = hdmi_channel_allocation(eld, channels);
  556. memset(&ai, 0, sizeof(ai));
  557. if (eld->conn_type == 0) { /* HDMI */
  558. struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
  559. hdmi_ai->type = 0x84;
  560. hdmi_ai->ver = 0x01;
  561. hdmi_ai->len = 0x0a;
  562. hdmi_ai->CC02_CT47 = channels - 1;
  563. hdmi_ai->CA = ca;
  564. hdmi_checksum_audio_infoframe(hdmi_ai);
  565. } else if (eld->conn_type == 1) { /* DisplayPort */
  566. struct dp_audio_infoframe *dp_ai = &ai.dp;
  567. dp_ai->type = 0x84;
  568. dp_ai->len = 0x1b;
  569. dp_ai->ver = 0x11 << 2;
  570. dp_ai->CC02_CT47 = channels - 1;
  571. dp_ai->CA = ca;
  572. } else {
  573. snd_printd("HDMI: unknown connection type at pin %d\n",
  574. pin_nid);
  575. return;
  576. }
  577. /*
  578. * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
  579. * sizeof(*dp_ai) to avoid partial match/update problems when
  580. * the user switches between HDMI/DP monitors.
  581. */
  582. if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
  583. sizeof(ai))) {
  584. snd_printdd("hdmi_setup_audio_infoframe: "
  585. "pin=%d channels=%d\n",
  586. pin_nid,
  587. channels);
  588. hdmi_setup_channel_mapping(codec, pin_nid, ca);
  589. hdmi_stop_infoframe_trans(codec, pin_nid);
  590. hdmi_fill_audio_infoframe(codec, pin_nid,
  591. ai.bytes, sizeof(ai));
  592. hdmi_start_infoframe_trans(codec, pin_nid);
  593. }
  594. }
  595. /*
  596. * Unsolicited events
  597. */
  598. static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
  599. struct hdmi_eld *eld);
  600. static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
  601. {
  602. struct hdmi_spec *spec = codec->spec;
  603. int pin_nid = res >> AC_UNSOL_RES_TAG_SHIFT;
  604. int pd = !!(res & AC_UNSOL_RES_PD);
  605. int eldv = !!(res & AC_UNSOL_RES_ELDV);
  606. int pin_idx;
  607. struct hdmi_eld *eld;
  608. printk(KERN_INFO
  609. "HDMI hot plug event: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
  610. codec->addr, pin_nid, pd, eldv);
  611. pin_idx = pin_nid_to_pin_index(spec, pin_nid);
  612. if (pin_idx < 0)
  613. return;
  614. eld = &spec->pins[pin_idx].sink_eld;
  615. hdmi_present_sense(codec, pin_nid, eld);
  616. /*
  617. * HDMI sink's ELD info cannot always be retrieved for now, e.g.
  618. * in console or for audio devices. Assume the highest speakers
  619. * configuration, to _not_ prohibit multi-channel audio playback.
  620. */
  621. if (!eld->spk_alloc)
  622. eld->spk_alloc = 0xffff;
  623. }
  624. static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
  625. {
  626. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  627. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  628. int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
  629. int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
  630. printk(KERN_INFO
  631. "HDMI CP event: CODEC=%d PIN=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
  632. codec->addr,
  633. tag,
  634. subtag,
  635. cp_state,
  636. cp_ready);
  637. /* TODO */
  638. if (cp_state)
  639. ;
  640. if (cp_ready)
  641. ;
  642. }
  643. static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
  644. {
  645. struct hdmi_spec *spec = codec->spec;
  646. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  647. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  648. if (pin_nid_to_pin_index(spec, tag) < 0) {
  649. snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
  650. return;
  651. }
  652. if (subtag == 0)
  653. hdmi_intrinsic_event(codec, res);
  654. else
  655. hdmi_non_intrinsic_event(codec, res);
  656. }
  657. /*
  658. * Callbacks
  659. */
  660. /* HBR should be Non-PCM, 8 channels */
  661. #define is_hbr_format(format) \
  662. ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
  663. static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  664. hda_nid_t pin_nid, u32 stream_tag, int format)
  665. {
  666. int pinctl;
  667. int new_pinctl = 0;
  668. if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
  669. pinctl = snd_hda_codec_read(codec, pin_nid, 0,
  670. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  671. new_pinctl = pinctl & ~AC_PINCTL_EPT;
  672. if (is_hbr_format(format))
  673. new_pinctl |= AC_PINCTL_EPT_HBR;
  674. else
  675. new_pinctl |= AC_PINCTL_EPT_NATIVE;
  676. snd_printdd("hdmi_setup_stream: "
  677. "NID=0x%x, %spinctl=0x%x\n",
  678. pin_nid,
  679. pinctl == new_pinctl ? "" : "new-",
  680. new_pinctl);
  681. if (pinctl != new_pinctl)
  682. snd_hda_codec_write(codec, pin_nid, 0,
  683. AC_VERB_SET_PIN_WIDGET_CONTROL,
  684. new_pinctl);
  685. }
  686. if (is_hbr_format(format) && !new_pinctl) {
  687. snd_printdd("hdmi_setup_stream: HBR is not supported\n");
  688. return -EINVAL;
  689. }
  690. snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
  691. return 0;
  692. }
  693. /*
  694. * HDA PCM callbacks
  695. */
  696. static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
  697. struct hda_codec *codec,
  698. struct snd_pcm_substream *substream)
  699. {
  700. struct hdmi_spec *spec = codec->spec;
  701. struct snd_pcm_runtime *runtime = substream->runtime;
  702. int pin_idx, cvt_idx, mux_idx = 0;
  703. struct hdmi_spec_per_pin *per_pin;
  704. struct hdmi_eld *eld;
  705. struct hdmi_spec_per_cvt *per_cvt = NULL;
  706. int pinctl;
  707. /* Validate hinfo */
  708. pin_idx = hinfo_to_pin_index(spec, hinfo);
  709. if (snd_BUG_ON(pin_idx < 0))
  710. return -EINVAL;
  711. per_pin = &spec->pins[pin_idx];
  712. eld = &per_pin->sink_eld;
  713. /* Dynamically assign converter to stream */
  714. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  715. per_cvt = &spec->cvts[cvt_idx];
  716. /* Must not already be assigned */
  717. if (per_cvt->assigned)
  718. continue;
  719. /* Must be in pin's mux's list of converters */
  720. for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
  721. if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
  722. break;
  723. /* Not in mux list */
  724. if (mux_idx == per_pin->num_mux_nids)
  725. continue;
  726. break;
  727. }
  728. /* No free converters */
  729. if (cvt_idx == spec->num_cvts)
  730. return -ENODEV;
  731. /* Claim converter */
  732. per_cvt->assigned = 1;
  733. hinfo->nid = per_cvt->cvt_nid;
  734. snd_hda_codec_write(codec, per_pin->pin_nid, 0,
  735. AC_VERB_SET_CONNECT_SEL,
  736. mux_idx);
  737. pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
  738. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  739. snd_hda_codec_write(codec, per_pin->pin_nid, 0,
  740. AC_VERB_SET_PIN_WIDGET_CONTROL,
  741. pinctl | PIN_OUT);
  742. snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
  743. /* Initially set the converter's capabilities */
  744. hinfo->channels_min = per_cvt->channels_min;
  745. hinfo->channels_max = per_cvt->channels_max;
  746. hinfo->rates = per_cvt->rates;
  747. hinfo->formats = per_cvt->formats;
  748. hinfo->maxbps = per_cvt->maxbps;
  749. /* Restrict capabilities by ELD if this isn't disabled */
  750. if (!static_hdmi_pcm && eld->eld_valid) {
  751. snd_hdmi_eld_update_pcm_info(eld, hinfo);
  752. if (hinfo->channels_min > hinfo->channels_max ||
  753. !hinfo->rates || !hinfo->formats)
  754. return -ENODEV;
  755. }
  756. /* Store the updated parameters */
  757. runtime->hw.channels_min = hinfo->channels_min;
  758. runtime->hw.channels_max = hinfo->channels_max;
  759. runtime->hw.formats = hinfo->formats;
  760. runtime->hw.rates = hinfo->rates;
  761. snd_pcm_hw_constraint_step(substream->runtime, 0,
  762. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  763. return 0;
  764. }
  765. /*
  766. * HDA/HDMI auto parsing
  767. */
  768. static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
  769. {
  770. struct hdmi_spec *spec = codec->spec;
  771. struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
  772. hda_nid_t pin_nid = per_pin->pin_nid;
  773. if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
  774. snd_printk(KERN_WARNING
  775. "HDMI: pin %d wcaps %#x "
  776. "does not support connection list\n",
  777. pin_nid, get_wcaps(codec, pin_nid));
  778. return -EINVAL;
  779. }
  780. per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
  781. per_pin->mux_nids,
  782. HDA_MAX_CONNECTIONS);
  783. return 0;
  784. }
  785. static void hdmi_present_sense(struct hda_codec *codec, hda_nid_t pin_nid,
  786. struct hdmi_eld *eld)
  787. {
  788. /*
  789. * Always execute a GetPinSense verb here, even when called from
  790. * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
  791. * response's PD bit is not the real PD value, but indicates that
  792. * the real PD value changed. An older version of the HD-audio
  793. * specification worked this way. Hence, we just ignore the data in
  794. * the unsolicited response to avoid custom WARs.
  795. */
  796. int present = snd_hda_pin_sense(codec, pin_nid);
  797. memset(eld, 0, sizeof(*eld));
  798. eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
  799. if (eld->monitor_present)
  800. eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
  801. else
  802. eld->eld_valid = 0;
  803. printk(KERN_INFO
  804. "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
  805. codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
  806. if (eld->eld_valid)
  807. if (!snd_hdmi_get_eld(eld, codec, pin_nid))
  808. snd_hdmi_show_eld(eld);
  809. snd_hda_input_jack_report(codec, pin_nid);
  810. }
  811. static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  812. {
  813. struct hdmi_spec *spec = codec->spec;
  814. unsigned int caps, config;
  815. int pin_idx;
  816. struct hdmi_spec_per_pin *per_pin;
  817. struct hdmi_eld *eld;
  818. int err;
  819. caps = snd_hda_param_read(codec, pin_nid, AC_PAR_PIN_CAP);
  820. if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
  821. return 0;
  822. config = snd_hda_codec_read(codec, pin_nid, 0,
  823. AC_VERB_GET_CONFIG_DEFAULT, 0);
  824. if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
  825. return 0;
  826. if (snd_BUG_ON(spec->num_pins >= MAX_HDMI_PINS))
  827. return -E2BIG;
  828. pin_idx = spec->num_pins;
  829. per_pin = &spec->pins[pin_idx];
  830. eld = &per_pin->sink_eld;
  831. per_pin->pin_nid = pin_nid;
  832. err = snd_hda_input_jack_add(codec, pin_nid,
  833. SND_JACK_VIDEOOUT, NULL);
  834. if (err < 0)
  835. return err;
  836. err = hdmi_read_pin_conn(codec, pin_idx);
  837. if (err < 0)
  838. return err;
  839. spec->num_pins++;
  840. hdmi_present_sense(codec, pin_nid, eld);
  841. return 0;
  842. }
  843. static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
  844. {
  845. struct hdmi_spec *spec = codec->spec;
  846. int cvt_idx;
  847. struct hdmi_spec_per_cvt *per_cvt;
  848. unsigned int chans;
  849. int err;
  850. if (snd_BUG_ON(spec->num_cvts >= MAX_HDMI_CVTS))
  851. return -E2BIG;
  852. chans = get_wcaps(codec, cvt_nid);
  853. chans = get_wcaps_channels(chans);
  854. cvt_idx = spec->num_cvts;
  855. per_cvt = &spec->cvts[cvt_idx];
  856. per_cvt->cvt_nid = cvt_nid;
  857. per_cvt->channels_min = 2;
  858. if (chans <= 16)
  859. per_cvt->channels_max = chans;
  860. err = snd_hda_query_supported_pcm(codec, cvt_nid,
  861. &per_cvt->rates,
  862. &per_cvt->formats,
  863. &per_cvt->maxbps);
  864. if (err < 0)
  865. return err;
  866. spec->num_cvts++;
  867. return 0;
  868. }
  869. static int hdmi_parse_codec(struct hda_codec *codec)
  870. {
  871. hda_nid_t nid;
  872. int i, nodes;
  873. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
  874. if (!nid || nodes < 0) {
  875. snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
  876. return -EINVAL;
  877. }
  878. for (i = 0; i < nodes; i++, nid++) {
  879. unsigned int caps;
  880. unsigned int type;
  881. caps = snd_hda_param_read(codec, nid, AC_PAR_AUDIO_WIDGET_CAP);
  882. type = get_wcaps_type(caps);
  883. if (!(caps & AC_WCAP_DIGITAL))
  884. continue;
  885. switch (type) {
  886. case AC_WID_AUD_OUT:
  887. hdmi_add_cvt(codec, nid);
  888. break;
  889. case AC_WID_PIN:
  890. hdmi_add_pin(codec, nid);
  891. break;
  892. }
  893. }
  894. /*
  895. * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
  896. * can be lost and presence sense verb will become inaccurate if the
  897. * HDA link is powered off at hot plug or hw initialization time.
  898. */
  899. #ifdef CONFIG_SND_HDA_POWER_SAVE
  900. if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
  901. AC_PWRST_EPSS))
  902. codec->bus->power_keep_link_on = 1;
  903. #endif
  904. return 0;
  905. }
  906. /*
  907. */
  908. static char *generic_hdmi_pcm_names[MAX_HDMI_PINS] = {
  909. "HDMI 0",
  910. "HDMI 1",
  911. "HDMI 2",
  912. "HDMI 3",
  913. };
  914. /*
  915. * HDMI callbacks
  916. */
  917. static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  918. struct hda_codec *codec,
  919. unsigned int stream_tag,
  920. unsigned int format,
  921. struct snd_pcm_substream *substream)
  922. {
  923. hda_nid_t cvt_nid = hinfo->nid;
  924. struct hdmi_spec *spec = codec->spec;
  925. int pin_idx = hinfo_to_pin_index(spec, hinfo);
  926. hda_nid_t pin_nid = spec->pins[pin_idx].pin_nid;
  927. hdmi_set_channel_count(codec, cvt_nid, substream->runtime->channels);
  928. hdmi_setup_audio_infoframe(codec, pin_idx, substream);
  929. return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
  930. }
  931. static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  932. struct hda_codec *codec,
  933. struct snd_pcm_substream *substream)
  934. {
  935. struct hdmi_spec *spec = codec->spec;
  936. int cvt_idx, pin_idx;
  937. struct hdmi_spec_per_cvt *per_cvt;
  938. struct hdmi_spec_per_pin *per_pin;
  939. int pinctl;
  940. snd_hda_codec_cleanup_stream(codec, hinfo->nid);
  941. if (hinfo->nid) {
  942. cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
  943. if (snd_BUG_ON(cvt_idx < 0))
  944. return -EINVAL;
  945. per_cvt = &spec->cvts[cvt_idx];
  946. snd_BUG_ON(!per_cvt->assigned);
  947. per_cvt->assigned = 0;
  948. hinfo->nid = 0;
  949. pin_idx = hinfo_to_pin_index(spec, hinfo);
  950. if (snd_BUG_ON(pin_idx < 0))
  951. return -EINVAL;
  952. per_pin = &spec->pins[pin_idx];
  953. pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
  954. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  955. snd_hda_codec_write(codec, per_pin->pin_nid, 0,
  956. AC_VERB_SET_PIN_WIDGET_CONTROL,
  957. pinctl & ~PIN_OUT);
  958. snd_hda_spdif_ctls_unassign(codec, pin_idx);
  959. }
  960. return 0;
  961. }
  962. static const struct hda_pcm_ops generic_ops = {
  963. .open = hdmi_pcm_open,
  964. .prepare = generic_hdmi_playback_pcm_prepare,
  965. .cleanup = generic_hdmi_playback_pcm_cleanup,
  966. };
  967. static int generic_hdmi_build_pcms(struct hda_codec *codec)
  968. {
  969. struct hdmi_spec *spec = codec->spec;
  970. int pin_idx;
  971. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  972. struct hda_pcm *info;
  973. struct hda_pcm_stream *pstr;
  974. info = &spec->pcm_rec[pin_idx];
  975. info->name = generic_hdmi_pcm_names[pin_idx];
  976. info->pcm_type = HDA_PCM_TYPE_HDMI;
  977. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  978. pstr->substreams = 1;
  979. pstr->ops = generic_ops;
  980. /* other pstr fields are set in open */
  981. }
  982. codec->num_pcms = spec->num_pins;
  983. codec->pcm_info = spec->pcm_rec;
  984. return 0;
  985. }
  986. static int generic_hdmi_build_controls(struct hda_codec *codec)
  987. {
  988. struct hdmi_spec *spec = codec->spec;
  989. int err;
  990. int pin_idx;
  991. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  992. struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
  993. err = snd_hda_create_spdif_out_ctls(codec,
  994. per_pin->pin_nid,
  995. per_pin->mux_nids[0]);
  996. if (err < 0)
  997. return err;
  998. snd_hda_spdif_ctls_unassign(codec, pin_idx);
  999. }
  1000. return 0;
  1001. }
  1002. static int generic_hdmi_init(struct hda_codec *codec)
  1003. {
  1004. struct hdmi_spec *spec = codec->spec;
  1005. int pin_idx;
  1006. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1007. struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
  1008. hda_nid_t pin_nid = per_pin->pin_nid;
  1009. struct hdmi_eld *eld = &per_pin->sink_eld;
  1010. hdmi_init_pin(codec, pin_nid);
  1011. snd_hda_codec_write(codec, pin_nid, 0,
  1012. AC_VERB_SET_UNSOLICITED_ENABLE,
  1013. AC_USRSP_EN | pin_nid);
  1014. snd_hda_eld_proc_new(codec, eld, pin_idx);
  1015. }
  1016. return 0;
  1017. }
  1018. static void generic_hdmi_free(struct hda_codec *codec)
  1019. {
  1020. struct hdmi_spec *spec = codec->spec;
  1021. int pin_idx;
  1022. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1023. struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
  1024. struct hdmi_eld *eld = &per_pin->sink_eld;
  1025. snd_hda_eld_proc_free(codec, eld);
  1026. }
  1027. snd_hda_input_jack_free(codec);
  1028. kfree(spec);
  1029. }
  1030. static const struct hda_codec_ops generic_hdmi_patch_ops = {
  1031. .init = generic_hdmi_init,
  1032. .free = generic_hdmi_free,
  1033. .build_pcms = generic_hdmi_build_pcms,
  1034. .build_controls = generic_hdmi_build_controls,
  1035. .unsol_event = hdmi_unsol_event,
  1036. };
  1037. static int patch_generic_hdmi(struct hda_codec *codec)
  1038. {
  1039. struct hdmi_spec *spec;
  1040. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1041. if (spec == NULL)
  1042. return -ENOMEM;
  1043. codec->spec = spec;
  1044. if (hdmi_parse_codec(codec) < 0) {
  1045. codec->spec = NULL;
  1046. kfree(spec);
  1047. return -EINVAL;
  1048. }
  1049. codec->patch_ops = generic_hdmi_patch_ops;
  1050. init_channel_allocations();
  1051. return 0;
  1052. }
  1053. /*
  1054. * Shared non-generic implementations
  1055. */
  1056. static int simple_playback_build_pcms(struct hda_codec *codec)
  1057. {
  1058. struct hdmi_spec *spec = codec->spec;
  1059. struct hda_pcm *info = spec->pcm_rec;
  1060. int i;
  1061. codec->num_pcms = spec->num_cvts;
  1062. codec->pcm_info = info;
  1063. for (i = 0; i < codec->num_pcms; i++, info++) {
  1064. unsigned int chans;
  1065. struct hda_pcm_stream *pstr;
  1066. chans = get_wcaps(codec, spec->cvts[i].cvt_nid);
  1067. chans = get_wcaps_channels(chans);
  1068. info->name = generic_hdmi_pcm_names[i];
  1069. info->pcm_type = HDA_PCM_TYPE_HDMI;
  1070. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  1071. snd_BUG_ON(!spec->pcm_playback);
  1072. *pstr = *spec->pcm_playback;
  1073. pstr->nid = spec->cvts[i].cvt_nid;
  1074. if (pstr->channels_max <= 2 && chans && chans <= 16)
  1075. pstr->channels_max = chans;
  1076. }
  1077. return 0;
  1078. }
  1079. static int simple_playback_build_controls(struct hda_codec *codec)
  1080. {
  1081. struct hdmi_spec *spec = codec->spec;
  1082. int err;
  1083. int i;
  1084. for (i = 0; i < codec->num_pcms; i++) {
  1085. err = snd_hda_create_spdif_out_ctls(codec,
  1086. spec->cvts[i].cvt_nid,
  1087. spec->cvts[i].cvt_nid);
  1088. if (err < 0)
  1089. return err;
  1090. }
  1091. return 0;
  1092. }
  1093. static void simple_playback_free(struct hda_codec *codec)
  1094. {
  1095. struct hdmi_spec *spec = codec->spec;
  1096. kfree(spec);
  1097. }
  1098. /*
  1099. * Nvidia specific implementations
  1100. */
  1101. #define Nv_VERB_SET_Channel_Allocation 0xF79
  1102. #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
  1103. #define Nv_VERB_SET_Audio_Protection_On 0xF98
  1104. #define Nv_VERB_SET_Audio_Protection_Off 0xF99
  1105. #define nvhdmi_master_con_nid_7x 0x04
  1106. #define nvhdmi_master_pin_nid_7x 0x05
  1107. static const hda_nid_t nvhdmi_con_nids_7x[4] = {
  1108. /*front, rear, clfe, rear_surr */
  1109. 0x6, 0x8, 0xa, 0xc,
  1110. };
  1111. static const struct hda_verb nvhdmi_basic_init_7x[] = {
  1112. /* set audio protect on */
  1113. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  1114. /* enable digital output on pin widget */
  1115. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1116. { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1117. { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1118. { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1119. { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1120. {} /* terminator */
  1121. };
  1122. #ifdef LIMITED_RATE_FMT_SUPPORT
  1123. /* support only the safe format and rate */
  1124. #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
  1125. #define SUPPORTED_MAXBPS 16
  1126. #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  1127. #else
  1128. /* support all rates and formats */
  1129. #define SUPPORTED_RATES \
  1130. (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
  1131. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
  1132. SNDRV_PCM_RATE_192000)
  1133. #define SUPPORTED_MAXBPS 24
  1134. #define SUPPORTED_FORMATS \
  1135. (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1136. #endif
  1137. static int nvhdmi_7x_init(struct hda_codec *codec)
  1138. {
  1139. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x);
  1140. return 0;
  1141. }
  1142. static unsigned int channels_2_6_8[] = {
  1143. 2, 6, 8
  1144. };
  1145. static unsigned int channels_2_8[] = {
  1146. 2, 8
  1147. };
  1148. static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
  1149. .count = ARRAY_SIZE(channels_2_6_8),
  1150. .list = channels_2_6_8,
  1151. .mask = 0,
  1152. };
  1153. static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
  1154. .count = ARRAY_SIZE(channels_2_8),
  1155. .list = channels_2_8,
  1156. .mask = 0,
  1157. };
  1158. static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1159. struct hda_codec *codec,
  1160. struct snd_pcm_substream *substream)
  1161. {
  1162. struct hdmi_spec *spec = codec->spec;
  1163. struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
  1164. switch (codec->preset->id) {
  1165. case 0x10de0002:
  1166. case 0x10de0003:
  1167. case 0x10de0005:
  1168. case 0x10de0006:
  1169. hw_constraints_channels = &hw_constraints_2_8_channels;
  1170. break;
  1171. case 0x10de0007:
  1172. hw_constraints_channels = &hw_constraints_2_6_8_channels;
  1173. break;
  1174. default:
  1175. break;
  1176. }
  1177. if (hw_constraints_channels != NULL) {
  1178. snd_pcm_hw_constraint_list(substream->runtime, 0,
  1179. SNDRV_PCM_HW_PARAM_CHANNELS,
  1180. hw_constraints_channels);
  1181. } else {
  1182. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1183. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1184. }
  1185. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1186. }
  1187. static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1188. struct hda_codec *codec,
  1189. struct snd_pcm_substream *substream)
  1190. {
  1191. struct hdmi_spec *spec = codec->spec;
  1192. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1193. }
  1194. static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1195. struct hda_codec *codec,
  1196. unsigned int stream_tag,
  1197. unsigned int format,
  1198. struct snd_pcm_substream *substream)
  1199. {
  1200. struct hdmi_spec *spec = codec->spec;
  1201. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1202. stream_tag, format, substream);
  1203. }
  1204. static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
  1205. int channels)
  1206. {
  1207. unsigned int chanmask;
  1208. int chan = channels ? (channels - 1) : 1;
  1209. switch (channels) {
  1210. default:
  1211. case 0:
  1212. case 2:
  1213. chanmask = 0x00;
  1214. break;
  1215. case 4:
  1216. chanmask = 0x08;
  1217. break;
  1218. case 6:
  1219. chanmask = 0x0b;
  1220. break;
  1221. case 8:
  1222. chanmask = 0x13;
  1223. break;
  1224. }
  1225. /* Set the audio infoframe channel allocation and checksum fields. The
  1226. * channel count is computed implicitly by the hardware. */
  1227. snd_hda_codec_write(codec, 0x1, 0,
  1228. Nv_VERB_SET_Channel_Allocation, chanmask);
  1229. snd_hda_codec_write(codec, 0x1, 0,
  1230. Nv_VERB_SET_Info_Frame_Checksum,
  1231. (0x71 - chan - chanmask));
  1232. }
  1233. static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
  1234. struct hda_codec *codec,
  1235. struct snd_pcm_substream *substream)
  1236. {
  1237. struct hdmi_spec *spec = codec->spec;
  1238. int i;
  1239. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
  1240. 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
  1241. for (i = 0; i < 4; i++) {
  1242. /* set the stream id */
  1243. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  1244. AC_VERB_SET_CHANNEL_STREAMID, 0);
  1245. /* set the stream format */
  1246. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  1247. AC_VERB_SET_STREAM_FORMAT, 0);
  1248. }
  1249. /* The audio hardware sends a channel count of 0x7 (8ch) when all the
  1250. * streams are disabled. */
  1251. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  1252. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1253. }
  1254. static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
  1255. struct hda_codec *codec,
  1256. unsigned int stream_tag,
  1257. unsigned int format,
  1258. struct snd_pcm_substream *substream)
  1259. {
  1260. int chs;
  1261. unsigned int dataDCC1, dataDCC2, channel_id;
  1262. int i;
  1263. struct hdmi_spec *spec = codec->spec;
  1264. struct hda_spdif_out *spdif =
  1265. snd_hda_spdif_out_of_nid(codec, spec->cvts[0].cvt_nid);
  1266. mutex_lock(&codec->spdif_mutex);
  1267. chs = substream->runtime->channels;
  1268. dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
  1269. dataDCC2 = 0x2;
  1270. /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
  1271. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
  1272. snd_hda_codec_write(codec,
  1273. nvhdmi_master_con_nid_7x,
  1274. 0,
  1275. AC_VERB_SET_DIGI_CONVERT_1,
  1276. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  1277. /* set the stream id */
  1278. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  1279. AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
  1280. /* set the stream format */
  1281. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  1282. AC_VERB_SET_STREAM_FORMAT, format);
  1283. /* turn on again (if needed) */
  1284. /* enable and set the channel status audio/data flag */
  1285. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
  1286. snd_hda_codec_write(codec,
  1287. nvhdmi_master_con_nid_7x,
  1288. 0,
  1289. AC_VERB_SET_DIGI_CONVERT_1,
  1290. spdif->ctls & 0xff);
  1291. snd_hda_codec_write(codec,
  1292. nvhdmi_master_con_nid_7x,
  1293. 0,
  1294. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  1295. }
  1296. for (i = 0; i < 4; i++) {
  1297. if (chs == 2)
  1298. channel_id = 0;
  1299. else
  1300. channel_id = i * 2;
  1301. /* turn off SPDIF once;
  1302. *otherwise the IEC958 bits won't be updated
  1303. */
  1304. if (codec->spdif_status_reset &&
  1305. (spdif->ctls & AC_DIG1_ENABLE))
  1306. snd_hda_codec_write(codec,
  1307. nvhdmi_con_nids_7x[i],
  1308. 0,
  1309. AC_VERB_SET_DIGI_CONVERT_1,
  1310. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  1311. /* set the stream id */
  1312. snd_hda_codec_write(codec,
  1313. nvhdmi_con_nids_7x[i],
  1314. 0,
  1315. AC_VERB_SET_CHANNEL_STREAMID,
  1316. (stream_tag << 4) | channel_id);
  1317. /* set the stream format */
  1318. snd_hda_codec_write(codec,
  1319. nvhdmi_con_nids_7x[i],
  1320. 0,
  1321. AC_VERB_SET_STREAM_FORMAT,
  1322. format);
  1323. /* turn on again (if needed) */
  1324. /* enable and set the channel status audio/data flag */
  1325. if (codec->spdif_status_reset &&
  1326. (spdif->ctls & AC_DIG1_ENABLE)) {
  1327. snd_hda_codec_write(codec,
  1328. nvhdmi_con_nids_7x[i],
  1329. 0,
  1330. AC_VERB_SET_DIGI_CONVERT_1,
  1331. spdif->ctls & 0xff);
  1332. snd_hda_codec_write(codec,
  1333. nvhdmi_con_nids_7x[i],
  1334. 0,
  1335. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  1336. }
  1337. }
  1338. nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
  1339. mutex_unlock(&codec->spdif_mutex);
  1340. return 0;
  1341. }
  1342. static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
  1343. .substreams = 1,
  1344. .channels_min = 2,
  1345. .channels_max = 8,
  1346. .nid = nvhdmi_master_con_nid_7x,
  1347. .rates = SUPPORTED_RATES,
  1348. .maxbps = SUPPORTED_MAXBPS,
  1349. .formats = SUPPORTED_FORMATS,
  1350. .ops = {
  1351. .open = simple_playback_pcm_open,
  1352. .close = nvhdmi_8ch_7x_pcm_close,
  1353. .prepare = nvhdmi_8ch_7x_pcm_prepare
  1354. },
  1355. };
  1356. static const struct hda_pcm_stream nvhdmi_pcm_playback_2ch = {
  1357. .substreams = 1,
  1358. .channels_min = 2,
  1359. .channels_max = 2,
  1360. .nid = nvhdmi_master_con_nid_7x,
  1361. .rates = SUPPORTED_RATES,
  1362. .maxbps = SUPPORTED_MAXBPS,
  1363. .formats = SUPPORTED_FORMATS,
  1364. .ops = {
  1365. .open = simple_playback_pcm_open,
  1366. .close = simple_playback_pcm_close,
  1367. .prepare = simple_playback_pcm_prepare
  1368. },
  1369. };
  1370. static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
  1371. .build_controls = simple_playback_build_controls,
  1372. .build_pcms = simple_playback_build_pcms,
  1373. .init = nvhdmi_7x_init,
  1374. .free = simple_playback_free,
  1375. };
  1376. static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
  1377. .build_controls = simple_playback_build_controls,
  1378. .build_pcms = simple_playback_build_pcms,
  1379. .init = nvhdmi_7x_init,
  1380. .free = simple_playback_free,
  1381. };
  1382. static int patch_nvhdmi_2ch(struct hda_codec *codec)
  1383. {
  1384. struct hdmi_spec *spec;
  1385. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1386. if (spec == NULL)
  1387. return -ENOMEM;
  1388. codec->spec = spec;
  1389. spec->multiout.num_dacs = 0; /* no analog */
  1390. spec->multiout.max_channels = 2;
  1391. spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x;
  1392. spec->num_cvts = 1;
  1393. spec->cvts[0].cvt_nid = nvhdmi_master_con_nid_7x;
  1394. spec->pcm_playback = &nvhdmi_pcm_playback_2ch;
  1395. codec->patch_ops = nvhdmi_patch_ops_2ch;
  1396. return 0;
  1397. }
  1398. static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
  1399. {
  1400. struct hdmi_spec *spec;
  1401. int err = patch_nvhdmi_2ch(codec);
  1402. if (err < 0)
  1403. return err;
  1404. spec = codec->spec;
  1405. spec->multiout.max_channels = 8;
  1406. spec->pcm_playback = &nvhdmi_pcm_playback_8ch_7x;
  1407. codec->patch_ops = nvhdmi_patch_ops_8ch_7x;
  1408. /* Initialize the audio infoframe channel mask and checksum to something
  1409. * valid */
  1410. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  1411. return 0;
  1412. }
  1413. /*
  1414. * ATI-specific implementations
  1415. *
  1416. * FIXME: we may omit the whole this and use the generic code once after
  1417. * it's confirmed to work.
  1418. */
  1419. #define ATIHDMI_CVT_NID 0x02 /* audio converter */
  1420. #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
  1421. static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1422. struct hda_codec *codec,
  1423. unsigned int stream_tag,
  1424. unsigned int format,
  1425. struct snd_pcm_substream *substream)
  1426. {
  1427. struct hdmi_spec *spec = codec->spec;
  1428. int chans = substream->runtime->channels;
  1429. int i, err;
  1430. err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
  1431. substream);
  1432. if (err < 0)
  1433. return err;
  1434. snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
  1435. AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
  1436. /* FIXME: XXX */
  1437. for (i = 0; i < chans; i++) {
  1438. snd_hda_codec_write(codec, spec->cvts[0].cvt_nid, 0,
  1439. AC_VERB_SET_HDMI_CHAN_SLOT,
  1440. (i << 4) | i);
  1441. }
  1442. return 0;
  1443. }
  1444. static const struct hda_pcm_stream atihdmi_pcm_digital_playback = {
  1445. .substreams = 1,
  1446. .channels_min = 2,
  1447. .channels_max = 2,
  1448. .nid = ATIHDMI_CVT_NID,
  1449. .ops = {
  1450. .open = simple_playback_pcm_open,
  1451. .close = simple_playback_pcm_close,
  1452. .prepare = atihdmi_playback_pcm_prepare
  1453. },
  1454. };
  1455. static const struct hda_verb atihdmi_basic_init[] = {
  1456. /* enable digital output on pin widget */
  1457. { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1458. {} /* terminator */
  1459. };
  1460. static int atihdmi_init(struct hda_codec *codec)
  1461. {
  1462. struct hdmi_spec *spec = codec->spec;
  1463. snd_hda_sequence_write(codec, atihdmi_basic_init);
  1464. /* SI codec requires to unmute the pin */
  1465. if (get_wcaps(codec, spec->pins[0].pin_nid) & AC_WCAP_OUT_AMP)
  1466. snd_hda_codec_write(codec, spec->pins[0].pin_nid, 0,
  1467. AC_VERB_SET_AMP_GAIN_MUTE,
  1468. AMP_OUT_UNMUTE);
  1469. return 0;
  1470. }
  1471. static const struct hda_codec_ops atihdmi_patch_ops = {
  1472. .build_controls = simple_playback_build_controls,
  1473. .build_pcms = simple_playback_build_pcms,
  1474. .init = atihdmi_init,
  1475. .free = simple_playback_free,
  1476. };
  1477. static int patch_atihdmi(struct hda_codec *codec)
  1478. {
  1479. struct hdmi_spec *spec;
  1480. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1481. if (spec == NULL)
  1482. return -ENOMEM;
  1483. codec->spec = spec;
  1484. spec->multiout.num_dacs = 0; /* no analog */
  1485. spec->multiout.max_channels = 2;
  1486. spec->multiout.dig_out_nid = ATIHDMI_CVT_NID;
  1487. spec->num_cvts = 1;
  1488. spec->cvts[0].cvt_nid = ATIHDMI_CVT_NID;
  1489. spec->pins[0].pin_nid = ATIHDMI_PIN_NID;
  1490. spec->pcm_playback = &atihdmi_pcm_digital_playback;
  1491. codec->patch_ops = atihdmi_patch_ops;
  1492. return 0;
  1493. }
  1494. /*
  1495. * patch entries
  1496. */
  1497. static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
  1498. { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
  1499. { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
  1500. { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
  1501. { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
  1502. { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
  1503. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
  1504. { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
  1505. { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1506. { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1507. { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1508. { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1509. { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
  1510. { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
  1511. { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
  1512. { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
  1513. { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
  1514. { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
  1515. { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
  1516. { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
  1517. { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
  1518. { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
  1519. { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
  1520. { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
  1521. /* 17 is known to be absent */
  1522. { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
  1523. { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generi