patch_hdmi.c 77 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769
  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/module.h>
  34. #include <sound/core.h>
  35. #include <sound/jack.h>
  36. #include <sound/asoundef.h>
  37. #include <sound/tlv.h>
  38. #include "hda_codec.h"
  39. #include "hda_local.h"
  40. #include "hda_jack.h"
  41. static bool static_hdmi_pcm;
  42. module_param(static_hdmi_pcm, bool, 0644);
  43. MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
  44. #define is_haswell(codec) ((codec)->vendor_id == 0x80862807)
  45. struct hdmi_spec_per_cvt {
  46. hda_nid_t cvt_nid;
  47. int assigned;
  48. unsigned int channels_min;
  49. unsigned int channels_max;
  50. u32 rates;
  51. u64 formats;
  52. unsigned int maxbps;
  53. };
  54. /* max. connections to a widget */
  55. #define HDA_MAX_CONNECTIONS 32
  56. struct hdmi_spec_per_pin {
  57. hda_nid_t pin_nid;
  58. int num_mux_nids;
  59. hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
  60. hda_nid_t cvt_nid;
  61. struct hda_codec *codec;
  62. struct hdmi_eld sink_eld;
  63. struct delayed_work work;
  64. struct snd_kcontrol *eld_ctl;
  65. int repoll_count;
  66. bool setup; /* the stream has been set up by prepare callback */
  67. int channels; /* current number of channels */
  68. bool non_pcm;
  69. bool chmap_set; /* channel-map override by ALSA API? */
  70. unsigned char chmap[8]; /* ALSA API channel-map */
  71. char pcm_name[8]; /* filled in build_pcm callbacks */
  72. };
  73. struct hdmi_spec {
  74. int num_cvts;
  75. struct snd_array cvts; /* struct hdmi_spec_per_cvt */
  76. hda_nid_t cvt_nids[4]; /* only for haswell fix */
  77. int num_pins;
  78. struct snd_array pins; /* struct hdmi_spec_per_pin */
  79. struct snd_array pcm_rec; /* struct hda_pcm */
  80. unsigned int channels_max; /* max over all cvts */
  81. struct hdmi_eld temp_eld;
  82. /*
  83. * Non-generic ATI/NVIDIA specific
  84. */
  85. struct hda_multi_out multiout;
  86. struct hda_pcm_stream pcm_playback;
  87. };
  88. struct hdmi_audio_infoframe {
  89. u8 type; /* 0x84 */
  90. u8 ver; /* 0x01 */
  91. u8 len; /* 0x0a */
  92. u8 checksum;
  93. u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
  94. u8 SS01_SF24;
  95. u8 CXT04;
  96. u8 CA;
  97. u8 LFEPBL01_LSV36_DM_INH7;
  98. };
  99. struct dp_audio_infoframe {
  100. u8 type; /* 0x84 */
  101. u8 len; /* 0x1b */
  102. u8 ver; /* 0x11 << 2 */
  103. u8 CC02_CT47; /* match with HDMI infoframe from this on */
  104. u8 SS01_SF24;
  105. u8 CXT04;
  106. u8 CA;
  107. u8 LFEPBL01_LSV36_DM_INH7;
  108. };
  109. union audio_infoframe {
  110. struct hdmi_audio_infoframe hdmi;
  111. struct dp_audio_infoframe dp;
  112. u8 bytes[0];
  113. };
  114. /*
  115. * CEA speaker placement:
  116. *
  117. * FLH FCH FRH
  118. * FLW FL FLC FC FRC FR FRW
  119. *
  120. * LFE
  121. * TC
  122. *
  123. * RL RLC RC RRC RR
  124. *
  125. * The Left/Right Surround channel _notions_ LS/RS in SMPTE 320M corresponds to
  126. * CEA RL/RR; The SMPTE channel _assignment_ C/LFE is swapped to CEA LFE/FC.
  127. */
  128. enum cea_speaker_placement {
  129. FL = (1 << 0), /* Front Left */
  130. FC = (1 << 1), /* Front Center */
  131. FR = (1 << 2), /* Front Right */
  132. FLC = (1 << 3), /* Front Left Center */
  133. FRC = (1 << 4), /* Front Right Center */
  134. RL = (1 << 5), /* Rear Left */
  135. RC = (1 << 6), /* Rear Center */
  136. RR = (1 << 7), /* Rear Right */
  137. RLC = (1 << 8), /* Rear Left Center */
  138. RRC = (1 << 9), /* Rear Right Center */
  139. LFE = (1 << 10), /* Low Frequency Effect */
  140. FLW = (1 << 11), /* Front Left Wide */
  141. FRW = (1 << 12), /* Front Right Wide */
  142. FLH = (1 << 13), /* Front Left High */
  143. FCH = (1 << 14), /* Front Center High */
  144. FRH = (1 << 15), /* Front Right High */
  145. TC = (1 << 16), /* Top Center */
  146. };
  147. /*
  148. * ELD SA bits in the CEA Speaker Allocation data block
  149. */
  150. static int eld_speaker_allocation_bits[] = {
  151. [0] = FL | FR,
  152. [1] = LFE,
  153. [2] = FC,
  154. [3] = RL | RR,
  155. [4] = RC,
  156. [5] = FLC | FRC,
  157. [6] = RLC | RRC,
  158. /* the following are not defined in ELD yet */
  159. [7] = FLW | FRW,
  160. [8] = FLH | FRH,
  161. [9] = TC,
  162. [10] = FCH,
  163. };
  164. struct cea_channel_speaker_allocation {
  165. int ca_index;
  166. int speakers[8];
  167. /* derived values, just for convenience */
  168. int channels;
  169. int spk_mask;
  170. };
  171. /*
  172. * ALSA sequence is:
  173. *
  174. * surround40 surround41 surround50 surround51 surround71
  175. * ch0 front left = = = =
  176. * ch1 front right = = = =
  177. * ch2 rear left = = = =
  178. * ch3 rear right = = = =
  179. * ch4 LFE center center center
  180. * ch5 LFE LFE
  181. * ch6 side left
  182. * ch7 side right
  183. *
  184. * surround71 = {FL, FR, RLC, RRC, FC, LFE, RL, RR}
  185. */
  186. static int hdmi_channel_mapping[0x32][8] = {
  187. /* stereo */
  188. [0x00] = { 0x00, 0x11, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
  189. /* 2.1 */
  190. [0x01] = { 0x00, 0x11, 0x22, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7 },
  191. /* Dolby Surround */
  192. [0x02] = { 0x00, 0x11, 0x23, 0xf2, 0xf4, 0xf5, 0xf6, 0xf7 },
  193. /* surround40 */
  194. [0x08] = { 0x00, 0x11, 0x24, 0x35, 0xf3, 0xf2, 0xf6, 0xf7 },
  195. /* 4ch */
  196. [0x03] = { 0x00, 0x11, 0x23, 0x32, 0x44, 0xf5, 0xf6, 0xf7 },
  197. /* surround41 */
  198. [0x09] = { 0x00, 0x11, 0x24, 0x35, 0x42, 0xf3, 0xf6, 0xf7 },
  199. /* surround50 */
  200. [0x0a] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0xf2, 0xf6, 0xf7 },
  201. /* surround51 */
  202. [0x0b] = { 0x00, 0x11, 0x24, 0x35, 0x43, 0x52, 0xf6, 0xf7 },
  203. /* 7.1 */
  204. [0x13] = { 0x00, 0x11, 0x26, 0x37, 0x43, 0x52, 0x64, 0x75 },
  205. };
  206. /*
  207. * This is an ordered list!
  208. *
  209. * The preceding ones have better chances to be selected by
  210. * hdmi_channel_allocation().
  211. */
  212. static struct cea_channel_speaker_allocation channel_allocations[] = {
  213. /* channel: 7 6 5 4 3 2 1 0 */
  214. { .ca_index = 0x00, .speakers = { 0, 0, 0, 0, 0, 0, FR, FL } },
  215. /* 2.1 */
  216. { .ca_index = 0x01, .speakers = { 0, 0, 0, 0, 0, LFE, FR, FL } },
  217. /* Dolby Surround */
  218. { .ca_index = 0x02, .speakers = { 0, 0, 0, 0, FC, 0, FR, FL } },
  219. /* surround40 */
  220. { .ca_index = 0x08, .speakers = { 0, 0, RR, RL, 0, 0, FR, FL } },
  221. /* surround41 */
  222. { .ca_index = 0x09, .speakers = { 0, 0, RR, RL, 0, LFE, FR, FL } },
  223. /* surround50 */
  224. { .ca_index = 0x0a, .speakers = { 0, 0, RR, RL, FC, 0, FR, FL } },
  225. /* surround51 */
  226. { .ca_index = 0x0b, .speakers = { 0, 0, RR, RL, FC, LFE, FR, FL } },
  227. /* 6.1 */
  228. { .ca_index = 0x0f, .speakers = { 0, RC, RR, RL, FC, LFE, FR, FL } },
  229. /* surround71 */
  230. { .ca_index = 0x13, .speakers = { RRC, RLC, RR, RL, FC, LFE, FR, FL } },
  231. { .ca_index = 0x03, .speakers = { 0, 0, 0, 0, FC, LFE, FR, FL } },
  232. { .ca_index = 0x04, .speakers = { 0, 0, 0, RC, 0, 0, FR, FL } },
  233. { .ca_index = 0x05, .speakers = { 0, 0, 0, RC, 0, LFE, FR, FL } },
  234. { .ca_index = 0x06, .speakers = { 0, 0, 0, RC, FC, 0, FR, FL } },
  235. { .ca_index = 0x07, .speakers = { 0, 0, 0, RC, FC, LFE, FR, FL } },
  236. { .ca_index = 0x0c, .speakers = { 0, RC, RR, RL, 0, 0, FR, FL } },
  237. { .ca_index = 0x0d, .speakers = { 0, RC, RR, RL, 0, LFE, FR, FL } },
  238. { .ca_index = 0x0e, .speakers = { 0, RC, RR, RL, FC, 0, FR, FL } },
  239. { .ca_index = 0x10, .speakers = { RRC, RLC, RR, RL, 0, 0, FR, FL } },
  240. { .ca_index = 0x11, .speakers = { RRC, RLC, RR, RL, 0, LFE, FR, FL } },
  241. { .ca_index = 0x12, .speakers = { RRC, RLC, RR, RL, FC, 0, FR, FL } },
  242. { .ca_index = 0x14, .speakers = { FRC, FLC, 0, 0, 0, 0, FR, FL } },
  243. { .ca_index = 0x15, .speakers = { FRC, FLC, 0, 0, 0, LFE, FR, FL } },
  244. { .ca_index = 0x16, .speakers = { FRC, FLC, 0, 0, FC, 0, FR, FL } },
  245. { .ca_index = 0x17, .speakers = { FRC, FLC, 0, 0, FC, LFE, FR, FL } },
  246. { .ca_index = 0x18, .speakers = { FRC, FLC, 0, RC, 0, 0, FR, FL } },
  247. { .ca_index = 0x19, .speakers = { FRC, FLC, 0, RC, 0, LFE, FR, FL } },
  248. { .ca_index = 0x1a, .speakers = { FRC, FLC, 0, RC, FC, 0, FR, FL } },
  249. { .ca_index = 0x1b, .speakers = { FRC, FLC, 0, RC, FC, LFE, FR, FL } },
  250. { .ca_index = 0x1c, .speakers = { FRC, FLC, RR, RL, 0, 0, FR, FL } },
  251. { .ca_index = 0x1d, .speakers = { FRC, FLC, RR, RL, 0, LFE, FR, FL } },
  252. { .ca_index = 0x1e, .speakers = { FRC, FLC, RR, RL, FC, 0, FR, FL } },
  253. { .ca_index = 0x1f, .speakers = { FRC, FLC, RR, RL, FC, LFE, FR, FL } },
  254. { .ca_index = 0x20, .speakers = { 0, FCH, RR, RL, FC, 0, FR, FL } },
  255. { .ca_index = 0x21, .speakers = { 0, FCH, RR, RL, FC, LFE, FR, FL } },
  256. { .ca_index = 0x22, .speakers = { TC, 0, RR, RL, FC, 0, FR, FL } },
  257. { .ca_index = 0x23, .speakers = { TC, 0, RR, RL, FC, LFE, FR, FL } },
  258. { .ca_index = 0x24, .speakers = { FRH, FLH, RR, RL, 0, 0, FR, FL } },
  259. { .ca_index = 0x25, .speakers = { FRH, FLH, RR, RL, 0, LFE, FR, FL } },
  260. { .ca_index = 0x26, .speakers = { FRW, FLW, RR, RL, 0, 0, FR, FL } },
  261. { .ca_index = 0x27, .speakers = { FRW, FLW, RR, RL, 0, LFE, FR, FL } },
  262. { .ca_index = 0x28, .speakers = { TC, RC, RR, RL, FC, 0, FR, FL } },
  263. { .ca_index = 0x29, .speakers = { TC, RC, RR, RL, FC, LFE, FR, FL } },
  264. { .ca_index = 0x2a, .speakers = { FCH, RC, RR, RL, FC, 0, FR, FL } },
  265. { .ca_index = 0x2b, .speakers = { FCH, RC, RR, RL, FC, LFE, FR, FL } },
  266. { .ca_index = 0x2c, .speakers = { TC, FCH, RR, RL, FC, 0, FR, FL } },
  267. { .ca_index = 0x2d, .speakers = { TC, FCH, RR, RL, FC, LFE, FR, FL } },
  268. { .ca_index = 0x2e, .speakers = { FRH, FLH, RR, RL, FC, 0, FR, FL } },
  269. { .ca_index = 0x2f, .speakers = { FRH, FLH, RR, RL, FC, LFE, FR, FL } },
  270. { .ca_index = 0x30, .speakers = { FRW, FLW, RR, RL, FC, 0, FR, FL } },
  271. { .ca_index = 0x31, .speakers = { FRW, FLW, RR, RL, FC, LFE, FR, FL } },
  272. };
  273. /*
  274. * HDMI routines
  275. */
  276. #define get_pin(spec, idx) \
  277. ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
  278. #define get_cvt(spec, idx) \
  279. ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
  280. #define get_pcm_rec(spec, idx) \
  281. ((struct hda_pcm *)snd_array_elem(&spec->pcm_rec, idx))
  282. static int pin_nid_to_pin_index(struct hdmi_spec *spec, hda_nid_t pin_nid)
  283. {
  284. int pin_idx;
  285. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
  286. if (get_pin(spec, pin_idx)->pin_nid == pin_nid)
  287. return pin_idx;
  288. snd_printk(KERN_WARNING "HDMI: pin nid %d not registered\n", pin_nid);
  289. return -EINVAL;
  290. }
  291. static int hinfo_to_pin_index(struct hdmi_spec *spec,
  292. struct hda_pcm_stream *hinfo)
  293. {
  294. int pin_idx;
  295. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++)
  296. if (get_pcm_rec(spec, pin_idx)->stream == hinfo)
  297. return pin_idx;
  298. snd_printk(KERN_WARNING "HDMI: hinfo %p not registered\n", hinfo);
  299. return -EINVAL;
  300. }
  301. static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
  302. {
  303. int cvt_idx;
  304. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
  305. if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
  306. return cvt_idx;
  307. snd_printk(KERN_WARNING "HDMI: cvt nid %d not registered\n", cvt_nid);
  308. return -EINVAL;
  309. }
  310. static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
  311. struct snd_ctl_elem_info *uinfo)
  312. {
  313. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  314. struct hdmi_spec *spec = codec->spec;
  315. struct hdmi_eld *eld;
  316. int pin_idx;
  317. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  318. pin_idx = kcontrol->private_value;
  319. eld = &get_pin(spec, pin_idx)->sink_eld;
  320. mutex_lock(&eld->lock);
  321. uinfo->count = eld->eld_valid ? eld->eld_size : 0;
  322. mutex_unlock(&eld->lock);
  323. return 0;
  324. }
  325. static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
  326. struct snd_ctl_elem_value *ucontrol)
  327. {
  328. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  329. struct hdmi_spec *spec = codec->spec;
  330. struct hdmi_eld *eld;
  331. int pin_idx;
  332. pin_idx = kcontrol->private_value;
  333. eld = &get_pin(spec, pin_idx)->sink_eld;
  334. mutex_lock(&eld->lock);
  335. if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data)) {
  336. mutex_unlock(&eld->lock);
  337. snd_BUG();
  338. return -EINVAL;
  339. }
  340. memset(ucontrol->value.bytes.data, 0,
  341. ARRAY_SIZE(ucontrol->value.bytes.data));
  342. if (eld->eld_valid)
  343. memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
  344. eld->eld_size);
  345. mutex_unlock(&eld->lock);
  346. return 0;
  347. }
  348. static struct snd_kcontrol_new eld_bytes_ctl = {
  349. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  350. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  351. .name = "ELD",
  352. .info = hdmi_eld_ctl_info,
  353. .get = hdmi_eld_ctl_get,
  354. };
  355. static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
  356. int device)
  357. {
  358. struct snd_kcontrol *kctl;
  359. struct hdmi_spec *spec = codec->spec;
  360. int err;
  361. kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
  362. if (!kctl)
  363. return -ENOMEM;
  364. kctl->private_value = pin_idx;
  365. kctl->id.device = device;
  366. err = snd_hda_ctl_add(codec, get_pin(spec, pin_idx)->pin_nid, kctl);
  367. if (err < 0)
  368. return err;
  369. get_pin(spec, pin_idx)->eld_ctl = kctl;
  370. return 0;
  371. }
  372. #ifdef BE_PARANOID
  373. static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  374. int *packet_index, int *byte_index)
  375. {
  376. int val;
  377. val = snd_hda_codec_read(codec, pin_nid, 0,
  378. AC_VERB_GET_HDMI_DIP_INDEX, 0);
  379. *packet_index = val >> 5;
  380. *byte_index = val & 0x1f;
  381. }
  382. #endif
  383. static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  384. int packet_index, int byte_index)
  385. {
  386. int val;
  387. val = (packet_index << 5) | (byte_index & 0x1f);
  388. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
  389. }
  390. static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
  391. unsigned char val)
  392. {
  393. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
  394. }
  395. static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  396. {
  397. /* Unmute */
  398. if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
  399. snd_hda_codec_write(codec, pin_nid, 0,
  400. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  401. /* Enable pin out: some machines with GM965 gets broken output when
  402. * the pin is disabled or changed while using with HDMI
  403. */
  404. snd_hda_codec_write(codec, pin_nid, 0,
  405. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  406. }
  407. static int hdmi_get_channel_count(struct hda_codec *codec, hda_nid_t cvt_nid)
  408. {
  409. return 1 + snd_hda_codec_read(codec, cvt_nid, 0,
  410. AC_VERB_GET_CVT_CHAN_COUNT, 0);
  411. }
  412. static void hdmi_set_channel_count(struct hda_codec *codec,
  413. hda_nid_t cvt_nid, int chs)
  414. {
  415. if (chs != hdmi_get_channel_count(codec, cvt_nid))
  416. snd_hda_codec_write(codec, cvt_nid, 0,
  417. AC_VERB_SET_CVT_CHAN_COUNT, chs - 1);
  418. }
  419. /*
  420. * Channel mapping routines
  421. */
  422. /*
  423. * Compute derived values in channel_allocations[].
  424. */
  425. static void init_channel_allocations(void)
  426. {
  427. int i, j;
  428. struct cea_channel_speaker_allocation *p;
  429. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  430. p = channel_allocations + i;
  431. p->channels = 0;
  432. p->spk_mask = 0;
  433. for (j = 0; j < ARRAY_SIZE(p->speakers); j++)
  434. if (p->speakers[j]) {
  435. p->channels++;
  436. p->spk_mask |= p->speakers[j];
  437. }
  438. }
  439. }
  440. static int get_channel_allocation_order(int ca)
  441. {
  442. int i;
  443. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  444. if (channel_allocations[i].ca_index == ca)
  445. break;
  446. }
  447. return i;
  448. }
  449. /*
  450. * The transformation takes two steps:
  451. *
  452. * eld->spk_alloc => (eld_speaker_allocation_bits[]) => spk_mask
  453. * spk_mask => (channel_allocations[]) => ai->CA
  454. *
  455. * TODO: it could select the wrong CA from multiple candidates.
  456. */
  457. static int hdmi_channel_allocation(struct hdmi_eld *eld, int channels)
  458. {
  459. int i;
  460. int ca = 0;
  461. int spk_mask = 0;
  462. char buf[SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE];
  463. /*
  464. * CA defaults to 0 for basic stereo audio
  465. */
  466. if (channels <= 2)
  467. return 0;
  468. /*
  469. * expand ELD's speaker allocation mask
  470. *
  471. * ELD tells the speaker mask in a compact(paired) form,
  472. * expand ELD's notions to match the ones used by Audio InfoFrame.
  473. */
  474. for (i = 0; i < ARRAY_SIZE(eld_speaker_allocation_bits); i++) {
  475. if (eld->info.spk_alloc & (1 << i))
  476. spk_mask |= eld_speaker_allocation_bits[i];
  477. }
  478. /* search for the first working match in the CA table */
  479. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  480. if (channels == channel_allocations[i].channels &&
  481. (spk_mask & channel_allocations[i].spk_mask) ==
  482. channel_allocations[i].spk_mask) {
  483. ca = channel_allocations[i].ca_index;
  484. break;
  485. }
  486. }
  487. if (!ca) {
  488. /* if there was no match, select the regular ALSA channel
  489. * allocation with the matching number of channels */
  490. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  491. if (channels == channel_allocations[i].channels) {
  492. ca = channel_allocations[i].ca_index;
  493. break;
  494. }
  495. }
  496. }
  497. snd_print_channel_allocation(eld->info.spk_alloc, buf, sizeof(buf));
  498. snd_printdd("HDMI: select CA 0x%x for %d-channel allocation: %s\n",
  499. ca, channels, buf);
  500. return ca;
  501. }
  502. static void hdmi_debug_channel_mapping(struct hda_codec *codec,
  503. hda_nid_t pin_nid)
  504. {
  505. #ifdef CONFIG_SND_DEBUG_VERBOSE
  506. int i;
  507. int slot;
  508. for (i = 0; i < 8; i++) {
  509. slot = snd_hda_codec_read(codec, pin_nid, 0,
  510. AC_VERB_GET_HDMI_CHAN_SLOT, i);
  511. printk(KERN_DEBUG "HDMI: ASP channel %d => slot %d\n",
  512. slot >> 4, slot & 0xf);
  513. }
  514. #endif
  515. }
  516. static void hdmi_std_setup_channel_mapping(struct hda_codec *codec,
  517. hda_nid_t pin_nid,
  518. bool non_pcm,
  519. int ca)
  520. {
  521. struct cea_channel_speaker_allocation *ch_alloc;
  522. int i;
  523. int err;
  524. int order;
  525. int non_pcm_mapping[8];
  526. order = get_channel_allocation_order(ca);
  527. ch_alloc = &channel_allocations[order];
  528. if (hdmi_channel_mapping[ca][1] == 0) {
  529. int hdmi_slot = 0;
  530. /* fill actual channel mappings in ALSA channel (i) order */
  531. for (i = 0; i < ch_alloc->channels; i++) {
  532. while (!ch_alloc->speakers[7 - hdmi_slot] && !WARN_ON(hdmi_slot >= 8))
  533. hdmi_slot++; /* skip zero slots */
  534. hdmi_channel_mapping[ca][i] = (i << 4) | hdmi_slot++;
  535. }
  536. /* fill the rest of the slots with ALSA channel 0xf */
  537. for (hdmi_slot = 0; hdmi_slot < 8; hdmi_slot++)
  538. if (!ch_alloc->speakers[7 - hdmi_slot])
  539. hdmi_channel_mapping[ca][i++] = (0xf << 4) | hdmi_slot;
  540. }
  541. if (non_pcm) {
  542. for (i = 0; i < ch_alloc->channels; i++)
  543. non_pcm_mapping[i] = i | (i << 4);
  544. for (; i < 8; i++)
  545. non_pcm_mapping[i] = 0xf | (i << 4);
  546. }
  547. for (i = 0; i < 8; i++) {
  548. err = snd_hda_codec_write(codec, pin_nid, 0,
  549. AC_VERB_SET_HDMI_CHAN_SLOT,
  550. non_pcm ? non_pcm_mapping[i] : hdmi_channel_mapping[ca][i]);
  551. if (err) {
  552. snd_printdd(KERN_NOTICE
  553. "HDMI: channel mapping failed\n");
  554. break;
  555. }
  556. }
  557. hdmi_debug_channel_mapping(codec, pin_nid);
  558. }
  559. struct channel_map_table {
  560. unsigned char map; /* ALSA API channel map position */
  561. unsigned char cea_slot; /* CEA slot value */
  562. int spk_mask; /* speaker position bit mask */
  563. };
  564. static struct channel_map_table map_tables[] = {
  565. { SNDRV_CHMAP_FL, 0x00, FL },
  566. { SNDRV_CHMAP_FR, 0x01, FR },
  567. { SNDRV_CHMAP_RL, 0x04, RL },
  568. { SNDRV_CHMAP_RR, 0x05, RR },
  569. { SNDRV_CHMAP_LFE, 0x02, LFE },
  570. { SNDRV_CHMAP_FC, 0x03, FC },
  571. { SNDRV_CHMAP_RLC, 0x06, RLC },
  572. { SNDRV_CHMAP_RRC, 0x07, RRC },
  573. {} /* terminator */
  574. };
  575. /* from ALSA API channel position to speaker bit mask */
  576. static int to_spk_mask(unsigned char c)
  577. {
  578. struct channel_map_table *t = map_tables;
  579. for (; t->map; t++) {
  580. if (t->map == c)
  581. return t->spk_mask;
  582. }
  583. return 0;
  584. }
  585. /* from ALSA API channel position to CEA slot */
  586. static int to_cea_slot(unsigned char c)
  587. {
  588. struct channel_map_table *t = map_tables;
  589. for (; t->map; t++) {
  590. if (t->map == c)
  591. return t->cea_slot;
  592. }
  593. return 0x0f;
  594. }
  595. /* from CEA slot to ALSA API channel position */
  596. static int from_cea_slot(unsigned char c)
  597. {
  598. struct channel_map_table *t = map_tables;
  599. for (; t->map; t++) {
  600. if (t->cea_slot == c)
  601. return t->map;
  602. }
  603. return 0;
  604. }
  605. /* from speaker bit mask to ALSA API channel position */
  606. static int spk_to_chmap(int spk)
  607. {
  608. struct channel_map_table *t = map_tables;
  609. for (; t->map; t++) {
  610. if (t->spk_mask == spk)
  611. return t->map;
  612. }
  613. return 0;
  614. }
  615. /* get the CA index corresponding to the given ALSA API channel map */
  616. static int hdmi_manual_channel_allocation(int chs, unsigned char *map)
  617. {
  618. int i, spks = 0, spk_mask = 0;
  619. for (i = 0; i < chs; i++) {
  620. int mask = to_spk_mask(map[i]);
  621. if (mask) {
  622. spk_mask |= mask;
  623. spks++;
  624. }
  625. }
  626. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++) {
  627. if ((chs == channel_allocations[i].channels ||
  628. spks == channel_allocations[i].channels) &&
  629. (spk_mask & channel_allocations[i].spk_mask) ==
  630. channel_allocations[i].spk_mask)
  631. return channel_allocations[i].ca_index;
  632. }
  633. return -1;
  634. }
  635. /* set up the channel slots for the given ALSA API channel map */
  636. static int hdmi_manual_setup_channel_mapping(struct hda_codec *codec,
  637. hda_nid_t pin_nid,
  638. int chs, unsigned char *map)
  639. {
  640. int i;
  641. for (i = 0; i < 8; i++) {
  642. int val, err;
  643. if (i < chs)
  644. val = to_cea_slot(map[i]);
  645. else
  646. val = 0xf;
  647. val |= (i << 4);
  648. err = snd_hda_codec_write(codec, pin_nid, 0,
  649. AC_VERB_SET_HDMI_CHAN_SLOT, val);
  650. if (err)
  651. return -EINVAL;
  652. }
  653. return 0;
  654. }
  655. /* store ALSA API channel map from the current default map */
  656. static void hdmi_setup_fake_chmap(unsigned char *map, int ca)
  657. {
  658. int i;
  659. int ordered_ca = get_channel_allocation_order(ca);
  660. for (i = 0; i < 8; i++) {
  661. if (i < channel_allocations[ordered_ca].channels)
  662. map[i] = from_cea_slot(hdmi_channel_mapping[ca][i] & 0x0f);
  663. else
  664. map[i] = 0;
  665. }
  666. }
  667. static void hdmi_setup_channel_mapping(struct hda_codec *codec,
  668. hda_nid_t pin_nid, bool non_pcm, int ca,
  669. int channels, unsigned char *map,
  670. bool chmap_set)
  671. {
  672. if (!non_pcm && chmap_set) {
  673. hdmi_manual_setup_channel_mapping(codec, pin_nid,
  674. channels, map);
  675. } else {
  676. hdmi_std_setup_channel_mapping(codec, pin_nid, non_pcm, ca);
  677. hdmi_setup_fake_chmap(map, ca);
  678. }
  679. }
  680. /*
  681. * Audio InfoFrame routines
  682. */
  683. /*
  684. * Enable Audio InfoFrame Transmission
  685. */
  686. static void hdmi_start_infoframe_trans(struct hda_codec *codec,
  687. hda_nid_t pin_nid)
  688. {
  689. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  690. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  691. AC_DIPXMIT_BEST);
  692. }
  693. /*
  694. * Disable Audio InfoFrame Transmission
  695. */
  696. static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
  697. hda_nid_t pin_nid)
  698. {
  699. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  700. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  701. AC_DIPXMIT_DISABLE);
  702. }
  703. static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
  704. {
  705. #ifdef CONFIG_SND_DEBUG_VERBOSE
  706. int i;
  707. int size;
  708. size = snd_hdmi_get_eld_size(codec, pin_nid);
  709. printk(KERN_DEBUG "HDMI: ELD buf size is %d\n", size);
  710. for (i = 0; i < 8; i++) {
  711. size = snd_hda_codec_read(codec, pin_nid, 0,
  712. AC_VERB_GET_HDMI_DIP_SIZE, i);
  713. printk(KERN_DEBUG "HDMI: DIP GP[%d] buf size is %d\n", i, size);
  714. }
  715. #endif
  716. }
  717. static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
  718. {
  719. #ifdef BE_PARANOID
  720. int i, j;
  721. int size;
  722. int pi, bi;
  723. for (i = 0; i < 8; i++) {
  724. size = snd_hda_codec_read(codec, pin_nid, 0,
  725. AC_VERB_GET_HDMI_DIP_SIZE, i);
  726. if (size == 0)
  727. continue;
  728. hdmi_set_dip_index(codec, pin_nid, i, 0x0);
  729. for (j = 1; j < 1000; j++) {
  730. hdmi_write_dip_byte(codec, pin_nid, 0x0);
  731. hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
  732. if (pi != i)
  733. snd_printd(KERN_INFO "dip index %d: %d != %d\n",
  734. bi, pi, i);
  735. if (bi == 0) /* byte index wrapped around */
  736. break;
  737. }
  738. snd_printd(KERN_INFO
  739. "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
  740. i, size, j);
  741. }
  742. #endif
  743. }
  744. static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
  745. {
  746. u8 *bytes = (u8 *)hdmi_ai;
  747. u8 sum = 0;
  748. int i;
  749. hdmi_ai->checksum = 0;
  750. for (i = 0; i < sizeof(*hdmi_ai); i++)
  751. sum += bytes[i];
  752. hdmi_ai->checksum = -sum;
  753. }
  754. static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
  755. hda_nid_t pin_nid,
  756. u8 *dip, int size)
  757. {
  758. int i;
  759. hdmi_debug_dip_size(codec, pin_nid);
  760. hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
  761. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  762. for (i = 0; i < size; i++)
  763. hdmi_write_dip_byte(codec, pin_nid, dip[i]);
  764. }
  765. static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
  766. u8 *dip, int size)
  767. {
  768. u8 val;
  769. int i;
  770. if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
  771. != AC_DIPXMIT_BEST)
  772. return false;
  773. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  774. for (i = 0; i < size; i++) {
  775. val = snd_hda_codec_read(codec, pin_nid, 0,
  776. AC_VERB_GET_HDMI_DIP_DATA, 0);
  777. if (val != dip[i])
  778. return false;
  779. }
  780. return true;
  781. }
  782. static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
  783. struct hdmi_spec_per_pin *per_pin,
  784. bool non_pcm)
  785. {
  786. hda_nid_t pin_nid = per_pin->pin_nid;
  787. int channels = per_pin->channels;
  788. int active_channels;
  789. struct hdmi_eld *eld;
  790. int ca, ordered_ca;
  791. union audio_infoframe ai;
  792. if (!channels)
  793. return;
  794. if (is_haswell(codec))
  795. snd_hda_codec_write(codec, pin_nid, 0,
  796. AC_VERB_SET_AMP_GAIN_MUTE,
  797. AMP_OUT_UNMUTE);
  798. eld = &per_pin->sink_eld;
  799. if (!eld->monitor_present)
  800. return;
  801. if (!non_pcm && per_pin->chmap_set)
  802. ca = hdmi_manual_channel_allocation(channels, per_pin->chmap);
  803. else
  804. ca = hdmi_channel_allocation(eld, channels);
  805. if (ca < 0)
  806. ca = 0;
  807. ordered_ca = get_channel_allocation_order(ca);
  808. active_channels = channel_allocations[ordered_ca].channels;
  809. hdmi_set_channel_count(codec, per_pin->cvt_nid, active_channels);
  810. memset(&ai, 0, sizeof(ai));
  811. if (eld->info.conn_type == 0) { /* HDMI */
  812. struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
  813. hdmi_ai->type = 0x84;
  814. hdmi_ai->ver = 0x01;
  815. hdmi_ai->len = 0x0a;
  816. hdmi_ai->CC02_CT47 = active_channels - 1;
  817. hdmi_ai->CA = ca;
  818. hdmi_checksum_audio_infoframe(hdmi_ai);
  819. } else if (eld->info.conn_type == 1) { /* DisplayPort */
  820. struct dp_audio_infoframe *dp_ai = &ai.dp;
  821. dp_ai->type = 0x84;
  822. dp_ai->len = 0x1b;
  823. dp_ai->ver = 0x11 << 2;
  824. dp_ai->CC02_CT47 = active_channels - 1;
  825. dp_ai->CA = ca;
  826. } else {
  827. snd_printd("HDMI: unknown connection type at pin %d\n",
  828. pin_nid);
  829. return;
  830. }
  831. /*
  832. * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
  833. * sizeof(*dp_ai) to avoid partial match/update problems when
  834. * the user switches between HDMI/DP monitors.
  835. */
  836. if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
  837. sizeof(ai))) {
  838. snd_printdd("hdmi_setup_audio_infoframe: "
  839. "pin=%d channels=%d\n",
  840. pin_nid,
  841. active_channels);
  842. hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
  843. channels, per_pin->chmap,
  844. per_pin->chmap_set);
  845. hdmi_stop_infoframe_trans(codec, pin_nid);
  846. hdmi_fill_audio_infoframe(codec, pin_nid,
  847. ai.bytes, sizeof(ai));
  848. hdmi_start_infoframe_trans(codec, pin_nid);
  849. } else {
  850. /* For non-pcm audio switch, setup new channel mapping
  851. * accordingly */
  852. if (per_pin->non_pcm != non_pcm)
  853. hdmi_setup_channel_mapping(codec, pin_nid, non_pcm, ca,
  854. channels, per_pin->chmap,
  855. per_pin->chmap_set);
  856. }
  857. per_pin->non_pcm = non_pcm;
  858. }
  859. /*
  860. * Unsolicited events
  861. */
  862. static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
  863. static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
  864. {
  865. struct hdmi_spec *spec = codec->spec;
  866. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  867. int pin_nid;
  868. int pin_idx;
  869. struct hda_jack_tbl *jack;
  870. int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
  871. jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
  872. if (!jack)
  873. return;
  874. pin_nid = jack->nid;
  875. jack->jack_dirty = 1;
  876. _snd_printd(SND_PR_VERBOSE,
  877. "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
  878. codec->addr, pin_nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
  879. !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
  880. pin_idx = pin_nid_to_pin_index(spec, pin_nid);
  881. if (pin_idx < 0)
  882. return;
  883. hdmi_present_sense(get_pin(spec, pin_idx), 1);
  884. snd_hda_jack_report_sync(codec);
  885. }
  886. static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
  887. {
  888. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  889. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  890. int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
  891. int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
  892. printk(KERN_INFO
  893. "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
  894. codec->addr,
  895. tag,
  896. subtag,
  897. cp_state,
  898. cp_ready);
  899. /* TODO */
  900. if (cp_state)
  901. ;
  902. if (cp_ready)
  903. ;
  904. }
  905. static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
  906. {
  907. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  908. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  909. if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
  910. snd_printd(KERN_INFO "Unexpected HDMI event tag 0x%x\n", tag);
  911. return;
  912. }
  913. if (subtag == 0)
  914. hdmi_intrinsic_event(codec, res);
  915. else
  916. hdmi_non_intrinsic_event(codec, res);
  917. }
  918. static void haswell_verify_D0(struct hda_codec *codec,
  919. hda_nid_t cvt_nid, hda_nid_t nid)
  920. {
  921. int pwr;
  922. /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
  923. * thus pins could only choose converter 0 for use. Make sure the
  924. * converters are in correct power state */
  925. if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
  926. snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  927. if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
  928. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
  929. AC_PWRST_D0);
  930. msleep(40);
  931. pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
  932. pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
  933. snd_printd("Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
  934. }
  935. }
  936. /*
  937. * Callbacks
  938. */
  939. /* HBR should be Non-PCM, 8 channels */
  940. #define is_hbr_format(format) \
  941. ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
  942. static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  943. hda_nid_t pin_nid, u32 stream_tag, int format)
  944. {
  945. int pinctl;
  946. int new_pinctl = 0;
  947. if (is_haswell(codec))
  948. haswell_verify_D0(codec, cvt_nid, pin_nid);
  949. if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
  950. pinctl = snd_hda_codec_read(codec, pin_nid, 0,
  951. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  952. new_pinctl = pinctl & ~AC_PINCTL_EPT;
  953. if (is_hbr_format(format))
  954. new_pinctl |= AC_PINCTL_EPT_HBR;
  955. else
  956. new_pinctl |= AC_PINCTL_EPT_NATIVE;
  957. snd_printdd("hdmi_setup_stream: "
  958. "NID=0x%x, %spinctl=0x%x\n",
  959. pin_nid,
  960. pinctl == new_pinctl ? "" : "new-",
  961. new_pinctl);
  962. if (pinctl != new_pinctl)
  963. snd_hda_codec_write(codec, pin_nid, 0,
  964. AC_VERB_SET_PIN_WIDGET_CONTROL,
  965. new_pinctl);
  966. }
  967. if (is_hbr_format(format) && !new_pinctl) {
  968. snd_printdd("hdmi_setup_stream: HBR is not supported\n");
  969. return -EINVAL;
  970. }
  971. snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
  972. return 0;
  973. }
  974. static int hdmi_choose_cvt(struct hda_codec *codec,
  975. int pin_idx, int *cvt_id, int *mux_id)
  976. {
  977. struct hdmi_spec *spec = codec->spec;
  978. struct hdmi_spec_per_pin *per_pin;
  979. struct hdmi_spec_per_cvt *per_cvt = NULL;
  980. int cvt_idx, mux_idx = 0;
  981. per_pin = get_pin(spec, pin_idx);
  982. /* Dynamically assign converter to stream */
  983. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  984. per_cvt = get_cvt(spec, cvt_idx);
  985. /* Must not already be assigned */
  986. if (per_cvt->assigned)
  987. continue;
  988. /* Must be in pin's mux's list of converters */
  989. for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
  990. if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
  991. break;
  992. /* Not in mux list */
  993. if (mux_idx == per_pin->num_mux_nids)
  994. continue;
  995. break;
  996. }
  997. /* No free converters */
  998. if (cvt_idx == spec->num_cvts)
  999. return -ENODEV;
  1000. if (cvt_id)
  1001. *cvt_id = cvt_idx;
  1002. if (mux_id)
  1003. *mux_id = mux_idx;
  1004. return 0;
  1005. }
  1006. static void haswell_config_cvts(struct hda_codec *codec,
  1007. hda_nid_t pin_nid, int mux_idx)
  1008. {
  1009. struct hdmi_spec *spec = codec->spec;
  1010. hda_nid_t nid, end_nid;
  1011. int cvt_idx, curr;
  1012. struct hdmi_spec_per_cvt *per_cvt;
  1013. /* configure all pins, including "no physical connection" ones */
  1014. end_nid = codec->start_nid + codec->num_nodes;
  1015. for (nid = codec->start_nid; nid < end_nid; nid++) {
  1016. unsigned int wid_caps = get_wcaps(codec, nid);
  1017. unsigned int wid_type = get_wcaps_type(wid_caps);
  1018. if (wid_type != AC_WID_PIN)
  1019. continue;
  1020. if (nid == pin_nid)
  1021. continue;
  1022. curr = snd_hda_codec_read(codec, nid, 0,
  1023. AC_VERB_GET_CONNECT_SEL, 0);
  1024. if (curr != mux_idx)
  1025. continue;
  1026. /* choose an unassigned converter. The conveters in the
  1027. * connection list are in the same order as in the codec.
  1028. */
  1029. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  1030. per_cvt = get_cvt(spec, cvt_idx);
  1031. if (!per_cvt->assigned) {
  1032. snd_printdd("choose cvt %d for pin nid %d\n",
  1033. cvt_idx, nid);
  1034. snd_hda_codec_write_cache(codec, nid, 0,
  1035. AC_VERB_SET_CONNECT_SEL,
  1036. cvt_idx);
  1037. break;
  1038. }
  1039. }
  1040. }
  1041. }
  1042. /*
  1043. * HDA PCM callbacks
  1044. */
  1045. static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
  1046. struct hda_codec *codec,
  1047. struct snd_pcm_substream *substream)
  1048. {
  1049. struct hdmi_spec *spec = codec->spec;
  1050. struct snd_pcm_runtime *runtime = substream->runtime;
  1051. int pin_idx, cvt_idx, mux_idx = 0;
  1052. struct hdmi_spec_per_pin *per_pin;
  1053. struct hdmi_eld *eld;
  1054. struct hdmi_spec_per_cvt *per_cvt = NULL;
  1055. int err;
  1056. /* Validate hinfo */
  1057. pin_idx = hinfo_to_pin_index(spec, hinfo);
  1058. if (snd_BUG_ON(pin_idx < 0))
  1059. return -EINVAL;
  1060. per_pin = get_pin(spec, pin_idx);
  1061. eld = &per_pin->sink_eld;
  1062. err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, &mux_idx);
  1063. if (err < 0)
  1064. return err;
  1065. per_cvt = get_cvt(spec, cvt_idx);
  1066. /* Claim converter */
  1067. per_cvt->assigned = 1;
  1068. per_pin->cvt_nid = per_cvt->cvt_nid;
  1069. hinfo->nid = per_cvt->cvt_nid;
  1070. snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
  1071. AC_VERB_SET_CONNECT_SEL,
  1072. mux_idx);
  1073. /* configure unused pins to choose other converters */
  1074. if (is_haswell(codec))
  1075. haswell_config_cvts(codec, per_pin->pin_nid, mux_idx);
  1076. snd_hda_spdif_ctls_assign(codec, pin_idx, per_cvt->cvt_nid);
  1077. /* Initially set the converter's capabilities */
  1078. hinfo->channels_min = per_cvt->channels_min;
  1079. hinfo->channels_max = per_cvt->channels_max;
  1080. hinfo->rates = per_cvt->rates;
  1081. hinfo->formats = per_cvt->formats;
  1082. hinfo->maxbps = per_cvt->maxbps;
  1083. /* Restrict capabilities by ELD if this isn't disabled */
  1084. if (!static_hdmi_pcm && eld->eld_valid) {
  1085. snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
  1086. if (hinfo->channels_min > hinfo->channels_max ||
  1087. !hinfo->rates || !hinfo->formats) {
  1088. per_cvt->assigned = 0;
  1089. hinfo->nid = 0;
  1090. snd_hda_spdif_ctls_unassign(codec, pin_idx);
  1091. return -ENODEV;
  1092. }
  1093. }
  1094. /* Store the updated parameters */
  1095. runtime->hw.channels_min = hinfo->channels_min;
  1096. runtime->hw.channels_max = hinfo->channels_max;
  1097. runtime->hw.formats = hinfo->formats;
  1098. runtime->hw.rates = hinfo->rates;
  1099. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1100. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1101. return 0;
  1102. }
  1103. /*
  1104. * HDA/HDMI auto parsing
  1105. */
  1106. static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
  1107. {
  1108. struct hdmi_spec *spec = codec->spec;
  1109. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1110. hda_nid_t pin_nid = per_pin->pin_nid;
  1111. if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
  1112. snd_printk(KERN_WARNING
  1113. "HDMI: pin %d wcaps %#x "
  1114. "does not support connection list\n",
  1115. pin_nid, get_wcaps(codec, pin_nid));
  1116. return -EINVAL;
  1117. }
  1118. per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
  1119. per_pin->mux_nids,
  1120. HDA_MAX_CONNECTIONS);
  1121. return 0;
  1122. }
  1123. static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
  1124. {
  1125. struct hda_codec *codec = per_pin->codec;
  1126. struct hdmi_spec *spec = codec->spec;
  1127. struct hdmi_eld *eld = &spec->temp_eld;
  1128. struct hdmi_eld *pin_eld = &per_pin->sink_eld;
  1129. hda_nid_t pin_nid = per_pin->pin_nid;
  1130. /*
  1131. * Always execute a GetPinSense verb here, even when called from
  1132. * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
  1133. * response's PD bit is not the real PD value, but indicates that
  1134. * the real PD value changed. An older version of the HD-audio
  1135. * specification worked this way. Hence, we just ignore the data in
  1136. * the unsolicited response to avoid custom WARs.
  1137. */
  1138. int present = snd_hda_pin_sense(codec, pin_nid);
  1139. bool update_eld = false;
  1140. bool eld_changed = false;
  1141. pin_eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
  1142. if (pin_eld->monitor_present)
  1143. eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
  1144. else
  1145. eld->eld_valid = false;
  1146. _snd_printd(SND_PR_VERBOSE,
  1147. "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
  1148. codec->addr, pin_nid, pin_eld->monitor_present, eld->eld_valid);
  1149. if (eld->eld_valid) {
  1150. if (snd_hdmi_get_eld(codec, pin_nid, eld->eld_buffer,
  1151. &eld->eld_size) < 0)
  1152. eld->eld_valid = false;
  1153. else {
  1154. memset(&eld->info, 0, sizeof(struct parsed_hdmi_eld));
  1155. if (snd_hdmi_parse_eld(&eld->info, eld->eld_buffer,
  1156. eld->eld_size) < 0)
  1157. eld->eld_valid = false;
  1158. }
  1159. if (eld->eld_valid) {
  1160. snd_hdmi_show_eld(&eld->info);
  1161. update_eld = true;
  1162. }
  1163. else if (repoll) {
  1164. queue_delayed_work(codec->bus->workq,
  1165. &per_pin->work,
  1166. msecs_to_jiffies(300));
  1167. return;
  1168. }
  1169. }
  1170. mutex_lock(&pin_eld->lock);
  1171. if (pin_eld->eld_valid && !eld->eld_valid) {
  1172. update_eld = true;
  1173. eld_changed = true;
  1174. }
  1175. if (update_eld) {
  1176. bool old_eld_valid = pin_eld->eld_valid;
  1177. pin_eld->eld_valid = eld->eld_valid;
  1178. eld_changed = pin_eld->eld_size != eld->eld_size ||
  1179. memcmp(pin_eld->eld_buffer, eld->eld_buffer,
  1180. eld->eld_size) != 0;
  1181. if (eld_changed)
  1182. memcpy(pin_eld->eld_buffer, eld->eld_buffer,
  1183. eld->eld_size);
  1184. pin_eld->eld_size = eld->eld_size;
  1185. pin_eld->info = eld->info;
  1186. /* Haswell-specific workaround: re-setup when the transcoder is
  1187. * changed during the stream playback
  1188. */
  1189. if (is_haswell(codec) &&
  1190. eld->eld_valid && !old_eld_valid && per_pin->setup)
  1191. hdmi_setup_audio_infoframe(codec, per_pin,
  1192. per_pin->non_pcm);
  1193. }
  1194. mutex_unlock(&pin_eld->lock);
  1195. if (eld_changed)
  1196. snd_ctl_notify(codec->bus->card,
  1197. SNDRV_CTL_EVENT_MASK_VALUE | SNDRV_CTL_EVENT_MASK_INFO,
  1198. &per_pin->eld_ctl->id);
  1199. }
  1200. static void hdmi_repoll_eld(struct work_struct *work)
  1201. {
  1202. struct hdmi_spec_per_pin *per_pin =
  1203. container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
  1204. if (per_pin->repoll_count++ > 6)
  1205. per_pin->repoll_count = 0;
  1206. hdmi_present_sense(per_pin, per_pin->repoll_count);
  1207. }
  1208. static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
  1209. hda_nid_t nid);
  1210. static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  1211. {
  1212. struct hdmi_spec *spec = codec->spec;
  1213. unsigned int caps, config;
  1214. int pin_idx;
  1215. struct hdmi_spec_per_pin *per_pin;
  1216. int err;
  1217. caps = snd_hda_query_pin_caps(codec, pin_nid);
  1218. if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
  1219. return 0;
  1220. config = snd_hda_codec_get_pincfg(codec, pin_nid);
  1221. if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
  1222. return 0;
  1223. if (is_haswell(codec))
  1224. intel_haswell_fixup_connect_list(codec, pin_nid);
  1225. pin_idx = spec->num_pins;
  1226. per_pin = snd_array_new(&spec->pins);
  1227. if (!per_pin)
  1228. return -ENOMEM;
  1229. per_pin->pin_nid = pin_nid;
  1230. per_pin->non_pcm = false;
  1231. err = hdmi_read_pin_conn(codec, pin_idx);
  1232. if (err < 0)
  1233. return err;
  1234. spec->num_pins++;
  1235. return 0;
  1236. }
  1237. static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
  1238. {
  1239. struct hdmi_spec *spec = codec->spec;
  1240. struct hdmi_spec_per_cvt *per_cvt;
  1241. unsigned int chans;
  1242. int err;
  1243. chans = get_wcaps(codec, cvt_nid);
  1244. chans = get_wcaps_channels(chans);
  1245. per_cvt = snd_array_new(&spec->cvts);
  1246. if (!per_cvt)
  1247. return -ENOMEM;
  1248. per_cvt->cvt_nid = cvt_nid;
  1249. per_cvt->channels_min = 2;
  1250. if (chans <= 16) {
  1251. per_cvt->channels_max = chans;
  1252. if (chans > spec->channels_max)
  1253. spec->channels_max = chans;
  1254. }
  1255. err = snd_hda_query_supported_pcm(codec, cvt_nid,
  1256. &per_cvt->rates,
  1257. &per_cvt->formats,
  1258. &per_cvt->maxbps);
  1259. if (err < 0)
  1260. return err;
  1261. if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
  1262. spec->cvt_nids[spec->num_cvts] = cvt_nid;
  1263. spec->num_cvts++;
  1264. return 0;
  1265. }
  1266. static int hdmi_parse_codec(struct hda_codec *codec)
  1267. {
  1268. hda_nid_t nid;
  1269. int i, nodes;
  1270. nodes = snd_hda_get_sub_nodes(codec, codec->afg, &nid);
  1271. if (!nid || nodes < 0) {
  1272. snd_printk(KERN_WARNING "HDMI: failed to get afg sub nodes\n");
  1273. return -EINVAL;
  1274. }
  1275. for (i = 0; i < nodes; i++, nid++) {
  1276. unsigned int caps;
  1277. unsigned int type;
  1278. caps = get_wcaps(codec, nid);
  1279. type = get_wcaps_type(caps);
  1280. if (!(caps & AC_WCAP_DIGITAL))
  1281. continue;
  1282. switch (type) {
  1283. case AC_WID_AUD_OUT:
  1284. hdmi_add_cvt(codec, nid);
  1285. break;
  1286. case AC_WID_PIN:
  1287. hdmi_add_pin(codec, nid);
  1288. break;
  1289. }
  1290. }
  1291. #ifdef CONFIG_PM
  1292. /* We're seeing some problems with unsolicited hot plug events on
  1293. * PantherPoint after S3, if this is not enabled */
  1294. if (codec->vendor_id == 0x80862806)
  1295. codec->bus->power_keep_link_on = 1;
  1296. /*
  1297. * G45/IbexPeak don't support EPSS: the unsolicited pin hot plug event
  1298. * can be lost and presence sense verb will become inaccurate if the
  1299. * HDA link is powered off at hot plug or hw initialization time.
  1300. */
  1301. else if (!(snd_hda_param_read(codec, codec->afg, AC_PAR_POWER_STATE) &
  1302. AC_PWRST_EPSS))
  1303. codec->bus->power_keep_link_on = 1;
  1304. #endif
  1305. return 0;
  1306. }
  1307. /*
  1308. */
  1309. static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
  1310. {
  1311. struct hda_spdif_out *spdif;
  1312. bool non_pcm;
  1313. mutex_lock(&codec->spdif_mutex);
  1314. spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
  1315. non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
  1316. mutex_unlock(&codec->spdif_mutex);
  1317. return non_pcm;
  1318. }
  1319. /*
  1320. * HDMI callbacks
  1321. */
  1322. static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1323. struct hda_codec *codec,
  1324. unsigned int stream_tag,
  1325. unsigned int format,
  1326. struct snd_pcm_substream *substream)
  1327. {
  1328. hda_nid_t cvt_nid = hinfo->nid;
  1329. struct hdmi_spec *spec = codec->spec;
  1330. int pin_idx = hinfo_to_pin_index(spec, hinfo);
  1331. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1332. hda_nid_t pin_nid = per_pin->pin_nid;
  1333. bool non_pcm;
  1334. non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
  1335. per_pin->channels = substream->runtime->channels;
  1336. per_pin->setup = true;
  1337. hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
  1338. return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
  1339. }
  1340. static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1341. struct hda_codec *codec,
  1342. struct snd_pcm_substream *substream)
  1343. {
  1344. snd_hda_codec_cleanup_stream(codec, hinfo->nid);
  1345. return 0;
  1346. }
  1347. static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
  1348. struct hda_codec *codec,
  1349. struct snd_pcm_substream *substream)
  1350. {
  1351. struct hdmi_spec *spec = codec->spec;
  1352. int cvt_idx, pin_idx;
  1353. struct hdmi_spec_per_cvt *per_cvt;
  1354. struct hdmi_spec_per_pin *per_pin;
  1355. if (hinfo->nid) {
  1356. cvt_idx = cvt_nid_to_cvt_index(spec, hinfo->nid);
  1357. if (snd_BUG_ON(cvt_idx < 0))
  1358. return -EINVAL;
  1359. per_cvt = get_cvt(spec, cvt_idx);
  1360. snd_BUG_ON(!per_cvt->assigned);
  1361. per_cvt->assigned = 0;
  1362. hinfo->nid = 0;
  1363. pin_idx = hinfo_to_pin_index(spec, hinfo);
  1364. if (snd_BUG_ON(pin_idx < 0))
  1365. return -EINVAL;
  1366. per_pin = get_pin(spec, pin_idx);
  1367. snd_hda_spdif_ctls_unassign(codec, pin_idx);
  1368. per_pin->chmap_set = false;
  1369. memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
  1370. per_pin->setup = false;
  1371. per_pin->channels = 0;
  1372. }
  1373. return 0;
  1374. }
  1375. static const struct hda_pcm_ops generic_ops = {
  1376. .open = hdmi_pcm_open,
  1377. .close = hdmi_pcm_close,
  1378. .prepare = generic_hdmi_playback_pcm_prepare,
  1379. .cleanup = generic_hdmi_playback_pcm_cleanup,
  1380. };
  1381. /*
  1382. * ALSA API channel-map control callbacks
  1383. */
  1384. static int hdmi_chmap_ctl_info(struct snd_kcontrol *kcontrol,
  1385. struct snd_ctl_elem_info *uinfo)
  1386. {
  1387. struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
  1388. struct hda_codec *codec = info->private_data;
  1389. struct hdmi_spec *spec = codec->spec;
  1390. uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
  1391. uinfo->count = spec->channels_max;
  1392. uinfo->value.integer.min = 0;
  1393. uinfo->value.integer.max = SNDRV_CHMAP_LAST;
  1394. return 0;
  1395. }
  1396. static int hdmi_chmap_ctl_tlv(struct snd_kcontrol *kcontrol, int op_flag,
  1397. unsigned int size, unsigned int __user *tlv)
  1398. {
  1399. struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
  1400. struct hda_codec *codec = info->private_data;
  1401. struct hdmi_spec *spec = codec->spec;
  1402. const unsigned int valid_mask =
  1403. FL | FR | RL | RR | LFE | FC | RLC | RRC;
  1404. unsigned int __user *dst;
  1405. int chs, count = 0;
  1406. if (size < 8)
  1407. return -ENOMEM;
  1408. if (put_user(SNDRV_CTL_TLVT_CONTAINER, tlv))
  1409. return -EFAULT;
  1410. size -= 8;
  1411. dst = tlv + 2;
  1412. for (chs = 2; chs <= spec->channels_max; chs++) {
  1413. int i, c;
  1414. struct cea_channel_speaker_allocation *cap;
  1415. cap = channel_allocations;
  1416. for (i = 0; i < ARRAY_SIZE(channel_allocations); i++, cap++) {
  1417. int chs_bytes = chs * 4;
  1418. if (cap->channels != chs)
  1419. continue;
  1420. if (cap->spk_mask & ~valid_mask)
  1421. continue;
  1422. if (size < 8)
  1423. return -ENOMEM;
  1424. if (put_user(SNDRV_CTL_TLVT_CHMAP_VAR, dst) ||
  1425. put_user(chs_bytes, dst + 1))
  1426. return -EFAULT;
  1427. dst += 2;
  1428. size -= 8;
  1429. count += 8;
  1430. if (size < chs_bytes)
  1431. return -ENOMEM;
  1432. size -= chs_bytes;
  1433. count += chs_bytes;
  1434. for (c = 7; c >= 0; c--) {
  1435. int spk = cap->speakers[c];
  1436. if (!spk)
  1437. continue;
  1438. if (put_user(spk_to_chmap(spk), dst))
  1439. return -EFAULT;
  1440. dst++;
  1441. }
  1442. }
  1443. }
  1444. if (put_user(count, tlv + 1))
  1445. return -EFAULT;
  1446. return 0;
  1447. }
  1448. static int hdmi_chmap_ctl_get(struct snd_kcontrol *kcontrol,
  1449. struct snd_ctl_elem_value *ucontrol)
  1450. {
  1451. struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
  1452. struct hda_codec *codec = info->private_data;
  1453. struct hdmi_spec *spec = codec->spec;
  1454. int pin_idx = kcontrol->private_value;
  1455. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1456. int i;
  1457. for (i = 0; i < ARRAY_SIZE(per_pin->chmap); i++)
  1458. ucontrol->value.integer.value[i] = per_pin->chmap[i];
  1459. return 0;
  1460. }
  1461. static int hdmi_chmap_ctl_put(struct snd_kcontrol *kcontrol,
  1462. struct snd_ctl_elem_value *ucontrol)
  1463. {
  1464. struct snd_pcm_chmap *info = snd_kcontrol_chip(kcontrol);
  1465. struct hda_codec *codec = info->private_data;
  1466. struct hdmi_spec *spec = codec->spec;
  1467. int pin_idx = kcontrol->private_value;
  1468. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1469. unsigned int ctl_idx;
  1470. struct snd_pcm_substream *substream;
  1471. unsigned char chmap[8];
  1472. int i, ca, prepared = 0;
  1473. ctl_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
  1474. substream = snd_pcm_chmap_substream(info, ctl_idx);
  1475. if (!substream || !substream->runtime)
  1476. return 0; /* just for avoiding error from alsactl restore */
  1477. switch (substream->runtime->status->state) {
  1478. case SNDRV_PCM_STATE_OPEN:
  1479. case SNDRV_PCM_STATE_SETUP:
  1480. break;
  1481. case SNDRV_PCM_STATE_PREPARED:
  1482. prepared = 1;
  1483. break;
  1484. default:
  1485. return -EBUSY;
  1486. }
  1487. memset(chmap, 0, sizeof(chmap));
  1488. for (i = 0; i < ARRAY_SIZE(chmap); i++)
  1489. chmap[i] = ucontrol->value.integer.value[i];
  1490. if (!memcmp(chmap, per_pin->chmap, sizeof(chmap)))
  1491. return 0;
  1492. ca = hdmi_manual_channel_allocation(ARRAY_SIZE(chmap), chmap);
  1493. if (ca < 0)
  1494. return -EINVAL;
  1495. per_pin->chmap_set = true;
  1496. memcpy(per_pin->chmap, chmap, sizeof(chmap));
  1497. if (prepared)
  1498. hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
  1499. return 0;
  1500. }
  1501. static int generic_hdmi_build_pcms(struct hda_codec *codec)
  1502. {
  1503. struct hdmi_spec *spec = codec->spec;
  1504. int pin_idx;
  1505. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1506. struct hda_pcm *info;
  1507. struct hda_pcm_stream *pstr;
  1508. struct hdmi_spec_per_pin *per_pin;
  1509. per_pin = get_pin(spec, pin_idx);
  1510. sprintf(per_pin->pcm_name, "HDMI %d", pin_idx);
  1511. info = snd_array_new(&spec->pcm_rec);
  1512. if (!info)
  1513. return -ENOMEM;
  1514. info->name = per_pin->pcm_name;
  1515. info->pcm_type = HDA_PCM_TYPE_HDMI;
  1516. info->own_chmap = true;
  1517. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  1518. pstr->substreams = 1;
  1519. pstr->ops = generic_ops;
  1520. /* other pstr fields are set in open */
  1521. }
  1522. codec->num_pcms = spec->num_pins;
  1523. codec->pcm_info = spec->pcm_rec.list;
  1524. return 0;
  1525. }
  1526. static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
  1527. {
  1528. char hdmi_str[32] = "HDMI/DP";
  1529. struct hdmi_spec *spec = codec->spec;
  1530. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1531. int pcmdev = get_pcm_rec(spec, pin_idx)->device;
  1532. if (pcmdev > 0)
  1533. sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
  1534. if (!is_jack_detectable(codec, per_pin->pin_nid))
  1535. strncat(hdmi_str, " Phantom",
  1536. sizeof(hdmi_str) - strlen(hdmi_str) - 1);
  1537. return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
  1538. }
  1539. static int generic_hdmi_build_controls(struct hda_codec *codec)
  1540. {
  1541. struct hdmi_spec *spec = codec->spec;
  1542. int err;
  1543. int pin_idx;
  1544. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1545. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1546. err = generic_hdmi_build_jack(codec, pin_idx);
  1547. if (err < 0)
  1548. return err;
  1549. err = snd_hda_create_dig_out_ctls(codec,
  1550. per_pin->pin_nid,
  1551. per_pin->mux_nids[0],
  1552. HDA_PCM_TYPE_HDMI);
  1553. if (err < 0)
  1554. return err;
  1555. snd_hda_spdif_ctls_unassign(codec, pin_idx);
  1556. /* add control for ELD Bytes */
  1557. err = hdmi_create_eld_ctl(codec, pin_idx,
  1558. get_pcm_rec(spec, pin_idx)->device);
  1559. if (err < 0)
  1560. return err;
  1561. hdmi_present_sense(per_pin, 0);
  1562. }
  1563. /* add channel maps */
  1564. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1565. struct snd_pcm_chmap *chmap;
  1566. struct snd_kcontrol *kctl;
  1567. int i;
  1568. if (!codec->pcm_info[pin_idx].pcm)
  1569. break;
  1570. err = snd_pcm_add_chmap_ctls(codec->pcm_info[pin_idx].pcm,
  1571. SNDRV_PCM_STREAM_PLAYBACK,
  1572. NULL, 0, pin_idx, &chmap);
  1573. if (err < 0)
  1574. return err;
  1575. /* override handlers */
  1576. chmap->private_data = codec;
  1577. kctl = chmap->kctl;
  1578. for (i = 0; i < kctl->count; i++)
  1579. kctl->vd[i].access |= SNDRV_CTL_ELEM_ACCESS_WRITE;
  1580. kctl->info = hdmi_chmap_ctl_info;
  1581. kctl->get = hdmi_chmap_ctl_get;
  1582. kctl->put = hdmi_chmap_ctl_put;
  1583. kctl->tlv.c = hdmi_chmap_ctl_tlv;
  1584. }
  1585. return 0;
  1586. }
  1587. static int generic_hdmi_init_per_pins(struct hda_codec *codec)
  1588. {
  1589. struct hdmi_spec *spec = codec->spec;
  1590. int pin_idx;
  1591. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1592. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1593. struct hdmi_eld *eld = &per_pin->sink_eld;
  1594. per_pin->codec = codec;
  1595. mutex_init(&eld->lock);
  1596. INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
  1597. snd_hda_eld_proc_new(codec, eld, pin_idx);
  1598. }
  1599. return 0;
  1600. }
  1601. static int generic_hdmi_init(struct hda_codec *codec)
  1602. {
  1603. struct hdmi_spec *spec = codec->spec;
  1604. int pin_idx;
  1605. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1606. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1607. hda_nid_t pin_nid = per_pin->pin_nid;
  1608. hdmi_init_pin(codec, pin_nid);
  1609. snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
  1610. }
  1611. return 0;
  1612. }
  1613. static void hdmi_array_init(struct hdmi_spec *spec, int nums)
  1614. {
  1615. snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
  1616. snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
  1617. snd_array_init(&spec->pcm_rec, sizeof(struct hda_pcm), nums);
  1618. }
  1619. static void hdmi_array_free(struct hdmi_spec *spec)
  1620. {
  1621. snd_array_free(&spec->pins);
  1622. snd_array_free(&spec->cvts);
  1623. snd_array_free(&spec->pcm_rec);
  1624. }
  1625. static void generic_hdmi_free(struct hda_codec *codec)
  1626. {
  1627. struct hdmi_spec *spec = codec->spec;
  1628. int pin_idx;
  1629. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1630. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1631. struct hdmi_eld *eld = &per_pin->sink_eld;
  1632. cancel_delayed_work(&per_pin->work);
  1633. snd_hda_eld_proc_free(codec, eld);
  1634. }
  1635. flush_workqueue(codec->bus->workq);
  1636. hdmi_array_free(spec);
  1637. kfree(spec);
  1638. }
  1639. #ifdef CONFIG_PM
  1640. static int generic_hdmi_resume(struct hda_codec *codec)
  1641. {
  1642. struct hdmi_spec *spec = codec->spec;
  1643. int pin_idx;
  1644. generic_hdmi_init(codec);
  1645. snd_hda_codec_resume_amp(codec);
  1646. snd_hda_codec_resume_cache(codec);
  1647. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1648. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1649. hdmi_present_sense(per_pin, 1);
  1650. }
  1651. return 0;
  1652. }
  1653. #endif
  1654. static const struct hda_codec_ops generic_hdmi_patch_ops = {
  1655. .init = generic_hdmi_init,
  1656. .free = generic_hdmi_free,
  1657. .build_pcms = generic_hdmi_build_pcms,
  1658. .build_controls = generic_hdmi_build_controls,
  1659. .unsol_event = hdmi_unsol_event,
  1660. #ifdef CONFIG_PM
  1661. .resume = generic_hdmi_resume,
  1662. #endif
  1663. };
  1664. static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
  1665. hda_nid_t nid)
  1666. {
  1667. struct hdmi_spec *spec = codec->spec;
  1668. hda_nid_t conns[4];
  1669. int nconns;
  1670. nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
  1671. if (nconns == spec->num_cvts &&
  1672. !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
  1673. return;
  1674. /* override pins connection list */
  1675. snd_printdd("hdmi: haswell: override pin connection 0x%x\n", nid);
  1676. snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
  1677. }
  1678. #define INTEL_VENDOR_NID 0x08
  1679. #define INTEL_GET_VENDOR_VERB 0xf81
  1680. #define INTEL_SET_VENDOR_VERB 0x781
  1681. #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
  1682. #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
  1683. static void intel_haswell_enable_all_pins(struct hda_codec *codec,
  1684. bool update_tree)
  1685. {
  1686. unsigned int vendor_param;
  1687. vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
  1688. INTEL_GET_VENDOR_VERB, 0);
  1689. if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
  1690. return;
  1691. vendor_param |= INTEL_EN_ALL_PIN_CVTS;
  1692. vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
  1693. INTEL_SET_VENDOR_VERB, vendor_param);
  1694. if (vendor_param == -1)
  1695. return;
  1696. if (update_tree)
  1697. snd_hda_codec_update_widgets(codec);
  1698. }
  1699. static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
  1700. {
  1701. unsigned int vendor_param;
  1702. vendor_param = snd_hda_codec_read(codec, INTEL_VENDOR_NID, 0,
  1703. INTEL_GET_VENDOR_VERB, 0);
  1704. if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
  1705. return;
  1706. /* enable DP1.2 mode */
  1707. vendor_param |= INTEL_EN_DP12;
  1708. snd_hda_codec_write_cache(codec, INTEL_VENDOR_NID, 0,
  1709. INTEL_SET_VENDOR_VERB, vendor_param);
  1710. }
  1711. /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
  1712. * Otherwise you may get severe h/w communication errors.
  1713. */
  1714. static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  1715. unsigned int power_state)
  1716. {
  1717. if (power_state == AC_PWRST_D0) {
  1718. intel_haswell_enable_all_pins(codec, false);
  1719. intel_haswell_fixup_enable_dp12(codec);
  1720. }
  1721. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
  1722. snd_hda_codec_set_power_to_all(codec, fg, power_state);
  1723. }
  1724. static int patch_generic_hdmi(struct hda_codec *codec)
  1725. {
  1726. struct hdmi_spec *spec;
  1727. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1728. if (spec == NULL)
  1729. return -ENOMEM;
  1730. codec->spec = spec;
  1731. hdmi_array_init(spec, 4);
  1732. if (is_haswell(codec)) {
  1733. intel_haswell_enable_all_pins(codec, true);
  1734. intel_haswell_fixup_enable_dp12(codec);
  1735. }
  1736. if (hdmi_parse_codec(codec) < 0) {
  1737. codec->spec = NULL;
  1738. kfree(spec);
  1739. return -EINVAL;
  1740. }
  1741. codec->patch_ops = generic_hdmi_patch_ops;
  1742. if (is_haswell(codec)) {
  1743. codec->patch_ops.set_power_state = haswell_set_power_state;
  1744. codec->dp_mst = true;
  1745. }
  1746. generic_hdmi_init_per_pins(codec);
  1747. init_channel_allocations();
  1748. return 0;
  1749. }
  1750. /*
  1751. * Shared non-generic implementations
  1752. */
  1753. static int simple_playback_build_pcms(struct hda_codec *codec)
  1754. {
  1755. struct hdmi_spec *spec = codec->spec;
  1756. struct hda_pcm *info;
  1757. unsigned int chans;
  1758. struct hda_pcm_stream *pstr;
  1759. struct hdmi_spec_per_cvt *per_cvt;
  1760. per_cvt = get_cvt(spec, 0);
  1761. chans = get_wcaps(codec, per_cvt->cvt_nid);
  1762. chans = get_wcaps_channels(chans);
  1763. info = snd_array_new(&spec->pcm_rec);
  1764. if (!info)
  1765. return -ENOMEM;
  1766. info->name = get_pin(spec, 0)->pcm_name;
  1767. sprintf(info->name, "HDMI 0");
  1768. info->pcm_type = HDA_PCM_TYPE_HDMI;
  1769. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  1770. *pstr = spec->pcm_playback;
  1771. pstr->nid = per_cvt->cvt_nid;
  1772. if (pstr->channels_max <= 2 && chans && chans <= 16)
  1773. pstr->channels_max = chans;
  1774. codec->num_pcms = 1;
  1775. codec->pcm_info = info;
  1776. return 0;
  1777. }
  1778. /* unsolicited event for jack sensing */
  1779. static void simple_hdmi_unsol_event(struct hda_codec *codec,
  1780. unsigned int res)
  1781. {
  1782. snd_hda_jack_set_dirty_all(codec);
  1783. snd_hda_jack_report_sync(codec);
  1784. }
  1785. /* generic_hdmi_build_jack can be used for simple_hdmi, too,
  1786. * as long as spec->pins[] is set correctly
  1787. */
  1788. #define simple_hdmi_build_jack generic_hdmi_build_jack
  1789. static int simple_playback_build_controls(struct hda_codec *codec)
  1790. {
  1791. struct hdmi_spec *spec = codec->spec;
  1792. struct hdmi_spec_per_cvt *per_cvt;
  1793. int err;
  1794. per_cvt = get_cvt(spec, 0);
  1795. err = snd_hda_create_spdif_out_ctls(codec, per_cvt->cvt_nid,
  1796. per_cvt->cvt_nid);
  1797. if (err < 0)
  1798. return err;
  1799. return simple_hdmi_build_jack(codec, 0);
  1800. }
  1801. static int simple_playback_init(struct hda_codec *codec)
  1802. {
  1803. struct hdmi_spec *spec = codec->spec;
  1804. struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
  1805. hda_nid_t pin = per_pin->pin_nid;
  1806. snd_hda_codec_write(codec, pin, 0,
  1807. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  1808. /* some codecs require to unmute the pin */
  1809. if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
  1810. snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  1811. AMP_OUT_UNMUTE);
  1812. snd_hda_jack_detect_enable(codec, pin, pin);
  1813. return 0;
  1814. }
  1815. static void simple_playback_free(struct hda_codec *codec)
  1816. {
  1817. struct hdmi_spec *spec = codec->spec;
  1818. hdmi_array_free(spec);
  1819. kfree(spec);
  1820. }
  1821. /*
  1822. * Nvidia specific implementations
  1823. */
  1824. #define Nv_VERB_SET_Channel_Allocation 0xF79
  1825. #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
  1826. #define Nv_VERB_SET_Audio_Protection_On 0xF98
  1827. #define Nv_VERB_SET_Audio_Protection_Off 0xF99
  1828. #define nvhdmi_master_con_nid_7x 0x04
  1829. #define nvhdmi_master_pin_nid_7x 0x05
  1830. static const hda_nid_t nvhdmi_con_nids_7x[4] = {
  1831. /*front, rear, clfe, rear_surr */
  1832. 0x6, 0x8, 0xa, 0xc,
  1833. };
  1834. static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
  1835. /* set audio protect on */
  1836. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  1837. /* enable digital output on pin widget */
  1838. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1839. {} /* terminator */
  1840. };
  1841. static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
  1842. /* set audio protect on */
  1843. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  1844. /* enable digital output on pin widget */
  1845. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1846. { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1847. { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1848. { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1849. { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  1850. {} /* terminator */
  1851. };
  1852. #ifdef LIMITED_RATE_FMT_SUPPORT
  1853. /* support only the safe format and rate */
  1854. #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
  1855. #define SUPPORTED_MAXBPS 16
  1856. #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  1857. #else
  1858. /* support all rates and formats */
  1859. #define SUPPORTED_RATES \
  1860. (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
  1861. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
  1862. SNDRV_PCM_RATE_192000)
  1863. #define SUPPORTED_MAXBPS 24
  1864. #define SUPPORTED_FORMATS \
  1865. (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  1866. #endif
  1867. static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
  1868. {
  1869. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
  1870. return 0;
  1871. }
  1872. static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
  1873. {
  1874. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
  1875. return 0;
  1876. }
  1877. static unsigned int channels_2_6_8[] = {
  1878. 2, 6, 8
  1879. };
  1880. static unsigned int channels_2_8[] = {
  1881. 2, 8
  1882. };
  1883. static struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
  1884. .count = ARRAY_SIZE(channels_2_6_8),
  1885. .list = channels_2_6_8,
  1886. .mask = 0,
  1887. };
  1888. static struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
  1889. .count = ARRAY_SIZE(channels_2_8),
  1890. .list = channels_2_8,
  1891. .mask = 0,
  1892. };
  1893. static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
  1894. struct hda_codec *codec,
  1895. struct snd_pcm_substream *substream)
  1896. {
  1897. struct hdmi_spec *spec = codec->spec;
  1898. struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
  1899. switch (codec->preset->id) {
  1900. case 0x10de0002:
  1901. case 0x10de0003:
  1902. case 0x10de0005:
  1903. case 0x10de0006:
  1904. hw_constraints_channels = &hw_constraints_2_8_channels;
  1905. break;
  1906. case 0x10de0007:
  1907. hw_constraints_channels = &hw_constraints_2_6_8_channels;
  1908. break;
  1909. default:
  1910. break;
  1911. }
  1912. if (hw_constraints_channels != NULL) {
  1913. snd_pcm_hw_constraint_list(substream->runtime, 0,
  1914. SNDRV_PCM_HW_PARAM_CHANNELS,
  1915. hw_constraints_channels);
  1916. } else {
  1917. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1918. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1919. }
  1920. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  1921. }
  1922. static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
  1923. struct hda_codec *codec,
  1924. struct snd_pcm_substream *substream)
  1925. {
  1926. struct hdmi_spec *spec = codec->spec;
  1927. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  1928. }
  1929. static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1930. struct hda_codec *codec,
  1931. unsigned int stream_tag,
  1932. unsigned int format,
  1933. struct snd_pcm_substream *substream)
  1934. {
  1935. struct hdmi_spec *spec = codec->spec;
  1936. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  1937. stream_tag, format, substream);
  1938. }
  1939. static const struct hda_pcm_stream simple_pcm_playback = {
  1940. .substreams = 1,
  1941. .channels_min = 2,
  1942. .channels_max = 2,
  1943. .ops = {
  1944. .open = simple_playback_pcm_open,
  1945. .close = simple_playback_pcm_close,
  1946. .prepare = simple_playback_pcm_prepare
  1947. },
  1948. };
  1949. static const struct hda_codec_ops simple_hdmi_patch_ops = {
  1950. .build_controls = simple_playback_build_controls,
  1951. .build_pcms = simple_playback_build_pcms,
  1952. .init = simple_playback_init,
  1953. .free = simple_playback_free,
  1954. .unsol_event = simple_hdmi_unsol_event,
  1955. };
  1956. static int patch_simple_hdmi(struct hda_codec *codec,
  1957. hda_nid_t cvt_nid, hda_nid_t pin_nid)
  1958. {
  1959. struct hdmi_spec *spec;
  1960. struct hdmi_spec_per_cvt *per_cvt;
  1961. struct hdmi_spec_per_pin *per_pin;
  1962. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1963. if (!spec)
  1964. return -ENOMEM;
  1965. codec->spec = spec;
  1966. hdmi_array_init(spec, 1);
  1967. spec->multiout.num_dacs = 0; /* no analog */
  1968. spec->multiout.max_channels = 2;
  1969. spec->multiout.dig_out_nid = cvt_nid;
  1970. spec->num_cvts = 1;
  1971. spec->num_pins = 1;
  1972. per_pin = snd_array_new(&spec->pins);
  1973. per_cvt = snd_array_new(&spec->cvts);
  1974. if (!per_pin || !per_cvt) {
  1975. simple_playback_free(codec);
  1976. return -ENOMEM;
  1977. }
  1978. per_cvt->cvt_nid = cvt_nid;
  1979. per_pin->pin_nid = pin_nid;
  1980. spec->pcm_playback = simple_pcm_playback;
  1981. codec->patch_ops = simple_hdmi_patch_ops;
  1982. return 0;
  1983. }
  1984. static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
  1985. int channels)
  1986. {
  1987. unsigned int chanmask;
  1988. int chan = channels ? (channels - 1) : 1;
  1989. switch (channels) {
  1990. default:
  1991. case 0:
  1992. case 2:
  1993. chanmask = 0x00;
  1994. break;
  1995. case 4:
  1996. chanmask = 0x08;
  1997. break;
  1998. case 6:
  1999. chanmask = 0x0b;
  2000. break;
  2001. case 8:
  2002. chanmask = 0x13;
  2003. break;
  2004. }
  2005. /* Set the audio infoframe channel allocation and checksum fields. The
  2006. * channel count is computed implicitly by the hardware. */
  2007. snd_hda_codec_write(codec, 0x1, 0,
  2008. Nv_VERB_SET_Channel_Allocation, chanmask);
  2009. snd_hda_codec_write(codec, 0x1, 0,
  2010. Nv_VERB_SET_Info_Frame_Checksum,
  2011. (0x71 - chan - chanmask));
  2012. }
  2013. static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
  2014. struct hda_codec *codec,
  2015. struct snd_pcm_substream *substream)
  2016. {
  2017. struct hdmi_spec *spec = codec->spec;
  2018. int i;
  2019. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
  2020. 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
  2021. for (i = 0; i < 4; i++) {
  2022. /* set the stream id */
  2023. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  2024. AC_VERB_SET_CHANNEL_STREAMID, 0);
  2025. /* set the stream format */
  2026. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  2027. AC_VERB_SET_STREAM_FORMAT, 0);
  2028. }
  2029. /* The audio hardware sends a channel count of 0x7 (8ch) when all the
  2030. * streams are disabled. */
  2031. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  2032. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  2033. }
  2034. static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
  2035. struct hda_codec *codec,
  2036. unsigned int stream_tag,
  2037. unsigned int format,
  2038. struct snd_pcm_substream *substream)
  2039. {
  2040. int chs;
  2041. unsigned int dataDCC2, channel_id;
  2042. int i;
  2043. struct hdmi_spec *spec = codec->spec;
  2044. struct hda_spdif_out *spdif;
  2045. struct hdmi_spec_per_cvt *per_cvt;
  2046. mutex_lock(&codec->spdif_mutex);
  2047. per_cvt = get_cvt(spec, 0);
  2048. spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
  2049. chs = substream->runtime->channels;
  2050. dataDCC2 = 0x2;
  2051. /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
  2052. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
  2053. snd_hda_codec_write(codec,
  2054. nvhdmi_master_con_nid_7x,
  2055. 0,
  2056. AC_VERB_SET_DIGI_CONVERT_1,
  2057. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  2058. /* set the stream id */
  2059. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  2060. AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
  2061. /* set the stream format */
  2062. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  2063. AC_VERB_SET_STREAM_FORMAT, format);
  2064. /* turn on again (if needed) */
  2065. /* enable and set the channel status audio/data flag */
  2066. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
  2067. snd_hda_codec_write(codec,
  2068. nvhdmi_master_con_nid_7x,
  2069. 0,
  2070. AC_VERB_SET_DIGI_CONVERT_1,
  2071. spdif->ctls & 0xff);
  2072. snd_hda_codec_write(codec,
  2073. nvhdmi_master_con_nid_7x,
  2074. 0,
  2075. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  2076. }
  2077. for (i = 0; i < 4; i++) {
  2078. if (chs == 2)
  2079. channel_id = 0;
  2080. else
  2081. channel_id = i * 2;
  2082. /* turn off SPDIF once;
  2083. *otherwise the IEC958 bits won't be updated
  2084. */
  2085. if (codec->spdif_status_reset &&
  2086. (spdif->ctls & AC_DIG1_ENABLE))
  2087. snd_hda_codec_write(codec,
  2088. nvhdmi_con_nids_7x[i],
  2089. 0,
  2090. AC_VERB_SET_DIGI_CONVERT_1,
  2091. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  2092. /* set the stream id */
  2093. snd_hda_codec_write(codec,
  2094. nvhdmi_con_nids_7x[i],
  2095. 0,
  2096. AC_VERB_SET_CHANNEL_STREAMID,
  2097. (stream_tag << 4) | channel_id);
  2098. /* set the stream format */
  2099. snd_hda_codec_write(codec,
  2100. nvhdmi_con_nids_7x[i],
  2101. 0,
  2102. AC_VERB_SET_STREAM_FORMAT,
  2103. format);
  2104. /* turn on again (if needed) */
  2105. /* enable and set the channel status audio/data flag */
  2106. if (codec->spdif_status_reset &&
  2107. (spdif->ctls & AC_DIG1_ENABLE)) {
  2108. snd_hda_codec_write(codec,
  2109. nvhdmi_con_nids_7x[i],
  2110. 0,
  2111. AC_VERB_SET_DIGI_CONVERT_1,
  2112. spdif->ctls & 0xff);
  2113. snd_hda_codec_write(codec,
  2114. nvhdmi_con_nids_7x[i],
  2115. 0,
  2116. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  2117. }
  2118. }
  2119. nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
  2120. mutex_unlock(&codec->spdif_mutex);
  2121. return 0;
  2122. }
  2123. static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
  2124. .substreams = 1,
  2125. .channels_min = 2,
  2126. .channels_max = 8,
  2127. .nid = nvhdmi_master_con_nid_7x,
  2128. .rates = SUPPORTED_RATES,
  2129. .maxbps = SUPPORTED_MAXBPS,
  2130. .formats = SUPPORTED_FORMATS,
  2131. .ops = {
  2132. .open = simple_playback_pcm_open,
  2133. .close = nvhdmi_8ch_7x_pcm_close,
  2134. .prepare = nvhdmi_8ch_7x_pcm_prepare
  2135. },
  2136. };
  2137. static int patch_nvhdmi_2ch(struct hda_codec *codec)
  2138. {
  2139. struct hdmi_spec *spec;
  2140. int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
  2141. nvhdmi_master_pin_nid_7x);
  2142. if (err < 0)
  2143. return err;
  2144. codec->patch_ops.init = nvhdmi_7x_init_2ch;
  2145. /* override the PCM rates, etc, as the codec doesn't give full list */
  2146. spec = codec->spec;
  2147. spec->pcm_playback.rates = SUPPORTED_RATES;
  2148. spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
  2149. spec->pcm_playback.formats = SUPPORTED_FORMATS;
  2150. return 0;
  2151. }
  2152. static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
  2153. {
  2154. struct hdmi_spec *spec = codec->spec;
  2155. int err = simple_playback_build_pcms(codec);
  2156. if (!err) {
  2157. struct hda_pcm *info = get_pcm_rec(spec, 0);
  2158. info->own_chmap = true;
  2159. }
  2160. return err;
  2161. }
  2162. static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
  2163. {
  2164. struct hdmi_spec *spec = codec->spec;
  2165. struct hda_pcm *info;
  2166. struct snd_pcm_chmap *chmap;
  2167. int err;
  2168. err = simple_playback_build_controls(codec);
  2169. if (err < 0)
  2170. return err;
  2171. /* add channel maps */
  2172. info = get_pcm_rec(spec, 0);
  2173. err = snd_pcm_add_chmap_ctls(info->pcm,
  2174. SNDRV_PCM_STREAM_PLAYBACK,
  2175. snd_pcm_alt_chmaps, 8, 0, &chmap);
  2176. if (err < 0)
  2177. return err;
  2178. switch (codec->preset->id) {
  2179. case 0x10de0002:
  2180. case 0x10de0003:
  2181. case 0x10de0005:
  2182. case 0x10de0006:
  2183. chmap->channel_mask = (1U << 2) | (1U << 8);
  2184. break;
  2185. case 0x10de0007:
  2186. chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
  2187. }
  2188. return 0;
  2189. }
  2190. static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
  2191. {
  2192. struct hdmi_spec *spec;
  2193. int err = patch_nvhdmi_2ch(codec);
  2194. if (err < 0)
  2195. return err;
  2196. spec = codec->spec;
  2197. spec->multiout.max_channels = 8;
  2198. spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
  2199. codec->patch_ops.init = nvhdmi_7x_init_8ch;
  2200. codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
  2201. codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
  2202. /* Initialize the audio infoframe channel mask and checksum to something
  2203. * valid */
  2204. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  2205. return 0;
  2206. }
  2207. /*
  2208. * ATI-specific implementations
  2209. *
  2210. * FIXME: we may omit the whole this and use the generic code once after
  2211. * it's confirmed to work.
  2212. */
  2213. #define ATIHDMI_CVT_NID 0x02 /* audio converter */
  2214. #define ATIHDMI_PIN_NID 0x03 /* HDMI output pin */
  2215. static int atihdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  2216. struct hda_codec *codec,
  2217. unsigned int stream_tag,
  2218. unsigned int format,
  2219. struct snd_pcm_substream *substream)
  2220. {
  2221. struct hdmi_spec *spec = codec->spec;
  2222. struct hdmi_spec_per_cvt *per_cvt = get_cvt(spec, 0);
  2223. int chans = substream->runtime->channels;
  2224. int i, err;
  2225. err = simple_playback_pcm_prepare(hinfo, codec, stream_tag, format,
  2226. substream);
  2227. if (err < 0)
  2228. return err;
  2229. snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
  2230. AC_VERB_SET_CVT_CHAN_COUNT, chans - 1);
  2231. /* FIXME: XXX */
  2232. for (i = 0; i < chans; i++) {
  2233. snd_hda_codec_write(codec, per_cvt->cvt_nid, 0,
  2234. AC_VERB_SET_HDMI_CHAN_SLOT,
  2235. (i << 4) | i);
  2236. }
  2237. return 0;
  2238. }
  2239. static int patch_atihdmi(struct hda_codec *codec)
  2240. {
  2241. struct hdmi_spec *spec;
  2242. int err = patch_simple_hdmi(codec, ATIHDMI_CVT_NID, ATIHDMI_PIN_NID);
  2243. if (err < 0)
  2244. return err;
  2245. spec = codec->spec;
  2246. spec->pcm_playback.ops.prepare = atihdmi_playback_pcm_prepare;
  2247. return 0;
  2248. }
  2249. /* VIA HDMI Implementation */
  2250. #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
  2251. #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
  2252. static int patch_via_hdmi(struct hda_codec *codec)
  2253. {
  2254. return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
  2255. }
  2256. /*
  2257. * patch entries
  2258. */
  2259. static const struct hda_codec_preset snd_hda_preset_hdmi[] = {
  2260. { .id = 0x1002793c, .name = "RS600 HDMI", .patch = patch_atihdmi },
  2261. { .id = 0x10027919, .name = "RS600 HDMI", .patch = patch_atihdmi },
  2262. { .id = 0x1002791a, .name = "RS690/780 HDMI", .patch = patch_atihdmi },
  2263. { .id = 0x1002aa01, .name = "R6xx HDMI", .patch = patch_generic_hdmi },
  2264. { .id = 0x10951390, .name = "SiI1390 HDMI", .patch = patch_generic_hdmi },
  2265. { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_generic_hdmi },
  2266. { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_generic_hdmi },
  2267. { .id = 0x10de0002, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  2268. { .id = 0x10de0003, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  2269. { .id = 0x10de0005, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  2270. { .id = 0x10de0006, .name = "MCP77/78 HDMI", .patch = patch_nvhdmi_8ch_7x },
  2271. { .id = 0x10de0007, .name = "MCP79/7A HDMI", .patch = patch_nvhdmi_8ch_7x },
  2272. { .id = 0x10de000a, .name = "GPU 0a HDMI/DP", .patch = patch_generic_hdmi },
  2273. { .id = 0x10de000b, .name = "GPU 0b HDMI/DP", .patch = patch_generic_hdmi },
  2274. { .id = 0x10de000c, .name = "MCP89 HDMI", .patch = patch_generic_hdmi },
  2275. { .id = 0x10de000d, .name = "GPU 0d HDMI/DP", .patch = patch_generic_hdmi },
  2276. { .id = 0x10de0010, .name = "GPU 10 HDMI/DP", .patch = patch_generic_hdmi },
  2277. { .id = 0x10de0011, .name = "GPU 11 HDMI/DP", .patch = patch_generic_hdmi },
  2278. { .id = 0x10de0012, .name = "GPU 12 HDMI/DP", .patch = patch_generic_hdmi },
  2279. { .id = 0x10de0013, .name = "GPU 13 HDMI/DP", .patch = patch_generic_hdmi },
  2280. { .id = 0x10de0014, .name = "GPU 14 HDMI/DP", .patch = patch_generic_hdmi },
  2281. { .id = 0x10de0015, .name = "GPU 15 HDMI/DP", .patch = patch_generic_hdmi },
  2282. { .id = 0x10de0016, .name = "GPU 16 HDMI/DP", .patch = patch_generic_hdmi },
  2283. /* 17 is known to be absent */
  2284. { .id = 0x10de0018, .name = "GPU 18 HDMI/DP", .patch = patch_generic_hdmi },
  2285. { .id = 0x10de0019, .name = "GPU 19 HDMI/DP", .patch = patch_generic_hdmi },
  2286. { .id = 0x10de001a, .name = "GPU 1a HDMI/DP", .patch = patch_generic_hdmi },
  2287. { .id = 0x10de001b, .name = "GPU 1b HDMI/DP", .patch = patch_generic_hdmi },
  2288. { .id = 0x10de001c, .name = "GPU 1c HDMI/DP", .patch = patch_generic_hdmi },
  2289. { .id = 0x10de0040, .name = "GPU 40 HDMI/DP", .patch = patch_generic_hdmi },
  2290. { .id = 0x10de0041, .name = "GPU 41 HDMI/DP", .patch = patch_generic_hdmi },
  2291. { .id = 0x10de0042, .name = "GPU 42 HDMI/DP", .patch = patch_generic_hdmi },
  2292. { .id = 0x10de0043, .name = "GPU 43 HDMI/DP", .patch = patch_generic_hdmi },
  2293. { .id = 0x10de0044, .name = "GPU 44 HDMI/DP", .patch = patch_generic_hdmi },
  2294. { .id = 0x10de0051, .name = "GPU 51 HDMI/DP", .patch = patch_generic_hdmi },
  2295. { .id = 0x10de0060, .name = "GPU 60 HDMI/DP", .patch = patch_generic_hdmi },
  2296. { .id = 0x10de0067, .name = "MCP67 HDMI", .patch = patch_nvhdmi_2ch },
  2297. { .id = 0x10de8001, .name = "MCP73 HDMI", .patch = patch_nvhdmi_2ch },
  2298. { .id = 0x11069f80, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
  2299. { .id = 0x11069f81, .name = "VX900 HDMI/DP", .patch = patch_via_hdmi },
  2300. { .id = 0x11069f84, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
  2301. { .id = 0x11069f85, .name = "VX11 HDMI/DP", .patch = patch_generic_hdmi },
  2302. { .id = 0x80860054, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
  2303. { .id = 0x80862801, .name = "Bearlake HDMI", .patch = patch_generic_hdmi },
  2304. { .id = 0x80862802, .name = "Cantiga HDMI", .patch = patch_generic_hdmi },
  2305. { .id = 0x80862803, .name = "Eaglelake HDMI", .patch = patch_generic_hdmi },
  2306. { .id = 0x80862804, .name = "IbexPeak HDMI", .patch = patch_generic_hdmi },
  2307. { .id = 0x80862805, .name = "CougarPoint HDMI", .patch = patch_generic_hdmi },
  2308. { .id = 0x80862806, .name = "PantherPoint HDMI", .patch = patch_generic_hdmi },
  2309. { .id = 0x80862807, .name = "Haswell HDMI", .patch = patch_generic_hdmi },
  2310. { .id = 0x80862880, .name = "CedarTrail HDMI", .patch = patch_generic_hdmi },
  2311. { .id = 0x808629fb, .name = "Crestline HDMI", .patch = patch_generic_hdmi },
  2312. {} /* terminator */
  2313. };
  2314. MODULE_ALIAS("snd-hda-codec-id:1002793c");
  2315. MODULE_ALIAS("snd-hda-codec-id:10027919");
  2316. MODULE_ALIAS("snd-hda-codec-id:1002791a");
  2317. MODULE_ALIAS("snd-hda-codec-id:1002aa01");
  2318. MODULE_ALIAS("snd-hda-codec-id:10951390");
  2319. MODULE_ALIAS("snd-hda-codec-id:10951392");
  2320. MODULE_ALIAS("snd-hda-codec-id:10de0002");
  2321. MODULE_ALIAS("snd-hda-codec-id:10de0003");
  2322. MODULE_ALIAS("snd-hda-codec-id:10de0005");
  2323. MODULE_ALIAS("snd-hda-codec-id:10de0006");
  2324. MODULE_ALIAS("snd-hda-codec-id:10de0007");
  2325. MODULE_ALIAS("snd-hda-codec-id:10de000a");
  2326. MODULE_ALIAS("snd-hda-codec-id:10de000b");
  2327. MODULE_ALIAS("snd-hda-codec-id:10de000c");
  2328. MODULE_ALIAS("snd-hda-codec-id:10de000d");
  2329. MODULE_ALIAS("snd-hda-codec-id:10de0010");
  2330. MODULE_ALIAS("snd-hda-codec-id:10de0011");
  2331. MODULE_ALIAS("snd-hda-codec-id:10de0012");
  2332. MODULE_ALIAS("snd-hda-codec-id:10de0013");
  2333. MODULE_ALIAS("snd-hda-codec-id:10de0014");
  2334. MODULE_ALIAS("snd-hda-codec-id:10de0015");
  2335. MODULE_ALIAS("snd-hda-codec-id:10de0016");
  2336. MODULE_ALIAS("snd-hda-codec-id:10de0018");
  2337. MODULE_ALIAS("snd-hda-codec-id:10de0019");
  2338. MODULE_ALIAS("snd-hda-codec-id:10de001a");
  2339. MODULE_ALIAS("snd-hda-codec-id:10de001b");
  2340. MODULE_ALIAS("snd-hda-codec-id:10de001c");
  2341. MODULE_ALIAS("snd-hda-codec-id:10de0040");
  2342. MODULE_ALIAS("snd-hda-codec-id:10de0041");
  2343. MODULE_ALIAS("snd-hda-codec-id:10de0042");
  2344. MODULE_ALIAS("snd-hda-codec-id:10de0043");
  2345. MODULE_ALIAS("snd-hda-codec-id:10de0044");
  2346. MODULE_ALIAS("snd-hda-codec-id:10de0051");
  2347. MODULE_ALIAS("snd-hda-codec-id:10de0060");
  2348. MODULE_ALIAS("snd-hda-codec-id:10de0067");
  2349. MODULE_ALIAS("snd-hda-codec-id:10de8001");
  2350. MODULE_ALIAS("snd-hda-codec-id:11069f80");
  2351. MODULE_ALIAS("snd-hda-codec-id:11069f81");
  2352. MODULE_ALIAS("snd-hda-codec-id:11069f84");
  2353. MODULE_ALIAS("snd-hda-codec-id:11069f85");
  2354. MODULE_ALIAS("snd-hda-codec-id:17e80047");
  2355. MODULE_ALIAS("snd-hda-codec-id:80860054");
  2356. MODULE_ALIAS("snd-hda-codec-id:80862801");
  2357. MODULE_ALIAS("snd-hda-codec-id:80862802");
  2358. MODULE_ALIAS("snd-hda-codec-id:80862803");
  2359. MODULE_ALIAS("snd-hda-codec-id:80862804");
  2360. MODULE_ALIAS("snd-hda-codec-id:80862805");
  2361. MODULE_ALIAS("snd-hda-codec-id:80862806");
  2362. MODULE_ALIAS("snd-hda-codec-id:80862807");
  2363. MODULE_ALIAS("snd-hda-codec-id:80862880");
  2364. MODULE_ALIAS("snd-hda-codec-id:808629fb");
  2365. MODULE_LICENSE("GPL");
  2366. MODULE_DESCRIPTION("HDMI HD-audio codec");
  2367. MODULE_ALIAS("snd-hda-codec-intelhdmi");
  2368. MODULE_ALIAS("snd-hda-codec-nvhdmi");
  2369. MODULE_ALIAS("snd-hda-codec-atihdmi");
  2370. static struct hda_codec_preset_list intel_list = {
  2371. .preset = snd_hda_preset_hdmi,
  2372. .owner = THIS_MODULE,
  2373. };
  2374. static int __init patch_hdmi_init(void)
  2375. {
  2376. return snd_hda_add_codec_preset(&intel_list);
  2377. }
  2378. static void __exit patch_hdmi_exit(void)
  2379. {
  2380. snd_hda_delete_codec_preset(&intel_list);
  2381. }
  2382. module_init(patch_hdmi_init)
  2383. module_exit(patch_hdmi_exit)