patch_hdmi.c 104 KB

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