patch_hdmi.c 107 KB

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