patch_hdmi.c 49 KB

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