patch_hdmi.c 93 KB

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