patch_hdmi.c 101 KB

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