patch_hdmi.c 50 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806
  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. /* Initially set the converter's capabilities */
  707. hinfo->channels_min = codec_pars->channels_min;
  708. hinfo->channels_max = codec_pars->channels_max;
  709. hinfo->rates = codec_pars->rates;
  710. hinfo->formats = codec_pars->formats;
  711. hinfo->maxbps = codec_pars->maxbps;
  712. eld = &spec->sink_eld[idx];
  713. if (!static_hdmi_pcm && eld->eld_valid) {
  714. snd_hdmi_eld_update_pcm_info(eld, hinfo);
  715. if (hinfo->channels_min > hinfo->channels_max ||
  716. !hinfo->rates || !hinfo->formats)
  717. return -ENODEV;
  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. spec->cvt[i]);
  938. if (err < 0)
  939. return err;
  940. }
  941. return 0;
  942. }
  943. static int generic_hdmi_init(struct hda_codec *codec)
  944. {
  945. struct hdmi_spec *spec = codec->spec;
  946. int i;
  947. for (i = 0; spec->pin[i]; i++) {
  948. hdmi_enable_output(codec, spec->pin[i]);
  949. snd_hda_codec_write(codec, spec->pin[i], 0,
  950. AC_VERB_SET_UNSOLICITED_ENABLE,
  951. AC_USRSP_EN | spec->pin[i]);
  952. }
  953. return 0;
  954. }
  955. static void generic_hdmi_free(struct hda_codec *codec)
  956. {
  957. struct hdmi_spec *spec = codec->spec;
  958. int i;
  959. for (i = 0; i < spec->num_pins; i++)
  960. snd_hda_eld_proc_free(codec, &spec->sink_eld[i]);
  961. snd_hda_input_jack_free(codec);
  962. kfree(spec);
  963. }
  964. static const struct hda_codec_ops generic_hdmi_patch_ops = {
  965. .init = generic_hdmi_init,
  966. .free = generic_hdmi_free,
  967. .build_pcms = generic_hdmi_build_pcms,
  968. .build_controls = generic_hdmi_build_controls,
  969. .unsol_event = hdmi_unsol_event,
  970. };
  971. static int patch_generic_hdmi(struct hda_codec *codec)
  972. {
  973. struct hdmi_spec *spec;
  974. int i;
  975. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  976. if (spec == NULL)
  977. return -ENOMEM;
  978. codec->spec = spec;
  979. if (hdmi_parse_codec(codec) < 0) {
  980. codec->spec = NULL;
  981. kfree(spec);
  982. return -EINVAL;
  983. }
  984. codec->patch_ops = generic_hdmi_patch_ops;
  985. for (i = 0; i < spec->num_pins; i++)
  986. snd_hda_eld_proc_new(codec, &spec->sink_eld[i], i);
  987. init_channel_allocations();
  988. return 0;
  989. }
  990. /*
  991. * Shared non-generic implementations
  992. */
  993. static int simple_playback_build_pcms(struct hda_codec *codec)
  994. {
  995. struct hdmi_spec *spec = codec->spec;
  996. struct hda_pcm *info = spec->pcm_rec;
  997. int i;
  998. codec->num_pcms = spec->num_cvts;
  999. codec->pcm_info = info;
  1000. for (i = 0; i < codec->num_pcms; i++, info++) {
  1001. unsigned int chans;
  1002. struct hda_pcm_stream *pstr;
  1003. chans = get_wcaps(codec, spec->cvt[i]);
  1004. chans = get_wcaps_channels(chans);
  1005. info->name = generic_hdmi_pcm_names[i];
  1006. info->pcm_type = HDA_PCM_TYPE_HDMI;
  1007. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  1008. snd_BUG_ON(!spec->pcm_playback);
  1009. *pstr = *spec->pcm_playback;
  1010. pstr->nid = spec->cvt[i];
  1011. if (pstr->channels_max <= 2 && chans && chans <= 16)
  1012. pstr->channels_max = chans;
  1013. }
  1014. return 0;
  1015. }
  1016. static int simple_playback_build_controls(struct hda_codec *codec)
  1017. {
  1018. struct hdmi_spec *spec = codec->spec;
  1019. int err;
  1020. int i;
  1021. for (i = 0; i < codec->num_pcms; i++) {
  1022. err = snd_hda_create_spdif_out_ctls(codec,
  1023. spec->cvt[i],
  1024. spec->cvt[i]);
  1025. if (err < 0)
  1026. return err;
  1027. }
  1028. return 0;
  1029. }
  1030. static void simple_playback_free(struct hda_codec *codec)
  1031. {
  1032. struct hdmi_spec *spec = codec->spec;
  1033. kfree(spec);
  1034. }
  1035. /*
  1036. * Nvidia specific implementations
  1037. */
  1038. #define Nv_VERB_SET_Channel_Allocation 0xF79
  1039. #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
  1040. #define Nv_VERB_SET_Audio_Protection_On 0xF98
  1041. #define Nv_VERB_SET_Audio_Protection_Off 0xF99
  1042. #define nvhdmi_master_con_nid_7x 0x04
  1043. #define nvhdmi_master_pin_nid_7x 0x05
  1044. static const hda_nid_t nvhdmi_con_nids_7x[4] = {
  1045. /*front, rear, clfe, rear_surr */
  1046. 0x6, 0x8, 0xa, 0xc,
  1047. };
  1048. static const struct hda_verb nvhdmi_basic_init_7x[] = {
  1049. /* set audio protect on */
  1050. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  1051. /* enable digital output on pin widget */
  1052. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1053. { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1054. { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1055. { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1056. { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1057. {} /* terminator */
  1058. };
  1059. #ifdef LIMITED_RATE_FMT_SUPPORT
  1060. /* support only the safe format and rate */
  1061. #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
  1062. #define SUPPORTED_MAXBPS 16
  1063. #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  1064. #else
  1065. /* support all rates and formats */
  1066. #define SUPPORTED_RATES \
  1067. (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
  1068. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
  1069. SNDRV_PCM_RATE_192000)
  1070. #define SUPPORTED_MAXBPS 24
  1071. #define SUPPORTED_FORMATS \
  1072. (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1073. #endif
  1074. static int nvhdmi_7x_init(struct hda_codec *codec)
  1075. {
  1076. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x);
  1077. return 0;
  1078. }
  1079. static unsigned int channels_2_6_8[] = {
  1080. 2, 6, 8
  1081. };
  1082. static unsigned int channels_2_8[] = {
  1083. 2, 8
  1084. };
  1085. static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
  1086. .count = ARRAY_SIZE(channels_2_6_8),
  1087. .list = channels_2_6_8,
  1088. .mask = 0,
  1089. };
  1090. static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
  1091. .count = ARRAY_SIZE(channels_2_8),
  1092. .list = channels_2_8,
  1093. .mask = 0,
  1094. };
  1095. static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1096. struct hda_codec *codec,
  1097. struct snd_pcm_substream *substream)
  1098. {
  1099. struct hdmi_spec *spec = codec->spec;
  1100. struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
  1101. switch (codec->preset->id) {
  1102. case 0x10de0002:
  1103. case 0x10de0003:
  1104. case 0x10de0005:
  1105. case 0x10de0006:
  1106. hw_constraints_channels = &hw_constraints_2_8_channels;
  1107. break;
  1108. case 0x10de0007:
  1109. hw_constraints_channels = &hw_constraints_2_6_8_channels;
  1110. break;
  1111. default:
  1112. break;
  1113. }
  1114. if (hw_constraints_channels != NULL) {
  1115. snd_pcm_hw_constraint_list(substream->runtime, 0,
  1116. SNDRV_PCM_HW_PARAM_CHANNELS,
  1117. hw_constraints_channels);
  1118. } else {
  1119. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1120. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1121. }
  1122. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1123. }
  1124. static int simple_playback_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. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1130. }
  1131. static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1132. struct hda_codec *codec,
  1133. unsigned int stream_tag,
  1134. unsigned int format,
  1135. struct snd_pcm_substream *substream)
  1136. {
  1137. struct hdmi_spec *spec = codec->spec;
  1138. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1139. stream_tag, format, substream);
  1140. }
  1141. static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
  1142. int channels)
  1143. {
  1144. unsigned int chanmask;
  1145. int chan = channels ? (channels - 1) : 1;
  1146. switch (channels) {
  1147. default:
  1148. case 0:
  1149. case 2:
  1150. chanmask = 0x00;
  1151. break;
  1152. case 4:
  1153. chanmask = 0x08;
  1154. break;
  1155. case 6:
  1156. chanmask = 0x0b;
  1157. break;
  1158. case 8:
  1159. chanmask = 0x13;
  1160. break;
  1161. }
  1162. /* Set the audio infoframe channel allocation and checksum fields. The
  1163. * channel count is computed implicitly by the hardware. */
  1164. snd_hda_codec_write(codec, 0x1, 0,
  1165. Nv_VERB_SET_Channel_Allocation, chanmask);
  1166. snd_hda_codec_write(codec, 0x1, 0,
  1167. Nv_VERB_SET_Info_Frame_Checksum,
  1168. (0x71 - chan - chanmask));
  1169. }
  1170. static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
  1171. struct hda_codec *codec,
  1172. struct snd_pcm_substream *substream)
  1173. {
  1174. struct hdmi_spec *spec = codec->spec;
  1175. int i;
  1176. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
  1177. 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
  1178. for (i = 0; i < 4; i++) {
  1179. /* set the stream id */
  1180. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  1181. AC_VERB_SET_CHANNEL_STREAMID, 0);
  1182. /* set the stream format */
  1183. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  1184. AC_VERB_SET_STREAM_FORMAT, 0);
  1185. }
  1186. /* The audio hardware sends a channel count of 0x7 (8ch) when all the
  1187. * streams are disabled. */
  1188. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  1189. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1190. }
  1191. static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
  1192. struct hda_codec *codec,
  1193. unsigned int stream_tag,
  1194. unsigned int format,
  1195. struct snd_pcm_substream *substream)
  1196. {
  1197. int chs;
  1198. unsigned int dataDCC1, dataDCC2, channel_id;
  1199. int i;
  1200. struct hdmi_spec *spec = codec->spec;
  1201. struct hda_spdif_out *spdif =
  1202. snd_hda_spdif_out_of_nid(codec, spec->cvt[0]);
  1203. mutex_lock(&codec->spdif_mutex);
  1204. chs = substream->runtime->channels;
  1205. dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
  1206. dataDCC2 = 0x2;
  1207. /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
  1208. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
  1209. snd_hda_codec_write(codec,
  1210. nvhdmi_master_con_nid_7x,
  1211. 0,
  1212. AC_VERB_SET_DIGI_CONVERT_1,
  1213. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  1214. /* set the stream id */
  1215. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  1216. AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
  1217. /* set the stream format */
  1218. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  1219. AC_VERB_SET_STREAM_FORMAT, format);
  1220. /* turn on again (if needed) */
  1221. /* enable and set the channel status audio/data flag */
  1222. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
  1223. snd_hda_codec_write(codec,
  1224. nvhdmi_master_con_nid_7x,
  1225. 0,
  1226. AC_VERB_SET_DIGI_CONVERT_1,
  1227. spdif->ctls & 0xff);
  1228. snd_hda_codec_write(codec,
  1229. nvhdmi_master_con_nid_7x,
  1230. 0,
  1231. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  1232. }
  1233. for (i = 0; i < 4; i++) {
  1234. if (chs == 2)
  1235. channel_id = 0;
  1236. else
  1237. channel_id = i * 2;
  1238. /* turn off SPDIF once;
  1239. *otherwise the IEC958 bits won't be updated
  1240. */
  1241. if (codec->spdif_status_reset &&
  1242. (spdif->ctls & AC_DIG1_ENABLE))
  1243. snd_hda_codec_write(codec,
  1244. nvhdmi_con_nids_7x[i],
  1245. 0,
  1246. AC_VERB_SET_DIGI_CONVERT_1,
  1247. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  1248. /* set the stream id */
  1249. snd_hda_codec_write(codec,
  1250. nvhdmi_con_nids_7x[i],
  1251. 0,
  1252. AC_VERB_SET_CHANNEL_STREAMID,
  1253. (stream_tag << 4) | channel_id);
  1254. /* set the stream format */
  1255. snd_hda_codec_write(codec,
  1256. nvhdmi_con_nids_7x[i],
  1257. 0,
  1258. AC_VERB_SET_STREAM_FORMAT,
  1259. format);
  1260. /* turn on again (if needed) */
  1261. /* enable and set the channel status audio/data flag */
  1262. if (codec->spdif_status_reset &&
  1263. (spdif->ctls & AC_DIG1_ENABLE)) {
  1264. snd_hda_codec_write(codec,
  1265. nvhdmi_con_nids_7x[i],
  1266. 0,
  1267. AC_VERB_SET_DIGI_CONVERT_1,
  1268. spdif->ctls & 0xff);
  1269. snd_hda_codec_write(codec,
  1270. nvhdmi_con_nids_7x[i],
  1271. 0,
  1272. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  1273. }
  1274. }
  1275. nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
  1276. mutex_unlock(&codec->spdif_mutex);
  1277. return 0;
  1278. }
  1279. static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
  1280. .substreams = 1,
  1281. .channels_min = 2,
  1282. .channels_max = 8,
  1283. .nid = nvhdmi_master_con_nid_7x,
  1284. .rates = SUPPORTED_RATES,
  1285. .maxbps = SUPPORTED_MAXBPS,
  1286. .formats = SUPPORTED_FORMATS,
  1287. .ops = {
  1288. .open = simple_playback_pcm_open,
  1289. .close = nvhdmi_8ch_7x_pcm_close,
  1290. .prepare = nvhdmi_8ch_7x_pcm_prepare
  1291. },
  1292. };
  1293. static const struct hda_pcm_stream nvhdmi_pcm_playback_2ch = {
  1294. .substreams = 1,
  1295. .channels_min = 2,
  1296. .channels_max = 2,
  1297. .nid = nvhdmi_master_con_nid_7x,
  1298. .rates = SUPPORTED_RATES,
  1299. .maxbps = SUPPORTED_MAXBPS,
  1300. .formats = SUPPORTED_FORMATS,
  1301. .ops = {
  1302. .open = simple_playback_pcm_open,
  1303. .close = simple_playback_pcm_close,
  1304. .prepare = simple_playback_pcm_prepare
  1305. },
  1306. };
  1307. static const struct hda_codec_ops nvhdmi_patch_ops_8ch_7x = {
  1308. .build_controls = simple_playback_build_controls,
  1309. .build_pcms = simple_playback_build_pcms,
  1310. .init = nvhdmi_7x_init,
  1311. .free = simple_playback_free,
  1312. };
  1313. static const struct hda_codec_ops nvhdmi_patch_ops_2ch = {
  1314. .build_controls = simple_playback_build_controls,
  1315. .build_pcms = simple_playback_build_pcms,
  1316. .init = nvhdmi_7x_init,
  1317. .free = simple_playback_free,
  1318. };
  1319. static int patch_nvhdmi_2ch(struct hda_codec *codec)
  1320. {
  1321. struct hdmi_spec *spec;
  1322. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1323. if (spec == NULL)
  1324. return -ENOMEM;
  1325. codec->spec = spec;
  1326. spec->multiout.num_dacs = 0; /* no analog */
  1327. spec->multiout.max_channels = 2;
  1328. spec->multiout.dig_out_nid = nvhdmi_master_con_nid_7x;
  1329. spec->num_cvts = 1;
  1330. spec->cvt[0] = nvhdmi_master_con_nid_7x;
  1331. spec->pcm_playback = &nvhdmi_pcm_playback_2ch;
  1332. codec->patch_ops = nvhdmi_patch_ops_2ch;
  1333. return 0;
  1334. }
  1335. static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
  1336. {
  1337. struct hdmi_spec *spec;
  1338. int err = patch_nvhdmi_2ch(codec);
  1339. if (err < 0)
  1340. return err;
  1341. spec = codec->spec;
  1342. spec->multiout.max_channels = 8;
  1343. spec->pcm_playback = &nvhdmi_pcm_playback_8ch_7x;
  1344. codec->patch_ops = nvhdmi_patch_ops_8ch_7x;
  1345. /* Initialize the audio infoframe channel mask and checksum to something
  1346. * valid */
  1347. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  1348. return 0;
  1349. }
  1350. /*
  1351. * ATI-specific implementations
  1352. *
  1353. * FIXME: we may omit the whole this and use the generic code once after
  1354. * it's confirmed to work.
  1355. */
  1356. #define ATIHDMI_CVT_NID 0x02 /* audio converter */
  1357. #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
  1358. static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1359. struct hda_codec *codec,
  1360. unsigned int stream_tag,
  1361. unsigned int format,
  1362. struct snd_pcm_substream *substream)
  1363. {
  1364. struct hdmi_spec *spec = codec->spec;
  1365. int chans = substream->runtime->channels;
  1366. int i, err;
  1367. err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
  1368. substream);
  1369. if (err < 0)
  1370. return err;
  1371. snd_hda_codec_write(codec, spec->cvt[0], 0, AC_VERB_SET_CVT_CHAN_COUNT,
  1372. chans - 1);
  1373. /* FIXME: XXX */
  1374. for (i = 0; i < chans; i++) {
  1375. snd_hda_codec_write(codec, spec->cvt[0], 0,
  1376. AC_VERB_SET_HDMI_CHAN_SLOT,
  1377. (i << 4) | i);
  1378. }
  1379. return 0;
  1380. }
  1381. static const struct hda_pcm_stream atihdmi_pcm_digital_playback = {
  1382. .substreams = 1,
  1383. .channels_min = 2,
  1384. .channels_max = 2,
  1385. .nid = ATIHDMI_CVT_NID,
  1386. .ops = {
  1387. .open = simple_playback_pcm_open,
  1388. .close = simple_playback_pcm_close,
  1389. .prepare = atihdmi_playback_pcm_prepare
  1390. },
  1391. };
  1392. static const struct hda_verb atihdmi_basic_init[] = {
  1393. /* enable digital output on pin widget */
  1394. { 0x03, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
  1395. {} /* terminator */
  1396. };
  1397. static int atihdmi_init(struct hda_codec *codec)
  1398. {
  1399. struct hdmi_spec *spec = codec->spec;
  1400. snd_hda_sequence_write(codec, atihdmi_basic_init);
  1401. /* SI codec requires to unmute the pin */
  1402. if (get_wcaps(codec, spec->pin[0]) & AC_WCAP_OUT_AMP)
  1403. snd_hda_codec_write(codec, spec->pin[0], 0,
  1404. AC_VERB_SET_AMP_GAIN_MUTE,
  1405. AMP_OUT_UNMUTE);
  1406. return 0;
  1407. }
  1408. static const struct hda_codec_ops atihdmi_patch_ops = {
  1409. .build_controls = simple_playback_build_controls,
  1410. .build_pcms = simple_playback_build_pcms,
  1411. .init = atihdmi_init,
  1412. .free = simple_playback_free,
  1413. };
  1414. static int patch_atihdmi(struct hda_codec *codec)
  1415. {
  1416. struct hdmi_spec *spec;
  1417. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1418. if (spec == NULL)
  1419. return -ENOMEM;
  1420. codec->spec = spec;
  1421. spec->multiout.num_dacs = 0; /* no analog */
  1422. spec->multiout.max_channels = 2;
  1423. spec->multiout.dig_out_nid = ATIHDMI_CVT_NID;
  1424. spec->num_cvts = 1;
  1425. spec->cvt[0] = ATIHDMI_CVT_NID;
  1426. spec->pin[0] = ATIHDMI_PIN_NID;
  1427. spec->pcm_playback = &atihdmi_pcm_digital_playback;
  1428. codec->patch_ops = atihdmi_patch_ops;
  1429. return 0;
  1430. }
  1431. /*
  1432. * patch entries
  1433. */
  1434. static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
  1435. { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
  1436. { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
  1437. { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
  1438. { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
  1439. { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
  1440. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
  1441. { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
  1442. { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1443. { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1444. { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1445. { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  1446. { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
  1447. { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
  1448. { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
  1449. { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
  1450. { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
  1451. { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
  1452. { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
  1453. { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
  1454. { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
  1455. { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
  1456. { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
  1457. { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
  1458. /* 17 is known to be absent */
  1459. { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
  1460. { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
  1461. { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
  1462. { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
  1463. { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
  1464. { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
  1465. { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
  1466. { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
  1467. { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
  1468. { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
  1469. { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
  1470. { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
  1471. { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
  1472. { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
  1473. { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
  1474. { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
  1475. { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
  1476. { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
  1477. { .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
  1478. { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
  1479. {} /* terminator */
  1480. };
  1481. MODULE_ALIAS("snd-hda-codec-id:1002793c");
  1482. MODULE_ALIAS("snd-hda-codec-id:10027919");
  1483. MODULE_ALIAS("snd-hda-codec-id:1002791a");
  1484. MODULE_ALIAS("snd-hda-codec-id:1002aa01");
  1485. MODULE_ALIAS("snd-hda-codec-id:10951390");
  1486. MODULE_ALIAS("snd-hda-codec-id:10951392");
  1487. MODULE_ALIAS("snd-hda-codec-id:10de0002");
  1488. MODULE_ALIAS("snd-hda-codec-id:10de0003");
  1489. MODULE_ALIAS("snd-hda-codec-id:10de0005");
  1490. MODULE_ALIAS("snd-hda-codec-id:10de0006");
  1491. MODULE_ALIAS("snd-hda-codec-id:10de0007");
  1492. MODULE_ALIAS("snd-hda-codec-id:10de000a");
  1493. MODULE_ALIAS("snd-hda-codec-id:10de000b");
  1494. MODULE_ALIAS("snd-hda-codec-id:10de000c");
  1495. MODULE_ALIAS("snd-hda-codec-id:10de000d");
  1496. MODULE_ALIAS("snd-hda-codec-id:10de0010");
  1497. MODULE_ALIAS("snd-hda-codec-id:10de0011");
  1498. MODULE_ALIAS("snd-hda-codec-id:10de0012");
  1499. MODULE_ALIAS("snd-hda-codec-id:10de0013");
  1500. MODULE_ALIAS("snd-hda-codec-id:10de0014");
  1501. MODULE_ALIAS("snd-hda-codec-id:10de0015");
  1502. MODULE_ALIAS("snd-hda-codec-id:10de0016");
  1503. MODULE_ALIAS("snd-hda-codec-id:10de0018");
  1504. MODULE_ALIAS("snd-hda-codec-id:10de0019");
  1505. MODULE_ALIAS("snd-hda-codec-id:10de001a");
  1506. MODULE_ALIAS("snd-hda-codec-id:10de001b");
  1507. MODULE_ALIAS("snd-hda-codec-id:10de001c");
  1508. MODULE_ALIAS("snd-hda-codec-id:10de0040");
  1509. MODULE_ALIAS("snd-hda-codec-id:10de0041");
  1510. MODULE_ALIAS("snd-hda-codec-id:10de0042");
  1511. MODULE_ALIAS("snd-hda-codec-id:10de0043");
  1512. MODULE_ALIAS("snd-hda-codec-id:10de0044");
  1513. MODULE_ALIAS("snd-hda-codec-id:10de0067");
  1514. MODULE_ALIAS("snd-hda-codec-id:10de8001");
  1515. MODULE_ALIAS("snd-hda-codec-id:17e80047");
  1516. MODULE_ALIAS("snd-hda-codec-id:80860054");
  1517. MODULE_ALIAS("snd-hda-codec-id:80862801");
  1518. MODULE_ALIAS("snd-hda-codec-id:80862802");
  1519. MODULE_ALIAS("snd-hda-codec-id:80862803");
  1520. MODULE_ALIAS("snd-hda-codec-id:80862804");
  1521. MODULE_ALIAS("snd-hda-codec-id:80862805");
  1522. MODULE_ALIAS("snd-hda-codec-id:80862806");
  1523. MODULE_ALIAS("snd-hda-codec-id:808629fb");
  1524. MODULE_LICENSE("GPL");
  1525. MODULE_DESCRIPTION("HDMI HD-audio codec");
  1526. MODULE_ALIAS("snd-hda-codec-intelhdmi");
  1527. MODULE_ALIAS("snd-hda-codec-nvhdmi");
  1528. MODULE_ALIAS("snd-hda-codec-atihdmi");
  1529. static struct hda_codec_preset_list intel_list = {
  1530. .preset = snd_hda_preset_hdmi,
  1531. .owner = THIS_MODULE,
  1532. };
  1533. static int __init patch_hdmi_init(void)
  1534. {
  1535. return snd_hda_add_codec_preset(&intel_list);
  1536. }
  1537. static void __exit patch_hdmi_exit(void)
  1538. {
  1539. snd_hda_delete_codec_preset(&intel_list);
  1540. }
  1541. module_init(patch_hdmi_init)
  1542. module_exit(patch_hdmi_exit)