patch_hdmi.c 75 KB

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