patch_hdmi.c 96 KB

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