patch_intelhdmi.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. /*
  2. *
  3. * patch_intelhdmi.c - Patch for Intel HDMI codecs
  4. *
  5. * Copyright(c) 2008 Intel Corporation. All rights reserved.
  6. *
  7. * Authors:
  8. * Jiang Zhe <zhe.jiang@intel.com>
  9. * Wu Fengguang <wfg@linux.intel.com>
  10. *
  11. * Maintained by:
  12. * Wu Fengguang <wfg@linux.intel.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify it
  15. * under the terms of the GNU General Public License as published by the Free
  16. * Software Foundation; either version 2 of the License, or (at your option)
  17. * any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful, but
  20. * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  21. * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  22. * for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software Foundation,
  26. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  27. */
  28. #include <linux/init.h>
  29. #include <linux/delay.h>
  30. #include <linux/slab.h>
  31. #include <sound/core.h>
  32. #include "hda_codec.h"
  33. #include "hda_local.h"
  34. #include "hda_patch.h"
  35. #define CVT_NID 0x02 /* audio converter */
  36. #define PIN_NID 0x03 /* HDMI output pin */
  37. #define INTEL_HDMI_EVENT_TAG 0x08
  38. struct intel_hdmi_spec {
  39. struct hda_multi_out multiout;
  40. struct hda_pcm pcm_rec;
  41. struct sink_eld sink;
  42. };
  43. static struct hda_verb pinout_enable_verb[] = {
  44. {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
  45. {} /* terminator */
  46. };
  47. static struct hda_verb pinout_disable_verb[] = {
  48. {PIN_NID, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00},
  49. {}
  50. };
  51. static struct hda_verb unsolicited_response_verb[] = {
  52. {PIN_NID, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN |
  53. INTEL_HDMI_EVENT_TAG},
  54. {}
  55. };
  56. static struct hda_verb def_chan_map[] = {
  57. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x00},
  58. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x11},
  59. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x22},
  60. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x33},
  61. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x44},
  62. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x55},
  63. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x66},
  64. {CVT_NID, AC_VERB_SET_HDMI_CHAN_SLOT, 0x77},
  65. {}
  66. };
  67. struct hdmi_audio_infoframe {
  68. u8 type; /* 0x84 */
  69. u8 ver; /* 0x01 */
  70. u8 len; /* 0x0a */
  71. u8 checksum; /* PB0 */
  72. u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
  73. u8 SS01_SF24;
  74. u8 CXT04;
  75. u8 CA;
  76. u8 LFEPBL01_LSV36_DM_INH7;
  77. u8 reserved[5]; /* PB6 - PB10 */
  78. };
  79. /*
  80. * CEA speaker placement:
  81. *
  82. * FLH FCH FRH
  83. * FLW FL FLC FC FRC FR FRW
  84. *
  85. * LFE
  86. * TC
  87. *
  88. * RL RLC RC RRC RR
  89. *
  90. * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
  91. * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
  92. */
  93. enum cea_speaker_placement {
  94. FL = (1 << 0), /* Front Left */
  95. FC = (1 << 1), /* Front Center */
  96. FR = (1 << 2), /* Front Right */
  97. FLC = (1 << 3), /* Front Left Center */
  98. FRC = (1 << 4), /* Front Right Center */
  99. RL = (1 << 5), /* Rear Left */
  100. RC = (1 << 6), /* Rear Center */
  101. RR = (1 << 7), /* Rear Right */
  102. RLC = (1 << 8), /* Rear Left Center */
  103. RRC = (1 << 9), /* Rear Right Center */
  104. LFE = (1 << 10), /* Low Frequency Effect */
  105. FLW = (1 << 11), /* Front Left Wide */
  106. FRW = (1 << 12), /* Front Right Wide */
  107. FLH = (1 << 13), /* Front Left High */
  108. FCH = (1 << 14), /* Front Center High */
  109. FRH = (1 << 15), /* Front Right High */
  110. TC = (1 << 16), /* Top Center */
  111. };
  112. /*
  113. * ELD SA bits in the CEA Speaker Allocation data block
  114. */
  115. static int eld_speaker_allocation_bits[] = {
  116. [0] = FL | FR,
  117. [1] = LFE,
  118. [2] = FC,
  119. [3] = RL | RR,
  120. [4] = RC,
  121. [5] = FLC | FRC,
  122. [6] = RLC | RRC,
  123. /* the following are not defined in ELD yet */
  124. [7] = FLW | FRW,
  125. [8] = FLH | FRH,
  126. [9] = TC,
  127. [10] = FCH,
  128. };
  129. struct cea_channel_speaker_allocation {
  130. int ca_index;
  131. int speakers[8];
  132. /* derived values, just for convenience */
  133. int channels;
  134. int spk_mask;
  135. };
  136. /*
  137. * This is an ordered list!
  138. *
  139. * The preceding ones have better chances to be selected by
  140. * hdmi_setup_channel_allocation().
  141. */
  142. static struct cea_channel_speaker_allocation channel_allocations[] = {
  143. /* channel: 8 7 6 5 4 3 2 1 */
  144. { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
  145. /* 2.1 */
  146. { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
  147. /* dolby surround */
  148. { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
  149. { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
  150. { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
  151. { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
  152. { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
  153. { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
  154. { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
  155. { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
  156. { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
  157. /* 5.1 */
  158. { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
  159. { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
  160. { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
  161. { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
  162. /* 6.1 */
  163. { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
  164. { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
  165. { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
  166. { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
  167. /* 7.1 */
  168. { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
  169. { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
  170. { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
  171. { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
  172. { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
  173. { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
  174. { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
  175. { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
  176. { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
  177. { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
  178. { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
  179. { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
  180. { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
  181. { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
  182. { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
  183. { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
  184. { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
  185. { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
  186. { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
  187. { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
  188. { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
  189. { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
  190. { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
  191. { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
  192. { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
  193. { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
  194. { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
  195. { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
  196. { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
  197. { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
  198. { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
  199. };
  200. /*
  201. * HDMI routines
  202. */
  203. #ifdef BE_PARANOID
  204. static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t nid,
  205. int *packet_index, int *byte_index)
  206. {
  207. int val;
  208. val = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_HDMI_DIP_INDEX, 0);
  209. *packet_index = val >> 5;
  210. *byte_index = val & 0x1f;
  211. }
  212. #endif
  213. static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t nid,
  214. int packet_index, int byte_index)
  215. {
  216. int val;
  217. val = (packet_index << 5) | (byte_index & 0x1f);
  218. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
  219. }
  220. static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t nid,
  221. unsigned char val)
  222. {
  223. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
  224. }
  225. static void hdmi_enable_output(struct hda_codec *codec)
  226. {
  227. /* Enable Audio InfoFrame Transmission */
  228. hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
  229. snd_hda_codec_write(codec, PIN_NID, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  230. AC_DIPXMIT_BEST);
  231. /* Unmute */
  232. if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
  233. snd_hda_codec_write(codec, PIN_NID, 0,
  234. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  235. /* Enable pin out */
  236. snd_hda_sequence_write(codec, pinout_enable_verb);
  237. }
  238. static void hdmi_disable_output(struct hda_codec *codec)
  239. {
  240. snd_hda_sequence_write(codec, pinout_disable_verb);
  241. if (get_wcaps(codec, PIN_NID) & AC_WCAP_OUT_AMP)
  242. snd_hda_codec_write(codec, PIN_NID, 0,
  243. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE);
  244. /*
  245. * FIXME: noises may arise when playing music after reloading the
  246. * kernel module, until the next X restart or monitor repower.
  247. */
  248. }
  249. static int hdmi_get_channel_count(struct hda_codec *codec)
  250. {
  251. return 1 + snd_hda_codec_read(codec, CVT_NID, 0,
  252. AC_VERB_GET_CVT_CHAN_COUNT, 0);
  253. }
  254. static void hdmi_set_channel_count(struct hda_codec *codec, int chs)
  255. {
  256. snd_hda_codec_write(codec, CVT_NID, 0,
  257. AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
  258. if (chs != hdmi_get_channel_count(codec))
  259. snd_printd(KERN_INFO "Channel count expect=%d, real=%d\n",
  260. chs, hdmi_get_channel_count(codec));
  261. }
  262. static void hdmi_debug_channel_mapping(struct hda_codec *codec)
  263. {
  264. #ifdef CONFIG_SND_DEBUG_VERBOSE
  265. int i;
  266. int slot;
  267. for (i = 0; i < 8; i++) {
  268. slot = snd_hda_codec_read(codec, CVT_NID, 0,
  269. AC_VERB_GET_HDMI_CHAN_SLOT, i);
  270. printk(KERN_DEBUG "ASP channel %d => slot %d\n",
  271. slot >> 4, slot & 0x7);
  272. }
  273. #endif
  274. }
  275. static void hdmi_parse_eld(struct hda_codec *codec)
  276. {
  277. struct intel_hdmi_spec *spec = codec->spec;
  278. struct sink_eld *eld = &spec->sink;
  279. if (!snd_hdmi_get_eld(eld, codec, PIN_NID))
  280. snd_hdmi_show_eld(eld);
  281. }
  282. /*
  283. * Audio Infoframe routines
  284. */
  285. static void hdmi_debug_dip_size(struct hda_codec *codec)
  286. {
  287. #ifdef CONFIG_SND_DEBUG_VERBOSE
  288. int i;
  289. int size;
  290. size = snd_hdmi_get_eld_size(codec, PIN_NID);
  291. printk(KERN_DEBUG "ELD buf size is %d\n", size);
  292. for (i = 0; i < 8; i++) {
  293. size = snd_hda_codec_read(codec, PIN_NID, 0,
  294. AC_VERB_GET_HDMI_DIP_SIZE, i);
  295. printk(KERN_DEBUG "DIP GP[%d] buf size is %d\n", i, size);
  296. }
  297. #endif
  298. }
  299. static void hdmi_clear_dip_buffers(struct hda_codec *codec)
  300. {
  301. #ifdef BE_PARANOID
  302. int i, j;
  303. int size;
  304. int pi, bi;
  305. for (i = 0; i < 8; i++) {
  306. size = snd_hda_codec_read(codec, PIN_NID, 0,
  307. AC_VERB_GET_HDMI_DIP_SIZE, i);
  308. if (size == 0)
  309. continue;
  310. hdmi_set_dip_index(codec, PIN_NID, i, 0x0);
  311. for (j = 1; j < 1000; j++) {
  312. hdmi_write_dip_byte(codec, PIN_NID, 0x0);
  313. hdmi_get_dip_index(codec, PIN_NID, &pi, &bi);
  314. if (pi != i)
  315. snd_printd(KERN_INFO "dip index %d: %d != %d\n",
  316. bi, pi, i);
  317. if (bi == 0) /* byte index wrapped around */
  318. break;
  319. }
  320. snd_printd(KERN_INFO
  321. "DIP GP[%d] buf reported size=%d, written=%d\n",
  322. i, size, j);
  323. }
  324. #endif
  325. }
  326. static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
  327. struct hdmi_audio_infoframe *ai)
  328. {
  329. u8 *params = (u8 *)ai;
  330. int i;
  331. hdmi_debug_dip_size(codec);
  332. hdmi_clear_dip_buffers(codec); /* be paranoid */
  333. hdmi_set_dip_index(codec, PIN_NID, 0x0, 0x0);
  334. for (i = 0; i < sizeof(ai); i++)
  335. hdmi_write_dip_byte(codec, PIN_NID, params[i]);
  336. }
  337. /*
  338. * Compute derived values in channel_allocations[].
  339. */
  340. static void init_channel_allocations(void)
  341. {
  342. int i, j;
  343. struct cea_channel_speaker_allocation *p;
  344. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  345. p = channel_allocations + i;
  346. p->channels = 0;
  347. p->spk_mask = 0;
  348. for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
  349. if (p->speakers[j]) {
  350. p->channels++;
  351. p->spk_mask |= p->speakers[j];
  352. }
  353. }
  354. }
  355. /*
  356. * The transformation takes two steps:
  357. *
  358. * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
  359. * spk_mask => (channel_allocations[]) => ai->CA
  360. *
  361. * TODO: it could select the wrong CA from multiple candidates.
  362. */
  363. static int hdmi_setup_channel_allocation(struct hda_codec *codec,
  364. struct hdmi_audio_infoframe *ai)
  365. {
  366. struct intel_hdmi_spec *spec = codec->spec;
  367. struct sink_eld *eld = &spec->sink;
  368. int i;
  369. int spk_mask = 0;
  370. int channels = 1 + (ai->CC02_CT47 & 0x7);
  371. char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
  372. /*
  373. * CA defaults to 0 for basic stereo audio
  374. */
  375. if (!eld->eld_ver)
  376. return 0;
  377. if (!eld->spk_alloc)
  378. return 0;
  379. if (channels <= 2)
  380. return 0;
  381. /*
  382. * expand ELD's speaker allocation mask
  383. *
  384. * ELD tells the speaker mask in a compact(paired) form,
  385. * expand ELD's notions to match the ones used by audio infoframe.
  386. */
  387. for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
  388. if (eld->spk_alloc & (1 << i))
  389. spk_mask |= eld_speaker_allocation_bits[i];
  390. }
  391. /* search for the first working match in the CA table */
  392. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  393. if (channels == channel_allocations[i].channels &&
  394. (spk_mask & channel_allocations[i].spk_mask) ==
  395. channel_allocations[i].spk_mask) {
  396. ai->CA = channel_allocations[i].ca_index;
  397. return 0;
  398. }
  399. }
  400. snd_print_channel_allocation(eld->spk_alloc, buf, sizeof(buf));
  401. snd_printd(KERN_INFO "failed to setup channel allocation: %d of %s\n",
  402. channels, buf);
  403. return -1;
  404. }
  405. static void hdmi_setup_channel_mapping(struct hda_codec *codec,
  406. struct hdmi_audio_infoframe *ai)
  407. {
  408. if (!ai->CA)
  409. return;
  410. /*
  411. * TODO: adjust channel mapping if necessary
  412. * ALSA sequence is front/surr/clfe/side?
  413. */
  414. snd_hda_sequence_write(codec, def_chan_map);
  415. hdmi_debug_channel_mapping(codec);
  416. }
  417. static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
  418. struct snd_pcm_substream *substream)
  419. {
  420. struct hdmi_audio_infoframe ai = {
  421. .type = 0x84,
  422. .ver = 0x01,
  423. .len = 0x0a,
  424. .CC02_CT47 = substream->runtime->channels - 1,
  425. };
  426. hdmi_setup_channel_allocation(codec, &ai);
  427. hdmi_setup_channel_mapping(codec, &ai);
  428. hdmi_fill_audio_infoframe(codec, &ai);
  429. }
  430. /*
  431. * Unsolicited events
  432. */
  433. static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
  434. {
  435. int pind = !!(res & AC_UNSOL_RES_PD);
  436. int eldv = !!(res & AC_UNSOL_RES_ELDV);
  437. printk(KERN_INFO "HDMI intrinsic event: PD=%d ELDV=%d\n", pind, eldv);
  438. if (pind && eldv) {
  439. hdmi_parse_eld(codec);
  440. /* TODO: do real things about ELD */
  441. }
  442. }
  443. static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
  444. {
  445. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  446. int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
  447. int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
  448. printk(KERN_INFO "HDMI non-intrinsic event: "
  449. "SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
  450. subtag,
  451. cp_state,
  452. cp_ready);
  453. /* who cares? */
  454. if (cp_state)
  455. ;
  456. if (cp_ready)
  457. ;
  458. }
  459. static void intel_hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
  460. {
  461. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  462. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  463. if (tag != INTEL_HDMI_EVENT_TAG) {
  464. snd_printd(KERN_INFO
  465. "Unexpected HDMI unsolicited event tag 0x%x\n",
  466. tag);
  467. return;
  468. }
  469. if (subtag == 0)
  470. hdmi_intrinsic_event(codec, res);
  471. else
  472. hdmi_non_intrinsic_event(codec, res);
  473. }
  474. /*
  475. * Callbacks
  476. */
  477. static int intel_hdmi_playback_pcm_open(struct hda_pcm_stream *hinfo,
  478. struct hda_codec *codec,
  479. struct snd_pcm_substream *substream)
  480. {
  481. struct intel_hdmi_spec *spec = codec->spec;
  482. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  483. }
  484. static int intel_hdmi_playback_pcm_close(struct hda_pcm_stream *hinfo,
  485. struct hda_codec *codec,
  486. struct snd_pcm_substream *substream)
  487. {
  488. struct intel_hdmi_spec *spec = codec->spec;
  489. hdmi_disable_output(codec);
  490. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  491. }
  492. static int intel_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  493. struct hda_codec *codec,
  494. unsigned int stream_tag,
  495. unsigned int format,
  496. struct snd_pcm_substream *substream)
  497. {
  498. struct intel_hdmi_spec *spec = codec->spec;
  499. snd_hda_multi_out_dig_prepare(codec, &spec->multiout, stream_tag,
  500. format, substream);
  501. hdmi_set_channel_count(codec, substream->runtime->channels);
  502. hdmi_setup_audio_infoframe(codec, substream);
  503. hdmi_enable_output(codec);
  504. return 0;
  505. }
  506. static struct hda_pcm_stream intel_hdmi_pcm_playback = {
  507. .substreams = 1,
  508. .channels_min = 2,
  509. .channels_max = 8,
  510. .nid = CVT_NID, /* NID to query formats and rates and setup streams */
  511. .ops = {
  512. .open = intel_hdmi_playback_pcm_open,
  513. .close = intel_hdmi_playback_pcm_close,
  514. .prepare = intel_hdmi_playback_pcm_prepare
  515. },
  516. };
  517. static int intel_hdmi_build_pcms(struct hda_codec *codec)
  518. {
  519. struct intel_hdmi_spec *spec = codec->spec;
  520. struct hda_pcm *info = &spec->pcm_rec;
  521. codec->num_pcms = 1;
  522. codec->pcm_info = info;
  523. info->name = "INTEL HDMI";
  524. info->pcm_type = HDA_PCM_TYPE_HDMI;
  525. info->stream[SNDRV_PCM_STREAM_PLAYBACK] = intel_hdmi_pcm_playback;
  526. return 0;
  527. }
  528. static int intel_hdmi_build_controls(struct hda_codec *codec)
  529. {
  530. struct intel_hdmi_spec *spec = codec->spec;
  531. int err;
  532. err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
  533. if (err < 0)
  534. return err;
  535. return 0;
  536. }
  537. static int intel_hdmi_init(struct hda_codec *codec)
  538. {
  539. /* disable audio output as early as possible */
  540. hdmi_disable_output(codec);
  541. snd_hda_sequence_write(codec, unsolicited_response_verb);
  542. return 0;
  543. }
  544. static void intel_hdmi_free(struct hda_codec *codec)
  545. {
  546. kfree(codec->spec);
  547. }
  548. static struct hda_codec_ops intel_hdmi_patch_ops = {
  549. .init = intel_hdmi_init,
  550. .free = intel_hdmi_free,
  551. .build_pcms = intel_hdmi_build_pcms,
  552. .build_controls = intel_hdmi_build_controls,
  553. .unsol_event = intel_hdmi_unsol_event,
  554. };
  555. static int patch_intel_hdmi(struct hda_codec *codec)
  556. {
  557. struct intel_hdmi_spec *spec;
  558. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  559. if (spec == NULL)
  560. return -ENOMEM;
  561. spec->multiout.num_dacs = 0; /* no analog */
  562. spec->multiout.max_channels = 8;
  563. spec->multiout.dig_out_nid = CVT_NID;
  564. codec->spec = spec;
  565. codec->patch_ops = intel_hdmi_patch_ops;
  566. snd_hda_eld_proc_new(codec, &spec->sink);
  567. init_channel_allocations();
  568. return 0;
  569. }
  570. struct hda_codec_preset snd_hda_preset_intelhdmi[] = {
  571. { .id = 0x808629fb, .name = "INTEL G45 DEVCL", .patch = patch_intel_hdmi },
  572. { .id = 0x80862801, .name = "INTEL G45 DEVBLC", .patch = patch_intel_hdmi },
  573. { .id = 0x80862802, .name = "INTEL G45 DEVCTG", .patch = patch_intel_hdmi },
  574. { .id = 0x80862803, .name = "INTEL G45 DEVELK", .patch = patch_intel_hdmi },
  575. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_intel_hdmi },
  576. {} /* terminator */
  577. };