patch_hdmi.c 66 KB

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