patch_hdmi.c 95 KB

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