patch_hdmi.c 91 KB

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