patch_hdmi.c 74 KB

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