patch_hdmi.c 76 KB

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