patch_hdmi.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915
  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 <linux/pm_runtime.h>
  36. #include <sound/core.h>
  37. #include <sound/jack.h>
  38. #include <sound/asoundef.h>
  39. #include <sound/tlv.h>
  40. #include <sound/hdaudio.h>
  41. #include <sound/hda_i915.h>
  42. #include <sound/hda_chmap.h>
  43. #include "hda_codec.h"
  44. #include "hda_local.h"
  45. #include "hda_jack.h"
  46. static bool static_hdmi_pcm;
  47. module_param(static_hdmi_pcm, bool, 0644);
  48. MODULE_PARM_DESC(static_hdmi_pcm, "Don't restrict PCM parameters per ELD info");
  49. #define is_haswell(codec) ((codec)->core.vendor_id == 0x80862807)
  50. #define is_broadwell(codec) ((codec)->core.vendor_id == 0x80862808)
  51. #define is_skylake(codec) ((codec)->core.vendor_id == 0x80862809)
  52. #define is_broxton(codec) ((codec)->core.vendor_id == 0x8086280a)
  53. #define is_kabylake(codec) ((codec)->core.vendor_id == 0x8086280b)
  54. #define is_geminilake(codec) (((codec)->core.vendor_id == 0x8086280d) || \
  55. ((codec)->core.vendor_id == 0x80862800))
  56. #define is_cannonlake(codec) ((codec)->core.vendor_id == 0x8086280c)
  57. #define is_haswell_plus(codec) (is_haswell(codec) || is_broadwell(codec) \
  58. || is_skylake(codec) || is_broxton(codec) \
  59. || is_kabylake(codec)) || is_geminilake(codec) \
  60. || is_cannonlake(codec)
  61. #define is_valleyview(codec) ((codec)->core.vendor_id == 0x80862882)
  62. #define is_cherryview(codec) ((codec)->core.vendor_id == 0x80862883)
  63. #define is_valleyview_plus(codec) (is_valleyview(codec) || is_cherryview(codec))
  64. struct hdmi_spec_per_cvt {
  65. hda_nid_t cvt_nid;
  66. int assigned;
  67. unsigned int channels_min;
  68. unsigned int channels_max;
  69. u32 rates;
  70. u64 formats;
  71. unsigned int maxbps;
  72. };
  73. /* max. connections to a widget */
  74. #define HDA_MAX_CONNECTIONS 32
  75. struct hdmi_spec_per_pin {
  76. hda_nid_t pin_nid;
  77. int dev_id;
  78. /* pin idx, different device entries on the same pin use the same idx */
  79. int pin_nid_idx;
  80. int num_mux_nids;
  81. hda_nid_t mux_nids[HDA_MAX_CONNECTIONS];
  82. int mux_idx;
  83. hda_nid_t cvt_nid;
  84. struct hda_codec *codec;
  85. struct hdmi_eld sink_eld;
  86. struct mutex lock;
  87. struct delayed_work work;
  88. struct hdmi_pcm *pcm; /* pointer to spec->pcm_rec[n] dynamically*/
  89. int pcm_idx; /* which pcm is attached. -1 means no pcm is attached */
  90. int repoll_count;
  91. bool setup; /* the stream has been set up by prepare callback */
  92. int channels; /* current number of channels */
  93. bool non_pcm;
  94. bool chmap_set; /* channel-map override by ALSA API? */
  95. unsigned char chmap[8]; /* ALSA API channel-map */
  96. #ifdef CONFIG_SND_PROC_FS
  97. struct snd_info_entry *proc_entry;
  98. #endif
  99. };
  100. /* operations used by generic code that can be overridden by patches */
  101. struct hdmi_ops {
  102. int (*pin_get_eld)(struct hda_codec *codec, hda_nid_t pin_nid,
  103. unsigned char *buf, int *eld_size);
  104. void (*pin_setup_infoframe)(struct hda_codec *codec, hda_nid_t pin_nid,
  105. int ca, int active_channels, int conn_type);
  106. /* enable/disable HBR (HD passthrough) */
  107. int (*pin_hbr_setup)(struct hda_codec *codec, hda_nid_t pin_nid, bool hbr);
  108. int (*setup_stream)(struct hda_codec *codec, hda_nid_t cvt_nid,
  109. hda_nid_t pin_nid, u32 stream_tag, int format);
  110. void (*pin_cvt_fixup)(struct hda_codec *codec,
  111. struct hdmi_spec_per_pin *per_pin,
  112. hda_nid_t cvt_nid);
  113. };
  114. struct hdmi_pcm {
  115. struct hda_pcm *pcm;
  116. struct snd_jack *jack;
  117. struct snd_kcontrol *eld_ctl;
  118. };
  119. struct hdmi_spec {
  120. int num_cvts;
  121. struct snd_array cvts; /* struct hdmi_spec_per_cvt */
  122. hda_nid_t cvt_nids[4]; /* only for haswell fix */
  123. /*
  124. * num_pins is the number of virtual pins
  125. * for example, there are 3 pins, and each pin
  126. * has 4 device entries, then the num_pins is 12
  127. */
  128. int num_pins;
  129. /*
  130. * num_nids is the number of real pins
  131. * In the above example, num_nids is 3
  132. */
  133. int num_nids;
  134. /*
  135. * dev_num is the number of device entries
  136. * on each pin.
  137. * In the above example, dev_num is 4
  138. */
  139. int dev_num;
  140. struct snd_array pins; /* struct hdmi_spec_per_pin */
  141. struct hdmi_pcm pcm_rec[16];
  142. struct mutex pcm_lock;
  143. /* pcm_bitmap means which pcms have been assigned to pins*/
  144. unsigned long pcm_bitmap;
  145. int pcm_used; /* counter of pcm_rec[] */
  146. /* bitmap shows whether the pcm is opened in user space
  147. * bit 0 means the first playback PCM (PCM3);
  148. * bit 1 means the second playback PCM, and so on.
  149. */
  150. unsigned long pcm_in_use;
  151. struct hdmi_eld temp_eld;
  152. struct hdmi_ops ops;
  153. bool dyn_pin_out;
  154. bool dyn_pcm_assign;
  155. /*
  156. * Non-generic VIA/NVIDIA specific
  157. */
  158. struct hda_multi_out multiout;
  159. struct hda_pcm_stream pcm_playback;
  160. /* i915/powerwell (Haswell+/Valleyview+) specific */
  161. bool use_acomp_notifier; /* use i915 eld_notify callback for hotplug */
  162. struct drm_audio_component_audio_ops drm_audio_ops;
  163. struct hdac_chmap chmap;
  164. hda_nid_t vendor_nid;
  165. };
  166. #ifdef CONFIG_SND_HDA_COMPONENT
  167. static inline bool codec_has_acomp(struct hda_codec *codec)
  168. {
  169. struct hdmi_spec *spec = codec->spec;
  170. return spec->use_acomp_notifier;
  171. }
  172. #else
  173. #define codec_has_acomp(codec) false
  174. #endif
  175. struct hdmi_audio_infoframe {
  176. u8 type; /* 0x84 */
  177. u8 ver; /* 0x01 */
  178. u8 len; /* 0x0a */
  179. u8 checksum;
  180. u8 CC02_CT47; /* CC in bits 0:2, CT in 4:7 */
  181. u8 SS01_SF24;
  182. u8 CXT04;
  183. u8 CA;
  184. u8 LFEPBL01_LSV36_DM_INH7;
  185. };
  186. struct dp_audio_infoframe {
  187. u8 type; /* 0x84 */
  188. u8 len; /* 0x1b */
  189. u8 ver; /* 0x11 << 2 */
  190. u8 CC02_CT47; /* match with HDMI infoframe from this on */
  191. u8 SS01_SF24;
  192. u8 CXT04;
  193. u8 CA;
  194. u8 LFEPBL01_LSV36_DM_INH7;
  195. };
  196. union audio_infoframe {
  197. struct hdmi_audio_infoframe hdmi;
  198. struct dp_audio_infoframe dp;
  199. u8 bytes[0];
  200. };
  201. /*
  202. * HDMI routines
  203. */
  204. #define get_pin(spec, idx) \
  205. ((struct hdmi_spec_per_pin *)snd_array_elem(&spec->pins, idx))
  206. #define get_cvt(spec, idx) \
  207. ((struct hdmi_spec_per_cvt *)snd_array_elem(&spec->cvts, idx))
  208. /* obtain hdmi_pcm object assigned to idx */
  209. #define get_hdmi_pcm(spec, idx) (&(spec)->pcm_rec[idx])
  210. /* obtain hda_pcm object assigned to idx */
  211. #define get_pcm_rec(spec, idx) (get_hdmi_pcm(spec, idx)->pcm)
  212. static int pin_id_to_pin_index(struct hda_codec *codec,
  213. hda_nid_t pin_nid, int dev_id)
  214. {
  215. struct hdmi_spec *spec = codec->spec;
  216. int pin_idx;
  217. struct hdmi_spec_per_pin *per_pin;
  218. /*
  219. * (dev_id == -1) means it is NON-MST pin
  220. * return the first virtual pin on this port
  221. */
  222. if (dev_id == -1)
  223. dev_id = 0;
  224. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  225. per_pin = get_pin(spec, pin_idx);
  226. if ((per_pin->pin_nid == pin_nid) &&
  227. (per_pin->dev_id == dev_id))
  228. return pin_idx;
  229. }
  230. codec_warn(codec, "HDMI: pin nid %d not registered\n", pin_nid);
  231. return -EINVAL;
  232. }
  233. static int hinfo_to_pcm_index(struct hda_codec *codec,
  234. struct hda_pcm_stream *hinfo)
  235. {
  236. struct hdmi_spec *spec = codec->spec;
  237. int pcm_idx;
  238. for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++)
  239. if (get_pcm_rec(spec, pcm_idx)->stream == hinfo)
  240. return pcm_idx;
  241. codec_warn(codec, "HDMI: hinfo %p not registered\n", hinfo);
  242. return -EINVAL;
  243. }
  244. static int hinfo_to_pin_index(struct hda_codec *codec,
  245. struct hda_pcm_stream *hinfo)
  246. {
  247. struct hdmi_spec *spec = codec->spec;
  248. struct hdmi_spec_per_pin *per_pin;
  249. int pin_idx;
  250. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  251. per_pin = get_pin(spec, pin_idx);
  252. if (per_pin->pcm &&
  253. per_pin->pcm->pcm->stream == hinfo)
  254. return pin_idx;
  255. }
  256. codec_dbg(codec, "HDMI: hinfo %p not registered\n", hinfo);
  257. return -EINVAL;
  258. }
  259. static struct hdmi_spec_per_pin *pcm_idx_to_pin(struct hdmi_spec *spec,
  260. int pcm_idx)
  261. {
  262. int i;
  263. struct hdmi_spec_per_pin *per_pin;
  264. for (i = 0; i < spec->num_pins; i++) {
  265. per_pin = get_pin(spec, i);
  266. if (per_pin->pcm_idx == pcm_idx)
  267. return per_pin;
  268. }
  269. return NULL;
  270. }
  271. static int cvt_nid_to_cvt_index(struct hda_codec *codec, hda_nid_t cvt_nid)
  272. {
  273. struct hdmi_spec *spec = codec->spec;
  274. int cvt_idx;
  275. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++)
  276. if (get_cvt(spec, cvt_idx)->cvt_nid == cvt_nid)
  277. return cvt_idx;
  278. codec_warn(codec, "HDMI: cvt nid %d not registered\n", cvt_nid);
  279. return -EINVAL;
  280. }
  281. static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
  282. struct snd_ctl_elem_info *uinfo)
  283. {
  284. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  285. struct hdmi_spec *spec = codec->spec;
  286. struct hdmi_spec_per_pin *per_pin;
  287. struct hdmi_eld *eld;
  288. int pcm_idx;
  289. uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
  290. pcm_idx = kcontrol->private_value;
  291. mutex_lock(&spec->pcm_lock);
  292. per_pin = pcm_idx_to_pin(spec, pcm_idx);
  293. if (!per_pin) {
  294. /* no pin is bound to the pcm */
  295. uinfo->count = 0;
  296. goto unlock;
  297. }
  298. eld = &per_pin->sink_eld;
  299. uinfo->count = eld->eld_valid ? eld->eld_size : 0;
  300. unlock:
  301. mutex_unlock(&spec->pcm_lock);
  302. return 0;
  303. }
  304. static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
  305. struct snd_ctl_elem_value *ucontrol)
  306. {
  307. struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
  308. struct hdmi_spec *spec = codec->spec;
  309. struct hdmi_spec_per_pin *per_pin;
  310. struct hdmi_eld *eld;
  311. int pcm_idx;
  312. int err = 0;
  313. pcm_idx = kcontrol->private_value;
  314. mutex_lock(&spec->pcm_lock);
  315. per_pin = pcm_idx_to_pin(spec, pcm_idx);
  316. if (!per_pin) {
  317. /* no pin is bound to the pcm */
  318. memset(ucontrol->value.bytes.data, 0,
  319. ARRAY_SIZE(ucontrol->value.bytes.data));
  320. goto unlock;
  321. }
  322. eld = &per_pin->sink_eld;
  323. if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) ||
  324. eld->eld_size > ELD_MAX_SIZE) {
  325. snd_BUG();
  326. err = -EINVAL;
  327. goto unlock;
  328. }
  329. memset(ucontrol->value.bytes.data, 0,
  330. ARRAY_SIZE(ucontrol->value.bytes.data));
  331. if (eld->eld_valid)
  332. memcpy(ucontrol->value.bytes.data, eld->eld_buffer,
  333. eld->eld_size);
  334. unlock:
  335. mutex_unlock(&spec->pcm_lock);
  336. return err;
  337. }
  338. static const struct snd_kcontrol_new eld_bytes_ctl = {
  339. .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
  340. .iface = SNDRV_CTL_ELEM_IFACE_PCM,
  341. .name = "ELD",
  342. .info = hdmi_eld_ctl_info,
  343. .get = hdmi_eld_ctl_get,
  344. };
  345. static int hdmi_create_eld_ctl(struct hda_codec *codec, int pcm_idx,
  346. int device)
  347. {
  348. struct snd_kcontrol *kctl;
  349. struct hdmi_spec *spec = codec->spec;
  350. int err;
  351. kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
  352. if (!kctl)
  353. return -ENOMEM;
  354. kctl->private_value = pcm_idx;
  355. kctl->id.device = device;
  356. /* no pin nid is associated with the kctl now
  357. * tbd: associate pin nid to eld ctl later
  358. */
  359. err = snd_hda_ctl_add(codec, 0, kctl);
  360. if (err < 0)
  361. return err;
  362. get_hdmi_pcm(spec, pcm_idx)->eld_ctl = kctl;
  363. return 0;
  364. }
  365. #ifdef BE_PARANOID
  366. static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  367. int *packet_index, int *byte_index)
  368. {
  369. int val;
  370. val = snd_hda_codec_read(codec, pin_nid, 0,
  371. AC_VERB_GET_HDMI_DIP_INDEX, 0);
  372. *packet_index = val >> 5;
  373. *byte_index = val & 0x1f;
  374. }
  375. #endif
  376. static void hdmi_set_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
  377. int packet_index, int byte_index)
  378. {
  379. int val;
  380. val = (packet_index << 5) | (byte_index & 0x1f);
  381. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_INDEX, val);
  382. }
  383. static void hdmi_write_dip_byte(struct hda_codec *codec, hda_nid_t pin_nid,
  384. unsigned char val)
  385. {
  386. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_DATA, val);
  387. }
  388. static void hdmi_init_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  389. {
  390. struct hdmi_spec *spec = codec->spec;
  391. int pin_out;
  392. /* Unmute */
  393. if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
  394. snd_hda_codec_write(codec, pin_nid, 0,
  395. AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
  396. if (spec->dyn_pin_out)
  397. /* Disable pin out until stream is active */
  398. pin_out = 0;
  399. else
  400. /* Enable pin out: some machines with GM965 gets broken output
  401. * when the pin is disabled or changed while using with HDMI
  402. */
  403. pin_out = PIN_OUT;
  404. snd_hda_codec_write(codec, pin_nid, 0,
  405. AC_VERB_SET_PIN_WIDGET_CONTROL, pin_out);
  406. }
  407. /*
  408. * ELD proc files
  409. */
  410. #ifdef CONFIG_SND_PROC_FS
  411. static void print_eld_info(struct snd_info_entry *entry,
  412. struct snd_info_buffer *buffer)
  413. {
  414. struct hdmi_spec_per_pin *per_pin = entry->private_data;
  415. mutex_lock(&per_pin->lock);
  416. snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer);
  417. mutex_unlock(&per_pin->lock);
  418. }
  419. static void write_eld_info(struct snd_info_entry *entry,
  420. struct snd_info_buffer *buffer)
  421. {
  422. struct hdmi_spec_per_pin *per_pin = entry->private_data;
  423. mutex_lock(&per_pin->lock);
  424. snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer);
  425. mutex_unlock(&per_pin->lock);
  426. }
  427. static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index)
  428. {
  429. char name[32];
  430. struct hda_codec *codec = per_pin->codec;
  431. struct snd_info_entry *entry;
  432. int err;
  433. snprintf(name, sizeof(name), "eld#%d.%d", codec->addr, index);
  434. err = snd_card_proc_new(codec->card, name, &entry);
  435. if (err < 0)
  436. return err;
  437. snd_info_set_text_ops(entry, per_pin, print_eld_info);
  438. entry->c.text.write = write_eld_info;
  439. entry->mode |= 0200;
  440. per_pin->proc_entry = entry;
  441. return 0;
  442. }
  443. static void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
  444. {
  445. if (!per_pin->codec->bus->shutdown) {
  446. snd_info_free_entry(per_pin->proc_entry);
  447. per_pin->proc_entry = NULL;
  448. }
  449. }
  450. #else
  451. static inline int eld_proc_new(struct hdmi_spec_per_pin *per_pin,
  452. int index)
  453. {
  454. return 0;
  455. }
  456. static inline void eld_proc_free(struct hdmi_spec_per_pin *per_pin)
  457. {
  458. }
  459. #endif
  460. /*
  461. * Audio InfoFrame routines
  462. */
  463. /*
  464. * Enable Audio InfoFrame Transmission
  465. */
  466. static void hdmi_start_infoframe_trans(struct hda_codec *codec,
  467. hda_nid_t pin_nid)
  468. {
  469. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  470. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  471. AC_DIPXMIT_BEST);
  472. }
  473. /*
  474. * Disable Audio InfoFrame Transmission
  475. */
  476. static void hdmi_stop_infoframe_trans(struct hda_codec *codec,
  477. hda_nid_t pin_nid)
  478. {
  479. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  480. snd_hda_codec_write(codec, pin_nid, 0, AC_VERB_SET_HDMI_DIP_XMIT,
  481. AC_DIPXMIT_DISABLE);
  482. }
  483. static void hdmi_debug_dip_size(struct hda_codec *codec, hda_nid_t pin_nid)
  484. {
  485. #ifdef CONFIG_SND_DEBUG_VERBOSE
  486. int i;
  487. int size;
  488. size = snd_hdmi_get_eld_size(codec, pin_nid);
  489. codec_dbg(codec, "HDMI: ELD buf size is %d\n", size);
  490. for (i = 0; i < 8; i++) {
  491. size = snd_hda_codec_read(codec, pin_nid, 0,
  492. AC_VERB_GET_HDMI_DIP_SIZE, i);
  493. codec_dbg(codec, "HDMI: DIP GP[%d] buf size is %d\n", i, size);
  494. }
  495. #endif
  496. }
  497. static void hdmi_clear_dip_buffers(struct hda_codec *codec, hda_nid_t pin_nid)
  498. {
  499. #ifdef BE_PARANOID
  500. int i, j;
  501. int size;
  502. int pi, bi;
  503. for (i = 0; i < 8; i++) {
  504. size = snd_hda_codec_read(codec, pin_nid, 0,
  505. AC_VERB_GET_HDMI_DIP_SIZE, i);
  506. if (size == 0)
  507. continue;
  508. hdmi_set_dip_index(codec, pin_nid, i, 0x0);
  509. for (j = 1; j < 1000; j++) {
  510. hdmi_write_dip_byte(codec, pin_nid, 0x0);
  511. hdmi_get_dip_index(codec, pin_nid, &pi, &bi);
  512. if (pi != i)
  513. codec_dbg(codec, "dip index %d: %d != %d\n",
  514. bi, pi, i);
  515. if (bi == 0) /* byte index wrapped around */
  516. break;
  517. }
  518. codec_dbg(codec,
  519. "HDMI: DIP GP[%d] buf reported size=%d, written=%d\n",
  520. i, size, j);
  521. }
  522. #endif
  523. }
  524. static void hdmi_checksum_audio_infoframe(struct hdmi_audio_infoframe *hdmi_ai)
  525. {
  526. u8 *bytes = (u8 *)hdmi_ai;
  527. u8 sum = 0;
  528. int i;
  529. hdmi_ai->checksum = 0;
  530. for (i = 0; i < sizeof(*hdmi_ai); i++)
  531. sum += bytes[i];
  532. hdmi_ai->checksum = -sum;
  533. }
  534. static void hdmi_fill_audio_infoframe(struct hda_codec *codec,
  535. hda_nid_t pin_nid,
  536. u8 *dip, int size)
  537. {
  538. int i;
  539. hdmi_debug_dip_size(codec, pin_nid);
  540. hdmi_clear_dip_buffers(codec, pin_nid); /* be paranoid */
  541. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  542. for (i = 0; i < size; i++)
  543. hdmi_write_dip_byte(codec, pin_nid, dip[i]);
  544. }
  545. static bool hdmi_infoframe_uptodate(struct hda_codec *codec, hda_nid_t pin_nid,
  546. u8 *dip, int size)
  547. {
  548. u8 val;
  549. int i;
  550. if (snd_hda_codec_read(codec, pin_nid, 0, AC_VERB_GET_HDMI_DIP_XMIT, 0)
  551. != AC_DIPXMIT_BEST)
  552. return false;
  553. hdmi_set_dip_index(codec, pin_nid, 0x0, 0x0);
  554. for (i = 0; i < size; i++) {
  555. val = snd_hda_codec_read(codec, pin_nid, 0,
  556. AC_VERB_GET_HDMI_DIP_DATA, 0);
  557. if (val != dip[i])
  558. return false;
  559. }
  560. return true;
  561. }
  562. static void hdmi_pin_setup_infoframe(struct hda_codec *codec,
  563. hda_nid_t pin_nid,
  564. int ca, int active_channels,
  565. int conn_type)
  566. {
  567. union audio_infoframe ai;
  568. memset(&ai, 0, sizeof(ai));
  569. if (conn_type == 0) { /* HDMI */
  570. struct hdmi_audio_infoframe *hdmi_ai = &ai.hdmi;
  571. hdmi_ai->type = 0x84;
  572. hdmi_ai->ver = 0x01;
  573. hdmi_ai->len = 0x0a;
  574. hdmi_ai->CC02_CT47 = active_channels - 1;
  575. hdmi_ai->CA = ca;
  576. hdmi_checksum_audio_infoframe(hdmi_ai);
  577. } else if (conn_type == 1) { /* DisplayPort */
  578. struct dp_audio_infoframe *dp_ai = &ai.dp;
  579. dp_ai->type = 0x84;
  580. dp_ai->len = 0x1b;
  581. dp_ai->ver = 0x11 << 2;
  582. dp_ai->CC02_CT47 = active_channels - 1;
  583. dp_ai->CA = ca;
  584. } else {
  585. codec_dbg(codec, "HDMI: unknown connection type at pin %d\n",
  586. pin_nid);
  587. return;
  588. }
  589. /*
  590. * sizeof(ai) is used instead of sizeof(*hdmi_ai) or
  591. * sizeof(*dp_ai) to avoid partial match/update problems when
  592. * the user switches between HDMI/DP monitors.
  593. */
  594. if (!hdmi_infoframe_uptodate(codec, pin_nid, ai.bytes,
  595. sizeof(ai))) {
  596. codec_dbg(codec,
  597. "hdmi_pin_setup_infoframe: pin=%d channels=%d ca=0x%02x\n",
  598. pin_nid,
  599. active_channels, ca);
  600. hdmi_stop_infoframe_trans(codec, pin_nid);
  601. hdmi_fill_audio_infoframe(codec, pin_nid,
  602. ai.bytes, sizeof(ai));
  603. hdmi_start_infoframe_trans(codec, pin_nid);
  604. }
  605. }
  606. static void hdmi_setup_audio_infoframe(struct hda_codec *codec,
  607. struct hdmi_spec_per_pin *per_pin,
  608. bool non_pcm)
  609. {
  610. struct hdmi_spec *spec = codec->spec;
  611. struct hdac_chmap *chmap = &spec->chmap;
  612. hda_nid_t pin_nid = per_pin->pin_nid;
  613. int channels = per_pin->channels;
  614. int active_channels;
  615. struct hdmi_eld *eld;
  616. int ca;
  617. if (!channels)
  618. return;
  619. /* some HW (e.g. HSW+) needs reprogramming the amp at each time */
  620. if (get_wcaps(codec, pin_nid) & AC_WCAP_OUT_AMP)
  621. snd_hda_codec_write(codec, pin_nid, 0,
  622. AC_VERB_SET_AMP_GAIN_MUTE,
  623. AMP_OUT_UNMUTE);
  624. eld = &per_pin->sink_eld;
  625. ca = snd_hdac_channel_allocation(&codec->core,
  626. eld->info.spk_alloc, channels,
  627. per_pin->chmap_set, non_pcm, per_pin->chmap);
  628. active_channels = snd_hdac_get_active_channels(ca);
  629. chmap->ops.set_channel_count(&codec->core, per_pin->cvt_nid,
  630. active_channels);
  631. /*
  632. * always configure channel mapping, it may have been changed by the
  633. * user in the meantime
  634. */
  635. snd_hdac_setup_channel_mapping(&spec->chmap,
  636. pin_nid, non_pcm, ca, channels,
  637. per_pin->chmap, per_pin->chmap_set);
  638. spec->ops.pin_setup_infoframe(codec, pin_nid, ca, active_channels,
  639. eld->info.conn_type);
  640. per_pin->non_pcm = non_pcm;
  641. }
  642. /*
  643. * Unsolicited events
  644. */
  645. static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll);
  646. static void check_presence_and_report(struct hda_codec *codec, hda_nid_t nid,
  647. int dev_id)
  648. {
  649. struct hdmi_spec *spec = codec->spec;
  650. int pin_idx = pin_id_to_pin_index(codec, nid, dev_id);
  651. if (pin_idx < 0)
  652. return;
  653. mutex_lock(&spec->pcm_lock);
  654. if (hdmi_present_sense(get_pin(spec, pin_idx), 1))
  655. snd_hda_jack_report_sync(codec);
  656. mutex_unlock(&spec->pcm_lock);
  657. }
  658. static void jack_callback(struct hda_codec *codec,
  659. struct hda_jack_callback *jack)
  660. {
  661. /* hda_jack don't support DP MST */
  662. check_presence_and_report(codec, jack->nid, 0);
  663. }
  664. static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
  665. {
  666. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  667. struct hda_jack_tbl *jack;
  668. int dev_entry = (res & AC_UNSOL_RES_DE) >> AC_UNSOL_RES_DE_SHIFT;
  669. /*
  670. * assume DP MST uses dyn_pcm_assign and acomp and
  671. * never comes here
  672. * if DP MST supports unsol event, below code need
  673. * consider dev_entry
  674. */
  675. jack = snd_hda_jack_tbl_get_from_tag(codec, tag);
  676. if (!jack)
  677. return;
  678. jack->jack_dirty = 1;
  679. codec_dbg(codec,
  680. "HDMI hot plug event: Codec=%d Pin=%d Device=%d Inactive=%d Presence_Detect=%d ELD_Valid=%d\n",
  681. codec->addr, jack->nid, dev_entry, !!(res & AC_UNSOL_RES_IA),
  682. !!(res & AC_UNSOL_RES_PD), !!(res & AC_UNSOL_RES_ELDV));
  683. /* hda_jack don't support DP MST */
  684. check_presence_and_report(codec, jack->nid, 0);
  685. }
  686. static void hdmi_non_intrinsic_event(struct hda_codec *codec, unsigned int res)
  687. {
  688. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  689. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  690. int cp_state = !!(res & AC_UNSOL_RES_CP_STATE);
  691. int cp_ready = !!(res & AC_UNSOL_RES_CP_READY);
  692. codec_info(codec,
  693. "HDMI CP event: CODEC=%d TAG=%d SUBTAG=0x%x CP_STATE=%d CP_READY=%d\n",
  694. codec->addr,
  695. tag,
  696. subtag,
  697. cp_state,
  698. cp_ready);
  699. /* TODO */
  700. if (cp_state)
  701. ;
  702. if (cp_ready)
  703. ;
  704. }
  705. static void hdmi_unsol_event(struct hda_codec *codec, unsigned int res)
  706. {
  707. int tag = res >> AC_UNSOL_RES_TAG_SHIFT;
  708. int subtag = (res & AC_UNSOL_RES_SUBTAG) >> AC_UNSOL_RES_SUBTAG_SHIFT;
  709. if (!snd_hda_jack_tbl_get_from_tag(codec, tag)) {
  710. codec_dbg(codec, "Unexpected HDMI event tag 0x%x\n", tag);
  711. return;
  712. }
  713. if (subtag == 0)
  714. hdmi_intrinsic_event(codec, res);
  715. else
  716. hdmi_non_intrinsic_event(codec, res);
  717. }
  718. static void haswell_verify_D0(struct hda_codec *codec,
  719. hda_nid_t cvt_nid, hda_nid_t nid)
  720. {
  721. int pwr;
  722. /* For Haswell, the converter 1/2 may keep in D3 state after bootup,
  723. * thus pins could only choose converter 0 for use. Make sure the
  724. * converters are in correct power state */
  725. if (!snd_hda_check_power_state(codec, cvt_nid, AC_PWRST_D0))
  726. snd_hda_codec_write(codec, cvt_nid, 0, AC_VERB_SET_POWER_STATE, AC_PWRST_D0);
  727. if (!snd_hda_check_power_state(codec, nid, AC_PWRST_D0)) {
  728. snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_POWER_STATE,
  729. AC_PWRST_D0);
  730. msleep(40);
  731. pwr = snd_hda_codec_read(codec, nid, 0, AC_VERB_GET_POWER_STATE, 0);
  732. pwr = (pwr & AC_PWRST_ACTUAL) >> AC_PWRST_ACTUAL_SHIFT;
  733. codec_dbg(codec, "Haswell HDMI audio: Power for pin 0x%x is now D%d\n", nid, pwr);
  734. }
  735. }
  736. /*
  737. * Callbacks
  738. */
  739. /* HBR should be Non-PCM, 8 channels */
  740. #define is_hbr_format(format) \
  741. ((format & AC_FMT_TYPE_NON_PCM) && (format & AC_FMT_CHAN_MASK) == 7)
  742. static int hdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
  743. bool hbr)
  744. {
  745. int pinctl, new_pinctl;
  746. if (snd_hda_query_pin_caps(codec, pin_nid) & AC_PINCAP_HBR) {
  747. pinctl = snd_hda_codec_read(codec, pin_nid, 0,
  748. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  749. if (pinctl < 0)
  750. return hbr ? -EINVAL : 0;
  751. new_pinctl = pinctl & ~AC_PINCTL_EPT;
  752. if (hbr)
  753. new_pinctl |= AC_PINCTL_EPT_HBR;
  754. else
  755. new_pinctl |= AC_PINCTL_EPT_NATIVE;
  756. codec_dbg(codec,
  757. "hdmi_pin_hbr_setup: NID=0x%x, %spinctl=0x%x\n",
  758. pin_nid,
  759. pinctl == new_pinctl ? "" : "new-",
  760. new_pinctl);
  761. if (pinctl != new_pinctl)
  762. snd_hda_codec_write(codec, pin_nid, 0,
  763. AC_VERB_SET_PIN_WIDGET_CONTROL,
  764. new_pinctl);
  765. } else if (hbr)
  766. return -EINVAL;
  767. return 0;
  768. }
  769. static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  770. hda_nid_t pin_nid, u32 stream_tag, int format)
  771. {
  772. struct hdmi_spec *spec = codec->spec;
  773. unsigned int param;
  774. int err;
  775. err = spec->ops.pin_hbr_setup(codec, pin_nid, is_hbr_format(format));
  776. if (err) {
  777. codec_dbg(codec, "hdmi_setup_stream: HBR is not supported\n");
  778. return err;
  779. }
  780. if (is_haswell_plus(codec)) {
  781. /*
  782. * on recent platforms IEC Coding Type is required for HBR
  783. * support, read current Digital Converter settings and set
  784. * ICT bitfield if needed.
  785. */
  786. param = snd_hda_codec_read(codec, cvt_nid, 0,
  787. AC_VERB_GET_DIGI_CONVERT_1, 0);
  788. param = (param >> 16) & ~(AC_DIG3_ICT);
  789. /* on recent platforms ICT mode is required for HBR support */
  790. if (is_hbr_format(format))
  791. param |= 0x1;
  792. snd_hda_codec_write(codec, cvt_nid, 0,
  793. AC_VERB_SET_DIGI_CONVERT_3, param);
  794. }
  795. snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format);
  796. return 0;
  797. }
  798. /* Try to find an available converter
  799. * If pin_idx is less then zero, just try to find an available converter.
  800. * Otherwise, try to find an available converter and get the cvt mux index
  801. * of the pin.
  802. */
  803. static int hdmi_choose_cvt(struct hda_codec *codec,
  804. int pin_idx, int *cvt_id)
  805. {
  806. struct hdmi_spec *spec = codec->spec;
  807. struct hdmi_spec_per_pin *per_pin;
  808. struct hdmi_spec_per_cvt *per_cvt = NULL;
  809. int cvt_idx, mux_idx = 0;
  810. /* pin_idx < 0 means no pin will be bound to the converter */
  811. if (pin_idx < 0)
  812. per_pin = NULL;
  813. else
  814. per_pin = get_pin(spec, pin_idx);
  815. /* Dynamically assign converter to stream */
  816. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  817. per_cvt = get_cvt(spec, cvt_idx);
  818. /* Must not already be assigned */
  819. if (per_cvt->assigned)
  820. continue;
  821. if (per_pin == NULL)
  822. break;
  823. /* Must be in pin's mux's list of converters */
  824. for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
  825. if (per_pin->mux_nids[mux_idx] == per_cvt->cvt_nid)
  826. break;
  827. /* Not in mux list */
  828. if (mux_idx == per_pin->num_mux_nids)
  829. continue;
  830. break;
  831. }
  832. /* No free converters */
  833. if (cvt_idx == spec->num_cvts)
  834. return -EBUSY;
  835. if (per_pin != NULL)
  836. per_pin->mux_idx = mux_idx;
  837. if (cvt_id)
  838. *cvt_id = cvt_idx;
  839. return 0;
  840. }
  841. /* Assure the pin select the right convetor */
  842. static void intel_verify_pin_cvt_connect(struct hda_codec *codec,
  843. struct hdmi_spec_per_pin *per_pin)
  844. {
  845. hda_nid_t pin_nid = per_pin->pin_nid;
  846. int mux_idx, curr;
  847. mux_idx = per_pin->mux_idx;
  848. curr = snd_hda_codec_read(codec, pin_nid, 0,
  849. AC_VERB_GET_CONNECT_SEL, 0);
  850. if (curr != mux_idx)
  851. snd_hda_codec_write_cache(codec, pin_nid, 0,
  852. AC_VERB_SET_CONNECT_SEL,
  853. mux_idx);
  854. }
  855. /* get the mux index for the converter of the pins
  856. * converter's mux index is the same for all pins on Intel platform
  857. */
  858. static int intel_cvt_id_to_mux_idx(struct hdmi_spec *spec,
  859. hda_nid_t cvt_nid)
  860. {
  861. int i;
  862. for (i = 0; i < spec->num_cvts; i++)
  863. if (spec->cvt_nids[i] == cvt_nid)
  864. return i;
  865. return -EINVAL;
  866. }
  867. /* Intel HDMI workaround to fix audio routing issue:
  868. * For some Intel display codecs, pins share the same connection list.
  869. * So a conveter can be selected by multiple pins and playback on any of these
  870. * pins will generate sound on the external display, because audio flows from
  871. * the same converter to the display pipeline. Also muting one pin may make
  872. * other pins have no sound output.
  873. * So this function assures that an assigned converter for a pin is not selected
  874. * by any other pins.
  875. */
  876. static void intel_not_share_assigned_cvt(struct hda_codec *codec,
  877. hda_nid_t pin_nid,
  878. int dev_id, int mux_idx)
  879. {
  880. struct hdmi_spec *spec = codec->spec;
  881. hda_nid_t nid;
  882. int cvt_idx, curr;
  883. struct hdmi_spec_per_cvt *per_cvt;
  884. struct hdmi_spec_per_pin *per_pin;
  885. int pin_idx;
  886. /* configure the pins connections */
  887. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  888. int dev_id_saved;
  889. int dev_num;
  890. per_pin = get_pin(spec, pin_idx);
  891. /*
  892. * pin not connected to monitor
  893. * no need to operate on it
  894. */
  895. if (!per_pin->pcm)
  896. continue;
  897. if ((per_pin->pin_nid == pin_nid) &&
  898. (per_pin->dev_id == dev_id))
  899. continue;
  900. /*
  901. * if per_pin->dev_id >= dev_num,
  902. * snd_hda_get_dev_select() will fail,
  903. * and the following operation is unpredictable.
  904. * So skip this situation.
  905. */
  906. dev_num = snd_hda_get_num_devices(codec, per_pin->pin_nid) + 1;
  907. if (per_pin->dev_id >= dev_num)
  908. continue;
  909. nid = per_pin->pin_nid;
  910. /*
  911. * Calling this function should not impact
  912. * on the device entry selection
  913. * So let's save the dev id for each pin,
  914. * and restore it when return
  915. */
  916. dev_id_saved = snd_hda_get_dev_select(codec, nid);
  917. snd_hda_set_dev_select(codec, nid, per_pin->dev_id);
  918. curr = snd_hda_codec_read(codec, nid, 0,
  919. AC_VERB_GET_CONNECT_SEL, 0);
  920. if (curr != mux_idx) {
  921. snd_hda_set_dev_select(codec, nid, dev_id_saved);
  922. continue;
  923. }
  924. /* choose an unassigned converter. The conveters in the
  925. * connection list are in the same order as in the codec.
  926. */
  927. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  928. per_cvt = get_cvt(spec, cvt_idx);
  929. if (!per_cvt->assigned) {
  930. codec_dbg(codec,
  931. "choose cvt %d for pin nid %d\n",
  932. cvt_idx, nid);
  933. snd_hda_codec_write_cache(codec, nid, 0,
  934. AC_VERB_SET_CONNECT_SEL,
  935. cvt_idx);
  936. break;
  937. }
  938. }
  939. snd_hda_set_dev_select(codec, nid, dev_id_saved);
  940. }
  941. }
  942. /* A wrapper of intel_not_share_asigned_cvt() */
  943. static void intel_not_share_assigned_cvt_nid(struct hda_codec *codec,
  944. hda_nid_t pin_nid, int dev_id, hda_nid_t cvt_nid)
  945. {
  946. int mux_idx;
  947. struct hdmi_spec *spec = codec->spec;
  948. /* On Intel platform, the mapping of converter nid to
  949. * mux index of the pins are always the same.
  950. * The pin nid may be 0, this means all pins will not
  951. * share the converter.
  952. */
  953. mux_idx = intel_cvt_id_to_mux_idx(spec, cvt_nid);
  954. if (mux_idx >= 0)
  955. intel_not_share_assigned_cvt(codec, pin_nid, dev_id, mux_idx);
  956. }
  957. /* skeleton caller of pin_cvt_fixup ops */
  958. static void pin_cvt_fixup(struct hda_codec *codec,
  959. struct hdmi_spec_per_pin *per_pin,
  960. hda_nid_t cvt_nid)
  961. {
  962. struct hdmi_spec *spec = codec->spec;
  963. if (spec->ops.pin_cvt_fixup)
  964. spec->ops.pin_cvt_fixup(codec, per_pin, cvt_nid);
  965. }
  966. /* called in hdmi_pcm_open when no pin is assigned to the PCM
  967. * in dyn_pcm_assign mode.
  968. */
  969. static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
  970. struct hda_codec *codec,
  971. struct snd_pcm_substream *substream)
  972. {
  973. struct hdmi_spec *spec = codec->spec;
  974. struct snd_pcm_runtime *runtime = substream->runtime;
  975. int cvt_idx, pcm_idx;
  976. struct hdmi_spec_per_cvt *per_cvt = NULL;
  977. int err;
  978. pcm_idx = hinfo_to_pcm_index(codec, hinfo);
  979. if (pcm_idx < 0)
  980. return -EINVAL;
  981. err = hdmi_choose_cvt(codec, -1, &cvt_idx);
  982. if (err)
  983. return err;
  984. per_cvt = get_cvt(spec, cvt_idx);
  985. per_cvt->assigned = 1;
  986. hinfo->nid = per_cvt->cvt_nid;
  987. pin_cvt_fixup(codec, NULL, per_cvt->cvt_nid);
  988. set_bit(pcm_idx, &spec->pcm_in_use);
  989. /* todo: setup spdif ctls assign */
  990. /* Initially set the converter's capabilities */
  991. hinfo->channels_min = per_cvt->channels_min;
  992. hinfo->channels_max = per_cvt->channels_max;
  993. hinfo->rates = per_cvt->rates;
  994. hinfo->formats = per_cvt->formats;
  995. hinfo->maxbps = per_cvt->maxbps;
  996. /* Store the updated parameters */
  997. runtime->hw.channels_min = hinfo->channels_min;
  998. runtime->hw.channels_max = hinfo->channels_max;
  999. runtime->hw.formats = hinfo->formats;
  1000. runtime->hw.rates = hinfo->rates;
  1001. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1002. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1003. return 0;
  1004. }
  1005. /*
  1006. * HDA PCM callbacks
  1007. */
  1008. static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
  1009. struct hda_codec *codec,
  1010. struct snd_pcm_substream *substream)
  1011. {
  1012. struct hdmi_spec *spec = codec->spec;
  1013. struct snd_pcm_runtime *runtime = substream->runtime;
  1014. int pin_idx, cvt_idx, pcm_idx;
  1015. struct hdmi_spec_per_pin *per_pin;
  1016. struct hdmi_eld *eld;
  1017. struct hdmi_spec_per_cvt *per_cvt = NULL;
  1018. int err;
  1019. /* Validate hinfo */
  1020. pcm_idx = hinfo_to_pcm_index(codec, hinfo);
  1021. if (pcm_idx < 0)
  1022. return -EINVAL;
  1023. mutex_lock(&spec->pcm_lock);
  1024. pin_idx = hinfo_to_pin_index(codec, hinfo);
  1025. if (!spec->dyn_pcm_assign) {
  1026. if (snd_BUG_ON(pin_idx < 0)) {
  1027. err = -EINVAL;
  1028. goto unlock;
  1029. }
  1030. } else {
  1031. /* no pin is assigned to the PCM
  1032. * PA need pcm open successfully when probe
  1033. */
  1034. if (pin_idx < 0) {
  1035. err = hdmi_pcm_open_no_pin(hinfo, codec, substream);
  1036. goto unlock;
  1037. }
  1038. }
  1039. err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx);
  1040. if (err < 0)
  1041. goto unlock;
  1042. per_cvt = get_cvt(spec, cvt_idx);
  1043. /* Claim converter */
  1044. per_cvt->assigned = 1;
  1045. set_bit(pcm_idx, &spec->pcm_in_use);
  1046. per_pin = get_pin(spec, pin_idx);
  1047. per_pin->cvt_nid = per_cvt->cvt_nid;
  1048. hinfo->nid = per_cvt->cvt_nid;
  1049. snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id);
  1050. snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
  1051. AC_VERB_SET_CONNECT_SEL,
  1052. per_pin->mux_idx);
  1053. /* configure unused pins to choose other converters */
  1054. pin_cvt_fixup(codec, per_pin, 0);
  1055. snd_hda_spdif_ctls_assign(codec, pcm_idx, per_cvt->cvt_nid);
  1056. /* Initially set the converter's capabilities */
  1057. hinfo->channels_min = per_cvt->channels_min;
  1058. hinfo->channels_max = per_cvt->channels_max;
  1059. hinfo->rates = per_cvt->rates;
  1060. hinfo->formats = per_cvt->formats;
  1061. hinfo->maxbps = per_cvt->maxbps;
  1062. eld = &per_pin->sink_eld;
  1063. /* Restrict capabilities by ELD if this isn't disabled */
  1064. if (!static_hdmi_pcm && eld->eld_valid) {
  1065. snd_hdmi_eld_update_pcm_info(&eld->info, hinfo);
  1066. if (hinfo->channels_min > hinfo->channels_max ||
  1067. !hinfo->rates || !hinfo->formats) {
  1068. per_cvt->assigned = 0;
  1069. hinfo->nid = 0;
  1070. snd_hda_spdif_ctls_unassign(codec, pcm_idx);
  1071. err = -ENODEV;
  1072. goto unlock;
  1073. }
  1074. }
  1075. /* Store the updated parameters */
  1076. runtime->hw.channels_min = hinfo->channels_min;
  1077. runtime->hw.channels_max = hinfo->channels_max;
  1078. runtime->hw.formats = hinfo->formats;
  1079. runtime->hw.rates = hinfo->rates;
  1080. snd_pcm_hw_constraint_step(substream->runtime, 0,
  1081. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  1082. unlock:
  1083. mutex_unlock(&spec->pcm_lock);
  1084. return err;
  1085. }
  1086. /*
  1087. * HDA/HDMI auto parsing
  1088. */
  1089. static int hdmi_read_pin_conn(struct hda_codec *codec, int pin_idx)
  1090. {
  1091. struct hdmi_spec *spec = codec->spec;
  1092. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1093. hda_nid_t pin_nid = per_pin->pin_nid;
  1094. if (!(get_wcaps(codec, pin_nid) & AC_WCAP_CONN_LIST)) {
  1095. codec_warn(codec,
  1096. "HDMI: pin %d wcaps %#x does not support connection list\n",
  1097. pin_nid, get_wcaps(codec, pin_nid));
  1098. return -EINVAL;
  1099. }
  1100. /* all the device entries on the same pin have the same conn list */
  1101. per_pin->num_mux_nids = snd_hda_get_connections(codec, pin_nid,
  1102. per_pin->mux_nids,
  1103. HDA_MAX_CONNECTIONS);
  1104. return 0;
  1105. }
  1106. static int hdmi_find_pcm_slot(struct hdmi_spec *spec,
  1107. struct hdmi_spec_per_pin *per_pin)
  1108. {
  1109. int i;
  1110. /* try the prefer PCM */
  1111. if (!test_bit(per_pin->pin_nid_idx, &spec->pcm_bitmap))
  1112. return per_pin->pin_nid_idx;
  1113. /* have a second try; check the "reserved area" over num_pins */
  1114. for (i = spec->num_nids; i < spec->pcm_used; i++) {
  1115. if (!test_bit(i, &spec->pcm_bitmap))
  1116. return i;
  1117. }
  1118. /* the last try; check the empty slots in pins */
  1119. for (i = 0; i < spec->num_nids; i++) {
  1120. if (!test_bit(i, &spec->pcm_bitmap))
  1121. return i;
  1122. }
  1123. return -EBUSY;
  1124. }
  1125. static void hdmi_attach_hda_pcm(struct hdmi_spec *spec,
  1126. struct hdmi_spec_per_pin *per_pin)
  1127. {
  1128. int idx;
  1129. /* pcm already be attached to the pin */
  1130. if (per_pin->pcm)
  1131. return;
  1132. idx = hdmi_find_pcm_slot(spec, per_pin);
  1133. if (idx == -EBUSY)
  1134. return;
  1135. per_pin->pcm_idx = idx;
  1136. per_pin->pcm = get_hdmi_pcm(spec, idx);
  1137. set_bit(idx, &spec->pcm_bitmap);
  1138. }
  1139. static void hdmi_detach_hda_pcm(struct hdmi_spec *spec,
  1140. struct hdmi_spec_per_pin *per_pin)
  1141. {
  1142. int idx;
  1143. /* pcm already be detached from the pin */
  1144. if (!per_pin->pcm)
  1145. return;
  1146. idx = per_pin->pcm_idx;
  1147. per_pin->pcm_idx = -1;
  1148. per_pin->pcm = NULL;
  1149. if (idx >= 0 && idx < spec->pcm_used)
  1150. clear_bit(idx, &spec->pcm_bitmap);
  1151. }
  1152. static int hdmi_get_pin_cvt_mux(struct hdmi_spec *spec,
  1153. struct hdmi_spec_per_pin *per_pin, hda_nid_t cvt_nid)
  1154. {
  1155. int mux_idx;
  1156. for (mux_idx = 0; mux_idx < per_pin->num_mux_nids; mux_idx++)
  1157. if (per_pin->mux_nids[mux_idx] == cvt_nid)
  1158. break;
  1159. return mux_idx;
  1160. }
  1161. static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid);
  1162. static void hdmi_pcm_setup_pin(struct hdmi_spec *spec,
  1163. struct hdmi_spec_per_pin *per_pin)
  1164. {
  1165. struct hda_codec *codec = per_pin->codec;
  1166. struct hda_pcm *pcm;
  1167. struct hda_pcm_stream *hinfo;
  1168. struct snd_pcm_substream *substream;
  1169. int mux_idx;
  1170. bool non_pcm;
  1171. if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
  1172. pcm = get_pcm_rec(spec, per_pin->pcm_idx);
  1173. else
  1174. return;
  1175. if (!pcm->pcm)
  1176. return;
  1177. if (!test_bit(per_pin->pcm_idx, &spec->pcm_in_use))
  1178. return;
  1179. /* hdmi audio only uses playback and one substream */
  1180. hinfo = pcm->stream;
  1181. substream = pcm->pcm->streams[0].substream;
  1182. per_pin->cvt_nid = hinfo->nid;
  1183. mux_idx = hdmi_get_pin_cvt_mux(spec, per_pin, hinfo->nid);
  1184. if (mux_idx < per_pin->num_mux_nids) {
  1185. snd_hda_set_dev_select(codec, per_pin->pin_nid,
  1186. per_pin->dev_id);
  1187. snd_hda_codec_write_cache(codec, per_pin->pin_nid, 0,
  1188. AC_VERB_SET_CONNECT_SEL,
  1189. mux_idx);
  1190. }
  1191. snd_hda_spdif_ctls_assign(codec, per_pin->pcm_idx, hinfo->nid);
  1192. non_pcm = check_non_pcm_per_cvt(codec, hinfo->nid);
  1193. if (substream->runtime)
  1194. per_pin->channels = substream->runtime->channels;
  1195. per_pin->setup = true;
  1196. per_pin->mux_idx = mux_idx;
  1197. hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
  1198. }
  1199. static void hdmi_pcm_reset_pin(struct hdmi_spec *spec,
  1200. struct hdmi_spec_per_pin *per_pin)
  1201. {
  1202. if (per_pin->pcm_idx >= 0 && per_pin->pcm_idx < spec->pcm_used)
  1203. snd_hda_spdif_ctls_unassign(per_pin->codec, per_pin->pcm_idx);
  1204. per_pin->chmap_set = false;
  1205. memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
  1206. per_pin->setup = false;
  1207. per_pin->channels = 0;
  1208. }
  1209. /* update per_pin ELD from the given new ELD;
  1210. * setup info frame and notification accordingly
  1211. */
  1212. static void update_eld(struct hda_codec *codec,
  1213. struct hdmi_spec_per_pin *per_pin,
  1214. struct hdmi_eld *eld)
  1215. {
  1216. struct hdmi_eld *pin_eld = &per_pin->sink_eld;
  1217. struct hdmi_spec *spec = codec->spec;
  1218. bool old_eld_valid = pin_eld->eld_valid;
  1219. bool eld_changed;
  1220. int pcm_idx = -1;
  1221. /* for monitor disconnection, save pcm_idx firstly */
  1222. pcm_idx = per_pin->pcm_idx;
  1223. if (spec->dyn_pcm_assign) {
  1224. if (eld->eld_valid) {
  1225. hdmi_attach_hda_pcm(spec, per_pin);
  1226. hdmi_pcm_setup_pin(spec, per_pin);
  1227. } else {
  1228. hdmi_pcm_reset_pin(spec, per_pin);
  1229. hdmi_detach_hda_pcm(spec, per_pin);
  1230. }
  1231. }
  1232. /* if pcm_idx == -1, it means this is in monitor connection event
  1233. * we can get the correct pcm_idx now.
  1234. */
  1235. if (pcm_idx == -1)
  1236. pcm_idx = per_pin->pcm_idx;
  1237. if (eld->eld_valid)
  1238. snd_hdmi_show_eld(codec, &eld->info);
  1239. eld_changed = (pin_eld->eld_valid != eld->eld_valid);
  1240. if (eld->eld_valid && pin_eld->eld_valid)
  1241. if (pin_eld->eld_size != eld->eld_size ||
  1242. memcmp(pin_eld->eld_buffer, eld->eld_buffer,
  1243. eld->eld_size) != 0)
  1244. eld_changed = true;
  1245. pin_eld->monitor_present = eld->monitor_present;
  1246. pin_eld->eld_valid = eld->eld_valid;
  1247. pin_eld->eld_size = eld->eld_size;
  1248. if (eld->eld_valid)
  1249. memcpy(pin_eld->eld_buffer, eld->eld_buffer, eld->eld_size);
  1250. pin_eld->info = eld->info;
  1251. /*
  1252. * Re-setup pin and infoframe. This is needed e.g. when
  1253. * - sink is first plugged-in
  1254. * - transcoder can change during stream playback on Haswell
  1255. * and this can make HW reset converter selection on a pin.
  1256. */
  1257. if (eld->eld_valid && !old_eld_valid && per_pin->setup) {
  1258. pin_cvt_fixup(codec, per_pin, 0);
  1259. hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
  1260. }
  1261. if (eld_changed && pcm_idx >= 0)
  1262. snd_ctl_notify(codec->card,
  1263. SNDRV_CTL_EVENT_MASK_VALUE |
  1264. SNDRV_CTL_EVENT_MASK_INFO,
  1265. &get_hdmi_pcm(spec, pcm_idx)->eld_ctl->id);
  1266. }
  1267. /* update ELD and jack state via HD-audio verbs */
  1268. static bool hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin,
  1269. int repoll)
  1270. {
  1271. struct hda_jack_tbl *jack;
  1272. struct hda_codec *codec = per_pin->codec;
  1273. struct hdmi_spec *spec = codec->spec;
  1274. struct hdmi_eld *eld = &spec->temp_eld;
  1275. hda_nid_t pin_nid = per_pin->pin_nid;
  1276. /*
  1277. * Always execute a GetPinSense verb here, even when called from
  1278. * hdmi_intrinsic_event; for some NVIDIA HW, the unsolicited
  1279. * response's PD bit is not the real PD value, but indicates that
  1280. * the real PD value changed. An older version of the HD-audio
  1281. * specification worked this way. Hence, we just ignore the data in
  1282. * the unsolicited response to avoid custom WARs.
  1283. */
  1284. int present;
  1285. bool ret;
  1286. bool do_repoll = false;
  1287. present = snd_hda_pin_sense(codec, pin_nid);
  1288. mutex_lock(&per_pin->lock);
  1289. eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE);
  1290. if (eld->monitor_present)
  1291. eld->eld_valid = !!(present & AC_PINSENSE_ELDV);
  1292. else
  1293. eld->eld_valid = false;
  1294. codec_dbg(codec,
  1295. "HDMI status: Codec=%d Pin=%d Presence_Detect=%d ELD_Valid=%d\n",
  1296. codec->addr, pin_nid, eld->monitor_present, eld->eld_valid);
  1297. if (eld->eld_valid) {
  1298. if (spec->ops.pin_get_eld(codec, pin_nid, eld->eld_buffer,
  1299. &eld->eld_size) < 0)
  1300. eld->eld_valid = false;
  1301. else {
  1302. if (snd_hdmi_parse_eld(codec, &eld->info, eld->eld_buffer,
  1303. eld->eld_size) < 0)
  1304. eld->eld_valid = false;
  1305. }
  1306. if (!eld->eld_valid && repoll)
  1307. do_repoll = true;
  1308. }
  1309. if (do_repoll)
  1310. schedule_delayed_work(&per_pin->work, msecs_to_jiffies(300));
  1311. else
  1312. update_eld(codec, per_pin, eld);
  1313. ret = !repoll || !eld->monitor_present || eld->eld_valid;
  1314. jack = snd_hda_jack_tbl_get(codec, pin_nid);
  1315. if (jack)
  1316. jack->block_report = !ret;
  1317. mutex_unlock(&per_pin->lock);
  1318. return ret;
  1319. }
  1320. static struct snd_jack *pin_idx_to_jack(struct hda_codec *codec,
  1321. struct hdmi_spec_per_pin *per_pin)
  1322. {
  1323. struct hdmi_spec *spec = codec->spec;
  1324. struct snd_jack *jack = NULL;
  1325. struct hda_jack_tbl *jack_tbl;
  1326. /* if !dyn_pcm_assign, get jack from hda_jack_tbl
  1327. * in !dyn_pcm_assign case, spec->pcm_rec[].jack is not
  1328. * NULL even after snd_hda_jack_tbl_clear() is called to
  1329. * free snd_jack. This may cause access invalid memory
  1330. * when calling snd_jack_report
  1331. */
  1332. if (per_pin->pcm_idx >= 0 && spec->dyn_pcm_assign)
  1333. jack = spec->pcm_rec[per_pin->pcm_idx].jack;
  1334. else if (!spec->dyn_pcm_assign) {
  1335. /*
  1336. * jack tbl doesn't support DP MST
  1337. * DP MST will use dyn_pcm_assign,
  1338. * so DP MST will never come here
  1339. */
  1340. jack_tbl = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
  1341. if (jack_tbl)
  1342. jack = jack_tbl->jack;
  1343. }
  1344. return jack;
  1345. }
  1346. /* update ELD and jack state via audio component */
  1347. static void sync_eld_via_acomp(struct hda_codec *codec,
  1348. struct hdmi_spec_per_pin *per_pin)
  1349. {
  1350. struct hdmi_spec *spec = codec->spec;
  1351. struct hdmi_eld *eld = &spec->temp_eld;
  1352. struct snd_jack *jack = NULL;
  1353. int size;
  1354. mutex_lock(&per_pin->lock);
  1355. eld->monitor_present = false;
  1356. size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid,
  1357. per_pin->dev_id, &eld->monitor_present,
  1358. eld->eld_buffer, ELD_MAX_SIZE);
  1359. if (size > 0) {
  1360. size = min(size, ELD_MAX_SIZE);
  1361. if (snd_hdmi_parse_eld(codec, &eld->info,
  1362. eld->eld_buffer, size) < 0)
  1363. size = -EINVAL;
  1364. }
  1365. if (size > 0) {
  1366. eld->eld_valid = true;
  1367. eld->eld_size = size;
  1368. } else {
  1369. eld->eld_valid = false;
  1370. eld->eld_size = 0;
  1371. }
  1372. /* pcm_idx >=0 before update_eld() means it is in monitor
  1373. * disconnected event. Jack must be fetched before update_eld()
  1374. */
  1375. jack = pin_idx_to_jack(codec, per_pin);
  1376. update_eld(codec, per_pin, eld);
  1377. if (jack == NULL)
  1378. jack = pin_idx_to_jack(codec, per_pin);
  1379. if (jack == NULL)
  1380. goto unlock;
  1381. snd_jack_report(jack,
  1382. eld->monitor_present ? SND_JACK_AVOUT : 0);
  1383. unlock:
  1384. mutex_unlock(&per_pin->lock);
  1385. }
  1386. static bool hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, int repoll)
  1387. {
  1388. struct hda_codec *codec = per_pin->codec;
  1389. int ret;
  1390. /* no temporary power up/down needed for component notifier */
  1391. if (!codec_has_acomp(codec)) {
  1392. ret = snd_hda_power_up_pm(codec);
  1393. if (ret < 0 && pm_runtime_suspended(hda_codec_dev(codec))) {
  1394. snd_hda_power_down_pm(codec);
  1395. return false;
  1396. }
  1397. }
  1398. if (codec_has_acomp(codec)) {
  1399. sync_eld_via_acomp(codec, per_pin);
  1400. ret = false; /* don't call snd_hda_jack_report_sync() */
  1401. } else {
  1402. ret = hdmi_present_sense_via_verbs(per_pin, repoll);
  1403. }
  1404. if (!codec_has_acomp(codec))
  1405. snd_hda_power_down_pm(codec);
  1406. return ret;
  1407. }
  1408. static void hdmi_repoll_eld(struct work_struct *work)
  1409. {
  1410. struct hdmi_spec_per_pin *per_pin =
  1411. container_of(to_delayed_work(work), struct hdmi_spec_per_pin, work);
  1412. struct hda_codec *codec = per_pin->codec;
  1413. struct hdmi_spec *spec = codec->spec;
  1414. if (per_pin->repoll_count++ > 6)
  1415. per_pin->repoll_count = 0;
  1416. mutex_lock(&spec->pcm_lock);
  1417. if (hdmi_present_sense(per_pin, per_pin->repoll_count))
  1418. snd_hda_jack_report_sync(per_pin->codec);
  1419. mutex_unlock(&spec->pcm_lock);
  1420. }
  1421. static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
  1422. hda_nid_t nid);
  1423. static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
  1424. {
  1425. struct hdmi_spec *spec = codec->spec;
  1426. unsigned int caps, config;
  1427. int pin_idx;
  1428. struct hdmi_spec_per_pin *per_pin;
  1429. int err;
  1430. int dev_num, i;
  1431. caps = snd_hda_query_pin_caps(codec, pin_nid);
  1432. if (!(caps & (AC_PINCAP_HDMI | AC_PINCAP_DP)))
  1433. return 0;
  1434. /*
  1435. * For DP MST audio, Configuration Default is the same for
  1436. * all device entries on the same pin
  1437. */
  1438. config = snd_hda_codec_get_pincfg(codec, pin_nid);
  1439. if (get_defcfg_connect(config) == AC_JACK_PORT_NONE)
  1440. return 0;
  1441. /*
  1442. * To simplify the implementation, malloc all
  1443. * the virtual pins in the initialization statically
  1444. */
  1445. if (is_haswell_plus(codec)) {
  1446. /*
  1447. * On Intel platforms, device entries number is
  1448. * changed dynamically. If there is a DP MST
  1449. * hub connected, the device entries number is 3.
  1450. * Otherwise, it is 1.
  1451. * Here we manually set dev_num to 3, so that
  1452. * we can initialize all the device entries when
  1453. * bootup statically.
  1454. */
  1455. dev_num = 3;
  1456. spec->dev_num = 3;
  1457. } else if (spec->dyn_pcm_assign && codec->dp_mst) {
  1458. dev_num = snd_hda_get_num_devices(codec, pin_nid) + 1;
  1459. /*
  1460. * spec->dev_num is the maxinum number of device entries
  1461. * among all the pins
  1462. */
  1463. spec->dev_num = (spec->dev_num > dev_num) ?
  1464. spec->dev_num : dev_num;
  1465. } else {
  1466. /*
  1467. * If the platform doesn't support DP MST,
  1468. * manually set dev_num to 1. This means
  1469. * the pin has only one device entry.
  1470. */
  1471. dev_num = 1;
  1472. spec->dev_num = 1;
  1473. }
  1474. for (i = 0; i < dev_num; i++) {
  1475. pin_idx = spec->num_pins;
  1476. per_pin = snd_array_new(&spec->pins);
  1477. if (!per_pin)
  1478. return -ENOMEM;
  1479. if (spec->dyn_pcm_assign) {
  1480. per_pin->pcm = NULL;
  1481. per_pin->pcm_idx = -1;
  1482. } else {
  1483. per_pin->pcm = get_hdmi_pcm(spec, pin_idx);
  1484. per_pin->pcm_idx = pin_idx;
  1485. }
  1486. per_pin->pin_nid = pin_nid;
  1487. per_pin->pin_nid_idx = spec->num_nids;
  1488. per_pin->dev_id = i;
  1489. per_pin->non_pcm = false;
  1490. snd_hda_set_dev_select(codec, pin_nid, i);
  1491. if (is_haswell_plus(codec))
  1492. intel_haswell_fixup_connect_list(codec, pin_nid);
  1493. err = hdmi_read_pin_conn(codec, pin_idx);
  1494. if (err < 0)
  1495. return err;
  1496. spec->num_pins++;
  1497. }
  1498. spec->num_nids++;
  1499. return 0;
  1500. }
  1501. static int hdmi_add_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
  1502. {
  1503. struct hdmi_spec *spec = codec->spec;
  1504. struct hdmi_spec_per_cvt *per_cvt;
  1505. unsigned int chans;
  1506. int err;
  1507. chans = get_wcaps(codec, cvt_nid);
  1508. chans = get_wcaps_channels(chans);
  1509. per_cvt = snd_array_new(&spec->cvts);
  1510. if (!per_cvt)
  1511. return -ENOMEM;
  1512. per_cvt->cvt_nid = cvt_nid;
  1513. per_cvt->channels_min = 2;
  1514. if (chans <= 16) {
  1515. per_cvt->channels_max = chans;
  1516. if (chans > spec->chmap.channels_max)
  1517. spec->chmap.channels_max = chans;
  1518. }
  1519. err = snd_hda_query_supported_pcm(codec, cvt_nid,
  1520. &per_cvt->rates,
  1521. &per_cvt->formats,
  1522. &per_cvt->maxbps);
  1523. if (err < 0)
  1524. return err;
  1525. if (spec->num_cvts < ARRAY_SIZE(spec->cvt_nids))
  1526. spec->cvt_nids[spec->num_cvts] = cvt_nid;
  1527. spec->num_cvts++;
  1528. return 0;
  1529. }
  1530. static int hdmi_parse_codec(struct hda_codec *codec)
  1531. {
  1532. hda_nid_t nid;
  1533. int i, nodes;
  1534. nodes = snd_hda_get_sub_nodes(codec, codec->core.afg, &nid);
  1535. if (!nid || nodes < 0) {
  1536. codec_warn(codec, "HDMI: failed to get afg sub nodes\n");
  1537. return -EINVAL;
  1538. }
  1539. for (i = 0; i < nodes; i++, nid++) {
  1540. unsigned int caps;
  1541. unsigned int type;
  1542. caps = get_wcaps(codec, nid);
  1543. type = get_wcaps_type(caps);
  1544. if (!(caps & AC_WCAP_DIGITAL))
  1545. continue;
  1546. switch (type) {
  1547. case AC_WID_AUD_OUT:
  1548. hdmi_add_cvt(codec, nid);
  1549. break;
  1550. case AC_WID_PIN:
  1551. hdmi_add_pin(codec, nid);
  1552. break;
  1553. }
  1554. }
  1555. return 0;
  1556. }
  1557. /*
  1558. */
  1559. static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid)
  1560. {
  1561. struct hda_spdif_out *spdif;
  1562. bool non_pcm;
  1563. mutex_lock(&codec->spdif_mutex);
  1564. spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid);
  1565. /* Add sanity check to pass klockwork check.
  1566. * This should never happen.
  1567. */
  1568. if (WARN_ON(spdif == NULL))
  1569. return true;
  1570. non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO);
  1571. mutex_unlock(&codec->spdif_mutex);
  1572. return non_pcm;
  1573. }
  1574. /*
  1575. * HDMI callbacks
  1576. */
  1577. static int generic_hdmi_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  1578. struct hda_codec *codec,
  1579. unsigned int stream_tag,
  1580. unsigned int format,
  1581. struct snd_pcm_substream *substream)
  1582. {
  1583. hda_nid_t cvt_nid = hinfo->nid;
  1584. struct hdmi_spec *spec = codec->spec;
  1585. int pin_idx;
  1586. struct hdmi_spec_per_pin *per_pin;
  1587. hda_nid_t pin_nid;
  1588. struct snd_pcm_runtime *runtime = substream->runtime;
  1589. bool non_pcm;
  1590. int pinctl;
  1591. int err = 0;
  1592. mutex_lock(&spec->pcm_lock);
  1593. pin_idx = hinfo_to_pin_index(codec, hinfo);
  1594. if (spec->dyn_pcm_assign && pin_idx < 0) {
  1595. /* when dyn_pcm_assign and pcm is not bound to a pin
  1596. * skip pin setup and return 0 to make audio playback
  1597. * be ongoing
  1598. */
  1599. pin_cvt_fixup(codec, NULL, cvt_nid);
  1600. snd_hda_codec_setup_stream(codec, cvt_nid,
  1601. stream_tag, 0, format);
  1602. goto unlock;
  1603. }
  1604. if (snd_BUG_ON(pin_idx < 0)) {
  1605. err = -EINVAL;
  1606. goto unlock;
  1607. }
  1608. per_pin = get_pin(spec, pin_idx);
  1609. pin_nid = per_pin->pin_nid;
  1610. /* Verify pin:cvt selections to avoid silent audio after S3.
  1611. * After S3, the audio driver restores pin:cvt selections
  1612. * but this can happen before gfx is ready and such selection
  1613. * is overlooked by HW. Thus multiple pins can share a same
  1614. * default convertor and mute control will affect each other,
  1615. * which can cause a resumed audio playback become silent
  1616. * after S3.
  1617. */
  1618. pin_cvt_fixup(codec, per_pin, 0);
  1619. /* Call sync_audio_rate to set the N/CTS/M manually if necessary */
  1620. /* Todo: add DP1.2 MST audio support later */
  1621. if (codec_has_acomp(codec))
  1622. snd_hdac_sync_audio_rate(&codec->core, pin_nid, per_pin->dev_id,
  1623. runtime->rate);
  1624. non_pcm = check_non_pcm_per_cvt(codec, cvt_nid);
  1625. mutex_lock(&per_pin->lock);
  1626. per_pin->channels = substream->runtime->channels;
  1627. per_pin->setup = true;
  1628. hdmi_setup_audio_infoframe(codec, per_pin, non_pcm);
  1629. mutex_unlock(&per_pin->lock);
  1630. if (spec->dyn_pin_out) {
  1631. pinctl = snd_hda_codec_read(codec, pin_nid, 0,
  1632. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1633. snd_hda_codec_write(codec, pin_nid, 0,
  1634. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1635. pinctl | PIN_OUT);
  1636. }
  1637. /* snd_hda_set_dev_select() has been called before */
  1638. err = spec->ops.setup_stream(codec, cvt_nid, pin_nid,
  1639. stream_tag, format);
  1640. unlock:
  1641. mutex_unlock(&spec->pcm_lock);
  1642. return err;
  1643. }
  1644. static int generic_hdmi_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
  1645. struct hda_codec *codec,
  1646. struct snd_pcm_substream *substream)
  1647. {
  1648. snd_hda_codec_cleanup_stream(codec, hinfo->nid);
  1649. return 0;
  1650. }
  1651. static int hdmi_pcm_close(struct hda_pcm_stream *hinfo,
  1652. struct hda_codec *codec,
  1653. struct snd_pcm_substream *substream)
  1654. {
  1655. struct hdmi_spec *spec = codec->spec;
  1656. int cvt_idx, pin_idx, pcm_idx;
  1657. struct hdmi_spec_per_cvt *per_cvt;
  1658. struct hdmi_spec_per_pin *per_pin;
  1659. int pinctl;
  1660. int err = 0;
  1661. if (hinfo->nid) {
  1662. pcm_idx = hinfo_to_pcm_index(codec, hinfo);
  1663. if (snd_BUG_ON(pcm_idx < 0))
  1664. return -EINVAL;
  1665. cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid);
  1666. if (snd_BUG_ON(cvt_idx < 0))
  1667. return -EINVAL;
  1668. per_cvt = get_cvt(spec, cvt_idx);
  1669. snd_BUG_ON(!per_cvt->assigned);
  1670. per_cvt->assigned = 0;
  1671. hinfo->nid = 0;
  1672. mutex_lock(&spec->pcm_lock);
  1673. snd_hda_spdif_ctls_unassign(codec, pcm_idx);
  1674. clear_bit(pcm_idx, &spec->pcm_in_use);
  1675. pin_idx = hinfo_to_pin_index(codec, hinfo);
  1676. if (spec->dyn_pcm_assign && pin_idx < 0)
  1677. goto unlock;
  1678. if (snd_BUG_ON(pin_idx < 0)) {
  1679. err = -EINVAL;
  1680. goto unlock;
  1681. }
  1682. per_pin = get_pin(spec, pin_idx);
  1683. if (spec->dyn_pin_out) {
  1684. pinctl = snd_hda_codec_read(codec, per_pin->pin_nid, 0,
  1685. AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
  1686. snd_hda_codec_write(codec, per_pin->pin_nid, 0,
  1687. AC_VERB_SET_PIN_WIDGET_CONTROL,
  1688. pinctl & ~PIN_OUT);
  1689. }
  1690. mutex_lock(&per_pin->lock);
  1691. per_pin->chmap_set = false;
  1692. memset(per_pin->chmap, 0, sizeof(per_pin->chmap));
  1693. per_pin->setup = false;
  1694. per_pin->channels = 0;
  1695. mutex_unlock(&per_pin->lock);
  1696. unlock:
  1697. mutex_unlock(&spec->pcm_lock);
  1698. }
  1699. return err;
  1700. }
  1701. static const struct hda_pcm_ops generic_ops = {
  1702. .open = hdmi_pcm_open,
  1703. .close = hdmi_pcm_close,
  1704. .prepare = generic_hdmi_playback_pcm_prepare,
  1705. .cleanup = generic_hdmi_playback_pcm_cleanup,
  1706. };
  1707. static int hdmi_get_spk_alloc(struct hdac_device *hdac, int pcm_idx)
  1708. {
  1709. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  1710. struct hdmi_spec *spec = codec->spec;
  1711. struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
  1712. if (!per_pin)
  1713. return 0;
  1714. return per_pin->sink_eld.info.spk_alloc;
  1715. }
  1716. static void hdmi_get_chmap(struct hdac_device *hdac, int pcm_idx,
  1717. unsigned char *chmap)
  1718. {
  1719. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  1720. struct hdmi_spec *spec = codec->spec;
  1721. struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
  1722. /* chmap is already set to 0 in caller */
  1723. if (!per_pin)
  1724. return;
  1725. memcpy(chmap, per_pin->chmap, ARRAY_SIZE(per_pin->chmap));
  1726. }
  1727. static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx,
  1728. unsigned char *chmap, int prepared)
  1729. {
  1730. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  1731. struct hdmi_spec *spec = codec->spec;
  1732. struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
  1733. if (!per_pin)
  1734. return;
  1735. mutex_lock(&per_pin->lock);
  1736. per_pin->chmap_set = true;
  1737. memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap));
  1738. if (prepared)
  1739. hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm);
  1740. mutex_unlock(&per_pin->lock);
  1741. }
  1742. static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx)
  1743. {
  1744. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  1745. struct hdmi_spec *spec = codec->spec;
  1746. struct hdmi_spec_per_pin *per_pin = pcm_idx_to_pin(spec, pcm_idx);
  1747. return per_pin ? true:false;
  1748. }
  1749. static int generic_hdmi_build_pcms(struct hda_codec *codec)
  1750. {
  1751. struct hdmi_spec *spec = codec->spec;
  1752. int idx;
  1753. /*
  1754. * for non-mst mode, pcm number is the same as before
  1755. * for DP MST mode, pcm number is (nid number + dev_num - 1)
  1756. * dev_num is the device entry number in a pin
  1757. *
  1758. */
  1759. for (idx = 0; idx < spec->num_nids + spec->dev_num - 1; idx++) {
  1760. struct hda_pcm *info;
  1761. struct hda_pcm_stream *pstr;
  1762. info = snd_hda_codec_pcm_new(codec, "HDMI %d", idx);
  1763. if (!info)
  1764. return -ENOMEM;
  1765. spec->pcm_rec[idx].pcm = info;
  1766. spec->pcm_used++;
  1767. info->pcm_type = HDA_PCM_TYPE_HDMI;
  1768. info->own_chmap = true;
  1769. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  1770. pstr->substreams = 1;
  1771. pstr->ops = generic_ops;
  1772. /* pcm number is less than 16 */
  1773. if (spec->pcm_used >= 16)
  1774. break;
  1775. /* other pstr fields are set in open */
  1776. }
  1777. return 0;
  1778. }
  1779. static void free_hdmi_jack_priv(struct snd_jack *jack)
  1780. {
  1781. struct hdmi_pcm *pcm = jack->private_data;
  1782. pcm->jack = NULL;
  1783. }
  1784. static int add_hdmi_jack_kctl(struct hda_codec *codec,
  1785. struct hdmi_spec *spec,
  1786. int pcm_idx,
  1787. const char *name)
  1788. {
  1789. struct snd_jack *jack;
  1790. int err;
  1791. err = snd_jack_new(codec->card, name, SND_JACK_AVOUT, &jack,
  1792. true, false);
  1793. if (err < 0)
  1794. return err;
  1795. spec->pcm_rec[pcm_idx].jack = jack;
  1796. jack->private_data = &spec->pcm_rec[pcm_idx];
  1797. jack->private_free = free_hdmi_jack_priv;
  1798. return 0;
  1799. }
  1800. static int generic_hdmi_build_jack(struct hda_codec *codec, int pcm_idx)
  1801. {
  1802. char hdmi_str[32] = "HDMI/DP";
  1803. struct hdmi_spec *spec = codec->spec;
  1804. struct hdmi_spec_per_pin *per_pin;
  1805. struct hda_jack_tbl *jack;
  1806. int pcmdev = get_pcm_rec(spec, pcm_idx)->device;
  1807. bool phantom_jack;
  1808. int ret;
  1809. if (pcmdev > 0)
  1810. sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);
  1811. if (spec->dyn_pcm_assign)
  1812. return add_hdmi_jack_kctl(codec, spec, pcm_idx, hdmi_str);
  1813. /* for !dyn_pcm_assign, we still use hda_jack for compatibility */
  1814. /* if !dyn_pcm_assign, it must be non-MST mode.
  1815. * This means pcms and pins are statically mapped.
  1816. * And pcm_idx is pin_idx.
  1817. */
  1818. per_pin = get_pin(spec, pcm_idx);
  1819. phantom_jack = !is_jack_detectable(codec, per_pin->pin_nid);
  1820. if (phantom_jack)
  1821. strncat(hdmi_str, " Phantom",
  1822. sizeof(hdmi_str) - strlen(hdmi_str) - 1);
  1823. ret = snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str,
  1824. phantom_jack);
  1825. if (ret < 0)
  1826. return ret;
  1827. jack = snd_hda_jack_tbl_get(codec, per_pin->pin_nid);
  1828. if (jack == NULL)
  1829. return 0;
  1830. /* assign jack->jack to pcm_rec[].jack to
  1831. * align with dyn_pcm_assign mode
  1832. */
  1833. spec->pcm_rec[pcm_idx].jack = jack->jack;
  1834. return 0;
  1835. }
  1836. static int generic_hdmi_build_controls(struct hda_codec *codec)
  1837. {
  1838. struct hdmi_spec *spec = codec->spec;
  1839. int dev, err;
  1840. int pin_idx, pcm_idx;
  1841. for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
  1842. if (!get_pcm_rec(spec, pcm_idx)->pcm) {
  1843. /* no PCM: mark this for skipping permanently */
  1844. set_bit(pcm_idx, &spec->pcm_bitmap);
  1845. continue;
  1846. }
  1847. err = generic_hdmi_build_jack(codec, pcm_idx);
  1848. if (err < 0)
  1849. return err;
  1850. /* create the spdif for each pcm
  1851. * pin will be bound when monitor is connected
  1852. */
  1853. if (spec->dyn_pcm_assign)
  1854. err = snd_hda_create_dig_out_ctls(codec,
  1855. 0, spec->cvt_nids[0],
  1856. HDA_PCM_TYPE_HDMI);
  1857. else {
  1858. struct hdmi_spec_per_pin *per_pin =
  1859. get_pin(spec, pcm_idx);
  1860. err = snd_hda_create_dig_out_ctls(codec,
  1861. per_pin->pin_nid,
  1862. per_pin->mux_nids[0],
  1863. HDA_PCM_TYPE_HDMI);
  1864. }
  1865. if (err < 0)
  1866. return err;
  1867. snd_hda_spdif_ctls_unassign(codec, pcm_idx);
  1868. dev = get_pcm_rec(spec, pcm_idx)->device;
  1869. if (dev != SNDRV_PCM_INVALID_DEVICE) {
  1870. /* add control for ELD Bytes */
  1871. err = hdmi_create_eld_ctl(codec, pcm_idx, dev);
  1872. if (err < 0)
  1873. return err;
  1874. }
  1875. }
  1876. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1877. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1878. hdmi_present_sense(per_pin, 0);
  1879. }
  1880. /* add channel maps */
  1881. for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
  1882. struct hda_pcm *pcm;
  1883. pcm = get_pcm_rec(spec, pcm_idx);
  1884. if (!pcm || !pcm->pcm)
  1885. break;
  1886. err = snd_hdac_add_chmap_ctls(pcm->pcm, pcm_idx, &spec->chmap);
  1887. if (err < 0)
  1888. return err;
  1889. }
  1890. return 0;
  1891. }
  1892. static int generic_hdmi_init_per_pins(struct hda_codec *codec)
  1893. {
  1894. struct hdmi_spec *spec = codec->spec;
  1895. int pin_idx;
  1896. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1897. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1898. per_pin->codec = codec;
  1899. mutex_init(&per_pin->lock);
  1900. INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
  1901. eld_proc_new(per_pin, pin_idx);
  1902. }
  1903. return 0;
  1904. }
  1905. static int generic_hdmi_init(struct hda_codec *codec)
  1906. {
  1907. struct hdmi_spec *spec = codec->spec;
  1908. int pin_idx;
  1909. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1910. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1911. hda_nid_t pin_nid = per_pin->pin_nid;
  1912. int dev_id = per_pin->dev_id;
  1913. snd_hda_set_dev_select(codec, pin_nid, dev_id);
  1914. hdmi_init_pin(codec, pin_nid);
  1915. if (!codec_has_acomp(codec))
  1916. snd_hda_jack_detect_enable_callback(codec, pin_nid,
  1917. codec->jackpoll_interval > 0 ?
  1918. jack_callback : NULL);
  1919. }
  1920. return 0;
  1921. }
  1922. static void hdmi_array_init(struct hdmi_spec *spec, int nums)
  1923. {
  1924. snd_array_init(&spec->pins, sizeof(struct hdmi_spec_per_pin), nums);
  1925. snd_array_init(&spec->cvts, sizeof(struct hdmi_spec_per_cvt), nums);
  1926. }
  1927. static void hdmi_array_free(struct hdmi_spec *spec)
  1928. {
  1929. snd_array_free(&spec->pins);
  1930. snd_array_free(&spec->cvts);
  1931. }
  1932. static void generic_spec_free(struct hda_codec *codec)
  1933. {
  1934. struct hdmi_spec *spec = codec->spec;
  1935. if (spec) {
  1936. hdmi_array_free(spec);
  1937. kfree(spec);
  1938. codec->spec = NULL;
  1939. }
  1940. codec->dp_mst = false;
  1941. }
  1942. static void generic_hdmi_free(struct hda_codec *codec)
  1943. {
  1944. struct hdmi_spec *spec = codec->spec;
  1945. int pin_idx, pcm_idx;
  1946. if (codec_has_acomp(codec))
  1947. snd_hdac_acomp_register_notifier(&codec->bus->core, NULL);
  1948. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1949. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1950. cancel_delayed_work_sync(&per_pin->work);
  1951. eld_proc_free(per_pin);
  1952. }
  1953. for (pcm_idx = 0; pcm_idx < spec->pcm_used; pcm_idx++) {
  1954. if (spec->pcm_rec[pcm_idx].jack == NULL)
  1955. continue;
  1956. if (spec->dyn_pcm_assign)
  1957. snd_device_free(codec->card,
  1958. spec->pcm_rec[pcm_idx].jack);
  1959. else
  1960. spec->pcm_rec[pcm_idx].jack = NULL;
  1961. }
  1962. generic_spec_free(codec);
  1963. }
  1964. #ifdef CONFIG_PM
  1965. static int generic_hdmi_resume(struct hda_codec *codec)
  1966. {
  1967. struct hdmi_spec *spec = codec->spec;
  1968. int pin_idx;
  1969. codec->patch_ops.init(codec);
  1970. regcache_sync(codec->core.regmap);
  1971. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  1972. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  1973. hdmi_present_sense(per_pin, 1);
  1974. }
  1975. return 0;
  1976. }
  1977. #endif
  1978. static const struct hda_codec_ops generic_hdmi_patch_ops = {
  1979. .init = generic_hdmi_init,
  1980. .free = generic_hdmi_free,
  1981. .build_pcms = generic_hdmi_build_pcms,
  1982. .build_controls = generic_hdmi_build_controls,
  1983. .unsol_event = hdmi_unsol_event,
  1984. #ifdef CONFIG_PM
  1985. .resume = generic_hdmi_resume,
  1986. #endif
  1987. };
  1988. static const struct hdmi_ops generic_standard_hdmi_ops = {
  1989. .pin_get_eld = snd_hdmi_get_eld,
  1990. .pin_setup_infoframe = hdmi_pin_setup_infoframe,
  1991. .pin_hbr_setup = hdmi_pin_hbr_setup,
  1992. .setup_stream = hdmi_setup_stream,
  1993. };
  1994. /* allocate codec->spec and assign/initialize generic parser ops */
  1995. static int alloc_generic_hdmi(struct hda_codec *codec)
  1996. {
  1997. struct hdmi_spec *spec;
  1998. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  1999. if (!spec)
  2000. return -ENOMEM;
  2001. spec->ops = generic_standard_hdmi_ops;
  2002. spec->dev_num = 1; /* initialize to 1 */
  2003. mutex_init(&spec->pcm_lock);
  2004. snd_hdac_register_chmap_ops(&codec->core, &spec->chmap);
  2005. spec->chmap.ops.get_chmap = hdmi_get_chmap;
  2006. spec->chmap.ops.set_chmap = hdmi_set_chmap;
  2007. spec->chmap.ops.is_pcm_attached = is_hdmi_pcm_attached;
  2008. spec->chmap.ops.get_spk_alloc = hdmi_get_spk_alloc,
  2009. codec->spec = spec;
  2010. hdmi_array_init(spec, 4);
  2011. codec->patch_ops = generic_hdmi_patch_ops;
  2012. return 0;
  2013. }
  2014. /* generic HDMI parser */
  2015. static int patch_generic_hdmi(struct hda_codec *codec)
  2016. {
  2017. int err;
  2018. err = alloc_generic_hdmi(codec);
  2019. if (err < 0)
  2020. return err;
  2021. err = hdmi_parse_codec(codec);
  2022. if (err < 0) {
  2023. generic_spec_free(codec);
  2024. return err;
  2025. }
  2026. generic_hdmi_init_per_pins(codec);
  2027. return 0;
  2028. }
  2029. /*
  2030. * Intel codec parsers and helpers
  2031. */
  2032. static void intel_haswell_fixup_connect_list(struct hda_codec *codec,
  2033. hda_nid_t nid)
  2034. {
  2035. struct hdmi_spec *spec = codec->spec;
  2036. hda_nid_t conns[4];
  2037. int nconns;
  2038. nconns = snd_hda_get_connections(codec, nid, conns, ARRAY_SIZE(conns));
  2039. if (nconns == spec->num_cvts &&
  2040. !memcmp(conns, spec->cvt_nids, spec->num_cvts * sizeof(hda_nid_t)))
  2041. return;
  2042. /* override pins connection list */
  2043. codec_dbg(codec, "hdmi: haswell: override pin connection 0x%x\n", nid);
  2044. snd_hda_override_conn_list(codec, nid, spec->num_cvts, spec->cvt_nids);
  2045. }
  2046. #define INTEL_VENDOR_NID 0x08
  2047. #define INTEL_GLK_VENDOR_NID 0x0B
  2048. #define INTEL_GET_VENDOR_VERB 0xf81
  2049. #define INTEL_SET_VENDOR_VERB 0x781
  2050. #define INTEL_EN_DP12 0x02 /* enable DP 1.2 features */
  2051. #define INTEL_EN_ALL_PIN_CVTS 0x01 /* enable 2nd & 3rd pins and convertors */
  2052. static void intel_haswell_enable_all_pins(struct hda_codec *codec,
  2053. bool update_tree)
  2054. {
  2055. unsigned int vendor_param;
  2056. struct hdmi_spec *spec = codec->spec;
  2057. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  2058. INTEL_GET_VENDOR_VERB, 0);
  2059. if (vendor_param == -1 || vendor_param & INTEL_EN_ALL_PIN_CVTS)
  2060. return;
  2061. vendor_param |= INTEL_EN_ALL_PIN_CVTS;
  2062. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  2063. INTEL_SET_VENDOR_VERB, vendor_param);
  2064. if (vendor_param == -1)
  2065. return;
  2066. if (update_tree)
  2067. snd_hda_codec_update_widgets(codec);
  2068. }
  2069. static void intel_haswell_fixup_enable_dp12(struct hda_codec *codec)
  2070. {
  2071. unsigned int vendor_param;
  2072. struct hdmi_spec *spec = codec->spec;
  2073. vendor_param = snd_hda_codec_read(codec, spec->vendor_nid, 0,
  2074. INTEL_GET_VENDOR_VERB, 0);
  2075. if (vendor_param == -1 || vendor_param & INTEL_EN_DP12)
  2076. return;
  2077. /* enable DP1.2 mode */
  2078. vendor_param |= INTEL_EN_DP12;
  2079. snd_hdac_regmap_add_vendor_verb(&codec->core, INTEL_SET_VENDOR_VERB);
  2080. snd_hda_codec_write_cache(codec, spec->vendor_nid, 0,
  2081. INTEL_SET_VENDOR_VERB, vendor_param);
  2082. }
  2083. /* Haswell needs to re-issue the vendor-specific verbs before turning to D0.
  2084. * Otherwise you may get severe h/w communication errors.
  2085. */
  2086. static void haswell_set_power_state(struct hda_codec *codec, hda_nid_t fg,
  2087. unsigned int power_state)
  2088. {
  2089. if (power_state == AC_PWRST_D0) {
  2090. intel_haswell_enable_all_pins(codec, false);
  2091. intel_haswell_fixup_enable_dp12(codec);
  2092. }
  2093. snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE, power_state);
  2094. snd_hda_codec_set_power_to_all(codec, fg, power_state);
  2095. }
  2096. /* There is a fixed mapping between audio pin node and display port.
  2097. * on SNB, IVY, HSW, BSW, SKL, BXT, KBL:
  2098. * Pin Widget 5 - PORT B (port = 1 in i915 driver)
  2099. * Pin Widget 6 - PORT C (port = 2 in i915 driver)
  2100. * Pin Widget 7 - PORT D (port = 3 in i915 driver)
  2101. *
  2102. * on VLV, ILK:
  2103. * Pin Widget 4 - PORT B (port = 1 in i915 driver)
  2104. * Pin Widget 5 - PORT C (port = 2 in i915 driver)
  2105. * Pin Widget 6 - PORT D (port = 3 in i915 driver)
  2106. */
  2107. static int intel_base_nid(struct hda_codec *codec)
  2108. {
  2109. switch (codec->core.vendor_id) {
  2110. case 0x80860054: /* ILK */
  2111. case 0x80862804: /* ILK */
  2112. case 0x80862882: /* VLV */
  2113. return 4;
  2114. default:
  2115. return 5;
  2116. }
  2117. }
  2118. static int intel_pin2port(void *audio_ptr, int pin_nid)
  2119. {
  2120. int base_nid = intel_base_nid(audio_ptr);
  2121. if (WARN_ON(pin_nid < base_nid || pin_nid >= base_nid + 3))
  2122. return -1;
  2123. return pin_nid - base_nid + 1; /* intel port is 1-based */
  2124. }
  2125. static void intel_pin_eld_notify(void *audio_ptr, int port, int pipe)
  2126. {
  2127. struct hda_codec *codec = audio_ptr;
  2128. int pin_nid;
  2129. int dev_id = pipe;
  2130. /* we assume only from port-B to port-D */
  2131. if (port < 1 || port > 3)
  2132. return;
  2133. pin_nid = port + intel_base_nid(codec) - 1; /* intel port is 1-based */
  2134. /* skip notification during system suspend (but not in runtime PM);
  2135. * the state will be updated at resume
  2136. */
  2137. if (snd_power_get_state(codec->card) != SNDRV_CTL_POWER_D0)
  2138. return;
  2139. /* ditto during suspend/resume process itself */
  2140. if (snd_hdac_is_in_pm(&codec->core))
  2141. return;
  2142. snd_hdac_i915_set_bclk(&codec->bus->core);
  2143. check_presence_and_report(codec, pin_nid, dev_id);
  2144. }
  2145. /* register i915 component pin_eld_notify callback */
  2146. static void register_i915_notifier(struct hda_codec *codec)
  2147. {
  2148. struct hdmi_spec *spec = codec->spec;
  2149. spec->use_acomp_notifier = true;
  2150. spec->drm_audio_ops.audio_ptr = codec;
  2151. /* intel_audio_codec_enable() or intel_audio_codec_disable()
  2152. * will call pin_eld_notify with using audio_ptr pointer
  2153. * We need make sure audio_ptr is really setup
  2154. */
  2155. wmb();
  2156. spec->drm_audio_ops.pin2port = intel_pin2port;
  2157. spec->drm_audio_ops.pin_eld_notify = intel_pin_eld_notify;
  2158. snd_hdac_acomp_register_notifier(&codec->bus->core,
  2159. &spec->drm_audio_ops);
  2160. }
  2161. /* setup_stream ops override for HSW+ */
  2162. static int i915_hsw_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  2163. hda_nid_t pin_nid, u32 stream_tag, int format)
  2164. {
  2165. haswell_verify_D0(codec, cvt_nid, pin_nid);
  2166. return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
  2167. }
  2168. /* pin_cvt_fixup ops override for HSW+ and VLV+ */
  2169. static void i915_pin_cvt_fixup(struct hda_codec *codec,
  2170. struct hdmi_spec_per_pin *per_pin,
  2171. hda_nid_t cvt_nid)
  2172. {
  2173. if (per_pin) {
  2174. snd_hda_set_dev_select(codec, per_pin->pin_nid,
  2175. per_pin->dev_id);
  2176. intel_verify_pin_cvt_connect(codec, per_pin);
  2177. intel_not_share_assigned_cvt(codec, per_pin->pin_nid,
  2178. per_pin->dev_id, per_pin->mux_idx);
  2179. } else {
  2180. intel_not_share_assigned_cvt_nid(codec, 0, 0, cvt_nid);
  2181. }
  2182. }
  2183. /* precondition and allocation for Intel codecs */
  2184. static int alloc_intel_hdmi(struct hda_codec *codec)
  2185. {
  2186. /* requires i915 binding */
  2187. if (!codec->bus->core.audio_component) {
  2188. codec_info(codec, "No i915 binding for Intel HDMI/DP codec\n");
  2189. /* set probe_id here to prevent generic fallback binding */
  2190. codec->probe_id = HDA_CODEC_ID_SKIP_PROBE;
  2191. return -ENODEV;
  2192. }
  2193. return alloc_generic_hdmi(codec);
  2194. }
  2195. /* parse and post-process for Intel codecs */
  2196. static int parse_intel_hdmi(struct hda_codec *codec)
  2197. {
  2198. int err;
  2199. err = hdmi_parse_codec(codec);
  2200. if (err < 0) {
  2201. generic_spec_free(codec);
  2202. return err;
  2203. }
  2204. generic_hdmi_init_per_pins(codec);
  2205. register_i915_notifier(codec);
  2206. return 0;
  2207. }
  2208. /* Intel Haswell and onwards; audio component with eld notifier */
  2209. static int intel_hsw_common_init(struct hda_codec *codec, hda_nid_t vendor_nid)
  2210. {
  2211. struct hdmi_spec *spec;
  2212. int err;
  2213. err = alloc_intel_hdmi(codec);
  2214. if (err < 0)
  2215. return err;
  2216. spec = codec->spec;
  2217. codec->dp_mst = true;
  2218. spec->dyn_pcm_assign = true;
  2219. spec->vendor_nid = vendor_nid;
  2220. intel_haswell_enable_all_pins(codec, true);
  2221. intel_haswell_fixup_enable_dp12(codec);
  2222. /* For Haswell/Broadwell, the controller is also in the power well and
  2223. * can cover the codec power request, and so need not set this flag.
  2224. */
  2225. if (!is_haswell(codec) && !is_broadwell(codec))
  2226. codec->core.link_power_control = 1;
  2227. codec->patch_ops.set_power_state = haswell_set_power_state;
  2228. codec->depop_delay = 0;
  2229. codec->auto_runtime_pm = 1;
  2230. spec->ops.setup_stream = i915_hsw_setup_stream;
  2231. spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
  2232. return parse_intel_hdmi(codec);
  2233. }
  2234. static int patch_i915_hsw_hdmi(struct hda_codec *codec)
  2235. {
  2236. return intel_hsw_common_init(codec, INTEL_VENDOR_NID);
  2237. }
  2238. static int patch_i915_glk_hdmi(struct hda_codec *codec)
  2239. {
  2240. return intel_hsw_common_init(codec, INTEL_GLK_VENDOR_NID);
  2241. }
  2242. /* Intel Baytrail and Braswell; with eld notifier */
  2243. static int patch_i915_byt_hdmi(struct hda_codec *codec)
  2244. {
  2245. struct hdmi_spec *spec;
  2246. int err;
  2247. err = alloc_intel_hdmi(codec);
  2248. if (err < 0)
  2249. return err;
  2250. spec = codec->spec;
  2251. /* For Valleyview/Cherryview, only the display codec is in the display
  2252. * power well and can use link_power ops to request/release the power.
  2253. */
  2254. codec->core.link_power_control = 1;
  2255. codec->depop_delay = 0;
  2256. codec->auto_runtime_pm = 1;
  2257. spec->ops.pin_cvt_fixup = i915_pin_cvt_fixup;
  2258. return parse_intel_hdmi(codec);
  2259. }
  2260. /* Intel IronLake, SandyBridge and IvyBridge; with eld notifier */
  2261. static int patch_i915_cpt_hdmi(struct hda_codec *codec)
  2262. {
  2263. int err;
  2264. err = alloc_intel_hdmi(codec);
  2265. if (err < 0)
  2266. return err;
  2267. return parse_intel_hdmi(codec);
  2268. }
  2269. /*
  2270. * Shared non-generic implementations
  2271. */
  2272. static int simple_playback_build_pcms(struct hda_codec *codec)
  2273. {
  2274. struct hdmi_spec *spec = codec->spec;
  2275. struct hda_pcm *info;
  2276. unsigned int chans;
  2277. struct hda_pcm_stream *pstr;
  2278. struct hdmi_spec_per_cvt *per_cvt;
  2279. per_cvt = get_cvt(spec, 0);
  2280. chans = get_wcaps(codec, per_cvt->cvt_nid);
  2281. chans = get_wcaps_channels(chans);
  2282. info = snd_hda_codec_pcm_new(codec, "HDMI 0");
  2283. if (!info)
  2284. return -ENOMEM;
  2285. spec->pcm_rec[0].pcm = info;
  2286. info->pcm_type = HDA_PCM_TYPE_HDMI;
  2287. pstr = &info->stream[SNDRV_PCM_STREAM_PLAYBACK];
  2288. *pstr = spec->pcm_playback;
  2289. pstr->nid = per_cvt->cvt_nid;
  2290. if (pstr->channels_max <= 2 && chans && chans <= 16)
  2291. pstr->channels_max = chans;
  2292. return 0;
  2293. }
  2294. /* unsolicited event for jack sensing */
  2295. static void simple_hdmi_unsol_event(struct hda_codec *codec,
  2296. unsigned int res)
  2297. {
  2298. snd_hda_jack_set_dirty_all(codec);
  2299. snd_hda_jack_report_sync(codec);
  2300. }
  2301. /* generic_hdmi_build_jack can be used for simple_hdmi, too,
  2302. * as long as spec->pins[] is set correctly
  2303. */
  2304. #define simple_hdmi_build_jack generic_hdmi_build_jack
  2305. static int simple_playback_build_controls(struct hda_codec *codec)
  2306. {
  2307. struct hdmi_spec *spec = codec->spec;
  2308. struct hdmi_spec_per_cvt *per_cvt;
  2309. int err;
  2310. per_cvt = get_cvt(spec, 0);
  2311. err = snd_hda_create_dig_out_ctls(codec, per_cvt->cvt_nid,
  2312. per_cvt->cvt_nid,
  2313. HDA_PCM_TYPE_HDMI);
  2314. if (err < 0)
  2315. return err;
  2316. return simple_hdmi_build_jack(codec, 0);
  2317. }
  2318. static int simple_playback_init(struct hda_codec *codec)
  2319. {
  2320. struct hdmi_spec *spec = codec->spec;
  2321. struct hdmi_spec_per_pin *per_pin = get_pin(spec, 0);
  2322. hda_nid_t pin = per_pin->pin_nid;
  2323. snd_hda_codec_write(codec, pin, 0,
  2324. AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT);
  2325. /* some codecs require to unmute the pin */
  2326. if (get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)
  2327. snd_hda_codec_write(codec, pin, 0, AC_VERB_SET_AMP_GAIN_MUTE,
  2328. AMP_OUT_UNMUTE);
  2329. snd_hda_jack_detect_enable(codec, pin);
  2330. return 0;
  2331. }
  2332. static void simple_playback_free(struct hda_codec *codec)
  2333. {
  2334. struct hdmi_spec *spec = codec->spec;
  2335. hdmi_array_free(spec);
  2336. kfree(spec);
  2337. }
  2338. /*
  2339. * Nvidia specific implementations
  2340. */
  2341. #define Nv_VERB_SET_Channel_Allocation 0xF79
  2342. #define Nv_VERB_SET_Info_Frame_Checksum 0xF7A
  2343. #define Nv_VERB_SET_Audio_Protection_On 0xF98
  2344. #define Nv_VERB_SET_Audio_Protection_Off 0xF99
  2345. #define nvhdmi_master_con_nid_7x 0x04
  2346. #define nvhdmi_master_pin_nid_7x 0x05
  2347. static const hda_nid_t nvhdmi_con_nids_7x[4] = {
  2348. /*front, rear, clfe, rear_surr */
  2349. 0x6, 0x8, 0xa, 0xc,
  2350. };
  2351. static const struct hda_verb nvhdmi_basic_init_7x_2ch[] = {
  2352. /* set audio protect on */
  2353. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  2354. /* enable digital output on pin widget */
  2355. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2356. {} /* terminator */
  2357. };
  2358. static const struct hda_verb nvhdmi_basic_init_7x_8ch[] = {
  2359. /* set audio protect on */
  2360. { 0x1, Nv_VERB_SET_Audio_Protection_On, 0x1},
  2361. /* enable digital output on pin widget */
  2362. { 0x5, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2363. { 0x7, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2364. { 0x9, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2365. { 0xb, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2366. { 0xd, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT | 0x5 },
  2367. {} /* terminator */
  2368. };
  2369. #ifdef LIMITED_RATE_FMT_SUPPORT
  2370. /* support only the safe format and rate */
  2371. #define SUPPORTED_RATES SNDRV_PCM_RATE_48000
  2372. #define SUPPORTED_MAXBPS 16
  2373. #define SUPPORTED_FORMATS SNDRV_PCM_FMTBIT_S16_LE
  2374. #else
  2375. /* support all rates and formats */
  2376. #define SUPPORTED_RATES \
  2377. (SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |\
  2378. SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | SNDRV_PCM_RATE_176400 |\
  2379. SNDRV_PCM_RATE_192000)
  2380. #define SUPPORTED_MAXBPS 24
  2381. #define SUPPORTED_FORMATS \
  2382. (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE)
  2383. #endif
  2384. static int nvhdmi_7x_init_2ch(struct hda_codec *codec)
  2385. {
  2386. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_2ch);
  2387. return 0;
  2388. }
  2389. static int nvhdmi_7x_init_8ch(struct hda_codec *codec)
  2390. {
  2391. snd_hda_sequence_write(codec, nvhdmi_basic_init_7x_8ch);
  2392. return 0;
  2393. }
  2394. static const unsigned int channels_2_6_8[] = {
  2395. 2, 6, 8
  2396. };
  2397. static const unsigned int channels_2_8[] = {
  2398. 2, 8
  2399. };
  2400. static const struct snd_pcm_hw_constraint_list hw_constraints_2_6_8_channels = {
  2401. .count = ARRAY_SIZE(channels_2_6_8),
  2402. .list = channels_2_6_8,
  2403. .mask = 0,
  2404. };
  2405. static const struct snd_pcm_hw_constraint_list hw_constraints_2_8_channels = {
  2406. .count = ARRAY_SIZE(channels_2_8),
  2407. .list = channels_2_8,
  2408. .mask = 0,
  2409. };
  2410. static int simple_playback_pcm_open(struct hda_pcm_stream *hinfo,
  2411. struct hda_codec *codec,
  2412. struct snd_pcm_substream *substream)
  2413. {
  2414. struct hdmi_spec *spec = codec->spec;
  2415. const struct snd_pcm_hw_constraint_list *hw_constraints_channels = NULL;
  2416. switch (codec->preset->vendor_id) {
  2417. case 0x10de0002:
  2418. case 0x10de0003:
  2419. case 0x10de0005:
  2420. case 0x10de0006:
  2421. hw_constraints_channels = &hw_constraints_2_8_channels;
  2422. break;
  2423. case 0x10de0007:
  2424. hw_constraints_channels = &hw_constraints_2_6_8_channels;
  2425. break;
  2426. default:
  2427. break;
  2428. }
  2429. if (hw_constraints_channels != NULL) {
  2430. snd_pcm_hw_constraint_list(substream->runtime, 0,
  2431. SNDRV_PCM_HW_PARAM_CHANNELS,
  2432. hw_constraints_channels);
  2433. } else {
  2434. snd_pcm_hw_constraint_step(substream->runtime, 0,
  2435. SNDRV_PCM_HW_PARAM_CHANNELS, 2);
  2436. }
  2437. return snd_hda_multi_out_dig_open(codec, &spec->multiout);
  2438. }
  2439. static int simple_playback_pcm_close(struct hda_pcm_stream *hinfo,
  2440. struct hda_codec *codec,
  2441. struct snd_pcm_substream *substream)
  2442. {
  2443. struct hdmi_spec *spec = codec->spec;
  2444. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  2445. }
  2446. static int simple_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
  2447. struct hda_codec *codec,
  2448. unsigned int stream_tag,
  2449. unsigned int format,
  2450. struct snd_pcm_substream *substream)
  2451. {
  2452. struct hdmi_spec *spec = codec->spec;
  2453. return snd_hda_multi_out_dig_prepare(codec, &spec->multiout,
  2454. stream_tag, format, substream);
  2455. }
  2456. static const struct hda_pcm_stream simple_pcm_playback = {
  2457. .substreams = 1,
  2458. .channels_min = 2,
  2459. .channels_max = 2,
  2460. .ops = {
  2461. .open = simple_playback_pcm_open,
  2462. .close = simple_playback_pcm_close,
  2463. .prepare = simple_playback_pcm_prepare
  2464. },
  2465. };
  2466. static const struct hda_codec_ops simple_hdmi_patch_ops = {
  2467. .build_controls = simple_playback_build_controls,
  2468. .build_pcms = simple_playback_build_pcms,
  2469. .init = simple_playback_init,
  2470. .free = simple_playback_free,
  2471. .unsol_event = simple_hdmi_unsol_event,
  2472. };
  2473. static int patch_simple_hdmi(struct hda_codec *codec,
  2474. hda_nid_t cvt_nid, hda_nid_t pin_nid)
  2475. {
  2476. struct hdmi_spec *spec;
  2477. struct hdmi_spec_per_cvt *per_cvt;
  2478. struct hdmi_spec_per_pin *per_pin;
  2479. spec = kzalloc(sizeof(*spec), GFP_KERNEL);
  2480. if (!spec)
  2481. return -ENOMEM;
  2482. codec->spec = spec;
  2483. hdmi_array_init(spec, 1);
  2484. spec->multiout.num_dacs = 0; /* no analog */
  2485. spec->multiout.max_channels = 2;
  2486. spec->multiout.dig_out_nid = cvt_nid;
  2487. spec->num_cvts = 1;
  2488. spec->num_pins = 1;
  2489. per_pin = snd_array_new(&spec->pins);
  2490. per_cvt = snd_array_new(&spec->cvts);
  2491. if (!per_pin || !per_cvt) {
  2492. simple_playback_free(codec);
  2493. return -ENOMEM;
  2494. }
  2495. per_cvt->cvt_nid = cvt_nid;
  2496. per_pin->pin_nid = pin_nid;
  2497. spec->pcm_playback = simple_pcm_playback;
  2498. codec->patch_ops = simple_hdmi_patch_ops;
  2499. return 0;
  2500. }
  2501. static void nvhdmi_8ch_7x_set_info_frame_parameters(struct hda_codec *codec,
  2502. int channels)
  2503. {
  2504. unsigned int chanmask;
  2505. int chan = channels ? (channels - 1) : 1;
  2506. switch (channels) {
  2507. default:
  2508. case 0:
  2509. case 2:
  2510. chanmask = 0x00;
  2511. break;
  2512. case 4:
  2513. chanmask = 0x08;
  2514. break;
  2515. case 6:
  2516. chanmask = 0x0b;
  2517. break;
  2518. case 8:
  2519. chanmask = 0x13;
  2520. break;
  2521. }
  2522. /* Set the audio infoframe channel allocation and checksum fields. The
  2523. * channel count is computed implicitly by the hardware. */
  2524. snd_hda_codec_write(codec, 0x1, 0,
  2525. Nv_VERB_SET_Channel_Allocation, chanmask);
  2526. snd_hda_codec_write(codec, 0x1, 0,
  2527. Nv_VERB_SET_Info_Frame_Checksum,
  2528. (0x71 - chan - chanmask));
  2529. }
  2530. static int nvhdmi_8ch_7x_pcm_close(struct hda_pcm_stream *hinfo,
  2531. struct hda_codec *codec,
  2532. struct snd_pcm_substream *substream)
  2533. {
  2534. struct hdmi_spec *spec = codec->spec;
  2535. int i;
  2536. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x,
  2537. 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
  2538. for (i = 0; i < 4; i++) {
  2539. /* set the stream id */
  2540. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  2541. AC_VERB_SET_CHANNEL_STREAMID, 0);
  2542. /* set the stream format */
  2543. snd_hda_codec_write(codec, nvhdmi_con_nids_7x[i], 0,
  2544. AC_VERB_SET_STREAM_FORMAT, 0);
  2545. }
  2546. /* The audio hardware sends a channel count of 0x7 (8ch) when all the
  2547. * streams are disabled. */
  2548. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  2549. return snd_hda_multi_out_dig_close(codec, &spec->multiout);
  2550. }
  2551. static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
  2552. struct hda_codec *codec,
  2553. unsigned int stream_tag,
  2554. unsigned int format,
  2555. struct snd_pcm_substream *substream)
  2556. {
  2557. int chs;
  2558. unsigned int dataDCC2, channel_id;
  2559. int i;
  2560. struct hdmi_spec *spec = codec->spec;
  2561. struct hda_spdif_out *spdif;
  2562. struct hdmi_spec_per_cvt *per_cvt;
  2563. mutex_lock(&codec->spdif_mutex);
  2564. per_cvt = get_cvt(spec, 0);
  2565. spdif = snd_hda_spdif_out_of_nid(codec, per_cvt->cvt_nid);
  2566. chs = substream->runtime->channels;
  2567. dataDCC2 = 0x2;
  2568. /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
  2569. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE))
  2570. snd_hda_codec_write(codec,
  2571. nvhdmi_master_con_nid_7x,
  2572. 0,
  2573. AC_VERB_SET_DIGI_CONVERT_1,
  2574. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  2575. /* set the stream id */
  2576. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  2577. AC_VERB_SET_CHANNEL_STREAMID, (stream_tag << 4) | 0x0);
  2578. /* set the stream format */
  2579. snd_hda_codec_write(codec, nvhdmi_master_con_nid_7x, 0,
  2580. AC_VERB_SET_STREAM_FORMAT, format);
  2581. /* turn on again (if needed) */
  2582. /* enable and set the channel status audio/data flag */
  2583. if (codec->spdif_status_reset && (spdif->ctls & AC_DIG1_ENABLE)) {
  2584. snd_hda_codec_write(codec,
  2585. nvhdmi_master_con_nid_7x,
  2586. 0,
  2587. AC_VERB_SET_DIGI_CONVERT_1,
  2588. spdif->ctls & 0xff);
  2589. snd_hda_codec_write(codec,
  2590. nvhdmi_master_con_nid_7x,
  2591. 0,
  2592. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  2593. }
  2594. for (i = 0; i < 4; i++) {
  2595. if (chs == 2)
  2596. channel_id = 0;
  2597. else
  2598. channel_id = i * 2;
  2599. /* turn off SPDIF once;
  2600. *otherwise the IEC958 bits won't be updated
  2601. */
  2602. if (codec->spdif_status_reset &&
  2603. (spdif->ctls & AC_DIG1_ENABLE))
  2604. snd_hda_codec_write(codec,
  2605. nvhdmi_con_nids_7x[i],
  2606. 0,
  2607. AC_VERB_SET_DIGI_CONVERT_1,
  2608. spdif->ctls & ~AC_DIG1_ENABLE & 0xff);
  2609. /* set the stream id */
  2610. snd_hda_codec_write(codec,
  2611. nvhdmi_con_nids_7x[i],
  2612. 0,
  2613. AC_VERB_SET_CHANNEL_STREAMID,
  2614. (stream_tag << 4) | channel_id);
  2615. /* set the stream format */
  2616. snd_hda_codec_write(codec,
  2617. nvhdmi_con_nids_7x[i],
  2618. 0,
  2619. AC_VERB_SET_STREAM_FORMAT,
  2620. format);
  2621. /* turn on again (if needed) */
  2622. /* enable and set the channel status audio/data flag */
  2623. if (codec->spdif_status_reset &&
  2624. (spdif->ctls & AC_DIG1_ENABLE)) {
  2625. snd_hda_codec_write(codec,
  2626. nvhdmi_con_nids_7x[i],
  2627. 0,
  2628. AC_VERB_SET_DIGI_CONVERT_1,
  2629. spdif->ctls & 0xff);
  2630. snd_hda_codec_write(codec,
  2631. nvhdmi_con_nids_7x[i],
  2632. 0,
  2633. AC_VERB_SET_DIGI_CONVERT_2, dataDCC2);
  2634. }
  2635. }
  2636. nvhdmi_8ch_7x_set_info_frame_parameters(codec, chs);
  2637. mutex_unlock(&codec->spdif_mutex);
  2638. return 0;
  2639. }
  2640. static const struct hda_pcm_stream nvhdmi_pcm_playback_8ch_7x = {
  2641. .substreams = 1,
  2642. .channels_min = 2,
  2643. .channels_max = 8,
  2644. .nid = nvhdmi_master_con_nid_7x,
  2645. .rates = SUPPORTED_RATES,
  2646. .maxbps = SUPPORTED_MAXBPS,
  2647. .formats = SUPPORTED_FORMATS,
  2648. .ops = {
  2649. .open = simple_playback_pcm_open,
  2650. .close = nvhdmi_8ch_7x_pcm_close,
  2651. .prepare = nvhdmi_8ch_7x_pcm_prepare
  2652. },
  2653. };
  2654. static int patch_nvhdmi_2ch(struct hda_codec *codec)
  2655. {
  2656. struct hdmi_spec *spec;
  2657. int err = patch_simple_hdmi(codec, nvhdmi_master_con_nid_7x,
  2658. nvhdmi_master_pin_nid_7x);
  2659. if (err < 0)
  2660. return err;
  2661. codec->patch_ops.init = nvhdmi_7x_init_2ch;
  2662. /* override the PCM rates, etc, as the codec doesn't give full list */
  2663. spec = codec->spec;
  2664. spec->pcm_playback.rates = SUPPORTED_RATES;
  2665. spec->pcm_playback.maxbps = SUPPORTED_MAXBPS;
  2666. spec->pcm_playback.formats = SUPPORTED_FORMATS;
  2667. return 0;
  2668. }
  2669. static int nvhdmi_7x_8ch_build_pcms(struct hda_codec *codec)
  2670. {
  2671. struct hdmi_spec *spec = codec->spec;
  2672. int err = simple_playback_build_pcms(codec);
  2673. if (!err) {
  2674. struct hda_pcm *info = get_pcm_rec(spec, 0);
  2675. info->own_chmap = true;
  2676. }
  2677. return err;
  2678. }
  2679. static int nvhdmi_7x_8ch_build_controls(struct hda_codec *codec)
  2680. {
  2681. struct hdmi_spec *spec = codec->spec;
  2682. struct hda_pcm *info;
  2683. struct snd_pcm_chmap *chmap;
  2684. int err;
  2685. err = simple_playback_build_controls(codec);
  2686. if (err < 0)
  2687. return err;
  2688. /* add channel maps */
  2689. info = get_pcm_rec(spec, 0);
  2690. err = snd_pcm_add_chmap_ctls(info->pcm,
  2691. SNDRV_PCM_STREAM_PLAYBACK,
  2692. snd_pcm_alt_chmaps, 8, 0, &chmap);
  2693. if (err < 0)
  2694. return err;
  2695. switch (codec->preset->vendor_id) {
  2696. case 0x10de0002:
  2697. case 0x10de0003:
  2698. case 0x10de0005:
  2699. case 0x10de0006:
  2700. chmap->channel_mask = (1U << 2) | (1U << 8);
  2701. break;
  2702. case 0x10de0007:
  2703. chmap->channel_mask = (1U << 2) | (1U << 6) | (1U << 8);
  2704. }
  2705. return 0;
  2706. }
  2707. static int patch_nvhdmi_8ch_7x(struct hda_codec *codec)
  2708. {
  2709. struct hdmi_spec *spec;
  2710. int err = patch_nvhdmi_2ch(codec);
  2711. if (err < 0)
  2712. return err;
  2713. spec = codec->spec;
  2714. spec->multiout.max_channels = 8;
  2715. spec->pcm_playback = nvhdmi_pcm_playback_8ch_7x;
  2716. codec->patch_ops.init = nvhdmi_7x_init_8ch;
  2717. codec->patch_ops.build_pcms = nvhdmi_7x_8ch_build_pcms;
  2718. codec->patch_ops.build_controls = nvhdmi_7x_8ch_build_controls;
  2719. /* Initialize the audio infoframe channel mask and checksum to something
  2720. * valid */
  2721. nvhdmi_8ch_7x_set_info_frame_parameters(codec, 8);
  2722. return 0;
  2723. }
  2724. /*
  2725. * NVIDIA codecs ignore ASP mapping for 2ch - confirmed on:
  2726. * - 0x10de0015
  2727. * - 0x10de0040
  2728. */
  2729. static int nvhdmi_chmap_cea_alloc_validate_get_type(struct hdac_chmap *chmap,
  2730. struct hdac_cea_channel_speaker_allocation *cap, int channels)
  2731. {
  2732. if (cap->ca_index == 0x00 && channels == 2)
  2733. return SNDRV_CTL_TLVT_CHMAP_FIXED;
  2734. /* If the speaker allocation matches the channel count, it is OK. */
  2735. if (cap->channels != channels)
  2736. return -1;
  2737. /* all channels are remappable freely */
  2738. return SNDRV_CTL_TLVT_CHMAP_VAR;
  2739. }
  2740. static int nvhdmi_chmap_validate(struct hdac_chmap *chmap,
  2741. int ca, int chs, unsigned char *map)
  2742. {
  2743. if (ca == 0x00 && (map[0] != SNDRV_CHMAP_FL || map[1] != SNDRV_CHMAP_FR))
  2744. return -EINVAL;
  2745. return 0;
  2746. }
  2747. static int patch_nvhdmi(struct hda_codec *codec)
  2748. {
  2749. struct hdmi_spec *spec;
  2750. int err;
  2751. err = patch_generic_hdmi(codec);
  2752. if (err)
  2753. return err;
  2754. spec = codec->spec;
  2755. spec->dyn_pin_out = true;
  2756. spec->chmap.ops.chmap_cea_alloc_validate_get_type =
  2757. nvhdmi_chmap_cea_alloc_validate_get_type;
  2758. spec->chmap.ops.chmap_validate = nvhdmi_chmap_validate;
  2759. return 0;
  2760. }
  2761. /*
  2762. * The HDA codec on NVIDIA Tegra contains two scratch registers that are
  2763. * accessed using vendor-defined verbs. These registers can be used for
  2764. * interoperability between the HDA and HDMI drivers.
  2765. */
  2766. /* Audio Function Group node */
  2767. #define NVIDIA_AFG_NID 0x01
  2768. /*
  2769. * The SCRATCH0 register is used to notify the HDMI codec of changes in audio
  2770. * format. On Tegra, bit 31 is used as a trigger that causes an interrupt to
  2771. * be raised in the HDMI codec. The remainder of the bits is arbitrary. This
  2772. * implementation stores the HDA format (see AC_FMT_*) in bits [15:0] and an
  2773. * additional bit (at position 30) to signal the validity of the format.
  2774. *
  2775. * | 31 | 30 | 29 16 | 15 0 |
  2776. * +---------+-------+--------+--------+
  2777. * | TRIGGER | VALID | UNUSED | FORMAT |
  2778. * +-----------------------------------|
  2779. *
  2780. * Note that for the trigger bit to take effect it needs to change value
  2781. * (i.e. it needs to be toggled).
  2782. */
  2783. #define NVIDIA_GET_SCRATCH0 0xfa6
  2784. #define NVIDIA_SET_SCRATCH0_BYTE0 0xfa7
  2785. #define NVIDIA_SET_SCRATCH0_BYTE1 0xfa8
  2786. #define NVIDIA_SET_SCRATCH0_BYTE2 0xfa9
  2787. #define NVIDIA_SET_SCRATCH0_BYTE3 0xfaa
  2788. #define NVIDIA_SCRATCH_TRIGGER (1 << 7)
  2789. #define NVIDIA_SCRATCH_VALID (1 << 6)
  2790. #define NVIDIA_GET_SCRATCH1 0xfab
  2791. #define NVIDIA_SET_SCRATCH1_BYTE0 0xfac
  2792. #define NVIDIA_SET_SCRATCH1_BYTE1 0xfad
  2793. #define NVIDIA_SET_SCRATCH1_BYTE2 0xfae
  2794. #define NVIDIA_SET_SCRATCH1_BYTE3 0xfaf
  2795. /*
  2796. * The format parameter is the HDA audio format (see AC_FMT_*). If set to 0,
  2797. * the format is invalidated so that the HDMI codec can be disabled.
  2798. */
  2799. static void tegra_hdmi_set_format(struct hda_codec *codec, unsigned int format)
  2800. {
  2801. unsigned int value;
  2802. /* bits [31:30] contain the trigger and valid bits */
  2803. value = snd_hda_codec_read(codec, NVIDIA_AFG_NID, 0,
  2804. NVIDIA_GET_SCRATCH0, 0);
  2805. value = (value >> 24) & 0xff;
  2806. /* bits [15:0] are used to store the HDA format */
  2807. snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
  2808. NVIDIA_SET_SCRATCH0_BYTE0,
  2809. (format >> 0) & 0xff);
  2810. snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
  2811. NVIDIA_SET_SCRATCH0_BYTE1,
  2812. (format >> 8) & 0xff);
  2813. /* bits [16:24] are unused */
  2814. snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
  2815. NVIDIA_SET_SCRATCH0_BYTE2, 0);
  2816. /*
  2817. * Bit 30 signals that the data is valid and hence that HDMI audio can
  2818. * be enabled.
  2819. */
  2820. if (format == 0)
  2821. value &= ~NVIDIA_SCRATCH_VALID;
  2822. else
  2823. value |= NVIDIA_SCRATCH_VALID;
  2824. /*
  2825. * Whenever the trigger bit is toggled, an interrupt is raised in the
  2826. * HDMI codec. The HDMI driver will use that as trigger to update its
  2827. * configuration.
  2828. */
  2829. value ^= NVIDIA_SCRATCH_TRIGGER;
  2830. snd_hda_codec_write(codec, NVIDIA_AFG_NID, 0,
  2831. NVIDIA_SET_SCRATCH0_BYTE3, value);
  2832. }
  2833. static int tegra_hdmi_pcm_prepare(struct hda_pcm_stream *hinfo,
  2834. struct hda_codec *codec,
  2835. unsigned int stream_tag,
  2836. unsigned int format,
  2837. struct snd_pcm_substream *substream)
  2838. {
  2839. int err;
  2840. err = generic_hdmi_playback_pcm_prepare(hinfo, codec, stream_tag,
  2841. format, substream);
  2842. if (err < 0)
  2843. return err;
  2844. /* notify the HDMI codec of the format change */
  2845. tegra_hdmi_set_format(codec, format);
  2846. return 0;
  2847. }
  2848. static int tegra_hdmi_pcm_cleanup(struct hda_pcm_stream *hinfo,
  2849. struct hda_codec *codec,
  2850. struct snd_pcm_substream *substream)
  2851. {
  2852. /* invalidate the format in the HDMI codec */
  2853. tegra_hdmi_set_format(codec, 0);
  2854. return generic_hdmi_playback_pcm_cleanup(hinfo, codec, substream);
  2855. }
  2856. static struct hda_pcm *hda_find_pcm_by_type(struct hda_codec *codec, int type)
  2857. {
  2858. struct hdmi_spec *spec = codec->spec;
  2859. unsigned int i;
  2860. for (i = 0; i < spec->num_pins; i++) {
  2861. struct hda_pcm *pcm = get_pcm_rec(spec, i);
  2862. if (pcm->pcm_type == type)
  2863. return pcm;
  2864. }
  2865. return NULL;
  2866. }
  2867. static int tegra_hdmi_build_pcms(struct hda_codec *codec)
  2868. {
  2869. struct hda_pcm_stream *stream;
  2870. struct hda_pcm *pcm;
  2871. int err;
  2872. err = generic_hdmi_build_pcms(codec);
  2873. if (err < 0)
  2874. return err;
  2875. pcm = hda_find_pcm_by_type(codec, HDA_PCM_TYPE_HDMI);
  2876. if (!pcm)
  2877. return -ENODEV;
  2878. /*
  2879. * Override ->prepare() and ->cleanup() operations to notify the HDMI
  2880. * codec about format changes.
  2881. */
  2882. stream = &pcm->stream[SNDRV_PCM_STREAM_PLAYBACK];
  2883. stream->ops.prepare = tegra_hdmi_pcm_prepare;
  2884. stream->ops.cleanup = tegra_hdmi_pcm_cleanup;
  2885. return 0;
  2886. }
  2887. static int patch_tegra_hdmi(struct hda_codec *codec)
  2888. {
  2889. int err;
  2890. err = patch_generic_hdmi(codec);
  2891. if (err)
  2892. return err;
  2893. codec->patch_ops.build_pcms = tegra_hdmi_build_pcms;
  2894. return 0;
  2895. }
  2896. /*
  2897. * ATI/AMD-specific implementations
  2898. */
  2899. #define is_amdhdmi_rev3_or_later(codec) \
  2900. ((codec)->core.vendor_id == 0x1002aa01 && \
  2901. ((codec)->core.revision_id & 0xff00) >= 0x0300)
  2902. #define has_amd_full_remap_support(codec) is_amdhdmi_rev3_or_later(codec)
  2903. /* ATI/AMD specific HDA pin verbs, see the AMD HDA Verbs specification */
  2904. #define ATI_VERB_SET_CHANNEL_ALLOCATION 0x771
  2905. #define ATI_VERB_SET_DOWNMIX_INFO 0x772
  2906. #define ATI_VERB_SET_MULTICHANNEL_01 0x777
  2907. #define ATI_VERB_SET_MULTICHANNEL_23 0x778
  2908. #define ATI_VERB_SET_MULTICHANNEL_45 0x779
  2909. #define ATI_VERB_SET_MULTICHANNEL_67 0x77a
  2910. #define ATI_VERB_SET_HBR_CONTROL 0x77c
  2911. #define ATI_VERB_SET_MULTICHANNEL_1 0x785
  2912. #define ATI_VERB_SET_MULTICHANNEL_3 0x786
  2913. #define ATI_VERB_SET_MULTICHANNEL_5 0x787
  2914. #define ATI_VERB_SET_MULTICHANNEL_7 0x788
  2915. #define ATI_VERB_SET_MULTICHANNEL_MODE 0x789
  2916. #define ATI_VERB_GET_CHANNEL_ALLOCATION 0xf71
  2917. #define ATI_VERB_GET_DOWNMIX_INFO 0xf72
  2918. #define ATI_VERB_GET_MULTICHANNEL_01 0xf77
  2919. #define ATI_VERB_GET_MULTICHANNEL_23 0xf78
  2920. #define ATI_VERB_GET_MULTICHANNEL_45 0xf79
  2921. #define ATI_VERB_GET_MULTICHANNEL_67 0xf7a
  2922. #define ATI_VERB_GET_HBR_CONTROL 0xf7c
  2923. #define ATI_VERB_GET_MULTICHANNEL_1 0xf85
  2924. #define ATI_VERB_GET_MULTICHANNEL_3 0xf86
  2925. #define ATI_VERB_GET_MULTICHANNEL_5 0xf87
  2926. #define ATI_VERB_GET_MULTICHANNEL_7 0xf88
  2927. #define ATI_VERB_GET_MULTICHANNEL_MODE 0xf89
  2928. /* AMD specific HDA cvt verbs */
  2929. #define ATI_VERB_SET_RAMP_RATE 0x770
  2930. #define ATI_VERB_GET_RAMP_RATE 0xf70
  2931. #define ATI_OUT_ENABLE 0x1
  2932. #define ATI_MULTICHANNEL_MODE_PAIRED 0
  2933. #define ATI_MULTICHANNEL_MODE_SINGLE 1
  2934. #define ATI_HBR_CAPABLE 0x01
  2935. #define ATI_HBR_ENABLE 0x10
  2936. static int atihdmi_pin_get_eld(struct hda_codec *codec, hda_nid_t nid,
  2937. unsigned char *buf, int *eld_size)
  2938. {
  2939. /* call hda_eld.c ATI/AMD-specific function */
  2940. return snd_hdmi_get_eld_ati(codec, nid, buf, eld_size,
  2941. is_amdhdmi_rev3_or_later(codec));
  2942. }
  2943. static void atihdmi_pin_setup_infoframe(struct hda_codec *codec, hda_nid_t pin_nid, int ca,
  2944. int active_channels, int conn_type)
  2945. {
  2946. snd_hda_codec_write(codec, pin_nid, 0, ATI_VERB_SET_CHANNEL_ALLOCATION, ca);
  2947. }
  2948. static int atihdmi_paired_swap_fc_lfe(int pos)
  2949. {
  2950. /*
  2951. * ATI/AMD have automatic FC/LFE swap built-in
  2952. * when in pairwise mapping mode.
  2953. */
  2954. switch (pos) {
  2955. /* see channel_allocations[].speakers[] */
  2956. case 2: return 3;
  2957. case 3: return 2;
  2958. default: break;
  2959. }
  2960. return pos;
  2961. }
  2962. static int atihdmi_paired_chmap_validate(struct hdac_chmap *chmap,
  2963. int ca, int chs, unsigned char *map)
  2964. {
  2965. struct hdac_cea_channel_speaker_allocation *cap;
  2966. int i, j;
  2967. /* check that only channel pairs need to be remapped on old pre-rev3 ATI/AMD */
  2968. cap = snd_hdac_get_ch_alloc_from_ca(ca);
  2969. for (i = 0; i < chs; ++i) {
  2970. int mask = snd_hdac_chmap_to_spk_mask(map[i]);
  2971. bool ok = false;
  2972. bool companion_ok = false;
  2973. if (!mask)
  2974. continue;
  2975. for (j = 0 + i % 2; j < 8; j += 2) {
  2976. int chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j);
  2977. if (cap->speakers[chan_idx] == mask) {
  2978. /* channel is in a supported position */
  2979. ok = true;
  2980. if (i % 2 == 0 && i + 1 < chs) {
  2981. /* even channel, check the odd companion */
  2982. int comp_chan_idx = 7 - atihdmi_paired_swap_fc_lfe(j + 1);
  2983. int comp_mask_req = snd_hdac_chmap_to_spk_mask(map[i+1]);
  2984. int comp_mask_act = cap->speakers[comp_chan_idx];
  2985. if (comp_mask_req == comp_mask_act)
  2986. companion_ok = true;
  2987. else
  2988. return -EINVAL;
  2989. }
  2990. break;
  2991. }
  2992. }
  2993. if (!ok)
  2994. return -EINVAL;
  2995. if (companion_ok)
  2996. i++; /* companion channel already checked */
  2997. }
  2998. return 0;
  2999. }
  3000. static int atihdmi_pin_set_slot_channel(struct hdac_device *hdac,
  3001. hda_nid_t pin_nid, int hdmi_slot, int stream_channel)
  3002. {
  3003. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  3004. int verb;
  3005. int ati_channel_setup = 0;
  3006. if (hdmi_slot > 7)
  3007. return -EINVAL;
  3008. if (!has_amd_full_remap_support(codec)) {
  3009. hdmi_slot = atihdmi_paired_swap_fc_lfe(hdmi_slot);
  3010. /* In case this is an odd slot but without stream channel, do not
  3011. * disable the slot since the corresponding even slot could have a
  3012. * channel. In case neither have a channel, the slot pair will be
  3013. * disabled when this function is called for the even slot. */
  3014. if (hdmi_slot % 2 != 0 && stream_channel == 0xf)
  3015. return 0;
  3016. hdmi_slot -= hdmi_slot % 2;
  3017. if (stream_channel != 0xf)
  3018. stream_channel -= stream_channel % 2;
  3019. }
  3020. verb = ATI_VERB_SET_MULTICHANNEL_01 + hdmi_slot/2 + (hdmi_slot % 2) * 0x00e;
  3021. /* ati_channel_setup format: [7..4] = stream_channel_id, [1] = mute, [0] = enable */
  3022. if (stream_channel != 0xf)
  3023. ati_channel_setup = (stream_channel << 4) | ATI_OUT_ENABLE;
  3024. return snd_hda_codec_write(codec, pin_nid, 0, verb, ati_channel_setup);
  3025. }
  3026. static int atihdmi_pin_get_slot_channel(struct hdac_device *hdac,
  3027. hda_nid_t pin_nid, int asp_slot)
  3028. {
  3029. struct hda_codec *codec = container_of(hdac, struct hda_codec, core);
  3030. bool was_odd = false;
  3031. int ati_asp_slot = asp_slot;
  3032. int verb;
  3033. int ati_channel_setup;
  3034. if (asp_slot > 7)
  3035. return -EINVAL;
  3036. if (!has_amd_full_remap_support(codec)) {
  3037. ati_asp_slot = atihdmi_paired_swap_fc_lfe(asp_slot);
  3038. if (ati_asp_slot % 2 != 0) {
  3039. ati_asp_slot -= 1;
  3040. was_odd = true;
  3041. }
  3042. }
  3043. verb = ATI_VERB_GET_MULTICHANNEL_01 + ati_asp_slot/2 + (ati_asp_slot % 2) * 0x00e;
  3044. ati_channel_setup = snd_hda_codec_read(codec, pin_nid, 0, verb, 0);
  3045. if (!(ati_channel_setup & ATI_OUT_ENABLE))
  3046. return 0xf;
  3047. return ((ati_channel_setup & 0xf0) >> 4) + !!was_odd;
  3048. }
  3049. static int atihdmi_paired_chmap_cea_alloc_validate_get_type(
  3050. struct hdac_chmap *chmap,
  3051. struct hdac_cea_channel_speaker_allocation *cap,
  3052. int channels)
  3053. {
  3054. int c;
  3055. /*
  3056. * Pre-rev3 ATI/AMD codecs operate in a paired channel mode, so
  3057. * we need to take that into account (a single channel may take 2
  3058. * channel slots if we need to carry a silent channel next to it).
  3059. * On Rev3+ AMD codecs this function is not used.
  3060. */
  3061. int chanpairs = 0;
  3062. /* We only produce even-numbered channel count TLVs */
  3063. if ((channels % 2) != 0)
  3064. return -1;
  3065. for (c = 0; c < 7; c += 2) {
  3066. if (cap->speakers[c] || cap->speakers[c+1])
  3067. chanpairs++;
  3068. }
  3069. if (chanpairs * 2 != channels)
  3070. return -1;
  3071. return SNDRV_CTL_TLVT_CHMAP_PAIRED;
  3072. }
  3073. static void atihdmi_paired_cea_alloc_to_tlv_chmap(struct hdac_chmap *hchmap,
  3074. struct hdac_cea_channel_speaker_allocation *cap,
  3075. unsigned int *chmap, int channels)
  3076. {
  3077. /* produce paired maps for pre-rev3 ATI/AMD codecs */
  3078. int count = 0;
  3079. int c;
  3080. for (c = 7; c >= 0; c--) {
  3081. int chan = 7 - atihdmi_paired_swap_fc_lfe(7 - c);
  3082. int spk = cap->speakers[chan];
  3083. if (!spk) {
  3084. /* add N/A channel if the companion channel is occupied */
  3085. if (cap->speakers[chan + (chan % 2 ? -1 : 1)])
  3086. chmap[count++] = SNDRV_CHMAP_NA;
  3087. continue;
  3088. }
  3089. chmap[count++] = snd_hdac_spk_to_chmap(spk);
  3090. }
  3091. WARN_ON(count != channels);
  3092. }
  3093. static int atihdmi_pin_hbr_setup(struct hda_codec *codec, hda_nid_t pin_nid,
  3094. bool hbr)
  3095. {
  3096. int hbr_ctl, hbr_ctl_new;
  3097. hbr_ctl = snd_hda_codec_read(codec, pin_nid, 0, ATI_VERB_GET_HBR_CONTROL, 0);
  3098. if (hbr_ctl >= 0 && (hbr_ctl & ATI_HBR_CAPABLE)) {
  3099. if (hbr)
  3100. hbr_ctl_new = hbr_ctl | ATI_HBR_ENABLE;
  3101. else
  3102. hbr_ctl_new = hbr_ctl & ~ATI_HBR_ENABLE;
  3103. codec_dbg(codec,
  3104. "atihdmi_pin_hbr_setup: NID=0x%x, %shbr-ctl=0x%x\n",
  3105. pin_nid,
  3106. hbr_ctl == hbr_ctl_new ? "" : "new-",
  3107. hbr_ctl_new);
  3108. if (hbr_ctl != hbr_ctl_new)
  3109. snd_hda_codec_write(codec, pin_nid, 0,
  3110. ATI_VERB_SET_HBR_CONTROL,
  3111. hbr_ctl_new);
  3112. } else if (hbr)
  3113. return -EINVAL;
  3114. return 0;
  3115. }
  3116. static int atihdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
  3117. hda_nid_t pin_nid, u32 stream_tag, int format)
  3118. {
  3119. if (is_amdhdmi_rev3_or_later(codec)) {
  3120. int ramp_rate = 180; /* default as per AMD spec */
  3121. /* disable ramp-up/down for non-pcm as per AMD spec */
  3122. if (format & AC_FMT_TYPE_NON_PCM)
  3123. ramp_rate = 0;
  3124. snd_hda_codec_write(codec, cvt_nid, 0, ATI_VERB_SET_RAMP_RATE, ramp_rate);
  3125. }
  3126. return hdmi_setup_stream(codec, cvt_nid, pin_nid, stream_tag, format);
  3127. }
  3128. static int atihdmi_init(struct hda_codec *codec)
  3129. {
  3130. struct hdmi_spec *spec = codec->spec;
  3131. int pin_idx, err;
  3132. err = generic_hdmi_init(codec);
  3133. if (err)
  3134. return err;
  3135. for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
  3136. struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx);
  3137. /* make sure downmix information in infoframe is zero */
  3138. snd_hda_codec_write(codec, per_pin->pin_nid, 0, ATI_VERB_SET_DOWNMIX_INFO, 0);
  3139. /* enable channel-wise remap mode if supported */
  3140. if (has_amd_full_remap_support(codec))
  3141. snd_hda_codec_write(codec, per_pin->pin_nid, 0,
  3142. ATI_VERB_SET_MULTICHANNEL_MODE,
  3143. ATI_MULTICHANNEL_MODE_SINGLE);
  3144. }
  3145. return 0;
  3146. }
  3147. static int patch_atihdmi(struct hda_codec *codec)
  3148. {
  3149. struct hdmi_spec *spec;
  3150. struct hdmi_spec_per_cvt *per_cvt;
  3151. int err, cvt_idx;
  3152. err = patch_generic_hdmi(codec);
  3153. if (err)
  3154. return err;
  3155. codec->patch_ops.init = atihdmi_init;
  3156. spec = codec->spec;
  3157. spec->ops.pin_get_eld = atihdmi_pin_get_eld;
  3158. spec->ops.pin_setup_infoframe = atihdmi_pin_setup_infoframe;
  3159. spec->ops.pin_hbr_setup = atihdmi_pin_hbr_setup;
  3160. spec->ops.setup_stream = atihdmi_setup_stream;
  3161. spec->chmap.ops.pin_get_slot_channel = atihdmi_pin_get_slot_channel;
  3162. spec->chmap.ops.pin_set_slot_channel = atihdmi_pin_set_slot_channel;
  3163. if (!has_amd_full_remap_support(codec)) {
  3164. /* override to ATI/AMD-specific versions with pairwise mapping */
  3165. spec->chmap.ops.chmap_cea_alloc_validate_get_type =
  3166. atihdmi_paired_chmap_cea_alloc_validate_get_type;
  3167. spec->chmap.ops.cea_alloc_to_tlv_chmap =
  3168. atihdmi_paired_cea_alloc_to_tlv_chmap;
  3169. spec->chmap.ops.chmap_validate = atihdmi_paired_chmap_validate;
  3170. }
  3171. /* ATI/AMD converters do not advertise all of their capabilities */
  3172. for (cvt_idx = 0; cvt_idx < spec->num_cvts; cvt_idx++) {
  3173. per_cvt = get_cvt(spec, cvt_idx);
  3174. per_cvt->channels_max = max(per_cvt->channels_max, 8u);
  3175. per_cvt->rates |= SUPPORTED_RATES;
  3176. per_cvt->formats |= SUPPORTED_FORMATS;
  3177. per_cvt->maxbps = max(per_cvt->maxbps, 24u);
  3178. }
  3179. spec->chmap.channels_max = max(spec->chmap.channels_max, 8u);
  3180. /* AMD GPUs have neither EPSS nor CLKSTOP bits, hence preventing
  3181. * the link-down as is. Tell the core to allow it.
  3182. */
  3183. codec->link_down_at_suspend = 1;
  3184. return 0;
  3185. }
  3186. /* VIA HDMI Implementation */
  3187. #define VIAHDMI_CVT_NID 0x02 /* audio converter1 */
  3188. #define VIAHDMI_PIN_NID 0x03 /* HDMI output pin1 */
  3189. static int patch_via_hdmi(struct hda_codec *codec)
  3190. {
  3191. return patch_simple_hdmi(codec, VIAHDMI_CVT_NID, VIAHDMI_PIN_NID);
  3192. }
  3193. /*
  3194. * patch entries
  3195. */
  3196. static const struct hda_device_id snd_hda_id_hdmi[] = {
  3197. HDA_CODEC_ENTRY(0x1002793c, "RS600 HDMI", patch_atihdmi),
  3198. HDA_CODEC_ENTRY(0x10027919, "RS600 HDMI", patch_atihdmi),
  3199. HDA_CODEC_ENTRY(0x1002791a, "RS690/780 HDMI", patch_atihdmi),
  3200. HDA_CODEC_ENTRY(0x1002aa01, "R6xx HDMI", patch_atihdmi),
  3201. HDA_CODEC_ENTRY(0x10951390, "SiI1390 HDMI", patch_generic_hdmi),
  3202. HDA_CODEC_ENTRY(0x10951392, "SiI1392 HDMI", patch_generic_hdmi),
  3203. HDA_CODEC_ENTRY(0x17e80047, "Chrontel HDMI", patch_generic_hdmi),
  3204. HDA_CODEC_ENTRY(0x10de0001, "MCP73 HDMI", patch_nvhdmi_2ch),
  3205. HDA_CODEC_ENTRY(0x10de0002, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
  3206. HDA_CODEC_ENTRY(0x10de0003, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
  3207. HDA_CODEC_ENTRY(0x10de0004, "GPU 04 HDMI", patch_nvhdmi_8ch_7x),
  3208. HDA_CODEC_ENTRY(0x10de0005, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
  3209. HDA_CODEC_ENTRY(0x10de0006, "MCP77/78 HDMI", patch_nvhdmi_8ch_7x),
  3210. HDA_CODEC_ENTRY(0x10de0007, "MCP79/7A HDMI", patch_nvhdmi_8ch_7x),
  3211. HDA_CODEC_ENTRY(0x10de0008, "GPU 08 HDMI/DP", patch_nvhdmi),
  3212. HDA_CODEC_ENTRY(0x10de0009, "GPU 09 HDMI/DP", patch_nvhdmi),
  3213. HDA_CODEC_ENTRY(0x10de000a, "GPU 0a HDMI/DP", patch_nvhdmi),
  3214. HDA_CODEC_ENTRY(0x10de000b, "GPU 0b HDMI/DP", patch_nvhdmi),
  3215. HDA_CODEC_ENTRY(0x10de000c, "MCP89 HDMI", patch_nvhdmi),
  3216. HDA_CODEC_ENTRY(0x10de000d, "GPU 0d HDMI/DP", patch_nvhdmi),
  3217. HDA_CODEC_ENTRY(0x10de0010, "GPU 10 HDMI/DP", patch_nvhdmi),
  3218. HDA_CODEC_ENTRY(0x10de0011, "GPU 11 HDMI/DP", patch_nvhdmi),
  3219. HDA_CODEC_ENTRY(0x10de0012, "GPU 12 HDMI/DP", patch_nvhdmi),
  3220. HDA_CODEC_ENTRY(0x10de0013, "GPU 13 HDMI/DP", patch_nvhdmi),
  3221. HDA_CODEC_ENTRY(0x10de0014, "GPU 14 HDMI/DP", patch_nvhdmi),
  3222. HDA_CODEC_ENTRY(0x10de0015, "GPU 15 HDMI/DP", patch_nvhdmi),
  3223. HDA_CODEC_ENTRY(0x10de0016, "GPU 16 HDMI/DP", patch_nvhdmi),
  3224. /* 17 is known to be absent */
  3225. HDA_CODEC_ENTRY(0x10de0018, "GPU 18 HDMI/DP", patch_nvhdmi),
  3226. HDA_CODEC_ENTRY(0x10de0019, "GPU 19 HDMI/DP", patch_nvhdmi),
  3227. HDA_CODEC_ENTRY(0x10de001a, "GPU 1a HDMI/DP", patch_nvhdmi),
  3228. HDA_CODEC_ENTRY(0x10de001b, "GPU 1b HDMI/DP", patch_nvhdmi),
  3229. HDA_CODEC_ENTRY(0x10de001c, "GPU 1c HDMI/DP", patch_nvhdmi),
  3230. HDA_CODEC_ENTRY(0x10de0020, "Tegra30 HDMI", patch_tegra_hdmi),
  3231. HDA_CODEC_ENTRY(0x10de0022, "Tegra114 HDMI", patch_tegra_hdmi),
  3232. HDA_CODEC_ENTRY(0x10de0028, "Tegra124 HDMI", patch_tegra_hdmi),
  3233. HDA_CODEC_ENTRY(0x10de0029, "Tegra210 HDMI/DP", patch_tegra_hdmi),
  3234. HDA_CODEC_ENTRY(0x10de0040, "GPU 40 HDMI/DP", patch_nvhdmi),
  3235. HDA_CODEC_ENTRY(0x10de0041, "GPU 41 HDMI/DP", patch_nvhdmi),
  3236. HDA_CODEC_ENTRY(0x10de0042, "GPU 42 HDMI/DP", patch_nvhdmi),
  3237. HDA_CODEC_ENTRY(0x10de0043, "GPU 43 HDMI/DP", patch_nvhdmi),
  3238. HDA_CODEC_ENTRY(0x10de0044, "GPU 44 HDMI/DP", patch_nvhdmi),
  3239. HDA_CODEC_ENTRY(0x10de0045, "GPU 45 HDMI/DP", patch_nvhdmi),
  3240. HDA_CODEC_ENTRY(0x10de0050, "GPU 50 HDMI/DP", patch_nvhdmi),
  3241. HDA_CODEC_ENTRY(0x10de0051, "GPU 51 HDMI/DP", patch_nvhdmi),
  3242. HDA_CODEC_ENTRY(0x10de0052, "GPU 52 HDMI/DP", patch_nvhdmi),
  3243. HDA_CODEC_ENTRY(0x10de0060, "GPU 60 HDMI/DP", patch_nvhdmi),
  3244. HDA_CODEC_ENTRY(0x10de0061, "GPU 61 HDMI/DP", patch_nvhdmi),
  3245. HDA_CODEC_ENTRY(0x10de0062, "GPU 62 HDMI/DP", patch_nvhdmi),
  3246. HDA_CODEC_ENTRY(0x10de0067, "MCP67 HDMI", patch_nvhdmi_2ch),
  3247. HDA_CODEC_ENTRY(0x10de0070, "GPU 70 HDMI/DP", patch_nvhdmi),
  3248. HDA_CODEC_ENTRY(0x10de0071, "GPU 71 HDMI/DP", patch_nvhdmi),
  3249. HDA_CODEC_ENTRY(0x10de0072, "GPU 72 HDMI/DP", patch_nvhdmi),
  3250. HDA_CODEC_ENTRY(0x10de0073, "GPU 73 HDMI/DP", patch_nvhdmi),
  3251. HDA_CODEC_ENTRY(0x10de0074, "GPU 74 HDMI/DP", patch_nvhdmi),
  3252. HDA_CODEC_ENTRY(0x10de0076, "GPU 76 HDMI/DP", patch_nvhdmi),
  3253. HDA_CODEC_ENTRY(0x10de007b, "GPU 7b HDMI/DP", patch_nvhdmi),
  3254. HDA_CODEC_ENTRY(0x10de007c, "GPU 7c HDMI/DP", patch_nvhdmi),
  3255. HDA_CODEC_ENTRY(0x10de007d, "GPU 7d HDMI/DP", patch_nvhdmi),
  3256. HDA_CODEC_ENTRY(0x10de007e, "GPU 7e HDMI/DP", patch_nvhdmi),
  3257. HDA_CODEC_ENTRY(0x10de0080, "GPU 80 HDMI/DP", patch_nvhdmi),
  3258. HDA_CODEC_ENTRY(0x10de0081, "GPU 81 HDMI/DP", patch_nvhdmi),
  3259. HDA_CODEC_ENTRY(0x10de0082, "GPU 82 HDMI/DP", patch_nvhdmi),
  3260. HDA_CODEC_ENTRY(0x10de0083, "GPU 83 HDMI/DP", patch_nvhdmi),
  3261. HDA_CODEC_ENTRY(0x10de0084, "GPU 84 HDMI/DP", patch_nvhdmi),
  3262. HDA_CODEC_ENTRY(0x10de0090, "GPU 90 HDMI/DP", patch_nvhdmi),
  3263. HDA_CODEC_ENTRY(0x10de0091, "GPU 91 HDMI/DP", patch_nvhdmi),
  3264. HDA_CODEC_ENTRY(0x10de0092, "GPU 92 HDMI/DP", patch_nvhdmi),
  3265. HDA_CODEC_ENTRY(0x10de0093, "GPU 93 HDMI/DP", patch_nvhdmi),
  3266. HDA_CODEC_ENTRY(0x10de0094, "GPU 94 HDMI/DP", patch_nvhdmi),
  3267. HDA_CODEC_ENTRY(0x10de0095, "GPU 95 HDMI/DP", patch_nvhdmi),
  3268. HDA_CODEC_ENTRY(0x10de0097, "GPU 97 HDMI/DP", patch_nvhdmi),
  3269. HDA_CODEC_ENTRY(0x10de0098, "GPU 98 HDMI/DP", patch_nvhdmi),
  3270. HDA_CODEC_ENTRY(0x10de0099, "GPU 99 HDMI/DP", patch_nvhdmi),
  3271. HDA_CODEC_ENTRY(0x10de8001, "MCP73 HDMI", patch_nvhdmi_2ch),
  3272. HDA_CODEC_ENTRY(0x10de8067, "MCP67/68 HDMI", patch_nvhdmi_2ch),
  3273. HDA_CODEC_ENTRY(0x11069f80, "VX900 HDMI/DP", patch_via_hdmi),
  3274. HDA_CODEC_ENTRY(0x11069f81, "VX900 HDMI/DP", patch_via_hdmi),
  3275. HDA_CODEC_ENTRY(0x11069f84, "VX11 HDMI/DP", patch_generic_hdmi),
  3276. HDA_CODEC_ENTRY(0x11069f85, "VX11 HDMI/DP", patch_generic_hdmi),
  3277. HDA_CODEC_ENTRY(0x80860054, "IbexPeak HDMI", patch_i915_cpt_hdmi),
  3278. HDA_CODEC_ENTRY(0x80862801, "Bearlake HDMI", patch_generic_hdmi),
  3279. HDA_CODEC_ENTRY(0x80862802, "Cantiga HDMI", patch_generic_hdmi),
  3280. HDA_CODEC_ENTRY(0x80862803, "Eaglelake HDMI", patch_generic_hdmi),
  3281. HDA_CODEC_ENTRY(0x80862804, "IbexPeak HDMI", patch_i915_cpt_hdmi),
  3282. HDA_CODEC_ENTRY(0x80862805, "CougarPoint HDMI", patch_i915_cpt_hdmi),
  3283. HDA_CODEC_ENTRY(0x80862806, "PantherPoint HDMI", patch_i915_cpt_hdmi),
  3284. HDA_CODEC_ENTRY(0x80862807, "Haswell HDMI", patch_i915_hsw_hdmi),
  3285. HDA_CODEC_ENTRY(0x80862808, "Broadwell HDMI", patch_i915_hsw_hdmi),
  3286. HDA_CODEC_ENTRY(0x80862809, "Skylake HDMI", patch_i915_hsw_hdmi),
  3287. HDA_CODEC_ENTRY(0x8086280a, "Broxton HDMI", patch_i915_hsw_hdmi),
  3288. HDA_CODEC_ENTRY(0x8086280b, "Kabylake HDMI", patch_i915_hsw_hdmi),
  3289. HDA_CODEC_ENTRY(0x8086280c, "Cannonlake HDMI", patch_i915_glk_hdmi),
  3290. HDA_CODEC_ENTRY(0x8086280d, "Geminilake HDMI", patch_i915_glk_hdmi),
  3291. HDA_CODEC_ENTRY(0x80862800, "Geminilake HDMI", patch_i915_glk_hdmi),
  3292. HDA_CODEC_ENTRY(0x80862880, "CedarTrail HDMI", patch_generic_hdmi),
  3293. HDA_CODEC_ENTRY(0x80862882, "Valleyview2 HDMI", patch_i915_byt_hdmi),
  3294. HDA_CODEC_ENTRY(0x80862883, "Braswell HDMI", patch_i915_byt_hdmi),
  3295. HDA_CODEC_ENTRY(0x808629fb, "Crestline HDMI", patch_generic_hdmi),
  3296. /* special ID for generic HDMI */
  3297. HDA_CODEC_ENTRY(HDA_CODEC_ID_GENERIC_HDMI, "Generic HDMI", patch_generic_hdmi),
  3298. {} /* terminator */
  3299. };
  3300. MODULE_DEVICE_TABLE(hdaudio, snd_hda_id_hdmi);
  3301. MODULE_LICENSE("GPL");
  3302. MODULE_DESCRIPTION("HDMI HD-audio codec");
  3303. MODULE_ALIAS("snd-hda-codec-intelhdmi");
  3304. MODULE_ALIAS("snd-hda-codec-nvhdmi");
  3305. MODULE_ALIAS("snd-hda-codec-atihdmi");
  3306. static struct hda_codec_driver hdmi_driver = {
  3307. .id = snd_hda_id_hdmi,
  3308. };
  3309. module_hda_codec_driver(hdmi_driver);