patch_hdmi.c 92 KB

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